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.

251993 lines
6.3MB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-9 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifdef __JUCE_JUCEHEADER__
  19. #error
  20. #endif
  21. /*** Start of inlined file: juce_TargetPlatform.h ***/
  22. #ifndef __JUCE_TARGETPLATFORM_JUCEHEADER__
  23. #define __JUCE_TARGETPLATFORM_JUCEHEADER__
  24. #if (defined (_WIN32) || defined (_WIN64))
  25. #define JUCE_WIN32 1
  26. #define JUCE_WINDOWS 1
  27. #elif defined (LINUX) || defined (__linux__)
  28. #define JUCE_LINUX 1
  29. #elif defined(__APPLE_CPP__) || defined(__APPLE_CC__)
  30. #include <CoreFoundation/CoreFoundation.h> // (needed to find out what platform we're using)
  31. #if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
  32. #define JUCE_IPHONE 1
  33. #else
  34. #define JUCE_MAC 1
  35. #endif
  36. #else
  37. #error "Unknown platform!"
  38. #endif
  39. #if JUCE_WINDOWS
  40. #ifdef _MSC_VER
  41. #ifdef _WIN64
  42. #define JUCE_64BIT 1
  43. #else
  44. #define JUCE_32BIT 1
  45. #endif
  46. #endif
  47. #ifdef _DEBUG
  48. #define JUCE_DEBUG 1
  49. #endif
  50. #ifdef __MINGW32__
  51. #define JUCE_MINGW 1
  52. #endif
  53. #define JUCE_LITTLE_ENDIAN 1
  54. #define JUCE_INTEL 1
  55. #endif
  56. #if JUCE_MAC
  57. #ifndef NDEBUG
  58. #define JUCE_DEBUG 1
  59. #endif
  60. #ifdef __LITTLE_ENDIAN__
  61. #define JUCE_LITTLE_ENDIAN 1
  62. #else
  63. #define JUCE_BIG_ENDIAN 1
  64. #endif
  65. #if defined (__ppc__) || defined (__ppc64__)
  66. #define JUCE_PPC 1
  67. #undef MAC_OS_X_VERSION_MAX_ALLOWED
  68. #define MAC_OS_X_VERSION_MAX_ALLOWED MAC_OS_X_VERSION_10_4
  69. #else
  70. #define JUCE_INTEL 1
  71. #endif
  72. #ifdef __LP64__
  73. #define JUCE_64BIT 1
  74. #else
  75. #define JUCE_32BIT 1
  76. #endif
  77. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_4
  78. #error "Building for OSX 10.3 is no longer supported!"
  79. #endif
  80. #ifndef MAC_OS_X_VERSION_10_5
  81. #error "To build with 10.4 compatibility, use a 10.5 or 10.6 SDK and set the deployment target to 10.4"
  82. #endif
  83. #endif
  84. #if JUCE_IPHONE
  85. #ifndef NDEBUG
  86. #define JUCE_DEBUG 1
  87. #endif
  88. #ifdef __LITTLE_ENDIAN__
  89. #define JUCE_LITTLE_ENDIAN 1
  90. #else
  91. #define JUCE_BIG_ENDIAN 1
  92. #endif
  93. #endif
  94. #if JUCE_LINUX
  95. #ifdef _DEBUG
  96. #define JUCE_DEBUG 1
  97. #endif
  98. // Allow override for big-endian Linux platforms
  99. #ifndef JUCE_BIG_ENDIAN
  100. #define JUCE_LITTLE_ENDIAN 1
  101. #endif
  102. #if defined (__LP64__) || defined (_LP64)
  103. #define JUCE_64BIT 1
  104. #else
  105. #define JUCE_32BIT 1
  106. #endif
  107. #define JUCE_INTEL 1
  108. #endif
  109. // Compiler type macros.
  110. #ifdef __GNUC__
  111. #define JUCE_GCC 1
  112. #elif defined (_MSC_VER)
  113. #define JUCE_MSVC 1
  114. #if _MSC_VER >= 1400
  115. #define JUCE_USE_INTRINSICS 1
  116. #endif
  117. #else
  118. #error unknown compiler
  119. #endif
  120. #endif // __JUCE_TARGETPLATFORM_JUCEHEADER__
  121. /*** End of inlined file: juce_TargetPlatform.h ***/
  122. // FORCE_AMALGAMATOR_INCLUDE
  123. /*** Start of inlined file: juce_Config.h ***/
  124. #ifndef __JUCE_CONFIG_JUCEHEADER__
  125. #define __JUCE_CONFIG_JUCEHEADER__
  126. #ifndef JUCE_NAMESPACE
  127. #define JUCE_NAMESPACE juce
  128. #endif
  129. #ifndef JUCE_FORCE_DEBUG
  130. //#define JUCE_FORCE_DEBUG 1
  131. #endif
  132. #ifndef JUCE_LOG_ASSERTIONS
  133. // #define JUCE_LOG_ASSERTIONS 1
  134. #endif
  135. #ifndef JUCE_ASIO
  136. #define JUCE_ASIO 1
  137. #endif
  138. #ifndef JUCE_WASAPI
  139. // #define JUCE_WASAPI 1
  140. #endif
  141. #ifndef JUCE_DIRECTSOUND
  142. #define JUCE_DIRECTSOUND 1
  143. #endif
  144. #ifndef JUCE_ALSA
  145. #define JUCE_ALSA 1
  146. #endif
  147. #ifndef JUCE_JACK
  148. #define JUCE_JACK 1
  149. #endif
  150. #if ! (defined (JUCE_QUICKTIME) || JUCE_LINUX || JUCE_IPHONE || (JUCE_WINDOWS && ! JUCE_MSVC))
  151. #define JUCE_QUICKTIME 1
  152. #endif
  153. #ifndef JUCE_OPENGL
  154. #define JUCE_OPENGL 1
  155. #endif
  156. #ifndef JUCE_USE_FLAC
  157. #define JUCE_USE_FLAC 1
  158. #endif
  159. #ifndef JUCE_USE_OGGVORBIS
  160. #define JUCE_USE_OGGVORBIS 1
  161. #endif
  162. #if (! defined (JUCE_USE_CDBURNER)) && ! (JUCE_WINDOWS && ! JUCE_MSVC)
  163. #define JUCE_USE_CDBURNER 1
  164. #endif
  165. #ifndef JUCE_USE_CDREADER
  166. #define JUCE_USE_CDREADER 1
  167. #endif
  168. #if JUCE_QUICKTIME && ! defined (JUCE_USE_CAMERA)
  169. // #define JUCE_USE_CAMERA 1
  170. #endif
  171. #ifndef JUCE_ENABLE_REPAINT_DEBUGGING
  172. // #define JUCE_ENABLE_REPAINT_DEBUGGING 1
  173. #endif
  174. #ifndef JUCE_USE_XINERAMA
  175. #define JUCE_USE_XINERAMA 1
  176. #endif
  177. #ifndef JUCE_USE_XSHM
  178. #define JUCE_USE_XSHM 1
  179. #endif
  180. #ifndef JUCE_USE_XRENDER
  181. //#define JUCE_USE_XRENDER 1
  182. #endif
  183. #ifndef JUCE_PLUGINHOST_VST
  184. // #define JUCE_PLUGINHOST_VST 1
  185. #endif
  186. #ifndef JUCE_PLUGINHOST_AU
  187. // #define JUCE_PLUGINHOST_AU 1
  188. #endif
  189. #ifndef JUCE_ONLY_BUILD_CORE_LIBRARY
  190. //#define JUCE_ONLY_BUILD_CORE_LIBRARY 1
  191. #endif
  192. #ifndef JUCE_WEB_BROWSER
  193. #define JUCE_WEB_BROWSER 1
  194. #endif
  195. #ifndef JUCE_SUPPORT_CARBON
  196. #define JUCE_SUPPORT_CARBON 1
  197. #endif
  198. #ifndef JUCE_INCLUDE_ZLIB_CODE
  199. #define JUCE_INCLUDE_ZLIB_CODE 1
  200. #endif
  201. #ifndef JUCE_INCLUDE_FLAC_CODE
  202. #define JUCE_INCLUDE_FLAC_CODE 1
  203. #endif
  204. #ifndef JUCE_INCLUDE_OGGVORBIS_CODE
  205. #define JUCE_INCLUDE_OGGVORBIS_CODE 1
  206. #endif
  207. #ifndef JUCE_INCLUDE_PNGLIB_CODE
  208. #define JUCE_INCLUDE_PNGLIB_CODE 1
  209. #endif
  210. #ifndef JUCE_INCLUDE_JPEGLIB_CODE
  211. #define JUCE_INCLUDE_JPEGLIB_CODE 1
  212. #endif
  213. #ifndef JUCE_CHECK_MEMORY_LEAKS
  214. #define JUCE_CHECK_MEMORY_LEAKS 1
  215. #endif
  216. #ifndef JUCE_CATCH_UNHANDLED_EXCEPTIONS
  217. #define JUCE_CATCH_UNHANDLED_EXCEPTIONS 1
  218. #endif
  219. // If only building the core classes, we can explicitly turn off some features to avoid including them:
  220. #if JUCE_ONLY_BUILD_CORE_LIBRARY
  221. #undef JUCE_QUICKTIME
  222. #define JUCE_QUICKTIME 0
  223. #undef JUCE_OPENGL
  224. #define JUCE_OPENGL 0
  225. #undef JUCE_USE_CDBURNER
  226. #define JUCE_USE_CDBURNER 0
  227. #undef JUCE_USE_CDREADER
  228. #define JUCE_USE_CDREADER 0
  229. #undef JUCE_WEB_BROWSER
  230. #define JUCE_WEB_BROWSER 0
  231. #undef JUCE_PLUGINHOST_AU
  232. #define JUCE_PLUGINHOST_AU 0
  233. #undef JUCE_PLUGINHOST_VST
  234. #define JUCE_PLUGINHOST_VST 0
  235. #endif
  236. #endif
  237. /*** End of inlined file: juce_Config.h ***/
  238. // FORCE_AMALGAMATOR_INCLUDE
  239. #ifndef JUCE_BUILD_CORE
  240. #define JUCE_BUILD_CORE 1
  241. #endif
  242. #ifndef JUCE_BUILD_MISC
  243. #define JUCE_BUILD_MISC 1
  244. #endif
  245. #ifndef JUCE_BUILD_GUI
  246. #define JUCE_BUILD_GUI 1
  247. #endif
  248. #ifndef JUCE_BUILD_NATIVE
  249. #define JUCE_BUILD_NATIVE 1
  250. #endif
  251. #if JUCE_ONLY_BUILD_CORE_LIBRARY
  252. #undef JUCE_BUILD_MISC
  253. #undef JUCE_BUILD_GUI
  254. #endif
  255. //==============================================================================
  256. #if JUCE_BUILD_NATIVE || JUCE_BUILD_CORE || (JUCE_BUILD_MISC && (JUCE_PLUGINHOST_VST || JUCE_PLUGINHOST_AU))
  257. #if JUCE_WINDOWS
  258. /*** Start of inlined file: juce_win32_NativeIncludes.h ***/
  259. #ifndef __JUCE_WIN32_NATIVEINCLUDES_JUCEHEADER__
  260. #define __JUCE_WIN32_NATIVEINCLUDES_JUCEHEADER__
  261. #ifndef STRICT
  262. #define STRICT 1
  263. #endif
  264. #undef WIN32_LEAN_AND_MEAN
  265. #define WIN32_LEAN_AND_MEAN 1
  266. #ifdef _MSC_VER
  267. #pragma warning (push)
  268. #pragma warning (disable : 4100 4201 4514 4312 4995)
  269. #endif
  270. #define _WIN32_WINNT 0x0500
  271. #define _UNICODE 1
  272. #define UNICODE 1
  273. #ifndef _WIN32_IE
  274. #define _WIN32_IE 0x0400
  275. #endif
  276. #include <windows.h>
  277. #include <windowsx.h>
  278. #include <commdlg.h>
  279. #include <shellapi.h>
  280. #include <mmsystem.h>
  281. #include <vfw.h>
  282. #include <tchar.h>
  283. #include <stddef.h>
  284. #include <ctime>
  285. #include <wininet.h>
  286. #include <nb30.h>
  287. #include <iphlpapi.h>
  288. #include <mapi.h>
  289. #include <float.h>
  290. #include <process.h>
  291. #include <Exdisp.h>
  292. #include <exdispid.h>
  293. #include <shlobj.h>
  294. #if ! JUCE_MINGW
  295. #include <crtdbg.h>
  296. #include <comutil.h>
  297. #endif
  298. #if JUCE_OPENGL
  299. #include <gl/gl.h>
  300. #endif
  301. #undef PACKED
  302. #if JUCE_ASIO
  303. #include "iasiodrv.h"
  304. #endif
  305. #if JUCE_USE_CDBURNER
  306. #include <imapi.h>
  307. #include <imapierror.h>
  308. #endif
  309. #if JUCE_USE_CAMERA
  310. #include <dshow.h>
  311. #include <qedit.h>
  312. #include <dshowasf.h>
  313. #endif
  314. #if JUCE_WASAPI
  315. #include <MMReg.h>
  316. #include <mmdeviceapi.h>
  317. #include <Audioclient.h>
  318. #include <Avrt.h>
  319. #include <functiondiscoverykeys.h>
  320. #endif
  321. #if JUCE_QUICKTIME
  322. #include <Movies.h>
  323. #include <QTML.h>
  324. #include <QuickTimeComponents.h>
  325. #include <MediaHandlers.h>
  326. #include <ImageCodec.h>
  327. #import <QTOLibrary.dll>
  328. #import <QTOControl.dll>
  329. #endif
  330. #ifdef _MSC_VER
  331. #pragma warning (pop)
  332. #endif
  333. template <class T>
  334. class ComSmartPtr
  335. {
  336. public:
  337. ComSmartPtr() throw() : p (0) {}
  338. ComSmartPtr (T* const p_) : p (p_) { if (p_ != 0) p_->AddRef(); }
  339. ComSmartPtr (const ComSmartPtr<T>& p_) : p (p_.p) { if (p != 0) p->AddRef(); }
  340. ~ComSmartPtr() { if (p != 0) p->Release(); }
  341. operator T*() const throw() { return p; }
  342. T& operator*() const throw() { return *p; }
  343. T** operator&() throw() { return &p; }
  344. T* operator->() const throw() { return p; }
  345. T* operator= (T* const newP)
  346. {
  347. if (newP != 0)
  348. newP->AddRef();
  349. if (p != 0)
  350. p->Release();
  351. p = newP;
  352. return newP;
  353. }
  354. T* operator= (const ComSmartPtr<T>& newP) { return operator= (newP.p); }
  355. HRESULT CoCreateInstance (REFCLSID rclsid, DWORD dwClsContext)
  356. {
  357. #ifndef __MINGW32__
  358. operator= (0);
  359. return ::CoCreateInstance (rclsid, 0, dwClsContext, __uuidof(T), (void**) &p);
  360. #else
  361. return S_FALSE;
  362. #endif
  363. }
  364. T* p;
  365. };
  366. #endif // __JUCE_WIN32_NATIVEINCLUDES_JUCEHEADER__
  367. /*** End of inlined file: juce_win32_NativeIncludes.h ***/
  368. #elif JUCE_LINUX
  369. /*** Start of inlined file: juce_linux_NativeIncludes.h ***/
  370. #ifndef __JUCE_LINUX_NATIVEINCLUDES_JUCEHEADER__
  371. #define __JUCE_LINUX_NATIVEINCLUDES_JUCEHEADER__
  372. #include <sched.h>
  373. #include <pthread.h>
  374. #include <sys/time.h>
  375. #include <errno.h>
  376. #include <sys/stat.h>
  377. #include <sys/dir.h>
  378. #include <sys/ptrace.h>
  379. #include <sys/vfs.h>
  380. #include <sys/wait.h>
  381. #include <fnmatch.h>
  382. #include <utime.h>
  383. #include <pwd.h>
  384. #include <fcntl.h>
  385. #include <dlfcn.h>
  386. #include <netdb.h>
  387. #include <arpa/inet.h>
  388. #include <netinet/in.h>
  389. #include <sys/types.h>
  390. #include <sys/ioctl.h>
  391. #include <sys/socket.h>
  392. #include <linux/if.h>
  393. #include <sys/sysinfo.h>
  394. #include <sys/file.h>
  395. #include <signal.h>
  396. #include <ft2build.h>
  397. #include FT_FREETYPE_H
  398. #include <X11/Xlib.h>
  399. #include <X11/Xatom.h>
  400. #include <X11/Xresource.h>
  401. #include <X11/Xutil.h>
  402. #include <X11/Xmd.h>
  403. #include <X11/keysym.h>
  404. #include <X11/cursorfont.h>
  405. #if JUCE_USE_XINERAMA
  406. #include <X11/extensions/Xinerama.h>
  407. #endif
  408. #if JUCE_USE_XSHM
  409. #include <X11/extensions/XShm.h>
  410. #include <sys/shm.h>
  411. #include <sys/ipc.h>
  412. #endif
  413. #if JUCE_USE_XRENDER
  414. // If you're missing these headers, try installing the libxrender-dev and libxcomposite-dev
  415. #include <X11/extensions/Xrender.h>
  416. #include <X11/extensions/Xcomposite.h>
  417. #endif
  418. #if JUCE_OPENGL
  419. #include <GL/glx.h>
  420. #endif
  421. #undef KeyPress
  422. #if JUCE_ALSA
  423. #include <alsa/asoundlib.h>
  424. #endif
  425. #if JUCE_JACK
  426. #include <jack/jack.h>
  427. //#include <jack/transport.h>
  428. #endif
  429. #undef SIZEOF
  430. #endif // __JUCE_LINUX_NATIVEINCLUDES_JUCEHEADER__
  431. /*** End of inlined file: juce_linux_NativeIncludes.h ***/
  432. #elif JUCE_MAC || JUCE_IPHONE
  433. /*** Start of inlined file: juce_mac_NativeIncludes.h ***/
  434. #ifndef __JUCE_MAC_NATIVEINCLUDES_JUCEHEADER__
  435. #define __JUCE_MAC_NATIVEINCLUDES_JUCEHEADER__
  436. #define USE_COREGRAPHICS_RENDERING 1
  437. #if JUCE_IPHONE
  438. #import <Foundation/Foundation.h>
  439. #import <UIKit/UIKit.h>
  440. #import <AudioToolbox/AudioToolbox.h>
  441. #import <AVFoundation/AVFoundation.h>
  442. #import <CoreData/CoreData.h>
  443. #import <MobileCoreServices/MobileCoreServices.h>
  444. #include <sys/fcntl.h>
  445. #else
  446. #import <Cocoa/Cocoa.h>
  447. #import <CoreAudio/HostTime.h>
  448. #import <CoreAudio/AudioHardware.h>
  449. #import <CoreMIDI/MIDIServices.h>
  450. #import <QTKit/QTKit.h>
  451. #import <WebKit/WebKit.h>
  452. #import <DiscRecording/DiscRecording.h>
  453. #import <IOKit/IOKitLib.h>
  454. #import <IOKit/IOCFPlugIn.h>
  455. #import <IOKit/hid/IOHIDLib.h>
  456. #import <IOKit/hid/IOHIDKeys.h>
  457. #import <IOKit/pwr_mgt/IOPMLib.h>
  458. #include <Carbon/Carbon.h>
  459. #include <sys/dir.h>
  460. #include <sys/socket.h>
  461. #endif
  462. #include <sys/sysctl.h>
  463. #include <sys/stat.h>
  464. #include <sys/param.h>
  465. #include <sys/mount.h>
  466. #include <fnmatch.h>
  467. #include <utime.h>
  468. #include <dlfcn.h>
  469. #include <ifaddrs.h>
  470. #include <net/if_dl.h>
  471. #include <mach/mach_time.h>
  472. #if MACOS_10_4_OR_EARLIER
  473. #include <GLUT/glut.h>
  474. #endif
  475. #if ! CGFLOAT_DEFINED
  476. #define CGFloat float
  477. #endif
  478. #endif // __JUCE_MAC_NATIVEINCLUDES_JUCEHEADER__
  479. /*** End of inlined file: juce_mac_NativeIncludes.h ***/
  480. #else
  481. #error "Unknown platform!"
  482. #endif
  483. #endif
  484. //==============================================================================
  485. #define DONT_SET_USING_JUCE_NAMESPACE 1
  486. #undef max
  487. #undef min
  488. #define NO_DUMMY_DECL
  489. #if JUCE_BUILD_NATIVE
  490. #include "juce_amalgamated.h" // FORCE_AMALGAMATOR_INCLUDE
  491. #endif
  492. #if (defined(_MSC_VER) && (_MSC_VER <= 1200))
  493. #pragma warning (disable: 4309 4305)
  494. #endif
  495. #if JUCE_MAC && JUCE_32BIT && JUCE_SUPPORT_CARBON && JUCE_BUILD_NATIVE && ! JUCE_ONLY_BUILD_CORE_LIBRARY
  496. BEGIN_JUCE_NAMESPACE
  497. /*** Start of inlined file: juce_mac_CarbonViewWrapperComponent.h ***/
  498. #ifndef __JUCE_MAC_CARBONVIEWWRAPPERCOMPONENT_JUCEHEADER__
  499. #define __JUCE_MAC_CARBONVIEWWRAPPERCOMPONENT_JUCEHEADER__
  500. class CarbonViewWrapperComponent : public Component,
  501. public ComponentMovementWatcher,
  502. public Timer
  503. {
  504. public:
  505. CarbonViewWrapperComponent()
  506. : ComponentMovementWatcher (this),
  507. wrapperWindow (0),
  508. embeddedView (0),
  509. recursiveResize (false)
  510. {
  511. }
  512. virtual ~CarbonViewWrapperComponent()
  513. {
  514. jassert (embeddedView == 0); // must call deleteWindow() in the subclass's destructor!
  515. }
  516. virtual HIViewRef attachView (WindowRef windowRef, HIViewRef rootView) = 0;
  517. virtual void removeView (HIViewRef embeddedView) = 0;
  518. virtual void mouseDown (int x, int y) {}
  519. virtual void paint() {}
  520. virtual bool getEmbeddedViewSize (int& w, int& h)
  521. {
  522. if (embeddedView == 0)
  523. return false;
  524. HIRect bounds;
  525. HIViewGetBounds (embeddedView, &bounds);
  526. w = jmax (1, roundToInt (bounds.size.width));
  527. h = jmax (1, roundToInt (bounds.size.height));
  528. return true;
  529. }
  530. void createWindow()
  531. {
  532. if (wrapperWindow == 0)
  533. {
  534. Rect r;
  535. r.left = getScreenX();
  536. r.top = getScreenY();
  537. r.right = r.left + getWidth();
  538. r.bottom = r.top + getHeight();
  539. CreateNewWindow (kDocumentWindowClass,
  540. (WindowAttributes) (kWindowStandardHandlerAttribute | kWindowCompositingAttribute
  541. | kWindowNoShadowAttribute | kWindowNoTitleBarAttribute),
  542. &r, &wrapperWindow);
  543. jassert (wrapperWindow != 0);
  544. if (wrapperWindow == 0)
  545. return;
  546. NSWindow* carbonWindow = [[NSWindow alloc] initWithWindowRef: wrapperWindow];
  547. NSWindow* ownerWindow = [((NSView*) getWindowHandle()) window];
  548. [ownerWindow addChildWindow: carbonWindow
  549. ordered: NSWindowAbove];
  550. embeddedView = attachView (wrapperWindow, HIViewGetRoot (wrapperWindow));
  551. EventTypeSpec windowEventTypes[] = { { kEventClassWindow, kEventWindowGetClickActivation },
  552. { kEventClassWindow, kEventWindowHandleDeactivate } };
  553. EventHandlerUPP upp = NewEventHandlerUPP (carbonEventCallback);
  554. InstallWindowEventHandler (wrapperWindow, upp,
  555. sizeof (windowEventTypes) / sizeof (EventTypeSpec),
  556. windowEventTypes, this, &eventHandlerRef);
  557. setOurSizeToEmbeddedViewSize();
  558. setEmbeddedWindowToOurSize();
  559. creationTime = Time::getCurrentTime();
  560. }
  561. }
  562. void deleteWindow()
  563. {
  564. removeView (embeddedView);
  565. embeddedView = 0;
  566. if (wrapperWindow != 0)
  567. {
  568. RemoveEventHandler (eventHandlerRef);
  569. DisposeWindow (wrapperWindow);
  570. wrapperWindow = 0;
  571. }
  572. }
  573. void setOurSizeToEmbeddedViewSize()
  574. {
  575. int w, h;
  576. if (getEmbeddedViewSize (w, h))
  577. {
  578. if (w != getWidth() || h != getHeight())
  579. {
  580. startTimer (50);
  581. setSize (w, h);
  582. if (getParentComponent() != 0)
  583. getParentComponent()->setSize (w, h);
  584. }
  585. else
  586. {
  587. startTimer (jlimit (50, 500, getTimerInterval() + 20));
  588. }
  589. }
  590. else
  591. {
  592. stopTimer();
  593. }
  594. }
  595. void setEmbeddedWindowToOurSize()
  596. {
  597. if (! recursiveResize)
  598. {
  599. recursiveResize = true;
  600. if (embeddedView != 0)
  601. {
  602. HIRect r;
  603. r.origin.x = 0;
  604. r.origin.y = 0;
  605. r.size.width = (float) getWidth();
  606. r.size.height = (float) getHeight();
  607. HIViewSetFrame (embeddedView, &r);
  608. }
  609. if (wrapperWindow != 0)
  610. {
  611. Rect wr;
  612. wr.left = getScreenX();
  613. wr.top = getScreenY();
  614. wr.right = wr.left + getWidth();
  615. wr.bottom = wr.top + getHeight();
  616. SetWindowBounds (wrapperWindow, kWindowContentRgn, &wr);
  617. ShowWindow (wrapperWindow);
  618. }
  619. recursiveResize = false;
  620. }
  621. }
  622. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  623. {
  624. setEmbeddedWindowToOurSize();
  625. }
  626. void componentPeerChanged()
  627. {
  628. deleteWindow();
  629. createWindow();
  630. }
  631. void componentVisibilityChanged (Component&)
  632. {
  633. if (isShowing())
  634. createWindow();
  635. else
  636. deleteWindow();
  637. setEmbeddedWindowToOurSize();
  638. }
  639. static void recursiveHIViewRepaint (HIViewRef view)
  640. {
  641. HIViewSetNeedsDisplay (view, true);
  642. HIViewRef child = HIViewGetFirstSubview (view);
  643. while (child != 0)
  644. {
  645. recursiveHIViewRepaint (child);
  646. child = HIViewGetNextView (child);
  647. }
  648. }
  649. void timerCallback()
  650. {
  651. setOurSizeToEmbeddedViewSize();
  652. // To avoid strange overpainting problems when the UI is first opened, we'll
  653. // repaint it a few times during the first second that it's on-screen..
  654. if ((Time::getCurrentTime() - creationTime).inMilliseconds() < 1000)
  655. recursiveHIViewRepaint (HIViewGetRoot (wrapperWindow));
  656. }
  657. OSStatus carbonEventHandler (EventHandlerCallRef nextHandlerRef,
  658. EventRef event)
  659. {
  660. switch (GetEventKind (event))
  661. {
  662. case kEventWindowHandleDeactivate:
  663. ActivateWindow (wrapperWindow, TRUE);
  664. break;
  665. case kEventWindowGetClickActivation:
  666. {
  667. getTopLevelComponent()->toFront (false);
  668. ClickActivationResult howToHandleClick = kActivateAndHandleClick;
  669. SetEventParameter (event, kEventParamClickActivation, typeClickActivationResult,
  670. sizeof (ClickActivationResult), &howToHandleClick);
  671. HIViewSetNeedsDisplay (embeddedView, true);
  672. }
  673. break;
  674. }
  675. return noErr;
  676. }
  677. static pascal OSStatus carbonEventCallback (EventHandlerCallRef nextHandlerRef,
  678. EventRef event, void* userData)
  679. {
  680. return ((CarbonViewWrapperComponent*) userData)->carbonEventHandler (nextHandlerRef, event);
  681. }
  682. protected:
  683. WindowRef wrapperWindow;
  684. HIViewRef embeddedView;
  685. bool recursiveResize;
  686. Time creationTime;
  687. EventHandlerRef eventHandlerRef;
  688. };
  689. #endif // __JUCE_MAC_CARBONVIEWWRAPPERCOMPONENT_JUCEHEADER__
  690. /*** End of inlined file: juce_mac_CarbonViewWrapperComponent.h ***/
  691. END_JUCE_NAMESPACE
  692. #endif
  693. #define JUCE_AMALGAMATED_TEMPLATE 1
  694. //==============================================================================
  695. #if JUCE_BUILD_CORE
  696. /*** Start of inlined file: juce_FileLogger.cpp ***/
  697. BEGIN_JUCE_NAMESPACE
  698. FileLogger::FileLogger (const File& logFile_,
  699. const String& welcomeMessage,
  700. const int maxInitialFileSizeBytes)
  701. : logFile (logFile_)
  702. {
  703. if (maxInitialFileSizeBytes >= 0)
  704. trimFileSize (maxInitialFileSizeBytes);
  705. if (! logFile_.exists())
  706. {
  707. // do this so that the parent directories get created..
  708. logFile_.create();
  709. }
  710. logStream = logFile_.createOutputStream (256);
  711. jassert (logStream != 0);
  712. String welcome;
  713. welcome << "\r\n**********************************************************\r\n"
  714. << welcomeMessage
  715. << "\r\nLog started: " << Time::getCurrentTime().toString (true, true)
  716. << "\r\n";
  717. logMessage (welcome);
  718. }
  719. FileLogger::~FileLogger()
  720. {
  721. }
  722. void FileLogger::logMessage (const String& message)
  723. {
  724. if (logStream != 0)
  725. {
  726. DBG (message);
  727. const ScopedLock sl (logLock);
  728. (*logStream) << message << T("\r\n");
  729. logStream->flush();
  730. }
  731. }
  732. void FileLogger::trimFileSize (int maxFileSizeBytes) const
  733. {
  734. if (maxFileSizeBytes <= 0)
  735. {
  736. logFile.deleteFile();
  737. }
  738. else
  739. {
  740. const int64 fileSize = logFile.getSize();
  741. if (fileSize > maxFileSizeBytes)
  742. {
  743. ScopedPointer <FileInputStream> in (logFile.createInputStream());
  744. jassert (in != 0);
  745. if (in != 0)
  746. {
  747. in->setPosition (fileSize - maxFileSizeBytes);
  748. String content;
  749. {
  750. MemoryBlock contentToSave;
  751. contentToSave.setSize (maxFileSizeBytes + 4);
  752. contentToSave.fillWith (0);
  753. in->read (contentToSave.getData(), maxFileSizeBytes);
  754. in = 0;
  755. content = contentToSave.toString();
  756. }
  757. int newStart = 0;
  758. while (newStart < fileSize
  759. && content[newStart] != '\n'
  760. && content[newStart] != '\r')
  761. ++newStart;
  762. logFile.deleteFile();
  763. logFile.appendText (content.substring (newStart), false, false);
  764. }
  765. }
  766. }
  767. }
  768. FileLogger* FileLogger::createDefaultAppLogger (const String& logFileSubDirectoryName,
  769. const String& logFileName,
  770. const String& welcomeMessage,
  771. const int maxInitialFileSizeBytes)
  772. {
  773. #if JUCE_MAC
  774. File logFile ("~/Library/Logs");
  775. logFile = logFile.getChildFile (logFileSubDirectoryName)
  776. .getChildFile (logFileName);
  777. #else
  778. File logFile (File::getSpecialLocation (File::userApplicationDataDirectory));
  779. if (logFile.isDirectory())
  780. {
  781. logFile = logFile.getChildFile (logFileSubDirectoryName)
  782. .getChildFile (logFileName);
  783. }
  784. #endif
  785. return new FileLogger (logFile, welcomeMessage, maxInitialFileSizeBytes);
  786. }
  787. END_JUCE_NAMESPACE
  788. /*** End of inlined file: juce_FileLogger.cpp ***/
  789. /*** Start of inlined file: juce_Logger.cpp ***/
  790. BEGIN_JUCE_NAMESPACE
  791. Logger::Logger()
  792. {
  793. }
  794. Logger::~Logger()
  795. {
  796. }
  797. static Logger* currentLogger = 0;
  798. void Logger::setCurrentLogger (Logger* const newLogger,
  799. const bool deleteOldLogger)
  800. {
  801. Logger* const oldLogger = currentLogger;
  802. currentLogger = newLogger;
  803. if (deleteOldLogger)
  804. delete oldLogger;
  805. }
  806. void Logger::writeToLog (const String& message)
  807. {
  808. if (currentLogger != 0)
  809. currentLogger->logMessage (message);
  810. else
  811. outputDebugString (message);
  812. }
  813. #if JUCE_LOG_ASSERTIONS
  814. void JUCE_API juce_LogAssertion (const char* filename, const int lineNum) throw()
  815. {
  816. String m ("JUCE Assertion failure in ");
  817. m << filename << ", line " << lineNum;
  818. Logger::writeToLog (m);
  819. }
  820. #endif
  821. END_JUCE_NAMESPACE
  822. /*** End of inlined file: juce_Logger.cpp ***/
  823. /*** Start of inlined file: juce_Random.cpp ***/
  824. BEGIN_JUCE_NAMESPACE
  825. Random::Random (const int64 seedValue) throw()
  826. : seed (seedValue)
  827. {
  828. }
  829. Random::~Random() throw()
  830. {
  831. }
  832. void Random::setSeed (const int64 newSeed) throw()
  833. {
  834. seed = newSeed;
  835. }
  836. void Random::combineSeed (const int64 seedValue) throw()
  837. {
  838. seed ^= nextInt64() ^ seedValue;
  839. }
  840. void Random::setSeedRandomly()
  841. {
  842. combineSeed ((int64) (pointer_sized_int) this);
  843. combineSeed (Time::getMillisecondCounter());
  844. combineSeed (Time::getHighResolutionTicks());
  845. combineSeed (Time::getHighResolutionTicksPerSecond());
  846. combineSeed (Time::currentTimeMillis());
  847. }
  848. int Random::nextInt() throw()
  849. {
  850. seed = (seed * literal64bit (0x5deece66d) + 11) & literal64bit (0xffffffffffff);
  851. return (int) (seed >> 16);
  852. }
  853. int Random::nextInt (const int maxValue) throw()
  854. {
  855. jassert (maxValue > 0);
  856. return (nextInt() & 0x7fffffff) % maxValue;
  857. }
  858. int64 Random::nextInt64() throw()
  859. {
  860. return (((int64) nextInt()) << 32) | (int64) (uint64) (uint32) nextInt();
  861. }
  862. bool Random::nextBool() throw()
  863. {
  864. return (nextInt() & 0x80000000) != 0;
  865. }
  866. float Random::nextFloat() throw()
  867. {
  868. return ((uint32) nextInt()) / (float) 0xffffffff;
  869. }
  870. double Random::nextDouble() throw()
  871. {
  872. return ((uint32) nextInt()) / (double) 0xffffffff;
  873. }
  874. const BitArray Random::nextLargeNumber (const BitArray& maximumValue) throw()
  875. {
  876. BitArray n;
  877. do
  878. {
  879. fillBitsRandomly (n, 0, maximumValue.getHighestBit() + 1);
  880. }
  881. while (n.compare (maximumValue) >= 0);
  882. return n;
  883. }
  884. void Random::fillBitsRandomly (BitArray& arrayToChange, int startBit, int numBits) throw()
  885. {
  886. arrayToChange.setBit (startBit + numBits - 1, true); // to force the array to pre-allocate space
  887. while ((startBit & 31) != 0 && numBits > 0)
  888. {
  889. arrayToChange.setBit (startBit++, nextBool());
  890. --numBits;
  891. }
  892. while (numBits >= 32)
  893. {
  894. arrayToChange.setBitRangeAsInt (startBit, 32, (unsigned int) nextInt());
  895. startBit += 32;
  896. numBits -= 32;
  897. }
  898. while (--numBits >= 0)
  899. arrayToChange.setBit (startBit + numBits, nextBool());
  900. }
  901. Random& Random::getSystemRandom() throw()
  902. {
  903. static Random sysRand (1);
  904. return sysRand;
  905. }
  906. END_JUCE_NAMESPACE
  907. /*** End of inlined file: juce_Random.cpp ***/
  908. /*** Start of inlined file: juce_RelativeTime.cpp ***/
  909. BEGIN_JUCE_NAMESPACE
  910. RelativeTime::RelativeTime (const double seconds_) throw()
  911. : seconds (seconds_)
  912. {
  913. }
  914. RelativeTime::RelativeTime (const RelativeTime& other) throw()
  915. : seconds (other.seconds)
  916. {
  917. }
  918. RelativeTime::~RelativeTime() throw()
  919. {
  920. }
  921. const RelativeTime RelativeTime::milliseconds (const int milliseconds) throw()
  922. {
  923. return RelativeTime (milliseconds * 0.001);
  924. }
  925. const RelativeTime RelativeTime::milliseconds (const int64 milliseconds) throw()
  926. {
  927. return RelativeTime (milliseconds * 0.001);
  928. }
  929. const RelativeTime RelativeTime::minutes (const double numberOfMinutes) throw()
  930. {
  931. return RelativeTime (numberOfMinutes * 60.0);
  932. }
  933. const RelativeTime RelativeTime::hours (const double numberOfHours) throw()
  934. {
  935. return RelativeTime (numberOfHours * (60.0 * 60.0));
  936. }
  937. const RelativeTime RelativeTime::days (const double numberOfDays) throw()
  938. {
  939. return RelativeTime (numberOfDays * (60.0 * 60.0 * 24.0));
  940. }
  941. const RelativeTime RelativeTime::weeks (const double numberOfWeeks) throw()
  942. {
  943. return RelativeTime (numberOfWeeks * (60.0 * 60.0 * 24.0 * 7.0));
  944. }
  945. int64 RelativeTime::inMilliseconds() const throw()
  946. {
  947. return (int64)(seconds * 1000.0);
  948. }
  949. double RelativeTime::inMinutes() const throw()
  950. {
  951. return seconds / 60.0;
  952. }
  953. double RelativeTime::inHours() const throw()
  954. {
  955. return seconds / (60.0 * 60.0);
  956. }
  957. double RelativeTime::inDays() const throw()
  958. {
  959. return seconds / (60.0 * 60.0 * 24.0);
  960. }
  961. double RelativeTime::inWeeks() const throw()
  962. {
  963. return seconds / (60.0 * 60.0 * 24.0 * 7.0);
  964. }
  965. const String RelativeTime::getDescription (const String& returnValueForZeroTime) const throw()
  966. {
  967. if (seconds < 0.001 && seconds > -0.001)
  968. return returnValueForZeroTime;
  969. String result;
  970. if (seconds < 0)
  971. result = T("-");
  972. int fieldsShown = 0;
  973. int n = abs ((int) inWeeks());
  974. if (n > 0)
  975. {
  976. result << n << ((n == 1) ? TRANS(" week ")
  977. : TRANS(" weeks "));
  978. ++fieldsShown;
  979. }
  980. n = abs ((int) inDays()) % 7;
  981. if (n > 0)
  982. {
  983. result << n << ((n == 1) ? TRANS(" day ")
  984. : TRANS(" days "));
  985. ++fieldsShown;
  986. }
  987. if (fieldsShown < 2)
  988. {
  989. n = abs ((int) inHours()) % 24;
  990. if (n > 0)
  991. {
  992. result << n << ((n == 1) ? TRANS(" hr ")
  993. : TRANS(" hrs "));
  994. ++fieldsShown;
  995. }
  996. if (fieldsShown < 2)
  997. {
  998. n = abs ((int) inMinutes()) % 60;
  999. if (n > 0)
  1000. {
  1001. result << n << ((n == 1) ? TRANS(" min ")
  1002. : TRANS(" mins "));
  1003. ++fieldsShown;
  1004. }
  1005. if (fieldsShown < 2)
  1006. {
  1007. n = abs ((int) inSeconds()) % 60;
  1008. if (n > 0)
  1009. {
  1010. result << n << ((n == 1) ? TRANS(" sec ")
  1011. : TRANS(" secs "));
  1012. ++fieldsShown;
  1013. }
  1014. if (fieldsShown < 1)
  1015. {
  1016. n = abs ((int) inMilliseconds()) % 1000;
  1017. if (n > 0)
  1018. {
  1019. result << n << TRANS(" ms");
  1020. ++fieldsShown;
  1021. }
  1022. }
  1023. }
  1024. }
  1025. }
  1026. return result.trimEnd();
  1027. }
  1028. RelativeTime& RelativeTime::operator= (const RelativeTime& other) throw()
  1029. {
  1030. seconds = other.seconds;
  1031. return *this;
  1032. }
  1033. bool RelativeTime::operator== (const RelativeTime& other) const throw()
  1034. {
  1035. return seconds == other.seconds;
  1036. }
  1037. bool RelativeTime::operator!= (const RelativeTime& other) const throw()
  1038. {
  1039. return seconds != other.seconds;
  1040. }
  1041. bool RelativeTime::operator> (const RelativeTime& other) const throw()
  1042. {
  1043. return seconds > other.seconds;
  1044. }
  1045. bool RelativeTime::operator< (const RelativeTime& other) const throw()
  1046. {
  1047. return seconds < other.seconds;
  1048. }
  1049. bool RelativeTime::operator>= (const RelativeTime& other) const throw()
  1050. {
  1051. return seconds >= other.seconds;
  1052. }
  1053. bool RelativeTime::operator<= (const RelativeTime& other) const throw()
  1054. {
  1055. return seconds <= other.seconds;
  1056. }
  1057. const RelativeTime RelativeTime::operator+ (const RelativeTime& timeToAdd) const throw()
  1058. {
  1059. return RelativeTime (seconds + timeToAdd.seconds);
  1060. }
  1061. const RelativeTime RelativeTime::operator- (const RelativeTime& timeToSubtract) const throw()
  1062. {
  1063. return RelativeTime (seconds - timeToSubtract.seconds);
  1064. }
  1065. const RelativeTime RelativeTime::operator+ (const double secondsToAdd) const throw()
  1066. {
  1067. return RelativeTime (seconds + secondsToAdd);
  1068. }
  1069. const RelativeTime RelativeTime::operator- (const double secondsToSubtract) const throw()
  1070. {
  1071. return RelativeTime (seconds - secondsToSubtract);
  1072. }
  1073. const RelativeTime& RelativeTime::operator+= (const RelativeTime& timeToAdd) throw()
  1074. {
  1075. seconds += timeToAdd.seconds;
  1076. return *this;
  1077. }
  1078. const RelativeTime& RelativeTime::operator-= (const RelativeTime& timeToSubtract) throw()
  1079. {
  1080. seconds -= timeToSubtract.seconds;
  1081. return *this;
  1082. }
  1083. const RelativeTime& RelativeTime::operator+= (const double secondsToAdd) throw()
  1084. {
  1085. seconds += secondsToAdd;
  1086. return *this;
  1087. }
  1088. const RelativeTime& RelativeTime::operator-= (const double secondsToSubtract) throw()
  1089. {
  1090. seconds -= secondsToSubtract;
  1091. return *this;
  1092. }
  1093. END_JUCE_NAMESPACE
  1094. /*** End of inlined file: juce_RelativeTime.cpp ***/
  1095. /*** Start of inlined file: juce_SystemStats.cpp ***/
  1096. BEGIN_JUCE_NAMESPACE
  1097. 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. };
  17234. QuickTimeAudioFormat::QuickTimeAudioFormat()
  17235. : AudioFormat (TRANS (quickTimeFormatName), (const tchar**) quickTimeExtensions)
  17236. {
  17237. }
  17238. QuickTimeAudioFormat::~QuickTimeAudioFormat()
  17239. {
  17240. }
  17241. const Array <int> QuickTimeAudioFormat::getPossibleSampleRates()
  17242. {
  17243. return Array<int>();
  17244. }
  17245. const Array <int> QuickTimeAudioFormat::getPossibleBitDepths()
  17246. {
  17247. return Array<int>();
  17248. }
  17249. bool QuickTimeAudioFormat::canDoStereo()
  17250. {
  17251. return true;
  17252. }
  17253. bool QuickTimeAudioFormat::canDoMono()
  17254. {
  17255. return true;
  17256. }
  17257. AudioFormatReader* QuickTimeAudioFormat::createReaderFor (InputStream* sourceStream,
  17258. const bool deleteStreamIfOpeningFails)
  17259. {
  17260. ScopedPointer <QTAudioReader> r (new QTAudioReader (sourceStream, 0));
  17261. if (r->ok)
  17262. return r.release();
  17263. if (! deleteStreamIfOpeningFails)
  17264. r->input = 0;
  17265. return 0;
  17266. }
  17267. AudioFormatWriter* QuickTimeAudioFormat::createWriterFor (OutputStream* /*streamToWriteTo*/,
  17268. double /*sampleRateToUse*/,
  17269. unsigned int /*numberOfChannels*/,
  17270. int /*bitsPerSample*/,
  17271. const StringPairArray& /*metadataValues*/,
  17272. int /*qualityOptionIndex*/)
  17273. {
  17274. jassertfalse // not yet implemented!
  17275. return 0;
  17276. }
  17277. END_JUCE_NAMESPACE
  17278. #endif
  17279. /*** End of inlined file: juce_QuickTimeAudioFormat.cpp ***/
  17280. /*** Start of inlined file: juce_WavAudioFormat.cpp ***/
  17281. BEGIN_JUCE_NAMESPACE
  17282. static const char* const wavFormatName = "WAV file";
  17283. static const tchar* const wavExtensions[] = { T(".wav"), T(".bwf"), 0 };
  17284. const tchar* const WavAudioFormat::bwavDescription = T("bwav description");
  17285. const tchar* const WavAudioFormat::bwavOriginator = T("bwav originator");
  17286. const tchar* const WavAudioFormat::bwavOriginatorRef = T("bwav originator ref");
  17287. const tchar* const WavAudioFormat::bwavOriginationDate = T("bwav origination date");
  17288. const tchar* const WavAudioFormat::bwavOriginationTime = T("bwav origination time");
  17289. const tchar* const WavAudioFormat::bwavTimeReference = T("bwav time reference");
  17290. const tchar* const WavAudioFormat::bwavCodingHistory = T("bwav coding history");
  17291. const StringPairArray WavAudioFormat::createBWAVMetadata (const String& description,
  17292. const String& originator,
  17293. const String& originatorRef,
  17294. const Time& date,
  17295. const int64 timeReferenceSamples,
  17296. const String& codingHistory)
  17297. {
  17298. StringPairArray m;
  17299. m.set (bwavDescription, description);
  17300. m.set (bwavOriginator, originator);
  17301. m.set (bwavOriginatorRef, originatorRef);
  17302. m.set (bwavOriginationDate, date.formatted (T("%Y-%m-%d")));
  17303. m.set (bwavOriginationTime, date.formatted (T("%H:%M:%S")));
  17304. m.set (bwavTimeReference, String (timeReferenceSamples));
  17305. m.set (bwavCodingHistory, codingHistory);
  17306. return m;
  17307. }
  17308. #if JUCE_MSVC
  17309. #pragma pack (push, 1)
  17310. #define PACKED
  17311. #elif JUCE_GCC
  17312. #define PACKED __attribute__((packed))
  17313. #else
  17314. #define PACKED
  17315. #endif
  17316. struct BWAVChunk
  17317. {
  17318. char description [256];
  17319. char originator [32];
  17320. char originatorRef [32];
  17321. char originationDate [10];
  17322. char originationTime [8];
  17323. uint32 timeRefLow;
  17324. uint32 timeRefHigh;
  17325. uint16 version;
  17326. uint8 umid[64];
  17327. uint8 reserved[190];
  17328. char codingHistory[1];
  17329. void copyTo (StringPairArray& values) const
  17330. {
  17331. values.set (WavAudioFormat::bwavDescription, String::fromUTF8 (description, 256));
  17332. values.set (WavAudioFormat::bwavOriginator, String::fromUTF8 (originator, 32));
  17333. values.set (WavAudioFormat::bwavOriginatorRef, String::fromUTF8 (originatorRef, 32));
  17334. values.set (WavAudioFormat::bwavOriginationDate, String::fromUTF8 (originationDate, 10));
  17335. values.set (WavAudioFormat::bwavOriginationTime, String::fromUTF8 (originationTime, 8));
  17336. const uint32 timeLow = ByteOrder::swapIfBigEndian (timeRefLow);
  17337. const uint32 timeHigh = ByteOrder::swapIfBigEndian (timeRefHigh);
  17338. const int64 time = (((int64)timeHigh) << 32) + timeLow;
  17339. values.set (WavAudioFormat::bwavTimeReference, String (time));
  17340. values.set (WavAudioFormat::bwavCodingHistory, String::fromUTF8 (codingHistory));
  17341. }
  17342. static MemoryBlock createFrom (const StringPairArray& values)
  17343. {
  17344. const size_t sizeNeeded = sizeof (BWAVChunk) + values [WavAudioFormat::bwavCodingHistory].getNumBytesAsUTF8();
  17345. MemoryBlock data ((sizeNeeded + 3) & ~3);
  17346. data.fillWith (0);
  17347. BWAVChunk* b = (BWAVChunk*) data.getData();
  17348. // Allow these calls to overwrite an extra byte at the end, which is fine as long
  17349. // as they get called in the right order..
  17350. values [WavAudioFormat::bwavDescription].copyToUTF8 (b->description, 257);
  17351. values [WavAudioFormat::bwavOriginator].copyToUTF8 (b->originator, 33);
  17352. values [WavAudioFormat::bwavOriginatorRef].copyToUTF8 (b->originatorRef, 33);
  17353. values [WavAudioFormat::bwavOriginationDate].copyToUTF8 (b->originationDate, 11);
  17354. values [WavAudioFormat::bwavOriginationTime].copyToUTF8 (b->originationTime, 9);
  17355. const int64 time = values [WavAudioFormat::bwavTimeReference].getLargeIntValue();
  17356. b->timeRefLow = ByteOrder::swapIfBigEndian ((uint32) (time & 0xffffffff));
  17357. b->timeRefHigh = ByteOrder::swapIfBigEndian ((uint32) (time >> 32));
  17358. values [WavAudioFormat::bwavCodingHistory].copyToUTF8 (b->codingHistory, 0x7fffffff);
  17359. if (b->description[0] != 0
  17360. || b->originator[0] != 0
  17361. || b->originationDate[0] != 0
  17362. || b->originationTime[0] != 0
  17363. || b->codingHistory[0] != 0
  17364. || time != 0)
  17365. {
  17366. return data;
  17367. }
  17368. return MemoryBlock();
  17369. }
  17370. } PACKED;
  17371. struct SMPLChunk
  17372. {
  17373. struct SampleLoop
  17374. {
  17375. uint32 identifier;
  17376. uint32 type;
  17377. uint32 start;
  17378. uint32 end;
  17379. uint32 fraction;
  17380. uint32 playCount;
  17381. } PACKED;
  17382. uint32 manufacturer;
  17383. uint32 product;
  17384. uint32 samplePeriod;
  17385. uint32 midiUnityNote;
  17386. uint32 midiPitchFraction;
  17387. uint32 smpteFormat;
  17388. uint32 smpteOffset;
  17389. uint32 numSampleLoops;
  17390. uint32 samplerData;
  17391. SampleLoop loops[1];
  17392. void copyTo (StringPairArray& values, const int totalSize) const
  17393. {
  17394. values.set ("Manufacturer", String (ByteOrder::swapIfBigEndian (manufacturer)));
  17395. values.set ("Product", String (ByteOrder::swapIfBigEndian (product)));
  17396. values.set ("SamplePeriod", String (ByteOrder::swapIfBigEndian (samplePeriod)));
  17397. values.set ("MidiUnityNote", String (ByteOrder::swapIfBigEndian (midiUnityNote)));
  17398. values.set ("MidiPitchFraction", String (ByteOrder::swapIfBigEndian (midiPitchFraction)));
  17399. values.set ("SmpteFormat", String (ByteOrder::swapIfBigEndian (smpteFormat)));
  17400. values.set ("SmpteOffset", String (ByteOrder::swapIfBigEndian (smpteOffset)));
  17401. values.set ("NumSampleLoops", String (ByteOrder::swapIfBigEndian (numSampleLoops)));
  17402. values.set ("SamplerData", String (ByteOrder::swapIfBigEndian (samplerData)));
  17403. for (uint32 i = 0; i < numSampleLoops; ++i)
  17404. {
  17405. if ((uint8*) (loops + (i + 1)) > ((uint8*) this) + totalSize)
  17406. break;
  17407. const String prefix ("Loop" + String(i));
  17408. values.set (prefix + "Identifier", String (ByteOrder::swapIfBigEndian (loops[i].identifier)));
  17409. values.set (prefix + "Type", String (ByteOrder::swapIfBigEndian (loops[i].type)));
  17410. values.set (prefix + "Start", String (ByteOrder::swapIfBigEndian (loops[i].start)));
  17411. values.set (prefix + "End", String (ByteOrder::swapIfBigEndian (loops[i].end)));
  17412. values.set (prefix + "Fraction", String (ByteOrder::swapIfBigEndian (loops[i].fraction)));
  17413. values.set (prefix + "PlayCount", String (ByteOrder::swapIfBigEndian (loops[i].playCount)));
  17414. }
  17415. }
  17416. static MemoryBlock createFrom (const StringPairArray& values)
  17417. {
  17418. const int numLoops = jmin (64, values.getValue ("NumSampleLoops", "0").getIntValue());
  17419. if (numLoops <= 0)
  17420. return MemoryBlock();
  17421. const size_t sizeNeeded = sizeof (SMPLChunk) + (numLoops - 1) * sizeof (SampleLoop);
  17422. MemoryBlock data ((sizeNeeded + 3) & ~3);
  17423. data.fillWith (0);
  17424. SMPLChunk* s = (SMPLChunk*) data.getData();
  17425. // Allow these calls to overwrite an extra byte at the end, which is fine as long
  17426. // as they get called in the right order..
  17427. s->manufacturer = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("Manufacturer", "0").getIntValue());
  17428. s->product = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("Product", "0").getIntValue());
  17429. s->samplePeriod = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SamplePeriod", "0").getIntValue());
  17430. s->midiUnityNote = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("MidiUnityNote", "60").getIntValue());
  17431. s->midiPitchFraction = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("MidiPitchFraction", "0").getIntValue());
  17432. s->smpteFormat = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SmpteFormat", "0").getIntValue());
  17433. s->smpteOffset = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SmpteOffset", "0").getIntValue());
  17434. s->numSampleLoops = ByteOrder::swapIfBigEndian ((uint32) numLoops);
  17435. s->samplerData = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SamplerData", "0").getIntValue());
  17436. for (int i = 0; i < numLoops; ++i)
  17437. {
  17438. const String prefix ("Loop" + String(i));
  17439. s->loops[i].identifier = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Identifier", "0").getIntValue());
  17440. s->loops[i].type = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Type", "0").getIntValue());
  17441. s->loops[i].start = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Start", "0").getIntValue());
  17442. s->loops[i].end = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "End", "0").getIntValue());
  17443. s->loops[i].fraction = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Fraction", "0").getIntValue());
  17444. s->loops[i].playCount = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "PlayCount", "0").getIntValue());
  17445. }
  17446. return data;
  17447. }
  17448. } PACKED;
  17449. struct ExtensibleWavSubFormat
  17450. {
  17451. uint32 data1;
  17452. uint16 data2;
  17453. uint16 data3;
  17454. uint8 data4[8];
  17455. } PACKED;
  17456. #if JUCE_MSVC
  17457. #pragma pack (pop)
  17458. #endif
  17459. #undef PACKED
  17460. class WavAudioFormatReader : public AudioFormatReader
  17461. {
  17462. int bytesPerFrame;
  17463. int64 dataChunkStart, dataLength;
  17464. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  17465. WavAudioFormatReader (const WavAudioFormatReader&);
  17466. WavAudioFormatReader& operator= (const WavAudioFormatReader&);
  17467. public:
  17468. int64 bwavChunkStart, bwavSize;
  17469. WavAudioFormatReader (InputStream* const in)
  17470. : AudioFormatReader (in, TRANS (wavFormatName)),
  17471. dataLength (0),
  17472. bwavChunkStart (0),
  17473. bwavSize (0)
  17474. {
  17475. if (input->readInt() == chunkName ("RIFF"))
  17476. {
  17477. const uint32 len = (uint32) input->readInt();
  17478. const int64 end = input->getPosition() + len;
  17479. bool hasGotType = false;
  17480. bool hasGotData = false;
  17481. if (input->readInt() == chunkName ("WAVE"))
  17482. {
  17483. while (input->getPosition() < end
  17484. && ! input->isExhausted())
  17485. {
  17486. const int chunkType = input->readInt();
  17487. uint32 length = (uint32) input->readInt();
  17488. const int64 chunkEnd = input->getPosition() + length + (length & 1);
  17489. if (chunkType == chunkName ("fmt "))
  17490. {
  17491. // read the format chunk
  17492. const unsigned short format = input->readShort();
  17493. const short numChans = input->readShort();
  17494. sampleRate = input->readInt();
  17495. const int bytesPerSec = input->readInt();
  17496. numChannels = numChans;
  17497. bytesPerFrame = bytesPerSec / (int)sampleRate;
  17498. bitsPerSample = 8 * bytesPerFrame / numChans;
  17499. if (format == 3)
  17500. {
  17501. usesFloatingPointData = true;
  17502. }
  17503. else if (format == 0xfffe /*WAVE_FORMAT_EXTENSIBLE*/)
  17504. {
  17505. if (length < 40) // too short
  17506. {
  17507. bytesPerFrame = 0;
  17508. }
  17509. else
  17510. {
  17511. input->skipNextBytes (12); // skip over blockAlign, bitsPerSample and speakerPosition mask
  17512. ExtensibleWavSubFormat subFormat;
  17513. subFormat.data1 = input->readInt();
  17514. subFormat.data2 = input->readShort();
  17515. subFormat.data3 = input->readShort();
  17516. input->read (subFormat.data4, sizeof (subFormat.data4));
  17517. const ExtensibleWavSubFormat pcmFormat
  17518. = { 0x00000001, 0x0000, 0x0010, { 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 } };
  17519. if (memcmp (&subFormat, &pcmFormat, sizeof (subFormat)) != 0)
  17520. {
  17521. const ExtensibleWavSubFormat ambisonicFormat
  17522. = { 0x00000001, 0x0721, 0x11d3, { 0x86, 0x44, 0xC8, 0xC1, 0xCA, 0x00, 0x00, 0x00 } };
  17523. if (memcmp (&subFormat, &ambisonicFormat, sizeof (subFormat)) != 0)
  17524. bytesPerFrame = 0;
  17525. }
  17526. }
  17527. }
  17528. else if (format != 1)
  17529. {
  17530. bytesPerFrame = 0;
  17531. }
  17532. hasGotType = true;
  17533. }
  17534. else if (chunkType == chunkName ("data"))
  17535. {
  17536. // get the data chunk's position
  17537. dataLength = length;
  17538. dataChunkStart = input->getPosition();
  17539. lengthInSamples = (bytesPerFrame > 0) ? (dataLength / bytesPerFrame) : 0;
  17540. hasGotData = true;
  17541. }
  17542. else if (chunkType == chunkName ("bext"))
  17543. {
  17544. bwavChunkStart = input->getPosition();
  17545. bwavSize = length;
  17546. // Broadcast-wav extension chunk..
  17547. HeapBlock <BWAVChunk> bwav;
  17548. bwav.calloc (jmax ((size_t) length + 1, sizeof (BWAVChunk)), 1);
  17549. input->read (bwav, length);
  17550. bwav->copyTo (metadataValues);
  17551. }
  17552. else if (chunkType == chunkName ("smpl"))
  17553. {
  17554. HeapBlock <SMPLChunk> smpl;
  17555. smpl.calloc (jmax ((size_t) length + 1, sizeof (SMPLChunk)), 1);
  17556. input->read (smpl, length);
  17557. smpl->copyTo (metadataValues, length);
  17558. }
  17559. else if (chunkEnd <= input->getPosition())
  17560. {
  17561. break;
  17562. }
  17563. input->setPosition (chunkEnd);
  17564. }
  17565. }
  17566. }
  17567. }
  17568. ~WavAudioFormatReader()
  17569. {
  17570. }
  17571. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  17572. int64 startSampleInFile, int numSamples)
  17573. {
  17574. const int64 samplesAvailable = lengthInSamples - startSampleInFile;
  17575. if (samplesAvailable < numSamples)
  17576. {
  17577. for (int i = numDestChannels; --i >= 0;)
  17578. if (destSamples[i] != 0)
  17579. zeromem (destSamples[i] + startOffsetInDestBuffer, sizeof (int) * numSamples);
  17580. numSamples = (int) samplesAvailable;
  17581. }
  17582. if (numSamples <= 0)
  17583. return true;
  17584. input->setPosition (dataChunkStart + startSampleInFile * bytesPerFrame);
  17585. const int tempBufSize = 480 * 3 * 4; // (keep this a multiple of 3)
  17586. char tempBuffer [tempBufSize];
  17587. while (numSamples > 0)
  17588. {
  17589. int* left = destSamples[0];
  17590. if (left != 0)
  17591. left += startOffsetInDestBuffer;
  17592. int* right = numDestChannels > 1 ? destSamples[1] : 0;
  17593. if (right != 0)
  17594. right += startOffsetInDestBuffer;
  17595. const int numThisTime = jmin (tempBufSize / bytesPerFrame, numSamples);
  17596. const int bytesRead = input->read (tempBuffer, numThisTime * bytesPerFrame);
  17597. if (bytesRead < numThisTime * bytesPerFrame)
  17598. zeromem (tempBuffer + bytesRead, numThisTime * bytesPerFrame - bytesRead);
  17599. if (bitsPerSample == 16)
  17600. {
  17601. const short* src = (const short*) tempBuffer;
  17602. if (numChannels > 1)
  17603. {
  17604. if (left == 0)
  17605. {
  17606. for (int i = numThisTime; --i >= 0;)
  17607. {
  17608. ++src;
  17609. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17610. }
  17611. }
  17612. else if (right == 0)
  17613. {
  17614. for (int i = numThisTime; --i >= 0;)
  17615. {
  17616. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17617. ++src;
  17618. }
  17619. }
  17620. else
  17621. {
  17622. for (int i = numThisTime; --i >= 0;)
  17623. {
  17624. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17625. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17626. }
  17627. }
  17628. }
  17629. else
  17630. {
  17631. for (int i = numThisTime; --i >= 0;)
  17632. {
  17633. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17634. }
  17635. }
  17636. }
  17637. else if (bitsPerSample == 24)
  17638. {
  17639. const char* src = (const char*) tempBuffer;
  17640. if (numChannels > 1)
  17641. {
  17642. if (left == 0)
  17643. {
  17644. for (int i = numThisTime; --i >= 0;)
  17645. {
  17646. src += 3;
  17647. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  17648. src += 3;
  17649. }
  17650. }
  17651. else if (right == 0)
  17652. {
  17653. for (int i = numThisTime; --i >= 0;)
  17654. {
  17655. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  17656. src += 6;
  17657. }
  17658. }
  17659. else
  17660. {
  17661. for (int i = 0; i < numThisTime; ++i)
  17662. {
  17663. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  17664. src += 3;
  17665. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  17666. src += 3;
  17667. }
  17668. }
  17669. }
  17670. else
  17671. {
  17672. for (int i = 0; i < numThisTime; ++i)
  17673. {
  17674. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  17675. src += 3;
  17676. }
  17677. }
  17678. }
  17679. else if (bitsPerSample == 32)
  17680. {
  17681. const unsigned int* src = (const unsigned int*) tempBuffer;
  17682. unsigned int* l = (unsigned int*) left;
  17683. unsigned int* r = (unsigned int*) right;
  17684. if (numChannels > 1)
  17685. {
  17686. if (l == 0)
  17687. {
  17688. for (int i = numThisTime; --i >= 0;)
  17689. {
  17690. ++src;
  17691. *r++ = ByteOrder::swapIfBigEndian (*src++);
  17692. }
  17693. }
  17694. else if (r == 0)
  17695. {
  17696. for (int i = numThisTime; --i >= 0;)
  17697. {
  17698. *l++ = ByteOrder::swapIfBigEndian (*src++);
  17699. ++src;
  17700. }
  17701. }
  17702. else
  17703. {
  17704. for (int i = numThisTime; --i >= 0;)
  17705. {
  17706. *l++ = ByteOrder::swapIfBigEndian (*src++);
  17707. *r++ = ByteOrder::swapIfBigEndian (*src++);
  17708. }
  17709. }
  17710. }
  17711. else
  17712. {
  17713. for (int i = numThisTime; --i >= 0;)
  17714. {
  17715. *l++ = ByteOrder::swapIfBigEndian (*src++);
  17716. }
  17717. }
  17718. left = (int*)l;
  17719. right = (int*)r;
  17720. }
  17721. else if (bitsPerSample == 8)
  17722. {
  17723. const unsigned char* src = (const unsigned char*) tempBuffer;
  17724. if (numChannels > 1)
  17725. {
  17726. if (left == 0)
  17727. {
  17728. for (int i = numThisTime; --i >= 0;)
  17729. {
  17730. ++src;
  17731. *right++ = ((int) *src++ - 128) << 24;
  17732. }
  17733. }
  17734. else if (right == 0)
  17735. {
  17736. for (int i = numThisTime; --i >= 0;)
  17737. {
  17738. *left++ = ((int) *src++ - 128) << 24;
  17739. ++src;
  17740. }
  17741. }
  17742. else
  17743. {
  17744. for (int i = numThisTime; --i >= 0;)
  17745. {
  17746. *left++ = ((int) *src++ - 128) << 24;
  17747. *right++ = ((int) *src++ - 128) << 24;
  17748. }
  17749. }
  17750. }
  17751. else
  17752. {
  17753. for (int i = numThisTime; --i >= 0;)
  17754. {
  17755. *left++ = ((int)*src++ - 128) << 24;
  17756. }
  17757. }
  17758. }
  17759. startOffsetInDestBuffer += numThisTime;
  17760. numSamples -= numThisTime;
  17761. }
  17762. if (numSamples > 0)
  17763. {
  17764. for (int i = numDestChannels; --i >= 0;)
  17765. if (destSamples[i] != 0)
  17766. zeromem (destSamples[i] + startOffsetInDestBuffer,
  17767. sizeof (int) * numSamples);
  17768. }
  17769. return true;
  17770. }
  17771. juce_UseDebuggingNewOperator
  17772. };
  17773. class WavAudioFormatWriter : public AudioFormatWriter
  17774. {
  17775. MemoryBlock tempBlock, bwavChunk, smplChunk;
  17776. uint32 lengthInSamples, bytesWritten;
  17777. int64 headerPosition;
  17778. bool writeFailed;
  17779. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  17780. WavAudioFormatWriter (const WavAudioFormatWriter&);
  17781. WavAudioFormatWriter& operator= (const WavAudioFormatWriter&);
  17782. void writeHeader()
  17783. {
  17784. const bool seekedOk = output->setPosition (headerPosition);
  17785. (void) seekedOk;
  17786. // if this fails, you've given it an output stream that can't seek! It needs
  17787. // to be able to seek back to write the header
  17788. jassert (seekedOk);
  17789. const int bytesPerFrame = numChannels * bitsPerSample / 8;
  17790. output->writeInt (chunkName ("RIFF"));
  17791. output->writeInt ((int) (lengthInSamples * bytesPerFrame
  17792. + ((bwavChunk.getSize() > 0) ? (44 + bwavChunk.getSize()) : 36)));
  17793. output->writeInt (chunkName ("WAVE"));
  17794. output->writeInt (chunkName ("fmt "));
  17795. output->writeInt (16);
  17796. output->writeShort ((bitsPerSample < 32) ? (short) 1 /*WAVE_FORMAT_PCM*/
  17797. : (short) 3 /*WAVE_FORMAT_IEEE_FLOAT*/);
  17798. output->writeShort ((short) numChannels);
  17799. output->writeInt ((int) sampleRate);
  17800. output->writeInt (bytesPerFrame * (int) sampleRate);
  17801. output->writeShort ((short) bytesPerFrame);
  17802. output->writeShort ((short) bitsPerSample);
  17803. if (bwavChunk.getSize() > 0)
  17804. {
  17805. output->writeInt (chunkName ("bext"));
  17806. output->writeInt ((int) bwavChunk.getSize());
  17807. output->write (bwavChunk.getData(), (int) bwavChunk.getSize());
  17808. }
  17809. if (smplChunk.getSize() > 0)
  17810. {
  17811. output->writeInt (chunkName ("smpl"));
  17812. output->writeInt ((int) smplChunk.getSize());
  17813. output->write (smplChunk.getData(), (int) smplChunk.getSize());
  17814. }
  17815. output->writeInt (chunkName ("data"));
  17816. output->writeInt (lengthInSamples * bytesPerFrame);
  17817. usesFloatingPointData = (bitsPerSample == 32);
  17818. }
  17819. public:
  17820. WavAudioFormatWriter (OutputStream* const out,
  17821. const double sampleRate_,
  17822. const unsigned int numChannels_,
  17823. const int bits,
  17824. const StringPairArray& metadataValues)
  17825. : AudioFormatWriter (out,
  17826. TRANS (wavFormatName),
  17827. sampleRate_,
  17828. numChannels_,
  17829. bits),
  17830. lengthInSamples (0),
  17831. bytesWritten (0),
  17832. writeFailed (false)
  17833. {
  17834. if (metadataValues.size() > 0)
  17835. {
  17836. bwavChunk = BWAVChunk::createFrom (metadataValues);
  17837. smplChunk = SMPLChunk::createFrom (metadataValues);
  17838. }
  17839. headerPosition = out->getPosition();
  17840. writeHeader();
  17841. }
  17842. ~WavAudioFormatWriter()
  17843. {
  17844. writeHeader();
  17845. }
  17846. bool write (const int** data, int numSamples)
  17847. {
  17848. if (writeFailed)
  17849. return false;
  17850. const int bytes = numChannels * numSamples * bitsPerSample / 8;
  17851. tempBlock.ensureSize (bytes, false);
  17852. char* buffer = (char*) tempBlock.getData();
  17853. const int* left = data[0];
  17854. const int* right = data[1];
  17855. if (right == 0)
  17856. right = left;
  17857. if (bitsPerSample == 16)
  17858. {
  17859. short* b = (short*) buffer;
  17860. if (numChannels > 1)
  17861. {
  17862. for (int i = numSamples; --i >= 0;)
  17863. {
  17864. *b++ = (short) ByteOrder::swapIfBigEndian ((unsigned short) (*left++ >> 16));
  17865. *b++ = (short) ByteOrder::swapIfBigEndian ((unsigned short) (*right++ >> 16));
  17866. }
  17867. }
  17868. else
  17869. {
  17870. for (int i = numSamples; --i >= 0;)
  17871. {
  17872. *b++ = (short) ByteOrder::swapIfBigEndian ((unsigned short) (*left++ >> 16));
  17873. }
  17874. }
  17875. }
  17876. else if (bitsPerSample == 24)
  17877. {
  17878. char* b = (char*) buffer;
  17879. if (numChannels > 1)
  17880. {
  17881. for (int i = numSamples; --i >= 0;)
  17882. {
  17883. ByteOrder::littleEndian24BitToChars ((*left++) >> 8, b);
  17884. b += 3;
  17885. ByteOrder::littleEndian24BitToChars ((*right++) >> 8, b);
  17886. b += 3;
  17887. }
  17888. }
  17889. else
  17890. {
  17891. for (int i = numSamples; --i >= 0;)
  17892. {
  17893. ByteOrder::littleEndian24BitToChars ((*left++) >> 8, b);
  17894. b += 3;
  17895. }
  17896. }
  17897. }
  17898. else if (bitsPerSample == 32)
  17899. {
  17900. unsigned int* b = (unsigned int*) buffer;
  17901. if (numChannels > 1)
  17902. {
  17903. for (int i = numSamples; --i >= 0;)
  17904. {
  17905. *b++ = ByteOrder::swapIfBigEndian ((unsigned int) *left++);
  17906. *b++ = ByteOrder::swapIfBigEndian ((unsigned int) *right++);
  17907. }
  17908. }
  17909. else
  17910. {
  17911. for (int i = numSamples; --i >= 0;)
  17912. {
  17913. *b++ = ByteOrder::swapIfBigEndian ((unsigned int) *left++);
  17914. }
  17915. }
  17916. }
  17917. else if (bitsPerSample == 8)
  17918. {
  17919. unsigned char* b = (unsigned char*) buffer;
  17920. if (numChannels > 1)
  17921. {
  17922. for (int i = numSamples; --i >= 0;)
  17923. {
  17924. *b++ = (unsigned char) (128 + (*left++ >> 24));
  17925. *b++ = (unsigned char) (128 + (*right++ >> 24));
  17926. }
  17927. }
  17928. else
  17929. {
  17930. for (int i = numSamples; --i >= 0;)
  17931. {
  17932. *b++ = (unsigned char) (128 + (*left++ >> 24));
  17933. }
  17934. }
  17935. }
  17936. if (bytesWritten + bytes >= (uint32) 0xfff00000
  17937. || ! output->write (buffer, bytes))
  17938. {
  17939. // failed to write to disk, so let's try writing the header.
  17940. // If it's just run out of disk space, then if it does manage
  17941. // to write the header, we'll still have a useable file..
  17942. writeHeader();
  17943. writeFailed = true;
  17944. return false;
  17945. }
  17946. else
  17947. {
  17948. bytesWritten += bytes;
  17949. lengthInSamples += numSamples;
  17950. return true;
  17951. }
  17952. }
  17953. juce_UseDebuggingNewOperator
  17954. };
  17955. WavAudioFormat::WavAudioFormat()
  17956. : AudioFormat (TRANS (wavFormatName), (const tchar**) wavExtensions)
  17957. {
  17958. }
  17959. WavAudioFormat::~WavAudioFormat()
  17960. {
  17961. }
  17962. const Array <int> WavAudioFormat::getPossibleSampleRates()
  17963. {
  17964. const int rates[] = { 22050, 32000, 44100, 48000, 88200, 96000, 176400, 192000, 0 };
  17965. return Array <int> (rates);
  17966. }
  17967. const Array <int> WavAudioFormat::getPossibleBitDepths()
  17968. {
  17969. const int depths[] = { 8, 16, 24, 32, 0 };
  17970. return Array <int> (depths);
  17971. }
  17972. bool WavAudioFormat::canDoStereo()
  17973. {
  17974. return true;
  17975. }
  17976. bool WavAudioFormat::canDoMono()
  17977. {
  17978. return true;
  17979. }
  17980. AudioFormatReader* WavAudioFormat::createReaderFor (InputStream* sourceStream,
  17981. const bool deleteStreamIfOpeningFails)
  17982. {
  17983. ScopedPointer <WavAudioFormatReader> r (new WavAudioFormatReader (sourceStream));
  17984. if (r->sampleRate != 0)
  17985. return r.release();
  17986. if (! deleteStreamIfOpeningFails)
  17987. r->input = 0;
  17988. return 0;
  17989. }
  17990. AudioFormatWriter* WavAudioFormat::createWriterFor (OutputStream* out,
  17991. double sampleRate,
  17992. unsigned int numChannels,
  17993. int bitsPerSample,
  17994. const StringPairArray& metadataValues,
  17995. int /*qualityOptionIndex*/)
  17996. {
  17997. if (getPossibleBitDepths().contains (bitsPerSample))
  17998. {
  17999. return new WavAudioFormatWriter (out,
  18000. sampleRate,
  18001. numChannels,
  18002. bitsPerSample,
  18003. metadataValues);
  18004. }
  18005. return 0;
  18006. }
  18007. static bool juce_slowCopyOfWavFileWithNewMetadata (const File& file, const StringPairArray& metadata)
  18008. {
  18009. TemporaryFile tempFile (file);
  18010. WavAudioFormat wav;
  18011. ScopedPointer <AudioFormatReader> reader (wav.createReaderFor (file.createInputStream(), true));
  18012. if (reader != 0)
  18013. {
  18014. ScopedPointer <OutputStream> outStream (tempFile.getFile().createOutputStream());
  18015. if (outStream != 0)
  18016. {
  18017. ScopedPointer <AudioFormatWriter> writer (wav.createWriterFor (outStream, reader->sampleRate,
  18018. reader->numChannels, reader->bitsPerSample,
  18019. metadata, 0));
  18020. if (writer != 0)
  18021. {
  18022. outStream.release();
  18023. bool ok = writer->writeFromAudioReader (*reader, 0, -1);
  18024. writer = 0;
  18025. reader = 0;
  18026. return ok && tempFile.overwriteTargetFileWithTemporary();
  18027. }
  18028. }
  18029. }
  18030. return false;
  18031. }
  18032. bool WavAudioFormat::replaceMetadataInFile (const File& wavFile, const StringPairArray& newMetadata)
  18033. {
  18034. ScopedPointer <WavAudioFormatReader> reader ((WavAudioFormatReader*) createReaderFor (wavFile.createInputStream(), true));
  18035. if (reader != 0)
  18036. {
  18037. const int64 bwavPos = reader->bwavChunkStart;
  18038. const int64 bwavSize = reader->bwavSize;
  18039. reader = 0;
  18040. if (bwavSize > 0)
  18041. {
  18042. MemoryBlock chunk = BWAVChunk::createFrom (newMetadata);
  18043. if (chunk.getSize() <= (size_t) bwavSize)
  18044. {
  18045. // the new one will fit in the space available, so write it directly..
  18046. const int64 oldSize = wavFile.getSize();
  18047. {
  18048. ScopedPointer <FileOutputStream> out (wavFile.createOutputStream());
  18049. out->setPosition (bwavPos);
  18050. out->write (chunk.getData(), (int) chunk.getSize());
  18051. out->setPosition (oldSize);
  18052. }
  18053. jassert (wavFile.getSize() == oldSize);
  18054. return true;
  18055. }
  18056. }
  18057. }
  18058. return juce_slowCopyOfWavFileWithNewMetadata (wavFile, newMetadata);
  18059. }
  18060. END_JUCE_NAMESPACE
  18061. /*** End of inlined file: juce_WavAudioFormat.cpp ***/
  18062. /*** Start of inlined file: juce_AudioFormatReaderSource.cpp ***/
  18063. BEGIN_JUCE_NAMESPACE
  18064. AudioFormatReaderSource::AudioFormatReaderSource (AudioFormatReader* const reader_,
  18065. const bool deleteReaderWhenThisIsDeleted)
  18066. : reader (reader_),
  18067. deleteReader (deleteReaderWhenThisIsDeleted),
  18068. nextPlayPos (0),
  18069. looping (false)
  18070. {
  18071. jassert (reader != 0);
  18072. }
  18073. AudioFormatReaderSource::~AudioFormatReaderSource()
  18074. {
  18075. releaseResources();
  18076. if (deleteReader)
  18077. delete reader;
  18078. }
  18079. void AudioFormatReaderSource::setNextReadPosition (int newPosition)
  18080. {
  18081. nextPlayPos = newPosition;
  18082. }
  18083. void AudioFormatReaderSource::setLooping (const bool shouldLoop) throw()
  18084. {
  18085. looping = shouldLoop;
  18086. }
  18087. int AudioFormatReaderSource::getNextReadPosition() const
  18088. {
  18089. return (looping) ? (nextPlayPos % (int) reader->lengthInSamples)
  18090. : nextPlayPos;
  18091. }
  18092. int AudioFormatReaderSource::getTotalLength() const
  18093. {
  18094. return (int) reader->lengthInSamples;
  18095. }
  18096. void AudioFormatReaderSource::prepareToPlay (int /*samplesPerBlockExpected*/,
  18097. double /*sampleRate*/)
  18098. {
  18099. }
  18100. void AudioFormatReaderSource::releaseResources()
  18101. {
  18102. }
  18103. void AudioFormatReaderSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18104. {
  18105. if (info.numSamples > 0)
  18106. {
  18107. const int start = nextPlayPos;
  18108. if (looping)
  18109. {
  18110. const int newStart = start % (int) reader->lengthInSamples;
  18111. const int newEnd = (start + info.numSamples) % (int) reader->lengthInSamples;
  18112. if (newEnd > newStart)
  18113. {
  18114. info.buffer->readFromAudioReader (reader,
  18115. info.startSample,
  18116. newEnd - newStart,
  18117. newStart,
  18118. true, true);
  18119. }
  18120. else
  18121. {
  18122. const int endSamps = (int) reader->lengthInSamples - newStart;
  18123. info.buffer->readFromAudioReader (reader,
  18124. info.startSample,
  18125. endSamps,
  18126. newStart,
  18127. true, true);
  18128. info.buffer->readFromAudioReader (reader,
  18129. info.startSample + endSamps,
  18130. newEnd,
  18131. 0,
  18132. true, true);
  18133. }
  18134. nextPlayPos = newEnd;
  18135. }
  18136. else
  18137. {
  18138. info.buffer->readFromAudioReader (reader,
  18139. info.startSample,
  18140. info.numSamples,
  18141. start,
  18142. true, true);
  18143. nextPlayPos += info.numSamples;
  18144. }
  18145. }
  18146. }
  18147. END_JUCE_NAMESPACE
  18148. /*** End of inlined file: juce_AudioFormatReaderSource.cpp ***/
  18149. /*** Start of inlined file: juce_AudioSourcePlayer.cpp ***/
  18150. BEGIN_JUCE_NAMESPACE
  18151. AudioSourcePlayer::AudioSourcePlayer()
  18152. : source (0),
  18153. sampleRate (0),
  18154. bufferSize (0),
  18155. tempBuffer (2, 8),
  18156. lastGain (1.0f),
  18157. gain (1.0f)
  18158. {
  18159. }
  18160. AudioSourcePlayer::~AudioSourcePlayer()
  18161. {
  18162. setSource (0);
  18163. }
  18164. void AudioSourcePlayer::setSource (AudioSource* newSource)
  18165. {
  18166. if (source != newSource)
  18167. {
  18168. AudioSource* const oldSource = source;
  18169. if (newSource != 0 && bufferSize > 0 && sampleRate > 0)
  18170. newSource->prepareToPlay (bufferSize, sampleRate);
  18171. {
  18172. const ScopedLock sl (readLock);
  18173. source = newSource;
  18174. }
  18175. if (oldSource != 0)
  18176. oldSource->releaseResources();
  18177. }
  18178. }
  18179. void AudioSourcePlayer::setGain (const float newGain) throw()
  18180. {
  18181. gain = newGain;
  18182. }
  18183. void AudioSourcePlayer::audioDeviceIOCallback (const float** inputChannelData,
  18184. int totalNumInputChannels,
  18185. float** outputChannelData,
  18186. int totalNumOutputChannels,
  18187. int numSamples)
  18188. {
  18189. // these should have been prepared by audioDeviceAboutToStart()...
  18190. jassert (sampleRate > 0 && bufferSize > 0);
  18191. const ScopedLock sl (readLock);
  18192. if (source != 0)
  18193. {
  18194. AudioSourceChannelInfo info;
  18195. int i, numActiveChans = 0, numInputs = 0, numOutputs = 0;
  18196. // messy stuff needed to compact the channels down into an array
  18197. // of non-zero pointers..
  18198. for (i = 0; i < totalNumInputChannels; ++i)
  18199. {
  18200. if (inputChannelData[i] != 0)
  18201. {
  18202. inputChans [numInputs++] = inputChannelData[i];
  18203. if (numInputs >= numElementsInArray (inputChans))
  18204. break;
  18205. }
  18206. }
  18207. for (i = 0; i < totalNumOutputChannels; ++i)
  18208. {
  18209. if (outputChannelData[i] != 0)
  18210. {
  18211. outputChans [numOutputs++] = outputChannelData[i];
  18212. if (numOutputs >= numElementsInArray (outputChans))
  18213. break;
  18214. }
  18215. }
  18216. if (numInputs > numOutputs)
  18217. {
  18218. // if there aren't enough output channels for the number of
  18219. // inputs, we need to create some temporary extra ones (can't
  18220. // use the input data in case it gets written to)
  18221. tempBuffer.setSize (numInputs - numOutputs, numSamples,
  18222. false, false, true);
  18223. for (i = 0; i < numOutputs; ++i)
  18224. {
  18225. channels[numActiveChans] = outputChans[i];
  18226. memcpy (channels[numActiveChans], inputChans[i], sizeof (float) * numSamples);
  18227. ++numActiveChans;
  18228. }
  18229. for (i = numOutputs; i < numInputs; ++i)
  18230. {
  18231. channels[numActiveChans] = tempBuffer.getSampleData (i - numOutputs, 0);
  18232. memcpy (channels[numActiveChans], inputChans[i], sizeof (float) * numSamples);
  18233. ++numActiveChans;
  18234. }
  18235. }
  18236. else
  18237. {
  18238. for (i = 0; i < numInputs; ++i)
  18239. {
  18240. channels[numActiveChans] = outputChans[i];
  18241. memcpy (channels[numActiveChans], inputChans[i], sizeof (float) * numSamples);
  18242. ++numActiveChans;
  18243. }
  18244. for (i = numInputs; i < numOutputs; ++i)
  18245. {
  18246. channels[numActiveChans] = outputChans[i];
  18247. zeromem (channels[numActiveChans], sizeof (float) * numSamples);
  18248. ++numActiveChans;
  18249. }
  18250. }
  18251. AudioSampleBuffer buffer (channels, numActiveChans, numSamples);
  18252. info.buffer = &buffer;
  18253. info.startSample = 0;
  18254. info.numSamples = numSamples;
  18255. source->getNextAudioBlock (info);
  18256. for (i = info.buffer->getNumChannels(); --i >= 0;)
  18257. info.buffer->applyGainRamp (i, info.startSample, info.numSamples, lastGain, gain);
  18258. lastGain = gain;
  18259. }
  18260. else
  18261. {
  18262. for (int i = 0; i < totalNumOutputChannels; ++i)
  18263. if (outputChannelData[i] != 0)
  18264. zeromem (outputChannelData[i], sizeof (float) * numSamples);
  18265. }
  18266. }
  18267. void AudioSourcePlayer::audioDeviceAboutToStart (AudioIODevice* device)
  18268. {
  18269. sampleRate = device->getCurrentSampleRate();
  18270. bufferSize = device->getCurrentBufferSizeSamples();
  18271. zeromem (channels, sizeof (channels));
  18272. if (source != 0)
  18273. source->prepareToPlay (bufferSize, sampleRate);
  18274. }
  18275. void AudioSourcePlayer::audioDeviceStopped()
  18276. {
  18277. if (source != 0)
  18278. source->releaseResources();
  18279. sampleRate = 0.0;
  18280. bufferSize = 0;
  18281. tempBuffer.setSize (2, 8);
  18282. }
  18283. END_JUCE_NAMESPACE
  18284. /*** End of inlined file: juce_AudioSourcePlayer.cpp ***/
  18285. /*** Start of inlined file: juce_AudioTransportSource.cpp ***/
  18286. BEGIN_JUCE_NAMESPACE
  18287. AudioTransportSource::AudioTransportSource()
  18288. : source (0),
  18289. resamplerSource (0),
  18290. bufferingSource (0),
  18291. positionableSource (0),
  18292. masterSource (0),
  18293. gain (1.0f),
  18294. lastGain (1.0f),
  18295. playing (false),
  18296. stopped (true),
  18297. sampleRate (44100.0),
  18298. sourceSampleRate (0.0),
  18299. blockSize (128),
  18300. readAheadBufferSize (0),
  18301. isPrepared (false),
  18302. inputStreamEOF (false)
  18303. {
  18304. }
  18305. AudioTransportSource::~AudioTransportSource()
  18306. {
  18307. setSource (0);
  18308. releaseResources();
  18309. }
  18310. void AudioTransportSource::setSource (PositionableAudioSource* const newSource,
  18311. int readAheadBufferSize_,
  18312. double sourceSampleRateToCorrectFor)
  18313. {
  18314. if (source == newSource)
  18315. {
  18316. if (source == 0)
  18317. return;
  18318. setSource (0, 0, 0); // deselect and reselect to avoid releasing resources wrongly
  18319. }
  18320. readAheadBufferSize = readAheadBufferSize_;
  18321. sourceSampleRate = sourceSampleRateToCorrectFor;
  18322. ResamplingAudioSource* newResamplerSource = 0;
  18323. BufferingAudioSource* newBufferingSource = 0;
  18324. PositionableAudioSource* newPositionableSource = 0;
  18325. AudioSource* newMasterSource = 0;
  18326. ScopedPointer <ResamplingAudioSource> oldResamplerSource (resamplerSource);
  18327. ScopedPointer <BufferingAudioSource> oldBufferingSource (bufferingSource);
  18328. AudioSource* oldMasterSource = masterSource;
  18329. if (newSource != 0)
  18330. {
  18331. newPositionableSource = newSource;
  18332. if (readAheadBufferSize_ > 0)
  18333. newPositionableSource = newBufferingSource
  18334. = new BufferingAudioSource (newPositionableSource, false, readAheadBufferSize_);
  18335. newPositionableSource->setNextReadPosition (0);
  18336. if (sourceSampleRateToCorrectFor != 0)
  18337. newMasterSource = newResamplerSource
  18338. = new ResamplingAudioSource (newPositionableSource, false);
  18339. else
  18340. newMasterSource = newPositionableSource;
  18341. if (isPrepared)
  18342. {
  18343. if (newResamplerSource != 0 && sourceSampleRate > 0 && sampleRate > 0)
  18344. newResamplerSource->setResamplingRatio (sourceSampleRate / sampleRate);
  18345. newMasterSource->prepareToPlay (blockSize, sampleRate);
  18346. }
  18347. }
  18348. {
  18349. const ScopedLock sl (callbackLock);
  18350. source = newSource;
  18351. resamplerSource = newResamplerSource;
  18352. bufferingSource = newBufferingSource;
  18353. masterSource = newMasterSource;
  18354. positionableSource = newPositionableSource;
  18355. playing = false;
  18356. }
  18357. if (oldMasterSource != 0)
  18358. oldMasterSource->releaseResources();
  18359. }
  18360. void AudioTransportSource::start()
  18361. {
  18362. if ((! playing) && masterSource != 0)
  18363. {
  18364. {
  18365. const ScopedLock sl (callbackLock);
  18366. playing = true;
  18367. stopped = false;
  18368. inputStreamEOF = false;
  18369. }
  18370. sendChangeMessage (this);
  18371. }
  18372. }
  18373. void AudioTransportSource::stop()
  18374. {
  18375. if (playing)
  18376. {
  18377. {
  18378. const ScopedLock sl (callbackLock);
  18379. playing = false;
  18380. }
  18381. int n = 500;
  18382. while (--n >= 0 && ! stopped)
  18383. Thread::sleep (2);
  18384. sendChangeMessage (this);
  18385. }
  18386. }
  18387. void AudioTransportSource::setPosition (double newPosition)
  18388. {
  18389. if (sampleRate > 0.0)
  18390. setNextReadPosition (roundToInt (newPosition * sampleRate));
  18391. }
  18392. double AudioTransportSource::getCurrentPosition() const
  18393. {
  18394. if (sampleRate > 0.0)
  18395. return getNextReadPosition() / sampleRate;
  18396. else
  18397. return 0.0;
  18398. }
  18399. void AudioTransportSource::setNextReadPosition (int newPosition)
  18400. {
  18401. if (positionableSource != 0)
  18402. {
  18403. if (sampleRate > 0 && sourceSampleRate > 0)
  18404. newPosition = roundToInt (newPosition * sourceSampleRate / sampleRate);
  18405. positionableSource->setNextReadPosition (newPosition);
  18406. }
  18407. }
  18408. int AudioTransportSource::getNextReadPosition() const
  18409. {
  18410. if (positionableSource != 0)
  18411. {
  18412. const double ratio = (sampleRate > 0 && sourceSampleRate > 0) ? sampleRate / sourceSampleRate : 1.0;
  18413. return roundToInt (positionableSource->getNextReadPosition() * ratio);
  18414. }
  18415. return 0;
  18416. }
  18417. int AudioTransportSource::getTotalLength() const
  18418. {
  18419. const ScopedLock sl (callbackLock);
  18420. if (positionableSource != 0)
  18421. {
  18422. const double ratio = (sampleRate > 0 && sourceSampleRate > 0) ? sampleRate / sourceSampleRate : 1.0;
  18423. return roundToInt (positionableSource->getTotalLength() * ratio);
  18424. }
  18425. return 0;
  18426. }
  18427. bool AudioTransportSource::isLooping() const
  18428. {
  18429. const ScopedLock sl (callbackLock);
  18430. return positionableSource != 0
  18431. && positionableSource->isLooping();
  18432. }
  18433. void AudioTransportSource::setGain (const float newGain) throw()
  18434. {
  18435. gain = newGain;
  18436. }
  18437. void AudioTransportSource::prepareToPlay (int samplesPerBlockExpected,
  18438. double sampleRate_)
  18439. {
  18440. const ScopedLock sl (callbackLock);
  18441. sampleRate = sampleRate_;
  18442. blockSize = samplesPerBlockExpected;
  18443. if (masterSource != 0)
  18444. masterSource->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18445. if (resamplerSource != 0 && sourceSampleRate != 0)
  18446. resamplerSource->setResamplingRatio (sourceSampleRate / sampleRate);
  18447. isPrepared = true;
  18448. }
  18449. void AudioTransportSource::releaseResources()
  18450. {
  18451. const ScopedLock sl (callbackLock);
  18452. if (masterSource != 0)
  18453. masterSource->releaseResources();
  18454. isPrepared = false;
  18455. }
  18456. void AudioTransportSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18457. {
  18458. const ScopedLock sl (callbackLock);
  18459. inputStreamEOF = false;
  18460. if (masterSource != 0 && ! stopped)
  18461. {
  18462. masterSource->getNextAudioBlock (info);
  18463. if (! playing)
  18464. {
  18465. // just stopped playing, so fade out the last block..
  18466. for (int i = info.buffer->getNumChannels(); --i >= 0;)
  18467. info.buffer->applyGainRamp (i, info.startSample, jmin (256, info.numSamples), 1.0f, 0.0f);
  18468. if (info.numSamples > 256)
  18469. info.buffer->clear (info.startSample + 256, info.numSamples - 256);
  18470. }
  18471. if (positionableSource->getNextReadPosition() > positionableSource->getTotalLength() + 1
  18472. && ! positionableSource->isLooping())
  18473. {
  18474. playing = false;
  18475. inputStreamEOF = true;
  18476. sendChangeMessage (this);
  18477. }
  18478. stopped = ! playing;
  18479. for (int i = info.buffer->getNumChannels(); --i >= 0;)
  18480. {
  18481. info.buffer->applyGainRamp (i, info.startSample, info.numSamples,
  18482. lastGain, gain);
  18483. }
  18484. }
  18485. else
  18486. {
  18487. info.clearActiveBufferRegion();
  18488. stopped = true;
  18489. }
  18490. lastGain = gain;
  18491. }
  18492. END_JUCE_NAMESPACE
  18493. /*** End of inlined file: juce_AudioTransportSource.cpp ***/
  18494. /*** Start of inlined file: juce_BufferingAudioSource.cpp ***/
  18495. BEGIN_JUCE_NAMESPACE
  18496. class SharedBufferingAudioSourceThread : public DeletedAtShutdown,
  18497. public Thread,
  18498. private Timer
  18499. {
  18500. public:
  18501. SharedBufferingAudioSourceThread()
  18502. : Thread ("Audio Buffer")
  18503. {
  18504. }
  18505. ~SharedBufferingAudioSourceThread()
  18506. {
  18507. stopThread (10000);
  18508. clearSingletonInstance();
  18509. }
  18510. juce_DeclareSingleton (SharedBufferingAudioSourceThread, false)
  18511. void addSource (BufferingAudioSource* source)
  18512. {
  18513. const ScopedLock sl (lock);
  18514. if (! sources.contains ((void*) source))
  18515. {
  18516. sources.add ((void*) source);
  18517. startThread();
  18518. stopTimer();
  18519. }
  18520. notify();
  18521. }
  18522. void removeSource (BufferingAudioSource* source)
  18523. {
  18524. const ScopedLock sl (lock);
  18525. sources.removeValue ((void*) source);
  18526. if (sources.size() == 0)
  18527. startTimer (5000);
  18528. }
  18529. private:
  18530. VoidArray sources;
  18531. CriticalSection lock;
  18532. void run()
  18533. {
  18534. while (! threadShouldExit())
  18535. {
  18536. bool busy = false;
  18537. for (int i = sources.size(); --i >= 0;)
  18538. {
  18539. if (threadShouldExit())
  18540. return;
  18541. const ScopedLock sl (lock);
  18542. BufferingAudioSource* const b = (BufferingAudioSource*) sources[i];
  18543. if (b != 0 && b->readNextBufferChunk())
  18544. busy = true;
  18545. }
  18546. if (! busy)
  18547. wait (500);
  18548. }
  18549. }
  18550. void timerCallback()
  18551. {
  18552. stopTimer();
  18553. if (sources.size() == 0)
  18554. deleteInstance();
  18555. }
  18556. SharedBufferingAudioSourceThread (const SharedBufferingAudioSourceThread&);
  18557. SharedBufferingAudioSourceThread& operator= (const SharedBufferingAudioSourceThread&);
  18558. };
  18559. juce_ImplementSingleton (SharedBufferingAudioSourceThread)
  18560. BufferingAudioSource::BufferingAudioSource (PositionableAudioSource* source_,
  18561. const bool deleteSourceWhenDeleted_,
  18562. int numberOfSamplesToBuffer_)
  18563. : source (source_),
  18564. deleteSourceWhenDeleted (deleteSourceWhenDeleted_),
  18565. numberOfSamplesToBuffer (jmax (1024, numberOfSamplesToBuffer_)),
  18566. buffer (2, 0),
  18567. bufferValidStart (0),
  18568. bufferValidEnd (0),
  18569. nextPlayPos (0),
  18570. wasSourceLooping (false)
  18571. {
  18572. jassert (source_ != 0);
  18573. jassert (numberOfSamplesToBuffer_ > 1024); // not much point using this class if you're
  18574. // not using a larger buffer..
  18575. }
  18576. BufferingAudioSource::~BufferingAudioSource()
  18577. {
  18578. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18579. if (thread != 0)
  18580. thread->removeSource (this);
  18581. if (deleteSourceWhenDeleted)
  18582. delete source;
  18583. }
  18584. void BufferingAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate_)
  18585. {
  18586. source->prepareToPlay (samplesPerBlockExpected, sampleRate_);
  18587. sampleRate = sampleRate_;
  18588. buffer.setSize (2, jmax (samplesPerBlockExpected * 2, numberOfSamplesToBuffer));
  18589. buffer.clear();
  18590. bufferValidStart = 0;
  18591. bufferValidEnd = 0;
  18592. SharedBufferingAudioSourceThread::getInstance()->addSource (this);
  18593. while (bufferValidEnd - bufferValidStart < jmin (((int) sampleRate_) / 4,
  18594. buffer.getNumSamples() / 2))
  18595. {
  18596. SharedBufferingAudioSourceThread::getInstance()->notify();
  18597. Thread::sleep (5);
  18598. }
  18599. }
  18600. void BufferingAudioSource::releaseResources()
  18601. {
  18602. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18603. if (thread != 0)
  18604. thread->removeSource (this);
  18605. buffer.setSize (2, 0);
  18606. source->releaseResources();
  18607. }
  18608. void BufferingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18609. {
  18610. const ScopedLock sl (bufferStartPosLock);
  18611. const int validStart = jlimit (bufferValidStart, bufferValidEnd, nextPlayPos) - nextPlayPos;
  18612. const int validEnd = jlimit (bufferValidStart, bufferValidEnd, nextPlayPos + info.numSamples) - nextPlayPos;
  18613. if (validStart == validEnd)
  18614. {
  18615. // total cache miss
  18616. info.clearActiveBufferRegion();
  18617. }
  18618. else
  18619. {
  18620. if (validStart > 0)
  18621. info.buffer->clear (info.startSample, validStart); // partial cache miss at start
  18622. if (validEnd < info.numSamples)
  18623. info.buffer->clear (info.startSample + validEnd,
  18624. info.numSamples - validEnd); // partial cache miss at end
  18625. if (validStart < validEnd)
  18626. {
  18627. for (int chan = jmin (2, info.buffer->getNumChannels()); --chan >= 0;)
  18628. {
  18629. const int startBufferIndex = (validStart + nextPlayPos) % buffer.getNumSamples();
  18630. const int endBufferIndex = (validEnd + nextPlayPos) % buffer.getNumSamples();
  18631. if (startBufferIndex < endBufferIndex)
  18632. {
  18633. info.buffer->copyFrom (chan, info.startSample + validStart,
  18634. buffer,
  18635. chan, startBufferIndex,
  18636. validEnd - validStart);
  18637. }
  18638. else
  18639. {
  18640. const int initialSize = buffer.getNumSamples() - startBufferIndex;
  18641. info.buffer->copyFrom (chan, info.startSample + validStart,
  18642. buffer,
  18643. chan, startBufferIndex,
  18644. initialSize);
  18645. info.buffer->copyFrom (chan, info.startSample + validStart + initialSize,
  18646. buffer,
  18647. chan, 0,
  18648. (validEnd - validStart) - initialSize);
  18649. }
  18650. }
  18651. }
  18652. nextPlayPos += info.numSamples;
  18653. if (source->isLooping() && nextPlayPos > 0)
  18654. nextPlayPos %= source->getTotalLength();
  18655. }
  18656. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18657. if (thread != 0)
  18658. thread->notify();
  18659. }
  18660. int BufferingAudioSource::getNextReadPosition() const
  18661. {
  18662. return (source->isLooping() && nextPlayPos > 0)
  18663. ? nextPlayPos % source->getTotalLength()
  18664. : nextPlayPos;
  18665. }
  18666. void BufferingAudioSource::setNextReadPosition (int newPosition)
  18667. {
  18668. const ScopedLock sl (bufferStartPosLock);
  18669. nextPlayPos = newPosition;
  18670. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18671. if (thread != 0)
  18672. thread->notify();
  18673. }
  18674. bool BufferingAudioSource::readNextBufferChunk()
  18675. {
  18676. int newBVS, newBVE, sectionToReadStart, sectionToReadEnd;
  18677. {
  18678. const ScopedLock sl (bufferStartPosLock);
  18679. if (wasSourceLooping != isLooping())
  18680. {
  18681. wasSourceLooping = isLooping();
  18682. bufferValidStart = 0;
  18683. bufferValidEnd = 0;
  18684. }
  18685. newBVS = jmax (0, nextPlayPos);
  18686. newBVE = newBVS + buffer.getNumSamples() - 4;
  18687. sectionToReadStart = 0;
  18688. sectionToReadEnd = 0;
  18689. const int maxChunkSize = 2048;
  18690. if (newBVS < bufferValidStart || newBVS >= bufferValidEnd)
  18691. {
  18692. newBVE = jmin (newBVE, newBVS + maxChunkSize);
  18693. sectionToReadStart = newBVS;
  18694. sectionToReadEnd = newBVE;
  18695. bufferValidStart = 0;
  18696. bufferValidEnd = 0;
  18697. }
  18698. else if (abs (newBVS - bufferValidStart) > 512
  18699. || abs (newBVE - bufferValidEnd) > 512)
  18700. {
  18701. newBVE = jmin (newBVE, bufferValidEnd + maxChunkSize);
  18702. sectionToReadStart = bufferValidEnd;
  18703. sectionToReadEnd = newBVE;
  18704. bufferValidStart = newBVS;
  18705. bufferValidEnd = jmin (bufferValidEnd, newBVE);
  18706. }
  18707. }
  18708. if (sectionToReadStart != sectionToReadEnd)
  18709. {
  18710. const int bufferIndexStart = sectionToReadStart % buffer.getNumSamples();
  18711. const int bufferIndexEnd = sectionToReadEnd % buffer.getNumSamples();
  18712. if (bufferIndexStart < bufferIndexEnd)
  18713. {
  18714. readBufferSection (sectionToReadStart,
  18715. sectionToReadEnd - sectionToReadStart,
  18716. bufferIndexStart);
  18717. }
  18718. else
  18719. {
  18720. const int initialSize = buffer.getNumSamples() - bufferIndexStart;
  18721. readBufferSection (sectionToReadStart,
  18722. initialSize,
  18723. bufferIndexStart);
  18724. readBufferSection (sectionToReadStart + initialSize,
  18725. (sectionToReadEnd - sectionToReadStart) - initialSize,
  18726. 0);
  18727. }
  18728. const ScopedLock sl2 (bufferStartPosLock);
  18729. bufferValidStart = newBVS;
  18730. bufferValidEnd = newBVE;
  18731. return true;
  18732. }
  18733. else
  18734. {
  18735. return false;
  18736. }
  18737. }
  18738. void BufferingAudioSource::readBufferSection (int start, int length, int bufferOffset)
  18739. {
  18740. if (source->getNextReadPosition() != start)
  18741. source->setNextReadPosition (start);
  18742. AudioSourceChannelInfo info;
  18743. info.buffer = &buffer;
  18744. info.startSample = bufferOffset;
  18745. info.numSamples = length;
  18746. source->getNextAudioBlock (info);
  18747. }
  18748. END_JUCE_NAMESPACE
  18749. /*** End of inlined file: juce_BufferingAudioSource.cpp ***/
  18750. /*** Start of inlined file: juce_ChannelRemappingAudioSource.cpp ***/
  18751. BEGIN_JUCE_NAMESPACE
  18752. ChannelRemappingAudioSource::ChannelRemappingAudioSource (AudioSource* const source_,
  18753. const bool deleteSourceWhenDeleted_)
  18754. : requiredNumberOfChannels (2),
  18755. source (source_),
  18756. deleteSourceWhenDeleted (deleteSourceWhenDeleted_),
  18757. buffer (2, 16)
  18758. {
  18759. remappedInfo.buffer = &buffer;
  18760. remappedInfo.startSample = 0;
  18761. }
  18762. ChannelRemappingAudioSource::~ChannelRemappingAudioSource()
  18763. {
  18764. if (deleteSourceWhenDeleted)
  18765. delete source;
  18766. }
  18767. void ChannelRemappingAudioSource::setNumberOfChannelsToProduce (const int requiredNumberOfChannels_) throw()
  18768. {
  18769. const ScopedLock sl (lock);
  18770. requiredNumberOfChannels = requiredNumberOfChannels_;
  18771. }
  18772. void ChannelRemappingAudioSource::clearAllMappings() throw()
  18773. {
  18774. const ScopedLock sl (lock);
  18775. remappedInputs.clear();
  18776. remappedOutputs.clear();
  18777. }
  18778. void ChannelRemappingAudioSource::setInputChannelMapping (const int destIndex, const int sourceIndex) throw()
  18779. {
  18780. const ScopedLock sl (lock);
  18781. while (remappedInputs.size() < destIndex)
  18782. remappedInputs.add (-1);
  18783. remappedInputs.set (destIndex, sourceIndex);
  18784. }
  18785. void ChannelRemappingAudioSource::setOutputChannelMapping (const int sourceIndex, const int destIndex) throw()
  18786. {
  18787. const ScopedLock sl (lock);
  18788. while (remappedOutputs.size() < sourceIndex)
  18789. remappedOutputs.add (-1);
  18790. remappedOutputs.set (sourceIndex, destIndex);
  18791. }
  18792. int ChannelRemappingAudioSource::getRemappedInputChannel (const int inputChannelIndex) const throw()
  18793. {
  18794. const ScopedLock sl (lock);
  18795. if (inputChannelIndex >= 0 && inputChannelIndex < remappedInputs.size())
  18796. return remappedInputs.getUnchecked (inputChannelIndex);
  18797. return -1;
  18798. }
  18799. int ChannelRemappingAudioSource::getRemappedOutputChannel (const int outputChannelIndex) const throw()
  18800. {
  18801. const ScopedLock sl (lock);
  18802. if (outputChannelIndex >= 0 && outputChannelIndex < remappedOutputs.size())
  18803. return remappedOutputs .getUnchecked (outputChannelIndex);
  18804. return -1;
  18805. }
  18806. void ChannelRemappingAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
  18807. {
  18808. source->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18809. }
  18810. void ChannelRemappingAudioSource::releaseResources()
  18811. {
  18812. source->releaseResources();
  18813. }
  18814. void ChannelRemappingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill)
  18815. {
  18816. const ScopedLock sl (lock);
  18817. buffer.setSize (requiredNumberOfChannels, bufferToFill.numSamples, false, false, true);
  18818. const int numChans = bufferToFill.buffer->getNumChannels();
  18819. int i;
  18820. for (i = 0; i < buffer.getNumChannels(); ++i)
  18821. {
  18822. const int remappedChan = getRemappedInputChannel (i);
  18823. if (remappedChan >= 0 && remappedChan < numChans)
  18824. {
  18825. buffer.copyFrom (i, 0, *bufferToFill.buffer,
  18826. remappedChan,
  18827. bufferToFill.startSample,
  18828. bufferToFill.numSamples);
  18829. }
  18830. else
  18831. {
  18832. buffer.clear (i, 0, bufferToFill.numSamples);
  18833. }
  18834. }
  18835. remappedInfo.numSamples = bufferToFill.numSamples;
  18836. source->getNextAudioBlock (remappedInfo);
  18837. bufferToFill.clearActiveBufferRegion();
  18838. for (i = 0; i < requiredNumberOfChannels; ++i)
  18839. {
  18840. const int remappedChan = getRemappedOutputChannel (i);
  18841. if (remappedChan >= 0 && remappedChan < numChans)
  18842. {
  18843. bufferToFill.buffer->addFrom (remappedChan, bufferToFill.startSample,
  18844. buffer, i, 0, bufferToFill.numSamples);
  18845. }
  18846. }
  18847. }
  18848. XmlElement* ChannelRemappingAudioSource::createXml() const throw()
  18849. {
  18850. XmlElement* e = new XmlElement (T("MAPPINGS"));
  18851. String ins, outs;
  18852. int i;
  18853. const ScopedLock sl (lock);
  18854. for (i = 0; i < remappedInputs.size(); ++i)
  18855. ins << remappedInputs.getUnchecked(i) << T(' ');
  18856. for (i = 0; i < remappedOutputs.size(); ++i)
  18857. outs << remappedOutputs.getUnchecked(i) << T(' ');
  18858. e->setAttribute (T("inputs"), ins.trimEnd());
  18859. e->setAttribute (T("outputs"), outs.trimEnd());
  18860. return e;
  18861. }
  18862. void ChannelRemappingAudioSource::restoreFromXml (const XmlElement& e) throw()
  18863. {
  18864. if (e.hasTagName (T("MAPPINGS")))
  18865. {
  18866. const ScopedLock sl (lock);
  18867. clearAllMappings();
  18868. StringArray ins, outs;
  18869. ins.addTokens (e.getStringAttribute (T("inputs")), false);
  18870. outs.addTokens (e.getStringAttribute (T("outputs")), false);
  18871. int i;
  18872. for (i = 0; i < ins.size(); ++i)
  18873. remappedInputs.add (ins[i].getIntValue());
  18874. for (i = 0; i < outs.size(); ++i)
  18875. remappedOutputs.add (outs[i].getIntValue());
  18876. }
  18877. }
  18878. END_JUCE_NAMESPACE
  18879. /*** End of inlined file: juce_ChannelRemappingAudioSource.cpp ***/
  18880. /*** Start of inlined file: juce_IIRFilterAudioSource.cpp ***/
  18881. BEGIN_JUCE_NAMESPACE
  18882. IIRFilterAudioSource::IIRFilterAudioSource (AudioSource* const inputSource,
  18883. const bool deleteInputWhenDeleted_)
  18884. : input (inputSource),
  18885. deleteInputWhenDeleted (deleteInputWhenDeleted_)
  18886. {
  18887. jassert (inputSource != 0);
  18888. for (int i = 2; --i >= 0;)
  18889. iirFilters.add (new IIRFilter());
  18890. }
  18891. IIRFilterAudioSource::~IIRFilterAudioSource()
  18892. {
  18893. if (deleteInputWhenDeleted)
  18894. delete input;
  18895. }
  18896. void IIRFilterAudioSource::setFilterParameters (const IIRFilter& newSettings)
  18897. {
  18898. for (int i = iirFilters.size(); --i >= 0;)
  18899. iirFilters.getUnchecked(i)->copyCoefficientsFrom (newSettings);
  18900. }
  18901. void IIRFilterAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
  18902. {
  18903. input->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18904. for (int i = iirFilters.size(); --i >= 0;)
  18905. iirFilters.getUnchecked(i)->reset();
  18906. }
  18907. void IIRFilterAudioSource::releaseResources()
  18908. {
  18909. input->releaseResources();
  18910. }
  18911. void IIRFilterAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill)
  18912. {
  18913. input->getNextAudioBlock (bufferToFill);
  18914. const int numChannels = bufferToFill.buffer->getNumChannels();
  18915. while (numChannels > iirFilters.size())
  18916. iirFilters.add (new IIRFilter (*iirFilters.getUnchecked (0)));
  18917. for (int i = 0; i < numChannels; ++i)
  18918. iirFilters.getUnchecked(i)
  18919. ->processSamples (bufferToFill.buffer->getSampleData (i, bufferToFill.startSample),
  18920. bufferToFill.numSamples);
  18921. }
  18922. END_JUCE_NAMESPACE
  18923. /*** End of inlined file: juce_IIRFilterAudioSource.cpp ***/
  18924. /*** Start of inlined file: juce_MixerAudioSource.cpp ***/
  18925. BEGIN_JUCE_NAMESPACE
  18926. MixerAudioSource::MixerAudioSource()
  18927. : tempBuffer (2, 0),
  18928. currentSampleRate (0.0),
  18929. bufferSizeExpected (0)
  18930. {
  18931. }
  18932. MixerAudioSource::~MixerAudioSource()
  18933. {
  18934. removeAllInputs();
  18935. }
  18936. void MixerAudioSource::addInputSource (AudioSource* input, const bool deleteWhenRemoved)
  18937. {
  18938. if (input != 0 && ! inputs.contains (input))
  18939. {
  18940. double localRate;
  18941. int localBufferSize;
  18942. {
  18943. const ScopedLock sl (lock);
  18944. localRate = currentSampleRate;
  18945. localBufferSize = bufferSizeExpected;
  18946. }
  18947. if (localRate != 0.0)
  18948. input->prepareToPlay (localBufferSize, localRate);
  18949. const ScopedLock sl (lock);
  18950. inputsToDelete.setBit (inputs.size(), deleteWhenRemoved);
  18951. inputs.add (input);
  18952. }
  18953. }
  18954. void MixerAudioSource::removeInputSource (AudioSource* input, const bool deleteInput)
  18955. {
  18956. if (input != 0)
  18957. {
  18958. int index;
  18959. {
  18960. const ScopedLock sl (lock);
  18961. index = inputs.indexOf ((void*) input);
  18962. if (index >= 0)
  18963. {
  18964. inputsToDelete.shiftBits (index, 1);
  18965. inputs.remove (index);
  18966. }
  18967. }
  18968. if (index >= 0)
  18969. {
  18970. input->releaseResources();
  18971. if (deleteInput)
  18972. delete input;
  18973. }
  18974. }
  18975. }
  18976. void MixerAudioSource::removeAllInputs()
  18977. {
  18978. VoidArray inputsCopy;
  18979. BitArray inputsToDeleteCopy;
  18980. {
  18981. const ScopedLock sl (lock);
  18982. inputsCopy = inputs;
  18983. inputsToDeleteCopy = inputsToDelete;
  18984. }
  18985. for (int i = inputsCopy.size(); --i >= 0;)
  18986. if (inputsToDeleteCopy[i])
  18987. delete (AudioSource*) inputsCopy[i];
  18988. }
  18989. void MixerAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
  18990. {
  18991. tempBuffer.setSize (2, samplesPerBlockExpected);
  18992. const ScopedLock sl (lock);
  18993. currentSampleRate = sampleRate;
  18994. bufferSizeExpected = samplesPerBlockExpected;
  18995. for (int i = inputs.size(); --i >= 0;)
  18996. ((AudioSource*) inputs.getUnchecked(i))->prepareToPlay (samplesPerBlockExpected,
  18997. sampleRate);
  18998. }
  18999. void MixerAudioSource::releaseResources()
  19000. {
  19001. const ScopedLock sl (lock);
  19002. for (int i = inputs.size(); --i >= 0;)
  19003. ((AudioSource*) inputs.getUnchecked(i))->releaseResources();
  19004. tempBuffer.setSize (2, 0);
  19005. currentSampleRate = 0;
  19006. bufferSizeExpected = 0;
  19007. }
  19008. void MixerAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  19009. {
  19010. const ScopedLock sl (lock);
  19011. if (inputs.size() > 0)
  19012. {
  19013. ((AudioSource*) inputs.getUnchecked(0))->getNextAudioBlock (info);
  19014. if (inputs.size() > 1)
  19015. {
  19016. tempBuffer.setSize (jmax (1, info.buffer->getNumChannels()),
  19017. info.buffer->getNumSamples());
  19018. AudioSourceChannelInfo info2;
  19019. info2.buffer = &tempBuffer;
  19020. info2.numSamples = info.numSamples;
  19021. info2.startSample = 0;
  19022. for (int i = 1; i < inputs.size(); ++i)
  19023. {
  19024. ((AudioSource*) inputs.getUnchecked(i))->getNextAudioBlock (info2);
  19025. for (int chan = 0; chan < info.buffer->getNumChannels(); ++chan)
  19026. info.buffer->addFrom (chan, info.startSample, tempBuffer, chan, 0, info.numSamples);
  19027. }
  19028. }
  19029. }
  19030. else
  19031. {
  19032. info.clearActiveBufferRegion();
  19033. }
  19034. }
  19035. END_JUCE_NAMESPACE
  19036. /*** End of inlined file: juce_MixerAudioSource.cpp ***/
  19037. /*** Start of inlined file: juce_ResamplingAudioSource.cpp ***/
  19038. BEGIN_JUCE_NAMESPACE
  19039. ResamplingAudioSource::ResamplingAudioSource (AudioSource* const inputSource,
  19040. const bool deleteInputWhenDeleted_)
  19041. : input (inputSource),
  19042. deleteInputWhenDeleted (deleteInputWhenDeleted_),
  19043. ratio (1.0),
  19044. lastRatio (1.0),
  19045. buffer (2, 0),
  19046. sampsInBuffer (0)
  19047. {
  19048. jassert (input != 0);
  19049. }
  19050. ResamplingAudioSource::~ResamplingAudioSource()
  19051. {
  19052. if (deleteInputWhenDeleted)
  19053. delete input;
  19054. }
  19055. void ResamplingAudioSource::setResamplingRatio (const double samplesInPerOutputSample)
  19056. {
  19057. jassert (samplesInPerOutputSample > 0);
  19058. const ScopedLock sl (ratioLock);
  19059. ratio = jmax (0.0, samplesInPerOutputSample);
  19060. }
  19061. void ResamplingAudioSource::prepareToPlay (int samplesPerBlockExpected,
  19062. double sampleRate)
  19063. {
  19064. const ScopedLock sl (ratioLock);
  19065. input->prepareToPlay (samplesPerBlockExpected, sampleRate);
  19066. buffer.setSize (2, roundToInt (samplesPerBlockExpected * ratio) + 32);
  19067. buffer.clear();
  19068. sampsInBuffer = 0;
  19069. bufferPos = 0;
  19070. subSampleOffset = 0.0;
  19071. createLowPass (ratio);
  19072. resetFilters();
  19073. }
  19074. void ResamplingAudioSource::releaseResources()
  19075. {
  19076. input->releaseResources();
  19077. buffer.setSize (2, 0);
  19078. }
  19079. void ResamplingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  19080. {
  19081. const ScopedLock sl (ratioLock);
  19082. if (lastRatio != ratio)
  19083. {
  19084. createLowPass (ratio);
  19085. lastRatio = ratio;
  19086. }
  19087. const int sampsNeeded = roundToInt (info.numSamples * ratio) + 2;
  19088. int bufferSize = buffer.getNumSamples();
  19089. if (bufferSize < sampsNeeded + 8)
  19090. {
  19091. bufferPos %= bufferSize;
  19092. bufferSize = sampsNeeded + 32;
  19093. buffer.setSize (buffer.getNumChannels(), bufferSize, true, true);
  19094. }
  19095. bufferPos %= bufferSize;
  19096. int endOfBufferPos = bufferPos + sampsInBuffer;
  19097. while (sampsNeeded > sampsInBuffer)
  19098. {
  19099. endOfBufferPos %= bufferSize;
  19100. int numToDo = jmin (sampsNeeded - sampsInBuffer,
  19101. bufferSize - endOfBufferPos);
  19102. AudioSourceChannelInfo readInfo;
  19103. readInfo.buffer = &buffer;
  19104. readInfo.numSamples = numToDo;
  19105. readInfo.startSample = endOfBufferPos;
  19106. input->getNextAudioBlock (readInfo);
  19107. if (ratio > 1.0001)
  19108. {
  19109. // for down-sampling, pre-apply the filter..
  19110. for (int i = jmin (2, info.buffer->getNumChannels()); --i >= 0;)
  19111. applyFilter (buffer.getSampleData (i, endOfBufferPos), numToDo, filterStates[i]);
  19112. }
  19113. sampsInBuffer += numToDo;
  19114. endOfBufferPos += numToDo;
  19115. }
  19116. float* dl = info.buffer->getSampleData (0, info.startSample);
  19117. float* dr = (info.buffer->getNumChannels() > 1) ? info.buffer->getSampleData (1, info.startSample) : 0;
  19118. const float* const bl = buffer.getSampleData (0, 0);
  19119. const float* const br = buffer.getSampleData (1, 0);
  19120. int nextPos = (bufferPos + 1) % bufferSize;
  19121. for (int m = info.numSamples; --m >= 0;)
  19122. {
  19123. const float alpha = (float) subSampleOffset;
  19124. const float invAlpha = 1.0f - alpha;
  19125. *dl++ = bl [bufferPos] * invAlpha + bl [nextPos] * alpha;
  19126. if (dr != 0)
  19127. *dr++ = br [bufferPos] * invAlpha + br [nextPos] * alpha;
  19128. subSampleOffset += ratio;
  19129. jassert (sampsInBuffer > 0);
  19130. while (subSampleOffset >= 1.0)
  19131. {
  19132. if (++bufferPos >= bufferSize)
  19133. bufferPos = 0;
  19134. --sampsInBuffer;
  19135. nextPos = (bufferPos + 1) % bufferSize;
  19136. subSampleOffset -= 1.0;
  19137. }
  19138. }
  19139. if (ratio < 0.9999)
  19140. {
  19141. // for up-sampling, apply the filter after transposing..
  19142. for (int i = jmin (2, info.buffer->getNumChannels()); --i >= 0;)
  19143. applyFilter (info.buffer->getSampleData (i, info.startSample), info.numSamples, filterStates[i]);
  19144. }
  19145. else if (ratio <= 1.0001)
  19146. {
  19147. // if the filter's not currently being applied, keep it stoked with the last couple of samples to avoid discontinuities
  19148. for (int i = jmin (2, info.buffer->getNumChannels()); --i >= 0;)
  19149. {
  19150. const float* const endOfBuffer = info.buffer->getSampleData (i, info.startSample + info.numSamples - 1);
  19151. FilterState& fs = filterStates[i];
  19152. if (info.numSamples > 1)
  19153. {
  19154. fs.y2 = fs.x2 = *(endOfBuffer - 1);
  19155. }
  19156. else
  19157. {
  19158. fs.y2 = fs.y1;
  19159. fs.x2 = fs.x1;
  19160. }
  19161. fs.y1 = fs.x1 = *endOfBuffer;
  19162. }
  19163. }
  19164. jassert (sampsInBuffer >= 0);
  19165. }
  19166. void ResamplingAudioSource::createLowPass (const double frequencyRatio)
  19167. {
  19168. const double proportionalRate = (frequencyRatio > 1.0) ? 0.5 / frequencyRatio
  19169. : 0.5 * frequencyRatio;
  19170. const double n = 1.0 / tan (double_Pi * jmax (0.001, proportionalRate));
  19171. const double nSquared = n * n;
  19172. const double c1 = 1.0 / (1.0 + sqrt (2.0) * n + nSquared);
  19173. setFilterCoefficients (c1,
  19174. c1 * 2.0f,
  19175. c1,
  19176. 1.0,
  19177. c1 * 2.0 * (1.0 - nSquared),
  19178. c1 * (1.0 - sqrt (2.0) * n + nSquared));
  19179. }
  19180. void ResamplingAudioSource::setFilterCoefficients (double c1, double c2, double c3, double c4, double c5, double c6)
  19181. {
  19182. const double a = 1.0 / c4;
  19183. c1 *= a;
  19184. c2 *= a;
  19185. c3 *= a;
  19186. c5 *= a;
  19187. c6 *= a;
  19188. coefficients[0] = c1;
  19189. coefficients[1] = c2;
  19190. coefficients[2] = c3;
  19191. coefficients[3] = c4;
  19192. coefficients[4] = c5;
  19193. coefficients[5] = c6;
  19194. }
  19195. void ResamplingAudioSource::resetFilters()
  19196. {
  19197. zeromem (filterStates, sizeof (filterStates));
  19198. }
  19199. void ResamplingAudioSource::applyFilter (float* samples, int num, FilterState& fs)
  19200. {
  19201. while (--num >= 0)
  19202. {
  19203. const double in = *samples;
  19204. double out = coefficients[0] * in
  19205. + coefficients[1] * fs.x1
  19206. + coefficients[2] * fs.x2
  19207. - coefficients[4] * fs.y1
  19208. - coefficients[5] * fs.y2;
  19209. #if JUCE_INTEL
  19210. if (! (out < -1.0e-8 || out > 1.0e-8))
  19211. out = 0;
  19212. #endif
  19213. fs.x2 = fs.x1;
  19214. fs.x1 = in;
  19215. fs.y2 = fs.y1;
  19216. fs.y1 = out;
  19217. *samples++ = (float) out;
  19218. }
  19219. }
  19220. END_JUCE_NAMESPACE
  19221. /*** End of inlined file: juce_ResamplingAudioSource.cpp ***/
  19222. /*** Start of inlined file: juce_ToneGeneratorAudioSource.cpp ***/
  19223. BEGIN_JUCE_NAMESPACE
  19224. ToneGeneratorAudioSource::ToneGeneratorAudioSource()
  19225. : frequency (1000.0),
  19226. sampleRate (44100.0),
  19227. currentPhase (0.0),
  19228. phasePerSample (0.0),
  19229. amplitude (0.5f)
  19230. {
  19231. }
  19232. ToneGeneratorAudioSource::~ToneGeneratorAudioSource()
  19233. {
  19234. }
  19235. void ToneGeneratorAudioSource::setAmplitude (const float newAmplitude)
  19236. {
  19237. amplitude = newAmplitude;
  19238. }
  19239. void ToneGeneratorAudioSource::setFrequency (const double newFrequencyHz)
  19240. {
  19241. frequency = newFrequencyHz;
  19242. phasePerSample = 0.0;
  19243. }
  19244. void ToneGeneratorAudioSource::prepareToPlay (int /*samplesPerBlockExpected*/,
  19245. double sampleRate_)
  19246. {
  19247. currentPhase = 0.0;
  19248. phasePerSample = 0.0;
  19249. sampleRate = sampleRate_;
  19250. }
  19251. void ToneGeneratorAudioSource::releaseResources()
  19252. {
  19253. }
  19254. void ToneGeneratorAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  19255. {
  19256. if (phasePerSample == 0.0)
  19257. phasePerSample = double_Pi * 2.0 / (sampleRate / frequency);
  19258. for (int i = 0; i < info.numSamples; ++i)
  19259. {
  19260. const float sample = amplitude * (float) sin (currentPhase);
  19261. currentPhase += phasePerSample;
  19262. for (int j = info.buffer->getNumChannels(); --j >= 0;)
  19263. *info.buffer->getSampleData (j, info.startSample + i) = sample;
  19264. }
  19265. }
  19266. END_JUCE_NAMESPACE
  19267. /*** End of inlined file: juce_ToneGeneratorAudioSource.cpp ***/
  19268. /*** Start of inlined file: juce_AudioDeviceManager.cpp ***/
  19269. BEGIN_JUCE_NAMESPACE
  19270. AudioDeviceManager::AudioDeviceSetup::AudioDeviceSetup()
  19271. : sampleRate (0),
  19272. bufferSize (0),
  19273. useDefaultInputChannels (true),
  19274. useDefaultOutputChannels (true)
  19275. {
  19276. }
  19277. bool AudioDeviceManager::AudioDeviceSetup::operator== (const AudioDeviceManager::AudioDeviceSetup& other) const
  19278. {
  19279. return outputDeviceName == other.outputDeviceName
  19280. && inputDeviceName == other.inputDeviceName
  19281. && sampleRate == other.sampleRate
  19282. && bufferSize == other.bufferSize
  19283. && inputChannels == other.inputChannels
  19284. && useDefaultInputChannels == other.useDefaultInputChannels
  19285. && outputChannels == other.outputChannels
  19286. && useDefaultOutputChannels == other.useDefaultOutputChannels;
  19287. }
  19288. AudioDeviceManager::AudioDeviceManager()
  19289. : currentAudioDevice (0),
  19290. numInputChansNeeded (0),
  19291. numOutputChansNeeded (2),
  19292. listNeedsScanning (true),
  19293. useInputNames (false),
  19294. inputLevelMeasurementEnabledCount (0),
  19295. inputLevel (0),
  19296. tempBuffer (2, 2),
  19297. defaultMidiOutput (0),
  19298. cpuUsageMs (0),
  19299. timeToCpuScale (0)
  19300. {
  19301. callbackHandler.owner = this;
  19302. }
  19303. AudioDeviceManager::~AudioDeviceManager()
  19304. {
  19305. currentAudioDevice = 0;
  19306. defaultMidiOutput = 0;
  19307. }
  19308. void AudioDeviceManager::createDeviceTypesIfNeeded()
  19309. {
  19310. if (availableDeviceTypes.size() == 0)
  19311. {
  19312. createAudioDeviceTypes (availableDeviceTypes);
  19313. while (lastDeviceTypeConfigs.size() < availableDeviceTypes.size())
  19314. lastDeviceTypeConfigs.add (new AudioDeviceSetup());
  19315. if (availableDeviceTypes.size() > 0)
  19316. currentDeviceType = availableDeviceTypes.getUnchecked(0)->getTypeName();
  19317. }
  19318. }
  19319. const OwnedArray <AudioIODeviceType>& AudioDeviceManager::getAvailableDeviceTypes()
  19320. {
  19321. scanDevicesIfNeeded();
  19322. return availableDeviceTypes;
  19323. }
  19324. AudioIODeviceType* juce_createAudioIODeviceType_CoreAudio();
  19325. AudioIODeviceType* juce_createAudioIODeviceType_iPhoneAudio();
  19326. AudioIODeviceType* juce_createAudioIODeviceType_WASAPI();
  19327. AudioIODeviceType* juce_createAudioIODeviceType_DirectSound();
  19328. AudioIODeviceType* juce_createAudioIODeviceType_ASIO();
  19329. AudioIODeviceType* juce_createAudioIODeviceType_ALSA();
  19330. AudioIODeviceType* juce_createAudioIODeviceType_JACK();
  19331. void AudioDeviceManager::createAudioDeviceTypes (OwnedArray <AudioIODeviceType>& list)
  19332. {
  19333. #if JUCE_WINDOWS
  19334. #if JUCE_WASAPI
  19335. if (SystemStats::getOperatingSystemType() >= SystemStats::WinVista)
  19336. list.add (juce_createAudioIODeviceType_WASAPI());
  19337. #endif
  19338. #if JUCE_DIRECTSOUND
  19339. list.add (juce_createAudioIODeviceType_DirectSound());
  19340. #endif
  19341. #if JUCE_ASIO
  19342. list.add (juce_createAudioIODeviceType_ASIO());
  19343. #endif
  19344. #endif
  19345. #if JUCE_MAC
  19346. list.add (juce_createAudioIODeviceType_CoreAudio());
  19347. #endif
  19348. #if JUCE_IPHONE
  19349. list.add (juce_createAudioIODeviceType_iPhoneAudio());
  19350. #endif
  19351. #if JUCE_LINUX && JUCE_ALSA
  19352. list.add (juce_createAudioIODeviceType_ALSA());
  19353. #endif
  19354. #if JUCE_LINUX && JUCE_JACK
  19355. list.add (juce_createAudioIODeviceType_JACK());
  19356. #endif
  19357. }
  19358. const String AudioDeviceManager::initialise (const int numInputChannelsNeeded,
  19359. const int numOutputChannelsNeeded,
  19360. const XmlElement* const e,
  19361. const bool selectDefaultDeviceOnFailure,
  19362. const String& preferredDefaultDeviceName,
  19363. const AudioDeviceSetup* preferredSetupOptions)
  19364. {
  19365. scanDevicesIfNeeded();
  19366. numInputChansNeeded = numInputChannelsNeeded;
  19367. numOutputChansNeeded = numOutputChannelsNeeded;
  19368. if (e != 0 && e->hasTagName (T("DEVICESETUP")))
  19369. {
  19370. lastExplicitSettings = new XmlElement (*e);
  19371. String error;
  19372. AudioDeviceSetup setup;
  19373. if (preferredSetupOptions != 0)
  19374. setup = *preferredSetupOptions;
  19375. if (e->getStringAttribute (T("audioDeviceName")).isNotEmpty())
  19376. {
  19377. setup.inputDeviceName = setup.outputDeviceName
  19378. = e->getStringAttribute (T("audioDeviceName"));
  19379. }
  19380. else
  19381. {
  19382. setup.inputDeviceName = e->getStringAttribute (T("audioInputDeviceName"));
  19383. setup.outputDeviceName = e->getStringAttribute (T("audioOutputDeviceName"));
  19384. }
  19385. currentDeviceType = e->getStringAttribute (T("deviceType"));
  19386. if (currentDeviceType.isEmpty())
  19387. {
  19388. AudioIODeviceType* const type = findType (setup.inputDeviceName, setup.outputDeviceName);
  19389. if (type != 0)
  19390. currentDeviceType = type->getTypeName();
  19391. else if (availableDeviceTypes.size() > 0)
  19392. currentDeviceType = availableDeviceTypes[0]->getTypeName();
  19393. }
  19394. setup.bufferSize = e->getIntAttribute (T("audioDeviceBufferSize"));
  19395. setup.sampleRate = e->getDoubleAttribute (T("audioDeviceRate"));
  19396. setup.inputChannels.parseString (e->getStringAttribute (T("audioDeviceInChans"), T("11")), 2);
  19397. setup.outputChannels.parseString (e->getStringAttribute (T("audioDeviceOutChans"), T("11")), 2);
  19398. setup.useDefaultInputChannels = ! e->hasAttribute (T("audioDeviceInChans"));
  19399. setup.useDefaultOutputChannels = ! e->hasAttribute (T("audioDeviceOutChans"));
  19400. error = setAudioDeviceSetup (setup, true);
  19401. midiInsFromXml.clear();
  19402. forEachXmlChildElementWithTagName (*e, c, T("MIDIINPUT"))
  19403. midiInsFromXml.add (c->getStringAttribute (T("name")));
  19404. const StringArray allMidiIns (MidiInput::getDevices());
  19405. for (int i = allMidiIns.size(); --i >= 0;)
  19406. setMidiInputEnabled (allMidiIns[i], midiInsFromXml.contains (allMidiIns[i]));
  19407. if (error.isNotEmpty() && selectDefaultDeviceOnFailure)
  19408. error = initialise (numInputChannelsNeeded, numOutputChannelsNeeded, 0,
  19409. false, preferredDefaultDeviceName);
  19410. setDefaultMidiOutput (e->getStringAttribute (T("defaultMidiOutput")));
  19411. return error;
  19412. }
  19413. else
  19414. {
  19415. AudioDeviceSetup setup;
  19416. if (preferredSetupOptions != 0)
  19417. {
  19418. setup = *preferredSetupOptions;
  19419. }
  19420. else if (preferredDefaultDeviceName.isNotEmpty())
  19421. {
  19422. for (int j = availableDeviceTypes.size(); --j >= 0;)
  19423. {
  19424. AudioIODeviceType* const type = availableDeviceTypes.getUnchecked(j);
  19425. StringArray outs (type->getDeviceNames (false));
  19426. int i;
  19427. for (i = 0; i < outs.size(); ++i)
  19428. {
  19429. if (outs[i].matchesWildcard (preferredDefaultDeviceName, true))
  19430. {
  19431. setup.outputDeviceName = outs[i];
  19432. break;
  19433. }
  19434. }
  19435. StringArray ins (type->getDeviceNames (true));
  19436. for (i = 0; i < ins.size(); ++i)
  19437. {
  19438. if (ins[i].matchesWildcard (preferredDefaultDeviceName, true))
  19439. {
  19440. setup.inputDeviceName = ins[i];
  19441. break;
  19442. }
  19443. }
  19444. }
  19445. }
  19446. insertDefaultDeviceNames (setup);
  19447. return setAudioDeviceSetup (setup, false);
  19448. }
  19449. }
  19450. void AudioDeviceManager::insertDefaultDeviceNames (AudioDeviceSetup& setup) const
  19451. {
  19452. AudioIODeviceType* type = getCurrentDeviceTypeObject();
  19453. if (type != 0)
  19454. {
  19455. if (setup.outputDeviceName.isEmpty())
  19456. setup.outputDeviceName = type->getDeviceNames (false) [type->getDefaultDeviceIndex (false)];
  19457. if (setup.inputDeviceName.isEmpty())
  19458. setup.inputDeviceName = type->getDeviceNames (true) [type->getDefaultDeviceIndex (true)];
  19459. }
  19460. }
  19461. XmlElement* AudioDeviceManager::createStateXml() const
  19462. {
  19463. return lastExplicitSettings != 0 ? new XmlElement (*lastExplicitSettings) : 0;
  19464. }
  19465. void AudioDeviceManager::scanDevicesIfNeeded()
  19466. {
  19467. if (listNeedsScanning)
  19468. {
  19469. listNeedsScanning = false;
  19470. createDeviceTypesIfNeeded();
  19471. for (int i = availableDeviceTypes.size(); --i >= 0;)
  19472. availableDeviceTypes.getUnchecked(i)->scanForDevices();
  19473. }
  19474. }
  19475. AudioIODeviceType* AudioDeviceManager::findType (const String& inputName, const String& outputName)
  19476. {
  19477. scanDevicesIfNeeded();
  19478. for (int i = availableDeviceTypes.size(); --i >= 0;)
  19479. {
  19480. AudioIODeviceType* const type = availableDeviceTypes.getUnchecked(i);
  19481. if ((inputName.isNotEmpty() && type->getDeviceNames (true).contains (inputName, true))
  19482. || (outputName.isNotEmpty() && type->getDeviceNames (false).contains (outputName, true)))
  19483. {
  19484. return type;
  19485. }
  19486. }
  19487. return 0;
  19488. }
  19489. void AudioDeviceManager::getAudioDeviceSetup (AudioDeviceSetup& setup)
  19490. {
  19491. setup = currentSetup;
  19492. }
  19493. void AudioDeviceManager::deleteCurrentDevice()
  19494. {
  19495. currentAudioDevice = 0;
  19496. currentSetup.inputDeviceName = String::empty;
  19497. currentSetup.outputDeviceName = String::empty;
  19498. }
  19499. void AudioDeviceManager::setCurrentAudioDeviceType (const String& type,
  19500. const bool treatAsChosenDevice)
  19501. {
  19502. for (int i = 0; i < availableDeviceTypes.size(); ++i)
  19503. {
  19504. if (availableDeviceTypes.getUnchecked(i)->getTypeName() == type
  19505. && currentDeviceType != type)
  19506. {
  19507. currentDeviceType = type;
  19508. AudioDeviceSetup s (*lastDeviceTypeConfigs.getUnchecked(i));
  19509. insertDefaultDeviceNames (s);
  19510. setAudioDeviceSetup (s, treatAsChosenDevice);
  19511. sendChangeMessage (this);
  19512. break;
  19513. }
  19514. }
  19515. }
  19516. AudioIODeviceType* AudioDeviceManager::getCurrentDeviceTypeObject() const
  19517. {
  19518. for (int i = 0; i < availableDeviceTypes.size(); ++i)
  19519. if (availableDeviceTypes[i]->getTypeName() == currentDeviceType)
  19520. return availableDeviceTypes[i];
  19521. return availableDeviceTypes[0];
  19522. }
  19523. const String AudioDeviceManager::setAudioDeviceSetup (const AudioDeviceSetup& newSetup,
  19524. const bool treatAsChosenDevice)
  19525. {
  19526. jassert (&newSetup != &currentSetup); // this will have no effect
  19527. if (newSetup == currentSetup && currentAudioDevice != 0)
  19528. return String::empty;
  19529. if (! (newSetup == currentSetup))
  19530. sendChangeMessage (this);
  19531. stopDevice();
  19532. const String newInputDeviceName (numInputChansNeeded == 0 ? String::empty : newSetup.inputDeviceName);
  19533. const String newOutputDeviceName (numOutputChansNeeded == 0 ? String::empty : newSetup.outputDeviceName);
  19534. String error;
  19535. AudioIODeviceType* type = getCurrentDeviceTypeObject();
  19536. if (type == 0 || (newInputDeviceName.isEmpty() && newOutputDeviceName.isEmpty()))
  19537. {
  19538. deleteCurrentDevice();
  19539. if (treatAsChosenDevice)
  19540. updateXml();
  19541. return String::empty;
  19542. }
  19543. if (currentSetup.inputDeviceName != newInputDeviceName
  19544. || currentSetup.outputDeviceName != newOutputDeviceName
  19545. || currentAudioDevice == 0)
  19546. {
  19547. deleteCurrentDevice();
  19548. scanDevicesIfNeeded();
  19549. if (newOutputDeviceName.isNotEmpty()
  19550. && ! type->getDeviceNames (false).contains (newOutputDeviceName))
  19551. {
  19552. return "No such device: " + newOutputDeviceName;
  19553. }
  19554. if (newInputDeviceName.isNotEmpty()
  19555. && ! type->getDeviceNames (true).contains (newInputDeviceName))
  19556. {
  19557. return "No such device: " + newInputDeviceName;
  19558. }
  19559. currentAudioDevice = type->createDevice (newOutputDeviceName, newInputDeviceName);
  19560. if (currentAudioDevice == 0)
  19561. 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!";
  19562. else
  19563. error = currentAudioDevice->getLastError();
  19564. if (error.isNotEmpty())
  19565. {
  19566. deleteCurrentDevice();
  19567. return error;
  19568. }
  19569. if (newSetup.useDefaultInputChannels)
  19570. {
  19571. inputChannels.clear();
  19572. inputChannels.setRange (0, numInputChansNeeded, true);
  19573. }
  19574. if (newSetup.useDefaultOutputChannels)
  19575. {
  19576. outputChannels.clear();
  19577. outputChannels.setRange (0, numOutputChansNeeded, true);
  19578. }
  19579. if (newInputDeviceName.isEmpty())
  19580. inputChannels.clear();
  19581. if (newOutputDeviceName.isEmpty())
  19582. outputChannels.clear();
  19583. }
  19584. if (! newSetup.useDefaultInputChannels)
  19585. inputChannels = newSetup.inputChannels;
  19586. if (! newSetup.useDefaultOutputChannels)
  19587. outputChannels = newSetup.outputChannels;
  19588. currentSetup = newSetup;
  19589. currentSetup.sampleRate = chooseBestSampleRate (newSetup.sampleRate);
  19590. error = currentAudioDevice->open (inputChannels,
  19591. outputChannels,
  19592. currentSetup.sampleRate,
  19593. currentSetup.bufferSize);
  19594. if (error.isEmpty())
  19595. {
  19596. currentDeviceType = currentAudioDevice->getTypeName();
  19597. currentAudioDevice->start (&callbackHandler);
  19598. currentSetup.sampleRate = currentAudioDevice->getCurrentSampleRate();
  19599. currentSetup.bufferSize = currentAudioDevice->getCurrentBufferSizeSamples();
  19600. currentSetup.inputChannels = currentAudioDevice->getActiveInputChannels();
  19601. currentSetup.outputChannels = currentAudioDevice->getActiveOutputChannels();
  19602. for (int i = 0; i < availableDeviceTypes.size(); ++i)
  19603. if (availableDeviceTypes.getUnchecked (i)->getTypeName() == currentDeviceType)
  19604. *(lastDeviceTypeConfigs.getUnchecked (i)) = currentSetup;
  19605. if (treatAsChosenDevice)
  19606. updateXml();
  19607. }
  19608. else
  19609. {
  19610. deleteCurrentDevice();
  19611. }
  19612. return error;
  19613. }
  19614. double AudioDeviceManager::chooseBestSampleRate (double rate) const
  19615. {
  19616. jassert (currentAudioDevice != 0);
  19617. if (rate > 0)
  19618. {
  19619. bool ok = false;
  19620. for (int i = currentAudioDevice->getNumSampleRates(); --i >= 0;)
  19621. {
  19622. const double sr = currentAudioDevice->getSampleRate (i);
  19623. if (sr == rate)
  19624. ok = true;
  19625. }
  19626. if (! ok)
  19627. rate = 0;
  19628. }
  19629. if (rate == 0)
  19630. {
  19631. double lowestAbove44 = 0.0;
  19632. for (int i = currentAudioDevice->getNumSampleRates(); --i >= 0;)
  19633. {
  19634. const double sr = currentAudioDevice->getSampleRate (i);
  19635. if (sr >= 44100.0 && (lowestAbove44 == 0 || sr < lowestAbove44))
  19636. lowestAbove44 = sr;
  19637. }
  19638. if (lowestAbove44 == 0.0)
  19639. rate = currentAudioDevice->getSampleRate (0);
  19640. else
  19641. rate = lowestAbove44;
  19642. }
  19643. return rate;
  19644. }
  19645. void AudioDeviceManager::stopDevice()
  19646. {
  19647. if (currentAudioDevice != 0)
  19648. currentAudioDevice->stop();
  19649. testSound = 0;
  19650. }
  19651. void AudioDeviceManager::closeAudioDevice()
  19652. {
  19653. stopDevice();
  19654. currentAudioDevice = 0;
  19655. }
  19656. void AudioDeviceManager::restartLastAudioDevice()
  19657. {
  19658. if (currentAudioDevice == 0)
  19659. {
  19660. if (currentSetup.inputDeviceName.isEmpty()
  19661. && currentSetup.outputDeviceName.isEmpty())
  19662. {
  19663. // This method will only reload the last device that was running
  19664. // before closeAudioDevice() was called - you need to actually open
  19665. // one first, with setAudioDevice().
  19666. jassertfalse
  19667. return;
  19668. }
  19669. AudioDeviceSetup s (currentSetup);
  19670. setAudioDeviceSetup (s, false);
  19671. }
  19672. }
  19673. void AudioDeviceManager::updateXml()
  19674. {
  19675. lastExplicitSettings = new XmlElement ("DEVICESETUP");
  19676. lastExplicitSettings->setAttribute ("deviceType", currentDeviceType);
  19677. lastExplicitSettings->setAttribute ("audioOutputDeviceName", currentSetup.outputDeviceName);
  19678. lastExplicitSettings->setAttribute ("audioInputDeviceName", currentSetup.inputDeviceName);
  19679. if (currentAudioDevice != 0)
  19680. {
  19681. lastExplicitSettings->setAttribute ("audioDeviceRate", currentAudioDevice->getCurrentSampleRate());
  19682. if (currentAudioDevice->getDefaultBufferSize() != currentAudioDevice->getCurrentBufferSizeSamples())
  19683. lastExplicitSettings->setAttribute ("audioDeviceBufferSize", currentAudioDevice->getCurrentBufferSizeSamples());
  19684. if (! currentSetup.useDefaultInputChannels)
  19685. lastExplicitSettings->setAttribute ("audioDeviceInChans", currentSetup.inputChannels.toString (2));
  19686. if (! currentSetup.useDefaultOutputChannels)
  19687. lastExplicitSettings->setAttribute ("audioDeviceOutChans", currentSetup.outputChannels.toString (2));
  19688. }
  19689. for (int i = 0; i < enabledMidiInputs.size(); ++i)
  19690. {
  19691. XmlElement* const m = lastExplicitSettings->createNewChildElement ("MIDIINPUT");
  19692. m->setAttribute ("name", enabledMidiInputs[i]->getName());
  19693. }
  19694. if (midiInsFromXml.size() > 0)
  19695. {
  19696. // Add any midi devices that have been enabled before, but which aren't currently
  19697. // open because the device has been disconnected.
  19698. const StringArray availableMidiDevices (MidiInput::getDevices());
  19699. for (int i = 0; i < midiInsFromXml.size(); ++i)
  19700. {
  19701. if (! availableMidiDevices.contains (midiInsFromXml[i], true))
  19702. {
  19703. XmlElement* const m = lastExplicitSettings->createNewChildElement ("MIDIINPUT");
  19704. m->setAttribute ("name", midiInsFromXml[i]);
  19705. }
  19706. }
  19707. }
  19708. if (defaultMidiOutputName.isNotEmpty())
  19709. lastExplicitSettings->setAttribute ("defaultMidiOutput", defaultMidiOutputName);
  19710. }
  19711. void AudioDeviceManager::addAudioCallback (AudioIODeviceCallback* newCallback)
  19712. {
  19713. {
  19714. const ScopedLock sl (audioCallbackLock);
  19715. if (callbacks.contains (newCallback))
  19716. return;
  19717. }
  19718. if (currentAudioDevice != 0 && newCallback != 0)
  19719. newCallback->audioDeviceAboutToStart (currentAudioDevice);
  19720. const ScopedLock sl (audioCallbackLock);
  19721. callbacks.add (newCallback);
  19722. }
  19723. void AudioDeviceManager::removeAudioCallback (AudioIODeviceCallback* callback)
  19724. {
  19725. if (callback != 0)
  19726. {
  19727. bool needsDeinitialising = currentAudioDevice != 0;
  19728. {
  19729. const ScopedLock sl (audioCallbackLock);
  19730. needsDeinitialising = needsDeinitialising && callbacks.contains (callback);
  19731. callbacks.removeValue (callback);
  19732. }
  19733. if (needsDeinitialising)
  19734. callback->audioDeviceStopped();
  19735. }
  19736. }
  19737. void AudioDeviceManager::audioDeviceIOCallbackInt (const float** inputChannelData,
  19738. int numInputChannels,
  19739. float** outputChannelData,
  19740. int numOutputChannels,
  19741. int numSamples)
  19742. {
  19743. const ScopedLock sl (audioCallbackLock);
  19744. if (inputLevelMeasurementEnabledCount > 0)
  19745. {
  19746. for (int j = 0; j < numSamples; ++j)
  19747. {
  19748. float s = 0;
  19749. for (int i = 0; i < numInputChannels; ++i)
  19750. s += fabsf (inputChannelData[i][j]);
  19751. s /= numInputChannels;
  19752. const double decayFactor = 0.99992;
  19753. if (s > inputLevel)
  19754. inputLevel = s;
  19755. else if (inputLevel > 0.001f)
  19756. inputLevel *= decayFactor;
  19757. else
  19758. inputLevel = 0;
  19759. }
  19760. }
  19761. if (callbacks.size() > 0)
  19762. {
  19763. const double callbackStartTime = Time::getMillisecondCounterHiRes();
  19764. tempBuffer.setSize (jmax (1, numOutputChannels), jmax (1, numSamples), false, false, true);
  19765. callbacks.getUnchecked(0)->audioDeviceIOCallback (inputChannelData, numInputChannels,
  19766. outputChannelData, numOutputChannels, numSamples);
  19767. float** const tempChans = tempBuffer.getArrayOfChannels();
  19768. for (int i = callbacks.size(); --i > 0;)
  19769. {
  19770. callbacks.getUnchecked(i)->audioDeviceIOCallback (inputChannelData, numInputChannels,
  19771. tempChans, numOutputChannels, numSamples);
  19772. for (int chan = 0; chan < numOutputChannels; ++chan)
  19773. {
  19774. const float* const src = tempChans [chan];
  19775. float* const dst = outputChannelData [chan];
  19776. if (src != 0 && dst != 0)
  19777. for (int j = 0; j < numSamples; ++j)
  19778. dst[j] += src[j];
  19779. }
  19780. }
  19781. const double msTaken = Time::getMillisecondCounterHiRes() - callbackStartTime;
  19782. const double filterAmount = 0.2;
  19783. cpuUsageMs += filterAmount * (msTaken - cpuUsageMs);
  19784. }
  19785. else
  19786. {
  19787. for (int i = 0; i < numOutputChannels; ++i)
  19788. zeromem (outputChannelData[i], sizeof (float) * numSamples);
  19789. }
  19790. if (testSound != 0)
  19791. {
  19792. const int numSamps = jmin (numSamples, testSound->getNumSamples() - testSoundPosition);
  19793. const float* const src = testSound->getSampleData (0, testSoundPosition);
  19794. for (int i = 0; i < numOutputChannels; ++i)
  19795. for (int j = 0; j < numSamps; ++j)
  19796. outputChannelData [i][j] += src[j];
  19797. testSoundPosition += numSamps;
  19798. if (testSoundPosition >= testSound->getNumSamples())
  19799. testSound = 0;
  19800. }
  19801. }
  19802. void AudioDeviceManager::audioDeviceAboutToStartInt (AudioIODevice* const device)
  19803. {
  19804. cpuUsageMs = 0;
  19805. const double sampleRate = device->getCurrentSampleRate();
  19806. const int blockSize = device->getCurrentBufferSizeSamples();
  19807. if (sampleRate > 0.0 && blockSize > 0)
  19808. {
  19809. const double msPerBlock = 1000.0 * blockSize / sampleRate;
  19810. timeToCpuScale = (msPerBlock > 0.0) ? (1.0 / msPerBlock) : 0.0;
  19811. }
  19812. {
  19813. const ScopedLock sl (audioCallbackLock);
  19814. for (int i = callbacks.size(); --i >= 0;)
  19815. callbacks.getUnchecked(i)->audioDeviceAboutToStart (device);
  19816. }
  19817. sendChangeMessage (this);
  19818. }
  19819. void AudioDeviceManager::audioDeviceStoppedInt()
  19820. {
  19821. cpuUsageMs = 0;
  19822. timeToCpuScale = 0;
  19823. sendChangeMessage (this);
  19824. const ScopedLock sl (audioCallbackLock);
  19825. for (int i = callbacks.size(); --i >= 0;)
  19826. callbacks.getUnchecked(i)->audioDeviceStopped();
  19827. }
  19828. double AudioDeviceManager::getCpuUsage() const
  19829. {
  19830. return jlimit (0.0, 1.0, timeToCpuScale * cpuUsageMs);
  19831. }
  19832. void AudioDeviceManager::setMidiInputEnabled (const String& name,
  19833. const bool enabled)
  19834. {
  19835. if (enabled != isMidiInputEnabled (name))
  19836. {
  19837. if (enabled)
  19838. {
  19839. const int index = MidiInput::getDevices().indexOf (name);
  19840. if (index >= 0)
  19841. {
  19842. MidiInput* const min = MidiInput::openDevice (index, &callbackHandler);
  19843. if (min != 0)
  19844. {
  19845. enabledMidiInputs.add (min);
  19846. min->start();
  19847. }
  19848. }
  19849. }
  19850. else
  19851. {
  19852. for (int i = enabledMidiInputs.size(); --i >= 0;)
  19853. if (enabledMidiInputs[i]->getName() == name)
  19854. enabledMidiInputs.remove (i);
  19855. }
  19856. updateXml();
  19857. sendChangeMessage (this);
  19858. }
  19859. }
  19860. bool AudioDeviceManager::isMidiInputEnabled (const String& name) const
  19861. {
  19862. for (int i = enabledMidiInputs.size(); --i >= 0;)
  19863. if (enabledMidiInputs[i]->getName() == name)
  19864. return true;
  19865. return false;
  19866. }
  19867. void AudioDeviceManager::addMidiInputCallback (const String& name,
  19868. MidiInputCallback* callback)
  19869. {
  19870. removeMidiInputCallback (name, callback);
  19871. if (name.isEmpty())
  19872. {
  19873. midiCallbacks.add (callback);
  19874. midiCallbackDevices.add (0);
  19875. }
  19876. else
  19877. {
  19878. for (int i = enabledMidiInputs.size(); --i >= 0;)
  19879. {
  19880. if (enabledMidiInputs[i]->getName() == name)
  19881. {
  19882. const ScopedLock sl (midiCallbackLock);
  19883. midiCallbacks.add (callback);
  19884. midiCallbackDevices.add (enabledMidiInputs[i]);
  19885. break;
  19886. }
  19887. }
  19888. }
  19889. }
  19890. void AudioDeviceManager::removeMidiInputCallback (const String& name,
  19891. MidiInputCallback* /*callback*/)
  19892. {
  19893. const ScopedLock sl (midiCallbackLock);
  19894. for (int i = midiCallbacks.size(); --i >= 0;)
  19895. {
  19896. String devName;
  19897. if (midiCallbackDevices.getUnchecked(i) != 0)
  19898. devName = midiCallbackDevices.getUnchecked(i)->getName();
  19899. if (devName == name)
  19900. {
  19901. midiCallbacks.remove (i);
  19902. midiCallbackDevices.remove (i);
  19903. }
  19904. }
  19905. }
  19906. void AudioDeviceManager::handleIncomingMidiMessageInt (MidiInput* source,
  19907. const MidiMessage& message)
  19908. {
  19909. if (! message.isActiveSense())
  19910. {
  19911. const bool isDefaultSource = (source == 0 || source == enabledMidiInputs.getFirst());
  19912. const ScopedLock sl (midiCallbackLock);
  19913. for (int i = midiCallbackDevices.size(); --i >= 0;)
  19914. {
  19915. MidiInput* const md = midiCallbackDevices.getUnchecked(i);
  19916. if (md == source || (md == 0 && isDefaultSource))
  19917. midiCallbacks.getUnchecked(i)->handleIncomingMidiMessage (source, message);
  19918. }
  19919. }
  19920. }
  19921. void AudioDeviceManager::setDefaultMidiOutput (const String& deviceName)
  19922. {
  19923. if (defaultMidiOutputName != deviceName)
  19924. {
  19925. SortedSet <AudioIODeviceCallback*> oldCallbacks;
  19926. {
  19927. const ScopedLock sl (audioCallbackLock);
  19928. oldCallbacks = callbacks;
  19929. callbacks.clear();
  19930. }
  19931. if (currentAudioDevice != 0)
  19932. for (int i = oldCallbacks.size(); --i >= 0;)
  19933. oldCallbacks.getUnchecked(i)->audioDeviceStopped();
  19934. defaultMidiOutput = 0;
  19935. defaultMidiOutputName = deviceName;
  19936. if (deviceName.isNotEmpty())
  19937. defaultMidiOutput = MidiOutput::openDevice (MidiOutput::getDevices().indexOf (deviceName));
  19938. if (currentAudioDevice != 0)
  19939. for (int i = oldCallbacks.size(); --i >= 0;)
  19940. oldCallbacks.getUnchecked(i)->audioDeviceAboutToStart (currentAudioDevice);
  19941. {
  19942. const ScopedLock sl (audioCallbackLock);
  19943. callbacks = oldCallbacks;
  19944. }
  19945. updateXml();
  19946. sendChangeMessage (this);
  19947. }
  19948. }
  19949. void AudioDeviceManager::CallbackHandler::audioDeviceIOCallback (const float** inputChannelData,
  19950. int numInputChannels,
  19951. float** outputChannelData,
  19952. int numOutputChannels,
  19953. int numSamples)
  19954. {
  19955. owner->audioDeviceIOCallbackInt (inputChannelData, numInputChannels, outputChannelData, numOutputChannels, numSamples);
  19956. }
  19957. void AudioDeviceManager::CallbackHandler::audioDeviceAboutToStart (AudioIODevice* device)
  19958. {
  19959. owner->audioDeviceAboutToStartInt (device);
  19960. }
  19961. void AudioDeviceManager::CallbackHandler::audioDeviceStopped()
  19962. {
  19963. owner->audioDeviceStoppedInt();
  19964. }
  19965. void AudioDeviceManager::CallbackHandler::handleIncomingMidiMessage (MidiInput* source, const MidiMessage& message)
  19966. {
  19967. owner->handleIncomingMidiMessageInt (source, message);
  19968. }
  19969. void AudioDeviceManager::playTestSound()
  19970. {
  19971. { // cunningly nested to swap, unlock and delete in that order.
  19972. ScopedPointer <AudioSampleBuffer> oldSound;
  19973. {
  19974. const ScopedLock sl (audioCallbackLock);
  19975. oldSound = testSound;
  19976. }
  19977. }
  19978. testSoundPosition = 0;
  19979. if (currentAudioDevice != 0)
  19980. {
  19981. const double sampleRate = currentAudioDevice->getCurrentSampleRate();
  19982. const int soundLength = (int) sampleRate;
  19983. AudioSampleBuffer* const newSound = new AudioSampleBuffer (1, soundLength);
  19984. float* samples = newSound->getSampleData (0);
  19985. const double frequency = MidiMessage::getMidiNoteInHertz (80);
  19986. const float amplitude = 0.5f;
  19987. const double phasePerSample = double_Pi * 2.0 / (sampleRate / frequency);
  19988. for (int i = 0; i < soundLength; ++i)
  19989. samples[i] = amplitude * (float) sin (i * phasePerSample);
  19990. newSound->applyGainRamp (0, 0, soundLength / 10, 0.0f, 1.0f);
  19991. newSound->applyGainRamp (0, soundLength - soundLength / 4, soundLength / 4, 1.0f, 0.0f);
  19992. const ScopedLock sl (audioCallbackLock);
  19993. testSound = newSound;
  19994. }
  19995. }
  19996. void AudioDeviceManager::enableInputLevelMeasurement (const bool enableMeasurement)
  19997. {
  19998. const ScopedLock sl (audioCallbackLock);
  19999. if (enableMeasurement)
  20000. ++inputLevelMeasurementEnabledCount;
  20001. else
  20002. --inputLevelMeasurementEnabledCount;
  20003. inputLevel = 0;
  20004. }
  20005. double AudioDeviceManager::getCurrentInputLevel() const
  20006. {
  20007. jassert (inputLevelMeasurementEnabledCount > 0); // you need to call enableInputLevelMeasurement() before using this!
  20008. return inputLevel;
  20009. }
  20010. END_JUCE_NAMESPACE
  20011. /*** End of inlined file: juce_AudioDeviceManager.cpp ***/
  20012. /*** Start of inlined file: juce_AudioIODevice.cpp ***/
  20013. BEGIN_JUCE_NAMESPACE
  20014. AudioIODevice::AudioIODevice (const String& deviceName, const String& typeName_)
  20015. : name (deviceName),
  20016. typeName (typeName_)
  20017. {
  20018. }
  20019. AudioIODevice::~AudioIODevice()
  20020. {
  20021. }
  20022. bool AudioIODevice::hasControlPanel() const
  20023. {
  20024. return false;
  20025. }
  20026. bool AudioIODevice::showControlPanel()
  20027. {
  20028. jassertfalse // this should only be called for devices which return true from
  20029. // their hasControlPanel() method.
  20030. return false;
  20031. }
  20032. END_JUCE_NAMESPACE
  20033. /*** End of inlined file: juce_AudioIODevice.cpp ***/
  20034. /*** Start of inlined file: juce_AudioIODeviceType.cpp ***/
  20035. BEGIN_JUCE_NAMESPACE
  20036. AudioIODeviceType::AudioIODeviceType (const tchar* const name)
  20037. : typeName (name)
  20038. {
  20039. }
  20040. AudioIODeviceType::~AudioIODeviceType()
  20041. {
  20042. }
  20043. END_JUCE_NAMESPACE
  20044. /*** End of inlined file: juce_AudioIODeviceType.cpp ***/
  20045. /*** Start of inlined file: juce_MidiOutput.cpp ***/
  20046. BEGIN_JUCE_NAMESPACE
  20047. MidiOutput::MidiOutput() throw()
  20048. : Thread ("midi out"),
  20049. internal (0),
  20050. firstMessage (0)
  20051. {
  20052. }
  20053. MidiOutput::PendingMessage::PendingMessage (const uint8* const data,
  20054. const int len,
  20055. const double sampleNumber) throw()
  20056. : message (data, len, sampleNumber)
  20057. {
  20058. }
  20059. void MidiOutput::sendBlockOfMessages (const MidiBuffer& buffer,
  20060. const double millisecondCounterToStartAt,
  20061. double samplesPerSecondForBuffer) throw()
  20062. {
  20063. // You've got to call startBackgroundThread() for this to actually work..
  20064. jassert (isThreadRunning());
  20065. // this needs to be a value in the future - RTFM for this method!
  20066. jassert (millisecondCounterToStartAt > 0);
  20067. const double timeScaleFactor = 1000.0 / samplesPerSecondForBuffer;
  20068. MidiBuffer::Iterator i (buffer);
  20069. const uint8* data;
  20070. int len, time;
  20071. while (i.getNextEvent (data, len, time))
  20072. {
  20073. const double eventTime = millisecondCounterToStartAt + timeScaleFactor * time;
  20074. PendingMessage* const m
  20075. = new PendingMessage (data, len, eventTime);
  20076. const ScopedLock sl (lock);
  20077. if (firstMessage == 0 || firstMessage->message.getTimeStamp() > eventTime)
  20078. {
  20079. m->next = firstMessage;
  20080. firstMessage = m;
  20081. }
  20082. else
  20083. {
  20084. PendingMessage* mm = firstMessage;
  20085. while (mm->next != 0 && mm->next->message.getTimeStamp() <= eventTime)
  20086. mm = mm->next;
  20087. m->next = mm->next;
  20088. mm->next = m;
  20089. }
  20090. }
  20091. notify();
  20092. }
  20093. void MidiOutput::clearAllPendingMessages() throw()
  20094. {
  20095. const ScopedLock sl (lock);
  20096. while (firstMessage != 0)
  20097. {
  20098. PendingMessage* const m = firstMessage;
  20099. firstMessage = firstMessage->next;
  20100. delete m;
  20101. }
  20102. }
  20103. void MidiOutput::startBackgroundThread() throw()
  20104. {
  20105. startThread (9);
  20106. }
  20107. void MidiOutput::stopBackgroundThread() throw()
  20108. {
  20109. stopThread (5000);
  20110. }
  20111. void MidiOutput::run()
  20112. {
  20113. while (! threadShouldExit())
  20114. {
  20115. uint32 now = Time::getMillisecondCounter();
  20116. uint32 eventTime = 0;
  20117. uint32 timeToWait = 500;
  20118. PendingMessage* message;
  20119. {
  20120. const ScopedLock sl (lock);
  20121. message = firstMessage;
  20122. if (message != 0)
  20123. {
  20124. eventTime = roundToInt (message->message.getTimeStamp());
  20125. if (eventTime > now + 20)
  20126. {
  20127. timeToWait = eventTime - (now + 20);
  20128. message = 0;
  20129. }
  20130. else
  20131. {
  20132. firstMessage = message->next;
  20133. }
  20134. }
  20135. }
  20136. if (message != 0)
  20137. {
  20138. if (eventTime > now)
  20139. {
  20140. Time::waitForMillisecondCounter (eventTime);
  20141. if (threadShouldExit())
  20142. break;
  20143. }
  20144. if (eventTime > now - 200)
  20145. sendMessageNow (message->message);
  20146. delete message;
  20147. }
  20148. else
  20149. {
  20150. jassert (timeToWait < 1000 * 30);
  20151. wait (timeToWait);
  20152. }
  20153. }
  20154. clearAllPendingMessages();
  20155. }
  20156. END_JUCE_NAMESPACE
  20157. /*** End of inlined file: juce_MidiOutput.cpp ***/
  20158. /*** Start of inlined file: juce_AudioDataConverters.cpp ***/
  20159. BEGIN_JUCE_NAMESPACE
  20160. void AudioDataConverters::convertFloatToInt16LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20161. {
  20162. const double maxVal = (double) 0x7fff;
  20163. char* intData = (char*) dest;
  20164. if (dest != (void*) source || destBytesPerSample <= 4)
  20165. {
  20166. for (int i = 0; i < numSamples; ++i)
  20167. {
  20168. *(uint16*)intData = ByteOrder::swapIfBigEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20169. intData += destBytesPerSample;
  20170. }
  20171. }
  20172. else
  20173. {
  20174. intData += destBytesPerSample * numSamples;
  20175. for (int i = numSamples; --i >= 0;)
  20176. {
  20177. intData -= destBytesPerSample;
  20178. *(uint16*)intData = ByteOrder::swapIfBigEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20179. }
  20180. }
  20181. }
  20182. void AudioDataConverters::convertFloatToInt16BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20183. {
  20184. const double maxVal = (double) 0x7fff;
  20185. char* intData = (char*) dest;
  20186. if (dest != (void*) source || destBytesPerSample <= 4)
  20187. {
  20188. for (int i = 0; i < numSamples; ++i)
  20189. {
  20190. *(uint16*) intData = ByteOrder::swapIfLittleEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20191. intData += destBytesPerSample;
  20192. }
  20193. }
  20194. else
  20195. {
  20196. intData += destBytesPerSample * numSamples;
  20197. for (int i = numSamples; --i >= 0;)
  20198. {
  20199. intData -= destBytesPerSample;
  20200. *(uint16*)intData = ByteOrder::swapIfLittleEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20201. }
  20202. }
  20203. }
  20204. void AudioDataConverters::convertFloatToInt24LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20205. {
  20206. const double maxVal = (double) 0x7fffff;
  20207. char* intData = (char*) dest;
  20208. if (dest != (void*) source || destBytesPerSample <= 4)
  20209. {
  20210. for (int i = 0; i < numSamples; ++i)
  20211. {
  20212. ByteOrder::littleEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20213. intData += destBytesPerSample;
  20214. }
  20215. }
  20216. else
  20217. {
  20218. intData += destBytesPerSample * numSamples;
  20219. for (int i = numSamples; --i >= 0;)
  20220. {
  20221. intData -= destBytesPerSample;
  20222. ByteOrder::littleEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20223. }
  20224. }
  20225. }
  20226. void AudioDataConverters::convertFloatToInt24BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20227. {
  20228. const double maxVal = (double) 0x7fffff;
  20229. char* intData = (char*) dest;
  20230. if (dest != (void*) source || destBytesPerSample <= 4)
  20231. {
  20232. for (int i = 0; i < numSamples; ++i)
  20233. {
  20234. ByteOrder::bigEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20235. intData += destBytesPerSample;
  20236. }
  20237. }
  20238. else
  20239. {
  20240. intData += destBytesPerSample * numSamples;
  20241. for (int i = numSamples; --i >= 0;)
  20242. {
  20243. intData -= destBytesPerSample;
  20244. ByteOrder::bigEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20245. }
  20246. }
  20247. }
  20248. void AudioDataConverters::convertFloatToInt32LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20249. {
  20250. const double maxVal = (double) 0x7fffffff;
  20251. char* intData = (char*) dest;
  20252. if (dest != (void*) source || destBytesPerSample <= 4)
  20253. {
  20254. for (int i = 0; i < numSamples; ++i)
  20255. {
  20256. *(uint32*)intData = ByteOrder::swapIfBigEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20257. intData += destBytesPerSample;
  20258. }
  20259. }
  20260. else
  20261. {
  20262. intData += destBytesPerSample * numSamples;
  20263. for (int i = numSamples; --i >= 0;)
  20264. {
  20265. intData -= destBytesPerSample;
  20266. *(uint32*)intData = ByteOrder::swapIfBigEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20267. }
  20268. }
  20269. }
  20270. void AudioDataConverters::convertFloatToInt32BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20271. {
  20272. const double maxVal = (double) 0x7fffffff;
  20273. char* intData = (char*) dest;
  20274. if (dest != (void*) source || destBytesPerSample <= 4)
  20275. {
  20276. for (int i = 0; i < numSamples; ++i)
  20277. {
  20278. *(uint32*)intData = ByteOrder::swapIfLittleEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20279. intData += destBytesPerSample;
  20280. }
  20281. }
  20282. else
  20283. {
  20284. intData += destBytesPerSample * numSamples;
  20285. for (int i = numSamples; --i >= 0;)
  20286. {
  20287. intData -= destBytesPerSample;
  20288. *(uint32*)intData = ByteOrder::swapIfLittleEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20289. }
  20290. }
  20291. }
  20292. void AudioDataConverters::convertFloatToFloat32LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20293. {
  20294. jassert (dest != (void*) source || destBytesPerSample <= 4); // This op can't be performed on in-place data!
  20295. char* d = (char*) dest;
  20296. for (int i = 0; i < numSamples; ++i)
  20297. {
  20298. *(float*) d = source[i];
  20299. #if JUCE_BIG_ENDIAN
  20300. *(uint32*) d = ByteOrder::swap (*(uint32*) d);
  20301. #endif
  20302. d += destBytesPerSample;
  20303. }
  20304. }
  20305. void AudioDataConverters::convertFloatToFloat32BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20306. {
  20307. jassert (dest != (void*) source || destBytesPerSample <= 4); // This op can't be performed on in-place data!
  20308. char* d = (char*) dest;
  20309. for (int i = 0; i < numSamples; ++i)
  20310. {
  20311. *(float*) d = source[i];
  20312. #if JUCE_LITTLE_ENDIAN
  20313. *(uint32*) d = ByteOrder::swap (*(uint32*) d);
  20314. #endif
  20315. d += destBytesPerSample;
  20316. }
  20317. }
  20318. void AudioDataConverters::convertInt16LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20319. {
  20320. const float scale = 1.0f / 0x7fff;
  20321. const char* intData = (const char*) source;
  20322. if (source != (void*) dest || srcBytesPerSample >= 4)
  20323. {
  20324. for (int i = 0; i < numSamples; ++i)
  20325. {
  20326. dest[i] = scale * (short) ByteOrder::swapIfBigEndian (*(uint16*)intData);
  20327. intData += srcBytesPerSample;
  20328. }
  20329. }
  20330. else
  20331. {
  20332. intData += srcBytesPerSample * numSamples;
  20333. for (int i = numSamples; --i >= 0;)
  20334. {
  20335. intData -= srcBytesPerSample;
  20336. dest[i] = scale * (short) ByteOrder::swapIfBigEndian (*(uint16*)intData);
  20337. }
  20338. }
  20339. }
  20340. void AudioDataConverters::convertInt16BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20341. {
  20342. const float scale = 1.0f / 0x7fff;
  20343. const char* intData = (const char*) source;
  20344. if (source != (void*) dest || srcBytesPerSample >= 4)
  20345. {
  20346. for (int i = 0; i < numSamples; ++i)
  20347. {
  20348. dest[i] = scale * (short) ByteOrder::swapIfLittleEndian (*(uint16*)intData);
  20349. intData += srcBytesPerSample;
  20350. }
  20351. }
  20352. else
  20353. {
  20354. intData += srcBytesPerSample * numSamples;
  20355. for (int i = numSamples; --i >= 0;)
  20356. {
  20357. intData -= srcBytesPerSample;
  20358. dest[i] = scale * (short) ByteOrder::swapIfLittleEndian (*(uint16*)intData);
  20359. }
  20360. }
  20361. }
  20362. void AudioDataConverters::convertInt24LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20363. {
  20364. const float scale = 1.0f / 0x7fffff;
  20365. const char* intData = (const char*) source;
  20366. if (source != (void*) dest || srcBytesPerSample >= 4)
  20367. {
  20368. for (int i = 0; i < numSamples; ++i)
  20369. {
  20370. dest[i] = scale * (short) ByteOrder::littleEndian24Bit (intData);
  20371. intData += srcBytesPerSample;
  20372. }
  20373. }
  20374. else
  20375. {
  20376. intData += srcBytesPerSample * numSamples;
  20377. for (int i = numSamples; --i >= 0;)
  20378. {
  20379. intData -= srcBytesPerSample;
  20380. dest[i] = scale * (short) ByteOrder::littleEndian24Bit (intData);
  20381. }
  20382. }
  20383. }
  20384. void AudioDataConverters::convertInt24BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20385. {
  20386. const float scale = 1.0f / 0x7fffff;
  20387. const char* intData = (const char*) source;
  20388. if (source != (void*) dest || srcBytesPerSample >= 4)
  20389. {
  20390. for (int i = 0; i < numSamples; ++i)
  20391. {
  20392. dest[i] = scale * (short) ByteOrder::bigEndian24Bit (intData);
  20393. intData += srcBytesPerSample;
  20394. }
  20395. }
  20396. else
  20397. {
  20398. intData += srcBytesPerSample * numSamples;
  20399. for (int i = numSamples; --i >= 0;)
  20400. {
  20401. intData -= srcBytesPerSample;
  20402. dest[i] = scale * (short) ByteOrder::bigEndian24Bit (intData);
  20403. }
  20404. }
  20405. }
  20406. void AudioDataConverters::convertInt32LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20407. {
  20408. const float scale = 1.0f / 0x7fffffff;
  20409. const char* intData = (const char*) source;
  20410. if (source != (void*) dest || srcBytesPerSample >= 4)
  20411. {
  20412. for (int i = 0; i < numSamples; ++i)
  20413. {
  20414. dest[i] = scale * (int) ByteOrder::swapIfBigEndian (*(uint32*) intData);
  20415. intData += srcBytesPerSample;
  20416. }
  20417. }
  20418. else
  20419. {
  20420. intData += srcBytesPerSample * numSamples;
  20421. for (int i = numSamples; --i >= 0;)
  20422. {
  20423. intData -= srcBytesPerSample;
  20424. dest[i] = scale * (int) ByteOrder::swapIfBigEndian (*(uint32*) intData);
  20425. }
  20426. }
  20427. }
  20428. void AudioDataConverters::convertInt32BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20429. {
  20430. const float scale = 1.0f / 0x7fffffff;
  20431. const char* intData = (const char*) source;
  20432. if (source != (void*) dest || srcBytesPerSample >= 4)
  20433. {
  20434. for (int i = 0; i < numSamples; ++i)
  20435. {
  20436. dest[i] = scale * (int) ByteOrder::swapIfLittleEndian (*(uint32*) intData);
  20437. intData += srcBytesPerSample;
  20438. }
  20439. }
  20440. else
  20441. {
  20442. intData += srcBytesPerSample * numSamples;
  20443. for (int i = numSamples; --i >= 0;)
  20444. {
  20445. intData -= srcBytesPerSample;
  20446. dest[i] = scale * (int) ByteOrder::swapIfLittleEndian (*(uint32*) intData);
  20447. }
  20448. }
  20449. }
  20450. void AudioDataConverters::convertFloat32LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20451. {
  20452. const char* s = (const char*) source;
  20453. for (int i = 0; i < numSamples; ++i)
  20454. {
  20455. dest[i] = *(float*)s;
  20456. #if JUCE_BIG_ENDIAN
  20457. uint32* const d = (uint32*) (dest + i);
  20458. *d = ByteOrder::swap (*d);
  20459. #endif
  20460. s += srcBytesPerSample;
  20461. }
  20462. }
  20463. void AudioDataConverters::convertFloat32BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20464. {
  20465. const char* s = (const char*) source;
  20466. for (int i = 0; i < numSamples; ++i)
  20467. {
  20468. dest[i] = *(float*)s;
  20469. #if JUCE_LITTLE_ENDIAN
  20470. uint32* const d = (uint32*) (dest + i);
  20471. *d = ByteOrder::swap (*d);
  20472. #endif
  20473. s += srcBytesPerSample;
  20474. }
  20475. }
  20476. void AudioDataConverters::convertFloatToFormat (const DataFormat destFormat,
  20477. const float* const source,
  20478. void* const dest,
  20479. const int numSamples)
  20480. {
  20481. switch (destFormat)
  20482. {
  20483. case int16LE:
  20484. convertFloatToInt16LE (source, dest, numSamples);
  20485. break;
  20486. case int16BE:
  20487. convertFloatToInt16BE (source, dest, numSamples);
  20488. break;
  20489. case int24LE:
  20490. convertFloatToInt24LE (source, dest, numSamples);
  20491. break;
  20492. case int24BE:
  20493. convertFloatToInt24BE (source, dest, numSamples);
  20494. break;
  20495. case int32LE:
  20496. convertFloatToInt32LE (source, dest, numSamples);
  20497. break;
  20498. case int32BE:
  20499. convertFloatToInt32BE (source, dest, numSamples);
  20500. break;
  20501. case float32LE:
  20502. convertFloatToFloat32LE (source, dest, numSamples);
  20503. break;
  20504. case float32BE:
  20505. convertFloatToFloat32BE (source, dest, numSamples);
  20506. break;
  20507. default:
  20508. jassertfalse
  20509. break;
  20510. }
  20511. }
  20512. void AudioDataConverters::convertFormatToFloat (const DataFormat sourceFormat,
  20513. const void* const source,
  20514. float* const dest,
  20515. const int numSamples)
  20516. {
  20517. switch (sourceFormat)
  20518. {
  20519. case int16LE:
  20520. convertInt16LEToFloat (source, dest, numSamples);
  20521. break;
  20522. case int16BE:
  20523. convertInt16BEToFloat (source, dest, numSamples);
  20524. break;
  20525. case int24LE:
  20526. convertInt24LEToFloat (source, dest, numSamples);
  20527. break;
  20528. case int24BE:
  20529. convertInt24BEToFloat (source, dest, numSamples);
  20530. break;
  20531. case int32LE:
  20532. convertInt32LEToFloat (source, dest, numSamples);
  20533. break;
  20534. case int32BE:
  20535. convertInt32BEToFloat (source, dest, numSamples);
  20536. break;
  20537. case float32LE:
  20538. convertFloat32LEToFloat (source, dest, numSamples);
  20539. break;
  20540. case float32BE:
  20541. convertFloat32BEToFloat (source, dest, numSamples);
  20542. break;
  20543. default:
  20544. jassertfalse
  20545. break;
  20546. }
  20547. }
  20548. void AudioDataConverters::interleaveSamples (const float** const source,
  20549. float* const dest,
  20550. const int numSamples,
  20551. const int numChannels)
  20552. {
  20553. for (int chan = 0; chan < numChannels; ++chan)
  20554. {
  20555. int i = chan;
  20556. const float* src = source [chan];
  20557. for (int j = 0; j < numSamples; ++j)
  20558. {
  20559. dest [i] = src [j];
  20560. i += numChannels;
  20561. }
  20562. }
  20563. }
  20564. void AudioDataConverters::deinterleaveSamples (const float* const source,
  20565. float** const dest,
  20566. const int numSamples,
  20567. const int numChannels)
  20568. {
  20569. for (int chan = 0; chan < numChannels; ++chan)
  20570. {
  20571. int i = chan;
  20572. float* dst = dest [chan];
  20573. for (int j = 0; j < numSamples; ++j)
  20574. {
  20575. dst [j] = source [i];
  20576. i += numChannels;
  20577. }
  20578. }
  20579. }
  20580. END_JUCE_NAMESPACE
  20581. /*** End of inlined file: juce_AudioDataConverters.cpp ***/
  20582. /*** Start of inlined file: juce_AudioSampleBuffer.cpp ***/
  20583. BEGIN_JUCE_NAMESPACE
  20584. AudioSampleBuffer::AudioSampleBuffer (const int numChannels_,
  20585. const int numSamples) throw()
  20586. : numChannels (numChannels_),
  20587. size (numSamples)
  20588. {
  20589. jassert (numSamples >= 0);
  20590. jassert (numChannels_ > 0);
  20591. allocateData();
  20592. }
  20593. AudioSampleBuffer::AudioSampleBuffer (const AudioSampleBuffer& other) throw()
  20594. : numChannels (other.numChannels),
  20595. size (other.size)
  20596. {
  20597. allocateData();
  20598. const size_t numBytes = size * sizeof (float);
  20599. for (int i = 0; i < numChannels; ++i)
  20600. memcpy (channels[i], other.channels[i], numBytes);
  20601. }
  20602. void AudioSampleBuffer::allocateData()
  20603. {
  20604. const size_t channelListSize = (numChannels + 1) * sizeof (float*);
  20605. allocatedBytes = (int) (numChannels * size * sizeof (float) + channelListSize + 32);
  20606. allocatedData.malloc (allocatedBytes);
  20607. channels = reinterpret_cast <float**> (allocatedData.getData());
  20608. float* chan = (float*) (allocatedData + channelListSize);
  20609. for (int i = 0; i < numChannels; ++i)
  20610. {
  20611. channels[i] = chan;
  20612. chan += size;
  20613. }
  20614. channels [numChannels] = 0;
  20615. }
  20616. AudioSampleBuffer::AudioSampleBuffer (float** dataToReferTo,
  20617. const int numChannels_,
  20618. const int numSamples) throw()
  20619. : numChannels (numChannels_),
  20620. size (numSamples),
  20621. allocatedBytes (0)
  20622. {
  20623. jassert (numChannels_ > 0);
  20624. allocateChannels (dataToReferTo);
  20625. }
  20626. void AudioSampleBuffer::setDataToReferTo (float** dataToReferTo,
  20627. const int newNumChannels,
  20628. const int newNumSamples) throw()
  20629. {
  20630. jassert (newNumChannels > 0);
  20631. allocatedBytes = 0;
  20632. allocatedData.free();
  20633. numChannels = newNumChannels;
  20634. size = newNumSamples;
  20635. allocateChannels (dataToReferTo);
  20636. }
  20637. void AudioSampleBuffer::allocateChannels (float** const dataToReferTo)
  20638. {
  20639. // (try to avoid doing a malloc here, as that'll blow up things like Pro-Tools)
  20640. if (numChannels < numElementsInArray (preallocatedChannelSpace))
  20641. {
  20642. channels = static_cast <float**> (preallocatedChannelSpace);
  20643. }
  20644. else
  20645. {
  20646. allocatedData.malloc (numChannels + 1, sizeof (float*));
  20647. channels = reinterpret_cast <float**> (allocatedData.getData());
  20648. }
  20649. for (int i = 0; i < numChannels; ++i)
  20650. {
  20651. // you have to pass in the same number of valid pointers as numChannels
  20652. jassert (dataToReferTo[i] != 0);
  20653. channels[i] = dataToReferTo[i];
  20654. }
  20655. channels [numChannels] = 0;
  20656. }
  20657. AudioSampleBuffer& AudioSampleBuffer::operator= (const AudioSampleBuffer& other) throw()
  20658. {
  20659. if (this != &other)
  20660. {
  20661. setSize (other.getNumChannels(), other.getNumSamples(), false, false, false);
  20662. const size_t numBytes = size * sizeof (float);
  20663. for (int i = 0; i < numChannels; ++i)
  20664. memcpy (channels[i], other.channels[i], numBytes);
  20665. }
  20666. return *this;
  20667. }
  20668. AudioSampleBuffer::~AudioSampleBuffer() throw()
  20669. {
  20670. }
  20671. void AudioSampleBuffer::setSize (const int newNumChannels,
  20672. const int newNumSamples,
  20673. const bool keepExistingContent,
  20674. const bool clearExtraSpace,
  20675. const bool avoidReallocating) throw()
  20676. {
  20677. jassert (newNumChannels > 0);
  20678. if (newNumSamples != size || newNumChannels != numChannels)
  20679. {
  20680. const size_t channelListSize = (newNumChannels + 1) * sizeof (float*);
  20681. const size_t newTotalBytes = (newNumChannels * newNumSamples * sizeof (float)) + channelListSize + 32;
  20682. if (keepExistingContent)
  20683. {
  20684. HeapBlock <char> newData;
  20685. newData.allocate (newTotalBytes, clearExtraSpace);
  20686. const int numChansToCopy = jmin (numChannels, newNumChannels);
  20687. const size_t numBytesToCopy = sizeof (float) * jmin (newNumSamples, size);
  20688. float** const newChannels = reinterpret_cast <float**> (newData.getData());
  20689. float* newChan = reinterpret_cast <float*> (newData + channelListSize);
  20690. for (int i = 0; i < numChansToCopy; ++i)
  20691. {
  20692. memcpy (newChan, channels[i], numBytesToCopy);
  20693. newChannels[i] = newChan;
  20694. newChan += newNumSamples;
  20695. }
  20696. allocatedData.swapWith (newData);
  20697. allocatedBytes = (int) newTotalBytes;
  20698. channels = newChannels;
  20699. }
  20700. else
  20701. {
  20702. if (avoidReallocating && allocatedBytes >= newTotalBytes)
  20703. {
  20704. if (clearExtraSpace)
  20705. zeromem (allocatedData, newTotalBytes);
  20706. }
  20707. else
  20708. {
  20709. allocatedBytes = newTotalBytes;
  20710. allocatedData.allocate (newTotalBytes, clearExtraSpace);
  20711. channels = reinterpret_cast <float**> (allocatedData.getData());
  20712. }
  20713. float* chan = reinterpret_cast <float*> (allocatedData + channelListSize);
  20714. for (int i = 0; i < newNumChannels; ++i)
  20715. {
  20716. channels[i] = chan;
  20717. chan += newNumSamples;
  20718. }
  20719. }
  20720. channels [newNumChannels] = 0;
  20721. size = newNumSamples;
  20722. numChannels = newNumChannels;
  20723. }
  20724. }
  20725. void AudioSampleBuffer::clear() throw()
  20726. {
  20727. for (int i = 0; i < numChannels; ++i)
  20728. zeromem (channels[i], size * sizeof (float));
  20729. }
  20730. void AudioSampleBuffer::clear (const int startSample,
  20731. const int numSamples) throw()
  20732. {
  20733. jassert (startSample >= 0 && startSample + numSamples <= size);
  20734. for (int i = 0; i < numChannels; ++i)
  20735. zeromem (channels [i] + startSample, numSamples * sizeof (float));
  20736. }
  20737. void AudioSampleBuffer::clear (const int channel,
  20738. const int startSample,
  20739. const int numSamples) throw()
  20740. {
  20741. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20742. jassert (startSample >= 0 && startSample + numSamples <= size);
  20743. zeromem (channels [channel] + startSample, numSamples * sizeof (float));
  20744. }
  20745. void AudioSampleBuffer::applyGain (const int channel,
  20746. const int startSample,
  20747. int numSamples,
  20748. const float gain) throw()
  20749. {
  20750. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20751. jassert (startSample >= 0 && startSample + numSamples <= size);
  20752. if (gain != 1.0f)
  20753. {
  20754. float* d = channels [channel] + startSample;
  20755. if (gain == 0.0f)
  20756. {
  20757. zeromem (d, sizeof (float) * numSamples);
  20758. }
  20759. else
  20760. {
  20761. while (--numSamples >= 0)
  20762. *d++ *= gain;
  20763. }
  20764. }
  20765. }
  20766. void AudioSampleBuffer::applyGainRamp (const int channel,
  20767. const int startSample,
  20768. int numSamples,
  20769. float startGain,
  20770. float endGain) throw()
  20771. {
  20772. if (startGain == endGain)
  20773. {
  20774. applyGain (channel, startSample, numSamples, startGain);
  20775. }
  20776. else
  20777. {
  20778. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20779. jassert (startSample >= 0 && startSample + numSamples <= size);
  20780. const float increment = (endGain - startGain) / numSamples;
  20781. float* d = channels [channel] + startSample;
  20782. while (--numSamples >= 0)
  20783. {
  20784. *d++ *= startGain;
  20785. startGain += increment;
  20786. }
  20787. }
  20788. }
  20789. void AudioSampleBuffer::applyGain (const int startSample,
  20790. const int numSamples,
  20791. const float gain) throw()
  20792. {
  20793. for (int i = 0; i < numChannels; ++i)
  20794. applyGain (i, startSample, numSamples, gain);
  20795. }
  20796. void AudioSampleBuffer::addFrom (const int destChannel,
  20797. const int destStartSample,
  20798. const AudioSampleBuffer& source,
  20799. const int sourceChannel,
  20800. const int sourceStartSample,
  20801. int numSamples,
  20802. const float gain) throw()
  20803. {
  20804. jassert (&source != this || sourceChannel != destChannel);
  20805. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20806. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20807. jassert (((unsigned int) sourceChannel) < (unsigned int) source.numChannels);
  20808. jassert (sourceStartSample >= 0 && sourceStartSample + numSamples <= source.size);
  20809. if (gain != 0.0f && numSamples > 0)
  20810. {
  20811. float* d = channels [destChannel] + destStartSample;
  20812. const float* s = source.channels [sourceChannel] + sourceStartSample;
  20813. if (gain != 1.0f)
  20814. {
  20815. while (--numSamples >= 0)
  20816. *d++ += gain * *s++;
  20817. }
  20818. else
  20819. {
  20820. while (--numSamples >= 0)
  20821. *d++ += *s++;
  20822. }
  20823. }
  20824. }
  20825. void AudioSampleBuffer::addFrom (const int destChannel,
  20826. const int destStartSample,
  20827. const float* source,
  20828. int numSamples,
  20829. const float gain) throw()
  20830. {
  20831. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20832. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20833. jassert (source != 0);
  20834. if (gain != 0.0f && numSamples > 0)
  20835. {
  20836. float* d = channels [destChannel] + destStartSample;
  20837. if (gain != 1.0f)
  20838. {
  20839. while (--numSamples >= 0)
  20840. *d++ += gain * *source++;
  20841. }
  20842. else
  20843. {
  20844. while (--numSamples >= 0)
  20845. *d++ += *source++;
  20846. }
  20847. }
  20848. }
  20849. void AudioSampleBuffer::addFromWithRamp (const int destChannel,
  20850. const int destStartSample,
  20851. const float* source,
  20852. int numSamples,
  20853. float startGain,
  20854. const float endGain) throw()
  20855. {
  20856. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20857. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20858. jassert (source != 0);
  20859. if (startGain == endGain)
  20860. {
  20861. addFrom (destChannel,
  20862. destStartSample,
  20863. source,
  20864. numSamples,
  20865. startGain);
  20866. }
  20867. else
  20868. {
  20869. if (numSamples > 0 && (startGain != 0.0f || endGain != 0.0f))
  20870. {
  20871. const float increment = (endGain - startGain) / numSamples;
  20872. float* d = channels [destChannel] + destStartSample;
  20873. while (--numSamples >= 0)
  20874. {
  20875. *d++ += startGain * *source++;
  20876. startGain += increment;
  20877. }
  20878. }
  20879. }
  20880. }
  20881. void AudioSampleBuffer::copyFrom (const int destChannel,
  20882. const int destStartSample,
  20883. const AudioSampleBuffer& source,
  20884. const int sourceChannel,
  20885. const int sourceStartSample,
  20886. int numSamples) throw()
  20887. {
  20888. jassert (&source != this || sourceChannel != destChannel);
  20889. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20890. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20891. jassert (((unsigned int) sourceChannel) < (unsigned int) source.numChannels);
  20892. jassert (sourceStartSample >= 0 && sourceStartSample + numSamples <= source.size);
  20893. if (numSamples > 0)
  20894. {
  20895. memcpy (channels [destChannel] + destStartSample,
  20896. source.channels [sourceChannel] + sourceStartSample,
  20897. sizeof (float) * numSamples);
  20898. }
  20899. }
  20900. void AudioSampleBuffer::copyFrom (const int destChannel,
  20901. const int destStartSample,
  20902. const float* source,
  20903. int numSamples) throw()
  20904. {
  20905. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20906. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20907. jassert (source != 0);
  20908. if (numSamples > 0)
  20909. {
  20910. memcpy (channels [destChannel] + destStartSample,
  20911. source,
  20912. sizeof (float) * numSamples);
  20913. }
  20914. }
  20915. void AudioSampleBuffer::copyFrom (const int destChannel,
  20916. const int destStartSample,
  20917. const float* source,
  20918. int numSamples,
  20919. const float gain) throw()
  20920. {
  20921. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20922. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20923. jassert (source != 0);
  20924. if (numSamples > 0)
  20925. {
  20926. float* d = channels [destChannel] + destStartSample;
  20927. if (gain != 1.0f)
  20928. {
  20929. if (gain == 0)
  20930. {
  20931. zeromem (d, sizeof (float) * numSamples);
  20932. }
  20933. else
  20934. {
  20935. while (--numSamples >= 0)
  20936. *d++ = gain * *source++;
  20937. }
  20938. }
  20939. else
  20940. {
  20941. memcpy (d, source, sizeof (float) * numSamples);
  20942. }
  20943. }
  20944. }
  20945. void AudioSampleBuffer::copyFromWithRamp (const int destChannel,
  20946. const int destStartSample,
  20947. const float* source,
  20948. int numSamples,
  20949. float startGain,
  20950. float endGain) throw()
  20951. {
  20952. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20953. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20954. jassert (source != 0);
  20955. if (startGain == endGain)
  20956. {
  20957. copyFrom (destChannel,
  20958. destStartSample,
  20959. source,
  20960. numSamples,
  20961. startGain);
  20962. }
  20963. else
  20964. {
  20965. if (numSamples > 0 && (startGain != 0.0f || endGain != 0.0f))
  20966. {
  20967. const float increment = (endGain - startGain) / numSamples;
  20968. float* d = channels [destChannel] + destStartSample;
  20969. while (--numSamples >= 0)
  20970. {
  20971. *d++ = startGain * *source++;
  20972. startGain += increment;
  20973. }
  20974. }
  20975. }
  20976. }
  20977. void AudioSampleBuffer::findMinMax (const int channel,
  20978. const int startSample,
  20979. int numSamples,
  20980. float& minVal,
  20981. float& maxVal) const throw()
  20982. {
  20983. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20984. jassert (startSample >= 0 && startSample + numSamples <= size);
  20985. if (numSamples <= 0)
  20986. {
  20987. minVal = 0.0f;
  20988. maxVal = 0.0f;
  20989. }
  20990. else
  20991. {
  20992. const float* d = channels [channel] + startSample;
  20993. float mn = *d++;
  20994. float mx = mn;
  20995. while (--numSamples > 0) // (> 0 rather than >= 0 because we've already taken the first sample)
  20996. {
  20997. const float samp = *d++;
  20998. if (samp > mx)
  20999. mx = samp;
  21000. if (samp < mn)
  21001. mn = samp;
  21002. }
  21003. maxVal = mx;
  21004. minVal = mn;
  21005. }
  21006. }
  21007. float AudioSampleBuffer::getMagnitude (const int channel,
  21008. const int startSample,
  21009. const int numSamples) const throw()
  21010. {
  21011. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  21012. jassert (startSample >= 0 && startSample + numSamples <= size);
  21013. float mn, mx;
  21014. findMinMax (channel, startSample, numSamples, mn, mx);
  21015. return jmax (mn, -mn, mx, -mx);
  21016. }
  21017. float AudioSampleBuffer::getMagnitude (const int startSample,
  21018. const int numSamples) const throw()
  21019. {
  21020. float mag = 0.0f;
  21021. for (int i = 0; i < numChannels; ++i)
  21022. mag = jmax (mag, getMagnitude (i, startSample, numSamples));
  21023. return mag;
  21024. }
  21025. float AudioSampleBuffer::getRMSLevel (const int channel,
  21026. const int startSample,
  21027. const int numSamples) const throw()
  21028. {
  21029. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  21030. jassert (startSample >= 0 && startSample + numSamples <= size);
  21031. if (numSamples <= 0 || channel < 0 || channel >= numChannels)
  21032. return 0.0f;
  21033. const float* const data = channels [channel] + startSample;
  21034. double sum = 0.0;
  21035. for (int i = 0; i < numSamples; ++i)
  21036. {
  21037. const float sample = data [i];
  21038. sum += sample * sample;
  21039. }
  21040. return (float) sqrt (sum / numSamples);
  21041. }
  21042. void AudioSampleBuffer::readFromAudioReader (AudioFormatReader* reader,
  21043. const int startSample,
  21044. const int numSamples,
  21045. const int readerStartSample,
  21046. const bool useLeftChan,
  21047. const bool useRightChan) throw()
  21048. {
  21049. jassert (reader != 0);
  21050. jassert (startSample >= 0 && startSample + numSamples <= size);
  21051. if (numSamples > 0)
  21052. {
  21053. int* chans[3];
  21054. if (useLeftChan == useRightChan)
  21055. {
  21056. chans[0] = (int*) getSampleData (0, startSample);
  21057. chans[1] = (reader->numChannels > 1 && getNumChannels() > 1) ? (int*) getSampleData (1, startSample) : 0;
  21058. }
  21059. else if (useLeftChan || (reader->numChannels == 1))
  21060. {
  21061. chans[0] = (int*) getSampleData (0, startSample);
  21062. chans[1] = 0;
  21063. }
  21064. else if (useRightChan)
  21065. {
  21066. chans[0] = 0;
  21067. chans[1] = (int*) getSampleData (0, startSample);
  21068. }
  21069. chans[2] = 0;
  21070. reader->read (chans, 2, readerStartSample, numSamples, true);
  21071. if (! reader->usesFloatingPointData)
  21072. {
  21073. for (int j = 0; j < 2; ++j)
  21074. {
  21075. float* const d = (float*) (chans[j]);
  21076. if (d != 0)
  21077. {
  21078. const float multiplier = 1.0f / 0x7fffffff;
  21079. for (int i = 0; i < numSamples; ++i)
  21080. d[i] = *(int*)(d + i) * multiplier;
  21081. }
  21082. }
  21083. }
  21084. if (numChannels > 1 && (chans[0] == 0 || chans[1] == 0))
  21085. {
  21086. // if this is a stereo buffer and the source was mono, dupe the first channel..
  21087. memcpy (getSampleData (1, startSample),
  21088. getSampleData (0, startSample),
  21089. sizeof (float) * numSamples);
  21090. }
  21091. }
  21092. }
  21093. void AudioSampleBuffer::writeToAudioWriter (AudioFormatWriter* writer,
  21094. const int startSample,
  21095. const int numSamples) const throw()
  21096. {
  21097. jassert (startSample >= 0 && startSample + numSamples <= size);
  21098. if (numSamples > 0)
  21099. {
  21100. int* chans [3];
  21101. if (writer->isFloatingPoint())
  21102. {
  21103. chans[0] = (int*) getSampleData (0, startSample);
  21104. if (numChannels > 1)
  21105. chans[1] = (int*) getSampleData (1, startSample);
  21106. else
  21107. chans[1] = 0;
  21108. chans[2] = 0;
  21109. writer->write ((const int**) chans, numSamples);
  21110. }
  21111. else
  21112. {
  21113. HeapBlock <int> tempBuffer (numSamples * 2);
  21114. chans[0] = tempBuffer;
  21115. if (numChannels > 1)
  21116. chans[1] = chans[0] + numSamples;
  21117. else
  21118. chans[1] = 0;
  21119. chans[2] = 0;
  21120. for (int j = 0; j < 2; ++j)
  21121. {
  21122. int* const dest = chans[j];
  21123. if (dest != 0)
  21124. {
  21125. const float* const src = channels [j] + startSample;
  21126. for (int i = 0; i < numSamples; ++i)
  21127. {
  21128. const double samp = src[i];
  21129. if (samp <= -1.0)
  21130. dest[i] = std::numeric_limits<int>::min();
  21131. else if (samp >= 1.0)
  21132. dest[i] = std::numeric_limits<int>::max();
  21133. else
  21134. dest[i] = roundToInt (std::numeric_limits<int>::max() * samp);
  21135. }
  21136. }
  21137. }
  21138. writer->write ((const int**) chans, numSamples);
  21139. }
  21140. }
  21141. }
  21142. END_JUCE_NAMESPACE
  21143. /*** End of inlined file: juce_AudioSampleBuffer.cpp ***/
  21144. /*** Start of inlined file: juce_IIRFilter.cpp ***/
  21145. BEGIN_JUCE_NAMESPACE
  21146. IIRFilter::IIRFilter() throw()
  21147. : active (false)
  21148. {
  21149. reset();
  21150. }
  21151. IIRFilter::IIRFilter (const IIRFilter& other) throw()
  21152. : active (other.active)
  21153. {
  21154. const ScopedLock sl (other.processLock);
  21155. memcpy (coefficients, other.coefficients, sizeof (coefficients));
  21156. reset();
  21157. }
  21158. IIRFilter::~IIRFilter() throw()
  21159. {
  21160. }
  21161. void IIRFilter::reset() throw()
  21162. {
  21163. const ScopedLock sl (processLock);
  21164. x1 = 0;
  21165. x2 = 0;
  21166. y1 = 0;
  21167. y2 = 0;
  21168. }
  21169. float IIRFilter::processSingleSampleRaw (const float in) throw()
  21170. {
  21171. float out = coefficients[0] * in
  21172. + coefficients[1] * x1
  21173. + coefficients[2] * x2
  21174. - coefficients[4] * y1
  21175. - coefficients[5] * y2;
  21176. #if JUCE_INTEL
  21177. if (! (out < -1.0e-8 || out > 1.0e-8))
  21178. out = 0;
  21179. #endif
  21180. x2 = x1;
  21181. x1 = in;
  21182. y2 = y1;
  21183. y1 = out;
  21184. return out;
  21185. }
  21186. void IIRFilter::processSamples (float* const samples,
  21187. const int numSamples) throw()
  21188. {
  21189. const ScopedLock sl (processLock);
  21190. if (active)
  21191. {
  21192. for (int i = 0; i < numSamples; ++i)
  21193. {
  21194. const float in = samples[i];
  21195. float out = coefficients[0] * in
  21196. + coefficients[1] * x1
  21197. + coefficients[2] * x2
  21198. - coefficients[4] * y1
  21199. - coefficients[5] * y2;
  21200. #if JUCE_INTEL
  21201. if (! (out < -1.0e-8 || out > 1.0e-8))
  21202. out = 0;
  21203. #endif
  21204. x2 = x1;
  21205. x1 = in;
  21206. y2 = y1;
  21207. y1 = out;
  21208. samples[i] = out;
  21209. }
  21210. }
  21211. }
  21212. void IIRFilter::makeLowPass (const double sampleRate,
  21213. const double frequency) throw()
  21214. {
  21215. jassert (sampleRate > 0);
  21216. const double n = 1.0 / tan (double_Pi * frequency / sampleRate);
  21217. const double nSquared = n * n;
  21218. const double c1 = 1.0 / (1.0 + sqrt (2.0) * n + nSquared);
  21219. setCoefficients (c1,
  21220. c1 * 2.0f,
  21221. c1,
  21222. 1.0,
  21223. c1 * 2.0 * (1.0 - nSquared),
  21224. c1 * (1.0 - sqrt (2.0) * n + nSquared));
  21225. }
  21226. void IIRFilter::makeHighPass (const double sampleRate,
  21227. const double frequency) throw()
  21228. {
  21229. const double n = tan (double_Pi * frequency / sampleRate);
  21230. const double nSquared = n * n;
  21231. const double c1 = 1.0 / (1.0 + sqrt (2.0) * n + nSquared);
  21232. setCoefficients (c1,
  21233. c1 * -2.0f,
  21234. c1,
  21235. 1.0,
  21236. c1 * 2.0 * (nSquared - 1.0),
  21237. c1 * (1.0 - sqrt (2.0) * n + nSquared));
  21238. }
  21239. void IIRFilter::makeLowShelf (const double sampleRate,
  21240. const double cutOffFrequency,
  21241. const double Q,
  21242. const float gainFactor) throw()
  21243. {
  21244. jassert (sampleRate > 0);
  21245. jassert (Q > 0);
  21246. const double A = jmax (0.0f, gainFactor);
  21247. const double aminus1 = A - 1.0;
  21248. const double aplus1 = A + 1.0;
  21249. const double omega = (double_Pi * 2.0 * jmax (cutOffFrequency, 2.0)) / sampleRate;
  21250. const double coso = cos (omega);
  21251. const double beta = sin (omega) * sqrt (A) / Q;
  21252. const double aminus1TimesCoso = aminus1 * coso;
  21253. setCoefficients (A * (aplus1 - aminus1TimesCoso + beta),
  21254. A * 2.0 * (aminus1 - aplus1 * coso),
  21255. A * (aplus1 - aminus1TimesCoso - beta),
  21256. aplus1 + aminus1TimesCoso + beta,
  21257. -2.0 * (aminus1 + aplus1 * coso),
  21258. aplus1 + aminus1TimesCoso - beta);
  21259. }
  21260. void IIRFilter::makeHighShelf (const double sampleRate,
  21261. const double cutOffFrequency,
  21262. const double Q,
  21263. const float gainFactor) throw()
  21264. {
  21265. jassert (sampleRate > 0);
  21266. jassert (Q > 0);
  21267. const double A = jmax (0.0f, gainFactor);
  21268. const double aminus1 = A - 1.0;
  21269. const double aplus1 = A + 1.0;
  21270. const double omega = (double_Pi * 2.0 * jmax (cutOffFrequency, 2.0)) / sampleRate;
  21271. const double coso = cos (omega);
  21272. const double beta = sin (omega) * sqrt (A) / Q;
  21273. const double aminus1TimesCoso = aminus1 * coso;
  21274. setCoefficients (A * (aplus1 + aminus1TimesCoso + beta),
  21275. A * -2.0 * (aminus1 + aplus1 * coso),
  21276. A * (aplus1 + aminus1TimesCoso - beta),
  21277. aplus1 - aminus1TimesCoso + beta,
  21278. 2.0 * (aminus1 - aplus1 * coso),
  21279. aplus1 - aminus1TimesCoso - beta);
  21280. }
  21281. void IIRFilter::makeBandPass (const double sampleRate,
  21282. const double centreFrequency,
  21283. const double Q,
  21284. const float gainFactor) throw()
  21285. {
  21286. jassert (sampleRate > 0);
  21287. jassert (Q > 0);
  21288. const double A = jmax (0.0f, gainFactor);
  21289. const double omega = (double_Pi * 2.0 * jmax (centreFrequency, 2.0)) / sampleRate;
  21290. const double alpha = 0.5 * sin (omega) / Q;
  21291. const double c2 = -2.0 * cos (omega);
  21292. const double alphaTimesA = alpha * A;
  21293. const double alphaOverA = alpha / A;
  21294. setCoefficients (1.0 + alphaTimesA,
  21295. c2,
  21296. 1.0 - alphaTimesA,
  21297. 1.0 + alphaOverA,
  21298. c2,
  21299. 1.0 - alphaOverA);
  21300. }
  21301. void IIRFilter::makeInactive() throw()
  21302. {
  21303. const ScopedLock sl (processLock);
  21304. active = false;
  21305. }
  21306. void IIRFilter::copyCoefficientsFrom (const IIRFilter& other) throw()
  21307. {
  21308. const ScopedLock sl (processLock);
  21309. memcpy (coefficients, other.coefficients, sizeof (coefficients));
  21310. active = other.active;
  21311. }
  21312. void IIRFilter::setCoefficients (double c1,
  21313. double c2,
  21314. double c3,
  21315. double c4,
  21316. double c5,
  21317. double c6) throw()
  21318. {
  21319. const double a = 1.0 / c4;
  21320. c1 *= a;
  21321. c2 *= a;
  21322. c3 *= a;
  21323. c5 *= a;
  21324. c6 *= a;
  21325. const ScopedLock sl (processLock);
  21326. coefficients[0] = (float) c1;
  21327. coefficients[1] = (float) c2;
  21328. coefficients[2] = (float) c3;
  21329. coefficients[3] = (float) c4;
  21330. coefficients[4] = (float) c5;
  21331. coefficients[5] = (float) c6;
  21332. active = true;
  21333. }
  21334. END_JUCE_NAMESPACE
  21335. /*** End of inlined file: juce_IIRFilter.cpp ***/
  21336. /*** Start of inlined file: juce_MidiBuffer.cpp ***/
  21337. BEGIN_JUCE_NAMESPACE
  21338. MidiBuffer::MidiBuffer() throw()
  21339. : bytesUsed (0)
  21340. {
  21341. }
  21342. MidiBuffer::MidiBuffer (const MidiMessage& message) throw()
  21343. : bytesUsed (0)
  21344. {
  21345. addEvent (message, 0);
  21346. }
  21347. MidiBuffer::MidiBuffer (const MidiBuffer& other) throw()
  21348. : data (other.data),
  21349. bytesUsed (other.bytesUsed)
  21350. {
  21351. }
  21352. MidiBuffer& MidiBuffer::operator= (const MidiBuffer& other) throw()
  21353. {
  21354. bytesUsed = other.bytesUsed;
  21355. data = other.data;
  21356. return *this;
  21357. }
  21358. void MidiBuffer::swap (MidiBuffer& other)
  21359. {
  21360. data.swapWith (other.data);
  21361. swapVariables <int> (bytesUsed, other.bytesUsed);
  21362. }
  21363. MidiBuffer::~MidiBuffer() throw()
  21364. {
  21365. }
  21366. void MidiBuffer::clear() throw()
  21367. {
  21368. bytesUsed = 0;
  21369. }
  21370. void MidiBuffer::clear (const int startSample,
  21371. const int numSamples) throw()
  21372. {
  21373. uint8* const start = findEventAfter (getData(), startSample - 1);
  21374. uint8* const end = findEventAfter (start, startSample + numSamples - 1);
  21375. if (end > start)
  21376. {
  21377. const size_t bytesToMove = (size_t) (bytesUsed - (end - getData()));
  21378. if (bytesToMove > 0)
  21379. memmove (start, end, bytesToMove);
  21380. bytesUsed -= (int) (end - start);
  21381. }
  21382. }
  21383. void MidiBuffer::addEvent (const MidiMessage& m,
  21384. const int sampleNumber) throw()
  21385. {
  21386. addEvent (m.getRawData(), m.getRawDataSize(), sampleNumber);
  21387. }
  21388. static int findActualEventLength (const uint8* const data,
  21389. const int maxBytes) throw()
  21390. {
  21391. unsigned int byte = (unsigned int) *data;
  21392. int size = 0;
  21393. if (byte == 0xf0 || byte == 0xf7)
  21394. {
  21395. const uint8* d = data + 1;
  21396. while (d < data + maxBytes)
  21397. if (*d++ == 0xf7)
  21398. break;
  21399. size = (int) (d - data);
  21400. }
  21401. else if (byte == 0xff)
  21402. {
  21403. int n;
  21404. const int bytesLeft = MidiMessage::readVariableLengthVal (data + 1, n);
  21405. size = jmin (maxBytes, n + 2 + bytesLeft);
  21406. }
  21407. else if (byte >= 0x80)
  21408. {
  21409. size = jmin (maxBytes, MidiMessage::getMessageLengthFromFirstByte ((uint8) byte));
  21410. }
  21411. return size;
  21412. }
  21413. void MidiBuffer::addEvent (const uint8* const newData,
  21414. const int maxBytes,
  21415. const int sampleNumber) throw()
  21416. {
  21417. const int numBytes = findActualEventLength (newData, maxBytes);
  21418. if (numBytes > 0)
  21419. {
  21420. int spaceNeeded = bytesUsed + numBytes + 6;
  21421. data.ensureSize ((spaceNeeded + spaceNeeded / 2 + 8) & ~7);
  21422. uint8* d = findEventAfter (getData(), sampleNumber);
  21423. const size_t bytesToMove = (size_t) (bytesUsed - (d - getData()));
  21424. if (bytesToMove > 0)
  21425. memmove (d + numBytes + 6,
  21426. d,
  21427. bytesToMove);
  21428. *(int*) d = sampleNumber;
  21429. d += 4;
  21430. *(uint16*) d = (uint16) numBytes;
  21431. d += 2;
  21432. memcpy (d, newData, numBytes);
  21433. bytesUsed += numBytes + 6;
  21434. }
  21435. }
  21436. void MidiBuffer::addEvents (const MidiBuffer& otherBuffer,
  21437. const int startSample,
  21438. const int numSamples,
  21439. const int sampleDeltaToAdd) throw()
  21440. {
  21441. Iterator i (otherBuffer);
  21442. i.setNextSamplePosition (startSample);
  21443. const uint8* eventData;
  21444. int eventSize, position;
  21445. while (i.getNextEvent (eventData, eventSize, position)
  21446. && (position < startSample + numSamples || numSamples < 0))
  21447. {
  21448. addEvent (eventData, eventSize, position + sampleDeltaToAdd);
  21449. }
  21450. }
  21451. bool MidiBuffer::isEmpty() const throw()
  21452. {
  21453. return bytesUsed == 0;
  21454. }
  21455. int MidiBuffer::getNumEvents() const throw()
  21456. {
  21457. int n = 0;
  21458. const uint8* d = getData();
  21459. const uint8* const end = d + bytesUsed;
  21460. while (d < end)
  21461. {
  21462. d += 4;
  21463. d += 2 + *(const uint16*) d;
  21464. ++n;
  21465. }
  21466. return n;
  21467. }
  21468. int MidiBuffer::getFirstEventTime() const throw()
  21469. {
  21470. return (bytesUsed > 0) ? *reinterpret_cast <const int*> (data.getData()) : 0;
  21471. }
  21472. int MidiBuffer::getLastEventTime() const throw()
  21473. {
  21474. if (bytesUsed == 0)
  21475. return 0;
  21476. const uint8* d = getData();
  21477. const uint8* const endData = d + bytesUsed;
  21478. for (;;)
  21479. {
  21480. const uint8* nextOne = d + 6 + * (const uint16*) (d + 4);
  21481. if (nextOne >= endData)
  21482. return *(const int*) d;
  21483. d = nextOne;
  21484. }
  21485. }
  21486. uint8* MidiBuffer::findEventAfter (uint8* d, const int samplePosition) const throw()
  21487. {
  21488. const uint8* const endData = getData() + bytesUsed;
  21489. while (d < endData && *(int*) d <= samplePosition)
  21490. {
  21491. d += 4;
  21492. d += 2 + *(uint16*) d;
  21493. }
  21494. return d;
  21495. }
  21496. MidiBuffer::Iterator::Iterator (const MidiBuffer& buffer_) throw()
  21497. : buffer (buffer_),
  21498. data (buffer_.getData())
  21499. {
  21500. }
  21501. MidiBuffer::Iterator::~Iterator() throw()
  21502. {
  21503. }
  21504. void MidiBuffer::Iterator::setNextSamplePosition (const int samplePosition) throw()
  21505. {
  21506. data = buffer.getData();
  21507. const uint8* dataEnd = data + buffer.bytesUsed;
  21508. while (data < dataEnd && *reinterpret_cast<const int*> (data) < samplePosition)
  21509. {
  21510. data += 4;
  21511. data += 2 + *(uint16*) data;
  21512. }
  21513. }
  21514. bool MidiBuffer::Iterator::getNextEvent (const uint8* &midiData,
  21515. int& numBytes,
  21516. int& samplePosition) throw()
  21517. {
  21518. if (data >= buffer.getData() + buffer.bytesUsed)
  21519. return false;
  21520. samplePosition = *(int*) data;
  21521. data += 4;
  21522. numBytes = *(uint16*) data;
  21523. data += 2;
  21524. midiData = data;
  21525. data += numBytes;
  21526. return true;
  21527. }
  21528. bool MidiBuffer::Iterator::getNextEvent (MidiMessage& result,
  21529. int& samplePosition) throw()
  21530. {
  21531. if (data >= buffer.getData() + buffer.bytesUsed)
  21532. return false;
  21533. samplePosition = *reinterpret_cast <const int*> (data);
  21534. data += 4;
  21535. const int numBytes = *reinterpret_cast <const uint16*> (data);
  21536. data += 2;
  21537. result = MidiMessage (data, numBytes, samplePosition);
  21538. data += numBytes;
  21539. return true;
  21540. }
  21541. END_JUCE_NAMESPACE
  21542. /*** End of inlined file: juce_MidiBuffer.cpp ***/
  21543. /*** Start of inlined file: juce_MidiFile.cpp ***/
  21544. BEGIN_JUCE_NAMESPACE
  21545. namespace MidiFileHelpers
  21546. {
  21547. static void writeVariableLengthInt (OutputStream& out, unsigned int v)
  21548. {
  21549. unsigned int buffer = v & 0x7F;
  21550. while ((v >>= 7) != 0)
  21551. {
  21552. buffer <<= 8;
  21553. buffer |= ((v & 0x7F) | 0x80);
  21554. }
  21555. for (;;)
  21556. {
  21557. out.writeByte ((char) buffer);
  21558. if (buffer & 0x80)
  21559. buffer >>= 8;
  21560. else
  21561. break;
  21562. }
  21563. }
  21564. static bool parseMidiHeader (const char* &data, short& timeFormat, short& fileType, short& numberOfTracks) throw()
  21565. {
  21566. unsigned int ch = (int) ByteOrder::bigEndianInt (data);
  21567. data += 4;
  21568. if (ch != ByteOrder::bigEndianInt ("MThd"))
  21569. {
  21570. bool ok = false;
  21571. if (ch == ByteOrder::bigEndianInt ("RIFF"))
  21572. {
  21573. for (int i = 0; i < 8; ++i)
  21574. {
  21575. ch = ByteOrder::bigEndianInt (data);
  21576. data += 4;
  21577. if (ch == ByteOrder::bigEndianInt ("MThd"))
  21578. {
  21579. ok = true;
  21580. break;
  21581. }
  21582. }
  21583. }
  21584. if (! ok)
  21585. return false;
  21586. }
  21587. unsigned int bytesRemaining = ByteOrder::bigEndianInt (data);
  21588. data += 4;
  21589. fileType = (short) ByteOrder::bigEndianShort (data);
  21590. data += 2;
  21591. numberOfTracks = (short) ByteOrder::bigEndianShort (data);
  21592. data += 2;
  21593. timeFormat = (short) ByteOrder::bigEndianShort (data);
  21594. data += 2;
  21595. bytesRemaining -= 6;
  21596. data += bytesRemaining;
  21597. return true;
  21598. }
  21599. static double convertTicksToSeconds (const double time,
  21600. const MidiMessageSequence& tempoEvents,
  21601. const int timeFormat)
  21602. {
  21603. if (timeFormat > 0)
  21604. {
  21605. int numer = 4, denom = 4;
  21606. double tempoTime = 0.0, correctedTempoTime = 0.0;
  21607. const double tickLen = 1.0 / (timeFormat & 0x7fff);
  21608. double secsPerTick = 0.5 * tickLen;
  21609. const int numEvents = tempoEvents.getNumEvents();
  21610. for (int i = 0; i < numEvents; ++i)
  21611. {
  21612. const MidiMessage& m = tempoEvents.getEventPointer(i)->message;
  21613. if (time <= m.getTimeStamp())
  21614. break;
  21615. if (timeFormat > 0)
  21616. {
  21617. correctedTempoTime = correctedTempoTime
  21618. + (m.getTimeStamp() - tempoTime) * secsPerTick;
  21619. }
  21620. else
  21621. {
  21622. correctedTempoTime = tickLen * m.getTimeStamp() / (((timeFormat & 0x7fff) >> 8) * (timeFormat & 0xff));
  21623. }
  21624. tempoTime = m.getTimeStamp();
  21625. if (m.isTempoMetaEvent())
  21626. secsPerTick = tickLen * m.getTempoSecondsPerQuarterNote();
  21627. else if (m.isTimeSignatureMetaEvent())
  21628. m.getTimeSignatureInfo (numer, denom);
  21629. while (i + 1 < numEvents)
  21630. {
  21631. const MidiMessage& m2 = tempoEvents.getEventPointer(i + 1)->message;
  21632. if (m2.getTimeStamp() == tempoTime)
  21633. {
  21634. ++i;
  21635. if (m2.isTempoMetaEvent())
  21636. secsPerTick = tickLen * m2.getTempoSecondsPerQuarterNote();
  21637. else if (m2.isTimeSignatureMetaEvent())
  21638. m2.getTimeSignatureInfo (numer, denom);
  21639. }
  21640. else
  21641. {
  21642. break;
  21643. }
  21644. }
  21645. }
  21646. return correctedTempoTime + (time - tempoTime) * secsPerTick;
  21647. }
  21648. else
  21649. {
  21650. return time / (((timeFormat & 0x7fff) >> 8) * (timeFormat & 0xff));
  21651. }
  21652. }
  21653. }
  21654. MidiFile::MidiFile() throw()
  21655. : timeFormat ((short) (unsigned short) 0xe728)
  21656. {
  21657. }
  21658. MidiFile::~MidiFile() throw()
  21659. {
  21660. clear();
  21661. }
  21662. void MidiFile::clear() throw()
  21663. {
  21664. tracks.clear();
  21665. }
  21666. int MidiFile::getNumTracks() const throw()
  21667. {
  21668. return tracks.size();
  21669. }
  21670. const MidiMessageSequence* MidiFile::getTrack (const int index) const throw()
  21671. {
  21672. return tracks [index];
  21673. }
  21674. void MidiFile::addTrack (const MidiMessageSequence& trackSequence) throw()
  21675. {
  21676. tracks.add (new MidiMessageSequence (trackSequence));
  21677. }
  21678. short MidiFile::getTimeFormat() const throw()
  21679. {
  21680. return timeFormat;
  21681. }
  21682. void MidiFile::setTicksPerQuarterNote (const int ticks) throw()
  21683. {
  21684. timeFormat = (short)ticks;
  21685. }
  21686. void MidiFile::setSmpteTimeFormat (const int framesPerSecond,
  21687. const int subframeResolution) throw()
  21688. {
  21689. timeFormat = (short) (((-framesPerSecond) << 8) | subframeResolution);
  21690. }
  21691. void MidiFile::findAllTempoEvents (MidiMessageSequence& tempoChangeEvents) const
  21692. {
  21693. for (int i = tracks.size(); --i >= 0;)
  21694. {
  21695. const int numEvents = tracks.getUnchecked(i)->getNumEvents();
  21696. for (int j = 0; j < numEvents; ++j)
  21697. {
  21698. const MidiMessage& m = tracks.getUnchecked(i)->getEventPointer (j)->message;
  21699. if (m.isTempoMetaEvent())
  21700. tempoChangeEvents.addEvent (m);
  21701. }
  21702. }
  21703. }
  21704. void MidiFile::findAllTimeSigEvents (MidiMessageSequence& timeSigEvents) const
  21705. {
  21706. for (int i = tracks.size(); --i >= 0;)
  21707. {
  21708. const int numEvents = tracks.getUnchecked(i)->getNumEvents();
  21709. for (int j = 0; j < numEvents; ++j)
  21710. {
  21711. const MidiMessage& m = tracks.getUnchecked(i)->getEventPointer (j)->message;
  21712. if (m.isTimeSignatureMetaEvent())
  21713. timeSigEvents.addEvent (m);
  21714. }
  21715. }
  21716. }
  21717. double MidiFile::getLastTimestamp() const
  21718. {
  21719. double t = 0.0;
  21720. for (int i = tracks.size(); --i >= 0;)
  21721. t = jmax (t, tracks.getUnchecked(i)->getEndTime());
  21722. return t;
  21723. }
  21724. bool MidiFile::readFrom (InputStream& sourceStream)
  21725. {
  21726. clear();
  21727. MemoryBlock data;
  21728. const int maxSensibleMidiFileSize = 2 * 1024 * 1024;
  21729. // (put a sanity-check on the file size, as midi files are generally small)
  21730. if (sourceStream.readIntoMemoryBlock (data, maxSensibleMidiFileSize))
  21731. {
  21732. size_t size = data.getSize();
  21733. const char* d = (char*) data.getData();
  21734. short fileType, expectedTracks;
  21735. if (size > 16 && MidiFileHelpers::parseMidiHeader (d, timeFormat, fileType, expectedTracks))
  21736. {
  21737. size -= (int) (d - (char*) data.getData());
  21738. int track = 0;
  21739. while (size > 0 && track < expectedTracks)
  21740. {
  21741. const int chunkType = (int) ByteOrder::bigEndianInt (d);
  21742. d += 4;
  21743. const int chunkSize = (int) ByteOrder::bigEndianInt (d);
  21744. d += 4;
  21745. if (chunkSize <= 0)
  21746. break;
  21747. if (size < 0)
  21748. return false;
  21749. if (chunkType == (int) ByteOrder::bigEndianInt ("MTrk"))
  21750. {
  21751. readNextTrack (d, chunkSize);
  21752. }
  21753. size -= chunkSize + 8;
  21754. d += chunkSize;
  21755. ++track;
  21756. }
  21757. return true;
  21758. }
  21759. }
  21760. return false;
  21761. }
  21762. // a comparator that puts all the note-offs before note-ons that have the same time
  21763. int MidiFile::compareElements (const MidiMessageSequence::MidiEventHolder* const first,
  21764. const MidiMessageSequence::MidiEventHolder* const second) throw()
  21765. {
  21766. const double diff = (first->message.getTimeStamp() - second->message.getTimeStamp());
  21767. if (diff == 0)
  21768. {
  21769. if (first->message.isNoteOff() && second->message.isNoteOn())
  21770. return -1;
  21771. else if (first->message.isNoteOn() && second->message.isNoteOff())
  21772. return 1;
  21773. else
  21774. return 0;
  21775. }
  21776. else
  21777. {
  21778. return (diff > 0) ? 1 : -1;
  21779. }
  21780. }
  21781. void MidiFile::readNextTrack (const char* data, int size)
  21782. {
  21783. double time = 0;
  21784. char lastStatusByte = 0;
  21785. MidiMessageSequence result;
  21786. while (size > 0)
  21787. {
  21788. int bytesUsed;
  21789. const int delay = MidiMessage::readVariableLengthVal ((const uint8*) data, bytesUsed);
  21790. data += bytesUsed;
  21791. size -= bytesUsed;
  21792. time += delay;
  21793. int messSize = 0;
  21794. const MidiMessage mm ((const uint8*) data, size, messSize, lastStatusByte, time);
  21795. if (messSize <= 0)
  21796. break;
  21797. size -= messSize;
  21798. data += messSize;
  21799. result.addEvent (mm);
  21800. const char firstByte = *(mm.getRawData());
  21801. if ((firstByte & 0xf0) != 0xf0)
  21802. lastStatusByte = firstByte;
  21803. }
  21804. // use a sort that puts all the note-offs before note-ons that have the same time
  21805. result.list.sort (*this, true);
  21806. result.updateMatchedPairs();
  21807. addTrack (result);
  21808. }
  21809. void MidiFile::convertTimestampTicksToSeconds()
  21810. {
  21811. MidiMessageSequence tempoEvents;
  21812. findAllTempoEvents (tempoEvents);
  21813. findAllTimeSigEvents (tempoEvents);
  21814. for (int i = 0; i < tracks.size(); ++i)
  21815. {
  21816. MidiMessageSequence& ms = *tracks.getUnchecked(i);
  21817. for (int j = ms.getNumEvents(); --j >= 0;)
  21818. {
  21819. MidiMessage& m = ms.getEventPointer(j)->message;
  21820. m.setTimeStamp (MidiFileHelpers::convertTicksToSeconds (m.getTimeStamp(),
  21821. tempoEvents,
  21822. timeFormat));
  21823. }
  21824. }
  21825. }
  21826. bool MidiFile::writeTo (OutputStream& out)
  21827. {
  21828. out.writeIntBigEndian ((int) ByteOrder::bigEndianInt ("MThd"));
  21829. out.writeIntBigEndian (6);
  21830. out.writeShortBigEndian (1); // type
  21831. out.writeShortBigEndian ((short) tracks.size());
  21832. out.writeShortBigEndian (timeFormat);
  21833. for (int i = 0; i < tracks.size(); ++i)
  21834. writeTrack (out, i);
  21835. out.flush();
  21836. return true;
  21837. }
  21838. void MidiFile::writeTrack (OutputStream& mainOut,
  21839. const int trackNum)
  21840. {
  21841. MemoryOutputStream out;
  21842. const MidiMessageSequence& ms = *tracks[trackNum];
  21843. int lastTick = 0;
  21844. char lastStatusByte = 0;
  21845. for (int i = 0; i < ms.getNumEvents(); ++i)
  21846. {
  21847. const MidiMessage& mm = ms.getEventPointer(i)->message;
  21848. const int tick = roundToInt (mm.getTimeStamp());
  21849. const int delta = jmax (0, tick - lastTick);
  21850. MidiFileHelpers::writeVariableLengthInt (out, delta);
  21851. lastTick = tick;
  21852. const char statusByte = *(mm.getRawData());
  21853. if ((statusByte == lastStatusByte)
  21854. && ((statusByte & 0xf0) != 0xf0)
  21855. && i > 0
  21856. && mm.getRawDataSize() > 1)
  21857. {
  21858. out.write (mm.getRawData() + 1, mm.getRawDataSize() - 1);
  21859. }
  21860. else
  21861. {
  21862. out.write (mm.getRawData(), mm.getRawDataSize());
  21863. }
  21864. lastStatusByte = statusByte;
  21865. }
  21866. out.writeByte (0);
  21867. const MidiMessage m (MidiMessage::endOfTrack());
  21868. out.write (m.getRawData(),
  21869. m.getRawDataSize());
  21870. mainOut.writeIntBigEndian ((int) ByteOrder::bigEndianInt ("MTrk"));
  21871. mainOut.writeIntBigEndian ((int) out.getDataSize());
  21872. mainOut.write (out.getData(), (int) out.getDataSize());
  21873. }
  21874. END_JUCE_NAMESPACE
  21875. /*** End of inlined file: juce_MidiFile.cpp ***/
  21876. /*** Start of inlined file: juce_MidiKeyboardState.cpp ***/
  21877. BEGIN_JUCE_NAMESPACE
  21878. MidiKeyboardState::MidiKeyboardState()
  21879. {
  21880. zeromem (noteStates, sizeof (noteStates));
  21881. }
  21882. MidiKeyboardState::~MidiKeyboardState()
  21883. {
  21884. }
  21885. void MidiKeyboardState::reset()
  21886. {
  21887. const ScopedLock sl (lock);
  21888. zeromem (noteStates, sizeof (noteStates));
  21889. eventsToAdd.clear();
  21890. }
  21891. bool MidiKeyboardState::isNoteOn (const int midiChannel, const int n) const throw()
  21892. {
  21893. jassert (midiChannel >= 0 && midiChannel <= 16);
  21894. return ((unsigned int) n) < 128
  21895. && (noteStates[n] & (1 << (midiChannel - 1))) != 0;
  21896. }
  21897. bool MidiKeyboardState::isNoteOnForChannels (const int midiChannelMask, const int n) const throw()
  21898. {
  21899. return ((unsigned int) n) < 128
  21900. && (noteStates[n] & midiChannelMask) != 0;
  21901. }
  21902. void MidiKeyboardState::noteOn (const int midiChannel, const int midiNoteNumber, const float velocity)
  21903. {
  21904. jassert (midiChannel >= 0 && midiChannel <= 16);
  21905. jassert (((unsigned int) midiNoteNumber) < 128);
  21906. const ScopedLock sl (lock);
  21907. if (((unsigned int) midiNoteNumber) < 128)
  21908. {
  21909. const int timeNow = (int) Time::getMillisecondCounter();
  21910. eventsToAdd.addEvent (MidiMessage::noteOn (midiChannel, midiNoteNumber, velocity), timeNow);
  21911. eventsToAdd.clear (0, timeNow - 500);
  21912. noteOnInternal (midiChannel, midiNoteNumber, velocity);
  21913. }
  21914. }
  21915. void MidiKeyboardState::noteOnInternal (const int midiChannel, const int midiNoteNumber, const float velocity)
  21916. {
  21917. if (((unsigned int) midiNoteNumber) < 128)
  21918. {
  21919. noteStates [midiNoteNumber] |= (1 << (midiChannel - 1));
  21920. for (int i = listeners.size(); --i >= 0;)
  21921. ((MidiKeyboardStateListener*) listeners.getUnchecked(i))
  21922. ->handleNoteOn (this, midiChannel, midiNoteNumber, velocity);
  21923. }
  21924. }
  21925. void MidiKeyboardState::noteOff (const int midiChannel, const int midiNoteNumber)
  21926. {
  21927. const ScopedLock sl (lock);
  21928. if (isNoteOn (midiChannel, midiNoteNumber))
  21929. {
  21930. const int timeNow = (int) Time::getMillisecondCounter();
  21931. eventsToAdd.addEvent (MidiMessage::noteOff (midiChannel, midiNoteNumber), timeNow);
  21932. eventsToAdd.clear (0, timeNow - 500);
  21933. noteOffInternal (midiChannel, midiNoteNumber);
  21934. }
  21935. }
  21936. void MidiKeyboardState::noteOffInternal (const int midiChannel, const int midiNoteNumber)
  21937. {
  21938. if (isNoteOn (midiChannel, midiNoteNumber))
  21939. {
  21940. noteStates [midiNoteNumber] &= ~(1 << (midiChannel - 1));
  21941. for (int i = listeners.size(); --i >= 0;)
  21942. ((MidiKeyboardStateListener*) listeners.getUnchecked(i))
  21943. ->handleNoteOff (this, midiChannel, midiNoteNumber);
  21944. }
  21945. }
  21946. void MidiKeyboardState::allNotesOff (const int midiChannel)
  21947. {
  21948. const ScopedLock sl (lock);
  21949. if (midiChannel <= 0)
  21950. {
  21951. for (int i = 1; i <= 16; ++i)
  21952. allNotesOff (i);
  21953. }
  21954. else
  21955. {
  21956. for (int i = 0; i < 128; ++i)
  21957. noteOff (midiChannel, i);
  21958. }
  21959. }
  21960. void MidiKeyboardState::processNextMidiEvent (const MidiMessage& message)
  21961. {
  21962. if (message.isNoteOn())
  21963. {
  21964. noteOnInternal (message.getChannel(), message.getNoteNumber(), message.getFloatVelocity());
  21965. }
  21966. else if (message.isNoteOff())
  21967. {
  21968. noteOffInternal (message.getChannel(), message.getNoteNumber());
  21969. }
  21970. else if (message.isAllNotesOff())
  21971. {
  21972. for (int i = 0; i < 128; ++i)
  21973. noteOffInternal (message.getChannel(), i);
  21974. }
  21975. }
  21976. void MidiKeyboardState::processNextMidiBuffer (MidiBuffer& buffer,
  21977. const int startSample,
  21978. const int numSamples,
  21979. const bool injectIndirectEvents)
  21980. {
  21981. MidiBuffer::Iterator i (buffer);
  21982. MidiMessage message (0xf4, 0.0);
  21983. int time;
  21984. const ScopedLock sl (lock);
  21985. while (i.getNextEvent (message, time))
  21986. processNextMidiEvent (message);
  21987. if (injectIndirectEvents)
  21988. {
  21989. MidiBuffer::Iterator i2 (eventsToAdd);
  21990. const int firstEventToAdd = eventsToAdd.getFirstEventTime();
  21991. const double scaleFactor = numSamples / (double) (eventsToAdd.getLastEventTime() + 1 - firstEventToAdd);
  21992. while (i2.getNextEvent (message, time))
  21993. {
  21994. const int pos = jlimit (0, numSamples - 1, roundToInt ((time - firstEventToAdd) * scaleFactor));
  21995. buffer.addEvent (message, startSample + pos);
  21996. }
  21997. }
  21998. eventsToAdd.clear();
  21999. }
  22000. void MidiKeyboardState::addListener (MidiKeyboardStateListener* const listener) throw()
  22001. {
  22002. const ScopedLock sl (lock);
  22003. listeners.addIfNotAlreadyThere (listener);
  22004. }
  22005. void MidiKeyboardState::removeListener (MidiKeyboardStateListener* const listener) throw()
  22006. {
  22007. const ScopedLock sl (lock);
  22008. listeners.removeValue (listener);
  22009. }
  22010. END_JUCE_NAMESPACE
  22011. /*** End of inlined file: juce_MidiKeyboardState.cpp ***/
  22012. /*** Start of inlined file: juce_MidiMessage.cpp ***/
  22013. BEGIN_JUCE_NAMESPACE
  22014. int MidiMessage::readVariableLengthVal (const uint8* data,
  22015. int& numBytesUsed) throw()
  22016. {
  22017. numBytesUsed = 0;
  22018. int v = 0;
  22019. int i;
  22020. do
  22021. {
  22022. i = (int) *data++;
  22023. if (++numBytesUsed > 6)
  22024. break;
  22025. v = (v << 7) + (i & 0x7f);
  22026. } while (i & 0x80);
  22027. return v;
  22028. }
  22029. int MidiMessage::getMessageLengthFromFirstByte (const uint8 firstByte) throw()
  22030. {
  22031. // this method only works for valid starting bytes of a short midi message
  22032. jassert (firstByte >= 0x80
  22033. && firstByte != 0xf0
  22034. && firstByte != 0xf7);
  22035. static const char messageLengths[] =
  22036. {
  22037. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  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. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  22042. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  22043. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  22044. 1, 2, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
  22045. };
  22046. return messageLengths [firstByte & 0x7f];
  22047. }
  22048. MidiMessage::MidiMessage (const uint8* const d,
  22049. const int dataSize,
  22050. const double t) throw()
  22051. : timeStamp (t),
  22052. message (0),
  22053. size (dataSize)
  22054. {
  22055. jassert (dataSize > 0);
  22056. if (dataSize <= 4)
  22057. data = (uint8*) &message;
  22058. else
  22059. data = (uint8*) juce_malloc (dataSize);
  22060. memcpy (data, d, dataSize);
  22061. // check that the length matches the data..
  22062. jassert (size > 3 || *d >= 0xf0 || getMessageLengthFromFirstByte (*d) == size);
  22063. }
  22064. MidiMessage::MidiMessage (const int byte1,
  22065. const double t) throw()
  22066. : timeStamp (t),
  22067. data ((uint8*) &message),
  22068. size (1)
  22069. {
  22070. data[0] = (uint8) byte1;
  22071. // check that the length matches the data..
  22072. jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 1);
  22073. }
  22074. MidiMessage::MidiMessage (const int byte1,
  22075. const int byte2,
  22076. const double t) throw()
  22077. : timeStamp (t),
  22078. data ((uint8*) &message),
  22079. size (2)
  22080. {
  22081. data[0] = (uint8) byte1;
  22082. data[1] = (uint8) byte2;
  22083. // check that the length matches the data..
  22084. jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 2);
  22085. }
  22086. MidiMessage::MidiMessage (const int byte1,
  22087. const int byte2,
  22088. const int byte3,
  22089. const double t) throw()
  22090. : timeStamp (t),
  22091. data ((uint8*) &message),
  22092. size (3)
  22093. {
  22094. data[0] = (uint8) byte1;
  22095. data[1] = (uint8) byte2;
  22096. data[2] = (uint8) byte3;
  22097. // check that the length matches the data..
  22098. jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 3);
  22099. }
  22100. MidiMessage::MidiMessage (const MidiMessage& other) throw()
  22101. : timeStamp (other.timeStamp),
  22102. message (other.message),
  22103. size (other.size)
  22104. {
  22105. if (other.data != (uint8*) &other.message)
  22106. {
  22107. data = (uint8*) juce_malloc (size);
  22108. memcpy (data, other.data, size);
  22109. }
  22110. else
  22111. {
  22112. data = (uint8*) &message;
  22113. }
  22114. }
  22115. MidiMessage::MidiMessage (const MidiMessage& other,
  22116. const double newTimeStamp) throw()
  22117. : timeStamp (newTimeStamp),
  22118. message (other.message),
  22119. size (other.size)
  22120. {
  22121. if (other.data != (uint8*) &other.message)
  22122. {
  22123. data = (uint8*) juce_malloc (size);
  22124. memcpy (data, other.data, size);
  22125. }
  22126. else
  22127. {
  22128. data = (uint8*) &message;
  22129. }
  22130. }
  22131. MidiMessage::MidiMessage (const uint8* src,
  22132. int sz,
  22133. int& numBytesUsed,
  22134. const uint8 lastStatusByte,
  22135. double t) throw()
  22136. : timeStamp (t),
  22137. data ((uint8*) &message),
  22138. message (0)
  22139. {
  22140. unsigned int byte = (unsigned int) *src;
  22141. if (byte < 0x80)
  22142. {
  22143. byte = (unsigned int) (uint8) lastStatusByte;
  22144. numBytesUsed = -1;
  22145. }
  22146. else
  22147. {
  22148. numBytesUsed = 0;
  22149. --sz;
  22150. ++src;
  22151. }
  22152. if (byte >= 0x80)
  22153. {
  22154. if (byte == 0xf0)
  22155. {
  22156. const uint8* d = (const uint8*) src;
  22157. while (d < src + sz)
  22158. {
  22159. if (*d >= 0x80) // stop if we hit a status byte, and don't include it in this message
  22160. {
  22161. if (*d == 0xf7) // include an 0xf7 if we hit one
  22162. ++d;
  22163. break;
  22164. }
  22165. ++d;
  22166. }
  22167. size = 1 + (int) (d - src);
  22168. data = (uint8*) juce_malloc (size);
  22169. *data = (uint8) byte;
  22170. memcpy (data + 1, src, size - 1);
  22171. }
  22172. else if (byte == 0xff)
  22173. {
  22174. int n;
  22175. const int bytesLeft = readVariableLengthVal (src + 1, n);
  22176. size = jmin (sz + 1, n + 2 + bytesLeft);
  22177. data = (uint8*) juce_malloc (size);
  22178. *data = (uint8) byte;
  22179. memcpy (data + 1, src, size - 1);
  22180. }
  22181. else
  22182. {
  22183. size = getMessageLengthFromFirstByte ((uint8) byte);
  22184. *data = (uint8) byte;
  22185. if (size > 1)
  22186. {
  22187. data[1] = src[0];
  22188. if (size > 2)
  22189. data[2] = src[1];
  22190. }
  22191. }
  22192. numBytesUsed += size;
  22193. }
  22194. else
  22195. {
  22196. message = 0;
  22197. size = 0;
  22198. }
  22199. }
  22200. MidiMessage& MidiMessage::operator= (const MidiMessage& other) throw()
  22201. {
  22202. if (this != &other)
  22203. {
  22204. timeStamp = other.timeStamp;
  22205. size = other.size;
  22206. message = other.message;
  22207. if (data != (uint8*) &message)
  22208. juce_free (data);
  22209. if (other.data != (uint8*) &other.message)
  22210. {
  22211. data = (uint8*) juce_malloc (size);
  22212. memcpy (data, other.data, size);
  22213. }
  22214. else
  22215. {
  22216. data = (uint8*) &message;
  22217. }
  22218. }
  22219. return *this;
  22220. }
  22221. MidiMessage::~MidiMessage() throw()
  22222. {
  22223. if (data != (uint8*) &message)
  22224. juce_free (data);
  22225. }
  22226. int MidiMessage::getChannel() const throw()
  22227. {
  22228. if ((data[0] & 0xf0) != 0xf0)
  22229. return (data[0] & 0xf) + 1;
  22230. else
  22231. return 0;
  22232. }
  22233. bool MidiMessage::isForChannel (const int channel) const throw()
  22234. {
  22235. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22236. return ((data[0] & 0xf) == channel - 1)
  22237. && ((data[0] & 0xf0) != 0xf0);
  22238. }
  22239. void MidiMessage::setChannel (const int channel) throw()
  22240. {
  22241. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22242. if ((data[0] & 0xf0) != (uint8) 0xf0)
  22243. data[0] = (uint8) ((data[0] & (uint8)0xf0)
  22244. | (uint8)(channel - 1));
  22245. }
  22246. bool MidiMessage::isNoteOn (const bool returnTrueForVelocity0) const throw()
  22247. {
  22248. return ((data[0] & 0xf0) == 0x90)
  22249. && (returnTrueForVelocity0 || data[2] != 0);
  22250. }
  22251. bool MidiMessage::isNoteOff (const bool returnTrueForNoteOnVelocity0) const throw()
  22252. {
  22253. return ((data[0] & 0xf0) == 0x80)
  22254. || (returnTrueForNoteOnVelocity0 && (data[2] == 0) && ((data[0] & 0xf0) == 0x90));
  22255. }
  22256. bool MidiMessage::isNoteOnOrOff() const throw()
  22257. {
  22258. const int d = data[0] & 0xf0;
  22259. return (d == 0x90) || (d == 0x80);
  22260. }
  22261. int MidiMessage::getNoteNumber() const throw()
  22262. {
  22263. return data[1];
  22264. }
  22265. void MidiMessage::setNoteNumber (const int newNoteNumber) throw()
  22266. {
  22267. if (isNoteOnOrOff())
  22268. data[1] = (uint8) jlimit (0, 127, newNoteNumber);
  22269. }
  22270. uint8 MidiMessage::getVelocity() const throw()
  22271. {
  22272. if (isNoteOnOrOff())
  22273. return data[2];
  22274. else
  22275. return 0;
  22276. }
  22277. float MidiMessage::getFloatVelocity() const throw()
  22278. {
  22279. return getVelocity() * (1.0f / 127.0f);
  22280. }
  22281. void MidiMessage::setVelocity (const float newVelocity) throw()
  22282. {
  22283. if (isNoteOnOrOff())
  22284. data[2] = (uint8) jlimit (0, 0x7f, roundToInt (newVelocity * 127.0f));
  22285. }
  22286. void MidiMessage::multiplyVelocity (const float scaleFactor) throw()
  22287. {
  22288. if (isNoteOnOrOff())
  22289. data[2] = (uint8) jlimit (0, 0x7f, roundToInt (scaleFactor * data[2]));
  22290. }
  22291. bool MidiMessage::isAftertouch() const throw()
  22292. {
  22293. return (data[0] & 0xf0) == 0xa0;
  22294. }
  22295. int MidiMessage::getAfterTouchValue() const throw()
  22296. {
  22297. return data[2];
  22298. }
  22299. const MidiMessage MidiMessage::aftertouchChange (const int channel,
  22300. const int noteNum,
  22301. const int aftertouchValue) throw()
  22302. {
  22303. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22304. jassert (((unsigned int) noteNum) <= 127);
  22305. jassert (((unsigned int) aftertouchValue) <= 127);
  22306. return MidiMessage (0xa0 | jlimit (0, 15, channel - 1),
  22307. noteNum & 0x7f,
  22308. aftertouchValue & 0x7f);
  22309. }
  22310. bool MidiMessage::isChannelPressure() const throw()
  22311. {
  22312. return (data[0] & 0xf0) == 0xd0;
  22313. }
  22314. int MidiMessage::getChannelPressureValue() const throw()
  22315. {
  22316. jassert (isChannelPressure());
  22317. return data[1];
  22318. }
  22319. const MidiMessage MidiMessage::channelPressureChange (const int channel,
  22320. const int pressure) throw()
  22321. {
  22322. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22323. jassert (((unsigned int) pressure) <= 127);
  22324. return MidiMessage (0xd0 | jlimit (0, 15, channel - 1),
  22325. pressure & 0x7f);
  22326. }
  22327. bool MidiMessage::isProgramChange() const throw()
  22328. {
  22329. return (data[0] & 0xf0) == 0xc0;
  22330. }
  22331. int MidiMessage::getProgramChangeNumber() const throw()
  22332. {
  22333. return data[1];
  22334. }
  22335. const MidiMessage MidiMessage::programChange (const int channel,
  22336. const int programNumber) throw()
  22337. {
  22338. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22339. return MidiMessage (0xc0 | jlimit (0, 15, channel - 1),
  22340. programNumber & 0x7f);
  22341. }
  22342. bool MidiMessage::isPitchWheel() const throw()
  22343. {
  22344. return (data[0] & 0xf0) == 0xe0;
  22345. }
  22346. int MidiMessage::getPitchWheelValue() const throw()
  22347. {
  22348. return data[1] | (data[2] << 7);
  22349. }
  22350. const MidiMessage MidiMessage::pitchWheel (const int channel,
  22351. const int position) throw()
  22352. {
  22353. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22354. jassert (((unsigned int) position) <= 0x3fff);
  22355. return MidiMessage (0xe0 | jlimit (0, 15, channel - 1),
  22356. position & 127,
  22357. (position >> 7) & 127);
  22358. }
  22359. bool MidiMessage::isController() const throw()
  22360. {
  22361. return (data[0] & 0xf0) == 0xb0;
  22362. }
  22363. int MidiMessage::getControllerNumber() const throw()
  22364. {
  22365. jassert (isController());
  22366. return data[1];
  22367. }
  22368. int MidiMessage::getControllerValue() const throw()
  22369. {
  22370. jassert (isController());
  22371. return data[2];
  22372. }
  22373. const MidiMessage MidiMessage::controllerEvent (const int channel,
  22374. const int controllerType,
  22375. const int value) throw()
  22376. {
  22377. // the channel must be between 1 and 16 inclusive
  22378. jassert (channel > 0 && channel <= 16);
  22379. return MidiMessage (0xb0 | jlimit (0, 15, channel - 1),
  22380. controllerType & 127,
  22381. value & 127);
  22382. }
  22383. const MidiMessage MidiMessage::noteOn (const int channel,
  22384. const int noteNumber,
  22385. const float velocity) throw()
  22386. {
  22387. return noteOn (channel, noteNumber, (uint8)(velocity * 127.0f));
  22388. }
  22389. const MidiMessage MidiMessage::noteOn (const int channel,
  22390. const int noteNumber,
  22391. const uint8 velocity) throw()
  22392. {
  22393. jassert (channel > 0 && channel <= 16);
  22394. jassert (((unsigned int) noteNumber) <= 127);
  22395. return MidiMessage (0x90 | jlimit (0, 15, channel - 1),
  22396. noteNumber & 127,
  22397. jlimit (0, 127, roundToInt (velocity)));
  22398. }
  22399. const MidiMessage MidiMessage::noteOff (const int channel,
  22400. const int noteNumber) throw()
  22401. {
  22402. jassert (channel > 0 && channel <= 16);
  22403. jassert (((unsigned int) noteNumber) <= 127);
  22404. return MidiMessage (0x80 | jlimit (0, 15, channel - 1), noteNumber & 127, 0);
  22405. }
  22406. const MidiMessage MidiMessage::allNotesOff (const int channel) throw()
  22407. {
  22408. jassert (channel > 0 && channel <= 16);
  22409. return controllerEvent (channel, 123, 0);
  22410. }
  22411. bool MidiMessage::isAllNotesOff() const throw()
  22412. {
  22413. return (data[0] & 0xf0) == 0xb0
  22414. && data[1] == 123;
  22415. }
  22416. const MidiMessage MidiMessage::allSoundOff (const int channel) throw()
  22417. {
  22418. return controllerEvent (channel, 120, 0);
  22419. }
  22420. bool MidiMessage::isAllSoundOff() const throw()
  22421. {
  22422. return (data[0] & 0xf0) == 0xb0
  22423. && data[1] == 120;
  22424. }
  22425. const MidiMessage MidiMessage::allControllersOff (const int channel) throw()
  22426. {
  22427. return controllerEvent (channel, 121, 0);
  22428. }
  22429. const MidiMessage MidiMessage::masterVolume (const float volume) throw()
  22430. {
  22431. const int vol = jlimit (0, 0x3fff, roundToInt (volume * 0x4000));
  22432. uint8 buf[8];
  22433. buf[0] = 0xf0;
  22434. buf[1] = 0x7f;
  22435. buf[2] = 0x7f;
  22436. buf[3] = 0x04;
  22437. buf[4] = 0x01;
  22438. buf[5] = (uint8) (vol & 0x7f);
  22439. buf[6] = (uint8) (vol >> 7);
  22440. buf[7] = 0xf7;
  22441. return MidiMessage (buf, 8);
  22442. }
  22443. bool MidiMessage::isSysEx() const throw()
  22444. {
  22445. return *data == 0xf0;
  22446. }
  22447. const MidiMessage MidiMessage::createSysExMessage (const uint8* sysexData,
  22448. const int dataSize) throw()
  22449. {
  22450. MemoryBlock mm (dataSize + 2);
  22451. uint8* const m = (uint8*) mm.getData();
  22452. m[0] = 0xf0;
  22453. memcpy (m + 1, sysexData, dataSize);
  22454. m[dataSize + 1] = 0xf7;
  22455. return MidiMessage (m, dataSize + 2);
  22456. }
  22457. const uint8* MidiMessage::getSysExData() const throw()
  22458. {
  22459. return (isSysEx()) ? getRawData() + 1
  22460. : 0;
  22461. }
  22462. int MidiMessage::getSysExDataSize() const throw()
  22463. {
  22464. return (isSysEx()) ? size - 2
  22465. : 0;
  22466. }
  22467. bool MidiMessage::isMetaEvent() const throw()
  22468. {
  22469. return *data == 0xff;
  22470. }
  22471. bool MidiMessage::isActiveSense() const throw()
  22472. {
  22473. return *data == 0xfe;
  22474. }
  22475. int MidiMessage::getMetaEventType() const throw()
  22476. {
  22477. if (*data != 0xff)
  22478. return -1;
  22479. else
  22480. return data[1];
  22481. }
  22482. int MidiMessage::getMetaEventLength() const throw()
  22483. {
  22484. if (*data == 0xff)
  22485. {
  22486. int n;
  22487. return jmin (size - 2, readVariableLengthVal (data + 2, n));
  22488. }
  22489. return 0;
  22490. }
  22491. const uint8* MidiMessage::getMetaEventData() const throw()
  22492. {
  22493. int n;
  22494. const uint8* d = data + 2;
  22495. readVariableLengthVal (d, n);
  22496. return d + n;
  22497. }
  22498. bool MidiMessage::isTrackMetaEvent() const throw()
  22499. {
  22500. return getMetaEventType() == 0;
  22501. }
  22502. bool MidiMessage::isEndOfTrackMetaEvent() const throw()
  22503. {
  22504. return getMetaEventType() == 47;
  22505. }
  22506. bool MidiMessage::isTextMetaEvent() const throw()
  22507. {
  22508. const int t = getMetaEventType();
  22509. return t > 0 && t < 16;
  22510. }
  22511. const String MidiMessage::getTextFromTextMetaEvent() const throw()
  22512. {
  22513. return String ((const char*) getMetaEventData(),
  22514. getMetaEventLength());
  22515. }
  22516. bool MidiMessage::isTrackNameEvent() const throw()
  22517. {
  22518. return (data[1] == 3)
  22519. && (*data == 0xff);
  22520. }
  22521. bool MidiMessage::isTempoMetaEvent() const throw()
  22522. {
  22523. return (data[1] == 81)
  22524. && (*data == 0xff);
  22525. }
  22526. bool MidiMessage::isMidiChannelMetaEvent() const throw()
  22527. {
  22528. return (data[1] == 0x20)
  22529. && (*data == 0xff)
  22530. && (data[2] == 1);
  22531. }
  22532. int MidiMessage::getMidiChannelMetaEventChannel() const throw()
  22533. {
  22534. return data[3] + 1;
  22535. }
  22536. double MidiMessage::getTempoSecondsPerQuarterNote() const throw()
  22537. {
  22538. if (! isTempoMetaEvent())
  22539. return 0.0;
  22540. const uint8* const d = getMetaEventData();
  22541. return (((unsigned int) d[0] << 16)
  22542. | ((unsigned int) d[1] << 8)
  22543. | d[2])
  22544. / 1000000.0;
  22545. }
  22546. double MidiMessage::getTempoMetaEventTickLength (const short timeFormat) const throw()
  22547. {
  22548. if (timeFormat > 0)
  22549. {
  22550. if (! isTempoMetaEvent())
  22551. return 0.5 / timeFormat;
  22552. return getTempoSecondsPerQuarterNote() / timeFormat;
  22553. }
  22554. else
  22555. {
  22556. const int frameCode = (-timeFormat) >> 8;
  22557. double framesPerSecond;
  22558. switch (frameCode)
  22559. {
  22560. case 24: framesPerSecond = 24.0; break;
  22561. case 25: framesPerSecond = 25.0; break;
  22562. case 29: framesPerSecond = 29.97; break;
  22563. case 30: framesPerSecond = 30.0; break;
  22564. default: framesPerSecond = 30.0; break;
  22565. }
  22566. return (1.0 / framesPerSecond) / (timeFormat & 0xff);
  22567. }
  22568. }
  22569. const MidiMessage MidiMessage::tempoMetaEvent (int microsecondsPerQuarterNote) throw()
  22570. {
  22571. uint8 d[8];
  22572. d[0] = 0xff;
  22573. d[1] = 81;
  22574. d[2] = 3;
  22575. d[3] = (uint8) (microsecondsPerQuarterNote >> 16);
  22576. d[4] = (uint8) ((microsecondsPerQuarterNote >> 8) & 0xff);
  22577. d[5] = (uint8) (microsecondsPerQuarterNote & 0xff);
  22578. return MidiMessage (d, 6, 0.0);
  22579. }
  22580. bool MidiMessage::isTimeSignatureMetaEvent() const throw()
  22581. {
  22582. return (data[1] == 0x58)
  22583. && (*data == (uint8) 0xff);
  22584. }
  22585. void MidiMessage::getTimeSignatureInfo (int& numerator,
  22586. int& denominator) const throw()
  22587. {
  22588. if (isTimeSignatureMetaEvent())
  22589. {
  22590. const uint8* const d = getMetaEventData();
  22591. numerator = d[0];
  22592. denominator = 1 << d[1];
  22593. }
  22594. else
  22595. {
  22596. numerator = 4;
  22597. denominator = 4;
  22598. }
  22599. }
  22600. const MidiMessage MidiMessage::timeSignatureMetaEvent (const int numerator,
  22601. const int denominator) throw()
  22602. {
  22603. uint8 d[8];
  22604. d[0] = 0xff;
  22605. d[1] = 0x58;
  22606. d[2] = 0x04;
  22607. d[3] = (uint8) numerator;
  22608. int n = 1;
  22609. int powerOfTwo = 0;
  22610. while (n < denominator)
  22611. {
  22612. n <<= 1;
  22613. ++powerOfTwo;
  22614. }
  22615. d[4] = (uint8) powerOfTwo;
  22616. d[5] = 0x01;
  22617. d[6] = 96;
  22618. return MidiMessage (d, 7, 0.0);
  22619. }
  22620. const MidiMessage MidiMessage::midiChannelMetaEvent (const int channel) throw()
  22621. {
  22622. uint8 d[8];
  22623. d[0] = 0xff;
  22624. d[1] = 0x20;
  22625. d[2] = 0x01;
  22626. d[3] = (uint8) jlimit (0, 0xff, channel - 1);
  22627. return MidiMessage (d, 4, 0.0);
  22628. }
  22629. bool MidiMessage::isKeySignatureMetaEvent() const throw()
  22630. {
  22631. return getMetaEventType() == 89;
  22632. }
  22633. int MidiMessage::getKeySignatureNumberOfSharpsOrFlats() const throw()
  22634. {
  22635. return (int) *getMetaEventData();
  22636. }
  22637. const MidiMessage MidiMessage::endOfTrack() throw()
  22638. {
  22639. return MidiMessage (0xff, 0x2f, 0, 0.0);
  22640. }
  22641. bool MidiMessage::isSongPositionPointer() const throw()
  22642. {
  22643. return *data == 0xf2;
  22644. }
  22645. int MidiMessage::getSongPositionPointerMidiBeat() const throw()
  22646. {
  22647. return data[1] | (data[2] << 7);
  22648. }
  22649. const MidiMessage MidiMessage::songPositionPointer (const int positionInMidiBeats) throw()
  22650. {
  22651. return MidiMessage (0xf2,
  22652. positionInMidiBeats & 127,
  22653. (positionInMidiBeats >> 7) & 127);
  22654. }
  22655. bool MidiMessage::isMidiStart() const throw()
  22656. {
  22657. return *data == 0xfa;
  22658. }
  22659. const MidiMessage MidiMessage::midiStart() throw()
  22660. {
  22661. return MidiMessage (0xfa);
  22662. }
  22663. bool MidiMessage::isMidiContinue() const throw()
  22664. {
  22665. return *data == 0xfb;
  22666. }
  22667. const MidiMessage MidiMessage::midiContinue() throw()
  22668. {
  22669. return MidiMessage (0xfb);
  22670. }
  22671. bool MidiMessage::isMidiStop() const throw()
  22672. {
  22673. return *data == 0xfc;
  22674. }
  22675. const MidiMessage MidiMessage::midiStop() throw()
  22676. {
  22677. return MidiMessage (0xfc);
  22678. }
  22679. bool MidiMessage::isMidiClock() const throw()
  22680. {
  22681. return *data == 0xf8;
  22682. }
  22683. const MidiMessage MidiMessage::midiClock() throw()
  22684. {
  22685. return MidiMessage (0xf8);
  22686. }
  22687. bool MidiMessage::isQuarterFrame() const throw()
  22688. {
  22689. return *data == 0xf1;
  22690. }
  22691. int MidiMessage::getQuarterFrameSequenceNumber() const throw()
  22692. {
  22693. return ((int) data[1]) >> 4;
  22694. }
  22695. int MidiMessage::getQuarterFrameValue() const throw()
  22696. {
  22697. return ((int) data[1]) & 0x0f;
  22698. }
  22699. const MidiMessage MidiMessage::quarterFrame (const int sequenceNumber,
  22700. const int value) throw()
  22701. {
  22702. return MidiMessage (0xf1, (sequenceNumber << 4) | value);
  22703. }
  22704. bool MidiMessage::isFullFrame() const throw()
  22705. {
  22706. return data[0] == 0xf0
  22707. && data[1] == 0x7f
  22708. && size >= 10
  22709. && data[3] == 0x01
  22710. && data[4] == 0x01;
  22711. }
  22712. void MidiMessage::getFullFrameParameters (int& hours,
  22713. int& minutes,
  22714. int& seconds,
  22715. int& frames,
  22716. MidiMessage::SmpteTimecodeType& timecodeType) const throw()
  22717. {
  22718. jassert (isFullFrame());
  22719. timecodeType = (SmpteTimecodeType) (data[5] >> 5);
  22720. hours = data[5] & 0x1f;
  22721. minutes = data[6];
  22722. seconds = data[7];
  22723. frames = data[8];
  22724. }
  22725. const MidiMessage MidiMessage::fullFrame (const int hours,
  22726. const int minutes,
  22727. const int seconds,
  22728. const int frames,
  22729. MidiMessage::SmpteTimecodeType timecodeType)
  22730. {
  22731. uint8 d[10];
  22732. d[0] = 0xf0;
  22733. d[1] = 0x7f;
  22734. d[2] = 0x7f;
  22735. d[3] = 0x01;
  22736. d[4] = 0x01;
  22737. d[5] = (uint8) ((hours & 0x01f) | (timecodeType << 5));
  22738. d[6] = (uint8) minutes;
  22739. d[7] = (uint8) seconds;
  22740. d[8] = (uint8) frames;
  22741. d[9] = 0xf7;
  22742. return MidiMessage (d, 10, 0.0);
  22743. }
  22744. bool MidiMessage::isMidiMachineControlMessage() const throw()
  22745. {
  22746. return data[0] == 0xf0
  22747. && data[1] == 0x7f
  22748. && data[3] == 0x06
  22749. && size > 5;
  22750. }
  22751. MidiMessage::MidiMachineControlCommand MidiMessage::getMidiMachineControlCommand() const throw()
  22752. {
  22753. jassert (isMidiMachineControlMessage());
  22754. return (MidiMachineControlCommand) data[4];
  22755. }
  22756. const MidiMessage MidiMessage::midiMachineControlCommand (MidiMessage::MidiMachineControlCommand command)
  22757. {
  22758. uint8 d[6];
  22759. d[0] = 0xf0;
  22760. d[1] = 0x7f;
  22761. d[2] = 0x00;
  22762. d[3] = 0x06;
  22763. d[4] = (uint8) command;
  22764. d[5] = 0xf7;
  22765. return MidiMessage (d, 6, 0.0);
  22766. }
  22767. bool MidiMessage::isMidiMachineControlGoto (int& hours,
  22768. int& minutes,
  22769. int& seconds,
  22770. int& frames) const throw()
  22771. {
  22772. if (size >= 12
  22773. && data[0] == 0xf0
  22774. && data[1] == 0x7f
  22775. && data[3] == 0x06
  22776. && data[4] == 0x44
  22777. && data[5] == 0x06
  22778. && data[6] == 0x01)
  22779. {
  22780. hours = data[7] % 24; // (that some machines send out hours > 24)
  22781. minutes = data[8];
  22782. seconds = data[9];
  22783. frames = data[10];
  22784. return true;
  22785. }
  22786. return false;
  22787. }
  22788. const MidiMessage MidiMessage::midiMachineControlGoto (int hours,
  22789. int minutes,
  22790. int seconds,
  22791. int frames)
  22792. {
  22793. uint8 d[12];
  22794. d[0] = 0xf0;
  22795. d[1] = 0x7f;
  22796. d[2] = 0x00;
  22797. d[3] = 0x06;
  22798. d[4] = 0x44;
  22799. d[5] = 0x06;
  22800. d[6] = 0x01;
  22801. d[7] = (uint8) hours;
  22802. d[8] = (uint8) minutes;
  22803. d[9] = (uint8) seconds;
  22804. d[10] = (uint8) frames;
  22805. d[11] = 0xf7;
  22806. return MidiMessage (d, 12, 0.0);
  22807. }
  22808. const String MidiMessage::getMidiNoteName (int note,
  22809. bool useSharps,
  22810. bool includeOctaveNumber,
  22811. int octaveNumForMiddleC) throw()
  22812. {
  22813. static const char* const sharpNoteNames[] = { "C", "C#", "D", "D#", "E",
  22814. "F", "F#", "G", "G#", "A",
  22815. "A#", "B" };
  22816. static const char* const flatNoteNames[] = { "C", "Db", "D", "Eb", "E",
  22817. "F", "Gb", "G", "Ab", "A",
  22818. "Bb", "B" };
  22819. if (((unsigned int) note) < 128)
  22820. {
  22821. const String s ((useSharps) ? sharpNoteNames [note % 12]
  22822. : flatNoteNames [note % 12]);
  22823. if (includeOctaveNumber)
  22824. return s + String (note / 12 + (octaveNumForMiddleC - 5));
  22825. else
  22826. return s;
  22827. }
  22828. return String::empty;
  22829. }
  22830. const double MidiMessage::getMidiNoteInHertz (int noteNumber) throw()
  22831. {
  22832. noteNumber -= 12 * 6 + 9; // now 0 = A440
  22833. return 440.0 * pow (2.0, noteNumber / 12.0);
  22834. }
  22835. const String MidiMessage::getGMInstrumentName (int n) throw()
  22836. {
  22837. const char *names[] =
  22838. {
  22839. "Acoustic Grand Piano", "Bright Acoustic Piano", "Electric Grand Piano", "Honky-tonk Piano",
  22840. "Electric Piano 1", "Electric Piano 2", "Harpsichord", "Clavinet", "Celesta", "Glockenspiel",
  22841. "Music Box", "Vibraphone", "Marimba", "Xylophone", "Tubular Bells", "Dulcimer", "Drawbar Organ",
  22842. "Percussive Organ", "Rock Organ", "Church Organ", "Reed Organ", "Accordion", "Harmonica",
  22843. "Tango Accordion", "Acoustic Guitar (nylon)", "Acoustic Guitar (steel)", "Electric Guitar (jazz)",
  22844. "Electric Guitar (clean)", "Electric Guitar (mute)", "Overdriven Guitar", "Distortion Guitar",
  22845. "Guitar Harmonics", "Acoustic Bass", "Electric Bass (finger)", "Electric Bass (pick)",
  22846. "Fretless Bass", "Slap Bass 1", "Slap Bass 2", "Synth Bass 1", "Synth Bass 2", "Violin",
  22847. "Viola", "Cello", "Contrabass", "Tremolo Strings", "Pizzicato Strings", "Orchestral Harp",
  22848. "Timpani", "String Ensemble 1", "String Ensemble 2", "SynthStrings 1", "SynthStrings 2",
  22849. "Choir Aahs", "Voice Oohs", "Synth Voice", "Orchestra Hit", "Trumpet", "Trombone", "Tuba",
  22850. "Muted Trumpet", "French Horn", "Brass Section", "SynthBrass 1", "SynthBrass 2", "Soprano Sax",
  22851. "Alto Sax", "Tenor Sax", "Baritone Sax", "Oboe", "English Horn", "Bassoon", "Clarinet",
  22852. "Piccolo", "Flute", "Recorder", "Pan Flute", "Blown Bottle", "Shakuhachi", "Whistle",
  22853. "Ocarina", "Lead 1 (square)", "Lead 2 (sawtooth)", "Lead 3 (calliope)", "Lead 4 (chiff)",
  22854. "Lead 5 (charang)", "Lead 6 (voice)", "Lead 7 (fifths)", "Lead 8 (bass+lead)", "Pad 1 (new age)",
  22855. "Pad 2 (warm)", "Pad 3 (polysynth)", "Pad 4 (choir)", "Pad 5 (bowed)", "Pad 6 (metallic)",
  22856. "Pad 7 (halo)", "Pad 8 (sweep)", "FX 1 (rain)", "FX 2 (soundtrack)", "FX 3 (crystal)",
  22857. "FX 4 (atmosphere)", "FX 5 (brightness)", "FX 6 (goblins)", "FX 7 (echoes)", "FX 8 (sci-fi)",
  22858. "Sitar", "Banjo", "Shamisen", "Koto", "Kalimba", "Bag pipe", "Fiddle", "Shanai", "Tinkle Bell",
  22859. "Agogo", "Steel Drums", "Woodblock", "Taiko Drum", "Melodic Tom", "Synth Drum", "Reverse Cymbal",
  22860. "Guitar Fret Noise", "Breath Noise", "Seashore", "Bird Tweet", "Telephone Ring", "Helicopter",
  22861. "Applause", "Gunshot"
  22862. };
  22863. return (((unsigned int) n) < 128) ? names[n]
  22864. : (const char*)0;
  22865. }
  22866. const String MidiMessage::getGMInstrumentBankName (int n) throw()
  22867. {
  22868. const char* names[] =
  22869. {
  22870. "Piano", "Chromatic Percussion", "Organ", "Guitar",
  22871. "Bass", "Strings", "Ensemble", "Brass",
  22872. "Reed", "Pipe", "Synth Lead", "Synth Pad",
  22873. "Synth Effects", "Ethnic", "Percussive", "Sound Effects"
  22874. };
  22875. return (((unsigned int) n) <= 15) ? names[n]
  22876. : (const char*)0;
  22877. }
  22878. const String MidiMessage::getRhythmInstrumentName (int n) throw()
  22879. {
  22880. const char* names[] =
  22881. {
  22882. "Acoustic Bass Drum", "Bass Drum 1", "Side Stick", "Acoustic Snare",
  22883. "Hand Clap", "Electric Snare", "Low Floor Tom", "Closed Hi-Hat", "High Floor Tom",
  22884. "Pedal Hi-Hat", "Low Tom", "Open Hi-Hat", "Low-Mid Tom", "Hi-Mid Tom", "Crash Cymbal 1",
  22885. "High Tom", "Ride Cymbal 1", "Chinese Cymbal", "Ride Bell", "Tambourine", "Splash Cymbal",
  22886. "Cowbell", "Crash Cymbal 2", "Vibraslap", "Ride Cymbal 2", "Hi Bongo", "Low Bongo",
  22887. "Mute Hi Conga", "Open Hi Conga", "Low Conga", "High Timbale", "Low Timbale", "High Agogo",
  22888. "Low Agogo", "Cabasa", "Maracas", "Short Whistle", "Long Whistle", "Short Guiro",
  22889. "Long Guiro", "Claves", "Hi Wood Block", "Low Wood Block", "Mute Cuica", "Open Cuica",
  22890. "Mute Triangle", "Open Triangle"
  22891. };
  22892. return (n >= 35 && n <= 81) ? names [n - 35]
  22893. : (const char*)0;
  22894. }
  22895. const String MidiMessage::getControllerName (int n) throw()
  22896. {
  22897. const char* names[] =
  22898. {
  22899. "Bank Select", "Modulation Wheel (coarse)", "Breath controller (coarse)",
  22900. 0, "Foot Pedal (coarse)", "Portamento Time (coarse)",
  22901. "Data Entry (coarse)", "Volume (coarse)", "Balance (coarse)",
  22902. 0, "Pan position (coarse)", "Expression (coarse)", "Effect Control 1 (coarse)",
  22903. "Effect Control 2 (coarse)", 0, 0, "General Purpose Slider 1", "General Purpose Slider 2",
  22904. "General Purpose Slider 3", "General Purpose Slider 4", 0, 0, 0, 0, 0, 0, 0, 0,
  22905. 0, 0, 0, 0, "Bank Select (fine)", "Modulation Wheel (fine)", "Breath controller (fine)",
  22906. 0, "Foot Pedal (fine)", "Portamento Time (fine)", "Data Entry (fine)", "Volume (fine)",
  22907. "Balance (fine)", 0, "Pan position (fine)", "Expression (fine)", "Effect Control 1 (fine)",
  22908. "Effect Control 2 (fine)", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  22909. "Hold Pedal (on/off)", "Portamento (on/off)", "Sustenuto Pedal (on/off)", "Soft Pedal (on/off)",
  22910. "Legato Pedal (on/off)", "Hold 2 Pedal (on/off)", "Sound Variation", "Sound Timbre",
  22911. "Sound Release Time", "Sound Attack Time", "Sound Brightness", "Sound Control 6",
  22912. "Sound Control 7", "Sound Control 8", "Sound Control 9", "Sound Control 10",
  22913. "General Purpose Button 1 (on/off)", "General Purpose Button 2 (on/off)",
  22914. "General Purpose Button 3 (on/off)", "General Purpose Button 4 (on/off)",
  22915. 0, 0, 0, 0, 0, 0, 0, "Reverb Level", "Tremolo Level", "Chorus Level", "Celeste Level",
  22916. "Phaser Level", "Data Button increment", "Data Button decrement", "Non-registered Parameter (fine)",
  22917. "Non-registered Parameter (coarse)", "Registered Parameter (fine)", "Registered Parameter (coarse)",
  22918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "All Sound Off", "All Controllers Off",
  22919. "Local Keyboard (on/off)", "All Notes Off", "Omni Mode Off", "Omni Mode On", "Mono Operation",
  22920. "Poly Operation"
  22921. };
  22922. return (((unsigned int) n) < 128) ? names[n]
  22923. : (const char*)0;
  22924. }
  22925. END_JUCE_NAMESPACE
  22926. /*** End of inlined file: juce_MidiMessage.cpp ***/
  22927. /*** Start of inlined file: juce_MidiMessageCollector.cpp ***/
  22928. BEGIN_JUCE_NAMESPACE
  22929. MidiMessageCollector::MidiMessageCollector()
  22930. : lastCallbackTime (0),
  22931. sampleRate (44100.0001)
  22932. {
  22933. }
  22934. MidiMessageCollector::~MidiMessageCollector()
  22935. {
  22936. }
  22937. void MidiMessageCollector::reset (const double sampleRate_)
  22938. {
  22939. jassert (sampleRate_ > 0);
  22940. const ScopedLock sl (midiCallbackLock);
  22941. sampleRate = sampleRate_;
  22942. incomingMessages.clear();
  22943. lastCallbackTime = Time::getMillisecondCounterHiRes();
  22944. }
  22945. void MidiMessageCollector::addMessageToQueue (const MidiMessage& message)
  22946. {
  22947. // you need to call reset() to set the correct sample rate before using this object
  22948. jassert (sampleRate != 44100.0001);
  22949. // the messages that come in here need to be time-stamped correctly - see MidiInput
  22950. // for details of what the number should be.
  22951. jassert (message.getTimeStamp() != 0);
  22952. const ScopedLock sl (midiCallbackLock);
  22953. const int sampleNumber
  22954. = (int) ((message.getTimeStamp() - 0.001 * lastCallbackTime) * sampleRate);
  22955. incomingMessages.addEvent (message, sampleNumber);
  22956. // if the messages don't get used for over a second, we'd better
  22957. // get rid of any old ones to avoid the queue getting too big
  22958. if (sampleNumber > sampleRate)
  22959. incomingMessages.clear (0, sampleNumber - (int) sampleRate);
  22960. }
  22961. void MidiMessageCollector::removeNextBlockOfMessages (MidiBuffer& destBuffer,
  22962. const int numSamples)
  22963. {
  22964. // you need to call reset() to set the correct sample rate before using this object
  22965. jassert (sampleRate != 44100.0001);
  22966. const double timeNow = Time::getMillisecondCounterHiRes();
  22967. const double msElapsed = timeNow - lastCallbackTime;
  22968. const ScopedLock sl (midiCallbackLock);
  22969. lastCallbackTime = timeNow;
  22970. if (! incomingMessages.isEmpty())
  22971. {
  22972. int numSourceSamples = jmax (1, roundToInt (msElapsed * 0.001 * sampleRate));
  22973. int startSample = 0;
  22974. int scale = 1 << 16;
  22975. const uint8* midiData;
  22976. int numBytes, samplePosition;
  22977. MidiBuffer::Iterator iter (incomingMessages);
  22978. if (numSourceSamples > numSamples)
  22979. {
  22980. // if our list of events is longer than the buffer we're being
  22981. // asked for, scale them down to squeeze them all in..
  22982. const int maxBlockLengthToUse = numSamples << 5;
  22983. if (numSourceSamples > maxBlockLengthToUse)
  22984. {
  22985. startSample = numSourceSamples - maxBlockLengthToUse;
  22986. numSourceSamples = maxBlockLengthToUse;
  22987. iter.setNextSamplePosition (startSample);
  22988. }
  22989. scale = (numSamples << 10) / numSourceSamples;
  22990. while (iter.getNextEvent (midiData, numBytes, samplePosition))
  22991. {
  22992. samplePosition = ((samplePosition - startSample) * scale) >> 10;
  22993. destBuffer.addEvent (midiData, numBytes,
  22994. jlimit (0, numSamples - 1, samplePosition));
  22995. }
  22996. }
  22997. else
  22998. {
  22999. // if our event list is shorter than the number we need, put them
  23000. // towards the end of the buffer
  23001. startSample = numSamples - numSourceSamples;
  23002. while (iter.getNextEvent (midiData, numBytes, samplePosition))
  23003. {
  23004. destBuffer.addEvent (midiData, numBytes,
  23005. jlimit (0, numSamples - 1, samplePosition + startSample));
  23006. }
  23007. }
  23008. incomingMessages.clear();
  23009. }
  23010. }
  23011. void MidiMessageCollector::handleNoteOn (MidiKeyboardState*, int midiChannel, int midiNoteNumber, float velocity)
  23012. {
  23013. MidiMessage m (MidiMessage::noteOn (midiChannel, midiNoteNumber, velocity));
  23014. m.setTimeStamp (Time::getMillisecondCounterHiRes() * 0.001);
  23015. addMessageToQueue (m);
  23016. }
  23017. void MidiMessageCollector::handleNoteOff (MidiKeyboardState*, int midiChannel, int midiNoteNumber)
  23018. {
  23019. MidiMessage m (MidiMessage::noteOff (midiChannel, midiNoteNumber));
  23020. m.setTimeStamp (Time::getMillisecondCounterHiRes() * 0.001);
  23021. addMessageToQueue (m);
  23022. }
  23023. void MidiMessageCollector::handleIncomingMidiMessage (MidiInput*, const MidiMessage& message)
  23024. {
  23025. addMessageToQueue (message);
  23026. }
  23027. END_JUCE_NAMESPACE
  23028. /*** End of inlined file: juce_MidiMessageCollector.cpp ***/
  23029. /*** Start of inlined file: juce_MidiMessageSequence.cpp ***/
  23030. BEGIN_JUCE_NAMESPACE
  23031. MidiMessageSequence::MidiMessageSequence()
  23032. {
  23033. }
  23034. MidiMessageSequence::MidiMessageSequence (const MidiMessageSequence& other)
  23035. {
  23036. list.ensureStorageAllocated (other.list.size());
  23037. for (int i = 0; i < other.list.size(); ++i)
  23038. list.add (new MidiEventHolder (other.list.getUnchecked(i)->message));
  23039. }
  23040. MidiMessageSequence& MidiMessageSequence::operator= (const MidiMessageSequence& other)
  23041. {
  23042. MidiMessageSequence otherCopy (other);
  23043. swapWith (otherCopy);
  23044. return *this;
  23045. }
  23046. void MidiMessageSequence::swapWith (MidiMessageSequence& other) throw()
  23047. {
  23048. list.swapWithArray (other.list);
  23049. }
  23050. MidiMessageSequence::~MidiMessageSequence()
  23051. {
  23052. }
  23053. void MidiMessageSequence::clear()
  23054. {
  23055. list.clear();
  23056. }
  23057. int MidiMessageSequence::getNumEvents() const
  23058. {
  23059. return list.size();
  23060. }
  23061. MidiMessageSequence::MidiEventHolder* MidiMessageSequence::getEventPointer (const int index) const
  23062. {
  23063. return list [index];
  23064. }
  23065. double MidiMessageSequence::getTimeOfMatchingKeyUp (const int index) const
  23066. {
  23067. const MidiEventHolder* const meh = list [index];
  23068. if (meh != 0 && meh->noteOffObject != 0)
  23069. return meh->noteOffObject->message.getTimeStamp();
  23070. else
  23071. return 0.0;
  23072. }
  23073. int MidiMessageSequence::getIndexOfMatchingKeyUp (const int index) const
  23074. {
  23075. const MidiEventHolder* const meh = list [index];
  23076. return (meh != 0) ? list.indexOf (meh->noteOffObject) : -1;
  23077. }
  23078. int MidiMessageSequence::getIndexOf (MidiEventHolder* const event) const
  23079. {
  23080. return list.indexOf (event);
  23081. }
  23082. int MidiMessageSequence::getNextIndexAtTime (const double timeStamp) const
  23083. {
  23084. const int numEvents = list.size();
  23085. int i;
  23086. for (i = 0; i < numEvents; ++i)
  23087. if (list.getUnchecked(i)->message.getTimeStamp() >= timeStamp)
  23088. break;
  23089. return i;
  23090. }
  23091. double MidiMessageSequence::getStartTime() const
  23092. {
  23093. if (list.size() > 0)
  23094. return list.getUnchecked(0)->message.getTimeStamp();
  23095. else
  23096. return 0;
  23097. }
  23098. double MidiMessageSequence::getEndTime() const
  23099. {
  23100. if (list.size() > 0)
  23101. return list.getLast()->message.getTimeStamp();
  23102. else
  23103. return 0;
  23104. }
  23105. double MidiMessageSequence::getEventTime (const int index) const
  23106. {
  23107. if (((unsigned int) index) < (unsigned int) list.size())
  23108. return list.getUnchecked (index)->message.getTimeStamp();
  23109. return 0.0;
  23110. }
  23111. void MidiMessageSequence::addEvent (const MidiMessage& newMessage,
  23112. double timeAdjustment)
  23113. {
  23114. MidiEventHolder* const newOne = new MidiEventHolder (newMessage);
  23115. timeAdjustment += newMessage.getTimeStamp();
  23116. newOne->message.setTimeStamp (timeAdjustment);
  23117. int i;
  23118. for (i = list.size(); --i >= 0;)
  23119. if (list.getUnchecked(i)->message.getTimeStamp() <= timeAdjustment)
  23120. break;
  23121. list.insert (i + 1, newOne);
  23122. }
  23123. void MidiMessageSequence::deleteEvent (const int index,
  23124. const bool deleteMatchingNoteUp)
  23125. {
  23126. if (((unsigned int) index) < (unsigned int) list.size())
  23127. {
  23128. if (deleteMatchingNoteUp)
  23129. deleteEvent (getIndexOfMatchingKeyUp (index), false);
  23130. list.remove (index);
  23131. }
  23132. }
  23133. void MidiMessageSequence::addSequence (const MidiMessageSequence& other,
  23134. double timeAdjustment,
  23135. double firstAllowableTime,
  23136. double endOfAllowableDestTimes)
  23137. {
  23138. firstAllowableTime -= timeAdjustment;
  23139. endOfAllowableDestTimes -= timeAdjustment;
  23140. for (int i = 0; i < other.list.size(); ++i)
  23141. {
  23142. const MidiMessage& m = other.list.getUnchecked(i)->message;
  23143. const double t = m.getTimeStamp();
  23144. if (t >= firstAllowableTime && t < endOfAllowableDestTimes)
  23145. {
  23146. MidiEventHolder* const newOne = new MidiEventHolder (m);
  23147. newOne->message.setTimeStamp (timeAdjustment + t);
  23148. list.add (newOne);
  23149. }
  23150. }
  23151. sort();
  23152. }
  23153. int MidiMessageSequence::compareElements (const MidiMessageSequence::MidiEventHolder* const first,
  23154. const MidiMessageSequence::MidiEventHolder* const second) throw()
  23155. {
  23156. const double diff = first->message.getTimeStamp()
  23157. - second->message.getTimeStamp();
  23158. return (diff > 0) - (diff < 0);
  23159. }
  23160. void MidiMessageSequence::sort()
  23161. {
  23162. list.sort (*this, true);
  23163. }
  23164. void MidiMessageSequence::updateMatchedPairs()
  23165. {
  23166. for (int i = 0; i < list.size(); ++i)
  23167. {
  23168. const MidiMessage& m1 = list.getUnchecked(i)->message;
  23169. if (m1.isNoteOn())
  23170. {
  23171. list.getUnchecked(i)->noteOffObject = 0;
  23172. const int note = m1.getNoteNumber();
  23173. const int chan = m1.getChannel();
  23174. const int len = list.size();
  23175. for (int j = i + 1; j < len; ++j)
  23176. {
  23177. const MidiMessage& m = list.getUnchecked(j)->message;
  23178. if (m.getNoteNumber() == note && m.getChannel() == chan)
  23179. {
  23180. if (m.isNoteOff())
  23181. {
  23182. list.getUnchecked(i)->noteOffObject = list[j];
  23183. break;
  23184. }
  23185. else if (m.isNoteOn())
  23186. {
  23187. list.insert (j, new MidiEventHolder (MidiMessage::noteOff (chan, note)));
  23188. list.getUnchecked(j)->message.setTimeStamp (m.getTimeStamp());
  23189. list.getUnchecked(i)->noteOffObject = list[j];
  23190. break;
  23191. }
  23192. }
  23193. }
  23194. }
  23195. }
  23196. }
  23197. void MidiMessageSequence::addTimeToMessages (const double delta)
  23198. {
  23199. for (int i = list.size(); --i >= 0;)
  23200. list.getUnchecked (i)->message.setTimeStamp (list.getUnchecked (i)->message.getTimeStamp()
  23201. + delta);
  23202. }
  23203. void MidiMessageSequence::extractMidiChannelMessages (const int channelNumberToExtract,
  23204. MidiMessageSequence& destSequence,
  23205. const bool alsoIncludeMetaEvents) const
  23206. {
  23207. for (int i = 0; i < list.size(); ++i)
  23208. {
  23209. const MidiMessage& mm = list.getUnchecked(i)->message;
  23210. if (mm.isForChannel (channelNumberToExtract)
  23211. || (alsoIncludeMetaEvents && mm.isMetaEvent()))
  23212. {
  23213. destSequence.addEvent (mm);
  23214. }
  23215. }
  23216. }
  23217. void MidiMessageSequence::extractSysExMessages (MidiMessageSequence& destSequence) const
  23218. {
  23219. for (int i = 0; i < list.size(); ++i)
  23220. {
  23221. const MidiMessage& mm = list.getUnchecked(i)->message;
  23222. if (mm.isSysEx())
  23223. destSequence.addEvent (mm);
  23224. }
  23225. }
  23226. void MidiMessageSequence::deleteMidiChannelMessages (const int channelNumberToRemove)
  23227. {
  23228. for (int i = list.size(); --i >= 0;)
  23229. if (list.getUnchecked(i)->message.isForChannel (channelNumberToRemove))
  23230. list.remove(i);
  23231. }
  23232. void MidiMessageSequence::deleteSysExMessages()
  23233. {
  23234. for (int i = list.size(); --i >= 0;)
  23235. if (list.getUnchecked(i)->message.isSysEx())
  23236. list.remove(i);
  23237. }
  23238. void MidiMessageSequence::createControllerUpdatesForTime (const int channelNumber,
  23239. const double time,
  23240. OwnedArray<MidiMessage>& dest)
  23241. {
  23242. bool doneProg = false;
  23243. bool donePitchWheel = false;
  23244. Array <int> doneControllers;
  23245. doneControllers.ensureStorageAllocated (32);
  23246. for (int i = list.size(); --i >= 0;)
  23247. {
  23248. const MidiMessage& mm = list.getUnchecked(i)->message;
  23249. if (mm.isForChannel (channelNumber)
  23250. && mm.getTimeStamp() <= time)
  23251. {
  23252. if (mm.isProgramChange())
  23253. {
  23254. if (! doneProg)
  23255. {
  23256. dest.add (new MidiMessage (mm, 0.0));
  23257. doneProg = true;
  23258. }
  23259. }
  23260. else if (mm.isController())
  23261. {
  23262. if (! doneControllers.contains (mm.getControllerNumber()))
  23263. {
  23264. dest.add (new MidiMessage (mm, 0.0));
  23265. doneControllers.add (mm.getControllerNumber());
  23266. }
  23267. }
  23268. else if (mm.isPitchWheel())
  23269. {
  23270. if (! donePitchWheel)
  23271. {
  23272. dest.add (new MidiMessage (mm, 0.0));
  23273. donePitchWheel = true;
  23274. }
  23275. }
  23276. }
  23277. }
  23278. }
  23279. MidiMessageSequence::MidiEventHolder::MidiEventHolder (const MidiMessage& message_)
  23280. : message (message_),
  23281. noteOffObject (0)
  23282. {
  23283. }
  23284. MidiMessageSequence::MidiEventHolder::~MidiEventHolder()
  23285. {
  23286. }
  23287. END_JUCE_NAMESPACE
  23288. /*** End of inlined file: juce_MidiMessageSequence.cpp ***/
  23289. /*** Start of inlined file: juce_AudioPluginFormat.cpp ***/
  23290. BEGIN_JUCE_NAMESPACE
  23291. AudioPluginFormat::AudioPluginFormat() throw()
  23292. {
  23293. }
  23294. AudioPluginFormat::~AudioPluginFormat()
  23295. {
  23296. }
  23297. END_JUCE_NAMESPACE
  23298. /*** End of inlined file: juce_AudioPluginFormat.cpp ***/
  23299. /*** Start of inlined file: juce_AudioPluginFormatManager.cpp ***/
  23300. BEGIN_JUCE_NAMESPACE
  23301. AudioPluginFormatManager::AudioPluginFormatManager() throw()
  23302. {
  23303. }
  23304. AudioPluginFormatManager::~AudioPluginFormatManager() throw()
  23305. {
  23306. clearSingletonInstance();
  23307. }
  23308. juce_ImplementSingleton_SingleThreaded (AudioPluginFormatManager);
  23309. void AudioPluginFormatManager::addDefaultFormats()
  23310. {
  23311. #ifdef JUCE_DEBUG
  23312. // you should only call this method once!
  23313. for (int i = formats.size(); --i >= 0;)
  23314. {
  23315. #if JUCE_PLUGINHOST_VST
  23316. jassert (dynamic_cast <VSTPluginFormat*> (formats[i]) == 0);
  23317. #endif
  23318. #if JUCE_PLUGINHOST_AU && JUCE_MAC
  23319. jassert (dynamic_cast <AudioUnitPluginFormat*> (formats[i]) == 0);
  23320. #endif
  23321. #if JUCE_PLUGINHOST_DX && JUCE_WIN32
  23322. jassert (dynamic_cast <DirectXPluginFormat*> (formats[i]) == 0);
  23323. #endif
  23324. #if JUCE_PLUGINHOST_LADSPA && JUCE_LINUX
  23325. jassert (dynamic_cast <LADSPAPluginFormat*> (formats[i]) == 0);
  23326. #endif
  23327. }
  23328. #endif
  23329. #if JUCE_PLUGINHOST_AU && JUCE_MAC
  23330. formats.add (new AudioUnitPluginFormat());
  23331. #endif
  23332. #if JUCE_PLUGINHOST_VST
  23333. formats.add (new VSTPluginFormat());
  23334. #endif
  23335. #if JUCE_PLUGINHOST_DX && JUCE_WIN32
  23336. formats.add (new DirectXPluginFormat());
  23337. #endif
  23338. #if JUCE_PLUGINHOST_LADSPA && JUCE_LINUX
  23339. formats.add (new LADSPAPluginFormat());
  23340. #endif
  23341. }
  23342. int AudioPluginFormatManager::getNumFormats() throw()
  23343. {
  23344. return formats.size();
  23345. }
  23346. AudioPluginFormat* AudioPluginFormatManager::getFormat (const int index) throw()
  23347. {
  23348. return formats [index];
  23349. }
  23350. void AudioPluginFormatManager::addFormat (AudioPluginFormat* const format) throw()
  23351. {
  23352. formats.add (format);
  23353. }
  23354. AudioPluginInstance* AudioPluginFormatManager::createPluginInstance (const PluginDescription& description,
  23355. String& errorMessage) const
  23356. {
  23357. AudioPluginInstance* result = 0;
  23358. for (int i = 0; i < formats.size(); ++i)
  23359. {
  23360. result = formats.getUnchecked(i)->createInstanceFromDescription (description);
  23361. if (result != 0)
  23362. break;
  23363. }
  23364. if (result == 0)
  23365. {
  23366. if (! doesPluginStillExist (description))
  23367. errorMessage = TRANS ("This plug-in file no longer exists");
  23368. else
  23369. errorMessage = TRANS ("This plug-in failed to load correctly");
  23370. }
  23371. return result;
  23372. }
  23373. bool AudioPluginFormatManager::doesPluginStillExist (const PluginDescription& description) const
  23374. {
  23375. for (int i = 0; i < formats.size(); ++i)
  23376. if (formats.getUnchecked(i)->getName() == description.pluginFormatName)
  23377. return formats.getUnchecked(i)->doesPluginStillExist (description);
  23378. return false;
  23379. }
  23380. END_JUCE_NAMESPACE
  23381. /*** End of inlined file: juce_AudioPluginFormatManager.cpp ***/
  23382. /*** Start of inlined file: juce_AudioPluginInstance.cpp ***/
  23383. #define JUCE_PLUGIN_HOST 1
  23384. BEGIN_JUCE_NAMESPACE
  23385. AudioPluginInstance::AudioPluginInstance()
  23386. {
  23387. }
  23388. AudioPluginInstance::~AudioPluginInstance()
  23389. {
  23390. }
  23391. END_JUCE_NAMESPACE
  23392. /*** End of inlined file: juce_AudioPluginInstance.cpp ***/
  23393. /*** Start of inlined file: juce_KnownPluginList.cpp ***/
  23394. BEGIN_JUCE_NAMESPACE
  23395. KnownPluginList::KnownPluginList()
  23396. {
  23397. }
  23398. KnownPluginList::~KnownPluginList()
  23399. {
  23400. }
  23401. void KnownPluginList::clear()
  23402. {
  23403. if (types.size() > 0)
  23404. {
  23405. types.clear();
  23406. sendChangeMessage (this);
  23407. }
  23408. }
  23409. PluginDescription* KnownPluginList::getTypeForFile (const String& fileOrIdentifier) const throw()
  23410. {
  23411. for (int i = 0; i < types.size(); ++i)
  23412. if (types.getUnchecked(i)->fileOrIdentifier == fileOrIdentifier)
  23413. return types.getUnchecked(i);
  23414. return 0;
  23415. }
  23416. PluginDescription* KnownPluginList::getTypeForIdentifierString (const String& identifierString) const throw()
  23417. {
  23418. for (int i = 0; i < types.size(); ++i)
  23419. if (types.getUnchecked(i)->createIdentifierString() == identifierString)
  23420. return types.getUnchecked(i);
  23421. return 0;
  23422. }
  23423. bool KnownPluginList::addType (const PluginDescription& type)
  23424. {
  23425. for (int i = types.size(); --i >= 0;)
  23426. {
  23427. if (types.getUnchecked(i)->isDuplicateOf (type))
  23428. {
  23429. // strange - found a duplicate plugin with different info..
  23430. jassert (types.getUnchecked(i)->name == type.name);
  23431. jassert (types.getUnchecked(i)->isInstrument == type.isInstrument);
  23432. *types.getUnchecked(i) = type;
  23433. return false;
  23434. }
  23435. }
  23436. types.add (new PluginDescription (type));
  23437. sendChangeMessage (this);
  23438. return true;
  23439. }
  23440. void KnownPluginList::removeType (const int index) throw()
  23441. {
  23442. types.remove (index);
  23443. sendChangeMessage (this);
  23444. }
  23445. static Time getFileModTime (const String& fileOrIdentifier) throw()
  23446. {
  23447. if (fileOrIdentifier.startsWithChar (T('/'))
  23448. || fileOrIdentifier[1] == T(':'))
  23449. {
  23450. return File (fileOrIdentifier).getLastModificationTime();
  23451. }
  23452. return Time (0);
  23453. }
  23454. static bool timesAreDifferent (const Time& t1, const Time& t2) throw()
  23455. {
  23456. return t1 != t2 || t1 == Time (0);
  23457. }
  23458. bool KnownPluginList::isListingUpToDate (const String& fileOrIdentifier) const throw()
  23459. {
  23460. if (getTypeForFile (fileOrIdentifier) == 0)
  23461. return false;
  23462. for (int i = types.size(); --i >= 0;)
  23463. {
  23464. const PluginDescription* const d = types.getUnchecked(i);
  23465. if (d->fileOrIdentifier == fileOrIdentifier
  23466. && timesAreDifferent (d->lastFileModTime, getFileModTime (fileOrIdentifier)))
  23467. {
  23468. return false;
  23469. }
  23470. }
  23471. return true;
  23472. }
  23473. bool KnownPluginList::scanAndAddFile (const String& fileOrIdentifier,
  23474. const bool dontRescanIfAlreadyInList,
  23475. OwnedArray <PluginDescription>& typesFound,
  23476. AudioPluginFormat& format)
  23477. {
  23478. bool addedOne = false;
  23479. if (dontRescanIfAlreadyInList
  23480. && getTypeForFile (fileOrIdentifier) != 0)
  23481. {
  23482. bool needsRescanning = false;
  23483. for (int i = types.size(); --i >= 0;)
  23484. {
  23485. const PluginDescription* const d = types.getUnchecked(i);
  23486. if (d->fileOrIdentifier == fileOrIdentifier)
  23487. {
  23488. if (timesAreDifferent (d->lastFileModTime, getFileModTime (fileOrIdentifier)))
  23489. needsRescanning = true;
  23490. else
  23491. typesFound.add (new PluginDescription (*d));
  23492. }
  23493. }
  23494. if (! needsRescanning)
  23495. return false;
  23496. }
  23497. OwnedArray <PluginDescription> found;
  23498. format.findAllTypesForFile (found, fileOrIdentifier);
  23499. for (int i = 0; i < found.size(); ++i)
  23500. {
  23501. PluginDescription* const desc = found.getUnchecked(i);
  23502. jassert (desc != 0);
  23503. if (addType (*desc))
  23504. addedOne = true;
  23505. typesFound.add (new PluginDescription (*desc));
  23506. }
  23507. return addedOne;
  23508. }
  23509. void KnownPluginList::scanAndAddDragAndDroppedFiles (const StringArray& files,
  23510. OwnedArray <PluginDescription>& typesFound)
  23511. {
  23512. for (int i = 0; i < files.size(); ++i)
  23513. {
  23514. bool loaded = false;
  23515. for (int j = 0; j < AudioPluginFormatManager::getInstance()->getNumFormats(); ++j)
  23516. {
  23517. AudioPluginFormat* const format = AudioPluginFormatManager::getInstance()->getFormat (j);
  23518. if (scanAndAddFile (files[i], true, typesFound, *format))
  23519. loaded = true;
  23520. }
  23521. if (! loaded)
  23522. {
  23523. const File f (files[i]);
  23524. if (f.isDirectory())
  23525. {
  23526. StringArray s;
  23527. {
  23528. Array<File> subFiles;
  23529. f.findChildFiles (subFiles, File::findFilesAndDirectories, false);
  23530. for (int j = 0; j < subFiles.size(); ++j)
  23531. s.add (subFiles.getReference(j).getFullPathName());
  23532. }
  23533. scanAndAddDragAndDroppedFiles (s, typesFound);
  23534. }
  23535. }
  23536. }
  23537. }
  23538. class PluginSorter
  23539. {
  23540. public:
  23541. KnownPluginList::SortMethod method;
  23542. PluginSorter() throw() {}
  23543. int compareElements (const PluginDescription* const first,
  23544. const PluginDescription* const second) const throw()
  23545. {
  23546. int diff = 0;
  23547. if (method == KnownPluginList::sortByCategory)
  23548. diff = first->category.compareLexicographically (second->category);
  23549. else if (method == KnownPluginList::sortByManufacturer)
  23550. diff = first->manufacturerName.compareLexicographically (second->manufacturerName);
  23551. else if (method == KnownPluginList::sortByFileSystemLocation)
  23552. diff = first->fileOrIdentifier.replaceCharacter (T('\\'), T('/'))
  23553. .upToLastOccurrenceOf (T("/"), false, false)
  23554. .compare (second->fileOrIdentifier.replaceCharacter (T('\\'), T('/'))
  23555. .upToLastOccurrenceOf (T("/"), false, false));
  23556. if (diff == 0)
  23557. diff = first->name.compareLexicographically (second->name);
  23558. return diff;
  23559. }
  23560. };
  23561. void KnownPluginList::sort (const SortMethod method)
  23562. {
  23563. if (method != defaultOrder)
  23564. {
  23565. PluginSorter sorter;
  23566. sorter.method = method;
  23567. types.sort (sorter, true);
  23568. sendChangeMessage (this);
  23569. }
  23570. }
  23571. XmlElement* KnownPluginList::createXml() const
  23572. {
  23573. XmlElement* const e = new XmlElement (T("KNOWNPLUGINS"));
  23574. for (int i = 0; i < types.size(); ++i)
  23575. e->addChildElement (types.getUnchecked(i)->createXml());
  23576. return e;
  23577. }
  23578. void KnownPluginList::recreateFromXml (const XmlElement& xml)
  23579. {
  23580. clear();
  23581. if (xml.hasTagName (T("KNOWNPLUGINS")))
  23582. {
  23583. forEachXmlChildElement (xml, e)
  23584. {
  23585. PluginDescription info;
  23586. if (info.loadFromXml (*e))
  23587. addType (info);
  23588. }
  23589. }
  23590. }
  23591. const int menuIdBase = 0x324503f4;
  23592. // This is used to turn a bunch of paths into a nested menu structure.
  23593. struct PluginFilesystemTree
  23594. {
  23595. private:
  23596. String folder;
  23597. OwnedArray <PluginFilesystemTree> subFolders;
  23598. Array <PluginDescription*> plugins;
  23599. void addPlugin (PluginDescription* const pd, const String& path)
  23600. {
  23601. if (path.isEmpty())
  23602. {
  23603. plugins.add (pd);
  23604. }
  23605. else
  23606. {
  23607. const String firstSubFolder (path.upToFirstOccurrenceOf (T("/"), false, false));
  23608. const String remainingPath (path.fromFirstOccurrenceOf (T("/"), false, false));
  23609. for (int i = subFolders.size(); --i >= 0;)
  23610. {
  23611. if (subFolders.getUnchecked(i)->folder.equalsIgnoreCase (firstSubFolder))
  23612. {
  23613. subFolders.getUnchecked(i)->addPlugin (pd, remainingPath);
  23614. return;
  23615. }
  23616. }
  23617. PluginFilesystemTree* const newFolder = new PluginFilesystemTree();
  23618. newFolder->folder = firstSubFolder;
  23619. subFolders.add (newFolder);
  23620. newFolder->addPlugin (pd, remainingPath);
  23621. }
  23622. }
  23623. // removes any deeply nested folders that don't contain any actual plugins
  23624. void optimise()
  23625. {
  23626. for (int i = subFolders.size(); --i >= 0;)
  23627. {
  23628. PluginFilesystemTree* const sub = subFolders.getUnchecked(i);
  23629. sub->optimise();
  23630. if (sub->plugins.size() == 0)
  23631. {
  23632. for (int j = 0; j < sub->subFolders.size(); ++j)
  23633. subFolders.add (sub->subFolders.getUnchecked(j));
  23634. sub->subFolders.clear (false);
  23635. subFolders.remove (i);
  23636. }
  23637. }
  23638. }
  23639. public:
  23640. void buildTree (const Array <PluginDescription*>& allPlugins)
  23641. {
  23642. for (int i = 0; i < allPlugins.size(); ++i)
  23643. {
  23644. String path (allPlugins.getUnchecked(i)
  23645. ->fileOrIdentifier.replaceCharacter (T('\\'), T('/'))
  23646. .upToLastOccurrenceOf (T("/"), false, false));
  23647. if (path.substring (1, 2) == T(":"))
  23648. path = path.substring (2);
  23649. addPlugin (allPlugins.getUnchecked(i), path);
  23650. }
  23651. optimise();
  23652. }
  23653. void addToMenu (PopupMenu& m, const OwnedArray <PluginDescription>& allPlugins) const
  23654. {
  23655. int i;
  23656. for (i = 0; i < subFolders.size(); ++i)
  23657. {
  23658. const PluginFilesystemTree* const sub = subFolders.getUnchecked(i);
  23659. PopupMenu subMenu;
  23660. sub->addToMenu (subMenu, allPlugins);
  23661. #if JUCE_MAC
  23662. // avoid the special AU formatting nonsense on Mac..
  23663. m.addSubMenu (sub->folder.fromFirstOccurrenceOf (T(":"), false, false), subMenu);
  23664. #else
  23665. m.addSubMenu (sub->folder, subMenu);
  23666. #endif
  23667. }
  23668. for (i = 0; i < plugins.size(); ++i)
  23669. {
  23670. PluginDescription* const plugin = plugins.getUnchecked(i);
  23671. m.addItem (allPlugins.indexOf (plugin) + menuIdBase,
  23672. plugin->name, true, false);
  23673. }
  23674. }
  23675. };
  23676. void KnownPluginList::addToMenu (PopupMenu& menu, const SortMethod sortMethod) const
  23677. {
  23678. Array <PluginDescription*> sorted;
  23679. {
  23680. PluginSorter sorter;
  23681. sorter.method = sortMethod;
  23682. for (int i = 0; i < types.size(); ++i)
  23683. sorted.addSorted (sorter, types.getUnchecked(i));
  23684. }
  23685. if (sortMethod == sortByCategory
  23686. || sortMethod == sortByManufacturer)
  23687. {
  23688. String lastSubMenuName;
  23689. PopupMenu sub;
  23690. for (int i = 0; i < sorted.size(); ++i)
  23691. {
  23692. const PluginDescription* const pd = sorted.getUnchecked(i);
  23693. String thisSubMenuName (sortMethod == sortByCategory ? pd->category
  23694. : pd->manufacturerName);
  23695. if (! thisSubMenuName.containsNonWhitespaceChars())
  23696. thisSubMenuName = T("Other");
  23697. if (thisSubMenuName != lastSubMenuName)
  23698. {
  23699. if (sub.getNumItems() > 0)
  23700. {
  23701. menu.addSubMenu (lastSubMenuName, sub);
  23702. sub.clear();
  23703. }
  23704. lastSubMenuName = thisSubMenuName;
  23705. }
  23706. sub.addItem (types.indexOf (pd) + menuIdBase, pd->name, true, false);
  23707. }
  23708. if (sub.getNumItems() > 0)
  23709. menu.addSubMenu (lastSubMenuName, sub);
  23710. }
  23711. else if (sortMethod == sortByFileSystemLocation)
  23712. {
  23713. PluginFilesystemTree root;
  23714. root.buildTree (sorted);
  23715. root.addToMenu (menu, types);
  23716. }
  23717. else
  23718. {
  23719. for (int i = 0; i < sorted.size(); ++i)
  23720. {
  23721. const PluginDescription* const pd = sorted.getUnchecked(i);
  23722. menu.addItem (types.indexOf (pd) + menuIdBase, pd->name, true, false);
  23723. }
  23724. }
  23725. }
  23726. int KnownPluginList::getIndexChosenByMenu (const int menuResultCode) const
  23727. {
  23728. const int i = menuResultCode - menuIdBase;
  23729. return (((unsigned int) i) < (unsigned int) types.size()) ? i : -1;
  23730. }
  23731. END_JUCE_NAMESPACE
  23732. /*** End of inlined file: juce_KnownPluginList.cpp ***/
  23733. /*** Start of inlined file: juce_PluginDescription.cpp ***/
  23734. BEGIN_JUCE_NAMESPACE
  23735. PluginDescription::PluginDescription() throw()
  23736. : uid (0),
  23737. isInstrument (false),
  23738. numInputChannels (0),
  23739. numOutputChannels (0)
  23740. {
  23741. }
  23742. PluginDescription::~PluginDescription() throw()
  23743. {
  23744. }
  23745. PluginDescription::PluginDescription (const PluginDescription& other) throw()
  23746. : name (other.name),
  23747. pluginFormatName (other.pluginFormatName),
  23748. category (other.category),
  23749. manufacturerName (other.manufacturerName),
  23750. version (other.version),
  23751. fileOrIdentifier (other.fileOrIdentifier),
  23752. lastFileModTime (other.lastFileModTime),
  23753. uid (other.uid),
  23754. isInstrument (other.isInstrument),
  23755. numInputChannels (other.numInputChannels),
  23756. numOutputChannels (other.numOutputChannels)
  23757. {
  23758. }
  23759. PluginDescription& PluginDescription::operator= (const PluginDescription& other) throw()
  23760. {
  23761. name = other.name;
  23762. pluginFormatName = other.pluginFormatName;
  23763. category = other.category;
  23764. manufacturerName = other.manufacturerName;
  23765. version = other.version;
  23766. fileOrIdentifier = other.fileOrIdentifier;
  23767. uid = other.uid;
  23768. isInstrument = other.isInstrument;
  23769. lastFileModTime = other.lastFileModTime;
  23770. numInputChannels = other.numInputChannels;
  23771. numOutputChannels = other.numOutputChannels;
  23772. return *this;
  23773. }
  23774. bool PluginDescription::isDuplicateOf (const PluginDescription& other) const
  23775. {
  23776. return fileOrIdentifier == other.fileOrIdentifier
  23777. && uid == other.uid;
  23778. }
  23779. const String PluginDescription::createIdentifierString() const throw()
  23780. {
  23781. return pluginFormatName
  23782. + T("-") + name
  23783. + T("-") + String::toHexString (fileOrIdentifier.hashCode())
  23784. + T("-") + String::toHexString (uid);
  23785. }
  23786. XmlElement* PluginDescription::createXml() const
  23787. {
  23788. XmlElement* const e = new XmlElement (T("PLUGIN"));
  23789. e->setAttribute (T("name"), name);
  23790. e->setAttribute (T("format"), pluginFormatName);
  23791. e->setAttribute (T("category"), category);
  23792. e->setAttribute (T("manufacturer"), manufacturerName);
  23793. e->setAttribute (T("version"), version);
  23794. e->setAttribute (T("file"), fileOrIdentifier);
  23795. e->setAttribute (T("uid"), String::toHexString (uid));
  23796. e->setAttribute (T("isInstrument"), isInstrument);
  23797. e->setAttribute (T("fileTime"), String::toHexString (lastFileModTime.toMilliseconds()));
  23798. e->setAttribute (T("numInputs"), numInputChannels);
  23799. e->setAttribute (T("numOutputs"), numOutputChannels);
  23800. return e;
  23801. }
  23802. bool PluginDescription::loadFromXml (const XmlElement& xml)
  23803. {
  23804. if (xml.hasTagName (T("PLUGIN")))
  23805. {
  23806. name = xml.getStringAttribute (T("name"));
  23807. pluginFormatName = xml.getStringAttribute (T("format"));
  23808. category = xml.getStringAttribute (T("category"));
  23809. manufacturerName = xml.getStringAttribute (T("manufacturer"));
  23810. version = xml.getStringAttribute (T("version"));
  23811. fileOrIdentifier = xml.getStringAttribute (T("file"));
  23812. uid = xml.getStringAttribute (T("uid")).getHexValue32();
  23813. isInstrument = xml.getBoolAttribute (T("isInstrument"), false);
  23814. lastFileModTime = Time (xml.getStringAttribute (T("fileTime")).getHexValue64());
  23815. numInputChannels = xml.getIntAttribute (T("numInputs"));
  23816. numOutputChannels = xml.getIntAttribute (T("numOutputs"));
  23817. return true;
  23818. }
  23819. return false;
  23820. }
  23821. END_JUCE_NAMESPACE
  23822. /*** End of inlined file: juce_PluginDescription.cpp ***/
  23823. /*** Start of inlined file: juce_PluginDirectoryScanner.cpp ***/
  23824. BEGIN_JUCE_NAMESPACE
  23825. PluginDirectoryScanner::PluginDirectoryScanner (KnownPluginList& listToAddTo,
  23826. AudioPluginFormat& formatToLookFor,
  23827. FileSearchPath directoriesToSearch,
  23828. const bool recursive,
  23829. const File& deadMansPedalFile_)
  23830. : list (listToAddTo),
  23831. format (formatToLookFor),
  23832. deadMansPedalFile (deadMansPedalFile_),
  23833. nextIndex (0),
  23834. progress (0)
  23835. {
  23836. directoriesToSearch.removeRedundantPaths();
  23837. filesOrIdentifiersToScan = format.searchPathsForPlugins (directoriesToSearch, recursive);
  23838. // If any plugins have crashed recently when being loaded, move them to the
  23839. // end of the list to give the others a chance to load correctly..
  23840. const StringArray crashedPlugins (getDeadMansPedalFile());
  23841. for (int i = 0; i < crashedPlugins.size(); ++i)
  23842. {
  23843. const String f = crashedPlugins[i];
  23844. for (int j = filesOrIdentifiersToScan.size(); --j >= 0;)
  23845. if (f == filesOrIdentifiersToScan[j])
  23846. filesOrIdentifiersToScan.move (j, -1);
  23847. }
  23848. }
  23849. PluginDirectoryScanner::~PluginDirectoryScanner()
  23850. {
  23851. }
  23852. const String PluginDirectoryScanner::getNextPluginFileThatWillBeScanned() const throw()
  23853. {
  23854. return format.getNameOfPluginFromIdentifier (filesOrIdentifiersToScan [nextIndex]);
  23855. }
  23856. bool PluginDirectoryScanner::scanNextFile (const bool dontRescanIfAlreadyInList)
  23857. {
  23858. String file (filesOrIdentifiersToScan [nextIndex]);
  23859. if (file.isNotEmpty())
  23860. {
  23861. if (! list.isListingUpToDate (file))
  23862. {
  23863. OwnedArray <PluginDescription> typesFound;
  23864. // Add this plugin to the end of the dead-man's pedal list in case it crashes...
  23865. StringArray crashedPlugins (getDeadMansPedalFile());
  23866. crashedPlugins.removeString (file);
  23867. crashedPlugins.add (file);
  23868. setDeadMansPedalFile (crashedPlugins);
  23869. list.scanAndAddFile (file,
  23870. dontRescanIfAlreadyInList,
  23871. typesFound,
  23872. format);
  23873. // Managed to load without crashing, so remove it from the dead-man's-pedal..
  23874. crashedPlugins.removeString (file);
  23875. setDeadMansPedalFile (crashedPlugins);
  23876. if (typesFound.size() == 0)
  23877. failedFiles.add (file);
  23878. }
  23879. ++nextIndex;
  23880. progress = nextIndex / (float) filesOrIdentifiersToScan.size();
  23881. }
  23882. return nextIndex < filesOrIdentifiersToScan.size();
  23883. }
  23884. const StringArray PluginDirectoryScanner::getDeadMansPedalFile() throw()
  23885. {
  23886. StringArray lines;
  23887. if (deadMansPedalFile != File::nonexistent)
  23888. {
  23889. lines.addLines (deadMansPedalFile.loadFileAsString());
  23890. lines.removeEmptyStrings();
  23891. }
  23892. return lines;
  23893. }
  23894. void PluginDirectoryScanner::setDeadMansPedalFile (const StringArray& newContents) throw()
  23895. {
  23896. if (deadMansPedalFile != File::nonexistent)
  23897. deadMansPedalFile.replaceWithText (newContents.joinIntoString ("\n"), true, true);
  23898. }
  23899. END_JUCE_NAMESPACE
  23900. /*** End of inlined file: juce_PluginDirectoryScanner.cpp ***/
  23901. /*** Start of inlined file: juce_PluginListComponent.cpp ***/
  23902. BEGIN_JUCE_NAMESPACE
  23903. PluginListComponent::PluginListComponent (KnownPluginList& listToEdit,
  23904. const File& deadMansPedalFile_,
  23905. PropertiesFile* const propertiesToUse_)
  23906. : list (listToEdit),
  23907. deadMansPedalFile (deadMansPedalFile_),
  23908. propertiesToUse (propertiesToUse_)
  23909. {
  23910. addAndMakeVisible (listBox = new ListBox (String::empty, this));
  23911. addAndMakeVisible (optionsButton = new TextButton ("Options..."));
  23912. optionsButton->addButtonListener (this);
  23913. optionsButton->setTriggeredOnMouseDown (true);
  23914. setSize (400, 600);
  23915. list.addChangeListener (this);
  23916. }
  23917. PluginListComponent::~PluginListComponent()
  23918. {
  23919. list.removeChangeListener (this);
  23920. deleteAllChildren();
  23921. }
  23922. void PluginListComponent::resized()
  23923. {
  23924. listBox->setBounds (0, 0, getWidth(), getHeight() - 30);
  23925. optionsButton->changeWidthToFitText (24);
  23926. optionsButton->setTopLeftPosition (8, getHeight() - 28);
  23927. }
  23928. void PluginListComponent::changeListenerCallback (void*)
  23929. {
  23930. listBox->updateContent();
  23931. listBox->repaint();
  23932. }
  23933. int PluginListComponent::getNumRows()
  23934. {
  23935. return list.getNumTypes();
  23936. }
  23937. void PluginListComponent::paintListBoxItem (int row,
  23938. Graphics& g,
  23939. int width, int height,
  23940. bool rowIsSelected)
  23941. {
  23942. if (rowIsSelected)
  23943. g.fillAll (findColour (TextEditor::highlightColourId));
  23944. const PluginDescription* const pd = list.getType (row);
  23945. if (pd != 0)
  23946. {
  23947. GlyphArrangement ga;
  23948. ga.addCurtailedLineOfText (Font (height * 0.7f, Font::bold), pd->name, 8.0f, height * 0.8f, width - 10.0f, true);
  23949. g.setColour (Colours::black);
  23950. ga.draw (g);
  23951. float x, y, r, b;
  23952. ga.getBoundingBox (0, -1, x, y, r, b, false);
  23953. String desc;
  23954. desc << pd->pluginFormatName
  23955. << (pd->isInstrument ? " instrument" : " effect")
  23956. << " - "
  23957. << pd->numInputChannels << (pd->numInputChannels == 1 ? " in" : " ins")
  23958. << " / "
  23959. << pd->numOutputChannels << (pd->numOutputChannels == 1 ? " out" : " outs");
  23960. if (pd->manufacturerName.isNotEmpty())
  23961. desc << " - " << pd->manufacturerName;
  23962. if (pd->version.isNotEmpty())
  23963. desc << " - " << pd->version;
  23964. if (pd->category.isNotEmpty())
  23965. desc << " - category: '" << pd->category << '\'';
  23966. g.setColour (Colours::grey);
  23967. ga.clear();
  23968. ga.addCurtailedLineOfText (Font (height * 0.6f), desc, r + 10.0f, height * 0.8f, width - r - 12.0f, true);
  23969. ga.draw (g);
  23970. }
  23971. }
  23972. void PluginListComponent::deleteKeyPressed (int lastRowSelected)
  23973. {
  23974. list.removeType (lastRowSelected);
  23975. }
  23976. void PluginListComponent::buttonClicked (Button* b)
  23977. {
  23978. if (optionsButton == b)
  23979. {
  23980. PopupMenu menu;
  23981. menu.addItem (1, TRANS("Clear list"));
  23982. menu.addItem (5, TRANS("Remove selected plugin from list"), listBox->getNumSelectedRows() > 0);
  23983. menu.addItem (6, TRANS("Show folder containing selected plugin"), listBox->getNumSelectedRows() > 0);
  23984. menu.addItem (7, TRANS("Remove any plugins whose files no longer exist"));
  23985. menu.addSeparator();
  23986. menu.addItem (2, TRANS("Sort alphabetically"));
  23987. menu.addItem (3, TRANS("Sort by category"));
  23988. menu.addItem (4, TRANS("Sort by manufacturer"));
  23989. menu.addSeparator();
  23990. for (int i = 0; i < AudioPluginFormatManager::getInstance()->getNumFormats(); ++i)
  23991. {
  23992. AudioPluginFormat* const format = AudioPluginFormatManager::getInstance()->getFormat (i);
  23993. if (format->getDefaultLocationsToSearch().getNumPaths() > 0)
  23994. menu.addItem (10 + i, "Scan for new or updated " + format->getName() + " plugins...");
  23995. }
  23996. const int r = menu.showAt (optionsButton);
  23997. if (r == 1)
  23998. {
  23999. list.clear();
  24000. }
  24001. else if (r == 2)
  24002. {
  24003. list.sort (KnownPluginList::sortAlphabetically);
  24004. }
  24005. else if (r == 3)
  24006. {
  24007. list.sort (KnownPluginList::sortByCategory);
  24008. }
  24009. else if (r == 4)
  24010. {
  24011. list.sort (KnownPluginList::sortByManufacturer);
  24012. }
  24013. else if (r == 5)
  24014. {
  24015. const SparseSet <int> selected (listBox->getSelectedRows());
  24016. for (int i = list.getNumTypes(); --i >= 0;)
  24017. if (selected.contains (i))
  24018. list.removeType (i);
  24019. }
  24020. else if (r == 6)
  24021. {
  24022. const PluginDescription* const desc = list.getType (listBox->getSelectedRow());
  24023. if (desc != 0)
  24024. {
  24025. if (File (desc->fileOrIdentifier).existsAsFile())
  24026. File (desc->fileOrIdentifier).getParentDirectory().startAsProcess();
  24027. }
  24028. }
  24029. else if (r == 7)
  24030. {
  24031. for (int i = list.getNumTypes(); --i >= 0;)
  24032. {
  24033. if (! AudioPluginFormatManager::getInstance()->doesPluginStillExist (*list.getType (i)))
  24034. {
  24035. list.removeType (i);
  24036. }
  24037. }
  24038. }
  24039. else if (r != 0)
  24040. {
  24041. typeToScan = r - 10;
  24042. startTimer (1);
  24043. }
  24044. }
  24045. }
  24046. void PluginListComponent::timerCallback()
  24047. {
  24048. stopTimer();
  24049. scanFor (AudioPluginFormatManager::getInstance()->getFormat (typeToScan));
  24050. }
  24051. bool PluginListComponent::isInterestedInFileDrag (const StringArray& /*files*/)
  24052. {
  24053. return true;
  24054. }
  24055. void PluginListComponent::filesDropped (const StringArray& files, int, int)
  24056. {
  24057. OwnedArray <PluginDescription> typesFound;
  24058. list.scanAndAddDragAndDroppedFiles (files, typesFound);
  24059. }
  24060. void PluginListComponent::scanFor (AudioPluginFormat* format)
  24061. {
  24062. if (format == 0)
  24063. return;
  24064. FileSearchPath path (format->getDefaultLocationsToSearch());
  24065. if (propertiesToUse != 0)
  24066. path = propertiesToUse->getValue ("lastPluginScanPath_" + format->getName(), path.toString());
  24067. {
  24068. AlertWindow aw (TRANS("Select folders to scan..."), String::empty, AlertWindow::NoIcon);
  24069. FileSearchPathListComponent pathList;
  24070. pathList.setSize (500, 300);
  24071. pathList.setPath (path);
  24072. aw.addCustomComponent (&pathList);
  24073. aw.addButton (TRANS("Scan"), 1, KeyPress::returnKey);
  24074. aw.addButton (TRANS("Cancel"), 0, KeyPress (KeyPress::escapeKey));
  24075. if (aw.runModalLoop() == 0)
  24076. return;
  24077. path = pathList.getPath();
  24078. }
  24079. if (propertiesToUse != 0)
  24080. {
  24081. propertiesToUse->setValue ("lastPluginScanPath_" + format->getName(), path.toString());
  24082. propertiesToUse->saveIfNeeded();
  24083. }
  24084. double progress = 0.0;
  24085. AlertWindow aw (TRANS("Scanning for plugins..."),
  24086. TRANS("Searching for all possible plugin files..."), AlertWindow::NoIcon);
  24087. aw.addButton (TRANS("Cancel"), 0, KeyPress (KeyPress::escapeKey));
  24088. aw.addProgressBarComponent (progress);
  24089. aw.enterModalState();
  24090. MessageManager::getInstance()->runDispatchLoopUntil (300);
  24091. PluginDirectoryScanner scanner (list, *format, path, true, deadMansPedalFile);
  24092. for (;;)
  24093. {
  24094. aw.setMessage (TRANS("Testing:\n\n")
  24095. + scanner.getNextPluginFileThatWillBeScanned());
  24096. MessageManager::getInstance()->runDispatchLoopUntil (20);
  24097. if (! scanner.scanNextFile (true))
  24098. break;
  24099. if (! aw.isCurrentlyModal())
  24100. break;
  24101. progress = scanner.getProgress();
  24102. }
  24103. if (scanner.getFailedFiles().size() > 0)
  24104. {
  24105. StringArray shortNames;
  24106. for (int i = 0; i < scanner.getFailedFiles().size(); ++i)
  24107. shortNames.add (File (scanner.getFailedFiles()[i]).getFileName());
  24108. AlertWindow::showMessageBox (AlertWindow::InfoIcon,
  24109. TRANS("Scan complete"),
  24110. TRANS("Note that the following files appeared to be plugin files, but failed to load correctly:\n\n")
  24111. + shortNames.joinIntoString (", "));
  24112. }
  24113. }
  24114. END_JUCE_NAMESPACE
  24115. /*** End of inlined file: juce_PluginListComponent.cpp ***/
  24116. /*** Start of inlined file: juce_AudioUnitPluginFormat.mm ***/
  24117. #if JUCE_PLUGINHOST_AU && (! (defined (LINUX) || defined (_WIN32)))
  24118. #include <AudioUnit/AudioUnit.h>
  24119. #include <AudioUnit/AUCocoaUIView.h>
  24120. #include <CoreAudioKit/AUGenericView.h>
  24121. #if JUCE_SUPPORT_CARBON
  24122. #include <AudioToolbox/AudioUnitUtilities.h>
  24123. #include <AudioUnit/AudioUnitCarbonView.h>
  24124. #endif
  24125. BEGIN_JUCE_NAMESPACE
  24126. #if JUCE_MAC && JUCE_SUPPORT_CARBON
  24127. #endif
  24128. #if JUCE_MAC
  24129. // Change this to disable logging of various activities
  24130. #ifndef AU_LOGGING
  24131. #define AU_LOGGING 1
  24132. #endif
  24133. #if AU_LOGGING
  24134. #define log(a) Logger::writeToLog(a);
  24135. #else
  24136. #define log(a)
  24137. #endif
  24138. static int insideCallback = 0;
  24139. static const String osTypeToString (OSType type) throw()
  24140. {
  24141. char s[4];
  24142. s[0] = (char) (((uint32) type) >> 24);
  24143. s[1] = (char) (((uint32) type) >> 16);
  24144. s[2] = (char) (((uint32) type) >> 8);
  24145. s[3] = (char) ((uint32) type);
  24146. return String (s, 4);
  24147. }
  24148. static OSType stringToOSType (const String& s1) throw()
  24149. {
  24150. const String s (s1 + " ");
  24151. return (((OSType) (unsigned char) s[0]) << 24)
  24152. | (((OSType) (unsigned char) s[1]) << 16)
  24153. | (((OSType) (unsigned char) s[2]) << 8)
  24154. | ((OSType) (unsigned char) s[3]);
  24155. }
  24156. static const tchar* auIdentifierPrefix = T("AudioUnit:");
  24157. static const String createAUPluginIdentifier (const ComponentDescription& desc)
  24158. {
  24159. jassert (osTypeToString ('abcd') == T("abcd")); // agh, must have got the endianness wrong..
  24160. jassert (stringToOSType ("abcd") == (OSType) 'abcd'); // ditto
  24161. String s (auIdentifierPrefix);
  24162. if (desc.componentType == kAudioUnitType_MusicDevice)
  24163. s << "Synths/";
  24164. else if (desc.componentType == kAudioUnitType_MusicEffect
  24165. || desc.componentType == kAudioUnitType_Effect)
  24166. s << "Effects/";
  24167. else if (desc.componentType == kAudioUnitType_Generator)
  24168. s << "Generators/";
  24169. else if (desc.componentType == kAudioUnitType_Panner)
  24170. s << "Panners/";
  24171. s << osTypeToString (desc.componentType)
  24172. << T(",")
  24173. << osTypeToString (desc.componentSubType)
  24174. << T(",")
  24175. << osTypeToString (desc.componentManufacturer);
  24176. return s;
  24177. }
  24178. static void getAUDetails (ComponentRecord* comp, String& name, String& manufacturer)
  24179. {
  24180. Handle componentNameHandle = NewHandle (sizeof (void*));
  24181. Handle componentInfoHandle = NewHandle (sizeof (void*));
  24182. if (componentNameHandle != 0 && componentInfoHandle != 0)
  24183. {
  24184. ComponentDescription desc;
  24185. if (GetComponentInfo (comp, &desc, componentNameHandle, componentInfoHandle, 0) == noErr)
  24186. {
  24187. ConstStr255Param nameString = (ConstStr255Param) (*componentNameHandle);
  24188. ConstStr255Param infoString = (ConstStr255Param) (*componentInfoHandle);
  24189. if (nameString != 0 && nameString[0] != 0)
  24190. {
  24191. const String all ((const char*) nameString + 1, nameString[0]);
  24192. DBG ("name: "+ all);
  24193. manufacturer = all.upToFirstOccurrenceOf (T(":"), false, false).trim();
  24194. name = all.fromFirstOccurrenceOf (T(":"), false, false).trim();
  24195. }
  24196. if (infoString != 0 && infoString[0] != 0)
  24197. {
  24198. const String all ((const char*) infoString + 1, infoString[0]);
  24199. DBG ("info: " + all);
  24200. }
  24201. if (name.isEmpty())
  24202. name = "<Unknown>";
  24203. }
  24204. DisposeHandle (componentNameHandle);
  24205. DisposeHandle (componentInfoHandle);
  24206. }
  24207. }
  24208. static bool getComponentDescFromIdentifier (const String& fileOrIdentifier, ComponentDescription& desc,
  24209. String& name, String& version, String& manufacturer)
  24210. {
  24211. zerostruct (desc);
  24212. if (fileOrIdentifier.startsWithIgnoreCase (auIdentifierPrefix))
  24213. {
  24214. String s (fileOrIdentifier.substring (jmax (fileOrIdentifier.lastIndexOfChar (T(':')),
  24215. fileOrIdentifier.lastIndexOfChar (T('/'))) + 1));
  24216. StringArray tokens;
  24217. tokens.addTokens (s, T(","), 0);
  24218. tokens.trim();
  24219. tokens.removeEmptyStrings();
  24220. if (tokens.size() == 3)
  24221. {
  24222. desc.componentType = stringToOSType (tokens[0]);
  24223. desc.componentSubType = stringToOSType (tokens[1]);
  24224. desc.componentManufacturer = stringToOSType (tokens[2]);
  24225. ComponentRecord* comp = FindNextComponent (0, &desc);
  24226. if (comp != 0)
  24227. {
  24228. getAUDetails (comp, name, manufacturer);
  24229. return true;
  24230. }
  24231. }
  24232. }
  24233. return false;
  24234. }
  24235. class AudioUnitPluginWindowCarbon;
  24236. class AudioUnitPluginWindowCocoa;
  24237. class AudioUnitPluginInstance : public AudioPluginInstance
  24238. {
  24239. public:
  24240. ~AudioUnitPluginInstance();
  24241. // AudioPluginInstance methods:
  24242. void fillInPluginDescription (PluginDescription& desc) const
  24243. {
  24244. desc.name = pluginName;
  24245. desc.fileOrIdentifier = createAUPluginIdentifier (componentDesc);
  24246. desc.uid = ((int) componentDesc.componentType)
  24247. ^ ((int) componentDesc.componentSubType)
  24248. ^ ((int) componentDesc.componentManufacturer);
  24249. desc.lastFileModTime = 0;
  24250. desc.pluginFormatName = "AudioUnit";
  24251. desc.category = getCategory();
  24252. desc.manufacturerName = manufacturer;
  24253. desc.version = version;
  24254. desc.numInputChannels = getNumInputChannels();
  24255. desc.numOutputChannels = getNumOutputChannels();
  24256. desc.isInstrument = (componentDesc.componentType == kAudioUnitType_MusicDevice);
  24257. }
  24258. const String getName() const { return pluginName; }
  24259. bool acceptsMidi() const { return wantsMidiMessages; }
  24260. bool producesMidi() const { return false; }
  24261. // AudioProcessor methods:
  24262. void prepareToPlay (double sampleRate, int estimatedSamplesPerBlock);
  24263. void releaseResources();
  24264. void processBlock (AudioSampleBuffer& buffer,
  24265. MidiBuffer& midiMessages);
  24266. AudioProcessorEditor* createEditor();
  24267. const String getInputChannelName (const int index) const;
  24268. bool isInputChannelStereoPair (int index) const;
  24269. const String getOutputChannelName (const int index) const;
  24270. bool isOutputChannelStereoPair (int index) const;
  24271. int getNumParameters();
  24272. float getParameter (int index);
  24273. void setParameter (int index, float newValue);
  24274. const String getParameterName (int index);
  24275. const String getParameterText (int index);
  24276. bool isParameterAutomatable (int index) const;
  24277. int getNumPrograms();
  24278. int getCurrentProgram();
  24279. void setCurrentProgram (int index);
  24280. const String getProgramName (int index);
  24281. void changeProgramName (int index, const String& newName);
  24282. void getStateInformation (MemoryBlock& destData);
  24283. void getCurrentProgramStateInformation (MemoryBlock& destData);
  24284. void setStateInformation (const void* data, int sizeInBytes);
  24285. void setCurrentProgramStateInformation (const void* data, int sizeInBytes);
  24286. juce_UseDebuggingNewOperator
  24287. private:
  24288. friend class AudioUnitPluginWindowCarbon;
  24289. friend class AudioUnitPluginWindowCocoa;
  24290. friend class AudioUnitPluginFormat;
  24291. ComponentDescription componentDesc;
  24292. String pluginName, manufacturer, version;
  24293. String fileOrIdentifier;
  24294. CriticalSection lock;
  24295. bool initialised, wantsMidiMessages, wasPlaying;
  24296. HeapBlock <AudioBufferList> outputBufferList;
  24297. AudioTimeStamp timeStamp;
  24298. AudioSampleBuffer* currentBuffer;
  24299. AudioUnit audioUnit;
  24300. Array <int> parameterIds;
  24301. bool getComponentDescFromFile (const String& fileOrIdentifier);
  24302. void initialise();
  24303. OSStatus renderGetInput (AudioUnitRenderActionFlags* ioActionFlags,
  24304. const AudioTimeStamp* inTimeStamp,
  24305. UInt32 inBusNumber,
  24306. UInt32 inNumberFrames,
  24307. AudioBufferList* ioData) const;
  24308. static OSStatus renderGetInputCallback (void* inRefCon,
  24309. AudioUnitRenderActionFlags* ioActionFlags,
  24310. const AudioTimeStamp* inTimeStamp,
  24311. UInt32 inBusNumber,
  24312. UInt32 inNumberFrames,
  24313. AudioBufferList* ioData)
  24314. {
  24315. return ((AudioUnitPluginInstance*) inRefCon)
  24316. ->renderGetInput (ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, ioData);
  24317. }
  24318. OSStatus getBeatAndTempo (Float64* outCurrentBeat, Float64* outCurrentTempo) const;
  24319. OSStatus getMusicalTimeLocation (UInt32* outDeltaSampleOffsetToNextBeat, Float32* outTimeSig_Numerator,
  24320. UInt32* outTimeSig_Denominator, Float64* outCurrentMeasureDownBeat) const;
  24321. OSStatus getTransportState (Boolean* outIsPlaying, Boolean* outTransportStateChanged,
  24322. Float64* outCurrentSampleInTimeLine, Boolean* outIsCycling,
  24323. Float64* outCycleStartBeat, Float64* outCycleEndBeat);
  24324. static OSStatus getBeatAndTempoCallback (void* inHostUserData, Float64* outCurrentBeat, Float64* outCurrentTempo)
  24325. {
  24326. return ((AudioUnitPluginInstance*) inHostUserData)->getBeatAndTempo (outCurrentBeat, outCurrentTempo);
  24327. }
  24328. static OSStatus getMusicalTimeLocationCallback (void* inHostUserData, UInt32* outDeltaSampleOffsetToNextBeat,
  24329. Float32* outTimeSig_Numerator, UInt32* outTimeSig_Denominator,
  24330. Float64* outCurrentMeasureDownBeat)
  24331. {
  24332. return ((AudioUnitPluginInstance*) inHostUserData)
  24333. ->getMusicalTimeLocation (outDeltaSampleOffsetToNextBeat, outTimeSig_Numerator,
  24334. outTimeSig_Denominator, outCurrentMeasureDownBeat);
  24335. }
  24336. static OSStatus getTransportStateCallback (void* inHostUserData, Boolean* outIsPlaying, Boolean* outTransportStateChanged,
  24337. Float64* outCurrentSampleInTimeLine, Boolean* outIsCycling,
  24338. Float64* outCycleStartBeat, Float64* outCycleEndBeat)
  24339. {
  24340. return ((AudioUnitPluginInstance*) inHostUserData)
  24341. ->getTransportState (outIsPlaying, outTransportStateChanged,
  24342. outCurrentSampleInTimeLine, outIsCycling,
  24343. outCycleStartBeat, outCycleEndBeat);
  24344. }
  24345. void getNumChannels (int& numIns, int& numOuts)
  24346. {
  24347. numIns = 0;
  24348. numOuts = 0;
  24349. AUChannelInfo supportedChannels [128];
  24350. UInt32 supportedChannelsSize = sizeof (supportedChannels);
  24351. if (AudioUnitGetProperty (audioUnit, kAudioUnitProperty_SupportedNumChannels, kAudioUnitScope_Global,
  24352. 0, supportedChannels, &supportedChannelsSize) == noErr
  24353. && supportedChannelsSize > 0)
  24354. {
  24355. for (int i = 0; i < supportedChannelsSize / sizeof (AUChannelInfo); ++i)
  24356. {
  24357. numIns = jmax (numIns, (int) supportedChannels[i].inChannels);
  24358. numOuts = jmax (numOuts, (int) supportedChannels[i].outChannels);
  24359. }
  24360. }
  24361. else
  24362. {
  24363. // (this really means the plugin will take any number of ins/outs as long
  24364. // as they are the same)
  24365. numIns = numOuts = 2;
  24366. }
  24367. }
  24368. const String getCategory() const;
  24369. AudioUnitPluginInstance (const String& fileOrIdentifier);
  24370. };
  24371. AudioUnitPluginInstance::AudioUnitPluginInstance (const String& fileOrIdentifier)
  24372. : fileOrIdentifier (fileOrIdentifier),
  24373. initialised (false),
  24374. wantsMidiMessages (false),
  24375. audioUnit (0),
  24376. currentBuffer (0)
  24377. {
  24378. try
  24379. {
  24380. ++insideCallback;
  24381. log (T("Opening AU: ") + fileOrIdentifier);
  24382. if (getComponentDescFromFile (fileOrIdentifier))
  24383. {
  24384. ComponentRecord* const comp = FindNextComponent (0, &componentDesc);
  24385. if (comp != 0)
  24386. {
  24387. audioUnit = (AudioUnit) OpenComponent (comp);
  24388. wantsMidiMessages = componentDesc.componentType == kAudioUnitType_MusicDevice
  24389. || componentDesc.componentType == kAudioUnitType_MusicEffect;
  24390. }
  24391. }
  24392. --insideCallback;
  24393. }
  24394. catch (...)
  24395. {
  24396. --insideCallback;
  24397. }
  24398. }
  24399. AudioUnitPluginInstance::~AudioUnitPluginInstance()
  24400. {
  24401. {
  24402. const ScopedLock sl (lock);
  24403. jassert (insideCallback == 0);
  24404. if (audioUnit != 0)
  24405. {
  24406. AudioUnitUninitialize (audioUnit);
  24407. CloseComponent (audioUnit);
  24408. audioUnit = 0;
  24409. }
  24410. }
  24411. }
  24412. bool AudioUnitPluginInstance::getComponentDescFromFile (const String& fileOrIdentifier)
  24413. {
  24414. zerostruct (componentDesc);
  24415. if (getComponentDescFromIdentifier (fileOrIdentifier, componentDesc, pluginName, version, manufacturer))
  24416. return true;
  24417. const File file (fileOrIdentifier);
  24418. if (! file.hasFileExtension (T(".component")))
  24419. return false;
  24420. const char* const utf8 = fileOrIdentifier.toUTF8();
  24421. CFURLRef url = CFURLCreateFromFileSystemRepresentation (0, (const UInt8*) utf8,
  24422. strlen (utf8), file.isDirectory());
  24423. if (url != 0)
  24424. {
  24425. CFBundleRef bundleRef = CFBundleCreate (kCFAllocatorDefault, url);
  24426. CFRelease (url);
  24427. if (bundleRef != 0)
  24428. {
  24429. CFTypeRef name = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleName"));
  24430. if (name != 0 && CFGetTypeID (name) == CFStringGetTypeID())
  24431. pluginName = PlatformUtilities::cfStringToJuceString ((CFStringRef) name);
  24432. if (pluginName.isEmpty())
  24433. pluginName = file.getFileNameWithoutExtension();
  24434. CFTypeRef versionString = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleVersion"));
  24435. if (versionString != 0 && CFGetTypeID (versionString) == CFStringGetTypeID())
  24436. version = PlatformUtilities::cfStringToJuceString ((CFStringRef) versionString);
  24437. CFTypeRef manuString = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleGetInfoString"));
  24438. if (manuString != 0 && CFGetTypeID (manuString) == CFStringGetTypeID())
  24439. manufacturer = PlatformUtilities::cfStringToJuceString ((CFStringRef) manuString);
  24440. short resFileId = CFBundleOpenBundleResourceMap (bundleRef);
  24441. UseResFile (resFileId);
  24442. for (int i = 1; i <= Count1Resources ('thng'); ++i)
  24443. {
  24444. Handle h = Get1IndResource ('thng', i);
  24445. if (h != 0)
  24446. {
  24447. HLock (h);
  24448. const uint32* const types = (const uint32*) *h;
  24449. if (types[0] == kAudioUnitType_MusicDevice
  24450. || types[0] == kAudioUnitType_MusicEffect
  24451. || types[0] == kAudioUnitType_Effect
  24452. || types[0] == kAudioUnitType_Generator
  24453. || types[0] == kAudioUnitType_Panner)
  24454. {
  24455. componentDesc.componentType = types[0];
  24456. componentDesc.componentSubType = types[1];
  24457. componentDesc.componentManufacturer = types[2];
  24458. break;
  24459. }
  24460. HUnlock (h);
  24461. ReleaseResource (h);
  24462. }
  24463. }
  24464. CFBundleCloseBundleResourceMap (bundleRef, resFileId);
  24465. CFRelease (bundleRef);
  24466. }
  24467. }
  24468. return componentDesc.componentType != 0 && componentDesc.componentSubType != 0;
  24469. }
  24470. void AudioUnitPluginInstance::initialise()
  24471. {
  24472. if (initialised || audioUnit == 0)
  24473. return;
  24474. log (T("Initialising AU: ") + pluginName);
  24475. parameterIds.clear();
  24476. {
  24477. UInt32 paramListSize = 0;
  24478. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_ParameterList, kAudioUnitScope_Global,
  24479. 0, 0, &paramListSize);
  24480. if (paramListSize > 0)
  24481. {
  24482. parameterIds.insertMultiple (0, 0, paramListSize / sizeof (int));
  24483. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_ParameterList, kAudioUnitScope_Global,
  24484. 0, &parameterIds.getReference(0), &paramListSize);
  24485. }
  24486. }
  24487. {
  24488. AURenderCallbackStruct info;
  24489. zerostruct (info);
  24490. info.inputProcRefCon = this;
  24491. info.inputProc = renderGetInputCallback;
  24492. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input,
  24493. 0, &info, sizeof (info));
  24494. }
  24495. {
  24496. HostCallbackInfo info;
  24497. zerostruct (info);
  24498. info.hostUserData = this;
  24499. info.beatAndTempoProc = getBeatAndTempoCallback;
  24500. info.musicalTimeLocationProc = getMusicalTimeLocationCallback;
  24501. info.transportStateProc = getTransportStateCallback;
  24502. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_HostCallbacks, kAudioUnitScope_Global,
  24503. 0, &info, sizeof (info));
  24504. }
  24505. int numIns, numOuts;
  24506. getNumChannels (numIns, numOuts);
  24507. setPlayConfigDetails (numIns, numOuts, 0, 0);
  24508. initialised = AudioUnitInitialize (audioUnit) == noErr;
  24509. setLatencySamples (0);
  24510. }
  24511. void AudioUnitPluginInstance::prepareToPlay (double sampleRate_,
  24512. int samplesPerBlockExpected)
  24513. {
  24514. initialise();
  24515. if (initialised)
  24516. {
  24517. int numIns, numOuts;
  24518. getNumChannels (numIns, numOuts);
  24519. setPlayConfigDetails (numIns, numOuts, sampleRate_, samplesPerBlockExpected);
  24520. Float64 latencySecs = 0.0;
  24521. UInt32 latencySize = sizeof (latencySecs);
  24522. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_Latency, kAudioUnitScope_Global,
  24523. 0, &latencySecs, &latencySize);
  24524. setLatencySamples (roundToInt (latencySecs * sampleRate_));
  24525. AudioUnitReset (audioUnit, kAudioUnitScope_Input, 0);
  24526. AudioUnitReset (audioUnit, kAudioUnitScope_Output, 0);
  24527. AudioUnitReset (audioUnit, kAudioUnitScope_Global, 0);
  24528. AudioStreamBasicDescription stream;
  24529. zerostruct (stream);
  24530. stream.mSampleRate = sampleRate_;
  24531. stream.mFormatID = kAudioFormatLinearPCM;
  24532. stream.mFormatFlags = kAudioFormatFlagsNativeFloatPacked | kAudioFormatFlagIsNonInterleaved;
  24533. stream.mFramesPerPacket = 1;
  24534. stream.mBytesPerPacket = 4;
  24535. stream.mBytesPerFrame = 4;
  24536. stream.mBitsPerChannel = 32;
  24537. stream.mChannelsPerFrame = numIns;
  24538. OSStatus err = AudioUnitSetProperty (audioUnit,
  24539. kAudioUnitProperty_StreamFormat,
  24540. kAudioUnitScope_Input,
  24541. 0, &stream, sizeof (stream));
  24542. stream.mChannelsPerFrame = numOuts;
  24543. err = AudioUnitSetProperty (audioUnit,
  24544. kAudioUnitProperty_StreamFormat,
  24545. kAudioUnitScope_Output,
  24546. 0, &stream, sizeof (stream));
  24547. outputBufferList.calloc (sizeof (AudioBufferList) + sizeof (AudioBuffer) * (numOuts + 1), 1);
  24548. outputBufferList->mNumberBuffers = numOuts;
  24549. for (int i = numOuts; --i >= 0;)
  24550. outputBufferList->mBuffers[i].mNumberChannels = 1;
  24551. zerostruct (timeStamp);
  24552. timeStamp.mSampleTime = 0;
  24553. timeStamp.mHostTime = AudioGetCurrentHostTime();
  24554. timeStamp.mFlags = kAudioTimeStampSampleTimeValid | kAudioTimeStampHostTimeValid;
  24555. currentBuffer = 0;
  24556. wasPlaying = false;
  24557. }
  24558. }
  24559. void AudioUnitPluginInstance::releaseResources()
  24560. {
  24561. if (initialised)
  24562. {
  24563. AudioUnitReset (audioUnit, kAudioUnitScope_Input, 0);
  24564. AudioUnitReset (audioUnit, kAudioUnitScope_Output, 0);
  24565. AudioUnitReset (audioUnit, kAudioUnitScope_Global, 0);
  24566. outputBufferList.free();
  24567. currentBuffer = 0;
  24568. }
  24569. }
  24570. OSStatus AudioUnitPluginInstance::renderGetInput (AudioUnitRenderActionFlags* ioActionFlags,
  24571. const AudioTimeStamp* inTimeStamp,
  24572. UInt32 inBusNumber,
  24573. UInt32 inNumberFrames,
  24574. AudioBufferList* ioData) const
  24575. {
  24576. if (inBusNumber == 0
  24577. && currentBuffer != 0)
  24578. {
  24579. jassert (inNumberFrames == currentBuffer->getNumSamples()); // if this ever happens, might need to add extra handling
  24580. for (int i = 0; i < ioData->mNumberBuffers; ++i)
  24581. {
  24582. if (i < currentBuffer->getNumChannels())
  24583. {
  24584. memcpy (ioData->mBuffers[i].mData,
  24585. currentBuffer->getSampleData (i, 0),
  24586. sizeof (float) * inNumberFrames);
  24587. }
  24588. else
  24589. {
  24590. zeromem (ioData->mBuffers[i].mData, sizeof (float) * inNumberFrames);
  24591. }
  24592. }
  24593. }
  24594. return noErr;
  24595. }
  24596. void AudioUnitPluginInstance::processBlock (AudioSampleBuffer& buffer,
  24597. MidiBuffer& midiMessages)
  24598. {
  24599. const int numSamples = buffer.getNumSamples();
  24600. if (initialised)
  24601. {
  24602. AudioUnitRenderActionFlags flags = 0;
  24603. timeStamp.mHostTime = AudioGetCurrentHostTime();
  24604. for (int i = getNumOutputChannels(); --i >= 0;)
  24605. {
  24606. outputBufferList->mBuffers[i].mDataByteSize = sizeof (float) * numSamples;
  24607. outputBufferList->mBuffers[i].mData = buffer.getSampleData (i, 0);
  24608. }
  24609. currentBuffer = &buffer;
  24610. if (wantsMidiMessages)
  24611. {
  24612. const uint8* midiEventData;
  24613. int midiEventSize, midiEventPosition;
  24614. MidiBuffer::Iterator i (midiMessages);
  24615. while (i.getNextEvent (midiEventData, midiEventSize, midiEventPosition))
  24616. {
  24617. if (midiEventSize <= 3)
  24618. MusicDeviceMIDIEvent (audioUnit,
  24619. midiEventData[0], midiEventData[1], midiEventData[2],
  24620. midiEventPosition);
  24621. else
  24622. MusicDeviceSysEx (audioUnit, midiEventData, midiEventSize);
  24623. }
  24624. midiMessages.clear();
  24625. }
  24626. AudioUnitRender (audioUnit, &flags, &timeStamp,
  24627. 0, numSamples, outputBufferList);
  24628. timeStamp.mSampleTime += numSamples;
  24629. }
  24630. else
  24631. {
  24632. // Not initialised, so just bypass..
  24633. for (int i = getNumInputChannels(); i < getNumOutputChannels(); ++i)
  24634. buffer.clear (i, 0, buffer.getNumSamples());
  24635. }
  24636. }
  24637. OSStatus AudioUnitPluginInstance::getBeatAndTempo (Float64* outCurrentBeat, Float64* outCurrentTempo) const
  24638. {
  24639. AudioPlayHead* const ph = getPlayHead();
  24640. AudioPlayHead::CurrentPositionInfo result;
  24641. if (ph != 0 && ph->getCurrentPosition (result))
  24642. {
  24643. if (outCurrentBeat != 0)
  24644. *outCurrentBeat = result.ppqPosition;
  24645. if (outCurrentTempo != 0)
  24646. *outCurrentTempo = result.bpm;
  24647. }
  24648. else
  24649. {
  24650. if (outCurrentBeat != 0)
  24651. *outCurrentBeat = 0;
  24652. if (outCurrentTempo != 0)
  24653. *outCurrentTempo = 120.0;
  24654. }
  24655. return noErr;
  24656. }
  24657. OSStatus AudioUnitPluginInstance::getMusicalTimeLocation (UInt32* outDeltaSampleOffsetToNextBeat,
  24658. Float32* outTimeSig_Numerator,
  24659. UInt32* outTimeSig_Denominator,
  24660. Float64* outCurrentMeasureDownBeat) const
  24661. {
  24662. AudioPlayHead* const ph = getPlayHead();
  24663. AudioPlayHead::CurrentPositionInfo result;
  24664. if (ph != 0 && ph->getCurrentPosition (result))
  24665. {
  24666. if (outTimeSig_Numerator != 0)
  24667. *outTimeSig_Numerator = result.timeSigNumerator;
  24668. if (outTimeSig_Denominator != 0)
  24669. *outTimeSig_Denominator = result.timeSigDenominator;
  24670. if (outDeltaSampleOffsetToNextBeat != 0)
  24671. *outDeltaSampleOffsetToNextBeat = 0; //xxx
  24672. if (outCurrentMeasureDownBeat != 0)
  24673. *outCurrentMeasureDownBeat = result.ppqPositionOfLastBarStart; //xxx wrong
  24674. }
  24675. else
  24676. {
  24677. if (outDeltaSampleOffsetToNextBeat != 0)
  24678. *outDeltaSampleOffsetToNextBeat = 0;
  24679. if (outTimeSig_Numerator != 0)
  24680. *outTimeSig_Numerator = 4;
  24681. if (outTimeSig_Denominator != 0)
  24682. *outTimeSig_Denominator = 4;
  24683. if (outCurrentMeasureDownBeat != 0)
  24684. *outCurrentMeasureDownBeat = 0;
  24685. }
  24686. return noErr;
  24687. }
  24688. OSStatus AudioUnitPluginInstance::getTransportState (Boolean* outIsPlaying,
  24689. Boolean* outTransportStateChanged,
  24690. Float64* outCurrentSampleInTimeLine,
  24691. Boolean* outIsCycling,
  24692. Float64* outCycleStartBeat,
  24693. Float64* outCycleEndBeat)
  24694. {
  24695. AudioPlayHead* const ph = getPlayHead();
  24696. AudioPlayHead::CurrentPositionInfo result;
  24697. if (ph != 0 && ph->getCurrentPosition (result))
  24698. {
  24699. if (outIsPlaying != 0)
  24700. *outIsPlaying = result.isPlaying;
  24701. if (outTransportStateChanged != 0)
  24702. {
  24703. *outTransportStateChanged = result.isPlaying != wasPlaying;
  24704. wasPlaying = result.isPlaying;
  24705. }
  24706. if (outCurrentSampleInTimeLine != 0)
  24707. *outCurrentSampleInTimeLine = roundToInt (result.timeInSeconds * getSampleRate());
  24708. if (outIsCycling != 0)
  24709. *outIsCycling = false;
  24710. if (outCycleStartBeat != 0)
  24711. *outCycleStartBeat = 0;
  24712. if (outCycleEndBeat != 0)
  24713. *outCycleEndBeat = 0;
  24714. }
  24715. else
  24716. {
  24717. if (outIsPlaying != 0)
  24718. *outIsPlaying = false;
  24719. if (outTransportStateChanged != 0)
  24720. *outTransportStateChanged = false;
  24721. if (outCurrentSampleInTimeLine != 0)
  24722. *outCurrentSampleInTimeLine = 0;
  24723. if (outIsCycling != 0)
  24724. *outIsCycling = false;
  24725. if (outCycleStartBeat != 0)
  24726. *outCycleStartBeat = 0;
  24727. if (outCycleEndBeat != 0)
  24728. *outCycleEndBeat = 0;
  24729. }
  24730. return noErr;
  24731. }
  24732. static VoidArray activeWindows;
  24733. class AudioUnitPluginWindowCocoa : public AudioProcessorEditor
  24734. {
  24735. public:
  24736. AudioUnitPluginWindowCocoa (AudioUnitPluginInstance& plugin_, const bool createGenericViewIfNeeded)
  24737. : AudioProcessorEditor (&plugin_),
  24738. plugin (plugin_),
  24739. wrapper (0)
  24740. {
  24741. addAndMakeVisible (wrapper = new NSViewComponent());
  24742. activeWindows.add (this);
  24743. setOpaque (true);
  24744. setVisible (true);
  24745. setSize (100, 100);
  24746. createView (createGenericViewIfNeeded);
  24747. }
  24748. ~AudioUnitPluginWindowCocoa()
  24749. {
  24750. const bool wasValid = isValid();
  24751. wrapper->setView (0);
  24752. activeWindows.removeValue (this);
  24753. if (wasValid)
  24754. plugin.editorBeingDeleted (this);
  24755. delete wrapper;
  24756. }
  24757. bool isValid() const { return wrapper->getView() != 0; }
  24758. void paint (Graphics& g)
  24759. {
  24760. g.fillAll (Colours::white);
  24761. }
  24762. void resized()
  24763. {
  24764. wrapper->setSize (getWidth(), getHeight());
  24765. }
  24766. private:
  24767. AudioUnitPluginInstance& plugin;
  24768. NSViewComponent* wrapper;
  24769. bool createView (const bool createGenericViewIfNeeded)
  24770. {
  24771. NSView* pluginView = 0;
  24772. UInt32 dataSize = 0;
  24773. Boolean isWritable = false;
  24774. if (AudioUnitGetPropertyInfo (plugin.audioUnit, kAudioUnitProperty_CocoaUI, kAudioUnitScope_Global,
  24775. 0, &dataSize, &isWritable) == noErr
  24776. && dataSize != 0
  24777. && AudioUnitGetPropertyInfo (plugin.audioUnit, kAudioUnitProperty_CocoaUI, kAudioUnitScope_Global,
  24778. 0, &dataSize, &isWritable) == noErr)
  24779. {
  24780. HeapBlock <AudioUnitCocoaViewInfo> info;
  24781. info.calloc (dataSize, 1);
  24782. if (AudioUnitGetProperty (plugin.audioUnit, kAudioUnitProperty_CocoaUI, kAudioUnitScope_Global,
  24783. 0, info, &dataSize) == noErr)
  24784. {
  24785. NSString* viewClassName = (NSString*) (info->mCocoaAUViewClass[0]);
  24786. NSString* path = (NSString*) CFURLCopyPath (info->mCocoaAUViewBundleLocation);
  24787. NSBundle* viewBundle = [NSBundle bundleWithPath: [path autorelease]];
  24788. Class viewClass = [viewBundle classNamed: viewClassName];
  24789. if ([viewClass conformsToProtocol: @protocol (AUCocoaUIBase)]
  24790. && [viewClass instancesRespondToSelector: @selector (interfaceVersion)]
  24791. && [viewClass instancesRespondToSelector: @selector (uiViewForAudioUnit: withSize:)])
  24792. {
  24793. id factory = [[[viewClass alloc] init] autorelease];
  24794. pluginView = [factory uiViewForAudioUnit: plugin.audioUnit
  24795. withSize: NSMakeSize (getWidth(), getHeight())];
  24796. }
  24797. for (int i = (dataSize - sizeof (CFURLRef)) / sizeof (CFStringRef); --i >= 0;)
  24798. {
  24799. CFRelease (info->mCocoaAUViewClass[i]);
  24800. CFRelease (info->mCocoaAUViewBundleLocation);
  24801. }
  24802. }
  24803. }
  24804. if (createGenericViewIfNeeded && (pluginView == 0))
  24805. pluginView = [[AUGenericView alloc] initWithAudioUnit: plugin.audioUnit];
  24806. wrapper->setView (pluginView);
  24807. if (pluginView != 0)
  24808. setSize ([pluginView frame].size.width,
  24809. [pluginView frame].size.height);
  24810. return pluginView != 0;
  24811. }
  24812. };
  24813. #if JUCE_SUPPORT_CARBON
  24814. class AudioUnitPluginWindowCarbon : public AudioProcessorEditor
  24815. {
  24816. public:
  24817. AudioUnitPluginWindowCarbon (AudioUnitPluginInstance& plugin_)
  24818. : AudioProcessorEditor (&plugin_),
  24819. plugin (plugin_),
  24820. viewComponent (0)
  24821. {
  24822. addAndMakeVisible (innerWrapper = new InnerWrapperComponent (this));
  24823. activeWindows.add (this);
  24824. setOpaque (true);
  24825. setVisible (true);
  24826. setSize (400, 300);
  24827. ComponentDescription viewList [16];
  24828. UInt32 viewListSize = sizeof (viewList);
  24829. AudioUnitGetProperty (plugin.audioUnit, kAudioUnitProperty_GetUIComponentList, kAudioUnitScope_Global,
  24830. 0, &viewList, &viewListSize);
  24831. componentRecord = FindNextComponent (0, &viewList[0]);
  24832. }
  24833. ~AudioUnitPluginWindowCarbon()
  24834. {
  24835. deleteAndZero (innerWrapper);
  24836. activeWindows.removeValue (this);
  24837. if (isValid())
  24838. plugin.editorBeingDeleted (this);
  24839. }
  24840. bool isValid() const throw() { return componentRecord != 0; }
  24841. void paint (Graphics& g)
  24842. {
  24843. g.fillAll (Colours::black);
  24844. }
  24845. void resized()
  24846. {
  24847. innerWrapper->setSize (getWidth(), getHeight());
  24848. }
  24849. bool keyStateChanged (const bool)
  24850. {
  24851. return false;
  24852. }
  24853. bool keyPressed (const KeyPress&)
  24854. {
  24855. return false;
  24856. }
  24857. void broughtToFront()
  24858. {
  24859. activeWindows.removeValue (this);
  24860. activeWindows.add (this);
  24861. }
  24862. AudioUnit getAudioUnit() const { return plugin.audioUnit; }
  24863. AudioUnitCarbonView getViewComponent()
  24864. {
  24865. if (viewComponent == 0 && componentRecord != 0)
  24866. viewComponent = (AudioUnitCarbonView) OpenComponent (componentRecord);
  24867. return viewComponent;
  24868. }
  24869. void closeViewComponent()
  24870. {
  24871. if (viewComponent != 0)
  24872. {
  24873. CloseComponent (viewComponent);
  24874. viewComponent = 0;
  24875. }
  24876. }
  24877. juce_UseDebuggingNewOperator
  24878. private:
  24879. AudioUnitPluginInstance& plugin;
  24880. ComponentRecord* componentRecord;
  24881. AudioUnitCarbonView viewComponent;
  24882. class InnerWrapperComponent : public CarbonViewWrapperComponent
  24883. {
  24884. public:
  24885. InnerWrapperComponent (AudioUnitPluginWindowCarbon* const owner_)
  24886. : owner (owner_)
  24887. {
  24888. }
  24889. ~InnerWrapperComponent()
  24890. {
  24891. deleteWindow();
  24892. }
  24893. HIViewRef attachView (WindowRef windowRef, HIViewRef rootView)
  24894. {
  24895. log (T("Opening AU GUI: ") + owner->plugin.getName());
  24896. AudioUnitCarbonView viewComponent = owner->getViewComponent();
  24897. if (viewComponent == 0)
  24898. return 0;
  24899. Float32Point pos = { 0, 0 };
  24900. Float32Point size = { 250, 200 };
  24901. HIViewRef pluginView = 0;
  24902. AudioUnitCarbonViewCreate (viewComponent,
  24903. owner->getAudioUnit(),
  24904. windowRef,
  24905. rootView,
  24906. &pos,
  24907. &size,
  24908. (ControlRef*) &pluginView);
  24909. return pluginView;
  24910. }
  24911. void removeView (HIViewRef)
  24912. {
  24913. log (T("Closing AU GUI: ") + owner->plugin.getName());
  24914. owner->closeViewComponent();
  24915. }
  24916. private:
  24917. AudioUnitPluginWindowCarbon* const owner;
  24918. };
  24919. friend class InnerWrapperComponent;
  24920. InnerWrapperComponent* innerWrapper;
  24921. };
  24922. #endif
  24923. AudioProcessorEditor* AudioUnitPluginInstance::createEditor()
  24924. {
  24925. ScopedPointer <AudioProcessorEditor> w (new AudioUnitPluginWindowCocoa (*this, false));
  24926. if (! static_cast <AudioUnitPluginWindowCocoa*> (static_cast <AudioProcessorEditor> (w))->isValid())
  24927. w = 0;
  24928. #if JUCE_SUPPORT_CARBON
  24929. if (w == 0)
  24930. {
  24931. w = new AudioUnitPluginWindowCarbon (*this);
  24932. if (! static_cast <AudioUnitPluginWindowCocoa*> (static_cast <AudioProcessorEditor> (w))->isValid())
  24933. w = 0;
  24934. }
  24935. #endif
  24936. if (w == 0)
  24937. w = new AudioUnitPluginWindowCocoa (*this, true); // use AUGenericView as a fallback
  24938. return w.release();
  24939. }
  24940. const String AudioUnitPluginInstance::getCategory() const
  24941. {
  24942. const char* result = 0;
  24943. switch (componentDesc.componentType)
  24944. {
  24945. case kAudioUnitType_Effect:
  24946. case kAudioUnitType_MusicEffect:
  24947. result = "Effect";
  24948. break;
  24949. case kAudioUnitType_MusicDevice:
  24950. result = "Synth";
  24951. break;
  24952. case kAudioUnitType_Generator:
  24953. result = "Generator";
  24954. break;
  24955. case kAudioUnitType_Panner:
  24956. result = "Panner";
  24957. break;
  24958. default:
  24959. break;
  24960. }
  24961. return result;
  24962. }
  24963. int AudioUnitPluginInstance::getNumParameters()
  24964. {
  24965. return parameterIds.size();
  24966. }
  24967. float AudioUnitPluginInstance::getParameter (int index)
  24968. {
  24969. const ScopedLock sl (lock);
  24970. Float32 value = 0.0f;
  24971. if (audioUnit != 0 && ((unsigned int) index) < (unsigned int) parameterIds.size())
  24972. {
  24973. AudioUnitGetParameter (audioUnit,
  24974. (UInt32) parameterIds.getUnchecked (index),
  24975. kAudioUnitScope_Global, 0,
  24976. &value);
  24977. }
  24978. return value;
  24979. }
  24980. void AudioUnitPluginInstance::setParameter (int index, float newValue)
  24981. {
  24982. const ScopedLock sl (lock);
  24983. if (audioUnit != 0 && ((unsigned int) index) < (unsigned int) parameterIds.size())
  24984. {
  24985. AudioUnitSetParameter (audioUnit,
  24986. (UInt32) parameterIds.getUnchecked (index),
  24987. kAudioUnitScope_Global, 0,
  24988. newValue, 0);
  24989. }
  24990. }
  24991. const String AudioUnitPluginInstance::getParameterName (int index)
  24992. {
  24993. AudioUnitParameterInfo info;
  24994. zerostruct (info);
  24995. UInt32 sz = sizeof (info);
  24996. String name;
  24997. if (AudioUnitGetProperty (audioUnit,
  24998. kAudioUnitProperty_ParameterInfo,
  24999. kAudioUnitScope_Global,
  25000. parameterIds [index], &info, &sz) == noErr)
  25001. {
  25002. if ((info.flags & kAudioUnitParameterFlag_HasCFNameString) != 0)
  25003. name = PlatformUtilities::cfStringToJuceString (info.cfNameString);
  25004. else
  25005. name = String (info.name, sizeof (info.name));
  25006. }
  25007. return name;
  25008. }
  25009. const String AudioUnitPluginInstance::getParameterText (int index)
  25010. {
  25011. return String (getParameter (index));
  25012. }
  25013. bool AudioUnitPluginInstance::isParameterAutomatable (int index) const
  25014. {
  25015. AudioUnitParameterInfo info;
  25016. UInt32 sz = sizeof (info);
  25017. if (AudioUnitGetProperty (audioUnit,
  25018. kAudioUnitProperty_ParameterInfo,
  25019. kAudioUnitScope_Global,
  25020. parameterIds [index], &info, &sz) == noErr)
  25021. {
  25022. return (info.flags & kAudioUnitParameterFlag_NonRealTime) == 0;
  25023. }
  25024. return true;
  25025. }
  25026. int AudioUnitPluginInstance::getNumPrograms()
  25027. {
  25028. CFArrayRef presets;
  25029. UInt32 sz = sizeof (CFArrayRef);
  25030. int num = 0;
  25031. if (AudioUnitGetProperty (audioUnit,
  25032. kAudioUnitProperty_FactoryPresets,
  25033. kAudioUnitScope_Global,
  25034. 0, &presets, &sz) == noErr)
  25035. {
  25036. num = (int) CFArrayGetCount (presets);
  25037. CFRelease (presets);
  25038. }
  25039. return num;
  25040. }
  25041. int AudioUnitPluginInstance::getCurrentProgram()
  25042. {
  25043. AUPreset current;
  25044. current.presetNumber = 0;
  25045. UInt32 sz = sizeof (AUPreset);
  25046. AudioUnitGetProperty (audioUnit,
  25047. kAudioUnitProperty_FactoryPresets,
  25048. kAudioUnitScope_Global,
  25049. 0, &current, &sz);
  25050. return current.presetNumber;
  25051. }
  25052. void AudioUnitPluginInstance::setCurrentProgram (int newIndex)
  25053. {
  25054. AUPreset current;
  25055. current.presetNumber = newIndex;
  25056. current.presetName = 0;
  25057. AudioUnitSetProperty (audioUnit,
  25058. kAudioUnitProperty_FactoryPresets,
  25059. kAudioUnitScope_Global,
  25060. 0, &current, sizeof (AUPreset));
  25061. }
  25062. const String AudioUnitPluginInstance::getProgramName (int index)
  25063. {
  25064. String s;
  25065. CFArrayRef presets;
  25066. UInt32 sz = sizeof (CFArrayRef);
  25067. if (AudioUnitGetProperty (audioUnit,
  25068. kAudioUnitProperty_FactoryPresets,
  25069. kAudioUnitScope_Global,
  25070. 0, &presets, &sz) == noErr)
  25071. {
  25072. for (CFIndex i = 0; i < CFArrayGetCount (presets); ++i)
  25073. {
  25074. const AUPreset* p = (const AUPreset*) CFArrayGetValueAtIndex (presets, i);
  25075. if (p != 0 && p->presetNumber == index)
  25076. {
  25077. s = PlatformUtilities::cfStringToJuceString (p->presetName);
  25078. break;
  25079. }
  25080. }
  25081. CFRelease (presets);
  25082. }
  25083. return s;
  25084. }
  25085. void AudioUnitPluginInstance::changeProgramName (int index, const String& newName)
  25086. {
  25087. jassertfalse // xxx not implemented!
  25088. }
  25089. const String AudioUnitPluginInstance::getInputChannelName (const int index) const
  25090. {
  25091. if (((unsigned int) index) < (unsigned int) getNumInputChannels())
  25092. return T("Input ") + String (index + 1);
  25093. return String::empty;
  25094. }
  25095. bool AudioUnitPluginInstance::isInputChannelStereoPair (int index) const
  25096. {
  25097. if (((unsigned int) index) >= (unsigned int) getNumInputChannels())
  25098. return false;
  25099. return true;
  25100. }
  25101. const String AudioUnitPluginInstance::getOutputChannelName (const int index) const
  25102. {
  25103. if (((unsigned int) index) < (unsigned int) getNumOutputChannels())
  25104. return T("Output ") + String (index + 1);
  25105. return String::empty;
  25106. }
  25107. bool AudioUnitPluginInstance::isOutputChannelStereoPair (int index) const
  25108. {
  25109. if (((unsigned int) index) >= (unsigned int) getNumOutputChannels())
  25110. return false;
  25111. return true;
  25112. }
  25113. void AudioUnitPluginInstance::getStateInformation (MemoryBlock& destData)
  25114. {
  25115. getCurrentProgramStateInformation (destData);
  25116. }
  25117. void AudioUnitPluginInstance::getCurrentProgramStateInformation (MemoryBlock& destData)
  25118. {
  25119. CFPropertyListRef propertyList = 0;
  25120. UInt32 sz = sizeof (CFPropertyListRef);
  25121. if (AudioUnitGetProperty (audioUnit,
  25122. kAudioUnitProperty_ClassInfo,
  25123. kAudioUnitScope_Global,
  25124. 0, &propertyList, &sz) == noErr)
  25125. {
  25126. CFWriteStreamRef stream = CFWriteStreamCreateWithAllocatedBuffers (kCFAllocatorDefault, kCFAllocatorDefault);
  25127. CFWriteStreamOpen (stream);
  25128. CFIndex bytesWritten = CFPropertyListWriteToStream (propertyList, stream, kCFPropertyListBinaryFormat_v1_0, 0);
  25129. CFWriteStreamClose (stream);
  25130. CFDataRef data = (CFDataRef) CFWriteStreamCopyProperty (stream, kCFStreamPropertyDataWritten);
  25131. destData.setSize (bytesWritten);
  25132. destData.copyFrom (CFDataGetBytePtr (data), 0, destData.getSize());
  25133. CFRelease (data);
  25134. CFRelease (stream);
  25135. CFRelease (propertyList);
  25136. }
  25137. }
  25138. void AudioUnitPluginInstance::setStateInformation (const void* data, int sizeInBytes)
  25139. {
  25140. setCurrentProgramStateInformation (data, sizeInBytes);
  25141. }
  25142. void AudioUnitPluginInstance::setCurrentProgramStateInformation (const void* data, int sizeInBytes)
  25143. {
  25144. CFReadStreamRef stream = CFReadStreamCreateWithBytesNoCopy (kCFAllocatorDefault,
  25145. (const UInt8*) data,
  25146. sizeInBytes,
  25147. kCFAllocatorNull);
  25148. CFReadStreamOpen (stream);
  25149. CFPropertyListFormat format = kCFPropertyListBinaryFormat_v1_0;
  25150. CFPropertyListRef propertyList = CFPropertyListCreateFromStream (kCFAllocatorDefault,
  25151. stream,
  25152. 0,
  25153. kCFPropertyListImmutable,
  25154. &format,
  25155. 0);
  25156. CFRelease (stream);
  25157. if (propertyList != 0)
  25158. AudioUnitSetProperty (audioUnit,
  25159. kAudioUnitProperty_ClassInfo,
  25160. kAudioUnitScope_Global,
  25161. 0, &propertyList, sizeof (propertyList));
  25162. }
  25163. AudioUnitPluginFormat::AudioUnitPluginFormat()
  25164. {
  25165. }
  25166. AudioUnitPluginFormat::~AudioUnitPluginFormat()
  25167. {
  25168. }
  25169. void AudioUnitPluginFormat::findAllTypesForFile (OwnedArray <PluginDescription>& results,
  25170. const String& fileOrIdentifier)
  25171. {
  25172. if (! fileMightContainThisPluginType (fileOrIdentifier))
  25173. return;
  25174. PluginDescription desc;
  25175. desc.fileOrIdentifier = fileOrIdentifier;
  25176. desc.uid = 0;
  25177. try
  25178. {
  25179. ScopedPointer <AudioPluginInstance> createdInstance (createInstanceFromDescription (desc));
  25180. AudioUnitPluginInstance* const auInstance = dynamic_cast <AudioUnitPluginInstance*> ((AudioPluginInstance*) createdInstance);
  25181. if (auInstance != 0)
  25182. {
  25183. auInstance->fillInPluginDescription (desc);
  25184. results.add (new PluginDescription (desc));
  25185. }
  25186. }
  25187. catch (...)
  25188. {
  25189. // crashed while loading...
  25190. }
  25191. }
  25192. AudioPluginInstance* AudioUnitPluginFormat::createInstanceFromDescription (const PluginDescription& desc)
  25193. {
  25194. if (fileMightContainThisPluginType (desc.fileOrIdentifier))
  25195. {
  25196. ScopedPointer <AudioUnitPluginInstance> result (new AudioUnitPluginInstance (desc.fileOrIdentifier));
  25197. if (result->audioUnit != 0)
  25198. {
  25199. result->initialise();
  25200. return result.release();
  25201. }
  25202. }
  25203. return 0;
  25204. }
  25205. const StringArray AudioUnitPluginFormat::searchPathsForPlugins (const FileSearchPath& /*directoriesToSearch*/,
  25206. const bool /*recursive*/)
  25207. {
  25208. StringArray result;
  25209. ComponentRecord* comp = 0;
  25210. ComponentDescription desc;
  25211. zerostruct (desc);
  25212. for (;;)
  25213. {
  25214. zerostruct (desc);
  25215. comp = FindNextComponent (comp, &desc);
  25216. if (comp == 0)
  25217. break;
  25218. GetComponentInfo (comp, &desc, 0, 0, 0);
  25219. if (desc.componentType == kAudioUnitType_MusicDevice
  25220. || desc.componentType == kAudioUnitType_MusicEffect
  25221. || desc.componentType == kAudioUnitType_Effect
  25222. || desc.componentType == kAudioUnitType_Generator
  25223. || desc.componentType == kAudioUnitType_Panner)
  25224. {
  25225. const String s (createAUPluginIdentifier (desc));
  25226. DBG (s);
  25227. result.add (s);
  25228. }
  25229. }
  25230. return result;
  25231. }
  25232. bool AudioUnitPluginFormat::fileMightContainThisPluginType (const String& fileOrIdentifier)
  25233. {
  25234. ComponentDescription desc;
  25235. String name, version, manufacturer;
  25236. if (getComponentDescFromIdentifier (fileOrIdentifier, desc, name, version, manufacturer))
  25237. return FindNextComponent (0, &desc) != 0;
  25238. const File f (fileOrIdentifier);
  25239. return f.hasFileExtension (T(".component"))
  25240. && f.isDirectory();
  25241. }
  25242. const String AudioUnitPluginFormat::getNameOfPluginFromIdentifier (const String& fileOrIdentifier)
  25243. {
  25244. ComponentDescription desc;
  25245. String name, version, manufacturer;
  25246. getComponentDescFromIdentifier (fileOrIdentifier, desc, name, version, manufacturer);
  25247. if (name.isEmpty())
  25248. name = fileOrIdentifier;
  25249. return name;
  25250. }
  25251. bool AudioUnitPluginFormat::doesPluginStillExist (const PluginDescription& desc)
  25252. {
  25253. if (desc.fileOrIdentifier.startsWithIgnoreCase (auIdentifierPrefix))
  25254. return fileMightContainThisPluginType (desc.fileOrIdentifier);
  25255. else
  25256. return File (desc.fileOrIdentifier).exists();
  25257. }
  25258. const FileSearchPath AudioUnitPluginFormat::getDefaultLocationsToSearch()
  25259. {
  25260. return FileSearchPath ("/(Default AudioUnit locations)");
  25261. }
  25262. #endif
  25263. END_JUCE_NAMESPACE
  25264. #undef log
  25265. #endif
  25266. /*** End of inlined file: juce_AudioUnitPluginFormat.mm ***/
  25267. /*** Start of inlined file: juce_VSTPluginFormat.mm ***/
  25268. // This file just wraps juce_VSTPluginFormat.cpp in an objective-C wrapper
  25269. #define JUCE_MAC_VST_INCLUDED 1
  25270. /*** Start of inlined file: juce_VSTPluginFormat.cpp ***/
  25271. #if JUCE_PLUGINHOST_VST
  25272. #if (defined (_WIN32) || defined (_WIN64))
  25273. #undef _WIN32_WINNT
  25274. #define _WIN32_WINNT 0x500
  25275. #undef STRICT
  25276. #define STRICT
  25277. #include <windows.h>
  25278. #include <float.h>
  25279. #pragma warning (disable : 4312 4355)
  25280. #elif defined (LINUX) || defined (__linux__)
  25281. #include <float.h>
  25282. #include <sys/time.h>
  25283. #include <X11/Xlib.h>
  25284. #include <X11/Xutil.h>
  25285. #include <X11/Xatom.h>
  25286. #undef Font
  25287. #undef KeyPress
  25288. #undef Drawable
  25289. #undef Time
  25290. #else
  25291. #ifndef JUCE_MAC_VST_INCLUDED
  25292. // On the mac, this file needs to be compiled indirectly, by using
  25293. // juce_VSTPluginFormat.mm instead - that wraps it as an objective-C file for cocoa
  25294. #error
  25295. #endif
  25296. #include <Cocoa/Cocoa.h>
  25297. #include <Carbon/Carbon.h>
  25298. #endif
  25299. #if ! (JUCE_MAC && JUCE_64BIT)
  25300. BEGIN_JUCE_NAMESPACE
  25301. #if JUCE_MAC && JUCE_SUPPORT_CARBON
  25302. #endif
  25303. #undef PRAGMA_ALIGN_SUPPORTED
  25304. #define VST_FORCE_DEPRECATED 0
  25305. #ifdef _MSC_VER
  25306. #pragma warning (push)
  25307. #pragma warning (disable: 4996)
  25308. #endif
  25309. #include "pluginterfaces/vst2.x/aeffectx.h"
  25310. #ifdef _MSC_VER
  25311. #pragma warning (pop)
  25312. #endif
  25313. #if JUCE_LINUX
  25314. #define Font JUCE_NAMESPACE::Font
  25315. #define KeyPress JUCE_NAMESPACE::KeyPress
  25316. #define Drawable JUCE_NAMESPACE::Drawable
  25317. #define Time JUCE_NAMESPACE::Time
  25318. #endif
  25319. /*** Start of inlined file: juce_VSTMidiEventList.h ***/
  25320. #ifdef __aeffect__
  25321. #ifndef __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25322. #define __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25323. class VSTMidiEventList
  25324. {
  25325. public:
  25326. VSTMidiEventList()
  25327. : numEventsUsed (0), numEventsAllocated (0)
  25328. {
  25329. }
  25330. ~VSTMidiEventList()
  25331. {
  25332. freeEvents();
  25333. }
  25334. void clear()
  25335. {
  25336. numEventsUsed = 0;
  25337. if (events != 0)
  25338. events->numEvents = 0;
  25339. }
  25340. void addEvent (const void* const midiData, const int numBytes, const int frameOffset)
  25341. {
  25342. ensureSize (numEventsUsed + 1);
  25343. VstMidiEvent* const e = (VstMidiEvent*) (events->events [numEventsUsed]);
  25344. events->numEvents = ++numEventsUsed;
  25345. if (numBytes <= 4)
  25346. {
  25347. if (e->type == kVstSysExType)
  25348. {
  25349. juce_free (((VstMidiSysexEvent*) e)->sysexDump);
  25350. e->type = kVstMidiType;
  25351. e->byteSize = sizeof (VstMidiEvent);
  25352. e->noteLength = 0;
  25353. e->noteOffset = 0;
  25354. e->detune = 0;
  25355. e->noteOffVelocity = 0;
  25356. }
  25357. e->deltaFrames = frameOffset;
  25358. memcpy (e->midiData, midiData, numBytes);
  25359. }
  25360. else
  25361. {
  25362. VstMidiSysexEvent* const se = (VstMidiSysexEvent*) e;
  25363. if (se->type == kVstSysExType)
  25364. se->sysexDump = (char*) juce_realloc (se->sysexDump, numBytes);
  25365. else
  25366. se->sysexDump = (char*) juce_malloc (numBytes);
  25367. memcpy (se->sysexDump, midiData, numBytes);
  25368. se->type = kVstSysExType;
  25369. se->byteSize = sizeof (VstMidiSysexEvent);
  25370. se->deltaFrames = frameOffset;
  25371. se->flags = 0;
  25372. se->dumpBytes = numBytes;
  25373. se->resvd1 = 0;
  25374. se->resvd2 = 0;
  25375. }
  25376. }
  25377. // Handy method to pull the events out of an event buffer supplied by the host
  25378. // or plugin.
  25379. static void addEventsToMidiBuffer (const VstEvents* events, MidiBuffer& dest)
  25380. {
  25381. for (int i = 0; i < events->numEvents; ++i)
  25382. {
  25383. const VstEvent* const e = events->events[i];
  25384. if (e != 0)
  25385. {
  25386. if (e->type == kVstMidiType)
  25387. {
  25388. dest.addEvent ((const JUCE_NAMESPACE::uint8*) ((const VstMidiEvent*) e)->midiData,
  25389. 4, e->deltaFrames);
  25390. }
  25391. else if (e->type == kVstSysExType)
  25392. {
  25393. dest.addEvent ((const JUCE_NAMESPACE::uint8*) ((const VstMidiSysexEvent*) e)->sysexDump,
  25394. (int) ((const VstMidiSysexEvent*) e)->dumpBytes,
  25395. e->deltaFrames);
  25396. }
  25397. }
  25398. }
  25399. }
  25400. void ensureSize (int numEventsNeeded)
  25401. {
  25402. if (numEventsNeeded > numEventsAllocated)
  25403. {
  25404. numEventsNeeded = (numEventsNeeded + 32) & ~31;
  25405. const int size = 20 + sizeof (VstEvent*) * numEventsNeeded;
  25406. if (events == 0)
  25407. events.calloc (size, 1);
  25408. else
  25409. events.realloc (size, 1);
  25410. for (int i = numEventsAllocated; i < numEventsNeeded; ++i)
  25411. {
  25412. VstMidiEvent* const e = (VstMidiEvent*) juce_calloc (jmax ((int) sizeof (VstMidiEvent),
  25413. (int) sizeof (VstMidiSysexEvent)));
  25414. e->type = kVstMidiType;
  25415. e->byteSize = sizeof (VstMidiEvent);
  25416. events->events[i] = (VstEvent*) e;
  25417. }
  25418. numEventsAllocated = numEventsNeeded;
  25419. }
  25420. }
  25421. void freeEvents()
  25422. {
  25423. if (events != 0)
  25424. {
  25425. for (int i = numEventsAllocated; --i >= 0;)
  25426. {
  25427. VstMidiEvent* const e = (VstMidiEvent*) (events->events[i]);
  25428. if (e->type == kVstSysExType)
  25429. juce_free (((VstMidiSysexEvent*) e)->sysexDump);
  25430. juce_free (e);
  25431. }
  25432. events.free();
  25433. numEventsUsed = 0;
  25434. numEventsAllocated = 0;
  25435. }
  25436. }
  25437. HeapBlock <VstEvents> events;
  25438. private:
  25439. int numEventsUsed, numEventsAllocated;
  25440. };
  25441. #endif // __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25442. #endif // __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25443. /*** End of inlined file: juce_VSTMidiEventList.h ***/
  25444. #if ! JUCE_WIN32
  25445. static void _fpreset() {}
  25446. static void _clearfp() {}
  25447. #endif
  25448. extern void juce_callAnyTimersSynchronously();
  25449. const int fxbVersionNum = 1;
  25450. struct fxProgram
  25451. {
  25452. long chunkMagic; // 'CcnK'
  25453. long byteSize; // of this chunk, excl. magic + byteSize
  25454. long fxMagic; // 'FxCk'
  25455. long version;
  25456. long fxID; // fx unique id
  25457. long fxVersion;
  25458. long numParams;
  25459. char prgName[28];
  25460. float params[1]; // variable no. of parameters
  25461. };
  25462. struct fxSet
  25463. {
  25464. long chunkMagic; // 'CcnK'
  25465. long byteSize; // of this chunk, excl. magic + byteSize
  25466. long fxMagic; // 'FxBk'
  25467. long version;
  25468. long fxID; // fx unique id
  25469. long fxVersion;
  25470. long numPrograms;
  25471. char future[128];
  25472. fxProgram programs[1]; // variable no. of programs
  25473. };
  25474. struct fxChunkSet
  25475. {
  25476. long chunkMagic; // 'CcnK'
  25477. long byteSize; // of this chunk, excl. magic + byteSize
  25478. long fxMagic; // 'FxCh', 'FPCh', or 'FBCh'
  25479. long version;
  25480. long fxID; // fx unique id
  25481. long fxVersion;
  25482. long numPrograms;
  25483. char future[128];
  25484. long chunkSize;
  25485. char chunk[8]; // variable
  25486. };
  25487. struct fxProgramSet
  25488. {
  25489. long chunkMagic; // 'CcnK'
  25490. long byteSize; // of this chunk, excl. magic + byteSize
  25491. long fxMagic; // 'FxCh', 'FPCh', or 'FBCh'
  25492. long version;
  25493. long fxID; // fx unique id
  25494. long fxVersion;
  25495. long numPrograms;
  25496. char name[28];
  25497. long chunkSize;
  25498. char chunk[8]; // variable
  25499. };
  25500. static long vst_swap (const long x) throw()
  25501. {
  25502. #ifdef JUCE_LITTLE_ENDIAN
  25503. return (long) ByteOrder::swap ((uint32) x);
  25504. #else
  25505. return x;
  25506. #endif
  25507. }
  25508. static float vst_swapFloat (const float x) throw()
  25509. {
  25510. #ifdef JUCE_LITTLE_ENDIAN
  25511. union { uint32 asInt; float asFloat; } n;
  25512. n.asFloat = x;
  25513. n.asInt = ByteOrder::swap (n.asInt);
  25514. return n.asFloat;
  25515. #else
  25516. return x;
  25517. #endif
  25518. }
  25519. typedef AEffect* (*MainCall) (audioMasterCallback);
  25520. static VstIntPtr VSTCALLBACK audioMaster (AEffect* effect, VstInt32 opcode, VstInt32 index, VstIntPtr value, void* ptr, float opt);
  25521. static int shellUIDToCreate = 0;
  25522. static int insideVSTCallback = 0;
  25523. class VSTPluginWindow;
  25524. // Change this to disable logging of various VST activities
  25525. #ifndef VST_LOGGING
  25526. #define VST_LOGGING 1
  25527. #endif
  25528. #if VST_LOGGING
  25529. #define log(a) Logger::writeToLog(a);
  25530. #else
  25531. #define log(a)
  25532. #endif
  25533. #if JUCE_MAC && JUCE_PPC
  25534. static void* NewCFMFromMachO (void* const machofp) throw()
  25535. {
  25536. void* result = juce_malloc (8);
  25537. ((void**) result)[0] = machofp;
  25538. ((void**) result)[1] = result;
  25539. return result;
  25540. }
  25541. #endif
  25542. #if JUCE_LINUX
  25543. extern Display* display;
  25544. extern XContext improbableNumber;
  25545. typedef void (*EventProcPtr) (XEvent* ev);
  25546. static bool xErrorTriggered;
  25547. static int temporaryErrorHandler (Display*, XErrorEvent*)
  25548. {
  25549. xErrorTriggered = true;
  25550. return 0;
  25551. }
  25552. static int getPropertyFromXWindow (Window handle, Atom atom)
  25553. {
  25554. XErrorHandler oldErrorHandler = XSetErrorHandler (temporaryErrorHandler);
  25555. xErrorTriggered = false;
  25556. int userSize;
  25557. unsigned long bytes, userCount;
  25558. unsigned char* data;
  25559. Atom userType;
  25560. XGetWindowProperty (display, handle, atom, 0, 1, false, AnyPropertyType,
  25561. &userType, &userSize, &userCount, &bytes, &data);
  25562. XSetErrorHandler (oldErrorHandler);
  25563. return (userCount == 1 && ! xErrorTriggered) ? *(int*) data
  25564. : 0;
  25565. }
  25566. static Window getChildWindow (Window windowToCheck)
  25567. {
  25568. Window rootWindow, parentWindow;
  25569. Window* childWindows;
  25570. unsigned int numChildren;
  25571. XQueryTree (display,
  25572. windowToCheck,
  25573. &rootWindow,
  25574. &parentWindow,
  25575. &childWindows,
  25576. &numChildren);
  25577. if (numChildren > 0)
  25578. return childWindows [0];
  25579. return 0;
  25580. }
  25581. static void translateJuceToXButtonModifiers (const MouseEvent& e, XEvent& ev) throw()
  25582. {
  25583. if (e.mods.isLeftButtonDown())
  25584. {
  25585. ev.xbutton.button = Button1;
  25586. ev.xbutton.state |= Button1Mask;
  25587. }
  25588. else if (e.mods.isRightButtonDown())
  25589. {
  25590. ev.xbutton.button = Button3;
  25591. ev.xbutton.state |= Button3Mask;
  25592. }
  25593. else if (e.mods.isMiddleButtonDown())
  25594. {
  25595. ev.xbutton.button = Button2;
  25596. ev.xbutton.state |= Button2Mask;
  25597. }
  25598. }
  25599. static void translateJuceToXMotionModifiers (const MouseEvent& e, XEvent& ev) throw()
  25600. {
  25601. if (e.mods.isLeftButtonDown())
  25602. ev.xmotion.state |= Button1Mask;
  25603. else if (e.mods.isRightButtonDown())
  25604. ev.xmotion.state |= Button3Mask;
  25605. else if (e.mods.isMiddleButtonDown())
  25606. ev.xmotion.state |= Button2Mask;
  25607. }
  25608. static void translateJuceToXCrossingModifiers (const MouseEvent& e, XEvent& ev) throw()
  25609. {
  25610. if (e.mods.isLeftButtonDown())
  25611. ev.xcrossing.state |= Button1Mask;
  25612. else if (e.mods.isRightButtonDown())
  25613. ev.xcrossing.state |= Button3Mask;
  25614. else if (e.mods.isMiddleButtonDown())
  25615. ev.xcrossing.state |= Button2Mask;
  25616. }
  25617. static void translateJuceToXMouseWheelModifiers (const MouseEvent& e, const float increment, XEvent& ev) throw()
  25618. {
  25619. if (increment < 0)
  25620. {
  25621. ev.xbutton.button = Button5;
  25622. ev.xbutton.state |= Button5Mask;
  25623. }
  25624. else if (increment > 0)
  25625. {
  25626. ev.xbutton.button = Button4;
  25627. ev.xbutton.state |= Button4Mask;
  25628. }
  25629. }
  25630. #endif
  25631. static VoidArray activeModules;
  25632. class ModuleHandle : public ReferenceCountedObject
  25633. {
  25634. public:
  25635. File file;
  25636. MainCall moduleMain;
  25637. String pluginName;
  25638. static ModuleHandle* findOrCreateModule (const File& file)
  25639. {
  25640. for (int i = activeModules.size(); --i >= 0;)
  25641. {
  25642. ModuleHandle* const module = (ModuleHandle*) activeModules.getUnchecked(i);
  25643. if (module->file == file)
  25644. return module;
  25645. }
  25646. _fpreset(); // (doesn't do any harm)
  25647. ++insideVSTCallback;
  25648. shellUIDToCreate = 0;
  25649. log ("Attempting to load VST: " + file.getFullPathName());
  25650. ScopedPointer <ModuleHandle> m (new ModuleHandle (file));
  25651. if (! m->open())
  25652. m = 0;
  25653. --insideVSTCallback;
  25654. _fpreset(); // (doesn't do any harm)
  25655. return m.release();
  25656. }
  25657. ModuleHandle (const File& file_)
  25658. : file (file_),
  25659. moduleMain (0),
  25660. #if JUCE_WIN32 || JUCE_LINUX
  25661. hModule (0)
  25662. #elif JUCE_MAC
  25663. fragId (0),
  25664. resHandle (0),
  25665. bundleRef (0),
  25666. resFileId (0)
  25667. #endif
  25668. {
  25669. activeModules.add (this);
  25670. #if JUCE_WIN32 || JUCE_LINUX
  25671. fullParentDirectoryPathName = file_.getParentDirectory().getFullPathName();
  25672. #elif JUCE_MAC
  25673. FSRef ref;
  25674. PlatformUtilities::makeFSRefFromPath (&ref, file_.getParentDirectory().getFullPathName());
  25675. FSGetCatalogInfo (&ref, kFSCatInfoNone, 0, 0, &parentDirFSSpec, 0);
  25676. #endif
  25677. }
  25678. ~ModuleHandle()
  25679. {
  25680. activeModules.removeValue (this);
  25681. close();
  25682. }
  25683. juce_UseDebuggingNewOperator
  25684. #if JUCE_WIN32 || JUCE_LINUX
  25685. void* hModule;
  25686. String fullParentDirectoryPathName;
  25687. bool open()
  25688. {
  25689. #if JUCE_WIN32
  25690. static bool timePeriodSet = false;
  25691. if (! timePeriodSet)
  25692. {
  25693. timePeriodSet = true;
  25694. timeBeginPeriod (2);
  25695. }
  25696. #endif
  25697. pluginName = file.getFileNameWithoutExtension();
  25698. hModule = PlatformUtilities::loadDynamicLibrary (file.getFullPathName());
  25699. moduleMain = (MainCall) PlatformUtilities::getProcedureEntryPoint (hModule, "VSTPluginMain");
  25700. if (moduleMain == 0)
  25701. moduleMain = (MainCall) PlatformUtilities::getProcedureEntryPoint (hModule, "main");
  25702. return moduleMain != 0;
  25703. }
  25704. void close()
  25705. {
  25706. _fpreset(); // (doesn't do any harm)
  25707. PlatformUtilities::freeDynamicLibrary (hModule);
  25708. }
  25709. void closeEffect (AEffect* eff)
  25710. {
  25711. eff->dispatcher (eff, effClose, 0, 0, 0, 0);
  25712. }
  25713. #else
  25714. CFragConnectionID fragId;
  25715. Handle resHandle;
  25716. CFBundleRef bundleRef;
  25717. FSSpec parentDirFSSpec;
  25718. short resFileId;
  25719. bool open()
  25720. {
  25721. bool ok = false;
  25722. const String filename (file.getFullPathName());
  25723. if (file.hasFileExtension (T(".vst")))
  25724. {
  25725. const char* const utf8 = filename.toUTF8();
  25726. CFURLRef url = CFURLCreateFromFileSystemRepresentation (0, (const UInt8*) utf8,
  25727. strlen (utf8), file.isDirectory());
  25728. if (url != 0)
  25729. {
  25730. bundleRef = CFBundleCreate (kCFAllocatorDefault, url);
  25731. CFRelease (url);
  25732. if (bundleRef != 0)
  25733. {
  25734. if (CFBundleLoadExecutable (bundleRef))
  25735. {
  25736. moduleMain = (MainCall) CFBundleGetFunctionPointerForName (bundleRef, CFSTR("main_macho"));
  25737. if (moduleMain == 0)
  25738. moduleMain = (MainCall) CFBundleGetFunctionPointerForName (bundleRef, CFSTR("VSTPluginMain"));
  25739. if (moduleMain != 0)
  25740. {
  25741. CFTypeRef name = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleName"));
  25742. if (name != 0)
  25743. {
  25744. if (CFGetTypeID (name) == CFStringGetTypeID())
  25745. {
  25746. char buffer[1024];
  25747. if (CFStringGetCString ((CFStringRef) name, buffer, sizeof (buffer), CFStringGetSystemEncoding()))
  25748. pluginName = buffer;
  25749. }
  25750. }
  25751. if (pluginName.isEmpty())
  25752. pluginName = file.getFileNameWithoutExtension();
  25753. resFileId = CFBundleOpenBundleResourceMap (bundleRef);
  25754. ok = true;
  25755. }
  25756. }
  25757. if (! ok)
  25758. {
  25759. CFBundleUnloadExecutable (bundleRef);
  25760. CFRelease (bundleRef);
  25761. bundleRef = 0;
  25762. }
  25763. }
  25764. }
  25765. }
  25766. #if JUCE_PPC
  25767. else
  25768. {
  25769. FSRef fn;
  25770. if (FSPathMakeRef ((UInt8*) filename.toUTF8(), &fn, 0) == noErr)
  25771. {
  25772. resFileId = FSOpenResFile (&fn, fsRdPerm);
  25773. if (resFileId != -1)
  25774. {
  25775. const int numEffs = Count1Resources ('aEff');
  25776. for (int i = 0; i < numEffs; ++i)
  25777. {
  25778. resHandle = Get1IndResource ('aEff', i + 1);
  25779. if (resHandle != 0)
  25780. {
  25781. OSType type;
  25782. Str255 name;
  25783. SInt16 id;
  25784. GetResInfo (resHandle, &id, &type, name);
  25785. pluginName = String ((const char*) name + 1, name[0]);
  25786. DetachResource (resHandle);
  25787. HLock (resHandle);
  25788. Ptr ptr;
  25789. Str255 errorText;
  25790. OSErr err = GetMemFragment (*resHandle, GetHandleSize (resHandle),
  25791. name, kPrivateCFragCopy,
  25792. &fragId, &ptr, errorText);
  25793. if (err == noErr)
  25794. {
  25795. moduleMain = (MainCall) newMachOFromCFM (ptr);
  25796. ok = true;
  25797. }
  25798. else
  25799. {
  25800. HUnlock (resHandle);
  25801. }
  25802. break;
  25803. }
  25804. }
  25805. if (! ok)
  25806. CloseResFile (resFileId);
  25807. }
  25808. }
  25809. }
  25810. #endif
  25811. return ok;
  25812. }
  25813. void close()
  25814. {
  25815. #if JUCE_PPC
  25816. if (fragId != 0)
  25817. {
  25818. if (moduleMain != 0)
  25819. disposeMachOFromCFM ((void*) moduleMain);
  25820. CloseConnection (&fragId);
  25821. HUnlock (resHandle);
  25822. if (resFileId != 0)
  25823. CloseResFile (resFileId);
  25824. }
  25825. else
  25826. #endif
  25827. if (bundleRef != 0)
  25828. {
  25829. CFBundleCloseBundleResourceMap (bundleRef, resFileId);
  25830. if (CFGetRetainCount (bundleRef) == 1)
  25831. CFBundleUnloadExecutable (bundleRef);
  25832. if (CFGetRetainCount (bundleRef) > 0)
  25833. CFRelease (bundleRef);
  25834. }
  25835. }
  25836. void closeEffect (AEffect* eff)
  25837. {
  25838. #if JUCE_PPC
  25839. if (fragId != 0)
  25840. {
  25841. VoidArray thingsToDelete;
  25842. thingsToDelete.add ((void*) eff->dispatcher);
  25843. thingsToDelete.add ((void*) eff->process);
  25844. thingsToDelete.add ((void*) eff->setParameter);
  25845. thingsToDelete.add ((void*) eff->getParameter);
  25846. thingsToDelete.add ((void*) eff->processReplacing);
  25847. eff->dispatcher (eff, effClose, 0, 0, 0, 0);
  25848. for (int i = thingsToDelete.size(); --i >= 0;)
  25849. disposeMachOFromCFM (thingsToDelete[i]);
  25850. }
  25851. else
  25852. #endif
  25853. {
  25854. eff->dispatcher (eff, effClose, 0, 0, 0, 0);
  25855. }
  25856. }
  25857. #if JUCE_PPC
  25858. static void* newMachOFromCFM (void* cfmfp)
  25859. {
  25860. if (cfmfp == 0)
  25861. return 0;
  25862. UInt32* const mfp = (UInt32*) juce_malloc (sizeof (UInt32) * 6);
  25863. mfp[0] = 0x3d800000 | ((UInt32) cfmfp >> 16);
  25864. mfp[1] = 0x618c0000 | ((UInt32) cfmfp & 0xffff);
  25865. mfp[2] = 0x800c0000;
  25866. mfp[3] = 0x804c0004;
  25867. mfp[4] = 0x7c0903a6;
  25868. mfp[5] = 0x4e800420;
  25869. MakeDataExecutable (mfp, sizeof (UInt32) * 6);
  25870. return mfp;
  25871. }
  25872. static void disposeMachOFromCFM (void* ptr)
  25873. {
  25874. juce_free (ptr);
  25875. }
  25876. void coerceAEffectFunctionCalls (AEffect* eff)
  25877. {
  25878. if (fragId != 0)
  25879. {
  25880. eff->dispatcher = (AEffectDispatcherProc) newMachOFromCFM ((void*) eff->dispatcher);
  25881. eff->process = (AEffectProcessProc) newMachOFromCFM ((void*) eff->process);
  25882. eff->setParameter = (AEffectSetParameterProc) newMachOFromCFM ((void*) eff->setParameter);
  25883. eff->getParameter = (AEffectGetParameterProc) newMachOFromCFM ((void*) eff->getParameter);
  25884. eff->processReplacing = (AEffectProcessProc) newMachOFromCFM ((void*) eff->processReplacing);
  25885. }
  25886. }
  25887. #endif
  25888. #endif
  25889. };
  25890. class VSTPluginInstance : public AudioPluginInstance,
  25891. private Timer,
  25892. private AsyncUpdater
  25893. {
  25894. public:
  25895. ~VSTPluginInstance();
  25896. // AudioPluginInstance methods:
  25897. void fillInPluginDescription (PluginDescription& desc) const
  25898. {
  25899. desc.name = name;
  25900. desc.fileOrIdentifier = module->file.getFullPathName();
  25901. desc.uid = getUID();
  25902. desc.lastFileModTime = module->file.getLastModificationTime();
  25903. desc.pluginFormatName = "VST";
  25904. desc.category = getCategory();
  25905. {
  25906. char buffer [kVstMaxVendorStrLen + 8];
  25907. zerostruct (buffer);
  25908. dispatch (effGetVendorString, 0, 0, buffer, 0);
  25909. desc.manufacturerName = buffer;
  25910. }
  25911. desc.version = getVersion();
  25912. desc.numInputChannels = getNumInputChannels();
  25913. desc.numOutputChannels = getNumOutputChannels();
  25914. desc.isInstrument = (effect != 0 && (effect->flags & effFlagsIsSynth) != 0);
  25915. }
  25916. const String getName() const { return name; }
  25917. int getUID() const throw();
  25918. bool acceptsMidi() const { return wantsMidiMessages; }
  25919. bool producesMidi() const { return dispatch (effCanDo, 0, 0, (void*) "sendVstMidiEvent", 0) > 0; }
  25920. // AudioProcessor methods:
  25921. void prepareToPlay (double sampleRate, int estimatedSamplesPerBlock);
  25922. void releaseResources();
  25923. void processBlock (AudioSampleBuffer& buffer,
  25924. MidiBuffer& midiMessages);
  25925. AudioProcessorEditor* createEditor();
  25926. const String getInputChannelName (const int index) const;
  25927. bool isInputChannelStereoPair (int index) const;
  25928. const String getOutputChannelName (const int index) const;
  25929. bool isOutputChannelStereoPair (int index) const;
  25930. int getNumParameters() { return effect != 0 ? effect->numParams : 0; }
  25931. float getParameter (int index);
  25932. void setParameter (int index, float newValue);
  25933. const String getParameterName (int index);
  25934. const String getParameterText (int index);
  25935. bool isParameterAutomatable (int index) const;
  25936. int getNumPrograms() { return effect != 0 ? effect->numPrograms : 0; }
  25937. int getCurrentProgram() { return dispatch (effGetProgram, 0, 0, 0, 0); }
  25938. void setCurrentProgram (int index);
  25939. const String getProgramName (int index);
  25940. void changeProgramName (int index, const String& newName);
  25941. void getStateInformation (MemoryBlock& destData);
  25942. void getCurrentProgramStateInformation (MemoryBlock& destData);
  25943. void setStateInformation (const void* data, int sizeInBytes);
  25944. void setCurrentProgramStateInformation (const void* data, int sizeInBytes);
  25945. void timerCallback();
  25946. void handleAsyncUpdate();
  25947. VstIntPtr handleCallback (VstInt32 opcode, VstInt32 index, VstInt32 value, void *ptr, float opt);
  25948. juce_UseDebuggingNewOperator
  25949. private:
  25950. friend class VSTPluginWindow;
  25951. friend class VSTPluginFormat;
  25952. AEffect* effect;
  25953. String name;
  25954. CriticalSection lock;
  25955. bool wantsMidiMessages, initialised, isPowerOn;
  25956. mutable StringArray programNames;
  25957. AudioSampleBuffer tempBuffer;
  25958. CriticalSection midiInLock;
  25959. MidiBuffer incomingMidi;
  25960. VSTMidiEventList midiEventsToSend;
  25961. VstTimeInfo vstHostTime;
  25962. HeapBlock <float*> channels;
  25963. ReferenceCountedObjectPtr <ModuleHandle> module;
  25964. int dispatch (const int opcode, const int index, const int value, void* const ptr, float opt) const;
  25965. bool restoreProgramSettings (const fxProgram* const prog);
  25966. const String getCurrentProgramName();
  25967. void setParamsInProgramBlock (fxProgram* const prog) throw();
  25968. void updateStoredProgramNames();
  25969. void initialise();
  25970. void handleMidiFromPlugin (const VstEvents* const events);
  25971. void createTempParameterStore (MemoryBlock& dest);
  25972. void restoreFromTempParameterStore (const MemoryBlock& mb);
  25973. const String getParameterLabel (int index) const;
  25974. bool usesChunks() const throw() { return effect != 0 && (effect->flags & effFlagsProgramChunks) != 0; }
  25975. void getChunkData (MemoryBlock& mb, bool isPreset, int maxSizeMB) const;
  25976. void setChunkData (const char* data, int size, bool isPreset);
  25977. bool loadFromFXBFile (const void* data, int numBytes);
  25978. bool saveToFXBFile (MemoryBlock& dest, bool isFXB, int maxSizeMB);
  25979. int getVersionNumber() const throw() { return effect != 0 ? effect->version : 0; }
  25980. const String getVersion() const throw();
  25981. const String getCategory() const throw();
  25982. bool hasEditor() const throw() { return effect != 0 && (effect->flags & effFlagsHasEditor) != 0; }
  25983. void setPower (const bool on);
  25984. VSTPluginInstance (const ReferenceCountedObjectPtr <ModuleHandle>& module);
  25985. };
  25986. VSTPluginInstance::VSTPluginInstance (const ReferenceCountedObjectPtr <ModuleHandle>& module_)
  25987. : effect (0),
  25988. wantsMidiMessages (false),
  25989. initialised (false),
  25990. isPowerOn (false),
  25991. tempBuffer (1, 1),
  25992. module (module_)
  25993. {
  25994. try
  25995. {
  25996. _fpreset();
  25997. ++insideVSTCallback;
  25998. name = module->pluginName;
  25999. log (T("Creating VST instance: ") + name);
  26000. #if JUCE_MAC
  26001. if (module->resFileId != 0)
  26002. UseResFile (module->resFileId);
  26003. #if JUCE_PPC
  26004. if (module->fragId != 0)
  26005. {
  26006. static void* audioMasterCoerced = 0;
  26007. if (audioMasterCoerced == 0)
  26008. audioMasterCoerced = NewCFMFromMachO ((void*) &audioMaster);
  26009. effect = module->moduleMain ((audioMasterCallback) audioMasterCoerced);
  26010. }
  26011. else
  26012. #endif
  26013. #endif
  26014. {
  26015. effect = module->moduleMain (&audioMaster);
  26016. }
  26017. --insideVSTCallback;
  26018. if (effect != 0 && effect->magic == kEffectMagic)
  26019. {
  26020. #if JUCE_PPC
  26021. module->coerceAEffectFunctionCalls (effect);
  26022. #endif
  26023. jassert (effect->resvd2 == 0);
  26024. jassert (effect->object != 0);
  26025. _fpreset(); // some dodgy plugs fuck around with this
  26026. }
  26027. else
  26028. {
  26029. effect = 0;
  26030. }
  26031. }
  26032. catch (...)
  26033. {
  26034. --insideVSTCallback;
  26035. }
  26036. }
  26037. VSTPluginInstance::~VSTPluginInstance()
  26038. {
  26039. {
  26040. const ScopedLock sl (lock);
  26041. jassert (insideVSTCallback == 0);
  26042. if (effect != 0 && effect->magic == kEffectMagic)
  26043. {
  26044. try
  26045. {
  26046. #if JUCE_MAC
  26047. if (module->resFileId != 0)
  26048. UseResFile (module->resFileId);
  26049. #endif
  26050. // Must delete any editors before deleting the plugin instance!
  26051. jassert (getActiveEditor() == 0);
  26052. _fpreset(); // some dodgy plugs fuck around with this
  26053. module->closeEffect (effect);
  26054. }
  26055. catch (...)
  26056. {}
  26057. }
  26058. module = 0;
  26059. effect = 0;
  26060. }
  26061. }
  26062. void VSTPluginInstance::initialise()
  26063. {
  26064. if (initialised || effect == 0)
  26065. return;
  26066. log (T("Initialising VST: ") + module->pluginName);
  26067. initialised = true;
  26068. dispatch (effIdentify, 0, 0, 0, 0);
  26069. // this code would ask the plugin for its name, but so few plugins
  26070. // actually bother implementing this correctly, that it's better to
  26071. // just ignore it and use the file name instead.
  26072. if (getSampleRate() > 0)
  26073. dispatch (effSetSampleRate, 0, 0, 0, (float) getSampleRate());
  26074. if (getBlockSize() > 0)
  26075. dispatch (effSetBlockSize, 0, jmax (32, getBlockSize()), 0, 0);
  26076. dispatch (effOpen, 0, 0, 0, 0);
  26077. setPlayConfigDetails (effect->numInputs, effect->numOutputs,
  26078. getSampleRate(), getBlockSize());
  26079. if (getNumPrograms() > 1)
  26080. setCurrentProgram (0);
  26081. else
  26082. dispatch (effSetProgram, 0, 0, 0, 0);
  26083. int i;
  26084. for (i = effect->numInputs; --i >= 0;)
  26085. dispatch (effConnectInput, i, 1, 0, 0);
  26086. for (i = effect->numOutputs; --i >= 0;)
  26087. dispatch (effConnectOutput, i, 1, 0, 0);
  26088. updateStoredProgramNames();
  26089. wantsMidiMessages = dispatch (effCanDo, 0, 0, (void*) "receiveVstMidiEvent", 0) > 0;
  26090. setLatencySamples (effect->initialDelay);
  26091. }
  26092. void VSTPluginInstance::prepareToPlay (double sampleRate_,
  26093. int samplesPerBlockExpected)
  26094. {
  26095. setPlayConfigDetails (effect->numInputs, effect->numOutputs,
  26096. sampleRate_, samplesPerBlockExpected);
  26097. setLatencySamples (effect->initialDelay);
  26098. channels.calloc (jmax (16, getNumOutputChannels(), getNumInputChannels()) + 2);
  26099. vstHostTime.tempo = 120.0;
  26100. vstHostTime.timeSigNumerator = 4;
  26101. vstHostTime.timeSigDenominator = 4;
  26102. vstHostTime.sampleRate = sampleRate_;
  26103. vstHostTime.samplePos = 0;
  26104. vstHostTime.flags = kVstNanosValid; /*| kVstTransportPlaying | kVstTempoValid | kVstTimeSigValid*/;
  26105. initialise();
  26106. if (initialised)
  26107. {
  26108. wantsMidiMessages = wantsMidiMessages
  26109. || (dispatch (effCanDo, 0, 0, (void*) "receiveVstMidiEvent", 0) > 0);
  26110. if (wantsMidiMessages)
  26111. midiEventsToSend.ensureSize (256);
  26112. else
  26113. midiEventsToSend.freeEvents();
  26114. incomingMidi.clear();
  26115. dispatch (effSetSampleRate, 0, 0, 0, (float) sampleRate_);
  26116. dispatch (effSetBlockSize, 0, jmax (16, samplesPerBlockExpected), 0, 0);
  26117. tempBuffer.setSize (jmax (1, effect->numOutputs), samplesPerBlockExpected);
  26118. if (! isPowerOn)
  26119. setPower (true);
  26120. // dodgy hack to force some plugins to initialise the sample rate..
  26121. if ((! hasEditor()) && getNumParameters() > 0)
  26122. {
  26123. const float old = getParameter (0);
  26124. setParameter (0, (old < 0.5f) ? 1.0f : 0.0f);
  26125. setParameter (0, old);
  26126. }
  26127. dispatch (effStartProcess, 0, 0, 0, 0);
  26128. }
  26129. }
  26130. void VSTPluginInstance::releaseResources()
  26131. {
  26132. if (initialised)
  26133. {
  26134. dispatch (effStopProcess, 0, 0, 0, 0);
  26135. setPower (false);
  26136. }
  26137. tempBuffer.setSize (1, 1);
  26138. incomingMidi.clear();
  26139. midiEventsToSend.freeEvents();
  26140. channels.free();
  26141. }
  26142. void VSTPluginInstance::processBlock (AudioSampleBuffer& buffer,
  26143. MidiBuffer& midiMessages)
  26144. {
  26145. const int numSamples = buffer.getNumSamples();
  26146. if (initialised)
  26147. {
  26148. AudioPlayHead* playHead = getPlayHead();
  26149. if (playHead != 0)
  26150. {
  26151. AudioPlayHead::CurrentPositionInfo position;
  26152. playHead->getCurrentPosition (position);
  26153. vstHostTime.tempo = position.bpm;
  26154. vstHostTime.timeSigNumerator = position.timeSigNumerator;
  26155. vstHostTime.timeSigDenominator = position.timeSigDenominator;
  26156. vstHostTime.ppqPos = position.ppqPosition;
  26157. vstHostTime.barStartPos = position.ppqPositionOfLastBarStart;
  26158. vstHostTime.flags |= kVstTempoValid | kVstTimeSigValid | kVstPpqPosValid | kVstBarsValid;
  26159. if (position.isPlaying)
  26160. vstHostTime.flags |= kVstTransportPlaying;
  26161. else
  26162. vstHostTime.flags &= ~kVstTransportPlaying;
  26163. }
  26164. #if JUCE_WIN32
  26165. vstHostTime.nanoSeconds = timeGetTime() * 1000000.0;
  26166. #elif JUCE_LINUX
  26167. timeval micro;
  26168. gettimeofday (&micro, 0);
  26169. vstHostTime.nanoSeconds = micro.tv_usec * 1000.0;
  26170. #elif JUCE_MAC
  26171. UnsignedWide micro;
  26172. Microseconds (&micro);
  26173. vstHostTime.nanoSeconds = micro.lo * 1000.0;
  26174. #endif
  26175. if (wantsMidiMessages)
  26176. {
  26177. midiEventsToSend.clear();
  26178. midiEventsToSend.ensureSize (1);
  26179. MidiBuffer::Iterator iter (midiMessages);
  26180. const uint8* midiData;
  26181. int numBytesOfMidiData, samplePosition;
  26182. while (iter.getNextEvent (midiData, numBytesOfMidiData, samplePosition))
  26183. {
  26184. midiEventsToSend.addEvent (midiData, numBytesOfMidiData,
  26185. jlimit (0, numSamples - 1, samplePosition));
  26186. }
  26187. try
  26188. {
  26189. effect->dispatcher (effect, effProcessEvents, 0, 0, midiEventsToSend.events, 0);
  26190. }
  26191. catch (...)
  26192. {}
  26193. }
  26194. int i;
  26195. const int maxChans = jmax (effect->numInputs, effect->numOutputs);
  26196. for (i = 0; i < maxChans; ++i)
  26197. channels[i] = buffer.getSampleData (i);
  26198. channels [maxChans] = 0;
  26199. _clearfp();
  26200. if ((effect->flags & effFlagsCanReplacing) != 0)
  26201. {
  26202. try
  26203. {
  26204. effect->processReplacing (effect, channels, channels, numSamples);
  26205. }
  26206. catch (...)
  26207. {}
  26208. }
  26209. else
  26210. {
  26211. tempBuffer.setSize (effect->numOutputs, numSamples);
  26212. tempBuffer.clear();
  26213. float* outs [64];
  26214. for (i = effect->numOutputs; --i >= 0;)
  26215. outs[i] = tempBuffer.getSampleData (i);
  26216. outs [effect->numOutputs] = 0;
  26217. try
  26218. {
  26219. effect->process (effect, channels, outs, numSamples);
  26220. }
  26221. catch (...)
  26222. {}
  26223. for (i = effect->numOutputs; --i >= 0;)
  26224. buffer.copyFrom (i, 0, outs[i], numSamples);
  26225. }
  26226. }
  26227. else
  26228. {
  26229. // Not initialised, so just bypass..
  26230. for (int i = getNumInputChannels(); i < getNumOutputChannels(); ++i)
  26231. buffer.clear (i, 0, buffer.getNumSamples());
  26232. }
  26233. {
  26234. // copy any incoming midi..
  26235. const ScopedLock sl (midiInLock);
  26236. midiMessages = incomingMidi;
  26237. incomingMidi.clear();
  26238. }
  26239. }
  26240. void VSTPluginInstance::handleMidiFromPlugin (const VstEvents* const events)
  26241. {
  26242. if (events != 0)
  26243. {
  26244. const ScopedLock sl (midiInLock);
  26245. VSTMidiEventList::addEventsToMidiBuffer (events, incomingMidi);
  26246. }
  26247. }
  26248. static Array <VSTPluginWindow*> activeVSTWindows;
  26249. class VSTPluginWindow : public AudioProcessorEditor,
  26250. #if ! JUCE_MAC
  26251. public ComponentMovementWatcher,
  26252. #endif
  26253. public Timer
  26254. {
  26255. public:
  26256. VSTPluginWindow (VSTPluginInstance& plugin_)
  26257. : AudioProcessorEditor (&plugin_),
  26258. #if ! JUCE_MAC
  26259. ComponentMovementWatcher (this),
  26260. #endif
  26261. plugin (plugin_),
  26262. isOpen (false),
  26263. wasShowing (false),
  26264. pluginRefusesToResize (false),
  26265. pluginWantsKeys (false),
  26266. alreadyInside (false),
  26267. recursiveResize (false)
  26268. {
  26269. #if JUCE_WIN32
  26270. sizeCheckCount = 0;
  26271. pluginHWND = 0;
  26272. #elif JUCE_LINUX
  26273. pluginWindow = None;
  26274. pluginProc = None;
  26275. #else
  26276. addAndMakeVisible (innerWrapper = new InnerWrapperComponent (this));
  26277. #endif
  26278. activeVSTWindows.add (this);
  26279. setSize (1, 1);
  26280. setOpaque (true);
  26281. setVisible (true);
  26282. }
  26283. ~VSTPluginWindow()
  26284. {
  26285. #if JUCE_MAC
  26286. innerWrapper = 0;
  26287. #else
  26288. closePluginWindow();
  26289. #endif
  26290. activeVSTWindows.removeValue (this);
  26291. plugin.editorBeingDeleted (this);
  26292. }
  26293. #if ! JUCE_MAC
  26294. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  26295. {
  26296. if (recursiveResize)
  26297. return;
  26298. Component* const topComp = getTopLevelComponent();
  26299. if (topComp->getPeer() != 0)
  26300. {
  26301. const Point<int> pos (relativePositionToOtherComponent (topComp, Point<int>()));
  26302. recursiveResize = true;
  26303. #if JUCE_WIN32
  26304. if (pluginHWND != 0)
  26305. MoveWindow (pluginHWND, pos.getX(), pos.getY(), getWidth(), getHeight(), TRUE);
  26306. #elif JUCE_LINUX
  26307. if (pluginWindow != 0)
  26308. {
  26309. XResizeWindow (display, pluginWindow, getWidth(), getHeight());
  26310. XMoveWindow (display, pluginWindow, pos.getX(), pos.getY());
  26311. XMapRaised (display, pluginWindow);
  26312. }
  26313. #endif
  26314. recursiveResize = false;
  26315. }
  26316. }
  26317. void componentVisibilityChanged (Component&)
  26318. {
  26319. const bool isShowingNow = isShowing();
  26320. if (wasShowing != isShowingNow)
  26321. {
  26322. wasShowing = isShowingNow;
  26323. if (isShowingNow)
  26324. openPluginWindow();
  26325. else
  26326. closePluginWindow();
  26327. }
  26328. componentMovedOrResized (true, true);
  26329. }
  26330. void componentPeerChanged()
  26331. {
  26332. closePluginWindow();
  26333. openPluginWindow();
  26334. }
  26335. #endif
  26336. bool keyStateChanged (const bool)
  26337. {
  26338. return pluginWantsKeys;
  26339. }
  26340. bool keyPressed (const KeyPress&)
  26341. {
  26342. return pluginWantsKeys;
  26343. }
  26344. #if JUCE_MAC
  26345. void paint (Graphics& g)
  26346. {
  26347. g.fillAll (Colours::black);
  26348. }
  26349. #else
  26350. void paint (Graphics& g)
  26351. {
  26352. if (isOpen)
  26353. {
  26354. ComponentPeer* const peer = getPeer();
  26355. if (peer != 0)
  26356. {
  26357. const Point<int> pos (getScreenPosition() - peer->getScreenPosition());
  26358. peer->addMaskedRegion (pos.getX(), pos.getY(), getWidth(), getHeight());
  26359. #if JUCE_LINUX
  26360. if (pluginWindow != 0)
  26361. {
  26362. const Rectangle<int> clip (g.getClipBounds());
  26363. XEvent ev;
  26364. zerostruct (ev);
  26365. ev.xexpose.type = Expose;
  26366. ev.xexpose.display = display;
  26367. ev.xexpose.window = pluginWindow;
  26368. ev.xexpose.x = clip.getX();
  26369. ev.xexpose.y = clip.getY();
  26370. ev.xexpose.width = clip.getWidth();
  26371. ev.xexpose.height = clip.getHeight();
  26372. sendEventToChild (&ev);
  26373. }
  26374. #endif
  26375. }
  26376. }
  26377. else
  26378. {
  26379. g.fillAll (Colours::black);
  26380. }
  26381. }
  26382. #endif
  26383. void timerCallback()
  26384. {
  26385. #if JUCE_WIN32
  26386. if (--sizeCheckCount <= 0)
  26387. {
  26388. sizeCheckCount = 10;
  26389. checkPluginWindowSize();
  26390. }
  26391. #endif
  26392. try
  26393. {
  26394. static bool reentrant = false;
  26395. if (! reentrant)
  26396. {
  26397. reentrant = true;
  26398. plugin.dispatch (effEditIdle, 0, 0, 0, 0);
  26399. reentrant = false;
  26400. }
  26401. }
  26402. catch (...)
  26403. {}
  26404. }
  26405. void mouseDown (const MouseEvent& e)
  26406. {
  26407. #if JUCE_LINUX
  26408. if (pluginWindow == 0)
  26409. return;
  26410. toFront (true);
  26411. XEvent ev;
  26412. zerostruct (ev);
  26413. ev.xbutton.display = display;
  26414. ev.xbutton.type = ButtonPress;
  26415. ev.xbutton.window = pluginWindow;
  26416. ev.xbutton.root = RootWindow (display, DefaultScreen (display));
  26417. ev.xbutton.time = CurrentTime;
  26418. ev.xbutton.x = e.x;
  26419. ev.xbutton.y = e.y;
  26420. ev.xbutton.x_root = e.getScreenX();
  26421. ev.xbutton.y_root = e.getScreenY();
  26422. translateJuceToXButtonModifiers (e, ev);
  26423. sendEventToChild (&ev);
  26424. #elif JUCE_WIN32
  26425. (void) e;
  26426. toFront (true);
  26427. #endif
  26428. }
  26429. void broughtToFront()
  26430. {
  26431. activeVSTWindows.removeValue (this);
  26432. activeVSTWindows.add (this);
  26433. #if JUCE_MAC
  26434. dispatch (effEditTop, 0, 0, 0, 0);
  26435. #endif
  26436. }
  26437. juce_UseDebuggingNewOperator
  26438. private:
  26439. VSTPluginInstance& plugin;
  26440. bool isOpen, wasShowing, recursiveResize;
  26441. bool pluginWantsKeys, pluginRefusesToResize, alreadyInside;
  26442. #if JUCE_WIN32
  26443. HWND pluginHWND;
  26444. void* originalWndProc;
  26445. int sizeCheckCount;
  26446. #elif JUCE_LINUX
  26447. Window pluginWindow;
  26448. EventProcPtr pluginProc;
  26449. #endif
  26450. #if JUCE_MAC
  26451. void openPluginWindow (WindowRef parentWindow)
  26452. {
  26453. if (isOpen || parentWindow == 0)
  26454. return;
  26455. isOpen = true;
  26456. ERect* rect = 0;
  26457. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26458. dispatch (effEditOpen, 0, 0, parentWindow, 0);
  26459. // do this before and after like in the steinberg example
  26460. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26461. dispatch (effGetProgram, 0, 0, 0, 0); // also in steinberg code
  26462. // Install keyboard hooks
  26463. pluginWantsKeys = (dispatch (effKeysRequired, 0, 0, 0, 0) == 0);
  26464. // double-check it's not too tiny
  26465. int w = 250, h = 150;
  26466. if (rect != 0)
  26467. {
  26468. w = rect->right - rect->left;
  26469. h = rect->bottom - rect->top;
  26470. if (w == 0 || h == 0)
  26471. {
  26472. w = 250;
  26473. h = 150;
  26474. }
  26475. }
  26476. w = jmax (w, 32);
  26477. h = jmax (h, 32);
  26478. setSize (w, h);
  26479. startTimer (18 + JUCE_NAMESPACE::Random::getSystemRandom().nextInt (5));
  26480. repaint();
  26481. }
  26482. #else
  26483. void openPluginWindow()
  26484. {
  26485. if (isOpen || getWindowHandle() == 0)
  26486. return;
  26487. log (T("Opening VST UI: ") + plugin.name);
  26488. isOpen = true;
  26489. ERect* rect = 0;
  26490. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26491. dispatch (effEditOpen, 0, 0, getWindowHandle(), 0);
  26492. // do this before and after like in the steinberg example
  26493. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26494. dispatch (effGetProgram, 0, 0, 0, 0); // also in steinberg code
  26495. // Install keyboard hooks
  26496. pluginWantsKeys = (dispatch (effKeysRequired, 0, 0, 0, 0) == 0);
  26497. #if JUCE_WIN32
  26498. originalWndProc = 0;
  26499. pluginHWND = GetWindow ((HWND) getWindowHandle(), GW_CHILD);
  26500. if (pluginHWND == 0)
  26501. {
  26502. isOpen = false;
  26503. setSize (300, 150);
  26504. return;
  26505. }
  26506. #pragma warning (push)
  26507. #pragma warning (disable: 4244)
  26508. originalWndProc = (void*) GetWindowLongPtr (pluginHWND, GWL_WNDPROC);
  26509. if (! pluginWantsKeys)
  26510. SetWindowLongPtr (pluginHWND, GWL_WNDPROC, (LONG_PTR) vstHookWndProc);
  26511. #pragma warning (pop)
  26512. int w, h;
  26513. RECT r;
  26514. GetWindowRect (pluginHWND, &r);
  26515. w = r.right - r.left;
  26516. h = r.bottom - r.top;
  26517. if (rect != 0)
  26518. {
  26519. const int rw = rect->right - rect->left;
  26520. const int rh = rect->bottom - rect->top;
  26521. if ((rw > 50 && rh > 50 && rw < 2000 && rh < 2000 && rw != w && rh != h)
  26522. || ((w == 0 && rw > 0) || (h == 0 && rh > 0)))
  26523. {
  26524. // very dodgy logic to decide which size is right.
  26525. if (abs (rw - w) > 350 || abs (rh - h) > 350)
  26526. {
  26527. SetWindowPos (pluginHWND, 0,
  26528. 0, 0, rw, rh,
  26529. SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
  26530. GetWindowRect (pluginHWND, &r);
  26531. w = r.right - r.left;
  26532. h = r.bottom - r.top;
  26533. pluginRefusesToResize = (w != rw) || (h != rh);
  26534. w = rw;
  26535. h = rh;
  26536. }
  26537. }
  26538. }
  26539. #elif JUCE_LINUX
  26540. pluginWindow = getChildWindow ((Window) getWindowHandle());
  26541. if (pluginWindow != 0)
  26542. pluginProc = (EventProcPtr) getPropertyFromXWindow (pluginWindow,
  26543. XInternAtom (display, "_XEventProc", False));
  26544. int w = 250, h = 150;
  26545. if (rect != 0)
  26546. {
  26547. w = rect->right - rect->left;
  26548. h = rect->bottom - rect->top;
  26549. if (w == 0 || h == 0)
  26550. {
  26551. w = 250;
  26552. h = 150;
  26553. }
  26554. }
  26555. if (pluginWindow != 0)
  26556. XMapRaised (display, pluginWindow);
  26557. #endif
  26558. // double-check it's not too tiny
  26559. w = jmax (w, 32);
  26560. h = jmax (h, 32);
  26561. setSize (w, h);
  26562. #if JUCE_WIN32
  26563. checkPluginWindowSize();
  26564. #endif
  26565. startTimer (18 + JUCE_NAMESPACE::Random::getSystemRandom().nextInt (5));
  26566. repaint();
  26567. }
  26568. #endif
  26569. #if ! JUCE_MAC
  26570. void closePluginWindow()
  26571. {
  26572. if (isOpen)
  26573. {
  26574. log (T("Closing VST UI: ") + plugin.getName());
  26575. isOpen = false;
  26576. dispatch (effEditClose, 0, 0, 0, 0);
  26577. #if JUCE_WIN32
  26578. #pragma warning (push)
  26579. #pragma warning (disable: 4244)
  26580. if (pluginHWND != 0 && IsWindow (pluginHWND))
  26581. SetWindowLongPtr (pluginHWND, GWL_WNDPROC, (LONG_PTR) originalWndProc);
  26582. #pragma warning (pop)
  26583. stopTimer();
  26584. if (pluginHWND != 0 && IsWindow (pluginHWND))
  26585. DestroyWindow (pluginHWND);
  26586. pluginHWND = 0;
  26587. #elif JUCE_LINUX
  26588. stopTimer();
  26589. pluginWindow = 0;
  26590. pluginProc = 0;
  26591. #endif
  26592. }
  26593. }
  26594. #endif
  26595. int dispatch (const int opcode, const int index, const int value, void* const ptr, float opt)
  26596. {
  26597. return plugin.dispatch (opcode, index, value, ptr, opt);
  26598. }
  26599. #if JUCE_WIN32
  26600. void checkPluginWindowSize() throw()
  26601. {
  26602. RECT r;
  26603. GetWindowRect (pluginHWND, &r);
  26604. const int w = r.right - r.left;
  26605. const int h = r.bottom - r.top;
  26606. if (isShowing() && w > 0 && h > 0
  26607. && (w != getWidth() || h != getHeight())
  26608. && ! pluginRefusesToResize)
  26609. {
  26610. setSize (w, h);
  26611. sizeCheckCount = 0;
  26612. }
  26613. }
  26614. // hooks to get keyboard events from VST windows..
  26615. static LRESULT CALLBACK vstHookWndProc (HWND hW, UINT message, WPARAM wParam, LPARAM lParam)
  26616. {
  26617. for (int i = activeVSTWindows.size(); --i >= 0;)
  26618. {
  26619. const VSTPluginWindow* const w = (const VSTPluginWindow*) activeVSTWindows.getUnchecked (i);
  26620. if (w->pluginHWND == hW)
  26621. {
  26622. if (message == WM_CHAR
  26623. || message == WM_KEYDOWN
  26624. || message == WM_SYSKEYDOWN
  26625. || message == WM_KEYUP
  26626. || message == WM_SYSKEYUP
  26627. || message == WM_APPCOMMAND)
  26628. {
  26629. SendMessage ((HWND) w->getTopLevelComponent()->getWindowHandle(),
  26630. message, wParam, lParam);
  26631. }
  26632. return CallWindowProc ((WNDPROC) (w->originalWndProc),
  26633. (HWND) w->pluginHWND,
  26634. message,
  26635. wParam,
  26636. lParam);
  26637. }
  26638. }
  26639. return DefWindowProc (hW, message, wParam, lParam);
  26640. }
  26641. #endif
  26642. #if JUCE_LINUX
  26643. // overload mouse/keyboard events to forward them to the plugin's inner window..
  26644. void sendEventToChild (XEvent* event)
  26645. {
  26646. if (pluginProc != 0)
  26647. {
  26648. // if the plugin publishes an event procedure, pass the event directly..
  26649. pluginProc (event);
  26650. }
  26651. else if (pluginWindow != 0)
  26652. {
  26653. // if the plugin has a window, then send the event to the window so that
  26654. // its message thread will pick it up..
  26655. XSendEvent (display, pluginWindow, False, 0L, event);
  26656. XFlush (display);
  26657. }
  26658. }
  26659. void mouseEnter (const MouseEvent& e)
  26660. {
  26661. if (pluginWindow != 0)
  26662. {
  26663. XEvent ev;
  26664. zerostruct (ev);
  26665. ev.xcrossing.display = display;
  26666. ev.xcrossing.type = EnterNotify;
  26667. ev.xcrossing.window = pluginWindow;
  26668. ev.xcrossing.root = RootWindow (display, DefaultScreen (display));
  26669. ev.xcrossing.time = CurrentTime;
  26670. ev.xcrossing.x = e.x;
  26671. ev.xcrossing.y = e.y;
  26672. ev.xcrossing.x_root = e.getScreenX();
  26673. ev.xcrossing.y_root = e.getScreenY();
  26674. ev.xcrossing.mode = NotifyNormal; // NotifyGrab, NotifyUngrab
  26675. ev.xcrossing.detail = NotifyAncestor; // NotifyVirtual, NotifyInferior, NotifyNonlinear,NotifyNonlinearVirtual
  26676. translateJuceToXCrossingModifiers (e, ev);
  26677. sendEventToChild (&ev);
  26678. }
  26679. }
  26680. void mouseExit (const MouseEvent& e)
  26681. {
  26682. if (pluginWindow != 0)
  26683. {
  26684. XEvent ev;
  26685. zerostruct (ev);
  26686. ev.xcrossing.display = display;
  26687. ev.xcrossing.type = LeaveNotify;
  26688. ev.xcrossing.window = pluginWindow;
  26689. ev.xcrossing.root = RootWindow (display, DefaultScreen (display));
  26690. ev.xcrossing.time = CurrentTime;
  26691. ev.xcrossing.x = e.x;
  26692. ev.xcrossing.y = e.y;
  26693. ev.xcrossing.x_root = e.getScreenX();
  26694. ev.xcrossing.y_root = e.getScreenY();
  26695. ev.xcrossing.mode = NotifyNormal; // NotifyGrab, NotifyUngrab
  26696. ev.xcrossing.detail = NotifyAncestor; // NotifyVirtual, NotifyInferior, NotifyNonlinear,NotifyNonlinearVirtual
  26697. ev.xcrossing.focus = hasKeyboardFocus (true); // TODO - yes ?
  26698. translateJuceToXCrossingModifiers (e, ev);
  26699. sendEventToChild (&ev);
  26700. }
  26701. }
  26702. void mouseMove (const MouseEvent& e)
  26703. {
  26704. if (pluginWindow != 0)
  26705. {
  26706. XEvent ev;
  26707. zerostruct (ev);
  26708. ev.xmotion.display = display;
  26709. ev.xmotion.type = MotionNotify;
  26710. ev.xmotion.window = pluginWindow;
  26711. ev.xmotion.root = RootWindow (display, DefaultScreen (display));
  26712. ev.xmotion.time = CurrentTime;
  26713. ev.xmotion.is_hint = NotifyNormal;
  26714. ev.xmotion.x = e.x;
  26715. ev.xmotion.y = e.y;
  26716. ev.xmotion.x_root = e.getScreenX();
  26717. ev.xmotion.y_root = e.getScreenY();
  26718. sendEventToChild (&ev);
  26719. }
  26720. }
  26721. void mouseDrag (const MouseEvent& e)
  26722. {
  26723. if (pluginWindow != 0)
  26724. {
  26725. XEvent ev;
  26726. zerostruct (ev);
  26727. ev.xmotion.display = display;
  26728. ev.xmotion.type = MotionNotify;
  26729. ev.xmotion.window = pluginWindow;
  26730. ev.xmotion.root = RootWindow (display, DefaultScreen (display));
  26731. ev.xmotion.time = CurrentTime;
  26732. ev.xmotion.x = e.x ;
  26733. ev.xmotion.y = e.y;
  26734. ev.xmotion.x_root = e.getScreenX();
  26735. ev.xmotion.y_root = e.getScreenY();
  26736. ev.xmotion.is_hint = NotifyNormal;
  26737. translateJuceToXMotionModifiers (e, ev);
  26738. sendEventToChild (&ev);
  26739. }
  26740. }
  26741. void mouseUp (const MouseEvent& e)
  26742. {
  26743. if (pluginWindow != 0)
  26744. {
  26745. XEvent ev;
  26746. zerostruct (ev);
  26747. ev.xbutton.display = display;
  26748. ev.xbutton.type = ButtonRelease;
  26749. ev.xbutton.window = pluginWindow;
  26750. ev.xbutton.root = RootWindow (display, DefaultScreen (display));
  26751. ev.xbutton.time = CurrentTime;
  26752. ev.xbutton.x = e.x;
  26753. ev.xbutton.y = e.y;
  26754. ev.xbutton.x_root = e.getScreenX();
  26755. ev.xbutton.y_root = e.getScreenY();
  26756. translateJuceToXButtonModifiers (e, ev);
  26757. sendEventToChild (&ev);
  26758. }
  26759. }
  26760. void mouseWheelMove (const MouseEvent& e,
  26761. float incrementX,
  26762. float incrementY)
  26763. {
  26764. if (pluginWindow != 0)
  26765. {
  26766. XEvent ev;
  26767. zerostruct (ev);
  26768. ev.xbutton.display = display;
  26769. ev.xbutton.type = ButtonPress;
  26770. ev.xbutton.window = pluginWindow;
  26771. ev.xbutton.root = RootWindow (display, DefaultScreen (display));
  26772. ev.xbutton.time = CurrentTime;
  26773. ev.xbutton.x = e.x;
  26774. ev.xbutton.y = e.y;
  26775. ev.xbutton.x_root = e.getScreenX();
  26776. ev.xbutton.y_root = e.getScreenY();
  26777. translateJuceToXMouseWheelModifiers (e, incrementY, ev);
  26778. sendEventToChild (&ev);
  26779. // TODO - put a usleep here ?
  26780. ev.xbutton.type = ButtonRelease;
  26781. sendEventToChild (&ev);
  26782. }
  26783. }
  26784. #endif
  26785. #if JUCE_MAC
  26786. #if ! JUCE_SUPPORT_CARBON
  26787. #error "To build VSTs, you need to enable the JUCE_SUPPORT_CARBON flag in your config!"
  26788. #endif
  26789. class InnerWrapperComponent : public CarbonViewWrapperComponent
  26790. {
  26791. public:
  26792. InnerWrapperComponent (VSTPluginWindow* const owner_)
  26793. : owner (owner_),
  26794. alreadyInside (false)
  26795. {
  26796. }
  26797. ~InnerWrapperComponent()
  26798. {
  26799. deleteWindow();
  26800. }
  26801. HIViewRef attachView (WindowRef windowRef, HIViewRef rootView)
  26802. {
  26803. owner->openPluginWindow (windowRef);
  26804. return 0;
  26805. }
  26806. void removeView (HIViewRef)
  26807. {
  26808. owner->dispatch (effEditClose, 0, 0, 0, 0);
  26809. owner->dispatch (effEditSleep, 0, 0, 0, 0);
  26810. }
  26811. bool getEmbeddedViewSize (int& w, int& h)
  26812. {
  26813. ERect* rect = 0;
  26814. owner->dispatch (effEditGetRect, 0, 0, &rect, 0);
  26815. w = rect->right - rect->left;
  26816. h = rect->bottom - rect->top;
  26817. return true;
  26818. }
  26819. void mouseDown (int x, int y)
  26820. {
  26821. if (! alreadyInside)
  26822. {
  26823. alreadyInside = true;
  26824. getTopLevelComponent()->toFront (true);
  26825. owner->dispatch (effEditMouse, x, y, 0, 0);
  26826. alreadyInside = false;
  26827. }
  26828. else
  26829. {
  26830. PostEvent (::mouseDown, 0);
  26831. }
  26832. }
  26833. void paint()
  26834. {
  26835. ComponentPeer* const peer = getPeer();
  26836. if (peer != 0)
  26837. {
  26838. const Point<int> pos (getScreenPosition() - peer->getScreenPosition());
  26839. ERect r;
  26840. r.left = pos.getX();
  26841. r.right = r.left + getWidth();
  26842. r.top = pos.getY();
  26843. r.bottom = r.top + getHeight();
  26844. owner->dispatch (effEditDraw, 0, 0, &r, 0);
  26845. }
  26846. }
  26847. private:
  26848. VSTPluginWindow* const owner;
  26849. bool alreadyInside;
  26850. };
  26851. friend class InnerWrapperComponent;
  26852. ScopedPointer <InnerWrapperComponent> innerWrapper;
  26853. void resized()
  26854. {
  26855. innerWrapper->setSize (getWidth(), getHeight());
  26856. }
  26857. #endif
  26858. };
  26859. AudioProcessorEditor* VSTPluginInstance::createEditor()
  26860. {
  26861. if (hasEditor())
  26862. return new VSTPluginWindow (*this);
  26863. return 0;
  26864. }
  26865. void VSTPluginInstance::handleAsyncUpdate()
  26866. {
  26867. // indicates that something about the plugin has changed..
  26868. updateHostDisplay();
  26869. }
  26870. bool VSTPluginInstance::restoreProgramSettings (const fxProgram* const prog)
  26871. {
  26872. if (vst_swap (prog->chunkMagic) == 'CcnK' && vst_swap (prog->fxMagic) == 'FxCk')
  26873. {
  26874. changeProgramName (getCurrentProgram(), prog->prgName);
  26875. for (int i = 0; i < vst_swap (prog->numParams); ++i)
  26876. setParameter (i, vst_swapFloat (prog->params[i]));
  26877. return true;
  26878. }
  26879. return false;
  26880. }
  26881. bool VSTPluginInstance::loadFromFXBFile (const void* const data,
  26882. const int dataSize)
  26883. {
  26884. if (dataSize < 28)
  26885. return false;
  26886. const fxSet* const set = (const fxSet*) data;
  26887. if ((vst_swap (set->chunkMagic) != 'CcnK' && vst_swap (set->chunkMagic) != 'KncC')
  26888. || vst_swap (set->version) > fxbVersionNum)
  26889. return false;
  26890. if (vst_swap (set->fxMagic) == 'FxBk')
  26891. {
  26892. // bank of programs
  26893. if (vst_swap (set->numPrograms) >= 0)
  26894. {
  26895. const int oldProg = getCurrentProgram();
  26896. const int numParams = vst_swap (((const fxProgram*) (set->programs))->numParams);
  26897. const int progLen = sizeof (fxProgram) + (numParams - 1) * sizeof (float);
  26898. for (int i = 0; i < vst_swap (set->numPrograms); ++i)
  26899. {
  26900. if (i != oldProg)
  26901. {
  26902. const fxProgram* const prog = (const fxProgram*) (((const char*) (set->programs)) + i * progLen);
  26903. if (((const char*) prog) - ((const char*) set) >= dataSize)
  26904. return false;
  26905. if (vst_swap (set->numPrograms) > 0)
  26906. setCurrentProgram (i);
  26907. if (! restoreProgramSettings (prog))
  26908. return false;
  26909. }
  26910. }
  26911. if (vst_swap (set->numPrograms) > 0)
  26912. setCurrentProgram (oldProg);
  26913. const fxProgram* const prog = (const fxProgram*) (((const char*) (set->programs)) + oldProg * progLen);
  26914. if (((const char*) prog) - ((const char*) set) >= dataSize)
  26915. return false;
  26916. if (! restoreProgramSettings (prog))
  26917. return false;
  26918. }
  26919. }
  26920. else if (vst_swap (set->fxMagic) == 'FxCk')
  26921. {
  26922. // single program
  26923. const fxProgram* const prog = (const fxProgram*) data;
  26924. if (vst_swap (prog->chunkMagic) != 'CcnK')
  26925. return false;
  26926. changeProgramName (getCurrentProgram(), prog->prgName);
  26927. for (int i = 0; i < vst_swap (prog->numParams); ++i)
  26928. setParameter (i, vst_swapFloat (prog->params[i]));
  26929. }
  26930. else if (vst_swap (set->fxMagic) == 'FBCh' || vst_swap (set->fxMagic) == 'hCBF')
  26931. {
  26932. // non-preset chunk
  26933. const fxChunkSet* const cset = (const fxChunkSet*) data;
  26934. if (vst_swap (cset->chunkSize) + sizeof (fxChunkSet) - 8 > (unsigned int) dataSize)
  26935. return false;
  26936. setChunkData (cset->chunk, vst_swap (cset->chunkSize), false);
  26937. }
  26938. else if (vst_swap (set->fxMagic) == 'FPCh' || vst_swap (set->fxMagic) == 'hCPF')
  26939. {
  26940. // preset chunk
  26941. const fxProgramSet* const cset = (const fxProgramSet*) data;
  26942. if (vst_swap (cset->chunkSize) + sizeof (fxProgramSet) - 8 > (unsigned int) dataSize)
  26943. return false;
  26944. setChunkData (cset->chunk, vst_swap (cset->chunkSize), true);
  26945. changeProgramName (getCurrentProgram(), cset->name);
  26946. }
  26947. else
  26948. {
  26949. return false;
  26950. }
  26951. return true;
  26952. }
  26953. void VSTPluginInstance::setParamsInProgramBlock (fxProgram* const prog) throw()
  26954. {
  26955. const int numParams = getNumParameters();
  26956. prog->chunkMagic = vst_swap ('CcnK');
  26957. prog->byteSize = 0;
  26958. prog->fxMagic = vst_swap ('FxCk');
  26959. prog->version = vst_swap (fxbVersionNum);
  26960. prog->fxID = vst_swap (getUID());
  26961. prog->fxVersion = vst_swap (getVersionNumber());
  26962. prog->numParams = vst_swap (numParams);
  26963. getCurrentProgramName().copyToCString (prog->prgName, sizeof (prog->prgName) - 1);
  26964. for (int i = 0; i < numParams; ++i)
  26965. prog->params[i] = vst_swapFloat (getParameter (i));
  26966. }
  26967. bool VSTPluginInstance::saveToFXBFile (MemoryBlock& dest, bool isFXB, int maxSizeMB)
  26968. {
  26969. const int numPrograms = getNumPrograms();
  26970. const int numParams = getNumParameters();
  26971. if (usesChunks())
  26972. {
  26973. if (isFXB)
  26974. {
  26975. MemoryBlock chunk;
  26976. getChunkData (chunk, false, maxSizeMB);
  26977. const size_t totalLen = sizeof (fxChunkSet) + chunk.getSize() - 8;
  26978. dest.setSize (totalLen, true);
  26979. fxChunkSet* const set = (fxChunkSet*) dest.getData();
  26980. set->chunkMagic = vst_swap ('CcnK');
  26981. set->byteSize = 0;
  26982. set->fxMagic = vst_swap ('FBCh');
  26983. set->version = vst_swap (fxbVersionNum);
  26984. set->fxID = vst_swap (getUID());
  26985. set->fxVersion = vst_swap (getVersionNumber());
  26986. set->numPrograms = vst_swap (numPrograms);
  26987. set->chunkSize = vst_swap ((long) chunk.getSize());
  26988. chunk.copyTo (set->chunk, 0, chunk.getSize());
  26989. }
  26990. else
  26991. {
  26992. MemoryBlock chunk;
  26993. getChunkData (chunk, true, maxSizeMB);
  26994. const size_t totalLen = sizeof (fxProgramSet) + chunk.getSize() - 8;
  26995. dest.setSize (totalLen, true);
  26996. fxProgramSet* const set = (fxProgramSet*) dest.getData();
  26997. set->chunkMagic = vst_swap ('CcnK');
  26998. set->byteSize = 0;
  26999. set->fxMagic = vst_swap ('FPCh');
  27000. set->version = vst_swap (fxbVersionNum);
  27001. set->fxID = vst_swap (getUID());
  27002. set->fxVersion = vst_swap (getVersionNumber());
  27003. set->numPrograms = vst_swap (numPrograms);
  27004. set->chunkSize = vst_swap ((long) chunk.getSize());
  27005. getCurrentProgramName().copyToCString (set->name, sizeof (set->name) - 1);
  27006. chunk.copyTo (set->chunk, 0, chunk.getSize());
  27007. }
  27008. }
  27009. else
  27010. {
  27011. if (isFXB)
  27012. {
  27013. const int progLen = sizeof (fxProgram) + (numParams - 1) * sizeof (float);
  27014. const int len = (sizeof (fxSet) - sizeof (fxProgram)) + progLen * jmax (1, numPrograms);
  27015. dest.setSize (len, true);
  27016. fxSet* const set = (fxSet*) dest.getData();
  27017. set->chunkMagic = vst_swap ('CcnK');
  27018. set->byteSize = 0;
  27019. set->fxMagic = vst_swap ('FxBk');
  27020. set->version = vst_swap (fxbVersionNum);
  27021. set->fxID = vst_swap (getUID());
  27022. set->fxVersion = vst_swap (getVersionNumber());
  27023. set->numPrograms = vst_swap (numPrograms);
  27024. const int oldProgram = getCurrentProgram();
  27025. MemoryBlock oldSettings;
  27026. createTempParameterStore (oldSettings);
  27027. setParamsInProgramBlock ((fxProgram*) (((char*) (set->programs)) + oldProgram * progLen));
  27028. for (int i = 0; i < numPrograms; ++i)
  27029. {
  27030. if (i != oldProgram)
  27031. {
  27032. setCurrentProgram (i);
  27033. setParamsInProgramBlock ((fxProgram*) (((char*) (set->programs)) + i * progLen));
  27034. }
  27035. }
  27036. setCurrentProgram (oldProgram);
  27037. restoreFromTempParameterStore (oldSettings);
  27038. }
  27039. else
  27040. {
  27041. const int totalLen = sizeof (fxProgram) + (numParams - 1) * sizeof (float);
  27042. dest.setSize (totalLen, true);
  27043. setParamsInProgramBlock ((fxProgram*) dest.getData());
  27044. }
  27045. }
  27046. return true;
  27047. }
  27048. void VSTPluginInstance::getChunkData (MemoryBlock& mb, bool isPreset, int maxSizeMB) const
  27049. {
  27050. if (usesChunks())
  27051. {
  27052. void* data = 0;
  27053. const int bytes = dispatch (effGetChunk, isPreset ? 1 : 0, 0, &data, 0.0f);
  27054. if (data != 0 && bytes <= maxSizeMB * 1024 * 1024)
  27055. {
  27056. mb.setSize (bytes);
  27057. mb.copyFrom (data, 0, bytes);
  27058. }
  27059. }
  27060. }
  27061. void VSTPluginInstance::setChunkData (const char* data, int size, bool isPreset)
  27062. {
  27063. if (size > 0 && usesChunks())
  27064. {
  27065. dispatch (effSetChunk, isPreset ? 1 : 0, size, (void*) data, 0.0f);
  27066. if (! isPreset)
  27067. updateStoredProgramNames();
  27068. }
  27069. }
  27070. void VSTPluginInstance::timerCallback()
  27071. {
  27072. if (dispatch (effIdle, 0, 0, 0, 0) == 0)
  27073. stopTimer();
  27074. }
  27075. int VSTPluginInstance::dispatch (const int opcode, const int index, const int value, void* const ptr, float opt) const
  27076. {
  27077. const ScopedLock sl (lock);
  27078. ++insideVSTCallback;
  27079. int result = 0;
  27080. try
  27081. {
  27082. if (effect != 0)
  27083. {
  27084. #if JUCE_MAC
  27085. if (module->resFileId != 0)
  27086. UseResFile (module->resFileId);
  27087. CGrafPtr oldPort;
  27088. if (getActiveEditor() != 0)
  27089. {
  27090. const Point<int> pos (getActiveEditor()->relativePositionToOtherComponent (getActiveEditor()->getTopLevelComponent(), Point<int>()));
  27091. GetPort (&oldPort);
  27092. SetPortWindowPort ((WindowRef) getActiveEditor()->getWindowHandle());
  27093. SetOrigin (-pos.getX(), -pos.getY());
  27094. }
  27095. #endif
  27096. result = effect->dispatcher (effect, opcode, index, value, ptr, opt);
  27097. #if JUCE_MAC
  27098. if (getActiveEditor() != 0)
  27099. SetPort (oldPort);
  27100. module->resFileId = CurResFile();
  27101. #endif
  27102. --insideVSTCallback;
  27103. return result;
  27104. }
  27105. }
  27106. catch (...)
  27107. {
  27108. }
  27109. --insideVSTCallback;
  27110. return result;
  27111. }
  27112. // handles non plugin-specific callbacks..
  27113. static const int defaultVSTSampleRateValue = 16384;
  27114. static const int defaultVSTBlockSizeValue = 512;
  27115. static VstIntPtr handleGeneralCallback (VstInt32 opcode, VstInt32 index, VstInt32 value, void *ptr, float opt)
  27116. {
  27117. (void) index;
  27118. (void) value;
  27119. (void) opt;
  27120. switch (opcode)
  27121. {
  27122. case audioMasterCanDo:
  27123. {
  27124. static const char* canDos[] = { "supplyIdle",
  27125. "sendVstEvents",
  27126. "sendVstMidiEvent",
  27127. "sendVstTimeInfo",
  27128. "receiveVstEvents",
  27129. "receiveVstMidiEvent",
  27130. "supportShell",
  27131. "shellCategory" };
  27132. for (int i = 0; i < numElementsInArray (canDos); ++i)
  27133. if (strcmp (canDos[i], (const char*) ptr) == 0)
  27134. return 1;
  27135. return 0;
  27136. }
  27137. case audioMasterVersion:
  27138. return 0x2400;
  27139. case audioMasterCurrentId:
  27140. return shellUIDToCreate;
  27141. case audioMasterGetNumAutomatableParameters:
  27142. return 0;
  27143. case audioMasterGetAutomationState:
  27144. return 1;
  27145. case audioMasterGetVendorVersion:
  27146. return 0x0101;
  27147. case audioMasterGetVendorString:
  27148. case audioMasterGetProductString:
  27149. {
  27150. String hostName ("Juce VST Host");
  27151. if (JUCEApplication::getInstance() != 0)
  27152. hostName = JUCEApplication::getInstance()->getApplicationName();
  27153. hostName.copyToCString ((char*) ptr, jmin (kVstMaxVendorStrLen, kVstMaxProductStrLen) - 1);
  27154. }
  27155. break;
  27156. case audioMasterGetSampleRate:
  27157. return (VstIntPtr) defaultVSTSampleRateValue;
  27158. case audioMasterGetBlockSize:
  27159. return (VstIntPtr) defaultVSTBlockSizeValue;
  27160. case audioMasterSetOutputSampleRate:
  27161. return 0;
  27162. default:
  27163. DBG ("*** Unhandled VST Callback: " + String ((int) opcode));
  27164. break;
  27165. }
  27166. return 0;
  27167. }
  27168. // handles callbacks for a specific plugin
  27169. VstIntPtr VSTPluginInstance::handleCallback (VstInt32 opcode, VstInt32 index, VstInt32 value, void *ptr, float opt)
  27170. {
  27171. switch (opcode)
  27172. {
  27173. case audioMasterAutomate:
  27174. sendParamChangeMessageToListeners (index, opt);
  27175. break;
  27176. case audioMasterProcessEvents:
  27177. handleMidiFromPlugin ((const VstEvents*) ptr);
  27178. break;
  27179. case audioMasterGetTime:
  27180. #ifdef _MSC_VER
  27181. #pragma warning (push)
  27182. #pragma warning (disable: 4311)
  27183. #endif
  27184. return (VstIntPtr) &vstHostTime;
  27185. #ifdef _MSC_VER
  27186. #pragma warning (pop)
  27187. #endif
  27188. break;
  27189. case audioMasterIdle:
  27190. if (insideVSTCallback == 0 && MessageManager::getInstance()->isThisTheMessageThread())
  27191. {
  27192. ++insideVSTCallback;
  27193. #if JUCE_MAC
  27194. if (getActiveEditor() != 0)
  27195. dispatch (effEditIdle, 0, 0, 0, 0);
  27196. #endif
  27197. juce_callAnyTimersSynchronously();
  27198. handleUpdateNowIfNeeded();
  27199. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  27200. ComponentPeer::getPeer (i)->performAnyPendingRepaintsNow();
  27201. --insideVSTCallback;
  27202. }
  27203. break;
  27204. case audioMasterUpdateDisplay:
  27205. triggerAsyncUpdate();
  27206. break;
  27207. case audioMasterTempoAt:
  27208. // returns (10000 * bpm)
  27209. break;
  27210. case audioMasterNeedIdle:
  27211. startTimer (50);
  27212. break;
  27213. case audioMasterSizeWindow:
  27214. if (getActiveEditor() != 0)
  27215. getActiveEditor()->setSize (index, value);
  27216. return 1;
  27217. case audioMasterGetSampleRate:
  27218. return (VstIntPtr) (getSampleRate() > 0 ? getSampleRate() : defaultVSTSampleRateValue);
  27219. case audioMasterGetBlockSize:
  27220. return (VstIntPtr) (getBlockSize() > 0 ? getBlockSize() : defaultVSTBlockSizeValue);
  27221. case audioMasterWantMidi:
  27222. wantsMidiMessages = true;
  27223. break;
  27224. case audioMasterGetDirectory:
  27225. #if JUCE_MAC
  27226. return (VstIntPtr) (void*) &module->parentDirFSSpec;
  27227. #else
  27228. return (VstIntPtr) (pointer_sized_uint) module->fullParentDirectoryPathName.toUTF8();
  27229. #endif
  27230. case audioMasterGetAutomationState:
  27231. // returns 0: not supported, 1: off, 2:read, 3:write, 4:read/write
  27232. break;
  27233. // none of these are handled (yet)..
  27234. case audioMasterBeginEdit:
  27235. case audioMasterEndEdit:
  27236. case audioMasterSetTime:
  27237. case audioMasterPinConnected:
  27238. case audioMasterGetParameterQuantization:
  27239. case audioMasterIOChanged:
  27240. case audioMasterGetInputLatency:
  27241. case audioMasterGetOutputLatency:
  27242. case audioMasterGetPreviousPlug:
  27243. case audioMasterGetNextPlug:
  27244. case audioMasterWillReplaceOrAccumulate:
  27245. case audioMasterGetCurrentProcessLevel:
  27246. case audioMasterOfflineStart:
  27247. case audioMasterOfflineRead:
  27248. case audioMasterOfflineWrite:
  27249. case audioMasterOfflineGetCurrentPass:
  27250. case audioMasterOfflineGetCurrentMetaPass:
  27251. case audioMasterVendorSpecific:
  27252. case audioMasterSetIcon:
  27253. case audioMasterGetLanguage:
  27254. case audioMasterOpenWindow:
  27255. case audioMasterCloseWindow:
  27256. break;
  27257. default:
  27258. return handleGeneralCallback (opcode, index, value, ptr, opt);
  27259. }
  27260. return 0;
  27261. }
  27262. // entry point for all callbacks from the plugin
  27263. static VstIntPtr VSTCALLBACK audioMaster (AEffect* effect, VstInt32 opcode, VstInt32 index, VstIntPtr value, void* ptr, float opt)
  27264. {
  27265. try
  27266. {
  27267. if (effect != 0 && effect->resvd2 != 0)
  27268. {
  27269. return ((VSTPluginInstance*)(effect->resvd2))
  27270. ->handleCallback (opcode, index, value, ptr, opt);
  27271. }
  27272. return handleGeneralCallback (opcode, index, value, ptr, opt);
  27273. }
  27274. catch (...)
  27275. {
  27276. return 0;
  27277. }
  27278. }
  27279. const String VSTPluginInstance::getVersion() const throw()
  27280. {
  27281. unsigned int v = dispatch (effGetVendorVersion, 0, 0, 0, 0);
  27282. String s;
  27283. if (v == 0 || v == -1)
  27284. v = getVersionNumber();
  27285. if (v != 0)
  27286. {
  27287. int versionBits[4];
  27288. int n = 0;
  27289. while (v != 0)
  27290. {
  27291. versionBits [n++] = (v & 0xff);
  27292. v >>= 8;
  27293. }
  27294. s << 'V';
  27295. while (n > 0)
  27296. {
  27297. s << versionBits [--n];
  27298. if (n > 0)
  27299. s << '.';
  27300. }
  27301. }
  27302. return s;
  27303. }
  27304. int VSTPluginInstance::getUID() const throw()
  27305. {
  27306. int uid = effect != 0 ? effect->uniqueID : 0;
  27307. if (uid == 0)
  27308. uid = module->file.hashCode();
  27309. return uid;
  27310. }
  27311. const String VSTPluginInstance::getCategory() const throw()
  27312. {
  27313. const char* result = 0;
  27314. switch (dispatch (effGetPlugCategory, 0, 0, 0, 0))
  27315. {
  27316. case kPlugCategEffect:
  27317. result = "Effect";
  27318. break;
  27319. case kPlugCategSynth:
  27320. result = "Synth";
  27321. break;
  27322. case kPlugCategAnalysis:
  27323. result = "Anaylsis";
  27324. break;
  27325. case kPlugCategMastering:
  27326. result = "Mastering";
  27327. break;
  27328. case kPlugCategSpacializer:
  27329. result = "Spacial";
  27330. break;
  27331. case kPlugCategRoomFx:
  27332. result = "Reverb";
  27333. break;
  27334. case kPlugSurroundFx:
  27335. result = "Surround";
  27336. break;
  27337. case kPlugCategRestoration:
  27338. result = "Restoration";
  27339. break;
  27340. case kPlugCategGenerator:
  27341. result = "Tone generation";
  27342. break;
  27343. default:
  27344. break;
  27345. }
  27346. return result;
  27347. }
  27348. float VSTPluginInstance::getParameter (int index)
  27349. {
  27350. if (effect != 0 && ((unsigned int) index) < (unsigned int) effect->numParams)
  27351. {
  27352. try
  27353. {
  27354. const ScopedLock sl (lock);
  27355. return effect->getParameter (effect, index);
  27356. }
  27357. catch (...)
  27358. {
  27359. }
  27360. }
  27361. return 0.0f;
  27362. }
  27363. void VSTPluginInstance::setParameter (int index, float newValue)
  27364. {
  27365. if (effect != 0 && ((unsigned int) index) < (unsigned int) effect->numParams)
  27366. {
  27367. try
  27368. {
  27369. const ScopedLock sl (lock);
  27370. if (effect->getParameter (effect, index) != newValue)
  27371. effect->setParameter (effect, index, newValue);
  27372. }
  27373. catch (...)
  27374. {
  27375. }
  27376. }
  27377. }
  27378. const String VSTPluginInstance::getParameterName (int index)
  27379. {
  27380. if (effect != 0)
  27381. {
  27382. jassert (index >= 0 && index < effect->numParams);
  27383. char nm [256];
  27384. zerostruct (nm);
  27385. dispatch (effGetParamName, index, 0, nm, 0);
  27386. return String (nm).trim();
  27387. }
  27388. return String::empty;
  27389. }
  27390. const String VSTPluginInstance::getParameterLabel (int index) const
  27391. {
  27392. if (effect != 0)
  27393. {
  27394. jassert (index >= 0 && index < effect->numParams);
  27395. char nm [256];
  27396. zerostruct (nm);
  27397. dispatch (effGetParamLabel, index, 0, nm, 0);
  27398. return String (nm).trim();
  27399. }
  27400. return String::empty;
  27401. }
  27402. const String VSTPluginInstance::getParameterText (int index)
  27403. {
  27404. if (effect != 0)
  27405. {
  27406. jassert (index >= 0 && index < effect->numParams);
  27407. char nm [256];
  27408. zerostruct (nm);
  27409. dispatch (effGetParamDisplay, index, 0, nm, 0);
  27410. return String (nm).trim();
  27411. }
  27412. return String::empty;
  27413. }
  27414. bool VSTPluginInstance::isParameterAutomatable (int index) const
  27415. {
  27416. if (effect != 0)
  27417. {
  27418. jassert (index >= 0 && index < effect->numParams);
  27419. return dispatch (effCanBeAutomated, index, 0, 0, 0) != 0;
  27420. }
  27421. return false;
  27422. }
  27423. void VSTPluginInstance::createTempParameterStore (MemoryBlock& dest)
  27424. {
  27425. dest.setSize (64 + 4 * getNumParameters());
  27426. dest.fillWith (0);
  27427. getCurrentProgramName().copyToCString ((char*) dest.getData(), 63);
  27428. float* const p = (float*) (((char*) dest.getData()) + 64);
  27429. for (int i = 0; i < getNumParameters(); ++i)
  27430. p[i] = getParameter(i);
  27431. }
  27432. void VSTPluginInstance::restoreFromTempParameterStore (const MemoryBlock& m)
  27433. {
  27434. changeProgramName (getCurrentProgram(), (const char*) m.getData());
  27435. float* p = (float*) (((char*) m.getData()) + 64);
  27436. for (int i = 0; i < getNumParameters(); ++i)
  27437. setParameter (i, p[i]);
  27438. }
  27439. void VSTPluginInstance::setCurrentProgram (int newIndex)
  27440. {
  27441. if (getNumPrograms() > 0 && newIndex != getCurrentProgram())
  27442. dispatch (effSetProgram, 0, jlimit (0, getNumPrograms() - 1, newIndex), 0, 0);
  27443. }
  27444. const String VSTPluginInstance::getProgramName (int index)
  27445. {
  27446. if (index == getCurrentProgram())
  27447. {
  27448. return getCurrentProgramName();
  27449. }
  27450. else if (effect != 0)
  27451. {
  27452. char nm [256];
  27453. zerostruct (nm);
  27454. if (dispatch (effGetProgramNameIndexed,
  27455. jlimit (0, getNumPrograms(), index),
  27456. -1, nm, 0) != 0)
  27457. {
  27458. return String (nm).trim();
  27459. }
  27460. }
  27461. return programNames [index];
  27462. }
  27463. void VSTPluginInstance::changeProgramName (int index, const String& newName)
  27464. {
  27465. if (index == getCurrentProgram())
  27466. {
  27467. if (getNumPrograms() > 0 && newName != getCurrentProgramName())
  27468. dispatch (effSetProgramName, 0, 0, (void*) newName.substring (0, 24).toCString(), 0.0f);
  27469. }
  27470. else
  27471. {
  27472. jassertfalse // xxx not implemented!
  27473. }
  27474. }
  27475. void VSTPluginInstance::updateStoredProgramNames()
  27476. {
  27477. if (effect != 0 && getNumPrograms() > 0)
  27478. {
  27479. char nm [256];
  27480. zerostruct (nm);
  27481. // only do this if the plugin can't use indexed names..
  27482. if (dispatch (effGetProgramNameIndexed, 0, -1, nm, 0) == 0)
  27483. {
  27484. const int oldProgram = getCurrentProgram();
  27485. MemoryBlock oldSettings;
  27486. createTempParameterStore (oldSettings);
  27487. for (int i = 0; i < getNumPrograms(); ++i)
  27488. {
  27489. setCurrentProgram (i);
  27490. getCurrentProgramName(); // (this updates the list)
  27491. }
  27492. setCurrentProgram (oldProgram);
  27493. restoreFromTempParameterStore (oldSettings);
  27494. }
  27495. }
  27496. }
  27497. const String VSTPluginInstance::getCurrentProgramName()
  27498. {
  27499. if (effect != 0)
  27500. {
  27501. char nm [256];
  27502. zerostruct (nm);
  27503. dispatch (effGetProgramName, 0, 0, nm, 0);
  27504. const int index = getCurrentProgram();
  27505. if (programNames[index].isEmpty())
  27506. {
  27507. while (programNames.size() < index)
  27508. programNames.add (String::empty);
  27509. programNames.set (index, String (nm).trim());
  27510. }
  27511. return String (nm).trim();
  27512. }
  27513. return String::empty;
  27514. }
  27515. const String VSTPluginInstance::getInputChannelName (const int index) const
  27516. {
  27517. if (index >= 0 && index < getNumInputChannels())
  27518. {
  27519. VstPinProperties pinProps;
  27520. if (dispatch (effGetInputProperties, index, 0, &pinProps, 0.0f) != 0)
  27521. return String (pinProps.label, sizeof (pinProps.label));
  27522. }
  27523. return String::empty;
  27524. }
  27525. bool VSTPluginInstance::isInputChannelStereoPair (int index) const
  27526. {
  27527. if (index < 0 || index >= getNumInputChannels())
  27528. return false;
  27529. VstPinProperties pinProps;
  27530. if (dispatch (effGetInputProperties, index, 0, &pinProps, 0.0f) != 0)
  27531. return (pinProps.flags & kVstPinIsStereo) != 0;
  27532. return true;
  27533. }
  27534. const String VSTPluginInstance::getOutputChannelName (const int index) const
  27535. {
  27536. if (index >= 0 && index < getNumOutputChannels())
  27537. {
  27538. VstPinProperties pinProps;
  27539. if (dispatch (effGetOutputProperties, index, 0, &pinProps, 0.0f) != 0)
  27540. return String (pinProps.label, sizeof (pinProps.label));
  27541. }
  27542. return String::empty;
  27543. }
  27544. bool VSTPluginInstance::isOutputChannelStereoPair (int index) const
  27545. {
  27546. if (index < 0 || index >= getNumOutputChannels())
  27547. return false;
  27548. VstPinProperties pinProps;
  27549. if (dispatch (effGetOutputProperties, index, 0, &pinProps, 0.0f) != 0)
  27550. return (pinProps.flags & kVstPinIsStereo) != 0;
  27551. return true;
  27552. }
  27553. void VSTPluginInstance::setPower (const bool on)
  27554. {
  27555. dispatch (effMainsChanged, 0, on ? 1 : 0, 0, 0);
  27556. isPowerOn = on;
  27557. }
  27558. const int defaultMaxSizeMB = 64;
  27559. void VSTPluginInstance::getStateInformation (MemoryBlock& destData)
  27560. {
  27561. saveToFXBFile (destData, true, defaultMaxSizeMB);
  27562. }
  27563. void VSTPluginInstance::getCurrentProgramStateInformation (MemoryBlock& destData)
  27564. {
  27565. saveToFXBFile (destData, false, defaultMaxSizeMB);
  27566. }
  27567. void VSTPluginInstance::setStateInformation (const void* data, int sizeInBytes)
  27568. {
  27569. loadFromFXBFile (data, sizeInBytes);
  27570. }
  27571. void VSTPluginInstance::setCurrentProgramStateInformation (const void* data, int sizeInBytes)
  27572. {
  27573. loadFromFXBFile (data, sizeInBytes);
  27574. }
  27575. VSTPluginFormat::VSTPluginFormat()
  27576. {
  27577. }
  27578. VSTPluginFormat::~VSTPluginFormat()
  27579. {
  27580. }
  27581. void VSTPluginFormat::findAllTypesForFile (OwnedArray <PluginDescription>& results,
  27582. const String& fileOrIdentifier)
  27583. {
  27584. if (! fileMightContainThisPluginType (fileOrIdentifier))
  27585. return;
  27586. PluginDescription desc;
  27587. desc.fileOrIdentifier = fileOrIdentifier;
  27588. desc.uid = 0;
  27589. ScopedPointer <VSTPluginInstance> instance (dynamic_cast <VSTPluginInstance*> (createInstanceFromDescription (desc)));
  27590. if (instance == 0)
  27591. return;
  27592. try
  27593. {
  27594. #if JUCE_MAC
  27595. if (instance->module->resFileId != 0)
  27596. UseResFile (instance->module->resFileId);
  27597. #endif
  27598. instance->fillInPluginDescription (desc);
  27599. VstPlugCategory category = (VstPlugCategory) instance->dispatch (effGetPlugCategory, 0, 0, 0, 0);
  27600. if (category != kPlugCategShell)
  27601. {
  27602. // Normal plugin...
  27603. results.add (new PluginDescription (desc));
  27604. ++insideVSTCallback;
  27605. instance->dispatch (effOpen, 0, 0, 0, 0);
  27606. --insideVSTCallback;
  27607. }
  27608. else
  27609. {
  27610. // It's a shell plugin, so iterate all the subtypes...
  27611. char shellEffectName [64];
  27612. for (;;)
  27613. {
  27614. zerostruct (shellEffectName);
  27615. const int uid = instance->dispatch (effShellGetNextPlugin, 0, 0, shellEffectName, 0);
  27616. if (uid == 0)
  27617. {
  27618. break;
  27619. }
  27620. else
  27621. {
  27622. desc.uid = uid;
  27623. desc.name = shellEffectName;
  27624. bool alreadyThere = false;
  27625. for (int i = results.size(); --i >= 0;)
  27626. {
  27627. PluginDescription* const d = results.getUnchecked(i);
  27628. if (d->isDuplicateOf (desc))
  27629. {
  27630. alreadyThere = true;
  27631. break;
  27632. }
  27633. }
  27634. if (! alreadyThere)
  27635. results.add (new PluginDescription (desc));
  27636. }
  27637. }
  27638. }
  27639. }
  27640. catch (...)
  27641. {
  27642. // crashed while loading...
  27643. }
  27644. }
  27645. AudioPluginInstance* VSTPluginFormat::createInstanceFromDescription (const PluginDescription& desc)
  27646. {
  27647. ScopedPointer <VSTPluginInstance> result;
  27648. if (fileMightContainThisPluginType (desc.fileOrIdentifier))
  27649. {
  27650. File file (desc.fileOrIdentifier);
  27651. const File previousWorkingDirectory (File::getCurrentWorkingDirectory());
  27652. file.getParentDirectory().setAsCurrentWorkingDirectory();
  27653. const ReferenceCountedObjectPtr <ModuleHandle> module (ModuleHandle::findOrCreateModule (file));
  27654. if (module != 0)
  27655. {
  27656. shellUIDToCreate = desc.uid;
  27657. result = new VSTPluginInstance (module);
  27658. if (result->effect != 0)
  27659. {
  27660. result->effect->resvd2 = (VstIntPtr) (pointer_sized_int) (VSTPluginInstance*) result;
  27661. result->initialise();
  27662. }
  27663. else
  27664. {
  27665. result = 0;
  27666. }
  27667. }
  27668. previousWorkingDirectory.setAsCurrentWorkingDirectory();
  27669. }
  27670. return result.release();
  27671. }
  27672. bool VSTPluginFormat::fileMightContainThisPluginType (const String& fileOrIdentifier)
  27673. {
  27674. const File f (fileOrIdentifier);
  27675. #if JUCE_MAC
  27676. if (f.isDirectory() && f.hasFileExtension (T(".vst")))
  27677. return true;
  27678. #if JUCE_PPC
  27679. FSRef fileRef;
  27680. if (PlatformUtilities::makeFSRefFromPath (&fileRef, f.getFullPathName()))
  27681. {
  27682. const short resFileId = FSOpenResFile (&fileRef, fsRdPerm);
  27683. if (resFileId != -1)
  27684. {
  27685. const int numEffects = Count1Resources ('aEff');
  27686. CloseResFile (resFileId);
  27687. if (numEffects > 0)
  27688. return true;
  27689. }
  27690. }
  27691. #endif
  27692. return false;
  27693. #elif JUCE_WIN32
  27694. return f.existsAsFile()
  27695. && f.hasFileExtension (T(".dll"));
  27696. #elif JUCE_LINUX
  27697. return f.existsAsFile()
  27698. && f.hasFileExtension (T(".so"));
  27699. #endif
  27700. }
  27701. const String VSTPluginFormat::getNameOfPluginFromIdentifier (const String& fileOrIdentifier)
  27702. {
  27703. return fileOrIdentifier;
  27704. }
  27705. bool VSTPluginFormat::doesPluginStillExist (const PluginDescription& desc)
  27706. {
  27707. return File (desc.fileOrIdentifier).exists();
  27708. }
  27709. const StringArray VSTPluginFormat::searchPathsForPlugins (const FileSearchPath& directoriesToSearch, const bool recursive)
  27710. {
  27711. StringArray results;
  27712. for (int j = 0; j < directoriesToSearch.getNumPaths(); ++j)
  27713. recursiveFileSearch (results, directoriesToSearch [j], recursive);
  27714. return results;
  27715. }
  27716. void VSTPluginFormat::recursiveFileSearch (StringArray& results, const File& dir, const bool recursive)
  27717. {
  27718. // avoid allowing the dir iterator to be recursive, because we want to avoid letting it delve inside
  27719. // .component or .vst directories.
  27720. DirectoryIterator iter (dir, false, "*", File::findFilesAndDirectories);
  27721. while (iter.next())
  27722. {
  27723. const File f (iter.getFile());
  27724. bool isPlugin = false;
  27725. if (fileMightContainThisPluginType (f.getFullPathName()))
  27726. {
  27727. isPlugin = true;
  27728. results.add (f.getFullPathName());
  27729. }
  27730. if (recursive && (! isPlugin) && f.isDirectory())
  27731. recursiveFileSearch (results, f, true);
  27732. }
  27733. }
  27734. const FileSearchPath VSTPluginFormat::getDefaultLocationsToSearch()
  27735. {
  27736. #if JUCE_MAC
  27737. return FileSearchPath ("~/Library/Audio/Plug-Ins/VST;/Library/Audio/Plug-Ins/VST");
  27738. #elif JUCE_WIN32
  27739. const String programFiles (File::getSpecialLocation (File::globalApplicationsDirectory).getFullPathName());
  27740. return FileSearchPath (programFiles + "\\Steinberg\\VstPlugins");
  27741. #elif JUCE_LINUX
  27742. return FileSearchPath ("/usr/lib/vst");
  27743. #endif
  27744. }
  27745. END_JUCE_NAMESPACE
  27746. #endif
  27747. #undef log
  27748. #endif
  27749. /*** End of inlined file: juce_VSTPluginFormat.cpp ***/
  27750. /*** End of inlined file: juce_VSTPluginFormat.mm ***/
  27751. /*** Start of inlined file: juce_AudioProcessor.cpp ***/
  27752. BEGIN_JUCE_NAMESPACE
  27753. AudioProcessor::AudioProcessor()
  27754. : playHead (0),
  27755. activeEditor (0),
  27756. sampleRate (0),
  27757. blockSize (0),
  27758. numInputChannels (0),
  27759. numOutputChannels (0),
  27760. latencySamples (0),
  27761. suspended (false),
  27762. nonRealtime (false)
  27763. {
  27764. }
  27765. AudioProcessor::~AudioProcessor()
  27766. {
  27767. // ooh, nasty - the editor should have been deleted before the filter
  27768. // that it refers to is deleted..
  27769. jassert (activeEditor == 0);
  27770. #ifdef JUCE_DEBUG
  27771. // This will fail if you've called beginParameterChangeGesture() for one
  27772. // or more parameters without having made a corresponding call to endParameterChangeGesture...
  27773. jassert (changingParams.countNumberOfSetBits() == 0);
  27774. #endif
  27775. }
  27776. void AudioProcessor::setPlayHead (AudioPlayHead* const newPlayHead) throw()
  27777. {
  27778. playHead = newPlayHead;
  27779. }
  27780. void AudioProcessor::addListener (AudioProcessorListener* const newListener) throw()
  27781. {
  27782. const ScopedLock sl (listenerLock);
  27783. listeners.addIfNotAlreadyThere (newListener);
  27784. }
  27785. void AudioProcessor::removeListener (AudioProcessorListener* const listenerToRemove) throw()
  27786. {
  27787. const ScopedLock sl (listenerLock);
  27788. listeners.removeValue (listenerToRemove);
  27789. }
  27790. void AudioProcessor::setPlayConfigDetails (const int numIns,
  27791. const int numOuts,
  27792. const double sampleRate_,
  27793. const int blockSize_) throw()
  27794. {
  27795. numInputChannels = numIns;
  27796. numOutputChannels = numOuts;
  27797. sampleRate = sampleRate_;
  27798. blockSize = blockSize_;
  27799. }
  27800. void AudioProcessor::setNonRealtime (const bool nonRealtime_) throw()
  27801. {
  27802. nonRealtime = nonRealtime_;
  27803. }
  27804. void AudioProcessor::setLatencySamples (const int newLatency)
  27805. {
  27806. if (latencySamples != newLatency)
  27807. {
  27808. latencySamples = newLatency;
  27809. updateHostDisplay();
  27810. }
  27811. }
  27812. void AudioProcessor::setParameterNotifyingHost (const int parameterIndex,
  27813. const float newValue)
  27814. {
  27815. setParameter (parameterIndex, newValue);
  27816. sendParamChangeMessageToListeners (parameterIndex, newValue);
  27817. }
  27818. void AudioProcessor::sendParamChangeMessageToListeners (const int parameterIndex, const float newValue)
  27819. {
  27820. jassert (((unsigned int) parameterIndex) < (unsigned int) getNumParameters());
  27821. for (int i = listeners.size(); --i >= 0;)
  27822. {
  27823. AudioProcessorListener* l;
  27824. {
  27825. const ScopedLock sl (listenerLock);
  27826. l = (AudioProcessorListener*) listeners [i];
  27827. }
  27828. if (l != 0)
  27829. l->audioProcessorParameterChanged (this, parameterIndex, newValue);
  27830. }
  27831. }
  27832. void AudioProcessor::beginParameterChangeGesture (int parameterIndex)
  27833. {
  27834. jassert (((unsigned int) parameterIndex) < (unsigned int) getNumParameters());
  27835. #ifdef JUCE_DEBUG
  27836. // This means you've called beginParameterChangeGesture twice in succession without a matching
  27837. // call to endParameterChangeGesture. That might be fine in most hosts, but better to avoid doing it.
  27838. jassert (! changingParams [parameterIndex]);
  27839. changingParams.setBit (parameterIndex);
  27840. #endif
  27841. for (int i = listeners.size(); --i >= 0;)
  27842. {
  27843. AudioProcessorListener* l;
  27844. {
  27845. const ScopedLock sl (listenerLock);
  27846. l = (AudioProcessorListener*) listeners [i];
  27847. }
  27848. if (l != 0)
  27849. l->audioProcessorParameterChangeGestureBegin (this, parameterIndex);
  27850. }
  27851. }
  27852. void AudioProcessor::endParameterChangeGesture (int parameterIndex)
  27853. {
  27854. jassert (((unsigned int) parameterIndex) < (unsigned int) getNumParameters());
  27855. #ifdef JUCE_DEBUG
  27856. // This means you've called endParameterChangeGesture without having previously called
  27857. // endParameterChangeGesture. That might be fine in most hosts, but better to keep the
  27858. // calls matched correctly.
  27859. jassert (changingParams [parameterIndex]);
  27860. changingParams.clearBit (parameterIndex);
  27861. #endif
  27862. for (int i = listeners.size(); --i >= 0;)
  27863. {
  27864. AudioProcessorListener* l;
  27865. {
  27866. const ScopedLock sl (listenerLock);
  27867. l = (AudioProcessorListener*) listeners [i];
  27868. }
  27869. if (l != 0)
  27870. l->audioProcessorParameterChangeGestureEnd (this, parameterIndex);
  27871. }
  27872. }
  27873. void AudioProcessor::updateHostDisplay()
  27874. {
  27875. for (int i = listeners.size(); --i >= 0;)
  27876. {
  27877. AudioProcessorListener* l;
  27878. {
  27879. const ScopedLock sl (listenerLock);
  27880. l = (AudioProcessorListener*) listeners [i];
  27881. }
  27882. if (l != 0)
  27883. l->audioProcessorChanged (this);
  27884. }
  27885. }
  27886. bool AudioProcessor::isParameterAutomatable (int /*parameterIndex*/) const
  27887. {
  27888. return true;
  27889. }
  27890. bool AudioProcessor::isMetaParameter (int /*parameterIndex*/) const
  27891. {
  27892. return false;
  27893. }
  27894. void AudioProcessor::suspendProcessing (const bool shouldBeSuspended)
  27895. {
  27896. const ScopedLock sl (callbackLock);
  27897. suspended = shouldBeSuspended;
  27898. }
  27899. void AudioProcessor::reset()
  27900. {
  27901. }
  27902. void AudioProcessor::editorBeingDeleted (AudioProcessorEditor* const editor) throw()
  27903. {
  27904. const ScopedLock sl (callbackLock);
  27905. jassert (activeEditor == editor);
  27906. if (activeEditor == editor)
  27907. activeEditor = 0;
  27908. }
  27909. AudioProcessorEditor* AudioProcessor::createEditorIfNeeded()
  27910. {
  27911. if (activeEditor != 0)
  27912. return activeEditor;
  27913. AudioProcessorEditor* const ed = createEditor();
  27914. if (ed != 0)
  27915. {
  27916. // you must give your editor comp a size before returning it..
  27917. jassert (ed->getWidth() > 0 && ed->getHeight() > 0);
  27918. const ScopedLock sl (callbackLock);
  27919. activeEditor = ed;
  27920. }
  27921. return ed;
  27922. }
  27923. void AudioProcessor::getCurrentProgramStateInformation (JUCE_NAMESPACE::MemoryBlock& destData)
  27924. {
  27925. getStateInformation (destData);
  27926. }
  27927. void AudioProcessor::setCurrentProgramStateInformation (const void* data, int sizeInBytes)
  27928. {
  27929. setStateInformation (data, sizeInBytes);
  27930. }
  27931. // magic number to identify memory blocks that we've stored as XML
  27932. const uint32 magicXmlNumber = 0x21324356;
  27933. void AudioProcessor::copyXmlToBinary (const XmlElement& xml,
  27934. JUCE_NAMESPACE::MemoryBlock& destData)
  27935. {
  27936. const String xmlString (xml.createDocument (String::empty, true, false));
  27937. const int stringLength = xmlString.getNumBytesAsUTF8();
  27938. destData.setSize (stringLength + 10);
  27939. char* const d = (char*) destData.getData();
  27940. *(uint32*) d = ByteOrder::swapIfBigEndian ((const uint32) magicXmlNumber);
  27941. *(uint32*) (d + 4) = ByteOrder::swapIfBigEndian ((const uint32) stringLength);
  27942. xmlString.copyToUTF8 (d + 8, stringLength + 1);
  27943. }
  27944. XmlElement* AudioProcessor::getXmlFromBinary (const void* data,
  27945. const int sizeInBytes)
  27946. {
  27947. if (sizeInBytes > 8
  27948. && ByteOrder::littleEndianInt ((const char*) data) == magicXmlNumber)
  27949. {
  27950. const int stringLength = (int) ByteOrder::littleEndianInt (((const char*) data) + 4);
  27951. if (stringLength > 0)
  27952. {
  27953. XmlDocument doc (String::fromUTF8 (((const char*) data) + 8,
  27954. jmin ((sizeInBytes - 8), stringLength)));
  27955. return doc.getDocumentElement();
  27956. }
  27957. }
  27958. return 0;
  27959. }
  27960. void AudioProcessorListener::audioProcessorParameterChangeGestureBegin (AudioProcessor*, int)
  27961. {
  27962. }
  27963. void AudioProcessorListener::audioProcessorParameterChangeGestureEnd (AudioProcessor*, int)
  27964. {
  27965. }
  27966. END_JUCE_NAMESPACE
  27967. /*** End of inlined file: juce_AudioProcessor.cpp ***/
  27968. /*** Start of inlined file: juce_AudioProcessorEditor.cpp ***/
  27969. BEGIN_JUCE_NAMESPACE
  27970. AudioProcessorEditor::AudioProcessorEditor (AudioProcessor* const owner_)
  27971. : owner (owner_)
  27972. {
  27973. // the filter must be valid..
  27974. jassert (owner != 0);
  27975. }
  27976. AudioProcessorEditor::~AudioProcessorEditor()
  27977. {
  27978. // if this fails, then the wrapper hasn't called editorBeingDeleted() on the
  27979. // filter for some reason..
  27980. jassert (owner->getActiveEditor() != this);
  27981. }
  27982. END_JUCE_NAMESPACE
  27983. /*** End of inlined file: juce_AudioProcessorEditor.cpp ***/
  27984. /*** Start of inlined file: juce_AudioProcessorGraph.cpp ***/
  27985. BEGIN_JUCE_NAMESPACE
  27986. const int AudioProcessorGraph::midiChannelIndex = 0x1000;
  27987. AudioProcessorGraph::Node::Node (const uint32 id_, AudioProcessor* const processor_)
  27988. : id (id_),
  27989. processor (processor_),
  27990. isPrepared (false)
  27991. {
  27992. jassert (processor_ != 0);
  27993. }
  27994. AudioProcessorGraph::Node::~Node()
  27995. {
  27996. delete processor;
  27997. }
  27998. void AudioProcessorGraph::Node::prepare (const double sampleRate, const int blockSize,
  27999. AudioProcessorGraph* const graph)
  28000. {
  28001. if (! isPrepared)
  28002. {
  28003. isPrepared = true;
  28004. AudioProcessorGraph::AudioGraphIOProcessor* const ioProc
  28005. = dynamic_cast <AudioProcessorGraph::AudioGraphIOProcessor*> (processor);
  28006. if (ioProc != 0)
  28007. ioProc->setParentGraph (graph);
  28008. processor->setPlayConfigDetails (processor->getNumInputChannels(),
  28009. processor->getNumOutputChannels(),
  28010. sampleRate, blockSize);
  28011. processor->prepareToPlay (sampleRate, blockSize);
  28012. }
  28013. }
  28014. void AudioProcessorGraph::Node::unprepare()
  28015. {
  28016. if (isPrepared)
  28017. {
  28018. isPrepared = false;
  28019. processor->releaseResources();
  28020. }
  28021. }
  28022. AudioProcessorGraph::AudioProcessorGraph()
  28023. : lastNodeId (0),
  28024. renderingBuffers (1, 1),
  28025. currentAudioOutputBuffer (1, 1)
  28026. {
  28027. }
  28028. AudioProcessorGraph::~AudioProcessorGraph()
  28029. {
  28030. clearRenderingSequence();
  28031. clear();
  28032. }
  28033. const String AudioProcessorGraph::getName() const
  28034. {
  28035. return "Audio Graph";
  28036. }
  28037. void AudioProcessorGraph::clear()
  28038. {
  28039. nodes.clear();
  28040. connections.clear();
  28041. triggerAsyncUpdate();
  28042. }
  28043. AudioProcessorGraph::Node* AudioProcessorGraph::getNodeForId (const uint32 nodeId) const
  28044. {
  28045. for (int i = nodes.size(); --i >= 0;)
  28046. if (nodes.getUnchecked(i)->id == nodeId)
  28047. return nodes.getUnchecked(i);
  28048. return 0;
  28049. }
  28050. AudioProcessorGraph::Node* AudioProcessorGraph::addNode (AudioProcessor* const newProcessor,
  28051. uint32 nodeId)
  28052. {
  28053. if (newProcessor == 0)
  28054. {
  28055. jassertfalse
  28056. return 0;
  28057. }
  28058. if (nodeId == 0)
  28059. {
  28060. nodeId = ++lastNodeId;
  28061. }
  28062. else
  28063. {
  28064. // you can't add a node with an id that already exists in the graph..
  28065. jassert (getNodeForId (nodeId) == 0);
  28066. removeNode (nodeId);
  28067. }
  28068. lastNodeId = nodeId;
  28069. Node* const n = new Node (nodeId, newProcessor);
  28070. nodes.add (n);
  28071. triggerAsyncUpdate();
  28072. AudioProcessorGraph::AudioGraphIOProcessor* const ioProc
  28073. = dynamic_cast <AudioProcessorGraph::AudioGraphIOProcessor*> (n->processor);
  28074. if (ioProc != 0)
  28075. ioProc->setParentGraph (this);
  28076. return n;
  28077. }
  28078. bool AudioProcessorGraph::removeNode (const uint32 nodeId)
  28079. {
  28080. disconnectNode (nodeId);
  28081. for (int i = nodes.size(); --i >= 0;)
  28082. {
  28083. if (nodes.getUnchecked(i)->id == nodeId)
  28084. {
  28085. AudioProcessorGraph::AudioGraphIOProcessor* const ioProc
  28086. = dynamic_cast <AudioProcessorGraph::AudioGraphIOProcessor*> (nodes.getUnchecked(i)->processor);
  28087. if (ioProc != 0)
  28088. ioProc->setParentGraph (0);
  28089. nodes.remove (i);
  28090. triggerAsyncUpdate();
  28091. return true;
  28092. }
  28093. }
  28094. return false;
  28095. }
  28096. const AudioProcessorGraph::Connection* AudioProcessorGraph::getConnectionBetween (const uint32 sourceNodeId,
  28097. const int sourceChannelIndex,
  28098. const uint32 destNodeId,
  28099. const int destChannelIndex) const
  28100. {
  28101. for (int i = connections.size(); --i >= 0;)
  28102. {
  28103. const Connection* const c = connections.getUnchecked(i);
  28104. if (c->sourceNodeId == sourceNodeId
  28105. && c->destNodeId == destNodeId
  28106. && c->sourceChannelIndex == sourceChannelIndex
  28107. && c->destChannelIndex == destChannelIndex)
  28108. {
  28109. return c;
  28110. }
  28111. }
  28112. return 0;
  28113. }
  28114. bool AudioProcessorGraph::isConnected (const uint32 possibleSourceNodeId,
  28115. const uint32 possibleDestNodeId) const
  28116. {
  28117. for (int i = connections.size(); --i >= 0;)
  28118. {
  28119. const Connection* const c = connections.getUnchecked(i);
  28120. if (c->sourceNodeId == possibleSourceNodeId
  28121. && c->destNodeId == possibleDestNodeId)
  28122. {
  28123. return true;
  28124. }
  28125. }
  28126. return false;
  28127. }
  28128. bool AudioProcessorGraph::canConnect (const uint32 sourceNodeId,
  28129. const int sourceChannelIndex,
  28130. const uint32 destNodeId,
  28131. const int destChannelIndex) const
  28132. {
  28133. if (sourceChannelIndex < 0
  28134. || destChannelIndex < 0
  28135. || sourceNodeId == destNodeId
  28136. || (destChannelIndex == midiChannelIndex) != (sourceChannelIndex == midiChannelIndex))
  28137. return false;
  28138. const Node* const source = getNodeForId (sourceNodeId);
  28139. if (source == 0
  28140. || (sourceChannelIndex != midiChannelIndex && sourceChannelIndex >= source->processor->getNumOutputChannels())
  28141. || (sourceChannelIndex == midiChannelIndex && ! source->processor->producesMidi()))
  28142. return false;
  28143. const Node* const dest = getNodeForId (destNodeId);
  28144. if (dest == 0
  28145. || (destChannelIndex != midiChannelIndex && destChannelIndex >= dest->processor->getNumInputChannels())
  28146. || (destChannelIndex == midiChannelIndex && ! dest->processor->acceptsMidi()))
  28147. return false;
  28148. return getConnectionBetween (sourceNodeId, sourceChannelIndex,
  28149. destNodeId, destChannelIndex) == 0;
  28150. }
  28151. bool AudioProcessorGraph::addConnection (const uint32 sourceNodeId,
  28152. const int sourceChannelIndex,
  28153. const uint32 destNodeId,
  28154. const int destChannelIndex)
  28155. {
  28156. if (! canConnect (sourceNodeId, sourceChannelIndex, destNodeId, destChannelIndex))
  28157. return false;
  28158. Connection* const c = new Connection();
  28159. c->sourceNodeId = sourceNodeId;
  28160. c->sourceChannelIndex = sourceChannelIndex;
  28161. c->destNodeId = destNodeId;
  28162. c->destChannelIndex = destChannelIndex;
  28163. connections.add (c);
  28164. triggerAsyncUpdate();
  28165. return true;
  28166. }
  28167. void AudioProcessorGraph::removeConnection (const int index)
  28168. {
  28169. connections.remove (index);
  28170. triggerAsyncUpdate();
  28171. }
  28172. bool AudioProcessorGraph::removeConnection (const uint32 sourceNodeId, const int sourceChannelIndex,
  28173. const uint32 destNodeId, const int destChannelIndex)
  28174. {
  28175. bool doneAnything = false;
  28176. for (int i = connections.size(); --i >= 0;)
  28177. {
  28178. const Connection* const c = connections.getUnchecked(i);
  28179. if (c->sourceNodeId == sourceNodeId
  28180. && c->destNodeId == destNodeId
  28181. && c->sourceChannelIndex == sourceChannelIndex
  28182. && c->destChannelIndex == destChannelIndex)
  28183. {
  28184. removeConnection (i);
  28185. doneAnything = true;
  28186. triggerAsyncUpdate();
  28187. }
  28188. }
  28189. return doneAnything;
  28190. }
  28191. bool AudioProcessorGraph::disconnectNode (const uint32 nodeId)
  28192. {
  28193. bool doneAnything = false;
  28194. for (int i = connections.size(); --i >= 0;)
  28195. {
  28196. const Connection* const c = connections.getUnchecked(i);
  28197. if (c->sourceNodeId == nodeId || c->destNodeId == nodeId)
  28198. {
  28199. removeConnection (i);
  28200. doneAnything = true;
  28201. triggerAsyncUpdate();
  28202. }
  28203. }
  28204. return doneAnything;
  28205. }
  28206. bool AudioProcessorGraph::removeIllegalConnections()
  28207. {
  28208. bool doneAnything = false;
  28209. for (int i = connections.size(); --i >= 0;)
  28210. {
  28211. const Connection* const c = connections.getUnchecked(i);
  28212. const Node* const source = getNodeForId (c->sourceNodeId);
  28213. const Node* const dest = getNodeForId (c->destNodeId);
  28214. if (source == 0 || dest == 0
  28215. || (c->sourceChannelIndex != midiChannelIndex
  28216. && (((unsigned int) c->sourceChannelIndex) >= (unsigned int) source->processor->getNumOutputChannels()))
  28217. || (c->sourceChannelIndex == midiChannelIndex
  28218. && ! source->processor->producesMidi())
  28219. || (c->destChannelIndex != midiChannelIndex
  28220. && (((unsigned int) c->destChannelIndex) >= (unsigned int) dest->processor->getNumInputChannels()))
  28221. || (c->destChannelIndex == midiChannelIndex
  28222. && ! dest->processor->acceptsMidi()))
  28223. {
  28224. removeConnection (i);
  28225. doneAnything = true;
  28226. triggerAsyncUpdate();
  28227. }
  28228. }
  28229. return doneAnything;
  28230. }
  28231. namespace GraphRenderingOps
  28232. {
  28233. class AudioGraphRenderingOp
  28234. {
  28235. public:
  28236. AudioGraphRenderingOp() {}
  28237. virtual ~AudioGraphRenderingOp() {}
  28238. virtual void perform (AudioSampleBuffer& sharedBufferChans,
  28239. const OwnedArray <MidiBuffer>& sharedMidiBuffers,
  28240. const int numSamples) = 0;
  28241. juce_UseDebuggingNewOperator
  28242. };
  28243. class ClearChannelOp : public AudioGraphRenderingOp
  28244. {
  28245. public:
  28246. ClearChannelOp (const int channelNum_)
  28247. : channelNum (channelNum_)
  28248. {}
  28249. ~ClearChannelOp() {}
  28250. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>&, const int numSamples)
  28251. {
  28252. sharedBufferChans.clear (channelNum, 0, numSamples);
  28253. }
  28254. private:
  28255. const int channelNum;
  28256. ClearChannelOp (const ClearChannelOp&);
  28257. ClearChannelOp& operator= (const ClearChannelOp&);
  28258. };
  28259. class CopyChannelOp : public AudioGraphRenderingOp
  28260. {
  28261. public:
  28262. CopyChannelOp (const int srcChannelNum_, const int dstChannelNum_)
  28263. : srcChannelNum (srcChannelNum_),
  28264. dstChannelNum (dstChannelNum_)
  28265. {}
  28266. ~CopyChannelOp() {}
  28267. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>&, const int numSamples)
  28268. {
  28269. sharedBufferChans.copyFrom (dstChannelNum, 0, sharedBufferChans, srcChannelNum, 0, numSamples);
  28270. }
  28271. private:
  28272. const int srcChannelNum, dstChannelNum;
  28273. CopyChannelOp (const CopyChannelOp&);
  28274. CopyChannelOp& operator= (const CopyChannelOp&);
  28275. };
  28276. class AddChannelOp : public AudioGraphRenderingOp
  28277. {
  28278. public:
  28279. AddChannelOp (const int srcChannelNum_, const int dstChannelNum_)
  28280. : srcChannelNum (srcChannelNum_),
  28281. dstChannelNum (dstChannelNum_)
  28282. {}
  28283. ~AddChannelOp() {}
  28284. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>&, const int numSamples)
  28285. {
  28286. sharedBufferChans.addFrom (dstChannelNum, 0, sharedBufferChans, srcChannelNum, 0, numSamples);
  28287. }
  28288. private:
  28289. const int srcChannelNum, dstChannelNum;
  28290. AddChannelOp (const AddChannelOp&);
  28291. AddChannelOp& operator= (const AddChannelOp&);
  28292. };
  28293. class ClearMidiBufferOp : public AudioGraphRenderingOp
  28294. {
  28295. public:
  28296. ClearMidiBufferOp (const int bufferNum_)
  28297. : bufferNum (bufferNum_)
  28298. {}
  28299. ~ClearMidiBufferOp() {}
  28300. void perform (AudioSampleBuffer&, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int)
  28301. {
  28302. sharedMidiBuffers.getUnchecked (bufferNum)->clear();
  28303. }
  28304. private:
  28305. const int bufferNum;
  28306. ClearMidiBufferOp (const ClearMidiBufferOp&);
  28307. ClearMidiBufferOp& operator= (const ClearMidiBufferOp&);
  28308. };
  28309. class CopyMidiBufferOp : public AudioGraphRenderingOp
  28310. {
  28311. public:
  28312. CopyMidiBufferOp (const int srcBufferNum_, const int dstBufferNum_)
  28313. : srcBufferNum (srcBufferNum_),
  28314. dstBufferNum (dstBufferNum_)
  28315. {}
  28316. ~CopyMidiBufferOp() {}
  28317. void perform (AudioSampleBuffer&, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int)
  28318. {
  28319. *sharedMidiBuffers.getUnchecked (dstBufferNum) = *sharedMidiBuffers.getUnchecked (srcBufferNum);
  28320. }
  28321. private:
  28322. const int srcBufferNum, dstBufferNum;
  28323. CopyMidiBufferOp (const CopyMidiBufferOp&);
  28324. CopyMidiBufferOp& operator= (const CopyMidiBufferOp&);
  28325. };
  28326. class AddMidiBufferOp : public AudioGraphRenderingOp
  28327. {
  28328. public:
  28329. AddMidiBufferOp (const int srcBufferNum_, const int dstBufferNum_)
  28330. : srcBufferNum (srcBufferNum_),
  28331. dstBufferNum (dstBufferNum_)
  28332. {}
  28333. ~AddMidiBufferOp() {}
  28334. void perform (AudioSampleBuffer&, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int numSamples)
  28335. {
  28336. sharedMidiBuffers.getUnchecked (dstBufferNum)
  28337. ->addEvents (*sharedMidiBuffers.getUnchecked (srcBufferNum), 0, numSamples, 0);
  28338. }
  28339. private:
  28340. const int srcBufferNum, dstBufferNum;
  28341. AddMidiBufferOp (const AddMidiBufferOp&);
  28342. AddMidiBufferOp& operator= (const AddMidiBufferOp&);
  28343. };
  28344. class ProcessBufferOp : public AudioGraphRenderingOp
  28345. {
  28346. public:
  28347. ProcessBufferOp (const AudioProcessorGraph::Node::Ptr& node_,
  28348. const Array <int>& audioChannelsToUse_,
  28349. const int totalChans_,
  28350. const int midiBufferToUse_)
  28351. : node (node_),
  28352. processor (node_->processor),
  28353. audioChannelsToUse (audioChannelsToUse_),
  28354. totalChans (jmax (1, totalChans_)),
  28355. midiBufferToUse (midiBufferToUse_)
  28356. {
  28357. channels.calloc (totalChans);
  28358. while (audioChannelsToUse.size() < totalChans)
  28359. audioChannelsToUse.add (0);
  28360. }
  28361. ~ProcessBufferOp()
  28362. {
  28363. }
  28364. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int numSamples)
  28365. {
  28366. for (int i = totalChans; --i >= 0;)
  28367. channels[i] = sharedBufferChans.getSampleData (audioChannelsToUse.getUnchecked (i), 0);
  28368. AudioSampleBuffer buffer (channels, totalChans, numSamples);
  28369. processor->processBlock (buffer, *sharedMidiBuffers.getUnchecked (midiBufferToUse));
  28370. }
  28371. const AudioProcessorGraph::Node::Ptr node;
  28372. AudioProcessor* const processor;
  28373. private:
  28374. Array <int> audioChannelsToUse;
  28375. HeapBlock <float*> channels;
  28376. int totalChans;
  28377. int midiBufferToUse;
  28378. ProcessBufferOp (const ProcessBufferOp&);
  28379. ProcessBufferOp& operator= (const ProcessBufferOp&);
  28380. };
  28381. class RenderingOpSequenceCalculator
  28382. {
  28383. public:
  28384. RenderingOpSequenceCalculator (AudioProcessorGraph& graph_,
  28385. const VoidArray& orderedNodes_,
  28386. VoidArray& renderingOps)
  28387. : graph (graph_),
  28388. orderedNodes (orderedNodes_)
  28389. {
  28390. nodeIds.add (-2); // first buffer is read-only zeros
  28391. channels.add (0);
  28392. midiNodeIds.add (-2);
  28393. for (int i = 0; i < orderedNodes.size(); ++i)
  28394. {
  28395. createRenderingOpsForNode ((AudioProcessorGraph::Node*) orderedNodes.getUnchecked(i),
  28396. renderingOps, i);
  28397. markAnyUnusedBuffersAsFree (i);
  28398. }
  28399. }
  28400. int getNumBuffersNeeded() const { return nodeIds.size(); }
  28401. int getNumMidiBuffersNeeded() const { return midiNodeIds.size(); }
  28402. juce_UseDebuggingNewOperator
  28403. private:
  28404. AudioProcessorGraph& graph;
  28405. const VoidArray& orderedNodes;
  28406. Array <int> nodeIds, channels, midiNodeIds;
  28407. void createRenderingOpsForNode (AudioProcessorGraph::Node* const node,
  28408. VoidArray& renderingOps,
  28409. const int ourRenderingIndex)
  28410. {
  28411. const int numIns = node->processor->getNumInputChannels();
  28412. const int numOuts = node->processor->getNumOutputChannels();
  28413. const int totalChans = jmax (numIns, numOuts);
  28414. Array <int> audioChannelsToUse;
  28415. int midiBufferToUse = -1;
  28416. for (int inputChan = 0; inputChan < numIns; ++inputChan)
  28417. {
  28418. // get a list of all the inputs to this node
  28419. Array <int> sourceNodes, sourceOutputChans;
  28420. for (int i = graph.getNumConnections(); --i >= 0;)
  28421. {
  28422. const AudioProcessorGraph::Connection* const c = graph.getConnection (i);
  28423. if (c->destNodeId == node->id && c->destChannelIndex == inputChan)
  28424. {
  28425. sourceNodes.add (c->sourceNodeId);
  28426. sourceOutputChans.add (c->sourceChannelIndex);
  28427. }
  28428. }
  28429. int bufIndex = -1;
  28430. if (sourceNodes.size() == 0)
  28431. {
  28432. // unconnected input channel
  28433. if (inputChan >= numOuts)
  28434. {
  28435. bufIndex = getReadOnlyEmptyBuffer();
  28436. jassert (bufIndex >= 0);
  28437. }
  28438. else
  28439. {
  28440. bufIndex = getFreeBuffer (false);
  28441. renderingOps.add (new ClearChannelOp (bufIndex));
  28442. }
  28443. }
  28444. else if (sourceNodes.size() == 1)
  28445. {
  28446. // channel with a straightforward single input..
  28447. const int srcNode = sourceNodes.getUnchecked(0);
  28448. const int srcChan = sourceOutputChans.getUnchecked(0);
  28449. bufIndex = getBufferContaining (srcNode, srcChan);
  28450. if (bufIndex < 0)
  28451. {
  28452. // if not found, this is probably a feedback loop
  28453. bufIndex = getReadOnlyEmptyBuffer();
  28454. jassert (bufIndex >= 0);
  28455. }
  28456. if (inputChan < numOuts
  28457. && isBufferNeededLater (ourRenderingIndex,
  28458. inputChan,
  28459. srcNode, srcChan))
  28460. {
  28461. // can't mess up this channel because it's needed later by another node, so we
  28462. // need to use a copy of it..
  28463. const int newFreeBuffer = getFreeBuffer (false);
  28464. renderingOps.add (new CopyChannelOp (bufIndex, newFreeBuffer));
  28465. bufIndex = newFreeBuffer;
  28466. }
  28467. }
  28468. else
  28469. {
  28470. // channel with a mix of several inputs..
  28471. // try to find a re-usable channel from our inputs..
  28472. int reusableInputIndex = -1;
  28473. for (int i = 0; i < sourceNodes.size(); ++i)
  28474. {
  28475. const int sourceBufIndex = getBufferContaining (sourceNodes.getUnchecked(i),
  28476. sourceOutputChans.getUnchecked(i));
  28477. if (sourceBufIndex >= 0
  28478. && ! isBufferNeededLater (ourRenderingIndex,
  28479. inputChan,
  28480. sourceNodes.getUnchecked(i),
  28481. sourceOutputChans.getUnchecked(i)))
  28482. {
  28483. // we've found one of our input chans that can be re-used..
  28484. reusableInputIndex = i;
  28485. bufIndex = sourceBufIndex;
  28486. break;
  28487. }
  28488. }
  28489. if (reusableInputIndex < 0)
  28490. {
  28491. // can't re-use any of our input chans, so get a new one and copy everything into it..
  28492. bufIndex = getFreeBuffer (false);
  28493. jassert (bufIndex != 0);
  28494. const int srcIndex = getBufferContaining (sourceNodes.getUnchecked (0),
  28495. sourceOutputChans.getUnchecked (0));
  28496. if (srcIndex < 0)
  28497. {
  28498. // if not found, this is probably a feedback loop
  28499. renderingOps.add (new ClearChannelOp (bufIndex));
  28500. }
  28501. else
  28502. {
  28503. renderingOps.add (new CopyChannelOp (srcIndex, bufIndex));
  28504. }
  28505. reusableInputIndex = 0;
  28506. }
  28507. for (int j = 0; j < sourceNodes.size(); ++j)
  28508. {
  28509. if (j != reusableInputIndex)
  28510. {
  28511. const int srcIndex = getBufferContaining (sourceNodes.getUnchecked(j),
  28512. sourceOutputChans.getUnchecked(j));
  28513. if (srcIndex >= 0)
  28514. renderingOps.add (new AddChannelOp (srcIndex, bufIndex));
  28515. }
  28516. }
  28517. }
  28518. jassert (bufIndex >= 0);
  28519. audioChannelsToUse.add (bufIndex);
  28520. if (inputChan < numOuts)
  28521. markBufferAsContaining (bufIndex, node->id, inputChan);
  28522. }
  28523. for (int outputChan = numIns; outputChan < numOuts; ++outputChan)
  28524. {
  28525. const int bufIndex = getFreeBuffer (false);
  28526. jassert (bufIndex != 0);
  28527. audioChannelsToUse.add (bufIndex);
  28528. markBufferAsContaining (bufIndex, node->id, outputChan);
  28529. }
  28530. // Now the same thing for midi..
  28531. Array <int> midiSourceNodes;
  28532. for (int i = graph.getNumConnections(); --i >= 0;)
  28533. {
  28534. const AudioProcessorGraph::Connection* const c = graph.getConnection (i);
  28535. if (c->destNodeId == node->id && c->destChannelIndex == AudioProcessorGraph::midiChannelIndex)
  28536. midiSourceNodes.add (c->sourceNodeId);
  28537. }
  28538. if (midiSourceNodes.size() == 0)
  28539. {
  28540. // No midi inputs..
  28541. midiBufferToUse = getFreeBuffer (true); // need to pick a buffer even if the processor doesn't use midi
  28542. if (node->processor->acceptsMidi() || node->processor->producesMidi())
  28543. renderingOps.add (new ClearMidiBufferOp (midiBufferToUse));
  28544. }
  28545. else if (midiSourceNodes.size() == 1)
  28546. {
  28547. // One midi input..
  28548. midiBufferToUse = getBufferContaining (midiSourceNodes.getUnchecked(0),
  28549. AudioProcessorGraph::midiChannelIndex);
  28550. if (midiBufferToUse >= 0)
  28551. {
  28552. if (isBufferNeededLater (ourRenderingIndex,
  28553. AudioProcessorGraph::midiChannelIndex,
  28554. midiSourceNodes.getUnchecked(0),
  28555. AudioProcessorGraph::midiChannelIndex))
  28556. {
  28557. // can't mess up this channel because it's needed later by another node, so we
  28558. // need to use a copy of it..
  28559. const int newFreeBuffer = getFreeBuffer (true);
  28560. renderingOps.add (new CopyMidiBufferOp (midiBufferToUse, newFreeBuffer));
  28561. midiBufferToUse = newFreeBuffer;
  28562. }
  28563. }
  28564. else
  28565. {
  28566. // probably a feedback loop, so just use an empty one..
  28567. midiBufferToUse = getFreeBuffer (true); // need to pick a buffer even if the processor doesn't use midi
  28568. }
  28569. }
  28570. else
  28571. {
  28572. // More than one midi input being mixed..
  28573. int reusableInputIndex = -1;
  28574. for (int i = 0; i < midiSourceNodes.size(); ++i)
  28575. {
  28576. const int sourceBufIndex = getBufferContaining (midiSourceNodes.getUnchecked(i),
  28577. AudioProcessorGraph::midiChannelIndex);
  28578. if (sourceBufIndex >= 0
  28579. && ! isBufferNeededLater (ourRenderingIndex,
  28580. AudioProcessorGraph::midiChannelIndex,
  28581. midiSourceNodes.getUnchecked(i),
  28582. AudioProcessorGraph::midiChannelIndex))
  28583. {
  28584. // we've found one of our input buffers that can be re-used..
  28585. reusableInputIndex = i;
  28586. midiBufferToUse = sourceBufIndex;
  28587. break;
  28588. }
  28589. }
  28590. if (reusableInputIndex < 0)
  28591. {
  28592. // can't re-use any of our input buffers, so get a new one and copy everything into it..
  28593. midiBufferToUse = getFreeBuffer (true);
  28594. jassert (midiBufferToUse >= 0);
  28595. const int srcIndex = getBufferContaining (midiSourceNodes.getUnchecked(0),
  28596. AudioProcessorGraph::midiChannelIndex);
  28597. if (srcIndex >= 0)
  28598. renderingOps.add (new CopyMidiBufferOp (srcIndex, midiBufferToUse));
  28599. else
  28600. renderingOps.add (new ClearMidiBufferOp (midiBufferToUse));
  28601. reusableInputIndex = 0;
  28602. }
  28603. for (int j = 0; j < midiSourceNodes.size(); ++j)
  28604. {
  28605. if (j != reusableInputIndex)
  28606. {
  28607. const int srcIndex = getBufferContaining (midiSourceNodes.getUnchecked(j),
  28608. AudioProcessorGraph::midiChannelIndex);
  28609. if (srcIndex >= 0)
  28610. renderingOps.add (new AddMidiBufferOp (srcIndex, midiBufferToUse));
  28611. }
  28612. }
  28613. }
  28614. if (node->processor->producesMidi())
  28615. markBufferAsContaining (midiBufferToUse, node->id,
  28616. AudioProcessorGraph::midiChannelIndex);
  28617. renderingOps.add (new ProcessBufferOp (node, audioChannelsToUse,
  28618. totalChans, midiBufferToUse));
  28619. }
  28620. int getFreeBuffer (const bool forMidi)
  28621. {
  28622. if (forMidi)
  28623. {
  28624. for (int i = 1; i < midiNodeIds.size(); ++i)
  28625. if (midiNodeIds.getUnchecked(i) < 0)
  28626. return i;
  28627. midiNodeIds.add (-1);
  28628. return midiNodeIds.size() - 1;
  28629. }
  28630. else
  28631. {
  28632. for (int i = 1; i < nodeIds.size(); ++i)
  28633. if (nodeIds.getUnchecked(i) < 0)
  28634. return i;
  28635. nodeIds.add (-1);
  28636. channels.add (0);
  28637. return nodeIds.size() - 1;
  28638. }
  28639. }
  28640. int getReadOnlyEmptyBuffer() const
  28641. {
  28642. return 0;
  28643. }
  28644. int getBufferContaining (const int nodeId, const int outputChannel) const
  28645. {
  28646. if (outputChannel == AudioProcessorGraph::midiChannelIndex)
  28647. {
  28648. for (int i = midiNodeIds.size(); --i >= 0;)
  28649. if (midiNodeIds.getUnchecked(i) == nodeId)
  28650. return i;
  28651. }
  28652. else
  28653. {
  28654. for (int i = nodeIds.size(); --i >= 0;)
  28655. if (nodeIds.getUnchecked(i) == nodeId
  28656. && channels.getUnchecked(i) == outputChannel)
  28657. return i;
  28658. }
  28659. return -1;
  28660. }
  28661. void markAnyUnusedBuffersAsFree (const int stepIndex)
  28662. {
  28663. int i;
  28664. for (i = 0; i < nodeIds.size(); ++i)
  28665. {
  28666. if (nodeIds.getUnchecked(i) >= 0
  28667. && ! isBufferNeededLater (stepIndex, -1,
  28668. nodeIds.getUnchecked(i),
  28669. channels.getUnchecked(i)))
  28670. {
  28671. nodeIds.set (i, -1);
  28672. }
  28673. }
  28674. for (i = 0; i < midiNodeIds.size(); ++i)
  28675. {
  28676. if (midiNodeIds.getUnchecked(i) >= 0
  28677. && ! isBufferNeededLater (stepIndex, -1,
  28678. midiNodeIds.getUnchecked(i),
  28679. AudioProcessorGraph::midiChannelIndex))
  28680. {
  28681. midiNodeIds.set (i, -1);
  28682. }
  28683. }
  28684. }
  28685. bool isBufferNeededLater (int stepIndexToSearchFrom,
  28686. int inputChannelOfIndexToIgnore,
  28687. const int nodeId,
  28688. const int outputChanIndex) const
  28689. {
  28690. while (stepIndexToSearchFrom < orderedNodes.size())
  28691. {
  28692. const AudioProcessorGraph::Node* const node = (const AudioProcessorGraph::Node*) orderedNodes.getUnchecked (stepIndexToSearchFrom);
  28693. if (outputChanIndex == AudioProcessorGraph::midiChannelIndex)
  28694. {
  28695. if (inputChannelOfIndexToIgnore != AudioProcessorGraph::midiChannelIndex
  28696. && graph.getConnectionBetween (nodeId, AudioProcessorGraph::midiChannelIndex,
  28697. node->id, AudioProcessorGraph::midiChannelIndex) != 0)
  28698. return true;
  28699. }
  28700. else
  28701. {
  28702. for (int i = 0; i < node->processor->getNumInputChannels(); ++i)
  28703. if (i != inputChannelOfIndexToIgnore
  28704. && graph.getConnectionBetween (nodeId, outputChanIndex,
  28705. node->id, i) != 0)
  28706. return true;
  28707. }
  28708. inputChannelOfIndexToIgnore = -1;
  28709. ++stepIndexToSearchFrom;
  28710. }
  28711. return false;
  28712. }
  28713. void markBufferAsContaining (int bufferNum, int nodeId, int outputIndex)
  28714. {
  28715. if (outputIndex == AudioProcessorGraph::midiChannelIndex)
  28716. {
  28717. jassert (bufferNum > 0 && bufferNum < midiNodeIds.size());
  28718. midiNodeIds.set (bufferNum, nodeId);
  28719. }
  28720. else
  28721. {
  28722. jassert (bufferNum >= 0 && bufferNum < nodeIds.size());
  28723. nodeIds.set (bufferNum, nodeId);
  28724. channels.set (bufferNum, outputIndex);
  28725. }
  28726. }
  28727. RenderingOpSequenceCalculator (const RenderingOpSequenceCalculator&);
  28728. RenderingOpSequenceCalculator& operator= (const RenderingOpSequenceCalculator&);
  28729. };
  28730. }
  28731. void AudioProcessorGraph::clearRenderingSequence()
  28732. {
  28733. const ScopedLock sl (renderLock);
  28734. for (int i = renderingOps.size(); --i >= 0;)
  28735. {
  28736. GraphRenderingOps::AudioGraphRenderingOp* const r
  28737. = (GraphRenderingOps::AudioGraphRenderingOp*) renderingOps.getUnchecked(i);
  28738. renderingOps.remove (i);
  28739. delete r;
  28740. }
  28741. }
  28742. bool AudioProcessorGraph::isAnInputTo (const uint32 possibleInputId,
  28743. const uint32 possibleDestinationId,
  28744. const int recursionCheck) const
  28745. {
  28746. if (recursionCheck > 0)
  28747. {
  28748. for (int i = connections.size(); --i >= 0;)
  28749. {
  28750. const AudioProcessorGraph::Connection* const c = connections.getUnchecked (i);
  28751. if (c->destNodeId == possibleDestinationId
  28752. && (c->sourceNodeId == possibleInputId
  28753. || isAnInputTo (possibleInputId, c->sourceNodeId, recursionCheck - 1)))
  28754. return true;
  28755. }
  28756. }
  28757. return false;
  28758. }
  28759. void AudioProcessorGraph::buildRenderingSequence()
  28760. {
  28761. VoidArray newRenderingOps;
  28762. int numRenderingBuffersNeeded = 2;
  28763. int numMidiBuffersNeeded = 1;
  28764. {
  28765. MessageManagerLock mml;
  28766. VoidArray orderedNodes;
  28767. int i;
  28768. for (i = 0; i < nodes.size(); ++i)
  28769. {
  28770. Node* const node = nodes.getUnchecked(i);
  28771. node->prepare (getSampleRate(), getBlockSize(), this);
  28772. int j = 0;
  28773. for (; j < orderedNodes.size(); ++j)
  28774. if (isAnInputTo (node->id,
  28775. ((Node*) orderedNodes.getUnchecked (j))->id,
  28776. nodes.size() + 1))
  28777. break;
  28778. orderedNodes.insert (j, node);
  28779. }
  28780. GraphRenderingOps::RenderingOpSequenceCalculator calculator (*this, orderedNodes, newRenderingOps);
  28781. numRenderingBuffersNeeded = calculator.getNumBuffersNeeded();
  28782. numMidiBuffersNeeded = calculator.getNumMidiBuffersNeeded();
  28783. }
  28784. VoidArray oldRenderingOps (renderingOps);
  28785. {
  28786. // swap over to the new rendering sequence..
  28787. const ScopedLock sl (renderLock);
  28788. renderingBuffers.setSize (numRenderingBuffersNeeded, getBlockSize());
  28789. renderingBuffers.clear();
  28790. for (int i = midiBuffers.size(); --i >= 0;)
  28791. midiBuffers.getUnchecked(i)->clear();
  28792. while (midiBuffers.size() < numMidiBuffersNeeded)
  28793. midiBuffers.add (new MidiBuffer());
  28794. renderingOps = newRenderingOps;
  28795. }
  28796. for (int i = oldRenderingOps.size(); --i >= 0;)
  28797. delete (GraphRenderingOps::AudioGraphRenderingOp*) oldRenderingOps.getUnchecked(i);
  28798. }
  28799. void AudioProcessorGraph::handleAsyncUpdate()
  28800. {
  28801. buildRenderingSequence();
  28802. }
  28803. void AudioProcessorGraph::prepareToPlay (double /*sampleRate*/, int estimatedSamplesPerBlock)
  28804. {
  28805. currentAudioInputBuffer = 0;
  28806. currentAudioOutputBuffer.setSize (jmax (1, getNumOutputChannels()), estimatedSamplesPerBlock);
  28807. currentMidiInputBuffer = 0;
  28808. currentMidiOutputBuffer.clear();
  28809. clearRenderingSequence();
  28810. buildRenderingSequence();
  28811. }
  28812. void AudioProcessorGraph::releaseResources()
  28813. {
  28814. for (int i = 0; i < nodes.size(); ++i)
  28815. nodes.getUnchecked(i)->unprepare();
  28816. renderingBuffers.setSize (1, 1);
  28817. midiBuffers.clear();
  28818. currentAudioInputBuffer = 0;
  28819. currentAudioOutputBuffer.setSize (1, 1);
  28820. currentMidiInputBuffer = 0;
  28821. currentMidiOutputBuffer.clear();
  28822. }
  28823. void AudioProcessorGraph::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
  28824. {
  28825. const int numSamples = buffer.getNumSamples();
  28826. const ScopedLock sl (renderLock);
  28827. currentAudioInputBuffer = &buffer;
  28828. currentAudioOutputBuffer.setSize (jmax (1, buffer.getNumChannels()), numSamples);
  28829. currentAudioOutputBuffer.clear();
  28830. currentMidiInputBuffer = &midiMessages;
  28831. currentMidiOutputBuffer.clear();
  28832. int i;
  28833. for (i = 0; i < renderingOps.size(); ++i)
  28834. {
  28835. GraphRenderingOps::AudioGraphRenderingOp* const op
  28836. = (GraphRenderingOps::AudioGraphRenderingOp*) renderingOps.getUnchecked(i);
  28837. op->perform (renderingBuffers, midiBuffers, numSamples);
  28838. }
  28839. for (i = 0; i < buffer.getNumChannels(); ++i)
  28840. buffer.copyFrom (i, 0, currentAudioOutputBuffer, i, 0, numSamples);
  28841. midiMessages.clear();
  28842. midiMessages.addEvents (currentMidiOutputBuffer, 0, buffer.getNumSamples(), 0);
  28843. }
  28844. const String AudioProcessorGraph::getInputChannelName (const int channelIndex) const
  28845. {
  28846. return "Input " + String (channelIndex + 1);
  28847. }
  28848. const String AudioProcessorGraph::getOutputChannelName (const int channelIndex) const
  28849. {
  28850. return "Output " + String (channelIndex + 1);
  28851. }
  28852. bool AudioProcessorGraph::isInputChannelStereoPair (int /*index*/) const
  28853. {
  28854. return true;
  28855. }
  28856. bool AudioProcessorGraph::isOutputChannelStereoPair (int /*index*/) const
  28857. {
  28858. return true;
  28859. }
  28860. bool AudioProcessorGraph::acceptsMidi() const
  28861. {
  28862. return true;
  28863. }
  28864. bool AudioProcessorGraph::producesMidi() const
  28865. {
  28866. return true;
  28867. }
  28868. void AudioProcessorGraph::getStateInformation (JUCE_NAMESPACE::MemoryBlock& /*destData*/)
  28869. {
  28870. }
  28871. void AudioProcessorGraph::setStateInformation (const void* /*data*/, int /*sizeInBytes*/)
  28872. {
  28873. }
  28874. AudioProcessorGraph::AudioGraphIOProcessor::AudioGraphIOProcessor (const IODeviceType type_)
  28875. : type (type_),
  28876. graph (0)
  28877. {
  28878. }
  28879. AudioProcessorGraph::AudioGraphIOProcessor::~AudioGraphIOProcessor()
  28880. {
  28881. }
  28882. const String AudioProcessorGraph::AudioGraphIOProcessor::getName() const
  28883. {
  28884. switch (type)
  28885. {
  28886. case audioOutputNode:
  28887. return "Audio Output";
  28888. case audioInputNode:
  28889. return "Audio Input";
  28890. case midiOutputNode:
  28891. return "Midi Output";
  28892. case midiInputNode:
  28893. return "Midi Input";
  28894. default:
  28895. break;
  28896. }
  28897. return String::empty;
  28898. }
  28899. void AudioProcessorGraph::AudioGraphIOProcessor::fillInPluginDescription (PluginDescription& d) const
  28900. {
  28901. d.name = getName();
  28902. d.uid = d.name.hashCode();
  28903. d.category = "I/O devices";
  28904. d.pluginFormatName = "Internal";
  28905. d.manufacturerName = "Raw Material Software";
  28906. d.version = "1.0";
  28907. d.isInstrument = false;
  28908. d.numInputChannels = getNumInputChannels();
  28909. if (type == audioOutputNode && graph != 0)
  28910. d.numInputChannels = graph->getNumInputChannels();
  28911. d.numOutputChannels = getNumOutputChannels();
  28912. if (type == audioInputNode && graph != 0)
  28913. d.numOutputChannels = graph->getNumOutputChannels();
  28914. }
  28915. void AudioProcessorGraph::AudioGraphIOProcessor::prepareToPlay (double, int)
  28916. {
  28917. jassert (graph != 0);
  28918. }
  28919. void AudioProcessorGraph::AudioGraphIOProcessor::releaseResources()
  28920. {
  28921. }
  28922. void AudioProcessorGraph::AudioGraphIOProcessor::processBlock (AudioSampleBuffer& buffer,
  28923. MidiBuffer& midiMessages)
  28924. {
  28925. jassert (graph != 0);
  28926. switch (type)
  28927. {
  28928. case audioOutputNode:
  28929. {
  28930. for (int i = jmin (graph->currentAudioOutputBuffer.getNumChannels(),
  28931. buffer.getNumChannels()); --i >= 0;)
  28932. {
  28933. graph->currentAudioOutputBuffer.addFrom (i, 0, buffer, i, 0, buffer.getNumSamples());
  28934. }
  28935. break;
  28936. }
  28937. case audioInputNode:
  28938. {
  28939. for (int i = jmin (graph->currentAudioInputBuffer->getNumChannels(),
  28940. buffer.getNumChannels()); --i >= 0;)
  28941. {
  28942. buffer.copyFrom (i, 0, *graph->currentAudioInputBuffer, i, 0, buffer.getNumSamples());
  28943. }
  28944. break;
  28945. }
  28946. case midiOutputNode:
  28947. graph->currentMidiOutputBuffer.addEvents (midiMessages, 0, buffer.getNumSamples(), 0);
  28948. break;
  28949. case midiInputNode:
  28950. midiMessages.addEvents (*graph->currentMidiInputBuffer, 0, buffer.getNumSamples(), 0);
  28951. break;
  28952. default:
  28953. break;
  28954. }
  28955. }
  28956. bool AudioProcessorGraph::AudioGraphIOProcessor::acceptsMidi() const
  28957. {
  28958. return type == midiOutputNode;
  28959. }
  28960. bool AudioProcessorGraph::AudioGraphIOProcessor::producesMidi() const
  28961. {
  28962. return type == midiInputNode;
  28963. }
  28964. const String AudioProcessorGraph::AudioGraphIOProcessor::getInputChannelName (const int channelIndex) const
  28965. {
  28966. switch (type)
  28967. {
  28968. case audioOutputNode:
  28969. return "Output " + String (channelIndex + 1);
  28970. case midiOutputNode:
  28971. return "Midi Output";
  28972. default:
  28973. break;
  28974. }
  28975. return String::empty;
  28976. }
  28977. const String AudioProcessorGraph::AudioGraphIOProcessor::getOutputChannelName (const int channelIndex) const
  28978. {
  28979. switch (type)
  28980. {
  28981. case audioInputNode:
  28982. return "Input " + String (channelIndex + 1);
  28983. case midiInputNode:
  28984. return "Midi Input";
  28985. default:
  28986. break;
  28987. }
  28988. return String::empty;
  28989. }
  28990. bool AudioProcessorGraph::AudioGraphIOProcessor::isInputChannelStereoPair (int /*index*/) const
  28991. {
  28992. return type == audioInputNode || type == audioOutputNode;
  28993. }
  28994. bool AudioProcessorGraph::AudioGraphIOProcessor::isOutputChannelStereoPair (int index) const
  28995. {
  28996. return isInputChannelStereoPair (index);
  28997. }
  28998. bool AudioProcessorGraph::AudioGraphIOProcessor::isInput() const
  28999. {
  29000. return type == audioInputNode || type == midiInputNode;
  29001. }
  29002. bool AudioProcessorGraph::AudioGraphIOProcessor::isOutput() const
  29003. {
  29004. return type == audioOutputNode || type == midiOutputNode;
  29005. }
  29006. AudioProcessorEditor* AudioProcessorGraph::AudioGraphIOProcessor::createEditor()
  29007. {
  29008. return 0;
  29009. }
  29010. int AudioProcessorGraph::AudioGraphIOProcessor::getNumParameters() { return 0; }
  29011. const String AudioProcessorGraph::AudioGraphIOProcessor::getParameterName (int) { return String::empty; }
  29012. float AudioProcessorGraph::AudioGraphIOProcessor::getParameter (int) { return 0.0f; }
  29013. const String AudioProcessorGraph::AudioGraphIOProcessor::getParameterText (int) { return String::empty; }
  29014. void AudioProcessorGraph::AudioGraphIOProcessor::setParameter (int, float) { }
  29015. int AudioProcessorGraph::AudioGraphIOProcessor::getNumPrograms() { return 0; }
  29016. int AudioProcessorGraph::AudioGraphIOProcessor::getCurrentProgram() { return 0; }
  29017. void AudioProcessorGraph::AudioGraphIOProcessor::setCurrentProgram (int) { }
  29018. const String AudioProcessorGraph::AudioGraphIOProcessor::getProgramName (int) { return String::empty; }
  29019. void AudioProcessorGraph::AudioGraphIOProcessor::changeProgramName (int, const String&) { }
  29020. void AudioProcessorGraph::AudioGraphIOProcessor::getStateInformation (JUCE_NAMESPACE::MemoryBlock&)
  29021. {
  29022. }
  29023. void AudioProcessorGraph::AudioGraphIOProcessor::setStateInformation (const void*, int)
  29024. {
  29025. }
  29026. void AudioProcessorGraph::AudioGraphIOProcessor::setParentGraph (AudioProcessorGraph* const newGraph)
  29027. {
  29028. graph = newGraph;
  29029. if (graph != 0)
  29030. {
  29031. setPlayConfigDetails (type == audioOutputNode ? graph->getNumOutputChannels() : 0,
  29032. type == audioInputNode ? graph->getNumInputChannels() : 0,
  29033. getSampleRate(),
  29034. getBlockSize());
  29035. updateHostDisplay();
  29036. }
  29037. }
  29038. END_JUCE_NAMESPACE
  29039. /*** End of inlined file: juce_AudioProcessorGraph.cpp ***/
  29040. /*** Start of inlined file: juce_AudioProcessorPlayer.cpp ***/
  29041. BEGIN_JUCE_NAMESPACE
  29042. AudioProcessorPlayer::AudioProcessorPlayer()
  29043. : processor (0),
  29044. sampleRate (0),
  29045. blockSize (0),
  29046. isPrepared (false),
  29047. numInputChans (0),
  29048. numOutputChans (0),
  29049. tempBuffer (1, 1)
  29050. {
  29051. }
  29052. AudioProcessorPlayer::~AudioProcessorPlayer()
  29053. {
  29054. setProcessor (0);
  29055. }
  29056. void AudioProcessorPlayer::setProcessor (AudioProcessor* const processorToPlay)
  29057. {
  29058. if (processor != processorToPlay)
  29059. {
  29060. if (processorToPlay != 0 && sampleRate > 0 && blockSize > 0)
  29061. {
  29062. processorToPlay->setPlayConfigDetails (numInputChans, numOutputChans,
  29063. sampleRate, blockSize);
  29064. processorToPlay->prepareToPlay (sampleRate, blockSize);
  29065. }
  29066. AudioProcessor* oldOne;
  29067. {
  29068. const ScopedLock sl (lock);
  29069. oldOne = isPrepared ? processor : 0;
  29070. processor = processorToPlay;
  29071. isPrepared = true;
  29072. }
  29073. if (oldOne != 0)
  29074. oldOne->releaseResources();
  29075. }
  29076. }
  29077. void AudioProcessorPlayer::audioDeviceIOCallback (const float** inputChannelData,
  29078. int numInputChannels,
  29079. float** outputChannelData,
  29080. int numOutputChannels,
  29081. int numSamples)
  29082. {
  29083. // these should have been prepared by audioDeviceAboutToStart()...
  29084. jassert (sampleRate > 0 && blockSize > 0);
  29085. incomingMidi.clear();
  29086. messageCollector.removeNextBlockOfMessages (incomingMidi, numSamples);
  29087. int i, totalNumChans = 0;
  29088. if (numInputChannels > numOutputChannels)
  29089. {
  29090. // if there aren't enough output channels for the number of
  29091. // inputs, we need to create some temporary extra ones (can't
  29092. // use the input data in case it gets written to)
  29093. tempBuffer.setSize (numInputChannels - numOutputChannels, numSamples,
  29094. false, false, true);
  29095. for (i = 0; i < numOutputChannels; ++i)
  29096. {
  29097. channels[totalNumChans] = outputChannelData[i];
  29098. memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * numSamples);
  29099. ++totalNumChans;
  29100. }
  29101. for (i = numOutputChannels; i < numInputChannels; ++i)
  29102. {
  29103. channels[totalNumChans] = tempBuffer.getSampleData (i - numOutputChannels, 0);
  29104. memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * numSamples);
  29105. ++totalNumChans;
  29106. }
  29107. }
  29108. else
  29109. {
  29110. for (i = 0; i < numInputChannels; ++i)
  29111. {
  29112. channels[totalNumChans] = outputChannelData[i];
  29113. memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * numSamples);
  29114. ++totalNumChans;
  29115. }
  29116. for (i = numInputChannels; i < numOutputChannels; ++i)
  29117. {
  29118. channels[totalNumChans] = outputChannelData[i];
  29119. zeromem (channels[totalNumChans], sizeof (float) * numSamples);
  29120. ++totalNumChans;
  29121. }
  29122. }
  29123. AudioSampleBuffer buffer (channels, totalNumChans, numSamples);
  29124. const ScopedLock sl (lock);
  29125. if (processor != 0)
  29126. processor->processBlock (buffer, incomingMidi);
  29127. }
  29128. void AudioProcessorPlayer::audioDeviceAboutToStart (AudioIODevice* device)
  29129. {
  29130. const ScopedLock sl (lock);
  29131. sampleRate = device->getCurrentSampleRate();
  29132. blockSize = device->getCurrentBufferSizeSamples();
  29133. numInputChans = device->getActiveInputChannels().countNumberOfSetBits();
  29134. numOutputChans = device->getActiveOutputChannels().countNumberOfSetBits();
  29135. messageCollector.reset (sampleRate);
  29136. zeromem (channels, sizeof (channels));
  29137. if (processor != 0)
  29138. {
  29139. if (isPrepared)
  29140. processor->releaseResources();
  29141. AudioProcessor* const oldProcessor = processor;
  29142. setProcessor (0);
  29143. setProcessor (oldProcessor);
  29144. }
  29145. }
  29146. void AudioProcessorPlayer::audioDeviceStopped()
  29147. {
  29148. const ScopedLock sl (lock);
  29149. if (processor != 0 && isPrepared)
  29150. processor->releaseResources();
  29151. sampleRate = 0.0;
  29152. blockSize = 0;
  29153. isPrepared = false;
  29154. tempBuffer.setSize (1, 1);
  29155. }
  29156. void AudioProcessorPlayer::handleIncomingMidiMessage (MidiInput*, const MidiMessage& message)
  29157. {
  29158. messageCollector.addMessageToQueue (message);
  29159. }
  29160. END_JUCE_NAMESPACE
  29161. /*** End of inlined file: juce_AudioProcessorPlayer.cpp ***/
  29162. /*** Start of inlined file: juce_GenericAudioProcessorEditor.cpp ***/
  29163. BEGIN_JUCE_NAMESPACE
  29164. class ProcessorParameterPropertyComp : public PropertyComponent,
  29165. public AudioProcessorListener,
  29166. public AsyncUpdater
  29167. {
  29168. public:
  29169. ProcessorParameterPropertyComp (const String& name,
  29170. AudioProcessor* const owner_,
  29171. const int index_)
  29172. : PropertyComponent (name),
  29173. owner (owner_),
  29174. index (index_)
  29175. {
  29176. addAndMakeVisible (slider = new ParamSlider (owner_, index_));
  29177. owner_->addListener (this);
  29178. }
  29179. ~ProcessorParameterPropertyComp()
  29180. {
  29181. owner->removeListener (this);
  29182. deleteAllChildren();
  29183. }
  29184. void refresh()
  29185. {
  29186. slider->setValue (owner->getParameter (index), false);
  29187. }
  29188. void audioProcessorChanged (AudioProcessor*) {}
  29189. void audioProcessorParameterChanged (AudioProcessor*, int parameterIndex, float)
  29190. {
  29191. if (parameterIndex == index)
  29192. triggerAsyncUpdate();
  29193. }
  29194. void handleAsyncUpdate()
  29195. {
  29196. refresh();
  29197. }
  29198. juce_UseDebuggingNewOperator
  29199. private:
  29200. AudioProcessor* const owner;
  29201. const int index;
  29202. Slider* slider;
  29203. class ParamSlider : public Slider
  29204. {
  29205. public:
  29206. ParamSlider (AudioProcessor* const owner_, const int index_)
  29207. : Slider (String::empty),
  29208. owner (owner_),
  29209. index (index_)
  29210. {
  29211. setRange (0.0, 1.0, 0.0);
  29212. setSliderStyle (Slider::LinearBar);
  29213. setTextBoxIsEditable (false);
  29214. setScrollWheelEnabled (false);
  29215. }
  29216. ~ParamSlider()
  29217. {
  29218. }
  29219. void valueChanged()
  29220. {
  29221. const float newVal = (float) getValue();
  29222. if (owner->getParameter (index) != newVal)
  29223. owner->setParameter (index, newVal);
  29224. }
  29225. const String getTextFromValue (double /*value*/)
  29226. {
  29227. return owner->getParameterText (index);
  29228. }
  29229. juce_UseDebuggingNewOperator
  29230. private:
  29231. AudioProcessor* const owner;
  29232. const int index;
  29233. ParamSlider (const ParamSlider&);
  29234. ParamSlider& operator= (const ParamSlider&);
  29235. };
  29236. ProcessorParameterPropertyComp (const ProcessorParameterPropertyComp&);
  29237. ProcessorParameterPropertyComp& operator= (const ProcessorParameterPropertyComp&);
  29238. };
  29239. GenericAudioProcessorEditor::GenericAudioProcessorEditor (AudioProcessor* const owner_)
  29240. : AudioProcessorEditor (owner_)
  29241. {
  29242. setOpaque (true);
  29243. addAndMakeVisible (panel = new PropertyPanel());
  29244. Array <PropertyComponent*> params;
  29245. const int numParams = owner_->getNumParameters();
  29246. int totalHeight = 0;
  29247. for (int i = 0; i < numParams; ++i)
  29248. {
  29249. String name (owner_->getParameterName (i));
  29250. if (name.trim().isEmpty())
  29251. name = "Unnamed";
  29252. ProcessorParameterPropertyComp* const pc = new ProcessorParameterPropertyComp (name, owner_, i);
  29253. params.add (pc);
  29254. totalHeight += pc->getPreferredHeight();
  29255. }
  29256. panel->addProperties (params);
  29257. setSize (400, jlimit (25, 400, totalHeight));
  29258. }
  29259. GenericAudioProcessorEditor::~GenericAudioProcessorEditor()
  29260. {
  29261. deleteAllChildren();
  29262. }
  29263. void GenericAudioProcessorEditor::paint (Graphics& g)
  29264. {
  29265. g.fillAll (Colours::white);
  29266. }
  29267. void GenericAudioProcessorEditor::resized()
  29268. {
  29269. panel->setSize (getWidth(), getHeight());
  29270. }
  29271. END_JUCE_NAMESPACE
  29272. /*** End of inlined file: juce_GenericAudioProcessorEditor.cpp ***/
  29273. /*** Start of inlined file: juce_Sampler.cpp ***/
  29274. BEGIN_JUCE_NAMESPACE
  29275. SamplerSound::SamplerSound (const String& name_,
  29276. AudioFormatReader& source,
  29277. const BitArray& midiNotes_,
  29278. const int midiNoteForNormalPitch,
  29279. const double attackTimeSecs,
  29280. const double releaseTimeSecs,
  29281. const double maxSampleLengthSeconds)
  29282. : name (name_),
  29283. midiNotes (midiNotes_),
  29284. midiRootNote (midiNoteForNormalPitch)
  29285. {
  29286. sourceSampleRate = source.sampleRate;
  29287. if (sourceSampleRate <= 0 || source.lengthInSamples <= 0)
  29288. {
  29289. length = 0;
  29290. attackSamples = 0;
  29291. releaseSamples = 0;
  29292. }
  29293. else
  29294. {
  29295. length = jmin ((int) source.lengthInSamples,
  29296. (int) (maxSampleLengthSeconds * sourceSampleRate));
  29297. data = new AudioSampleBuffer (jmin (2, (int) source.numChannels), length + 4);
  29298. data->readFromAudioReader (&source, 0, length + 4, 0, true, true);
  29299. attackSamples = roundToInt (attackTimeSecs * sourceSampleRate);
  29300. releaseSamples = roundToInt (releaseTimeSecs * sourceSampleRate);
  29301. }
  29302. }
  29303. SamplerSound::~SamplerSound()
  29304. {
  29305. }
  29306. bool SamplerSound::appliesToNote (const int midiNoteNumber)
  29307. {
  29308. return midiNotes [midiNoteNumber];
  29309. }
  29310. bool SamplerSound::appliesToChannel (const int /*midiChannel*/)
  29311. {
  29312. return true;
  29313. }
  29314. SamplerVoice::SamplerVoice()
  29315. : pitchRatio (0.0),
  29316. sourceSamplePosition (0.0),
  29317. lgain (0.0f),
  29318. rgain (0.0f),
  29319. isInAttack (false),
  29320. isInRelease (false)
  29321. {
  29322. }
  29323. SamplerVoice::~SamplerVoice()
  29324. {
  29325. }
  29326. bool SamplerVoice::canPlaySound (SynthesiserSound* sound)
  29327. {
  29328. return dynamic_cast <const SamplerSound*> (sound) != 0;
  29329. }
  29330. void SamplerVoice::startNote (const int midiNoteNumber,
  29331. const float velocity,
  29332. SynthesiserSound* s,
  29333. const int /*currentPitchWheelPosition*/)
  29334. {
  29335. const SamplerSound* const sound = dynamic_cast <const SamplerSound*> (s);
  29336. jassert (sound != 0); // this object can only play SamplerSounds!
  29337. if (sound != 0)
  29338. {
  29339. const double targetFreq = MidiMessage::getMidiNoteInHertz (midiNoteNumber);
  29340. const double naturalFreq = MidiMessage::getMidiNoteInHertz (sound->midiRootNote);
  29341. pitchRatio = (targetFreq * sound->sourceSampleRate) / (naturalFreq * getSampleRate());
  29342. sourceSamplePosition = 0.0;
  29343. lgain = velocity;
  29344. rgain = velocity;
  29345. isInAttack = (sound->attackSamples > 0);
  29346. isInRelease = false;
  29347. if (isInAttack)
  29348. {
  29349. attackReleaseLevel = 0.0f;
  29350. attackDelta = (float) (pitchRatio / sound->attackSamples);
  29351. }
  29352. else
  29353. {
  29354. attackReleaseLevel = 1.0f;
  29355. attackDelta = 0.0f;
  29356. }
  29357. if (sound->releaseSamples > 0)
  29358. {
  29359. releaseDelta = (float) (-pitchRatio / sound->releaseSamples);
  29360. }
  29361. else
  29362. {
  29363. releaseDelta = 0.0f;
  29364. }
  29365. }
  29366. }
  29367. void SamplerVoice::stopNote (const bool allowTailOff)
  29368. {
  29369. if (allowTailOff)
  29370. {
  29371. isInAttack = false;
  29372. isInRelease = true;
  29373. }
  29374. else
  29375. {
  29376. clearCurrentNote();
  29377. }
  29378. }
  29379. void SamplerVoice::pitchWheelMoved (const int /*newValue*/)
  29380. {
  29381. }
  29382. void SamplerVoice::controllerMoved (const int /*controllerNumber*/,
  29383. const int /*newValue*/)
  29384. {
  29385. }
  29386. void SamplerVoice::renderNextBlock (AudioSampleBuffer& outputBuffer, int startSample, int numSamples)
  29387. {
  29388. const SamplerSound* const playingSound = (SamplerSound*) (SynthesiserSound*) getCurrentlyPlayingSound();
  29389. if (playingSound != 0)
  29390. {
  29391. const float* const inL = playingSound->data->getSampleData (0, 0);
  29392. const float* const inR = playingSound->data->getNumChannels() > 1
  29393. ? playingSound->data->getSampleData (1, 0) : 0;
  29394. float* outL = outputBuffer.getSampleData (0, startSample);
  29395. float* outR = outputBuffer.getNumChannels() > 1 ? outputBuffer.getSampleData (1, startSample) : 0;
  29396. while (--numSamples >= 0)
  29397. {
  29398. const int pos = (int) sourceSamplePosition;
  29399. const float alpha = (float) (sourceSamplePosition - pos);
  29400. const float invAlpha = 1.0f - alpha;
  29401. // just using a very simple linear interpolation here..
  29402. float l = (inL [pos] * invAlpha + inL [pos + 1] * alpha);
  29403. float r = (inR != 0) ? (inR [pos] * invAlpha + inR [pos + 1] * alpha)
  29404. : l;
  29405. l *= lgain;
  29406. r *= rgain;
  29407. if (isInAttack)
  29408. {
  29409. l *= attackReleaseLevel;
  29410. r *= attackReleaseLevel;
  29411. attackReleaseLevel += attackDelta;
  29412. if (attackReleaseLevel >= 1.0f)
  29413. {
  29414. attackReleaseLevel = 1.0f;
  29415. isInAttack = false;
  29416. }
  29417. }
  29418. else if (isInRelease)
  29419. {
  29420. l *= attackReleaseLevel;
  29421. r *= attackReleaseLevel;
  29422. attackReleaseLevel += releaseDelta;
  29423. if (attackReleaseLevel <= 0.0f)
  29424. {
  29425. stopNote (false);
  29426. break;
  29427. }
  29428. }
  29429. if (outR != 0)
  29430. {
  29431. *outL++ += l;
  29432. *outR++ += r;
  29433. }
  29434. else
  29435. {
  29436. *outL++ += (l + r) * 0.5f;
  29437. }
  29438. sourceSamplePosition += pitchRatio;
  29439. if (sourceSamplePosition > playingSound->length)
  29440. {
  29441. stopNote (false);
  29442. break;
  29443. }
  29444. }
  29445. }
  29446. }
  29447. END_JUCE_NAMESPACE
  29448. /*** End of inlined file: juce_Sampler.cpp ***/
  29449. /*** Start of inlined file: juce_Synthesiser.cpp ***/
  29450. BEGIN_JUCE_NAMESPACE
  29451. SynthesiserSound::SynthesiserSound()
  29452. {
  29453. }
  29454. SynthesiserSound::~SynthesiserSound()
  29455. {
  29456. }
  29457. SynthesiserVoice::SynthesiserVoice()
  29458. : currentSampleRate (44100.0),
  29459. currentlyPlayingNote (-1),
  29460. noteOnTime (0),
  29461. currentlyPlayingSound (0)
  29462. {
  29463. }
  29464. SynthesiserVoice::~SynthesiserVoice()
  29465. {
  29466. }
  29467. bool SynthesiserVoice::isPlayingChannel (const int midiChannel) const
  29468. {
  29469. return currentlyPlayingSound != 0
  29470. && currentlyPlayingSound->appliesToChannel (midiChannel);
  29471. }
  29472. void SynthesiserVoice::setCurrentPlaybackSampleRate (const double newRate)
  29473. {
  29474. currentSampleRate = newRate;
  29475. }
  29476. void SynthesiserVoice::clearCurrentNote()
  29477. {
  29478. currentlyPlayingNote = -1;
  29479. currentlyPlayingSound = 0;
  29480. }
  29481. Synthesiser::Synthesiser()
  29482. : sampleRate (0),
  29483. lastNoteOnCounter (0),
  29484. shouldStealNotes (true)
  29485. {
  29486. for (int i = 0; i < numElementsInArray (lastPitchWheelValues); ++i)
  29487. lastPitchWheelValues[i] = 0x2000;
  29488. }
  29489. Synthesiser::~Synthesiser()
  29490. {
  29491. }
  29492. SynthesiserVoice* Synthesiser::getVoice (const int index) const
  29493. {
  29494. const ScopedLock sl (lock);
  29495. return voices [index];
  29496. }
  29497. void Synthesiser::clearVoices()
  29498. {
  29499. const ScopedLock sl (lock);
  29500. voices.clear();
  29501. }
  29502. void Synthesiser::addVoice (SynthesiserVoice* const newVoice)
  29503. {
  29504. const ScopedLock sl (lock);
  29505. voices.add (newVoice);
  29506. }
  29507. void Synthesiser::removeVoice (const int index)
  29508. {
  29509. const ScopedLock sl (lock);
  29510. voices.remove (index);
  29511. }
  29512. void Synthesiser::clearSounds()
  29513. {
  29514. const ScopedLock sl (lock);
  29515. sounds.clear();
  29516. }
  29517. void Synthesiser::addSound (const SynthesiserSound::Ptr& newSound)
  29518. {
  29519. const ScopedLock sl (lock);
  29520. sounds.add (newSound);
  29521. }
  29522. void Synthesiser::removeSound (const int index)
  29523. {
  29524. const ScopedLock sl (lock);
  29525. sounds.remove (index);
  29526. }
  29527. void Synthesiser::setNoteStealingEnabled (const bool shouldStealNotes_)
  29528. {
  29529. shouldStealNotes = shouldStealNotes_;
  29530. }
  29531. void Synthesiser::setCurrentPlaybackSampleRate (const double newRate)
  29532. {
  29533. if (sampleRate != newRate)
  29534. {
  29535. const ScopedLock sl (lock);
  29536. allNotesOff (0, false);
  29537. sampleRate = newRate;
  29538. for (int i = voices.size(); --i >= 0;)
  29539. voices.getUnchecked (i)->setCurrentPlaybackSampleRate (newRate);
  29540. }
  29541. }
  29542. void Synthesiser::renderNextBlock (AudioSampleBuffer& outputBuffer,
  29543. const MidiBuffer& midiData,
  29544. int startSample,
  29545. int numSamples)
  29546. {
  29547. // must set the sample rate before using this!
  29548. jassert (sampleRate != 0);
  29549. const ScopedLock sl (lock);
  29550. MidiBuffer::Iterator midiIterator (midiData);
  29551. midiIterator.setNextSamplePosition (startSample);
  29552. MidiMessage m (0xf4, 0.0);
  29553. while (numSamples > 0)
  29554. {
  29555. int midiEventPos;
  29556. const bool useEvent = midiIterator.getNextEvent (m, midiEventPos)
  29557. && midiEventPos < startSample + numSamples;
  29558. const int numThisTime = useEvent ? midiEventPos - startSample
  29559. : numSamples;
  29560. if (numThisTime > 0)
  29561. {
  29562. for (int i = voices.size(); --i >= 0;)
  29563. voices.getUnchecked (i)->renderNextBlock (outputBuffer, startSample, numThisTime);
  29564. }
  29565. if (useEvent)
  29566. {
  29567. if (m.isNoteOn())
  29568. {
  29569. const int channel = m.getChannel();
  29570. noteOn (channel,
  29571. m.getNoteNumber(),
  29572. m.getFloatVelocity());
  29573. }
  29574. else if (m.isNoteOff())
  29575. {
  29576. noteOff (m.getChannel(),
  29577. m.getNoteNumber(),
  29578. true);
  29579. }
  29580. else if (m.isAllNotesOff() || m.isAllSoundOff())
  29581. {
  29582. allNotesOff (m.getChannel(), true);
  29583. }
  29584. else if (m.isPitchWheel())
  29585. {
  29586. const int channel = m.getChannel();
  29587. const int wheelPos = m.getPitchWheelValue();
  29588. lastPitchWheelValues [channel - 1] = wheelPos;
  29589. handlePitchWheel (channel, wheelPos);
  29590. }
  29591. else if (m.isController())
  29592. {
  29593. handleController (m.getChannel(),
  29594. m.getControllerNumber(),
  29595. m.getControllerValue());
  29596. }
  29597. }
  29598. startSample += numThisTime;
  29599. numSamples -= numThisTime;
  29600. }
  29601. }
  29602. void Synthesiser::noteOn (const int midiChannel,
  29603. const int midiNoteNumber,
  29604. const float velocity)
  29605. {
  29606. const ScopedLock sl (lock);
  29607. for (int i = sounds.size(); --i >= 0;)
  29608. {
  29609. SynthesiserSound* const sound = sounds.getUnchecked(i);
  29610. if (sound->appliesToNote (midiNoteNumber)
  29611. && sound->appliesToChannel (midiChannel))
  29612. {
  29613. startVoice (findFreeVoice (sound, shouldStealNotes),
  29614. sound, midiChannel, midiNoteNumber, velocity);
  29615. }
  29616. }
  29617. }
  29618. void Synthesiser::startVoice (SynthesiserVoice* const voice,
  29619. SynthesiserSound* const sound,
  29620. const int midiChannel,
  29621. const int midiNoteNumber,
  29622. const float velocity)
  29623. {
  29624. if (voice != 0 && sound != 0)
  29625. {
  29626. if (voice->currentlyPlayingSound != 0)
  29627. voice->stopNote (false);
  29628. voice->startNote (midiNoteNumber,
  29629. velocity,
  29630. sound,
  29631. lastPitchWheelValues [midiChannel - 1]);
  29632. voice->currentlyPlayingNote = midiNoteNumber;
  29633. voice->noteOnTime = ++lastNoteOnCounter;
  29634. voice->currentlyPlayingSound = sound;
  29635. }
  29636. }
  29637. void Synthesiser::noteOff (const int midiChannel,
  29638. const int midiNoteNumber,
  29639. const bool allowTailOff)
  29640. {
  29641. const ScopedLock sl (lock);
  29642. for (int i = voices.size(); --i >= 0;)
  29643. {
  29644. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29645. if (voice->getCurrentlyPlayingNote() == midiNoteNumber)
  29646. {
  29647. SynthesiserSound* const sound = voice->getCurrentlyPlayingSound();
  29648. if (sound != 0
  29649. && sound->appliesToNote (midiNoteNumber)
  29650. && sound->appliesToChannel (midiChannel))
  29651. {
  29652. voice->stopNote (allowTailOff);
  29653. // the subclass MUST call clearCurrentNote() if it's not tailing off! RTFM for stopNote()!
  29654. jassert (allowTailOff || (voice->getCurrentlyPlayingNote() < 0 && voice->getCurrentlyPlayingSound() == 0));
  29655. }
  29656. }
  29657. }
  29658. }
  29659. void Synthesiser::allNotesOff (const int midiChannel,
  29660. const bool allowTailOff)
  29661. {
  29662. const ScopedLock sl (lock);
  29663. for (int i = voices.size(); --i >= 0;)
  29664. {
  29665. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29666. if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
  29667. voice->stopNote (allowTailOff);
  29668. }
  29669. }
  29670. void Synthesiser::handlePitchWheel (const int midiChannel,
  29671. const int wheelValue)
  29672. {
  29673. const ScopedLock sl (lock);
  29674. for (int i = voices.size(); --i >= 0;)
  29675. {
  29676. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29677. if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
  29678. {
  29679. voice->pitchWheelMoved (wheelValue);
  29680. }
  29681. }
  29682. }
  29683. void Synthesiser::handleController (const int midiChannel,
  29684. const int controllerNumber,
  29685. const int controllerValue)
  29686. {
  29687. const ScopedLock sl (lock);
  29688. for (int i = voices.size(); --i >= 0;)
  29689. {
  29690. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29691. if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
  29692. voice->controllerMoved (controllerNumber, controllerValue);
  29693. }
  29694. }
  29695. SynthesiserVoice* Synthesiser::findFreeVoice (SynthesiserSound* soundToPlay,
  29696. const bool stealIfNoneAvailable) const
  29697. {
  29698. const ScopedLock sl (lock);
  29699. for (int i = voices.size(); --i >= 0;)
  29700. if (voices.getUnchecked (i)->getCurrentlyPlayingNote() < 0
  29701. && voices.getUnchecked (i)->canPlaySound (soundToPlay))
  29702. return voices.getUnchecked (i);
  29703. if (stealIfNoneAvailable)
  29704. {
  29705. // currently this just steals the one that's been playing the longest, but could be made a bit smarter..
  29706. SynthesiserVoice* oldest = 0;
  29707. for (int i = voices.size(); --i >= 0;)
  29708. {
  29709. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29710. if (voice->canPlaySound (soundToPlay)
  29711. && (oldest == 0 || oldest->noteOnTime > voice->noteOnTime))
  29712. oldest = voice;
  29713. }
  29714. jassert (oldest != 0);
  29715. return oldest;
  29716. }
  29717. return 0;
  29718. }
  29719. END_JUCE_NAMESPACE
  29720. /*** End of inlined file: juce_Synthesiser.cpp ***/
  29721. /*** Start of inlined file: juce_ActionBroadcaster.cpp ***/
  29722. BEGIN_JUCE_NAMESPACE
  29723. ActionBroadcaster::ActionBroadcaster() throw()
  29724. {
  29725. // are you trying to create this object before or after juce has been intialised??
  29726. jassert (MessageManager::instance != 0);
  29727. }
  29728. ActionBroadcaster::~ActionBroadcaster()
  29729. {
  29730. // all event-based objects must be deleted BEFORE juce is shut down!
  29731. jassert (MessageManager::instance != 0);
  29732. }
  29733. void ActionBroadcaster::addActionListener (ActionListener* const listener)
  29734. {
  29735. actionListenerList.addActionListener (listener);
  29736. }
  29737. void ActionBroadcaster::removeActionListener (ActionListener* const listener)
  29738. {
  29739. jassert (actionListenerList.isValidMessageListener());
  29740. if (actionListenerList.isValidMessageListener())
  29741. actionListenerList.removeActionListener (listener);
  29742. }
  29743. void ActionBroadcaster::removeAllActionListeners()
  29744. {
  29745. actionListenerList.removeAllActionListeners();
  29746. }
  29747. void ActionBroadcaster::sendActionMessage (const String& message) const
  29748. {
  29749. actionListenerList.sendActionMessage (message);
  29750. }
  29751. END_JUCE_NAMESPACE
  29752. /*** End of inlined file: juce_ActionBroadcaster.cpp ***/
  29753. /*** Start of inlined file: juce_ActionListenerList.cpp ***/
  29754. BEGIN_JUCE_NAMESPACE
  29755. // special message of our own with a string in it
  29756. class ActionMessage : public Message
  29757. {
  29758. public:
  29759. const String message;
  29760. ActionMessage (const String& messageText,
  29761. void* const listener_) throw()
  29762. : message (messageText)
  29763. {
  29764. pointerParameter = listener_;
  29765. }
  29766. ~ActionMessage() throw()
  29767. {
  29768. }
  29769. private:
  29770. ActionMessage (const ActionMessage&);
  29771. ActionMessage& operator= (const ActionMessage&);
  29772. };
  29773. ActionListenerList::ActionListenerList() throw()
  29774. {
  29775. }
  29776. ActionListenerList::~ActionListenerList() throw()
  29777. {
  29778. }
  29779. void ActionListenerList::addActionListener (ActionListener* const listener) throw()
  29780. {
  29781. const ScopedLock sl (actionListenerLock_);
  29782. jassert (listener != 0);
  29783. jassert (! actionListeners_.contains (listener)); // trying to add a listener to the list twice!
  29784. if (listener != 0)
  29785. actionListeners_.add (listener);
  29786. }
  29787. void ActionListenerList::removeActionListener (ActionListener* const listener) throw()
  29788. {
  29789. const ScopedLock sl (actionListenerLock_);
  29790. jassert (actionListeners_.contains (listener)); // trying to remove a listener that isn't on the list!
  29791. actionListeners_.removeValue (listener);
  29792. }
  29793. void ActionListenerList::removeAllActionListeners() throw()
  29794. {
  29795. const ScopedLock sl (actionListenerLock_);
  29796. actionListeners_.clear();
  29797. }
  29798. void ActionListenerList::sendActionMessage (const String& message) const
  29799. {
  29800. const ScopedLock sl (actionListenerLock_);
  29801. for (int i = actionListeners_.size(); --i >= 0;)
  29802. {
  29803. postMessage (new ActionMessage (message,
  29804. (ActionListener*) actionListeners_.getUnchecked(i)));
  29805. }
  29806. }
  29807. void ActionListenerList::handleMessage (const Message& message)
  29808. {
  29809. const ActionMessage& am = (const ActionMessage&) message;
  29810. if (actionListeners_.contains (am.pointerParameter))
  29811. ((ActionListener*) am.pointerParameter)->actionListenerCallback (am.message);
  29812. }
  29813. END_JUCE_NAMESPACE
  29814. /*** End of inlined file: juce_ActionListenerList.cpp ***/
  29815. /*** Start of inlined file: juce_AsyncUpdater.cpp ***/
  29816. BEGIN_JUCE_NAMESPACE
  29817. AsyncUpdater::AsyncUpdater() throw()
  29818. : asyncMessagePending (false)
  29819. {
  29820. internalAsyncHandler.owner = this;
  29821. }
  29822. AsyncUpdater::~AsyncUpdater()
  29823. {
  29824. }
  29825. void AsyncUpdater::triggerAsyncUpdate() throw()
  29826. {
  29827. if (! asyncMessagePending)
  29828. {
  29829. asyncMessagePending = true;
  29830. internalAsyncHandler.postMessage (new Message());
  29831. }
  29832. }
  29833. void AsyncUpdater::cancelPendingUpdate() throw()
  29834. {
  29835. asyncMessagePending = false;
  29836. }
  29837. void AsyncUpdater::handleUpdateNowIfNeeded()
  29838. {
  29839. if (asyncMessagePending)
  29840. {
  29841. asyncMessagePending = false;
  29842. handleAsyncUpdate();
  29843. }
  29844. }
  29845. void AsyncUpdater::AsyncUpdaterInternal::handleMessage (const Message&)
  29846. {
  29847. owner->handleUpdateNowIfNeeded();
  29848. }
  29849. END_JUCE_NAMESPACE
  29850. /*** End of inlined file: juce_AsyncUpdater.cpp ***/
  29851. /*** Start of inlined file: juce_ChangeBroadcaster.cpp ***/
  29852. BEGIN_JUCE_NAMESPACE
  29853. ChangeBroadcaster::ChangeBroadcaster() throw()
  29854. {
  29855. // are you trying to create this object before or after juce has been intialised??
  29856. jassert (MessageManager::instance != 0);
  29857. }
  29858. ChangeBroadcaster::~ChangeBroadcaster()
  29859. {
  29860. // all event-based objects must be deleted BEFORE juce is shut down!
  29861. jassert (MessageManager::instance != 0);
  29862. }
  29863. void ChangeBroadcaster::addChangeListener (ChangeListener* const listener) throw()
  29864. {
  29865. changeListenerList.addChangeListener (listener);
  29866. }
  29867. void ChangeBroadcaster::removeChangeListener (ChangeListener* const listener) throw()
  29868. {
  29869. jassert (changeListenerList.isValidMessageListener());
  29870. if (changeListenerList.isValidMessageListener())
  29871. changeListenerList.removeChangeListener (listener);
  29872. }
  29873. void ChangeBroadcaster::removeAllChangeListeners() throw()
  29874. {
  29875. changeListenerList.removeAllChangeListeners();
  29876. }
  29877. void ChangeBroadcaster::sendChangeMessage (void* objectThatHasChanged) throw()
  29878. {
  29879. changeListenerList.sendChangeMessage (objectThatHasChanged);
  29880. }
  29881. void ChangeBroadcaster::sendSynchronousChangeMessage (void* objectThatHasChanged)
  29882. {
  29883. changeListenerList.sendSynchronousChangeMessage (objectThatHasChanged);
  29884. }
  29885. void ChangeBroadcaster::dispatchPendingMessages()
  29886. {
  29887. changeListenerList.dispatchPendingMessages();
  29888. }
  29889. END_JUCE_NAMESPACE
  29890. /*** End of inlined file: juce_ChangeBroadcaster.cpp ***/
  29891. /*** Start of inlined file: juce_ChangeListenerList.cpp ***/
  29892. BEGIN_JUCE_NAMESPACE
  29893. ChangeListenerList::ChangeListenerList() throw()
  29894. : lastChangedObject (0),
  29895. messagePending (false)
  29896. {
  29897. }
  29898. ChangeListenerList::~ChangeListenerList() throw()
  29899. {
  29900. }
  29901. void ChangeListenerList::addChangeListener (ChangeListener* const listener) throw()
  29902. {
  29903. const ScopedLock sl (lock);
  29904. jassert (listener != 0);
  29905. if (listener != 0)
  29906. listeners.add (listener);
  29907. }
  29908. void ChangeListenerList::removeChangeListener (ChangeListener* const listener) throw()
  29909. {
  29910. const ScopedLock sl (lock);
  29911. listeners.removeValue (listener);
  29912. }
  29913. void ChangeListenerList::removeAllChangeListeners() throw()
  29914. {
  29915. const ScopedLock sl (lock);
  29916. listeners.clear();
  29917. }
  29918. void ChangeListenerList::sendChangeMessage (void* const objectThatHasChanged) throw()
  29919. {
  29920. const ScopedLock sl (lock);
  29921. if ((! messagePending) && (listeners.size() > 0))
  29922. {
  29923. lastChangedObject = objectThatHasChanged;
  29924. postMessage (new Message (0, 0, 0, objectThatHasChanged));
  29925. messagePending = true;
  29926. }
  29927. }
  29928. void ChangeListenerList::handleMessage (const Message& message)
  29929. {
  29930. sendSynchronousChangeMessage (message.pointerParameter);
  29931. }
  29932. void ChangeListenerList::sendSynchronousChangeMessage (void* const objectThatHasChanged)
  29933. {
  29934. const ScopedLock sl (lock);
  29935. messagePending = false;
  29936. for (int i = listeners.size(); --i >= 0;)
  29937. {
  29938. ChangeListener* const l = (ChangeListener*) listeners.getUnchecked (i);
  29939. {
  29940. const ScopedUnlock tempUnlocker (lock);
  29941. l->changeListenerCallback (objectThatHasChanged);
  29942. }
  29943. i = jmin (i, listeners.size());
  29944. }
  29945. }
  29946. void ChangeListenerList::dispatchPendingMessages()
  29947. {
  29948. if (messagePending)
  29949. sendSynchronousChangeMessage (lastChangedObject);
  29950. }
  29951. END_JUCE_NAMESPACE
  29952. /*** End of inlined file: juce_ChangeListenerList.cpp ***/
  29953. /*** Start of inlined file: juce_InterprocessConnection.cpp ***/
  29954. BEGIN_JUCE_NAMESPACE
  29955. InterprocessConnection::InterprocessConnection (const bool callbacksOnMessageThread,
  29956. const uint32 magicMessageHeaderNumber)
  29957. : Thread ("Juce IPC connection"),
  29958. callbackConnectionState (false),
  29959. useMessageThread (callbacksOnMessageThread),
  29960. magicMessageHeader (magicMessageHeaderNumber),
  29961. pipeReceiveMessageTimeout (-1)
  29962. {
  29963. }
  29964. InterprocessConnection::~InterprocessConnection()
  29965. {
  29966. callbackConnectionState = false;
  29967. disconnect();
  29968. }
  29969. bool InterprocessConnection::connectToSocket (const String& hostName,
  29970. const int portNumber,
  29971. const int timeOutMillisecs)
  29972. {
  29973. disconnect();
  29974. const ScopedLock sl (pipeAndSocketLock);
  29975. socket = new StreamingSocket();
  29976. if (socket->connect (hostName, portNumber, timeOutMillisecs))
  29977. {
  29978. connectionMadeInt();
  29979. startThread();
  29980. return true;
  29981. }
  29982. else
  29983. {
  29984. socket = 0;
  29985. return false;
  29986. }
  29987. }
  29988. bool InterprocessConnection::connectToPipe (const String& pipeName,
  29989. const int pipeReceiveMessageTimeoutMs)
  29990. {
  29991. disconnect();
  29992. ScopedPointer <NamedPipe> newPipe (new NamedPipe());
  29993. if (newPipe->openExisting (pipeName))
  29994. {
  29995. const ScopedLock sl (pipeAndSocketLock);
  29996. pipeReceiveMessageTimeout = pipeReceiveMessageTimeoutMs;
  29997. initialiseWithPipe (newPipe.release());
  29998. return true;
  29999. }
  30000. return false;
  30001. }
  30002. bool InterprocessConnection::createPipe (const String& pipeName,
  30003. const int pipeReceiveMessageTimeoutMs)
  30004. {
  30005. disconnect();
  30006. ScopedPointer <NamedPipe> newPipe (new NamedPipe());
  30007. if (newPipe->createNewPipe (pipeName))
  30008. {
  30009. const ScopedLock sl (pipeAndSocketLock);
  30010. pipeReceiveMessageTimeout = pipeReceiveMessageTimeoutMs;
  30011. initialiseWithPipe (newPipe.release());
  30012. return true;
  30013. }
  30014. return false;
  30015. }
  30016. void InterprocessConnection::disconnect()
  30017. {
  30018. if (socket != 0)
  30019. socket->close();
  30020. if (pipe != 0)
  30021. {
  30022. pipe->cancelPendingReads();
  30023. pipe->close();
  30024. }
  30025. stopThread (4000);
  30026. {
  30027. const ScopedLock sl (pipeAndSocketLock);
  30028. socket = 0;
  30029. pipe = 0;
  30030. }
  30031. connectionLostInt();
  30032. }
  30033. bool InterprocessConnection::isConnected() const
  30034. {
  30035. const ScopedLock sl (pipeAndSocketLock);
  30036. return ((socket != 0 && socket->isConnected())
  30037. || (pipe != 0 && pipe->isOpen()))
  30038. && isThreadRunning();
  30039. }
  30040. const String InterprocessConnection::getConnectedHostName() const
  30041. {
  30042. if (pipe != 0)
  30043. {
  30044. return "localhost";
  30045. }
  30046. else if (socket != 0)
  30047. {
  30048. if (! socket->isLocal())
  30049. return socket->getHostName();
  30050. return "localhost";
  30051. }
  30052. return String::empty;
  30053. }
  30054. bool InterprocessConnection::sendMessage (const MemoryBlock& message)
  30055. {
  30056. uint32 messageHeader[2];
  30057. messageHeader [0] = ByteOrder::swapIfBigEndian (magicMessageHeader);
  30058. messageHeader [1] = ByteOrder::swapIfBigEndian ((uint32) message.getSize());
  30059. MemoryBlock messageData (sizeof (messageHeader) + message.getSize());
  30060. messageData.copyFrom (messageHeader, 0, sizeof (messageHeader));
  30061. messageData.copyFrom (message.getData(), sizeof (messageHeader), message.getSize());
  30062. size_t bytesWritten = 0;
  30063. const ScopedLock sl (pipeAndSocketLock);
  30064. if (socket != 0)
  30065. {
  30066. bytesWritten = socket->write (messageData.getData(), (int) messageData.getSize());
  30067. }
  30068. else if (pipe != 0)
  30069. {
  30070. bytesWritten = pipe->write (messageData.getData(), (int) messageData.getSize());
  30071. }
  30072. if (bytesWritten < 0)
  30073. {
  30074. // error..
  30075. return false;
  30076. }
  30077. return (bytesWritten == messageData.getSize());
  30078. }
  30079. void InterprocessConnection::initialiseWithSocket (StreamingSocket* const socket_)
  30080. {
  30081. jassert (socket == 0);
  30082. socket = socket_;
  30083. connectionMadeInt();
  30084. startThread();
  30085. }
  30086. void InterprocessConnection::initialiseWithPipe (NamedPipe* const pipe_)
  30087. {
  30088. jassert (pipe == 0);
  30089. pipe = pipe_;
  30090. connectionMadeInt();
  30091. startThread();
  30092. }
  30093. const int messageMagicNumber = 0xb734128b;
  30094. void InterprocessConnection::handleMessage (const Message& message)
  30095. {
  30096. if (message.intParameter1 == messageMagicNumber)
  30097. {
  30098. switch (message.intParameter2)
  30099. {
  30100. case 0:
  30101. {
  30102. ScopedPointer <MemoryBlock> data ((MemoryBlock*) message.pointerParameter);
  30103. messageReceived (*data);
  30104. break;
  30105. }
  30106. case 1:
  30107. connectionMade();
  30108. break;
  30109. case 2:
  30110. connectionLost();
  30111. break;
  30112. }
  30113. }
  30114. }
  30115. void InterprocessConnection::connectionMadeInt()
  30116. {
  30117. if (! callbackConnectionState)
  30118. {
  30119. callbackConnectionState = true;
  30120. if (useMessageThread)
  30121. postMessage (new Message (messageMagicNumber, 1, 0, 0));
  30122. else
  30123. connectionMade();
  30124. }
  30125. }
  30126. void InterprocessConnection::connectionLostInt()
  30127. {
  30128. if (callbackConnectionState)
  30129. {
  30130. callbackConnectionState = false;
  30131. if (useMessageThread)
  30132. postMessage (new Message (messageMagicNumber, 2, 0, 0));
  30133. else
  30134. connectionLost();
  30135. }
  30136. }
  30137. void InterprocessConnection::deliverDataInt (const MemoryBlock& data)
  30138. {
  30139. jassert (callbackConnectionState);
  30140. if (useMessageThread)
  30141. postMessage (new Message (messageMagicNumber, 0, 0, new MemoryBlock (data)));
  30142. else
  30143. messageReceived (data);
  30144. }
  30145. bool InterprocessConnection::readNextMessageInt()
  30146. {
  30147. const int maximumMessageSize = 1024 * 1024 * 10; // sanity check
  30148. uint32 messageHeader[2];
  30149. const int bytes = (socket != 0) ? socket->read (messageHeader, sizeof (messageHeader), true)
  30150. : pipe->read (messageHeader, sizeof (messageHeader), pipeReceiveMessageTimeout);
  30151. if (bytes == sizeof (messageHeader)
  30152. && ByteOrder::swapIfBigEndian (messageHeader[0]) == magicMessageHeader)
  30153. {
  30154. const int bytesInMessage = (int) ByteOrder::swapIfBigEndian (messageHeader[1]);
  30155. if (bytesInMessage > 0 && bytesInMessage < maximumMessageSize)
  30156. {
  30157. MemoryBlock messageData (bytesInMessage, true);
  30158. int bytesRead = 0;
  30159. while (bytesRead < bytesInMessage)
  30160. {
  30161. if (threadShouldExit())
  30162. return false;
  30163. const int numThisTime = jmin (bytesInMessage, 65536);
  30164. const int bytesIn = (socket != 0) ? socket->read (((char*) messageData.getData()) + bytesRead, numThisTime, true)
  30165. : pipe->read (((char*) messageData.getData()) + bytesRead, numThisTime,
  30166. pipeReceiveMessageTimeout);
  30167. if (bytesIn <= 0)
  30168. break;
  30169. bytesRead += bytesIn;
  30170. }
  30171. if (bytesRead >= 0)
  30172. deliverDataInt (messageData);
  30173. }
  30174. }
  30175. else if (bytes < 0)
  30176. {
  30177. {
  30178. const ScopedLock sl (pipeAndSocketLock);
  30179. socket = 0;
  30180. }
  30181. connectionLostInt();
  30182. return false;
  30183. }
  30184. return true;
  30185. }
  30186. void InterprocessConnection::run()
  30187. {
  30188. while (! threadShouldExit())
  30189. {
  30190. if (socket != 0)
  30191. {
  30192. const int ready = socket->waitUntilReady (true, 0);
  30193. if (ready < 0)
  30194. {
  30195. {
  30196. const ScopedLock sl (pipeAndSocketLock);
  30197. socket = 0;
  30198. }
  30199. connectionLostInt();
  30200. break;
  30201. }
  30202. else if (ready > 0)
  30203. {
  30204. if (! readNextMessageInt())
  30205. break;
  30206. }
  30207. else
  30208. {
  30209. Thread::sleep (2);
  30210. }
  30211. }
  30212. else if (pipe != 0)
  30213. {
  30214. if (! pipe->isOpen())
  30215. {
  30216. {
  30217. const ScopedLock sl (pipeAndSocketLock);
  30218. pipe = 0;
  30219. }
  30220. connectionLostInt();
  30221. break;
  30222. }
  30223. else
  30224. {
  30225. if (! readNextMessageInt())
  30226. break;
  30227. }
  30228. }
  30229. else
  30230. {
  30231. break;
  30232. }
  30233. }
  30234. }
  30235. END_JUCE_NAMESPACE
  30236. /*** End of inlined file: juce_InterprocessConnection.cpp ***/
  30237. /*** Start of inlined file: juce_InterprocessConnectionServer.cpp ***/
  30238. BEGIN_JUCE_NAMESPACE
  30239. InterprocessConnectionServer::InterprocessConnectionServer()
  30240. : Thread ("Juce IPC server")
  30241. {
  30242. }
  30243. InterprocessConnectionServer::~InterprocessConnectionServer()
  30244. {
  30245. stop();
  30246. }
  30247. bool InterprocessConnectionServer::beginWaitingForSocket (const int portNumber)
  30248. {
  30249. stop();
  30250. socket = new StreamingSocket();
  30251. if (socket->createListener (portNumber))
  30252. {
  30253. startThread();
  30254. return true;
  30255. }
  30256. socket = 0;
  30257. return false;
  30258. }
  30259. void InterprocessConnectionServer::stop()
  30260. {
  30261. signalThreadShouldExit();
  30262. if (socket != 0)
  30263. socket->close();
  30264. stopThread (4000);
  30265. socket = 0;
  30266. }
  30267. void InterprocessConnectionServer::run()
  30268. {
  30269. while ((! threadShouldExit()) && socket != 0)
  30270. {
  30271. ScopedPointer <StreamingSocket> clientSocket (socket->waitForNextConnection());
  30272. if (clientSocket != 0)
  30273. {
  30274. InterprocessConnection* newConnection = createConnectionObject();
  30275. if (newConnection != 0)
  30276. newConnection->initialiseWithSocket (clientSocket.release());
  30277. }
  30278. }
  30279. }
  30280. END_JUCE_NAMESPACE
  30281. /*** End of inlined file: juce_InterprocessConnectionServer.cpp ***/
  30282. /*** Start of inlined file: juce_Message.cpp ***/
  30283. BEGIN_JUCE_NAMESPACE
  30284. Message::Message() throw()
  30285. {
  30286. }
  30287. Message::~Message() throw()
  30288. {
  30289. }
  30290. Message::Message (const int intParameter1_,
  30291. const int intParameter2_,
  30292. const int intParameter3_,
  30293. void* const pointerParameter_) throw()
  30294. : intParameter1 (intParameter1_),
  30295. intParameter2 (intParameter2_),
  30296. intParameter3 (intParameter3_),
  30297. pointerParameter (pointerParameter_)
  30298. {
  30299. }
  30300. END_JUCE_NAMESPACE
  30301. /*** End of inlined file: juce_Message.cpp ***/
  30302. /*** Start of inlined file: juce_MessageListener.cpp ***/
  30303. BEGIN_JUCE_NAMESPACE
  30304. MessageListener::MessageListener() throw()
  30305. {
  30306. // are you trying to create a messagelistener before or after juce has been intialised??
  30307. jassert (MessageManager::instance != 0);
  30308. if (MessageManager::instance != 0)
  30309. MessageManager::instance->messageListeners.add (this);
  30310. }
  30311. MessageListener::~MessageListener()
  30312. {
  30313. if (MessageManager::instance != 0)
  30314. MessageManager::instance->messageListeners.removeValue (this);
  30315. }
  30316. void MessageListener::postMessage (Message* const message) const throw()
  30317. {
  30318. message->messageRecipient = const_cast <MessageListener*> (this);
  30319. if (MessageManager::instance == 0)
  30320. MessageManager::getInstance();
  30321. MessageManager::instance->postMessageToQueue (message);
  30322. }
  30323. bool MessageListener::isValidMessageListener() const throw()
  30324. {
  30325. return (MessageManager::instance != 0)
  30326. && MessageManager::instance->messageListeners.contains (this);
  30327. }
  30328. END_JUCE_NAMESPACE
  30329. /*** End of inlined file: juce_MessageListener.cpp ***/
  30330. /*** Start of inlined file: juce_MessageManager.cpp ***/
  30331. BEGIN_JUCE_NAMESPACE
  30332. // platform-specific functions..
  30333. bool juce_dispatchNextMessageOnSystemQueue (bool returnIfNoPendingMessages);
  30334. bool juce_postMessageToSystemQueue (void* message);
  30335. MessageManager* MessageManager::instance = 0;
  30336. static const int quitMessageId = 0xfffff321;
  30337. MessageManager::MessageManager() throw()
  30338. : quitMessagePosted (false),
  30339. quitMessageReceived (false),
  30340. threadWithLock (0)
  30341. {
  30342. messageThreadId = Thread::getCurrentThreadId();
  30343. }
  30344. MessageManager::~MessageManager() throw()
  30345. {
  30346. broadcastListeners = 0;
  30347. doPlatformSpecificShutdown();
  30348. jassert (instance == this);
  30349. instance = 0; // do this last in case this instance is still needed by doPlatformSpecificShutdown()
  30350. }
  30351. MessageManager* MessageManager::getInstance() throw()
  30352. {
  30353. if (instance == 0)
  30354. {
  30355. instance = new MessageManager();
  30356. doPlatformSpecificInitialisation();
  30357. }
  30358. return instance;
  30359. }
  30360. void MessageManager::postMessageToQueue (Message* const message)
  30361. {
  30362. if (quitMessagePosted || ! juce_postMessageToSystemQueue (message))
  30363. delete message;
  30364. }
  30365. CallbackMessage::CallbackMessage() throw() {}
  30366. CallbackMessage::~CallbackMessage() throw() {}
  30367. void CallbackMessage::post()
  30368. {
  30369. if (MessageManager::instance != 0)
  30370. MessageManager::instance->postCallbackMessage (this);
  30371. }
  30372. void MessageManager::postCallbackMessage (Message* const message)
  30373. {
  30374. message->messageRecipient = 0;
  30375. postMessageToQueue (message);
  30376. }
  30377. // not for public use..
  30378. void MessageManager::deliverMessage (void* message)
  30379. {
  30380. const ScopedPointer <Message> m ((Message*) message);
  30381. MessageListener* const recipient = m->messageRecipient;
  30382. JUCE_TRY
  30383. {
  30384. if (messageListeners.contains (recipient))
  30385. {
  30386. recipient->handleMessage (*m);
  30387. }
  30388. else if (recipient == 0)
  30389. {
  30390. if (m->intParameter1 == quitMessageId)
  30391. {
  30392. quitMessageReceived = true;
  30393. }
  30394. else
  30395. {
  30396. CallbackMessage* const cm = dynamic_cast <CallbackMessage*> ((Message*) m);
  30397. if (cm != 0)
  30398. cm->messageCallback();
  30399. }
  30400. }
  30401. }
  30402. JUCE_CATCH_EXCEPTION
  30403. }
  30404. #if ! (JUCE_MAC || JUCE_IPHONE)
  30405. void MessageManager::runDispatchLoop()
  30406. {
  30407. jassert (isThisTheMessageThread()); // must only be called by the message thread
  30408. runDispatchLoopUntil (-1);
  30409. }
  30410. void MessageManager::stopDispatchLoop()
  30411. {
  30412. Message* const m = new Message (quitMessageId, 0, 0, 0);
  30413. m->messageRecipient = 0;
  30414. postMessageToQueue (m);
  30415. quitMessagePosted = true;
  30416. }
  30417. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  30418. {
  30419. jassert (isThisTheMessageThread()); // must only be called by the message thread
  30420. const int64 endTime = Time::currentTimeMillis() + millisecondsToRunFor;
  30421. while ((millisecondsToRunFor < 0 || endTime > Time::currentTimeMillis())
  30422. && ! quitMessageReceived)
  30423. {
  30424. JUCE_TRY
  30425. {
  30426. if (! juce_dispatchNextMessageOnSystemQueue (millisecondsToRunFor >= 0))
  30427. {
  30428. const int msToWait = (int) (endTime - Time::currentTimeMillis());
  30429. if (msToWait > 0)
  30430. Thread::sleep (jmin (5, msToWait));
  30431. }
  30432. }
  30433. JUCE_CATCH_EXCEPTION
  30434. }
  30435. return ! quitMessageReceived;
  30436. }
  30437. #endif
  30438. void MessageManager::deliverBroadcastMessage (const String& value)
  30439. {
  30440. if (broadcastListeners != 0)
  30441. broadcastListeners->sendActionMessage (value);
  30442. }
  30443. void MessageManager::registerBroadcastListener (ActionListener* const listener) throw()
  30444. {
  30445. if (broadcastListeners == 0)
  30446. broadcastListeners = new ActionListenerList();
  30447. broadcastListeners->addActionListener (listener);
  30448. }
  30449. void MessageManager::deregisterBroadcastListener (ActionListener* const listener) throw()
  30450. {
  30451. if (broadcastListeners != 0)
  30452. broadcastListeners->removeActionListener (listener);
  30453. }
  30454. bool MessageManager::isThisTheMessageThread() const throw()
  30455. {
  30456. return Thread::getCurrentThreadId() == messageThreadId;
  30457. }
  30458. void MessageManager::setCurrentThreadAsMessageThread()
  30459. {
  30460. if (messageThreadId != Thread::getCurrentThreadId())
  30461. {
  30462. messageThreadId = Thread::getCurrentThreadId();
  30463. // This is needed on windows to make sure the message window is created by this thread
  30464. doPlatformSpecificShutdown();
  30465. doPlatformSpecificInitialisation();
  30466. }
  30467. }
  30468. bool MessageManager::currentThreadHasLockedMessageManager() const throw()
  30469. {
  30470. const Thread::ThreadID thisThread = Thread::getCurrentThreadId();
  30471. return thisThread == messageThreadId || thisThread == threadWithLock;
  30472. }
  30473. class MessageManagerLock::SharedEvents : public ReferenceCountedObject
  30474. {
  30475. public:
  30476. SharedEvents() {}
  30477. ~SharedEvents() {}
  30478. WaitableEvent lockedEvent, releaseEvent;
  30479. private:
  30480. SharedEvents (const SharedEvents&);
  30481. SharedEvents& operator= (const SharedEvents&);
  30482. };
  30483. class MessageManagerLock::BlockingMessage : public CallbackMessage
  30484. {
  30485. public:
  30486. BlockingMessage (MessageManagerLock::SharedEvents* const events_) : events (events_) {}
  30487. ~BlockingMessage() throw() {}
  30488. void messageCallback()
  30489. {
  30490. events->lockedEvent.signal();
  30491. events->releaseEvent.wait();
  30492. }
  30493. juce_UseDebuggingNewOperator
  30494. private:
  30495. ReferenceCountedObjectPtr <MessageManagerLock::SharedEvents> events;
  30496. BlockingMessage (const BlockingMessage&);
  30497. BlockingMessage& operator= (const BlockingMessage&);
  30498. };
  30499. MessageManagerLock::MessageManagerLock (Thread* const threadToCheck) throw()
  30500. : sharedEvents (0),
  30501. locked (false)
  30502. {
  30503. init (threadToCheck, 0);
  30504. }
  30505. MessageManagerLock::MessageManagerLock (ThreadPoolJob* const jobToCheckForExitSignal) throw()
  30506. : sharedEvents (0),
  30507. locked (false)
  30508. {
  30509. init (0, jobToCheckForExitSignal);
  30510. }
  30511. void MessageManagerLock::init (Thread* const threadToCheck, ThreadPoolJob* const job) throw()
  30512. {
  30513. if (MessageManager::instance != 0)
  30514. {
  30515. if (MessageManager::instance->currentThreadHasLockedMessageManager())
  30516. {
  30517. locked = true; // either we're on the message thread, or this is a re-entrant call.
  30518. }
  30519. else
  30520. {
  30521. if (threadToCheck == 0 && job == 0)
  30522. {
  30523. MessageManager::instance->lockingLock.enter();
  30524. }
  30525. else
  30526. {
  30527. while (! MessageManager::instance->lockingLock.tryEnter())
  30528. {
  30529. if ((threadToCheck != 0 && threadToCheck->threadShouldExit())
  30530. || (job != 0 && job->shouldExit()))
  30531. return;
  30532. Thread::sleep (1);
  30533. }
  30534. }
  30535. sharedEvents = new SharedEvents();
  30536. sharedEvents->incReferenceCount();
  30537. (new BlockingMessage (sharedEvents))->post();
  30538. while (! sharedEvents->lockedEvent.wait (50))
  30539. {
  30540. if ((threadToCheck != 0 && threadToCheck->threadShouldExit())
  30541. || (job != 0 && job->shouldExit()))
  30542. {
  30543. sharedEvents->releaseEvent.signal();
  30544. sharedEvents->decReferenceCount();
  30545. sharedEvents = 0;
  30546. MessageManager::instance->lockingLock.exit();
  30547. return;
  30548. }
  30549. }
  30550. jassert (MessageManager::instance->threadWithLock == 0);
  30551. MessageManager::instance->threadWithLock = Thread::getCurrentThreadId();
  30552. locked = true;
  30553. }
  30554. }
  30555. }
  30556. MessageManagerLock::~MessageManagerLock() throw()
  30557. {
  30558. if (sharedEvents != 0)
  30559. {
  30560. jassert (MessageManager::instance == 0 || MessageManager::instance->currentThreadHasLockedMessageManager());
  30561. sharedEvents->releaseEvent.signal();
  30562. sharedEvents->decReferenceCount();
  30563. if (MessageManager::instance != 0)
  30564. {
  30565. MessageManager::instance->threadWithLock = 0;
  30566. MessageManager::instance->lockingLock.exit();
  30567. }
  30568. }
  30569. }
  30570. END_JUCE_NAMESPACE
  30571. /*** End of inlined file: juce_MessageManager.cpp ***/
  30572. /*** Start of inlined file: juce_MultiTimer.cpp ***/
  30573. BEGIN_JUCE_NAMESPACE
  30574. class MultiTimer::MultiTimerCallback : public Timer
  30575. {
  30576. public:
  30577. MultiTimerCallback (const int timerId_, MultiTimer& owner_)
  30578. : timerId (timerId_),
  30579. owner (owner_)
  30580. {
  30581. }
  30582. ~MultiTimerCallback()
  30583. {
  30584. }
  30585. void timerCallback()
  30586. {
  30587. owner.timerCallback (timerId);
  30588. }
  30589. const int timerId;
  30590. private:
  30591. MultiTimer& owner;
  30592. };
  30593. MultiTimer::MultiTimer() throw()
  30594. {
  30595. }
  30596. MultiTimer::MultiTimer (const MultiTimer&) throw()
  30597. {
  30598. }
  30599. MultiTimer::~MultiTimer()
  30600. {
  30601. const ScopedLock sl (timerListLock);
  30602. timers.clear();
  30603. }
  30604. void MultiTimer::startTimer (const int timerId, const int intervalInMilliseconds) throw()
  30605. {
  30606. const ScopedLock sl (timerListLock);
  30607. for (int i = timers.size(); --i >= 0;)
  30608. {
  30609. MultiTimerCallback* const t = timers.getUnchecked(i);
  30610. if (t->timerId == timerId)
  30611. {
  30612. t->startTimer (intervalInMilliseconds);
  30613. return;
  30614. }
  30615. }
  30616. MultiTimerCallback* const newTimer = new MultiTimerCallback (timerId, *this);
  30617. timers.add (newTimer);
  30618. newTimer->startTimer (intervalInMilliseconds);
  30619. }
  30620. void MultiTimer::stopTimer (const int timerId) throw()
  30621. {
  30622. const ScopedLock sl (timerListLock);
  30623. for (int i = timers.size(); --i >= 0;)
  30624. {
  30625. MultiTimerCallback* const t = timers.getUnchecked(i);
  30626. if (t->timerId == timerId)
  30627. t->stopTimer();
  30628. }
  30629. }
  30630. bool MultiTimer::isTimerRunning (const int timerId) const throw()
  30631. {
  30632. const ScopedLock sl (timerListLock);
  30633. for (int i = timers.size(); --i >= 0;)
  30634. {
  30635. const MultiTimerCallback* const t = timers.getUnchecked(i);
  30636. if (t->timerId == timerId)
  30637. return t->isTimerRunning();
  30638. }
  30639. return false;
  30640. }
  30641. int MultiTimer::getTimerInterval (const int timerId) const throw()
  30642. {
  30643. const ScopedLock sl (timerListLock);
  30644. for (int i = timers.size(); --i >= 0;)
  30645. {
  30646. const MultiTimerCallback* const t = timers.getUnchecked(i);
  30647. if (t->timerId == timerId)
  30648. return t->getTimerInterval();
  30649. }
  30650. return 0;
  30651. }
  30652. END_JUCE_NAMESPACE
  30653. /*** End of inlined file: juce_MultiTimer.cpp ***/
  30654. /*** Start of inlined file: juce_Timer.cpp ***/
  30655. BEGIN_JUCE_NAMESPACE
  30656. class InternalTimerThread : private Thread,
  30657. private MessageListener,
  30658. private DeletedAtShutdown,
  30659. private AsyncUpdater
  30660. {
  30661. public:
  30662. InternalTimerThread()
  30663. : Thread ("Juce Timer"),
  30664. firstTimer (0),
  30665. callbackNeeded (false)
  30666. {
  30667. triggerAsyncUpdate();
  30668. }
  30669. ~InternalTimerThread() throw()
  30670. {
  30671. stopThread (4000);
  30672. jassert (instance == this || instance == 0);
  30673. if (instance == this)
  30674. instance = 0;
  30675. }
  30676. void run()
  30677. {
  30678. uint32 lastTime = Time::getMillisecondCounter();
  30679. while (! threadShouldExit())
  30680. {
  30681. const uint32 now = Time::getMillisecondCounter();
  30682. if (now <= lastTime)
  30683. {
  30684. wait (2);
  30685. continue;
  30686. }
  30687. const int elapsed = now - lastTime;
  30688. lastTime = now;
  30689. int timeUntilFirstTimer = 1000;
  30690. {
  30691. const ScopedLock sl (lock);
  30692. decrementAllCounters (elapsed);
  30693. if (firstTimer != 0)
  30694. timeUntilFirstTimer = firstTimer->countdownMs;
  30695. }
  30696. if (timeUntilFirstTimer <= 0)
  30697. {
  30698. if (callbackNeeded.set (true))
  30699. {
  30700. postMessage (new Message());
  30701. const uint32 messageDeliveryTimeout = now + 2000;
  30702. while (callbackNeeded.get())
  30703. {
  30704. wait (4);
  30705. if (threadShouldExit())
  30706. return;
  30707. if (Time::getMillisecondCounter() > messageDeliveryTimeout)
  30708. break;
  30709. }
  30710. }
  30711. }
  30712. else
  30713. {
  30714. // don't wait for too long because running this loop also helps keep the
  30715. // Time::getApproximateMillisecondTimer value stay up-to-date
  30716. wait (jlimit (1, 50, timeUntilFirstTimer));
  30717. }
  30718. }
  30719. }
  30720. void callTimers()
  30721. {
  30722. const ScopedLock sl (lock);
  30723. while (firstTimer != 0 && firstTimer->countdownMs <= 0)
  30724. {
  30725. Timer* const t = firstTimer;
  30726. t->countdownMs = t->periodMs;
  30727. removeTimer (t);
  30728. addTimer (t);
  30729. const ScopedUnlock ul (lock);
  30730. JUCE_TRY
  30731. {
  30732. t->timerCallback();
  30733. }
  30734. JUCE_CATCH_EXCEPTION
  30735. }
  30736. callbackNeeded.set (false);
  30737. }
  30738. void handleMessage (const Message&)
  30739. {
  30740. callTimers();
  30741. }
  30742. void callTimersSynchronously()
  30743. {
  30744. if (! isThreadRunning())
  30745. {
  30746. // (This is relied on by some plugins in cases where the MM has
  30747. // had to restart and the async callback never started)
  30748. cancelPendingUpdate();
  30749. triggerAsyncUpdate();
  30750. }
  30751. callTimers();
  30752. }
  30753. static void callAnyTimersSynchronously()
  30754. {
  30755. if (InternalTimerThread::instance != 0)
  30756. InternalTimerThread::instance->callTimersSynchronously();
  30757. }
  30758. static inline void add (Timer* const tim) throw()
  30759. {
  30760. if (instance == 0)
  30761. instance = new InternalTimerThread();
  30762. const ScopedLock sl (instance->lock);
  30763. instance->addTimer (tim);
  30764. }
  30765. static inline void remove (Timer* const tim) throw()
  30766. {
  30767. if (instance != 0)
  30768. {
  30769. const ScopedLock sl (instance->lock);
  30770. instance->removeTimer (tim);
  30771. }
  30772. }
  30773. static inline void resetCounter (Timer* const tim,
  30774. const int newCounter) throw()
  30775. {
  30776. if (instance != 0)
  30777. {
  30778. tim->countdownMs = newCounter;
  30779. tim->periodMs = newCounter;
  30780. if ((tim->next != 0 && tim->next->countdownMs < tim->countdownMs)
  30781. || (tim->previous != 0 && tim->previous->countdownMs > tim->countdownMs))
  30782. {
  30783. const ScopedLock sl (instance->lock);
  30784. instance->removeTimer (tim);
  30785. instance->addTimer (tim);
  30786. }
  30787. }
  30788. }
  30789. private:
  30790. friend class Timer;
  30791. static InternalTimerThread* instance;
  30792. static CriticalSection lock;
  30793. Timer* volatile firstTimer;
  30794. class AtomicBool
  30795. {
  30796. public:
  30797. AtomicBool (const bool value) throw() : value (static_cast<int32> (value)) {}
  30798. ~AtomicBool() throw() {}
  30799. bool get() const throw() { return value != 0; }
  30800. bool set (const bool newValue) { return Atomic::compareAndExchange (value, newValue ? 1 : 0, value) != 0; }
  30801. private:
  30802. int32 value;
  30803. AtomicBool (const AtomicBool&);
  30804. AtomicBool& operator= (const AtomicBool&);
  30805. };
  30806. AtomicBool callbackNeeded;
  30807. void addTimer (Timer* const t) throw()
  30808. {
  30809. #ifdef JUCE_DEBUG
  30810. Timer* tt = firstTimer;
  30811. while (tt != 0)
  30812. {
  30813. // trying to add a timer that's already here - shouldn't get to this point,
  30814. // so if you get this assertion, let me know!
  30815. jassert (tt != t);
  30816. tt = tt->next;
  30817. }
  30818. jassert (t->previous == 0 && t->next == 0);
  30819. #endif
  30820. Timer* i = firstTimer;
  30821. if (i == 0 || i->countdownMs > t->countdownMs)
  30822. {
  30823. t->next = firstTimer;
  30824. firstTimer = t;
  30825. }
  30826. else
  30827. {
  30828. while (i->next != 0 && i->next->countdownMs <= t->countdownMs)
  30829. i = i->next;
  30830. jassert (i != 0);
  30831. t->next = i->next;
  30832. t->previous = i;
  30833. i->next = t;
  30834. }
  30835. if (t->next != 0)
  30836. t->next->previous = t;
  30837. jassert ((t->next == 0 || t->next->countdownMs >= t->countdownMs)
  30838. && (t->previous == 0 || t->previous->countdownMs <= t->countdownMs));
  30839. notify();
  30840. }
  30841. void removeTimer (Timer* const t) throw()
  30842. {
  30843. #ifdef JUCE_DEBUG
  30844. Timer* tt = firstTimer;
  30845. bool found = false;
  30846. while (tt != 0)
  30847. {
  30848. if (tt == t)
  30849. {
  30850. found = true;
  30851. break;
  30852. }
  30853. tt = tt->next;
  30854. }
  30855. // trying to remove a timer that's not here - shouldn't get to this point,
  30856. // so if you get this assertion, let me know!
  30857. jassert (found);
  30858. #endif
  30859. if (t->previous != 0)
  30860. {
  30861. jassert (firstTimer != t);
  30862. t->previous->next = t->next;
  30863. }
  30864. else
  30865. {
  30866. jassert (firstTimer == t);
  30867. firstTimer = t->next;
  30868. }
  30869. if (t->next != 0)
  30870. t->next->previous = t->previous;
  30871. t->next = 0;
  30872. t->previous = 0;
  30873. }
  30874. void decrementAllCounters (const int numMillisecs) const
  30875. {
  30876. Timer* t = firstTimer;
  30877. while (t != 0)
  30878. {
  30879. t->countdownMs -= numMillisecs;
  30880. t = t->next;
  30881. }
  30882. }
  30883. void handleAsyncUpdate()
  30884. {
  30885. startThread (7);
  30886. }
  30887. InternalTimerThread (const InternalTimerThread&);
  30888. InternalTimerThread& operator= (const InternalTimerThread&);
  30889. };
  30890. InternalTimerThread* InternalTimerThread::instance = 0;
  30891. CriticalSection InternalTimerThread::lock;
  30892. void juce_callAnyTimersSynchronously()
  30893. {
  30894. InternalTimerThread::callAnyTimersSynchronously();
  30895. }
  30896. #ifdef JUCE_DEBUG
  30897. static SortedSet <Timer*> activeTimers;
  30898. #endif
  30899. Timer::Timer() throw()
  30900. : countdownMs (0),
  30901. periodMs (0),
  30902. previous (0),
  30903. next (0)
  30904. {
  30905. #ifdef JUCE_DEBUG
  30906. activeTimers.add (this);
  30907. #endif
  30908. }
  30909. Timer::Timer (const Timer&) throw()
  30910. : countdownMs (0),
  30911. periodMs (0),
  30912. previous (0),
  30913. next (0)
  30914. {
  30915. #ifdef JUCE_DEBUG
  30916. activeTimers.add (this);
  30917. #endif
  30918. }
  30919. Timer::~Timer()
  30920. {
  30921. stopTimer();
  30922. #ifdef JUCE_DEBUG
  30923. activeTimers.removeValue (this);
  30924. #endif
  30925. }
  30926. void Timer::startTimer (const int interval) throw()
  30927. {
  30928. const ScopedLock sl (InternalTimerThread::lock);
  30929. #ifdef JUCE_DEBUG
  30930. // this isn't a valid object! Your timer might be a dangling pointer or something..
  30931. jassert (activeTimers.contains (this));
  30932. #endif
  30933. if (periodMs == 0)
  30934. {
  30935. countdownMs = interval;
  30936. periodMs = jmax (1, interval);
  30937. InternalTimerThread::add (this);
  30938. }
  30939. else
  30940. {
  30941. InternalTimerThread::resetCounter (this, interval);
  30942. }
  30943. }
  30944. void Timer::stopTimer() throw()
  30945. {
  30946. const ScopedLock sl (InternalTimerThread::lock);
  30947. #ifdef JUCE_DEBUG
  30948. // this isn't a valid object! Your timer might be a dangling pointer or something..
  30949. jassert (activeTimers.contains (this));
  30950. #endif
  30951. if (periodMs > 0)
  30952. {
  30953. InternalTimerThread::remove (this);
  30954. periodMs = 0;
  30955. }
  30956. }
  30957. END_JUCE_NAMESPACE
  30958. /*** End of inlined file: juce_Timer.cpp ***/
  30959. #endif
  30960. #if JUCE_BUILD_GUI
  30961. /*** Start of inlined file: juce_Component.cpp ***/
  30962. BEGIN_JUCE_NAMESPACE
  30963. Component* Component::currentlyFocusedComponent = 0;
  30964. static Array <Component*> modalComponentStack, modalComponentReturnValueKeys;
  30965. static Array <int> modalReturnValues;
  30966. enum ComponentMessageNumbers
  30967. {
  30968. customCommandMessage = 0x7fff0001,
  30969. exitModalStateMessage = 0x7fff0002
  30970. };
  30971. #define checkMessageManagerIsLocked jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  30972. static uint32 nextComponentUID = 0;
  30973. Component::Component()
  30974. : parentComponent_ (0),
  30975. componentUID (++nextComponentUID),
  30976. numDeepMouseListeners (0),
  30977. lookAndFeel_ (0),
  30978. effect_ (0),
  30979. bufferedImage_ (0),
  30980. mouseListeners_ (0),
  30981. keyListeners_ (0),
  30982. componentFlags_ (0)
  30983. {
  30984. }
  30985. Component::Component (const String& name)
  30986. : componentName_ (name),
  30987. parentComponent_ (0),
  30988. componentUID (++nextComponentUID),
  30989. numDeepMouseListeners (0),
  30990. lookAndFeel_ (0),
  30991. effect_ (0),
  30992. bufferedImage_ (0),
  30993. mouseListeners_ (0),
  30994. keyListeners_ (0),
  30995. componentFlags_ (0)
  30996. {
  30997. }
  30998. Component::~Component()
  30999. {
  31000. componentListeners.call (&ComponentListener::componentBeingDeleted, *this);
  31001. if (parentComponent_ != 0)
  31002. {
  31003. parentComponent_->removeChildComponent (this);
  31004. }
  31005. else if ((currentlyFocusedComponent == this)
  31006. || isParentOf (currentlyFocusedComponent))
  31007. {
  31008. giveAwayFocus();
  31009. }
  31010. if (flags.hasHeavyweightPeerFlag)
  31011. removeFromDesktop();
  31012. modalComponentStack.removeValue (this);
  31013. for (int i = childComponentList_.size(); --i >= 0;)
  31014. childComponentList_.getUnchecked(i)->parentComponent_ = 0;
  31015. delete bufferedImage_;
  31016. delete mouseListeners_;
  31017. delete keyListeners_;
  31018. }
  31019. void Component::setName (const String& name)
  31020. {
  31021. // if component methods are being called from threads other than the message
  31022. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31023. checkMessageManagerIsLocked
  31024. if (componentName_ != name)
  31025. {
  31026. componentName_ = name;
  31027. if (flags.hasHeavyweightPeerFlag)
  31028. {
  31029. ComponentPeer* const peer = getPeer();
  31030. jassert (peer != 0);
  31031. if (peer != 0)
  31032. peer->setTitle (name);
  31033. }
  31034. BailOutChecker checker (this);
  31035. componentListeners.callChecked (checker, &ComponentListener::componentNameChanged, *this);
  31036. }
  31037. }
  31038. void Component::setVisible (bool shouldBeVisible)
  31039. {
  31040. if (flags.visibleFlag != shouldBeVisible)
  31041. {
  31042. // if component methods are being called from threads other than the message
  31043. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31044. checkMessageManagerIsLocked
  31045. SafePointer<Component> safePointer (this);
  31046. flags.visibleFlag = shouldBeVisible;
  31047. internalRepaint (0, 0, getWidth(), getHeight());
  31048. sendFakeMouseMove();
  31049. if (! shouldBeVisible)
  31050. {
  31051. if (currentlyFocusedComponent == this
  31052. || isParentOf (currentlyFocusedComponent))
  31053. {
  31054. if (parentComponent_ != 0)
  31055. parentComponent_->grabKeyboardFocus();
  31056. else
  31057. giveAwayFocus();
  31058. }
  31059. }
  31060. sendVisibilityChangeMessage();
  31061. if (safePointer != 0 && flags.hasHeavyweightPeerFlag)
  31062. {
  31063. ComponentPeer* const peer = getPeer();
  31064. jassert (peer != 0);
  31065. if (peer != 0)
  31066. {
  31067. peer->setVisible (shouldBeVisible);
  31068. internalHierarchyChanged();
  31069. }
  31070. }
  31071. }
  31072. }
  31073. void Component::visibilityChanged()
  31074. {
  31075. }
  31076. void Component::sendVisibilityChangeMessage()
  31077. {
  31078. BailOutChecker checker (this);
  31079. visibilityChanged();
  31080. if (! checker.shouldBailOut())
  31081. componentListeners.callChecked (checker, &ComponentListener::componentVisibilityChanged, *this);
  31082. }
  31083. bool Component::isShowing() const
  31084. {
  31085. if (flags.visibleFlag)
  31086. {
  31087. if (parentComponent_ != 0)
  31088. {
  31089. return parentComponent_->isShowing();
  31090. }
  31091. else
  31092. {
  31093. const ComponentPeer* const peer = getPeer();
  31094. return peer != 0 && ! peer->isMinimised();
  31095. }
  31096. }
  31097. return false;
  31098. }
  31099. class FadeOutProxyComponent : public Component,
  31100. public Timer
  31101. {
  31102. public:
  31103. FadeOutProxyComponent (Component* comp,
  31104. const int fadeLengthMs,
  31105. const int deltaXToMove,
  31106. const int deltaYToMove,
  31107. const float scaleFactorAtEnd)
  31108. : lastTime (0),
  31109. alpha (1.0f),
  31110. scale (1.0f)
  31111. {
  31112. image = comp->createComponentSnapshot (Rectangle<int> (0, 0, comp->getWidth(), comp->getHeight()));
  31113. setBounds (comp->getBounds());
  31114. comp->getParentComponent()->addAndMakeVisible (this);
  31115. toBehind (comp);
  31116. alphaChangePerMs = -1.0f / (float)fadeLengthMs;
  31117. centreX = comp->getX() + comp->getWidth() * 0.5f;
  31118. xChangePerMs = deltaXToMove / (float)fadeLengthMs;
  31119. centreY = comp->getY() + comp->getHeight() * 0.5f;
  31120. yChangePerMs = deltaYToMove / (float)fadeLengthMs;
  31121. scaleChangePerMs = (scaleFactorAtEnd - 1.0f) / (float)fadeLengthMs;
  31122. setInterceptsMouseClicks (false, false);
  31123. // 30 fps is enough for a fade, but we need a higher rate if it's moving as well..
  31124. startTimer (1000 / ((deltaXToMove == 0 && deltaYToMove == 0) ? 30 : 50));
  31125. }
  31126. ~FadeOutProxyComponent()
  31127. {
  31128. delete image;
  31129. }
  31130. void paint (Graphics& g)
  31131. {
  31132. g.setOpacity (alpha);
  31133. g.drawImage (image,
  31134. 0, 0, getWidth(), getHeight(),
  31135. 0, 0, image->getWidth(), image->getHeight());
  31136. }
  31137. void timerCallback()
  31138. {
  31139. const uint32 now = Time::getMillisecondCounter();
  31140. if (lastTime == 0)
  31141. lastTime = now;
  31142. const int msPassed = (now > lastTime) ? now - lastTime : 0;
  31143. lastTime = now;
  31144. alpha += alphaChangePerMs * msPassed;
  31145. if (alpha > 0)
  31146. {
  31147. if (xChangePerMs != 0.0f || yChangePerMs != 0.0f || scaleChangePerMs != 0.0f)
  31148. {
  31149. centreX += xChangePerMs * msPassed;
  31150. centreY += yChangePerMs * msPassed;
  31151. scale += scaleChangePerMs * msPassed;
  31152. const int w = roundToInt (image->getWidth() * scale);
  31153. const int h = roundToInt (image->getHeight() * scale);
  31154. setBounds (roundToInt (centreX) - w / 2,
  31155. roundToInt (centreY) - h / 2,
  31156. w, h);
  31157. }
  31158. repaint();
  31159. }
  31160. else
  31161. {
  31162. delete this;
  31163. }
  31164. }
  31165. juce_UseDebuggingNewOperator
  31166. private:
  31167. Image* image;
  31168. uint32 lastTime;
  31169. float alpha, alphaChangePerMs;
  31170. float centreX, xChangePerMs;
  31171. float centreY, yChangePerMs;
  31172. float scale, scaleChangePerMs;
  31173. FadeOutProxyComponent (const FadeOutProxyComponent&);
  31174. FadeOutProxyComponent& operator= (const FadeOutProxyComponent&);
  31175. };
  31176. void Component::fadeOutComponent (const int millisecondsToFade,
  31177. const int deltaXToMove,
  31178. const int deltaYToMove,
  31179. const float scaleFactorAtEnd)
  31180. {
  31181. //xxx won't work for comps without parents
  31182. if (isShowing() && millisecondsToFade > 0)
  31183. new FadeOutProxyComponent (this, millisecondsToFade,
  31184. deltaXToMove, deltaYToMove, scaleFactorAtEnd);
  31185. setVisible (false);
  31186. }
  31187. bool Component::isValidComponent() const
  31188. {
  31189. return (this != 0) && isValidMessageListener();
  31190. }
  31191. void* Component::getWindowHandle() const
  31192. {
  31193. const ComponentPeer* const peer = getPeer();
  31194. if (peer != 0)
  31195. return peer->getNativeHandle();
  31196. return 0;
  31197. }
  31198. void Component::addToDesktop (int styleWanted, void* nativeWindowToAttachTo)
  31199. {
  31200. // if component methods are being called from threads other than the message
  31201. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31202. checkMessageManagerIsLocked
  31203. if (isOpaque())
  31204. styleWanted &= ~ComponentPeer::windowIsSemiTransparent;
  31205. else
  31206. styleWanted |= ComponentPeer::windowIsSemiTransparent;
  31207. int currentStyleFlags = 0;
  31208. // don't use getPeer(), so that we only get the peer that's specifically
  31209. // for this comp, and not for one of its parents.
  31210. ComponentPeer* peer = ComponentPeer::getPeerFor (this);
  31211. if (peer != 0)
  31212. currentStyleFlags = peer->getStyleFlags();
  31213. if (styleWanted != currentStyleFlags || ! flags.hasHeavyweightPeerFlag)
  31214. {
  31215. SafePointer<Component> safePointer (this);
  31216. #if JUCE_LINUX
  31217. // it's wise to give the component a non-zero size before
  31218. // putting it on the desktop, as X windows get confused by this, and
  31219. // a (1, 1) minimum size is enforced here.
  31220. setSize (jmax (1, getWidth()),
  31221. jmax (1, getHeight()));
  31222. #endif
  31223. const Point<int> topLeft (relativePositionToGlobal (Point<int> (0, 0)));
  31224. bool wasFullscreen = false;
  31225. bool wasMinimised = false;
  31226. ComponentBoundsConstrainer* currentConstainer = 0;
  31227. Rectangle<int> oldNonFullScreenBounds;
  31228. if (peer != 0)
  31229. {
  31230. wasFullscreen = peer->isFullScreen();
  31231. wasMinimised = peer->isMinimised();
  31232. currentConstainer = peer->getConstrainer();
  31233. oldNonFullScreenBounds = peer->getNonFullScreenBounds();
  31234. removeFromDesktop();
  31235. setTopLeftPosition (topLeft.getX(), topLeft.getY());
  31236. }
  31237. if (parentComponent_ != 0)
  31238. parentComponent_->removeChildComponent (this);
  31239. if (safePointer != 0)
  31240. {
  31241. flags.hasHeavyweightPeerFlag = true;
  31242. peer = createNewPeer (styleWanted, nativeWindowToAttachTo);
  31243. Desktop::getInstance().addDesktopComponent (this);
  31244. bounds_.setPosition (topLeft);
  31245. peer->setBounds (topLeft.getX(), topLeft.getY(), getWidth(), getHeight(), false);
  31246. peer->setVisible (isVisible());
  31247. if (wasFullscreen)
  31248. {
  31249. peer->setFullScreen (true);
  31250. peer->setNonFullScreenBounds (oldNonFullScreenBounds);
  31251. }
  31252. if (wasMinimised)
  31253. peer->setMinimised (true);
  31254. if (isAlwaysOnTop())
  31255. peer->setAlwaysOnTop (true);
  31256. peer->setConstrainer (currentConstainer);
  31257. repaint();
  31258. }
  31259. internalHierarchyChanged();
  31260. }
  31261. }
  31262. void Component::removeFromDesktop()
  31263. {
  31264. // if component methods are being called from threads other than the message
  31265. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31266. checkMessageManagerIsLocked
  31267. if (flags.hasHeavyweightPeerFlag)
  31268. {
  31269. ComponentPeer* const peer = ComponentPeer::getPeerFor (this);
  31270. flags.hasHeavyweightPeerFlag = false;
  31271. jassert (peer != 0);
  31272. delete peer;
  31273. Desktop::getInstance().removeDesktopComponent (this);
  31274. }
  31275. }
  31276. bool Component::isOnDesktop() const throw()
  31277. {
  31278. return flags.hasHeavyweightPeerFlag;
  31279. }
  31280. void Component::userTriedToCloseWindow()
  31281. {
  31282. /* This means that the user's trying to get rid of your window with the 'close window' system
  31283. menu option (on windows) or possibly the task manager - you should really handle this
  31284. and delete or hide your component in an appropriate way.
  31285. If you want to ignore the event and don't want to trigger this assertion, just override
  31286. this method and do nothing.
  31287. */
  31288. jassertfalse
  31289. }
  31290. void Component::minimisationStateChanged (bool)
  31291. {
  31292. }
  31293. void Component::setOpaque (const bool shouldBeOpaque)
  31294. {
  31295. if (shouldBeOpaque != flags.opaqueFlag)
  31296. {
  31297. flags.opaqueFlag = shouldBeOpaque;
  31298. if (flags.hasHeavyweightPeerFlag)
  31299. {
  31300. const ComponentPeer* const peer = ComponentPeer::getPeerFor (this);
  31301. if (peer != 0)
  31302. {
  31303. // to make it recreate the heavyweight window
  31304. addToDesktop (peer->getStyleFlags());
  31305. }
  31306. }
  31307. repaint();
  31308. }
  31309. }
  31310. bool Component::isOpaque() const throw()
  31311. {
  31312. return flags.opaqueFlag;
  31313. }
  31314. void Component::setBufferedToImage (const bool shouldBeBuffered)
  31315. {
  31316. if (shouldBeBuffered != flags.bufferToImageFlag)
  31317. {
  31318. deleteAndZero (bufferedImage_);
  31319. flags.bufferToImageFlag = shouldBeBuffered;
  31320. }
  31321. }
  31322. void Component::toFront (const bool setAsForeground)
  31323. {
  31324. // if component methods are being called from threads other than the message
  31325. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31326. checkMessageManagerIsLocked
  31327. if (flags.hasHeavyweightPeerFlag)
  31328. {
  31329. ComponentPeer* const peer = getPeer();
  31330. if (peer != 0)
  31331. {
  31332. peer->toFront (setAsForeground);
  31333. if (setAsForeground && ! hasKeyboardFocus (true))
  31334. grabKeyboardFocus();
  31335. }
  31336. }
  31337. else if (parentComponent_ != 0)
  31338. {
  31339. if (parentComponent_->childComponentList_.getLast() != this)
  31340. {
  31341. const int index = parentComponent_->childComponentList_.indexOf (this);
  31342. if (index >= 0)
  31343. {
  31344. int insertIndex = -1;
  31345. if (! flags.alwaysOnTopFlag)
  31346. {
  31347. insertIndex = parentComponent_->childComponentList_.size() - 1;
  31348. while (insertIndex > 0
  31349. && parentComponent_->childComponentList_.getUnchecked (insertIndex)->isAlwaysOnTop())
  31350. {
  31351. --insertIndex;
  31352. }
  31353. }
  31354. if (index != insertIndex)
  31355. {
  31356. parentComponent_->childComponentList_.move (index, insertIndex);
  31357. sendFakeMouseMove();
  31358. repaintParent();
  31359. }
  31360. }
  31361. }
  31362. if (setAsForeground)
  31363. {
  31364. internalBroughtToFront();
  31365. grabKeyboardFocus();
  31366. }
  31367. }
  31368. }
  31369. void Component::toBehind (Component* const other)
  31370. {
  31371. if (other != 0)
  31372. {
  31373. // the two components must belong to the same parent..
  31374. jassert (parentComponent_ == other->parentComponent_);
  31375. if (parentComponent_ != 0)
  31376. {
  31377. const int index = parentComponent_->childComponentList_.indexOf (this);
  31378. int otherIndex = parentComponent_->childComponentList_.indexOf (other);
  31379. if (index >= 0
  31380. && otherIndex >= 0
  31381. && index != otherIndex - 1
  31382. && other != this)
  31383. {
  31384. if (index < otherIndex)
  31385. --otherIndex;
  31386. parentComponent_->childComponentList_.move (index, otherIndex);
  31387. sendFakeMouseMove();
  31388. repaintParent();
  31389. }
  31390. }
  31391. else if (isOnDesktop())
  31392. {
  31393. jassert (other->isOnDesktop());
  31394. if (other->isOnDesktop())
  31395. {
  31396. ComponentPeer* const us = getPeer();
  31397. ComponentPeer* const them = other->getPeer();
  31398. jassert (us != 0 && them != 0);
  31399. if (us != 0 && them != 0)
  31400. us->toBehind (them);
  31401. }
  31402. }
  31403. }
  31404. }
  31405. void Component::toBack()
  31406. {
  31407. if (isOnDesktop())
  31408. {
  31409. jassertfalse //xxx need to add this to native window
  31410. }
  31411. else if (parentComponent_ != 0
  31412. && parentComponent_->childComponentList_.getFirst() != this)
  31413. {
  31414. const int index = parentComponent_->childComponentList_.indexOf (this);
  31415. if (index > 0)
  31416. {
  31417. int insertIndex = 0;
  31418. if (flags.alwaysOnTopFlag)
  31419. {
  31420. while (insertIndex < parentComponent_->childComponentList_.size()
  31421. && ! parentComponent_->childComponentList_.getUnchecked (insertIndex)->isAlwaysOnTop())
  31422. {
  31423. ++insertIndex;
  31424. }
  31425. }
  31426. if (index != insertIndex)
  31427. {
  31428. parentComponent_->childComponentList_.move (index, insertIndex);
  31429. sendFakeMouseMove();
  31430. repaintParent();
  31431. }
  31432. }
  31433. }
  31434. }
  31435. void Component::setAlwaysOnTop (const bool shouldStayOnTop)
  31436. {
  31437. if (shouldStayOnTop != flags.alwaysOnTopFlag)
  31438. {
  31439. flags.alwaysOnTopFlag = shouldStayOnTop;
  31440. if (isOnDesktop())
  31441. {
  31442. ComponentPeer* const peer = getPeer();
  31443. jassert (peer != 0);
  31444. if (peer != 0)
  31445. {
  31446. if (! peer->setAlwaysOnTop (shouldStayOnTop))
  31447. {
  31448. // some kinds of peer can't change their always-on-top status, so
  31449. // for these, we'll need to create a new window
  31450. const int oldFlags = peer->getStyleFlags();
  31451. removeFromDesktop();
  31452. addToDesktop (oldFlags);
  31453. }
  31454. }
  31455. }
  31456. if (shouldStayOnTop)
  31457. toFront (false);
  31458. internalHierarchyChanged();
  31459. }
  31460. }
  31461. bool Component::isAlwaysOnTop() const throw()
  31462. {
  31463. return flags.alwaysOnTopFlag;
  31464. }
  31465. int Component::proportionOfWidth (const float proportion) const throw()
  31466. {
  31467. return roundToInt (proportion * bounds_.getWidth());
  31468. }
  31469. int Component::proportionOfHeight (const float proportion) const throw()
  31470. {
  31471. return roundToInt (proportion * bounds_.getHeight());
  31472. }
  31473. int Component::getParentWidth() const throw()
  31474. {
  31475. return (parentComponent_ != 0) ? parentComponent_->getWidth()
  31476. : getParentMonitorArea().getWidth();
  31477. }
  31478. int Component::getParentHeight() const throw()
  31479. {
  31480. return (parentComponent_ != 0) ? parentComponent_->getHeight()
  31481. : getParentMonitorArea().getHeight();
  31482. }
  31483. int Component::getScreenX() const
  31484. {
  31485. return getScreenPosition().getX();
  31486. }
  31487. int Component::getScreenY() const
  31488. {
  31489. return getScreenPosition().getY();
  31490. }
  31491. const Point<int> Component::getScreenPosition() const
  31492. {
  31493. return (parentComponent_ != 0) ? parentComponent_->getScreenPosition() + getPosition()
  31494. : (flags.hasHeavyweightPeerFlag ? getPeer()->getScreenPosition()
  31495. : getPosition());
  31496. }
  31497. const Rectangle<int> Component::getScreenBounds() const
  31498. {
  31499. return bounds_.withPosition (getScreenPosition());
  31500. }
  31501. const Point<int> Component::relativePositionToGlobal (const Point<int>& relativePosition) const
  31502. {
  31503. const Component* c = this;
  31504. Point<int> p (relativePosition);
  31505. do
  31506. {
  31507. if (c->flags.hasHeavyweightPeerFlag)
  31508. return c->getPeer()->relativePositionToGlobal (p);
  31509. p += c->getPosition();
  31510. c = c->parentComponent_;
  31511. }
  31512. while (c != 0);
  31513. return p;
  31514. }
  31515. const Point<int> Component::globalPositionToRelative (const Point<int>& screenPosition) const
  31516. {
  31517. if (flags.hasHeavyweightPeerFlag)
  31518. {
  31519. return getPeer()->globalPositionToRelative (screenPosition);
  31520. }
  31521. else
  31522. {
  31523. if (parentComponent_ != 0)
  31524. return parentComponent_->globalPositionToRelative (screenPosition) - getPosition();
  31525. return screenPosition - getPosition();
  31526. }
  31527. }
  31528. const Point<int> Component::relativePositionToOtherComponent (const Component* const targetComponent, const Point<int>& positionRelativeToThis) const
  31529. {
  31530. Point<int> p (positionRelativeToThis);
  31531. if (targetComponent != 0)
  31532. {
  31533. const Component* c = this;
  31534. do
  31535. {
  31536. if (c == targetComponent)
  31537. return p;
  31538. if (c->flags.hasHeavyweightPeerFlag)
  31539. {
  31540. p = c->getPeer()->relativePositionToGlobal (p);
  31541. break;
  31542. }
  31543. p += c->getPosition();
  31544. c = c->parentComponent_;
  31545. }
  31546. while (c != 0);
  31547. p = targetComponent->globalPositionToRelative (p);
  31548. }
  31549. return p;
  31550. }
  31551. void Component::setBounds (int x, int y, int w, int h)
  31552. {
  31553. // if component methods are being called from threads other than the message
  31554. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31555. checkMessageManagerIsLocked
  31556. if (w < 0) w = 0;
  31557. if (h < 0) h = 0;
  31558. const bool wasResized = (getWidth() != w || getHeight() != h);
  31559. const bool wasMoved = (getX() != x || getY() != y);
  31560. #ifdef JUCE_DEBUG
  31561. // It's a very bad idea to try to resize a window during its paint() method!
  31562. jassert (! (flags.isInsidePaintCall && wasResized && isOnDesktop()));
  31563. #endif
  31564. if (wasMoved || wasResized)
  31565. {
  31566. if (flags.visibleFlag)
  31567. {
  31568. // send a fake mouse move to trigger enter/exit messages if needed..
  31569. sendFakeMouseMove();
  31570. if (! flags.hasHeavyweightPeerFlag)
  31571. repaintParent();
  31572. }
  31573. bounds_.setBounds (x, y, w, h);
  31574. if (wasResized)
  31575. repaint();
  31576. else if (! flags.hasHeavyweightPeerFlag)
  31577. repaintParent();
  31578. if (flags.hasHeavyweightPeerFlag)
  31579. {
  31580. ComponentPeer* const peer = getPeer();
  31581. if (peer != 0)
  31582. {
  31583. if (wasMoved && wasResized)
  31584. peer->setBounds (getX(), getY(), getWidth(), getHeight(), false);
  31585. else if (wasMoved)
  31586. peer->setPosition (getX(), getY());
  31587. else if (wasResized)
  31588. peer->setSize (getWidth(), getHeight());
  31589. }
  31590. }
  31591. sendMovedResizedMessages (wasMoved, wasResized);
  31592. }
  31593. }
  31594. void Component::sendMovedResizedMessages (const bool wasMoved, const bool wasResized)
  31595. {
  31596. JUCE_TRY
  31597. {
  31598. if (wasMoved)
  31599. moved();
  31600. if (wasResized)
  31601. {
  31602. resized();
  31603. for (int i = childComponentList_.size(); --i >= 0;)
  31604. {
  31605. childComponentList_.getUnchecked(i)->parentSizeChanged();
  31606. i = jmin (i, childComponentList_.size());
  31607. }
  31608. }
  31609. BailOutChecker checker (this);
  31610. if (parentComponent_ != 0)
  31611. parentComponent_->childBoundsChanged (this);
  31612. if (! checker.shouldBailOut())
  31613. componentListeners.callChecked (checker, &ComponentListener::componentMovedOrResized,
  31614. *this, wasMoved, wasResized);
  31615. }
  31616. JUCE_CATCH_EXCEPTION
  31617. }
  31618. void Component::setSize (const int w, const int h)
  31619. {
  31620. setBounds (getX(), getY(), w, h);
  31621. }
  31622. void Component::setTopLeftPosition (const int x, const int y)
  31623. {
  31624. setBounds (x, y, getWidth(), getHeight());
  31625. }
  31626. void Component::setTopRightPosition (const int x, const int y)
  31627. {
  31628. setTopLeftPosition (x - getWidth(), y);
  31629. }
  31630. void Component::setBounds (const Rectangle<int>& r)
  31631. {
  31632. setBounds (r.getX(),
  31633. r.getY(),
  31634. r.getWidth(),
  31635. r.getHeight());
  31636. }
  31637. void Component::setBoundsRelative (const float x, const float y,
  31638. const float w, const float h)
  31639. {
  31640. const int pw = getParentWidth();
  31641. const int ph = getParentHeight();
  31642. setBounds (roundToInt (x * pw),
  31643. roundToInt (y * ph),
  31644. roundToInt (w * pw),
  31645. roundToInt (h * ph));
  31646. }
  31647. void Component::setCentrePosition (const int x, const int y)
  31648. {
  31649. setTopLeftPosition (x - getWidth() / 2,
  31650. y - getHeight() / 2);
  31651. }
  31652. void Component::setCentreRelative (const float x, const float y)
  31653. {
  31654. setCentrePosition (roundToInt (getParentWidth() * x),
  31655. roundToInt (getParentHeight() * y));
  31656. }
  31657. void Component::centreWithSize (const int width, const int height)
  31658. {
  31659. setBounds ((getParentWidth() - width) / 2,
  31660. (getParentHeight() - height) / 2,
  31661. width,
  31662. height);
  31663. }
  31664. void Component::setBoundsInset (const BorderSize& borders)
  31665. {
  31666. setBounds (borders.getLeft(),
  31667. borders.getTop(),
  31668. getParentWidth() - (borders.getLeftAndRight()),
  31669. getParentHeight() - (borders.getTopAndBottom()));
  31670. }
  31671. void Component::setBoundsToFit (int x, int y, int width, int height,
  31672. const Justification& justification,
  31673. const bool onlyReduceInSize)
  31674. {
  31675. // it's no good calling this method unless both the component and
  31676. // target rectangle have a finite size.
  31677. jassert (getWidth() > 0 && getHeight() > 0 && width > 0 && height > 0);
  31678. if (getWidth() > 0 && getHeight() > 0
  31679. && width > 0 && height > 0)
  31680. {
  31681. int newW, newH;
  31682. if (onlyReduceInSize && getWidth() <= width && getHeight() <= height)
  31683. {
  31684. newW = getWidth();
  31685. newH = getHeight();
  31686. }
  31687. else
  31688. {
  31689. const double imageRatio = getHeight() / (double) getWidth();
  31690. const double targetRatio = height / (double) width;
  31691. if (imageRatio <= targetRatio)
  31692. {
  31693. newW = width;
  31694. newH = jmin (height, roundToInt (newW * imageRatio));
  31695. }
  31696. else
  31697. {
  31698. newH = height;
  31699. newW = jmin (width, roundToInt (newH / imageRatio));
  31700. }
  31701. }
  31702. if (newW > 0 && newH > 0)
  31703. {
  31704. int newX, newY;
  31705. justification.applyToRectangle (newX, newY, newW, newH,
  31706. x, y, width, height);
  31707. setBounds (newX, newY, newW, newH);
  31708. }
  31709. }
  31710. }
  31711. bool Component::hitTest (int x, int y)
  31712. {
  31713. if (! flags.ignoresMouseClicksFlag)
  31714. return true;
  31715. if (flags.allowChildMouseClicksFlag)
  31716. {
  31717. for (int i = getNumChildComponents(); --i >= 0;)
  31718. {
  31719. Component* const c = getChildComponent (i);
  31720. if (c->isVisible()
  31721. && c->bounds_.contains (x, y)
  31722. && c->hitTest (x - c->getX(),
  31723. y - c->getY()))
  31724. {
  31725. return true;
  31726. }
  31727. }
  31728. }
  31729. return false;
  31730. }
  31731. void Component::setInterceptsMouseClicks (const bool allowClicks,
  31732. const bool allowClicksOnChildComponents) throw()
  31733. {
  31734. flags.ignoresMouseClicksFlag = ! allowClicks;
  31735. flags.allowChildMouseClicksFlag = allowClicksOnChildComponents;
  31736. }
  31737. void Component::getInterceptsMouseClicks (bool& allowsClicksOnThisComponent,
  31738. bool& allowsClicksOnChildComponents) const throw()
  31739. {
  31740. allowsClicksOnThisComponent = ! flags.ignoresMouseClicksFlag;
  31741. allowsClicksOnChildComponents = flags.allowChildMouseClicksFlag;
  31742. }
  31743. bool Component::contains (const int x, const int y)
  31744. {
  31745. if (((unsigned int) x) < (unsigned int) getWidth()
  31746. && ((unsigned int) y) < (unsigned int) getHeight()
  31747. && hitTest (x, y))
  31748. {
  31749. if (parentComponent_ != 0)
  31750. {
  31751. return parentComponent_->contains (x + getX(),
  31752. y + getY());
  31753. }
  31754. else if (flags.hasHeavyweightPeerFlag)
  31755. {
  31756. const ComponentPeer* const peer = getPeer();
  31757. if (peer != 0)
  31758. return peer->contains (Point<int> (x, y), true);
  31759. }
  31760. }
  31761. return false;
  31762. }
  31763. bool Component::reallyContains (int x, int y, const bool returnTrueIfWithinAChild)
  31764. {
  31765. if (! contains (x, y))
  31766. return false;
  31767. Component* p = this;
  31768. while (p->parentComponent_ != 0)
  31769. {
  31770. x += p->getX();
  31771. y += p->getY();
  31772. p = p->parentComponent_;
  31773. }
  31774. const Component* const c = p->getComponentAt (x, y);
  31775. return (c == this) || (returnTrueIfWithinAChild && isParentOf (c));
  31776. }
  31777. Component* Component::getComponentAt (const Point<int>& position)
  31778. {
  31779. return getComponentAt (position.getX(), position.getY());
  31780. }
  31781. Component* Component::getComponentAt (const int x, const int y)
  31782. {
  31783. if (flags.visibleFlag
  31784. && ((unsigned int) x) < (unsigned int) getWidth()
  31785. && ((unsigned int) y) < (unsigned int) getHeight()
  31786. && hitTest (x, y))
  31787. {
  31788. for (int i = childComponentList_.size(); --i >= 0;)
  31789. {
  31790. Component* const child = childComponentList_.getUnchecked(i);
  31791. Component* const c = child->getComponentAt (x - child->getX(),
  31792. y - child->getY());
  31793. if (c != 0)
  31794. return c;
  31795. }
  31796. return this;
  31797. }
  31798. return 0;
  31799. }
  31800. void Component::addChildComponent (Component* const child, int zOrder)
  31801. {
  31802. // if component methods are being called from threads other than the message
  31803. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31804. checkMessageManagerIsLocked
  31805. if (child != 0 && child->parentComponent_ != this)
  31806. {
  31807. if (child->parentComponent_ != 0)
  31808. child->parentComponent_->removeChildComponent (child);
  31809. else
  31810. child->removeFromDesktop();
  31811. child->parentComponent_ = this;
  31812. if (child->isVisible())
  31813. child->repaintParent();
  31814. if (! child->isAlwaysOnTop())
  31815. {
  31816. if (zOrder < 0 || zOrder > childComponentList_.size())
  31817. zOrder = childComponentList_.size();
  31818. while (zOrder > 0)
  31819. {
  31820. if (! childComponentList_.getUnchecked (zOrder - 1)->isAlwaysOnTop())
  31821. break;
  31822. --zOrder;
  31823. }
  31824. }
  31825. childComponentList_.insert (zOrder, child);
  31826. child->internalHierarchyChanged();
  31827. internalChildrenChanged();
  31828. }
  31829. }
  31830. void Component::addAndMakeVisible (Component* const child, int zOrder)
  31831. {
  31832. if (child != 0)
  31833. {
  31834. child->setVisible (true);
  31835. addChildComponent (child, zOrder);
  31836. }
  31837. }
  31838. void Component::removeChildComponent (Component* const child)
  31839. {
  31840. removeChildComponent (childComponentList_.indexOf (child));
  31841. }
  31842. Component* Component::removeChildComponent (const int index)
  31843. {
  31844. // if component methods are being called from threads other than the message
  31845. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31846. checkMessageManagerIsLocked
  31847. Component* const child = childComponentList_ [index];
  31848. if (child != 0)
  31849. {
  31850. sendFakeMouseMove();
  31851. child->repaintParent();
  31852. childComponentList_.remove (index);
  31853. child->parentComponent_ = 0;
  31854. JUCE_TRY
  31855. {
  31856. if ((currentlyFocusedComponent == child)
  31857. || child->isParentOf (currentlyFocusedComponent))
  31858. {
  31859. // get rid first to force the grabKeyboardFocus to change to us.
  31860. giveAwayFocus();
  31861. grabKeyboardFocus();
  31862. }
  31863. }
  31864. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  31865. catch (const std::exception& e)
  31866. {
  31867. currentlyFocusedComponent = 0;
  31868. Desktop::getInstance().triggerFocusCallback();
  31869. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__);
  31870. }
  31871. catch (...)
  31872. {
  31873. currentlyFocusedComponent = 0;
  31874. Desktop::getInstance().triggerFocusCallback();
  31875. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__);
  31876. }
  31877. #endif
  31878. child->internalHierarchyChanged();
  31879. internalChildrenChanged();
  31880. }
  31881. return child;
  31882. }
  31883. void Component::removeAllChildren()
  31884. {
  31885. for (int i = childComponentList_.size(); --i >= 0;)
  31886. removeChildComponent (i);
  31887. }
  31888. void Component::deleteAllChildren()
  31889. {
  31890. for (int i = childComponentList_.size(); --i >= 0;)
  31891. delete (removeChildComponent (i));
  31892. }
  31893. int Component::getNumChildComponents() const throw()
  31894. {
  31895. return childComponentList_.size();
  31896. }
  31897. Component* Component::getChildComponent (const int index) const throw()
  31898. {
  31899. return childComponentList_ [index];
  31900. }
  31901. int Component::getIndexOfChildComponent (const Component* const child) const throw()
  31902. {
  31903. return childComponentList_.indexOf (const_cast <Component*> (child));
  31904. }
  31905. Component* Component::getTopLevelComponent() const throw()
  31906. {
  31907. const Component* comp = this;
  31908. while (comp->parentComponent_ != 0)
  31909. comp = comp->parentComponent_;
  31910. return const_cast <Component*> (comp);
  31911. }
  31912. bool Component::isParentOf (const Component* possibleChild) const throw()
  31913. {
  31914. if (! possibleChild->isValidComponent())
  31915. {
  31916. jassert (possibleChild == 0);
  31917. return false;
  31918. }
  31919. while (possibleChild != 0)
  31920. {
  31921. possibleChild = possibleChild->parentComponent_;
  31922. if (possibleChild == this)
  31923. return true;
  31924. }
  31925. return false;
  31926. }
  31927. void Component::parentHierarchyChanged()
  31928. {
  31929. }
  31930. void Component::childrenChanged()
  31931. {
  31932. }
  31933. void Component::internalChildrenChanged()
  31934. {
  31935. if (componentListeners.isEmpty())
  31936. {
  31937. childrenChanged();
  31938. }
  31939. else
  31940. {
  31941. BailOutChecker checker (this);
  31942. childrenChanged();
  31943. if (! checker.shouldBailOut())
  31944. componentListeners.callChecked (checker, &ComponentListener::componentChildrenChanged, *this);
  31945. }
  31946. }
  31947. void Component::internalHierarchyChanged()
  31948. {
  31949. BailOutChecker checker (this);
  31950. parentHierarchyChanged();
  31951. if (checker.shouldBailOut())
  31952. return;
  31953. componentListeners.callChecked (checker, &ComponentListener::componentParentHierarchyChanged, *this);
  31954. if (checker.shouldBailOut())
  31955. return;
  31956. for (int i = childComponentList_.size(); --i >= 0;)
  31957. {
  31958. childComponentList_.getUnchecked (i)->internalHierarchyChanged();
  31959. if (checker.shouldBailOut())
  31960. {
  31961. // you really shouldn't delete the parent component during a callback telling you
  31962. // that it's changed..
  31963. jassertfalse;
  31964. return;
  31965. }
  31966. i = jmin (i, childComponentList_.size());
  31967. }
  31968. }
  31969. void* Component::runModalLoopCallback (void* userData)
  31970. {
  31971. return (void*) (pointer_sized_int) ((Component*) userData)->runModalLoop();
  31972. }
  31973. int Component::runModalLoop()
  31974. {
  31975. if (! MessageManager::getInstance()->isThisTheMessageThread())
  31976. {
  31977. // use a callback so this can be called from non-gui threads
  31978. return (int) (pointer_sized_int)
  31979. MessageManager::getInstance()
  31980. ->callFunctionOnMessageThread (&runModalLoopCallback, (void*) this);
  31981. }
  31982. SafePointer<Component> prevFocused (getCurrentlyFocusedComponent());
  31983. if (! isCurrentlyModal())
  31984. enterModalState();
  31985. JUCE_TRY
  31986. {
  31987. while (flags.currentlyModalFlag && flags.visibleFlag)
  31988. {
  31989. if (! MessageManager::getInstance()->runDispatchLoopUntil (20))
  31990. break;
  31991. // check whether this component was deleted during the last message
  31992. if (! isValidMessageListener())
  31993. break;
  31994. }
  31995. }
  31996. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  31997. catch (const std::exception& e)
  31998. {
  31999. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__);
  32000. return 0;
  32001. }
  32002. catch (...)
  32003. {
  32004. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__);
  32005. return 0;
  32006. }
  32007. #endif
  32008. const int modalIndex = modalComponentReturnValueKeys.indexOf (this);
  32009. int returnValue = 0;
  32010. if (modalIndex >= 0)
  32011. {
  32012. modalComponentReturnValueKeys.remove (modalIndex);
  32013. returnValue = modalReturnValues.remove (modalIndex);
  32014. }
  32015. modalComponentStack.removeValue (this);
  32016. if (prevFocused != 0)
  32017. prevFocused->grabKeyboardFocus();
  32018. return returnValue;
  32019. }
  32020. void Component::enterModalState (const bool takeKeyboardFocus_)
  32021. {
  32022. // if component methods are being called from threads other than the message
  32023. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32024. checkMessageManagerIsLocked
  32025. // Check for an attempt to make a component modal when it already is!
  32026. // This can cause nasty problems..
  32027. jassert (! flags.currentlyModalFlag);
  32028. if (! isCurrentlyModal())
  32029. {
  32030. modalComponentStack.add (this);
  32031. modalComponentReturnValueKeys.add (this);
  32032. modalReturnValues.add (0);
  32033. flags.currentlyModalFlag = true;
  32034. setVisible (true);
  32035. if (takeKeyboardFocus_)
  32036. grabKeyboardFocus();
  32037. }
  32038. }
  32039. void Component::exitModalState (const int returnValue)
  32040. {
  32041. if (isCurrentlyModal())
  32042. {
  32043. if (MessageManager::getInstance()->isThisTheMessageThread())
  32044. {
  32045. const int modalIndex = modalComponentReturnValueKeys.indexOf (this);
  32046. if (modalIndex >= 0)
  32047. {
  32048. modalReturnValues.set (modalIndex, returnValue);
  32049. }
  32050. else
  32051. {
  32052. modalComponentReturnValueKeys.add (this);
  32053. modalReturnValues.add (returnValue);
  32054. }
  32055. modalComponentStack.removeValue (this);
  32056. flags.currentlyModalFlag = false;
  32057. bringModalComponentToFront();
  32058. }
  32059. else
  32060. {
  32061. postMessage (new Message (exitModalStateMessage, returnValue, 0, 0));
  32062. }
  32063. }
  32064. }
  32065. bool Component::isCurrentlyModal() const throw()
  32066. {
  32067. return flags.currentlyModalFlag
  32068. && getCurrentlyModalComponent() == this;
  32069. }
  32070. bool Component::isCurrentlyBlockedByAnotherModalComponent() const
  32071. {
  32072. Component* const mc = getCurrentlyModalComponent();
  32073. return mc != 0
  32074. && mc != this
  32075. && (! mc->isParentOf (this))
  32076. && ! mc->canModalEventBeSentToComponent (this);
  32077. }
  32078. int JUCE_CALLTYPE Component::getNumCurrentlyModalComponents() throw()
  32079. {
  32080. return modalComponentStack.size();
  32081. }
  32082. Component* JUCE_CALLTYPE Component::getCurrentlyModalComponent (int index) throw()
  32083. {
  32084. Component* const c = static_cast <Component*> (modalComponentStack [modalComponentStack.size() - index - 1]);
  32085. return c->isValidComponent() ? c : 0;
  32086. }
  32087. void Component::bringModalComponentToFront()
  32088. {
  32089. ComponentPeer* lastOne = 0;
  32090. for (int i = 0; i < getNumCurrentlyModalComponents(); ++i)
  32091. {
  32092. Component* const c = getCurrentlyModalComponent (i);
  32093. if (c == 0)
  32094. break;
  32095. ComponentPeer* peer = c->getPeer();
  32096. if (peer != 0 && peer != lastOne)
  32097. {
  32098. if (lastOne == 0)
  32099. {
  32100. peer->toFront (true);
  32101. peer->grabFocus();
  32102. }
  32103. else
  32104. peer->toBehind (lastOne);
  32105. lastOne = peer;
  32106. }
  32107. }
  32108. }
  32109. void Component::setBroughtToFrontOnMouseClick (const bool shouldBeBroughtToFront) throw()
  32110. {
  32111. flags.bringToFrontOnClickFlag = shouldBeBroughtToFront;
  32112. }
  32113. bool Component::isBroughtToFrontOnMouseClick() const throw()
  32114. {
  32115. return flags.bringToFrontOnClickFlag;
  32116. }
  32117. void Component::setMouseCursor (const MouseCursor& cursor)
  32118. {
  32119. cursor_ = cursor;
  32120. if (flags.visibleFlag)
  32121. sendFakeMouseMove();
  32122. }
  32123. const MouseCursor Component::getMouseCursor()
  32124. {
  32125. return cursor_;
  32126. }
  32127. void Component::updateMouseCursor() const
  32128. {
  32129. sendFakeMouseMove();
  32130. }
  32131. void Component::setRepaintsOnMouseActivity (const bool shouldRepaint) throw()
  32132. {
  32133. flags.repaintOnMouseActivityFlag = shouldRepaint;
  32134. }
  32135. void Component::repaintParent()
  32136. {
  32137. if (flags.visibleFlag)
  32138. internalRepaint (0, 0, getWidth(), getHeight());
  32139. }
  32140. void Component::repaint()
  32141. {
  32142. repaint (0, 0, getWidth(), getHeight());
  32143. }
  32144. void Component::repaint (const int x, const int y,
  32145. const int w, const int h)
  32146. {
  32147. deleteAndZero (bufferedImage_);
  32148. if (flags.visibleFlag)
  32149. internalRepaint (x, y, w, h);
  32150. }
  32151. void Component::internalRepaint (int x, int y, int w, int h)
  32152. {
  32153. // if component methods are being called from threads other than the message
  32154. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32155. checkMessageManagerIsLocked
  32156. if (x < 0)
  32157. {
  32158. w += x;
  32159. x = 0;
  32160. }
  32161. if (x + w > getWidth())
  32162. w = getWidth() - x;
  32163. if (w > 0)
  32164. {
  32165. if (y < 0)
  32166. {
  32167. h += y;
  32168. y = 0;
  32169. }
  32170. if (y + h > getHeight())
  32171. h = getHeight() - y;
  32172. if (h > 0)
  32173. {
  32174. if (parentComponent_ != 0)
  32175. {
  32176. x += getX();
  32177. y += getY();
  32178. if (parentComponent_->flags.visibleFlag)
  32179. parentComponent_->internalRepaint (x, y, w, h);
  32180. }
  32181. else if (flags.hasHeavyweightPeerFlag)
  32182. {
  32183. ComponentPeer* const peer = getPeer();
  32184. if (peer != 0)
  32185. peer->repaint (x, y, w, h);
  32186. }
  32187. }
  32188. }
  32189. }
  32190. void Component::renderComponent (Graphics& g)
  32191. {
  32192. const Rectangle<int> clipBounds (g.getClipBounds());
  32193. g.saveState();
  32194. clipObscuredRegions (g, clipBounds, 0, 0);
  32195. if (! g.isClipEmpty())
  32196. {
  32197. if (flags.bufferToImageFlag)
  32198. {
  32199. if (bufferedImage_ == 0)
  32200. {
  32201. bufferedImage_ = Image::createNativeImage (flags.opaqueFlag ? Image::RGB : Image::ARGB,
  32202. getWidth(), getHeight(), ! flags.opaqueFlag);
  32203. Graphics imG (*bufferedImage_);
  32204. paint (imG);
  32205. }
  32206. g.setColour (Colours::black);
  32207. g.drawImageAt (bufferedImage_, 0, 0);
  32208. }
  32209. else
  32210. {
  32211. paint (g);
  32212. }
  32213. }
  32214. g.restoreState();
  32215. for (int i = 0; i < childComponentList_.size(); ++i)
  32216. {
  32217. Component* const child = childComponentList_.getUnchecked (i);
  32218. if (child->isVisible() && clipBounds.intersects (child->getBounds()))
  32219. {
  32220. g.saveState();
  32221. if (g.reduceClipRegion (child->getX(), child->getY(),
  32222. child->getWidth(), child->getHeight()))
  32223. {
  32224. for (int j = i + 1; j < childComponentList_.size(); ++j)
  32225. {
  32226. const Component* const sibling = childComponentList_.getUnchecked (j);
  32227. if (sibling->flags.opaqueFlag && sibling->isVisible())
  32228. g.excludeClipRegion (sibling->getBounds());
  32229. }
  32230. if (! g.isClipEmpty())
  32231. {
  32232. g.setOrigin (child->getX(), child->getY());
  32233. child->paintEntireComponent (g);
  32234. }
  32235. }
  32236. g.restoreState();
  32237. }
  32238. }
  32239. g.saveState();
  32240. paintOverChildren (g);
  32241. g.restoreState();
  32242. }
  32243. void Component::paintEntireComponent (Graphics& g)
  32244. {
  32245. jassert (! g.isClipEmpty());
  32246. #ifdef JUCE_DEBUG
  32247. flags.isInsidePaintCall = true;
  32248. #endif
  32249. if (effect_ != 0)
  32250. {
  32251. ScopedPointer<Image> effectImage (Image::createNativeImage (flags.opaqueFlag ? Image::RGB : Image::ARGB,
  32252. getWidth(), getHeight(),
  32253. ! flags.opaqueFlag));
  32254. {
  32255. Graphics g2 (*effectImage);
  32256. renderComponent (g2);
  32257. }
  32258. effect_->applyEffect (*effectImage, g);
  32259. }
  32260. else
  32261. {
  32262. renderComponent (g);
  32263. }
  32264. #ifdef JUCE_DEBUG
  32265. flags.isInsidePaintCall = false;
  32266. #endif
  32267. }
  32268. Image* Component::createComponentSnapshot (const Rectangle<int>& areaToGrab,
  32269. const bool clipImageToComponentBounds)
  32270. {
  32271. Rectangle<int> r (areaToGrab);
  32272. if (clipImageToComponentBounds)
  32273. r = r.getIntersection (Rectangle<int> (0, 0, getWidth(), getHeight()));
  32274. ScopedPointer<Image> componentImage (Image::createNativeImage (flags.opaqueFlag ? Image::RGB : Image::ARGB,
  32275. jmax (1, r.getWidth()),
  32276. jmax (1, r.getHeight()),
  32277. true));
  32278. Graphics imageContext (*componentImage);
  32279. imageContext.setOrigin (-r.getX(), -r.getY());
  32280. paintEntireComponent (imageContext);
  32281. return componentImage.release();
  32282. }
  32283. void Component::setComponentEffect (ImageEffectFilter* const effect)
  32284. {
  32285. if (effect_ != effect)
  32286. {
  32287. effect_ = effect;
  32288. repaint();
  32289. }
  32290. }
  32291. LookAndFeel& Component::getLookAndFeel() const throw()
  32292. {
  32293. const Component* c = this;
  32294. do
  32295. {
  32296. if (c->lookAndFeel_ != 0)
  32297. return *(c->lookAndFeel_);
  32298. c = c->parentComponent_;
  32299. }
  32300. while (c != 0);
  32301. return LookAndFeel::getDefaultLookAndFeel();
  32302. }
  32303. void Component::setLookAndFeel (LookAndFeel* const newLookAndFeel)
  32304. {
  32305. if (lookAndFeel_ != newLookAndFeel)
  32306. {
  32307. lookAndFeel_ = newLookAndFeel;
  32308. sendLookAndFeelChange();
  32309. }
  32310. }
  32311. void Component::lookAndFeelChanged()
  32312. {
  32313. }
  32314. void Component::sendLookAndFeelChange()
  32315. {
  32316. repaint();
  32317. lookAndFeelChanged();
  32318. // (it's not a great idea to do anything that would delete this component
  32319. // during the lookAndFeelChanged() callback)
  32320. jassert (isValidComponent());
  32321. SafePointer<Component> safePointer (this);
  32322. for (int i = childComponentList_.size(); --i >= 0;)
  32323. {
  32324. childComponentList_.getUnchecked (i)->sendLookAndFeelChange();
  32325. if (safePointer == 0)
  32326. return;
  32327. i = jmin (i, childComponentList_.size());
  32328. }
  32329. }
  32330. static const var::identifier getColourPropertyId (const int colourId)
  32331. {
  32332. String s;
  32333. s.preallocateStorage (18);
  32334. s << T("jcclr_") << String::toHexString (colourId);
  32335. return s;
  32336. }
  32337. const Colour Component::findColour (const int colourId, const bool inheritFromParent) const
  32338. {
  32339. var* v = properties.getItem (getColourPropertyId (colourId));
  32340. if (v != 0)
  32341. return Colour ((int) *v);
  32342. if (inheritFromParent && parentComponent_ != 0)
  32343. return parentComponent_->findColour (colourId, true);
  32344. return getLookAndFeel().findColour (colourId);
  32345. }
  32346. bool Component::isColourSpecified (const int colourId) const
  32347. {
  32348. return properties.contains (getColourPropertyId (colourId));
  32349. }
  32350. void Component::removeColour (const int colourId)
  32351. {
  32352. if (properties.remove (getColourPropertyId (colourId)))
  32353. colourChanged();
  32354. }
  32355. void Component::setColour (const int colourId, const Colour& colour)
  32356. {
  32357. if (properties.set (getColourPropertyId (colourId), (int) colour.getARGB()))
  32358. colourChanged();
  32359. }
  32360. void Component::copyAllExplicitColoursTo (Component& target) const
  32361. {
  32362. bool changed = false;
  32363. for (int i = properties.size(); --i >= 0;)
  32364. {
  32365. const var::identifier name (properties.getName(i));
  32366. if (name.name.startsWith (T("jcclr_")))
  32367. if (target.properties.set (name, properties [name]))
  32368. changed = true;
  32369. }
  32370. if (changed)
  32371. target.colourChanged();
  32372. }
  32373. void Component::colourChanged()
  32374. {
  32375. }
  32376. const Rectangle<int> Component::getUnclippedArea() const
  32377. {
  32378. int x = 0, y = 0, w = getWidth(), h = getHeight();
  32379. Component* p = parentComponent_;
  32380. int px = getX();
  32381. int py = getY();
  32382. while (p != 0)
  32383. {
  32384. if (! Rectangle<int>::intersectRectangles (x, y, w, h, -px, -py, p->getWidth(), p->getHeight()))
  32385. return Rectangle<int>();
  32386. px += p->getX();
  32387. py += p->getY();
  32388. p = p->parentComponent_;
  32389. }
  32390. return Rectangle<int> (x, y, w, h);
  32391. }
  32392. void Component::clipObscuredRegions (Graphics& g, const Rectangle<int>& clipRect,
  32393. const int deltaX, const int deltaY) const
  32394. {
  32395. for (int i = childComponentList_.size(); --i >= 0;)
  32396. {
  32397. const Component* const c = childComponentList_.getUnchecked(i);
  32398. if (c->isVisible())
  32399. {
  32400. const Rectangle<int> newClip (clipRect.getIntersection (c->bounds_));
  32401. if (! newClip.isEmpty())
  32402. {
  32403. if (c->isOpaque())
  32404. {
  32405. g.excludeClipRegion (newClip.translated (deltaX, deltaY));
  32406. }
  32407. else
  32408. {
  32409. c->clipObscuredRegions (g, newClip.translated (-c->getX(), -c->getY()),
  32410. c->getX() + deltaX,
  32411. c->getY() + deltaY);
  32412. }
  32413. }
  32414. }
  32415. }
  32416. }
  32417. void Component::getVisibleArea (RectangleList& result,
  32418. const bool includeSiblings) const
  32419. {
  32420. result.clear();
  32421. const Rectangle<int> unclipped (getUnclippedArea());
  32422. if (! unclipped.isEmpty())
  32423. {
  32424. result.add (unclipped);
  32425. if (includeSiblings)
  32426. {
  32427. const Component* const c = getTopLevelComponent();
  32428. c->subtractObscuredRegions (result, c->relativePositionToOtherComponent (this, Point<int>()),
  32429. Rectangle<int> (0, 0, c->getWidth(), c->getHeight()),
  32430. this);
  32431. }
  32432. subtractObscuredRegions (result, Point<int>(), unclipped, 0);
  32433. result.consolidate();
  32434. }
  32435. }
  32436. void Component::subtractObscuredRegions (RectangleList& result,
  32437. const Point<int>& delta,
  32438. const Rectangle<int>& clipRect,
  32439. const Component* const compToAvoid) const
  32440. {
  32441. for (int i = childComponentList_.size(); --i >= 0;)
  32442. {
  32443. const Component* const c = childComponentList_.getUnchecked(i);
  32444. if (c != compToAvoid && c->isVisible())
  32445. {
  32446. if (c->isOpaque())
  32447. {
  32448. Rectangle<int> childBounds (c->bounds_.getIntersection (clipRect));
  32449. childBounds.translate (delta.getX(), delta.getY());
  32450. result.subtract (childBounds);
  32451. }
  32452. else
  32453. {
  32454. Rectangle<int> newClip (clipRect.getIntersection (c->bounds_));
  32455. newClip.translate (-c->getX(), -c->getY());
  32456. c->subtractObscuredRegions (result, c->getPosition() + delta,
  32457. newClip, compToAvoid);
  32458. }
  32459. }
  32460. }
  32461. }
  32462. void Component::mouseEnter (const MouseEvent&)
  32463. {
  32464. // base class does nothing
  32465. }
  32466. void Component::mouseExit (const MouseEvent&)
  32467. {
  32468. // base class does nothing
  32469. }
  32470. void Component::mouseDown (const MouseEvent&)
  32471. {
  32472. // base class does nothing
  32473. }
  32474. void Component::mouseUp (const MouseEvent&)
  32475. {
  32476. // base class does nothing
  32477. }
  32478. void Component::mouseDrag (const MouseEvent&)
  32479. {
  32480. // base class does nothing
  32481. }
  32482. void Component::mouseMove (const MouseEvent&)
  32483. {
  32484. // base class does nothing
  32485. }
  32486. void Component::mouseDoubleClick (const MouseEvent&)
  32487. {
  32488. // base class does nothing
  32489. }
  32490. void Component::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  32491. {
  32492. // the base class just passes this event up to its parent..
  32493. if (parentComponent_ != 0)
  32494. parentComponent_->mouseWheelMove (e.getEventRelativeTo (parentComponent_),
  32495. wheelIncrementX, wheelIncrementY);
  32496. }
  32497. void Component::resized()
  32498. {
  32499. // base class does nothing
  32500. }
  32501. void Component::moved()
  32502. {
  32503. // base class does nothing
  32504. }
  32505. void Component::childBoundsChanged (Component*)
  32506. {
  32507. // base class does nothing
  32508. }
  32509. void Component::parentSizeChanged()
  32510. {
  32511. // base class does nothing
  32512. }
  32513. void Component::addComponentListener (ComponentListener* const newListener)
  32514. {
  32515. componentListeners.add (newListener);
  32516. }
  32517. void Component::removeComponentListener (ComponentListener* const listenerToRemove)
  32518. {
  32519. jassert (isValidComponent());
  32520. componentListeners.remove (listenerToRemove);
  32521. }
  32522. void Component::inputAttemptWhenModal()
  32523. {
  32524. bringModalComponentToFront();
  32525. getLookAndFeel().playAlertSound();
  32526. }
  32527. bool Component::canModalEventBeSentToComponent (const Component*)
  32528. {
  32529. return false;
  32530. }
  32531. void Component::internalModalInputAttempt()
  32532. {
  32533. Component* const current = getCurrentlyModalComponent();
  32534. if (current != 0)
  32535. current->inputAttemptWhenModal();
  32536. }
  32537. void Component::paint (Graphics&)
  32538. {
  32539. // all painting is done in the subclasses
  32540. jassert (! isOpaque()); // if your component's opaque, you've gotta paint it!
  32541. }
  32542. void Component::paintOverChildren (Graphics&)
  32543. {
  32544. // all painting is done in the subclasses
  32545. }
  32546. void Component::handleMessage (const Message& message)
  32547. {
  32548. if (message.intParameter1 == exitModalStateMessage)
  32549. {
  32550. exitModalState (message.intParameter2);
  32551. }
  32552. else if (message.intParameter1 == customCommandMessage)
  32553. {
  32554. handleCommandMessage (message.intParameter2);
  32555. }
  32556. }
  32557. void Component::postCommandMessage (const int commandId)
  32558. {
  32559. postMessage (new Message (customCommandMessage, commandId, 0, 0));
  32560. }
  32561. void Component::handleCommandMessage (int)
  32562. {
  32563. // used by subclasses
  32564. }
  32565. void Component::addMouseListener (MouseListener* const newListener,
  32566. const bool wantsEventsForAllNestedChildComponents)
  32567. {
  32568. // if component methods are being called from threads other than the message
  32569. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32570. checkMessageManagerIsLocked
  32571. if (mouseListeners_ == 0)
  32572. mouseListeners_ = new VoidArray();
  32573. if (! mouseListeners_->contains (newListener))
  32574. {
  32575. if (wantsEventsForAllNestedChildComponents)
  32576. {
  32577. mouseListeners_->insert (0, newListener);
  32578. ++numDeepMouseListeners;
  32579. }
  32580. else
  32581. {
  32582. mouseListeners_->add (newListener);
  32583. }
  32584. }
  32585. }
  32586. void Component::removeMouseListener (MouseListener* const listenerToRemove)
  32587. {
  32588. // if component methods are being called from threads other than the message
  32589. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32590. checkMessageManagerIsLocked
  32591. if (mouseListeners_ != 0)
  32592. {
  32593. const int index = mouseListeners_->indexOf (listenerToRemove);
  32594. if (index >= 0)
  32595. {
  32596. if (index < numDeepMouseListeners)
  32597. --numDeepMouseListeners;
  32598. mouseListeners_->remove (index);
  32599. }
  32600. }
  32601. }
  32602. void Component::internalMouseEnter (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  32603. {
  32604. if (isCurrentlyBlockedByAnotherModalComponent())
  32605. {
  32606. // if something else is modal, always just show a normal mouse cursor
  32607. source.showMouseCursor (MouseCursor::NormalCursor);
  32608. return;
  32609. }
  32610. if (! flags.mouseInsideFlag)
  32611. {
  32612. flags.mouseInsideFlag = true;
  32613. flags.mouseOverFlag = true;
  32614. flags.draggingFlag = false;
  32615. BailOutChecker checker (this);
  32616. if (flags.repaintOnMouseActivityFlag)
  32617. repaint();
  32618. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32619. this, time, relativePos,
  32620. time, 0, false);
  32621. mouseEnter (me);
  32622. if (checker.shouldBailOut())
  32623. return;
  32624. Desktop::getInstance().resetTimer();
  32625. Desktop::getInstance().mouseListeners.callChecked (checker, &MouseListener::mouseEnter, me);
  32626. if (checker.shouldBailOut())
  32627. return;
  32628. if (mouseListeners_ != 0)
  32629. {
  32630. for (int i = mouseListeners_->size(); --i >= 0;)
  32631. {
  32632. ((MouseListener*) mouseListeners_->getUnchecked(i))->mouseEnter (me);
  32633. if (checker.shouldBailOut())
  32634. return;
  32635. i = jmin (i, mouseListeners_->size());
  32636. }
  32637. }
  32638. Component* p = parentComponent_;
  32639. while (p != 0)
  32640. {
  32641. if (p->numDeepMouseListeners > 0)
  32642. {
  32643. BailOutChecker checker (this, p);
  32644. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32645. {
  32646. ((MouseListener*) (p->mouseListeners_->getUnchecked(i)))->mouseEnter (me);
  32647. if (checker.shouldBailOut())
  32648. return;
  32649. i = jmin (i, p->numDeepMouseListeners);
  32650. }
  32651. }
  32652. p = p->parentComponent_;
  32653. }
  32654. }
  32655. }
  32656. void Component::internalMouseExit (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  32657. {
  32658. BailOutChecker checker (this);
  32659. if (flags.draggingFlag)
  32660. {
  32661. internalMouseUp (source, relativePos, time, source.getCurrentModifiers().getRawFlags());
  32662. if (checker.shouldBailOut())
  32663. return;
  32664. }
  32665. if (flags.mouseInsideFlag || flags.mouseOverFlag)
  32666. {
  32667. flags.mouseInsideFlag = false;
  32668. flags.mouseOverFlag = false;
  32669. flags.draggingFlag = false;
  32670. if (flags.repaintOnMouseActivityFlag)
  32671. repaint();
  32672. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32673. this, time, relativePos,
  32674. time, 0, false);
  32675. mouseExit (me);
  32676. if (checker.shouldBailOut())
  32677. return;
  32678. Desktop::getInstance().resetTimer();
  32679. Desktop::getInstance().mouseListeners.callChecked (checker, &MouseListener::mouseExit, me);
  32680. if (checker.shouldBailOut())
  32681. return;
  32682. if (mouseListeners_ != 0)
  32683. {
  32684. for (int i = mouseListeners_->size(); --i >= 0;)
  32685. {
  32686. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseExit (me);
  32687. if (checker.shouldBailOut())
  32688. return;
  32689. i = jmin (i, mouseListeners_->size());
  32690. }
  32691. }
  32692. Component* p = parentComponent_;
  32693. while (p != 0)
  32694. {
  32695. if (p->numDeepMouseListeners > 0)
  32696. {
  32697. BailOutChecker checker (this, p);
  32698. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32699. {
  32700. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseExit (me);
  32701. if (checker.shouldBailOut())
  32702. return;
  32703. i = jmin (i, p->numDeepMouseListeners);
  32704. }
  32705. }
  32706. p = p->parentComponent_;
  32707. }
  32708. }
  32709. }
  32710. class InternalDragRepeater : public Timer
  32711. {
  32712. public:
  32713. InternalDragRepeater()
  32714. {}
  32715. ~InternalDragRepeater()
  32716. {
  32717. clearSingletonInstance();
  32718. }
  32719. juce_DeclareSingleton_SingleThreaded_Minimal (InternalDragRepeater)
  32720. void timerCallback()
  32721. {
  32722. Desktop& desktop = Desktop::getInstance();
  32723. int numMiceDown = 0;
  32724. for (int i = desktop.getNumMouseSources(); --i >= 0;)
  32725. {
  32726. MouseInputSource* const source = desktop.getMouseSource(i);
  32727. if (source->isDragging())
  32728. {
  32729. source->triggerFakeMove();
  32730. ++numMiceDown;
  32731. }
  32732. }
  32733. if (numMiceDown == 0)
  32734. deleteInstance();
  32735. }
  32736. juce_UseDebuggingNewOperator
  32737. private:
  32738. InternalDragRepeater (const InternalDragRepeater&);
  32739. InternalDragRepeater& operator= (const InternalDragRepeater&);
  32740. };
  32741. juce_ImplementSingleton_SingleThreaded (InternalDragRepeater)
  32742. void Component::beginDragAutoRepeat (const int interval)
  32743. {
  32744. if (interval > 0)
  32745. {
  32746. if (InternalDragRepeater::getInstance()->getTimerInterval() != interval)
  32747. InternalDragRepeater::getInstance()->startTimer (interval);
  32748. }
  32749. else
  32750. {
  32751. InternalDragRepeater::deleteInstance();
  32752. }
  32753. }
  32754. void Component::internalMouseDown (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  32755. {
  32756. Desktop& desktop = Desktop::getInstance();
  32757. BailOutChecker checker (this);
  32758. if (isCurrentlyBlockedByAnotherModalComponent())
  32759. {
  32760. internalModalInputAttempt();
  32761. if (checker.shouldBailOut())
  32762. return;
  32763. // If processing the input attempt has exited the modal loop, we'll allow the event
  32764. // to be delivered..
  32765. if (isCurrentlyBlockedByAnotherModalComponent())
  32766. {
  32767. // allow blocked mouse-events to go to global listeners..
  32768. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32769. this, time, relativePos, time,
  32770. source.getNumberOfMultipleClicks(), false);
  32771. desktop.resetTimer();
  32772. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseDown, me);
  32773. return;
  32774. }
  32775. }
  32776. {
  32777. Component* c = this;
  32778. while (c != 0)
  32779. {
  32780. if (c->isBroughtToFrontOnMouseClick())
  32781. {
  32782. c->toFront (true);
  32783. if (checker.shouldBailOut())
  32784. return;
  32785. }
  32786. c = c->parentComponent_;
  32787. }
  32788. }
  32789. if (! flags.dontFocusOnMouseClickFlag)
  32790. {
  32791. grabFocusInternal (focusChangedByMouseClick);
  32792. if (checker.shouldBailOut())
  32793. return;
  32794. }
  32795. flags.draggingFlag = true;
  32796. flags.mouseOverFlag = true;
  32797. if (flags.repaintOnMouseActivityFlag)
  32798. repaint();
  32799. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32800. this, time, relativePos, time,
  32801. source.getNumberOfMultipleClicks(), false);
  32802. mouseDown (me);
  32803. if (checker.shouldBailOut())
  32804. return;
  32805. desktop.resetTimer();
  32806. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseDown, me);
  32807. if (checker.shouldBailOut())
  32808. return;
  32809. if (mouseListeners_ != 0)
  32810. {
  32811. for (int i = mouseListeners_->size(); --i >= 0;)
  32812. {
  32813. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseDown (me);
  32814. if (checker.shouldBailOut())
  32815. return;
  32816. i = jmin (i, mouseListeners_->size());
  32817. }
  32818. }
  32819. Component* p = parentComponent_;
  32820. while (p != 0)
  32821. {
  32822. if (p->numDeepMouseListeners > 0)
  32823. {
  32824. BailOutChecker checker (this, p);
  32825. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32826. {
  32827. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseDown (me);
  32828. if (checker.shouldBailOut())
  32829. return;
  32830. i = jmin (i, p->numDeepMouseListeners);
  32831. }
  32832. }
  32833. p = p->parentComponent_;
  32834. }
  32835. }
  32836. void Component::internalMouseUp (MouseInputSource& source, const Point<int>& relativePos, const Time& time, const ModifierKeys& oldModifiers)
  32837. {
  32838. if (flags.draggingFlag)
  32839. {
  32840. Desktop& desktop = Desktop::getInstance();
  32841. flags.draggingFlag = false;
  32842. BailOutChecker checker (this);
  32843. if (flags.repaintOnMouseActivityFlag)
  32844. repaint();
  32845. const MouseEvent me (source, relativePos,
  32846. oldModifiers, this, time,
  32847. globalPositionToRelative (source.getLastMouseDownPosition()),
  32848. source.getLastMouseDownTime(),
  32849. source.getNumberOfMultipleClicks(),
  32850. source.hasMouseMovedSignificantlySincePressed());
  32851. mouseUp (me);
  32852. if (checker.shouldBailOut())
  32853. return;
  32854. desktop.resetTimer();
  32855. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseUp, me);
  32856. if (checker.shouldBailOut())
  32857. return;
  32858. if (mouseListeners_ != 0)
  32859. {
  32860. for (int i = mouseListeners_->size(); --i >= 0;)
  32861. {
  32862. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseUp (me);
  32863. if (checker.shouldBailOut())
  32864. return;
  32865. i = jmin (i, mouseListeners_->size());
  32866. }
  32867. }
  32868. {
  32869. Component* p = parentComponent_;
  32870. while (p != 0)
  32871. {
  32872. if (p->numDeepMouseListeners > 0)
  32873. {
  32874. BailOutChecker checker (this, p);
  32875. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32876. {
  32877. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseUp (me);
  32878. if (checker.shouldBailOut())
  32879. return;
  32880. i = jmin (i, p->numDeepMouseListeners);
  32881. }
  32882. }
  32883. p = p->parentComponent_;
  32884. }
  32885. }
  32886. // check for double-click
  32887. if (me.getNumberOfClicks() >= 2)
  32888. {
  32889. const int numListeners = (mouseListeners_ != 0) ? mouseListeners_->size() : 0;
  32890. mouseDoubleClick (me);
  32891. if (checker.shouldBailOut())
  32892. return;
  32893. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseDoubleClick, me);
  32894. if (checker.shouldBailOut())
  32895. return;
  32896. for (int i = numListeners; --i >= 0;)
  32897. {
  32898. if (checker.shouldBailOut())
  32899. return;
  32900. MouseListener* const ml = (MouseListener*)((*mouseListeners_)[i]);
  32901. if (ml != 0)
  32902. ml->mouseDoubleClick (me);
  32903. }
  32904. if (checker.shouldBailOut())
  32905. return;
  32906. Component* p = parentComponent_;
  32907. while (p != 0)
  32908. {
  32909. if (p->numDeepMouseListeners > 0)
  32910. {
  32911. BailOutChecker checker (this, p);
  32912. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32913. {
  32914. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseDoubleClick (me);
  32915. if (checker.shouldBailOut())
  32916. return;
  32917. i = jmin (i, p->numDeepMouseListeners);
  32918. }
  32919. }
  32920. p = p->parentComponent_;
  32921. }
  32922. }
  32923. }
  32924. }
  32925. void Component::internalMouseDrag (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  32926. {
  32927. if (flags.draggingFlag)
  32928. {
  32929. Desktop& desktop = Desktop::getInstance();
  32930. flags.mouseOverFlag = reallyContains (relativePos.getX(), relativePos.getY(), false);
  32931. BailOutChecker checker (this);
  32932. const MouseEvent me (source, relativePos,
  32933. source.getCurrentModifiers(), this, time,
  32934. globalPositionToRelative (source.getLastMouseDownPosition()),
  32935. source.getLastMouseDownTime(),
  32936. source.getNumberOfMultipleClicks(),
  32937. source.hasMouseMovedSignificantlySincePressed());
  32938. mouseDrag (me);
  32939. if (checker.shouldBailOut())
  32940. return;
  32941. desktop.resetTimer();
  32942. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseDrag, me);
  32943. if (checker.shouldBailOut())
  32944. return;
  32945. if (mouseListeners_ != 0)
  32946. {
  32947. for (int i = mouseListeners_->size(); --i >= 0;)
  32948. {
  32949. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseDrag (me);
  32950. if (checker.shouldBailOut())
  32951. return;
  32952. i = jmin (i, mouseListeners_->size());
  32953. }
  32954. }
  32955. Component* p = parentComponent_;
  32956. while (p != 0)
  32957. {
  32958. if (p->numDeepMouseListeners > 0)
  32959. {
  32960. BailOutChecker checker (this, p);
  32961. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32962. {
  32963. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseDrag (me);
  32964. if (checker.shouldBailOut())
  32965. return;
  32966. i = jmin (i, p->numDeepMouseListeners);
  32967. }
  32968. }
  32969. p = p->parentComponent_;
  32970. }
  32971. }
  32972. }
  32973. void Component::internalMouseMove (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  32974. {
  32975. Desktop& desktop = Desktop::getInstance();
  32976. BailOutChecker checker (this);
  32977. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32978. this, time, relativePos,
  32979. time, 0, false);
  32980. if (isCurrentlyBlockedByAnotherModalComponent())
  32981. {
  32982. // allow blocked mouse-events to go to global listeners..
  32983. desktop.sendMouseMove();
  32984. }
  32985. else
  32986. {
  32987. flags.mouseOverFlag = true;
  32988. mouseMove (me);
  32989. if (checker.shouldBailOut())
  32990. return;
  32991. desktop.resetTimer();
  32992. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseMove, me);
  32993. if (checker.shouldBailOut())
  32994. return;
  32995. if (mouseListeners_ != 0)
  32996. {
  32997. for (int i = mouseListeners_->size(); --i >= 0;)
  32998. {
  32999. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseMove (me);
  33000. if (checker.shouldBailOut())
  33001. return;
  33002. i = jmin (i, mouseListeners_->size());
  33003. }
  33004. }
  33005. Component* p = parentComponent_;
  33006. while (p != 0)
  33007. {
  33008. if (p->numDeepMouseListeners > 0)
  33009. {
  33010. BailOutChecker checker (this, p);
  33011. for (int i = p->numDeepMouseListeners; --i >= 0;)
  33012. {
  33013. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseMove (me);
  33014. if (checker.shouldBailOut())
  33015. return;
  33016. i = jmin (i, p->numDeepMouseListeners);
  33017. }
  33018. }
  33019. p = p->parentComponent_;
  33020. }
  33021. }
  33022. }
  33023. void Component::internalMouseWheel (MouseInputSource& source, const Point<int>& relativePos,
  33024. const Time& time, const float amountX, const float amountY)
  33025. {
  33026. Desktop& desktop = Desktop::getInstance();
  33027. BailOutChecker checker (this);
  33028. const float wheelIncrementX = amountX * (1.0f / 256.0f);
  33029. const float wheelIncrementY = amountY * (1.0f / 256.0f);
  33030. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  33031. this, time, relativePos, time, 0, false);
  33032. if (isCurrentlyBlockedByAnotherModalComponent())
  33033. {
  33034. // allow blocked mouse-events to go to global listeners..
  33035. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseWheelMove, me, wheelIncrementX, wheelIncrementY);
  33036. }
  33037. else
  33038. {
  33039. mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  33040. if (checker.shouldBailOut())
  33041. return;
  33042. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseWheelMove, me, wheelIncrementX, wheelIncrementY);
  33043. if (checker.shouldBailOut())
  33044. return;
  33045. if (mouseListeners_ != 0)
  33046. {
  33047. for (int i = mouseListeners_->size(); --i >= 0;)
  33048. {
  33049. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  33050. if (checker.shouldBailOut())
  33051. return;
  33052. i = jmin (i, mouseListeners_->size());
  33053. }
  33054. }
  33055. Component* p = parentComponent_;
  33056. while (p != 0)
  33057. {
  33058. if (p->numDeepMouseListeners > 0)
  33059. {
  33060. BailOutChecker checker (this, p);
  33061. for (int i = p->numDeepMouseListeners; --i >= 0;)
  33062. {
  33063. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  33064. if (checker.shouldBailOut())
  33065. return;
  33066. i = jmin (i, p->numDeepMouseListeners);
  33067. }
  33068. }
  33069. p = p->parentComponent_;
  33070. }
  33071. }
  33072. }
  33073. void Component::sendFakeMouseMove() const
  33074. {
  33075. Desktop::getInstance().getMainMouseSource().triggerFakeMove();
  33076. }
  33077. void Component::broughtToFront()
  33078. {
  33079. }
  33080. void Component::internalBroughtToFront()
  33081. {
  33082. if (! isValidComponent())
  33083. return;
  33084. if (flags.hasHeavyweightPeerFlag)
  33085. Desktop::getInstance().componentBroughtToFront (this);
  33086. BailOutChecker checker (this);
  33087. broughtToFront();
  33088. if (checker.shouldBailOut())
  33089. return;
  33090. componentListeners.callChecked (checker, &ComponentListener::componentBroughtToFront, *this);
  33091. if (checker.shouldBailOut())
  33092. return;
  33093. // When brought to the front and there's a modal component blocking this one,
  33094. // we need to bring the modal one to the front instead..
  33095. Component* const cm = getCurrentlyModalComponent();
  33096. if (cm != 0 && cm->getTopLevelComponent() != getTopLevelComponent())
  33097. bringModalComponentToFront();
  33098. }
  33099. void Component::focusGained (FocusChangeType)
  33100. {
  33101. // base class does nothing
  33102. }
  33103. void Component::internalFocusGain (const FocusChangeType cause)
  33104. {
  33105. SafePointer<Component> safePointer (this);
  33106. focusGained (cause);
  33107. if (safePointer != 0)
  33108. internalChildFocusChange (cause);
  33109. }
  33110. void Component::focusLost (FocusChangeType)
  33111. {
  33112. // base class does nothing
  33113. }
  33114. void Component::internalFocusLoss (const FocusChangeType cause)
  33115. {
  33116. SafePointer<Component> safePointer (this);
  33117. focusLost (focusChangedDirectly);
  33118. if (safePointer != 0)
  33119. internalChildFocusChange (cause);
  33120. }
  33121. void Component::focusOfChildComponentChanged (FocusChangeType /*cause*/)
  33122. {
  33123. // base class does nothing
  33124. }
  33125. void Component::internalChildFocusChange (FocusChangeType cause)
  33126. {
  33127. const bool childIsNowFocused = hasKeyboardFocus (true);
  33128. if (flags.childCompFocusedFlag != childIsNowFocused)
  33129. {
  33130. flags.childCompFocusedFlag = childIsNowFocused;
  33131. SafePointer<Component> safePointer (this);
  33132. focusOfChildComponentChanged (cause);
  33133. if (safePointer == 0)
  33134. return;
  33135. }
  33136. if (parentComponent_ != 0)
  33137. parentComponent_->internalChildFocusChange (cause);
  33138. }
  33139. bool Component::isEnabled() const throw()
  33140. {
  33141. return (! flags.isDisabledFlag)
  33142. && (parentComponent_ == 0 || parentComponent_->isEnabled());
  33143. }
  33144. void Component::setEnabled (const bool shouldBeEnabled)
  33145. {
  33146. if (flags.isDisabledFlag == shouldBeEnabled)
  33147. {
  33148. flags.isDisabledFlag = ! shouldBeEnabled;
  33149. // if any parent components are disabled, setting our flag won't make a difference,
  33150. // so no need to send a change message
  33151. if (parentComponent_ == 0 || parentComponent_->isEnabled())
  33152. sendEnablementChangeMessage();
  33153. }
  33154. }
  33155. void Component::sendEnablementChangeMessage()
  33156. {
  33157. SafePointer<Component> safePointer (this);
  33158. enablementChanged();
  33159. if (safePointer == 0)
  33160. return;
  33161. for (int i = getNumChildComponents(); --i >= 0;)
  33162. {
  33163. Component* const c = getChildComponent (i);
  33164. if (c != 0)
  33165. {
  33166. c->sendEnablementChangeMessage();
  33167. if (safePointer == 0)
  33168. return;
  33169. }
  33170. }
  33171. }
  33172. void Component::enablementChanged()
  33173. {
  33174. }
  33175. void Component::setWantsKeyboardFocus (const bool wantsFocus) throw()
  33176. {
  33177. flags.wantsFocusFlag = wantsFocus;
  33178. }
  33179. void Component::setMouseClickGrabsKeyboardFocus (const bool shouldGrabFocus)
  33180. {
  33181. flags.dontFocusOnMouseClickFlag = ! shouldGrabFocus;
  33182. }
  33183. bool Component::getMouseClickGrabsKeyboardFocus() const throw()
  33184. {
  33185. return ! flags.dontFocusOnMouseClickFlag;
  33186. }
  33187. bool Component::getWantsKeyboardFocus() const throw()
  33188. {
  33189. return flags.wantsFocusFlag && ! flags.isDisabledFlag;
  33190. }
  33191. void Component::setFocusContainer (const bool shouldBeFocusContainer) throw()
  33192. {
  33193. flags.isFocusContainerFlag = shouldBeFocusContainer;
  33194. }
  33195. bool Component::isFocusContainer() const throw()
  33196. {
  33197. return flags.isFocusContainerFlag;
  33198. }
  33199. int Component::getExplicitFocusOrder() const
  33200. {
  33201. return properties ["_jexfo"];
  33202. }
  33203. void Component::setExplicitFocusOrder (const int newFocusOrderIndex)
  33204. {
  33205. properties.set ("_jexfo", newFocusOrderIndex);
  33206. }
  33207. KeyboardFocusTraverser* Component::createFocusTraverser()
  33208. {
  33209. if (flags.isFocusContainerFlag || parentComponent_ == 0)
  33210. return new KeyboardFocusTraverser();
  33211. return parentComponent_->createFocusTraverser();
  33212. }
  33213. void Component::takeKeyboardFocus (const FocusChangeType cause)
  33214. {
  33215. // give the focus to this component
  33216. if (currentlyFocusedComponent != this)
  33217. {
  33218. JUCE_TRY
  33219. {
  33220. // get the focus onto our desktop window
  33221. ComponentPeer* const peer = getPeer();
  33222. if (peer != 0)
  33223. {
  33224. SafePointer<Component> safePointer (this);
  33225. peer->grabFocus();
  33226. if (peer->isFocused() && currentlyFocusedComponent != this)
  33227. {
  33228. Component* const componentLosingFocus = currentlyFocusedComponent;
  33229. currentlyFocusedComponent = this;
  33230. Desktop::getInstance().triggerFocusCallback();
  33231. // call this after setting currentlyFocusedComponent so that the one that's
  33232. // losing it has a chance to see where focus is going
  33233. if (componentLosingFocus->isValidComponent())
  33234. componentLosingFocus->internalFocusLoss (cause);
  33235. if (currentlyFocusedComponent == this)
  33236. {
  33237. focusGained (cause);
  33238. if (safePointer != 0)
  33239. internalChildFocusChange (cause);
  33240. }
  33241. }
  33242. }
  33243. }
  33244. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  33245. catch (const std::exception& e)
  33246. {
  33247. currentlyFocusedComponent = 0;
  33248. Desktop::getInstance().triggerFocusCallback();
  33249. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__);
  33250. }
  33251. catch (...)
  33252. {
  33253. currentlyFocusedComponent = 0;
  33254. Desktop::getInstance().triggerFocusCallback();
  33255. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__);
  33256. }
  33257. #endif
  33258. }
  33259. }
  33260. void Component::grabFocusInternal (const FocusChangeType cause, const bool canTryParent)
  33261. {
  33262. if (isShowing())
  33263. {
  33264. if (flags.wantsFocusFlag && (isEnabled() || parentComponent_ == 0))
  33265. {
  33266. takeKeyboardFocus (cause);
  33267. }
  33268. else
  33269. {
  33270. if (isParentOf (currentlyFocusedComponent)
  33271. && currentlyFocusedComponent->isShowing())
  33272. {
  33273. // do nothing if the focused component is actually a child of ours..
  33274. }
  33275. else
  33276. {
  33277. // find the default child component..
  33278. ScopedPointer <KeyboardFocusTraverser> traverser (createFocusTraverser());
  33279. if (traverser != 0)
  33280. {
  33281. Component* const defaultComp = traverser->getDefaultComponent (this);
  33282. traverser = 0;
  33283. if (defaultComp != 0)
  33284. {
  33285. defaultComp->grabFocusInternal (cause, false);
  33286. return;
  33287. }
  33288. }
  33289. if (canTryParent && parentComponent_ != 0)
  33290. {
  33291. // if no children want it and we're allowed to try our parent comp,
  33292. // then pass up to parent, which will try our siblings.
  33293. parentComponent_->grabFocusInternal (cause, true);
  33294. }
  33295. }
  33296. }
  33297. }
  33298. }
  33299. void Component::grabKeyboardFocus()
  33300. {
  33301. // if component methods are being called from threads other than the message
  33302. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  33303. checkMessageManagerIsLocked
  33304. grabFocusInternal (focusChangedDirectly);
  33305. }
  33306. void Component::moveKeyboardFocusToSibling (const bool moveToNext)
  33307. {
  33308. // if component methods are being called from threads other than the message
  33309. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  33310. checkMessageManagerIsLocked
  33311. if (parentComponent_ != 0)
  33312. {
  33313. ScopedPointer <KeyboardFocusTraverser> traverser (createFocusTraverser());
  33314. if (traverser != 0)
  33315. {
  33316. Component* const nextComp = moveToNext ? traverser->getNextComponent (this)
  33317. : traverser->getPreviousComponent (this);
  33318. traverser = 0;
  33319. if (nextComp != 0)
  33320. {
  33321. if (nextComp->isCurrentlyBlockedByAnotherModalComponent())
  33322. {
  33323. SafePointer<Component> safePointer (this);
  33324. internalModalInputAttempt();
  33325. if (safePointer == 0 || nextComp->isCurrentlyBlockedByAnotherModalComponent())
  33326. return;
  33327. }
  33328. nextComp->grabFocusInternal (focusChangedByTabKey);
  33329. return;
  33330. }
  33331. }
  33332. parentComponent_->moveKeyboardFocusToSibling (moveToNext);
  33333. }
  33334. }
  33335. bool Component::hasKeyboardFocus (const bool trueIfChildIsFocused) const
  33336. {
  33337. return (currentlyFocusedComponent == this)
  33338. || (trueIfChildIsFocused && isParentOf (currentlyFocusedComponent));
  33339. }
  33340. Component* JUCE_CALLTYPE Component::getCurrentlyFocusedComponent() throw()
  33341. {
  33342. return currentlyFocusedComponent;
  33343. }
  33344. void Component::giveAwayFocus()
  33345. {
  33346. // use a copy so we can clear the value before the call
  33347. Component* const componentLosingFocus = currentlyFocusedComponent;
  33348. currentlyFocusedComponent = 0;
  33349. Desktop::getInstance().triggerFocusCallback();
  33350. if (componentLosingFocus->isValidComponent())
  33351. componentLosingFocus->internalFocusLoss (focusChangedDirectly);
  33352. }
  33353. bool Component::isMouseOver() const throw()
  33354. {
  33355. return flags.mouseOverFlag;
  33356. }
  33357. bool Component::isMouseButtonDown() const throw()
  33358. {
  33359. return flags.draggingFlag;
  33360. }
  33361. bool Component::isMouseOverOrDragging() const throw()
  33362. {
  33363. return flags.mouseOverFlag || flags.draggingFlag;
  33364. }
  33365. bool JUCE_CALLTYPE Component::isMouseButtonDownAnywhere() throw()
  33366. {
  33367. return ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown();
  33368. }
  33369. const Point<int> Component::getMouseXYRelative() const
  33370. {
  33371. return globalPositionToRelative (Desktop::getMousePosition());
  33372. }
  33373. const Rectangle<int> Component::getParentMonitorArea() const
  33374. {
  33375. return Desktop::getInstance()
  33376. .getMonitorAreaContaining (relativePositionToGlobal (Point<int> (getWidth() / 2,
  33377. getHeight() / 2)));
  33378. }
  33379. void Component::addKeyListener (KeyListener* const newListener)
  33380. {
  33381. if (keyListeners_ == 0)
  33382. keyListeners_ = new VoidArray();
  33383. keyListeners_->addIfNotAlreadyThere (newListener);
  33384. }
  33385. void Component::removeKeyListener (KeyListener* const listenerToRemove)
  33386. {
  33387. if (keyListeners_ != 0)
  33388. keyListeners_->removeValue (listenerToRemove);
  33389. }
  33390. bool Component::keyPressed (const KeyPress&)
  33391. {
  33392. return false;
  33393. }
  33394. bool Component::keyStateChanged (const bool /*isKeyDown*/)
  33395. {
  33396. return false;
  33397. }
  33398. void Component::modifierKeysChanged (const ModifierKeys& modifiers)
  33399. {
  33400. if (parentComponent_ != 0)
  33401. parentComponent_->modifierKeysChanged (modifiers);
  33402. }
  33403. void Component::internalModifierKeysChanged()
  33404. {
  33405. sendFakeMouseMove();
  33406. modifierKeysChanged (ModifierKeys::getCurrentModifiers());
  33407. }
  33408. ComponentPeer* Component::getPeer() const
  33409. {
  33410. if (flags.hasHeavyweightPeerFlag)
  33411. return ComponentPeer::getPeerFor (this);
  33412. else if (parentComponent_ != 0)
  33413. return parentComponent_->getPeer();
  33414. else
  33415. return 0;
  33416. }
  33417. Component::BailOutChecker::BailOutChecker (Component* const component1, Component* const component2_)
  33418. : safePointer1 (component1), safePointer2 (component2_), component2 (component2_)
  33419. {
  33420. jassert (component1 != 0);
  33421. }
  33422. bool Component::BailOutChecker::shouldBailOut() const throw()
  33423. {
  33424. return safePointer1 == 0 || safePointer2.getComponent() != component2;
  33425. }
  33426. END_JUCE_NAMESPACE
  33427. /*** End of inlined file: juce_Component.cpp ***/
  33428. /*** Start of inlined file: juce_ComponentListener.cpp ***/
  33429. BEGIN_JUCE_NAMESPACE
  33430. void ComponentListener::componentMovedOrResized (Component&, bool, bool) {}
  33431. void ComponentListener::componentBroughtToFront (Component&) {}
  33432. void ComponentListener::componentVisibilityChanged (Component&) {}
  33433. void ComponentListener::componentChildrenChanged (Component&) {}
  33434. void ComponentListener::componentParentHierarchyChanged (Component&) {}
  33435. void ComponentListener::componentNameChanged (Component&) {}
  33436. void ComponentListener::componentBeingDeleted (Component&) {}
  33437. END_JUCE_NAMESPACE
  33438. /*** End of inlined file: juce_ComponentListener.cpp ***/
  33439. /*** Start of inlined file: juce_Desktop.cpp ***/
  33440. BEGIN_JUCE_NAMESPACE
  33441. Desktop::Desktop()
  33442. : mouseClickCounter (0),
  33443. kioskModeComponent (0)
  33444. {
  33445. createMouseInputSources();
  33446. refreshMonitorSizes();
  33447. }
  33448. Desktop::~Desktop()
  33449. {
  33450. jassert (instance == this);
  33451. instance = 0;
  33452. // doh! If you don't delete all your windows before exiting, you're going to
  33453. // be leaking memory!
  33454. jassert (desktopComponents.size() == 0);
  33455. }
  33456. Desktop& JUCE_CALLTYPE Desktop::getInstance()
  33457. {
  33458. if (instance == 0)
  33459. instance = new Desktop();
  33460. return *instance;
  33461. }
  33462. Desktop* Desktop::instance = 0;
  33463. extern void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords,
  33464. const bool clipToWorkArea);
  33465. void Desktop::refreshMonitorSizes()
  33466. {
  33467. const Array <Rectangle<int> > oldClipped (monitorCoordsClipped);
  33468. const Array <Rectangle<int> > oldUnclipped (monitorCoordsUnclipped);
  33469. monitorCoordsClipped.clear();
  33470. monitorCoordsUnclipped.clear();
  33471. juce_updateMultiMonitorInfo (monitorCoordsClipped, true);
  33472. juce_updateMultiMonitorInfo (monitorCoordsUnclipped, false);
  33473. jassert (monitorCoordsClipped.size() > 0
  33474. && monitorCoordsClipped.size() == monitorCoordsUnclipped.size());
  33475. if (oldClipped != monitorCoordsClipped
  33476. || oldUnclipped != monitorCoordsUnclipped)
  33477. {
  33478. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  33479. {
  33480. ComponentPeer* const p = ComponentPeer::getPeer (i);
  33481. if (p != 0)
  33482. p->handleScreenSizeChange();
  33483. }
  33484. }
  33485. }
  33486. int Desktop::getNumDisplayMonitors() const throw()
  33487. {
  33488. return monitorCoordsClipped.size();
  33489. }
  33490. const Rectangle<int> Desktop::getDisplayMonitorCoordinates (const int index, const bool clippedToWorkArea) const throw()
  33491. {
  33492. return clippedToWorkArea ? monitorCoordsClipped [index]
  33493. : monitorCoordsUnclipped [index];
  33494. }
  33495. const RectangleList Desktop::getAllMonitorDisplayAreas (const bool clippedToWorkArea) const throw()
  33496. {
  33497. RectangleList rl;
  33498. for (int i = 0; i < getNumDisplayMonitors(); ++i)
  33499. rl.addWithoutMerging (getDisplayMonitorCoordinates (i, clippedToWorkArea));
  33500. return rl;
  33501. }
  33502. const Rectangle<int> Desktop::getMainMonitorArea (const bool clippedToWorkArea) const throw()
  33503. {
  33504. return getDisplayMonitorCoordinates (0, clippedToWorkArea);
  33505. }
  33506. const Rectangle<int> Desktop::getMonitorAreaContaining (const Point<int>& position, const bool clippedToWorkArea) const
  33507. {
  33508. Rectangle<int> best (getMainMonitorArea (clippedToWorkArea));
  33509. double bestDistance = 1.0e10;
  33510. for (int i = getNumDisplayMonitors(); --i >= 0;)
  33511. {
  33512. const Rectangle<int> rect (getDisplayMonitorCoordinates (i, clippedToWorkArea));
  33513. if (rect.contains (position))
  33514. return rect;
  33515. const double distance = rect.getCentre().getDistanceFrom (position);
  33516. if (distance < bestDistance)
  33517. {
  33518. bestDistance = distance;
  33519. best = rect;
  33520. }
  33521. }
  33522. return best;
  33523. }
  33524. int Desktop::getNumComponents() const throw()
  33525. {
  33526. return desktopComponents.size();
  33527. }
  33528. Component* Desktop::getComponent (const int index) const throw()
  33529. {
  33530. return desktopComponents [index];
  33531. }
  33532. Component* Desktop::findComponentAt (const Point<int>& screenPosition) const
  33533. {
  33534. for (int i = desktopComponents.size(); --i >= 0;)
  33535. {
  33536. Component* const c = desktopComponents.getUnchecked(i);
  33537. const Point<int> relative (c->globalPositionToRelative (screenPosition));
  33538. if (c->contains (relative.getX(), relative.getY()))
  33539. return c->getComponentAt (relative.getX(), relative.getY());
  33540. }
  33541. return 0;
  33542. }
  33543. void Desktop::addDesktopComponent (Component* const c)
  33544. {
  33545. jassert (c != 0);
  33546. jassert (! desktopComponents.contains (c));
  33547. desktopComponents.addIfNotAlreadyThere (c);
  33548. }
  33549. void Desktop::removeDesktopComponent (Component* const c)
  33550. {
  33551. desktopComponents.removeValue (c);
  33552. }
  33553. void Desktop::componentBroughtToFront (Component* const c)
  33554. {
  33555. const int index = desktopComponents.indexOf (c);
  33556. jassert (index >= 0);
  33557. if (index >= 0)
  33558. {
  33559. int newIndex = -1;
  33560. if (! c->isAlwaysOnTop())
  33561. {
  33562. newIndex = desktopComponents.size();
  33563. while (newIndex > 0 && desktopComponents.getUnchecked (newIndex - 1)->isAlwaysOnTop())
  33564. --newIndex;
  33565. --newIndex;
  33566. }
  33567. desktopComponents.move (index, newIndex);
  33568. }
  33569. }
  33570. const Point<int> Desktop::getLastMouseDownPosition() throw()
  33571. {
  33572. return getInstance().getMainMouseSource().getLastMouseDownPosition();
  33573. }
  33574. int Desktop::getMouseButtonClickCounter() throw()
  33575. {
  33576. return getInstance().mouseClickCounter;
  33577. }
  33578. void Desktop::incrementMouseClickCounter() throw()
  33579. {
  33580. ++mouseClickCounter;
  33581. }
  33582. int Desktop::getNumDraggingMouseSources() const throw()
  33583. {
  33584. int num = 0;
  33585. for (int i = mouseSources.size(); --i >= 0;)
  33586. if (mouseSources.getUnchecked(i)->isDragging())
  33587. ++num;
  33588. return num;
  33589. }
  33590. MouseInputSource* Desktop::getDraggingMouseSource (int index) const throw()
  33591. {
  33592. int num = 0;
  33593. for (int i = mouseSources.size(); --i >= 0;)
  33594. {
  33595. MouseInputSource* const mi = mouseSources.getUnchecked(i);
  33596. if (mi->isDragging())
  33597. {
  33598. if (index == num)
  33599. return mi;
  33600. ++num;
  33601. }
  33602. }
  33603. return 0;
  33604. }
  33605. void Desktop::addFocusChangeListener (FocusChangeListener* const listener)
  33606. {
  33607. focusListeners.add (listener);
  33608. }
  33609. void Desktop::removeFocusChangeListener (FocusChangeListener* const listener)
  33610. {
  33611. focusListeners.remove (listener);
  33612. }
  33613. void Desktop::triggerFocusCallback()
  33614. {
  33615. triggerAsyncUpdate();
  33616. }
  33617. void Desktop::handleAsyncUpdate()
  33618. {
  33619. Component* currentFocus = Component::getCurrentlyFocusedComponent();
  33620. focusListeners.call (&FocusChangeListener::globalFocusChanged, currentFocus);
  33621. }
  33622. void Desktop::addGlobalMouseListener (MouseListener* const listener)
  33623. {
  33624. mouseListeners.add (listener);
  33625. resetTimer();
  33626. }
  33627. void Desktop::removeGlobalMouseListener (MouseListener* const listener)
  33628. {
  33629. mouseListeners.remove (listener);
  33630. resetTimer();
  33631. }
  33632. void Desktop::timerCallback()
  33633. {
  33634. if (lastFakeMouseMove != getMousePosition())
  33635. sendMouseMove();
  33636. }
  33637. void Desktop::sendMouseMove()
  33638. {
  33639. if (! mouseListeners.isEmpty())
  33640. {
  33641. startTimer (20);
  33642. lastFakeMouseMove = getMousePosition();
  33643. Component* const target = findComponentAt (lastFakeMouseMove);
  33644. if (target != 0)
  33645. {
  33646. Component::BailOutChecker checker (target);
  33647. const Point<int> pos (target->globalPositionToRelative (lastFakeMouseMove));
  33648. const Time now (Time::getCurrentTime());
  33649. const MouseEvent me (getMainMouseSource(), pos, ModifierKeys::getCurrentModifiers(),
  33650. target, now, pos, now, 0, false);
  33651. if (me.mods.isAnyMouseButtonDown())
  33652. mouseListeners.callChecked (checker, &MouseListener::mouseDrag, me);
  33653. else
  33654. mouseListeners.callChecked (checker, &MouseListener::mouseMove, me);
  33655. }
  33656. }
  33657. }
  33658. void Desktop::resetTimer()
  33659. {
  33660. if (mouseListeners.size() == 0)
  33661. stopTimer();
  33662. else
  33663. startTimer (100);
  33664. lastFakeMouseMove = getMousePosition();
  33665. }
  33666. extern void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars);
  33667. void Desktop::setKioskModeComponent (Component* componentToUse, const bool allowMenusAndBars)
  33668. {
  33669. if (kioskModeComponent != componentToUse)
  33670. {
  33671. // agh! Don't delete a component without first stopping it being the kiosk comp
  33672. jassert (kioskModeComponent == 0 || kioskModeComponent->isValidComponent());
  33673. // agh! Don't remove a component from the desktop if it's the kiosk comp!
  33674. jassert (kioskModeComponent == 0 || kioskModeComponent->isOnDesktop());
  33675. if (kioskModeComponent->isValidComponent())
  33676. {
  33677. juce_setKioskComponent (kioskModeComponent, false, allowMenusAndBars);
  33678. kioskModeComponent->setBounds (kioskComponentOriginalBounds);
  33679. }
  33680. kioskModeComponent = componentToUse;
  33681. if (kioskModeComponent != 0)
  33682. {
  33683. jassert (kioskModeComponent->isValidComponent());
  33684. // Only components that are already on the desktop can be put into kiosk mode!
  33685. jassert (kioskModeComponent->isOnDesktop());
  33686. kioskComponentOriginalBounds = kioskModeComponent->getBounds();
  33687. juce_setKioskComponent (kioskModeComponent, true, allowMenusAndBars);
  33688. }
  33689. }
  33690. }
  33691. END_JUCE_NAMESPACE
  33692. /*** End of inlined file: juce_Desktop.cpp ***/
  33693. /*** Start of inlined file: juce_ArrowButton.cpp ***/
  33694. BEGIN_JUCE_NAMESPACE
  33695. ArrowButton::ArrowButton (const String& name,
  33696. float arrowDirectionInRadians,
  33697. const Colour& arrowColour)
  33698. : Button (name),
  33699. colour (arrowColour)
  33700. {
  33701. path.lineTo (0.0f, 1.0f);
  33702. path.lineTo (1.0f, 0.5f);
  33703. path.closeSubPath();
  33704. path.applyTransform (AffineTransform::rotation (float_Pi * 2.0f * arrowDirectionInRadians,
  33705. 0.5f, 0.5f));
  33706. setComponentEffect (&shadow);
  33707. buttonStateChanged();
  33708. }
  33709. ArrowButton::~ArrowButton()
  33710. {
  33711. }
  33712. void ArrowButton::paintButton (Graphics& g,
  33713. bool /*isMouseOverButton*/,
  33714. bool /*isButtonDown*/)
  33715. {
  33716. g.setColour (colour);
  33717. g.fillPath (path, path.getTransformToScaleToFit ((float) offset,
  33718. (float) offset,
  33719. (float) (getWidth() - 3),
  33720. (float) (getHeight() - 3),
  33721. false));
  33722. }
  33723. void ArrowButton::buttonStateChanged()
  33724. {
  33725. offset = (isDown()) ? 1 : 0;
  33726. shadow.setShadowProperties ((isDown()) ? 1.2f : 3.0f,
  33727. 0.3f, -1, 0);
  33728. }
  33729. END_JUCE_NAMESPACE
  33730. /*** End of inlined file: juce_ArrowButton.cpp ***/
  33731. /*** Start of inlined file: juce_Button.cpp ***/
  33732. BEGIN_JUCE_NAMESPACE
  33733. class Button::RepeatTimer : public Timer
  33734. {
  33735. public:
  33736. RepeatTimer (Button& owner_) : owner (owner_) {}
  33737. void timerCallback() { owner.repeatTimerCallback(); }
  33738. juce_UseDebuggingNewOperator
  33739. private:
  33740. Button& owner;
  33741. RepeatTimer (const RepeatTimer&);
  33742. RepeatTimer& operator= (const RepeatTimer&);
  33743. };
  33744. Button::Button (const String& name)
  33745. : Component (name),
  33746. text (name),
  33747. buttonPressTime (0),
  33748. lastTimeCallbackTime (0),
  33749. commandManagerToUse (0),
  33750. autoRepeatDelay (-1),
  33751. autoRepeatSpeed (0),
  33752. autoRepeatMinimumDelay (-1),
  33753. radioGroupId (0),
  33754. commandID (0),
  33755. connectedEdgeFlags (0),
  33756. buttonState (buttonNormal),
  33757. lastToggleState (false),
  33758. clickTogglesState (false),
  33759. needsToRelease (false),
  33760. needsRepainting (false),
  33761. isKeyDown (false),
  33762. triggerOnMouseDown (false),
  33763. generateTooltip (false)
  33764. {
  33765. setWantsKeyboardFocus (true);
  33766. isOn.addListener (this);
  33767. }
  33768. Button::~Button()
  33769. {
  33770. isOn.removeListener (this);
  33771. if (commandManagerToUse != 0)
  33772. commandManagerToUse->removeListener (this);
  33773. repeatTimer = 0;
  33774. clearShortcuts();
  33775. }
  33776. void Button::setButtonText (const String& newText)
  33777. {
  33778. if (text != newText)
  33779. {
  33780. text = newText;
  33781. repaint();
  33782. }
  33783. }
  33784. void Button::setTooltip (const String& newTooltip)
  33785. {
  33786. SettableTooltipClient::setTooltip (newTooltip);
  33787. generateTooltip = false;
  33788. }
  33789. const String Button::getTooltip()
  33790. {
  33791. if (generateTooltip && commandManagerToUse != 0 && commandID != 0)
  33792. {
  33793. String tt (commandManagerToUse->getDescriptionOfCommand (commandID));
  33794. Array <KeyPress> keyPresses (commandManagerToUse->getKeyMappings()->getKeyPressesAssignedToCommand (commandID));
  33795. for (int i = 0; i < keyPresses.size(); ++i)
  33796. {
  33797. const String key (keyPresses.getReference(i).getTextDescription());
  33798. tt << " [";
  33799. if (key.length() == 1)
  33800. tt << TRANS("shortcut") << ": '" << key << "']";
  33801. else
  33802. tt << key << ']';
  33803. }
  33804. return tt;
  33805. }
  33806. return SettableTooltipClient::getTooltip();
  33807. }
  33808. void Button::setConnectedEdges (const int connectedEdgeFlags_)
  33809. {
  33810. if (connectedEdgeFlags != connectedEdgeFlags_)
  33811. {
  33812. connectedEdgeFlags = connectedEdgeFlags_;
  33813. repaint();
  33814. }
  33815. }
  33816. void Button::setToggleState (const bool shouldBeOn,
  33817. const bool sendChangeNotification)
  33818. {
  33819. if (shouldBeOn != lastToggleState)
  33820. {
  33821. isOn = shouldBeOn;
  33822. lastToggleState = shouldBeOn;
  33823. repaint();
  33824. if (sendChangeNotification)
  33825. {
  33826. Component::SafePointer<Component> deletionWatcher (this);
  33827. sendClickMessage (ModifierKeys());
  33828. if (deletionWatcher == 0)
  33829. return;
  33830. }
  33831. if (lastToggleState)
  33832. turnOffOtherButtonsInGroup (sendChangeNotification);
  33833. }
  33834. }
  33835. void Button::setClickingTogglesState (const bool shouldToggle) throw()
  33836. {
  33837. clickTogglesState = shouldToggle;
  33838. // if you've got clickTogglesState turned on, you shouldn't also connect the button
  33839. // up to be a command invoker. Instead, your command handler must flip the state of whatever
  33840. // it is that this button represents, and the button will update its state to reflect this
  33841. // in the applicationCommandListChanged() method.
  33842. jassert (commandManagerToUse == 0 || ! clickTogglesState);
  33843. }
  33844. bool Button::getClickingTogglesState() const throw()
  33845. {
  33846. return clickTogglesState;
  33847. }
  33848. void Button::valueChanged (Value& value)
  33849. {
  33850. if (value.refersToSameSourceAs (isOn))
  33851. setToggleState (isOn.getValue(), true);
  33852. }
  33853. void Button::setRadioGroupId (const int newGroupId)
  33854. {
  33855. if (radioGroupId != newGroupId)
  33856. {
  33857. radioGroupId = newGroupId;
  33858. if (lastToggleState)
  33859. turnOffOtherButtonsInGroup (true);
  33860. }
  33861. }
  33862. void Button::turnOffOtherButtonsInGroup (const bool sendChangeNotification)
  33863. {
  33864. Component* const p = getParentComponent();
  33865. if (p != 0 && radioGroupId != 0)
  33866. {
  33867. Component::SafePointer<Component> deletionWatcher (this);
  33868. for (int i = p->getNumChildComponents(); --i >= 0;)
  33869. {
  33870. Component* const c = p->getChildComponent (i);
  33871. if (c != this)
  33872. {
  33873. Button* const b = dynamic_cast <Button*> (c);
  33874. if (b != 0 && b->getRadioGroupId() == radioGroupId)
  33875. {
  33876. b->setToggleState (false, sendChangeNotification);
  33877. if (deletionWatcher == 0)
  33878. return;
  33879. }
  33880. }
  33881. }
  33882. }
  33883. }
  33884. void Button::enablementChanged()
  33885. {
  33886. updateState (0);
  33887. repaint();
  33888. }
  33889. Button::ButtonState Button::updateState (const MouseEvent* const e)
  33890. {
  33891. ButtonState state = buttonNormal;
  33892. if (isEnabled() && isVisible() && ! isCurrentlyBlockedByAnotherModalComponent())
  33893. {
  33894. Point<int> mousePos;
  33895. if (e == 0)
  33896. mousePos = getMouseXYRelative();
  33897. else
  33898. mousePos = e->getEventRelativeTo (this).getPosition();
  33899. const bool over = reallyContains (mousePos.getX(), mousePos.getY(), true);
  33900. const bool down = isMouseButtonDown();
  33901. if ((down && (over || (triggerOnMouseDown && buttonState == buttonDown))) || isKeyDown)
  33902. state = buttonDown;
  33903. else if (over)
  33904. state = buttonOver;
  33905. }
  33906. setState (state);
  33907. return state;
  33908. }
  33909. void Button::setState (const ButtonState newState)
  33910. {
  33911. if (buttonState != newState)
  33912. {
  33913. buttonState = newState;
  33914. repaint();
  33915. if (buttonState == buttonDown)
  33916. {
  33917. buttonPressTime = Time::getApproximateMillisecondCounter();
  33918. lastTimeCallbackTime = buttonPressTime;
  33919. }
  33920. sendStateMessage();
  33921. }
  33922. }
  33923. bool Button::isDown() const throw()
  33924. {
  33925. return buttonState == buttonDown;
  33926. }
  33927. bool Button::isOver() const throw()
  33928. {
  33929. return buttonState != buttonNormal;
  33930. }
  33931. void Button::buttonStateChanged()
  33932. {
  33933. }
  33934. uint32 Button::getMillisecondsSinceButtonDown() const throw()
  33935. {
  33936. const uint32 now = Time::getApproximateMillisecondCounter();
  33937. return now > buttonPressTime ? now - buttonPressTime : 0;
  33938. }
  33939. void Button::setTriggeredOnMouseDown (const bool isTriggeredOnMouseDown) throw()
  33940. {
  33941. triggerOnMouseDown = isTriggeredOnMouseDown;
  33942. }
  33943. void Button::clicked()
  33944. {
  33945. }
  33946. void Button::clicked (const ModifierKeys& /*modifiers*/)
  33947. {
  33948. clicked();
  33949. }
  33950. static const int clickMessageId = 0x2f3f4f99;
  33951. void Button::triggerClick()
  33952. {
  33953. postCommandMessage (clickMessageId);
  33954. }
  33955. void Button::internalClickCallback (const ModifierKeys& modifiers)
  33956. {
  33957. if (clickTogglesState)
  33958. setToggleState ((radioGroupId != 0) || ! lastToggleState, false);
  33959. sendClickMessage (modifiers);
  33960. }
  33961. void Button::flashButtonState()
  33962. {
  33963. if (isEnabled())
  33964. {
  33965. needsToRelease = true;
  33966. setState (buttonDown);
  33967. getRepeatTimer().startTimer (100);
  33968. }
  33969. }
  33970. void Button::handleCommandMessage (int commandId)
  33971. {
  33972. if (commandId == clickMessageId)
  33973. {
  33974. if (isEnabled())
  33975. {
  33976. flashButtonState();
  33977. internalClickCallback (ModifierKeys::getCurrentModifiers());
  33978. }
  33979. }
  33980. else
  33981. {
  33982. Component::handleCommandMessage (commandId);
  33983. }
  33984. }
  33985. void Button::addButtonListener (ButtonListener* const newListener)
  33986. {
  33987. buttonListeners.add (newListener);
  33988. }
  33989. void Button::removeButtonListener (ButtonListener* const listener)
  33990. {
  33991. buttonListeners.remove (listener);
  33992. }
  33993. void Button::sendClickMessage (const ModifierKeys& modifiers)
  33994. {
  33995. Component::BailOutChecker checker (this);
  33996. if (commandManagerToUse != 0 && commandID != 0)
  33997. {
  33998. ApplicationCommandTarget::InvocationInfo info (commandID);
  33999. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromButton;
  34000. info.originatingComponent = this;
  34001. commandManagerToUse->invoke (info, true);
  34002. }
  34003. clicked (modifiers);
  34004. if (! checker.shouldBailOut())
  34005. buttonListeners.callChecked (checker, &ButtonListener::buttonClicked, this);
  34006. }
  34007. void Button::sendStateMessage()
  34008. {
  34009. Component::BailOutChecker checker (this);
  34010. buttonStateChanged();
  34011. if (! checker.shouldBailOut())
  34012. buttonListeners.callChecked (checker, &ButtonListener::buttonStateChanged, this);
  34013. }
  34014. void Button::paint (Graphics& g)
  34015. {
  34016. if (needsToRelease && isEnabled())
  34017. {
  34018. needsToRelease = false;
  34019. needsRepainting = true;
  34020. }
  34021. paintButton (g, isOver(), isDown());
  34022. }
  34023. void Button::mouseEnter (const MouseEvent& e)
  34024. {
  34025. updateState (&e);
  34026. }
  34027. void Button::mouseExit (const MouseEvent& e)
  34028. {
  34029. updateState (&e);
  34030. }
  34031. void Button::mouseDown (const MouseEvent& e)
  34032. {
  34033. updateState (&e);
  34034. if (isDown())
  34035. {
  34036. if (autoRepeatDelay >= 0)
  34037. getRepeatTimer().startTimer (autoRepeatDelay);
  34038. if (triggerOnMouseDown)
  34039. internalClickCallback (e.mods);
  34040. }
  34041. }
  34042. void Button::mouseUp (const MouseEvent& e)
  34043. {
  34044. const bool wasDown = isDown();
  34045. updateState (&e);
  34046. if (wasDown && isOver() && ! triggerOnMouseDown)
  34047. internalClickCallback (e.mods);
  34048. }
  34049. void Button::mouseDrag (const MouseEvent& e)
  34050. {
  34051. const ButtonState oldState = buttonState;
  34052. updateState (&e);
  34053. if (autoRepeatDelay >= 0 && buttonState != oldState && isDown())
  34054. getRepeatTimer().startTimer (autoRepeatSpeed);
  34055. }
  34056. void Button::focusGained (FocusChangeType)
  34057. {
  34058. updateState (0);
  34059. repaint();
  34060. }
  34061. void Button::focusLost (FocusChangeType)
  34062. {
  34063. updateState (0);
  34064. repaint();
  34065. }
  34066. void Button::setVisible (bool shouldBeVisible)
  34067. {
  34068. if (shouldBeVisible != isVisible())
  34069. {
  34070. Component::setVisible (shouldBeVisible);
  34071. if (! shouldBeVisible)
  34072. needsToRelease = false;
  34073. updateState (0);
  34074. }
  34075. else
  34076. {
  34077. Component::setVisible (shouldBeVisible);
  34078. }
  34079. }
  34080. void Button::parentHierarchyChanged()
  34081. {
  34082. Component* const newKeySource = (shortcuts.size() == 0) ? 0 : getTopLevelComponent();
  34083. if (newKeySource != keySource.getComponent())
  34084. {
  34085. if (keySource != 0)
  34086. keySource->removeKeyListener (this);
  34087. keySource = newKeySource;
  34088. if (keySource != 0)
  34089. keySource->addKeyListener (this);
  34090. }
  34091. }
  34092. void Button::setCommandToTrigger (ApplicationCommandManager* const commandManagerToUse_,
  34093. const int commandID_,
  34094. const bool generateTooltip_)
  34095. {
  34096. commandID = commandID_;
  34097. generateTooltip = generateTooltip_;
  34098. if (commandManagerToUse != commandManagerToUse_)
  34099. {
  34100. if (commandManagerToUse != 0)
  34101. commandManagerToUse->removeListener (this);
  34102. commandManagerToUse = commandManagerToUse_;
  34103. if (commandManagerToUse != 0)
  34104. commandManagerToUse->addListener (this);
  34105. // if you've got clickTogglesState turned on, you shouldn't also connect the button
  34106. // up to be a command invoker. Instead, your command handler must flip the state of whatever
  34107. // it is that this button represents, and the button will update its state to reflect this
  34108. // in the applicationCommandListChanged() method.
  34109. jassert (commandManagerToUse == 0 || ! clickTogglesState);
  34110. }
  34111. if (commandManagerToUse != 0)
  34112. applicationCommandListChanged();
  34113. else
  34114. setEnabled (true);
  34115. }
  34116. void Button::applicationCommandInvoked (const ApplicationCommandTarget::InvocationInfo& info)
  34117. {
  34118. if (info.commandID == commandID
  34119. && (info.commandFlags & ApplicationCommandInfo::dontTriggerVisualFeedback) == 0)
  34120. {
  34121. flashButtonState();
  34122. }
  34123. }
  34124. void Button::applicationCommandListChanged()
  34125. {
  34126. if (commandManagerToUse != 0)
  34127. {
  34128. ApplicationCommandInfo info (0);
  34129. ApplicationCommandTarget* const target = commandManagerToUse->getTargetForCommand (commandID, info);
  34130. setEnabled (target != 0 && (info.flags & ApplicationCommandInfo::isDisabled) == 0);
  34131. if (target != 0)
  34132. setToggleState ((info.flags & ApplicationCommandInfo::isTicked) != 0, false);
  34133. }
  34134. }
  34135. void Button::addShortcut (const KeyPress& key)
  34136. {
  34137. if (key.isValid())
  34138. {
  34139. jassert (! isRegisteredForShortcut (key)); // already registered!
  34140. shortcuts.add (key);
  34141. parentHierarchyChanged();
  34142. }
  34143. }
  34144. void Button::clearShortcuts()
  34145. {
  34146. shortcuts.clear();
  34147. parentHierarchyChanged();
  34148. }
  34149. bool Button::isShortcutPressed() const
  34150. {
  34151. if (! isCurrentlyBlockedByAnotherModalComponent())
  34152. {
  34153. for (int i = shortcuts.size(); --i >= 0;)
  34154. if (shortcuts.getReference(i).isCurrentlyDown())
  34155. return true;
  34156. }
  34157. return false;
  34158. }
  34159. bool Button::isRegisteredForShortcut (const KeyPress& key) const
  34160. {
  34161. for (int i = shortcuts.size(); --i >= 0;)
  34162. if (key == shortcuts.getReference(i))
  34163. return true;
  34164. return false;
  34165. }
  34166. bool Button::keyStateChanged (const bool, Component*)
  34167. {
  34168. if (! isEnabled())
  34169. return false;
  34170. const bool wasDown = isKeyDown;
  34171. isKeyDown = isShortcutPressed();
  34172. if (autoRepeatDelay >= 0 && (isKeyDown && ! wasDown))
  34173. getRepeatTimer().startTimer (autoRepeatDelay);
  34174. updateState (0);
  34175. if (isEnabled() && wasDown && ! isKeyDown)
  34176. {
  34177. internalClickCallback (ModifierKeys::getCurrentModifiers());
  34178. // (return immediately - this button may now have been deleted)
  34179. return true;
  34180. }
  34181. return wasDown || isKeyDown;
  34182. }
  34183. bool Button::keyPressed (const KeyPress&, Component*)
  34184. {
  34185. // returning true will avoid forwarding events for keys that we're using as shortcuts
  34186. return isShortcutPressed();
  34187. }
  34188. bool Button::keyPressed (const KeyPress& key)
  34189. {
  34190. if (isEnabled() && key.isKeyCode (KeyPress::returnKey))
  34191. {
  34192. triggerClick();
  34193. return true;
  34194. }
  34195. return false;
  34196. }
  34197. void Button::setRepeatSpeed (const int initialDelayMillisecs,
  34198. const int repeatMillisecs,
  34199. const int minimumDelayInMillisecs) throw()
  34200. {
  34201. autoRepeatDelay = initialDelayMillisecs;
  34202. autoRepeatSpeed = repeatMillisecs;
  34203. autoRepeatMinimumDelay = jmin (autoRepeatSpeed, minimumDelayInMillisecs);
  34204. }
  34205. void Button::repeatTimerCallback()
  34206. {
  34207. if (needsRepainting)
  34208. {
  34209. getRepeatTimer().stopTimer();
  34210. updateState (0);
  34211. needsRepainting = false;
  34212. }
  34213. else if (autoRepeatSpeed > 0 && (isKeyDown || (updateState (0) == buttonDown)))
  34214. {
  34215. int repeatSpeed = autoRepeatSpeed;
  34216. if (autoRepeatMinimumDelay >= 0)
  34217. {
  34218. double timeHeldDown = jmin (1.0, getMillisecondsSinceButtonDown() / 4000.0);
  34219. timeHeldDown *= timeHeldDown;
  34220. repeatSpeed = repeatSpeed + (int) (timeHeldDown * (autoRepeatMinimumDelay - repeatSpeed));
  34221. }
  34222. repeatSpeed = jmax (1, repeatSpeed);
  34223. getRepeatTimer().startTimer (repeatSpeed);
  34224. const uint32 now = Time::getApproximateMillisecondCounter();
  34225. const int numTimesToCallback = (now > lastTimeCallbackTime) ? jmax (1, (int) (now - lastTimeCallbackTime) / repeatSpeed) : 1;
  34226. lastTimeCallbackTime = now;
  34227. Component::SafePointer<Component> deletionWatcher (this);
  34228. for (int i = numTimesToCallback; --i >= 0;)
  34229. {
  34230. internalClickCallback (ModifierKeys::getCurrentModifiers());
  34231. if (deletionWatcher == 0 || ! isDown())
  34232. return;
  34233. }
  34234. }
  34235. else if (! needsToRelease)
  34236. {
  34237. getRepeatTimer().stopTimer();
  34238. }
  34239. }
  34240. Button::RepeatTimer& Button::getRepeatTimer()
  34241. {
  34242. if (repeatTimer == 0)
  34243. repeatTimer = new RepeatTimer (*this);
  34244. return *repeatTimer;
  34245. }
  34246. END_JUCE_NAMESPACE
  34247. /*** End of inlined file: juce_Button.cpp ***/
  34248. /*** Start of inlined file: juce_DrawableButton.cpp ***/
  34249. BEGIN_JUCE_NAMESPACE
  34250. DrawableButton::DrawableButton (const String& name,
  34251. const DrawableButton::ButtonStyle buttonStyle)
  34252. : Button (name),
  34253. style (buttonStyle),
  34254. edgeIndent (3)
  34255. {
  34256. if (buttonStyle == ImageOnButtonBackground)
  34257. {
  34258. backgroundOff = Colour (0xffbbbbff);
  34259. backgroundOn = Colour (0xff3333ff);
  34260. }
  34261. else
  34262. {
  34263. backgroundOff = Colours::transparentBlack;
  34264. backgroundOn = Colour (0xaabbbbff);
  34265. }
  34266. }
  34267. DrawableButton::~DrawableButton()
  34268. {
  34269. deleteImages();
  34270. }
  34271. void DrawableButton::deleteImages()
  34272. {
  34273. }
  34274. void DrawableButton::setImages (const Drawable* normal,
  34275. const Drawable* over,
  34276. const Drawable* down,
  34277. const Drawable* disabled,
  34278. const Drawable* normalOn,
  34279. const Drawable* overOn,
  34280. const Drawable* downOn,
  34281. const Drawable* disabledOn)
  34282. {
  34283. deleteImages();
  34284. jassert (normal != 0); // you really need to give it at least a normal image..
  34285. if (normal != 0)
  34286. normalImage = normal->createCopy();
  34287. if (over != 0)
  34288. overImage = over->createCopy();
  34289. if (down != 0)
  34290. downImage = down->createCopy();
  34291. if (disabled != 0)
  34292. disabledImage = disabled->createCopy();
  34293. if (normalOn != 0)
  34294. normalImageOn = normalOn->createCopy();
  34295. if (overOn != 0)
  34296. overImageOn = overOn->createCopy();
  34297. if (downOn != 0)
  34298. downImageOn = downOn->createCopy();
  34299. if (disabledOn != 0)
  34300. disabledImageOn = disabledOn->createCopy();
  34301. repaint();
  34302. }
  34303. void DrawableButton::setButtonStyle (const DrawableButton::ButtonStyle newStyle)
  34304. {
  34305. if (style != newStyle)
  34306. {
  34307. style = newStyle;
  34308. repaint();
  34309. }
  34310. }
  34311. void DrawableButton::setBackgroundColours (const Colour& toggledOffColour,
  34312. const Colour& toggledOnColour)
  34313. {
  34314. if (backgroundOff != toggledOffColour
  34315. || backgroundOn != toggledOnColour)
  34316. {
  34317. backgroundOff = toggledOffColour;
  34318. backgroundOn = toggledOnColour;
  34319. repaint();
  34320. }
  34321. }
  34322. const Colour& DrawableButton::getBackgroundColour() const throw()
  34323. {
  34324. return getToggleState() ? backgroundOn
  34325. : backgroundOff;
  34326. }
  34327. void DrawableButton::setEdgeIndent (const int numPixelsIndent)
  34328. {
  34329. edgeIndent = numPixelsIndent;
  34330. repaint();
  34331. }
  34332. void DrawableButton::paintButton (Graphics& g,
  34333. bool isMouseOverButton,
  34334. bool isButtonDown)
  34335. {
  34336. Rectangle<int> imageSpace;
  34337. if (style == ImageOnButtonBackground)
  34338. {
  34339. const int insetX = getWidth() / 4;
  34340. const int insetY = getHeight() / 4;
  34341. imageSpace.setBounds (insetX, insetY, getWidth() - insetX * 2, getHeight() - insetY * 2);
  34342. getLookAndFeel().drawButtonBackground (g, *this,
  34343. getBackgroundColour(),
  34344. isMouseOverButton,
  34345. isButtonDown);
  34346. }
  34347. else
  34348. {
  34349. g.fillAll (getBackgroundColour());
  34350. const int textH = (style == ImageAboveTextLabel)
  34351. ? jmin (16, proportionOfHeight (0.25f))
  34352. : 0;
  34353. const int indentX = jmin (edgeIndent, proportionOfWidth (0.3f));
  34354. const int indentY = jmin (edgeIndent, proportionOfHeight (0.3f));
  34355. imageSpace.setBounds (indentX, indentY,
  34356. getWidth() - indentX * 2,
  34357. getHeight() - indentY * 2 - textH);
  34358. if (textH > 0)
  34359. {
  34360. g.setFont ((float) textH);
  34361. g.setColour (Colours::black.withAlpha (isEnabled() ? 1.0f : 0.4f));
  34362. g.drawFittedText (getButtonText(),
  34363. 2, getHeight() - textH - 1,
  34364. getWidth() - 4, textH,
  34365. Justification::centred, 1);
  34366. }
  34367. }
  34368. g.setImageResamplingQuality (Graphics::mediumResamplingQuality);
  34369. g.setOpacity (1.0f);
  34370. const Drawable* imageToDraw = 0;
  34371. if (isEnabled())
  34372. {
  34373. imageToDraw = getCurrentImage();
  34374. }
  34375. else
  34376. {
  34377. imageToDraw = getToggleState() ? disabledImageOn
  34378. : disabledImage;
  34379. if (imageToDraw == 0)
  34380. {
  34381. g.setOpacity (0.4f);
  34382. imageToDraw = getNormalImage();
  34383. }
  34384. }
  34385. if (imageToDraw != 0)
  34386. {
  34387. if (style == ImageRaw)
  34388. {
  34389. imageToDraw->draw (g, 1.0f);
  34390. }
  34391. else
  34392. {
  34393. imageToDraw->drawWithin (g,
  34394. imageSpace.getX(),
  34395. imageSpace.getY(),
  34396. imageSpace.getWidth(),
  34397. imageSpace.getHeight(),
  34398. RectanglePlacement::centred,
  34399. 1.0f);
  34400. }
  34401. }
  34402. }
  34403. const Drawable* DrawableButton::getCurrentImage() const throw()
  34404. {
  34405. if (isDown())
  34406. return getDownImage();
  34407. if (isOver())
  34408. return getOverImage();
  34409. return getNormalImage();
  34410. }
  34411. const Drawable* DrawableButton::getNormalImage() const throw()
  34412. {
  34413. return (getToggleState() && normalImageOn != 0) ? normalImageOn
  34414. : normalImage;
  34415. }
  34416. const Drawable* DrawableButton::getOverImage() const throw()
  34417. {
  34418. const Drawable* d = normalImage;
  34419. if (getToggleState())
  34420. {
  34421. if (overImageOn != 0)
  34422. d = overImageOn;
  34423. else if (normalImageOn != 0)
  34424. d = normalImageOn;
  34425. else if (overImage != 0)
  34426. d = overImage;
  34427. }
  34428. else
  34429. {
  34430. if (overImage != 0)
  34431. d = overImage;
  34432. }
  34433. return d;
  34434. }
  34435. const Drawable* DrawableButton::getDownImage() const throw()
  34436. {
  34437. const Drawable* d = normalImage;
  34438. if (getToggleState())
  34439. {
  34440. if (downImageOn != 0)
  34441. d = downImageOn;
  34442. else if (overImageOn != 0)
  34443. d = overImageOn;
  34444. else if (normalImageOn != 0)
  34445. d = normalImageOn;
  34446. else if (downImage != 0)
  34447. d = downImage;
  34448. else
  34449. d = getOverImage();
  34450. }
  34451. else
  34452. {
  34453. if (downImage != 0)
  34454. d = downImage;
  34455. else
  34456. d = getOverImage();
  34457. }
  34458. return d;
  34459. }
  34460. END_JUCE_NAMESPACE
  34461. /*** End of inlined file: juce_DrawableButton.cpp ***/
  34462. /*** Start of inlined file: juce_HyperlinkButton.cpp ***/
  34463. BEGIN_JUCE_NAMESPACE
  34464. HyperlinkButton::HyperlinkButton (const String& linkText,
  34465. const URL& linkURL)
  34466. : Button (linkText),
  34467. url (linkURL),
  34468. font (14.0f, Font::underlined),
  34469. resizeFont (true),
  34470. justification (Justification::centred)
  34471. {
  34472. setMouseCursor (MouseCursor::PointingHandCursor);
  34473. setTooltip (linkURL.toString (false));
  34474. }
  34475. HyperlinkButton::~HyperlinkButton()
  34476. {
  34477. }
  34478. void HyperlinkButton::setFont (const Font& newFont,
  34479. const bool resizeToMatchComponentHeight,
  34480. const Justification& justificationType)
  34481. {
  34482. font = newFont;
  34483. resizeFont = resizeToMatchComponentHeight;
  34484. justification = justificationType;
  34485. repaint();
  34486. }
  34487. void HyperlinkButton::setURL (const URL& newURL) throw()
  34488. {
  34489. url = newURL;
  34490. setTooltip (newURL.toString (false));
  34491. }
  34492. const Font HyperlinkButton::getFontToUse() const
  34493. {
  34494. Font f (font);
  34495. if (resizeFont)
  34496. f.setHeight (getHeight() * 0.7f);
  34497. return f;
  34498. }
  34499. void HyperlinkButton::changeWidthToFitText()
  34500. {
  34501. setSize (getFontToUse().getStringWidth (getName()) + 6, getHeight());
  34502. }
  34503. void HyperlinkButton::colourChanged()
  34504. {
  34505. repaint();
  34506. }
  34507. void HyperlinkButton::clicked()
  34508. {
  34509. if (url.isWellFormed())
  34510. url.launchInDefaultBrowser();
  34511. }
  34512. void HyperlinkButton::paintButton (Graphics& g,
  34513. bool isMouseOverButton,
  34514. bool isButtonDown)
  34515. {
  34516. const Colour textColour (findColour (textColourId));
  34517. if (isEnabled())
  34518. g.setColour ((isMouseOverButton) ? textColour.darker ((isButtonDown) ? 1.3f : 0.4f)
  34519. : textColour);
  34520. else
  34521. g.setColour (textColour.withMultipliedAlpha (0.4f));
  34522. g.setFont (getFontToUse());
  34523. g.drawText (getButtonText(),
  34524. 2, 0, getWidth() - 2, getHeight(),
  34525. justification.getOnlyHorizontalFlags() | Justification::verticallyCentred,
  34526. true);
  34527. }
  34528. END_JUCE_NAMESPACE
  34529. /*** End of inlined file: juce_HyperlinkButton.cpp ***/
  34530. /*** Start of inlined file: juce_ImageButton.cpp ***/
  34531. BEGIN_JUCE_NAMESPACE
  34532. ImageButton::ImageButton (const String& text_)
  34533. : Button (text_),
  34534. scaleImageToFit (true),
  34535. preserveProportions (true),
  34536. alphaThreshold (0),
  34537. imageX (0),
  34538. imageY (0),
  34539. imageW (0),
  34540. imageH (0),
  34541. normalImage (0),
  34542. overImage (0),
  34543. downImage (0)
  34544. {
  34545. }
  34546. ImageButton::~ImageButton()
  34547. {
  34548. deleteImages();
  34549. }
  34550. void ImageButton::deleteImages()
  34551. {
  34552. ImageCache::releaseOrDelete (normalImage);
  34553. ImageCache::releaseOrDelete (overImage);
  34554. ImageCache::releaseOrDelete (downImage);
  34555. }
  34556. void ImageButton::setImages (const bool resizeButtonNowToFitThisImage,
  34557. const bool rescaleImagesWhenButtonSizeChanges,
  34558. const bool preserveImageProportions,
  34559. Image* const normalImage_,
  34560. const float imageOpacityWhenNormal,
  34561. const Colour& overlayColourWhenNormal,
  34562. Image* const overImage_,
  34563. const float imageOpacityWhenOver,
  34564. const Colour& overlayColourWhenOver,
  34565. Image* const downImage_,
  34566. const float imageOpacityWhenDown,
  34567. const Colour& overlayColourWhenDown,
  34568. const float hitTestAlphaThreshold)
  34569. {
  34570. deleteImages();
  34571. normalImage = normalImage_;
  34572. overImage = overImage_;
  34573. downImage = downImage_;
  34574. if (resizeButtonNowToFitThisImage && normalImage != 0)
  34575. {
  34576. imageW = normalImage->getWidth();
  34577. imageH = normalImage->getHeight();
  34578. setSize (imageW, imageH);
  34579. }
  34580. scaleImageToFit = rescaleImagesWhenButtonSizeChanges;
  34581. preserveProportions = preserveImageProportions;
  34582. normalOpacity = imageOpacityWhenNormal;
  34583. normalOverlay = overlayColourWhenNormal;
  34584. overOpacity = imageOpacityWhenOver;
  34585. overOverlay = overlayColourWhenOver;
  34586. downOpacity = imageOpacityWhenDown;
  34587. downOverlay = overlayColourWhenDown;
  34588. alphaThreshold = (unsigned char) jlimit (0, 0xff, roundToInt (255.0f * hitTestAlphaThreshold));
  34589. repaint();
  34590. }
  34591. Image* ImageButton::getCurrentImage() const
  34592. {
  34593. if (isDown() || getToggleState())
  34594. return getDownImage();
  34595. if (isOver())
  34596. return getOverImage();
  34597. return getNormalImage();
  34598. }
  34599. Image* ImageButton::getNormalImage() const throw()
  34600. {
  34601. return normalImage;
  34602. }
  34603. Image* ImageButton::getOverImage() const throw()
  34604. {
  34605. return (overImage != 0) ? overImage
  34606. : normalImage;
  34607. }
  34608. Image* ImageButton::getDownImage() const throw()
  34609. {
  34610. return (downImage != 0) ? downImage
  34611. : getOverImage();
  34612. }
  34613. void ImageButton::paintButton (Graphics& g,
  34614. bool isMouseOverButton,
  34615. bool isButtonDown)
  34616. {
  34617. if (! isEnabled())
  34618. {
  34619. isMouseOverButton = false;
  34620. isButtonDown = false;
  34621. }
  34622. Image* const im = getCurrentImage();
  34623. if (im != 0)
  34624. {
  34625. const int iw = im->getWidth();
  34626. const int ih = im->getHeight();
  34627. imageW = getWidth();
  34628. imageH = getHeight();
  34629. imageX = (imageW - iw) >> 1;
  34630. imageY = (imageH - ih) >> 1;
  34631. if (scaleImageToFit)
  34632. {
  34633. if (preserveProportions)
  34634. {
  34635. int newW, newH;
  34636. const float imRatio = ih / (float)iw;
  34637. const float destRatio = imageH / (float)imageW;
  34638. if (imRatio > destRatio)
  34639. {
  34640. newW = roundToInt (imageH / imRatio);
  34641. newH = imageH;
  34642. }
  34643. else
  34644. {
  34645. newW = imageW;
  34646. newH = roundToInt (imageW * imRatio);
  34647. }
  34648. imageX = (imageW - newW) / 2;
  34649. imageY = (imageH - newH) / 2;
  34650. imageW = newW;
  34651. imageH = newH;
  34652. }
  34653. else
  34654. {
  34655. imageX = 0;
  34656. imageY = 0;
  34657. }
  34658. }
  34659. if (! scaleImageToFit)
  34660. {
  34661. imageW = iw;
  34662. imageH = ih;
  34663. }
  34664. getLookAndFeel().drawImageButton (g, im, imageX, imageY, imageW, imageH,
  34665. isButtonDown ? downOverlay
  34666. : (isMouseOverButton ? overOverlay
  34667. : normalOverlay),
  34668. isButtonDown ? downOpacity
  34669. : (isMouseOverButton ? overOpacity
  34670. : normalOpacity),
  34671. *this);
  34672. }
  34673. }
  34674. bool ImageButton::hitTest (int x, int y)
  34675. {
  34676. if (alphaThreshold == 0)
  34677. return true;
  34678. Image* const im = getCurrentImage();
  34679. return im == 0
  34680. || (imageW > 0 && imageH > 0
  34681. && alphaThreshold < im->getPixelAt (((x - imageX) * im->getWidth()) / imageW,
  34682. ((y - imageY) * im->getHeight()) / imageH).getAlpha());
  34683. }
  34684. END_JUCE_NAMESPACE
  34685. /*** End of inlined file: juce_ImageButton.cpp ***/
  34686. /*** Start of inlined file: juce_ShapeButton.cpp ***/
  34687. BEGIN_JUCE_NAMESPACE
  34688. ShapeButton::ShapeButton (const String& text_,
  34689. const Colour& normalColour_,
  34690. const Colour& overColour_,
  34691. const Colour& downColour_)
  34692. : Button (text_),
  34693. normalColour (normalColour_),
  34694. overColour (overColour_),
  34695. downColour (downColour_),
  34696. maintainShapeProportions (false),
  34697. outlineWidth (0.0f)
  34698. {
  34699. }
  34700. ShapeButton::~ShapeButton()
  34701. {
  34702. }
  34703. void ShapeButton::setColours (const Colour& newNormalColour,
  34704. const Colour& newOverColour,
  34705. const Colour& newDownColour)
  34706. {
  34707. normalColour = newNormalColour;
  34708. overColour = newOverColour;
  34709. downColour = newDownColour;
  34710. }
  34711. void ShapeButton::setOutline (const Colour& newOutlineColour,
  34712. const float newOutlineWidth)
  34713. {
  34714. outlineColour = newOutlineColour;
  34715. outlineWidth = newOutlineWidth;
  34716. }
  34717. void ShapeButton::setShape (const Path& newShape,
  34718. const bool resizeNowToFitThisShape,
  34719. const bool maintainShapeProportions_,
  34720. const bool hasShadow)
  34721. {
  34722. shape = newShape;
  34723. maintainShapeProportions = maintainShapeProportions_;
  34724. shadow.setShadowProperties (3.0f, 0.5f, 0, 0);
  34725. setComponentEffect ((hasShadow) ? &shadow : 0);
  34726. if (resizeNowToFitThisShape)
  34727. {
  34728. Rectangle<float> bounds (shape.getBounds());
  34729. if (hasShadow)
  34730. bounds.expand (4.0f, 4.0f);
  34731. shape.applyTransform (AffineTransform::translation (-bounds.getX(), -bounds.getY()));
  34732. setSize (1 + (int) (bounds.getWidth() + outlineWidth),
  34733. 1 + (int) (bounds.getHeight() + outlineWidth));
  34734. }
  34735. }
  34736. void ShapeButton::paintButton (Graphics& g, bool isMouseOverButton, bool isButtonDown)
  34737. {
  34738. if (! isEnabled())
  34739. {
  34740. isMouseOverButton = false;
  34741. isButtonDown = false;
  34742. }
  34743. g.setColour ((isButtonDown) ? downColour
  34744. : (isMouseOverButton) ? overColour
  34745. : normalColour);
  34746. int w = getWidth();
  34747. int h = getHeight();
  34748. if (getComponentEffect() != 0)
  34749. {
  34750. w -= 4;
  34751. h -= 4;
  34752. }
  34753. const float offset = (outlineWidth * 0.5f) + (isButtonDown ? 1.5f : 0.0f);
  34754. const AffineTransform trans (shape.getTransformToScaleToFit (offset, offset,
  34755. w - offset - outlineWidth,
  34756. h - offset - outlineWidth,
  34757. maintainShapeProportions));
  34758. g.fillPath (shape, trans);
  34759. if (outlineWidth > 0.0f)
  34760. {
  34761. g.setColour (outlineColour);
  34762. g.strokePath (shape, PathStrokeType (outlineWidth), trans);
  34763. }
  34764. }
  34765. END_JUCE_NAMESPACE
  34766. /*** End of inlined file: juce_ShapeButton.cpp ***/
  34767. /*** Start of inlined file: juce_TextButton.cpp ***/
  34768. BEGIN_JUCE_NAMESPACE
  34769. TextButton::TextButton (const String& name,
  34770. const String& toolTip)
  34771. : Button (name)
  34772. {
  34773. setTooltip (toolTip);
  34774. }
  34775. TextButton::~TextButton()
  34776. {
  34777. }
  34778. void TextButton::paintButton (Graphics& g,
  34779. bool isMouseOverButton,
  34780. bool isButtonDown)
  34781. {
  34782. getLookAndFeel().drawButtonBackground (g, *this,
  34783. findColour (getToggleState() ? buttonOnColourId
  34784. : buttonColourId),
  34785. isMouseOverButton,
  34786. isButtonDown);
  34787. getLookAndFeel().drawButtonText (g, *this,
  34788. isMouseOverButton,
  34789. isButtonDown);
  34790. }
  34791. void TextButton::colourChanged()
  34792. {
  34793. repaint();
  34794. }
  34795. const Font TextButton::getFont()
  34796. {
  34797. return Font (jmin (15.0f, getHeight() * 0.6f));
  34798. }
  34799. void TextButton::changeWidthToFitText (const int newHeight)
  34800. {
  34801. if (newHeight >= 0)
  34802. setSize (jmax (1, getWidth()), newHeight);
  34803. setSize (getFont().getStringWidth (getButtonText()) + getHeight(),
  34804. getHeight());
  34805. }
  34806. END_JUCE_NAMESPACE
  34807. /*** End of inlined file: juce_TextButton.cpp ***/
  34808. /*** Start of inlined file: juce_ToggleButton.cpp ***/
  34809. BEGIN_JUCE_NAMESPACE
  34810. ToggleButton::ToggleButton (const String& buttonText)
  34811. : Button (buttonText)
  34812. {
  34813. setClickingTogglesState (true);
  34814. }
  34815. ToggleButton::~ToggleButton()
  34816. {
  34817. }
  34818. void ToggleButton::paintButton (Graphics& g,
  34819. bool isMouseOverButton,
  34820. bool isButtonDown)
  34821. {
  34822. getLookAndFeel().drawToggleButton (g, *this,
  34823. isMouseOverButton,
  34824. isButtonDown);
  34825. }
  34826. void ToggleButton::changeWidthToFitText()
  34827. {
  34828. getLookAndFeel().changeToggleButtonWidthToFitText (*this);
  34829. }
  34830. void ToggleButton::colourChanged()
  34831. {
  34832. repaint();
  34833. }
  34834. END_JUCE_NAMESPACE
  34835. /*** End of inlined file: juce_ToggleButton.cpp ***/
  34836. /*** Start of inlined file: juce_ToolbarButton.cpp ***/
  34837. BEGIN_JUCE_NAMESPACE
  34838. ToolbarButton::ToolbarButton (const int itemId_,
  34839. const String& buttonText,
  34840. Drawable* const normalImage_,
  34841. Drawable* const toggledOnImage_)
  34842. : ToolbarItemComponent (itemId_, buttonText, true),
  34843. normalImage (normalImage_),
  34844. toggledOnImage (toggledOnImage_)
  34845. {
  34846. }
  34847. ToolbarButton::~ToolbarButton()
  34848. {
  34849. }
  34850. bool ToolbarButton::getToolbarItemSizes (int toolbarDepth,
  34851. bool /*isToolbarVertical*/,
  34852. int& preferredSize,
  34853. int& minSize, int& maxSize)
  34854. {
  34855. preferredSize = minSize = maxSize = toolbarDepth;
  34856. return true;
  34857. }
  34858. void ToolbarButton::paintButtonArea (Graphics& g,
  34859. int width, int height,
  34860. bool /*isMouseOver*/,
  34861. bool /*isMouseDown*/)
  34862. {
  34863. Drawable* d = normalImage;
  34864. if (getToggleState() && toggledOnImage != 0)
  34865. d = toggledOnImage;
  34866. if (! isEnabled())
  34867. {
  34868. Image im (Image::ARGB, width, height, true);
  34869. Graphics g2 (im);
  34870. d->drawWithin (g2, 0, 0, width, height, RectanglePlacement::centred, 1.0f);
  34871. im.desaturate();
  34872. g.drawImageAt (&im, 0, 0);
  34873. }
  34874. else
  34875. {
  34876. d->drawWithin (g, 0, 0, width, height, RectanglePlacement::centred, 1.0f);
  34877. }
  34878. }
  34879. void ToolbarButton::contentAreaChanged (const Rectangle<int>&)
  34880. {
  34881. }
  34882. END_JUCE_NAMESPACE
  34883. /*** End of inlined file: juce_ToolbarButton.cpp ***/
  34884. /*** Start of inlined file: juce_CodeDocument.cpp ***/
  34885. BEGIN_JUCE_NAMESPACE
  34886. class CodeDocumentLine
  34887. {
  34888. public:
  34889. CodeDocumentLine (const tchar* const line_,
  34890. const int lineLength_,
  34891. const int numNewLineChars,
  34892. const int lineStartInFile_)
  34893. : line (line_, lineLength_),
  34894. lineStartInFile (lineStartInFile_),
  34895. lineLength (lineLength_),
  34896. lineLengthWithoutNewLines (lineLength_ - numNewLineChars)
  34897. {
  34898. }
  34899. ~CodeDocumentLine()
  34900. {
  34901. }
  34902. static void createLines (Array <CodeDocumentLine*>& newLines, const String& text)
  34903. {
  34904. const tchar* const t = (const tchar*) text;
  34905. int pos = 0;
  34906. while (t [pos] != 0)
  34907. {
  34908. const int startOfLine = pos;
  34909. int numNewLineChars = 0;
  34910. while (t[pos] != 0)
  34911. {
  34912. if (t[pos] == T('\r'))
  34913. {
  34914. ++numNewLineChars;
  34915. ++pos;
  34916. if (t[pos] == T('\n'))
  34917. {
  34918. ++numNewLineChars;
  34919. ++pos;
  34920. }
  34921. break;
  34922. }
  34923. if (t[pos] == T('\n'))
  34924. {
  34925. ++numNewLineChars;
  34926. ++pos;
  34927. break;
  34928. }
  34929. ++pos;
  34930. }
  34931. newLines.add (new CodeDocumentLine (t + startOfLine, pos - startOfLine,
  34932. numNewLineChars, startOfLine));
  34933. }
  34934. jassert (pos == text.length());
  34935. }
  34936. bool endsWithLineBreak() const throw()
  34937. {
  34938. return lineLengthWithoutNewLines != lineLength;
  34939. }
  34940. void updateLength() throw()
  34941. {
  34942. lineLengthWithoutNewLines = lineLength = line.length();
  34943. while (lineLengthWithoutNewLines > 0
  34944. && (line [lineLengthWithoutNewLines - 1] == '\n'
  34945. || line [lineLengthWithoutNewLines - 1] == '\r'))
  34946. {
  34947. --lineLengthWithoutNewLines;
  34948. }
  34949. }
  34950. String line;
  34951. int lineStartInFile, lineLength, lineLengthWithoutNewLines;
  34952. };
  34953. CodeDocument::Iterator::Iterator (CodeDocument* const document_)
  34954. : document (document_),
  34955. currentLine (document_->lines[0]),
  34956. line (0),
  34957. position (0)
  34958. {
  34959. }
  34960. CodeDocument::Iterator::Iterator (const CodeDocument::Iterator& other)
  34961. : document (other.document),
  34962. currentLine (other.currentLine),
  34963. line (other.line),
  34964. position (other.position)
  34965. {
  34966. }
  34967. CodeDocument::Iterator& CodeDocument::Iterator::operator= (const CodeDocument::Iterator& other) throw()
  34968. {
  34969. document = other.document;
  34970. currentLine = other.currentLine;
  34971. line = other.line;
  34972. position = other.position;
  34973. return *this;
  34974. }
  34975. CodeDocument::Iterator::~Iterator() throw()
  34976. {
  34977. }
  34978. juce_wchar CodeDocument::Iterator::nextChar()
  34979. {
  34980. if (currentLine == 0)
  34981. return 0;
  34982. jassert (currentLine == document->lines.getUnchecked (line));
  34983. const juce_wchar result = currentLine->line [position - currentLine->lineStartInFile];
  34984. if (++position >= currentLine->lineStartInFile + currentLine->lineLength)
  34985. {
  34986. ++line;
  34987. currentLine = document->lines [line];
  34988. }
  34989. return result;
  34990. }
  34991. void CodeDocument::Iterator::skip()
  34992. {
  34993. if (currentLine != 0)
  34994. {
  34995. jassert (currentLine == document->lines.getUnchecked (line));
  34996. if (++position >= currentLine->lineStartInFile + currentLine->lineLength)
  34997. {
  34998. ++line;
  34999. currentLine = document->lines [line];
  35000. }
  35001. }
  35002. }
  35003. void CodeDocument::Iterator::skipToEndOfLine()
  35004. {
  35005. if (currentLine != 0)
  35006. {
  35007. jassert (currentLine == document->lines.getUnchecked (line));
  35008. ++line;
  35009. currentLine = document->lines [line];
  35010. if (currentLine != 0)
  35011. position = currentLine->lineStartInFile;
  35012. else
  35013. position = document->getNumCharacters();
  35014. }
  35015. }
  35016. juce_wchar CodeDocument::Iterator::peekNextChar() const
  35017. {
  35018. if (currentLine == 0)
  35019. return 0;
  35020. jassert (currentLine == document->lines.getUnchecked (line));
  35021. return const_cast <const String&> (currentLine->line) [position - currentLine->lineStartInFile];
  35022. }
  35023. void CodeDocument::Iterator::skipWhitespace()
  35024. {
  35025. while (CharacterFunctions::isWhitespace (peekNextChar()))
  35026. skip();
  35027. }
  35028. bool CodeDocument::Iterator::isEOF() const throw()
  35029. {
  35030. return currentLine == 0;
  35031. }
  35032. CodeDocument::Position::Position() throw()
  35033. : owner (0), characterPos (0), line (0),
  35034. indexInLine (0), positionMaintained (false)
  35035. {
  35036. }
  35037. CodeDocument::Position::Position (const CodeDocument* const ownerDocument,
  35038. const int line_, const int indexInLine_) throw()
  35039. : owner (const_cast <CodeDocument*> (ownerDocument)),
  35040. characterPos (0), line (line_),
  35041. indexInLine (indexInLine_), positionMaintained (false)
  35042. {
  35043. setLineAndIndex (line_, indexInLine_);
  35044. }
  35045. CodeDocument::Position::Position (const CodeDocument* const ownerDocument,
  35046. const int characterPos_) throw()
  35047. : owner (const_cast <CodeDocument*> (ownerDocument)),
  35048. positionMaintained (false)
  35049. {
  35050. setPosition (characterPos_);
  35051. }
  35052. CodeDocument::Position::Position (const Position& other) throw()
  35053. : owner (other.owner), characterPos (other.characterPos), line (other.line),
  35054. indexInLine (other.indexInLine), positionMaintained (false)
  35055. {
  35056. jassert (*this == other);
  35057. }
  35058. CodeDocument::Position::~Position() throw()
  35059. {
  35060. setPositionMaintained (false);
  35061. }
  35062. CodeDocument::Position& CodeDocument::Position::operator= (const Position& other) throw()
  35063. {
  35064. if (this != &other)
  35065. {
  35066. const bool wasPositionMaintained = positionMaintained;
  35067. if (owner != other.owner)
  35068. setPositionMaintained (false);
  35069. owner = other.owner;
  35070. line = other.line;
  35071. indexInLine = other.indexInLine;
  35072. characterPos = other.characterPos;
  35073. setPositionMaintained (wasPositionMaintained);
  35074. jassert (*this == other);
  35075. }
  35076. return *this;
  35077. }
  35078. bool CodeDocument::Position::operator== (const Position& other) const throw()
  35079. {
  35080. jassert ((characterPos == other.characterPos)
  35081. == (line == other.line && indexInLine == other.indexInLine));
  35082. return characterPos == other.characterPos
  35083. && line == other.line
  35084. && indexInLine == other.indexInLine
  35085. && owner == other.owner;
  35086. }
  35087. bool CodeDocument::Position::operator!= (const Position& other) const throw()
  35088. {
  35089. return ! operator== (other);
  35090. }
  35091. void CodeDocument::Position::setLineAndIndex (const int newLine, const int newIndexInLine) throw()
  35092. {
  35093. jassert (owner != 0);
  35094. if (owner->lines.size() == 0)
  35095. {
  35096. line = 0;
  35097. indexInLine = 0;
  35098. characterPos = 0;
  35099. }
  35100. else
  35101. {
  35102. if (newLine >= owner->lines.size())
  35103. {
  35104. line = owner->lines.size() - 1;
  35105. CodeDocumentLine* const l = owner->lines.getUnchecked (line);
  35106. jassert (l != 0);
  35107. indexInLine = l->lineLengthWithoutNewLines;
  35108. characterPos = l->lineStartInFile + indexInLine;
  35109. }
  35110. else
  35111. {
  35112. line = jmax (0, newLine);
  35113. CodeDocumentLine* const l = owner->lines.getUnchecked (line);
  35114. jassert (l != 0);
  35115. if (l->lineLengthWithoutNewLines > 0)
  35116. indexInLine = jlimit (0, l->lineLengthWithoutNewLines, newIndexInLine);
  35117. else
  35118. indexInLine = 0;
  35119. characterPos = l->lineStartInFile + indexInLine;
  35120. }
  35121. }
  35122. }
  35123. void CodeDocument::Position::setPosition (const int newPosition) throw()
  35124. {
  35125. jassert (owner != 0);
  35126. line = 0;
  35127. indexInLine = 0;
  35128. characterPos = 0;
  35129. if (newPosition > 0)
  35130. {
  35131. int lineStart = 0;
  35132. int lineEnd = owner->lines.size();
  35133. for (;;)
  35134. {
  35135. if (lineEnd - lineStart < 4)
  35136. {
  35137. for (int i = lineStart; i < lineEnd; ++i)
  35138. {
  35139. CodeDocumentLine* const l = owner->lines.getUnchecked (i);
  35140. int index = newPosition - l->lineStartInFile;
  35141. if (index >= 0 && (index < l->lineLength || i == lineEnd - 1))
  35142. {
  35143. line = i;
  35144. indexInLine = jmin (l->lineLengthWithoutNewLines, index);
  35145. characterPos = l->lineStartInFile + indexInLine;
  35146. }
  35147. }
  35148. break;
  35149. }
  35150. else
  35151. {
  35152. const int midIndex = (lineStart + lineEnd + 1) / 2;
  35153. CodeDocumentLine* const mid = owner->lines.getUnchecked (midIndex);
  35154. if (newPosition >= mid->lineStartInFile)
  35155. lineStart = midIndex;
  35156. else
  35157. lineEnd = midIndex;
  35158. }
  35159. }
  35160. }
  35161. }
  35162. void CodeDocument::Position::moveBy (int characterDelta) throw()
  35163. {
  35164. jassert (owner != 0);
  35165. if (characterDelta == 1)
  35166. {
  35167. setPosition (getPosition());
  35168. // If moving right, make sure we don't get stuck between the \r and \n characters..
  35169. if (line < owner->lines.size())
  35170. {
  35171. CodeDocumentLine* const l = owner->lines.getUnchecked (line);
  35172. if (indexInLine + characterDelta < l->lineLength
  35173. && indexInLine + characterDelta >= l->lineLengthWithoutNewLines + 1)
  35174. ++characterDelta;
  35175. }
  35176. }
  35177. setPosition (characterPos + characterDelta);
  35178. }
  35179. const CodeDocument::Position CodeDocument::Position::movedBy (const int characterDelta) const throw()
  35180. {
  35181. CodeDocument::Position p (*this);
  35182. p.moveBy (characterDelta);
  35183. return p;
  35184. }
  35185. const CodeDocument::Position CodeDocument::Position::movedByLines (const int deltaLines) const throw()
  35186. {
  35187. CodeDocument::Position p (*this);
  35188. p.setLineAndIndex (getLineNumber() + deltaLines, getIndexInLine());
  35189. return p;
  35190. }
  35191. const tchar CodeDocument::Position::getCharacter() const throw()
  35192. {
  35193. const CodeDocumentLine* const l = owner->lines [line];
  35194. return l == 0 ? 0 : l->line [getIndexInLine()];
  35195. }
  35196. const String CodeDocument::Position::getLineText() const throw()
  35197. {
  35198. const CodeDocumentLine* const l = owner->lines [line];
  35199. return l == 0 ? String::empty : l->line;
  35200. }
  35201. void CodeDocument::Position::setPositionMaintained (const bool isMaintained) throw()
  35202. {
  35203. if (isMaintained != positionMaintained)
  35204. {
  35205. positionMaintained = isMaintained;
  35206. if (owner != 0)
  35207. {
  35208. if (isMaintained)
  35209. {
  35210. jassert (! owner->positionsToMaintain.contains (this));
  35211. owner->positionsToMaintain.add (this);
  35212. }
  35213. else
  35214. {
  35215. jassert (owner->positionsToMaintain.contains (this));
  35216. owner->positionsToMaintain.removeValue (this);
  35217. }
  35218. }
  35219. }
  35220. }
  35221. CodeDocument::CodeDocument()
  35222. : undoManager (std::numeric_limits<int>::max(), 10000),
  35223. currentActionIndex (0),
  35224. indexOfSavedState (-1),
  35225. maximumLineLength (-1),
  35226. newLineChars ("\r\n")
  35227. {
  35228. }
  35229. CodeDocument::~CodeDocument()
  35230. {
  35231. }
  35232. const String CodeDocument::getAllContent() const throw()
  35233. {
  35234. return getTextBetween (Position (this, 0),
  35235. Position (this, lines.size(), 0));
  35236. }
  35237. const String CodeDocument::getTextBetween (const Position& start, const Position& end) const throw()
  35238. {
  35239. if (end.getPosition() <= start.getPosition())
  35240. return String::empty;
  35241. const int startLine = start.getLineNumber();
  35242. const int endLine = end.getLineNumber();
  35243. if (startLine == endLine)
  35244. {
  35245. CodeDocumentLine* const line = lines [startLine];
  35246. return (line == 0) ? String::empty : line->line.substring (start.getIndexInLine(), end.getIndexInLine());
  35247. }
  35248. String result;
  35249. result.preallocateStorage (end.getPosition() - start.getPosition() + 4);
  35250. String::Concatenator concatenator (result);
  35251. const int maxLine = jmin (lines.size() - 1, endLine);
  35252. for (int i = jmax (0, startLine); i <= maxLine; ++i)
  35253. {
  35254. const CodeDocumentLine* line = lines.getUnchecked(i);
  35255. int len = line->lineLength;
  35256. if (i == startLine)
  35257. {
  35258. const int index = start.getIndexInLine();
  35259. concatenator.append (line->line.substring (index, len));
  35260. }
  35261. else if (i == endLine)
  35262. {
  35263. len = end.getIndexInLine();
  35264. concatenator.append (line->line.substring (0, len));
  35265. }
  35266. else
  35267. {
  35268. concatenator.append (line->line);
  35269. }
  35270. }
  35271. return result;
  35272. }
  35273. int CodeDocument::getNumCharacters() const throw()
  35274. {
  35275. const CodeDocumentLine* const lastLine = lines.getLast();
  35276. return (lastLine == 0) ? 0 : lastLine->lineStartInFile + lastLine->lineLength;
  35277. }
  35278. const String CodeDocument::getLine (const int lineIndex) const throw()
  35279. {
  35280. const CodeDocumentLine* const line = lines [lineIndex];
  35281. return (line == 0) ? String::empty : line->line;
  35282. }
  35283. int CodeDocument::getMaximumLineLength() throw()
  35284. {
  35285. if (maximumLineLength < 0)
  35286. {
  35287. maximumLineLength = 0;
  35288. for (int i = lines.size(); --i >= 0;)
  35289. maximumLineLength = jmax (maximumLineLength, lines.getUnchecked(i)->lineLength);
  35290. }
  35291. return maximumLineLength;
  35292. }
  35293. void CodeDocument::deleteSection (const Position& startPosition, const Position& endPosition)
  35294. {
  35295. remove (startPosition.getPosition(), endPosition.getPosition(), true);
  35296. }
  35297. void CodeDocument::insertText (const Position& position, const String& text)
  35298. {
  35299. insert (text, position.getPosition(), true);
  35300. }
  35301. void CodeDocument::replaceAllContent (const String& newContent)
  35302. {
  35303. remove (0, getNumCharacters(), true);
  35304. insert (newContent, 0, true);
  35305. }
  35306. bool CodeDocument::loadFromStream (InputStream& stream)
  35307. {
  35308. replaceAllContent (stream.readEntireStreamAsString());
  35309. setSavePoint();
  35310. clearUndoHistory();
  35311. return true;
  35312. }
  35313. bool CodeDocument::writeToStream (OutputStream& stream)
  35314. {
  35315. for (int i = 0; i < lines.size(); ++i)
  35316. {
  35317. String temp (lines.getUnchecked(i)->line); // use a copy to avoid bloating the memory footprint of the stored string.
  35318. const char* utf8 = temp.toUTF8();
  35319. if (! stream.write (utf8, (int) strlen (utf8)))
  35320. return false;
  35321. }
  35322. return true;
  35323. }
  35324. void CodeDocument::setNewLineCharacters (const String& newLine) throw()
  35325. {
  35326. jassert (newLine == T("\r\n") || newLine == T("\n") || newLine == T("\r"));
  35327. newLineChars = newLine;
  35328. }
  35329. void CodeDocument::newTransaction()
  35330. {
  35331. undoManager.beginNewTransaction (String::empty);
  35332. }
  35333. void CodeDocument::undo()
  35334. {
  35335. newTransaction();
  35336. undoManager.undo();
  35337. }
  35338. void CodeDocument::redo()
  35339. {
  35340. undoManager.redo();
  35341. }
  35342. void CodeDocument::clearUndoHistory()
  35343. {
  35344. undoManager.clearUndoHistory();
  35345. }
  35346. void CodeDocument::setSavePoint() throw()
  35347. {
  35348. indexOfSavedState = currentActionIndex;
  35349. }
  35350. bool CodeDocument::hasChangedSinceSavePoint() const throw()
  35351. {
  35352. return currentActionIndex != indexOfSavedState;
  35353. }
  35354. static int getCodeCharacterCategory (const tchar character) throw()
  35355. {
  35356. return (CharacterFunctions::isLetterOrDigit (character) || character == '_')
  35357. ? 2 : (CharacterFunctions::isWhitespace (character) ? 0 : 1);
  35358. }
  35359. const CodeDocument::Position CodeDocument::findWordBreakAfter (const Position& position) const throw()
  35360. {
  35361. Position p (position);
  35362. const int maxDistance = 256;
  35363. int i = 0;
  35364. while (i < maxDistance
  35365. && CharacterFunctions::isWhitespace (p.getCharacter())
  35366. && (i == 0 || (p.getCharacter() != T('\n')
  35367. && p.getCharacter() != T('\r'))))
  35368. {
  35369. ++i;
  35370. p.moveBy (1);
  35371. }
  35372. if (i == 0)
  35373. {
  35374. const int type = getCodeCharacterCategory (p.getCharacter());
  35375. while (i < maxDistance && type == getCodeCharacterCategory (p.getCharacter()))
  35376. {
  35377. ++i;
  35378. p.moveBy (1);
  35379. }
  35380. while (i < maxDistance
  35381. && CharacterFunctions::isWhitespace (p.getCharacter())
  35382. && (i == 0 || (p.getCharacter() != T('\n')
  35383. && p.getCharacter() != T('\r'))))
  35384. {
  35385. ++i;
  35386. p.moveBy (1);
  35387. }
  35388. }
  35389. return p;
  35390. }
  35391. const CodeDocument::Position CodeDocument::findWordBreakBefore (const Position& position) const throw()
  35392. {
  35393. Position p (position);
  35394. const int maxDistance = 256;
  35395. int i = 0;
  35396. bool stoppedAtLineStart = false;
  35397. while (i < maxDistance)
  35398. {
  35399. const tchar c = p.movedBy (-1).getCharacter();
  35400. if (c == T('\r') || c == T('\n'))
  35401. {
  35402. stoppedAtLineStart = true;
  35403. if (i > 0)
  35404. break;
  35405. }
  35406. if (! CharacterFunctions::isWhitespace (c))
  35407. break;
  35408. p.moveBy (-1);
  35409. ++i;
  35410. }
  35411. if (i < maxDistance && ! stoppedAtLineStart)
  35412. {
  35413. const int type = getCodeCharacterCategory (p.movedBy (-1).getCharacter());
  35414. while (i < maxDistance && type == getCodeCharacterCategory (p.movedBy (-1).getCharacter()))
  35415. {
  35416. p.moveBy (-1);
  35417. ++i;
  35418. }
  35419. }
  35420. return p;
  35421. }
  35422. void CodeDocument::checkLastLineStatus()
  35423. {
  35424. while (lines.size() > 0
  35425. && lines.getLast()->lineLength == 0
  35426. && (lines.size() == 1 || ! lines.getUnchecked (lines.size() - 2)->endsWithLineBreak()))
  35427. {
  35428. // remove any empty lines at the end if the preceding line doesn't end in a newline.
  35429. lines.removeLast();
  35430. }
  35431. const CodeDocumentLine* const lastLine = lines.getLast();
  35432. if (lastLine != 0 && lastLine->endsWithLineBreak())
  35433. {
  35434. // check that there's an empty line at the end if the preceding one ends in a newline..
  35435. lines.add (new CodeDocumentLine (String::empty, 0, 0, lastLine->lineStartInFile + lastLine->lineLength));
  35436. }
  35437. }
  35438. void CodeDocument::addListener (CodeDocument::Listener* const listener) throw()
  35439. {
  35440. listeners.addIfNotAlreadyThere (listener);
  35441. }
  35442. void CodeDocument::removeListener (CodeDocument::Listener* const listener) throw()
  35443. {
  35444. listeners.removeValue (listener);
  35445. }
  35446. void CodeDocument::sendListenerChangeMessage (const int startLine, const int endLine)
  35447. {
  35448. const Position startPos (this, startLine, 0);
  35449. const Position endPos (this, endLine, 0);
  35450. for (int i = listeners.size(); --i >= 0;)
  35451. {
  35452. Listener* const l = (Listener*) listeners[i];
  35453. if (l != 0)
  35454. l->codeDocumentChanged (startPos, endPos);
  35455. }
  35456. }
  35457. class CodeDocumentInsertAction : public UndoableAction
  35458. {
  35459. CodeDocument& owner;
  35460. const String text;
  35461. int insertPos;
  35462. CodeDocumentInsertAction (const CodeDocumentInsertAction&);
  35463. CodeDocumentInsertAction& operator= (const CodeDocumentInsertAction&);
  35464. public:
  35465. CodeDocumentInsertAction (CodeDocument& owner_, const String& text_, const int insertPos_) throw()
  35466. : owner (owner_),
  35467. text (text_),
  35468. insertPos (insertPos_)
  35469. {
  35470. }
  35471. ~CodeDocumentInsertAction() {}
  35472. bool perform()
  35473. {
  35474. owner.currentActionIndex++;
  35475. owner.insert (text, insertPos, false);
  35476. return true;
  35477. }
  35478. bool undo()
  35479. {
  35480. owner.currentActionIndex--;
  35481. owner.remove (insertPos, insertPos + text.length(), false);
  35482. return true;
  35483. }
  35484. int getSizeInUnits() { return text.length() + 32; }
  35485. };
  35486. void CodeDocument::insert (const String& text, const int insertPos, const bool undoable)
  35487. {
  35488. if (text.isEmpty())
  35489. return;
  35490. if (undoable)
  35491. {
  35492. undoManager.perform (new CodeDocumentInsertAction (*this, text, insertPos));
  35493. }
  35494. else
  35495. {
  35496. Position pos (this, insertPos);
  35497. const int firstAffectedLine = pos.getLineNumber();
  35498. int lastAffectedLine = firstAffectedLine + 1;
  35499. CodeDocumentLine* const firstLine = lines [firstAffectedLine];
  35500. String textInsideOriginalLine (text);
  35501. if (firstLine != 0)
  35502. {
  35503. const int index = pos.getIndexInLine();
  35504. textInsideOriginalLine = firstLine->line.substring (0, index)
  35505. + textInsideOriginalLine
  35506. + firstLine->line.substring (index);
  35507. }
  35508. maximumLineLength = -1;
  35509. Array <CodeDocumentLine*> newLines;
  35510. CodeDocumentLine::createLines (newLines, textInsideOriginalLine);
  35511. jassert (newLines.size() > 0);
  35512. CodeDocumentLine* const newFirstLine = newLines.getUnchecked (0);
  35513. newFirstLine->lineStartInFile = firstLine != 0 ? firstLine->lineStartInFile : 0;
  35514. lines.set (firstAffectedLine, newFirstLine);
  35515. if (newLines.size() > 1)
  35516. {
  35517. for (int i = 1; i < newLines.size(); ++i)
  35518. {
  35519. CodeDocumentLine* const l = newLines.getUnchecked (i);
  35520. lines.insert (firstAffectedLine + i, l);
  35521. }
  35522. lastAffectedLine = lines.size();
  35523. }
  35524. int i, lineStart = newFirstLine->lineStartInFile;
  35525. for (i = firstAffectedLine; i < lines.size(); ++i)
  35526. {
  35527. CodeDocumentLine* const l = lines.getUnchecked (i);
  35528. l->lineStartInFile = lineStart;
  35529. lineStart += l->lineLength;
  35530. }
  35531. checkLastLineStatus();
  35532. const int newTextLength = text.length();
  35533. for (i = 0; i < positionsToMaintain.size(); ++i)
  35534. {
  35535. CodeDocument::Position* const p = positionsToMaintain.getUnchecked(i);
  35536. if (p->getPosition() >= insertPos)
  35537. p->setPosition (p->getPosition() + newTextLength);
  35538. }
  35539. sendListenerChangeMessage (firstAffectedLine, lastAffectedLine);
  35540. }
  35541. }
  35542. class CodeDocumentDeleteAction : public UndoableAction
  35543. {
  35544. CodeDocument& owner;
  35545. int startPos, endPos;
  35546. String removedText;
  35547. CodeDocumentDeleteAction (const CodeDocumentDeleteAction&);
  35548. CodeDocumentDeleteAction& operator= (const CodeDocumentDeleteAction&);
  35549. public:
  35550. CodeDocumentDeleteAction (CodeDocument& owner_, const int startPos_, const int endPos_) throw()
  35551. : owner (owner_),
  35552. startPos (startPos_),
  35553. endPos (endPos_)
  35554. {
  35555. removedText = owner.getTextBetween (CodeDocument::Position (&owner, startPos),
  35556. CodeDocument::Position (&owner, endPos));
  35557. }
  35558. ~CodeDocumentDeleteAction() {}
  35559. bool perform()
  35560. {
  35561. owner.currentActionIndex++;
  35562. owner.remove (startPos, endPos, false);
  35563. return true;
  35564. }
  35565. bool undo()
  35566. {
  35567. owner.currentActionIndex--;
  35568. owner.insert (removedText, startPos, false);
  35569. return true;
  35570. }
  35571. int getSizeInUnits() { return removedText.length() + 32; }
  35572. };
  35573. void CodeDocument::remove (const int startPos, const int endPos, const bool undoable)
  35574. {
  35575. if (endPos <= startPos)
  35576. return;
  35577. if (undoable)
  35578. {
  35579. undoManager.perform (new CodeDocumentDeleteAction (*this, startPos, endPos));
  35580. }
  35581. else
  35582. {
  35583. Position startPosition (this, startPos);
  35584. Position endPosition (this, endPos);
  35585. maximumLineLength = -1;
  35586. const int firstAffectedLine = startPosition.getLineNumber();
  35587. const int endLine = endPosition.getLineNumber();
  35588. int lastAffectedLine = firstAffectedLine + 1;
  35589. CodeDocumentLine* const firstLine = lines.getUnchecked (firstAffectedLine);
  35590. if (firstAffectedLine == endLine)
  35591. {
  35592. firstLine->line = firstLine->line.substring (0, startPosition.getIndexInLine())
  35593. + firstLine->line.substring (endPosition.getIndexInLine());
  35594. firstLine->updateLength();
  35595. }
  35596. else
  35597. {
  35598. lastAffectedLine = lines.size();
  35599. CodeDocumentLine* const lastLine = lines.getUnchecked (endLine);
  35600. jassert (lastLine != 0);
  35601. firstLine->line = firstLine->line.substring (0, startPosition.getIndexInLine())
  35602. + lastLine->line.substring (endPosition.getIndexInLine());
  35603. firstLine->updateLength();
  35604. int numLinesToRemove = endLine - firstAffectedLine;
  35605. lines.removeRange (firstAffectedLine + 1, numLinesToRemove);
  35606. }
  35607. int i;
  35608. for (i = firstAffectedLine + 1; i < lines.size(); ++i)
  35609. {
  35610. CodeDocumentLine* const l = lines.getUnchecked (i);
  35611. const CodeDocumentLine* const previousLine = lines.getUnchecked (i - 1);
  35612. l->lineStartInFile = previousLine->lineStartInFile + previousLine->lineLength;
  35613. }
  35614. checkLastLineStatus();
  35615. const int totalChars = getNumCharacters();
  35616. for (i = 0; i < positionsToMaintain.size(); ++i)
  35617. {
  35618. CodeDocument::Position* p = positionsToMaintain.getUnchecked(i);
  35619. if (p->getPosition() > startPosition.getPosition())
  35620. p->setPosition (jmax (startPos, p->getPosition() + startPos - endPos));
  35621. if (p->getPosition() > totalChars)
  35622. p->setPosition (totalChars);
  35623. }
  35624. sendListenerChangeMessage (firstAffectedLine, lastAffectedLine);
  35625. }
  35626. }
  35627. END_JUCE_NAMESPACE
  35628. /*** End of inlined file: juce_CodeDocument.cpp ***/
  35629. /*** Start of inlined file: juce_CodeEditorComponent.cpp ***/
  35630. BEGIN_JUCE_NAMESPACE
  35631. class CaretComponent : public Component,
  35632. public Timer
  35633. {
  35634. public:
  35635. CaretComponent()
  35636. {
  35637. setAlwaysOnTop (true);
  35638. setInterceptsMouseClicks (false, false);
  35639. }
  35640. ~CaretComponent()
  35641. {
  35642. }
  35643. void paint (Graphics& g)
  35644. {
  35645. if (getParentComponent()->hasKeyboardFocus (true))
  35646. g.fillAll (findColour (CodeEditorComponent::caretColourId));
  35647. }
  35648. void timerCallback()
  35649. {
  35650. setVisible (! isVisible());
  35651. }
  35652. void updatePosition (CodeEditorComponent& owner)
  35653. {
  35654. startTimer (400);
  35655. setVisible (true);
  35656. const Rectangle<int> pos (owner.getCharacterBounds (owner.getCaretPos()));
  35657. setBounds (pos.getX(), pos.getY(), 2, pos.getHeight());
  35658. }
  35659. };
  35660. class CodeEditorComponent::CodeEditorLine
  35661. {
  35662. public:
  35663. CodeEditorLine() throw()
  35664. {
  35665. }
  35666. ~CodeEditorLine() throw()
  35667. {
  35668. }
  35669. bool update (CodeDocument& document, int lineNum,
  35670. CodeDocument::Iterator& source,
  35671. CodeTokeniser* analyser, const int spacesPerTab,
  35672. const CodeDocument::Position& selectionStart,
  35673. const CodeDocument::Position& selectionEnd)
  35674. {
  35675. Array <SyntaxToken> newTokens;
  35676. newTokens.ensureStorageAllocated (8);
  35677. if (analyser == 0)
  35678. {
  35679. newTokens.add (SyntaxToken (document.getLine (lineNum), -1));
  35680. }
  35681. else if (lineNum < document.getNumLines())
  35682. {
  35683. const CodeDocument::Position pos (&document, lineNum, 0);
  35684. createTokens (pos.getPosition(), pos.getLineText(),
  35685. source, analyser, newTokens);
  35686. }
  35687. replaceTabsWithSpaces (newTokens, spacesPerTab);
  35688. int newHighlightStart = 0;
  35689. int newHighlightEnd = 0;
  35690. if (selectionStart.getLineNumber() <= lineNum && selectionEnd.getLineNumber() >= lineNum)
  35691. {
  35692. const String line (document.getLine (lineNum));
  35693. CodeDocument::Position lineStart (&document, lineNum, 0), lineEnd (&document, lineNum + 1, 0);
  35694. newHighlightStart = indexToColumn (jmax (0, selectionStart.getPosition() - lineStart.getPosition()),
  35695. line, spacesPerTab);
  35696. newHighlightEnd = indexToColumn (jmin (lineEnd.getPosition() - lineStart.getPosition(), selectionEnd.getPosition() - lineStart.getPosition()),
  35697. line, spacesPerTab);
  35698. }
  35699. if (newHighlightStart != highlightColumnStart || newHighlightEnd != highlightColumnEnd)
  35700. {
  35701. highlightColumnStart = newHighlightStart;
  35702. highlightColumnEnd = newHighlightEnd;
  35703. }
  35704. else
  35705. {
  35706. if (tokens.size() == newTokens.size())
  35707. {
  35708. bool allTheSame = true;
  35709. for (int i = newTokens.size(); --i >= 0;)
  35710. {
  35711. if (tokens.getReference(i) != newTokens.getReference(i))
  35712. {
  35713. allTheSame = false;
  35714. break;
  35715. }
  35716. }
  35717. if (allTheSame)
  35718. return false;
  35719. }
  35720. }
  35721. tokens.swapWithArray (newTokens);
  35722. return true;
  35723. }
  35724. void draw (CodeEditorComponent& owner, Graphics& g, const Font& font,
  35725. float x, const int y, const int baselineOffset, const int lineHeight,
  35726. const Colour& highlightColour) const throw()
  35727. {
  35728. if (highlightColumnStart < highlightColumnEnd)
  35729. {
  35730. g.setColour (highlightColour);
  35731. g.fillRect (roundToInt (x + highlightColumnStart * owner.getCharWidth()), y,
  35732. roundToInt ((highlightColumnEnd - highlightColumnStart) * owner.getCharWidth()), lineHeight);
  35733. }
  35734. int lastType = std::numeric_limits<int>::min();
  35735. for (int i = 0; i < tokens.size(); ++i)
  35736. {
  35737. SyntaxToken& token = tokens.getReference(i);
  35738. if (lastType != token.tokenType)
  35739. {
  35740. lastType = token.tokenType;
  35741. g.setColour (owner.getColourForTokenType (lastType));
  35742. }
  35743. g.drawSingleLineText (token.text, roundToInt (x), y + baselineOffset);
  35744. if (i < tokens.size() - 1)
  35745. {
  35746. if (token.width < 0)
  35747. token.width = font.getStringWidthFloat (token.text);
  35748. x += token.width;
  35749. }
  35750. }
  35751. }
  35752. private:
  35753. struct SyntaxToken
  35754. {
  35755. String text;
  35756. int tokenType;
  35757. float width;
  35758. SyntaxToken (const String& text_, const int type) throw()
  35759. : text (text_), tokenType (type), width (-1.0f)
  35760. {
  35761. }
  35762. bool operator!= (const SyntaxToken& other) const throw()
  35763. {
  35764. return text != other.text || tokenType != other.tokenType;
  35765. }
  35766. };
  35767. Array <SyntaxToken> tokens;
  35768. int highlightColumnStart, highlightColumnEnd;
  35769. static void createTokens (int startPosition, const String& lineText,
  35770. CodeDocument::Iterator& source,
  35771. CodeTokeniser* analyser,
  35772. Array <SyntaxToken>& newTokens)
  35773. {
  35774. CodeDocument::Iterator lastIterator (source);
  35775. const int lineLength = lineText.length();
  35776. for (;;)
  35777. {
  35778. int tokenType = analyser->readNextToken (source);
  35779. int tokenStart = lastIterator.getPosition();
  35780. int tokenEnd = source.getPosition();
  35781. if (tokenEnd <= tokenStart)
  35782. break;
  35783. tokenEnd -= startPosition;
  35784. if (tokenEnd > 0)
  35785. {
  35786. tokenStart -= startPosition;
  35787. newTokens.add (SyntaxToken (lineText.substring (jmax (0, tokenStart), tokenEnd),
  35788. tokenType));
  35789. if (tokenEnd >= lineLength)
  35790. break;
  35791. }
  35792. lastIterator = source;
  35793. }
  35794. source = lastIterator;
  35795. }
  35796. static void replaceTabsWithSpaces (Array <SyntaxToken>& tokens, const int spacesPerTab) throw()
  35797. {
  35798. int x = 0;
  35799. for (int i = 0; i < tokens.size(); ++i)
  35800. {
  35801. SyntaxToken& t = tokens.getReference(i);
  35802. for (;;)
  35803. {
  35804. int tabPos = t.text.indexOfChar (T('\t'));
  35805. if (tabPos < 0)
  35806. break;
  35807. const int spacesNeeded = spacesPerTab - ((tabPos + x) % spacesPerTab);
  35808. t.text = t.text.replaceSection (tabPos, 1, String::repeatedString (T(" "), spacesNeeded));
  35809. }
  35810. x += t.text.length();
  35811. }
  35812. }
  35813. int indexToColumn (int index, const String& line, int spacesPerTab) const throw()
  35814. {
  35815. jassert (index <= line.length());
  35816. int col = 0;
  35817. for (int i = 0; i < index; ++i)
  35818. {
  35819. if (line[i] != T('\t'))
  35820. ++col;
  35821. else
  35822. col += spacesPerTab - (col % spacesPerTab);
  35823. }
  35824. return col;
  35825. }
  35826. };
  35827. CodeEditorComponent::CodeEditorComponent (CodeDocument& document_,
  35828. CodeTokeniser* const codeTokeniser_)
  35829. : document (document_),
  35830. firstLineOnScreen (0),
  35831. gutter (5),
  35832. spacesPerTab (4),
  35833. lineHeight (0),
  35834. linesOnScreen (0),
  35835. columnsOnScreen (0),
  35836. scrollbarThickness (16),
  35837. columnToTryToMaintain (-1),
  35838. useSpacesForTabs (false),
  35839. xOffset (0),
  35840. codeTokeniser (codeTokeniser_)
  35841. {
  35842. caretPos = CodeDocument::Position (&document_, 0, 0);
  35843. caretPos.setPositionMaintained (true);
  35844. selectionStart = CodeDocument::Position (&document_, 0, 0);
  35845. selectionStart.setPositionMaintained (true);
  35846. selectionEnd = CodeDocument::Position (&document_, 0, 0);
  35847. selectionEnd.setPositionMaintained (true);
  35848. setOpaque (true);
  35849. setMouseCursor (MouseCursor (MouseCursor::IBeamCursor));
  35850. setWantsKeyboardFocus (true);
  35851. addAndMakeVisible (verticalScrollBar = new ScrollBar (true));
  35852. verticalScrollBar->setSingleStepSize (1.0);
  35853. addAndMakeVisible (horizontalScrollBar = new ScrollBar (false));
  35854. horizontalScrollBar->setSingleStepSize (1.0);
  35855. addAndMakeVisible (caret = new CaretComponent());
  35856. Font f (12.0f);
  35857. f.setTypefaceName (Font::getDefaultMonospacedFontName());
  35858. setFont (f);
  35859. resetToDefaultColours();
  35860. verticalScrollBar->addListener (this);
  35861. horizontalScrollBar->addListener (this);
  35862. document.addListener (this);
  35863. }
  35864. CodeEditorComponent::~CodeEditorComponent()
  35865. {
  35866. document.removeListener (this);
  35867. deleteAllChildren();
  35868. }
  35869. void CodeEditorComponent::loadContent (const String& newContent)
  35870. {
  35871. clearCachedIterators (0);
  35872. document.replaceAllContent (newContent);
  35873. document.clearUndoHistory();
  35874. document.setSavePoint();
  35875. caretPos.setPosition (0);
  35876. selectionStart.setPosition (0);
  35877. selectionEnd.setPosition (0);
  35878. scrollToLine (0);
  35879. }
  35880. void CodeEditorComponent::codeDocumentChanged (const CodeDocument::Position& affectedTextStart,
  35881. const CodeDocument::Position& affectedTextEnd)
  35882. {
  35883. clearCachedIterators (affectedTextStart.getLineNumber());
  35884. triggerAsyncUpdate();
  35885. ((CaretComponent*) caret)->updatePosition (*this);
  35886. columnToTryToMaintain = -1;
  35887. if (affectedTextEnd.getPosition() >= selectionStart.getPosition()
  35888. && affectedTextStart.getPosition() <= selectionEnd.getPosition())
  35889. deselectAll();
  35890. if (caretPos.getPosition() > affectedTextEnd.getPosition()
  35891. || caretPos.getPosition() < affectedTextStart.getPosition())
  35892. moveCaretTo (affectedTextStart, false);
  35893. updateScrollBars();
  35894. }
  35895. void CodeEditorComponent::resized()
  35896. {
  35897. linesOnScreen = (getHeight() - scrollbarThickness) / lineHeight;
  35898. columnsOnScreen = (int) ((getWidth() - scrollbarThickness) / charWidth);
  35899. lines.clear();
  35900. rebuildLineTokens();
  35901. ((CaretComponent*) caret)->updatePosition (*this);
  35902. verticalScrollBar->setBounds (getWidth() - scrollbarThickness, 0, scrollbarThickness, getHeight() - scrollbarThickness);
  35903. horizontalScrollBar->setBounds (gutter, getHeight() - scrollbarThickness, getWidth() - scrollbarThickness - gutter, scrollbarThickness);
  35904. updateScrollBars();
  35905. }
  35906. void CodeEditorComponent::paint (Graphics& g)
  35907. {
  35908. handleUpdateNowIfNeeded();
  35909. g.fillAll (findColour (CodeEditorComponent::backgroundColourId));
  35910. g.reduceClipRegion (gutter, 0, verticalScrollBar->getX() - gutter, horizontalScrollBar->getY());
  35911. g.setFont (font);
  35912. const int baselineOffset = (int) font.getAscent();
  35913. const Colour defaultColour (findColour (CodeEditorComponent::defaultTextColourId));
  35914. const Colour highlightColour (findColour (CodeEditorComponent::highlightColourId));
  35915. const Rectangle<int> clip (g.getClipBounds());
  35916. const int firstLineToDraw = jmax (0, clip.getY() / lineHeight);
  35917. const int lastLineToDraw = jmin (lines.size(), clip.getBottom() / lineHeight + 1);
  35918. for (int j = firstLineToDraw; j < lastLineToDraw; ++j)
  35919. {
  35920. lines.getUnchecked(j)->draw (*this, g, font,
  35921. (float) (gutter - xOffset * charWidth),
  35922. lineHeight * j, baselineOffset, lineHeight,
  35923. highlightColour);
  35924. }
  35925. }
  35926. void CodeEditorComponent::setScrollbarThickness (const int thickness) throw()
  35927. {
  35928. if (scrollbarThickness != thickness)
  35929. {
  35930. scrollbarThickness = thickness;
  35931. resized();
  35932. }
  35933. }
  35934. void CodeEditorComponent::handleAsyncUpdate()
  35935. {
  35936. rebuildLineTokens();
  35937. }
  35938. void CodeEditorComponent::rebuildLineTokens()
  35939. {
  35940. cancelPendingUpdate();
  35941. const int numNeeded = linesOnScreen + 1;
  35942. int minLineToRepaint = numNeeded;
  35943. int maxLineToRepaint = 0;
  35944. if (numNeeded != lines.size())
  35945. {
  35946. lines.clear();
  35947. for (int i = numNeeded; --i >= 0;)
  35948. lines.add (new CodeEditorLine());
  35949. minLineToRepaint = 0;
  35950. maxLineToRepaint = numNeeded;
  35951. }
  35952. jassert (numNeeded == lines.size());
  35953. CodeDocument::Iterator source (&document);
  35954. getIteratorForPosition (CodeDocument::Position (&document, firstLineOnScreen, 0).getPosition(), source);
  35955. for (int i = 0; i < numNeeded; ++i)
  35956. {
  35957. CodeEditorLine* const line = lines.getUnchecked(i);
  35958. if (line->update (document, firstLineOnScreen + i, source, codeTokeniser, spacesPerTab,
  35959. selectionStart, selectionEnd))
  35960. {
  35961. minLineToRepaint = jmin (minLineToRepaint, i);
  35962. maxLineToRepaint = jmax (maxLineToRepaint, i);
  35963. }
  35964. }
  35965. if (minLineToRepaint <= maxLineToRepaint)
  35966. {
  35967. repaint (gutter, lineHeight * minLineToRepaint - 1,
  35968. verticalScrollBar->getX() - gutter,
  35969. lineHeight * (1 + maxLineToRepaint - minLineToRepaint) + 2);
  35970. }
  35971. }
  35972. void CodeEditorComponent::moveCaretTo (const CodeDocument::Position& newPos, const bool highlighting)
  35973. {
  35974. caretPos = newPos;
  35975. columnToTryToMaintain = -1;
  35976. if (highlighting)
  35977. {
  35978. if (dragType == notDragging)
  35979. {
  35980. if (abs (caretPos.getPosition() - selectionStart.getPosition())
  35981. < abs (caretPos.getPosition() - selectionEnd.getPosition()))
  35982. dragType = draggingSelectionStart;
  35983. else
  35984. dragType = draggingSelectionEnd;
  35985. }
  35986. if (dragType == draggingSelectionStart)
  35987. {
  35988. selectionStart = caretPos;
  35989. if (selectionEnd.getPosition() < selectionStart.getPosition())
  35990. {
  35991. const CodeDocument::Position temp (selectionStart);
  35992. selectionStart = selectionEnd;
  35993. selectionEnd = temp;
  35994. dragType = draggingSelectionEnd;
  35995. }
  35996. }
  35997. else
  35998. {
  35999. selectionEnd = caretPos;
  36000. if (selectionEnd.getPosition() < selectionStart.getPosition())
  36001. {
  36002. const CodeDocument::Position temp (selectionStart);
  36003. selectionStart = selectionEnd;
  36004. selectionEnd = temp;
  36005. dragType = draggingSelectionStart;
  36006. }
  36007. }
  36008. triggerAsyncUpdate();
  36009. }
  36010. else
  36011. {
  36012. deselectAll();
  36013. }
  36014. ((CaretComponent*) caret)->updatePosition (*this);
  36015. scrollToKeepCaretOnScreen();
  36016. updateScrollBars();
  36017. }
  36018. void CodeEditorComponent::deselectAll()
  36019. {
  36020. if (selectionStart != selectionEnd)
  36021. triggerAsyncUpdate();
  36022. selectionStart = caretPos;
  36023. selectionEnd = caretPos;
  36024. }
  36025. void CodeEditorComponent::updateScrollBars()
  36026. {
  36027. verticalScrollBar->setRangeLimits (0, jmax (document.getNumLines(), firstLineOnScreen + linesOnScreen));
  36028. verticalScrollBar->setCurrentRange (firstLineOnScreen, linesOnScreen);
  36029. horizontalScrollBar->setRangeLimits (0, jmax ((double) document.getMaximumLineLength(), xOffset + columnsOnScreen));
  36030. horizontalScrollBar->setCurrentRange (xOffset, columnsOnScreen);
  36031. }
  36032. void CodeEditorComponent::scrollToLineInternal (int newFirstLineOnScreen)
  36033. {
  36034. newFirstLineOnScreen = jlimit (0, jmax (0, document.getNumLines() - 1),
  36035. newFirstLineOnScreen);
  36036. if (newFirstLineOnScreen != firstLineOnScreen)
  36037. {
  36038. firstLineOnScreen = newFirstLineOnScreen;
  36039. ((CaretComponent*) caret)->updatePosition (*this);
  36040. updateCachedIterators (firstLineOnScreen);
  36041. triggerAsyncUpdate();
  36042. }
  36043. }
  36044. void CodeEditorComponent::scrollToColumnInternal (double column)
  36045. {
  36046. const double newOffset = jlimit (0.0, document.getMaximumLineLength() + 3.0, column);
  36047. if (xOffset != newOffset)
  36048. {
  36049. xOffset = newOffset;
  36050. ((CaretComponent*) caret)->updatePosition (*this);
  36051. repaint();
  36052. }
  36053. }
  36054. void CodeEditorComponent::scrollToLine (int newFirstLineOnScreen)
  36055. {
  36056. scrollToLineInternal (newFirstLineOnScreen);
  36057. updateScrollBars();
  36058. }
  36059. void CodeEditorComponent::scrollToColumn (int newFirstColumnOnScreen)
  36060. {
  36061. scrollToColumnInternal (newFirstColumnOnScreen);
  36062. updateScrollBars();
  36063. }
  36064. void CodeEditorComponent::scrollBy (int deltaLines)
  36065. {
  36066. scrollToLine (firstLineOnScreen + deltaLines);
  36067. }
  36068. void CodeEditorComponent::scrollToKeepCaretOnScreen()
  36069. {
  36070. if (caretPos.getLineNumber() < firstLineOnScreen)
  36071. scrollBy (caretPos.getLineNumber() - firstLineOnScreen);
  36072. else if (caretPos.getLineNumber() >= firstLineOnScreen + linesOnScreen)
  36073. scrollBy (caretPos.getLineNumber() - (firstLineOnScreen + linesOnScreen - 1));
  36074. const int column = indexToColumn (caretPos.getLineNumber(), caretPos.getIndexInLine());
  36075. if (column >= xOffset + columnsOnScreen - 1)
  36076. scrollToColumn (column + 1 - columnsOnScreen);
  36077. else if (column < xOffset)
  36078. scrollToColumn (column);
  36079. }
  36080. const Rectangle<int> CodeEditorComponent::getCharacterBounds (const CodeDocument::Position& pos) const throw()
  36081. {
  36082. return Rectangle<int> (roundToInt ((gutter - xOffset * charWidth) + indexToColumn (pos.getLineNumber(), pos.getIndexInLine()) * charWidth),
  36083. (pos.getLineNumber() - firstLineOnScreen) * lineHeight,
  36084. roundToInt (charWidth),
  36085. lineHeight);
  36086. }
  36087. const CodeDocument::Position CodeEditorComponent::getPositionAt (int x, int y)
  36088. {
  36089. const int line = y / lineHeight + firstLineOnScreen;
  36090. const int column = roundToInt ((x - (gutter - xOffset * charWidth)) / charWidth);
  36091. const int index = columnToIndex (line, column);
  36092. return CodeDocument::Position (&document, line, index);
  36093. }
  36094. void CodeEditorComponent::insertTextAtCaret (const String& newText)
  36095. {
  36096. document.deleteSection (selectionStart, selectionEnd);
  36097. if (newText.isNotEmpty())
  36098. document.insertText (caretPos, newText);
  36099. scrollToKeepCaretOnScreen();
  36100. }
  36101. void CodeEditorComponent::insertTabAtCaret()
  36102. {
  36103. if (CharacterFunctions::isWhitespace (caretPos.getCharacter())
  36104. && caretPos.getLineNumber() == caretPos.movedBy (1).getLineNumber())
  36105. {
  36106. moveCaretTo (document.findWordBreakAfter (caretPos), false);
  36107. }
  36108. if (useSpacesForTabs)
  36109. {
  36110. const int caretCol = indexToColumn (caretPos.getLineNumber(), caretPos.getIndexInLine());
  36111. const int spacesNeeded = spacesPerTab - (caretCol % spacesPerTab);
  36112. insertTextAtCaret (String::repeatedString (T(" "), spacesNeeded));
  36113. }
  36114. else
  36115. {
  36116. insertTextAtCaret (T("\t"));
  36117. }
  36118. }
  36119. void CodeEditorComponent::cut()
  36120. {
  36121. insertTextAtCaret (String::empty);
  36122. }
  36123. void CodeEditorComponent::copy()
  36124. {
  36125. newTransaction();
  36126. const String selection (document.getTextBetween (selectionStart, selectionEnd));
  36127. if (selection.isNotEmpty())
  36128. SystemClipboard::copyTextToClipboard (selection);
  36129. }
  36130. void CodeEditorComponent::copyThenCut()
  36131. {
  36132. copy();
  36133. cut();
  36134. newTransaction();
  36135. }
  36136. void CodeEditorComponent::paste()
  36137. {
  36138. newTransaction();
  36139. const String clip (SystemClipboard::getTextFromClipboard());
  36140. if (clip.isNotEmpty())
  36141. insertTextAtCaret (clip);
  36142. newTransaction();
  36143. }
  36144. void CodeEditorComponent::cursorLeft (const bool moveInWholeWordSteps, const bool selecting)
  36145. {
  36146. newTransaction();
  36147. if (moveInWholeWordSteps)
  36148. moveCaretTo (document.findWordBreakBefore (caretPos), selecting);
  36149. else
  36150. moveCaretTo (caretPos.movedBy (-1), selecting);
  36151. }
  36152. void CodeEditorComponent::cursorRight (const bool moveInWholeWordSteps, const bool selecting)
  36153. {
  36154. newTransaction();
  36155. if (moveInWholeWordSteps)
  36156. moveCaretTo (document.findWordBreakAfter (caretPos), selecting);
  36157. else
  36158. moveCaretTo (caretPos.movedBy (1), selecting);
  36159. }
  36160. void CodeEditorComponent::moveLineDelta (const int delta, const bool selecting)
  36161. {
  36162. CodeDocument::Position pos (caretPos);
  36163. const int newLineNum = pos.getLineNumber() + delta;
  36164. if (columnToTryToMaintain < 0)
  36165. columnToTryToMaintain = indexToColumn (pos.getLineNumber(), pos.getIndexInLine());
  36166. pos.setLineAndIndex (newLineNum, columnToIndex (newLineNum, columnToTryToMaintain));
  36167. const int colToMaintain = columnToTryToMaintain;
  36168. moveCaretTo (pos, selecting);
  36169. columnToTryToMaintain = colToMaintain;
  36170. }
  36171. void CodeEditorComponent::cursorDown (const bool selecting)
  36172. {
  36173. newTransaction();
  36174. if (caretPos.getLineNumber() == document.getNumLines() - 1)
  36175. moveCaretTo (CodeDocument::Position (&document, std::numeric_limits<int>::max(), std::numeric_limits<int>::max()), selecting);
  36176. else
  36177. moveLineDelta (1, selecting);
  36178. }
  36179. void CodeEditorComponent::cursorUp (const bool selecting)
  36180. {
  36181. newTransaction();
  36182. if (caretPos.getLineNumber() == 0)
  36183. moveCaretTo (CodeDocument::Position (&document, 0, 0), selecting);
  36184. else
  36185. moveLineDelta (-1, selecting);
  36186. }
  36187. void CodeEditorComponent::pageDown (const bool selecting)
  36188. {
  36189. newTransaction();
  36190. scrollBy (jlimit (0, linesOnScreen, 1 + document.getNumLines() - firstLineOnScreen - linesOnScreen));
  36191. moveLineDelta (linesOnScreen, selecting);
  36192. }
  36193. void CodeEditorComponent::pageUp (const bool selecting)
  36194. {
  36195. newTransaction();
  36196. scrollBy (-linesOnScreen);
  36197. moveLineDelta (-linesOnScreen, selecting);
  36198. }
  36199. void CodeEditorComponent::scrollUp()
  36200. {
  36201. newTransaction();
  36202. scrollBy (1);
  36203. if (caretPos.getLineNumber() < firstLineOnScreen)
  36204. moveLineDelta (1, false);
  36205. }
  36206. void CodeEditorComponent::scrollDown()
  36207. {
  36208. newTransaction();
  36209. scrollBy (-1);
  36210. if (caretPos.getLineNumber() >= firstLineOnScreen + linesOnScreen)
  36211. moveLineDelta (-1, false);
  36212. }
  36213. void CodeEditorComponent::goToStartOfDocument (const bool selecting)
  36214. {
  36215. newTransaction();
  36216. moveCaretTo (CodeDocument::Position (&document, 0, 0), selecting);
  36217. }
  36218. static int findFirstNonWhitespaceChar (const String& line) throw()
  36219. {
  36220. const int len = line.length();
  36221. for (int i = 0; i < len; ++i)
  36222. if (! CharacterFunctions::isWhitespace (line [i]))
  36223. return i;
  36224. return 0;
  36225. }
  36226. void CodeEditorComponent::goToStartOfLine (const bool selecting)
  36227. {
  36228. newTransaction();
  36229. int index = findFirstNonWhitespaceChar (caretPos.getLineText());
  36230. if (index >= caretPos.getIndexInLine() && caretPos.getIndexInLine() > 0)
  36231. index = 0;
  36232. moveCaretTo (CodeDocument::Position (&document, caretPos.getLineNumber(), index), selecting);
  36233. }
  36234. void CodeEditorComponent::goToEndOfDocument (const bool selecting)
  36235. {
  36236. newTransaction();
  36237. moveCaretTo (CodeDocument::Position (&document, std::numeric_limits<int>::max(), std::numeric_limits<int>::max()), selecting);
  36238. }
  36239. void CodeEditorComponent::goToEndOfLine (const bool selecting)
  36240. {
  36241. newTransaction();
  36242. moveCaretTo (CodeDocument::Position (&document, caretPos.getLineNumber(), std::numeric_limits<int>::max()), selecting);
  36243. }
  36244. void CodeEditorComponent::backspace (const bool moveInWholeWordSteps)
  36245. {
  36246. if (moveInWholeWordSteps)
  36247. {
  36248. cut(); // in case something is already highlighted
  36249. moveCaretTo (document.findWordBreakBefore (caretPos), true);
  36250. }
  36251. else
  36252. {
  36253. if (selectionStart == selectionEnd)
  36254. selectionStart.moveBy (-1);
  36255. }
  36256. cut();
  36257. }
  36258. void CodeEditorComponent::deleteForward (const bool moveInWholeWordSteps)
  36259. {
  36260. if (moveInWholeWordSteps)
  36261. {
  36262. cut(); // in case something is already highlighted
  36263. moveCaretTo (document.findWordBreakAfter (caretPos), true);
  36264. }
  36265. else
  36266. {
  36267. if (selectionStart == selectionEnd)
  36268. selectionEnd.moveBy (1);
  36269. else
  36270. newTransaction();
  36271. }
  36272. cut();
  36273. }
  36274. void CodeEditorComponent::selectAll()
  36275. {
  36276. newTransaction();
  36277. moveCaretTo (CodeDocument::Position (&document, std::numeric_limits<int>::max(), std::numeric_limits<int>::max()), false);
  36278. moveCaretTo (CodeDocument::Position (&document, 0, 0), true);
  36279. }
  36280. void CodeEditorComponent::undo()
  36281. {
  36282. document.undo();
  36283. scrollToKeepCaretOnScreen();
  36284. }
  36285. void CodeEditorComponent::redo()
  36286. {
  36287. document.redo();
  36288. scrollToKeepCaretOnScreen();
  36289. }
  36290. void CodeEditorComponent::newTransaction()
  36291. {
  36292. document.newTransaction();
  36293. startTimer (600);
  36294. }
  36295. void CodeEditorComponent::timerCallback()
  36296. {
  36297. newTransaction();
  36298. }
  36299. const Range<int> CodeEditorComponent::getHighlightedRegion() const
  36300. {
  36301. return Range<int> (selectionStart.getPosition(), selectionEnd.getPosition());
  36302. }
  36303. void CodeEditorComponent::setHighlightedRegion (const Range<int>& newRange)
  36304. {
  36305. moveCaretTo (CodeDocument::Position (&document, newRange.getStart()), false);
  36306. moveCaretTo (CodeDocument::Position (&document, newRange.getEnd()), true);
  36307. }
  36308. const String CodeEditorComponent::getTextInRange (const Range<int>& range) const
  36309. {
  36310. return document.getTextBetween (CodeDocument::Position (&document, range.getStart()),
  36311. CodeDocument::Position (&document, range.getEnd()));
  36312. }
  36313. bool CodeEditorComponent::keyPressed (const KeyPress& key)
  36314. {
  36315. const bool moveInWholeWordSteps = key.getModifiers().isCtrlDown() || key.getModifiers().isAltDown();
  36316. const bool shiftDown = key.getModifiers().isShiftDown();
  36317. if (key.isKeyCode (KeyPress::leftKey))
  36318. {
  36319. cursorLeft (moveInWholeWordSteps, shiftDown);
  36320. }
  36321. else if (key.isKeyCode (KeyPress::rightKey))
  36322. {
  36323. cursorRight (moveInWholeWordSteps, shiftDown);
  36324. }
  36325. else if (key.isKeyCode (KeyPress::upKey))
  36326. {
  36327. if (key.getModifiers().isCtrlDown() && ! shiftDown)
  36328. scrollDown();
  36329. #if JUCE_MAC
  36330. else if (key.getModifiers().isCommandDown())
  36331. goToStartOfDocument (shiftDown);
  36332. #endif
  36333. else
  36334. cursorUp (shiftDown);
  36335. }
  36336. else if (key.isKeyCode (KeyPress::downKey))
  36337. {
  36338. if (key.getModifiers().isCtrlDown() && ! shiftDown)
  36339. scrollUp();
  36340. #if JUCE_MAC
  36341. else if (key.getModifiers().isCommandDown())
  36342. goToEndOfDocument (shiftDown);
  36343. #endif
  36344. else
  36345. cursorDown (shiftDown);
  36346. }
  36347. else if (key.isKeyCode (KeyPress::pageDownKey))
  36348. {
  36349. pageDown (shiftDown);
  36350. }
  36351. else if (key.isKeyCode (KeyPress::pageUpKey))
  36352. {
  36353. pageUp (shiftDown);
  36354. }
  36355. else if (key.isKeyCode (KeyPress::homeKey))
  36356. {
  36357. if (moveInWholeWordSteps)
  36358. goToStartOfDocument (shiftDown);
  36359. else
  36360. goToStartOfLine (shiftDown);
  36361. }
  36362. else if (key.isKeyCode (KeyPress::endKey))
  36363. {
  36364. if (moveInWholeWordSteps)
  36365. goToEndOfDocument (shiftDown);
  36366. else
  36367. goToEndOfLine (shiftDown);
  36368. }
  36369. else if (key.isKeyCode (KeyPress::backspaceKey))
  36370. {
  36371. backspace (moveInWholeWordSteps);
  36372. }
  36373. else if (key.isKeyCode (KeyPress::deleteKey))
  36374. {
  36375. deleteForward (moveInWholeWordSteps);
  36376. }
  36377. else if (key == KeyPress (T('c'), ModifierKeys::commandModifier, 0))
  36378. {
  36379. copy();
  36380. }
  36381. else if (key == KeyPress (T('x'), ModifierKeys::commandModifier, 0))
  36382. {
  36383. copyThenCut();
  36384. }
  36385. else if (key == KeyPress (T('v'), ModifierKeys::commandModifier, 0))
  36386. {
  36387. paste();
  36388. }
  36389. else if (key == KeyPress (T('z'), ModifierKeys::commandModifier, 0))
  36390. {
  36391. undo();
  36392. }
  36393. else if (key == KeyPress (T('y'), ModifierKeys::commandModifier, 0)
  36394. || key == KeyPress (T('z'), ModifierKeys::commandModifier | ModifierKeys::shiftModifier, 0))
  36395. {
  36396. redo();
  36397. }
  36398. else if (key == KeyPress (T('a'), ModifierKeys::commandModifier, 0))
  36399. {
  36400. selectAll();
  36401. }
  36402. else if (key == KeyPress::tabKey || key.getTextCharacter() == '\t')
  36403. {
  36404. insertTabAtCaret();
  36405. }
  36406. else if (key == KeyPress::returnKey)
  36407. {
  36408. newTransaction();
  36409. insertTextAtCaret (document.getNewLineCharacters());
  36410. }
  36411. else if (key.isKeyCode (KeyPress::escapeKey))
  36412. {
  36413. newTransaction();
  36414. }
  36415. else if (key.getTextCharacter() >= ' ')
  36416. {
  36417. insertTextAtCaret (String::charToString (key.getTextCharacter()));
  36418. }
  36419. else
  36420. {
  36421. return false;
  36422. }
  36423. return true;
  36424. }
  36425. void CodeEditorComponent::mouseDown (const MouseEvent& e)
  36426. {
  36427. newTransaction();
  36428. dragType = notDragging;
  36429. if (! e.mods.isPopupMenu())
  36430. {
  36431. beginDragAutoRepeat (100);
  36432. moveCaretTo (getPositionAt (e.x, e.y), e.mods.isShiftDown());
  36433. }
  36434. else
  36435. {
  36436. }
  36437. }
  36438. void CodeEditorComponent::mouseDrag (const MouseEvent& e)
  36439. {
  36440. if (! e.mods.isPopupMenu())
  36441. moveCaretTo (getPositionAt (e.x, e.y), true);
  36442. }
  36443. void CodeEditorComponent::mouseUp (const MouseEvent&)
  36444. {
  36445. newTransaction();
  36446. beginDragAutoRepeat (0);
  36447. dragType = notDragging;
  36448. }
  36449. void CodeEditorComponent::mouseDoubleClick (const MouseEvent& e)
  36450. {
  36451. CodeDocument::Position tokenStart (getPositionAt (e.x, e.y));
  36452. CodeDocument::Position tokenEnd (tokenStart);
  36453. if (e.getNumberOfClicks() > 2)
  36454. {
  36455. tokenStart.setLineAndIndex (tokenStart.getLineNumber(), 0);
  36456. tokenEnd.setLineAndIndex (tokenStart.getLineNumber() + 1, 0);
  36457. }
  36458. else
  36459. {
  36460. while (CharacterFunctions::isLetterOrDigit (tokenEnd.getCharacter()))
  36461. tokenEnd.moveBy (1);
  36462. tokenStart = tokenEnd;
  36463. while (tokenStart.getIndexInLine() > 0
  36464. && CharacterFunctions::isLetterOrDigit (tokenStart.movedBy (-1).getCharacter()))
  36465. tokenStart.moveBy (-1);
  36466. }
  36467. moveCaretTo (tokenEnd, false);
  36468. moveCaretTo (tokenStart, true);
  36469. }
  36470. void CodeEditorComponent::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  36471. {
  36472. verticalScrollBar->mouseWheelMove (e, 0, wheelIncrementY);
  36473. horizontalScrollBar->mouseWheelMove (e, wheelIncrementX, 0);
  36474. }
  36475. void CodeEditorComponent::scrollBarMoved (ScrollBar* scrollBarThatHasMoved, double newRangeStart)
  36476. {
  36477. if (scrollBarThatHasMoved == verticalScrollBar)
  36478. scrollToLineInternal ((int) newRangeStart);
  36479. else
  36480. scrollToColumnInternal (newRangeStart);
  36481. }
  36482. void CodeEditorComponent::setTabSize (const int numSpaces, const bool insertSpaces) throw()
  36483. {
  36484. useSpacesForTabs = insertSpaces;
  36485. if (spacesPerTab != numSpaces)
  36486. {
  36487. spacesPerTab = numSpaces;
  36488. triggerAsyncUpdate();
  36489. }
  36490. }
  36491. int CodeEditorComponent::indexToColumn (int lineNum, int index) const throw()
  36492. {
  36493. const String line (document.getLine (lineNum));
  36494. jassert (index <= line.length());
  36495. int col = 0;
  36496. for (int i = 0; i < index; ++i)
  36497. {
  36498. if (line[i] != T('\t'))
  36499. ++col;
  36500. else
  36501. col += getTabSize() - (col % getTabSize());
  36502. }
  36503. return col;
  36504. }
  36505. int CodeEditorComponent::columnToIndex (int lineNum, int column) const throw()
  36506. {
  36507. const String line (document.getLine (lineNum));
  36508. const int lineLength = line.length();
  36509. int i, col = 0;
  36510. for (i = 0; i < lineLength; ++i)
  36511. {
  36512. if (line[i] != T('\t'))
  36513. ++col;
  36514. else
  36515. col += getTabSize() - (col % getTabSize());
  36516. if (col > column)
  36517. break;
  36518. }
  36519. return i;
  36520. }
  36521. void CodeEditorComponent::setFont (const Font& newFont)
  36522. {
  36523. font = newFont;
  36524. charWidth = font.getStringWidthFloat (T("0"));
  36525. lineHeight = roundToInt (font.getHeight());
  36526. resized();
  36527. }
  36528. void CodeEditorComponent::resetToDefaultColours()
  36529. {
  36530. coloursForTokenCategories.clear();
  36531. if (codeTokeniser != 0)
  36532. {
  36533. for (int i = codeTokeniser->getTokenTypes().size(); --i >= 0;)
  36534. setColourForTokenType (i, codeTokeniser->getDefaultColour (i));
  36535. }
  36536. }
  36537. void CodeEditorComponent::setColourForTokenType (const int tokenType, const Colour& colour)
  36538. {
  36539. jassert (tokenType < 256);
  36540. while (coloursForTokenCategories.size() < tokenType)
  36541. coloursForTokenCategories.add (Colours::black);
  36542. coloursForTokenCategories.set (tokenType, colour);
  36543. repaint();
  36544. }
  36545. const Colour CodeEditorComponent::getColourForTokenType (const int tokenType) const throw()
  36546. {
  36547. if (((unsigned int) tokenType) >= (unsigned int) coloursForTokenCategories.size())
  36548. return findColour (CodeEditorComponent::defaultTextColourId);
  36549. return coloursForTokenCategories.getReference (tokenType);
  36550. }
  36551. void CodeEditorComponent::clearCachedIterators (const int firstLineToBeInvalid) throw()
  36552. {
  36553. int i;
  36554. for (i = cachedIterators.size(); --i >= 0;)
  36555. if (cachedIterators.getUnchecked (i)->getLine() < firstLineToBeInvalid)
  36556. break;
  36557. cachedIterators.removeRange (jmax (0, i - 1), cachedIterators.size());
  36558. }
  36559. void CodeEditorComponent::updateCachedIterators (int maxLineNum)
  36560. {
  36561. const int maxNumCachedPositions = 5000;
  36562. const int linesBetweenCachedSources = jmax (10, document.getNumLines() / maxNumCachedPositions);
  36563. if (cachedIterators.size() == 0)
  36564. cachedIterators.add (new CodeDocument::Iterator (&document));
  36565. if (codeTokeniser == 0)
  36566. return;
  36567. for (;;)
  36568. {
  36569. CodeDocument::Iterator* last = cachedIterators.getLast();
  36570. if (last->getLine() >= maxLineNum)
  36571. break;
  36572. CodeDocument::Iterator* t = new CodeDocument::Iterator (*last);
  36573. cachedIterators.add (t);
  36574. const int targetLine = last->getLine() + linesBetweenCachedSources;
  36575. for (;;)
  36576. {
  36577. codeTokeniser->readNextToken (*t);
  36578. if (t->getLine() >= targetLine)
  36579. break;
  36580. if (t->isEOF())
  36581. return;
  36582. }
  36583. }
  36584. }
  36585. void CodeEditorComponent::getIteratorForPosition (int position, CodeDocument::Iterator& source)
  36586. {
  36587. if (codeTokeniser == 0)
  36588. return;
  36589. for (int i = cachedIterators.size(); --i >= 0;)
  36590. {
  36591. CodeDocument::Iterator* t = cachedIterators.getUnchecked (i);
  36592. if (t->getPosition() <= position)
  36593. {
  36594. source = *t;
  36595. break;
  36596. }
  36597. }
  36598. while (source.getPosition() < position)
  36599. {
  36600. const CodeDocument::Iterator original (source);
  36601. codeTokeniser->readNextToken (source);
  36602. if (source.getPosition() > position || source.isEOF())
  36603. {
  36604. source = original;
  36605. break;
  36606. }
  36607. }
  36608. }
  36609. END_JUCE_NAMESPACE
  36610. /*** End of inlined file: juce_CodeEditorComponent.cpp ***/
  36611. /*** Start of inlined file: juce_CPlusPlusCodeTokeniser.cpp ***/
  36612. BEGIN_JUCE_NAMESPACE
  36613. CPlusPlusCodeTokeniser::CPlusPlusCodeTokeniser()
  36614. {
  36615. }
  36616. CPlusPlusCodeTokeniser::~CPlusPlusCodeTokeniser()
  36617. {
  36618. }
  36619. namespace CppTokeniser
  36620. {
  36621. static bool isIdentifierStart (const tchar c) throw()
  36622. {
  36623. return CharacterFunctions::isLetter (c)
  36624. || c == T('_') || c == T('@');
  36625. }
  36626. static bool isIdentifierBody (const tchar c) throw()
  36627. {
  36628. return CharacterFunctions::isLetter (c)
  36629. || CharacterFunctions::isDigit (c)
  36630. || c == T('_') || c == T('@');
  36631. }
  36632. static int parseIdentifier (CodeDocument::Iterator& source) throw()
  36633. {
  36634. static const tchar* keywords2Char[] =
  36635. { T("if"), T("do"), T("or"), 0 };
  36636. static const tchar* keywords3Char[] =
  36637. { T("for"), T("int"), T("new"), T("try"), T("xor"), T("and"), T("asm"), T("not"), 0 };
  36638. static const tchar* keywords4Char[] =
  36639. { T("bool"), T("void"), T("this"), T("true"), T("long"), T("else"), T("char"),
  36640. T("enum"), T("case"), T("goto"), T("auto"), 0 };
  36641. static const tchar* keywords5Char[] =
  36642. { T("while"), T("bitor"), T("break"), T("catch"), T("class"), T("compl"), T("const"), T("false"),
  36643. T("float"), T("short"), T("throw"), T("union"), T("using"), T("or_eq"), 0 };
  36644. static const tchar* keywords6Char[] =
  36645. { T("return"), T("struct"), T("and_eq"), T("bitand"), T("delete"), T("double"), T("extern"),
  36646. T("friend"), T("inline"), T("not_eq"), T("public"), T("sizeof"), T("static"), T("signed"),
  36647. T("switch"), T("typeid"), T("wchar_t"), T("xor_eq"), 0};
  36648. static const tchar* keywordsOther[] =
  36649. { T("const_cast"), T("continue"), T("default"), T("explicit"), T("mutable"), T("namespace"),
  36650. T("operator"), T("private"), T("protected"), T("register"), T("reinterpret_cast"), T("static_cast"),
  36651. T("template"), T("typedef"), T("typename"), T("unsigned"), T("virtual"), T("volatile"),
  36652. T("@implementation"), T("@interface"), T("@end"), T("@synthesize"), T("@dynamic"), T("@public"),
  36653. T("@private"), T("@property"), T("@protected"), T("@class"), 0 };
  36654. int tokenLength = 0;
  36655. tchar possibleIdentifier [19];
  36656. while (isIdentifierBody (source.peekNextChar()))
  36657. {
  36658. const tchar c = source.nextChar();
  36659. if (tokenLength < numElementsInArray (possibleIdentifier) - 1)
  36660. possibleIdentifier [tokenLength] = c;
  36661. ++tokenLength;
  36662. }
  36663. if (tokenLength > 1 && tokenLength <= 16)
  36664. {
  36665. possibleIdentifier [tokenLength] = 0;
  36666. const tchar** k;
  36667. switch (tokenLength)
  36668. {
  36669. case 2: k = keywords2Char; break;
  36670. case 3: k = keywords3Char; break;
  36671. case 4: k = keywords4Char; break;
  36672. case 5: k = keywords5Char; break;
  36673. case 6: k = keywords6Char; break;
  36674. default: k = keywordsOther; break;
  36675. }
  36676. int i = 0;
  36677. while (k[i] != 0)
  36678. {
  36679. if (k[i][0] == possibleIdentifier[0] && CharacterFunctions::compare (k[i], possibleIdentifier) == 0)
  36680. return CPlusPlusCodeTokeniser::tokenType_builtInKeyword;
  36681. ++i;
  36682. }
  36683. }
  36684. return CPlusPlusCodeTokeniser::tokenType_identifier;
  36685. }
  36686. static bool skipNumberSuffix (CodeDocument::Iterator& source)
  36687. {
  36688. const juce_wchar c = source.peekNextChar();
  36689. if (c == 'l' || c == 'L' || c == 'u' || c == 'U')
  36690. source.skip();
  36691. if (CharacterFunctions::isLetterOrDigit (source.peekNextChar()))
  36692. return false;
  36693. return true;
  36694. }
  36695. static bool isHexDigit (const juce_wchar c) throw()
  36696. {
  36697. return (c >= '0' && c <= '9')
  36698. || (c >= 'a' && c <= 'f')
  36699. || (c >= 'A' && c <= 'F');
  36700. }
  36701. static bool parseHexLiteral (CodeDocument::Iterator& source) throw()
  36702. {
  36703. if (source.nextChar() != '0')
  36704. return false;
  36705. juce_wchar c = source.nextChar();
  36706. if (c != 'x' && c != 'X')
  36707. return false;
  36708. int numDigits = 0;
  36709. while (isHexDigit (source.peekNextChar()))
  36710. {
  36711. ++numDigits;
  36712. source.skip();
  36713. }
  36714. if (numDigits == 0)
  36715. return false;
  36716. return skipNumberSuffix (source);
  36717. }
  36718. static bool isOctalDigit (const juce_wchar c) throw()
  36719. {
  36720. return c >= '0' && c <= '7';
  36721. }
  36722. static bool parseOctalLiteral (CodeDocument::Iterator& source) throw()
  36723. {
  36724. if (source.nextChar() != '0')
  36725. return false;
  36726. if (! isOctalDigit (source.nextChar()))
  36727. return false;
  36728. while (isOctalDigit (source.peekNextChar()))
  36729. source.skip();
  36730. return skipNumberSuffix (source);
  36731. }
  36732. static bool isDecimalDigit (const juce_wchar c) throw()
  36733. {
  36734. return c >= '0' && c <= '9';
  36735. }
  36736. static bool parseDecimalLiteral (CodeDocument::Iterator& source) throw()
  36737. {
  36738. int numChars = 0;
  36739. while (isDecimalDigit (source.peekNextChar()))
  36740. {
  36741. ++numChars;
  36742. source.skip();
  36743. }
  36744. if (numChars == 0)
  36745. return false;
  36746. return skipNumberSuffix (source);
  36747. }
  36748. static bool parseFloatLiteral (CodeDocument::Iterator& source) throw()
  36749. {
  36750. int numDigits = 0;
  36751. while (isDecimalDigit (source.peekNextChar()))
  36752. {
  36753. source.skip();
  36754. ++numDigits;
  36755. }
  36756. const bool hasPoint = (source.peekNextChar() == '.');
  36757. if (hasPoint)
  36758. {
  36759. source.skip();
  36760. while (isDecimalDigit (source.peekNextChar()))
  36761. {
  36762. source.skip();
  36763. ++numDigits;
  36764. }
  36765. }
  36766. if (numDigits == 0)
  36767. return false;
  36768. juce_wchar c = source.peekNextChar();
  36769. const bool hasExponent = (c == 'e' || c == 'E');
  36770. if (hasExponent)
  36771. {
  36772. source.skip();
  36773. c = source.peekNextChar();
  36774. if (c == '+' || c == '-')
  36775. source.skip();
  36776. int numExpDigits = 0;
  36777. while (isDecimalDigit (source.peekNextChar()))
  36778. {
  36779. source.skip();
  36780. ++numExpDigits;
  36781. }
  36782. if (numExpDigits == 0)
  36783. return false;
  36784. }
  36785. c = source.peekNextChar();
  36786. if (c == 'f' || c == 'F')
  36787. source.skip();
  36788. else if (! (hasExponent || hasPoint))
  36789. return false;
  36790. return true;
  36791. }
  36792. static int parseNumber (CodeDocument::Iterator& source)
  36793. {
  36794. const CodeDocument::Iterator original (source);
  36795. if (parseFloatLiteral (source))
  36796. return CPlusPlusCodeTokeniser::tokenType_floatLiteral;
  36797. source = original;
  36798. if (parseHexLiteral (source))
  36799. return CPlusPlusCodeTokeniser::tokenType_integerLiteral;
  36800. source = original;
  36801. if (parseOctalLiteral (source))
  36802. return CPlusPlusCodeTokeniser::tokenType_integerLiteral;
  36803. source = original;
  36804. if (parseDecimalLiteral (source))
  36805. return CPlusPlusCodeTokeniser::tokenType_integerLiteral;
  36806. source = original;
  36807. source.skip();
  36808. return CPlusPlusCodeTokeniser::tokenType_error;
  36809. }
  36810. static void skipQuotedString (CodeDocument::Iterator& source) throw()
  36811. {
  36812. const juce_wchar quote = source.nextChar();
  36813. for (;;)
  36814. {
  36815. const juce_wchar c = source.nextChar();
  36816. if (c == quote || c == 0)
  36817. break;
  36818. if (c == '\\')
  36819. source.skip();
  36820. }
  36821. }
  36822. static void skipComment (CodeDocument::Iterator& source) throw()
  36823. {
  36824. bool lastWasStar = false;
  36825. for (;;)
  36826. {
  36827. const juce_wchar c = source.nextChar();
  36828. if (c == 0 || (c == T('/') && lastWasStar))
  36829. break;
  36830. lastWasStar = (c == '*');
  36831. }
  36832. }
  36833. }
  36834. int CPlusPlusCodeTokeniser::readNextToken (CodeDocument::Iterator& source)
  36835. {
  36836. int result = tokenType_error;
  36837. source.skipWhitespace();
  36838. tchar firstChar = source.peekNextChar();
  36839. switch (firstChar)
  36840. {
  36841. case 0:
  36842. source.skip();
  36843. break;
  36844. case T('0'):
  36845. case T('1'):
  36846. case T('2'):
  36847. case T('3'):
  36848. case T('4'):
  36849. case T('5'):
  36850. case T('6'):
  36851. case T('7'):
  36852. case T('8'):
  36853. case T('9'):
  36854. result = CppTokeniser::parseNumber (source);
  36855. break;
  36856. case T('.'):
  36857. result = CppTokeniser::parseNumber (source);
  36858. if (result == tokenType_error)
  36859. result = tokenType_punctuation;
  36860. break;
  36861. case T(','):
  36862. case T(';'):
  36863. case T(':'):
  36864. source.skip();
  36865. result = tokenType_punctuation;
  36866. break;
  36867. case T('('):
  36868. case T(')'):
  36869. case T('{'):
  36870. case T('}'):
  36871. case T('['):
  36872. case T(']'):
  36873. source.skip();
  36874. result = tokenType_bracket;
  36875. break;
  36876. case T('"'):
  36877. case T('\''):
  36878. CppTokeniser::skipQuotedString (source);
  36879. result = tokenType_stringLiteral;
  36880. break;
  36881. case T('+'):
  36882. result = tokenType_operator;
  36883. source.skip();
  36884. if (source.peekNextChar() == T('+'))
  36885. source.skip();
  36886. else if (source.peekNextChar() == T('='))
  36887. source.skip();
  36888. break;
  36889. case T('-'):
  36890. source.skip();
  36891. result = CppTokeniser::parseNumber (source);
  36892. if (result == tokenType_error)
  36893. {
  36894. result = tokenType_operator;
  36895. if (source.peekNextChar() == T('-'))
  36896. source.skip();
  36897. else if (source.peekNextChar() == T('='))
  36898. source.skip();
  36899. }
  36900. break;
  36901. case T('*'):
  36902. case T('%'):
  36903. case T('='):
  36904. case T('!'):
  36905. result = tokenType_operator;
  36906. source.skip();
  36907. if (source.peekNextChar() == T('='))
  36908. source.skip();
  36909. break;
  36910. case T('/'):
  36911. result = tokenType_operator;
  36912. source.skip();
  36913. if (source.peekNextChar() == T('='))
  36914. {
  36915. source.skip();
  36916. }
  36917. else if (source.peekNextChar() == T('/'))
  36918. {
  36919. result = tokenType_comment;
  36920. source.skipToEndOfLine();
  36921. }
  36922. else if (source.peekNextChar() == T('*'))
  36923. {
  36924. source.skip();
  36925. result = tokenType_comment;
  36926. CppTokeniser::skipComment (source);
  36927. }
  36928. break;
  36929. case T('?'):
  36930. case T('~'):
  36931. source.skip();
  36932. result = tokenType_operator;
  36933. break;
  36934. case T('<'):
  36935. source.skip();
  36936. result = tokenType_operator;
  36937. if (source.peekNextChar() == T('='))
  36938. {
  36939. source.skip();
  36940. }
  36941. else if (source.peekNextChar() == T('<'))
  36942. {
  36943. source.skip();
  36944. if (source.peekNextChar() == T('='))
  36945. source.skip();
  36946. }
  36947. break;
  36948. case T('>'):
  36949. source.skip();
  36950. result = tokenType_operator;
  36951. if (source.peekNextChar() == T('='))
  36952. {
  36953. source.skip();
  36954. }
  36955. else if (source.peekNextChar() == T('<'))
  36956. {
  36957. source.skip();
  36958. if (source.peekNextChar() == T('='))
  36959. source.skip();
  36960. }
  36961. break;
  36962. case T('|'):
  36963. source.skip();
  36964. result = tokenType_operator;
  36965. if (source.peekNextChar() == T('='))
  36966. {
  36967. source.skip();
  36968. }
  36969. else if (source.peekNextChar() == T('|'))
  36970. {
  36971. source.skip();
  36972. if (source.peekNextChar() == T('='))
  36973. source.skip();
  36974. }
  36975. break;
  36976. case T('&'):
  36977. source.skip();
  36978. result = tokenType_operator;
  36979. if (source.peekNextChar() == T('='))
  36980. {
  36981. source.skip();
  36982. }
  36983. else if (source.peekNextChar() == T('&'))
  36984. {
  36985. source.skip();
  36986. if (source.peekNextChar() == T('='))
  36987. source.skip();
  36988. }
  36989. break;
  36990. case T('^'):
  36991. source.skip();
  36992. result = tokenType_operator;
  36993. if (source.peekNextChar() == T('='))
  36994. {
  36995. source.skip();
  36996. }
  36997. else if (source.peekNextChar() == T('^'))
  36998. {
  36999. source.skip();
  37000. if (source.peekNextChar() == T('='))
  37001. source.skip();
  37002. }
  37003. break;
  37004. case T('#'):
  37005. result = tokenType_preprocessor;
  37006. source.skipToEndOfLine();
  37007. break;
  37008. default:
  37009. if (CppTokeniser::isIdentifierStart (firstChar))
  37010. result = CppTokeniser::parseIdentifier (source);
  37011. else
  37012. source.skip();
  37013. break;
  37014. }
  37015. //jassert (result != tokenType_unknown);
  37016. return result;
  37017. }
  37018. const StringArray CPlusPlusCodeTokeniser::getTokenTypes()
  37019. {
  37020. StringArray s;
  37021. s.add ("Error");
  37022. s.add ("Comment");
  37023. s.add ("C++ keyword");
  37024. s.add ("Identifier");
  37025. s.add ("Integer literal");
  37026. s.add ("Float literal");
  37027. s.add ("String literal");
  37028. s.add ("Operator");
  37029. s.add ("Bracket");
  37030. s.add ("Punctuation");
  37031. s.add ("Preprocessor line");
  37032. return s;
  37033. }
  37034. const Colour CPlusPlusCodeTokeniser::getDefaultColour (const int tokenType)
  37035. {
  37036. const uint32 colours[] =
  37037. {
  37038. 0xffcc0000, // error
  37039. 0xff00aa00, // comment
  37040. 0xff0000cc, // keyword
  37041. 0xff000000, // identifier
  37042. 0xff880000, // int literal
  37043. 0xff885500, // float literal
  37044. 0xff990099, // string literal
  37045. 0xff225500, // operator
  37046. 0xff000055, // bracket
  37047. 0xff004400, // punctuation
  37048. 0xff660000 // preprocessor
  37049. };
  37050. if (tokenType >= 0 && tokenType < numElementsInArray (colours))
  37051. return Colour (colours [tokenType]);
  37052. return Colours::black;
  37053. }
  37054. END_JUCE_NAMESPACE
  37055. /*** End of inlined file: juce_CPlusPlusCodeTokeniser.cpp ***/
  37056. /*** Start of inlined file: juce_ComboBox.cpp ***/
  37057. BEGIN_JUCE_NAMESPACE
  37058. ComboBox::ComboBox (const String& name)
  37059. : Component (name),
  37060. lastCurrentId (0),
  37061. isButtonDown (false),
  37062. separatorPending (false),
  37063. menuActive (false),
  37064. label (0)
  37065. {
  37066. noChoicesMessage = TRANS("(no choices)");
  37067. setRepaintsOnMouseActivity (true);
  37068. lookAndFeelChanged();
  37069. currentId.addListener (this);
  37070. }
  37071. ComboBox::~ComboBox()
  37072. {
  37073. currentId.removeListener (this);
  37074. if (menuActive)
  37075. PopupMenu::dismissAllActiveMenus();
  37076. label = 0;
  37077. deleteAllChildren();
  37078. }
  37079. void ComboBox::setEditableText (const bool isEditable)
  37080. {
  37081. label->setEditable (isEditable, isEditable, false);
  37082. setWantsKeyboardFocus (! isEditable);
  37083. resized();
  37084. }
  37085. bool ComboBox::isTextEditable() const throw()
  37086. {
  37087. return label->isEditable();
  37088. }
  37089. void ComboBox::setJustificationType (const Justification& justification) throw()
  37090. {
  37091. label->setJustificationType (justification);
  37092. }
  37093. const Justification ComboBox::getJustificationType() const throw()
  37094. {
  37095. return label->getJustificationType();
  37096. }
  37097. void ComboBox::setTooltip (const String& newTooltip)
  37098. {
  37099. SettableTooltipClient::setTooltip (newTooltip);
  37100. label->setTooltip (newTooltip);
  37101. }
  37102. void ComboBox::addItem (const String& newItemText,
  37103. const int newItemId) throw()
  37104. {
  37105. // you can't add empty strings to the list..
  37106. jassert (newItemText.isNotEmpty());
  37107. // IDs must be non-zero, as zero is used to indicate a lack of selecion.
  37108. jassert (newItemId != 0);
  37109. // you shouldn't use duplicate item IDs!
  37110. jassert (getItemForId (newItemId) == 0);
  37111. if (newItemText.isNotEmpty() && newItemId != 0)
  37112. {
  37113. if (separatorPending)
  37114. {
  37115. separatorPending = false;
  37116. ItemInfo* const item = new ItemInfo();
  37117. item->itemId = 0;
  37118. item->isEnabled = false;
  37119. item->isHeading = false;
  37120. items.add (item);
  37121. }
  37122. ItemInfo* const item = new ItemInfo();
  37123. item->name = newItemText;
  37124. item->itemId = newItemId;
  37125. item->isEnabled = true;
  37126. item->isHeading = false;
  37127. items.add (item);
  37128. }
  37129. }
  37130. void ComboBox::addSeparator() throw()
  37131. {
  37132. separatorPending = (items.size() > 0);
  37133. }
  37134. void ComboBox::addSectionHeading (const String& headingName) throw()
  37135. {
  37136. // you can't add empty strings to the list..
  37137. jassert (headingName.isNotEmpty());
  37138. if (headingName.isNotEmpty())
  37139. {
  37140. if (separatorPending)
  37141. {
  37142. separatorPending = false;
  37143. ItemInfo* const item = new ItemInfo();
  37144. item->itemId = 0;
  37145. item->isEnabled = false;
  37146. item->isHeading = false;
  37147. items.add (item);
  37148. }
  37149. ItemInfo* const item = new ItemInfo();
  37150. item->name = headingName;
  37151. item->itemId = 0;
  37152. item->isEnabled = true;
  37153. item->isHeading = true;
  37154. items.add (item);
  37155. }
  37156. }
  37157. void ComboBox::setItemEnabled (const int itemId,
  37158. const bool shouldBeEnabled) throw()
  37159. {
  37160. ItemInfo* const item = getItemForId (itemId);
  37161. if (item != 0)
  37162. item->isEnabled = shouldBeEnabled;
  37163. }
  37164. void ComboBox::changeItemText (const int itemId,
  37165. const String& newText) throw()
  37166. {
  37167. ItemInfo* const item = getItemForId (itemId);
  37168. jassert (item != 0);
  37169. if (item != 0)
  37170. item->name = newText;
  37171. }
  37172. void ComboBox::clear (const bool dontSendChangeMessage)
  37173. {
  37174. items.clear();
  37175. separatorPending = false;
  37176. if (! label->isEditable())
  37177. setSelectedItemIndex (-1, dontSendChangeMessage);
  37178. }
  37179. bool ComboBox::ItemInfo::isSeparator() const throw()
  37180. {
  37181. return name.isEmpty();
  37182. }
  37183. bool ComboBox::ItemInfo::isRealItem() const throw()
  37184. {
  37185. return ! (isHeading || name.isEmpty());
  37186. }
  37187. ComboBox::ItemInfo* ComboBox::getItemForId (const int itemId) const throw()
  37188. {
  37189. if (itemId != 0)
  37190. {
  37191. for (int i = items.size(); --i >= 0;)
  37192. if (items.getUnchecked(i)->itemId == itemId)
  37193. return items.getUnchecked(i);
  37194. }
  37195. return 0;
  37196. }
  37197. ComboBox::ItemInfo* ComboBox::getItemForIndex (const int index) const throw()
  37198. {
  37199. int n = 0;
  37200. for (int i = 0; i < items.size(); ++i)
  37201. {
  37202. ItemInfo* const item = items.getUnchecked(i);
  37203. if (item->isRealItem())
  37204. if (n++ == index)
  37205. return item;
  37206. }
  37207. return 0;
  37208. }
  37209. int ComboBox::getNumItems() const throw()
  37210. {
  37211. int n = 0;
  37212. for (int i = items.size(); --i >= 0;)
  37213. if (items.getUnchecked(i)->isRealItem())
  37214. ++n;
  37215. return n;
  37216. }
  37217. const String ComboBox::getItemText (const int index) const throw()
  37218. {
  37219. const ItemInfo* const item = getItemForIndex (index);
  37220. if (item != 0)
  37221. return item->name;
  37222. return String::empty;
  37223. }
  37224. int ComboBox::getItemId (const int index) const throw()
  37225. {
  37226. const ItemInfo* const item = getItemForIndex (index);
  37227. return (item != 0) ? item->itemId : 0;
  37228. }
  37229. int ComboBox::indexOfItemId (const int itemId) const throw()
  37230. {
  37231. int n = 0;
  37232. for (int i = 0; i < items.size(); ++i)
  37233. {
  37234. const ItemInfo* const item = items.getUnchecked(i);
  37235. if (item->isRealItem())
  37236. {
  37237. if (item->itemId == itemId)
  37238. return n;
  37239. ++n;
  37240. }
  37241. }
  37242. return -1;
  37243. }
  37244. int ComboBox::getSelectedItemIndex() const throw()
  37245. {
  37246. int index = indexOfItemId (currentId.getValue());
  37247. if (getText() != getItemText (index))
  37248. index = -1;
  37249. return index;
  37250. }
  37251. void ComboBox::setSelectedItemIndex (const int index,
  37252. const bool dontSendChangeMessage) throw()
  37253. {
  37254. setSelectedId (getItemId (index), dontSendChangeMessage);
  37255. }
  37256. int ComboBox::getSelectedId() const throw()
  37257. {
  37258. const ItemInfo* const item = getItemForId (currentId.getValue());
  37259. return (item != 0 && getText() == item->name)
  37260. ? item->itemId
  37261. : 0;
  37262. }
  37263. void ComboBox::setSelectedId (const int newItemId,
  37264. const bool dontSendChangeMessage) throw()
  37265. {
  37266. const ItemInfo* const item = getItemForId (newItemId);
  37267. const String newItemText (item != 0 ? item->name : String::empty);
  37268. if (lastCurrentId != newItemId || label->getText() != newItemText)
  37269. {
  37270. if (! dontSendChangeMessage)
  37271. triggerAsyncUpdate();
  37272. label->setText (newItemText, false);
  37273. lastCurrentId = newItemId;
  37274. currentId = newItemId;
  37275. repaint(); // for the benefit of the 'none selected' text
  37276. }
  37277. }
  37278. void ComboBox::valueChanged (Value&)
  37279. {
  37280. if (lastCurrentId != (int) currentId.getValue())
  37281. setSelectedId (currentId.getValue(), false);
  37282. }
  37283. const String ComboBox::getText() const throw()
  37284. {
  37285. return label->getText();
  37286. }
  37287. void ComboBox::setText (const String& newText,
  37288. const bool dontSendChangeMessage) throw()
  37289. {
  37290. for (int i = items.size(); --i >= 0;)
  37291. {
  37292. const ItemInfo* const item = items.getUnchecked(i);
  37293. if (item->isRealItem()
  37294. && item->name == newText)
  37295. {
  37296. setSelectedId (item->itemId, dontSendChangeMessage);
  37297. return;
  37298. }
  37299. }
  37300. lastCurrentId = 0;
  37301. currentId = 0;
  37302. if (label->getText() != newText)
  37303. {
  37304. label->setText (newText, false);
  37305. if (! dontSendChangeMessage)
  37306. triggerAsyncUpdate();
  37307. }
  37308. repaint();
  37309. }
  37310. void ComboBox::showEditor()
  37311. {
  37312. jassert (isTextEditable()); // you probably shouldn't do this to a non-editable combo box?
  37313. label->showEditor();
  37314. }
  37315. void ComboBox::setTextWhenNothingSelected (const String& newMessage) throw()
  37316. {
  37317. textWhenNothingSelected = newMessage;
  37318. repaint();
  37319. }
  37320. const String ComboBox::getTextWhenNothingSelected() const throw()
  37321. {
  37322. return textWhenNothingSelected;
  37323. }
  37324. void ComboBox::setTextWhenNoChoicesAvailable (const String& newMessage) throw()
  37325. {
  37326. noChoicesMessage = newMessage;
  37327. }
  37328. const String ComboBox::getTextWhenNoChoicesAvailable() const throw()
  37329. {
  37330. return noChoicesMessage;
  37331. }
  37332. void ComboBox::paint (Graphics& g)
  37333. {
  37334. getLookAndFeel().drawComboBox (g,
  37335. getWidth(),
  37336. getHeight(),
  37337. isButtonDown,
  37338. label->getRight(),
  37339. 0,
  37340. getWidth() - label->getRight(),
  37341. getHeight(),
  37342. *this);
  37343. if (textWhenNothingSelected.isNotEmpty()
  37344. && label->getText().isEmpty()
  37345. && ! label->isBeingEdited())
  37346. {
  37347. g.setColour (findColour (textColourId).withMultipliedAlpha (0.5f));
  37348. g.setFont (label->getFont());
  37349. g.drawFittedText (textWhenNothingSelected,
  37350. label->getX() + 2, label->getY() + 1,
  37351. label->getWidth() - 4, label->getHeight() - 2,
  37352. label->getJustificationType(),
  37353. jmax (1, (int) (label->getHeight() / label->getFont().getHeight())));
  37354. }
  37355. }
  37356. void ComboBox::resized()
  37357. {
  37358. if (getHeight() > 0 && getWidth() > 0)
  37359. getLookAndFeel().positionComboBoxText (*this, *label);
  37360. }
  37361. void ComboBox::enablementChanged()
  37362. {
  37363. repaint();
  37364. }
  37365. void ComboBox::lookAndFeelChanged()
  37366. {
  37367. repaint();
  37368. Label* const newLabel = getLookAndFeel().createComboBoxTextBox (*this);
  37369. if (label != 0)
  37370. {
  37371. newLabel->setEditable (label->isEditable());
  37372. newLabel->setJustificationType (label->getJustificationType());
  37373. newLabel->setTooltip (label->getTooltip());
  37374. newLabel->setText (label->getText(), false);
  37375. }
  37376. label = newLabel;
  37377. addAndMakeVisible (newLabel);
  37378. newLabel->addListener (this);
  37379. newLabel->addMouseListener (this, false);
  37380. newLabel->setColour (Label::backgroundColourId, Colours::transparentBlack);
  37381. newLabel->setColour (Label::textColourId, findColour (ComboBox::textColourId));
  37382. newLabel->setColour (TextEditor::textColourId, findColour (ComboBox::textColourId));
  37383. newLabel->setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  37384. newLabel->setColour (TextEditor::highlightColourId, findColour (TextEditor::highlightColourId));
  37385. newLabel->setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  37386. resized();
  37387. }
  37388. void ComboBox::colourChanged()
  37389. {
  37390. lookAndFeelChanged();
  37391. }
  37392. bool ComboBox::keyPressed (const KeyPress& key)
  37393. {
  37394. bool used = false;
  37395. if (key.isKeyCode (KeyPress::upKey)
  37396. || key.isKeyCode (KeyPress::leftKey))
  37397. {
  37398. setSelectedItemIndex (jmax (0, getSelectedItemIndex() - 1));
  37399. used = true;
  37400. }
  37401. else if (key.isKeyCode (KeyPress::downKey)
  37402. || key.isKeyCode (KeyPress::rightKey))
  37403. {
  37404. setSelectedItemIndex (jmin (getSelectedItemIndex() + 1, getNumItems() - 1));
  37405. used = true;
  37406. }
  37407. else if (key.isKeyCode (KeyPress::returnKey))
  37408. {
  37409. showPopup();
  37410. used = true;
  37411. }
  37412. return used;
  37413. }
  37414. bool ComboBox::keyStateChanged (const bool isKeyDown)
  37415. {
  37416. // only forward key events that aren't used by this component
  37417. return isKeyDown
  37418. && (KeyPress::isKeyCurrentlyDown (KeyPress::upKey)
  37419. || KeyPress::isKeyCurrentlyDown (KeyPress::leftKey)
  37420. || KeyPress::isKeyCurrentlyDown (KeyPress::downKey)
  37421. || KeyPress::isKeyCurrentlyDown (KeyPress::rightKey));
  37422. }
  37423. void ComboBox::focusGained (FocusChangeType)
  37424. {
  37425. repaint();
  37426. }
  37427. void ComboBox::focusLost (FocusChangeType)
  37428. {
  37429. repaint();
  37430. }
  37431. void ComboBox::labelTextChanged (Label*)
  37432. {
  37433. triggerAsyncUpdate();
  37434. }
  37435. void ComboBox::showPopup()
  37436. {
  37437. if (! menuActive)
  37438. {
  37439. const int selectedId = getSelectedId();
  37440. Component::SafePointer<Component> deletionWatcher (this);
  37441. PopupMenu menu;
  37442. menu.setLookAndFeel (&getLookAndFeel());
  37443. for (int i = 0; i < items.size(); ++i)
  37444. {
  37445. const ItemInfo* const item = items.getUnchecked(i);
  37446. if (item->isSeparator())
  37447. menu.addSeparator();
  37448. else if (item->isHeading)
  37449. menu.addSectionHeader (item->name);
  37450. else
  37451. menu.addItem (item->itemId, item->name,
  37452. item->isEnabled, item->itemId == selectedId);
  37453. }
  37454. if (items.size() == 0)
  37455. menu.addItem (1, noChoicesMessage, false);
  37456. const int itemHeight = jlimit (12, 24, getHeight());
  37457. menuActive = true;
  37458. const int resultId = menu.showAt (this, selectedId,
  37459. getWidth(), 1, itemHeight);
  37460. if (deletionWatcher == 0)
  37461. return;
  37462. menuActive = false;
  37463. if (resultId != 0)
  37464. setSelectedId (resultId);
  37465. }
  37466. }
  37467. void ComboBox::mouseDown (const MouseEvent& e)
  37468. {
  37469. beginDragAutoRepeat (300);
  37470. isButtonDown = isEnabled();
  37471. if (isButtonDown
  37472. && (e.eventComponent == this || ! label->isEditable()))
  37473. {
  37474. showPopup();
  37475. }
  37476. }
  37477. void ComboBox::mouseDrag (const MouseEvent& e)
  37478. {
  37479. beginDragAutoRepeat (50);
  37480. if (isButtonDown && ! e.mouseWasClicked())
  37481. showPopup();
  37482. }
  37483. void ComboBox::mouseUp (const MouseEvent& e2)
  37484. {
  37485. if (isButtonDown)
  37486. {
  37487. isButtonDown = false;
  37488. repaint();
  37489. const MouseEvent e (e2.getEventRelativeTo (this));
  37490. if (reallyContains (e.x, e.y, true)
  37491. && (e2.eventComponent == this || ! label->isEditable()))
  37492. {
  37493. showPopup();
  37494. }
  37495. }
  37496. }
  37497. void ComboBox::addListener (ComboBoxListener* const listener) throw()
  37498. {
  37499. listeners.add (listener);
  37500. }
  37501. void ComboBox::removeListener (ComboBoxListener* const listener) throw()
  37502. {
  37503. listeners.remove (listener);
  37504. }
  37505. void ComboBox::handleAsyncUpdate()
  37506. {
  37507. Component::BailOutChecker checker (this);
  37508. listeners.callChecked (checker, &ComboBoxListener::comboBoxChanged, this);
  37509. }
  37510. END_JUCE_NAMESPACE
  37511. /*** End of inlined file: juce_ComboBox.cpp ***/
  37512. /*** Start of inlined file: juce_Label.cpp ***/
  37513. BEGIN_JUCE_NAMESPACE
  37514. Label::Label (const String& componentName,
  37515. const String& labelText)
  37516. : Component (componentName),
  37517. textValue (labelText),
  37518. lastTextValue (labelText),
  37519. font (15.0f),
  37520. justification (Justification::centredLeft),
  37521. ownerComponent (0),
  37522. horizontalBorderSize (5),
  37523. verticalBorderSize (1),
  37524. minimumHorizontalScale (0.7f),
  37525. editSingleClick (false),
  37526. editDoubleClick (false),
  37527. lossOfFocusDiscardsChanges (false)
  37528. {
  37529. setColour (TextEditor::textColourId, Colours::black);
  37530. setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  37531. setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  37532. textValue.addListener (this);
  37533. }
  37534. Label::~Label()
  37535. {
  37536. textValue.removeListener (this);
  37537. if (ownerComponent != 0)
  37538. ownerComponent->removeComponentListener (this);
  37539. editor = 0;
  37540. }
  37541. void Label::setText (const String& newText,
  37542. const bool broadcastChangeMessage)
  37543. {
  37544. hideEditor (true);
  37545. if (lastTextValue != newText)
  37546. {
  37547. lastTextValue = newText;
  37548. textValue = newText;
  37549. repaint();
  37550. textWasChanged();
  37551. if (ownerComponent != 0)
  37552. componentMovedOrResized (*ownerComponent, true, true);
  37553. if (broadcastChangeMessage)
  37554. callChangeListeners();
  37555. }
  37556. }
  37557. const String Label::getText (const bool returnActiveEditorContents) const throw()
  37558. {
  37559. return (returnActiveEditorContents && isBeingEdited())
  37560. ? editor->getText()
  37561. : textValue.toString();
  37562. }
  37563. void Label::valueChanged (Value&)
  37564. {
  37565. if (lastTextValue != textValue.toString())
  37566. setText (textValue.toString(), true);
  37567. }
  37568. void Label::setFont (const Font& newFont) throw()
  37569. {
  37570. font = newFont;
  37571. repaint();
  37572. }
  37573. const Font& Label::getFont() const throw()
  37574. {
  37575. return font;
  37576. }
  37577. void Label::setEditable (const bool editOnSingleClick,
  37578. const bool editOnDoubleClick,
  37579. const bool lossOfFocusDiscardsChanges_) throw()
  37580. {
  37581. editSingleClick = editOnSingleClick;
  37582. editDoubleClick = editOnDoubleClick;
  37583. lossOfFocusDiscardsChanges = lossOfFocusDiscardsChanges_;
  37584. setWantsKeyboardFocus (editOnSingleClick || editOnDoubleClick);
  37585. setFocusContainer (editOnSingleClick || editOnDoubleClick);
  37586. }
  37587. void Label::setJustificationType (const Justification& justification_) throw()
  37588. {
  37589. justification = justification_;
  37590. repaint();
  37591. }
  37592. void Label::setBorderSize (int h, int v)
  37593. {
  37594. horizontalBorderSize = h;
  37595. verticalBorderSize = v;
  37596. repaint();
  37597. }
  37598. Component* Label::getAttachedComponent() const
  37599. {
  37600. return static_cast<Component*> (ownerComponent);
  37601. }
  37602. void Label::attachToComponent (Component* owner,
  37603. const bool onLeft)
  37604. {
  37605. if (ownerComponent != 0)
  37606. ownerComponent->removeComponentListener (this);
  37607. ownerComponent = owner;
  37608. leftOfOwnerComp = onLeft;
  37609. if (ownerComponent != 0)
  37610. {
  37611. setVisible (owner->isVisible());
  37612. ownerComponent->addComponentListener (this);
  37613. componentParentHierarchyChanged (*ownerComponent);
  37614. componentMovedOrResized (*ownerComponent, true, true);
  37615. }
  37616. }
  37617. void Label::componentMovedOrResized (Component& component,
  37618. bool /*wasMoved*/,
  37619. bool /*wasResized*/)
  37620. {
  37621. if (leftOfOwnerComp)
  37622. {
  37623. setSize (jmin (getFont().getStringWidth (textValue.toString()) + 8, component.getX()),
  37624. component.getHeight());
  37625. setTopRightPosition (component.getX(), component.getY());
  37626. }
  37627. else
  37628. {
  37629. setSize (component.getWidth(),
  37630. 8 + roundToInt (getFont().getHeight()));
  37631. setTopLeftPosition (component.getX(), component.getY() - getHeight());
  37632. }
  37633. }
  37634. void Label::componentParentHierarchyChanged (Component& component)
  37635. {
  37636. if (component.getParentComponent() != 0)
  37637. component.getParentComponent()->addChildComponent (this);
  37638. }
  37639. void Label::componentVisibilityChanged (Component& component)
  37640. {
  37641. setVisible (component.isVisible());
  37642. }
  37643. void Label::textWasEdited()
  37644. {
  37645. }
  37646. void Label::textWasChanged()
  37647. {
  37648. }
  37649. void Label::showEditor()
  37650. {
  37651. if (editor == 0)
  37652. {
  37653. addAndMakeVisible (editor = createEditorComponent());
  37654. editor->setText (getText(), false);
  37655. editor->addListener (this);
  37656. editor->grabKeyboardFocus();
  37657. editor->setHighlightedRegion (Range<int> (0, textValue.toString().length()));
  37658. editor->addListener (this);
  37659. resized();
  37660. repaint();
  37661. editorShown (editor);
  37662. enterModalState();
  37663. editor->grabKeyboardFocus();
  37664. }
  37665. }
  37666. void Label::editorShown (TextEditor* /*editorComponent*/)
  37667. {
  37668. }
  37669. void Label::editorAboutToBeHidden (TextEditor* /*editorComponent*/)
  37670. {
  37671. }
  37672. bool Label::updateFromTextEditorContents()
  37673. {
  37674. jassert (editor != 0);
  37675. const String newText (editor->getText());
  37676. if (textValue.toString() != newText)
  37677. {
  37678. lastTextValue = newText;
  37679. textValue = newText;
  37680. repaint();
  37681. textWasChanged();
  37682. if (ownerComponent != 0)
  37683. componentMovedOrResized (*ownerComponent, true, true);
  37684. return true;
  37685. }
  37686. return false;
  37687. }
  37688. void Label::hideEditor (const bool discardCurrentEditorContents)
  37689. {
  37690. if (editor != 0)
  37691. {
  37692. Component::SafePointer<Component> deletionChecker (this);
  37693. editorAboutToBeHidden (editor);
  37694. const bool changed = (! discardCurrentEditorContents)
  37695. && updateFromTextEditorContents();
  37696. editor = 0;
  37697. repaint();
  37698. if (changed)
  37699. textWasEdited();
  37700. if (deletionChecker != 0)
  37701. exitModalState (0);
  37702. if (changed && deletionChecker != 0)
  37703. callChangeListeners();
  37704. }
  37705. }
  37706. void Label::inputAttemptWhenModal()
  37707. {
  37708. if (editor != 0)
  37709. {
  37710. if (lossOfFocusDiscardsChanges)
  37711. textEditorEscapeKeyPressed (*editor);
  37712. else
  37713. textEditorReturnKeyPressed (*editor);
  37714. }
  37715. }
  37716. bool Label::isBeingEdited() const throw()
  37717. {
  37718. return editor != 0;
  37719. }
  37720. TextEditor* Label::createEditorComponent()
  37721. {
  37722. TextEditor* const ed = new TextEditor (getName());
  37723. ed->setFont (font);
  37724. // copy these colours from our own settings..
  37725. const int cols[] = { TextEditor::backgroundColourId,
  37726. TextEditor::textColourId,
  37727. TextEditor::highlightColourId,
  37728. TextEditor::highlightedTextColourId,
  37729. TextEditor::caretColourId,
  37730. TextEditor::outlineColourId,
  37731. TextEditor::focusedOutlineColourId,
  37732. TextEditor::shadowColourId };
  37733. for (int i = 0; i < numElementsInArray (cols); ++i)
  37734. ed->setColour (cols[i], findColour (cols[i]));
  37735. return ed;
  37736. }
  37737. void Label::paint (Graphics& g)
  37738. {
  37739. getLookAndFeel().drawLabel (g, *this);
  37740. }
  37741. void Label::mouseUp (const MouseEvent& e)
  37742. {
  37743. if (editSingleClick
  37744. && e.mouseWasClicked()
  37745. && contains (e.x, e.y)
  37746. && ! e.mods.isPopupMenu())
  37747. {
  37748. showEditor();
  37749. }
  37750. }
  37751. void Label::mouseDoubleClick (const MouseEvent& e)
  37752. {
  37753. if (editDoubleClick && ! e.mods.isPopupMenu())
  37754. showEditor();
  37755. }
  37756. void Label::resized()
  37757. {
  37758. if (editor != 0)
  37759. editor->setBoundsInset (BorderSize (0));
  37760. }
  37761. void Label::focusGained (FocusChangeType cause)
  37762. {
  37763. if (editSingleClick && cause == focusChangedByTabKey)
  37764. showEditor();
  37765. }
  37766. void Label::enablementChanged()
  37767. {
  37768. repaint();
  37769. }
  37770. void Label::colourChanged()
  37771. {
  37772. repaint();
  37773. }
  37774. void Label::setMinimumHorizontalScale (const float newScale)
  37775. {
  37776. if (minimumHorizontalScale != newScale)
  37777. {
  37778. minimumHorizontalScale = newScale;
  37779. repaint();
  37780. }
  37781. }
  37782. // We'll use a custom focus traverser here to make sure focus goes from the
  37783. // text editor to another component rather than back to the label itself.
  37784. class LabelKeyboardFocusTraverser : public KeyboardFocusTraverser
  37785. {
  37786. public:
  37787. LabelKeyboardFocusTraverser() {}
  37788. Component* getNextComponent (Component* current)
  37789. {
  37790. return KeyboardFocusTraverser::getNextComponent (dynamic_cast <TextEditor*> (current) != 0
  37791. ? current->getParentComponent() : current);
  37792. }
  37793. Component* getPreviousComponent (Component* current)
  37794. {
  37795. return KeyboardFocusTraverser::getPreviousComponent (dynamic_cast <TextEditor*> (current) != 0
  37796. ? current->getParentComponent() : current);
  37797. }
  37798. };
  37799. KeyboardFocusTraverser* Label::createFocusTraverser()
  37800. {
  37801. return new LabelKeyboardFocusTraverser();
  37802. }
  37803. void Label::addListener (LabelListener* const listener) throw()
  37804. {
  37805. listeners.add (listener);
  37806. }
  37807. void Label::removeListener (LabelListener* const listener) throw()
  37808. {
  37809. listeners.remove (listener);
  37810. }
  37811. void Label::callChangeListeners()
  37812. {
  37813. Component::BailOutChecker checker (this);
  37814. listeners.callChecked (checker, &LabelListener::labelTextChanged, this);
  37815. }
  37816. void Label::textEditorTextChanged (TextEditor& ed)
  37817. {
  37818. if (editor != 0)
  37819. {
  37820. jassert (&ed == editor);
  37821. if (! (hasKeyboardFocus (true) || isCurrentlyBlockedByAnotherModalComponent()))
  37822. {
  37823. if (lossOfFocusDiscardsChanges)
  37824. textEditorEscapeKeyPressed (ed);
  37825. else
  37826. textEditorReturnKeyPressed (ed);
  37827. }
  37828. }
  37829. }
  37830. void Label::textEditorReturnKeyPressed (TextEditor& ed)
  37831. {
  37832. if (editor != 0)
  37833. {
  37834. jassert (&ed == editor);
  37835. (void) ed;
  37836. const bool changed = updateFromTextEditorContents();
  37837. hideEditor (true);
  37838. if (changed)
  37839. {
  37840. Component::SafePointer<Component> deletionChecker (this);
  37841. textWasEdited();
  37842. if (deletionChecker != 0)
  37843. callChangeListeners();
  37844. }
  37845. }
  37846. }
  37847. void Label::textEditorEscapeKeyPressed (TextEditor& ed)
  37848. {
  37849. if (editor != 0)
  37850. {
  37851. jassert (&ed == editor);
  37852. (void) ed;
  37853. editor->setText (textValue.toString(), false);
  37854. hideEditor (true);
  37855. }
  37856. }
  37857. void Label::textEditorFocusLost (TextEditor& ed)
  37858. {
  37859. textEditorTextChanged (ed);
  37860. }
  37861. END_JUCE_NAMESPACE
  37862. /*** End of inlined file: juce_Label.cpp ***/
  37863. /*** Start of inlined file: juce_ListBox.cpp ***/
  37864. BEGIN_JUCE_NAMESPACE
  37865. class ListBoxRowComponent : public Component,
  37866. public TooltipClient
  37867. {
  37868. public:
  37869. ListBoxRowComponent (ListBox& owner_)
  37870. : owner (owner_),
  37871. row (-1),
  37872. selected (false),
  37873. isDragging (false)
  37874. {
  37875. }
  37876. ~ListBoxRowComponent()
  37877. {
  37878. deleteAllChildren();
  37879. }
  37880. void paint (Graphics& g)
  37881. {
  37882. if (owner.getModel() != 0)
  37883. owner.getModel()->paintListBoxItem (row, g, getWidth(), getHeight(), selected);
  37884. }
  37885. void update (const int row_, const bool selected_)
  37886. {
  37887. if (row != row_ || selected != selected_)
  37888. {
  37889. repaint();
  37890. row = row_;
  37891. selected = selected_;
  37892. }
  37893. if (owner.getModel() != 0)
  37894. {
  37895. Component* const customComp = owner.getModel()->refreshComponentForRow (row_, selected_, getChildComponent (0));
  37896. if (customComp != 0)
  37897. {
  37898. addAndMakeVisible (customComp);
  37899. customComp->setBounds (0, 0, getWidth(), getHeight());
  37900. for (int i = getNumChildComponents(); --i >= 0;)
  37901. if (getChildComponent (i) != customComp)
  37902. delete getChildComponent (i);
  37903. }
  37904. else
  37905. {
  37906. deleteAllChildren();
  37907. }
  37908. }
  37909. }
  37910. void mouseDown (const MouseEvent& e)
  37911. {
  37912. isDragging = false;
  37913. selectRowOnMouseUp = false;
  37914. if (isEnabled())
  37915. {
  37916. if (! selected)
  37917. {
  37918. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  37919. if (owner.getModel() != 0)
  37920. owner.getModel()->listBoxItemClicked (row, e);
  37921. }
  37922. else
  37923. {
  37924. selectRowOnMouseUp = true;
  37925. }
  37926. }
  37927. }
  37928. void mouseUp (const MouseEvent& e)
  37929. {
  37930. if (isEnabled() && selectRowOnMouseUp && ! isDragging)
  37931. {
  37932. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  37933. if (owner.getModel() != 0)
  37934. owner.getModel()->listBoxItemClicked (row, e);
  37935. }
  37936. }
  37937. void mouseDoubleClick (const MouseEvent& e)
  37938. {
  37939. if (owner.getModel() != 0 && isEnabled())
  37940. owner.getModel()->listBoxItemDoubleClicked (row, e);
  37941. }
  37942. void mouseDrag (const MouseEvent& e)
  37943. {
  37944. if (isEnabled() && owner.getModel() != 0 && ! (e.mouseWasClicked() || isDragging))
  37945. {
  37946. const SparseSet <int> selectedRows (owner.getSelectedRows());
  37947. if (selectedRows.size() > 0)
  37948. {
  37949. const String dragDescription (owner.getModel()->getDragSourceDescription (selectedRows));
  37950. if (dragDescription.isNotEmpty())
  37951. {
  37952. isDragging = true;
  37953. owner.startDragAndDrop (e, dragDescription);
  37954. }
  37955. }
  37956. }
  37957. }
  37958. void resized()
  37959. {
  37960. if (getNumChildComponents() > 0)
  37961. getChildComponent(0)->setBounds (0, 0, getWidth(), getHeight());
  37962. }
  37963. const String getTooltip()
  37964. {
  37965. if (owner.getModel() != 0)
  37966. return owner.getModel()->getTooltipForRow (row);
  37967. return String::empty;
  37968. }
  37969. juce_UseDebuggingNewOperator
  37970. bool neededFlag;
  37971. private:
  37972. ListBox& owner;
  37973. int row;
  37974. bool selected, isDragging, selectRowOnMouseUp;
  37975. ListBoxRowComponent (const ListBoxRowComponent&);
  37976. ListBoxRowComponent& operator= (const ListBoxRowComponent&);
  37977. };
  37978. class ListViewport : public Viewport
  37979. {
  37980. public:
  37981. int firstIndex, firstWholeIndex, lastWholeIndex;
  37982. bool hasUpdated;
  37983. ListViewport (ListBox& owner_)
  37984. : owner (owner_)
  37985. {
  37986. setWantsKeyboardFocus (false);
  37987. setViewedComponent (new Component());
  37988. getViewedComponent()->addMouseListener (this, false);
  37989. getViewedComponent()->setWantsKeyboardFocus (false);
  37990. }
  37991. ~ListViewport()
  37992. {
  37993. getViewedComponent()->removeMouseListener (this);
  37994. getViewedComponent()->deleteAllChildren();
  37995. }
  37996. ListBoxRowComponent* getComponentForRow (const int row) const throw()
  37997. {
  37998. return (ListBoxRowComponent*) getViewedComponent()
  37999. ->getChildComponent (row % jmax (1, getViewedComponent()->getNumChildComponents()));
  38000. }
  38001. int getRowNumberOfComponent (Component* const rowComponent) const throw()
  38002. {
  38003. const int index = getIndexOfChildComponent (rowComponent);
  38004. const int num = getViewedComponent()->getNumChildComponents();
  38005. for (int i = num; --i >= 0;)
  38006. if (((firstIndex + i) % jmax (1, num)) == index)
  38007. return firstIndex + i;
  38008. return -1;
  38009. }
  38010. Component* getComponentForRowIfOnscreen (const int row) const throw()
  38011. {
  38012. return (row >= firstIndex && row < firstIndex + getViewedComponent()->getNumChildComponents())
  38013. ? getComponentForRow (row) : 0;
  38014. }
  38015. void visibleAreaChanged (int, int, int, int)
  38016. {
  38017. updateVisibleArea (true);
  38018. if (owner.getModel() != 0)
  38019. owner.getModel()->listWasScrolled();
  38020. }
  38021. void updateVisibleArea (const bool makeSureItUpdatesContent)
  38022. {
  38023. hasUpdated = false;
  38024. const int newX = getViewedComponent()->getX();
  38025. int newY = getViewedComponent()->getY();
  38026. const int newW = jmax (owner.minimumRowWidth, getMaximumVisibleWidth());
  38027. const int newH = owner.totalItems * owner.getRowHeight();
  38028. if (newY + newH < getMaximumVisibleHeight() && newH > getMaximumVisibleHeight())
  38029. newY = getMaximumVisibleHeight() - newH;
  38030. getViewedComponent()->setBounds (newX, newY, newW, newH);
  38031. if (makeSureItUpdatesContent && ! hasUpdated)
  38032. updateContents();
  38033. }
  38034. void updateContents()
  38035. {
  38036. hasUpdated = true;
  38037. const int rowHeight = owner.getRowHeight();
  38038. if (rowHeight > 0)
  38039. {
  38040. const int y = getViewPositionY();
  38041. const int w = getViewedComponent()->getWidth();
  38042. const int numNeeded = 2 + getMaximumVisibleHeight() / rowHeight;
  38043. while (numNeeded > getViewedComponent()->getNumChildComponents())
  38044. getViewedComponent()->addAndMakeVisible (new ListBoxRowComponent (owner));
  38045. jassert (numNeeded >= 0);
  38046. while (numNeeded < getViewedComponent()->getNumChildComponents())
  38047. {
  38048. Component* const rowToRemove
  38049. = getViewedComponent()->getChildComponent (getViewedComponent()->getNumChildComponents() - 1);
  38050. delete rowToRemove;
  38051. }
  38052. firstIndex = y / rowHeight;
  38053. firstWholeIndex = (y + rowHeight - 1) / rowHeight;
  38054. lastWholeIndex = (y + getMaximumVisibleHeight() - 1) / rowHeight;
  38055. for (int i = 0; i < numNeeded; ++i)
  38056. {
  38057. const int row = i + firstIndex;
  38058. ListBoxRowComponent* const rowComp = getComponentForRow (row);
  38059. if (rowComp != 0)
  38060. {
  38061. rowComp->setBounds (0, row * rowHeight, w, rowHeight);
  38062. rowComp->update (row, owner.isRowSelected (row));
  38063. }
  38064. }
  38065. }
  38066. if (owner.headerComponent != 0)
  38067. owner.headerComponent->setBounds (owner.outlineThickness + getViewedComponent()->getX(),
  38068. owner.outlineThickness,
  38069. jmax (owner.getWidth() - owner.outlineThickness * 2,
  38070. getViewedComponent()->getWidth()),
  38071. owner.headerComponent->getHeight());
  38072. }
  38073. void paint (Graphics& g)
  38074. {
  38075. if (isOpaque())
  38076. g.fillAll (owner.findColour (ListBox::backgroundColourId));
  38077. }
  38078. bool keyPressed (const KeyPress& key)
  38079. {
  38080. if (key.isKeyCode (KeyPress::upKey)
  38081. || key.isKeyCode (KeyPress::downKey)
  38082. || key.isKeyCode (KeyPress::pageUpKey)
  38083. || key.isKeyCode (KeyPress::pageDownKey)
  38084. || key.isKeyCode (KeyPress::homeKey)
  38085. || key.isKeyCode (KeyPress::endKey))
  38086. {
  38087. // we want to avoid these keypresses going to the viewport, and instead allow
  38088. // them to pass up to our listbox..
  38089. return false;
  38090. }
  38091. return Viewport::keyPressed (key);
  38092. }
  38093. juce_UseDebuggingNewOperator
  38094. private:
  38095. ListBox& owner;
  38096. ListViewport (const ListViewport&);
  38097. ListViewport& operator= (const ListViewport&);
  38098. };
  38099. ListBox::ListBox (const String& name, ListBoxModel* const model_)
  38100. : Component (name),
  38101. model (model_),
  38102. headerComponent (0),
  38103. totalItems (0),
  38104. rowHeight (22),
  38105. minimumRowWidth (0),
  38106. outlineThickness (0),
  38107. lastRowSelected (-1),
  38108. mouseMoveSelects (false),
  38109. multipleSelection (false),
  38110. hasDoneInitialUpdate (false)
  38111. {
  38112. addAndMakeVisible (viewport = new ListViewport (*this));
  38113. setWantsKeyboardFocus (true);
  38114. colourChanged();
  38115. }
  38116. ListBox::~ListBox()
  38117. {
  38118. deleteAllChildren();
  38119. }
  38120. void ListBox::setModel (ListBoxModel* const newModel)
  38121. {
  38122. if (model != newModel)
  38123. {
  38124. model = newModel;
  38125. updateContent();
  38126. }
  38127. }
  38128. void ListBox::setMultipleSelectionEnabled (bool b)
  38129. {
  38130. multipleSelection = b;
  38131. }
  38132. void ListBox::setMouseMoveSelectsRows (bool b)
  38133. {
  38134. mouseMoveSelects = b;
  38135. if (b)
  38136. addMouseListener (this, true);
  38137. }
  38138. void ListBox::paint (Graphics& g)
  38139. {
  38140. if (! hasDoneInitialUpdate)
  38141. updateContent();
  38142. g.fillAll (findColour (backgroundColourId));
  38143. }
  38144. void ListBox::paintOverChildren (Graphics& g)
  38145. {
  38146. if (outlineThickness > 0)
  38147. {
  38148. g.setColour (findColour (outlineColourId));
  38149. g.drawRect (0, 0, getWidth(), getHeight(), outlineThickness);
  38150. }
  38151. }
  38152. void ListBox::resized()
  38153. {
  38154. viewport->setBoundsInset (BorderSize (outlineThickness + ((headerComponent != 0) ? headerComponent->getHeight() : 0),
  38155. outlineThickness,
  38156. outlineThickness,
  38157. outlineThickness));
  38158. viewport->setSingleStepSizes (20, getRowHeight());
  38159. viewport->updateVisibleArea (false);
  38160. }
  38161. void ListBox::visibilityChanged()
  38162. {
  38163. viewport->updateVisibleArea (true);
  38164. }
  38165. Viewport* ListBox::getViewport() const throw()
  38166. {
  38167. return viewport;
  38168. }
  38169. void ListBox::updateContent()
  38170. {
  38171. hasDoneInitialUpdate = true;
  38172. totalItems = (model != 0) ? model->getNumRows() : 0;
  38173. bool selectionChanged = false;
  38174. if (selected [selected.size() - 1] >= totalItems)
  38175. {
  38176. selected.removeRange (totalItems, std::numeric_limits<int>::max() - totalItems);
  38177. lastRowSelected = getSelectedRow (0);
  38178. selectionChanged = true;
  38179. }
  38180. viewport->updateVisibleArea (isVisible());
  38181. viewport->resized();
  38182. if (selectionChanged && model != 0)
  38183. model->selectedRowsChanged (lastRowSelected);
  38184. }
  38185. void ListBox::selectRow (const int row,
  38186. bool dontScroll,
  38187. bool deselectOthersFirst)
  38188. {
  38189. selectRowInternal (row, dontScroll, deselectOthersFirst, false);
  38190. }
  38191. void ListBox::selectRowInternal (const int row,
  38192. bool dontScroll,
  38193. bool deselectOthersFirst,
  38194. bool isMouseClick)
  38195. {
  38196. if (! multipleSelection)
  38197. deselectOthersFirst = true;
  38198. if ((! isRowSelected (row))
  38199. || (deselectOthersFirst && getNumSelectedRows() > 1))
  38200. {
  38201. if (((unsigned int) row) < (unsigned int) totalItems)
  38202. {
  38203. if (deselectOthersFirst)
  38204. selected.clear();
  38205. selected.addRange (row, 1);
  38206. if (getHeight() == 0 || getWidth() == 0)
  38207. dontScroll = true;
  38208. viewport->hasUpdated = false;
  38209. if (row < viewport->firstWholeIndex && ! dontScroll)
  38210. {
  38211. viewport->setViewPosition (viewport->getViewPositionX(),
  38212. row * getRowHeight());
  38213. }
  38214. else if (row >= viewport->lastWholeIndex && ! dontScroll)
  38215. {
  38216. const int rowsOnScreen = viewport->lastWholeIndex - viewport->firstWholeIndex;
  38217. if (row >= lastRowSelected + rowsOnScreen
  38218. && rowsOnScreen < totalItems - 1
  38219. && ! isMouseClick)
  38220. {
  38221. viewport->setViewPosition (viewport->getViewPositionX(),
  38222. jlimit (0, jmax (0, totalItems - rowsOnScreen), row)
  38223. * getRowHeight());
  38224. }
  38225. else
  38226. {
  38227. viewport->setViewPosition (viewport->getViewPositionX(),
  38228. jmax (0, (row + 1) * getRowHeight() - viewport->getMaximumVisibleHeight()));
  38229. }
  38230. }
  38231. if (! viewport->hasUpdated)
  38232. viewport->updateContents();
  38233. lastRowSelected = row;
  38234. model->selectedRowsChanged (row);
  38235. }
  38236. else
  38237. {
  38238. if (deselectOthersFirst)
  38239. deselectAllRows();
  38240. }
  38241. }
  38242. }
  38243. void ListBox::deselectRow (const int row)
  38244. {
  38245. if (selected.contains (row))
  38246. {
  38247. selected.removeRange (row, 1);
  38248. if (row == lastRowSelected)
  38249. lastRowSelected = getSelectedRow (0);
  38250. viewport->updateContents();
  38251. model->selectedRowsChanged (lastRowSelected);
  38252. }
  38253. }
  38254. void ListBox::setSelectedRows (const SparseSet<int>& setOfRowsToBeSelected,
  38255. const bool sendNotificationEventToModel)
  38256. {
  38257. selected = setOfRowsToBeSelected;
  38258. selected.removeRange (totalItems, std::numeric_limits<int>::max() - totalItems);
  38259. if (! isRowSelected (lastRowSelected))
  38260. lastRowSelected = getSelectedRow (0);
  38261. viewport->updateContents();
  38262. if ((model != 0) && sendNotificationEventToModel)
  38263. model->selectedRowsChanged (lastRowSelected);
  38264. }
  38265. const SparseSet<int> ListBox::getSelectedRows() const
  38266. {
  38267. return selected;
  38268. }
  38269. void ListBox::selectRangeOfRows (int firstRow, int lastRow)
  38270. {
  38271. if (multipleSelection && (firstRow != lastRow))
  38272. {
  38273. const int numRows = totalItems - 1;
  38274. firstRow = jlimit (0, jmax (0, numRows), firstRow);
  38275. lastRow = jlimit (0, jmax (0, numRows), lastRow);
  38276. selected.addRange (jmin (firstRow, lastRow),
  38277. abs (firstRow - lastRow) + 1);
  38278. selected.removeRange (lastRow, 1);
  38279. }
  38280. selectRowInternal (lastRow, false, false, true);
  38281. }
  38282. void ListBox::flipRowSelection (const int row)
  38283. {
  38284. if (isRowSelected (row))
  38285. deselectRow (row);
  38286. else
  38287. selectRowInternal (row, false, false, true);
  38288. }
  38289. void ListBox::deselectAllRows()
  38290. {
  38291. if (! selected.isEmpty())
  38292. {
  38293. selected.clear();
  38294. lastRowSelected = -1;
  38295. viewport->updateContents();
  38296. if (model != 0)
  38297. model->selectedRowsChanged (lastRowSelected);
  38298. }
  38299. }
  38300. void ListBox::selectRowsBasedOnModifierKeys (const int row,
  38301. const ModifierKeys& mods)
  38302. {
  38303. if (multipleSelection && mods.isCommandDown())
  38304. {
  38305. flipRowSelection (row);
  38306. }
  38307. else if (multipleSelection && mods.isShiftDown() && lastRowSelected >= 0)
  38308. {
  38309. selectRangeOfRows (lastRowSelected, row);
  38310. }
  38311. else if ((! mods.isPopupMenu()) || ! isRowSelected (row))
  38312. {
  38313. selectRowInternal (row, false, true, true);
  38314. }
  38315. }
  38316. int ListBox::getNumSelectedRows() const
  38317. {
  38318. return selected.size();
  38319. }
  38320. int ListBox::getSelectedRow (const int index) const
  38321. {
  38322. return (((unsigned int) index) < (unsigned int) selected.size())
  38323. ? selected [index] : -1;
  38324. }
  38325. bool ListBox::isRowSelected (const int row) const
  38326. {
  38327. return selected.contains (row);
  38328. }
  38329. int ListBox::getLastRowSelected() const
  38330. {
  38331. return (isRowSelected (lastRowSelected)) ? lastRowSelected : -1;
  38332. }
  38333. int ListBox::getRowContainingPosition (const int x, const int y) const throw()
  38334. {
  38335. if (((unsigned int) x) < (unsigned int) getWidth())
  38336. {
  38337. const int row = (viewport->getViewPositionY() + y - viewport->getY()) / rowHeight;
  38338. if (((unsigned int) row) < (unsigned int) totalItems)
  38339. return row;
  38340. }
  38341. return -1;
  38342. }
  38343. int ListBox::getInsertionIndexForPosition (const int x, const int y) const throw()
  38344. {
  38345. if (((unsigned int) x) < (unsigned int) getWidth())
  38346. {
  38347. const int row = (viewport->getViewPositionY() + y + rowHeight / 2 - viewport->getY()) / rowHeight;
  38348. return jlimit (0, totalItems, row);
  38349. }
  38350. return -1;
  38351. }
  38352. Component* ListBox::getComponentForRowNumber (const int row) const throw()
  38353. {
  38354. Component* const listRowComp = viewport->getComponentForRowIfOnscreen (row);
  38355. return listRowComp != 0 ? listRowComp->getChildComponent (0) : 0;
  38356. }
  38357. int ListBox::getRowNumberOfComponent (Component* const rowComponent) const throw()
  38358. {
  38359. return viewport->getRowNumberOfComponent (rowComponent);
  38360. }
  38361. const Rectangle<int> ListBox::getRowPosition (const int rowNumber,
  38362. const bool relativeToComponentTopLeft) const throw()
  38363. {
  38364. const int rowHeight = getRowHeight();
  38365. int y = viewport->getY() + rowHeight * rowNumber;
  38366. if (relativeToComponentTopLeft)
  38367. y -= viewport->getViewPositionY();
  38368. return Rectangle<int> (viewport->getX(), y,
  38369. viewport->getViewedComponent()->getWidth(), rowHeight);
  38370. }
  38371. void ListBox::setVerticalPosition (const double proportion)
  38372. {
  38373. const int offscreen = viewport->getViewedComponent()->getHeight() - viewport->getHeight();
  38374. viewport->setViewPosition (viewport->getViewPositionX(),
  38375. jmax (0, roundToInt (proportion * offscreen)));
  38376. }
  38377. double ListBox::getVerticalPosition() const
  38378. {
  38379. const int offscreen = viewport->getViewedComponent()->getHeight() - viewport->getHeight();
  38380. return (offscreen > 0) ? viewport->getViewPositionY() / (double) offscreen
  38381. : 0;
  38382. }
  38383. int ListBox::getVisibleRowWidth() const throw()
  38384. {
  38385. return viewport->getViewWidth();
  38386. }
  38387. void ListBox::scrollToEnsureRowIsOnscreen (const int row)
  38388. {
  38389. if (row < viewport->firstWholeIndex)
  38390. {
  38391. viewport->setViewPosition (viewport->getViewPositionX(),
  38392. row * getRowHeight());
  38393. }
  38394. else if (row >= viewport->lastWholeIndex)
  38395. {
  38396. viewport->setViewPosition (viewport->getViewPositionX(),
  38397. jmax (0, (row + 1) * getRowHeight() - viewport->getMaximumVisibleHeight()));
  38398. }
  38399. }
  38400. bool ListBox::keyPressed (const KeyPress& key)
  38401. {
  38402. const int numVisibleRows = viewport->getHeight() / getRowHeight();
  38403. const bool multiple = multipleSelection
  38404. && (lastRowSelected >= 0)
  38405. && (key.getModifiers().isShiftDown()
  38406. || key.getModifiers().isCtrlDown()
  38407. || key.getModifiers().isCommandDown());
  38408. if (key.isKeyCode (KeyPress::upKey))
  38409. {
  38410. if (multiple)
  38411. selectRangeOfRows (lastRowSelected, lastRowSelected - 1);
  38412. else
  38413. selectRow (jmax (0, lastRowSelected - 1));
  38414. }
  38415. else if (key.isKeyCode (KeyPress::returnKey)
  38416. && isRowSelected (lastRowSelected))
  38417. {
  38418. if (model != 0)
  38419. model->returnKeyPressed (lastRowSelected);
  38420. }
  38421. else if (key.isKeyCode (KeyPress::pageUpKey))
  38422. {
  38423. if (multiple)
  38424. selectRangeOfRows (lastRowSelected, lastRowSelected - numVisibleRows);
  38425. else
  38426. selectRow (jmax (0, jmax (0, lastRowSelected) - numVisibleRows));
  38427. }
  38428. else if (key.isKeyCode (KeyPress::pageDownKey))
  38429. {
  38430. if (multiple)
  38431. selectRangeOfRows (lastRowSelected, lastRowSelected + numVisibleRows);
  38432. else
  38433. selectRow (jmin (totalItems - 1, jmax (0, lastRowSelected) + numVisibleRows));
  38434. }
  38435. else if (key.isKeyCode (KeyPress::homeKey))
  38436. {
  38437. if (multiple && key.getModifiers().isShiftDown())
  38438. selectRangeOfRows (lastRowSelected, 0);
  38439. else
  38440. selectRow (0);
  38441. }
  38442. else if (key.isKeyCode (KeyPress::endKey))
  38443. {
  38444. if (multiple && key.getModifiers().isShiftDown())
  38445. selectRangeOfRows (lastRowSelected, totalItems - 1);
  38446. else
  38447. selectRow (totalItems - 1);
  38448. }
  38449. else if (key.isKeyCode (KeyPress::downKey))
  38450. {
  38451. if (multiple)
  38452. selectRangeOfRows (lastRowSelected, lastRowSelected + 1);
  38453. else
  38454. selectRow (jmin (totalItems - 1, jmax (0, lastRowSelected) + 1));
  38455. }
  38456. else if ((key.isKeyCode (KeyPress::deleteKey) || key.isKeyCode (KeyPress::backspaceKey))
  38457. && isRowSelected (lastRowSelected))
  38458. {
  38459. if (model != 0)
  38460. model->deleteKeyPressed (lastRowSelected);
  38461. }
  38462. else if (multiple && key == KeyPress (T('a'), ModifierKeys::commandModifier, 0))
  38463. {
  38464. selectRangeOfRows (0, std::numeric_limits<int>::max());
  38465. }
  38466. else
  38467. {
  38468. return false;
  38469. }
  38470. return true;
  38471. }
  38472. bool ListBox::keyStateChanged (const bool isKeyDown)
  38473. {
  38474. return isKeyDown
  38475. && (KeyPress::isKeyCurrentlyDown (KeyPress::upKey)
  38476. || KeyPress::isKeyCurrentlyDown (KeyPress::pageUpKey)
  38477. || KeyPress::isKeyCurrentlyDown (KeyPress::downKey)
  38478. || KeyPress::isKeyCurrentlyDown (KeyPress::pageDownKey)
  38479. || KeyPress::isKeyCurrentlyDown (KeyPress::homeKey)
  38480. || KeyPress::isKeyCurrentlyDown (KeyPress::endKey)
  38481. || KeyPress::isKeyCurrentlyDown (KeyPress::returnKey));
  38482. }
  38483. void ListBox::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  38484. {
  38485. getHorizontalScrollBar()->mouseWheelMove (e, wheelIncrementX, 0);
  38486. getVerticalScrollBar()->mouseWheelMove (e, 0, wheelIncrementY);
  38487. }
  38488. void ListBox::mouseMove (const MouseEvent& e)
  38489. {
  38490. if (mouseMoveSelects)
  38491. {
  38492. const MouseEvent e2 (e.getEventRelativeTo (this));
  38493. selectRow (getRowContainingPosition (e2.x, e2.y), true);
  38494. }
  38495. }
  38496. void ListBox::mouseExit (const MouseEvent& e)
  38497. {
  38498. mouseMove (e);
  38499. }
  38500. void ListBox::mouseUp (const MouseEvent& e)
  38501. {
  38502. if (e.mouseWasClicked() && model != 0)
  38503. model->backgroundClicked();
  38504. }
  38505. void ListBox::setRowHeight (const int newHeight)
  38506. {
  38507. rowHeight = jmax (1, newHeight);
  38508. viewport->setSingleStepSizes (20, rowHeight);
  38509. updateContent();
  38510. }
  38511. int ListBox::getNumRowsOnScreen() const throw()
  38512. {
  38513. return viewport->getMaximumVisibleHeight() / rowHeight;
  38514. }
  38515. void ListBox::setMinimumContentWidth (const int newMinimumWidth)
  38516. {
  38517. minimumRowWidth = newMinimumWidth;
  38518. updateContent();
  38519. }
  38520. int ListBox::getVisibleContentWidth() const throw()
  38521. {
  38522. return viewport->getMaximumVisibleWidth();
  38523. }
  38524. ScrollBar* ListBox::getVerticalScrollBar() const throw()
  38525. {
  38526. return viewport->getVerticalScrollBar();
  38527. }
  38528. ScrollBar* ListBox::getHorizontalScrollBar() const throw()
  38529. {
  38530. return viewport->getHorizontalScrollBar();
  38531. }
  38532. void ListBox::colourChanged()
  38533. {
  38534. setOpaque (findColour (backgroundColourId).isOpaque());
  38535. viewport->setOpaque (isOpaque());
  38536. repaint();
  38537. }
  38538. void ListBox::setOutlineThickness (const int outlineThickness_)
  38539. {
  38540. outlineThickness = outlineThickness_;
  38541. resized();
  38542. }
  38543. void ListBox::setHeaderComponent (Component* const newHeaderComponent)
  38544. {
  38545. if (headerComponent != newHeaderComponent)
  38546. {
  38547. delete headerComponent;
  38548. headerComponent = newHeaderComponent;
  38549. addAndMakeVisible (newHeaderComponent);
  38550. ListBox::resized();
  38551. }
  38552. }
  38553. void ListBox::repaintRow (const int rowNumber) throw()
  38554. {
  38555. const Rectangle<int> r (getRowPosition (rowNumber, true));
  38556. repaint (r.getX(), r.getY(), r.getWidth(), r.getHeight());
  38557. }
  38558. Image* ListBox::createSnapshotOfSelectedRows (int& imageX, int& imageY)
  38559. {
  38560. Rectangle<int> imageArea;
  38561. const int firstRow = getRowContainingPosition (0, 0);
  38562. int i;
  38563. for (i = getNumRowsOnScreen() + 2; --i >= 0;)
  38564. {
  38565. Component* rowComp = viewport->getComponentForRowIfOnscreen (firstRow + i);
  38566. if (rowComp != 0 && isRowSelected (firstRow + i))
  38567. {
  38568. const Point<int> pos (rowComp->relativePositionToOtherComponent (this, Point<int>()));
  38569. const Rectangle<int> rowRect (pos.getX(), pos.getY(), rowComp->getWidth(), rowComp->getHeight());
  38570. if (imageArea.isEmpty())
  38571. imageArea = rowRect;
  38572. else
  38573. imageArea = imageArea.getUnion (rowRect);
  38574. }
  38575. }
  38576. imageArea = imageArea.getIntersection (Rectangle<int> (0, 0, getWidth(), getHeight()));
  38577. imageX = imageArea.getX();
  38578. imageY = imageArea.getY();
  38579. Image* snapshot = Image::createNativeImage (Image::ARGB, imageArea.getWidth(), imageArea.getHeight(), true);
  38580. for (i = getNumRowsOnScreen() + 2; --i >= 0;)
  38581. {
  38582. Component* rowComp = viewport->getComponentForRowIfOnscreen (firstRow + i);
  38583. if (rowComp != 0 && isRowSelected (firstRow + i))
  38584. {
  38585. const Point<int> pos (rowComp->relativePositionToOtherComponent (this, Point<int>()));
  38586. Graphics g (*snapshot);
  38587. g.setOrigin (pos.getX() - imageX, pos.getY() - imageY);
  38588. if (g.reduceClipRegion (0, 0, rowComp->getWidth(), rowComp->getHeight()))
  38589. rowComp->paintEntireComponent (g);
  38590. }
  38591. }
  38592. return snapshot;
  38593. }
  38594. void ListBox::startDragAndDrop (const MouseEvent& e, const String& dragDescription)
  38595. {
  38596. DragAndDropContainer* const dragContainer
  38597. = DragAndDropContainer::findParentDragContainerFor (this);
  38598. if (dragContainer != 0)
  38599. {
  38600. int x, y;
  38601. Image* dragImage = createSnapshotOfSelectedRows (x, y);
  38602. dragImage->multiplyAllAlphas (0.6f);
  38603. MouseEvent e2 (e.getEventRelativeTo (this));
  38604. const Point<int> p (x - e2.x, y - e2.y);
  38605. dragContainer->startDragging (dragDescription, this, dragImage, true, &p);
  38606. }
  38607. else
  38608. {
  38609. // to be able to do a drag-and-drop operation, the listbox needs to
  38610. // be inside a component which is also a DragAndDropContainer.
  38611. jassertfalse
  38612. }
  38613. }
  38614. Component* ListBoxModel::refreshComponentForRow (int, bool, Component* existingComponentToUpdate)
  38615. {
  38616. (void) existingComponentToUpdate;
  38617. jassert (existingComponentToUpdate == 0); // indicates a failure in the code the recycles the components
  38618. return 0;
  38619. }
  38620. void ListBoxModel::listBoxItemClicked (int, const MouseEvent&)
  38621. {
  38622. }
  38623. void ListBoxModel::listBoxItemDoubleClicked (int, const MouseEvent&)
  38624. {
  38625. }
  38626. void ListBoxModel::backgroundClicked()
  38627. {
  38628. }
  38629. void ListBoxModel::selectedRowsChanged (int)
  38630. {
  38631. }
  38632. void ListBoxModel::deleteKeyPressed (int)
  38633. {
  38634. }
  38635. void ListBoxModel::returnKeyPressed (int)
  38636. {
  38637. }
  38638. void ListBoxModel::listWasScrolled()
  38639. {
  38640. }
  38641. const String ListBoxModel::getDragSourceDescription (const SparseSet<int>&)
  38642. {
  38643. return String::empty;
  38644. }
  38645. const String ListBoxModel::getTooltipForRow (int)
  38646. {
  38647. return String::empty;
  38648. }
  38649. END_JUCE_NAMESPACE
  38650. /*** End of inlined file: juce_ListBox.cpp ***/
  38651. /*** Start of inlined file: juce_ProgressBar.cpp ***/
  38652. BEGIN_JUCE_NAMESPACE
  38653. ProgressBar::ProgressBar (double& progress_)
  38654. : progress (progress_),
  38655. displayPercentage (true),
  38656. lastCallbackTime (0)
  38657. {
  38658. currentValue = jlimit (0.0, 1.0, progress);
  38659. }
  38660. ProgressBar::~ProgressBar()
  38661. {
  38662. }
  38663. void ProgressBar::setPercentageDisplay (const bool shouldDisplayPercentage)
  38664. {
  38665. displayPercentage = shouldDisplayPercentage;
  38666. repaint();
  38667. }
  38668. void ProgressBar::setTextToDisplay (const String& text)
  38669. {
  38670. displayPercentage = false;
  38671. displayedMessage = text;
  38672. }
  38673. void ProgressBar::lookAndFeelChanged()
  38674. {
  38675. setOpaque (findColour (backgroundColourId).isOpaque());
  38676. }
  38677. void ProgressBar::colourChanged()
  38678. {
  38679. lookAndFeelChanged();
  38680. }
  38681. void ProgressBar::paint (Graphics& g)
  38682. {
  38683. String text;
  38684. if (displayPercentage)
  38685. {
  38686. if (currentValue >= 0 && currentValue <= 1.0)
  38687. text << roundToInt (currentValue * 100.0) << T("%");
  38688. }
  38689. else
  38690. {
  38691. text = displayedMessage;
  38692. }
  38693. getLookAndFeel().drawProgressBar (g, *this,
  38694. getWidth(), getHeight(),
  38695. currentValue, text);
  38696. }
  38697. void ProgressBar::visibilityChanged()
  38698. {
  38699. if (isVisible())
  38700. startTimer (30);
  38701. else
  38702. stopTimer();
  38703. }
  38704. void ProgressBar::timerCallback()
  38705. {
  38706. double newProgress = progress;
  38707. const uint32 now = Time::getMillisecondCounter();
  38708. const int timeSinceLastCallback = (int) (now - lastCallbackTime);
  38709. lastCallbackTime = now;
  38710. if (currentValue != newProgress
  38711. || newProgress < 0 || newProgress >= 1.0
  38712. || currentMessage != displayedMessage)
  38713. {
  38714. if (currentValue < newProgress
  38715. && newProgress >= 0 && newProgress < 1.0
  38716. && currentValue >= 0 && currentValue < 1.0)
  38717. {
  38718. newProgress = jmin (currentValue + 0.0008 * timeSinceLastCallback,
  38719. newProgress);
  38720. }
  38721. currentValue = newProgress;
  38722. currentMessage = displayedMessage;
  38723. repaint();
  38724. }
  38725. }
  38726. END_JUCE_NAMESPACE
  38727. /*** End of inlined file: juce_ProgressBar.cpp ***/
  38728. /*** Start of inlined file: juce_Slider.cpp ***/
  38729. BEGIN_JUCE_NAMESPACE
  38730. class SliderPopupDisplayComponent : public BubbleComponent
  38731. {
  38732. public:
  38733. SliderPopupDisplayComponent (Slider* const owner_)
  38734. : owner (owner_),
  38735. font (15.0f, Font::bold)
  38736. {
  38737. setAlwaysOnTop (true);
  38738. }
  38739. ~SliderPopupDisplayComponent()
  38740. {
  38741. }
  38742. void paintContent (Graphics& g, int w, int h)
  38743. {
  38744. g.setFont (font);
  38745. g.setColour (Colours::black);
  38746. g.drawFittedText (text, 0, 0, w, h, Justification::centred, 1);
  38747. }
  38748. void getContentSize (int& w, int& h)
  38749. {
  38750. w = font.getStringWidth (text) + 18;
  38751. h = (int) (font.getHeight() * 1.6f);
  38752. }
  38753. void updatePosition (const String& newText)
  38754. {
  38755. if (text != newText)
  38756. {
  38757. text = newText;
  38758. repaint();
  38759. }
  38760. BubbleComponent::setPosition (owner);
  38761. }
  38762. juce_UseDebuggingNewOperator
  38763. private:
  38764. Slider* owner;
  38765. Font font;
  38766. String text;
  38767. SliderPopupDisplayComponent (const SliderPopupDisplayComponent&);
  38768. SliderPopupDisplayComponent& operator= (const SliderPopupDisplayComponent&);
  38769. };
  38770. Slider::Slider (const String& name)
  38771. : Component (name),
  38772. lastCurrentValue (0),
  38773. lastValueMin (0),
  38774. lastValueMax (0),
  38775. minimum (0),
  38776. maximum (10),
  38777. interval (0),
  38778. skewFactor (1.0),
  38779. velocityModeSensitivity (1.0),
  38780. velocityModeOffset (0.0),
  38781. velocityModeThreshold (1),
  38782. rotaryStart (float_Pi * 1.2f),
  38783. rotaryEnd (float_Pi * 2.8f),
  38784. numDecimalPlaces (7),
  38785. sliderRegionStart (0),
  38786. sliderRegionSize (1),
  38787. sliderBeingDragged (-1),
  38788. pixelsForFullDragExtent (250),
  38789. style (LinearHorizontal),
  38790. textBoxPos (TextBoxLeft),
  38791. textBoxWidth (80),
  38792. textBoxHeight (20),
  38793. incDecButtonMode (incDecButtonsNotDraggable),
  38794. editableText (true),
  38795. doubleClickToValue (false),
  38796. isVelocityBased (false),
  38797. userKeyOverridesVelocity (true),
  38798. rotaryStop (true),
  38799. incDecButtonsSideBySide (false),
  38800. sendChangeOnlyOnRelease (false),
  38801. popupDisplayEnabled (false),
  38802. menuEnabled (false),
  38803. menuShown (false),
  38804. scrollWheelEnabled (true),
  38805. snapsToMousePos (true),
  38806. valueBox (0),
  38807. incButton (0),
  38808. decButton (0),
  38809. popupDisplay (0),
  38810. parentForPopupDisplay (0)
  38811. {
  38812. setWantsKeyboardFocus (false);
  38813. setRepaintsOnMouseActivity (true);
  38814. lookAndFeelChanged();
  38815. updateText();
  38816. currentValue.addListener (this);
  38817. valueMin.addListener (this);
  38818. valueMax.addListener (this);
  38819. }
  38820. Slider::~Slider()
  38821. {
  38822. currentValue.removeListener (this);
  38823. valueMin.removeListener (this);
  38824. valueMax.removeListener (this);
  38825. popupDisplay = 0;
  38826. deleteAllChildren();
  38827. }
  38828. void Slider::handleAsyncUpdate()
  38829. {
  38830. cancelPendingUpdate();
  38831. Component::BailOutChecker checker (this);
  38832. listeners.callChecked (checker, &SliderListener::sliderValueChanged, this);
  38833. }
  38834. void Slider::sendDragStart()
  38835. {
  38836. startedDragging();
  38837. Component::BailOutChecker checker (this);
  38838. listeners.callChecked (checker, &SliderListener::sliderDragStarted, this);
  38839. }
  38840. void Slider::sendDragEnd()
  38841. {
  38842. stoppedDragging();
  38843. sliderBeingDragged = -1;
  38844. Component::BailOutChecker checker (this);
  38845. listeners.callChecked (checker, &SliderListener::sliderDragEnded, this);
  38846. }
  38847. void Slider::addListener (SliderListener* const listener)
  38848. {
  38849. listeners.add (listener);
  38850. }
  38851. void Slider::removeListener (SliderListener* const listener)
  38852. {
  38853. listeners.remove (listener);
  38854. }
  38855. void Slider::setSliderStyle (const SliderStyle newStyle)
  38856. {
  38857. if (style != newStyle)
  38858. {
  38859. style = newStyle;
  38860. repaint();
  38861. lookAndFeelChanged();
  38862. }
  38863. }
  38864. void Slider::setRotaryParameters (const float startAngleRadians,
  38865. const float endAngleRadians,
  38866. const bool stopAtEnd)
  38867. {
  38868. // make sure the values are sensible..
  38869. jassert (rotaryStart >= 0 && rotaryEnd >= 0);
  38870. jassert (rotaryStart < float_Pi * 4.0f && rotaryEnd < float_Pi * 4.0f);
  38871. jassert (rotaryStart < rotaryEnd);
  38872. rotaryStart = startAngleRadians;
  38873. rotaryEnd = endAngleRadians;
  38874. rotaryStop = stopAtEnd;
  38875. }
  38876. void Slider::setVelocityBasedMode (const bool velBased)
  38877. {
  38878. isVelocityBased = velBased;
  38879. }
  38880. void Slider::setVelocityModeParameters (const double sensitivity,
  38881. const int threshold,
  38882. const double offset,
  38883. const bool userCanPressKeyToSwapMode)
  38884. {
  38885. jassert (threshold >= 0);
  38886. jassert (sensitivity > 0);
  38887. jassert (offset >= 0);
  38888. velocityModeSensitivity = sensitivity;
  38889. velocityModeOffset = offset;
  38890. velocityModeThreshold = threshold;
  38891. userKeyOverridesVelocity = userCanPressKeyToSwapMode;
  38892. }
  38893. void Slider::setSkewFactor (const double factor)
  38894. {
  38895. skewFactor = factor;
  38896. }
  38897. void Slider::setSkewFactorFromMidPoint (const double sliderValueToShowAtMidPoint)
  38898. {
  38899. if (maximum > minimum)
  38900. skewFactor = log (0.5) / log ((sliderValueToShowAtMidPoint - minimum)
  38901. / (maximum - minimum));
  38902. }
  38903. void Slider::setMouseDragSensitivity (const int distanceForFullScaleDrag)
  38904. {
  38905. jassert (distanceForFullScaleDrag > 0);
  38906. pixelsForFullDragExtent = distanceForFullScaleDrag;
  38907. }
  38908. void Slider::setIncDecButtonsMode (const IncDecButtonMode mode)
  38909. {
  38910. if (incDecButtonMode != mode)
  38911. {
  38912. incDecButtonMode = mode;
  38913. lookAndFeelChanged();
  38914. }
  38915. }
  38916. void Slider::setTextBoxStyle (const TextEntryBoxPosition newPosition,
  38917. const bool isReadOnly,
  38918. const int textEntryBoxWidth,
  38919. const int textEntryBoxHeight)
  38920. {
  38921. textBoxPos = newPosition;
  38922. editableText = ! isReadOnly;
  38923. textBoxWidth = textEntryBoxWidth;
  38924. textBoxHeight = textEntryBoxHeight;
  38925. repaint();
  38926. lookAndFeelChanged();
  38927. }
  38928. void Slider::setTextBoxIsEditable (const bool shouldBeEditable)
  38929. {
  38930. editableText = shouldBeEditable;
  38931. if (valueBox != 0)
  38932. valueBox->setEditable (shouldBeEditable && isEnabled());
  38933. }
  38934. void Slider::showTextBox()
  38935. {
  38936. jassert (editableText); // this should probably be avoided in read-only sliders.
  38937. if (valueBox != 0)
  38938. valueBox->showEditor();
  38939. }
  38940. void Slider::hideTextBox (const bool discardCurrentEditorContents)
  38941. {
  38942. if (valueBox != 0)
  38943. {
  38944. valueBox->hideEditor (discardCurrentEditorContents);
  38945. if (discardCurrentEditorContents)
  38946. updateText();
  38947. }
  38948. }
  38949. void Slider::setChangeNotificationOnlyOnRelease (const bool onlyNotifyOnRelease)
  38950. {
  38951. sendChangeOnlyOnRelease = onlyNotifyOnRelease;
  38952. }
  38953. void Slider::setSliderSnapsToMousePosition (const bool shouldSnapToMouse)
  38954. {
  38955. snapsToMousePos = shouldSnapToMouse;
  38956. }
  38957. void Slider::setPopupDisplayEnabled (const bool enabled,
  38958. Component* const parentComponentToUse)
  38959. {
  38960. popupDisplayEnabled = enabled;
  38961. parentForPopupDisplay = parentComponentToUse;
  38962. }
  38963. void Slider::colourChanged()
  38964. {
  38965. lookAndFeelChanged();
  38966. }
  38967. void Slider::lookAndFeelChanged()
  38968. {
  38969. const String previousTextBoxContent (valueBox != 0 ? valueBox->getText()
  38970. : getTextFromValue (currentValue.getValue()));
  38971. deleteAllChildren();
  38972. valueBox = 0;
  38973. LookAndFeel& lf = getLookAndFeel();
  38974. if (textBoxPos != NoTextBox)
  38975. {
  38976. addAndMakeVisible (valueBox = getLookAndFeel().createSliderTextBox (*this));
  38977. valueBox->setWantsKeyboardFocus (false);
  38978. valueBox->setText (previousTextBoxContent, false);
  38979. valueBox->setEditable (editableText && isEnabled());
  38980. valueBox->addListener (this);
  38981. if (style == LinearBar)
  38982. valueBox->addMouseListener (this, false);
  38983. valueBox->setTooltip (getTooltip());
  38984. }
  38985. if (style == IncDecButtons)
  38986. {
  38987. addAndMakeVisible (incButton = lf.createSliderButton (true));
  38988. incButton->addButtonListener (this);
  38989. addAndMakeVisible (decButton = lf.createSliderButton (false));
  38990. decButton->addButtonListener (this);
  38991. if (incDecButtonMode != incDecButtonsNotDraggable)
  38992. {
  38993. incButton->addMouseListener (this, false);
  38994. decButton->addMouseListener (this, false);
  38995. }
  38996. else
  38997. {
  38998. incButton->setRepeatSpeed (300, 100, 20);
  38999. incButton->addMouseListener (decButton, false);
  39000. decButton->setRepeatSpeed (300, 100, 20);
  39001. decButton->addMouseListener (incButton, false);
  39002. }
  39003. incButton->setTooltip (getTooltip());
  39004. decButton->setTooltip (getTooltip());
  39005. }
  39006. setComponentEffect (lf.getSliderEffect());
  39007. resized();
  39008. repaint();
  39009. }
  39010. void Slider::setRange (const double newMin,
  39011. const double newMax,
  39012. const double newInt)
  39013. {
  39014. if (minimum != newMin
  39015. || maximum != newMax
  39016. || interval != newInt)
  39017. {
  39018. minimum = newMin;
  39019. maximum = newMax;
  39020. interval = newInt;
  39021. // figure out the number of DPs needed to display all values at this
  39022. // interval setting.
  39023. numDecimalPlaces = 7;
  39024. if (newInt != 0)
  39025. {
  39026. int v = abs ((int) (newInt * 10000000));
  39027. while ((v % 10) == 0)
  39028. {
  39029. --numDecimalPlaces;
  39030. v /= 10;
  39031. }
  39032. }
  39033. // keep the current values inside the new range..
  39034. if (style != TwoValueHorizontal && style != TwoValueVertical)
  39035. {
  39036. setValue (getValue(), false, false);
  39037. }
  39038. else
  39039. {
  39040. setMinValue (getMinValue(), false, false);
  39041. setMaxValue (getMaxValue(), false, false);
  39042. }
  39043. updateText();
  39044. }
  39045. }
  39046. void Slider::triggerChangeMessage (const bool synchronous)
  39047. {
  39048. if (synchronous)
  39049. handleAsyncUpdate();
  39050. else
  39051. triggerAsyncUpdate();
  39052. valueChanged();
  39053. }
  39054. void Slider::valueChanged (Value& value)
  39055. {
  39056. if (value.refersToSameSourceAs (currentValue))
  39057. {
  39058. if (style != TwoValueHorizontal && style != TwoValueVertical)
  39059. setValue (currentValue.getValue(), false, false);
  39060. }
  39061. else if (value.refersToSameSourceAs (valueMin))
  39062. setMinValue (valueMin.getValue(), false, false, true);
  39063. else if (value.refersToSameSourceAs (valueMax))
  39064. setMaxValue (valueMax.getValue(), false, false, true);
  39065. }
  39066. double Slider::getValue() const
  39067. {
  39068. // for a two-value style slider, you should use the getMinValue() and getMaxValue()
  39069. // methods to get the two values.
  39070. jassert (style != TwoValueHorizontal && style != TwoValueVertical);
  39071. return currentValue.getValue();
  39072. }
  39073. void Slider::setValue (double newValue,
  39074. const bool sendUpdateMessage,
  39075. const bool sendMessageSynchronously)
  39076. {
  39077. // for a two-value style slider, you should use the setMinValue() and setMaxValue()
  39078. // methods to set the two values.
  39079. jassert (style != TwoValueHorizontal && style != TwoValueVertical);
  39080. newValue = constrainedValue (newValue);
  39081. if (style == ThreeValueHorizontal || style == ThreeValueVertical)
  39082. {
  39083. jassert ((double) valueMin.getValue() <= (double) valueMax.getValue());
  39084. newValue = jlimit ((double) valueMin.getValue(),
  39085. (double) valueMax.getValue(),
  39086. newValue);
  39087. }
  39088. if (newValue != lastCurrentValue)
  39089. {
  39090. if (valueBox != 0)
  39091. valueBox->hideEditor (true);
  39092. lastCurrentValue = newValue;
  39093. currentValue = newValue;
  39094. updateText();
  39095. repaint();
  39096. if (popupDisplay != 0)
  39097. {
  39098. static_cast <SliderPopupDisplayComponent*> (static_cast <Component*> (popupDisplay))
  39099. ->updatePosition (getTextFromValue (newValue));
  39100. popupDisplay->repaint();
  39101. }
  39102. if (sendUpdateMessage)
  39103. triggerChangeMessage (sendMessageSynchronously);
  39104. }
  39105. }
  39106. double Slider::getMinValue() const
  39107. {
  39108. // The minimum value only applies to sliders that are in two- or three-value mode.
  39109. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  39110. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  39111. return valueMin.getValue();
  39112. }
  39113. double Slider::getMaxValue() const
  39114. {
  39115. // The maximum value only applies to sliders that are in two- or three-value mode.
  39116. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  39117. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  39118. return valueMax.getValue();
  39119. }
  39120. void Slider::setMinValue (double newValue, const bool sendUpdateMessage, const bool sendMessageSynchronously, const bool allowNudgingOfOtherValues)
  39121. {
  39122. // The minimum value only applies to sliders that are in two- or three-value mode.
  39123. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  39124. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  39125. newValue = constrainedValue (newValue);
  39126. if (style == TwoValueHorizontal || style == TwoValueVertical)
  39127. {
  39128. if (allowNudgingOfOtherValues && newValue > (double) valueMax.getValue())
  39129. setMaxValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39130. newValue = jmin ((double) valueMax.getValue(), newValue);
  39131. }
  39132. else
  39133. {
  39134. if (allowNudgingOfOtherValues && newValue > lastCurrentValue)
  39135. setValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39136. newValue = jmin (lastCurrentValue, newValue);
  39137. }
  39138. if (lastValueMin != newValue)
  39139. {
  39140. lastValueMin = newValue;
  39141. valueMin = newValue;
  39142. repaint();
  39143. if (popupDisplay != 0)
  39144. {
  39145. static_cast <SliderPopupDisplayComponent*> (static_cast <Component*> (popupDisplay))
  39146. ->updatePosition (getTextFromValue (newValue));
  39147. popupDisplay->repaint();
  39148. }
  39149. if (sendUpdateMessage)
  39150. triggerChangeMessage (sendMessageSynchronously);
  39151. }
  39152. }
  39153. void Slider::setMaxValue (double newValue, const bool sendUpdateMessage, const bool sendMessageSynchronously, const bool allowNudgingOfOtherValues)
  39154. {
  39155. // The maximum value only applies to sliders that are in two- or three-value mode.
  39156. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  39157. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  39158. newValue = constrainedValue (newValue);
  39159. if (style == TwoValueHorizontal || style == TwoValueVertical)
  39160. {
  39161. if (allowNudgingOfOtherValues && newValue < (double) valueMin.getValue())
  39162. setMinValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39163. newValue = jmax ((double) valueMin.getValue(), newValue);
  39164. }
  39165. else
  39166. {
  39167. if (allowNudgingOfOtherValues && newValue < lastCurrentValue)
  39168. setValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39169. newValue = jmax (lastCurrentValue, newValue);
  39170. }
  39171. if (lastValueMax != newValue)
  39172. {
  39173. lastValueMax = newValue;
  39174. valueMax = newValue;
  39175. repaint();
  39176. if (popupDisplay != 0)
  39177. {
  39178. static_cast <SliderPopupDisplayComponent*> (static_cast <Component*> (popupDisplay))
  39179. ->updatePosition (getTextFromValue (valueMax.getValue()));
  39180. popupDisplay->repaint();
  39181. }
  39182. if (sendUpdateMessage)
  39183. triggerChangeMessage (sendMessageSynchronously);
  39184. }
  39185. }
  39186. void Slider::setDoubleClickReturnValue (const bool isDoubleClickEnabled,
  39187. const double valueToSetOnDoubleClick)
  39188. {
  39189. doubleClickToValue = isDoubleClickEnabled;
  39190. doubleClickReturnValue = valueToSetOnDoubleClick;
  39191. }
  39192. double Slider::getDoubleClickReturnValue (bool& isEnabled_) const
  39193. {
  39194. isEnabled_ = doubleClickToValue;
  39195. return doubleClickReturnValue;
  39196. }
  39197. void Slider::updateText()
  39198. {
  39199. if (valueBox != 0)
  39200. valueBox->setText (getTextFromValue (currentValue.getValue()), false);
  39201. }
  39202. void Slider::setTextValueSuffix (const String& suffix)
  39203. {
  39204. if (textSuffix != suffix)
  39205. {
  39206. textSuffix = suffix;
  39207. updateText();
  39208. }
  39209. }
  39210. const String Slider::getTextFromValue (double v)
  39211. {
  39212. if (numDecimalPlaces > 0)
  39213. return String (v, numDecimalPlaces) + textSuffix;
  39214. else
  39215. return String (roundToInt (v)) + textSuffix;
  39216. }
  39217. double Slider::getValueFromText (const String& text)
  39218. {
  39219. String t (text.trimStart());
  39220. if (t.endsWith (textSuffix))
  39221. t = t.substring (0, t.length() - textSuffix.length());
  39222. while (t.startsWithChar (T('+')))
  39223. t = t.substring (1).trimStart();
  39224. return t.initialSectionContainingOnly (T("0123456789.,-"))
  39225. .getDoubleValue();
  39226. }
  39227. double Slider::proportionOfLengthToValue (double proportion)
  39228. {
  39229. if (skewFactor != 1.0 && proportion > 0.0)
  39230. proportion = exp (log (proportion) / skewFactor);
  39231. return minimum + (maximum - minimum) * proportion;
  39232. }
  39233. double Slider::valueToProportionOfLength (double value)
  39234. {
  39235. const double n = (value - minimum) / (maximum - minimum);
  39236. return skewFactor == 1.0 ? n : pow (n, skewFactor);
  39237. }
  39238. double Slider::snapValue (double attemptedValue, const bool)
  39239. {
  39240. return attemptedValue;
  39241. }
  39242. void Slider::startedDragging()
  39243. {
  39244. }
  39245. void Slider::stoppedDragging()
  39246. {
  39247. }
  39248. void Slider::valueChanged()
  39249. {
  39250. }
  39251. void Slider::enablementChanged()
  39252. {
  39253. repaint();
  39254. }
  39255. void Slider::setPopupMenuEnabled (const bool menuEnabled_)
  39256. {
  39257. menuEnabled = menuEnabled_;
  39258. }
  39259. void Slider::setScrollWheelEnabled (const bool enabled)
  39260. {
  39261. scrollWheelEnabled = enabled;
  39262. }
  39263. void Slider::labelTextChanged (Label* label)
  39264. {
  39265. const double newValue = snapValue (getValueFromText (label->getText()), false);
  39266. if (newValue != (double) currentValue.getValue())
  39267. {
  39268. sendDragStart();
  39269. setValue (newValue, true, true);
  39270. sendDragEnd();
  39271. }
  39272. updateText(); // force a clean-up of the text, needed in case setValue() hasn't done this.
  39273. }
  39274. void Slider::buttonClicked (Button* button)
  39275. {
  39276. if (style == IncDecButtons)
  39277. {
  39278. sendDragStart();
  39279. if (button == incButton)
  39280. setValue (snapValue (getValue() + interval, false), true, true);
  39281. else if (button == decButton)
  39282. setValue (snapValue (getValue() - interval, false), true, true);
  39283. sendDragEnd();
  39284. }
  39285. }
  39286. double Slider::constrainedValue (double value) const
  39287. {
  39288. if (interval > 0)
  39289. value = minimum + interval * floor ((value - minimum) / interval + 0.5);
  39290. if (value <= minimum || maximum <= minimum)
  39291. value = minimum;
  39292. else if (value >= maximum)
  39293. value = maximum;
  39294. return value;
  39295. }
  39296. float Slider::getLinearSliderPos (const double value)
  39297. {
  39298. double sliderPosProportional;
  39299. if (maximum > minimum)
  39300. {
  39301. if (value < minimum)
  39302. {
  39303. sliderPosProportional = 0.0;
  39304. }
  39305. else if (value > maximum)
  39306. {
  39307. sliderPosProportional = 1.0;
  39308. }
  39309. else
  39310. {
  39311. sliderPosProportional = valueToProportionOfLength (value);
  39312. jassert (sliderPosProportional >= 0 && sliderPosProportional <= 1.0);
  39313. }
  39314. }
  39315. else
  39316. {
  39317. sliderPosProportional = 0.5;
  39318. }
  39319. if (isVertical() || style == IncDecButtons)
  39320. sliderPosProportional = 1.0 - sliderPosProportional;
  39321. return (float) (sliderRegionStart + sliderPosProportional * sliderRegionSize);
  39322. }
  39323. bool Slider::isHorizontal() const
  39324. {
  39325. return style == LinearHorizontal
  39326. || style == LinearBar
  39327. || style == TwoValueHorizontal
  39328. || style == ThreeValueHorizontal;
  39329. }
  39330. bool Slider::isVertical() const
  39331. {
  39332. return style == LinearVertical
  39333. || style == TwoValueVertical
  39334. || style == ThreeValueVertical;
  39335. }
  39336. bool Slider::incDecDragDirectionIsHorizontal() const
  39337. {
  39338. return incDecButtonMode == incDecButtonsDraggable_Horizontal
  39339. || (incDecButtonMode == incDecButtonsDraggable_AutoDirection && incDecButtonsSideBySide);
  39340. }
  39341. float Slider::getPositionOfValue (const double value)
  39342. {
  39343. if (isHorizontal() || isVertical())
  39344. {
  39345. return getLinearSliderPos (value);
  39346. }
  39347. else
  39348. {
  39349. jassertfalse // not a valid call on a slider that doesn't work linearly!
  39350. return 0.0f;
  39351. }
  39352. }
  39353. void Slider::paint (Graphics& g)
  39354. {
  39355. if (style != IncDecButtons)
  39356. {
  39357. if (style == Rotary || style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  39358. {
  39359. const float sliderPos = (float) valueToProportionOfLength (lastCurrentValue);
  39360. jassert (sliderPos >= 0 && sliderPos <= 1.0f);
  39361. getLookAndFeel().drawRotarySlider (g,
  39362. sliderRect.getX(),
  39363. sliderRect.getY(),
  39364. sliderRect.getWidth(),
  39365. sliderRect.getHeight(),
  39366. sliderPos,
  39367. rotaryStart, rotaryEnd,
  39368. *this);
  39369. }
  39370. else
  39371. {
  39372. getLookAndFeel().drawLinearSlider (g,
  39373. sliderRect.getX(),
  39374. sliderRect.getY(),
  39375. sliderRect.getWidth(),
  39376. sliderRect.getHeight(),
  39377. getLinearSliderPos (lastCurrentValue),
  39378. getLinearSliderPos (lastValueMin),
  39379. getLinearSliderPos (lastValueMax),
  39380. style,
  39381. *this);
  39382. }
  39383. if (style == LinearBar && valueBox == 0)
  39384. {
  39385. g.setColour (findColour (Slider::textBoxOutlineColourId));
  39386. g.drawRect (0, 0, getWidth(), getHeight(), 1);
  39387. }
  39388. }
  39389. }
  39390. void Slider::resized()
  39391. {
  39392. int minXSpace = 0;
  39393. int minYSpace = 0;
  39394. if (textBoxPos == TextBoxLeft || textBoxPos == TextBoxRight)
  39395. minXSpace = 30;
  39396. else
  39397. minYSpace = 15;
  39398. const int tbw = jmax (0, jmin (textBoxWidth, getWidth() - minXSpace));
  39399. const int tbh = jmax (0, jmin (textBoxHeight, getHeight() - minYSpace));
  39400. if (style == LinearBar)
  39401. {
  39402. if (valueBox != 0)
  39403. valueBox->setBounds (0, 0, getWidth(), getHeight());
  39404. }
  39405. else
  39406. {
  39407. if (textBoxPos == NoTextBox)
  39408. {
  39409. sliderRect.setBounds (0, 0, getWidth(), getHeight());
  39410. }
  39411. else if (textBoxPos == TextBoxLeft)
  39412. {
  39413. valueBox->setBounds (0, (getHeight() - tbh) / 2, tbw, tbh);
  39414. sliderRect.setBounds (tbw, 0, getWidth() - tbw, getHeight());
  39415. }
  39416. else if (textBoxPos == TextBoxRight)
  39417. {
  39418. valueBox->setBounds (getWidth() - tbw, (getHeight() - tbh) / 2, tbw, tbh);
  39419. sliderRect.setBounds (0, 0, getWidth() - tbw, getHeight());
  39420. }
  39421. else if (textBoxPos == TextBoxAbove)
  39422. {
  39423. valueBox->setBounds ((getWidth() - tbw) / 2, 0, tbw, tbh);
  39424. sliderRect.setBounds (0, tbh, getWidth(), getHeight() - tbh);
  39425. }
  39426. else if (textBoxPos == TextBoxBelow)
  39427. {
  39428. valueBox->setBounds ((getWidth() - tbw) / 2, getHeight() - tbh, tbw, tbh);
  39429. sliderRect.setBounds (0, 0, getWidth(), getHeight() - tbh);
  39430. }
  39431. }
  39432. const int indent = getLookAndFeel().getSliderThumbRadius (*this);
  39433. if (style == LinearBar)
  39434. {
  39435. const int barIndent = 1;
  39436. sliderRegionStart = barIndent;
  39437. sliderRegionSize = getWidth() - barIndent * 2;
  39438. sliderRect.setBounds (sliderRegionStart, barIndent,
  39439. sliderRegionSize, getHeight() - barIndent * 2);
  39440. }
  39441. else if (isHorizontal())
  39442. {
  39443. sliderRegionStart = sliderRect.getX() + indent;
  39444. sliderRegionSize = jmax (1, sliderRect.getWidth() - indent * 2);
  39445. sliderRect.setBounds (sliderRegionStart, sliderRect.getY(),
  39446. sliderRegionSize, sliderRect.getHeight());
  39447. }
  39448. else if (isVertical())
  39449. {
  39450. sliderRegionStart = sliderRect.getY() + indent;
  39451. sliderRegionSize = jmax (1, sliderRect.getHeight() - indent * 2);
  39452. sliderRect.setBounds (sliderRect.getX(), sliderRegionStart,
  39453. sliderRect.getWidth(), sliderRegionSize);
  39454. }
  39455. else
  39456. {
  39457. sliderRegionStart = 0;
  39458. sliderRegionSize = 100;
  39459. }
  39460. if (style == IncDecButtons)
  39461. {
  39462. Rectangle<int> buttonRect (sliderRect);
  39463. if (textBoxPos == TextBoxLeft || textBoxPos == TextBoxRight)
  39464. buttonRect.expand (-2, 0);
  39465. else
  39466. buttonRect.expand (0, -2);
  39467. incDecButtonsSideBySide = buttonRect.getWidth() > buttonRect.getHeight();
  39468. if (incDecButtonsSideBySide)
  39469. {
  39470. decButton->setBounds (buttonRect.getX(),
  39471. buttonRect.getY(),
  39472. buttonRect.getWidth() / 2,
  39473. buttonRect.getHeight());
  39474. decButton->setConnectedEdges (Button::ConnectedOnRight);
  39475. incButton->setBounds (buttonRect.getCentreX(),
  39476. buttonRect.getY(),
  39477. buttonRect.getWidth() / 2,
  39478. buttonRect.getHeight());
  39479. incButton->setConnectedEdges (Button::ConnectedOnLeft);
  39480. }
  39481. else
  39482. {
  39483. incButton->setBounds (buttonRect.getX(),
  39484. buttonRect.getY(),
  39485. buttonRect.getWidth(),
  39486. buttonRect.getHeight() / 2);
  39487. incButton->setConnectedEdges (Button::ConnectedOnBottom);
  39488. decButton->setBounds (buttonRect.getX(),
  39489. buttonRect.getCentreY(),
  39490. buttonRect.getWidth(),
  39491. buttonRect.getHeight() / 2);
  39492. decButton->setConnectedEdges (Button::ConnectedOnTop);
  39493. }
  39494. }
  39495. }
  39496. void Slider::focusOfChildComponentChanged (FocusChangeType)
  39497. {
  39498. repaint();
  39499. }
  39500. void Slider::mouseDown (const MouseEvent& e)
  39501. {
  39502. mouseWasHidden = false;
  39503. incDecDragged = false;
  39504. mouseXWhenLastDragged = e.x;
  39505. mouseYWhenLastDragged = e.y;
  39506. mouseDragStartX = e.getMouseDownX();
  39507. mouseDragStartY = e.getMouseDownY();
  39508. if (isEnabled())
  39509. {
  39510. if (e.mods.isPopupMenu() && menuEnabled)
  39511. {
  39512. menuShown = true;
  39513. PopupMenu m;
  39514. m.setLookAndFeel (&getLookAndFeel());
  39515. m.addItem (1, TRANS ("velocity-sensitive mode"), true, isVelocityBased);
  39516. m.addSeparator();
  39517. if (style == Rotary || style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  39518. {
  39519. PopupMenu rotaryMenu;
  39520. rotaryMenu.addItem (2, TRANS ("use circular dragging"), true, style == Rotary);
  39521. rotaryMenu.addItem (3, TRANS ("use left-right dragging"), true, style == RotaryHorizontalDrag);
  39522. rotaryMenu.addItem (4, TRANS ("use up-down dragging"), true, style == RotaryVerticalDrag);
  39523. m.addSubMenu (TRANS ("rotary mode"), rotaryMenu);
  39524. }
  39525. const int r = m.show();
  39526. if (r == 1)
  39527. {
  39528. setVelocityBasedMode (! isVelocityBased);
  39529. }
  39530. else if (r == 2)
  39531. {
  39532. setSliderStyle (Rotary);
  39533. }
  39534. else if (r == 3)
  39535. {
  39536. setSliderStyle (RotaryHorizontalDrag);
  39537. }
  39538. else if (r == 4)
  39539. {
  39540. setSliderStyle (RotaryVerticalDrag);
  39541. }
  39542. }
  39543. else if (maximum > minimum)
  39544. {
  39545. menuShown = false;
  39546. if (valueBox != 0)
  39547. valueBox->hideEditor (true);
  39548. sliderBeingDragged = 0;
  39549. if (style == TwoValueHorizontal
  39550. || style == TwoValueVertical
  39551. || style == ThreeValueHorizontal
  39552. || style == ThreeValueVertical)
  39553. {
  39554. const float mousePos = (float) (isVertical() ? e.y : e.x);
  39555. const float normalPosDistance = fabsf (getLinearSliderPos (currentValue.getValue()) - mousePos);
  39556. const float minPosDistance = fabsf (getLinearSliderPos (valueMin.getValue()) - 0.1f - mousePos);
  39557. const float maxPosDistance = fabsf (getLinearSliderPos (valueMax.getValue()) + 0.1f - mousePos);
  39558. if (style == TwoValueHorizontal || style == TwoValueVertical)
  39559. {
  39560. if (maxPosDistance <= minPosDistance)
  39561. sliderBeingDragged = 2;
  39562. else
  39563. sliderBeingDragged = 1;
  39564. }
  39565. else if (style == ThreeValueHorizontal || style == ThreeValueVertical)
  39566. {
  39567. if (normalPosDistance >= minPosDistance && maxPosDistance >= minPosDistance)
  39568. sliderBeingDragged = 1;
  39569. else if (normalPosDistance >= maxPosDistance)
  39570. sliderBeingDragged = 2;
  39571. }
  39572. }
  39573. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  39574. lastAngle = rotaryStart + (rotaryEnd - rotaryStart)
  39575. * valueToProportionOfLength (currentValue.getValue());
  39576. valueWhenLastDragged = ((sliderBeingDragged == 2) ? valueMax
  39577. : ((sliderBeingDragged == 1) ? valueMin
  39578. : currentValue)).getValue();
  39579. valueOnMouseDown = valueWhenLastDragged;
  39580. if (popupDisplayEnabled)
  39581. {
  39582. SliderPopupDisplayComponent* const popup = new SliderPopupDisplayComponent (this);
  39583. popupDisplay = popup;
  39584. if (parentForPopupDisplay != 0)
  39585. {
  39586. parentForPopupDisplay->addChildComponent (popup);
  39587. }
  39588. else
  39589. {
  39590. popup->addToDesktop (0);
  39591. }
  39592. popup->setVisible (true);
  39593. }
  39594. sendDragStart();
  39595. mouseDrag (e);
  39596. }
  39597. }
  39598. }
  39599. void Slider::mouseUp (const MouseEvent&)
  39600. {
  39601. if (isEnabled()
  39602. && (! menuShown)
  39603. && (maximum > minimum)
  39604. && (style != IncDecButtons || incDecDragged))
  39605. {
  39606. restoreMouseIfHidden();
  39607. if (sendChangeOnlyOnRelease && valueOnMouseDown != (double) currentValue.getValue())
  39608. triggerChangeMessage (false);
  39609. sendDragEnd();
  39610. popupDisplay = 0;
  39611. if (style == IncDecButtons)
  39612. {
  39613. incButton->setState (Button::buttonNormal);
  39614. decButton->setState (Button::buttonNormal);
  39615. }
  39616. }
  39617. }
  39618. void Slider::restoreMouseIfHidden()
  39619. {
  39620. if (mouseWasHidden)
  39621. {
  39622. mouseWasHidden = false;
  39623. for (int i = Desktop::getInstance().getNumMouseSources(); --i >= 0;)
  39624. Desktop::getInstance().getMouseSource(i)->enableUnboundedMouseMovement (false);
  39625. const double pos = (sliderBeingDragged == 2) ? getMaxValue()
  39626. : ((sliderBeingDragged == 1) ? getMinValue()
  39627. : (double) currentValue.getValue());
  39628. Point<int> mousePos;
  39629. if (style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  39630. {
  39631. mousePos = Desktop::getLastMouseDownPosition();
  39632. if (style == RotaryHorizontalDrag)
  39633. {
  39634. const double posDiff = valueToProportionOfLength (pos) - valueToProportionOfLength (valueOnMouseDown);
  39635. mousePos += Point<int> (roundToInt (pixelsForFullDragExtent * posDiff), 0);
  39636. }
  39637. else
  39638. {
  39639. const double posDiff = valueToProportionOfLength (valueOnMouseDown) - valueToProportionOfLength (pos);
  39640. mousePos += Point<int> (0, roundToInt (pixelsForFullDragExtent * posDiff));
  39641. }
  39642. }
  39643. else
  39644. {
  39645. const int pixelPos = (int) getLinearSliderPos (pos);
  39646. mousePos = relativePositionToGlobal (Point<int> (isHorizontal() ? pixelPos : (getWidth() / 2),
  39647. isVertical() ? pixelPos : (getHeight() / 2)));
  39648. }
  39649. Desktop::setMousePosition (mousePos);
  39650. }
  39651. }
  39652. void Slider::modifierKeysChanged (const ModifierKeys& modifiers)
  39653. {
  39654. if (isEnabled()
  39655. && style != IncDecButtons
  39656. && style != Rotary
  39657. && isVelocityBased == modifiers.isAnyModifierKeyDown())
  39658. {
  39659. restoreMouseIfHidden();
  39660. }
  39661. }
  39662. static double smallestAngleBetween (double a1, double a2)
  39663. {
  39664. return jmin (fabs (a1 - a2),
  39665. fabs (a1 + double_Pi * 2.0 - a2),
  39666. fabs (a2 + double_Pi * 2.0 - a1));
  39667. }
  39668. void Slider::mouseDrag (const MouseEvent& e)
  39669. {
  39670. if (isEnabled()
  39671. && (! menuShown)
  39672. && (maximum > minimum))
  39673. {
  39674. if (style == Rotary)
  39675. {
  39676. int dx = e.x - sliderRect.getCentreX();
  39677. int dy = e.y - sliderRect.getCentreY();
  39678. if (dx * dx + dy * dy > 25)
  39679. {
  39680. double angle = atan2 ((double) dx, (double) -dy);
  39681. while (angle < 0.0)
  39682. angle += double_Pi * 2.0;
  39683. if (rotaryStop && ! e.mouseWasClicked())
  39684. {
  39685. if (fabs (angle - lastAngle) > double_Pi)
  39686. {
  39687. if (angle >= lastAngle)
  39688. angle -= double_Pi * 2.0;
  39689. else
  39690. angle += double_Pi * 2.0;
  39691. }
  39692. if (angle >= lastAngle)
  39693. angle = jmin (angle, (double) jmax (rotaryStart, rotaryEnd));
  39694. else
  39695. angle = jmax (angle, (double) jmin (rotaryStart, rotaryEnd));
  39696. }
  39697. else
  39698. {
  39699. while (angle < rotaryStart)
  39700. angle += double_Pi * 2.0;
  39701. if (angle > rotaryEnd)
  39702. {
  39703. if (smallestAngleBetween (angle, rotaryStart) <= smallestAngleBetween (angle, rotaryEnd))
  39704. angle = rotaryStart;
  39705. else
  39706. angle = rotaryEnd;
  39707. }
  39708. }
  39709. const double proportion = (angle - rotaryStart) / (rotaryEnd - rotaryStart);
  39710. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, proportion));
  39711. lastAngle = angle;
  39712. }
  39713. }
  39714. else
  39715. {
  39716. if (style == LinearBar && e.mouseWasClicked()
  39717. && valueBox != 0 && valueBox->isEditable())
  39718. return;
  39719. if (style == IncDecButtons && ! incDecDragged)
  39720. {
  39721. if (e.getDistanceFromDragStart() < 10 || e.mouseWasClicked())
  39722. return;
  39723. incDecDragged = true;
  39724. mouseDragStartX = e.x;
  39725. mouseDragStartY = e.y;
  39726. }
  39727. if ((isVelocityBased == (userKeyOverridesVelocity ? e.mods.testFlags (ModifierKeys::ctrlModifier | ModifierKeys::commandModifier | ModifierKeys::altModifier)
  39728. : false))
  39729. || ((maximum - minimum) / sliderRegionSize < interval))
  39730. {
  39731. const int mousePos = (isHorizontal() || style == RotaryHorizontalDrag) ? e.x : e.y;
  39732. double scaledMousePos = (mousePos - sliderRegionStart) / (double) sliderRegionSize;
  39733. if (style == RotaryHorizontalDrag
  39734. || style == RotaryVerticalDrag
  39735. || style == IncDecButtons
  39736. || ((style == LinearHorizontal || style == LinearVertical || style == LinearBar)
  39737. && ! snapsToMousePos))
  39738. {
  39739. const int mouseDiff = (style == RotaryHorizontalDrag
  39740. || style == LinearHorizontal
  39741. || style == LinearBar
  39742. || (style == IncDecButtons && incDecDragDirectionIsHorizontal()))
  39743. ? e.x - mouseDragStartX
  39744. : mouseDragStartY - e.y;
  39745. double newPos = valueToProportionOfLength (valueOnMouseDown)
  39746. + mouseDiff * (1.0 / pixelsForFullDragExtent);
  39747. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, newPos));
  39748. if (style == IncDecButtons)
  39749. {
  39750. incButton->setState (mouseDiff < 0 ? Button::buttonNormal : Button::buttonDown);
  39751. decButton->setState (mouseDiff > 0 ? Button::buttonNormal : Button::buttonDown);
  39752. }
  39753. }
  39754. else
  39755. {
  39756. if (isVertical())
  39757. scaledMousePos = 1.0 - scaledMousePos;
  39758. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, scaledMousePos));
  39759. }
  39760. }
  39761. else
  39762. {
  39763. const int mouseDiff = (isHorizontal() || style == RotaryHorizontalDrag
  39764. || (style == IncDecButtons && incDecDragDirectionIsHorizontal()))
  39765. ? e.x - mouseXWhenLastDragged
  39766. : e.y - mouseYWhenLastDragged;
  39767. const double maxSpeed = jmax (200, sliderRegionSize);
  39768. double speed = jlimit (0.0, maxSpeed, (double) abs (mouseDiff));
  39769. if (speed != 0)
  39770. {
  39771. speed = 0.2 * velocityModeSensitivity
  39772. * (1.0 + sin (double_Pi * (1.5 + jmin (0.5, velocityModeOffset
  39773. + jmax (0.0, (double) (speed - velocityModeThreshold))
  39774. / maxSpeed))));
  39775. if (mouseDiff < 0)
  39776. speed = -speed;
  39777. if (isVertical() || style == RotaryVerticalDrag
  39778. || (style == IncDecButtons && ! incDecDragDirectionIsHorizontal()))
  39779. speed = -speed;
  39780. const double currentPos = valueToProportionOfLength (valueWhenLastDragged);
  39781. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, currentPos + speed));
  39782. e.source.enableUnboundedMouseMovement (true, false);
  39783. mouseWasHidden = true;
  39784. }
  39785. }
  39786. }
  39787. valueWhenLastDragged = jlimit (minimum, maximum, valueWhenLastDragged);
  39788. if (sliderBeingDragged == 0)
  39789. {
  39790. setValue (snapValue (valueWhenLastDragged, true),
  39791. ! sendChangeOnlyOnRelease, true);
  39792. }
  39793. else if (sliderBeingDragged == 1)
  39794. {
  39795. setMinValue (snapValue (valueWhenLastDragged, true),
  39796. ! sendChangeOnlyOnRelease, false, true);
  39797. if (e.mods.isShiftDown())
  39798. setMaxValue (getMinValue() + minMaxDiff, false, false, true);
  39799. else
  39800. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  39801. }
  39802. else
  39803. {
  39804. jassert (sliderBeingDragged == 2);
  39805. setMaxValue (snapValue (valueWhenLastDragged, true),
  39806. ! sendChangeOnlyOnRelease, false, true);
  39807. if (e.mods.isShiftDown())
  39808. setMinValue (getMaxValue() - minMaxDiff, false, false, true);
  39809. else
  39810. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  39811. }
  39812. mouseXWhenLastDragged = e.x;
  39813. mouseYWhenLastDragged = e.y;
  39814. }
  39815. }
  39816. void Slider::mouseDoubleClick (const MouseEvent&)
  39817. {
  39818. if (doubleClickToValue
  39819. && isEnabled()
  39820. && style != IncDecButtons
  39821. && minimum <= doubleClickReturnValue
  39822. && maximum >= doubleClickReturnValue)
  39823. {
  39824. sendDragStart();
  39825. setValue (doubleClickReturnValue, true, true);
  39826. sendDragEnd();
  39827. }
  39828. }
  39829. void Slider::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  39830. {
  39831. if (scrollWheelEnabled && isEnabled()
  39832. && style != TwoValueHorizontal
  39833. && style != TwoValueVertical)
  39834. {
  39835. if (maximum > minimum && ! e.mods.isAnyMouseButtonDown())
  39836. {
  39837. if (valueBox != 0)
  39838. valueBox->hideEditor (false);
  39839. const double value = (double) currentValue.getValue();
  39840. const double proportionDelta = (wheelIncrementX != 0 ? -wheelIncrementX : wheelIncrementY) * 0.15f;
  39841. const double currentPos = valueToProportionOfLength (value);
  39842. const double newValue = proportionOfLengthToValue (jlimit (0.0, 1.0, currentPos + proportionDelta));
  39843. double delta = (newValue != value)
  39844. ? jmax (fabs (newValue - value), interval) : 0;
  39845. if (value > newValue)
  39846. delta = -delta;
  39847. sendDragStart();
  39848. setValue (snapValue (value + delta, false), true, true);
  39849. sendDragEnd();
  39850. }
  39851. }
  39852. else
  39853. {
  39854. Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
  39855. }
  39856. }
  39857. void SliderListener::sliderDragStarted (Slider*)
  39858. {
  39859. }
  39860. void SliderListener::sliderDragEnded (Slider*)
  39861. {
  39862. }
  39863. END_JUCE_NAMESPACE
  39864. /*** End of inlined file: juce_Slider.cpp ***/
  39865. /*** Start of inlined file: juce_TableHeaderComponent.cpp ***/
  39866. BEGIN_JUCE_NAMESPACE
  39867. class DragOverlayComp : public Component
  39868. {
  39869. public:
  39870. DragOverlayComp (Image* const image_)
  39871. : image (image_)
  39872. {
  39873. image->multiplyAllAlphas (0.8f);
  39874. setAlwaysOnTop (true);
  39875. }
  39876. ~DragOverlayComp()
  39877. {
  39878. }
  39879. void paint (Graphics& g)
  39880. {
  39881. g.drawImageAt (image, 0, 0);
  39882. }
  39883. private:
  39884. ScopedPointer <Image> image;
  39885. DragOverlayComp (const DragOverlayComp&);
  39886. DragOverlayComp& operator= (const DragOverlayComp&);
  39887. };
  39888. TableHeaderComponent::TableHeaderComponent()
  39889. : columnsChanged (false),
  39890. columnsResized (false),
  39891. sortChanged (false),
  39892. menuActive (true),
  39893. stretchToFit (false),
  39894. columnIdBeingResized (0),
  39895. columnIdBeingDragged (0),
  39896. columnIdUnderMouse (0),
  39897. lastDeliberateWidth (0)
  39898. {
  39899. }
  39900. TableHeaderComponent::~TableHeaderComponent()
  39901. {
  39902. dragOverlayComp = 0;
  39903. }
  39904. void TableHeaderComponent::setPopupMenuActive (const bool hasMenu)
  39905. {
  39906. menuActive = hasMenu;
  39907. }
  39908. bool TableHeaderComponent::isPopupMenuActive() const { return menuActive; }
  39909. int TableHeaderComponent::getNumColumns (const bool onlyCountVisibleColumns) const
  39910. {
  39911. if (onlyCountVisibleColumns)
  39912. {
  39913. int num = 0;
  39914. for (int i = columns.size(); --i >= 0;)
  39915. if (columns.getUnchecked(i)->isVisible())
  39916. ++num;
  39917. return num;
  39918. }
  39919. else
  39920. {
  39921. return columns.size();
  39922. }
  39923. }
  39924. const String TableHeaderComponent::getColumnName (const int columnId) const
  39925. {
  39926. const ColumnInfo* const ci = getInfoForId (columnId);
  39927. return ci != 0 ? ci->name : String::empty;
  39928. }
  39929. void TableHeaderComponent::setColumnName (const int columnId, const String& newName)
  39930. {
  39931. ColumnInfo* const ci = getInfoForId (columnId);
  39932. if (ci != 0 && ci->name != newName)
  39933. {
  39934. ci->name = newName;
  39935. sendColumnsChanged();
  39936. }
  39937. }
  39938. void TableHeaderComponent::addColumn (const String& columnName,
  39939. const int columnId,
  39940. const int width,
  39941. const int minimumWidth,
  39942. const int maximumWidth,
  39943. const int propertyFlags,
  39944. const int insertIndex)
  39945. {
  39946. // can't have a duplicate or null ID!
  39947. jassert (columnId != 0 && getIndexOfColumnId (columnId, false) < 0);
  39948. jassert (width > 0);
  39949. ColumnInfo* const ci = new ColumnInfo();
  39950. ci->name = columnName;
  39951. ci->id = columnId;
  39952. ci->width = width;
  39953. ci->lastDeliberateWidth = width;
  39954. ci->minimumWidth = minimumWidth;
  39955. ci->maximumWidth = maximumWidth;
  39956. if (ci->maximumWidth < 0)
  39957. ci->maximumWidth = std::numeric_limits<int>::max();
  39958. jassert (ci->maximumWidth >= ci->minimumWidth);
  39959. ci->propertyFlags = propertyFlags;
  39960. columns.insert (insertIndex, ci);
  39961. sendColumnsChanged();
  39962. }
  39963. void TableHeaderComponent::removeColumn (const int columnIdToRemove)
  39964. {
  39965. const int index = getIndexOfColumnId (columnIdToRemove, false);
  39966. if (index >= 0)
  39967. {
  39968. columns.remove (index);
  39969. sortChanged = true;
  39970. sendColumnsChanged();
  39971. }
  39972. }
  39973. void TableHeaderComponent::removeAllColumns()
  39974. {
  39975. if (columns.size() > 0)
  39976. {
  39977. columns.clear();
  39978. sendColumnsChanged();
  39979. }
  39980. }
  39981. void TableHeaderComponent::moveColumn (const int columnId, int newIndex)
  39982. {
  39983. const int currentIndex = getIndexOfColumnId (columnId, false);
  39984. newIndex = visibleIndexToTotalIndex (newIndex);
  39985. if (columns [currentIndex] != 0 && currentIndex != newIndex)
  39986. {
  39987. columns.move (currentIndex, newIndex);
  39988. sendColumnsChanged();
  39989. }
  39990. }
  39991. int TableHeaderComponent::getColumnWidth (const int columnId) const
  39992. {
  39993. const ColumnInfo* const ci = getInfoForId (columnId);
  39994. return ci != 0 ? ci->width : 0;
  39995. }
  39996. void TableHeaderComponent::setColumnWidth (const int columnId, const int newWidth)
  39997. {
  39998. ColumnInfo* const ci = getInfoForId (columnId);
  39999. if (ci != 0 && ci->width != newWidth)
  40000. {
  40001. const int numColumns = getNumColumns (true);
  40002. ci->lastDeliberateWidth = ci->width
  40003. = jlimit (ci->minimumWidth, ci->maximumWidth, newWidth);
  40004. if (stretchToFit)
  40005. {
  40006. const int index = getIndexOfColumnId (columnId, true) + 1;
  40007. if (((unsigned int) index) < (unsigned int) numColumns)
  40008. {
  40009. const int x = getColumnPosition (index).getX();
  40010. if (lastDeliberateWidth == 0)
  40011. lastDeliberateWidth = getTotalWidth();
  40012. resizeColumnsToFit (visibleIndexToTotalIndex (index), lastDeliberateWidth - x);
  40013. }
  40014. }
  40015. repaint();
  40016. columnsResized = true;
  40017. triggerAsyncUpdate();
  40018. }
  40019. }
  40020. int TableHeaderComponent::getIndexOfColumnId (const int columnId, const bool onlyCountVisibleColumns) const
  40021. {
  40022. int n = 0;
  40023. for (int i = 0; i < columns.size(); ++i)
  40024. {
  40025. if ((! onlyCountVisibleColumns) || columns.getUnchecked(i)->isVisible())
  40026. {
  40027. if (columns.getUnchecked(i)->id == columnId)
  40028. return n;
  40029. ++n;
  40030. }
  40031. }
  40032. return -1;
  40033. }
  40034. int TableHeaderComponent::getColumnIdOfIndex (int index, const bool onlyCountVisibleColumns) const
  40035. {
  40036. if (onlyCountVisibleColumns)
  40037. index = visibleIndexToTotalIndex (index);
  40038. const ColumnInfo* const ci = columns [index];
  40039. return (ci != 0) ? ci->id : 0;
  40040. }
  40041. const Rectangle<int> TableHeaderComponent::getColumnPosition (const int index) const
  40042. {
  40043. int x = 0, width = 0, n = 0;
  40044. for (int i = 0; i < columns.size(); ++i)
  40045. {
  40046. x += width;
  40047. if (columns.getUnchecked(i)->isVisible())
  40048. {
  40049. width = columns.getUnchecked(i)->width;
  40050. if (n++ == index)
  40051. break;
  40052. }
  40053. else
  40054. {
  40055. width = 0;
  40056. }
  40057. }
  40058. return Rectangle<int> (x, 0, width, getHeight());
  40059. }
  40060. int TableHeaderComponent::getColumnIdAtX (const int xToFind) const
  40061. {
  40062. if (xToFind >= 0)
  40063. {
  40064. int x = 0;
  40065. for (int i = 0; i < columns.size(); ++i)
  40066. {
  40067. const ColumnInfo* const ci = columns.getUnchecked(i);
  40068. if (ci->isVisible())
  40069. {
  40070. x += ci->width;
  40071. if (xToFind < x)
  40072. return ci->id;
  40073. }
  40074. }
  40075. }
  40076. return 0;
  40077. }
  40078. int TableHeaderComponent::getTotalWidth() const
  40079. {
  40080. int w = 0;
  40081. for (int i = columns.size(); --i >= 0;)
  40082. if (columns.getUnchecked(i)->isVisible())
  40083. w += columns.getUnchecked(i)->width;
  40084. return w;
  40085. }
  40086. void TableHeaderComponent::setStretchToFitActive (const bool shouldStretchToFit)
  40087. {
  40088. stretchToFit = shouldStretchToFit;
  40089. lastDeliberateWidth = getTotalWidth();
  40090. resized();
  40091. }
  40092. bool TableHeaderComponent::isStretchToFitActive() const
  40093. {
  40094. return stretchToFit;
  40095. }
  40096. void TableHeaderComponent::resizeAllColumnsToFit (int targetTotalWidth)
  40097. {
  40098. if (stretchToFit && getWidth() > 0
  40099. && columnIdBeingResized == 0 && columnIdBeingDragged == 0)
  40100. {
  40101. lastDeliberateWidth = targetTotalWidth;
  40102. resizeColumnsToFit (0, targetTotalWidth);
  40103. }
  40104. }
  40105. void TableHeaderComponent::resizeColumnsToFit (int firstColumnIndex, int targetTotalWidth)
  40106. {
  40107. targetTotalWidth = jmax (targetTotalWidth, 0);
  40108. StretchableObjectResizer sor;
  40109. int i;
  40110. for (i = firstColumnIndex; i < columns.size(); ++i)
  40111. {
  40112. ColumnInfo* const ci = columns.getUnchecked(i);
  40113. if (ci->isVisible())
  40114. sor.addItem (ci->lastDeliberateWidth, ci->minimumWidth, ci->maximumWidth);
  40115. }
  40116. sor.resizeToFit (targetTotalWidth);
  40117. int visIndex = 0;
  40118. for (i = firstColumnIndex; i < columns.size(); ++i)
  40119. {
  40120. ColumnInfo* const ci = columns.getUnchecked(i);
  40121. if (ci->isVisible())
  40122. {
  40123. const int newWidth = jlimit (ci->minimumWidth, ci->maximumWidth,
  40124. (int) floor (sor.getItemSize (visIndex++)));
  40125. if (newWidth != ci->width)
  40126. {
  40127. ci->width = newWidth;
  40128. repaint();
  40129. columnsResized = true;
  40130. triggerAsyncUpdate();
  40131. }
  40132. }
  40133. }
  40134. }
  40135. void TableHeaderComponent::setColumnVisible (const int columnId, const bool shouldBeVisible)
  40136. {
  40137. ColumnInfo* const ci = getInfoForId (columnId);
  40138. if (ci != 0 && shouldBeVisible != ci->isVisible())
  40139. {
  40140. if (shouldBeVisible)
  40141. ci->propertyFlags |= visible;
  40142. else
  40143. ci->propertyFlags &= ~visible;
  40144. sendColumnsChanged();
  40145. resized();
  40146. }
  40147. }
  40148. bool TableHeaderComponent::isColumnVisible (const int columnId) const
  40149. {
  40150. const ColumnInfo* const ci = getInfoForId (columnId);
  40151. return ci != 0 && ci->isVisible();
  40152. }
  40153. void TableHeaderComponent::setSortColumnId (const int columnId, const bool sortForwards)
  40154. {
  40155. if (getSortColumnId() != columnId || isSortedForwards() != sortForwards)
  40156. {
  40157. for (int i = columns.size(); --i >= 0;)
  40158. columns.getUnchecked(i)->propertyFlags &= ~(sortedForwards | sortedBackwards);
  40159. ColumnInfo* const ci = getInfoForId (columnId);
  40160. if (ci != 0)
  40161. ci->propertyFlags |= (sortForwards ? sortedForwards : sortedBackwards);
  40162. reSortTable();
  40163. }
  40164. }
  40165. int TableHeaderComponent::getSortColumnId() const
  40166. {
  40167. for (int i = columns.size(); --i >= 0;)
  40168. if ((columns.getUnchecked(i)->propertyFlags & (sortedForwards | sortedBackwards)) != 0)
  40169. return columns.getUnchecked(i)->id;
  40170. return 0;
  40171. }
  40172. bool TableHeaderComponent::isSortedForwards() const
  40173. {
  40174. for (int i = columns.size(); --i >= 0;)
  40175. if ((columns.getUnchecked(i)->propertyFlags & (sortedForwards | sortedBackwards)) != 0)
  40176. return (columns.getUnchecked(i)->propertyFlags & sortedForwards) != 0;
  40177. return true;
  40178. }
  40179. void TableHeaderComponent::reSortTable()
  40180. {
  40181. sortChanged = true;
  40182. repaint();
  40183. triggerAsyncUpdate();
  40184. }
  40185. const String TableHeaderComponent::toString() const
  40186. {
  40187. String s;
  40188. XmlElement doc ("TABLELAYOUT");
  40189. doc.setAttribute ("sortedCol", getSortColumnId());
  40190. doc.setAttribute ("sortForwards", isSortedForwards());
  40191. for (int i = 0; i < columns.size(); ++i)
  40192. {
  40193. const ColumnInfo* const ci = columns.getUnchecked (i);
  40194. XmlElement* const e = doc.createNewChildElement ("COLUMN");
  40195. e->setAttribute ("id", ci->id);
  40196. e->setAttribute ("visible", ci->isVisible());
  40197. e->setAttribute ("width", ci->width);
  40198. }
  40199. return doc.createDocument (String::empty, true, false);
  40200. }
  40201. void TableHeaderComponent::restoreFromString (const String& storedVersion)
  40202. {
  40203. XmlDocument doc (storedVersion);
  40204. ScopedPointer <XmlElement> storedXml (doc.getDocumentElement());
  40205. int index = 0;
  40206. if (storedXml != 0 && storedXml->hasTagName ("TABLELAYOUT"))
  40207. {
  40208. forEachXmlChildElement (*storedXml, col)
  40209. {
  40210. const int tabId = col->getIntAttribute ("id");
  40211. ColumnInfo* const ci = getInfoForId (tabId);
  40212. if (ci != 0)
  40213. {
  40214. columns.move (columns.indexOf (ci), index);
  40215. ci->width = col->getIntAttribute ("width");
  40216. setColumnVisible (tabId, col->getBoolAttribute ("visible"));
  40217. }
  40218. ++index;
  40219. }
  40220. columnsResized = true;
  40221. sendColumnsChanged();
  40222. setSortColumnId (storedXml->getIntAttribute ("sortedCol"),
  40223. storedXml->getBoolAttribute ("sortForwards", true));
  40224. }
  40225. }
  40226. void TableHeaderComponent::addListener (TableHeaderListener* const newListener)
  40227. {
  40228. listeners.addIfNotAlreadyThere (newListener);
  40229. }
  40230. void TableHeaderComponent::removeListener (TableHeaderListener* const listenerToRemove)
  40231. {
  40232. listeners.removeValue (listenerToRemove);
  40233. }
  40234. void TableHeaderComponent::columnClicked (int columnId, const ModifierKeys& mods)
  40235. {
  40236. const ColumnInfo* const ci = getInfoForId (columnId);
  40237. if (ci != 0 && (ci->propertyFlags & sortable) != 0 && ! mods.isPopupMenu())
  40238. setSortColumnId (columnId, (ci->propertyFlags & sortedForwards) == 0);
  40239. }
  40240. void TableHeaderComponent::addMenuItems (PopupMenu& menu, const int /*columnIdClicked*/)
  40241. {
  40242. for (int i = 0; i < columns.size(); ++i)
  40243. {
  40244. const ColumnInfo* const ci = columns.getUnchecked(i);
  40245. if ((ci->propertyFlags & appearsOnColumnMenu) != 0)
  40246. menu.addItem (ci->id, ci->name,
  40247. (ci->propertyFlags & (sortedForwards | sortedBackwards)) == 0,
  40248. isColumnVisible (ci->id));
  40249. }
  40250. }
  40251. void TableHeaderComponent::reactToMenuItem (const int menuReturnId, const int /*columnIdClicked*/)
  40252. {
  40253. if (getIndexOfColumnId (menuReturnId, false) >= 0)
  40254. setColumnVisible (menuReturnId, ! isColumnVisible (menuReturnId));
  40255. }
  40256. void TableHeaderComponent::paint (Graphics& g)
  40257. {
  40258. LookAndFeel& lf = getLookAndFeel();
  40259. lf.drawTableHeaderBackground (g, *this);
  40260. const Rectangle<int> clip (g.getClipBounds());
  40261. int x = 0;
  40262. for (int i = 0; i < columns.size(); ++i)
  40263. {
  40264. const ColumnInfo* const ci = columns.getUnchecked(i);
  40265. if (ci->isVisible())
  40266. {
  40267. if (x + ci->width > clip.getX()
  40268. && (ci->id != columnIdBeingDragged
  40269. || dragOverlayComp == 0
  40270. || ! dragOverlayComp->isVisible()))
  40271. {
  40272. g.saveState();
  40273. g.setOrigin (x, 0);
  40274. g.reduceClipRegion (0, 0, ci->width, getHeight());
  40275. lf.drawTableHeaderColumn (g, ci->name, ci->id, ci->width, getHeight(),
  40276. ci->id == columnIdUnderMouse,
  40277. ci->id == columnIdUnderMouse && isMouseButtonDown(),
  40278. ci->propertyFlags);
  40279. g.restoreState();
  40280. }
  40281. x += ci->width;
  40282. if (x >= clip.getRight())
  40283. break;
  40284. }
  40285. }
  40286. }
  40287. void TableHeaderComponent::resized()
  40288. {
  40289. }
  40290. void TableHeaderComponent::mouseMove (const MouseEvent& e)
  40291. {
  40292. updateColumnUnderMouse (e.x, e.y);
  40293. }
  40294. void TableHeaderComponent::mouseEnter (const MouseEvent& e)
  40295. {
  40296. updateColumnUnderMouse (e.x, e.y);
  40297. }
  40298. void TableHeaderComponent::mouseExit (const MouseEvent& e)
  40299. {
  40300. updateColumnUnderMouse (e.x, e.y);
  40301. }
  40302. void TableHeaderComponent::mouseDown (const MouseEvent& e)
  40303. {
  40304. repaint();
  40305. columnIdBeingResized = 0;
  40306. columnIdBeingDragged = 0;
  40307. if (columnIdUnderMouse != 0)
  40308. {
  40309. draggingColumnOffset = e.x - getColumnPosition (getIndexOfColumnId (columnIdUnderMouse, true)).getX();
  40310. if (e.mods.isPopupMenu())
  40311. columnClicked (columnIdUnderMouse, e.mods);
  40312. }
  40313. if (menuActive && e.mods.isPopupMenu())
  40314. showColumnChooserMenu (columnIdUnderMouse);
  40315. }
  40316. void TableHeaderComponent::mouseDrag (const MouseEvent& e)
  40317. {
  40318. if (columnIdBeingResized == 0
  40319. && columnIdBeingDragged == 0
  40320. && ! (e.mouseWasClicked() || e.mods.isPopupMenu()))
  40321. {
  40322. dragOverlayComp = 0;
  40323. columnIdBeingResized = getResizeDraggerAt (e.getMouseDownX());
  40324. if (columnIdBeingResized != 0)
  40325. {
  40326. const ColumnInfo* const ci = getInfoForId (columnIdBeingResized);
  40327. initialColumnWidth = ci->width;
  40328. }
  40329. else
  40330. {
  40331. beginDrag (e);
  40332. }
  40333. }
  40334. if (columnIdBeingResized != 0)
  40335. {
  40336. const ColumnInfo* const ci = getInfoForId (columnIdBeingResized);
  40337. if (ci != 0)
  40338. {
  40339. int w = jlimit (ci->minimumWidth, ci->maximumWidth,
  40340. initialColumnWidth + e.getDistanceFromDragStartX());
  40341. if (stretchToFit)
  40342. {
  40343. // prevent us dragging a column too far right if we're in stretch-to-fit mode
  40344. int minWidthOnRight = 0;
  40345. for (int i = getIndexOfColumnId (columnIdBeingResized, false) + 1; i < columns.size(); ++i)
  40346. if (columns.getUnchecked (i)->isVisible())
  40347. minWidthOnRight += columns.getUnchecked (i)->minimumWidth;
  40348. const Rectangle<int> currentPos (getColumnPosition (getIndexOfColumnId (columnIdBeingResized, true)));
  40349. w = jmax (ci->minimumWidth, jmin (w, getWidth() - minWidthOnRight - currentPos.getX()));
  40350. }
  40351. setColumnWidth (columnIdBeingResized, w);
  40352. }
  40353. }
  40354. else if (columnIdBeingDragged != 0)
  40355. {
  40356. if (e.y >= -50 && e.y < getHeight() + 50)
  40357. {
  40358. if (dragOverlayComp != 0)
  40359. {
  40360. dragOverlayComp->setVisible (true);
  40361. dragOverlayComp->setBounds (jlimit (0,
  40362. jmax (0, getTotalWidth() - dragOverlayComp->getWidth()),
  40363. e.x - draggingColumnOffset),
  40364. 0,
  40365. dragOverlayComp->getWidth(),
  40366. getHeight());
  40367. for (int i = columns.size(); --i >= 0;)
  40368. {
  40369. const int currentIndex = getIndexOfColumnId (columnIdBeingDragged, true);
  40370. int newIndex = currentIndex;
  40371. if (newIndex > 0)
  40372. {
  40373. // if the previous column isn't draggable, we can't move our column
  40374. // past it, because that'd change the undraggable column's position..
  40375. const ColumnInfo* const previous = columns.getUnchecked (newIndex - 1);
  40376. if ((previous->propertyFlags & draggable) != 0)
  40377. {
  40378. const int leftOfPrevious = getColumnPosition (newIndex - 1).getX();
  40379. const int rightOfCurrent = getColumnPosition (newIndex).getRight();
  40380. if (abs (dragOverlayComp->getX() - leftOfPrevious)
  40381. < abs (dragOverlayComp->getRight() - rightOfCurrent))
  40382. {
  40383. --newIndex;
  40384. }
  40385. }
  40386. }
  40387. if (newIndex < columns.size() - 1)
  40388. {
  40389. // if the next column isn't draggable, we can't move our column
  40390. // past it, because that'd change the undraggable column's position..
  40391. const ColumnInfo* const nextCol = columns.getUnchecked (newIndex + 1);
  40392. if ((nextCol->propertyFlags & draggable) != 0)
  40393. {
  40394. const int leftOfCurrent = getColumnPosition (newIndex).getX();
  40395. const int rightOfNext = getColumnPosition (newIndex + 1).getRight();
  40396. if (abs (dragOverlayComp->getX() - leftOfCurrent)
  40397. > abs (dragOverlayComp->getRight() - rightOfNext))
  40398. {
  40399. ++newIndex;
  40400. }
  40401. }
  40402. }
  40403. if (newIndex != currentIndex)
  40404. moveColumn (columnIdBeingDragged, newIndex);
  40405. else
  40406. break;
  40407. }
  40408. }
  40409. }
  40410. else
  40411. {
  40412. endDrag (draggingColumnOriginalIndex);
  40413. }
  40414. }
  40415. }
  40416. void TableHeaderComponent::beginDrag (const MouseEvent& e)
  40417. {
  40418. if (columnIdBeingDragged == 0)
  40419. {
  40420. columnIdBeingDragged = getColumnIdAtX (e.getMouseDownX());
  40421. const ColumnInfo* const ci = getInfoForId (columnIdBeingDragged);
  40422. if (ci == 0 || (ci->propertyFlags & draggable) == 0)
  40423. {
  40424. columnIdBeingDragged = 0;
  40425. }
  40426. else
  40427. {
  40428. draggingColumnOriginalIndex = getIndexOfColumnId (columnIdBeingDragged, true);
  40429. const Rectangle<int> columnRect (getColumnPosition (draggingColumnOriginalIndex));
  40430. const int temp = columnIdBeingDragged;
  40431. columnIdBeingDragged = 0;
  40432. addAndMakeVisible (dragOverlayComp = new DragOverlayComp (createComponentSnapshot (columnRect, false)));
  40433. columnIdBeingDragged = temp;
  40434. dragOverlayComp->setBounds (columnRect);
  40435. for (int i = listeners.size(); --i >= 0;)
  40436. {
  40437. listeners.getUnchecked(i)->tableColumnDraggingChanged (this, columnIdBeingDragged);
  40438. i = jmin (i, listeners.size() - 1);
  40439. }
  40440. }
  40441. }
  40442. }
  40443. void TableHeaderComponent::endDrag (const int finalIndex)
  40444. {
  40445. if (columnIdBeingDragged != 0)
  40446. {
  40447. moveColumn (columnIdBeingDragged, finalIndex);
  40448. columnIdBeingDragged = 0;
  40449. repaint();
  40450. for (int i = listeners.size(); --i >= 0;)
  40451. {
  40452. listeners.getUnchecked(i)->tableColumnDraggingChanged (this, 0);
  40453. i = jmin (i, listeners.size() - 1);
  40454. }
  40455. }
  40456. }
  40457. void TableHeaderComponent::mouseUp (const MouseEvent& e)
  40458. {
  40459. mouseDrag (e);
  40460. for (int i = columns.size(); --i >= 0;)
  40461. if (columns.getUnchecked (i)->isVisible())
  40462. columns.getUnchecked (i)->lastDeliberateWidth = columns.getUnchecked (i)->width;
  40463. columnIdBeingResized = 0;
  40464. repaint();
  40465. endDrag (getIndexOfColumnId (columnIdBeingDragged, true));
  40466. updateColumnUnderMouse (e.x, e.y);
  40467. if (columnIdUnderMouse != 0 && e.mouseWasClicked() && ! e.mods.isPopupMenu())
  40468. columnClicked (columnIdUnderMouse, e.mods);
  40469. dragOverlayComp = 0;
  40470. }
  40471. const MouseCursor TableHeaderComponent::getMouseCursor()
  40472. {
  40473. if (columnIdBeingResized != 0 || (getResizeDraggerAt (getMouseXYRelative().getX()) != 0 && ! isMouseButtonDown()))
  40474. return MouseCursor (MouseCursor::LeftRightResizeCursor);
  40475. return Component::getMouseCursor();
  40476. }
  40477. bool TableHeaderComponent::ColumnInfo::isVisible() const
  40478. {
  40479. return (propertyFlags & TableHeaderComponent::visible) != 0;
  40480. }
  40481. TableHeaderComponent::ColumnInfo* TableHeaderComponent::getInfoForId (const int id) const
  40482. {
  40483. for (int i = columns.size(); --i >= 0;)
  40484. if (columns.getUnchecked(i)->id == id)
  40485. return columns.getUnchecked(i);
  40486. return 0;
  40487. }
  40488. int TableHeaderComponent::visibleIndexToTotalIndex (const int visibleIndex) const
  40489. {
  40490. int n = 0;
  40491. for (int i = 0; i < columns.size(); ++i)
  40492. {
  40493. if (columns.getUnchecked(i)->isVisible())
  40494. {
  40495. if (n == visibleIndex)
  40496. return i;
  40497. ++n;
  40498. }
  40499. }
  40500. return -1;
  40501. }
  40502. void TableHeaderComponent::sendColumnsChanged()
  40503. {
  40504. if (stretchToFit && lastDeliberateWidth > 0)
  40505. resizeAllColumnsToFit (lastDeliberateWidth);
  40506. repaint();
  40507. columnsChanged = true;
  40508. triggerAsyncUpdate();
  40509. }
  40510. void TableHeaderComponent::handleAsyncUpdate()
  40511. {
  40512. const bool changed = columnsChanged || sortChanged;
  40513. const bool sized = columnsResized || changed;
  40514. const bool sorted = sortChanged;
  40515. columnsChanged = false;
  40516. columnsResized = false;
  40517. sortChanged = false;
  40518. if (sorted)
  40519. {
  40520. for (int i = listeners.size(); --i >= 0;)
  40521. {
  40522. listeners.getUnchecked(i)->tableSortOrderChanged (this);
  40523. i = jmin (i, listeners.size() - 1);
  40524. }
  40525. }
  40526. if (changed)
  40527. {
  40528. for (int i = listeners.size(); --i >= 0;)
  40529. {
  40530. listeners.getUnchecked(i)->tableColumnsChanged (this);
  40531. i = jmin (i, listeners.size() - 1);
  40532. }
  40533. }
  40534. if (sized)
  40535. {
  40536. for (int i = listeners.size(); --i >= 0;)
  40537. {
  40538. listeners.getUnchecked(i)->tableColumnsResized (this);
  40539. i = jmin (i, listeners.size() - 1);
  40540. }
  40541. }
  40542. }
  40543. int TableHeaderComponent::getResizeDraggerAt (const int mouseX) const
  40544. {
  40545. if (((unsigned int) mouseX) < (unsigned int) getWidth())
  40546. {
  40547. const int draggableDistance = 3;
  40548. int x = 0;
  40549. for (int i = 0; i < columns.size(); ++i)
  40550. {
  40551. const ColumnInfo* const ci = columns.getUnchecked(i);
  40552. if (ci->isVisible())
  40553. {
  40554. if (abs (mouseX - (x + ci->width)) <= draggableDistance
  40555. && (ci->propertyFlags & resizable) != 0)
  40556. return ci->id;
  40557. x += ci->width;
  40558. }
  40559. }
  40560. }
  40561. return 0;
  40562. }
  40563. void TableHeaderComponent::updateColumnUnderMouse (int x, int y)
  40564. {
  40565. const int newCol = (reallyContains (x, y, true) && getResizeDraggerAt (x) == 0)
  40566. ? getColumnIdAtX (x) : 0;
  40567. if (newCol != columnIdUnderMouse)
  40568. {
  40569. columnIdUnderMouse = newCol;
  40570. repaint();
  40571. }
  40572. }
  40573. void TableHeaderComponent::showColumnChooserMenu (const int columnIdClicked)
  40574. {
  40575. PopupMenu m;
  40576. addMenuItems (m, columnIdClicked);
  40577. if (m.getNumItems() > 0)
  40578. {
  40579. m.setLookAndFeel (&getLookAndFeel());
  40580. const int result = m.show();
  40581. if (result != 0)
  40582. reactToMenuItem (result, columnIdClicked);
  40583. }
  40584. }
  40585. void TableHeaderListener::tableColumnDraggingChanged (TableHeaderComponent*, int)
  40586. {
  40587. }
  40588. END_JUCE_NAMESPACE
  40589. /*** End of inlined file: juce_TableHeaderComponent.cpp ***/
  40590. /*** Start of inlined file: juce_TableListBox.cpp ***/
  40591. BEGIN_JUCE_NAMESPACE
  40592. static const char* const tableColumnPropertyTag = "_tableColumnID";
  40593. class TableListRowComp : public Component,
  40594. public TooltipClient
  40595. {
  40596. public:
  40597. TableListRowComp (TableListBox& owner_)
  40598. : owner (owner_),
  40599. row (-1),
  40600. isSelected (false)
  40601. {
  40602. }
  40603. ~TableListRowComp()
  40604. {
  40605. deleteAllChildren();
  40606. }
  40607. void paint (Graphics& g)
  40608. {
  40609. TableListBoxModel* const model = owner.getModel();
  40610. if (model != 0)
  40611. {
  40612. const TableHeaderComponent* const header = owner.getHeader();
  40613. model->paintRowBackground (g, row, getWidth(), getHeight(), isSelected);
  40614. const int numColumns = header->getNumColumns (true);
  40615. for (int i = 0; i < numColumns; ++i)
  40616. {
  40617. if (! columnsWithComponents [i])
  40618. {
  40619. const int columnId = header->getColumnIdOfIndex (i, true);
  40620. Rectangle<int> columnRect (header->getColumnPosition (i));
  40621. columnRect.setSize (columnRect.getWidth(), getHeight());
  40622. g.saveState();
  40623. g.reduceClipRegion (columnRect);
  40624. g.setOrigin (columnRect.getX(), 0);
  40625. model->paintCell (g, row, columnId, columnRect.getWidth(), columnRect.getHeight(), isSelected);
  40626. g.restoreState();
  40627. }
  40628. }
  40629. }
  40630. }
  40631. void update (const int newRow, const bool isNowSelected)
  40632. {
  40633. if (newRow != row || isNowSelected != isSelected)
  40634. {
  40635. row = newRow;
  40636. isSelected = isNowSelected;
  40637. repaint();
  40638. }
  40639. if (row < owner.getNumRows())
  40640. {
  40641. jassert (row >= 0);
  40642. const var::identifier tagPropertyName ("_tableLastUseNum");
  40643. const int newTag = Random::getSystemRandom().nextInt();
  40644. const TableHeaderComponent* const header = owner.getHeader();
  40645. const int numColumns = header->getNumColumns (true);
  40646. int i;
  40647. columnsWithComponents.clear();
  40648. if (owner.getModel() != 0)
  40649. {
  40650. for (i = 0; i < numColumns; ++i)
  40651. {
  40652. const int columnId = header->getColumnIdOfIndex (i, true);
  40653. Component* const newComp
  40654. = owner.getModel()->refreshComponentForCell (row, columnId, isSelected,
  40655. findChildComponentForColumn (columnId));
  40656. if (newComp != 0)
  40657. {
  40658. addAndMakeVisible (newComp);
  40659. newComp->getProperties().set (tagPropertyName, newTag);
  40660. newComp->getProperties().set (tableColumnPropertyTag, columnId);
  40661. const Rectangle<int> columnRect (header->getColumnPosition (i));
  40662. newComp->setBounds (columnRect.getX(), 0, columnRect.getWidth(), getHeight());
  40663. columnsWithComponents.setBit (i);
  40664. }
  40665. }
  40666. }
  40667. for (i = getNumChildComponents(); --i >= 0;)
  40668. {
  40669. Component* const c = getChildComponent (i);
  40670. if ((int) c->getProperties() [tagPropertyName] != newTag)
  40671. delete c;
  40672. }
  40673. }
  40674. else
  40675. {
  40676. columnsWithComponents.clear();
  40677. deleteAllChildren();
  40678. }
  40679. }
  40680. void resized()
  40681. {
  40682. for (int i = getNumChildComponents(); --i >= 0;)
  40683. {
  40684. Component* const c = getChildComponent (i);
  40685. const int columnId = c->getProperties() [tableColumnPropertyTag];
  40686. if (columnId != 0)
  40687. {
  40688. const Rectangle<int> columnRect (owner.getHeader()->getColumnPosition (owner.getHeader()->getIndexOfColumnId (columnId, true)));
  40689. c->setBounds (columnRect.getX(), 0, columnRect.getWidth(), getHeight());
  40690. }
  40691. }
  40692. }
  40693. void mouseDown (const MouseEvent& e)
  40694. {
  40695. isDragging = false;
  40696. selectRowOnMouseUp = false;
  40697. if (isEnabled())
  40698. {
  40699. if (! isSelected)
  40700. {
  40701. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  40702. const int columnId = owner.getHeader()->getColumnIdAtX (e.x);
  40703. if (columnId != 0 && owner.getModel() != 0)
  40704. owner.getModel()->cellClicked (row, columnId, e);
  40705. }
  40706. else
  40707. {
  40708. selectRowOnMouseUp = true;
  40709. }
  40710. }
  40711. }
  40712. void mouseDrag (const MouseEvent& e)
  40713. {
  40714. if (isEnabled() && owner.getModel() != 0 && ! (e.mouseWasClicked() || isDragging))
  40715. {
  40716. const SparseSet <int> selectedRows (owner.getSelectedRows());
  40717. if (selectedRows.size() > 0)
  40718. {
  40719. const String dragDescription (owner.getModel()->getDragSourceDescription (selectedRows));
  40720. if (dragDescription.isNotEmpty())
  40721. {
  40722. isDragging = true;
  40723. owner.startDragAndDrop (e, dragDescription);
  40724. }
  40725. }
  40726. }
  40727. }
  40728. void mouseUp (const MouseEvent& e)
  40729. {
  40730. if (selectRowOnMouseUp && e.mouseWasClicked() && isEnabled())
  40731. {
  40732. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  40733. const int columnId = owner.getHeader()->getColumnIdAtX (e.x);
  40734. if (columnId != 0 && owner.getModel() != 0)
  40735. owner.getModel()->cellClicked (row, columnId, e);
  40736. }
  40737. }
  40738. void mouseDoubleClick (const MouseEvent& e)
  40739. {
  40740. const int columnId = owner.getHeader()->getColumnIdAtX (e.x);
  40741. if (columnId != 0 && owner.getModel() != 0)
  40742. owner.getModel()->cellDoubleClicked (row, columnId, e);
  40743. }
  40744. const String getTooltip()
  40745. {
  40746. const int columnId = owner.getHeader()->getColumnIdAtX (getMouseXYRelative().getX());
  40747. if (columnId != 0 && owner.getModel() != 0)
  40748. return owner.getModel()->getCellTooltip (row, columnId);
  40749. return String::empty;
  40750. }
  40751. juce_UseDebuggingNewOperator
  40752. private:
  40753. TableListBox& owner;
  40754. int row;
  40755. bool isSelected, isDragging, selectRowOnMouseUp;
  40756. BitArray columnsWithComponents;
  40757. Component* findChildComponentForColumn (const int columnId) const
  40758. {
  40759. for (int i = getNumChildComponents(); --i >= 0;)
  40760. {
  40761. Component* const c = getChildComponent (i);
  40762. if ((int) c->getProperties() [tableColumnPropertyTag] == columnId)
  40763. return c;
  40764. }
  40765. return 0;
  40766. }
  40767. TableListRowComp (const TableListRowComp&);
  40768. TableListRowComp& operator= (const TableListRowComp&);
  40769. };
  40770. class TableListBoxHeader : public TableHeaderComponent
  40771. {
  40772. public:
  40773. TableListBoxHeader (TableListBox& owner_)
  40774. : owner (owner_)
  40775. {
  40776. }
  40777. ~TableListBoxHeader()
  40778. {
  40779. }
  40780. void addMenuItems (PopupMenu& menu, const int columnIdClicked)
  40781. {
  40782. if (owner.isAutoSizeMenuOptionShown())
  40783. {
  40784. menu.addItem (0xf836743, TRANS("Auto-size this column"), columnIdClicked != 0);
  40785. menu.addItem (0xf836744, TRANS("Auto-size all columns"), owner.getHeader()->getNumColumns (true) > 0);
  40786. menu.addSeparator();
  40787. }
  40788. TableHeaderComponent::addMenuItems (menu, columnIdClicked);
  40789. }
  40790. void reactToMenuItem (const int menuReturnId, const int columnIdClicked)
  40791. {
  40792. if (menuReturnId == 0xf836743)
  40793. {
  40794. owner.autoSizeColumn (columnIdClicked);
  40795. }
  40796. else if (menuReturnId == 0xf836744)
  40797. {
  40798. owner.autoSizeAllColumns();
  40799. }
  40800. else
  40801. {
  40802. TableHeaderComponent::reactToMenuItem (menuReturnId, columnIdClicked);
  40803. }
  40804. }
  40805. juce_UseDebuggingNewOperator
  40806. private:
  40807. TableListBox& owner;
  40808. TableListBoxHeader (const TableListBoxHeader&);
  40809. TableListBoxHeader& operator= (const TableListBoxHeader&);
  40810. };
  40811. TableListBox::TableListBox (const String& name, TableListBoxModel* const model_)
  40812. : ListBox (name, 0),
  40813. model (model_),
  40814. autoSizeOptionsShown (true)
  40815. {
  40816. ListBox::model = this;
  40817. header = new TableListBoxHeader (*this);
  40818. header->setSize (100, 28);
  40819. header->addListener (this);
  40820. setHeaderComponent (header);
  40821. }
  40822. TableListBox::~TableListBox()
  40823. {
  40824. deleteAllChildren();
  40825. }
  40826. void TableListBox::setModel (TableListBoxModel* const newModel)
  40827. {
  40828. if (model != newModel)
  40829. {
  40830. model = newModel;
  40831. updateContent();
  40832. }
  40833. }
  40834. int TableListBox::getHeaderHeight() const
  40835. {
  40836. return header->getHeight();
  40837. }
  40838. void TableListBox::setHeaderHeight (const int newHeight)
  40839. {
  40840. header->setSize (header->getWidth(), newHeight);
  40841. resized();
  40842. }
  40843. void TableListBox::autoSizeColumn (const int columnId)
  40844. {
  40845. const int width = model != 0 ? model->getColumnAutoSizeWidth (columnId) : 0;
  40846. if (width > 0)
  40847. header->setColumnWidth (columnId, width);
  40848. }
  40849. void TableListBox::autoSizeAllColumns()
  40850. {
  40851. for (int i = 0; i < header->getNumColumns (true); ++i)
  40852. autoSizeColumn (header->getColumnIdOfIndex (i, true));
  40853. }
  40854. void TableListBox::setAutoSizeMenuOptionShown (const bool shouldBeShown)
  40855. {
  40856. autoSizeOptionsShown = shouldBeShown;
  40857. }
  40858. bool TableListBox::isAutoSizeMenuOptionShown() const
  40859. {
  40860. return autoSizeOptionsShown;
  40861. }
  40862. const Rectangle<int> TableListBox::getCellPosition (const int columnId,
  40863. const int rowNumber,
  40864. const bool relativeToComponentTopLeft) const
  40865. {
  40866. Rectangle<int> headerCell (header->getColumnPosition (header->getIndexOfColumnId (columnId, true)));
  40867. if (relativeToComponentTopLeft)
  40868. headerCell.translate (header->getX(), 0);
  40869. const Rectangle<int> row (getRowPosition (rowNumber, relativeToComponentTopLeft));
  40870. return Rectangle<int> (headerCell.getX(), row.getY(),
  40871. headerCell.getWidth(), row.getHeight());
  40872. }
  40873. void TableListBox::scrollToEnsureColumnIsOnscreen (const int columnId)
  40874. {
  40875. ScrollBar* const scrollbar = getHorizontalScrollBar();
  40876. if (scrollbar != 0)
  40877. {
  40878. const Rectangle<int> pos (header->getColumnPosition (header->getIndexOfColumnId (columnId, true)));
  40879. double x = scrollbar->getCurrentRangeStart();
  40880. const double w = scrollbar->getCurrentRangeSize();
  40881. if (pos.getX() < x)
  40882. x = pos.getX();
  40883. else if (pos.getRight() > x + w)
  40884. x += jmax (0.0, pos.getRight() - (x + w));
  40885. scrollbar->setCurrentRangeStart (x);
  40886. }
  40887. }
  40888. int TableListBox::getNumRows()
  40889. {
  40890. return model != 0 ? model->getNumRows() : 0;
  40891. }
  40892. void TableListBox::paintListBoxItem (int, Graphics&, int, int, bool)
  40893. {
  40894. }
  40895. Component* TableListBox::refreshComponentForRow (int rowNumber, bool isRowSelected_, Component* existingComponentToUpdate)
  40896. {
  40897. if (existingComponentToUpdate == 0)
  40898. existingComponentToUpdate = new TableListRowComp (*this);
  40899. ((TableListRowComp*) existingComponentToUpdate)->update (rowNumber, isRowSelected_);
  40900. return existingComponentToUpdate;
  40901. }
  40902. void TableListBox::selectedRowsChanged (int row)
  40903. {
  40904. if (model != 0)
  40905. model->selectedRowsChanged (row);
  40906. }
  40907. void TableListBox::deleteKeyPressed (int row)
  40908. {
  40909. if (model != 0)
  40910. model->deleteKeyPressed (row);
  40911. }
  40912. void TableListBox::returnKeyPressed (int row)
  40913. {
  40914. if (model != 0)
  40915. model->returnKeyPressed (row);
  40916. }
  40917. void TableListBox::backgroundClicked()
  40918. {
  40919. if (model != 0)
  40920. model->backgroundClicked();
  40921. }
  40922. void TableListBox::listWasScrolled()
  40923. {
  40924. if (model != 0)
  40925. model->listWasScrolled();
  40926. }
  40927. void TableListBox::tableColumnsChanged (TableHeaderComponent*)
  40928. {
  40929. setMinimumContentWidth (header->getTotalWidth());
  40930. repaint();
  40931. updateColumnComponents();
  40932. }
  40933. void TableListBox::tableColumnsResized (TableHeaderComponent*)
  40934. {
  40935. setMinimumContentWidth (header->getTotalWidth());
  40936. repaint();
  40937. updateColumnComponents();
  40938. }
  40939. void TableListBox::tableSortOrderChanged (TableHeaderComponent*)
  40940. {
  40941. if (model != 0)
  40942. model->sortOrderChanged (header->getSortColumnId(),
  40943. header->isSortedForwards());
  40944. }
  40945. void TableListBox::tableColumnDraggingChanged (TableHeaderComponent*, int columnIdNowBeingDragged_)
  40946. {
  40947. columnIdNowBeingDragged = columnIdNowBeingDragged_;
  40948. repaint();
  40949. }
  40950. void TableListBox::resized()
  40951. {
  40952. ListBox::resized();
  40953. header->resizeAllColumnsToFit (getVisibleContentWidth());
  40954. setMinimumContentWidth (header->getTotalWidth());
  40955. }
  40956. void TableListBox::updateColumnComponents() const
  40957. {
  40958. const int firstRow = getRowContainingPosition (0, 0);
  40959. for (int i = firstRow + getNumRowsOnScreen() + 2; --i >= firstRow;)
  40960. {
  40961. TableListRowComp* const rowComp = dynamic_cast <TableListRowComp*> (getComponentForRowNumber (i));
  40962. if (rowComp != 0)
  40963. rowComp->resized();
  40964. }
  40965. }
  40966. void TableListBoxModel::cellClicked (int, int, const MouseEvent&)
  40967. {
  40968. }
  40969. void TableListBoxModel::cellDoubleClicked (int, int, const MouseEvent&)
  40970. {
  40971. }
  40972. void TableListBoxModel::backgroundClicked()
  40973. {
  40974. }
  40975. void TableListBoxModel::sortOrderChanged (int, const bool)
  40976. {
  40977. }
  40978. int TableListBoxModel::getColumnAutoSizeWidth (int)
  40979. {
  40980. return 0;
  40981. }
  40982. void TableListBoxModel::selectedRowsChanged (int)
  40983. {
  40984. }
  40985. void TableListBoxModel::deleteKeyPressed (int)
  40986. {
  40987. }
  40988. void TableListBoxModel::returnKeyPressed (int)
  40989. {
  40990. }
  40991. void TableListBoxModel::listWasScrolled()
  40992. {
  40993. }
  40994. const String TableListBoxModel::getCellTooltip (int /*rowNumber*/, int /*columnId*/)
  40995. {
  40996. return String::empty;
  40997. }
  40998. const String TableListBoxModel::getDragSourceDescription (const SparseSet<int>&)
  40999. {
  41000. return String::empty;
  41001. }
  41002. Component* TableListBoxModel::refreshComponentForCell (int, int, bool, Component* existingComponentToUpdate)
  41003. {
  41004. (void) existingComponentToUpdate;
  41005. jassert (existingComponentToUpdate == 0); // indicates a failure in the code the recycles the components
  41006. return 0;
  41007. }
  41008. END_JUCE_NAMESPACE
  41009. /*** End of inlined file: juce_TableListBox.cpp ***/
  41010. /*** Start of inlined file: juce_TextEditor.cpp ***/
  41011. BEGIN_JUCE_NAMESPACE
  41012. // a word or space that can't be broken down any further
  41013. struct TextAtom
  41014. {
  41015. String atomText;
  41016. float width;
  41017. uint16 numChars;
  41018. bool isWhitespace() const { return CharacterFunctions::isWhitespace (atomText[0]); }
  41019. bool isNewLine() const { return atomText[0] == T('\r') || atomText[0] == T('\n'); }
  41020. const String getText (const tchar passwordCharacter) const
  41021. {
  41022. if (passwordCharacter == 0)
  41023. return atomText;
  41024. else
  41025. return String::repeatedString (String::charToString (passwordCharacter),
  41026. atomText.length());
  41027. }
  41028. const String getTrimmedText (const tchar passwordCharacter) const
  41029. {
  41030. if (passwordCharacter == 0)
  41031. return atomText.substring (0, numChars);
  41032. else if (isNewLine())
  41033. return String::empty;
  41034. else
  41035. return String::repeatedString (String::charToString (passwordCharacter), numChars);
  41036. }
  41037. };
  41038. // a run of text with a single font and colour
  41039. class UniformTextSection
  41040. {
  41041. public:
  41042. UniformTextSection (const String& text,
  41043. const Font& font_,
  41044. const Colour& colour_,
  41045. const tchar passwordCharacter)
  41046. : font (font_),
  41047. colour (colour_)
  41048. {
  41049. initialiseAtoms (text, passwordCharacter);
  41050. }
  41051. UniformTextSection (const UniformTextSection& other)
  41052. : font (other.font),
  41053. colour (other.colour)
  41054. {
  41055. atoms.ensureStorageAllocated (other.atoms.size());
  41056. for (int i = 0; i < other.atoms.size(); ++i)
  41057. atoms.add (new TextAtom (*(const TextAtom*) other.atoms.getUnchecked(i)));
  41058. }
  41059. ~UniformTextSection()
  41060. {
  41061. // (no need to delete the atoms, as they're explicitly deleted by the caller)
  41062. }
  41063. void clear()
  41064. {
  41065. for (int i = atoms.size(); --i >= 0;)
  41066. delete getAtom(i);
  41067. atoms.clear();
  41068. }
  41069. int getNumAtoms() const
  41070. {
  41071. return atoms.size();
  41072. }
  41073. TextAtom* getAtom (const int index) const
  41074. {
  41075. return (TextAtom*) atoms.getUnchecked (index);
  41076. }
  41077. void append (const UniformTextSection& other, const tchar passwordCharacter)
  41078. {
  41079. if (other.atoms.size() > 0)
  41080. {
  41081. TextAtom* const lastAtom = (TextAtom*) atoms.getLast();
  41082. int i = 0;
  41083. if (lastAtom != 0)
  41084. {
  41085. if (! CharacterFunctions::isWhitespace (lastAtom->atomText.getLastCharacter()))
  41086. {
  41087. TextAtom* const first = other.getAtom(0);
  41088. if (! CharacterFunctions::isWhitespace (first->atomText[0]))
  41089. {
  41090. lastAtom->atomText += first->atomText;
  41091. lastAtom->numChars = (uint16) (lastAtom->numChars + first->numChars);
  41092. lastAtom->width = font.getStringWidthFloat (lastAtom->getText (passwordCharacter));
  41093. delete first;
  41094. ++i;
  41095. }
  41096. }
  41097. }
  41098. atoms.ensureStorageAllocated (atoms.size() + other.atoms.size() - i);
  41099. while (i < other.atoms.size())
  41100. {
  41101. atoms.add (other.getAtom(i));
  41102. ++i;
  41103. }
  41104. }
  41105. }
  41106. UniformTextSection* split (const int indexToBreakAt,
  41107. const tchar passwordCharacter)
  41108. {
  41109. UniformTextSection* const section2 = new UniformTextSection (String::empty,
  41110. font, colour,
  41111. passwordCharacter);
  41112. int index = 0;
  41113. for (int i = 0; i < atoms.size(); ++i)
  41114. {
  41115. TextAtom* const atom = getAtom(i);
  41116. const int nextIndex = index + atom->numChars;
  41117. if (index == indexToBreakAt)
  41118. {
  41119. int j;
  41120. for (j = i; j < atoms.size(); ++j)
  41121. section2->atoms.add (getAtom (j));
  41122. for (j = atoms.size(); --j >= i;)
  41123. atoms.remove (j);
  41124. break;
  41125. }
  41126. else if (indexToBreakAt >= index && indexToBreakAt < nextIndex)
  41127. {
  41128. TextAtom* const secondAtom = new TextAtom();
  41129. secondAtom->atomText = atom->atomText.substring (indexToBreakAt - index);
  41130. secondAtom->width = font.getStringWidthFloat (secondAtom->getText (passwordCharacter));
  41131. secondAtom->numChars = (uint16) secondAtom->atomText.length();
  41132. section2->atoms.add (secondAtom);
  41133. atom->atomText = atom->atomText.substring (0, indexToBreakAt - index);
  41134. atom->width = font.getStringWidthFloat (atom->getText (passwordCharacter));
  41135. atom->numChars = (uint16) (indexToBreakAt - index);
  41136. int j;
  41137. for (j = i + 1; j < atoms.size(); ++j)
  41138. section2->atoms.add (getAtom (j));
  41139. for (j = atoms.size(); --j > i;)
  41140. atoms.remove (j);
  41141. break;
  41142. }
  41143. index = nextIndex;
  41144. }
  41145. return section2;
  41146. }
  41147. void appendAllText (String::Concatenator& concatenator) const
  41148. {
  41149. for (int i = 0; i < atoms.size(); ++i)
  41150. concatenator.append (getAtom(i)->atomText);
  41151. }
  41152. void appendSubstring (String::Concatenator& concatenator,
  41153. const Range<int>& range) const
  41154. {
  41155. int index = 0;
  41156. for (int i = 0; i < atoms.size(); ++i)
  41157. {
  41158. const TextAtom* const atom = getAtom (i);
  41159. const int nextIndex = index + atom->numChars;
  41160. if (range.getStart() < nextIndex)
  41161. {
  41162. if (range.getEnd() <= index)
  41163. break;
  41164. const Range<int> r ((range - index).getIntersectionWith (Range<int> (0, (int) atom->numChars)));
  41165. if (! r.isEmpty())
  41166. concatenator.append (atom->atomText.substring (r.getStart(), r.getEnd()));
  41167. }
  41168. index = nextIndex;
  41169. }
  41170. }
  41171. int getTotalLength() const
  41172. {
  41173. int total = 0;
  41174. for (int i = atoms.size(); --i >= 0;)
  41175. total += getAtom(i)->numChars;
  41176. return total;
  41177. }
  41178. void setFont (const Font& newFont,
  41179. const tchar passwordCharacter)
  41180. {
  41181. if (font != newFont)
  41182. {
  41183. font = newFont;
  41184. for (int i = atoms.size(); --i >= 0;)
  41185. {
  41186. TextAtom* const atom = (TextAtom*) atoms.getUnchecked(i);
  41187. atom->width = newFont.getStringWidthFloat (atom->getText (passwordCharacter));
  41188. }
  41189. }
  41190. }
  41191. juce_UseDebuggingNewOperator
  41192. Font font;
  41193. Colour colour;
  41194. private:
  41195. VoidArray atoms;
  41196. void initialiseAtoms (const String& textToParse,
  41197. const tchar passwordCharacter)
  41198. {
  41199. int i = 0;
  41200. const int len = textToParse.length();
  41201. const tchar* const text = (const tchar*) textToParse;
  41202. while (i < len)
  41203. {
  41204. int start = i;
  41205. // create a whitespace atom unless it starts with non-ws
  41206. if (CharacterFunctions::isWhitespace (text[i])
  41207. && text[i] != T('\r')
  41208. && text[i] != T('\n'))
  41209. {
  41210. while (i < len
  41211. && CharacterFunctions::isWhitespace (text[i])
  41212. && text[i] != T('\r')
  41213. && text[i] != T('\n'))
  41214. {
  41215. ++i;
  41216. }
  41217. }
  41218. else
  41219. {
  41220. if (text[i] == T('\r'))
  41221. {
  41222. ++i;
  41223. if ((i < len) && (text[i] == T('\n')))
  41224. {
  41225. ++start;
  41226. ++i;
  41227. }
  41228. }
  41229. else if (text[i] == T('\n'))
  41230. {
  41231. ++i;
  41232. }
  41233. else
  41234. {
  41235. while ((i < len) && ! CharacterFunctions::isWhitespace (text[i]))
  41236. ++i;
  41237. }
  41238. }
  41239. TextAtom* const atom = new TextAtom();
  41240. atom->atomText = String (text + start, i - start);
  41241. atom->width = font.getStringWidthFloat (atom->getText (passwordCharacter));
  41242. atom->numChars = (uint16) (i - start);
  41243. atoms.add (atom);
  41244. }
  41245. }
  41246. UniformTextSection& operator= (const UniformTextSection& other);
  41247. };
  41248. class TextEditorIterator
  41249. {
  41250. public:
  41251. TextEditorIterator (const VoidArray& sections_,
  41252. const float wordWrapWidth_,
  41253. const tchar passwordCharacter_)
  41254. : indexInText (0),
  41255. lineY (0),
  41256. lineHeight (0),
  41257. maxDescent (0),
  41258. atomX (0),
  41259. atomRight (0),
  41260. atom (0),
  41261. currentSection (0),
  41262. sections (sections_),
  41263. sectionIndex (0),
  41264. atomIndex (0),
  41265. wordWrapWidth (wordWrapWidth_),
  41266. passwordCharacter (passwordCharacter_)
  41267. {
  41268. jassert (wordWrapWidth_ > 0);
  41269. if (sections.size() > 0)
  41270. {
  41271. currentSection = (const UniformTextSection*) sections.getUnchecked (sectionIndex);
  41272. if (currentSection != 0)
  41273. beginNewLine();
  41274. }
  41275. }
  41276. TextEditorIterator (const TextEditorIterator& other)
  41277. : indexInText (other.indexInText),
  41278. lineY (other.lineY),
  41279. lineHeight (other.lineHeight),
  41280. maxDescent (other.maxDescent),
  41281. atomX (other.atomX),
  41282. atomRight (other.atomRight),
  41283. atom (other.atom),
  41284. currentSection (other.currentSection),
  41285. sections (other.sections),
  41286. sectionIndex (other.sectionIndex),
  41287. atomIndex (other.atomIndex),
  41288. wordWrapWidth (other.wordWrapWidth),
  41289. passwordCharacter (other.passwordCharacter),
  41290. tempAtom (other.tempAtom)
  41291. {
  41292. }
  41293. ~TextEditorIterator()
  41294. {
  41295. }
  41296. bool next()
  41297. {
  41298. if (atom == &tempAtom)
  41299. {
  41300. const int numRemaining = tempAtom.atomText.length() - tempAtom.numChars;
  41301. if (numRemaining > 0)
  41302. {
  41303. tempAtom.atomText = tempAtom.atomText.substring (tempAtom.numChars);
  41304. atomX = 0;
  41305. if (tempAtom.numChars > 0)
  41306. lineY += lineHeight;
  41307. indexInText += tempAtom.numChars;
  41308. GlyphArrangement g;
  41309. g.addLineOfText (currentSection->font, atom->getText (passwordCharacter), 0.0f, 0.0f);
  41310. int split;
  41311. for (split = 0; split < g.getNumGlyphs(); ++split)
  41312. if (shouldWrap (g.getGlyph (split).getRight()))
  41313. break;
  41314. if (split > 0 && split <= numRemaining)
  41315. {
  41316. tempAtom.numChars = (uint16) split;
  41317. tempAtom.width = g.getGlyph (split - 1).getRight();
  41318. atomRight = atomX + tempAtom.width;
  41319. return true;
  41320. }
  41321. }
  41322. }
  41323. bool forceNewLine = false;
  41324. if (sectionIndex >= sections.size())
  41325. {
  41326. moveToEndOfLastAtom();
  41327. return false;
  41328. }
  41329. else if (atomIndex >= currentSection->getNumAtoms() - 1)
  41330. {
  41331. if (atomIndex >= currentSection->getNumAtoms())
  41332. {
  41333. if (++sectionIndex >= sections.size())
  41334. {
  41335. moveToEndOfLastAtom();
  41336. return false;
  41337. }
  41338. atomIndex = 0;
  41339. currentSection = (const UniformTextSection*) sections.getUnchecked (sectionIndex);
  41340. }
  41341. else
  41342. {
  41343. const TextAtom* const lastAtom = currentSection->getAtom (atomIndex);
  41344. if (! lastAtom->isWhitespace())
  41345. {
  41346. // handle the case where the last atom in a section is actually part of the same
  41347. // word as the first atom of the next section...
  41348. float right = atomRight + lastAtom->width;
  41349. float lineHeight2 = lineHeight;
  41350. float maxDescent2 = maxDescent;
  41351. for (int section = sectionIndex + 1; section < sections.size(); ++section)
  41352. {
  41353. const UniformTextSection* const s = (const UniformTextSection*) sections.getUnchecked (section);
  41354. if (s->getNumAtoms() == 0)
  41355. break;
  41356. const TextAtom* const nextAtom = s->getAtom (0);
  41357. if (nextAtom->isWhitespace())
  41358. break;
  41359. right += nextAtom->width;
  41360. lineHeight2 = jmax (lineHeight2, s->font.getHeight());
  41361. maxDescent2 = jmax (maxDescent2, s->font.getDescent());
  41362. if (shouldWrap (right))
  41363. {
  41364. lineHeight = lineHeight2;
  41365. maxDescent = maxDescent2;
  41366. forceNewLine = true;
  41367. break;
  41368. }
  41369. if (s->getNumAtoms() > 1)
  41370. break;
  41371. }
  41372. }
  41373. }
  41374. }
  41375. if (atom != 0)
  41376. {
  41377. atomX = atomRight;
  41378. indexInText += atom->numChars;
  41379. if (atom->isNewLine())
  41380. beginNewLine();
  41381. }
  41382. atom = currentSection->getAtom (atomIndex);
  41383. atomRight = atomX + atom->width;
  41384. ++atomIndex;
  41385. if (shouldWrap (atomRight) || forceNewLine)
  41386. {
  41387. if (atom->isWhitespace())
  41388. {
  41389. // leave whitespace at the end of a line, but truncate it to avoid scrolling
  41390. atomRight = jmin (atomRight, wordWrapWidth);
  41391. }
  41392. else
  41393. {
  41394. atomRight = atom->width;
  41395. if (shouldWrap (atomRight)) // atom too big to fit on a line, so break it up..
  41396. {
  41397. tempAtom = *atom;
  41398. tempAtom.width = 0;
  41399. tempAtom.numChars = 0;
  41400. atom = &tempAtom;
  41401. if (atomX > 0)
  41402. beginNewLine();
  41403. return next();
  41404. }
  41405. beginNewLine();
  41406. return true;
  41407. }
  41408. }
  41409. return true;
  41410. }
  41411. void beginNewLine()
  41412. {
  41413. atomX = 0;
  41414. lineY += lineHeight;
  41415. int tempSectionIndex = sectionIndex;
  41416. int tempAtomIndex = atomIndex;
  41417. const UniformTextSection* section = (const UniformTextSection*) sections.getUnchecked (tempSectionIndex);
  41418. lineHeight = section->font.getHeight();
  41419. maxDescent = section->font.getDescent();
  41420. float x = (atom != 0) ? atom->width : 0;
  41421. while (! shouldWrap (x))
  41422. {
  41423. if (tempSectionIndex >= sections.size())
  41424. break;
  41425. bool checkSize = false;
  41426. if (tempAtomIndex >= section->getNumAtoms())
  41427. {
  41428. if (++tempSectionIndex >= sections.size())
  41429. break;
  41430. tempAtomIndex = 0;
  41431. section = (const UniformTextSection*) sections.getUnchecked (tempSectionIndex);
  41432. checkSize = true;
  41433. }
  41434. const TextAtom* const nextAtom = section->getAtom (tempAtomIndex);
  41435. if (nextAtom == 0)
  41436. break;
  41437. x += nextAtom->width;
  41438. if (shouldWrap (x) || nextAtom->isNewLine())
  41439. break;
  41440. if (checkSize)
  41441. {
  41442. lineHeight = jmax (lineHeight, section->font.getHeight());
  41443. maxDescent = jmax (maxDescent, section->font.getDescent());
  41444. }
  41445. ++tempAtomIndex;
  41446. }
  41447. }
  41448. void draw (Graphics& g, const UniformTextSection*& lastSection) const
  41449. {
  41450. if (passwordCharacter != 0 || ! atom->isWhitespace())
  41451. {
  41452. if (lastSection != currentSection)
  41453. {
  41454. lastSection = currentSection;
  41455. g.setColour (currentSection->colour);
  41456. g.setFont (currentSection->font);
  41457. }
  41458. jassert (atom->getTrimmedText (passwordCharacter).isNotEmpty());
  41459. GlyphArrangement ga;
  41460. ga.addLineOfText (currentSection->font,
  41461. atom->getTrimmedText (passwordCharacter),
  41462. atomX,
  41463. (float) roundToInt (lineY + lineHeight - maxDescent));
  41464. ga.draw (g);
  41465. }
  41466. }
  41467. void drawSelection (Graphics& g,
  41468. const Range<int>& selection) const
  41469. {
  41470. const int startX = roundToInt (indexToX (selection.getStart()));
  41471. const int endX = roundToInt (indexToX (selection.getEnd()));
  41472. const int y = roundToInt (lineY);
  41473. const int nextY = roundToInt (lineY + lineHeight);
  41474. g.fillRect (startX, y, endX - startX, nextY - y);
  41475. }
  41476. void drawSelectedText (Graphics& g,
  41477. const Range<int>& selection,
  41478. const Colour& selectedTextColour) const
  41479. {
  41480. if (passwordCharacter != 0 || ! atom->isWhitespace())
  41481. {
  41482. GlyphArrangement ga;
  41483. ga.addLineOfText (currentSection->font,
  41484. atom->getTrimmedText (passwordCharacter),
  41485. atomX,
  41486. (float) roundToInt (lineY + lineHeight - maxDescent));
  41487. if (selection.getEnd() < indexInText + atom->numChars)
  41488. {
  41489. GlyphArrangement ga2 (ga);
  41490. ga2.removeRangeOfGlyphs (0, selection.getEnd() - indexInText);
  41491. ga.removeRangeOfGlyphs (selection.getEnd() - indexInText, -1);
  41492. g.setColour (currentSection->colour);
  41493. ga2.draw (g);
  41494. }
  41495. if (selection.getStart() > indexInText)
  41496. {
  41497. GlyphArrangement ga2 (ga);
  41498. ga2.removeRangeOfGlyphs (selection.getStart() - indexInText, -1);
  41499. ga.removeRangeOfGlyphs (0, selection.getStart() - indexInText);
  41500. g.setColour (currentSection->colour);
  41501. ga2.draw (g);
  41502. }
  41503. g.setColour (selectedTextColour);
  41504. ga.draw (g);
  41505. }
  41506. }
  41507. float indexToX (const int indexToFind) const
  41508. {
  41509. if (indexToFind <= indexInText)
  41510. return atomX;
  41511. if (indexToFind >= indexInText + atom->numChars)
  41512. return atomRight;
  41513. GlyphArrangement g;
  41514. g.addLineOfText (currentSection->font,
  41515. atom->getText (passwordCharacter),
  41516. atomX, 0.0f);
  41517. if (indexToFind - indexInText >= g.getNumGlyphs())
  41518. return atomRight;
  41519. return jmin (atomRight, g.getGlyph (indexToFind - indexInText).getLeft());
  41520. }
  41521. int xToIndex (const float xToFind) const
  41522. {
  41523. if (xToFind <= atomX || atom->isNewLine())
  41524. return indexInText;
  41525. if (xToFind >= atomRight)
  41526. return indexInText + atom->numChars;
  41527. GlyphArrangement g;
  41528. g.addLineOfText (currentSection->font,
  41529. atom->getText (passwordCharacter),
  41530. atomX, 0.0f);
  41531. int j;
  41532. for (j = 0; j < g.getNumGlyphs(); ++j)
  41533. if ((g.getGlyph(j).getLeft() + g.getGlyph(j).getRight()) / 2 > xToFind)
  41534. break;
  41535. return indexInText + j;
  41536. }
  41537. bool getCharPosition (const int index, float& cx, float& cy, float& lineHeight_)
  41538. {
  41539. while (next())
  41540. {
  41541. if (indexInText + atom->numChars > index)
  41542. {
  41543. cx = indexToX (index);
  41544. cy = lineY;
  41545. lineHeight_ = lineHeight;
  41546. return true;
  41547. }
  41548. }
  41549. cx = atomX;
  41550. cy = lineY;
  41551. lineHeight_ = lineHeight;
  41552. return false;
  41553. }
  41554. juce_UseDebuggingNewOperator
  41555. int indexInText;
  41556. float lineY, lineHeight, maxDescent;
  41557. float atomX, atomRight;
  41558. const TextAtom* atom;
  41559. const UniformTextSection* currentSection;
  41560. private:
  41561. const VoidArray& sections;
  41562. int sectionIndex, atomIndex;
  41563. const float wordWrapWidth;
  41564. const tchar passwordCharacter;
  41565. TextAtom tempAtom;
  41566. TextEditorIterator& operator= (const TextEditorIterator&);
  41567. void moveToEndOfLastAtom()
  41568. {
  41569. if (atom != 0)
  41570. {
  41571. atomX = atomRight;
  41572. if (atom->isNewLine())
  41573. {
  41574. atomX = 0.0f;
  41575. lineY += lineHeight;
  41576. }
  41577. }
  41578. }
  41579. bool shouldWrap (const float x) const
  41580. {
  41581. return (x - 0.0001f) >= wordWrapWidth;
  41582. }
  41583. };
  41584. class TextEditorInsertAction : public UndoableAction
  41585. {
  41586. TextEditor& owner;
  41587. const String text;
  41588. const int insertIndex, oldCaretPos, newCaretPos;
  41589. const Font font;
  41590. const Colour colour;
  41591. TextEditorInsertAction (const TextEditorInsertAction&);
  41592. TextEditorInsertAction& operator= (const TextEditorInsertAction&);
  41593. public:
  41594. TextEditorInsertAction (TextEditor& owner_,
  41595. const String& text_,
  41596. const int insertIndex_,
  41597. const Font& font_,
  41598. const Colour& colour_,
  41599. const int oldCaretPos_,
  41600. const int newCaretPos_)
  41601. : owner (owner_),
  41602. text (text_),
  41603. insertIndex (insertIndex_),
  41604. oldCaretPos (oldCaretPos_),
  41605. newCaretPos (newCaretPos_),
  41606. font (font_),
  41607. colour (colour_)
  41608. {
  41609. }
  41610. ~TextEditorInsertAction()
  41611. {
  41612. }
  41613. bool perform()
  41614. {
  41615. owner.insert (text, insertIndex, font, colour, 0, newCaretPos);
  41616. return true;
  41617. }
  41618. bool undo()
  41619. {
  41620. owner.remove (Range<int> (insertIndex, insertIndex + text.length()), 0, oldCaretPos);
  41621. return true;
  41622. }
  41623. int getSizeInUnits()
  41624. {
  41625. return text.length() + 16;
  41626. }
  41627. };
  41628. class TextEditorRemoveAction : public UndoableAction
  41629. {
  41630. TextEditor& owner;
  41631. const Range<int> range;
  41632. const int oldCaretPos, newCaretPos;
  41633. VoidArray removedSections;
  41634. TextEditorRemoveAction (const TextEditorRemoveAction&);
  41635. TextEditorRemoveAction& operator= (const TextEditorRemoveAction&);
  41636. public:
  41637. TextEditorRemoveAction (TextEditor& owner_,
  41638. const Range<int> range_,
  41639. const int oldCaretPos_,
  41640. const int newCaretPos_,
  41641. const VoidArray& removedSections_)
  41642. : owner (owner_),
  41643. range (range_),
  41644. oldCaretPos (oldCaretPos_),
  41645. newCaretPos (newCaretPos_),
  41646. removedSections (removedSections_)
  41647. {
  41648. }
  41649. ~TextEditorRemoveAction()
  41650. {
  41651. for (int i = removedSections.size(); --i >= 0;)
  41652. {
  41653. UniformTextSection* const section = (UniformTextSection*) removedSections.getUnchecked (i);
  41654. section->clear();
  41655. delete section;
  41656. }
  41657. }
  41658. bool perform()
  41659. {
  41660. owner.remove (range, 0, newCaretPos);
  41661. return true;
  41662. }
  41663. bool undo()
  41664. {
  41665. owner.reinsert (range.getStart(), removedSections);
  41666. owner.moveCursorTo (oldCaretPos, false);
  41667. return true;
  41668. }
  41669. int getSizeInUnits()
  41670. {
  41671. int n = 0;
  41672. for (int i = removedSections.size(); --i >= 0;)
  41673. {
  41674. UniformTextSection* const section = (UniformTextSection*) removedSections.getUnchecked (i);
  41675. n += section->getTotalLength();
  41676. }
  41677. return n + 16;
  41678. }
  41679. };
  41680. class TextHolderComponent : public Component,
  41681. public Timer,
  41682. public Value::Listener
  41683. {
  41684. TextEditor& owner;
  41685. TextHolderComponent (const TextHolderComponent&);
  41686. TextHolderComponent& operator= (const TextHolderComponent&);
  41687. public:
  41688. TextHolderComponent (TextEditor& owner_)
  41689. : owner (owner_)
  41690. {
  41691. setWantsKeyboardFocus (false);
  41692. setInterceptsMouseClicks (false, true);
  41693. owner.getTextValue().addListener (this);
  41694. }
  41695. ~TextHolderComponent()
  41696. {
  41697. owner.getTextValue().removeListener (this);
  41698. }
  41699. void paint (Graphics& g)
  41700. {
  41701. owner.drawContent (g);
  41702. }
  41703. void timerCallback()
  41704. {
  41705. owner.timerCallbackInt();
  41706. }
  41707. const MouseCursor getMouseCursor()
  41708. {
  41709. return owner.getMouseCursor();
  41710. }
  41711. void valueChanged (Value&)
  41712. {
  41713. owner.textWasChangedByValue();
  41714. }
  41715. };
  41716. class TextEditorViewport : public Viewport
  41717. {
  41718. TextEditor* const owner;
  41719. float lastWordWrapWidth;
  41720. TextEditorViewport (const TextEditorViewport&);
  41721. TextEditorViewport& operator= (const TextEditorViewport&);
  41722. public:
  41723. TextEditorViewport (TextEditor* const owner_)
  41724. : owner (owner_),
  41725. lastWordWrapWidth (0)
  41726. {
  41727. }
  41728. ~TextEditorViewport()
  41729. {
  41730. }
  41731. void visibleAreaChanged (int, int, int, int)
  41732. {
  41733. const float wordWrapWidth = owner->getWordWrapWidth();
  41734. if (wordWrapWidth != lastWordWrapWidth)
  41735. {
  41736. lastWordWrapWidth = wordWrapWidth;
  41737. owner->updateTextHolderSize();
  41738. }
  41739. }
  41740. };
  41741. namespace TextEditorDefs
  41742. {
  41743. const int flashSpeedIntervalMs = 380;
  41744. const int textChangeMessageId = 0x10003001;
  41745. const int returnKeyMessageId = 0x10003002;
  41746. const int escapeKeyMessageId = 0x10003003;
  41747. const int focusLossMessageId = 0x10003004;
  41748. const int maxActionsPerTransaction = 100;
  41749. }
  41750. TextEditor::TextEditor (const String& name,
  41751. const tchar passwordCharacter_)
  41752. : Component (name),
  41753. borderSize (1, 1, 1, 3),
  41754. readOnly (false),
  41755. multiline (false),
  41756. wordWrap (false),
  41757. returnKeyStartsNewLine (false),
  41758. caretVisible (true),
  41759. popupMenuEnabled (true),
  41760. selectAllTextWhenFocused (false),
  41761. scrollbarVisible (true),
  41762. wasFocused (false),
  41763. caretFlashState (true),
  41764. keepCursorOnScreen (true),
  41765. tabKeyUsed (false),
  41766. menuActive (false),
  41767. valueTextNeedsUpdating (false),
  41768. cursorX (0),
  41769. cursorY (0),
  41770. cursorHeight (0),
  41771. maxTextLength (0),
  41772. leftIndent (4),
  41773. topIndent (4),
  41774. lastTransactionTime (0),
  41775. currentFont (14.0f),
  41776. totalNumChars (0),
  41777. caretPosition (0),
  41778. passwordCharacter (passwordCharacter_),
  41779. dragType (notDragging)
  41780. {
  41781. setOpaque (true);
  41782. addAndMakeVisible (viewport = new TextEditorViewport (this));
  41783. viewport->setViewedComponent (textHolder = new TextHolderComponent (*this));
  41784. viewport->setWantsKeyboardFocus (false);
  41785. viewport->setScrollBarsShown (false, false);
  41786. setMouseCursor (MouseCursor::IBeamCursor);
  41787. setWantsKeyboardFocus (true);
  41788. }
  41789. TextEditor::~TextEditor()
  41790. {
  41791. textValue.referTo (Value());
  41792. clearInternal (0);
  41793. viewport = 0;
  41794. textHolder = 0;
  41795. }
  41796. void TextEditor::newTransaction()
  41797. {
  41798. lastTransactionTime = Time::getApproximateMillisecondCounter();
  41799. undoManager.beginNewTransaction();
  41800. }
  41801. void TextEditor::doUndoRedo (const bool isRedo)
  41802. {
  41803. if (! isReadOnly())
  41804. {
  41805. if (isRedo ? undoManager.redo()
  41806. : undoManager.undo())
  41807. {
  41808. scrollToMakeSureCursorIsVisible();
  41809. repaint();
  41810. textChanged();
  41811. }
  41812. }
  41813. }
  41814. void TextEditor::setMultiLine (const bool shouldBeMultiLine,
  41815. const bool shouldWordWrap)
  41816. {
  41817. multiline = shouldBeMultiLine;
  41818. wordWrap = shouldWordWrap && shouldBeMultiLine;
  41819. setScrollbarsShown (scrollbarVisible);
  41820. viewport->setViewPosition (0, 0);
  41821. resized();
  41822. scrollToMakeSureCursorIsVisible();
  41823. }
  41824. bool TextEditor::isMultiLine() const
  41825. {
  41826. return multiline;
  41827. }
  41828. void TextEditor::setScrollbarsShown (bool enabled)
  41829. {
  41830. scrollbarVisible = enabled;
  41831. enabled = enabled && isMultiLine();
  41832. viewport->setScrollBarsShown (enabled, enabled);
  41833. }
  41834. void TextEditor::setReadOnly (const bool shouldBeReadOnly)
  41835. {
  41836. readOnly = shouldBeReadOnly;
  41837. enablementChanged();
  41838. }
  41839. bool TextEditor::isReadOnly() const
  41840. {
  41841. return readOnly || ! isEnabled();
  41842. }
  41843. void TextEditor::setReturnKeyStartsNewLine (const bool shouldStartNewLine)
  41844. {
  41845. returnKeyStartsNewLine = shouldStartNewLine;
  41846. }
  41847. void TextEditor::setTabKeyUsedAsCharacter (const bool shouldTabKeyBeUsed)
  41848. {
  41849. tabKeyUsed = shouldTabKeyBeUsed;
  41850. }
  41851. void TextEditor::setPopupMenuEnabled (const bool b)
  41852. {
  41853. popupMenuEnabled = b;
  41854. }
  41855. void TextEditor::setSelectAllWhenFocused (const bool b)
  41856. {
  41857. selectAllTextWhenFocused = b;
  41858. }
  41859. const Font TextEditor::getFont() const
  41860. {
  41861. return currentFont;
  41862. }
  41863. void TextEditor::setFont (const Font& newFont)
  41864. {
  41865. currentFont = newFont;
  41866. scrollToMakeSureCursorIsVisible();
  41867. }
  41868. void TextEditor::applyFontToAllText (const Font& newFont)
  41869. {
  41870. currentFont = newFont;
  41871. const Colour overallColour (findColour (textColourId));
  41872. for (int i = sections.size(); --i >= 0;)
  41873. {
  41874. UniformTextSection* const uts = (UniformTextSection*) sections.getUnchecked(i);
  41875. uts->setFont (newFont, passwordCharacter);
  41876. uts->colour = overallColour;
  41877. }
  41878. coalesceSimilarSections();
  41879. updateTextHolderSize();
  41880. scrollToMakeSureCursorIsVisible();
  41881. repaint();
  41882. }
  41883. void TextEditor::colourChanged()
  41884. {
  41885. setOpaque (findColour (backgroundColourId).isOpaque());
  41886. repaint();
  41887. }
  41888. void TextEditor::setCaretVisible (const bool shouldCaretBeVisible)
  41889. {
  41890. caretVisible = shouldCaretBeVisible;
  41891. if (shouldCaretBeVisible)
  41892. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  41893. setMouseCursor (shouldCaretBeVisible ? MouseCursor::IBeamCursor
  41894. : MouseCursor::NormalCursor);
  41895. }
  41896. void TextEditor::setInputRestrictions (const int maxLen,
  41897. const String& chars)
  41898. {
  41899. maxTextLength = jmax (0, maxLen);
  41900. allowedCharacters = chars;
  41901. }
  41902. void TextEditor::setTextToShowWhenEmpty (const String& text, const Colour& colourToUse)
  41903. {
  41904. textToShowWhenEmpty = text;
  41905. colourForTextWhenEmpty = colourToUse;
  41906. }
  41907. void TextEditor::setPasswordCharacter (const tchar newPasswordCharacter)
  41908. {
  41909. if (passwordCharacter != newPasswordCharacter)
  41910. {
  41911. passwordCharacter = newPasswordCharacter;
  41912. resized();
  41913. repaint();
  41914. }
  41915. }
  41916. void TextEditor::setScrollBarThickness (const int newThicknessPixels)
  41917. {
  41918. viewport->setScrollBarThickness (newThicknessPixels);
  41919. }
  41920. void TextEditor::setScrollBarButtonVisibility (const bool buttonsVisible)
  41921. {
  41922. viewport->setScrollBarButtonVisibility (buttonsVisible);
  41923. }
  41924. void TextEditor::clear()
  41925. {
  41926. clearInternal (0);
  41927. updateTextHolderSize();
  41928. undoManager.clearUndoHistory();
  41929. }
  41930. void TextEditor::setText (const String& newText,
  41931. const bool sendTextChangeMessage)
  41932. {
  41933. const int newLength = newText.length();
  41934. if (newLength != getTotalNumChars() || getText() != newText)
  41935. {
  41936. const int oldCursorPos = caretPosition;
  41937. const bool cursorWasAtEnd = oldCursorPos >= getTotalNumChars();
  41938. clearInternal (0);
  41939. insert (newText, 0, currentFont, findColour (textColourId), 0, caretPosition);
  41940. // if you're adding text with line-feeds to a single-line text editor, it
  41941. // ain't gonna look right!
  41942. jassert (multiline || ! newText.containsAnyOf (T("\r\n")));
  41943. if (cursorWasAtEnd && ! isMultiLine())
  41944. moveCursorTo (getTotalNumChars(), false);
  41945. else
  41946. moveCursorTo (oldCursorPos, false);
  41947. if (sendTextChangeMessage)
  41948. textChanged();
  41949. repaint();
  41950. }
  41951. updateTextHolderSize();
  41952. scrollToMakeSureCursorIsVisible();
  41953. undoManager.clearUndoHistory();
  41954. }
  41955. Value& TextEditor::getTextValue()
  41956. {
  41957. if (valueTextNeedsUpdating)
  41958. {
  41959. valueTextNeedsUpdating = false;
  41960. textValue = getText();
  41961. }
  41962. return textValue;
  41963. }
  41964. void TextEditor::textWasChangedByValue()
  41965. {
  41966. if (textValue.getValueSource().getReferenceCount() > 1)
  41967. setText (textValue.getValue());
  41968. }
  41969. void TextEditor::textChanged()
  41970. {
  41971. updateTextHolderSize();
  41972. postCommandMessage (TextEditorDefs::textChangeMessageId);
  41973. if (textValue.getValueSource().getReferenceCount() > 1)
  41974. {
  41975. valueTextNeedsUpdating = false;
  41976. textValue = getText();
  41977. }
  41978. }
  41979. void TextEditor::returnPressed()
  41980. {
  41981. postCommandMessage (TextEditorDefs::returnKeyMessageId);
  41982. }
  41983. void TextEditor::escapePressed()
  41984. {
  41985. postCommandMessage (TextEditorDefs::escapeKeyMessageId);
  41986. }
  41987. void TextEditor::addListener (TextEditorListener* const newListener)
  41988. {
  41989. listeners.add (newListener);
  41990. }
  41991. void TextEditor::removeListener (TextEditorListener* const listenerToRemove)
  41992. {
  41993. listeners.remove (listenerToRemove);
  41994. }
  41995. void TextEditor::timerCallbackInt()
  41996. {
  41997. const bool newState = (! caretFlashState) && ! isCurrentlyBlockedByAnotherModalComponent();
  41998. if (caretFlashState != newState)
  41999. {
  42000. caretFlashState = newState;
  42001. if (caretFlashState)
  42002. wasFocused = true;
  42003. if (caretVisible
  42004. && hasKeyboardFocus (false)
  42005. && ! isReadOnly())
  42006. {
  42007. repaintCaret();
  42008. }
  42009. }
  42010. const unsigned int now = Time::getApproximateMillisecondCounter();
  42011. if (now > lastTransactionTime + 200)
  42012. newTransaction();
  42013. }
  42014. void TextEditor::repaintCaret()
  42015. {
  42016. if (! findColour (caretColourId).isTransparent())
  42017. repaint (borderSize.getLeft() + textHolder->getX() + leftIndent + roundToInt (cursorX) - 1,
  42018. borderSize.getTop() + textHolder->getY() + topIndent + roundToInt (cursorY) - 1,
  42019. 4,
  42020. roundToInt (cursorHeight) + 2);
  42021. }
  42022. void TextEditor::repaintText (const Range<int>& range)
  42023. {
  42024. if (! range.isEmpty())
  42025. {
  42026. float x = 0, y = 0, lh = currentFont.getHeight();
  42027. const float wordWrapWidth = getWordWrapWidth();
  42028. if (wordWrapWidth > 0)
  42029. {
  42030. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  42031. i.getCharPosition (range.getStart(), x, y, lh);
  42032. const int y1 = (int) y;
  42033. int y2;
  42034. if (range.getEnd() >= getTotalNumChars())
  42035. {
  42036. y2 = textHolder->getHeight();
  42037. }
  42038. else
  42039. {
  42040. i.getCharPosition (range.getEnd(), x, y, lh);
  42041. y2 = (int) (y + lh * 2.0f);
  42042. }
  42043. textHolder->repaint (0, y1, textHolder->getWidth(), y2 - y1);
  42044. }
  42045. }
  42046. }
  42047. void TextEditor::moveCaret (int newCaretPos)
  42048. {
  42049. if (newCaretPos < 0)
  42050. newCaretPos = 0;
  42051. else if (newCaretPos > getTotalNumChars())
  42052. newCaretPos = getTotalNumChars();
  42053. if (newCaretPos != getCaretPosition())
  42054. {
  42055. repaintCaret();
  42056. caretFlashState = true;
  42057. caretPosition = newCaretPos;
  42058. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  42059. scrollToMakeSureCursorIsVisible();
  42060. repaintCaret();
  42061. }
  42062. }
  42063. void TextEditor::setCaretPosition (const int newIndex)
  42064. {
  42065. moveCursorTo (newIndex, false);
  42066. }
  42067. int TextEditor::getCaretPosition() const
  42068. {
  42069. return caretPosition;
  42070. }
  42071. void TextEditor::scrollEditorToPositionCaret (const int desiredCaretX,
  42072. const int desiredCaretY)
  42073. {
  42074. updateCaretPosition();
  42075. int vx = roundToInt (cursorX) - desiredCaretX;
  42076. int vy = roundToInt (cursorY) - desiredCaretY;
  42077. if (desiredCaretX < jmax (1, proportionOfWidth (0.05f)))
  42078. {
  42079. vx += desiredCaretX - proportionOfWidth (0.2f);
  42080. }
  42081. else if (desiredCaretX > jmax (0, viewport->getMaximumVisibleWidth() - (wordWrap ? 2 : 10)))
  42082. {
  42083. vx += desiredCaretX + (isMultiLine() ? proportionOfWidth (0.2f) : 10) - viewport->getMaximumVisibleWidth();
  42084. }
  42085. vx = jlimit (0, jmax (0, textHolder->getWidth() + 8 - viewport->getMaximumVisibleWidth()), vx);
  42086. if (! isMultiLine())
  42087. {
  42088. vy = viewport->getViewPositionY();
  42089. }
  42090. else
  42091. {
  42092. vy = jlimit (0, jmax (0, textHolder->getHeight() - viewport->getMaximumVisibleHeight()), vy);
  42093. const int curH = roundToInt (cursorHeight);
  42094. if (desiredCaretY < 0)
  42095. {
  42096. vy = jmax (0, desiredCaretY + vy);
  42097. }
  42098. else if (desiredCaretY > jmax (0, viewport->getMaximumVisibleHeight() - topIndent - curH))
  42099. {
  42100. vy += desiredCaretY + 2 + curH + topIndent - viewport->getMaximumVisibleHeight();
  42101. }
  42102. }
  42103. viewport->setViewPosition (vx, vy);
  42104. }
  42105. const Rectangle<int> TextEditor::getCaretRectangle()
  42106. {
  42107. updateCaretPosition();
  42108. return Rectangle<int> (roundToInt (cursorX) - viewport->getX(),
  42109. roundToInt (cursorY) - viewport->getY(),
  42110. 1, roundToInt (cursorHeight));
  42111. }
  42112. float TextEditor::getWordWrapWidth() const
  42113. {
  42114. return (wordWrap) ? (float) (viewport->getMaximumVisibleWidth() - leftIndent - leftIndent / 2)
  42115. : 1.0e10f;
  42116. }
  42117. void TextEditor::updateTextHolderSize()
  42118. {
  42119. const float wordWrapWidth = getWordWrapWidth();
  42120. if (wordWrapWidth > 0)
  42121. {
  42122. float maxWidth = 0.0f;
  42123. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  42124. while (i.next())
  42125. maxWidth = jmax (maxWidth, i.atomRight);
  42126. const int w = leftIndent + roundToInt (maxWidth);
  42127. const int h = topIndent + roundToInt (jmax (i.lineY + i.lineHeight,
  42128. currentFont.getHeight()));
  42129. textHolder->setSize (w + 1, h + 1);
  42130. }
  42131. }
  42132. int TextEditor::getTextWidth() const
  42133. {
  42134. return textHolder->getWidth();
  42135. }
  42136. int TextEditor::getTextHeight() const
  42137. {
  42138. return textHolder->getHeight();
  42139. }
  42140. void TextEditor::setIndents (const int newLeftIndent,
  42141. const int newTopIndent)
  42142. {
  42143. leftIndent = newLeftIndent;
  42144. topIndent = newTopIndent;
  42145. }
  42146. void TextEditor::setBorder (const BorderSize& border)
  42147. {
  42148. borderSize = border;
  42149. resized();
  42150. }
  42151. const BorderSize TextEditor::getBorder() const
  42152. {
  42153. return borderSize;
  42154. }
  42155. void TextEditor::setScrollToShowCursor (const bool shouldScrollToShowCursor)
  42156. {
  42157. keepCursorOnScreen = shouldScrollToShowCursor;
  42158. }
  42159. void TextEditor::updateCaretPosition()
  42160. {
  42161. cursorHeight = currentFont.getHeight(); // (in case the text is empty and the call below doesn't set this value)
  42162. getCharPosition (caretPosition, cursorX, cursorY, cursorHeight);
  42163. }
  42164. void TextEditor::scrollToMakeSureCursorIsVisible()
  42165. {
  42166. updateCaretPosition();
  42167. if (keepCursorOnScreen)
  42168. {
  42169. int x = viewport->getViewPositionX();
  42170. int y = viewport->getViewPositionY();
  42171. const int relativeCursorX = roundToInt (cursorX) - x;
  42172. const int relativeCursorY = roundToInt (cursorY) - y;
  42173. if (relativeCursorX < jmax (1, proportionOfWidth (0.05f)))
  42174. {
  42175. x += relativeCursorX - proportionOfWidth (0.2f);
  42176. }
  42177. else if (relativeCursorX > jmax (0, viewport->getMaximumVisibleWidth() - (wordWrap ? 2 : 10)))
  42178. {
  42179. x += relativeCursorX + (isMultiLine() ? proportionOfWidth (0.2f) : 10) - viewport->getMaximumVisibleWidth();
  42180. }
  42181. x = jlimit (0, jmax (0, textHolder->getWidth() + 8 - viewport->getMaximumVisibleWidth()), x);
  42182. if (! isMultiLine())
  42183. {
  42184. y = (getHeight() - textHolder->getHeight() - topIndent) / -2;
  42185. }
  42186. else
  42187. {
  42188. const int curH = roundToInt (cursorHeight);
  42189. if (relativeCursorY < 0)
  42190. {
  42191. y = jmax (0, relativeCursorY + y);
  42192. }
  42193. else if (relativeCursorY > jmax (0, viewport->getMaximumVisibleHeight() - topIndent - curH))
  42194. {
  42195. y += relativeCursorY + 2 + curH + topIndent - viewport->getMaximumVisibleHeight();
  42196. }
  42197. }
  42198. viewport->setViewPosition (x, y);
  42199. }
  42200. }
  42201. void TextEditor::moveCursorTo (const int newPosition,
  42202. const bool isSelecting)
  42203. {
  42204. if (isSelecting)
  42205. {
  42206. moveCaret (newPosition);
  42207. const Range<int> oldSelection (selection);
  42208. if (dragType == notDragging)
  42209. {
  42210. if (abs (getCaretPosition() - selection.getStart()) < abs (getCaretPosition() - selection.getEnd()))
  42211. dragType = draggingSelectionStart;
  42212. else
  42213. dragType = draggingSelectionEnd;
  42214. }
  42215. if (dragType == draggingSelectionStart)
  42216. {
  42217. if (getCaretPosition() >= selection.getEnd())
  42218. dragType = draggingSelectionEnd;
  42219. selection = Range<int>::between (getCaretPosition(), selection.getEnd());
  42220. }
  42221. else
  42222. {
  42223. if (getCaretPosition() < selection.getStart())
  42224. dragType = draggingSelectionStart;
  42225. selection = Range<int>::between (getCaretPosition(), selection.getStart());
  42226. }
  42227. repaintText (selection.getUnionWith (oldSelection));
  42228. }
  42229. else
  42230. {
  42231. dragType = notDragging;
  42232. repaintText (selection);
  42233. moveCaret (newPosition);
  42234. selection = Range<int>::emptyRange (getCaretPosition());
  42235. }
  42236. }
  42237. int TextEditor::getTextIndexAt (const int x,
  42238. const int y)
  42239. {
  42240. return indexAtPosition ((float) (x + viewport->getViewPositionX() - leftIndent),
  42241. (float) (y + viewport->getViewPositionY() - topIndent));
  42242. }
  42243. void TextEditor::insertTextAtCaret (const String& newText_)
  42244. {
  42245. String newText (newText_);
  42246. if (allowedCharacters.isNotEmpty())
  42247. newText = newText.retainCharacters (allowedCharacters);
  42248. if (! isMultiLine())
  42249. newText = newText.replaceCharacters (T("\r\n"), T(" "));
  42250. else
  42251. newText = newText.replace (T("\r\n"), T("\n"));
  42252. const int newCaretPos = selection.getStart() + newText.length();
  42253. const int insertIndex = selection.getStart();
  42254. remove (selection, getUndoManager(),
  42255. newText.isNotEmpty() ? newCaretPos - 1 : newCaretPos);
  42256. if (maxTextLength > 0)
  42257. newText = newText.substring (0, maxTextLength - getTotalNumChars());
  42258. if (newText.isNotEmpty())
  42259. insert (newText,
  42260. insertIndex,
  42261. currentFont,
  42262. findColour (textColourId),
  42263. getUndoManager(),
  42264. newCaretPos);
  42265. textChanged();
  42266. }
  42267. void TextEditor::setHighlightedRegion (const Range<int>& newSelection)
  42268. {
  42269. moveCursorTo (newSelection.getStart(), false);
  42270. moveCursorTo (newSelection.getEnd(), true);
  42271. }
  42272. void TextEditor::copy()
  42273. {
  42274. if (passwordCharacter == 0)
  42275. {
  42276. const String selection (getHighlightedText());
  42277. if (selection.isNotEmpty())
  42278. SystemClipboard::copyTextToClipboard (selection);
  42279. }
  42280. }
  42281. void TextEditor::paste()
  42282. {
  42283. if (! isReadOnly())
  42284. {
  42285. const String clip (SystemClipboard::getTextFromClipboard());
  42286. if (clip.isNotEmpty())
  42287. insertTextAtCaret (clip);
  42288. }
  42289. }
  42290. void TextEditor::cut()
  42291. {
  42292. if (! isReadOnly())
  42293. {
  42294. moveCaret (selection.getEnd());
  42295. insertTextAtCaret (String::empty);
  42296. }
  42297. }
  42298. void TextEditor::drawContent (Graphics& g)
  42299. {
  42300. const float wordWrapWidth = getWordWrapWidth();
  42301. if (wordWrapWidth > 0)
  42302. {
  42303. g.setOrigin (leftIndent, topIndent);
  42304. const Rectangle<int> clip (g.getClipBounds());
  42305. Colour selectedTextColour;
  42306. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  42307. while (i.lineY + 200.0 < clip.getY() && i.next())
  42308. {}
  42309. if (! selection.isEmpty())
  42310. {
  42311. g.setColour (findColour (highlightColourId)
  42312. .withMultipliedAlpha (hasKeyboardFocus (true) ? 1.0f : 0.5f));
  42313. selectedTextColour = findColour (highlightedTextColourId);
  42314. TextEditorIterator i2 (i);
  42315. while (i2.next() && i2.lineY < clip.getBottom())
  42316. {
  42317. if (i2.lineY + i2.lineHeight >= clip.getY()
  42318. && selection.intersects (Range<int> (i2.indexInText, i2.indexInText + i2.atom->numChars)))
  42319. {
  42320. i2.drawSelection (g, selection);
  42321. }
  42322. }
  42323. }
  42324. const UniformTextSection* lastSection = 0;
  42325. while (i.next() && i.lineY < clip.getBottom())
  42326. {
  42327. if (i.lineY + i.lineHeight >= clip.getY())
  42328. {
  42329. if (selection.intersects (Range<int> (i.indexInText, i.indexInText + i.atom->numChars)))
  42330. {
  42331. i.drawSelectedText (g, selection, selectedTextColour);
  42332. lastSection = 0;
  42333. }
  42334. else
  42335. {
  42336. i.draw (g, lastSection);
  42337. }
  42338. }
  42339. }
  42340. }
  42341. }
  42342. void TextEditor::paint (Graphics& g)
  42343. {
  42344. getLookAndFeel().fillTextEditorBackground (g, getWidth(), getHeight(), *this);
  42345. }
  42346. void TextEditor::paintOverChildren (Graphics& g)
  42347. {
  42348. if (caretFlashState
  42349. && hasKeyboardFocus (false)
  42350. && caretVisible
  42351. && ! isReadOnly())
  42352. {
  42353. g.setColour (findColour (caretColourId));
  42354. g.fillRect (borderSize.getLeft() + textHolder->getX() + leftIndent + cursorX,
  42355. borderSize.getTop() + textHolder->getY() + topIndent + cursorY,
  42356. 2.0f, cursorHeight);
  42357. }
  42358. if (textToShowWhenEmpty.isNotEmpty()
  42359. && (! hasKeyboardFocus (false))
  42360. && getTotalNumChars() == 0)
  42361. {
  42362. g.setColour (colourForTextWhenEmpty);
  42363. g.setFont (getFont());
  42364. if (isMultiLine())
  42365. {
  42366. g.drawText (textToShowWhenEmpty,
  42367. 0, 0, getWidth(), getHeight(),
  42368. Justification::centred, true);
  42369. }
  42370. else
  42371. {
  42372. g.drawText (textToShowWhenEmpty,
  42373. leftIndent, topIndent,
  42374. viewport->getWidth() - leftIndent,
  42375. viewport->getHeight() - topIndent,
  42376. Justification::centredLeft, true);
  42377. }
  42378. }
  42379. getLookAndFeel().drawTextEditorOutline (g, getWidth(), getHeight(), *this);
  42380. }
  42381. void TextEditor::mouseDown (const MouseEvent& e)
  42382. {
  42383. beginDragAutoRepeat (100);
  42384. newTransaction();
  42385. if (wasFocused || ! selectAllTextWhenFocused)
  42386. {
  42387. if (! (popupMenuEnabled && e.mods.isPopupMenu()))
  42388. {
  42389. moveCursorTo (getTextIndexAt (e.x, e.y),
  42390. e.mods.isShiftDown());
  42391. }
  42392. else
  42393. {
  42394. PopupMenu m;
  42395. m.setLookAndFeel (&getLookAndFeel());
  42396. addPopupMenuItems (m, &e);
  42397. menuActive = true;
  42398. const int result = m.show();
  42399. menuActive = false;
  42400. if (result != 0)
  42401. performPopupMenuAction (result);
  42402. }
  42403. }
  42404. }
  42405. void TextEditor::mouseDrag (const MouseEvent& e)
  42406. {
  42407. if (wasFocused || ! selectAllTextWhenFocused)
  42408. {
  42409. if (! (popupMenuEnabled && e.mods.isPopupMenu()))
  42410. {
  42411. moveCursorTo (getTextIndexAt (e.x, e.y), true);
  42412. }
  42413. }
  42414. }
  42415. void TextEditor::mouseUp (const MouseEvent& e)
  42416. {
  42417. newTransaction();
  42418. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  42419. if (wasFocused || ! selectAllTextWhenFocused)
  42420. {
  42421. if (e.mouseWasClicked() && ! (popupMenuEnabled && e.mods.isPopupMenu()))
  42422. {
  42423. moveCaret (getTextIndexAt (e.x, e.y));
  42424. }
  42425. }
  42426. wasFocused = true;
  42427. }
  42428. void TextEditor::mouseDoubleClick (const MouseEvent& e)
  42429. {
  42430. int tokenEnd = getTextIndexAt (e.x, e.y);
  42431. int tokenStart = tokenEnd;
  42432. if (e.getNumberOfClicks() > 3)
  42433. {
  42434. tokenStart = 0;
  42435. tokenEnd = getTotalNumChars();
  42436. }
  42437. else
  42438. {
  42439. const String t (getText());
  42440. const int totalLength = getTotalNumChars();
  42441. while (tokenEnd < totalLength)
  42442. {
  42443. if (CharacterFunctions::isLetterOrDigit (t [tokenEnd]))
  42444. ++tokenEnd;
  42445. else
  42446. break;
  42447. }
  42448. tokenStart = tokenEnd;
  42449. while (tokenStart > 0)
  42450. {
  42451. if (CharacterFunctions::isLetterOrDigit (t [tokenStart - 1]))
  42452. --tokenStart;
  42453. else
  42454. break;
  42455. }
  42456. if (e.getNumberOfClicks() > 2)
  42457. {
  42458. while (tokenEnd < totalLength)
  42459. {
  42460. if (t [tokenEnd] != T('\r') && t [tokenEnd] != T('\n'))
  42461. ++tokenEnd;
  42462. else
  42463. break;
  42464. }
  42465. while (tokenStart > 0)
  42466. {
  42467. if (t [tokenStart - 1] != T('\r') && t [tokenStart - 1] != T('\n'))
  42468. --tokenStart;
  42469. else
  42470. break;
  42471. }
  42472. }
  42473. }
  42474. moveCursorTo (tokenEnd, false);
  42475. moveCursorTo (tokenStart, true);
  42476. }
  42477. void TextEditor::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  42478. {
  42479. if (! viewport->useMouseWheelMoveIfNeeded (e, wheelIncrementX, wheelIncrementY))
  42480. Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
  42481. }
  42482. bool TextEditor::keyPressed (const KeyPress& key)
  42483. {
  42484. if (isReadOnly() && key != KeyPress (T('c'), ModifierKeys::commandModifier, 0))
  42485. return false;
  42486. const bool moveInWholeWordSteps = key.getModifiers().isCtrlDown() || key.getModifiers().isAltDown();
  42487. if (key.isKeyCode (KeyPress::leftKey)
  42488. || key.isKeyCode (KeyPress::upKey))
  42489. {
  42490. newTransaction();
  42491. int newPos;
  42492. if (isMultiLine() && key.isKeyCode (KeyPress::upKey))
  42493. newPos = indexAtPosition (cursorX, cursorY - 1);
  42494. else if (moveInWholeWordSteps)
  42495. newPos = findWordBreakBefore (getCaretPosition());
  42496. else
  42497. newPos = getCaretPosition() - 1;
  42498. moveCursorTo (newPos, key.getModifiers().isShiftDown());
  42499. }
  42500. else if (key.isKeyCode (KeyPress::rightKey)
  42501. || key.isKeyCode (KeyPress::downKey))
  42502. {
  42503. newTransaction();
  42504. int newPos;
  42505. if (isMultiLine() && key.isKeyCode (KeyPress::downKey))
  42506. newPos = indexAtPosition (cursorX, cursorY + cursorHeight + 1);
  42507. else if (moveInWholeWordSteps)
  42508. newPos = findWordBreakAfter (getCaretPosition());
  42509. else
  42510. newPos = getCaretPosition() + 1;
  42511. moveCursorTo (newPos, key.getModifiers().isShiftDown());
  42512. }
  42513. else if (key.isKeyCode (KeyPress::pageDownKey) && isMultiLine())
  42514. {
  42515. newTransaction();
  42516. moveCursorTo (indexAtPosition (cursorX, cursorY + cursorHeight + viewport->getViewHeight()),
  42517. key.getModifiers().isShiftDown());
  42518. }
  42519. else if (key.isKeyCode (KeyPress::pageUpKey) && isMultiLine())
  42520. {
  42521. newTransaction();
  42522. moveCursorTo (indexAtPosition (cursorX, cursorY - viewport->getViewHeight()),
  42523. key.getModifiers().isShiftDown());
  42524. }
  42525. else if (key.isKeyCode (KeyPress::homeKey))
  42526. {
  42527. newTransaction();
  42528. if (isMultiLine() && ! moveInWholeWordSteps)
  42529. moveCursorTo (indexAtPosition (0.0f, cursorY),
  42530. key.getModifiers().isShiftDown());
  42531. else
  42532. moveCursorTo (0, key.getModifiers().isShiftDown());
  42533. }
  42534. else if (key.isKeyCode (KeyPress::endKey))
  42535. {
  42536. newTransaction();
  42537. if (isMultiLine() && ! moveInWholeWordSteps)
  42538. moveCursorTo (indexAtPosition ((float) textHolder->getWidth(), cursorY),
  42539. key.getModifiers().isShiftDown());
  42540. else
  42541. moveCursorTo (getTotalNumChars(), key.getModifiers().isShiftDown());
  42542. }
  42543. else if (key.isKeyCode (KeyPress::backspaceKey))
  42544. {
  42545. if (moveInWholeWordSteps)
  42546. {
  42547. moveCursorTo (findWordBreakBefore (getCaretPosition()), true);
  42548. }
  42549. else
  42550. {
  42551. if (selection.isEmpty() && selection.getStart() > 0)
  42552. selection.setStart (selection.getEnd() - 1);
  42553. }
  42554. cut();
  42555. }
  42556. else if (key.isKeyCode (KeyPress::deleteKey))
  42557. {
  42558. if (key.getModifiers().isShiftDown())
  42559. copy();
  42560. if (selection.isEmpty() && selection.getStart() < getTotalNumChars())
  42561. selection.setEnd (selection.getStart() + 1);
  42562. cut();
  42563. }
  42564. else if (key == KeyPress (T('c'), ModifierKeys::commandModifier, 0)
  42565. || key == KeyPress (KeyPress::insertKey, ModifierKeys::ctrlModifier, 0))
  42566. {
  42567. newTransaction();
  42568. copy();
  42569. }
  42570. else if (key == KeyPress (T('x'), ModifierKeys::commandModifier, 0))
  42571. {
  42572. newTransaction();
  42573. copy();
  42574. cut();
  42575. }
  42576. else if (key == KeyPress (T('v'), ModifierKeys::commandModifier, 0)
  42577. || key == KeyPress (KeyPress::insertKey, ModifierKeys::shiftModifier, 0))
  42578. {
  42579. newTransaction();
  42580. paste();
  42581. }
  42582. else if (key == KeyPress (T('z'), ModifierKeys::commandModifier, 0))
  42583. {
  42584. newTransaction();
  42585. doUndoRedo (false);
  42586. }
  42587. else if (key == KeyPress (T('y'), ModifierKeys::commandModifier, 0))
  42588. {
  42589. newTransaction();
  42590. doUndoRedo (true);
  42591. }
  42592. else if (key == KeyPress (T('a'), ModifierKeys::commandModifier, 0))
  42593. {
  42594. newTransaction();
  42595. moveCursorTo (getTotalNumChars(), false);
  42596. moveCursorTo (0, true);
  42597. }
  42598. else if (key == KeyPress::returnKey)
  42599. {
  42600. newTransaction();
  42601. if (returnKeyStartsNewLine)
  42602. insertTextAtCaret (T("\n"));
  42603. else
  42604. returnPressed();
  42605. }
  42606. else if (key.isKeyCode (KeyPress::escapeKey))
  42607. {
  42608. newTransaction();
  42609. moveCursorTo (getCaretPosition(), false);
  42610. escapePressed();
  42611. }
  42612. else if (key.getTextCharacter() >= ' '
  42613. || (tabKeyUsed && (key.getTextCharacter() == '\t')))
  42614. {
  42615. insertTextAtCaret (String::charToString (key.getTextCharacter()));
  42616. lastTransactionTime = Time::getApproximateMillisecondCounter();
  42617. }
  42618. else
  42619. {
  42620. return false;
  42621. }
  42622. return true;
  42623. }
  42624. bool TextEditor::keyStateChanged (const bool isKeyDown)
  42625. {
  42626. if (! isKeyDown)
  42627. return false;
  42628. #if JUCE_WIN32
  42629. if (KeyPress (KeyPress::F4Key, ModifierKeys::altModifier, 0).isCurrentlyDown())
  42630. return false; // We need to explicitly allow alt-F4 to pass through on Windows
  42631. #endif
  42632. // (overridden to avoid forwarding key events to the parent)
  42633. return ! ModifierKeys::getCurrentModifiers().isCommandDown();
  42634. }
  42635. const int baseMenuItemID = 0x7fff0000;
  42636. void TextEditor::addPopupMenuItems (PopupMenu& m, const MouseEvent*)
  42637. {
  42638. const bool writable = ! isReadOnly();
  42639. if (passwordCharacter == 0)
  42640. {
  42641. m.addItem (baseMenuItemID + 1, TRANS("cut"), writable);
  42642. m.addItem (baseMenuItemID + 2, TRANS("copy"), ! selection.isEmpty());
  42643. m.addItem (baseMenuItemID + 3, TRANS("paste"), writable);
  42644. }
  42645. m.addItem (baseMenuItemID + 4, TRANS("delete"), writable);
  42646. m.addSeparator();
  42647. m.addItem (baseMenuItemID + 5, TRANS("select all"));
  42648. m.addSeparator();
  42649. if (getUndoManager() != 0)
  42650. {
  42651. m.addItem (baseMenuItemID + 6, TRANS("undo"), undoManager.canUndo());
  42652. m.addItem (baseMenuItemID + 7, TRANS("redo"), undoManager.canRedo());
  42653. }
  42654. }
  42655. void TextEditor::performPopupMenuAction (const int menuItemID)
  42656. {
  42657. switch (menuItemID)
  42658. {
  42659. case baseMenuItemID + 1:
  42660. copy();
  42661. cut();
  42662. break;
  42663. case baseMenuItemID + 2:
  42664. copy();
  42665. break;
  42666. case baseMenuItemID + 3:
  42667. paste();
  42668. break;
  42669. case baseMenuItemID + 4:
  42670. cut();
  42671. break;
  42672. case baseMenuItemID + 5:
  42673. moveCursorTo (getTotalNumChars(), false);
  42674. moveCursorTo (0, true);
  42675. break;
  42676. case baseMenuItemID + 6:
  42677. doUndoRedo (false);
  42678. break;
  42679. case baseMenuItemID + 7:
  42680. doUndoRedo (true);
  42681. break;
  42682. default:
  42683. break;
  42684. }
  42685. }
  42686. void TextEditor::focusGained (FocusChangeType)
  42687. {
  42688. newTransaction();
  42689. caretFlashState = true;
  42690. if (selectAllTextWhenFocused)
  42691. {
  42692. moveCursorTo (0, false);
  42693. moveCursorTo (getTotalNumChars(), true);
  42694. }
  42695. repaint();
  42696. if (caretVisible)
  42697. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  42698. ComponentPeer* const peer = getPeer();
  42699. if (peer != 0 && ! isReadOnly())
  42700. peer->textInputRequired (getScreenPosition() - peer->getScreenPosition());
  42701. }
  42702. void TextEditor::focusLost (FocusChangeType)
  42703. {
  42704. newTransaction();
  42705. wasFocused = false;
  42706. textHolder->stopTimer();
  42707. caretFlashState = false;
  42708. postCommandMessage (TextEditorDefs::focusLossMessageId);
  42709. repaint();
  42710. }
  42711. void TextEditor::resized()
  42712. {
  42713. viewport->setBoundsInset (borderSize);
  42714. viewport->setSingleStepSizes (16, roundToInt (currentFont.getHeight()));
  42715. updateTextHolderSize();
  42716. if (! isMultiLine())
  42717. {
  42718. scrollToMakeSureCursorIsVisible();
  42719. }
  42720. else
  42721. {
  42722. updateCaretPosition();
  42723. }
  42724. }
  42725. void TextEditor::handleCommandMessage (const int commandId)
  42726. {
  42727. Component::BailOutChecker checker (this);
  42728. switch (commandId)
  42729. {
  42730. case TextEditorDefs::textChangeMessageId:
  42731. listeners.callChecked (checker, &TextEditorListener::textEditorTextChanged, (TextEditor&) *this);
  42732. break;
  42733. case TextEditorDefs::returnKeyMessageId:
  42734. listeners.callChecked (checker, &TextEditorListener::textEditorReturnKeyPressed, (TextEditor&) *this);
  42735. break;
  42736. case TextEditorDefs::escapeKeyMessageId:
  42737. listeners.callChecked (checker, &TextEditorListener::textEditorEscapeKeyPressed, (TextEditor&) *this);
  42738. break;
  42739. case TextEditorDefs::focusLossMessageId:
  42740. listeners.callChecked (checker, &TextEditorListener::textEditorFocusLost, (TextEditor&) *this);
  42741. break;
  42742. default:
  42743. jassertfalse
  42744. break;
  42745. }
  42746. }
  42747. void TextEditor::enablementChanged()
  42748. {
  42749. setMouseCursor (isReadOnly() ? MouseCursor::NormalCursor
  42750. : MouseCursor::IBeamCursor);
  42751. repaint();
  42752. }
  42753. UndoManager* TextEditor::getUndoManager() throw()
  42754. {
  42755. return isReadOnly() ? &undoManager : 0;
  42756. }
  42757. void TextEditor::clearInternal (UndoManager* const um)
  42758. {
  42759. remove (Range<int> (0, getTotalNumChars()), um, caretPosition);
  42760. }
  42761. void TextEditor::insert (const String& text,
  42762. const int insertIndex,
  42763. const Font& font,
  42764. const Colour& colour,
  42765. UndoManager* const um,
  42766. const int caretPositionToMoveTo)
  42767. {
  42768. if (text.isNotEmpty())
  42769. {
  42770. if (um != 0)
  42771. {
  42772. if (um->getNumActionsInCurrentTransaction() > TextEditorDefs::maxActionsPerTransaction)
  42773. newTransaction();
  42774. um->perform (new TextEditorInsertAction (*this,
  42775. text,
  42776. insertIndex,
  42777. font,
  42778. colour,
  42779. caretPosition,
  42780. caretPositionToMoveTo));
  42781. }
  42782. else
  42783. {
  42784. repaintText (Range<int> (insertIndex, getTotalNumChars())); // must do this before and after changing the data, in case
  42785. // a line gets moved due to word wrap
  42786. int index = 0;
  42787. int nextIndex = 0;
  42788. for (int i = 0; i < sections.size(); ++i)
  42789. {
  42790. nextIndex = index + ((UniformTextSection*) sections.getUnchecked(i))->getTotalLength();
  42791. if (insertIndex == index)
  42792. {
  42793. sections.insert (i, new UniformTextSection (text,
  42794. font, colour,
  42795. passwordCharacter));
  42796. break;
  42797. }
  42798. else if (insertIndex > index && insertIndex < nextIndex)
  42799. {
  42800. splitSection (i, insertIndex - index);
  42801. sections.insert (i + 1, new UniformTextSection (text,
  42802. font, colour,
  42803. passwordCharacter));
  42804. break;
  42805. }
  42806. index = nextIndex;
  42807. }
  42808. if (nextIndex == insertIndex)
  42809. sections.add (new UniformTextSection (text,
  42810. font, colour,
  42811. passwordCharacter));
  42812. coalesceSimilarSections();
  42813. totalNumChars = -1;
  42814. valueTextNeedsUpdating = true;
  42815. moveCursorTo (caretPositionToMoveTo, false);
  42816. repaintText (Range<int> (insertIndex, getTotalNumChars()));
  42817. }
  42818. }
  42819. }
  42820. void TextEditor::reinsert (const int insertIndex,
  42821. const VoidArray& sectionsToInsert)
  42822. {
  42823. int index = 0;
  42824. int nextIndex = 0;
  42825. for (int i = 0; i < sections.size(); ++i)
  42826. {
  42827. nextIndex = index + ((UniformTextSection*) sections.getUnchecked(i))->getTotalLength();
  42828. if (insertIndex == index)
  42829. {
  42830. for (int j = sectionsToInsert.size(); --j >= 0;)
  42831. sections.insert (i, new UniformTextSection (*(UniformTextSection*) sectionsToInsert.getUnchecked(j)));
  42832. break;
  42833. }
  42834. else if (insertIndex > index && insertIndex < nextIndex)
  42835. {
  42836. splitSection (i, insertIndex - index);
  42837. for (int j = sectionsToInsert.size(); --j >= 0;)
  42838. sections.insert (i + 1, new UniformTextSection (*(UniformTextSection*) sectionsToInsert.getUnchecked(j)));
  42839. break;
  42840. }
  42841. index = nextIndex;
  42842. }
  42843. if (nextIndex == insertIndex)
  42844. {
  42845. for (int j = 0; j < sectionsToInsert.size(); ++j)
  42846. sections.add (new UniformTextSection (*(UniformTextSection*) sectionsToInsert.getUnchecked(j)));
  42847. }
  42848. coalesceSimilarSections();
  42849. totalNumChars = -1;
  42850. valueTextNeedsUpdating = true;
  42851. }
  42852. void TextEditor::remove (const Range<int>& range,
  42853. UndoManager* const um,
  42854. const int caretPositionToMoveTo)
  42855. {
  42856. if (! range.isEmpty())
  42857. {
  42858. int index = 0;
  42859. for (int i = 0; i < sections.size(); ++i)
  42860. {
  42861. const int nextIndex = index + ((UniformTextSection*) sections[i])->getTotalLength();
  42862. if (range.getStart() > index && range.getStart() < nextIndex)
  42863. {
  42864. splitSection (i, range.getStart() - index);
  42865. --i;
  42866. }
  42867. else if (range.getEnd() > index && range.getEnd() < nextIndex)
  42868. {
  42869. splitSection (i, range.getEnd() - index);
  42870. --i;
  42871. }
  42872. else
  42873. {
  42874. index = nextIndex;
  42875. if (index > range.getEnd())
  42876. break;
  42877. }
  42878. }
  42879. index = 0;
  42880. if (um != 0)
  42881. {
  42882. VoidArray removedSections;
  42883. for (int i = 0; i < sections.size(); ++i)
  42884. {
  42885. if (range.getEnd() <= range.getStart())
  42886. break;
  42887. UniformTextSection* const section = (UniformTextSection*) sections.getUnchecked (i);
  42888. const int nextIndex = index + section->getTotalLength();
  42889. if (range.getStart() <= index && range.getEnd() >= nextIndex)
  42890. removedSections.add (new UniformTextSection (*section));
  42891. index = nextIndex;
  42892. }
  42893. if (um->getNumActionsInCurrentTransaction() > TextEditorDefs::maxActionsPerTransaction)
  42894. newTransaction();
  42895. um->perform (new TextEditorRemoveAction (*this,
  42896. range,
  42897. caretPosition,
  42898. caretPositionToMoveTo,
  42899. removedSections));
  42900. }
  42901. else
  42902. {
  42903. Range<int> remainingRange (range);
  42904. for (int i = 0; i < sections.size(); ++i)
  42905. {
  42906. UniformTextSection* const section = (UniformTextSection*) sections.getUnchecked (i);
  42907. const int nextIndex = index + section->getTotalLength();
  42908. if (remainingRange.getStart() <= index && remainingRange.getEnd() >= nextIndex)
  42909. {
  42910. sections.remove(i);
  42911. section->clear();
  42912. delete section;
  42913. remainingRange.setEnd (remainingRange.getEnd() - (nextIndex - index));
  42914. if (remainingRange.isEmpty())
  42915. break;
  42916. --i;
  42917. }
  42918. else
  42919. {
  42920. index = nextIndex;
  42921. }
  42922. }
  42923. coalesceSimilarSections();
  42924. totalNumChars = -1;
  42925. valueTextNeedsUpdating = true;
  42926. moveCursorTo (caretPositionToMoveTo, false);
  42927. repaintText (Range<int> (range.getStart(), getTotalNumChars()));
  42928. }
  42929. }
  42930. }
  42931. const String TextEditor::getText() const
  42932. {
  42933. String t;
  42934. t.preallocateStorage (getTotalNumChars());
  42935. String::Concatenator concatenator (t);
  42936. for (int i = 0; i < sections.size(); ++i)
  42937. ((const UniformTextSection*) sections.getUnchecked(i))->appendAllText (concatenator);
  42938. return t;
  42939. }
  42940. const String TextEditor::getTextInRange (const Range<int>& range) const
  42941. {
  42942. String t;
  42943. if (! range.isEmpty())
  42944. {
  42945. t.preallocateStorage (jmin (getTotalNumChars(), range.getLength()));
  42946. String::Concatenator concatenator (t);
  42947. int index = 0;
  42948. for (int i = 0; i < sections.size(); ++i)
  42949. {
  42950. const UniformTextSection* const s = (const UniformTextSection*) sections.getUnchecked(i);
  42951. const int nextIndex = index + s->getTotalLength();
  42952. if (range.getStart() < nextIndex)
  42953. {
  42954. if (range.getEnd() <= index)
  42955. break;
  42956. s->appendSubstring (concatenator, range - index);
  42957. }
  42958. index = nextIndex;
  42959. }
  42960. }
  42961. return t;
  42962. }
  42963. const String TextEditor::getHighlightedText() const
  42964. {
  42965. return getTextInRange (selection);
  42966. }
  42967. int TextEditor::getTotalNumChars() const
  42968. {
  42969. if (totalNumChars < 0)
  42970. {
  42971. totalNumChars = 0;
  42972. for (int i = sections.size(); --i >= 0;)
  42973. totalNumChars += ((const UniformTextSection*) sections.getUnchecked(i))->getTotalLength();
  42974. }
  42975. return totalNumChars;
  42976. }
  42977. bool TextEditor::isEmpty() const
  42978. {
  42979. return getTotalNumChars() == 0;
  42980. }
  42981. void TextEditor::getCharPosition (const int index, float& cx, float& cy, float& lineHeight) const
  42982. {
  42983. const float wordWrapWidth = getWordWrapWidth();
  42984. if (wordWrapWidth > 0 && sections.size() > 0)
  42985. {
  42986. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  42987. i.getCharPosition (index, cx, cy, lineHeight);
  42988. }
  42989. else
  42990. {
  42991. cx = cy = 0;
  42992. lineHeight = currentFont.getHeight();
  42993. }
  42994. }
  42995. int TextEditor::indexAtPosition (const float x, const float y)
  42996. {
  42997. const float wordWrapWidth = getWordWrapWidth();
  42998. if (wordWrapWidth > 0)
  42999. {
  43000. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  43001. while (i.next())
  43002. {
  43003. if (i.lineY + i.lineHeight > y)
  43004. {
  43005. if (i.lineY > y)
  43006. return jmax (0, i.indexInText - 1);
  43007. if (i.atomX >= x)
  43008. return i.indexInText;
  43009. if (x < i.atomRight)
  43010. return i.xToIndex (x);
  43011. }
  43012. }
  43013. }
  43014. return getTotalNumChars();
  43015. }
  43016. static int getCharacterCategory (const tchar character)
  43017. {
  43018. return CharacterFunctions::isLetterOrDigit (character)
  43019. ? 2 : (CharacterFunctions::isWhitespace (character) ? 0 : 1);
  43020. }
  43021. int TextEditor::findWordBreakAfter (const int position) const
  43022. {
  43023. const String t (getTextInRange (Range<int> (position, position + 512)));
  43024. const int totalLength = t.length();
  43025. int i = 0;
  43026. while (i < totalLength && CharacterFunctions::isWhitespace (t[i]))
  43027. ++i;
  43028. const int type = getCharacterCategory (t[i]);
  43029. while (i < totalLength && type == getCharacterCategory (t[i]))
  43030. ++i;
  43031. while (i < totalLength && CharacterFunctions::isWhitespace (t[i]))
  43032. ++i;
  43033. return position + i;
  43034. }
  43035. int TextEditor::findWordBreakBefore (const int position) const
  43036. {
  43037. if (position <= 0)
  43038. return 0;
  43039. const int startOfBuffer = jmax (0, position - 512);
  43040. const String t (getTextInRange (Range<int> (startOfBuffer, position)));
  43041. int i = position - startOfBuffer;
  43042. while (i > 0 && CharacterFunctions::isWhitespace (t [i - 1]))
  43043. --i;
  43044. if (i > 0)
  43045. {
  43046. const int type = getCharacterCategory (t [i - 1]);
  43047. while (i > 0 && type == getCharacterCategory (t [i - 1]))
  43048. --i;
  43049. }
  43050. jassert (startOfBuffer + i >= 0);
  43051. return startOfBuffer + i;
  43052. }
  43053. void TextEditor::splitSection (const int sectionIndex,
  43054. const int charToSplitAt)
  43055. {
  43056. jassert (sections[sectionIndex] != 0);
  43057. sections.insert (sectionIndex + 1,
  43058. ((UniformTextSection*) sections.getUnchecked (sectionIndex))
  43059. ->split (charToSplitAt, passwordCharacter));
  43060. }
  43061. void TextEditor::coalesceSimilarSections()
  43062. {
  43063. for (int i = 0; i < sections.size() - 1; ++i)
  43064. {
  43065. UniformTextSection* const s1 = (UniformTextSection*) sections.getUnchecked (i);
  43066. UniformTextSection* const s2 = (UniformTextSection*) sections.getUnchecked (i + 1);
  43067. if (s1->font == s2->font
  43068. && s1->colour == s2->colour)
  43069. {
  43070. s1->append (*s2, passwordCharacter);
  43071. sections.remove (i + 1);
  43072. delete s2;
  43073. --i;
  43074. }
  43075. }
  43076. }
  43077. END_JUCE_NAMESPACE
  43078. /*** End of inlined file: juce_TextEditor.cpp ***/
  43079. /*** Start of inlined file: juce_Toolbar.cpp ***/
  43080. BEGIN_JUCE_NAMESPACE
  43081. const tchar* const Toolbar::toolbarDragDescriptor = T("_toolbarItem_");
  43082. class ToolbarSpacerComp : public ToolbarItemComponent
  43083. {
  43084. public:
  43085. ToolbarSpacerComp (const int itemId_, const float fixedSize_, const bool drawBar_)
  43086. : ToolbarItemComponent (itemId_, String::empty, false),
  43087. fixedSize (fixedSize_),
  43088. drawBar (drawBar_)
  43089. {
  43090. }
  43091. ~ToolbarSpacerComp()
  43092. {
  43093. }
  43094. bool getToolbarItemSizes (int toolbarThickness, bool /*isToolbarVertical*/,
  43095. int& preferredSize, int& minSize, int& maxSize)
  43096. {
  43097. if (fixedSize <= 0)
  43098. {
  43099. preferredSize = toolbarThickness * 2;
  43100. minSize = 4;
  43101. maxSize = 32768;
  43102. }
  43103. else
  43104. {
  43105. maxSize = roundToInt (toolbarThickness * fixedSize);
  43106. minSize = drawBar ? maxSize : jmin (4, maxSize);
  43107. preferredSize = maxSize;
  43108. if (getEditingMode() == editableOnPalette)
  43109. preferredSize = maxSize = toolbarThickness / (drawBar ? 3 : 2);
  43110. }
  43111. return true;
  43112. }
  43113. void paintButtonArea (Graphics&, int, int, bool, bool)
  43114. {
  43115. }
  43116. void contentAreaChanged (const Rectangle<int>&)
  43117. {
  43118. }
  43119. int getResizeOrder() const throw()
  43120. {
  43121. return fixedSize <= 0 ? 0 : 1;
  43122. }
  43123. void paint (Graphics& g)
  43124. {
  43125. const int w = getWidth();
  43126. const int h = getHeight();
  43127. if (drawBar)
  43128. {
  43129. g.setColour (findColour (Toolbar::separatorColourId, true));
  43130. const float thickness = 0.2f;
  43131. if (isToolbarVertical())
  43132. g.fillRect (w * 0.1f, h * (0.5f - thickness * 0.5f), w * 0.8f, h * thickness);
  43133. else
  43134. g.fillRect (w * (0.5f - thickness * 0.5f), h * 0.1f, w * thickness, h * 0.8f);
  43135. }
  43136. if (getEditingMode() != normalMode && ! drawBar)
  43137. {
  43138. g.setColour (findColour (Toolbar::separatorColourId, true));
  43139. const int indentX = jmin (2, (w - 3) / 2);
  43140. const int indentY = jmin (2, (h - 3) / 2);
  43141. g.drawRect (indentX, indentY, w - indentX * 2, h - indentY * 2, 1);
  43142. if (fixedSize <= 0)
  43143. {
  43144. float x1, y1, x2, y2, x3, y3, x4, y4, hw, hl;
  43145. if (isToolbarVertical())
  43146. {
  43147. x1 = w * 0.5f;
  43148. y1 = h * 0.4f;
  43149. x2 = x1;
  43150. y2 = indentX * 2.0f;
  43151. x3 = x1;
  43152. y3 = h * 0.6f;
  43153. x4 = x1;
  43154. y4 = h - y2;
  43155. hw = w * 0.15f;
  43156. hl = w * 0.2f;
  43157. }
  43158. else
  43159. {
  43160. x1 = w * 0.4f;
  43161. y1 = h * 0.5f;
  43162. x2 = indentX * 2.0f;
  43163. y2 = y1;
  43164. x3 = w * 0.6f;
  43165. y3 = y1;
  43166. x4 = w - x2;
  43167. y4 = y1;
  43168. hw = h * 0.15f;
  43169. hl = h * 0.2f;
  43170. }
  43171. Path p;
  43172. p.addArrow (x1, y1, x2, y2, 1.5f, hw, hl);
  43173. p.addArrow (x3, y3, x4, y4, 1.5f, hw, hl);
  43174. g.fillPath (p);
  43175. }
  43176. }
  43177. }
  43178. juce_UseDebuggingNewOperator
  43179. private:
  43180. const float fixedSize;
  43181. const bool drawBar;
  43182. ToolbarSpacerComp (const ToolbarSpacerComp&);
  43183. ToolbarSpacerComp& operator= (const ToolbarSpacerComp&);
  43184. };
  43185. class MissingItemsComponent : public PopupMenuCustomComponent
  43186. {
  43187. public:
  43188. MissingItemsComponent (Toolbar& owner_, const int height_)
  43189. : PopupMenuCustomComponent (true),
  43190. owner (owner_),
  43191. height (height_)
  43192. {
  43193. for (int i = owner_.items.size(); --i >= 0;)
  43194. {
  43195. ToolbarItemComponent* const tc = owner_.items.getUnchecked(i);
  43196. if (dynamic_cast <ToolbarSpacerComp*> (tc) == 0 && ! tc->isVisible())
  43197. {
  43198. oldIndexes.insert (0, i);
  43199. addAndMakeVisible (tc, 0);
  43200. }
  43201. }
  43202. layout (400);
  43203. }
  43204. ~MissingItemsComponent()
  43205. {
  43206. // deleting the toolbar while its menu it open??
  43207. jassert (owner.isValidComponent());
  43208. for (int i = 0; i < getNumChildComponents(); ++i)
  43209. {
  43210. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getChildComponent (i));
  43211. if (tc != 0)
  43212. {
  43213. tc->setVisible (false);
  43214. const int index = oldIndexes.remove (i);
  43215. owner.addChildComponent (tc, index);
  43216. --i;
  43217. }
  43218. }
  43219. owner.resized();
  43220. }
  43221. void layout (const int preferredWidth)
  43222. {
  43223. const int indent = 8;
  43224. int x = indent;
  43225. int y = indent;
  43226. int maxX = 0;
  43227. for (int i = 0; i < getNumChildComponents(); ++i)
  43228. {
  43229. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getChildComponent (i));
  43230. if (tc != 0)
  43231. {
  43232. int preferredSize = 1, minSize = 1, maxSize = 1;
  43233. if (tc->getToolbarItemSizes (height, false, preferredSize, minSize, maxSize))
  43234. {
  43235. if (x + preferredSize > preferredWidth && x > indent)
  43236. {
  43237. x = indent;
  43238. y += height;
  43239. }
  43240. tc->setBounds (x, y, preferredSize, height);
  43241. x += preferredSize;
  43242. maxX = jmax (maxX, x);
  43243. }
  43244. }
  43245. }
  43246. setSize (maxX + 8, y + height + 8);
  43247. }
  43248. void getIdealSize (int& idealWidth, int& idealHeight)
  43249. {
  43250. idealWidth = getWidth();
  43251. idealHeight = getHeight();
  43252. }
  43253. juce_UseDebuggingNewOperator
  43254. private:
  43255. Toolbar& owner;
  43256. const int height;
  43257. Array <int> oldIndexes;
  43258. MissingItemsComponent (const MissingItemsComponent&);
  43259. MissingItemsComponent& operator= (const MissingItemsComponent&);
  43260. };
  43261. Toolbar::Toolbar()
  43262. : vertical (false),
  43263. isEditingActive (false),
  43264. toolbarStyle (Toolbar::iconsOnly)
  43265. {
  43266. addChildComponent (missingItemsButton = getLookAndFeel().createToolbarMissingItemsButton (*this));
  43267. missingItemsButton->setAlwaysOnTop (true);
  43268. missingItemsButton->addButtonListener (this);
  43269. }
  43270. Toolbar::~Toolbar()
  43271. {
  43272. animator.cancelAllAnimations (true);
  43273. deleteAllChildren();
  43274. }
  43275. void Toolbar::setVertical (const bool shouldBeVertical)
  43276. {
  43277. if (vertical != shouldBeVertical)
  43278. {
  43279. vertical = shouldBeVertical;
  43280. resized();
  43281. }
  43282. }
  43283. void Toolbar::clear()
  43284. {
  43285. for (int i = items.size(); --i >= 0;)
  43286. {
  43287. ToolbarItemComponent* const tc = items.getUnchecked(i);
  43288. items.remove (i);
  43289. delete tc;
  43290. }
  43291. resized();
  43292. }
  43293. ToolbarItemComponent* Toolbar::createItem (ToolbarItemFactory& factory, const int itemId)
  43294. {
  43295. if (itemId == ToolbarItemFactory::separatorBarId)
  43296. return new ToolbarSpacerComp (itemId, 0.1f, true);
  43297. else if (itemId == ToolbarItemFactory::spacerId)
  43298. return new ToolbarSpacerComp (itemId, 0.5f, false);
  43299. else if (itemId == ToolbarItemFactory::flexibleSpacerId)
  43300. return new ToolbarSpacerComp (itemId, 0, false);
  43301. return factory.createItem (itemId);
  43302. }
  43303. void Toolbar::addItemInternal (ToolbarItemFactory& factory,
  43304. const int itemId,
  43305. const int insertIndex)
  43306. {
  43307. // An ID can't be zero - this might indicate a mistake somewhere?
  43308. jassert (itemId != 0);
  43309. ToolbarItemComponent* const tc = createItem (factory, itemId);
  43310. if (tc != 0)
  43311. {
  43312. #ifdef JUCE_DEBUG
  43313. Array <int> allowedIds;
  43314. factory.getAllToolbarItemIds (allowedIds);
  43315. // If your factory can create an item for a given ID, it must also return
  43316. // that ID from its getAllToolbarItemIds() method!
  43317. jassert (allowedIds.contains (itemId));
  43318. #endif
  43319. items.insert (insertIndex, tc);
  43320. addAndMakeVisible (tc, insertIndex);
  43321. }
  43322. }
  43323. void Toolbar::addItem (ToolbarItemFactory& factory,
  43324. const int itemId,
  43325. const int insertIndex)
  43326. {
  43327. addItemInternal (factory, itemId, insertIndex);
  43328. resized();
  43329. }
  43330. void Toolbar::addDefaultItems (ToolbarItemFactory& factoryToUse)
  43331. {
  43332. Array <int> ids;
  43333. factoryToUse.getDefaultItemSet (ids);
  43334. clear();
  43335. for (int i = 0; i < ids.size(); ++i)
  43336. addItemInternal (factoryToUse, ids.getUnchecked (i), -1);
  43337. resized();
  43338. }
  43339. void Toolbar::removeToolbarItem (const int itemIndex)
  43340. {
  43341. ToolbarItemComponent* const tc = getItemComponent (itemIndex);
  43342. if (tc != 0)
  43343. {
  43344. items.removeValue (tc);
  43345. delete tc;
  43346. resized();
  43347. }
  43348. }
  43349. int Toolbar::getNumItems() const throw()
  43350. {
  43351. return items.size();
  43352. }
  43353. int Toolbar::getItemId (const int itemIndex) const throw()
  43354. {
  43355. ToolbarItemComponent* const tc = getItemComponent (itemIndex);
  43356. return tc != 0 ? tc->getItemId() : 0;
  43357. }
  43358. ToolbarItemComponent* Toolbar::getItemComponent (const int itemIndex) const throw()
  43359. {
  43360. return items [itemIndex];
  43361. }
  43362. ToolbarItemComponent* Toolbar::getNextActiveComponent (int index, const int delta) const
  43363. {
  43364. for (;;)
  43365. {
  43366. index += delta;
  43367. ToolbarItemComponent* const tc = getItemComponent (index);
  43368. if (tc == 0)
  43369. break;
  43370. if (tc->isActive)
  43371. return tc;
  43372. }
  43373. return 0;
  43374. }
  43375. void Toolbar::setStyle (const ToolbarItemStyle& newStyle)
  43376. {
  43377. if (toolbarStyle != newStyle)
  43378. {
  43379. toolbarStyle = newStyle;
  43380. updateAllItemPositions (false);
  43381. }
  43382. }
  43383. const String Toolbar::toString() const
  43384. {
  43385. String s (T("TB:"));
  43386. for (int i = 0; i < getNumItems(); ++i)
  43387. s << getItemId(i) << T(' ');
  43388. return s.trimEnd();
  43389. }
  43390. bool Toolbar::restoreFromString (ToolbarItemFactory& factoryToUse,
  43391. const String& savedVersion)
  43392. {
  43393. if (! savedVersion.startsWith (T("TB:")))
  43394. return false;
  43395. StringArray tokens;
  43396. tokens.addTokens (savedVersion.substring (3), false);
  43397. clear();
  43398. for (int i = 0; i < tokens.size(); ++i)
  43399. addItemInternal (factoryToUse, tokens[i].getIntValue(), -1);
  43400. resized();
  43401. return true;
  43402. }
  43403. void Toolbar::paint (Graphics& g)
  43404. {
  43405. getLookAndFeel().paintToolbarBackground (g, getWidth(), getHeight(), *this);
  43406. }
  43407. int Toolbar::getThickness() const throw()
  43408. {
  43409. return vertical ? getWidth() : getHeight();
  43410. }
  43411. int Toolbar::getLength() const throw()
  43412. {
  43413. return vertical ? getHeight() : getWidth();
  43414. }
  43415. void Toolbar::setEditingActive (const bool active)
  43416. {
  43417. if (isEditingActive != active)
  43418. {
  43419. isEditingActive = active;
  43420. updateAllItemPositions (false);
  43421. }
  43422. }
  43423. void Toolbar::resized()
  43424. {
  43425. updateAllItemPositions (false);
  43426. }
  43427. void Toolbar::updateAllItemPositions (const bool animate)
  43428. {
  43429. if (getWidth() > 0 && getHeight() > 0)
  43430. {
  43431. StretchableObjectResizer resizer;
  43432. int i;
  43433. for (i = 0; i < items.size(); ++i)
  43434. {
  43435. ToolbarItemComponent* const tc = items.getUnchecked(i);
  43436. tc->setEditingMode (isEditingActive ? ToolbarItemComponent::editableOnToolbar
  43437. : ToolbarItemComponent::normalMode);
  43438. tc->setStyle (toolbarStyle);
  43439. ToolbarSpacerComp* const spacer = dynamic_cast <ToolbarSpacerComp*> (tc);
  43440. int preferredSize = 1, minSize = 1, maxSize = 1;
  43441. if (tc->getToolbarItemSizes (getThickness(), isVertical(),
  43442. preferredSize, minSize, maxSize))
  43443. {
  43444. tc->isActive = true;
  43445. resizer.addItem (preferredSize, minSize, maxSize,
  43446. spacer != 0 ? spacer->getResizeOrder() : 2);
  43447. }
  43448. else
  43449. {
  43450. tc->isActive = false;
  43451. tc->setVisible (false);
  43452. }
  43453. }
  43454. resizer.resizeToFit (getLength());
  43455. int totalLength = 0;
  43456. for (i = 0; i < resizer.getNumItems(); ++i)
  43457. totalLength += (int) resizer.getItemSize (i);
  43458. const bool itemsOffTheEnd = totalLength > getLength();
  43459. const int extrasButtonSize = getThickness() / 2;
  43460. missingItemsButton->setSize (extrasButtonSize, extrasButtonSize);
  43461. missingItemsButton->setVisible (itemsOffTheEnd);
  43462. missingItemsButton->setEnabled (! isEditingActive);
  43463. if (vertical)
  43464. missingItemsButton->setCentrePosition (getWidth() / 2,
  43465. getHeight() - 4 - extrasButtonSize / 2);
  43466. else
  43467. missingItemsButton->setCentrePosition (getWidth() - 4 - extrasButtonSize / 2,
  43468. getHeight() / 2);
  43469. const int maxLength = itemsOffTheEnd ? (vertical ? missingItemsButton->getY()
  43470. : missingItemsButton->getX()) - 4
  43471. : getLength();
  43472. int pos = 0, activeIndex = 0;
  43473. for (i = 0; i < items.size(); ++i)
  43474. {
  43475. ToolbarItemComponent* const tc = items.getUnchecked(i);
  43476. if (tc->isActive)
  43477. {
  43478. const int size = (int) resizer.getItemSize (activeIndex++);
  43479. Rectangle<int> newBounds;
  43480. if (vertical)
  43481. newBounds.setBounds (0, pos, getWidth(), size);
  43482. else
  43483. newBounds.setBounds (pos, 0, size, getHeight());
  43484. if (animate)
  43485. {
  43486. animator.animateComponent (tc, newBounds, 200, 3.0, 0.0);
  43487. }
  43488. else
  43489. {
  43490. animator.cancelAnimation (tc, false);
  43491. tc->setBounds (newBounds);
  43492. }
  43493. pos += size;
  43494. tc->setVisible (pos <= maxLength
  43495. && ((! tc->isBeingDragged)
  43496. || tc->getEditingMode() == ToolbarItemComponent::editableOnPalette));
  43497. }
  43498. }
  43499. }
  43500. }
  43501. void Toolbar::buttonClicked (Button*)
  43502. {
  43503. jassert (missingItemsButton->isShowing());
  43504. if (missingItemsButton->isShowing())
  43505. {
  43506. PopupMenu m;
  43507. m.addCustomItem (1, new MissingItemsComponent (*this, getThickness()));
  43508. m.showAt (missingItemsButton);
  43509. }
  43510. }
  43511. bool Toolbar::isInterestedInDragSource (const String& sourceDescription,
  43512. Component* /*sourceComponent*/)
  43513. {
  43514. return sourceDescription == toolbarDragDescriptor && isEditingActive;
  43515. }
  43516. void Toolbar::itemDragMove (const String&, Component* sourceComponent, int x, int y)
  43517. {
  43518. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (sourceComponent);
  43519. if (tc != 0)
  43520. {
  43521. if (getNumItems() == 0)
  43522. {
  43523. if (tc->getEditingMode() == ToolbarItemComponent::editableOnPalette)
  43524. {
  43525. ToolbarItemPalette* const palette = tc->findParentComponentOfClass ((ToolbarItemPalette*) 0);
  43526. if (palette != 0)
  43527. palette->replaceComponent (tc);
  43528. }
  43529. else
  43530. {
  43531. jassert (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar);
  43532. }
  43533. items.add (tc);
  43534. addChildComponent (tc);
  43535. updateAllItemPositions (false);
  43536. }
  43537. else
  43538. {
  43539. for (int i = getNumItems(); --i >= 0;)
  43540. {
  43541. int currentIndex = getIndexOfChildComponent (tc);
  43542. if (currentIndex < 0)
  43543. {
  43544. if (tc->getEditingMode() == ToolbarItemComponent::editableOnPalette)
  43545. {
  43546. ToolbarItemPalette* const palette = tc->findParentComponentOfClass ((ToolbarItemPalette*) 0);
  43547. if (palette != 0)
  43548. palette->replaceComponent (tc);
  43549. }
  43550. else
  43551. {
  43552. jassert (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar);
  43553. }
  43554. items.add (tc);
  43555. addChildComponent (tc);
  43556. currentIndex = getIndexOfChildComponent (tc);
  43557. updateAllItemPositions (true);
  43558. }
  43559. int newIndex = currentIndex;
  43560. const int dragObjectLeft = vertical ? (y - tc->dragOffsetY) : (x - tc->dragOffsetX);
  43561. const int dragObjectRight = dragObjectLeft + (vertical ? tc->getHeight() : tc->getWidth());
  43562. const Rectangle<int> current (animator.getComponentDestination (getChildComponent (newIndex)));
  43563. ToolbarItemComponent* const prev = getNextActiveComponent (newIndex, -1);
  43564. if (prev != 0)
  43565. {
  43566. const Rectangle<int> previousPos (animator.getComponentDestination (prev));
  43567. if (abs (dragObjectLeft - (vertical ? previousPos.getY() : previousPos.getX())
  43568. < abs (dragObjectRight - (vertical ? current.getBottom() : current.getRight()))))
  43569. {
  43570. newIndex = getIndexOfChildComponent (prev);
  43571. }
  43572. }
  43573. ToolbarItemComponent* const next = getNextActiveComponent (newIndex, 1);
  43574. if (next != 0)
  43575. {
  43576. const Rectangle<int> nextPos (animator.getComponentDestination (next));
  43577. if (abs (dragObjectLeft - (vertical ? current.getY() : current.getX())
  43578. > abs (dragObjectRight - (vertical ? nextPos.getBottom() : nextPos.getRight()))))
  43579. {
  43580. newIndex = getIndexOfChildComponent (next) + 1;
  43581. }
  43582. }
  43583. if (newIndex != currentIndex)
  43584. {
  43585. items.removeValue (tc);
  43586. removeChildComponent (tc);
  43587. addChildComponent (tc, newIndex);
  43588. items.insert (newIndex, tc);
  43589. updateAllItemPositions (true);
  43590. }
  43591. else
  43592. {
  43593. break;
  43594. }
  43595. }
  43596. }
  43597. }
  43598. }
  43599. void Toolbar::itemDragExit (const String&, Component* sourceComponent)
  43600. {
  43601. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (sourceComponent);
  43602. if (tc != 0)
  43603. {
  43604. if (isParentOf (tc))
  43605. {
  43606. items.removeValue (tc);
  43607. removeChildComponent (tc);
  43608. updateAllItemPositions (true);
  43609. }
  43610. }
  43611. }
  43612. void Toolbar::itemDropped (const String&, Component*, int, int)
  43613. {
  43614. }
  43615. void Toolbar::mouseDown (const MouseEvent& e)
  43616. {
  43617. if (e.mods.isPopupMenu())
  43618. {
  43619. }
  43620. }
  43621. class ToolbarCustomisationDialog : public DialogWindow
  43622. {
  43623. public:
  43624. ToolbarCustomisationDialog (ToolbarItemFactory& factory,
  43625. Toolbar* const toolbar_,
  43626. const int optionFlags)
  43627. : DialogWindow (TRANS("Add/remove items from toolbar"), Colours::white, true, true),
  43628. toolbar (toolbar_)
  43629. {
  43630. setContentComponent (new CustomiserPanel (factory, toolbar, optionFlags), true, true);
  43631. setResizable (true, true);
  43632. setResizeLimits (400, 300, 1500, 1000);
  43633. positionNearBar();
  43634. }
  43635. ~ToolbarCustomisationDialog()
  43636. {
  43637. setContentComponent (0, true);
  43638. }
  43639. void closeButtonPressed()
  43640. {
  43641. setVisible (false);
  43642. }
  43643. bool canModalEventBeSentToComponent (const Component* comp)
  43644. {
  43645. return toolbar->isParentOf (comp);
  43646. }
  43647. void positionNearBar()
  43648. {
  43649. const Rectangle<int> screenSize (toolbar->getParentMonitorArea());
  43650. const int tbx = toolbar->getScreenX();
  43651. const int tby = toolbar->getScreenY();
  43652. const int gap = 8;
  43653. int x, y;
  43654. if (toolbar->isVertical())
  43655. {
  43656. y = tby;
  43657. if (tbx > screenSize.getCentreX())
  43658. x = tbx - getWidth() - gap;
  43659. else
  43660. x = tbx + toolbar->getWidth() + gap;
  43661. }
  43662. else
  43663. {
  43664. x = tbx + (toolbar->getWidth() - getWidth()) / 2;
  43665. if (tby > screenSize.getCentreY())
  43666. y = tby - getHeight() - gap;
  43667. else
  43668. y = tby + toolbar->getHeight() + gap;
  43669. }
  43670. setTopLeftPosition (x, y);
  43671. }
  43672. private:
  43673. Toolbar* const toolbar;
  43674. class CustomiserPanel : public Component,
  43675. private ComboBoxListener,
  43676. private ButtonListener
  43677. {
  43678. public:
  43679. CustomiserPanel (ToolbarItemFactory& factory_,
  43680. Toolbar* const toolbar_,
  43681. const int optionFlags)
  43682. : factory (factory_),
  43683. toolbar (toolbar_),
  43684. styleBox (0),
  43685. defaultButton (0)
  43686. {
  43687. addAndMakeVisible (palette = new ToolbarItemPalette (factory, toolbar));
  43688. if ((optionFlags & (Toolbar::allowIconsOnlyChoice
  43689. | Toolbar::allowIconsWithTextChoice
  43690. | Toolbar::allowTextOnlyChoice)) != 0)
  43691. {
  43692. addAndMakeVisible (styleBox = new ComboBox (String::empty));
  43693. styleBox->setEditableText (false);
  43694. if ((optionFlags & Toolbar::allowIconsOnlyChoice) != 0)
  43695. styleBox->addItem (TRANS("Show icons only"), 1);
  43696. if ((optionFlags & Toolbar::allowIconsWithTextChoice) != 0)
  43697. styleBox->addItem (TRANS("Show icons and descriptions"), 2);
  43698. if ((optionFlags & Toolbar::allowTextOnlyChoice) != 0)
  43699. styleBox->addItem (TRANS("Show descriptions only"), 3);
  43700. if (toolbar_->getStyle() == Toolbar::iconsOnly)
  43701. styleBox->setSelectedId (1);
  43702. else if (toolbar_->getStyle() == Toolbar::iconsWithText)
  43703. styleBox->setSelectedId (2);
  43704. else if (toolbar_->getStyle() == Toolbar::textOnly)
  43705. styleBox->setSelectedId (3);
  43706. styleBox->addListener (this);
  43707. }
  43708. if ((optionFlags & Toolbar::showResetToDefaultsButton) != 0)
  43709. {
  43710. addAndMakeVisible (defaultButton = new TextButton (TRANS ("Restore to default set of items")));
  43711. defaultButton->addButtonListener (this);
  43712. }
  43713. addAndMakeVisible (instructions = new Label (String::empty,
  43714. 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.")));
  43715. instructions->setFont (Font (13.0f));
  43716. setSize (500, 300);
  43717. }
  43718. ~CustomiserPanel()
  43719. {
  43720. deleteAllChildren();
  43721. }
  43722. void comboBoxChanged (ComboBox*)
  43723. {
  43724. if (styleBox->getSelectedId() == 1)
  43725. toolbar->setStyle (Toolbar::iconsOnly);
  43726. else if (styleBox->getSelectedId() == 2)
  43727. toolbar->setStyle (Toolbar::iconsWithText);
  43728. else if (styleBox->getSelectedId() == 3)
  43729. toolbar->setStyle (Toolbar::textOnly);
  43730. palette->resized(); // to make it update the styles
  43731. }
  43732. void buttonClicked (Button*)
  43733. {
  43734. toolbar->addDefaultItems (factory);
  43735. }
  43736. void paint (Graphics& g)
  43737. {
  43738. Colour background;
  43739. DialogWindow* const dw = findParentComponentOfClass ((DialogWindow*) 0);
  43740. if (dw != 0)
  43741. background = dw->getBackgroundColour();
  43742. g.setColour (background.contrasting().withAlpha (0.3f));
  43743. g.fillRect (palette->getX(), palette->getBottom() - 1, palette->getWidth(), 1);
  43744. }
  43745. void resized()
  43746. {
  43747. palette->setBounds (0, 0, getWidth(), getHeight() - 120);
  43748. if (styleBox != 0)
  43749. styleBox->setBounds (10, getHeight() - 110, 200, 22);
  43750. if (defaultButton != 0)
  43751. {
  43752. defaultButton->changeWidthToFitText (22);
  43753. defaultButton->setTopLeftPosition (240, getHeight() - 110);
  43754. }
  43755. instructions->setBounds (10, getHeight() - 80, getWidth() - 20, 80);
  43756. }
  43757. private:
  43758. ToolbarItemFactory& factory;
  43759. Toolbar* const toolbar;
  43760. Label* instructions;
  43761. ToolbarItemPalette* palette;
  43762. ComboBox* styleBox;
  43763. TextButton* defaultButton;
  43764. };
  43765. };
  43766. void Toolbar::showCustomisationDialog (ToolbarItemFactory& factory, const int optionFlags)
  43767. {
  43768. setEditingActive (true);
  43769. ToolbarCustomisationDialog dw (factory, this, optionFlags);
  43770. dw.runModalLoop();
  43771. jassert (isValidComponent()); // ? deleting the toolbar while it's being edited?
  43772. setEditingActive (false);
  43773. }
  43774. END_JUCE_NAMESPACE
  43775. /*** End of inlined file: juce_Toolbar.cpp ***/
  43776. /*** Start of inlined file: juce_ToolbarItemComponent.cpp ***/
  43777. BEGIN_JUCE_NAMESPACE
  43778. ToolbarItemFactory::ToolbarItemFactory()
  43779. {
  43780. }
  43781. ToolbarItemFactory::~ToolbarItemFactory()
  43782. {
  43783. }
  43784. class ItemDragAndDropOverlayComponent : public Component
  43785. {
  43786. public:
  43787. ItemDragAndDropOverlayComponent()
  43788. : isDragging (false)
  43789. {
  43790. setAlwaysOnTop (true);
  43791. setRepaintsOnMouseActivity (true);
  43792. setMouseCursor (MouseCursor::DraggingHandCursor);
  43793. }
  43794. ~ItemDragAndDropOverlayComponent()
  43795. {
  43796. }
  43797. void paint (Graphics& g)
  43798. {
  43799. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  43800. if (isMouseOverOrDragging()
  43801. && tc != 0
  43802. && tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
  43803. {
  43804. g.setColour (findColour (Toolbar::editingModeOutlineColourId, true));
  43805. g.drawRect (0, 0, getWidth(), getHeight(),
  43806. jmin (2, (getWidth() - 1) / 2, (getHeight() - 1) / 2));
  43807. }
  43808. }
  43809. void mouseDown (const MouseEvent& e)
  43810. {
  43811. isDragging = false;
  43812. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  43813. if (tc != 0)
  43814. {
  43815. tc->dragOffsetX = e.x;
  43816. tc->dragOffsetY = e.y;
  43817. }
  43818. }
  43819. void mouseDrag (const MouseEvent& e)
  43820. {
  43821. if (! (isDragging || e.mouseWasClicked()))
  43822. {
  43823. isDragging = true;
  43824. DragAndDropContainer* const dnd = DragAndDropContainer::findParentDragContainerFor (this);
  43825. if (dnd != 0)
  43826. {
  43827. dnd->startDragging (Toolbar::toolbarDragDescriptor, getParentComponent(), 0, true);
  43828. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  43829. if (tc != 0)
  43830. {
  43831. tc->isBeingDragged = true;
  43832. if (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
  43833. tc->setVisible (false);
  43834. }
  43835. }
  43836. }
  43837. }
  43838. void mouseUp (const MouseEvent&)
  43839. {
  43840. isDragging = false;
  43841. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  43842. if (tc != 0)
  43843. {
  43844. tc->isBeingDragged = false;
  43845. Toolbar* const tb = tc->getToolbar();
  43846. if (tb != 0)
  43847. tb->updateAllItemPositions (true);
  43848. else if (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
  43849. delete tc;
  43850. }
  43851. }
  43852. void parentSizeChanged()
  43853. {
  43854. setBounds (0, 0, getParentWidth(), getParentHeight());
  43855. }
  43856. juce_UseDebuggingNewOperator
  43857. private:
  43858. bool isDragging;
  43859. ItemDragAndDropOverlayComponent (const ItemDragAndDropOverlayComponent&);
  43860. ItemDragAndDropOverlayComponent& operator= (const ItemDragAndDropOverlayComponent&);
  43861. };
  43862. ToolbarItemComponent::ToolbarItemComponent (const int itemId_,
  43863. const String& labelText,
  43864. const bool isBeingUsedAsAButton_)
  43865. : Button (labelText),
  43866. itemId (itemId_),
  43867. mode (normalMode),
  43868. toolbarStyle (Toolbar::iconsOnly),
  43869. dragOffsetX (0),
  43870. dragOffsetY (0),
  43871. isActive (true),
  43872. isBeingDragged (false),
  43873. isBeingUsedAsAButton (isBeingUsedAsAButton_)
  43874. {
  43875. // Your item ID can't be 0!
  43876. jassert (itemId_ != 0);
  43877. }
  43878. ToolbarItemComponent::~ToolbarItemComponent()
  43879. {
  43880. jassert (overlayComp == 0 || overlayComp->isValidComponent());
  43881. overlayComp = 0;
  43882. }
  43883. Toolbar* ToolbarItemComponent::getToolbar() const
  43884. {
  43885. return dynamic_cast <Toolbar*> (getParentComponent());
  43886. }
  43887. bool ToolbarItemComponent::isToolbarVertical() const
  43888. {
  43889. const Toolbar* const t = getToolbar();
  43890. return t != 0 && t->isVertical();
  43891. }
  43892. void ToolbarItemComponent::setStyle (const Toolbar::ToolbarItemStyle& newStyle)
  43893. {
  43894. if (toolbarStyle != newStyle)
  43895. {
  43896. toolbarStyle = newStyle;
  43897. repaint();
  43898. resized();
  43899. }
  43900. }
  43901. void ToolbarItemComponent::paintButton (Graphics& g, bool isMouseOver, bool isMouseDown)
  43902. {
  43903. if (isBeingUsedAsAButton)
  43904. getLookAndFeel().paintToolbarButtonBackground (g, getWidth(), getHeight(),
  43905. isMouseOver, isMouseDown, *this);
  43906. if (toolbarStyle != Toolbar::iconsOnly)
  43907. {
  43908. const int indent = contentArea.getX();
  43909. int y = indent;
  43910. int h = getHeight() - indent * 2;
  43911. if (toolbarStyle == Toolbar::iconsWithText)
  43912. {
  43913. y = contentArea.getBottom() + indent / 2;
  43914. h -= contentArea.getHeight();
  43915. }
  43916. getLookAndFeel().paintToolbarButtonLabel (g, indent, y, getWidth() - indent * 2, h,
  43917. getButtonText(), *this);
  43918. }
  43919. if (! contentArea.isEmpty())
  43920. {
  43921. g.saveState();
  43922. g.setOrigin (contentArea.getX(), contentArea.getY());
  43923. g.reduceClipRegion (0, 0, contentArea.getWidth(), contentArea.getHeight());
  43924. paintButtonArea (g, contentArea.getWidth(), contentArea.getHeight(), isMouseOver, isMouseDown);
  43925. g.restoreState();
  43926. }
  43927. }
  43928. void ToolbarItemComponent::resized()
  43929. {
  43930. if (toolbarStyle != Toolbar::textOnly)
  43931. {
  43932. const int indent = jmin (proportionOfWidth (0.08f),
  43933. proportionOfHeight (0.08f));
  43934. contentArea = Rectangle<int> (indent, indent,
  43935. getWidth() - indent * 2,
  43936. toolbarStyle == Toolbar::iconsWithText ? proportionOfHeight (0.55f)
  43937. : (getHeight() - indent * 2));
  43938. }
  43939. else
  43940. {
  43941. contentArea = Rectangle<int>();
  43942. }
  43943. contentAreaChanged (contentArea);
  43944. }
  43945. void ToolbarItemComponent::setEditingMode (const ToolbarEditingMode newMode)
  43946. {
  43947. if (mode != newMode)
  43948. {
  43949. mode = newMode;
  43950. repaint();
  43951. if (mode == normalMode)
  43952. {
  43953. jassert (overlayComp == 0 || overlayComp->isValidComponent());
  43954. overlayComp = 0;
  43955. }
  43956. else if (overlayComp == 0)
  43957. {
  43958. addAndMakeVisible (overlayComp = new ItemDragAndDropOverlayComponent());
  43959. overlayComp->parentSizeChanged();
  43960. }
  43961. resized();
  43962. }
  43963. }
  43964. END_JUCE_NAMESPACE
  43965. /*** End of inlined file: juce_ToolbarItemComponent.cpp ***/
  43966. /*** Start of inlined file: juce_ToolbarItemPalette.cpp ***/
  43967. BEGIN_JUCE_NAMESPACE
  43968. ToolbarItemPalette::ToolbarItemPalette (ToolbarItemFactory& factory_,
  43969. Toolbar* const toolbar_)
  43970. : factory (factory_),
  43971. toolbar (toolbar_)
  43972. {
  43973. Component* const itemHolder = new Component();
  43974. Array <int> allIds;
  43975. factory_.getAllToolbarItemIds (allIds);
  43976. for (int i = 0; i < allIds.size(); ++i)
  43977. {
  43978. ToolbarItemComponent* const tc = Toolbar::createItem (factory_, allIds.getUnchecked (i));
  43979. jassert (tc != 0);
  43980. if (tc != 0)
  43981. {
  43982. itemHolder->addAndMakeVisible (tc);
  43983. tc->setEditingMode (ToolbarItemComponent::editableOnPalette);
  43984. }
  43985. }
  43986. viewport = new Viewport();
  43987. viewport->setViewedComponent (itemHolder);
  43988. addAndMakeVisible (viewport);
  43989. }
  43990. ToolbarItemPalette::~ToolbarItemPalette()
  43991. {
  43992. viewport->getViewedComponent()->deleteAllChildren();
  43993. deleteAllChildren();
  43994. }
  43995. void ToolbarItemPalette::resized()
  43996. {
  43997. viewport->setBoundsInset (BorderSize (1));
  43998. Component* const itemHolder = viewport->getViewedComponent();
  43999. const int indent = 8;
  44000. const int preferredWidth = viewport->getWidth() - viewport->getScrollBarThickness() - indent;
  44001. const int height = toolbar->getThickness();
  44002. int x = indent;
  44003. int y = indent;
  44004. int maxX = 0;
  44005. for (int i = 0; i < itemHolder->getNumChildComponents(); ++i)
  44006. {
  44007. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (itemHolder->getChildComponent (i));
  44008. if (tc != 0)
  44009. {
  44010. tc->setStyle (toolbar->getStyle());
  44011. int preferredSize = 1, minSize = 1, maxSize = 1;
  44012. if (tc->getToolbarItemSizes (height, false, preferredSize, minSize, maxSize))
  44013. {
  44014. if (x + preferredSize > preferredWidth && x > indent)
  44015. {
  44016. x = indent;
  44017. y += height;
  44018. }
  44019. tc->setBounds (x, y, preferredSize, height);
  44020. x += preferredSize + 8;
  44021. maxX = jmax (maxX, x);
  44022. }
  44023. }
  44024. }
  44025. itemHolder->setSize (maxX, y + height + 8);
  44026. }
  44027. void ToolbarItemPalette::replaceComponent (ToolbarItemComponent* const comp)
  44028. {
  44029. ToolbarItemComponent* const tc = Toolbar::createItem (factory, comp->getItemId());
  44030. jassert (tc != 0);
  44031. if (tc != 0)
  44032. {
  44033. tc->setBounds (comp->getBounds());
  44034. tc->setStyle (toolbar->getStyle());
  44035. tc->setEditingMode (comp->getEditingMode());
  44036. viewport->getViewedComponent()->addAndMakeVisible (tc, getIndexOfChildComponent (comp));
  44037. }
  44038. }
  44039. END_JUCE_NAMESPACE
  44040. /*** End of inlined file: juce_ToolbarItemPalette.cpp ***/
  44041. /*** Start of inlined file: juce_TreeView.cpp ***/
  44042. BEGIN_JUCE_NAMESPACE
  44043. class TreeViewContentComponent : public Component,
  44044. public TooltipClient
  44045. {
  44046. public:
  44047. TreeViewContentComponent (TreeView* const owner_)
  44048. : owner (owner_),
  44049. buttonUnderMouse (0),
  44050. isDragging (false)
  44051. {
  44052. }
  44053. ~TreeViewContentComponent()
  44054. {
  44055. deleteAllChildren();
  44056. }
  44057. void mouseDown (const MouseEvent& e)
  44058. {
  44059. updateButtonUnderMouse (e);
  44060. isDragging = false;
  44061. needSelectionOnMouseUp = false;
  44062. Rectangle<int> pos;
  44063. TreeViewItem* const item = findItemAt (e.y, pos);
  44064. if (item == 0)
  44065. return;
  44066. // (if the open/close buttons are hidden, we'll treat clicks to the left of the item
  44067. // as selection clicks)
  44068. if (e.x < pos.getX() && owner->openCloseButtonsVisible)
  44069. {
  44070. if (e.x >= pos.getX() - owner->getIndentSize())
  44071. item->setOpen (! item->isOpen());
  44072. // (clicks to the left of an open/close button are ignored)
  44073. }
  44074. else
  44075. {
  44076. // mouse-down inside the body of the item..
  44077. if (! owner->isMultiSelectEnabled())
  44078. item->setSelected (true, true);
  44079. else if (item->isSelected())
  44080. needSelectionOnMouseUp = ! e.mods.isPopupMenu();
  44081. else
  44082. selectBasedOnModifiers (item, e.mods);
  44083. if (e.x >= pos.getX())
  44084. item->itemClicked (e.withNewPosition (e.getPosition() - pos.getPosition()));
  44085. }
  44086. }
  44087. void mouseUp (const MouseEvent& e)
  44088. {
  44089. updateButtonUnderMouse (e);
  44090. if (needSelectionOnMouseUp && e.mouseWasClicked())
  44091. {
  44092. Rectangle<int> pos;
  44093. TreeViewItem* const item = findItemAt (e.y, pos);
  44094. if (item != 0)
  44095. selectBasedOnModifiers (item, e.mods);
  44096. }
  44097. }
  44098. void mouseDoubleClick (const MouseEvent& e)
  44099. {
  44100. if (e.getNumberOfClicks() != 3) // ignore triple clicks
  44101. {
  44102. Rectangle<int> pos;
  44103. TreeViewItem* const item = findItemAt (e.y, pos);
  44104. if (item != 0 && (e.x >= pos.getX() || ! owner->openCloseButtonsVisible))
  44105. item->itemDoubleClicked (e.withNewPosition (e.getPosition() - pos.getPosition()));
  44106. }
  44107. }
  44108. void mouseDrag (const MouseEvent& e)
  44109. {
  44110. if (isEnabled()
  44111. && ! (isDragging || e.mouseWasClicked()
  44112. || e.getDistanceFromDragStart() < 5
  44113. || e.mods.isPopupMenu()))
  44114. {
  44115. isDragging = true;
  44116. Rectangle<int> pos;
  44117. TreeViewItem* const item = findItemAt (e.getMouseDownY(), pos);
  44118. if (item != 0 && e.getMouseDownX() >= pos.getX())
  44119. {
  44120. const String dragDescription (item->getDragSourceDescription());
  44121. if (dragDescription.isNotEmpty())
  44122. {
  44123. DragAndDropContainer* const dragContainer
  44124. = DragAndDropContainer::findParentDragContainerFor (this);
  44125. if (dragContainer != 0)
  44126. {
  44127. pos.setSize (pos.getWidth(), item->itemHeight);
  44128. Image* dragImage = Component::createComponentSnapshot (pos, true);
  44129. dragImage->multiplyAllAlphas (0.6f);
  44130. Point<int> imageOffset (pos.getX() - e.x, pos.getY() - e.y);
  44131. dragContainer->startDragging (dragDescription, owner, dragImage, true, &imageOffset);
  44132. }
  44133. else
  44134. {
  44135. // to be able to do a drag-and-drop operation, the treeview needs to
  44136. // be inside a component which is also a DragAndDropContainer.
  44137. jassertfalse
  44138. }
  44139. }
  44140. }
  44141. }
  44142. }
  44143. void mouseMove (const MouseEvent& e)
  44144. {
  44145. updateButtonUnderMouse (e);
  44146. }
  44147. void mouseExit (const MouseEvent& e)
  44148. {
  44149. updateButtonUnderMouse (e);
  44150. }
  44151. void paint (Graphics& g);
  44152. TreeViewItem* findItemAt (int y, Rectangle<int>& itemPosition) const;
  44153. static bool isMouseDraggingInChildCompOf (Component* const comp)
  44154. {
  44155. for (int i = Desktop::getInstance().getNumMouseSources(); --i >= 0;)
  44156. {
  44157. MouseInputSource* source = Desktop::getInstance().getMouseSource(i);
  44158. if (source->isDragging())
  44159. {
  44160. Component* const underMouse = source->getComponentUnderMouse();
  44161. if (underMouse != 0 && (comp == underMouse || comp->isParentOf (underMouse)))
  44162. return true;
  44163. }
  44164. }
  44165. return false;
  44166. }
  44167. void updateComponents()
  44168. {
  44169. const int visibleTop = -getY();
  44170. const int visibleBottom = visibleTop + getParentHeight();
  44171. BitArray itemsToKeep;
  44172. TreeViewItem* item = owner->rootItem;
  44173. int y = (item != 0 && !owner->rootItemVisible) ? -item->itemHeight : 0;
  44174. while (item != 0 && y < visibleBottom)
  44175. {
  44176. y += item->itemHeight;
  44177. if (y >= visibleTop)
  44178. {
  44179. const int index = rowComponentIds.indexOf (item->uid);
  44180. if (index < 0)
  44181. {
  44182. Component* const comp = item->createItemComponent();
  44183. if (comp != 0)
  44184. {
  44185. addAndMakeVisible (comp);
  44186. itemsToKeep.setBit (rowComponentItems.size());
  44187. rowComponentItems.add (item);
  44188. rowComponentIds.add (item->uid);
  44189. rowComponents.add (comp);
  44190. }
  44191. }
  44192. else
  44193. {
  44194. itemsToKeep.setBit (index);
  44195. }
  44196. }
  44197. item = item->getNextVisibleItem (true);
  44198. }
  44199. for (int i = rowComponentItems.size(); --i >= 0;)
  44200. {
  44201. Component* const comp = (Component*) rowComponents.getUnchecked(i);
  44202. bool keep = false;
  44203. if (isParentOf (comp))
  44204. {
  44205. if (itemsToKeep[i])
  44206. {
  44207. const TreeViewItem* const item = (TreeViewItem*) rowComponentItems.getUnchecked(i);
  44208. Rectangle<int> pos (item->getItemPosition (false));
  44209. pos.setSize (pos.getWidth(), item->itemHeight);
  44210. if (pos.getBottom() >= visibleTop && pos.getY() < visibleBottom)
  44211. {
  44212. keep = true;
  44213. comp->setBounds (pos);
  44214. }
  44215. }
  44216. if ((! keep) && isMouseDraggingInChildCompOf (comp))
  44217. {
  44218. keep = true;
  44219. comp->setSize (0, 0);
  44220. }
  44221. }
  44222. if (! keep)
  44223. {
  44224. delete comp;
  44225. rowComponents.remove (i);
  44226. rowComponentIds.remove (i);
  44227. rowComponentItems.remove (i);
  44228. }
  44229. }
  44230. }
  44231. void updateButtonUnderMouse (const MouseEvent& e)
  44232. {
  44233. TreeViewItem* newItem = 0;
  44234. if (owner->openCloseButtonsVisible)
  44235. {
  44236. Rectangle<int> pos;
  44237. TreeViewItem* item = findItemAt (e.y, pos);
  44238. if (item != 0 && e.x < pos.getX() && e.x >= pos.getX() - owner->getIndentSize())
  44239. {
  44240. newItem = item;
  44241. if (! newItem->mightContainSubItems())
  44242. newItem = 0;
  44243. }
  44244. }
  44245. if (buttonUnderMouse != newItem)
  44246. {
  44247. if (buttonUnderMouse != 0 && containsItem (buttonUnderMouse))
  44248. {
  44249. const Rectangle<int> r (buttonUnderMouse->getItemPosition (false));
  44250. repaint (0, r.getY(), r.getX(), buttonUnderMouse->getItemHeight());
  44251. }
  44252. buttonUnderMouse = newItem;
  44253. if (buttonUnderMouse != 0)
  44254. {
  44255. const Rectangle<int> r (buttonUnderMouse->getItemPosition (false));
  44256. repaint (0, r.getY(), r.getX(), buttonUnderMouse->getItemHeight());
  44257. }
  44258. }
  44259. }
  44260. bool isMouseOverButton (TreeViewItem* item) const throw()
  44261. {
  44262. return item == buttonUnderMouse;
  44263. }
  44264. void resized()
  44265. {
  44266. owner->itemsChanged();
  44267. }
  44268. const String getTooltip()
  44269. {
  44270. Rectangle<int> pos;
  44271. TreeViewItem* const item = findItemAt (getMouseXYRelative().getY(), pos);
  44272. if (item != 0)
  44273. return item->getTooltip();
  44274. return owner->getTooltip();
  44275. }
  44276. juce_UseDebuggingNewOperator
  44277. private:
  44278. TreeView* const owner;
  44279. VoidArray rowComponentItems;
  44280. Array <int> rowComponentIds;
  44281. VoidArray rowComponents;
  44282. TreeViewItem* buttonUnderMouse;
  44283. bool isDragging, needSelectionOnMouseUp;
  44284. TreeViewContentComponent (const TreeViewContentComponent&);
  44285. TreeViewContentComponent& operator= (const TreeViewContentComponent&);
  44286. void selectBasedOnModifiers (TreeViewItem* const item, const ModifierKeys& modifiers)
  44287. {
  44288. TreeViewItem* firstSelected = 0;
  44289. if (modifiers.isShiftDown() && ((firstSelected = owner->getSelectedItem (0)) != 0))
  44290. {
  44291. TreeViewItem* const lastSelected = owner->getSelectedItem (owner->getNumSelectedItems() - 1);
  44292. jassert (lastSelected != 0);
  44293. int rowStart = firstSelected->getRowNumberInTree();
  44294. int rowEnd = lastSelected->getRowNumberInTree();
  44295. if (rowStart > rowEnd)
  44296. swapVariables (rowStart, rowEnd);
  44297. int ourRow = item->getRowNumberInTree();
  44298. int otherEnd = ourRow < rowEnd ? rowStart : rowEnd;
  44299. if (ourRow > otherEnd)
  44300. swapVariables (ourRow, otherEnd);
  44301. for (int i = ourRow; i <= otherEnd; ++i)
  44302. owner->getItemOnRow (i)->setSelected (true, false);
  44303. }
  44304. else
  44305. {
  44306. const bool cmd = modifiers.isCommandDown();
  44307. item->setSelected ((! cmd) || (! item->isSelected()), ! cmd);
  44308. }
  44309. }
  44310. bool containsItem (TreeViewItem* const item) const
  44311. {
  44312. for (int i = rowComponentItems.size(); --i >= 0;)
  44313. if ((TreeViewItem*) rowComponentItems.getUnchecked (i) == item)
  44314. return true;
  44315. return false;
  44316. }
  44317. };
  44318. class TreeViewport : public Viewport
  44319. {
  44320. public:
  44321. TreeViewport() throw() {}
  44322. ~TreeViewport() throw() {}
  44323. void updateComponents()
  44324. {
  44325. if (getViewedComponent() != 0)
  44326. ((TreeViewContentComponent*) getViewedComponent())->updateComponents();
  44327. repaint();
  44328. }
  44329. void visibleAreaChanged (int, int, int, int)
  44330. {
  44331. updateComponents();
  44332. }
  44333. juce_UseDebuggingNewOperator
  44334. private:
  44335. TreeViewport (const TreeViewport&);
  44336. TreeViewport& operator= (const TreeViewport&);
  44337. };
  44338. TreeView::TreeView (const String& componentName)
  44339. : Component (componentName),
  44340. rootItem (0),
  44341. dragInsertPointHighlight (0),
  44342. dragTargetGroupHighlight (0),
  44343. indentSize (24),
  44344. defaultOpenness (false),
  44345. needsRecalculating (true),
  44346. rootItemVisible (true),
  44347. multiSelectEnabled (false),
  44348. openCloseButtonsVisible (true)
  44349. {
  44350. addAndMakeVisible (viewport = new TreeViewport());
  44351. viewport->setViewedComponent (new TreeViewContentComponent (this));
  44352. viewport->setWantsKeyboardFocus (false);
  44353. setWantsKeyboardFocus (true);
  44354. }
  44355. TreeView::~TreeView()
  44356. {
  44357. if (rootItem != 0)
  44358. rootItem->setOwnerView (0);
  44359. deleteAllChildren();
  44360. }
  44361. void TreeView::setRootItem (TreeViewItem* const newRootItem)
  44362. {
  44363. if (rootItem != newRootItem)
  44364. {
  44365. if (newRootItem != 0)
  44366. {
  44367. jassert (newRootItem->ownerView == 0); // can't use a tree item in more than one tree at once..
  44368. if (newRootItem->ownerView != 0)
  44369. newRootItem->ownerView->setRootItem (0);
  44370. }
  44371. if (rootItem != 0)
  44372. rootItem->setOwnerView (0);
  44373. rootItem = newRootItem;
  44374. if (newRootItem != 0)
  44375. newRootItem->setOwnerView (this);
  44376. needsRecalculating = true;
  44377. handleAsyncUpdate();
  44378. if (rootItem != 0 && (defaultOpenness || ! rootItemVisible))
  44379. {
  44380. rootItem->setOpen (false); // force a re-open
  44381. rootItem->setOpen (true);
  44382. }
  44383. }
  44384. }
  44385. void TreeView::deleteRootItem()
  44386. {
  44387. const ScopedPointer <TreeViewItem> deleter (rootItem);
  44388. setRootItem (0);
  44389. }
  44390. void TreeView::setRootItemVisible (const bool shouldBeVisible)
  44391. {
  44392. rootItemVisible = shouldBeVisible;
  44393. if (rootItem != 0 && (defaultOpenness || ! rootItemVisible))
  44394. {
  44395. rootItem->setOpen (false); // force a re-open
  44396. rootItem->setOpen (true);
  44397. }
  44398. itemsChanged();
  44399. }
  44400. void TreeView::colourChanged()
  44401. {
  44402. setOpaque (findColour (backgroundColourId).isOpaque());
  44403. repaint();
  44404. }
  44405. void TreeView::setIndentSize (const int newIndentSize)
  44406. {
  44407. if (indentSize != newIndentSize)
  44408. {
  44409. indentSize = newIndentSize;
  44410. resized();
  44411. }
  44412. }
  44413. void TreeView::setDefaultOpenness (const bool isOpenByDefault)
  44414. {
  44415. if (defaultOpenness != isOpenByDefault)
  44416. {
  44417. defaultOpenness = isOpenByDefault;
  44418. itemsChanged();
  44419. }
  44420. }
  44421. void TreeView::setMultiSelectEnabled (const bool canMultiSelect)
  44422. {
  44423. multiSelectEnabled = canMultiSelect;
  44424. }
  44425. void TreeView::setOpenCloseButtonsVisible (const bool shouldBeVisible)
  44426. {
  44427. if (openCloseButtonsVisible != shouldBeVisible)
  44428. {
  44429. openCloseButtonsVisible = shouldBeVisible;
  44430. itemsChanged();
  44431. }
  44432. }
  44433. void TreeView::clearSelectedItems()
  44434. {
  44435. if (rootItem != 0)
  44436. rootItem->deselectAllRecursively();
  44437. }
  44438. int TreeView::getNumSelectedItems() const throw()
  44439. {
  44440. return (rootItem != 0) ? rootItem->countSelectedItemsRecursively() : 0;
  44441. }
  44442. TreeViewItem* TreeView::getSelectedItem (const int index) const throw()
  44443. {
  44444. return (rootItem != 0) ? rootItem->getSelectedItemWithIndex (index) : 0;
  44445. }
  44446. int TreeView::getNumRowsInTree() const
  44447. {
  44448. if (rootItem != 0)
  44449. return rootItem->getNumRows() - (rootItemVisible ? 0 : 1);
  44450. return 0;
  44451. }
  44452. TreeViewItem* TreeView::getItemOnRow (int index) const
  44453. {
  44454. if (! rootItemVisible)
  44455. ++index;
  44456. if (rootItem != 0 && index >= 0)
  44457. return rootItem->getItemOnRow (index);
  44458. return 0;
  44459. }
  44460. TreeViewItem* TreeView::getItemAt (int y) const throw()
  44461. {
  44462. TreeViewContentComponent* const tc = (TreeViewContentComponent*) viewport->getViewedComponent();
  44463. Rectangle<int> pos;
  44464. return tc->findItemAt (relativePositionToOtherComponent (tc, Point<int> (0, y)).getY(), pos);
  44465. }
  44466. TreeViewItem* TreeView::findItemFromIdentifierString (const String& identifierString) const
  44467. {
  44468. if (rootItem == 0)
  44469. return 0;
  44470. return rootItem->findItemFromIdentifierString (identifierString);
  44471. }
  44472. XmlElement* TreeView::getOpennessState (const bool alsoIncludeScrollPosition) const
  44473. {
  44474. XmlElement* e = 0;
  44475. if (rootItem != 0)
  44476. {
  44477. e = rootItem->getOpennessState();
  44478. if (e != 0 && alsoIncludeScrollPosition)
  44479. e->setAttribute (T("scrollPos"), viewport->getViewPositionY());
  44480. }
  44481. return e;
  44482. }
  44483. void TreeView::restoreOpennessState (const XmlElement& newState)
  44484. {
  44485. if (rootItem != 0)
  44486. {
  44487. rootItem->restoreOpennessState (newState);
  44488. if (newState.hasAttribute (T("scrollPos")))
  44489. viewport->setViewPosition (viewport->getViewPositionX(),
  44490. newState.getIntAttribute (T("scrollPos")));
  44491. }
  44492. }
  44493. void TreeView::paint (Graphics& g)
  44494. {
  44495. g.fillAll (findColour (backgroundColourId));
  44496. }
  44497. void TreeView::resized()
  44498. {
  44499. viewport->setBounds (0, 0, getWidth(), getHeight());
  44500. itemsChanged();
  44501. handleAsyncUpdate();
  44502. }
  44503. void TreeView::enablementChanged()
  44504. {
  44505. repaint();
  44506. }
  44507. void TreeView::moveSelectedRow (int delta)
  44508. {
  44509. if (delta == 0)
  44510. return;
  44511. int rowSelected = 0;
  44512. TreeViewItem* const firstSelected = getSelectedItem (0);
  44513. if (firstSelected != 0)
  44514. rowSelected = firstSelected->getRowNumberInTree();
  44515. rowSelected = jlimit (0, getNumRowsInTree() - 1, rowSelected + delta);
  44516. for (;;)
  44517. {
  44518. TreeViewItem* item = getItemOnRow (rowSelected);
  44519. if (item != 0)
  44520. {
  44521. if (! item->canBeSelected())
  44522. {
  44523. // if the row we want to highlight doesn't allow it, try skipping
  44524. // to the next item..
  44525. const int nextRowToTry = jlimit (0, getNumRowsInTree() - 1,
  44526. rowSelected + (delta < 0 ? -1 : 1));
  44527. if (rowSelected != nextRowToTry)
  44528. {
  44529. rowSelected = nextRowToTry;
  44530. continue;
  44531. }
  44532. else
  44533. {
  44534. break;
  44535. }
  44536. }
  44537. item->setSelected (true, true);
  44538. scrollToKeepItemVisible (item);
  44539. }
  44540. break;
  44541. }
  44542. }
  44543. void TreeView::scrollToKeepItemVisible (TreeViewItem* item)
  44544. {
  44545. if (item != 0 && item->ownerView == this)
  44546. {
  44547. handleAsyncUpdate();
  44548. item = item->getDeepestOpenParentItem();
  44549. int y = item->y;
  44550. int viewTop = viewport->getViewPositionY();
  44551. if (y < viewTop)
  44552. {
  44553. viewport->setViewPosition (viewport->getViewPositionX(), y);
  44554. }
  44555. else if (y + item->itemHeight > viewTop + viewport->getViewHeight())
  44556. {
  44557. viewport->setViewPosition (viewport->getViewPositionX(),
  44558. (y + item->itemHeight) - viewport->getViewHeight());
  44559. }
  44560. }
  44561. }
  44562. bool TreeView::keyPressed (const KeyPress& key)
  44563. {
  44564. if (key.isKeyCode (KeyPress::upKey))
  44565. {
  44566. moveSelectedRow (-1);
  44567. }
  44568. else if (key.isKeyCode (KeyPress::downKey))
  44569. {
  44570. moveSelectedRow (1);
  44571. }
  44572. else if (key.isKeyCode (KeyPress::pageDownKey) || key.isKeyCode (KeyPress::pageUpKey))
  44573. {
  44574. if (rootItem != 0)
  44575. {
  44576. int rowsOnScreen = getHeight() / jmax (1, rootItem->itemHeight);
  44577. if (key.isKeyCode (KeyPress::pageUpKey))
  44578. rowsOnScreen = -rowsOnScreen;
  44579. moveSelectedRow (rowsOnScreen);
  44580. }
  44581. }
  44582. else if (key.isKeyCode (KeyPress::homeKey))
  44583. {
  44584. moveSelectedRow (-0x3fffffff);
  44585. }
  44586. else if (key.isKeyCode (KeyPress::endKey))
  44587. {
  44588. moveSelectedRow (0x3fffffff);
  44589. }
  44590. else if (key.isKeyCode (KeyPress::returnKey))
  44591. {
  44592. TreeViewItem* const firstSelected = getSelectedItem (0);
  44593. if (firstSelected != 0)
  44594. firstSelected->setOpen (! firstSelected->isOpen());
  44595. }
  44596. else if (key.isKeyCode (KeyPress::leftKey))
  44597. {
  44598. TreeViewItem* const firstSelected = getSelectedItem (0);
  44599. if (firstSelected != 0)
  44600. {
  44601. if (firstSelected->isOpen())
  44602. {
  44603. firstSelected->setOpen (false);
  44604. }
  44605. else
  44606. {
  44607. TreeViewItem* parent = firstSelected->parentItem;
  44608. if ((! rootItemVisible) && parent == rootItem)
  44609. parent = 0;
  44610. if (parent != 0)
  44611. {
  44612. parent->setSelected (true, true);
  44613. scrollToKeepItemVisible (parent);
  44614. }
  44615. }
  44616. }
  44617. }
  44618. else if (key.isKeyCode (KeyPress::rightKey))
  44619. {
  44620. TreeViewItem* const firstSelected = getSelectedItem (0);
  44621. if (firstSelected != 0)
  44622. {
  44623. if (firstSelected->isOpen() || ! firstSelected->mightContainSubItems())
  44624. moveSelectedRow (1);
  44625. else
  44626. firstSelected->setOpen (true);
  44627. }
  44628. }
  44629. else
  44630. {
  44631. return false;
  44632. }
  44633. return true;
  44634. }
  44635. void TreeView::itemsChanged() throw()
  44636. {
  44637. needsRecalculating = true;
  44638. repaint();
  44639. triggerAsyncUpdate();
  44640. }
  44641. void TreeView::handleAsyncUpdate()
  44642. {
  44643. if (needsRecalculating)
  44644. {
  44645. needsRecalculating = false;
  44646. const ScopedLock sl (nodeAlterationLock);
  44647. if (rootItem != 0)
  44648. rootItem->updatePositions (rootItemVisible ? 0 : -rootItem->itemHeight);
  44649. ((TreeViewport*) viewport)->updateComponents();
  44650. if (rootItem != 0)
  44651. {
  44652. viewport->getViewedComponent()
  44653. ->setSize (jmax (viewport->getMaximumVisibleWidth(), rootItem->totalWidth),
  44654. rootItem->totalHeight - (rootItemVisible ? 0 : rootItem->itemHeight));
  44655. }
  44656. else
  44657. {
  44658. viewport->getViewedComponent()->setSize (0, 0);
  44659. }
  44660. }
  44661. }
  44662. class TreeViewDragInsertPointHighlight : public Component
  44663. {
  44664. public:
  44665. TreeViewDragInsertPointHighlight()
  44666. : lastItem (0)
  44667. {
  44668. setSize (100, 12);
  44669. setAlwaysOnTop (true);
  44670. setInterceptsMouseClicks (false, false);
  44671. }
  44672. ~TreeViewDragInsertPointHighlight() {}
  44673. void setTargetPosition (TreeViewItem* const item, int insertIndex, const int x, const int y, const int width) throw()
  44674. {
  44675. lastItem = item;
  44676. lastIndex = insertIndex;
  44677. const int offset = getHeight() / 2;
  44678. setBounds (x - offset, y - offset, width - (x - offset), getHeight());
  44679. }
  44680. void paint (Graphics& g)
  44681. {
  44682. Path p;
  44683. const float h = (float) getHeight();
  44684. p.addEllipse (2.0f, 2.0f, h - 4.0f, h - 4.0f);
  44685. p.startNewSubPath (h - 2.0f, h / 2.0f);
  44686. p.lineTo ((float) getWidth(), h / 2.0f);
  44687. g.setColour (findColour (TreeView::dragAndDropIndicatorColourId, true));
  44688. g.strokePath (p, PathStrokeType (2.0f));
  44689. }
  44690. TreeViewItem* lastItem;
  44691. int lastIndex;
  44692. };
  44693. class TreeViewDragTargetGroupHighlight : public Component
  44694. {
  44695. public:
  44696. TreeViewDragTargetGroupHighlight()
  44697. {
  44698. setAlwaysOnTop (true);
  44699. setInterceptsMouseClicks (false, false);
  44700. }
  44701. ~TreeViewDragTargetGroupHighlight() {}
  44702. void setTargetPosition (TreeViewItem* const item) throw()
  44703. {
  44704. Rectangle<int> r (item->getItemPosition (true));
  44705. r.setHeight (item->getItemHeight());
  44706. setBounds (r);
  44707. }
  44708. void paint (Graphics& g)
  44709. {
  44710. g.setColour (findColour (TreeView::dragAndDropIndicatorColourId, true));
  44711. g.drawRoundedRectangle (1.0f, 1.0f, getWidth() - 2.0f, getHeight() - 2.0f, 3.0f, 2.0f);
  44712. }
  44713. };
  44714. void TreeView::showDragHighlight (TreeViewItem* item, int insertIndex, int x, int y) throw()
  44715. {
  44716. beginDragAutoRepeat (1000 / 30);
  44717. if (dragInsertPointHighlight == 0)
  44718. {
  44719. addAndMakeVisible (dragInsertPointHighlight = new TreeViewDragInsertPointHighlight());
  44720. addAndMakeVisible (dragTargetGroupHighlight = new TreeViewDragTargetGroupHighlight());
  44721. }
  44722. ((TreeViewDragInsertPointHighlight*) dragInsertPointHighlight)
  44723. ->setTargetPosition (item, insertIndex, x, y, viewport->getViewWidth());
  44724. ((TreeViewDragTargetGroupHighlight*) dragTargetGroupHighlight)
  44725. ->setTargetPosition (item);
  44726. }
  44727. void TreeView::hideDragHighlight() throw()
  44728. {
  44729. deleteAndZero (dragInsertPointHighlight);
  44730. deleteAndZero (dragTargetGroupHighlight);
  44731. }
  44732. TreeViewItem* TreeView::getInsertPosition (int& x, int& y, int& insertIndex,
  44733. const StringArray& files, const String& sourceDescription,
  44734. Component* sourceComponent) const throw()
  44735. {
  44736. insertIndex = 0;
  44737. TreeViewItem* item = getItemAt (y);
  44738. if (item == 0)
  44739. return 0;
  44740. Rectangle<int> itemPos (item->getItemPosition (true));
  44741. insertIndex = item->getIndexInParent();
  44742. const int oldY = y;
  44743. y = itemPos.getY();
  44744. if (item->getNumSubItems() == 0 || ! item->isOpen())
  44745. {
  44746. if (files.size() > 0 ? item->isInterestedInFileDrag (files)
  44747. : item->isInterestedInDragSource (sourceDescription, sourceComponent))
  44748. {
  44749. // Check if we're trying to drag into an empty group item..
  44750. if (oldY > itemPos.getY() + itemPos.getHeight() / 4
  44751. && oldY < itemPos.getBottom() - itemPos.getHeight() / 4)
  44752. {
  44753. insertIndex = 0;
  44754. x = itemPos.getX() + getIndentSize();
  44755. y = itemPos.getBottom();
  44756. return item;
  44757. }
  44758. }
  44759. }
  44760. if (oldY > itemPos.getCentreY())
  44761. {
  44762. y += item->getItemHeight();
  44763. while (item->isLastOfSiblings() && item->parentItem != 0
  44764. && item->parentItem->parentItem != 0)
  44765. {
  44766. if (x > itemPos.getX())
  44767. break;
  44768. item = item->parentItem;
  44769. itemPos = item->getItemPosition (true);
  44770. insertIndex = item->getIndexInParent();
  44771. }
  44772. ++insertIndex;
  44773. }
  44774. x = itemPos.getX();
  44775. return item->parentItem;
  44776. }
  44777. void TreeView::handleDrag (const StringArray& files, const String& sourceDescription, Component* sourceComponent, int x, int y)
  44778. {
  44779. const bool scrolled = viewport->autoScroll (x, y, 20, 10);
  44780. int insertIndex;
  44781. TreeViewItem* const item = getInsertPosition (x, y, insertIndex, files, sourceDescription, sourceComponent);
  44782. if (item != 0)
  44783. {
  44784. if (scrolled || dragInsertPointHighlight == 0
  44785. || ((TreeViewDragInsertPointHighlight*) dragInsertPointHighlight)->lastItem != item
  44786. || ((TreeViewDragInsertPointHighlight*) dragInsertPointHighlight)->lastIndex != insertIndex)
  44787. {
  44788. if (files.size() > 0 ? item->isInterestedInFileDrag (files)
  44789. : item->isInterestedInDragSource (sourceDescription, sourceComponent))
  44790. showDragHighlight (item, insertIndex, x, y);
  44791. else
  44792. hideDragHighlight();
  44793. }
  44794. }
  44795. else
  44796. {
  44797. hideDragHighlight();
  44798. }
  44799. }
  44800. void TreeView::handleDrop (const StringArray& files, const String& sourceDescription, Component* sourceComponent, int x, int y)
  44801. {
  44802. hideDragHighlight();
  44803. int insertIndex;
  44804. TreeViewItem* const item = getInsertPosition (x, y, insertIndex, files, sourceDescription, sourceComponent);
  44805. if (item != 0)
  44806. {
  44807. if (files.size() > 0)
  44808. {
  44809. if (item->isInterestedInFileDrag (files))
  44810. item->filesDropped (files, insertIndex);
  44811. }
  44812. else
  44813. {
  44814. if (item->isInterestedInDragSource (sourceDescription, sourceComponent))
  44815. item->itemDropped (sourceDescription, sourceComponent, insertIndex);
  44816. }
  44817. }
  44818. }
  44819. bool TreeView::isInterestedInFileDrag (const StringArray&)
  44820. {
  44821. return true;
  44822. }
  44823. void TreeView::fileDragEnter (const StringArray& files, int x, int y)
  44824. {
  44825. fileDragMove (files, x, y);
  44826. }
  44827. void TreeView::fileDragMove (const StringArray& files, int x, int y)
  44828. {
  44829. handleDrag (files, String::empty, 0, x, y);
  44830. }
  44831. void TreeView::fileDragExit (const StringArray&)
  44832. {
  44833. hideDragHighlight();
  44834. }
  44835. void TreeView::filesDropped (const StringArray& files, int x, int y)
  44836. {
  44837. handleDrop (files, String::empty, 0, x, y);
  44838. }
  44839. bool TreeView::isInterestedInDragSource (const String& /*sourceDescription*/, Component* /*sourceComponent*/)
  44840. {
  44841. return true;
  44842. }
  44843. void TreeView::itemDragEnter (const String& sourceDescription, Component* sourceComponent, int x, int y)
  44844. {
  44845. itemDragMove (sourceDescription, sourceComponent, x, y);
  44846. }
  44847. void TreeView::itemDragMove (const String& sourceDescription, Component* sourceComponent, int x, int y)
  44848. {
  44849. handleDrag (StringArray(), sourceDescription, sourceComponent, x, y);
  44850. }
  44851. void TreeView::itemDragExit (const String& /*sourceDescription*/, Component* /*sourceComponent*/)
  44852. {
  44853. hideDragHighlight();
  44854. }
  44855. void TreeView::itemDropped (const String& sourceDescription, Component* sourceComponent, int x, int y)
  44856. {
  44857. handleDrop (StringArray(), sourceDescription, sourceComponent, x, y);
  44858. }
  44859. void TreeViewContentComponent::paint (Graphics& g)
  44860. {
  44861. if (owner->rootItem != 0)
  44862. {
  44863. owner->handleAsyncUpdate();
  44864. if (! owner->rootItemVisible)
  44865. g.setOrigin (0, -owner->rootItem->itemHeight);
  44866. owner->rootItem->paintRecursively (g, getWidth());
  44867. }
  44868. }
  44869. TreeViewItem* TreeViewContentComponent::findItemAt (int y, Rectangle<int>& itemPosition) const
  44870. {
  44871. if (owner->rootItem != 0)
  44872. {
  44873. owner->handleAsyncUpdate();
  44874. if (! owner->rootItemVisible)
  44875. y += owner->rootItem->itemHeight;
  44876. TreeViewItem* const ti = owner->rootItem->findItemRecursively (y);
  44877. if (ti != 0)
  44878. itemPosition = ti->getItemPosition (false);
  44879. return ti;
  44880. }
  44881. return 0;
  44882. }
  44883. enum TreeViewOpenness
  44884. {
  44885. opennessDefault = 0,
  44886. opennessClosed = 1,
  44887. opennessOpen = 2
  44888. };
  44889. TreeViewItem::TreeViewItem()
  44890. : ownerView (0),
  44891. parentItem (0),
  44892. y (0),
  44893. itemHeight (0),
  44894. totalHeight (0),
  44895. selected (false),
  44896. redrawNeeded (true),
  44897. drawLinesInside (true),
  44898. drawsInLeftMargin (false),
  44899. openness (opennessDefault)
  44900. {
  44901. static int nextUID = 0;
  44902. uid = nextUID++;
  44903. }
  44904. TreeViewItem::~TreeViewItem()
  44905. {
  44906. }
  44907. const String TreeViewItem::getUniqueName() const
  44908. {
  44909. return String::empty;
  44910. }
  44911. void TreeViewItem::itemOpennessChanged (bool)
  44912. {
  44913. }
  44914. int TreeViewItem::getNumSubItems() const throw()
  44915. {
  44916. return subItems.size();
  44917. }
  44918. TreeViewItem* TreeViewItem::getSubItem (const int index) const throw()
  44919. {
  44920. return subItems [index];
  44921. }
  44922. void TreeViewItem::clearSubItems()
  44923. {
  44924. if (subItems.size() > 0)
  44925. {
  44926. if (ownerView != 0)
  44927. {
  44928. const ScopedLock sl (ownerView->nodeAlterationLock);
  44929. subItems.clear();
  44930. treeHasChanged();
  44931. }
  44932. else
  44933. {
  44934. subItems.clear();
  44935. }
  44936. }
  44937. }
  44938. void TreeViewItem::addSubItem (TreeViewItem* const newItem, const int insertPosition)
  44939. {
  44940. if (newItem != 0)
  44941. {
  44942. newItem->parentItem = this;
  44943. newItem->setOwnerView (ownerView);
  44944. newItem->y = 0;
  44945. newItem->itemHeight = newItem->getItemHeight();
  44946. newItem->totalHeight = 0;
  44947. newItem->itemWidth = newItem->getItemWidth();
  44948. newItem->totalWidth = 0;
  44949. if (ownerView != 0)
  44950. {
  44951. const ScopedLock sl (ownerView->nodeAlterationLock);
  44952. subItems.insert (insertPosition, newItem);
  44953. treeHasChanged();
  44954. if (newItem->isOpen())
  44955. newItem->itemOpennessChanged (true);
  44956. }
  44957. else
  44958. {
  44959. subItems.insert (insertPosition, newItem);
  44960. if (newItem->isOpen())
  44961. newItem->itemOpennessChanged (true);
  44962. }
  44963. }
  44964. }
  44965. void TreeViewItem::removeSubItem (const int index, const bool deleteItem)
  44966. {
  44967. if (ownerView != 0)
  44968. {
  44969. const ScopedLock sl (ownerView->nodeAlterationLock);
  44970. if (((unsigned int) index) < (unsigned int) subItems.size())
  44971. {
  44972. subItems.remove (index, deleteItem);
  44973. treeHasChanged();
  44974. }
  44975. }
  44976. else
  44977. {
  44978. subItems.remove (index, deleteItem);
  44979. }
  44980. }
  44981. bool TreeViewItem::isOpen() const throw()
  44982. {
  44983. if (openness == opennessDefault)
  44984. return ownerView != 0 && ownerView->defaultOpenness;
  44985. else
  44986. return openness == opennessOpen;
  44987. }
  44988. void TreeViewItem::setOpen (const bool shouldBeOpen)
  44989. {
  44990. if (isOpen() != shouldBeOpen)
  44991. {
  44992. openness = shouldBeOpen ? opennessOpen
  44993. : opennessClosed;
  44994. treeHasChanged();
  44995. itemOpennessChanged (isOpen());
  44996. }
  44997. }
  44998. bool TreeViewItem::isSelected() const throw()
  44999. {
  45000. return selected;
  45001. }
  45002. void TreeViewItem::deselectAllRecursively()
  45003. {
  45004. setSelected (false, false);
  45005. for (int i = 0; i < subItems.size(); ++i)
  45006. subItems.getUnchecked(i)->deselectAllRecursively();
  45007. }
  45008. void TreeViewItem::setSelected (const bool shouldBeSelected,
  45009. const bool deselectOtherItemsFirst)
  45010. {
  45011. if (shouldBeSelected && ! canBeSelected())
  45012. return;
  45013. if (deselectOtherItemsFirst)
  45014. getTopLevelItem()->deselectAllRecursively();
  45015. if (shouldBeSelected != selected)
  45016. {
  45017. selected = shouldBeSelected;
  45018. if (ownerView != 0)
  45019. ownerView->repaint();
  45020. itemSelectionChanged (shouldBeSelected);
  45021. }
  45022. }
  45023. void TreeViewItem::paintItem (Graphics&, int, int)
  45024. {
  45025. }
  45026. void TreeViewItem::paintOpenCloseButton (Graphics& g, int width, int height, bool isMouseOver)
  45027. {
  45028. ownerView->getLookAndFeel()
  45029. .drawTreeviewPlusMinusBox (g, 0, 0, width, height, ! isOpen(), isMouseOver);
  45030. }
  45031. void TreeViewItem::itemClicked (const MouseEvent&)
  45032. {
  45033. }
  45034. void TreeViewItem::itemDoubleClicked (const MouseEvent&)
  45035. {
  45036. if (mightContainSubItems())
  45037. setOpen (! isOpen());
  45038. }
  45039. void TreeViewItem::itemSelectionChanged (bool)
  45040. {
  45041. }
  45042. const String TreeViewItem::getTooltip()
  45043. {
  45044. return String::empty;
  45045. }
  45046. const String TreeViewItem::getDragSourceDescription()
  45047. {
  45048. return String::empty;
  45049. }
  45050. bool TreeViewItem::isInterestedInFileDrag (const StringArray&)
  45051. {
  45052. return false;
  45053. }
  45054. void TreeViewItem::filesDropped (const StringArray& /*files*/, int /*insertIndex*/)
  45055. {
  45056. }
  45057. bool TreeViewItem::isInterestedInDragSource (const String& /*sourceDescription*/, Component* /*sourceComponent*/)
  45058. {
  45059. return false;
  45060. }
  45061. void TreeViewItem::itemDropped (const String& /*sourceDescription*/, Component* /*sourceComponent*/, int /*insertIndex*/)
  45062. {
  45063. }
  45064. const Rectangle<int> TreeViewItem::getItemPosition (const bool relativeToTreeViewTopLeft) const throw()
  45065. {
  45066. const int indentX = getIndentX();
  45067. int width = itemWidth;
  45068. if (ownerView != 0 && width < 0)
  45069. width = ownerView->viewport->getViewWidth() - indentX;
  45070. Rectangle<int> r (indentX, y, jmax (0, width), totalHeight);
  45071. if (relativeToTreeViewTopLeft)
  45072. r.setPosition (r.getX() - ownerView->viewport->getViewPositionX(),
  45073. r.getY() - ownerView->viewport->getViewPositionY());
  45074. return r;
  45075. }
  45076. void TreeViewItem::treeHasChanged() const throw()
  45077. {
  45078. if (ownerView != 0)
  45079. ownerView->itemsChanged();
  45080. }
  45081. void TreeViewItem::repaintItem() const
  45082. {
  45083. if (ownerView != 0 && areAllParentsOpen())
  45084. {
  45085. const Rectangle<int> r (getItemPosition (true));
  45086. ownerView->viewport->repaint (0, r.getY(), r.getRight(), r.getHeight());
  45087. }
  45088. }
  45089. bool TreeViewItem::areAllParentsOpen() const throw()
  45090. {
  45091. return parentItem == 0
  45092. || (parentItem->isOpen() && parentItem->areAllParentsOpen());
  45093. }
  45094. void TreeViewItem::updatePositions (int newY)
  45095. {
  45096. y = newY;
  45097. itemHeight = getItemHeight();
  45098. totalHeight = itemHeight;
  45099. itemWidth = getItemWidth();
  45100. totalWidth = jmax (itemWidth, 0) + getIndentX();
  45101. if (isOpen())
  45102. {
  45103. newY += totalHeight;
  45104. for (int i = 0; i < subItems.size(); ++i)
  45105. {
  45106. TreeViewItem* const ti = subItems.getUnchecked(i);
  45107. ti->updatePositions (newY);
  45108. newY += ti->totalHeight;
  45109. totalHeight += ti->totalHeight;
  45110. totalWidth = jmax (totalWidth, ti->totalWidth);
  45111. }
  45112. }
  45113. }
  45114. TreeViewItem* TreeViewItem::getDeepestOpenParentItem() throw()
  45115. {
  45116. TreeViewItem* result = this;
  45117. TreeViewItem* item = this;
  45118. while (item->parentItem != 0)
  45119. {
  45120. item = item->parentItem;
  45121. if (! item->isOpen())
  45122. result = item;
  45123. }
  45124. return result;
  45125. }
  45126. void TreeViewItem::setOwnerView (TreeView* const newOwner) throw()
  45127. {
  45128. ownerView = newOwner;
  45129. for (int i = subItems.size(); --i >= 0;)
  45130. subItems.getUnchecked(i)->setOwnerView (newOwner);
  45131. }
  45132. int TreeViewItem::getIndentX() const throw()
  45133. {
  45134. const int indentWidth = ownerView->getIndentSize();
  45135. int x = ownerView->rootItemVisible ? indentWidth : 0;
  45136. if (! ownerView->openCloseButtonsVisible)
  45137. x -= indentWidth;
  45138. TreeViewItem* p = parentItem;
  45139. while (p != 0)
  45140. {
  45141. x += indentWidth;
  45142. p = p->parentItem;
  45143. }
  45144. return x;
  45145. }
  45146. void TreeViewItem::setDrawsInLeftMargin (bool canDrawInLeftMargin) throw()
  45147. {
  45148. drawsInLeftMargin = canDrawInLeftMargin;
  45149. }
  45150. void TreeViewItem::paintRecursively (Graphics& g, int width)
  45151. {
  45152. jassert (ownerView != 0);
  45153. if (ownerView == 0)
  45154. return;
  45155. const int indent = getIndentX();
  45156. const int itemW = itemWidth < 0 ? width - indent : itemWidth;
  45157. g.setColour (ownerView->findColour (TreeView::linesColourId));
  45158. const float halfH = itemHeight * 0.5f;
  45159. int depth = 0;
  45160. TreeViewItem* p = parentItem;
  45161. while (p != 0)
  45162. {
  45163. ++depth;
  45164. p = p->parentItem;
  45165. }
  45166. if (! ownerView->rootItemVisible)
  45167. --depth;
  45168. const int indentWidth = ownerView->getIndentSize();
  45169. if (depth >= 0 && ownerView->openCloseButtonsVisible)
  45170. {
  45171. float x = (depth + 0.5f) * indentWidth;
  45172. if (depth >= 0)
  45173. {
  45174. if (parentItem != 0 && parentItem->drawLinesInside)
  45175. g.drawLine (x, 0, x, isLastOfSiblings() ? halfH : (float) itemHeight);
  45176. if ((parentItem != 0 && parentItem->drawLinesInside)
  45177. || (parentItem == 0 && drawLinesInside))
  45178. g.drawLine (x, halfH, x + indentWidth / 2, halfH);
  45179. }
  45180. p = parentItem;
  45181. int d = depth;
  45182. while (p != 0 && --d >= 0)
  45183. {
  45184. x -= (float) indentWidth;
  45185. if ((p->parentItem == 0 || p->parentItem->drawLinesInside)
  45186. && ! p->isLastOfSiblings())
  45187. {
  45188. g.drawLine (x, 0, x, (float) itemHeight);
  45189. }
  45190. p = p->parentItem;
  45191. }
  45192. if (mightContainSubItems())
  45193. {
  45194. g.saveState();
  45195. g.setOrigin (depth * indentWidth, 0);
  45196. g.reduceClipRegion (0, 0, indentWidth, itemHeight);
  45197. paintOpenCloseButton (g, indentWidth, itemHeight,
  45198. ((TreeViewContentComponent*) ownerView->viewport->getViewedComponent())
  45199. ->isMouseOverButton (this));
  45200. g.restoreState();
  45201. }
  45202. }
  45203. {
  45204. g.saveState();
  45205. g.setOrigin (indent, 0);
  45206. if (g.reduceClipRegion (drawsInLeftMargin ? -indent : 0, 0,
  45207. drawsInLeftMargin ? itemW + indent : itemW, itemHeight))
  45208. paintItem (g, itemW, itemHeight);
  45209. g.restoreState();
  45210. }
  45211. if (isOpen())
  45212. {
  45213. const Rectangle<int> clip (g.getClipBounds());
  45214. for (int i = 0; i < subItems.size(); ++i)
  45215. {
  45216. TreeViewItem* const ti = subItems.getUnchecked(i);
  45217. const int relY = ti->y - y;
  45218. if (relY >= clip.getBottom())
  45219. break;
  45220. if (relY + ti->totalHeight >= clip.getY())
  45221. {
  45222. g.saveState();
  45223. g.setOrigin (0, relY);
  45224. if (g.reduceClipRegion (0, 0, width, ti->totalHeight))
  45225. ti->paintRecursively (g, width);
  45226. g.restoreState();
  45227. }
  45228. }
  45229. }
  45230. }
  45231. bool TreeViewItem::isLastOfSiblings() const throw()
  45232. {
  45233. return parentItem == 0
  45234. || parentItem->subItems.getLast() == this;
  45235. }
  45236. int TreeViewItem::getIndexInParent() const throw()
  45237. {
  45238. if (parentItem == 0)
  45239. return 0;
  45240. return parentItem->subItems.indexOf (this);
  45241. }
  45242. TreeViewItem* TreeViewItem::getTopLevelItem() throw()
  45243. {
  45244. return (parentItem == 0) ? this
  45245. : parentItem->getTopLevelItem();
  45246. }
  45247. int TreeViewItem::getNumRows() const throw()
  45248. {
  45249. int num = 1;
  45250. if (isOpen())
  45251. {
  45252. for (int i = subItems.size(); --i >= 0;)
  45253. num += subItems.getUnchecked(i)->getNumRows();
  45254. }
  45255. return num;
  45256. }
  45257. TreeViewItem* TreeViewItem::getItemOnRow (int index) throw()
  45258. {
  45259. if (index == 0)
  45260. return this;
  45261. if (index > 0 && isOpen())
  45262. {
  45263. --index;
  45264. for (int i = 0; i < subItems.size(); ++i)
  45265. {
  45266. TreeViewItem* const item = subItems.getUnchecked(i);
  45267. if (index == 0)
  45268. return item;
  45269. const int numRows = item->getNumRows();
  45270. if (numRows > index)
  45271. return item->getItemOnRow (index);
  45272. index -= numRows;
  45273. }
  45274. }
  45275. return 0;
  45276. }
  45277. TreeViewItem* TreeViewItem::findItemRecursively (int targetY) throw()
  45278. {
  45279. if (((unsigned int) targetY) < (unsigned int) totalHeight)
  45280. {
  45281. const int h = itemHeight;
  45282. if (targetY < h)
  45283. return this;
  45284. if (isOpen())
  45285. {
  45286. targetY -= h;
  45287. for (int i = 0; i < subItems.size(); ++i)
  45288. {
  45289. TreeViewItem* const ti = subItems.getUnchecked(i);
  45290. if (targetY < ti->totalHeight)
  45291. return ti->findItemRecursively (targetY);
  45292. targetY -= ti->totalHeight;
  45293. }
  45294. }
  45295. }
  45296. return 0;
  45297. }
  45298. int TreeViewItem::countSelectedItemsRecursively() const throw()
  45299. {
  45300. int total = 0;
  45301. if (isSelected())
  45302. ++total;
  45303. for (int i = subItems.size(); --i >= 0;)
  45304. total += subItems.getUnchecked(i)->countSelectedItemsRecursively();
  45305. return total;
  45306. }
  45307. TreeViewItem* TreeViewItem::getSelectedItemWithIndex (int index) throw()
  45308. {
  45309. if (isSelected())
  45310. {
  45311. if (index == 0)
  45312. return this;
  45313. --index;
  45314. }
  45315. if (index >= 0)
  45316. {
  45317. for (int i = 0; i < subItems.size(); ++i)
  45318. {
  45319. TreeViewItem* const item = subItems.getUnchecked(i);
  45320. TreeViewItem* const found = item->getSelectedItemWithIndex (index);
  45321. if (found != 0)
  45322. return found;
  45323. index -= item->countSelectedItemsRecursively();
  45324. }
  45325. }
  45326. return 0;
  45327. }
  45328. int TreeViewItem::getRowNumberInTree() const throw()
  45329. {
  45330. if (parentItem != 0 && ownerView != 0)
  45331. {
  45332. int n = 1 + parentItem->getRowNumberInTree();
  45333. int ourIndex = parentItem->subItems.indexOf (this);
  45334. jassert (ourIndex >= 0);
  45335. while (--ourIndex >= 0)
  45336. n += parentItem->subItems [ourIndex]->getNumRows();
  45337. if (parentItem->parentItem == 0
  45338. && ! ownerView->rootItemVisible)
  45339. --n;
  45340. return n;
  45341. }
  45342. else
  45343. {
  45344. return 0;
  45345. }
  45346. }
  45347. void TreeViewItem::setLinesDrawnForSubItems (const bool drawLines) throw()
  45348. {
  45349. drawLinesInside = drawLines;
  45350. }
  45351. TreeViewItem* TreeViewItem::getNextVisibleItem (const bool recurse) const throw()
  45352. {
  45353. if (recurse && isOpen() && subItems.size() > 0)
  45354. return subItems [0];
  45355. if (parentItem != 0)
  45356. {
  45357. const int nextIndex = parentItem->subItems.indexOf (this) + 1;
  45358. if (nextIndex >= parentItem->subItems.size())
  45359. return parentItem->getNextVisibleItem (false);
  45360. return parentItem->subItems [nextIndex];
  45361. }
  45362. return 0;
  45363. }
  45364. const String TreeViewItem::getItemIdentifierString() const
  45365. {
  45366. String s;
  45367. if (parentItem != 0)
  45368. s = parentItem->getItemIdentifierString();
  45369. return s + T("/") + getUniqueName().replaceCharacter (T('/'), T('\\'));
  45370. }
  45371. TreeViewItem* TreeViewItem::findItemFromIdentifierString (const String& identifierString)
  45372. {
  45373. const String uid (getUniqueName());
  45374. if (uid == identifierString)
  45375. return this;
  45376. if (identifierString.startsWith (uid + T("/")))
  45377. {
  45378. const String remainingPath (identifierString.substring (uid.length() + 1));
  45379. bool wasOpen = isOpen();
  45380. setOpen (true);
  45381. for (int i = subItems.size(); --i >= 0;)
  45382. {
  45383. TreeViewItem* item = subItems.getUnchecked(i)->findItemFromIdentifierString (remainingPath);
  45384. if (item != 0)
  45385. return item;
  45386. }
  45387. setOpen (wasOpen);
  45388. }
  45389. return 0;
  45390. }
  45391. void TreeViewItem::restoreOpennessState (const XmlElement& e) throw()
  45392. {
  45393. if (e.hasTagName (T("CLOSED")))
  45394. {
  45395. setOpen (false);
  45396. }
  45397. else if (e.hasTagName (T("OPEN")))
  45398. {
  45399. setOpen (true);
  45400. forEachXmlChildElement (e, n)
  45401. {
  45402. const String id (n->getStringAttribute (T("id")));
  45403. for (int i = 0; i < subItems.size(); ++i)
  45404. {
  45405. TreeViewItem* const ti = subItems.getUnchecked(i);
  45406. if (ti->getUniqueName() == id)
  45407. {
  45408. ti->restoreOpennessState (*n);
  45409. break;
  45410. }
  45411. }
  45412. }
  45413. }
  45414. }
  45415. XmlElement* TreeViewItem::getOpennessState() const throw()
  45416. {
  45417. const String name (getUniqueName());
  45418. if (name.isNotEmpty())
  45419. {
  45420. XmlElement* e;
  45421. if (isOpen())
  45422. {
  45423. e = new XmlElement (T("OPEN"));
  45424. for (int i = 0; i < subItems.size(); ++i)
  45425. e->addChildElement (subItems.getUnchecked(i)->getOpennessState());
  45426. }
  45427. else
  45428. {
  45429. e = new XmlElement (T("CLOSED"));
  45430. }
  45431. e->setAttribute (T("id"), name);
  45432. return e;
  45433. }
  45434. else
  45435. {
  45436. // trying to save the openness for an element that has no name - this won't
  45437. // work because it needs the names to identify what to open.
  45438. jassertfalse
  45439. }
  45440. return 0;
  45441. }
  45442. END_JUCE_NAMESPACE
  45443. /*** End of inlined file: juce_TreeView.cpp ***/
  45444. /*** Start of inlined file: juce_DirectoryContentsDisplayComponent.cpp ***/
  45445. BEGIN_JUCE_NAMESPACE
  45446. DirectoryContentsDisplayComponent::DirectoryContentsDisplayComponent (DirectoryContentsList& listToShow)
  45447. : fileList (listToShow)
  45448. {
  45449. }
  45450. DirectoryContentsDisplayComponent::~DirectoryContentsDisplayComponent()
  45451. {
  45452. }
  45453. FileBrowserListener::~FileBrowserListener()
  45454. {
  45455. }
  45456. void DirectoryContentsDisplayComponent::addListener (FileBrowserListener* const listener) throw()
  45457. {
  45458. listeners.add (listener);
  45459. }
  45460. void DirectoryContentsDisplayComponent::removeListener (FileBrowserListener* const listener) throw()
  45461. {
  45462. listeners.remove (listener);
  45463. }
  45464. void DirectoryContentsDisplayComponent::sendSelectionChangeMessage()
  45465. {
  45466. Component::BailOutChecker checker (dynamic_cast <Component*> (this));
  45467. listeners.callChecked (checker, &FileBrowserListener::selectionChanged);
  45468. }
  45469. void DirectoryContentsDisplayComponent::sendMouseClickMessage (const File& file, const MouseEvent& e)
  45470. {
  45471. if (fileList.getDirectory().exists())
  45472. {
  45473. Component::BailOutChecker checker (dynamic_cast <Component*> (this));
  45474. listeners.callChecked (checker, &FileBrowserListener::fileClicked, file, e);
  45475. }
  45476. }
  45477. void DirectoryContentsDisplayComponent::sendDoubleClickMessage (const File& file)
  45478. {
  45479. if (fileList.getDirectory().exists())
  45480. {
  45481. Component::BailOutChecker checker (dynamic_cast <Component*> (this));
  45482. listeners.callChecked (checker, &FileBrowserListener::fileDoubleClicked, file);
  45483. }
  45484. }
  45485. END_JUCE_NAMESPACE
  45486. /*** End of inlined file: juce_DirectoryContentsDisplayComponent.cpp ***/
  45487. /*** Start of inlined file: juce_DirectoryContentsList.cpp ***/
  45488. BEGIN_JUCE_NAMESPACE
  45489. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  45490. bool* isDirectory, bool* isHidden, int64* fileSize, Time* modTime,
  45491. Time* creationTime, bool* isReadOnly);
  45492. bool juce_findFileNext (void* handle, String& resultFile,
  45493. bool* isDirectory, bool* isHidden, int64* fileSize,
  45494. Time* modTime, Time* creationTime, bool* isReadOnly);
  45495. void juce_findFileClose (void* handle);
  45496. DirectoryContentsList::DirectoryContentsList (const FileFilter* const fileFilter_,
  45497. TimeSliceThread& thread_)
  45498. : fileFilter (fileFilter_),
  45499. thread (thread_),
  45500. includeDirectories (false),
  45501. includeFiles (false),
  45502. ignoreHiddenFiles (true),
  45503. fileFindHandle (0),
  45504. shouldStop (true)
  45505. {
  45506. }
  45507. DirectoryContentsList::~DirectoryContentsList()
  45508. {
  45509. clear();
  45510. }
  45511. void DirectoryContentsList::setIgnoresHiddenFiles (const bool shouldIgnoreHiddenFiles)
  45512. {
  45513. ignoreHiddenFiles = shouldIgnoreHiddenFiles;
  45514. }
  45515. const File& DirectoryContentsList::getDirectory() const
  45516. {
  45517. return root;
  45518. }
  45519. void DirectoryContentsList::setDirectory (const File& directory,
  45520. const bool includeDirectories_,
  45521. const bool includeFiles_)
  45522. {
  45523. if (directory != root
  45524. || includeDirectories != includeDirectories_
  45525. || includeFiles != includeFiles_)
  45526. {
  45527. clear();
  45528. root = directory;
  45529. includeDirectories = includeDirectories_;
  45530. includeFiles = includeFiles_;
  45531. refresh();
  45532. }
  45533. }
  45534. void DirectoryContentsList::clear()
  45535. {
  45536. shouldStop = true;
  45537. thread.removeTimeSliceClient (this);
  45538. if (fileFindHandle != 0)
  45539. {
  45540. juce_findFileClose (fileFindHandle);
  45541. fileFindHandle = 0;
  45542. }
  45543. if (files.size() > 0)
  45544. {
  45545. files.clear();
  45546. changed();
  45547. }
  45548. }
  45549. void DirectoryContentsList::refresh()
  45550. {
  45551. clear();
  45552. if (root.isDirectory())
  45553. {
  45554. String fileFound;
  45555. bool fileFoundIsDir, isHidden, isReadOnly;
  45556. int64 fileSize;
  45557. Time modTime, creationTime;
  45558. String path (root.getFullPathName());
  45559. if (! path.endsWithChar (File::separator))
  45560. path += File::separator;
  45561. jassert (fileFindHandle == 0);
  45562. fileFindHandle = juce_findFileStart (path, T("*"), fileFound,
  45563. &fileFoundIsDir,
  45564. &isHidden,
  45565. &fileSize,
  45566. &modTime,
  45567. &creationTime,
  45568. &isReadOnly);
  45569. if (fileFindHandle != 0 && fileFound.isNotEmpty())
  45570. {
  45571. if (addFile (fileFound, fileFoundIsDir, isHidden,
  45572. fileSize, modTime, creationTime, isReadOnly))
  45573. {
  45574. changed();
  45575. }
  45576. }
  45577. shouldStop = false;
  45578. thread.addTimeSliceClient (this);
  45579. }
  45580. }
  45581. int DirectoryContentsList::getNumFiles() const
  45582. {
  45583. return files.size();
  45584. }
  45585. bool DirectoryContentsList::getFileInfo (const int index,
  45586. FileInfo& result) const
  45587. {
  45588. const ScopedLock sl (fileListLock);
  45589. const FileInfo* const info = files [index];
  45590. if (info != 0)
  45591. {
  45592. result = *info;
  45593. return true;
  45594. }
  45595. return false;
  45596. }
  45597. const File DirectoryContentsList::getFile (const int index) const
  45598. {
  45599. const ScopedLock sl (fileListLock);
  45600. const FileInfo* const info = files [index];
  45601. if (info != 0)
  45602. return root.getChildFile (info->filename);
  45603. return File::nonexistent;
  45604. }
  45605. bool DirectoryContentsList::isStillLoading() const
  45606. {
  45607. return fileFindHandle != 0;
  45608. }
  45609. void DirectoryContentsList::changed()
  45610. {
  45611. sendChangeMessage (this);
  45612. }
  45613. bool DirectoryContentsList::useTimeSlice()
  45614. {
  45615. const uint32 startTime = Time::getApproximateMillisecondCounter();
  45616. bool hasChanged = false;
  45617. for (int i = 100; --i >= 0;)
  45618. {
  45619. if (! checkNextFile (hasChanged))
  45620. {
  45621. if (hasChanged)
  45622. changed();
  45623. return false;
  45624. }
  45625. if (shouldStop || (Time::getApproximateMillisecondCounter() > startTime + 150))
  45626. break;
  45627. }
  45628. if (hasChanged)
  45629. changed();
  45630. return true;
  45631. }
  45632. bool DirectoryContentsList::checkNextFile (bool& hasChanged)
  45633. {
  45634. if (fileFindHandle != 0)
  45635. {
  45636. String fileFound;
  45637. bool fileFoundIsDir, isHidden, isReadOnly;
  45638. int64 fileSize;
  45639. Time modTime, creationTime;
  45640. if (juce_findFileNext (fileFindHandle, fileFound,
  45641. &fileFoundIsDir, &isHidden,
  45642. &fileSize,
  45643. &modTime,
  45644. &creationTime,
  45645. &isReadOnly))
  45646. {
  45647. if (addFile (fileFound, fileFoundIsDir, isHidden, fileSize,
  45648. modTime, creationTime, isReadOnly))
  45649. {
  45650. hasChanged = true;
  45651. }
  45652. return true;
  45653. }
  45654. else
  45655. {
  45656. juce_findFileClose (fileFindHandle);
  45657. fileFindHandle = 0;
  45658. }
  45659. }
  45660. return false;
  45661. }
  45662. int DirectoryContentsList::compareElements (const DirectoryContentsList::FileInfo* const first,
  45663. const DirectoryContentsList::FileInfo* const second)
  45664. {
  45665. #if JUCE_WINDOWS
  45666. if (first->isDirectory != second->isDirectory)
  45667. return first->isDirectory ? -1 : 1;
  45668. #endif
  45669. return first->filename.compareIgnoreCase (second->filename);
  45670. }
  45671. bool DirectoryContentsList::addFile (const String& filename,
  45672. const bool isDir,
  45673. const bool isHidden,
  45674. const int64 fileSize,
  45675. const Time& modTime,
  45676. const Time& creationTime,
  45677. const bool isReadOnly)
  45678. {
  45679. if (filename == T("..")
  45680. || filename == T(".")
  45681. || (ignoreHiddenFiles && isHidden))
  45682. return false;
  45683. const File file (root.getChildFile (filename));
  45684. if (((isDir && includeDirectories) || ((! isDir) && includeFiles))
  45685. && (fileFilter == 0
  45686. || ((! isDir) && fileFilter->isFileSuitable (file))
  45687. || (isDir && fileFilter->isDirectorySuitable (file))))
  45688. {
  45689. ScopedPointer <FileInfo> info (new FileInfo());
  45690. info->filename = filename;
  45691. info->fileSize = fileSize;
  45692. info->modificationTime = modTime;
  45693. info->creationTime = creationTime;
  45694. info->isDirectory = isDir;
  45695. info->isReadOnly = isReadOnly;
  45696. const ScopedLock sl (fileListLock);
  45697. for (int i = files.size(); --i >= 0;)
  45698. if (files.getUnchecked(i)->filename == info->filename)
  45699. return false;
  45700. files.addSorted (*this, info.release());
  45701. return true;
  45702. }
  45703. return false;
  45704. }
  45705. END_JUCE_NAMESPACE
  45706. /*** End of inlined file: juce_DirectoryContentsList.cpp ***/
  45707. /*** Start of inlined file: juce_FileBrowserComponent.cpp ***/
  45708. BEGIN_JUCE_NAMESPACE
  45709. FileBrowserComponent::FileBrowserComponent (int flags_,
  45710. const File& initialFileOrDirectory,
  45711. const FileFilter* fileFilter_,
  45712. FilePreviewComponent* previewComp_)
  45713. : FileFilter (String::empty),
  45714. fileFilter (fileFilter_),
  45715. flags (flags_),
  45716. previewComp (previewComp_),
  45717. thread ("Juce FileBrowser")
  45718. {
  45719. // You need to specify one or other of the open/save flags..
  45720. jassert ((flags & (saveMode | openMode)) != 0);
  45721. jassert ((flags & (saveMode | openMode)) != (saveMode | openMode));
  45722. // You need to specify at least one of these flags..
  45723. jassert ((flags & (canSelectFiles | canSelectDirectories)) != 0);
  45724. String filename;
  45725. if (initialFileOrDirectory == File::nonexistent)
  45726. {
  45727. currentRoot = File::getCurrentWorkingDirectory();
  45728. }
  45729. else if (initialFileOrDirectory.isDirectory())
  45730. {
  45731. currentRoot = initialFileOrDirectory;
  45732. }
  45733. else
  45734. {
  45735. chosenFiles.add (initialFileOrDirectory);
  45736. currentRoot = initialFileOrDirectory.getParentDirectory();
  45737. filename = initialFileOrDirectory.getFileName();
  45738. }
  45739. fileList = new DirectoryContentsList (this, thread);
  45740. if ((flags & useTreeView) != 0)
  45741. {
  45742. FileTreeComponent* const tree = new FileTreeComponent (*fileList);
  45743. if ((flags & canSelectMultipleItems) != 0)
  45744. tree->setMultiSelectEnabled (true);
  45745. addAndMakeVisible (tree);
  45746. fileListComponent = tree;
  45747. }
  45748. else
  45749. {
  45750. FileListComponent* const list = new FileListComponent (*fileList);
  45751. list->setOutlineThickness (1);
  45752. if ((flags & canSelectMultipleItems) != 0)
  45753. list->setMultipleSelectionEnabled (true);
  45754. addAndMakeVisible (list);
  45755. fileListComponent = list;
  45756. }
  45757. fileListComponent->addListener (this);
  45758. addAndMakeVisible (currentPathBox = new ComboBox ("path"));
  45759. currentPathBox->setEditableText (true);
  45760. StringArray rootNames, rootPaths;
  45761. const BitArray separators (getRoots (rootNames, rootPaths));
  45762. for (int i = 0; i < rootNames.size(); ++i)
  45763. {
  45764. if (separators [i])
  45765. currentPathBox->addSeparator();
  45766. currentPathBox->addItem (rootNames[i], i + 1);
  45767. }
  45768. currentPathBox->addSeparator();
  45769. currentPathBox->addListener (this);
  45770. addAndMakeVisible (filenameBox = new TextEditor());
  45771. filenameBox->setMultiLine (false);
  45772. filenameBox->setSelectAllWhenFocused (true);
  45773. filenameBox->setText (filename, false);
  45774. filenameBox->addListener (this);
  45775. filenameBox->setReadOnly ((flags & (filenameBoxIsReadOnly | canSelectMultipleItems)) != 0);
  45776. Label* label = new Label ("f", TRANS("file:"));
  45777. addAndMakeVisible (label);
  45778. label->attachToComponent (filenameBox, true);
  45779. addAndMakeVisible (goUpButton = getLookAndFeel().createFileBrowserGoUpButton());
  45780. goUpButton->addButtonListener (this);
  45781. goUpButton->setTooltip (TRANS ("go up to parent directory"));
  45782. if (previewComp != 0)
  45783. addAndMakeVisible (previewComp);
  45784. setRoot (currentRoot);
  45785. thread.startThread (4);
  45786. }
  45787. FileBrowserComponent::~FileBrowserComponent()
  45788. {
  45789. if (previewComp != 0)
  45790. removeChildComponent (previewComp);
  45791. deleteAllChildren();
  45792. fileList = 0;
  45793. thread.stopThread (10000);
  45794. }
  45795. void FileBrowserComponent::addListener (FileBrowserListener* const newListener) throw()
  45796. {
  45797. listeners.add (newListener);
  45798. }
  45799. void FileBrowserComponent::removeListener (FileBrowserListener* const listener) throw()
  45800. {
  45801. listeners.remove (listener);
  45802. }
  45803. bool FileBrowserComponent::isSaveMode() const throw()
  45804. {
  45805. return (flags & saveMode) != 0;
  45806. }
  45807. int FileBrowserComponent::getNumSelectedFiles() const throw()
  45808. {
  45809. if (chosenFiles.size() == 0 && currentFileIsValid())
  45810. return 1;
  45811. return chosenFiles.size();
  45812. }
  45813. const File FileBrowserComponent::getSelectedFile (int index) const throw()
  45814. {
  45815. if (! filenameBox->isReadOnly())
  45816. return currentRoot.getChildFile (filenameBox->getText());
  45817. else
  45818. return chosenFiles[index];
  45819. }
  45820. bool FileBrowserComponent::currentFileIsValid() const
  45821. {
  45822. if (isSaveMode())
  45823. return ! getSelectedFile (0).isDirectory();
  45824. else
  45825. return getSelectedFile (0).exists();
  45826. }
  45827. const File FileBrowserComponent::getHighlightedFile() const throw()
  45828. {
  45829. return fileListComponent->getSelectedFile (0);
  45830. }
  45831. bool FileBrowserComponent::isFileSuitable (const File& file) const
  45832. {
  45833. return (flags & canSelectFiles) != 0 ? (fileFilter == 0 || fileFilter->isFileSuitable (file))
  45834. : false;
  45835. }
  45836. bool FileBrowserComponent::isDirectorySuitable (const File&) const
  45837. {
  45838. return true;
  45839. }
  45840. bool FileBrowserComponent::isFileOrDirSuitable (const File& f) const
  45841. {
  45842. if (f.isDirectory())
  45843. return (flags & canSelectDirectories) != 0 && (fileFilter == 0 || fileFilter->isDirectorySuitable (f));
  45844. return (flags & canSelectFiles) != 0 && f.exists()
  45845. && (fileFilter == 0 || fileFilter->isFileSuitable (f));
  45846. }
  45847. const File FileBrowserComponent::getRoot() const
  45848. {
  45849. return currentRoot;
  45850. }
  45851. void FileBrowserComponent::setRoot (const File& newRootDirectory)
  45852. {
  45853. if (currentRoot != newRootDirectory)
  45854. {
  45855. fileListComponent->scrollToTop();
  45856. String path (newRootDirectory.getFullPathName());
  45857. if (path.isEmpty())
  45858. path += File::separator;
  45859. StringArray rootNames, rootPaths;
  45860. getRoots (rootNames, rootPaths);
  45861. if (! rootPaths.contains (path, true))
  45862. {
  45863. bool alreadyListed = false;
  45864. for (int i = currentPathBox->getNumItems(); --i >= 0;)
  45865. {
  45866. if (currentPathBox->getItemText (i).equalsIgnoreCase (path))
  45867. {
  45868. alreadyListed = true;
  45869. break;
  45870. }
  45871. }
  45872. if (! alreadyListed)
  45873. currentPathBox->addItem (path, currentPathBox->getNumItems() + 2);
  45874. }
  45875. }
  45876. currentRoot = newRootDirectory;
  45877. fileList->setDirectory (currentRoot, true, true);
  45878. String currentRootName (currentRoot.getFullPathName());
  45879. if (currentRootName.isEmpty())
  45880. currentRootName += File::separator;
  45881. currentPathBox->setText (currentRootName, true);
  45882. goUpButton->setEnabled (currentRoot.getParentDirectory().isDirectory()
  45883. && currentRoot.getParentDirectory() != currentRoot);
  45884. }
  45885. void FileBrowserComponent::goUp()
  45886. {
  45887. setRoot (getRoot().getParentDirectory());
  45888. }
  45889. void FileBrowserComponent::refresh()
  45890. {
  45891. fileList->refresh();
  45892. }
  45893. const String FileBrowserComponent::getActionVerb() const
  45894. {
  45895. return isSaveMode() ? TRANS("Save") : TRANS("Open");
  45896. }
  45897. FilePreviewComponent* FileBrowserComponent::getPreviewComponent() const throw()
  45898. {
  45899. return previewComp;
  45900. }
  45901. void FileBrowserComponent::resized()
  45902. {
  45903. getLookAndFeel()
  45904. .layoutFileBrowserComponent (*this, fileListComponent,
  45905. previewComp, currentPathBox,
  45906. filenameBox, goUpButton);
  45907. }
  45908. void FileBrowserComponent::sendListenerChangeMessage()
  45909. {
  45910. Component::BailOutChecker checker (this);
  45911. if (previewComp != 0)
  45912. previewComp->selectedFileChanged (getSelectedFile (0));
  45913. // You shouldn't delete the browser when the file gets changed!
  45914. jassert (! checker.shouldBailOut());
  45915. listeners.callChecked (checker, &FileBrowserListener::selectionChanged);
  45916. }
  45917. void FileBrowserComponent::selectionChanged()
  45918. {
  45919. StringArray newFilenames;
  45920. bool resetChosenFiles = true;
  45921. for (int i = 0; i < fileListComponent->getNumSelectedFiles(); ++i)
  45922. {
  45923. const File f (fileListComponent->getSelectedFile (i));
  45924. if (isFileOrDirSuitable (f))
  45925. {
  45926. if (resetChosenFiles)
  45927. {
  45928. chosenFiles.clear();
  45929. resetChosenFiles = false;
  45930. }
  45931. chosenFiles.add (f);
  45932. newFilenames.add (f.getRelativePathFrom (getRoot()));
  45933. }
  45934. }
  45935. if (newFilenames.size() > 0)
  45936. filenameBox->setText (newFilenames.joinIntoString (T(", ")), false);
  45937. sendListenerChangeMessage();
  45938. }
  45939. void FileBrowserComponent::fileClicked (const File& f, const MouseEvent& e)
  45940. {
  45941. Component::BailOutChecker checker (this);
  45942. listeners.callChecked (checker, &FileBrowserListener::fileClicked, f, e);
  45943. }
  45944. void FileBrowserComponent::fileDoubleClicked (const File& f)
  45945. {
  45946. if (f.isDirectory())
  45947. {
  45948. setRoot (f);
  45949. }
  45950. else
  45951. {
  45952. Component::BailOutChecker checker (this);
  45953. listeners.callChecked (checker, &FileBrowserListener::fileDoubleClicked, f);
  45954. }
  45955. }
  45956. bool FileBrowserComponent::keyPressed (const KeyPress& key)
  45957. {
  45958. #if JUCE_LINUX || JUCE_WINDOWS
  45959. if (key.getModifiers().isCommandDown()
  45960. && (key.getKeyCode() == 'H' || key.getKeyCode() == 'h'))
  45961. {
  45962. fileList->setIgnoresHiddenFiles (! fileList->ignoresHiddenFiles());
  45963. fileList->refresh();
  45964. return true;
  45965. }
  45966. #endif
  45967. return false;
  45968. }
  45969. void FileBrowserComponent::textEditorTextChanged (TextEditor&)
  45970. {
  45971. sendListenerChangeMessage();
  45972. }
  45973. void FileBrowserComponent::textEditorReturnKeyPressed (TextEditor&)
  45974. {
  45975. if (filenameBox->getText().containsChar (File::separator))
  45976. {
  45977. const File f (currentRoot.getChildFile (filenameBox->getText()));
  45978. if (f.isDirectory())
  45979. {
  45980. setRoot (f);
  45981. chosenFiles.clear();
  45982. filenameBox->setText (String::empty);
  45983. }
  45984. else
  45985. {
  45986. setRoot (f.getParentDirectory());
  45987. chosenFiles.clear();
  45988. chosenFiles.add (f);
  45989. filenameBox->setText (f.getFileName());
  45990. }
  45991. }
  45992. else
  45993. {
  45994. fileDoubleClicked (getSelectedFile (0));
  45995. }
  45996. }
  45997. void FileBrowserComponent::textEditorEscapeKeyPressed (TextEditor&)
  45998. {
  45999. }
  46000. void FileBrowserComponent::textEditorFocusLost (TextEditor&)
  46001. {
  46002. if (! isSaveMode())
  46003. selectionChanged();
  46004. }
  46005. void FileBrowserComponent::buttonClicked (Button*)
  46006. {
  46007. goUp();
  46008. }
  46009. void FileBrowserComponent::comboBoxChanged (ComboBox*)
  46010. {
  46011. const String newText (currentPathBox->getText().trim().unquoted());
  46012. if (newText.isNotEmpty())
  46013. {
  46014. const int index = currentPathBox->getSelectedId() - 1;
  46015. StringArray rootNames, rootPaths;
  46016. getRoots (rootNames, rootPaths);
  46017. if (rootPaths [index].isNotEmpty())
  46018. {
  46019. setRoot (File (rootPaths [index]));
  46020. }
  46021. else
  46022. {
  46023. File f (newText);
  46024. for (;;)
  46025. {
  46026. if (f.isDirectory())
  46027. {
  46028. setRoot (f);
  46029. break;
  46030. }
  46031. if (f.getParentDirectory() == f)
  46032. break;
  46033. f = f.getParentDirectory();
  46034. }
  46035. }
  46036. }
  46037. }
  46038. const BitArray FileBrowserComponent::getRoots (StringArray& rootNames, StringArray& rootPaths)
  46039. {
  46040. BitArray separators;
  46041. #if JUCE_WINDOWS
  46042. Array<File> roots;
  46043. File::findFileSystemRoots (roots);
  46044. rootPaths.clear();
  46045. for (int i = 0; i < roots.size(); ++i)
  46046. {
  46047. const File& drive = roots.getReference(i);
  46048. String name (drive.getFullPathName());
  46049. rootPaths.add (name);
  46050. if (drive.isOnHardDisk())
  46051. {
  46052. String volume (drive.getVolumeLabel());
  46053. if (volume.isEmpty())
  46054. volume = TRANS("Hard Drive");
  46055. name << " [" << drive.getVolumeLabel() << ']';
  46056. }
  46057. else if (drive.isOnCDRomDrive())
  46058. {
  46059. name << TRANS(" [CD/DVD drive]");
  46060. }
  46061. rootNames.add (name);
  46062. }
  46063. separators.setBit (rootPaths.size());
  46064. rootPaths.add (File::getSpecialLocation (File::userDocumentsDirectory).getFullPathName());
  46065. rootNames.add ("Documents");
  46066. rootPaths.add (File::getSpecialLocation (File::userDesktopDirectory).getFullPathName());
  46067. rootNames.add ("Desktop");
  46068. #endif
  46069. #if JUCE_MAC
  46070. rootPaths.add (File::getSpecialLocation (File::userHomeDirectory).getFullPathName());
  46071. rootNames.add ("Home folder");
  46072. rootPaths.add (File::getSpecialLocation (File::userDocumentsDirectory).getFullPathName());
  46073. rootNames.add ("Documents");
  46074. rootPaths.add (File::getSpecialLocation (File::userDesktopDirectory).getFullPathName());
  46075. rootNames.add ("Desktop");
  46076. separators.setBit (rootPaths.size());
  46077. Array <File> volumes;
  46078. File vol ("/Volumes");
  46079. vol.findChildFiles (volumes, File::findDirectories, false);
  46080. for (int i = 0; i < volumes.size(); ++i)
  46081. {
  46082. const File& volume = volumes.getReference(i);
  46083. if (volume.isDirectory() && ! volume.getFileName().startsWithChar (T('.')))
  46084. {
  46085. rootPaths.add (volume.getFullPathName());
  46086. rootNames.add (volume.getFileName());
  46087. }
  46088. }
  46089. #endif
  46090. #if JUCE_LINUX
  46091. rootPaths.add ("/");
  46092. rootNames.add ("/");
  46093. rootPaths.add (File::getSpecialLocation (File::userHomeDirectory).getFullPathName());
  46094. rootNames.add ("Home folder");
  46095. rootPaths.add (File::getSpecialLocation (File::userDesktopDirectory).getFullPathName());
  46096. rootNames.add ("Desktop");
  46097. #endif
  46098. return separators;
  46099. }
  46100. END_JUCE_NAMESPACE
  46101. /*** End of inlined file: juce_FileBrowserComponent.cpp ***/
  46102. /*** Start of inlined file: juce_FileChooser.cpp ***/
  46103. BEGIN_JUCE_NAMESPACE
  46104. FileChooser::FileChooser (const String& chooserBoxTitle,
  46105. const File& currentFileOrDirectory,
  46106. const String& fileFilters,
  46107. const bool useNativeDialogBox_)
  46108. : title (chooserBoxTitle),
  46109. filters (fileFilters),
  46110. startingFile (currentFileOrDirectory),
  46111. useNativeDialogBox (useNativeDialogBox_)
  46112. {
  46113. #if JUCE_LINUX
  46114. useNativeDialogBox = false;
  46115. #endif
  46116. if (! fileFilters.containsNonWhitespaceChars())
  46117. filters = T("*");
  46118. }
  46119. FileChooser::~FileChooser()
  46120. {
  46121. }
  46122. bool FileChooser::browseForFileToOpen (FilePreviewComponent* previewComponent)
  46123. {
  46124. return showDialog (false, true, false, false, false, previewComponent);
  46125. }
  46126. bool FileChooser::browseForMultipleFilesToOpen (FilePreviewComponent* previewComponent)
  46127. {
  46128. return showDialog (false, true, false, false, true, previewComponent);
  46129. }
  46130. bool FileChooser::browseForMultipleFilesOrDirectories (FilePreviewComponent* previewComponent)
  46131. {
  46132. return showDialog (true, true, false, false, true, previewComponent);
  46133. }
  46134. bool FileChooser::browseForFileToSave (const bool warnAboutOverwritingExistingFiles)
  46135. {
  46136. return showDialog (false, true, true, warnAboutOverwritingExistingFiles, false, 0);
  46137. }
  46138. bool FileChooser::browseForDirectory()
  46139. {
  46140. return showDialog (true, false, false, false, false, 0);
  46141. }
  46142. const File FileChooser::getResult() const
  46143. {
  46144. // if you've used a multiple-file select, you should use the getResults() method
  46145. // to retrieve all the files that were chosen.
  46146. jassert (results.size() <= 1);
  46147. return results.getFirst();
  46148. }
  46149. const Array<File>& FileChooser::getResults() const
  46150. {
  46151. return results;
  46152. }
  46153. bool FileChooser::showDialog (const bool selectsDirectories,
  46154. const bool selectsFiles,
  46155. const bool isSave,
  46156. const bool warnAboutOverwritingExistingFiles,
  46157. const bool selectMultipleFiles,
  46158. FilePreviewComponent* const previewComponent)
  46159. {
  46160. Component::SafePointer<Component> previouslyFocused (Component::getCurrentlyFocusedComponent());
  46161. results.clear();
  46162. // the preview component needs to be the right size before you pass it in here..
  46163. jassert (previewComponent == 0 || (previewComponent->getWidth() > 10
  46164. && previewComponent->getHeight() > 10));
  46165. #if JUCE_WINDOWS
  46166. if (useNativeDialogBox && ! (selectsFiles && selectsDirectories))
  46167. #elif JUCE_MAC
  46168. if (useNativeDialogBox && (previewComponent == 0))
  46169. #else
  46170. if (false)
  46171. #endif
  46172. {
  46173. showPlatformDialog (results, title, startingFile, filters,
  46174. selectsDirectories, selectsFiles, isSave,
  46175. warnAboutOverwritingExistingFiles,
  46176. selectMultipleFiles,
  46177. previewComponent);
  46178. }
  46179. else
  46180. {
  46181. WildcardFileFilter wildcard (selectsFiles ? filters : String::empty,
  46182. selectsDirectories ? "*" : String::empty,
  46183. String::empty);
  46184. int flags = isSave ? FileBrowserComponent::saveMode
  46185. : FileBrowserComponent::openMode;
  46186. if (selectsFiles)
  46187. flags |= FileBrowserComponent::canSelectFiles;
  46188. if (selectsDirectories)
  46189. flags |= FileBrowserComponent::canSelectDirectories;
  46190. if (selectMultipleFiles)
  46191. flags |= FileBrowserComponent::canSelectMultipleItems;
  46192. FileBrowserComponent browserComponent (flags, startingFile, &wildcard, previewComponent);
  46193. FileChooserDialogBox box (title, String::empty,
  46194. browserComponent,
  46195. warnAboutOverwritingExistingFiles,
  46196. browserComponent.findColour (AlertWindow::backgroundColourId));
  46197. if (box.show())
  46198. {
  46199. for (int i = 0; i < browserComponent.getNumSelectedFiles(); ++i)
  46200. results.add (browserComponent.getSelectedFile (i));
  46201. }
  46202. }
  46203. if (previouslyFocused != 0)
  46204. previouslyFocused->grabKeyboardFocus();
  46205. return results.size() > 0;
  46206. }
  46207. FilePreviewComponent::FilePreviewComponent()
  46208. {
  46209. }
  46210. FilePreviewComponent::~FilePreviewComponent()
  46211. {
  46212. }
  46213. END_JUCE_NAMESPACE
  46214. /*** End of inlined file: juce_FileChooser.cpp ***/
  46215. /*** Start of inlined file: juce_FileChooserDialogBox.cpp ***/
  46216. BEGIN_JUCE_NAMESPACE
  46217. FileChooserDialogBox::FileChooserDialogBox (const String& name,
  46218. const String& instructions,
  46219. FileBrowserComponent& chooserComponent,
  46220. const bool warnAboutOverwritingExistingFiles_,
  46221. const Colour& backgroundColour)
  46222. : ResizableWindow (name, backgroundColour, true),
  46223. warnAboutOverwritingExistingFiles (warnAboutOverwritingExistingFiles_)
  46224. {
  46225. content = new ContentComponent();
  46226. content->setName (name);
  46227. content->instructions = instructions;
  46228. content->chooserComponent = &chooserComponent;
  46229. content->addAndMakeVisible (&chooserComponent);
  46230. content->okButton = new TextButton (chooserComponent.getActionVerb());
  46231. content->addAndMakeVisible (content->okButton);
  46232. content->okButton->addButtonListener (this);
  46233. content->okButton->setEnabled (chooserComponent.currentFileIsValid());
  46234. content->okButton->addShortcut (KeyPress (KeyPress::returnKey, 0, 0));
  46235. content->cancelButton = new TextButton (TRANS("Cancel"));
  46236. content->addAndMakeVisible (content->cancelButton);
  46237. content->cancelButton->addButtonListener (this);
  46238. content->cancelButton->addShortcut (KeyPress (KeyPress::escapeKey, 0, 0));
  46239. setContentComponent (content);
  46240. setResizable (true, true);
  46241. setResizeLimits (300, 300, 1200, 1000);
  46242. content->chooserComponent->addListener (this);
  46243. }
  46244. FileChooserDialogBox::~FileChooserDialogBox()
  46245. {
  46246. content->chooserComponent->removeListener (this);
  46247. }
  46248. bool FileChooserDialogBox::show (int w, int h)
  46249. {
  46250. if (w <= 0)
  46251. {
  46252. Component* const previewComp = content->chooserComponent->getPreviewComponent();
  46253. if (previewComp != 0)
  46254. w = 400 + previewComp->getWidth();
  46255. else
  46256. w = 600;
  46257. }
  46258. if (h <= 0)
  46259. h = 500;
  46260. centreWithSize (w, h);
  46261. const bool ok = (runModalLoop() != 0);
  46262. setVisible (false);
  46263. return ok;
  46264. }
  46265. void FileChooserDialogBox::buttonClicked (Button* button)
  46266. {
  46267. if (button == content->okButton)
  46268. {
  46269. if (warnAboutOverwritingExistingFiles
  46270. && content->chooserComponent->isSaveMode()
  46271. && content->chooserComponent->getSelectedFile(0).exists())
  46272. {
  46273. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  46274. TRANS("File already exists"),
  46275. TRANS("There's already a file called:\n\n")
  46276. + content->chooserComponent->getSelectedFile(0).getFullPathName()
  46277. + T("\n\nAre you sure you want to overwrite it?"),
  46278. TRANS("overwrite"),
  46279. TRANS("cancel")))
  46280. {
  46281. return;
  46282. }
  46283. }
  46284. exitModalState (1);
  46285. }
  46286. else if (button == content->cancelButton)
  46287. closeButtonPressed();
  46288. }
  46289. void FileChooserDialogBox::closeButtonPressed()
  46290. {
  46291. setVisible (false);
  46292. }
  46293. void FileChooserDialogBox::selectionChanged()
  46294. {
  46295. content->okButton->setEnabled (content->chooserComponent->currentFileIsValid());
  46296. }
  46297. void FileChooserDialogBox::fileClicked (const File&, const MouseEvent&)
  46298. {
  46299. }
  46300. void FileChooserDialogBox::fileDoubleClicked (const File&)
  46301. {
  46302. selectionChanged();
  46303. content->okButton->triggerClick();
  46304. }
  46305. FileChooserDialogBox::ContentComponent::ContentComponent()
  46306. {
  46307. setInterceptsMouseClicks (false, true);
  46308. }
  46309. FileChooserDialogBox::ContentComponent::~ContentComponent()
  46310. {
  46311. delete okButton;
  46312. delete cancelButton;
  46313. }
  46314. void FileChooserDialogBox::ContentComponent::paint (Graphics& g)
  46315. {
  46316. g.setColour (getLookAndFeel().findColour (FileChooserDialogBox::titleTextColourId));
  46317. text.draw (g);
  46318. }
  46319. void FileChooserDialogBox::ContentComponent::resized()
  46320. {
  46321. getLookAndFeel().createFileChooserHeaderText (getName(), instructions, text, getWidth());
  46322. float left, top, right, bottom;
  46323. text.getBoundingBox (0, text.getNumGlyphs(), left, top, right, bottom, false);
  46324. const int y = roundToInt (bottom) + 10;
  46325. const int buttonHeight = 26;
  46326. const int buttonY = getHeight() - buttonHeight - 8;
  46327. chooserComponent->setBounds (0, y, getWidth(), buttonY - y - 20);
  46328. okButton->setBounds (proportionOfWidth (0.25f), buttonY,
  46329. proportionOfWidth (0.2f), buttonHeight);
  46330. cancelButton->setBounds (proportionOfWidth (0.55f), buttonY,
  46331. proportionOfWidth (0.2f), buttonHeight);
  46332. }
  46333. END_JUCE_NAMESPACE
  46334. /*** End of inlined file: juce_FileChooserDialogBox.cpp ***/
  46335. /*** Start of inlined file: juce_FileFilter.cpp ***/
  46336. BEGIN_JUCE_NAMESPACE
  46337. FileFilter::FileFilter (const String& filterDescription)
  46338. : description (filterDescription)
  46339. {
  46340. }
  46341. FileFilter::~FileFilter()
  46342. {
  46343. }
  46344. const String& FileFilter::getDescription() const throw()
  46345. {
  46346. return description;
  46347. }
  46348. END_JUCE_NAMESPACE
  46349. /*** End of inlined file: juce_FileFilter.cpp ***/
  46350. /*** Start of inlined file: juce_FileListComponent.cpp ***/
  46351. BEGIN_JUCE_NAMESPACE
  46352. Image* juce_createIconForFile (const File& file);
  46353. FileListComponent::FileListComponent (DirectoryContentsList& listToShow)
  46354. : ListBox (String::empty, 0),
  46355. DirectoryContentsDisplayComponent (listToShow)
  46356. {
  46357. setModel (this);
  46358. fileList.addChangeListener (this);
  46359. }
  46360. FileListComponent::~FileListComponent()
  46361. {
  46362. fileList.removeChangeListener (this);
  46363. deleteAllChildren();
  46364. }
  46365. int FileListComponent::getNumSelectedFiles() const
  46366. {
  46367. return getNumSelectedRows();
  46368. }
  46369. const File FileListComponent::getSelectedFile (int index) const
  46370. {
  46371. return fileList.getFile (getSelectedRow (index));
  46372. }
  46373. void FileListComponent::scrollToTop()
  46374. {
  46375. getVerticalScrollBar()->setCurrentRangeStart (0);
  46376. }
  46377. void FileListComponent::changeListenerCallback (void*)
  46378. {
  46379. updateContent();
  46380. if (lastDirectory != fileList.getDirectory())
  46381. {
  46382. lastDirectory = fileList.getDirectory();
  46383. deselectAllRows();
  46384. }
  46385. }
  46386. class FileListItemComponent : public Component,
  46387. public TimeSliceClient,
  46388. public AsyncUpdater
  46389. {
  46390. public:
  46391. FileListItemComponent (FileListComponent& owner_,
  46392. TimeSliceThread& thread_) throw()
  46393. : owner (owner_),
  46394. thread (thread_),
  46395. icon (0)
  46396. {
  46397. }
  46398. ~FileListItemComponent() throw()
  46399. {
  46400. thread.removeTimeSliceClient (this);
  46401. clearIcon();
  46402. }
  46403. void paint (Graphics& g)
  46404. {
  46405. getLookAndFeel().drawFileBrowserRow (g, getWidth(), getHeight(),
  46406. file.getFileName(),
  46407. icon,
  46408. fileSize, modTime,
  46409. isDirectory, highlighted,
  46410. index);
  46411. }
  46412. void mouseDown (const MouseEvent& e)
  46413. {
  46414. owner.selectRowsBasedOnModifierKeys (index, e.mods);
  46415. owner.sendMouseClickMessage (file, e);
  46416. }
  46417. void mouseDoubleClick (const MouseEvent&)
  46418. {
  46419. owner.sendDoubleClickMessage (file);
  46420. }
  46421. void update (const File& root,
  46422. const DirectoryContentsList::FileInfo* const fileInfo,
  46423. const int index_,
  46424. const bool highlighted_) throw()
  46425. {
  46426. thread.removeTimeSliceClient (this);
  46427. if (highlighted_ != highlighted
  46428. || index_ != index)
  46429. {
  46430. index = index_;
  46431. highlighted = highlighted_;
  46432. repaint();
  46433. }
  46434. File newFile;
  46435. String newFileSize;
  46436. String newModTime;
  46437. if (fileInfo != 0)
  46438. {
  46439. newFile = root.getChildFile (fileInfo->filename);
  46440. newFileSize = File::descriptionOfSizeInBytes (fileInfo->fileSize);
  46441. newModTime = fileInfo->modificationTime.formatted (T("%d %b '%y %H:%M"));
  46442. }
  46443. if (newFile != file
  46444. || fileSize != newFileSize
  46445. || modTime != newModTime)
  46446. {
  46447. file = newFile;
  46448. fileSize = newFileSize;
  46449. modTime = newModTime;
  46450. isDirectory = fileInfo != 0 && fileInfo->isDirectory;
  46451. repaint();
  46452. clearIcon();
  46453. }
  46454. if (file != File::nonexistent
  46455. && icon == 0 && ! isDirectory)
  46456. {
  46457. updateIcon (true);
  46458. if (icon == 0)
  46459. thread.addTimeSliceClient (this);
  46460. }
  46461. }
  46462. bool useTimeSlice()
  46463. {
  46464. updateIcon (false);
  46465. return false;
  46466. }
  46467. void handleAsyncUpdate()
  46468. {
  46469. repaint();
  46470. }
  46471. juce_UseDebuggingNewOperator
  46472. private:
  46473. FileListComponent& owner;
  46474. TimeSliceThread& thread;
  46475. bool highlighted;
  46476. int index;
  46477. File file;
  46478. String fileSize;
  46479. String modTime;
  46480. Image* icon;
  46481. bool isDirectory;
  46482. void clearIcon() throw()
  46483. {
  46484. ImageCache::release (icon);
  46485. icon = 0;
  46486. }
  46487. void updateIcon (const bool onlyUpdateIfCached) throw()
  46488. {
  46489. if (icon == 0)
  46490. {
  46491. const int hashCode = (file.getFullPathName() + T("_iconCacheSalt")).hashCode();
  46492. Image* im = ImageCache::getFromHashCode (hashCode);
  46493. if (im == 0 && ! onlyUpdateIfCached)
  46494. {
  46495. im = juce_createIconForFile (file);
  46496. if (im != 0)
  46497. ImageCache::addImageToCache (im, hashCode);
  46498. }
  46499. if (im != 0)
  46500. {
  46501. icon = im;
  46502. triggerAsyncUpdate();
  46503. }
  46504. }
  46505. }
  46506. };
  46507. int FileListComponent::getNumRows()
  46508. {
  46509. return fileList.getNumFiles();
  46510. }
  46511. void FileListComponent::paintListBoxItem (int, Graphics&, int, int, bool)
  46512. {
  46513. }
  46514. Component* FileListComponent::refreshComponentForRow (int row, bool isSelected, Component* existingComponentToUpdate)
  46515. {
  46516. FileListItemComponent* comp = dynamic_cast <FileListItemComponent*> (existingComponentToUpdate);
  46517. if (comp == 0)
  46518. {
  46519. delete existingComponentToUpdate;
  46520. comp = new FileListItemComponent (*this, fileList.getTimeSliceThread());
  46521. }
  46522. DirectoryContentsList::FileInfo fileInfo;
  46523. if (fileList.getFileInfo (row, fileInfo))
  46524. comp->update (fileList.getDirectory(), &fileInfo, row, isSelected);
  46525. else
  46526. comp->update (fileList.getDirectory(), 0, row, isSelected);
  46527. return comp;
  46528. }
  46529. void FileListComponent::selectedRowsChanged (int /*lastRowSelected*/)
  46530. {
  46531. sendSelectionChangeMessage();
  46532. }
  46533. void FileListComponent::deleteKeyPressed (int /*currentSelectedRow*/)
  46534. {
  46535. }
  46536. void FileListComponent::returnKeyPressed (int currentSelectedRow)
  46537. {
  46538. sendDoubleClickMessage (fileList.getFile (currentSelectedRow));
  46539. }
  46540. END_JUCE_NAMESPACE
  46541. /*** End of inlined file: juce_FileListComponent.cpp ***/
  46542. /*** Start of inlined file: juce_FilenameComponent.cpp ***/
  46543. BEGIN_JUCE_NAMESPACE
  46544. FilenameComponent::FilenameComponent (const String& name,
  46545. const File& currentFile,
  46546. const bool canEditFilename,
  46547. const bool isDirectory,
  46548. const bool isForSaving,
  46549. const String& fileBrowserWildcard,
  46550. const String& enforcedSuffix_,
  46551. const String& textWhenNothingSelected)
  46552. : Component (name),
  46553. maxRecentFiles (30),
  46554. isDir (isDirectory),
  46555. isSaving (isForSaving),
  46556. isFileDragOver (false),
  46557. wildcard (fileBrowserWildcard),
  46558. enforcedSuffix (enforcedSuffix_)
  46559. {
  46560. addAndMakeVisible (filenameBox = new ComboBox (T("fn")));
  46561. filenameBox->setEditableText (canEditFilename);
  46562. filenameBox->addListener (this);
  46563. filenameBox->setTextWhenNothingSelected (textWhenNothingSelected);
  46564. filenameBox->setTextWhenNoChoicesAvailable (TRANS("(no recently seleced files)"));
  46565. browseButton = 0;
  46566. setBrowseButtonText (T("..."));
  46567. setCurrentFile (currentFile, true);
  46568. }
  46569. FilenameComponent::~FilenameComponent()
  46570. {
  46571. deleteAllChildren();
  46572. }
  46573. void FilenameComponent::paintOverChildren (Graphics& g)
  46574. {
  46575. if (isFileDragOver)
  46576. {
  46577. g.setColour (Colours::red.withAlpha (0.2f));
  46578. g.drawRect (0, 0, getWidth(), getHeight(), 3);
  46579. }
  46580. }
  46581. void FilenameComponent::resized()
  46582. {
  46583. getLookAndFeel().layoutFilenameComponent (*this, filenameBox, browseButton);
  46584. }
  46585. void FilenameComponent::setBrowseButtonText (const String& newBrowseButtonText)
  46586. {
  46587. browseButtonText = newBrowseButtonText;
  46588. lookAndFeelChanged();
  46589. }
  46590. void FilenameComponent::lookAndFeelChanged()
  46591. {
  46592. deleteAndZero (browseButton);
  46593. addAndMakeVisible (browseButton = getLookAndFeel().createFilenameComponentBrowseButton (browseButtonText));
  46594. browseButton->setConnectedEdges (Button::ConnectedOnLeft);
  46595. resized();
  46596. browseButton->addButtonListener (this);
  46597. }
  46598. void FilenameComponent::setTooltip (const String& newTooltip)
  46599. {
  46600. SettableTooltipClient::setTooltip (newTooltip);
  46601. filenameBox->setTooltip (newTooltip);
  46602. }
  46603. void FilenameComponent::setDefaultBrowseTarget (const File& newDefaultDirectory) throw()
  46604. {
  46605. defaultBrowseFile = newDefaultDirectory;
  46606. }
  46607. void FilenameComponent::buttonClicked (Button*)
  46608. {
  46609. FileChooser fc (TRANS("Choose a new file"),
  46610. getCurrentFile() == File::nonexistent ? defaultBrowseFile
  46611. : getCurrentFile(),
  46612. wildcard);
  46613. if (isDir ? fc.browseForDirectory()
  46614. : (isSaving ? fc.browseForFileToSave (false)
  46615. : fc.browseForFileToOpen()))
  46616. {
  46617. setCurrentFile (fc.getResult(), true);
  46618. }
  46619. }
  46620. void FilenameComponent::comboBoxChanged (ComboBox*)
  46621. {
  46622. setCurrentFile (getCurrentFile(), true);
  46623. }
  46624. bool FilenameComponent::isInterestedInFileDrag (const StringArray&)
  46625. {
  46626. return true;
  46627. }
  46628. void FilenameComponent::filesDropped (const StringArray& filenames, int, int)
  46629. {
  46630. isFileDragOver = false;
  46631. repaint();
  46632. const File f (filenames[0]);
  46633. if (f.exists() && (f.isDirectory() == isDir))
  46634. setCurrentFile (f, true);
  46635. }
  46636. void FilenameComponent::fileDragEnter (const StringArray&, int, int)
  46637. {
  46638. isFileDragOver = true;
  46639. repaint();
  46640. }
  46641. void FilenameComponent::fileDragExit (const StringArray&)
  46642. {
  46643. isFileDragOver = false;
  46644. repaint();
  46645. }
  46646. const File FilenameComponent::getCurrentFile() const
  46647. {
  46648. File f (filenameBox->getText());
  46649. if (enforcedSuffix.isNotEmpty())
  46650. f = f.withFileExtension (enforcedSuffix);
  46651. return f;
  46652. }
  46653. void FilenameComponent::setCurrentFile (File newFile,
  46654. const bool addToRecentlyUsedList,
  46655. const bool sendChangeNotification)
  46656. {
  46657. if (enforcedSuffix.isNotEmpty())
  46658. newFile = newFile.withFileExtension (enforcedSuffix);
  46659. if (newFile.getFullPathName() != lastFilename)
  46660. {
  46661. lastFilename = newFile.getFullPathName();
  46662. if (addToRecentlyUsedList)
  46663. addRecentlyUsedFile (newFile);
  46664. filenameBox->setText (lastFilename, true);
  46665. if (sendChangeNotification)
  46666. triggerAsyncUpdate();
  46667. }
  46668. }
  46669. void FilenameComponent::setFilenameIsEditable (const bool shouldBeEditable)
  46670. {
  46671. filenameBox->setEditableText (shouldBeEditable);
  46672. }
  46673. const StringArray FilenameComponent::getRecentlyUsedFilenames() const
  46674. {
  46675. StringArray names;
  46676. for (int i = 0; i < filenameBox->getNumItems(); ++i)
  46677. names.add (filenameBox->getItemText (i));
  46678. return names;
  46679. }
  46680. void FilenameComponent::setRecentlyUsedFilenames (const StringArray& filenames)
  46681. {
  46682. if (filenames != getRecentlyUsedFilenames())
  46683. {
  46684. filenameBox->clear();
  46685. for (int i = 0; i < jmin (filenames.size(), maxRecentFiles); ++i)
  46686. filenameBox->addItem (filenames[i], i + 1);
  46687. }
  46688. }
  46689. void FilenameComponent::setMaxNumberOfRecentFiles (const int newMaximum)
  46690. {
  46691. maxRecentFiles = jmax (1, newMaximum);
  46692. setRecentlyUsedFilenames (getRecentlyUsedFilenames());
  46693. }
  46694. void FilenameComponent::addRecentlyUsedFile (const File& file)
  46695. {
  46696. StringArray files (getRecentlyUsedFilenames());
  46697. if (file.getFullPathName().isNotEmpty())
  46698. {
  46699. files.removeString (file.getFullPathName(), true);
  46700. files.insert (0, file.getFullPathName());
  46701. setRecentlyUsedFilenames (files);
  46702. }
  46703. }
  46704. void FilenameComponent::addListener (FilenameComponentListener* const listener) throw()
  46705. {
  46706. listeners.add (listener);
  46707. }
  46708. void FilenameComponent::removeListener (FilenameComponentListener* const listener) throw()
  46709. {
  46710. listeners.remove (listener);
  46711. }
  46712. void FilenameComponent::handleAsyncUpdate()
  46713. {
  46714. Component::BailOutChecker checker (this);
  46715. listeners.callChecked (checker, &FilenameComponentListener::filenameComponentChanged, this);
  46716. }
  46717. END_JUCE_NAMESPACE
  46718. /*** End of inlined file: juce_FilenameComponent.cpp ***/
  46719. /*** Start of inlined file: juce_FileSearchPathListComponent.cpp ***/
  46720. BEGIN_JUCE_NAMESPACE
  46721. FileSearchPathListComponent::FileSearchPathListComponent()
  46722. {
  46723. addAndMakeVisible (listBox = new ListBox (String::empty, this));
  46724. listBox->setColour (ListBox::backgroundColourId, Colours::black.withAlpha (0.02f));
  46725. listBox->setColour (ListBox::outlineColourId, Colours::black.withAlpha (0.1f));
  46726. listBox->setOutlineThickness (1);
  46727. addAndMakeVisible (addButton = new TextButton ("+"));
  46728. addButton->addButtonListener (this);
  46729. addButton->setConnectedEdges (Button::ConnectedOnLeft | Button::ConnectedOnRight | Button::ConnectedOnBottom | Button::ConnectedOnTop);
  46730. addAndMakeVisible (removeButton = new TextButton ("-"));
  46731. removeButton->addButtonListener (this);
  46732. removeButton->setConnectedEdges (Button::ConnectedOnLeft | Button::ConnectedOnRight | Button::ConnectedOnBottom | Button::ConnectedOnTop);
  46733. addAndMakeVisible (changeButton = new TextButton (TRANS("change...")));
  46734. changeButton->addButtonListener (this);
  46735. addAndMakeVisible (upButton = new DrawableButton (String::empty, DrawableButton::ImageOnButtonBackground));
  46736. upButton->addButtonListener (this);
  46737. {
  46738. Path arrowPath;
  46739. arrowPath.addArrow (50.0f, 100.0f, 50.0f, 0.0f, 40.0f, 100.0f, 50.0f);
  46740. DrawablePath arrowImage;
  46741. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  46742. arrowImage.setPath (arrowPath);
  46743. ((DrawableButton*) upButton)->setImages (&arrowImage);
  46744. }
  46745. addAndMakeVisible (downButton = new DrawableButton (String::empty, DrawableButton::ImageOnButtonBackground));
  46746. downButton->addButtonListener (this);
  46747. {
  46748. Path arrowPath;
  46749. arrowPath.addArrow (50.0f, 0.0f, 50.0f, 100.0f, 40.0f, 100.0f, 50.0f);
  46750. DrawablePath arrowImage;
  46751. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  46752. arrowImage.setPath (arrowPath);
  46753. ((DrawableButton*) downButton)->setImages (&arrowImage);
  46754. }
  46755. updateButtons();
  46756. }
  46757. FileSearchPathListComponent::~FileSearchPathListComponent()
  46758. {
  46759. deleteAllChildren();
  46760. }
  46761. void FileSearchPathListComponent::updateButtons() throw()
  46762. {
  46763. const bool anythingSelected = listBox->getNumSelectedRows() > 0;
  46764. removeButton->setEnabled (anythingSelected);
  46765. changeButton->setEnabled (anythingSelected);
  46766. upButton->setEnabled (anythingSelected);
  46767. downButton->setEnabled (anythingSelected);
  46768. }
  46769. void FileSearchPathListComponent::changed() throw()
  46770. {
  46771. listBox->updateContent();
  46772. listBox->repaint();
  46773. updateButtons();
  46774. }
  46775. void FileSearchPathListComponent::setPath (const FileSearchPath& newPath)
  46776. {
  46777. if (newPath.toString() != path.toString())
  46778. {
  46779. path = newPath;
  46780. changed();
  46781. }
  46782. }
  46783. void FileSearchPathListComponent::setDefaultBrowseTarget (const File& newDefaultDirectory) throw()
  46784. {
  46785. defaultBrowseTarget = newDefaultDirectory;
  46786. }
  46787. int FileSearchPathListComponent::getNumRows()
  46788. {
  46789. return path.getNumPaths();
  46790. }
  46791. void FileSearchPathListComponent::paintListBoxItem (int rowNumber, Graphics& g, int width, int height, bool rowIsSelected)
  46792. {
  46793. if (rowIsSelected)
  46794. g.fillAll (findColour (TextEditor::highlightColourId));
  46795. g.setColour (findColour (ListBox::textColourId));
  46796. Font f (height * 0.7f);
  46797. f.setHorizontalScale (0.9f);
  46798. g.setFont (f);
  46799. g.drawText (path [rowNumber].getFullPathName(),
  46800. 4, 0, width - 6, height,
  46801. Justification::centredLeft, true);
  46802. }
  46803. void FileSearchPathListComponent::deleteKeyPressed (int row)
  46804. {
  46805. if (((unsigned int) row) < (unsigned int) path.getNumPaths())
  46806. {
  46807. path.remove (row);
  46808. changed();
  46809. }
  46810. }
  46811. void FileSearchPathListComponent::returnKeyPressed (int row)
  46812. {
  46813. FileChooser chooser (TRANS("Change folder..."), path [row], T("*"));
  46814. if (chooser.browseForDirectory())
  46815. {
  46816. path.remove (row);
  46817. path.add (chooser.getResult(), row);
  46818. changed();
  46819. }
  46820. }
  46821. void FileSearchPathListComponent::listBoxItemDoubleClicked (int row, const MouseEvent&)
  46822. {
  46823. returnKeyPressed (row);
  46824. }
  46825. void FileSearchPathListComponent::selectedRowsChanged (int)
  46826. {
  46827. updateButtons();
  46828. }
  46829. void FileSearchPathListComponent::paint (Graphics& g)
  46830. {
  46831. g.fillAll (findColour (backgroundColourId));
  46832. }
  46833. void FileSearchPathListComponent::resized()
  46834. {
  46835. const int buttonH = 22;
  46836. const int buttonY = getHeight() - buttonH - 4;
  46837. listBox->setBounds (2, 2, getWidth() - 4, buttonY - 5);
  46838. addButton->setBounds (2, buttonY, buttonH, buttonH);
  46839. removeButton->setBounds (addButton->getRight(), buttonY, buttonH, buttonH);
  46840. ((TextButton*) changeButton)->changeWidthToFitText (buttonH);
  46841. downButton->setSize (buttonH * 2, buttonH);
  46842. upButton->setSize (buttonH * 2, buttonH);
  46843. downButton->setTopRightPosition (getWidth() - 2, buttonY);
  46844. upButton->setTopRightPosition (downButton->getX() - 4, buttonY);
  46845. changeButton->setTopRightPosition (upButton->getX() - 8, buttonY);
  46846. }
  46847. bool FileSearchPathListComponent::isInterestedInFileDrag (const StringArray&)
  46848. {
  46849. return true;
  46850. }
  46851. void FileSearchPathListComponent::filesDropped (const StringArray& filenames, int, int mouseY)
  46852. {
  46853. for (int i = filenames.size(); --i >= 0;)
  46854. {
  46855. const File f (filenames[i]);
  46856. if (f.isDirectory())
  46857. {
  46858. const int row = listBox->getRowContainingPosition (0, mouseY - listBox->getY());
  46859. path.add (f, row);
  46860. changed();
  46861. }
  46862. }
  46863. }
  46864. void FileSearchPathListComponent::buttonClicked (Button* button)
  46865. {
  46866. const int currentRow = listBox->getSelectedRow();
  46867. if (button == removeButton)
  46868. {
  46869. deleteKeyPressed (currentRow);
  46870. }
  46871. else if (button == addButton)
  46872. {
  46873. File start (defaultBrowseTarget);
  46874. if (start == File::nonexistent)
  46875. start = path [0];
  46876. if (start == File::nonexistent)
  46877. start = File::getCurrentWorkingDirectory();
  46878. FileChooser chooser (TRANS("Add a folder..."), start, T("*"));
  46879. if (chooser.browseForDirectory())
  46880. {
  46881. path.add (chooser.getResult(), currentRow);
  46882. }
  46883. }
  46884. else if (button == changeButton)
  46885. {
  46886. returnKeyPressed (currentRow);
  46887. }
  46888. else if (button == upButton)
  46889. {
  46890. if (currentRow > 0 && currentRow < path.getNumPaths())
  46891. {
  46892. const File f (path[currentRow]);
  46893. path.remove (currentRow);
  46894. path.add (f, currentRow - 1);
  46895. listBox->selectRow (currentRow - 1);
  46896. }
  46897. }
  46898. else if (button == downButton)
  46899. {
  46900. if (currentRow >= 0 && currentRow < path.getNumPaths() - 1)
  46901. {
  46902. const File f (path[currentRow]);
  46903. path.remove (currentRow);
  46904. path.add (f, currentRow + 1);
  46905. listBox->selectRow (currentRow + 1);
  46906. }
  46907. }
  46908. changed();
  46909. }
  46910. END_JUCE_NAMESPACE
  46911. /*** End of inlined file: juce_FileSearchPathListComponent.cpp ***/
  46912. /*** Start of inlined file: juce_FileTreeComponent.cpp ***/
  46913. BEGIN_JUCE_NAMESPACE
  46914. Image* juce_createIconForFile (const File& file);
  46915. class FileListTreeItem : public TreeViewItem,
  46916. public TimeSliceClient,
  46917. public AsyncUpdater,
  46918. public ChangeListener
  46919. {
  46920. public:
  46921. FileListTreeItem (FileTreeComponent& owner_,
  46922. DirectoryContentsList* const parentContentsList_,
  46923. const int indexInContentsList_,
  46924. const File& file_,
  46925. TimeSliceThread& thread_) throw()
  46926. : file (file_),
  46927. owner (owner_),
  46928. parentContentsList (parentContentsList_),
  46929. indexInContentsList (indexInContentsList_),
  46930. subContentsList (0),
  46931. canDeleteSubContentsList (false),
  46932. thread (thread_),
  46933. icon (0)
  46934. {
  46935. DirectoryContentsList::FileInfo fileInfo;
  46936. if (parentContentsList_ != 0
  46937. && parentContentsList_->getFileInfo (indexInContentsList_, fileInfo))
  46938. {
  46939. fileSize = File::descriptionOfSizeInBytes (fileInfo.fileSize);
  46940. modTime = fileInfo.modificationTime.formatted (T("%d %b '%y %H:%M"));
  46941. isDirectory = fileInfo.isDirectory;
  46942. }
  46943. else
  46944. {
  46945. isDirectory = true;
  46946. }
  46947. }
  46948. ~FileListTreeItem() throw()
  46949. {
  46950. thread.removeTimeSliceClient (this);
  46951. clearSubItems();
  46952. ImageCache::release (icon);
  46953. if (canDeleteSubContentsList)
  46954. delete subContentsList;
  46955. }
  46956. bool mightContainSubItems() { return isDirectory; }
  46957. const String getUniqueName() const { return file.getFullPathName(); }
  46958. int getItemHeight() const { return 22; }
  46959. const String getDragSourceDescription() { return owner.getDragAndDropDescription(); }
  46960. void itemOpennessChanged (bool isNowOpen)
  46961. {
  46962. if (isNowOpen)
  46963. {
  46964. clearSubItems();
  46965. isDirectory = file.isDirectory();
  46966. if (isDirectory)
  46967. {
  46968. if (subContentsList == 0)
  46969. {
  46970. jassert (parentContentsList != 0);
  46971. DirectoryContentsList* const l = new DirectoryContentsList (parentContentsList->getFilter(), thread);
  46972. l->setDirectory (file, true, true);
  46973. setSubContentsList (l);
  46974. canDeleteSubContentsList = true;
  46975. }
  46976. changeListenerCallback (0);
  46977. }
  46978. }
  46979. }
  46980. void setSubContentsList (DirectoryContentsList* newList) throw()
  46981. {
  46982. jassert (subContentsList == 0);
  46983. subContentsList = newList;
  46984. newList->addChangeListener (this);
  46985. }
  46986. void changeListenerCallback (void*)
  46987. {
  46988. clearSubItems();
  46989. if (isOpen() && subContentsList != 0)
  46990. {
  46991. for (int i = 0; i < subContentsList->getNumFiles(); ++i)
  46992. {
  46993. FileListTreeItem* const item
  46994. = new FileListTreeItem (owner, subContentsList, i, subContentsList->getFile(i), thread);
  46995. addSubItem (item);
  46996. }
  46997. }
  46998. }
  46999. void paintItem (Graphics& g, int width, int height)
  47000. {
  47001. if (file != File::nonexistent)
  47002. {
  47003. updateIcon (true);
  47004. if (icon == 0)
  47005. thread.addTimeSliceClient (this);
  47006. }
  47007. owner.getLookAndFeel()
  47008. .drawFileBrowserRow (g, width, height,
  47009. file.getFileName(),
  47010. icon,
  47011. fileSize, modTime,
  47012. isDirectory, isSelected(),
  47013. indexInContentsList);
  47014. }
  47015. void itemClicked (const MouseEvent& e)
  47016. {
  47017. owner.sendMouseClickMessage (file, e);
  47018. }
  47019. void itemDoubleClicked (const MouseEvent& e)
  47020. {
  47021. TreeViewItem::itemDoubleClicked (e);
  47022. owner.sendDoubleClickMessage (file);
  47023. }
  47024. void itemSelectionChanged (bool)
  47025. {
  47026. owner.sendSelectionChangeMessage();
  47027. }
  47028. bool useTimeSlice()
  47029. {
  47030. updateIcon (false);
  47031. thread.removeTimeSliceClient (this);
  47032. return false;
  47033. }
  47034. void handleAsyncUpdate()
  47035. {
  47036. owner.repaint();
  47037. }
  47038. const File file;
  47039. juce_UseDebuggingNewOperator
  47040. private:
  47041. FileTreeComponent& owner;
  47042. DirectoryContentsList* parentContentsList;
  47043. int indexInContentsList;
  47044. DirectoryContentsList* subContentsList;
  47045. bool isDirectory, canDeleteSubContentsList;
  47046. TimeSliceThread& thread;
  47047. Image* icon;
  47048. String fileSize;
  47049. String modTime;
  47050. void updateIcon (const bool onlyUpdateIfCached) throw()
  47051. {
  47052. if (icon == 0)
  47053. {
  47054. const int hashCode = (file.getFullPathName() + T("_iconCacheSalt")).hashCode();
  47055. Image* im = ImageCache::getFromHashCode (hashCode);
  47056. if (im == 0 && ! onlyUpdateIfCached)
  47057. {
  47058. im = juce_createIconForFile (file);
  47059. if (im != 0)
  47060. ImageCache::addImageToCache (im, hashCode);
  47061. }
  47062. if (im != 0)
  47063. {
  47064. icon = im;
  47065. triggerAsyncUpdate();
  47066. }
  47067. }
  47068. }
  47069. };
  47070. FileTreeComponent::FileTreeComponent (DirectoryContentsList& listToShow)
  47071. : DirectoryContentsDisplayComponent (listToShow)
  47072. {
  47073. FileListTreeItem* const root
  47074. = new FileListTreeItem (*this, 0, 0, listToShow.getDirectory(),
  47075. listToShow.getTimeSliceThread());
  47076. root->setSubContentsList (&listToShow);
  47077. setRootItemVisible (false);
  47078. setRootItem (root);
  47079. }
  47080. FileTreeComponent::~FileTreeComponent()
  47081. {
  47082. deleteRootItem();
  47083. }
  47084. const File FileTreeComponent::getSelectedFile (const int index) const
  47085. {
  47086. const FileListTreeItem* const item = dynamic_cast <const FileListTreeItem*> (getSelectedItem (index));
  47087. if (item != 0)
  47088. return item->file;
  47089. return File::nonexistent;
  47090. }
  47091. void FileTreeComponent::scrollToTop()
  47092. {
  47093. getViewport()->getVerticalScrollBar()->setCurrentRangeStart (0);
  47094. }
  47095. void FileTreeComponent::setDragAndDropDescription (const String& description) throw()
  47096. {
  47097. dragAndDropDescription = description;
  47098. }
  47099. END_JUCE_NAMESPACE
  47100. /*** End of inlined file: juce_FileTreeComponent.cpp ***/
  47101. /*** Start of inlined file: juce_ImagePreviewComponent.cpp ***/
  47102. BEGIN_JUCE_NAMESPACE
  47103. ImagePreviewComponent::ImagePreviewComponent()
  47104. {
  47105. }
  47106. ImagePreviewComponent::~ImagePreviewComponent()
  47107. {
  47108. }
  47109. void ImagePreviewComponent::getThumbSize (int& w, int& h) const
  47110. {
  47111. const int availableW = proportionOfWidth (0.97f);
  47112. const int availableH = getHeight() - 13 * 4;
  47113. const double scale = jmin (1.0,
  47114. availableW / (double) w,
  47115. availableH / (double) h);
  47116. w = roundToInt (scale * w);
  47117. h = roundToInt (scale * h);
  47118. }
  47119. void ImagePreviewComponent::selectedFileChanged (const File& file)
  47120. {
  47121. if (fileToLoad != file)
  47122. {
  47123. fileToLoad = file;
  47124. startTimer (100);
  47125. }
  47126. }
  47127. void ImagePreviewComponent::timerCallback()
  47128. {
  47129. stopTimer();
  47130. currentThumbnail = 0;
  47131. currentDetails = String::empty;
  47132. repaint();
  47133. ScopedPointer <FileInputStream> in (fileToLoad.createInputStream());
  47134. if (in != 0)
  47135. {
  47136. ImageFileFormat* const format = ImageFileFormat::findImageFormatForStream (*in);
  47137. if (format != 0)
  47138. {
  47139. currentThumbnail = format->decodeImage (*in);
  47140. if (currentThumbnail != 0)
  47141. {
  47142. int w = currentThumbnail->getWidth();
  47143. int h = currentThumbnail->getHeight();
  47144. currentDetails
  47145. << fileToLoad.getFileName() << "\n"
  47146. << format->getFormatName() << "\n"
  47147. << w << " x " << h << " pixels\n"
  47148. << File::descriptionOfSizeInBytes (fileToLoad.getSize());
  47149. getThumbSize (w, h);
  47150. currentThumbnail = currentThumbnail->createCopy (w, h);
  47151. }
  47152. }
  47153. }
  47154. }
  47155. void ImagePreviewComponent::paint (Graphics& g)
  47156. {
  47157. if (currentThumbnail != 0)
  47158. {
  47159. g.setFont (13.0f);
  47160. int w = currentThumbnail->getWidth();
  47161. int h = currentThumbnail->getHeight();
  47162. getThumbSize (w, h);
  47163. const int numLines = 4;
  47164. const int totalH = 13 * numLines + h + 4;
  47165. const int y = (getHeight() - totalH) / 2;
  47166. g.drawImageWithin (currentThumbnail,
  47167. (getWidth() - w) / 2, y, w, h,
  47168. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize,
  47169. false);
  47170. g.drawFittedText (currentDetails,
  47171. 0, y + h + 4, getWidth(), 100,
  47172. Justification::centredTop, numLines);
  47173. }
  47174. }
  47175. END_JUCE_NAMESPACE
  47176. /*** End of inlined file: juce_ImagePreviewComponent.cpp ***/
  47177. /*** Start of inlined file: juce_WildcardFileFilter.cpp ***/
  47178. BEGIN_JUCE_NAMESPACE
  47179. WildcardFileFilter::WildcardFileFilter (const String& fileWildcardPatterns,
  47180. const String& directoryWildcardPatterns,
  47181. const String& description_)
  47182. : FileFilter (description_.isEmpty() ? fileWildcardPatterns
  47183. : (description_ + T(" (") + fileWildcardPatterns + T(")")))
  47184. {
  47185. parse (fileWildcardPatterns, fileWildcards);
  47186. parse (directoryWildcardPatterns, directoryWildcards);
  47187. }
  47188. WildcardFileFilter::~WildcardFileFilter()
  47189. {
  47190. }
  47191. bool WildcardFileFilter::isFileSuitable (const File& file) const
  47192. {
  47193. return match (file, fileWildcards);
  47194. }
  47195. bool WildcardFileFilter::isDirectorySuitable (const File& file) const
  47196. {
  47197. return match (file, directoryWildcards);
  47198. }
  47199. void WildcardFileFilter::parse (const String& pattern, StringArray& result) throw()
  47200. {
  47201. result.addTokens (pattern.toLowerCase(), T(";,"), T("\"'"));
  47202. result.trim();
  47203. result.removeEmptyStrings();
  47204. // special case for *.*, because people use it to mean "any file", but it
  47205. // would actually ignore files with no extension.
  47206. for (int i = result.size(); --i >= 0;)
  47207. if (result[i] == T("*.*"))
  47208. result.set (i, T("*"));
  47209. }
  47210. bool WildcardFileFilter::match (const File& file, const StringArray& wildcards) throw()
  47211. {
  47212. const String filename (file.getFileName());
  47213. for (int i = wildcards.size(); --i >= 0;)
  47214. if (filename.matchesWildcard (wildcards[i], true))
  47215. return true;
  47216. return false;
  47217. }
  47218. END_JUCE_NAMESPACE
  47219. /*** End of inlined file: juce_WildcardFileFilter.cpp ***/
  47220. /*** Start of inlined file: juce_KeyboardFocusTraverser.cpp ***/
  47221. BEGIN_JUCE_NAMESPACE
  47222. KeyboardFocusTraverser::KeyboardFocusTraverser()
  47223. {
  47224. }
  47225. KeyboardFocusTraverser::~KeyboardFocusTraverser()
  47226. {
  47227. }
  47228. namespace KeyboardFocusHelpers
  47229. {
  47230. // This will sort a set of components, so that they are ordered in terms of
  47231. // left-to-right and then top-to-bottom.
  47232. class ScreenPositionComparator
  47233. {
  47234. public:
  47235. ScreenPositionComparator() {}
  47236. static int compareElements (const Component* const first, const Component* const second) throw()
  47237. {
  47238. int explicitOrder1 = first->getExplicitFocusOrder();
  47239. if (explicitOrder1 <= 0)
  47240. explicitOrder1 = std::numeric_limits<int>::max() / 2;
  47241. int explicitOrder2 = second->getExplicitFocusOrder();
  47242. if (explicitOrder2 <= 0)
  47243. explicitOrder2 = std::numeric_limits<int>::max() / 2;
  47244. if (explicitOrder1 != explicitOrder2)
  47245. return explicitOrder1 - explicitOrder2;
  47246. const int diff = first->getY() - second->getY();
  47247. return (diff == 0) ? first->getX() - second->getX()
  47248. : diff;
  47249. }
  47250. };
  47251. static void findAllFocusableComponents (Component* const parent, Array <Component*>& comps)
  47252. {
  47253. if (parent->getNumChildComponents() > 0)
  47254. {
  47255. Array <Component*> localComps;
  47256. ScreenPositionComparator comparator;
  47257. int i;
  47258. for (i = parent->getNumChildComponents(); --i >= 0;)
  47259. {
  47260. Component* const c = parent->getChildComponent (i);
  47261. if (c->isVisible() && c->isEnabled())
  47262. localComps.addSorted (comparator, c);
  47263. }
  47264. for (i = 0; i < localComps.size(); ++i)
  47265. {
  47266. Component* const c = localComps.getUnchecked (i);
  47267. if (c->getWantsKeyboardFocus())
  47268. comps.add (c);
  47269. if (! c->isFocusContainer())
  47270. findAllFocusableComponents (c, comps);
  47271. }
  47272. }
  47273. }
  47274. }
  47275. static Component* getIncrementedComponent (Component* const current, const int delta) throw()
  47276. {
  47277. Component* focusContainer = current->getParentComponent();
  47278. if (focusContainer != 0)
  47279. {
  47280. while (focusContainer->getParentComponent() != 0 && ! focusContainer->isFocusContainer())
  47281. focusContainer = focusContainer->getParentComponent();
  47282. if (focusContainer != 0)
  47283. {
  47284. Array <Component*> comps;
  47285. KeyboardFocusHelpers::findAllFocusableComponents (focusContainer, comps);
  47286. if (comps.size() > 0)
  47287. {
  47288. const int index = comps.indexOf (current);
  47289. return comps [(index + comps.size() + delta) % comps.size()];
  47290. }
  47291. }
  47292. }
  47293. return 0;
  47294. }
  47295. Component* KeyboardFocusTraverser::getNextComponent (Component* current)
  47296. {
  47297. return getIncrementedComponent (current, 1);
  47298. }
  47299. Component* KeyboardFocusTraverser::getPreviousComponent (Component* current)
  47300. {
  47301. return getIncrementedComponent (current, -1);
  47302. }
  47303. Component* KeyboardFocusTraverser::getDefaultComponent (Component* parentComponent)
  47304. {
  47305. Array <Component*> comps;
  47306. if (parentComponent != 0)
  47307. KeyboardFocusHelpers::findAllFocusableComponents (parentComponent, comps);
  47308. return comps.getFirst();
  47309. }
  47310. END_JUCE_NAMESPACE
  47311. /*** End of inlined file: juce_KeyboardFocusTraverser.cpp ***/
  47312. /*** Start of inlined file: juce_KeyListener.cpp ***/
  47313. BEGIN_JUCE_NAMESPACE
  47314. bool KeyListener::keyStateChanged (const bool, Component*)
  47315. {
  47316. return false;
  47317. }
  47318. END_JUCE_NAMESPACE
  47319. /*** End of inlined file: juce_KeyListener.cpp ***/
  47320. /*** Start of inlined file: juce_KeyMappingEditorComponent.cpp ***/
  47321. BEGIN_JUCE_NAMESPACE
  47322. // N.B. these two includes are put here deliberately to avoid problems with
  47323. // old GCCs failing on long include paths
  47324. const int maxKeys = 3;
  47325. class KeyMappingChangeButton : public Button
  47326. {
  47327. public:
  47328. KeyMappingChangeButton (KeyMappingEditorComponent* const owner_,
  47329. const CommandID commandID_,
  47330. const String& keyName,
  47331. const int keyNum_)
  47332. : Button (keyName),
  47333. owner (owner_),
  47334. commandID (commandID_),
  47335. keyNum (keyNum_)
  47336. {
  47337. setWantsKeyboardFocus (false);
  47338. setTriggeredOnMouseDown (keyNum >= 0);
  47339. if (keyNum_ < 0)
  47340. setTooltip (TRANS("adds a new key-mapping"));
  47341. else
  47342. setTooltip (TRANS("click to change this key-mapping"));
  47343. }
  47344. ~KeyMappingChangeButton()
  47345. {
  47346. }
  47347. void paintButton (Graphics& g, bool /*isOver*/, bool /*isDown*/)
  47348. {
  47349. getLookAndFeel().drawKeymapChangeButton (g, getWidth(), getHeight(), *this,
  47350. keyNum >= 0 ? getName() : String::empty);
  47351. }
  47352. void clicked()
  47353. {
  47354. if (keyNum >= 0)
  47355. {
  47356. // existing key clicked..
  47357. PopupMenu m;
  47358. m.addItem (1, TRANS("change this key-mapping"));
  47359. m.addSeparator();
  47360. m.addItem (2, TRANS("remove this key-mapping"));
  47361. const int res = m.show();
  47362. if (res == 1)
  47363. {
  47364. owner->assignNewKey (commandID, keyNum);
  47365. }
  47366. else if (res == 2)
  47367. {
  47368. owner->getMappings()->removeKeyPress (commandID, keyNum);
  47369. }
  47370. }
  47371. else
  47372. {
  47373. // + button pressed..
  47374. owner->assignNewKey (commandID, -1);
  47375. }
  47376. }
  47377. void fitToContent (const int h) throw()
  47378. {
  47379. if (keyNum < 0)
  47380. {
  47381. setSize (h, h);
  47382. }
  47383. else
  47384. {
  47385. Font f (h * 0.6f);
  47386. setSize (jlimit (h * 4, h * 8, 6 + f.getStringWidth (getName())), h);
  47387. }
  47388. }
  47389. juce_UseDebuggingNewOperator
  47390. private:
  47391. KeyMappingEditorComponent* const owner;
  47392. const CommandID commandID;
  47393. const int keyNum;
  47394. KeyMappingChangeButton (const KeyMappingChangeButton&);
  47395. KeyMappingChangeButton& operator= (const KeyMappingChangeButton&);
  47396. };
  47397. class KeyMappingItemComponent : public Component
  47398. {
  47399. public:
  47400. KeyMappingItemComponent (KeyMappingEditorComponent* const owner_,
  47401. const CommandID commandID_)
  47402. : owner (owner_),
  47403. commandID (commandID_)
  47404. {
  47405. setInterceptsMouseClicks (false, true);
  47406. const bool isReadOnly = owner_->isCommandReadOnly (commandID);
  47407. const Array <KeyPress> keyPresses (owner_->getMappings()->getKeyPressesAssignedToCommand (commandID));
  47408. for (int i = 0; i < jmin (maxKeys, keyPresses.size()); ++i)
  47409. {
  47410. KeyMappingChangeButton* const kb
  47411. = new KeyMappingChangeButton (owner_, commandID,
  47412. owner_->getDescriptionForKeyPress (keyPresses.getReference (i)), i);
  47413. kb->setEnabled (! isReadOnly);
  47414. addAndMakeVisible (kb);
  47415. }
  47416. KeyMappingChangeButton* const kb
  47417. = new KeyMappingChangeButton (owner_, commandID, String::empty, -1);
  47418. addChildComponent (kb);
  47419. kb->setVisible (keyPresses.size() < maxKeys && ! isReadOnly);
  47420. }
  47421. ~KeyMappingItemComponent()
  47422. {
  47423. deleteAllChildren();
  47424. }
  47425. void paint (Graphics& g)
  47426. {
  47427. g.setFont (getHeight() * 0.7f);
  47428. g.setColour (findColour (KeyMappingEditorComponent::textColourId));
  47429. g.drawFittedText (owner->getMappings()->getCommandManager()->getNameOfCommand (commandID),
  47430. 4, 0, jmax (40, getChildComponent (0)->getX() - 5), getHeight(),
  47431. Justification::centredLeft, true);
  47432. }
  47433. void resized()
  47434. {
  47435. int x = getWidth() - 4;
  47436. for (int i = getNumChildComponents(); --i >= 0;)
  47437. {
  47438. KeyMappingChangeButton* const kb = dynamic_cast <KeyMappingChangeButton*> (getChildComponent (i));
  47439. kb->fitToContent (getHeight() - 2);
  47440. kb->setTopRightPosition (x, 1);
  47441. x -= kb->getWidth() + 5;
  47442. }
  47443. }
  47444. juce_UseDebuggingNewOperator
  47445. private:
  47446. KeyMappingEditorComponent* const owner;
  47447. const CommandID commandID;
  47448. KeyMappingItemComponent (const KeyMappingItemComponent&);
  47449. KeyMappingItemComponent& operator= (const KeyMappingItemComponent&);
  47450. };
  47451. class KeyMappingTreeViewItem : public TreeViewItem
  47452. {
  47453. public:
  47454. KeyMappingTreeViewItem (KeyMappingEditorComponent* const owner_,
  47455. const CommandID commandID_)
  47456. : owner (owner_),
  47457. commandID (commandID_)
  47458. {
  47459. }
  47460. ~KeyMappingTreeViewItem()
  47461. {
  47462. }
  47463. const String getUniqueName() const { return String ((int) commandID) + "_id"; }
  47464. bool mightContainSubItems() { return false; }
  47465. int getItemHeight() const { return 20; }
  47466. Component* createItemComponent()
  47467. {
  47468. return new KeyMappingItemComponent (owner, commandID);
  47469. }
  47470. juce_UseDebuggingNewOperator
  47471. private:
  47472. KeyMappingEditorComponent* const owner;
  47473. const CommandID commandID;
  47474. KeyMappingTreeViewItem (const KeyMappingTreeViewItem&);
  47475. KeyMappingTreeViewItem& operator= (const KeyMappingTreeViewItem&);
  47476. };
  47477. class KeyCategoryTreeViewItem : public TreeViewItem
  47478. {
  47479. public:
  47480. KeyCategoryTreeViewItem (KeyMappingEditorComponent* const owner_,
  47481. const String& name)
  47482. : owner (owner_),
  47483. categoryName (name)
  47484. {
  47485. }
  47486. ~KeyCategoryTreeViewItem()
  47487. {
  47488. }
  47489. const String getUniqueName() const { return categoryName + "_cat"; }
  47490. bool mightContainSubItems() { return true; }
  47491. int getItemHeight() const { return 28; }
  47492. void paintItem (Graphics& g, int width, int height)
  47493. {
  47494. g.setFont (height * 0.6f, Font::bold);
  47495. g.setColour (owner->findColour (KeyMappingEditorComponent::textColourId));
  47496. g.drawText (categoryName,
  47497. 2, 0, width - 2, height,
  47498. Justification::centredLeft, true);
  47499. }
  47500. void itemOpennessChanged (bool isNowOpen)
  47501. {
  47502. if (isNowOpen)
  47503. {
  47504. if (getNumSubItems() == 0)
  47505. {
  47506. Array <CommandID> commands (owner->getMappings()->getCommandManager()->getCommandsInCategory (categoryName));
  47507. for (int i = 0; i < commands.size(); ++i)
  47508. {
  47509. if (owner->shouldCommandBeIncluded (commands[i]))
  47510. addSubItem (new KeyMappingTreeViewItem (owner, commands[i]));
  47511. }
  47512. }
  47513. }
  47514. else
  47515. {
  47516. clearSubItems();
  47517. }
  47518. }
  47519. juce_UseDebuggingNewOperator
  47520. private:
  47521. KeyMappingEditorComponent* owner;
  47522. String categoryName;
  47523. KeyCategoryTreeViewItem (const KeyCategoryTreeViewItem&);
  47524. KeyCategoryTreeViewItem& operator= (const KeyCategoryTreeViewItem&);
  47525. };
  47526. KeyMappingEditorComponent::KeyMappingEditorComponent (KeyPressMappingSet* const mappingManager,
  47527. const bool showResetToDefaultButton)
  47528. : mappings (mappingManager)
  47529. {
  47530. jassert (mappingManager != 0); // can't be null!
  47531. mappingManager->addChangeListener (this);
  47532. setLinesDrawnForSubItems (false);
  47533. resetButton = 0;
  47534. if (showResetToDefaultButton)
  47535. {
  47536. addAndMakeVisible (resetButton = new TextButton (TRANS("reset to defaults")));
  47537. resetButton->addButtonListener (this);
  47538. }
  47539. addAndMakeVisible (tree = new TreeView());
  47540. tree->setColour (TreeView::backgroundColourId, findColour (backgroundColourId));
  47541. tree->setRootItemVisible (false);
  47542. tree->setDefaultOpenness (true);
  47543. tree->setRootItem (this);
  47544. }
  47545. KeyMappingEditorComponent::~KeyMappingEditorComponent()
  47546. {
  47547. mappings->removeChangeListener (this);
  47548. deleteAllChildren();
  47549. }
  47550. bool KeyMappingEditorComponent::mightContainSubItems()
  47551. {
  47552. return true;
  47553. }
  47554. const String KeyMappingEditorComponent::getUniqueName() const
  47555. {
  47556. return T("keys");
  47557. }
  47558. void KeyMappingEditorComponent::setColours (const Colour& mainBackground,
  47559. const Colour& textColour)
  47560. {
  47561. setColour (backgroundColourId, mainBackground);
  47562. setColour (textColourId, textColour);
  47563. tree->setColour (TreeView::backgroundColourId, mainBackground);
  47564. }
  47565. void KeyMappingEditorComponent::parentHierarchyChanged()
  47566. {
  47567. changeListenerCallback (0);
  47568. }
  47569. void KeyMappingEditorComponent::resized()
  47570. {
  47571. int h = getHeight();
  47572. if (resetButton != 0)
  47573. {
  47574. const int buttonHeight = 20;
  47575. h -= buttonHeight + 8;
  47576. int x = getWidth() - 8;
  47577. const int y = h + 6;
  47578. resetButton->changeWidthToFitText (buttonHeight);
  47579. resetButton->setTopRightPosition (x, y);
  47580. }
  47581. tree->setBounds (0, 0, getWidth(), h);
  47582. }
  47583. void KeyMappingEditorComponent::buttonClicked (Button* button)
  47584. {
  47585. if (button == resetButton)
  47586. {
  47587. if (AlertWindow::showOkCancelBox (AlertWindow::QuestionIcon,
  47588. TRANS("Reset to defaults"),
  47589. TRANS("Are you sure you want to reset all the key-mappings to their default state?"),
  47590. TRANS("Reset")))
  47591. {
  47592. mappings->resetToDefaultMappings();
  47593. }
  47594. }
  47595. }
  47596. void KeyMappingEditorComponent::changeListenerCallback (void*)
  47597. {
  47598. ScopedPointer <XmlElement> openness (tree->getOpennessState (true));
  47599. clearSubItems();
  47600. const StringArray categories (mappings->getCommandManager()->getCommandCategories());
  47601. for (int i = 0; i < categories.size(); ++i)
  47602. {
  47603. const Array <CommandID> commands (mappings->getCommandManager()->getCommandsInCategory (categories[i]));
  47604. int count = 0;
  47605. for (int j = 0; j < commands.size(); ++j)
  47606. if (shouldCommandBeIncluded (commands[j]))
  47607. ++count;
  47608. if (count > 0)
  47609. addSubItem (new KeyCategoryTreeViewItem (this, categories[i]));
  47610. }
  47611. if (openness != 0)
  47612. tree->restoreOpennessState (*openness);
  47613. }
  47614. class KeyEntryWindow : public AlertWindow
  47615. {
  47616. public:
  47617. KeyEntryWindow (KeyMappingEditorComponent* const owner_)
  47618. : AlertWindow (TRANS("New key-mapping"),
  47619. TRANS("Please press a key combination now..."),
  47620. AlertWindow::NoIcon),
  47621. owner (owner_)
  47622. {
  47623. addButton (TRANS("ok"), 1);
  47624. addButton (TRANS("cancel"), 0);
  47625. // (avoid return + escape keys getting processed by the buttons..)
  47626. for (int i = getNumChildComponents(); --i >= 0;)
  47627. getChildComponent (i)->setWantsKeyboardFocus (false);
  47628. setWantsKeyboardFocus (true);
  47629. grabKeyboardFocus();
  47630. }
  47631. ~KeyEntryWindow()
  47632. {
  47633. }
  47634. bool keyPressed (const KeyPress& key)
  47635. {
  47636. lastPress = key;
  47637. String message (TRANS("Key: ") + owner->getDescriptionForKeyPress (key));
  47638. const CommandID previousCommand = owner->getMappings()->findCommandForKeyPress (key);
  47639. if (previousCommand != 0)
  47640. {
  47641. message << "\n\n"
  47642. << TRANS("(Currently assigned to \"")
  47643. << owner->getMappings()->getCommandManager()->getNameOfCommand (previousCommand)
  47644. << "\")";
  47645. }
  47646. setMessage (message);
  47647. return true;
  47648. }
  47649. bool keyStateChanged (const bool)
  47650. {
  47651. return true;
  47652. }
  47653. KeyPress lastPress;
  47654. juce_UseDebuggingNewOperator
  47655. private:
  47656. KeyMappingEditorComponent* owner;
  47657. KeyEntryWindow (const KeyEntryWindow&);
  47658. KeyEntryWindow& operator= (const KeyEntryWindow&);
  47659. };
  47660. void KeyMappingEditorComponent::assignNewKey (const CommandID commandID, const int index)
  47661. {
  47662. KeyEntryWindow entryWindow (this);
  47663. if (entryWindow.runModalLoop() != 0)
  47664. {
  47665. entryWindow.setVisible (false);
  47666. if (entryWindow.lastPress.isValid())
  47667. {
  47668. const CommandID previousCommand = mappings->findCommandForKeyPress (entryWindow.lastPress);
  47669. if (previousCommand != 0)
  47670. {
  47671. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  47672. TRANS("Change key-mapping"),
  47673. TRANS("This key is already assigned to the command \"")
  47674. + mappings->getCommandManager()->getNameOfCommand (previousCommand)
  47675. + TRANS("\"\n\nDo you want to re-assign it to this new command instead?"),
  47676. TRANS("re-assign"),
  47677. TRANS("cancel")))
  47678. {
  47679. return;
  47680. }
  47681. }
  47682. mappings->removeKeyPress (entryWindow.lastPress);
  47683. if (index >= 0)
  47684. mappings->removeKeyPress (commandID, index);
  47685. mappings->addKeyPress (commandID, entryWindow.lastPress, index);
  47686. }
  47687. }
  47688. }
  47689. bool KeyMappingEditorComponent::shouldCommandBeIncluded (const CommandID commandID)
  47690. {
  47691. const ApplicationCommandInfo* const ci = mappings->getCommandManager()->getCommandForID (commandID);
  47692. return (ci != 0) && ((ci->flags & ApplicationCommandInfo::hiddenFromKeyEditor) == 0);
  47693. }
  47694. bool KeyMappingEditorComponent::isCommandReadOnly (const CommandID commandID)
  47695. {
  47696. const ApplicationCommandInfo* const ci = mappings->getCommandManager()->getCommandForID (commandID);
  47697. return (ci != 0) && ((ci->flags & ApplicationCommandInfo::readOnlyInKeyEditor) != 0);
  47698. }
  47699. const String KeyMappingEditorComponent::getDescriptionForKeyPress (const KeyPress& key)
  47700. {
  47701. return key.getTextDescription();
  47702. }
  47703. END_JUCE_NAMESPACE
  47704. /*** End of inlined file: juce_KeyMappingEditorComponent.cpp ***/
  47705. /*** Start of inlined file: juce_KeyPress.cpp ***/
  47706. BEGIN_JUCE_NAMESPACE
  47707. KeyPress::KeyPress() throw()
  47708. : keyCode (0),
  47709. mods (0),
  47710. textCharacter (0)
  47711. {
  47712. }
  47713. KeyPress::KeyPress (const int keyCode_,
  47714. const ModifierKeys& mods_,
  47715. const juce_wchar textCharacter_) throw()
  47716. : keyCode (keyCode_),
  47717. mods (mods_),
  47718. textCharacter (textCharacter_)
  47719. {
  47720. }
  47721. KeyPress::KeyPress (const int keyCode_) throw()
  47722. : keyCode (keyCode_),
  47723. textCharacter (0)
  47724. {
  47725. }
  47726. KeyPress::KeyPress (const KeyPress& other) throw()
  47727. : keyCode (other.keyCode),
  47728. mods (other.mods),
  47729. textCharacter (other.textCharacter)
  47730. {
  47731. }
  47732. KeyPress& KeyPress::operator= (const KeyPress& other) throw()
  47733. {
  47734. keyCode = other.keyCode;
  47735. mods = other.mods;
  47736. textCharacter = other.textCharacter;
  47737. return *this;
  47738. }
  47739. bool KeyPress::operator== (const KeyPress& other) const throw()
  47740. {
  47741. return mods.getRawFlags() == other.mods.getRawFlags()
  47742. && (textCharacter == other.textCharacter
  47743. || textCharacter == 0
  47744. || other.textCharacter == 0)
  47745. && (keyCode == other.keyCode
  47746. || (keyCode < 256
  47747. && other.keyCode < 256
  47748. && CharacterFunctions::toLowerCase ((tchar) keyCode)
  47749. == CharacterFunctions::toLowerCase ((tchar) other.keyCode)));
  47750. }
  47751. bool KeyPress::operator!= (const KeyPress& other) const throw()
  47752. {
  47753. return ! operator== (other);
  47754. }
  47755. bool KeyPress::isCurrentlyDown() const throw()
  47756. {
  47757. return isKeyCurrentlyDown (keyCode)
  47758. && (ModifierKeys::getCurrentModifiers().getRawFlags() & ModifierKeys::allKeyboardModifiers)
  47759. == (mods.getRawFlags() & ModifierKeys::allKeyboardModifiers);
  47760. }
  47761. struct KeyNameAndCode
  47762. {
  47763. const char* name;
  47764. int code;
  47765. };
  47766. static const KeyNameAndCode keyNameTranslations[] =
  47767. {
  47768. { "spacebar", KeyPress::spaceKey },
  47769. { "return", KeyPress::returnKey },
  47770. { "escape", KeyPress::escapeKey },
  47771. { "backspace", KeyPress::backspaceKey },
  47772. { "cursor left", KeyPress::leftKey },
  47773. { "cursor right", KeyPress::rightKey },
  47774. { "cursor up", KeyPress::upKey },
  47775. { "cursor down", KeyPress::downKey },
  47776. { "page up", KeyPress::pageUpKey },
  47777. { "page down", KeyPress::pageDownKey },
  47778. { "home", KeyPress::homeKey },
  47779. { "end", KeyPress::endKey },
  47780. { "delete", KeyPress::deleteKey },
  47781. { "insert", KeyPress::insertKey },
  47782. { "tab", KeyPress::tabKey },
  47783. { "play", KeyPress::playKey },
  47784. { "stop", KeyPress::stopKey },
  47785. { "fast forward", KeyPress::fastForwardKey },
  47786. { "rewind", KeyPress::rewindKey }
  47787. };
  47788. static const tchar* const numberPadPrefix = T("numpad ");
  47789. const KeyPress KeyPress::createFromDescription (const String& desc) throw()
  47790. {
  47791. int modifiers = 0;
  47792. if (desc.containsWholeWordIgnoreCase (T("ctrl"))
  47793. || desc.containsWholeWordIgnoreCase (T("control"))
  47794. || desc.containsWholeWordIgnoreCase (T("ctl")))
  47795. modifiers |= ModifierKeys::ctrlModifier;
  47796. if (desc.containsWholeWordIgnoreCase (T("shift"))
  47797. || desc.containsWholeWordIgnoreCase (T("shft")))
  47798. modifiers |= ModifierKeys::shiftModifier;
  47799. if (desc.containsWholeWordIgnoreCase (T("alt"))
  47800. || desc.containsWholeWordIgnoreCase (T("option")))
  47801. modifiers |= ModifierKeys::altModifier;
  47802. if (desc.containsWholeWordIgnoreCase (T("command"))
  47803. || desc.containsWholeWordIgnoreCase (T("cmd")))
  47804. modifiers |= ModifierKeys::commandModifier;
  47805. int key = 0;
  47806. for (int i = 0; i < numElementsInArray (keyNameTranslations); ++i)
  47807. {
  47808. if (desc.containsWholeWordIgnoreCase (String (keyNameTranslations[i].name)))
  47809. {
  47810. key = keyNameTranslations[i].code;
  47811. break;
  47812. }
  47813. }
  47814. if (key == 0)
  47815. {
  47816. // see if it's a numpad key..
  47817. if (desc.containsIgnoreCase (numberPadPrefix))
  47818. {
  47819. const tchar lastChar = desc.trimEnd().getLastCharacter();
  47820. if (lastChar >= T('0') && lastChar <= T('9'))
  47821. key = numberPad0 + lastChar - T('0');
  47822. else if (lastChar == T('+'))
  47823. key = numberPadAdd;
  47824. else if (lastChar == T('-'))
  47825. key = numberPadSubtract;
  47826. else if (lastChar == T('*'))
  47827. key = numberPadMultiply;
  47828. else if (lastChar == T('/'))
  47829. key = numberPadDivide;
  47830. else if (lastChar == T('.'))
  47831. key = numberPadDecimalPoint;
  47832. else if (lastChar == T('='))
  47833. key = numberPadEquals;
  47834. else if (desc.endsWith (T("separator")))
  47835. key = numberPadSeparator;
  47836. else if (desc.endsWith (T("delete")))
  47837. key = numberPadDelete;
  47838. }
  47839. if (key == 0)
  47840. {
  47841. // see if it's a function key..
  47842. for (int i = 1; i <= 12; ++i)
  47843. if (desc.containsWholeWordIgnoreCase (T("f") + String (i)))
  47844. key = F1Key + i - 1;
  47845. if (key == 0)
  47846. {
  47847. // give up and use the hex code..
  47848. const int hexCode = desc.fromFirstOccurrenceOf (T("#"), false, false)
  47849. .toLowerCase()
  47850. .retainCharacters (T("0123456789abcdef"))
  47851. .getHexValue32();
  47852. if (hexCode > 0)
  47853. key = hexCode;
  47854. else
  47855. key = CharacterFunctions::toUpperCase (desc.getLastCharacter());
  47856. }
  47857. }
  47858. }
  47859. return KeyPress (key, ModifierKeys (modifiers), 0);
  47860. }
  47861. const String KeyPress::getTextDescription() const throw()
  47862. {
  47863. String desc;
  47864. if (keyCode > 0)
  47865. {
  47866. // some keyboard layouts use a shift-key to get the slash, but in those cases, we
  47867. // want to store it as being a slash, not shift+whatever.
  47868. if (textCharacter == T('/'))
  47869. return "/";
  47870. if (mods.isCtrlDown())
  47871. desc << "ctrl + ";
  47872. if (mods.isShiftDown())
  47873. desc << "shift + ";
  47874. #if JUCE_MAC
  47875. // only do this on the mac, because on Windows ctrl and command are the same,
  47876. // and this would get confusing
  47877. if (mods.isCommandDown())
  47878. desc << "command + ";
  47879. if (mods.isAltDown())
  47880. desc << "option + ";
  47881. #else
  47882. if (mods.isAltDown())
  47883. desc << "alt + ";
  47884. #endif
  47885. for (int i = 0; i < numElementsInArray (keyNameTranslations); ++i)
  47886. if (keyCode == keyNameTranslations[i].code)
  47887. return desc + keyNameTranslations[i].name;
  47888. if (keyCode >= F1Key && keyCode <= F16Key)
  47889. desc << 'F' << (1 + keyCode - F1Key);
  47890. else if (keyCode >= numberPad0 && keyCode <= numberPad9)
  47891. desc << numberPadPrefix << (keyCode - numberPad0);
  47892. else if (keyCode >= 33 && keyCode < 176)
  47893. desc += CharacterFunctions::toUpperCase ((tchar) keyCode);
  47894. else if (keyCode == numberPadAdd)
  47895. desc << numberPadPrefix << '+';
  47896. else if (keyCode == numberPadSubtract)
  47897. desc << numberPadPrefix << '-';
  47898. else if (keyCode == numberPadMultiply)
  47899. desc << numberPadPrefix << '*';
  47900. else if (keyCode == numberPadDivide)
  47901. desc << numberPadPrefix << '/';
  47902. else if (keyCode == numberPadSeparator)
  47903. desc << numberPadPrefix << "separator";
  47904. else if (keyCode == numberPadDecimalPoint)
  47905. desc << numberPadPrefix << '.';
  47906. else if (keyCode == numberPadDelete)
  47907. desc << numberPadPrefix << "delete";
  47908. else
  47909. desc << '#' << String::toHexString (keyCode);
  47910. }
  47911. return desc;
  47912. }
  47913. END_JUCE_NAMESPACE
  47914. /*** End of inlined file: juce_KeyPress.cpp ***/
  47915. /*** Start of inlined file: juce_KeyPressMappingSet.cpp ***/
  47916. BEGIN_JUCE_NAMESPACE
  47917. KeyPressMappingSet::KeyPressMappingSet (ApplicationCommandManager* const commandManager_) throw()
  47918. : commandManager (commandManager_)
  47919. {
  47920. // A manager is needed to get the descriptions of commands, and will be called when
  47921. // a command is invoked. So you can't leave this null..
  47922. jassert (commandManager_ != 0);
  47923. Desktop::getInstance().addFocusChangeListener (this);
  47924. }
  47925. KeyPressMappingSet::KeyPressMappingSet (const KeyPressMappingSet& other) throw()
  47926. : commandManager (other.commandManager)
  47927. {
  47928. Desktop::getInstance().addFocusChangeListener (this);
  47929. }
  47930. KeyPressMappingSet::~KeyPressMappingSet()
  47931. {
  47932. Desktop::getInstance().removeFocusChangeListener (this);
  47933. }
  47934. const Array <KeyPress> KeyPressMappingSet::getKeyPressesAssignedToCommand (const CommandID commandID) const throw()
  47935. {
  47936. for (int i = 0; i < mappings.size(); ++i)
  47937. if (mappings.getUnchecked(i)->commandID == commandID)
  47938. return mappings.getUnchecked (i)->keypresses;
  47939. return Array <KeyPress> ();
  47940. }
  47941. void KeyPressMappingSet::addKeyPress (const CommandID commandID,
  47942. const KeyPress& newKeyPress,
  47943. int insertIndex) throw()
  47944. {
  47945. // If you specify an upper-case letter but no shift key, how is the user supposed to press it!?
  47946. // Stick to lower-case letters when defining a keypress, to avoid ambiguity.
  47947. jassert (! (CharacterFunctions::isUpperCase (newKeyPress.getTextCharacter())
  47948. && ! newKeyPress.getModifiers().isShiftDown()));
  47949. if (findCommandForKeyPress (newKeyPress) != commandID)
  47950. {
  47951. removeKeyPress (newKeyPress);
  47952. if (newKeyPress.isValid())
  47953. {
  47954. for (int i = mappings.size(); --i >= 0;)
  47955. {
  47956. if (mappings.getUnchecked(i)->commandID == commandID)
  47957. {
  47958. mappings.getUnchecked(i)->keypresses.insert (insertIndex, newKeyPress);
  47959. sendChangeMessage (this);
  47960. return;
  47961. }
  47962. }
  47963. const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID);
  47964. if (ci != 0)
  47965. {
  47966. CommandMapping* const cm = new CommandMapping();
  47967. cm->commandID = commandID;
  47968. cm->keypresses.add (newKeyPress);
  47969. cm->wantsKeyUpDownCallbacks = (ci->flags & ApplicationCommandInfo::wantsKeyUpDownCallbacks) != 0;
  47970. mappings.add (cm);
  47971. sendChangeMessage (this);
  47972. }
  47973. }
  47974. }
  47975. }
  47976. void KeyPressMappingSet::resetToDefaultMappings() throw()
  47977. {
  47978. mappings.clear();
  47979. for (int i = 0; i < commandManager->getNumCommands(); ++i)
  47980. {
  47981. const ApplicationCommandInfo* const ci = commandManager->getCommandForIndex (i);
  47982. for (int j = 0; j < ci->defaultKeypresses.size(); ++j)
  47983. {
  47984. addKeyPress (ci->commandID,
  47985. ci->defaultKeypresses.getReference (j));
  47986. }
  47987. }
  47988. sendChangeMessage (this);
  47989. }
  47990. void KeyPressMappingSet::resetToDefaultMapping (const CommandID commandID) throw()
  47991. {
  47992. clearAllKeyPresses (commandID);
  47993. const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID);
  47994. for (int j = 0; j < ci->defaultKeypresses.size(); ++j)
  47995. {
  47996. addKeyPress (ci->commandID,
  47997. ci->defaultKeypresses.getReference (j));
  47998. }
  47999. }
  48000. void KeyPressMappingSet::clearAllKeyPresses() throw()
  48001. {
  48002. if (mappings.size() > 0)
  48003. {
  48004. sendChangeMessage (this);
  48005. mappings.clear();
  48006. }
  48007. }
  48008. void KeyPressMappingSet::clearAllKeyPresses (const CommandID commandID) throw()
  48009. {
  48010. for (int i = mappings.size(); --i >= 0;)
  48011. {
  48012. if (mappings.getUnchecked(i)->commandID == commandID)
  48013. {
  48014. mappings.remove (i);
  48015. sendChangeMessage (this);
  48016. }
  48017. }
  48018. }
  48019. void KeyPressMappingSet::removeKeyPress (const KeyPress& keypress) throw()
  48020. {
  48021. if (keypress.isValid())
  48022. {
  48023. for (int i = mappings.size(); --i >= 0;)
  48024. {
  48025. CommandMapping* const cm = mappings.getUnchecked(i);
  48026. for (int j = cm->keypresses.size(); --j >= 0;)
  48027. {
  48028. if (keypress == cm->keypresses [j])
  48029. {
  48030. cm->keypresses.remove (j);
  48031. sendChangeMessage (this);
  48032. }
  48033. }
  48034. }
  48035. }
  48036. }
  48037. void KeyPressMappingSet::removeKeyPress (const CommandID commandID,
  48038. const int keyPressIndex) throw()
  48039. {
  48040. for (int i = mappings.size(); --i >= 0;)
  48041. {
  48042. if (mappings.getUnchecked(i)->commandID == commandID)
  48043. {
  48044. mappings.getUnchecked(i)->keypresses.remove (keyPressIndex);
  48045. sendChangeMessage (this);
  48046. break;
  48047. }
  48048. }
  48049. }
  48050. CommandID KeyPressMappingSet::findCommandForKeyPress (const KeyPress& keyPress) const throw()
  48051. {
  48052. for (int i = 0; i < mappings.size(); ++i)
  48053. if (mappings.getUnchecked(i)->keypresses.contains (keyPress))
  48054. return mappings.getUnchecked(i)->commandID;
  48055. return 0;
  48056. }
  48057. bool KeyPressMappingSet::containsMapping (const CommandID commandID,
  48058. const KeyPress& keyPress) const throw()
  48059. {
  48060. for (int i = mappings.size(); --i >= 0;)
  48061. if (mappings.getUnchecked(i)->commandID == commandID)
  48062. return mappings.getUnchecked(i)->keypresses.contains (keyPress);
  48063. return false;
  48064. }
  48065. void KeyPressMappingSet::invokeCommand (const CommandID commandID,
  48066. const KeyPress& key,
  48067. const bool isKeyDown,
  48068. const int millisecsSinceKeyPressed,
  48069. Component* const originatingComponent) const
  48070. {
  48071. ApplicationCommandTarget::InvocationInfo info (commandID);
  48072. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromKeyPress;
  48073. info.isKeyDown = isKeyDown;
  48074. info.keyPress = key;
  48075. info.millisecsSinceKeyPressed = millisecsSinceKeyPressed;
  48076. info.originatingComponent = originatingComponent;
  48077. commandManager->invoke (info, false);
  48078. }
  48079. bool KeyPressMappingSet::restoreFromXml (const XmlElement& xmlVersion)
  48080. {
  48081. if (xmlVersion.hasTagName (T("KEYMAPPINGS")))
  48082. {
  48083. if (xmlVersion.getBoolAttribute (T("basedOnDefaults"), true))
  48084. {
  48085. // if the XML was created as a set of differences from the default mappings,
  48086. // (i.e. by calling createXml (true)), then we need to first restore the defaults.
  48087. resetToDefaultMappings();
  48088. }
  48089. else
  48090. {
  48091. // if the XML was created calling createXml (false), then we need to clear all
  48092. // the keys and treat the xml as describing the entire set of mappings.
  48093. clearAllKeyPresses();
  48094. }
  48095. forEachXmlChildElement (xmlVersion, map)
  48096. {
  48097. const CommandID commandId = map->getStringAttribute (T("commandId")).getHexValue32();
  48098. if (commandId != 0)
  48099. {
  48100. const KeyPress key (KeyPress::createFromDescription (map->getStringAttribute (T("key"))));
  48101. if (map->hasTagName (T("MAPPING")))
  48102. {
  48103. addKeyPress (commandId, key);
  48104. }
  48105. else if (map->hasTagName (T("UNMAPPING")))
  48106. {
  48107. if (containsMapping (commandId, key))
  48108. removeKeyPress (key);
  48109. }
  48110. }
  48111. }
  48112. return true;
  48113. }
  48114. return false;
  48115. }
  48116. XmlElement* KeyPressMappingSet::createXml (const bool saveDifferencesFromDefaultSet) const
  48117. {
  48118. ScopedPointer <KeyPressMappingSet> defaultSet;
  48119. if (saveDifferencesFromDefaultSet)
  48120. {
  48121. defaultSet = new KeyPressMappingSet (commandManager);
  48122. defaultSet->resetToDefaultMappings();
  48123. }
  48124. XmlElement* const doc = new XmlElement (T("KEYMAPPINGS"));
  48125. doc->setAttribute (T("basedOnDefaults"), saveDifferencesFromDefaultSet);
  48126. int i;
  48127. for (i = 0; i < mappings.size(); ++i)
  48128. {
  48129. const CommandMapping* const cm = mappings.getUnchecked(i);
  48130. for (int j = 0; j < cm->keypresses.size(); ++j)
  48131. {
  48132. if (defaultSet == 0
  48133. || ! defaultSet->containsMapping (cm->commandID, cm->keypresses.getReference (j)))
  48134. {
  48135. XmlElement* const map = doc->createNewChildElement ("MAPPING");
  48136. map->setAttribute (T("commandId"), String::toHexString ((int) cm->commandID));
  48137. map->setAttribute (T("description"), commandManager->getDescriptionOfCommand (cm->commandID));
  48138. map->setAttribute (T("key"), cm->keypresses.getReference (j).getTextDescription());
  48139. }
  48140. }
  48141. }
  48142. if (defaultSet != 0)
  48143. {
  48144. for (i = 0; i < defaultSet->mappings.size(); ++i)
  48145. {
  48146. const CommandMapping* const cm = defaultSet->mappings.getUnchecked(i);
  48147. for (int j = 0; j < cm->keypresses.size(); ++j)
  48148. {
  48149. if (! containsMapping (cm->commandID, cm->keypresses.getReference (j)))
  48150. {
  48151. XmlElement* const map = doc->createNewChildElement ("UNMAPPING");
  48152. map->setAttribute (T("commandId"), String::toHexString ((int) cm->commandID));
  48153. map->setAttribute (T("description"), commandManager->getDescriptionOfCommand (cm->commandID));
  48154. map->setAttribute (T("key"), cm->keypresses.getReference (j).getTextDescription());
  48155. }
  48156. }
  48157. }
  48158. }
  48159. return doc;
  48160. }
  48161. bool KeyPressMappingSet::keyPressed (const KeyPress& key,
  48162. Component* originatingComponent)
  48163. {
  48164. bool used = false;
  48165. const CommandID commandID = findCommandForKeyPress (key);
  48166. const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID);
  48167. if (ci != 0
  48168. && (ci->flags & ApplicationCommandInfo::wantsKeyUpDownCallbacks) == 0)
  48169. {
  48170. ApplicationCommandInfo info (0);
  48171. if (commandManager->getTargetForCommand (commandID, info) != 0
  48172. && (info.flags & ApplicationCommandInfo::isDisabled) == 0)
  48173. {
  48174. invokeCommand (commandID, key, true, 0, originatingComponent);
  48175. used = true;
  48176. }
  48177. else
  48178. {
  48179. if (originatingComponent != 0)
  48180. originatingComponent->getLookAndFeel().playAlertSound();
  48181. }
  48182. }
  48183. return used;
  48184. }
  48185. bool KeyPressMappingSet::keyStateChanged (const bool /*isKeyDown*/, Component* originatingComponent)
  48186. {
  48187. bool used = false;
  48188. const uint32 now = Time::getMillisecondCounter();
  48189. for (int i = mappings.size(); --i >= 0;)
  48190. {
  48191. CommandMapping* const cm = mappings.getUnchecked(i);
  48192. if (cm->wantsKeyUpDownCallbacks)
  48193. {
  48194. for (int j = cm->keypresses.size(); --j >= 0;)
  48195. {
  48196. const KeyPress key (cm->keypresses.getReference (j));
  48197. const bool isDown = key.isCurrentlyDown();
  48198. int keyPressEntryIndex = 0;
  48199. bool wasDown = false;
  48200. for (int k = keysDown.size(); --k >= 0;)
  48201. {
  48202. if (key == keysDown.getUnchecked(k)->key)
  48203. {
  48204. keyPressEntryIndex = k;
  48205. wasDown = true;
  48206. used = true;
  48207. break;
  48208. }
  48209. }
  48210. if (isDown != wasDown)
  48211. {
  48212. int millisecs = 0;
  48213. if (isDown)
  48214. {
  48215. KeyPressTime* const k = new KeyPressTime();
  48216. k->key = key;
  48217. k->timeWhenPressed = now;
  48218. keysDown.add (k);
  48219. }
  48220. else
  48221. {
  48222. const uint32 pressTime = keysDown.getUnchecked (keyPressEntryIndex)->timeWhenPressed;
  48223. if (now > pressTime)
  48224. millisecs = now - pressTime;
  48225. keysDown.remove (keyPressEntryIndex);
  48226. }
  48227. invokeCommand (cm->commandID, key, isDown, millisecs, originatingComponent);
  48228. used = true;
  48229. }
  48230. }
  48231. }
  48232. }
  48233. return used;
  48234. }
  48235. void KeyPressMappingSet::globalFocusChanged (Component* focusedComponent)
  48236. {
  48237. if (focusedComponent != 0)
  48238. focusedComponent->keyStateChanged (false);
  48239. }
  48240. END_JUCE_NAMESPACE
  48241. /*** End of inlined file: juce_KeyPressMappingSet.cpp ***/
  48242. /*** Start of inlined file: juce_ModifierKeys.cpp ***/
  48243. BEGIN_JUCE_NAMESPACE
  48244. ModifierKeys::ModifierKeys (const int flags_) throw()
  48245. : flags (flags_)
  48246. {
  48247. }
  48248. ModifierKeys::ModifierKeys (const ModifierKeys& other) throw()
  48249. : flags (other.flags)
  48250. {
  48251. }
  48252. ModifierKeys& ModifierKeys::operator= (const ModifierKeys& other) throw()
  48253. {
  48254. flags = other.flags;
  48255. return *this;
  48256. }
  48257. ModifierKeys ModifierKeys::currentModifiers;
  48258. const ModifierKeys ModifierKeys::getCurrentModifiers() throw()
  48259. {
  48260. return currentModifiers;
  48261. }
  48262. int ModifierKeys::getNumMouseButtonsDown() const throw()
  48263. {
  48264. int num = 0;
  48265. if (isLeftButtonDown()) ++num;
  48266. if (isRightButtonDown()) ++num;
  48267. if (isMiddleButtonDown()) ++num;
  48268. return num;
  48269. }
  48270. END_JUCE_NAMESPACE
  48271. /*** End of inlined file: juce_ModifierKeys.cpp ***/
  48272. /*** Start of inlined file: juce_ComponentAnimator.cpp ***/
  48273. BEGIN_JUCE_NAMESPACE
  48274. struct AnimationTask
  48275. {
  48276. AnimationTask (Component* const comp)
  48277. : component (comp)
  48278. {
  48279. }
  48280. Component::SafePointer<Component> component;
  48281. Rectangle<int> destination;
  48282. int msElapsed, msTotal;
  48283. double startSpeed, midSpeed, endSpeed, lastProgress;
  48284. double left, top, right, bottom;
  48285. bool useTimeslice (const int elapsed)
  48286. {
  48287. if (component == 0)
  48288. return false;
  48289. msElapsed += elapsed;
  48290. double newProgress = msElapsed / (double) msTotal;
  48291. if (newProgress >= 0 && newProgress < 1.0)
  48292. {
  48293. newProgress = timeToDistance (newProgress);
  48294. const double delta = (newProgress - lastProgress) / (1.0 - lastProgress);
  48295. jassert (newProgress >= lastProgress);
  48296. lastProgress = newProgress;
  48297. left += (destination.getX() - left) * delta;
  48298. top += (destination.getY() - top) * delta;
  48299. right += (destination.getRight() - right) * delta;
  48300. bottom += (destination.getBottom() - bottom) * delta;
  48301. if (delta < 1.0)
  48302. {
  48303. const Rectangle<int> newBounds (roundToInt (left),
  48304. roundToInt (top),
  48305. roundToInt (right - left),
  48306. roundToInt (bottom - top));
  48307. if (newBounds != destination)
  48308. {
  48309. component->setBounds (newBounds);
  48310. return true;
  48311. }
  48312. }
  48313. }
  48314. component->setBounds (destination);
  48315. return false;
  48316. }
  48317. void moveToFinalDestination()
  48318. {
  48319. if (component != 0)
  48320. component->setBounds (destination);
  48321. }
  48322. private:
  48323. inline double timeToDistance (const double time) const
  48324. {
  48325. return (time < 0.5) ? time * (startSpeed + time * (midSpeed - startSpeed))
  48326. : 0.5 * (startSpeed + 0.5 * (midSpeed - startSpeed))
  48327. + (time - 0.5) * (midSpeed + (time - 0.5) * (endSpeed - midSpeed));
  48328. }
  48329. };
  48330. ComponentAnimator::ComponentAnimator()
  48331. : lastTime (0)
  48332. {
  48333. }
  48334. ComponentAnimator::~ComponentAnimator()
  48335. {
  48336. cancelAllAnimations (false);
  48337. jassert (tasks.size() == 0);
  48338. }
  48339. void* ComponentAnimator::findTaskFor (Component* const component) const
  48340. {
  48341. for (int i = tasks.size(); --i >= 0;)
  48342. if (component == ((AnimationTask*) tasks.getUnchecked(i))->component.getComponent())
  48343. return tasks.getUnchecked(i);
  48344. return 0;
  48345. }
  48346. void ComponentAnimator::animateComponent (Component* const component,
  48347. const Rectangle<int>& finalPosition,
  48348. const int millisecondsToSpendMoving,
  48349. const double startSpeed,
  48350. const double endSpeed)
  48351. {
  48352. if (component != 0)
  48353. {
  48354. AnimationTask* at = (AnimationTask*) findTaskFor (component);
  48355. if (at == 0)
  48356. {
  48357. at = new AnimationTask (component);
  48358. tasks.add (at);
  48359. sendChangeMessage (this);
  48360. }
  48361. at->msElapsed = 0;
  48362. at->lastProgress = 0;
  48363. at->msTotal = jmax (1, millisecondsToSpendMoving);
  48364. at->destination = finalPosition;
  48365. // the speeds must be 0 or greater!
  48366. jassert (startSpeed >= 0 && endSpeed >= 0)
  48367. const double invTotalDistance = 4.0 / (startSpeed + endSpeed + 2.0);
  48368. at->startSpeed = jmax (0.0, startSpeed * invTotalDistance);
  48369. at->midSpeed = invTotalDistance;
  48370. at->endSpeed = jmax (0.0, endSpeed * invTotalDistance);
  48371. at->left = component->getX();
  48372. at->top = component->getY();
  48373. at->right = component->getRight();
  48374. at->bottom = component->getBottom();
  48375. if (! isTimerRunning())
  48376. {
  48377. lastTime = Time::getMillisecondCounter();
  48378. startTimer (1000 / 50);
  48379. }
  48380. }
  48381. }
  48382. void ComponentAnimator::cancelAllAnimations (const bool moveComponentsToTheirFinalPositions)
  48383. {
  48384. for (int i = tasks.size(); --i >= 0;)
  48385. {
  48386. AnimationTask* const at = (AnimationTask*) tasks.getUnchecked(i);
  48387. if (moveComponentsToTheirFinalPositions)
  48388. at->moveToFinalDestination();
  48389. delete at;
  48390. tasks.remove (i);
  48391. sendChangeMessage (this);
  48392. }
  48393. }
  48394. void ComponentAnimator::cancelAnimation (Component* const component,
  48395. const bool moveComponentToItsFinalPosition)
  48396. {
  48397. AnimationTask* const at = (AnimationTask*) findTaskFor (component);
  48398. if (at != 0)
  48399. {
  48400. if (moveComponentToItsFinalPosition)
  48401. at->moveToFinalDestination();
  48402. tasks.removeValue (at);
  48403. delete at;
  48404. sendChangeMessage (this);
  48405. }
  48406. }
  48407. const Rectangle<int> ComponentAnimator::getComponentDestination (Component* const component)
  48408. {
  48409. AnimationTask* const at = (AnimationTask*) findTaskFor (component);
  48410. if (at != 0)
  48411. return at->destination;
  48412. else if (component != 0)
  48413. return component->getBounds();
  48414. return Rectangle<int>();
  48415. }
  48416. bool ComponentAnimator::isAnimating (Component* component) const
  48417. {
  48418. return findTaskFor (component) != 0;
  48419. }
  48420. void ComponentAnimator::timerCallback()
  48421. {
  48422. const uint32 timeNow = Time::getMillisecondCounter();
  48423. if (lastTime == 0 || lastTime == timeNow)
  48424. lastTime = timeNow;
  48425. const int elapsed = timeNow - lastTime;
  48426. for (int i = tasks.size(); --i >= 0;)
  48427. {
  48428. AnimationTask* const at = (AnimationTask*) tasks.getUnchecked(i);
  48429. if (! at->useTimeslice (elapsed))
  48430. {
  48431. tasks.remove (i);
  48432. delete at;
  48433. sendChangeMessage (this);
  48434. }
  48435. }
  48436. lastTime = timeNow;
  48437. if (tasks.size() == 0)
  48438. stopTimer();
  48439. }
  48440. END_JUCE_NAMESPACE
  48441. /*** End of inlined file: juce_ComponentAnimator.cpp ***/
  48442. /*** Start of inlined file: juce_ComponentBoundsConstrainer.cpp ***/
  48443. BEGIN_JUCE_NAMESPACE
  48444. ComponentBoundsConstrainer::ComponentBoundsConstrainer() throw()
  48445. : minW (0),
  48446. maxW (0x3fffffff),
  48447. minH (0),
  48448. maxH (0x3fffffff),
  48449. minOffTop (0),
  48450. minOffLeft (0),
  48451. minOffBottom (0),
  48452. minOffRight (0),
  48453. aspectRatio (0.0)
  48454. {
  48455. }
  48456. ComponentBoundsConstrainer::~ComponentBoundsConstrainer()
  48457. {
  48458. }
  48459. void ComponentBoundsConstrainer::setMinimumWidth (const int minimumWidth) throw()
  48460. {
  48461. minW = minimumWidth;
  48462. }
  48463. void ComponentBoundsConstrainer::setMaximumWidth (const int maximumWidth) throw()
  48464. {
  48465. maxW = maximumWidth;
  48466. }
  48467. void ComponentBoundsConstrainer::setMinimumHeight (const int minimumHeight) throw()
  48468. {
  48469. minH = minimumHeight;
  48470. }
  48471. void ComponentBoundsConstrainer::setMaximumHeight (const int maximumHeight) throw()
  48472. {
  48473. maxH = maximumHeight;
  48474. }
  48475. void ComponentBoundsConstrainer::setMinimumSize (const int minimumWidth, const int minimumHeight) throw()
  48476. {
  48477. jassert (maxW >= minimumWidth);
  48478. jassert (maxH >= minimumHeight);
  48479. jassert (minimumWidth > 0 && minimumHeight > 0);
  48480. minW = minimumWidth;
  48481. minH = minimumHeight;
  48482. if (minW > maxW)
  48483. maxW = minW;
  48484. if (minH > maxH)
  48485. maxH = minH;
  48486. }
  48487. void ComponentBoundsConstrainer::setMaximumSize (const int maximumWidth, const int maximumHeight) throw()
  48488. {
  48489. jassert (maximumWidth >= minW);
  48490. jassert (maximumHeight >= minH);
  48491. jassert (maximumWidth > 0 && maximumHeight > 0);
  48492. maxW = jmax (minW, maximumWidth);
  48493. maxH = jmax (minH, maximumHeight);
  48494. }
  48495. void ComponentBoundsConstrainer::setSizeLimits (const int minimumWidth,
  48496. const int minimumHeight,
  48497. const int maximumWidth,
  48498. const int maximumHeight) throw()
  48499. {
  48500. jassert (maximumWidth >= minimumWidth);
  48501. jassert (maximumHeight >= minimumHeight);
  48502. jassert (maximumWidth > 0 && maximumHeight > 0);
  48503. jassert (minimumWidth > 0 && minimumHeight > 0);
  48504. minW = jmax (0, minimumWidth);
  48505. minH = jmax (0, minimumHeight);
  48506. maxW = jmax (minW, maximumWidth);
  48507. maxH = jmax (minH, maximumHeight);
  48508. }
  48509. void ComponentBoundsConstrainer::setMinimumOnscreenAmounts (const int minimumWhenOffTheTop,
  48510. const int minimumWhenOffTheLeft,
  48511. const int minimumWhenOffTheBottom,
  48512. const int minimumWhenOffTheRight) throw()
  48513. {
  48514. minOffTop = minimumWhenOffTheTop;
  48515. minOffLeft = minimumWhenOffTheLeft;
  48516. minOffBottom = minimumWhenOffTheBottom;
  48517. minOffRight = minimumWhenOffTheRight;
  48518. }
  48519. void ComponentBoundsConstrainer::setFixedAspectRatio (const double widthOverHeight) throw()
  48520. {
  48521. aspectRatio = jmax (0.0, widthOverHeight);
  48522. }
  48523. double ComponentBoundsConstrainer::getFixedAspectRatio() const throw()
  48524. {
  48525. return aspectRatio;
  48526. }
  48527. void ComponentBoundsConstrainer::setBoundsForComponent (Component* const component,
  48528. const Rectangle<int>& targetBounds,
  48529. const bool isStretchingTop,
  48530. const bool isStretchingLeft,
  48531. const bool isStretchingBottom,
  48532. const bool isStretchingRight)
  48533. {
  48534. jassert (component != 0);
  48535. Rectangle<int> limits, bounds (targetBounds);
  48536. BorderSize border;
  48537. Component* const parent = component->getParentComponent();
  48538. if (parent == 0)
  48539. {
  48540. ComponentPeer* peer = component->getPeer();
  48541. if (peer != 0)
  48542. border = peer->getFrameSize();
  48543. limits = Desktop::getInstance().getMonitorAreaContaining (bounds.getCentre());
  48544. }
  48545. else
  48546. {
  48547. limits.setSize (parent->getWidth(), parent->getHeight());
  48548. }
  48549. border.addTo (bounds);
  48550. checkBounds (bounds,
  48551. border.addedTo (component->getBounds()), limits,
  48552. isStretchingTop, isStretchingLeft,
  48553. isStretchingBottom, isStretchingRight);
  48554. border.subtractFrom (bounds);
  48555. applyBoundsToComponent (component, bounds);
  48556. }
  48557. void ComponentBoundsConstrainer::checkComponentBounds (Component* component)
  48558. {
  48559. setBoundsForComponent (component, component->getBounds(),
  48560. false, false, false, false);
  48561. }
  48562. void ComponentBoundsConstrainer::applyBoundsToComponent (Component* component,
  48563. const Rectangle<int>& bounds)
  48564. {
  48565. component->setBounds (bounds);
  48566. }
  48567. void ComponentBoundsConstrainer::resizeStart()
  48568. {
  48569. }
  48570. void ComponentBoundsConstrainer::resizeEnd()
  48571. {
  48572. }
  48573. void ComponentBoundsConstrainer::checkBounds (Rectangle<int>& bounds,
  48574. const Rectangle<int>& old,
  48575. const Rectangle<int>& limits,
  48576. const bool isStretchingTop,
  48577. const bool isStretchingLeft,
  48578. const bool isStretchingBottom,
  48579. const bool isStretchingRight)
  48580. {
  48581. int x = bounds.getX();
  48582. int y = bounds.getY();
  48583. int w = bounds.getWidth();
  48584. int h = bounds.getHeight();
  48585. // constrain the size if it's being stretched..
  48586. if (isStretchingLeft)
  48587. {
  48588. x = jlimit (old.getRight() - maxW, old.getRight() - minW, x);
  48589. w = old.getRight() - x;
  48590. }
  48591. if (isStretchingRight)
  48592. {
  48593. w = jlimit (minW, maxW, w);
  48594. }
  48595. if (isStretchingTop)
  48596. {
  48597. y = jlimit (old.getBottom() - maxH, old.getBottom() - minH, y);
  48598. h = old.getBottom() - y;
  48599. }
  48600. if (isStretchingBottom)
  48601. {
  48602. h = jlimit (minH, maxH, h);
  48603. }
  48604. // constrain the aspect ratio if one has been specified..
  48605. if (aspectRatio > 0.0 && w > 0 && h > 0)
  48606. {
  48607. bool adjustWidth;
  48608. if ((isStretchingTop || isStretchingBottom) && ! (isStretchingLeft || isStretchingRight))
  48609. {
  48610. adjustWidth = true;
  48611. }
  48612. else if ((isStretchingLeft || isStretchingRight) && ! (isStretchingTop || isStretchingBottom))
  48613. {
  48614. adjustWidth = false;
  48615. }
  48616. else
  48617. {
  48618. const double oldRatio = (old.getHeight() > 0) ? fabs (old.getWidth() / (double) old.getHeight()) : 0.0;
  48619. const double newRatio = fabs (w / (double) h);
  48620. adjustWidth = (oldRatio > newRatio);
  48621. }
  48622. if (adjustWidth)
  48623. {
  48624. w = roundToInt (h * aspectRatio);
  48625. if (w > maxW || w < minW)
  48626. {
  48627. w = jlimit (minW, maxW, w);
  48628. h = roundToInt (w / aspectRatio);
  48629. }
  48630. }
  48631. else
  48632. {
  48633. h = roundToInt (w / aspectRatio);
  48634. if (h > maxH || h < minH)
  48635. {
  48636. h = jlimit (minH, maxH, h);
  48637. w = roundToInt (h * aspectRatio);
  48638. }
  48639. }
  48640. if ((isStretchingTop || isStretchingBottom) && ! (isStretchingLeft || isStretchingRight))
  48641. {
  48642. x = old.getX() + (old.getWidth() - w) / 2;
  48643. }
  48644. else if ((isStretchingLeft || isStretchingRight) && ! (isStretchingTop || isStretchingBottom))
  48645. {
  48646. y = old.getY() + (old.getHeight() - h) / 2;
  48647. }
  48648. else
  48649. {
  48650. if (isStretchingLeft)
  48651. x = old.getRight() - w;
  48652. if (isStretchingTop)
  48653. y = old.getBottom() - h;
  48654. }
  48655. }
  48656. // ...and constrain the position if limits have been set for that.
  48657. if (minOffTop > 0 || minOffLeft > 0 || minOffBottom > 0 || minOffRight > 0)
  48658. {
  48659. if (minOffTop > 0)
  48660. {
  48661. const int limit = limits.getY() + jmin (minOffTop - h, 0);
  48662. if (y < limit)
  48663. {
  48664. if (isStretchingTop)
  48665. h -= (limit - y);
  48666. y = limit;
  48667. }
  48668. }
  48669. if (minOffLeft > 0)
  48670. {
  48671. const int limit = limits.getX() + jmin (minOffLeft - w, 0);
  48672. if (x < limit)
  48673. {
  48674. if (isStretchingLeft)
  48675. w -= (limit - x);
  48676. x = limit;
  48677. }
  48678. }
  48679. if (minOffBottom > 0)
  48680. {
  48681. const int limit = limits.getBottom() - jmin (minOffBottom, h);
  48682. if (y > limit)
  48683. {
  48684. if (isStretchingBottom)
  48685. h += (limit - y);
  48686. else
  48687. y = limit;
  48688. }
  48689. }
  48690. if (minOffRight > 0)
  48691. {
  48692. const int limit = limits.getRight() - jmin (minOffRight, w);
  48693. if (x > limit)
  48694. {
  48695. if (isStretchingRight)
  48696. w += (limit - x);
  48697. else
  48698. x = limit;
  48699. }
  48700. }
  48701. }
  48702. jassert (w >= 0 && h >= 0);
  48703. bounds = Rectangle<int> (x, y, w, h);
  48704. }
  48705. END_JUCE_NAMESPACE
  48706. /*** End of inlined file: juce_ComponentBoundsConstrainer.cpp ***/
  48707. /*** Start of inlined file: juce_ComponentMovementWatcher.cpp ***/
  48708. BEGIN_JUCE_NAMESPACE
  48709. ComponentMovementWatcher::ComponentMovementWatcher (Component* const component_)
  48710. : component (component_),
  48711. lastPeer (0),
  48712. reentrant (false)
  48713. {
  48714. jassert (component != 0); // can't use this with a null pointer..
  48715. component->addComponentListener (this);
  48716. registerWithParentComps();
  48717. }
  48718. ComponentMovementWatcher::~ComponentMovementWatcher()
  48719. {
  48720. component->removeComponentListener (this);
  48721. unregister();
  48722. }
  48723. void ComponentMovementWatcher::componentParentHierarchyChanged (Component&)
  48724. {
  48725. // agh! don't delete the target component without deleting this object first!
  48726. jassert (component != 0);
  48727. if (! reentrant)
  48728. {
  48729. reentrant = true;
  48730. ComponentPeer* const peer = component->getPeer();
  48731. if (peer != lastPeer)
  48732. {
  48733. componentPeerChanged();
  48734. if (component == 0)
  48735. return;
  48736. lastPeer = peer;
  48737. }
  48738. unregister();
  48739. registerWithParentComps();
  48740. reentrant = false;
  48741. componentMovedOrResized (*component, true, true);
  48742. }
  48743. }
  48744. void ComponentMovementWatcher::componentMovedOrResized (Component&, bool wasMoved, bool wasResized)
  48745. {
  48746. // agh! don't delete the target component without deleting this object first!
  48747. jassert (component != 0);
  48748. if (wasMoved)
  48749. {
  48750. const Point<int> pos (component->relativePositionToOtherComponent (component->getTopLevelComponent(), Point<int>()));
  48751. wasMoved = lastBounds.getPosition() != pos;
  48752. lastBounds.setPosition (pos);
  48753. }
  48754. wasResized = (lastBounds.getWidth() != component->getWidth() || lastBounds.getHeight() != component->getHeight());
  48755. lastBounds.setSize (component->getWidth(), component->getHeight());
  48756. if (wasMoved || wasResized)
  48757. componentMovedOrResized (wasMoved, wasResized);
  48758. }
  48759. void ComponentMovementWatcher::registerWithParentComps() throw()
  48760. {
  48761. Component* p = component->getParentComponent();
  48762. while (p != 0)
  48763. {
  48764. p->addComponentListener (this);
  48765. registeredParentComps.add (p);
  48766. p = p->getParentComponent();
  48767. }
  48768. }
  48769. void ComponentMovementWatcher::unregister() throw()
  48770. {
  48771. for (int i = registeredParentComps.size(); --i >= 0;)
  48772. ((Component*) registeredParentComps.getUnchecked(i))->removeComponentListener (this);
  48773. registeredParentComps.clear();
  48774. }
  48775. END_JUCE_NAMESPACE
  48776. /*** End of inlined file: juce_ComponentMovementWatcher.cpp ***/
  48777. /*** Start of inlined file: juce_GroupComponent.cpp ***/
  48778. BEGIN_JUCE_NAMESPACE
  48779. GroupComponent::GroupComponent (const String& componentName,
  48780. const String& labelText)
  48781. : Component (componentName),
  48782. text (labelText),
  48783. justification (Justification::left)
  48784. {
  48785. setInterceptsMouseClicks (false, true);
  48786. }
  48787. GroupComponent::~GroupComponent()
  48788. {
  48789. }
  48790. void GroupComponent::setText (const String& newText) throw()
  48791. {
  48792. if (text != newText)
  48793. {
  48794. text = newText;
  48795. repaint();
  48796. }
  48797. }
  48798. const String GroupComponent::getText() const throw()
  48799. {
  48800. return text;
  48801. }
  48802. void GroupComponent::setTextLabelPosition (const Justification& newJustification)
  48803. {
  48804. if (justification.getFlags() != newJustification.getFlags())
  48805. {
  48806. justification = newJustification;
  48807. repaint();
  48808. }
  48809. }
  48810. void GroupComponent::paint (Graphics& g)
  48811. {
  48812. getLookAndFeel()
  48813. .drawGroupComponentOutline (g, getWidth(), getHeight(),
  48814. text, justification,
  48815. *this);
  48816. }
  48817. void GroupComponent::enablementChanged()
  48818. {
  48819. repaint();
  48820. }
  48821. void GroupComponent::colourChanged()
  48822. {
  48823. repaint();
  48824. }
  48825. END_JUCE_NAMESPACE
  48826. /*** End of inlined file: juce_GroupComponent.cpp ***/
  48827. /*** Start of inlined file: juce_MultiDocumentPanel.cpp ***/
  48828. BEGIN_JUCE_NAMESPACE
  48829. MultiDocumentPanelWindow::MultiDocumentPanelWindow (const Colour& backgroundColour)
  48830. : DocumentWindow (String::empty, backgroundColour,
  48831. DocumentWindow::maximiseButton | DocumentWindow::closeButton, false)
  48832. {
  48833. }
  48834. MultiDocumentPanelWindow::~MultiDocumentPanelWindow()
  48835. {
  48836. }
  48837. void MultiDocumentPanelWindow::maximiseButtonPressed()
  48838. {
  48839. MultiDocumentPanel* const owner = getOwner();
  48840. jassert (owner != 0); // these windows are only designed to be used inside a MultiDocumentPanel!
  48841. if (owner != 0)
  48842. owner->setLayoutMode (MultiDocumentPanel::MaximisedWindowsWithTabs);
  48843. }
  48844. void MultiDocumentPanelWindow::closeButtonPressed()
  48845. {
  48846. MultiDocumentPanel* const owner = getOwner();
  48847. jassert (owner != 0); // these windows are only designed to be used inside a MultiDocumentPanel!
  48848. if (owner != 0)
  48849. owner->closeDocument (getContentComponent(), true);
  48850. }
  48851. void MultiDocumentPanelWindow::activeWindowStatusChanged()
  48852. {
  48853. DocumentWindow::activeWindowStatusChanged();
  48854. updateOrder();
  48855. }
  48856. void MultiDocumentPanelWindow::broughtToFront()
  48857. {
  48858. DocumentWindow::broughtToFront();
  48859. updateOrder();
  48860. }
  48861. void MultiDocumentPanelWindow::updateOrder()
  48862. {
  48863. MultiDocumentPanel* const owner = getOwner();
  48864. if (owner != 0)
  48865. owner->updateOrder();
  48866. }
  48867. MultiDocumentPanel* MultiDocumentPanelWindow::getOwner() const throw()
  48868. {
  48869. // (unable to use the syntax findParentComponentOfClass <MultiDocumentPanel> () because of a VC6 compiler bug)
  48870. return findParentComponentOfClass ((MultiDocumentPanel*) 0);
  48871. }
  48872. class MDITabbedComponentInternal : public TabbedComponent
  48873. {
  48874. public:
  48875. MDITabbedComponentInternal()
  48876. : TabbedComponent (TabbedButtonBar::TabsAtTop)
  48877. {
  48878. }
  48879. ~MDITabbedComponentInternal()
  48880. {
  48881. }
  48882. void currentTabChanged (const int, const String&)
  48883. {
  48884. // (unable to use the syntax findParentComponentOfClass <MultiDocumentPanel> () because of a VC6 compiler bug)
  48885. MultiDocumentPanel* const owner = findParentComponentOfClass ((MultiDocumentPanel*) 0);
  48886. if (owner != 0)
  48887. owner->updateOrder();
  48888. }
  48889. };
  48890. MultiDocumentPanel::MultiDocumentPanel()
  48891. : mode (MaximisedWindowsWithTabs),
  48892. tabComponent (0),
  48893. backgroundColour (Colours::lightblue),
  48894. maximumNumDocuments (0),
  48895. numDocsBeforeTabsUsed (0)
  48896. {
  48897. setOpaque (true);
  48898. }
  48899. MultiDocumentPanel::~MultiDocumentPanel()
  48900. {
  48901. closeAllDocuments (false);
  48902. }
  48903. static bool shouldDeleteComp (Component* const c)
  48904. {
  48905. return c->getProperties() ["mdiDocumentDelete_"];
  48906. }
  48907. bool MultiDocumentPanel::closeAllDocuments (const bool checkItsOkToCloseFirst)
  48908. {
  48909. while (components.size() > 0)
  48910. if (! closeDocument (components.getLast(), checkItsOkToCloseFirst))
  48911. return false;
  48912. return true;
  48913. }
  48914. MultiDocumentPanelWindow* MultiDocumentPanel::createNewDocumentWindow()
  48915. {
  48916. return new MultiDocumentPanelWindow (backgroundColour);
  48917. }
  48918. void MultiDocumentPanel::addWindow (Component* component)
  48919. {
  48920. MultiDocumentPanelWindow* const dw = createNewDocumentWindow();
  48921. dw->setResizable (true, false);
  48922. dw->setContentComponent (component, false, true);
  48923. dw->setName (component->getName());
  48924. const var bkg (component->getProperties() ["mdiDocumentBkg_"]);
  48925. dw->setBackgroundColour (bkg.isVoid() ? backgroundColour : Colour ((int) bkg));
  48926. int x = 4;
  48927. Component* const topComp = getChildComponent (getNumChildComponents() - 1);
  48928. if (topComp != 0 && topComp->getX() == x && topComp->getY() == x)
  48929. x += 16;
  48930. dw->setTopLeftPosition (x, x);
  48931. const var pos (component->getProperties() ["mdiDocumentPos_"]);
  48932. if (pos.toString().isNotEmpty())
  48933. dw->restoreWindowStateFromString (pos.toString());
  48934. addAndMakeVisible (dw);
  48935. dw->toFront (true);
  48936. }
  48937. bool MultiDocumentPanel::addDocument (Component* const component,
  48938. const Colour& docColour,
  48939. const bool deleteWhenRemoved)
  48940. {
  48941. // If you try passing a full DocumentWindow or ResizableWindow in here, you'll end up
  48942. // with a frame-within-a-frame! Just pass in the bare content component.
  48943. jassert (dynamic_cast <ResizableWindow*> (component) == 0);
  48944. if (component == 0 || (maximumNumDocuments > 0 && components.size() >= maximumNumDocuments))
  48945. return false;
  48946. components.add (component);
  48947. component->getProperties().set ("mdiDocumentDelete_", deleteWhenRemoved);
  48948. component->getProperties().set ("mdiDocumentBkg_", (int) docColour.getARGB());
  48949. component->addComponentListener (this);
  48950. if (mode == FloatingWindows)
  48951. {
  48952. if (isFullscreenWhenOneDocument())
  48953. {
  48954. if (components.size() == 1)
  48955. {
  48956. addAndMakeVisible (component);
  48957. }
  48958. else
  48959. {
  48960. if (components.size() == 2)
  48961. addWindow (components.getFirst());
  48962. addWindow (component);
  48963. }
  48964. }
  48965. else
  48966. {
  48967. addWindow (component);
  48968. }
  48969. }
  48970. else
  48971. {
  48972. if (tabComponent == 0 && components.size() > numDocsBeforeTabsUsed)
  48973. {
  48974. addAndMakeVisible (tabComponent = new MDITabbedComponentInternal());
  48975. Array <Component*> temp (components);
  48976. for (int i = 0; i < temp.size(); ++i)
  48977. tabComponent->addTab (temp[i]->getName(), docColour, temp[i], false);
  48978. resized();
  48979. }
  48980. else
  48981. {
  48982. if (tabComponent != 0)
  48983. tabComponent->addTab (component->getName(), docColour, component, false);
  48984. else
  48985. addAndMakeVisible (component);
  48986. }
  48987. setActiveDocument (component);
  48988. }
  48989. resized();
  48990. activeDocumentChanged();
  48991. return true;
  48992. }
  48993. bool MultiDocumentPanel::closeDocument (Component* component,
  48994. const bool checkItsOkToCloseFirst)
  48995. {
  48996. if (components.contains (component))
  48997. {
  48998. if (checkItsOkToCloseFirst && ! tryToCloseDocument (component))
  48999. return false;
  49000. component->removeComponentListener (this);
  49001. const bool shouldDelete = shouldDeleteComp (component);
  49002. component->getProperties().remove ("mdiDocumentDelete_");
  49003. component->getProperties().remove ("mdiDocumentBkg_");
  49004. if (mode == FloatingWindows)
  49005. {
  49006. for (int i = getNumChildComponents(); --i >= 0;)
  49007. {
  49008. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49009. if (dw != 0 && dw->getContentComponent() == component)
  49010. {
  49011. dw->setContentComponent (0, false);
  49012. delete dw;
  49013. break;
  49014. }
  49015. }
  49016. if (shouldDelete)
  49017. delete component;
  49018. components.removeValue (component);
  49019. if (isFullscreenWhenOneDocument() && components.size() == 1)
  49020. {
  49021. for (int i = getNumChildComponents(); --i >= 0;)
  49022. {
  49023. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49024. if (dw != 0)
  49025. {
  49026. dw->setContentComponent (0, false);
  49027. delete dw;
  49028. }
  49029. }
  49030. addAndMakeVisible (components.getFirst());
  49031. }
  49032. }
  49033. else
  49034. {
  49035. jassert (components.indexOf (component) >= 0);
  49036. if (tabComponent != 0)
  49037. {
  49038. for (int i = tabComponent->getNumTabs(); --i >= 0;)
  49039. if (tabComponent->getTabContentComponent (i) == component)
  49040. tabComponent->removeTab (i);
  49041. }
  49042. else
  49043. {
  49044. removeChildComponent (component);
  49045. }
  49046. if (shouldDelete)
  49047. delete component;
  49048. if (tabComponent != 0 && tabComponent->getNumTabs() <= numDocsBeforeTabsUsed)
  49049. deleteAndZero (tabComponent);
  49050. components.removeValue (component);
  49051. if (components.size() > 0 && tabComponent == 0)
  49052. addAndMakeVisible (components.getFirst());
  49053. }
  49054. resized();
  49055. activeDocumentChanged();
  49056. }
  49057. else
  49058. {
  49059. jassertfalse
  49060. }
  49061. return true;
  49062. }
  49063. int MultiDocumentPanel::getNumDocuments() const throw()
  49064. {
  49065. return components.size();
  49066. }
  49067. Component* MultiDocumentPanel::getDocument (const int index) const throw()
  49068. {
  49069. return components [index];
  49070. }
  49071. Component* MultiDocumentPanel::getActiveDocument() const throw()
  49072. {
  49073. if (mode == FloatingWindows)
  49074. {
  49075. for (int i = getNumChildComponents(); --i >= 0;)
  49076. {
  49077. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49078. if (dw != 0 && dw->isActiveWindow())
  49079. return dw->getContentComponent();
  49080. }
  49081. }
  49082. return components.getLast();
  49083. }
  49084. void MultiDocumentPanel::setActiveDocument (Component* component)
  49085. {
  49086. if (mode == FloatingWindows)
  49087. {
  49088. component = getContainerComp (component);
  49089. if (component != 0)
  49090. component->toFront (true);
  49091. }
  49092. else if (tabComponent != 0)
  49093. {
  49094. jassert (components.indexOf (component) >= 0);
  49095. for (int i = tabComponent->getNumTabs(); --i >= 0;)
  49096. {
  49097. if (tabComponent->getTabContentComponent (i) == component)
  49098. {
  49099. tabComponent->setCurrentTabIndex (i);
  49100. break;
  49101. }
  49102. }
  49103. }
  49104. else
  49105. {
  49106. component->grabKeyboardFocus();
  49107. }
  49108. }
  49109. void MultiDocumentPanel::activeDocumentChanged()
  49110. {
  49111. }
  49112. void MultiDocumentPanel::setMaximumNumDocuments (const int newNumber)
  49113. {
  49114. maximumNumDocuments = newNumber;
  49115. }
  49116. void MultiDocumentPanel::useFullscreenWhenOneDocument (const bool shouldUseTabs)
  49117. {
  49118. numDocsBeforeTabsUsed = shouldUseTabs ? 1 : 0;
  49119. }
  49120. bool MultiDocumentPanel::isFullscreenWhenOneDocument() const throw()
  49121. {
  49122. return numDocsBeforeTabsUsed != 0;
  49123. }
  49124. void MultiDocumentPanel::setLayoutMode (const LayoutMode newLayoutMode)
  49125. {
  49126. if (mode != newLayoutMode)
  49127. {
  49128. mode = newLayoutMode;
  49129. if (mode == FloatingWindows)
  49130. {
  49131. deleteAndZero (tabComponent);
  49132. }
  49133. else
  49134. {
  49135. for (int i = getNumChildComponents(); --i >= 0;)
  49136. {
  49137. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49138. if (dw != 0)
  49139. {
  49140. dw->getContentComponent()->getProperties().set ("mdiDocumentPos_", dw->getWindowStateAsString());
  49141. dw->setContentComponent (0, false);
  49142. delete dw;
  49143. }
  49144. }
  49145. }
  49146. resized();
  49147. const Array <Component*> tempComps (components);
  49148. components.clear();
  49149. for (int i = 0; i < tempComps.size(); ++i)
  49150. {
  49151. Component* const c = tempComps.getUnchecked(i);
  49152. addDocument (c,
  49153. Colour ((int) c->getProperties().getWithDefault ("mdiDocumentBkg_", (int) Colours::white.getARGB())),
  49154. shouldDeleteComp (c));
  49155. }
  49156. }
  49157. }
  49158. void MultiDocumentPanel::setBackgroundColour (const Colour& newBackgroundColour)
  49159. {
  49160. if (backgroundColour != newBackgroundColour)
  49161. {
  49162. backgroundColour = newBackgroundColour;
  49163. setOpaque (newBackgroundColour.isOpaque());
  49164. repaint();
  49165. }
  49166. }
  49167. void MultiDocumentPanel::paint (Graphics& g)
  49168. {
  49169. g.fillAll (backgroundColour);
  49170. }
  49171. void MultiDocumentPanel::resized()
  49172. {
  49173. if (mode == MaximisedWindowsWithTabs || components.size() == numDocsBeforeTabsUsed)
  49174. {
  49175. for (int i = getNumChildComponents(); --i >= 0;)
  49176. getChildComponent (i)->setBounds (0, 0, getWidth(), getHeight());
  49177. }
  49178. setWantsKeyboardFocus (components.size() == 0);
  49179. }
  49180. Component* MultiDocumentPanel::getContainerComp (Component* c) const
  49181. {
  49182. if (mode == FloatingWindows)
  49183. {
  49184. for (int i = 0; i < getNumChildComponents(); ++i)
  49185. {
  49186. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49187. if (dw != 0 && dw->getContentComponent() == c)
  49188. {
  49189. c = dw;
  49190. break;
  49191. }
  49192. }
  49193. }
  49194. return c;
  49195. }
  49196. void MultiDocumentPanel::componentNameChanged (Component&)
  49197. {
  49198. if (mode == FloatingWindows)
  49199. {
  49200. for (int i = 0; i < getNumChildComponents(); ++i)
  49201. {
  49202. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49203. if (dw != 0)
  49204. dw->setName (dw->getContentComponent()->getName());
  49205. }
  49206. }
  49207. else if (tabComponent != 0)
  49208. {
  49209. for (int i = tabComponent->getNumTabs(); --i >= 0;)
  49210. tabComponent->setTabName (i, tabComponent->getTabContentComponent (i)->getName());
  49211. }
  49212. }
  49213. void MultiDocumentPanel::updateOrder()
  49214. {
  49215. const Array <Component*> oldList (components);
  49216. if (mode == FloatingWindows)
  49217. {
  49218. components.clear();
  49219. for (int i = 0; i < getNumChildComponents(); ++i)
  49220. {
  49221. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49222. if (dw != 0)
  49223. components.add (dw->getContentComponent());
  49224. }
  49225. }
  49226. else
  49227. {
  49228. if (tabComponent != 0)
  49229. {
  49230. Component* const current = tabComponent->getCurrentContentComponent();
  49231. if (current != 0)
  49232. {
  49233. components.removeValue (current);
  49234. components.add (current);
  49235. }
  49236. }
  49237. }
  49238. if (components != oldList)
  49239. activeDocumentChanged();
  49240. }
  49241. END_JUCE_NAMESPACE
  49242. /*** End of inlined file: juce_MultiDocumentPanel.cpp ***/
  49243. /*** Start of inlined file: juce_ResizableBorderComponent.cpp ***/
  49244. BEGIN_JUCE_NAMESPACE
  49245. enum ResizableBorderComponentZones
  49246. {
  49247. zoneL = 1,
  49248. zoneR = 2,
  49249. zoneT = 4,
  49250. zoneB = 8
  49251. };
  49252. ResizableBorderComponent::ResizableBorderComponent (Component* const componentToResize,
  49253. ComponentBoundsConstrainer* const constrainer_)
  49254. : component (componentToResize),
  49255. constrainer (constrainer_),
  49256. borderSize (5),
  49257. mouseZone (0)
  49258. {
  49259. }
  49260. ResizableBorderComponent::~ResizableBorderComponent()
  49261. {
  49262. }
  49263. void ResizableBorderComponent::paint (Graphics& g)
  49264. {
  49265. getLookAndFeel().drawResizableFrame (g, getWidth(), getHeight(), borderSize);
  49266. }
  49267. void ResizableBorderComponent::mouseEnter (const MouseEvent& e)
  49268. {
  49269. updateMouseZone (e);
  49270. }
  49271. void ResizableBorderComponent::mouseMove (const MouseEvent& e)
  49272. {
  49273. updateMouseZone (e);
  49274. }
  49275. void ResizableBorderComponent::mouseDown (const MouseEvent& e)
  49276. {
  49277. if (component == 0)
  49278. {
  49279. jassertfalse // You've deleted the component that this resizer was supposed to be using!
  49280. return;
  49281. }
  49282. updateMouseZone (e);
  49283. originalBounds = component->getBounds();
  49284. if (constrainer != 0)
  49285. constrainer->resizeStart();
  49286. }
  49287. void ResizableBorderComponent::mouseDrag (const MouseEvent& e)
  49288. {
  49289. if (component == 0)
  49290. {
  49291. jassertfalse // You've deleted the component that this resizer was supposed to be using!
  49292. return;
  49293. }
  49294. Rectangle<int> bounds (originalBounds);
  49295. if ((mouseZone & zoneL) != 0)
  49296. bounds.setLeft (bounds.getX() + e.getDistanceFromDragStartX());
  49297. if ((mouseZone & zoneT) != 0)
  49298. bounds.setTop (bounds.getY() + e.getDistanceFromDragStartY());
  49299. if ((mouseZone & zoneR) != 0)
  49300. bounds.setWidth (bounds.getWidth() + e.getDistanceFromDragStartX());
  49301. if ((mouseZone & zoneB) != 0)
  49302. bounds.setHeight (bounds.getHeight() + e.getDistanceFromDragStartY());
  49303. if (constrainer != 0)
  49304. constrainer->setBoundsForComponent (component, bounds,
  49305. (mouseZone & zoneT) != 0,
  49306. (mouseZone & zoneL) != 0,
  49307. (mouseZone & zoneB) != 0,
  49308. (mouseZone & zoneR) != 0);
  49309. else
  49310. component->setBounds (bounds);
  49311. }
  49312. void ResizableBorderComponent::mouseUp (const MouseEvent&)
  49313. {
  49314. if (constrainer != 0)
  49315. constrainer->resizeEnd();
  49316. }
  49317. bool ResizableBorderComponent::hitTest (int x, int y)
  49318. {
  49319. return x < borderSize.getLeft()
  49320. || x >= getWidth() - borderSize.getRight()
  49321. || y < borderSize.getTop()
  49322. || y >= getHeight() - borderSize.getBottom();
  49323. }
  49324. void ResizableBorderComponent::setBorderThickness (const BorderSize& newBorderSize)
  49325. {
  49326. if (borderSize != newBorderSize)
  49327. {
  49328. borderSize = newBorderSize;
  49329. repaint();
  49330. }
  49331. }
  49332. const BorderSize ResizableBorderComponent::getBorderThickness() const
  49333. {
  49334. return borderSize;
  49335. }
  49336. void ResizableBorderComponent::updateMouseZone (const MouseEvent& e)
  49337. {
  49338. int newZone = 0;
  49339. if (ResizableBorderComponent::hitTest (e.x, e.y))
  49340. {
  49341. if (e.x < jmax (borderSize.getLeft(),
  49342. proportionOfWidth (0.1f),
  49343. jmin (10, proportionOfWidth (0.33f))))
  49344. newZone |= zoneL;
  49345. else if (e.x >= jmin (getWidth() - borderSize.getRight(),
  49346. proportionOfWidth (0.9f),
  49347. getWidth() - jmin (10, proportionOfWidth (0.33f))))
  49348. newZone |= zoneR;
  49349. if (e.y < jmax (borderSize.getTop(),
  49350. proportionOfHeight (0.1f),
  49351. jmin (10, proportionOfHeight (0.33f))))
  49352. newZone |= zoneT;
  49353. else if (e.y >= jmin (getHeight() - borderSize.getBottom(),
  49354. proportionOfHeight (0.9f),
  49355. getHeight() - jmin (10, proportionOfHeight (0.33f))))
  49356. newZone |= zoneB;
  49357. }
  49358. if (mouseZone != newZone)
  49359. {
  49360. mouseZone = newZone;
  49361. MouseCursor::StandardCursorType mc = MouseCursor::NormalCursor;
  49362. switch (newZone)
  49363. {
  49364. case (zoneL | zoneT): mc = MouseCursor::TopLeftCornerResizeCursor; break;
  49365. case zoneT: mc = MouseCursor::TopEdgeResizeCursor; break;
  49366. case (zoneR | zoneT): mc = MouseCursor::TopRightCornerResizeCursor; break;
  49367. case zoneL: mc = MouseCursor::LeftEdgeResizeCursor; break;
  49368. case zoneR: mc = MouseCursor::RightEdgeResizeCursor; break;
  49369. case (zoneL | zoneB): mc = MouseCursor::BottomLeftCornerResizeCursor; break;
  49370. case zoneB: mc = MouseCursor::BottomEdgeResizeCursor; break;
  49371. case (zoneR | zoneB): mc = MouseCursor::BottomRightCornerResizeCursor; break;
  49372. default: break;
  49373. }
  49374. setMouseCursor (mc);
  49375. }
  49376. }
  49377. END_JUCE_NAMESPACE
  49378. /*** End of inlined file: juce_ResizableBorderComponent.cpp ***/
  49379. /*** Start of inlined file: juce_ResizableCornerComponent.cpp ***/
  49380. BEGIN_JUCE_NAMESPACE
  49381. ResizableCornerComponent::ResizableCornerComponent (Component* const componentToResize,
  49382. ComponentBoundsConstrainer* const constrainer_)
  49383. : component (componentToResize),
  49384. constrainer (constrainer_)
  49385. {
  49386. setRepaintsOnMouseActivity (true);
  49387. setMouseCursor (MouseCursor::BottomRightCornerResizeCursor);
  49388. }
  49389. ResizableCornerComponent::~ResizableCornerComponent()
  49390. {
  49391. }
  49392. void ResizableCornerComponent::paint (Graphics& g)
  49393. {
  49394. getLookAndFeel()
  49395. .drawCornerResizer (g, getWidth(), getHeight(),
  49396. isMouseOverOrDragging(),
  49397. isMouseButtonDown());
  49398. }
  49399. void ResizableCornerComponent::mouseDown (const MouseEvent&)
  49400. {
  49401. if (component == 0)
  49402. {
  49403. jassertfalse; // You've deleted the component that this resizer is supposed to be controlling!
  49404. return;
  49405. }
  49406. originalBounds = component->getBounds();
  49407. if (constrainer != 0)
  49408. constrainer->resizeStart();
  49409. }
  49410. void ResizableCornerComponent::mouseDrag (const MouseEvent& e)
  49411. {
  49412. if (component == 0)
  49413. {
  49414. jassertfalse; // You've deleted the component that this resizer is supposed to be controlling!
  49415. return;
  49416. }
  49417. Rectangle<int> r (originalBounds.withSize (originalBounds.getWidth() + e.getDistanceFromDragStartX(),
  49418. originalBounds.getHeight() + e.getDistanceFromDragStartY()));
  49419. if (constrainer != 0)
  49420. constrainer->setBoundsForComponent (component, r, false, false, true, true);
  49421. else
  49422. component->setBounds (r);
  49423. }
  49424. void ResizableCornerComponent::mouseUp (const MouseEvent&)
  49425. {
  49426. if (constrainer != 0)
  49427. constrainer->resizeStart();
  49428. }
  49429. bool ResizableCornerComponent::hitTest (int x, int y)
  49430. {
  49431. if (getWidth() <= 0)
  49432. return false;
  49433. const int yAtX = getHeight() - (getHeight() * x / getWidth());
  49434. return y >= yAtX - getHeight() / 4;
  49435. }
  49436. END_JUCE_NAMESPACE
  49437. /*** End of inlined file: juce_ResizableCornerComponent.cpp ***/
  49438. /*** Start of inlined file: juce_ScrollBar.cpp ***/
  49439. BEGIN_JUCE_NAMESPACE
  49440. class ScrollbarButton : public Button
  49441. {
  49442. public:
  49443. int direction;
  49444. ScrollbarButton (const int direction_,
  49445. ScrollBar& owner_) throw()
  49446. : Button (String::empty),
  49447. direction (direction_),
  49448. owner (owner_)
  49449. {
  49450. setWantsKeyboardFocus (false);
  49451. }
  49452. ~ScrollbarButton()
  49453. {
  49454. }
  49455. void paintButton (Graphics& g,
  49456. bool isMouseOver,
  49457. bool isMouseDown)
  49458. {
  49459. getLookAndFeel()
  49460. .drawScrollbarButton (g, owner,
  49461. getWidth(), getHeight(),
  49462. direction,
  49463. owner.isVertical(),
  49464. isMouseOver, isMouseDown);
  49465. }
  49466. void clicked()
  49467. {
  49468. owner.moveScrollbarInSteps ((direction == 1 || direction == 2) ? 1 : -1);
  49469. }
  49470. juce_UseDebuggingNewOperator
  49471. private:
  49472. ScrollBar& owner;
  49473. ScrollbarButton (const ScrollbarButton&);
  49474. ScrollbarButton& operator= (const ScrollbarButton&);
  49475. };
  49476. ScrollBar::ScrollBar (const bool vertical_,
  49477. const bool buttonsAreVisible)
  49478. : minimum (0.0),
  49479. maximum (1.0),
  49480. rangeStart (0.0),
  49481. rangeSize (0.1),
  49482. singleStepSize (0.1),
  49483. thumbAreaStart (0),
  49484. thumbAreaSize (0),
  49485. thumbStart (0),
  49486. thumbSize (0),
  49487. initialDelayInMillisecs (100),
  49488. repeatDelayInMillisecs (50),
  49489. minimumDelayInMillisecs (10),
  49490. vertical (vertical_),
  49491. isDraggingThumb (false),
  49492. alwaysVisible (false),
  49493. upButton (0),
  49494. downButton (0)
  49495. {
  49496. setButtonVisibility (buttonsAreVisible);
  49497. setRepaintsOnMouseActivity (true);
  49498. setFocusContainer (true);
  49499. }
  49500. ScrollBar::~ScrollBar()
  49501. {
  49502. deleteAllChildren();
  49503. }
  49504. void ScrollBar::setRangeLimits (const double newMinimum,
  49505. const double newMaximum) throw()
  49506. {
  49507. minimum = newMinimum;
  49508. maximum = newMaximum;
  49509. jassert (maximum >= minimum); // these can't be the wrong way round!
  49510. setCurrentRangeStart (rangeStart);
  49511. updateThumbPosition();
  49512. }
  49513. void ScrollBar::setCurrentRange (double newStart,
  49514. double newSize) throw()
  49515. {
  49516. newSize = jlimit (0.0, maximum - minimum, newSize);
  49517. newStart = jlimit (minimum, maximum - newSize, newStart);
  49518. if (rangeStart != newStart
  49519. || rangeSize != newSize)
  49520. {
  49521. rangeStart = newStart;
  49522. rangeSize = newSize;
  49523. updateThumbPosition();
  49524. triggerAsyncUpdate();
  49525. }
  49526. }
  49527. void ScrollBar::setCurrentRangeStart (double newStart) throw()
  49528. {
  49529. setCurrentRange (newStart, rangeSize);
  49530. }
  49531. void ScrollBar::setSingleStepSize (const double newSingleStepSize) throw()
  49532. {
  49533. singleStepSize = newSingleStepSize;
  49534. }
  49535. void ScrollBar::moveScrollbarInSteps (const int howManySteps) throw()
  49536. {
  49537. setCurrentRangeStart (rangeStart + howManySteps * singleStepSize);
  49538. }
  49539. void ScrollBar::moveScrollbarInPages (const int howManyPages) throw()
  49540. {
  49541. setCurrentRangeStart (rangeStart + howManyPages * rangeSize);
  49542. }
  49543. void ScrollBar::scrollToTop() throw()
  49544. {
  49545. setCurrentRangeStart (minimum);
  49546. }
  49547. void ScrollBar::scrollToBottom() throw()
  49548. {
  49549. setCurrentRangeStart (maximum - rangeSize);
  49550. }
  49551. void ScrollBar::setButtonRepeatSpeed (const int initialDelayInMillisecs_,
  49552. const int repeatDelayInMillisecs_,
  49553. const int minimumDelayInMillisecs_) throw()
  49554. {
  49555. initialDelayInMillisecs = initialDelayInMillisecs_;
  49556. repeatDelayInMillisecs = repeatDelayInMillisecs_;
  49557. minimumDelayInMillisecs = minimumDelayInMillisecs_;
  49558. if (upButton != 0)
  49559. {
  49560. upButton->setRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
  49561. downButton->setRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
  49562. }
  49563. }
  49564. void ScrollBar::addListener (ScrollBarListener* const listener) throw()
  49565. {
  49566. listeners.add (listener);
  49567. }
  49568. void ScrollBar::removeListener (ScrollBarListener* const listener) throw()
  49569. {
  49570. listeners.remove (listener);
  49571. }
  49572. void ScrollBar::handleAsyncUpdate()
  49573. {
  49574. listeners.call (&ScrollBarListener::scrollBarMoved, this, rangeStart);
  49575. }
  49576. void ScrollBar::updateThumbPosition() throw()
  49577. {
  49578. int newThumbSize = roundToInt ((maximum > minimum) ? (rangeSize * thumbAreaSize) / (maximum - minimum)
  49579. : thumbAreaSize);
  49580. if (newThumbSize < getLookAndFeel().getMinimumScrollbarThumbSize (*this))
  49581. newThumbSize = jmin (getLookAndFeel().getMinimumScrollbarThumbSize (*this), thumbAreaSize - 1);
  49582. if (newThumbSize > thumbAreaSize)
  49583. newThumbSize = thumbAreaSize;
  49584. int newThumbStart = thumbAreaStart;
  49585. if (maximum - minimum > rangeSize)
  49586. newThumbStart += roundToInt (((rangeStart - minimum) * (thumbAreaSize - newThumbSize))
  49587. / ((maximum - minimum) - rangeSize));
  49588. setVisible (alwaysVisible || (maximum - minimum > rangeSize && rangeSize > 0.0));
  49589. if (thumbStart != newThumbStart || thumbSize != newThumbSize)
  49590. {
  49591. const int repaintStart = jmin (thumbStart, newThumbStart) - 4;
  49592. const int repaintSize = jmax (thumbStart + thumbSize, newThumbStart + newThumbSize) + 8 - repaintStart;
  49593. if (vertical)
  49594. repaint (0, repaintStart, getWidth(), repaintSize);
  49595. else
  49596. repaint (repaintStart, 0, repaintSize, getHeight());
  49597. thumbStart = newThumbStart;
  49598. thumbSize = newThumbSize;
  49599. }
  49600. }
  49601. void ScrollBar::setOrientation (const bool shouldBeVertical) throw()
  49602. {
  49603. if (vertical != shouldBeVertical)
  49604. {
  49605. vertical = shouldBeVertical;
  49606. if (upButton != 0)
  49607. {
  49608. ((ScrollbarButton*) upButton)->direction = (vertical) ? 0 : 3;
  49609. ((ScrollbarButton*) downButton)->direction = (vertical) ? 2 : 1;
  49610. }
  49611. updateThumbPosition();
  49612. }
  49613. }
  49614. void ScrollBar::setButtonVisibility (const bool buttonsAreVisible)
  49615. {
  49616. deleteAndZero (upButton);
  49617. deleteAndZero (downButton);
  49618. if (buttonsAreVisible)
  49619. {
  49620. addAndMakeVisible (upButton = new ScrollbarButton ((vertical) ? 0 : 3, *this));
  49621. addAndMakeVisible (downButton = new ScrollbarButton ((vertical) ? 2 : 1, *this));
  49622. setButtonRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
  49623. }
  49624. updateThumbPosition();
  49625. }
  49626. void ScrollBar::setAutoHide (const bool shouldHideWhenFullRange)
  49627. {
  49628. alwaysVisible = ! shouldHideWhenFullRange;
  49629. updateThumbPosition();
  49630. }
  49631. void ScrollBar::paint (Graphics& g)
  49632. {
  49633. if (thumbAreaSize > 0)
  49634. {
  49635. LookAndFeel& lf = getLookAndFeel();
  49636. const int thumb = (thumbAreaSize > lf.getMinimumScrollbarThumbSize (*this))
  49637. ? thumbSize : 0;
  49638. if (vertical)
  49639. {
  49640. lf.drawScrollbar (g, *this,
  49641. 0, thumbAreaStart,
  49642. getWidth(), thumbAreaSize,
  49643. vertical,
  49644. thumbStart, thumb,
  49645. isMouseOver(), isMouseButtonDown());
  49646. }
  49647. else
  49648. {
  49649. lf.drawScrollbar (g, *this,
  49650. thumbAreaStart, 0,
  49651. thumbAreaSize, getHeight(),
  49652. vertical,
  49653. thumbStart, thumb,
  49654. isMouseOver(), isMouseButtonDown());
  49655. }
  49656. }
  49657. }
  49658. void ScrollBar::lookAndFeelChanged()
  49659. {
  49660. setComponentEffect (getLookAndFeel().getScrollbarEffect());
  49661. }
  49662. void ScrollBar::resized()
  49663. {
  49664. const int length = ((vertical) ? getHeight() : getWidth());
  49665. const int buttonSize = (upButton != 0) ? jmin (getLookAndFeel().getScrollbarButtonSize (*this), (length >> 1))
  49666. : 0;
  49667. if (length < 32 + getLookAndFeel().getMinimumScrollbarThumbSize (*this))
  49668. {
  49669. thumbAreaStart = length >> 1;
  49670. thumbAreaSize = 0;
  49671. }
  49672. else
  49673. {
  49674. thumbAreaStart = buttonSize;
  49675. thumbAreaSize = length - (buttonSize << 1);
  49676. }
  49677. if (upButton != 0)
  49678. {
  49679. if (vertical)
  49680. {
  49681. upButton->setBounds (0, 0, getWidth(), buttonSize);
  49682. downButton->setBounds (0, thumbAreaStart + thumbAreaSize, getWidth(), buttonSize);
  49683. }
  49684. else
  49685. {
  49686. upButton->setBounds (0, 0, buttonSize, getHeight());
  49687. downButton->setBounds (thumbAreaStart + thumbAreaSize, 0, buttonSize, getHeight());
  49688. }
  49689. }
  49690. updateThumbPosition();
  49691. }
  49692. void ScrollBar::mouseDown (const MouseEvent& e)
  49693. {
  49694. isDraggingThumb = false;
  49695. lastMousePos = vertical ? e.y : e.x;
  49696. dragStartMousePos = lastMousePos;
  49697. dragStartRange = rangeStart;
  49698. if (dragStartMousePos < thumbStart)
  49699. {
  49700. moveScrollbarInPages (-1);
  49701. startTimer (400);
  49702. }
  49703. else if (dragStartMousePos >= thumbStart + thumbSize)
  49704. {
  49705. moveScrollbarInPages (1);
  49706. startTimer (400);
  49707. }
  49708. else
  49709. {
  49710. isDraggingThumb = (thumbAreaSize > getLookAndFeel().getMinimumScrollbarThumbSize (*this))
  49711. && (thumbAreaSize > thumbSize);
  49712. }
  49713. }
  49714. void ScrollBar::mouseDrag (const MouseEvent& e)
  49715. {
  49716. if (isDraggingThumb)
  49717. {
  49718. const int deltaPixels = ((vertical) ? e.y : e.x) - dragStartMousePos;
  49719. setCurrentRangeStart (dragStartRange
  49720. + deltaPixels * ((maximum - minimum) - rangeSize)
  49721. / (thumbAreaSize - thumbSize));
  49722. }
  49723. else
  49724. {
  49725. lastMousePos = (vertical) ? e.y : e.x;
  49726. }
  49727. }
  49728. void ScrollBar::mouseUp (const MouseEvent&)
  49729. {
  49730. isDraggingThumb = false;
  49731. stopTimer();
  49732. repaint();
  49733. }
  49734. void ScrollBar::mouseWheelMove (const MouseEvent&,
  49735. float wheelIncrementX,
  49736. float wheelIncrementY)
  49737. {
  49738. float increment = vertical ? wheelIncrementY : wheelIncrementX;
  49739. if (increment < 0)
  49740. increment = jmin (increment * 10.0f, -1.0f);
  49741. else if (increment > 0)
  49742. increment = jmax (increment * 10.0f, 1.0f);
  49743. setCurrentRangeStart (rangeStart - singleStepSize * increment);
  49744. }
  49745. void ScrollBar::timerCallback()
  49746. {
  49747. if (isMouseButtonDown())
  49748. {
  49749. startTimer (40);
  49750. if (lastMousePos < thumbStart)
  49751. setCurrentRangeStart (rangeStart - rangeSize);
  49752. else if (lastMousePos > thumbStart + thumbSize)
  49753. setCurrentRangeStart (rangeStart + rangeSize);
  49754. }
  49755. else
  49756. {
  49757. stopTimer();
  49758. }
  49759. }
  49760. bool ScrollBar::keyPressed (const KeyPress& key)
  49761. {
  49762. if (! isVisible())
  49763. return false;
  49764. if (key.isKeyCode (KeyPress::upKey) || key.isKeyCode (KeyPress::leftKey))
  49765. moveScrollbarInSteps (-1);
  49766. else if (key.isKeyCode (KeyPress::downKey) || key.isKeyCode (KeyPress::rightKey))
  49767. moveScrollbarInSteps (1);
  49768. else if (key.isKeyCode (KeyPress::pageUpKey))
  49769. moveScrollbarInPages (-1);
  49770. else if (key.isKeyCode (KeyPress::pageDownKey))
  49771. moveScrollbarInPages (1);
  49772. else if (key.isKeyCode (KeyPress::homeKey))
  49773. scrollToTop();
  49774. else if (key.isKeyCode (KeyPress::endKey))
  49775. scrollToBottom();
  49776. else
  49777. return false;
  49778. return true;
  49779. }
  49780. END_JUCE_NAMESPACE
  49781. /*** End of inlined file: juce_ScrollBar.cpp ***/
  49782. /*** Start of inlined file: juce_StretchableLayoutManager.cpp ***/
  49783. BEGIN_JUCE_NAMESPACE
  49784. StretchableLayoutManager::StretchableLayoutManager()
  49785. : totalSize (0)
  49786. {
  49787. }
  49788. StretchableLayoutManager::~StretchableLayoutManager()
  49789. {
  49790. }
  49791. void StretchableLayoutManager::clearAllItems()
  49792. {
  49793. items.clear();
  49794. totalSize = 0;
  49795. }
  49796. void StretchableLayoutManager::setItemLayout (const int itemIndex,
  49797. const double minimumSize,
  49798. const double maximumSize,
  49799. const double preferredSize)
  49800. {
  49801. ItemLayoutProperties* layout = getInfoFor (itemIndex);
  49802. if (layout == 0)
  49803. {
  49804. layout = new ItemLayoutProperties();
  49805. layout->itemIndex = itemIndex;
  49806. int i;
  49807. for (i = 0; i < items.size(); ++i)
  49808. if (items.getUnchecked (i)->itemIndex > itemIndex)
  49809. break;
  49810. items.insert (i, layout);
  49811. }
  49812. layout->minSize = minimumSize;
  49813. layout->maxSize = maximumSize;
  49814. layout->preferredSize = preferredSize;
  49815. layout->currentSize = 0;
  49816. }
  49817. bool StretchableLayoutManager::getItemLayout (const int itemIndex,
  49818. double& minimumSize,
  49819. double& maximumSize,
  49820. double& preferredSize) const
  49821. {
  49822. const ItemLayoutProperties* const layout = getInfoFor (itemIndex);
  49823. if (layout != 0)
  49824. {
  49825. minimumSize = layout->minSize;
  49826. maximumSize = layout->maxSize;
  49827. preferredSize = layout->preferredSize;
  49828. return true;
  49829. }
  49830. return false;
  49831. }
  49832. void StretchableLayoutManager::setTotalSize (const int newTotalSize)
  49833. {
  49834. totalSize = newTotalSize;
  49835. fitComponentsIntoSpace (0, items.size(), totalSize, 0);
  49836. }
  49837. int StretchableLayoutManager::getItemCurrentPosition (const int itemIndex) const
  49838. {
  49839. int pos = 0;
  49840. for (int i = 0; i < itemIndex; ++i)
  49841. {
  49842. const ItemLayoutProperties* const layout = getInfoFor (i);
  49843. if (layout != 0)
  49844. pos += layout->currentSize;
  49845. }
  49846. return pos;
  49847. }
  49848. int StretchableLayoutManager::getItemCurrentAbsoluteSize (const int itemIndex) const
  49849. {
  49850. const ItemLayoutProperties* const layout = getInfoFor (itemIndex);
  49851. if (layout != 0)
  49852. return layout->currentSize;
  49853. return 0;
  49854. }
  49855. double StretchableLayoutManager::getItemCurrentRelativeSize (const int itemIndex) const
  49856. {
  49857. const ItemLayoutProperties* const layout = getInfoFor (itemIndex);
  49858. if (layout != 0)
  49859. return -layout->currentSize / (double) totalSize;
  49860. return 0;
  49861. }
  49862. void StretchableLayoutManager::setItemPosition (const int itemIndex,
  49863. int newPosition)
  49864. {
  49865. for (int i = items.size(); --i >= 0;)
  49866. {
  49867. const ItemLayoutProperties* const layout = items.getUnchecked(i);
  49868. if (layout->itemIndex == itemIndex)
  49869. {
  49870. int realTotalSize = jmax (totalSize, getMinimumSizeOfItems (0, items.size()));
  49871. const int minSizeAfterThisComp = getMinimumSizeOfItems (i, items.size());
  49872. const int maxSizeAfterThisComp = getMaximumSizeOfItems (i + 1, items.size());
  49873. newPosition = jmax (newPosition, totalSize - maxSizeAfterThisComp - layout->currentSize);
  49874. newPosition = jmin (newPosition, realTotalSize - minSizeAfterThisComp);
  49875. int endPos = fitComponentsIntoSpace (0, i, newPosition, 0);
  49876. endPos += layout->currentSize;
  49877. fitComponentsIntoSpace (i + 1, items.size(), totalSize - endPos, endPos);
  49878. updatePrefSizesToMatchCurrentPositions();
  49879. break;
  49880. }
  49881. }
  49882. }
  49883. void StretchableLayoutManager::layOutComponents (Component** const components,
  49884. int numComponents,
  49885. int x, int y, int w, int h,
  49886. const bool vertically,
  49887. const bool resizeOtherDimension)
  49888. {
  49889. setTotalSize (vertically ? h : w);
  49890. int pos = vertically ? y : x;
  49891. for (int i = 0; i < numComponents; ++i)
  49892. {
  49893. const ItemLayoutProperties* const layout = getInfoFor (i);
  49894. if (layout != 0)
  49895. {
  49896. Component* const c = components[i];
  49897. if (c != 0)
  49898. {
  49899. if (i == numComponents - 1)
  49900. {
  49901. // if it's the last item, crop it to exactly fit the available space..
  49902. if (resizeOtherDimension)
  49903. {
  49904. if (vertically)
  49905. c->setBounds (x, pos, w, jmax (layout->currentSize, h - pos));
  49906. else
  49907. c->setBounds (pos, y, jmax (layout->currentSize, w - pos), h);
  49908. }
  49909. else
  49910. {
  49911. if (vertically)
  49912. c->setBounds (c->getX(), pos, c->getWidth(), jmax (layout->currentSize, h - pos));
  49913. else
  49914. c->setBounds (pos, c->getY(), jmax (layout->currentSize, w - pos), c->getHeight());
  49915. }
  49916. }
  49917. else
  49918. {
  49919. if (resizeOtherDimension)
  49920. {
  49921. if (vertically)
  49922. c->setBounds (x, pos, w, layout->currentSize);
  49923. else
  49924. c->setBounds (pos, y, layout->currentSize, h);
  49925. }
  49926. else
  49927. {
  49928. if (vertically)
  49929. c->setBounds (c->getX(), pos, c->getWidth(), layout->currentSize);
  49930. else
  49931. c->setBounds (pos, c->getY(), layout->currentSize, c->getHeight());
  49932. }
  49933. }
  49934. }
  49935. pos += layout->currentSize;
  49936. }
  49937. }
  49938. }
  49939. StretchableLayoutManager::ItemLayoutProperties* StretchableLayoutManager::getInfoFor (const int itemIndex) const
  49940. {
  49941. for (int i = items.size(); --i >= 0;)
  49942. if (items.getUnchecked(i)->itemIndex == itemIndex)
  49943. return items.getUnchecked(i);
  49944. return 0;
  49945. }
  49946. int StretchableLayoutManager::fitComponentsIntoSpace (const int startIndex,
  49947. const int endIndex,
  49948. const int availableSpace,
  49949. int startPos)
  49950. {
  49951. // calculate the total sizes
  49952. int i;
  49953. double totalIdealSize = 0.0;
  49954. int totalMinimums = 0;
  49955. for (i = startIndex; i < endIndex; ++i)
  49956. {
  49957. ItemLayoutProperties* const layout = items.getUnchecked (i);
  49958. layout->currentSize = sizeToRealSize (layout->minSize, totalSize);
  49959. totalMinimums += layout->currentSize;
  49960. totalIdealSize += sizeToRealSize (layout->preferredSize, availableSpace);
  49961. }
  49962. if (totalIdealSize <= 0)
  49963. totalIdealSize = 1.0;
  49964. // now calc the best sizes..
  49965. int extraSpace = availableSpace - totalMinimums;
  49966. while (extraSpace > 0)
  49967. {
  49968. int numWantingMoreSpace = 0;
  49969. int numHavingTakenExtraSpace = 0;
  49970. // first figure out how many comps want a slice of the extra space..
  49971. for (i = startIndex; i < endIndex; ++i)
  49972. {
  49973. ItemLayoutProperties* const layout = items.getUnchecked (i);
  49974. double sizeWanted = sizeToRealSize (layout->preferredSize, availableSpace);
  49975. const int bestSize = jlimit (layout->currentSize,
  49976. jmax (layout->currentSize,
  49977. sizeToRealSize (layout->maxSize, totalSize)),
  49978. roundToInt (sizeWanted * availableSpace / totalIdealSize));
  49979. if (bestSize > layout->currentSize)
  49980. ++numWantingMoreSpace;
  49981. }
  49982. // ..share out the extra space..
  49983. for (i = startIndex; i < endIndex; ++i)
  49984. {
  49985. ItemLayoutProperties* const layout = items.getUnchecked (i);
  49986. double sizeWanted = sizeToRealSize (layout->preferredSize, availableSpace);
  49987. int bestSize = jlimit (layout->currentSize,
  49988. jmax (layout->currentSize, sizeToRealSize (layout->maxSize, totalSize)),
  49989. roundToInt (sizeWanted * availableSpace / totalIdealSize));
  49990. const int extraWanted = bestSize - layout->currentSize;
  49991. if (extraWanted > 0)
  49992. {
  49993. const int extraAllowed = jmin (extraWanted,
  49994. extraSpace / jmax (1, numWantingMoreSpace));
  49995. if (extraAllowed > 0)
  49996. {
  49997. ++numHavingTakenExtraSpace;
  49998. --numWantingMoreSpace;
  49999. layout->currentSize += extraAllowed;
  50000. extraSpace -= extraAllowed;
  50001. }
  50002. }
  50003. }
  50004. if (numHavingTakenExtraSpace <= 0)
  50005. break;
  50006. }
  50007. // ..and calculate the end position
  50008. for (i = startIndex; i < endIndex; ++i)
  50009. {
  50010. ItemLayoutProperties* const layout = items.getUnchecked(i);
  50011. startPos += layout->currentSize;
  50012. }
  50013. return startPos;
  50014. }
  50015. int StretchableLayoutManager::getMinimumSizeOfItems (const int startIndex,
  50016. const int endIndex) const
  50017. {
  50018. int totalMinimums = 0;
  50019. for (int i = startIndex; i < endIndex; ++i)
  50020. totalMinimums += sizeToRealSize (items.getUnchecked (i)->minSize, totalSize);
  50021. return totalMinimums;
  50022. }
  50023. int StretchableLayoutManager::getMaximumSizeOfItems (const int startIndex, const int endIndex) const
  50024. {
  50025. int totalMaximums = 0;
  50026. for (int i = startIndex; i < endIndex; ++i)
  50027. totalMaximums += sizeToRealSize (items.getUnchecked (i)->maxSize, totalSize);
  50028. return totalMaximums;
  50029. }
  50030. void StretchableLayoutManager::updatePrefSizesToMatchCurrentPositions()
  50031. {
  50032. for (int i = 0; i < items.size(); ++i)
  50033. {
  50034. ItemLayoutProperties* const layout = items.getUnchecked (i);
  50035. layout->preferredSize
  50036. = (layout->preferredSize < 0) ? getItemCurrentRelativeSize (i)
  50037. : getItemCurrentAbsoluteSize (i);
  50038. }
  50039. }
  50040. int StretchableLayoutManager::sizeToRealSize (double size, int totalSpace)
  50041. {
  50042. if (size < 0)
  50043. size *= -totalSpace;
  50044. return roundToInt (size);
  50045. }
  50046. END_JUCE_NAMESPACE
  50047. /*** End of inlined file: juce_StretchableLayoutManager.cpp ***/
  50048. /*** Start of inlined file: juce_StretchableLayoutResizerBar.cpp ***/
  50049. BEGIN_JUCE_NAMESPACE
  50050. StretchableLayoutResizerBar::StretchableLayoutResizerBar (StretchableLayoutManager* layout_,
  50051. const int itemIndex_,
  50052. const bool isVertical_)
  50053. : layout (layout_),
  50054. itemIndex (itemIndex_),
  50055. isVertical (isVertical_)
  50056. {
  50057. setRepaintsOnMouseActivity (true);
  50058. setMouseCursor (MouseCursor (isVertical_ ? MouseCursor::LeftRightResizeCursor
  50059. : MouseCursor::UpDownResizeCursor));
  50060. }
  50061. StretchableLayoutResizerBar::~StretchableLayoutResizerBar()
  50062. {
  50063. }
  50064. void StretchableLayoutResizerBar::paint (Graphics& g)
  50065. {
  50066. getLookAndFeel().drawStretchableLayoutResizerBar (g,
  50067. getWidth(), getHeight(),
  50068. isVertical,
  50069. isMouseOver(),
  50070. isMouseButtonDown());
  50071. }
  50072. void StretchableLayoutResizerBar::mouseDown (const MouseEvent&)
  50073. {
  50074. mouseDownPos = layout->getItemCurrentPosition (itemIndex);
  50075. }
  50076. void StretchableLayoutResizerBar::mouseDrag (const MouseEvent& e)
  50077. {
  50078. const int desiredPos = mouseDownPos + (isVertical ? e.getDistanceFromDragStartX()
  50079. : e.getDistanceFromDragStartY());
  50080. layout->setItemPosition (itemIndex, desiredPos);
  50081. hasBeenMoved();
  50082. }
  50083. void StretchableLayoutResizerBar::hasBeenMoved()
  50084. {
  50085. if (getParentComponent() != 0)
  50086. getParentComponent()->resized();
  50087. }
  50088. END_JUCE_NAMESPACE
  50089. /*** End of inlined file: juce_StretchableLayoutResizerBar.cpp ***/
  50090. /*** Start of inlined file: juce_StretchableObjectResizer.cpp ***/
  50091. BEGIN_JUCE_NAMESPACE
  50092. StretchableObjectResizer::StretchableObjectResizer()
  50093. {
  50094. }
  50095. StretchableObjectResizer::~StretchableObjectResizer()
  50096. {
  50097. }
  50098. void StretchableObjectResizer::addItem (const double size,
  50099. const double minSize, const double maxSize,
  50100. const int order)
  50101. {
  50102. // the order must be >= 0 but less than the maximum integer value.
  50103. jassert (order >= 0 && order < std::numeric_limits<int>::max());
  50104. Item* const item = new Item();
  50105. item->size = size;
  50106. item->minSize = minSize;
  50107. item->maxSize = maxSize;
  50108. item->order = order;
  50109. items.add (item);
  50110. }
  50111. double StretchableObjectResizer::getItemSize (const int index) const throw()
  50112. {
  50113. const Item* const it = items [index];
  50114. return it != 0 ? it->size : 0;
  50115. }
  50116. void StretchableObjectResizer::resizeToFit (const double targetSize)
  50117. {
  50118. int order = 0;
  50119. for (;;)
  50120. {
  50121. double currentSize = 0;
  50122. double minSize = 0;
  50123. double maxSize = 0;
  50124. int nextHighestOrder = std::numeric_limits<int>::max();
  50125. for (int i = 0; i < items.size(); ++i)
  50126. {
  50127. const Item* const it = items.getUnchecked(i);
  50128. currentSize += it->size;
  50129. if (it->order <= order)
  50130. {
  50131. minSize += it->minSize;
  50132. maxSize += it->maxSize;
  50133. }
  50134. else
  50135. {
  50136. minSize += it->size;
  50137. maxSize += it->size;
  50138. nextHighestOrder = jmin (nextHighestOrder, it->order);
  50139. }
  50140. }
  50141. const double thisIterationTarget = jlimit (minSize, maxSize, targetSize);
  50142. if (thisIterationTarget >= currentSize)
  50143. {
  50144. const double availableExtraSpace = maxSize - currentSize;
  50145. const double targetAmountOfExtraSpace = thisIterationTarget - currentSize;
  50146. const double scale = targetAmountOfExtraSpace / availableExtraSpace;
  50147. for (int i = 0; i < items.size(); ++i)
  50148. {
  50149. Item* const it = items.getUnchecked(i);
  50150. if (it->order <= order)
  50151. it->size = jmin (it->maxSize, it->size + (it->maxSize - it->size) * scale);
  50152. }
  50153. }
  50154. else
  50155. {
  50156. const double amountOfSlack = currentSize - minSize;
  50157. const double targetAmountOfSlack = thisIterationTarget - minSize;
  50158. const double scale = targetAmountOfSlack / amountOfSlack;
  50159. for (int i = 0; i < items.size(); ++i)
  50160. {
  50161. Item* const it = items.getUnchecked(i);
  50162. if (it->order <= order)
  50163. it->size = jmax (it->minSize, it->minSize + (it->size - it->minSize) * scale);
  50164. }
  50165. }
  50166. if (nextHighestOrder < std::numeric_limits<int>::max())
  50167. order = nextHighestOrder;
  50168. else
  50169. break;
  50170. }
  50171. }
  50172. END_JUCE_NAMESPACE
  50173. /*** End of inlined file: juce_StretchableObjectResizer.cpp ***/
  50174. /*** Start of inlined file: juce_TabbedButtonBar.cpp ***/
  50175. BEGIN_JUCE_NAMESPACE
  50176. TabBarButton::TabBarButton (const String& name,
  50177. TabbedButtonBar* const owner_,
  50178. const int index)
  50179. : Button (name),
  50180. owner (owner_),
  50181. tabIndex (index),
  50182. overlapPixels (0)
  50183. {
  50184. shadow.setShadowProperties (2.2f, 0.7f, 0, 0);
  50185. setComponentEffect (&shadow);
  50186. setWantsKeyboardFocus (false);
  50187. }
  50188. TabBarButton::~TabBarButton()
  50189. {
  50190. }
  50191. void TabBarButton::paintButton (Graphics& g,
  50192. bool isMouseOverButton,
  50193. bool isButtonDown)
  50194. {
  50195. int x, y, w, h;
  50196. getActiveArea (x, y, w, h);
  50197. g.setOrigin (x, y);
  50198. getLookAndFeel()
  50199. .drawTabButton (g, w, h,
  50200. owner->getTabBackgroundColour (tabIndex),
  50201. tabIndex, getButtonText(), *this,
  50202. owner->getOrientation(),
  50203. isMouseOverButton, isButtonDown,
  50204. getToggleState());
  50205. }
  50206. void TabBarButton::clicked (const ModifierKeys& mods)
  50207. {
  50208. if (mods.isPopupMenu())
  50209. owner->popupMenuClickOnTab (tabIndex, getButtonText());
  50210. else
  50211. owner->setCurrentTabIndex (tabIndex);
  50212. }
  50213. bool TabBarButton::hitTest (int mx, int my)
  50214. {
  50215. int x, y, w, h;
  50216. getActiveArea (x, y, w, h);
  50217. if (owner->getOrientation() == TabbedButtonBar::TabsAtLeft
  50218. || owner->getOrientation() == TabbedButtonBar::TabsAtRight)
  50219. {
  50220. if (((unsigned int) mx) < (unsigned int) getWidth()
  50221. && my >= y + overlapPixels
  50222. && my < y + h - overlapPixels)
  50223. return true;
  50224. }
  50225. else
  50226. {
  50227. if (mx >= x + overlapPixels && mx < x + w - overlapPixels
  50228. && ((unsigned int) my) < (unsigned int) getHeight())
  50229. return true;
  50230. }
  50231. Path p;
  50232. getLookAndFeel()
  50233. .createTabButtonShape (p, w, h, tabIndex, getButtonText(), *this,
  50234. owner->getOrientation(),
  50235. false, false, getToggleState());
  50236. return p.contains ((float) (mx - x),
  50237. (float) (my - y));
  50238. }
  50239. int TabBarButton::getBestTabLength (const int depth)
  50240. {
  50241. return jlimit (depth * 2,
  50242. depth * 7,
  50243. getLookAndFeel().getTabButtonBestWidth (tabIndex, getButtonText(), depth, *this));
  50244. }
  50245. void TabBarButton::getActiveArea (int& x, int& y, int& w, int& h)
  50246. {
  50247. x = 0;
  50248. y = 0;
  50249. int r = getWidth();
  50250. int b = getHeight();
  50251. const int spaceAroundImage = getLookAndFeel().getTabButtonSpaceAroundImage();
  50252. if (owner->getOrientation() != TabbedButtonBar::TabsAtLeft)
  50253. r -= spaceAroundImage;
  50254. if (owner->getOrientation() != TabbedButtonBar::TabsAtRight)
  50255. x += spaceAroundImage;
  50256. if (owner->getOrientation() != TabbedButtonBar::TabsAtBottom)
  50257. y += spaceAroundImage;
  50258. if (owner->getOrientation() != TabbedButtonBar::TabsAtTop)
  50259. b -= spaceAroundImage;
  50260. w = r - x;
  50261. h = b - y;
  50262. }
  50263. class TabAreaBehindFrontButtonComponent : public Component
  50264. {
  50265. public:
  50266. TabAreaBehindFrontButtonComponent (TabbedButtonBar* const owner_)
  50267. : owner (owner_)
  50268. {
  50269. setInterceptsMouseClicks (false, false);
  50270. }
  50271. ~TabAreaBehindFrontButtonComponent()
  50272. {
  50273. }
  50274. void paint (Graphics& g)
  50275. {
  50276. getLookAndFeel()
  50277. .drawTabAreaBehindFrontButton (g, getWidth(), getHeight(),
  50278. *owner, owner->getOrientation());
  50279. }
  50280. void enablementChanged()
  50281. {
  50282. repaint();
  50283. }
  50284. private:
  50285. TabbedButtonBar* const owner;
  50286. TabAreaBehindFrontButtonComponent (const TabAreaBehindFrontButtonComponent&);
  50287. TabAreaBehindFrontButtonComponent& operator= (const TabAreaBehindFrontButtonComponent&);
  50288. };
  50289. TabbedButtonBar::TabbedButtonBar (const Orientation orientation_)
  50290. : orientation (orientation_),
  50291. currentTabIndex (-1),
  50292. extraTabsButton (0)
  50293. {
  50294. setInterceptsMouseClicks (false, true);
  50295. addAndMakeVisible (behindFrontTab = new TabAreaBehindFrontButtonComponent (this));
  50296. setFocusContainer (true);
  50297. }
  50298. TabbedButtonBar::~TabbedButtonBar()
  50299. {
  50300. deleteAllChildren();
  50301. }
  50302. void TabbedButtonBar::setOrientation (const Orientation newOrientation)
  50303. {
  50304. orientation = newOrientation;
  50305. for (int i = getNumChildComponents(); --i >= 0;)
  50306. getChildComponent (i)->resized();
  50307. resized();
  50308. }
  50309. TabBarButton* TabbedButtonBar::createTabButton (const String& name, const int index)
  50310. {
  50311. return new TabBarButton (name, this, index);
  50312. }
  50313. void TabbedButtonBar::clearTabs()
  50314. {
  50315. tabs.clear();
  50316. tabColours.clear();
  50317. currentTabIndex = -1;
  50318. deleteAndZero (extraTabsButton);
  50319. removeChildComponent (behindFrontTab);
  50320. deleteAllChildren();
  50321. addChildComponent (behindFrontTab);
  50322. setCurrentTabIndex (-1);
  50323. }
  50324. void TabbedButtonBar::addTab (const String& tabName,
  50325. const Colour& tabBackgroundColour,
  50326. int insertIndex)
  50327. {
  50328. jassert (tabName.isNotEmpty()); // you have to give them all a name..
  50329. if (tabName.isNotEmpty())
  50330. {
  50331. if (((unsigned int) insertIndex) > (unsigned int) tabs.size())
  50332. insertIndex = tabs.size();
  50333. for (int i = tabs.size(); --i >= insertIndex;)
  50334. {
  50335. TabBarButton* const tb = getTabButton (i);
  50336. if (tb != 0)
  50337. tb->tabIndex++;
  50338. }
  50339. tabs.insert (insertIndex, tabName);
  50340. tabColours.insert (insertIndex, tabBackgroundColour);
  50341. TabBarButton* const tb = createTabButton (tabName, insertIndex);
  50342. jassert (tb != 0); // your createTabButton() mustn't return zero!
  50343. addAndMakeVisible (tb, insertIndex);
  50344. resized();
  50345. if (currentTabIndex < 0)
  50346. setCurrentTabIndex (0);
  50347. }
  50348. }
  50349. void TabbedButtonBar::setTabName (const int tabIndex,
  50350. const String& newName)
  50351. {
  50352. if (((unsigned int) tabIndex) < (unsigned int) tabs.size()
  50353. && tabs[tabIndex] != newName)
  50354. {
  50355. tabs.set (tabIndex, newName);
  50356. TabBarButton* const tb = getTabButton (tabIndex);
  50357. if (tb != 0)
  50358. tb->setButtonText (newName);
  50359. resized();
  50360. }
  50361. }
  50362. void TabbedButtonBar::removeTab (const int tabIndex)
  50363. {
  50364. if (((unsigned int) tabIndex) < (unsigned int) tabs.size())
  50365. {
  50366. const int oldTabIndex = currentTabIndex;
  50367. if (currentTabIndex == tabIndex)
  50368. currentTabIndex = -1;
  50369. tabs.remove (tabIndex);
  50370. tabColours.remove (tabIndex);
  50371. delete getTabButton (tabIndex);
  50372. for (int i = tabIndex + 1; i <= tabs.size(); ++i)
  50373. {
  50374. TabBarButton* const tb = getTabButton (i);
  50375. if (tb != 0)
  50376. tb->tabIndex--;
  50377. }
  50378. resized();
  50379. setCurrentTabIndex (jlimit (0, jmax (0, tabs.size() - 1), oldTabIndex));
  50380. }
  50381. }
  50382. void TabbedButtonBar::moveTab (const int currentIndex,
  50383. const int newIndex)
  50384. {
  50385. tabs.move (currentIndex, newIndex);
  50386. tabColours.move (currentIndex, newIndex);
  50387. resized();
  50388. }
  50389. int TabbedButtonBar::getNumTabs() const
  50390. {
  50391. return tabs.size();
  50392. }
  50393. const StringArray TabbedButtonBar::getTabNames() const
  50394. {
  50395. return tabs;
  50396. }
  50397. void TabbedButtonBar::setCurrentTabIndex (int newIndex, const bool sendChangeMessage_)
  50398. {
  50399. if (currentTabIndex != newIndex)
  50400. {
  50401. if (((unsigned int) newIndex) >= (unsigned int) tabs.size())
  50402. newIndex = -1;
  50403. currentTabIndex = newIndex;
  50404. for (int i = 0; i < getNumChildComponents(); ++i)
  50405. {
  50406. TabBarButton* const tb = dynamic_cast <TabBarButton*> (getChildComponent (i));
  50407. if (tb != 0)
  50408. tb->setToggleState (tb->tabIndex == newIndex, false);
  50409. }
  50410. resized();
  50411. if (sendChangeMessage_)
  50412. sendChangeMessage (this);
  50413. currentTabChanged (newIndex, newIndex >= 0 ? tabs [newIndex] : String::empty);
  50414. }
  50415. }
  50416. TabBarButton* TabbedButtonBar::getTabButton (const int index) const
  50417. {
  50418. for (int i = getNumChildComponents(); --i >= 0;)
  50419. {
  50420. TabBarButton* const tb = dynamic_cast <TabBarButton*> (getChildComponent (i));
  50421. if (tb != 0 && tb->tabIndex == index)
  50422. return tb;
  50423. }
  50424. return 0;
  50425. }
  50426. void TabbedButtonBar::lookAndFeelChanged()
  50427. {
  50428. deleteAndZero (extraTabsButton);
  50429. resized();
  50430. }
  50431. void TabbedButtonBar::resized()
  50432. {
  50433. const double minimumScale = 0.7;
  50434. int depth = getWidth();
  50435. int length = getHeight();
  50436. if (orientation == TabsAtTop || orientation == TabsAtBottom)
  50437. swapVariables (depth, length);
  50438. const int overlap = getLookAndFeel().getTabButtonOverlap (depth)
  50439. + getLookAndFeel().getTabButtonSpaceAroundImage() * 2;
  50440. int i, totalLength = overlap;
  50441. int numVisibleButtons = tabs.size();
  50442. for (i = 0; i < getNumChildComponents(); ++i)
  50443. {
  50444. TabBarButton* const tb = dynamic_cast <TabBarButton*> (getChildComponent (i));
  50445. if (tb != 0)
  50446. {
  50447. totalLength += tb->getBestTabLength (depth) - overlap;
  50448. tb->overlapPixels = overlap / 2;
  50449. }
  50450. }
  50451. double scale = 1.0;
  50452. if (totalLength > length)
  50453. scale = jmax (minimumScale, length / (double) totalLength);
  50454. const bool isTooBig = totalLength * scale > length;
  50455. int tabsButtonPos = 0;
  50456. if (isTooBig)
  50457. {
  50458. if (extraTabsButton == 0)
  50459. {
  50460. addAndMakeVisible (extraTabsButton = getLookAndFeel().createTabBarExtrasButton());
  50461. extraTabsButton->addButtonListener (this);
  50462. extraTabsButton->setAlwaysOnTop (true);
  50463. extraTabsButton->setTriggeredOnMouseDown (true);
  50464. }
  50465. const int buttonSize = jmin (proportionOfWidth (0.7f), proportionOfHeight (0.7f));
  50466. extraTabsButton->setSize (buttonSize, buttonSize);
  50467. if (orientation == TabsAtTop || orientation == TabsAtBottom)
  50468. {
  50469. tabsButtonPos = getWidth() - buttonSize / 2 - 1;
  50470. extraTabsButton->setCentrePosition (tabsButtonPos, getHeight() / 2);
  50471. }
  50472. else
  50473. {
  50474. tabsButtonPos = getHeight() - buttonSize / 2 - 1;
  50475. extraTabsButton->setCentrePosition (getWidth() / 2, tabsButtonPos);
  50476. }
  50477. totalLength = 0;
  50478. for (i = 0; i < tabs.size(); ++i)
  50479. {
  50480. TabBarButton* const tb = getTabButton (i);
  50481. if (tb != 0)
  50482. {
  50483. const int newLength = totalLength + tb->getBestTabLength (depth);
  50484. if (i > 0 && newLength * minimumScale > tabsButtonPos)
  50485. {
  50486. totalLength += overlap;
  50487. break;
  50488. }
  50489. numVisibleButtons = i + 1;
  50490. totalLength = newLength - overlap;
  50491. }
  50492. }
  50493. scale = jmax (minimumScale, tabsButtonPos / (double) totalLength);
  50494. }
  50495. else
  50496. {
  50497. deleteAndZero (extraTabsButton);
  50498. }
  50499. int pos = 0;
  50500. TabBarButton* frontTab = 0;
  50501. for (i = 0; i < tabs.size(); ++i)
  50502. {
  50503. TabBarButton* const tb = getTabButton (i);
  50504. if (tb != 0)
  50505. {
  50506. const int bestLength = roundToInt (scale * tb->getBestTabLength (depth));
  50507. if (i < numVisibleButtons)
  50508. {
  50509. if (orientation == TabsAtTop || orientation == TabsAtBottom)
  50510. tb->setBounds (pos, 0, bestLength, getHeight());
  50511. else
  50512. tb->setBounds (0, pos, getWidth(), bestLength);
  50513. tb->toBack();
  50514. if (tb->tabIndex == currentTabIndex)
  50515. frontTab = tb;
  50516. tb->setVisible (true);
  50517. }
  50518. else
  50519. {
  50520. tb->setVisible (false);
  50521. }
  50522. pos += bestLength - overlap;
  50523. }
  50524. }
  50525. behindFrontTab->setBounds (0, 0, getWidth(), getHeight());
  50526. if (frontTab != 0)
  50527. {
  50528. frontTab->toFront (false);
  50529. behindFrontTab->toBehind (frontTab);
  50530. }
  50531. }
  50532. const Colour TabbedButtonBar::getTabBackgroundColour (const int tabIndex)
  50533. {
  50534. return tabColours [tabIndex];
  50535. }
  50536. void TabbedButtonBar::setTabBackgroundColour (const int tabIndex, const Colour& newColour)
  50537. {
  50538. if (((unsigned int) tabIndex) < (unsigned int) tabColours.size()
  50539. && tabColours [tabIndex] != newColour)
  50540. {
  50541. tabColours.set (tabIndex, newColour);
  50542. repaint();
  50543. }
  50544. }
  50545. void TabbedButtonBar::buttonClicked (Button* button)
  50546. {
  50547. if (extraTabsButton == button)
  50548. {
  50549. PopupMenu m;
  50550. for (int i = 0; i < tabs.size(); ++i)
  50551. {
  50552. TabBarButton* const tb = getTabButton (i);
  50553. if (tb != 0 && ! tb->isVisible())
  50554. m.addItem (tb->tabIndex + 1, tabs[i], true, i == currentTabIndex);
  50555. }
  50556. const int res = m.showAt (extraTabsButton);
  50557. if (res != 0)
  50558. setCurrentTabIndex (res - 1);
  50559. }
  50560. }
  50561. void TabbedButtonBar::currentTabChanged (const int, const String&)
  50562. {
  50563. }
  50564. void TabbedButtonBar::popupMenuClickOnTab (const int, const String&)
  50565. {
  50566. }
  50567. END_JUCE_NAMESPACE
  50568. /*** End of inlined file: juce_TabbedButtonBar.cpp ***/
  50569. /*** Start of inlined file: juce_TabbedComponent.cpp ***/
  50570. BEGIN_JUCE_NAMESPACE
  50571. class TabCompButtonBar : public TabbedButtonBar
  50572. {
  50573. public:
  50574. TabCompButtonBar (TabbedComponent* const owner_,
  50575. const TabbedButtonBar::Orientation orientation)
  50576. : TabbedButtonBar (orientation),
  50577. owner (owner_)
  50578. {
  50579. }
  50580. ~TabCompButtonBar()
  50581. {
  50582. }
  50583. void currentTabChanged (const int newCurrentTabIndex,
  50584. const String& newTabName)
  50585. {
  50586. owner->changeCallback (newCurrentTabIndex, newTabName);
  50587. }
  50588. void popupMenuClickOnTab (const int tabIndex,
  50589. const String& tabName)
  50590. {
  50591. owner->popupMenuClickOnTab (tabIndex, tabName);
  50592. }
  50593. const Colour getTabBackgroundColour (const int tabIndex)
  50594. {
  50595. return owner->tabs->getTabBackgroundColour (tabIndex);
  50596. }
  50597. TabBarButton* createTabButton (const String& tabName, const int tabIndex)
  50598. {
  50599. return owner->createTabButton (tabName, tabIndex);
  50600. }
  50601. juce_UseDebuggingNewOperator
  50602. private:
  50603. TabbedComponent* const owner;
  50604. TabCompButtonBar (const TabCompButtonBar&);
  50605. TabCompButtonBar& operator= (const TabCompButtonBar&);
  50606. };
  50607. TabbedComponent::TabbedComponent (const TabbedButtonBar::Orientation orientation)
  50608. : panelComponent (0),
  50609. tabDepth (30),
  50610. outlineThickness (1),
  50611. edgeIndent (0)
  50612. {
  50613. addAndMakeVisible (tabs = new TabCompButtonBar (this, orientation));
  50614. }
  50615. TabbedComponent::~TabbedComponent()
  50616. {
  50617. clearTabs();
  50618. delete tabs;
  50619. }
  50620. void TabbedComponent::setOrientation (const TabbedButtonBar::Orientation orientation)
  50621. {
  50622. tabs->setOrientation (orientation);
  50623. resized();
  50624. }
  50625. TabbedButtonBar::Orientation TabbedComponent::getOrientation() const throw()
  50626. {
  50627. return tabs->getOrientation();
  50628. }
  50629. void TabbedComponent::setTabBarDepth (const int newDepth)
  50630. {
  50631. if (tabDepth != newDepth)
  50632. {
  50633. tabDepth = newDepth;
  50634. resized();
  50635. }
  50636. }
  50637. TabBarButton* TabbedComponent::createTabButton (const String& tabName, const int tabIndex)
  50638. {
  50639. return new TabBarButton (tabName, tabs, tabIndex);
  50640. }
  50641. void TabbedComponent::clearTabs()
  50642. {
  50643. if (panelComponent != 0)
  50644. {
  50645. panelComponent->setVisible (false);
  50646. removeChildComponent (panelComponent);
  50647. panelComponent = 0;
  50648. }
  50649. tabs->clearTabs();
  50650. for (int i = contentComponents.size(); --i >= 0;)
  50651. {
  50652. Component* const c = contentComponents.getUnchecked(i);
  50653. // be careful not to delete these components until they've been removed from the tab component
  50654. jassert (c == 0 || c->isValidComponent());
  50655. if (c != 0 && (bool) c->getProperties() ["deleteByTabComp_"])
  50656. delete c;
  50657. }
  50658. contentComponents.clear();
  50659. }
  50660. void TabbedComponent::addTab (const String& tabName,
  50661. const Colour& tabBackgroundColour,
  50662. Component* const contentComponent,
  50663. const bool deleteComponentWhenNotNeeded,
  50664. const int insertIndex)
  50665. {
  50666. contentComponents.insert (insertIndex, contentComponent);
  50667. if (contentComponent != 0)
  50668. contentComponent->getProperties().set ("deleteByTabComp_", deleteComponentWhenNotNeeded);
  50669. tabs->addTab (tabName, tabBackgroundColour, insertIndex);
  50670. }
  50671. void TabbedComponent::setTabName (const int tabIndex,
  50672. const String& newName)
  50673. {
  50674. tabs->setTabName (tabIndex, newName);
  50675. }
  50676. void TabbedComponent::removeTab (const int tabIndex)
  50677. {
  50678. Component* const c = contentComponents [tabIndex];
  50679. if (c != 0 && (bool) c->getProperties() ["deleteByTabComp_"])
  50680. {
  50681. if (c == panelComponent)
  50682. panelComponent = 0;
  50683. delete c;
  50684. }
  50685. contentComponents.remove (tabIndex);
  50686. tabs->removeTab (tabIndex);
  50687. }
  50688. int TabbedComponent::getNumTabs() const
  50689. {
  50690. return tabs->getNumTabs();
  50691. }
  50692. const StringArray TabbedComponent::getTabNames() const
  50693. {
  50694. return tabs->getTabNames();
  50695. }
  50696. Component* TabbedComponent::getTabContentComponent (const int tabIndex) const throw()
  50697. {
  50698. return contentComponents [tabIndex];
  50699. }
  50700. const Colour TabbedComponent::getTabBackgroundColour (const int tabIndex) const throw()
  50701. {
  50702. return tabs->getTabBackgroundColour (tabIndex);
  50703. }
  50704. void TabbedComponent::setTabBackgroundColour (const int tabIndex, const Colour& newColour)
  50705. {
  50706. tabs->setTabBackgroundColour (tabIndex, newColour);
  50707. if (getCurrentTabIndex() == tabIndex)
  50708. repaint();
  50709. }
  50710. void TabbedComponent::setCurrentTabIndex (const int newTabIndex, const bool sendChangeMessage)
  50711. {
  50712. tabs->setCurrentTabIndex (newTabIndex, sendChangeMessage);
  50713. }
  50714. int TabbedComponent::getCurrentTabIndex() const
  50715. {
  50716. return tabs->getCurrentTabIndex();
  50717. }
  50718. const String& TabbedComponent::getCurrentTabName() const
  50719. {
  50720. return tabs->getCurrentTabName();
  50721. }
  50722. void TabbedComponent::setOutline (int thickness)
  50723. {
  50724. outlineThickness = thickness;
  50725. repaint();
  50726. }
  50727. void TabbedComponent::setIndent (const int indentThickness)
  50728. {
  50729. edgeIndent = indentThickness;
  50730. }
  50731. void TabbedComponent::paint (Graphics& g)
  50732. {
  50733. g.fillAll (findColour (backgroundColourId));
  50734. const TabbedButtonBar::Orientation o = getOrientation();
  50735. int x = 0;
  50736. int y = 0;
  50737. int r = getWidth();
  50738. int b = getHeight();
  50739. if (o == TabbedButtonBar::TabsAtTop)
  50740. y += tabDepth;
  50741. else if (o == TabbedButtonBar::TabsAtBottom)
  50742. b -= tabDepth;
  50743. else if (o == TabbedButtonBar::TabsAtLeft)
  50744. x += tabDepth;
  50745. else if (o == TabbedButtonBar::TabsAtRight)
  50746. r -= tabDepth;
  50747. g.reduceClipRegion (x, y, r - x, b - y);
  50748. g.fillAll (tabs->getTabBackgroundColour (getCurrentTabIndex()));
  50749. if (outlineThickness > 0)
  50750. {
  50751. if (o == TabbedButtonBar::TabsAtTop)
  50752. --y;
  50753. else if (o == TabbedButtonBar::TabsAtBottom)
  50754. ++b;
  50755. else if (o == TabbedButtonBar::TabsAtLeft)
  50756. --x;
  50757. else if (o == TabbedButtonBar::TabsAtRight)
  50758. ++r;
  50759. g.setColour (findColour (outlineColourId));
  50760. g.drawRect (x, y, r - x, b - y, outlineThickness);
  50761. }
  50762. }
  50763. void TabbedComponent::resized()
  50764. {
  50765. const TabbedButtonBar::Orientation o = getOrientation();
  50766. const int indent = edgeIndent + outlineThickness;
  50767. BorderSize indents (indent);
  50768. if (o == TabbedButtonBar::TabsAtTop)
  50769. {
  50770. tabs->setBounds (0, 0, getWidth(), tabDepth);
  50771. indents.setTop (tabDepth + edgeIndent);
  50772. }
  50773. else if (o == TabbedButtonBar::TabsAtBottom)
  50774. {
  50775. tabs->setBounds (0, getHeight() - tabDepth, getWidth(), tabDepth);
  50776. indents.setBottom (tabDepth + edgeIndent);
  50777. }
  50778. else if (o == TabbedButtonBar::TabsAtLeft)
  50779. {
  50780. tabs->setBounds (0, 0, tabDepth, getHeight());
  50781. indents.setLeft (tabDepth + edgeIndent);
  50782. }
  50783. else if (o == TabbedButtonBar::TabsAtRight)
  50784. {
  50785. tabs->setBounds (getWidth() - tabDepth, 0, tabDepth, getHeight());
  50786. indents.setRight (tabDepth + edgeIndent);
  50787. }
  50788. const Rectangle<int> bounds (indents.subtractedFrom (Rectangle<int> (0, 0, getWidth(), getHeight())));
  50789. for (int i = contentComponents.size(); --i >= 0;)
  50790. if (contentComponents.getUnchecked (i) != 0)
  50791. contentComponents.getUnchecked (i)->setBounds (bounds);
  50792. }
  50793. void TabbedComponent::lookAndFeelChanged()
  50794. {
  50795. for (int i = contentComponents.size(); --i >= 0;)
  50796. if (contentComponents.getUnchecked (i) != 0)
  50797. contentComponents.getUnchecked (i)->lookAndFeelChanged();
  50798. }
  50799. void TabbedComponent::changeCallback (const int newCurrentTabIndex,
  50800. const String& newTabName)
  50801. {
  50802. if (panelComponent != 0)
  50803. {
  50804. panelComponent->setVisible (false);
  50805. removeChildComponent (panelComponent);
  50806. panelComponent = 0;
  50807. }
  50808. if (getCurrentTabIndex() >= 0)
  50809. {
  50810. panelComponent = contentComponents [getCurrentTabIndex()];
  50811. if (panelComponent != 0)
  50812. {
  50813. // do these ops as two stages instead of addAndMakeVisible() so that the
  50814. // component has always got a parent when it gets the visibilityChanged() callback
  50815. addChildComponent (panelComponent);
  50816. panelComponent->setVisible (true);
  50817. panelComponent->toFront (true);
  50818. }
  50819. repaint();
  50820. }
  50821. resized();
  50822. currentTabChanged (newCurrentTabIndex, newTabName);
  50823. }
  50824. void TabbedComponent::currentTabChanged (const int, const String&)
  50825. {
  50826. }
  50827. void TabbedComponent::popupMenuClickOnTab (const int, const String&)
  50828. {
  50829. }
  50830. END_JUCE_NAMESPACE
  50831. /*** End of inlined file: juce_TabbedComponent.cpp ***/
  50832. /*** Start of inlined file: juce_Viewport.cpp ***/
  50833. BEGIN_JUCE_NAMESPACE
  50834. Viewport::Viewport (const String& componentName)
  50835. : Component (componentName),
  50836. contentComp (0),
  50837. lastVX (0),
  50838. lastVY (0),
  50839. lastVW (0),
  50840. lastVH (0),
  50841. scrollBarThickness (0),
  50842. singleStepX (16),
  50843. singleStepY (16),
  50844. showHScrollbar (true),
  50845. showVScrollbar (true)
  50846. {
  50847. // content holder is used to clip the contents so they don't overlap the scrollbars
  50848. addAndMakeVisible (contentHolder = new Component());
  50849. contentHolder->setInterceptsMouseClicks (false, true);
  50850. verticalScrollBar = new ScrollBar (true);
  50851. horizontalScrollBar = new ScrollBar (false);
  50852. addChildComponent (verticalScrollBar);
  50853. addChildComponent (horizontalScrollBar);
  50854. verticalScrollBar->addListener (this);
  50855. horizontalScrollBar->addListener (this);
  50856. setInterceptsMouseClicks (false, true);
  50857. setWantsKeyboardFocus (true);
  50858. }
  50859. Viewport::~Viewport()
  50860. {
  50861. contentHolder->deleteAllChildren();
  50862. deleteAllChildren();
  50863. }
  50864. void Viewport::visibleAreaChanged (int, int, int, int)
  50865. {
  50866. }
  50867. void Viewport::setViewedComponent (Component* const newViewedComponent)
  50868. {
  50869. if (contentComp.getComponent() != newViewedComponent)
  50870. {
  50871. {
  50872. ScopedPointer<Component> oldCompDeleter (contentComp);
  50873. contentComp = 0;
  50874. }
  50875. contentComp = newViewedComponent;
  50876. if (contentComp != 0)
  50877. {
  50878. contentComp->setTopLeftPosition (0, 0);
  50879. contentHolder->addAndMakeVisible (contentComp);
  50880. contentComp->addComponentListener (this);
  50881. }
  50882. updateVisibleRegion();
  50883. }
  50884. }
  50885. int Viewport::getMaximumVisibleWidth() const throw()
  50886. {
  50887. return jmax (0, getWidth() - (verticalScrollBar->isVisible() ? getScrollBarThickness() : 0));
  50888. }
  50889. int Viewport::getMaximumVisibleHeight() const throw()
  50890. {
  50891. return jmax (0, getHeight() - (horizontalScrollBar->isVisible() ? getScrollBarThickness() : 0));
  50892. }
  50893. void Viewport::setViewPosition (const int xPixelsOffset,
  50894. const int yPixelsOffset)
  50895. {
  50896. if (contentComp != 0)
  50897. contentComp->setTopLeftPosition (-xPixelsOffset,
  50898. -yPixelsOffset);
  50899. }
  50900. void Viewport::setViewPositionProportionately (const double x,
  50901. const double y)
  50902. {
  50903. if (contentComp != 0)
  50904. setViewPosition (jmax (0, roundToInt (x * (contentComp->getWidth() - getWidth()))),
  50905. jmax (0, roundToInt (y * (contentComp->getHeight() - getHeight()))));
  50906. }
  50907. bool Viewport::autoScroll (int mouseX, int mouseY, int activeBorderThickness, int maximumSpeed)
  50908. {
  50909. if (contentComp != 0)
  50910. {
  50911. int dx = 0, dy = 0;
  50912. if (mouseX < activeBorderThickness)
  50913. dx = activeBorderThickness - mouseX;
  50914. else if (mouseX >= contentHolder->getWidth() - activeBorderThickness)
  50915. dx = (contentHolder->getWidth() - activeBorderThickness) - mouseX;
  50916. if (dx < 0)
  50917. dx = jmax (dx, -maximumSpeed, contentHolder->getWidth() - contentComp->getRight());
  50918. else
  50919. dx = jmin (dx, maximumSpeed, -contentComp->getX());
  50920. if (mouseY < activeBorderThickness)
  50921. dy = activeBorderThickness - mouseY;
  50922. else if (mouseY >= contentHolder->getHeight() - activeBorderThickness)
  50923. dy = (contentHolder->getHeight() - activeBorderThickness) - mouseY;
  50924. if (dy < 0)
  50925. dy = jmax (dy, -maximumSpeed, contentHolder->getHeight() - contentComp->getBottom());
  50926. else
  50927. dy = jmin (dy, maximumSpeed, -contentComp->getY());
  50928. if (dx != 0 || dy != 0)
  50929. {
  50930. contentComp->setTopLeftPosition (contentComp->getX() + dx,
  50931. contentComp->getY() + dy);
  50932. return true;
  50933. }
  50934. }
  50935. return false;
  50936. }
  50937. void Viewport::componentMovedOrResized (Component&, bool, bool)
  50938. {
  50939. updateVisibleRegion();
  50940. }
  50941. void Viewport::resized()
  50942. {
  50943. updateVisibleRegion();
  50944. }
  50945. void Viewport::updateVisibleRegion()
  50946. {
  50947. if (contentComp != 0)
  50948. {
  50949. const int newVX = -contentComp->getX();
  50950. const int newVY = -contentComp->getY();
  50951. if (newVX == 0 && newVY == 0
  50952. && contentComp->getWidth() <= getWidth()
  50953. && contentComp->getHeight() <= getHeight())
  50954. {
  50955. horizontalScrollBar->setVisible (false);
  50956. verticalScrollBar->setVisible (false);
  50957. }
  50958. horizontalScrollBar->setRangeLimits (0.0, contentComp->getWidth());
  50959. horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth());
  50960. horizontalScrollBar->setSingleStepSize (singleStepX);
  50961. if (! (contentComp->getWidth() > 0 && showHScrollbar && getHeight() > getScrollBarThickness()))
  50962. horizontalScrollBar->setVisible (false);
  50963. verticalScrollBar->setRangeLimits (0.0, contentComp->getHeight());
  50964. verticalScrollBar->setCurrentRange (newVY, getMaximumVisibleHeight());
  50965. verticalScrollBar->setSingleStepSize (singleStepY);
  50966. if (! (contentComp->getHeight() > 0 && showVScrollbar && getWidth() > getScrollBarThickness()))
  50967. verticalScrollBar->setVisible (false);
  50968. if (verticalScrollBar->isVisible())
  50969. {
  50970. horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth());
  50971. verticalScrollBar->setCurrentRange (newVY, getMaximumVisibleHeight());
  50972. verticalScrollBar
  50973. ->setBounds (getMaximumVisibleWidth(), 0,
  50974. getScrollBarThickness(), getMaximumVisibleHeight());
  50975. }
  50976. if (horizontalScrollBar->isVisible())
  50977. {
  50978. horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth());
  50979. horizontalScrollBar
  50980. ->setBounds (0, getMaximumVisibleHeight(),
  50981. getMaximumVisibleWidth(), getScrollBarThickness());
  50982. }
  50983. contentHolder->setSize (getMaximumVisibleWidth(),
  50984. getMaximumVisibleHeight());
  50985. const int newVW = jmin (contentComp->getRight(), getMaximumVisibleWidth());
  50986. const int newVH = jmin (contentComp->getBottom(), getMaximumVisibleHeight());
  50987. if (newVX != lastVX
  50988. || newVY != lastVY
  50989. || newVW != lastVW
  50990. || newVH != lastVH)
  50991. {
  50992. lastVX = newVX;
  50993. lastVY = newVY;
  50994. lastVW = newVW;
  50995. lastVH = newVH;
  50996. visibleAreaChanged (newVX, newVY, newVW, newVH);
  50997. }
  50998. horizontalScrollBar->handleUpdateNowIfNeeded();
  50999. verticalScrollBar->handleUpdateNowIfNeeded();
  51000. }
  51001. else
  51002. {
  51003. horizontalScrollBar->setVisible (false);
  51004. verticalScrollBar->setVisible (false);
  51005. }
  51006. }
  51007. void Viewport::setSingleStepSizes (const int stepX,
  51008. const int stepY)
  51009. {
  51010. singleStepX = stepX;
  51011. singleStepY = stepY;
  51012. updateVisibleRegion();
  51013. }
  51014. void Viewport::setScrollBarsShown (const bool showVerticalScrollbarIfNeeded,
  51015. const bool showHorizontalScrollbarIfNeeded)
  51016. {
  51017. showVScrollbar = showVerticalScrollbarIfNeeded;
  51018. showHScrollbar = showHorizontalScrollbarIfNeeded;
  51019. updateVisibleRegion();
  51020. }
  51021. void Viewport::setScrollBarThickness (const int thickness)
  51022. {
  51023. scrollBarThickness = thickness;
  51024. updateVisibleRegion();
  51025. }
  51026. int Viewport::getScrollBarThickness() const throw()
  51027. {
  51028. return (scrollBarThickness > 0) ? scrollBarThickness
  51029. : getLookAndFeel().getDefaultScrollbarWidth();
  51030. }
  51031. void Viewport::setScrollBarButtonVisibility (const bool buttonsVisible)
  51032. {
  51033. verticalScrollBar->setButtonVisibility (buttonsVisible);
  51034. horizontalScrollBar->setButtonVisibility (buttonsVisible);
  51035. }
  51036. void Viewport::scrollBarMoved (ScrollBar* scrollBarThatHasMoved, double newRangeStart)
  51037. {
  51038. if (scrollBarThatHasMoved == horizontalScrollBar)
  51039. {
  51040. setViewPosition (roundToInt (newRangeStart), getViewPositionY());
  51041. }
  51042. else if (scrollBarThatHasMoved == verticalScrollBar)
  51043. {
  51044. setViewPosition (getViewPositionX(), roundToInt (newRangeStart));
  51045. }
  51046. }
  51047. void Viewport::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  51048. {
  51049. if (! useMouseWheelMoveIfNeeded (e, wheelIncrementX, wheelIncrementY))
  51050. Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
  51051. }
  51052. bool Viewport::useMouseWheelMoveIfNeeded (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  51053. {
  51054. if (! (e.mods.isAltDown() || e.mods.isCtrlDown()))
  51055. {
  51056. const bool hasVertBar = verticalScrollBar->isVisible();
  51057. const bool hasHorzBar = horizontalScrollBar->isVisible();
  51058. if (hasHorzBar && (wheelIncrementX != 0 || e.mods.isShiftDown() || ! hasVertBar))
  51059. {
  51060. if (wheelIncrementX == 0 && ! hasVertBar)
  51061. wheelIncrementX = wheelIncrementY;
  51062. horizontalScrollBar->mouseWheelMove (e.getEventRelativeTo (horizontalScrollBar),
  51063. wheelIncrementX, wheelIncrementY);
  51064. return true;
  51065. }
  51066. else if (hasVertBar && wheelIncrementY != 0)
  51067. {
  51068. verticalScrollBar->mouseWheelMove (e.getEventRelativeTo (verticalScrollBar),
  51069. wheelIncrementX, wheelIncrementY);
  51070. return true;
  51071. }
  51072. }
  51073. return false;
  51074. }
  51075. bool Viewport::keyPressed (const KeyPress& key)
  51076. {
  51077. const bool isUpDownKey = key.isKeyCode (KeyPress::upKey)
  51078. || key.isKeyCode (KeyPress::downKey)
  51079. || key.isKeyCode (KeyPress::pageUpKey)
  51080. || key.isKeyCode (KeyPress::pageDownKey)
  51081. || key.isKeyCode (KeyPress::homeKey)
  51082. || key.isKeyCode (KeyPress::endKey);
  51083. if (verticalScrollBar->isVisible() && isUpDownKey)
  51084. return verticalScrollBar->keyPressed (key);
  51085. const bool isLeftRightKey = key.isKeyCode (KeyPress::leftKey)
  51086. || key.isKeyCode (KeyPress::rightKey);
  51087. if (horizontalScrollBar->isVisible() && (isUpDownKey || isLeftRightKey))
  51088. return horizontalScrollBar->keyPressed (key);
  51089. return false;
  51090. }
  51091. END_JUCE_NAMESPACE
  51092. /*** End of inlined file: juce_Viewport.cpp ***/
  51093. /*** Start of inlined file: juce_LookAndFeel.cpp ***/
  51094. BEGIN_JUCE_NAMESPACE
  51095. static const Colour createBaseColour (const Colour& buttonColour,
  51096. const bool hasKeyboardFocus,
  51097. const bool isMouseOverButton,
  51098. const bool isButtonDown) throw()
  51099. {
  51100. const float sat = hasKeyboardFocus ? 1.3f : 0.9f;
  51101. const Colour baseColour (buttonColour.withMultipliedSaturation (sat));
  51102. if (isButtonDown)
  51103. return baseColour.contrasting (0.2f);
  51104. else if (isMouseOverButton)
  51105. return baseColour.contrasting (0.1f);
  51106. return baseColour;
  51107. }
  51108. static String defaultSansName, defaultSerifName, defaultFixedName;
  51109. void clearUpDefaultFontNames() throw()
  51110. {
  51111. defaultSansName = String::empty;
  51112. defaultSerifName = String::empty;
  51113. defaultFixedName = String::empty;
  51114. }
  51115. LookAndFeel::LookAndFeel()
  51116. {
  51117. /* if this fails it means you're trying to create a LookAndFeel object before
  51118. the static Colours have been initialised. That ain't gonna work. It probably
  51119. means that you're using a static LookAndFeel object and that your compiler has
  51120. decided to intialise it before the Colours class.
  51121. */
  51122. jassert (Colours::white == Colour (0xffffffff));
  51123. // set up the standard set of colours..
  51124. const int textButtonColour = 0xffbbbbff;
  51125. const int textHighlightColour = 0x401111ee;
  51126. const int standardOutlineColour = 0xb2808080;
  51127. static const int standardColours[] =
  51128. {
  51129. TextButton::buttonColourId, textButtonColour,
  51130. TextButton::buttonOnColourId, 0xff4444ff,
  51131. TextButton::textColourOnId, 0xff000000,
  51132. TextButton::textColourOffId, 0xff000000,
  51133. ComboBox::buttonColourId, 0xffbbbbff,
  51134. ComboBox::outlineColourId, standardOutlineColour,
  51135. ToggleButton::textColourId, 0xff000000,
  51136. TextEditor::backgroundColourId, 0xffffffff,
  51137. TextEditor::textColourId, 0xff000000,
  51138. TextEditor::highlightColourId, textHighlightColour,
  51139. TextEditor::highlightedTextColourId, 0xff000000,
  51140. TextEditor::caretColourId, 0xff000000,
  51141. TextEditor::outlineColourId, 0x00000000,
  51142. TextEditor::focusedOutlineColourId, textButtonColour,
  51143. TextEditor::shadowColourId, 0x38000000,
  51144. Label::backgroundColourId, 0x00000000,
  51145. Label::textColourId, 0xff000000,
  51146. Label::outlineColourId, 0x00000000,
  51147. ScrollBar::backgroundColourId, 0x00000000,
  51148. ScrollBar::thumbColourId, 0xffffffff,
  51149. ScrollBar::trackColourId, 0xffffffff,
  51150. TreeView::linesColourId, 0x4c000000,
  51151. TreeView::backgroundColourId, 0x00000000,
  51152. TreeView::dragAndDropIndicatorColourId, 0x80ff0000,
  51153. PopupMenu::backgroundColourId, 0xffffffff,
  51154. PopupMenu::textColourId, 0xff000000,
  51155. PopupMenu::headerTextColourId, 0xff000000,
  51156. PopupMenu::highlightedTextColourId, 0xffffffff,
  51157. PopupMenu::highlightedBackgroundColourId, 0x991111aa,
  51158. ComboBox::textColourId, 0xff000000,
  51159. ComboBox::backgroundColourId, 0xffffffff,
  51160. ComboBox::arrowColourId, 0x99000000,
  51161. ListBox::backgroundColourId, 0xffffffff,
  51162. ListBox::outlineColourId, standardOutlineColour,
  51163. ListBox::textColourId, 0xff000000,
  51164. Slider::backgroundColourId, 0x00000000,
  51165. Slider::thumbColourId, textButtonColour,
  51166. Slider::trackColourId, 0x7fffffff,
  51167. Slider::rotarySliderFillColourId, 0x7f0000ff,
  51168. Slider::rotarySliderOutlineColourId, 0x66000000,
  51169. Slider::textBoxTextColourId, 0xff000000,
  51170. Slider::textBoxBackgroundColourId, 0xffffffff,
  51171. Slider::textBoxHighlightColourId, textHighlightColour,
  51172. Slider::textBoxOutlineColourId, standardOutlineColour,
  51173. ResizableWindow::backgroundColourId, 0xff777777,
  51174. //DocumentWindow::textColourId, 0xff000000, // (this is deliberately not set)
  51175. AlertWindow::backgroundColourId, 0xffededed,
  51176. AlertWindow::textColourId, 0xff000000,
  51177. AlertWindow::outlineColourId, 0xff666666,
  51178. ProgressBar::backgroundColourId, 0xffeeeeee,
  51179. ProgressBar::foregroundColourId, 0xffaaaaee,
  51180. TooltipWindow::backgroundColourId, 0xffeeeebb,
  51181. TooltipWindow::textColourId, 0xff000000,
  51182. TooltipWindow::outlineColourId, 0x4c000000,
  51183. TabbedComponent::backgroundColourId, 0x00000000,
  51184. TabbedComponent::outlineColourId, 0xff777777,
  51185. TabbedButtonBar::tabOutlineColourId, 0x80000000,
  51186. TabbedButtonBar::frontOutlineColourId, 0x90000000,
  51187. Toolbar::backgroundColourId, 0xfff6f8f9,
  51188. Toolbar::separatorColourId, 0x4c000000,
  51189. Toolbar::buttonMouseOverBackgroundColourId, 0x4c0000ff,
  51190. Toolbar::buttonMouseDownBackgroundColourId, 0x800000ff,
  51191. Toolbar::labelTextColourId, 0xff000000,
  51192. Toolbar::editingModeOutlineColourId, 0xffff0000,
  51193. HyperlinkButton::textColourId, 0xcc1111ee,
  51194. GroupComponent::outlineColourId, 0x66000000,
  51195. GroupComponent::textColourId, 0xff000000,
  51196. DirectoryContentsDisplayComponent::highlightColourId, textHighlightColour,
  51197. DirectoryContentsDisplayComponent::textColourId, 0xff000000,
  51198. 0x1000440, /*LassoComponent::lassoFillColourId*/ 0x66dddddd,
  51199. 0x1000441, /*LassoComponent::lassoOutlineColourId*/ 0x99111111,
  51200. MidiKeyboardComponent::whiteNoteColourId, 0xffffffff,
  51201. MidiKeyboardComponent::blackNoteColourId, 0xff000000,
  51202. MidiKeyboardComponent::keySeparatorLineColourId, 0x66000000,
  51203. MidiKeyboardComponent::mouseOverKeyOverlayColourId, 0x80ffff00,
  51204. MidiKeyboardComponent::keyDownOverlayColourId, 0xffb6b600,
  51205. MidiKeyboardComponent::textLabelColourId, 0xff000000,
  51206. MidiKeyboardComponent::upDownButtonBackgroundColourId, 0xffd3d3d3,
  51207. MidiKeyboardComponent::upDownButtonArrowColourId, 0xff000000,
  51208. CodeEditorComponent::backgroundColourId, 0xffffffff,
  51209. CodeEditorComponent::caretColourId, 0xff000000,
  51210. CodeEditorComponent::highlightColourId, textHighlightColour,
  51211. CodeEditorComponent::defaultTextColourId, 0xff000000,
  51212. ColourSelector::backgroundColourId, 0xffe5e5e5,
  51213. ColourSelector::labelTextColourId, 0xff000000,
  51214. KeyMappingEditorComponent::backgroundColourId, 0x00000000,
  51215. KeyMappingEditorComponent::textColourId, 0xff000000,
  51216. FileSearchPathListComponent::backgroundColourId, 0xffffffff,
  51217. FileChooserDialogBox::titleTextColourId, 0xff000000,
  51218. };
  51219. for (int i = 0; i < numElementsInArray (standardColours); i += 2)
  51220. setColour (standardColours [i], Colour (standardColours [i + 1]));
  51221. if (defaultSansName.isEmpty())
  51222. Font::getPlatformDefaultFontNames (defaultSansName, defaultSerifName, defaultFixedName);
  51223. defaultSans = defaultSansName;
  51224. defaultSerif = defaultSerifName;
  51225. defaultFixed = defaultFixedName;
  51226. }
  51227. LookAndFeel::~LookAndFeel()
  51228. {
  51229. }
  51230. const Colour LookAndFeel::findColour (const int colourId) const throw()
  51231. {
  51232. const int index = colourIds.indexOf (colourId);
  51233. if (index >= 0)
  51234. return colours [index];
  51235. jassertfalse
  51236. return Colours::black;
  51237. }
  51238. void LookAndFeel::setColour (const int colourId, const Colour& colour) throw()
  51239. {
  51240. const int index = colourIds.indexOf (colourId);
  51241. if (index >= 0)
  51242. colours.set (index, colour);
  51243. colourIds.add (colourId);
  51244. colours.add (colour);
  51245. }
  51246. bool LookAndFeel::isColourSpecified (const int colourId) const throw()
  51247. {
  51248. return colourIds.contains (colourId);
  51249. }
  51250. static LookAndFeel* defaultLF = 0;
  51251. static LookAndFeel* currentDefaultLF = 0;
  51252. LookAndFeel& LookAndFeel::getDefaultLookAndFeel() throw()
  51253. {
  51254. // if this happens, your app hasn't initialised itself properly.. if you're
  51255. // trying to hack your own main() function, have a look at
  51256. // JUCEApplication::initialiseForGUI()
  51257. jassert (currentDefaultLF != 0);
  51258. return *currentDefaultLF;
  51259. }
  51260. void LookAndFeel::setDefaultLookAndFeel (LookAndFeel* newDefaultLookAndFeel) throw()
  51261. {
  51262. if (newDefaultLookAndFeel == 0)
  51263. {
  51264. if (defaultLF == 0)
  51265. defaultLF = new LookAndFeel();
  51266. newDefaultLookAndFeel = defaultLF;
  51267. }
  51268. currentDefaultLF = newDefaultLookAndFeel;
  51269. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  51270. {
  51271. Component* const c = Desktop::getInstance().getComponent (i);
  51272. if (c != 0)
  51273. c->sendLookAndFeelChange();
  51274. }
  51275. }
  51276. void LookAndFeel::clearDefaultLookAndFeel() throw()
  51277. {
  51278. if (currentDefaultLF == defaultLF)
  51279. currentDefaultLF = 0;
  51280. deleteAndZero (defaultLF);
  51281. }
  51282. const Typeface::Ptr LookAndFeel::getTypefaceForFont (const Font& font)
  51283. {
  51284. String faceName (font.getTypefaceName());
  51285. if (faceName == Font::getDefaultSansSerifFontName())
  51286. faceName = defaultSans;
  51287. else if (faceName == Font::getDefaultSerifFontName())
  51288. faceName = defaultSerif;
  51289. else if (faceName == Font::getDefaultMonospacedFontName())
  51290. faceName = defaultFixed;
  51291. Font f (font);
  51292. f.setTypefaceName (faceName);
  51293. return Typeface::createSystemTypefaceFor (f);
  51294. }
  51295. void LookAndFeel::setDefaultSansSerifTypefaceName (const String& newName)
  51296. {
  51297. defaultSans = newName;
  51298. }
  51299. const MouseCursor LookAndFeel::getMouseCursorFor (Component& component)
  51300. {
  51301. return component.getMouseCursor();
  51302. }
  51303. void LookAndFeel::drawButtonBackground (Graphics& g,
  51304. Button& button,
  51305. const Colour& backgroundColour,
  51306. bool isMouseOverButton,
  51307. bool isButtonDown)
  51308. {
  51309. const int width = button.getWidth();
  51310. const int height = button.getHeight();
  51311. const float outlineThickness = button.isEnabled() ? ((isButtonDown || isMouseOverButton) ? 1.2f : 0.7f) : 0.4f;
  51312. const float halfThickness = outlineThickness * 0.5f;
  51313. const float indentL = button.isConnectedOnLeft() ? 0.1f : halfThickness;
  51314. const float indentR = button.isConnectedOnRight() ? 0.1f : halfThickness;
  51315. const float indentT = button.isConnectedOnTop() ? 0.1f : halfThickness;
  51316. const float indentB = button.isConnectedOnBottom() ? 0.1f : halfThickness;
  51317. const Colour baseColour (createBaseColour (backgroundColour,
  51318. button.hasKeyboardFocus (true),
  51319. isMouseOverButton, isButtonDown)
  51320. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  51321. drawGlassLozenge (g,
  51322. indentL,
  51323. indentT,
  51324. width - indentL - indentR,
  51325. height - indentT - indentB,
  51326. baseColour, outlineThickness, -1.0f,
  51327. button.isConnectedOnLeft(),
  51328. button.isConnectedOnRight(),
  51329. button.isConnectedOnTop(),
  51330. button.isConnectedOnBottom());
  51331. }
  51332. const Font LookAndFeel::getFontForTextButton (TextButton& button)
  51333. {
  51334. return button.getFont();
  51335. }
  51336. void LookAndFeel::drawButtonText (Graphics& g, TextButton& button,
  51337. bool /*isMouseOverButton*/, bool /*isButtonDown*/)
  51338. {
  51339. Font font (getFontForTextButton (button));
  51340. g.setFont (font);
  51341. g.setColour (button.findColour (button.getToggleState() ? TextButton::textColourOnId
  51342. : TextButton::textColourOffId)
  51343. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  51344. const int yIndent = jmin (4, button.proportionOfHeight (0.3f));
  51345. const int cornerSize = jmin (button.getHeight(), button.getWidth()) / 2;
  51346. const int fontHeight = roundToInt (font.getHeight() * 0.6f);
  51347. const int leftIndent = jmin (fontHeight, 2 + cornerSize / (button.isConnectedOnLeft() ? 4 : 2));
  51348. const int rightIndent = jmin (fontHeight, 2 + cornerSize / (button.isConnectedOnRight() ? 4 : 2));
  51349. g.drawFittedText (button.getButtonText(),
  51350. leftIndent,
  51351. yIndent,
  51352. button.getWidth() - leftIndent - rightIndent,
  51353. button.getHeight() - yIndent * 2,
  51354. Justification::centred, 2);
  51355. }
  51356. void LookAndFeel::drawTickBox (Graphics& g,
  51357. Component& component,
  51358. float x, float y, float w, float h,
  51359. const bool ticked,
  51360. const bool isEnabled,
  51361. const bool isMouseOverButton,
  51362. const bool isButtonDown)
  51363. {
  51364. const float boxSize = w * 0.7f;
  51365. drawGlassSphere (g, x, y + (h - boxSize) * 0.5f, boxSize,
  51366. createBaseColour (component.findColour (TextButton::buttonColourId)
  51367. .withMultipliedAlpha (isEnabled ? 1.0f : 0.5f),
  51368. true,
  51369. isMouseOverButton,
  51370. isButtonDown),
  51371. isEnabled ? ((isButtonDown || isMouseOverButton) ? 1.1f : 0.5f) : 0.3f);
  51372. if (ticked)
  51373. {
  51374. Path tick;
  51375. tick.startNewSubPath (1.5f, 3.0f);
  51376. tick.lineTo (3.0f, 6.0f);
  51377. tick.lineTo (6.0f, 0.0f);
  51378. g.setColour (isEnabled ? Colours::black : Colours::grey);
  51379. const AffineTransform trans (AffineTransform::scale (w / 9.0f, h / 9.0f)
  51380. .translated (x, y));
  51381. g.strokePath (tick, PathStrokeType (2.5f), trans);
  51382. }
  51383. }
  51384. void LookAndFeel::drawToggleButton (Graphics& g,
  51385. ToggleButton& button,
  51386. bool isMouseOverButton,
  51387. bool isButtonDown)
  51388. {
  51389. if (button.hasKeyboardFocus (true))
  51390. {
  51391. g.setColour (button.findColour (TextEditor::focusedOutlineColourId));
  51392. g.drawRect (0, 0, button.getWidth(), button.getHeight());
  51393. }
  51394. float fontSize = jmin (15.0f, button.getHeight() * 0.75f);
  51395. const float tickWidth = fontSize * 1.1f;
  51396. drawTickBox (g, button, 4.0f, (button.getHeight() - tickWidth) * 0.5f,
  51397. tickWidth, tickWidth,
  51398. button.getToggleState(),
  51399. button.isEnabled(),
  51400. isMouseOverButton,
  51401. isButtonDown);
  51402. g.setColour (button.findColour (ToggleButton::textColourId));
  51403. g.setFont (fontSize);
  51404. if (! button.isEnabled())
  51405. g.setOpacity (0.5f);
  51406. const int textX = (int) tickWidth + 5;
  51407. g.drawFittedText (button.getButtonText(),
  51408. textX, 0,
  51409. button.getWidth() - textX - 2, button.getHeight(),
  51410. Justification::centredLeft, 10);
  51411. }
  51412. void LookAndFeel::changeToggleButtonWidthToFitText (ToggleButton& button)
  51413. {
  51414. Font font (jmin (15.0f, button.getHeight() * 0.6f));
  51415. const int tickWidth = jmin (24, button.getHeight());
  51416. button.setSize (font.getStringWidth (button.getButtonText()) + tickWidth + 8,
  51417. button.getHeight());
  51418. }
  51419. AlertWindow* LookAndFeel::createAlertWindow (const String& title,
  51420. const String& message,
  51421. const String& button1,
  51422. const String& button2,
  51423. const String& button3,
  51424. AlertWindow::AlertIconType iconType,
  51425. int numButtons,
  51426. Component* associatedComponent)
  51427. {
  51428. AlertWindow* aw = new AlertWindow (title, message, iconType, associatedComponent);
  51429. if (numButtons == 1)
  51430. {
  51431. aw->addButton (button1, 0,
  51432. KeyPress (KeyPress::escapeKey, 0, 0),
  51433. KeyPress (KeyPress::returnKey, 0, 0));
  51434. }
  51435. else
  51436. {
  51437. const KeyPress button1ShortCut (CharacterFunctions::toLowerCase (button1[0]), 0, 0);
  51438. KeyPress button2ShortCut (CharacterFunctions::toLowerCase (button2[0]), 0, 0);
  51439. if (button1ShortCut == button2ShortCut)
  51440. button2ShortCut = KeyPress();
  51441. if (numButtons == 2)
  51442. {
  51443. aw->addButton (button1, 1, KeyPress (KeyPress::returnKey, 0, 0), button1ShortCut);
  51444. aw->addButton (button2, 0, KeyPress (KeyPress::escapeKey, 0, 0), button2ShortCut);
  51445. }
  51446. else if (numButtons == 3)
  51447. {
  51448. aw->addButton (button1, 1, button1ShortCut);
  51449. aw->addButton (button2, 2, button2ShortCut);
  51450. aw->addButton (button3, 0, KeyPress (KeyPress::escapeKey, 0, 0));
  51451. }
  51452. }
  51453. return aw;
  51454. }
  51455. void LookAndFeel::drawAlertBox (Graphics& g,
  51456. AlertWindow& alert,
  51457. const Rectangle<int>& textArea,
  51458. TextLayout& textLayout)
  51459. {
  51460. g.fillAll (alert.findColour (AlertWindow::backgroundColourId));
  51461. int iconSpaceUsed = 0;
  51462. Justification alignment (Justification::horizontallyCentred);
  51463. const int iconWidth = 80;
  51464. int iconSize = jmin (iconWidth + 50, alert.getHeight() + 20);
  51465. if (alert.containsAnyExtraComponents() || alert.getNumButtons() > 2)
  51466. iconSize = jmin (iconSize, textArea.getHeight() + 50);
  51467. const Rectangle<int> iconRect (iconSize / -10, iconSize / -10,
  51468. iconSize, iconSize);
  51469. if (alert.getAlertType() != AlertWindow::NoIcon)
  51470. {
  51471. Path icon;
  51472. uint32 colour;
  51473. char character;
  51474. if (alert.getAlertType() == AlertWindow::WarningIcon)
  51475. {
  51476. colour = 0x55ff5555;
  51477. character = '!';
  51478. icon.addTriangle (iconRect.getX() + iconRect.getWidth() * 0.5f, (float) iconRect.getY(),
  51479. (float) iconRect.getRight(), (float) iconRect.getBottom(),
  51480. (float) iconRect.getX(), (float) iconRect.getBottom());
  51481. icon = icon.createPathWithRoundedCorners (5.0f);
  51482. }
  51483. else
  51484. {
  51485. colour = alert.getAlertType() == AlertWindow::InfoIcon ? 0x605555ff : 0x40b69900;
  51486. character = alert.getAlertType() == AlertWindow::InfoIcon ? 'i' : '?';
  51487. icon.addEllipse ((float) iconRect.getX(), (float) iconRect.getY(),
  51488. (float) iconRect.getWidth(), (float) iconRect.getHeight());
  51489. }
  51490. GlyphArrangement ga;
  51491. ga.addFittedText (Font (iconRect.getHeight() * 0.9f, Font::bold),
  51492. String::charToString (character),
  51493. (float) iconRect.getX(), (float) iconRect.getY(),
  51494. (float) iconRect.getWidth(), (float) iconRect.getHeight(),
  51495. Justification::centred, false);
  51496. ga.createPath (icon);
  51497. icon.setUsingNonZeroWinding (false);
  51498. g.setColour (Colour (colour));
  51499. g.fillPath (icon);
  51500. iconSpaceUsed = iconWidth;
  51501. alignment = Justification::left;
  51502. }
  51503. g.setColour (alert.findColour (AlertWindow::textColourId));
  51504. textLayout.drawWithin (g,
  51505. textArea.getX() + iconSpaceUsed, textArea.getY(),
  51506. textArea.getWidth() - iconSpaceUsed, textArea.getHeight(),
  51507. alignment.getFlags() | Justification::top);
  51508. g.setColour (alert.findColour (AlertWindow::outlineColourId));
  51509. g.drawRect (0, 0, alert.getWidth(), alert.getHeight());
  51510. }
  51511. int LookAndFeel::getAlertBoxWindowFlags()
  51512. {
  51513. return ComponentPeer::windowAppearsOnTaskbar
  51514. | ComponentPeer::windowHasDropShadow;
  51515. }
  51516. int LookAndFeel::getAlertWindowButtonHeight()
  51517. {
  51518. return 28;
  51519. }
  51520. const Font LookAndFeel::getAlertWindowFont()
  51521. {
  51522. return Font (12.0f);
  51523. }
  51524. void LookAndFeel::drawProgressBar (Graphics& g, ProgressBar& progressBar,
  51525. int width, int height,
  51526. double progress, const String& textToShow)
  51527. {
  51528. const Colour background (progressBar.findColour (ProgressBar::backgroundColourId));
  51529. const Colour foreground (progressBar.findColour (ProgressBar::foregroundColourId));
  51530. g.fillAll (background);
  51531. if (progress >= 0.0f && progress < 1.0f)
  51532. {
  51533. drawGlassLozenge (g, 1.0f, 1.0f,
  51534. (float) jlimit (0.0, width - 2.0, progress * (width - 2.0)),
  51535. (float) (height - 2),
  51536. foreground,
  51537. 0.5f, 0.0f,
  51538. true, true, true, true);
  51539. }
  51540. else
  51541. {
  51542. // spinning bar..
  51543. g.setColour (foreground);
  51544. const int stripeWidth = height * 2;
  51545. const int position = (Time::getMillisecondCounter() / 15) % stripeWidth;
  51546. Path p;
  51547. for (float x = (float) (- position); x < width + stripeWidth; x += stripeWidth)
  51548. p.addQuadrilateral (x, 0.0f,
  51549. x + stripeWidth * 0.5f, 0.0f,
  51550. x, (float) height,
  51551. x - stripeWidth * 0.5f, (float) height);
  51552. Image im (Image::ARGB, width, height, true);
  51553. {
  51554. Graphics g2 (im);
  51555. drawGlassLozenge (g2, 1.0f, 1.0f,
  51556. (float) (width - 2),
  51557. (float) (height - 2),
  51558. foreground,
  51559. 0.5f, 0.0f,
  51560. true, true, true, true);
  51561. }
  51562. g.setTiledImageFill (im, 0, 0, 0.85f);
  51563. g.fillPath (p);
  51564. }
  51565. if (textToShow.isNotEmpty())
  51566. {
  51567. g.setColour (Colour::contrasting (background, foreground));
  51568. g.setFont (height * 0.6f);
  51569. g.drawText (textToShow, 0, 0, width, height, Justification::centred, false);
  51570. }
  51571. }
  51572. void LookAndFeel::drawSpinningWaitAnimation (Graphics& g, const Colour& colour, int x, int y, int w, int h)
  51573. {
  51574. const float radius = jmin (w, h) * 0.4f;
  51575. const float thickness = radius * 0.15f;
  51576. Path p;
  51577. p.addRoundedRectangle (radius * 0.4f, thickness * -0.5f,
  51578. radius * 0.6f, thickness,
  51579. thickness * 0.5f);
  51580. const float cx = x + w * 0.5f;
  51581. const float cy = y + h * 0.5f;
  51582. const uint32 animationIndex = (Time::getMillisecondCounter() / (1000 / 10)) % 12;
  51583. for (int i = 0; i < 12; ++i)
  51584. {
  51585. const int n = (i + 12 - animationIndex) % 12;
  51586. g.setColour (colour.withMultipliedAlpha ((n + 1) / 12.0f));
  51587. g.fillPath (p, AffineTransform::rotation (i * (float_Pi / 6.0f))
  51588. .translated (cx, cy));
  51589. }
  51590. }
  51591. void LookAndFeel::drawScrollbarButton (Graphics& g,
  51592. ScrollBar& scrollbar,
  51593. int width, int height,
  51594. int buttonDirection,
  51595. bool /*isScrollbarVertical*/,
  51596. bool /*isMouseOverButton*/,
  51597. bool isButtonDown)
  51598. {
  51599. Path p;
  51600. if (buttonDirection == 0)
  51601. p.addTriangle (width * 0.5f, height * 0.2f,
  51602. width * 0.1f, height * 0.7f,
  51603. width * 0.9f, height * 0.7f);
  51604. else if (buttonDirection == 1)
  51605. p.addTriangle (width * 0.8f, height * 0.5f,
  51606. width * 0.3f, height * 0.1f,
  51607. width * 0.3f, height * 0.9f);
  51608. else if (buttonDirection == 2)
  51609. p.addTriangle (width * 0.5f, height * 0.8f,
  51610. width * 0.1f, height * 0.3f,
  51611. width * 0.9f, height * 0.3f);
  51612. else if (buttonDirection == 3)
  51613. p.addTriangle (width * 0.2f, height * 0.5f,
  51614. width * 0.7f, height * 0.1f,
  51615. width * 0.7f, height * 0.9f);
  51616. if (isButtonDown)
  51617. g.setColour (scrollbar.findColour (ScrollBar::thumbColourId).contrasting (0.2f));
  51618. else
  51619. g.setColour (scrollbar.findColour (ScrollBar::thumbColourId));
  51620. g.fillPath (p);
  51621. g.setColour (Colour (0x80000000));
  51622. g.strokePath (p, PathStrokeType (0.5f));
  51623. }
  51624. void LookAndFeel::drawScrollbar (Graphics& g,
  51625. ScrollBar& scrollbar,
  51626. int x, int y,
  51627. int width, int height,
  51628. bool isScrollbarVertical,
  51629. int thumbStartPosition,
  51630. int thumbSize,
  51631. bool /*isMouseOver*/,
  51632. bool /*isMouseDown*/)
  51633. {
  51634. g.fillAll (scrollbar.findColour (ScrollBar::backgroundColourId));
  51635. Path slotPath, thumbPath;
  51636. const float slotIndent = jmin (width, height) > 15 ? 1.0f : 0.0f;
  51637. const float slotIndentx2 = slotIndent * 2.0f;
  51638. const float thumbIndent = slotIndent + 1.0f;
  51639. const float thumbIndentx2 = thumbIndent * 2.0f;
  51640. float gx1 = 0.0f, gy1 = 0.0f, gx2 = 0.0f, gy2 = 0.0f;
  51641. if (isScrollbarVertical)
  51642. {
  51643. slotPath.addRoundedRectangle (x + slotIndent,
  51644. y + slotIndent,
  51645. width - slotIndentx2,
  51646. height - slotIndentx2,
  51647. (width - slotIndentx2) * 0.5f);
  51648. if (thumbSize > 0)
  51649. thumbPath.addRoundedRectangle (x + thumbIndent,
  51650. thumbStartPosition + thumbIndent,
  51651. width - thumbIndentx2,
  51652. thumbSize - thumbIndentx2,
  51653. (width - thumbIndentx2) * 0.5f);
  51654. gx1 = (float) x;
  51655. gx2 = x + width * 0.7f;
  51656. }
  51657. else
  51658. {
  51659. slotPath.addRoundedRectangle (x + slotIndent,
  51660. y + slotIndent,
  51661. width - slotIndentx2,
  51662. height - slotIndentx2,
  51663. (height - slotIndentx2) * 0.5f);
  51664. if (thumbSize > 0)
  51665. thumbPath.addRoundedRectangle (thumbStartPosition + thumbIndent,
  51666. y + thumbIndent,
  51667. thumbSize - thumbIndentx2,
  51668. height - thumbIndentx2,
  51669. (height - thumbIndentx2) * 0.5f);
  51670. gy1 = (float) y;
  51671. gy2 = y + height * 0.7f;
  51672. }
  51673. const Colour thumbColour (scrollbar.findColour (ScrollBar::thumbColourId));
  51674. g.setGradientFill (ColourGradient (thumbColour.overlaidWith (Colour (0x44000000)), gx1, gy1,
  51675. thumbColour.overlaidWith (Colour (0x19000000)), gx2, gy2, false));
  51676. g.fillPath (slotPath);
  51677. if (isScrollbarVertical)
  51678. {
  51679. gx1 = x + width * 0.6f;
  51680. gx2 = (float) x + width;
  51681. }
  51682. else
  51683. {
  51684. gy1 = y + height * 0.6f;
  51685. gy2 = (float) y + height;
  51686. }
  51687. g.setGradientFill (ColourGradient (Colours::transparentBlack,gx1, gy1,
  51688. Colour (0x19000000), gx2, gy2, false));
  51689. g.fillPath (slotPath);
  51690. g.setColour (thumbColour);
  51691. g.fillPath (thumbPath);
  51692. g.setGradientFill (ColourGradient (Colour (0x10000000), gx1, gy1,
  51693. Colours::transparentBlack, gx2, gy2, false));
  51694. g.saveState();
  51695. if (isScrollbarVertical)
  51696. g.reduceClipRegion (x + width / 2, y, width, height);
  51697. else
  51698. g.reduceClipRegion (x, y + height / 2, width, height);
  51699. g.fillPath (thumbPath);
  51700. g.restoreState();
  51701. g.setColour (Colour (0x4c000000));
  51702. g.strokePath (thumbPath, PathStrokeType (0.4f));
  51703. }
  51704. ImageEffectFilter* LookAndFeel::getScrollbarEffect()
  51705. {
  51706. return 0;
  51707. }
  51708. int LookAndFeel::getMinimumScrollbarThumbSize (ScrollBar& scrollbar)
  51709. {
  51710. return jmin (scrollbar.getWidth(), scrollbar.getHeight()) * 2;
  51711. }
  51712. int LookAndFeel::getDefaultScrollbarWidth()
  51713. {
  51714. return 18;
  51715. }
  51716. int LookAndFeel::getScrollbarButtonSize (ScrollBar& scrollbar)
  51717. {
  51718. return 2 + (scrollbar.isVertical() ? scrollbar.getWidth()
  51719. : scrollbar.getHeight());
  51720. }
  51721. const Path LookAndFeel::getTickShape (const float height)
  51722. {
  51723. static const unsigned char tickShapeData[] =
  51724. {
  51725. 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,
  51726. 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,
  51727. 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,
  51728. 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,
  51729. 96,140,68,0,128,188,67,0,224,168,68,0,0,119,67,99,101
  51730. };
  51731. Path p;
  51732. p.loadPathFromData (tickShapeData, sizeof (tickShapeData));
  51733. p.scaleToFit (0, 0, height * 2.0f, height, true);
  51734. return p;
  51735. }
  51736. const Path LookAndFeel::getCrossShape (const float height)
  51737. {
  51738. static const unsigned char crossShapeData[] =
  51739. {
  51740. 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,
  51741. 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,
  51742. 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,
  51743. 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,
  51744. 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,
  51745. 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,
  51746. 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
  51747. };
  51748. Path p;
  51749. p.loadPathFromData (crossShapeData, sizeof (crossShapeData));
  51750. p.scaleToFit (0, 0, height * 2.0f, height, true);
  51751. return p;
  51752. }
  51753. void LookAndFeel::drawTreeviewPlusMinusBox (Graphics& g, int x, int y, int w, int h, bool isPlus, bool /*isMouseOver*/)
  51754. {
  51755. const int boxSize = ((jmin (16, w, h) << 1) / 3) | 1;
  51756. x += (w - boxSize) >> 1;
  51757. y += (h - boxSize) >> 1;
  51758. w = boxSize;
  51759. h = boxSize;
  51760. g.setColour (Colour (0xe5ffffff));
  51761. g.fillRect (x, y, w, h);
  51762. g.setColour (Colour (0x80000000));
  51763. g.drawRect (x, y, w, h);
  51764. const float size = boxSize / 2 + 1.0f;
  51765. const float centre = (float) (boxSize / 2);
  51766. g.fillRect (x + (w - size) * 0.5f, y + centre, size, 1.0f);
  51767. if (isPlus)
  51768. g.fillRect (x + centre, y + (h - size) * 0.5f, 1.0f, size);
  51769. }
  51770. void LookAndFeel::drawBubble (Graphics& g,
  51771. float tipX, float tipY,
  51772. float boxX, float boxY,
  51773. float boxW, float boxH)
  51774. {
  51775. int side = 0;
  51776. if (tipX < boxX)
  51777. side = 1;
  51778. else if (tipX > boxX + boxW)
  51779. side = 3;
  51780. else if (tipY > boxY + boxH)
  51781. side = 2;
  51782. const float indent = 2.0f;
  51783. Path p;
  51784. p.addBubble (boxX + indent,
  51785. boxY + indent,
  51786. boxW - indent * 2.0f,
  51787. boxH - indent * 2.0f,
  51788. 5.0f,
  51789. tipX, tipY,
  51790. side,
  51791. 0.5f,
  51792. jmin (15.0f, boxW * 0.3f, boxH * 0.3f));
  51793. //xxx need to take comp as param for colour
  51794. g.setColour (findColour (TooltipWindow::backgroundColourId).withAlpha (0.9f));
  51795. g.fillPath (p);
  51796. //xxx as above
  51797. g.setColour (findColour (TooltipWindow::textColourId).withAlpha (0.4f));
  51798. g.strokePath (p, PathStrokeType (1.33f));
  51799. }
  51800. const Font LookAndFeel::getPopupMenuFont()
  51801. {
  51802. return Font (17.0f);
  51803. }
  51804. void LookAndFeel::getIdealPopupMenuItemSize (const String& text,
  51805. const bool isSeparator,
  51806. int standardMenuItemHeight,
  51807. int& idealWidth,
  51808. int& idealHeight)
  51809. {
  51810. if (isSeparator)
  51811. {
  51812. idealWidth = 50;
  51813. idealHeight = standardMenuItemHeight > 0 ? standardMenuItemHeight / 2 : 10;
  51814. }
  51815. else
  51816. {
  51817. Font font (getPopupMenuFont());
  51818. if (standardMenuItemHeight > 0 && font.getHeight() > standardMenuItemHeight / 1.3f)
  51819. font.setHeight (standardMenuItemHeight / 1.3f);
  51820. idealHeight = standardMenuItemHeight > 0 ? standardMenuItemHeight : roundToInt (font.getHeight() * 1.3f);
  51821. idealWidth = font.getStringWidth (text) + idealHeight * 2;
  51822. }
  51823. }
  51824. void LookAndFeel::drawPopupMenuBackground (Graphics& g, int width, int height)
  51825. {
  51826. const Colour background (findColour (PopupMenu::backgroundColourId));
  51827. g.fillAll (background);
  51828. g.setColour (background.overlaidWith (Colour (0x2badd8e6)));
  51829. for (int i = 0; i < height; i += 3)
  51830. g.fillRect (0, i, width, 1);
  51831. #if ! JUCE_MAC
  51832. g.setColour (findColour (PopupMenu::textColourId).withAlpha (0.6f));
  51833. g.drawRect (0, 0, width, height);
  51834. #endif
  51835. }
  51836. void LookAndFeel::drawPopupMenuUpDownArrow (Graphics& g,
  51837. int width, int height,
  51838. bool isScrollUpArrow)
  51839. {
  51840. const Colour background (findColour (PopupMenu::backgroundColourId));
  51841. g.setGradientFill (ColourGradient (background, 0.0f, height * 0.5f,
  51842. background.withAlpha (0.0f),
  51843. 0.0f, isScrollUpArrow ? ((float) height) : 0.0f,
  51844. false));
  51845. g.fillRect (1, 1, width - 2, height - 2);
  51846. const float hw = width * 0.5f;
  51847. const float arrowW = height * 0.3f;
  51848. const float y1 = height * (isScrollUpArrow ? 0.6f : 0.3f);
  51849. const float y2 = height * (isScrollUpArrow ? 0.3f : 0.6f);
  51850. Path p;
  51851. p.addTriangle (hw - arrowW, y1,
  51852. hw + arrowW, y1,
  51853. hw, y2);
  51854. g.setColour (findColour (PopupMenu::textColourId).withAlpha (0.5f));
  51855. g.fillPath (p);
  51856. }
  51857. void LookAndFeel::drawPopupMenuItem (Graphics& g,
  51858. int width, int height,
  51859. const bool isSeparator,
  51860. const bool isActive,
  51861. const bool isHighlighted,
  51862. const bool isTicked,
  51863. const bool hasSubMenu,
  51864. const String& text,
  51865. const String& shortcutKeyText,
  51866. Image* image,
  51867. const Colour* const textColourToUse)
  51868. {
  51869. const float halfH = height * 0.5f;
  51870. if (isSeparator)
  51871. {
  51872. const float separatorIndent = 5.5f;
  51873. g.setColour (Colour (0x33000000));
  51874. g.drawLine (separatorIndent, halfH, width - separatorIndent, halfH);
  51875. g.setColour (Colour (0x66ffffff));
  51876. g.drawLine (separatorIndent, halfH + 1.0f, width - separatorIndent, halfH + 1.0f);
  51877. }
  51878. else
  51879. {
  51880. Colour textColour (findColour (PopupMenu::textColourId));
  51881. if (textColourToUse != 0)
  51882. textColour = *textColourToUse;
  51883. if (isHighlighted)
  51884. {
  51885. g.setColour (findColour (PopupMenu::highlightedBackgroundColourId));
  51886. g.fillRect (1, 1, width - 2, height - 2);
  51887. g.setColour (findColour (PopupMenu::highlightedTextColourId));
  51888. }
  51889. else
  51890. {
  51891. g.setColour (textColour);
  51892. }
  51893. if (! isActive)
  51894. g.setOpacity (0.3f);
  51895. Font font (getPopupMenuFont());
  51896. if (font.getHeight() > height / 1.3f)
  51897. font.setHeight (height / 1.3f);
  51898. g.setFont (font);
  51899. const int leftBorder = (height * 5) / 4;
  51900. const int rightBorder = 4;
  51901. if (image != 0)
  51902. {
  51903. g.drawImageWithin (image,
  51904. 2, 1, leftBorder - 4, height - 2,
  51905. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize, false);
  51906. }
  51907. else if (isTicked)
  51908. {
  51909. const Path tick (getTickShape (1.0f));
  51910. const float th = font.getAscent();
  51911. const float ty = halfH - th * 0.5f;
  51912. g.fillPath (tick, tick.getTransformToScaleToFit (2.0f, ty, (float) (leftBorder - 4),
  51913. th, true));
  51914. }
  51915. g.drawFittedText (text,
  51916. leftBorder, 0,
  51917. width - (leftBorder + rightBorder), height,
  51918. Justification::centredLeft, 1);
  51919. if (shortcutKeyText.isNotEmpty())
  51920. {
  51921. Font f2 (font);
  51922. f2.setHeight (f2.getHeight() * 0.75f);
  51923. f2.setHorizontalScale (0.95f);
  51924. g.setFont (f2);
  51925. g.drawText (shortcutKeyText,
  51926. leftBorder,
  51927. 0,
  51928. width - (leftBorder + rightBorder + 4),
  51929. height,
  51930. Justification::centredRight,
  51931. true);
  51932. }
  51933. if (hasSubMenu)
  51934. {
  51935. const float arrowH = 0.6f * getPopupMenuFont().getAscent();
  51936. const float x = width - height * 0.6f;
  51937. Path p;
  51938. p.addTriangle (x, halfH - arrowH * 0.5f,
  51939. x, halfH + arrowH * 0.5f,
  51940. x + arrowH * 0.6f, halfH);
  51941. g.fillPath (p);
  51942. }
  51943. }
  51944. }
  51945. int LookAndFeel::getMenuWindowFlags()
  51946. {
  51947. return ComponentPeer::windowHasDropShadow;
  51948. }
  51949. void LookAndFeel::drawMenuBarBackground (Graphics& g, int width, int height,
  51950. bool, MenuBarComponent& menuBar)
  51951. {
  51952. const Colour baseColour (createBaseColour (menuBar.findColour (PopupMenu::backgroundColourId), false, false, false));
  51953. if (menuBar.isEnabled())
  51954. {
  51955. drawShinyButtonShape (g,
  51956. -4.0f, 0.0f,
  51957. width + 8.0f, (float) height,
  51958. 0.0f,
  51959. baseColour,
  51960. 0.4f,
  51961. true, true, true, true);
  51962. }
  51963. else
  51964. {
  51965. g.fillAll (baseColour);
  51966. }
  51967. }
  51968. const Font LookAndFeel::getMenuBarFont (MenuBarComponent& menuBar, int /*itemIndex*/, const String& /*itemText*/)
  51969. {
  51970. return Font (menuBar.getHeight() * 0.7f);
  51971. }
  51972. int LookAndFeel::getMenuBarItemWidth (MenuBarComponent& menuBar, int itemIndex, const String& itemText)
  51973. {
  51974. return getMenuBarFont (menuBar, itemIndex, itemText)
  51975. .getStringWidth (itemText) + menuBar.getHeight();
  51976. }
  51977. void LookAndFeel::drawMenuBarItem (Graphics& g,
  51978. int width, int height,
  51979. int itemIndex,
  51980. const String& itemText,
  51981. bool isMouseOverItem,
  51982. bool isMenuOpen,
  51983. bool /*isMouseOverBar*/,
  51984. MenuBarComponent& menuBar)
  51985. {
  51986. if (! menuBar.isEnabled())
  51987. {
  51988. g.setColour (menuBar.findColour (PopupMenu::textColourId)
  51989. .withMultipliedAlpha (0.5f));
  51990. }
  51991. else if (isMenuOpen || isMouseOverItem)
  51992. {
  51993. g.fillAll (menuBar.findColour (PopupMenu::highlightedBackgroundColourId));
  51994. g.setColour (menuBar.findColour (PopupMenu::highlightedTextColourId));
  51995. }
  51996. else
  51997. {
  51998. g.setColour (menuBar.findColour (PopupMenu::textColourId));
  51999. }
  52000. g.setFont (getMenuBarFont (menuBar, itemIndex, itemText));
  52001. g.drawFittedText (itemText, 0, 0, width, height, Justification::centred, 1);
  52002. }
  52003. void LookAndFeel::fillTextEditorBackground (Graphics& g, int /*width*/, int /*height*/,
  52004. TextEditor& textEditor)
  52005. {
  52006. g.fillAll (textEditor.findColour (TextEditor::backgroundColourId));
  52007. }
  52008. void LookAndFeel::drawTextEditorOutline (Graphics& g, int width, int height, TextEditor& textEditor)
  52009. {
  52010. if (textEditor.isEnabled())
  52011. {
  52012. if (textEditor.hasKeyboardFocus (true) && ! textEditor.isReadOnly())
  52013. {
  52014. const int border = 2;
  52015. g.setColour (textEditor.findColour (TextEditor::focusedOutlineColourId));
  52016. g.drawRect (0, 0, width, height, border);
  52017. g.setOpacity (1.0f);
  52018. const Colour shadowColour (textEditor.findColour (TextEditor::shadowColourId).withMultipliedAlpha (0.75f));
  52019. g.drawBevel (0, 0, width, height + 2, border + 2, shadowColour, shadowColour);
  52020. }
  52021. else
  52022. {
  52023. g.setColour (textEditor.findColour (TextEditor::outlineColourId));
  52024. g.drawRect (0, 0, width, height);
  52025. g.setOpacity (1.0f);
  52026. const Colour shadowColour (textEditor.findColour (TextEditor::shadowColourId));
  52027. g.drawBevel (0, 0, width, height + 2, 3, shadowColour, shadowColour);
  52028. }
  52029. }
  52030. }
  52031. void LookAndFeel::drawComboBox (Graphics& g, int width, int height,
  52032. const bool isButtonDown,
  52033. int buttonX, int buttonY,
  52034. int buttonW, int buttonH,
  52035. ComboBox& box)
  52036. {
  52037. g.fillAll (box.findColour (ComboBox::backgroundColourId));
  52038. if (box.isEnabled() && box.hasKeyboardFocus (false))
  52039. {
  52040. g.setColour (box.findColour (TextButton::buttonColourId));
  52041. g.drawRect (0, 0, width, height, 2);
  52042. }
  52043. else
  52044. {
  52045. g.setColour (box.findColour (ComboBox::outlineColourId));
  52046. g.drawRect (0, 0, width, height);
  52047. }
  52048. const float outlineThickness = box.isEnabled() ? (isButtonDown ? 1.2f : 0.5f) : 0.3f;
  52049. const Colour baseColour (createBaseColour (box.findColour (ComboBox::buttonColourId),
  52050. box.hasKeyboardFocus (true),
  52051. false, isButtonDown)
  52052. .withMultipliedAlpha (box.isEnabled() ? 1.0f : 0.5f));
  52053. drawGlassLozenge (g,
  52054. buttonX + outlineThickness, buttonY + outlineThickness,
  52055. buttonW - outlineThickness * 2.0f, buttonH - outlineThickness * 2.0f,
  52056. baseColour, outlineThickness, -1.0f,
  52057. true, true, true, true);
  52058. if (box.isEnabled())
  52059. {
  52060. const float arrowX = 0.3f;
  52061. const float arrowH = 0.2f;
  52062. Path p;
  52063. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.45f - arrowH),
  52064. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.45f,
  52065. buttonX + buttonW * arrowX, buttonY + buttonH * 0.45f);
  52066. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.55f + arrowH),
  52067. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.55f,
  52068. buttonX + buttonW * arrowX, buttonY + buttonH * 0.55f);
  52069. g.setColour (box.findColour (ComboBox::arrowColourId));
  52070. g.fillPath (p);
  52071. }
  52072. }
  52073. const Font LookAndFeel::getComboBoxFont (ComboBox& box)
  52074. {
  52075. return Font (jmin (15.0f, box.getHeight() * 0.85f));
  52076. }
  52077. Label* LookAndFeel::createComboBoxTextBox (ComboBox&)
  52078. {
  52079. return new Label (String::empty, String::empty);
  52080. }
  52081. void LookAndFeel::positionComboBoxText (ComboBox& box, Label& label)
  52082. {
  52083. label.setBounds (1, 1,
  52084. box.getWidth() + 3 - box.getHeight(),
  52085. box.getHeight() - 2);
  52086. label.setFont (getComboBoxFont (box));
  52087. }
  52088. void LookAndFeel::drawLabel (Graphics& g, Label& label)
  52089. {
  52090. g.fillAll (label.findColour (Label::backgroundColourId));
  52091. if (! label.isBeingEdited())
  52092. {
  52093. const float alpha = label.isEnabled() ? 1.0f : 0.5f;
  52094. g.setColour (label.findColour (Label::textColourId).withMultipliedAlpha (alpha));
  52095. g.setFont (label.getFont());
  52096. g.drawFittedText (label.getText(),
  52097. label.getHorizontalBorderSize(),
  52098. label.getVerticalBorderSize(),
  52099. label.getWidth() - 2 * label.getHorizontalBorderSize(),
  52100. label.getHeight() - 2 * label.getVerticalBorderSize(),
  52101. label.getJustificationType(),
  52102. jmax (1, (int) (label.getHeight() / label.getFont().getHeight())),
  52103. label.getMinimumHorizontalScale());
  52104. g.setColour (label.findColour (Label::outlineColourId).withMultipliedAlpha (alpha));
  52105. g.drawRect (0, 0, label.getWidth(), label.getHeight());
  52106. }
  52107. else if (label.isEnabled())
  52108. {
  52109. g.setColour (label.findColour (Label::outlineColourId));
  52110. g.drawRect (0, 0, label.getWidth(), label.getHeight());
  52111. }
  52112. }
  52113. void LookAndFeel::drawLinearSliderBackground (Graphics& g,
  52114. int x, int y,
  52115. int width, int height,
  52116. float /*sliderPos*/,
  52117. float /*minSliderPos*/,
  52118. float /*maxSliderPos*/,
  52119. const Slider::SliderStyle /*style*/,
  52120. Slider& slider)
  52121. {
  52122. const float sliderRadius = (float) (getSliderThumbRadius (slider) - 2);
  52123. const Colour trackColour (slider.findColour (Slider::trackColourId));
  52124. const Colour gradCol1 (trackColour.overlaidWith (Colours::black.withAlpha (slider.isEnabled() ? 0.25f : 0.13f)));
  52125. const Colour gradCol2 (trackColour.overlaidWith (Colour (0x14000000)));
  52126. Path indent;
  52127. if (slider.isHorizontal())
  52128. {
  52129. const float iy = y + height * 0.5f - sliderRadius * 0.5f;
  52130. const float ih = sliderRadius;
  52131. g.setGradientFill (ColourGradient (gradCol1, 0.0f, iy,
  52132. gradCol2, 0.0f, iy + ih, false));
  52133. indent.addRoundedRectangle (x - sliderRadius * 0.5f, iy,
  52134. width + sliderRadius, ih,
  52135. 5.0f);
  52136. g.fillPath (indent);
  52137. }
  52138. else
  52139. {
  52140. const float ix = x + width * 0.5f - sliderRadius * 0.5f;
  52141. const float iw = sliderRadius;
  52142. g.setGradientFill (ColourGradient (gradCol1, ix, 0.0f,
  52143. gradCol2, ix + iw, 0.0f, false));
  52144. indent.addRoundedRectangle (ix, y - sliderRadius * 0.5f,
  52145. iw, height + sliderRadius,
  52146. 5.0f);
  52147. g.fillPath (indent);
  52148. }
  52149. g.setColour (Colour (0x4c000000));
  52150. g.strokePath (indent, PathStrokeType (0.5f));
  52151. }
  52152. void LookAndFeel::drawLinearSliderThumb (Graphics& g,
  52153. int x, int y,
  52154. int width, int height,
  52155. float sliderPos,
  52156. float minSliderPos,
  52157. float maxSliderPos,
  52158. const Slider::SliderStyle style,
  52159. Slider& slider)
  52160. {
  52161. const float sliderRadius = (float) (getSliderThumbRadius (slider) - 2);
  52162. Colour knobColour (createBaseColour (slider.findColour (Slider::thumbColourId),
  52163. slider.hasKeyboardFocus (false) && slider.isEnabled(),
  52164. slider.isMouseOverOrDragging() && slider.isEnabled(),
  52165. slider.isMouseButtonDown() && slider.isEnabled()));
  52166. const float outlineThickness = slider.isEnabled() ? 0.8f : 0.3f;
  52167. if (style == Slider::LinearHorizontal || style == Slider::LinearVertical)
  52168. {
  52169. float kx, ky;
  52170. if (style == Slider::LinearVertical)
  52171. {
  52172. kx = x + width * 0.5f;
  52173. ky = sliderPos;
  52174. }
  52175. else
  52176. {
  52177. kx = sliderPos;
  52178. ky = y + height * 0.5f;
  52179. }
  52180. drawGlassSphere (g,
  52181. kx - sliderRadius,
  52182. ky - sliderRadius,
  52183. sliderRadius * 2.0f,
  52184. knobColour, outlineThickness);
  52185. }
  52186. else
  52187. {
  52188. if (style == Slider::ThreeValueVertical)
  52189. {
  52190. drawGlassSphere (g, x + width * 0.5f - sliderRadius,
  52191. sliderPos - sliderRadius,
  52192. sliderRadius * 2.0f,
  52193. knobColour, outlineThickness);
  52194. }
  52195. else if (style == Slider::ThreeValueHorizontal)
  52196. {
  52197. drawGlassSphere (g,sliderPos - sliderRadius,
  52198. y + height * 0.5f - sliderRadius,
  52199. sliderRadius * 2.0f,
  52200. knobColour, outlineThickness);
  52201. }
  52202. if (style == Slider::TwoValueVertical || style == Slider::ThreeValueVertical)
  52203. {
  52204. const float sr = jmin (sliderRadius, width * 0.4f);
  52205. drawGlassPointer (g, jmax (0.0f, x + width * 0.5f - sliderRadius * 2.0f),
  52206. minSliderPos - sliderRadius,
  52207. sliderRadius * 2.0f, knobColour, outlineThickness, 1);
  52208. drawGlassPointer (g, jmin (x + width - sliderRadius * 2.0f, x + width * 0.5f), maxSliderPos - sr,
  52209. sliderRadius * 2.0f, knobColour, outlineThickness, 3);
  52210. }
  52211. else if (style == Slider::TwoValueHorizontal || style == Slider::ThreeValueHorizontal)
  52212. {
  52213. const float sr = jmin (sliderRadius, height * 0.4f);
  52214. drawGlassPointer (g, minSliderPos - sr,
  52215. jmax (0.0f, y + height * 0.5f - sliderRadius * 2.0f),
  52216. sliderRadius * 2.0f, knobColour, outlineThickness, 2);
  52217. drawGlassPointer (g, maxSliderPos - sliderRadius,
  52218. jmin (y + height - sliderRadius * 2.0f, y + height * 0.5f),
  52219. sliderRadius * 2.0f, knobColour, outlineThickness, 4);
  52220. }
  52221. }
  52222. }
  52223. void LookAndFeel::drawLinearSlider (Graphics& g,
  52224. int x, int y,
  52225. int width, int height,
  52226. float sliderPos,
  52227. float minSliderPos,
  52228. float maxSliderPos,
  52229. const Slider::SliderStyle style,
  52230. Slider& slider)
  52231. {
  52232. g.fillAll (slider.findColour (Slider::backgroundColourId));
  52233. if (style == Slider::LinearBar)
  52234. {
  52235. const bool isMouseOver = slider.isMouseOverOrDragging() && slider.isEnabled();
  52236. Colour baseColour (createBaseColour (slider.findColour (Slider::thumbColourId)
  52237. .withMultipliedSaturation (slider.isEnabled() ? 1.0f : 0.5f),
  52238. false,
  52239. isMouseOver,
  52240. isMouseOver || slider.isMouseButtonDown()));
  52241. drawShinyButtonShape (g,
  52242. (float) x, (float) y, sliderPos - (float) x, (float) height, 0.0f,
  52243. baseColour,
  52244. slider.isEnabled() ? 0.9f : 0.3f,
  52245. true, true, true, true);
  52246. }
  52247. else
  52248. {
  52249. drawLinearSliderBackground (g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
  52250. drawLinearSliderThumb (g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
  52251. }
  52252. }
  52253. int LookAndFeel::getSliderThumbRadius (Slider& slider)
  52254. {
  52255. return jmin (7,
  52256. slider.getHeight() / 2,
  52257. slider.getWidth() / 2) + 2;
  52258. }
  52259. void LookAndFeel::drawRotarySlider (Graphics& g,
  52260. int x, int y,
  52261. int width, int height,
  52262. float sliderPos,
  52263. const float rotaryStartAngle,
  52264. const float rotaryEndAngle,
  52265. Slider& slider)
  52266. {
  52267. const float radius = jmin (width / 2, height / 2) - 2.0f;
  52268. const float centreX = x + width * 0.5f;
  52269. const float centreY = y + height * 0.5f;
  52270. const float rx = centreX - radius;
  52271. const float ry = centreY - radius;
  52272. const float rw = radius * 2.0f;
  52273. const float angle = rotaryStartAngle + sliderPos * (rotaryEndAngle - rotaryStartAngle);
  52274. const bool isMouseOver = slider.isMouseOverOrDragging() && slider.isEnabled();
  52275. if (radius > 12.0f)
  52276. {
  52277. if (slider.isEnabled())
  52278. g.setColour (slider.findColour (Slider::rotarySliderFillColourId).withAlpha (isMouseOver ? 1.0f : 0.7f));
  52279. else
  52280. g.setColour (Colour (0x80808080));
  52281. const float thickness = 0.7f;
  52282. {
  52283. Path filledArc;
  52284. filledArc.addPieSegment (rx, ry, rw, rw,
  52285. rotaryStartAngle,
  52286. angle,
  52287. thickness);
  52288. g.fillPath (filledArc);
  52289. }
  52290. if (thickness > 0)
  52291. {
  52292. const float innerRadius = radius * 0.2f;
  52293. Path p;
  52294. p.addTriangle (-innerRadius, 0.0f,
  52295. 0.0f, -radius * thickness * 1.1f,
  52296. innerRadius, 0.0f);
  52297. p.addEllipse (-innerRadius, -innerRadius, innerRadius * 2.0f, innerRadius * 2.0f);
  52298. g.fillPath (p, AffineTransform::rotation (angle).translated (centreX, centreY));
  52299. }
  52300. if (slider.isEnabled())
  52301. g.setColour (slider.findColour (Slider::rotarySliderOutlineColourId));
  52302. else
  52303. g.setColour (Colour (0x80808080));
  52304. Path outlineArc;
  52305. outlineArc.addPieSegment (rx, ry, rw, rw, rotaryStartAngle, rotaryEndAngle, thickness);
  52306. outlineArc.closeSubPath();
  52307. g.strokePath (outlineArc, PathStrokeType (slider.isEnabled() ? (isMouseOver ? 2.0f : 1.2f) : 0.3f));
  52308. }
  52309. else
  52310. {
  52311. if (slider.isEnabled())
  52312. g.setColour (slider.findColour (Slider::rotarySliderFillColourId).withAlpha (isMouseOver ? 1.0f : 0.7f));
  52313. else
  52314. g.setColour (Colour (0x80808080));
  52315. Path p;
  52316. p.addEllipse (-0.4f * rw, -0.4f * rw, rw * 0.8f, rw * 0.8f);
  52317. PathStrokeType (rw * 0.1f).createStrokedPath (p, p);
  52318. p.addLineSegment (0.0f, 0.0f, 0.0f, -radius, rw * 0.2f);
  52319. g.fillPath (p, AffineTransform::rotation (angle).translated (centreX, centreY));
  52320. }
  52321. }
  52322. Button* LookAndFeel::createSliderButton (const bool isIncrement)
  52323. {
  52324. return new TextButton (isIncrement ? "+" : "-", String::empty);
  52325. }
  52326. class SliderLabelComp : public Label
  52327. {
  52328. public:
  52329. SliderLabelComp() : Label (String::empty, String::empty) {}
  52330. ~SliderLabelComp() {}
  52331. void mouseWheelMove (const MouseEvent&, float, float) {}
  52332. };
  52333. Label* LookAndFeel::createSliderTextBox (Slider& slider)
  52334. {
  52335. Label* const l = new SliderLabelComp();
  52336. l->setJustificationType (Justification::centred);
  52337. l->setColour (Label::textColourId, slider.findColour (Slider::textBoxTextColourId));
  52338. l->setColour (Label::backgroundColourId,
  52339. (slider.getSliderStyle() == Slider::LinearBar) ? Colours::transparentBlack
  52340. : slider.findColour (Slider::textBoxBackgroundColourId));
  52341. l->setColour (Label::outlineColourId, slider.findColour (Slider::textBoxOutlineColourId));
  52342. l->setColour (TextEditor::textColourId, slider.findColour (Slider::textBoxTextColourId));
  52343. l->setColour (TextEditor::backgroundColourId,
  52344. slider.findColour (Slider::textBoxBackgroundColourId)
  52345. .withAlpha (slider.getSliderStyle() == Slider::LinearBar ? 0.7f : 1.0f));
  52346. l->setColour (TextEditor::outlineColourId, slider.findColour (Slider::textBoxOutlineColourId));
  52347. return l;
  52348. }
  52349. ImageEffectFilter* LookAndFeel::getSliderEffect()
  52350. {
  52351. return 0;
  52352. }
  52353. static const TextLayout layoutTooltipText (const String& text) throw()
  52354. {
  52355. const float tooltipFontSize = 12.0f;
  52356. const int maxToolTipWidth = 400;
  52357. const Font f (tooltipFontSize, Font::bold);
  52358. TextLayout tl (text, f);
  52359. tl.layout (maxToolTipWidth, Justification::left, true);
  52360. return tl;
  52361. }
  52362. void LookAndFeel::getTooltipSize (const String& tipText, int& width, int& height)
  52363. {
  52364. const TextLayout tl (layoutTooltipText (tipText));
  52365. width = tl.getWidth() + 14;
  52366. height = tl.getHeight() + 6;
  52367. }
  52368. void LookAndFeel::drawTooltip (Graphics& g, const String& text, int width, int height)
  52369. {
  52370. g.fillAll (findColour (TooltipWindow::backgroundColourId));
  52371. const Colour textCol (findColour (TooltipWindow::textColourId));
  52372. #if ! JUCE_MAC // The mac windows already have a non-optional 1 pix outline, so don't double it here..
  52373. g.setColour (findColour (TooltipWindow::outlineColourId));
  52374. g.drawRect (0, 0, width, height, 1);
  52375. #endif
  52376. const TextLayout tl (layoutTooltipText (text));
  52377. g.setColour (findColour (TooltipWindow::textColourId));
  52378. tl.drawWithin (g, 0, 0, width, height, Justification::centred);
  52379. }
  52380. Button* LookAndFeel::createFilenameComponentBrowseButton (const String& text)
  52381. {
  52382. return new TextButton (text, TRANS("click to browse for a different file"));
  52383. }
  52384. void LookAndFeel::layoutFilenameComponent (FilenameComponent& filenameComp,
  52385. ComboBox* filenameBox,
  52386. Button* browseButton)
  52387. {
  52388. browseButton->setSize (80, filenameComp.getHeight());
  52389. TextButton* const tb = dynamic_cast <TextButton*> (browseButton);
  52390. if (tb != 0)
  52391. tb->changeWidthToFitText();
  52392. browseButton->setTopRightPosition (filenameComp.getWidth(), 0);
  52393. filenameBox->setBounds (0, 0, browseButton->getX(), filenameComp.getHeight());
  52394. }
  52395. void LookAndFeel::drawImageButton (Graphics& g, Image* image,
  52396. int imageX, int imageY, int imageW, int imageH,
  52397. const Colour& overlayColour,
  52398. float imageOpacity,
  52399. ImageButton& button)
  52400. {
  52401. if (! button.isEnabled())
  52402. imageOpacity *= 0.3f;
  52403. if (! overlayColour.isOpaque())
  52404. {
  52405. g.setOpacity (imageOpacity);
  52406. g.drawImage (image, imageX, imageY, imageW, imageH,
  52407. 0, 0, image->getWidth(), image->getHeight(), false);
  52408. }
  52409. if (! overlayColour.isTransparent())
  52410. {
  52411. g.setColour (overlayColour);
  52412. g.drawImage (image, imageX, imageY, imageW, imageH,
  52413. 0, 0, image->getWidth(), image->getHeight(), true);
  52414. }
  52415. }
  52416. void LookAndFeel::drawCornerResizer (Graphics& g,
  52417. int w, int h,
  52418. bool /*isMouseOver*/,
  52419. bool /*isMouseDragging*/)
  52420. {
  52421. const float lineThickness = jmin (w, h) * 0.075f;
  52422. for (float i = 0.0f; i < 1.0f; i += 0.3f)
  52423. {
  52424. g.setColour (Colours::lightgrey);
  52425. g.drawLine (w * i,
  52426. h + 1.0f,
  52427. w + 1.0f,
  52428. h * i,
  52429. lineThickness);
  52430. g.setColour (Colours::darkgrey);
  52431. g.drawLine (w * i + lineThickness,
  52432. h + 1.0f,
  52433. w + 1.0f,
  52434. h * i + lineThickness,
  52435. lineThickness);
  52436. }
  52437. }
  52438. void LookAndFeel::drawResizableFrame (Graphics&, int /*w*/, int /*h*/,
  52439. const BorderSize& /*borders*/)
  52440. {
  52441. }
  52442. void LookAndFeel::fillResizableWindowBackground (Graphics& g, int /*w*/, int /*h*/,
  52443. const BorderSize& /*border*/, ResizableWindow& window)
  52444. {
  52445. g.fillAll (window.getBackgroundColour());
  52446. }
  52447. void LookAndFeel::drawResizableWindowBorder (Graphics& g, int w, int h,
  52448. const BorderSize& border, ResizableWindow&)
  52449. {
  52450. g.setColour (Colour (0x80000000));
  52451. g.drawRect (0, 0, w, h);
  52452. g.setColour (Colour (0x19000000));
  52453. g.drawRect (border.getLeft() - 1,
  52454. border.getTop() - 1,
  52455. w + 2 - border.getLeftAndRight(),
  52456. h + 2 - border.getTopAndBottom());
  52457. }
  52458. void LookAndFeel::drawDocumentWindowTitleBar (DocumentWindow& window,
  52459. Graphics& g, int w, int h,
  52460. int titleSpaceX, int titleSpaceW,
  52461. const Image* icon,
  52462. bool drawTitleTextOnLeft)
  52463. {
  52464. const bool isActive = window.isActiveWindow();
  52465. g.setGradientFill (ColourGradient (window.getBackgroundColour(),
  52466. 0.0f, 0.0f,
  52467. window.getBackgroundColour().contrasting (isActive ? 0.15f : 0.05f),
  52468. 0.0f, (float) h, false));
  52469. g.fillAll();
  52470. Font font (h * 0.65f, Font::bold);
  52471. g.setFont (font);
  52472. int textW = font.getStringWidth (window.getName());
  52473. int iconW = 0;
  52474. int iconH = 0;
  52475. if (icon != 0)
  52476. {
  52477. iconH = (int) font.getHeight();
  52478. iconW = icon->getWidth() * iconH / icon->getHeight() + 4;
  52479. }
  52480. textW = jmin (titleSpaceW, textW + iconW);
  52481. int textX = drawTitleTextOnLeft ? titleSpaceX
  52482. : jmax (titleSpaceX, (w - textW) / 2);
  52483. if (textX + textW > titleSpaceX + titleSpaceW)
  52484. textX = titleSpaceX + titleSpaceW - textW;
  52485. if (icon != 0)
  52486. {
  52487. g.setOpacity (isActive ? 1.0f : 0.6f);
  52488. g.drawImageWithin (icon, textX, (h - iconH) / 2, iconW, iconH,
  52489. RectanglePlacement::centred, false);
  52490. textX += iconW;
  52491. textW -= iconW;
  52492. }
  52493. if (window.isColourSpecified (DocumentWindow::textColourId) || isColourSpecified (DocumentWindow::textColourId))
  52494. g.setColour (findColour (DocumentWindow::textColourId));
  52495. else
  52496. g.setColour (window.getBackgroundColour().contrasting (isActive ? 0.7f : 0.4f));
  52497. g.drawText (window.getName(), textX, 0, textW, h, Justification::centredLeft, true);
  52498. }
  52499. class GlassWindowButton : public Button
  52500. {
  52501. public:
  52502. GlassWindowButton (const String& name, const Colour& col,
  52503. const Path& normalShape_,
  52504. const Path& toggledShape_) throw()
  52505. : Button (name),
  52506. colour (col),
  52507. normalShape (normalShape_),
  52508. toggledShape (toggledShape_)
  52509. {
  52510. }
  52511. ~GlassWindowButton()
  52512. {
  52513. }
  52514. void paintButton (Graphics& g, bool isMouseOverButton, bool isButtonDown)
  52515. {
  52516. float alpha = isMouseOverButton ? (isButtonDown ? 1.0f : 0.8f) : 0.55f;
  52517. if (! isEnabled())
  52518. alpha *= 0.5f;
  52519. float x = 0, y = 0, diam;
  52520. if (getWidth() < getHeight())
  52521. {
  52522. diam = (float) getWidth();
  52523. y = (getHeight() - getWidth()) * 0.5f;
  52524. }
  52525. else
  52526. {
  52527. diam = (float) getHeight();
  52528. y = (getWidth() - getHeight()) * 0.5f;
  52529. }
  52530. x += diam * 0.05f;
  52531. y += diam * 0.05f;
  52532. diam *= 0.9f;
  52533. g.setGradientFill (ColourGradient (Colour::greyLevel (0.9f).withAlpha (alpha), 0, y + diam,
  52534. Colour::greyLevel (0.6f).withAlpha (alpha), 0, y, false));
  52535. g.fillEllipse (x, y, diam, diam);
  52536. x += 2.0f;
  52537. y += 2.0f;
  52538. diam -= 4.0f;
  52539. LookAndFeel::drawGlassSphere (g, x, y, diam, colour.withAlpha (alpha), 1.0f);
  52540. Path& p = getToggleState() ? toggledShape : normalShape;
  52541. const AffineTransform t (p.getTransformToScaleToFit (x + diam * 0.3f, y + diam * 0.3f,
  52542. diam * 0.4f, diam * 0.4f, true));
  52543. g.setColour (Colours::black.withAlpha (alpha * 0.6f));
  52544. g.fillPath (p, t);
  52545. }
  52546. juce_UseDebuggingNewOperator
  52547. private:
  52548. Colour colour;
  52549. Path normalShape, toggledShape;
  52550. GlassWindowButton (const GlassWindowButton&);
  52551. GlassWindowButton& operator= (const GlassWindowButton&);
  52552. };
  52553. Button* LookAndFeel::createDocumentWindowButton (int buttonType)
  52554. {
  52555. Path shape;
  52556. const float crossThickness = 0.25f;
  52557. if (buttonType == DocumentWindow::closeButton)
  52558. {
  52559. shape.addLineSegment (0.0f, 0.0f, 1.0f, 1.0f, crossThickness * 1.4f);
  52560. shape.addLineSegment (1.0f, 0.0f, 0.0f, 1.0f, crossThickness * 1.4f);
  52561. return new GlassWindowButton ("close", Colour (0xffdd1100), shape, shape);
  52562. }
  52563. else if (buttonType == DocumentWindow::minimiseButton)
  52564. {
  52565. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, crossThickness);
  52566. return new GlassWindowButton ("minimise", Colour (0xffaa8811), shape, shape);
  52567. }
  52568. else if (buttonType == DocumentWindow::maximiseButton)
  52569. {
  52570. shape.addLineSegment (0.5f, 0.0f, 0.5f, 1.0f, crossThickness);
  52571. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, crossThickness);
  52572. Path fullscreenShape;
  52573. fullscreenShape.startNewSubPath (45.0f, 100.0f);
  52574. fullscreenShape.lineTo (0.0f, 100.0f);
  52575. fullscreenShape.lineTo (0.0f, 0.0f);
  52576. fullscreenShape.lineTo (100.0f, 0.0f);
  52577. fullscreenShape.lineTo (100.0f, 45.0f);
  52578. fullscreenShape.addRectangle (45.0f, 45.0f, 100.0f, 100.0f);
  52579. PathStrokeType (30.0f).createStrokedPath (fullscreenShape, fullscreenShape);
  52580. return new GlassWindowButton ("maximise", Colour (0xff119911), shape, fullscreenShape);
  52581. }
  52582. jassertfalse
  52583. return 0;
  52584. }
  52585. void LookAndFeel::positionDocumentWindowButtons (DocumentWindow&,
  52586. int titleBarX,
  52587. int titleBarY,
  52588. int titleBarW,
  52589. int titleBarH,
  52590. Button* minimiseButton,
  52591. Button* maximiseButton,
  52592. Button* closeButton,
  52593. bool positionTitleBarButtonsOnLeft)
  52594. {
  52595. const int buttonW = titleBarH - titleBarH / 8;
  52596. int x = positionTitleBarButtonsOnLeft ? titleBarX + 4
  52597. : titleBarX + titleBarW - buttonW - buttonW / 4;
  52598. if (closeButton != 0)
  52599. {
  52600. closeButton->setBounds (x, titleBarY, buttonW, titleBarH);
  52601. x += positionTitleBarButtonsOnLeft ? buttonW : -(buttonW + buttonW / 4);
  52602. }
  52603. if (positionTitleBarButtonsOnLeft)
  52604. swapVariables (minimiseButton, maximiseButton);
  52605. if (maximiseButton != 0)
  52606. {
  52607. maximiseButton->setBounds (x, titleBarY, buttonW, titleBarH);
  52608. x += positionTitleBarButtonsOnLeft ? buttonW : -buttonW;
  52609. }
  52610. if (minimiseButton != 0)
  52611. minimiseButton->setBounds (x, titleBarY, buttonW, titleBarH);
  52612. }
  52613. int LookAndFeel::getDefaultMenuBarHeight()
  52614. {
  52615. return 24;
  52616. }
  52617. DropShadower* LookAndFeel::createDropShadowerForComponent (Component*)
  52618. {
  52619. return new DropShadower (0.4f, 1, 5, 10);
  52620. }
  52621. void LookAndFeel::drawStretchableLayoutResizerBar (Graphics& g,
  52622. int w, int h,
  52623. bool /*isVerticalBar*/,
  52624. bool isMouseOver,
  52625. bool isMouseDragging)
  52626. {
  52627. float alpha = 0.5f;
  52628. if (isMouseOver || isMouseDragging)
  52629. {
  52630. g.fillAll (Colour (0x190000ff));
  52631. alpha = 1.0f;
  52632. }
  52633. const float cx = w * 0.5f;
  52634. const float cy = h * 0.5f;
  52635. const float cr = jmin (w, h) * 0.4f;
  52636. g.setGradientFill (ColourGradient (Colours::white.withAlpha (alpha), cx + cr * 0.1f, cy + cr,
  52637. Colours::black.withAlpha (alpha), cx, cy - cr * 4.0f,
  52638. true));
  52639. g.fillEllipse (cx - cr, cy - cr, cr * 2.0f, cr * 2.0f);
  52640. }
  52641. void LookAndFeel::drawGroupComponentOutline (Graphics& g, int width, int height,
  52642. const String& text,
  52643. const Justification& position,
  52644. GroupComponent& group)
  52645. {
  52646. const float textH = 15.0f;
  52647. const float indent = 3.0f;
  52648. const float textEdgeGap = 4.0f;
  52649. float cs = 5.0f;
  52650. Font f (textH);
  52651. Path p;
  52652. float x = indent;
  52653. float y = f.getAscent() - 3.0f;
  52654. float w = jmax (0.0f, width - x * 2.0f);
  52655. float h = jmax (0.0f, height - y - indent);
  52656. cs = jmin (cs, w * 0.5f, h * 0.5f);
  52657. const float cs2 = 2.0f * cs;
  52658. float textW = text.isEmpty() ? 0 : jlimit (0.0f, jmax (0.0f, w - cs2 - textEdgeGap * 2), f.getStringWidth (text) + textEdgeGap * 2.0f);
  52659. float textX = cs + textEdgeGap;
  52660. if (position.testFlags (Justification::horizontallyCentred))
  52661. textX = cs + (w - cs2 - textW) * 0.5f;
  52662. else if (position.testFlags (Justification::right))
  52663. textX = w - cs - textW - textEdgeGap;
  52664. p.startNewSubPath (x + textX + textW, y);
  52665. p.lineTo (x + w - cs, y);
  52666. p.addArc (x + w - cs2, y, cs2, cs2, 0, float_Pi * 0.5f);
  52667. p.lineTo (x + w, y + h - cs);
  52668. p.addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi);
  52669. p.lineTo (x + cs, y + h);
  52670. p.addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f);
  52671. p.lineTo (x, y + cs);
  52672. p.addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f);
  52673. p.lineTo (x + textX, y);
  52674. const float alpha = group.isEnabled() ? 1.0f : 0.5f;
  52675. g.setColour (group.findColour (GroupComponent::outlineColourId)
  52676. .withMultipliedAlpha (alpha));
  52677. g.strokePath (p, PathStrokeType (2.0f));
  52678. g.setColour (group.findColour (GroupComponent::textColourId)
  52679. .withMultipliedAlpha (alpha));
  52680. g.setFont (f);
  52681. g.drawText (text,
  52682. roundToInt (x + textX), 0,
  52683. roundToInt (textW),
  52684. roundToInt (textH),
  52685. Justification::centred, true);
  52686. }
  52687. int LookAndFeel::getTabButtonOverlap (int tabDepth)
  52688. {
  52689. return 1 + tabDepth / 3;
  52690. }
  52691. int LookAndFeel::getTabButtonSpaceAroundImage()
  52692. {
  52693. return 4;
  52694. }
  52695. void LookAndFeel::createTabButtonShape (Path& p,
  52696. int width, int height,
  52697. int /*tabIndex*/,
  52698. const String& /*text*/,
  52699. Button& /*button*/,
  52700. TabbedButtonBar::Orientation orientation,
  52701. const bool /*isMouseOver*/,
  52702. const bool /*isMouseDown*/,
  52703. const bool /*isFrontTab*/)
  52704. {
  52705. const float w = (float) width;
  52706. const float h = (float) height;
  52707. float length = w;
  52708. float depth = h;
  52709. if (orientation == TabbedButtonBar::TabsAtLeft
  52710. || orientation == TabbedButtonBar::TabsAtRight)
  52711. {
  52712. swapVariables (length, depth);
  52713. }
  52714. const float indent = (float) getTabButtonOverlap ((int) depth);
  52715. const float overhang = 4.0f;
  52716. if (orientation == TabbedButtonBar::TabsAtLeft)
  52717. {
  52718. p.startNewSubPath (w, 0.0f);
  52719. p.lineTo (0.0f, indent);
  52720. p.lineTo (0.0f, h - indent);
  52721. p.lineTo (w, h);
  52722. p.lineTo (w + overhang, h + overhang);
  52723. p.lineTo (w + overhang, -overhang);
  52724. }
  52725. else if (orientation == TabbedButtonBar::TabsAtRight)
  52726. {
  52727. p.startNewSubPath (0.0f, 0.0f);
  52728. p.lineTo (w, indent);
  52729. p.lineTo (w, h - indent);
  52730. p.lineTo (0.0f, h);
  52731. p.lineTo (-overhang, h + overhang);
  52732. p.lineTo (-overhang, -overhang);
  52733. }
  52734. else if (orientation == TabbedButtonBar::TabsAtBottom)
  52735. {
  52736. p.startNewSubPath (0.0f, 0.0f);
  52737. p.lineTo (indent, h);
  52738. p.lineTo (w - indent, h);
  52739. p.lineTo (w, 0.0f);
  52740. p.lineTo (w + overhang, -overhang);
  52741. p.lineTo (-overhang, -overhang);
  52742. }
  52743. else
  52744. {
  52745. p.startNewSubPath (0.0f, h);
  52746. p.lineTo (indent, 0.0f);
  52747. p.lineTo (w - indent, 0.0f);
  52748. p.lineTo (w, h);
  52749. p.lineTo (w + overhang, h + overhang);
  52750. p.lineTo (-overhang, h + overhang);
  52751. }
  52752. p.closeSubPath();
  52753. p = p.createPathWithRoundedCorners (3.0f);
  52754. }
  52755. void LookAndFeel::fillTabButtonShape (Graphics& g,
  52756. const Path& path,
  52757. const Colour& preferredColour,
  52758. int /*tabIndex*/,
  52759. const String& /*text*/,
  52760. Button& button,
  52761. TabbedButtonBar::Orientation /*orientation*/,
  52762. const bool /*isMouseOver*/,
  52763. const bool /*isMouseDown*/,
  52764. const bool isFrontTab)
  52765. {
  52766. g.setColour (isFrontTab ? preferredColour
  52767. : preferredColour.withMultipliedAlpha (0.9f));
  52768. g.fillPath (path);
  52769. g.setColour (button.findColour (isFrontTab ? TabbedButtonBar::frontOutlineColourId
  52770. : TabbedButtonBar::tabOutlineColourId, false)
  52771. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  52772. g.strokePath (path, PathStrokeType (isFrontTab ? 1.0f : 0.5f));
  52773. }
  52774. void LookAndFeel::drawTabButtonText (Graphics& g,
  52775. int x, int y, int w, int h,
  52776. const Colour& preferredBackgroundColour,
  52777. int /*tabIndex*/,
  52778. const String& text,
  52779. Button& button,
  52780. TabbedButtonBar::Orientation orientation,
  52781. const bool isMouseOver,
  52782. const bool isMouseDown,
  52783. const bool isFrontTab)
  52784. {
  52785. int length = w;
  52786. int depth = h;
  52787. if (orientation == TabbedButtonBar::TabsAtLeft
  52788. || orientation == TabbedButtonBar::TabsAtRight)
  52789. {
  52790. swapVariables (length, depth);
  52791. }
  52792. Font font (depth * 0.6f);
  52793. font.setUnderline (button.hasKeyboardFocus (false));
  52794. GlyphArrangement textLayout;
  52795. textLayout.addFittedText (font, text.trim(),
  52796. 0.0f, 0.0f, (float) length, (float) depth,
  52797. Justification::centred,
  52798. jmax (1, depth / 12));
  52799. AffineTransform transform;
  52800. if (orientation == TabbedButtonBar::TabsAtLeft)
  52801. {
  52802. transform = transform.rotated (float_Pi * -0.5f)
  52803. .translated ((float) x, (float) (y + h));
  52804. }
  52805. else if (orientation == TabbedButtonBar::TabsAtRight)
  52806. {
  52807. transform = transform.rotated (float_Pi * 0.5f)
  52808. .translated ((float) (x + w), (float) y);
  52809. }
  52810. else
  52811. {
  52812. transform = transform.translated ((float) x, (float) y);
  52813. }
  52814. if (isFrontTab && (button.isColourSpecified (TabbedButtonBar::frontTextColourId) || isColourSpecified (TabbedButtonBar::frontTextColourId)))
  52815. g.setColour (findColour (TabbedButtonBar::frontTextColourId));
  52816. else if (button.isColourSpecified (TabbedButtonBar::tabTextColourId) || isColourSpecified (TabbedButtonBar::tabTextColourId))
  52817. g.setColour (findColour (TabbedButtonBar::tabTextColourId));
  52818. else
  52819. g.setColour (preferredBackgroundColour.contrasting());
  52820. if (! (isMouseOver || isMouseDown))
  52821. g.setOpacity (0.8f);
  52822. if (! button.isEnabled())
  52823. g.setOpacity (0.3f);
  52824. textLayout.draw (g, transform);
  52825. }
  52826. int LookAndFeel::getTabButtonBestWidth (int /*tabIndex*/,
  52827. const String& text,
  52828. int tabDepth,
  52829. Button&)
  52830. {
  52831. Font f (tabDepth * 0.6f);
  52832. return f.getStringWidth (text.trim()) + getTabButtonOverlap (tabDepth) * 2;
  52833. }
  52834. void LookAndFeel::drawTabButton (Graphics& g,
  52835. int w, int h,
  52836. const Colour& preferredColour,
  52837. int tabIndex,
  52838. const String& text,
  52839. Button& button,
  52840. TabbedButtonBar::Orientation orientation,
  52841. const bool isMouseOver,
  52842. const bool isMouseDown,
  52843. const bool isFrontTab)
  52844. {
  52845. int length = w;
  52846. int depth = h;
  52847. if (orientation == TabbedButtonBar::TabsAtLeft
  52848. || orientation == TabbedButtonBar::TabsAtRight)
  52849. {
  52850. swapVariables (length, depth);
  52851. }
  52852. Path tabShape;
  52853. createTabButtonShape (tabShape, w, h,
  52854. tabIndex, text, button, orientation,
  52855. isMouseOver, isMouseDown, isFrontTab);
  52856. fillTabButtonShape (g, tabShape, preferredColour,
  52857. tabIndex, text, button, orientation,
  52858. isMouseOver, isMouseDown, isFrontTab);
  52859. const int indent = getTabButtonOverlap (depth);
  52860. int x = 0, y = 0;
  52861. if (orientation == TabbedButtonBar::TabsAtLeft
  52862. || orientation == TabbedButtonBar::TabsAtRight)
  52863. {
  52864. y += indent;
  52865. h -= indent * 2;
  52866. }
  52867. else
  52868. {
  52869. x += indent;
  52870. w -= indent * 2;
  52871. }
  52872. drawTabButtonText (g, x, y, w, h, preferredColour,
  52873. tabIndex, text, button, orientation,
  52874. isMouseOver, isMouseDown, isFrontTab);
  52875. }
  52876. void LookAndFeel::drawTabAreaBehindFrontButton (Graphics& g,
  52877. int w, int h,
  52878. TabbedButtonBar& tabBar,
  52879. TabbedButtonBar::Orientation orientation)
  52880. {
  52881. const float shadowSize = 0.2f;
  52882. float x1 = 0.0f, y1 = 0.0f, x2 = 0.0f, y2 = 0.0f;
  52883. Rectangle<int> shadowRect;
  52884. if (orientation == TabbedButtonBar::TabsAtLeft)
  52885. {
  52886. x1 = (float) w;
  52887. x2 = w * (1.0f - shadowSize);
  52888. shadowRect.setBounds ((int) x2, 0, w - (int) x2, h);
  52889. }
  52890. else if (orientation == TabbedButtonBar::TabsAtRight)
  52891. {
  52892. x2 = w * shadowSize;
  52893. shadowRect.setBounds (0, 0, (int) x2, h);
  52894. }
  52895. else if (orientation == TabbedButtonBar::TabsAtBottom)
  52896. {
  52897. y2 = h * shadowSize;
  52898. shadowRect.setBounds (0, 0, w, (int) y2);
  52899. }
  52900. else
  52901. {
  52902. y1 = (float) h;
  52903. y2 = h * (1.0f - shadowSize);
  52904. shadowRect.setBounds (0, (int) y2, w, h - (int) y2);
  52905. }
  52906. g.setGradientFill (ColourGradient (Colours::black.withAlpha (tabBar.isEnabled() ? 0.3f : 0.15f), x1, y1,
  52907. Colours::transparentBlack, x2, y2, false));
  52908. shadowRect.expand (2, 2);
  52909. g.fillRect (shadowRect);
  52910. g.setColour (Colour (0x80000000));
  52911. if (orientation == TabbedButtonBar::TabsAtLeft)
  52912. {
  52913. g.fillRect (w - 1, 0, 1, h);
  52914. }
  52915. else if (orientation == TabbedButtonBar::TabsAtRight)
  52916. {
  52917. g.fillRect (0, 0, 1, h);
  52918. }
  52919. else if (orientation == TabbedButtonBar::TabsAtBottom)
  52920. {
  52921. g.fillRect (0, 0, w, 1);
  52922. }
  52923. else
  52924. {
  52925. g.fillRect (0, h - 1, w, 1);
  52926. }
  52927. }
  52928. Button* LookAndFeel::createTabBarExtrasButton()
  52929. {
  52930. const float thickness = 7.0f;
  52931. const float indent = 22.0f;
  52932. Path p;
  52933. p.addEllipse (-10.0f, -10.0f, 120.0f, 120.0f);
  52934. DrawablePath ellipse;
  52935. ellipse.setPath (p);
  52936. ellipse.setFill (Colour (0x99ffffff));
  52937. p.clear();
  52938. p.addEllipse (0.0f, 0.0f, 100.0f, 100.0f);
  52939. p.addRectangle (indent, 50.0f - thickness, 100.0f - indent * 2.0f, thickness * 2.0f);
  52940. p.addRectangle (50.0f - thickness, indent, thickness * 2.0f, 50.0f - indent - thickness);
  52941. p.addRectangle (50.0f - thickness, 50.0f + thickness, thickness * 2.0f, 50.0f - indent - thickness);
  52942. p.setUsingNonZeroWinding (false);
  52943. DrawablePath dp;
  52944. dp.setPath (p);
  52945. dp.setFill (Colour (0x59000000));
  52946. DrawableComposite normalImage;
  52947. normalImage.insertDrawable (ellipse);
  52948. normalImage.insertDrawable (dp);
  52949. dp.setFill (Colour (0xcc000000));
  52950. DrawableComposite overImage;
  52951. overImage.insertDrawable (ellipse);
  52952. overImage.insertDrawable (dp);
  52953. DrawableButton* db = new DrawableButton (T("tabs"), DrawableButton::ImageFitted);
  52954. db->setImages (&normalImage, &overImage, 0);
  52955. return db;
  52956. }
  52957. void LookAndFeel::drawTableHeaderBackground (Graphics& g, TableHeaderComponent& header)
  52958. {
  52959. g.fillAll (Colours::white);
  52960. const int w = header.getWidth();
  52961. const int h = header.getHeight();
  52962. g.setGradientFill (ColourGradient (Colour (0xffe8ebf9), 0.0f, h * 0.5f,
  52963. Colour (0xfff6f8f9), 0.0f, h - 1.0f,
  52964. false));
  52965. g.fillRect (0, h / 2, w, h);
  52966. g.setColour (Colour (0x33000000));
  52967. g.fillRect (0, h - 1, w, 1);
  52968. for (int i = header.getNumColumns (true); --i >= 0;)
  52969. g.fillRect (header.getColumnPosition (i).getRight() - 1, 0, 1, h - 1);
  52970. }
  52971. void LookAndFeel::drawTableHeaderColumn (Graphics& g, const String& columnName, int /*columnId*/,
  52972. int width, int height,
  52973. bool isMouseOver, bool isMouseDown,
  52974. int columnFlags)
  52975. {
  52976. if (isMouseDown)
  52977. g.fillAll (Colour (0x8899aadd));
  52978. else if (isMouseOver)
  52979. g.fillAll (Colour (0x5599aadd));
  52980. int rightOfText = width - 4;
  52981. if ((columnFlags & (TableHeaderComponent::sortedForwards | TableHeaderComponent::sortedBackwards)) != 0)
  52982. {
  52983. const float top = height * ((columnFlags & TableHeaderComponent::sortedForwards) != 0 ? 0.35f : (1.0f - 0.35f));
  52984. const float bottom = height - top;
  52985. const float w = height * 0.5f;
  52986. const float x = rightOfText - (w * 1.25f);
  52987. rightOfText = (int) x;
  52988. Path sortArrow;
  52989. sortArrow.addTriangle (x, bottom, x + w * 0.5f, top, x + w, bottom);
  52990. g.setColour (Colour (0x99000000));
  52991. g.fillPath (sortArrow);
  52992. }
  52993. g.setColour (Colours::black);
  52994. g.setFont (height * 0.5f, Font::bold);
  52995. const int textX = 4;
  52996. g.drawFittedText (columnName, textX, 0, rightOfText - textX, height, Justification::centredLeft, 1);
  52997. }
  52998. void LookAndFeel::paintToolbarBackground (Graphics& g, int w, int h, Toolbar& toolbar)
  52999. {
  53000. const Colour background (toolbar.findColour (Toolbar::backgroundColourId));
  53001. g.setGradientFill (ColourGradient (background, 0.0f, 0.0f,
  53002. background.darker (0.1f),
  53003. toolbar.isVertical() ? w - 1.0f : 0.0f,
  53004. toolbar.isVertical() ? 0.0f : h - 1.0f,
  53005. false));
  53006. g.fillAll();
  53007. }
  53008. Button* LookAndFeel::createToolbarMissingItemsButton (Toolbar& /*toolbar*/)
  53009. {
  53010. return createTabBarExtrasButton();
  53011. }
  53012. void LookAndFeel::paintToolbarButtonBackground (Graphics& g, int /*width*/, int /*height*/,
  53013. bool isMouseOver, bool isMouseDown,
  53014. ToolbarItemComponent& component)
  53015. {
  53016. if (isMouseDown)
  53017. g.fillAll (component.findColour (Toolbar::buttonMouseDownBackgroundColourId, true));
  53018. else if (isMouseOver)
  53019. g.fillAll (component.findColour (Toolbar::buttonMouseOverBackgroundColourId, true));
  53020. }
  53021. void LookAndFeel::paintToolbarButtonLabel (Graphics& g, int x, int y, int width, int height,
  53022. const String& text, ToolbarItemComponent& component)
  53023. {
  53024. g.setColour (component.findColour (Toolbar::labelTextColourId, true)
  53025. .withAlpha (component.isEnabled() ? 1.0f : 0.25f));
  53026. const float fontHeight = jmin (14.0f, height * 0.85f);
  53027. g.setFont (fontHeight);
  53028. g.drawFittedText (text,
  53029. x, y, width, height,
  53030. Justification::centred,
  53031. jmax (1, height / (int) fontHeight));
  53032. }
  53033. void LookAndFeel::drawPropertyPanelSectionHeader (Graphics& g, const String& name,
  53034. bool isOpen, int width, int height)
  53035. {
  53036. const int buttonSize = (height * 3) / 4;
  53037. const int buttonIndent = (height - buttonSize) / 2;
  53038. drawTreeviewPlusMinusBox (g, buttonIndent, buttonIndent, buttonSize, buttonSize, ! isOpen, false);
  53039. const int textX = buttonIndent * 2 + buttonSize + 2;
  53040. g.setColour (Colours::black);
  53041. g.setFont (height * 0.7f, Font::bold);
  53042. g.drawText (name, textX, 0, width - textX - 4, height, Justification::centredLeft, true);
  53043. }
  53044. void LookAndFeel::drawPropertyComponentBackground (Graphics& g, int width, int height,
  53045. PropertyComponent&)
  53046. {
  53047. g.setColour (Colour (0x66ffffff));
  53048. g.fillRect (0, 0, width, height - 1);
  53049. }
  53050. void LookAndFeel::drawPropertyComponentLabel (Graphics& g, int, int height,
  53051. PropertyComponent& component)
  53052. {
  53053. g.setColour (Colours::black);
  53054. if (! component.isEnabled())
  53055. g.setOpacity (0.6f);
  53056. g.setFont (jmin (height, 24) * 0.65f);
  53057. const Rectangle<int> r (getPropertyComponentContentPosition (component));
  53058. g.drawFittedText (component.getName(),
  53059. 3, r.getY(), r.getX() - 5, r.getHeight(),
  53060. Justification::centredLeft, 2);
  53061. }
  53062. const Rectangle<int> LookAndFeel::getPropertyComponentContentPosition (PropertyComponent& component)
  53063. {
  53064. return Rectangle<int> (component.getWidth() / 3, 1,
  53065. component.getWidth() - component.getWidth() / 3 - 1, component.getHeight() - 3);
  53066. }
  53067. void LookAndFeel::createFileChooserHeaderText (const String& title,
  53068. const String& instructions,
  53069. GlyphArrangement& text,
  53070. int width)
  53071. {
  53072. text.clear();
  53073. text.addJustifiedText (Font (17.0f, Font::bold), title,
  53074. 8.0f, 22.0f, width - 16.0f,
  53075. Justification::centred);
  53076. text.addJustifiedText (Font (14.0f), instructions,
  53077. 8.0f, 24.0f + 16.0f, width - 16.0f,
  53078. Justification::centred);
  53079. }
  53080. void LookAndFeel::drawFileBrowserRow (Graphics& g, int width, int height,
  53081. const String& filename, Image* icon,
  53082. const String& fileSizeDescription,
  53083. const String& fileTimeDescription,
  53084. const bool isDirectory,
  53085. const bool isItemSelected,
  53086. const int /*itemIndex*/)
  53087. {
  53088. if (isItemSelected)
  53089. g.fillAll (findColour (DirectoryContentsDisplayComponent::highlightColourId));
  53090. g.setColour (findColour (DirectoryContentsDisplayComponent::textColourId));
  53091. g.setFont (height * 0.7f);
  53092. Image* im = icon;
  53093. Image* toRelease = 0;
  53094. if (im == 0)
  53095. {
  53096. toRelease = im = (isDirectory ? getDefaultFolderImage()
  53097. : getDefaultDocumentFileImage());
  53098. }
  53099. const int x = 32;
  53100. if (im != 0)
  53101. {
  53102. g.drawImageWithin (im, 2, 2, x - 4, height - 4,
  53103. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize,
  53104. false);
  53105. ImageCache::release (toRelease);
  53106. }
  53107. if (width > 450 && ! isDirectory)
  53108. {
  53109. const int sizeX = roundToInt (width * 0.7f);
  53110. const int dateX = roundToInt (width * 0.8f);
  53111. g.drawFittedText (filename,
  53112. x, 0, sizeX - x, height,
  53113. Justification::centredLeft, 1);
  53114. g.setFont (height * 0.5f);
  53115. g.setColour (Colours::darkgrey);
  53116. if (! isDirectory)
  53117. {
  53118. g.drawFittedText (fileSizeDescription,
  53119. sizeX, 0, dateX - sizeX - 8, height,
  53120. Justification::centredRight, 1);
  53121. g.drawFittedText (fileTimeDescription,
  53122. dateX, 0, width - 8 - dateX, height,
  53123. Justification::centredRight, 1);
  53124. }
  53125. }
  53126. else
  53127. {
  53128. g.drawFittedText (filename,
  53129. x, 0, width - x, height,
  53130. Justification::centredLeft, 1);
  53131. }
  53132. }
  53133. Button* LookAndFeel::createFileBrowserGoUpButton()
  53134. {
  53135. DrawableButton* goUpButton = new DrawableButton ("up", DrawableButton::ImageOnButtonBackground);
  53136. Path arrowPath;
  53137. arrowPath.addArrow (50.0f, 100.0f, 50.0f, 0.0f, 40.0f, 100.0f, 50.0f);
  53138. DrawablePath arrowImage;
  53139. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  53140. arrowImage.setPath (arrowPath);
  53141. goUpButton->setImages (&arrowImage);
  53142. return goUpButton;
  53143. }
  53144. void LookAndFeel::layoutFileBrowserComponent (FileBrowserComponent& browserComp,
  53145. DirectoryContentsDisplayComponent* fileListComponent,
  53146. FilePreviewComponent* previewComp,
  53147. ComboBox* currentPathBox,
  53148. TextEditor* filenameBox,
  53149. Button* goUpButton)
  53150. {
  53151. const int x = 8;
  53152. int w = browserComp.getWidth() - x - x;
  53153. if (previewComp != 0)
  53154. {
  53155. const int previewWidth = w / 3;
  53156. previewComp->setBounds (x + w - previewWidth, 0, previewWidth, browserComp.getHeight());
  53157. w -= previewWidth + 4;
  53158. }
  53159. int y = 4;
  53160. const int controlsHeight = 22;
  53161. const int bottomSectionHeight = controlsHeight + 8;
  53162. const int upButtonWidth = 50;
  53163. currentPathBox->setBounds (x, y, w - upButtonWidth - 6, controlsHeight);
  53164. goUpButton->setBounds (x + w - upButtonWidth, y, upButtonWidth, controlsHeight);
  53165. y += controlsHeight + 4;
  53166. Component* const listAsComp = dynamic_cast <Component*> (fileListComponent);
  53167. listAsComp->setBounds (x, y, w, browserComp.getHeight() - y - bottomSectionHeight);
  53168. y = listAsComp->getBottom() + 4;
  53169. filenameBox->setBounds (x + 50, y, w - 50, controlsHeight);
  53170. }
  53171. Image* LookAndFeel::getDefaultFolderImage()
  53172. {
  53173. 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,
  53174. 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,
  53175. 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,
  53176. 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,
  53177. 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,
  53178. 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,
  53179. 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,
  53180. 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,
  53181. 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,
  53182. 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,
  53183. 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,
  53184. 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,
  53185. 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,
  53186. 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,
  53187. 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,
  53188. 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,
  53189. 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,
  53190. 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,
  53191. 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,
  53192. 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,
  53193. 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,
  53194. 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,
  53195. 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,
  53196. 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,
  53197. 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,
  53198. 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,
  53199. 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,
  53200. 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,
  53201. 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,
  53202. 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,
  53203. 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,
  53204. 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,
  53205. 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,
  53206. 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,
  53207. 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,
  53208. 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,
  53209. 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,
  53210. 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,
  53211. 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,
  53212. 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,
  53213. 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,
  53214. 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,
  53215. 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,
  53216. 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};
  53217. return ImageCache::getFromMemory (foldericon_png, sizeof (foldericon_png));
  53218. }
  53219. Image* LookAndFeel::getDefaultDocumentFileImage()
  53220. {
  53221. 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,
  53222. 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,
  53223. 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,
  53224. 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,
  53225. 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,
  53226. 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,
  53227. 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,
  53228. 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,
  53229. 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,
  53230. 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,
  53231. 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,
  53232. 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,
  53233. 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,
  53234. 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,
  53235. 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,
  53236. 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,
  53237. 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,
  53238. 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,
  53239. 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,
  53240. 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,
  53241. 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,
  53242. 174,66,96,130,0,0};
  53243. return ImageCache::getFromMemory (fileicon_png, sizeof (fileicon_png));
  53244. }
  53245. void LookAndFeel::playAlertSound()
  53246. {
  53247. PlatformUtilities::beep();
  53248. }
  53249. void LookAndFeel::drawLevelMeter (Graphics& g, int width, int height, float level)
  53250. {
  53251. g.setColour (Colours::white.withAlpha (0.7f));
  53252. g.fillRoundedRectangle (0.0f, 0.0f, (float) width, (float) height, 3.0f);
  53253. g.setColour (Colours::black.withAlpha (0.2f));
  53254. g.drawRoundedRectangle (1.0f, 1.0f, width - 2.0f, height - 2.0f, 3.0f, 1.0f);
  53255. const int totalBlocks = 7;
  53256. const int numBlocks = roundToInt (totalBlocks * level);
  53257. const float w = (width - 6.0f) / (float) totalBlocks;
  53258. for (int i = 0; i < totalBlocks; ++i)
  53259. {
  53260. if (i >= numBlocks)
  53261. g.setColour (Colours::lightblue.withAlpha (0.6f));
  53262. else
  53263. g.setColour (i < totalBlocks - 1 ? Colours::blue.withAlpha (0.5f)
  53264. : Colours::red);
  53265. g.fillRoundedRectangle (3.0f + i * w + w * 0.1f, 3.0f, w * 0.8f, height - 6.0f, w * 0.4f);
  53266. }
  53267. }
  53268. void LookAndFeel::drawKeymapChangeButton (Graphics& g, int width, int height, Button& button, const String& keyDescription)
  53269. {
  53270. const Colour textColour (button.findColour (KeyMappingEditorComponent::textColourId, true));
  53271. if (keyDescription.isNotEmpty())
  53272. {
  53273. if (button.isEnabled())
  53274. {
  53275. const float alpha = button.isDown() ? 0.3f : (button.isOver() ? 0.15f : 0.08f);
  53276. g.fillAll (textColour.withAlpha (alpha));
  53277. g.setOpacity (0.3f);
  53278. g.drawBevel (0, 0, width, height, 2);
  53279. }
  53280. g.setColour (textColour);
  53281. g.setFont (height * 0.6f);
  53282. g.drawFittedText (keyDescription,
  53283. 3, 0, width - 6, height,
  53284. Justification::centred, 1);
  53285. }
  53286. else
  53287. {
  53288. const float thickness = 7.0f;
  53289. const float indent = 22.0f;
  53290. Path p;
  53291. p.addEllipse (0.0f, 0.0f, 100.0f, 100.0f);
  53292. p.addRectangle (indent, 50.0f - thickness, 100.0f - indent * 2.0f, thickness * 2.0f);
  53293. p.addRectangle (50.0f - thickness, indent, thickness * 2.0f, 50.0f - indent - thickness);
  53294. p.addRectangle (50.0f - thickness, 50.0f + thickness, thickness * 2.0f, 50.0f - indent - thickness);
  53295. p.setUsingNonZeroWinding (false);
  53296. g.setColour (textColour.withAlpha (button.isDown() ? 0.7f : (button.isOver() ? 0.5f : 0.3f)));
  53297. g.fillPath (p, p.getTransformToScaleToFit (2.0f, 2.0f, width - 4.0f, height - 4.0f, true));
  53298. }
  53299. if (button.hasKeyboardFocus (false))
  53300. {
  53301. g.setColour (textColour.withAlpha (0.4f));
  53302. g.drawRect (0, 0, width, height);
  53303. }
  53304. }
  53305. static void createRoundedPath (Path& p,
  53306. const float x, const float y,
  53307. const float w, const float h,
  53308. const float cs,
  53309. const bool curveTopLeft, const bool curveTopRight,
  53310. const bool curveBottomLeft, const bool curveBottomRight) throw()
  53311. {
  53312. const float cs2 = 2.0f * cs;
  53313. if (curveTopLeft)
  53314. {
  53315. p.startNewSubPath (x, y + cs);
  53316. p.addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f);
  53317. }
  53318. else
  53319. {
  53320. p.startNewSubPath (x, y);
  53321. }
  53322. if (curveTopRight)
  53323. {
  53324. p.lineTo (x + w - cs, y);
  53325. p.addArc (x + w - cs2, y, cs2, cs2, 0.0f, float_Pi * 0.5f);
  53326. }
  53327. else
  53328. {
  53329. p.lineTo (x + w, y);
  53330. }
  53331. if (curveBottomRight)
  53332. {
  53333. p.lineTo (x + w, y + h - cs);
  53334. p.addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi);
  53335. }
  53336. else
  53337. {
  53338. p.lineTo (x + w, y + h);
  53339. }
  53340. if (curveBottomLeft)
  53341. {
  53342. p.lineTo (x + cs, y + h);
  53343. p.addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f);
  53344. }
  53345. else
  53346. {
  53347. p.lineTo (x, y + h);
  53348. }
  53349. p.closeSubPath();
  53350. }
  53351. void LookAndFeel::drawShinyButtonShape (Graphics& g,
  53352. float x, float y, float w, float h,
  53353. float maxCornerSize,
  53354. const Colour& baseColour,
  53355. const float strokeWidth,
  53356. const bool flatOnLeft,
  53357. const bool flatOnRight,
  53358. const bool flatOnTop,
  53359. const bool flatOnBottom) throw()
  53360. {
  53361. if (w <= strokeWidth * 1.1f || h <= strokeWidth * 1.1f)
  53362. return;
  53363. const float cs = jmin (maxCornerSize, w * 0.5f, h * 0.5f);
  53364. Path outline;
  53365. createRoundedPath (outline, x, y, w, h, cs,
  53366. ! (flatOnLeft || flatOnTop),
  53367. ! (flatOnRight || flatOnTop),
  53368. ! (flatOnLeft || flatOnBottom),
  53369. ! (flatOnRight || flatOnBottom));
  53370. ColourGradient cg (baseColour, 0.0f, y,
  53371. baseColour.overlaidWith (Colour (0x070000ff)), 0.0f, y + h,
  53372. false);
  53373. cg.addColour (0.5, baseColour.overlaidWith (Colour (0x33ffffff)));
  53374. cg.addColour (0.51, baseColour.overlaidWith (Colour (0x110000ff)));
  53375. g.setGradientFill (cg);
  53376. g.fillPath (outline);
  53377. g.setColour (Colour (0x80000000));
  53378. g.strokePath (outline, PathStrokeType (strokeWidth));
  53379. }
  53380. void LookAndFeel::drawGlassSphere (Graphics& g,
  53381. const float x, const float y,
  53382. const float diameter,
  53383. const Colour& colour,
  53384. const float outlineThickness) throw()
  53385. {
  53386. if (diameter <= outlineThickness)
  53387. return;
  53388. Path p;
  53389. p.addEllipse (x, y, diameter, diameter);
  53390. {
  53391. ColourGradient cg (Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y,
  53392. Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y + diameter, false);
  53393. cg.addColour (0.4, Colours::white.overlaidWith (colour));
  53394. g.setGradientFill (cg);
  53395. g.fillPath (p);
  53396. }
  53397. g.setGradientFill (ColourGradient (Colours::white, 0, y + diameter * 0.06f,
  53398. Colours::transparentWhite, 0, y + diameter * 0.3f, false));
  53399. g.fillEllipse (x + diameter * 0.2f, y + diameter * 0.05f, diameter * 0.6f, diameter * 0.4f);
  53400. ColourGradient cg (Colours::transparentBlack,
  53401. x + diameter * 0.5f, y + diameter * 0.5f,
  53402. Colours::black.withAlpha (0.5f * outlineThickness * colour.getFloatAlpha()),
  53403. x, y + diameter * 0.5f, true);
  53404. cg.addColour (0.7, Colours::transparentBlack);
  53405. cg.addColour (0.8, Colours::black.withAlpha (0.1f * outlineThickness));
  53406. g.setGradientFill (cg);
  53407. g.fillPath (p);
  53408. g.setColour (Colours::black.withAlpha (0.5f * colour.getFloatAlpha()));
  53409. g.drawEllipse (x, y, diameter, diameter, outlineThickness);
  53410. }
  53411. void LookAndFeel::drawGlassPointer (Graphics& g,
  53412. const float x, const float y,
  53413. const float diameter,
  53414. const Colour& colour, const float outlineThickness,
  53415. const int direction) throw()
  53416. {
  53417. if (diameter <= outlineThickness)
  53418. return;
  53419. Path p;
  53420. p.startNewSubPath (x + diameter * 0.5f, y);
  53421. p.lineTo (x + diameter, y + diameter * 0.6f);
  53422. p.lineTo (x + diameter, y + diameter);
  53423. p.lineTo (x, y + diameter);
  53424. p.lineTo (x, y + diameter * 0.6f);
  53425. p.closeSubPath();
  53426. p.applyTransform (AffineTransform::rotation (direction * (float_Pi * 0.5f), x + diameter * 0.5f, y + diameter * 0.5f));
  53427. {
  53428. ColourGradient cg (Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y,
  53429. Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y + diameter, false);
  53430. cg.addColour (0.4, Colours::white.overlaidWith (colour));
  53431. g.setGradientFill (cg);
  53432. g.fillPath (p);
  53433. }
  53434. ColourGradient cg (Colours::transparentBlack,
  53435. x + diameter * 0.5f, y + diameter * 0.5f,
  53436. Colours::black.withAlpha (0.5f * outlineThickness * colour.getFloatAlpha()),
  53437. x - diameter * 0.2f, y + diameter * 0.5f, true);
  53438. cg.addColour (0.5, Colours::transparentBlack);
  53439. cg.addColour (0.7, Colours::black.withAlpha (0.07f * outlineThickness));
  53440. g.setGradientFill (cg);
  53441. g.fillPath (p);
  53442. g.setColour (Colours::black.withAlpha (0.5f * colour.getFloatAlpha()));
  53443. g.strokePath (p, PathStrokeType (outlineThickness));
  53444. }
  53445. void LookAndFeel::drawGlassLozenge (Graphics& g,
  53446. const float x, const float y,
  53447. const float width, const float height,
  53448. const Colour& colour,
  53449. const float outlineThickness,
  53450. const float cornerSize,
  53451. const bool flatOnLeft,
  53452. const bool flatOnRight,
  53453. const bool flatOnTop,
  53454. const bool flatOnBottom) throw()
  53455. {
  53456. if (width <= outlineThickness || height <= outlineThickness)
  53457. return;
  53458. const int intX = (int) x;
  53459. const int intY = (int) y;
  53460. const int intW = (int) width;
  53461. const int intH = (int) height;
  53462. const float cs = cornerSize < 0 ? jmin (width * 0.5f, height * 0.5f) : cornerSize;
  53463. const float edgeBlurRadius = height * 0.75f + (height - cs * 2.0f);
  53464. const int intEdge = (int) edgeBlurRadius;
  53465. Path outline;
  53466. createRoundedPath (outline, x, y, width, height, cs,
  53467. ! (flatOnLeft || flatOnTop),
  53468. ! (flatOnRight || flatOnTop),
  53469. ! (flatOnLeft || flatOnBottom),
  53470. ! (flatOnRight || flatOnBottom));
  53471. {
  53472. ColourGradient cg (colour.darker (0.2f), 0, y,
  53473. colour.darker (0.2f), 0, y + height, false);
  53474. cg.addColour (0.03, colour.withMultipliedAlpha (0.3f));
  53475. cg.addColour (0.4, colour);
  53476. cg.addColour (0.97, colour.withMultipliedAlpha (0.3f));
  53477. g.setGradientFill (cg);
  53478. g.fillPath (outline);
  53479. }
  53480. ColourGradient cg (Colours::transparentBlack, x + edgeBlurRadius, y + height * 0.5f,
  53481. colour.darker (0.2f), x, y + height * 0.5f, true);
  53482. cg.addColour (jlimit (0.0, 1.0, 1.0 - (cs * 0.5f) / edgeBlurRadius), Colours::transparentBlack);
  53483. cg.addColour (jlimit (0.0, 1.0, 1.0 - (cs * 0.25f) / edgeBlurRadius), colour.darker (0.2f).withMultipliedAlpha (0.3f));
  53484. if (! (flatOnLeft || flatOnTop || flatOnBottom))
  53485. {
  53486. g.saveState();
  53487. g.setGradientFill (cg);
  53488. g.reduceClipRegion (intX, intY, intEdge, intH);
  53489. g.fillPath (outline);
  53490. g.restoreState();
  53491. }
  53492. if (! (flatOnRight || flatOnTop || flatOnBottom))
  53493. {
  53494. cg.x1 = x + width - edgeBlurRadius;
  53495. cg.x2 = x + width;
  53496. g.saveState();
  53497. g.setGradientFill (cg);
  53498. g.reduceClipRegion (intX + intW - intEdge, intY, 2 + intEdge, intH);
  53499. g.fillPath (outline);
  53500. g.restoreState();
  53501. }
  53502. {
  53503. const float leftIndent = flatOnLeft ? 0.0f : cs * 0.4f;
  53504. const float rightIndent = flatOnRight ? 0.0f : cs * 0.4f;
  53505. Path highlight;
  53506. createRoundedPath (highlight,
  53507. x + leftIndent,
  53508. y + cs * 0.1f,
  53509. width - (leftIndent + rightIndent),
  53510. height * 0.4f, cs * 0.4f,
  53511. ! (flatOnLeft || flatOnTop),
  53512. ! (flatOnRight || flatOnTop),
  53513. ! (flatOnLeft || flatOnBottom),
  53514. ! (flatOnRight || flatOnBottom));
  53515. g.setGradientFill (ColourGradient (colour.brighter (10.0f), 0, y + height * 0.06f,
  53516. Colours::transparentWhite, 0, y + height * 0.4f, false));
  53517. g.fillPath (highlight);
  53518. }
  53519. g.setColour (colour.darker().withMultipliedAlpha (1.5f));
  53520. g.strokePath (outline, PathStrokeType (outlineThickness));
  53521. }
  53522. END_JUCE_NAMESPACE
  53523. /*** End of inlined file: juce_LookAndFeel.cpp ***/
  53524. /*** Start of inlined file: juce_OldSchoolLookAndFeel.cpp ***/
  53525. BEGIN_JUCE_NAMESPACE
  53526. OldSchoolLookAndFeel::OldSchoolLookAndFeel()
  53527. {
  53528. setColour (TextButton::buttonColourId, Colour (0xffbbbbff));
  53529. setColour (ListBox::outlineColourId, findColour (ComboBox::outlineColourId));
  53530. setColour (ScrollBar::thumbColourId, Colour (0xffbbbbdd));
  53531. setColour (ScrollBar::backgroundColourId, Colours::transparentBlack);
  53532. setColour (Slider::thumbColourId, Colours::white);
  53533. setColour (Slider::trackColourId, Colour (0x7f000000));
  53534. setColour (Slider::textBoxOutlineColourId, Colours::grey);
  53535. setColour (ProgressBar::backgroundColourId, Colours::white.withAlpha (0.6f));
  53536. setColour (ProgressBar::foregroundColourId, Colours::green.withAlpha (0.7f));
  53537. setColour (PopupMenu::backgroundColourId, Colour (0xffeef5f8));
  53538. setColour (PopupMenu::highlightedBackgroundColourId, Colour (0xbfa4c2ce));
  53539. setColour (PopupMenu::highlightedTextColourId, Colours::black);
  53540. setColour (TextEditor::focusedOutlineColourId, findColour (TextButton::buttonColourId));
  53541. scrollbarShadow.setShadowProperties (2.2f, 0.5f, 0, 0);
  53542. }
  53543. OldSchoolLookAndFeel::~OldSchoolLookAndFeel()
  53544. {
  53545. }
  53546. void OldSchoolLookAndFeel::drawButtonBackground (Graphics& g,
  53547. Button& button,
  53548. const Colour& backgroundColour,
  53549. bool isMouseOverButton,
  53550. bool isButtonDown)
  53551. {
  53552. const int width = button.getWidth();
  53553. const int height = button.getHeight();
  53554. const float indent = 2.0f;
  53555. const int cornerSize = jmin (roundToInt (width * 0.4f),
  53556. roundToInt (height * 0.4f));
  53557. Path p;
  53558. p.addRoundedRectangle (indent, indent,
  53559. width - indent * 2.0f,
  53560. height - indent * 2.0f,
  53561. (float) cornerSize);
  53562. Colour bc (backgroundColour.withMultipliedSaturation (0.3f));
  53563. if (isMouseOverButton)
  53564. {
  53565. if (isButtonDown)
  53566. bc = bc.brighter();
  53567. else if (bc.getBrightness() > 0.5f)
  53568. bc = bc.darker (0.1f);
  53569. else
  53570. bc = bc.brighter (0.1f);
  53571. }
  53572. g.setColour (bc);
  53573. g.fillPath (p);
  53574. g.setColour (bc.contrasting().withAlpha ((isMouseOverButton) ? 0.6f : 0.4f));
  53575. g.strokePath (p, PathStrokeType ((isMouseOverButton) ? 2.0f : 1.4f));
  53576. }
  53577. void OldSchoolLookAndFeel::drawTickBox (Graphics& g,
  53578. Component& /*component*/,
  53579. float x, float y, float w, float h,
  53580. const bool ticked,
  53581. const bool isEnabled,
  53582. const bool /*isMouseOverButton*/,
  53583. const bool isButtonDown)
  53584. {
  53585. Path box;
  53586. box.addRoundedRectangle (0.0f, 2.0f, 6.0f, 6.0f, 1.0f);
  53587. g.setColour (isEnabled ? Colours::blue.withAlpha (isButtonDown ? 0.3f : 0.1f)
  53588. : Colours::lightgrey.withAlpha (0.1f));
  53589. AffineTransform trans (AffineTransform::scale (w / 9.0f, h / 9.0f).translated (x, y));
  53590. g.fillPath (box, trans);
  53591. g.setColour (Colours::black.withAlpha (0.6f));
  53592. g.strokePath (box, PathStrokeType (0.9f), trans);
  53593. if (ticked)
  53594. {
  53595. Path tick;
  53596. tick.startNewSubPath (1.5f, 3.0f);
  53597. tick.lineTo (3.0f, 6.0f);
  53598. tick.lineTo (6.0f, 0.0f);
  53599. g.setColour (isEnabled ? Colours::black : Colours::grey);
  53600. g.strokePath (tick, PathStrokeType (2.5f), trans);
  53601. }
  53602. }
  53603. void OldSchoolLookAndFeel::drawToggleButton (Graphics& g,
  53604. ToggleButton& button,
  53605. bool isMouseOverButton,
  53606. bool isButtonDown)
  53607. {
  53608. if (button.hasKeyboardFocus (true))
  53609. {
  53610. g.setColour (button.findColour (TextEditor::focusedOutlineColourId));
  53611. g.drawRect (0, 0, button.getWidth(), button.getHeight());
  53612. }
  53613. const int tickWidth = jmin (20, button.getHeight() - 4);
  53614. drawTickBox (g, button, 4.0f, (button.getHeight() - tickWidth) * 0.5f,
  53615. (float) tickWidth, (float) tickWidth,
  53616. button.getToggleState(),
  53617. button.isEnabled(),
  53618. isMouseOverButton,
  53619. isButtonDown);
  53620. g.setColour (button.findColour (ToggleButton::textColourId));
  53621. g.setFont (jmin (15.0f, button.getHeight() * 0.6f));
  53622. if (! button.isEnabled())
  53623. g.setOpacity (0.5f);
  53624. const int textX = tickWidth + 5;
  53625. g.drawFittedText (button.getButtonText(),
  53626. textX, 4,
  53627. button.getWidth() - textX - 2, button.getHeight() - 8,
  53628. Justification::centredLeft, 10);
  53629. }
  53630. void OldSchoolLookAndFeel::drawProgressBar (Graphics& g, ProgressBar& progressBar,
  53631. int width, int height,
  53632. double progress, const String& textToShow)
  53633. {
  53634. if (progress < 0 || progress >= 1.0)
  53635. {
  53636. LookAndFeel::drawProgressBar (g, progressBar, width, height, progress, textToShow);
  53637. }
  53638. else
  53639. {
  53640. const Colour background (progressBar.findColour (ProgressBar::backgroundColourId));
  53641. const Colour foreground (progressBar.findColour (ProgressBar::foregroundColourId));
  53642. g.fillAll (background);
  53643. g.setColour (foreground);
  53644. g.fillRect (1, 1,
  53645. jlimit (0, width - 2, roundToInt (progress * (width - 2))),
  53646. height - 2);
  53647. if (textToShow.isNotEmpty())
  53648. {
  53649. g.setColour (Colour::contrasting (background, foreground));
  53650. g.setFont (height * 0.6f);
  53651. g.drawText (textToShow, 0, 0, width, height, Justification::centred, false);
  53652. }
  53653. }
  53654. }
  53655. void OldSchoolLookAndFeel::drawScrollbarButton (Graphics& g,
  53656. ScrollBar& bar,
  53657. int width, int height,
  53658. int buttonDirection,
  53659. bool isScrollbarVertical,
  53660. bool isMouseOverButton,
  53661. bool isButtonDown)
  53662. {
  53663. if (isScrollbarVertical)
  53664. width -= 2;
  53665. else
  53666. height -= 2;
  53667. Path p;
  53668. if (buttonDirection == 0)
  53669. p.addTriangle (width * 0.5f, height * 0.2f,
  53670. width * 0.1f, height * 0.7f,
  53671. width * 0.9f, height * 0.7f);
  53672. else if (buttonDirection == 1)
  53673. p.addTriangle (width * 0.8f, height * 0.5f,
  53674. width * 0.3f, height * 0.1f,
  53675. width * 0.3f, height * 0.9f);
  53676. else if (buttonDirection == 2)
  53677. p.addTriangle (width * 0.5f, height * 0.8f,
  53678. width * 0.1f, height * 0.3f,
  53679. width * 0.9f, height * 0.3f);
  53680. else if (buttonDirection == 3)
  53681. p.addTriangle (width * 0.2f, height * 0.5f,
  53682. width * 0.7f, height * 0.1f,
  53683. width * 0.7f, height * 0.9f);
  53684. if (isButtonDown)
  53685. g.setColour (Colours::white);
  53686. else if (isMouseOverButton)
  53687. g.setColour (Colours::white.withAlpha (0.7f));
  53688. else
  53689. g.setColour (bar.findColour (ScrollBar::thumbColourId).withAlpha (0.5f));
  53690. g.fillPath (p);
  53691. g.setColour (Colours::black.withAlpha (0.5f));
  53692. g.strokePath (p, PathStrokeType (0.5f));
  53693. }
  53694. void OldSchoolLookAndFeel::drawScrollbar (Graphics& g,
  53695. ScrollBar& bar,
  53696. int x, int y,
  53697. int width, int height,
  53698. bool isScrollbarVertical,
  53699. int thumbStartPosition,
  53700. int thumbSize,
  53701. bool isMouseOver,
  53702. bool isMouseDown)
  53703. {
  53704. g.fillAll (bar.findColour (ScrollBar::backgroundColourId));
  53705. g.setColour (bar.findColour (ScrollBar::thumbColourId)
  53706. .withAlpha ((isMouseOver || isMouseDown) ? 0.4f : 0.15f));
  53707. if (thumbSize > 0.0f)
  53708. {
  53709. Rectangle<int> thumb;
  53710. if (isScrollbarVertical)
  53711. {
  53712. width -= 2;
  53713. g.fillRect (x + roundToInt (width * 0.35f), y,
  53714. roundToInt (width * 0.3f), height);
  53715. thumb.setBounds (x + 1, thumbStartPosition,
  53716. width - 2, thumbSize);
  53717. }
  53718. else
  53719. {
  53720. height -= 2;
  53721. g.fillRect (x, y + roundToInt (height * 0.35f),
  53722. width, roundToInt (height * 0.3f));
  53723. thumb.setBounds (thumbStartPosition, y + 1,
  53724. thumbSize, height - 2);
  53725. }
  53726. g.setColour (bar.findColour (ScrollBar::thumbColourId)
  53727. .withAlpha ((isMouseOver || isMouseDown) ? 0.95f : 0.7f));
  53728. g.fillRect (thumb);
  53729. g.setColour (Colours::black.withAlpha ((isMouseOver || isMouseDown) ? 0.4f : 0.25f));
  53730. g.drawRect (thumb.getX(), thumb.getY(), thumb.getWidth(), thumb.getHeight());
  53731. if (thumbSize > 16)
  53732. {
  53733. for (int i = 3; --i >= 0;)
  53734. {
  53735. const float linePos = thumbStartPosition + thumbSize / 2 + (i - 1) * 4.0f;
  53736. g.setColour (Colours::black.withAlpha (0.15f));
  53737. if (isScrollbarVertical)
  53738. {
  53739. g.drawLine (x + width * 0.2f, linePos, width * 0.8f, linePos);
  53740. g.setColour (Colours::white.withAlpha (0.15f));
  53741. g.drawLine (width * 0.2f, linePos - 1, width * 0.8f, linePos - 1);
  53742. }
  53743. else
  53744. {
  53745. g.drawLine (linePos, height * 0.2f, linePos, height * 0.8f);
  53746. g.setColour (Colours::white.withAlpha (0.15f));
  53747. g.drawLine (linePos - 1, height * 0.2f, linePos - 1, height * 0.8f);
  53748. }
  53749. }
  53750. }
  53751. }
  53752. }
  53753. ImageEffectFilter* OldSchoolLookAndFeel::getScrollbarEffect()
  53754. {
  53755. return &scrollbarShadow;
  53756. }
  53757. void OldSchoolLookAndFeel::drawPopupMenuBackground (Graphics& g, int width, int height)
  53758. {
  53759. g.fillAll (findColour (PopupMenu::backgroundColourId));
  53760. g.setColour (Colours::black.withAlpha (0.6f));
  53761. g.drawRect (0, 0, width, height);
  53762. }
  53763. void OldSchoolLookAndFeel::drawMenuBarBackground (Graphics& g, int /*width*/, int /*height*/,
  53764. bool, MenuBarComponent& menuBar)
  53765. {
  53766. g.fillAll (menuBar.findColour (PopupMenu::backgroundColourId));
  53767. }
  53768. void OldSchoolLookAndFeel::drawTextEditorOutline (Graphics& g, int width, int height, TextEditor& textEditor)
  53769. {
  53770. if (textEditor.isEnabled())
  53771. {
  53772. g.setColour (textEditor.findColour (TextEditor::outlineColourId));
  53773. g.drawRect (0, 0, width, height);
  53774. }
  53775. }
  53776. void OldSchoolLookAndFeel::drawComboBox (Graphics& g, int width, int height,
  53777. const bool isButtonDown,
  53778. int buttonX, int buttonY,
  53779. int buttonW, int buttonH,
  53780. ComboBox& box)
  53781. {
  53782. g.fillAll (box.findColour (ComboBox::backgroundColourId));
  53783. g.setColour (box.findColour ((isButtonDown) ? ComboBox::buttonColourId
  53784. : ComboBox::backgroundColourId));
  53785. g.fillRect (buttonX, buttonY, buttonW, buttonH);
  53786. g.setColour (box.findColour (ComboBox::outlineColourId));
  53787. g.drawRect (0, 0, width, height);
  53788. const float arrowX = 0.2f;
  53789. const float arrowH = 0.3f;
  53790. if (box.isEnabled())
  53791. {
  53792. Path p;
  53793. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.45f - arrowH),
  53794. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.45f,
  53795. buttonX + buttonW * arrowX, buttonY + buttonH * 0.45f);
  53796. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.55f + arrowH),
  53797. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.55f,
  53798. buttonX + buttonW * arrowX, buttonY + buttonH * 0.55f);
  53799. g.setColour (box.findColour ((isButtonDown) ? ComboBox::backgroundColourId
  53800. : ComboBox::buttonColourId));
  53801. g.fillPath (p);
  53802. }
  53803. }
  53804. const Font OldSchoolLookAndFeel::getComboBoxFont (ComboBox& box)
  53805. {
  53806. Font f (jmin (15.0f, box.getHeight() * 0.85f));
  53807. f.setHorizontalScale (0.9f);
  53808. return f;
  53809. }
  53810. static void drawTriangle (Graphics& g, float x1, float y1, float x2, float y2, float x3, float y3, const Colour& fill, const Colour& outline) throw()
  53811. {
  53812. Path p;
  53813. p.addTriangle (x1, y1, x2, y2, x3, y3);
  53814. g.setColour (fill);
  53815. g.fillPath (p);
  53816. g.setColour (outline);
  53817. g.strokePath (p, PathStrokeType (0.3f));
  53818. }
  53819. void OldSchoolLookAndFeel::drawLinearSlider (Graphics& g,
  53820. int x, int y,
  53821. int w, int h,
  53822. float sliderPos,
  53823. float minSliderPos,
  53824. float maxSliderPos,
  53825. const Slider::SliderStyle style,
  53826. Slider& slider)
  53827. {
  53828. g.fillAll (slider.findColour (Slider::backgroundColourId));
  53829. if (style == Slider::LinearBar)
  53830. {
  53831. g.setColour (slider.findColour (Slider::thumbColourId));
  53832. g.fillRect (x, y, (int) sliderPos - x, h);
  53833. g.setColour (slider.findColour (Slider::textBoxTextColourId).withMultipliedAlpha (0.5f));
  53834. g.drawRect (x, y, (int) sliderPos - x, h);
  53835. }
  53836. else
  53837. {
  53838. g.setColour (slider.findColour (Slider::trackColourId)
  53839. .withMultipliedAlpha (slider.isEnabled() ? 1.0f : 0.3f));
  53840. if (slider.isHorizontal())
  53841. {
  53842. g.fillRect (x, y + roundToInt (h * 0.6f),
  53843. w, roundToInt (h * 0.2f));
  53844. }
  53845. else
  53846. {
  53847. g.fillRect (x + roundToInt (w * 0.5f - jmin (3.0f, w * 0.1f)), y,
  53848. jmin (4, roundToInt (w * 0.2f)), h);
  53849. }
  53850. float alpha = 0.35f;
  53851. if (slider.isEnabled())
  53852. alpha = slider.isMouseOverOrDragging() ? 1.0f : 0.7f;
  53853. const Colour fill (slider.findColour (Slider::thumbColourId).withAlpha (alpha));
  53854. const Colour outline (Colours::black.withAlpha (slider.isEnabled() ? 0.7f : 0.35f));
  53855. if (style == Slider::TwoValueVertical || style == Slider::ThreeValueVertical)
  53856. {
  53857. drawTriangle (g, x + w * 0.5f + jmin (4.0f, w * 0.3f), minSliderPos,
  53858. x + w * 0.5f - jmin (8.0f, w * 0.4f), minSliderPos - 7.0f,
  53859. x + w * 0.5f - jmin (8.0f, w * 0.4f), minSliderPos,
  53860. fill, outline);
  53861. drawTriangle (g, x + w * 0.5f + jmin (4.0f, w * 0.3f), maxSliderPos,
  53862. x + w * 0.5f - jmin (8.0f, w * 0.4f), maxSliderPos,
  53863. x + w * 0.5f - jmin (8.0f, w * 0.4f), maxSliderPos + 7.0f,
  53864. fill, outline);
  53865. }
  53866. else if (style == Slider::TwoValueHorizontal || style == Slider::ThreeValueHorizontal)
  53867. {
  53868. drawTriangle (g, minSliderPos, y + h * 0.6f - jmin (4.0f, h * 0.3f),
  53869. minSliderPos - 7.0f, y + h * 0.9f ,
  53870. minSliderPos, y + h * 0.9f,
  53871. fill, outline);
  53872. drawTriangle (g, maxSliderPos, y + h * 0.6f - jmin (4.0f, h * 0.3f),
  53873. maxSliderPos, y + h * 0.9f,
  53874. maxSliderPos + 7.0f, y + h * 0.9f,
  53875. fill, outline);
  53876. }
  53877. if (style == Slider::LinearHorizontal || style == Slider::ThreeValueHorizontal)
  53878. {
  53879. drawTriangle (g, sliderPos, y + h * 0.9f,
  53880. sliderPos - 7.0f, y + h * 0.2f,
  53881. sliderPos + 7.0f, y + h * 0.2f,
  53882. fill, outline);
  53883. }
  53884. else if (style == Slider::LinearVertical || style == Slider::ThreeValueVertical)
  53885. {
  53886. drawTriangle (g, x + w * 0.5f - jmin (4.0f, w * 0.3f), sliderPos,
  53887. x + w * 0.5f + jmin (8.0f, w * 0.4f), sliderPos - 7.0f,
  53888. x + w * 0.5f + jmin (8.0f, w * 0.4f), sliderPos + 7.0f,
  53889. fill, outline);
  53890. }
  53891. }
  53892. }
  53893. Button* OldSchoolLookAndFeel::createSliderButton (const bool isIncrement)
  53894. {
  53895. if (isIncrement)
  53896. return new ArrowButton ("u", 0.75f, Colours::white.withAlpha (0.8f));
  53897. else
  53898. return new ArrowButton ("d", 0.25f, Colours::white.withAlpha (0.8f));
  53899. }
  53900. ImageEffectFilter* OldSchoolLookAndFeel::getSliderEffect()
  53901. {
  53902. return &scrollbarShadow;
  53903. }
  53904. int OldSchoolLookAndFeel::getSliderThumbRadius (Slider&)
  53905. {
  53906. return 8;
  53907. }
  53908. void OldSchoolLookAndFeel::drawCornerResizer (Graphics& g,
  53909. int w, int h,
  53910. bool isMouseOver,
  53911. bool isMouseDragging)
  53912. {
  53913. g.setColour ((isMouseOver || isMouseDragging) ? Colours::lightgrey
  53914. : Colours::darkgrey);
  53915. const float lineThickness = jmin (w, h) * 0.1f;
  53916. for (float i = 0.0f; i < 1.0f; i += 0.3f)
  53917. {
  53918. g.drawLine (w * i,
  53919. h + 1.0f,
  53920. w + 1.0f,
  53921. h * i,
  53922. lineThickness);
  53923. }
  53924. }
  53925. Button* OldSchoolLookAndFeel::createDocumentWindowButton (int buttonType)
  53926. {
  53927. Path shape;
  53928. if (buttonType == DocumentWindow::closeButton)
  53929. {
  53930. shape.addLineSegment (0.0f, 0.0f, 1.0f, 1.0f, 0.35f);
  53931. shape.addLineSegment (1.0f, 0.0f, 0.0f, 1.0f, 0.35f);
  53932. ShapeButton* const b = new ShapeButton ("close",
  53933. Colour (0x7fff3333),
  53934. Colour (0xd7ff3333),
  53935. Colour (0xf7ff3333));
  53936. b->setShape (shape, true, true, true);
  53937. return b;
  53938. }
  53939. else if (buttonType == DocumentWindow::minimiseButton)
  53940. {
  53941. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, 0.25f);
  53942. DrawableButton* b = new DrawableButton ("minimise", DrawableButton::ImageFitted);
  53943. DrawablePath dp;
  53944. dp.setPath (shape);
  53945. dp.setFill (Colours::black.withAlpha (0.3f));
  53946. b->setImages (&dp);
  53947. return b;
  53948. }
  53949. else if (buttonType == DocumentWindow::maximiseButton)
  53950. {
  53951. shape.addLineSegment (0.5f, 0.0f, 0.5f, 1.0f, 0.25f);
  53952. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, 0.25f);
  53953. DrawableButton* b = new DrawableButton ("maximise", DrawableButton::ImageFitted);
  53954. DrawablePath dp;
  53955. dp.setPath (shape);
  53956. dp.setFill (Colours::black.withAlpha (0.3f));
  53957. b->setImages (&dp);
  53958. return b;
  53959. }
  53960. jassertfalse
  53961. return 0;
  53962. }
  53963. void OldSchoolLookAndFeel::positionDocumentWindowButtons (DocumentWindow&,
  53964. int titleBarX,
  53965. int titleBarY,
  53966. int titleBarW,
  53967. int titleBarH,
  53968. Button* minimiseButton,
  53969. Button* maximiseButton,
  53970. Button* closeButton,
  53971. bool positionTitleBarButtonsOnLeft)
  53972. {
  53973. titleBarY += titleBarH / 8;
  53974. titleBarH -= titleBarH / 4;
  53975. const int buttonW = titleBarH;
  53976. int x = positionTitleBarButtonsOnLeft ? titleBarX + 4
  53977. : titleBarX + titleBarW - buttonW - 4;
  53978. if (closeButton != 0)
  53979. {
  53980. closeButton->setBounds (x, titleBarY, buttonW, titleBarH);
  53981. x += positionTitleBarButtonsOnLeft ? buttonW + buttonW / 5
  53982. : -(buttonW + buttonW / 5);
  53983. }
  53984. if (positionTitleBarButtonsOnLeft)
  53985. swapVariables (minimiseButton, maximiseButton);
  53986. if (maximiseButton != 0)
  53987. {
  53988. maximiseButton->setBounds (x, titleBarY - 2, buttonW, titleBarH);
  53989. x += positionTitleBarButtonsOnLeft ? buttonW : -buttonW;
  53990. }
  53991. if (minimiseButton != 0)
  53992. minimiseButton->setBounds (x, titleBarY - 2, buttonW, titleBarH);
  53993. }
  53994. END_JUCE_NAMESPACE
  53995. /*** End of inlined file: juce_OldSchoolLookAndFeel.cpp ***/
  53996. /*** Start of inlined file: juce_MenuBarComponent.cpp ***/
  53997. BEGIN_JUCE_NAMESPACE
  53998. class DummyMenuComponent : public Component
  53999. {
  54000. DummyMenuComponent (const DummyMenuComponent&);
  54001. DummyMenuComponent& operator= (const DummyMenuComponent&);
  54002. public:
  54003. DummyMenuComponent() {}
  54004. ~DummyMenuComponent() {}
  54005. void inputAttemptWhenModal()
  54006. {
  54007. exitModalState (0);
  54008. }
  54009. };
  54010. MenuBarComponent::MenuBarComponent (MenuBarModel* model_)
  54011. : model (0),
  54012. itemUnderMouse (-1),
  54013. currentPopupIndex (-1),
  54014. indexToShowAgain (-1),
  54015. lastMouseX (0),
  54016. lastMouseY (0),
  54017. inModalState (false)
  54018. {
  54019. setRepaintsOnMouseActivity (true);
  54020. setWantsKeyboardFocus (false);
  54021. setMouseClickGrabsKeyboardFocus (false);
  54022. setModel (model_);
  54023. }
  54024. MenuBarComponent::~MenuBarComponent()
  54025. {
  54026. setModel (0);
  54027. Desktop::getInstance().removeGlobalMouseListener (this);
  54028. currentPopup = 0;
  54029. }
  54030. void MenuBarComponent::setModel (MenuBarModel* const newModel)
  54031. {
  54032. if (model != newModel)
  54033. {
  54034. if (model != 0)
  54035. model->removeListener (this);
  54036. model = newModel;
  54037. if (model != 0)
  54038. model->addListener (this);
  54039. repaint();
  54040. menuBarItemsChanged (0);
  54041. }
  54042. }
  54043. void MenuBarComponent::paint (Graphics& g)
  54044. {
  54045. const bool isMouseOverBar = currentPopupIndex >= 0 || itemUnderMouse >= 0 || isMouseOver();
  54046. getLookAndFeel().drawMenuBarBackground (g,
  54047. getWidth(),
  54048. getHeight(),
  54049. isMouseOverBar,
  54050. *this);
  54051. if (model != 0)
  54052. {
  54053. for (int i = 0; i < menuNames.size(); ++i)
  54054. {
  54055. g.saveState();
  54056. g.setOrigin (xPositions [i], 0);
  54057. g.reduceClipRegion (0, 0, xPositions[i + 1] - xPositions[i], getHeight());
  54058. getLookAndFeel().drawMenuBarItem (g,
  54059. xPositions[i + 1] - xPositions[i],
  54060. getHeight(),
  54061. i,
  54062. menuNames[i],
  54063. i == itemUnderMouse,
  54064. i == currentPopupIndex,
  54065. isMouseOverBar,
  54066. *this);
  54067. g.restoreState();
  54068. }
  54069. }
  54070. }
  54071. void MenuBarComponent::resized()
  54072. {
  54073. xPositions.clear();
  54074. int x = 2;
  54075. xPositions.add (x);
  54076. for (int i = 0; i < menuNames.size(); ++i)
  54077. {
  54078. x += getLookAndFeel().getMenuBarItemWidth (*this, i, menuNames[i]);
  54079. xPositions.add (x);
  54080. }
  54081. }
  54082. int MenuBarComponent::getItemAt (const int x, const int y)
  54083. {
  54084. for (int i = 0; i < xPositions.size(); ++i)
  54085. if (x >= xPositions[i] && x < xPositions[i + 1])
  54086. return reallyContains (x, y, true) ? i : -1;
  54087. return -1;
  54088. }
  54089. void MenuBarComponent::repaintMenuItem (int index)
  54090. {
  54091. if (((unsigned int) index) < (unsigned int) xPositions.size())
  54092. {
  54093. const int x1 = xPositions [index];
  54094. const int x2 = xPositions [index + 1];
  54095. repaint (x1 - 2, 0, x2 - x1 + 4, getHeight());
  54096. }
  54097. }
  54098. void MenuBarComponent::updateItemUnderMouse (int x, int y)
  54099. {
  54100. const int newItem = getItemAt (x, y);
  54101. if (itemUnderMouse != newItem)
  54102. {
  54103. repaintMenuItem (itemUnderMouse);
  54104. itemUnderMouse = newItem;
  54105. repaintMenuItem (itemUnderMouse);
  54106. }
  54107. }
  54108. void MenuBarComponent::hideCurrentMenu()
  54109. {
  54110. currentPopup = 0;
  54111. repaint();
  54112. }
  54113. void MenuBarComponent::showMenu (int index)
  54114. {
  54115. if (index != currentPopupIndex)
  54116. {
  54117. if (inModalState)
  54118. {
  54119. hideCurrentMenu();
  54120. indexToShowAgain = index;
  54121. return;
  54122. }
  54123. indexToShowAgain = -1;
  54124. currentPopupIndex = -1;
  54125. itemUnderMouse = index;
  54126. currentPopup = 0;
  54127. menuBarItemsChanged (0);
  54128. Component::SafePointer<Component> prevFocused (getCurrentlyFocusedComponent());
  54129. Component::SafePointer<Component> deletionChecker (this);
  54130. enterModalState (false);
  54131. inModalState = true;
  54132. int result = 0;
  54133. ApplicationCommandManager* managerOfChosenCommand = 0;
  54134. Desktop::getInstance().addGlobalMouseListener (this);
  54135. for (;;)
  54136. {
  54137. const int x = getScreenX() + xPositions [itemUnderMouse];
  54138. const int w = xPositions [itemUnderMouse + 1] - xPositions [itemUnderMouse];
  54139. currentPopupIndex = itemUnderMouse;
  54140. indexToShowAgain = -1;
  54141. repaint();
  54142. if (((unsigned int) itemUnderMouse) < (unsigned int) menuNames.size())
  54143. {
  54144. PopupMenu m (model->getMenuForIndex (itemUnderMouse,
  54145. menuNames [itemUnderMouse]));
  54146. if (m.lookAndFeel == 0)
  54147. m.setLookAndFeel (&getLookAndFeel());
  54148. currentPopup = m.createMenuComponent (x, getScreenY(),
  54149. w, getHeight(),
  54150. 0, w, 0, 0,
  54151. true, this,
  54152. &managerOfChosenCommand,
  54153. this);
  54154. }
  54155. if (currentPopup == 0)
  54156. {
  54157. currentPopup = new DummyMenuComponent();
  54158. addAndMakeVisible (currentPopup);
  54159. }
  54160. currentPopup->enterModalState (false);
  54161. currentPopup->toFront (false); // need to do this after making it modal, or it could
  54162. // be stuck behind other comps that are already modal..
  54163. result = currentPopup->runModalLoop();
  54164. if (deletionChecker == 0)
  54165. return;
  54166. const int lastPopupIndex = currentPopupIndex;
  54167. currentPopup = 0;
  54168. currentPopupIndex = -1;
  54169. if (result != 0)
  54170. {
  54171. topLevelIndexClicked = lastPopupIndex;
  54172. break;
  54173. }
  54174. else if (indexToShowAgain >= 0)
  54175. {
  54176. menuBarItemsChanged (0);
  54177. repaint();
  54178. itemUnderMouse = indexToShowAgain;
  54179. if (((unsigned int) itemUnderMouse) >= (unsigned int) menuNames.size())
  54180. break;
  54181. }
  54182. else
  54183. {
  54184. break;
  54185. }
  54186. }
  54187. Desktop::getInstance().removeGlobalMouseListener (this);
  54188. inModalState = false;
  54189. exitModalState (0);
  54190. if (prevFocused != 0)
  54191. prevFocused->grabKeyboardFocus();
  54192. const Point<int> mousePos (getMouseXYRelative());
  54193. updateItemUnderMouse (mousePos.getX(), mousePos.getY());
  54194. repaint();
  54195. if (result != 0)
  54196. {
  54197. if (managerOfChosenCommand != 0)
  54198. {
  54199. ApplicationCommandTarget::InvocationInfo info (result);
  54200. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromMenu;
  54201. managerOfChosenCommand->invoke (info, true);
  54202. }
  54203. postCommandMessage (result);
  54204. }
  54205. }
  54206. }
  54207. void MenuBarComponent::handleCommandMessage (int commandId)
  54208. {
  54209. if (model != 0)
  54210. model->menuItemSelected (commandId, topLevelIndexClicked);
  54211. }
  54212. void MenuBarComponent::mouseEnter (const MouseEvent& e)
  54213. {
  54214. if (e.eventComponent == this)
  54215. updateItemUnderMouse (e.x, e.y);
  54216. }
  54217. void MenuBarComponent::mouseExit (const MouseEvent& e)
  54218. {
  54219. if (e.eventComponent == this)
  54220. updateItemUnderMouse (e.x, e.y);
  54221. }
  54222. void MenuBarComponent::mouseDown (const MouseEvent& e)
  54223. {
  54224. if (currentPopupIndex < 0)
  54225. {
  54226. const MouseEvent e2 (e.getEventRelativeTo (this));
  54227. updateItemUnderMouse (e2.x, e2.y);
  54228. currentPopupIndex = -2;
  54229. showMenu (itemUnderMouse);
  54230. }
  54231. }
  54232. void MenuBarComponent::mouseDrag (const MouseEvent& e)
  54233. {
  54234. const MouseEvent e2 (e.getEventRelativeTo (this));
  54235. const int item = getItemAt (e2.x, e2.y);
  54236. if (item >= 0)
  54237. showMenu (item);
  54238. }
  54239. void MenuBarComponent::mouseUp (const MouseEvent& e)
  54240. {
  54241. const MouseEvent e2 (e.getEventRelativeTo (this));
  54242. updateItemUnderMouse (e2.x, e2.y);
  54243. if (itemUnderMouse < 0 && dynamic_cast <DummyMenuComponent*> ((Component*) currentPopup) != 0)
  54244. hideCurrentMenu();
  54245. }
  54246. void MenuBarComponent::mouseMove (const MouseEvent& e)
  54247. {
  54248. const MouseEvent e2 (e.getEventRelativeTo (this));
  54249. if (lastMouseX != e2.x || lastMouseY != e2.y)
  54250. {
  54251. if (currentPopupIndex >= 0)
  54252. {
  54253. const int item = getItemAt (e2.x, e2.y);
  54254. if (item >= 0)
  54255. showMenu (item);
  54256. }
  54257. else
  54258. {
  54259. updateItemUnderMouse (e2.x, e2.y);
  54260. }
  54261. lastMouseX = e2.x;
  54262. lastMouseY = e2.y;
  54263. }
  54264. }
  54265. bool MenuBarComponent::keyPressed (const KeyPress& key)
  54266. {
  54267. bool used = false;
  54268. const int numMenus = menuNames.size();
  54269. const int currentIndex = jlimit (0, menuNames.size() - 1, currentPopupIndex);
  54270. if (key.isKeyCode (KeyPress::leftKey))
  54271. {
  54272. showMenu ((currentIndex + numMenus - 1) % numMenus);
  54273. used = true;
  54274. }
  54275. else if (key.isKeyCode (KeyPress::rightKey))
  54276. {
  54277. showMenu ((currentIndex + 1) % numMenus);
  54278. used = true;
  54279. }
  54280. return used;
  54281. }
  54282. void MenuBarComponent::inputAttemptWhenModal()
  54283. {
  54284. hideCurrentMenu();
  54285. }
  54286. void MenuBarComponent::menuBarItemsChanged (MenuBarModel* /*menuBarModel*/)
  54287. {
  54288. StringArray newNames;
  54289. if (model != 0)
  54290. newNames = model->getMenuBarNames();
  54291. if (newNames != menuNames)
  54292. {
  54293. menuNames = newNames;
  54294. repaint();
  54295. resized();
  54296. }
  54297. }
  54298. void MenuBarComponent::menuCommandInvoked (MenuBarModel* /*menuBarModel*/,
  54299. const ApplicationCommandTarget::InvocationInfo& info)
  54300. {
  54301. if (model == 0
  54302. || (info.commandFlags & ApplicationCommandInfo::dontTriggerVisualFeedback) != 0)
  54303. return;
  54304. for (int i = 0; i < menuNames.size(); ++i)
  54305. {
  54306. const PopupMenu menu (model->getMenuForIndex (i, menuNames [i]));
  54307. if (menu.containsCommandItem (info.commandID))
  54308. {
  54309. itemUnderMouse = i;
  54310. repaintMenuItem (i);
  54311. startTimer (200);
  54312. break;
  54313. }
  54314. }
  54315. }
  54316. void MenuBarComponent::timerCallback()
  54317. {
  54318. stopTimer();
  54319. const Point<int> mousePos (getMouseXYRelative());
  54320. updateItemUnderMouse (mousePos.getX(), mousePos.getY());
  54321. }
  54322. END_JUCE_NAMESPACE
  54323. /*** End of inlined file: juce_MenuBarComponent.cpp ***/
  54324. /*** Start of inlined file: juce_MenuBarModel.cpp ***/
  54325. BEGIN_JUCE_NAMESPACE
  54326. MenuBarModel::MenuBarModel() throw()
  54327. : manager (0)
  54328. {
  54329. }
  54330. MenuBarModel::~MenuBarModel()
  54331. {
  54332. setApplicationCommandManagerToWatch (0);
  54333. }
  54334. void MenuBarModel::menuItemsChanged()
  54335. {
  54336. triggerAsyncUpdate();
  54337. }
  54338. void MenuBarModel::setApplicationCommandManagerToWatch (ApplicationCommandManager* const newManager) throw()
  54339. {
  54340. if (manager != newManager)
  54341. {
  54342. if (manager != 0)
  54343. manager->removeListener (this);
  54344. manager = newManager;
  54345. if (manager != 0)
  54346. manager->addListener (this);
  54347. }
  54348. }
  54349. void MenuBarModel::addListener (MenuBarModelListener* const newListener) throw()
  54350. {
  54351. listeners.add (newListener);
  54352. }
  54353. void MenuBarModel::removeListener (MenuBarModelListener* const listenerToRemove) throw()
  54354. {
  54355. // Trying to remove a listener that isn't on the list!
  54356. // If this assertion happens because this object is a dangling pointer, make sure you've not
  54357. // deleted this menu model while it's still being used by something (e.g. by a MenuBarComponent)
  54358. jassert (listeners.contains (listenerToRemove));
  54359. listeners.remove (listenerToRemove);
  54360. }
  54361. void MenuBarModel::handleAsyncUpdate()
  54362. {
  54363. listeners.call (&MenuBarModelListener::menuBarItemsChanged, this);
  54364. }
  54365. void MenuBarModel::applicationCommandInvoked (const ApplicationCommandTarget::InvocationInfo& info)
  54366. {
  54367. listeners.call (&MenuBarModelListener::menuCommandInvoked, this, info);
  54368. }
  54369. void MenuBarModel::applicationCommandListChanged()
  54370. {
  54371. menuItemsChanged();
  54372. }
  54373. END_JUCE_NAMESPACE
  54374. /*** End of inlined file: juce_MenuBarModel.cpp ***/
  54375. /*** Start of inlined file: juce_PopupMenu.cpp ***/
  54376. BEGIN_JUCE_NAMESPACE
  54377. class PopupMenu::Item
  54378. {
  54379. public:
  54380. Item()
  54381. : itemId (0), active (true), isSeparator (true), isTicked (false),
  54382. usesColour (false), customComp (0), commandManager (0)
  54383. {
  54384. }
  54385. Item (const int itemId_,
  54386. const String& text_,
  54387. const bool active_,
  54388. const bool isTicked_,
  54389. const Image* im,
  54390. const Colour& textColour_,
  54391. const bool usesColour_,
  54392. PopupMenuCustomComponent* const customComp_,
  54393. const PopupMenu* const subMenu_,
  54394. ApplicationCommandManager* const commandManager_)
  54395. : itemId (itemId_), text (text_), textColour (textColour_),
  54396. active (active_), isSeparator (false), isTicked (isTicked_),
  54397. usesColour (usesColour_), customComp (customComp_),
  54398. commandManager (commandManager_)
  54399. {
  54400. if (subMenu_ != 0)
  54401. subMenu = new PopupMenu (*subMenu_);
  54402. if (im != 0)
  54403. image = im->createCopy();
  54404. if (commandManager_ != 0 && itemId_ != 0)
  54405. {
  54406. String shortcutKey;
  54407. Array <KeyPress> keyPresses (commandManager_->getKeyMappings()
  54408. ->getKeyPressesAssignedToCommand (itemId_));
  54409. for (int i = 0; i < keyPresses.size(); ++i)
  54410. {
  54411. const String key (keyPresses.getReference(i).getTextDescription());
  54412. if (shortcutKey.isNotEmpty())
  54413. shortcutKey << ", ";
  54414. if (key.length() == 1)
  54415. shortcutKey << "shortcut: '" << key << '\'';
  54416. else
  54417. shortcutKey << key;
  54418. }
  54419. shortcutKey = shortcutKey.trim();
  54420. if (shortcutKey.isNotEmpty())
  54421. text << "<end>" << shortcutKey;
  54422. }
  54423. }
  54424. Item (const Item& other)
  54425. : itemId (other.itemId),
  54426. text (other.text),
  54427. textColour (other.textColour),
  54428. active (other.active),
  54429. isSeparator (other.isSeparator),
  54430. isTicked (other.isTicked),
  54431. usesColour (other.usesColour),
  54432. customComp (other.customComp),
  54433. commandManager (other.commandManager)
  54434. {
  54435. if (other.subMenu != 0)
  54436. subMenu = new PopupMenu (*(other.subMenu));
  54437. if (other.image != 0)
  54438. image = other.image->createCopy();
  54439. }
  54440. ~Item()
  54441. {
  54442. customComp = 0;
  54443. }
  54444. bool canBeTriggered() const throw()
  54445. {
  54446. return active && ! (isSeparator || (subMenu != 0));
  54447. }
  54448. bool hasActiveSubMenu() const throw()
  54449. {
  54450. return active && (subMenu != 0);
  54451. }
  54452. const int itemId;
  54453. String text;
  54454. const Colour textColour;
  54455. const bool active, isSeparator, isTicked, usesColour;
  54456. ScopedPointer <Image> image;
  54457. ReferenceCountedObjectPtr <PopupMenuCustomComponent> customComp;
  54458. ScopedPointer <PopupMenu> subMenu;
  54459. ApplicationCommandManager* const commandManager;
  54460. juce_UseDebuggingNewOperator
  54461. private:
  54462. Item& operator= (const Item&);
  54463. };
  54464. class PopupMenu::ItemComponent : public Component
  54465. {
  54466. public:
  54467. ItemComponent (const PopupMenu::Item& itemInfo_)
  54468. : itemInfo (itemInfo_),
  54469. isHighlighted (false)
  54470. {
  54471. if (itemInfo.customComp != 0)
  54472. addAndMakeVisible (itemInfo.customComp);
  54473. }
  54474. ~ItemComponent()
  54475. {
  54476. if (itemInfo.customComp != 0)
  54477. removeChildComponent (itemInfo.customComp);
  54478. }
  54479. void getIdealSize (int& idealWidth,
  54480. int& idealHeight,
  54481. const int standardItemHeight)
  54482. {
  54483. if (itemInfo.customComp != 0)
  54484. {
  54485. itemInfo.customComp->getIdealSize (idealWidth, idealHeight);
  54486. }
  54487. else
  54488. {
  54489. getLookAndFeel().getIdealPopupMenuItemSize (itemInfo.text,
  54490. itemInfo.isSeparator,
  54491. standardItemHeight,
  54492. idealWidth,
  54493. idealHeight);
  54494. }
  54495. }
  54496. void paint (Graphics& g)
  54497. {
  54498. if (itemInfo.customComp == 0)
  54499. {
  54500. String mainText (itemInfo.text);
  54501. String endText;
  54502. const int endIndex = mainText.indexOf (T("<end>"));
  54503. if (endIndex >= 0)
  54504. {
  54505. endText = mainText.substring (endIndex + 5).trim();
  54506. mainText = mainText.substring (0, endIndex);
  54507. }
  54508. getLookAndFeel()
  54509. .drawPopupMenuItem (g, getWidth(), getHeight(),
  54510. itemInfo.isSeparator,
  54511. itemInfo.active,
  54512. isHighlighted,
  54513. itemInfo.isTicked,
  54514. itemInfo.subMenu != 0,
  54515. mainText, endText,
  54516. itemInfo.image,
  54517. itemInfo.usesColour ? &(itemInfo.textColour) : 0);
  54518. }
  54519. }
  54520. void resized()
  54521. {
  54522. if (getNumChildComponents() > 0)
  54523. getChildComponent(0)->setBounds (2, 0, getWidth() - 4, getHeight());
  54524. }
  54525. void setHighlighted (bool shouldBeHighlighted)
  54526. {
  54527. shouldBeHighlighted = shouldBeHighlighted && itemInfo.active;
  54528. if (isHighlighted != shouldBeHighlighted)
  54529. {
  54530. isHighlighted = shouldBeHighlighted;
  54531. if (itemInfo.customComp != 0)
  54532. {
  54533. itemInfo.customComp->isHighlighted = shouldBeHighlighted;
  54534. itemInfo.customComp->repaint();
  54535. }
  54536. repaint();
  54537. }
  54538. }
  54539. PopupMenu::Item itemInfo;
  54540. juce_UseDebuggingNewOperator
  54541. private:
  54542. bool isHighlighted;
  54543. ItemComponent (const ItemComponent&);
  54544. ItemComponent& operator= (const ItemComponent&);
  54545. };
  54546. namespace PopupMenuSettings
  54547. {
  54548. static const int scrollZone = 24;
  54549. static const int borderSize = 2;
  54550. static const int timerInterval = 50;
  54551. static const int dismissCommandId = 0x6287345f;
  54552. }
  54553. class PopupMenu::Window : public Component,
  54554. private Timer
  54555. {
  54556. public:
  54557. Window()
  54558. : Component (T("menu")),
  54559. owner (0),
  54560. currentChild (0),
  54561. activeSubMenu (0),
  54562. menuBarComponent (0),
  54563. managerOfChosenCommand (0),
  54564. minimumWidth (0),
  54565. maximumNumColumns (7),
  54566. standardItemHeight (0),
  54567. isOver (false),
  54568. hasBeenOver (false),
  54569. isDown (false),
  54570. needsToScroll (false),
  54571. hideOnExit (false),
  54572. disableMouseMoves (false),
  54573. hasAnyJuceCompHadFocus (false),
  54574. numColumns (0),
  54575. contentHeight (0),
  54576. childYOffset (0),
  54577. timeEnteredCurrentChildComp (0),
  54578. scrollAcceleration (1.0)
  54579. {
  54580. menuCreationTime = lastFocused = lastScroll = Time::getMillisecondCounter();
  54581. setWantsKeyboardFocus (true);
  54582. setMouseClickGrabsKeyboardFocus (false);
  54583. setOpaque (true);
  54584. setAlwaysOnTop (true);
  54585. Desktop::getInstance().addGlobalMouseListener (this);
  54586. getActiveWindows().add (this);
  54587. }
  54588. ~Window()
  54589. {
  54590. getActiveWindows().removeValue (this);
  54591. Desktop::getInstance().removeGlobalMouseListener (this);
  54592. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  54593. activeSubMenu = 0;
  54594. deleteAllChildren();
  54595. }
  54596. static Window* create (const PopupMenu& menu,
  54597. const bool dismissOnMouseUp,
  54598. Window* const owner_,
  54599. const int minX, const int maxX,
  54600. const int minY, const int maxY,
  54601. const int minimumWidth,
  54602. const int maximumNumColumns,
  54603. const int standardItemHeight,
  54604. const bool alignToRectangle,
  54605. const int itemIdThatMustBeVisible,
  54606. Component* const menuBarComponent,
  54607. ApplicationCommandManager** managerOfChosenCommand,
  54608. Component* const componentAttachedTo)
  54609. {
  54610. if (menu.items.size() > 0)
  54611. {
  54612. int totalItems = 0;
  54613. ScopedPointer <Window> mw (new Window());
  54614. mw->setLookAndFeel (menu.lookAndFeel);
  54615. mw->setWantsKeyboardFocus (false);
  54616. mw->minimumWidth = minimumWidth;
  54617. mw->maximumNumColumns = maximumNumColumns;
  54618. mw->standardItemHeight = standardItemHeight;
  54619. mw->dismissOnMouseUp = dismissOnMouseUp;
  54620. for (int i = 0; i < menu.items.size(); ++i)
  54621. {
  54622. PopupMenu::Item* const item = menu.items.getUnchecked(i);
  54623. mw->addItem (*item);
  54624. ++totalItems;
  54625. }
  54626. if (totalItems > 0)
  54627. {
  54628. mw->owner = owner_;
  54629. mw->menuBarComponent = menuBarComponent;
  54630. mw->managerOfChosenCommand = managerOfChosenCommand;
  54631. mw->componentAttachedTo = componentAttachedTo;
  54632. mw->componentAttachedToOriginal = componentAttachedTo;
  54633. mw->calculateWindowPos (minX, maxX, minY, maxY, alignToRectangle);
  54634. mw->setTopLeftPosition (mw->windowPos.getX(),
  54635. mw->windowPos.getY());
  54636. mw->updateYPositions();
  54637. if (itemIdThatMustBeVisible != 0)
  54638. {
  54639. const int y = minY - mw->windowPos.getY();
  54640. mw->ensureItemIsVisible (itemIdThatMustBeVisible,
  54641. (((unsigned int) y) < (unsigned int) mw->windowPos.getHeight()) ? y : -1);
  54642. }
  54643. mw->resizeToBestWindowPos();
  54644. mw->addToDesktop (ComponentPeer::windowIsTemporary
  54645. | mw->getLookAndFeel().getMenuWindowFlags());
  54646. return mw.release();
  54647. }
  54648. }
  54649. return 0;
  54650. }
  54651. void paint (Graphics& g)
  54652. {
  54653. getLookAndFeel().drawPopupMenuBackground (g, getWidth(), getHeight());
  54654. }
  54655. void paintOverChildren (Graphics& g)
  54656. {
  54657. if (isScrolling())
  54658. {
  54659. LookAndFeel& lf = getLookAndFeel();
  54660. if (isScrollZoneActive (false))
  54661. lf.drawPopupMenuUpDownArrow (g, getWidth(), PopupMenuSettings::scrollZone, true);
  54662. if (isScrollZoneActive (true))
  54663. {
  54664. g.setOrigin (0, getHeight() - PopupMenuSettings::scrollZone);
  54665. lf.drawPopupMenuUpDownArrow (g, getWidth(), PopupMenuSettings::scrollZone, false);
  54666. }
  54667. }
  54668. }
  54669. bool isScrollZoneActive (bool bottomOne) const
  54670. {
  54671. return isScrolling()
  54672. && (bottomOne
  54673. ? childYOffset < contentHeight - windowPos.getHeight()
  54674. : childYOffset > 0);
  54675. }
  54676. void addItem (const PopupMenu::Item& item)
  54677. {
  54678. PopupMenu::ItemComponent* const mic = new PopupMenu::ItemComponent (item);
  54679. addAndMakeVisible (mic);
  54680. int itemW = 80;
  54681. int itemH = 16;
  54682. mic->getIdealSize (itemW, itemH, standardItemHeight);
  54683. mic->setSize (itemW, jlimit (2, 600, itemH));
  54684. mic->addMouseListener (this, false);
  54685. }
  54686. // hide this and all sub-comps
  54687. void hide (const PopupMenu::Item* const item)
  54688. {
  54689. if (isVisible())
  54690. {
  54691. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  54692. activeSubMenu = 0;
  54693. currentChild = 0;
  54694. exitModalState (item != 0 ? item->itemId : 0);
  54695. setVisible (false);
  54696. if (item != 0
  54697. && item->commandManager != 0
  54698. && item->itemId != 0)
  54699. {
  54700. *managerOfChosenCommand = item->commandManager;
  54701. }
  54702. }
  54703. }
  54704. void dismissMenu (const PopupMenu::Item* const item)
  54705. {
  54706. if (owner != 0)
  54707. {
  54708. owner->dismissMenu (item);
  54709. }
  54710. else
  54711. {
  54712. if (item != 0)
  54713. {
  54714. // need a copy of this on the stack as the one passed in will get deleted during this call
  54715. const PopupMenu::Item mi (*item);
  54716. hide (&mi);
  54717. }
  54718. else
  54719. {
  54720. hide (0);
  54721. }
  54722. }
  54723. }
  54724. void mouseMove (const MouseEvent&)
  54725. {
  54726. timerCallback();
  54727. }
  54728. void mouseDown (const MouseEvent&)
  54729. {
  54730. timerCallback();
  54731. }
  54732. void mouseDrag (const MouseEvent&)
  54733. {
  54734. timerCallback();
  54735. }
  54736. void mouseUp (const MouseEvent&)
  54737. {
  54738. timerCallback();
  54739. }
  54740. void mouseWheelMove (const MouseEvent&, float /*amountX*/, float amountY)
  54741. {
  54742. alterChildYPos (roundToInt (-10.0f * amountY * PopupMenuSettings::scrollZone));
  54743. lastMouse = Point<int> (-1, -1);
  54744. }
  54745. bool keyPressed (const KeyPress& key)
  54746. {
  54747. if (key.isKeyCode (KeyPress::downKey))
  54748. {
  54749. selectNextItem (1);
  54750. }
  54751. else if (key.isKeyCode (KeyPress::upKey))
  54752. {
  54753. selectNextItem (-1);
  54754. }
  54755. else if (key.isKeyCode (KeyPress::leftKey))
  54756. {
  54757. if (owner != 0)
  54758. {
  54759. Component::SafePointer<Window> parentWindow (owner);
  54760. PopupMenu::ItemComponent* currentChildOfParent = parentWindow->currentChild;
  54761. hide (0);
  54762. if (parentWindow != 0)
  54763. parentWindow->setCurrentlyHighlightedChild (currentChildOfParent);
  54764. disableTimerUntilMouseMoves();
  54765. }
  54766. else if (menuBarComponent != 0)
  54767. {
  54768. menuBarComponent->keyPressed (key);
  54769. }
  54770. }
  54771. else if (key.isKeyCode (KeyPress::rightKey))
  54772. {
  54773. disableTimerUntilMouseMoves();
  54774. if (showSubMenuFor (currentChild))
  54775. {
  54776. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  54777. if (activeSubMenu != 0 && activeSubMenu->isVisible())
  54778. activeSubMenu->selectNextItem (1);
  54779. }
  54780. else if (menuBarComponent != 0)
  54781. {
  54782. menuBarComponent->keyPressed (key);
  54783. }
  54784. }
  54785. else if (key.isKeyCode (KeyPress::returnKey))
  54786. {
  54787. triggerCurrentlyHighlightedItem();
  54788. }
  54789. else if (key.isKeyCode (KeyPress::escapeKey))
  54790. {
  54791. dismissMenu (0);
  54792. }
  54793. else
  54794. {
  54795. return false;
  54796. }
  54797. return true;
  54798. }
  54799. void inputAttemptWhenModal()
  54800. {
  54801. timerCallback();
  54802. if (! isOverAnyMenu())
  54803. {
  54804. if (componentAttachedTo != 0)
  54805. {
  54806. // we want to dismiss the menu, but if we do it synchronously, then
  54807. // the mouse-click will be allowed to pass through. That's good, except
  54808. // when the user clicks on the button that orginally popped the menu up,
  54809. // as they'll expect the menu to go away, and in fact it'll just
  54810. // come back. So only dismiss synchronously if they're not on the original
  54811. // comp that we're attached to.
  54812. const Point<int> mousePos (componentAttachedTo->getMouseXYRelative());
  54813. if (componentAttachedTo->reallyContains (mousePos.getX(), mousePos.getY(), true))
  54814. {
  54815. postCommandMessage (PopupMenuSettings::dismissCommandId); // dismiss asynchrounously
  54816. return;
  54817. }
  54818. }
  54819. dismissMenu (0);
  54820. }
  54821. }
  54822. void handleCommandMessage (int commandId)
  54823. {
  54824. Component::handleCommandMessage (commandId);
  54825. if (commandId == PopupMenuSettings::dismissCommandId)
  54826. dismissMenu (0);
  54827. }
  54828. void timerCallback()
  54829. {
  54830. if (! isVisible())
  54831. return;
  54832. if (componentAttachedTo != componentAttachedToOriginal)
  54833. {
  54834. dismissMenu (0);
  54835. return;
  54836. }
  54837. Window* currentlyModalWindow = dynamic_cast <Window*> (Component::getCurrentlyModalComponent());
  54838. if (currentlyModalWindow != 0 && ! treeContains (currentlyModalWindow))
  54839. return;
  54840. startTimer (PopupMenuSettings::timerInterval); // do this in case it was called from a mouse
  54841. // move rather than a real timer callback
  54842. const Point<int> globalMousePos (Desktop::getMousePosition());
  54843. const Point<int> localMousePos (globalPositionToRelative (globalMousePos));
  54844. const uint32 now = Time::getMillisecondCounter();
  54845. if (now > timeEnteredCurrentChildComp + 100
  54846. && reallyContains (localMousePos.getX(), localMousePos.getY(), true)
  54847. && currentChild->isValidComponent()
  54848. && (! disableMouseMoves)
  54849. && ! (activeSubMenu != 0 && activeSubMenu->isVisible()))
  54850. {
  54851. showSubMenuFor (currentChild);
  54852. }
  54853. if (globalMousePos != lastMouse || now > lastMouseMoveTime + 350)
  54854. {
  54855. highlightItemUnderMouse (globalMousePos, localMousePos);
  54856. }
  54857. bool overScrollArea = false;
  54858. if (isScrolling()
  54859. && (isOver || (isDown && ((unsigned int) localMousePos.getX()) < (unsigned int) getWidth()))
  54860. && ((isScrollZoneActive (false) && localMousePos.getY() < PopupMenuSettings::scrollZone)
  54861. || (isScrollZoneActive (true) && localMousePos.getY() > getHeight() - PopupMenuSettings::scrollZone)))
  54862. {
  54863. if (now > lastScroll + 20)
  54864. {
  54865. scrollAcceleration = jmin (4.0, scrollAcceleration * 1.04);
  54866. int amount = 0;
  54867. for (int i = 0; i < getNumChildComponents() && amount == 0; ++i)
  54868. amount = ((int) scrollAcceleration) * getChildComponent (i)->getHeight();
  54869. alterChildYPos (localMousePos.getY() < PopupMenuSettings::scrollZone ? -amount : amount);
  54870. lastScroll = now;
  54871. }
  54872. overScrollArea = true;
  54873. lastMouse = Point<int> (-1, -1); // trigger a mouse-move
  54874. }
  54875. else
  54876. {
  54877. scrollAcceleration = 1.0;
  54878. }
  54879. const bool wasDown = isDown;
  54880. bool isOverAny = isOverAnyMenu();
  54881. if (hideOnExit && hasBeenOver && (! isOverAny) && activeSubMenu != 0)
  54882. {
  54883. activeSubMenu->updateMouseOverStatus (globalMousePos);
  54884. isOverAny = isOverAnyMenu();
  54885. }
  54886. if (hideOnExit && hasBeenOver && ! isOverAny)
  54887. {
  54888. hide (0);
  54889. }
  54890. else
  54891. {
  54892. isDown = hasBeenOver
  54893. && (ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown()
  54894. || ModifierKeys::getCurrentModifiersRealtime().isAnyMouseButtonDown());
  54895. bool anyFocused = Process::isForegroundProcess();
  54896. if (anyFocused && Component::getCurrentlyFocusedComponent() == 0)
  54897. {
  54898. // because no component at all may have focus, our test here will
  54899. // only be triggered when something has focus and then loses it.
  54900. anyFocused = ! hasAnyJuceCompHadFocus;
  54901. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  54902. {
  54903. if (ComponentPeer::getPeer (i)->isFocused())
  54904. {
  54905. anyFocused = true;
  54906. hasAnyJuceCompHadFocus = true;
  54907. break;
  54908. }
  54909. }
  54910. }
  54911. if (! anyFocused)
  54912. {
  54913. if (now > lastFocused + 10)
  54914. {
  54915. wasHiddenBecauseOfAppChange() = true;
  54916. dismissMenu (0);
  54917. return; // may have been deleted by the previous call..
  54918. }
  54919. }
  54920. else if (wasDown && now > menuCreationTime + 250
  54921. && ! (isDown || overScrollArea))
  54922. {
  54923. isOver = reallyContains (localMousePos.getX(), localMousePos.getY(), true);
  54924. if (isOver)
  54925. {
  54926. triggerCurrentlyHighlightedItem();
  54927. }
  54928. else if ((hasBeenOver || ! dismissOnMouseUp) && ! isOverAny)
  54929. {
  54930. dismissMenu (0);
  54931. }
  54932. return; // may have been deleted by the previous calls..
  54933. }
  54934. else
  54935. {
  54936. lastFocused = now;
  54937. }
  54938. }
  54939. }
  54940. static Array<Window*>& getActiveWindows()
  54941. {
  54942. static Array<Window*> activeMenuWindows;
  54943. return activeMenuWindows;
  54944. }
  54945. static bool& wasHiddenBecauseOfAppChange() throw()
  54946. {
  54947. static bool b = false;
  54948. return b;
  54949. }
  54950. juce_UseDebuggingNewOperator
  54951. private:
  54952. Window* owner;
  54953. PopupMenu::ItemComponent* currentChild;
  54954. ScopedPointer <Window> activeSubMenu;
  54955. Component* menuBarComponent;
  54956. ApplicationCommandManager** managerOfChosenCommand;
  54957. Component::SafePointer<Component> componentAttachedTo;
  54958. Component* componentAttachedToOriginal;
  54959. Rectangle<int> windowPos;
  54960. Point<int> lastMouse;
  54961. int minimumWidth, maximumNumColumns, standardItemHeight;
  54962. bool isOver, hasBeenOver, isDown, needsToScroll;
  54963. bool dismissOnMouseUp, hideOnExit, disableMouseMoves, hasAnyJuceCompHadFocus;
  54964. int numColumns, contentHeight, childYOffset;
  54965. Array <int> columnWidths;
  54966. uint32 menuCreationTime, lastFocused, lastScroll, lastMouseMoveTime, timeEnteredCurrentChildComp;
  54967. double scrollAcceleration;
  54968. bool overlaps (const Rectangle<int>& r) const
  54969. {
  54970. return r.intersects (getBounds())
  54971. || (owner != 0 && owner->overlaps (r));
  54972. }
  54973. bool isOverAnyMenu() const
  54974. {
  54975. return (owner != 0) ? owner->isOverAnyMenu()
  54976. : isOverChildren();
  54977. }
  54978. bool isOverChildren() const
  54979. {
  54980. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  54981. return isVisible()
  54982. && (isOver || (activeSubMenu != 0 && activeSubMenu->isOverChildren()));
  54983. }
  54984. void updateMouseOverStatus (const Point<int>& globalMousePos)
  54985. {
  54986. const Point<int> relPos (globalPositionToRelative (globalMousePos));
  54987. isOver = reallyContains (relPos.getX(), relPos.getY(), true);
  54988. if (activeSubMenu != 0)
  54989. activeSubMenu->updateMouseOverStatus (globalMousePos);
  54990. }
  54991. bool treeContains (const Window* const window) const throw()
  54992. {
  54993. const Window* mw = this;
  54994. while (mw->owner != 0)
  54995. mw = mw->owner;
  54996. while (mw != 0)
  54997. {
  54998. if (mw == window)
  54999. return true;
  55000. mw = mw->activeSubMenu;
  55001. }
  55002. return false;
  55003. }
  55004. void calculateWindowPos (const int minX, const int maxX,
  55005. const int minY, const int maxY,
  55006. const bool alignToRectangle)
  55007. {
  55008. const Rectangle<int> mon (Desktop::getInstance()
  55009. .getMonitorAreaContaining (Point<int> ((minX + maxX) / 2,
  55010. (minY + maxY) / 2),
  55011. #if JUCE_MAC
  55012. true));
  55013. #else
  55014. false)); // on windows, don't stop the menu overlapping the taskbar
  55015. #endif
  55016. int x, y, widthToUse, heightToUse;
  55017. layoutMenuItems (mon.getWidth() - 24, widthToUse, heightToUse);
  55018. if (alignToRectangle)
  55019. {
  55020. x = minX;
  55021. const int spaceUnder = mon.getHeight() - (maxY - mon.getY());
  55022. const int spaceOver = minY - mon.getY();
  55023. if (heightToUse < spaceUnder - 30 || spaceUnder >= spaceOver)
  55024. y = maxY;
  55025. else
  55026. y = minY - heightToUse;
  55027. }
  55028. else
  55029. {
  55030. bool tendTowardsRight = (minX + maxX) / 2 < mon.getCentreX();
  55031. if (owner != 0)
  55032. {
  55033. if (owner->owner != 0)
  55034. {
  55035. const bool ownerGoingRight = (owner->getX() + owner->getWidth() / 2
  55036. > owner->owner->getX() + owner->owner->getWidth() / 2);
  55037. if (ownerGoingRight && maxX + widthToUse < mon.getRight() - 4)
  55038. tendTowardsRight = true;
  55039. else if ((! ownerGoingRight) && minX > widthToUse + 4)
  55040. tendTowardsRight = false;
  55041. }
  55042. else if (maxX + widthToUse < mon.getRight() - 32)
  55043. {
  55044. tendTowardsRight = true;
  55045. }
  55046. }
  55047. const int biggestSpace = jmax (mon.getRight() - maxX,
  55048. minX - mon.getX()) - 32;
  55049. if (biggestSpace < widthToUse)
  55050. {
  55051. layoutMenuItems (biggestSpace + (maxX - minX) / 3, widthToUse, heightToUse);
  55052. if (numColumns > 1)
  55053. layoutMenuItems (biggestSpace - 4, widthToUse, heightToUse);
  55054. tendTowardsRight = (mon.getRight() - maxX) >= (minX - mon.getX());
  55055. }
  55056. if (tendTowardsRight)
  55057. x = jmin (mon.getRight() - widthToUse - 4, maxX);
  55058. else
  55059. x = jmax (mon.getX() + 4, minX - widthToUse);
  55060. y = minY;
  55061. if ((minY + maxY) / 2 > mon.getCentreY())
  55062. y = jmax (mon.getY(), maxY - heightToUse);
  55063. }
  55064. x = jmax (mon.getX() + 1, jmin (mon.getRight() - (widthToUse + 6), x));
  55065. y = jmax (mon.getY() + 1, jmin (mon.getBottom() - (heightToUse + 6), y));
  55066. windowPos.setBounds (x, y, widthToUse, heightToUse);
  55067. // sets this flag if it's big enough to obscure any of its parent menus
  55068. hideOnExit = (owner != 0)
  55069. && owner->windowPos.intersects (windowPos.expanded (-4, -4));
  55070. }
  55071. void layoutMenuItems (const int maxMenuW, int& width, int& height)
  55072. {
  55073. numColumns = 0;
  55074. contentHeight = 0;
  55075. const int maxMenuH = getParentHeight() - 24;
  55076. int totalW;
  55077. do
  55078. {
  55079. ++numColumns;
  55080. totalW = workOutBestSize (maxMenuW);
  55081. if (totalW > maxMenuW)
  55082. {
  55083. numColumns = jmax (1, numColumns - 1);
  55084. totalW = workOutBestSize (maxMenuW); // to update col widths
  55085. break;
  55086. }
  55087. else if (totalW > maxMenuW / 2 || contentHeight < maxMenuH)
  55088. {
  55089. break;
  55090. }
  55091. } while (numColumns < maximumNumColumns);
  55092. const int actualH = jmin (contentHeight, maxMenuH);
  55093. needsToScroll = contentHeight > actualH;
  55094. width = updateYPositions();
  55095. height = actualH + PopupMenuSettings::borderSize * 2;
  55096. }
  55097. int workOutBestSize (const int maxMenuW)
  55098. {
  55099. int totalW = 0;
  55100. contentHeight = 0;
  55101. int childNum = 0;
  55102. for (int col = 0; col < numColumns; ++col)
  55103. {
  55104. int i, colW = 50, colH = 0;
  55105. const int numChildren = jmin (getNumChildComponents() - childNum,
  55106. (getNumChildComponents() + numColumns - 1) / numColumns);
  55107. for (i = numChildren; --i >= 0;)
  55108. {
  55109. colW = jmax (colW, getChildComponent (childNum + i)->getWidth());
  55110. colH += getChildComponent (childNum + i)->getHeight();
  55111. }
  55112. colW = jmin (maxMenuW / jmax (1, numColumns - 2), colW + PopupMenuSettings::borderSize * 2);
  55113. columnWidths.set (col, colW);
  55114. totalW += colW;
  55115. contentHeight = jmax (contentHeight, colH);
  55116. childNum += numChildren;
  55117. }
  55118. if (totalW < minimumWidth)
  55119. {
  55120. totalW = minimumWidth;
  55121. for (int col = 0; col < numColumns; ++col)
  55122. columnWidths.set (0, totalW / numColumns);
  55123. }
  55124. return totalW;
  55125. }
  55126. void ensureItemIsVisible (const int itemId, int wantedY)
  55127. {
  55128. jassert (itemId != 0)
  55129. for (int i = getNumChildComponents(); --i >= 0;)
  55130. {
  55131. PopupMenu::ItemComponent* const m = (PopupMenu::ItemComponent*) getChildComponent (i);
  55132. if (m != 0
  55133. && m->itemInfo.itemId == itemId
  55134. && windowPos.getHeight() > PopupMenuSettings::scrollZone * 4)
  55135. {
  55136. const int currentY = m->getY();
  55137. if (wantedY > 0 || currentY < 0 || m->getBottom() > windowPos.getHeight())
  55138. {
  55139. if (wantedY < 0)
  55140. wantedY = jlimit (PopupMenuSettings::scrollZone,
  55141. jmax (PopupMenuSettings::scrollZone,
  55142. windowPos.getHeight() - (PopupMenuSettings::scrollZone + m->getHeight())),
  55143. currentY);
  55144. const Rectangle<int> mon (Desktop::getInstance().getMonitorAreaContaining (windowPos.getPosition(), true));
  55145. int deltaY = wantedY - currentY;
  55146. windowPos.setSize (jmin (windowPos.getWidth(), mon.getWidth()),
  55147. jmin (windowPos.getHeight(), mon.getHeight()));
  55148. const int newY = jlimit (mon.getY(),
  55149. mon.getBottom() - windowPos.getHeight(),
  55150. windowPos.getY() + deltaY);
  55151. deltaY -= newY - windowPos.getY();
  55152. childYOffset -= deltaY;
  55153. windowPos.setPosition (windowPos.getX(), newY);
  55154. updateYPositions();
  55155. }
  55156. break;
  55157. }
  55158. }
  55159. }
  55160. void resizeToBestWindowPos()
  55161. {
  55162. Rectangle<int> r (windowPos);
  55163. if (childYOffset < 0)
  55164. {
  55165. r.setBounds (r.getX(), r.getY() - childYOffset,
  55166. r.getWidth(), r.getHeight() + childYOffset);
  55167. }
  55168. else if (childYOffset > 0)
  55169. {
  55170. const int spaceAtBottom = r.getHeight() - (contentHeight - childYOffset);
  55171. if (spaceAtBottom > 0)
  55172. r.setSize (r.getWidth(), r.getHeight() - spaceAtBottom);
  55173. }
  55174. setBounds (r);
  55175. updateYPositions();
  55176. }
  55177. void alterChildYPos (const int delta)
  55178. {
  55179. if (isScrolling())
  55180. {
  55181. childYOffset += delta;
  55182. if (delta < 0)
  55183. {
  55184. childYOffset = jmax (childYOffset, 0);
  55185. }
  55186. else if (delta > 0)
  55187. {
  55188. childYOffset = jmin (childYOffset,
  55189. contentHeight - windowPos.getHeight() + PopupMenuSettings::borderSize);
  55190. }
  55191. updateYPositions();
  55192. }
  55193. else
  55194. {
  55195. childYOffset = 0;
  55196. }
  55197. resizeToBestWindowPos();
  55198. repaint();
  55199. }
  55200. int updateYPositions()
  55201. {
  55202. int x = 0;
  55203. int childNum = 0;
  55204. for (int col = 0; col < numColumns; ++col)
  55205. {
  55206. const int numChildren = jmin (getNumChildComponents() - childNum,
  55207. (getNumChildComponents() + numColumns - 1) / numColumns);
  55208. const int colW = columnWidths [col];
  55209. int y = PopupMenuSettings::borderSize - (childYOffset + (getY() - windowPos.getY()));
  55210. for (int i = 0; i < numChildren; ++i)
  55211. {
  55212. Component* const c = getChildComponent (childNum + i);
  55213. c->setBounds (x, y, colW, c->getHeight());
  55214. y += c->getHeight();
  55215. }
  55216. x += colW;
  55217. childNum += numChildren;
  55218. }
  55219. return x;
  55220. }
  55221. bool isScrolling() const throw()
  55222. {
  55223. return childYOffset != 0 || needsToScroll;
  55224. }
  55225. void setCurrentlyHighlightedChild (PopupMenu::ItemComponent* const child)
  55226. {
  55227. if (currentChild->isValidComponent())
  55228. currentChild->setHighlighted (false);
  55229. currentChild = child;
  55230. if (currentChild != 0)
  55231. {
  55232. currentChild->setHighlighted (true);
  55233. timeEnteredCurrentChildComp = Time::getApproximateMillisecondCounter();
  55234. }
  55235. }
  55236. bool showSubMenuFor (PopupMenu::ItemComponent* const childComp)
  55237. {
  55238. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  55239. activeSubMenu = 0;
  55240. if (childComp->isValidComponent() && childComp->itemInfo.hasActiveSubMenu())
  55241. {
  55242. const Point<int> topLeft (childComp->relativePositionToGlobal (Point<int>()));
  55243. const Point<int> bottomRight (childComp->relativePositionToGlobal (Point<int> (childComp->getWidth(), childComp->getHeight())));
  55244. activeSubMenu = Window::create (*(childComp->itemInfo.subMenu),
  55245. dismissOnMouseUp,
  55246. this,
  55247. topLeft.getX(), bottomRight.getX(), topLeft.getY(), bottomRight.getY(),
  55248. 0, maximumNumColumns,
  55249. standardItemHeight,
  55250. false, 0, menuBarComponent,
  55251. managerOfChosenCommand,
  55252. componentAttachedTo);
  55253. if (activeSubMenu != 0)
  55254. {
  55255. activeSubMenu->setVisible (true);
  55256. activeSubMenu->enterModalState (false);
  55257. activeSubMenu->toFront (false);
  55258. return true;
  55259. }
  55260. }
  55261. return false;
  55262. }
  55263. void highlightItemUnderMouse (const Point<int>& globalMousePos, const Point<int>& localMousePos)
  55264. {
  55265. isOver = reallyContains (localMousePos.getX(), localMousePos.getY(), true);
  55266. if (isOver)
  55267. hasBeenOver = true;
  55268. if (lastMouse.getDistanceFrom (globalMousePos) > 2)
  55269. {
  55270. lastMouseMoveTime = Time::getApproximateMillisecondCounter();
  55271. if (disableMouseMoves && isOver)
  55272. disableMouseMoves = false;
  55273. }
  55274. if (disableMouseMoves)
  55275. return;
  55276. bool isMovingTowardsMenu = false;
  55277. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent())
  55278. if (isOver && (activeSubMenu != 0) && globalMousePos != lastMouse)
  55279. {
  55280. // try to intelligently guess whether the user is moving the mouse towards a currently-open
  55281. // submenu. To do this, look at whether the mouse stays inside a triangular region that
  55282. // extends from the last mouse pos to the submenu's rectangle..
  55283. float subX = (float) activeSubMenu->getScreenX();
  55284. if (activeSubMenu->getX() > getX())
  55285. {
  55286. lastMouse -= Point<int> (2, 0); // to enlarge the triangle a bit, in case the mouse only moves a couple of pixels
  55287. }
  55288. else
  55289. {
  55290. lastMouse += Point<int> (2, 0);
  55291. subX += activeSubMenu->getWidth();
  55292. }
  55293. Path areaTowardsSubMenu;
  55294. areaTowardsSubMenu.addTriangle ((float) lastMouse.getX(),
  55295. (float) lastMouse.getY(),
  55296. subX,
  55297. (float) activeSubMenu->getScreenY(),
  55298. subX,
  55299. (float) (activeSubMenu->getScreenY() + activeSubMenu->getHeight()));
  55300. isMovingTowardsMenu = areaTowardsSubMenu.contains ((float) globalMousePos.getX(), (float) globalMousePos.getY());
  55301. }
  55302. lastMouse = globalMousePos;
  55303. if (! isMovingTowardsMenu)
  55304. {
  55305. Component* c = getComponentAt (localMousePos.getX(), localMousePos.getY());
  55306. if (c == this)
  55307. c = 0;
  55308. PopupMenu::ItemComponent* mic = dynamic_cast <PopupMenu::ItemComponent*> (c);
  55309. if (mic == 0 && c != 0)
  55310. mic = c->findParentComponentOfClass ((PopupMenu::ItemComponent*) 0);
  55311. if (mic != currentChild
  55312. && (isOver || (activeSubMenu == 0) || ! activeSubMenu->isVisible()))
  55313. {
  55314. if (isOver && (c != 0) && (activeSubMenu != 0))
  55315. {
  55316. activeSubMenu->hide (0);
  55317. }
  55318. if (! isOver)
  55319. mic = 0;
  55320. setCurrentlyHighlightedChild (mic);
  55321. }
  55322. }
  55323. }
  55324. void triggerCurrentlyHighlightedItem()
  55325. {
  55326. if (currentChild->isValidComponent()
  55327. && currentChild->itemInfo.canBeTriggered()
  55328. && (currentChild->itemInfo.customComp == 0
  55329. || currentChild->itemInfo.customComp->isTriggeredAutomatically))
  55330. {
  55331. dismissMenu (&currentChild->itemInfo);
  55332. }
  55333. }
  55334. void selectNextItem (const int delta)
  55335. {
  55336. disableTimerUntilMouseMoves();
  55337. PopupMenu::ItemComponent* mic = 0;
  55338. bool wasLastOne = (currentChild == 0);
  55339. const int numItems = getNumChildComponents();
  55340. for (int i = 0; i < numItems + 1; ++i)
  55341. {
  55342. int index = (delta > 0) ? i : (numItems - 1 - i);
  55343. index = (index + numItems) % numItems;
  55344. mic = dynamic_cast <PopupMenu::ItemComponent*> (getChildComponent (index));
  55345. if (mic != 0 && (mic->itemInfo.canBeTriggered() || mic->itemInfo.hasActiveSubMenu())
  55346. && wasLastOne)
  55347. break;
  55348. if (mic == currentChild)
  55349. wasLastOne = true;
  55350. }
  55351. setCurrentlyHighlightedChild (mic);
  55352. }
  55353. void disableTimerUntilMouseMoves()
  55354. {
  55355. disableMouseMoves = true;
  55356. if (owner != 0)
  55357. owner->disableTimerUntilMouseMoves();
  55358. }
  55359. Window (const Window&);
  55360. Window& operator= (const Window&);
  55361. };
  55362. PopupMenu::PopupMenu()
  55363. : lookAndFeel (0),
  55364. separatorPending (false)
  55365. {
  55366. }
  55367. PopupMenu::PopupMenu (const PopupMenu& other)
  55368. : lookAndFeel (other.lookAndFeel),
  55369. separatorPending (false)
  55370. {
  55371. items.ensureStorageAllocated (other.items.size());
  55372. for (int i = 0; i < other.items.size(); ++i)
  55373. items.add (new Item (*other.items.getUnchecked(i)));
  55374. }
  55375. PopupMenu& PopupMenu::operator= (const PopupMenu& other)
  55376. {
  55377. if (this != &other)
  55378. {
  55379. lookAndFeel = other.lookAndFeel;
  55380. clear();
  55381. items.ensureStorageAllocated (other.items.size());
  55382. for (int i = 0; i < other.items.size(); ++i)
  55383. items.add (new Item (*other.items.getUnchecked(i)));
  55384. }
  55385. return *this;
  55386. }
  55387. PopupMenu::~PopupMenu()
  55388. {
  55389. clear();
  55390. }
  55391. void PopupMenu::clear()
  55392. {
  55393. items.clear();
  55394. separatorPending = false;
  55395. }
  55396. void PopupMenu::addSeparatorIfPending()
  55397. {
  55398. if (separatorPending)
  55399. {
  55400. separatorPending = false;
  55401. if (items.size() > 0)
  55402. items.add (new Item());
  55403. }
  55404. }
  55405. void PopupMenu::addItem (const int itemResultId,
  55406. const String& itemText,
  55407. const bool isActive,
  55408. const bool isTicked,
  55409. const Image* const iconToUse)
  55410. {
  55411. jassert (itemResultId != 0); // 0 is used as a return value to indicate that the user
  55412. // didn't pick anything, so you shouldn't use it as the id
  55413. // for an item..
  55414. addSeparatorIfPending();
  55415. items.add (new Item (itemResultId, itemText, isActive, isTicked,
  55416. iconToUse, Colours::black, false, 0, 0, 0));
  55417. }
  55418. void PopupMenu::addCommandItem (ApplicationCommandManager* commandManager,
  55419. const int commandID,
  55420. const String& displayName)
  55421. {
  55422. jassert (commandManager != 0 && commandID != 0);
  55423. const ApplicationCommandInfo* const registeredInfo = commandManager->getCommandForID (commandID);
  55424. if (registeredInfo != 0)
  55425. {
  55426. ApplicationCommandInfo info (*registeredInfo);
  55427. ApplicationCommandTarget* const target = commandManager->getTargetForCommand (commandID, info);
  55428. addSeparatorIfPending();
  55429. items.add (new Item (commandID,
  55430. displayName.isNotEmpty() ? displayName
  55431. : info.shortName,
  55432. target != 0 && (info.flags & ApplicationCommandInfo::isDisabled) == 0,
  55433. (info.flags & ApplicationCommandInfo::isTicked) != 0,
  55434. 0,
  55435. Colours::black,
  55436. false,
  55437. 0, 0,
  55438. commandManager));
  55439. }
  55440. }
  55441. void PopupMenu::addColouredItem (const int itemResultId,
  55442. const String& itemText,
  55443. const Colour& itemTextColour,
  55444. const bool isActive,
  55445. const bool isTicked,
  55446. const Image* const iconToUse)
  55447. {
  55448. jassert (itemResultId != 0); // 0 is used as a return value to indicate that the user
  55449. // didn't pick anything, so you shouldn't use it as the id
  55450. // for an item..
  55451. addSeparatorIfPending();
  55452. items.add (new Item (itemResultId, itemText, isActive, isTicked,
  55453. iconToUse, itemTextColour, true, 0, 0, 0));
  55454. }
  55455. void PopupMenu::addCustomItem (const int itemResultId,
  55456. PopupMenuCustomComponent* const customComponent)
  55457. {
  55458. jassert (itemResultId != 0); // 0 is used as a return value to indicate that the user
  55459. // didn't pick anything, so you shouldn't use it as the id
  55460. // for an item..
  55461. addSeparatorIfPending();
  55462. items.add (new Item (itemResultId, String::empty, true, false, 0,
  55463. Colours::black, false, customComponent, 0, 0));
  55464. }
  55465. class NormalComponentWrapper : public PopupMenuCustomComponent
  55466. {
  55467. public:
  55468. NormalComponentWrapper (Component* const comp,
  55469. const int w, const int h,
  55470. const bool triggerMenuItemAutomaticallyWhenClicked)
  55471. : PopupMenuCustomComponent (triggerMenuItemAutomaticallyWhenClicked),
  55472. width (w),
  55473. height (h)
  55474. {
  55475. addAndMakeVisible (comp);
  55476. }
  55477. ~NormalComponentWrapper() {}
  55478. void getIdealSize (int& idealWidth, int& idealHeight)
  55479. {
  55480. idealWidth = width;
  55481. idealHeight = height;
  55482. }
  55483. void resized()
  55484. {
  55485. if (getChildComponent(0) != 0)
  55486. getChildComponent(0)->setBounds (0, 0, getWidth(), getHeight());
  55487. }
  55488. juce_UseDebuggingNewOperator
  55489. private:
  55490. const int width, height;
  55491. NormalComponentWrapper (const NormalComponentWrapper&);
  55492. NormalComponentWrapper& operator= (const NormalComponentWrapper&);
  55493. };
  55494. void PopupMenu::addCustomItem (const int itemResultId,
  55495. Component* customComponent,
  55496. int idealWidth, int idealHeight,
  55497. const bool triggerMenuItemAutomaticallyWhenClicked)
  55498. {
  55499. addCustomItem (itemResultId,
  55500. new NormalComponentWrapper (customComponent,
  55501. idealWidth, idealHeight,
  55502. triggerMenuItemAutomaticallyWhenClicked));
  55503. }
  55504. void PopupMenu::addSubMenu (const String& subMenuName,
  55505. const PopupMenu& subMenu,
  55506. const bool isActive,
  55507. Image* const iconToUse,
  55508. const bool isTicked)
  55509. {
  55510. addSeparatorIfPending();
  55511. items.add (new Item (0, subMenuName, isActive && (subMenu.getNumItems() > 0), isTicked,
  55512. iconToUse, Colours::black, false, 0, &subMenu, 0));
  55513. }
  55514. void PopupMenu::addSeparator()
  55515. {
  55516. separatorPending = true;
  55517. }
  55518. class HeaderItemComponent : public PopupMenuCustomComponent
  55519. {
  55520. public:
  55521. HeaderItemComponent (const String& name)
  55522. : PopupMenuCustomComponent (false)
  55523. {
  55524. setName (name);
  55525. }
  55526. ~HeaderItemComponent()
  55527. {
  55528. }
  55529. void paint (Graphics& g)
  55530. {
  55531. Font f (getLookAndFeel().getPopupMenuFont());
  55532. f.setBold (true);
  55533. g.setFont (f);
  55534. g.setColour (findColour (PopupMenu::headerTextColourId));
  55535. g.drawFittedText (getName(),
  55536. 12, 0, getWidth() - 16, proportionOfHeight (0.8f),
  55537. Justification::bottomLeft, 1);
  55538. }
  55539. void getIdealSize (int& idealWidth,
  55540. int& idealHeight)
  55541. {
  55542. getLookAndFeel().getIdealPopupMenuItemSize (getName(), false, -1, idealWidth, idealHeight);
  55543. idealHeight += idealHeight / 2;
  55544. idealWidth += idealWidth / 4;
  55545. }
  55546. juce_UseDebuggingNewOperator
  55547. };
  55548. void PopupMenu::addSectionHeader (const String& title)
  55549. {
  55550. addCustomItem (0X4734a34f, new HeaderItemComponent (title));
  55551. }
  55552. Component* PopupMenu::createMenuComponent (const int x, const int y, const int w, const int h,
  55553. const int itemIdThatMustBeVisible,
  55554. const int minimumWidth,
  55555. const int maximumNumColumns,
  55556. const int standardItemHeight,
  55557. const bool alignToRectangle,
  55558. Component* menuBarComponent,
  55559. ApplicationCommandManager** managerOfChosenCommand,
  55560. Component* const componentAttachedTo)
  55561. {
  55562. Window* const pw
  55563. = Window::create (*this,
  55564. ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown(),
  55565. 0,
  55566. x, x + w,
  55567. y, y + h,
  55568. minimumWidth,
  55569. maximumNumColumns,
  55570. standardItemHeight,
  55571. alignToRectangle,
  55572. itemIdThatMustBeVisible,
  55573. menuBarComponent,
  55574. managerOfChosenCommand,
  55575. componentAttachedTo);
  55576. if (pw != 0)
  55577. pw->setVisible (true);
  55578. return pw;
  55579. }
  55580. int PopupMenu::showMenu (const int x, const int y, const int w, const int h,
  55581. const int itemIdThatMustBeVisible,
  55582. const int minimumWidth,
  55583. const int maximumNumColumns,
  55584. const int standardItemHeight,
  55585. const bool alignToRectangle,
  55586. Component* const componentAttachedTo)
  55587. {
  55588. Component::SafePointer<Component> prevFocused (Component::getCurrentlyFocusedComponent());
  55589. Component::SafePointer<Component> prevTopLevel ((prevFocused != 0) ? prevFocused->getTopLevelComponent() : 0);
  55590. Window::wasHiddenBecauseOfAppChange() = false;
  55591. int result = 0;
  55592. ApplicationCommandManager* managerOfChosenCommand = 0;
  55593. ScopedPointer <Component> popupComp (createMenuComponent (x, y, w, h,
  55594. itemIdThatMustBeVisible,
  55595. minimumWidth,
  55596. maximumNumColumns > 0 ? maximumNumColumns : 7,
  55597. standardItemHeight,
  55598. alignToRectangle, 0,
  55599. &managerOfChosenCommand,
  55600. componentAttachedTo));
  55601. if (popupComp != 0)
  55602. {
  55603. popupComp->enterModalState (false);
  55604. popupComp->toFront (false); // need to do this after making it modal, or it could
  55605. // be stuck behind other comps that are already modal..
  55606. result = popupComp->runModalLoop();
  55607. popupComp = 0;
  55608. if (! Window::wasHiddenBecauseOfAppChange())
  55609. {
  55610. if (prevTopLevel != 0)
  55611. prevTopLevel->toFront (true);
  55612. if (prevFocused != 0)
  55613. prevFocused->grabKeyboardFocus();
  55614. }
  55615. }
  55616. if (managerOfChosenCommand != 0 && result != 0)
  55617. {
  55618. ApplicationCommandTarget::InvocationInfo info (result);
  55619. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromMenu;
  55620. managerOfChosenCommand->invoke (info, true);
  55621. }
  55622. return result;
  55623. }
  55624. int PopupMenu::show (const int itemIdThatMustBeVisible,
  55625. const int minimumWidth,
  55626. const int maximumNumColumns,
  55627. const int standardItemHeight)
  55628. {
  55629. const Point<int> mousePos (Desktop::getMousePosition());
  55630. return showAt (mousePos.getX(), mousePos.getY(),
  55631. itemIdThatMustBeVisible,
  55632. minimumWidth,
  55633. maximumNumColumns,
  55634. standardItemHeight);
  55635. }
  55636. int PopupMenu::showAt (const int screenX,
  55637. const int screenY,
  55638. const int itemIdThatMustBeVisible,
  55639. const int minimumWidth,
  55640. const int maximumNumColumns,
  55641. const int standardItemHeight)
  55642. {
  55643. return showMenu (screenX, screenY, 1, 1,
  55644. itemIdThatMustBeVisible,
  55645. minimumWidth, maximumNumColumns,
  55646. standardItemHeight,
  55647. false, 0);
  55648. }
  55649. int PopupMenu::showAt (Component* componentToAttachTo,
  55650. const int itemIdThatMustBeVisible,
  55651. const int minimumWidth,
  55652. const int maximumNumColumns,
  55653. const int standardItemHeight)
  55654. {
  55655. if (componentToAttachTo != 0)
  55656. {
  55657. return showMenu (componentToAttachTo->getScreenX(),
  55658. componentToAttachTo->getScreenY(),
  55659. componentToAttachTo->getWidth(),
  55660. componentToAttachTo->getHeight(),
  55661. itemIdThatMustBeVisible,
  55662. minimumWidth,
  55663. maximumNumColumns,
  55664. standardItemHeight,
  55665. true, componentToAttachTo);
  55666. }
  55667. else
  55668. {
  55669. return show (itemIdThatMustBeVisible,
  55670. minimumWidth,
  55671. maximumNumColumns,
  55672. standardItemHeight);
  55673. }
  55674. }
  55675. void JUCE_CALLTYPE PopupMenu::dismissAllActiveMenus()
  55676. {
  55677. for (int i = Window::getActiveWindows().size(); --i >= 0;)
  55678. {
  55679. Window* const pmw = Window::getActiveWindows()[i];
  55680. if (pmw != 0)
  55681. pmw->dismissMenu (0);
  55682. }
  55683. }
  55684. int PopupMenu::getNumItems() const throw()
  55685. {
  55686. int num = 0;
  55687. for (int i = items.size(); --i >= 0;)
  55688. if (! (items.getUnchecked(i))->isSeparator)
  55689. ++num;
  55690. return num;
  55691. }
  55692. bool PopupMenu::containsCommandItem (const int commandID) const
  55693. {
  55694. for (int i = items.size(); --i >= 0;)
  55695. {
  55696. const Item* mi = items.getUnchecked (i);
  55697. if ((mi->itemId == commandID && mi->commandManager != 0)
  55698. || (mi->subMenu != 0 && mi->subMenu->containsCommandItem (commandID)))
  55699. {
  55700. return true;
  55701. }
  55702. }
  55703. return false;
  55704. }
  55705. bool PopupMenu::containsAnyActiveItems() const throw()
  55706. {
  55707. for (int i = items.size(); --i >= 0;)
  55708. {
  55709. const Item* const mi = items.getUnchecked (i);
  55710. if (mi->subMenu != 0)
  55711. {
  55712. if (mi->subMenu->containsAnyActiveItems())
  55713. return true;
  55714. }
  55715. else if (mi->active)
  55716. {
  55717. return true;
  55718. }
  55719. }
  55720. return false;
  55721. }
  55722. void PopupMenu::setLookAndFeel (LookAndFeel* const newLookAndFeel)
  55723. {
  55724. lookAndFeel = newLookAndFeel;
  55725. }
  55726. PopupMenuCustomComponent::PopupMenuCustomComponent (const bool isTriggeredAutomatically_)
  55727. : isHighlighted (false),
  55728. isTriggeredAutomatically (isTriggeredAutomatically_)
  55729. {
  55730. }
  55731. PopupMenuCustomComponent::~PopupMenuCustomComponent()
  55732. {
  55733. }
  55734. void PopupMenuCustomComponent::triggerMenuItem()
  55735. {
  55736. PopupMenu::ItemComponent* const mic = dynamic_cast <PopupMenu::ItemComponent*> (getParentComponent());
  55737. if (mic != 0)
  55738. {
  55739. PopupMenu::Window* const pmw = dynamic_cast <PopupMenu::Window*> (mic->getParentComponent());
  55740. if (pmw != 0)
  55741. {
  55742. pmw->dismissMenu (&mic->itemInfo);
  55743. }
  55744. else
  55745. {
  55746. // something must have gone wrong with the component hierarchy if this happens..
  55747. jassertfalse
  55748. }
  55749. }
  55750. else
  55751. {
  55752. // why isn't this component inside a menu? Not much point triggering the item if
  55753. // there's no menu.
  55754. jassertfalse
  55755. }
  55756. }
  55757. PopupMenu::MenuItemIterator::MenuItemIterator (const PopupMenu& menu_)
  55758. : subMenu (0),
  55759. itemId (0),
  55760. isSeparator (false),
  55761. isTicked (false),
  55762. isEnabled (false),
  55763. isCustomComponent (false),
  55764. isSectionHeader (false),
  55765. customColour (0),
  55766. customImage (0),
  55767. menu (menu_),
  55768. index (0)
  55769. {
  55770. }
  55771. PopupMenu::MenuItemIterator::~MenuItemIterator()
  55772. {
  55773. }
  55774. bool PopupMenu::MenuItemIterator::next()
  55775. {
  55776. if (index >= menu.items.size())
  55777. return false;
  55778. const Item* const item = menu.items.getUnchecked (index);
  55779. ++index;
  55780. itemName = item->customComp != 0 ? item->customComp->getName() : item->text;
  55781. subMenu = item->subMenu;
  55782. itemId = item->itemId;
  55783. isSeparator = item->isSeparator;
  55784. isTicked = item->isTicked;
  55785. isEnabled = item->active;
  55786. isSectionHeader = dynamic_cast <HeaderItemComponent*> ((PopupMenuCustomComponent*) item->customComp) != 0;
  55787. isCustomComponent = (! isSectionHeader) && item->customComp != 0;
  55788. customColour = item->usesColour ? &(item->textColour) : 0;
  55789. customImage = item->image;
  55790. commandManager = item->commandManager;
  55791. return true;
  55792. }
  55793. END_JUCE_NAMESPACE
  55794. /*** End of inlined file: juce_PopupMenu.cpp ***/
  55795. /*** Start of inlined file: juce_ComponentDragger.cpp ***/
  55796. BEGIN_JUCE_NAMESPACE
  55797. ComponentDragger::ComponentDragger()
  55798. : constrainer (0)
  55799. {
  55800. }
  55801. ComponentDragger::~ComponentDragger()
  55802. {
  55803. }
  55804. void ComponentDragger::startDraggingComponent (Component* const componentToDrag,
  55805. ComponentBoundsConstrainer* const constrainer_)
  55806. {
  55807. jassert (componentToDrag->isValidComponent());
  55808. if (componentToDrag != 0)
  55809. {
  55810. constrainer = constrainer_;
  55811. originalPos = componentToDrag->relativePositionToGlobal (Point<int>());
  55812. }
  55813. }
  55814. void ComponentDragger::dragComponent (Component* const componentToDrag, const MouseEvent& e)
  55815. {
  55816. jassert (componentToDrag->isValidComponent());
  55817. jassert (e.mods.isAnyMouseButtonDown()); // (the event has to be a drag event..)
  55818. if (componentToDrag != 0)
  55819. {
  55820. Rectangle<int> bounds (componentToDrag->getBounds().withPosition (originalPos));
  55821. const Component* const parentComp = componentToDrag->getParentComponent();
  55822. if (parentComp != 0)
  55823. bounds.setPosition (parentComp->globalPositionToRelative (originalPos));
  55824. bounds.setPosition (bounds.getPosition() + e.getOffsetFromDragStart());
  55825. if (constrainer != 0)
  55826. constrainer->setBoundsForComponent (componentToDrag, bounds, false, false, false, false);
  55827. else
  55828. componentToDrag->setBounds (bounds);
  55829. }
  55830. }
  55831. END_JUCE_NAMESPACE
  55832. /*** End of inlined file: juce_ComponentDragger.cpp ***/
  55833. /*** Start of inlined file: juce_DragAndDropContainer.cpp ***/
  55834. BEGIN_JUCE_NAMESPACE
  55835. bool juce_performDragDropFiles (const StringArray& files, const bool copyFiles, bool& shouldStop);
  55836. bool juce_performDragDropText (const String& text, bool& shouldStop);
  55837. class DragImageComponent : public Component,
  55838. public Timer
  55839. {
  55840. public:
  55841. DragImageComponent (Image* const im,
  55842. const String& desc,
  55843. Component* const sourceComponent,
  55844. Component* const mouseDragSource_,
  55845. DragAndDropContainer* const o,
  55846. const Point<int>& imageOffset_)
  55847. : image (im),
  55848. source (sourceComponent),
  55849. mouseDragSource (mouseDragSource_),
  55850. owner (o),
  55851. dragDesc (desc),
  55852. imageOffset (imageOffset_),
  55853. hasCheckedForExternalDrag (false),
  55854. drawImage (true)
  55855. {
  55856. setSize (im->getWidth(), im->getHeight());
  55857. if (mouseDragSource == 0)
  55858. mouseDragSource = source;
  55859. mouseDragSource->addMouseListener (this, false);
  55860. startTimer (200);
  55861. setInterceptsMouseClicks (false, false);
  55862. setAlwaysOnTop (true);
  55863. }
  55864. ~DragImageComponent()
  55865. {
  55866. if (owner->dragImageComponent == this)
  55867. owner->dragImageComponent.release();
  55868. if (mouseDragSource != 0)
  55869. {
  55870. mouseDragSource->removeMouseListener (this);
  55871. if (getCurrentlyOver() != 0 && getCurrentlyOver()->isInterestedInDragSource (dragDesc, source))
  55872. getCurrentlyOver()->itemDragExit (dragDesc, source);
  55873. }
  55874. }
  55875. void paint (Graphics& g)
  55876. {
  55877. if (isOpaque())
  55878. g.fillAll (Colours::white);
  55879. if (drawImage)
  55880. {
  55881. g.setOpacity (1.0f);
  55882. g.drawImageAt (image, 0, 0);
  55883. }
  55884. }
  55885. DragAndDropTarget* findTarget (const Point<int>& screenPos, Point<int>& relativePos)
  55886. {
  55887. Component* hit = getParentComponent();
  55888. if (hit == 0)
  55889. {
  55890. hit = Desktop::getInstance().findComponentAt (screenPos);
  55891. }
  55892. else
  55893. {
  55894. const Point<int> relPos (hit->globalPositionToRelative (screenPos));
  55895. hit = hit->getComponentAt (relPos.getX(), relPos.getY());
  55896. }
  55897. // (note: use a local copy of the dragDesc member in case the callback runs
  55898. // a modal loop and deletes this object before the method completes)
  55899. const String dragDescLocal (dragDesc);
  55900. while (hit != 0)
  55901. {
  55902. DragAndDropTarget* const ddt = dynamic_cast <DragAndDropTarget*> (hit);
  55903. if (ddt != 0 && ddt->isInterestedInDragSource (dragDescLocal, source))
  55904. {
  55905. relativePos = hit->globalPositionToRelative (screenPos);
  55906. return ddt;
  55907. }
  55908. hit = hit->getParentComponent();
  55909. }
  55910. return 0;
  55911. }
  55912. void mouseUp (const MouseEvent& e)
  55913. {
  55914. if (e.originalComponent != this)
  55915. {
  55916. if (mouseDragSource != 0)
  55917. mouseDragSource->removeMouseListener (this);
  55918. bool dropAccepted = false;
  55919. DragAndDropTarget* ddt = 0;
  55920. Point<int> relPos;
  55921. if (isVisible())
  55922. {
  55923. setVisible (false);
  55924. ddt = findTarget (e.getScreenPosition(), relPos);
  55925. // fade this component and remove it - it'll be deleted later by the timer callback
  55926. dropAccepted = ddt != 0;
  55927. setVisible (true);
  55928. if (dropAccepted || source == 0)
  55929. {
  55930. fadeOutComponent (120);
  55931. }
  55932. else
  55933. {
  55934. const Point<int> target (source->relativePositionToGlobal (Point<int> (source->getWidth() / 2,
  55935. source->getHeight() / 2)));
  55936. const Point<int> ourCentre (relativePositionToGlobal (Point<int> (getWidth() / 2,
  55937. getHeight() / 2)));
  55938. fadeOutComponent (120,
  55939. target.getX() - ourCentre.getX(),
  55940. target.getY() - ourCentre.getY());
  55941. }
  55942. }
  55943. if (getParentComponent() != 0)
  55944. getParentComponent()->removeChildComponent (this);
  55945. if (dropAccepted && ddt != 0)
  55946. {
  55947. // (note: use a local copy of the dragDesc member in case the callback runs
  55948. // a modal loop and deletes this object before the method completes)
  55949. const String dragDescLocal (dragDesc);
  55950. currentlyOverComp = 0;
  55951. ddt->itemDropped (dragDescLocal, source, relPos.getX(), relPos.getY());
  55952. }
  55953. // careful - this object could now be deleted..
  55954. }
  55955. }
  55956. void updateLocation (const bool canDoExternalDrag, const Point<int>& screenPos)
  55957. {
  55958. // (note: use a local copy of the dragDesc member in case the callback runs
  55959. // a modal loop and deletes this object before it returns)
  55960. const String dragDescLocal (dragDesc);
  55961. Point<int> newPos (screenPos + imageOffset);
  55962. if (getParentComponent() != 0)
  55963. newPos = getParentComponent()->globalPositionToRelative (newPos);
  55964. //if (newX != getX() || newY != getY())
  55965. {
  55966. setTopLeftPosition (newPos.getX(), newPos.getY());
  55967. Point<int> relPos;
  55968. DragAndDropTarget* const ddt = findTarget (screenPos, relPos);
  55969. Component* ddtComp = dynamic_cast <Component*> (ddt);
  55970. drawImage = (ddt == 0) || ddt->shouldDrawDragImageWhenOver();
  55971. if (ddtComp != currentlyOverComp)
  55972. {
  55973. if (currentlyOverComp != 0 && source != 0
  55974. && getCurrentlyOver()->isInterestedInDragSource (dragDescLocal, source))
  55975. {
  55976. getCurrentlyOver()->itemDragExit (dragDescLocal, source);
  55977. }
  55978. currentlyOverComp = ddtComp;
  55979. if (ddt != 0 && ddt->isInterestedInDragSource (dragDescLocal, source))
  55980. ddt->itemDragEnter (dragDescLocal, source, relPos.getX(), relPos.getY());
  55981. }
  55982. if (getCurrentlyOver() != 0 && getCurrentlyOver()->isInterestedInDragSource (dragDescLocal, source))
  55983. getCurrentlyOver()->itemDragMove (dragDescLocal, source, relPos.getX(), relPos.getY());
  55984. if (getCurrentlyOver() == 0
  55985. && canDoExternalDrag
  55986. && ! hasCheckedForExternalDrag)
  55987. {
  55988. if (Desktop::getInstance().findComponentAt (screenPos) == 0)
  55989. {
  55990. hasCheckedForExternalDrag = true;
  55991. StringArray files;
  55992. bool canMoveFiles = false;
  55993. if (owner->shouldDropFilesWhenDraggedExternally (dragDescLocal, source, files, canMoveFiles)
  55994. && files.size() > 0)
  55995. {
  55996. Component::SafePointer<Component> cdw (this);
  55997. setVisible (false);
  55998. if (ModifierKeys::getCurrentModifiersRealtime().isAnyMouseButtonDown())
  55999. DragAndDropContainer::performExternalDragDropOfFiles (files, canMoveFiles);
  56000. if (cdw != 0)
  56001. delete this;
  56002. return;
  56003. }
  56004. }
  56005. }
  56006. }
  56007. }
  56008. void mouseDrag (const MouseEvent& e)
  56009. {
  56010. if (e.originalComponent != this)
  56011. updateLocation (true, e.getScreenPosition());
  56012. }
  56013. void timerCallback()
  56014. {
  56015. if (source == 0)
  56016. {
  56017. delete this;
  56018. }
  56019. else if (! isMouseButtonDownAnywhere())
  56020. {
  56021. if (mouseDragSource != 0)
  56022. mouseDragSource->removeMouseListener (this);
  56023. delete this;
  56024. }
  56025. }
  56026. private:
  56027. ScopedPointer<Image> image;
  56028. Component::SafePointer<Component> source;
  56029. Component::SafePointer<Component> mouseDragSource;
  56030. DragAndDropContainer* const owner;
  56031. Component::SafePointer<Component> currentlyOverComp;
  56032. DragAndDropTarget* getCurrentlyOver()
  56033. {
  56034. return dynamic_cast <DragAndDropTarget*> (static_cast <Component*> (currentlyOverComp));
  56035. }
  56036. String dragDesc;
  56037. const Point<int> imageOffset;
  56038. bool hasCheckedForExternalDrag, drawImage;
  56039. DragImageComponent (const DragImageComponent&);
  56040. DragImageComponent& operator= (const DragImageComponent&);
  56041. };
  56042. DragAndDropContainer::DragAndDropContainer()
  56043. {
  56044. }
  56045. DragAndDropContainer::~DragAndDropContainer()
  56046. {
  56047. dragImageComponent = 0;
  56048. }
  56049. void DragAndDropContainer::startDragging (const String& sourceDescription,
  56050. Component* sourceComponent,
  56051. Image* dragImage_,
  56052. const bool allowDraggingToExternalWindows,
  56053. const Point<int>* imageOffsetFromMouse)
  56054. {
  56055. ScopedPointer <Image> dragImage (dragImage_);
  56056. if (dragImageComponent == 0)
  56057. {
  56058. Component* const thisComp = dynamic_cast <Component*> (this);
  56059. if (thisComp == 0)
  56060. {
  56061. jassertfalse; // Your DragAndDropContainer needs to be a Component!
  56062. return;
  56063. }
  56064. MouseInputSource* draggingSource = Desktop::getInstance().getDraggingMouseSource (0);
  56065. if (draggingSource == 0 || ! draggingSource->isDragging())
  56066. {
  56067. jassertfalse; // You must call startDragging() from within a mouseDown or mouseDrag callback!
  56068. return;
  56069. }
  56070. const Point<int> lastMouseDown (Desktop::getLastMouseDownPosition());
  56071. Point<int> imageOffset;
  56072. if (dragImage == 0)
  56073. {
  56074. dragImage = sourceComponent->createComponentSnapshot (Rectangle<int> (0, 0, sourceComponent->getWidth(), sourceComponent->getHeight()));
  56075. if (dragImage->getFormat() != Image::ARGB)
  56076. {
  56077. Image* newIm = Image::createNativeImage (Image::ARGB, dragImage->getWidth(), dragImage->getHeight(), true);
  56078. Graphics g2 (*newIm);
  56079. g2.drawImageAt (dragImage, 0, 0);
  56080. dragImage = newIm;
  56081. }
  56082. dragImage->multiplyAllAlphas (0.6f);
  56083. const int lo = 150;
  56084. const int hi = 400;
  56085. Point<int> relPos (sourceComponent->globalPositionToRelative (lastMouseDown));
  56086. Point<int> clipped (Rectangle<int> (0, 0, dragImage->getWidth(), dragImage->getHeight())
  56087. .getConstrainedPoint (relPos));
  56088. for (int y = dragImage->getHeight(); --y >= 0;)
  56089. {
  56090. const double dy = (y - clipped.getY()) * (y - clipped.getY());
  56091. for (int x = dragImage->getWidth(); --x >= 0;)
  56092. {
  56093. const int dx = x - clipped.getX();
  56094. const int distance = roundToInt (sqrt (dx * dx + dy));
  56095. if (distance > lo)
  56096. {
  56097. const float alpha = (distance > hi) ? 0
  56098. : (hi - distance) / (float) (hi - lo)
  56099. + Random::getSystemRandom().nextFloat() * 0.008f;
  56100. dragImage->multiplyAlphaAt (x, y, alpha);
  56101. }
  56102. }
  56103. }
  56104. imageOffset = -clipped;
  56105. }
  56106. else
  56107. {
  56108. if (imageOffsetFromMouse == 0)
  56109. imageOffset = Point<int> (dragImage->getWidth() / -2,
  56110. dragImage->getHeight() / -2);
  56111. else
  56112. imageOffset = *imageOffsetFromMouse;
  56113. }
  56114. dragImageComponent = new DragImageComponent (dragImage.release(), sourceDescription, sourceComponent,
  56115. draggingSource->getComponentUnderMouse(), this, imageOffset);
  56116. currentDragDesc = sourceDescription;
  56117. if (allowDraggingToExternalWindows)
  56118. {
  56119. if (! Desktop::canUseSemiTransparentWindows())
  56120. dragImageComponent->setOpaque (true);
  56121. dragImageComponent->addToDesktop (ComponentPeer::windowIgnoresMouseClicks
  56122. | ComponentPeer::windowIsTemporary
  56123. | ComponentPeer::windowIgnoresKeyPresses);
  56124. }
  56125. else
  56126. thisComp->addChildComponent (dragImageComponent);
  56127. static_cast <DragImageComponent*> (static_cast <Component*> (dragImageComponent))->updateLocation (false, lastMouseDown);
  56128. dragImageComponent->setVisible (true);
  56129. }
  56130. }
  56131. bool DragAndDropContainer::isDragAndDropActive() const
  56132. {
  56133. return dragImageComponent != 0;
  56134. }
  56135. const String DragAndDropContainer::getCurrentDragDescription() const
  56136. {
  56137. return (dragImageComponent != 0) ? currentDragDesc
  56138. : String::empty;
  56139. }
  56140. DragAndDropContainer* DragAndDropContainer::findParentDragContainerFor (Component* c)
  56141. {
  56142. if (c == 0)
  56143. return 0;
  56144. // (unable to use the syntax findParentComponentOfClass <DragAndDropContainer> () because of a VC6 compiler bug)
  56145. return c->findParentComponentOfClass ((DragAndDropContainer*) 0);
  56146. }
  56147. bool DragAndDropContainer::shouldDropFilesWhenDraggedExternally (const String&, Component*, StringArray&, bool&)
  56148. {
  56149. return false;
  56150. }
  56151. void DragAndDropTarget::itemDragEnter (const String&, Component*, int, int)
  56152. {
  56153. }
  56154. void DragAndDropTarget::itemDragMove (const String&, Component*, int, int)
  56155. {
  56156. }
  56157. void DragAndDropTarget::itemDragExit (const String&, Component*)
  56158. {
  56159. }
  56160. bool DragAndDropTarget::shouldDrawDragImageWhenOver()
  56161. {
  56162. return true;
  56163. }
  56164. void FileDragAndDropTarget::fileDragEnter (const StringArray&, int, int)
  56165. {
  56166. }
  56167. void FileDragAndDropTarget::fileDragMove (const StringArray&, int, int)
  56168. {
  56169. }
  56170. void FileDragAndDropTarget::fileDragExit (const StringArray&)
  56171. {
  56172. }
  56173. END_JUCE_NAMESPACE
  56174. /*** End of inlined file: juce_DragAndDropContainer.cpp ***/
  56175. /*** Start of inlined file: juce_MouseCursor.cpp ***/
  56176. BEGIN_JUCE_NAMESPACE
  56177. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw();
  56178. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw();
  56179. // isStandard set depending on which interface was used to create the cursor
  56180. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw();
  56181. static CriticalSection activeCursorListLock;
  56182. static VoidArray activeCursors;
  56183. class SharedMouseCursorInternal : public ReferenceCountedObject
  56184. {
  56185. public:
  56186. SharedMouseCursorInternal (const MouseCursor::StandardCursorType type) throw()
  56187. : standardType (type),
  56188. isStandard (true)
  56189. {
  56190. handle = juce_createStandardMouseCursor (standardType);
  56191. activeCursors.add (this);
  56192. }
  56193. SharedMouseCursorInternal (const Image& image, const int hotSpotX, const int hotSpotY) throw()
  56194. : standardType (MouseCursor::NormalCursor),
  56195. isStandard (false)
  56196. {
  56197. handle = juce_createMouseCursorFromImage (image, hotSpotX, hotSpotY);
  56198. }
  56199. ~SharedMouseCursorInternal() throw()
  56200. {
  56201. juce_deleteMouseCursor (handle, isStandard);
  56202. activeCursors.removeValue (this);
  56203. }
  56204. void* getHandle() const throw()
  56205. {
  56206. return handle;
  56207. }
  56208. static SharedMouseCursorInternal* findInstance (MouseCursor::StandardCursorType type) throw()
  56209. {
  56210. for (int i = activeCursors.size(); --i >= 0;)
  56211. {
  56212. SharedMouseCursorInternal* const r = (SharedMouseCursorInternal*) activeCursors.getUnchecked(i);
  56213. if (r->standardType == type)
  56214. return r;
  56215. }
  56216. return new SharedMouseCursorInternal (type);
  56217. }
  56218. juce_UseDebuggingNewOperator
  56219. private:
  56220. void* handle;
  56221. const MouseCursor::StandardCursorType standardType;
  56222. const bool isStandard;
  56223. SharedMouseCursorInternal& operator= (const SharedMouseCursorInternal&);
  56224. };
  56225. MouseCursor::MouseCursor() throw()
  56226. {
  56227. const ScopedLock sl (activeCursorListLock);
  56228. cursorHandle = SharedMouseCursorInternal::findInstance (NormalCursor);
  56229. }
  56230. MouseCursor::MouseCursor (const StandardCursorType type) throw()
  56231. {
  56232. const ScopedLock sl (activeCursorListLock);
  56233. cursorHandle = SharedMouseCursorInternal::findInstance (type);
  56234. }
  56235. MouseCursor::MouseCursor (const Image& image, const int hotSpotX, const int hotSpotY) throw()
  56236. {
  56237. const ScopedLock sl (activeCursorListLock);
  56238. cursorHandle = new SharedMouseCursorInternal (image, hotSpotX, hotSpotY);
  56239. }
  56240. MouseCursor::MouseCursor (const MouseCursor& other) throw()
  56241. : cursorHandle (other.cursorHandle)
  56242. {
  56243. }
  56244. MouseCursor::~MouseCursor() throw()
  56245. {
  56246. }
  56247. MouseCursor& MouseCursor::operator= (const MouseCursor& other) throw()
  56248. {
  56249. cursorHandle = other.cursorHandle;
  56250. return *this;
  56251. }
  56252. bool MouseCursor::operator== (const MouseCursor& other) const throw()
  56253. {
  56254. return cursorHandle == other.cursorHandle;
  56255. }
  56256. bool MouseCursor::operator!= (const MouseCursor& other) const throw()
  56257. {
  56258. return cursorHandle != other.cursorHandle;
  56259. }
  56260. void* MouseCursor::getHandle() const throw()
  56261. {
  56262. return cursorHandle->getHandle();
  56263. }
  56264. void MouseCursor::showWaitCursor() throw()
  56265. {
  56266. Desktop::getInstance().getMainMouseSource().showMouseCursor (MouseCursor::WaitCursor);
  56267. }
  56268. void MouseCursor::hideWaitCursor() throw()
  56269. {
  56270. Desktop::getInstance().getMainMouseSource().revealCursor();
  56271. }
  56272. END_JUCE_NAMESPACE
  56273. /*** End of inlined file: juce_MouseCursor.cpp ***/
  56274. /*** Start of inlined file: juce_MouseEvent.cpp ***/
  56275. BEGIN_JUCE_NAMESPACE
  56276. MouseEvent::MouseEvent (MouseInputSource& source_,
  56277. const Point<int>& position,
  56278. const ModifierKeys& mods_,
  56279. Component* const originator,
  56280. const Time& eventTime_,
  56281. const Point<int> mouseDownPos_,
  56282. const Time& mouseDownTime_,
  56283. const int numberOfClicks_,
  56284. const bool mouseWasDragged) throw()
  56285. : x (position.getX()),
  56286. y (position.getY()),
  56287. mods (mods_),
  56288. eventComponent (originator),
  56289. originalComponent (originator),
  56290. eventTime (eventTime_),
  56291. source (source_),
  56292. mouseDownPos (mouseDownPos_),
  56293. mouseDownTime (mouseDownTime_),
  56294. numberOfClicks (numberOfClicks_),
  56295. wasMovedSinceMouseDown (mouseWasDragged)
  56296. {
  56297. }
  56298. MouseEvent::~MouseEvent() throw()
  56299. {
  56300. }
  56301. const MouseEvent MouseEvent::getEventRelativeTo (Component* const otherComponent) const throw()
  56302. {
  56303. if (otherComponent == 0)
  56304. {
  56305. jassertfalse
  56306. return *this;
  56307. }
  56308. return MouseEvent (source, eventComponent->relativePositionToOtherComponent (otherComponent, getPosition()),
  56309. mods, originalComponent, eventTime,
  56310. eventComponent->relativePositionToOtherComponent (otherComponent, mouseDownPos),
  56311. mouseDownTime, numberOfClicks, wasMovedSinceMouseDown);
  56312. }
  56313. const MouseEvent MouseEvent::withNewPosition (const Point<int>& newPosition) const throw()
  56314. {
  56315. return MouseEvent (source, newPosition, mods, originalComponent,
  56316. eventTime, mouseDownPos, mouseDownTime,
  56317. numberOfClicks, wasMovedSinceMouseDown);
  56318. }
  56319. bool MouseEvent::mouseWasClicked() const throw()
  56320. {
  56321. return ! wasMovedSinceMouseDown;
  56322. }
  56323. int MouseEvent::getMouseDownX() const throw()
  56324. {
  56325. return mouseDownPos.getX();
  56326. }
  56327. int MouseEvent::getMouseDownY() const throw()
  56328. {
  56329. return mouseDownPos.getY();
  56330. }
  56331. const Point<int> MouseEvent::getMouseDownPosition() const throw()
  56332. {
  56333. return mouseDownPos;
  56334. }
  56335. int MouseEvent::getDistanceFromDragStartX() const throw()
  56336. {
  56337. return x - mouseDownPos.getX();
  56338. }
  56339. int MouseEvent::getDistanceFromDragStartY() const throw()
  56340. {
  56341. return y - mouseDownPos.getY();
  56342. }
  56343. int MouseEvent::getDistanceFromDragStart() const throw()
  56344. {
  56345. return mouseDownPos.getDistanceFrom (getPosition());
  56346. }
  56347. const Point<int> MouseEvent::getOffsetFromDragStart() const throw()
  56348. {
  56349. return getPosition() - mouseDownPos;
  56350. }
  56351. int MouseEvent::getLengthOfMousePress() const throw()
  56352. {
  56353. if (mouseDownTime.toMilliseconds() > 0)
  56354. return jmax (0, (int) (eventTime - mouseDownTime).inMilliseconds());
  56355. return 0;
  56356. }
  56357. const Point<int> MouseEvent::getPosition() const throw()
  56358. {
  56359. return Point<int> (x, y);
  56360. }
  56361. int MouseEvent::getScreenX() const
  56362. {
  56363. return getScreenPosition().getX();
  56364. }
  56365. int MouseEvent::getScreenY() const
  56366. {
  56367. return getScreenPosition().getY();
  56368. }
  56369. const Point<int> MouseEvent::getScreenPosition() const
  56370. {
  56371. return eventComponent->relativePositionToGlobal (Point<int> (x, y));
  56372. }
  56373. int MouseEvent::getMouseDownScreenX() const
  56374. {
  56375. return getMouseDownScreenPosition().getX();
  56376. }
  56377. int MouseEvent::getMouseDownScreenY() const
  56378. {
  56379. return getMouseDownScreenPosition().getY();
  56380. }
  56381. const Point<int> MouseEvent::getMouseDownScreenPosition() const
  56382. {
  56383. return eventComponent->relativePositionToGlobal (mouseDownPos);
  56384. }
  56385. static int doubleClickTimeOutMs = 400;
  56386. void MouseEvent::setDoubleClickTimeout (const int newTime) throw()
  56387. {
  56388. doubleClickTimeOutMs = newTime;
  56389. }
  56390. int MouseEvent::getDoubleClickTimeout() throw()
  56391. {
  56392. return doubleClickTimeOutMs;
  56393. }
  56394. END_JUCE_NAMESPACE
  56395. /*** End of inlined file: juce_MouseEvent.cpp ***/
  56396. /*** Start of inlined file: juce_MouseInputSource.cpp ***/
  56397. BEGIN_JUCE_NAMESPACE
  56398. class MouseInputSourceInternal : public AsyncUpdater
  56399. {
  56400. public:
  56401. MouseInputSourceInternal (MouseInputSource& source_, const int index_, const bool isMouseDevice_)
  56402. : index (index_), isMouseDevice (isMouseDevice_), source (source_), lastPeer (0), lastTime (0),
  56403. isUnboundedMouseModeOn (false), isCursorVisibleUntilOffscreen (false), currentCursorHandle (0)
  56404. {
  56405. zerostruct (mouseDowns);
  56406. }
  56407. ~MouseInputSourceInternal()
  56408. {
  56409. }
  56410. bool isDragging() const throw()
  56411. {
  56412. return buttonState.isAnyMouseButtonDown();
  56413. }
  56414. Component* getComponentUnderMouse() const
  56415. {
  56416. return static_cast <Component*> (componentUnderMouse);
  56417. }
  56418. const ModifierKeys getCurrentModifiers() const
  56419. {
  56420. return ModifierKeys::getCurrentModifiers().withoutMouseButtons().withFlags (buttonState.getRawFlags());
  56421. }
  56422. ComponentPeer* getPeer()
  56423. {
  56424. if (! ComponentPeer::isValidPeer (lastPeer))
  56425. lastPeer = 0;
  56426. return lastPeer;
  56427. }
  56428. Component* findComponentAt (const Point<int>& screenPos)
  56429. {
  56430. ComponentPeer* const peer = getPeer();
  56431. if (peer != 0)
  56432. {
  56433. Component* const comp = peer->getComponent();
  56434. const Point<int> relativePos (comp->globalPositionToRelative (screenPos));
  56435. // (the contains() call is needed to test for overlapping desktop windows)
  56436. if (comp->contains (relativePos.getX(), relativePos.getY()))
  56437. return comp->getComponentAt (relativePos);
  56438. }
  56439. return 0;
  56440. }
  56441. const Point<int> getScreenPosition() const throw()
  56442. {
  56443. return lastScreenPos + unboundedMouseOffset;
  56444. }
  56445. void sendMouseEnter (Component* const comp, const Point<int>& screenPos, const int64 time)
  56446. {
  56447. //DBG ("Mouse " + String (source.getIndex()) + " enter: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56448. comp->internalMouseEnter (source, comp->globalPositionToRelative (screenPos), time);
  56449. }
  56450. void sendMouseExit (Component* const comp, const Point<int>& screenPos, const int64 time)
  56451. {
  56452. //DBG ("Mouse " + String (source.getIndex()) + " exit: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56453. comp->internalMouseExit (source, comp->globalPositionToRelative (screenPos), time);
  56454. }
  56455. void sendMouseMove (Component* const comp, const Point<int>& screenPos, const int64 time)
  56456. {
  56457. //DBG ("Mouse " + String (source.getIndex()) + " move: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56458. comp->internalMouseMove (source, comp->globalPositionToRelative (screenPos), time);
  56459. }
  56460. void sendMouseDown (Component* const comp, const Point<int>& screenPos, const int64 time)
  56461. {
  56462. //DBG ("Mouse " + String (source.getIndex()) + " down: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56463. comp->internalMouseDown (source, comp->globalPositionToRelative (screenPos), time);
  56464. }
  56465. void sendMouseDrag (Component* const comp, const Point<int>& screenPos, const int64 time)
  56466. {
  56467. //DBG ("Mouse " + String (source.getIndex()) + " drag: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56468. comp->internalMouseDrag (source, comp->globalPositionToRelative (screenPos), time);
  56469. }
  56470. void sendMouseUp (Component* const comp, const Point<int>& screenPos, const int64 time)
  56471. {
  56472. //DBG ("Mouse " + String (source.getIndex()) + " up: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56473. comp->internalMouseUp (source, comp->globalPositionToRelative (screenPos), time, getCurrentModifiers());
  56474. }
  56475. void sendMouseWheel (Component* const comp, const Point<int>& screenPos, const int64 time, float x, float y)
  56476. {
  56477. //DBG ("Mouse " + String (source.getIndex()) + " wheel: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56478. comp->internalMouseWheel (source, comp->globalPositionToRelative (screenPos), time, x, y);
  56479. }
  56480. void setButtons (const Point<int>& screenPos, const int64 time, const ModifierKeys& newButtonState)
  56481. {
  56482. if (buttonState != newButtonState)
  56483. {
  56484. // (ignore secondary clicks when there's already a button down)
  56485. if (buttonState.isAnyMouseButtonDown() == newButtonState.isAnyMouseButtonDown())
  56486. {
  56487. buttonState = newButtonState;
  56488. return;
  56489. }
  56490. if (buttonState.isAnyMouseButtonDown())
  56491. {
  56492. Component* const current = getComponentUnderMouse();
  56493. if (current != 0)
  56494. sendMouseUp (current, screenPos + unboundedMouseOffset, time);
  56495. enableUnboundedMouseMovement (false, false);
  56496. }
  56497. buttonState = newButtonState;
  56498. if (buttonState.isAnyMouseButtonDown())
  56499. {
  56500. Desktop::getInstance().incrementMouseClickCounter();
  56501. Component* const current = getComponentUnderMouse();
  56502. if (current != 0)
  56503. {
  56504. registerMouseDown (screenPos, time, current);
  56505. sendMouseDown (current, screenPos, time);
  56506. }
  56507. }
  56508. }
  56509. }
  56510. void setComponentUnderMouse (Component* const newComponent, const Point<int>& screenPos, const int64 time)
  56511. {
  56512. Component* current = getComponentUnderMouse();
  56513. if (newComponent != current)
  56514. {
  56515. Component::SafePointer<Component> safeNewComp (newComponent);
  56516. const ModifierKeys originalButtonState (buttonState);
  56517. if (current != 0)
  56518. {
  56519. setButtons (screenPos, time, ModifierKeys());
  56520. sendMouseExit (current, screenPos, time);
  56521. buttonState = originalButtonState;
  56522. }
  56523. componentUnderMouse = safeNewComp;
  56524. current = getComponentUnderMouse();
  56525. if (current != 0)
  56526. sendMouseEnter (current, screenPos, time);
  56527. revealCursor (false);
  56528. setButtons (screenPos, time, originalButtonState);
  56529. }
  56530. }
  56531. void setPeer (ComponentPeer* const newPeer, const Point<int>& screenPos, const int64 time)
  56532. {
  56533. ModifierKeys::updateCurrentModifiers();
  56534. if (newPeer != lastPeer)
  56535. {
  56536. setComponentUnderMouse (0, screenPos, time);
  56537. lastPeer = newPeer;
  56538. setComponentUnderMouse (findComponentAt (screenPos), screenPos, time);
  56539. }
  56540. }
  56541. void setScreenPos (const Point<int>& newScreenPos, const int64 time, const bool forceUpdate)
  56542. {
  56543. if (! isDragging())
  56544. setComponentUnderMouse (findComponentAt (newScreenPos), newScreenPos, time);
  56545. if (newScreenPos != lastScreenPos || forceUpdate)
  56546. {
  56547. cancelPendingUpdate();
  56548. lastScreenPos = newScreenPos;
  56549. Component* const current = getComponentUnderMouse();
  56550. if (current != 0)
  56551. {
  56552. if (isDragging())
  56553. {
  56554. registerMouseDrag (newScreenPos);
  56555. sendMouseDrag (current, newScreenPos + unboundedMouseOffset, time);
  56556. if (isUnboundedMouseModeOn)
  56557. handleUnboundedDrag (current);
  56558. }
  56559. else
  56560. {
  56561. sendMouseMove (current, newScreenPos, time);
  56562. }
  56563. }
  56564. revealCursor (false);
  56565. }
  56566. }
  56567. void handleEvent (ComponentPeer* const newPeer, const Point<int>& positionWithinPeer, const int64 time, const ModifierKeys& newMods)
  56568. {
  56569. jassert (newPeer != 0);
  56570. lastTime = time;
  56571. const Point<int> screenPos (newPeer->relativePositionToGlobal (positionWithinPeer));
  56572. if (isDragging() && newMods.isAnyMouseButtonDown())
  56573. {
  56574. setScreenPos (screenPos, time, false);
  56575. }
  56576. else
  56577. {
  56578. setPeer (newPeer, screenPos, time);
  56579. ComponentPeer* peer = getPeer();
  56580. if (peer != 0)
  56581. {
  56582. setButtons (screenPos, time, newMods);
  56583. peer = getPeer();
  56584. if (peer != 0)
  56585. setScreenPos (peer->relativePositionToGlobal (positionWithinPeer), time, false);
  56586. }
  56587. }
  56588. }
  56589. void handleWheel (ComponentPeer* const peer, const Point<int>& positionWithinPeer, int64 time, float x, float y)
  56590. {
  56591. jassert (peer != 0);
  56592. lastTime = time;
  56593. const Point<int> screenPos (peer->relativePositionToGlobal (positionWithinPeer));
  56594. setPeer (peer, screenPos, time);
  56595. setScreenPos (screenPos, time, false);
  56596. triggerFakeMove();
  56597. if (! isDragging())
  56598. {
  56599. Component* current = getComponentUnderMouse();
  56600. if (current != 0)
  56601. sendMouseWheel (current, screenPos, time, x, y);
  56602. }
  56603. }
  56604. const Time getLastMouseDownTime() const throw()
  56605. {
  56606. return Time (mouseDowns[0].time);
  56607. }
  56608. const Point<int> getLastMouseDownPosition() const throw()
  56609. {
  56610. return mouseDowns[0].position;
  56611. }
  56612. int getNumberOfMultipleClicks() const throw()
  56613. {
  56614. int numClicks = 0;
  56615. if (mouseDowns[0].time != 0)
  56616. {
  56617. if (! mouseMovedSignificantlySincePressed)
  56618. ++numClicks;
  56619. for (int i = 1; i < numElementsInArray (mouseDowns); ++i)
  56620. {
  56621. if (mouseDowns[0].time - mouseDowns[i].time < (int) (MouseEvent::getDoubleClickTimeout() * (1.0 + 0.25 * (i - 1)))
  56622. && abs (mouseDowns[0].position.getX() - mouseDowns[i].position.getX()) < 8
  56623. && abs (mouseDowns[0].position.getY() - mouseDowns[i].position.getY()) < 8
  56624. && mouseDowns[0].component == mouseDowns[i].component)
  56625. {
  56626. ++numClicks;
  56627. }
  56628. else
  56629. {
  56630. break;
  56631. }
  56632. }
  56633. }
  56634. return numClicks;
  56635. }
  56636. bool hasMouseMovedSignificantlySincePressed() const throw()
  56637. {
  56638. return mouseMovedSignificantlySincePressed
  56639. || lastTime > mouseDowns[0].time + 300;
  56640. }
  56641. void triggerFakeMove()
  56642. {
  56643. triggerAsyncUpdate();
  56644. }
  56645. void handleAsyncUpdate()
  56646. {
  56647. if (! isDragging())
  56648. setScreenPos (Desktop::getMousePosition(), jmax (lastTime, Time::currentTimeMillis()), true);
  56649. }
  56650. void enableUnboundedMouseMovement (bool enable, bool keepCursorVisibleUntilOffscreen)
  56651. {
  56652. enable = enable && isDragging();
  56653. isCursorVisibleUntilOffscreen = keepCursorVisibleUntilOffscreen;
  56654. if (enable != isUnboundedMouseModeOn)
  56655. {
  56656. if ((! enable) && ((! isCursorVisibleUntilOffscreen) || ! unboundedMouseOffset.isOrigin()))
  56657. {
  56658. // when released, return the mouse to within the component's bounds
  56659. Component* current = getComponentUnderMouse();
  56660. if (current != 0)
  56661. Desktop::setMousePosition (current->getScreenBounds()
  56662. .getConstrainedPoint (current->getMouseXYRelative()));
  56663. }
  56664. isUnboundedMouseModeOn = enable;
  56665. unboundedMouseOffset = Point<int>();
  56666. revealCursor (true);
  56667. }
  56668. }
  56669. void handleUnboundedDrag (Component* current)
  56670. {
  56671. const Rectangle<int> screenArea (current->getParentMonitorArea().expanded (-2, -2));
  56672. if (! screenArea.contains (lastScreenPos))
  56673. {
  56674. const Point<int> compPos (current->getScreenPosition());
  56675. int deltaX = 0, deltaY = 0;
  56676. if (lastScreenPos.getX() <= screenArea.getX() || lastScreenPos.getX() >= screenArea.getRight())
  56677. deltaX = compPos.getX() + current->getWidth() / 2 - lastScreenPos.getX();
  56678. if (lastScreenPos.getY() <= screenArea.getY() || lastScreenPos.getY() >= screenArea.getBottom())
  56679. deltaY = compPos.getY() + current->getHeight() / 2 - lastScreenPos.getY();
  56680. const Point<int> delta (deltaX, deltaY);
  56681. unboundedMouseOffset -= delta;
  56682. Desktop::setMousePosition (lastScreenPos + delta);
  56683. }
  56684. else if (isCursorVisibleUntilOffscreen
  56685. && (! unboundedMouseOffset.isOrigin())
  56686. && screenArea.contains (lastScreenPos + unboundedMouseOffset))
  56687. {
  56688. Desktop::setMousePosition (lastScreenPos + unboundedMouseOffset);
  56689. unboundedMouseOffset = Point<int>();
  56690. }
  56691. }
  56692. void showMouseCursor (MouseCursor cursor, bool forcedUpdate)
  56693. {
  56694. if (isUnboundedMouseModeOn && ((! unboundedMouseOffset.isOrigin()) || ! isCursorVisibleUntilOffscreen))
  56695. {
  56696. cursor = MouseCursor::NoCursor;
  56697. forcedUpdate = true;
  56698. }
  56699. if (forcedUpdate || cursor.getHandle() != currentCursorHandle)
  56700. {
  56701. currentCursorHandle = cursor.getHandle();
  56702. cursor.showInWindow (lastPeer);
  56703. }
  56704. }
  56705. void hideCursor()
  56706. {
  56707. showMouseCursor (MouseCursor::NoCursor, true);
  56708. }
  56709. void revealCursor (bool forcedUpdate)
  56710. {
  56711. MouseCursor mc (MouseCursor::NormalCursor);
  56712. Component* current = getComponentUnderMouse();
  56713. if (current != 0)
  56714. mc = current->getLookAndFeel().getMouseCursorFor (*current);
  56715. showMouseCursor (mc, forcedUpdate);
  56716. }
  56717. int index;
  56718. bool isMouseDevice;
  56719. Point<int> lastScreenPos;
  56720. ModifierKeys buttonState;
  56721. private:
  56722. MouseInputSource& source;
  56723. Component::SafePointer<Component> componentUnderMouse;
  56724. ComponentPeer* lastPeer;
  56725. Point<int> unboundedMouseOffset;
  56726. bool isUnboundedMouseModeOn, isCursorVisibleUntilOffscreen;
  56727. void* currentCursorHandle;
  56728. struct RecentMouseDown
  56729. {
  56730. Point<int> position;
  56731. int64 time;
  56732. Component* component;
  56733. };
  56734. RecentMouseDown mouseDowns[4];
  56735. bool mouseMovedSignificantlySincePressed;
  56736. int64 lastTime;
  56737. void registerMouseDown (const Point<int>& screenPos, const int64 time, Component* const component) throw()
  56738. {
  56739. for (int i = numElementsInArray (mouseDowns); --i > 0;)
  56740. mouseDowns[i] = mouseDowns[i - 1];
  56741. mouseDowns[0].position = screenPos;
  56742. mouseDowns[0].time = time;
  56743. mouseDowns[0].component = component;
  56744. mouseMovedSignificantlySincePressed = false;
  56745. }
  56746. void registerMouseDrag (const Point<int>& screenPos) throw()
  56747. {
  56748. mouseMovedSignificantlySincePressed = mouseMovedSignificantlySincePressed
  56749. || mouseDowns[0].position.getDistanceFrom (screenPos) >= 4;
  56750. }
  56751. };
  56752. MouseInputSource::MouseInputSource (const int index, const bool isMouseDevice)
  56753. {
  56754. pimpl = new MouseInputSourceInternal (*this, index, isMouseDevice);
  56755. }
  56756. MouseInputSource::~MouseInputSource()
  56757. {
  56758. }
  56759. bool MouseInputSource::isMouse() const { return pimpl->isMouseDevice; }
  56760. bool MouseInputSource::isTouch() const { return ! isMouse(); }
  56761. bool MouseInputSource::canHover() const { return isMouse(); }
  56762. bool MouseInputSource::hasMouseWheel() const { return isMouse(); }
  56763. int MouseInputSource::getIndex() const { return pimpl->index; }
  56764. bool MouseInputSource::isDragging() const { return pimpl->isDragging(); }
  56765. const Point<int> MouseInputSource::getScreenPosition() const { return pimpl->getScreenPosition(); }
  56766. const ModifierKeys MouseInputSource::getCurrentModifiers() const { return pimpl->getCurrentModifiers(); }
  56767. Component* MouseInputSource::getComponentUnderMouse() const { return pimpl->getComponentUnderMouse(); }
  56768. void MouseInputSource::triggerFakeMove() const { pimpl->triggerFakeMove(); }
  56769. int MouseInputSource::getNumberOfMultipleClicks() const throw() { return pimpl->getNumberOfMultipleClicks(); }
  56770. const Time MouseInputSource::getLastMouseDownTime() const throw() { return pimpl->getLastMouseDownTime(); }
  56771. const Point<int> MouseInputSource::getLastMouseDownPosition() const throw() { return pimpl->getLastMouseDownPosition(); }
  56772. bool MouseInputSource::hasMouseMovedSignificantlySincePressed() const throw() { return pimpl->hasMouseMovedSignificantlySincePressed(); }
  56773. bool MouseInputSource::canDoUnboundedMovement() const throw() { return isMouse(); }
  56774. void MouseInputSource::enableUnboundedMouseMovement (bool isEnabled, bool keepCursorVisibleUntilOffscreen) { pimpl->enableUnboundedMouseMovement (isEnabled, keepCursorVisibleUntilOffscreen); }
  56775. bool MouseInputSource::hasMouseCursor() const throw() { return isMouse(); }
  56776. void MouseInputSource::showMouseCursor (const MouseCursor& cursor) { pimpl->showMouseCursor (cursor, false); }
  56777. void MouseInputSource::hideCursor() { pimpl->hideCursor(); }
  56778. void MouseInputSource::revealCursor() { pimpl->revealCursor (false); }
  56779. void MouseInputSource::forceMouseCursorUpdate() { pimpl->revealCursor (true); }
  56780. void MouseInputSource::handleEvent (ComponentPeer* peer, const Point<int>& positionWithinPeer, const int64 time, const ModifierKeys& mods)
  56781. {
  56782. pimpl->handleEvent (peer, positionWithinPeer, time, mods.withOnlyMouseButtons());
  56783. }
  56784. void MouseInputSource::handleWheel (ComponentPeer* const peer, const Point<int>& positionWithinPeer, const int64 time, const float x, const float y)
  56785. {
  56786. pimpl->handleWheel (peer, positionWithinPeer, time, x, y);
  56787. }
  56788. END_JUCE_NAMESPACE
  56789. /*** End of inlined file: juce_MouseInputSource.cpp ***/
  56790. /*** Start of inlined file: juce_MouseHoverDetector.cpp ***/
  56791. BEGIN_JUCE_NAMESPACE
  56792. MouseHoverDetector::MouseHoverDetector (const int hoverTimeMillisecs_)
  56793. : source (0),
  56794. hoverTimeMillisecs (hoverTimeMillisecs_),
  56795. hasJustHovered (false)
  56796. {
  56797. internalTimer.owner = this;
  56798. }
  56799. MouseHoverDetector::~MouseHoverDetector()
  56800. {
  56801. setHoverComponent (0);
  56802. }
  56803. void MouseHoverDetector::setHoverTimeMillisecs (const int newTimeInMillisecs)
  56804. {
  56805. hoverTimeMillisecs = newTimeInMillisecs;
  56806. }
  56807. void MouseHoverDetector::setHoverComponent (Component* const newSourceComponent)
  56808. {
  56809. if (source != newSourceComponent)
  56810. {
  56811. internalTimer.stopTimer();
  56812. hasJustHovered = false;
  56813. if (source != 0)
  56814. {
  56815. // ! you need to delete the hover detector before deleting its component
  56816. jassert (source->isValidComponent());
  56817. source->removeMouseListener (&internalTimer);
  56818. }
  56819. source = newSourceComponent;
  56820. if (newSourceComponent != 0)
  56821. newSourceComponent->addMouseListener (&internalTimer, false);
  56822. }
  56823. }
  56824. void MouseHoverDetector::hoverTimerCallback()
  56825. {
  56826. internalTimer.stopTimer();
  56827. if (source != 0)
  56828. {
  56829. const Point<int> pos (source->getMouseXYRelative());
  56830. if (source->reallyContains (pos.getX(), pos.getY(), false))
  56831. {
  56832. hasJustHovered = true;
  56833. mouseHovered (pos.getX(), pos.getY());
  56834. }
  56835. }
  56836. }
  56837. void MouseHoverDetector::checkJustHoveredCallback()
  56838. {
  56839. if (hasJustHovered)
  56840. {
  56841. hasJustHovered = false;
  56842. mouseMovedAfterHover();
  56843. }
  56844. }
  56845. void MouseHoverDetector::HoverDetectorInternal::timerCallback()
  56846. {
  56847. owner->hoverTimerCallback();
  56848. }
  56849. void MouseHoverDetector::HoverDetectorInternal::mouseEnter (const MouseEvent&)
  56850. {
  56851. stopTimer();
  56852. owner->checkJustHoveredCallback();
  56853. }
  56854. void MouseHoverDetector::HoverDetectorInternal::mouseExit (const MouseEvent&)
  56855. {
  56856. stopTimer();
  56857. owner->checkJustHoveredCallback();
  56858. }
  56859. void MouseHoverDetector::HoverDetectorInternal::mouseDown (const MouseEvent&)
  56860. {
  56861. stopTimer();
  56862. owner->checkJustHoveredCallback();
  56863. }
  56864. void MouseHoverDetector::HoverDetectorInternal::mouseUp (const MouseEvent&)
  56865. {
  56866. stopTimer();
  56867. owner->checkJustHoveredCallback();
  56868. }
  56869. void MouseHoverDetector::HoverDetectorInternal::mouseMove (const MouseEvent& e)
  56870. {
  56871. if (lastX != e.x || lastY != e.y) // to avoid fake mouse-moves setting it off
  56872. {
  56873. lastX = e.x;
  56874. lastY = e.y;
  56875. if (owner->source != 0)
  56876. startTimer (owner->hoverTimeMillisecs);
  56877. owner->checkJustHoveredCallback();
  56878. }
  56879. }
  56880. void MouseHoverDetector::HoverDetectorInternal::mouseWheelMove (const MouseEvent&, float, float)
  56881. {
  56882. stopTimer();
  56883. owner->checkJustHoveredCallback();
  56884. }
  56885. END_JUCE_NAMESPACE
  56886. /*** End of inlined file: juce_MouseHoverDetector.cpp ***/
  56887. /*** Start of inlined file: juce_MouseListener.cpp ***/
  56888. BEGIN_JUCE_NAMESPACE
  56889. void MouseListener::mouseEnter (const MouseEvent&)
  56890. {
  56891. }
  56892. void MouseListener::mouseExit (const MouseEvent&)
  56893. {
  56894. }
  56895. void MouseListener::mouseDown (const MouseEvent&)
  56896. {
  56897. }
  56898. void MouseListener::mouseUp (const MouseEvent&)
  56899. {
  56900. }
  56901. void MouseListener::mouseDrag (const MouseEvent&)
  56902. {
  56903. }
  56904. void MouseListener::mouseMove (const MouseEvent&)
  56905. {
  56906. }
  56907. void MouseListener::mouseDoubleClick (const MouseEvent&)
  56908. {
  56909. }
  56910. void MouseListener::mouseWheelMove (const MouseEvent&, float, float)
  56911. {
  56912. }
  56913. END_JUCE_NAMESPACE
  56914. /*** End of inlined file: juce_MouseListener.cpp ***/
  56915. /*** Start of inlined file: juce_BooleanPropertyComponent.cpp ***/
  56916. BEGIN_JUCE_NAMESPACE
  56917. BooleanPropertyComponent::BooleanPropertyComponent (const String& name,
  56918. const String& buttonTextWhenTrue,
  56919. const String& buttonTextWhenFalse)
  56920. : PropertyComponent (name),
  56921. onText (buttonTextWhenTrue),
  56922. offText (buttonTextWhenFalse)
  56923. {
  56924. createButton();
  56925. button->addButtonListener (this);
  56926. }
  56927. BooleanPropertyComponent::BooleanPropertyComponent (const Value& valueToControl,
  56928. const String& name,
  56929. const String& buttonText)
  56930. : PropertyComponent (name),
  56931. onText (buttonText),
  56932. offText (buttonText)
  56933. {
  56934. createButton();
  56935. button->setButtonText (buttonText);
  56936. button->getToggleStateValue().referTo (valueToControl);
  56937. button->setClickingTogglesState (true);
  56938. }
  56939. BooleanPropertyComponent::~BooleanPropertyComponent()
  56940. {
  56941. deleteAllChildren();
  56942. }
  56943. void BooleanPropertyComponent::createButton()
  56944. {
  56945. addAndMakeVisible (button = new ToggleButton (String::empty));
  56946. button->setClickingTogglesState (false);
  56947. }
  56948. void BooleanPropertyComponent::setState (const bool newState)
  56949. {
  56950. button->setToggleState (newState, true);
  56951. }
  56952. bool BooleanPropertyComponent::getState() const
  56953. {
  56954. return button->getToggleState();
  56955. }
  56956. void BooleanPropertyComponent::paint (Graphics& g)
  56957. {
  56958. PropertyComponent::paint (g);
  56959. const Rectangle<int> r (button->getBounds());
  56960. g.setColour (Colours::white);
  56961. g.fillRect (r);
  56962. g.setColour (findColour (ComboBox::outlineColourId));
  56963. g.drawRect (r.getX(), r.getY(), r.getWidth(), r.getHeight());
  56964. }
  56965. void BooleanPropertyComponent::refresh()
  56966. {
  56967. button->setToggleState (getState(), false);
  56968. button->setButtonText (button->getToggleState() ? onText : offText);
  56969. }
  56970. void BooleanPropertyComponent::buttonClicked (Button*)
  56971. {
  56972. setState (! getState());
  56973. }
  56974. END_JUCE_NAMESPACE
  56975. /*** End of inlined file: juce_BooleanPropertyComponent.cpp ***/
  56976. /*** Start of inlined file: juce_ButtonPropertyComponent.cpp ***/
  56977. BEGIN_JUCE_NAMESPACE
  56978. ButtonPropertyComponent::ButtonPropertyComponent (const String& name,
  56979. const bool triggerOnMouseDown)
  56980. : PropertyComponent (name)
  56981. {
  56982. addAndMakeVisible (button = new TextButton (String::empty));
  56983. button->setTriggeredOnMouseDown (triggerOnMouseDown);
  56984. button->addButtonListener (this);
  56985. }
  56986. ButtonPropertyComponent::~ButtonPropertyComponent()
  56987. {
  56988. deleteAllChildren();
  56989. }
  56990. void ButtonPropertyComponent::refresh()
  56991. {
  56992. button->setButtonText (getButtonText());
  56993. }
  56994. void ButtonPropertyComponent::buttonClicked (Button*)
  56995. {
  56996. buttonClicked();
  56997. }
  56998. END_JUCE_NAMESPACE
  56999. /*** End of inlined file: juce_ButtonPropertyComponent.cpp ***/
  57000. /*** Start of inlined file: juce_ChoicePropertyComponent.cpp ***/
  57001. BEGIN_JUCE_NAMESPACE
  57002. ChoicePropertyComponent::ChoicePropertyComponent (const String& name)
  57003. : PropertyComponent (name),
  57004. comboBox (0)
  57005. {
  57006. }
  57007. ChoicePropertyComponent::ChoicePropertyComponent (const Value& valueToControl,
  57008. const String& name,
  57009. const StringArray& choices_,
  57010. const Array <int>* choiceIDs)
  57011. : PropertyComponent (name),
  57012. choices (choices_),
  57013. comboBox (0)
  57014. {
  57015. createComboBox (choiceIDs);
  57016. comboBox->getSelectedIdAsValue().referTo (valueToControl);
  57017. }
  57018. ChoicePropertyComponent::~ChoicePropertyComponent()
  57019. {
  57020. deleteAllChildren();
  57021. }
  57022. void ChoicePropertyComponent::createComboBox (const Array <int>* choiceIDs)
  57023. {
  57024. // The array of IDs must contain the same number of values as the choices list!
  57025. jassert (choiceIDs == 0 || choiceIDs->size() == choices.size());
  57026. addAndMakeVisible (comboBox = new ComboBox (String::empty));
  57027. for (int i = 0; i < choices.size(); ++i)
  57028. {
  57029. if (choices[i].isNotEmpty())
  57030. comboBox->addItem (choices[i], choiceIDs == 0 ? (i + 1)
  57031. : ((*choiceIDs)[i]));
  57032. else
  57033. comboBox->addSeparator();
  57034. }
  57035. comboBox->setEditableText (false);
  57036. }
  57037. void ChoicePropertyComponent::setIndex (const int newIndex)
  57038. {
  57039. comboBox->setSelectedId (comboBox->getItemId (newIndex));
  57040. }
  57041. int ChoicePropertyComponent::getIndex() const
  57042. {
  57043. return comboBox->getSelectedItemIndex();
  57044. }
  57045. const StringArray& ChoicePropertyComponent::getChoices() const
  57046. {
  57047. return choices;
  57048. }
  57049. void ChoicePropertyComponent::refresh()
  57050. {
  57051. if (comboBox == 0)
  57052. {
  57053. createComboBox (0);
  57054. comboBox->addListener (this);
  57055. }
  57056. comboBox->setSelectedId (getIndex() + 1, true);
  57057. }
  57058. void ChoicePropertyComponent::comboBoxChanged (ComboBox*)
  57059. {
  57060. const int newIndex = comboBox->getSelectedId() - 1;
  57061. if (newIndex != getIndex())
  57062. setIndex (newIndex);
  57063. }
  57064. END_JUCE_NAMESPACE
  57065. /*** End of inlined file: juce_ChoicePropertyComponent.cpp ***/
  57066. /*** Start of inlined file: juce_PropertyComponent.cpp ***/
  57067. BEGIN_JUCE_NAMESPACE
  57068. PropertyComponent::PropertyComponent (const String& name,
  57069. const int preferredHeight_)
  57070. : Component (name),
  57071. preferredHeight (preferredHeight_)
  57072. {
  57073. jassert (name.isNotEmpty());
  57074. }
  57075. PropertyComponent::~PropertyComponent()
  57076. {
  57077. }
  57078. void PropertyComponent::paint (Graphics& g)
  57079. {
  57080. getLookAndFeel().drawPropertyComponentBackground (g, getWidth(), getHeight(), *this);
  57081. getLookAndFeel().drawPropertyComponentLabel (g, getWidth(), getHeight(), *this);
  57082. }
  57083. void PropertyComponent::resized()
  57084. {
  57085. if (getNumChildComponents() > 0)
  57086. getChildComponent (0)->setBounds (getLookAndFeel().getPropertyComponentContentPosition (*this));
  57087. }
  57088. void PropertyComponent::enablementChanged()
  57089. {
  57090. repaint();
  57091. }
  57092. END_JUCE_NAMESPACE
  57093. /*** End of inlined file: juce_PropertyComponent.cpp ***/
  57094. /*** Start of inlined file: juce_PropertyPanel.cpp ***/
  57095. BEGIN_JUCE_NAMESPACE
  57096. class PropertyHolderComponent : public Component
  57097. {
  57098. public:
  57099. PropertyHolderComponent()
  57100. {
  57101. }
  57102. ~PropertyHolderComponent()
  57103. {
  57104. deleteAllChildren();
  57105. }
  57106. void paint (Graphics&)
  57107. {
  57108. }
  57109. void updateLayout (const int width);
  57110. void refreshAll() const;
  57111. };
  57112. class PropertySectionComponent : public Component
  57113. {
  57114. public:
  57115. PropertySectionComponent (const String& sectionTitle,
  57116. const Array <PropertyComponent*>& newProperties,
  57117. const bool open)
  57118. : Component (sectionTitle),
  57119. titleHeight (sectionTitle.isNotEmpty() ? 22 : 0),
  57120. isOpen_ (open)
  57121. {
  57122. for (int i = newProperties.size(); --i >= 0;)
  57123. {
  57124. addAndMakeVisible (newProperties.getUnchecked(i));
  57125. newProperties.getUnchecked(i)->refresh();
  57126. }
  57127. }
  57128. ~PropertySectionComponent()
  57129. {
  57130. deleteAllChildren();
  57131. }
  57132. void paint (Graphics& g)
  57133. {
  57134. if (titleHeight > 0)
  57135. getLookAndFeel().drawPropertyPanelSectionHeader (g, getName(), isOpen(), getWidth(), titleHeight);
  57136. }
  57137. void resized()
  57138. {
  57139. int y = titleHeight;
  57140. for (int i = getNumChildComponents(); --i >= 0;)
  57141. {
  57142. PropertyComponent* const pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57143. if (pec != 0)
  57144. {
  57145. const int prefH = pec->getPreferredHeight();
  57146. pec->setBounds (1, y, getWidth() - 2, prefH);
  57147. y += prefH;
  57148. }
  57149. }
  57150. }
  57151. int getPreferredHeight() const
  57152. {
  57153. int y = titleHeight;
  57154. if (isOpen())
  57155. {
  57156. for (int i = 0; i < getNumChildComponents(); ++i)
  57157. {
  57158. PropertyComponent* pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57159. if (pec != 0)
  57160. y += pec->getPreferredHeight();
  57161. }
  57162. }
  57163. return y;
  57164. }
  57165. void setOpen (const bool open)
  57166. {
  57167. if (isOpen_ != open)
  57168. {
  57169. isOpen_ = open;
  57170. for (int i = 0; i < getNumChildComponents(); ++i)
  57171. {
  57172. PropertyComponent* pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57173. if (pec != 0)
  57174. pec->setVisible (open);
  57175. }
  57176. // (unable to use the syntax findParentComponentOfClass <DragAndDropContainer> () because of a VC6 compiler bug)
  57177. PropertyPanel* const pp = findParentComponentOfClass ((PropertyPanel*) 0);
  57178. if (pp != 0)
  57179. pp->resized();
  57180. }
  57181. }
  57182. bool isOpen() const
  57183. {
  57184. return isOpen_;
  57185. }
  57186. void refreshAll() const
  57187. {
  57188. for (int i = 0; i < getNumChildComponents(); ++i)
  57189. {
  57190. PropertyComponent* pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57191. if (pec != 0)
  57192. pec->refresh();
  57193. }
  57194. }
  57195. void mouseDown (const MouseEvent&)
  57196. {
  57197. }
  57198. void mouseUp (const MouseEvent& e)
  57199. {
  57200. if (e.getMouseDownX() < titleHeight
  57201. && e.x < titleHeight
  57202. && e.y < titleHeight
  57203. && e.getNumberOfClicks() != 2)
  57204. {
  57205. setOpen (! isOpen());
  57206. }
  57207. }
  57208. void mouseDoubleClick (const MouseEvent& e)
  57209. {
  57210. if (e.y < titleHeight)
  57211. setOpen (! isOpen());
  57212. }
  57213. private:
  57214. int titleHeight;
  57215. bool isOpen_;
  57216. };
  57217. void PropertyHolderComponent::updateLayout (const int width)
  57218. {
  57219. int y = 0;
  57220. for (int i = getNumChildComponents(); --i >= 0;)
  57221. {
  57222. PropertySectionComponent* const section
  57223. = dynamic_cast <PropertySectionComponent*> (getChildComponent (i));
  57224. if (section != 0)
  57225. {
  57226. const int prefH = section->getPreferredHeight();
  57227. section->setBounds (0, y, width, prefH);
  57228. y += prefH;
  57229. }
  57230. }
  57231. setSize (width, y);
  57232. repaint();
  57233. }
  57234. void PropertyHolderComponent::refreshAll() const
  57235. {
  57236. for (int i = getNumChildComponents(); --i >= 0;)
  57237. {
  57238. PropertySectionComponent* const section
  57239. = dynamic_cast <PropertySectionComponent*> (getChildComponent (i));
  57240. if (section != 0)
  57241. section->refreshAll();
  57242. }
  57243. }
  57244. PropertyPanel::PropertyPanel()
  57245. {
  57246. messageWhenEmpty = TRANS("(nothing selected)");
  57247. addAndMakeVisible (viewport = new Viewport());
  57248. viewport->setViewedComponent (propertyHolderComponent = new PropertyHolderComponent());
  57249. viewport->setFocusContainer (true);
  57250. }
  57251. PropertyPanel::~PropertyPanel()
  57252. {
  57253. clear();
  57254. deleteAllChildren();
  57255. }
  57256. void PropertyPanel::paint (Graphics& g)
  57257. {
  57258. if (propertyHolderComponent->getNumChildComponents() == 0)
  57259. {
  57260. g.setColour (Colours::black.withAlpha (0.5f));
  57261. g.setFont (14.0f);
  57262. g.drawText (messageWhenEmpty, 0, 0, getWidth(), 30,
  57263. Justification::centred, true);
  57264. }
  57265. }
  57266. void PropertyPanel::resized()
  57267. {
  57268. viewport->setBounds (0, 0, getWidth(), getHeight());
  57269. updatePropHolderLayout();
  57270. }
  57271. void PropertyPanel::clear()
  57272. {
  57273. if (propertyHolderComponent->getNumChildComponents() > 0)
  57274. {
  57275. propertyHolderComponent->deleteAllChildren();
  57276. repaint();
  57277. }
  57278. }
  57279. void PropertyPanel::addProperties (const Array <PropertyComponent*>& newProperties)
  57280. {
  57281. if (propertyHolderComponent->getNumChildComponents() == 0)
  57282. repaint();
  57283. propertyHolderComponent->addAndMakeVisible (new PropertySectionComponent (String::empty,
  57284. newProperties,
  57285. true), 0);
  57286. updatePropHolderLayout();
  57287. }
  57288. void PropertyPanel::addSection (const String& sectionTitle,
  57289. const Array <PropertyComponent*>& newProperties,
  57290. const bool shouldBeOpen)
  57291. {
  57292. jassert (sectionTitle.isNotEmpty());
  57293. if (propertyHolderComponent->getNumChildComponents() == 0)
  57294. repaint();
  57295. propertyHolderComponent->addAndMakeVisible (new PropertySectionComponent (sectionTitle,
  57296. newProperties,
  57297. shouldBeOpen), 0);
  57298. updatePropHolderLayout();
  57299. }
  57300. void PropertyPanel::updatePropHolderLayout() const
  57301. {
  57302. const int maxWidth = viewport->getMaximumVisibleWidth();
  57303. ((PropertyHolderComponent*) propertyHolderComponent)->updateLayout (maxWidth);
  57304. const int newMaxWidth = viewport->getMaximumVisibleWidth();
  57305. if (maxWidth != newMaxWidth)
  57306. {
  57307. // need to do this twice because of scrollbars changing the size, etc.
  57308. ((PropertyHolderComponent*) propertyHolderComponent)->updateLayout (newMaxWidth);
  57309. }
  57310. }
  57311. void PropertyPanel::refreshAll() const
  57312. {
  57313. ((PropertyHolderComponent*) propertyHolderComponent)->refreshAll();
  57314. }
  57315. const StringArray PropertyPanel::getSectionNames() const
  57316. {
  57317. StringArray s;
  57318. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57319. {
  57320. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57321. if (section != 0 && section->getName().isNotEmpty())
  57322. s.add (section->getName());
  57323. }
  57324. return s;
  57325. }
  57326. bool PropertyPanel::isSectionOpen (const int sectionIndex) const
  57327. {
  57328. int index = 0;
  57329. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57330. {
  57331. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57332. if (section != 0 && section->getName().isNotEmpty())
  57333. {
  57334. if (index == sectionIndex)
  57335. return section->isOpen();
  57336. ++index;
  57337. }
  57338. }
  57339. return false;
  57340. }
  57341. void PropertyPanel::setSectionOpen (const int sectionIndex, const bool shouldBeOpen)
  57342. {
  57343. int index = 0;
  57344. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57345. {
  57346. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57347. if (section != 0 && section->getName().isNotEmpty())
  57348. {
  57349. if (index == sectionIndex)
  57350. {
  57351. section->setOpen (shouldBeOpen);
  57352. break;
  57353. }
  57354. ++index;
  57355. }
  57356. }
  57357. }
  57358. void PropertyPanel::setSectionEnabled (const int sectionIndex, const bool shouldBeEnabled)
  57359. {
  57360. int index = 0;
  57361. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57362. {
  57363. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57364. if (section != 0 && section->getName().isNotEmpty())
  57365. {
  57366. if (index == sectionIndex)
  57367. {
  57368. section->setEnabled (shouldBeEnabled);
  57369. break;
  57370. }
  57371. ++index;
  57372. }
  57373. }
  57374. }
  57375. XmlElement* PropertyPanel::getOpennessState() const
  57376. {
  57377. XmlElement* const xml = new XmlElement (T("PROPERTYPANELSTATE"));
  57378. xml->setAttribute ("scrollPos", viewport->getViewPositionY());
  57379. const StringArray sections (getSectionNames());
  57380. for (int i = 0; i < sections.size(); ++i)
  57381. {
  57382. if (sections[i].isNotEmpty())
  57383. {
  57384. XmlElement* const e = xml->createNewChildElement ("SECTION");
  57385. e->setAttribute ("name", sections[i]);
  57386. e->setAttribute ("open", isSectionOpen (i) ? 1 : 0);
  57387. }
  57388. }
  57389. return xml;
  57390. }
  57391. void PropertyPanel::restoreOpennessState (const XmlElement& xml)
  57392. {
  57393. if (xml.hasTagName (T("PROPERTYPANELSTATE")))
  57394. {
  57395. const StringArray sections (getSectionNames());
  57396. forEachXmlChildElementWithTagName (xml, e, T("SECTION"))
  57397. {
  57398. setSectionOpen (sections.indexOf (e->getStringAttribute (T("name"))),
  57399. e->getBoolAttribute (T("open")));
  57400. }
  57401. viewport->setViewPosition (viewport->getViewPositionX(),
  57402. xml.getIntAttribute ("scrollPos", viewport->getViewPositionY()));
  57403. }
  57404. }
  57405. void PropertyPanel::setMessageWhenEmpty (const String& newMessage)
  57406. {
  57407. if (messageWhenEmpty != newMessage)
  57408. {
  57409. messageWhenEmpty = newMessage;
  57410. repaint();
  57411. }
  57412. }
  57413. const String& PropertyPanel::getMessageWhenEmpty() const
  57414. {
  57415. return messageWhenEmpty;
  57416. }
  57417. END_JUCE_NAMESPACE
  57418. /*** End of inlined file: juce_PropertyPanel.cpp ***/
  57419. /*** Start of inlined file: juce_SliderPropertyComponent.cpp ***/
  57420. BEGIN_JUCE_NAMESPACE
  57421. SliderPropertyComponent::SliderPropertyComponent (const String& name,
  57422. const double rangeMin,
  57423. const double rangeMax,
  57424. const double interval,
  57425. const double skewFactor)
  57426. : PropertyComponent (name)
  57427. {
  57428. addAndMakeVisible (slider = new Slider (name));
  57429. slider->setRange (rangeMin, rangeMax, interval);
  57430. slider->setSkewFactor (skewFactor);
  57431. slider->setSliderStyle (Slider::LinearBar);
  57432. slider->addListener (this);
  57433. }
  57434. SliderPropertyComponent::SliderPropertyComponent (Value& valueToControl,
  57435. const String& name,
  57436. const double rangeMin,
  57437. const double rangeMax,
  57438. const double interval,
  57439. const double skewFactor)
  57440. : PropertyComponent (name)
  57441. {
  57442. addAndMakeVisible (slider = new Slider (name));
  57443. slider->setRange (rangeMin, rangeMax, interval);
  57444. slider->setSkewFactor (skewFactor);
  57445. slider->setSliderStyle (Slider::LinearBar);
  57446. slider->getValueObject().referTo (valueToControl);
  57447. }
  57448. SliderPropertyComponent::~SliderPropertyComponent()
  57449. {
  57450. deleteAllChildren();
  57451. }
  57452. void SliderPropertyComponent::setValue (const double /*newValue*/)
  57453. {
  57454. }
  57455. const double SliderPropertyComponent::getValue() const
  57456. {
  57457. return slider->getValue();
  57458. }
  57459. void SliderPropertyComponent::refresh()
  57460. {
  57461. slider->setValue (getValue(), false);
  57462. }
  57463. void SliderPropertyComponent::sliderValueChanged (Slider*)
  57464. {
  57465. if (getValue() != slider->getValue())
  57466. setValue (slider->getValue());
  57467. }
  57468. END_JUCE_NAMESPACE
  57469. /*** End of inlined file: juce_SliderPropertyComponent.cpp ***/
  57470. /*** Start of inlined file: juce_TextPropertyComponent.cpp ***/
  57471. BEGIN_JUCE_NAMESPACE
  57472. class TextPropLabel : public Label
  57473. {
  57474. TextPropertyComponent& owner;
  57475. int maxChars;
  57476. bool isMultiline;
  57477. public:
  57478. TextPropLabel (TextPropertyComponent& owner_,
  57479. const int maxChars_, const bool isMultiline_)
  57480. : Label (String::empty, String::empty),
  57481. owner (owner_),
  57482. maxChars (maxChars_),
  57483. isMultiline (isMultiline_)
  57484. {
  57485. setEditable (true, true, false);
  57486. setColour (backgroundColourId, Colours::white);
  57487. setColour (outlineColourId, findColour (ComboBox::outlineColourId));
  57488. }
  57489. ~TextPropLabel()
  57490. {
  57491. }
  57492. TextEditor* createEditorComponent()
  57493. {
  57494. TextEditor* const textEditor = Label::createEditorComponent();
  57495. textEditor->setInputRestrictions (maxChars);
  57496. if (isMultiline)
  57497. {
  57498. textEditor->setMultiLine (true, true);
  57499. textEditor->setReturnKeyStartsNewLine (true);
  57500. }
  57501. return textEditor;
  57502. }
  57503. void textWasEdited()
  57504. {
  57505. owner.textWasEdited();
  57506. }
  57507. };
  57508. TextPropertyComponent::TextPropertyComponent (const String& name,
  57509. const int maxNumChars,
  57510. const bool isMultiLine)
  57511. : PropertyComponent (name)
  57512. {
  57513. createEditor (maxNumChars, isMultiLine);
  57514. }
  57515. TextPropertyComponent::TextPropertyComponent (const Value& valueToControl,
  57516. const String& name,
  57517. const int maxNumChars,
  57518. const bool isMultiLine)
  57519. : PropertyComponent (name)
  57520. {
  57521. createEditor (maxNumChars, isMultiLine);
  57522. textEditor->getTextValue().referTo (valueToControl);
  57523. }
  57524. TextPropertyComponent::~TextPropertyComponent()
  57525. {
  57526. deleteAllChildren();
  57527. }
  57528. void TextPropertyComponent::setText (const String& newText)
  57529. {
  57530. textEditor->setText (newText, true);
  57531. }
  57532. const String TextPropertyComponent::getText() const
  57533. {
  57534. return textEditor->getText();
  57535. }
  57536. void TextPropertyComponent::createEditor (const int maxNumChars, const bool isMultiLine)
  57537. {
  57538. addAndMakeVisible (textEditor = new TextPropLabel (*this, maxNumChars, isMultiLine));
  57539. if (isMultiLine)
  57540. {
  57541. textEditor->setJustificationType (Justification::topLeft);
  57542. preferredHeight = 120;
  57543. }
  57544. }
  57545. void TextPropertyComponent::refresh()
  57546. {
  57547. textEditor->setText (getText(), false);
  57548. }
  57549. void TextPropertyComponent::textWasEdited()
  57550. {
  57551. const String newText (textEditor->getText());
  57552. if (getText() != newText)
  57553. setText (newText);
  57554. }
  57555. END_JUCE_NAMESPACE
  57556. /*** End of inlined file: juce_TextPropertyComponent.cpp ***/
  57557. /*** Start of inlined file: juce_AudioDeviceSelectorComponent.cpp ***/
  57558. BEGIN_JUCE_NAMESPACE
  57559. class SimpleDeviceManagerInputLevelMeter : public Component,
  57560. public Timer
  57561. {
  57562. public:
  57563. SimpleDeviceManagerInputLevelMeter (AudioDeviceManager* const manager_)
  57564. : manager (manager_),
  57565. level (0)
  57566. {
  57567. startTimer (50);
  57568. manager->enableInputLevelMeasurement (true);
  57569. }
  57570. ~SimpleDeviceManagerInputLevelMeter()
  57571. {
  57572. manager->enableInputLevelMeasurement (false);
  57573. }
  57574. void timerCallback()
  57575. {
  57576. const float newLevel = (float) manager->getCurrentInputLevel();
  57577. if (fabsf (level - newLevel) > 0.005f)
  57578. {
  57579. level = newLevel;
  57580. repaint();
  57581. }
  57582. }
  57583. void paint (Graphics& g)
  57584. {
  57585. getLookAndFeel().drawLevelMeter (g, getWidth(), getHeight(),
  57586. (float) exp (log (level) / 3.0)); // (add a bit of a skew to make the level more obvious)
  57587. }
  57588. private:
  57589. AudioDeviceManager* const manager;
  57590. float level;
  57591. };
  57592. class MidiInputSelectorComponentListBox : public ListBox,
  57593. public ListBoxModel
  57594. {
  57595. public:
  57596. MidiInputSelectorComponentListBox (AudioDeviceManager& deviceManager_,
  57597. const String& noItemsMessage_,
  57598. const int minNumber_,
  57599. const int maxNumber_)
  57600. : ListBox (String::empty, 0),
  57601. deviceManager (deviceManager_),
  57602. noItemsMessage (noItemsMessage_),
  57603. minNumber (minNumber_),
  57604. maxNumber (maxNumber_)
  57605. {
  57606. items = MidiInput::getDevices();
  57607. setModel (this);
  57608. setOutlineThickness (1);
  57609. }
  57610. ~MidiInputSelectorComponentListBox()
  57611. {
  57612. }
  57613. int getNumRows()
  57614. {
  57615. return items.size();
  57616. }
  57617. void paintListBoxItem (int row,
  57618. Graphics& g,
  57619. int width, int height,
  57620. bool rowIsSelected)
  57621. {
  57622. if (((unsigned int) row) < (unsigned int) items.size())
  57623. {
  57624. if (rowIsSelected)
  57625. g.fillAll (findColour (TextEditor::highlightColourId)
  57626. .withMultipliedAlpha (0.3f));
  57627. const String item (items [row]);
  57628. bool enabled = deviceManager.isMidiInputEnabled (item);
  57629. const int x = getTickX();
  57630. const float tickW = height * 0.75f;
  57631. getLookAndFeel().drawTickBox (g, *this, x - tickW, (height - tickW) / 2, tickW, tickW,
  57632. enabled, true, true, false);
  57633. g.setFont (height * 0.6f);
  57634. g.setColour (findColour (ListBox::textColourId, true).withMultipliedAlpha (enabled ? 1.0f : 0.6f));
  57635. g.drawText (item, x, 0, width - x - 2, height, Justification::centredLeft, true);
  57636. }
  57637. }
  57638. void listBoxItemClicked (int row, const MouseEvent& e)
  57639. {
  57640. selectRow (row);
  57641. if (e.x < getTickX())
  57642. flipEnablement (row);
  57643. }
  57644. void listBoxItemDoubleClicked (int row, const MouseEvent&)
  57645. {
  57646. flipEnablement (row);
  57647. }
  57648. void returnKeyPressed (int row)
  57649. {
  57650. flipEnablement (row);
  57651. }
  57652. void paint (Graphics& g)
  57653. {
  57654. ListBox::paint (g);
  57655. if (items.size() == 0)
  57656. {
  57657. g.setColour (Colours::grey);
  57658. g.setFont (13.0f);
  57659. g.drawText (noItemsMessage,
  57660. 0, 0, getWidth(), getHeight() / 2,
  57661. Justification::centred, true);
  57662. }
  57663. }
  57664. int getBestHeight (const int preferredHeight)
  57665. {
  57666. const int extra = getOutlineThickness() * 2;
  57667. return jmax (getRowHeight() * 2 + extra,
  57668. jmin (getRowHeight() * getNumRows() + extra,
  57669. preferredHeight));
  57670. }
  57671. juce_UseDebuggingNewOperator
  57672. private:
  57673. AudioDeviceManager& deviceManager;
  57674. const String noItemsMessage;
  57675. StringArray items;
  57676. int minNumber, maxNumber;
  57677. void flipEnablement (const int row)
  57678. {
  57679. if (((unsigned int) row) < (unsigned int) items.size())
  57680. {
  57681. const String item (items [row]);
  57682. deviceManager.setMidiInputEnabled (item, ! deviceManager.isMidiInputEnabled (item));
  57683. }
  57684. }
  57685. int getTickX() const
  57686. {
  57687. return getRowHeight() + 5;
  57688. }
  57689. MidiInputSelectorComponentListBox (const MidiInputSelectorComponentListBox&);
  57690. MidiInputSelectorComponentListBox& operator= (const MidiInputSelectorComponentListBox&);
  57691. };
  57692. class AudioDeviceSettingsPanel : public Component,
  57693. public ComboBoxListener,
  57694. public ChangeListener,
  57695. public ButtonListener
  57696. {
  57697. public:
  57698. AudioDeviceSettingsPanel (AudioIODeviceType* type_,
  57699. AudioIODeviceType::DeviceSetupDetails& setup_,
  57700. const bool hideAdvancedOptionsWithButton)
  57701. : type (type_),
  57702. setup (setup_)
  57703. {
  57704. sampleRateDropDown = 0;
  57705. sampleRateLabel = 0;
  57706. bufferSizeDropDown = 0;
  57707. bufferSizeLabel = 0;
  57708. outputDeviceDropDown = 0;
  57709. outputDeviceLabel = 0;
  57710. inputDeviceDropDown = 0;
  57711. inputDeviceLabel = 0;
  57712. testButton = 0;
  57713. inputLevelMeter = 0;
  57714. showUIButton = 0;
  57715. inputChanList = 0;
  57716. outputChanList = 0;
  57717. inputChanLabel = 0;
  57718. outputChanLabel = 0;
  57719. showAdvancedSettingsButton = 0;
  57720. if (hideAdvancedOptionsWithButton)
  57721. {
  57722. addAndMakeVisible (showAdvancedSettingsButton = new TextButton (TRANS("Show advanced settings...")));
  57723. showAdvancedSettingsButton->addButtonListener (this);
  57724. }
  57725. type->scanForDevices();
  57726. setup.manager->addChangeListener (this);
  57727. changeListenerCallback (0);
  57728. }
  57729. ~AudioDeviceSettingsPanel()
  57730. {
  57731. setup.manager->removeChangeListener (this);
  57732. deleteAndZero (outputDeviceLabel);
  57733. deleteAndZero (inputDeviceLabel);
  57734. deleteAndZero (sampleRateLabel);
  57735. deleteAndZero (bufferSizeLabel);
  57736. deleteAndZero (showUIButton);
  57737. deleteAndZero (inputChanLabel);
  57738. deleteAndZero (outputChanLabel);
  57739. deleteAndZero (showAdvancedSettingsButton);
  57740. deleteAllChildren();
  57741. }
  57742. void resized()
  57743. {
  57744. const int lx = proportionOfWidth (0.35f);
  57745. const int w = proportionOfWidth (0.4f);
  57746. const int h = 24;
  57747. const int space = 6;
  57748. const int dh = h + space;
  57749. int y = 0;
  57750. if (outputDeviceDropDown != 0)
  57751. {
  57752. outputDeviceDropDown->setBounds (lx, y, w, h);
  57753. if (testButton != 0)
  57754. testButton->setBounds (proportionOfWidth (0.77f),
  57755. outputDeviceDropDown->getY(),
  57756. proportionOfWidth (0.18f),
  57757. h);
  57758. y += dh;
  57759. }
  57760. if (inputDeviceDropDown != 0)
  57761. {
  57762. inputDeviceDropDown->setBounds (lx, y, w, h);
  57763. inputLevelMeter->setBounds (proportionOfWidth (0.77f),
  57764. inputDeviceDropDown->getY(),
  57765. proportionOfWidth (0.18f),
  57766. h);
  57767. y += dh;
  57768. }
  57769. const int maxBoxHeight = 100;//(getHeight() - y - dh * 2) / numBoxes;
  57770. if (outputChanList != 0)
  57771. {
  57772. const int bh = outputChanList->getBestHeight (maxBoxHeight);
  57773. outputChanList->setBounds (lx, y, proportionOfWidth (0.55f), bh);
  57774. y += bh + space;
  57775. }
  57776. if (inputChanList != 0)
  57777. {
  57778. const int bh = inputChanList->getBestHeight (maxBoxHeight);
  57779. inputChanList->setBounds (lx, y, proportionOfWidth (0.55f), bh);
  57780. y += bh + space;
  57781. }
  57782. y += space * 2;
  57783. if (showAdvancedSettingsButton != 0)
  57784. {
  57785. showAdvancedSettingsButton->changeWidthToFitText (h);
  57786. showAdvancedSettingsButton->setTopLeftPosition (lx, y);
  57787. }
  57788. if (sampleRateDropDown != 0)
  57789. {
  57790. sampleRateDropDown->setVisible (showAdvancedSettingsButton == 0
  57791. || ! showAdvancedSettingsButton->isVisible());
  57792. sampleRateDropDown->setBounds (lx, y, w, h);
  57793. y += dh;
  57794. }
  57795. if (bufferSizeDropDown != 0)
  57796. {
  57797. bufferSizeDropDown->setVisible (showAdvancedSettingsButton == 0
  57798. || ! showAdvancedSettingsButton->isVisible());
  57799. bufferSizeDropDown->setBounds (lx, y, w, h);
  57800. y += dh;
  57801. }
  57802. if (showUIButton != 0)
  57803. {
  57804. showUIButton->setVisible (showAdvancedSettingsButton == 0
  57805. || ! showAdvancedSettingsButton->isVisible());
  57806. showUIButton->changeWidthToFitText (h);
  57807. showUIButton->setTopLeftPosition (lx, y);
  57808. }
  57809. }
  57810. void comboBoxChanged (ComboBox* comboBoxThatHasChanged)
  57811. {
  57812. if (comboBoxThatHasChanged == 0)
  57813. return;
  57814. AudioDeviceManager::AudioDeviceSetup config;
  57815. setup.manager->getAudioDeviceSetup (config);
  57816. String error;
  57817. if (comboBoxThatHasChanged == outputDeviceDropDown
  57818. || comboBoxThatHasChanged == inputDeviceDropDown)
  57819. {
  57820. if (outputDeviceDropDown != 0)
  57821. config.outputDeviceName = outputDeviceDropDown->getSelectedId() < 0 ? String::empty
  57822. : outputDeviceDropDown->getText();
  57823. if (inputDeviceDropDown != 0)
  57824. config.inputDeviceName = inputDeviceDropDown->getSelectedId() < 0 ? String::empty
  57825. : inputDeviceDropDown->getText();
  57826. if (! type->hasSeparateInputsAndOutputs())
  57827. config.inputDeviceName = config.outputDeviceName;
  57828. if (comboBoxThatHasChanged == inputDeviceDropDown)
  57829. config.useDefaultInputChannels = true;
  57830. else
  57831. config.useDefaultOutputChannels = true;
  57832. error = setup.manager->setAudioDeviceSetup (config, true);
  57833. showCorrectDeviceName (inputDeviceDropDown, true);
  57834. showCorrectDeviceName (outputDeviceDropDown, false);
  57835. updateControlPanelButton();
  57836. resized();
  57837. }
  57838. else if (comboBoxThatHasChanged == sampleRateDropDown)
  57839. {
  57840. if (sampleRateDropDown->getSelectedId() > 0)
  57841. {
  57842. config.sampleRate = sampleRateDropDown->getSelectedId();
  57843. error = setup.manager->setAudioDeviceSetup (config, true);
  57844. }
  57845. }
  57846. else if (comboBoxThatHasChanged == bufferSizeDropDown)
  57847. {
  57848. if (bufferSizeDropDown->getSelectedId() > 0)
  57849. {
  57850. config.bufferSize = bufferSizeDropDown->getSelectedId();
  57851. error = setup.manager->setAudioDeviceSetup (config, true);
  57852. }
  57853. }
  57854. if (error.isNotEmpty())
  57855. {
  57856. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  57857. T("Error when trying to open audio device!"),
  57858. error);
  57859. }
  57860. }
  57861. void buttonClicked (Button* button)
  57862. {
  57863. if (button == showAdvancedSettingsButton)
  57864. {
  57865. showAdvancedSettingsButton->setVisible (false);
  57866. resized();
  57867. }
  57868. else if (button == showUIButton)
  57869. {
  57870. AudioIODevice* const device = setup.manager->getCurrentAudioDevice();
  57871. if (device != 0 && device->showControlPanel())
  57872. {
  57873. setup.manager->closeAudioDevice();
  57874. setup.manager->restartLastAudioDevice();
  57875. getTopLevelComponent()->toFront (true);
  57876. }
  57877. }
  57878. else if (button == testButton && testButton != 0)
  57879. {
  57880. setup.manager->playTestSound();
  57881. }
  57882. }
  57883. void updateControlPanelButton()
  57884. {
  57885. AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice();
  57886. deleteAndZero (showUIButton);
  57887. if (currentDevice != 0 && currentDevice->hasControlPanel())
  57888. {
  57889. addAndMakeVisible (showUIButton = new TextButton (TRANS ("show this device's control panel"),
  57890. TRANS ("opens the device's own control panel")));
  57891. showUIButton->addButtonListener (this);
  57892. }
  57893. resized();
  57894. }
  57895. void changeListenerCallback (void*)
  57896. {
  57897. AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice();
  57898. if (setup.maxNumOutputChannels > 0 || ! type->hasSeparateInputsAndOutputs())
  57899. {
  57900. if (outputDeviceDropDown == 0)
  57901. {
  57902. outputDeviceDropDown = new ComboBox (String::empty);
  57903. outputDeviceDropDown->addListener (this);
  57904. addAndMakeVisible (outputDeviceDropDown);
  57905. outputDeviceLabel = new Label (String::empty,
  57906. type->hasSeparateInputsAndOutputs() ? TRANS ("output:")
  57907. : TRANS ("device:"));
  57908. outputDeviceLabel->attachToComponent (outputDeviceDropDown, true);
  57909. if (setup.maxNumOutputChannels > 0)
  57910. {
  57911. addAndMakeVisible (testButton = new TextButton (TRANS ("Test")));
  57912. testButton->addButtonListener (this);
  57913. }
  57914. }
  57915. addNamesToDeviceBox (*outputDeviceDropDown, false);
  57916. }
  57917. if (setup.maxNumInputChannels > 0 && type->hasSeparateInputsAndOutputs())
  57918. {
  57919. if (inputDeviceDropDown == 0)
  57920. {
  57921. inputDeviceDropDown = new ComboBox (String::empty);
  57922. inputDeviceDropDown->addListener (this);
  57923. addAndMakeVisible (inputDeviceDropDown);
  57924. inputDeviceLabel = new Label (String::empty, TRANS ("input:"));
  57925. inputDeviceLabel->attachToComponent (inputDeviceDropDown, true);
  57926. addAndMakeVisible (inputLevelMeter
  57927. = new SimpleDeviceManagerInputLevelMeter (setup.manager));
  57928. }
  57929. addNamesToDeviceBox (*inputDeviceDropDown, true);
  57930. }
  57931. updateControlPanelButton();
  57932. showCorrectDeviceName (inputDeviceDropDown, true);
  57933. showCorrectDeviceName (outputDeviceDropDown, false);
  57934. if (currentDevice != 0)
  57935. {
  57936. if (setup.maxNumOutputChannels > 0
  57937. && setup.minNumOutputChannels < setup.manager->getCurrentAudioDevice()->getOutputChannelNames().size())
  57938. {
  57939. if (outputChanList == 0)
  57940. {
  57941. addAndMakeVisible (outputChanList
  57942. = new ChannelSelectorListBox (setup, ChannelSelectorListBox::audioOutputType,
  57943. TRANS ("(no audio output channels found)")));
  57944. outputChanLabel = new Label (String::empty, TRANS ("active output channels:"));
  57945. outputChanLabel->attachToComponent (outputChanList, true);
  57946. }
  57947. outputChanList->refresh();
  57948. }
  57949. else
  57950. {
  57951. deleteAndZero (outputChanLabel);
  57952. deleteAndZero (outputChanList);
  57953. }
  57954. if (setup.maxNumInputChannels > 0
  57955. && setup.minNumInputChannels < setup.manager->getCurrentAudioDevice()->getInputChannelNames().size())
  57956. {
  57957. if (inputChanList == 0)
  57958. {
  57959. addAndMakeVisible (inputChanList
  57960. = new ChannelSelectorListBox (setup, ChannelSelectorListBox::audioInputType,
  57961. TRANS ("(no audio input channels found)")));
  57962. inputChanLabel = new Label (String::empty, TRANS ("active input channels:"));
  57963. inputChanLabel->attachToComponent (inputChanList, true);
  57964. }
  57965. inputChanList->refresh();
  57966. }
  57967. else
  57968. {
  57969. deleteAndZero (inputChanLabel);
  57970. deleteAndZero (inputChanList);
  57971. }
  57972. // sample rate..
  57973. {
  57974. if (sampleRateDropDown == 0)
  57975. {
  57976. addAndMakeVisible (sampleRateDropDown = new ComboBox (String::empty));
  57977. sampleRateDropDown->addListener (this);
  57978. delete sampleRateLabel;
  57979. sampleRateLabel = new Label (String::empty, TRANS ("sample rate:"));
  57980. sampleRateLabel->attachToComponent (sampleRateDropDown, true);
  57981. }
  57982. else
  57983. {
  57984. sampleRateDropDown->clear();
  57985. sampleRateDropDown->removeListener (this);
  57986. }
  57987. const int numRates = currentDevice->getNumSampleRates();
  57988. for (int i = 0; i < numRates; ++i)
  57989. {
  57990. const int rate = roundToInt (currentDevice->getSampleRate (i));
  57991. sampleRateDropDown->addItem (String (rate) + T(" Hz"), rate);
  57992. }
  57993. sampleRateDropDown->setSelectedId (roundToInt (currentDevice->getCurrentSampleRate()), true);
  57994. sampleRateDropDown->addListener (this);
  57995. }
  57996. // buffer size
  57997. {
  57998. if (bufferSizeDropDown == 0)
  57999. {
  58000. addAndMakeVisible (bufferSizeDropDown = new ComboBox (String::empty));
  58001. bufferSizeDropDown->addListener (this);
  58002. delete bufferSizeLabel;
  58003. bufferSizeLabel = new Label (String::empty, TRANS ("audio buffer size:"));
  58004. bufferSizeLabel->attachToComponent (bufferSizeDropDown, true);
  58005. }
  58006. else
  58007. {
  58008. bufferSizeDropDown->clear();
  58009. }
  58010. const int numBufferSizes = currentDevice->getNumBufferSizesAvailable();
  58011. double currentRate = currentDevice->getCurrentSampleRate();
  58012. if (currentRate == 0)
  58013. currentRate = 48000.0;
  58014. for (int i = 0; i < numBufferSizes; ++i)
  58015. {
  58016. const int bs = currentDevice->getBufferSizeSamples (i);
  58017. bufferSizeDropDown->addItem (String (bs)
  58018. + T(" samples (")
  58019. + String (bs * 1000.0 / currentRate, 1)
  58020. + T(" ms)"),
  58021. bs);
  58022. }
  58023. bufferSizeDropDown->setSelectedId (currentDevice->getCurrentBufferSizeSamples(), true);
  58024. }
  58025. }
  58026. else
  58027. {
  58028. jassert (setup.manager->getCurrentAudioDevice() == 0); // not the correct device type!
  58029. deleteAndZero (sampleRateLabel);
  58030. deleteAndZero (bufferSizeLabel);
  58031. deleteAndZero (sampleRateDropDown);
  58032. deleteAndZero (bufferSizeDropDown);
  58033. if (outputDeviceDropDown != 0)
  58034. outputDeviceDropDown->setSelectedId (-1, true);
  58035. if (inputDeviceDropDown != 0)
  58036. inputDeviceDropDown->setSelectedId (-1, true);
  58037. }
  58038. resized();
  58039. setSize (getWidth(), getLowestY() + 4);
  58040. }
  58041. private:
  58042. AudioIODeviceType* const type;
  58043. const AudioIODeviceType::DeviceSetupDetails setup;
  58044. ComboBox* outputDeviceDropDown;
  58045. ComboBox* inputDeviceDropDown;
  58046. ComboBox* sampleRateDropDown;
  58047. ComboBox* bufferSizeDropDown;
  58048. Label* outputDeviceLabel;
  58049. Label* inputDeviceLabel;
  58050. Label* sampleRateLabel;
  58051. Label* bufferSizeLabel;
  58052. Label* inputChanLabel;
  58053. Label* outputChanLabel;
  58054. TextButton* testButton;
  58055. Component* inputLevelMeter;
  58056. TextButton* showUIButton;
  58057. TextButton* showAdvancedSettingsButton;
  58058. void showCorrectDeviceName (ComboBox* const box, const bool isInput)
  58059. {
  58060. if (box != 0)
  58061. {
  58062. AudioIODevice* const currentDevice = dynamic_cast <AudioIODevice*> (setup.manager->getCurrentAudioDevice());
  58063. const int index = type->getIndexOfDevice (currentDevice, isInput);
  58064. box->setSelectedId (index + 1, true);
  58065. if (testButton != 0 && ! isInput)
  58066. testButton->setEnabled (index >= 0);
  58067. }
  58068. }
  58069. void addNamesToDeviceBox (ComboBox& combo, bool isInputs)
  58070. {
  58071. const StringArray devs (type->getDeviceNames (isInputs));
  58072. combo.clear (true);
  58073. for (int i = 0; i < devs.size(); ++i)
  58074. combo.addItem (devs[i], i + 1);
  58075. combo.addItem (TRANS("<< none >>"), -1);
  58076. combo.setSelectedId (-1, true);
  58077. }
  58078. int getLowestY() const
  58079. {
  58080. int y = 0;
  58081. for (int i = getNumChildComponents(); --i >= 0;)
  58082. y = jmax (y, getChildComponent (i)->getBottom());
  58083. return y;
  58084. }
  58085. public:
  58086. class ChannelSelectorListBox : public ListBox,
  58087. public ListBoxModel
  58088. {
  58089. public:
  58090. enum BoxType
  58091. {
  58092. audioInputType,
  58093. audioOutputType
  58094. };
  58095. ChannelSelectorListBox (const AudioIODeviceType::DeviceSetupDetails& setup_,
  58096. const BoxType type_,
  58097. const String& noItemsMessage_)
  58098. : ListBox (String::empty, 0),
  58099. setup (setup_),
  58100. type (type_),
  58101. noItemsMessage (noItemsMessage_)
  58102. {
  58103. refresh();
  58104. setModel (this);
  58105. setOutlineThickness (1);
  58106. }
  58107. ~ChannelSelectorListBox()
  58108. {
  58109. }
  58110. void refresh()
  58111. {
  58112. items.clear();
  58113. AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice();
  58114. if (currentDevice != 0)
  58115. {
  58116. if (type == audioInputType)
  58117. items = currentDevice->getInputChannelNames();
  58118. else if (type == audioOutputType)
  58119. items = currentDevice->getOutputChannelNames();
  58120. if (setup.useStereoPairs)
  58121. {
  58122. StringArray pairs;
  58123. for (int i = 0; i < items.size(); i += 2)
  58124. {
  58125. String name (items[i]);
  58126. String name2 (items[i + 1]);
  58127. String commonBit;
  58128. for (int j = 0; j < name.length(); ++j)
  58129. if (name.substring (0, j).equalsIgnoreCase (name2.substring (0, j)))
  58130. commonBit = name.substring (0, j);
  58131. pairs.add (name.trim()
  58132. + " + "
  58133. + name2.substring (commonBit.length()).trim());
  58134. }
  58135. items = pairs;
  58136. }
  58137. }
  58138. updateContent();
  58139. repaint();
  58140. }
  58141. int getNumRows()
  58142. {
  58143. return items.size();
  58144. }
  58145. void paintListBoxItem (int row,
  58146. Graphics& g,
  58147. int width, int height,
  58148. bool rowIsSelected)
  58149. {
  58150. if (((unsigned int) row) < (unsigned int) items.size())
  58151. {
  58152. if (rowIsSelected)
  58153. g.fillAll (findColour (TextEditor::highlightColourId)
  58154. .withMultipliedAlpha (0.3f));
  58155. const String item (items [row]);
  58156. bool enabled = false;
  58157. AudioDeviceManager::AudioDeviceSetup config;
  58158. setup.manager->getAudioDeviceSetup (config);
  58159. if (setup.useStereoPairs)
  58160. {
  58161. if (type == audioInputType)
  58162. enabled = config.inputChannels [row * 2] || config.inputChannels [row * 2 + 1];
  58163. else if (type == audioOutputType)
  58164. enabled = config.outputChannels [row * 2] || config.outputChannels [row * 2 + 1];
  58165. }
  58166. else
  58167. {
  58168. if (type == audioInputType)
  58169. enabled = config.inputChannels [row];
  58170. else if (type == audioOutputType)
  58171. enabled = config.outputChannels [row];
  58172. }
  58173. const int x = getTickX();
  58174. const float tickW = height * 0.75f;
  58175. getLookAndFeel().drawTickBox (g, *this, x - tickW, (height - tickW) / 2, tickW, tickW,
  58176. enabled, true, true, false);
  58177. g.setFont (height * 0.6f);
  58178. g.setColour (findColour (ListBox::textColourId, true).withMultipliedAlpha (enabled ? 1.0f : 0.6f));
  58179. g.drawText (item, x, 0, width - x - 2, height, Justification::centredLeft, true);
  58180. }
  58181. }
  58182. void listBoxItemClicked (int row, const MouseEvent& e)
  58183. {
  58184. selectRow (row);
  58185. if (e.x < getTickX())
  58186. flipEnablement (row);
  58187. }
  58188. void listBoxItemDoubleClicked (int row, const MouseEvent&)
  58189. {
  58190. flipEnablement (row);
  58191. }
  58192. void returnKeyPressed (int row)
  58193. {
  58194. flipEnablement (row);
  58195. }
  58196. void paint (Graphics& g)
  58197. {
  58198. ListBox::paint (g);
  58199. if (items.size() == 0)
  58200. {
  58201. g.setColour (Colours::grey);
  58202. g.setFont (13.0f);
  58203. g.drawText (noItemsMessage,
  58204. 0, 0, getWidth(), getHeight() / 2,
  58205. Justification::centred, true);
  58206. }
  58207. }
  58208. int getBestHeight (int maxHeight)
  58209. {
  58210. return getRowHeight() * jlimit (2, jmax (2, maxHeight / getRowHeight()),
  58211. getNumRows())
  58212. + getOutlineThickness() * 2;
  58213. }
  58214. juce_UseDebuggingNewOperator
  58215. private:
  58216. const AudioIODeviceType::DeviceSetupDetails setup;
  58217. const BoxType type;
  58218. const String noItemsMessage;
  58219. StringArray items;
  58220. void flipEnablement (const int row)
  58221. {
  58222. jassert (type == audioInputType || type == audioOutputType);
  58223. if (((unsigned int) row) < (unsigned int) items.size())
  58224. {
  58225. AudioDeviceManager::AudioDeviceSetup config;
  58226. setup.manager->getAudioDeviceSetup (config);
  58227. if (setup.useStereoPairs)
  58228. {
  58229. BitArray bits;
  58230. BitArray& original = (type == audioInputType ? config.inputChannels
  58231. : config.outputChannels);
  58232. int i;
  58233. for (i = 0; i < 256; i += 2)
  58234. bits.setBit (i / 2, original [i] || original [i + 1]);
  58235. if (type == audioInputType)
  58236. {
  58237. config.useDefaultInputChannels = false;
  58238. flipBit (bits, row, setup.minNumInputChannels / 2, setup.maxNumInputChannels / 2);
  58239. }
  58240. else
  58241. {
  58242. config.useDefaultOutputChannels = false;
  58243. flipBit (bits, row, setup.minNumOutputChannels / 2, setup.maxNumOutputChannels / 2);
  58244. }
  58245. for (i = 0; i < 256; ++i)
  58246. original.setBit (i, bits [i / 2]);
  58247. }
  58248. else
  58249. {
  58250. if (type == audioInputType)
  58251. {
  58252. config.useDefaultInputChannels = false;
  58253. flipBit (config.inputChannels, row, setup.minNumInputChannels, setup.maxNumInputChannels);
  58254. }
  58255. else
  58256. {
  58257. config.useDefaultOutputChannels = false;
  58258. flipBit (config.outputChannels, row, setup.minNumOutputChannels, setup.maxNumOutputChannels);
  58259. }
  58260. }
  58261. String error (setup.manager->setAudioDeviceSetup (config, true));
  58262. if (! error.isEmpty())
  58263. {
  58264. //xxx
  58265. }
  58266. }
  58267. }
  58268. static void flipBit (BitArray& chans, int index, int minNumber, int maxNumber)
  58269. {
  58270. const int numActive = chans.countNumberOfSetBits();
  58271. if (chans [index])
  58272. {
  58273. if (numActive > minNumber)
  58274. chans.setBit (index, false);
  58275. }
  58276. else
  58277. {
  58278. if (numActive >= maxNumber)
  58279. {
  58280. const int firstActiveChan = chans.findNextSetBit();
  58281. chans.setBit (index > firstActiveChan
  58282. ? firstActiveChan : chans.getHighestBit(),
  58283. false);
  58284. }
  58285. chans.setBit (index, true);
  58286. }
  58287. }
  58288. int getTickX() const
  58289. {
  58290. return getRowHeight() + 5;
  58291. }
  58292. ChannelSelectorListBox (const ChannelSelectorListBox&);
  58293. ChannelSelectorListBox& operator= (const ChannelSelectorListBox&);
  58294. };
  58295. private:
  58296. ChannelSelectorListBox* inputChanList;
  58297. ChannelSelectorListBox* outputChanList;
  58298. AudioDeviceSettingsPanel (const AudioDeviceSettingsPanel&);
  58299. AudioDeviceSettingsPanel& operator= (const AudioDeviceSettingsPanel&);
  58300. };
  58301. AudioDeviceSelectorComponent::AudioDeviceSelectorComponent (AudioDeviceManager& deviceManager_,
  58302. const int minInputChannels_,
  58303. const int maxInputChannels_,
  58304. const int minOutputChannels_,
  58305. const int maxOutputChannels_,
  58306. const bool showMidiInputOptions,
  58307. const bool showMidiOutputSelector,
  58308. const bool showChannelsAsStereoPairs_,
  58309. const bool hideAdvancedOptionsWithButton_)
  58310. : deviceManager (deviceManager_),
  58311. deviceTypeDropDown (0),
  58312. deviceTypeDropDownLabel (0),
  58313. audioDeviceSettingsComp (0),
  58314. minOutputChannels (minOutputChannels_),
  58315. maxOutputChannels (maxOutputChannels_),
  58316. minInputChannels (minInputChannels_),
  58317. maxInputChannels (maxInputChannels_),
  58318. showChannelsAsStereoPairs (showChannelsAsStereoPairs_),
  58319. hideAdvancedOptionsWithButton (hideAdvancedOptionsWithButton_)
  58320. {
  58321. jassert (minOutputChannels >= 0 && minOutputChannels <= maxOutputChannels);
  58322. jassert (minInputChannels >= 0 && minInputChannels <= maxInputChannels);
  58323. if (deviceManager_.getAvailableDeviceTypes().size() > 1)
  58324. {
  58325. deviceTypeDropDown = new ComboBox (String::empty);
  58326. for (int i = 0; i < deviceManager_.getAvailableDeviceTypes().size(); ++i)
  58327. {
  58328. deviceTypeDropDown
  58329. ->addItem (deviceManager_.getAvailableDeviceTypes().getUnchecked(i)->getTypeName(),
  58330. i + 1);
  58331. }
  58332. addAndMakeVisible (deviceTypeDropDown);
  58333. deviceTypeDropDown->addListener (this);
  58334. deviceTypeDropDownLabel = new Label (String::empty, TRANS ("audio device type:"));
  58335. deviceTypeDropDownLabel->setJustificationType (Justification::centredRight);
  58336. deviceTypeDropDownLabel->attachToComponent (deviceTypeDropDown, true);
  58337. }
  58338. if (showMidiInputOptions)
  58339. {
  58340. addAndMakeVisible (midiInputsList
  58341. = new MidiInputSelectorComponentListBox (deviceManager,
  58342. TRANS("(no midi inputs available)"),
  58343. 0, 0));
  58344. midiInputsLabel = new Label (String::empty, TRANS ("active midi inputs:"));
  58345. midiInputsLabel->setJustificationType (Justification::topRight);
  58346. midiInputsLabel->attachToComponent (midiInputsList, true);
  58347. }
  58348. else
  58349. {
  58350. midiInputsList = 0;
  58351. midiInputsLabel = 0;
  58352. }
  58353. if (showMidiOutputSelector)
  58354. {
  58355. addAndMakeVisible (midiOutputSelector = new ComboBox (String::empty));
  58356. midiOutputSelector->addListener (this);
  58357. midiOutputLabel = new Label ("lm", TRANS("Midi Output:"));
  58358. midiOutputLabel->attachToComponent (midiOutputSelector, true);
  58359. }
  58360. else
  58361. {
  58362. midiOutputSelector = 0;
  58363. midiOutputLabel = 0;
  58364. }
  58365. deviceManager_.addChangeListener (this);
  58366. changeListenerCallback (0);
  58367. }
  58368. AudioDeviceSelectorComponent::~AudioDeviceSelectorComponent()
  58369. {
  58370. deviceManager.removeChangeListener (this);
  58371. deleteAllChildren();
  58372. }
  58373. void AudioDeviceSelectorComponent::resized()
  58374. {
  58375. const int lx = proportionOfWidth (0.35f);
  58376. const int w = proportionOfWidth (0.4f);
  58377. const int h = 24;
  58378. const int space = 6;
  58379. const int dh = h + space;
  58380. int y = 15;
  58381. if (deviceTypeDropDown != 0)
  58382. {
  58383. deviceTypeDropDown->setBounds (lx, y, proportionOfWidth (0.3f), h);
  58384. y += dh + space * 2;
  58385. }
  58386. if (audioDeviceSettingsComp != 0)
  58387. {
  58388. audioDeviceSettingsComp->setBounds (0, y, getWidth(), audioDeviceSettingsComp->getHeight());
  58389. y += audioDeviceSettingsComp->getHeight() + space;
  58390. }
  58391. if (midiInputsList != 0)
  58392. {
  58393. const int bh = midiInputsList->getBestHeight (jmin (h * 8, getHeight() - y - space - h));
  58394. midiInputsList->setBounds (lx, y, w, bh);
  58395. y += bh + space;
  58396. }
  58397. if (midiOutputSelector != 0)
  58398. midiOutputSelector->setBounds (lx, y, w, h);
  58399. }
  58400. void AudioDeviceSelectorComponent::childBoundsChanged (Component* child)
  58401. {
  58402. if (child == audioDeviceSettingsComp)
  58403. resized();
  58404. }
  58405. void AudioDeviceSelectorComponent::buttonClicked (Button*)
  58406. {
  58407. AudioIODevice* const device = deviceManager.getCurrentAudioDevice();
  58408. if (device != 0 && device->hasControlPanel())
  58409. {
  58410. if (device->showControlPanel())
  58411. deviceManager.restartLastAudioDevice();
  58412. getTopLevelComponent()->toFront (true);
  58413. }
  58414. }
  58415. void AudioDeviceSelectorComponent::comboBoxChanged (ComboBox* comboBoxThatHasChanged)
  58416. {
  58417. if (comboBoxThatHasChanged == deviceTypeDropDown)
  58418. {
  58419. AudioIODeviceType* const type = deviceManager.getAvailableDeviceTypes() [deviceTypeDropDown->getSelectedId() - 1];
  58420. if (type != 0)
  58421. {
  58422. deleteAndZero (audioDeviceSettingsComp);
  58423. deviceManager.setCurrentAudioDeviceType (type->getTypeName(), true);
  58424. changeListenerCallback (0); // needed in case the type hasn't actally changed
  58425. }
  58426. }
  58427. else if (comboBoxThatHasChanged == midiOutputSelector)
  58428. {
  58429. deviceManager.setDefaultMidiOutput (midiOutputSelector->getText());
  58430. }
  58431. }
  58432. void AudioDeviceSelectorComponent::changeListenerCallback (void*)
  58433. {
  58434. if (deviceTypeDropDown != 0)
  58435. {
  58436. deviceTypeDropDown->setText (deviceManager.getCurrentAudioDeviceType(), false);
  58437. }
  58438. if (audioDeviceSettingsComp == 0
  58439. || audioDeviceSettingsCompType != deviceManager.getCurrentAudioDeviceType())
  58440. {
  58441. audioDeviceSettingsCompType = deviceManager.getCurrentAudioDeviceType();
  58442. deleteAndZero (audioDeviceSettingsComp);
  58443. AudioIODeviceType* const type
  58444. = deviceManager.getAvailableDeviceTypes() [deviceTypeDropDown == 0
  58445. ? 0 : deviceTypeDropDown->getSelectedId() - 1];
  58446. if (type != 0)
  58447. {
  58448. AudioIODeviceType::DeviceSetupDetails details;
  58449. details.manager = &deviceManager;
  58450. details.minNumInputChannels = minInputChannels;
  58451. details.maxNumInputChannels = maxInputChannels;
  58452. details.minNumOutputChannels = minOutputChannels;
  58453. details.maxNumOutputChannels = maxOutputChannels;
  58454. details.useStereoPairs = showChannelsAsStereoPairs;
  58455. audioDeviceSettingsComp = new AudioDeviceSettingsPanel (type, details, hideAdvancedOptionsWithButton);
  58456. if (audioDeviceSettingsComp != 0)
  58457. {
  58458. addAndMakeVisible (audioDeviceSettingsComp);
  58459. audioDeviceSettingsComp->resized();
  58460. }
  58461. }
  58462. }
  58463. if (midiInputsList != 0)
  58464. {
  58465. midiInputsList->updateContent();
  58466. midiInputsList->repaint();
  58467. }
  58468. if (midiOutputSelector != 0)
  58469. {
  58470. midiOutputSelector->clear();
  58471. const StringArray midiOuts (MidiOutput::getDevices());
  58472. midiOutputSelector->addItem (TRANS("<< none >>"), -1);
  58473. midiOutputSelector->addSeparator();
  58474. for (int i = 0; i < midiOuts.size(); ++i)
  58475. midiOutputSelector->addItem (midiOuts[i], i + 1);
  58476. int current = -1;
  58477. if (deviceManager.getDefaultMidiOutput() != 0)
  58478. current = 1 + midiOuts.indexOf (deviceManager.getDefaultMidiOutputName());
  58479. midiOutputSelector->setSelectedId (current, true);
  58480. }
  58481. resized();
  58482. }
  58483. END_JUCE_NAMESPACE
  58484. /*** End of inlined file: juce_AudioDeviceSelectorComponent.cpp ***/
  58485. /*** Start of inlined file: juce_BubbleComponent.cpp ***/
  58486. BEGIN_JUCE_NAMESPACE
  58487. BubbleComponent::BubbleComponent()
  58488. : side (0),
  58489. allowablePlacements (above | below | left | right),
  58490. arrowTipX (0.0f),
  58491. arrowTipY (0.0f)
  58492. {
  58493. setInterceptsMouseClicks (false, false);
  58494. shadow.setShadowProperties (5.0f, 0.35f, 0, 0);
  58495. setComponentEffect (&shadow);
  58496. }
  58497. BubbleComponent::~BubbleComponent()
  58498. {
  58499. }
  58500. void BubbleComponent::paint (Graphics& g)
  58501. {
  58502. int x = content.getX();
  58503. int y = content.getY();
  58504. int w = content.getWidth();
  58505. int h = content.getHeight();
  58506. int cw, ch;
  58507. getContentSize (cw, ch);
  58508. if (side == 3)
  58509. x += w - cw;
  58510. else if (side != 1)
  58511. x += (w - cw) / 2;
  58512. w = cw;
  58513. if (side == 2)
  58514. y += h - ch;
  58515. else if (side != 0)
  58516. y += (h - ch) / 2;
  58517. h = ch;
  58518. getLookAndFeel().drawBubble (g, arrowTipX, arrowTipY,
  58519. (float) x, (float) y,
  58520. (float) w, (float) h);
  58521. const int cx = x + (w - cw) / 2;
  58522. const int cy = y + (h - ch) / 2;
  58523. const int indent = 3;
  58524. g.setOrigin (cx + indent, cy + indent);
  58525. g.reduceClipRegion (0, 0, cw - indent * 2, ch - indent * 2);
  58526. paintContent (g, cw - indent * 2, ch - indent * 2);
  58527. }
  58528. void BubbleComponent::setAllowedPlacement (const int newPlacement)
  58529. {
  58530. allowablePlacements = newPlacement;
  58531. }
  58532. void BubbleComponent::setPosition (Component* componentToPointTo)
  58533. {
  58534. jassert (componentToPointTo->isValidComponent());
  58535. Point<int> pos;
  58536. if (getParentComponent() != 0)
  58537. pos = componentToPointTo->relativePositionToOtherComponent (getParentComponent(), pos);
  58538. else
  58539. pos = componentToPointTo->relativePositionToGlobal (pos);
  58540. setPosition (Rectangle<int> (pos.getX(), pos.getY(), componentToPointTo->getWidth(), componentToPointTo->getHeight()));
  58541. }
  58542. void BubbleComponent::setPosition (const int arrowTipX_,
  58543. const int arrowTipY_)
  58544. {
  58545. setPosition (Rectangle<int> (arrowTipX_, arrowTipY_, 1, 1));
  58546. }
  58547. void BubbleComponent::setPosition (const Rectangle<int>& rectangleToPointTo)
  58548. {
  58549. Rectangle<int> availableSpace;
  58550. if (getParentComponent() != 0)
  58551. {
  58552. availableSpace.setSize (getParentComponent()->getWidth(),
  58553. getParentComponent()->getHeight());
  58554. }
  58555. else
  58556. {
  58557. availableSpace = getParentMonitorArea();
  58558. }
  58559. int x = 0;
  58560. int y = 0;
  58561. int w = 150;
  58562. int h = 30;
  58563. getContentSize (w, h);
  58564. w += 30;
  58565. h += 30;
  58566. const float edgeIndent = 2.0f;
  58567. const int arrowLength = jmin (10, h / 3, w / 3);
  58568. int spaceAbove = ((allowablePlacements & above) != 0) ? jmax (0, rectangleToPointTo.getY() - availableSpace.getY()) : -1;
  58569. int spaceBelow = ((allowablePlacements & below) != 0) ? jmax (0, availableSpace.getBottom() - rectangleToPointTo.getBottom()) : -1;
  58570. int spaceLeft = ((allowablePlacements & left) != 0) ? jmax (0, rectangleToPointTo.getX() - availableSpace.getX()) : -1;
  58571. int spaceRight = ((allowablePlacements & right) != 0) ? jmax (0, availableSpace.getRight() - rectangleToPointTo.getRight()) : -1;
  58572. // look at whether the component is elongated, and if so, try to position next to its longer dimension.
  58573. if (rectangleToPointTo.getWidth() > rectangleToPointTo.getHeight() * 2
  58574. && (spaceAbove > h + 20 || spaceBelow > h + 20))
  58575. {
  58576. spaceLeft = spaceRight = 0;
  58577. }
  58578. else if (rectangleToPointTo.getWidth() < rectangleToPointTo.getHeight() / 2
  58579. && (spaceLeft > w + 20 || spaceRight > w + 20))
  58580. {
  58581. spaceAbove = spaceBelow = 0;
  58582. }
  58583. if (jmax (spaceAbove, spaceBelow) >= jmax (spaceLeft, spaceRight))
  58584. {
  58585. x = rectangleToPointTo.getX() + (rectangleToPointTo.getWidth() - w) / 2;
  58586. arrowTipX = w * 0.5f;
  58587. content.setSize (w, h - arrowLength);
  58588. if (spaceAbove >= spaceBelow)
  58589. {
  58590. // above
  58591. y = rectangleToPointTo.getY() - h;
  58592. content.setPosition (0, 0);
  58593. arrowTipY = h - edgeIndent;
  58594. side = 2;
  58595. }
  58596. else
  58597. {
  58598. // below
  58599. y = rectangleToPointTo.getBottom();
  58600. content.setPosition (0, arrowLength);
  58601. arrowTipY = edgeIndent;
  58602. side = 0;
  58603. }
  58604. }
  58605. else
  58606. {
  58607. y = rectangleToPointTo.getY() + (rectangleToPointTo.getHeight() - h) / 2;
  58608. arrowTipY = h * 0.5f;
  58609. content.setSize (w - arrowLength, h);
  58610. if (spaceLeft > spaceRight)
  58611. {
  58612. // on the left
  58613. x = rectangleToPointTo.getX() - w;
  58614. content.setPosition (0, 0);
  58615. arrowTipX = w - edgeIndent;
  58616. side = 3;
  58617. }
  58618. else
  58619. {
  58620. // on the right
  58621. x = rectangleToPointTo.getRight();
  58622. content.setPosition (arrowLength, 0);
  58623. arrowTipX = edgeIndent;
  58624. side = 1;
  58625. }
  58626. }
  58627. setBounds (x, y, w, h);
  58628. }
  58629. END_JUCE_NAMESPACE
  58630. /*** End of inlined file: juce_BubbleComponent.cpp ***/
  58631. /*** Start of inlined file: juce_BubbleMessageComponent.cpp ***/
  58632. BEGIN_JUCE_NAMESPACE
  58633. BubbleMessageComponent::BubbleMessageComponent (int fadeOutLengthMs)
  58634. : fadeOutLength (fadeOutLengthMs),
  58635. deleteAfterUse (false)
  58636. {
  58637. }
  58638. BubbleMessageComponent::~BubbleMessageComponent()
  58639. {
  58640. fadeOutComponent (fadeOutLength);
  58641. }
  58642. void BubbleMessageComponent::showAt (int x, int y,
  58643. const String& text,
  58644. const int numMillisecondsBeforeRemoving,
  58645. const bool removeWhenMouseClicked,
  58646. const bool deleteSelfAfterUse)
  58647. {
  58648. textLayout.clear();
  58649. textLayout.setText (text, Font (14.0f));
  58650. textLayout.layout (256, Justification::centredLeft, true);
  58651. setPosition (x, y);
  58652. init (numMillisecondsBeforeRemoving, removeWhenMouseClicked, deleteSelfAfterUse);
  58653. }
  58654. void BubbleMessageComponent::showAt (Component* const component,
  58655. const String& text,
  58656. const int numMillisecondsBeforeRemoving,
  58657. const bool removeWhenMouseClicked,
  58658. const bool deleteSelfAfterUse)
  58659. {
  58660. textLayout.clear();
  58661. textLayout.setText (text, Font (14.0f));
  58662. textLayout.layout (256, Justification::centredLeft, true);
  58663. setPosition (component);
  58664. init (numMillisecondsBeforeRemoving, removeWhenMouseClicked, deleteSelfAfterUse);
  58665. }
  58666. void BubbleMessageComponent::init (const int numMillisecondsBeforeRemoving,
  58667. const bool removeWhenMouseClicked,
  58668. const bool deleteSelfAfterUse)
  58669. {
  58670. setVisible (true);
  58671. deleteAfterUse = deleteSelfAfterUse;
  58672. if (numMillisecondsBeforeRemoving > 0)
  58673. expiryTime = Time::getMillisecondCounter() + numMillisecondsBeforeRemoving;
  58674. else
  58675. expiryTime = 0;
  58676. startTimer (77);
  58677. mouseClickCounter = Desktop::getInstance().getMouseButtonClickCounter();
  58678. if (! (removeWhenMouseClicked && isShowing()))
  58679. mouseClickCounter += 0xfffff;
  58680. repaint();
  58681. }
  58682. void BubbleMessageComponent::getContentSize (int& w, int& h)
  58683. {
  58684. w = textLayout.getWidth() + 16;
  58685. h = textLayout.getHeight() + 16;
  58686. }
  58687. void BubbleMessageComponent::paintContent (Graphics& g, int w, int h)
  58688. {
  58689. g.setColour (findColour (TooltipWindow::textColourId));
  58690. textLayout.drawWithin (g, 0, 0, w, h, Justification::centred);
  58691. }
  58692. void BubbleMessageComponent::timerCallback()
  58693. {
  58694. if (Desktop::getInstance().getMouseButtonClickCounter() > mouseClickCounter)
  58695. {
  58696. stopTimer();
  58697. setVisible (false);
  58698. if (deleteAfterUse)
  58699. delete this;
  58700. }
  58701. else if (expiryTime != 0 && Time::getMillisecondCounter() > expiryTime)
  58702. {
  58703. stopTimer();
  58704. fadeOutComponent (fadeOutLength);
  58705. if (deleteAfterUse)
  58706. delete this;
  58707. }
  58708. }
  58709. END_JUCE_NAMESPACE
  58710. /*** End of inlined file: juce_BubbleMessageComponent.cpp ***/
  58711. /*** Start of inlined file: juce_ColourSelector.cpp ***/
  58712. BEGIN_JUCE_NAMESPACE
  58713. static const int swatchesPerRow = 8;
  58714. static const int swatchHeight = 22;
  58715. class ColourComponentSlider : public Slider
  58716. {
  58717. public:
  58718. ColourComponentSlider (const String& name)
  58719. : Slider (name)
  58720. {
  58721. setRange (0.0, 255.0, 1.0);
  58722. }
  58723. ~ColourComponentSlider()
  58724. {
  58725. }
  58726. const String getTextFromValue (double value)
  58727. {
  58728. return String::toHexString ((int) value).toUpperCase().paddedLeft ('0', 2);
  58729. }
  58730. double getValueFromText (const String& text)
  58731. {
  58732. return (double) text.getHexValue32();
  58733. }
  58734. private:
  58735. ColourComponentSlider (const ColourComponentSlider&);
  58736. ColourComponentSlider& operator= (const ColourComponentSlider&);
  58737. };
  58738. class ColourSpaceMarker : public Component
  58739. {
  58740. public:
  58741. ColourSpaceMarker()
  58742. {
  58743. setInterceptsMouseClicks (false, false);
  58744. }
  58745. ~ColourSpaceMarker()
  58746. {
  58747. }
  58748. void paint (Graphics& g)
  58749. {
  58750. g.setColour (Colour::greyLevel (0.1f));
  58751. g.drawEllipse (1.0f, 1.0f, getWidth() - 2.0f, getHeight() - 2.0f, 1.0f);
  58752. g.setColour (Colour::greyLevel (0.9f));
  58753. g.drawEllipse (2.0f, 2.0f, getWidth() - 4.0f, getHeight() - 4.0f, 1.0f);
  58754. }
  58755. private:
  58756. ColourSpaceMarker (const ColourSpaceMarker&);
  58757. ColourSpaceMarker& operator= (const ColourSpaceMarker&);
  58758. };
  58759. class ColourSpaceView : public Component
  58760. {
  58761. ColourSelector* const owner;
  58762. float& h;
  58763. float& s;
  58764. float& v;
  58765. float lastHue;
  58766. ColourSpaceMarker* marker;
  58767. const int edge;
  58768. public:
  58769. ColourSpaceView (ColourSelector* owner_,
  58770. float& h_, float& s_, float& v_,
  58771. const int edgeSize)
  58772. : owner (owner_),
  58773. h (h_), s (s_), v (v_),
  58774. lastHue (0.0f),
  58775. edge (edgeSize)
  58776. {
  58777. addAndMakeVisible (marker = new ColourSpaceMarker());
  58778. setMouseCursor (MouseCursor::CrosshairCursor);
  58779. }
  58780. ~ColourSpaceView()
  58781. {
  58782. deleteAllChildren();
  58783. }
  58784. void paint (Graphics& g)
  58785. {
  58786. if (colours == 0)
  58787. {
  58788. const int width = getWidth() / 2;
  58789. const int height = getHeight() / 2;
  58790. colours = new Image (Image::RGB, width, height, false);
  58791. Image::BitmapData pixels (*colours, 0, 0, width, height, true);
  58792. for (int y = 0; y < height; ++y)
  58793. {
  58794. const float v = 1.0f - y / (float) height;
  58795. for (int x = 0; x < width; ++x)
  58796. {
  58797. const float s = x / (float) width;
  58798. const Colour col (h, s, v, 1.0f);
  58799. PixelRGB* const pix = (PixelRGB*) pixels.getPixelPointer (x, y);
  58800. pix->set (col.getPixelARGB());
  58801. }
  58802. }
  58803. }
  58804. g.setOpacity (1.0f);
  58805. g.drawImage (colours, edge, edge, getWidth() - edge * 2, getHeight() - edge * 2,
  58806. 0, 0, colours->getWidth(), colours->getHeight());
  58807. }
  58808. void mouseDown (const MouseEvent& e)
  58809. {
  58810. mouseDrag (e);
  58811. }
  58812. void mouseDrag (const MouseEvent& e)
  58813. {
  58814. const float s = (e.x - edge) / (float) (getWidth() - edge * 2);
  58815. const float v = 1.0f - (e.y - edge) / (float) (getHeight() - edge * 2);
  58816. owner->setSV (s, v);
  58817. }
  58818. void updateIfNeeded()
  58819. {
  58820. if (lastHue != h)
  58821. {
  58822. lastHue = h;
  58823. colours = 0;
  58824. repaint();
  58825. }
  58826. updateMarker();
  58827. }
  58828. void resized()
  58829. {
  58830. colours = 0;
  58831. updateMarker();
  58832. }
  58833. private:
  58834. ScopedPointer <Image> colours;
  58835. void updateMarker() const throw()
  58836. {
  58837. marker->setBounds (roundToInt ((getWidth() - edge * 2) * s),
  58838. roundToInt ((getHeight() - edge * 2) * (1.0f - v)),
  58839. edge * 2, edge * 2);
  58840. }
  58841. ColourSpaceView (const ColourSpaceView&);
  58842. ColourSpaceView& operator= (const ColourSpaceView&);
  58843. };
  58844. class HueSelectorMarker : public Component
  58845. {
  58846. public:
  58847. HueSelectorMarker()
  58848. {
  58849. setInterceptsMouseClicks (false, false);
  58850. }
  58851. ~HueSelectorMarker()
  58852. {
  58853. }
  58854. void paint (Graphics& g)
  58855. {
  58856. Path p;
  58857. p.addTriangle (1.0f, 1.0f,
  58858. getWidth() * 0.3f, getHeight() * 0.5f,
  58859. 1.0f, getHeight() - 1.0f);
  58860. p.addTriangle (getWidth() - 1.0f, 1.0f,
  58861. getWidth() * 0.7f, getHeight() * 0.5f,
  58862. getWidth() - 1.0f, getHeight() - 1.0f);
  58863. g.setColour (Colours::white.withAlpha (0.75f));
  58864. g.fillPath (p);
  58865. g.setColour (Colours::black.withAlpha (0.75f));
  58866. g.strokePath (p, PathStrokeType (1.2f));
  58867. }
  58868. private:
  58869. HueSelectorMarker (const HueSelectorMarker&);
  58870. HueSelectorMarker& operator= (const HueSelectorMarker&);
  58871. };
  58872. class HueSelectorComp : public Component
  58873. {
  58874. public:
  58875. HueSelectorComp (ColourSelector* owner_,
  58876. float& h_, float& s_, float& v_,
  58877. const int edgeSize)
  58878. : owner (owner_),
  58879. h (h_), s (s_), v (v_),
  58880. lastHue (0.0f),
  58881. edge (edgeSize)
  58882. {
  58883. addAndMakeVisible (marker = new HueSelectorMarker());
  58884. }
  58885. ~HueSelectorComp()
  58886. {
  58887. deleteAllChildren();
  58888. }
  58889. void paint (Graphics& g)
  58890. {
  58891. const float yScale = 1.0f / (getHeight() - edge * 2);
  58892. const Rectangle<int> clip (g.getClipBounds());
  58893. for (int y = jmin (clip.getBottom(), getHeight() - edge); --y >= jmax (edge, clip.getY());)
  58894. {
  58895. g.setColour (Colour ((y - edge) * yScale, 1.0f, 1.0f, 1.0f));
  58896. g.fillRect (edge, y, getWidth() - edge * 2, 1);
  58897. }
  58898. }
  58899. void resized()
  58900. {
  58901. marker->setBounds (0, roundToInt ((getHeight() - edge * 2) * h),
  58902. getWidth(), edge * 2);
  58903. }
  58904. void mouseDown (const MouseEvent& e)
  58905. {
  58906. mouseDrag (e);
  58907. }
  58908. void mouseDrag (const MouseEvent& e)
  58909. {
  58910. const float hue = (e.y - edge) / (float) (getHeight() - edge * 2);
  58911. owner->setHue (hue);
  58912. }
  58913. void updateIfNeeded()
  58914. {
  58915. resized();
  58916. }
  58917. private:
  58918. ColourSelector* const owner;
  58919. float& h;
  58920. float& s;
  58921. float& v;
  58922. float lastHue;
  58923. HueSelectorMarker* marker;
  58924. const int edge;
  58925. HueSelectorComp (const HueSelectorComp&);
  58926. HueSelectorComp& operator= (const HueSelectorComp&);
  58927. };
  58928. class ColourSelector::SwatchComponent : public Component
  58929. {
  58930. public:
  58931. SwatchComponent (ColourSelector* owner_, int index_)
  58932. : owner (owner_),
  58933. index (index_)
  58934. {
  58935. }
  58936. ~SwatchComponent()
  58937. {
  58938. }
  58939. void paint (Graphics& g)
  58940. {
  58941. const Colour colour (owner->getSwatchColour (index));
  58942. g.fillCheckerBoard (0, 0, getWidth(), getHeight(),
  58943. 6, 6,
  58944. Colour (0xffdddddd).overlaidWith (colour),
  58945. Colour (0xffffffff).overlaidWith (colour));
  58946. }
  58947. void mouseDown (const MouseEvent&)
  58948. {
  58949. PopupMenu m;
  58950. m.addItem (1, TRANS("Use this swatch as the current colour"));
  58951. m.addSeparator();
  58952. m.addItem (2, TRANS("Set this swatch to the current colour"));
  58953. const int r = m.showAt (this);
  58954. if (r == 1)
  58955. {
  58956. owner->setCurrentColour (owner->getSwatchColour (index));
  58957. }
  58958. else if (r == 2)
  58959. {
  58960. if (owner->getSwatchColour (index) != owner->getCurrentColour())
  58961. {
  58962. owner->setSwatchColour (index, owner->getCurrentColour());
  58963. repaint();
  58964. }
  58965. }
  58966. }
  58967. private:
  58968. ColourSelector* const owner;
  58969. const int index;
  58970. SwatchComponent (const SwatchComponent&);
  58971. SwatchComponent& operator= (const SwatchComponent&);
  58972. };
  58973. ColourSelector::ColourSelector (const int flags_,
  58974. const int edgeGap_,
  58975. const int gapAroundColourSpaceComponent)
  58976. : colour (Colours::white),
  58977. flags (flags_),
  58978. topSpace (0),
  58979. edgeGap (edgeGap_)
  58980. {
  58981. // not much point having a selector with no components in it!
  58982. jassert ((flags_ & (showColourAtTop | showSliders | showColourspace)) != 0);
  58983. updateHSV();
  58984. if ((flags & showSliders) != 0)
  58985. {
  58986. addAndMakeVisible (sliders[0] = new ColourComponentSlider (TRANS ("red")));
  58987. addAndMakeVisible (sliders[1] = new ColourComponentSlider (TRANS ("green")));
  58988. addAndMakeVisible (sliders[2] = new ColourComponentSlider (TRANS ("blue")));
  58989. addChildComponent (sliders[3] = new ColourComponentSlider (TRANS ("alpha")));
  58990. sliders[3]->setVisible ((flags & showAlphaChannel) != 0);
  58991. for (int i = 4; --i >= 0;)
  58992. sliders[i]->addListener (this);
  58993. }
  58994. else
  58995. {
  58996. zeromem (sliders, sizeof (sliders));
  58997. }
  58998. if ((flags & showColourspace) != 0)
  58999. {
  59000. addAndMakeVisible (colourSpace = new ColourSpaceView (this, h, s, v, gapAroundColourSpaceComponent));
  59001. addAndMakeVisible (hueSelector = new HueSelectorComp (this, h, s, v, gapAroundColourSpaceComponent));
  59002. }
  59003. else
  59004. {
  59005. colourSpace = 0;
  59006. hueSelector = 0;
  59007. }
  59008. update();
  59009. }
  59010. ColourSelector::~ColourSelector()
  59011. {
  59012. dispatchPendingMessages();
  59013. swatchComponents.clear();
  59014. deleteAllChildren();
  59015. }
  59016. const Colour ColourSelector::getCurrentColour() const
  59017. {
  59018. return ((flags & showAlphaChannel) != 0) ? colour
  59019. : colour.withAlpha ((uint8) 0xff);
  59020. }
  59021. void ColourSelector::setCurrentColour (const Colour& c)
  59022. {
  59023. if (c != colour)
  59024. {
  59025. colour = ((flags & showAlphaChannel) != 0) ? c : c.withAlpha ((uint8) 0xff);
  59026. updateHSV();
  59027. update();
  59028. }
  59029. }
  59030. void ColourSelector::setHue (float newH)
  59031. {
  59032. newH = jlimit (0.0f, 1.0f, newH);
  59033. if (h != newH)
  59034. {
  59035. h = newH;
  59036. colour = Colour (h, s, v, colour.getFloatAlpha());
  59037. update();
  59038. }
  59039. }
  59040. void ColourSelector::setSV (float newS, float newV)
  59041. {
  59042. newS = jlimit (0.0f, 1.0f, newS);
  59043. newV = jlimit (0.0f, 1.0f, newV);
  59044. if (s != newS || v != newV)
  59045. {
  59046. s = newS;
  59047. v = newV;
  59048. colour = Colour (h, s, v, colour.getFloatAlpha());
  59049. update();
  59050. }
  59051. }
  59052. void ColourSelector::updateHSV()
  59053. {
  59054. colour.getHSB (h, s, v);
  59055. }
  59056. void ColourSelector::update()
  59057. {
  59058. if (sliders[0] != 0)
  59059. {
  59060. sliders[0]->setValue ((int) colour.getRed());
  59061. sliders[1]->setValue ((int) colour.getGreen());
  59062. sliders[2]->setValue ((int) colour.getBlue());
  59063. sliders[3]->setValue ((int) colour.getAlpha());
  59064. }
  59065. if (colourSpace != 0)
  59066. {
  59067. ((ColourSpaceView*) colourSpace)->updateIfNeeded();
  59068. ((HueSelectorComp*) hueSelector)->updateIfNeeded();
  59069. }
  59070. if ((flags & showColourAtTop) != 0)
  59071. repaint (0, edgeGap, getWidth(), topSpace - edgeGap);
  59072. sendChangeMessage (this);
  59073. }
  59074. void ColourSelector::paint (Graphics& g)
  59075. {
  59076. g.fillAll (findColour (backgroundColourId));
  59077. if ((flags & showColourAtTop) != 0)
  59078. {
  59079. const Colour colour (getCurrentColour());
  59080. g.fillCheckerBoard (edgeGap, edgeGap, getWidth() - edgeGap - edgeGap, topSpace - edgeGap - edgeGap,
  59081. 10, 10,
  59082. Colour (0xffdddddd).overlaidWith (colour),
  59083. Colour (0xffffffff).overlaidWith (colour));
  59084. g.setColour (Colours::white.overlaidWith (colour).contrasting());
  59085. g.setFont (14.0f, true);
  59086. g.drawText (colour.toDisplayString ((flags & showAlphaChannel) != 0),
  59087. 0, edgeGap, getWidth(), topSpace - edgeGap * 2,
  59088. Justification::centred, false);
  59089. }
  59090. if ((flags & showSliders) != 0)
  59091. {
  59092. g.setColour (findColour (labelTextColourId));
  59093. g.setFont (11.0f);
  59094. for (int i = 4; --i >= 0;)
  59095. {
  59096. if (sliders[i]->isVisible())
  59097. g.drawText (sliders[i]->getName() + T(":"),
  59098. 0, sliders[i]->getY(),
  59099. sliders[i]->getX() - 8, sliders[i]->getHeight(),
  59100. Justification::centredRight, false);
  59101. }
  59102. }
  59103. }
  59104. void ColourSelector::resized()
  59105. {
  59106. const int numSliders = ((flags & showAlphaChannel) != 0) ? 4 : 3;
  59107. const int numSwatches = getNumSwatches();
  59108. const int swatchSpace = numSwatches > 0 ? edgeGap + swatchHeight * ((numSwatches + 7) / swatchesPerRow) : 0;
  59109. const int sliderSpace = ((flags & showSliders) != 0) ? jmin (22 * numSliders + edgeGap, proportionOfHeight (0.3f)) : 0;
  59110. topSpace = ((flags & showColourAtTop) != 0) ? jmin (30 + edgeGap * 2, proportionOfHeight (0.2f)) : edgeGap;
  59111. int y = topSpace;
  59112. if ((flags & showColourspace) != 0)
  59113. {
  59114. const int hueWidth = jmin (50, proportionOfWidth (0.15f));
  59115. colourSpace->setBounds (edgeGap, y,
  59116. getWidth() - hueWidth - edgeGap - 4,
  59117. getHeight() - topSpace - sliderSpace - swatchSpace - edgeGap);
  59118. hueSelector->setBounds (colourSpace->getRight() + 4, y,
  59119. getWidth() - edgeGap - (colourSpace->getRight() + 4),
  59120. colourSpace->getHeight());
  59121. y = getHeight() - sliderSpace - swatchSpace - edgeGap;
  59122. }
  59123. if ((flags & showSliders) != 0)
  59124. {
  59125. const int sliderHeight = jmax (4, sliderSpace / numSliders);
  59126. for (int i = 0; i < numSliders; ++i)
  59127. {
  59128. sliders[i]->setBounds (proportionOfWidth (0.2f), y,
  59129. proportionOfWidth (0.72f), sliderHeight - 2);
  59130. y += sliderHeight;
  59131. }
  59132. }
  59133. if (numSwatches > 0)
  59134. {
  59135. const int startX = 8;
  59136. const int xGap = 4;
  59137. const int yGap = 4;
  59138. const int swatchWidth = (getWidth() - startX * 2) / swatchesPerRow;
  59139. y += edgeGap;
  59140. if (swatchComponents.size() != numSwatches)
  59141. {
  59142. swatchComponents.clear();
  59143. for (int i = 0; i < numSwatches; ++i)
  59144. {
  59145. SwatchComponent* const sc = new SwatchComponent (this, i);
  59146. swatchComponents.add (sc);
  59147. addAndMakeVisible (sc);
  59148. }
  59149. }
  59150. int x = startX;
  59151. for (int i = 0; i < swatchComponents.size(); ++i)
  59152. {
  59153. SwatchComponent* const sc = swatchComponents.getUnchecked(i);
  59154. sc->setBounds (x + xGap / 2,
  59155. y + yGap / 2,
  59156. swatchWidth - xGap,
  59157. swatchHeight - yGap);
  59158. if (((i + 1) % swatchesPerRow) == 0)
  59159. {
  59160. x = startX;
  59161. y += swatchHeight;
  59162. }
  59163. else
  59164. {
  59165. x += swatchWidth;
  59166. }
  59167. }
  59168. }
  59169. }
  59170. void ColourSelector::sliderValueChanged (Slider*)
  59171. {
  59172. if (sliders[0] != 0)
  59173. setCurrentColour (Colour ((uint8) sliders[0]->getValue(),
  59174. (uint8) sliders[1]->getValue(),
  59175. (uint8) sliders[2]->getValue(),
  59176. (uint8) sliders[3]->getValue()));
  59177. }
  59178. int ColourSelector::getNumSwatches() const
  59179. {
  59180. return 0;
  59181. }
  59182. const Colour ColourSelector::getSwatchColour (const int) const
  59183. {
  59184. jassertfalse // if you've overridden getNumSwatches(), you also need to implement this method
  59185. return Colours::black;
  59186. }
  59187. void ColourSelector::setSwatchColour (const int, const Colour&) const
  59188. {
  59189. jassertfalse // if you've overridden getNumSwatches(), you also need to implement this method
  59190. }
  59191. END_JUCE_NAMESPACE
  59192. /*** End of inlined file: juce_ColourSelector.cpp ***/
  59193. /*** Start of inlined file: juce_DropShadower.cpp ***/
  59194. BEGIN_JUCE_NAMESPACE
  59195. class ShadowWindow : public Component
  59196. {
  59197. Component* owner;
  59198. Image** shadowImageSections;
  59199. const int type; // 0 = left, 1 = right, 2 = top, 3 = bottom. left + right are full-height
  59200. public:
  59201. ShadowWindow (Component* const owner_,
  59202. const int type_,
  59203. Image** const shadowImageSections_)
  59204. : owner (owner_),
  59205. shadowImageSections (shadowImageSections_),
  59206. type (type_)
  59207. {
  59208. setInterceptsMouseClicks (false, false);
  59209. if (owner_->isOnDesktop())
  59210. {
  59211. setSize (1, 1); // to keep the OS happy by not having zero-size windows
  59212. addToDesktop (ComponentPeer::windowIgnoresMouseClicks
  59213. | ComponentPeer::windowIsTemporary
  59214. | ComponentPeer::windowIgnoresKeyPresses);
  59215. }
  59216. else if (owner_->getParentComponent() != 0)
  59217. {
  59218. owner_->getParentComponent()->addChildComponent (this);
  59219. }
  59220. }
  59221. ~ShadowWindow()
  59222. {
  59223. }
  59224. void paint (Graphics& g)
  59225. {
  59226. Image* const topLeft = shadowImageSections [type * 3];
  59227. Image* const bottomRight = shadowImageSections [type * 3 + 1];
  59228. Image* const filler = shadowImageSections [type * 3 + 2];
  59229. g.setOpacity (1.0f);
  59230. if (type < 2)
  59231. {
  59232. int imH = jmin (topLeft->getHeight(), getHeight() / 2);
  59233. g.drawImage (topLeft,
  59234. 0, 0, topLeft->getWidth(), imH,
  59235. 0, 0, topLeft->getWidth(), imH);
  59236. imH = jmin (bottomRight->getHeight(), getHeight() - getHeight() / 2);
  59237. g.drawImage (bottomRight,
  59238. 0, getHeight() - imH, bottomRight->getWidth(), imH,
  59239. 0, bottomRight->getHeight() - imH, bottomRight->getWidth(), imH);
  59240. g.setTiledImageFill (*filler, 0, 0, 1.0f);
  59241. g.fillRect (0, topLeft->getHeight(), getWidth(), getHeight() - (topLeft->getHeight() + bottomRight->getHeight()));
  59242. }
  59243. else
  59244. {
  59245. int imW = jmin (topLeft->getWidth(), getWidth() / 2);
  59246. g.drawImage (topLeft,
  59247. 0, 0, imW, topLeft->getHeight(),
  59248. 0, 0, imW, topLeft->getHeight());
  59249. imW = jmin (bottomRight->getWidth(), getWidth() - getWidth() / 2);
  59250. g.drawImage (bottomRight,
  59251. getWidth() - imW, 0, imW, bottomRight->getHeight(),
  59252. bottomRight->getWidth() - imW, 0, imW, bottomRight->getHeight());
  59253. g.setTiledImageFill (*filler, 0, 0, 1.0f);
  59254. g.fillRect (topLeft->getWidth(), 0, getWidth() - (topLeft->getWidth() + bottomRight->getWidth()), getHeight());
  59255. }
  59256. }
  59257. void resized()
  59258. {
  59259. repaint(); // (needed for correct repainting)
  59260. }
  59261. private:
  59262. ShadowWindow (const ShadowWindow&);
  59263. ShadowWindow& operator= (const ShadowWindow&);
  59264. };
  59265. DropShadower::DropShadower (const float alpha_,
  59266. const int xOffset_,
  59267. const int yOffset_,
  59268. const float blurRadius_)
  59269. : owner (0),
  59270. numShadows (0),
  59271. shadowEdge (jmax (xOffset_, yOffset_) + (int) blurRadius_),
  59272. xOffset (xOffset_),
  59273. yOffset (yOffset_),
  59274. alpha (alpha_),
  59275. blurRadius (blurRadius_),
  59276. inDestructor (false),
  59277. reentrant (false)
  59278. {
  59279. }
  59280. DropShadower::~DropShadower()
  59281. {
  59282. if (owner != 0)
  59283. owner->removeComponentListener (this);
  59284. inDestructor = true;
  59285. deleteShadowWindows();
  59286. }
  59287. void DropShadower::deleteShadowWindows()
  59288. {
  59289. if (numShadows > 0)
  59290. {
  59291. int i;
  59292. for (i = numShadows; --i >= 0;)
  59293. delete shadowWindows[i];
  59294. for (i = 12; --i >= 0;)
  59295. delete shadowImageSections[i];
  59296. numShadows = 0;
  59297. }
  59298. }
  59299. void DropShadower::setOwner (Component* componentToFollow)
  59300. {
  59301. if (componentToFollow != owner)
  59302. {
  59303. if (owner != 0)
  59304. owner->removeComponentListener (this);
  59305. // (the component can't be null)
  59306. jassert (componentToFollow != 0);
  59307. owner = componentToFollow;
  59308. jassert (owner != 0);
  59309. jassert (owner->isOpaque()); // doesn't work properly for semi-transparent comps!
  59310. owner->addComponentListener (this);
  59311. updateShadows();
  59312. }
  59313. }
  59314. void DropShadower::componentMovedOrResized (Component&, bool /*wasMoved*/, bool /*wasResized*/)
  59315. {
  59316. updateShadows();
  59317. }
  59318. void DropShadower::componentBroughtToFront (Component&)
  59319. {
  59320. bringShadowWindowsToFront();
  59321. }
  59322. void DropShadower::componentChildrenChanged (Component&)
  59323. {
  59324. }
  59325. void DropShadower::componentParentHierarchyChanged (Component&)
  59326. {
  59327. deleteShadowWindows();
  59328. updateShadows();
  59329. }
  59330. void DropShadower::componentVisibilityChanged (Component&)
  59331. {
  59332. updateShadows();
  59333. }
  59334. void DropShadower::updateShadows()
  59335. {
  59336. if (reentrant || inDestructor || (owner == 0))
  59337. return;
  59338. reentrant = true;
  59339. ComponentPeer* const nw = owner->getPeer();
  59340. const bool isOwnerVisible = owner->isVisible()
  59341. && (nw == 0 || ! nw->isMinimised());
  59342. const bool createShadowWindows = numShadows == 0
  59343. && owner->getWidth() > 0
  59344. && owner->getHeight() > 0
  59345. && isOwnerVisible
  59346. && (Desktop::canUseSemiTransparentWindows()
  59347. || owner->getParentComponent() != 0);
  59348. if (createShadowWindows)
  59349. {
  59350. // keep a cached version of the image to save doing the gaussian too often
  59351. String imageId;
  59352. imageId << shadowEdge << T(',')
  59353. << xOffset << T(',')
  59354. << yOffset << T(',')
  59355. << alpha;
  59356. const int hash = imageId.hashCode();
  59357. Image* bigIm = ImageCache::getFromHashCode (hash);
  59358. if (bigIm == 0)
  59359. {
  59360. bigIm = Image::createNativeImage (Image::ARGB, shadowEdge * 5, shadowEdge * 5, true);
  59361. Graphics bigG (*bigIm);
  59362. bigG.setColour (Colours::black.withAlpha (alpha));
  59363. bigG.fillRect (shadowEdge + xOffset,
  59364. shadowEdge + yOffset,
  59365. bigIm->getWidth() - (shadowEdge * 2),
  59366. bigIm->getHeight() - (shadowEdge * 2));
  59367. ImageConvolutionKernel blurKernel (roundToInt (blurRadius * 2.0f));
  59368. blurKernel.createGaussianBlur (blurRadius);
  59369. blurKernel.applyToImage (*bigIm, 0,
  59370. xOffset,
  59371. yOffset,
  59372. bigIm->getWidth(),
  59373. bigIm->getHeight());
  59374. ImageCache::addImageToCache (bigIm, hash);
  59375. }
  59376. const int iw = bigIm->getWidth();
  59377. const int ih = bigIm->getHeight();
  59378. const int shadowEdge2 = shadowEdge * 2;
  59379. setShadowImage (bigIm, 0, shadowEdge, shadowEdge2, 0, 0);
  59380. setShadowImage (bigIm, 1, shadowEdge, shadowEdge2, 0, ih - shadowEdge2);
  59381. setShadowImage (bigIm, 2, shadowEdge, shadowEdge, 0, shadowEdge2);
  59382. setShadowImage (bigIm, 3, shadowEdge, shadowEdge2, iw - shadowEdge, 0);
  59383. setShadowImage (bigIm, 4, shadowEdge, shadowEdge2, iw - shadowEdge, ih - shadowEdge2);
  59384. setShadowImage (bigIm, 5, shadowEdge, shadowEdge, iw - shadowEdge, shadowEdge2);
  59385. setShadowImage (bigIm, 6, shadowEdge, shadowEdge, shadowEdge, 0);
  59386. setShadowImage (bigIm, 7, shadowEdge, shadowEdge, iw - shadowEdge2, 0);
  59387. setShadowImage (bigIm, 8, shadowEdge, shadowEdge, shadowEdge2, 0);
  59388. setShadowImage (bigIm, 9, shadowEdge, shadowEdge, shadowEdge, ih - shadowEdge);
  59389. setShadowImage (bigIm, 10, shadowEdge, shadowEdge, iw - shadowEdge2, ih - shadowEdge);
  59390. setShadowImage (bigIm, 11, shadowEdge, shadowEdge, shadowEdge2, ih - shadowEdge);
  59391. ImageCache::release (bigIm);
  59392. for (int i = 0; i < 4; ++i)
  59393. {
  59394. shadowWindows[numShadows] = new ShadowWindow (owner, i, shadowImageSections);
  59395. ++numShadows;
  59396. }
  59397. }
  59398. if (numShadows > 0)
  59399. {
  59400. for (int i = numShadows; --i >= 0;)
  59401. {
  59402. shadowWindows[i]->setAlwaysOnTop (owner->isAlwaysOnTop());
  59403. shadowWindows[i]->setVisible (isOwnerVisible);
  59404. }
  59405. const int x = owner->getX();
  59406. const int y = owner->getY() - shadowEdge;
  59407. const int w = owner->getWidth();
  59408. const int h = owner->getHeight() + shadowEdge + shadowEdge;
  59409. shadowWindows[0]->setBounds (x - shadowEdge,
  59410. y,
  59411. shadowEdge,
  59412. h);
  59413. shadowWindows[1]->setBounds (x + w,
  59414. y,
  59415. shadowEdge,
  59416. h);
  59417. shadowWindows[2]->setBounds (x,
  59418. y,
  59419. w,
  59420. shadowEdge);
  59421. shadowWindows[3]->setBounds (x,
  59422. owner->getBottom(),
  59423. w,
  59424. shadowEdge);
  59425. }
  59426. reentrant = false;
  59427. if (createShadowWindows)
  59428. bringShadowWindowsToFront();
  59429. }
  59430. void DropShadower::setShadowImage (Image* const src,
  59431. const int num,
  59432. const int w,
  59433. const int h,
  59434. const int sx,
  59435. const int sy)
  59436. {
  59437. shadowImageSections[num] = new Image (Image::ARGB, w, h, true);
  59438. Graphics g (*shadowImageSections[num]);
  59439. g.drawImage (src, 0, 0, w, h, sx, sy, w, h);
  59440. }
  59441. void DropShadower::bringShadowWindowsToFront()
  59442. {
  59443. if (! (inDestructor || reentrant))
  59444. {
  59445. updateShadows();
  59446. reentrant = true;
  59447. for (int i = numShadows; --i >= 0;)
  59448. shadowWindows[i]->toBehind (owner);
  59449. reentrant = false;
  59450. }
  59451. }
  59452. END_JUCE_NAMESPACE
  59453. /*** End of inlined file: juce_DropShadower.cpp ***/
  59454. /*** Start of inlined file: juce_MagnifierComponent.cpp ***/
  59455. BEGIN_JUCE_NAMESPACE
  59456. class MagnifyingPeer : public ComponentPeer
  59457. {
  59458. public:
  59459. MagnifyingPeer (Component* const component_,
  59460. MagnifierComponent* const magnifierComp_)
  59461. : ComponentPeer (component_, 0),
  59462. magnifierComp (magnifierComp_)
  59463. {
  59464. }
  59465. ~MagnifyingPeer()
  59466. {
  59467. }
  59468. void* getNativeHandle() const { return 0; }
  59469. void setVisible (bool) {}
  59470. void setTitle (const String&) {}
  59471. void setPosition (int, int) {}
  59472. void setSize (int, int) {}
  59473. void setBounds (int, int, int, int, const bool) {}
  59474. void setMinimised (bool) {}
  59475. bool isMinimised() const { return false; }
  59476. void setFullScreen (bool) {}
  59477. bool isFullScreen() const { return false; }
  59478. const BorderSize getFrameSize() const { return BorderSize (0); }
  59479. bool setAlwaysOnTop (bool) { return true; }
  59480. void toFront (bool) {}
  59481. void toBehind (ComponentPeer*) {}
  59482. void setIcon (const Image&) {}
  59483. bool isFocused() const
  59484. {
  59485. return magnifierComp->hasKeyboardFocus (true);
  59486. }
  59487. void grabFocus()
  59488. {
  59489. ComponentPeer* peer = magnifierComp->getPeer();
  59490. if (peer != 0)
  59491. peer->grabFocus();
  59492. }
  59493. void textInputRequired (const Point<int>& position)
  59494. {
  59495. ComponentPeer* peer = magnifierComp->getPeer();
  59496. if (peer != 0)
  59497. peer->textInputRequired (position);
  59498. }
  59499. const Rectangle<int> getBounds() const
  59500. {
  59501. return Rectangle<int> (magnifierComp->getScreenX(), magnifierComp->getScreenY(),
  59502. component->getWidth(), component->getHeight());
  59503. }
  59504. const Point<int> getScreenPosition() const
  59505. {
  59506. return magnifierComp->getScreenPosition();
  59507. }
  59508. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition)
  59509. {
  59510. const double zoom = magnifierComp->getScaleFactor();
  59511. return magnifierComp->relativePositionToGlobal (Point<int> (roundToInt (relativePosition.getX() * zoom),
  59512. roundToInt (relativePosition.getY() * zoom)));
  59513. }
  59514. const Point<int> globalPositionToRelative (const Point<int>& screenPosition)
  59515. {
  59516. const Point<int> p (magnifierComp->globalPositionToRelative (screenPosition));
  59517. const double zoom = magnifierComp->getScaleFactor();
  59518. return Point<int> (roundToInt (p.getX() / zoom),
  59519. roundToInt (p.getY() / zoom));
  59520. }
  59521. bool contains (const Point<int>& position, bool) const
  59522. {
  59523. return ((unsigned int) position.getX()) < (unsigned int) magnifierComp->getWidth()
  59524. && ((unsigned int) position.getY()) < (unsigned int) magnifierComp->getHeight();
  59525. }
  59526. void repaint (int x, int y, int w, int h)
  59527. {
  59528. const double zoom = magnifierComp->getScaleFactor();
  59529. magnifierComp->repaint ((int) (x * zoom),
  59530. (int) (y * zoom),
  59531. roundToInt (w * zoom) + 1,
  59532. roundToInt (h * zoom) + 1);
  59533. }
  59534. void performAnyPendingRepaintsNow()
  59535. {
  59536. }
  59537. juce_UseDebuggingNewOperator
  59538. private:
  59539. MagnifierComponent* const magnifierComp;
  59540. MagnifyingPeer (const MagnifyingPeer&);
  59541. MagnifyingPeer& operator= (const MagnifyingPeer&);
  59542. };
  59543. class PeerHolderComp : public Component
  59544. {
  59545. public:
  59546. PeerHolderComp (MagnifierComponent* const magnifierComp_)
  59547. : magnifierComp (magnifierComp_)
  59548. {
  59549. setVisible (true);
  59550. }
  59551. ~PeerHolderComp()
  59552. {
  59553. }
  59554. ComponentPeer* createNewPeer (int, void*)
  59555. {
  59556. return new MagnifyingPeer (this, magnifierComp);
  59557. }
  59558. void childBoundsChanged (Component* c)
  59559. {
  59560. if (c != 0)
  59561. {
  59562. setSize (c->getWidth(), c->getHeight());
  59563. magnifierComp->childBoundsChanged (this);
  59564. }
  59565. }
  59566. void mouseWheelMove (const MouseEvent& e, float ix, float iy)
  59567. {
  59568. // unhandled mouse wheel moves can be referred upwards to the parent comp..
  59569. Component* const p = magnifierComp->getParentComponent();
  59570. if (p != 0)
  59571. p->mouseWheelMove (e.getEventRelativeTo (p), ix, iy);
  59572. }
  59573. private:
  59574. MagnifierComponent* const magnifierComp;
  59575. PeerHolderComp (const PeerHolderComp&);
  59576. PeerHolderComp& operator= (const PeerHolderComp&);
  59577. };
  59578. MagnifierComponent::MagnifierComponent (Component* const content_,
  59579. const bool deleteContentCompWhenNoLongerNeeded)
  59580. : content (content_),
  59581. scaleFactor (0.0),
  59582. peer (0),
  59583. deleteContent (deleteContentCompWhenNoLongerNeeded),
  59584. quality (Graphics::lowResamplingQuality),
  59585. mouseSource (0, true)
  59586. {
  59587. holderComp = new PeerHolderComp (this);
  59588. setScaleFactor (1.0);
  59589. }
  59590. MagnifierComponent::~MagnifierComponent()
  59591. {
  59592. delete holderComp;
  59593. if (deleteContent)
  59594. delete content;
  59595. }
  59596. void MagnifierComponent::setScaleFactor (double newScaleFactor)
  59597. {
  59598. jassert (newScaleFactor > 0.0); // hmm - unlikely to work well with a negative scale factor
  59599. newScaleFactor = jlimit (1.0 / 8.0, 1000.0, newScaleFactor);
  59600. if (scaleFactor != newScaleFactor)
  59601. {
  59602. scaleFactor = newScaleFactor;
  59603. if (scaleFactor == 1.0)
  59604. {
  59605. holderComp->removeFromDesktop();
  59606. peer = 0;
  59607. addChildComponent (content);
  59608. childBoundsChanged (content);
  59609. }
  59610. else
  59611. {
  59612. holderComp->addAndMakeVisible (content);
  59613. holderComp->childBoundsChanged (content);
  59614. childBoundsChanged (holderComp);
  59615. holderComp->addToDesktop (0);
  59616. peer = holderComp->getPeer();
  59617. }
  59618. repaint();
  59619. }
  59620. }
  59621. void MagnifierComponent::setResamplingQuality (Graphics::ResamplingQuality newQuality)
  59622. {
  59623. quality = newQuality;
  59624. }
  59625. void MagnifierComponent::paint (Graphics& g)
  59626. {
  59627. const int w = holderComp->getWidth();
  59628. const int h = holderComp->getHeight();
  59629. if (w == 0 || h == 0)
  59630. return;
  59631. const Rectangle<int> r (g.getClipBounds());
  59632. const int srcX = (int) (r.getX() / scaleFactor);
  59633. const int srcY = (int) (r.getY() / scaleFactor);
  59634. int srcW = roundToInt (r.getRight() / scaleFactor) - srcX;
  59635. int srcH = roundToInt (r.getBottom() / scaleFactor) - srcY;
  59636. if (scaleFactor >= 1.0)
  59637. {
  59638. ++srcW;
  59639. ++srcH;
  59640. }
  59641. Image temp (Image::ARGB, jmax (w, srcX + srcW), jmax (h, srcY + srcH), false);
  59642. temp.clear (srcX, srcY, srcW, srcH);
  59643. {
  59644. Graphics g2 (temp);
  59645. g2.reduceClipRegion (srcX, srcY, srcW, srcH);
  59646. holderComp->paintEntireComponent (g2);
  59647. }
  59648. g.setImageResamplingQuality (quality);
  59649. g.drawImageTransformed (&temp, temp.getBounds(),
  59650. AffineTransform::scale ((float) scaleFactor, (float) scaleFactor),
  59651. false);
  59652. }
  59653. void MagnifierComponent::childBoundsChanged (Component* c)
  59654. {
  59655. if (c != 0)
  59656. setSize (roundToInt (c->getWidth() * scaleFactor),
  59657. roundToInt (c->getHeight() * scaleFactor));
  59658. }
  59659. void MagnifierComponent::passOnMouseEventToPeer (const MouseEvent& e)
  59660. {
  59661. if (peer != 0)
  59662. mouseSource.handleEvent (peer, Point<int> (scaleInt (e.x), scaleInt (e.y)),
  59663. e.eventTime.toMilliseconds(), ModifierKeys::getCurrentModifiers());
  59664. }
  59665. void MagnifierComponent::mouseDown (const MouseEvent& e)
  59666. {
  59667. passOnMouseEventToPeer (e);
  59668. }
  59669. void MagnifierComponent::mouseUp (const MouseEvent& e)
  59670. {
  59671. passOnMouseEventToPeer (e);
  59672. }
  59673. void MagnifierComponent::mouseDrag (const MouseEvent& e)
  59674. {
  59675. passOnMouseEventToPeer (e);
  59676. }
  59677. void MagnifierComponent::mouseMove (const MouseEvent& e)
  59678. {
  59679. passOnMouseEventToPeer (e);
  59680. }
  59681. void MagnifierComponent::mouseEnter (const MouseEvent& e)
  59682. {
  59683. passOnMouseEventToPeer (e);
  59684. }
  59685. void MagnifierComponent::mouseExit (const MouseEvent& e)
  59686. {
  59687. passOnMouseEventToPeer (e);
  59688. }
  59689. void MagnifierComponent::mouseWheelMove (const MouseEvent& e, float ix, float iy)
  59690. {
  59691. if (peer != 0)
  59692. peer->handleMouseWheel (e.source.getIndex(),
  59693. Point<int> (scaleInt (e.x), scaleInt (e.y)), e.eventTime.toMilliseconds(),
  59694. ix * 256.0f, iy * 256.0f);
  59695. else
  59696. Component::mouseWheelMove (e, ix, iy);
  59697. }
  59698. int MagnifierComponent::scaleInt (const int n) const
  59699. {
  59700. return roundToInt (n / scaleFactor);
  59701. }
  59702. END_JUCE_NAMESPACE
  59703. /*** End of inlined file: juce_MagnifierComponent.cpp ***/
  59704. /*** Start of inlined file: juce_MidiKeyboardComponent.cpp ***/
  59705. BEGIN_JUCE_NAMESPACE
  59706. class MidiKeyboardUpDownButton : public Button
  59707. {
  59708. public:
  59709. MidiKeyboardUpDownButton (MidiKeyboardComponent* const owner_,
  59710. const int delta_)
  59711. : Button (String::empty),
  59712. owner (owner_),
  59713. delta (delta_)
  59714. {
  59715. setOpaque (true);
  59716. }
  59717. ~MidiKeyboardUpDownButton()
  59718. {
  59719. }
  59720. void clicked()
  59721. {
  59722. int note = owner->getLowestVisibleKey();
  59723. if (delta < 0)
  59724. note = (note - 1) / 12;
  59725. else
  59726. note = note / 12 + 1;
  59727. owner->setLowestVisibleKey (note * 12);
  59728. }
  59729. void paintButton (Graphics& g,
  59730. bool isMouseOverButton,
  59731. bool isButtonDown)
  59732. {
  59733. owner->drawUpDownButton (g, getWidth(), getHeight(),
  59734. isMouseOverButton, isButtonDown,
  59735. delta > 0);
  59736. }
  59737. private:
  59738. MidiKeyboardComponent* const owner;
  59739. const int delta;
  59740. MidiKeyboardUpDownButton (const MidiKeyboardUpDownButton&);
  59741. MidiKeyboardUpDownButton& operator= (const MidiKeyboardUpDownButton&);
  59742. };
  59743. MidiKeyboardComponent::MidiKeyboardComponent (MidiKeyboardState& state_,
  59744. const Orientation orientation_)
  59745. : state (state_),
  59746. xOffset (0),
  59747. blackNoteLength (1),
  59748. keyWidth (16.0f),
  59749. orientation (orientation_),
  59750. midiChannel (1),
  59751. midiInChannelMask (0xffff),
  59752. velocity (1.0f),
  59753. noteUnderMouse (-1),
  59754. mouseDownNote (-1),
  59755. rangeStart (0),
  59756. rangeEnd (127),
  59757. firstKey (12 * 4),
  59758. canScroll (true),
  59759. mouseDragging (false),
  59760. useMousePositionForVelocity (true),
  59761. keyMappingOctave (6),
  59762. octaveNumForMiddleC (3)
  59763. {
  59764. addChildComponent (scrollDown = new MidiKeyboardUpDownButton (this, -1));
  59765. addChildComponent (scrollUp = new MidiKeyboardUpDownButton (this, 1));
  59766. // initialise with a default set of querty key-mappings..
  59767. const char* const keymap = "awsedftgyhujkolp;";
  59768. for (int i = String (keymap).length(); --i >= 0;)
  59769. setKeyPressForNote (KeyPress (keymap[i], 0, 0), i);
  59770. setOpaque (true);
  59771. setWantsKeyboardFocus (true);
  59772. state.addListener (this);
  59773. }
  59774. MidiKeyboardComponent::~MidiKeyboardComponent()
  59775. {
  59776. state.removeListener (this);
  59777. jassert (mouseDownNote < 0 && keysPressed.countNumberOfSetBits() == 0); // leaving stuck notes!
  59778. deleteAllChildren();
  59779. }
  59780. void MidiKeyboardComponent::setKeyWidth (const float widthInPixels)
  59781. {
  59782. keyWidth = widthInPixels;
  59783. resized();
  59784. }
  59785. void MidiKeyboardComponent::setOrientation (const Orientation newOrientation)
  59786. {
  59787. if (orientation != newOrientation)
  59788. {
  59789. orientation = newOrientation;
  59790. resized();
  59791. }
  59792. }
  59793. void MidiKeyboardComponent::setAvailableRange (const int lowestNote,
  59794. const int highestNote)
  59795. {
  59796. jassert (lowestNote >= 0 && lowestNote <= 127);
  59797. jassert (highestNote >= 0 && highestNote <= 127);
  59798. jassert (lowestNote <= highestNote);
  59799. if (rangeStart != lowestNote || rangeEnd != highestNote)
  59800. {
  59801. rangeStart = jlimit (0, 127, lowestNote);
  59802. rangeEnd = jlimit (0, 127, highestNote);
  59803. firstKey = jlimit (rangeStart, rangeEnd, firstKey);
  59804. resized();
  59805. }
  59806. }
  59807. void MidiKeyboardComponent::setLowestVisibleKey (int noteNumber)
  59808. {
  59809. noteNumber = jlimit (rangeStart, rangeEnd, noteNumber);
  59810. if (noteNumber != firstKey)
  59811. {
  59812. firstKey = noteNumber;
  59813. sendChangeMessage (this);
  59814. resized();
  59815. }
  59816. }
  59817. void MidiKeyboardComponent::setScrollButtonsVisible (const bool canScroll_)
  59818. {
  59819. if (canScroll != canScroll_)
  59820. {
  59821. canScroll = canScroll_;
  59822. resized();
  59823. }
  59824. }
  59825. void MidiKeyboardComponent::colourChanged()
  59826. {
  59827. repaint();
  59828. }
  59829. void MidiKeyboardComponent::setMidiChannel (const int midiChannelNumber)
  59830. {
  59831. jassert (midiChannelNumber > 0 && midiChannelNumber <= 16);
  59832. if (midiChannel != midiChannelNumber)
  59833. {
  59834. resetAnyKeysInUse();
  59835. midiChannel = jlimit (1, 16, midiChannelNumber);
  59836. }
  59837. }
  59838. void MidiKeyboardComponent::setMidiChannelsToDisplay (const int midiChannelMask)
  59839. {
  59840. midiInChannelMask = midiChannelMask;
  59841. triggerAsyncUpdate();
  59842. }
  59843. void MidiKeyboardComponent::setVelocity (const float velocity_, const bool useMousePositionForVelocity_)
  59844. {
  59845. velocity = jlimit (0.0f, 1.0f, velocity_);
  59846. useMousePositionForVelocity = useMousePositionForVelocity_;
  59847. }
  59848. void MidiKeyboardComponent::getKeyPosition (int midiNoteNumber, const float keyWidth, int& x, int& w) const
  59849. {
  59850. jassert (midiNoteNumber >= 0 && midiNoteNumber < 128);
  59851. static const float blackNoteWidth = 0.7f;
  59852. static const float notePos[] = { 0.0f, 1 - blackNoteWidth * 0.6f,
  59853. 1.0f, 2 - blackNoteWidth * 0.4f,
  59854. 2.0f, 3.0f, 4 - blackNoteWidth * 0.7f,
  59855. 4.0f, 5 - blackNoteWidth * 0.5f,
  59856. 5.0f, 6 - blackNoteWidth * 0.3f,
  59857. 6.0f };
  59858. static const float widths[] = { 1.0f, blackNoteWidth,
  59859. 1.0f, blackNoteWidth,
  59860. 1.0f, 1.0f, blackNoteWidth,
  59861. 1.0f, blackNoteWidth,
  59862. 1.0f, blackNoteWidth,
  59863. 1.0f };
  59864. const int octave = midiNoteNumber / 12;
  59865. const int note = midiNoteNumber % 12;
  59866. x = roundToInt (octave * 7.0f * keyWidth + notePos [note] * keyWidth);
  59867. w = roundToInt (widths [note] * keyWidth);
  59868. }
  59869. void MidiKeyboardComponent::getKeyPos (int midiNoteNumber, int& x, int& w) const
  59870. {
  59871. getKeyPosition (midiNoteNumber, keyWidth, x, w);
  59872. int rx, rw;
  59873. getKeyPosition (rangeStart, keyWidth, rx, rw);
  59874. x -= xOffset + rx;
  59875. }
  59876. int MidiKeyboardComponent::getKeyStartPosition (const int midiNoteNumber) const
  59877. {
  59878. int x, y;
  59879. getKeyPos (midiNoteNumber, x, y);
  59880. return x;
  59881. }
  59882. static const uint8 whiteNotes[] = { 0, 2, 4, 5, 7, 9, 11 };
  59883. static const uint8 blackNotes[] = { 1, 3, 6, 8, 10 };
  59884. int MidiKeyboardComponent::xyToNote (const Point<int>& pos, float& mousePositionVelocity)
  59885. {
  59886. if (! reallyContains (pos.getX(), pos.getY(), false))
  59887. return -1;
  59888. Point<int> p (pos);
  59889. if (orientation != horizontalKeyboard)
  59890. {
  59891. p = Point<int> (p.getY(), p.getX());
  59892. if (orientation == verticalKeyboardFacingLeft)
  59893. p = Point<int> (p.getX(), getWidth() - p.getY());
  59894. else
  59895. p = Point<int> (getHeight() - p.getX(), p.getY());
  59896. }
  59897. return remappedXYToNote (p + Point<int> (xOffset, 0), mousePositionVelocity);
  59898. }
  59899. int MidiKeyboardComponent::remappedXYToNote (const Point<int>& pos, float& mousePositionVelocity) const
  59900. {
  59901. if (pos.getY() < blackNoteLength)
  59902. {
  59903. for (int octaveStart = 12 * (rangeStart / 12); octaveStart <= rangeEnd; octaveStart += 12)
  59904. {
  59905. for (int i = 0; i < 5; ++i)
  59906. {
  59907. const int note = octaveStart + blackNotes [i];
  59908. if (note >= rangeStart && note <= rangeEnd)
  59909. {
  59910. int kx, kw;
  59911. getKeyPos (note, kx, kw);
  59912. kx += xOffset;
  59913. if (pos.getX() >= kx && pos.getX() < kx + kw)
  59914. {
  59915. mousePositionVelocity = pos.getY() / (float) blackNoteLength;
  59916. return note;
  59917. }
  59918. }
  59919. }
  59920. }
  59921. }
  59922. for (int octaveStart = 12 * (rangeStart / 12); octaveStart <= rangeEnd; octaveStart += 12)
  59923. {
  59924. for (int i = 0; i < 7; ++i)
  59925. {
  59926. const int note = octaveStart + whiteNotes [i];
  59927. if (note >= rangeStart && note <= rangeEnd)
  59928. {
  59929. int kx, kw;
  59930. getKeyPos (note, kx, kw);
  59931. kx += xOffset;
  59932. if (pos.getX() >= kx && pos.getX() < kx + kw)
  59933. {
  59934. const int whiteNoteLength = (orientation == horizontalKeyboard) ? getHeight() : getWidth();
  59935. mousePositionVelocity = pos.getY() / (float) whiteNoteLength;
  59936. return note;
  59937. }
  59938. }
  59939. }
  59940. }
  59941. mousePositionVelocity = 0;
  59942. return -1;
  59943. }
  59944. void MidiKeyboardComponent::repaintNote (const int noteNum)
  59945. {
  59946. if (noteNum >= rangeStart && noteNum <= rangeEnd)
  59947. {
  59948. int x, w;
  59949. getKeyPos (noteNum, x, w);
  59950. if (orientation == horizontalKeyboard)
  59951. repaint (x, 0, w, getHeight());
  59952. else if (orientation == verticalKeyboardFacingLeft)
  59953. repaint (0, x, getWidth(), w);
  59954. else if (orientation == verticalKeyboardFacingRight)
  59955. repaint (0, getHeight() - x - w, getWidth(), w);
  59956. }
  59957. }
  59958. void MidiKeyboardComponent::paint (Graphics& g)
  59959. {
  59960. g.fillAll (Colours::white.overlaidWith (findColour (whiteNoteColourId)));
  59961. const Colour lineColour (findColour (keySeparatorLineColourId));
  59962. const Colour textColour (findColour (textLabelColourId));
  59963. int x, w, octave;
  59964. for (octave = 0; octave < 128; octave += 12)
  59965. {
  59966. for (int white = 0; white < 7; ++white)
  59967. {
  59968. const int noteNum = octave + whiteNotes [white];
  59969. if (noteNum >= rangeStart && noteNum <= rangeEnd)
  59970. {
  59971. getKeyPos (noteNum, x, w);
  59972. if (orientation == horizontalKeyboard)
  59973. drawWhiteNote (noteNum, g, x, 0, w, getHeight(),
  59974. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  59975. noteUnderMouse == noteNum,
  59976. lineColour, textColour);
  59977. else if (orientation == verticalKeyboardFacingLeft)
  59978. drawWhiteNote (noteNum, g, 0, x, getWidth(), w,
  59979. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  59980. noteUnderMouse == noteNum,
  59981. lineColour, textColour);
  59982. else if (orientation == verticalKeyboardFacingRight)
  59983. drawWhiteNote (noteNum, g, 0, getHeight() - x - w, getWidth(), w,
  59984. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  59985. noteUnderMouse == noteNum,
  59986. lineColour, textColour);
  59987. }
  59988. }
  59989. }
  59990. float x1 = 0.0f, y1 = 0.0f, x2 = 0.0f, y2 = 0.0f;
  59991. if (orientation == verticalKeyboardFacingLeft)
  59992. {
  59993. x1 = getWidth() - 1.0f;
  59994. x2 = getWidth() - 5.0f;
  59995. }
  59996. else if (orientation == verticalKeyboardFacingRight)
  59997. x2 = 5.0f;
  59998. else
  59999. y2 = 5.0f;
  60000. g.setGradientFill (ColourGradient (Colours::black.withAlpha (0.3f), x1, y1,
  60001. Colours::transparentBlack, x2, y2, false));
  60002. getKeyPos (rangeEnd, x, w);
  60003. x += w;
  60004. if (orientation == verticalKeyboardFacingLeft)
  60005. g.fillRect (getWidth() - 5, 0, 5, x);
  60006. else if (orientation == verticalKeyboardFacingRight)
  60007. g.fillRect (0, 0, 5, x);
  60008. else
  60009. g.fillRect (0, 0, x, 5);
  60010. g.setColour (lineColour);
  60011. if (orientation == verticalKeyboardFacingLeft)
  60012. g.fillRect (0, 0, 1, x);
  60013. else if (orientation == verticalKeyboardFacingRight)
  60014. g.fillRect (getWidth() - 1, 0, 1, x);
  60015. else
  60016. g.fillRect (0, getHeight() - 1, x, 1);
  60017. const Colour blackNoteColour (findColour (blackNoteColourId));
  60018. for (octave = 0; octave < 128; octave += 12)
  60019. {
  60020. for (int black = 0; black < 5; ++black)
  60021. {
  60022. const int noteNum = octave + blackNotes [black];
  60023. if (noteNum >= rangeStart && noteNum <= rangeEnd)
  60024. {
  60025. getKeyPos (noteNum, x, w);
  60026. if (orientation == horizontalKeyboard)
  60027. drawBlackNote (noteNum, g, x, 0, w, blackNoteLength,
  60028. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  60029. noteUnderMouse == noteNum,
  60030. blackNoteColour);
  60031. else if (orientation == verticalKeyboardFacingLeft)
  60032. drawBlackNote (noteNum, g, getWidth() - blackNoteLength, x, blackNoteLength, w,
  60033. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  60034. noteUnderMouse == noteNum,
  60035. blackNoteColour);
  60036. else if (orientation == verticalKeyboardFacingRight)
  60037. drawBlackNote (noteNum, g, 0, getHeight() - x - w, blackNoteLength, w,
  60038. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  60039. noteUnderMouse == noteNum,
  60040. blackNoteColour);
  60041. }
  60042. }
  60043. }
  60044. }
  60045. void MidiKeyboardComponent::drawWhiteNote (int midiNoteNumber,
  60046. Graphics& g, int x, int y, int w, int h,
  60047. bool isDown, bool isOver,
  60048. const Colour& lineColour,
  60049. const Colour& textColour)
  60050. {
  60051. Colour c (Colours::transparentWhite);
  60052. if (isDown)
  60053. c = findColour (keyDownOverlayColourId);
  60054. if (isOver)
  60055. c = c.overlaidWith (findColour (mouseOverKeyOverlayColourId));
  60056. g.setColour (c);
  60057. g.fillRect (x, y, w, h);
  60058. const String text (getWhiteNoteText (midiNoteNumber));
  60059. if (! text.isEmpty())
  60060. {
  60061. g.setColour (textColour);
  60062. Font f (jmin (12.0f, keyWidth * 0.9f));
  60063. f.setHorizontalScale (0.8f);
  60064. g.setFont (f);
  60065. Justification justification (Justification::centredBottom);
  60066. if (orientation == verticalKeyboardFacingLeft)
  60067. justification = Justification::centredLeft;
  60068. else if (orientation == verticalKeyboardFacingRight)
  60069. justification = Justification::centredRight;
  60070. g.drawFittedText (text, x + 2, y + 2, w - 4, h - 4, justification, 1);
  60071. }
  60072. g.setColour (lineColour);
  60073. if (orientation == horizontalKeyboard)
  60074. g.fillRect (x, y, 1, h);
  60075. else if (orientation == verticalKeyboardFacingLeft)
  60076. g.fillRect (x, y, w, 1);
  60077. else if (orientation == verticalKeyboardFacingRight)
  60078. g.fillRect (x, y + h - 1, w, 1);
  60079. if (midiNoteNumber == rangeEnd)
  60080. {
  60081. if (orientation == horizontalKeyboard)
  60082. g.fillRect (x + w, y, 1, h);
  60083. else if (orientation == verticalKeyboardFacingLeft)
  60084. g.fillRect (x, y + h, w, 1);
  60085. else if (orientation == verticalKeyboardFacingRight)
  60086. g.fillRect (x, y - 1, w, 1);
  60087. }
  60088. }
  60089. void MidiKeyboardComponent::drawBlackNote (int /*midiNoteNumber*/,
  60090. Graphics& g, int x, int y, int w, int h,
  60091. bool isDown, bool isOver,
  60092. const Colour& noteFillColour)
  60093. {
  60094. Colour c (noteFillColour);
  60095. if (isDown)
  60096. c = c.overlaidWith (findColour (keyDownOverlayColourId));
  60097. if (isOver)
  60098. c = c.overlaidWith (findColour (mouseOverKeyOverlayColourId));
  60099. g.setColour (c);
  60100. g.fillRect (x, y, w, h);
  60101. if (isDown)
  60102. {
  60103. g.setColour (noteFillColour);
  60104. g.drawRect (x, y, w, h);
  60105. }
  60106. else
  60107. {
  60108. const int xIndent = jmax (1, jmin (w, h) / 8);
  60109. g.setColour (c.brighter());
  60110. if (orientation == horizontalKeyboard)
  60111. g.fillRect (x + xIndent, y, w - xIndent * 2, 7 * h / 8);
  60112. else if (orientation == verticalKeyboardFacingLeft)
  60113. g.fillRect (x + w / 8, y + xIndent, w - w / 8, h - xIndent * 2);
  60114. else if (orientation == verticalKeyboardFacingRight)
  60115. g.fillRect (x, y + xIndent, 7 * w / 8, h - xIndent * 2);
  60116. }
  60117. }
  60118. void MidiKeyboardComponent::setOctaveForMiddleC (const int octaveNumForMiddleC_) throw()
  60119. {
  60120. octaveNumForMiddleC = octaveNumForMiddleC_;
  60121. repaint();
  60122. }
  60123. const String MidiKeyboardComponent::getWhiteNoteText (const int midiNoteNumber)
  60124. {
  60125. if (keyWidth > 14.0f && midiNoteNumber % 12 == 0)
  60126. return MidiMessage::getMidiNoteName (midiNoteNumber, true, true, octaveNumForMiddleC);
  60127. return String::empty;
  60128. }
  60129. void MidiKeyboardComponent::drawUpDownButton (Graphics& g, int w, int h,
  60130. const bool isMouseOver,
  60131. const bool isButtonDown,
  60132. const bool movesOctavesUp)
  60133. {
  60134. g.fillAll (findColour (upDownButtonBackgroundColourId));
  60135. float angle;
  60136. if (orientation == MidiKeyboardComponent::horizontalKeyboard)
  60137. angle = movesOctavesUp ? 0.0f : 0.5f;
  60138. else if (orientation == MidiKeyboardComponent::verticalKeyboardFacingLeft)
  60139. angle = movesOctavesUp ? 0.25f : 0.75f;
  60140. else
  60141. angle = movesOctavesUp ? 0.75f : 0.25f;
  60142. Path path;
  60143. path.lineTo (0.0f, 1.0f);
  60144. path.lineTo (1.0f, 0.5f);
  60145. path.closeSubPath();
  60146. path.applyTransform (AffineTransform::rotation (float_Pi * 2.0f * angle, 0.5f, 0.5f));
  60147. g.setColour (findColour (upDownButtonArrowColourId)
  60148. .withAlpha (isButtonDown ? 1.0f : (isMouseOver ? 0.6f : 0.4f)));
  60149. g.fillPath (path, path.getTransformToScaleToFit (1.0f, 1.0f,
  60150. w - 2.0f,
  60151. h - 2.0f,
  60152. true));
  60153. }
  60154. void MidiKeyboardComponent::resized()
  60155. {
  60156. int w = getWidth();
  60157. int h = getHeight();
  60158. if (w > 0 && h > 0)
  60159. {
  60160. if (orientation != horizontalKeyboard)
  60161. swapVariables (w, h);
  60162. blackNoteLength = roundToInt (h * 0.7f);
  60163. int kx2, kw2;
  60164. getKeyPos (rangeEnd, kx2, kw2);
  60165. kx2 += kw2;
  60166. if (firstKey != rangeStart)
  60167. {
  60168. int kx1, kw1;
  60169. getKeyPos (rangeStart, kx1, kw1);
  60170. if (kx2 - kx1 <= w)
  60171. {
  60172. firstKey = rangeStart;
  60173. sendChangeMessage (this);
  60174. repaint();
  60175. }
  60176. }
  60177. const bool showScrollButtons = canScroll && (firstKey > rangeStart || kx2 > w + xOffset * 2);
  60178. scrollDown->setVisible (showScrollButtons);
  60179. scrollUp->setVisible (showScrollButtons);
  60180. xOffset = 0;
  60181. if (showScrollButtons)
  60182. {
  60183. const int scrollButtonW = jmin (12, w / 2);
  60184. if (orientation == horizontalKeyboard)
  60185. {
  60186. scrollDown->setBounds (0, 0, scrollButtonW, getHeight());
  60187. scrollUp->setBounds (getWidth() - scrollButtonW, 0, scrollButtonW, getHeight());
  60188. }
  60189. else if (orientation == verticalKeyboardFacingLeft)
  60190. {
  60191. scrollDown->setBounds (0, 0, getWidth(), scrollButtonW);
  60192. scrollUp->setBounds (0, getHeight() - scrollButtonW, getWidth(), scrollButtonW);
  60193. }
  60194. else if (orientation == verticalKeyboardFacingRight)
  60195. {
  60196. scrollDown->setBounds (0, getHeight() - scrollButtonW, getWidth(), scrollButtonW);
  60197. scrollUp->setBounds (0, 0, getWidth(), scrollButtonW);
  60198. }
  60199. int endOfLastKey, kw;
  60200. getKeyPos (rangeEnd, endOfLastKey, kw);
  60201. endOfLastKey += kw;
  60202. float mousePositionVelocity;
  60203. const int spaceAvailable = w - scrollButtonW * 2;
  60204. const int lastStartKey = remappedXYToNote (Point<int> (endOfLastKey - spaceAvailable, 0), mousePositionVelocity) + 1;
  60205. if (lastStartKey >= 0 && firstKey > lastStartKey)
  60206. {
  60207. firstKey = jlimit (rangeStart, rangeEnd, lastStartKey);
  60208. sendChangeMessage (this);
  60209. }
  60210. int newOffset = 0;
  60211. getKeyPos (firstKey, newOffset, kw);
  60212. xOffset = newOffset - scrollButtonW;
  60213. }
  60214. else
  60215. {
  60216. firstKey = rangeStart;
  60217. }
  60218. timerCallback();
  60219. repaint();
  60220. }
  60221. }
  60222. void MidiKeyboardComponent::handleNoteOn (MidiKeyboardState*, int /*midiChannel*/, int /*midiNoteNumber*/, float /*velocity*/)
  60223. {
  60224. triggerAsyncUpdate();
  60225. }
  60226. void MidiKeyboardComponent::handleNoteOff (MidiKeyboardState*, int /*midiChannel*/, int /*midiNoteNumber*/)
  60227. {
  60228. triggerAsyncUpdate();
  60229. }
  60230. void MidiKeyboardComponent::handleAsyncUpdate()
  60231. {
  60232. for (int i = rangeStart; i <= rangeEnd; ++i)
  60233. {
  60234. if (keysCurrentlyDrawnDown[i] != state.isNoteOnForChannels (midiInChannelMask, i))
  60235. {
  60236. keysCurrentlyDrawnDown.setBit (i, state.isNoteOnForChannels (midiInChannelMask, i));
  60237. repaintNote (i);
  60238. }
  60239. }
  60240. }
  60241. void MidiKeyboardComponent::resetAnyKeysInUse()
  60242. {
  60243. if (keysPressed.countNumberOfSetBits() > 0 || mouseDownNote > 0)
  60244. {
  60245. state.allNotesOff (midiChannel);
  60246. keysPressed.clear();
  60247. mouseDownNote = -1;
  60248. }
  60249. }
  60250. void MidiKeyboardComponent::updateNoteUnderMouse (const Point<int>& pos)
  60251. {
  60252. float mousePositionVelocity = 0.0f;
  60253. const int newNote = (mouseDragging || isMouseOver())
  60254. ? xyToNote (pos, mousePositionVelocity) : -1;
  60255. if (noteUnderMouse != newNote)
  60256. {
  60257. if (mouseDownNote >= 0)
  60258. {
  60259. state.noteOff (midiChannel, mouseDownNote);
  60260. mouseDownNote = -1;
  60261. }
  60262. if (mouseDragging && newNote >= 0)
  60263. {
  60264. if (! useMousePositionForVelocity)
  60265. mousePositionVelocity = 1.0f;
  60266. state.noteOn (midiChannel, newNote, mousePositionVelocity * velocity);
  60267. mouseDownNote = newNote;
  60268. }
  60269. repaintNote (noteUnderMouse);
  60270. noteUnderMouse = newNote;
  60271. repaintNote (noteUnderMouse);
  60272. }
  60273. else if (mouseDownNote >= 0 && ! mouseDragging)
  60274. {
  60275. state.noteOff (midiChannel, mouseDownNote);
  60276. mouseDownNote = -1;
  60277. }
  60278. }
  60279. void MidiKeyboardComponent::mouseMove (const MouseEvent& e)
  60280. {
  60281. updateNoteUnderMouse (e.getPosition());
  60282. stopTimer();
  60283. }
  60284. void MidiKeyboardComponent::mouseDrag (const MouseEvent& e)
  60285. {
  60286. float mousePositionVelocity;
  60287. const int newNote = xyToNote (e.getPosition(), mousePositionVelocity);
  60288. if (newNote >= 0)
  60289. mouseDraggedToKey (newNote, e);
  60290. updateNoteUnderMouse (e.getPosition());
  60291. }
  60292. bool MidiKeyboardComponent::mouseDownOnKey (int /*midiNoteNumber*/, const MouseEvent&)
  60293. {
  60294. return true;
  60295. }
  60296. void MidiKeyboardComponent::mouseDraggedToKey (int /*midiNoteNumber*/, const MouseEvent&)
  60297. {
  60298. }
  60299. void MidiKeyboardComponent::mouseDown (const MouseEvent& e)
  60300. {
  60301. float mousePositionVelocity;
  60302. const int newNote = xyToNote (e.getPosition(), mousePositionVelocity);
  60303. mouseDragging = false;
  60304. if (newNote >= 0 && mouseDownOnKey (newNote, e))
  60305. {
  60306. repaintNote (noteUnderMouse);
  60307. noteUnderMouse = -1;
  60308. mouseDragging = true;
  60309. updateNoteUnderMouse (e.getPosition());
  60310. startTimer (500);
  60311. }
  60312. }
  60313. void MidiKeyboardComponent::mouseUp (const MouseEvent& e)
  60314. {
  60315. mouseDragging = false;
  60316. updateNoteUnderMouse (e.getPosition());
  60317. stopTimer();
  60318. }
  60319. void MidiKeyboardComponent::mouseEnter (const MouseEvent& e)
  60320. {
  60321. updateNoteUnderMouse (e.getPosition());
  60322. }
  60323. void MidiKeyboardComponent::mouseExit (const MouseEvent& e)
  60324. {
  60325. updateNoteUnderMouse (e.getPosition());
  60326. }
  60327. void MidiKeyboardComponent::mouseWheelMove (const MouseEvent&, float ix, float iy)
  60328. {
  60329. setLowestVisibleKey (getLowestVisibleKey() + roundToInt ((ix != 0 ? ix : iy) * 5.0f));
  60330. }
  60331. void MidiKeyboardComponent::timerCallback()
  60332. {
  60333. updateNoteUnderMouse (getMouseXYRelative());
  60334. }
  60335. void MidiKeyboardComponent::clearKeyMappings()
  60336. {
  60337. resetAnyKeysInUse();
  60338. keyPressNotes.clear();
  60339. keyPresses.clear();
  60340. }
  60341. void MidiKeyboardComponent::setKeyPressForNote (const KeyPress& key,
  60342. const int midiNoteOffsetFromC)
  60343. {
  60344. removeKeyPressForNote (midiNoteOffsetFromC);
  60345. keyPressNotes.add (midiNoteOffsetFromC);
  60346. keyPresses.add (key);
  60347. }
  60348. void MidiKeyboardComponent::removeKeyPressForNote (const int midiNoteOffsetFromC)
  60349. {
  60350. for (int i = keyPressNotes.size(); --i >= 0;)
  60351. {
  60352. if (keyPressNotes.getUnchecked (i) == midiNoteOffsetFromC)
  60353. {
  60354. keyPressNotes.remove (i);
  60355. keyPresses.remove (i);
  60356. }
  60357. }
  60358. }
  60359. void MidiKeyboardComponent::setKeyPressBaseOctave (const int newOctaveNumber)
  60360. {
  60361. jassert (newOctaveNumber >= 0 && newOctaveNumber <= 10);
  60362. keyMappingOctave = newOctaveNumber;
  60363. }
  60364. bool MidiKeyboardComponent::keyStateChanged (const bool /*isKeyDown*/)
  60365. {
  60366. bool keyPressUsed = false;
  60367. for (int i = keyPresses.size(); --i >= 0;)
  60368. {
  60369. const int note = 12 * keyMappingOctave + keyPressNotes.getUnchecked (i);
  60370. if (keyPresses.getReference(i).isCurrentlyDown())
  60371. {
  60372. if (! keysPressed [note])
  60373. {
  60374. keysPressed.setBit (note);
  60375. state.noteOn (midiChannel, note, velocity);
  60376. keyPressUsed = true;
  60377. }
  60378. }
  60379. else
  60380. {
  60381. if (keysPressed [note])
  60382. {
  60383. keysPressed.clearBit (note);
  60384. state.noteOff (midiChannel, note);
  60385. keyPressUsed = true;
  60386. }
  60387. }
  60388. }
  60389. return keyPressUsed;
  60390. }
  60391. void MidiKeyboardComponent::focusLost (FocusChangeType)
  60392. {
  60393. resetAnyKeysInUse();
  60394. }
  60395. END_JUCE_NAMESPACE
  60396. /*** End of inlined file: juce_MidiKeyboardComponent.cpp ***/
  60397. /*** Start of inlined file: juce_OpenGLComponent.cpp ***/
  60398. #if JUCE_OPENGL
  60399. BEGIN_JUCE_NAMESPACE
  60400. extern void juce_glViewport (const int w, const int h);
  60401. OpenGLPixelFormat::OpenGLPixelFormat (const int bitsPerRGBComponent,
  60402. const int alphaBits_,
  60403. const int depthBufferBits_,
  60404. const int stencilBufferBits_) throw()
  60405. : redBits (bitsPerRGBComponent),
  60406. greenBits (bitsPerRGBComponent),
  60407. blueBits (bitsPerRGBComponent),
  60408. alphaBits (alphaBits_),
  60409. depthBufferBits (depthBufferBits_),
  60410. stencilBufferBits (stencilBufferBits_),
  60411. accumulationBufferRedBits (0),
  60412. accumulationBufferGreenBits (0),
  60413. accumulationBufferBlueBits (0),
  60414. accumulationBufferAlphaBits (0),
  60415. fullSceneAntiAliasingNumSamples (0)
  60416. {
  60417. }
  60418. bool OpenGLPixelFormat::operator== (const OpenGLPixelFormat& other) const throw()
  60419. {
  60420. return memcmp (this, &other, sizeof (other)) == 0;
  60421. }
  60422. static VoidArray knownContexts;
  60423. OpenGLContext::OpenGLContext() throw()
  60424. {
  60425. knownContexts.add (this);
  60426. }
  60427. OpenGLContext::~OpenGLContext()
  60428. {
  60429. knownContexts.removeValue (this);
  60430. }
  60431. OpenGLContext* OpenGLContext::getCurrentContext()
  60432. {
  60433. for (int i = knownContexts.size(); --i >= 0;)
  60434. {
  60435. OpenGLContext* const oglc = (OpenGLContext*) knownContexts.getUnchecked(i);
  60436. if (oglc->isActive())
  60437. return oglc;
  60438. }
  60439. return 0;
  60440. }
  60441. class OpenGLComponent::OpenGLComponentWatcher : public ComponentMovementWatcher
  60442. {
  60443. public:
  60444. OpenGLComponentWatcher (OpenGLComponent* const owner_)
  60445. : ComponentMovementWatcher (owner_),
  60446. owner (owner_),
  60447. wasShowing (false)
  60448. {
  60449. }
  60450. ~OpenGLComponentWatcher() {}
  60451. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  60452. {
  60453. owner->updateContextPosition();
  60454. }
  60455. void componentPeerChanged()
  60456. {
  60457. const ScopedLock sl (owner->getContextLock());
  60458. owner->deleteContext();
  60459. }
  60460. void componentVisibilityChanged (Component&)
  60461. {
  60462. const bool isShowingNow = owner->isShowing();
  60463. if (wasShowing != isShowingNow)
  60464. {
  60465. wasShowing = isShowingNow;
  60466. owner->updateContextPosition();
  60467. }
  60468. }
  60469. juce_UseDebuggingNewOperator
  60470. private:
  60471. OpenGLComponent* const owner;
  60472. bool wasShowing;
  60473. };
  60474. OpenGLComponent::OpenGLComponent()
  60475. : context (0),
  60476. contextToShareListsWith (0),
  60477. needToUpdateViewport (true)
  60478. {
  60479. setOpaque (true);
  60480. componentWatcher = new OpenGLComponentWatcher (this);
  60481. }
  60482. OpenGLComponent::~OpenGLComponent()
  60483. {
  60484. deleteContext();
  60485. componentWatcher = 0;
  60486. }
  60487. void OpenGLComponent::deleteContext()
  60488. {
  60489. const ScopedLock sl (contextLock);
  60490. deleteAndZero (context);
  60491. }
  60492. void OpenGLComponent::updateContextPosition()
  60493. {
  60494. needToUpdateViewport = true;
  60495. if (getWidth() > 0 && getHeight() > 0)
  60496. {
  60497. Component* const topComp = getTopLevelComponent();
  60498. if (topComp->getPeer() != 0)
  60499. {
  60500. const ScopedLock sl (contextLock);
  60501. if (context != 0)
  60502. context->updateWindowPosition (getScreenX() - topComp->getScreenX(),
  60503. getScreenY() - topComp->getScreenY(),
  60504. getWidth(),
  60505. getHeight(),
  60506. topComp->getHeight());
  60507. }
  60508. }
  60509. }
  60510. const OpenGLPixelFormat OpenGLComponent::getPixelFormat() const
  60511. {
  60512. OpenGLPixelFormat pf;
  60513. const ScopedLock sl (contextLock);
  60514. if (context != 0)
  60515. pf = context->getPixelFormat();
  60516. return pf;
  60517. }
  60518. void OpenGLComponent::setPixelFormat (const OpenGLPixelFormat& formatToUse)
  60519. {
  60520. if (! (preferredPixelFormat == formatToUse))
  60521. {
  60522. const ScopedLock sl (contextLock);
  60523. deleteContext();
  60524. preferredPixelFormat = formatToUse;
  60525. }
  60526. }
  60527. void OpenGLComponent::shareWith (OpenGLContext* c)
  60528. {
  60529. if (contextToShareListsWith != c)
  60530. {
  60531. const ScopedLock sl (contextLock);
  60532. deleteContext();
  60533. contextToShareListsWith = c;
  60534. }
  60535. }
  60536. bool OpenGLComponent::makeCurrentContextActive()
  60537. {
  60538. if (context == 0)
  60539. {
  60540. const ScopedLock sl (contextLock);
  60541. if (isShowing() && getTopLevelComponent()->getPeer() != 0)
  60542. {
  60543. context = OpenGLContext::createContextForWindow (this,
  60544. preferredPixelFormat,
  60545. contextToShareListsWith);
  60546. if (context != 0)
  60547. {
  60548. updateContextPosition();
  60549. if (context->makeActive())
  60550. newOpenGLContextCreated();
  60551. }
  60552. }
  60553. }
  60554. return context != 0 && context->makeActive();
  60555. }
  60556. void OpenGLComponent::makeCurrentContextInactive()
  60557. {
  60558. if (context != 0)
  60559. context->makeInactive();
  60560. }
  60561. bool OpenGLComponent::isActiveContext() const throw()
  60562. {
  60563. return context != 0 && context->isActive();
  60564. }
  60565. void OpenGLComponent::swapBuffers()
  60566. {
  60567. if (context != 0)
  60568. context->swapBuffers();
  60569. }
  60570. void OpenGLComponent::paint (Graphics&)
  60571. {
  60572. if (renderAndSwapBuffers())
  60573. {
  60574. ComponentPeer* const peer = getPeer();
  60575. if (peer != 0)
  60576. {
  60577. const Point<int> topLeft (getScreenPosition() - peer->getScreenPosition());
  60578. peer->addMaskedRegion (topLeft.getX(), topLeft.getY(), getWidth(), getHeight());
  60579. }
  60580. }
  60581. }
  60582. bool OpenGLComponent::renderAndSwapBuffers()
  60583. {
  60584. const ScopedLock sl (contextLock);
  60585. if (! makeCurrentContextActive())
  60586. return false;
  60587. if (needToUpdateViewport)
  60588. {
  60589. needToUpdateViewport = false;
  60590. juce_glViewport (getWidth(), getHeight());
  60591. }
  60592. renderOpenGL();
  60593. swapBuffers();
  60594. return true;
  60595. }
  60596. void OpenGLComponent::internalRepaint (int x, int y, int w, int h)
  60597. {
  60598. Component::internalRepaint (x, y, w, h);
  60599. if (context != 0)
  60600. context->repaint();
  60601. }
  60602. END_JUCE_NAMESPACE
  60603. #endif
  60604. /*** End of inlined file: juce_OpenGLComponent.cpp ***/
  60605. /*** Start of inlined file: juce_PreferencesPanel.cpp ***/
  60606. BEGIN_JUCE_NAMESPACE
  60607. PreferencesPanel::PreferencesPanel()
  60608. : buttonSize (70)
  60609. {
  60610. }
  60611. PreferencesPanel::~PreferencesPanel()
  60612. {
  60613. currentPage = 0;
  60614. deleteAllChildren();
  60615. }
  60616. void PreferencesPanel::addSettingsPage (const String& title,
  60617. const Drawable* icon,
  60618. const Drawable* overIcon,
  60619. const Drawable* downIcon)
  60620. {
  60621. DrawableButton* button = new DrawableButton (title, DrawableButton::ImageAboveTextLabel);
  60622. button->setImages (icon, overIcon, downIcon);
  60623. button->setRadioGroupId (1);
  60624. button->addButtonListener (this);
  60625. button->setClickingTogglesState (true);
  60626. button->setWantsKeyboardFocus (false);
  60627. addAndMakeVisible (button);
  60628. resized();
  60629. if (currentPage == 0)
  60630. setCurrentPage (title);
  60631. }
  60632. void PreferencesPanel::addSettingsPage (const String& title,
  60633. const char* imageData,
  60634. const int imageDataSize)
  60635. {
  60636. DrawableImage icon, iconOver, iconDown;
  60637. icon.setImage (ImageCache::getFromMemory (imageData, imageDataSize), true);
  60638. iconOver.setImage (ImageCache::getFromMemory (imageData, imageDataSize), true);
  60639. iconOver.setOverlayColour (Colours::black.withAlpha (0.12f));
  60640. iconDown.setImage (ImageCache::getFromMemory (imageData, imageDataSize), true);
  60641. iconDown.setOverlayColour (Colours::black.withAlpha (0.25f));
  60642. addSettingsPage (title, &icon, &iconOver, &iconDown);
  60643. }
  60644. class PrefsDialogWindow : public DialogWindow
  60645. {
  60646. public:
  60647. PrefsDialogWindow (const String& dialogtitle,
  60648. const Colour& backgroundColour)
  60649. : DialogWindow (dialogtitle, backgroundColour, true)
  60650. {
  60651. }
  60652. ~PrefsDialogWindow()
  60653. {
  60654. }
  60655. void closeButtonPressed()
  60656. {
  60657. exitModalState (0);
  60658. }
  60659. private:
  60660. PrefsDialogWindow (const PrefsDialogWindow&);
  60661. PrefsDialogWindow& operator= (const PrefsDialogWindow&);
  60662. };
  60663. void PreferencesPanel::showInDialogBox (const String& dialogtitle,
  60664. int dialogWidth,
  60665. int dialogHeight,
  60666. const Colour& backgroundColour)
  60667. {
  60668. setSize (dialogWidth, dialogHeight);
  60669. PrefsDialogWindow dw (dialogtitle, backgroundColour);
  60670. dw.setContentComponent (this, true, true);
  60671. dw.centreAroundComponent (0, dw.getWidth(), dw.getHeight());
  60672. dw.runModalLoop();
  60673. dw.setContentComponent (0, false, false);
  60674. }
  60675. void PreferencesPanel::resized()
  60676. {
  60677. int x = 0;
  60678. for (int i = 0; i < getNumChildComponents(); ++i)
  60679. {
  60680. Component* c = getChildComponent (i);
  60681. if (dynamic_cast <DrawableButton*> (c) == 0)
  60682. {
  60683. c->setBounds (0, buttonSize + 5, getWidth(), getHeight() - buttonSize - 5);
  60684. }
  60685. else
  60686. {
  60687. c->setBounds (x, 0, buttonSize, buttonSize);
  60688. x += buttonSize;
  60689. }
  60690. }
  60691. }
  60692. void PreferencesPanel::paint (Graphics& g)
  60693. {
  60694. g.setColour (Colours::grey);
  60695. g.fillRect (0, buttonSize + 2, getWidth(), 1);
  60696. }
  60697. void PreferencesPanel::setCurrentPage (const String& pageName)
  60698. {
  60699. if (currentPageName != pageName)
  60700. {
  60701. currentPageName = pageName;
  60702. currentPage = 0;
  60703. currentPage = createComponentForPage (pageName);
  60704. if (currentPage != 0)
  60705. {
  60706. addAndMakeVisible (currentPage);
  60707. currentPage->toBack();
  60708. resized();
  60709. }
  60710. for (int i = 0; i < getNumChildComponents(); ++i)
  60711. {
  60712. DrawableButton* db = dynamic_cast <DrawableButton*> (getChildComponent (i));
  60713. if (db != 0 && db->getName() == pageName)
  60714. {
  60715. db->setToggleState (true, false);
  60716. break;
  60717. }
  60718. }
  60719. }
  60720. }
  60721. void PreferencesPanel::buttonClicked (Button*)
  60722. {
  60723. for (int i = 0; i < getNumChildComponents(); ++i)
  60724. {
  60725. DrawableButton* db = dynamic_cast <DrawableButton*> (getChildComponent (i));
  60726. if (db != 0 && db->getToggleState())
  60727. {
  60728. setCurrentPage (db->getName());
  60729. break;
  60730. }
  60731. }
  60732. }
  60733. END_JUCE_NAMESPACE
  60734. /*** End of inlined file: juce_PreferencesPanel.cpp ***/
  60735. /*** Start of inlined file: juce_SystemTrayIconComponent.cpp ***/
  60736. #if JUCE_WINDOWS || JUCE_LINUX
  60737. BEGIN_JUCE_NAMESPACE
  60738. SystemTrayIconComponent::SystemTrayIconComponent()
  60739. {
  60740. addToDesktop (0);
  60741. }
  60742. SystemTrayIconComponent::~SystemTrayIconComponent()
  60743. {
  60744. }
  60745. END_JUCE_NAMESPACE
  60746. #endif
  60747. /*** End of inlined file: juce_SystemTrayIconComponent.cpp ***/
  60748. /*** Start of inlined file: juce_AlertWindow.cpp ***/
  60749. BEGIN_JUCE_NAMESPACE
  60750. static const int titleH = 24;
  60751. static const int iconWidth = 80;
  60752. class AlertWindowTextEditor : public TextEditor
  60753. {
  60754. public:
  60755. static const tchar passwordChar;
  60756. AlertWindowTextEditor (const String& name, const bool isPasswordBox)
  60757. : TextEditor (name, isPasswordBox ? passwordChar : 0)
  60758. {
  60759. setSelectAllWhenFocused (true);
  60760. }
  60761. ~AlertWindowTextEditor()
  60762. {
  60763. }
  60764. void returnPressed()
  60765. {
  60766. // pass these up the component hierarchy to be trigger the buttons
  60767. getParentComponent()->keyPressed (KeyPress (KeyPress::returnKey, 0, T('\n')));
  60768. }
  60769. void escapePressed()
  60770. {
  60771. // pass these up the component hierarchy to be trigger the buttons
  60772. getParentComponent()->keyPressed (KeyPress (KeyPress::escapeKey, 0, 0));
  60773. }
  60774. private:
  60775. AlertWindowTextEditor (const AlertWindowTextEditor&);
  60776. AlertWindowTextEditor& operator= (const AlertWindowTextEditor&);
  60777. };
  60778. #if JUCE_LINUX
  60779. const tchar AlertWindowTextEditor::passwordChar = 0x2022;
  60780. #else
  60781. const tchar AlertWindowTextEditor::passwordChar = 0x25cf;
  60782. #endif
  60783. AlertWindow::AlertWindow (const String& title,
  60784. const String& message,
  60785. AlertIconType iconType,
  60786. Component* associatedComponent_)
  60787. : TopLevelWindow (title, true),
  60788. alertIconType (iconType),
  60789. associatedComponent (associatedComponent_)
  60790. {
  60791. if (message.isEmpty())
  60792. text = T(" "); // to force an update if the message is empty
  60793. setMessage (message);
  60794. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  60795. {
  60796. Component* const c = Desktop::getInstance().getComponent (i);
  60797. if (c != 0 && c->isAlwaysOnTop() && c->isShowing())
  60798. {
  60799. setAlwaysOnTop (true);
  60800. break;
  60801. }
  60802. }
  60803. if (JUCEApplication::getInstance() == 0)
  60804. setAlwaysOnTop (true); // for a plugin, make it always-on-top because the host windows are often top-level
  60805. lookAndFeelChanged();
  60806. constrainer.setMinimumOnscreenAmounts (0x10000, 0x10000, 0x10000, 0x10000);
  60807. }
  60808. AlertWindow::~AlertWindow()
  60809. {
  60810. for (int i = customComps.size(); --i >= 0;)
  60811. removeChildComponent ((Component*) customComps[i]);
  60812. deleteAllChildren();
  60813. }
  60814. void AlertWindow::userTriedToCloseWindow()
  60815. {
  60816. exitModalState (0);
  60817. }
  60818. void AlertWindow::setMessage (const String& message)
  60819. {
  60820. const String newMessage (message.substring (0, 2048));
  60821. if (text != newMessage)
  60822. {
  60823. text = newMessage;
  60824. font.setHeight (15.0f);
  60825. Font titleFont (font.getHeight() * 1.1f, Font::bold);
  60826. textLayout.setText (getName() + T("\n\n"), titleFont);
  60827. textLayout.appendText (text, font);
  60828. updateLayout (true);
  60829. repaint();
  60830. }
  60831. }
  60832. void AlertWindow::buttonClicked (Button* button)
  60833. {
  60834. for (int i = 0; i < buttons.size(); i++)
  60835. {
  60836. TextButton* const c = (TextButton*) buttons[i];
  60837. if (button->getName() == c->getName())
  60838. {
  60839. if (c->getParentComponent() != 0)
  60840. c->getParentComponent()->exitModalState (c->getCommandID());
  60841. break;
  60842. }
  60843. }
  60844. }
  60845. void AlertWindow::addButton (const String& name,
  60846. const int returnValue,
  60847. const KeyPress& shortcutKey1,
  60848. const KeyPress& shortcutKey2)
  60849. {
  60850. TextButton* const b = new TextButton (name, String::empty);
  60851. b->setWantsKeyboardFocus (true);
  60852. b->setMouseClickGrabsKeyboardFocus (false);
  60853. b->setCommandToTrigger (0, returnValue, false);
  60854. b->addShortcut (shortcutKey1);
  60855. b->addShortcut (shortcutKey2);
  60856. b->addButtonListener (this);
  60857. b->changeWidthToFitText (getLookAndFeel().getAlertWindowButtonHeight());
  60858. addAndMakeVisible (b, 0);
  60859. buttons.add (b);
  60860. updateLayout (false);
  60861. }
  60862. int AlertWindow::getNumButtons() const
  60863. {
  60864. return buttons.size();
  60865. }
  60866. void AlertWindow::addTextEditor (const String& name,
  60867. const String& initialContents,
  60868. const String& onScreenLabel,
  60869. const bool isPasswordBox)
  60870. {
  60871. AlertWindowTextEditor* const tc = new AlertWindowTextEditor (name, isPasswordBox);
  60872. tc->setColour (TextEditor::outlineColourId, findColour (ComboBox::outlineColourId));
  60873. tc->setFont (font);
  60874. tc->setText (initialContents);
  60875. tc->setCaretPosition (initialContents.length());
  60876. addAndMakeVisible (tc);
  60877. textBoxes.add (tc);
  60878. allComps.add (tc);
  60879. textboxNames.add (onScreenLabel);
  60880. updateLayout (false);
  60881. }
  60882. const String AlertWindow::getTextEditorContents (const String& nameOfTextEditor) const
  60883. {
  60884. for (int i = textBoxes.size(); --i >= 0;)
  60885. if (((TextEditor*)textBoxes[i])->getName() == nameOfTextEditor)
  60886. return ((TextEditor*)textBoxes[i])->getText();
  60887. return String::empty;
  60888. }
  60889. void AlertWindow::addComboBox (const String& name,
  60890. const StringArray& items,
  60891. const String& onScreenLabel)
  60892. {
  60893. ComboBox* const cb = new ComboBox (name);
  60894. for (int i = 0; i < items.size(); ++i)
  60895. cb->addItem (items[i], i + 1);
  60896. addAndMakeVisible (cb);
  60897. cb->setSelectedItemIndex (0);
  60898. comboBoxes.add (cb);
  60899. allComps.add (cb);
  60900. comboBoxNames.add (onScreenLabel);
  60901. updateLayout (false);
  60902. }
  60903. ComboBox* AlertWindow::getComboBoxComponent (const String& nameOfList) const
  60904. {
  60905. for (int i = comboBoxes.size(); --i >= 0;)
  60906. if (((ComboBox*) comboBoxes[i])->getName() == nameOfList)
  60907. return (ComboBox*) comboBoxes[i];
  60908. return 0;
  60909. }
  60910. class AlertTextComp : public TextEditor
  60911. {
  60912. public:
  60913. AlertTextComp (const String& message,
  60914. const Font& font)
  60915. {
  60916. setReadOnly (true);
  60917. setMultiLine (true, true);
  60918. setCaretVisible (false);
  60919. setScrollbarsShown (true);
  60920. lookAndFeelChanged();
  60921. setWantsKeyboardFocus (false);
  60922. setFont (font);
  60923. setText (message, false);
  60924. bestWidth = 2 * (int) sqrt (font.getHeight() * font.getStringWidth (message));
  60925. setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  60926. setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  60927. setColour (TextEditor::shadowColourId, Colours::transparentBlack);
  60928. }
  60929. ~AlertTextComp()
  60930. {
  60931. }
  60932. int getPreferredWidth() const throw() { return bestWidth; }
  60933. void updateLayout (const int width)
  60934. {
  60935. TextLayout text;
  60936. text.appendText (getText(), getFont());
  60937. text.layout (width - 8, Justification::topLeft, true);
  60938. setSize (width, jmin (width, text.getHeight() + (int) getFont().getHeight()));
  60939. }
  60940. private:
  60941. int bestWidth;
  60942. AlertTextComp (const AlertTextComp&);
  60943. AlertTextComp& operator= (const AlertTextComp&);
  60944. };
  60945. void AlertWindow::addTextBlock (const String& text)
  60946. {
  60947. AlertTextComp* const c = new AlertTextComp (text, font);
  60948. textBlocks.add (c);
  60949. allComps.add (c);
  60950. addAndMakeVisible (c);
  60951. updateLayout (false);
  60952. }
  60953. void AlertWindow::addProgressBarComponent (double& progressValue)
  60954. {
  60955. ProgressBar* const pb = new ProgressBar (progressValue);
  60956. progressBars.add (pb);
  60957. allComps.add (pb);
  60958. addAndMakeVisible (pb);
  60959. updateLayout (false);
  60960. }
  60961. void AlertWindow::addCustomComponent (Component* const component)
  60962. {
  60963. customComps.add (component);
  60964. allComps.add (component);
  60965. addAndMakeVisible (component);
  60966. updateLayout (false);
  60967. }
  60968. int AlertWindow::getNumCustomComponents() const
  60969. {
  60970. return customComps.size();
  60971. }
  60972. Component* AlertWindow::getCustomComponent (const int index) const
  60973. {
  60974. return (Component*) customComps [index];
  60975. }
  60976. Component* AlertWindow::removeCustomComponent (const int index)
  60977. {
  60978. Component* const c = getCustomComponent (index);
  60979. if (c != 0)
  60980. {
  60981. customComps.removeValue (c);
  60982. allComps.removeValue (c);
  60983. removeChildComponent (c);
  60984. updateLayout (false);
  60985. }
  60986. return c;
  60987. }
  60988. void AlertWindow::paint (Graphics& g)
  60989. {
  60990. getLookAndFeel().drawAlertBox (g, *this, textArea, textLayout);
  60991. g.setColour (findColour (textColourId));
  60992. g.setFont (getLookAndFeel().getAlertWindowFont());
  60993. int i;
  60994. for (i = textBoxes.size(); --i >= 0;)
  60995. {
  60996. const TextEditor* const te = (TextEditor*) textBoxes[i];
  60997. g.drawFittedText (textboxNames[i],
  60998. te->getX(), te->getY() - 14,
  60999. te->getWidth(), 14,
  61000. Justification::centredLeft, 1);
  61001. }
  61002. for (i = comboBoxNames.size(); --i >= 0;)
  61003. {
  61004. const ComboBox* const cb = (ComboBox*) comboBoxes[i];
  61005. g.drawFittedText (comboBoxNames[i],
  61006. cb->getX(), cb->getY() - 14,
  61007. cb->getWidth(), 14,
  61008. Justification::centredLeft, 1);
  61009. }
  61010. for (i = customComps.size(); --i >= 0;)
  61011. {
  61012. const Component* const c = (Component*) customComps[i];
  61013. g.drawFittedText (c->getName(),
  61014. c->getX(), c->getY() - 14,
  61015. c->getWidth(), 14,
  61016. Justification::centredLeft, 1);
  61017. }
  61018. }
  61019. void AlertWindow::updateLayout (const bool onlyIncreaseSize)
  61020. {
  61021. const int wid = jmax (font.getStringWidth (text),
  61022. font.getStringWidth (getName()));
  61023. const int sw = (int) sqrt (font.getHeight() * wid);
  61024. int w = jmin (300 + sw * 2, (int) (getParentWidth() * 0.7f));
  61025. const int edgeGap = 10;
  61026. const int labelHeight = 18;
  61027. int iconSpace;
  61028. if (alertIconType == NoIcon)
  61029. {
  61030. textLayout.layout (w, Justification::horizontallyCentred, true);
  61031. iconSpace = 0;
  61032. }
  61033. else
  61034. {
  61035. textLayout.layout (w, Justification::left, true);
  61036. iconSpace = iconWidth;
  61037. }
  61038. w = jmax (350, textLayout.getWidth() + iconSpace + edgeGap * 4);
  61039. w = jmin (w, (int) (getParentWidth() * 0.7f));
  61040. const int textLayoutH = textLayout.getHeight();
  61041. const int textBottom = 16 + titleH + textLayoutH;
  61042. int h = textBottom;
  61043. int buttonW = 40;
  61044. int i;
  61045. for (i = 0; i < buttons.size(); ++i)
  61046. buttonW += 16 + ((const TextButton*) buttons[i])->getWidth();
  61047. w = jmax (buttonW, w);
  61048. h += (textBoxes.size() + comboBoxes.size() + progressBars.size()) * 50;
  61049. if (buttons.size() > 0)
  61050. h += 20 + ((TextButton*) buttons[0])->getHeight();
  61051. for (i = customComps.size(); --i >= 0;)
  61052. {
  61053. Component* c = (Component*) customComps[i];
  61054. w = jmax (w, (c->getWidth() * 100) / 80);
  61055. h += 10 + c->getHeight();
  61056. if (c->getName().isNotEmpty())
  61057. h += labelHeight;
  61058. }
  61059. for (i = textBlocks.size(); --i >= 0;)
  61060. {
  61061. const AlertTextComp* const ac = (AlertTextComp*) textBlocks[i];
  61062. w = jmax (w, ac->getPreferredWidth());
  61063. }
  61064. w = jmin (w, (int) (getParentWidth() * 0.7f));
  61065. for (i = textBlocks.size(); --i >= 0;)
  61066. {
  61067. AlertTextComp* const ac = (AlertTextComp*) textBlocks[i];
  61068. ac->updateLayout ((int) (w * 0.8f));
  61069. h += ac->getHeight() + 10;
  61070. }
  61071. h = jmin (getParentHeight() - 50, h);
  61072. if (onlyIncreaseSize)
  61073. {
  61074. w = jmax (w, getWidth());
  61075. h = jmax (h, getHeight());
  61076. }
  61077. if (! isVisible())
  61078. {
  61079. centreAroundComponent (associatedComponent, w, h);
  61080. }
  61081. else
  61082. {
  61083. const int cx = getX() + getWidth() / 2;
  61084. const int cy = getY() + getHeight() / 2;
  61085. setBounds (cx - w / 2,
  61086. cy - h / 2,
  61087. w, h);
  61088. }
  61089. textArea.setBounds (edgeGap, edgeGap, w - (edgeGap * 2), h - edgeGap);
  61090. const int spacer = 16;
  61091. int totalWidth = -spacer;
  61092. for (i = buttons.size(); --i >= 0;)
  61093. totalWidth += ((TextButton*) buttons[i])->getWidth() + spacer;
  61094. int x = (w - totalWidth) / 2;
  61095. int y = (int) (getHeight() * 0.95f);
  61096. for (i = 0; i < buttons.size(); ++i)
  61097. {
  61098. TextButton* const c = (TextButton*) buttons[i];
  61099. int ny = proportionOfHeight (0.95f) - c->getHeight();
  61100. c->setTopLeftPosition (x, ny);
  61101. if (ny < y)
  61102. y = ny;
  61103. x += c->getWidth() + spacer;
  61104. c->toFront (false);
  61105. }
  61106. y = textBottom;
  61107. for (i = 0; i < allComps.size(); ++i)
  61108. {
  61109. Component* const c = (Component*) allComps[i];
  61110. int h = 22;
  61111. const int comboIndex = comboBoxes.indexOf (c);
  61112. if (comboIndex >= 0 && comboBoxNames [comboIndex].isNotEmpty())
  61113. y += labelHeight;
  61114. const int tbIndex = textBoxes.indexOf (c);
  61115. if (tbIndex >= 0 && textboxNames[tbIndex].isNotEmpty())
  61116. y += labelHeight;
  61117. if (customComps.contains (c))
  61118. {
  61119. if (c->getName().isNotEmpty())
  61120. y += labelHeight;
  61121. c->setTopLeftPosition (proportionOfWidth (0.1f), y);
  61122. h = c->getHeight();
  61123. }
  61124. else if (textBlocks.contains (c))
  61125. {
  61126. c->setTopLeftPosition ((getWidth() - c->getWidth()) / 2, y);
  61127. h = c->getHeight();
  61128. }
  61129. else
  61130. {
  61131. c->setBounds (proportionOfWidth (0.1f), y, proportionOfWidth (0.8f), h);
  61132. }
  61133. y += h + 10;
  61134. }
  61135. setWantsKeyboardFocus (getNumChildComponents() == 0);
  61136. }
  61137. bool AlertWindow::containsAnyExtraComponents() const
  61138. {
  61139. return textBoxes.size()
  61140. + comboBoxes.size()
  61141. + progressBars.size()
  61142. + customComps.size() > 0;
  61143. }
  61144. void AlertWindow::mouseDown (const MouseEvent&)
  61145. {
  61146. dragger.startDraggingComponent (this, &constrainer);
  61147. }
  61148. void AlertWindow::mouseDrag (const MouseEvent& e)
  61149. {
  61150. dragger.dragComponent (this, e);
  61151. }
  61152. bool AlertWindow::keyPressed (const KeyPress& key)
  61153. {
  61154. for (int i = buttons.size(); --i >= 0;)
  61155. {
  61156. TextButton* const b = (TextButton*) buttons[i];
  61157. if (b->isRegisteredForShortcut (key))
  61158. {
  61159. b->triggerClick();
  61160. return true;
  61161. }
  61162. }
  61163. if (key.isKeyCode (KeyPress::escapeKey) && buttons.size() == 0)
  61164. {
  61165. exitModalState (0);
  61166. return true;
  61167. }
  61168. else if (key.isKeyCode (KeyPress::returnKey) && buttons.size() == 1)
  61169. {
  61170. ((TextButton*) buttons.getFirst())->triggerClick();
  61171. return true;
  61172. }
  61173. return false;
  61174. }
  61175. void AlertWindow::lookAndFeelChanged()
  61176. {
  61177. const int flags = getLookAndFeel().getAlertBoxWindowFlags();
  61178. setUsingNativeTitleBar ((flags & ComponentPeer::windowHasTitleBar) != 0);
  61179. setDropShadowEnabled (isOpaque() && (flags & ComponentPeer::windowHasDropShadow) != 0);
  61180. }
  61181. int AlertWindow::getDesktopWindowStyleFlags() const
  61182. {
  61183. return getLookAndFeel().getAlertBoxWindowFlags();
  61184. }
  61185. struct AlertWindowInfo
  61186. {
  61187. String title, message, button1, button2, button3;
  61188. AlertWindow::AlertIconType iconType;
  61189. int numButtons;
  61190. Component::SafePointer<Component> associatedComponent;
  61191. int run() const
  61192. {
  61193. return (int) (pointer_sized_int)
  61194. MessageManager::getInstance()->callFunctionOnMessageThread (showCallback, (void*) this);
  61195. }
  61196. private:
  61197. int show() const
  61198. {
  61199. LookAndFeel& lf = associatedComponent != 0 ? associatedComponent->getLookAndFeel()
  61200. : LookAndFeel::getDefaultLookAndFeel();
  61201. ScopedPointer <Component> alertBox (lf.createAlertWindow (title, message, button1, button2, button3,
  61202. iconType, numButtons, associatedComponent));
  61203. jassert (alertBox != 0); // you have to return one of these!
  61204. return alertBox->runModalLoop();
  61205. }
  61206. static void* showCallback (void* userData)
  61207. {
  61208. return (void*) (pointer_sized_int) ((const AlertWindowInfo*) userData)->show();
  61209. }
  61210. };
  61211. void AlertWindow::showMessageBox (AlertIconType iconType,
  61212. const String& title,
  61213. const String& message,
  61214. const String& buttonText,
  61215. Component* associatedComponent)
  61216. {
  61217. AlertWindowInfo info;
  61218. info.title = title;
  61219. info.message = message;
  61220. info.button1 = buttonText.isEmpty() ? TRANS("ok") : buttonText;
  61221. info.iconType = iconType;
  61222. info.numButtons = 1;
  61223. info.associatedComponent = associatedComponent;
  61224. info.run();
  61225. }
  61226. bool AlertWindow::showOkCancelBox (AlertIconType iconType,
  61227. const String& title,
  61228. const String& message,
  61229. const String& button1Text,
  61230. const String& button2Text,
  61231. Component* associatedComponent)
  61232. {
  61233. AlertWindowInfo info;
  61234. info.title = title;
  61235. info.message = message;
  61236. info.button1 = button1Text.isEmpty() ? TRANS("ok") : button1Text;
  61237. info.button2 = button2Text.isEmpty() ? TRANS("cancel") : button2Text;
  61238. info.iconType = iconType;
  61239. info.numButtons = 2;
  61240. info.associatedComponent = associatedComponent;
  61241. return info.run() != 0;
  61242. }
  61243. int AlertWindow::showYesNoCancelBox (AlertIconType iconType,
  61244. const String& title,
  61245. const String& message,
  61246. const String& button1Text,
  61247. const String& button2Text,
  61248. const String& button3Text,
  61249. Component* associatedComponent)
  61250. {
  61251. AlertWindowInfo info;
  61252. info.title = title;
  61253. info.message = message;
  61254. info.button1 = button1Text.isEmpty() ? TRANS("yes") : button1Text;
  61255. info.button2 = button2Text.isEmpty() ? TRANS("no") : button2Text;
  61256. info.button3 = button3Text.isEmpty() ? TRANS("cancel") : button3Text;
  61257. info.iconType = iconType;
  61258. info.numButtons = 3;
  61259. info.associatedComponent = associatedComponent;
  61260. return info.run();
  61261. }
  61262. END_JUCE_NAMESPACE
  61263. /*** End of inlined file: juce_AlertWindow.cpp ***/
  61264. /*** Start of inlined file: juce_ComponentPeer.cpp ***/
  61265. BEGIN_JUCE_NAMESPACE
  61266. //#define JUCE_ENABLE_REPAINT_DEBUGGING 1
  61267. static VoidArray heavyweightPeers;
  61268. ComponentPeer::ComponentPeer (Component* const component_,
  61269. const int styleFlags_) throw()
  61270. : component (component_),
  61271. styleFlags (styleFlags_),
  61272. lastPaintTime (0),
  61273. constrainer (0),
  61274. lastDragAndDropCompUnderMouse (0),
  61275. fakeMouseMessageSent (false),
  61276. isWindowMinimised (false)
  61277. {
  61278. heavyweightPeers.add (this);
  61279. }
  61280. ComponentPeer::~ComponentPeer()
  61281. {
  61282. heavyweightPeers.removeValue (this);
  61283. Desktop::getInstance().triggerFocusCallback();
  61284. }
  61285. int ComponentPeer::getNumPeers() throw()
  61286. {
  61287. return heavyweightPeers.size();
  61288. }
  61289. ComponentPeer* ComponentPeer::getPeer (const int index) throw()
  61290. {
  61291. return (ComponentPeer*) heavyweightPeers [index];
  61292. }
  61293. ComponentPeer* ComponentPeer::getPeerFor (const Component* const component) throw()
  61294. {
  61295. for (int i = heavyweightPeers.size(); --i >= 0;)
  61296. {
  61297. ComponentPeer* const peer = (ComponentPeer*) heavyweightPeers.getUnchecked(i);
  61298. if (peer->getComponent() == component)
  61299. return peer;
  61300. }
  61301. return 0;
  61302. }
  61303. bool ComponentPeer::isValidPeer (const ComponentPeer* const peer) throw()
  61304. {
  61305. return heavyweightPeers.contains (const_cast <ComponentPeer*> (peer));
  61306. }
  61307. void ComponentPeer::updateCurrentModifiers() throw()
  61308. {
  61309. ModifierKeys::updateCurrentModifiers();
  61310. }
  61311. void ComponentPeer::handleMouseEvent (const int touchIndex, const Point<int>& positionWithinPeer, const ModifierKeys& newMods, const int64 time)
  61312. {
  61313. MouseInputSource* const mouse = Desktop::getInstance().getMouseSource (touchIndex);
  61314. jassert (mouse != 0); // not enough sources!
  61315. mouse->handleEvent (this, positionWithinPeer, time, newMods);
  61316. }
  61317. void ComponentPeer::handleMouseWheel (const int touchIndex, const Point<int>& positionWithinPeer, const int64 time, const float x, const float y)
  61318. {
  61319. MouseInputSource* const mouse = Desktop::getInstance().getMouseSource (touchIndex);
  61320. jassert (mouse != 0); // not enough sources!
  61321. mouse->handleWheel (this, positionWithinPeer, time, x, y);
  61322. }
  61323. void ComponentPeer::handlePaint (LowLevelGraphicsContext& contextToPaintTo)
  61324. {
  61325. Graphics g (&contextToPaintTo);
  61326. #if JUCE_ENABLE_REPAINT_DEBUGGING
  61327. g.saveState();
  61328. #endif
  61329. JUCE_TRY
  61330. {
  61331. component->paintEntireComponent (g);
  61332. }
  61333. JUCE_CATCH_EXCEPTION
  61334. #if JUCE_ENABLE_REPAINT_DEBUGGING
  61335. // enabling this code will fill all areas that get repainted with a colour overlay, to show
  61336. // clearly when things are being repainted.
  61337. {
  61338. g.restoreState();
  61339. g.fillAll (Colour ((uint8) Random::getSystemRandom().nextInt (255),
  61340. (uint8) Random::getSystemRandom().nextInt (255),
  61341. (uint8) Random::getSystemRandom().nextInt (255),
  61342. (uint8) 0x50));
  61343. }
  61344. #endif
  61345. }
  61346. bool ComponentPeer::handleKeyPress (const int keyCode,
  61347. const juce_wchar textCharacter)
  61348. {
  61349. updateCurrentModifiers();
  61350. Component* target = Component::getCurrentlyFocusedComponent() != 0
  61351. ? Component::getCurrentlyFocusedComponent()
  61352. : component;
  61353. if (target->isCurrentlyBlockedByAnotherModalComponent())
  61354. {
  61355. Component* const currentModalComp = Component::getCurrentlyModalComponent();
  61356. if (currentModalComp != 0)
  61357. target = currentModalComp;
  61358. }
  61359. const KeyPress keyInfo (keyCode,
  61360. ModifierKeys::getCurrentModifiers().getRawFlags()
  61361. & ModifierKeys::allKeyboardModifiers,
  61362. textCharacter);
  61363. bool keyWasUsed = false;
  61364. while (target != 0)
  61365. {
  61366. const Component::SafePointer<Component> deletionChecker (target);
  61367. if (target->keyListeners_ != 0)
  61368. {
  61369. for (int i = target->keyListeners_->size(); --i >= 0;)
  61370. {
  61371. keyWasUsed = ((KeyListener*) target->keyListeners_->getUnchecked(i))->keyPressed (keyInfo, target);
  61372. if (keyWasUsed || deletionChecker == 0)
  61373. return keyWasUsed;
  61374. i = jmin (i, target->keyListeners_->size());
  61375. }
  61376. }
  61377. keyWasUsed = target->keyPressed (keyInfo);
  61378. if (keyWasUsed || deletionChecker == 0)
  61379. break;
  61380. if (keyInfo.isKeyCode (KeyPress::tabKey) && Component::getCurrentlyFocusedComponent() != 0)
  61381. {
  61382. Component* const currentlyFocused = Component::getCurrentlyFocusedComponent();
  61383. currentlyFocused->moveKeyboardFocusToSibling (! keyInfo.getModifiers().isShiftDown());
  61384. keyWasUsed = (currentlyFocused != Component::getCurrentlyFocusedComponent());
  61385. break;
  61386. }
  61387. target = target->parentComponent_;
  61388. }
  61389. return keyWasUsed;
  61390. }
  61391. bool ComponentPeer::handleKeyUpOrDown (const bool isKeyDown)
  61392. {
  61393. updateCurrentModifiers();
  61394. Component* target = Component::getCurrentlyFocusedComponent() != 0
  61395. ? Component::getCurrentlyFocusedComponent()
  61396. : component;
  61397. if (target->isCurrentlyBlockedByAnotherModalComponent())
  61398. {
  61399. Component* const currentModalComp = Component::getCurrentlyModalComponent();
  61400. if (currentModalComp != 0)
  61401. target = currentModalComp;
  61402. }
  61403. bool keyWasUsed = false;
  61404. while (target != 0)
  61405. {
  61406. const Component::SafePointer<Component> deletionChecker (target);
  61407. keyWasUsed = target->keyStateChanged (isKeyDown);
  61408. if (keyWasUsed || deletionChecker == 0)
  61409. break;
  61410. if (target->keyListeners_ != 0)
  61411. {
  61412. for (int i = target->keyListeners_->size(); --i >= 0;)
  61413. {
  61414. keyWasUsed = ((KeyListener*) target->keyListeners_->getUnchecked(i))->keyStateChanged (isKeyDown, target);
  61415. if (keyWasUsed || deletionChecker == 0)
  61416. return keyWasUsed;
  61417. i = jmin (i, target->keyListeners_->size());
  61418. }
  61419. }
  61420. target = target->parentComponent_;
  61421. }
  61422. return keyWasUsed;
  61423. }
  61424. void ComponentPeer::handleModifierKeysChange()
  61425. {
  61426. updateCurrentModifiers();
  61427. Component* target = Desktop::getInstance().getMainMouseSource().getComponentUnderMouse();
  61428. if (target == 0)
  61429. target = Component::getCurrentlyFocusedComponent();
  61430. if (target == 0)
  61431. target = component;
  61432. if (target != 0)
  61433. target->internalModifierKeysChanged();
  61434. }
  61435. TextInputTarget* ComponentPeer::findCurrentTextInputTarget()
  61436. {
  61437. Component* const c = Component::getCurrentlyFocusedComponent();
  61438. if (component->isParentOf (c))
  61439. return dynamic_cast <TextInputTarget*> (c);
  61440. return 0;
  61441. }
  61442. void ComponentPeer::handleBroughtToFront()
  61443. {
  61444. updateCurrentModifiers();
  61445. if (component != 0)
  61446. component->internalBroughtToFront();
  61447. }
  61448. void ComponentPeer::setConstrainer (ComponentBoundsConstrainer* const newConstrainer) throw()
  61449. {
  61450. constrainer = newConstrainer;
  61451. }
  61452. void ComponentPeer::handleMovedOrResized()
  61453. {
  61454. jassert (component->isValidComponent());
  61455. updateCurrentModifiers();
  61456. const bool nowMinimised = isMinimised();
  61457. if (component->flags.hasHeavyweightPeerFlag && ! nowMinimised)
  61458. {
  61459. const Component::SafePointer<Component> deletionChecker (component);
  61460. const Rectangle<int> newBounds (getBounds());
  61461. const bool wasMoved = (component->getPosition() != newBounds.getPosition());
  61462. const bool wasResized = (component->getWidth() != newBounds.getWidth() || component->getHeight() != newBounds.getHeight());
  61463. if (wasMoved || wasResized)
  61464. {
  61465. component->bounds_ = newBounds;
  61466. if (wasResized)
  61467. component->repaint();
  61468. component->sendMovedResizedMessages (wasMoved, wasResized);
  61469. if (deletionChecker == 0)
  61470. return;
  61471. }
  61472. }
  61473. if (isWindowMinimised != nowMinimised)
  61474. {
  61475. isWindowMinimised = nowMinimised;
  61476. component->minimisationStateChanged (nowMinimised);
  61477. component->sendVisibilityChangeMessage();
  61478. }
  61479. if (! isFullScreen())
  61480. lastNonFullscreenBounds = component->getBounds();
  61481. }
  61482. void ComponentPeer::handleFocusGain()
  61483. {
  61484. updateCurrentModifiers();
  61485. if (component->isParentOf (lastFocusedComponent))
  61486. {
  61487. Component::currentlyFocusedComponent = lastFocusedComponent;
  61488. Desktop::getInstance().triggerFocusCallback();
  61489. lastFocusedComponent->internalFocusGain (Component::focusChangedDirectly);
  61490. }
  61491. else
  61492. {
  61493. if (! component->isCurrentlyBlockedByAnotherModalComponent())
  61494. component->grabKeyboardFocus();
  61495. else
  61496. Component::bringModalComponentToFront();
  61497. }
  61498. }
  61499. void ComponentPeer::handleFocusLoss()
  61500. {
  61501. updateCurrentModifiers();
  61502. if (component->hasKeyboardFocus (true))
  61503. {
  61504. lastFocusedComponent = Component::currentlyFocusedComponent;
  61505. if (lastFocusedComponent != 0)
  61506. {
  61507. Component::currentlyFocusedComponent = 0;
  61508. Desktop::getInstance().triggerFocusCallback();
  61509. lastFocusedComponent->internalFocusLoss (Component::focusChangedByMouseClick);
  61510. }
  61511. }
  61512. }
  61513. Component* ComponentPeer::getLastFocusedSubcomponent() const throw()
  61514. {
  61515. return (component->isParentOf (lastFocusedComponent) && lastFocusedComponent->isShowing())
  61516. ? static_cast <Component*> (lastFocusedComponent)
  61517. : component;
  61518. }
  61519. void ComponentPeer::handleScreenSizeChange()
  61520. {
  61521. updateCurrentModifiers();
  61522. component->parentSizeChanged();
  61523. handleMovedOrResized();
  61524. }
  61525. void ComponentPeer::setNonFullScreenBounds (const Rectangle<int>& newBounds) throw()
  61526. {
  61527. lastNonFullscreenBounds = newBounds;
  61528. }
  61529. const Rectangle<int>& ComponentPeer::getNonFullScreenBounds() const throw()
  61530. {
  61531. return lastNonFullscreenBounds;
  61532. }
  61533. static FileDragAndDropTarget* findDragAndDropTarget (Component* c,
  61534. const StringArray& files,
  61535. FileDragAndDropTarget* const lastOne)
  61536. {
  61537. while (c != 0)
  61538. {
  61539. FileDragAndDropTarget* const t = dynamic_cast <FileDragAndDropTarget*> (c);
  61540. if (t != 0 && (t == lastOne || t->isInterestedInFileDrag (files)))
  61541. return t;
  61542. c = c->getParentComponent();
  61543. }
  61544. return 0;
  61545. }
  61546. void ComponentPeer::handleFileDragMove (const StringArray& files, const Point<int>& position)
  61547. {
  61548. updateCurrentModifiers();
  61549. FileDragAndDropTarget* lastTarget
  61550. = dynamic_cast<FileDragAndDropTarget*> (static_cast<Component*> (dragAndDropTargetComponent));
  61551. FileDragAndDropTarget* newTarget = 0;
  61552. Component* const compUnderMouse = component->getComponentAt (position);
  61553. if (compUnderMouse != lastDragAndDropCompUnderMouse)
  61554. {
  61555. lastDragAndDropCompUnderMouse = compUnderMouse;
  61556. newTarget = findDragAndDropTarget (compUnderMouse, files, lastTarget);
  61557. if (newTarget != lastTarget)
  61558. {
  61559. if (lastTarget != 0)
  61560. lastTarget->fileDragExit (files);
  61561. dragAndDropTargetComponent = 0;
  61562. if (newTarget != 0)
  61563. {
  61564. dragAndDropTargetComponent = dynamic_cast <Component*> (newTarget);
  61565. const Point<int> pos (component->relativePositionToOtherComponent (dragAndDropTargetComponent, position));
  61566. newTarget->fileDragEnter (files, pos.getX(), pos.getY());
  61567. }
  61568. }
  61569. }
  61570. else
  61571. {
  61572. newTarget = lastTarget;
  61573. }
  61574. if (newTarget != 0)
  61575. {
  61576. Component* const targetComp = dynamic_cast <Component*> (newTarget);
  61577. const Point<int> pos (component->relativePositionToOtherComponent (targetComp, position));
  61578. newTarget->fileDragMove (files, pos.getX(), pos.getY());
  61579. }
  61580. }
  61581. void ComponentPeer::handleFileDragExit (const StringArray& files)
  61582. {
  61583. handleFileDragMove (files, Point<int> (-1, -1));
  61584. jassert (dragAndDropTargetComponent == 0);
  61585. lastDragAndDropCompUnderMouse = 0;
  61586. }
  61587. void ComponentPeer::handleFileDragDrop (const StringArray& files, const Point<int>& position)
  61588. {
  61589. handleFileDragMove (files, position);
  61590. if (dragAndDropTargetComponent != 0)
  61591. {
  61592. FileDragAndDropTarget* const target
  61593. = dynamic_cast<FileDragAndDropTarget*> (static_cast<Component*> (dragAndDropTargetComponent));
  61594. dragAndDropTargetComponent = 0;
  61595. lastDragAndDropCompUnderMouse = 0;
  61596. if (target != 0)
  61597. {
  61598. Component* const targetComp = dynamic_cast <Component*> (target);
  61599. if (targetComp->isCurrentlyBlockedByAnotherModalComponent())
  61600. {
  61601. targetComp->internalModalInputAttempt();
  61602. if (targetComp->isCurrentlyBlockedByAnotherModalComponent())
  61603. return;
  61604. }
  61605. const Point<int> pos (component->relativePositionToOtherComponent (targetComp, position));
  61606. target->filesDropped (files, pos.getX(), pos.getY());
  61607. }
  61608. }
  61609. }
  61610. void ComponentPeer::handleUserClosingWindow()
  61611. {
  61612. updateCurrentModifiers();
  61613. component->userTriedToCloseWindow();
  61614. }
  61615. void ComponentPeer::bringModalComponentToFront()
  61616. {
  61617. Component::bringModalComponentToFront();
  61618. }
  61619. void ComponentPeer::clearMaskedRegion() throw()
  61620. {
  61621. maskedRegion.clear();
  61622. }
  61623. void ComponentPeer::addMaskedRegion (int x, int y, int w, int h) throw()
  61624. {
  61625. maskedRegion.add (x, y, w, h);
  61626. }
  61627. const StringArray ComponentPeer::getAvailableRenderingEngines() throw()
  61628. {
  61629. StringArray s;
  61630. s.add ("Software Renderer");
  61631. return s;
  61632. }
  61633. int ComponentPeer::getCurrentRenderingEngine() throw()
  61634. {
  61635. return 0;
  61636. }
  61637. void ComponentPeer::setCurrentRenderingEngine (int /*index*/) throw()
  61638. {
  61639. }
  61640. END_JUCE_NAMESPACE
  61641. /*** End of inlined file: juce_ComponentPeer.cpp ***/
  61642. /*** Start of inlined file: juce_DialogWindow.cpp ***/
  61643. BEGIN_JUCE_NAMESPACE
  61644. DialogWindow::DialogWindow (const String& name,
  61645. const Colour& backgroundColour_,
  61646. const bool escapeKeyTriggersCloseButton_,
  61647. const bool addToDesktop_)
  61648. : DocumentWindow (name, backgroundColour_, DocumentWindow::closeButton, addToDesktop_),
  61649. escapeKeyTriggersCloseButton (escapeKeyTriggersCloseButton_)
  61650. {
  61651. }
  61652. DialogWindow::~DialogWindow()
  61653. {
  61654. }
  61655. void DialogWindow::resized()
  61656. {
  61657. DocumentWindow::resized();
  61658. const KeyPress esc (KeyPress::escapeKey, 0, 0);
  61659. if (escapeKeyTriggersCloseButton
  61660. && getCloseButton() != 0
  61661. && ! getCloseButton()->isRegisteredForShortcut (esc))
  61662. {
  61663. getCloseButton()->addShortcut (esc);
  61664. }
  61665. }
  61666. class TempDialogWindow : public DialogWindow
  61667. {
  61668. public:
  61669. TempDialogWindow (const String& title, const Colour& colour, const bool escapeCloses)
  61670. : DialogWindow (title, colour, escapeCloses, true)
  61671. {
  61672. }
  61673. ~TempDialogWindow()
  61674. {
  61675. }
  61676. void closeButtonPressed()
  61677. {
  61678. setVisible (false);
  61679. }
  61680. private:
  61681. TempDialogWindow (const TempDialogWindow&);
  61682. TempDialogWindow& operator= (const TempDialogWindow&);
  61683. };
  61684. int DialogWindow::showModalDialog (const String& dialogTitle,
  61685. Component* contentComponent,
  61686. Component* componentToCentreAround,
  61687. const Colour& colour,
  61688. const bool escapeKeyTriggersCloseButton,
  61689. const bool shouldBeResizable,
  61690. const bool useBottomRightCornerResizer)
  61691. {
  61692. TempDialogWindow dw (dialogTitle, colour, escapeKeyTriggersCloseButton);
  61693. dw.setContentComponent (contentComponent, true, true);
  61694. dw.centreAroundComponent (componentToCentreAround, dw.getWidth(), dw.getHeight());
  61695. dw.setResizable (shouldBeResizable, useBottomRightCornerResizer);
  61696. const int result = dw.runModalLoop();
  61697. dw.setContentComponent (0, false);
  61698. return result;
  61699. }
  61700. END_JUCE_NAMESPACE
  61701. /*** End of inlined file: juce_DialogWindow.cpp ***/
  61702. /*** Start of inlined file: juce_DocumentWindow.cpp ***/
  61703. BEGIN_JUCE_NAMESPACE
  61704. class DocumentWindow::ButtonListenerProxy : public ButtonListener
  61705. {
  61706. public:
  61707. ButtonListenerProxy (DocumentWindow& owner_)
  61708. : owner (owner_)
  61709. {
  61710. }
  61711. void buttonClicked (Button* button)
  61712. {
  61713. if (button == owner.getMinimiseButton())
  61714. owner.minimiseButtonPressed();
  61715. else if (button == owner.getMaximiseButton())
  61716. owner.maximiseButtonPressed();
  61717. else if (button == owner.getCloseButton())
  61718. owner.closeButtonPressed();
  61719. }
  61720. juce_UseDebuggingNewOperator
  61721. private:
  61722. DocumentWindow& owner;
  61723. ButtonListenerProxy (const ButtonListenerProxy&);
  61724. ButtonListenerProxy& operator= (const ButtonListenerProxy&);
  61725. };
  61726. DocumentWindow::DocumentWindow (const String& title,
  61727. const Colour& backgroundColour,
  61728. const int requiredButtons_,
  61729. const bool addToDesktop_)
  61730. : ResizableWindow (title, backgroundColour, addToDesktop_),
  61731. titleBarHeight (26),
  61732. menuBarHeight (24),
  61733. requiredButtons (requiredButtons_),
  61734. #if JUCE_MAC
  61735. positionTitleBarButtonsOnLeft (true),
  61736. #else
  61737. positionTitleBarButtonsOnLeft (false),
  61738. #endif
  61739. drawTitleTextCentred (true),
  61740. menuBarModel (0)
  61741. {
  61742. setResizeLimits (128, 128, 32768, 32768);
  61743. lookAndFeelChanged();
  61744. }
  61745. DocumentWindow::~DocumentWindow()
  61746. {
  61747. for (int i = numElementsInArray (titleBarButtons); --i >= 0;)
  61748. titleBarButtons[i] = 0;
  61749. menuBar = 0;
  61750. }
  61751. void DocumentWindow::repaintTitleBar()
  61752. {
  61753. const Rectangle<int> titleBarArea (getTitleBarArea());
  61754. repaint (titleBarArea.getX(), titleBarArea.getY(),
  61755. titleBarArea.getWidth(), titleBarArea.getHeight());
  61756. }
  61757. void DocumentWindow::setName (const String& newName)
  61758. {
  61759. if (newName != getName())
  61760. {
  61761. Component::setName (newName);
  61762. repaintTitleBar();
  61763. }
  61764. }
  61765. void DocumentWindow::setIcon (const Image* imageToUse)
  61766. {
  61767. titleBarIcon = imageToUse != 0 ? imageToUse->createCopy() : 0;
  61768. repaintTitleBar();
  61769. }
  61770. void DocumentWindow::setTitleBarHeight (const int newHeight)
  61771. {
  61772. titleBarHeight = newHeight;
  61773. resized();
  61774. repaintTitleBar();
  61775. }
  61776. void DocumentWindow::setTitleBarButtonsRequired (const int requiredButtons_,
  61777. const bool positionTitleBarButtonsOnLeft_)
  61778. {
  61779. requiredButtons = requiredButtons_;
  61780. positionTitleBarButtonsOnLeft = positionTitleBarButtonsOnLeft_;
  61781. lookAndFeelChanged();
  61782. }
  61783. void DocumentWindow::setTitleBarTextCentred (const bool textShouldBeCentred)
  61784. {
  61785. drawTitleTextCentred = textShouldBeCentred;
  61786. repaintTitleBar();
  61787. }
  61788. void DocumentWindow::setMenuBar (MenuBarModel* menuBarModel_,
  61789. const int menuBarHeight_)
  61790. {
  61791. if (menuBarModel != menuBarModel_)
  61792. {
  61793. menuBar = 0;
  61794. menuBarModel = menuBarModel_;
  61795. menuBarHeight = (menuBarHeight_ > 0) ? menuBarHeight_
  61796. : getLookAndFeel().getDefaultMenuBarHeight();
  61797. if (menuBarModel != 0)
  61798. {
  61799. // (call the Component method directly to avoid the assertion in ResizableWindow)
  61800. Component::addAndMakeVisible (menuBar = new MenuBarComponent (menuBarModel));
  61801. menuBar->setEnabled (isActiveWindow());
  61802. }
  61803. resized();
  61804. }
  61805. }
  61806. void DocumentWindow::closeButtonPressed()
  61807. {
  61808. /* If you've got a close button, you have to override this method to get
  61809. rid of your window!
  61810. If the window is just a pop-up, you should override this method and make
  61811. it delete the window in whatever way is appropriate for your app. E.g. you
  61812. might just want to call "delete this".
  61813. If your app is centred around this window such that the whole app should quit when
  61814. the window is closed, then you will probably want to use this method as an opportunity
  61815. to call JUCEApplication::quit(), and leave the window to be deleted later by your
  61816. JUCEApplication::shutdown() method. (Doing it this way means that your window will
  61817. still get cleaned-up if the app is quit by some other means (e.g. a cmd-Q on the mac
  61818. or closing it via the taskbar icon on Windows).
  61819. */
  61820. jassertfalse
  61821. }
  61822. void DocumentWindow::minimiseButtonPressed()
  61823. {
  61824. setMinimised (true);
  61825. }
  61826. void DocumentWindow::maximiseButtonPressed()
  61827. {
  61828. setFullScreen (! isFullScreen());
  61829. }
  61830. void DocumentWindow::paint (Graphics& g)
  61831. {
  61832. ResizableWindow::paint (g);
  61833. if (resizableBorder == 0)
  61834. {
  61835. g.setColour (getBackgroundColour().overlaidWith (Colour (0x80000000)));
  61836. const BorderSize border (getBorderThickness());
  61837. g.fillRect (0, 0, getWidth(), border.getTop());
  61838. g.fillRect (0, border.getTop(), border.getLeft(), getHeight() - border.getTopAndBottom());
  61839. g.fillRect (getWidth() - border.getRight(), border.getTop(), border.getRight(), getHeight() - border.getTopAndBottom());
  61840. g.fillRect (0, getHeight() - border.getBottom(), getWidth(), border.getBottom());
  61841. }
  61842. const Rectangle<int> titleBarArea (getTitleBarArea());
  61843. g.setOrigin (titleBarArea.getX(), titleBarArea.getY());
  61844. g.reduceClipRegion (0, 0, titleBarArea.getWidth(), titleBarArea.getHeight());
  61845. int titleSpaceX1 = 6;
  61846. int titleSpaceX2 = titleBarArea.getWidth() - 6;
  61847. for (int i = 0; i < 3; ++i)
  61848. {
  61849. if (titleBarButtons[i] != 0)
  61850. {
  61851. if (positionTitleBarButtonsOnLeft)
  61852. titleSpaceX1 = jmax (titleSpaceX1, titleBarButtons[i]->getRight() + (getWidth() - titleBarButtons[i]->getRight()) / 8);
  61853. else
  61854. titleSpaceX2 = jmin (titleSpaceX2, titleBarButtons[i]->getX() - (titleBarButtons[i]->getX() / 8));
  61855. }
  61856. }
  61857. getLookAndFeel().drawDocumentWindowTitleBar (*this, g,
  61858. titleBarArea.getWidth(),
  61859. titleBarArea.getHeight(),
  61860. titleSpaceX1,
  61861. jmax (1, titleSpaceX2 - titleSpaceX1),
  61862. titleBarIcon,
  61863. ! drawTitleTextCentred);
  61864. }
  61865. void DocumentWindow::resized()
  61866. {
  61867. ResizableWindow::resized();
  61868. if (titleBarButtons[1] != 0)
  61869. titleBarButtons[1]->setToggleState (isFullScreen(), false);
  61870. const Rectangle<int> titleBarArea (getTitleBarArea());
  61871. getLookAndFeel()
  61872. .positionDocumentWindowButtons (*this,
  61873. titleBarArea.getX(), titleBarArea.getY(),
  61874. titleBarArea.getWidth(), titleBarArea.getHeight(),
  61875. titleBarButtons[0],
  61876. titleBarButtons[1],
  61877. titleBarButtons[2],
  61878. positionTitleBarButtonsOnLeft);
  61879. if (menuBar != 0)
  61880. menuBar->setBounds (titleBarArea.getX(), titleBarArea.getBottom(),
  61881. titleBarArea.getWidth(), menuBarHeight);
  61882. }
  61883. const BorderSize DocumentWindow::getBorderThickness()
  61884. {
  61885. return BorderSize ((isFullScreen() || isUsingNativeTitleBar())
  61886. ? 0 : (resizableBorder != 0 ? 4 : 1));
  61887. }
  61888. const BorderSize DocumentWindow::getContentComponentBorder()
  61889. {
  61890. BorderSize border (getBorderThickness());
  61891. border.setTop (border.getTop()
  61892. + (isUsingNativeTitleBar() ? 0 : titleBarHeight)
  61893. + (menuBar != 0 ? menuBarHeight : 0));
  61894. return border;
  61895. }
  61896. int DocumentWindow::getTitleBarHeight() const
  61897. {
  61898. return isUsingNativeTitleBar() ? 0 : jmin (titleBarHeight, getHeight() - 4);
  61899. }
  61900. const Rectangle<int> DocumentWindow::getTitleBarArea()
  61901. {
  61902. const BorderSize border (getBorderThickness());
  61903. return Rectangle<int> (border.getLeft(), border.getTop(),
  61904. getWidth() - border.getLeftAndRight(),
  61905. getTitleBarHeight());
  61906. }
  61907. Button* DocumentWindow::getCloseButton() const throw()
  61908. {
  61909. return titleBarButtons[2];
  61910. }
  61911. Button* DocumentWindow::getMinimiseButton() const throw()
  61912. {
  61913. return titleBarButtons[0];
  61914. }
  61915. Button* DocumentWindow::getMaximiseButton() const throw()
  61916. {
  61917. return titleBarButtons[1];
  61918. }
  61919. int DocumentWindow::getDesktopWindowStyleFlags() const
  61920. {
  61921. int flags = ResizableWindow::getDesktopWindowStyleFlags();
  61922. if ((requiredButtons & minimiseButton) != 0)
  61923. flags |= ComponentPeer::windowHasMinimiseButton;
  61924. if ((requiredButtons & maximiseButton) != 0)
  61925. flags |= ComponentPeer::windowHasMaximiseButton;
  61926. if ((requiredButtons & closeButton) != 0)
  61927. flags |= ComponentPeer::windowHasCloseButton;
  61928. return flags;
  61929. }
  61930. void DocumentWindow::lookAndFeelChanged()
  61931. {
  61932. int i;
  61933. for (i = numElementsInArray (titleBarButtons); --i >= 0;)
  61934. titleBarButtons[i] = 0;
  61935. if (! isUsingNativeTitleBar())
  61936. {
  61937. titleBarButtons[0] = ((requiredButtons & minimiseButton) != 0)
  61938. ? getLookAndFeel().createDocumentWindowButton (minimiseButton) : 0;
  61939. titleBarButtons[1] = ((requiredButtons & maximiseButton) != 0)
  61940. ? getLookAndFeel().createDocumentWindowButton (maximiseButton) : 0;
  61941. titleBarButtons[2] = ((requiredButtons & closeButton) != 0)
  61942. ? getLookAndFeel().createDocumentWindowButton (closeButton) : 0;
  61943. for (i = 0; i < 3; ++i)
  61944. {
  61945. if (titleBarButtons[i] != 0)
  61946. {
  61947. if (buttonListener == 0)
  61948. buttonListener = new ButtonListenerProxy (*this);
  61949. titleBarButtons[i]->addButtonListener (buttonListener);
  61950. titleBarButtons[i]->setWantsKeyboardFocus (false);
  61951. // (call the Component method directly to avoid the assertion in ResizableWindow)
  61952. Component::addAndMakeVisible (titleBarButtons[i]);
  61953. }
  61954. }
  61955. if (getCloseButton() != 0)
  61956. {
  61957. #if JUCE_MAC
  61958. getCloseButton()->addShortcut (KeyPress (T('w'), ModifierKeys::commandModifier, 0));
  61959. #else
  61960. getCloseButton()->addShortcut (KeyPress (KeyPress::F4Key, ModifierKeys::altModifier, 0));
  61961. #endif
  61962. }
  61963. }
  61964. activeWindowStatusChanged();
  61965. ResizableWindow::lookAndFeelChanged();
  61966. }
  61967. void DocumentWindow::parentHierarchyChanged()
  61968. {
  61969. lookAndFeelChanged();
  61970. }
  61971. void DocumentWindow::activeWindowStatusChanged()
  61972. {
  61973. ResizableWindow::activeWindowStatusChanged();
  61974. for (int i = numElementsInArray (titleBarButtons); --i >= 0;)
  61975. if (titleBarButtons[i] != 0)
  61976. titleBarButtons[i]->setEnabled (isActiveWindow());
  61977. if (menuBar != 0)
  61978. menuBar->setEnabled (isActiveWindow());
  61979. }
  61980. void DocumentWindow::mouseDoubleClick (const MouseEvent& e)
  61981. {
  61982. if (getTitleBarArea().contains (e.x, e.y)
  61983. && getMaximiseButton() != 0)
  61984. {
  61985. getMaximiseButton()->triggerClick();
  61986. }
  61987. }
  61988. void DocumentWindow::userTriedToCloseWindow()
  61989. {
  61990. closeButtonPressed();
  61991. }
  61992. END_JUCE_NAMESPACE
  61993. /*** End of inlined file: juce_DocumentWindow.cpp ***/
  61994. /*** Start of inlined file: juce_ResizableWindow.cpp ***/
  61995. BEGIN_JUCE_NAMESPACE
  61996. ResizableWindow::ResizableWindow (const String& name,
  61997. const bool addToDesktop_)
  61998. : TopLevelWindow (name, addToDesktop_),
  61999. resizeToFitContent (false),
  62000. fullscreen (false),
  62001. lastNonFullScreenPos (50, 50, 256, 256),
  62002. constrainer (0)
  62003. #ifdef JUCE_DEBUG
  62004. , hasBeenResized (false)
  62005. #endif
  62006. {
  62007. defaultConstrainer.setMinimumOnscreenAmounts (0x10000, 16, 24, 16);
  62008. lastNonFullScreenPos.setBounds (50, 50, 256, 256);
  62009. if (addToDesktop_)
  62010. Component::addToDesktop (getDesktopWindowStyleFlags());
  62011. }
  62012. ResizableWindow::ResizableWindow (const String& name,
  62013. const Colour& backgroundColour_,
  62014. const bool addToDesktop_)
  62015. : TopLevelWindow (name, addToDesktop_),
  62016. resizeToFitContent (false),
  62017. fullscreen (false),
  62018. lastNonFullScreenPos (50, 50, 256, 256),
  62019. constrainer (0)
  62020. #ifdef JUCE_DEBUG
  62021. , hasBeenResized (false)
  62022. #endif
  62023. {
  62024. setBackgroundColour (backgroundColour_);
  62025. defaultConstrainer.setMinimumOnscreenAmounts (0x10000, 16, 24, 16);
  62026. if (addToDesktop_)
  62027. Component::addToDesktop (getDesktopWindowStyleFlags());
  62028. }
  62029. ResizableWindow::~ResizableWindow()
  62030. {
  62031. resizableCorner = 0;
  62032. resizableBorder = 0;
  62033. contentComponent = 0;
  62034. // have you been adding your own components directly to this window..? tut tut tut.
  62035. // Read the instructions for using a ResizableWindow!
  62036. jassert (getNumChildComponents() == 0);
  62037. }
  62038. int ResizableWindow::getDesktopWindowStyleFlags() const
  62039. {
  62040. int flags = TopLevelWindow::getDesktopWindowStyleFlags();
  62041. if (isResizable() && (flags & ComponentPeer::windowHasTitleBar) != 0)
  62042. flags |= ComponentPeer::windowIsResizable;
  62043. return flags;
  62044. }
  62045. void ResizableWindow::setContentComponent (Component* const newContentComponent,
  62046. const bool deleteOldOne,
  62047. const bool resizeToFit)
  62048. {
  62049. resizeToFitContent = resizeToFit;
  62050. if (newContentComponent != (Component*) contentComponent)
  62051. {
  62052. if (! deleteOldOne)
  62053. removeChildComponent (contentComponent.release());
  62054. contentComponent = newContentComponent;
  62055. Component::addAndMakeVisible (contentComponent);
  62056. }
  62057. if (resizeToFit)
  62058. childBoundsChanged (contentComponent);
  62059. resized(); // must always be called to position the new content comp
  62060. }
  62061. void ResizableWindow::setContentComponentSize (int width, int height)
  62062. {
  62063. jassert (width > 0 && height > 0); // not a great idea to give it a zero size..
  62064. const BorderSize border (getContentComponentBorder());
  62065. setSize (width + border.getLeftAndRight(),
  62066. height + border.getTopAndBottom());
  62067. }
  62068. const BorderSize ResizableWindow::getBorderThickness()
  62069. {
  62070. return BorderSize (isUsingNativeTitleBar() ? 0 : ((resizableBorder != 0 && ! isFullScreen()) ? 5 : 3));
  62071. }
  62072. const BorderSize ResizableWindow::getContentComponentBorder()
  62073. {
  62074. return getBorderThickness();
  62075. }
  62076. void ResizableWindow::moved()
  62077. {
  62078. updateLastPos();
  62079. }
  62080. void ResizableWindow::visibilityChanged()
  62081. {
  62082. TopLevelWindow::visibilityChanged();
  62083. updateLastPos();
  62084. }
  62085. void ResizableWindow::resized()
  62086. {
  62087. if (resizableBorder != 0)
  62088. {
  62089. resizableBorder->setVisible (! isFullScreen());
  62090. resizableBorder->setBorderThickness (getBorderThickness());
  62091. resizableBorder->setSize (getWidth(), getHeight());
  62092. resizableBorder->toBack();
  62093. }
  62094. if (resizableCorner != 0)
  62095. {
  62096. resizableCorner->setVisible (! isFullScreen());
  62097. const int resizerSize = 18;
  62098. resizableCorner->setBounds (getWidth() - resizerSize,
  62099. getHeight() - resizerSize,
  62100. resizerSize, resizerSize);
  62101. }
  62102. if (contentComponent != 0)
  62103. contentComponent->setBoundsInset (getContentComponentBorder());
  62104. updateLastPos();
  62105. #ifdef JUCE_DEBUG
  62106. hasBeenResized = true;
  62107. #endif
  62108. }
  62109. void ResizableWindow::childBoundsChanged (Component* child)
  62110. {
  62111. if ((child == contentComponent) && (child != 0) && resizeToFitContent)
  62112. {
  62113. // not going to look very good if this component has a zero size..
  62114. jassert (child->getWidth() > 0);
  62115. jassert (child->getHeight() > 0);
  62116. const BorderSize borders (getContentComponentBorder());
  62117. setSize (child->getWidth() + borders.getLeftAndRight(),
  62118. child->getHeight() + borders.getTopAndBottom());
  62119. }
  62120. }
  62121. void ResizableWindow::activeWindowStatusChanged()
  62122. {
  62123. const BorderSize borders (getContentComponentBorder());
  62124. repaint (0, 0, getWidth(), borders.getTop());
  62125. repaint (0, borders.getTop(), borders.getLeft(), getHeight() - borders.getBottom() - borders.getTop());
  62126. repaint (0, getHeight() - borders.getBottom(), getWidth(), borders.getBottom());
  62127. repaint (getWidth() - borders.getRight(), borders.getTop(), borders.getRight(), getHeight() - borders.getBottom() - borders.getTop());
  62128. }
  62129. void ResizableWindow::setResizable (const bool shouldBeResizable,
  62130. const bool useBottomRightCornerResizer)
  62131. {
  62132. if (shouldBeResizable)
  62133. {
  62134. if (useBottomRightCornerResizer)
  62135. {
  62136. resizableBorder = 0;
  62137. if (resizableCorner == 0)
  62138. {
  62139. Component::addChildComponent (resizableCorner = new ResizableCornerComponent (this, constrainer));
  62140. resizableCorner->setAlwaysOnTop (true);
  62141. }
  62142. }
  62143. else
  62144. {
  62145. resizableCorner = 0;
  62146. if (resizableBorder == 0)
  62147. Component::addChildComponent (resizableBorder = new ResizableBorderComponent (this, constrainer));
  62148. }
  62149. }
  62150. else
  62151. {
  62152. resizableCorner = 0;
  62153. resizableBorder = 0;
  62154. }
  62155. if (isUsingNativeTitleBar())
  62156. recreateDesktopWindow();
  62157. childBoundsChanged (contentComponent);
  62158. resized();
  62159. }
  62160. bool ResizableWindow::isResizable() const throw()
  62161. {
  62162. return resizableCorner != 0
  62163. || resizableBorder != 0;
  62164. }
  62165. void ResizableWindow::setResizeLimits (const int newMinimumWidth,
  62166. const int newMinimumHeight,
  62167. const int newMaximumWidth,
  62168. const int newMaximumHeight) throw()
  62169. {
  62170. // if you've set up a custom constrainer then these settings won't have any effect..
  62171. jassert (constrainer == &defaultConstrainer || constrainer == 0);
  62172. if (constrainer == 0)
  62173. setConstrainer (&defaultConstrainer);
  62174. defaultConstrainer.setSizeLimits (newMinimumWidth, newMinimumHeight,
  62175. newMaximumWidth, newMaximumHeight);
  62176. setBoundsConstrained (getBounds());
  62177. }
  62178. void ResizableWindow::setConstrainer (ComponentBoundsConstrainer* newConstrainer)
  62179. {
  62180. if (constrainer != newConstrainer)
  62181. {
  62182. constrainer = newConstrainer;
  62183. const bool useBottomRightCornerResizer = resizableCorner != 0;
  62184. const bool shouldBeResizable = useBottomRightCornerResizer || resizableBorder != 0;
  62185. resizableCorner = 0;
  62186. resizableBorder = 0;
  62187. setResizable (shouldBeResizable, useBottomRightCornerResizer);
  62188. ComponentPeer* const peer = getPeer();
  62189. if (peer != 0)
  62190. peer->setConstrainer (newConstrainer);
  62191. }
  62192. }
  62193. void ResizableWindow::setBoundsConstrained (const Rectangle<int>& bounds)
  62194. {
  62195. if (constrainer != 0)
  62196. constrainer->setBoundsForComponent (this, bounds, false, false, false, false);
  62197. else
  62198. setBounds (bounds);
  62199. }
  62200. void ResizableWindow::paint (Graphics& g)
  62201. {
  62202. getLookAndFeel().fillResizableWindowBackground (g, getWidth(), getHeight(),
  62203. getBorderThickness(), *this);
  62204. if (! isFullScreen())
  62205. {
  62206. getLookAndFeel().drawResizableWindowBorder (g, getWidth(), getHeight(),
  62207. getBorderThickness(), *this);
  62208. }
  62209. #ifdef JUCE_DEBUG
  62210. /* If this fails, then you've probably written a subclass with a resized()
  62211. callback but forgotten to make it call its parent class's resized() method.
  62212. It's important when you override methods like resized(), moved(),
  62213. etc., that you make sure the base class methods also get called.
  62214. Of course you shouldn't really be overriding ResizableWindow::resized() anyway,
  62215. because your content should all be inside the content component - and it's the
  62216. content component's resized() method that you should be using to do your
  62217. layout.
  62218. */
  62219. jassert (hasBeenResized || (getWidth() == 0 && getHeight() == 0));
  62220. #endif
  62221. }
  62222. void ResizableWindow::lookAndFeelChanged()
  62223. {
  62224. resized();
  62225. if (isOnDesktop())
  62226. {
  62227. Component::addToDesktop (getDesktopWindowStyleFlags());
  62228. ComponentPeer* const peer = getPeer();
  62229. if (peer != 0)
  62230. peer->setConstrainer (constrainer);
  62231. }
  62232. }
  62233. const Colour ResizableWindow::getBackgroundColour() const throw()
  62234. {
  62235. return findColour (backgroundColourId, false);
  62236. }
  62237. void ResizableWindow::setBackgroundColour (const Colour& newColour)
  62238. {
  62239. Colour backgroundColour (newColour);
  62240. if (! Desktop::canUseSemiTransparentWindows())
  62241. backgroundColour = newColour.withAlpha (1.0f);
  62242. setColour (backgroundColourId, backgroundColour);
  62243. setOpaque (backgroundColour.isOpaque());
  62244. repaint();
  62245. }
  62246. bool ResizableWindow::isFullScreen() const
  62247. {
  62248. if (isOnDesktop())
  62249. {
  62250. ComponentPeer* const peer = getPeer();
  62251. return peer != 0 && peer->isFullScreen();
  62252. }
  62253. return fullscreen;
  62254. }
  62255. void ResizableWindow::setFullScreen (const bool shouldBeFullScreen)
  62256. {
  62257. if (shouldBeFullScreen != isFullScreen())
  62258. {
  62259. updateLastPos();
  62260. fullscreen = shouldBeFullScreen;
  62261. if (isOnDesktop())
  62262. {
  62263. ComponentPeer* const peer = getPeer();
  62264. if (peer != 0)
  62265. {
  62266. // keep a copy of this intact in case the real one gets messed-up while we're un-maximising
  62267. const Rectangle<int> lastPos (lastNonFullScreenPos);
  62268. peer->setFullScreen (shouldBeFullScreen);
  62269. if (! shouldBeFullScreen)
  62270. setBounds (lastPos);
  62271. }
  62272. else
  62273. {
  62274. jassertfalse
  62275. }
  62276. }
  62277. else
  62278. {
  62279. if (shouldBeFullScreen)
  62280. setBounds (0, 0, getParentWidth(), getParentHeight());
  62281. else
  62282. setBounds (lastNonFullScreenPos);
  62283. }
  62284. resized();
  62285. }
  62286. }
  62287. bool ResizableWindow::isMinimised() const
  62288. {
  62289. ComponentPeer* const peer = getPeer();
  62290. return (peer != 0) && peer->isMinimised();
  62291. }
  62292. void ResizableWindow::setMinimised (const bool shouldMinimise)
  62293. {
  62294. if (shouldMinimise != isMinimised())
  62295. {
  62296. ComponentPeer* const peer = getPeer();
  62297. if (peer != 0)
  62298. {
  62299. updateLastPos();
  62300. peer->setMinimised (shouldMinimise);
  62301. }
  62302. else
  62303. {
  62304. jassertfalse
  62305. }
  62306. }
  62307. }
  62308. void ResizableWindow::updateLastPos()
  62309. {
  62310. if (isShowing() && ! (isFullScreen() || isMinimised()))
  62311. {
  62312. lastNonFullScreenPos = getBounds();
  62313. }
  62314. }
  62315. void ResizableWindow::parentSizeChanged()
  62316. {
  62317. if (isFullScreen() && getParentComponent() != 0)
  62318. {
  62319. setBounds (0, 0, getParentWidth(), getParentHeight());
  62320. }
  62321. }
  62322. const String ResizableWindow::getWindowStateAsString()
  62323. {
  62324. updateLastPos();
  62325. return (isFullScreen() ? "fs " : "") + lastNonFullScreenPos.toString();
  62326. }
  62327. bool ResizableWindow::restoreWindowStateFromString (const String& s)
  62328. {
  62329. StringArray tokens;
  62330. tokens.addTokens (s, false);
  62331. tokens.removeEmptyStrings();
  62332. tokens.trim();
  62333. const bool fs = tokens[0].startsWithIgnoreCase (T("fs"));
  62334. const int firstCoord = fs ? 1 : 0;
  62335. if (tokens.size() != firstCoord + 4)
  62336. return false;
  62337. Rectangle<int> newPos (tokens[firstCoord].getIntValue(),
  62338. tokens[firstCoord + 1].getIntValue(),
  62339. tokens[firstCoord + 2].getIntValue(),
  62340. tokens[firstCoord + 3].getIntValue());
  62341. if (newPos.isEmpty())
  62342. return false;
  62343. const Rectangle<int> screen (Desktop::getInstance().getMonitorAreaContaining (newPos.getCentre()));
  62344. ComponentPeer* const peer = isOnDesktop() ? getPeer() : 0;
  62345. if (peer != 0)
  62346. peer->getFrameSize().addTo (newPos);
  62347. if (! screen.contains (newPos))
  62348. {
  62349. newPos.setSize (jmin (newPos.getWidth(), screen.getWidth()),
  62350. jmin (newPos.getHeight(), screen.getHeight()));
  62351. newPos.setPosition (jlimit (screen.getX(), screen.getRight() - newPos.getWidth(), newPos.getX()),
  62352. jlimit (screen.getY(), screen.getBottom() - newPos.getHeight(), newPos.getY()));
  62353. }
  62354. if (peer != 0)
  62355. {
  62356. peer->getFrameSize().subtractFrom (newPos);
  62357. peer->setNonFullScreenBounds (newPos);
  62358. }
  62359. lastNonFullScreenPos = newPos;
  62360. setFullScreen (fs);
  62361. if (! fs)
  62362. setBoundsConstrained (newPos);
  62363. return true;
  62364. }
  62365. void ResizableWindow::mouseDown (const MouseEvent&)
  62366. {
  62367. if (! isFullScreen())
  62368. dragger.startDraggingComponent (this, constrainer);
  62369. }
  62370. void ResizableWindow::mouseDrag (const MouseEvent& e)
  62371. {
  62372. if (! isFullScreen())
  62373. dragger.dragComponent (this, e);
  62374. }
  62375. #ifdef JUCE_DEBUG
  62376. void ResizableWindow::addChildComponent (Component* const child, int zOrder)
  62377. {
  62378. /* Agh! You shouldn't add components directly to a ResizableWindow - this class
  62379. manages its child components automatically, and if you add your own it'll cause
  62380. trouble. Instead, use setContentComponent() to give it a component which
  62381. will be automatically resized and kept in the right place - then you can add
  62382. subcomponents to the content comp. See the notes for the ResizableWindow class
  62383. for more info.
  62384. If you really know what you're doing and want to avoid this assertion, just call
  62385. Component::addChildComponent directly.
  62386. */
  62387. jassertfalse
  62388. Component::addChildComponent (child, zOrder);
  62389. }
  62390. void ResizableWindow::addAndMakeVisible (Component* const child, int zOrder)
  62391. {
  62392. /* Agh! You shouldn't add components directly to a ResizableWindow - this class
  62393. manages its child components automatically, and if you add your own it'll cause
  62394. trouble. Instead, use setContentComponent() to give it a component which
  62395. will be automatically resized and kept in the right place - then you can add
  62396. subcomponents to the content comp. See the notes for the ResizableWindow class
  62397. for more info.
  62398. If you really know what you're doing and want to avoid this assertion, just call
  62399. Component::addAndMakeVisible directly.
  62400. */
  62401. jassertfalse
  62402. Component::addAndMakeVisible (child, zOrder);
  62403. }
  62404. #endif
  62405. END_JUCE_NAMESPACE
  62406. /*** End of inlined file: juce_ResizableWindow.cpp ***/
  62407. /*** Start of inlined file: juce_SplashScreen.cpp ***/
  62408. BEGIN_JUCE_NAMESPACE
  62409. SplashScreen::SplashScreen()
  62410. : backgroundImage (0)
  62411. {
  62412. setOpaque (true);
  62413. }
  62414. SplashScreen::~SplashScreen()
  62415. {
  62416. ImageCache::releaseOrDelete (backgroundImage);
  62417. }
  62418. void SplashScreen::show (const String& title,
  62419. Image* const backgroundImage_,
  62420. const int minimumTimeToDisplayFor,
  62421. const bool useDropShadow,
  62422. const bool removeOnMouseClick)
  62423. {
  62424. backgroundImage = backgroundImage_;
  62425. jassert (backgroundImage_ != 0);
  62426. if (backgroundImage_ != 0)
  62427. {
  62428. setOpaque (! backgroundImage_->hasAlphaChannel());
  62429. show (title,
  62430. backgroundImage_->getWidth(),
  62431. backgroundImage_->getHeight(),
  62432. minimumTimeToDisplayFor,
  62433. useDropShadow,
  62434. removeOnMouseClick);
  62435. }
  62436. }
  62437. void SplashScreen::show (const String& title,
  62438. const int width,
  62439. const int height,
  62440. const int minimumTimeToDisplayFor,
  62441. const bool useDropShadow,
  62442. const bool removeOnMouseClick)
  62443. {
  62444. setName (title);
  62445. setAlwaysOnTop (true);
  62446. setVisible (true);
  62447. centreWithSize (width, height);
  62448. addToDesktop (useDropShadow ? ComponentPeer::windowHasDropShadow : 0);
  62449. toFront (false);
  62450. MessageManager::getInstance()->runDispatchLoopUntil (300);
  62451. repaint();
  62452. originalClickCounter = removeOnMouseClick
  62453. ? Desktop::getMouseButtonClickCounter()
  62454. : std::numeric_limits<int>::max();
  62455. earliestTimeToDelete = Time::getCurrentTime() + RelativeTime::milliseconds (minimumTimeToDisplayFor);
  62456. startTimer (50);
  62457. }
  62458. void SplashScreen::paint (Graphics& g)
  62459. {
  62460. if (backgroundImage != 0)
  62461. {
  62462. g.setOpacity (1.0f);
  62463. g.drawImage (backgroundImage,
  62464. 0, 0, getWidth(), getHeight(),
  62465. 0, 0, backgroundImage->getWidth(), backgroundImage->getHeight());
  62466. }
  62467. }
  62468. void SplashScreen::timerCallback()
  62469. {
  62470. if (Time::getCurrentTime() > earliestTimeToDelete
  62471. || Desktop::getMouseButtonClickCounter() > originalClickCounter)
  62472. {
  62473. delete this;
  62474. }
  62475. }
  62476. END_JUCE_NAMESPACE
  62477. /*** End of inlined file: juce_SplashScreen.cpp ***/
  62478. /*** Start of inlined file: juce_ThreadWithProgressWindow.cpp ***/
  62479. BEGIN_JUCE_NAMESPACE
  62480. ThreadWithProgressWindow::ThreadWithProgressWindow (const String& title,
  62481. const bool hasProgressBar,
  62482. const bool hasCancelButton,
  62483. const int timeOutMsWhenCancelling_,
  62484. const String& cancelButtonText)
  62485. : Thread ("Juce Progress Window"),
  62486. progress (0.0),
  62487. timeOutMsWhenCancelling (timeOutMsWhenCancelling_)
  62488. {
  62489. alertWindow = LookAndFeel::getDefaultLookAndFeel()
  62490. .createAlertWindow (title, String::empty, cancelButtonText,
  62491. String::empty, String::empty,
  62492. AlertWindow::NoIcon, hasCancelButton ? 1 : 0, 0);
  62493. if (hasProgressBar)
  62494. alertWindow->addProgressBarComponent (progress);
  62495. }
  62496. ThreadWithProgressWindow::~ThreadWithProgressWindow()
  62497. {
  62498. stopThread (timeOutMsWhenCancelling);
  62499. }
  62500. bool ThreadWithProgressWindow::runThread (const int priority)
  62501. {
  62502. startThread (priority);
  62503. startTimer (100);
  62504. {
  62505. const ScopedLock sl (messageLock);
  62506. alertWindow->setMessage (message);
  62507. }
  62508. const bool finishedNaturally = alertWindow->runModalLoop() != 0;
  62509. stopThread (timeOutMsWhenCancelling);
  62510. alertWindow->setVisible (false);
  62511. return finishedNaturally;
  62512. }
  62513. void ThreadWithProgressWindow::setProgress (const double newProgress)
  62514. {
  62515. progress = newProgress;
  62516. }
  62517. void ThreadWithProgressWindow::setStatusMessage (const String& newStatusMessage)
  62518. {
  62519. const ScopedLock sl (messageLock);
  62520. message = newStatusMessage;
  62521. }
  62522. void ThreadWithProgressWindow::timerCallback()
  62523. {
  62524. if (! isThreadRunning())
  62525. {
  62526. // thread has finished normally..
  62527. alertWindow->exitModalState (1);
  62528. alertWindow->setVisible (false);
  62529. }
  62530. else
  62531. {
  62532. const ScopedLock sl (messageLock);
  62533. alertWindow->setMessage (message);
  62534. }
  62535. }
  62536. END_JUCE_NAMESPACE
  62537. /*** End of inlined file: juce_ThreadWithProgressWindow.cpp ***/
  62538. /*** Start of inlined file: juce_TooltipWindow.cpp ***/
  62539. BEGIN_JUCE_NAMESPACE
  62540. TooltipWindow::TooltipWindow (Component* const parentComponent,
  62541. const int millisecondsBeforeTipAppears_)
  62542. : Component ("tooltip"),
  62543. millisecondsBeforeTipAppears (millisecondsBeforeTipAppears_),
  62544. lastHideTime (0),
  62545. lastComponentUnderMouse (0),
  62546. changedCompsSinceShown (true)
  62547. {
  62548. startTimer (123);
  62549. setAlwaysOnTop (true);
  62550. setOpaque (true);
  62551. if (parentComponent != 0)
  62552. parentComponent->addChildComponent (this);
  62553. }
  62554. TooltipWindow::~TooltipWindow()
  62555. {
  62556. hide();
  62557. }
  62558. void TooltipWindow::setMillisecondsBeforeTipAppears (const int newTimeMs) throw()
  62559. {
  62560. millisecondsBeforeTipAppears = newTimeMs;
  62561. }
  62562. void TooltipWindow::paint (Graphics& g)
  62563. {
  62564. getLookAndFeel().drawTooltip (g, tipShowing, getWidth(), getHeight());
  62565. }
  62566. void TooltipWindow::mouseEnter (const MouseEvent&)
  62567. {
  62568. hide();
  62569. }
  62570. void TooltipWindow::showFor (const String& tip)
  62571. {
  62572. jassert (tip.isNotEmpty());
  62573. tipShowing = tip;
  62574. Point<int> mousePos (Desktop::getMousePosition());
  62575. if (getParentComponent() != 0)
  62576. mousePos = getParentComponent()->globalPositionToRelative (mousePos);
  62577. int x, y, w, h;
  62578. getLookAndFeel().getTooltipSize (tip, w, h);
  62579. if (mousePos.getX() > getParentWidth() / 2)
  62580. x = mousePos.getX() - (w + 12);
  62581. else
  62582. x = mousePos.getX() + 24;
  62583. if (mousePos.getY() > getParentHeight() / 2)
  62584. y = mousePos.getY() - (h + 6);
  62585. else
  62586. y = mousePos.getY() + 6;
  62587. setBounds (x, y, w, h);
  62588. setVisible (true);
  62589. if (getParentComponent() == 0)
  62590. {
  62591. addToDesktop (ComponentPeer::windowHasDropShadow
  62592. | ComponentPeer::windowIsTemporary
  62593. | ComponentPeer::windowIgnoresKeyPresses);
  62594. }
  62595. toFront (false);
  62596. }
  62597. const String TooltipWindow::getTipFor (Component* const c)
  62598. {
  62599. if (c != 0
  62600. && Process::isForegroundProcess()
  62601. && ! Component::isMouseButtonDownAnywhere())
  62602. {
  62603. TooltipClient* const ttc = dynamic_cast <TooltipClient*> (c);
  62604. if (ttc != 0 && ! c->isCurrentlyBlockedByAnotherModalComponent())
  62605. return ttc->getTooltip();
  62606. }
  62607. return String::empty;
  62608. }
  62609. void TooltipWindow::hide()
  62610. {
  62611. tipShowing = String::empty;
  62612. removeFromDesktop();
  62613. setVisible (false);
  62614. }
  62615. void TooltipWindow::timerCallback()
  62616. {
  62617. const unsigned int now = Time::getApproximateMillisecondCounter();
  62618. Component* const newComp = Desktop::getInstance().getMainMouseSource().getComponentUnderMouse();
  62619. const String newTip (getTipFor (newComp));
  62620. const bool tipChanged = (newTip != lastTipUnderMouse || newComp != lastComponentUnderMouse);
  62621. lastComponentUnderMouse = newComp;
  62622. lastTipUnderMouse = newTip;
  62623. const int clickCount = Desktop::getInstance().getMouseButtonClickCounter();
  62624. const bool mouseWasClicked = clickCount > mouseClicks;
  62625. mouseClicks = clickCount;
  62626. const Point<int> mousePos (Desktop::getMousePosition());
  62627. const bool mouseMovedQuickly = mousePos.getDistanceFrom (lastMousePos) > 12;
  62628. lastMousePos = mousePos;
  62629. if (tipChanged || mouseWasClicked || mouseMovedQuickly)
  62630. lastCompChangeTime = now;
  62631. if (isVisible() || now < lastHideTime + 500)
  62632. {
  62633. // if a tip is currently visible (or has just disappeared), update to a new one
  62634. // immediately if needed..
  62635. if (newComp == 0 || mouseWasClicked || newTip.isEmpty())
  62636. {
  62637. if (isVisible())
  62638. {
  62639. lastHideTime = now;
  62640. hide();
  62641. }
  62642. }
  62643. else if (tipChanged)
  62644. {
  62645. showFor (newTip);
  62646. }
  62647. }
  62648. else
  62649. {
  62650. // if there isn't currently a tip, but one is needed, only let it
  62651. // appear after a timeout..
  62652. if (newTip.isNotEmpty()
  62653. && newTip != tipShowing
  62654. && now > lastCompChangeTime + millisecondsBeforeTipAppears)
  62655. {
  62656. showFor (newTip);
  62657. }
  62658. }
  62659. }
  62660. END_JUCE_NAMESPACE
  62661. /*** End of inlined file: juce_TooltipWindow.cpp ***/
  62662. /*** Start of inlined file: juce_TopLevelWindow.cpp ***/
  62663. BEGIN_JUCE_NAMESPACE
  62664. class TopLevelWindowManager : public Timer,
  62665. public DeletedAtShutdown
  62666. {
  62667. public:
  62668. TopLevelWindowManager()
  62669. : currentActive (0)
  62670. {
  62671. }
  62672. ~TopLevelWindowManager()
  62673. {
  62674. clearSingletonInstance();
  62675. }
  62676. juce_DeclareSingleton_SingleThreaded_Minimal (TopLevelWindowManager)
  62677. void timerCallback()
  62678. {
  62679. startTimer (jmin (1731, getTimerInterval() * 2));
  62680. TopLevelWindow* active = 0;
  62681. if (Process::isForegroundProcess())
  62682. {
  62683. active = currentActive;
  62684. Component* const c = Component::getCurrentlyFocusedComponent();
  62685. TopLevelWindow* tlw = dynamic_cast <TopLevelWindow*> (c);
  62686. if (tlw == 0 && c != 0)
  62687. // (unable to use the syntax findParentComponentOfClass <TopLevelWindow> () because of a VC6 compiler bug)
  62688. tlw = c->findParentComponentOfClass ((TopLevelWindow*) 0);
  62689. if (tlw != 0)
  62690. active = tlw;
  62691. }
  62692. if (active != currentActive)
  62693. {
  62694. currentActive = active;
  62695. for (int i = windows.size(); --i >= 0;)
  62696. {
  62697. TopLevelWindow* const tlw = (TopLevelWindow*) windows.getUnchecked (i);
  62698. tlw->setWindowActive (isWindowActive (tlw));
  62699. i = jmin (i, windows.size() - 1);
  62700. }
  62701. Desktop::getInstance().triggerFocusCallback();
  62702. }
  62703. }
  62704. bool addWindow (TopLevelWindow* const w) throw()
  62705. {
  62706. windows.add (w);
  62707. startTimer (10);
  62708. return isWindowActive (w);
  62709. }
  62710. void removeWindow (TopLevelWindow* const w) throw()
  62711. {
  62712. startTimer (10);
  62713. if (currentActive == w)
  62714. currentActive = 0;
  62715. windows.removeValue (w);
  62716. if (windows.size() == 0)
  62717. deleteInstance();
  62718. }
  62719. VoidArray windows;
  62720. private:
  62721. TopLevelWindow* currentActive;
  62722. bool isWindowActive (TopLevelWindow* const tlw) const throw()
  62723. {
  62724. return (tlw == currentActive
  62725. || tlw->isParentOf (currentActive)
  62726. || tlw->hasKeyboardFocus (true))
  62727. && tlw->isShowing();
  62728. }
  62729. TopLevelWindowManager (const TopLevelWindowManager&);
  62730. TopLevelWindowManager& operator= (const TopLevelWindowManager&);
  62731. };
  62732. juce_ImplementSingleton_SingleThreaded (TopLevelWindowManager)
  62733. void juce_CheckCurrentlyFocusedTopLevelWindow()
  62734. {
  62735. if (TopLevelWindowManager::getInstanceWithoutCreating() != 0)
  62736. TopLevelWindowManager::getInstanceWithoutCreating()->startTimer (20);
  62737. }
  62738. TopLevelWindow::TopLevelWindow (const String& name,
  62739. const bool addToDesktop_)
  62740. : Component (name),
  62741. useDropShadow (true),
  62742. useNativeTitleBar (false),
  62743. windowIsActive_ (false)
  62744. {
  62745. setOpaque (true);
  62746. if (addToDesktop_)
  62747. Component::addToDesktop (getDesktopWindowStyleFlags());
  62748. else
  62749. setDropShadowEnabled (true);
  62750. setWantsKeyboardFocus (true);
  62751. setBroughtToFrontOnMouseClick (true);
  62752. windowIsActive_ = TopLevelWindowManager::getInstance()->addWindow (this);
  62753. }
  62754. TopLevelWindow::~TopLevelWindow()
  62755. {
  62756. shadower = 0;
  62757. TopLevelWindowManager::getInstance()->removeWindow (this);
  62758. }
  62759. void TopLevelWindow::focusOfChildComponentChanged (FocusChangeType)
  62760. {
  62761. if (hasKeyboardFocus (true))
  62762. TopLevelWindowManager::getInstance()->timerCallback();
  62763. else
  62764. TopLevelWindowManager::getInstance()->startTimer (10);
  62765. }
  62766. void TopLevelWindow::setWindowActive (const bool isNowActive) throw()
  62767. {
  62768. if (windowIsActive_ != isNowActive)
  62769. {
  62770. windowIsActive_ = isNowActive;
  62771. activeWindowStatusChanged();
  62772. }
  62773. }
  62774. void TopLevelWindow::activeWindowStatusChanged()
  62775. {
  62776. }
  62777. void TopLevelWindow::parentHierarchyChanged()
  62778. {
  62779. setDropShadowEnabled (useDropShadow);
  62780. }
  62781. void TopLevelWindow::visibilityChanged()
  62782. {
  62783. if (isShowing())
  62784. toFront (true);
  62785. }
  62786. int TopLevelWindow::getDesktopWindowStyleFlags() const
  62787. {
  62788. int flags = ComponentPeer::windowAppearsOnTaskbar;
  62789. if (useDropShadow)
  62790. flags |= ComponentPeer::windowHasDropShadow;
  62791. if (useNativeTitleBar)
  62792. flags |= ComponentPeer::windowHasTitleBar;
  62793. return flags;
  62794. }
  62795. void TopLevelWindow::setDropShadowEnabled (const bool useShadow)
  62796. {
  62797. useDropShadow = useShadow;
  62798. if (isOnDesktop())
  62799. {
  62800. shadower = 0;
  62801. Component::addToDesktop (getDesktopWindowStyleFlags());
  62802. }
  62803. else
  62804. {
  62805. if (useShadow && isOpaque())
  62806. {
  62807. if (shadower == 0)
  62808. {
  62809. shadower = getLookAndFeel().createDropShadowerForComponent (this);
  62810. if (shadower != 0)
  62811. shadower->setOwner (this);
  62812. }
  62813. }
  62814. else
  62815. {
  62816. shadower = 0;
  62817. }
  62818. }
  62819. }
  62820. void TopLevelWindow::setUsingNativeTitleBar (const bool useNativeTitleBar_)
  62821. {
  62822. if (useNativeTitleBar != useNativeTitleBar_)
  62823. {
  62824. useNativeTitleBar = useNativeTitleBar_;
  62825. recreateDesktopWindow();
  62826. sendLookAndFeelChange();
  62827. }
  62828. }
  62829. void TopLevelWindow::recreateDesktopWindow()
  62830. {
  62831. if (isOnDesktop())
  62832. {
  62833. Component::addToDesktop (getDesktopWindowStyleFlags());
  62834. toFront (true);
  62835. }
  62836. }
  62837. void TopLevelWindow::addToDesktop (int windowStyleFlags, void* nativeWindowToAttachTo)
  62838. {
  62839. /* It's not recommended to change the desktop window flags directly for a TopLevelWindow,
  62840. because this class needs to make sure its layout corresponds with settings like whether
  62841. it's got a native title bar or not.
  62842. If you need custom flags for your window, you can override the getDesktopWindowStyleFlags()
  62843. method. If you do this, it's best to call the base class's getDesktopWindowStyleFlags()
  62844. method, then add or remove whatever flags are necessary from this value before returning it.
  62845. */
  62846. jassert ((windowStyleFlags & ~ComponentPeer::windowIsSemiTransparent)
  62847. == (getDesktopWindowStyleFlags() & ~ComponentPeer::windowIsSemiTransparent));
  62848. Component::addToDesktop (windowStyleFlags, nativeWindowToAttachTo);
  62849. if (windowStyleFlags != getDesktopWindowStyleFlags())
  62850. sendLookAndFeelChange();
  62851. }
  62852. void TopLevelWindow::centreAroundComponent (Component* c, const int width, const int height)
  62853. {
  62854. if (c == 0)
  62855. c = TopLevelWindow::getActiveTopLevelWindow();
  62856. if (c == 0)
  62857. {
  62858. centreWithSize (width, height);
  62859. }
  62860. else
  62861. {
  62862. Point<int> p (c->relativePositionToGlobal (Point<int> ((c->getWidth() - width) / 2,
  62863. (c->getHeight() - height) / 2)));
  62864. Rectangle<int> parentArea (c->getParentMonitorArea());
  62865. if (getParentComponent() != 0)
  62866. {
  62867. p = getParentComponent()->globalPositionToRelative (p);
  62868. parentArea.setBounds (0, 0, getParentWidth(), getParentHeight());
  62869. }
  62870. parentArea.reduce (12, 12);
  62871. setBounds (jlimit (parentArea.getX(), jmax (parentArea.getX(), parentArea.getRight() - width), p.getX()),
  62872. jlimit (parentArea.getY(), jmax (parentArea.getY(), parentArea.getBottom() - height), p.getY()),
  62873. width, height);
  62874. }
  62875. }
  62876. int TopLevelWindow::getNumTopLevelWindows() throw()
  62877. {
  62878. return TopLevelWindowManager::getInstance()->windows.size();
  62879. }
  62880. TopLevelWindow* TopLevelWindow::getTopLevelWindow (const int index) throw()
  62881. {
  62882. return (TopLevelWindow*) TopLevelWindowManager::getInstance()->windows [index];
  62883. }
  62884. TopLevelWindow* TopLevelWindow::getActiveTopLevelWindow() throw()
  62885. {
  62886. TopLevelWindow* best = 0;
  62887. int bestNumTWLParents = -1;
  62888. for (int i = TopLevelWindow::getNumTopLevelWindows(); --i >= 0;)
  62889. {
  62890. TopLevelWindow* const tlw = TopLevelWindow::getTopLevelWindow (i);
  62891. if (tlw->isActiveWindow())
  62892. {
  62893. int numTWLParents = 0;
  62894. const Component* c = tlw->getParentComponent();
  62895. while (c != 0)
  62896. {
  62897. if (dynamic_cast <const TopLevelWindow*> (c) != 0)
  62898. ++numTWLParents;
  62899. c = c->getParentComponent();
  62900. }
  62901. if (bestNumTWLParents < numTWLParents)
  62902. {
  62903. best = tlw;
  62904. bestNumTWLParents = numTWLParents;
  62905. }
  62906. }
  62907. }
  62908. return best;
  62909. }
  62910. END_JUCE_NAMESPACE
  62911. /*** End of inlined file: juce_TopLevelWindow.cpp ***/
  62912. /*** Start of inlined file: juce_Colour.cpp ***/
  62913. BEGIN_JUCE_NAMESPACE
  62914. namespace ColourHelpers
  62915. {
  62916. static uint8 floatAlphaToInt (const float alpha) throw()
  62917. {
  62918. return (uint8) jlimit (0, 0xff, roundToInt (alpha * 255.0f));
  62919. }
  62920. static void convertHSBtoRGB (float h, float s, float v,
  62921. uint8& r, uint8& g, uint8& b) throw()
  62922. {
  62923. v = jlimit (0.0f, 1.0f, v);
  62924. v *= 255.0f;
  62925. const uint8 intV = (uint8) roundToInt (v);
  62926. if (s <= 0)
  62927. {
  62928. r = intV;
  62929. g = intV;
  62930. b = intV;
  62931. }
  62932. else
  62933. {
  62934. s = jmin (1.0f, s);
  62935. h = jlimit (0.0f, 1.0f, h);
  62936. h = (h - floorf (h)) * 6.0f + 0.00001f; // need a small adjustment to compensate for rounding errors
  62937. const float f = h - floorf (h);
  62938. const uint8 x = (uint8) roundToInt (v * (1.0f - s));
  62939. const float y = v * (1.0f - s * f);
  62940. const float z = v * (1.0f - (s * (1.0f - f)));
  62941. if (h < 1.0f)
  62942. {
  62943. r = intV;
  62944. g = (uint8) roundToInt (z);
  62945. b = x;
  62946. }
  62947. else if (h < 2.0f)
  62948. {
  62949. r = (uint8) roundToInt (y);
  62950. g = intV;
  62951. b = x;
  62952. }
  62953. else if (h < 3.0f)
  62954. {
  62955. r = x;
  62956. g = intV;
  62957. b = (uint8) roundToInt (z);
  62958. }
  62959. else if (h < 4.0f)
  62960. {
  62961. r = x;
  62962. g = (uint8) roundToInt (y);
  62963. b = intV;
  62964. }
  62965. else if (h < 5.0f)
  62966. {
  62967. r = (uint8) roundToInt (z);
  62968. g = x;
  62969. b = intV;
  62970. }
  62971. else if (h < 6.0f)
  62972. {
  62973. r = intV;
  62974. g = x;
  62975. b = (uint8) roundToInt (y);
  62976. }
  62977. else
  62978. {
  62979. r = 0;
  62980. g = 0;
  62981. b = 0;
  62982. }
  62983. }
  62984. }
  62985. }
  62986. Colour::Colour() throw()
  62987. : argb (0)
  62988. {
  62989. }
  62990. Colour::Colour (const Colour& other) throw()
  62991. : argb (other.argb)
  62992. {
  62993. }
  62994. Colour& Colour::operator= (const Colour& other) throw()
  62995. {
  62996. argb = other.argb;
  62997. return *this;
  62998. }
  62999. bool Colour::operator== (const Colour& other) const throw()
  63000. {
  63001. return argb.getARGB() == other.argb.getARGB();
  63002. }
  63003. bool Colour::operator!= (const Colour& other) const throw()
  63004. {
  63005. return argb.getARGB() != other.argb.getARGB();
  63006. }
  63007. Colour::Colour (const uint32 argb_) throw()
  63008. : argb (argb_)
  63009. {
  63010. }
  63011. Colour::Colour (const uint8 red,
  63012. const uint8 green,
  63013. const uint8 blue) throw()
  63014. {
  63015. argb.setARGB (0xff, red, green, blue);
  63016. }
  63017. const Colour Colour::fromRGB (const uint8 red,
  63018. const uint8 green,
  63019. const uint8 blue) throw()
  63020. {
  63021. return Colour (red, green, blue);
  63022. }
  63023. Colour::Colour (const uint8 red,
  63024. const uint8 green,
  63025. const uint8 blue,
  63026. const uint8 alpha) throw()
  63027. {
  63028. argb.setARGB (alpha, red, green, blue);
  63029. }
  63030. const Colour Colour::fromRGBA (const uint8 red,
  63031. const uint8 green,
  63032. const uint8 blue,
  63033. const uint8 alpha) throw()
  63034. {
  63035. return Colour (red, green, blue, alpha);
  63036. }
  63037. Colour::Colour (const uint8 red,
  63038. const uint8 green,
  63039. const uint8 blue,
  63040. const float alpha) throw()
  63041. {
  63042. argb.setARGB (ColourHelpers::floatAlphaToInt (alpha), red, green, blue);
  63043. }
  63044. const Colour Colour::fromRGBAFloat (const uint8 red,
  63045. const uint8 green,
  63046. const uint8 blue,
  63047. const float alpha) throw()
  63048. {
  63049. return Colour (red, green, blue, alpha);
  63050. }
  63051. Colour::Colour (const float hue,
  63052. const float saturation,
  63053. const float brightness,
  63054. const float alpha) throw()
  63055. {
  63056. uint8 r = getRed(), g = getGreen(), b = getBlue();
  63057. ColourHelpers::convertHSBtoRGB (hue, saturation, brightness, r, g, b);
  63058. argb.setARGB (ColourHelpers::floatAlphaToInt (alpha), r, g, b);
  63059. }
  63060. const Colour Colour::fromHSV (const float hue,
  63061. const float saturation,
  63062. const float brightness,
  63063. const float alpha) throw()
  63064. {
  63065. return Colour (hue, saturation, brightness, alpha);
  63066. }
  63067. Colour::Colour (const float hue,
  63068. const float saturation,
  63069. const float brightness,
  63070. const uint8 alpha) throw()
  63071. {
  63072. uint8 r = getRed(), g = getGreen(), b = getBlue();
  63073. ColourHelpers::convertHSBtoRGB (hue, saturation, brightness, r, g, b);
  63074. argb.setARGB (alpha, r, g, b);
  63075. }
  63076. Colour::~Colour() throw()
  63077. {
  63078. }
  63079. const PixelARGB Colour::getPixelARGB() const throw()
  63080. {
  63081. PixelARGB p (argb);
  63082. p.premultiply();
  63083. return p;
  63084. }
  63085. uint32 Colour::getARGB() const throw()
  63086. {
  63087. return argb.getARGB();
  63088. }
  63089. bool Colour::isTransparent() const throw()
  63090. {
  63091. return getAlpha() == 0;
  63092. }
  63093. bool Colour::isOpaque() const throw()
  63094. {
  63095. return getAlpha() == 0xff;
  63096. }
  63097. const Colour Colour::withAlpha (const uint8 newAlpha) const throw()
  63098. {
  63099. PixelARGB newCol (argb);
  63100. newCol.setAlpha (newAlpha);
  63101. return Colour (newCol.getARGB());
  63102. }
  63103. const Colour Colour::withAlpha (const float newAlpha) const throw()
  63104. {
  63105. jassert (newAlpha >= 0 && newAlpha <= 1.0f);
  63106. PixelARGB newCol (argb);
  63107. newCol.setAlpha (ColourHelpers::floatAlphaToInt (newAlpha));
  63108. return Colour (newCol.getARGB());
  63109. }
  63110. const Colour Colour::withMultipliedAlpha (const float alphaMultiplier) const throw()
  63111. {
  63112. jassert (alphaMultiplier >= 0);
  63113. PixelARGB newCol (argb);
  63114. newCol.setAlpha ((uint8) jmin (0xff, roundToInt (alphaMultiplier * newCol.getAlpha())));
  63115. return Colour (newCol.getARGB());
  63116. }
  63117. const Colour Colour::overlaidWith (const Colour& src) const throw()
  63118. {
  63119. const int destAlpha = getAlpha();
  63120. if (destAlpha > 0)
  63121. {
  63122. const int invA = 0xff - (int) src.getAlpha();
  63123. const int resA = 0xff - (((0xff - destAlpha) * invA) >> 8);
  63124. if (resA > 0)
  63125. {
  63126. const int da = (invA * destAlpha) / resA;
  63127. return Colour ((uint8) (src.getRed() + ((((int) getRed() - src.getRed()) * da) >> 8)),
  63128. (uint8) (src.getGreen() + ((((int) getGreen() - src.getGreen()) * da) >> 8)),
  63129. (uint8) (src.getBlue() + ((((int) getBlue() - src.getBlue()) * da) >> 8)),
  63130. (uint8) resA);
  63131. }
  63132. return *this;
  63133. }
  63134. else
  63135. {
  63136. return src;
  63137. }
  63138. }
  63139. const Colour Colour::interpolatedWith (const Colour& other, float proportionOfOther) const throw()
  63140. {
  63141. if (proportionOfOther <= 0)
  63142. return *this;
  63143. if (proportionOfOther >= 1.0f)
  63144. return other;
  63145. PixelARGB c1 (getPixelARGB());
  63146. const PixelARGB c2 (other.getPixelARGB());
  63147. c1.tween (c2, roundToInt (proportionOfOther * 255.0f));
  63148. c1.unpremultiply();
  63149. return Colour (c1.getARGB());
  63150. }
  63151. float Colour::getFloatRed() const throw()
  63152. {
  63153. return getRed() / 255.0f;
  63154. }
  63155. float Colour::getFloatGreen() const throw()
  63156. {
  63157. return getGreen() / 255.0f;
  63158. }
  63159. float Colour::getFloatBlue() const throw()
  63160. {
  63161. return getBlue() / 255.0f;
  63162. }
  63163. float Colour::getFloatAlpha() const throw()
  63164. {
  63165. return getAlpha() / 255.0f;
  63166. }
  63167. void Colour::getHSB (float& h, float& s, float& v) const throw()
  63168. {
  63169. const int r = getRed();
  63170. const int g = getGreen();
  63171. const int b = getBlue();
  63172. const int hi = jmax (r, g, b);
  63173. const int lo = jmin (r, g, b);
  63174. if (hi != 0)
  63175. {
  63176. s = (hi - lo) / (float) hi;
  63177. if (s != 0)
  63178. {
  63179. const float invDiff = 1.0f / (hi - lo);
  63180. const float red = (hi - r) * invDiff;
  63181. const float green = (hi - g) * invDiff;
  63182. const float blue = (hi - b) * invDiff;
  63183. if (r == hi)
  63184. h = blue - green;
  63185. else if (g == hi)
  63186. h = 2.0f + red - blue;
  63187. else
  63188. h = 4.0f + green - red;
  63189. h *= 1.0f / 6.0f;
  63190. if (h < 0)
  63191. ++h;
  63192. }
  63193. else
  63194. {
  63195. h = 0;
  63196. }
  63197. }
  63198. else
  63199. {
  63200. s = 0;
  63201. h = 0;
  63202. }
  63203. v = hi / 255.0f;
  63204. }
  63205. float Colour::getHue() const throw()
  63206. {
  63207. float h, s, b;
  63208. getHSB (h, s, b);
  63209. return h;
  63210. }
  63211. const Colour Colour::withHue (const float hue) const throw()
  63212. {
  63213. float h, s, b;
  63214. getHSB (h, s, b);
  63215. return Colour (hue, s, b, getAlpha());
  63216. }
  63217. const Colour Colour::withRotatedHue (const float amountToRotate) const throw()
  63218. {
  63219. float h, s, b;
  63220. getHSB (h, s, b);
  63221. h += amountToRotate;
  63222. h -= floorf (h);
  63223. return Colour (h, s, b, getAlpha());
  63224. }
  63225. float Colour::getSaturation() const throw()
  63226. {
  63227. float h, s, b;
  63228. getHSB (h, s, b);
  63229. return s;
  63230. }
  63231. const Colour Colour::withSaturation (const float saturation) const throw()
  63232. {
  63233. float h, s, b;
  63234. getHSB (h, s, b);
  63235. return Colour (h, saturation, b, getAlpha());
  63236. }
  63237. const Colour Colour::withMultipliedSaturation (const float amount) const throw()
  63238. {
  63239. float h, s, b;
  63240. getHSB (h, s, b);
  63241. return Colour (h, jmin (1.0f, s * amount), b, getAlpha());
  63242. }
  63243. float Colour::getBrightness() const throw()
  63244. {
  63245. float h, s, b;
  63246. getHSB (h, s, b);
  63247. return b;
  63248. }
  63249. const Colour Colour::withBrightness (const float brightness) const throw()
  63250. {
  63251. float h, s, b;
  63252. getHSB (h, s, b);
  63253. return Colour (h, s, brightness, getAlpha());
  63254. }
  63255. const Colour Colour::withMultipliedBrightness (const float amount) const throw()
  63256. {
  63257. float h, s, b;
  63258. getHSB (h, s, b);
  63259. b *= amount;
  63260. if (b > 1.0f)
  63261. b = 1.0f;
  63262. return Colour (h, s, b, getAlpha());
  63263. }
  63264. const Colour Colour::brighter (float amount) const throw()
  63265. {
  63266. amount = 1.0f / (1.0f + amount);
  63267. return Colour ((uint8) (255 - (amount * (255 - getRed()))),
  63268. (uint8) (255 - (amount * (255 - getGreen()))),
  63269. (uint8) (255 - (amount * (255 - getBlue()))),
  63270. getAlpha());
  63271. }
  63272. const Colour Colour::darker (float amount) const throw()
  63273. {
  63274. amount = 1.0f / (1.0f + amount);
  63275. return Colour ((uint8) (amount * getRed()),
  63276. (uint8) (amount * getGreen()),
  63277. (uint8) (amount * getBlue()),
  63278. getAlpha());
  63279. }
  63280. const Colour Colour::greyLevel (const float brightness) throw()
  63281. {
  63282. const uint8 level
  63283. = (uint8) jlimit (0x00, 0xff, roundToInt (brightness * 255.0f));
  63284. return Colour (level, level, level);
  63285. }
  63286. const Colour Colour::contrasting (const float amount) const throw()
  63287. {
  63288. return overlaidWith ((((int) getRed() + (int) getGreen() + (int) getBlue() >= 3 * 128)
  63289. ? Colours::black
  63290. : Colours::white).withAlpha (amount));
  63291. }
  63292. const Colour Colour::contrasting (const Colour& colour1,
  63293. const Colour& colour2) throw()
  63294. {
  63295. const float b1 = colour1.getBrightness();
  63296. const float b2 = colour2.getBrightness();
  63297. float best = 0.0f;
  63298. float bestDist = 0.0f;
  63299. for (float i = 0.0f; i < 1.0f; i += 0.02f)
  63300. {
  63301. const float d1 = fabsf (i - b1);
  63302. const float d2 = fabsf (i - b2);
  63303. const float dist = jmin (d1, d2, 1.0f - d1, 1.0f - d2);
  63304. if (dist > bestDist)
  63305. {
  63306. best = i;
  63307. bestDist = dist;
  63308. }
  63309. }
  63310. return colour1.overlaidWith (colour2.withMultipliedAlpha (0.5f))
  63311. .withBrightness (best);
  63312. }
  63313. const String Colour::toString() const
  63314. {
  63315. return String::toHexString ((int) argb.getARGB());
  63316. }
  63317. const Colour Colour::fromString (const String& encodedColourString)
  63318. {
  63319. return Colour ((uint32) encodedColourString.getHexValue32());
  63320. }
  63321. const String Colour::toDisplayString (const bool includeAlphaValue) const
  63322. {
  63323. return String::toHexString ((int) (argb.getARGB() & (includeAlphaValue ? 0xffffffff : 0xffffff)))
  63324. .paddedLeft ('0', includeAlphaValue ? 8 : 6)
  63325. .toUpperCase();
  63326. }
  63327. END_JUCE_NAMESPACE
  63328. /*** End of inlined file: juce_Colour.cpp ***/
  63329. /*** Start of inlined file: juce_ColourGradient.cpp ***/
  63330. BEGIN_JUCE_NAMESPACE
  63331. ColourGradient::ColourGradient() throw()
  63332. {
  63333. #ifdef JUCE_DEBUG
  63334. x1 = 987654.0f;
  63335. #endif
  63336. }
  63337. ColourGradient::ColourGradient (const Colour& colour1,
  63338. const float x1_,
  63339. const float y1_,
  63340. const Colour& colour2,
  63341. const float x2_,
  63342. const float y2_,
  63343. const bool isRadial_) throw()
  63344. : x1 (x1_),
  63345. y1 (y1_),
  63346. x2 (x2_),
  63347. y2 (y2_),
  63348. isRadial (isRadial_)
  63349. {
  63350. colours.add (0);
  63351. colours.add (colour1.getARGB());
  63352. colours.add (1 << 16);
  63353. colours.add (colour2.getARGB());
  63354. }
  63355. ColourGradient::~ColourGradient() throw()
  63356. {
  63357. }
  63358. void ColourGradient::clearColours() throw()
  63359. {
  63360. colours.clear();
  63361. }
  63362. void ColourGradient::addColour (const double proportionAlongGradient,
  63363. const Colour& colour) throw()
  63364. {
  63365. // must be within the two end-points
  63366. jassert (proportionAlongGradient >= 0 && proportionAlongGradient <= 1.0);
  63367. const uint32 pos = jlimit (0, 65535, roundToInt (proportionAlongGradient * 65536.0));
  63368. int i;
  63369. for (i = 0; i < colours.size(); i += 2)
  63370. if (colours.getUnchecked(i) > pos)
  63371. break;
  63372. colours.insert (i, pos);
  63373. colours.insert (i + 1, colour.getARGB());
  63374. }
  63375. void ColourGradient::multiplyOpacity (const float multiplier) throw()
  63376. {
  63377. for (int i = 1; i < colours.size(); i += 2)
  63378. {
  63379. const Colour c (colours.getUnchecked(i));
  63380. colours.set (i, c.withMultipliedAlpha (multiplier).getARGB());
  63381. }
  63382. }
  63383. int ColourGradient::getNumColours() const throw()
  63384. {
  63385. return colours.size() >> 1;
  63386. }
  63387. double ColourGradient::getColourPosition (const int index) const throw()
  63388. {
  63389. return jlimit (0.0, 1.0, colours [index << 1] / 65535.0);
  63390. }
  63391. const Colour ColourGradient::getColour (const int index) const throw()
  63392. {
  63393. return Colour (colours [(index << 1) + 1]);
  63394. }
  63395. const Colour ColourGradient::getColourAtPosition (const float position) const throw()
  63396. {
  63397. jassert (colours.getUnchecked (0) == 0); // the first colour specified has to go at position 0
  63398. const int integerPos = jlimit (0, 65535, roundToInt (position * 65536.0f));
  63399. if (integerPos <= 0 || colours.size() <= 2)
  63400. return getColour (0);
  63401. int i = colours.size() - 2;
  63402. while (integerPos < (int) colours.getUnchecked(i))
  63403. i -= 2;
  63404. if (i >= colours.size() - 2)
  63405. return Colour (colours.getUnchecked(i));
  63406. const int pos1 = colours.getUnchecked (i);
  63407. const Colour col1 (colours.getUnchecked (i + 1));
  63408. const int pos2 = colours.getUnchecked (i + 2);
  63409. const Colour col2 (colours.getUnchecked (i + 3));
  63410. return col1.interpolatedWith (col2, (integerPos - pos1) / (float) (pos2 - pos1));
  63411. }
  63412. int ColourGradient::createLookupTable (const AffineTransform& transform, HeapBlock <PixelARGB>& lookupTable) const throw()
  63413. {
  63414. #ifdef JUCE_DEBUG
  63415. // trying to use the object without setting its co-ordinates? Have a careful read of
  63416. // the comments for the constructors.
  63417. jassert (x1 != 987654.0f);
  63418. #endif
  63419. const int numColours = colours.size() >> 1;
  63420. float tx1 = x1, ty1 = y1, tx2 = x2, ty2 = y2;
  63421. transform.transformPoint (tx1, ty1);
  63422. transform.transformPoint (tx2, ty2);
  63423. const double distance = juce_hypot (tx1 - tx2, ty1 - ty2);
  63424. const int numEntries = jlimit (1, (numColours - 1) << 8, 3 * (int) distance);
  63425. lookupTable.malloc (numEntries);
  63426. if (numColours >= 2)
  63427. {
  63428. jassert (colours.getUnchecked (0) == 0); // the first colour specified has to go at position 0
  63429. PixelARGB pix1 (colours.getUnchecked (1));
  63430. pix1.premultiply();
  63431. int index = 0;
  63432. for (int j = 2; j < colours.size(); j += 2)
  63433. {
  63434. const int numToDo = ((colours.getUnchecked (j) * (numEntries - 1)) >> 16) - index;
  63435. PixelARGB pix2 (colours.getUnchecked (j + 1));
  63436. pix2.premultiply();
  63437. for (int i = 0; i < numToDo; ++i)
  63438. {
  63439. jassert (index >= 0 && index < numEntries);
  63440. lookupTable[index] = pix1;
  63441. lookupTable[index].tween (pix2, (i << 8) / numToDo);
  63442. ++index;
  63443. }
  63444. pix1 = pix2;
  63445. }
  63446. while (index < numEntries)
  63447. lookupTable [index++] = pix1;
  63448. }
  63449. else
  63450. {
  63451. jassertfalse // no colours specified!
  63452. }
  63453. return numEntries;
  63454. }
  63455. bool ColourGradient::isOpaque() const throw()
  63456. {
  63457. for (int i = 1; i < colours.size(); i += 2)
  63458. if (PixelARGB (colours.getUnchecked(i)).getAlpha() < 0xff)
  63459. return false;
  63460. return true;
  63461. }
  63462. bool ColourGradient::isInvisible() const throw()
  63463. {
  63464. for (int i = 1; i < colours.size(); i += 2)
  63465. if (PixelARGB (colours.getUnchecked(i)).getAlpha() > 0)
  63466. return false;
  63467. return true;
  63468. }
  63469. END_JUCE_NAMESPACE
  63470. /*** End of inlined file: juce_ColourGradient.cpp ***/
  63471. /*** Start of inlined file: juce_Colours.cpp ***/
  63472. BEGIN_JUCE_NAMESPACE
  63473. const Colour Colours::transparentBlack (0);
  63474. const Colour Colours::transparentWhite (0x00ffffff);
  63475. const Colour Colours::aliceblue (0xfff0f8ff);
  63476. const Colour Colours::antiquewhite (0xfffaebd7);
  63477. const Colour Colours::aqua (0xff00ffff);
  63478. const Colour Colours::aquamarine (0xff7fffd4);
  63479. const Colour Colours::azure (0xfff0ffff);
  63480. const Colour Colours::beige (0xfff5f5dc);
  63481. const Colour Colours::bisque (0xffffe4c4);
  63482. const Colour Colours::black (0xff000000);
  63483. const Colour Colours::blanchedalmond (0xffffebcd);
  63484. const Colour Colours::blue (0xff0000ff);
  63485. const Colour Colours::blueviolet (0xff8a2be2);
  63486. const Colour Colours::brown (0xffa52a2a);
  63487. const Colour Colours::burlywood (0xffdeb887);
  63488. const Colour Colours::cadetblue (0xff5f9ea0);
  63489. const Colour Colours::chartreuse (0xff7fff00);
  63490. const Colour Colours::chocolate (0xffd2691e);
  63491. const Colour Colours::coral (0xffff7f50);
  63492. const Colour Colours::cornflowerblue (0xff6495ed);
  63493. const Colour Colours::cornsilk (0xfffff8dc);
  63494. const Colour Colours::crimson (0xffdc143c);
  63495. const Colour Colours::cyan (0xff00ffff);
  63496. const Colour Colours::darkblue (0xff00008b);
  63497. const Colour Colours::darkcyan (0xff008b8b);
  63498. const Colour Colours::darkgoldenrod (0xffb8860b);
  63499. const Colour Colours::darkgrey (0xff555555);
  63500. const Colour Colours::darkgreen (0xff006400);
  63501. const Colour Colours::darkkhaki (0xffbdb76b);
  63502. const Colour Colours::darkmagenta (0xff8b008b);
  63503. const Colour Colours::darkolivegreen (0xff556b2f);
  63504. const Colour Colours::darkorange (0xffff8c00);
  63505. const Colour Colours::darkorchid (0xff9932cc);
  63506. const Colour Colours::darkred (0xff8b0000);
  63507. const Colour Colours::darksalmon (0xffe9967a);
  63508. const Colour Colours::darkseagreen (0xff8fbc8f);
  63509. const Colour Colours::darkslateblue (0xff483d8b);
  63510. const Colour Colours::darkslategrey (0xff2f4f4f);
  63511. const Colour Colours::darkturquoise (0xff00ced1);
  63512. const Colour Colours::darkviolet (0xff9400d3);
  63513. const Colour Colours::deeppink (0xffff1493);
  63514. const Colour Colours::deepskyblue (0xff00bfff);
  63515. const Colour Colours::dimgrey (0xff696969);
  63516. const Colour Colours::dodgerblue (0xff1e90ff);
  63517. const Colour Colours::firebrick (0xffb22222);
  63518. const Colour Colours::floralwhite (0xfffffaf0);
  63519. const Colour Colours::forestgreen (0xff228b22);
  63520. const Colour Colours::fuchsia (0xffff00ff);
  63521. const Colour Colours::gainsboro (0xffdcdcdc);
  63522. const Colour Colours::gold (0xffffd700);
  63523. const Colour Colours::goldenrod (0xffdaa520);
  63524. const Colour Colours::grey (0xff808080);
  63525. const Colour Colours::green (0xff008000);
  63526. const Colour Colours::greenyellow (0xffadff2f);
  63527. const Colour Colours::honeydew (0xfff0fff0);
  63528. const Colour Colours::hotpink (0xffff69b4);
  63529. const Colour Colours::indianred (0xffcd5c5c);
  63530. const Colour Colours::indigo (0xff4b0082);
  63531. const Colour Colours::ivory (0xfffffff0);
  63532. const Colour Colours::khaki (0xfff0e68c);
  63533. const Colour Colours::lavender (0xffe6e6fa);
  63534. const Colour Colours::lavenderblush (0xfffff0f5);
  63535. const Colour Colours::lemonchiffon (0xfffffacd);
  63536. const Colour Colours::lightblue (0xffadd8e6);
  63537. const Colour Colours::lightcoral (0xfff08080);
  63538. const Colour Colours::lightcyan (0xffe0ffff);
  63539. const Colour Colours::lightgoldenrodyellow (0xfffafad2);
  63540. const Colour Colours::lightgreen (0xff90ee90);
  63541. const Colour Colours::lightgrey (0xffd3d3d3);
  63542. const Colour Colours::lightpink (0xffffb6c1);
  63543. const Colour Colours::lightsalmon (0xffffa07a);
  63544. const Colour Colours::lightseagreen (0xff20b2aa);
  63545. const Colour Colours::lightskyblue (0xff87cefa);
  63546. const Colour Colours::lightslategrey (0xff778899);
  63547. const Colour Colours::lightsteelblue (0xffb0c4de);
  63548. const Colour Colours::lightyellow (0xffffffe0);
  63549. const Colour Colours::lime (0xff00ff00);
  63550. const Colour Colours::limegreen (0xff32cd32);
  63551. const Colour Colours::linen (0xfffaf0e6);
  63552. const Colour Colours::magenta (0xffff00ff);
  63553. const Colour Colours::maroon (0xff800000);
  63554. const Colour Colours::mediumaquamarine (0xff66cdaa);
  63555. const Colour Colours::mediumblue (0xff0000cd);
  63556. const Colour Colours::mediumorchid (0xffba55d3);
  63557. const Colour Colours::mediumpurple (0xff9370db);
  63558. const Colour Colours::mediumseagreen (0xff3cb371);
  63559. const Colour Colours::mediumslateblue (0xff7b68ee);
  63560. const Colour Colours::mediumspringgreen (0xff00fa9a);
  63561. const Colour Colours::mediumturquoise (0xff48d1cc);
  63562. const Colour Colours::mediumvioletred (0xffc71585);
  63563. const Colour Colours::midnightblue (0xff191970);
  63564. const Colour Colours::mintcream (0xfff5fffa);
  63565. const Colour Colours::mistyrose (0xffffe4e1);
  63566. const Colour Colours::navajowhite (0xffffdead);
  63567. const Colour Colours::navy (0xff000080);
  63568. const Colour Colours::oldlace (0xfffdf5e6);
  63569. const Colour Colours::olive (0xff808000);
  63570. const Colour Colours::olivedrab (0xff6b8e23);
  63571. const Colour Colours::orange (0xffffa500);
  63572. const Colour Colours::orangered (0xffff4500);
  63573. const Colour Colours::orchid (0xffda70d6);
  63574. const Colour Colours::palegoldenrod (0xffeee8aa);
  63575. const Colour Colours::palegreen (0xff98fb98);
  63576. const Colour Colours::paleturquoise (0xffafeeee);
  63577. const Colour Colours::palevioletred (0xffdb7093);
  63578. const Colour Colours::papayawhip (0xffffefd5);
  63579. const Colour Colours::peachpuff (0xffffdab9);
  63580. const Colour Colours::peru (0xffcd853f);
  63581. const Colour Colours::pink (0xffffc0cb);
  63582. const Colour Colours::plum (0xffdda0dd);
  63583. const Colour Colours::powderblue (0xffb0e0e6);
  63584. const Colour Colours::purple (0xff800080);
  63585. const Colour Colours::red (0xffff0000);
  63586. const Colour Colours::rosybrown (0xffbc8f8f);
  63587. const Colour Colours::royalblue (0xff4169e1);
  63588. const Colour Colours::saddlebrown (0xff8b4513);
  63589. const Colour Colours::salmon (0xfffa8072);
  63590. const Colour Colours::sandybrown (0xfff4a460);
  63591. const Colour Colours::seagreen (0xff2e8b57);
  63592. const Colour Colours::seashell (0xfffff5ee);
  63593. const Colour Colours::sienna (0xffa0522d);
  63594. const Colour Colours::silver (0xffc0c0c0);
  63595. const Colour Colours::skyblue (0xff87ceeb);
  63596. const Colour Colours::slateblue (0xff6a5acd);
  63597. const Colour Colours::slategrey (0xff708090);
  63598. const Colour Colours::snow (0xfffffafa);
  63599. const Colour Colours::springgreen (0xff00ff7f);
  63600. const Colour Colours::steelblue (0xff4682b4);
  63601. const Colour Colours::tan (0xffd2b48c);
  63602. const Colour Colours::teal (0xff008080);
  63603. const Colour Colours::thistle (0xffd8bfd8);
  63604. const Colour Colours::tomato (0xffff6347);
  63605. const Colour Colours::turquoise (0xff40e0d0);
  63606. const Colour Colours::violet (0xffee82ee);
  63607. const Colour Colours::wheat (0xfff5deb3);
  63608. const Colour Colours::white (0xffffffff);
  63609. const Colour Colours::whitesmoke (0xfff5f5f5);
  63610. const Colour Colours::yellow (0xffffff00);
  63611. const Colour Colours::yellowgreen (0xff9acd32);
  63612. const Colour Colours::findColourForName (const String& colourName,
  63613. const Colour& defaultColour)
  63614. {
  63615. static const int presets[] =
  63616. {
  63617. // (first value is the string's hashcode, second is ARGB)
  63618. 0x05978fff, 0xff000000, /* black */
  63619. 0x06bdcc29, 0xffffffff, /* white */
  63620. 0x002e305a, 0xff0000ff, /* blue */
  63621. 0x00308adf, 0xff808080, /* grey */
  63622. 0x05e0cf03, 0xff008000, /* green */
  63623. 0x0001b891, 0xffff0000, /* red */
  63624. 0xd43c6474, 0xffffff00, /* yellow */
  63625. 0x620886da, 0xfff0f8ff, /* aliceblue */
  63626. 0x20a2676a, 0xfffaebd7, /* antiquewhite */
  63627. 0x002dcebc, 0xff00ffff, /* aqua */
  63628. 0x46bb5f7e, 0xff7fffd4, /* aquamarine */
  63629. 0x0590228f, 0xfff0ffff, /* azure */
  63630. 0x05947fe4, 0xfff5f5dc, /* beige */
  63631. 0xad388e35, 0xffffe4c4, /* bisque */
  63632. 0x00674f7e, 0xffffebcd, /* blanchedalmond */
  63633. 0x39129959, 0xff8a2be2, /* blueviolet */
  63634. 0x059a8136, 0xffa52a2a, /* brown */
  63635. 0x89cea8f9, 0xffdeb887, /* burlywood */
  63636. 0x0fa260cf, 0xff5f9ea0, /* cadetblue */
  63637. 0x6b748956, 0xff7fff00, /* chartreuse */
  63638. 0x2903623c, 0xffd2691e, /* chocolate */
  63639. 0x05a74431, 0xffff7f50, /* coral */
  63640. 0x618d42dd, 0xff6495ed, /* cornflowerblue */
  63641. 0xe4b479fd, 0xfffff8dc, /* cornsilk */
  63642. 0x3d8c4edf, 0xffdc143c, /* crimson */
  63643. 0x002ed323, 0xff00ffff, /* cyan */
  63644. 0x67cc74d0, 0xff00008b, /* darkblue */
  63645. 0x67cd1799, 0xff008b8b, /* darkcyan */
  63646. 0x31bbd168, 0xffb8860b, /* darkgoldenrod */
  63647. 0x67cecf55, 0xff555555, /* darkgrey */
  63648. 0x920b194d, 0xff006400, /* darkgreen */
  63649. 0x923edd4c, 0xffbdb76b, /* darkkhaki */
  63650. 0x5c293873, 0xff8b008b, /* darkmagenta */
  63651. 0x6b6671fe, 0xff556b2f, /* darkolivegreen */
  63652. 0xbcfd2524, 0xffff8c00, /* darkorange */
  63653. 0xbcfdf799, 0xff9932cc, /* darkorchid */
  63654. 0x55ee0d5b, 0xff8b0000, /* darkred */
  63655. 0xc2e5f564, 0xffe9967a, /* darksalmon */
  63656. 0x61be858a, 0xff8fbc8f, /* darkseagreen */
  63657. 0xc2b0f2bd, 0xff483d8b, /* darkslateblue */
  63658. 0xc2b34d42, 0xff2f4f4f, /* darkslategrey */
  63659. 0x7cf2b06b, 0xff00ced1, /* darkturquoise */
  63660. 0xc8769375, 0xff9400d3, /* darkviolet */
  63661. 0x25832862, 0xffff1493, /* deeppink */
  63662. 0xfcad568f, 0xff00bfff, /* deepskyblue */
  63663. 0x634c8b67, 0xff696969, /* dimgrey */
  63664. 0x45c1ce55, 0xff1e90ff, /* dodgerblue */
  63665. 0xef19e3cb, 0xffb22222, /* firebrick */
  63666. 0xb852b195, 0xfffffaf0, /* floralwhite */
  63667. 0xd086fd06, 0xff228b22, /* forestgreen */
  63668. 0xe106b6d7, 0xffff00ff, /* fuchsia */
  63669. 0x7880d61e, 0xffdcdcdc, /* gainsboro */
  63670. 0x00308060, 0xffffd700, /* gold */
  63671. 0xb3b3bc1e, 0xffdaa520, /* goldenrod */
  63672. 0xbab8a537, 0xffadff2f, /* greenyellow */
  63673. 0xe4cacafb, 0xfff0fff0, /* honeydew */
  63674. 0x41892743, 0xffff69b4, /* hotpink */
  63675. 0xd5796f1a, 0xffcd5c5c, /* indianred */
  63676. 0xb969fed2, 0xff4b0082, /* indigo */
  63677. 0x05fef6a9, 0xfffffff0, /* ivory */
  63678. 0x06149302, 0xfff0e68c, /* khaki */
  63679. 0xad5a05c7, 0xffe6e6fa, /* lavender */
  63680. 0x7c4d5b99, 0xfffff0f5, /* lavenderblush */
  63681. 0x195756f0, 0xfffffacd, /* lemonchiffon */
  63682. 0x28e4ea70, 0xffadd8e6, /* lightblue */
  63683. 0xf3c7ccdb, 0xfff08080, /* lightcoral */
  63684. 0x28e58d39, 0xffe0ffff, /* lightcyan */
  63685. 0x21234e3c, 0xfffafad2, /* lightgoldenrodyellow */
  63686. 0xf40157ad, 0xff90ee90, /* lightgreen */
  63687. 0x28e744f5, 0xffd3d3d3, /* lightgrey */
  63688. 0x28eb3b8c, 0xffffb6c1, /* lightpink */
  63689. 0x9fb78304, 0xffffa07a, /* lightsalmon */
  63690. 0x50632b2a, 0xff20b2aa, /* lightseagreen */
  63691. 0x68fb7b25, 0xff87cefa, /* lightskyblue */
  63692. 0xa8a35ba2, 0xff778899, /* lightslategrey */
  63693. 0xa20d484f, 0xffb0c4de, /* lightsteelblue */
  63694. 0xaa2cf10a, 0xffffffe0, /* lightyellow */
  63695. 0x0032afd5, 0xff00ff00, /* lime */
  63696. 0x607bbc4e, 0xff32cd32, /* limegreen */
  63697. 0x06234efa, 0xfffaf0e6, /* linen */
  63698. 0x316858a9, 0xffff00ff, /* magenta */
  63699. 0xbf8ca470, 0xff800000, /* maroon */
  63700. 0xbd58e0b3, 0xff66cdaa, /* mediumaquamarine */
  63701. 0x967dfd4f, 0xff0000cd, /* mediumblue */
  63702. 0x056f5c58, 0xffba55d3, /* mediumorchid */
  63703. 0x07556b71, 0xff9370db, /* mediumpurple */
  63704. 0x5369b689, 0xff3cb371, /* mediumseagreen */
  63705. 0x066be19e, 0xff7b68ee, /* mediumslateblue */
  63706. 0x3256b281, 0xff00fa9a, /* mediumspringgreen */
  63707. 0xc0ad9f4c, 0xff48d1cc, /* mediumturquoise */
  63708. 0x628e63dd, 0xffc71585, /* mediumvioletred */
  63709. 0x168eb32a, 0xff191970, /* midnightblue */
  63710. 0x4306b960, 0xfff5fffa, /* mintcream */
  63711. 0x4cbc0e6b, 0xffffe4e1, /* mistyrose */
  63712. 0xe97218a6, 0xffffdead, /* navajowhite */
  63713. 0x00337bb6, 0xff000080, /* navy */
  63714. 0xadd2d33e, 0xfffdf5e6, /* oldlace */
  63715. 0x064ee1db, 0xff808000, /* olive */
  63716. 0x9e33a98a, 0xff6b8e23, /* olivedrab */
  63717. 0xc3de262e, 0xffffa500, /* orange */
  63718. 0x58bebba3, 0xffff4500, /* orangered */
  63719. 0xc3def8a3, 0xffda70d6, /* orchid */
  63720. 0x28cb4834, 0xffeee8aa, /* palegoldenrod */
  63721. 0x3d9dd619, 0xff98fb98, /* palegreen */
  63722. 0x74022737, 0xffafeeee, /* paleturquoise */
  63723. 0x15e2ebc8, 0xffdb7093, /* palevioletred */
  63724. 0x5fd898e2, 0xffffefd5, /* papayawhip */
  63725. 0x93e1b776, 0xffffdab9, /* peachpuff */
  63726. 0x003472f8, 0xffcd853f, /* peru */
  63727. 0x00348176, 0xffffc0cb, /* pink */
  63728. 0x00348d94, 0xffdda0dd, /* plum */
  63729. 0xd036be93, 0xffb0e0e6, /* powderblue */
  63730. 0xc5c507bc, 0xff800080, /* purple */
  63731. 0xa89d65b3, 0xffbc8f8f, /* rosybrown */
  63732. 0xbd9413e1, 0xff4169e1, /* royalblue */
  63733. 0xf456044f, 0xff8b4513, /* saddlebrown */
  63734. 0xc9c6f66e, 0xfffa8072, /* salmon */
  63735. 0x0bb131e1, 0xfff4a460, /* sandybrown */
  63736. 0x34636c14, 0xff2e8b57, /* seagreen */
  63737. 0x3507fb41, 0xfffff5ee, /* seashell */
  63738. 0xca348772, 0xffa0522d, /* sienna */
  63739. 0xca37d30d, 0xffc0c0c0, /* silver */
  63740. 0x80da74fb, 0xff87ceeb, /* skyblue */
  63741. 0x44a8dd73, 0xff6a5acd, /* slateblue */
  63742. 0x44ab37f8, 0xff708090, /* slategrey */
  63743. 0x0035f183, 0xfffffafa, /* snow */
  63744. 0xd5440d16, 0xff00ff7f, /* springgreen */
  63745. 0x3e1524a5, 0xff4682b4, /* steelblue */
  63746. 0x0001bfa1, 0xffd2b48c, /* tan */
  63747. 0x0036425c, 0xff008080, /* teal */
  63748. 0xafc8858f, 0xffd8bfd8, /* thistle */
  63749. 0xcc41600a, 0xffff6347, /* tomato */
  63750. 0xfeea9b21, 0xff40e0d0, /* turquoise */
  63751. 0xcf57947f, 0xffee82ee, /* violet */
  63752. 0x06bdbae7, 0xfff5deb3, /* wheat */
  63753. 0x10802ee6, 0xfff5f5f5, /* whitesmoke */
  63754. 0xe1b5130f, 0xff9acd32 /* yellowgreen */
  63755. };
  63756. const int hash = colourName.trim().toLowerCase().hashCode();
  63757. for (int i = 0; i < numElementsInArray (presets); i += 2)
  63758. if (presets [i] == hash)
  63759. return Colour (presets [i + 1]);
  63760. return defaultColour;
  63761. }
  63762. END_JUCE_NAMESPACE
  63763. /*** End of inlined file: juce_Colours.cpp ***/
  63764. /*** Start of inlined file: juce_EdgeTable.cpp ***/
  63765. BEGIN_JUCE_NAMESPACE
  63766. const int juce_edgeTableDefaultEdgesPerLine = 32;
  63767. EdgeTable::EdgeTable (const Rectangle<int>& bounds_,
  63768. const Path& path, const AffineTransform& transform)
  63769. : bounds (bounds_),
  63770. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  63771. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  63772. needToCheckEmptinesss (true)
  63773. {
  63774. table.malloc ((bounds.getHeight() + 1) * lineStrideElements);
  63775. int* t = table;
  63776. for (int i = bounds.getHeight(); --i >= 0;)
  63777. {
  63778. *t = 0;
  63779. t += lineStrideElements;
  63780. }
  63781. const int topLimit = bounds.getY() << 8;
  63782. const int heightLimit = bounds.getHeight() << 8;
  63783. const int leftLimit = bounds.getX() << 8;
  63784. const int rightLimit = bounds.getRight() << 8;
  63785. PathFlatteningIterator iter (path, transform);
  63786. while (iter.next())
  63787. {
  63788. int y1 = roundToInt (iter.y1 * 256.0f);
  63789. int y2 = roundToInt (iter.y2 * 256.0f);
  63790. if (y1 != y2)
  63791. {
  63792. y1 -= topLimit;
  63793. y2 -= topLimit;
  63794. const int startY = y1;
  63795. int direction = -1;
  63796. if (y1 > y2)
  63797. {
  63798. swapVariables (y1, y2);
  63799. direction = 1;
  63800. }
  63801. if (y1 < 0)
  63802. y1 = 0;
  63803. if (y2 > heightLimit)
  63804. y2 = heightLimit;
  63805. if (y1 < y2)
  63806. {
  63807. const double startX = 256.0f * iter.x1;
  63808. const double multiplier = (iter.x2 - iter.x1) / (iter.y2 - iter.y1);
  63809. const int stepSize = jlimit (1, 256, 256 / (1 + (int) fabs (multiplier)));
  63810. do
  63811. {
  63812. const int step = jmin (stepSize, y2 - y1, 256 - (y1 & 255));
  63813. int x = roundToInt (startX + multiplier * ((y1 + (step >> 1)) - startY));
  63814. if (x < leftLimit)
  63815. x = leftLimit;
  63816. else if (x >= rightLimit)
  63817. x = rightLimit - 1;
  63818. addEdgePoint (x, y1 >> 8, direction * step);
  63819. y1 += step;
  63820. }
  63821. while (y1 < y2);
  63822. }
  63823. }
  63824. }
  63825. sanitiseLevels (path.isUsingNonZeroWinding());
  63826. }
  63827. EdgeTable::EdgeTable (const Rectangle<int>& rectangleToAdd)
  63828. : bounds (rectangleToAdd),
  63829. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  63830. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  63831. needToCheckEmptinesss (true)
  63832. {
  63833. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  63834. table[0] = 0;
  63835. const int x1 = rectangleToAdd.getX() << 8;
  63836. const int x2 = rectangleToAdd.getRight() << 8;
  63837. int* t = table;
  63838. for (int i = rectangleToAdd.getHeight(); --i >= 0;)
  63839. {
  63840. t[0] = 2;
  63841. t[1] = x1;
  63842. t[2] = 255;
  63843. t[3] = x2;
  63844. t[4] = 0;
  63845. t += lineStrideElements;
  63846. }
  63847. }
  63848. EdgeTable::EdgeTable (const RectangleList& rectanglesToAdd)
  63849. : bounds (rectanglesToAdd.getBounds()),
  63850. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  63851. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  63852. needToCheckEmptinesss (true)
  63853. {
  63854. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  63855. int* t = table;
  63856. for (int i = bounds.getHeight(); --i >= 0;)
  63857. {
  63858. *t = 0;
  63859. t += lineStrideElements;
  63860. }
  63861. for (RectangleList::Iterator iter (rectanglesToAdd); iter.next();)
  63862. {
  63863. const Rectangle<int>* const r = iter.getRectangle();
  63864. const int x1 = r->getX() << 8;
  63865. const int x2 = r->getRight() << 8;
  63866. int y = r->getY() - bounds.getY();
  63867. for (int j = r->getHeight(); --j >= 0;)
  63868. {
  63869. addEdgePoint (x1, y, 255);
  63870. addEdgePoint (x2, y, -255);
  63871. ++y;
  63872. }
  63873. }
  63874. sanitiseLevels (true);
  63875. }
  63876. EdgeTable::EdgeTable (const float x, const float y, const float w, const float h)
  63877. : bounds (Rectangle<int> ((int) floorf (x), roundToInt (y * 256.0f) >> 8, 2 + (int) w, 2 + (int) h)),
  63878. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  63879. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  63880. needToCheckEmptinesss (true)
  63881. {
  63882. jassert (w > 0 && h > 0);
  63883. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  63884. table[0] = 0;
  63885. const int x1 = roundToInt (x * 256.0f);
  63886. const int x2 = roundToInt ((x + w) * 256.0f);
  63887. int y1 = roundToInt (y * 256.0f) - (bounds.getY() << 8);
  63888. jassert (y1 < 256);
  63889. int y2 = roundToInt ((y + h) * 256.0f) - (bounds.getY() << 8);
  63890. if (x2 <= x1 || y2 <= y1)
  63891. {
  63892. bounds.setHeight (0);
  63893. return;
  63894. }
  63895. int lineY = 0;
  63896. int* t = table;
  63897. if ((y1 >> 8) == (y2 >> 8))
  63898. {
  63899. t[0] = 2;
  63900. t[1] = x1;
  63901. t[2] = y2 - y1;
  63902. t[3] = x2;
  63903. t[4] = 0;
  63904. ++lineY;
  63905. t += lineStrideElements;
  63906. }
  63907. else
  63908. {
  63909. t[0] = 2;
  63910. t[1] = x1;
  63911. t[2] = 255 - (y1 & 255);
  63912. t[3] = x2;
  63913. t[4] = 0;
  63914. ++lineY;
  63915. t += lineStrideElements;
  63916. while (lineY < (y2 >> 8))
  63917. {
  63918. t[0] = 2;
  63919. t[1] = x1;
  63920. t[2] = 255;
  63921. t[3] = x2;
  63922. t[4] = 0;
  63923. ++lineY;
  63924. t += lineStrideElements;
  63925. }
  63926. jassert (lineY < bounds.getHeight());
  63927. t[0] = 2;
  63928. t[1] = x1;
  63929. t[2] = y2 & 255;
  63930. t[3] = x2;
  63931. t[4] = 0;
  63932. ++lineY;
  63933. t += lineStrideElements;
  63934. }
  63935. while (lineY < bounds.getHeight())
  63936. {
  63937. t[0] = 0;
  63938. t += lineStrideElements;
  63939. ++lineY;
  63940. }
  63941. }
  63942. EdgeTable::EdgeTable (const EdgeTable& other)
  63943. : table (0)
  63944. {
  63945. operator= (other);
  63946. }
  63947. EdgeTable& EdgeTable::operator= (const EdgeTable& other)
  63948. {
  63949. bounds = other.bounds;
  63950. maxEdgesPerLine = other.maxEdgesPerLine;
  63951. lineStrideElements = other.lineStrideElements;
  63952. needToCheckEmptinesss = other.needToCheckEmptinesss;
  63953. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  63954. copyEdgeTableData (table, lineStrideElements, other.table, lineStrideElements, bounds.getHeight());
  63955. return *this;
  63956. }
  63957. EdgeTable::~EdgeTable()
  63958. {
  63959. }
  63960. void EdgeTable::copyEdgeTableData (int* dest, const int destLineStride, const int* src, const int srcLineStride, int numLines) throw()
  63961. {
  63962. while (--numLines >= 0)
  63963. {
  63964. memcpy (dest, src, (src[0] * 2 + 1) * sizeof (int));
  63965. src += srcLineStride;
  63966. dest += destLineStride;
  63967. }
  63968. }
  63969. void EdgeTable::sanitiseLevels (const bool useNonZeroWinding) throw()
  63970. {
  63971. // Convert the table from relative windings to absolute levels..
  63972. int* lineStart = table;
  63973. for (int i = bounds.getHeight(); --i >= 0;)
  63974. {
  63975. int* line = lineStart;
  63976. lineStart += lineStrideElements;
  63977. int num = *line;
  63978. if (num == 0)
  63979. continue;
  63980. int level = 0;
  63981. if (useNonZeroWinding)
  63982. {
  63983. while (--num > 0)
  63984. {
  63985. line += 2;
  63986. level += *line;
  63987. int corrected = abs (level);
  63988. if (corrected >> 8)
  63989. corrected = 255;
  63990. *line = corrected;
  63991. }
  63992. }
  63993. else
  63994. {
  63995. while (--num > 0)
  63996. {
  63997. line += 2;
  63998. level += *line;
  63999. int corrected = abs (level);
  64000. if (corrected >> 8)
  64001. {
  64002. corrected &= 511;
  64003. if (corrected >> 8)
  64004. corrected = 511 - corrected;
  64005. }
  64006. *line = corrected;
  64007. }
  64008. }
  64009. line[2] = 0; // force the last level to 0, just in case something went wrong in creating the table
  64010. }
  64011. }
  64012. void EdgeTable::remapTableForNumEdges (const int newNumEdgesPerLine) throw()
  64013. {
  64014. if (newNumEdgesPerLine != maxEdgesPerLine)
  64015. {
  64016. maxEdgesPerLine = newNumEdgesPerLine;
  64017. jassert (bounds.getHeight() > 0);
  64018. const int newLineStrideElements = maxEdgesPerLine * 2 + 1;
  64019. HeapBlock <int> newTable (bounds.getHeight() * newLineStrideElements);
  64020. copyEdgeTableData (newTable, newLineStrideElements, table, lineStrideElements, bounds.getHeight());
  64021. table.swapWith (newTable);
  64022. lineStrideElements = newLineStrideElements;
  64023. }
  64024. }
  64025. void EdgeTable::optimiseTable() throw()
  64026. {
  64027. int maxLineElements = 0;
  64028. for (int i = bounds.getHeight(); --i >= 0;)
  64029. maxLineElements = jmax (maxLineElements, table [i * lineStrideElements]);
  64030. remapTableForNumEdges (maxLineElements);
  64031. }
  64032. void EdgeTable::addEdgePoint (const int x, const int y, const int winding) throw()
  64033. {
  64034. jassert (y >= 0 && y < bounds.getHeight());
  64035. int* line = table + lineStrideElements * y;
  64036. const int numPoints = line[0];
  64037. int n = numPoints << 1;
  64038. if (n > 0)
  64039. {
  64040. while (n > 0)
  64041. {
  64042. const int cx = line [n - 1];
  64043. if (cx <= x)
  64044. {
  64045. if (cx == x)
  64046. {
  64047. line [n] += winding;
  64048. return;
  64049. }
  64050. break;
  64051. }
  64052. n -= 2;
  64053. }
  64054. if (numPoints >= maxEdgesPerLine)
  64055. {
  64056. remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine);
  64057. jassert (numPoints < maxEdgesPerLine);
  64058. line = table + lineStrideElements * y;
  64059. }
  64060. memmove (line + (n + 3), line + (n + 1), sizeof (int) * ((numPoints << 1) - n));
  64061. }
  64062. line [n + 1] = x;
  64063. line [n + 2] = winding;
  64064. line[0]++;
  64065. }
  64066. void EdgeTable::translate (float dx, int dy) throw()
  64067. {
  64068. bounds.setPosition (bounds.getX() + (int) floorf (dx), bounds.getY() + dy);
  64069. int* lineStart = table;
  64070. const int intDx = (int) (dx * 256.0f);
  64071. for (int i = bounds.getHeight(); --i >= 0;)
  64072. {
  64073. int* line = lineStart;
  64074. lineStart += lineStrideElements;
  64075. int num = *line++;
  64076. while (--num >= 0)
  64077. {
  64078. *line += intDx;
  64079. line += 2;
  64080. }
  64081. }
  64082. }
  64083. void EdgeTable::intersectWithEdgeTableLine (const int y, const int* otherLine) throw()
  64084. {
  64085. jassert (y >= 0 && y < bounds.getHeight());
  64086. int* dest = table + lineStrideElements * y;
  64087. if (dest[0] == 0)
  64088. return;
  64089. int otherNumPoints = *otherLine;
  64090. if (otherNumPoints == 0)
  64091. {
  64092. *dest = 0;
  64093. return;
  64094. }
  64095. const int right = bounds.getRight() << 8;
  64096. // optimise for the common case where our line lies entirely within a
  64097. // single pair of points, as happens when clipping to a simple rect.
  64098. if (otherNumPoints == 2 && otherLine[2] >= 255)
  64099. {
  64100. clipEdgeTableLineToRange (dest, otherLine[1], jmin (right, otherLine[3]));
  64101. return;
  64102. }
  64103. ++otherLine;
  64104. const size_t lineSizeBytes = (dest[0] * 2 + 1) * sizeof (int);
  64105. int* temp = (int*) alloca (lineSizeBytes);
  64106. memcpy (temp, dest, lineSizeBytes);
  64107. const int* src1 = temp;
  64108. int srcNum1 = *src1++;
  64109. int x1 = *src1++;
  64110. const int* src2 = otherLine;
  64111. int srcNum2 = otherNumPoints;
  64112. int x2 = *src2++;
  64113. int destIndex = 0, destTotal = 0;
  64114. int level1 = 0, level2 = 0;
  64115. int lastX = std::numeric_limits<int>::min(), lastLevel = 0;
  64116. while (srcNum1 > 0 && srcNum2 > 0)
  64117. {
  64118. int nextX;
  64119. if (x1 < x2)
  64120. {
  64121. nextX = x1;
  64122. level1 = *src1++;
  64123. x1 = *src1++;
  64124. --srcNum1;
  64125. }
  64126. else if (x1 == x2)
  64127. {
  64128. nextX = x1;
  64129. level1 = *src1++;
  64130. level2 = *src2++;
  64131. x1 = *src1++;
  64132. x2 = *src2++;
  64133. --srcNum1;
  64134. --srcNum2;
  64135. }
  64136. else
  64137. {
  64138. nextX = x2;
  64139. level2 = *src2++;
  64140. x2 = *src2++;
  64141. --srcNum2;
  64142. }
  64143. if (nextX > lastX)
  64144. {
  64145. if (nextX >= right)
  64146. break;
  64147. lastX = nextX;
  64148. const int nextLevel = (level1 * (level2 + 1)) >> 8;
  64149. jassert (((unsigned int) nextLevel) < (unsigned int) 256);
  64150. if (nextLevel != lastLevel)
  64151. {
  64152. if (destTotal >= maxEdgesPerLine)
  64153. {
  64154. dest[0] = destTotal;
  64155. remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine);
  64156. dest = table + lineStrideElements * y;
  64157. }
  64158. ++destTotal;
  64159. lastLevel = nextLevel;
  64160. dest[++destIndex] = nextX;
  64161. dest[++destIndex] = nextLevel;
  64162. }
  64163. }
  64164. }
  64165. if (lastLevel > 0)
  64166. {
  64167. if (destTotal >= maxEdgesPerLine)
  64168. {
  64169. dest[0] = destTotal;
  64170. remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine);
  64171. dest = table + lineStrideElements * y;
  64172. }
  64173. ++destTotal;
  64174. dest[++destIndex] = right;
  64175. dest[++destIndex] = 0;
  64176. }
  64177. dest[0] = destTotal;
  64178. #if JUCE_DEBUG
  64179. int last = std::numeric_limits<int>::min();
  64180. for (int i = 0; i < dest[0]; ++i)
  64181. {
  64182. jassert (dest[i * 2 + 1] > last);
  64183. last = dest[i * 2 + 1];
  64184. }
  64185. jassert (dest [dest[0] * 2] == 0);
  64186. #endif
  64187. }
  64188. void EdgeTable::clipEdgeTableLineToRange (int* dest, const int x1, const int x2) throw()
  64189. {
  64190. int* lastItem = dest + (dest[0] * 2 - 1);
  64191. if (x2 < lastItem[0])
  64192. {
  64193. if (x2 <= dest[1])
  64194. {
  64195. dest[0] = 0;
  64196. return;
  64197. }
  64198. while (x2 < lastItem[-2])
  64199. {
  64200. --(dest[0]);
  64201. lastItem -= 2;
  64202. }
  64203. lastItem[0] = x2;
  64204. lastItem[1] = 0;
  64205. }
  64206. if (x1 > dest[1])
  64207. {
  64208. while (lastItem[0] > x1)
  64209. lastItem -= 2;
  64210. const int itemsRemoved = (int) (lastItem - (dest + 1)) / 2;
  64211. if (itemsRemoved > 0)
  64212. {
  64213. dest[0] -= itemsRemoved;
  64214. memmove (dest + 1, lastItem, dest[0] * (sizeof (int) * 2));
  64215. }
  64216. dest[1] = x1;
  64217. }
  64218. }
  64219. void EdgeTable::clipToRectangle (const Rectangle<int>& r) throw()
  64220. {
  64221. const Rectangle<int> clipped (r.getIntersection (bounds));
  64222. if (clipped.isEmpty())
  64223. {
  64224. needToCheckEmptinesss = false;
  64225. bounds.setHeight (0);
  64226. }
  64227. else
  64228. {
  64229. const int top = clipped.getY() - bounds.getY();
  64230. const int bottom = clipped.getBottom() - bounds.getY();
  64231. if (bottom < bounds.getHeight())
  64232. bounds.setHeight (bottom);
  64233. if (clipped.getRight() < bounds.getRight())
  64234. bounds.setRight (clipped.getRight());
  64235. for (int i = top; --i >= 0;)
  64236. table [lineStrideElements * i] = 0;
  64237. if (clipped.getX() > bounds.getX())
  64238. {
  64239. const int x1 = clipped.getX() << 8;
  64240. const int x2 = jmin (bounds.getRight(), clipped.getRight()) << 8;
  64241. int* line = table + lineStrideElements * top;
  64242. for (int i = bottom - top; --i >= 0;)
  64243. {
  64244. if (line[0] != 0)
  64245. clipEdgeTableLineToRange (line, x1, x2);
  64246. line += lineStrideElements;
  64247. }
  64248. }
  64249. needToCheckEmptinesss = true;
  64250. }
  64251. }
  64252. void EdgeTable::excludeRectangle (const Rectangle<int>& r) throw()
  64253. {
  64254. const Rectangle<int> clipped (r.getIntersection (bounds));
  64255. if (! clipped.isEmpty())
  64256. {
  64257. const int top = clipped.getY() - bounds.getY();
  64258. const int bottom = clipped.getBottom() - bounds.getY();
  64259. //XXX optimise here by shortening the table if it fills top or bottom
  64260. const int rectLine[] = { 4, std::numeric_limits<int>::min(), 255,
  64261. clipped.getX() << 8, 0,
  64262. clipped.getRight() << 8, 255,
  64263. std::numeric_limits<int>::max(), 0 };
  64264. for (int i = top; i < bottom; ++i)
  64265. intersectWithEdgeTableLine (i, rectLine);
  64266. needToCheckEmptinesss = true;
  64267. }
  64268. }
  64269. void EdgeTable::clipToEdgeTable (const EdgeTable& other)
  64270. {
  64271. const Rectangle<int> clipped (other.bounds.getIntersection (bounds));
  64272. if (clipped.isEmpty())
  64273. {
  64274. needToCheckEmptinesss = false;
  64275. bounds.setHeight (0);
  64276. }
  64277. else
  64278. {
  64279. const int top = clipped.getY() - bounds.getY();
  64280. const int bottom = clipped.getBottom() - bounds.getY();
  64281. if (bottom < bounds.getHeight())
  64282. bounds.setHeight (bottom);
  64283. if (clipped.getRight() < bounds.getRight())
  64284. bounds.setRight (clipped.getRight());
  64285. int i = 0;
  64286. for (i = top; --i >= 0;)
  64287. table [lineStrideElements * i] = 0;
  64288. const int* otherLine = other.table + other.lineStrideElements * (clipped.getY() - other.bounds.getY());
  64289. for (i = top; i < bottom; ++i)
  64290. {
  64291. intersectWithEdgeTableLine (i, otherLine);
  64292. otherLine += other.lineStrideElements;
  64293. }
  64294. needToCheckEmptinesss = true;
  64295. }
  64296. }
  64297. void EdgeTable::clipLineToMask (int x, int y, const uint8* mask, int maskStride, int numPixels) throw()
  64298. {
  64299. y -= bounds.getY();
  64300. if (y < 0 || y >= bounds.getHeight())
  64301. return;
  64302. needToCheckEmptinesss = true;
  64303. if (numPixels <= 0)
  64304. {
  64305. table [lineStrideElements * y] = 0;
  64306. return;
  64307. }
  64308. int* tempLine = (int*) alloca ((numPixels * 2 + 4) * sizeof (int));
  64309. int destIndex = 0, lastLevel = 0;
  64310. while (--numPixels >= 0)
  64311. {
  64312. const int alpha = *mask;
  64313. mask += maskStride;
  64314. if (alpha != lastLevel)
  64315. {
  64316. tempLine[++destIndex] = (x << 8);
  64317. tempLine[++destIndex] = alpha;
  64318. lastLevel = alpha;
  64319. }
  64320. ++x;
  64321. }
  64322. if (lastLevel > 0)
  64323. {
  64324. tempLine[++destIndex] = (x << 8);
  64325. tempLine[++destIndex] = 0;
  64326. }
  64327. tempLine[0] = destIndex >> 1;
  64328. intersectWithEdgeTableLine (y, tempLine);
  64329. }
  64330. bool EdgeTable::isEmpty() throw()
  64331. {
  64332. if (needToCheckEmptinesss)
  64333. {
  64334. needToCheckEmptinesss = false;
  64335. int* t = table;
  64336. for (int i = bounds.getHeight(); --i >= 0;)
  64337. {
  64338. if (t[0] > 1)
  64339. return false;
  64340. t += lineStrideElements;
  64341. }
  64342. bounds.setHeight (0);
  64343. }
  64344. return bounds.getHeight() == 0;
  64345. }
  64346. END_JUCE_NAMESPACE
  64347. /*** End of inlined file: juce_EdgeTable.cpp ***/
  64348. /*** Start of inlined file: juce_FillType.cpp ***/
  64349. BEGIN_JUCE_NAMESPACE
  64350. FillType::FillType() throw()
  64351. : colour (0xff000000), image (0)
  64352. {
  64353. }
  64354. FillType::FillType (const Colour& colour_) throw()
  64355. : colour (colour_), image (0)
  64356. {
  64357. }
  64358. FillType::FillType (const ColourGradient& gradient_) throw()
  64359. : colour (0xff000000), gradient (new ColourGradient (gradient_)), image (0)
  64360. {
  64361. }
  64362. FillType::FillType (const Image& image_, const AffineTransform& transform_) throw()
  64363. : colour (0xff000000), image (&image_), transform (transform_)
  64364. {
  64365. }
  64366. FillType::FillType (const FillType& other) throw()
  64367. : colour (other.colour),
  64368. gradient (other.gradient != 0 ? new ColourGradient (*other.gradient) : 0),
  64369. image (other.image), transform (other.transform)
  64370. {
  64371. }
  64372. FillType& FillType::operator= (const FillType& other) throw()
  64373. {
  64374. if (this != &other)
  64375. {
  64376. colour = other.colour;
  64377. gradient = (other.gradient != 0 ? new ColourGradient (*other.gradient) : 0);
  64378. image = other.image;
  64379. transform = other.transform;
  64380. }
  64381. return *this;
  64382. }
  64383. FillType::~FillType() throw()
  64384. {
  64385. }
  64386. void FillType::setColour (const Colour& newColour) throw()
  64387. {
  64388. gradient = 0;
  64389. image = 0;
  64390. colour = newColour;
  64391. }
  64392. void FillType::setGradient (const ColourGradient& newGradient) throw()
  64393. {
  64394. if (gradient != 0)
  64395. {
  64396. *gradient = newGradient;
  64397. }
  64398. else
  64399. {
  64400. image = 0;
  64401. gradient = new ColourGradient (newGradient);
  64402. colour = Colours::black;
  64403. }
  64404. }
  64405. void FillType::setTiledImage (const Image& image_, const AffineTransform& transform_) throw()
  64406. {
  64407. gradient = 0;
  64408. image = &image_;
  64409. transform = transform_;
  64410. colour = Colours::black;
  64411. }
  64412. void FillType::setOpacity (const float newOpacity) throw()
  64413. {
  64414. colour = colour.withAlpha (newOpacity);
  64415. }
  64416. END_JUCE_NAMESPACE
  64417. /*** End of inlined file: juce_FillType.cpp ***/
  64418. /*** Start of inlined file: juce_Graphics.cpp ***/
  64419. BEGIN_JUCE_NAMESPACE
  64420. static const Graphics::ResamplingQuality defaultQuality = Graphics::mediumResamplingQuality;
  64421. template <typename Type>
  64422. static bool areCoordsSensibleNumbers (Type x, Type y, Type w, Type h)
  64423. {
  64424. const int maxVal = 0x3fffffff;
  64425. return (int) x >= -maxVal && (int) x <= maxVal
  64426. && (int) y >= -maxVal && (int) y <= maxVal
  64427. && (int) w >= -maxVal && (int) w <= maxVal
  64428. && (int) h >= -maxVal && (int) h <= maxVal;
  64429. }
  64430. LowLevelGraphicsContext::LowLevelGraphicsContext()
  64431. {
  64432. }
  64433. LowLevelGraphicsContext::~LowLevelGraphicsContext()
  64434. {
  64435. }
  64436. Graphics::Graphics (Image& imageToDrawOnto) throw()
  64437. : context (imageToDrawOnto.createLowLevelContext()),
  64438. contextToDelete (context),
  64439. saveStatePending (false)
  64440. {
  64441. }
  64442. Graphics::Graphics (LowLevelGraphicsContext* const internalContext) throw()
  64443. : context (internalContext),
  64444. saveStatePending (false)
  64445. {
  64446. }
  64447. Graphics::~Graphics() throw()
  64448. {
  64449. }
  64450. void Graphics::resetToDefaultState() throw()
  64451. {
  64452. saveStateIfPending();
  64453. context->setFill (FillType());
  64454. context->setFont (Font());
  64455. context->setInterpolationQuality (defaultQuality);
  64456. }
  64457. bool Graphics::isVectorDevice() const throw()
  64458. {
  64459. return context->isVectorDevice();
  64460. }
  64461. bool Graphics::reduceClipRegion (const int x, const int y,
  64462. const int w, const int h) throw()
  64463. {
  64464. saveStateIfPending();
  64465. return context->clipToRectangle (Rectangle<int> (x, y, w, h));
  64466. }
  64467. bool Graphics::reduceClipRegion (const RectangleList& clipRegion) throw()
  64468. {
  64469. saveStateIfPending();
  64470. return context->clipToRectangleList (clipRegion);
  64471. }
  64472. bool Graphics::reduceClipRegion (const Path& path, const AffineTransform& transform) throw()
  64473. {
  64474. saveStateIfPending();
  64475. context->clipToPath (path, transform);
  64476. return ! context->isClipEmpty();
  64477. }
  64478. bool Graphics::reduceClipRegion (const Image& image, const Rectangle<int>& sourceClipRegion, const AffineTransform& transform) throw()
  64479. {
  64480. saveStateIfPending();
  64481. context->clipToImageAlpha (image, sourceClipRegion, transform);
  64482. return ! context->isClipEmpty();
  64483. }
  64484. void Graphics::excludeClipRegion (const Rectangle<int>& rectangleToExclude) throw()
  64485. {
  64486. saveStateIfPending();
  64487. context->excludeClipRectangle (rectangleToExclude);
  64488. }
  64489. bool Graphics::isClipEmpty() const throw()
  64490. {
  64491. return context->isClipEmpty();
  64492. }
  64493. const Rectangle<int> Graphics::getClipBounds() const throw()
  64494. {
  64495. return context->getClipBounds();
  64496. }
  64497. void Graphics::saveState() throw()
  64498. {
  64499. saveStateIfPending();
  64500. saveStatePending = true;
  64501. }
  64502. void Graphics::restoreState() throw()
  64503. {
  64504. if (saveStatePending)
  64505. saveStatePending = false;
  64506. else
  64507. context->restoreState();
  64508. }
  64509. void Graphics::saveStateIfPending() throw()
  64510. {
  64511. if (saveStatePending)
  64512. {
  64513. saveStatePending = false;
  64514. context->saveState();
  64515. }
  64516. }
  64517. void Graphics::setOrigin (const int newOriginX,
  64518. const int newOriginY) throw()
  64519. {
  64520. saveStateIfPending();
  64521. context->setOrigin (newOriginX, newOriginY);
  64522. }
  64523. bool Graphics::clipRegionIntersects (const int x, const int y,
  64524. const int w, const int h) const throw()
  64525. {
  64526. return context->clipRegionIntersects (Rectangle<int> (x, y, w, h));
  64527. }
  64528. void Graphics::setColour (const Colour& newColour) throw()
  64529. {
  64530. saveStateIfPending();
  64531. context->setFill (FillType (newColour));
  64532. }
  64533. void Graphics::setOpacity (const float newOpacity) throw()
  64534. {
  64535. saveStateIfPending();
  64536. context->setOpacity (newOpacity);
  64537. }
  64538. void Graphics::setGradientFill (const ColourGradient& gradient) throw()
  64539. {
  64540. saveStateIfPending();
  64541. context->setFill (FillType (gradient));
  64542. }
  64543. void Graphics::setTiledImageFill (const Image& imageToUse,
  64544. const int anchorX,
  64545. const int anchorY,
  64546. const float opacity) throw()
  64547. {
  64548. saveStateIfPending();
  64549. context->setFill (FillType (imageToUse, AffineTransform::translation ((float) anchorX, (float) anchorY)));
  64550. context->setOpacity (opacity);
  64551. }
  64552. void Graphics::setFillType (const FillType& newFill) throw()
  64553. {
  64554. saveStateIfPending();
  64555. context->setFill (newFill);
  64556. }
  64557. void Graphics::setFont (const Font& newFont) throw()
  64558. {
  64559. saveStateIfPending();
  64560. context->setFont (newFont);
  64561. }
  64562. void Graphics::setFont (const float newFontHeight,
  64563. const int newFontStyleFlags) throw()
  64564. {
  64565. saveStateIfPending();
  64566. Font f (context->getFont());
  64567. f.setSizeAndStyle (newFontHeight, newFontStyleFlags, 1.0f, 0);
  64568. context->setFont (f);
  64569. }
  64570. void Graphics::drawSingleLineText (const String& text,
  64571. const int startX,
  64572. const int baselineY) const throw()
  64573. {
  64574. if (text.isNotEmpty()
  64575. && startX < context->getClipBounds().getRight())
  64576. {
  64577. GlyphArrangement arr;
  64578. arr.addLineOfText (context->getFont(), text, (float) startX, (float) baselineY);
  64579. arr.draw (*this);
  64580. }
  64581. }
  64582. void Graphics::drawTextAsPath (const String& text,
  64583. const AffineTransform& transform) const throw()
  64584. {
  64585. if (text.isNotEmpty())
  64586. {
  64587. GlyphArrangement arr;
  64588. arr.addLineOfText (context->getFont(), text, 0.0f, 0.0f);
  64589. arr.draw (*this, transform);
  64590. }
  64591. }
  64592. void Graphics::drawMultiLineText (const String& text,
  64593. const int startX,
  64594. const int baselineY,
  64595. const int maximumLineWidth) const throw()
  64596. {
  64597. if (text.isNotEmpty()
  64598. && startX < context->getClipBounds().getRight())
  64599. {
  64600. GlyphArrangement arr;
  64601. arr.addJustifiedText (context->getFont(), text,
  64602. (float) startX, (float) baselineY, (float) maximumLineWidth,
  64603. Justification::left);
  64604. arr.draw (*this);
  64605. }
  64606. }
  64607. void Graphics::drawText (const String& text,
  64608. const int x,
  64609. const int y,
  64610. const int width,
  64611. const int height,
  64612. const Justification& justificationType,
  64613. const bool useEllipsesIfTooBig) const throw()
  64614. {
  64615. if (text.isNotEmpty() && context->clipRegionIntersects (Rectangle<int> (x, y, width, height)))
  64616. {
  64617. GlyphArrangement arr;
  64618. arr.addCurtailedLineOfText (context->getFont(), text,
  64619. 0.0f, 0.0f, (float)width,
  64620. useEllipsesIfTooBig);
  64621. arr.justifyGlyphs (0, arr.getNumGlyphs(),
  64622. (float) x, (float) y,
  64623. (float) width, (float) height,
  64624. justificationType);
  64625. arr.draw (*this);
  64626. }
  64627. }
  64628. void Graphics::drawFittedText (const String& text,
  64629. const int x,
  64630. const int y,
  64631. const int width,
  64632. const int height,
  64633. const Justification& justification,
  64634. const int maximumNumberOfLines,
  64635. const float minimumHorizontalScale) const throw()
  64636. {
  64637. if (text.isNotEmpty()
  64638. && width > 0 && height > 0
  64639. && context->clipRegionIntersects (Rectangle<int> (x, y, width, height)))
  64640. {
  64641. GlyphArrangement arr;
  64642. arr.addFittedText (context->getFont(), text,
  64643. (float) x, (float) y,
  64644. (float) width, (float) height,
  64645. justification,
  64646. maximumNumberOfLines,
  64647. minimumHorizontalScale);
  64648. arr.draw (*this);
  64649. }
  64650. }
  64651. void Graphics::fillRect (int x,
  64652. int y,
  64653. int width,
  64654. int height) const throw()
  64655. {
  64656. // passing in a silly number can cause maths problems in rendering!
  64657. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64658. context->fillRect (Rectangle<int> (x, y, width, height), false);
  64659. }
  64660. void Graphics::fillRect (const Rectangle<int>& r) const throw()
  64661. {
  64662. context->fillRect (r, false);
  64663. }
  64664. void Graphics::fillRect (const float x,
  64665. const float y,
  64666. const float width,
  64667. const float height) const throw()
  64668. {
  64669. // passing in a silly number can cause maths problems in rendering!
  64670. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64671. Path p;
  64672. p.addRectangle (x, y, width, height);
  64673. fillPath (p);
  64674. }
  64675. void Graphics::setPixel (int x, int y) const throw()
  64676. {
  64677. context->fillRect (Rectangle<int> (x, y, 1, 1), false);
  64678. }
  64679. void Graphics::fillAll() const throw()
  64680. {
  64681. fillRect (context->getClipBounds());
  64682. }
  64683. void Graphics::fillAll (const Colour& colourToUse) const throw()
  64684. {
  64685. if (! colourToUse.isTransparent())
  64686. {
  64687. const Rectangle<int> clip (context->getClipBounds());
  64688. context->saveState();
  64689. context->setFill (FillType (colourToUse));
  64690. context->fillRect (clip, false);
  64691. context->restoreState();
  64692. }
  64693. }
  64694. void Graphics::fillPath (const Path& path,
  64695. const AffineTransform& transform) const throw()
  64696. {
  64697. if ((! context->isClipEmpty()) && ! path.isEmpty())
  64698. context->fillPath (path, transform);
  64699. }
  64700. void Graphics::strokePath (const Path& path,
  64701. const PathStrokeType& strokeType,
  64702. const AffineTransform& transform) const throw()
  64703. {
  64704. Path stroke;
  64705. strokeType.createStrokedPath (stroke, path, transform);
  64706. fillPath (stroke);
  64707. }
  64708. void Graphics::drawRect (const int x,
  64709. const int y,
  64710. const int width,
  64711. const int height,
  64712. const int lineThickness) const throw()
  64713. {
  64714. // passing in a silly number can cause maths problems in rendering!
  64715. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64716. context->fillRect (Rectangle<int> (x, y, width, lineThickness), false);
  64717. context->fillRect (Rectangle<int> (x, y + lineThickness, lineThickness, height - lineThickness * 2), false);
  64718. context->fillRect (Rectangle<int> (x + width - lineThickness, y + lineThickness, lineThickness, height - lineThickness * 2), false);
  64719. context->fillRect (Rectangle<int> (x, y + height - lineThickness, width, lineThickness), false);
  64720. }
  64721. void Graphics::drawRect (const float x,
  64722. const float y,
  64723. const float width,
  64724. const float height,
  64725. const float lineThickness) const throw()
  64726. {
  64727. // passing in a silly number can cause maths problems in rendering!
  64728. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64729. Path p;
  64730. p.addRectangle (x, y, width, lineThickness);
  64731. p.addRectangle (x, y + lineThickness, lineThickness, height - lineThickness * 2.0f);
  64732. p.addRectangle (x + width - lineThickness, y + lineThickness, lineThickness, height - lineThickness * 2.0f);
  64733. p.addRectangle (x, y + height - lineThickness, width, lineThickness);
  64734. fillPath (p);
  64735. }
  64736. void Graphics::drawRect (const Rectangle<int>& r,
  64737. const int lineThickness) const throw()
  64738. {
  64739. drawRect (r.getX(), r.getY(),
  64740. r.getWidth(), r.getHeight(),
  64741. lineThickness);
  64742. }
  64743. void Graphics::drawBevel (const int x,
  64744. const int y,
  64745. const int width,
  64746. const int height,
  64747. const int bevelThickness,
  64748. const Colour& topLeftColour,
  64749. const Colour& bottomRightColour,
  64750. const bool useGradient,
  64751. const bool sharpEdgeOnOutside) const throw()
  64752. {
  64753. // passing in a silly number can cause maths problems in rendering!
  64754. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64755. if (clipRegionIntersects (x, y, width, height))
  64756. {
  64757. context->saveState();
  64758. const float oldOpacity = 1.0f;//xxx state->colour.getFloatAlpha();
  64759. const float ramp = oldOpacity / bevelThickness;
  64760. for (int i = bevelThickness; --i >= 0;)
  64761. {
  64762. const float op = useGradient ? ramp * (sharpEdgeOnOutside ? bevelThickness - i : i)
  64763. : oldOpacity;
  64764. context->setFill (FillType (topLeftColour.withMultipliedAlpha (op)));
  64765. context->fillRect (Rectangle<int> (x + i, y + i, width - i * 2, 1), false);
  64766. context->setFill (FillType (topLeftColour.withMultipliedAlpha (op * 0.75f)));
  64767. context->fillRect (Rectangle<int> (x + i, y + i + 1, 1, height - i * 2 - 2), false);
  64768. context->setFill (FillType (bottomRightColour.withMultipliedAlpha (op)));
  64769. context->fillRect (Rectangle<int> (x + i, y + height - i - 1, width - i * 2, 1), false);
  64770. context->setFill (FillType (bottomRightColour.withMultipliedAlpha (op * 0.75f)));
  64771. context->fillRect (Rectangle<int> (x + width - i - 1, y + i + 1, 1, height - i * 2 - 2), false);
  64772. }
  64773. context->restoreState();
  64774. }
  64775. }
  64776. void Graphics::fillEllipse (const float x,
  64777. const float y,
  64778. const float width,
  64779. const float height) const throw()
  64780. {
  64781. // passing in a silly number can cause maths problems in rendering!
  64782. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64783. Path p;
  64784. p.addEllipse (x, y, width, height);
  64785. fillPath (p);
  64786. }
  64787. void Graphics::drawEllipse (const float x,
  64788. const float y,
  64789. const float width,
  64790. const float height,
  64791. const float lineThickness) const throw()
  64792. {
  64793. // passing in a silly number can cause maths problems in rendering!
  64794. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64795. Path p;
  64796. p.addEllipse (x, y, width, height);
  64797. strokePath (p, PathStrokeType (lineThickness));
  64798. }
  64799. void Graphics::fillRoundedRectangle (const float x,
  64800. const float y,
  64801. const float width,
  64802. const float height,
  64803. const float cornerSize) const throw()
  64804. {
  64805. // passing in a silly number can cause maths problems in rendering!
  64806. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64807. Path p;
  64808. p.addRoundedRectangle (x, y, width, height, cornerSize);
  64809. fillPath (p);
  64810. }
  64811. void Graphics::fillRoundedRectangle (const Rectangle<int>& r,
  64812. const float cornerSize) const throw()
  64813. {
  64814. fillRoundedRectangle ((float) r.getX(),
  64815. (float) r.getY(),
  64816. (float) r.getWidth(),
  64817. (float) r.getHeight(),
  64818. cornerSize);
  64819. }
  64820. void Graphics::drawRoundedRectangle (const float x,
  64821. const float y,
  64822. const float width,
  64823. const float height,
  64824. const float cornerSize,
  64825. const float lineThickness) const throw()
  64826. {
  64827. // passing in a silly number can cause maths problems in rendering!
  64828. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64829. Path p;
  64830. p.addRoundedRectangle (x, y, width, height, cornerSize);
  64831. strokePath (p, PathStrokeType (lineThickness));
  64832. }
  64833. void Graphics::drawRoundedRectangle (const Rectangle<int>& r,
  64834. const float cornerSize,
  64835. const float lineThickness) const throw()
  64836. {
  64837. drawRoundedRectangle ((float) r.getX(),
  64838. (float) r.getY(),
  64839. (float) r.getWidth(),
  64840. (float) r.getHeight(),
  64841. cornerSize, lineThickness);
  64842. }
  64843. void Graphics::drawArrow (const float startX,
  64844. const float startY,
  64845. const float endX,
  64846. const float endY,
  64847. const float lineThickness,
  64848. const float arrowheadWidth,
  64849. const float arrowheadLength) const throw()
  64850. {
  64851. Path p;
  64852. p.addArrow (startX, startY, endX, endY,
  64853. lineThickness, arrowheadWidth, arrowheadLength);
  64854. fillPath (p);
  64855. }
  64856. void Graphics::fillCheckerBoard (int x, int y,
  64857. int width, int height,
  64858. const int checkWidth,
  64859. const int checkHeight,
  64860. const Colour& colour1,
  64861. const Colour& colour2) const throw()
  64862. {
  64863. jassert (checkWidth > 0 && checkHeight > 0); // can't be zero or less!
  64864. if (checkWidth > 0 && checkHeight > 0)
  64865. {
  64866. context->saveState();
  64867. if (colour1 == colour2)
  64868. {
  64869. context->setFill (FillType (colour1));
  64870. context->fillRect (Rectangle<int> (x, y, width, height), false);
  64871. }
  64872. else
  64873. {
  64874. const Rectangle<int> clip (context->getClipBounds());
  64875. const int right = jmin (x + width, clip.getRight());
  64876. const int bottom = jmin (y + height, clip.getBottom());
  64877. int cy = 0;
  64878. while (y < bottom)
  64879. {
  64880. int cx = cy;
  64881. for (int xx = x; xx < right; xx += checkWidth)
  64882. {
  64883. context->setFill (FillType (((cx++ & 1) == 0) ? colour1 : colour2));
  64884. context->fillRect (Rectangle<int> (xx, y, jmin (checkWidth, right - xx), jmin (checkHeight, bottom - y)),
  64885. false);
  64886. }
  64887. ++cy;
  64888. y += checkHeight;
  64889. }
  64890. }
  64891. context->restoreState();
  64892. }
  64893. }
  64894. void Graphics::drawVerticalLine (const int x, float top, float bottom) const throw()
  64895. {
  64896. context->drawVerticalLine (x, top, bottom);
  64897. }
  64898. void Graphics::drawHorizontalLine (const int y, float left, float right) const throw()
  64899. {
  64900. context->drawHorizontalLine (y, left, right);
  64901. }
  64902. void Graphics::drawLine (float x1, float y1, float x2, float y2) const throw()
  64903. {
  64904. context->drawLine (x1, y1, x2, y2);
  64905. }
  64906. void Graphics::drawLine (const float startX,
  64907. const float startY,
  64908. const float endX,
  64909. const float endY,
  64910. const float lineThickness) const throw()
  64911. {
  64912. Path p;
  64913. p.addLineSegment (startX, startY, endX, endY, lineThickness);
  64914. fillPath (p);
  64915. }
  64916. void Graphics::drawLine (const Line& line) const throw()
  64917. {
  64918. drawLine (line.getStartX(), line.getStartY(), line.getEndX(), line.getEndY());
  64919. }
  64920. void Graphics::drawLine (const Line& line,
  64921. const float lineThickness) const throw()
  64922. {
  64923. drawLine (line.getStartX(), line.getStartY(), line.getEndX(), line.getEndY(), lineThickness);
  64924. }
  64925. void Graphics::drawDashedLine (const float startX,
  64926. const float startY,
  64927. const float endX,
  64928. const float endY,
  64929. const float* const dashLengths,
  64930. const int numDashLengths,
  64931. const float lineThickness) const throw()
  64932. {
  64933. const double dx = endX - startX;
  64934. const double dy = endY - startY;
  64935. const double totalLen = juce_hypot (dx, dy);
  64936. if (totalLen >= 0.5)
  64937. {
  64938. const double onePixAlpha = 1.0 / totalLen;
  64939. double alpha = 0.0;
  64940. float x = startX;
  64941. float y = startY;
  64942. int n = 0;
  64943. while (alpha < 1.0f)
  64944. {
  64945. alpha = jmin (1.0, alpha + dashLengths[n++] * onePixAlpha);
  64946. n = n % numDashLengths;
  64947. const float oldX = x;
  64948. const float oldY = y;
  64949. x = (float) (startX + dx * alpha);
  64950. y = (float) (startY + dy * alpha);
  64951. if ((n & 1) != 0)
  64952. {
  64953. if (lineThickness != 1.0f)
  64954. drawLine (oldX, oldY, x, y, lineThickness);
  64955. else
  64956. drawLine (oldX, oldY, x, y);
  64957. }
  64958. }
  64959. }
  64960. }
  64961. void Graphics::setImageResamplingQuality (const Graphics::ResamplingQuality newQuality) throw()
  64962. {
  64963. saveStateIfPending();
  64964. context->setInterpolationQuality (newQuality);
  64965. }
  64966. void Graphics::drawImageAt (const Image* const imageToDraw,
  64967. const int topLeftX,
  64968. const int topLeftY,
  64969. const bool fillAlphaChannelWithCurrentBrush) const throw()
  64970. {
  64971. if (imageToDraw != 0)
  64972. {
  64973. const int imageW = imageToDraw->getWidth();
  64974. const int imageH = imageToDraw->getHeight();
  64975. drawImage (imageToDraw,
  64976. topLeftX, topLeftY, imageW, imageH,
  64977. 0, 0, imageW, imageH,
  64978. fillAlphaChannelWithCurrentBrush);
  64979. }
  64980. }
  64981. void Graphics::drawImageWithin (const Image* const imageToDraw,
  64982. const int destX,
  64983. const int destY,
  64984. const int destW,
  64985. const int destH,
  64986. const RectanglePlacement& placementWithinTarget,
  64987. const bool fillAlphaChannelWithCurrentBrush) const throw()
  64988. {
  64989. // passing in a silly number can cause maths problems in rendering!
  64990. jassert (areCoordsSensibleNumbers (destX, destY, destW, destH));
  64991. if (imageToDraw != 0)
  64992. {
  64993. const int imageW = imageToDraw->getWidth();
  64994. const int imageH = imageToDraw->getHeight();
  64995. if (imageW > 0 && imageH > 0)
  64996. {
  64997. double newX = 0.0, newY = 0.0;
  64998. double newW = imageW;
  64999. double newH = imageH;
  65000. placementWithinTarget.applyTo (newX, newY, newW, newH,
  65001. destX, destY, destW, destH);
  65002. if (newW > 0 && newH > 0)
  65003. {
  65004. drawImage (imageToDraw,
  65005. roundToInt (newX), roundToInt (newY),
  65006. roundToInt (newW), roundToInt (newH),
  65007. 0, 0, imageW, imageH,
  65008. fillAlphaChannelWithCurrentBrush);
  65009. }
  65010. }
  65011. }
  65012. }
  65013. void Graphics::drawImage (const Image* const imageToDraw,
  65014. int dx, int dy, int dw, int dh,
  65015. int sx, int sy, int sw, int sh,
  65016. const bool fillAlphaChannelWithCurrentBrush) const throw()
  65017. {
  65018. // passing in a silly number can cause maths problems in rendering!
  65019. jassert (areCoordsSensibleNumbers (dx, dy, dw, dh));
  65020. jassert (areCoordsSensibleNumbers (sx, sy, sw, sh));
  65021. if (context->clipRegionIntersects (Rectangle<int> (dx, dy, dw, dh)))
  65022. {
  65023. drawImageTransformed (imageToDraw, Rectangle<int> (sx, sy, sw, sh),
  65024. AffineTransform::scale (dw / (float) sw, dh / (float) sh)
  65025. .translated ((float) dx, (float) dy),
  65026. fillAlphaChannelWithCurrentBrush);
  65027. }
  65028. }
  65029. void Graphics::drawImageTransformed (const Image* const imageToDraw,
  65030. const Rectangle<int>& imageSubRegion,
  65031. const AffineTransform& transform,
  65032. const bool fillAlphaChannelWithCurrentBrush) const throw()
  65033. {
  65034. if (imageToDraw != 0 && ! context->isClipEmpty())
  65035. {
  65036. const Rectangle<int> srcClip (imageSubRegion.getIntersection (imageToDraw->getBounds()));
  65037. if (fillAlphaChannelWithCurrentBrush)
  65038. {
  65039. context->saveState();
  65040. context->clipToImageAlpha (*imageToDraw, srcClip, transform);
  65041. fillAll();
  65042. context->restoreState();
  65043. }
  65044. else
  65045. {
  65046. context->drawImage (*imageToDraw, srcClip, transform, false);
  65047. }
  65048. }
  65049. }
  65050. END_JUCE_NAMESPACE
  65051. /*** End of inlined file: juce_Graphics.cpp ***/
  65052. /*** Start of inlined file: juce_Justification.cpp ***/
  65053. BEGIN_JUCE_NAMESPACE
  65054. Justification::Justification (const Justification& other) throw()
  65055. : flags (other.flags)
  65056. {
  65057. }
  65058. Justification& Justification::operator= (const Justification& other) throw()
  65059. {
  65060. flags = other.flags;
  65061. return *this;
  65062. }
  65063. int Justification::getOnlyVerticalFlags() const throw()
  65064. {
  65065. return flags & (top | bottom | verticallyCentred);
  65066. }
  65067. int Justification::getOnlyHorizontalFlags() const throw()
  65068. {
  65069. return flags & (left | right | horizontallyCentred | horizontallyJustified);
  65070. }
  65071. void Justification::applyToRectangle (int& x, int& y,
  65072. const int w, const int h,
  65073. const int spaceX, const int spaceY,
  65074. const int spaceW, const int spaceH) const throw()
  65075. {
  65076. if ((flags & horizontallyCentred) != 0)
  65077. {
  65078. x = spaceX + ((spaceW - w) >> 1);
  65079. }
  65080. else if ((flags & right) != 0)
  65081. {
  65082. x = spaceX + spaceW - w;
  65083. }
  65084. else
  65085. {
  65086. x = spaceX;
  65087. }
  65088. if ((flags & verticallyCentred) != 0)
  65089. {
  65090. y = spaceY + ((spaceH - h) >> 1);
  65091. }
  65092. else if ((flags & bottom) != 0)
  65093. {
  65094. y = spaceY + spaceH - h;
  65095. }
  65096. else
  65097. {
  65098. y = spaceY;
  65099. }
  65100. }
  65101. END_JUCE_NAMESPACE
  65102. /*** End of inlined file: juce_Justification.cpp ***/
  65103. /*** Start of inlined file: juce_LowLevelGraphicsPostScriptRenderer.cpp ***/
  65104. BEGIN_JUCE_NAMESPACE
  65105. // this will throw an assertion if you try to draw something that's not
  65106. // possible in postscript
  65107. #define WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS 0
  65108. #if defined (JUCE_DEBUG) && WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS
  65109. #define notPossibleInPostscriptAssert jassertfalse
  65110. #else
  65111. #define notPossibleInPostscriptAssert
  65112. #endif
  65113. LowLevelGraphicsPostScriptRenderer::LowLevelGraphicsPostScriptRenderer (OutputStream& resultingPostScript,
  65114. const String& documentTitle,
  65115. const int totalWidth_,
  65116. const int totalHeight_)
  65117. : out (resultingPostScript),
  65118. totalWidth (totalWidth_),
  65119. totalHeight (totalHeight_),
  65120. needToClip (true)
  65121. {
  65122. stateStack.add (new SavedState());
  65123. stateStack.getLast()->clip = Rectangle<int> (0, 0, totalWidth_, totalHeight_);
  65124. const float scale = jmin ((520.0f / totalWidth_), (750.0f / totalHeight));
  65125. out << "%!PS-Adobe-3.0 EPSF-3.0"
  65126. "\n%%BoundingBox: 0 0 600 824"
  65127. "\n%%Pages: 0"
  65128. "\n%%Creator: Raw Material Software JUCE"
  65129. "\n%%Title: " << documentTitle <<
  65130. "\n%%CreationDate: none"
  65131. "\n%%LanguageLevel: 2"
  65132. "\n%%EndComments"
  65133. "\n%%BeginProlog"
  65134. "\n%%BeginResource: JRes"
  65135. "\n/bd {bind def} bind def"
  65136. "\n/c {setrgbcolor} bd"
  65137. "\n/m {moveto} bd"
  65138. "\n/l {lineto} bd"
  65139. "\n/rl {rlineto} bd"
  65140. "\n/ct {curveto} bd"
  65141. "\n/cp {closepath} bd"
  65142. "\n/pr {3 index 3 index moveto 1 index 0 rlineto 0 1 index rlineto pop neg 0 rlineto pop pop closepath} bd"
  65143. "\n/doclip {initclip newpath} bd"
  65144. "\n/endclip {clip newpath} bd"
  65145. "\n%%EndResource"
  65146. "\n%%EndProlog"
  65147. "\n%%BeginSetup"
  65148. "\n%%EndSetup"
  65149. "\n%%Page: 1 1"
  65150. "\n%%BeginPageSetup"
  65151. "\n%%EndPageSetup\n\n"
  65152. << "40 800 translate\n"
  65153. << scale << ' ' << scale << " scale\n\n";
  65154. }
  65155. LowLevelGraphicsPostScriptRenderer::~LowLevelGraphicsPostScriptRenderer()
  65156. {
  65157. }
  65158. bool LowLevelGraphicsPostScriptRenderer::isVectorDevice() const
  65159. {
  65160. return true;
  65161. }
  65162. void LowLevelGraphicsPostScriptRenderer::setOrigin (int x, int y)
  65163. {
  65164. if (x != 0 || y != 0)
  65165. {
  65166. stateStack.getLast()->xOffset += x;
  65167. stateStack.getLast()->yOffset += y;
  65168. needToClip = true;
  65169. }
  65170. }
  65171. bool LowLevelGraphicsPostScriptRenderer::clipToRectangle (const Rectangle<int>& r)
  65172. {
  65173. needToClip = true;
  65174. return stateStack.getLast()->clip.clipTo (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65175. }
  65176. bool LowLevelGraphicsPostScriptRenderer::clipToRectangleList (const RectangleList& clipRegion)
  65177. {
  65178. needToClip = true;
  65179. return stateStack.getLast()->clip.clipTo (clipRegion);
  65180. }
  65181. void LowLevelGraphicsPostScriptRenderer::excludeClipRectangle (const Rectangle<int>& r)
  65182. {
  65183. needToClip = true;
  65184. stateStack.getLast()->clip.subtract (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65185. }
  65186. void LowLevelGraphicsPostScriptRenderer::clipToPath (const Path& path, const AffineTransform& transform)
  65187. {
  65188. writeClip();
  65189. Path p (path);
  65190. p.applyTransform (transform.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset));
  65191. writePath (p);
  65192. out << "clip\n";
  65193. }
  65194. void LowLevelGraphicsPostScriptRenderer::clipToImageAlpha (const Image& /*sourceImage*/, const Rectangle<int>& /*srcClip*/, const AffineTransform& /*transform*/)
  65195. {
  65196. needToClip = true;
  65197. jassertfalse // xxx
  65198. }
  65199. bool LowLevelGraphicsPostScriptRenderer::clipRegionIntersects (const Rectangle<int>& r)
  65200. {
  65201. return stateStack.getLast()->clip.intersectsRectangle (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65202. }
  65203. const Rectangle<int> LowLevelGraphicsPostScriptRenderer::getClipBounds() const
  65204. {
  65205. return stateStack.getLast()->clip.getBounds().translated (-stateStack.getLast()->xOffset,
  65206. -stateStack.getLast()->yOffset);
  65207. }
  65208. bool LowLevelGraphicsPostScriptRenderer::isClipEmpty() const
  65209. {
  65210. return stateStack.getLast()->clip.isEmpty();
  65211. }
  65212. LowLevelGraphicsPostScriptRenderer::SavedState::SavedState()
  65213. : xOffset (0),
  65214. yOffset (0)
  65215. {
  65216. }
  65217. LowLevelGraphicsPostScriptRenderer::SavedState::~SavedState()
  65218. {
  65219. }
  65220. void LowLevelGraphicsPostScriptRenderer::saveState()
  65221. {
  65222. stateStack.add (new SavedState (*stateStack.getLast()));
  65223. }
  65224. void LowLevelGraphicsPostScriptRenderer::restoreState()
  65225. {
  65226. jassert (stateStack.size() > 0);
  65227. if (stateStack.size() > 0)
  65228. stateStack.removeLast();
  65229. }
  65230. void LowLevelGraphicsPostScriptRenderer::writeClip()
  65231. {
  65232. if (needToClip)
  65233. {
  65234. needToClip = false;
  65235. out << "doclip ";
  65236. int itemsOnLine = 0;
  65237. for (RectangleList::Iterator i (stateStack.getLast()->clip); i.next();)
  65238. {
  65239. if (++itemsOnLine == 6)
  65240. {
  65241. itemsOnLine = 0;
  65242. out << '\n';
  65243. }
  65244. const Rectangle<int>& r = *i.getRectangle();
  65245. out << r.getX() << ' ' << -r.getY() << ' '
  65246. << r.getWidth() << ' ' << -r.getHeight() << " pr ";
  65247. }
  65248. out << "endclip\n";
  65249. }
  65250. }
  65251. void LowLevelGraphicsPostScriptRenderer::writeColour (const Colour& colour)
  65252. {
  65253. Colour c (Colours::white.overlaidWith (colour));
  65254. if (lastColour != c)
  65255. {
  65256. lastColour = c;
  65257. out << String (c.getFloatRed(), 3) << ' '
  65258. << String (c.getFloatGreen(), 3) << ' '
  65259. << String (c.getFloatBlue(), 3) << " c\n";
  65260. }
  65261. }
  65262. void LowLevelGraphicsPostScriptRenderer::writeXY (const float x, const float y) const
  65263. {
  65264. out << String (x, 2) << ' '
  65265. << String (-y, 2) << ' ';
  65266. }
  65267. void LowLevelGraphicsPostScriptRenderer::writePath (const Path& path) const
  65268. {
  65269. out << "newpath ";
  65270. float lastX = 0.0f;
  65271. float lastY = 0.0f;
  65272. int itemsOnLine = 0;
  65273. Path::Iterator i (path);
  65274. while (i.next())
  65275. {
  65276. if (++itemsOnLine == 4)
  65277. {
  65278. itemsOnLine = 0;
  65279. out << '\n';
  65280. }
  65281. switch (i.elementType)
  65282. {
  65283. case Path::Iterator::startNewSubPath:
  65284. writeXY (i.x1, i.y1);
  65285. lastX = i.x1;
  65286. lastY = i.y1;
  65287. out << "m ";
  65288. break;
  65289. case Path::Iterator::lineTo:
  65290. writeXY (i.x1, i.y1);
  65291. lastX = i.x1;
  65292. lastY = i.y1;
  65293. out << "l ";
  65294. break;
  65295. case Path::Iterator::quadraticTo:
  65296. {
  65297. const float cp1x = lastX + (i.x1 - lastX) * 2.0f / 3.0f;
  65298. const float cp1y = lastY + (i.y1 - lastY) * 2.0f / 3.0f;
  65299. const float cp2x = cp1x + (i.x2 - lastX) / 3.0f;
  65300. const float cp2y = cp1y + (i.y2 - lastY) / 3.0f;
  65301. writeXY (cp1x, cp1y);
  65302. writeXY (cp2x, cp2y);
  65303. writeXY (i.x2, i.y2);
  65304. out << "ct ";
  65305. lastX = i.x2;
  65306. lastY = i.y2;
  65307. }
  65308. break;
  65309. case Path::Iterator::cubicTo:
  65310. writeXY (i.x1, i.y1);
  65311. writeXY (i.x2, i.y2);
  65312. writeXY (i.x3, i.y3);
  65313. out << "ct ";
  65314. lastX = i.x3;
  65315. lastY = i.y3;
  65316. break;
  65317. case Path::Iterator::closePath:
  65318. out << "cp ";
  65319. break;
  65320. default:
  65321. jassertfalse
  65322. break;
  65323. }
  65324. }
  65325. out << '\n';
  65326. }
  65327. void LowLevelGraphicsPostScriptRenderer::writeTransform (const AffineTransform& trans) const
  65328. {
  65329. out << "[ "
  65330. << trans.mat00 << ' '
  65331. << trans.mat10 << ' '
  65332. << trans.mat01 << ' '
  65333. << trans.mat11 << ' '
  65334. << trans.mat02 << ' '
  65335. << trans.mat12 << " ] concat ";
  65336. }
  65337. void LowLevelGraphicsPostScriptRenderer::setFill (const FillType& fillType)
  65338. {
  65339. stateStack.getLast()->fillType = fillType;
  65340. }
  65341. void LowLevelGraphicsPostScriptRenderer::setOpacity (float /*opacity*/)
  65342. {
  65343. }
  65344. void LowLevelGraphicsPostScriptRenderer::setInterpolationQuality (Graphics::ResamplingQuality /*quality*/)
  65345. {
  65346. }
  65347. void LowLevelGraphicsPostScriptRenderer::fillRect (const Rectangle<int>& r, const bool /*replaceExistingContents*/)
  65348. {
  65349. if (stateStack.getLast()->fillType.isColour())
  65350. {
  65351. writeClip();
  65352. writeColour (stateStack.getLast()->fillType.colour);
  65353. Rectangle<int> r2 (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65354. out << r2.getX() << ' ' << -r2.getBottom() << ' ' << r2.getWidth() << ' ' << r2.getHeight() << " rectfill\n";
  65355. }
  65356. else
  65357. {
  65358. Path p;
  65359. p.addRectangle (r);
  65360. fillPath (p, AffineTransform::identity);
  65361. }
  65362. }
  65363. void LowLevelGraphicsPostScriptRenderer::fillPath (const Path& path, const AffineTransform& t)
  65364. {
  65365. if (stateStack.getLast()->fillType.isColour())
  65366. {
  65367. writeClip();
  65368. Path p (path);
  65369. p.applyTransform (t.translated ((float) stateStack.getLast()->xOffset,
  65370. (float) stateStack.getLast()->yOffset));
  65371. writePath (p);
  65372. writeColour (stateStack.getLast()->fillType.colour);
  65373. out << "fill\n";
  65374. }
  65375. else if (stateStack.getLast()->fillType.isGradient())
  65376. {
  65377. // this doesn't work correctly yet - it could be improved to handle solid gradients, but
  65378. // postscript can't do semi-transparent ones.
  65379. notPossibleInPostscriptAssert // you can disable this warning by setting the WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS flag at the top of this file
  65380. writeClip();
  65381. out << "gsave ";
  65382. {
  65383. Path p (path);
  65384. p.applyTransform (t.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset));
  65385. writePath (p);
  65386. out << "clip\n";
  65387. }
  65388. const Rectangle<int> bounds (stateStack.getLast()->clip.getBounds());
  65389. // ideally this would draw lots of lines or ellipses to approximate the gradient, but for the
  65390. // time-being, this just fills it with the average colour..
  65391. writeColour (stateStack.getLast()->fillType.gradient->getColourAtPosition (0.5f));
  65392. out << bounds.getX() << ' ' << -bounds.getBottom() << ' ' << bounds.getWidth() << ' ' << bounds.getHeight() << " rectfill\n";
  65393. out << "grestore\n";
  65394. }
  65395. }
  65396. void LowLevelGraphicsPostScriptRenderer::writeImage (const Image& im,
  65397. const int sx, const int sy,
  65398. const int maxW, const int maxH) const
  65399. {
  65400. out << "{<\n";
  65401. const int w = jmin (maxW, im.getWidth());
  65402. const int h = jmin (maxH, im.getHeight());
  65403. int charsOnLine = 0;
  65404. const Image::BitmapData srcData (im, 0, 0, w, h);
  65405. Colour pixel;
  65406. for (int y = h; --y >= 0;)
  65407. {
  65408. for (int x = 0; x < w; ++x)
  65409. {
  65410. const uint8* pixelData = srcData.getPixelPointer (x, y);
  65411. if (x >= sx && y >= sy)
  65412. {
  65413. if (im.isARGB())
  65414. {
  65415. PixelARGB p (*(const PixelARGB*) pixelData);
  65416. p.unpremultiply();
  65417. pixel = Colours::white.overlaidWith (Colour (p.getARGB()));
  65418. }
  65419. else if (im.isRGB())
  65420. {
  65421. pixel = Colour (((const PixelRGB*) pixelData)->getARGB());
  65422. }
  65423. else
  65424. {
  65425. pixel = Colour ((uint8) 0, (uint8) 0, (uint8) 0, *pixelData);
  65426. }
  65427. }
  65428. else
  65429. {
  65430. pixel = Colours::transparentWhite;
  65431. }
  65432. const uint8 pixelValues[3] = { pixel.getRed(), pixel.getGreen(), pixel.getBlue() };
  65433. out << String::toHexString (pixelValues, 3, 0);
  65434. charsOnLine += 3;
  65435. if (charsOnLine > 100)
  65436. {
  65437. out << '\n';
  65438. charsOnLine = 0;
  65439. }
  65440. }
  65441. }
  65442. out << "\n>}\n";
  65443. }
  65444. void LowLevelGraphicsPostScriptRenderer::drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  65445. const AffineTransform& transform, const bool /*fillEntireClipAsTiles*/)
  65446. {
  65447. const int w = jmin (sourceImage.getWidth(), srcClip.getRight());
  65448. const int h = jmin (sourceImage.getHeight(), srcClip.getBottom());
  65449. writeClip();
  65450. out << "gsave ";
  65451. writeTransform (transform.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset)
  65452. .scaled (1.0f, -1.0f));
  65453. RectangleList imageClip;
  65454. sourceImage.createSolidAreaMask (imageClip, 0.5f);
  65455. imageClip.clipTo (srcClip);
  65456. out << "newpath ";
  65457. int itemsOnLine = 0;
  65458. for (RectangleList::Iterator i (imageClip); i.next();)
  65459. {
  65460. if (++itemsOnLine == 6)
  65461. {
  65462. out << '\n';
  65463. itemsOnLine = 0;
  65464. }
  65465. const Rectangle<int>& r = *i.getRectangle();
  65466. out << r.getX() << ' ' << r.getY() << ' ' << r.getWidth() << ' ' << r.getHeight() << " pr ";
  65467. }
  65468. out << " clip newpath\n";
  65469. out << w << ' ' << h << " scale\n";
  65470. out << w << ' ' << h << " 8 [" << w << " 0 0 -" << h << ' ' << (int) 0 << ' ' << h << " ]\n";
  65471. writeImage (sourceImage, srcClip.getX(), srcClip.getY(), srcClip.getWidth(), srcClip.getHeight());
  65472. out << "false 3 colorimage grestore\n";
  65473. needToClip = true;
  65474. }
  65475. void LowLevelGraphicsPostScriptRenderer::drawLine (double x1, double y1, double x2, double y2)
  65476. {
  65477. Path p;
  65478. p.addLineSegment ((float) x1, (float) y1, (float) x2, (float) y2, 1.0f);
  65479. fillPath (p, AffineTransform::identity);
  65480. }
  65481. void LowLevelGraphicsPostScriptRenderer::drawVerticalLine (const int x, double top, double bottom)
  65482. {
  65483. drawLine (x, top, x, bottom);
  65484. }
  65485. void LowLevelGraphicsPostScriptRenderer::drawHorizontalLine (const int y, double left, double right)
  65486. {
  65487. drawLine (left, y, right, y);
  65488. }
  65489. void LowLevelGraphicsPostScriptRenderer::setFont (const Font& newFont)
  65490. {
  65491. stateStack.getLast()->font = newFont;
  65492. }
  65493. const Font LowLevelGraphicsPostScriptRenderer::getFont()
  65494. {
  65495. return stateStack.getLast()->font;
  65496. }
  65497. void LowLevelGraphicsPostScriptRenderer::drawGlyph (int glyphNumber, const AffineTransform& transform)
  65498. {
  65499. Path p;
  65500. Font& font = stateStack.getLast()->font;
  65501. font.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  65502. fillPath (p, AffineTransform::scale (font.getHeight() * font.getHorizontalScale(), font.getHeight()).followedBy (transform));
  65503. }
  65504. END_JUCE_NAMESPACE
  65505. /*** End of inlined file: juce_LowLevelGraphicsPostScriptRenderer.cpp ***/
  65506. /*** Start of inlined file: juce_LowLevelGraphicsSoftwareRenderer.cpp ***/
  65507. BEGIN_JUCE_NAMESPACE
  65508. #if (JUCE_WINDOWS || JUCE_LINUX) && ! JUCE_64BIT
  65509. #define JUCE_USE_SSE_INSTRUCTIONS 1
  65510. #endif
  65511. #if JUCE_MSVC && JUCE_DEBUG
  65512. #pragma warning (disable: 4714) // warning about forcedinline methods not being inlined
  65513. #endif
  65514. #if JUCE_MSVC
  65515. #pragma warning (push)
  65516. #pragma warning (disable: 4127) // "expression is constant" warning
  65517. #endif
  65518. template <class PixelType, bool replaceExisting = false>
  65519. class SolidColourEdgeTableRenderer
  65520. {
  65521. public:
  65522. SolidColourEdgeTableRenderer (const Image::BitmapData& data_, const PixelARGB& colour) throw()
  65523. : data (data_),
  65524. sourceColour (colour)
  65525. {
  65526. if (sizeof (PixelType) == 3)
  65527. {
  65528. areRGBComponentsEqual = sourceColour.getRed() == sourceColour.getGreen()
  65529. && sourceColour.getGreen() == sourceColour.getBlue();
  65530. filler[0].set (sourceColour);
  65531. filler[1].set (sourceColour);
  65532. filler[2].set (sourceColour);
  65533. filler[3].set (sourceColour);
  65534. }
  65535. }
  65536. forcedinline void setEdgeTableYPos (const int y) throw()
  65537. {
  65538. linePixels = (PixelType*) data.getLinePointer (y);
  65539. }
  65540. forcedinline void handleEdgeTablePixel (const int x, const int alphaLevel) const throw()
  65541. {
  65542. if (replaceExisting)
  65543. linePixels[x].set (sourceColour);
  65544. else
  65545. linePixels[x].blend (sourceColour, alphaLevel);
  65546. }
  65547. forcedinline void handleEdgeTableLine (const int x, int width, const int alphaLevel) const throw()
  65548. {
  65549. PixelARGB p (sourceColour);
  65550. p.multiplyAlpha (alphaLevel);
  65551. PixelType* dest = linePixels + x;
  65552. if (replaceExisting || p.getAlpha() >= 0xff)
  65553. replaceLine (dest, p, width);
  65554. else
  65555. blendLine (dest, p, width);
  65556. }
  65557. private:
  65558. const Image::BitmapData& data;
  65559. PixelType* linePixels;
  65560. PixelARGB sourceColour;
  65561. PixelRGB filler [4];
  65562. bool areRGBComponentsEqual;
  65563. inline void blendLine (PixelType* dest, const PixelARGB& colour, int width) const throw()
  65564. {
  65565. do
  65566. {
  65567. dest->blend (colour);
  65568. ++dest;
  65569. } while (--width > 0);
  65570. }
  65571. forcedinline void replaceLine (PixelRGB* dest, const PixelARGB& colour, int width) const throw()
  65572. {
  65573. if (areRGBComponentsEqual) // if all the component values are the same, we can cheat..
  65574. {
  65575. memset (dest, colour.getRed(), width * 3);
  65576. }
  65577. else
  65578. {
  65579. if (width >> 5)
  65580. {
  65581. const int* const intFiller = (const int*) filler;
  65582. while (width > 8 && (((pointer_sized_int) dest) & 7) != 0)
  65583. {
  65584. dest->set (colour);
  65585. ++dest;
  65586. --width;
  65587. }
  65588. while (width > 4)
  65589. {
  65590. ((int*) dest) [0] = intFiller[0];
  65591. ((int*) dest) [1] = intFiller[1];
  65592. ((int*) dest) [2] = intFiller[2];
  65593. dest = (PixelRGB*) (((uint8*) dest) + 12);
  65594. width -= 4;
  65595. }
  65596. }
  65597. while (--width >= 0)
  65598. {
  65599. dest->set (colour);
  65600. ++dest;
  65601. }
  65602. }
  65603. }
  65604. forcedinline void replaceLine (PixelAlpha* dest, const PixelARGB& colour, int width) const throw()
  65605. {
  65606. memset (dest, colour.getAlpha(), width);
  65607. }
  65608. forcedinline void replaceLine (PixelARGB* dest, const PixelARGB& colour, int width) const throw()
  65609. {
  65610. do
  65611. {
  65612. dest->set (colour);
  65613. ++dest;
  65614. } while (--width > 0);
  65615. }
  65616. SolidColourEdgeTableRenderer (const SolidColourEdgeTableRenderer&);
  65617. SolidColourEdgeTableRenderer& operator= (const SolidColourEdgeTableRenderer&);
  65618. };
  65619. class LinearGradientPixelGenerator
  65620. {
  65621. public:
  65622. LinearGradientPixelGenerator (const ColourGradient& gradient, const AffineTransform& transform, const PixelARGB* const lookupTable_, const int numEntries_)
  65623. : lookupTable (lookupTable_), numEntries (numEntries_)
  65624. {
  65625. jassert (numEntries_ >= 0);
  65626. float x1 = gradient.x1;
  65627. float y1 = gradient.y1;
  65628. float x2 = gradient.x2;
  65629. float y2 = gradient.y2;
  65630. if (! transform.isIdentity())
  65631. {
  65632. const Line l (x2, y2, x1, y1);
  65633. const Point<float> p3 = l.getPointAlongLine (0.0f, 100.0f);
  65634. float x3 = p3.getX();
  65635. float y3 = p3.getY();
  65636. transform.transformPoint (x1, y1);
  65637. transform.transformPoint (x2, y2);
  65638. transform.transformPoint (x3, y3);
  65639. const Line l2 (x2, y2, x3, y3);
  65640. const float prop = l2.findNearestPointTo (x1, y1);
  65641. const Point<float> newP2 (l2.getPointAlongLineProportionally (prop));
  65642. x2 = newP2.getX();
  65643. y2 = newP2.getY();
  65644. }
  65645. vertical = fabs (x1 - x2) < 0.001f;
  65646. horizontal = fabs (y1 - y2) < 0.001f;
  65647. if (vertical)
  65648. {
  65649. scale = roundToInt ((numEntries << (int) numScaleBits) / (double) (y2 - y1));
  65650. start = roundToInt (y1 * scale);
  65651. }
  65652. else if (horizontal)
  65653. {
  65654. scale = roundToInt ((numEntries << (int) numScaleBits) / (double) (x2 - x1));
  65655. start = roundToInt (x1 * scale);
  65656. }
  65657. else
  65658. {
  65659. grad = (y2 - y1) / (double) (x1 - x2);
  65660. yTerm = y1 - x1 / grad;
  65661. scale = roundToInt ((numEntries << (int) numScaleBits) / (yTerm * grad - (y2 * grad - x2)));
  65662. grad *= scale;
  65663. }
  65664. }
  65665. forcedinline void setY (const int y) throw()
  65666. {
  65667. if (vertical)
  65668. linePix = lookupTable [jlimit (0, numEntries, (y * scale - start) >> (int) numScaleBits)];
  65669. else if (! horizontal)
  65670. start = roundToInt ((y - yTerm) * grad);
  65671. }
  65672. inline const PixelARGB getPixel (const int x) const throw()
  65673. {
  65674. return vertical ? linePix
  65675. : lookupTable [jlimit (0, numEntries, (x * scale - start) >> (int) numScaleBits)];
  65676. }
  65677. private:
  65678. const PixelARGB* const lookupTable;
  65679. const int numEntries;
  65680. PixelARGB linePix;
  65681. int start, scale;
  65682. double grad, yTerm;
  65683. bool vertical, horizontal;
  65684. enum { numScaleBits = 12 };
  65685. LinearGradientPixelGenerator (const LinearGradientPixelGenerator&);
  65686. LinearGradientPixelGenerator& operator= (const LinearGradientPixelGenerator&);
  65687. };
  65688. class RadialGradientPixelGenerator
  65689. {
  65690. public:
  65691. RadialGradientPixelGenerator (const ColourGradient& gradient, const AffineTransform&,
  65692. const PixelARGB* const lookupTable_, const int numEntries_) throw()
  65693. : lookupTable (lookupTable_),
  65694. numEntries (numEntries_),
  65695. gx1 (gradient.x1),
  65696. gy1 (gradient.y1)
  65697. {
  65698. jassert (numEntries_ >= 0);
  65699. const float gdx = gradient.x1 - gradient.x2;
  65700. const float gdy = gradient.y1 - gradient.y2;
  65701. maxDist = gdx * gdx + gdy * gdy;
  65702. invScale = numEntries / sqrt (maxDist);
  65703. jassert (roundToInt (sqrt (maxDist) * invScale) <= numEntries);
  65704. }
  65705. forcedinline void setY (const int y) throw()
  65706. {
  65707. dy = y - gy1;
  65708. dy *= dy;
  65709. }
  65710. inline const PixelARGB getPixel (const int px) const throw()
  65711. {
  65712. double x = px - gx1;
  65713. x *= x;
  65714. x += dy;
  65715. return lookupTable [x >= maxDist ? numEntries : roundToInt (sqrt (x) * invScale)];
  65716. }
  65717. protected:
  65718. const PixelARGB* const lookupTable;
  65719. const int numEntries;
  65720. const double gx1, gy1;
  65721. double maxDist, invScale, dy;
  65722. RadialGradientPixelGenerator (const RadialGradientPixelGenerator&);
  65723. RadialGradientPixelGenerator& operator= (const RadialGradientPixelGenerator&);
  65724. };
  65725. class TransformedRadialGradientPixelGenerator : public RadialGradientPixelGenerator
  65726. {
  65727. public:
  65728. TransformedRadialGradientPixelGenerator (const ColourGradient& gradient, const AffineTransform& transform,
  65729. const PixelARGB* const lookupTable_, const int numEntries_) throw()
  65730. : RadialGradientPixelGenerator (gradient, transform, lookupTable_, numEntries_),
  65731. inverseTransform (transform.inverted())
  65732. {
  65733. tM10 = inverseTransform.mat10;
  65734. tM00 = inverseTransform.mat00;
  65735. }
  65736. forcedinline void setY (const int y) throw()
  65737. {
  65738. lineYM01 = inverseTransform.mat01 * y + inverseTransform.mat02 - gx1;
  65739. lineYM11 = inverseTransform.mat11 * y + inverseTransform.mat12 - gy1;
  65740. }
  65741. inline const PixelARGB getPixel (const int px) const throw()
  65742. {
  65743. double x = px;
  65744. const double y = tM10 * x + lineYM11;
  65745. x = tM00 * x + lineYM01;
  65746. x *= x;
  65747. x += y * y;
  65748. if (x >= maxDist)
  65749. return lookupTable [numEntries];
  65750. else
  65751. return lookupTable [jmin (numEntries, roundToInt (sqrt (x) * invScale))];
  65752. }
  65753. private:
  65754. double tM10, tM00, lineYM01, lineYM11;
  65755. const AffineTransform inverseTransform;
  65756. TransformedRadialGradientPixelGenerator (const TransformedRadialGradientPixelGenerator&);
  65757. TransformedRadialGradientPixelGenerator& operator= (const TransformedRadialGradientPixelGenerator&);
  65758. };
  65759. template <class PixelType, class GradientType>
  65760. class GradientEdgeTableRenderer : public GradientType
  65761. {
  65762. public:
  65763. GradientEdgeTableRenderer (const Image::BitmapData& destData_, const ColourGradient& gradient, const AffineTransform& transform,
  65764. const PixelARGB* const lookupTable_, const int numEntries_) throw()
  65765. : GradientType (gradient, transform, lookupTable_, numEntries_ - 1),
  65766. destData (destData_)
  65767. {
  65768. }
  65769. forcedinline void setEdgeTableYPos (const int y) throw()
  65770. {
  65771. linePixels = (PixelType*) destData.getLinePointer (y);
  65772. GradientType::setY (y);
  65773. }
  65774. forcedinline void handleEdgeTablePixel (const int x, const int alphaLevel) const throw()
  65775. {
  65776. linePixels[x].blend (GradientType::getPixel (x), alphaLevel);
  65777. }
  65778. forcedinline void handleEdgeTableLine (int x, int width, const int alphaLevel) const throw()
  65779. {
  65780. PixelType* dest = linePixels + x;
  65781. if (alphaLevel < 0xff)
  65782. {
  65783. do
  65784. {
  65785. (dest++)->blend (GradientType::getPixel (x++), alphaLevel);
  65786. } while (--width > 0);
  65787. }
  65788. else
  65789. {
  65790. do
  65791. {
  65792. (dest++)->blend (GradientType::getPixel (x++));
  65793. } while (--width > 0);
  65794. }
  65795. }
  65796. private:
  65797. const Image::BitmapData& destData;
  65798. PixelType* linePixels;
  65799. GradientEdgeTableRenderer (const GradientEdgeTableRenderer&);
  65800. GradientEdgeTableRenderer& operator= (const GradientEdgeTableRenderer&);
  65801. };
  65802. static forcedinline int safeModulo (int n, const int divisor) throw()
  65803. {
  65804. jassert (divisor > 0);
  65805. n %= divisor;
  65806. return (n < 0) ? (n + divisor) : n;
  65807. }
  65808. template <class DestPixelType, class SrcPixelType, bool repeatPattern>
  65809. class ImageFillEdgeTableRenderer
  65810. {
  65811. public:
  65812. ImageFillEdgeTableRenderer (const Image::BitmapData& destData_,
  65813. const Image::BitmapData& srcData_,
  65814. const int extraAlpha_,
  65815. const int x, const int y) throw()
  65816. : destData (destData_),
  65817. srcData (srcData_),
  65818. extraAlpha (extraAlpha_ + 1),
  65819. xOffset (repeatPattern ? safeModulo (x, srcData_.width) - srcData_.width : x),
  65820. yOffset (repeatPattern ? safeModulo (y, srcData_.height) - srcData_.height : y)
  65821. {
  65822. }
  65823. forcedinline void setEdgeTableYPos (int y) throw()
  65824. {
  65825. linePixels = (DestPixelType*) destData.getLinePointer (y);
  65826. y -= yOffset;
  65827. if (repeatPattern)
  65828. {
  65829. jassert (y >= 0);
  65830. y %= srcData.height;
  65831. }
  65832. sourceLineStart = (SrcPixelType*) srcData.getLinePointer (y);
  65833. }
  65834. forcedinline void handleEdgeTablePixel (int x, int alphaLevel) const throw()
  65835. {
  65836. alphaLevel = (alphaLevel * extraAlpha) >> 8;
  65837. linePixels[x].blend (sourceLineStart [repeatPattern ? ((x - xOffset) % srcData.width) : (x - xOffset)], alphaLevel);
  65838. }
  65839. forcedinline void handleEdgeTableLine (int x, int width, int alphaLevel) const throw()
  65840. {
  65841. DestPixelType* dest = linePixels + x;
  65842. alphaLevel = (alphaLevel * extraAlpha) >> 8;
  65843. x -= xOffset;
  65844. jassert (repeatPattern || (x >= 0 && x + width <= srcData.width));
  65845. if (alphaLevel < 0xfe)
  65846. {
  65847. do
  65848. {
  65849. dest++ ->blend (sourceLineStart [repeatPattern ? (x++ % srcData.width) : x++], alphaLevel);
  65850. } while (--width > 0);
  65851. }
  65852. else
  65853. {
  65854. if (repeatPattern)
  65855. {
  65856. do
  65857. {
  65858. dest++ ->blend (sourceLineStart [x++ % srcData.width]);
  65859. } while (--width > 0);
  65860. }
  65861. else
  65862. {
  65863. copyRow (dest, sourceLineStart + x, width);
  65864. }
  65865. }
  65866. }
  65867. void clipEdgeTableLine (EdgeTable& et, int x, int y, int width) throw()
  65868. {
  65869. jassert (x - xOffset >= 0 && x + width - xOffset <= srcData.width);
  65870. SrcPixelType* s = (SrcPixelType*) srcData.getLinePointer (y - yOffset);
  65871. uint8* mask = (uint8*) (s + x - xOffset);
  65872. if (sizeof (SrcPixelType) == sizeof (PixelARGB))
  65873. mask += PixelARGB::indexA;
  65874. et.clipLineToMask (x, y, mask, sizeof (SrcPixelType), width);
  65875. }
  65876. private:
  65877. const Image::BitmapData& destData;
  65878. const Image::BitmapData& srcData;
  65879. const int extraAlpha, xOffset, yOffset;
  65880. DestPixelType* linePixels;
  65881. SrcPixelType* sourceLineStart;
  65882. template <class PixelType1, class PixelType2>
  65883. forcedinline static void copyRow (PixelType1* dest, PixelType2* src, int width) throw()
  65884. {
  65885. do
  65886. {
  65887. dest++ ->blend (*src++);
  65888. } while (--width > 0);
  65889. }
  65890. forcedinline static void copyRow (PixelRGB* dest, PixelRGB* src, int width) throw()
  65891. {
  65892. memcpy (dest, src, width * sizeof (PixelRGB));
  65893. }
  65894. ImageFillEdgeTableRenderer (const ImageFillEdgeTableRenderer&);
  65895. ImageFillEdgeTableRenderer& operator= (const ImageFillEdgeTableRenderer&);
  65896. };
  65897. template <class DestPixelType, class SrcPixelType, bool repeatPattern>
  65898. class TransformedImageFillEdgeTableRenderer
  65899. {
  65900. public:
  65901. TransformedImageFillEdgeTableRenderer (const Image::BitmapData& destData_,
  65902. const Image::BitmapData& srcData_,
  65903. const AffineTransform& transform,
  65904. const int extraAlpha_,
  65905. const bool betterQuality_) throw()
  65906. : interpolator (transform),
  65907. destData (destData_),
  65908. srcData (srcData_),
  65909. extraAlpha (extraAlpha_ + 1),
  65910. betterQuality (betterQuality_),
  65911. pixelOffset (betterQuality_ ? 0.5f : 0.0f),
  65912. pixelOffsetInt (betterQuality_ ? -128 : 0),
  65913. maxX (srcData_.width - 1),
  65914. maxY (srcData_.height - 1),
  65915. scratchSize (2048)
  65916. {
  65917. scratchBuffer.malloc (scratchSize);
  65918. }
  65919. ~TransformedImageFillEdgeTableRenderer() throw()
  65920. {
  65921. }
  65922. forcedinline void setEdgeTableYPos (const int newY) throw()
  65923. {
  65924. y = newY;
  65925. linePixels = (DestPixelType*) destData.getLinePointer (newY);
  65926. }
  65927. forcedinline void handleEdgeTablePixel (const int x, int alphaLevel) throw()
  65928. {
  65929. alphaLevel *= extraAlpha;
  65930. alphaLevel >>= 8;
  65931. SrcPixelType p;
  65932. generate (&p, x, 1);
  65933. linePixels[x].blend (p, alphaLevel);
  65934. }
  65935. forcedinline void handleEdgeTableLine (const int x, int width, int alphaLevel) throw()
  65936. {
  65937. if (width > scratchSize)
  65938. {
  65939. scratchSize = width;
  65940. scratchBuffer.malloc (scratchSize);
  65941. }
  65942. SrcPixelType* span = scratchBuffer;
  65943. generate (span, x, width);
  65944. DestPixelType* dest = linePixels + x;
  65945. alphaLevel *= extraAlpha;
  65946. alphaLevel >>= 8;
  65947. if (alphaLevel < 0xfe)
  65948. {
  65949. do
  65950. {
  65951. dest++ ->blend (*span++, alphaLevel);
  65952. } while (--width > 0);
  65953. }
  65954. else
  65955. {
  65956. do
  65957. {
  65958. dest++ ->blend (*span++);
  65959. } while (--width > 0);
  65960. }
  65961. }
  65962. void clipEdgeTableLine (EdgeTable& et, int x, int y_, int width) throw()
  65963. {
  65964. if (width > scratchSize)
  65965. {
  65966. scratchSize = width;
  65967. scratchBuffer.malloc (scratchSize);
  65968. }
  65969. y = y_;
  65970. generate (scratchBuffer, x, width);
  65971. const uint8* mask = reinterpret_cast <uint8*> (scratchBuffer.getData());
  65972. if (sizeof (SrcPixelType) == sizeof (PixelARGB))
  65973. mask += PixelARGB::indexA;
  65974. et.clipLineToMask (x, y_, mask, sizeof (SrcPixelType), width);
  65975. }
  65976. private:
  65977. void generate (PixelARGB* dest, const int x, int numPixels) throw()
  65978. {
  65979. this->interpolator.setStartOfLine (x + pixelOffset, y + pixelOffset, numPixels);
  65980. do
  65981. {
  65982. int hiResX, hiResY;
  65983. this->interpolator.next (hiResX, hiResY);
  65984. hiResX += pixelOffsetInt;
  65985. hiResY += pixelOffsetInt;
  65986. int loResX = hiResX >> 8;
  65987. int loResY = hiResY >> 8;
  65988. if (repeatPattern)
  65989. {
  65990. loResX = safeModulo (loResX, srcData.width);
  65991. loResY = safeModulo (loResY, srcData.height);
  65992. }
  65993. if (betterQuality
  65994. && ((unsigned int) loResX) < (unsigned int) maxX
  65995. && ((unsigned int) loResY) < (unsigned int) maxY)
  65996. {
  65997. uint32 c[4] = { 256 * 128, 256 * 128, 256 * 128, 256 * 128 };
  65998. hiResX &= 255;
  65999. hiResY &= 255;
  66000. const uint8* src = this->srcData.getPixelPointer (loResX, loResY);
  66001. uint32 weight = (256 - hiResX) * (256 - hiResY);
  66002. c[0] += weight * src[0];
  66003. c[1] += weight * src[1];
  66004. c[2] += weight * src[2];
  66005. c[3] += weight * src[3];
  66006. weight = hiResX * (256 - hiResY);
  66007. c[0] += weight * src[4];
  66008. c[1] += weight * src[5];
  66009. c[2] += weight * src[6];
  66010. c[3] += weight * src[7];
  66011. src += this->srcData.lineStride;
  66012. weight = (256 - hiResX) * hiResY;
  66013. c[0] += weight * src[0];
  66014. c[1] += weight * src[1];
  66015. c[2] += weight * src[2];
  66016. c[3] += weight * src[3];
  66017. weight = hiResX * hiResY;
  66018. c[0] += weight * src[4];
  66019. c[1] += weight * src[5];
  66020. c[2] += weight * src[6];
  66021. c[3] += weight * src[7];
  66022. dest->setARGB ((uint8) (c[PixelARGB::indexA] >> 16),
  66023. (uint8) (c[PixelARGB::indexR] >> 16),
  66024. (uint8) (c[PixelARGB::indexG] >> 16),
  66025. (uint8) (c[PixelARGB::indexB] >> 16));
  66026. }
  66027. else
  66028. {
  66029. if (! repeatPattern)
  66030. {
  66031. // Beyond the edges, just repeat the edge pixels and leave the anti-aliasing to be handled by the edgetable
  66032. if (loResX < 0) loResX = 0;
  66033. if (loResY < 0) loResY = 0;
  66034. if (loResX > maxX) loResX = maxX;
  66035. if (loResY > maxY) loResY = maxY;
  66036. }
  66037. dest->set (*(const PixelARGB*) this->srcData.getPixelPointer (loResX, loResY));
  66038. }
  66039. ++dest;
  66040. } while (--numPixels > 0);
  66041. }
  66042. void generate (PixelRGB* dest, const int x, int numPixels) throw()
  66043. {
  66044. this->interpolator.setStartOfLine (x + pixelOffset, y + pixelOffset, numPixels);
  66045. do
  66046. {
  66047. int hiResX, hiResY;
  66048. this->interpolator.next (hiResX, hiResY);
  66049. hiResX += pixelOffsetInt;
  66050. hiResY += pixelOffsetInt;
  66051. int loResX = hiResX >> 8;
  66052. int loResY = hiResY >> 8;
  66053. if (repeatPattern)
  66054. {
  66055. loResX = safeModulo (loResX, srcData.width);
  66056. loResY = safeModulo (loResY, srcData.height);
  66057. }
  66058. if (betterQuality
  66059. && ((unsigned int) loResX) < (unsigned int) maxX
  66060. && ((unsigned int) loResY) < (unsigned int) maxY)
  66061. {
  66062. uint32 c[3] = { 256 * 128, 256 * 128, 256 * 128 };
  66063. hiResX &= 255;
  66064. hiResY &= 255;
  66065. const uint8* src = this->srcData.getPixelPointer (loResX, loResY);
  66066. unsigned int weight = (256 - hiResX) * (256 - hiResY);
  66067. c[0] += weight * src[0];
  66068. c[1] += weight * src[1];
  66069. c[2] += weight * src[2];
  66070. weight = hiResX * (256 - hiResY);
  66071. c[0] += weight * src[3];
  66072. c[1] += weight * src[4];
  66073. c[2] += weight * src[5];
  66074. src += this->srcData.lineStride;
  66075. weight = (256 - hiResX) * hiResY;
  66076. c[0] += weight * src[0];
  66077. c[1] += weight * src[1];
  66078. c[2] += weight * src[2];
  66079. weight = hiResX * hiResY;
  66080. c[0] += weight * src[3];
  66081. c[1] += weight * src[4];
  66082. c[2] += weight * src[5];
  66083. dest->setARGB ((uint8) 255,
  66084. (uint8) (c[PixelRGB::indexR] >> 16),
  66085. (uint8) (c[PixelRGB::indexG] >> 16),
  66086. (uint8) (c[PixelRGB::indexB] >> 16));
  66087. }
  66088. else
  66089. {
  66090. if (! repeatPattern)
  66091. {
  66092. // Beyond the edges, just repeat the edge pixels and leave the anti-aliasing to be handled by the edgetable
  66093. if (loResX < 0) loResX = 0;
  66094. if (loResY < 0) loResY = 0;
  66095. if (loResX > maxX) loResX = maxX;
  66096. if (loResY > maxY) loResY = maxY;
  66097. }
  66098. dest->set (*(const PixelRGB*) this->srcData.getPixelPointer (loResX, loResY));
  66099. }
  66100. ++dest;
  66101. } while (--numPixels > 0);
  66102. }
  66103. void generate (PixelAlpha* dest, const int x, int numPixels) throw()
  66104. {
  66105. this->interpolator.setStartOfLine (x + pixelOffset, y + pixelOffset, numPixels);
  66106. do
  66107. {
  66108. int hiResX, hiResY;
  66109. this->interpolator.next (hiResX, hiResY);
  66110. hiResX += pixelOffsetInt;
  66111. hiResY += pixelOffsetInt;
  66112. int loResX = hiResX >> 8;
  66113. int loResY = hiResY >> 8;
  66114. if (repeatPattern)
  66115. {
  66116. loResX = safeModulo (loResX, srcData.width);
  66117. loResY = safeModulo (loResY, srcData.height);
  66118. }
  66119. if (betterQuality
  66120. && ((unsigned int) loResX) < (unsigned int) maxX
  66121. && ((unsigned int) loResY) < (unsigned int) maxY)
  66122. {
  66123. hiResX &= 255;
  66124. hiResY &= 255;
  66125. const uint8* src = this->srcData.getPixelPointer (loResX, loResY);
  66126. uint32 c = 256 * 128;
  66127. c += src[0] * ((256 - hiResX) * (256 - hiResY));
  66128. c += src[1] * (hiResX * (256 - hiResY));
  66129. src += this->srcData.lineStride;
  66130. c += src[0] * ((256 - hiResX) * hiResY);
  66131. c += src[1] * (hiResX * hiResY);
  66132. *((uint8*) dest) = (uint8) c;
  66133. }
  66134. else
  66135. {
  66136. if (! repeatPattern)
  66137. {
  66138. // Beyond the edges, just repeat the edge pixels and leave the anti-aliasing to be handled by the edgetable
  66139. if (loResX < 0) loResX = 0;
  66140. if (loResY < 0) loResY = 0;
  66141. if (loResX > maxX) loResX = maxX;
  66142. if (loResY > maxY) loResY = maxY;
  66143. }
  66144. *((uint8*) dest) = *(this->srcData.getPixelPointer (loResX, loResY));
  66145. }
  66146. ++dest;
  66147. } while (--numPixels > 0);
  66148. }
  66149. class TransformedImageSpanInterpolator
  66150. {
  66151. public:
  66152. TransformedImageSpanInterpolator (const AffineTransform& transform) throw()
  66153. : inverseTransform (transform.inverted())
  66154. {}
  66155. void setStartOfLine (float x, float y, const int numPixels) throw()
  66156. {
  66157. float x1 = x, y1 = y;
  66158. inverseTransform.transformPoint (x1, y1);
  66159. x += numPixels;
  66160. inverseTransform.transformPoint (x, y);
  66161. xBresenham.set ((int) (x1 * 256.0f), (int) (x * 256.0f), numPixels);
  66162. yBresenham.set ((int) (y1 * 256.0f), (int) (y * 256.0f), numPixels);
  66163. }
  66164. void next (int& x, int& y) throw()
  66165. {
  66166. x = xBresenham.n;
  66167. xBresenham.stepToNext();
  66168. y = yBresenham.n;
  66169. yBresenham.stepToNext();
  66170. }
  66171. private:
  66172. class BresenhamInterpolator
  66173. {
  66174. public:
  66175. BresenhamInterpolator() throw() {}
  66176. void set (const int n1, const int n2, const int numSteps_) throw()
  66177. {
  66178. numSteps = jmax (1, numSteps_);
  66179. step = (n2 - n1) / numSteps;
  66180. remainder = modulo = (n2 - n1) % numSteps;
  66181. n = n1;
  66182. if (modulo <= 0)
  66183. {
  66184. modulo += numSteps;
  66185. remainder += numSteps;
  66186. --step;
  66187. }
  66188. modulo -= numSteps;
  66189. }
  66190. forcedinline void stepToNext() throw()
  66191. {
  66192. modulo += remainder;
  66193. n += step;
  66194. if (modulo > 0)
  66195. {
  66196. modulo -= numSteps;
  66197. ++n;
  66198. }
  66199. }
  66200. int n;
  66201. private:
  66202. int numSteps, step, modulo, remainder;
  66203. };
  66204. const AffineTransform inverseTransform;
  66205. BresenhamInterpolator xBresenham, yBresenham;
  66206. TransformedImageSpanInterpolator (const TransformedImageSpanInterpolator&);
  66207. TransformedImageSpanInterpolator& operator= (const TransformedImageSpanInterpolator&);
  66208. };
  66209. TransformedImageSpanInterpolator interpolator;
  66210. const Image::BitmapData& destData;
  66211. const Image::BitmapData& srcData;
  66212. const int extraAlpha;
  66213. const bool betterQuality;
  66214. const float pixelOffset;
  66215. const int pixelOffsetInt, maxX, maxY;
  66216. int y;
  66217. DestPixelType* linePixels;
  66218. HeapBlock <SrcPixelType> scratchBuffer;
  66219. int scratchSize;
  66220. TransformedImageFillEdgeTableRenderer (const TransformedImageFillEdgeTableRenderer&);
  66221. TransformedImageFillEdgeTableRenderer& operator= (const TransformedImageFillEdgeTableRenderer&);
  66222. };
  66223. class LLGCSavedState
  66224. {
  66225. public:
  66226. LLGCSavedState (const Rectangle<int>& clip_, const int xOffset_, const int yOffset_,
  66227. const Font& font_, const FillType& fillType_,
  66228. const Graphics::ResamplingQuality interpolationQuality_) throw()
  66229. : edgeTable (new EdgeTableHolder (EdgeTable (clip_))),
  66230. xOffset (xOffset_), yOffset (yOffset_),
  66231. font (font_), fillType (fillType_),
  66232. interpolationQuality (interpolationQuality_)
  66233. {
  66234. }
  66235. LLGCSavedState (const LLGCSavedState& other) throw()
  66236. : edgeTable (other.edgeTable), xOffset (other.xOffset),
  66237. yOffset (other.yOffset), font (other.font),
  66238. fillType (other.fillType), interpolationQuality (other.interpolationQuality)
  66239. {
  66240. }
  66241. ~LLGCSavedState() throw()
  66242. {
  66243. }
  66244. bool clipToRectangle (const Rectangle<int>& r) throw()
  66245. {
  66246. dupeEdgeTableIfMultiplyReferenced();
  66247. edgeTable->edgeTable.clipToRectangle (r.translated (xOffset, yOffset));
  66248. return ! edgeTable->edgeTable.isEmpty();
  66249. }
  66250. bool clipToRectangleList (const RectangleList& r) throw()
  66251. {
  66252. dupeEdgeTableIfMultiplyReferenced();
  66253. RectangleList offsetList (r);
  66254. offsetList.offsetAll (xOffset, yOffset);
  66255. EdgeTable e2 (offsetList);
  66256. edgeTable->edgeTable.clipToEdgeTable (e2);
  66257. return ! edgeTable->edgeTable.isEmpty();
  66258. }
  66259. bool excludeClipRectangle (const Rectangle<int>& r) throw()
  66260. {
  66261. dupeEdgeTableIfMultiplyReferenced();
  66262. edgeTable->edgeTable.excludeRectangle (r.translated (xOffset, yOffset));
  66263. return ! edgeTable->edgeTable.isEmpty();
  66264. }
  66265. void clipToPath (const Path& p, const AffineTransform& transform) throw()
  66266. {
  66267. dupeEdgeTableIfMultiplyReferenced();
  66268. EdgeTable et (edgeTable->edgeTable.getMaximumBounds(), p, transform.translated ((float) xOffset, (float) yOffset));
  66269. edgeTable->edgeTable.clipToEdgeTable (et);
  66270. }
  66271. void fillEdgeTable (Image& image, EdgeTable& et, const bool replaceContents = false) throw()
  66272. {
  66273. et.clipToEdgeTable (edgeTable->edgeTable);
  66274. Image::BitmapData destData (image, 0, 0, image.getWidth(), image.getHeight(), true);
  66275. if (fillType.isGradient())
  66276. {
  66277. jassert (! replaceContents); // that option is just for solid colours
  66278. ColourGradient g2 (*(fillType.gradient));
  66279. g2.multiplyOpacity (fillType.getOpacity());
  66280. g2.x1 -= 0.5f; g2.y1 -= 0.5f;
  66281. g2.x2 -= 0.5f; g2.y2 -= 0.5f;
  66282. AffineTransform transform (fillType.transform.translated ((float) xOffset, (float) yOffset));
  66283. const bool isIdentity = transform.isOnlyTranslation();
  66284. if (isIdentity)
  66285. {
  66286. // If our translation doesn't involve any distortion, we can speed it up..
  66287. transform.transformPoint (g2.x1, g2.y1);
  66288. transform.transformPoint (g2.x2, g2.y2);
  66289. transform = AffineTransform::identity;
  66290. }
  66291. HeapBlock <PixelARGB> lookupTable;
  66292. const int numLookupEntries = g2.createLookupTable (transform, lookupTable);
  66293. jassert (numLookupEntries > 0);
  66294. switch (image.getFormat())
  66295. {
  66296. case Image::ARGB: renderGradient (et, destData, g2, transform, lookupTable, numLookupEntries, isIdentity, (PixelARGB*) 0); break;
  66297. case Image::RGB: renderGradient (et, destData, g2, transform, lookupTable, numLookupEntries, isIdentity, (PixelRGB*) 0); break;
  66298. default: renderGradient (et, destData, g2, transform, lookupTable, numLookupEntries, isIdentity, (PixelAlpha*) 0); break;
  66299. }
  66300. }
  66301. else if (fillType.isTiledImage())
  66302. {
  66303. renderImage (image, *(fillType.image), fillType.image->getBounds(), fillType.transform, &et);
  66304. }
  66305. else
  66306. {
  66307. const PixelARGB fillColour (fillType.colour.getPixelARGB());
  66308. switch (image.getFormat())
  66309. {
  66310. case Image::ARGB: renderSolidFill (et, destData, fillColour, replaceContents, (PixelARGB*) 0); break;
  66311. case Image::RGB: renderSolidFill (et, destData, fillColour, replaceContents, (PixelRGB*) 0); break;
  66312. default: renderSolidFill (et, destData, fillColour, replaceContents, (PixelAlpha*) 0); break;
  66313. }
  66314. }
  66315. }
  66316. void renderImage (Image& destImage, const Image& sourceImage, const Rectangle<int>& srcClip,
  66317. const AffineTransform& t, const EdgeTable* const tiledFillClipRegion) throw()
  66318. {
  66319. const AffineTransform transform (t.translated ((float) xOffset, (float) yOffset));
  66320. const Image::BitmapData destData (destImage, 0, 0, destImage.getWidth(), destImage.getHeight(), true);
  66321. const Image::BitmapData srcData (sourceImage, srcClip.getX(), srcClip.getY(), srcClip.getWidth(), srcClip.getHeight());
  66322. const int alpha = fillType.colour.getAlpha();
  66323. const bool betterQuality = (interpolationQuality != Graphics::lowResamplingQuality);
  66324. if (transform.isOnlyTranslation())
  66325. {
  66326. // If our translation doesn't involve any distortion, just use a simple blit..
  66327. int tx = (int) (transform.getTranslationX() * 256.0f);
  66328. int ty = (int) (transform.getTranslationY() * 256.0f);
  66329. if ((! betterQuality) || ((tx | ty) & 224) == 0)
  66330. {
  66331. tx = ((tx + 128) >> 8);
  66332. ty = ((ty + 128) >> 8);
  66333. if (tiledFillClipRegion != 0)
  66334. {
  66335. blittedRenderImage (sourceImage, destImage, *tiledFillClipRegion, destData, srcData, alpha, tx, ty, true);
  66336. }
  66337. else
  66338. {
  66339. EdgeTable et (Rectangle<int> (tx, ty, srcClip.getWidth(), srcClip.getHeight()).getIntersection (destImage.getBounds()));
  66340. et.clipToEdgeTable (edgeTable->edgeTable);
  66341. if (! et.isEmpty())
  66342. blittedRenderImage (sourceImage, destImage, et, destData, srcData, alpha, tx, ty, false);
  66343. }
  66344. return;
  66345. }
  66346. }
  66347. if (transform.isSingularity())
  66348. return;
  66349. if (tiledFillClipRegion != 0)
  66350. {
  66351. transformedRenderImage (sourceImage, destImage, *tiledFillClipRegion, destData, srcData, alpha, transform, betterQuality, true);
  66352. }
  66353. else
  66354. {
  66355. Path p;
  66356. p.addRectangle (0.0f, 0.0f, (float) srcClip.getWidth(), (float) srcClip.getHeight());
  66357. EdgeTable et (edgeTable->edgeTable.getMaximumBounds(), p, transform);
  66358. et.clipToEdgeTable (edgeTable->edgeTable);
  66359. if (! et.isEmpty())
  66360. transformedRenderImage (sourceImage, destImage, et, destData, srcData, alpha, transform, betterQuality, false);
  66361. }
  66362. }
  66363. void clipToImageAlpha (const Image& image, const Rectangle<int>& srcClip, const AffineTransform& t) throw()
  66364. {
  66365. if (! image.hasAlphaChannel())
  66366. {
  66367. Path p;
  66368. p.addRectangle (srcClip);
  66369. clipToPath (p, t);
  66370. return;
  66371. }
  66372. dupeEdgeTableIfMultiplyReferenced();
  66373. const AffineTransform transform (t.translated ((float) xOffset, (float) yOffset));
  66374. const Image::BitmapData srcData (image, srcClip.getX(), srcClip.getY(), srcClip.getWidth(), srcClip.getHeight());
  66375. const bool betterQuality = (interpolationQuality != Graphics::lowResamplingQuality);
  66376. EdgeTable& et = edgeTable->edgeTable;
  66377. if (transform.isOnlyTranslation())
  66378. {
  66379. // If our translation doesn't involve any distortion, just use a simple blit..
  66380. const int tx = (int) (transform.getTranslationX() * 256.0f);
  66381. const int ty = (int) (transform.getTranslationY() * 256.0f);
  66382. if ((! betterQuality) || ((tx | ty) & 224) == 0)
  66383. {
  66384. const int imageX = ((tx + 128) >> 8);
  66385. const int imageY = ((ty + 128) >> 8);
  66386. if (image.getFormat() == Image::ARGB)
  66387. straightClipImage (et, srcData, imageX, imageY, (PixelARGB*)0);
  66388. else
  66389. straightClipImage (et, srcData, imageX, imageY, (PixelAlpha*)0);
  66390. return;
  66391. }
  66392. }
  66393. if (transform.isSingularity())
  66394. {
  66395. et.clipToRectangle (Rectangle<int>());
  66396. return;
  66397. }
  66398. {
  66399. Path p;
  66400. p.addRectangle (0, 0, (float) srcData.width, (float) srcData.height);
  66401. EdgeTable et2 (et.getMaximumBounds(), p, transform);
  66402. et.clipToEdgeTable (et2);
  66403. }
  66404. if (! et.isEmpty())
  66405. {
  66406. if (image.getFormat() == Image::ARGB)
  66407. transformedClipImage (et, srcData, transform, betterQuality, (PixelARGB*)0);
  66408. else
  66409. transformedClipImage (et, srcData, transform, betterQuality, (PixelAlpha*)0);
  66410. }
  66411. }
  66412. template <class SrcPixelType>
  66413. void transformedClipImage (EdgeTable& et, const Image::BitmapData& srcData, const AffineTransform& transform, const bool betterQuality, const SrcPixelType *) throw()
  66414. {
  66415. TransformedImageFillEdgeTableRenderer <SrcPixelType, SrcPixelType, false> renderer (srcData, srcData, transform, 255, betterQuality);
  66416. for (int y = 0; y < et.getMaximumBounds().getHeight(); ++y)
  66417. renderer.clipEdgeTableLine (et, et.getMaximumBounds().getX(), y + et.getMaximumBounds().getY(),
  66418. et.getMaximumBounds().getWidth());
  66419. }
  66420. template <class SrcPixelType>
  66421. void straightClipImage (EdgeTable& et, const Image::BitmapData& srcData, int imageX, int imageY, const SrcPixelType *) throw()
  66422. {
  66423. Rectangle<int> r (imageX, imageY, srcData.width, srcData.height);
  66424. et.clipToRectangle (r);
  66425. ImageFillEdgeTableRenderer <SrcPixelType, SrcPixelType, false> renderer (srcData, srcData, 255, imageX, imageY);
  66426. for (int y = 0; y < r.getHeight(); ++y)
  66427. renderer.clipEdgeTableLine (et, r.getX(), y + r.getY(), r.getWidth());
  66428. }
  66429. class EdgeTableHolder : public ReferenceCountedObject
  66430. {
  66431. public:
  66432. EdgeTableHolder (const EdgeTable& e) throw() : edgeTable (e) {}
  66433. EdgeTable edgeTable;
  66434. };
  66435. ReferenceCountedObjectPtr<EdgeTableHolder> edgeTable;
  66436. int xOffset, yOffset;
  66437. Font font;
  66438. FillType fillType;
  66439. Graphics::ResamplingQuality interpolationQuality;
  66440. private:
  66441. LLGCSavedState& operator= (const LLGCSavedState&);
  66442. void dupeEdgeTableIfMultiplyReferenced() throw()
  66443. {
  66444. if (edgeTable->getReferenceCount() > 1)
  66445. edgeTable = new EdgeTableHolder (edgeTable->edgeTable);
  66446. }
  66447. template <class DestPixelType>
  66448. void renderGradient (EdgeTable& et, const Image::BitmapData& destData, const ColourGradient& g, const AffineTransform& transform,
  66449. const PixelARGB* const lookupTable, const int numLookupEntries, const bool isIdentity, DestPixelType*) throw()
  66450. {
  66451. jassert (destData.pixelStride == sizeof (DestPixelType));
  66452. if (g.isRadial)
  66453. {
  66454. if (isIdentity)
  66455. {
  66456. GradientEdgeTableRenderer <DestPixelType, RadialGradientPixelGenerator> renderer (destData, g, transform, lookupTable, numLookupEntries);
  66457. et.iterate (renderer);
  66458. }
  66459. else
  66460. {
  66461. GradientEdgeTableRenderer <DestPixelType, TransformedRadialGradientPixelGenerator> renderer (destData, g, transform, lookupTable, numLookupEntries);
  66462. et.iterate (renderer);
  66463. }
  66464. }
  66465. else
  66466. {
  66467. GradientEdgeTableRenderer <DestPixelType, LinearGradientPixelGenerator> renderer (destData, g, transform, lookupTable, numLookupEntries);
  66468. et.iterate (renderer);
  66469. }
  66470. }
  66471. template <class DestPixelType>
  66472. void renderSolidFill (EdgeTable& et, const Image::BitmapData& destData, const PixelARGB& fillColour, const bool replaceContents, DestPixelType*) throw()
  66473. {
  66474. jassert (destData.pixelStride == sizeof (DestPixelType));
  66475. if (replaceContents)
  66476. {
  66477. SolidColourEdgeTableRenderer <DestPixelType, true> r (destData, fillColour);
  66478. et.iterate (r);
  66479. }
  66480. else
  66481. {
  66482. SolidColourEdgeTableRenderer <DestPixelType, false> r (destData, fillColour);
  66483. et.iterate (r);
  66484. }
  66485. }
  66486. void transformedRenderImage (const Image& srcImage, Image& destImage, const EdgeTable& et, const Image::BitmapData& destData, const Image::BitmapData& srcData,
  66487. const int alpha, const AffineTransform& transform, const bool betterQuality, const bool repeatPattern) throw()
  66488. {
  66489. switch (destImage.getFormat())
  66490. {
  66491. case Image::ARGB:
  66492. switch (srcImage.getFormat())
  66493. {
  66494. case Image::ARGB:
  66495. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelARGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66496. else { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelARGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66497. break;
  66498. case Image::RGB:
  66499. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelRGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66500. else { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelRGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66501. break;
  66502. default:
  66503. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66504. else { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66505. break;
  66506. }
  66507. break;
  66508. case Image::RGB:
  66509. switch (srcImage.getFormat())
  66510. {
  66511. case Image::ARGB:
  66512. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelARGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66513. else { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelARGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66514. break;
  66515. case Image::RGB:
  66516. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelRGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66517. else { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelRGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66518. break;
  66519. default:
  66520. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66521. else { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66522. break;
  66523. }
  66524. break;
  66525. default:
  66526. switch (srcImage.getFormat())
  66527. {
  66528. case Image::ARGB:
  66529. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66530. else { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66531. break;
  66532. case Image::RGB:
  66533. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66534. else { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66535. break;
  66536. default:
  66537. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66538. else { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66539. break;
  66540. }
  66541. break;
  66542. }
  66543. }
  66544. void blittedRenderImage (const Image& srcImage, Image& destImage, const EdgeTable& et, const Image::BitmapData& destData,
  66545. const Image::BitmapData& srcData, const int alpha, int x, int y, const bool repeatPattern) throw()
  66546. {
  66547. switch (destImage.getFormat())
  66548. {
  66549. case Image::ARGB:
  66550. switch (srcImage.getFormat())
  66551. {
  66552. case Image::ARGB:
  66553. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelARGB, PixelARGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66554. else { ImageFillEdgeTableRenderer <PixelARGB, PixelARGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66555. break;
  66556. case Image::RGB:
  66557. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelARGB, PixelRGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66558. else { ImageFillEdgeTableRenderer <PixelARGB, PixelRGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66559. break;
  66560. default:
  66561. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66562. else { ImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66563. break;
  66564. }
  66565. break;
  66566. case Image::RGB:
  66567. switch (srcImage.getFormat())
  66568. {
  66569. case Image::ARGB:
  66570. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelRGB, PixelARGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66571. else { ImageFillEdgeTableRenderer <PixelRGB, PixelARGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66572. break;
  66573. case Image::RGB:
  66574. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelRGB, PixelRGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66575. else { ImageFillEdgeTableRenderer <PixelRGB, PixelRGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66576. break;
  66577. default:
  66578. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66579. else { ImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66580. break;
  66581. }
  66582. break;
  66583. default:
  66584. switch (srcImage.getFormat())
  66585. {
  66586. case Image::ARGB:
  66587. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66588. else { ImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66589. break;
  66590. case Image::RGB:
  66591. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66592. else { ImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66593. break;
  66594. default:
  66595. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66596. else { ImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66597. break;
  66598. }
  66599. break;
  66600. }
  66601. }
  66602. };
  66603. LowLevelGraphicsSoftwareRenderer::LowLevelGraphicsSoftwareRenderer (Image& image_)
  66604. : image (image_)
  66605. {
  66606. currentState = new LLGCSavedState (image_.getBounds(), 0, 0, Font(),
  66607. FillType(), Graphics::mediumResamplingQuality);
  66608. }
  66609. LowLevelGraphicsSoftwareRenderer::~LowLevelGraphicsSoftwareRenderer()
  66610. {
  66611. }
  66612. bool LowLevelGraphicsSoftwareRenderer::isVectorDevice() const
  66613. {
  66614. return false;
  66615. }
  66616. void LowLevelGraphicsSoftwareRenderer::setOrigin (int x, int y)
  66617. {
  66618. currentState->xOffset += x;
  66619. currentState->yOffset += y;
  66620. }
  66621. bool LowLevelGraphicsSoftwareRenderer::clipToRectangle (const Rectangle<int>& r)
  66622. {
  66623. return currentState->clipToRectangle (r);
  66624. }
  66625. bool LowLevelGraphicsSoftwareRenderer::clipToRectangleList (const RectangleList& clipRegion)
  66626. {
  66627. return currentState->clipToRectangleList (clipRegion);
  66628. }
  66629. void LowLevelGraphicsSoftwareRenderer::excludeClipRectangle (const Rectangle<int>& r)
  66630. {
  66631. currentState->excludeClipRectangle (r);
  66632. }
  66633. void LowLevelGraphicsSoftwareRenderer::clipToPath (const Path& path, const AffineTransform& transform)
  66634. {
  66635. currentState->clipToPath (path, transform);
  66636. }
  66637. void LowLevelGraphicsSoftwareRenderer::clipToImageAlpha (const Image& sourceImage, const Rectangle<int>& srcClip, const AffineTransform& transform)
  66638. {
  66639. currentState->clipToImageAlpha (sourceImage, srcClip, transform);
  66640. }
  66641. bool LowLevelGraphicsSoftwareRenderer::clipRegionIntersects (const Rectangle<int>& r)
  66642. {
  66643. return currentState->edgeTable->edgeTable.getMaximumBounds()
  66644. .intersects (r.translated (currentState->xOffset, currentState->yOffset));
  66645. }
  66646. const Rectangle<int> LowLevelGraphicsSoftwareRenderer::getClipBounds() const
  66647. {
  66648. return currentState->edgeTable->edgeTable.getMaximumBounds().translated (-currentState->xOffset, -currentState->yOffset);
  66649. }
  66650. bool LowLevelGraphicsSoftwareRenderer::isClipEmpty() const
  66651. {
  66652. return currentState->edgeTable->edgeTable.isEmpty();
  66653. }
  66654. void LowLevelGraphicsSoftwareRenderer::saveState()
  66655. {
  66656. stateStack.add (new LLGCSavedState (*currentState));
  66657. }
  66658. void LowLevelGraphicsSoftwareRenderer::restoreState()
  66659. {
  66660. LLGCSavedState* const top = stateStack.getLast();
  66661. if (top != 0)
  66662. {
  66663. currentState = top;
  66664. stateStack.removeLast (1, false);
  66665. }
  66666. else
  66667. {
  66668. jassertfalse // trying to pop with an empty stack!
  66669. }
  66670. }
  66671. void LowLevelGraphicsSoftwareRenderer::setFill (const FillType& fillType)
  66672. {
  66673. currentState->fillType = fillType;
  66674. }
  66675. void LowLevelGraphicsSoftwareRenderer::setOpacity (float newOpacity)
  66676. {
  66677. currentState->fillType.setOpacity (newOpacity);
  66678. }
  66679. void LowLevelGraphicsSoftwareRenderer::setInterpolationQuality (Graphics::ResamplingQuality quality)
  66680. {
  66681. currentState->interpolationQuality = quality;
  66682. }
  66683. void LowLevelGraphicsSoftwareRenderer::fillRect (const Rectangle<int>& r, const bool replaceExistingContents)
  66684. {
  66685. const Rectangle<int>& totalClip = currentState->edgeTable->edgeTable.getMaximumBounds();
  66686. const Rectangle<int> clipped (totalClip.getIntersection (r.translated (currentState->xOffset, currentState->yOffset)));
  66687. if (! clipped.isEmpty())
  66688. {
  66689. EdgeTable et (clipped);
  66690. currentState->fillEdgeTable (image, et, replaceExistingContents);
  66691. }
  66692. }
  66693. void LowLevelGraphicsSoftwareRenderer::fillPath (const Path& path, const AffineTransform& transform)
  66694. {
  66695. EdgeTable et (currentState->edgeTable->edgeTable.getMaximumBounds(),
  66696. path, transform.translated ((float) currentState->xOffset,
  66697. (float) currentState->yOffset));
  66698. currentState->fillEdgeTable (image, et);
  66699. }
  66700. void LowLevelGraphicsSoftwareRenderer::drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  66701. const AffineTransform& transform, const bool fillEntireClipAsTiles)
  66702. {
  66703. jassert (sourceImage.getBounds().contains (srcClip));
  66704. currentState->renderImage (image, sourceImage, srcClip, transform,
  66705. fillEntireClipAsTiles ? &(currentState->edgeTable->edgeTable) : 0);
  66706. }
  66707. void LowLevelGraphicsSoftwareRenderer::drawLine (double x1, double y1, double x2, double y2)
  66708. {
  66709. Path p;
  66710. p.addLineSegment ((float) x1, (float) y1, (float) x2, (float) y2, 1.0f);
  66711. fillPath (p, AffineTransform::identity);
  66712. }
  66713. void LowLevelGraphicsSoftwareRenderer::drawVerticalLine (const int x, double top, double bottom)
  66714. {
  66715. if (bottom > top)
  66716. {
  66717. EdgeTable et ((float) (x + currentState->xOffset), (float) (top + currentState->yOffset), 1.0f, (float) (bottom - top));
  66718. currentState->fillEdgeTable (image, et);
  66719. }
  66720. }
  66721. void LowLevelGraphicsSoftwareRenderer::drawHorizontalLine (const int y, double left, double right)
  66722. {
  66723. if (right > left)
  66724. {
  66725. EdgeTable et ((float) (left + currentState->xOffset), (float) (y + currentState->yOffset),
  66726. (float) (right - left), 1.0f);
  66727. currentState->fillEdgeTable (image, et);
  66728. }
  66729. }
  66730. class GlyphCache : private DeletedAtShutdown
  66731. {
  66732. public:
  66733. GlyphCache() throw()
  66734. : accessCounter (0), hits (0), misses (0)
  66735. {
  66736. for (int i = 120; --i >= 0;)
  66737. glyphs.add (new CachedGlyph());
  66738. }
  66739. ~GlyphCache() throw()
  66740. {
  66741. clearSingletonInstance();
  66742. }
  66743. juce_DeclareSingleton_SingleThreaded_Minimal (GlyphCache);
  66744. void drawGlyph (LLGCSavedState& state, Image& image, const Font& font, const int glyphNumber, float x, float y) throw()
  66745. {
  66746. ++accessCounter;
  66747. int oldestCounter = std::numeric_limits<int>::max();
  66748. CachedGlyph* oldest = 0;
  66749. for (int i = glyphs.size(); --i >= 0;)
  66750. {
  66751. CachedGlyph* const glyph = glyphs.getUnchecked (i);
  66752. if (glyph->glyph == glyphNumber && glyph->font == font)
  66753. {
  66754. ++hits;
  66755. glyph->lastAccessCount = accessCounter;
  66756. glyph->draw (state, image, x, y);
  66757. return;
  66758. }
  66759. if (glyph->lastAccessCount <= oldestCounter)
  66760. {
  66761. oldestCounter = glyph->lastAccessCount;
  66762. oldest = glyph;
  66763. }
  66764. }
  66765. if (hits + ++misses > (glyphs.size() << 4))
  66766. {
  66767. if (misses * 2 > hits)
  66768. {
  66769. for (int i = 32; --i >= 0;)
  66770. glyphs.add (new CachedGlyph());
  66771. }
  66772. hits = misses = 0;
  66773. oldest = glyphs.getLast();
  66774. }
  66775. jassert (oldest != 0);
  66776. oldest->lastAccessCount = accessCounter;
  66777. oldest->generate (font, glyphNumber);
  66778. oldest->draw (state, image, x, y);
  66779. }
  66780. class CachedGlyph
  66781. {
  66782. public:
  66783. CachedGlyph() : glyph (0), lastAccessCount (0) {}
  66784. ~CachedGlyph() {}
  66785. void draw (LLGCSavedState& state, Image& image, const float x, const float y) const throw()
  66786. {
  66787. if (edgeTable != 0)
  66788. {
  66789. EdgeTable et (*edgeTable);
  66790. et.translate (x, roundToInt (y));
  66791. state.fillEdgeTable (image, et, false);
  66792. }
  66793. }
  66794. void generate (const Font& newFont, const int glyphNumber) throw()
  66795. {
  66796. font = newFont;
  66797. glyph = glyphNumber;
  66798. edgeTable = 0;
  66799. Path glyphPath;
  66800. font.getTypeface()->getOutlineForGlyph (glyphNumber, glyphPath);
  66801. if (! glyphPath.isEmpty())
  66802. {
  66803. const float fontHeight = font.getHeight();
  66804. const AffineTransform transform (AffineTransform::scale (fontHeight * font.getHorizontalScale(), fontHeight)
  66805. .translated (0.0f, -0.5f));
  66806. edgeTable = new EdgeTable (glyphPath.getBoundsTransformed (transform).getSmallestIntegerContainer().expanded (1, 0),
  66807. glyphPath, transform);
  66808. }
  66809. }
  66810. int glyph, lastAccessCount;
  66811. Font font;
  66812. juce_UseDebuggingNewOperator
  66813. private:
  66814. ScopedPointer <EdgeTable> edgeTable;
  66815. CachedGlyph (const CachedGlyph&);
  66816. CachedGlyph& operator= (const CachedGlyph&);
  66817. };
  66818. juce_UseDebuggingNewOperator
  66819. private:
  66820. OwnedArray <CachedGlyph> glyphs;
  66821. int accessCounter, hits, misses;
  66822. GlyphCache (const GlyphCache&);
  66823. GlyphCache& operator= (const GlyphCache&);
  66824. };
  66825. juce_ImplementSingleton_SingleThreaded (GlyphCache);
  66826. void LowLevelGraphicsSoftwareRenderer::setFont (const Font& newFont)
  66827. {
  66828. currentState->font = newFont;
  66829. }
  66830. const Font LowLevelGraphicsSoftwareRenderer::getFont()
  66831. {
  66832. return currentState->font;
  66833. }
  66834. void LowLevelGraphicsSoftwareRenderer::drawGlyph (int glyphNumber, const AffineTransform& transform)
  66835. {
  66836. Font& f = currentState->font;
  66837. if (transform.isOnlyTranslation())
  66838. {
  66839. GlyphCache::getInstance()->drawGlyph (*currentState, image, f, glyphNumber,
  66840. transform.getTranslationX() + (float) currentState->xOffset,
  66841. transform.getTranslationY() + (float) currentState->yOffset);
  66842. }
  66843. else
  66844. {
  66845. Path p;
  66846. f.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  66847. fillPath (p, AffineTransform::scale (f.getHeight() * f.getHorizontalScale(), f.getHeight()).followedBy (transform));
  66848. }
  66849. }
  66850. #if JUCE_MSVC
  66851. #pragma warning (pop)
  66852. #endif
  66853. END_JUCE_NAMESPACE
  66854. /*** End of inlined file: juce_LowLevelGraphicsSoftwareRenderer.cpp ***/
  66855. /*** Start of inlined file: juce_RectanglePlacement.cpp ***/
  66856. BEGIN_JUCE_NAMESPACE
  66857. RectanglePlacement::RectanglePlacement (const RectanglePlacement& other) throw()
  66858. : flags (other.flags)
  66859. {
  66860. }
  66861. RectanglePlacement& RectanglePlacement::operator= (const RectanglePlacement& other) throw()
  66862. {
  66863. flags = other.flags;
  66864. return *this;
  66865. }
  66866. void RectanglePlacement::applyTo (double& x, double& y,
  66867. double& w, double& h,
  66868. const double dx, const double dy,
  66869. const double dw, const double dh) const throw()
  66870. {
  66871. if (w == 0 || h == 0)
  66872. return;
  66873. if ((flags & stretchToFit) != 0)
  66874. {
  66875. x = dx;
  66876. y = dy;
  66877. w = dw;
  66878. h = dh;
  66879. }
  66880. else
  66881. {
  66882. double scale = (flags & fillDestination) != 0 ? jmax (dw / w, dh / h)
  66883. : jmin (dw / w, dh / h);
  66884. if ((flags & onlyReduceInSize) != 0)
  66885. scale = jmin (scale, 1.0);
  66886. if ((flags & onlyIncreaseInSize) != 0)
  66887. scale = jmax (scale, 1.0);
  66888. w *= scale;
  66889. h *= scale;
  66890. if ((flags & xLeft) != 0)
  66891. x = dx;
  66892. else if ((flags & xRight) != 0)
  66893. x = dx + dw - w;
  66894. else
  66895. x = dx + (dw - w) * 0.5;
  66896. if ((flags & yTop) != 0)
  66897. y = dy;
  66898. else if ((flags & yBottom) != 0)
  66899. y = dy + dh - h;
  66900. else
  66901. y = dy + (dh - h) * 0.5;
  66902. }
  66903. }
  66904. const AffineTransform RectanglePlacement::getTransformToFit (float x, float y,
  66905. float w, float h,
  66906. const float dx, const float dy,
  66907. const float dw, const float dh) const throw()
  66908. {
  66909. if (w == 0 || h == 0)
  66910. return AffineTransform::identity;
  66911. const float scaleX = dw / w;
  66912. const float scaleY = dh / h;
  66913. if ((flags & stretchToFit) != 0)
  66914. return AffineTransform::translation (-x, -y)
  66915. .scaled (scaleX, scaleY)
  66916. .translated (dx, dy);
  66917. float scale = (flags & fillDestination) != 0 ? jmax (scaleX, scaleY)
  66918. : jmin (scaleX, scaleY);
  66919. if ((flags & onlyReduceInSize) != 0)
  66920. scale = jmin (scale, 1.0f);
  66921. if ((flags & onlyIncreaseInSize) != 0)
  66922. scale = jmax (scale, 1.0f);
  66923. w *= scale;
  66924. h *= scale;
  66925. float newX = dx;
  66926. if ((flags & xRight) != 0)
  66927. newX += dw - w; // right
  66928. else if ((flags & xLeft) == 0)
  66929. newX += (dw - w) / 2.0f; // centre
  66930. float newY = dy;
  66931. if ((flags & yBottom) != 0)
  66932. newY += dh - h; // bottom
  66933. else if ((flags & yTop) == 0)
  66934. newY += (dh - h) / 2.0f; // centre
  66935. return AffineTransform::translation (-x, -y)
  66936. .scaled (scale, scale)
  66937. .translated (newX, newY);
  66938. }
  66939. END_JUCE_NAMESPACE
  66940. /*** End of inlined file: juce_RectanglePlacement.cpp ***/
  66941. /*** Start of inlined file: juce_Drawable.cpp ***/
  66942. BEGIN_JUCE_NAMESPACE
  66943. Drawable::RenderingContext::RenderingContext (Graphics& g_,
  66944. const AffineTransform& transform_,
  66945. const float opacity_) throw()
  66946. : g (g_),
  66947. transform (transform_),
  66948. opacity (opacity_)
  66949. {
  66950. }
  66951. Drawable::Drawable()
  66952. {
  66953. }
  66954. Drawable::~Drawable()
  66955. {
  66956. }
  66957. void Drawable::draw (Graphics& g, const float opacity,
  66958. const AffineTransform& transform) const
  66959. {
  66960. render (RenderingContext (g, transform, opacity));
  66961. }
  66962. void Drawable::drawAt (Graphics& g, const float x, const float y, const float opacity) const
  66963. {
  66964. draw (g, opacity, AffineTransform::translation (x, y));
  66965. }
  66966. void Drawable::drawWithin (Graphics& g,
  66967. const int destX,
  66968. const int destY,
  66969. const int destW,
  66970. const int destH,
  66971. const RectanglePlacement& placement,
  66972. const float opacity) const
  66973. {
  66974. if (destW > 0 && destH > 0)
  66975. {
  66976. Rectangle<float> bounds (getBounds());
  66977. draw (g, opacity,
  66978. placement.getTransformToFit (bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight(),
  66979. (float) destX, (float) destY,
  66980. (float) destW, (float) destH));
  66981. }
  66982. }
  66983. Drawable* Drawable::createFromImageData (const void* data, const size_t numBytes)
  66984. {
  66985. Drawable* result = 0;
  66986. Image* const image = ImageFileFormat::loadFrom (data, (int) numBytes);
  66987. if (image != 0)
  66988. {
  66989. DrawableImage* const di = new DrawableImage();
  66990. di->setImage (image, true);
  66991. result = di;
  66992. }
  66993. else
  66994. {
  66995. const String asString (String::createStringFromData (data, (int) numBytes));
  66996. XmlDocument doc (asString);
  66997. ScopedPointer <XmlElement> outer (doc.getDocumentElement (true));
  66998. if (outer != 0 && outer->hasTagName (T("svg")))
  66999. {
  67000. ScopedPointer <XmlElement> svg (doc.getDocumentElement());
  67001. if (svg != 0)
  67002. result = Drawable::createFromSVG (*svg);
  67003. }
  67004. }
  67005. return result;
  67006. }
  67007. Drawable* Drawable::createFromImageDataStream (InputStream& dataSource)
  67008. {
  67009. MemoryBlock mb;
  67010. dataSource.readIntoMemoryBlock (mb);
  67011. return createFromImageData (mb.getData(), mb.getSize());
  67012. }
  67013. Drawable* Drawable::createFromImageFile (const File& file)
  67014. {
  67015. const ScopedPointer <FileInputStream> fin (file.createInputStream());
  67016. return fin != 0 ? createFromImageDataStream (*fin) : 0;
  67017. }
  67018. Drawable* Drawable::createFromValueTree (const ValueTree& tree) throw()
  67019. {
  67020. Drawable* d = DrawablePath::createFromValueTree (tree);
  67021. if (d == 0)
  67022. {
  67023. d = DrawableComposite::createFromValueTree (tree);
  67024. if (d == 0)
  67025. {
  67026. d = DrawableImage::createFromValueTree (tree);
  67027. if (d == 0)
  67028. d = DrawableText::createFromValueTree (tree);
  67029. }
  67030. }
  67031. return d;
  67032. }
  67033. END_JUCE_NAMESPACE
  67034. /*** End of inlined file: juce_Drawable.cpp ***/
  67035. /*** Start of inlined file: juce_DrawableComposite.cpp ***/
  67036. BEGIN_JUCE_NAMESPACE
  67037. DrawableComposite::DrawableComposite()
  67038. {
  67039. }
  67040. DrawableComposite::~DrawableComposite()
  67041. {
  67042. }
  67043. void DrawableComposite::insertDrawable (Drawable* drawable,
  67044. const AffineTransform& transform,
  67045. const int index)
  67046. {
  67047. if (drawable != 0)
  67048. {
  67049. if (! drawables.contains (drawable))
  67050. {
  67051. drawables.insert (index, drawable);
  67052. if (transform.isIdentity())
  67053. transforms.insert (index, 0);
  67054. else
  67055. transforms.insert (index, new AffineTransform (transform));
  67056. }
  67057. else
  67058. {
  67059. jassertfalse // trying to add a drawable that's already in here!
  67060. }
  67061. }
  67062. }
  67063. void DrawableComposite::insertDrawable (const Drawable& drawable,
  67064. const AffineTransform& transform,
  67065. const int index)
  67066. {
  67067. insertDrawable (drawable.createCopy(), transform, index);
  67068. }
  67069. void DrawableComposite::removeDrawable (const int index, const bool deleteDrawable)
  67070. {
  67071. drawables.remove (index, deleteDrawable);
  67072. transforms.remove (index);
  67073. }
  67074. void DrawableComposite::bringToFront (const int index)
  67075. {
  67076. if (index >= 0 && index < drawables.size() - 1)
  67077. {
  67078. drawables.move (index, -1);
  67079. transforms.move (index, -1);
  67080. }
  67081. }
  67082. void DrawableComposite::render (const Drawable::RenderingContext& context) const
  67083. {
  67084. if (drawables.size() > 0 && context.opacity > 0)
  67085. {
  67086. if (context.opacity >= 1.0f || drawables.size() == 1)
  67087. {
  67088. Drawable::RenderingContext contextCopy (context);
  67089. for (int i = 0; i < drawables.size(); ++i)
  67090. {
  67091. const AffineTransform* const t = transforms.getUnchecked(i);
  67092. contextCopy.transform = (t == 0) ? context.transform
  67093. : t->followedBy (context.transform);
  67094. drawables.getUnchecked(i)->render (contextCopy);
  67095. }
  67096. }
  67097. else
  67098. {
  67099. // To correctly render a whole composite layer with an overall transparency,
  67100. // we need to render everything opaquely into a temp buffer, then blend that
  67101. // with the target opacity...
  67102. const Rectangle<int> clipBounds (context.g.getClipBounds());
  67103. Image tempImage (Image::ARGB, clipBounds.getWidth(), clipBounds.getHeight(), true);
  67104. {
  67105. Graphics tempG (tempImage);
  67106. tempG.setOrigin (-clipBounds.getX(), -clipBounds.getY());
  67107. Drawable::RenderingContext tempContext (tempG, context.transform, 1.0f);
  67108. render (tempContext);
  67109. }
  67110. context.g.setOpacity (context.opacity);
  67111. context.g.drawImageAt (&tempImage, clipBounds.getX(), clipBounds.getY());
  67112. }
  67113. }
  67114. }
  67115. const Rectangle<float> DrawableComposite::getBounds() const
  67116. {
  67117. Rectangle<float> bounds;
  67118. for (int i = 0; i < drawables.size(); ++i)
  67119. {
  67120. const Drawable* const d = drawables.getUnchecked(i);
  67121. const AffineTransform* const t = transforms.getUnchecked(i);
  67122. const Rectangle<float> childBounds (t == 0 ? d->getBounds()
  67123. : d->getBounds().transformed (*t));
  67124. if (bounds.isEmpty())
  67125. bounds = childBounds;
  67126. else if (! childBounds.isEmpty())
  67127. bounds = bounds.getUnion (childBounds);
  67128. }
  67129. return bounds;
  67130. }
  67131. bool DrawableComposite::hitTest (float x, float y) const
  67132. {
  67133. for (int i = 0; i < drawables.size(); ++i)
  67134. {
  67135. float tx = x;
  67136. float ty = y;
  67137. const AffineTransform* const t = transforms.getUnchecked(i);
  67138. if (t != 0)
  67139. t->inverted().transformPoint (tx, ty);
  67140. if (drawables.getUnchecked(i)->hitTest (tx, ty))
  67141. return true;
  67142. }
  67143. return false;
  67144. }
  67145. Drawable* DrawableComposite::createCopy() const
  67146. {
  67147. DrawableComposite* const dc = new DrawableComposite();
  67148. for (int i = 0; i < drawables.size(); ++i)
  67149. {
  67150. dc->drawables.add (drawables.getUnchecked(i)->createCopy());
  67151. const AffineTransform* const t = transforms.getUnchecked(i);
  67152. dc->transforms.add (t != 0 ? new AffineTransform (*t) : 0);
  67153. }
  67154. return dc;
  67155. }
  67156. ValueTree DrawableComposite::createValueTree() const throw()
  67157. {
  67158. ValueTree v (T("Group"));
  67159. if (getName().isNotEmpty())
  67160. v.setProperty ("id", getName(), 0);
  67161. for (int i = 0; i < drawables.size(); ++i)
  67162. {
  67163. Drawable* const d = drawables.getUnchecked(i);
  67164. ValueTree child (d->createValueTree());
  67165. AffineTransform* transform = transforms.getUnchecked(i);
  67166. if (transform != 0)
  67167. {
  67168. String t;
  67169. t << transform->mat00 << " " << transform->mat01 << " " << transform->mat02 << " "
  67170. << transform->mat10 << " " << transform->mat11 << " " << transform->mat12;
  67171. child.setProperty ("transform", t, 0);
  67172. }
  67173. v.addChild (child, -1, 0);
  67174. }
  67175. return v;
  67176. }
  67177. DrawableComposite* DrawableComposite::createFromValueTree (const ValueTree& tree) throw()
  67178. {
  67179. if (! tree.hasType ("Group"))
  67180. return 0;
  67181. DrawableComposite* dc = new DrawableComposite();
  67182. dc->setName (tree ["id"]);
  67183. for (int i = 0; i < tree.getNumChildren(); ++i)
  67184. {
  67185. ValueTree childTree (tree.getChild (i));
  67186. Drawable* d = Drawable::createFromValueTree (childTree);
  67187. if (d != 0)
  67188. {
  67189. AffineTransform transform;
  67190. const String transformAtt (childTree ["transform"].toString());
  67191. if (transformAtt.isNotEmpty())
  67192. {
  67193. StringArray tokens;
  67194. tokens.addTokens (transformAtt.trim(), false);
  67195. tokens.removeEmptyStrings (true);
  67196. if (tokens.size() == 6)
  67197. {
  67198. float f[6];
  67199. for (int j = 0; j < 6; ++j)
  67200. f[j] = (float) tokens[j].getDoubleValue();
  67201. transform = AffineTransform (f[0], f[1], f[2], f[3], f[4], f[5]);
  67202. }
  67203. }
  67204. dc->insertDrawable (d, transform);
  67205. }
  67206. }
  67207. return dc;
  67208. }
  67209. END_JUCE_NAMESPACE
  67210. /*** End of inlined file: juce_DrawableComposite.cpp ***/
  67211. /*** Start of inlined file: juce_DrawableImage.cpp ***/
  67212. BEGIN_JUCE_NAMESPACE
  67213. DrawableImage::DrawableImage()
  67214. : image (0),
  67215. canDeleteImage (false),
  67216. opacity (1.0f),
  67217. overlayColour (0x00000000)
  67218. {
  67219. }
  67220. DrawableImage::~DrawableImage()
  67221. {
  67222. clearImage();
  67223. }
  67224. void DrawableImage::clearImage()
  67225. {
  67226. if (canDeleteImage && image != 0)
  67227. ImageCache::releaseOrDelete (image);
  67228. image = 0;
  67229. }
  67230. void DrawableImage::setImage (const Image& imageToCopy)
  67231. {
  67232. clearImage();
  67233. image = new Image (imageToCopy);
  67234. canDeleteImage = true;
  67235. }
  67236. void DrawableImage::setImage (Image* imageToUse,
  67237. const bool releaseWhenNotNeeded)
  67238. {
  67239. clearImage();
  67240. image = imageToUse;
  67241. canDeleteImage = releaseWhenNotNeeded;
  67242. }
  67243. void DrawableImage::setOpacity (const float newOpacity)
  67244. {
  67245. opacity = newOpacity;
  67246. }
  67247. void DrawableImage::setOverlayColour (const Colour& newOverlayColour)
  67248. {
  67249. overlayColour = newOverlayColour;
  67250. }
  67251. void DrawableImage::render (const Drawable::RenderingContext& context) const
  67252. {
  67253. if (image != 0)
  67254. {
  67255. if (opacity > 0.0f && ! overlayColour.isOpaque())
  67256. {
  67257. context.g.setOpacity (context.opacity * opacity);
  67258. context.g.drawImageTransformed (image, image->getBounds(),
  67259. context.transform, false);
  67260. }
  67261. if (! overlayColour.isTransparent())
  67262. {
  67263. context.g.setColour (overlayColour.withMultipliedAlpha (context.opacity));
  67264. context.g.drawImageTransformed (image, image->getBounds(),
  67265. context.transform, true);
  67266. }
  67267. }
  67268. }
  67269. const Rectangle<float> DrawableImage::getBounds() const
  67270. {
  67271. if (image == 0)
  67272. return Rectangle<float>();
  67273. return Rectangle<float> (0, 0, (float) image->getWidth(), (float) image->getHeight());
  67274. }
  67275. bool DrawableImage::hitTest (float x, float y) const
  67276. {
  67277. return image != 0
  67278. && x >= 0.0f
  67279. && y >= 0.0f
  67280. && x < image->getWidth()
  67281. && y < image->getHeight()
  67282. && image->getPixelAt (roundToInt (x), roundToInt (y)).getAlpha() >= 127;
  67283. }
  67284. Drawable* DrawableImage::createCopy() const
  67285. {
  67286. DrawableImage* const di = new DrawableImage();
  67287. di->opacity = opacity;
  67288. di->overlayColour = overlayColour;
  67289. if (image != 0)
  67290. {
  67291. if ((! canDeleteImage) || ! ImageCache::isImageInCache (image))
  67292. {
  67293. di->setImage (*image);
  67294. }
  67295. else
  67296. {
  67297. ImageCache::incReferenceCount (image);
  67298. di->setImage (image, true);
  67299. }
  67300. }
  67301. return di;
  67302. }
  67303. ValueTree DrawableImage::createValueTree() const throw()
  67304. {
  67305. ValueTree v (T("Image"));
  67306. if (getName().isNotEmpty())
  67307. v.setProperty ("id", getName(), 0);
  67308. if (opacity < 1.0f)
  67309. v.setProperty ("opacity", (double) opacity, 0);
  67310. if (! overlayColour.isTransparent())
  67311. v.setProperty ("overlay", String::toHexString ((int) overlayColour.getARGB()), 0);
  67312. if (image != 0)
  67313. {
  67314. MemoryOutputStream imageData;
  67315. PNGImageFormat pngFormat;
  67316. if (pngFormat.writeImageToStream (*image, imageData))
  67317. {
  67318. String base64 (MemoryBlock (imageData.getData(), imageData.getDataSize()).toBase64Encoding());
  67319. for (int i = (base64.length() & ~127); i >= 0; i -= 128)
  67320. base64 = base64.substring (0, i) + "\n" + base64.substring (i);
  67321. v.setProperty ("data", base64, 0);
  67322. }
  67323. }
  67324. return v;
  67325. }
  67326. DrawableImage* DrawableImage::createFromValueTree (const ValueTree& tree) throw()
  67327. {
  67328. if (! tree.hasType ("Image"))
  67329. return 0;
  67330. DrawableImage* di = new DrawableImage();
  67331. di->setName (tree ["id"]);
  67332. di->opacity = tree.hasProperty ("opacity") ? (float) tree ["opacity"] : 1.0f;
  67333. di->overlayColour = Colour (tree ["overlay"].toString().getHexValue32());
  67334. MemoryBlock imageData;
  67335. if (imageData.fromBase64Encoding (tree ["data"]))
  67336. {
  67337. Image* const im = ImageFileFormat::loadFrom (imageData.getData(), (int) imageData.getSize());
  67338. if (im == 0)
  67339. return false;
  67340. di->setImage (im, true);
  67341. }
  67342. return di;
  67343. }
  67344. END_JUCE_NAMESPACE
  67345. /*** End of inlined file: juce_DrawableImage.cpp ***/
  67346. /*** Start of inlined file: juce_DrawablePath.cpp ***/
  67347. BEGIN_JUCE_NAMESPACE
  67348. DrawablePath::DrawablePath()
  67349. : mainFill (FillType (Colours::black)),
  67350. strokeFill (FillType (Colours::transparentBlack)),
  67351. strokeType (0.0f)
  67352. {
  67353. }
  67354. DrawablePath::~DrawablePath()
  67355. {
  67356. }
  67357. void DrawablePath::setPath (const Path& newPath) throw()
  67358. {
  67359. path = newPath;
  67360. updateOutline();
  67361. }
  67362. void DrawablePath::setFill (const FillType& newFill) throw()
  67363. {
  67364. mainFill = newFill;
  67365. }
  67366. void DrawablePath::setStrokeFill (const FillType& newFill) throw()
  67367. {
  67368. strokeFill = newFill;
  67369. }
  67370. void DrawablePath::setStrokeType (const PathStrokeType& newStrokeType) throw()
  67371. {
  67372. strokeType = newStrokeType;
  67373. updateOutline();
  67374. }
  67375. void DrawablePath::setStrokeThickness (const float newThickness) throw()
  67376. {
  67377. setStrokeType (PathStrokeType (newThickness, strokeType.getJointStyle(), strokeType.getEndStyle()));
  67378. }
  67379. void DrawablePath::render (const Drawable::RenderingContext& context) const
  67380. {
  67381. {
  67382. FillType f (mainFill);
  67383. if (f.isGradient())
  67384. f.gradient->multiplyOpacity (context.opacity);
  67385. f.transform = f.transform.followedBy (context.transform);
  67386. context.g.setFillType (f);
  67387. context.g.fillPath (path, context.transform);
  67388. }
  67389. if (strokeType.getStrokeThickness() > 0.0f)
  67390. {
  67391. FillType f (strokeFill);
  67392. if (f.isGradient())
  67393. f.gradient->multiplyOpacity (context.opacity);
  67394. f.transform = f.transform.followedBy (context.transform);
  67395. context.g.setFillType (f);
  67396. context.g.fillPath (stroke, context.transform);
  67397. }
  67398. }
  67399. void DrawablePath::updateOutline()
  67400. {
  67401. stroke.clear();
  67402. strokeType.createStrokedPath (stroke, path, AffineTransform::identity, 4.0f);
  67403. }
  67404. const Rectangle<float> DrawablePath::getBounds() const
  67405. {
  67406. if (strokeType.getStrokeThickness() > 0.0f)
  67407. return stroke.getBounds();
  67408. else
  67409. return path.getBounds();
  67410. }
  67411. bool DrawablePath::hitTest (float x, float y) const
  67412. {
  67413. return path.contains (x, y)
  67414. || stroke.contains (x, y);
  67415. }
  67416. Drawable* DrawablePath::createCopy() const
  67417. {
  67418. DrawablePath* const dp = new DrawablePath();
  67419. dp->path = path;
  67420. dp->stroke = stroke;
  67421. dp->mainFill = mainFill;
  67422. dp->strokeFill = strokeFill;
  67423. dp->strokeType = strokeType;
  67424. return dp;
  67425. }
  67426. static const FillType readFillTypeFromTree (const ValueTree& v)
  67427. {
  67428. const String type (v["type"].toString());
  67429. if (type.equalsIgnoreCase (T("solid")))
  67430. {
  67431. const String colour (v ["colour"].toString());
  67432. return FillType (Colour (colour.isEmpty() ? (uint32) 0xff000000
  67433. : (uint32) colour.getHexValue32()));
  67434. }
  67435. else if (type.equalsIgnoreCase ("gradient"))
  67436. {
  67437. ColourGradient g;
  67438. g.x1 = v["x1"];
  67439. g.y1 = v["y1"];
  67440. g.x2 = v["x2"];
  67441. g.y2 = v["y2"];
  67442. g.isRadial = v["radial"];
  67443. StringArray colours;
  67444. colours.addTokens (v["colours"].toString(), false);
  67445. for (int i = 0; i < colours.size() / 2; ++i)
  67446. g.addColour (colours[i * 2].getDoubleValue(),
  67447. Colour ((uint32) colours[i * 2 + 1].getHexValue32()));
  67448. return FillType (g);
  67449. }
  67450. jassertfalse
  67451. return FillType();
  67452. }
  67453. static ValueTree createTreeForFillType (const String& tagName, const FillType& fillType)
  67454. {
  67455. ValueTree v (tagName);
  67456. if (fillType.isColour())
  67457. {
  67458. v.setProperty ("type", T("solid"), 0);
  67459. v.setProperty ("colour", String::toHexString ((int) fillType.colour.getARGB()), 0);
  67460. }
  67461. else if (fillType.isGradient())
  67462. {
  67463. v.setProperty ("type", T("gradient"), 0);
  67464. v.setProperty ("x1", fillType.gradient->x1, 0);
  67465. v.setProperty ("y1", fillType.gradient->y1, 0);
  67466. v.setProperty ("x2", fillType.gradient->x2, 0);
  67467. v.setProperty ("y2", fillType.gradient->y2, 0);
  67468. v.setProperty ("radial", fillType.gradient->isRadial, 0);
  67469. String s;
  67470. for (int i = 0; i < fillType.gradient->getNumColours(); ++i)
  67471. s << " " << fillType.gradient->getColourPosition (i)
  67472. << " " << String::toHexString ((int) fillType.gradient->getColour(i).getARGB());
  67473. v.setProperty ("colours", s.trimStart(), 0);
  67474. }
  67475. else
  67476. {
  67477. jassertfalse //xxx
  67478. }
  67479. return v;
  67480. }
  67481. ValueTree DrawablePath::createValueTree() const throw()
  67482. {
  67483. ValueTree v (T("Path"));
  67484. v.addChild (createTreeForFillType (T("fill"), mainFill), -1, 0);
  67485. v.addChild (createTreeForFillType (T("stroke"), strokeFill), -1, 0);
  67486. if (getName().isNotEmpty())
  67487. v.setProperty ("id", getName(), 0);
  67488. v.setProperty ("strokeWidth", (double) strokeType.getStrokeThickness(), 0);
  67489. v.setProperty ("jointStyle", strokeType.getJointStyle() == PathStrokeType::mitered
  67490. ? T("miter") : (strokeType.getJointStyle() == PathStrokeType::curved ? T("curved") : T("bevel")), 0);
  67491. v.setProperty ("capStyle", strokeType.getEndStyle() == PathStrokeType::butt
  67492. ? T("butt") : (strokeType.getEndStyle() == PathStrokeType::square ? T("square") : T("round")), 0);
  67493. v.setProperty ("path", path.toString(), 0);
  67494. return v;
  67495. }
  67496. DrawablePath* DrawablePath::createFromValueTree (const ValueTree& tree) throw()
  67497. {
  67498. if (! tree.hasType ("Path"))
  67499. return 0;
  67500. DrawablePath* p = new DrawablePath();
  67501. p->setName (tree ["id"]);
  67502. p->mainFill = readFillTypeFromTree (tree.getChildWithName (T("fill")));
  67503. p->strokeFill = readFillTypeFromTree (tree.getChildWithName (T("stroke")));
  67504. const String jointStyle (tree ["jointStyle"].toString());
  67505. const String endStyle (tree ["capStyle"].toString());
  67506. p->strokeType
  67507. = PathStrokeType (tree ["strokeWidth"],
  67508. jointStyle.equalsIgnoreCase (T("curved")) ? PathStrokeType::curved
  67509. : (jointStyle.equalsIgnoreCase (T("bevel")) ? PathStrokeType::beveled
  67510. : PathStrokeType::mitered),
  67511. endStyle.equalsIgnoreCase (T("square")) ? PathStrokeType::square
  67512. : (endStyle.equalsIgnoreCase (T("round")) ? PathStrokeType::rounded
  67513. : PathStrokeType::butt));
  67514. p->path.clear();
  67515. p->path.restoreFromString (tree ["path"]);
  67516. p->updateOutline();
  67517. return p;
  67518. }
  67519. END_JUCE_NAMESPACE
  67520. /*** End of inlined file: juce_DrawablePath.cpp ***/
  67521. /*** Start of inlined file: juce_DrawableText.cpp ***/
  67522. BEGIN_JUCE_NAMESPACE
  67523. DrawableText::DrawableText()
  67524. : colour (Colours::white)
  67525. {
  67526. }
  67527. DrawableText::~DrawableText()
  67528. {
  67529. }
  67530. void DrawableText::setText (const GlyphArrangement& newText)
  67531. {
  67532. text = newText;
  67533. }
  67534. void DrawableText::setText (const String& newText, const Font& fontToUse)
  67535. {
  67536. text.clear();
  67537. text.addLineOfText (fontToUse, newText, 0.0f, 0.0f);
  67538. }
  67539. void DrawableText::setColour (const Colour& newColour)
  67540. {
  67541. colour = newColour;
  67542. }
  67543. void DrawableText::render (const Drawable::RenderingContext& context) const
  67544. {
  67545. context.g.setColour (colour.withMultipliedAlpha (context.opacity));
  67546. text.draw (context.g, context.transform);
  67547. }
  67548. const Rectangle<float> DrawableText::getBounds() const
  67549. {
  67550. float x, y, w, h;
  67551. text.getBoundingBox (0, -1, x, y, w, h, false); // (really returns top, left, bottom, right)
  67552. w -= x;
  67553. h -= y;
  67554. return Rectangle<float> (x, y, w, h);
  67555. }
  67556. bool DrawableText::hitTest (float x, float y) const
  67557. {
  67558. return text.findGlyphIndexAt (x, y) >= 0;
  67559. }
  67560. Drawable* DrawableText::createCopy() const
  67561. {
  67562. DrawableText* const dt = new DrawableText();
  67563. dt->text = text;
  67564. dt->colour = colour;
  67565. return dt;
  67566. }
  67567. ValueTree DrawableText::createValueTree() const throw()
  67568. {
  67569. ValueTree v (T("Text"));
  67570. if (getName().isNotEmpty())
  67571. v.setProperty ("id", getName(), 0);
  67572. jassertfalse // xxx not finished!
  67573. return v;
  67574. }
  67575. DrawableText* DrawableText::createFromValueTree (const ValueTree& tree) throw()
  67576. {
  67577. if (! tree.hasType ("Text"))
  67578. return 0;
  67579. DrawableText* dt = new DrawableText();
  67580. dt->setName (tree ["id"]);
  67581. jassertfalse // xxx not finished!
  67582. return dt;
  67583. }
  67584. END_JUCE_NAMESPACE
  67585. /*** End of inlined file: juce_DrawableText.cpp ***/
  67586. /*** Start of inlined file: juce_SVGParser.cpp ***/
  67587. BEGIN_JUCE_NAMESPACE
  67588. class SVGState
  67589. {
  67590. public:
  67591. SVGState (const XmlElement* const topLevel)
  67592. : topLevelXml (topLevel),
  67593. elementX (0), elementY (0),
  67594. width (512), height (512),
  67595. viewBoxW (0), viewBoxH (0)
  67596. {
  67597. }
  67598. ~SVGState()
  67599. {
  67600. }
  67601. Drawable* parseSVGElement (const XmlElement& xml)
  67602. {
  67603. if (! xml.hasTagName (T("svg")))
  67604. return 0;
  67605. DrawableComposite* const drawable = new DrawableComposite();
  67606. drawable->setName (xml.getStringAttribute (T("id")));
  67607. SVGState newState (*this);
  67608. if (xml.hasAttribute (T("transform")))
  67609. newState.addTransform (xml);
  67610. newState.elementX = getCoordLength (xml.getStringAttribute (T("x"), String (newState.elementX)), viewBoxW);
  67611. newState.elementY = getCoordLength (xml.getStringAttribute (T("y"), String (newState.elementY)), viewBoxH);
  67612. newState.width = getCoordLength (xml.getStringAttribute (T("width"), String (newState.width)), viewBoxW);
  67613. newState.height = getCoordLength (xml.getStringAttribute (T("height"), String (newState.height)), viewBoxH);
  67614. if (xml.hasAttribute (T("viewBox")))
  67615. {
  67616. const String viewParams (xml.getStringAttribute (T("viewBox")));
  67617. int i = 0;
  67618. float vx, vy, vw, vh;
  67619. if (parseCoords (viewParams, vx, vy, i, true)
  67620. && parseCoords (viewParams, vw, vh, i, true)
  67621. && vw > 0
  67622. && vh > 0)
  67623. {
  67624. newState.viewBoxW = vw;
  67625. newState.viewBoxH = vh;
  67626. int placementFlags = 0;
  67627. const String aspect (xml.getStringAttribute (T("preserveAspectRatio")));
  67628. if (aspect.containsIgnoreCase (T("none")))
  67629. {
  67630. placementFlags = RectanglePlacement::stretchToFit;
  67631. }
  67632. else
  67633. {
  67634. if (aspect.containsIgnoreCase (T("slice")))
  67635. placementFlags |= RectanglePlacement::fillDestination;
  67636. if (aspect.containsIgnoreCase (T("xMin")))
  67637. placementFlags |= RectanglePlacement::xLeft;
  67638. else if (aspect.containsIgnoreCase (T("xMax")))
  67639. placementFlags |= RectanglePlacement::xRight;
  67640. else
  67641. placementFlags |= RectanglePlacement::xMid;
  67642. if (aspect.containsIgnoreCase (T("yMin")))
  67643. placementFlags |= RectanglePlacement::yTop;
  67644. else if (aspect.containsIgnoreCase (T("yMax")))
  67645. placementFlags |= RectanglePlacement::yBottom;
  67646. else
  67647. placementFlags |= RectanglePlacement::yMid;
  67648. }
  67649. const RectanglePlacement placement (placementFlags);
  67650. newState.transform
  67651. = placement.getTransformToFit (vx, vy, vw, vh,
  67652. 0.0f, 0.0f, newState.width, newState.height)
  67653. .followedBy (newState.transform);
  67654. }
  67655. }
  67656. else
  67657. {
  67658. if (viewBoxW == 0)
  67659. newState.viewBoxW = newState.width;
  67660. if (viewBoxH == 0)
  67661. newState.viewBoxH = newState.height;
  67662. }
  67663. newState.parseSubElements (xml, drawable);
  67664. return drawable;
  67665. }
  67666. private:
  67667. const XmlElement* const topLevelXml;
  67668. float elementX, elementY, width, height, viewBoxW, viewBoxH;
  67669. AffineTransform transform;
  67670. String cssStyleText;
  67671. void parseSubElements (const XmlElement& xml, DrawableComposite* const parentDrawable)
  67672. {
  67673. forEachXmlChildElement (xml, e)
  67674. {
  67675. Drawable* d = 0;
  67676. if (e->hasTagName (T("g")))
  67677. d = parseGroupElement (*e);
  67678. else if (e->hasTagName (T("svg")))
  67679. d = parseSVGElement (*e);
  67680. else if (e->hasTagName (T("path")))
  67681. d = parsePath (*e);
  67682. else if (e->hasTagName (T("rect")))
  67683. d = parseRect (*e);
  67684. else if (e->hasTagName (T("circle")))
  67685. d = parseCircle (*e);
  67686. else if (e->hasTagName (T("ellipse")))
  67687. d = parseEllipse (*e);
  67688. else if (e->hasTagName (T("line")))
  67689. d = parseLine (*e);
  67690. else if (e->hasTagName (T("polyline")))
  67691. d = parsePolygon (*e, true);
  67692. else if (e->hasTagName (T("polygon")))
  67693. d = parsePolygon (*e, false);
  67694. else if (e->hasTagName (T("text")))
  67695. d = parseText (*e);
  67696. else if (e->hasTagName (T("switch")))
  67697. d = parseSwitch (*e);
  67698. else if (e->hasTagName (T("style")))
  67699. parseCSSStyle (*e);
  67700. parentDrawable->insertDrawable (d);
  67701. }
  67702. }
  67703. DrawableComposite* parseSwitch (const XmlElement& xml)
  67704. {
  67705. const XmlElement* const group = xml.getChildByName (T("g"));
  67706. if (group != 0)
  67707. return parseGroupElement (*group);
  67708. return 0;
  67709. }
  67710. DrawableComposite* parseGroupElement (const XmlElement& xml)
  67711. {
  67712. DrawableComposite* const drawable = new DrawableComposite();
  67713. drawable->setName (xml.getStringAttribute (T("id")));
  67714. if (xml.hasAttribute (T("transform")))
  67715. {
  67716. SVGState newState (*this);
  67717. newState.addTransform (xml);
  67718. newState.parseSubElements (xml, drawable);
  67719. }
  67720. else
  67721. {
  67722. parseSubElements (xml, drawable);
  67723. }
  67724. return drawable;
  67725. }
  67726. Drawable* parsePath (const XmlElement& xml) const
  67727. {
  67728. const String d (xml.getStringAttribute (T("d")).trimStart());
  67729. Path path;
  67730. if (getStyleAttribute (&xml, T("fill-rule")).trim().equalsIgnoreCase (T("evenodd")))
  67731. path.setUsingNonZeroWinding (false);
  67732. int index = 0;
  67733. float lastX = 0, lastY = 0;
  67734. float lastX2 = 0, lastY2 = 0;
  67735. tchar lastCommandChar = 0;
  67736. bool isRelative = true;
  67737. bool carryOn = true;
  67738. const String validCommandChars (T("MmLlHhVvCcSsQqTtAaZz"));
  67739. for (;;)
  67740. {
  67741. float x, y, x2, y2, x3, y3;
  67742. if (validCommandChars.containsChar (d[index]))
  67743. {
  67744. lastCommandChar = d [index++];
  67745. isRelative = (lastCommandChar >= 'a' && lastCommandChar <= 'z');
  67746. }
  67747. switch (lastCommandChar)
  67748. {
  67749. case T('M'):
  67750. case T('m'):
  67751. case T('L'):
  67752. case T('l'):
  67753. if (parseCoords (d, x, y, index, false))
  67754. {
  67755. if (isRelative)
  67756. {
  67757. x += lastX;
  67758. y += lastY;
  67759. }
  67760. if (lastCommandChar == T('M') || lastCommandChar == T('m'))
  67761. path.startNewSubPath (x, y);
  67762. else
  67763. path.lineTo (x, y);
  67764. lastX2 = lastX;
  67765. lastY2 = lastY;
  67766. lastX = x;
  67767. lastY = y;
  67768. }
  67769. else
  67770. {
  67771. ++index;
  67772. }
  67773. break;
  67774. case T('H'):
  67775. case T('h'):
  67776. if (parseCoord (d, x, index, false, true))
  67777. {
  67778. if (isRelative)
  67779. x += lastX;
  67780. path.lineTo (x, lastY);
  67781. lastX2 = lastX;
  67782. lastX = x;
  67783. }
  67784. else
  67785. {
  67786. ++index;
  67787. }
  67788. break;
  67789. case T('V'):
  67790. case T('v'):
  67791. if (parseCoord (d, y, index, false, false))
  67792. {
  67793. if (isRelative)
  67794. y += lastY;
  67795. path.lineTo (lastX, y);
  67796. lastY2 = lastY;
  67797. lastY = y;
  67798. }
  67799. else
  67800. {
  67801. ++index;
  67802. }
  67803. break;
  67804. case T('C'):
  67805. case T('c'):
  67806. if (parseCoords (d, x, y, index, false)
  67807. && parseCoords (d, x2, y2, index, false)
  67808. && parseCoords (d, x3, y3, index, false))
  67809. {
  67810. if (isRelative)
  67811. {
  67812. x += lastX;
  67813. y += lastY;
  67814. x2 += lastX;
  67815. y2 += lastY;
  67816. x3 += lastX;
  67817. y3 += lastY;
  67818. }
  67819. path.cubicTo (x, y, x2, y2, x3, y3);
  67820. lastX2 = x2;
  67821. lastY2 = y2;
  67822. lastX = x3;
  67823. lastY = y3;
  67824. }
  67825. else
  67826. {
  67827. ++index;
  67828. }
  67829. break;
  67830. case T('S'):
  67831. case T('s'):
  67832. if (parseCoords (d, x, y, index, false)
  67833. && parseCoords (d, x3, y3, index, false))
  67834. {
  67835. if (isRelative)
  67836. {
  67837. x += lastX;
  67838. y += lastY;
  67839. x3 += lastX;
  67840. y3 += lastY;
  67841. }
  67842. x2 = lastX + (lastX - lastX2);
  67843. y2 = lastY + (lastY - lastY2);
  67844. path.cubicTo (x2, y2, x, y, x3, y3);
  67845. lastX2 = x;
  67846. lastY2 = y;
  67847. lastX = x3;
  67848. lastY = y3;
  67849. }
  67850. else
  67851. {
  67852. ++index;
  67853. }
  67854. break;
  67855. case T('Q'):
  67856. case T('q'):
  67857. if (parseCoords (d, x, y, index, false)
  67858. && parseCoords (d, x2, y2, index, false))
  67859. {
  67860. if (isRelative)
  67861. {
  67862. x += lastX;
  67863. y += lastY;
  67864. x2 += lastX;
  67865. y2 += lastY;
  67866. }
  67867. path.quadraticTo (x, y, x2, y2);
  67868. lastX2 = x;
  67869. lastY2 = y;
  67870. lastX = x2;
  67871. lastY = y2;
  67872. }
  67873. else
  67874. {
  67875. ++index;
  67876. }
  67877. break;
  67878. case T('T'):
  67879. case T('t'):
  67880. if (parseCoords (d, x, y, index, false))
  67881. {
  67882. if (isRelative)
  67883. {
  67884. x += lastX;
  67885. y += lastY;
  67886. }
  67887. x2 = lastX + (lastX - lastX2);
  67888. y2 = lastY + (lastY - lastY2);
  67889. path.quadraticTo (x2, y2, x, y);
  67890. lastX2 = x2;
  67891. lastY2 = y2;
  67892. lastX = x;
  67893. lastY = y;
  67894. }
  67895. else
  67896. {
  67897. ++index;
  67898. }
  67899. break;
  67900. case T('A'):
  67901. case T('a'):
  67902. if (parseCoords (d, x, y, index, false))
  67903. {
  67904. String num;
  67905. if (parseNextNumber (d, num, index, false))
  67906. {
  67907. const float angle = num.getFloatValue() * (180.0f / float_Pi);
  67908. if (parseNextNumber (d, num, index, false))
  67909. {
  67910. const bool largeArc = num.getIntValue() != 0;
  67911. if (parseNextNumber (d, num, index, false))
  67912. {
  67913. const bool sweep = num.getIntValue() != 0;
  67914. if (parseCoords (d, x2, y2, index, false))
  67915. {
  67916. if (isRelative)
  67917. {
  67918. x2 += lastX;
  67919. y2 += lastY;
  67920. }
  67921. if (lastX != x2 || lastY != y2)
  67922. {
  67923. double centreX, centreY, startAngle, deltaAngle;
  67924. double rx = x, ry = y;
  67925. endpointToCentreParameters (lastX, lastY, x2, y2,
  67926. angle, largeArc, sweep,
  67927. rx, ry, centreX, centreY,
  67928. startAngle, deltaAngle);
  67929. path.addCentredArc ((float) centreX, (float) centreY,
  67930. (float) rx, (float) ry,
  67931. angle, (float) startAngle, (float) (startAngle + deltaAngle),
  67932. false);
  67933. path.lineTo (x2, y2);
  67934. }
  67935. lastX2 = lastX;
  67936. lastY2 = lastY;
  67937. lastX = x2;
  67938. lastY = y2;
  67939. }
  67940. }
  67941. }
  67942. }
  67943. }
  67944. else
  67945. {
  67946. ++index;
  67947. }
  67948. break;
  67949. case T('Z'):
  67950. case T('z'):
  67951. path.closeSubPath();
  67952. while (CharacterFunctions::isWhitespace (d [index]))
  67953. ++index;
  67954. break;
  67955. default:
  67956. carryOn = false;
  67957. break;
  67958. }
  67959. if (! carryOn)
  67960. break;
  67961. }
  67962. return parseShape (xml, path);
  67963. }
  67964. Drawable* parseRect (const XmlElement& xml) const
  67965. {
  67966. Path rect;
  67967. const bool hasRX = xml.hasAttribute (T("rx"));
  67968. const bool hasRY = xml.hasAttribute (T("ry"));
  67969. if (hasRX || hasRY)
  67970. {
  67971. float rx = getCoordLength (xml.getStringAttribute (T("rx")), viewBoxW);
  67972. float ry = getCoordLength (xml.getStringAttribute (T("ry")), viewBoxH);
  67973. if (! hasRX)
  67974. rx = ry;
  67975. else if (! hasRY)
  67976. ry = rx;
  67977. rect.addRoundedRectangle (getCoordLength (xml.getStringAttribute (T("x")), viewBoxW),
  67978. getCoordLength (xml.getStringAttribute (T("y")), viewBoxH),
  67979. getCoordLength (xml.getStringAttribute (T("width")), viewBoxW),
  67980. getCoordLength (xml.getStringAttribute (T("height")), viewBoxH),
  67981. rx, ry);
  67982. }
  67983. else
  67984. {
  67985. rect.addRectangle (getCoordLength (xml.getStringAttribute (T("x")), viewBoxW),
  67986. getCoordLength (xml.getStringAttribute (T("y")), viewBoxH),
  67987. getCoordLength (xml.getStringAttribute (T("width")), viewBoxW),
  67988. getCoordLength (xml.getStringAttribute (T("height")), viewBoxH));
  67989. }
  67990. return parseShape (xml, rect);
  67991. }
  67992. Drawable* parseCircle (const XmlElement& xml) const
  67993. {
  67994. Path circle;
  67995. const float cx = getCoordLength (xml.getStringAttribute (T("cx")), viewBoxW);
  67996. const float cy = getCoordLength (xml.getStringAttribute (T("cy")), viewBoxH);
  67997. const float radius = getCoordLength (xml.getStringAttribute (T("r")), viewBoxW);
  67998. circle.addEllipse (cx - radius, cy - radius, radius * 2.0f, radius * 2.0f);
  67999. return parseShape (xml, circle);
  68000. }
  68001. Drawable* parseEllipse (const XmlElement& xml) const
  68002. {
  68003. Path ellipse;
  68004. const float cx = getCoordLength (xml.getStringAttribute (T("cx")), viewBoxW);
  68005. const float cy = getCoordLength (xml.getStringAttribute (T("cy")), viewBoxH);
  68006. const float radiusX = getCoordLength (xml.getStringAttribute (T("rx")), viewBoxW);
  68007. const float radiusY = getCoordLength (xml.getStringAttribute (T("ry")), viewBoxH);
  68008. ellipse.addEllipse (cx - radiusX, cy - radiusY, radiusX * 2.0f, radiusY * 2.0f);
  68009. return parseShape (xml, ellipse);
  68010. }
  68011. Drawable* parseLine (const XmlElement& xml) const
  68012. {
  68013. Path line;
  68014. const float x1 = getCoordLength (xml.getStringAttribute (T("x1")), viewBoxW);
  68015. const float y1 = getCoordLength (xml.getStringAttribute (T("y1")), viewBoxH);
  68016. const float x2 = getCoordLength (xml.getStringAttribute (T("x2")), viewBoxW);
  68017. const float y2 = getCoordLength (xml.getStringAttribute (T("y2")), viewBoxH);
  68018. line.startNewSubPath (x1, y1);
  68019. line.lineTo (x2, y2);
  68020. return parseShape (xml, line);
  68021. }
  68022. Drawable* parsePolygon (const XmlElement& xml, const bool isPolyline) const
  68023. {
  68024. const String points (xml.getStringAttribute (T("points")));
  68025. Path path;
  68026. int index = 0;
  68027. float x, y;
  68028. if (parseCoords (points, x, y, index, true))
  68029. {
  68030. float firstX = x;
  68031. float firstY = y;
  68032. float lastX = 0, lastY = 0;
  68033. path.startNewSubPath (x, y);
  68034. while (parseCoords (points, x, y, index, true))
  68035. {
  68036. lastX = x;
  68037. lastY = y;
  68038. path.lineTo (x, y);
  68039. }
  68040. if ((! isPolyline) || (firstX == lastX && firstY == lastY))
  68041. path.closeSubPath();
  68042. }
  68043. return parseShape (xml, path);
  68044. }
  68045. Drawable* parseShape (const XmlElement& xml, Path& path,
  68046. const bool shouldParseTransform = true) const
  68047. {
  68048. if (shouldParseTransform && xml.hasAttribute (T("transform")))
  68049. {
  68050. SVGState newState (*this);
  68051. newState.addTransform (xml);
  68052. return newState.parseShape (xml, path, false);
  68053. }
  68054. DrawablePath* dp = new DrawablePath();
  68055. dp->setName (xml.getStringAttribute (T("id")));
  68056. dp->setFill (FillType (Colours::transparentBlack));
  68057. path.applyTransform (transform);
  68058. dp->setPath (path);
  68059. Path::Iterator iter (path);
  68060. bool containsClosedSubPath = false;
  68061. while (iter.next())
  68062. {
  68063. if (iter.elementType == Path::Iterator::closePath)
  68064. {
  68065. containsClosedSubPath = true;
  68066. break;
  68067. }
  68068. }
  68069. dp->setFill (getPathFillType (path,
  68070. getStyleAttribute (&xml, T("fill")),
  68071. getStyleAttribute (&xml, T("fill-opacity")),
  68072. getStyleAttribute (&xml, T("opacity")),
  68073. containsClosedSubPath ? Colours::black
  68074. : Colours::transparentBlack));
  68075. const String strokeType (getStyleAttribute (&xml, T("stroke")));
  68076. if (strokeType.isNotEmpty() && ! strokeType.equalsIgnoreCase (T("none")))
  68077. {
  68078. dp->setStrokeFill (getPathFillType (path, strokeType,
  68079. getStyleAttribute (&xml, T("stroke-opacity")),
  68080. getStyleAttribute (&xml, T("opacity")),
  68081. Colours::transparentBlack));
  68082. dp->setStrokeType (getStrokeFor (&xml));
  68083. }
  68084. return dp;
  68085. }
  68086. const XmlElement* findLinkedElement (const XmlElement* e) const
  68087. {
  68088. const String id (e->getStringAttribute (T("xlink:href")));
  68089. if (! id.startsWithChar (T('#')))
  68090. return 0;
  68091. return findElementForId (topLevelXml, id.substring (1));
  68092. }
  68093. void addGradientStopsIn (ColourGradient& cg, const XmlElement* const fillXml) const
  68094. {
  68095. if (fillXml == 0)
  68096. return;
  68097. forEachXmlChildElementWithTagName (*fillXml, e, T("stop"))
  68098. {
  68099. int index = 0;
  68100. Colour col (parseColour (getStyleAttribute (e, T("stop-color")), index, Colours::black));
  68101. const String opacity (getStyleAttribute (e, T("stop-opacity"), T("1")));
  68102. col = col.withMultipliedAlpha (jlimit (0.0f, 1.0f, opacity.getFloatValue()));
  68103. double offset = e->getDoubleAttribute (T("offset"));
  68104. if (e->getStringAttribute (T("offset")).containsChar (T('%')))
  68105. offset *= 0.01;
  68106. cg.addColour (jlimit (0.0, 1.0, offset), col);
  68107. }
  68108. }
  68109. const FillType getPathFillType (const Path& path,
  68110. const String& fill,
  68111. const String& fillOpacity,
  68112. const String& overallOpacity,
  68113. const Colour& defaultColour) const
  68114. {
  68115. float opacity = 1.0f;
  68116. if (overallOpacity.isNotEmpty())
  68117. opacity = jlimit (0.0f, 1.0f, overallOpacity.getFloatValue());
  68118. if (fillOpacity.isNotEmpty())
  68119. opacity *= (jlimit (0.0f, 1.0f, fillOpacity.getFloatValue()));
  68120. if (fill.startsWithIgnoreCase (T("url")))
  68121. {
  68122. const String id (fill.fromFirstOccurrenceOf (T("#"), false, false)
  68123. .upToLastOccurrenceOf (T(")"), false, false).trim());
  68124. const XmlElement* const fillXml = findElementForId (topLevelXml, id);
  68125. if (fillXml != 0
  68126. && (fillXml->hasTagName (T("linearGradient"))
  68127. || fillXml->hasTagName (T("radialGradient"))))
  68128. {
  68129. const XmlElement* inheritedFrom = findLinkedElement (fillXml);
  68130. ColourGradient gradient;
  68131. addGradientStopsIn (gradient, inheritedFrom);
  68132. addGradientStopsIn (gradient, fillXml);
  68133. if (gradient.getNumColours() > 0)
  68134. {
  68135. gradient.addColour (0.0, gradient.getColour (0));
  68136. gradient.addColour (1.0, gradient.getColour (gradient.getNumColours() - 1));
  68137. }
  68138. else
  68139. {
  68140. gradient.addColour (0.0, Colours::black);
  68141. gradient.addColour (1.0, Colours::black);
  68142. }
  68143. if (overallOpacity.isNotEmpty())
  68144. gradient.multiplyOpacity (overallOpacity.getFloatValue());
  68145. jassert (gradient.getNumColours() > 0);
  68146. gradient.isRadial = fillXml->hasTagName (T("radialGradient"));
  68147. float width = viewBoxW;
  68148. float height = viewBoxH;
  68149. float dx = 0.0f;
  68150. float dy = 0.0f;
  68151. const bool userSpace = fillXml->getStringAttribute (T("gradientUnits")).equalsIgnoreCase (T("userSpaceOnUse"));
  68152. if (! userSpace)
  68153. {
  68154. const Rectangle<float> bounds (path.getBounds());
  68155. dx = bounds.getX();
  68156. dy = bounds.getY();
  68157. width = bounds.getWidth();
  68158. height = bounds.getHeight();
  68159. }
  68160. if (gradient.isRadial)
  68161. {
  68162. gradient.x1 = dx + getCoordLength (fillXml->getStringAttribute (T("cx"), T("50%")), width);
  68163. gradient.y1 = dy + getCoordLength (fillXml->getStringAttribute (T("cy"), T("50%")), height);
  68164. const float radius = getCoordLength (fillXml->getStringAttribute (T("r"), T("50%")), width);
  68165. gradient.x2 = gradient.x1 + radius;
  68166. gradient.y2 = gradient.y1;
  68167. //xxx (the fx, fy focal point isn't handled properly here..)
  68168. }
  68169. else
  68170. {
  68171. gradient.x1 = dx + getCoordLength (fillXml->getStringAttribute (T("x1"), T("0%")), width);
  68172. gradient.y1 = dy + getCoordLength (fillXml->getStringAttribute (T("y1"), T("0%")), height);
  68173. gradient.x2 = dx + getCoordLength (fillXml->getStringAttribute (T("x2"), T("100%")), width);
  68174. gradient.y2 = dy + getCoordLength (fillXml->getStringAttribute (T("y2"), T("0%")), height);
  68175. if (gradient.x1 == gradient.x2 && gradient.y1 == gradient.y2)
  68176. return Colour (gradient.getColour (gradient.getNumColours() - 1));
  68177. }
  68178. FillType type (gradient);
  68179. type.transform = parseTransform (fillXml->getStringAttribute (T("gradientTransform")))
  68180. .followedBy (transform);
  68181. return type;
  68182. }
  68183. }
  68184. if (fill.equalsIgnoreCase (T("none")))
  68185. return Colours::transparentBlack;
  68186. int i = 0;
  68187. const Colour colour (parseColour (fill, i, defaultColour));
  68188. return colour.withMultipliedAlpha (opacity);
  68189. }
  68190. const PathStrokeType getStrokeFor (const XmlElement* const xml) const
  68191. {
  68192. const String width (getStyleAttribute (xml, T("stroke-width")));
  68193. const String cap (getStyleAttribute (xml, T("stroke-linecap")));
  68194. const String join (getStyleAttribute (xml, T("stroke-linejoin")));
  68195. //const String mitreLimit (getStyleAttribute (xml, T("stroke-miterlimit")));
  68196. //const String dashArray (getStyleAttribute (xml, T("stroke-dasharray")));
  68197. //const String dashOffset (getStyleAttribute (xml, T("stroke-dashoffset")));
  68198. PathStrokeType::JointStyle joinStyle = PathStrokeType::mitered;
  68199. PathStrokeType::EndCapStyle capStyle = PathStrokeType::butt;
  68200. if (join.equalsIgnoreCase (T("round")))
  68201. joinStyle = PathStrokeType::curved;
  68202. else if (join.equalsIgnoreCase (T("bevel")))
  68203. joinStyle = PathStrokeType::beveled;
  68204. if (cap.equalsIgnoreCase (T("round")))
  68205. capStyle = PathStrokeType::rounded;
  68206. else if (cap.equalsIgnoreCase (T("square")))
  68207. capStyle = PathStrokeType::square;
  68208. float ox = 0.0f, oy = 0.0f;
  68209. transform.transformPoint (ox, oy);
  68210. float x = getCoordLength (width, viewBoxW), y = 0.0f;
  68211. transform.transformPoint (x, y);
  68212. return PathStrokeType (width.isNotEmpty() ? juce_hypotf (x - ox, y - oy) : 1.0f,
  68213. joinStyle, capStyle);
  68214. }
  68215. Drawable* parseText (const XmlElement& xml)
  68216. {
  68217. Array <float> xCoords, yCoords, dxCoords, dyCoords;
  68218. getCoordList (xCoords, getInheritedAttribute (&xml, T("x")), true, true);
  68219. getCoordList (yCoords, getInheritedAttribute (&xml, T("y")), true, false);
  68220. getCoordList (dxCoords, getInheritedAttribute (&xml, T("dx")), true, true);
  68221. getCoordList (dyCoords, getInheritedAttribute (&xml, T("dy")), true, false);
  68222. //xxx not done text yet!
  68223. forEachXmlChildElement (xml, e)
  68224. {
  68225. if (e->isTextElement())
  68226. {
  68227. const String text (e->getText());
  68228. Path path;
  68229. Drawable* s = parseShape (*e, path);
  68230. delete s;
  68231. }
  68232. else if (e->hasTagName (T("tspan")))
  68233. {
  68234. Drawable* s = parseText (*e);
  68235. delete s;
  68236. }
  68237. }
  68238. return 0;
  68239. }
  68240. void addTransform (const XmlElement& xml)
  68241. {
  68242. transform = parseTransform (xml.getStringAttribute (T("transform")))
  68243. .followedBy (transform);
  68244. }
  68245. bool parseCoord (const String& s, float& value, int& index,
  68246. const bool allowUnits, const bool isX) const
  68247. {
  68248. String number;
  68249. if (! parseNextNumber (s, number, index, allowUnits))
  68250. {
  68251. value = 0;
  68252. return false;
  68253. }
  68254. value = getCoordLength (number, isX ? viewBoxW : viewBoxH);
  68255. return true;
  68256. }
  68257. bool parseCoords (const String& s, float& x, float& y,
  68258. int& index, const bool allowUnits) const
  68259. {
  68260. return parseCoord (s, x, index, allowUnits, true)
  68261. && parseCoord (s, y, index, allowUnits, false);
  68262. }
  68263. float getCoordLength (const String& s, const float sizeForProportions) const
  68264. {
  68265. float n = s.getFloatValue();
  68266. const int len = s.length();
  68267. if (len > 2)
  68268. {
  68269. const float dpi = 96.0f;
  68270. const tchar n1 = s [len - 2];
  68271. const tchar n2 = s [len - 1];
  68272. if (n1 == T('i') && n2 == T('n'))
  68273. n *= dpi;
  68274. else if (n1 == T('m') && n2 == T('m'))
  68275. n *= dpi / 25.4f;
  68276. else if (n1 == T('c') && n2 == T('m'))
  68277. n *= dpi / 2.54f;
  68278. else if (n1 == T('p') && n2 == T('c'))
  68279. n *= 15.0f;
  68280. else if (n2 == T('%'))
  68281. n *= 0.01f * sizeForProportions;
  68282. }
  68283. return n;
  68284. }
  68285. void getCoordList (Array <float>& coords, const String& list,
  68286. const bool allowUnits, const bool isX) const
  68287. {
  68288. int index = 0;
  68289. float value;
  68290. while (parseCoord (list, value, index, allowUnits, isX))
  68291. coords.add (value);
  68292. }
  68293. void parseCSSStyle (const XmlElement& xml)
  68294. {
  68295. cssStyleText = xml.getAllSubText() + T("\n") + cssStyleText;
  68296. }
  68297. const String getStyleAttribute (const XmlElement* xml, const String& attributeName,
  68298. const String& defaultValue = String::empty) const
  68299. {
  68300. if (xml->hasAttribute (attributeName))
  68301. return xml->getStringAttribute (attributeName, defaultValue);
  68302. const String styleAtt (xml->getStringAttribute (T("style")));
  68303. if (styleAtt.isNotEmpty())
  68304. {
  68305. const String value (getAttributeFromStyleList (styleAtt, attributeName, String::empty));
  68306. if (value.isNotEmpty())
  68307. return value;
  68308. }
  68309. else if (xml->hasAttribute (T("class")))
  68310. {
  68311. const String className (T(".") + xml->getStringAttribute (T("class")));
  68312. int index = cssStyleText.indexOfIgnoreCase (className + T(" "));
  68313. if (index < 0)
  68314. index = cssStyleText.indexOfIgnoreCase (className + T("{"));
  68315. if (index >= 0)
  68316. {
  68317. const int openBracket = cssStyleText.indexOfChar (index, T('{'));
  68318. if (openBracket > index)
  68319. {
  68320. const int closeBracket = cssStyleText.indexOfChar (openBracket, T('}'));
  68321. if (closeBracket > openBracket)
  68322. {
  68323. const String value (getAttributeFromStyleList (cssStyleText.substring (openBracket + 1, closeBracket), attributeName, defaultValue));
  68324. if (value.isNotEmpty())
  68325. return value;
  68326. }
  68327. }
  68328. }
  68329. }
  68330. xml = const_cast <XmlElement*> (topLevelXml)->findParentElementOf (xml);
  68331. if (xml != 0)
  68332. return getStyleAttribute (xml, attributeName, defaultValue);
  68333. return defaultValue;
  68334. }
  68335. const String getInheritedAttribute (const XmlElement* xml, const String& attributeName) const
  68336. {
  68337. if (xml->hasAttribute (attributeName))
  68338. return xml->getStringAttribute (attributeName);
  68339. xml = const_cast <XmlElement*> (topLevelXml)->findParentElementOf (xml);
  68340. if (xml != 0)
  68341. return getInheritedAttribute (xml, attributeName);
  68342. return String::empty;
  68343. }
  68344. static bool isIdentifierChar (const tchar c)
  68345. {
  68346. return CharacterFunctions::isLetter (c) || c == T('-');
  68347. }
  68348. static const String getAttributeFromStyleList (const String& list, const String& attributeName, const String& defaultValue)
  68349. {
  68350. int i = 0;
  68351. for (;;)
  68352. {
  68353. i = list.indexOf (i, attributeName);
  68354. if (i < 0)
  68355. break;
  68356. if ((i == 0 || (i > 0 && ! isIdentifierChar (list [i - 1])))
  68357. && ! isIdentifierChar (list [i + attributeName.length()]))
  68358. {
  68359. i = list.indexOfChar (i, T(':'));
  68360. if (i < 0)
  68361. break;
  68362. int end = list.indexOfChar (i, T(';'));
  68363. if (end < 0)
  68364. end = 0x7ffff;
  68365. return list.substring (i + 1, end).trim();
  68366. }
  68367. ++i;
  68368. }
  68369. return defaultValue;
  68370. }
  68371. static bool parseNextNumber (const String& source, String& value, int& index, const bool allowUnits)
  68372. {
  68373. const tchar* const s = (const tchar*) source;
  68374. while (CharacterFunctions::isWhitespace (s[index]) || s[index] == T(','))
  68375. ++index;
  68376. int start = index;
  68377. if (CharacterFunctions::isDigit (s[index]) || s[index] == T('.') || s[index] == T('-'))
  68378. ++index;
  68379. while (CharacterFunctions::isDigit (s[index]) || s[index] == T('.'))
  68380. ++index;
  68381. if ((s[index] == T('e') || s[index] == T('E'))
  68382. && (CharacterFunctions::isDigit (s[index + 1])
  68383. || s[index + 1] == T('-')
  68384. || s[index + 1] == T('+')))
  68385. {
  68386. index += 2;
  68387. while (CharacterFunctions::isDigit (s[index]))
  68388. ++index;
  68389. }
  68390. if (allowUnits)
  68391. {
  68392. while (CharacterFunctions::isLetter (s[index]))
  68393. ++index;
  68394. }
  68395. if (index == start)
  68396. return false;
  68397. value = String (s + start, index - start);
  68398. while (CharacterFunctions::isWhitespace (s[index]) || s[index] == T(','))
  68399. ++index;
  68400. return true;
  68401. }
  68402. static const Colour parseColour (const String& s, int& index, const Colour& defaultColour)
  68403. {
  68404. if (s [index] == T('#'))
  68405. {
  68406. uint32 hex [6];
  68407. zeromem (hex, sizeof (hex));
  68408. int numChars = 0;
  68409. for (int i = 6; --i >= 0;)
  68410. {
  68411. const int hexValue = CharacterFunctions::getHexDigitValue (s [++index]);
  68412. if (hexValue >= 0)
  68413. hex [numChars++] = hexValue;
  68414. else
  68415. break;
  68416. }
  68417. if (numChars <= 3)
  68418. return Colour ((uint8) (hex [0] * 0x11),
  68419. (uint8) (hex [1] * 0x11),
  68420. (uint8) (hex [2] * 0x11));
  68421. else
  68422. return Colour ((uint8) ((hex [0] << 4) + hex [1]),
  68423. (uint8) ((hex [2] << 4) + hex [3]),
  68424. (uint8) ((hex [4] << 4) + hex [5]));
  68425. }
  68426. else if (s [index] == T('r')
  68427. && s [index + 1] == T('g')
  68428. && s [index + 2] == T('b'))
  68429. {
  68430. const int openBracket = s.indexOfChar (index, T('('));
  68431. const int closeBracket = s.indexOfChar (openBracket, T(')'));
  68432. if (openBracket >= 3 && closeBracket > openBracket)
  68433. {
  68434. index = closeBracket;
  68435. StringArray tokens;
  68436. tokens.addTokens (s.substring (openBracket + 1, closeBracket), T(","), T(""));
  68437. tokens.trim();
  68438. tokens.removeEmptyStrings();
  68439. if (tokens[0].containsChar (T('%')))
  68440. return Colour ((uint8) roundToInt (2.55 * tokens[0].getDoubleValue()),
  68441. (uint8) roundToInt (2.55 * tokens[1].getDoubleValue()),
  68442. (uint8) roundToInt (2.55 * tokens[2].getDoubleValue()));
  68443. else
  68444. return Colour ((uint8) tokens[0].getIntValue(),
  68445. (uint8) tokens[1].getIntValue(),
  68446. (uint8) tokens[2].getIntValue());
  68447. }
  68448. }
  68449. return Colours::findColourForName (s, defaultColour);
  68450. }
  68451. static const AffineTransform parseTransform (String t)
  68452. {
  68453. AffineTransform result;
  68454. while (t.isNotEmpty())
  68455. {
  68456. StringArray tokens;
  68457. tokens.addTokens (t.fromFirstOccurrenceOf (T("("), false, false)
  68458. .upToFirstOccurrenceOf (T(")"), false, false),
  68459. T(", "), String::empty);
  68460. tokens.removeEmptyStrings (true);
  68461. float numbers [6];
  68462. for (int i = 0; i < 6; ++i)
  68463. numbers[i] = tokens[i].getFloatValue();
  68464. AffineTransform trans;
  68465. if (t.startsWithIgnoreCase (T("matrix")))
  68466. {
  68467. trans = AffineTransform (numbers[0], numbers[2], numbers[4],
  68468. numbers[1], numbers[3], numbers[5]);
  68469. }
  68470. else if (t.startsWithIgnoreCase (T("translate")))
  68471. {
  68472. jassert (tokens.size() == 2);
  68473. trans = AffineTransform::translation (numbers[0], numbers[1]);
  68474. }
  68475. else if (t.startsWithIgnoreCase (T("scale")))
  68476. {
  68477. if (tokens.size() == 1)
  68478. trans = AffineTransform::scale (numbers[0], numbers[0]);
  68479. else
  68480. trans = AffineTransform::scale (numbers[0], numbers[1]);
  68481. }
  68482. else if (t.startsWithIgnoreCase (T("rotate")))
  68483. {
  68484. if (tokens.size() != 3)
  68485. trans = AffineTransform::rotation (numbers[0] / (180.0f / float_Pi));
  68486. else
  68487. trans = AffineTransform::rotation (numbers[0] / (180.0f / float_Pi),
  68488. numbers[1], numbers[2]);
  68489. }
  68490. else if (t.startsWithIgnoreCase (T("skewX")))
  68491. {
  68492. trans = AffineTransform (1.0f, tanf (numbers[0] * (float_Pi / 180.0f)), 0.0f,
  68493. 0.0f, 1.0f, 0.0f);
  68494. }
  68495. else if (t.startsWithIgnoreCase (T("skewY")))
  68496. {
  68497. trans = AffineTransform (1.0f, 0.0f, 0.0f,
  68498. tanf (numbers[0] * (float_Pi / 180.0f)), 1.0f, 0.0f);
  68499. }
  68500. result = trans.followedBy (result);
  68501. t = t.fromFirstOccurrenceOf (T(")"), false, false).trimStart();
  68502. }
  68503. return result;
  68504. }
  68505. static void endpointToCentreParameters (const double x1, const double y1,
  68506. const double x2, const double y2,
  68507. const double angle,
  68508. const bool largeArc, const bool sweep,
  68509. double& rx, double& ry,
  68510. double& centreX, double& centreY,
  68511. double& startAngle, double& deltaAngle)
  68512. {
  68513. const double midX = (x1 - x2) * 0.5;
  68514. const double midY = (y1 - y2) * 0.5;
  68515. const double cosAngle = cos (angle);
  68516. const double sinAngle = sin (angle);
  68517. const double xp = cosAngle * midX + sinAngle * midY;
  68518. const double yp = cosAngle * midY - sinAngle * midX;
  68519. const double xp2 = xp * xp;
  68520. const double yp2 = yp * yp;
  68521. double rx2 = rx * rx;
  68522. double ry2 = ry * ry;
  68523. const double s = (xp2 / rx2) + (yp2 / ry2);
  68524. double c;
  68525. if (s <= 1.0)
  68526. {
  68527. c = sqrt (jmax (0.0, ((rx2 * ry2) - (rx2 * yp2) - (ry2 * xp2))
  68528. / (( rx2 * yp2) + (ry2 * xp2))));
  68529. if (largeArc == sweep)
  68530. c = -c;
  68531. }
  68532. else
  68533. {
  68534. const double s2 = sqrt (s);
  68535. rx *= s2;
  68536. ry *= s2;
  68537. rx2 = rx * rx;
  68538. ry2 = ry * ry;
  68539. c = 0;
  68540. }
  68541. const double cpx = ((rx * yp) / ry) * c;
  68542. const double cpy = ((-ry * xp) / rx) * c;
  68543. centreX = ((x1 + x2) * 0.5) + (cosAngle * cpx) - (sinAngle * cpy);
  68544. centreY = ((y1 + y2) * 0.5) + (sinAngle * cpx) + (cosAngle * cpy);
  68545. const double ux = (xp - cpx) / rx;
  68546. const double uy = (yp - cpy) / ry;
  68547. const double vx = (-xp - cpx) / rx;
  68548. const double vy = (-yp - cpy) / ry;
  68549. const double length = juce_hypot (ux, uy);
  68550. startAngle = acos (jlimit (-1.0, 1.0, ux / length));
  68551. if (uy < 0)
  68552. startAngle = -startAngle;
  68553. startAngle += double_Pi * 0.5;
  68554. deltaAngle = acos (jlimit (-1.0, 1.0, ((ux * vx) + (uy * vy))
  68555. / (length * juce_hypot (vx, vy))));
  68556. if ((ux * vy) - (uy * vx) < 0)
  68557. deltaAngle = -deltaAngle;
  68558. if (sweep)
  68559. {
  68560. if (deltaAngle < 0)
  68561. deltaAngle += double_Pi * 2.0;
  68562. }
  68563. else
  68564. {
  68565. if (deltaAngle > 0)
  68566. deltaAngle -= double_Pi * 2.0;
  68567. }
  68568. deltaAngle = fmod (deltaAngle, double_Pi * 2.0);
  68569. }
  68570. static const XmlElement* findElementForId (const XmlElement* const parent, const String& id)
  68571. {
  68572. forEachXmlChildElement (*parent, e)
  68573. {
  68574. if (e->compareAttribute (T("id"), id))
  68575. return e;
  68576. const XmlElement* const found = findElementForId (e, id);
  68577. if (found != 0)
  68578. return found;
  68579. }
  68580. return 0;
  68581. }
  68582. SVGState& operator= (const SVGState&);
  68583. };
  68584. Drawable* Drawable::createFromSVG (const XmlElement& svgDocument)
  68585. {
  68586. SVGState state (&svgDocument);
  68587. return state.parseSVGElement (svgDocument);
  68588. }
  68589. END_JUCE_NAMESPACE
  68590. /*** End of inlined file: juce_SVGParser.cpp ***/
  68591. /*** Start of inlined file: juce_DropShadowEffect.cpp ***/
  68592. BEGIN_JUCE_NAMESPACE
  68593. #if JUCE_MSVC
  68594. #pragma optimize ("t", on) // try to avoid slowing everything down in debug builds
  68595. #endif
  68596. DropShadowEffect::DropShadowEffect()
  68597. : offsetX (0),
  68598. offsetY (0),
  68599. radius (4),
  68600. opacity (0.6f)
  68601. {
  68602. }
  68603. DropShadowEffect::~DropShadowEffect()
  68604. {
  68605. }
  68606. void DropShadowEffect::setShadowProperties (const float newRadius,
  68607. const float newOpacity,
  68608. const int newShadowOffsetX,
  68609. const int newShadowOffsetY)
  68610. {
  68611. radius = jmax (1.1f, newRadius);
  68612. offsetX = newShadowOffsetX;
  68613. offsetY = newShadowOffsetY;
  68614. opacity = newOpacity;
  68615. }
  68616. void DropShadowEffect::applyEffect (Image& image, Graphics& g)
  68617. {
  68618. const int w = image.getWidth();
  68619. const int h = image.getHeight();
  68620. Image shadowImage (Image::SingleChannel, w, h, false);
  68621. const Image::BitmapData srcData (image, 0, 0, w, h);
  68622. const Image::BitmapData destData (shadowImage, 0, 0, w, h, true);
  68623. const int filter = roundToInt (63.0f / radius);
  68624. const int radiusMinus1 = roundToInt ((radius - 1.0f) * 63.0f);
  68625. for (int x = w; --x >= 0;)
  68626. {
  68627. int shadowAlpha = 0;
  68628. const PixelARGB* src = ((const PixelARGB*) srcData.data) + x;
  68629. uint8* shadowPix = destData.data + x;
  68630. for (int y = h; --y >= 0;)
  68631. {
  68632. shadowAlpha = ((shadowAlpha * radiusMinus1 + (src->getAlpha() << 6)) * filter) >> 12;
  68633. *shadowPix = (uint8) shadowAlpha;
  68634. src = (const PixelARGB*) (((const uint8*) src) + srcData.lineStride);
  68635. shadowPix += destData.lineStride;
  68636. }
  68637. }
  68638. for (int y = h; --y >= 0;)
  68639. {
  68640. int shadowAlpha = 0;
  68641. uint8* shadowPix = destData.getLinePointer (y);
  68642. for (int x = w; --x >= 0;)
  68643. {
  68644. shadowAlpha = ((shadowAlpha * radiusMinus1 + (*shadowPix << 6)) * filter) >> 12;
  68645. *shadowPix++ = (uint8) shadowAlpha;
  68646. }
  68647. }
  68648. g.setColour (Colours::black.withAlpha (opacity));
  68649. g.drawImageAt (&shadowImage, offsetX, offsetY, true);
  68650. g.setOpacity (1.0f);
  68651. g.drawImageAt (&image, 0, 0);
  68652. }
  68653. END_JUCE_NAMESPACE
  68654. /*** End of inlined file: juce_DropShadowEffect.cpp ***/
  68655. /*** Start of inlined file: juce_GlowEffect.cpp ***/
  68656. BEGIN_JUCE_NAMESPACE
  68657. GlowEffect::GlowEffect()
  68658. : radius (2.0f),
  68659. colour (Colours::white)
  68660. {
  68661. }
  68662. GlowEffect::~GlowEffect()
  68663. {
  68664. }
  68665. void GlowEffect::setGlowProperties (const float newRadius,
  68666. const Colour& newColour)
  68667. {
  68668. radius = newRadius;
  68669. colour = newColour;
  68670. }
  68671. void GlowEffect::applyEffect (Image& image, Graphics& g)
  68672. {
  68673. const int w = image.getWidth();
  68674. const int h = image.getHeight();
  68675. Image temp (image.getFormat(), w, h, true);
  68676. ImageConvolutionKernel blurKernel (roundToInt (radius * 2.0f));
  68677. blurKernel.createGaussianBlur (radius);
  68678. blurKernel.rescaleAllValues (radius);
  68679. blurKernel.applyToImage (temp, &image, 0, 0, w, h);
  68680. g.setColour (colour);
  68681. g.drawImageAt (&temp, 0, 0, true);
  68682. g.setOpacity (1.0f);
  68683. g.drawImageAt (&image, 0, 0, false);
  68684. }
  68685. END_JUCE_NAMESPACE
  68686. /*** End of inlined file: juce_GlowEffect.cpp ***/
  68687. /*** Start of inlined file: juce_ReduceOpacityEffect.cpp ***/
  68688. BEGIN_JUCE_NAMESPACE
  68689. ReduceOpacityEffect::ReduceOpacityEffect (const float opacity_)
  68690. : opacity (opacity_)
  68691. {
  68692. }
  68693. ReduceOpacityEffect::~ReduceOpacityEffect()
  68694. {
  68695. }
  68696. void ReduceOpacityEffect::setOpacity (const float newOpacity)
  68697. {
  68698. opacity = jlimit (0.0f, 1.0f, newOpacity);
  68699. }
  68700. void ReduceOpacityEffect::applyEffect (Image& image, Graphics& g)
  68701. {
  68702. g.setOpacity (opacity);
  68703. g.drawImageAt (&image, 0, 0);
  68704. }
  68705. END_JUCE_NAMESPACE
  68706. /*** End of inlined file: juce_ReduceOpacityEffect.cpp ***/
  68707. /*** Start of inlined file: juce_Font.cpp ***/
  68708. BEGIN_JUCE_NAMESPACE
  68709. static const float minFontHeight = 0.1f;
  68710. static const float maxFontHeight = 10000.0f;
  68711. static const float defaultFontHeight = 14.0f;
  68712. static const tchar* const juce_defaultFontNameSans = T("<Sans-Serif>");
  68713. static const tchar* const juce_defaultFontNameSerif = T("<Serif>");
  68714. static const tchar* const juce_defaultFontNameMono = T("<Monospaced>");
  68715. void clearUpDefaultFontNames() throw(); // in juce_LookAndFeel.cpp
  68716. Font::SharedFontInternal::SharedFontInternal (const String& typefaceName_, const float height_, const float horizontalScale_,
  68717. const float kerning_, const float ascent_, const int styleFlags_,
  68718. Typeface* const typeface_) throw()
  68719. : typefaceName (typefaceName_),
  68720. height (height_),
  68721. horizontalScale (horizontalScale_),
  68722. kerning (kerning_),
  68723. ascent (ascent_),
  68724. styleFlags (styleFlags_),
  68725. typeface (typeface_)
  68726. {
  68727. }
  68728. Font::SharedFontInternal::SharedFontInternal (const SharedFontInternal& other) throw()
  68729. : typefaceName (other.typefaceName),
  68730. height (other.height),
  68731. horizontalScale (other.horizontalScale),
  68732. kerning (other.kerning),
  68733. ascent (other.ascent),
  68734. styleFlags (other.styleFlags),
  68735. typeface (other.typeface)
  68736. {
  68737. }
  68738. Font::Font() throw()
  68739. : font (new SharedFontInternal (juce_defaultFontNameSans, defaultFontHeight,
  68740. 1.0f, 0, 0, Font::plain, 0))
  68741. {
  68742. }
  68743. Font::Font (const float fontHeight, const int styleFlags_) throw()
  68744. : font (new SharedFontInternal (juce_defaultFontNameSans, jlimit (minFontHeight, maxFontHeight, fontHeight),
  68745. 1.0f, 0, 0, styleFlags_, 0))
  68746. {
  68747. }
  68748. Font::Font (const String& typefaceName_,
  68749. const float fontHeight,
  68750. const int styleFlags_) throw()
  68751. : font (new SharedFontInternal (typefaceName_, jlimit (minFontHeight, maxFontHeight, fontHeight),
  68752. 1.0f, 0, 0, styleFlags_, 0))
  68753. {
  68754. }
  68755. Font::Font (const Font& other) throw()
  68756. : font (other.font)
  68757. {
  68758. }
  68759. Font& Font::operator= (const Font& other) throw()
  68760. {
  68761. font = other.font;
  68762. return *this;
  68763. }
  68764. Font::~Font() throw()
  68765. {
  68766. }
  68767. Font::Font (const Typeface::Ptr& typeface) throw()
  68768. : font (new SharedFontInternal (typeface->getName(), defaultFontHeight,
  68769. 1.0f, 0, 0, Font::plain, typeface))
  68770. {
  68771. }
  68772. bool Font::operator== (const Font& other) const throw()
  68773. {
  68774. return font == other.font
  68775. || (font->height == other.font->height
  68776. && font->styleFlags == other.font->styleFlags
  68777. && font->horizontalScale == other.font->horizontalScale
  68778. && font->kerning == other.font->kerning
  68779. && font->typefaceName == other.font->typefaceName);
  68780. }
  68781. bool Font::operator!= (const Font& other) const throw()
  68782. {
  68783. return ! operator== (other);
  68784. }
  68785. void Font::dupeInternalIfShared() throw()
  68786. {
  68787. if (font->getReferenceCount() > 1)
  68788. font = new SharedFontInternal (*font);
  68789. }
  68790. const String Font::getDefaultSansSerifFontName() throw()
  68791. {
  68792. return juce_defaultFontNameSans;
  68793. }
  68794. const String Font::getDefaultSerifFontName() throw()
  68795. {
  68796. return juce_defaultFontNameSerif;
  68797. }
  68798. const String Font::getDefaultMonospacedFontName() throw()
  68799. {
  68800. return juce_defaultFontNameMono;
  68801. }
  68802. void Font::setTypefaceName (const String& faceName) throw()
  68803. {
  68804. if (faceName != font->typefaceName)
  68805. {
  68806. dupeInternalIfShared();
  68807. font->typefaceName = faceName;
  68808. font->typeface = 0;
  68809. font->ascent = 0;
  68810. }
  68811. }
  68812. static String fallbackFont;
  68813. const String Font::getFallbackFontName() throw()
  68814. {
  68815. return fallbackFont;
  68816. }
  68817. void Font::setFallbackFontName (const String& name) throw()
  68818. {
  68819. fallbackFont = name;
  68820. }
  68821. void Font::setHeight (float newHeight) throw()
  68822. {
  68823. newHeight = jlimit (minFontHeight, maxFontHeight, newHeight);
  68824. if (font->height != newHeight)
  68825. {
  68826. dupeInternalIfShared();
  68827. font->height = newHeight;
  68828. }
  68829. }
  68830. void Font::setHeightWithoutChangingWidth (float newHeight) throw()
  68831. {
  68832. newHeight = jlimit (minFontHeight, maxFontHeight, newHeight);
  68833. if (font->height != newHeight)
  68834. {
  68835. dupeInternalIfShared();
  68836. font->horizontalScale *= (font->height / newHeight);
  68837. font->height = newHeight;
  68838. }
  68839. }
  68840. void Font::setStyleFlags (const int newFlags) throw()
  68841. {
  68842. if (font->styleFlags != newFlags)
  68843. {
  68844. dupeInternalIfShared();
  68845. font->styleFlags = newFlags;
  68846. font->typeface = 0;
  68847. font->ascent = 0;
  68848. }
  68849. }
  68850. void Font::setSizeAndStyle (float newHeight,
  68851. const int newStyleFlags,
  68852. const float newHorizontalScale,
  68853. const float newKerningAmount) throw()
  68854. {
  68855. newHeight = jlimit (minFontHeight, maxFontHeight, newHeight);
  68856. if (font->height != newHeight
  68857. || font->horizontalScale != newHorizontalScale
  68858. || font->kerning != newKerningAmount)
  68859. {
  68860. dupeInternalIfShared();
  68861. font->height = newHeight;
  68862. font->horizontalScale = newHorizontalScale;
  68863. font->kerning = newKerningAmount;
  68864. }
  68865. setStyleFlags (newStyleFlags);
  68866. }
  68867. void Font::setHorizontalScale (const float scaleFactor) throw()
  68868. {
  68869. dupeInternalIfShared();
  68870. font->horizontalScale = scaleFactor;
  68871. }
  68872. void Font::setExtraKerningFactor (const float extraKerning) throw()
  68873. {
  68874. dupeInternalIfShared();
  68875. font->kerning = extraKerning;
  68876. }
  68877. void Font::setBold (const bool shouldBeBold) throw()
  68878. {
  68879. setStyleFlags (shouldBeBold ? (font->styleFlags | bold)
  68880. : (font->styleFlags & ~bold));
  68881. }
  68882. bool Font::isBold() const throw()
  68883. {
  68884. return (font->styleFlags & bold) != 0;
  68885. }
  68886. void Font::setItalic (const bool shouldBeItalic) throw()
  68887. {
  68888. setStyleFlags (shouldBeItalic ? (font->styleFlags | italic)
  68889. : (font->styleFlags & ~italic));
  68890. }
  68891. bool Font::isItalic() const throw()
  68892. {
  68893. return (font->styleFlags & italic) != 0;
  68894. }
  68895. void Font::setUnderline (const bool shouldBeUnderlined) throw()
  68896. {
  68897. setStyleFlags (shouldBeUnderlined ? (font->styleFlags | underlined)
  68898. : (font->styleFlags & ~underlined));
  68899. }
  68900. bool Font::isUnderlined() const throw()
  68901. {
  68902. return (font->styleFlags & underlined) != 0;
  68903. }
  68904. float Font::getAscent() const throw()
  68905. {
  68906. if (font->ascent == 0)
  68907. font->ascent = getTypeface()->getAscent();
  68908. return font->height * font->ascent;
  68909. }
  68910. float Font::getDescent() const throw()
  68911. {
  68912. return font->height - getAscent();
  68913. }
  68914. int Font::getStringWidth (const String& text) const throw()
  68915. {
  68916. return roundToInt (getStringWidthFloat (text));
  68917. }
  68918. float Font::getStringWidthFloat (const String& text) const throw()
  68919. {
  68920. float w = getTypeface()->getStringWidth (text);
  68921. if (font->kerning != 0)
  68922. w += font->kerning * text.length();
  68923. return w * font->height * font->horizontalScale;
  68924. }
  68925. void Font::getGlyphPositions (const String& text, Array <int>& glyphs, Array <float>& xOffsets) const throw()
  68926. {
  68927. getTypeface()->getGlyphPositions (text, glyphs, xOffsets);
  68928. const float scale = font->height * font->horizontalScale;
  68929. const int num = xOffsets.size();
  68930. if (num > 0)
  68931. {
  68932. float* const x = &(xOffsets.getReference(0));
  68933. if (font->kerning != 0)
  68934. {
  68935. for (int i = 0; i < num; ++i)
  68936. x[i] = (x[i] + i * font->kerning) * scale;
  68937. }
  68938. else
  68939. {
  68940. for (int i = 0; i < num; ++i)
  68941. x[i] *= scale;
  68942. }
  68943. }
  68944. }
  68945. void Font::findFonts (Array<Font>& destArray) throw()
  68946. {
  68947. const StringArray names (findAllTypefaceNames());
  68948. for (int i = 0; i < names.size(); ++i)
  68949. destArray.add (Font (names[i], defaultFontHeight, Font::plain));
  68950. }
  68951. class TypefaceCache : public DeletedAtShutdown
  68952. {
  68953. public:
  68954. TypefaceCache (int numToCache = 10) throw()
  68955. : counter (1)
  68956. {
  68957. while (--numToCache >= 0)
  68958. faces.add (new CachedFace());
  68959. }
  68960. ~TypefaceCache()
  68961. {
  68962. clearUpDefaultFontNames();
  68963. clearSingletonInstance();
  68964. }
  68965. juce_DeclareSingleton_SingleThreaded_Minimal (TypefaceCache)
  68966. const Typeface::Ptr findTypefaceFor (const Font& font) throw()
  68967. {
  68968. const int flags = font.getStyleFlags() & (Font::bold | Font::italic);
  68969. const String faceName (font.getTypefaceName());
  68970. int i;
  68971. for (i = faces.size(); --i >= 0;)
  68972. {
  68973. CachedFace* const face = faces.getUnchecked(i);
  68974. if (face->flags == flags
  68975. && face->typefaceName == faceName)
  68976. {
  68977. face->lastUsageCount = ++counter;
  68978. return face->typeFace;
  68979. }
  68980. }
  68981. int replaceIndex = 0;
  68982. int bestLastUsageCount = std::numeric_limits<int>::max();
  68983. for (i = faces.size(); --i >= 0;)
  68984. {
  68985. const int lu = faces.getUnchecked(i)->lastUsageCount;
  68986. if (bestLastUsageCount > lu)
  68987. {
  68988. bestLastUsageCount = lu;
  68989. replaceIndex = i;
  68990. }
  68991. }
  68992. CachedFace* const face = faces.getUnchecked (replaceIndex);
  68993. face->typefaceName = faceName;
  68994. face->flags = flags;
  68995. face->lastUsageCount = ++counter;
  68996. face->typeFace = LookAndFeel::getDefaultLookAndFeel().getTypefaceForFont (font);
  68997. jassert (face->typeFace != 0); // the look and feel must return a typeface!
  68998. return face->typeFace;
  68999. }
  69000. juce_UseDebuggingNewOperator
  69001. private:
  69002. struct CachedFace
  69003. {
  69004. CachedFace() throw()
  69005. : lastUsageCount (0), flags (-1)
  69006. {
  69007. }
  69008. String typefaceName;
  69009. int lastUsageCount;
  69010. int flags;
  69011. Typeface::Ptr typeFace;
  69012. };
  69013. int counter;
  69014. OwnedArray <CachedFace> faces;
  69015. TypefaceCache (const TypefaceCache&);
  69016. TypefaceCache& operator= (const TypefaceCache&);
  69017. };
  69018. juce_ImplementSingleton_SingleThreaded (TypefaceCache)
  69019. Typeface* Font::getTypeface() const throw()
  69020. {
  69021. if (font->typeface == 0)
  69022. font->typeface = TypefaceCache::getInstance()->findTypefaceFor (*this);
  69023. return font->typeface;
  69024. }
  69025. END_JUCE_NAMESPACE
  69026. /*** End of inlined file: juce_Font.cpp ***/
  69027. /*** Start of inlined file: juce_GlyphArrangement.cpp ***/
  69028. BEGIN_JUCE_NAMESPACE
  69029. PositionedGlyph::PositionedGlyph (const float x_, const float y_, const float w_, const Font& font_,
  69030. const juce_wchar character_, const int glyph_)
  69031. : x (x_),
  69032. y (y_),
  69033. w (w_),
  69034. font (font_),
  69035. character (character_),
  69036. glyph (glyph_)
  69037. {
  69038. }
  69039. PositionedGlyph::PositionedGlyph (const PositionedGlyph& other)
  69040. : x (other.x),
  69041. y (other.y),
  69042. w (other.w),
  69043. font (other.font),
  69044. character (other.character),
  69045. glyph (other.glyph)
  69046. {
  69047. }
  69048. void PositionedGlyph::draw (const Graphics& g) const
  69049. {
  69050. if (! isWhitespace())
  69051. {
  69052. g.getInternalContext()->setFont (font);
  69053. g.getInternalContext()->drawGlyph (glyph, AffineTransform::translation (x, y));
  69054. }
  69055. }
  69056. void PositionedGlyph::draw (const Graphics& g,
  69057. const AffineTransform& transform) const
  69058. {
  69059. if (! isWhitespace())
  69060. {
  69061. g.getInternalContext()->setFont (font);
  69062. g.getInternalContext()->drawGlyph (glyph, AffineTransform::translation (x, y)
  69063. .followedBy (transform));
  69064. }
  69065. }
  69066. void PositionedGlyph::createPath (Path& path) const
  69067. {
  69068. if (! isWhitespace())
  69069. {
  69070. Typeface* const t = font.getTypeface();
  69071. if (t != 0)
  69072. {
  69073. Path p;
  69074. t->getOutlineForGlyph (glyph, p);
  69075. path.addPath (p, AffineTransform::scale (font.getHeight() * font.getHorizontalScale(), font.getHeight())
  69076. .translated (x, y));
  69077. }
  69078. }
  69079. }
  69080. bool PositionedGlyph::hitTest (float px, float py) const
  69081. {
  69082. if (px >= getLeft() && px < getRight()
  69083. && py >= getTop() && py < getBottom()
  69084. && ! isWhitespace())
  69085. {
  69086. Typeface* const t = font.getTypeface();
  69087. if (t != 0)
  69088. {
  69089. Path p;
  69090. t->getOutlineForGlyph (glyph, p);
  69091. AffineTransform::translation (-x, -y)
  69092. .scaled (1.0f / (font.getHeight() * font.getHorizontalScale()), 1.0f / font.getHeight())
  69093. .transformPoint (px, py);
  69094. return p.contains (px, py);
  69095. }
  69096. }
  69097. return false;
  69098. }
  69099. void PositionedGlyph::moveBy (const float deltaX,
  69100. const float deltaY)
  69101. {
  69102. x += deltaX;
  69103. y += deltaY;
  69104. }
  69105. GlyphArrangement::GlyphArrangement()
  69106. {
  69107. glyphs.ensureStorageAllocated (128);
  69108. }
  69109. GlyphArrangement::GlyphArrangement (const GlyphArrangement& other)
  69110. {
  69111. addGlyphArrangement (other);
  69112. }
  69113. GlyphArrangement& GlyphArrangement::operator= (const GlyphArrangement& other)
  69114. {
  69115. if (this != &other)
  69116. {
  69117. clear();
  69118. addGlyphArrangement (other);
  69119. }
  69120. return *this;
  69121. }
  69122. GlyphArrangement::~GlyphArrangement()
  69123. {
  69124. }
  69125. void GlyphArrangement::clear()
  69126. {
  69127. glyphs.clear();
  69128. }
  69129. PositionedGlyph& GlyphArrangement::getGlyph (const int index) const
  69130. {
  69131. jassert (((unsigned int) index) < (unsigned int) glyphs.size());
  69132. return *glyphs [index];
  69133. }
  69134. void GlyphArrangement::addGlyphArrangement (const GlyphArrangement& other)
  69135. {
  69136. glyphs.ensureStorageAllocated (glyphs.size() + other.glyphs.size());
  69137. for (int i = 0; i < other.glyphs.size(); ++i)
  69138. glyphs.add (new PositionedGlyph (*other.glyphs.getUnchecked (i)));
  69139. }
  69140. void GlyphArrangement::removeRangeOfGlyphs (int startIndex, const int num)
  69141. {
  69142. glyphs.removeRange (startIndex, num < 0 ? glyphs.size() : num);
  69143. }
  69144. void GlyphArrangement::addLineOfText (const Font& font,
  69145. const String& text,
  69146. const float xOffset,
  69147. const float yOffset)
  69148. {
  69149. addCurtailedLineOfText (font, text,
  69150. xOffset, yOffset,
  69151. 1.0e10f, false);
  69152. }
  69153. void GlyphArrangement::addCurtailedLineOfText (const Font& font,
  69154. const String& text,
  69155. float xOffset,
  69156. const float yOffset,
  69157. const float maxWidthPixels,
  69158. const bool useEllipsis)
  69159. {
  69160. if (text.isNotEmpty())
  69161. {
  69162. Array <int> newGlyphs;
  69163. Array <float> xOffsets;
  69164. font.getGlyphPositions (text, newGlyphs, xOffsets);
  69165. const int textLen = newGlyphs.size();
  69166. const juce_wchar* const unicodeText = (const juce_wchar*) text;
  69167. for (int i = 0; i < textLen; ++i)
  69168. {
  69169. const float thisX = xOffsets.getUnchecked (i);
  69170. const float nextX = xOffsets.getUnchecked (i + 1);
  69171. if (nextX > maxWidthPixels + 1.0f)
  69172. {
  69173. // curtail the string if it's too wide..
  69174. if (useEllipsis && textLen > 3 && glyphs.size() >= 3)
  69175. insertEllipsis (font, xOffset + maxWidthPixels, 0, glyphs.size());
  69176. break;
  69177. }
  69178. else
  69179. {
  69180. glyphs.add (new PositionedGlyph (xOffset + thisX, yOffset, nextX - thisX,
  69181. font, unicodeText[i], newGlyphs.getUnchecked(i)));
  69182. }
  69183. }
  69184. }
  69185. }
  69186. int GlyphArrangement::insertEllipsis (const Font& font, const float maxXPos,
  69187. const int startIndex, int endIndex)
  69188. {
  69189. int numDeleted = 0;
  69190. if (glyphs.size() > 0)
  69191. {
  69192. Array<int> dotGlyphs;
  69193. Array<float> dotXs;
  69194. font.getGlyphPositions (T(".."), dotGlyphs, dotXs);
  69195. const float dx = dotXs[1];
  69196. float xOffset = 0.0f, yOffset = 0.0f;
  69197. while (endIndex > startIndex)
  69198. {
  69199. const PositionedGlyph* pg = glyphs.getUnchecked (--endIndex);
  69200. xOffset = pg->x;
  69201. yOffset = pg->y;
  69202. glyphs.remove (endIndex);
  69203. ++numDeleted;
  69204. if (xOffset + dx * 3 <= maxXPos)
  69205. break;
  69206. }
  69207. for (int i = 3; --i >= 0;)
  69208. {
  69209. glyphs.insert (endIndex++, new PositionedGlyph (xOffset, yOffset, dx,
  69210. font, '.', dotGlyphs.getFirst()));
  69211. --numDeleted;
  69212. xOffset += dx;
  69213. if (xOffset > maxXPos)
  69214. break;
  69215. }
  69216. }
  69217. return numDeleted;
  69218. }
  69219. void GlyphArrangement::addJustifiedText (const Font& font,
  69220. const String& text,
  69221. float x, float y,
  69222. const float maxLineWidth,
  69223. const Justification& horizontalLayout)
  69224. {
  69225. int lineStartIndex = glyphs.size();
  69226. addLineOfText (font, text, x, y);
  69227. const float originalY = y;
  69228. while (lineStartIndex < glyphs.size())
  69229. {
  69230. int i = lineStartIndex;
  69231. if (glyphs.getUnchecked(i)->getCharacter() != T('\n')
  69232. && glyphs.getUnchecked(i)->getCharacter() != T('\r'))
  69233. ++i;
  69234. const float lineMaxX = glyphs.getUnchecked (lineStartIndex)->getLeft() + maxLineWidth;
  69235. int lastWordBreakIndex = -1;
  69236. while (i < glyphs.size())
  69237. {
  69238. const PositionedGlyph* pg = glyphs.getUnchecked (i);
  69239. const juce_wchar c = pg->getCharacter();
  69240. if (c == T('\r') || c == T('\n'))
  69241. {
  69242. ++i;
  69243. if (c == T('\r') && i < glyphs.size()
  69244. && glyphs.getUnchecked(i)->getCharacter() == T('\n'))
  69245. ++i;
  69246. break;
  69247. }
  69248. else if (pg->isWhitespace())
  69249. {
  69250. lastWordBreakIndex = i + 1;
  69251. }
  69252. else if (pg->getRight() - 0.0001f >= lineMaxX)
  69253. {
  69254. if (lastWordBreakIndex >= 0)
  69255. i = lastWordBreakIndex;
  69256. break;
  69257. }
  69258. ++i;
  69259. }
  69260. const float currentLineStartX = glyphs.getUnchecked (lineStartIndex)->getLeft();
  69261. float currentLineEndX = currentLineStartX;
  69262. for (int j = i; --j >= lineStartIndex;)
  69263. {
  69264. if (! glyphs.getUnchecked (j)->isWhitespace())
  69265. {
  69266. currentLineEndX = glyphs.getUnchecked (j)->getRight();
  69267. break;
  69268. }
  69269. }
  69270. float deltaX = 0.0f;
  69271. if (horizontalLayout.testFlags (Justification::horizontallyJustified))
  69272. spreadOutLine (lineStartIndex, i - lineStartIndex, maxLineWidth);
  69273. else if (horizontalLayout.testFlags (Justification::horizontallyCentred))
  69274. deltaX = (maxLineWidth - (currentLineEndX - currentLineStartX)) * 0.5f;
  69275. else if (horizontalLayout.testFlags (Justification::right))
  69276. deltaX = maxLineWidth - (currentLineEndX - currentLineStartX);
  69277. moveRangeOfGlyphs (lineStartIndex, i - lineStartIndex,
  69278. x + deltaX - currentLineStartX, y - originalY);
  69279. lineStartIndex = i;
  69280. y += font.getHeight();
  69281. }
  69282. }
  69283. void GlyphArrangement::addFittedText (const Font& f,
  69284. const String& text,
  69285. const float x, const float y,
  69286. const float width, const float height,
  69287. const Justification& layout,
  69288. int maximumLines,
  69289. const float minimumHorizontalScale)
  69290. {
  69291. // doesn't make much sense if this is outside a sensible range of 0.5 to 1.0
  69292. jassert (minimumHorizontalScale > 0 && minimumHorizontalScale <= 1.0f);
  69293. if (text.containsAnyOf (T("\r\n")))
  69294. {
  69295. GlyphArrangement ga;
  69296. ga.addJustifiedText (f, text, x, y, width, layout);
  69297. float l, t, r, b;
  69298. ga.getBoundingBox (0, -1, l, t, r, b, false);
  69299. float dy = y - t;
  69300. if (layout.testFlags (Justification::verticallyCentred))
  69301. dy += (height - (b - t)) * 0.5f;
  69302. else if (layout.testFlags (Justification::bottom))
  69303. dy += height - (b - t);
  69304. ga.moveRangeOfGlyphs (0, -1, 0.0f, dy);
  69305. glyphs.ensureStorageAllocated (glyphs.size() + ga.glyphs.size());
  69306. for (int i = 0; i < ga.glyphs.size(); ++i)
  69307. glyphs.add (ga.glyphs.getUnchecked (i));
  69308. ga.glyphs.clear (false);
  69309. return;
  69310. }
  69311. int startIndex = glyphs.size();
  69312. addLineOfText (f, text.trim(), x, y);
  69313. if (glyphs.size() > startIndex)
  69314. {
  69315. float lineWidth = glyphs.getUnchecked (glyphs.size() - 1)->getRight()
  69316. - glyphs.getUnchecked (startIndex)->getLeft();
  69317. if (lineWidth <= 0)
  69318. return;
  69319. if (lineWidth * minimumHorizontalScale < width)
  69320. {
  69321. if (lineWidth > width)
  69322. stretchRangeOfGlyphs (startIndex, glyphs.size() - startIndex,
  69323. width / lineWidth);
  69324. justifyGlyphs (startIndex, glyphs.size() - startIndex,
  69325. x, y, width, height, layout);
  69326. }
  69327. else if (maximumLines <= 1)
  69328. {
  69329. fitLineIntoSpace (startIndex, glyphs.size() - startIndex,
  69330. x, y, width, height, f, layout, minimumHorizontalScale);
  69331. }
  69332. else
  69333. {
  69334. Font font (f);
  69335. String txt (text.trim());
  69336. const int length = txt.length();
  69337. const int originalStartIndex = startIndex;
  69338. int numLines = 1;
  69339. if (length <= 12 && ! txt.containsAnyOf (T(" -\t\r\n")))
  69340. maximumLines = 1;
  69341. maximumLines = jmin (maximumLines, length);
  69342. while (numLines < maximumLines)
  69343. {
  69344. ++numLines;
  69345. const float newFontHeight = height / (float) numLines;
  69346. if (newFontHeight < font.getHeight())
  69347. {
  69348. font.setHeight (jmax (8.0f, newFontHeight));
  69349. removeRangeOfGlyphs (startIndex, -1);
  69350. addLineOfText (font, txt, x, y);
  69351. lineWidth = glyphs.getUnchecked (glyphs.size() - 1)->getRight()
  69352. - glyphs.getUnchecked (startIndex)->getLeft();
  69353. }
  69354. if (numLines > lineWidth / width || newFontHeight < 8.0f)
  69355. break;
  69356. }
  69357. if (numLines < 1)
  69358. numLines = 1;
  69359. float lineY = y;
  69360. float widthPerLine = lineWidth / numLines;
  69361. int lastLineStartIndex = 0;
  69362. for (int line = 0; line < numLines; ++line)
  69363. {
  69364. int i = startIndex;
  69365. lastLineStartIndex = i;
  69366. float lineStartX = glyphs.getUnchecked (startIndex)->getLeft();
  69367. if (line == numLines - 1)
  69368. {
  69369. widthPerLine = width;
  69370. i = glyphs.size();
  69371. }
  69372. else
  69373. {
  69374. while (i < glyphs.size())
  69375. {
  69376. lineWidth = (glyphs.getUnchecked (i)->getRight() - lineStartX);
  69377. if (lineWidth > widthPerLine)
  69378. {
  69379. // got to a point where the line's too long, so skip forward to find a
  69380. // good place to break it..
  69381. const int searchStartIndex = i;
  69382. while (i < glyphs.size())
  69383. {
  69384. if ((glyphs.getUnchecked (i)->getRight() - lineStartX) * minimumHorizontalScale < width)
  69385. {
  69386. if (glyphs.getUnchecked (i)->isWhitespace()
  69387. || glyphs.getUnchecked (i)->getCharacter() == T('-'))
  69388. {
  69389. ++i;
  69390. break;
  69391. }
  69392. }
  69393. else
  69394. {
  69395. // can't find a suitable break, so try looking backwards..
  69396. i = searchStartIndex;
  69397. for (int back = 1; back < jmin (5, i - startIndex - 1); ++back)
  69398. {
  69399. if (glyphs.getUnchecked (i - back)->isWhitespace()
  69400. || glyphs.getUnchecked (i - back)->getCharacter() == T('-'))
  69401. {
  69402. i -= back - 1;
  69403. break;
  69404. }
  69405. }
  69406. break;
  69407. }
  69408. ++i;
  69409. }
  69410. break;
  69411. }
  69412. ++i;
  69413. }
  69414. int wsStart = i;
  69415. while (wsStart > 0 && glyphs.getUnchecked (wsStart - 1)->isWhitespace())
  69416. --wsStart;
  69417. int wsEnd = i;
  69418. while (wsEnd < glyphs.size() && glyphs.getUnchecked (wsEnd)->isWhitespace())
  69419. ++wsEnd;
  69420. removeRangeOfGlyphs (wsStart, wsEnd - wsStart);
  69421. i = jmax (wsStart, startIndex + 1);
  69422. }
  69423. i -= fitLineIntoSpace (startIndex, i - startIndex,
  69424. x, lineY, width, font.getHeight(), font,
  69425. layout.getOnlyHorizontalFlags() | Justification::verticallyCentred,
  69426. minimumHorizontalScale);
  69427. startIndex = i;
  69428. lineY += font.getHeight();
  69429. if (startIndex >= glyphs.size())
  69430. break;
  69431. }
  69432. justifyGlyphs (originalStartIndex, glyphs.size() - originalStartIndex,
  69433. x, y, width, height, layout.getFlags() & ~Justification::horizontallyJustified);
  69434. }
  69435. }
  69436. }
  69437. void GlyphArrangement::moveRangeOfGlyphs (int startIndex, int num,
  69438. const float dx, const float dy)
  69439. {
  69440. jassert (startIndex >= 0);
  69441. if (dx != 0.0f || dy != 0.0f)
  69442. {
  69443. if (num < 0 || startIndex + num > glyphs.size())
  69444. num = glyphs.size() - startIndex;
  69445. while (--num >= 0)
  69446. glyphs.getUnchecked (startIndex++)->moveBy (dx, dy);
  69447. }
  69448. }
  69449. int GlyphArrangement::fitLineIntoSpace (int start, int numGlyphs, float x, float y, float w, float h, const Font& font,
  69450. const Justification& justification, float minimumHorizontalScale)
  69451. {
  69452. int numDeleted = 0;
  69453. const float lineStartX = glyphs.getUnchecked (start)->getLeft();
  69454. float lineWidth = glyphs.getUnchecked (start + numGlyphs - 1)->getRight() - lineStartX;
  69455. if (lineWidth > w)
  69456. {
  69457. if (minimumHorizontalScale < 1.0f)
  69458. {
  69459. stretchRangeOfGlyphs (start, numGlyphs, jmax (minimumHorizontalScale, w / lineWidth));
  69460. lineWidth = glyphs.getUnchecked (start + numGlyphs - 1)->getRight() - lineStartX - 0.5f;
  69461. }
  69462. if (lineWidth > w)
  69463. {
  69464. numDeleted = insertEllipsis (font, lineStartX + w, start, start + numGlyphs);
  69465. numGlyphs -= numDeleted;
  69466. }
  69467. }
  69468. justifyGlyphs (start, numGlyphs, x, y, w, h, justification);
  69469. return numDeleted;
  69470. }
  69471. void GlyphArrangement::stretchRangeOfGlyphs (int startIndex, int num,
  69472. const float horizontalScaleFactor)
  69473. {
  69474. jassert (startIndex >= 0);
  69475. if (num < 0 || startIndex + num > glyphs.size())
  69476. num = glyphs.size() - startIndex;
  69477. if (num > 0)
  69478. {
  69479. const float xAnchor = glyphs.getUnchecked (startIndex)->getLeft();
  69480. while (--num >= 0)
  69481. {
  69482. PositionedGlyph* const pg = glyphs.getUnchecked (startIndex++);
  69483. pg->x = xAnchor + (pg->x - xAnchor) * horizontalScaleFactor;
  69484. pg->font.setHorizontalScale (pg->font.getHorizontalScale() * horizontalScaleFactor);
  69485. pg->w *= horizontalScaleFactor;
  69486. }
  69487. }
  69488. }
  69489. void GlyphArrangement::getBoundingBox (int startIndex, int num,
  69490. float& left,
  69491. float& top,
  69492. float& right,
  69493. float& bottom,
  69494. const bool includeWhitespace) const
  69495. {
  69496. jassert (startIndex >= 0);
  69497. if (num < 0 || startIndex + num > glyphs.size())
  69498. num = glyphs.size() - startIndex;
  69499. left = 0.0f;
  69500. top = 0.0f;
  69501. right = 0.0f;
  69502. bottom = 0.0f;
  69503. bool isFirst = true;
  69504. while (--num >= 0)
  69505. {
  69506. const PositionedGlyph* const pg = glyphs.getUnchecked (startIndex++);
  69507. if (includeWhitespace || ! pg->isWhitespace())
  69508. {
  69509. if (isFirst)
  69510. {
  69511. isFirst = false;
  69512. left = pg->getLeft();
  69513. top = pg->getTop();
  69514. right = pg->getRight();
  69515. bottom = pg->getBottom();
  69516. }
  69517. else
  69518. {
  69519. left = jmin (left, pg->getLeft());
  69520. top = jmin (top, pg->getTop());
  69521. right = jmax (right, pg->getRight());
  69522. bottom = jmax (bottom, pg->getBottom());
  69523. }
  69524. }
  69525. }
  69526. }
  69527. void GlyphArrangement::justifyGlyphs (const int startIndex,
  69528. const int num,
  69529. const float x, const float y,
  69530. const float width, const float height,
  69531. const Justification& justification)
  69532. {
  69533. jassert (num >= 0 && startIndex >= 0);
  69534. if (glyphs.size() > 0 && num > 0)
  69535. {
  69536. float left, top, right, bottom;
  69537. getBoundingBox (startIndex, num, left, top, right, bottom,
  69538. ! justification.testFlags (Justification::horizontallyJustified
  69539. | Justification::horizontallyCentred));
  69540. float deltaX = 0.0f;
  69541. if (justification.testFlags (Justification::horizontallyJustified))
  69542. deltaX = x - left;
  69543. else if (justification.testFlags (Justification::horizontallyCentred))
  69544. deltaX = x + (width - (right - left)) * 0.5f - left;
  69545. else if (justification.testFlags (Justification::right))
  69546. deltaX = (x + width) - right;
  69547. else
  69548. deltaX = x - left;
  69549. float deltaY = 0.0f;
  69550. if (justification.testFlags (Justification::top))
  69551. deltaY = y - top;
  69552. else if (justification.testFlags (Justification::bottom))
  69553. deltaY = (y + height) - bottom;
  69554. else
  69555. deltaY = y + (height - (bottom - top)) * 0.5f - top;
  69556. moveRangeOfGlyphs (startIndex, num, deltaX, deltaY);
  69557. if (justification.testFlags (Justification::horizontallyJustified))
  69558. {
  69559. int lineStart = 0;
  69560. float baseY = glyphs.getUnchecked (startIndex)->getBaselineY();
  69561. int i;
  69562. for (i = 0; i < num; ++i)
  69563. {
  69564. const float glyphY = glyphs.getUnchecked (startIndex + i)->getBaselineY();
  69565. if (glyphY != baseY)
  69566. {
  69567. spreadOutLine (startIndex + lineStart, i - lineStart, width);
  69568. lineStart = i;
  69569. baseY = glyphY;
  69570. }
  69571. }
  69572. if (i > lineStart)
  69573. spreadOutLine (startIndex + lineStart, i - lineStart, width);
  69574. }
  69575. }
  69576. }
  69577. void GlyphArrangement::spreadOutLine (const int start, const int num, const float targetWidth)
  69578. {
  69579. if (start + num < glyphs.size()
  69580. && glyphs.getUnchecked (start + num - 1)->getCharacter() != T('\r')
  69581. && glyphs.getUnchecked (start + num - 1)->getCharacter() != T('\n'))
  69582. {
  69583. int numSpaces = 0;
  69584. int spacesAtEnd = 0;
  69585. for (int i = 0; i < num; ++i)
  69586. {
  69587. if (glyphs.getUnchecked (start + i)->isWhitespace())
  69588. {
  69589. ++spacesAtEnd;
  69590. ++numSpaces;
  69591. }
  69592. else
  69593. {
  69594. spacesAtEnd = 0;
  69595. }
  69596. }
  69597. numSpaces -= spacesAtEnd;
  69598. if (numSpaces > 0)
  69599. {
  69600. const float startX = glyphs.getUnchecked (start)->getLeft();
  69601. const float endX = glyphs.getUnchecked (start + num - 1 - spacesAtEnd)->getRight();
  69602. const float extraPaddingBetweenWords
  69603. = (targetWidth - (endX - startX)) / (float) numSpaces;
  69604. float deltaX = 0.0f;
  69605. for (int i = 0; i < num; ++i)
  69606. {
  69607. glyphs.getUnchecked (start + i)->moveBy (deltaX, 0.0f);
  69608. if (glyphs.getUnchecked (start + i)->isWhitespace())
  69609. deltaX += extraPaddingBetweenWords;
  69610. }
  69611. }
  69612. }
  69613. }
  69614. void GlyphArrangement::draw (const Graphics& g) const
  69615. {
  69616. for (int i = 0; i < glyphs.size(); ++i)
  69617. {
  69618. const PositionedGlyph* const pg = glyphs.getUnchecked(i);
  69619. if (pg->font.isUnderlined())
  69620. {
  69621. const float lineThickness = (pg->font.getDescent()) * 0.3f;
  69622. float nextX = pg->x + pg->w;
  69623. if (i < glyphs.size() - 1 && glyphs.getUnchecked (i + 1)->y == pg->y)
  69624. nextX = glyphs.getUnchecked (i + 1)->x;
  69625. g.fillRect (pg->x, pg->y + lineThickness * 2.0f,
  69626. nextX - pg->x, lineThickness);
  69627. }
  69628. pg->draw (g);
  69629. }
  69630. }
  69631. void GlyphArrangement::draw (const Graphics& g, const AffineTransform& transform) const
  69632. {
  69633. for (int i = 0; i < glyphs.size(); ++i)
  69634. {
  69635. const PositionedGlyph* const pg = glyphs.getUnchecked(i);
  69636. if (pg->font.isUnderlined())
  69637. {
  69638. const float lineThickness = (pg->font.getDescent()) * 0.3f;
  69639. float nextX = pg->x + pg->w;
  69640. if (i < glyphs.size() - 1 && glyphs.getUnchecked (i + 1)->y == pg->y)
  69641. nextX = glyphs.getUnchecked (i + 1)->x;
  69642. Path p;
  69643. p.addLineSegment (pg->x, pg->y + lineThickness * 2.0f,
  69644. nextX, pg->y + lineThickness * 2.0f,
  69645. lineThickness);
  69646. g.fillPath (p, transform);
  69647. }
  69648. pg->draw (g, transform);
  69649. }
  69650. }
  69651. void GlyphArrangement::createPath (Path& path) const
  69652. {
  69653. for (int i = 0; i < glyphs.size(); ++i)
  69654. glyphs.getUnchecked (i)->createPath (path);
  69655. }
  69656. int GlyphArrangement::findGlyphIndexAt (float x, float y) const
  69657. {
  69658. for (int i = 0; i < glyphs.size(); ++i)
  69659. if (glyphs.getUnchecked (i)->hitTest (x, y))
  69660. return i;
  69661. return -1;
  69662. }
  69663. END_JUCE_NAMESPACE
  69664. /*** End of inlined file: juce_GlyphArrangement.cpp ***/
  69665. /*** Start of inlined file: juce_TextLayout.cpp ***/
  69666. BEGIN_JUCE_NAMESPACE
  69667. class TextLayout::Token
  69668. {
  69669. public:
  69670. String text;
  69671. Font font;
  69672. int x, y, w, h;
  69673. int line, lineHeight;
  69674. bool isWhitespace, isNewLine;
  69675. Token (const String& t,
  69676. const Font& f,
  69677. const bool isWhitespace_) throw()
  69678. : text (t),
  69679. font (f),
  69680. x(0),
  69681. y(0),
  69682. isWhitespace (isWhitespace_)
  69683. {
  69684. w = font.getStringWidth (t);
  69685. h = roundToInt (f.getHeight());
  69686. isNewLine = t.containsAnyOf (T("\r\n"));
  69687. }
  69688. Token (const Token& other) throw()
  69689. : text (other.text),
  69690. font (other.font),
  69691. x (other.x),
  69692. y (other.y),
  69693. w (other.w),
  69694. h (other.h),
  69695. line (other.line),
  69696. lineHeight (other.lineHeight),
  69697. isWhitespace (other.isWhitespace),
  69698. isNewLine (other.isNewLine)
  69699. {
  69700. }
  69701. ~Token() throw()
  69702. {
  69703. }
  69704. void draw (Graphics& g,
  69705. const int xOffset,
  69706. const int yOffset) throw()
  69707. {
  69708. if (! isWhitespace)
  69709. {
  69710. g.setFont (font);
  69711. g.drawSingleLineText (text.trimEnd(),
  69712. xOffset + x,
  69713. yOffset + y + (lineHeight - h)
  69714. + roundToInt (font.getAscent()));
  69715. }
  69716. }
  69717. juce_UseDebuggingNewOperator
  69718. };
  69719. TextLayout::TextLayout() throw()
  69720. : totalLines (0)
  69721. {
  69722. tokens.ensureStorageAllocated (64);
  69723. }
  69724. TextLayout::TextLayout (const String& text,
  69725. const Font& font) throw()
  69726. : totalLines (0)
  69727. {
  69728. tokens.ensureStorageAllocated (64);
  69729. appendText (text, font);
  69730. }
  69731. TextLayout::TextLayout (const TextLayout& other) throw()
  69732. : totalLines (0)
  69733. {
  69734. *this = other;
  69735. }
  69736. TextLayout& TextLayout::operator= (const TextLayout& other) throw()
  69737. {
  69738. if (this != &other)
  69739. {
  69740. clear();
  69741. totalLines = other.totalLines;
  69742. for (int i = 0; i < other.tokens.size(); ++i)
  69743. tokens.add (new Token (*other.tokens.getUnchecked(i)));
  69744. }
  69745. return *this;
  69746. }
  69747. TextLayout::~TextLayout() throw()
  69748. {
  69749. clear();
  69750. }
  69751. void TextLayout::clear() throw()
  69752. {
  69753. tokens.clear();
  69754. totalLines = 0;
  69755. }
  69756. void TextLayout::appendText (const String& text,
  69757. const Font& font) throw()
  69758. {
  69759. const tchar* t = text;
  69760. String currentString;
  69761. int lastCharType = 0;
  69762. for (;;)
  69763. {
  69764. const tchar c = *t++;
  69765. if (c == 0)
  69766. break;
  69767. int charType;
  69768. if (c == T('\r') || c == T('\n'))
  69769. {
  69770. charType = 0;
  69771. }
  69772. else if (CharacterFunctions::isWhitespace (c))
  69773. {
  69774. charType = 2;
  69775. }
  69776. else
  69777. {
  69778. charType = 1;
  69779. }
  69780. if (charType == 0 || charType != lastCharType)
  69781. {
  69782. if (currentString.isNotEmpty())
  69783. {
  69784. tokens.add (new Token (currentString, font,
  69785. lastCharType == 2 || lastCharType == 0));
  69786. }
  69787. currentString = String::charToString (c);
  69788. if (c == T('\r') && *t == T('\n'))
  69789. currentString += *t++;
  69790. }
  69791. else
  69792. {
  69793. currentString += c;
  69794. }
  69795. lastCharType = charType;
  69796. }
  69797. if (currentString.isNotEmpty())
  69798. tokens.add (new Token (currentString, font, lastCharType == 2));
  69799. }
  69800. void TextLayout::setText (const String& text, const Font& font) throw()
  69801. {
  69802. clear();
  69803. appendText (text, font);
  69804. }
  69805. void TextLayout::layout (int maxWidth,
  69806. const Justification& justification,
  69807. const bool attemptToBalanceLineLengths) throw()
  69808. {
  69809. if (attemptToBalanceLineLengths)
  69810. {
  69811. const int originalW = maxWidth;
  69812. int bestWidth = maxWidth;
  69813. float bestLineProportion = 0.0f;
  69814. while (maxWidth > originalW / 2)
  69815. {
  69816. layout (maxWidth, justification, false);
  69817. if (getNumLines() <= 1)
  69818. return;
  69819. const int lastLineW = getLineWidth (getNumLines() - 1);
  69820. const int lastButOneLineW = getLineWidth (getNumLines() - 2);
  69821. const float prop = lastLineW / (float) lastButOneLineW;
  69822. if (prop > 0.9f)
  69823. return;
  69824. if (prop > bestLineProportion)
  69825. {
  69826. bestLineProportion = prop;
  69827. bestWidth = maxWidth;
  69828. }
  69829. maxWidth -= 10;
  69830. }
  69831. layout (bestWidth, justification, false);
  69832. }
  69833. else
  69834. {
  69835. int x = 0;
  69836. int y = 0;
  69837. int h = 0;
  69838. totalLines = 0;
  69839. int i;
  69840. for (i = 0; i < tokens.size(); ++i)
  69841. {
  69842. Token* const t = tokens.getUnchecked(i);
  69843. t->x = x;
  69844. t->y = y;
  69845. t->line = totalLines;
  69846. x += t->w;
  69847. h = jmax (h, t->h);
  69848. const Token* nextTok = tokens [i + 1];
  69849. if (nextTok == 0)
  69850. break;
  69851. if (t->isNewLine || ((! nextTok->isWhitespace) && x + nextTok->w > maxWidth))
  69852. {
  69853. // finished a line, so go back and update the heights of the things on it
  69854. for (int j = i; j >= 0; --j)
  69855. {
  69856. Token* const tok = tokens.getUnchecked(j);
  69857. if (tok->line == totalLines)
  69858. tok->lineHeight = h;
  69859. else
  69860. break;
  69861. }
  69862. x = 0;
  69863. y += h;
  69864. h = 0;
  69865. ++totalLines;
  69866. }
  69867. }
  69868. // finished a line, so go back and update the heights of the things on it
  69869. for (int j = jmin (i, tokens.size() - 1); j >= 0; --j)
  69870. {
  69871. Token* const t = tokens.getUnchecked(j);
  69872. if (t->line == totalLines)
  69873. t->lineHeight = h;
  69874. else
  69875. break;
  69876. }
  69877. ++totalLines;
  69878. if (! justification.testFlags (Justification::left))
  69879. {
  69880. int totalW = getWidth();
  69881. for (i = totalLines; --i >= 0;)
  69882. {
  69883. const int lineW = getLineWidth (i);
  69884. int dx = 0;
  69885. if (justification.testFlags (Justification::horizontallyCentred))
  69886. dx = (totalW - lineW) / 2;
  69887. else if (justification.testFlags (Justification::right))
  69888. dx = totalW - lineW;
  69889. for (int j = tokens.size(); --j >= 0;)
  69890. {
  69891. Token* const t = tokens.getUnchecked(j);
  69892. if (t->line == i)
  69893. t->x += dx;
  69894. }
  69895. }
  69896. }
  69897. }
  69898. }
  69899. int TextLayout::getLineWidth (const int lineNumber) const throw()
  69900. {
  69901. int maxW = 0;
  69902. for (int i = tokens.size(); --i >= 0;)
  69903. {
  69904. const Token* const t = tokens.getUnchecked(i);
  69905. if (t->line == lineNumber && ! t->isWhitespace)
  69906. maxW = jmax (maxW, t->x + t->w);
  69907. }
  69908. return maxW;
  69909. }
  69910. int TextLayout::getWidth() const throw()
  69911. {
  69912. int maxW = 0;
  69913. for (int i = tokens.size(); --i >= 0;)
  69914. {
  69915. const Token* const t = tokens.getUnchecked(i);
  69916. if (! t->isWhitespace)
  69917. maxW = jmax (maxW, t->x + t->w);
  69918. }
  69919. return maxW;
  69920. }
  69921. int TextLayout::getHeight() const throw()
  69922. {
  69923. int maxH = 0;
  69924. for (int i = tokens.size(); --i >= 0;)
  69925. {
  69926. const Token* const t = tokens.getUnchecked(i);
  69927. if (! t->isWhitespace)
  69928. maxH = jmax (maxH, t->y + t->h);
  69929. }
  69930. return maxH;
  69931. }
  69932. void TextLayout::draw (Graphics& g,
  69933. const int xOffset,
  69934. const int yOffset) const throw()
  69935. {
  69936. for (int i = tokens.size(); --i >= 0;)
  69937. tokens.getUnchecked(i)->draw (g, xOffset, yOffset);
  69938. }
  69939. void TextLayout::drawWithin (Graphics& g,
  69940. int x, int y, int w, int h,
  69941. const Justification& justification) const throw()
  69942. {
  69943. justification.applyToRectangle (x, y, getWidth(), getHeight(),
  69944. x, y, w, h);
  69945. draw (g, x, y);
  69946. }
  69947. END_JUCE_NAMESPACE
  69948. /*** End of inlined file: juce_TextLayout.cpp ***/
  69949. /*** Start of inlined file: juce_Typeface.cpp ***/
  69950. BEGIN_JUCE_NAMESPACE
  69951. Typeface::Typeface (const String& name_) throw()
  69952. : name (name_)
  69953. {
  69954. }
  69955. Typeface::~Typeface()
  69956. {
  69957. }
  69958. class CustomTypeface::GlyphInfo
  69959. {
  69960. public:
  69961. GlyphInfo (const juce_wchar character_, const Path& path_, const float width_) throw()
  69962. : character (character_), path (path_), width (width_)
  69963. {
  69964. }
  69965. ~GlyphInfo() throw()
  69966. {
  69967. }
  69968. struct KerningPair
  69969. {
  69970. juce_wchar character2;
  69971. float kerningAmount;
  69972. };
  69973. void addKerningPair (const juce_wchar subsequentCharacter,
  69974. const float extraKerningAmount) throw()
  69975. {
  69976. KerningPair kp;
  69977. kp.character2 = subsequentCharacter;
  69978. kp.kerningAmount = extraKerningAmount;
  69979. kerningPairs.add (kp);
  69980. }
  69981. float getHorizontalSpacing (const juce_wchar subsequentCharacter) const throw()
  69982. {
  69983. if (subsequentCharacter != 0)
  69984. {
  69985. for (int i = kerningPairs.size(); --i >= 0;)
  69986. if (kerningPairs.getReference(i).character2 == subsequentCharacter)
  69987. return width + kerningPairs.getReference(i).kerningAmount;
  69988. }
  69989. return width;
  69990. }
  69991. const juce_wchar character;
  69992. const Path path;
  69993. float width;
  69994. Array <KerningPair> kerningPairs;
  69995. juce_UseDebuggingNewOperator
  69996. private:
  69997. GlyphInfo (const GlyphInfo&);
  69998. GlyphInfo& operator= (const GlyphInfo&);
  69999. };
  70000. CustomTypeface::CustomTypeface()
  70001. : Typeface (String::empty)
  70002. {
  70003. clear();
  70004. }
  70005. CustomTypeface::CustomTypeface (InputStream& serialisedTypefaceStream)
  70006. : Typeface (String::empty)
  70007. {
  70008. clear();
  70009. GZIPDecompressorInputStream gzin (&serialisedTypefaceStream, false);
  70010. BufferedInputStream in (&gzin, 32768, false);
  70011. name = in.readString();
  70012. isBold = in.readBool();
  70013. isItalic = in.readBool();
  70014. ascent = in.readFloat();
  70015. defaultCharacter = (juce_wchar) in.readShort();
  70016. int i, numChars = in.readInt();
  70017. for (i = 0; i < numChars; ++i)
  70018. {
  70019. const juce_wchar c = (juce_wchar) in.readShort();
  70020. const float width = in.readFloat();
  70021. Path p;
  70022. p.loadPathFromStream (in);
  70023. addGlyph (c, p, width);
  70024. }
  70025. const int numKerningPairs = in.readInt();
  70026. for (i = 0; i < numKerningPairs; ++i)
  70027. {
  70028. const juce_wchar char1 = (juce_wchar) in.readShort();
  70029. const juce_wchar char2 = (juce_wchar) in.readShort();
  70030. addKerningPair (char1, char2, in.readFloat());
  70031. }
  70032. }
  70033. CustomTypeface::~CustomTypeface()
  70034. {
  70035. }
  70036. void CustomTypeface::clear()
  70037. {
  70038. defaultCharacter = 0;
  70039. ascent = 1.0f;
  70040. isBold = isItalic = false;
  70041. zeromem (lookupTable, sizeof (lookupTable));
  70042. glyphs.clear();
  70043. }
  70044. void CustomTypeface::setCharacteristics (const String& name_, const float ascent_, const bool isBold_,
  70045. const bool isItalic_, const juce_wchar defaultCharacter_) throw()
  70046. {
  70047. name = name_;
  70048. defaultCharacter = defaultCharacter_;
  70049. ascent = ascent_;
  70050. isBold = isBold_;
  70051. isItalic = isItalic_;
  70052. }
  70053. void CustomTypeface::addGlyph (const juce_wchar character, const Path& path, const float width) throw()
  70054. {
  70055. // Check that you're not trying to add the same character twice..
  70056. jassert (findGlyph (character, false) == 0);
  70057. if (((unsigned int) character) < (unsigned int) numElementsInArray (lookupTable))
  70058. lookupTable [character] = (short) glyphs.size();
  70059. glyphs.add (new GlyphInfo (character, path, width));
  70060. }
  70061. void CustomTypeface::addKerningPair (const juce_wchar char1, const juce_wchar char2, const float extraAmount) throw()
  70062. {
  70063. if (extraAmount != 0)
  70064. {
  70065. GlyphInfo* const g = findGlyph (char1, true);
  70066. jassert (g != 0); // can only add kerning pairs for characters that exist!
  70067. if (g != 0)
  70068. g->addKerningPair (char2, extraAmount);
  70069. }
  70070. }
  70071. CustomTypeface::GlyphInfo* CustomTypeface::findGlyph (const juce_wchar character, const bool loadIfNeeded) throw()
  70072. {
  70073. if (((unsigned int) character) < (unsigned int) numElementsInArray (lookupTable) && lookupTable [character] > 0)
  70074. return glyphs [(int) lookupTable [(int) character]];
  70075. for (int i = 0; i < glyphs.size(); ++i)
  70076. {
  70077. GlyphInfo* const g = glyphs.getUnchecked(i);
  70078. if (g->character == character)
  70079. return g;
  70080. }
  70081. if (loadIfNeeded && loadGlyphIfPossible (character))
  70082. return findGlyph (character, false);
  70083. return 0;
  70084. }
  70085. CustomTypeface::GlyphInfo* CustomTypeface::findGlyphSubstituting (const juce_wchar character) throw()
  70086. {
  70087. GlyphInfo* glyph = findGlyph (character, true);
  70088. if (glyph == 0)
  70089. {
  70090. if (CharacterFunctions::isWhitespace (character) && character != L' ')
  70091. glyph = findGlyph (L' ', true);
  70092. if (glyph == 0)
  70093. {
  70094. const Font fallbackFont (Font::getFallbackFontName(), 10, 0);
  70095. Typeface* const fallbackTypeface = fallbackFont.getTypeface();
  70096. if (fallbackTypeface != 0 && fallbackTypeface != this)
  70097. {
  70098. //xxx
  70099. }
  70100. if (glyph == 0)
  70101. glyph = findGlyph (defaultCharacter, true);
  70102. }
  70103. }
  70104. return glyph;
  70105. }
  70106. bool CustomTypeface::loadGlyphIfPossible (const juce_wchar /*characterNeeded*/)
  70107. {
  70108. return false;
  70109. }
  70110. void CustomTypeface::addGlyphsFromOtherTypeface (Typeface& typefaceToCopy, juce_wchar characterStartIndex, int numCharacters) throw()
  70111. {
  70112. for (int i = 0; i < numCharacters; ++i)
  70113. {
  70114. const juce_wchar c = (juce_wchar) (characterStartIndex + i);
  70115. Array <int> glyphIndexes;
  70116. Array <float> offsets;
  70117. typefaceToCopy.getGlyphPositions (String::charToString (c), glyphIndexes, offsets);
  70118. const int glyphIndex = glyphIndexes.getFirst();
  70119. if (glyphIndex >= 0 && glyphIndexes.size() > 0)
  70120. {
  70121. const float glyphWidth = offsets[1];
  70122. Path p;
  70123. typefaceToCopy.getOutlineForGlyph (glyphIndex, p);
  70124. addGlyph (c, p, glyphWidth);
  70125. for (int j = glyphs.size() - 1; --j >= 0;)
  70126. {
  70127. const juce_wchar char2 = glyphs.getUnchecked (j)->character;
  70128. glyphIndexes.clearQuick();
  70129. offsets.clearQuick();
  70130. typefaceToCopy.getGlyphPositions (String::charToString (c) + String::charToString (char2), glyphIndexes, offsets);
  70131. if (offsets.size() > 1)
  70132. addKerningPair (c, char2, offsets[1] - glyphWidth);
  70133. }
  70134. }
  70135. }
  70136. }
  70137. bool CustomTypeface::writeToStream (OutputStream& outputStream)
  70138. {
  70139. GZIPCompressorOutputStream out (&outputStream);
  70140. out.writeString (name);
  70141. out.writeBool (isBold);
  70142. out.writeBool (isItalic);
  70143. out.writeFloat (ascent);
  70144. out.writeShort ((short) (unsigned short) defaultCharacter);
  70145. out.writeInt (glyphs.size());
  70146. int i, numKerningPairs = 0;
  70147. for (i = 0; i < glyphs.size(); ++i)
  70148. {
  70149. const GlyphInfo* const g = glyphs.getUnchecked (i);
  70150. out.writeShort ((short) (unsigned short) g->character);
  70151. out.writeFloat (g->width);
  70152. g->path.writePathToStream (out);
  70153. numKerningPairs += g->kerningPairs.size();
  70154. }
  70155. out.writeInt (numKerningPairs);
  70156. for (i = 0; i < glyphs.size(); ++i)
  70157. {
  70158. const GlyphInfo* const g = glyphs.getUnchecked (i);
  70159. for (int j = 0; j < g->kerningPairs.size(); ++j)
  70160. {
  70161. const GlyphInfo::KerningPair& p = g->kerningPairs.getReference (j);
  70162. out.writeShort ((short) (unsigned short) g->character);
  70163. out.writeShort ((short) (unsigned short) p.character2);
  70164. out.writeFloat (p.kerningAmount);
  70165. }
  70166. }
  70167. return true;
  70168. }
  70169. float CustomTypeface::getAscent() const
  70170. {
  70171. return ascent;
  70172. }
  70173. float CustomTypeface::getDescent() const
  70174. {
  70175. return 1.0f - ascent;
  70176. }
  70177. float CustomTypeface::getStringWidth (const String& text)
  70178. {
  70179. float x = 0;
  70180. const juce_wchar* t = (const juce_wchar*) text;
  70181. while (*t != 0)
  70182. {
  70183. const GlyphInfo* const glyph = findGlyphSubstituting (*t++);
  70184. if (glyph != 0)
  70185. x += glyph->getHorizontalSpacing (*t);
  70186. }
  70187. return x;
  70188. }
  70189. void CustomTypeface::getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array<float>& xOffsets)
  70190. {
  70191. xOffsets.add (0);
  70192. float x = 0;
  70193. const juce_wchar* t = (const juce_wchar*) text;
  70194. while (*t != 0)
  70195. {
  70196. const juce_wchar c = *t++;
  70197. const GlyphInfo* const glyph = findGlyphSubstituting (c);
  70198. if (glyph != 0)
  70199. {
  70200. x += glyph->getHorizontalSpacing (*t);
  70201. resultGlyphs.add ((int) glyph->character);
  70202. xOffsets.add (x);
  70203. }
  70204. }
  70205. }
  70206. bool CustomTypeface::getOutlineForGlyph (int glyphNumber, Path& path)
  70207. {
  70208. const GlyphInfo* const glyph = findGlyphSubstituting ((juce_wchar) glyphNumber);
  70209. if (glyph != 0)
  70210. {
  70211. path = glyph->path;
  70212. return true;
  70213. }
  70214. return false;
  70215. }
  70216. END_JUCE_NAMESPACE
  70217. /*** End of inlined file: juce_Typeface.cpp ***/
  70218. /*** Start of inlined file: juce_AffineTransform.cpp ***/
  70219. BEGIN_JUCE_NAMESPACE
  70220. AffineTransform::AffineTransform() throw()
  70221. : mat00 (1.0f),
  70222. mat01 (0),
  70223. mat02 (0),
  70224. mat10 (0),
  70225. mat11 (1.0f),
  70226. mat12 (0)
  70227. {
  70228. }
  70229. AffineTransform::AffineTransform (const AffineTransform& other) throw()
  70230. : mat00 (other.mat00),
  70231. mat01 (other.mat01),
  70232. mat02 (other.mat02),
  70233. mat10 (other.mat10),
  70234. mat11 (other.mat11),
  70235. mat12 (other.mat12)
  70236. {
  70237. }
  70238. AffineTransform::AffineTransform (const float mat00_,
  70239. const float mat01_,
  70240. const float mat02_,
  70241. const float mat10_,
  70242. const float mat11_,
  70243. const float mat12_) throw()
  70244. : mat00 (mat00_),
  70245. mat01 (mat01_),
  70246. mat02 (mat02_),
  70247. mat10 (mat10_),
  70248. mat11 (mat11_),
  70249. mat12 (mat12_)
  70250. {
  70251. }
  70252. AffineTransform& AffineTransform::operator= (const AffineTransform& other) throw()
  70253. {
  70254. mat00 = other.mat00;
  70255. mat01 = other.mat01;
  70256. mat02 = other.mat02;
  70257. mat10 = other.mat10;
  70258. mat11 = other.mat11;
  70259. mat12 = other.mat12;
  70260. return *this;
  70261. }
  70262. bool AffineTransform::operator== (const AffineTransform& other) const throw()
  70263. {
  70264. return mat00 == other.mat00
  70265. && mat01 == other.mat01
  70266. && mat02 == other.mat02
  70267. && mat10 == other.mat10
  70268. && mat11 == other.mat11
  70269. && mat12 == other.mat12;
  70270. }
  70271. bool AffineTransform::operator!= (const AffineTransform& other) const throw()
  70272. {
  70273. return ! operator== (other);
  70274. }
  70275. bool AffineTransform::isIdentity() const throw()
  70276. {
  70277. return (mat01 == 0)
  70278. && (mat02 == 0)
  70279. && (mat10 == 0)
  70280. && (mat12 == 0)
  70281. && (mat00 == 1.0f)
  70282. && (mat11 == 1.0f);
  70283. }
  70284. const AffineTransform AffineTransform::identity;
  70285. const AffineTransform AffineTransform::followedBy (const AffineTransform& other) const throw()
  70286. {
  70287. return AffineTransform (other.mat00 * mat00 + other.mat01 * mat10,
  70288. other.mat00 * mat01 + other.mat01 * mat11,
  70289. other.mat00 * mat02 + other.mat01 * mat12 + other.mat02,
  70290. other.mat10 * mat00 + other.mat11 * mat10,
  70291. other.mat10 * mat01 + other.mat11 * mat11,
  70292. other.mat10 * mat02 + other.mat11 * mat12 + other.mat12);
  70293. }
  70294. const AffineTransform AffineTransform::followedBy (const float omat00,
  70295. const float omat01,
  70296. const float omat02,
  70297. const float omat10,
  70298. const float omat11,
  70299. const float omat12) const throw()
  70300. {
  70301. return AffineTransform (omat00 * mat00 + omat01 * mat10,
  70302. omat00 * mat01 + omat01 * mat11,
  70303. omat00 * mat02 + omat01 * mat12 + omat02,
  70304. omat10 * mat00 + omat11 * mat10,
  70305. omat10 * mat01 + omat11 * mat11,
  70306. omat10 * mat02 + omat11 * mat12 + omat12);
  70307. }
  70308. const AffineTransform AffineTransform::translated (const float dx,
  70309. const float dy) const throw()
  70310. {
  70311. return AffineTransform (mat00, mat01, mat02 + dx,
  70312. mat10, mat11, mat12 + dy);
  70313. }
  70314. const AffineTransform AffineTransform::translation (const float dx,
  70315. const float dy) throw()
  70316. {
  70317. return AffineTransform (1.0f, 0, dx,
  70318. 0, 1.0f, dy);
  70319. }
  70320. const AffineTransform AffineTransform::rotated (const float rad) const throw()
  70321. {
  70322. const float cosRad = cosf (rad);
  70323. const float sinRad = sinf (rad);
  70324. return followedBy (cosRad, -sinRad, 0,
  70325. sinRad, cosRad, 0);
  70326. }
  70327. const AffineTransform AffineTransform::rotation (const float rad) throw()
  70328. {
  70329. const float cosRad = cosf (rad);
  70330. const float sinRad = sinf (rad);
  70331. return AffineTransform (cosRad, -sinRad, 0,
  70332. sinRad, cosRad, 0);
  70333. }
  70334. const AffineTransform AffineTransform::rotated (const float angle,
  70335. const float pivotX,
  70336. const float pivotY) const throw()
  70337. {
  70338. return translated (-pivotX, -pivotY)
  70339. .rotated (angle)
  70340. .translated (pivotX, pivotY);
  70341. }
  70342. const AffineTransform AffineTransform::rotation (const float angle,
  70343. const float pivotX,
  70344. const float pivotY) throw()
  70345. {
  70346. return translation (-pivotX, -pivotY)
  70347. .rotated (angle)
  70348. .translated (pivotX, pivotY);
  70349. }
  70350. const AffineTransform AffineTransform::scaled (const float factorX,
  70351. const float factorY) const throw()
  70352. {
  70353. return AffineTransform (factorX * mat00, factorX * mat01, factorX * mat02,
  70354. factorY * mat10, factorY * mat11, factorY * mat12);
  70355. }
  70356. const AffineTransform AffineTransform::scale (const float factorX,
  70357. const float factorY) throw()
  70358. {
  70359. return AffineTransform (factorX, 0, 0,
  70360. 0, factorY, 0);
  70361. }
  70362. const AffineTransform AffineTransform::sheared (const float shearX,
  70363. const float shearY) const throw()
  70364. {
  70365. return followedBy (1.0f, shearX, 0,
  70366. shearY, 1.0f, 0);
  70367. }
  70368. const AffineTransform AffineTransform::inverted() const throw()
  70369. {
  70370. double determinant = (mat00 * mat11 - mat10 * mat01);
  70371. if (determinant != 0.0)
  70372. {
  70373. determinant = 1.0 / determinant;
  70374. const float dst00 = (float) (mat11 * determinant);
  70375. const float dst10 = (float) (-mat10 * determinant);
  70376. const float dst01 = (float) (-mat01 * determinant);
  70377. const float dst11 = (float) (mat00 * determinant);
  70378. return AffineTransform (dst00, dst01, -mat02 * dst00 - mat12 * dst01,
  70379. dst10, dst11, -mat02 * dst10 - mat12 * dst11);
  70380. }
  70381. else
  70382. {
  70383. // singularity..
  70384. return *this;
  70385. }
  70386. }
  70387. bool AffineTransform::isSingularity() const throw()
  70388. {
  70389. return (mat00 * mat11 - mat10 * mat01) == 0.0;
  70390. }
  70391. bool AffineTransform::isOnlyTranslation() const throw()
  70392. {
  70393. return (mat01 == 0)
  70394. && (mat10 == 0)
  70395. && (mat00 == 1.0f)
  70396. && (mat11 == 1.0f);
  70397. }
  70398. void AffineTransform::transformPoint (float& x,
  70399. float& y) const throw()
  70400. {
  70401. const float oldX = x;
  70402. x = mat00 * oldX + mat01 * y + mat02;
  70403. y = mat10 * oldX + mat11 * y + mat12;
  70404. }
  70405. void AffineTransform::transformPoint (double& x,
  70406. double& y) const throw()
  70407. {
  70408. const double oldX = x;
  70409. x = mat00 * oldX + mat01 * y + mat02;
  70410. y = mat10 * oldX + mat11 * y + mat12;
  70411. }
  70412. END_JUCE_NAMESPACE
  70413. /*** End of inlined file: juce_AffineTransform.cpp ***/
  70414. /*** Start of inlined file: juce_BorderSize.cpp ***/
  70415. BEGIN_JUCE_NAMESPACE
  70416. BorderSize::BorderSize() throw()
  70417. : top (0),
  70418. left (0),
  70419. bottom (0),
  70420. right (0)
  70421. {
  70422. }
  70423. BorderSize::BorderSize (const BorderSize& other) throw()
  70424. : top (other.top),
  70425. left (other.left),
  70426. bottom (other.bottom),
  70427. right (other.right)
  70428. {
  70429. }
  70430. BorderSize::BorderSize (const int topGap,
  70431. const int leftGap,
  70432. const int bottomGap,
  70433. const int rightGap) throw()
  70434. : top (topGap),
  70435. left (leftGap),
  70436. bottom (bottomGap),
  70437. right (rightGap)
  70438. {
  70439. }
  70440. BorderSize::BorderSize (const int allGaps) throw()
  70441. : top (allGaps),
  70442. left (allGaps),
  70443. bottom (allGaps),
  70444. right (allGaps)
  70445. {
  70446. }
  70447. BorderSize::~BorderSize() throw()
  70448. {
  70449. }
  70450. void BorderSize::setTop (const int newTopGap) throw()
  70451. {
  70452. top = newTopGap;
  70453. }
  70454. void BorderSize::setLeft (const int newLeftGap) throw()
  70455. {
  70456. left = newLeftGap;
  70457. }
  70458. void BorderSize::setBottom (const int newBottomGap) throw()
  70459. {
  70460. bottom = newBottomGap;
  70461. }
  70462. void BorderSize::setRight (const int newRightGap) throw()
  70463. {
  70464. right = newRightGap;
  70465. }
  70466. const Rectangle<int> BorderSize::subtractedFrom (const Rectangle<int>& r) const throw()
  70467. {
  70468. return Rectangle<int> (r.getX() + left,
  70469. r.getY() + top,
  70470. r.getWidth() - (left + right),
  70471. r.getHeight() - (top + bottom));
  70472. }
  70473. void BorderSize::subtractFrom (Rectangle<int>& r) const throw()
  70474. {
  70475. r.setBounds (r.getX() + left,
  70476. r.getY() + top,
  70477. r.getWidth() - (left + right),
  70478. r.getHeight() - (top + bottom));
  70479. }
  70480. const Rectangle<int> BorderSize::addedTo (const Rectangle<int>& r) const throw()
  70481. {
  70482. return Rectangle<int> (r.getX() - left,
  70483. r.getY() - top,
  70484. r.getWidth() + (left + right),
  70485. r.getHeight() + (top + bottom));
  70486. }
  70487. void BorderSize::addTo (Rectangle<int>& r) const throw()
  70488. {
  70489. r.setBounds (r.getX() - left,
  70490. r.getY() - top,
  70491. r.getWidth() + (left + right),
  70492. r.getHeight() + (top + bottom));
  70493. }
  70494. bool BorderSize::operator== (const BorderSize& other) const throw()
  70495. {
  70496. return top == other.top
  70497. && left == other.left
  70498. && bottom == other.bottom
  70499. && right == other.right;
  70500. }
  70501. bool BorderSize::operator!= (const BorderSize& other) const throw()
  70502. {
  70503. return ! operator== (other);
  70504. }
  70505. END_JUCE_NAMESPACE
  70506. /*** End of inlined file: juce_BorderSize.cpp ***/
  70507. /*** Start of inlined file: juce_Line.cpp ***/
  70508. BEGIN_JUCE_NAMESPACE
  70509. static bool juce_lineIntersection (const float x1, const float y1,
  70510. const float x2, const float y2,
  70511. const float x3, const float y3,
  70512. const float x4, const float y4,
  70513. float& intersectionX,
  70514. float& intersectionY) throw()
  70515. {
  70516. if (x2 != x3 || y2 != y3)
  70517. {
  70518. const float dx1 = x2 - x1;
  70519. const float dy1 = y2 - y1;
  70520. const float dx2 = x4 - x3;
  70521. const float dy2 = y4 - y3;
  70522. const float divisor = dx1 * dy2 - dx2 * dy1;
  70523. if (divisor == 0)
  70524. {
  70525. if (! ((dx1 == 0 && dy1 == 0) || (dx2 == 0 && dy2 == 0)))
  70526. {
  70527. if (dy1 == 0 && dy2 != 0)
  70528. {
  70529. const float along = (y1 - y3) / dy2;
  70530. intersectionX = x3 + along * dx2;
  70531. intersectionY = y1;
  70532. return along >= 0 && along <= 1.0f;
  70533. }
  70534. else if (dy2 == 0 && dy1 != 0)
  70535. {
  70536. const float along = (y3 - y1) / dy1;
  70537. intersectionX = x1 + along * dx1;
  70538. intersectionY = y3;
  70539. return along >= 0 && along <= 1.0f;
  70540. }
  70541. else if (dx1 == 0 && dx2 != 0)
  70542. {
  70543. const float along = (x1 - x3) / dx2;
  70544. intersectionX = x1;
  70545. intersectionY = y3 + along * dy2;
  70546. return along >= 0 && along <= 1.0f;
  70547. }
  70548. else if (dx2 == 0 && dx1 != 0)
  70549. {
  70550. const float along = (x3 - x1) / dx1;
  70551. intersectionX = x3;
  70552. intersectionY = y1 + along * dy1;
  70553. return along >= 0 && along <= 1.0f;
  70554. }
  70555. }
  70556. intersectionX = 0.5f * (x2 + x3);
  70557. intersectionY = 0.5f * (y2 + y3);
  70558. return false;
  70559. }
  70560. const float along1 = ((y1 - y3) * dx2 - (x1 - x3) * dy2) / divisor;
  70561. intersectionX = x1 + along1 * dx1;
  70562. intersectionY = y1 + along1 * dy1;
  70563. if (along1 < 0 || along1 > 1.0f)
  70564. return false;
  70565. const float along2 = ((y1 - y3) * dx1 - (x1 - x3) * dy1) / divisor;
  70566. return along2 >= 0 && along2 <= 1.0f;
  70567. }
  70568. intersectionX = x2;
  70569. intersectionY = y2;
  70570. return true;
  70571. }
  70572. Line::Line() throw()
  70573. : startX (0.0f),
  70574. startY (0.0f),
  70575. endX (0.0f),
  70576. endY (0.0f)
  70577. {
  70578. }
  70579. Line::Line (const Line& other) throw()
  70580. : startX (other.startX),
  70581. startY (other.startY),
  70582. endX (other.endX),
  70583. endY (other.endY)
  70584. {
  70585. }
  70586. Line::Line (const float startX_, const float startY_,
  70587. const float endX_, const float endY_) throw()
  70588. : startX (startX_),
  70589. startY (startY_),
  70590. endX (endX_),
  70591. endY (endY_)
  70592. {
  70593. }
  70594. Line::Line (const Point<float>& start,
  70595. const Point<float>& end) throw()
  70596. : startX (start.getX()),
  70597. startY (start.getY()),
  70598. endX (end.getX()),
  70599. endY (end.getY())
  70600. {
  70601. }
  70602. Line& Line::operator= (const Line& other) throw()
  70603. {
  70604. startX = other.startX;
  70605. startY = other.startY;
  70606. endX = other.endX;
  70607. endY = other.endY;
  70608. return *this;
  70609. }
  70610. Line::~Line() throw()
  70611. {
  70612. }
  70613. const Point<float> Line::getStart() const throw()
  70614. {
  70615. return Point<float> (startX, startY);
  70616. }
  70617. const Point<float> Line::getEnd() const throw()
  70618. {
  70619. return Point<float> (endX, endY);
  70620. }
  70621. void Line::setStart (const float newStartX,
  70622. const float newStartY) throw()
  70623. {
  70624. startX = newStartX;
  70625. startY = newStartY;
  70626. }
  70627. void Line::setStart (const Point<float>& newStart) throw()
  70628. {
  70629. startX = newStart.getX();
  70630. startY = newStart.getY();
  70631. }
  70632. void Line::setEnd (const float newEndX,
  70633. const float newEndY) throw()
  70634. {
  70635. endX = newEndX;
  70636. endY = newEndY;
  70637. }
  70638. void Line::setEnd (const Point<float>& newEnd) throw()
  70639. {
  70640. endX = newEnd.getX();
  70641. endY = newEnd.getY();
  70642. }
  70643. bool Line::operator== (const Line& other) const throw()
  70644. {
  70645. return startX == other.startX
  70646. && startY == other.startY
  70647. && endX == other.endX
  70648. && endY == other.endY;
  70649. }
  70650. bool Line::operator!= (const Line& other) const throw()
  70651. {
  70652. return startX != other.startX
  70653. || startY != other.startY
  70654. || endX != other.endX
  70655. || endY != other.endY;
  70656. }
  70657. void Line::applyTransform (const AffineTransform& transform) throw()
  70658. {
  70659. transform.transformPoint (startX, startY);
  70660. transform.transformPoint (endX, endY);
  70661. }
  70662. float Line::getLength() const throw()
  70663. {
  70664. return (float) juce_hypot (startX - endX,
  70665. startY - endY);
  70666. }
  70667. float Line::getAngle() const throw()
  70668. {
  70669. return atan2f (endX - startX,
  70670. endY - startY);
  70671. }
  70672. const Point<float> Line::getPointAlongLine (const float distanceFromStart) const throw()
  70673. {
  70674. const float alpha = distanceFromStart / getLength();
  70675. return Point<float> (startX + (endX - startX) * alpha,
  70676. startY + (endY - startY) * alpha);
  70677. }
  70678. const Point<float> Line::getPointAlongLine (const float offsetX,
  70679. const float offsetY) const throw()
  70680. {
  70681. const float dx = endX - startX;
  70682. const float dy = endY - startY;
  70683. const double length = juce_hypot (dx, dy);
  70684. if (length == 0)
  70685. return Point<float> (startX, startY);
  70686. else
  70687. return Point<float> (startX + (float) (((dx * offsetX) - (dy * offsetY)) / length),
  70688. startY + (float) (((dy * offsetX) + (dx * offsetY)) / length));
  70689. }
  70690. const Point<float> Line::getPointAlongLineProportionally (const float alpha) const throw()
  70691. {
  70692. return Point<float> (startX + (endX - startX) * alpha,
  70693. startY + (endY - startY) * alpha);
  70694. }
  70695. float Line::getDistanceFromLine (const float x,
  70696. const float y) const throw()
  70697. {
  70698. const double dx = endX - startX;
  70699. const double dy = endY - startY;
  70700. const double length = dx * dx + dy * dy;
  70701. if (length > 0)
  70702. {
  70703. const double prop = ((x - startX) * dx + (y - startY) * dy) / length;
  70704. if (prop >= 0.0f && prop < 1.0f)
  70705. {
  70706. return (float) juce_hypot (x - (startX + prop * dx),
  70707. y - (startY + prop * dy));
  70708. }
  70709. }
  70710. return (float) jmin (juce_hypot (x - startX, y - startY),
  70711. juce_hypot (x - endX, y - endY));
  70712. }
  70713. float Line::findNearestPointTo (const float x,
  70714. const float y) const throw()
  70715. {
  70716. const double dx = endX - startX;
  70717. const double dy = endY - startY;
  70718. const double length = dx * dx + dy * dy;
  70719. if (length <= 0.0)
  70720. return 0.0f;
  70721. return jlimit (0.0f, 1.0f,
  70722. (float) (((x - startX) * dx + (y - startY) * dy) / length));
  70723. }
  70724. const Line Line::withShortenedStart (const float distanceToShortenBy) const throw()
  70725. {
  70726. const float length = getLength();
  70727. return Line (getPointAlongLine (jmin (distanceToShortenBy, length)),
  70728. getEnd());
  70729. }
  70730. const Line Line::withShortenedEnd (const float distanceToShortenBy) const throw()
  70731. {
  70732. const float length = getLength();
  70733. return Line (getStart(),
  70734. getPointAlongLine (length - jmin (distanceToShortenBy, length)));
  70735. }
  70736. bool Line::clipToPath (const Path& path,
  70737. const bool keepSectionOutsidePath) throw()
  70738. {
  70739. const bool startInside = path.contains (startX, startY);
  70740. const bool endInside = path.contains (endX, endY);
  70741. if (startInside == endInside)
  70742. {
  70743. if (keepSectionOutsidePath != startInside)
  70744. {
  70745. // entirely outside the path
  70746. return false;
  70747. }
  70748. else
  70749. {
  70750. // entirely inside the path
  70751. startX = 0.0f;
  70752. startY = 0.0f;
  70753. endX = 0.0f;
  70754. endY = 0.0f;
  70755. return true;
  70756. }
  70757. }
  70758. else
  70759. {
  70760. bool changed = false;
  70761. PathFlatteningIterator iter (path, AffineTransform::identity);
  70762. while (iter.next())
  70763. {
  70764. float ix, iy;
  70765. if (intersects (Line (iter.x1, iter.y1,
  70766. iter.x2, iter.y2),
  70767. ix, iy))
  70768. {
  70769. if ((startInside && keepSectionOutsidePath)
  70770. || (endInside && ! keepSectionOutsidePath))
  70771. {
  70772. setStart (ix, iy);
  70773. }
  70774. else
  70775. {
  70776. setEnd (ix, iy);
  70777. }
  70778. changed = true;
  70779. }
  70780. }
  70781. return changed;
  70782. }
  70783. }
  70784. bool Line::intersects (const Line& line,
  70785. float& intersectionX,
  70786. float& intersectionY) const throw()
  70787. {
  70788. return juce_lineIntersection (startX, startY,
  70789. endX, endY,
  70790. line.startX, line.startY,
  70791. line.endX, line.endY,
  70792. intersectionX,
  70793. intersectionY);
  70794. }
  70795. bool Line::isVertical() const throw()
  70796. {
  70797. return startX == endX;
  70798. }
  70799. bool Line::isHorizontal() const throw()
  70800. {
  70801. return startY == endY;
  70802. }
  70803. bool Line::isPointAbove (const float x, const float y) const throw()
  70804. {
  70805. return startX != endX
  70806. && y < ((endY - startY) * (x - startX)) / (endX - startX) + startY;
  70807. }
  70808. END_JUCE_NAMESPACE
  70809. /*** End of inlined file: juce_Line.cpp ***/
  70810. /*** Start of inlined file: juce_Path.cpp ***/
  70811. BEGIN_JUCE_NAMESPACE
  70812. // tests that some co-ords aren't NaNs
  70813. #define CHECK_COORDS_ARE_VALID(x, y) \
  70814. jassert (x == x && y == y);
  70815. const float Path::lineMarker = 100001.0f;
  70816. const float Path::moveMarker = 100002.0f;
  70817. const float Path::quadMarker = 100003.0f;
  70818. const float Path::cubicMarker = 100004.0f;
  70819. const float Path::closeSubPathMarker = 100005.0f;
  70820. static const int defaultGranularity = 32;
  70821. Path::Path() throw()
  70822. : numElements (0),
  70823. pathXMin (0),
  70824. pathXMax (0),
  70825. pathYMin (0),
  70826. pathYMax (0),
  70827. useNonZeroWinding (true)
  70828. {
  70829. }
  70830. Path::~Path() throw()
  70831. {
  70832. }
  70833. Path::Path (const Path& other) throw()
  70834. : numElements (other.numElements),
  70835. pathXMin (other.pathXMin),
  70836. pathXMax (other.pathXMax),
  70837. pathYMin (other.pathYMin),
  70838. pathYMax (other.pathYMax),
  70839. useNonZeroWinding (other.useNonZeroWinding)
  70840. {
  70841. if (numElements > 0)
  70842. {
  70843. data.setAllocatedSize (numElements);
  70844. memcpy (data.elements, other.data.elements, numElements * sizeof (float));
  70845. }
  70846. }
  70847. Path& Path::operator= (const Path& other) throw()
  70848. {
  70849. if (this != &other)
  70850. {
  70851. data.ensureAllocatedSize (other.numElements);
  70852. numElements = other.numElements;
  70853. pathXMin = other.pathXMin;
  70854. pathXMax = other.pathXMax;
  70855. pathYMin = other.pathYMin;
  70856. pathYMax = other.pathYMax;
  70857. useNonZeroWinding = other.useNonZeroWinding;
  70858. if (numElements > 0)
  70859. memcpy (data.elements, other.data.elements, numElements * sizeof (float));
  70860. }
  70861. return *this;
  70862. }
  70863. void Path::clear() throw()
  70864. {
  70865. numElements = 0;
  70866. pathXMin = 0;
  70867. pathYMin = 0;
  70868. pathYMax = 0;
  70869. pathXMax = 0;
  70870. }
  70871. void Path::swapWithPath (Path& other)
  70872. {
  70873. data.swapWith (other.data);
  70874. swapVariables <int> (numElements, other.numElements);
  70875. swapVariables <float> (pathXMin, other.pathXMin);
  70876. swapVariables <float> (pathXMax, other.pathXMax);
  70877. swapVariables <float> (pathYMin, other.pathYMin);
  70878. swapVariables <float> (pathYMax, other.pathYMax);
  70879. swapVariables <bool> (useNonZeroWinding, other.useNonZeroWinding);
  70880. }
  70881. void Path::setUsingNonZeroWinding (const bool isNonZero) throw()
  70882. {
  70883. useNonZeroWinding = isNonZero;
  70884. }
  70885. void Path::scaleToFit (const float x, const float y, const float w, const float h,
  70886. const bool preserveProportions) throw()
  70887. {
  70888. applyTransform (getTransformToScaleToFit (x, y, w, h, preserveProportions));
  70889. }
  70890. bool Path::isEmpty() const throw()
  70891. {
  70892. int i = 0;
  70893. while (i < numElements)
  70894. {
  70895. const float type = data.elements [i++];
  70896. if (type == moveMarker)
  70897. {
  70898. i += 2;
  70899. }
  70900. else if (type == lineMarker
  70901. || type == quadMarker
  70902. || type == cubicMarker)
  70903. {
  70904. return false;
  70905. }
  70906. }
  70907. return true;
  70908. }
  70909. const Rectangle<float> Path::getBounds () const throw()
  70910. {
  70911. return Rectangle<float> (pathXMin, pathYMin,
  70912. pathXMax - pathXMin,
  70913. pathYMax - pathYMin);
  70914. }
  70915. const Rectangle<float> Path::getBoundsTransformed (const AffineTransform& transform) const throw()
  70916. {
  70917. return getBounds().transformed (transform);
  70918. }
  70919. void Path::startNewSubPath (const float x,
  70920. const float y) throw()
  70921. {
  70922. CHECK_COORDS_ARE_VALID (x, y);
  70923. if (numElements == 0)
  70924. {
  70925. pathXMin = pathXMax = x;
  70926. pathYMin = pathYMax = y;
  70927. }
  70928. else
  70929. {
  70930. pathXMin = jmin (pathXMin, x);
  70931. pathXMax = jmax (pathXMax, x);
  70932. pathYMin = jmin (pathYMin, y);
  70933. pathYMax = jmax (pathYMax, y);
  70934. }
  70935. data.ensureAllocatedSize (numElements + 3);
  70936. data.elements [numElements++] = moveMarker;
  70937. data.elements [numElements++] = x;
  70938. data.elements [numElements++] = y;
  70939. }
  70940. void Path::lineTo (const float x, const float y) throw()
  70941. {
  70942. CHECK_COORDS_ARE_VALID (x, y);
  70943. if (numElements == 0)
  70944. startNewSubPath (0, 0);
  70945. data.ensureAllocatedSize (numElements + 3);
  70946. data.elements [numElements++] = lineMarker;
  70947. data.elements [numElements++] = x;
  70948. data.elements [numElements++] = y;
  70949. pathXMin = jmin (pathXMin, x);
  70950. pathXMax = jmax (pathXMax, x);
  70951. pathYMin = jmin (pathYMin, y);
  70952. pathYMax = jmax (pathYMax, y);
  70953. }
  70954. void Path::quadraticTo (const float x1, const float y1,
  70955. const float x2, const float y2) throw()
  70956. {
  70957. CHECK_COORDS_ARE_VALID (x1, y1);
  70958. CHECK_COORDS_ARE_VALID (x2, y2);
  70959. if (numElements == 0)
  70960. startNewSubPath (0, 0);
  70961. data.ensureAllocatedSize (numElements + 5);
  70962. data.elements [numElements++] = quadMarker;
  70963. data.elements [numElements++] = x1;
  70964. data.elements [numElements++] = y1;
  70965. data.elements [numElements++] = x2;
  70966. data.elements [numElements++] = y2;
  70967. pathXMin = jmin (pathXMin, x1, x2);
  70968. pathXMax = jmax (pathXMax, x1, x2);
  70969. pathYMin = jmin (pathYMin, y1, y2);
  70970. pathYMax = jmax (pathYMax, y1, y2);
  70971. }
  70972. void Path::cubicTo (const float x1, const float y1,
  70973. const float x2, const float y2,
  70974. const float x3, const float y3) throw()
  70975. {
  70976. CHECK_COORDS_ARE_VALID (x1, y1);
  70977. CHECK_COORDS_ARE_VALID (x2, y2);
  70978. CHECK_COORDS_ARE_VALID (x3, y3);
  70979. if (numElements == 0)
  70980. startNewSubPath (0, 0);
  70981. data.ensureAllocatedSize (numElements + 7);
  70982. data.elements [numElements++] = cubicMarker;
  70983. data.elements [numElements++] = x1;
  70984. data.elements [numElements++] = y1;
  70985. data.elements [numElements++] = x2;
  70986. data.elements [numElements++] = y2;
  70987. data.elements [numElements++] = x3;
  70988. data.elements [numElements++] = y3;
  70989. pathXMin = jmin (pathXMin, x1, x2, x3);
  70990. pathXMax = jmax (pathXMax, x1, x2, x3);
  70991. pathYMin = jmin (pathYMin, y1, y2, y3);
  70992. pathYMax = jmax (pathYMax, y1, y2, y3);
  70993. }
  70994. void Path::closeSubPath() throw()
  70995. {
  70996. if (numElements > 0
  70997. && data.elements [numElements - 1] != closeSubPathMarker)
  70998. {
  70999. data.ensureAllocatedSize (numElements + 1);
  71000. data.elements [numElements++] = closeSubPathMarker;
  71001. }
  71002. }
  71003. const Point<float> Path::getCurrentPosition() const
  71004. {
  71005. int i = numElements - 1;
  71006. if (i > 0 && data.elements[i] == closeSubPathMarker)
  71007. {
  71008. while (i >= 0)
  71009. {
  71010. if (data.elements[i] == moveMarker)
  71011. {
  71012. i += 2;
  71013. break;
  71014. }
  71015. --i;
  71016. }
  71017. }
  71018. if (i > 0)
  71019. return Point<float> (data.elements [i - 1], data.elements [i]);
  71020. return Point<float>();
  71021. }
  71022. void Path::addRectangle (const float x, const float y,
  71023. const float w, const float h) throw()
  71024. {
  71025. float x1 = x, y1 = y, x2 = x + w, y2 = y + h;
  71026. if (w < 0)
  71027. swapVariables (x1, x2);
  71028. if (h < 0)
  71029. swapVariables (y1, y2);
  71030. data.ensureAllocatedSize (numElements + 13);
  71031. if (numElements == 0)
  71032. {
  71033. pathXMin = x1;
  71034. pathXMax = x2;
  71035. pathYMin = y1;
  71036. pathYMax = y2;
  71037. }
  71038. else
  71039. {
  71040. pathXMin = jmin (pathXMin, x1);
  71041. pathXMax = jmax (pathXMax, x2);
  71042. pathYMin = jmin (pathYMin, y1);
  71043. pathYMax = jmax (pathYMax, y2);
  71044. }
  71045. data.elements [numElements++] = moveMarker;
  71046. data.elements [numElements++] = x1;
  71047. data.elements [numElements++] = y2;
  71048. data.elements [numElements++] = lineMarker;
  71049. data.elements [numElements++] = x1;
  71050. data.elements [numElements++] = y1;
  71051. data.elements [numElements++] = lineMarker;
  71052. data.elements [numElements++] = x2;
  71053. data.elements [numElements++] = y1;
  71054. data.elements [numElements++] = lineMarker;
  71055. data.elements [numElements++] = x2;
  71056. data.elements [numElements++] = y2;
  71057. data.elements [numElements++] = closeSubPathMarker;
  71058. }
  71059. void Path::addRectangle (const Rectangle<int>& rectangle) throw()
  71060. {
  71061. addRectangle ((float) rectangle.getX(), (float) rectangle.getY(),
  71062. (float) rectangle.getWidth(), (float) rectangle.getHeight());
  71063. }
  71064. void Path::addRoundedRectangle (const float x, const float y,
  71065. const float w, const float h,
  71066. float csx,
  71067. float csy) throw()
  71068. {
  71069. csx = jmin (csx, w * 0.5f);
  71070. csy = jmin (csy, h * 0.5f);
  71071. const float cs45x = csx * 0.45f;
  71072. const float cs45y = csy * 0.45f;
  71073. const float x2 = x + w;
  71074. const float y2 = y + h;
  71075. startNewSubPath (x + csx, y);
  71076. lineTo (x2 - csx, y);
  71077. cubicTo (x2 - cs45x, y, x2, y + cs45y, x2, y + csy);
  71078. lineTo (x2, y2 - csy);
  71079. cubicTo (x2, y2 - cs45y, x2 - cs45x, y2, x2 - csx, y2);
  71080. lineTo (x + csx, y2);
  71081. cubicTo (x + cs45x, y2, x, y2 - cs45y, x, y2 - csy);
  71082. lineTo (x, y + csy);
  71083. cubicTo (x, y + cs45y, x + cs45x, y, x + csx, y);
  71084. closeSubPath();
  71085. }
  71086. void Path::addRoundedRectangle (const float x, const float y,
  71087. const float w, const float h,
  71088. float cs) throw()
  71089. {
  71090. addRoundedRectangle (x, y, w, h, cs, cs);
  71091. }
  71092. void Path::addTriangle (const float x1, const float y1,
  71093. const float x2, const float y2,
  71094. const float x3, const float y3) throw()
  71095. {
  71096. startNewSubPath (x1, y1);
  71097. lineTo (x2, y2);
  71098. lineTo (x3, y3);
  71099. closeSubPath();
  71100. }
  71101. void Path::addQuadrilateral (const float x1, const float y1,
  71102. const float x2, const float y2,
  71103. const float x3, const float y3,
  71104. const float x4, const float y4) throw()
  71105. {
  71106. startNewSubPath (x1, y1);
  71107. lineTo (x2, y2);
  71108. lineTo (x3, y3);
  71109. lineTo (x4, y4);
  71110. closeSubPath();
  71111. }
  71112. void Path::addEllipse (const float x, const float y,
  71113. const float w, const float h) throw()
  71114. {
  71115. const float hw = w * 0.5f;
  71116. const float hw55 = hw * 0.55f;
  71117. const float hh = h * 0.5f;
  71118. const float hh45 = hh * 0.55f;
  71119. const float cx = x + hw;
  71120. const float cy = y + hh;
  71121. startNewSubPath (cx, cy - hh);
  71122. cubicTo (cx + hw55, cy - hh, cx + hw, cy - hh45, cx + hw, cy);
  71123. cubicTo (cx + hw, cy + hh45, cx + hw55, cy + hh, cx, cy + hh);
  71124. cubicTo (cx - hw55, cy + hh, cx - hw, cy + hh45, cx - hw, cy);
  71125. cubicTo (cx - hw, cy - hh45, cx - hw55, cy - hh, cx, cy - hh);
  71126. closeSubPath();
  71127. }
  71128. void Path::addArc (const float x, const float y,
  71129. const float w, const float h,
  71130. const float fromRadians,
  71131. const float toRadians,
  71132. const bool startAsNewSubPath) throw()
  71133. {
  71134. const float radiusX = w / 2.0f;
  71135. const float radiusY = h / 2.0f;
  71136. addCentredArc (x + radiusX,
  71137. y + radiusY,
  71138. radiusX, radiusY,
  71139. 0.0f,
  71140. fromRadians, toRadians,
  71141. startAsNewSubPath);
  71142. }
  71143. static const float ellipseAngularIncrement = 0.05f;
  71144. void Path::addCentredArc (const float centreX, const float centreY,
  71145. const float radiusX, const float radiusY,
  71146. const float rotationOfEllipse,
  71147. const float fromRadians,
  71148. const float toRadians,
  71149. const bool startAsNewSubPath) throw()
  71150. {
  71151. if (radiusX > 0.0f && radiusY > 0.0f)
  71152. {
  71153. const AffineTransform rotation (AffineTransform::rotation (rotationOfEllipse, centreX, centreY));
  71154. float angle = fromRadians;
  71155. if (startAsNewSubPath)
  71156. {
  71157. float x = centreX + radiusX * sinf (angle);
  71158. float y = centreY - radiusY * cosf (angle);
  71159. if (rotationOfEllipse != 0)
  71160. rotation.transformPoint (x, y);
  71161. startNewSubPath (x, y);
  71162. }
  71163. if (fromRadians < toRadians)
  71164. {
  71165. if (startAsNewSubPath)
  71166. angle += ellipseAngularIncrement;
  71167. while (angle < toRadians)
  71168. {
  71169. float x = centreX + radiusX * sinf (angle);
  71170. float y = centreY - radiusY * cosf (angle);
  71171. if (rotationOfEllipse != 0)
  71172. rotation.transformPoint (x, y);
  71173. lineTo (x, y);
  71174. angle += ellipseAngularIncrement;
  71175. }
  71176. }
  71177. else
  71178. {
  71179. if (startAsNewSubPath)
  71180. angle -= ellipseAngularIncrement;
  71181. while (angle > toRadians)
  71182. {
  71183. float x = centreX + radiusX * sinf (angle);
  71184. float y = centreY - radiusY * cosf (angle);
  71185. if (rotationOfEllipse != 0)
  71186. rotation.transformPoint (x, y);
  71187. lineTo (x, y);
  71188. angle -= ellipseAngularIncrement;
  71189. }
  71190. }
  71191. float x = centreX + radiusX * sinf (toRadians);
  71192. float y = centreY - radiusY * cosf (toRadians);
  71193. if (rotationOfEllipse != 0)
  71194. rotation.transformPoint (x, y);
  71195. lineTo (x, y);
  71196. }
  71197. }
  71198. void Path::addPieSegment (const float x, const float y,
  71199. const float width, const float height,
  71200. const float fromRadians,
  71201. const float toRadians,
  71202. const float innerCircleProportionalSize)
  71203. {
  71204. float hw = width * 0.5f;
  71205. float hh = height * 0.5f;
  71206. const float centreX = x + hw;
  71207. const float centreY = y + hh;
  71208. startNewSubPath (centreX + hw * sinf (fromRadians),
  71209. centreY - hh * cosf (fromRadians));
  71210. addArc (x, y, width, height, fromRadians, toRadians);
  71211. if (fabs (fromRadians - toRadians) > float_Pi * 1.999f)
  71212. {
  71213. closeSubPath();
  71214. if (innerCircleProportionalSize > 0)
  71215. {
  71216. hw *= innerCircleProportionalSize;
  71217. hh *= innerCircleProportionalSize;
  71218. startNewSubPath (centreX + hw * sinf (toRadians),
  71219. centreY - hh * cosf (toRadians));
  71220. addArc (centreX - hw, centreY - hh, hw * 2.0f, hh * 2.0f,
  71221. toRadians, fromRadians);
  71222. }
  71223. }
  71224. else
  71225. {
  71226. if (innerCircleProportionalSize > 0)
  71227. {
  71228. hw *= innerCircleProportionalSize;
  71229. hh *= innerCircleProportionalSize;
  71230. addArc (centreX - hw, centreY - hh, hw * 2.0f, hh * 2.0f,
  71231. toRadians, fromRadians);
  71232. }
  71233. else
  71234. {
  71235. lineTo (centreX, centreY);
  71236. }
  71237. }
  71238. closeSubPath();
  71239. }
  71240. static void perpendicularOffset (const float x1, const float y1,
  71241. const float x2, const float y2,
  71242. const float offsetX, const float offsetY,
  71243. float& resultX, float& resultY) throw()
  71244. {
  71245. const float dx = x2 - x1;
  71246. const float dy = y2 - y1;
  71247. const float len = juce_hypotf (dx, dy);
  71248. if (len == 0)
  71249. {
  71250. resultX = x1;
  71251. resultY = y1;
  71252. }
  71253. else
  71254. {
  71255. resultX = x1 + ((dx * offsetX) - (dy * offsetY)) / len;
  71256. resultY = y1 + ((dy * offsetX) + (dx * offsetY)) / len;
  71257. }
  71258. }
  71259. void Path::addLineSegment (const float startX, const float startY,
  71260. const float endX, const float endY,
  71261. float lineThickness) throw()
  71262. {
  71263. lineThickness *= 0.5f;
  71264. float x, y;
  71265. perpendicularOffset (startX, startY, endX, endY,
  71266. 0, lineThickness, x, y);
  71267. startNewSubPath (x, y);
  71268. perpendicularOffset (startX, startY, endX, endY,
  71269. 0, -lineThickness, x, y);
  71270. lineTo (x, y);
  71271. perpendicularOffset (endX, endY, startX, startY,
  71272. 0, lineThickness, x, y);
  71273. lineTo (x, y);
  71274. perpendicularOffset (endX, endY, startX, startY,
  71275. 0, -lineThickness, x, y);
  71276. lineTo (x, y);
  71277. closeSubPath();
  71278. }
  71279. void Path::addArrow (const float startX, const float startY,
  71280. const float endX, const float endY,
  71281. float lineThickness,
  71282. float arrowheadWidth,
  71283. float arrowheadLength) throw()
  71284. {
  71285. lineThickness *= 0.5f;
  71286. arrowheadWidth *= 0.5f;
  71287. arrowheadLength = jmin (arrowheadLength, 0.8f * juce_hypotf (startX - endX,
  71288. startY - endY));
  71289. float x, y;
  71290. perpendicularOffset (startX, startY, endX, endY,
  71291. 0, lineThickness, x, y);
  71292. startNewSubPath (x, y);
  71293. perpendicularOffset (startX, startY, endX, endY,
  71294. 0, -lineThickness, x, y);
  71295. lineTo (x, y);
  71296. perpendicularOffset (endX, endY, startX, startY,
  71297. arrowheadLength, lineThickness, x, y);
  71298. lineTo (x, y);
  71299. perpendicularOffset (endX, endY, startX, startY,
  71300. arrowheadLength, arrowheadWidth, x, y);
  71301. lineTo (x, y);
  71302. perpendicularOffset (endX, endY, startX, startY,
  71303. 0, 0, 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. arrowheadLength, -lineThickness, x, y);
  71310. lineTo (x, y);
  71311. closeSubPath();
  71312. }
  71313. void Path::addStar (const float centreX,
  71314. const float centreY,
  71315. const int numberOfPoints,
  71316. const float innerRadius,
  71317. const float outerRadius,
  71318. const float startAngle)
  71319. {
  71320. jassert (numberOfPoints > 1); // this would be silly.
  71321. if (numberOfPoints > 1)
  71322. {
  71323. const float angleBetweenPoints = float_Pi * 2.0f / numberOfPoints;
  71324. for (int i = 0; i < numberOfPoints; ++i)
  71325. {
  71326. float angle = startAngle + i * angleBetweenPoints;
  71327. const float x = centreX + outerRadius * sinf (angle);
  71328. const float y = centreY - outerRadius * cosf (angle);
  71329. if (i == 0)
  71330. startNewSubPath (x, y);
  71331. else
  71332. lineTo (x, y);
  71333. angle += angleBetweenPoints * 0.5f;
  71334. lineTo (centreX + innerRadius * sinf (angle),
  71335. centreY - innerRadius * cosf (angle));
  71336. }
  71337. closeSubPath();
  71338. }
  71339. }
  71340. void Path::addBubble (float x, float y,
  71341. float w, float h,
  71342. float cs,
  71343. float tipX,
  71344. float tipY,
  71345. int whichSide,
  71346. float arrowPos,
  71347. float arrowWidth)
  71348. {
  71349. if (w > 1.0f && h > 1.0f)
  71350. {
  71351. cs = jmin (cs, w * 0.5f, h * 0.5f);
  71352. const float cs2 = 2.0f * cs;
  71353. startNewSubPath (x + cs, y);
  71354. if (whichSide == 0)
  71355. {
  71356. const float halfArrowW = jmin (arrowWidth, w - cs2) * 0.5f;
  71357. const float arrowX1 = x + cs + jmax (0.0f, (w - cs2) * arrowPos - halfArrowW);
  71358. lineTo (arrowX1, y);
  71359. lineTo (tipX, tipY);
  71360. lineTo (arrowX1 + halfArrowW * 2.0f, y);
  71361. }
  71362. lineTo (x + w - cs, y);
  71363. if (cs > 0.0f)
  71364. addArc (x + w - cs2, y, cs2, cs2, 0, float_Pi * 0.5f);
  71365. if (whichSide == 3)
  71366. {
  71367. const float halfArrowH = jmin (arrowWidth, h - cs2) * 0.5f;
  71368. const float arrowY1 = y + cs + jmax (0.0f, (h - cs2) * arrowPos - halfArrowH);
  71369. lineTo (x + w, arrowY1);
  71370. lineTo (tipX, tipY);
  71371. lineTo (x + w, arrowY1 + halfArrowH * 2.0f);
  71372. }
  71373. lineTo (x + w, y + h - cs);
  71374. if (cs > 0.0f)
  71375. addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi);
  71376. if (whichSide == 2)
  71377. {
  71378. const float halfArrowW = jmin (arrowWidth, w - cs2) * 0.5f;
  71379. const float arrowX1 = x + cs + jmax (0.0f, (w - cs2) * arrowPos - halfArrowW);
  71380. lineTo (arrowX1 + halfArrowW * 2.0f, y + h);
  71381. lineTo (tipX, tipY);
  71382. lineTo (arrowX1, y + h);
  71383. }
  71384. lineTo (x + cs, y + h);
  71385. if (cs > 0.0f)
  71386. addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f);
  71387. if (whichSide == 1)
  71388. {
  71389. const float halfArrowH = jmin (arrowWidth, h - cs2) * 0.5f;
  71390. const float arrowY1 = y + cs + jmax (0.0f, (h - cs2) * arrowPos - halfArrowH);
  71391. lineTo (x, arrowY1 + halfArrowH * 2.0f);
  71392. lineTo (tipX, tipY);
  71393. lineTo (x, arrowY1);
  71394. }
  71395. lineTo (x, y + cs);
  71396. if (cs > 0.0f)
  71397. addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f - ellipseAngularIncrement);
  71398. closeSubPath();
  71399. }
  71400. }
  71401. void Path::addPath (const Path& other) throw()
  71402. {
  71403. int i = 0;
  71404. while (i < other.numElements)
  71405. {
  71406. const float type = other.data.elements [i++];
  71407. if (type == moveMarker)
  71408. {
  71409. startNewSubPath (other.data.elements [i],
  71410. other.data.elements [i + 1]);
  71411. i += 2;
  71412. }
  71413. else if (type == lineMarker)
  71414. {
  71415. lineTo (other.data.elements [i],
  71416. other.data.elements [i + 1]);
  71417. i += 2;
  71418. }
  71419. else if (type == quadMarker)
  71420. {
  71421. quadraticTo (other.data.elements [i],
  71422. other.data.elements [i + 1],
  71423. other.data.elements [i + 2],
  71424. other.data.elements [i + 3]);
  71425. i += 4;
  71426. }
  71427. else if (type == cubicMarker)
  71428. {
  71429. cubicTo (other.data.elements [i],
  71430. other.data.elements [i + 1],
  71431. other.data.elements [i + 2],
  71432. other.data.elements [i + 3],
  71433. other.data.elements [i + 4],
  71434. other.data.elements [i + 5]);
  71435. i += 6;
  71436. }
  71437. else if (type == closeSubPathMarker)
  71438. {
  71439. closeSubPath();
  71440. }
  71441. else
  71442. {
  71443. // something's gone wrong with the element list!
  71444. jassertfalse
  71445. }
  71446. }
  71447. }
  71448. void Path::addPath (const Path& other,
  71449. const AffineTransform& transformToApply) throw()
  71450. {
  71451. int i = 0;
  71452. while (i < other.numElements)
  71453. {
  71454. const float type = other.data.elements [i++];
  71455. if (type == closeSubPathMarker)
  71456. {
  71457. closeSubPath();
  71458. }
  71459. else
  71460. {
  71461. float x = other.data.elements [i++];
  71462. float y = other.data.elements [i++];
  71463. transformToApply.transformPoint (x, y);
  71464. if (type == moveMarker)
  71465. {
  71466. startNewSubPath (x, y);
  71467. }
  71468. else if (type == lineMarker)
  71469. {
  71470. lineTo (x, y);
  71471. }
  71472. else if (type == quadMarker)
  71473. {
  71474. float x2 = other.data.elements [i++];
  71475. float y2 = other.data.elements [i++];
  71476. transformToApply.transformPoint (x2, y2);
  71477. quadraticTo (x, y, x2, y2);
  71478. }
  71479. else if (type == cubicMarker)
  71480. {
  71481. float x2 = other.data.elements [i++];
  71482. float y2 = other.data.elements [i++];
  71483. float x3 = other.data.elements [i++];
  71484. float y3 = other.data.elements [i++];
  71485. transformToApply.transformPoint (x2, y2);
  71486. transformToApply.transformPoint (x3, y3);
  71487. cubicTo (x, y, x2, y2, x3, y3);
  71488. }
  71489. else
  71490. {
  71491. // something's gone wrong with the element list!
  71492. jassertfalse
  71493. }
  71494. }
  71495. }
  71496. }
  71497. void Path::applyTransform (const AffineTransform& transform) throw()
  71498. {
  71499. int i = 0;
  71500. pathYMin = pathXMin = 0;
  71501. pathYMax = pathXMax = 0;
  71502. bool setMaxMin = false;
  71503. while (i < numElements)
  71504. {
  71505. const float type = data.elements [i++];
  71506. if (type == moveMarker)
  71507. {
  71508. transform.transformPoint (data.elements [i],
  71509. data.elements [i + 1]);
  71510. if (setMaxMin)
  71511. {
  71512. pathXMin = jmin (pathXMin, data.elements [i]);
  71513. pathXMax = jmax (pathXMax, data.elements [i]);
  71514. pathYMin = jmin (pathYMin, data.elements [i + 1]);
  71515. pathYMax = jmax (pathYMax, data.elements [i + 1]);
  71516. }
  71517. else
  71518. {
  71519. pathXMin = pathXMax = data.elements [i];
  71520. pathYMin = pathYMax = data.elements [i + 1];
  71521. setMaxMin = true;
  71522. }
  71523. i += 2;
  71524. }
  71525. else if (type == lineMarker)
  71526. {
  71527. transform.transformPoint (data.elements [i],
  71528. data.elements [i + 1]);
  71529. pathXMin = jmin (pathXMin, data.elements [i]);
  71530. pathXMax = jmax (pathXMax, data.elements [i]);
  71531. pathYMin = jmin (pathYMin, data.elements [i + 1]);
  71532. pathYMax = jmax (pathYMax, data.elements [i + 1]);
  71533. i += 2;
  71534. }
  71535. else if (type == quadMarker)
  71536. {
  71537. transform.transformPoint (data.elements [i],
  71538. data.elements [i + 1]);
  71539. transform.transformPoint (data.elements [i + 2],
  71540. data.elements [i + 3]);
  71541. pathXMin = jmin (pathXMin, data.elements [i], data.elements [i + 2]);
  71542. pathXMax = jmax (pathXMax, data.elements [i], data.elements [i + 2]);
  71543. pathYMin = jmin (pathYMin, data.elements [i + 1], data.elements [i + 3]);
  71544. pathYMax = jmax (pathYMax, data.elements [i + 1], data.elements [i + 3]);
  71545. i += 4;
  71546. }
  71547. else if (type == cubicMarker)
  71548. {
  71549. transform.transformPoint (data.elements [i],
  71550. data.elements [i + 1]);
  71551. transform.transformPoint (data.elements [i + 2],
  71552. data.elements [i + 3]);
  71553. transform.transformPoint (data.elements [i + 4],
  71554. data.elements [i + 5]);
  71555. pathXMin = jmin (pathXMin, data.elements [i], data.elements [i + 2], data.elements [i + 4]);
  71556. pathXMax = jmax (pathXMax, data.elements [i], data.elements [i + 2], data.elements [i + 4]);
  71557. pathYMin = jmin (pathYMin, data.elements [i + 1], data.elements [i + 3], data.elements [i + 5]);
  71558. pathYMax = jmax (pathYMax, data.elements [i + 1], data.elements [i + 3], data.elements [i + 5]);
  71559. i += 6;
  71560. }
  71561. }
  71562. }
  71563. const AffineTransform Path::getTransformToScaleToFit (const float x, const float y,
  71564. const float w, const float h,
  71565. const bool preserveProportions,
  71566. const Justification& justification) const throw()
  71567. {
  71568. Rectangle<float> bounds (getBounds());
  71569. if (preserveProportions)
  71570. {
  71571. if (w <= 0 || h <= 0 || bounds.isEmpty())
  71572. return AffineTransform::identity;
  71573. float newW, newH;
  71574. const float srcRatio = bounds.getHeight() / bounds.getWidth();
  71575. if (srcRatio > h / w)
  71576. {
  71577. newW = h / srcRatio;
  71578. newH = h;
  71579. }
  71580. else
  71581. {
  71582. newW = w;
  71583. newH = w * srcRatio;
  71584. }
  71585. float newXCentre = x;
  71586. float newYCentre = y;
  71587. if (justification.testFlags (Justification::left))
  71588. newXCentre += newW * 0.5f;
  71589. else if (justification.testFlags (Justification::right))
  71590. newXCentre += w - newW * 0.5f;
  71591. else
  71592. newXCentre += w * 0.5f;
  71593. if (justification.testFlags (Justification::top))
  71594. newYCentre += newH * 0.5f;
  71595. else if (justification.testFlags (Justification::bottom))
  71596. newYCentre += h - newH * 0.5f;
  71597. else
  71598. newYCentre += h * 0.5f;
  71599. return AffineTransform::translation (bounds.getWidth() * -0.5f - bounds.getX(),
  71600. bounds.getHeight() * -0.5f - bounds.getY())
  71601. .scaled (newW / bounds.getWidth(), newH / bounds.getHeight())
  71602. .translated (newXCentre, newYCentre);
  71603. }
  71604. else
  71605. {
  71606. return AffineTransform::translation (-bounds.getX(), -bounds.getY())
  71607. .scaled (w / bounds.getWidth(), h / bounds.getHeight())
  71608. .translated (x, y);
  71609. }
  71610. }
  71611. bool Path::contains (const float x, const float y, const float tolerence) const throw()
  71612. {
  71613. if (x <= pathXMin || x >= pathXMax
  71614. || y <= pathYMin || y >= pathYMax)
  71615. return false;
  71616. PathFlatteningIterator i (*this, AffineTransform::identity, tolerence);
  71617. int positiveCrossings = 0;
  71618. int negativeCrossings = 0;
  71619. while (i.next())
  71620. {
  71621. if ((i.y1 <= y && i.y2 > y)
  71622. || (i.y2 <= y && i.y1 > y))
  71623. {
  71624. const float intersectX = i.x1 + (i.x2 - i.x1) * (y - i.y1) / (i.y2 - i.y1);
  71625. if (intersectX <= x)
  71626. {
  71627. if (i.y1 < i.y2)
  71628. ++positiveCrossings;
  71629. else
  71630. ++negativeCrossings;
  71631. }
  71632. }
  71633. }
  71634. return (useNonZeroWinding) ? (negativeCrossings != positiveCrossings)
  71635. : ((negativeCrossings + positiveCrossings) & 1) != 0;
  71636. }
  71637. bool Path::intersectsLine (const float x1, const float y1,
  71638. const float x2, const float y2,
  71639. const float tolerence) throw()
  71640. {
  71641. PathFlatteningIterator i (*this, AffineTransform::identity, tolerence);
  71642. const Line line1 (x1, y1, x2, y2);
  71643. while (i.next())
  71644. {
  71645. const Line line2 (i.x1, i.y1, i.x2, i.y2);
  71646. float ix, iy;
  71647. if (line1.intersects (line2, ix, iy))
  71648. return true;
  71649. }
  71650. return false;
  71651. }
  71652. const Path Path::createPathWithRoundedCorners (const float cornerRadius) const throw()
  71653. {
  71654. if (cornerRadius <= 0.01f)
  71655. return *this;
  71656. int indexOfPathStart = 0, indexOfPathStartThis = 0;
  71657. int n = 0;
  71658. bool lastWasLine = false, firstWasLine = false;
  71659. Path p;
  71660. while (n < numElements)
  71661. {
  71662. const float type = data.elements [n++];
  71663. if (type == moveMarker)
  71664. {
  71665. indexOfPathStart = p.numElements;
  71666. indexOfPathStartThis = n - 1;
  71667. const float x = data.elements [n++];
  71668. const float y = data.elements [n++];
  71669. p.startNewSubPath (x, y);
  71670. lastWasLine = false;
  71671. firstWasLine = (data.elements [n] == lineMarker);
  71672. }
  71673. else if (type == lineMarker || type == closeSubPathMarker)
  71674. {
  71675. float startX = 0, startY = 0, joinX = 0, joinY = 0, endX, endY;
  71676. if (type == lineMarker)
  71677. {
  71678. endX = data.elements [n++];
  71679. endY = data.elements [n++];
  71680. if (n > 8)
  71681. {
  71682. startX = data.elements [n - 8];
  71683. startY = data.elements [n - 7];
  71684. joinX = data.elements [n - 5];
  71685. joinY = data.elements [n - 4];
  71686. }
  71687. }
  71688. else
  71689. {
  71690. endX = data.elements [indexOfPathStartThis + 1];
  71691. endY = data.elements [indexOfPathStartThis + 2];
  71692. if (n > 6)
  71693. {
  71694. startX = data.elements [n - 6];
  71695. startY = data.elements [n - 5];
  71696. joinX = data.elements [n - 3];
  71697. joinY = data.elements [n - 2];
  71698. }
  71699. }
  71700. if (lastWasLine)
  71701. {
  71702. const double len1 = juce_hypot (startX - joinX,
  71703. startY - joinY);
  71704. if (len1 > 0)
  71705. {
  71706. const double propNeeded = jmin (0.5, cornerRadius / len1);
  71707. p.data.elements [p.numElements - 2] = (float) (joinX - (joinX - startX) * propNeeded);
  71708. p.data.elements [p.numElements - 1] = (float) (joinY - (joinY - startY) * propNeeded);
  71709. }
  71710. const double len2 = juce_hypot (endX - joinX,
  71711. endY - joinY);
  71712. if (len2 > 0)
  71713. {
  71714. const double propNeeded = jmin (0.5, cornerRadius / len2);
  71715. p.quadraticTo (joinX, joinY,
  71716. (float) (joinX + (endX - joinX) * propNeeded),
  71717. (float) (joinY + (endY - joinY) * propNeeded));
  71718. }
  71719. p.lineTo (endX, endY);
  71720. }
  71721. else if (type == lineMarker)
  71722. {
  71723. p.lineTo (endX, endY);
  71724. lastWasLine = true;
  71725. }
  71726. if (type == closeSubPathMarker)
  71727. {
  71728. if (firstWasLine)
  71729. {
  71730. startX = data.elements [n - 3];
  71731. startY = data.elements [n - 2];
  71732. joinX = endX;
  71733. joinY = endY;
  71734. endX = data.elements [indexOfPathStartThis + 4];
  71735. endY = data.elements [indexOfPathStartThis + 5];
  71736. const double len1 = juce_hypot (startX - joinX,
  71737. startY - joinY);
  71738. if (len1 > 0)
  71739. {
  71740. const double propNeeded = jmin (0.5, cornerRadius / len1);
  71741. p.data.elements [p.numElements - 2] = (float) (joinX - (joinX - startX) * propNeeded);
  71742. p.data.elements [p.numElements - 1] = (float) (joinY - (joinY - startY) * propNeeded);
  71743. }
  71744. const double len2 = juce_hypot (endX - joinX,
  71745. endY - joinY);
  71746. if (len2 > 0)
  71747. {
  71748. const double propNeeded = jmin (0.5, cornerRadius / len2);
  71749. endX = (float) (joinX + (endX - joinX) * propNeeded);
  71750. endY = (float) (joinY + (endY - joinY) * propNeeded);
  71751. p.quadraticTo (joinX, joinY, endX, endY);
  71752. p.data.elements [indexOfPathStart + 1] = endX;
  71753. p.data.elements [indexOfPathStart + 2] = endY;
  71754. }
  71755. }
  71756. p.closeSubPath();
  71757. }
  71758. }
  71759. else if (type == quadMarker)
  71760. {
  71761. lastWasLine = false;
  71762. const float x1 = data.elements [n++];
  71763. const float y1 = data.elements [n++];
  71764. const float x2 = data.elements [n++];
  71765. const float y2 = data.elements [n++];
  71766. p.quadraticTo (x1, y1, x2, y2);
  71767. }
  71768. else if (type == cubicMarker)
  71769. {
  71770. lastWasLine = false;
  71771. const float x1 = data.elements [n++];
  71772. const float y1 = data.elements [n++];
  71773. const float x2 = data.elements [n++];
  71774. const float y2 = data.elements [n++];
  71775. const float x3 = data.elements [n++];
  71776. const float y3 = data.elements [n++];
  71777. p.cubicTo (x1, y1, x2, y2, x3, y3);
  71778. }
  71779. }
  71780. return p;
  71781. }
  71782. void Path::loadPathFromStream (InputStream& source)
  71783. {
  71784. while (! source.isExhausted())
  71785. {
  71786. switch (source.readByte())
  71787. {
  71788. case 'm':
  71789. {
  71790. const float x = source.readFloat();
  71791. const float y = source.readFloat();
  71792. startNewSubPath (x, y);
  71793. break;
  71794. }
  71795. case 'l':
  71796. {
  71797. const float x = source.readFloat();
  71798. const float y = source.readFloat();
  71799. lineTo (x, y);
  71800. break;
  71801. }
  71802. case 'q':
  71803. {
  71804. const float x1 = source.readFloat();
  71805. const float y1 = source.readFloat();
  71806. const float x2 = source.readFloat();
  71807. const float y2 = source.readFloat();
  71808. quadraticTo (x1, y1, x2, y2);
  71809. break;
  71810. }
  71811. case 'b':
  71812. {
  71813. const float x1 = source.readFloat();
  71814. const float y1 = source.readFloat();
  71815. const float x2 = source.readFloat();
  71816. const float y2 = source.readFloat();
  71817. const float x3 = source.readFloat();
  71818. const float y3 = source.readFloat();
  71819. cubicTo (x1, y1, x2, y2, x3, y3);
  71820. break;
  71821. }
  71822. case 'c':
  71823. closeSubPath();
  71824. break;
  71825. case 'n':
  71826. useNonZeroWinding = true;
  71827. break;
  71828. case 'z':
  71829. useNonZeroWinding = false;
  71830. break;
  71831. case 'e':
  71832. return; // end of path marker
  71833. default:
  71834. jassertfalse // illegal char in the stream
  71835. break;
  71836. }
  71837. }
  71838. }
  71839. void Path::loadPathFromData (const unsigned char* const data,
  71840. const int numberOfBytes) throw()
  71841. {
  71842. MemoryInputStream in ((const char*) data, numberOfBytes, false);
  71843. loadPathFromStream (in);
  71844. }
  71845. void Path::writePathToStream (OutputStream& dest) const
  71846. {
  71847. dest.writeByte ((useNonZeroWinding) ? 'n' : 'z');
  71848. int i = 0;
  71849. while (i < numElements)
  71850. {
  71851. const float type = data.elements [i++];
  71852. if (type == moveMarker)
  71853. {
  71854. dest.writeByte ('m');
  71855. dest.writeFloat (data.elements [i++]);
  71856. dest.writeFloat (data.elements [i++]);
  71857. }
  71858. else if (type == lineMarker)
  71859. {
  71860. dest.writeByte ('l');
  71861. dest.writeFloat (data.elements [i++]);
  71862. dest.writeFloat (data.elements [i++]);
  71863. }
  71864. else if (type == quadMarker)
  71865. {
  71866. dest.writeByte ('q');
  71867. dest.writeFloat (data.elements [i++]);
  71868. dest.writeFloat (data.elements [i++]);
  71869. dest.writeFloat (data.elements [i++]);
  71870. dest.writeFloat (data.elements [i++]);
  71871. }
  71872. else if (type == cubicMarker)
  71873. {
  71874. dest.writeByte ('b');
  71875. dest.writeFloat (data.elements [i++]);
  71876. dest.writeFloat (data.elements [i++]);
  71877. dest.writeFloat (data.elements [i++]);
  71878. dest.writeFloat (data.elements [i++]);
  71879. dest.writeFloat (data.elements [i++]);
  71880. dest.writeFloat (data.elements [i++]);
  71881. }
  71882. else if (type == closeSubPathMarker)
  71883. {
  71884. dest.writeByte ('c');
  71885. }
  71886. }
  71887. dest.writeByte ('e'); // marks the end-of-path
  71888. }
  71889. const String Path::toString() const
  71890. {
  71891. MemoryOutputStream s (2048, 2048);
  71892. if (! useNonZeroWinding)
  71893. s << "a ";
  71894. int i = 0;
  71895. float lastMarker = 0.0f;
  71896. while (i < numElements)
  71897. {
  71898. const float marker = data.elements [i++];
  71899. char markerChar = 0;
  71900. int numCoords = 0;
  71901. if (marker == moveMarker)
  71902. {
  71903. markerChar = 'm';
  71904. numCoords = 2;
  71905. }
  71906. else if (marker == lineMarker)
  71907. {
  71908. markerChar = 'l';
  71909. numCoords = 2;
  71910. }
  71911. else if (marker == quadMarker)
  71912. {
  71913. markerChar = 'q';
  71914. numCoords = 4;
  71915. }
  71916. else if (marker == cubicMarker)
  71917. {
  71918. markerChar = 'c';
  71919. numCoords = 6;
  71920. }
  71921. else
  71922. {
  71923. jassert (marker == closeSubPathMarker);
  71924. markerChar = 'z';
  71925. }
  71926. if (marker != lastMarker)
  71927. {
  71928. s << markerChar << ' ';
  71929. lastMarker = marker;
  71930. }
  71931. while (--numCoords >= 0 && i < numElements)
  71932. {
  71933. String n (data.elements [i++], 3);
  71934. if (n.endsWithChar (T('0')))
  71935. {
  71936. do
  71937. {
  71938. n = n.dropLastCharacters (1);
  71939. } while (n.endsWithChar (T('0')));
  71940. if (n.endsWithChar (T('.')))
  71941. n = n.dropLastCharacters (1);
  71942. }
  71943. s << n << ' ';
  71944. }
  71945. }
  71946. const char* const result = (const char*) s.getData();
  71947. size_t len = s.getDataSize();
  71948. while (len > 0 && CharacterFunctions::isWhitespace (result [len - 1]))
  71949. --len;
  71950. return String (result, len);
  71951. }
  71952. static const String nextToken (const tchar*& t)
  71953. {
  71954. while (CharacterFunctions::isWhitespace (*t))
  71955. ++t;
  71956. const tchar* const start = t;
  71957. while (*t != 0 && ! CharacterFunctions::isWhitespace (*t))
  71958. ++t;
  71959. const int length = (int) (t - start);
  71960. while (CharacterFunctions::isWhitespace (*t))
  71961. ++t;
  71962. return String (start, length);
  71963. }
  71964. void Path::restoreFromString (const String& stringVersion)
  71965. {
  71966. clear();
  71967. setUsingNonZeroWinding (true);
  71968. const tchar* t = stringVersion;
  71969. tchar marker = T('m');
  71970. int numValues = 2;
  71971. float values [6];
  71972. while (*t != 0)
  71973. {
  71974. const String token (nextToken (t));
  71975. const tchar firstChar = token[0];
  71976. int startNum = 0;
  71977. if (firstChar == T('m') || firstChar == T('l'))
  71978. {
  71979. marker = firstChar;
  71980. numValues = 2;
  71981. }
  71982. else if (firstChar == T('q'))
  71983. {
  71984. marker = firstChar;
  71985. numValues = 4;
  71986. }
  71987. else if (firstChar == T('c'))
  71988. {
  71989. marker = firstChar;
  71990. numValues = 6;
  71991. }
  71992. else if (firstChar == T('z'))
  71993. {
  71994. marker = firstChar;
  71995. numValues = 0;
  71996. }
  71997. else if (firstChar == T('a'))
  71998. {
  71999. setUsingNonZeroWinding (false);
  72000. continue;
  72001. }
  72002. else
  72003. {
  72004. ++startNum;
  72005. values [0] = token.getFloatValue();
  72006. }
  72007. for (int i = startNum; i < numValues; ++i)
  72008. values [i] = nextToken (t).getFloatValue();
  72009. switch (marker)
  72010. {
  72011. case T('m'):
  72012. startNewSubPath (values[0], values[1]);
  72013. break;
  72014. case T('l'):
  72015. lineTo (values[0], values[1]);
  72016. break;
  72017. case T('q'):
  72018. quadraticTo (values[0], values[1],
  72019. values[2], values[3]);
  72020. break;
  72021. case T('c'):
  72022. cubicTo (values[0], values[1],
  72023. values[2], values[3],
  72024. values[4], values[5]);
  72025. break;
  72026. case T('z'):
  72027. closeSubPath();
  72028. break;
  72029. default:
  72030. jassertfalse // illegal string format?
  72031. break;
  72032. }
  72033. }
  72034. }
  72035. Path::Iterator::Iterator (const Path& path_)
  72036. : path (path_),
  72037. index (0)
  72038. {
  72039. }
  72040. Path::Iterator::~Iterator()
  72041. {
  72042. }
  72043. bool Path::Iterator::next()
  72044. {
  72045. const float* const elements = path.data.elements;
  72046. if (index < path.numElements)
  72047. {
  72048. const float type = elements [index++];
  72049. if (type == moveMarker)
  72050. {
  72051. elementType = startNewSubPath;
  72052. x1 = elements [index++];
  72053. y1 = elements [index++];
  72054. }
  72055. else if (type == lineMarker)
  72056. {
  72057. elementType = lineTo;
  72058. x1 = elements [index++];
  72059. y1 = elements [index++];
  72060. }
  72061. else if (type == quadMarker)
  72062. {
  72063. elementType = quadraticTo;
  72064. x1 = elements [index++];
  72065. y1 = elements [index++];
  72066. x2 = elements [index++];
  72067. y2 = elements [index++];
  72068. }
  72069. else if (type == cubicMarker)
  72070. {
  72071. elementType = cubicTo;
  72072. x1 = elements [index++];
  72073. y1 = elements [index++];
  72074. x2 = elements [index++];
  72075. y2 = elements [index++];
  72076. x3 = elements [index++];
  72077. y3 = elements [index++];
  72078. }
  72079. else if (type == closeSubPathMarker)
  72080. {
  72081. elementType = closePath;
  72082. }
  72083. return true;
  72084. }
  72085. return false;
  72086. }
  72087. END_JUCE_NAMESPACE
  72088. /*** End of inlined file: juce_Path.cpp ***/
  72089. /*** Start of inlined file: juce_PathIterator.cpp ***/
  72090. BEGIN_JUCE_NAMESPACE
  72091. #if JUCE_MSVC
  72092. #pragma optimize ("t", on)
  72093. #endif
  72094. PathFlatteningIterator::PathFlatteningIterator (const Path& path_,
  72095. const AffineTransform& transform_,
  72096. float tolerence_) throw()
  72097. : x2 (0),
  72098. y2 (0),
  72099. closesSubPath (false),
  72100. subPathIndex (-1),
  72101. path (path_),
  72102. transform (transform_),
  72103. points (path_.data.elements),
  72104. tolerence (tolerence_ * tolerence_),
  72105. subPathCloseX (0),
  72106. subPathCloseY (0),
  72107. stackBase (32),
  72108. index (0),
  72109. stackSize (32)
  72110. {
  72111. isIdentityTransform = transform.isIdentity();
  72112. stackPos = stackBase;
  72113. }
  72114. PathFlatteningIterator::~PathFlatteningIterator() throw()
  72115. {
  72116. }
  72117. bool PathFlatteningIterator::next() throw()
  72118. {
  72119. x1 = x2;
  72120. y1 = y2;
  72121. float x3 = 0;
  72122. float y3 = 0;
  72123. float x4 = 0;
  72124. float y4 = 0;
  72125. float type;
  72126. for (;;)
  72127. {
  72128. if (stackPos == stackBase)
  72129. {
  72130. if (index >= path.numElements)
  72131. {
  72132. return false;
  72133. }
  72134. else
  72135. {
  72136. type = points [index++];
  72137. if (type != Path::closeSubPathMarker)
  72138. {
  72139. x2 = points [index++];
  72140. y2 = points [index++];
  72141. if (! isIdentityTransform)
  72142. transform.transformPoint (x2, y2);
  72143. if (type == Path::quadMarker)
  72144. {
  72145. x3 = points [index++];
  72146. y3 = points [index++];
  72147. if (! isIdentityTransform)
  72148. transform.transformPoint (x3, y3);
  72149. }
  72150. else if (type == Path::cubicMarker)
  72151. {
  72152. x3 = points [index++];
  72153. y3 = points [index++];
  72154. x4 = points [index++];
  72155. y4 = points [index++];
  72156. if (! isIdentityTransform)
  72157. {
  72158. transform.transformPoint (x3, y3);
  72159. transform.transformPoint (x4, y4);
  72160. }
  72161. }
  72162. }
  72163. }
  72164. }
  72165. else
  72166. {
  72167. type = *--stackPos;
  72168. if (type != Path::closeSubPathMarker)
  72169. {
  72170. x2 = *--stackPos;
  72171. y2 = *--stackPos;
  72172. if (type == Path::quadMarker)
  72173. {
  72174. x3 = *--stackPos;
  72175. y3 = *--stackPos;
  72176. }
  72177. else if (type == Path::cubicMarker)
  72178. {
  72179. x3 = *--stackPos;
  72180. y3 = *--stackPos;
  72181. x4 = *--stackPos;
  72182. y4 = *--stackPos;
  72183. }
  72184. }
  72185. }
  72186. if (type == Path::lineMarker)
  72187. {
  72188. ++subPathIndex;
  72189. closesSubPath = (stackPos == stackBase)
  72190. && (index < path.numElements)
  72191. && (points [index] == Path::closeSubPathMarker)
  72192. && x2 == subPathCloseX
  72193. && y2 == subPathCloseY;
  72194. return true;
  72195. }
  72196. else if (type == Path::quadMarker)
  72197. {
  72198. const int offset = (int) (stackPos - stackBase);
  72199. if (offset >= stackSize - 10)
  72200. {
  72201. stackSize <<= 1;
  72202. stackBase.realloc (stackSize);
  72203. stackPos = stackBase + offset;
  72204. }
  72205. const float dx1 = x1 - x2;
  72206. const float dy1 = y1 - y2;
  72207. const float dx2 = x2 - x3;
  72208. const float dy2 = y2 - y3;
  72209. const float m1x = (x1 + x2) * 0.5f;
  72210. const float m1y = (y1 + y2) * 0.5f;
  72211. const float m2x = (x2 + x3) * 0.5f;
  72212. const float m2y = (y2 + y3) * 0.5f;
  72213. const float m3x = (m1x + m2x) * 0.5f;
  72214. const float m3y = (m1y + m2y) * 0.5f;
  72215. if (dx1*dx1 + dy1*dy1 + dx2*dx2 + dy2*dy2 > tolerence)
  72216. {
  72217. *stackPos++ = y3;
  72218. *stackPos++ = x3;
  72219. *stackPos++ = m2y;
  72220. *stackPos++ = m2x;
  72221. *stackPos++ = Path::quadMarker;
  72222. *stackPos++ = m3y;
  72223. *stackPos++ = m3x;
  72224. *stackPos++ = m1y;
  72225. *stackPos++ = m1x;
  72226. *stackPos++ = Path::quadMarker;
  72227. }
  72228. else
  72229. {
  72230. *stackPos++ = y3;
  72231. *stackPos++ = x3;
  72232. *stackPos++ = Path::lineMarker;
  72233. *stackPos++ = m3y;
  72234. *stackPos++ = m3x;
  72235. *stackPos++ = Path::lineMarker;
  72236. }
  72237. jassert (stackPos < stackBase + stackSize);
  72238. }
  72239. else if (type == Path::cubicMarker)
  72240. {
  72241. const int offset = (int) (stackPos - stackBase);
  72242. if (offset >= stackSize - 16)
  72243. {
  72244. stackSize <<= 1;
  72245. stackBase.realloc (stackSize);
  72246. stackPos = stackBase + offset;
  72247. }
  72248. const float dx1 = x1 - x2;
  72249. const float dy1 = y1 - y2;
  72250. const float dx2 = x2 - x3;
  72251. const float dy2 = y2 - y3;
  72252. const float dx3 = x3 - x4;
  72253. const float dy3 = y3 - y4;
  72254. const float m1x = (x1 + x2) * 0.5f;
  72255. const float m1y = (y1 + y2) * 0.5f;
  72256. const float m2x = (x3 + x2) * 0.5f;
  72257. const float m2y = (y3 + y2) * 0.5f;
  72258. const float m3x = (x3 + x4) * 0.5f;
  72259. const float m3y = (y3 + y4) * 0.5f;
  72260. const float m4x = (m1x + m2x) * 0.5f;
  72261. const float m4y = (m1y + m2y) * 0.5f;
  72262. const float m5x = (m3x + m2x) * 0.5f;
  72263. const float m5y = (m3y + m2y) * 0.5f;
  72264. if (dx1*dx1 + dy1*dy1 + dx2*dx2
  72265. + dy2*dy2 + dx3*dx3 + dy3*dy3 > tolerence)
  72266. {
  72267. *stackPos++ = y4;
  72268. *stackPos++ = x4;
  72269. *stackPos++ = m3y;
  72270. *stackPos++ = m3x;
  72271. *stackPos++ = m5y;
  72272. *stackPos++ = m5x;
  72273. *stackPos++ = Path::cubicMarker;
  72274. *stackPos++ = (m4y + m5y) * 0.5f;
  72275. *stackPos++ = (m4x + m5x) * 0.5f;
  72276. *stackPos++ = m4y;
  72277. *stackPos++ = m4x;
  72278. *stackPos++ = m1y;
  72279. *stackPos++ = m1x;
  72280. *stackPos++ = Path::cubicMarker;
  72281. }
  72282. else
  72283. {
  72284. *stackPos++ = y4;
  72285. *stackPos++ = x4;
  72286. *stackPos++ = Path::lineMarker;
  72287. *stackPos++ = m5y;
  72288. *stackPos++ = m5x;
  72289. *stackPos++ = Path::lineMarker;
  72290. *stackPos++ = m4y;
  72291. *stackPos++ = m4x;
  72292. *stackPos++ = Path::lineMarker;
  72293. }
  72294. }
  72295. else if (type == Path::closeSubPathMarker)
  72296. {
  72297. if (x2 != subPathCloseX || y2 != subPathCloseY)
  72298. {
  72299. x1 = x2;
  72300. y1 = y2;
  72301. x2 = subPathCloseX;
  72302. y2 = subPathCloseY;
  72303. closesSubPath = true;
  72304. return true;
  72305. }
  72306. }
  72307. else
  72308. {
  72309. jassert (type == Path::moveMarker);
  72310. subPathIndex = -1;
  72311. subPathCloseX = x1 = x2;
  72312. subPathCloseY = y1 = y2;
  72313. }
  72314. }
  72315. }
  72316. END_JUCE_NAMESPACE
  72317. /*** End of inlined file: juce_PathIterator.cpp ***/
  72318. /*** Start of inlined file: juce_PathStrokeType.cpp ***/
  72319. BEGIN_JUCE_NAMESPACE
  72320. PathStrokeType::PathStrokeType (const float strokeThickness,
  72321. const JointStyle jointStyle_,
  72322. const EndCapStyle endStyle_) throw()
  72323. : thickness (strokeThickness),
  72324. jointStyle (jointStyle_),
  72325. endStyle (endStyle_)
  72326. {
  72327. }
  72328. PathStrokeType::PathStrokeType (const PathStrokeType& other) throw()
  72329. : thickness (other.thickness),
  72330. jointStyle (other.jointStyle),
  72331. endStyle (other.endStyle)
  72332. {
  72333. }
  72334. PathStrokeType& PathStrokeType::operator= (const PathStrokeType& other) throw()
  72335. {
  72336. thickness = other.thickness;
  72337. jointStyle = other.jointStyle;
  72338. endStyle = other.endStyle;
  72339. return *this;
  72340. }
  72341. PathStrokeType::~PathStrokeType() throw()
  72342. {
  72343. }
  72344. bool PathStrokeType::operator== (const PathStrokeType& other) const throw()
  72345. {
  72346. return thickness == other.thickness
  72347. && jointStyle == other.jointStyle
  72348. && endStyle == other.endStyle;
  72349. }
  72350. bool PathStrokeType::operator!= (const PathStrokeType& other) const throw()
  72351. {
  72352. return ! operator== (other);
  72353. }
  72354. static bool lineIntersection (const float x1, const float y1,
  72355. const float x2, const float y2,
  72356. const float x3, const float y3,
  72357. const float x4, const float y4,
  72358. float& intersectionX,
  72359. float& intersectionY,
  72360. float& distanceBeyondLine1EndSquared) throw()
  72361. {
  72362. if (x2 != x3 || y2 != y3)
  72363. {
  72364. const float dx1 = x2 - x1;
  72365. const float dy1 = y2 - y1;
  72366. const float dx2 = x4 - x3;
  72367. const float dy2 = y4 - y3;
  72368. const float divisor = dx1 * dy2 - dx2 * dy1;
  72369. if (divisor == 0)
  72370. {
  72371. if (! ((dx1 == 0 && dy1 == 0) || (dx2 == 0 && dy2 == 0)))
  72372. {
  72373. if (dy1 == 0 && dy2 != 0)
  72374. {
  72375. const float along = (y1 - y3) / dy2;
  72376. intersectionX = x3 + along * dx2;
  72377. intersectionY = y1;
  72378. distanceBeyondLine1EndSquared = intersectionX - x2;
  72379. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72380. if ((x2 > x1) == (intersectionX < x2))
  72381. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72382. return along >= 0 && along <= 1.0f;
  72383. }
  72384. else if (dy2 == 0 && dy1 != 0)
  72385. {
  72386. const float along = (y3 - y1) / dy1;
  72387. intersectionX = x1 + along * dx1;
  72388. intersectionY = y3;
  72389. distanceBeyondLine1EndSquared = (along - 1.0f) * dx1;
  72390. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72391. if (along < 1.0f)
  72392. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72393. return along >= 0 && along <= 1.0f;
  72394. }
  72395. else if (dx1 == 0 && dx2 != 0)
  72396. {
  72397. const float along = (x1 - x3) / dx2;
  72398. intersectionX = x1;
  72399. intersectionY = y3 + along * dy2;
  72400. distanceBeyondLine1EndSquared = intersectionY - y2;
  72401. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72402. if ((y2 > y1) == (intersectionY < y2))
  72403. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72404. return along >= 0 && along <= 1.0f;
  72405. }
  72406. else if (dx2 == 0 && dx1 != 0)
  72407. {
  72408. const float along = (x3 - x1) / dx1;
  72409. intersectionX = x3;
  72410. intersectionY = y1 + along * dy1;
  72411. distanceBeyondLine1EndSquared = (along - 1.0f) * dy1;
  72412. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72413. if (along < 1.0f)
  72414. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72415. return along >= 0 && along <= 1.0f;
  72416. }
  72417. }
  72418. intersectionX = 0.5f * (x2 + x3);
  72419. intersectionY = 0.5f * (y2 + y3);
  72420. distanceBeyondLine1EndSquared = 0.0f;
  72421. return false;
  72422. }
  72423. else
  72424. {
  72425. const float along1 = ((y1 - y3) * dx2 - (x1 - x3) * dy2) / divisor;
  72426. intersectionX = x1 + along1 * dx1;
  72427. intersectionY = y1 + along1 * dy1;
  72428. if (along1 >= 0 && along1 <= 1.0f)
  72429. {
  72430. const float along2 = ((y1 - y3) * dx1 - (x1 - x3) * dy1);
  72431. if (along2 >= 0 && along2 <= divisor)
  72432. {
  72433. distanceBeyondLine1EndSquared = 0.0f;
  72434. return true;
  72435. }
  72436. }
  72437. distanceBeyondLine1EndSquared = along1 - 1.0f;
  72438. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72439. distanceBeyondLine1EndSquared *= (dx1 * dx1 + dy1 * dy1);
  72440. if (along1 < 1.0f)
  72441. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72442. return false;
  72443. }
  72444. }
  72445. intersectionX = x2;
  72446. intersectionY = y2;
  72447. distanceBeyondLine1EndSquared = 0.0f;
  72448. return true;
  72449. }
  72450. namespace PathFunctions
  72451. {
  72452. // part of stroke drawing stuff
  72453. static void addEdgeAndJoint (Path& destPath,
  72454. const PathStrokeType::JointStyle style,
  72455. const float maxMiterExtensionSquared, const float width,
  72456. const float x1, const float y1,
  72457. const float x2, const float y2,
  72458. const float x3, const float y3,
  72459. const float x4, const float y4,
  72460. const float midX, const float midY)
  72461. {
  72462. if (style == PathStrokeType::beveled
  72463. || (x3 == x4 && y3 == y4)
  72464. || (x1 == x2 && y1 == y2))
  72465. {
  72466. destPath.lineTo (x2, y2);
  72467. destPath.lineTo (x3, y3);
  72468. }
  72469. else
  72470. {
  72471. float jx, jy, distanceBeyondLine1EndSquared;
  72472. // if they intersect, use this point..
  72473. if (lineIntersection (x1, y1, x2, y2,
  72474. x3, y3, x4, y4,
  72475. jx, jy, distanceBeyondLine1EndSquared))
  72476. {
  72477. destPath.lineTo (jx, jy);
  72478. }
  72479. else
  72480. {
  72481. if (style == PathStrokeType::mitered)
  72482. {
  72483. if (distanceBeyondLine1EndSquared < maxMiterExtensionSquared
  72484. && distanceBeyondLine1EndSquared > 0.0f)
  72485. {
  72486. destPath.lineTo (jx, jy);
  72487. }
  72488. else
  72489. {
  72490. // the end sticks out too far, so just use a blunt joint
  72491. destPath.lineTo (x2, y2);
  72492. destPath.lineTo (x3, y3);
  72493. }
  72494. }
  72495. else
  72496. {
  72497. // curved joints
  72498. float angle1 = atan2f (x2 - midX, y2 - midY);
  72499. float angle2 = atan2f (x3 - midX, y3 - midY);
  72500. const float angleIncrement = 0.1f;
  72501. destPath.lineTo (x2, y2);
  72502. if (fabs (angle1 - angle2) > angleIncrement)
  72503. {
  72504. if (angle2 > angle1 + float_Pi
  72505. || (angle2 < angle1 && angle2 >= angle1 - float_Pi))
  72506. {
  72507. if (angle2 > angle1)
  72508. angle2 -= float_Pi * 2.0f;
  72509. jassert (angle1 <= angle2 + float_Pi);
  72510. angle1 -= angleIncrement;
  72511. while (angle1 > angle2)
  72512. {
  72513. destPath.lineTo (midX + width * sinf (angle1),
  72514. midY + width * cosf (angle1));
  72515. angle1 -= angleIncrement;
  72516. }
  72517. }
  72518. else
  72519. {
  72520. if (angle1 > angle2)
  72521. angle1 -= float_Pi * 2.0f;
  72522. jassert (angle1 >= angle2 - float_Pi);
  72523. angle1 += angleIncrement;
  72524. while (angle1 < angle2)
  72525. {
  72526. destPath.lineTo (midX + width * sinf (angle1),
  72527. midY + width * cosf (angle1));
  72528. angle1 += angleIncrement;
  72529. }
  72530. }
  72531. }
  72532. destPath.lineTo (x3, y3);
  72533. }
  72534. }
  72535. }
  72536. }
  72537. static void addLineEnd (Path& destPath,
  72538. const PathStrokeType::EndCapStyle style,
  72539. const float x1, const float y1,
  72540. const float x2, const float y2,
  72541. const float width)
  72542. {
  72543. if (style == PathStrokeType::butt)
  72544. {
  72545. destPath.lineTo (x2, y2);
  72546. }
  72547. else
  72548. {
  72549. float offx1, offy1, offx2, offy2;
  72550. float dx = x2 - x1;
  72551. float dy = y2 - y1;
  72552. const float len = juce_hypotf (dx, dy);
  72553. if (len == 0)
  72554. {
  72555. offx1 = offx2 = x1;
  72556. offy1 = offy2 = y1;
  72557. }
  72558. else
  72559. {
  72560. const float offset = width / len;
  72561. dx *= offset;
  72562. dy *= offset;
  72563. offx1 = x1 + dy;
  72564. offy1 = y1 - dx;
  72565. offx2 = x2 + dy;
  72566. offy2 = y2 - dx;
  72567. }
  72568. if (style == PathStrokeType::square)
  72569. {
  72570. // sqaure ends
  72571. destPath.lineTo (offx1, offy1);
  72572. destPath.lineTo (offx2, offy2);
  72573. destPath.lineTo (x2, y2);
  72574. }
  72575. else
  72576. {
  72577. // rounded ends
  72578. const float midx = (offx1 + offx2) * 0.5f;
  72579. const float midy = (offy1 + offy2) * 0.5f;
  72580. destPath.cubicTo (x1 + (offx1 - x1) * 0.55f, y1 + (offy1 - y1) * 0.55f,
  72581. offx1 + (midx - offx1) * 0.45f, offy1 + (midy - offy1) * 0.45f,
  72582. midx, midy);
  72583. destPath.cubicTo (midx + (offx2 - midx) * 0.55f, midy + (offy2 - midy) * 0.55f,
  72584. offx2 + (x2 - offx2) * 0.45f, offy2 + (y2 - offy2) * 0.45f,
  72585. x2, y2);
  72586. }
  72587. }
  72588. }
  72589. struct LineSection
  72590. {
  72591. LineSection() {}
  72592. LineSection (int) {}
  72593. float x1, y1, x2, y2; // original line
  72594. float lx1, ly1, lx2, ly2; // the left-hand stroke
  72595. float rx1, ry1, rx2, ry2; // the right-hand stroke
  72596. };
  72597. static void addSubPath (Path& destPath, const Array <LineSection>& subPath,
  72598. const bool isClosed,
  72599. const float width, const float maxMiterExtensionSquared,
  72600. const PathStrokeType::JointStyle jointStyle, const PathStrokeType::EndCapStyle endStyle)
  72601. {
  72602. jassert (subPath.size() > 0);
  72603. const LineSection& firstLine = subPath.getReference (0);
  72604. float lastX1 = firstLine.lx1;
  72605. float lastY1 = firstLine.ly1;
  72606. float lastX2 = firstLine.lx2;
  72607. float lastY2 = firstLine.ly2;
  72608. if (isClosed)
  72609. {
  72610. destPath.startNewSubPath (lastX1, lastY1);
  72611. }
  72612. else
  72613. {
  72614. destPath.startNewSubPath (firstLine.rx2, firstLine.ry2);
  72615. addLineEnd (destPath, endStyle,
  72616. firstLine.rx2, firstLine.ry2,
  72617. lastX1, lastY1,
  72618. width);
  72619. }
  72620. int i;
  72621. for (i = 1; i < subPath.size(); ++i)
  72622. {
  72623. const LineSection& l = subPath.getReference (i);
  72624. addEdgeAndJoint (destPath, jointStyle,
  72625. maxMiterExtensionSquared, width,
  72626. lastX1, lastY1, lastX2, lastY2,
  72627. l.lx1, l.ly1, l.lx2, l.ly2,
  72628. l.x1, l.y1);
  72629. lastX1 = l.lx1;
  72630. lastY1 = l.ly1;
  72631. lastX2 = l.lx2;
  72632. lastY2 = l.ly2;
  72633. }
  72634. const LineSection& lastLine = subPath.getReference (subPath.size() - 1);
  72635. if (isClosed)
  72636. {
  72637. const LineSection& l = subPath.getReference (0);
  72638. addEdgeAndJoint (destPath, jointStyle,
  72639. maxMiterExtensionSquared, width,
  72640. lastX1, lastY1, lastX2, lastY2,
  72641. l.lx1, l.ly1, l.lx2, l.ly2,
  72642. l.x1, l.y1);
  72643. destPath.closeSubPath();
  72644. destPath.startNewSubPath (lastLine.rx1, lastLine.ry1);
  72645. }
  72646. else
  72647. {
  72648. destPath.lineTo (lastX2, lastY2);
  72649. addLineEnd (destPath, endStyle,
  72650. lastX2, lastY2,
  72651. lastLine.rx1, lastLine.ry1,
  72652. width);
  72653. }
  72654. lastX1 = lastLine.rx1;
  72655. lastY1 = lastLine.ry1;
  72656. lastX2 = lastLine.rx2;
  72657. lastY2 = lastLine.ry2;
  72658. for (i = subPath.size() - 1; --i >= 0;)
  72659. {
  72660. const LineSection& l = subPath.getReference (i);
  72661. addEdgeAndJoint (destPath, jointStyle,
  72662. maxMiterExtensionSquared, width,
  72663. lastX1, lastY1, lastX2, lastY2,
  72664. l.rx1, l.ry1, l.rx2, l.ry2,
  72665. l.x2, l.y2);
  72666. lastX1 = l.rx1;
  72667. lastY1 = l.ry1;
  72668. lastX2 = l.rx2;
  72669. lastY2 = l.ry2;
  72670. }
  72671. if (isClosed)
  72672. {
  72673. addEdgeAndJoint (destPath, jointStyle,
  72674. maxMiterExtensionSquared, width,
  72675. lastX1, lastY1, lastX2, lastY2,
  72676. lastLine.rx1, lastLine.ry1, lastLine.rx2, lastLine.ry2,
  72677. lastLine.x2, lastLine.y2);
  72678. }
  72679. else
  72680. {
  72681. // do the last line
  72682. destPath.lineTo (lastX2, lastY2);
  72683. }
  72684. destPath.closeSubPath();
  72685. }
  72686. }
  72687. void PathStrokeType::createStrokedPath (Path& destPath,
  72688. const Path& source,
  72689. const AffineTransform& transform,
  72690. const float extraAccuracy) const
  72691. {
  72692. if (thickness <= 0)
  72693. {
  72694. destPath.clear();
  72695. return;
  72696. }
  72697. const Path* sourcePath = &source;
  72698. Path temp;
  72699. if (sourcePath == &destPath)
  72700. {
  72701. destPath.swapWithPath (temp);
  72702. sourcePath = &temp;
  72703. }
  72704. else
  72705. {
  72706. destPath.clear();
  72707. }
  72708. destPath.setUsingNonZeroWinding (true);
  72709. const float maxMiterExtensionSquared = 9.0f * thickness * thickness;
  72710. const float width = 0.5f * thickness;
  72711. // Iterate the path, creating a list of the
  72712. // left/right-hand lines along either side of it...
  72713. PathFlatteningIterator it (*sourcePath, transform, 9.0f / extraAccuracy);
  72714. using namespace PathFunctions;
  72715. Array <LineSection> subPath;
  72716. LineSection l;
  72717. l.x1 = 0;
  72718. l.y1 = 0;
  72719. const float minSegmentLength = 2.0f / (extraAccuracy * extraAccuracy);
  72720. while (it.next())
  72721. {
  72722. if (it.subPathIndex == 0)
  72723. {
  72724. if (subPath.size() > 0)
  72725. {
  72726. addSubPath (destPath, subPath, false, width, maxMiterExtensionSquared, jointStyle, endStyle);
  72727. subPath.clearQuick();
  72728. }
  72729. l.x1 = it.x1;
  72730. l.y1 = it.y1;
  72731. }
  72732. l.x2 = it.x2;
  72733. l.y2 = it.y2;
  72734. float dx = l.x2 - l.x1;
  72735. float dy = l.y2 - l.y1;
  72736. const float hypotSquared = dx*dx + dy*dy;
  72737. if (it.closesSubPath || hypotSquared > minSegmentLength || it.isLastInSubpath())
  72738. {
  72739. const float len = sqrtf (hypotSquared);
  72740. if (len == 0)
  72741. {
  72742. l.rx1 = l.rx2 = l.lx1 = l.lx2 = l.x1;
  72743. l.ry1 = l.ry2 = l.ly1 = l.ly2 = l.y1;
  72744. }
  72745. else
  72746. {
  72747. const float offset = width / len;
  72748. dx *= offset;
  72749. dy *= offset;
  72750. l.rx2 = l.x1 - dy;
  72751. l.ry2 = l.y1 + dx;
  72752. l.lx1 = l.x1 + dy;
  72753. l.ly1 = l.y1 - dx;
  72754. l.lx2 = l.x2 + dy;
  72755. l.ly2 = l.y2 - dx;
  72756. l.rx1 = l.x2 - dy;
  72757. l.ry1 = l.y2 + dx;
  72758. }
  72759. subPath.add (l);
  72760. if (it.closesSubPath)
  72761. {
  72762. addSubPath (destPath, subPath, true, width, maxMiterExtensionSquared, jointStyle, endStyle);
  72763. subPath.clearQuick();
  72764. }
  72765. else
  72766. {
  72767. l.x1 = it.x2;
  72768. l.y1 = it.y2;
  72769. }
  72770. }
  72771. }
  72772. if (subPath.size() > 0)
  72773. addSubPath (destPath, subPath, false, width, maxMiterExtensionSquared, jointStyle, endStyle);
  72774. }
  72775. void PathStrokeType::createDashedStroke (Path& destPath,
  72776. const Path& sourcePath,
  72777. const float* dashLengths,
  72778. int numDashLengths,
  72779. const AffineTransform& transform,
  72780. const float extraAccuracy) const
  72781. {
  72782. if (thickness <= 0)
  72783. return;
  72784. // this should really be an even number..
  72785. jassert ((numDashLengths & 1) == 0);
  72786. Path newDestPath;
  72787. PathFlatteningIterator it (sourcePath, transform, 9.0f / extraAccuracy);
  72788. bool first = true;
  72789. int dashNum = 0;
  72790. float pos = 0.0f, lineLen = 0.0f, lineEndPos = 0.0f;
  72791. float dx = 0.0f, dy = 0.0f;
  72792. for (;;)
  72793. {
  72794. const bool isSolid = ((dashNum & 1) == 0);
  72795. const float dashLen = dashLengths [dashNum++ % numDashLengths];
  72796. jassert (dashLen > 0); // must be a positive increment!
  72797. if (dashLen <= 0)
  72798. break;
  72799. pos += dashLen;
  72800. while (pos > lineEndPos)
  72801. {
  72802. if (! it.next())
  72803. {
  72804. if (isSolid && ! first)
  72805. newDestPath.lineTo (it.x2, it.y2);
  72806. createStrokedPath (destPath, newDestPath, AffineTransform::identity, extraAccuracy);
  72807. return;
  72808. }
  72809. if (isSolid && ! first)
  72810. newDestPath.lineTo (it.x1, it.y1);
  72811. else
  72812. newDestPath.startNewSubPath (it.x1, it.y1);
  72813. dx = it.x2 - it.x1;
  72814. dy = it.y2 - it.y1;
  72815. lineLen = juce_hypotf (dx, dy);
  72816. lineEndPos += lineLen;
  72817. first = it.closesSubPath;
  72818. }
  72819. const float alpha = (pos - (lineEndPos - lineLen)) / lineLen;
  72820. if (isSolid)
  72821. newDestPath.lineTo (it.x1 + dx * alpha,
  72822. it.y1 + dy * alpha);
  72823. else
  72824. newDestPath.startNewSubPath (it.x1 + dx * alpha,
  72825. it.y1 + dy * alpha);
  72826. }
  72827. }
  72828. END_JUCE_NAMESPACE
  72829. /*** End of inlined file: juce_PathStrokeType.cpp ***/
  72830. /*** Start of inlined file: juce_PositionedRectangle.cpp ***/
  72831. BEGIN_JUCE_NAMESPACE
  72832. PositionedRectangle::PositionedRectangle() throw()
  72833. : x (0.0),
  72834. y (0.0),
  72835. w (0.0),
  72836. h (0.0),
  72837. xMode (anchorAtLeftOrTop | absoluteFromParentTopLeft),
  72838. yMode (anchorAtLeftOrTop | absoluteFromParentTopLeft),
  72839. wMode (absoluteSize),
  72840. hMode (absoluteSize)
  72841. {
  72842. }
  72843. PositionedRectangle::PositionedRectangle (const PositionedRectangle& other) throw()
  72844. : x (other.x),
  72845. y (other.y),
  72846. w (other.w),
  72847. h (other.h),
  72848. xMode (other.xMode),
  72849. yMode (other.yMode),
  72850. wMode (other.wMode),
  72851. hMode (other.hMode)
  72852. {
  72853. }
  72854. PositionedRectangle& PositionedRectangle::operator= (const PositionedRectangle& other) throw()
  72855. {
  72856. x = other.x;
  72857. y = other.y;
  72858. w = other.w;
  72859. h = other.h;
  72860. xMode = other.xMode;
  72861. yMode = other.yMode;
  72862. wMode = other.wMode;
  72863. hMode = other.hMode;
  72864. return *this;
  72865. }
  72866. PositionedRectangle::~PositionedRectangle() throw()
  72867. {
  72868. }
  72869. bool PositionedRectangle::operator== (const PositionedRectangle& other) const throw()
  72870. {
  72871. return x == other.x
  72872. && y == other.y
  72873. && w == other.w
  72874. && h == other.h
  72875. && xMode == other.xMode
  72876. && yMode == other.yMode
  72877. && wMode == other.wMode
  72878. && hMode == other.hMode;
  72879. }
  72880. bool PositionedRectangle::operator!= (const PositionedRectangle& other) const throw()
  72881. {
  72882. return ! operator== (other);
  72883. }
  72884. PositionedRectangle::PositionedRectangle (const String& stringVersion) throw()
  72885. {
  72886. StringArray tokens;
  72887. tokens.addTokens (stringVersion, false);
  72888. decodePosString (tokens [0], xMode, x);
  72889. decodePosString (tokens [1], yMode, y);
  72890. decodeSizeString (tokens [2], wMode, w);
  72891. decodeSizeString (tokens [3], hMode, h);
  72892. }
  72893. const String PositionedRectangle::toString() const throw()
  72894. {
  72895. String s;
  72896. s.preallocateStorage (12);
  72897. addPosDescription (s, xMode, x);
  72898. s << T(' ');
  72899. addPosDescription (s, yMode, y);
  72900. s << T(' ');
  72901. addSizeDescription (s, wMode, w);
  72902. s << T(' ');
  72903. addSizeDescription (s, hMode, h);
  72904. return s;
  72905. }
  72906. const Rectangle<int> PositionedRectangle::getRectangle (const Rectangle<int>& target) const throw()
  72907. {
  72908. jassert (! target.isEmpty());
  72909. double x_, y_, w_, h_;
  72910. applyPosAndSize (x_, w_, x, w, xMode, wMode, target.getX(), target.getWidth());
  72911. applyPosAndSize (y_, h_, y, h, yMode, hMode, target.getY(), target.getHeight());
  72912. return Rectangle<int> (roundToInt (x_), roundToInt (y_),
  72913. roundToInt (w_), roundToInt (h_));
  72914. }
  72915. void PositionedRectangle::getRectangleDouble (const Rectangle<int>& target,
  72916. double& x_, double& y_,
  72917. double& w_, double& h_) const throw()
  72918. {
  72919. jassert (! target.isEmpty());
  72920. applyPosAndSize (x_, w_, x, w, xMode, wMode, target.getX(), target.getWidth());
  72921. applyPosAndSize (y_, h_, y, h, yMode, hMode, target.getY(), target.getHeight());
  72922. }
  72923. void PositionedRectangle::applyToComponent (Component& comp) const throw()
  72924. {
  72925. comp.setBounds (getRectangle (Rectangle<int> (0, 0, comp.getParentWidth(), comp.getParentHeight())));
  72926. }
  72927. void PositionedRectangle::updateFrom (const Rectangle<int>& rectangle,
  72928. const Rectangle<int>& target) throw()
  72929. {
  72930. updatePosAndSize (x, w, rectangle.getX(), rectangle.getWidth(), xMode, wMode, target.getX(), target.getWidth());
  72931. updatePosAndSize (y, h, rectangle.getY(), rectangle.getHeight(), yMode, hMode, target.getY(), target.getHeight());
  72932. }
  72933. void PositionedRectangle::updateFromDouble (const double newX, const double newY,
  72934. const double newW, const double newH,
  72935. const Rectangle<int>& target) throw()
  72936. {
  72937. updatePosAndSize (x, w, newX, newW, xMode, wMode, target.getX(), target.getWidth());
  72938. updatePosAndSize (y, h, newY, newH, yMode, hMode, target.getY(), target.getHeight());
  72939. }
  72940. void PositionedRectangle::updateFromComponent (const Component& comp) throw()
  72941. {
  72942. if (comp.getParentComponent() == 0 && ! comp.isOnDesktop())
  72943. updateFrom (comp.getBounds(), Rectangle<int>());
  72944. else
  72945. updateFrom (comp.getBounds(), Rectangle<int> (0, 0, comp.getParentWidth(), comp.getParentHeight()));
  72946. }
  72947. PositionedRectangle::AnchorPoint PositionedRectangle::getAnchorPointX() const throw()
  72948. {
  72949. return (AnchorPoint) (xMode & (anchorAtLeftOrTop | anchorAtRightOrBottom | anchorAtCentre));
  72950. }
  72951. PositionedRectangle::PositionMode PositionedRectangle::getPositionModeX() const throw()
  72952. {
  72953. return (PositionMode) (xMode & (absoluteFromParentTopLeft
  72954. | absoluteFromParentBottomRight
  72955. | absoluteFromParentCentre
  72956. | proportionOfParentSize));
  72957. }
  72958. PositionedRectangle::AnchorPoint PositionedRectangle::getAnchorPointY() const throw()
  72959. {
  72960. return (AnchorPoint) (yMode & (anchorAtLeftOrTop | anchorAtRightOrBottom | anchorAtCentre));
  72961. }
  72962. PositionedRectangle::PositionMode PositionedRectangle::getPositionModeY() const throw()
  72963. {
  72964. return (PositionMode) (yMode & (absoluteFromParentTopLeft
  72965. | absoluteFromParentBottomRight
  72966. | absoluteFromParentCentre
  72967. | proportionOfParentSize));
  72968. }
  72969. PositionedRectangle::SizeMode PositionedRectangle::getWidthMode() const throw()
  72970. {
  72971. return (SizeMode) wMode;
  72972. }
  72973. PositionedRectangle::SizeMode PositionedRectangle::getHeightMode() const throw()
  72974. {
  72975. return (SizeMode) hMode;
  72976. }
  72977. void PositionedRectangle::setModes (const AnchorPoint xAnchor,
  72978. const PositionMode xMode_,
  72979. const AnchorPoint yAnchor,
  72980. const PositionMode yMode_,
  72981. const SizeMode widthMode,
  72982. const SizeMode heightMode,
  72983. const Rectangle<int>& target) throw()
  72984. {
  72985. if (xMode != (xAnchor | xMode_) || wMode != widthMode)
  72986. {
  72987. double tx, tw;
  72988. applyPosAndSize (tx, tw, x, w, xMode, wMode, target.getX(), target.getWidth());
  72989. xMode = (uint8) (xAnchor | xMode_);
  72990. wMode = (uint8) widthMode;
  72991. updatePosAndSize (x, w, tx, tw, xMode, wMode, target.getX(), target.getWidth());
  72992. }
  72993. if (yMode != (yAnchor | yMode_) || hMode != heightMode)
  72994. {
  72995. double ty, th;
  72996. applyPosAndSize (ty, th, y, h, yMode, hMode, target.getY(), target.getHeight());
  72997. yMode = (uint8) (yAnchor | yMode_);
  72998. hMode = (uint8) heightMode;
  72999. updatePosAndSize (y, h, ty, th, yMode, hMode, target.getY(), target.getHeight());
  73000. }
  73001. }
  73002. bool PositionedRectangle::isPositionAbsolute() const throw()
  73003. {
  73004. return xMode == absoluteFromParentTopLeft
  73005. && yMode == absoluteFromParentTopLeft
  73006. && wMode == absoluteSize
  73007. && hMode == absoluteSize;
  73008. }
  73009. void PositionedRectangle::addPosDescription (String& s, const uint8 mode, const double value) const throw()
  73010. {
  73011. if ((mode & proportionOfParentSize) != 0)
  73012. {
  73013. s << (roundToInt (value * 100000.0) / 1000.0) << T('%');
  73014. }
  73015. else
  73016. {
  73017. s << (roundToInt (value * 100.0) / 100.0);
  73018. if ((mode & absoluteFromParentBottomRight) != 0)
  73019. s << T('R');
  73020. else if ((mode & absoluteFromParentCentre) != 0)
  73021. s << T('C');
  73022. }
  73023. if ((mode & anchorAtRightOrBottom) != 0)
  73024. s << T('r');
  73025. else if ((mode & anchorAtCentre) != 0)
  73026. s << T('c');
  73027. }
  73028. void PositionedRectangle::addSizeDescription (String& s, const uint8 mode, const double value) const throw()
  73029. {
  73030. if (mode == proportionalSize)
  73031. s << (roundToInt (value * 100000.0) / 1000.0) << T('%');
  73032. else if (mode == parentSizeMinusAbsolute)
  73033. s << (roundToInt (value * 100.0) / 100.0) << T('M');
  73034. else
  73035. s << (roundToInt (value * 100.0) / 100.0);
  73036. }
  73037. void PositionedRectangle::decodePosString (const String& s, uint8& mode, double& value) throw()
  73038. {
  73039. if (s.containsChar (T('r')))
  73040. mode = anchorAtRightOrBottom;
  73041. else if (s.containsChar (T('c')))
  73042. mode = anchorAtCentre;
  73043. else
  73044. mode = anchorAtLeftOrTop;
  73045. if (s.containsChar (T('%')))
  73046. {
  73047. mode |= proportionOfParentSize;
  73048. value = s.removeCharacters (T("%rcRC")).getDoubleValue() / 100.0;
  73049. }
  73050. else
  73051. {
  73052. if (s.containsChar (T('R')))
  73053. mode |= absoluteFromParentBottomRight;
  73054. else if (s.containsChar (T('C')))
  73055. mode |= absoluteFromParentCentre;
  73056. else
  73057. mode |= absoluteFromParentTopLeft;
  73058. value = s.removeCharacters (T("rcRC")).getDoubleValue();
  73059. }
  73060. }
  73061. void PositionedRectangle::decodeSizeString (const String& s, uint8& mode, double& value) throw()
  73062. {
  73063. if (s.containsChar (T('%')))
  73064. {
  73065. mode = proportionalSize;
  73066. value = s.upToFirstOccurrenceOf (T("%"), false, false).getDoubleValue() / 100.0;
  73067. }
  73068. else if (s.containsChar (T('M')))
  73069. {
  73070. mode = parentSizeMinusAbsolute;
  73071. value = s.getDoubleValue();
  73072. }
  73073. else
  73074. {
  73075. mode = absoluteSize;
  73076. value = s.getDoubleValue();
  73077. }
  73078. }
  73079. void PositionedRectangle::applyPosAndSize (double& xOut, double& wOut,
  73080. const double x_, const double w_,
  73081. const uint8 xMode_, const uint8 wMode_,
  73082. const int parentPos,
  73083. const int parentSize) const throw()
  73084. {
  73085. if (wMode_ == proportionalSize)
  73086. wOut = roundToInt (w_ * parentSize);
  73087. else if (wMode_ == parentSizeMinusAbsolute)
  73088. wOut = jmax (0, parentSize - roundToInt (w_));
  73089. else
  73090. wOut = roundToInt (w_);
  73091. if ((xMode_ & proportionOfParentSize) != 0)
  73092. xOut = parentPos + x_ * parentSize;
  73093. else if ((xMode_ & absoluteFromParentBottomRight) != 0)
  73094. xOut = (parentPos + parentSize) - x_;
  73095. else if ((xMode_ & absoluteFromParentCentre) != 0)
  73096. xOut = x_ + (parentPos + parentSize / 2);
  73097. else
  73098. xOut = x_ + parentPos;
  73099. if ((xMode_ & anchorAtRightOrBottom) != 0)
  73100. xOut -= wOut;
  73101. else if ((xMode_ & anchorAtCentre) != 0)
  73102. xOut -= wOut / 2;
  73103. }
  73104. void PositionedRectangle::updatePosAndSize (double& xOut, double& wOut,
  73105. double x_, const double w_,
  73106. const uint8 xMode_, const uint8 wMode_,
  73107. const int parentPos,
  73108. const int parentSize) const throw()
  73109. {
  73110. if (wMode_ == proportionalSize)
  73111. {
  73112. if (parentSize > 0)
  73113. wOut = w_ / parentSize;
  73114. }
  73115. else if (wMode_ == parentSizeMinusAbsolute)
  73116. wOut = parentSize - w_;
  73117. else
  73118. wOut = w_;
  73119. if ((xMode_ & anchorAtRightOrBottom) != 0)
  73120. x_ += w_;
  73121. else if ((xMode_ & anchorAtCentre) != 0)
  73122. x_ += w_ / 2;
  73123. if ((xMode_ & proportionOfParentSize) != 0)
  73124. {
  73125. if (parentSize > 0)
  73126. xOut = (x_ - parentPos) / parentSize;
  73127. }
  73128. else if ((xMode_ & absoluteFromParentBottomRight) != 0)
  73129. xOut = (parentPos + parentSize) - x_;
  73130. else if ((xMode_ & absoluteFromParentCentre) != 0)
  73131. xOut = x_ - (parentPos + parentSize / 2);
  73132. else
  73133. xOut = x_ - parentPos;
  73134. }
  73135. END_JUCE_NAMESPACE
  73136. /*** End of inlined file: juce_PositionedRectangle.cpp ***/
  73137. /*** Start of inlined file: juce_RectangleList.cpp ***/
  73138. BEGIN_JUCE_NAMESPACE
  73139. RectangleList::RectangleList() throw()
  73140. {
  73141. }
  73142. RectangleList::RectangleList (const Rectangle<int>& rect) throw()
  73143. {
  73144. if (! rect.isEmpty())
  73145. rects.add (rect);
  73146. }
  73147. RectangleList::RectangleList (const RectangleList& other) throw()
  73148. : rects (other.rects)
  73149. {
  73150. }
  73151. RectangleList& RectangleList::operator= (const RectangleList& other) throw()
  73152. {
  73153. rects = other.rects;
  73154. return *this;
  73155. }
  73156. RectangleList::~RectangleList() throw()
  73157. {
  73158. }
  73159. void RectangleList::clear() throw()
  73160. {
  73161. rects.clearQuick();
  73162. }
  73163. const Rectangle<int> RectangleList::getRectangle (const int index) const throw()
  73164. {
  73165. if (((unsigned int) index) < (unsigned int) rects.size())
  73166. return rects.getReference (index);
  73167. return Rectangle<int>();
  73168. }
  73169. bool RectangleList::isEmpty() const throw()
  73170. {
  73171. return rects.size() == 0;
  73172. }
  73173. RectangleList::Iterator::Iterator (const RectangleList& list) throw()
  73174. : current (0),
  73175. owner (list),
  73176. index (list.rects.size())
  73177. {
  73178. }
  73179. RectangleList::Iterator::~Iterator() throw()
  73180. {
  73181. }
  73182. bool RectangleList::Iterator::next() throw()
  73183. {
  73184. if (--index >= 0)
  73185. {
  73186. current = & (owner.rects.getReference (index));
  73187. return true;
  73188. }
  73189. return false;
  73190. }
  73191. void RectangleList::add (const Rectangle<int>& rect) throw()
  73192. {
  73193. if (! rect.isEmpty())
  73194. {
  73195. if (rects.size() == 0)
  73196. {
  73197. rects.add (rect);
  73198. }
  73199. else
  73200. {
  73201. bool anyOverlaps = false;
  73202. int i;
  73203. for (i = rects.size(); --i >= 0;)
  73204. {
  73205. Rectangle<int>& ourRect = rects.getReference (i);
  73206. if (rect.intersects (ourRect))
  73207. {
  73208. if (rect.contains (ourRect))
  73209. rects.remove (i);
  73210. else if (! ourRect.reduceIfPartlyContainedIn (rect))
  73211. anyOverlaps = true;
  73212. }
  73213. }
  73214. if (anyOverlaps && rects.size() > 0)
  73215. {
  73216. RectangleList r (rect);
  73217. for (i = rects.size(); --i >= 0;)
  73218. {
  73219. const Rectangle<int>& ourRect = rects.getReference (i);
  73220. if (rect.intersects (ourRect))
  73221. {
  73222. r.subtract (ourRect);
  73223. if (r.rects.size() == 0)
  73224. return;
  73225. }
  73226. }
  73227. for (i = r.getNumRectangles(); --i >= 0;)
  73228. rects.add (r.rects.getReference (i));
  73229. }
  73230. else
  73231. {
  73232. rects.add (rect);
  73233. }
  73234. }
  73235. }
  73236. }
  73237. void RectangleList::addWithoutMerging (const Rectangle<int>& rect) throw()
  73238. {
  73239. rects.add (rect);
  73240. }
  73241. void RectangleList::add (const int x, const int y, const int w, const int h) throw()
  73242. {
  73243. if (rects.size() == 0)
  73244. {
  73245. if (w > 0 && h > 0)
  73246. rects.add (Rectangle<int> (x, y, w, h));
  73247. }
  73248. else
  73249. {
  73250. add (Rectangle<int> (x, y, w, h));
  73251. }
  73252. }
  73253. void RectangleList::add (const RectangleList& other) throw()
  73254. {
  73255. for (int i = 0; i < other.rects.size(); ++i)
  73256. add (other.rects.getReference (i));
  73257. }
  73258. void RectangleList::subtract (const Rectangle<int>& rect) throw()
  73259. {
  73260. const int originalNumRects = rects.size();
  73261. if (originalNumRects > 0)
  73262. {
  73263. const int x1 = rect.x;
  73264. const int y1 = rect.y;
  73265. const int x2 = x1 + rect.w;
  73266. const int y2 = y1 + rect.h;
  73267. for (int i = getNumRectangles(); --i >= 0;)
  73268. {
  73269. Rectangle<int>& r = rects.getReference (i);
  73270. const int rx1 = r.x;
  73271. const int ry1 = r.y;
  73272. const int rx2 = rx1 + r.w;
  73273. const int ry2 = ry1 + r.h;
  73274. if (! (x2 <= rx1 || x1 >= rx2 || y2 <= ry1 || y1 >= ry2))
  73275. {
  73276. if (x1 > rx1 && x1 < rx2)
  73277. {
  73278. if (y1 <= ry1 && y2 >= ry2 && x2 >= rx2)
  73279. {
  73280. r.w = x1 - rx1;
  73281. }
  73282. else
  73283. {
  73284. r.x = x1;
  73285. r.w = rx2 - x1;
  73286. rects.insert (i + 1, Rectangle<int> (rx1, ry1, x1 - rx1, ry2 - ry1));
  73287. i += 2;
  73288. }
  73289. }
  73290. else if (x2 > rx1 && x2 < rx2)
  73291. {
  73292. r.x = x2;
  73293. r.w = rx2 - x2;
  73294. if (y1 > ry1 || y2 < ry2 || x1 > rx1)
  73295. {
  73296. rects.insert (i + 1, Rectangle<int> (rx1, ry1, x2 - rx1, ry2 - ry1));
  73297. i += 2;
  73298. }
  73299. }
  73300. else if (y1 > ry1 && y1 < ry2)
  73301. {
  73302. if (x1 <= rx1 && x2 >= rx2 && y2 >= ry2)
  73303. {
  73304. r.h = y1 - ry1;
  73305. }
  73306. else
  73307. {
  73308. r.y = y1;
  73309. r.h = ry2 - y1;
  73310. rects.insert (i + 1, Rectangle<int> (rx1, ry1, rx2 - rx1, y1 - ry1));
  73311. i += 2;
  73312. }
  73313. }
  73314. else if (y2 > ry1 && y2 < ry2)
  73315. {
  73316. r.y = y2;
  73317. r.h = ry2 - y2;
  73318. if (x1 > rx1 || x2 < rx2 || y1 > ry1)
  73319. {
  73320. rects.insert (i + 1, Rectangle<int> (rx1, ry1, rx2 - rx1, y2 - ry1));
  73321. i += 2;
  73322. }
  73323. }
  73324. else
  73325. {
  73326. rects.remove (i);
  73327. }
  73328. }
  73329. }
  73330. if (rects.size() > originalNumRects + 10)
  73331. consolidate();
  73332. }
  73333. }
  73334. void RectangleList::subtract (const RectangleList& otherList) throw()
  73335. {
  73336. for (int i = otherList.rects.size(); --i >= 0;)
  73337. subtract (otherList.rects.getReference (i));
  73338. }
  73339. bool RectangleList::clipTo (const Rectangle<int>& rect) throw()
  73340. {
  73341. bool notEmpty = false;
  73342. if (rect.isEmpty())
  73343. {
  73344. clear();
  73345. }
  73346. else
  73347. {
  73348. for (int i = rects.size(); --i >= 0;)
  73349. {
  73350. Rectangle<int>& r = rects.getReference (i);
  73351. if (! rect.intersectRectangle (r.x, r.y, r.w, r.h))
  73352. rects.remove (i);
  73353. else
  73354. notEmpty = true;
  73355. }
  73356. }
  73357. return notEmpty;
  73358. }
  73359. bool RectangleList::clipTo (const RectangleList& other) throw()
  73360. {
  73361. if (rects.size() == 0)
  73362. return false;
  73363. RectangleList result;
  73364. for (int j = 0; j < rects.size(); ++j)
  73365. {
  73366. const Rectangle<int>& rect = rects.getReference (j);
  73367. for (int i = other.rects.size(); --i >= 0;)
  73368. {
  73369. Rectangle<int> r (other.rects.getReference (i));
  73370. if (rect.intersectRectangle (r.x, r.y, r.w, r.h))
  73371. result.rects.add (r);
  73372. }
  73373. }
  73374. swapWith (result);
  73375. return ! isEmpty();
  73376. }
  73377. bool RectangleList::getIntersectionWith (const Rectangle<int>& rect, RectangleList& destRegion) const throw()
  73378. {
  73379. destRegion.clear();
  73380. if (! rect.isEmpty())
  73381. {
  73382. for (int i = rects.size(); --i >= 0;)
  73383. {
  73384. Rectangle<int> r (rects.getReference (i));
  73385. if (rect.intersectRectangle (r.x, r.y, r.w, r.h))
  73386. destRegion.rects.add (r);
  73387. }
  73388. }
  73389. return destRegion.rects.size() > 0;
  73390. }
  73391. void RectangleList::swapWith (RectangleList& otherList) throw()
  73392. {
  73393. rects.swapWithArray (otherList.rects);
  73394. }
  73395. void RectangleList::consolidate() throw()
  73396. {
  73397. int i;
  73398. for (i = 0; i < getNumRectangles() - 1; ++i)
  73399. {
  73400. Rectangle<int>& r = rects.getReference (i);
  73401. const int rx1 = r.x;
  73402. const int ry1 = r.y;
  73403. const int rx2 = rx1 + r.w;
  73404. const int ry2 = ry1 + r.h;
  73405. for (int j = rects.size(); --j > i;)
  73406. {
  73407. Rectangle<int>& r2 = rects.getReference (j);
  73408. const int jrx1 = r2.x;
  73409. const int jry1 = r2.y;
  73410. const int jrx2 = jrx1 + r2.w;
  73411. const int jry2 = jry1 + r2.h;
  73412. // if the vertical edges of any blocks are touching and their horizontals don't
  73413. // line up, split them horizontally..
  73414. if (jrx1 == rx2 || jrx2 == rx1)
  73415. {
  73416. if (jry1 > ry1 && jry1 < ry2)
  73417. {
  73418. r.h = jry1 - ry1;
  73419. rects.add (Rectangle<int> (rx1, jry1, rx2 - rx1, ry2 - jry1));
  73420. i = -1;
  73421. break;
  73422. }
  73423. if (jry2 > ry1 && jry2 < ry2)
  73424. {
  73425. r.h = jry2 - ry1;
  73426. rects.add (Rectangle<int> (rx1, jry2, rx2 - rx1, ry2 - jry2));
  73427. i = -1;
  73428. break;
  73429. }
  73430. else if (ry1 > jry1 && ry1 < jry2)
  73431. {
  73432. r2.h = ry1 - jry1;
  73433. rects.add (Rectangle<int> (jrx1, ry1, jrx2 - jrx1, jry2 - ry1));
  73434. i = -1;
  73435. break;
  73436. }
  73437. else if (ry2 > jry1 && ry2 < jry2)
  73438. {
  73439. r2.h = ry2 - jry1;
  73440. rects.add (Rectangle<int> (jrx1, ry2, jrx2 - jrx1, jry2 - ry2));
  73441. i = -1;
  73442. break;
  73443. }
  73444. }
  73445. }
  73446. }
  73447. for (i = 0; i < rects.size() - 1; ++i)
  73448. {
  73449. Rectangle<int>& r = rects.getReference (i);
  73450. for (int j = rects.size(); --j > i;)
  73451. {
  73452. if (r.enlargeIfAdjacent (rects.getReference (j)))
  73453. {
  73454. rects.remove (j);
  73455. i = -1;
  73456. break;
  73457. }
  73458. }
  73459. }
  73460. }
  73461. bool RectangleList::containsPoint (const int x, const int y) const throw()
  73462. {
  73463. for (int i = getNumRectangles(); --i >= 0;)
  73464. if (rects.getReference (i).contains (x, y))
  73465. return true;
  73466. return false;
  73467. }
  73468. bool RectangleList::containsRectangle (const Rectangle<int>& rectangleToCheck) const throw()
  73469. {
  73470. if (rects.size() > 1)
  73471. {
  73472. RectangleList r (rectangleToCheck);
  73473. for (int i = rects.size(); --i >= 0;)
  73474. {
  73475. r.subtract (rects.getReference (i));
  73476. if (r.rects.size() == 0)
  73477. return true;
  73478. }
  73479. }
  73480. else if (rects.size() > 0)
  73481. {
  73482. return rects.getReference (0).contains (rectangleToCheck);
  73483. }
  73484. return false;
  73485. }
  73486. bool RectangleList::intersectsRectangle (const Rectangle<int>& rectangleToCheck) const throw()
  73487. {
  73488. for (int i = rects.size(); --i >= 0;)
  73489. if (rects.getReference (i).intersects (rectangleToCheck))
  73490. return true;
  73491. return false;
  73492. }
  73493. bool RectangleList::intersects (const RectangleList& other) const throw()
  73494. {
  73495. for (int i = rects.size(); --i >= 0;)
  73496. if (other.intersectsRectangle (rects.getReference (i)))
  73497. return true;
  73498. return false;
  73499. }
  73500. const Rectangle<int> RectangleList::getBounds() const throw()
  73501. {
  73502. if (rects.size() <= 1)
  73503. {
  73504. if (rects.size() == 0)
  73505. return Rectangle<int>();
  73506. else
  73507. return rects.getReference (0);
  73508. }
  73509. else
  73510. {
  73511. const Rectangle<int>& r = rects.getReference (0);
  73512. int minX = r.x;
  73513. int minY = r.y;
  73514. int maxX = minX + r.w;
  73515. int maxY = minY + r.h;
  73516. for (int i = rects.size(); --i > 0;)
  73517. {
  73518. const Rectangle<int>& r2 = rects.getReference (i);
  73519. minX = jmin (minX, r2.x);
  73520. minY = jmin (minY, r2.y);
  73521. maxX = jmax (maxX, r2.getRight());
  73522. maxY = jmax (maxY, r2.getBottom());
  73523. }
  73524. return Rectangle<int> (minX, minY, maxX - minX, maxY - minY);
  73525. }
  73526. }
  73527. void RectangleList::offsetAll (const int dx, const int dy) throw()
  73528. {
  73529. for (int i = rects.size(); --i >= 0;)
  73530. {
  73531. Rectangle<int>& r = rects.getReference (i);
  73532. r.x += dx;
  73533. r.y += dy;
  73534. }
  73535. }
  73536. const Path RectangleList::toPath() const throw()
  73537. {
  73538. Path p;
  73539. for (int i = rects.size(); --i >= 0;)
  73540. {
  73541. const Rectangle<int>& r = rects.getReference (i);
  73542. p.addRectangle ((float) r.x,
  73543. (float) r.y,
  73544. (float) r.w,
  73545. (float) r.h);
  73546. }
  73547. return p;
  73548. }
  73549. END_JUCE_NAMESPACE
  73550. /*** End of inlined file: juce_RectangleList.cpp ***/
  73551. /*** Start of inlined file: juce_Image.cpp ***/
  73552. BEGIN_JUCE_NAMESPACE
  73553. static const int fullAlphaThreshold = 253;
  73554. Image::Image (const PixelFormat format_,
  73555. const int imageWidth_,
  73556. const int imageHeight_)
  73557. : format (format_),
  73558. imageWidth (imageWidth_),
  73559. imageHeight (imageHeight_),
  73560. imageData (0)
  73561. {
  73562. jassert (format_ == RGB || format_ == ARGB || format_ == SingleChannel);
  73563. jassert (imageWidth_ > 0 && imageHeight_ > 0); // it's illegal to create a zero-sized image - the
  73564. // actual image will be at least 1x1.
  73565. }
  73566. Image::Image (const PixelFormat format_,
  73567. const int imageWidth_,
  73568. const int imageHeight_,
  73569. const bool clearImage)
  73570. : format (format_),
  73571. imageWidth (imageWidth_),
  73572. imageHeight (imageHeight_)
  73573. {
  73574. jassert (format_ == RGB || format_ == ARGB || format_ == SingleChannel);
  73575. jassert (imageWidth_ > 0 && imageHeight_ > 0); // it's illegal to create a zero-sized image - the
  73576. // actual image will be at least 1x1.
  73577. pixelStride = (format == RGB) ? 3 : ((format == ARGB) ? 4 : 1);
  73578. lineStride = (pixelStride * jmax (1, imageWidth_) + 3) & ~3;
  73579. imageDataAllocated.allocate (lineStride * jmax (1, imageHeight_), clearImage);
  73580. imageData = imageDataAllocated;
  73581. }
  73582. Image::Image (const Image& other)
  73583. : format (other.format),
  73584. imageWidth (other.imageWidth),
  73585. imageHeight (other.imageHeight)
  73586. {
  73587. pixelStride = (format == RGB) ? 3 : ((format == ARGB) ? 4 : 1);
  73588. lineStride = (pixelStride * jmax (1, imageWidth) + 3) & ~3;
  73589. imageDataAllocated.malloc (lineStride * jmax (1, imageHeight));
  73590. imageData = imageDataAllocated;
  73591. BitmapData srcData (other, 0, 0, imageWidth, imageHeight);
  73592. setPixelData (0, 0, imageWidth, imageHeight, srcData.data, srcData.lineStride);
  73593. }
  73594. Image::~Image()
  73595. {
  73596. }
  73597. LowLevelGraphicsContext* Image::createLowLevelContext()
  73598. {
  73599. return new LowLevelGraphicsSoftwareRenderer (*this);
  73600. }
  73601. Image::BitmapData::BitmapData (Image& image, int x, int y, int w, int h, const bool /*makeWritable*/)
  73602. : data (image.imageData + image.lineStride * y + image.pixelStride * x),
  73603. lineStride (image.lineStride),
  73604. pixelStride (image.pixelStride),
  73605. width (w),
  73606. height (h)
  73607. {
  73608. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= image.getWidth() && y + h <= image.getHeight());
  73609. }
  73610. Image::BitmapData::BitmapData (const Image& image, int x, int y, int w, int h)
  73611. : data (image.imageData + image.lineStride * y + image.pixelStride * x),
  73612. lineStride (image.lineStride),
  73613. pixelStride (image.pixelStride),
  73614. width (w),
  73615. height (h)
  73616. {
  73617. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= image.getWidth() && y + h <= image.getHeight());
  73618. }
  73619. Image::BitmapData::~BitmapData()
  73620. {
  73621. }
  73622. void Image::setPixelData (int x, int y, int w, int h,
  73623. const uint8* sourcePixelData, int sourceLineStride)
  73624. {
  73625. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= imageWidth && y + h <= imageHeight);
  73626. if (Rectangle<int>::intersectRectangles (x, y, w, h, 0, 0, imageWidth, imageHeight))
  73627. {
  73628. const BitmapData dest (*this, x, y, w, h, true);
  73629. for (int i = 0; i < h; ++i)
  73630. {
  73631. memcpy (dest.getLinePointer(i),
  73632. sourcePixelData + sourceLineStride * i,
  73633. w * dest.pixelStride);
  73634. }
  73635. }
  73636. }
  73637. void Image::clear (int dx, int dy, int dw, int dh,
  73638. const Colour& colourToClearTo)
  73639. {
  73640. const PixelARGB col (colourToClearTo.getPixelARGB());
  73641. const BitmapData destData (*this, dx, dy, dw, dh, true);
  73642. uint8* dest = destData.data;
  73643. while (--dh >= 0)
  73644. {
  73645. uint8* line = dest;
  73646. dest += destData.lineStride;
  73647. if (isARGB())
  73648. {
  73649. for (int x = dw; --x >= 0;)
  73650. {
  73651. ((PixelARGB*) line)->set (col);
  73652. line += destData.pixelStride;
  73653. }
  73654. }
  73655. else if (isRGB())
  73656. {
  73657. for (int x = dw; --x >= 0;)
  73658. {
  73659. ((PixelRGB*) line)->set (col);
  73660. line += destData.pixelStride;
  73661. }
  73662. }
  73663. else
  73664. {
  73665. for (int x = dw; --x >= 0;)
  73666. {
  73667. *line = col.getAlpha();
  73668. line += destData.pixelStride;
  73669. }
  73670. }
  73671. }
  73672. }
  73673. Image* Image::createCopy (int newWidth, int newHeight,
  73674. const Graphics::ResamplingQuality quality) const
  73675. {
  73676. if (newWidth < 0)
  73677. newWidth = imageWidth;
  73678. if (newHeight < 0)
  73679. newHeight = imageHeight;
  73680. Image* const newImage = Image::createNativeImage (format, newWidth, newHeight, true);
  73681. Graphics g (*newImage);
  73682. g.setImageResamplingQuality (quality);
  73683. g.drawImage (this,
  73684. 0, 0, newWidth, newHeight,
  73685. 0, 0, imageWidth, imageHeight,
  73686. false);
  73687. return newImage;
  73688. }
  73689. Image* Image::createCopyOfAlphaChannel() const
  73690. {
  73691. jassert (format != SingleChannel);
  73692. Image* const newImage = Image::createNativeImage (SingleChannel, imageWidth, imageHeight, false);
  73693. if (! hasAlphaChannel())
  73694. {
  73695. newImage->clear (0, 0, imageWidth, imageHeight, Colours::black);
  73696. }
  73697. else
  73698. {
  73699. const BitmapData destData (*newImage, 0, 0, imageWidth, imageHeight, true);
  73700. const BitmapData srcData (*this, 0, 0, imageWidth, imageHeight);
  73701. for (int y = 0; y < imageHeight; ++y)
  73702. {
  73703. const PixelARGB* src = (const PixelARGB*) srcData.getLinePointer(y);
  73704. uint8* dst = destData.getLinePointer (y);
  73705. for (int x = imageWidth; --x >= 0;)
  73706. {
  73707. *dst++ = src->getAlpha();
  73708. ++src;
  73709. }
  73710. }
  73711. }
  73712. return newImage;
  73713. }
  73714. const Colour Image::getPixelAt (const int x, const int y) const
  73715. {
  73716. Colour c;
  73717. if (((unsigned int) x) < (unsigned int) imageWidth
  73718. && ((unsigned int) y) < (unsigned int) imageHeight)
  73719. {
  73720. const BitmapData srcData (*this, x, y, 1, 1);
  73721. if (isARGB())
  73722. {
  73723. PixelARGB p (*(const PixelARGB*) srcData.data);
  73724. p.unpremultiply();
  73725. c = Colour (p.getARGB());
  73726. }
  73727. else if (isRGB())
  73728. c = Colour (((const PixelRGB*) srcData.data)->getARGB());
  73729. else
  73730. c = Colour ((uint8) 0, (uint8) 0, (uint8) 0, *(srcData.data));
  73731. }
  73732. return c;
  73733. }
  73734. void Image::setPixelAt (const int x, const int y,
  73735. const Colour& colour)
  73736. {
  73737. if (((unsigned int) x) < (unsigned int) imageWidth
  73738. && ((unsigned int) y) < (unsigned int) imageHeight)
  73739. {
  73740. const BitmapData destData (*this, x, y, 1, 1, true);
  73741. const PixelARGB col (colour.getPixelARGB());
  73742. if (isARGB())
  73743. ((PixelARGB*) destData.data)->set (col);
  73744. else if (isRGB())
  73745. ((PixelRGB*) destData.data)->set (col);
  73746. else
  73747. *(destData.data) = col.getAlpha();
  73748. }
  73749. }
  73750. void Image::multiplyAlphaAt (const int x, const int y,
  73751. const float multiplier)
  73752. {
  73753. if (((unsigned int) x) < (unsigned int) imageWidth
  73754. && ((unsigned int) y) < (unsigned int) imageHeight
  73755. && hasAlphaChannel())
  73756. {
  73757. const BitmapData destData (*this, x, y, 1, 1, true);
  73758. if (isARGB())
  73759. ((PixelARGB*) destData.data)->multiplyAlpha (multiplier);
  73760. else
  73761. *(destData.data) = (uint8) (*(destData.data) * multiplier);
  73762. }
  73763. }
  73764. void Image::multiplyAllAlphas (const float amountToMultiplyBy)
  73765. {
  73766. if (hasAlphaChannel())
  73767. {
  73768. const BitmapData destData (*this, 0, 0, getWidth(), getHeight(), true);
  73769. if (isARGB())
  73770. {
  73771. for (int y = 0; y < imageHeight; ++y)
  73772. {
  73773. uint8* p = destData.getLinePointer (y);
  73774. for (int x = 0; x < imageWidth; ++x)
  73775. {
  73776. ((PixelARGB*) p)->multiplyAlpha (amountToMultiplyBy);
  73777. p += destData.pixelStride;
  73778. }
  73779. }
  73780. }
  73781. else
  73782. {
  73783. for (int y = 0; y < imageHeight; ++y)
  73784. {
  73785. uint8* p = destData.getLinePointer (y);
  73786. for (int x = 0; x < imageWidth; ++x)
  73787. {
  73788. *p = (uint8) (*p * amountToMultiplyBy);
  73789. p += destData.pixelStride;
  73790. }
  73791. }
  73792. }
  73793. }
  73794. else
  73795. {
  73796. jassertfalse // can't do this without an alpha-channel!
  73797. }
  73798. }
  73799. void Image::desaturate()
  73800. {
  73801. if (isARGB() || isRGB())
  73802. {
  73803. const BitmapData destData (*this, 0, 0, getWidth(), getHeight(), true);
  73804. if (isARGB())
  73805. {
  73806. for (int y = 0; y < imageHeight; ++y)
  73807. {
  73808. uint8* p = destData.getLinePointer (y);
  73809. for (int x = 0; x < imageWidth; ++x)
  73810. {
  73811. ((PixelARGB*) p)->desaturate();
  73812. p += destData.pixelStride;
  73813. }
  73814. }
  73815. }
  73816. else
  73817. {
  73818. for (int y = 0; y < imageHeight; ++y)
  73819. {
  73820. uint8* p = destData.getLinePointer (y);
  73821. for (int x = 0; x < imageWidth; ++x)
  73822. {
  73823. ((PixelRGB*) p)->desaturate();
  73824. p += destData.pixelStride;
  73825. }
  73826. }
  73827. }
  73828. }
  73829. }
  73830. void Image::createSolidAreaMask (RectangleList& result, const float alphaThreshold) const
  73831. {
  73832. if (hasAlphaChannel())
  73833. {
  73834. const uint8 threshold = (uint8) jlimit (0, 255, roundToInt (alphaThreshold * 255.0f));
  73835. SparseSet <int> pixelsOnRow;
  73836. const BitmapData srcData (*this, 0, 0, getWidth(), getHeight());
  73837. for (int y = 0; y < imageHeight; ++y)
  73838. {
  73839. pixelsOnRow.clear();
  73840. const uint8* lineData = srcData.getLinePointer (y);
  73841. if (isARGB())
  73842. {
  73843. for (int x = 0; x < imageWidth; ++x)
  73844. {
  73845. if (((const PixelARGB*) lineData)->getAlpha() >= threshold)
  73846. pixelsOnRow.addRange (x, 1);
  73847. lineData += srcData.pixelStride;
  73848. }
  73849. }
  73850. else
  73851. {
  73852. for (int x = 0; x < imageWidth; ++x)
  73853. {
  73854. if (*lineData >= threshold)
  73855. pixelsOnRow.addRange (x, 1);
  73856. lineData += srcData.pixelStride;
  73857. }
  73858. }
  73859. for (int i = 0; i < pixelsOnRow.getNumRanges(); ++i)
  73860. {
  73861. int x, w;
  73862. if (pixelsOnRow.getRange (i, x, w))
  73863. result.add (Rectangle<int> (x, y, w, 1));
  73864. }
  73865. result.consolidate();
  73866. }
  73867. }
  73868. else
  73869. {
  73870. result.add (0, 0, imageWidth, imageHeight);
  73871. }
  73872. }
  73873. void Image::moveImageSection (int dx, int dy,
  73874. int sx, int sy,
  73875. int w, int h)
  73876. {
  73877. if (dx < 0)
  73878. {
  73879. w += dx;
  73880. sx -= dx;
  73881. dx = 0;
  73882. }
  73883. if (dy < 0)
  73884. {
  73885. h += dy;
  73886. sy -= dy;
  73887. dy = 0;
  73888. }
  73889. if (sx < 0)
  73890. {
  73891. w += sx;
  73892. dx -= sx;
  73893. sx = 0;
  73894. }
  73895. if (sy < 0)
  73896. {
  73897. h += sy;
  73898. dy -= sy;
  73899. sy = 0;
  73900. }
  73901. const int minX = jmin (dx, sx);
  73902. const int minY = jmin (dy, sy);
  73903. w = jmin (w, getWidth() - jmax (sx, dx));
  73904. h = jmin (h, getHeight() - jmax (sy, dy));
  73905. if (w > 0 && h > 0)
  73906. {
  73907. const int maxX = jmax (dx, sx) + w;
  73908. const int maxY = jmax (dy, sy) + h;
  73909. const BitmapData destData (*this, minX, minY, maxX - minX, maxY - minY, true);
  73910. uint8* dst = destData.getPixelPointer (dx - minX, dy - minY);
  73911. const uint8* src = destData.getPixelPointer (sx - minX, sy - minY);
  73912. const int lineSize = destData.pixelStride * w;
  73913. if (dy > sy)
  73914. {
  73915. while (--h >= 0)
  73916. {
  73917. const int offset = h * destData.lineStride;
  73918. memmove (dst + offset, src + offset, lineSize);
  73919. }
  73920. }
  73921. else if (dst != src)
  73922. {
  73923. while (--h >= 0)
  73924. {
  73925. memmove (dst, src, lineSize);
  73926. dst += destData.lineStride;
  73927. src += destData.lineStride;
  73928. }
  73929. }
  73930. }
  73931. }
  73932. END_JUCE_NAMESPACE
  73933. /*** End of inlined file: juce_Image.cpp ***/
  73934. /*** Start of inlined file: juce_ImageCache.cpp ***/
  73935. BEGIN_JUCE_NAMESPACE
  73936. struct ImageCacheItem
  73937. {
  73938. ScopedPointer <Image> image;
  73939. int64 hashCode;
  73940. int refCount;
  73941. uint32 releaseTime;
  73942. juce_UseDebuggingNewOperator
  73943. };
  73944. static ImageCache* instance = 0;
  73945. static int cacheTimeout = 5000;
  73946. ImageCache::ImageCache()
  73947. {
  73948. }
  73949. ImageCache::~ImageCache()
  73950. {
  73951. jassert (instance == this);
  73952. instance = 0;
  73953. }
  73954. Image* ImageCache::getFromHashCode (const int64 hashCode)
  73955. {
  73956. if (instance != 0)
  73957. {
  73958. const ScopedLock sl (instance->lock);
  73959. for (int i = instance->images.size(); --i >= 0;)
  73960. {
  73961. ImageCacheItem* const ci = instance->images.getUnchecked(i);
  73962. if (ci->hashCode == hashCode)
  73963. {
  73964. ci->refCount++;
  73965. return ci->image;
  73966. }
  73967. }
  73968. }
  73969. return 0;
  73970. }
  73971. void ImageCache::addImageToCache (Image* const image,
  73972. const int64 hashCode)
  73973. {
  73974. if (image != 0)
  73975. {
  73976. if (instance == 0)
  73977. instance = new ImageCache();
  73978. ImageCacheItem* const newC = new ImageCacheItem();
  73979. newC->hashCode = hashCode;
  73980. newC->image = image;
  73981. newC->refCount = 1;
  73982. newC->releaseTime = 0;
  73983. const ScopedLock sl (instance->lock);
  73984. instance->images.add (newC);
  73985. }
  73986. }
  73987. void ImageCache::release (Image* const imageToRelease)
  73988. {
  73989. if (imageToRelease != 0 && instance != 0)
  73990. {
  73991. const ScopedLock sl (instance->lock);
  73992. for (int i = instance->images.size(); --i >= 0;)
  73993. {
  73994. ImageCacheItem* const ci = instance->images.getUnchecked(i);
  73995. if ((Image*) ci->image == imageToRelease)
  73996. {
  73997. if (--(ci->refCount) == 0)
  73998. ci->releaseTime = Time::getApproximateMillisecondCounter();
  73999. if (! instance->isTimerRunning())
  74000. instance->startTimer (999);
  74001. break;
  74002. }
  74003. }
  74004. }
  74005. }
  74006. void ImageCache::releaseOrDelete (Image* const imageToRelease)
  74007. {
  74008. if (isImageInCache (imageToRelease))
  74009. release (imageToRelease);
  74010. else
  74011. delete imageToRelease;
  74012. }
  74013. bool ImageCache::isImageInCache (Image* const imageToLookFor)
  74014. {
  74015. if (instance != 0)
  74016. {
  74017. const ScopedLock sl (instance->lock);
  74018. for (int i = instance->images.size(); --i >= 0;)
  74019. if ((Image*) instance->images.getUnchecked(i)->image == imageToLookFor)
  74020. return true;
  74021. }
  74022. return false;
  74023. }
  74024. void ImageCache::incReferenceCount (Image* const image)
  74025. {
  74026. if (instance != 0)
  74027. {
  74028. const ScopedLock sl (instance->lock);
  74029. for (int i = instance->images.size(); --i >= 0;)
  74030. {
  74031. ImageCacheItem* const ci = (ImageCacheItem*) instance->images.getUnchecked(i);
  74032. if ((Image*) ci->image == image)
  74033. {
  74034. ci->refCount++;
  74035. return;
  74036. }
  74037. }
  74038. }
  74039. jassertfalse // (trying to inc the ref count of an image that's not in the cache)
  74040. }
  74041. void ImageCache::timerCallback()
  74042. {
  74043. int numberStillNeedingReleasing = 0;
  74044. const unsigned int now = Time::getApproximateMillisecondCounter();
  74045. const ScopedLock sl (lock);
  74046. for (int i = images.size(); --i >= 0;)
  74047. {
  74048. ImageCacheItem* const ci = images.getUnchecked(i);
  74049. if (ci->refCount <= 0)
  74050. {
  74051. if (now > ci->releaseTime + cacheTimeout
  74052. || now < ci->releaseTime - 1000)
  74053. {
  74054. images.remove (i);
  74055. }
  74056. else
  74057. {
  74058. ++numberStillNeedingReleasing;
  74059. }
  74060. }
  74061. }
  74062. if (numberStillNeedingReleasing == 0)
  74063. stopTimer();
  74064. }
  74065. Image* ImageCache::getFromFile (const File& file)
  74066. {
  74067. const int64 hashCode = file.hashCode64();
  74068. Image* image = getFromHashCode (hashCode);
  74069. if (image == 0)
  74070. {
  74071. image = ImageFileFormat::loadFrom (file);
  74072. addImageToCache (image, hashCode);
  74073. }
  74074. return image;
  74075. }
  74076. Image* ImageCache::getFromMemory (const void* imageData,
  74077. const int dataSize)
  74078. {
  74079. const int64 hashCode = (int64) (pointer_sized_int) imageData;
  74080. Image* image = getFromHashCode (hashCode);
  74081. if (image == 0)
  74082. {
  74083. image = ImageFileFormat::loadFrom (imageData, dataSize);
  74084. addImageToCache (image, hashCode);
  74085. }
  74086. return image;
  74087. }
  74088. void ImageCache::setCacheTimeout (const int millisecs)
  74089. {
  74090. cacheTimeout = millisecs;
  74091. }
  74092. END_JUCE_NAMESPACE
  74093. /*** End of inlined file: juce_ImageCache.cpp ***/
  74094. /*** Start of inlined file: juce_ImageConvolutionKernel.cpp ***/
  74095. BEGIN_JUCE_NAMESPACE
  74096. ImageConvolutionKernel::ImageConvolutionKernel (const int size_)
  74097. : values (size_ * size_),
  74098. size (size_)
  74099. {
  74100. clear();
  74101. }
  74102. ImageConvolutionKernel::~ImageConvolutionKernel()
  74103. {
  74104. }
  74105. float ImageConvolutionKernel::getKernelValue (const int x, const int y) const throw()
  74106. {
  74107. if (((unsigned int) x) < (unsigned int) size
  74108. && ((unsigned int) y) < (unsigned int) size)
  74109. {
  74110. return values [x + y * size];
  74111. }
  74112. else
  74113. {
  74114. jassertfalse;
  74115. return 0;
  74116. }
  74117. }
  74118. void ImageConvolutionKernel::setKernelValue (const int x, const int y, const float value) throw()
  74119. {
  74120. if (((unsigned int) x) < (unsigned int) size
  74121. && ((unsigned int) y) < (unsigned int) size)
  74122. {
  74123. values [x + y * size] = value;
  74124. }
  74125. else
  74126. {
  74127. jassertfalse;
  74128. }
  74129. }
  74130. void ImageConvolutionKernel::clear()
  74131. {
  74132. for (int i = size * size; --i >= 0;)
  74133. values[i] = 0;
  74134. }
  74135. void ImageConvolutionKernel::setOverallSum (const float desiredTotalSum)
  74136. {
  74137. double currentTotal = 0.0;
  74138. for (int i = size * size; --i >= 0;)
  74139. currentTotal += values[i];
  74140. rescaleAllValues ((float) (desiredTotalSum / currentTotal));
  74141. }
  74142. void ImageConvolutionKernel::rescaleAllValues (const float multiplier)
  74143. {
  74144. for (int i = size * size; --i >= 0;)
  74145. values[i] *= multiplier;
  74146. }
  74147. void ImageConvolutionKernel::createGaussianBlur (const float radius)
  74148. {
  74149. const double radiusFactor = -1.0 / (radius * radius * 2);
  74150. const int centre = size >> 1;
  74151. for (int y = size; --y >= 0;)
  74152. {
  74153. for (int x = size; --x >= 0;)
  74154. {
  74155. const int cx = x - centre;
  74156. const int cy = y - centre;
  74157. values [x + y * size] = (float) exp (radiusFactor * (cx * cx + cy * cy));
  74158. }
  74159. }
  74160. setOverallSum (1.0f);
  74161. }
  74162. void ImageConvolutionKernel::applyToImage (Image& destImage,
  74163. const Image* sourceImage,
  74164. int dx,
  74165. int dy,
  74166. int dw,
  74167. int dh) const
  74168. {
  74169. ScopedPointer <Image> imageCreated;
  74170. if (sourceImage == 0)
  74171. {
  74172. sourceImage = imageCreated = destImage.createCopy();
  74173. }
  74174. else
  74175. {
  74176. jassert (sourceImage->getWidth() == destImage.getWidth()
  74177. && sourceImage->getHeight() == destImage.getHeight()
  74178. && sourceImage->getFormat() == destImage.getFormat());
  74179. if (sourceImage->getWidth() != destImage.getWidth()
  74180. || sourceImage->getHeight() != destImage.getHeight()
  74181. || sourceImage->getFormat() != destImage.getFormat())
  74182. return;
  74183. }
  74184. const int imageWidth = destImage.getWidth();
  74185. const int imageHeight = destImage.getHeight();
  74186. if (dx >= imageWidth || dy >= imageHeight)
  74187. return;
  74188. if (dx + dw > imageWidth)
  74189. dw = imageWidth - dx;
  74190. if (dy + dh > imageHeight)
  74191. dh = imageHeight - dy;
  74192. const int dx2 = dx + dw;
  74193. const int dy2 = dy + dh;
  74194. const Image::BitmapData destData (destImage, dx, dy, dw, dh, true);
  74195. uint8* line = destData.data;
  74196. const Image::BitmapData srcData (*sourceImage, 0, 0, sourceImage->getWidth(), sourceImage->getHeight());
  74197. if (destData.pixelStride == 4)
  74198. {
  74199. for (int y = dy; y < dy2; ++y)
  74200. {
  74201. uint8* dest = line;
  74202. line += destData.lineStride;
  74203. for (int x = dx; x < dx2; ++x)
  74204. {
  74205. float c1 = 0;
  74206. float c2 = 0;
  74207. float c3 = 0;
  74208. float c4 = 0;
  74209. for (int yy = 0; yy < size; ++yy)
  74210. {
  74211. const int sy = y + yy - (size >> 1);
  74212. if (sy >= imageHeight)
  74213. break;
  74214. if (sy >= 0)
  74215. {
  74216. int sx = x - (size >> 1);
  74217. const uint8* src = srcData.getPixelPointer (sx, sy);
  74218. for (int xx = 0; xx < size; ++xx)
  74219. {
  74220. if (sx >= imageWidth)
  74221. break;
  74222. if (sx >= 0)
  74223. {
  74224. const float kernelMult = values [xx + yy * size];
  74225. c1 += kernelMult * *src++;
  74226. c2 += kernelMult * *src++;
  74227. c3 += kernelMult * *src++;
  74228. c4 += kernelMult * *src++;
  74229. }
  74230. else
  74231. {
  74232. src += 4;
  74233. }
  74234. ++sx;
  74235. }
  74236. }
  74237. }
  74238. *dest++ = (uint8) jmin (0xff, roundToInt (c1));
  74239. *dest++ = (uint8) jmin (0xff, roundToInt (c2));
  74240. *dest++ = (uint8) jmin (0xff, roundToInt (c3));
  74241. *dest++ = (uint8) jmin (0xff, roundToInt (c4));
  74242. }
  74243. }
  74244. }
  74245. else if (destData.pixelStride == 3)
  74246. {
  74247. for (int y = dy; y < dy2; ++y)
  74248. {
  74249. uint8* dest = line;
  74250. line += destData.lineStride;
  74251. for (int x = dx; x < dx2; ++x)
  74252. {
  74253. float c1 = 0;
  74254. float c2 = 0;
  74255. float c3 = 0;
  74256. for (int yy = 0; yy < size; ++yy)
  74257. {
  74258. const int sy = y + yy - (size >> 1);
  74259. if (sy >= imageHeight)
  74260. break;
  74261. if (sy >= 0)
  74262. {
  74263. int sx = x - (size >> 1);
  74264. const uint8* src = srcData.getPixelPointer (sx, sy);
  74265. for (int xx = 0; xx < size; ++xx)
  74266. {
  74267. if (sx >= imageWidth)
  74268. break;
  74269. if (sx >= 0)
  74270. {
  74271. const float kernelMult = values [xx + yy * size];
  74272. c1 += kernelMult * *src++;
  74273. c2 += kernelMult * *src++;
  74274. c3 += kernelMult * *src++;
  74275. }
  74276. else
  74277. {
  74278. src += 3;
  74279. }
  74280. ++sx;
  74281. }
  74282. }
  74283. }
  74284. *dest++ = (uint8) roundToInt (c1);
  74285. *dest++ = (uint8) roundToInt (c2);
  74286. *dest++ = (uint8) roundToInt (c3);
  74287. }
  74288. }
  74289. }
  74290. }
  74291. END_JUCE_NAMESPACE
  74292. /*** End of inlined file: juce_ImageConvolutionKernel.cpp ***/
  74293. /*** Start of inlined file: juce_ImageFileFormat.cpp ***/
  74294. BEGIN_JUCE_NAMESPACE
  74295. /*** Start of inlined file: juce_GIFLoader.h ***/
  74296. #ifndef __JUCE_GIFLOADER_JUCEHEADER__
  74297. #define __JUCE_GIFLOADER_JUCEHEADER__
  74298. #ifndef DOXYGEN
  74299. class GIFLoader
  74300. {
  74301. public:
  74302. GIFLoader (InputStream& in);
  74303. ~GIFLoader();
  74304. Image* getImage() const { return image; }
  74305. private:
  74306. Image* image;
  74307. InputStream& input;
  74308. uint8 buffer [300];
  74309. uint8 palette [256][4];
  74310. bool dataBlockIsZero, fresh, finished;
  74311. int currentBit, lastBit, lastByteIndex;
  74312. int codeSize, setCodeSize;
  74313. int maxCode, maxCodeSize;
  74314. int firstcode, oldcode;
  74315. int clearCode, end_code;
  74316. enum { maxGifCode = 1 << 12 };
  74317. int table [2] [maxGifCode];
  74318. int stack [2 * maxGifCode];
  74319. int *sp;
  74320. bool getSizeFromHeader (int& width, int& height);
  74321. bool readPalette (const int numCols);
  74322. int readDataBlock (unsigned char* dest);
  74323. int processExtension (int type, int& transparent);
  74324. int readLZWByte (bool initialise, int input_code_size);
  74325. int getCode (int code_size, bool initialise);
  74326. bool readImage (int width, int height, int interlace, int transparent);
  74327. static inline int makeWord (const uint8 a, const uint8 b) { return (b << 8) | a; }
  74328. GIFLoader (const GIFLoader&);
  74329. GIFLoader& operator= (const GIFLoader&);
  74330. };
  74331. #endif // DOXYGEN
  74332. #endif // __JUCE_GIFLOADER_JUCEHEADER__
  74333. /*** End of inlined file: juce_GIFLoader.h ***/
  74334. Image* juce_loadPNGImageFromStream (InputStream& inputStream);
  74335. bool juce_writePNGImageToStream (const Image& image, OutputStream& out);
  74336. PNGImageFormat::PNGImageFormat() {}
  74337. PNGImageFormat::~PNGImageFormat() {}
  74338. const String PNGImageFormat::getFormatName()
  74339. {
  74340. return T("PNG");
  74341. }
  74342. bool PNGImageFormat::canUnderstand (InputStream& in)
  74343. {
  74344. const int bytesNeeded = 4;
  74345. char header [bytesNeeded];
  74346. return in.read (header, bytesNeeded) == bytesNeeded
  74347. && header[1] == 'P'
  74348. && header[2] == 'N'
  74349. && header[3] == 'G';
  74350. }
  74351. Image* PNGImageFormat::decodeImage (InputStream& in)
  74352. {
  74353. return juce_loadPNGImageFromStream (in);
  74354. }
  74355. bool PNGImageFormat::writeImageToStream (const Image& sourceImage,
  74356. OutputStream& destStream)
  74357. {
  74358. return juce_writePNGImageToStream (sourceImage, destStream);
  74359. }
  74360. Image* juce_loadJPEGImageFromStream (InputStream& inputStream);
  74361. bool juce_writeJPEGImageToStream (const Image& image, OutputStream& out, float quality);
  74362. JPEGImageFormat::JPEGImageFormat()
  74363. : quality (-1.0f)
  74364. {
  74365. }
  74366. JPEGImageFormat::~JPEGImageFormat() {}
  74367. void JPEGImageFormat::setQuality (const float newQuality)
  74368. {
  74369. quality = newQuality;
  74370. }
  74371. const String JPEGImageFormat::getFormatName()
  74372. {
  74373. return T("JPEG");
  74374. }
  74375. bool JPEGImageFormat::canUnderstand (InputStream& in)
  74376. {
  74377. const int bytesNeeded = 10;
  74378. uint8 header [bytesNeeded];
  74379. if (in.read (header, bytesNeeded) == bytesNeeded)
  74380. {
  74381. return header[0] == 0xff
  74382. && header[1] == 0xd8
  74383. && header[2] == 0xff
  74384. && (header[3] == 0xe0 || header[3] == 0xe1);
  74385. }
  74386. return false;
  74387. }
  74388. Image* JPEGImageFormat::decodeImage (InputStream& in)
  74389. {
  74390. return juce_loadJPEGImageFromStream (in);
  74391. }
  74392. bool JPEGImageFormat::writeImageToStream (const Image& sourceImage,
  74393. OutputStream& destStream)
  74394. {
  74395. return juce_writeJPEGImageToStream (sourceImage, destStream, quality);
  74396. }
  74397. class GIFImageFormat : public ImageFileFormat
  74398. {
  74399. public:
  74400. GIFImageFormat() {}
  74401. ~GIFImageFormat() {}
  74402. const String getFormatName()
  74403. {
  74404. return T("GIF");
  74405. }
  74406. bool canUnderstand (InputStream& in)
  74407. {
  74408. const int bytesNeeded = 4;
  74409. char header [bytesNeeded];
  74410. return (in.read (header, bytesNeeded) == bytesNeeded)
  74411. && header[0] == 'G'
  74412. && header[1] == 'I'
  74413. && header[2] == 'F';
  74414. }
  74415. Image* decodeImage (InputStream& in)
  74416. {
  74417. const ScopedPointer <GIFLoader> loader (new GIFLoader (in));
  74418. return loader->getImage();
  74419. }
  74420. bool writeImageToStream (const Image& /*sourceImage*/, OutputStream& /*destStream*/)
  74421. {
  74422. return false;
  74423. }
  74424. };
  74425. ImageFileFormat* ImageFileFormat::findImageFormatForStream (InputStream& input)
  74426. {
  74427. static PNGImageFormat png;
  74428. static JPEGImageFormat jpg;
  74429. static GIFImageFormat gif;
  74430. ImageFileFormat* formats[4];
  74431. int numFormats = 0;
  74432. formats [numFormats++] = &png;
  74433. formats [numFormats++] = &jpg;
  74434. formats [numFormats++] = &gif;
  74435. const int64 streamPos = input.getPosition();
  74436. for (int i = 0; i < numFormats; ++i)
  74437. {
  74438. const bool found = formats[i]->canUnderstand (input);
  74439. input.setPosition (streamPos);
  74440. if (found)
  74441. return formats[i];
  74442. }
  74443. return 0;
  74444. }
  74445. Image* ImageFileFormat::loadFrom (InputStream& input)
  74446. {
  74447. ImageFileFormat* const format = findImageFormatForStream (input);
  74448. if (format != 0)
  74449. return format->decodeImage (input);
  74450. return 0;
  74451. }
  74452. Image* ImageFileFormat::loadFrom (const File& file)
  74453. {
  74454. InputStream* const in = file.createInputStream();
  74455. if (in != 0)
  74456. {
  74457. BufferedInputStream b (in, 8192, true);
  74458. return loadFrom (b);
  74459. }
  74460. return 0;
  74461. }
  74462. Image* ImageFileFormat::loadFrom (const void* rawData, const int numBytes)
  74463. {
  74464. if (rawData != 0 && numBytes > 4)
  74465. {
  74466. MemoryInputStream stream (rawData, numBytes, false);
  74467. return loadFrom (stream);
  74468. }
  74469. return 0;
  74470. }
  74471. END_JUCE_NAMESPACE
  74472. /*** End of inlined file: juce_ImageFileFormat.cpp ***/
  74473. /*** Start of inlined file: juce_GIFLoader.cpp ***/
  74474. BEGIN_JUCE_NAMESPACE
  74475. GIFLoader::GIFLoader (InputStream& in)
  74476. : image (0),
  74477. input (in),
  74478. dataBlockIsZero (false),
  74479. fresh (false),
  74480. finished (false)
  74481. {
  74482. currentBit = lastBit = lastByteIndex = 0;
  74483. maxCode = maxCodeSize = codeSize = setCodeSize = 0;
  74484. firstcode = oldcode = 0;
  74485. clearCode = end_code = 0;
  74486. int imageWidth, imageHeight;
  74487. int transparent = -1;
  74488. if (! getSizeFromHeader (imageWidth, imageHeight))
  74489. return;
  74490. if ((imageWidth <= 0) || (imageHeight <= 0))
  74491. return;
  74492. unsigned char buf [16];
  74493. if (in.read (buf, 3) != 3)
  74494. return;
  74495. int numColours = 2 << (buf[0] & 7);
  74496. if ((buf[0] & 0x80) != 0)
  74497. readPalette (numColours);
  74498. for (;;)
  74499. {
  74500. if (input.read (buf, 1) != 1)
  74501. break;
  74502. if (buf[0] == ';')
  74503. break;
  74504. if (buf[0] == '!')
  74505. {
  74506. if (input.read (buf, 1) != 1)
  74507. break;
  74508. if (processExtension (buf[0], transparent) < 0)
  74509. break;
  74510. continue;
  74511. }
  74512. if (buf[0] != ',')
  74513. continue;
  74514. if (input.read (buf, 9) != 9)
  74515. break;
  74516. imageWidth = makeWord (buf[4], buf[5]);
  74517. imageHeight = makeWord (buf[6], buf[7]);
  74518. numColours = 2 << (buf[8] & 7);
  74519. if ((buf[8] & 0x80) != 0)
  74520. if (! readPalette (numColours))
  74521. break;
  74522. image = Image::createNativeImage ((transparent >= 0) ? Image::ARGB : Image::RGB,
  74523. imageWidth, imageHeight, (transparent >= 0));
  74524. readImage (imageWidth, imageHeight,
  74525. (buf[8] & 0x40) != 0,
  74526. transparent);
  74527. break;
  74528. }
  74529. }
  74530. GIFLoader::~GIFLoader()
  74531. {
  74532. }
  74533. bool GIFLoader::getSizeFromHeader (int& w, int& h)
  74534. {
  74535. unsigned char b [8];
  74536. if (input.read (b, 6) == 6)
  74537. {
  74538. if ((strncmp ("GIF87a", (char*) b, 6) == 0)
  74539. || (strncmp ("GIF89a", (char*) b, 6) == 0))
  74540. {
  74541. if (input.read (b, 4) == 4)
  74542. {
  74543. w = makeWord (b[0], b[1]);
  74544. h = makeWord (b[2], b[3]);
  74545. return true;
  74546. }
  74547. }
  74548. }
  74549. return false;
  74550. }
  74551. bool GIFLoader::readPalette (const int numCols)
  74552. {
  74553. unsigned char rgb[4];
  74554. for (int i = 0; i < numCols; ++i)
  74555. {
  74556. input.read (rgb, 3);
  74557. palette [i][0] = rgb[0];
  74558. palette [i][1] = rgb[1];
  74559. palette [i][2] = rgb[2];
  74560. palette [i][3] = 0xff;
  74561. }
  74562. return true;
  74563. }
  74564. int GIFLoader::readDataBlock (unsigned char* const dest)
  74565. {
  74566. unsigned char n;
  74567. if (input.read (&n, 1) == 1)
  74568. {
  74569. dataBlockIsZero = (n == 0);
  74570. if (dataBlockIsZero || (input.read (dest, n) == n))
  74571. return n;
  74572. }
  74573. return -1;
  74574. }
  74575. int GIFLoader::processExtension (const int type, int& transparent)
  74576. {
  74577. unsigned char b [300];
  74578. int n = 0;
  74579. if (type == 0xf9)
  74580. {
  74581. n = readDataBlock (b);
  74582. if (n < 0)
  74583. return 1;
  74584. if ((b[0] & 0x1) != 0)
  74585. transparent = b[3];
  74586. }
  74587. do
  74588. {
  74589. n = readDataBlock (b);
  74590. }
  74591. while (n > 0);
  74592. return n;
  74593. }
  74594. int GIFLoader::getCode (const int codeSize_, const bool initialise)
  74595. {
  74596. if (initialise)
  74597. {
  74598. currentBit = 0;
  74599. lastBit = 0;
  74600. finished = false;
  74601. return 0;
  74602. }
  74603. if ((currentBit + codeSize_) >= lastBit)
  74604. {
  74605. if (finished)
  74606. return -1;
  74607. buffer[0] = buffer [lastByteIndex - 2];
  74608. buffer[1] = buffer [lastByteIndex - 1];
  74609. const int n = readDataBlock (&buffer[2]);
  74610. if (n == 0)
  74611. finished = true;
  74612. lastByteIndex = 2 + n;
  74613. currentBit = (currentBit - lastBit) + 16;
  74614. lastBit = (2 + n) * 8 ;
  74615. }
  74616. int result = 0;
  74617. int i = currentBit;
  74618. for (int j = 0; j < codeSize_; ++j)
  74619. {
  74620. result |= ((buffer[i >> 3] & (1 << (i & 7))) != 0) << j;
  74621. ++i;
  74622. }
  74623. currentBit += codeSize_;
  74624. return result;
  74625. }
  74626. int GIFLoader::readLZWByte (const bool initialise, const int inputCodeSize)
  74627. {
  74628. int code, incode, i;
  74629. if (initialise)
  74630. {
  74631. setCodeSize = inputCodeSize;
  74632. codeSize = setCodeSize + 1;
  74633. clearCode = 1 << setCodeSize;
  74634. end_code = clearCode + 1;
  74635. maxCodeSize = 2 * clearCode;
  74636. maxCode = clearCode + 2;
  74637. getCode (0, true);
  74638. fresh = true;
  74639. for (i = 0; i < clearCode; ++i)
  74640. {
  74641. table[0][i] = 0;
  74642. table[1][i] = i;
  74643. }
  74644. for (; i < maxGifCode; ++i)
  74645. {
  74646. table[0][i] = 0;
  74647. table[1][i] = 0;
  74648. }
  74649. sp = stack;
  74650. return 0;
  74651. }
  74652. else if (fresh)
  74653. {
  74654. fresh = false;
  74655. do
  74656. {
  74657. firstcode = oldcode
  74658. = getCode (codeSize, false);
  74659. }
  74660. while (firstcode == clearCode);
  74661. return firstcode;
  74662. }
  74663. if (sp > stack)
  74664. return *--sp;
  74665. while ((code = getCode (codeSize, false)) >= 0)
  74666. {
  74667. if (code == clearCode)
  74668. {
  74669. for (i = 0; i < clearCode; ++i)
  74670. {
  74671. table[0][i] = 0;
  74672. table[1][i] = i;
  74673. }
  74674. for (; i < maxGifCode; ++i)
  74675. {
  74676. table[0][i] = 0;
  74677. table[1][i] = 0;
  74678. }
  74679. codeSize = setCodeSize + 1;
  74680. maxCodeSize = 2 * clearCode;
  74681. maxCode = clearCode + 2;
  74682. sp = stack;
  74683. firstcode = oldcode = getCode (codeSize, false);
  74684. return firstcode;
  74685. }
  74686. else if (code == end_code)
  74687. {
  74688. if (dataBlockIsZero)
  74689. return -2;
  74690. unsigned char buf [260];
  74691. int n;
  74692. while ((n = readDataBlock (buf)) > 0)
  74693. {}
  74694. if (n != 0)
  74695. return -2;
  74696. }
  74697. incode = code;
  74698. if (code >= maxCode)
  74699. {
  74700. *sp++ = firstcode;
  74701. code = oldcode;
  74702. }
  74703. while (code >= clearCode)
  74704. {
  74705. *sp++ = table[1][code];
  74706. if (code == table[0][code])
  74707. return -2;
  74708. code = table[0][code];
  74709. }
  74710. *sp++ = firstcode = table[1][code];
  74711. if ((code = maxCode) < maxGifCode)
  74712. {
  74713. table[0][code] = oldcode;
  74714. table[1][code] = firstcode;
  74715. ++maxCode;
  74716. if ((maxCode >= maxCodeSize)
  74717. && (maxCodeSize < maxGifCode))
  74718. {
  74719. maxCodeSize <<= 1;
  74720. ++codeSize;
  74721. }
  74722. }
  74723. oldcode = incode;
  74724. if (sp > stack)
  74725. return *--sp;
  74726. }
  74727. return code;
  74728. }
  74729. bool GIFLoader::readImage (const int width, const int height,
  74730. const int interlace, const int transparent)
  74731. {
  74732. unsigned char c;
  74733. if (input.read (&c, 1) != 1
  74734. || readLZWByte (true, c) < 0)
  74735. return false;
  74736. if (transparent >= 0)
  74737. {
  74738. palette [transparent][0] = 0;
  74739. palette [transparent][1] = 0;
  74740. palette [transparent][2] = 0;
  74741. palette [transparent][3] = 0;
  74742. }
  74743. int index;
  74744. int xpos = 0, ypos = 0, pass = 0;
  74745. const Image::BitmapData destData (*image, 0, 0, width, height, true);
  74746. uint8* p = destData.data;
  74747. const bool hasAlpha = image->hasAlphaChannel();
  74748. while ((index = readLZWByte (false, c)) >= 0)
  74749. {
  74750. const uint8* const paletteEntry = palette [index];
  74751. if (hasAlpha)
  74752. {
  74753. ((PixelARGB*) p)->setARGB (paletteEntry[3],
  74754. paletteEntry[0],
  74755. paletteEntry[1],
  74756. paletteEntry[2]);
  74757. ((PixelARGB*) p)->premultiply();
  74758. }
  74759. else
  74760. {
  74761. ((PixelRGB*) p)->setARGB (0,
  74762. paletteEntry[0],
  74763. paletteEntry[1],
  74764. paletteEntry[2]);
  74765. }
  74766. p += destData.pixelStride;
  74767. ++xpos;
  74768. if (xpos == width)
  74769. {
  74770. xpos = 0;
  74771. if (interlace)
  74772. {
  74773. switch (pass)
  74774. {
  74775. case 0:
  74776. case 1:
  74777. ypos += 8;
  74778. break;
  74779. case 2:
  74780. ypos += 4;
  74781. break;
  74782. case 3:
  74783. ypos += 2;
  74784. break;
  74785. }
  74786. while (ypos >= height)
  74787. {
  74788. ++pass;
  74789. switch (pass)
  74790. {
  74791. case 1:
  74792. ypos = 4;
  74793. break;
  74794. case 2:
  74795. ypos = 2;
  74796. break;
  74797. case 3:
  74798. ypos = 1;
  74799. break;
  74800. default:
  74801. return true;
  74802. }
  74803. }
  74804. }
  74805. else
  74806. {
  74807. ++ypos;
  74808. }
  74809. p = destData.getPixelPointer (xpos, ypos);
  74810. }
  74811. if (ypos >= height)
  74812. break;
  74813. }
  74814. return true;
  74815. }
  74816. END_JUCE_NAMESPACE
  74817. /*** End of inlined file: juce_GIFLoader.cpp ***/
  74818. #endif
  74819. //==============================================================================
  74820. // some files include lots of library code, so leave them to the end to avoid cluttering
  74821. // up the build for the clean files.
  74822. #if JUCE_BUILD_CORE
  74823. /*** Start of inlined file: juce_GZIPCompressorOutputStream.cpp ***/
  74824. namespace zlibNamespace
  74825. {
  74826. #if JUCE_INCLUDE_ZLIB_CODE
  74827. #undef OS_CODE
  74828. #undef fdopen
  74829. /*** Start of inlined file: zlib.h ***/
  74830. #ifndef ZLIB_H
  74831. #define ZLIB_H
  74832. /*** Start of inlined file: zconf.h ***/
  74833. #ifndef ZCONF_H
  74834. #define ZCONF_H
  74835. // *** Just a few hacks here to make it compile nicely with Juce..
  74836. #define Z_PREFIX 1
  74837. #undef __MACTYPES__
  74838. #ifdef _MSC_VER
  74839. #pragma warning (disable : 4131 4127 4244 4267)
  74840. #endif
  74841. #ifdef Z_PREFIX
  74842. # define deflateInit_ z_deflateInit_
  74843. # define deflate z_deflate
  74844. # define deflateEnd z_deflateEnd
  74845. # define inflateInit_ z_inflateInit_
  74846. # define inflate z_inflate
  74847. # define inflateEnd z_inflateEnd
  74848. # define deflateInit2_ z_deflateInit2_
  74849. # define deflateSetDictionary z_deflateSetDictionary
  74850. # define deflateCopy z_deflateCopy
  74851. # define deflateReset z_deflateReset
  74852. # define deflateParams z_deflateParams
  74853. # define deflateBound z_deflateBound
  74854. # define deflatePrime z_deflatePrime
  74855. # define inflateInit2_ z_inflateInit2_
  74856. # define inflateSetDictionary z_inflateSetDictionary
  74857. # define inflateSync z_inflateSync
  74858. # define inflateSyncPoint z_inflateSyncPoint
  74859. # define inflateCopy z_inflateCopy
  74860. # define inflateReset z_inflateReset
  74861. # define inflateBack z_inflateBack
  74862. # define inflateBackEnd z_inflateBackEnd
  74863. # define compress z_compress
  74864. # define compress2 z_compress2
  74865. # define compressBound z_compressBound
  74866. # define uncompress z_uncompress
  74867. # define adler32 z_adler32
  74868. # define crc32 z_crc32
  74869. # define get_crc_table z_get_crc_table
  74870. # define zError z_zError
  74871. # define alloc_func z_alloc_func
  74872. # define free_func z_free_func
  74873. # define in_func z_in_func
  74874. # define out_func z_out_func
  74875. # define Byte z_Byte
  74876. # define uInt z_uInt
  74877. # define uLong z_uLong
  74878. # define Bytef z_Bytef
  74879. # define charf z_charf
  74880. # define intf z_intf
  74881. # define uIntf z_uIntf
  74882. # define uLongf z_uLongf
  74883. # define voidpf z_voidpf
  74884. # define voidp z_voidp
  74885. #endif
  74886. #if defined(__MSDOS__) && !defined(MSDOS)
  74887. # define MSDOS
  74888. #endif
  74889. #if (defined(OS_2) || defined(__OS2__)) && !defined(OS2)
  74890. # define OS2
  74891. #endif
  74892. #if defined(_WINDOWS) && !defined(WINDOWS)
  74893. # define WINDOWS
  74894. #endif
  74895. #if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__)
  74896. # ifndef WIN32
  74897. # define WIN32
  74898. # endif
  74899. #endif
  74900. #if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32)
  74901. # if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__)
  74902. # ifndef SYS16BIT
  74903. # define SYS16BIT
  74904. # endif
  74905. # endif
  74906. #endif
  74907. #ifdef SYS16BIT
  74908. # define MAXSEG_64K
  74909. #endif
  74910. #ifdef MSDOS
  74911. # define UNALIGNED_OK
  74912. #endif
  74913. #ifdef __STDC_VERSION__
  74914. # ifndef STDC
  74915. # define STDC
  74916. # endif
  74917. # if __STDC_VERSION__ >= 199901L
  74918. # ifndef STDC99
  74919. # define STDC99
  74920. # endif
  74921. # endif
  74922. #endif
  74923. #if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus))
  74924. # define STDC
  74925. #endif
  74926. #if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__))
  74927. # define STDC
  74928. #endif
  74929. #if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32))
  74930. # define STDC
  74931. #endif
  74932. #if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__))
  74933. # define STDC
  74934. #endif
  74935. #if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */
  74936. # define STDC
  74937. #endif
  74938. #ifndef STDC
  74939. # ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
  74940. # define const /* note: need a more gentle solution here */
  74941. # endif
  74942. #endif
  74943. #if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)
  74944. # define NO_DUMMY_DECL
  74945. #endif
  74946. #ifndef MAX_MEM_LEVEL
  74947. # ifdef MAXSEG_64K
  74948. # define MAX_MEM_LEVEL 8
  74949. # else
  74950. # define MAX_MEM_LEVEL 9
  74951. # endif
  74952. #endif
  74953. #ifndef MAX_WBITS
  74954. # define MAX_WBITS 15 /* 32K LZ77 window */
  74955. #endif
  74956. #ifndef OF /* function prototypes */
  74957. # ifdef STDC
  74958. # define OF(args) args
  74959. # else
  74960. # define OF(args) ()
  74961. # endif
  74962. #endif
  74963. #ifdef SYS16BIT
  74964. # if defined(M_I86SM) || defined(M_I86MM)
  74965. # define SMALL_MEDIUM
  74966. # ifdef _MSC_VER
  74967. # define FAR _far
  74968. # else
  74969. # define FAR far
  74970. # endif
  74971. # endif
  74972. # if (defined(__SMALL__) || defined(__MEDIUM__))
  74973. # define SMALL_MEDIUM
  74974. # ifdef __BORLANDC__
  74975. # define FAR _far
  74976. # else
  74977. # define FAR far
  74978. # endif
  74979. # endif
  74980. #endif
  74981. #if defined(WINDOWS) || defined(WIN32)
  74982. # ifdef ZLIB_DLL
  74983. # if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500))
  74984. # ifdef ZLIB_INTERNAL
  74985. # define ZEXTERN extern __declspec(dllexport)
  74986. # else
  74987. # define ZEXTERN extern __declspec(dllimport)
  74988. # endif
  74989. # endif
  74990. # endif /* ZLIB_DLL */
  74991. # ifdef ZLIB_WINAPI
  74992. # ifdef FAR
  74993. # undef FAR
  74994. # endif
  74995. # include <windows.h>
  74996. # define ZEXPORT WINAPI
  74997. # ifdef WIN32
  74998. # define ZEXPORTVA WINAPIV
  74999. # else
  75000. # define ZEXPORTVA FAR CDECL
  75001. # endif
  75002. # endif
  75003. #endif
  75004. #if defined (__BEOS__)
  75005. # ifdef ZLIB_DLL
  75006. # ifdef ZLIB_INTERNAL
  75007. # define ZEXPORT __declspec(dllexport)
  75008. # define ZEXPORTVA __declspec(dllexport)
  75009. # else
  75010. # define ZEXPORT __declspec(dllimport)
  75011. # define ZEXPORTVA __declspec(dllimport)
  75012. # endif
  75013. # endif
  75014. #endif
  75015. #ifndef ZEXTERN
  75016. # define ZEXTERN extern
  75017. #endif
  75018. #ifndef ZEXPORT
  75019. # define ZEXPORT
  75020. #endif
  75021. #ifndef ZEXPORTVA
  75022. # define ZEXPORTVA
  75023. #endif
  75024. #ifndef FAR
  75025. # define FAR
  75026. #endif
  75027. #if !defined(__MACTYPES__)
  75028. typedef unsigned char Byte; /* 8 bits */
  75029. #endif
  75030. typedef unsigned int uInt; /* 16 bits or more */
  75031. typedef unsigned long uLong; /* 32 bits or more */
  75032. #ifdef SMALL_MEDIUM
  75033. # define Bytef Byte FAR
  75034. #else
  75035. typedef Byte FAR Bytef;
  75036. #endif
  75037. typedef char FAR charf;
  75038. typedef int FAR intf;
  75039. typedef uInt FAR uIntf;
  75040. typedef uLong FAR uLongf;
  75041. #ifdef STDC
  75042. typedef void const *voidpc;
  75043. typedef void FAR *voidpf;
  75044. typedef void *voidp;
  75045. #else
  75046. typedef Byte const *voidpc;
  75047. typedef Byte FAR *voidpf;
  75048. typedef Byte *voidp;
  75049. #endif
  75050. #if 0 /* HAVE_UNISTD_H -- this line is updated by ./configure */
  75051. # include <sys/types.h> /* for off_t */
  75052. # include <unistd.h> /* for SEEK_* and off_t */
  75053. # ifdef VMS
  75054. # include <unixio.h> /* for off_t */
  75055. # endif
  75056. # define z_off_t off_t
  75057. #endif
  75058. #ifndef SEEK_SET
  75059. # define SEEK_SET 0 /* Seek from beginning of file. */
  75060. # define SEEK_CUR 1 /* Seek from current position. */
  75061. # define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
  75062. #endif
  75063. #ifndef z_off_t
  75064. # define z_off_t long
  75065. #endif
  75066. #if defined(__OS400__)
  75067. # define NO_vsnprintf
  75068. #endif
  75069. #if defined(__MVS__)
  75070. # define NO_vsnprintf
  75071. # ifdef FAR
  75072. # undef FAR
  75073. # endif
  75074. #endif
  75075. #if defined(__MVS__)
  75076. # pragma map(deflateInit_,"DEIN")
  75077. # pragma map(deflateInit2_,"DEIN2")
  75078. # pragma map(deflateEnd,"DEEND")
  75079. # pragma map(deflateBound,"DEBND")
  75080. # pragma map(inflateInit_,"ININ")
  75081. # pragma map(inflateInit2_,"ININ2")
  75082. # pragma map(inflateEnd,"INEND")
  75083. # pragma map(inflateSync,"INSY")
  75084. # pragma map(inflateSetDictionary,"INSEDI")
  75085. # pragma map(compressBound,"CMBND")
  75086. # pragma map(inflate_table,"INTABL")
  75087. # pragma map(inflate_fast,"INFA")
  75088. # pragma map(inflate_copyright,"INCOPY")
  75089. #endif
  75090. #endif /* ZCONF_H */
  75091. /*** End of inlined file: zconf.h ***/
  75092. #ifdef __cplusplus
  75093. extern "C" {
  75094. #endif
  75095. #define ZLIB_VERSION "1.2.3"
  75096. #define ZLIB_VERNUM 0x1230
  75097. typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
  75098. typedef void (*free_func) OF((voidpf opaque, voidpf address));
  75099. struct internal_state;
  75100. typedef struct z_stream_s {
  75101. Bytef *next_in; /* next input byte */
  75102. uInt avail_in; /* number of bytes available at next_in */
  75103. uLong total_in; /* total nb of input bytes read so far */
  75104. Bytef *next_out; /* next output byte should be put there */
  75105. uInt avail_out; /* remaining free space at next_out */
  75106. uLong total_out; /* total nb of bytes output so far */
  75107. char *msg; /* last error message, NULL if no error */
  75108. struct internal_state FAR *state; /* not visible by applications */
  75109. alloc_func zalloc; /* used to allocate the internal state */
  75110. free_func zfree; /* used to free the internal state */
  75111. voidpf opaque; /* private data object passed to zalloc and zfree */
  75112. int data_type; /* best guess about the data type: binary or text */
  75113. uLong adler; /* adler32 value of the uncompressed data */
  75114. uLong reserved; /* reserved for future use */
  75115. } z_stream;
  75116. typedef z_stream FAR *z_streamp;
  75117. typedef struct gz_header_s {
  75118. int text; /* true if compressed data believed to be text */
  75119. uLong time; /* modification time */
  75120. int xflags; /* extra flags (not used when writing a gzip file) */
  75121. int os; /* operating system */
  75122. Bytef *extra; /* pointer to extra field or Z_NULL if none */
  75123. uInt extra_len; /* extra field length (valid if extra != Z_NULL) */
  75124. uInt extra_max; /* space at extra (only when reading header) */
  75125. Bytef *name; /* pointer to zero-terminated file name or Z_NULL */
  75126. uInt name_max; /* space at name (only when reading header) */
  75127. Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */
  75128. uInt comm_max; /* space at comment (only when reading header) */
  75129. int hcrc; /* true if there was or will be a header crc */
  75130. int done; /* true when done reading gzip header (not used
  75131. when writing a gzip file) */
  75132. } gz_header;
  75133. typedef gz_header FAR *gz_headerp;
  75134. #define Z_NO_FLUSH 0
  75135. #define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
  75136. #define Z_SYNC_FLUSH 2
  75137. #define Z_FULL_FLUSH 3
  75138. #define Z_FINISH 4
  75139. #define Z_BLOCK 5
  75140. #define Z_OK 0
  75141. #define Z_STREAM_END 1
  75142. #define Z_NEED_DICT 2
  75143. #define Z_ERRNO (-1)
  75144. #define Z_STREAM_ERROR (-2)
  75145. #define Z_DATA_ERROR (-3)
  75146. #define Z_MEM_ERROR (-4)
  75147. #define Z_BUF_ERROR (-5)
  75148. #define Z_VERSION_ERROR (-6)
  75149. #define Z_NO_COMPRESSION 0
  75150. #define Z_BEST_SPEED 1
  75151. #define Z_BEST_COMPRESSION 9
  75152. #define Z_DEFAULT_COMPRESSION (-1)
  75153. #define Z_FILTERED 1
  75154. #define Z_HUFFMAN_ONLY 2
  75155. #define Z_RLE 3
  75156. #define Z_FIXED 4
  75157. #define Z_DEFAULT_STRATEGY 0
  75158. #define Z_BINARY 0
  75159. #define Z_TEXT 1
  75160. #define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */
  75161. #define Z_UNKNOWN 2
  75162. #define Z_DEFLATED 8
  75163. #define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
  75164. #define zlib_version zlibVersion()
  75165. //ZEXTERN const char * ZEXPORT zlibVersion OF((void));
  75166. ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
  75167. ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
  75168. ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
  75169. ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
  75170. ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
  75171. const Bytef *dictionary,
  75172. uInt dictLength));
  75173. ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
  75174. z_streamp source));
  75175. ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
  75176. ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
  75177. int level,
  75178. int strategy));
  75179. ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm,
  75180. int good_length,
  75181. int max_lazy,
  75182. int nice_length,
  75183. int max_chain));
  75184. ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm,
  75185. uLong sourceLen));
  75186. ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
  75187. int bits,
  75188. int value));
  75189. ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm,
  75190. gz_headerp head));
  75191. ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
  75192. const Bytef *dictionary,
  75193. uInt dictLength));
  75194. ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
  75195. ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest,
  75196. z_streamp source));
  75197. ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
  75198. ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm,
  75199. int bits,
  75200. int value));
  75201. ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm,
  75202. gz_headerp head));
  75203. typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *));
  75204. typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned));
  75205. ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
  75206. in_func in, void FAR *in_desc,
  75207. out_func out, void FAR *out_desc));
  75208. ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm));
  75209. //ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void));
  75210. ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen,
  75211. const Bytef *source, uLong sourceLen));
  75212. ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen,
  75213. const Bytef *source, uLong sourceLen,
  75214. int level));
  75215. ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen));
  75216. ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
  75217. const Bytef *source, uLong sourceLen));
  75218. typedef voidp gzFile;
  75219. ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
  75220. ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
  75221. ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
  75222. ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
  75223. ZEXTERN int ZEXPORT gzwrite OF((gzFile file,
  75224. voidpc buf, unsigned len));
  75225. ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...));
  75226. ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
  75227. ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
  75228. ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c));
  75229. ZEXTERN int ZEXPORT gzgetc OF((gzFile file));
  75230. ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file));
  75231. ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));
  75232. ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file,
  75233. z_off_t offset, int whence));
  75234. ZEXTERN int ZEXPORT gzrewind OF((gzFile file));
  75235. ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file));
  75236. ZEXTERN int ZEXPORT gzeof OF((gzFile file));
  75237. ZEXTERN int ZEXPORT gzdirect OF((gzFile file));
  75238. ZEXTERN int ZEXPORT gzclose OF((gzFile file));
  75239. ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
  75240. ZEXTERN void ZEXPORT gzclearerr OF((gzFile file));
  75241. ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
  75242. ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2,
  75243. z_off_t len2));
  75244. ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
  75245. ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2));
  75246. ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level,
  75247. const char *version, int stream_size));
  75248. ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm,
  75249. const char *version, int stream_size));
  75250. ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method,
  75251. int windowBits, int memLevel,
  75252. int strategy, const char *version,
  75253. int stream_size));
  75254. ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits,
  75255. const char *version, int stream_size));
  75256. ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
  75257. unsigned char FAR *window,
  75258. const char *version,
  75259. int stream_size));
  75260. #define deflateInit(strm, level) \
  75261. deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream))
  75262. #define inflateInit(strm) \
  75263. inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream))
  75264. #define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
  75265. deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
  75266. (strategy), ZLIB_VERSION, sizeof(z_stream))
  75267. #define inflateInit2(strm, windowBits) \
  75268. inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
  75269. #define inflateBackInit(strm, windowBits, window) \
  75270. inflateBackInit_((strm), (windowBits), (window), \
  75271. ZLIB_VERSION, sizeof(z_stream))
  75272. #if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL)
  75273. struct internal_state {int dummy;}; /* hack for buggy compilers */
  75274. #endif
  75275. ZEXTERN const char * ZEXPORT zError OF((int));
  75276. ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp z));
  75277. ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void));
  75278. #ifdef __cplusplus
  75279. }
  75280. #endif
  75281. #endif /* ZLIB_H */
  75282. /*** End of inlined file: zlib.h ***/
  75283. #undef OS_CODE
  75284. #else
  75285. #include <zlib.h>
  75286. #endif
  75287. }
  75288. BEGIN_JUCE_NAMESPACE
  75289. using namespace zlibNamespace;
  75290. // internal helper object that holds the zlib structures so they don't have to be
  75291. // included publicly.
  75292. class GZIPCompressorHelper
  75293. {
  75294. public:
  75295. GZIPCompressorHelper (const int compressionLevel, const bool nowrap)
  75296. : data (0),
  75297. dataSize (0),
  75298. compLevel (compressionLevel),
  75299. strategy (0),
  75300. setParams (true),
  75301. streamIsValid (false),
  75302. finished (false),
  75303. shouldFinish (false)
  75304. {
  75305. zerostruct (stream);
  75306. streamIsValid = (deflateInit2 (&stream, compLevel, Z_DEFLATED,
  75307. nowrap ? -MAX_WBITS : MAX_WBITS,
  75308. 8, strategy) == Z_OK);
  75309. }
  75310. ~GZIPCompressorHelper()
  75311. {
  75312. if (streamIsValid)
  75313. deflateEnd (&stream);
  75314. }
  75315. bool needsInput() const throw()
  75316. {
  75317. return dataSize <= 0;
  75318. }
  75319. void setInput (uint8* const newData, const int size) throw()
  75320. {
  75321. data = newData;
  75322. dataSize = size;
  75323. }
  75324. int doNextBlock (uint8* const dest, const int destSize) throw()
  75325. {
  75326. if (streamIsValid)
  75327. {
  75328. stream.next_in = data;
  75329. stream.next_out = dest;
  75330. stream.avail_in = dataSize;
  75331. stream.avail_out = destSize;
  75332. const int result = setParams ? deflateParams (&stream, compLevel, strategy)
  75333. : deflate (&stream, shouldFinish ? Z_FINISH : Z_NO_FLUSH);
  75334. setParams = false;
  75335. switch (result)
  75336. {
  75337. case Z_STREAM_END:
  75338. finished = true;
  75339. // Deliberate fall-through..
  75340. case Z_OK:
  75341. data += dataSize - stream.avail_in;
  75342. dataSize = stream.avail_in;
  75343. return destSize - stream.avail_out;
  75344. default:
  75345. break;
  75346. }
  75347. }
  75348. return 0;
  75349. }
  75350. private:
  75351. z_stream stream;
  75352. uint8* data;
  75353. int dataSize, compLevel, strategy;
  75354. bool setParams, streamIsValid;
  75355. public:
  75356. bool finished, shouldFinish;
  75357. };
  75358. const int gzipCompBufferSize = 32768;
  75359. GZIPCompressorOutputStream::GZIPCompressorOutputStream (OutputStream* const destStream_,
  75360. int compressionLevel,
  75361. const bool deleteDestStream,
  75362. const bool noWrap)
  75363. : destStream (destStream_),
  75364. streamToDelete (deleteDestStream ? destStream_ : 0),
  75365. buffer (gzipCompBufferSize)
  75366. {
  75367. if (compressionLevel < 1 || compressionLevel > 9)
  75368. compressionLevel = -1;
  75369. helper = new GZIPCompressorHelper (compressionLevel, noWrap);
  75370. }
  75371. GZIPCompressorOutputStream::~GZIPCompressorOutputStream()
  75372. {
  75373. flush();
  75374. }
  75375. void GZIPCompressorOutputStream::flush()
  75376. {
  75377. if (! helper->finished)
  75378. {
  75379. helper->shouldFinish = true;
  75380. while (! helper->finished)
  75381. doNextBlock();
  75382. }
  75383. destStream->flush();
  75384. }
  75385. bool GZIPCompressorOutputStream::write (const void* destBuffer, int howMany)
  75386. {
  75387. if (! helper->finished)
  75388. {
  75389. helper->setInput ((uint8*) destBuffer, howMany);
  75390. while (! helper->needsInput())
  75391. {
  75392. if (! doNextBlock())
  75393. return false;
  75394. }
  75395. }
  75396. return true;
  75397. }
  75398. bool GZIPCompressorOutputStream::doNextBlock()
  75399. {
  75400. const int len = helper->doNextBlock (buffer, gzipCompBufferSize);
  75401. if (len > 0)
  75402. return destStream->write (buffer, len);
  75403. else
  75404. return true;
  75405. }
  75406. int64 GZIPCompressorOutputStream::getPosition()
  75407. {
  75408. return destStream->getPosition();
  75409. }
  75410. bool GZIPCompressorOutputStream::setPosition (int64 /*newPosition*/)
  75411. {
  75412. jassertfalse // can't do it!
  75413. return false;
  75414. }
  75415. END_JUCE_NAMESPACE
  75416. /*** End of inlined file: juce_GZIPCompressorOutputStream.cpp ***/
  75417. /*** Start of inlined file: juce_GZIPDecompressorInputStream.cpp ***/
  75418. #if JUCE_MSVC
  75419. #pragma warning (push)
  75420. #pragma warning (disable: 4309 4305)
  75421. #endif
  75422. namespace zlibNamespace
  75423. {
  75424. #if JUCE_INCLUDE_ZLIB_CODE
  75425. extern "C"
  75426. {
  75427. #undef OS_CODE
  75428. #undef fdopen
  75429. #define ZLIB_INTERNAL
  75430. #define NO_DUMMY_DECL
  75431. /*** Start of inlined file: adler32.c ***/
  75432. #define ZLIB_INTERNAL
  75433. #define BASE 65521UL /* largest prime smaller than 65536 */
  75434. #define NMAX 5552
  75435. #define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;}
  75436. #define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
  75437. #define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
  75438. #define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
  75439. #define DO16(buf) DO8(buf,0); DO8(buf,8);
  75440. #ifdef NO_DIVIDE
  75441. # define MOD(a) \
  75442. do { \
  75443. if (a >= (BASE << 16)) a -= (BASE << 16); \
  75444. if (a >= (BASE << 15)) a -= (BASE << 15); \
  75445. if (a >= (BASE << 14)) a -= (BASE << 14); \
  75446. if (a >= (BASE << 13)) a -= (BASE << 13); \
  75447. if (a >= (BASE << 12)) a -= (BASE << 12); \
  75448. if (a >= (BASE << 11)) a -= (BASE << 11); \
  75449. if (a >= (BASE << 10)) a -= (BASE << 10); \
  75450. if (a >= (BASE << 9)) a -= (BASE << 9); \
  75451. if (a >= (BASE << 8)) a -= (BASE << 8); \
  75452. if (a >= (BASE << 7)) a -= (BASE << 7); \
  75453. if (a >= (BASE << 6)) a -= (BASE << 6); \
  75454. if (a >= (BASE << 5)) a -= (BASE << 5); \
  75455. if (a >= (BASE << 4)) a -= (BASE << 4); \
  75456. if (a >= (BASE << 3)) a -= (BASE << 3); \
  75457. if (a >= (BASE << 2)) a -= (BASE << 2); \
  75458. if (a >= (BASE << 1)) a -= (BASE << 1); \
  75459. if (a >= BASE) a -= BASE; \
  75460. } while (0)
  75461. # define MOD4(a) \
  75462. do { \
  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. #else
  75470. # define MOD(a) a %= BASE
  75471. # define MOD4(a) a %= BASE
  75472. #endif
  75473. uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len)
  75474. {
  75475. unsigned long sum2;
  75476. unsigned n;
  75477. sum2 = (adler >> 16) & 0xffff;
  75478. adler &= 0xffff;
  75479. if (len == 1) {
  75480. adler += buf[0];
  75481. if (adler >= BASE)
  75482. adler -= BASE;
  75483. sum2 += adler;
  75484. if (sum2 >= BASE)
  75485. sum2 -= BASE;
  75486. return adler | (sum2 << 16);
  75487. }
  75488. if (buf == Z_NULL)
  75489. return 1L;
  75490. if (len < 16) {
  75491. while (len--) {
  75492. adler += *buf++;
  75493. sum2 += adler;
  75494. }
  75495. if (adler >= BASE)
  75496. adler -= BASE;
  75497. MOD4(sum2); /* only added so many BASE's */
  75498. return adler | (sum2 << 16);
  75499. }
  75500. while (len >= NMAX) {
  75501. len -= NMAX;
  75502. n = NMAX / 16; /* NMAX is divisible by 16 */
  75503. do {
  75504. DO16(buf); /* 16 sums unrolled */
  75505. buf += 16;
  75506. } while (--n);
  75507. MOD(adler);
  75508. MOD(sum2);
  75509. }
  75510. if (len) { /* avoid modulos if none remaining */
  75511. while (len >= 16) {
  75512. len -= 16;
  75513. DO16(buf);
  75514. buf += 16;
  75515. }
  75516. while (len--) {
  75517. adler += *buf++;
  75518. sum2 += adler;
  75519. }
  75520. MOD(adler);
  75521. MOD(sum2);
  75522. }
  75523. return adler | (sum2 << 16);
  75524. }
  75525. uLong ZEXPORT adler32_combine(uLong adler1, uLong adler2, z_off_t len2)
  75526. {
  75527. unsigned long sum1;
  75528. unsigned long sum2;
  75529. unsigned rem;
  75530. rem = (unsigned)(len2 % BASE);
  75531. sum1 = adler1 & 0xffff;
  75532. sum2 = rem * sum1;
  75533. MOD(sum2);
  75534. sum1 += (adler2 & 0xffff) + BASE - 1;
  75535. sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
  75536. if (sum1 > BASE) sum1 -= BASE;
  75537. if (sum1 > BASE) sum1 -= BASE;
  75538. if (sum2 > (BASE << 1)) sum2 -= (BASE << 1);
  75539. if (sum2 > BASE) sum2 -= BASE;
  75540. return sum1 | (sum2 << 16);
  75541. }
  75542. /*** End of inlined file: adler32.c ***/
  75543. /*** Start of inlined file: compress.c ***/
  75544. #define ZLIB_INTERNAL
  75545. int ZEXPORT compress2 (Bytef *dest, uLongf *destLen, const Bytef *source,
  75546. uLong sourceLen, int level)
  75547. {
  75548. z_stream stream;
  75549. int err;
  75550. stream.next_in = (Bytef*)source;
  75551. stream.avail_in = (uInt)sourceLen;
  75552. #ifdef MAXSEG_64K
  75553. if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
  75554. #endif
  75555. stream.next_out = dest;
  75556. stream.avail_out = (uInt)*destLen;
  75557. if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
  75558. stream.zalloc = (alloc_func)0;
  75559. stream.zfree = (free_func)0;
  75560. stream.opaque = (voidpf)0;
  75561. err = deflateInit(&stream, level);
  75562. if (err != Z_OK) return err;
  75563. err = deflate(&stream, Z_FINISH);
  75564. if (err != Z_STREAM_END) {
  75565. deflateEnd(&stream);
  75566. return err == Z_OK ? Z_BUF_ERROR : err;
  75567. }
  75568. *destLen = stream.total_out;
  75569. err = deflateEnd(&stream);
  75570. return err;
  75571. }
  75572. int ZEXPORT compress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen)
  75573. {
  75574. return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
  75575. }
  75576. uLong ZEXPORT compressBound (uLong sourceLen)
  75577. {
  75578. return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + 11;
  75579. }
  75580. /*** End of inlined file: compress.c ***/
  75581. #undef DO1
  75582. #undef DO8
  75583. /*** Start of inlined file: crc32.c ***/
  75584. #ifdef MAKECRCH
  75585. # include <stdio.h>
  75586. # ifndef DYNAMIC_CRC_TABLE
  75587. # define DYNAMIC_CRC_TABLE
  75588. # endif /* !DYNAMIC_CRC_TABLE */
  75589. #endif /* MAKECRCH */
  75590. /*** Start of inlined file: zutil.h ***/
  75591. #ifndef ZUTIL_H
  75592. #define ZUTIL_H
  75593. #define ZLIB_INTERNAL
  75594. #ifdef STDC
  75595. # ifndef _WIN32_WCE
  75596. # include <stddef.h>
  75597. # endif
  75598. # include <string.h>
  75599. # include <stdlib.h>
  75600. #endif
  75601. #ifdef NO_ERRNO_H
  75602. # ifdef _WIN32_WCE
  75603. # define errno z_errno
  75604. # endif
  75605. extern int errno;
  75606. #else
  75607. # ifndef _WIN32_WCE
  75608. # include <errno.h>
  75609. # endif
  75610. #endif
  75611. #ifndef local
  75612. # define local static
  75613. #endif
  75614. typedef unsigned char uch;
  75615. typedef uch FAR uchf;
  75616. typedef unsigned short ush;
  75617. typedef ush FAR ushf;
  75618. typedef unsigned long ulg;
  75619. extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
  75620. #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
  75621. #define ERR_RETURN(strm,err) \
  75622. return (strm->msg = (char*)ERR_MSG(err), (err))
  75623. #ifndef DEF_WBITS
  75624. # define DEF_WBITS MAX_WBITS
  75625. #endif
  75626. #if MAX_MEM_LEVEL >= 8
  75627. # define DEF_MEM_LEVEL 8
  75628. #else
  75629. # define DEF_MEM_LEVEL MAX_MEM_LEVEL
  75630. #endif
  75631. #define STORED_BLOCK 0
  75632. #define STATIC_TREES 1
  75633. #define DYN_TREES 2
  75634. #define MIN_MATCH 3
  75635. #define MAX_MATCH 258
  75636. #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
  75637. #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
  75638. # define OS_CODE 0x00
  75639. # if defined(__TURBOC__) || defined(__BORLANDC__)
  75640. # if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
  75641. void _Cdecl farfree( void *block );
  75642. void *_Cdecl farmalloc( unsigned long nbytes );
  75643. # else
  75644. # include <alloc.h>
  75645. # endif
  75646. # else /* MSC or DJGPP */
  75647. # include <malloc.h>
  75648. # endif
  75649. #endif
  75650. #ifdef AMIGA
  75651. # define OS_CODE 0x01
  75652. #endif
  75653. #if defined(VAXC) || defined(VMS)
  75654. # define OS_CODE 0x02
  75655. # define F_OPEN(name, mode) \
  75656. fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
  75657. #endif
  75658. #if defined(ATARI) || defined(atarist)
  75659. # define OS_CODE 0x05
  75660. #endif
  75661. #ifdef OS2
  75662. # define OS_CODE 0x06
  75663. # ifdef M_I86
  75664. #include <malloc.h>
  75665. # endif
  75666. #endif
  75667. #if defined(MACOS) || TARGET_OS_MAC
  75668. # define OS_CODE 0x07
  75669. # if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
  75670. # include <unix.h> /* for fdopen */
  75671. # else
  75672. # ifndef fdopen
  75673. # define fdopen(fd,mode) NULL /* No fdopen() */
  75674. # endif
  75675. # endif
  75676. #endif
  75677. #ifdef TOPS20
  75678. # define OS_CODE 0x0a
  75679. #endif
  75680. #ifdef WIN32
  75681. # ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */
  75682. # define OS_CODE 0x0b
  75683. # endif
  75684. #endif
  75685. #ifdef __50SERIES /* Prime/PRIMOS */
  75686. # define OS_CODE 0x0f
  75687. #endif
  75688. #if defined(_BEOS_) || defined(RISCOS)
  75689. # define fdopen(fd,mode) NULL /* No fdopen() */
  75690. #endif
  75691. #if (defined(_MSC_VER) && (_MSC_VER > 600))
  75692. # if defined(_WIN32_WCE)
  75693. # define fdopen(fd,mode) NULL /* No fdopen() */
  75694. # ifndef _PTRDIFF_T_DEFINED
  75695. typedef int ptrdiff_t;
  75696. # define _PTRDIFF_T_DEFINED
  75697. # endif
  75698. # else
  75699. # define fdopen(fd,type) _fdopen(fd,type)
  75700. # endif
  75701. #endif
  75702. #ifndef OS_CODE
  75703. # define OS_CODE 0x03 /* assume Unix */
  75704. #endif
  75705. #ifndef F_OPEN
  75706. # define F_OPEN(name, mode) fopen((name), (mode))
  75707. #endif
  75708. #if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)
  75709. # ifndef HAVE_VSNPRINTF
  75710. # define HAVE_VSNPRINTF
  75711. # endif
  75712. #endif
  75713. #if defined(__CYGWIN__)
  75714. # ifndef HAVE_VSNPRINTF
  75715. # define HAVE_VSNPRINTF
  75716. # endif
  75717. #endif
  75718. #ifndef HAVE_VSNPRINTF
  75719. # ifdef MSDOS
  75720. # define NO_vsnprintf
  75721. # endif
  75722. # ifdef __TURBOC__
  75723. # define NO_vsnprintf
  75724. # endif
  75725. # ifdef WIN32
  75726. # if !defined(vsnprintf) && !defined(NO_vsnprintf)
  75727. # define vsnprintf _vsnprintf
  75728. # endif
  75729. # endif
  75730. # ifdef __SASC
  75731. # define NO_vsnprintf
  75732. # endif
  75733. #endif
  75734. #ifdef VMS
  75735. # define NO_vsnprintf
  75736. #endif
  75737. #if defined(pyr)
  75738. # define NO_MEMCPY
  75739. #endif
  75740. #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
  75741. # define NO_MEMCPY
  75742. #endif
  75743. #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
  75744. # define HAVE_MEMCPY
  75745. #endif
  75746. #ifdef HAVE_MEMCPY
  75747. # ifdef SMALL_MEDIUM /* MSDOS small or medium model */
  75748. # define zmemcpy _fmemcpy
  75749. # define zmemcmp _fmemcmp
  75750. # define zmemzero(dest, len) _fmemset(dest, 0, len)
  75751. # else
  75752. # define zmemcpy memcpy
  75753. # define zmemcmp memcmp
  75754. # define zmemzero(dest, len) memset(dest, 0, len)
  75755. # endif
  75756. #else
  75757. extern void zmemcpy OF((Bytef* dest, const Bytef* source, uInt len));
  75758. extern int zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len));
  75759. extern void zmemzero OF((Bytef* dest, uInt len));
  75760. #endif
  75761. #ifdef DEBUG
  75762. # include <stdio.h>
  75763. extern int z_verbose;
  75764. extern void z_error OF((const char *m));
  75765. # define Assert(cond,msg) {if(!(cond)) z_error(msg);}
  75766. # define Trace(x) {if (z_verbose>=0) fprintf x ;}
  75767. # define Tracev(x) {if (z_verbose>0) fprintf x ;}
  75768. # define Tracevv(x) {if (z_verbose>1) fprintf x ;}
  75769. # define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
  75770. # define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
  75771. #else
  75772. # define Assert(cond,msg)
  75773. # define Trace(x)
  75774. # define Tracev(x)
  75775. # define Tracevv(x)
  75776. # define Tracec(c,x)
  75777. # define Tracecv(c,x)
  75778. #endif
  75779. voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size));
  75780. void zcfree OF((voidpf opaque, voidpf ptr));
  75781. #define ZALLOC(strm, items, size) \
  75782. (*((strm)->zalloc))((strm)->opaque, (items), (size))
  75783. #define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
  75784. #define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
  75785. #endif /* ZUTIL_H */
  75786. /*** End of inlined file: zutil.h ***/
  75787. /* for STDC and FAR definitions */
  75788. #define local static
  75789. #ifndef NOBYFOUR
  75790. # ifdef STDC /* need ANSI C limits.h to determine sizes */
  75791. # include <limits.h>
  75792. # define BYFOUR
  75793. # if (UINT_MAX == 0xffffffffUL)
  75794. typedef unsigned int u4;
  75795. # else
  75796. # if (ULONG_MAX == 0xffffffffUL)
  75797. typedef unsigned long u4;
  75798. # else
  75799. # if (USHRT_MAX == 0xffffffffUL)
  75800. typedef unsigned short u4;
  75801. # else
  75802. # undef BYFOUR /* can't find a four-byte integer type! */
  75803. # endif
  75804. # endif
  75805. # endif
  75806. # endif /* STDC */
  75807. #endif /* !NOBYFOUR */
  75808. #ifdef BYFOUR
  75809. # define REV(w) (((w)>>24)+(((w)>>8)&0xff00)+ \
  75810. (((w)&0xff00)<<8)+(((w)&0xff)<<24))
  75811. local unsigned long crc32_little OF((unsigned long,
  75812. const unsigned char FAR *, unsigned));
  75813. local unsigned long crc32_big OF((unsigned long,
  75814. const unsigned char FAR *, unsigned));
  75815. # define TBLS 8
  75816. #else
  75817. # define TBLS 1
  75818. #endif /* BYFOUR */
  75819. local unsigned long gf2_matrix_times OF((unsigned long *mat,
  75820. unsigned long vec));
  75821. local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat));
  75822. #ifdef DYNAMIC_CRC_TABLE
  75823. local volatile int crc_table_empty = 1;
  75824. local unsigned long FAR crc_table[TBLS][256];
  75825. local void make_crc_table OF((void));
  75826. #ifdef MAKECRCH
  75827. local void write_table OF((FILE *, const unsigned long FAR *));
  75828. #endif /* MAKECRCH */
  75829. local void make_crc_table()
  75830. {
  75831. unsigned long c;
  75832. int n, k;
  75833. unsigned long poly; /* polynomial exclusive-or pattern */
  75834. static volatile int first = 1; /* flag to limit concurrent making */
  75835. static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
  75836. if (first) {
  75837. first = 0;
  75838. poly = 0UL;
  75839. for (n = 0; n < sizeof(p)/sizeof(unsigned char); n++)
  75840. poly |= 1UL << (31 - p[n]);
  75841. for (n = 0; n < 256; n++) {
  75842. c = (unsigned long)n;
  75843. for (k = 0; k < 8; k++)
  75844. c = c & 1 ? poly ^ (c >> 1) : c >> 1;
  75845. crc_table[0][n] = c;
  75846. }
  75847. #ifdef BYFOUR
  75848. for (n = 0; n < 256; n++) {
  75849. c = crc_table[0][n];
  75850. crc_table[4][n] = REV(c);
  75851. for (k = 1; k < 4; k++) {
  75852. c = crc_table[0][c & 0xff] ^ (c >> 8);
  75853. crc_table[k][n] = c;
  75854. crc_table[k + 4][n] = REV(c);
  75855. }
  75856. }
  75857. #endif /* BYFOUR */
  75858. crc_table_empty = 0;
  75859. }
  75860. else { /* not first */
  75861. while (crc_table_empty)
  75862. ;
  75863. }
  75864. #ifdef MAKECRCH
  75865. {
  75866. FILE *out;
  75867. out = fopen("crc32.h", "w");
  75868. if (out == NULL) return;
  75869. fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n");
  75870. fprintf(out, " * Generated automatically by crc32.c\n */\n\n");
  75871. fprintf(out, "local const unsigned long FAR ");
  75872. fprintf(out, "crc_table[TBLS][256] =\n{\n {\n");
  75873. write_table(out, crc_table[0]);
  75874. # ifdef BYFOUR
  75875. fprintf(out, "#ifdef BYFOUR\n");
  75876. for (k = 1; k < 8; k++) {
  75877. fprintf(out, " },\n {\n");
  75878. write_table(out, crc_table[k]);
  75879. }
  75880. fprintf(out, "#endif\n");
  75881. # endif /* BYFOUR */
  75882. fprintf(out, " }\n};\n");
  75883. fclose(out);
  75884. }
  75885. #endif /* MAKECRCH */
  75886. }
  75887. #ifdef MAKECRCH
  75888. local void write_table(out, table)
  75889. FILE *out;
  75890. const unsigned long FAR *table;
  75891. {
  75892. int n;
  75893. for (n = 0; n < 256; n++)
  75894. fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ", table[n],
  75895. n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", "));
  75896. }
  75897. #endif /* MAKECRCH */
  75898. #else /* !DYNAMIC_CRC_TABLE */
  75899. /*** Start of inlined file: crc32.h ***/
  75900. local const unsigned long FAR crc_table[TBLS][256] =
  75901. {
  75902. {
  75903. 0x00000000UL, 0x77073096UL, 0xee0e612cUL, 0x990951baUL, 0x076dc419UL,
  75904. 0x706af48fUL, 0xe963a535UL, 0x9e6495a3UL, 0x0edb8832UL, 0x79dcb8a4UL,
  75905. 0xe0d5e91eUL, 0x97d2d988UL, 0x09b64c2bUL, 0x7eb17cbdUL, 0xe7b82d07UL,
  75906. 0x90bf1d91UL, 0x1db71064UL, 0x6ab020f2UL, 0xf3b97148UL, 0x84be41deUL,
  75907. 0x1adad47dUL, 0x6ddde4ebUL, 0xf4d4b551UL, 0x83d385c7UL, 0x136c9856UL,
  75908. 0x646ba8c0UL, 0xfd62f97aUL, 0x8a65c9ecUL, 0x14015c4fUL, 0x63066cd9UL,
  75909. 0xfa0f3d63UL, 0x8d080df5UL, 0x3b6e20c8UL, 0x4c69105eUL, 0xd56041e4UL,
  75910. 0xa2677172UL, 0x3c03e4d1UL, 0x4b04d447UL, 0xd20d85fdUL, 0xa50ab56bUL,
  75911. 0x35b5a8faUL, 0x42b2986cUL, 0xdbbbc9d6UL, 0xacbcf940UL, 0x32d86ce3UL,
  75912. 0x45df5c75UL, 0xdcd60dcfUL, 0xabd13d59UL, 0x26d930acUL, 0x51de003aUL,
  75913. 0xc8d75180UL, 0xbfd06116UL, 0x21b4f4b5UL, 0x56b3c423UL, 0xcfba9599UL,
  75914. 0xb8bda50fUL, 0x2802b89eUL, 0x5f058808UL, 0xc60cd9b2UL, 0xb10be924UL,
  75915. 0x2f6f7c87UL, 0x58684c11UL, 0xc1611dabUL, 0xb6662d3dUL, 0x76dc4190UL,
  75916. 0x01db7106UL, 0x98d220bcUL, 0xefd5102aUL, 0x71b18589UL, 0x06b6b51fUL,
  75917. 0x9fbfe4a5UL, 0xe8b8d433UL, 0x7807c9a2UL, 0x0f00f934UL, 0x9609a88eUL,
  75918. 0xe10e9818UL, 0x7f6a0dbbUL, 0x086d3d2dUL, 0x91646c97UL, 0xe6635c01UL,
  75919. 0x6b6b51f4UL, 0x1c6c6162UL, 0x856530d8UL, 0xf262004eUL, 0x6c0695edUL,
  75920. 0x1b01a57bUL, 0x8208f4c1UL, 0xf50fc457UL, 0x65b0d9c6UL, 0x12b7e950UL,
  75921. 0x8bbeb8eaUL, 0xfcb9887cUL, 0x62dd1ddfUL, 0x15da2d49UL, 0x8cd37cf3UL,
  75922. 0xfbd44c65UL, 0x4db26158UL, 0x3ab551ceUL, 0xa3bc0074UL, 0xd4bb30e2UL,
  75923. 0x4adfa541UL, 0x3dd895d7UL, 0xa4d1c46dUL, 0xd3d6f4fbUL, 0x4369e96aUL,
  75924. 0x346ed9fcUL, 0xad678846UL, 0xda60b8d0UL, 0x44042d73UL, 0x33031de5UL,
  75925. 0xaa0a4c5fUL, 0xdd0d7cc9UL, 0x5005713cUL, 0x270241aaUL, 0xbe0b1010UL,
  75926. 0xc90c2086UL, 0x5768b525UL, 0x206f85b3UL, 0xb966d409UL, 0xce61e49fUL,
  75927. 0x5edef90eUL, 0x29d9c998UL, 0xb0d09822UL, 0xc7d7a8b4UL, 0x59b33d17UL,
  75928. 0x2eb40d81UL, 0xb7bd5c3bUL, 0xc0ba6cadUL, 0xedb88320UL, 0x9abfb3b6UL,
  75929. 0x03b6e20cUL, 0x74b1d29aUL, 0xead54739UL, 0x9dd277afUL, 0x04db2615UL,
  75930. 0x73dc1683UL, 0xe3630b12UL, 0x94643b84UL, 0x0d6d6a3eUL, 0x7a6a5aa8UL,
  75931. 0xe40ecf0bUL, 0x9309ff9dUL, 0x0a00ae27UL, 0x7d079eb1UL, 0xf00f9344UL,
  75932. 0x8708a3d2UL, 0x1e01f268UL, 0x6906c2feUL, 0xf762575dUL, 0x806567cbUL,
  75933. 0x196c3671UL, 0x6e6b06e7UL, 0xfed41b76UL, 0x89d32be0UL, 0x10da7a5aUL,
  75934. 0x67dd4accUL, 0xf9b9df6fUL, 0x8ebeeff9UL, 0x17b7be43UL, 0x60b08ed5UL,
  75935. 0xd6d6a3e8UL, 0xa1d1937eUL, 0x38d8c2c4UL, 0x4fdff252UL, 0xd1bb67f1UL,
  75936. 0xa6bc5767UL, 0x3fb506ddUL, 0x48b2364bUL, 0xd80d2bdaUL, 0xaf0a1b4cUL,
  75937. 0x36034af6UL, 0x41047a60UL, 0xdf60efc3UL, 0xa867df55UL, 0x316e8eefUL,
  75938. 0x4669be79UL, 0xcb61b38cUL, 0xbc66831aUL, 0x256fd2a0UL, 0x5268e236UL,
  75939. 0xcc0c7795UL, 0xbb0b4703UL, 0x220216b9UL, 0x5505262fUL, 0xc5ba3bbeUL,
  75940. 0xb2bd0b28UL, 0x2bb45a92UL, 0x5cb36a04UL, 0xc2d7ffa7UL, 0xb5d0cf31UL,
  75941. 0x2cd99e8bUL, 0x5bdeae1dUL, 0x9b64c2b0UL, 0xec63f226UL, 0x756aa39cUL,
  75942. 0x026d930aUL, 0x9c0906a9UL, 0xeb0e363fUL, 0x72076785UL, 0x05005713UL,
  75943. 0x95bf4a82UL, 0xe2b87a14UL, 0x7bb12baeUL, 0x0cb61b38UL, 0x92d28e9bUL,
  75944. 0xe5d5be0dUL, 0x7cdcefb7UL, 0x0bdbdf21UL, 0x86d3d2d4UL, 0xf1d4e242UL,
  75945. 0x68ddb3f8UL, 0x1fda836eUL, 0x81be16cdUL, 0xf6b9265bUL, 0x6fb077e1UL,
  75946. 0x18b74777UL, 0x88085ae6UL, 0xff0f6a70UL, 0x66063bcaUL, 0x11010b5cUL,
  75947. 0x8f659effUL, 0xf862ae69UL, 0x616bffd3UL, 0x166ccf45UL, 0xa00ae278UL,
  75948. 0xd70dd2eeUL, 0x4e048354UL, 0x3903b3c2UL, 0xa7672661UL, 0xd06016f7UL,
  75949. 0x4969474dUL, 0x3e6e77dbUL, 0xaed16a4aUL, 0xd9d65adcUL, 0x40df0b66UL,
  75950. 0x37d83bf0UL, 0xa9bcae53UL, 0xdebb9ec5UL, 0x47b2cf7fUL, 0x30b5ffe9UL,
  75951. 0xbdbdf21cUL, 0xcabac28aUL, 0x53b39330UL, 0x24b4a3a6UL, 0xbad03605UL,
  75952. 0xcdd70693UL, 0x54de5729UL, 0x23d967bfUL, 0xb3667a2eUL, 0xc4614ab8UL,
  75953. 0x5d681b02UL, 0x2a6f2b94UL, 0xb40bbe37UL, 0xc30c8ea1UL, 0x5a05df1bUL,
  75954. 0x2d02ef8dUL
  75955. #ifdef BYFOUR
  75956. },
  75957. {
  75958. 0x00000000UL, 0x191b3141UL, 0x32366282UL, 0x2b2d53c3UL, 0x646cc504UL,
  75959. 0x7d77f445UL, 0x565aa786UL, 0x4f4196c7UL, 0xc8d98a08UL, 0xd1c2bb49UL,
  75960. 0xfaefe88aUL, 0xe3f4d9cbUL, 0xacb54f0cUL, 0xb5ae7e4dUL, 0x9e832d8eUL,
  75961. 0x87981ccfUL, 0x4ac21251UL, 0x53d92310UL, 0x78f470d3UL, 0x61ef4192UL,
  75962. 0x2eaed755UL, 0x37b5e614UL, 0x1c98b5d7UL, 0x05838496UL, 0x821b9859UL,
  75963. 0x9b00a918UL, 0xb02dfadbUL, 0xa936cb9aUL, 0xe6775d5dUL, 0xff6c6c1cUL,
  75964. 0xd4413fdfUL, 0xcd5a0e9eUL, 0x958424a2UL, 0x8c9f15e3UL, 0xa7b24620UL,
  75965. 0xbea97761UL, 0xf1e8e1a6UL, 0xe8f3d0e7UL, 0xc3de8324UL, 0xdac5b265UL,
  75966. 0x5d5daeaaUL, 0x44469febUL, 0x6f6bcc28UL, 0x7670fd69UL, 0x39316baeUL,
  75967. 0x202a5aefUL, 0x0b07092cUL, 0x121c386dUL, 0xdf4636f3UL, 0xc65d07b2UL,
  75968. 0xed705471UL, 0xf46b6530UL, 0xbb2af3f7UL, 0xa231c2b6UL, 0x891c9175UL,
  75969. 0x9007a034UL, 0x179fbcfbUL, 0x0e848dbaUL, 0x25a9de79UL, 0x3cb2ef38UL,
  75970. 0x73f379ffUL, 0x6ae848beUL, 0x41c51b7dUL, 0x58de2a3cUL, 0xf0794f05UL,
  75971. 0xe9627e44UL, 0xc24f2d87UL, 0xdb541cc6UL, 0x94158a01UL, 0x8d0ebb40UL,
  75972. 0xa623e883UL, 0xbf38d9c2UL, 0x38a0c50dUL, 0x21bbf44cUL, 0x0a96a78fUL,
  75973. 0x138d96ceUL, 0x5ccc0009UL, 0x45d73148UL, 0x6efa628bUL, 0x77e153caUL,
  75974. 0xbabb5d54UL, 0xa3a06c15UL, 0x888d3fd6UL, 0x91960e97UL, 0xded79850UL,
  75975. 0xc7cca911UL, 0xece1fad2UL, 0xf5facb93UL, 0x7262d75cUL, 0x6b79e61dUL,
  75976. 0x4054b5deUL, 0x594f849fUL, 0x160e1258UL, 0x0f152319UL, 0x243870daUL,
  75977. 0x3d23419bUL, 0x65fd6ba7UL, 0x7ce65ae6UL, 0x57cb0925UL, 0x4ed03864UL,
  75978. 0x0191aea3UL, 0x188a9fe2UL, 0x33a7cc21UL, 0x2abcfd60UL, 0xad24e1afUL,
  75979. 0xb43fd0eeUL, 0x9f12832dUL, 0x8609b26cUL, 0xc94824abUL, 0xd05315eaUL,
  75980. 0xfb7e4629UL, 0xe2657768UL, 0x2f3f79f6UL, 0x362448b7UL, 0x1d091b74UL,
  75981. 0x04122a35UL, 0x4b53bcf2UL, 0x52488db3UL, 0x7965de70UL, 0x607eef31UL,
  75982. 0xe7e6f3feUL, 0xfefdc2bfUL, 0xd5d0917cUL, 0xcccba03dUL, 0x838a36faUL,
  75983. 0x9a9107bbUL, 0xb1bc5478UL, 0xa8a76539UL, 0x3b83984bUL, 0x2298a90aUL,
  75984. 0x09b5fac9UL, 0x10aecb88UL, 0x5fef5d4fUL, 0x46f46c0eUL, 0x6dd93fcdUL,
  75985. 0x74c20e8cUL, 0xf35a1243UL, 0xea412302UL, 0xc16c70c1UL, 0xd8774180UL,
  75986. 0x9736d747UL, 0x8e2de606UL, 0xa500b5c5UL, 0xbc1b8484UL, 0x71418a1aUL,
  75987. 0x685abb5bUL, 0x4377e898UL, 0x5a6cd9d9UL, 0x152d4f1eUL, 0x0c367e5fUL,
  75988. 0x271b2d9cUL, 0x3e001cddUL, 0xb9980012UL, 0xa0833153UL, 0x8bae6290UL,
  75989. 0x92b553d1UL, 0xddf4c516UL, 0xc4eff457UL, 0xefc2a794UL, 0xf6d996d5UL,
  75990. 0xae07bce9UL, 0xb71c8da8UL, 0x9c31de6bUL, 0x852aef2aUL, 0xca6b79edUL,
  75991. 0xd37048acUL, 0xf85d1b6fUL, 0xe1462a2eUL, 0x66de36e1UL, 0x7fc507a0UL,
  75992. 0x54e85463UL, 0x4df36522UL, 0x02b2f3e5UL, 0x1ba9c2a4UL, 0x30849167UL,
  75993. 0x299fa026UL, 0xe4c5aeb8UL, 0xfdde9ff9UL, 0xd6f3cc3aUL, 0xcfe8fd7bUL,
  75994. 0x80a96bbcUL, 0x99b25afdUL, 0xb29f093eUL, 0xab84387fUL, 0x2c1c24b0UL,
  75995. 0x350715f1UL, 0x1e2a4632UL, 0x07317773UL, 0x4870e1b4UL, 0x516bd0f5UL,
  75996. 0x7a468336UL, 0x635db277UL, 0xcbfad74eUL, 0xd2e1e60fUL, 0xf9ccb5ccUL,
  75997. 0xe0d7848dUL, 0xaf96124aUL, 0xb68d230bUL, 0x9da070c8UL, 0x84bb4189UL,
  75998. 0x03235d46UL, 0x1a386c07UL, 0x31153fc4UL, 0x280e0e85UL, 0x674f9842UL,
  75999. 0x7e54a903UL, 0x5579fac0UL, 0x4c62cb81UL, 0x8138c51fUL, 0x9823f45eUL,
  76000. 0xb30ea79dUL, 0xaa1596dcUL, 0xe554001bUL, 0xfc4f315aUL, 0xd7626299UL,
  76001. 0xce7953d8UL, 0x49e14f17UL, 0x50fa7e56UL, 0x7bd72d95UL, 0x62cc1cd4UL,
  76002. 0x2d8d8a13UL, 0x3496bb52UL, 0x1fbbe891UL, 0x06a0d9d0UL, 0x5e7ef3ecUL,
  76003. 0x4765c2adUL, 0x6c48916eUL, 0x7553a02fUL, 0x3a1236e8UL, 0x230907a9UL,
  76004. 0x0824546aUL, 0x113f652bUL, 0x96a779e4UL, 0x8fbc48a5UL, 0xa4911b66UL,
  76005. 0xbd8a2a27UL, 0xf2cbbce0UL, 0xebd08da1UL, 0xc0fdde62UL, 0xd9e6ef23UL,
  76006. 0x14bce1bdUL, 0x0da7d0fcUL, 0x268a833fUL, 0x3f91b27eUL, 0x70d024b9UL,
  76007. 0x69cb15f8UL, 0x42e6463bUL, 0x5bfd777aUL, 0xdc656bb5UL, 0xc57e5af4UL,
  76008. 0xee530937UL, 0xf7483876UL, 0xb809aeb1UL, 0xa1129ff0UL, 0x8a3fcc33UL,
  76009. 0x9324fd72UL
  76010. },
  76011. {
  76012. 0x00000000UL, 0x01c26a37UL, 0x0384d46eUL, 0x0246be59UL, 0x0709a8dcUL,
  76013. 0x06cbc2ebUL, 0x048d7cb2UL, 0x054f1685UL, 0x0e1351b8UL, 0x0fd13b8fUL,
  76014. 0x0d9785d6UL, 0x0c55efe1UL, 0x091af964UL, 0x08d89353UL, 0x0a9e2d0aUL,
  76015. 0x0b5c473dUL, 0x1c26a370UL, 0x1de4c947UL, 0x1fa2771eUL, 0x1e601d29UL,
  76016. 0x1b2f0bacUL, 0x1aed619bUL, 0x18abdfc2UL, 0x1969b5f5UL, 0x1235f2c8UL,
  76017. 0x13f798ffUL, 0x11b126a6UL, 0x10734c91UL, 0x153c5a14UL, 0x14fe3023UL,
  76018. 0x16b88e7aUL, 0x177ae44dUL, 0x384d46e0UL, 0x398f2cd7UL, 0x3bc9928eUL,
  76019. 0x3a0bf8b9UL, 0x3f44ee3cUL, 0x3e86840bUL, 0x3cc03a52UL, 0x3d025065UL,
  76020. 0x365e1758UL, 0x379c7d6fUL, 0x35dac336UL, 0x3418a901UL, 0x3157bf84UL,
  76021. 0x3095d5b3UL, 0x32d36beaUL, 0x331101ddUL, 0x246be590UL, 0x25a98fa7UL,
  76022. 0x27ef31feUL, 0x262d5bc9UL, 0x23624d4cUL, 0x22a0277bUL, 0x20e69922UL,
  76023. 0x2124f315UL, 0x2a78b428UL, 0x2bbade1fUL, 0x29fc6046UL, 0x283e0a71UL,
  76024. 0x2d711cf4UL, 0x2cb376c3UL, 0x2ef5c89aUL, 0x2f37a2adUL, 0x709a8dc0UL,
  76025. 0x7158e7f7UL, 0x731e59aeUL, 0x72dc3399UL, 0x7793251cUL, 0x76514f2bUL,
  76026. 0x7417f172UL, 0x75d59b45UL, 0x7e89dc78UL, 0x7f4bb64fUL, 0x7d0d0816UL,
  76027. 0x7ccf6221UL, 0x798074a4UL, 0x78421e93UL, 0x7a04a0caUL, 0x7bc6cafdUL,
  76028. 0x6cbc2eb0UL, 0x6d7e4487UL, 0x6f38fadeUL, 0x6efa90e9UL, 0x6bb5866cUL,
  76029. 0x6a77ec5bUL, 0x68315202UL, 0x69f33835UL, 0x62af7f08UL, 0x636d153fUL,
  76030. 0x612bab66UL, 0x60e9c151UL, 0x65a6d7d4UL, 0x6464bde3UL, 0x662203baUL,
  76031. 0x67e0698dUL, 0x48d7cb20UL, 0x4915a117UL, 0x4b531f4eUL, 0x4a917579UL,
  76032. 0x4fde63fcUL, 0x4e1c09cbUL, 0x4c5ab792UL, 0x4d98dda5UL, 0x46c49a98UL,
  76033. 0x4706f0afUL, 0x45404ef6UL, 0x448224c1UL, 0x41cd3244UL, 0x400f5873UL,
  76034. 0x4249e62aUL, 0x438b8c1dUL, 0x54f16850UL, 0x55330267UL, 0x5775bc3eUL,
  76035. 0x56b7d609UL, 0x53f8c08cUL, 0x523aaabbUL, 0x507c14e2UL, 0x51be7ed5UL,
  76036. 0x5ae239e8UL, 0x5b2053dfUL, 0x5966ed86UL, 0x58a487b1UL, 0x5deb9134UL,
  76037. 0x5c29fb03UL, 0x5e6f455aUL, 0x5fad2f6dUL, 0xe1351b80UL, 0xe0f771b7UL,
  76038. 0xe2b1cfeeUL, 0xe373a5d9UL, 0xe63cb35cUL, 0xe7fed96bUL, 0xe5b86732UL,
  76039. 0xe47a0d05UL, 0xef264a38UL, 0xeee4200fUL, 0xeca29e56UL, 0xed60f461UL,
  76040. 0xe82fe2e4UL, 0xe9ed88d3UL, 0xebab368aUL, 0xea695cbdUL, 0xfd13b8f0UL,
  76041. 0xfcd1d2c7UL, 0xfe976c9eUL, 0xff5506a9UL, 0xfa1a102cUL, 0xfbd87a1bUL,
  76042. 0xf99ec442UL, 0xf85cae75UL, 0xf300e948UL, 0xf2c2837fUL, 0xf0843d26UL,
  76043. 0xf1465711UL, 0xf4094194UL, 0xf5cb2ba3UL, 0xf78d95faUL, 0xf64fffcdUL,
  76044. 0xd9785d60UL, 0xd8ba3757UL, 0xdafc890eUL, 0xdb3ee339UL, 0xde71f5bcUL,
  76045. 0xdfb39f8bUL, 0xddf521d2UL, 0xdc374be5UL, 0xd76b0cd8UL, 0xd6a966efUL,
  76046. 0xd4efd8b6UL, 0xd52db281UL, 0xd062a404UL, 0xd1a0ce33UL, 0xd3e6706aUL,
  76047. 0xd2241a5dUL, 0xc55efe10UL, 0xc49c9427UL, 0xc6da2a7eUL, 0xc7184049UL,
  76048. 0xc25756ccUL, 0xc3953cfbUL, 0xc1d382a2UL, 0xc011e895UL, 0xcb4dafa8UL,
  76049. 0xca8fc59fUL, 0xc8c97bc6UL, 0xc90b11f1UL, 0xcc440774UL, 0xcd866d43UL,
  76050. 0xcfc0d31aUL, 0xce02b92dUL, 0x91af9640UL, 0x906dfc77UL, 0x922b422eUL,
  76051. 0x93e92819UL, 0x96a63e9cUL, 0x976454abUL, 0x9522eaf2UL, 0x94e080c5UL,
  76052. 0x9fbcc7f8UL, 0x9e7eadcfUL, 0x9c381396UL, 0x9dfa79a1UL, 0x98b56f24UL,
  76053. 0x99770513UL, 0x9b31bb4aUL, 0x9af3d17dUL, 0x8d893530UL, 0x8c4b5f07UL,
  76054. 0x8e0de15eUL, 0x8fcf8b69UL, 0x8a809decUL, 0x8b42f7dbUL, 0x89044982UL,
  76055. 0x88c623b5UL, 0x839a6488UL, 0x82580ebfUL, 0x801eb0e6UL, 0x81dcdad1UL,
  76056. 0x8493cc54UL, 0x8551a663UL, 0x8717183aUL, 0x86d5720dUL, 0xa9e2d0a0UL,
  76057. 0xa820ba97UL, 0xaa6604ceUL, 0xaba46ef9UL, 0xaeeb787cUL, 0xaf29124bUL,
  76058. 0xad6fac12UL, 0xacadc625UL, 0xa7f18118UL, 0xa633eb2fUL, 0xa4755576UL,
  76059. 0xa5b73f41UL, 0xa0f829c4UL, 0xa13a43f3UL, 0xa37cfdaaUL, 0xa2be979dUL,
  76060. 0xb5c473d0UL, 0xb40619e7UL, 0xb640a7beUL, 0xb782cd89UL, 0xb2cddb0cUL,
  76061. 0xb30fb13bUL, 0xb1490f62UL, 0xb08b6555UL, 0xbbd72268UL, 0xba15485fUL,
  76062. 0xb853f606UL, 0xb9919c31UL, 0xbcde8ab4UL, 0xbd1ce083UL, 0xbf5a5edaUL,
  76063. 0xbe9834edUL
  76064. },
  76065. {
  76066. 0x00000000UL, 0xb8bc6765UL, 0xaa09c88bUL, 0x12b5afeeUL, 0x8f629757UL,
  76067. 0x37def032UL, 0x256b5fdcUL, 0x9dd738b9UL, 0xc5b428efUL, 0x7d084f8aUL,
  76068. 0x6fbde064UL, 0xd7018701UL, 0x4ad6bfb8UL, 0xf26ad8ddUL, 0xe0df7733UL,
  76069. 0x58631056UL, 0x5019579fUL, 0xe8a530faUL, 0xfa109f14UL, 0x42acf871UL,
  76070. 0xdf7bc0c8UL, 0x67c7a7adUL, 0x75720843UL, 0xcdce6f26UL, 0x95ad7f70UL,
  76071. 0x2d111815UL, 0x3fa4b7fbUL, 0x8718d09eUL, 0x1acfe827UL, 0xa2738f42UL,
  76072. 0xb0c620acUL, 0x087a47c9UL, 0xa032af3eUL, 0x188ec85bUL, 0x0a3b67b5UL,
  76073. 0xb28700d0UL, 0x2f503869UL, 0x97ec5f0cUL, 0x8559f0e2UL, 0x3de59787UL,
  76074. 0x658687d1UL, 0xdd3ae0b4UL, 0xcf8f4f5aUL, 0x7733283fUL, 0xeae41086UL,
  76075. 0x525877e3UL, 0x40edd80dUL, 0xf851bf68UL, 0xf02bf8a1UL, 0x48979fc4UL,
  76076. 0x5a22302aUL, 0xe29e574fUL, 0x7f496ff6UL, 0xc7f50893UL, 0xd540a77dUL,
  76077. 0x6dfcc018UL, 0x359fd04eUL, 0x8d23b72bUL, 0x9f9618c5UL, 0x272a7fa0UL,
  76078. 0xbafd4719UL, 0x0241207cUL, 0x10f48f92UL, 0xa848e8f7UL, 0x9b14583dUL,
  76079. 0x23a83f58UL, 0x311d90b6UL, 0x89a1f7d3UL, 0x1476cf6aUL, 0xaccaa80fUL,
  76080. 0xbe7f07e1UL, 0x06c36084UL, 0x5ea070d2UL, 0xe61c17b7UL, 0xf4a9b859UL,
  76081. 0x4c15df3cUL, 0xd1c2e785UL, 0x697e80e0UL, 0x7bcb2f0eUL, 0xc377486bUL,
  76082. 0xcb0d0fa2UL, 0x73b168c7UL, 0x6104c729UL, 0xd9b8a04cUL, 0x446f98f5UL,
  76083. 0xfcd3ff90UL, 0xee66507eUL, 0x56da371bUL, 0x0eb9274dUL, 0xb6054028UL,
  76084. 0xa4b0efc6UL, 0x1c0c88a3UL, 0x81dbb01aUL, 0x3967d77fUL, 0x2bd27891UL,
  76085. 0x936e1ff4UL, 0x3b26f703UL, 0x839a9066UL, 0x912f3f88UL, 0x299358edUL,
  76086. 0xb4446054UL, 0x0cf80731UL, 0x1e4da8dfUL, 0xa6f1cfbaUL, 0xfe92dfecUL,
  76087. 0x462eb889UL, 0x549b1767UL, 0xec277002UL, 0x71f048bbUL, 0xc94c2fdeUL,
  76088. 0xdbf98030UL, 0x6345e755UL, 0x6b3fa09cUL, 0xd383c7f9UL, 0xc1366817UL,
  76089. 0x798a0f72UL, 0xe45d37cbUL, 0x5ce150aeUL, 0x4e54ff40UL, 0xf6e89825UL,
  76090. 0xae8b8873UL, 0x1637ef16UL, 0x048240f8UL, 0xbc3e279dUL, 0x21e91f24UL,
  76091. 0x99557841UL, 0x8be0d7afUL, 0x335cb0caUL, 0xed59b63bUL, 0x55e5d15eUL,
  76092. 0x47507eb0UL, 0xffec19d5UL, 0x623b216cUL, 0xda874609UL, 0xc832e9e7UL,
  76093. 0x708e8e82UL, 0x28ed9ed4UL, 0x9051f9b1UL, 0x82e4565fUL, 0x3a58313aUL,
  76094. 0xa78f0983UL, 0x1f336ee6UL, 0x0d86c108UL, 0xb53aa66dUL, 0xbd40e1a4UL,
  76095. 0x05fc86c1UL, 0x1749292fUL, 0xaff54e4aUL, 0x322276f3UL, 0x8a9e1196UL,
  76096. 0x982bbe78UL, 0x2097d91dUL, 0x78f4c94bUL, 0xc048ae2eUL, 0xd2fd01c0UL,
  76097. 0x6a4166a5UL, 0xf7965e1cUL, 0x4f2a3979UL, 0x5d9f9697UL, 0xe523f1f2UL,
  76098. 0x4d6b1905UL, 0xf5d77e60UL, 0xe762d18eUL, 0x5fdeb6ebUL, 0xc2098e52UL,
  76099. 0x7ab5e937UL, 0x680046d9UL, 0xd0bc21bcUL, 0x88df31eaUL, 0x3063568fUL,
  76100. 0x22d6f961UL, 0x9a6a9e04UL, 0x07bda6bdUL, 0xbf01c1d8UL, 0xadb46e36UL,
  76101. 0x15080953UL, 0x1d724e9aUL, 0xa5ce29ffUL, 0xb77b8611UL, 0x0fc7e174UL,
  76102. 0x9210d9cdUL, 0x2aacbea8UL, 0x38191146UL, 0x80a57623UL, 0xd8c66675UL,
  76103. 0x607a0110UL, 0x72cfaefeUL, 0xca73c99bUL, 0x57a4f122UL, 0xef189647UL,
  76104. 0xfdad39a9UL, 0x45115eccUL, 0x764dee06UL, 0xcef18963UL, 0xdc44268dUL,
  76105. 0x64f841e8UL, 0xf92f7951UL, 0x41931e34UL, 0x5326b1daUL, 0xeb9ad6bfUL,
  76106. 0xb3f9c6e9UL, 0x0b45a18cUL, 0x19f00e62UL, 0xa14c6907UL, 0x3c9b51beUL,
  76107. 0x842736dbUL, 0x96929935UL, 0x2e2efe50UL, 0x2654b999UL, 0x9ee8defcUL,
  76108. 0x8c5d7112UL, 0x34e11677UL, 0xa9362eceUL, 0x118a49abUL, 0x033fe645UL,
  76109. 0xbb838120UL, 0xe3e09176UL, 0x5b5cf613UL, 0x49e959fdUL, 0xf1553e98UL,
  76110. 0x6c820621UL, 0xd43e6144UL, 0xc68bceaaUL, 0x7e37a9cfUL, 0xd67f4138UL,
  76111. 0x6ec3265dUL, 0x7c7689b3UL, 0xc4caeed6UL, 0x591dd66fUL, 0xe1a1b10aUL,
  76112. 0xf3141ee4UL, 0x4ba87981UL, 0x13cb69d7UL, 0xab770eb2UL, 0xb9c2a15cUL,
  76113. 0x017ec639UL, 0x9ca9fe80UL, 0x241599e5UL, 0x36a0360bUL, 0x8e1c516eUL,
  76114. 0x866616a7UL, 0x3eda71c2UL, 0x2c6fde2cUL, 0x94d3b949UL, 0x090481f0UL,
  76115. 0xb1b8e695UL, 0xa30d497bUL, 0x1bb12e1eUL, 0x43d23e48UL, 0xfb6e592dUL,
  76116. 0xe9dbf6c3UL, 0x516791a6UL, 0xccb0a91fUL, 0x740cce7aUL, 0x66b96194UL,
  76117. 0xde0506f1UL
  76118. },
  76119. {
  76120. 0x00000000UL, 0x96300777UL, 0x2c610eeeUL, 0xba510999UL, 0x19c46d07UL,
  76121. 0x8ff46a70UL, 0x35a563e9UL, 0xa395649eUL, 0x3288db0eUL, 0xa4b8dc79UL,
  76122. 0x1ee9d5e0UL, 0x88d9d297UL, 0x2b4cb609UL, 0xbd7cb17eUL, 0x072db8e7UL,
  76123. 0x911dbf90UL, 0x6410b71dUL, 0xf220b06aUL, 0x4871b9f3UL, 0xde41be84UL,
  76124. 0x7dd4da1aUL, 0xebe4dd6dUL, 0x51b5d4f4UL, 0xc785d383UL, 0x56986c13UL,
  76125. 0xc0a86b64UL, 0x7af962fdUL, 0xecc9658aUL, 0x4f5c0114UL, 0xd96c0663UL,
  76126. 0x633d0ffaUL, 0xf50d088dUL, 0xc8206e3bUL, 0x5e10694cUL, 0xe44160d5UL,
  76127. 0x727167a2UL, 0xd1e4033cUL, 0x47d4044bUL, 0xfd850dd2UL, 0x6bb50aa5UL,
  76128. 0xfaa8b535UL, 0x6c98b242UL, 0xd6c9bbdbUL, 0x40f9bcacUL, 0xe36cd832UL,
  76129. 0x755cdf45UL, 0xcf0dd6dcUL, 0x593dd1abUL, 0xac30d926UL, 0x3a00de51UL,
  76130. 0x8051d7c8UL, 0x1661d0bfUL, 0xb5f4b421UL, 0x23c4b356UL, 0x9995bacfUL,
  76131. 0x0fa5bdb8UL, 0x9eb80228UL, 0x0888055fUL, 0xb2d90cc6UL, 0x24e90bb1UL,
  76132. 0x877c6f2fUL, 0x114c6858UL, 0xab1d61c1UL, 0x3d2d66b6UL, 0x9041dc76UL,
  76133. 0x0671db01UL, 0xbc20d298UL, 0x2a10d5efUL, 0x8985b171UL, 0x1fb5b606UL,
  76134. 0xa5e4bf9fUL, 0x33d4b8e8UL, 0xa2c90778UL, 0x34f9000fUL, 0x8ea80996UL,
  76135. 0x18980ee1UL, 0xbb0d6a7fUL, 0x2d3d6d08UL, 0x976c6491UL, 0x015c63e6UL,
  76136. 0xf4516b6bUL, 0x62616c1cUL, 0xd8306585UL, 0x4e0062f2UL, 0xed95066cUL,
  76137. 0x7ba5011bUL, 0xc1f40882UL, 0x57c40ff5UL, 0xc6d9b065UL, 0x50e9b712UL,
  76138. 0xeab8be8bUL, 0x7c88b9fcUL, 0xdf1ddd62UL, 0x492dda15UL, 0xf37cd38cUL,
  76139. 0x654cd4fbUL, 0x5861b24dUL, 0xce51b53aUL, 0x7400bca3UL, 0xe230bbd4UL,
  76140. 0x41a5df4aUL, 0xd795d83dUL, 0x6dc4d1a4UL, 0xfbf4d6d3UL, 0x6ae96943UL,
  76141. 0xfcd96e34UL, 0x468867adUL, 0xd0b860daUL, 0x732d0444UL, 0xe51d0333UL,
  76142. 0x5f4c0aaaUL, 0xc97c0dddUL, 0x3c710550UL, 0xaa410227UL, 0x10100bbeUL,
  76143. 0x86200cc9UL, 0x25b56857UL, 0xb3856f20UL, 0x09d466b9UL, 0x9fe461ceUL,
  76144. 0x0ef9de5eUL, 0x98c9d929UL, 0x2298d0b0UL, 0xb4a8d7c7UL, 0x173db359UL,
  76145. 0x810db42eUL, 0x3b5cbdb7UL, 0xad6cbac0UL, 0x2083b8edUL, 0xb6b3bf9aUL,
  76146. 0x0ce2b603UL, 0x9ad2b174UL, 0x3947d5eaUL, 0xaf77d29dUL, 0x1526db04UL,
  76147. 0x8316dc73UL, 0x120b63e3UL, 0x843b6494UL, 0x3e6a6d0dUL, 0xa85a6a7aUL,
  76148. 0x0bcf0ee4UL, 0x9dff0993UL, 0x27ae000aUL, 0xb19e077dUL, 0x44930ff0UL,
  76149. 0xd2a30887UL, 0x68f2011eUL, 0xfec20669UL, 0x5d5762f7UL, 0xcb676580UL,
  76150. 0x71366c19UL, 0xe7066b6eUL, 0x761bd4feUL, 0xe02bd389UL, 0x5a7ada10UL,
  76151. 0xcc4add67UL, 0x6fdfb9f9UL, 0xf9efbe8eUL, 0x43beb717UL, 0xd58eb060UL,
  76152. 0xe8a3d6d6UL, 0x7e93d1a1UL, 0xc4c2d838UL, 0x52f2df4fUL, 0xf167bbd1UL,
  76153. 0x6757bca6UL, 0xdd06b53fUL, 0x4b36b248UL, 0xda2b0dd8UL, 0x4c1b0aafUL,
  76154. 0xf64a0336UL, 0x607a0441UL, 0xc3ef60dfUL, 0x55df67a8UL, 0xef8e6e31UL,
  76155. 0x79be6946UL, 0x8cb361cbUL, 0x1a8366bcUL, 0xa0d26f25UL, 0x36e26852UL,
  76156. 0x95770cccUL, 0x03470bbbUL, 0xb9160222UL, 0x2f260555UL, 0xbe3bbac5UL,
  76157. 0x280bbdb2UL, 0x925ab42bUL, 0x046ab35cUL, 0xa7ffd7c2UL, 0x31cfd0b5UL,
  76158. 0x8b9ed92cUL, 0x1daede5bUL, 0xb0c2649bUL, 0x26f263ecUL, 0x9ca36a75UL,
  76159. 0x0a936d02UL, 0xa906099cUL, 0x3f360eebUL, 0x85670772UL, 0x13570005UL,
  76160. 0x824abf95UL, 0x147ab8e2UL, 0xae2bb17bUL, 0x381bb60cUL, 0x9b8ed292UL,
  76161. 0x0dbed5e5UL, 0xb7efdc7cUL, 0x21dfdb0bUL, 0xd4d2d386UL, 0x42e2d4f1UL,
  76162. 0xf8b3dd68UL, 0x6e83da1fUL, 0xcd16be81UL, 0x5b26b9f6UL, 0xe177b06fUL,
  76163. 0x7747b718UL, 0xe65a0888UL, 0x706a0fffUL, 0xca3b0666UL, 0x5c0b0111UL,
  76164. 0xff9e658fUL, 0x69ae62f8UL, 0xd3ff6b61UL, 0x45cf6c16UL, 0x78e20aa0UL,
  76165. 0xeed20dd7UL, 0x5483044eUL, 0xc2b30339UL, 0x612667a7UL, 0xf71660d0UL,
  76166. 0x4d476949UL, 0xdb776e3eUL, 0x4a6ad1aeUL, 0xdc5ad6d9UL, 0x660bdf40UL,
  76167. 0xf03bd837UL, 0x53aebca9UL, 0xc59ebbdeUL, 0x7fcfb247UL, 0xe9ffb530UL,
  76168. 0x1cf2bdbdUL, 0x8ac2bacaUL, 0x3093b353UL, 0xa6a3b424UL, 0x0536d0baUL,
  76169. 0x9306d7cdUL, 0x2957de54UL, 0xbf67d923UL, 0x2e7a66b3UL, 0xb84a61c4UL,
  76170. 0x021b685dUL, 0x942b6f2aUL, 0x37be0bb4UL, 0xa18e0cc3UL, 0x1bdf055aUL,
  76171. 0x8def022dUL
  76172. },
  76173. {
  76174. 0x00000000UL, 0x41311b19UL, 0x82623632UL, 0xc3532d2bUL, 0x04c56c64UL,
  76175. 0x45f4777dUL, 0x86a75a56UL, 0xc796414fUL, 0x088ad9c8UL, 0x49bbc2d1UL,
  76176. 0x8ae8effaUL, 0xcbd9f4e3UL, 0x0c4fb5acUL, 0x4d7eaeb5UL, 0x8e2d839eUL,
  76177. 0xcf1c9887UL, 0x5112c24aUL, 0x1023d953UL, 0xd370f478UL, 0x9241ef61UL,
  76178. 0x55d7ae2eUL, 0x14e6b537UL, 0xd7b5981cUL, 0x96848305UL, 0x59981b82UL,
  76179. 0x18a9009bUL, 0xdbfa2db0UL, 0x9acb36a9UL, 0x5d5d77e6UL, 0x1c6c6cffUL,
  76180. 0xdf3f41d4UL, 0x9e0e5acdUL, 0xa2248495UL, 0xe3159f8cUL, 0x2046b2a7UL,
  76181. 0x6177a9beUL, 0xa6e1e8f1UL, 0xe7d0f3e8UL, 0x2483dec3UL, 0x65b2c5daUL,
  76182. 0xaaae5d5dUL, 0xeb9f4644UL, 0x28cc6b6fUL, 0x69fd7076UL, 0xae6b3139UL,
  76183. 0xef5a2a20UL, 0x2c09070bUL, 0x6d381c12UL, 0xf33646dfUL, 0xb2075dc6UL,
  76184. 0x715470edUL, 0x30656bf4UL, 0xf7f32abbUL, 0xb6c231a2UL, 0x75911c89UL,
  76185. 0x34a00790UL, 0xfbbc9f17UL, 0xba8d840eUL, 0x79dea925UL, 0x38efb23cUL,
  76186. 0xff79f373UL, 0xbe48e86aUL, 0x7d1bc541UL, 0x3c2ade58UL, 0x054f79f0UL,
  76187. 0x447e62e9UL, 0x872d4fc2UL, 0xc61c54dbUL, 0x018a1594UL, 0x40bb0e8dUL,
  76188. 0x83e823a6UL, 0xc2d938bfUL, 0x0dc5a038UL, 0x4cf4bb21UL, 0x8fa7960aUL,
  76189. 0xce968d13UL, 0x0900cc5cUL, 0x4831d745UL, 0x8b62fa6eUL, 0xca53e177UL,
  76190. 0x545dbbbaUL, 0x156ca0a3UL, 0xd63f8d88UL, 0x970e9691UL, 0x5098d7deUL,
  76191. 0x11a9ccc7UL, 0xd2fae1ecUL, 0x93cbfaf5UL, 0x5cd76272UL, 0x1de6796bUL,
  76192. 0xdeb55440UL, 0x9f844f59UL, 0x58120e16UL, 0x1923150fUL, 0xda703824UL,
  76193. 0x9b41233dUL, 0xa76bfd65UL, 0xe65ae67cUL, 0x2509cb57UL, 0x6438d04eUL,
  76194. 0xa3ae9101UL, 0xe29f8a18UL, 0x21cca733UL, 0x60fdbc2aUL, 0xafe124adUL,
  76195. 0xeed03fb4UL, 0x2d83129fUL, 0x6cb20986UL, 0xab2448c9UL, 0xea1553d0UL,
  76196. 0x29467efbUL, 0x687765e2UL, 0xf6793f2fUL, 0xb7482436UL, 0x741b091dUL,
  76197. 0x352a1204UL, 0xf2bc534bUL, 0xb38d4852UL, 0x70de6579UL, 0x31ef7e60UL,
  76198. 0xfef3e6e7UL, 0xbfc2fdfeUL, 0x7c91d0d5UL, 0x3da0cbccUL, 0xfa368a83UL,
  76199. 0xbb07919aUL, 0x7854bcb1UL, 0x3965a7a8UL, 0x4b98833bUL, 0x0aa99822UL,
  76200. 0xc9fab509UL, 0x88cbae10UL, 0x4f5def5fUL, 0x0e6cf446UL, 0xcd3fd96dUL,
  76201. 0x8c0ec274UL, 0x43125af3UL, 0x022341eaUL, 0xc1706cc1UL, 0x804177d8UL,
  76202. 0x47d73697UL, 0x06e62d8eUL, 0xc5b500a5UL, 0x84841bbcUL, 0x1a8a4171UL,
  76203. 0x5bbb5a68UL, 0x98e87743UL, 0xd9d96c5aUL, 0x1e4f2d15UL, 0x5f7e360cUL,
  76204. 0x9c2d1b27UL, 0xdd1c003eUL, 0x120098b9UL, 0x533183a0UL, 0x9062ae8bUL,
  76205. 0xd153b592UL, 0x16c5f4ddUL, 0x57f4efc4UL, 0x94a7c2efUL, 0xd596d9f6UL,
  76206. 0xe9bc07aeUL, 0xa88d1cb7UL, 0x6bde319cUL, 0x2aef2a85UL, 0xed796bcaUL,
  76207. 0xac4870d3UL, 0x6f1b5df8UL, 0x2e2a46e1UL, 0xe136de66UL, 0xa007c57fUL,
  76208. 0x6354e854UL, 0x2265f34dUL, 0xe5f3b202UL, 0xa4c2a91bUL, 0x67918430UL,
  76209. 0x26a09f29UL, 0xb8aec5e4UL, 0xf99fdefdUL, 0x3accf3d6UL, 0x7bfde8cfUL,
  76210. 0xbc6ba980UL, 0xfd5ab299UL, 0x3e099fb2UL, 0x7f3884abUL, 0xb0241c2cUL,
  76211. 0xf1150735UL, 0x32462a1eUL, 0x73773107UL, 0xb4e17048UL, 0xf5d06b51UL,
  76212. 0x3683467aUL, 0x77b25d63UL, 0x4ed7facbUL, 0x0fe6e1d2UL, 0xccb5ccf9UL,
  76213. 0x8d84d7e0UL, 0x4a1296afUL, 0x0b238db6UL, 0xc870a09dUL, 0x8941bb84UL,
  76214. 0x465d2303UL, 0x076c381aUL, 0xc43f1531UL, 0x850e0e28UL, 0x42984f67UL,
  76215. 0x03a9547eUL, 0xc0fa7955UL, 0x81cb624cUL, 0x1fc53881UL, 0x5ef42398UL,
  76216. 0x9da70eb3UL, 0xdc9615aaUL, 0x1b0054e5UL, 0x5a314ffcUL, 0x996262d7UL,
  76217. 0xd85379ceUL, 0x174fe149UL, 0x567efa50UL, 0x952dd77bUL, 0xd41ccc62UL,
  76218. 0x138a8d2dUL, 0x52bb9634UL, 0x91e8bb1fUL, 0xd0d9a006UL, 0xecf37e5eUL,
  76219. 0xadc26547UL, 0x6e91486cUL, 0x2fa05375UL, 0xe836123aUL, 0xa9070923UL,
  76220. 0x6a542408UL, 0x2b653f11UL, 0xe479a796UL, 0xa548bc8fUL, 0x661b91a4UL,
  76221. 0x272a8abdUL, 0xe0bccbf2UL, 0xa18dd0ebUL, 0x62defdc0UL, 0x23efe6d9UL,
  76222. 0xbde1bc14UL, 0xfcd0a70dUL, 0x3f838a26UL, 0x7eb2913fUL, 0xb924d070UL,
  76223. 0xf815cb69UL, 0x3b46e642UL, 0x7a77fd5bUL, 0xb56b65dcUL, 0xf45a7ec5UL,
  76224. 0x370953eeUL, 0x763848f7UL, 0xb1ae09b8UL, 0xf09f12a1UL, 0x33cc3f8aUL,
  76225. 0x72fd2493UL
  76226. },
  76227. {
  76228. 0x00000000UL, 0x376ac201UL, 0x6ed48403UL, 0x59be4602UL, 0xdca80907UL,
  76229. 0xebc2cb06UL, 0xb27c8d04UL, 0x85164f05UL, 0xb851130eUL, 0x8f3bd10fUL,
  76230. 0xd685970dUL, 0xe1ef550cUL, 0x64f91a09UL, 0x5393d808UL, 0x0a2d9e0aUL,
  76231. 0x3d475c0bUL, 0x70a3261cUL, 0x47c9e41dUL, 0x1e77a21fUL, 0x291d601eUL,
  76232. 0xac0b2f1bUL, 0x9b61ed1aUL, 0xc2dfab18UL, 0xf5b56919UL, 0xc8f23512UL,
  76233. 0xff98f713UL, 0xa626b111UL, 0x914c7310UL, 0x145a3c15UL, 0x2330fe14UL,
  76234. 0x7a8eb816UL, 0x4de47a17UL, 0xe0464d38UL, 0xd72c8f39UL, 0x8e92c93bUL,
  76235. 0xb9f80b3aUL, 0x3cee443fUL, 0x0b84863eUL, 0x523ac03cUL, 0x6550023dUL,
  76236. 0x58175e36UL, 0x6f7d9c37UL, 0x36c3da35UL, 0x01a91834UL, 0x84bf5731UL,
  76237. 0xb3d59530UL, 0xea6bd332UL, 0xdd011133UL, 0x90e56b24UL, 0xa78fa925UL,
  76238. 0xfe31ef27UL, 0xc95b2d26UL, 0x4c4d6223UL, 0x7b27a022UL, 0x2299e620UL,
  76239. 0x15f32421UL, 0x28b4782aUL, 0x1fdeba2bUL, 0x4660fc29UL, 0x710a3e28UL,
  76240. 0xf41c712dUL, 0xc376b32cUL, 0x9ac8f52eUL, 0xada2372fUL, 0xc08d9a70UL,
  76241. 0xf7e75871UL, 0xae591e73UL, 0x9933dc72UL, 0x1c259377UL, 0x2b4f5176UL,
  76242. 0x72f11774UL, 0x459bd575UL, 0x78dc897eUL, 0x4fb64b7fUL, 0x16080d7dUL,
  76243. 0x2162cf7cUL, 0xa4748079UL, 0x931e4278UL, 0xcaa0047aUL, 0xfdcac67bUL,
  76244. 0xb02ebc6cUL, 0x87447e6dUL, 0xdefa386fUL, 0xe990fa6eUL, 0x6c86b56bUL,
  76245. 0x5bec776aUL, 0x02523168UL, 0x3538f369UL, 0x087faf62UL, 0x3f156d63UL,
  76246. 0x66ab2b61UL, 0x51c1e960UL, 0xd4d7a665UL, 0xe3bd6464UL, 0xba032266UL,
  76247. 0x8d69e067UL, 0x20cbd748UL, 0x17a11549UL, 0x4e1f534bUL, 0x7975914aUL,
  76248. 0xfc63de4fUL, 0xcb091c4eUL, 0x92b75a4cUL, 0xa5dd984dUL, 0x989ac446UL,
  76249. 0xaff00647UL, 0xf64e4045UL, 0xc1248244UL, 0x4432cd41UL, 0x73580f40UL,
  76250. 0x2ae64942UL, 0x1d8c8b43UL, 0x5068f154UL, 0x67023355UL, 0x3ebc7557UL,
  76251. 0x09d6b756UL, 0x8cc0f853UL, 0xbbaa3a52UL, 0xe2147c50UL, 0xd57ebe51UL,
  76252. 0xe839e25aUL, 0xdf53205bUL, 0x86ed6659UL, 0xb187a458UL, 0x3491eb5dUL,
  76253. 0x03fb295cUL, 0x5a456f5eUL, 0x6d2fad5fUL, 0x801b35e1UL, 0xb771f7e0UL,
  76254. 0xeecfb1e2UL, 0xd9a573e3UL, 0x5cb33ce6UL, 0x6bd9fee7UL, 0x3267b8e5UL,
  76255. 0x050d7ae4UL, 0x384a26efUL, 0x0f20e4eeUL, 0x569ea2ecUL, 0x61f460edUL,
  76256. 0xe4e22fe8UL, 0xd388ede9UL, 0x8a36abebUL, 0xbd5c69eaUL, 0xf0b813fdUL,
  76257. 0xc7d2d1fcUL, 0x9e6c97feUL, 0xa90655ffUL, 0x2c101afaUL, 0x1b7ad8fbUL,
  76258. 0x42c49ef9UL, 0x75ae5cf8UL, 0x48e900f3UL, 0x7f83c2f2UL, 0x263d84f0UL,
  76259. 0x115746f1UL, 0x944109f4UL, 0xa32bcbf5UL, 0xfa958df7UL, 0xcdff4ff6UL,
  76260. 0x605d78d9UL, 0x5737bad8UL, 0x0e89fcdaUL, 0x39e33edbUL, 0xbcf571deUL,
  76261. 0x8b9fb3dfUL, 0xd221f5ddUL, 0xe54b37dcUL, 0xd80c6bd7UL, 0xef66a9d6UL,
  76262. 0xb6d8efd4UL, 0x81b22dd5UL, 0x04a462d0UL, 0x33cea0d1UL, 0x6a70e6d3UL,
  76263. 0x5d1a24d2UL, 0x10fe5ec5UL, 0x27949cc4UL, 0x7e2adac6UL, 0x494018c7UL,
  76264. 0xcc5657c2UL, 0xfb3c95c3UL, 0xa282d3c1UL, 0x95e811c0UL, 0xa8af4dcbUL,
  76265. 0x9fc58fcaUL, 0xc67bc9c8UL, 0xf1110bc9UL, 0x740744ccUL, 0x436d86cdUL,
  76266. 0x1ad3c0cfUL, 0x2db902ceUL, 0x4096af91UL, 0x77fc6d90UL, 0x2e422b92UL,
  76267. 0x1928e993UL, 0x9c3ea696UL, 0xab546497UL, 0xf2ea2295UL, 0xc580e094UL,
  76268. 0xf8c7bc9fUL, 0xcfad7e9eUL, 0x9613389cUL, 0xa179fa9dUL, 0x246fb598UL,
  76269. 0x13057799UL, 0x4abb319bUL, 0x7dd1f39aUL, 0x3035898dUL, 0x075f4b8cUL,
  76270. 0x5ee10d8eUL, 0x698bcf8fUL, 0xec9d808aUL, 0xdbf7428bUL, 0x82490489UL,
  76271. 0xb523c688UL, 0x88649a83UL, 0xbf0e5882UL, 0xe6b01e80UL, 0xd1dadc81UL,
  76272. 0x54cc9384UL, 0x63a65185UL, 0x3a181787UL, 0x0d72d586UL, 0xa0d0e2a9UL,
  76273. 0x97ba20a8UL, 0xce0466aaUL, 0xf96ea4abUL, 0x7c78ebaeUL, 0x4b1229afUL,
  76274. 0x12ac6fadUL, 0x25c6adacUL, 0x1881f1a7UL, 0x2feb33a6UL, 0x765575a4UL,
  76275. 0x413fb7a5UL, 0xc429f8a0UL, 0xf3433aa1UL, 0xaafd7ca3UL, 0x9d97bea2UL,
  76276. 0xd073c4b5UL, 0xe71906b4UL, 0xbea740b6UL, 0x89cd82b7UL, 0x0cdbcdb2UL,
  76277. 0x3bb10fb3UL, 0x620f49b1UL, 0x55658bb0UL, 0x6822d7bbUL, 0x5f4815baUL,
  76278. 0x06f653b8UL, 0x319c91b9UL, 0xb48adebcUL, 0x83e01cbdUL, 0xda5e5abfUL,
  76279. 0xed3498beUL
  76280. },
  76281. {
  76282. 0x00000000UL, 0x6567bcb8UL, 0x8bc809aaUL, 0xeeafb512UL, 0x5797628fUL,
  76283. 0x32f0de37UL, 0xdc5f6b25UL, 0xb938d79dUL, 0xef28b4c5UL, 0x8a4f087dUL,
  76284. 0x64e0bd6fUL, 0x018701d7UL, 0xb8bfd64aUL, 0xddd86af2UL, 0x3377dfe0UL,
  76285. 0x56106358UL, 0x9f571950UL, 0xfa30a5e8UL, 0x149f10faUL, 0x71f8ac42UL,
  76286. 0xc8c07bdfUL, 0xada7c767UL, 0x43087275UL, 0x266fcecdUL, 0x707fad95UL,
  76287. 0x1518112dUL, 0xfbb7a43fUL, 0x9ed01887UL, 0x27e8cf1aUL, 0x428f73a2UL,
  76288. 0xac20c6b0UL, 0xc9477a08UL, 0x3eaf32a0UL, 0x5bc88e18UL, 0xb5673b0aUL,
  76289. 0xd00087b2UL, 0x6938502fUL, 0x0c5fec97UL, 0xe2f05985UL, 0x8797e53dUL,
  76290. 0xd1878665UL, 0xb4e03addUL, 0x5a4f8fcfUL, 0x3f283377UL, 0x8610e4eaUL,
  76291. 0xe3775852UL, 0x0dd8ed40UL, 0x68bf51f8UL, 0xa1f82bf0UL, 0xc49f9748UL,
  76292. 0x2a30225aUL, 0x4f579ee2UL, 0xf66f497fUL, 0x9308f5c7UL, 0x7da740d5UL,
  76293. 0x18c0fc6dUL, 0x4ed09f35UL, 0x2bb7238dUL, 0xc518969fUL, 0xa07f2a27UL,
  76294. 0x1947fdbaUL, 0x7c204102UL, 0x928ff410UL, 0xf7e848a8UL, 0x3d58149bUL,
  76295. 0x583fa823UL, 0xb6901d31UL, 0xd3f7a189UL, 0x6acf7614UL, 0x0fa8caacUL,
  76296. 0xe1077fbeUL, 0x8460c306UL, 0xd270a05eUL, 0xb7171ce6UL, 0x59b8a9f4UL,
  76297. 0x3cdf154cUL, 0x85e7c2d1UL, 0xe0807e69UL, 0x0e2fcb7bUL, 0x6b4877c3UL,
  76298. 0xa20f0dcbUL, 0xc768b173UL, 0x29c70461UL, 0x4ca0b8d9UL, 0xf5986f44UL,
  76299. 0x90ffd3fcUL, 0x7e5066eeUL, 0x1b37da56UL, 0x4d27b90eUL, 0x284005b6UL,
  76300. 0xc6efb0a4UL, 0xa3880c1cUL, 0x1ab0db81UL, 0x7fd76739UL, 0x9178d22bUL,
  76301. 0xf41f6e93UL, 0x03f7263bUL, 0x66909a83UL, 0x883f2f91UL, 0xed589329UL,
  76302. 0x546044b4UL, 0x3107f80cUL, 0xdfa84d1eUL, 0xbacff1a6UL, 0xecdf92feUL,
  76303. 0x89b82e46UL, 0x67179b54UL, 0x027027ecUL, 0xbb48f071UL, 0xde2f4cc9UL,
  76304. 0x3080f9dbUL, 0x55e74563UL, 0x9ca03f6bUL, 0xf9c783d3UL, 0x176836c1UL,
  76305. 0x720f8a79UL, 0xcb375de4UL, 0xae50e15cUL, 0x40ff544eUL, 0x2598e8f6UL,
  76306. 0x73888baeUL, 0x16ef3716UL, 0xf8408204UL, 0x9d273ebcUL, 0x241fe921UL,
  76307. 0x41785599UL, 0xafd7e08bUL, 0xcab05c33UL, 0x3bb659edUL, 0x5ed1e555UL,
  76308. 0xb07e5047UL, 0xd519ecffUL, 0x6c213b62UL, 0x094687daUL, 0xe7e932c8UL,
  76309. 0x828e8e70UL, 0xd49eed28UL, 0xb1f95190UL, 0x5f56e482UL, 0x3a31583aUL,
  76310. 0x83098fa7UL, 0xe66e331fUL, 0x08c1860dUL, 0x6da63ab5UL, 0xa4e140bdUL,
  76311. 0xc186fc05UL, 0x2f294917UL, 0x4a4ef5afUL, 0xf3762232UL, 0x96119e8aUL,
  76312. 0x78be2b98UL, 0x1dd99720UL, 0x4bc9f478UL, 0x2eae48c0UL, 0xc001fdd2UL,
  76313. 0xa566416aUL, 0x1c5e96f7UL, 0x79392a4fUL, 0x97969f5dUL, 0xf2f123e5UL,
  76314. 0x05196b4dUL, 0x607ed7f5UL, 0x8ed162e7UL, 0xebb6de5fUL, 0x528e09c2UL,
  76315. 0x37e9b57aUL, 0xd9460068UL, 0xbc21bcd0UL, 0xea31df88UL, 0x8f566330UL,
  76316. 0x61f9d622UL, 0x049e6a9aUL, 0xbda6bd07UL, 0xd8c101bfUL, 0x366eb4adUL,
  76317. 0x53090815UL, 0x9a4e721dUL, 0xff29cea5UL, 0x11867bb7UL, 0x74e1c70fUL,
  76318. 0xcdd91092UL, 0xa8beac2aUL, 0x46111938UL, 0x2376a580UL, 0x7566c6d8UL,
  76319. 0x10017a60UL, 0xfeaecf72UL, 0x9bc973caUL, 0x22f1a457UL, 0x479618efUL,
  76320. 0xa939adfdUL, 0xcc5e1145UL, 0x06ee4d76UL, 0x6389f1ceUL, 0x8d2644dcUL,
  76321. 0xe841f864UL, 0x51792ff9UL, 0x341e9341UL, 0xdab12653UL, 0xbfd69aebUL,
  76322. 0xe9c6f9b3UL, 0x8ca1450bUL, 0x620ef019UL, 0x07694ca1UL, 0xbe519b3cUL,
  76323. 0xdb362784UL, 0x35999296UL, 0x50fe2e2eUL, 0x99b95426UL, 0xfcdee89eUL,
  76324. 0x12715d8cUL, 0x7716e134UL, 0xce2e36a9UL, 0xab498a11UL, 0x45e63f03UL,
  76325. 0x208183bbUL, 0x7691e0e3UL, 0x13f65c5bUL, 0xfd59e949UL, 0x983e55f1UL,
  76326. 0x2106826cUL, 0x44613ed4UL, 0xaace8bc6UL, 0xcfa9377eUL, 0x38417fd6UL,
  76327. 0x5d26c36eUL, 0xb389767cUL, 0xd6eecac4UL, 0x6fd61d59UL, 0x0ab1a1e1UL,
  76328. 0xe41e14f3UL, 0x8179a84bUL, 0xd769cb13UL, 0xb20e77abUL, 0x5ca1c2b9UL,
  76329. 0x39c67e01UL, 0x80fea99cUL, 0xe5991524UL, 0x0b36a036UL, 0x6e511c8eUL,
  76330. 0xa7166686UL, 0xc271da3eUL, 0x2cde6f2cUL, 0x49b9d394UL, 0xf0810409UL,
  76331. 0x95e6b8b1UL, 0x7b490da3UL, 0x1e2eb11bUL, 0x483ed243UL, 0x2d596efbUL,
  76332. 0xc3f6dbe9UL, 0xa6916751UL, 0x1fa9b0ccUL, 0x7ace0c74UL, 0x9461b966UL,
  76333. 0xf10605deUL
  76334. #endif
  76335. }
  76336. };
  76337. /*** End of inlined file: crc32.h ***/
  76338. #endif /* DYNAMIC_CRC_TABLE */
  76339. const unsigned long FAR * ZEXPORT get_crc_table()
  76340. {
  76341. #ifdef DYNAMIC_CRC_TABLE
  76342. if (crc_table_empty)
  76343. make_crc_table();
  76344. #endif /* DYNAMIC_CRC_TABLE */
  76345. return (const unsigned long FAR *)crc_table;
  76346. }
  76347. #define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8)
  76348. #define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1
  76349. unsigned long ZEXPORT crc32 (unsigned long crc, const unsigned char FAR *buf, unsigned len)
  76350. {
  76351. if (buf == Z_NULL) return 0UL;
  76352. #ifdef DYNAMIC_CRC_TABLE
  76353. if (crc_table_empty)
  76354. make_crc_table();
  76355. #endif /* DYNAMIC_CRC_TABLE */
  76356. #ifdef BYFOUR
  76357. if (sizeof(void *) == sizeof(ptrdiff_t)) {
  76358. u4 endian;
  76359. endian = 1;
  76360. if (*((unsigned char *)(&endian)))
  76361. return crc32_little(crc, buf, len);
  76362. else
  76363. return crc32_big(crc, buf, len);
  76364. }
  76365. #endif /* BYFOUR */
  76366. crc = crc ^ 0xffffffffUL;
  76367. while (len >= 8) {
  76368. DO8;
  76369. len -= 8;
  76370. }
  76371. if (len) do {
  76372. DO1;
  76373. } while (--len);
  76374. return crc ^ 0xffffffffUL;
  76375. }
  76376. #ifdef BYFOUR
  76377. #define DOLIT4 c ^= *buf4++; \
  76378. c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \
  76379. crc_table[1][(c >> 16) & 0xff] ^ crc_table[0][c >> 24]
  76380. #define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4
  76381. local unsigned long crc32_little(unsigned long crc, const unsigned char FAR *buf, unsigned len)
  76382. {
  76383. register u4 c;
  76384. register const u4 FAR *buf4;
  76385. c = (u4)crc;
  76386. c = ~c;
  76387. while (len && ((ptrdiff_t)buf & 3)) {
  76388. c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
  76389. len--;
  76390. }
  76391. buf4 = (const u4 FAR *)(const void FAR *)buf;
  76392. while (len >= 32) {
  76393. DOLIT32;
  76394. len -= 32;
  76395. }
  76396. while (len >= 4) {
  76397. DOLIT4;
  76398. len -= 4;
  76399. }
  76400. buf = (const unsigned char FAR *)buf4;
  76401. if (len) do {
  76402. c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
  76403. } while (--len);
  76404. c = ~c;
  76405. return (unsigned long)c;
  76406. }
  76407. #define DOBIG4 c ^= *++buf4; \
  76408. c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \
  76409. crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24]
  76410. #define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4
  76411. local unsigned long crc32_big (unsigned long crc, const unsigned char FAR *buf, unsigned len)
  76412. {
  76413. register u4 c;
  76414. register const u4 FAR *buf4;
  76415. c = REV((u4)crc);
  76416. c = ~c;
  76417. while (len && ((ptrdiff_t)buf & 3)) {
  76418. c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
  76419. len--;
  76420. }
  76421. buf4 = (const u4 FAR *)(const void FAR *)buf;
  76422. buf4--;
  76423. while (len >= 32) {
  76424. DOBIG32;
  76425. len -= 32;
  76426. }
  76427. while (len >= 4) {
  76428. DOBIG4;
  76429. len -= 4;
  76430. }
  76431. buf4++;
  76432. buf = (const unsigned char FAR *)buf4;
  76433. if (len) do {
  76434. c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
  76435. } while (--len);
  76436. c = ~c;
  76437. return (unsigned long)(REV(c));
  76438. }
  76439. #endif /* BYFOUR */
  76440. #define GF2_DIM 32 /* dimension of GF(2) vectors (length of CRC) */
  76441. local unsigned long gf2_matrix_times (unsigned long *mat, unsigned long vec)
  76442. {
  76443. unsigned long sum;
  76444. sum = 0;
  76445. while (vec) {
  76446. if (vec & 1)
  76447. sum ^= *mat;
  76448. vec >>= 1;
  76449. mat++;
  76450. }
  76451. return sum;
  76452. }
  76453. local void gf2_matrix_square (unsigned long *square, unsigned long *mat)
  76454. {
  76455. int n;
  76456. for (n = 0; n < GF2_DIM; n++)
  76457. square[n] = gf2_matrix_times(mat, mat[n]);
  76458. }
  76459. uLong ZEXPORT crc32_combine (uLong crc1, uLong crc2, z_off_t len2)
  76460. {
  76461. int n;
  76462. unsigned long row;
  76463. unsigned long even[GF2_DIM]; /* even-power-of-two zeros operator */
  76464. unsigned long odd[GF2_DIM]; /* odd-power-of-two zeros operator */
  76465. if (len2 == 0)
  76466. return crc1;
  76467. odd[0] = 0xedb88320L; /* CRC-32 polynomial */
  76468. row = 1;
  76469. for (n = 1; n < GF2_DIM; n++) {
  76470. odd[n] = row;
  76471. row <<= 1;
  76472. }
  76473. gf2_matrix_square(even, odd);
  76474. gf2_matrix_square(odd, even);
  76475. do {
  76476. gf2_matrix_square(even, odd);
  76477. if (len2 & 1)
  76478. crc1 = gf2_matrix_times(even, crc1);
  76479. len2 >>= 1;
  76480. if (len2 == 0)
  76481. break;
  76482. gf2_matrix_square(odd, even);
  76483. if (len2 & 1)
  76484. crc1 = gf2_matrix_times(odd, crc1);
  76485. len2 >>= 1;
  76486. } while (len2 != 0);
  76487. crc1 ^= crc2;
  76488. return crc1;
  76489. }
  76490. /*** End of inlined file: crc32.c ***/
  76491. /*** Start of inlined file: deflate.c ***/
  76492. /*** Start of inlined file: deflate.h ***/
  76493. #ifndef DEFLATE_H
  76494. #define DEFLATE_H
  76495. #ifndef NO_GZIP
  76496. # define GZIP
  76497. #endif
  76498. #define NO_DUMMY_DECL
  76499. #define LENGTH_CODES 29
  76500. #define LITERALS 256
  76501. #define L_CODES (LITERALS+1+LENGTH_CODES)
  76502. #define D_CODES 30
  76503. #define BL_CODES 19
  76504. #define HEAP_SIZE (2*L_CODES+1)
  76505. #define MAX_BITS 15
  76506. #define INIT_STATE 42
  76507. #define EXTRA_STATE 69
  76508. #define NAME_STATE 73
  76509. #define COMMENT_STATE 91
  76510. #define HCRC_STATE 103
  76511. #define BUSY_STATE 113
  76512. #define FINISH_STATE 666
  76513. typedef struct ct_data_s {
  76514. union {
  76515. ush freq; /* frequency count */
  76516. ush code; /* bit string */
  76517. } fc;
  76518. union {
  76519. ush dad; /* father node in Huffman tree */
  76520. ush len; /* length of bit string */
  76521. } dl;
  76522. } FAR ct_data;
  76523. #define Freq fc.freq
  76524. #define Code fc.code
  76525. #define Dad dl.dad
  76526. #define Len dl.len
  76527. typedef struct static_tree_desc_s static_tree_desc;
  76528. typedef struct tree_desc_s {
  76529. ct_data *dyn_tree; /* the dynamic tree */
  76530. int max_code; /* largest code with non zero frequency */
  76531. static_tree_desc *stat_desc; /* the corresponding static tree */
  76532. } FAR tree_desc;
  76533. typedef ush Pos;
  76534. typedef Pos FAR Posf;
  76535. typedef unsigned IPos;
  76536. typedef struct internal_state {
  76537. z_streamp strm; /* pointer back to this zlib stream */
  76538. int status; /* as the name implies */
  76539. Bytef *pending_buf; /* output still pending */
  76540. ulg pending_buf_size; /* size of pending_buf */
  76541. Bytef *pending_out; /* next pending byte to output to the stream */
  76542. uInt pending; /* nb of bytes in the pending buffer */
  76543. int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
  76544. gz_headerp gzhead; /* gzip header information to write */
  76545. uInt gzindex; /* where in extra, name, or comment */
  76546. Byte method; /* STORED (for zip only) or DEFLATED */
  76547. int last_flush; /* value of flush param for previous deflate call */
  76548. uInt w_size; /* LZ77 window size (32K by default) */
  76549. uInt w_bits; /* log2(w_size) (8..16) */
  76550. uInt w_mask; /* w_size - 1 */
  76551. Bytef *window;
  76552. ulg window_size;
  76553. Posf *prev;
  76554. Posf *head; /* Heads of the hash chains or NIL. */
  76555. uInt ins_h; /* hash index of string to be inserted */
  76556. uInt hash_size; /* number of elements in hash table */
  76557. uInt hash_bits; /* log2(hash_size) */
  76558. uInt hash_mask; /* hash_size-1 */
  76559. uInt hash_shift;
  76560. long block_start;
  76561. uInt match_length; /* length of best match */
  76562. IPos prev_match; /* previous match */
  76563. int match_available; /* set if previous match exists */
  76564. uInt strstart; /* start of string to insert */
  76565. uInt match_start; /* start of matching string */
  76566. uInt lookahead; /* number of valid bytes ahead in window */
  76567. uInt prev_length;
  76568. uInt max_chain_length;
  76569. uInt max_lazy_match;
  76570. # define max_insert_length max_lazy_match
  76571. int level; /* compression level (1..9) */
  76572. int strategy; /* favor or force Huffman coding*/
  76573. uInt good_match;
  76574. int nice_match; /* Stop searching when current match exceeds this */
  76575. struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */
  76576. struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
  76577. struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */
  76578. struct tree_desc_s l_desc; /* desc. for literal tree */
  76579. struct tree_desc_s d_desc; /* desc. for distance tree */
  76580. struct tree_desc_s bl_desc; /* desc. for bit length tree */
  76581. ush bl_count[MAX_BITS+1];
  76582. int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */
  76583. int heap_len; /* number of elements in the heap */
  76584. int heap_max; /* element of largest frequency */
  76585. uch depth[2*L_CODES+1];
  76586. uchf *l_buf; /* buffer for literals or lengths */
  76587. uInt lit_bufsize;
  76588. uInt last_lit; /* running index in l_buf */
  76589. ushf *d_buf;
  76590. ulg opt_len; /* bit length of current block with optimal trees */
  76591. ulg static_len; /* bit length of current block with static trees */
  76592. uInt matches; /* number of string matches in current block */
  76593. int last_eob_len; /* bit length of EOB code for last block */
  76594. #ifdef DEBUG
  76595. ulg compressed_len; /* total bit length of compressed file mod 2^32 */
  76596. ulg bits_sent; /* bit length of compressed data sent mod 2^32 */
  76597. #endif
  76598. ush bi_buf;
  76599. int bi_valid;
  76600. } FAR deflate_state;
  76601. #define put_byte(s, c) {s->pending_buf[s->pending++] = (c);}
  76602. #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
  76603. #define MAX_DIST(s) ((s)->w_size-MIN_LOOKAHEAD)
  76604. void _tr_init OF((deflate_state *s));
  76605. int _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc));
  76606. void _tr_flush_block OF((deflate_state *s, charf *buf, ulg stored_len,
  76607. int eof));
  76608. void _tr_align OF((deflate_state *s));
  76609. void _tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len,
  76610. int eof));
  76611. #define d_code(dist) \
  76612. ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)])
  76613. #ifndef DEBUG
  76614. #if defined(GEN_TREES_H) || !defined(STDC)
  76615. extern uch _length_code[];
  76616. extern uch _dist_code[];
  76617. #else
  76618. extern const uch _length_code[];
  76619. extern const uch _dist_code[];
  76620. #endif
  76621. # define _tr_tally_lit(s, c, flush) \
  76622. { uch cc = (c); \
  76623. s->d_buf[s->last_lit] = 0; \
  76624. s->l_buf[s->last_lit++] = cc; \
  76625. s->dyn_ltree[cc].Freq++; \
  76626. flush = (s->last_lit == s->lit_bufsize-1); \
  76627. }
  76628. # define _tr_tally_dist(s, distance, length, flush) \
  76629. { uch len = (length); \
  76630. ush dist = (distance); \
  76631. s->d_buf[s->last_lit] = dist; \
  76632. s->l_buf[s->last_lit++] = len; \
  76633. dist--; \
  76634. s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
  76635. s->dyn_dtree[d_code(dist)].Freq++; \
  76636. flush = (s->last_lit == s->lit_bufsize-1); \
  76637. }
  76638. #else
  76639. # define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c)
  76640. # define _tr_tally_dist(s, distance, length, flush) \
  76641. flush = _tr_tally(s, distance, length)
  76642. #endif
  76643. #endif /* DEFLATE_H */
  76644. /*** End of inlined file: deflate.h ***/
  76645. const char deflate_copyright[] =
  76646. " deflate 1.2.3 Copyright 1995-2005 Jean-loup Gailly ";
  76647. typedef enum {
  76648. need_more, /* block not completed, need more input or more output */
  76649. block_done, /* block flush performed */
  76650. finish_started, /* finish started, need only more output at next deflate */
  76651. finish_done /* finish done, accept no more input or output */
  76652. } block_state;
  76653. typedef block_state (*compress_func) OF((deflate_state *s, int flush));
  76654. local void fill_window OF((deflate_state *s));
  76655. local block_state deflate_stored OF((deflate_state *s, int flush));
  76656. local block_state deflate_fast OF((deflate_state *s, int flush));
  76657. #ifndef FASTEST
  76658. local block_state deflate_slow OF((deflate_state *s, int flush));
  76659. #endif
  76660. local void lm_init OF((deflate_state *s));
  76661. local void putShortMSB OF((deflate_state *s, uInt b));
  76662. local void flush_pending OF((z_streamp strm));
  76663. local int read_buf OF((z_streamp strm, Bytef *buf, unsigned size));
  76664. #ifndef FASTEST
  76665. #ifdef ASMV
  76666. void match_init OF((void)); /* asm code initialization */
  76667. uInt longest_match OF((deflate_state *s, IPos cur_match));
  76668. #else
  76669. local uInt longest_match OF((deflate_state *s, IPos cur_match));
  76670. #endif
  76671. #endif
  76672. local uInt longest_match_fast OF((deflate_state *s, IPos cur_match));
  76673. #ifdef DEBUG
  76674. local void check_match OF((deflate_state *s, IPos start, IPos match,
  76675. int length));
  76676. #endif
  76677. #define NIL 0
  76678. #ifndef TOO_FAR
  76679. # define TOO_FAR 4096
  76680. #endif
  76681. #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
  76682. typedef struct config_s {
  76683. ush good_length; /* reduce lazy search above this match length */
  76684. ush max_lazy; /* do not perform lazy search above this match length */
  76685. ush nice_length; /* quit search above this match length */
  76686. ush max_chain;
  76687. compress_func func;
  76688. } config;
  76689. #ifdef FASTEST
  76690. local const config configuration_table[2] = {
  76691. {0, 0, 0, 0, deflate_stored}, /* store only */
  76692. {4, 4, 8, 4, deflate_fast}}; /* max speed, no lazy matches */
  76693. #else
  76694. local const config configuration_table[10] = {
  76695. {0, 0, 0, 0, deflate_stored}, /* store only */
  76696. {4, 4, 8, 4, deflate_fast}, /* max speed, no lazy matches */
  76697. {4, 5, 16, 8, deflate_fast},
  76698. {4, 6, 32, 32, deflate_fast},
  76699. {4, 4, 16, 16, deflate_slow}, /* lazy matches */
  76700. {8, 16, 32, 32, deflate_slow},
  76701. {8, 16, 128, 128, deflate_slow},
  76702. {8, 32, 128, 256, deflate_slow},
  76703. {32, 128, 258, 1024, deflate_slow},
  76704. {32, 258, 258, 4096, deflate_slow}}; /* max compression */
  76705. #endif
  76706. #define EQUAL 0
  76707. #ifndef NO_DUMMY_DECL
  76708. struct static_tree_desc_s {int dummy;}; /* for buggy compilers */
  76709. #endif
  76710. #define UPDATE_HASH(s,h,c) (h = (((h)<<s->hash_shift) ^ (c)) & s->hash_mask)
  76711. #ifdef FASTEST
  76712. #define INSERT_STRING(s, str, match_head) \
  76713. (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
  76714. match_head = s->head[s->ins_h], \
  76715. s->head[s->ins_h] = (Pos)(str))
  76716. #else
  76717. #define INSERT_STRING(s, str, match_head) \
  76718. (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
  76719. match_head = s->prev[(str) & s->w_mask] = s->head[s->ins_h], \
  76720. s->head[s->ins_h] = (Pos)(str))
  76721. #endif
  76722. #define CLEAR_HASH(s) \
  76723. s->head[s->hash_size-1] = NIL; \
  76724. zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head));
  76725. int ZEXPORT deflateInit_(z_streamp strm, int level, const char *version, int stream_size)
  76726. {
  76727. return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL,
  76728. Z_DEFAULT_STRATEGY, version, stream_size);
  76729. }
  76730. int ZEXPORT deflateInit2_ (z_streamp strm, int level, int method, int windowBits, int memLevel, int strategy, const char *version, int stream_size)
  76731. {
  76732. deflate_state *s;
  76733. int wrap = 1;
  76734. static const char my_version[] = ZLIB_VERSION;
  76735. ushf *overlay;
  76736. if (version == Z_NULL || version[0] != my_version[0] ||
  76737. stream_size != sizeof(z_stream)) {
  76738. return Z_VERSION_ERROR;
  76739. }
  76740. if (strm == Z_NULL) return Z_STREAM_ERROR;
  76741. strm->msg = Z_NULL;
  76742. if (strm->zalloc == (alloc_func)0) {
  76743. strm->zalloc = zcalloc;
  76744. strm->opaque = (voidpf)0;
  76745. }
  76746. if (strm->zfree == (free_func)0) strm->zfree = zcfree;
  76747. #ifdef FASTEST
  76748. if (level != 0) level = 1;
  76749. #else
  76750. if (level == Z_DEFAULT_COMPRESSION) level = 6;
  76751. #endif
  76752. if (windowBits < 0) { /* suppress zlib wrapper */
  76753. wrap = 0;
  76754. windowBits = -windowBits;
  76755. }
  76756. #ifdef GZIP
  76757. else if (windowBits > 15) {
  76758. wrap = 2; /* write gzip wrapper instead */
  76759. windowBits -= 16;
  76760. }
  76761. #endif
  76762. if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED ||
  76763. windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
  76764. strategy < 0 || strategy > Z_FIXED) {
  76765. return Z_STREAM_ERROR;
  76766. }
  76767. if (windowBits == 8) windowBits = 9; /* until 256-byte window bug fixed */
  76768. s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state));
  76769. if (s == Z_NULL) return Z_MEM_ERROR;
  76770. strm->state = (struct internal_state FAR *)s;
  76771. s->strm = strm;
  76772. s->wrap = wrap;
  76773. s->gzhead = Z_NULL;
  76774. s->w_bits = windowBits;
  76775. s->w_size = 1 << s->w_bits;
  76776. s->w_mask = s->w_size - 1;
  76777. s->hash_bits = memLevel + 7;
  76778. s->hash_size = 1 << s->hash_bits;
  76779. s->hash_mask = s->hash_size - 1;
  76780. s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH);
  76781. s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte));
  76782. s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos));
  76783. s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos));
  76784. s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */
  76785. overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2);
  76786. s->pending_buf = (uchf *) overlay;
  76787. s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(ush)+2L);
  76788. if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL ||
  76789. s->pending_buf == Z_NULL) {
  76790. s->status = FINISH_STATE;
  76791. strm->msg = (char*)ERR_MSG(Z_MEM_ERROR);
  76792. deflateEnd (strm);
  76793. return Z_MEM_ERROR;
  76794. }
  76795. s->d_buf = overlay + s->lit_bufsize/sizeof(ush);
  76796. s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize;
  76797. s->level = level;
  76798. s->strategy = strategy;
  76799. s->method = (Byte)method;
  76800. return deflateReset(strm);
  76801. }
  76802. int ZEXPORT deflateSetDictionary (z_streamp strm, const Bytef *dictionary, uInt dictLength)
  76803. {
  76804. deflate_state *s;
  76805. uInt length = dictLength;
  76806. uInt n;
  76807. IPos hash_head = 0;
  76808. if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL ||
  76809. strm->state->wrap == 2 ||
  76810. (strm->state->wrap == 1 && strm->state->status != INIT_STATE))
  76811. return Z_STREAM_ERROR;
  76812. s = strm->state;
  76813. if (s->wrap)
  76814. strm->adler = adler32(strm->adler, dictionary, dictLength);
  76815. if (length < MIN_MATCH) return Z_OK;
  76816. if (length > MAX_DIST(s)) {
  76817. length = MAX_DIST(s);
  76818. dictionary += dictLength - length; /* use the tail of the dictionary */
  76819. }
  76820. zmemcpy(s->window, dictionary, length);
  76821. s->strstart = length;
  76822. s->block_start = (long)length;
  76823. s->ins_h = s->window[0];
  76824. UPDATE_HASH(s, s->ins_h, s->window[1]);
  76825. for (n = 0; n <= length - MIN_MATCH; n++) {
  76826. INSERT_STRING(s, n, hash_head);
  76827. }
  76828. if (hash_head) hash_head = 0; /* to make compiler happy */
  76829. return Z_OK;
  76830. }
  76831. int ZEXPORT deflateReset (z_streamp strm)
  76832. {
  76833. deflate_state *s;
  76834. if (strm == Z_NULL || strm->state == Z_NULL ||
  76835. strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) {
  76836. return Z_STREAM_ERROR;
  76837. }
  76838. strm->total_in = strm->total_out = 0;
  76839. strm->msg = Z_NULL; /* use zfree if we ever allocate msg dynamically */
  76840. strm->data_type = Z_UNKNOWN;
  76841. s = (deflate_state *)strm->state;
  76842. s->pending = 0;
  76843. s->pending_out = s->pending_buf;
  76844. if (s->wrap < 0) {
  76845. s->wrap = -s->wrap; /* was made negative by deflate(..., Z_FINISH); */
  76846. }
  76847. s->status = s->wrap ? INIT_STATE : BUSY_STATE;
  76848. strm->adler =
  76849. #ifdef GZIP
  76850. s->wrap == 2 ? crc32(0L, Z_NULL, 0) :
  76851. #endif
  76852. adler32(0L, Z_NULL, 0);
  76853. s->last_flush = Z_NO_FLUSH;
  76854. _tr_init(s);
  76855. lm_init(s);
  76856. return Z_OK;
  76857. }
  76858. int ZEXPORT deflateSetHeader (z_streamp strm, gz_headerp head)
  76859. {
  76860. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  76861. if (strm->state->wrap != 2) return Z_STREAM_ERROR;
  76862. strm->state->gzhead = head;
  76863. return Z_OK;
  76864. }
  76865. int ZEXPORT deflatePrime (z_streamp strm, int bits, int value)
  76866. {
  76867. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  76868. strm->state->bi_valid = bits;
  76869. strm->state->bi_buf = (ush)(value & ((1 << bits) - 1));
  76870. return Z_OK;
  76871. }
  76872. int ZEXPORT deflateParams (z_streamp strm, int level, int strategy)
  76873. {
  76874. deflate_state *s;
  76875. compress_func func;
  76876. int err = Z_OK;
  76877. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  76878. s = strm->state;
  76879. #ifdef FASTEST
  76880. if (level != 0) level = 1;
  76881. #else
  76882. if (level == Z_DEFAULT_COMPRESSION) level = 6;
  76883. #endif
  76884. if (level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED) {
  76885. return Z_STREAM_ERROR;
  76886. }
  76887. func = configuration_table[s->level].func;
  76888. if (func != configuration_table[level].func && strm->total_in != 0) {
  76889. err = deflate(strm, Z_PARTIAL_FLUSH);
  76890. }
  76891. if (s->level != level) {
  76892. s->level = level;
  76893. s->max_lazy_match = configuration_table[level].max_lazy;
  76894. s->good_match = configuration_table[level].good_length;
  76895. s->nice_match = configuration_table[level].nice_length;
  76896. s->max_chain_length = configuration_table[level].max_chain;
  76897. }
  76898. s->strategy = strategy;
  76899. return err;
  76900. }
  76901. int ZEXPORT deflateTune (z_streamp strm, int good_length, int max_lazy, int nice_length, int max_chain)
  76902. {
  76903. deflate_state *s;
  76904. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  76905. s = strm->state;
  76906. s->good_match = good_length;
  76907. s->max_lazy_match = max_lazy;
  76908. s->nice_match = nice_length;
  76909. s->max_chain_length = max_chain;
  76910. return Z_OK;
  76911. }
  76912. uLong ZEXPORT deflateBound (z_streamp strm, uLong sourceLen)
  76913. {
  76914. deflate_state *s;
  76915. uLong destLen;
  76916. destLen = sourceLen +
  76917. ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 11;
  76918. if (strm == Z_NULL || strm->state == Z_NULL)
  76919. return destLen;
  76920. s = strm->state;
  76921. if (s->w_bits != 15 || s->hash_bits != 8 + 7)
  76922. return destLen;
  76923. return compressBound(sourceLen);
  76924. }
  76925. local void putShortMSB (deflate_state *s, uInt b)
  76926. {
  76927. put_byte(s, (Byte)(b >> 8));
  76928. put_byte(s, (Byte)(b & 0xff));
  76929. }
  76930. local void flush_pending (z_streamp strm)
  76931. {
  76932. unsigned len = strm->state->pending;
  76933. if (len > strm->avail_out) len = strm->avail_out;
  76934. if (len == 0) return;
  76935. zmemcpy(strm->next_out, strm->state->pending_out, len);
  76936. strm->next_out += len;
  76937. strm->state->pending_out += len;
  76938. strm->total_out += len;
  76939. strm->avail_out -= len;
  76940. strm->state->pending -= len;
  76941. if (strm->state->pending == 0) {
  76942. strm->state->pending_out = strm->state->pending_buf;
  76943. }
  76944. }
  76945. int ZEXPORT deflate (z_streamp strm, int flush)
  76946. {
  76947. int old_flush; /* value of flush param for previous deflate call */
  76948. deflate_state *s;
  76949. if (strm == Z_NULL || strm->state == Z_NULL ||
  76950. flush > Z_FINISH || flush < 0) {
  76951. return Z_STREAM_ERROR;
  76952. }
  76953. s = strm->state;
  76954. if (strm->next_out == Z_NULL ||
  76955. (strm->next_in == Z_NULL && strm->avail_in != 0) ||
  76956. (s->status == FINISH_STATE && flush != Z_FINISH)) {
  76957. ERR_RETURN(strm, Z_STREAM_ERROR);
  76958. }
  76959. if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR);
  76960. s->strm = strm; /* just in case */
  76961. old_flush = s->last_flush;
  76962. s->last_flush = flush;
  76963. if (s->status == INIT_STATE) {
  76964. #ifdef GZIP
  76965. if (s->wrap == 2) {
  76966. strm->adler = crc32(0L, Z_NULL, 0);
  76967. put_byte(s, 31);
  76968. put_byte(s, 139);
  76969. put_byte(s, 8);
  76970. if (s->gzhead == NULL) {
  76971. put_byte(s, 0);
  76972. put_byte(s, 0);
  76973. put_byte(s, 0);
  76974. put_byte(s, 0);
  76975. put_byte(s, 0);
  76976. put_byte(s, s->level == 9 ? 2 :
  76977. (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
  76978. 4 : 0));
  76979. put_byte(s, OS_CODE);
  76980. s->status = BUSY_STATE;
  76981. }
  76982. else {
  76983. put_byte(s, (s->gzhead->text ? 1 : 0) +
  76984. (s->gzhead->hcrc ? 2 : 0) +
  76985. (s->gzhead->extra == Z_NULL ? 0 : 4) +
  76986. (s->gzhead->name == Z_NULL ? 0 : 8) +
  76987. (s->gzhead->comment == Z_NULL ? 0 : 16)
  76988. );
  76989. put_byte(s, (Byte)(s->gzhead->time & 0xff));
  76990. put_byte(s, (Byte)((s->gzhead->time >> 8) & 0xff));
  76991. put_byte(s, (Byte)((s->gzhead->time >> 16) & 0xff));
  76992. put_byte(s, (Byte)((s->gzhead->time >> 24) & 0xff));
  76993. put_byte(s, s->level == 9 ? 2 :
  76994. (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
  76995. 4 : 0));
  76996. put_byte(s, s->gzhead->os & 0xff);
  76997. if (s->gzhead->extra != NULL) {
  76998. put_byte(s, s->gzhead->extra_len & 0xff);
  76999. put_byte(s, (s->gzhead->extra_len >> 8) & 0xff);
  77000. }
  77001. if (s->gzhead->hcrc)
  77002. strm->adler = crc32(strm->adler, s->pending_buf,
  77003. s->pending);
  77004. s->gzindex = 0;
  77005. s->status = EXTRA_STATE;
  77006. }
  77007. }
  77008. else
  77009. #endif
  77010. {
  77011. uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8;
  77012. uInt level_flags;
  77013. if (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2)
  77014. level_flags = 0;
  77015. else if (s->level < 6)
  77016. level_flags = 1;
  77017. else if (s->level == 6)
  77018. level_flags = 2;
  77019. else
  77020. level_flags = 3;
  77021. header |= (level_flags << 6);
  77022. if (s->strstart != 0) header |= PRESET_DICT;
  77023. header += 31 - (header % 31);
  77024. s->status = BUSY_STATE;
  77025. putShortMSB(s, header);
  77026. if (s->strstart != 0) {
  77027. putShortMSB(s, (uInt)(strm->adler >> 16));
  77028. putShortMSB(s, (uInt)(strm->adler & 0xffff));
  77029. }
  77030. strm->adler = adler32(0L, Z_NULL, 0);
  77031. }
  77032. }
  77033. #ifdef GZIP
  77034. if (s->status == EXTRA_STATE) {
  77035. if (s->gzhead->extra != NULL) {
  77036. uInt beg = s->pending; /* start of bytes to update crc */
  77037. while (s->gzindex < (s->gzhead->extra_len & 0xffff)) {
  77038. if (s->pending == s->pending_buf_size) {
  77039. if (s->gzhead->hcrc && s->pending > beg)
  77040. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77041. s->pending - beg);
  77042. flush_pending(strm);
  77043. beg = s->pending;
  77044. if (s->pending == s->pending_buf_size)
  77045. break;
  77046. }
  77047. put_byte(s, s->gzhead->extra[s->gzindex]);
  77048. s->gzindex++;
  77049. }
  77050. if (s->gzhead->hcrc && s->pending > beg)
  77051. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77052. s->pending - beg);
  77053. if (s->gzindex == s->gzhead->extra_len) {
  77054. s->gzindex = 0;
  77055. s->status = NAME_STATE;
  77056. }
  77057. }
  77058. else
  77059. s->status = NAME_STATE;
  77060. }
  77061. if (s->status == NAME_STATE) {
  77062. if (s->gzhead->name != NULL) {
  77063. uInt beg = s->pending; /* start of bytes to update crc */
  77064. int val;
  77065. do {
  77066. if (s->pending == s->pending_buf_size) {
  77067. if (s->gzhead->hcrc && s->pending > beg)
  77068. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77069. s->pending - beg);
  77070. flush_pending(strm);
  77071. beg = s->pending;
  77072. if (s->pending == s->pending_buf_size) {
  77073. val = 1;
  77074. break;
  77075. }
  77076. }
  77077. val = s->gzhead->name[s->gzindex++];
  77078. put_byte(s, val);
  77079. } while (val != 0);
  77080. if (s->gzhead->hcrc && s->pending > beg)
  77081. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77082. s->pending - beg);
  77083. if (val == 0) {
  77084. s->gzindex = 0;
  77085. s->status = COMMENT_STATE;
  77086. }
  77087. }
  77088. else
  77089. s->status = COMMENT_STATE;
  77090. }
  77091. if (s->status == COMMENT_STATE) {
  77092. if (s->gzhead->comment != NULL) {
  77093. uInt beg = s->pending; /* start of bytes to update crc */
  77094. int val;
  77095. do {
  77096. if (s->pending == s->pending_buf_size) {
  77097. if (s->gzhead->hcrc && s->pending > beg)
  77098. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77099. s->pending - beg);
  77100. flush_pending(strm);
  77101. beg = s->pending;
  77102. if (s->pending == s->pending_buf_size) {
  77103. val = 1;
  77104. break;
  77105. }
  77106. }
  77107. val = s->gzhead->comment[s->gzindex++];
  77108. put_byte(s, val);
  77109. } while (val != 0);
  77110. if (s->gzhead->hcrc && s->pending > beg)
  77111. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77112. s->pending - beg);
  77113. if (val == 0)
  77114. s->status = HCRC_STATE;
  77115. }
  77116. else
  77117. s->status = HCRC_STATE;
  77118. }
  77119. if (s->status == HCRC_STATE) {
  77120. if (s->gzhead->hcrc) {
  77121. if (s->pending + 2 > s->pending_buf_size)
  77122. flush_pending(strm);
  77123. if (s->pending + 2 <= s->pending_buf_size) {
  77124. put_byte(s, (Byte)(strm->adler & 0xff));
  77125. put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
  77126. strm->adler = crc32(0L, Z_NULL, 0);
  77127. s->status = BUSY_STATE;
  77128. }
  77129. }
  77130. else
  77131. s->status = BUSY_STATE;
  77132. }
  77133. #endif
  77134. if (s->pending != 0) {
  77135. flush_pending(strm);
  77136. if (strm->avail_out == 0) {
  77137. s->last_flush = -1;
  77138. return Z_OK;
  77139. }
  77140. } else if (strm->avail_in == 0 && flush <= old_flush &&
  77141. flush != Z_FINISH) {
  77142. ERR_RETURN(strm, Z_BUF_ERROR);
  77143. }
  77144. if (s->status == FINISH_STATE && strm->avail_in != 0) {
  77145. ERR_RETURN(strm, Z_BUF_ERROR);
  77146. }
  77147. if (strm->avail_in != 0 || s->lookahead != 0 ||
  77148. (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) {
  77149. block_state bstate;
  77150. bstate = (*(configuration_table[s->level].func))(s, flush);
  77151. if (bstate == finish_started || bstate == finish_done) {
  77152. s->status = FINISH_STATE;
  77153. }
  77154. if (bstate == need_more || bstate == finish_started) {
  77155. if (strm->avail_out == 0) {
  77156. s->last_flush = -1; /* avoid BUF_ERROR next call, see above */
  77157. }
  77158. return Z_OK;
  77159. }
  77160. if (bstate == block_done) {
  77161. if (flush == Z_PARTIAL_FLUSH) {
  77162. _tr_align(s);
  77163. } else { /* FULL_FLUSH or SYNC_FLUSH */
  77164. _tr_stored_block(s, (char*)0, 0L, 0);
  77165. if (flush == Z_FULL_FLUSH) {
  77166. CLEAR_HASH(s); /* forget history */
  77167. }
  77168. }
  77169. flush_pending(strm);
  77170. if (strm->avail_out == 0) {
  77171. s->last_flush = -1; /* avoid BUF_ERROR at next call, see above */
  77172. return Z_OK;
  77173. }
  77174. }
  77175. }
  77176. Assert(strm->avail_out > 0, "bug2");
  77177. if (flush != Z_FINISH) return Z_OK;
  77178. if (s->wrap <= 0) return Z_STREAM_END;
  77179. #ifdef GZIP
  77180. if (s->wrap == 2) {
  77181. put_byte(s, (Byte)(strm->adler & 0xff));
  77182. put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
  77183. put_byte(s, (Byte)((strm->adler >> 16) & 0xff));
  77184. put_byte(s, (Byte)((strm->adler >> 24) & 0xff));
  77185. put_byte(s, (Byte)(strm->total_in & 0xff));
  77186. put_byte(s, (Byte)((strm->total_in >> 8) & 0xff));
  77187. put_byte(s, (Byte)((strm->total_in >> 16) & 0xff));
  77188. put_byte(s, (Byte)((strm->total_in >> 24) & 0xff));
  77189. }
  77190. else
  77191. #endif
  77192. {
  77193. putShortMSB(s, (uInt)(strm->adler >> 16));
  77194. putShortMSB(s, (uInt)(strm->adler & 0xffff));
  77195. }
  77196. flush_pending(strm);
  77197. if (s->wrap > 0) s->wrap = -s->wrap; /* write the trailer only once! */
  77198. return s->pending != 0 ? Z_OK : Z_STREAM_END;
  77199. }
  77200. int ZEXPORT deflateEnd (z_streamp strm)
  77201. {
  77202. int status;
  77203. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77204. status = strm->state->status;
  77205. if (status != INIT_STATE &&
  77206. status != EXTRA_STATE &&
  77207. status != NAME_STATE &&
  77208. status != COMMENT_STATE &&
  77209. status != HCRC_STATE &&
  77210. status != BUSY_STATE &&
  77211. status != FINISH_STATE) {
  77212. return Z_STREAM_ERROR;
  77213. }
  77214. TRY_FREE(strm, strm->state->pending_buf);
  77215. TRY_FREE(strm, strm->state->head);
  77216. TRY_FREE(strm, strm->state->prev);
  77217. TRY_FREE(strm, strm->state->window);
  77218. ZFREE(strm, strm->state);
  77219. strm->state = Z_NULL;
  77220. return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK;
  77221. }
  77222. int ZEXPORT deflateCopy (z_streamp dest, z_streamp source)
  77223. {
  77224. #ifdef MAXSEG_64K
  77225. return Z_STREAM_ERROR;
  77226. #else
  77227. deflate_state *ds;
  77228. deflate_state *ss;
  77229. ushf *overlay;
  77230. if (source == Z_NULL || dest == Z_NULL || source->state == Z_NULL) {
  77231. return Z_STREAM_ERROR;
  77232. }
  77233. ss = source->state;
  77234. zmemcpy(dest, source, sizeof(z_stream));
  77235. ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state));
  77236. if (ds == Z_NULL) return Z_MEM_ERROR;
  77237. dest->state = (struct internal_state FAR *) ds;
  77238. zmemcpy(ds, ss, sizeof(deflate_state));
  77239. ds->strm = dest;
  77240. ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));
  77241. ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos));
  77242. ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos));
  77243. overlay = (ushf *) ZALLOC(dest, ds->lit_bufsize, sizeof(ush)+2);
  77244. ds->pending_buf = (uchf *) overlay;
  77245. if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL ||
  77246. ds->pending_buf == Z_NULL) {
  77247. deflateEnd (dest);
  77248. return Z_MEM_ERROR;
  77249. }
  77250. zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte));
  77251. zmemcpy(ds->prev, ss->prev, ds->w_size * sizeof(Pos));
  77252. zmemcpy(ds->head, ss->head, ds->hash_size * sizeof(Pos));
  77253. zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size);
  77254. ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
  77255. ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush);
  77256. ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize;
  77257. ds->l_desc.dyn_tree = ds->dyn_ltree;
  77258. ds->d_desc.dyn_tree = ds->dyn_dtree;
  77259. ds->bl_desc.dyn_tree = ds->bl_tree;
  77260. return Z_OK;
  77261. #endif /* MAXSEG_64K */
  77262. }
  77263. local int read_buf (z_streamp strm, Bytef *buf, unsigned size)
  77264. {
  77265. unsigned len = strm->avail_in;
  77266. if (len > size) len = size;
  77267. if (len == 0) return 0;
  77268. strm->avail_in -= len;
  77269. if (strm->state->wrap == 1) {
  77270. strm->adler = adler32(strm->adler, strm->next_in, len);
  77271. }
  77272. #ifdef GZIP
  77273. else if (strm->state->wrap == 2) {
  77274. strm->adler = crc32(strm->adler, strm->next_in, len);
  77275. }
  77276. #endif
  77277. zmemcpy(buf, strm->next_in, len);
  77278. strm->next_in += len;
  77279. strm->total_in += len;
  77280. return (int)len;
  77281. }
  77282. local void lm_init (deflate_state *s)
  77283. {
  77284. s->window_size = (ulg)2L*s->w_size;
  77285. CLEAR_HASH(s);
  77286. s->max_lazy_match = configuration_table[s->level].max_lazy;
  77287. s->good_match = configuration_table[s->level].good_length;
  77288. s->nice_match = configuration_table[s->level].nice_length;
  77289. s->max_chain_length = configuration_table[s->level].max_chain;
  77290. s->strstart = 0;
  77291. s->block_start = 0L;
  77292. s->lookahead = 0;
  77293. s->match_length = s->prev_length = MIN_MATCH-1;
  77294. s->match_available = 0;
  77295. s->ins_h = 0;
  77296. #ifndef FASTEST
  77297. #ifdef ASMV
  77298. match_init(); /* initialize the asm code */
  77299. #endif
  77300. #endif
  77301. }
  77302. #ifndef FASTEST
  77303. #ifndef ASMV
  77304. local uInt longest_match(deflate_state *s, IPos cur_match)
  77305. {
  77306. unsigned chain_length = s->max_chain_length;/* max hash chain length */
  77307. register Bytef *scan = s->window + s->strstart; /* current string */
  77308. register Bytef *match; /* matched string */
  77309. register int len; /* length of current match */
  77310. int best_len = s->prev_length; /* best match length so far */
  77311. int nice_match = s->nice_match; /* stop if match long enough */
  77312. IPos limit = s->strstart > (IPos)MAX_DIST(s) ?
  77313. s->strstart - (IPos)MAX_DIST(s) : NIL;
  77314. Posf *prev = s->prev;
  77315. uInt wmask = s->w_mask;
  77316. #ifdef UNALIGNED_OK
  77317. register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1;
  77318. register ush scan_start = *(ushf*)scan;
  77319. register ush scan_end = *(ushf*)(scan+best_len-1);
  77320. #else
  77321. register Bytef *strend = s->window + s->strstart + MAX_MATCH;
  77322. register Byte scan_end1 = scan[best_len-1];
  77323. register Byte scan_end = scan[best_len];
  77324. #endif
  77325. Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
  77326. if (s->prev_length >= s->good_match) {
  77327. chain_length >>= 2;
  77328. }
  77329. if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead;
  77330. Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
  77331. do {
  77332. Assert(cur_match < s->strstart, "no future");
  77333. match = s->window + cur_match;
  77334. #if (defined(UNALIGNED_OK) && MAX_MATCH == 258)
  77335. if (*(ushf*)(match+best_len-1) != scan_end ||
  77336. *(ushf*)match != scan_start) continue;
  77337. Assert(scan[2] == match[2], "scan[2]?");
  77338. scan++, match++;
  77339. do {
  77340. } while (*(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77341. *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77342. *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77343. *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77344. scan < strend);
  77345. Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  77346. if (*scan == *match) scan++;
  77347. len = (MAX_MATCH - 1) - (int)(strend-scan);
  77348. scan = strend - (MAX_MATCH-1);
  77349. #else /* UNALIGNED_OK */
  77350. if (match[best_len] != scan_end ||
  77351. match[best_len-1] != scan_end1 ||
  77352. *match != *scan ||
  77353. *++match != scan[1]) continue;
  77354. scan += 2, match++;
  77355. Assert(*scan == *match, "match[2]?");
  77356. do {
  77357. } while (*++scan == *++match && *++scan == *++match &&
  77358. *++scan == *++match && *++scan == *++match &&
  77359. *++scan == *++match && *++scan == *++match &&
  77360. *++scan == *++match && *++scan == *++match &&
  77361. scan < strend);
  77362. Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  77363. len = MAX_MATCH - (int)(strend - scan);
  77364. scan = strend - MAX_MATCH;
  77365. #endif /* UNALIGNED_OK */
  77366. if (len > best_len) {
  77367. s->match_start = cur_match;
  77368. best_len = len;
  77369. if (len >= nice_match) break;
  77370. #ifdef UNALIGNED_OK
  77371. scan_end = *(ushf*)(scan+best_len-1);
  77372. #else
  77373. scan_end1 = scan[best_len-1];
  77374. scan_end = scan[best_len];
  77375. #endif
  77376. }
  77377. } while ((cur_match = prev[cur_match & wmask]) > limit
  77378. && --chain_length != 0);
  77379. if ((uInt)best_len <= s->lookahead) return (uInt)best_len;
  77380. return s->lookahead;
  77381. }
  77382. #endif /* ASMV */
  77383. #endif /* FASTEST */
  77384. local uInt longest_match_fast (deflate_state *s, IPos cur_match)
  77385. {
  77386. register Bytef *scan = s->window + s->strstart; /* current string */
  77387. register Bytef *match; /* matched string */
  77388. register int len; /* length of current match */
  77389. register Bytef *strend = s->window + s->strstart + MAX_MATCH;
  77390. Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
  77391. Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
  77392. Assert(cur_match < s->strstart, "no future");
  77393. match = s->window + cur_match;
  77394. if (match[0] != scan[0] || match[1] != scan[1]) return MIN_MATCH-1;
  77395. scan += 2, match += 2;
  77396. Assert(*scan == *match, "match[2]?");
  77397. do {
  77398. } while (*++scan == *++match && *++scan == *++match &&
  77399. *++scan == *++match && *++scan == *++match &&
  77400. *++scan == *++match && *++scan == *++match &&
  77401. *++scan == *++match && *++scan == *++match &&
  77402. scan < strend);
  77403. Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  77404. len = MAX_MATCH - (int)(strend - scan);
  77405. if (len < MIN_MATCH) return MIN_MATCH - 1;
  77406. s->match_start = cur_match;
  77407. return (uInt)len <= s->lookahead ? (uInt)len : s->lookahead;
  77408. }
  77409. #ifdef DEBUG
  77410. local void check_match(deflate_state *s, IPos start, IPos match, int length)
  77411. {
  77412. if (zmemcmp(s->window + match,
  77413. s->window + start, length) != EQUAL) {
  77414. fprintf(stderr, " start %u, match %u, length %d\n",
  77415. start, match, length);
  77416. do {
  77417. fprintf(stderr, "%c%c", s->window[match++], s->window[start++]);
  77418. } while (--length != 0);
  77419. z_error("invalid match");
  77420. }
  77421. if (z_verbose > 1) {
  77422. fprintf(stderr,"\\[%d,%d]", start-match, length);
  77423. do { putc(s->window[start++], stderr); } while (--length != 0);
  77424. }
  77425. }
  77426. #else
  77427. # define check_match(s, start, match, length)
  77428. #endif /* DEBUG */
  77429. local void fill_window (deflate_state *s)
  77430. {
  77431. register unsigned n, m;
  77432. register Posf *p;
  77433. unsigned more; /* Amount of free space at the end of the window. */
  77434. uInt wsize = s->w_size;
  77435. do {
  77436. more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);
  77437. if (sizeof(int) <= 2) {
  77438. if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
  77439. more = wsize;
  77440. } else if (more == (unsigned)(-1)) {
  77441. more--;
  77442. }
  77443. }
  77444. if (s->strstart >= wsize+MAX_DIST(s)) {
  77445. zmemcpy(s->window, s->window+wsize, (unsigned)wsize);
  77446. s->match_start -= wsize;
  77447. s->strstart -= wsize; /* we now have strstart >= MAX_DIST */
  77448. s->block_start -= (long) wsize;
  77449. n = s->hash_size;
  77450. p = &s->head[n];
  77451. do {
  77452. m = *--p;
  77453. *p = (Pos)(m >= wsize ? m-wsize : NIL);
  77454. } while (--n);
  77455. n = wsize;
  77456. #ifndef FASTEST
  77457. p = &s->prev[n];
  77458. do {
  77459. m = *--p;
  77460. *p = (Pos)(m >= wsize ? m-wsize : NIL);
  77461. } while (--n);
  77462. #endif
  77463. more += wsize;
  77464. }
  77465. if (s->strm->avail_in == 0) return;
  77466. Assert(more >= 2, "more < 2");
  77467. n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more);
  77468. s->lookahead += n;
  77469. if (s->lookahead >= MIN_MATCH) {
  77470. s->ins_h = s->window[s->strstart];
  77471. UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
  77472. #if MIN_MATCH != 3
  77473. Call UPDATE_HASH() MIN_MATCH-3 more times
  77474. #endif
  77475. }
  77476. } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0);
  77477. }
  77478. #define FLUSH_BLOCK_ONLY(s, eof) { \
  77479. _tr_flush_block(s, (s->block_start >= 0L ? \
  77480. (charf *)&s->window[(unsigned)s->block_start] : \
  77481. (charf *)Z_NULL), \
  77482. (ulg)((long)s->strstart - s->block_start), \
  77483. (eof)); \
  77484. s->block_start = s->strstart; \
  77485. flush_pending(s->strm); \
  77486. Tracev((stderr,"[FLUSH]")); \
  77487. }
  77488. #define FLUSH_BLOCK(s, eof) { \
  77489. FLUSH_BLOCK_ONLY(s, eof); \
  77490. if (s->strm->avail_out == 0) return (eof) ? finish_started : need_more; \
  77491. }
  77492. local block_state deflate_stored(deflate_state *s, int flush)
  77493. {
  77494. ulg max_block_size = 0xffff;
  77495. ulg max_start;
  77496. if (max_block_size > s->pending_buf_size - 5) {
  77497. max_block_size = s->pending_buf_size - 5;
  77498. }
  77499. for (;;) {
  77500. if (s->lookahead <= 1) {
  77501. Assert(s->strstart < s->w_size+MAX_DIST(s) ||
  77502. s->block_start >= (long)s->w_size, "slide too late");
  77503. fill_window(s);
  77504. if (s->lookahead == 0 && flush == Z_NO_FLUSH) return need_more;
  77505. if (s->lookahead == 0) break; /* flush the current block */
  77506. }
  77507. Assert(s->block_start >= 0L, "block gone");
  77508. s->strstart += s->lookahead;
  77509. s->lookahead = 0;
  77510. max_start = s->block_start + max_block_size;
  77511. if (s->strstart == 0 || (ulg)s->strstart >= max_start) {
  77512. s->lookahead = (uInt)(s->strstart - max_start);
  77513. s->strstart = (uInt)max_start;
  77514. FLUSH_BLOCK(s, 0);
  77515. }
  77516. if (s->strstart - (uInt)s->block_start >= MAX_DIST(s)) {
  77517. FLUSH_BLOCK(s, 0);
  77518. }
  77519. }
  77520. FLUSH_BLOCK(s, flush == Z_FINISH);
  77521. return flush == Z_FINISH ? finish_done : block_done;
  77522. }
  77523. local block_state deflate_fast(deflate_state *s, int flush)
  77524. {
  77525. IPos hash_head = NIL; /* head of the hash chain */
  77526. int bflush; /* set if current block must be flushed */
  77527. for (;;) {
  77528. if (s->lookahead < MIN_LOOKAHEAD) {
  77529. fill_window(s);
  77530. if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
  77531. return need_more;
  77532. }
  77533. if (s->lookahead == 0) break; /* flush the current block */
  77534. }
  77535. if (s->lookahead >= MIN_MATCH) {
  77536. INSERT_STRING(s, s->strstart, hash_head);
  77537. }
  77538. if (hash_head != NIL && s->strstart - hash_head <= MAX_DIST(s)) {
  77539. #ifdef FASTEST
  77540. if ((s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) ||
  77541. (s->strategy == Z_RLE && s->strstart - hash_head == 1)) {
  77542. s->match_length = longest_match_fast (s, hash_head);
  77543. }
  77544. #else
  77545. if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) {
  77546. s->match_length = longest_match (s, hash_head);
  77547. } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {
  77548. s->match_length = longest_match_fast (s, hash_head);
  77549. }
  77550. #endif
  77551. }
  77552. if (s->match_length >= MIN_MATCH) {
  77553. check_match(s, s->strstart, s->match_start, s->match_length);
  77554. _tr_tally_dist(s, s->strstart - s->match_start,
  77555. s->match_length - MIN_MATCH, bflush);
  77556. s->lookahead -= s->match_length;
  77557. #ifndef FASTEST
  77558. if (s->match_length <= s->max_insert_length &&
  77559. s->lookahead >= MIN_MATCH) {
  77560. s->match_length--; /* string at strstart already in table */
  77561. do {
  77562. s->strstart++;
  77563. INSERT_STRING(s, s->strstart, hash_head);
  77564. } while (--s->match_length != 0);
  77565. s->strstart++;
  77566. } else
  77567. #endif
  77568. {
  77569. s->strstart += s->match_length;
  77570. s->match_length = 0;
  77571. s->ins_h = s->window[s->strstart];
  77572. UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
  77573. #if MIN_MATCH != 3
  77574. Call UPDATE_HASH() MIN_MATCH-3 more times
  77575. #endif
  77576. }
  77577. } else {
  77578. Tracevv((stderr,"%c", s->window[s->strstart]));
  77579. _tr_tally_lit (s, s->window[s->strstart], bflush);
  77580. s->lookahead--;
  77581. s->strstart++;
  77582. }
  77583. if (bflush) FLUSH_BLOCK(s, 0);
  77584. }
  77585. FLUSH_BLOCK(s, flush == Z_FINISH);
  77586. return flush == Z_FINISH ? finish_done : block_done;
  77587. }
  77588. #ifndef FASTEST
  77589. local block_state deflate_slow(deflate_state *s, int flush)
  77590. {
  77591. IPos hash_head = NIL; /* head of hash chain */
  77592. int bflush; /* set if current block must be flushed */
  77593. for (;;) {
  77594. if (s->lookahead < MIN_LOOKAHEAD) {
  77595. fill_window(s);
  77596. if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
  77597. return need_more;
  77598. }
  77599. if (s->lookahead == 0) break; /* flush the current block */
  77600. }
  77601. if (s->lookahead >= MIN_MATCH) {
  77602. INSERT_STRING(s, s->strstart, hash_head);
  77603. }
  77604. s->prev_length = s->match_length, s->prev_match = s->match_start;
  77605. s->match_length = MIN_MATCH-1;
  77606. if (hash_head != NIL && s->prev_length < s->max_lazy_match &&
  77607. s->strstart - hash_head <= MAX_DIST(s)) {
  77608. if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) {
  77609. s->match_length = longest_match (s, hash_head);
  77610. } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {
  77611. s->match_length = longest_match_fast (s, hash_head);
  77612. }
  77613. if (s->match_length <= 5 && (s->strategy == Z_FILTERED
  77614. #if TOO_FAR <= 32767
  77615. || (s->match_length == MIN_MATCH &&
  77616. s->strstart - s->match_start > TOO_FAR)
  77617. #endif
  77618. )) {
  77619. s->match_length = MIN_MATCH-1;
  77620. }
  77621. }
  77622. if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) {
  77623. uInt max_insert = s->strstart + s->lookahead - MIN_MATCH;
  77624. check_match(s, s->strstart-1, s->prev_match, s->prev_length);
  77625. _tr_tally_dist(s, s->strstart -1 - s->prev_match,
  77626. s->prev_length - MIN_MATCH, bflush);
  77627. s->lookahead -= s->prev_length-1;
  77628. s->prev_length -= 2;
  77629. do {
  77630. if (++s->strstart <= max_insert) {
  77631. INSERT_STRING(s, s->strstart, hash_head);
  77632. }
  77633. } while (--s->prev_length != 0);
  77634. s->match_available = 0;
  77635. s->match_length = MIN_MATCH-1;
  77636. s->strstart++;
  77637. if (bflush) FLUSH_BLOCK(s, 0);
  77638. } else if (s->match_available) {
  77639. Tracevv((stderr,"%c", s->window[s->strstart-1]));
  77640. _tr_tally_lit(s, s->window[s->strstart-1], bflush);
  77641. if (bflush) {
  77642. FLUSH_BLOCK_ONLY(s, 0);
  77643. }
  77644. s->strstart++;
  77645. s->lookahead--;
  77646. if (s->strm->avail_out == 0) return need_more;
  77647. } else {
  77648. s->match_available = 1;
  77649. s->strstart++;
  77650. s->lookahead--;
  77651. }
  77652. }
  77653. Assert (flush != Z_NO_FLUSH, "no flush?");
  77654. if (s->match_available) {
  77655. Tracevv((stderr,"%c", s->window[s->strstart-1]));
  77656. _tr_tally_lit(s, s->window[s->strstart-1], bflush);
  77657. s->match_available = 0;
  77658. }
  77659. FLUSH_BLOCK(s, flush == Z_FINISH);
  77660. return flush == Z_FINISH ? finish_done : block_done;
  77661. }
  77662. #endif /* FASTEST */
  77663. #if 0
  77664. local block_state deflate_rle(s, flush)
  77665. deflate_state *s;
  77666. int flush;
  77667. {
  77668. int bflush; /* set if current block must be flushed */
  77669. uInt run; /* length of run */
  77670. uInt max; /* maximum length of run */
  77671. uInt prev; /* byte at distance one to match */
  77672. Bytef *scan; /* scan for end of run */
  77673. for (;;) {
  77674. if (s->lookahead < MAX_MATCH) {
  77675. fill_window(s);
  77676. if (s->lookahead < MAX_MATCH && flush == Z_NO_FLUSH) {
  77677. return need_more;
  77678. }
  77679. if (s->lookahead == 0) break; /* flush the current block */
  77680. }
  77681. run = 0;
  77682. if (s->strstart > 0) { /* if there is a previous byte, that is */
  77683. max = s->lookahead < MAX_MATCH ? s->lookahead : MAX_MATCH;
  77684. scan = s->window + s->strstart - 1;
  77685. prev = *scan++;
  77686. do {
  77687. if (*scan++ != prev)
  77688. break;
  77689. } while (++run < max);
  77690. }
  77691. if (run >= MIN_MATCH) {
  77692. check_match(s, s->strstart, s->strstart - 1, run);
  77693. _tr_tally_dist(s, 1, run - MIN_MATCH, bflush);
  77694. s->lookahead -= run;
  77695. s->strstart += run;
  77696. } else {
  77697. Tracevv((stderr,"%c", s->window[s->strstart]));
  77698. _tr_tally_lit (s, s->window[s->strstart], bflush);
  77699. s->lookahead--;
  77700. s->strstart++;
  77701. }
  77702. if (bflush) FLUSH_BLOCK(s, 0);
  77703. }
  77704. FLUSH_BLOCK(s, flush == Z_FINISH);
  77705. return flush == Z_FINISH ? finish_done : block_done;
  77706. }
  77707. #endif
  77708. /*** End of inlined file: deflate.c ***/
  77709. /*** Start of inlined file: inffast.c ***/
  77710. /*** Start of inlined file: inftrees.h ***/
  77711. #ifndef _INFTREES_H_
  77712. #define _INFTREES_H_
  77713. typedef struct {
  77714. unsigned char op; /* operation, extra bits, table bits */
  77715. unsigned char bits; /* bits in this part of the code */
  77716. unsigned short val; /* offset in table or code value */
  77717. } code;
  77718. #define ENOUGH 2048
  77719. #define MAXD 592
  77720. typedef enum {
  77721. CODES,
  77722. LENS,
  77723. DISTS
  77724. } codetype;
  77725. extern int inflate_table OF((codetype type, unsigned short FAR *lens,
  77726. unsigned codes, code FAR * FAR *table,
  77727. unsigned FAR *bits, unsigned short FAR *work));
  77728. #endif
  77729. /*** End of inlined file: inftrees.h ***/
  77730. /*** Start of inlined file: inflate.h ***/
  77731. #ifndef _INFLATE_H_
  77732. #define _INFLATE_H_
  77733. #ifndef NO_GZIP
  77734. # define GUNZIP
  77735. #endif
  77736. typedef enum {
  77737. HEAD, /* i: waiting for magic header */
  77738. FLAGS, /* i: waiting for method and flags (gzip) */
  77739. TIME, /* i: waiting for modification time (gzip) */
  77740. OS, /* i: waiting for extra flags and operating system (gzip) */
  77741. EXLEN, /* i: waiting for extra length (gzip) */
  77742. EXTRA, /* i: waiting for extra bytes (gzip) */
  77743. NAME, /* i: waiting for end of file name (gzip) */
  77744. COMMENT, /* i: waiting for end of comment (gzip) */
  77745. HCRC, /* i: waiting for header crc (gzip) */
  77746. DICTID, /* i: waiting for dictionary check value */
  77747. DICT, /* waiting for inflateSetDictionary() call */
  77748. TYPE, /* i: waiting for type bits, including last-flag bit */
  77749. TYPEDO, /* i: same, but skip check to exit inflate on new block */
  77750. STORED, /* i: waiting for stored size (length and complement) */
  77751. COPY, /* i/o: waiting for input or output to copy stored block */
  77752. TABLE, /* i: waiting for dynamic block table lengths */
  77753. LENLENS, /* i: waiting for code length code lengths */
  77754. CODELENS, /* i: waiting for length/lit and distance code lengths */
  77755. LEN, /* i: waiting for length/lit code */
  77756. LENEXT, /* i: waiting for length extra bits */
  77757. DIST, /* i: waiting for distance code */
  77758. DISTEXT, /* i: waiting for distance extra bits */
  77759. MATCH, /* o: waiting for output space to copy string */
  77760. LIT, /* o: waiting for output space to write literal */
  77761. CHECK, /* i: waiting for 32-bit check value */
  77762. LENGTH, /* i: waiting for 32-bit length (gzip) */
  77763. DONE, /* finished check, done -- remain here until reset */
  77764. BAD, /* got a data error -- remain here until reset */
  77765. MEM, /* got an inflate() memory error -- remain here until reset */
  77766. SYNC /* looking for synchronization bytes to restart inflate() */
  77767. } inflate_mode;
  77768. struct inflate_state {
  77769. inflate_mode mode; /* current inflate mode */
  77770. int last; /* true if processing last block */
  77771. int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
  77772. int havedict; /* true if dictionary provided */
  77773. int flags; /* gzip header method and flags (0 if zlib) */
  77774. unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */
  77775. unsigned long check; /* protected copy of check value */
  77776. unsigned long total; /* protected copy of output count */
  77777. gz_headerp head; /* where to save gzip header information */
  77778. unsigned wbits; /* log base 2 of requested window size */
  77779. unsigned wsize; /* window size or zero if not using window */
  77780. unsigned whave; /* valid bytes in the window */
  77781. unsigned write; /* window write index */
  77782. unsigned char FAR *window; /* allocated sliding window, if needed */
  77783. unsigned long hold; /* input bit accumulator */
  77784. unsigned bits; /* number of bits in "in" */
  77785. unsigned length; /* literal or length of data to copy */
  77786. unsigned offset; /* distance back to copy string from */
  77787. unsigned extra; /* extra bits needed */
  77788. code const FAR *lencode; /* starting table for length/literal codes */
  77789. code const FAR *distcode; /* starting table for distance codes */
  77790. unsigned lenbits; /* index bits for lencode */
  77791. unsigned distbits; /* index bits for distcode */
  77792. unsigned ncode; /* number of code length code lengths */
  77793. unsigned nlen; /* number of length code lengths */
  77794. unsigned ndist; /* number of distance code lengths */
  77795. unsigned have; /* number of code lengths in lens[] */
  77796. code FAR *next; /* next available space in codes[] */
  77797. unsigned short lens[320]; /* temporary storage for code lengths */
  77798. unsigned short work[288]; /* work area for code table building */
  77799. code codes[ENOUGH]; /* space for code tables */
  77800. };
  77801. #endif
  77802. /*** End of inlined file: inflate.h ***/
  77803. /*** Start of inlined file: inffast.h ***/
  77804. void inflate_fast OF((z_streamp strm, unsigned start));
  77805. /*** End of inlined file: inffast.h ***/
  77806. #ifndef ASMINF
  77807. #ifdef POSTINC
  77808. # define OFF 0
  77809. # define PUP(a) *(a)++
  77810. #else
  77811. # define OFF 1
  77812. # define PUP(a) *++(a)
  77813. #endif
  77814. void inflate_fast (z_streamp strm, unsigned start)
  77815. {
  77816. struct inflate_state FAR *state;
  77817. unsigned char FAR *in; /* local strm->next_in */
  77818. unsigned char FAR *last; /* while in < last, enough input available */
  77819. unsigned char FAR *out; /* local strm->next_out */
  77820. unsigned char FAR *beg; /* inflate()'s initial strm->next_out */
  77821. unsigned char FAR *end; /* while out < end, enough space available */
  77822. #ifdef INFLATE_STRICT
  77823. unsigned dmax; /* maximum distance from zlib header */
  77824. #endif
  77825. unsigned wsize; /* window size or zero if not using window */
  77826. unsigned whave; /* valid bytes in the window */
  77827. unsigned write; /* window write index */
  77828. unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */
  77829. unsigned long hold; /* local strm->hold */
  77830. unsigned bits; /* local strm->bits */
  77831. code const FAR *lcode; /* local strm->lencode */
  77832. code const FAR *dcode; /* local strm->distcode */
  77833. unsigned lmask; /* mask for first level of length codes */
  77834. unsigned dmask; /* mask for first level of distance codes */
  77835. code thisx; /* retrieved table entry */
  77836. unsigned op; /* code bits, operation, extra bits, or */
  77837. unsigned len; /* match length, unused bytes */
  77838. unsigned dist; /* match distance */
  77839. unsigned char FAR *from; /* where to copy match from */
  77840. state = (struct inflate_state FAR *)strm->state;
  77841. in = strm->next_in - OFF;
  77842. last = in + (strm->avail_in - 5);
  77843. out = strm->next_out - OFF;
  77844. beg = out - (start - strm->avail_out);
  77845. end = out + (strm->avail_out - 257);
  77846. #ifdef INFLATE_STRICT
  77847. dmax = state->dmax;
  77848. #endif
  77849. wsize = state->wsize;
  77850. whave = state->whave;
  77851. write = state->write;
  77852. window = state->window;
  77853. hold = state->hold;
  77854. bits = state->bits;
  77855. lcode = state->lencode;
  77856. dcode = state->distcode;
  77857. lmask = (1U << state->lenbits) - 1;
  77858. dmask = (1U << state->distbits) - 1;
  77859. do {
  77860. if (bits < 15) {
  77861. hold += (unsigned long)(PUP(in)) << bits;
  77862. bits += 8;
  77863. hold += (unsigned long)(PUP(in)) << bits;
  77864. bits += 8;
  77865. }
  77866. thisx = lcode[hold & lmask];
  77867. dolen:
  77868. op = (unsigned)(thisx.bits);
  77869. hold >>= op;
  77870. bits -= op;
  77871. op = (unsigned)(thisx.op);
  77872. if (op == 0) { /* literal */
  77873. Tracevv((stderr, thisx.val >= 0x20 && thisx.val < 0x7f ?
  77874. "inflate: literal '%c'\n" :
  77875. "inflate: literal 0x%02x\n", thisx.val));
  77876. PUP(out) = (unsigned char)(thisx.val);
  77877. }
  77878. else if (op & 16) { /* length base */
  77879. len = (unsigned)(thisx.val);
  77880. op &= 15; /* number of extra bits */
  77881. if (op) {
  77882. if (bits < op) {
  77883. hold += (unsigned long)(PUP(in)) << bits;
  77884. bits += 8;
  77885. }
  77886. len += (unsigned)hold & ((1U << op) - 1);
  77887. hold >>= op;
  77888. bits -= op;
  77889. }
  77890. Tracevv((stderr, "inflate: length %u\n", len));
  77891. if (bits < 15) {
  77892. hold += (unsigned long)(PUP(in)) << bits;
  77893. bits += 8;
  77894. hold += (unsigned long)(PUP(in)) << bits;
  77895. bits += 8;
  77896. }
  77897. thisx = dcode[hold & dmask];
  77898. dodist:
  77899. op = (unsigned)(thisx.bits);
  77900. hold >>= op;
  77901. bits -= op;
  77902. op = (unsigned)(thisx.op);
  77903. if (op & 16) { /* distance base */
  77904. dist = (unsigned)(thisx.val);
  77905. op &= 15; /* number of extra bits */
  77906. if (bits < op) {
  77907. hold += (unsigned long)(PUP(in)) << bits;
  77908. bits += 8;
  77909. if (bits < op) {
  77910. hold += (unsigned long)(PUP(in)) << bits;
  77911. bits += 8;
  77912. }
  77913. }
  77914. dist += (unsigned)hold & ((1U << op) - 1);
  77915. #ifdef INFLATE_STRICT
  77916. if (dist > dmax) {
  77917. strm->msg = (char *)"invalid distance too far back";
  77918. state->mode = BAD;
  77919. break;
  77920. }
  77921. #endif
  77922. hold >>= op;
  77923. bits -= op;
  77924. Tracevv((stderr, "inflate: distance %u\n", dist));
  77925. op = (unsigned)(out - beg); /* max distance in output */
  77926. if (dist > op) { /* see if copy from window */
  77927. op = dist - op; /* distance back in window */
  77928. if (op > whave) {
  77929. strm->msg = (char *)"invalid distance too far back";
  77930. state->mode = BAD;
  77931. break;
  77932. }
  77933. from = window - OFF;
  77934. if (write == 0) { /* very common case */
  77935. from += wsize - op;
  77936. if (op < len) { /* some from window */
  77937. len -= op;
  77938. do {
  77939. PUP(out) = PUP(from);
  77940. } while (--op);
  77941. from = out - dist; /* rest from output */
  77942. }
  77943. }
  77944. else if (write < op) { /* wrap around window */
  77945. from += wsize + write - op;
  77946. op -= write;
  77947. if (op < len) { /* some from end of window */
  77948. len -= op;
  77949. do {
  77950. PUP(out) = PUP(from);
  77951. } while (--op);
  77952. from = window - OFF;
  77953. if (write < len) { /* some from start of window */
  77954. op = write;
  77955. len -= op;
  77956. do {
  77957. PUP(out) = PUP(from);
  77958. } while (--op);
  77959. from = out - dist; /* rest from output */
  77960. }
  77961. }
  77962. }
  77963. else { /* contiguous in window */
  77964. from += write - op;
  77965. if (op < len) { /* some from window */
  77966. len -= op;
  77967. do {
  77968. PUP(out) = PUP(from);
  77969. } while (--op);
  77970. from = out - dist; /* rest from output */
  77971. }
  77972. }
  77973. while (len > 2) {
  77974. PUP(out) = PUP(from);
  77975. PUP(out) = PUP(from);
  77976. PUP(out) = PUP(from);
  77977. len -= 3;
  77978. }
  77979. if (len) {
  77980. PUP(out) = PUP(from);
  77981. if (len > 1)
  77982. PUP(out) = PUP(from);
  77983. }
  77984. }
  77985. else {
  77986. from = out - dist; /* copy direct from output */
  77987. do { /* minimum length is three */
  77988. PUP(out) = PUP(from);
  77989. PUP(out) = PUP(from);
  77990. PUP(out) = PUP(from);
  77991. len -= 3;
  77992. } while (len > 2);
  77993. if (len) {
  77994. PUP(out) = PUP(from);
  77995. if (len > 1)
  77996. PUP(out) = PUP(from);
  77997. }
  77998. }
  77999. }
  78000. else if ((op & 64) == 0) { /* 2nd level distance code */
  78001. thisx = dcode[thisx.val + (hold & ((1U << op) - 1))];
  78002. goto dodist;
  78003. }
  78004. else {
  78005. strm->msg = (char *)"invalid distance code";
  78006. state->mode = BAD;
  78007. break;
  78008. }
  78009. }
  78010. else if ((op & 64) == 0) { /* 2nd level length code */
  78011. thisx = lcode[thisx.val + (hold & ((1U << op) - 1))];
  78012. goto dolen;
  78013. }
  78014. else if (op & 32) { /* end-of-block */
  78015. Tracevv((stderr, "inflate: end of block\n"));
  78016. state->mode = TYPE;
  78017. break;
  78018. }
  78019. else {
  78020. strm->msg = (char *)"invalid literal/length code";
  78021. state->mode = BAD;
  78022. break;
  78023. }
  78024. } while (in < last && out < end);
  78025. len = bits >> 3;
  78026. in -= len;
  78027. bits -= len << 3;
  78028. hold &= (1U << bits) - 1;
  78029. strm->next_in = in + OFF;
  78030. strm->next_out = out + OFF;
  78031. strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last));
  78032. strm->avail_out = (unsigned)(out < end ?
  78033. 257 + (end - out) : 257 - (out - end));
  78034. state->hold = hold;
  78035. state->bits = bits;
  78036. return;
  78037. }
  78038. #endif /* !ASMINF */
  78039. /*** End of inlined file: inffast.c ***/
  78040. #undef PULLBYTE
  78041. #undef LOAD
  78042. #undef RESTORE
  78043. #undef INITBITS
  78044. #undef NEEDBITS
  78045. #undef DROPBITS
  78046. #undef BYTEBITS
  78047. /*** Start of inlined file: inflate.c ***/
  78048. /*** Start of inlined file: inffast.h ***/
  78049. void inflate_fast OF((z_streamp strm, unsigned start));
  78050. /*** End of inlined file: inffast.h ***/
  78051. #ifdef MAKEFIXED
  78052. # ifndef BUILDFIXED
  78053. # define BUILDFIXED
  78054. # endif
  78055. #endif
  78056. local void fixedtables OF((struct inflate_state FAR *state));
  78057. local int updatewindow OF((z_streamp strm, unsigned out));
  78058. #ifdef BUILDFIXED
  78059. void makefixed OF((void));
  78060. #endif
  78061. local unsigned syncsearch OF((unsigned FAR *have, unsigned char FAR *buf,
  78062. unsigned len));
  78063. int ZEXPORT inflateReset (z_streamp strm)
  78064. {
  78065. struct inflate_state FAR *state;
  78066. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  78067. state = (struct inflate_state FAR *)strm->state;
  78068. strm->total_in = strm->total_out = state->total = 0;
  78069. strm->msg = Z_NULL;
  78070. strm->adler = 1; /* to support ill-conceived Java test suite */
  78071. state->mode = HEAD;
  78072. state->last = 0;
  78073. state->havedict = 0;
  78074. state->dmax = 32768U;
  78075. state->head = Z_NULL;
  78076. state->wsize = 0;
  78077. state->whave = 0;
  78078. state->write = 0;
  78079. state->hold = 0;
  78080. state->bits = 0;
  78081. state->lencode = state->distcode = state->next = state->codes;
  78082. Tracev((stderr, "inflate: reset\n"));
  78083. return Z_OK;
  78084. }
  78085. int ZEXPORT inflatePrime (z_streamp strm, int bits, int value)
  78086. {
  78087. struct inflate_state FAR *state;
  78088. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  78089. state = (struct inflate_state FAR *)strm->state;
  78090. if (bits > 16 || state->bits + bits > 32) return Z_STREAM_ERROR;
  78091. value &= (1L << bits) - 1;
  78092. state->hold += value << state->bits;
  78093. state->bits += bits;
  78094. return Z_OK;
  78095. }
  78096. int ZEXPORT inflateInit2_(z_streamp strm, int windowBits, const char *version, int stream_size)
  78097. {
  78098. struct inflate_state FAR *state;
  78099. if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
  78100. stream_size != (int)(sizeof(z_stream)))
  78101. return Z_VERSION_ERROR;
  78102. if (strm == Z_NULL) return Z_STREAM_ERROR;
  78103. strm->msg = Z_NULL; /* in case we return an error */
  78104. if (strm->zalloc == (alloc_func)0) {
  78105. strm->zalloc = zcalloc;
  78106. strm->opaque = (voidpf)0;
  78107. }
  78108. if (strm->zfree == (free_func)0) strm->zfree = zcfree;
  78109. state = (struct inflate_state FAR *)
  78110. ZALLOC(strm, 1, sizeof(struct inflate_state));
  78111. if (state == Z_NULL) return Z_MEM_ERROR;
  78112. Tracev((stderr, "inflate: allocated\n"));
  78113. strm->state = (struct internal_state FAR *)state;
  78114. if (windowBits < 0) {
  78115. state->wrap = 0;
  78116. windowBits = -windowBits;
  78117. }
  78118. else {
  78119. state->wrap = (windowBits >> 4) + 1;
  78120. #ifdef GUNZIP
  78121. if (windowBits < 48) windowBits &= 15;
  78122. #endif
  78123. }
  78124. if (windowBits < 8 || windowBits > 15) {
  78125. ZFREE(strm, state);
  78126. strm->state = Z_NULL;
  78127. return Z_STREAM_ERROR;
  78128. }
  78129. state->wbits = (unsigned)windowBits;
  78130. state->window = Z_NULL;
  78131. return inflateReset(strm);
  78132. }
  78133. int ZEXPORT inflateInit_ (z_streamp strm, const char *version, int stream_size)
  78134. {
  78135. return inflateInit2_(strm, DEF_WBITS, version, stream_size);
  78136. }
  78137. local void fixedtables (struct inflate_state FAR *state)
  78138. {
  78139. #ifdef BUILDFIXED
  78140. static int virgin = 1;
  78141. static code *lenfix, *distfix;
  78142. static code fixed[544];
  78143. if (virgin) {
  78144. unsigned sym, bits;
  78145. static code *next;
  78146. sym = 0;
  78147. while (sym < 144) state->lens[sym++] = 8;
  78148. while (sym < 256) state->lens[sym++] = 9;
  78149. while (sym < 280) state->lens[sym++] = 7;
  78150. while (sym < 288) state->lens[sym++] = 8;
  78151. next = fixed;
  78152. lenfix = next;
  78153. bits = 9;
  78154. inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work);
  78155. sym = 0;
  78156. while (sym < 32) state->lens[sym++] = 5;
  78157. distfix = next;
  78158. bits = 5;
  78159. inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work);
  78160. virgin = 0;
  78161. }
  78162. #else /* !BUILDFIXED */
  78163. /*** Start of inlined file: inffixed.h ***/
  78164. static const code lenfix[512] = {
  78165. {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48},
  78166. {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128},
  78167. {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59},
  78168. {0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176},
  78169. {0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20},
  78170. {21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100},
  78171. {0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8},
  78172. {0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216},
  78173. {18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76},
  78174. {0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114},
  78175. {0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2},
  78176. {0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148},
  78177. {20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42},
  78178. {0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86},
  78179. {0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15},
  78180. {0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236},
  78181. {16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62},
  78182. {0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142},
  78183. {0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31},
  78184. {0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162},
  78185. {0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25},
  78186. {0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105},
  78187. {0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4},
  78188. {0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202},
  78189. {17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69},
  78190. {0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125},
  78191. {0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13},
  78192. {0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195},
  78193. {19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35},
  78194. {0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91},
  78195. {0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19},
  78196. {0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246},
  78197. {16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55},
  78198. {0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135},
  78199. {0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99},
  78200. {0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190},
  78201. {0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16},
  78202. {20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96},
  78203. {0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6},
  78204. {0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209},
  78205. {17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72},
  78206. {0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116},
  78207. {0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4},
  78208. {0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153},
  78209. {20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44},
  78210. {0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82},
  78211. {0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11},
  78212. {0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229},
  78213. {16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58},
  78214. {0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138},
  78215. {0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51},
  78216. {0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173},
  78217. {0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30},
  78218. {0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110},
  78219. {0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0},
  78220. {0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195},
  78221. {16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65},
  78222. {0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121},
  78223. {0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9},
  78224. {0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258},
  78225. {19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37},
  78226. {0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93},
  78227. {0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23},
  78228. {0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251},
  78229. {16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51},
  78230. {0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131},
  78231. {0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67},
  78232. {0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183},
  78233. {0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23},
  78234. {64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103},
  78235. {0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9},
  78236. {0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223},
  78237. {18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79},
  78238. {0,9,255}
  78239. };
  78240. static const code distfix[32] = {
  78241. {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025},
  78242. {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193},
  78243. {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385},
  78244. {19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577},
  78245. {16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073},
  78246. {22,5,193},{64,5,0}
  78247. };
  78248. /*** End of inlined file: inffixed.h ***/
  78249. #endif /* BUILDFIXED */
  78250. state->lencode = lenfix;
  78251. state->lenbits = 9;
  78252. state->distcode = distfix;
  78253. state->distbits = 5;
  78254. }
  78255. #ifdef MAKEFIXED
  78256. #include <stdio.h>
  78257. void makefixed()
  78258. {
  78259. unsigned low, size;
  78260. struct inflate_state state;
  78261. fixedtables(&state);
  78262. puts(" /* inffixed.h -- table for decoding fixed codes");
  78263. puts(" * Generated automatically by makefixed().");
  78264. puts(" */");
  78265. puts("");
  78266. puts(" /* WARNING: this file should *not* be used by applications.");
  78267. puts(" It is part of the implementation of this library and is");
  78268. puts(" subject to change. Applications should only use zlib.h.");
  78269. puts(" */");
  78270. puts("");
  78271. size = 1U << 9;
  78272. printf(" static const code lenfix[%u] = {", size);
  78273. low = 0;
  78274. for (;;) {
  78275. if ((low % 7) == 0) printf("\n ");
  78276. printf("{%u,%u,%d}", state.lencode[low].op, state.lencode[low].bits,
  78277. state.lencode[low].val);
  78278. if (++low == size) break;
  78279. putchar(',');
  78280. }
  78281. puts("\n };");
  78282. size = 1U << 5;
  78283. printf("\n static const code distfix[%u] = {", size);
  78284. low = 0;
  78285. for (;;) {
  78286. if ((low % 6) == 0) printf("\n ");
  78287. printf("{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits,
  78288. state.distcode[low].val);
  78289. if (++low == size) break;
  78290. putchar(',');
  78291. }
  78292. puts("\n };");
  78293. }
  78294. #endif /* MAKEFIXED */
  78295. local int updatewindow (z_streamp strm, unsigned out)
  78296. {
  78297. struct inflate_state FAR *state;
  78298. unsigned copy, dist;
  78299. state = (struct inflate_state FAR *)strm->state;
  78300. if (state->window == Z_NULL) {
  78301. state->window = (unsigned char FAR *)
  78302. ZALLOC(strm, 1U << state->wbits,
  78303. sizeof(unsigned char));
  78304. if (state->window == Z_NULL) return 1;
  78305. }
  78306. if (state->wsize == 0) {
  78307. state->wsize = 1U << state->wbits;
  78308. state->write = 0;
  78309. state->whave = 0;
  78310. }
  78311. copy = out - strm->avail_out;
  78312. if (copy >= state->wsize) {
  78313. zmemcpy(state->window, strm->next_out - state->wsize, state->wsize);
  78314. state->write = 0;
  78315. state->whave = state->wsize;
  78316. }
  78317. else {
  78318. dist = state->wsize - state->write;
  78319. if (dist > copy) dist = copy;
  78320. zmemcpy(state->window + state->write, strm->next_out - copy, dist);
  78321. copy -= dist;
  78322. if (copy) {
  78323. zmemcpy(state->window, strm->next_out - copy, copy);
  78324. state->write = copy;
  78325. state->whave = state->wsize;
  78326. }
  78327. else {
  78328. state->write += dist;
  78329. if (state->write == state->wsize) state->write = 0;
  78330. if (state->whave < state->wsize) state->whave += dist;
  78331. }
  78332. }
  78333. return 0;
  78334. }
  78335. #ifdef GUNZIP
  78336. # define UPDATE(check, buf, len) \
  78337. (state->flags ? crc32(check, buf, len) : adler32(check, buf, len))
  78338. #else
  78339. # define UPDATE(check, buf, len) adler32(check, buf, len)
  78340. #endif
  78341. #ifdef GUNZIP
  78342. # define CRC2(check, word) \
  78343. do { \
  78344. hbuf[0] = (unsigned char)(word); \
  78345. hbuf[1] = (unsigned char)((word) >> 8); \
  78346. check = crc32(check, hbuf, 2); \
  78347. } while (0)
  78348. # define CRC4(check, word) \
  78349. do { \
  78350. hbuf[0] = (unsigned char)(word); \
  78351. hbuf[1] = (unsigned char)((word) >> 8); \
  78352. hbuf[2] = (unsigned char)((word) >> 16); \
  78353. hbuf[3] = (unsigned char)((word) >> 24); \
  78354. check = crc32(check, hbuf, 4); \
  78355. } while (0)
  78356. #endif
  78357. #define LOAD() \
  78358. do { \
  78359. put = strm->next_out; \
  78360. left = strm->avail_out; \
  78361. next = strm->next_in; \
  78362. have = strm->avail_in; \
  78363. hold = state->hold; \
  78364. bits = state->bits; \
  78365. } while (0)
  78366. #define RESTORE() \
  78367. do { \
  78368. strm->next_out = put; \
  78369. strm->avail_out = left; \
  78370. strm->next_in = next; \
  78371. strm->avail_in = have; \
  78372. state->hold = hold; \
  78373. state->bits = bits; \
  78374. } while (0)
  78375. #define INITBITS() \
  78376. do { \
  78377. hold = 0; \
  78378. bits = 0; \
  78379. } while (0)
  78380. #define PULLBYTE() \
  78381. do { \
  78382. if (have == 0) goto inf_leave; \
  78383. have--; \
  78384. hold += (unsigned long)(*next++) << bits; \
  78385. bits += 8; \
  78386. } while (0)
  78387. #define NEEDBITS(n) \
  78388. do { \
  78389. while (bits < (unsigned)(n)) \
  78390. PULLBYTE(); \
  78391. } while (0)
  78392. #define BITS(n) \
  78393. ((unsigned)hold & ((1U << (n)) - 1))
  78394. #define DROPBITS(n) \
  78395. do { \
  78396. hold >>= (n); \
  78397. bits -= (unsigned)(n); \
  78398. } while (0)
  78399. #define BYTEBITS() \
  78400. do { \
  78401. hold >>= bits & 7; \
  78402. bits -= bits & 7; \
  78403. } while (0)
  78404. #define REVERSE(q) \
  78405. ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
  78406. (((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
  78407. int ZEXPORT inflate (z_streamp strm, int flush)
  78408. {
  78409. struct inflate_state FAR *state;
  78410. unsigned char FAR *next; /* next input */
  78411. unsigned char FAR *put; /* next output */
  78412. unsigned have, left; /* available input and output */
  78413. unsigned long hold; /* bit buffer */
  78414. unsigned bits; /* bits in bit buffer */
  78415. unsigned in, out; /* save starting available input and output */
  78416. unsigned copy; /* number of stored or match bytes to copy */
  78417. unsigned char FAR *from; /* where to copy match bytes from */
  78418. code thisx; /* current decoding table entry */
  78419. code last; /* parent table entry */
  78420. unsigned len; /* length to copy for repeats, bits to drop */
  78421. int ret; /* return code */
  78422. #ifdef GUNZIP
  78423. unsigned char hbuf[4]; /* buffer for gzip header crc calculation */
  78424. #endif
  78425. static const unsigned short order[19] = /* permutation of code lengths */
  78426. {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
  78427. if (strm == Z_NULL || strm->state == Z_NULL || strm->next_out == Z_NULL ||
  78428. (strm->next_in == Z_NULL && strm->avail_in != 0))
  78429. return Z_STREAM_ERROR;
  78430. state = (struct inflate_state FAR *)strm->state;
  78431. if (state->mode == TYPE) state->mode = TYPEDO; /* skip check */
  78432. LOAD();
  78433. in = have;
  78434. out = left;
  78435. ret = Z_OK;
  78436. for (;;)
  78437. switch (state->mode) {
  78438. case HEAD:
  78439. if (state->wrap == 0) {
  78440. state->mode = TYPEDO;
  78441. break;
  78442. }
  78443. NEEDBITS(16);
  78444. #ifdef GUNZIP
  78445. if ((state->wrap & 2) && hold == 0x8b1f) { /* gzip header */
  78446. state->check = crc32(0L, Z_NULL, 0);
  78447. CRC2(state->check, hold);
  78448. INITBITS();
  78449. state->mode = FLAGS;
  78450. break;
  78451. }
  78452. state->flags = 0; /* expect zlib header */
  78453. if (state->head != Z_NULL)
  78454. state->head->done = -1;
  78455. if (!(state->wrap & 1) || /* check if zlib header allowed */
  78456. #else
  78457. if (
  78458. #endif
  78459. ((BITS(8) << 8) + (hold >> 8)) % 31) {
  78460. strm->msg = (char *)"incorrect header check";
  78461. state->mode = BAD;
  78462. break;
  78463. }
  78464. if (BITS(4) != Z_DEFLATED) {
  78465. strm->msg = (char *)"unknown compression method";
  78466. state->mode = BAD;
  78467. break;
  78468. }
  78469. DROPBITS(4);
  78470. len = BITS(4) + 8;
  78471. if (len > state->wbits) {
  78472. strm->msg = (char *)"invalid window size";
  78473. state->mode = BAD;
  78474. break;
  78475. }
  78476. state->dmax = 1U << len;
  78477. Tracev((stderr, "inflate: zlib header ok\n"));
  78478. strm->adler = state->check = adler32(0L, Z_NULL, 0);
  78479. state->mode = hold & 0x200 ? DICTID : TYPE;
  78480. INITBITS();
  78481. break;
  78482. #ifdef GUNZIP
  78483. case FLAGS:
  78484. NEEDBITS(16);
  78485. state->flags = (int)(hold);
  78486. if ((state->flags & 0xff) != Z_DEFLATED) {
  78487. strm->msg = (char *)"unknown compression method";
  78488. state->mode = BAD;
  78489. break;
  78490. }
  78491. if (state->flags & 0xe000) {
  78492. strm->msg = (char *)"unknown header flags set";
  78493. state->mode = BAD;
  78494. break;
  78495. }
  78496. if (state->head != Z_NULL)
  78497. state->head->text = (int)((hold >> 8) & 1);
  78498. if (state->flags & 0x0200) CRC2(state->check, hold);
  78499. INITBITS();
  78500. state->mode = TIME;
  78501. case TIME:
  78502. NEEDBITS(32);
  78503. if (state->head != Z_NULL)
  78504. state->head->time = hold;
  78505. if (state->flags & 0x0200) CRC4(state->check, hold);
  78506. INITBITS();
  78507. state->mode = OS;
  78508. case OS:
  78509. NEEDBITS(16);
  78510. if (state->head != Z_NULL) {
  78511. state->head->xflags = (int)(hold & 0xff);
  78512. state->head->os = (int)(hold >> 8);
  78513. }
  78514. if (state->flags & 0x0200) CRC2(state->check, hold);
  78515. INITBITS();
  78516. state->mode = EXLEN;
  78517. case EXLEN:
  78518. if (state->flags & 0x0400) {
  78519. NEEDBITS(16);
  78520. state->length = (unsigned)(hold);
  78521. if (state->head != Z_NULL)
  78522. state->head->extra_len = (unsigned)hold;
  78523. if (state->flags & 0x0200) CRC2(state->check, hold);
  78524. INITBITS();
  78525. }
  78526. else if (state->head != Z_NULL)
  78527. state->head->extra = Z_NULL;
  78528. state->mode = EXTRA;
  78529. case EXTRA:
  78530. if (state->flags & 0x0400) {
  78531. copy = state->length;
  78532. if (copy > have) copy = have;
  78533. if (copy) {
  78534. if (state->head != Z_NULL &&
  78535. state->head->extra != Z_NULL) {
  78536. len = state->head->extra_len - state->length;
  78537. zmemcpy(state->head->extra + len, next,
  78538. len + copy > state->head->extra_max ?
  78539. state->head->extra_max - len : copy);
  78540. }
  78541. if (state->flags & 0x0200)
  78542. state->check = crc32(state->check, next, copy);
  78543. have -= copy;
  78544. next += copy;
  78545. state->length -= copy;
  78546. }
  78547. if (state->length) goto inf_leave;
  78548. }
  78549. state->length = 0;
  78550. state->mode = NAME;
  78551. case NAME:
  78552. if (state->flags & 0x0800) {
  78553. if (have == 0) goto inf_leave;
  78554. copy = 0;
  78555. do {
  78556. len = (unsigned)(next[copy++]);
  78557. if (state->head != Z_NULL &&
  78558. state->head->name != Z_NULL &&
  78559. state->length < state->head->name_max)
  78560. state->head->name[state->length++] = len;
  78561. } while (len && copy < have);
  78562. if (state->flags & 0x0200)
  78563. state->check = crc32(state->check, next, copy);
  78564. have -= copy;
  78565. next += copy;
  78566. if (len) goto inf_leave;
  78567. }
  78568. else if (state->head != Z_NULL)
  78569. state->head->name = Z_NULL;
  78570. state->length = 0;
  78571. state->mode = COMMENT;
  78572. case COMMENT:
  78573. if (state->flags & 0x1000) {
  78574. if (have == 0) goto inf_leave;
  78575. copy = 0;
  78576. do {
  78577. len = (unsigned)(next[copy++]);
  78578. if (state->head != Z_NULL &&
  78579. state->head->comment != Z_NULL &&
  78580. state->length < state->head->comm_max)
  78581. state->head->comment[state->length++] = len;
  78582. } while (len && copy < have);
  78583. if (state->flags & 0x0200)
  78584. state->check = crc32(state->check, next, copy);
  78585. have -= copy;
  78586. next += copy;
  78587. if (len) goto inf_leave;
  78588. }
  78589. else if (state->head != Z_NULL)
  78590. state->head->comment = Z_NULL;
  78591. state->mode = HCRC;
  78592. case HCRC:
  78593. if (state->flags & 0x0200) {
  78594. NEEDBITS(16);
  78595. if (hold != (state->check & 0xffff)) {
  78596. strm->msg = (char *)"header crc mismatch";
  78597. state->mode = BAD;
  78598. break;
  78599. }
  78600. INITBITS();
  78601. }
  78602. if (state->head != Z_NULL) {
  78603. state->head->hcrc = (int)((state->flags >> 9) & 1);
  78604. state->head->done = 1;
  78605. }
  78606. strm->adler = state->check = crc32(0L, Z_NULL, 0);
  78607. state->mode = TYPE;
  78608. break;
  78609. #endif
  78610. case DICTID:
  78611. NEEDBITS(32);
  78612. strm->adler = state->check = REVERSE(hold);
  78613. INITBITS();
  78614. state->mode = DICT;
  78615. case DICT:
  78616. if (state->havedict == 0) {
  78617. RESTORE();
  78618. return Z_NEED_DICT;
  78619. }
  78620. strm->adler = state->check = adler32(0L, Z_NULL, 0);
  78621. state->mode = TYPE;
  78622. case TYPE:
  78623. if (flush == Z_BLOCK) goto inf_leave;
  78624. case TYPEDO:
  78625. if (state->last) {
  78626. BYTEBITS();
  78627. state->mode = CHECK;
  78628. break;
  78629. }
  78630. NEEDBITS(3);
  78631. state->last = BITS(1);
  78632. DROPBITS(1);
  78633. switch (BITS(2)) {
  78634. case 0: /* stored block */
  78635. Tracev((stderr, "inflate: stored block%s\n",
  78636. state->last ? " (last)" : ""));
  78637. state->mode = STORED;
  78638. break;
  78639. case 1: /* fixed block */
  78640. fixedtables(state);
  78641. Tracev((stderr, "inflate: fixed codes block%s\n",
  78642. state->last ? " (last)" : ""));
  78643. state->mode = LEN; /* decode codes */
  78644. break;
  78645. case 2: /* dynamic block */
  78646. Tracev((stderr, "inflate: dynamic codes block%s\n",
  78647. state->last ? " (last)" : ""));
  78648. state->mode = TABLE;
  78649. break;
  78650. case 3:
  78651. strm->msg = (char *)"invalid block type";
  78652. state->mode = BAD;
  78653. }
  78654. DROPBITS(2);
  78655. break;
  78656. case STORED:
  78657. BYTEBITS(); /* go to byte boundary */
  78658. NEEDBITS(32);
  78659. if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
  78660. strm->msg = (char *)"invalid stored block lengths";
  78661. state->mode = BAD;
  78662. break;
  78663. }
  78664. state->length = (unsigned)hold & 0xffff;
  78665. Tracev((stderr, "inflate: stored length %u\n",
  78666. state->length));
  78667. INITBITS();
  78668. state->mode = COPY;
  78669. case COPY:
  78670. copy = state->length;
  78671. if (copy) {
  78672. if (copy > have) copy = have;
  78673. if (copy > left) copy = left;
  78674. if (copy == 0) goto inf_leave;
  78675. zmemcpy(put, next, copy);
  78676. have -= copy;
  78677. next += copy;
  78678. left -= copy;
  78679. put += copy;
  78680. state->length -= copy;
  78681. break;
  78682. }
  78683. Tracev((stderr, "inflate: stored end\n"));
  78684. state->mode = TYPE;
  78685. break;
  78686. case TABLE:
  78687. NEEDBITS(14);
  78688. state->nlen = BITS(5) + 257;
  78689. DROPBITS(5);
  78690. state->ndist = BITS(5) + 1;
  78691. DROPBITS(5);
  78692. state->ncode = BITS(4) + 4;
  78693. DROPBITS(4);
  78694. #ifndef PKZIP_BUG_WORKAROUND
  78695. if (state->nlen > 286 || state->ndist > 30) {
  78696. strm->msg = (char *)"too many length or distance symbols";
  78697. state->mode = BAD;
  78698. break;
  78699. }
  78700. #endif
  78701. Tracev((stderr, "inflate: table sizes ok\n"));
  78702. state->have = 0;
  78703. state->mode = LENLENS;
  78704. case LENLENS:
  78705. while (state->have < state->ncode) {
  78706. NEEDBITS(3);
  78707. state->lens[order[state->have++]] = (unsigned short)BITS(3);
  78708. DROPBITS(3);
  78709. }
  78710. while (state->have < 19)
  78711. state->lens[order[state->have++]] = 0;
  78712. state->next = state->codes;
  78713. state->lencode = (code const FAR *)(state->next);
  78714. state->lenbits = 7;
  78715. ret = inflate_table(CODES, state->lens, 19, &(state->next),
  78716. &(state->lenbits), state->work);
  78717. if (ret) {
  78718. strm->msg = (char *)"invalid code lengths set";
  78719. state->mode = BAD;
  78720. break;
  78721. }
  78722. Tracev((stderr, "inflate: code lengths ok\n"));
  78723. state->have = 0;
  78724. state->mode = CODELENS;
  78725. case CODELENS:
  78726. while (state->have < state->nlen + state->ndist) {
  78727. for (;;) {
  78728. thisx = state->lencode[BITS(state->lenbits)];
  78729. if ((unsigned)(thisx.bits) <= bits) break;
  78730. PULLBYTE();
  78731. }
  78732. if (thisx.val < 16) {
  78733. NEEDBITS(thisx.bits);
  78734. DROPBITS(thisx.bits);
  78735. state->lens[state->have++] = thisx.val;
  78736. }
  78737. else {
  78738. if (thisx.val == 16) {
  78739. NEEDBITS(thisx.bits + 2);
  78740. DROPBITS(thisx.bits);
  78741. if (state->have == 0) {
  78742. strm->msg = (char *)"invalid bit length repeat";
  78743. state->mode = BAD;
  78744. break;
  78745. }
  78746. len = state->lens[state->have - 1];
  78747. copy = 3 + BITS(2);
  78748. DROPBITS(2);
  78749. }
  78750. else if (thisx.val == 17) {
  78751. NEEDBITS(thisx.bits + 3);
  78752. DROPBITS(thisx.bits);
  78753. len = 0;
  78754. copy = 3 + BITS(3);
  78755. DROPBITS(3);
  78756. }
  78757. else {
  78758. NEEDBITS(thisx.bits + 7);
  78759. DROPBITS(thisx.bits);
  78760. len = 0;
  78761. copy = 11 + BITS(7);
  78762. DROPBITS(7);
  78763. }
  78764. if (state->have + copy > state->nlen + state->ndist) {
  78765. strm->msg = (char *)"invalid bit length repeat";
  78766. state->mode = BAD;
  78767. break;
  78768. }
  78769. while (copy--)
  78770. state->lens[state->have++] = (unsigned short)len;
  78771. }
  78772. }
  78773. if (state->mode == BAD) break;
  78774. state->next = state->codes;
  78775. state->lencode = (code const FAR *)(state->next);
  78776. state->lenbits = 9;
  78777. ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
  78778. &(state->lenbits), state->work);
  78779. if (ret) {
  78780. strm->msg = (char *)"invalid literal/lengths set";
  78781. state->mode = BAD;
  78782. break;
  78783. }
  78784. state->distcode = (code const FAR *)(state->next);
  78785. state->distbits = 6;
  78786. ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
  78787. &(state->next), &(state->distbits), state->work);
  78788. if (ret) {
  78789. strm->msg = (char *)"invalid distances set";
  78790. state->mode = BAD;
  78791. break;
  78792. }
  78793. Tracev((stderr, "inflate: codes ok\n"));
  78794. state->mode = LEN;
  78795. case LEN:
  78796. if (have >= 6 && left >= 258) {
  78797. RESTORE();
  78798. inflate_fast(strm, out);
  78799. LOAD();
  78800. break;
  78801. }
  78802. for (;;) {
  78803. thisx = state->lencode[BITS(state->lenbits)];
  78804. if ((unsigned)(thisx.bits) <= bits) break;
  78805. PULLBYTE();
  78806. }
  78807. if (thisx.op && (thisx.op & 0xf0) == 0) {
  78808. last = thisx;
  78809. for (;;) {
  78810. thisx = state->lencode[last.val +
  78811. (BITS(last.bits + last.op) >> last.bits)];
  78812. if ((unsigned)(last.bits + thisx.bits) <= bits) break;
  78813. PULLBYTE();
  78814. }
  78815. DROPBITS(last.bits);
  78816. }
  78817. DROPBITS(thisx.bits);
  78818. state->length = (unsigned)thisx.val;
  78819. if ((int)(thisx.op) == 0) {
  78820. Tracevv((stderr, thisx.val >= 0x20 && thisx.val < 0x7f ?
  78821. "inflate: literal '%c'\n" :
  78822. "inflate: literal 0x%02x\n", thisx.val));
  78823. state->mode = LIT;
  78824. break;
  78825. }
  78826. if (thisx.op & 32) {
  78827. Tracevv((stderr, "inflate: end of block\n"));
  78828. state->mode = TYPE;
  78829. break;
  78830. }
  78831. if (thisx.op & 64) {
  78832. strm->msg = (char *)"invalid literal/length code";
  78833. state->mode = BAD;
  78834. break;
  78835. }
  78836. state->extra = (unsigned)(thisx.op) & 15;
  78837. state->mode = LENEXT;
  78838. case LENEXT:
  78839. if (state->extra) {
  78840. NEEDBITS(state->extra);
  78841. state->length += BITS(state->extra);
  78842. DROPBITS(state->extra);
  78843. }
  78844. Tracevv((stderr, "inflate: length %u\n", state->length));
  78845. state->mode = DIST;
  78846. case DIST:
  78847. for (;;) {
  78848. thisx = state->distcode[BITS(state->distbits)];
  78849. if ((unsigned)(thisx.bits) <= bits) break;
  78850. PULLBYTE();
  78851. }
  78852. if ((thisx.op & 0xf0) == 0) {
  78853. last = thisx;
  78854. for (;;) {
  78855. thisx = state->distcode[last.val +
  78856. (BITS(last.bits + last.op) >> last.bits)];
  78857. if ((unsigned)(last.bits + thisx.bits) <= bits) break;
  78858. PULLBYTE();
  78859. }
  78860. DROPBITS(last.bits);
  78861. }
  78862. DROPBITS(thisx.bits);
  78863. if (thisx.op & 64) {
  78864. strm->msg = (char *)"invalid distance code";
  78865. state->mode = BAD;
  78866. break;
  78867. }
  78868. state->offset = (unsigned)thisx.val;
  78869. state->extra = (unsigned)(thisx.op) & 15;
  78870. state->mode = DISTEXT;
  78871. case DISTEXT:
  78872. if (state->extra) {
  78873. NEEDBITS(state->extra);
  78874. state->offset += BITS(state->extra);
  78875. DROPBITS(state->extra);
  78876. }
  78877. #ifdef INFLATE_STRICT
  78878. if (state->offset > state->dmax) {
  78879. strm->msg = (char *)"invalid distance too far back";
  78880. state->mode = BAD;
  78881. break;
  78882. }
  78883. #endif
  78884. if (state->offset > state->whave + out - left) {
  78885. strm->msg = (char *)"invalid distance too far back";
  78886. state->mode = BAD;
  78887. break;
  78888. }
  78889. Tracevv((stderr, "inflate: distance %u\n", state->offset));
  78890. state->mode = MATCH;
  78891. case MATCH:
  78892. if (left == 0) goto inf_leave;
  78893. copy = out - left;
  78894. if (state->offset > copy) { /* copy from window */
  78895. copy = state->offset - copy;
  78896. if (copy > state->write) {
  78897. copy -= state->write;
  78898. from = state->window + (state->wsize - copy);
  78899. }
  78900. else
  78901. from = state->window + (state->write - copy);
  78902. if (copy > state->length) copy = state->length;
  78903. }
  78904. else { /* copy from output */
  78905. from = put - state->offset;
  78906. copy = state->length;
  78907. }
  78908. if (copy > left) copy = left;
  78909. left -= copy;
  78910. state->length -= copy;
  78911. do {
  78912. *put++ = *from++;
  78913. } while (--copy);
  78914. if (state->length == 0) state->mode = LEN;
  78915. break;
  78916. case LIT:
  78917. if (left == 0) goto inf_leave;
  78918. *put++ = (unsigned char)(state->length);
  78919. left--;
  78920. state->mode = LEN;
  78921. break;
  78922. case CHECK:
  78923. if (state->wrap) {
  78924. NEEDBITS(32);
  78925. out -= left;
  78926. strm->total_out += out;
  78927. state->total += out;
  78928. if (out)
  78929. strm->adler = state->check =
  78930. UPDATE(state->check, put - out, out);
  78931. out = left;
  78932. if ((
  78933. #ifdef GUNZIP
  78934. state->flags ? hold :
  78935. #endif
  78936. REVERSE(hold)) != state->check) {
  78937. strm->msg = (char *)"incorrect data check";
  78938. state->mode = BAD;
  78939. break;
  78940. }
  78941. INITBITS();
  78942. Tracev((stderr, "inflate: check matches trailer\n"));
  78943. }
  78944. #ifdef GUNZIP
  78945. state->mode = LENGTH;
  78946. case LENGTH:
  78947. if (state->wrap && state->flags) {
  78948. NEEDBITS(32);
  78949. if (hold != (state->total & 0xffffffffUL)) {
  78950. strm->msg = (char *)"incorrect length check";
  78951. state->mode = BAD;
  78952. break;
  78953. }
  78954. INITBITS();
  78955. Tracev((stderr, "inflate: length matches trailer\n"));
  78956. }
  78957. #endif
  78958. state->mode = DONE;
  78959. case DONE:
  78960. ret = Z_STREAM_END;
  78961. goto inf_leave;
  78962. case BAD:
  78963. ret = Z_DATA_ERROR;
  78964. goto inf_leave;
  78965. case MEM:
  78966. return Z_MEM_ERROR;
  78967. case SYNC:
  78968. default:
  78969. return Z_STREAM_ERROR;
  78970. }
  78971. inf_leave:
  78972. RESTORE();
  78973. if (state->wsize || (state->mode < CHECK && out != strm->avail_out))
  78974. if (updatewindow(strm, out)) {
  78975. state->mode = MEM;
  78976. return Z_MEM_ERROR;
  78977. }
  78978. in -= strm->avail_in;
  78979. out -= strm->avail_out;
  78980. strm->total_in += in;
  78981. strm->total_out += out;
  78982. state->total += out;
  78983. if (state->wrap && out)
  78984. strm->adler = state->check =
  78985. UPDATE(state->check, strm->next_out - out, out);
  78986. strm->data_type = state->bits + (state->last ? 64 : 0) +
  78987. (state->mode == TYPE ? 128 : 0);
  78988. if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK)
  78989. ret = Z_BUF_ERROR;
  78990. return ret;
  78991. }
  78992. int ZEXPORT inflateEnd (z_streamp strm)
  78993. {
  78994. struct inflate_state FAR *state;
  78995. if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
  78996. return Z_STREAM_ERROR;
  78997. state = (struct inflate_state FAR *)strm->state;
  78998. if (state->window != Z_NULL) ZFREE(strm, state->window);
  78999. ZFREE(strm, strm->state);
  79000. strm->state = Z_NULL;
  79001. Tracev((stderr, "inflate: end\n"));
  79002. return Z_OK;
  79003. }
  79004. int ZEXPORT inflateSetDictionary (z_streamp strm, const Bytef *dictionary, uInt dictLength)
  79005. {
  79006. struct inflate_state FAR *state;
  79007. unsigned long id_;
  79008. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  79009. state = (struct inflate_state FAR *)strm->state;
  79010. if (state->wrap != 0 && state->mode != DICT)
  79011. return Z_STREAM_ERROR;
  79012. if (state->mode == DICT) {
  79013. id_ = adler32(0L, Z_NULL, 0);
  79014. id_ = adler32(id_, dictionary, dictLength);
  79015. if (id_ != state->check)
  79016. return Z_DATA_ERROR;
  79017. }
  79018. if (updatewindow(strm, strm->avail_out)) {
  79019. state->mode = MEM;
  79020. return Z_MEM_ERROR;
  79021. }
  79022. if (dictLength > state->wsize) {
  79023. zmemcpy(state->window, dictionary + dictLength - state->wsize,
  79024. state->wsize);
  79025. state->whave = state->wsize;
  79026. }
  79027. else {
  79028. zmemcpy(state->window + state->wsize - dictLength, dictionary,
  79029. dictLength);
  79030. state->whave = dictLength;
  79031. }
  79032. state->havedict = 1;
  79033. Tracev((stderr, "inflate: dictionary set\n"));
  79034. return Z_OK;
  79035. }
  79036. int ZEXPORT inflateGetHeader (z_streamp strm, gz_headerp head)
  79037. {
  79038. struct inflate_state FAR *state;
  79039. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  79040. state = (struct inflate_state FAR *)strm->state;
  79041. if ((state->wrap & 2) == 0) return Z_STREAM_ERROR;
  79042. state->head = head;
  79043. head->done = 0;
  79044. return Z_OK;
  79045. }
  79046. local unsigned syncsearch (unsigned FAR *have, unsigned char FAR *buf, unsigned len)
  79047. {
  79048. unsigned got;
  79049. unsigned next;
  79050. got = *have;
  79051. next = 0;
  79052. while (next < len && got < 4) {
  79053. if ((int)(buf[next]) == (got < 2 ? 0 : 0xff))
  79054. got++;
  79055. else if (buf[next])
  79056. got = 0;
  79057. else
  79058. got = 4 - got;
  79059. next++;
  79060. }
  79061. *have = got;
  79062. return next;
  79063. }
  79064. int ZEXPORT inflateSync (z_streamp strm)
  79065. {
  79066. unsigned len; /* number of bytes to look at or looked at */
  79067. unsigned long in, out; /* temporary to save total_in and total_out */
  79068. unsigned char buf[4]; /* to restore bit buffer to byte string */
  79069. struct inflate_state FAR *state;
  79070. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  79071. state = (struct inflate_state FAR *)strm->state;
  79072. if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR;
  79073. if (state->mode != SYNC) {
  79074. state->mode = SYNC;
  79075. state->hold <<= state->bits & 7;
  79076. state->bits -= state->bits & 7;
  79077. len = 0;
  79078. while (state->bits >= 8) {
  79079. buf[len++] = (unsigned char)(state->hold);
  79080. state->hold >>= 8;
  79081. state->bits -= 8;
  79082. }
  79083. state->have = 0;
  79084. syncsearch(&(state->have), buf, len);
  79085. }
  79086. len = syncsearch(&(state->have), strm->next_in, strm->avail_in);
  79087. strm->avail_in -= len;
  79088. strm->next_in += len;
  79089. strm->total_in += len;
  79090. if (state->have != 4) return Z_DATA_ERROR;
  79091. in = strm->total_in; out = strm->total_out;
  79092. inflateReset(strm);
  79093. strm->total_in = in; strm->total_out = out;
  79094. state->mode = TYPE;
  79095. return Z_OK;
  79096. }
  79097. int ZEXPORT inflateSyncPoint (z_streamp strm)
  79098. {
  79099. struct inflate_state FAR *state;
  79100. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  79101. state = (struct inflate_state FAR *)strm->state;
  79102. return state->mode == STORED && state->bits == 0;
  79103. }
  79104. int ZEXPORT inflateCopy(z_streamp dest, z_streamp source)
  79105. {
  79106. struct inflate_state FAR *state;
  79107. struct inflate_state FAR *copy;
  79108. unsigned char FAR *window;
  79109. unsigned wsize;
  79110. if (dest == Z_NULL || source == Z_NULL || source->state == Z_NULL ||
  79111. source->zalloc == (alloc_func)0 || source->zfree == (free_func)0)
  79112. return Z_STREAM_ERROR;
  79113. state = (struct inflate_state FAR *)source->state;
  79114. copy = (struct inflate_state FAR *)
  79115. ZALLOC(source, 1, sizeof(struct inflate_state));
  79116. if (copy == Z_NULL) return Z_MEM_ERROR;
  79117. window = Z_NULL;
  79118. if (state->window != Z_NULL) {
  79119. window = (unsigned char FAR *)
  79120. ZALLOC(source, 1U << state->wbits, sizeof(unsigned char));
  79121. if (window == Z_NULL) {
  79122. ZFREE(source, copy);
  79123. return Z_MEM_ERROR;
  79124. }
  79125. }
  79126. zmemcpy(dest, source, sizeof(z_stream));
  79127. zmemcpy(copy, state, sizeof(struct inflate_state));
  79128. if (state->lencode >= state->codes &&
  79129. state->lencode <= state->codes + ENOUGH - 1) {
  79130. copy->lencode = copy->codes + (state->lencode - state->codes);
  79131. copy->distcode = copy->codes + (state->distcode - state->codes);
  79132. }
  79133. copy->next = copy->codes + (state->next - state->codes);
  79134. if (window != Z_NULL) {
  79135. wsize = 1U << state->wbits;
  79136. zmemcpy(window, state->window, wsize);
  79137. }
  79138. copy->window = window;
  79139. dest->state = (struct internal_state FAR *)copy;
  79140. return Z_OK;
  79141. }
  79142. /*** End of inlined file: inflate.c ***/
  79143. /*** Start of inlined file: inftrees.c ***/
  79144. #define MAXBITS 15
  79145. const char inflate_copyright[] =
  79146. " inflate 1.2.3 Copyright 1995-2005 Mark Adler ";
  79147. int inflate_table (codetype type,
  79148. unsigned short FAR *lens,
  79149. unsigned codes,
  79150. code FAR * FAR *table,
  79151. unsigned FAR *bits,
  79152. unsigned short FAR *work)
  79153. {
  79154. unsigned len; /* a code's length in bits */
  79155. unsigned sym; /* index of code symbols */
  79156. unsigned min, max; /* minimum and maximum code lengths */
  79157. unsigned root; /* number of index bits for root table */
  79158. unsigned curr; /* number of index bits for current table */
  79159. unsigned drop; /* code bits to drop for sub-table */
  79160. int left; /* number of prefix codes available */
  79161. unsigned used; /* code entries in table used */
  79162. unsigned huff; /* Huffman code */
  79163. unsigned incr; /* for incrementing code, index */
  79164. unsigned fill; /* index for replicating entries */
  79165. unsigned low; /* low bits for current root entry */
  79166. unsigned mask; /* mask for low root bits */
  79167. code thisx; /* table entry for duplication */
  79168. code FAR *next; /* next available space in table */
  79169. const unsigned short FAR *base; /* base value table to use */
  79170. const unsigned short FAR *extra; /* extra bits table to use */
  79171. int end; /* use base and extra for symbol > end */
  79172. unsigned short count[MAXBITS+1]; /* number of codes of each length */
  79173. unsigned short offs[MAXBITS+1]; /* offsets in table for each length */
  79174. static const unsigned short lbase[31] = { /* Length codes 257..285 base */
  79175. 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
  79176. 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
  79177. static const unsigned short lext[31] = { /* Length codes 257..285 extra */
  79178. 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
  79179. 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 201, 196};
  79180. static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
  79181. 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
  79182. 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
  79183. 8193, 12289, 16385, 24577, 0, 0};
  79184. static const unsigned short dext[32] = { /* Distance codes 0..29 extra */
  79185. 16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22,
  79186. 23, 23, 24, 24, 25, 25, 26, 26, 27, 27,
  79187. 28, 28, 29, 29, 64, 64};
  79188. for (len = 0; len <= MAXBITS; len++)
  79189. count[len] = 0;
  79190. for (sym = 0; sym < codes; sym++)
  79191. count[lens[sym]]++;
  79192. root = *bits;
  79193. for (max = MAXBITS; max >= 1; max--)
  79194. if (count[max] != 0) break;
  79195. if (root > max) root = max;
  79196. if (max == 0) { /* no symbols to code at all */
  79197. thisx.op = (unsigned char)64; /* invalid code marker */
  79198. thisx.bits = (unsigned char)1;
  79199. thisx.val = (unsigned short)0;
  79200. *(*table)++ = thisx; /* make a table to force an error */
  79201. *(*table)++ = thisx;
  79202. *bits = 1;
  79203. return 0; /* no symbols, but wait for decoding to report error */
  79204. }
  79205. for (min = 1; min <= MAXBITS; min++)
  79206. if (count[min] != 0) break;
  79207. if (root < min) root = min;
  79208. left = 1;
  79209. for (len = 1; len <= MAXBITS; len++) {
  79210. left <<= 1;
  79211. left -= count[len];
  79212. if (left < 0) return -1; /* over-subscribed */
  79213. }
  79214. if (left > 0 && (type == CODES || max != 1))
  79215. return -1; /* incomplete set */
  79216. offs[1] = 0;
  79217. for (len = 1; len < MAXBITS; len++)
  79218. offs[len + 1] = offs[len] + count[len];
  79219. for (sym = 0; sym < codes; sym++)
  79220. if (lens[sym] != 0) work[offs[lens[sym]]++] = (unsigned short)sym;
  79221. switch (type) {
  79222. case CODES:
  79223. base = extra = work; /* dummy value--not used */
  79224. end = 19;
  79225. break;
  79226. case LENS:
  79227. base = lbase;
  79228. base -= 257;
  79229. extra = lext;
  79230. extra -= 257;
  79231. end = 256;
  79232. break;
  79233. default: /* DISTS */
  79234. base = dbase;
  79235. extra = dext;
  79236. end = -1;
  79237. }
  79238. huff = 0; /* starting code */
  79239. sym = 0; /* starting code symbol */
  79240. len = min; /* starting code length */
  79241. next = *table; /* current table to fill in */
  79242. curr = root; /* current table index bits */
  79243. drop = 0; /* current bits to drop from code for index */
  79244. low = (unsigned)(-1); /* trigger new sub-table when len > root */
  79245. used = 1U << root; /* use root table entries */
  79246. mask = used - 1; /* mask for comparing low */
  79247. if (type == LENS && used >= ENOUGH - MAXD)
  79248. return 1;
  79249. for (;;) {
  79250. thisx.bits = (unsigned char)(len - drop);
  79251. if ((int)(work[sym]) < end) {
  79252. thisx.op = (unsigned char)0;
  79253. thisx.val = work[sym];
  79254. }
  79255. else if ((int)(work[sym]) > end) {
  79256. thisx.op = (unsigned char)(extra[work[sym]]);
  79257. thisx.val = base[work[sym]];
  79258. }
  79259. else {
  79260. thisx.op = (unsigned char)(32 + 64); /* end of block */
  79261. thisx.val = 0;
  79262. }
  79263. incr = 1U << (len - drop);
  79264. fill = 1U << curr;
  79265. min = fill; /* save offset to next table */
  79266. do {
  79267. fill -= incr;
  79268. next[(huff >> drop) + fill] = thisx;
  79269. } while (fill != 0);
  79270. incr = 1U << (len - 1);
  79271. while (huff & incr)
  79272. incr >>= 1;
  79273. if (incr != 0) {
  79274. huff &= incr - 1;
  79275. huff += incr;
  79276. }
  79277. else
  79278. huff = 0;
  79279. sym++;
  79280. if (--(count[len]) == 0) {
  79281. if (len == max) break;
  79282. len = lens[work[sym]];
  79283. }
  79284. if (len > root && (huff & mask) != low) {
  79285. if (drop == 0)
  79286. drop = root;
  79287. next += min; /* here min is 1 << curr */
  79288. curr = len - drop;
  79289. left = (int)(1 << curr);
  79290. while (curr + drop < max) {
  79291. left -= count[curr + drop];
  79292. if (left <= 0) break;
  79293. curr++;
  79294. left <<= 1;
  79295. }
  79296. used += 1U << curr;
  79297. if (type == LENS && used >= ENOUGH - MAXD)
  79298. return 1;
  79299. low = huff & mask;
  79300. (*table)[low].op = (unsigned char)curr;
  79301. (*table)[low].bits = (unsigned char)root;
  79302. (*table)[low].val = (unsigned short)(next - *table);
  79303. }
  79304. }
  79305. thisx.op = (unsigned char)64; /* invalid code marker */
  79306. thisx.bits = (unsigned char)(len - drop);
  79307. thisx.val = (unsigned short)0;
  79308. while (huff != 0) {
  79309. if (drop != 0 && (huff & mask) != low) {
  79310. drop = 0;
  79311. len = root;
  79312. next = *table;
  79313. thisx.bits = (unsigned char)len;
  79314. }
  79315. next[huff >> drop] = thisx;
  79316. incr = 1U << (len - 1);
  79317. while (huff & incr)
  79318. incr >>= 1;
  79319. if (incr != 0) {
  79320. huff &= incr - 1;
  79321. huff += incr;
  79322. }
  79323. else
  79324. huff = 0;
  79325. }
  79326. *table += used;
  79327. *bits = root;
  79328. return 0;
  79329. }
  79330. /*** End of inlined file: inftrees.c ***/
  79331. /*** Start of inlined file: trees.c ***/
  79332. #ifdef DEBUG
  79333. # include <ctype.h>
  79334. #endif
  79335. #define MAX_BL_BITS 7
  79336. #define END_BLOCK 256
  79337. #define REP_3_6 16
  79338. #define REPZ_3_10 17
  79339. #define REPZ_11_138 18
  79340. local const int extra_lbits[LENGTH_CODES] /* extra bits for each length code */
  79341. = {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};
  79342. local const int extra_dbits[D_CODES] /* extra bits for each distance code */
  79343. = {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};
  79344. local const int extra_blbits[BL_CODES]/* extra bits for each bit length code */
  79345. = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7};
  79346. local const uch bl_order[BL_CODES]
  79347. = {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15};
  79348. #define Buf_size (8 * 2*sizeof(char))
  79349. #define DIST_CODE_LEN 512 /* see definition of array dist_code below */
  79350. #if defined(GEN_TREES_H) || !defined(STDC)
  79351. local ct_data static_ltree[L_CODES+2];
  79352. local ct_data static_dtree[D_CODES];
  79353. uch _dist_code[DIST_CODE_LEN];
  79354. uch _length_code[MAX_MATCH-MIN_MATCH+1];
  79355. local int base_length[LENGTH_CODES];
  79356. local int base_dist[D_CODES];
  79357. #else
  79358. /*** Start of inlined file: trees.h ***/
  79359. local const ct_data static_ltree[L_CODES+2] = {
  79360. {{ 12},{ 8}}, {{140},{ 8}}, {{ 76},{ 8}}, {{204},{ 8}}, {{ 44},{ 8}},
  79361. {{172},{ 8}}, {{108},{ 8}}, {{236},{ 8}}, {{ 28},{ 8}}, {{156},{ 8}},
  79362. {{ 92},{ 8}}, {{220},{ 8}}, {{ 60},{ 8}}, {{188},{ 8}}, {{124},{ 8}},
  79363. {{252},{ 8}}, {{ 2},{ 8}}, {{130},{ 8}}, {{ 66},{ 8}}, {{194},{ 8}},
  79364. {{ 34},{ 8}}, {{162},{ 8}}, {{ 98},{ 8}}, {{226},{ 8}}, {{ 18},{ 8}},
  79365. {{146},{ 8}}, {{ 82},{ 8}}, {{210},{ 8}}, {{ 50},{ 8}}, {{178},{ 8}},
  79366. {{114},{ 8}}, {{242},{ 8}}, {{ 10},{ 8}}, {{138},{ 8}}, {{ 74},{ 8}},
  79367. {{202},{ 8}}, {{ 42},{ 8}}, {{170},{ 8}}, {{106},{ 8}}, {{234},{ 8}},
  79368. {{ 26},{ 8}}, {{154},{ 8}}, {{ 90},{ 8}}, {{218},{ 8}}, {{ 58},{ 8}},
  79369. {{186},{ 8}}, {{122},{ 8}}, {{250},{ 8}}, {{ 6},{ 8}}, {{134},{ 8}},
  79370. {{ 70},{ 8}}, {{198},{ 8}}, {{ 38},{ 8}}, {{166},{ 8}}, {{102},{ 8}},
  79371. {{230},{ 8}}, {{ 22},{ 8}}, {{150},{ 8}}, {{ 86},{ 8}}, {{214},{ 8}},
  79372. {{ 54},{ 8}}, {{182},{ 8}}, {{118},{ 8}}, {{246},{ 8}}, {{ 14},{ 8}},
  79373. {{142},{ 8}}, {{ 78},{ 8}}, {{206},{ 8}}, {{ 46},{ 8}}, {{174},{ 8}},
  79374. {{110},{ 8}}, {{238},{ 8}}, {{ 30},{ 8}}, {{158},{ 8}}, {{ 94},{ 8}},
  79375. {{222},{ 8}}, {{ 62},{ 8}}, {{190},{ 8}}, {{126},{ 8}}, {{254},{ 8}},
  79376. {{ 1},{ 8}}, {{129},{ 8}}, {{ 65},{ 8}}, {{193},{ 8}}, {{ 33},{ 8}},
  79377. {{161},{ 8}}, {{ 97},{ 8}}, {{225},{ 8}}, {{ 17},{ 8}}, {{145},{ 8}},
  79378. {{ 81},{ 8}}, {{209},{ 8}}, {{ 49},{ 8}}, {{177},{ 8}}, {{113},{ 8}},
  79379. {{241},{ 8}}, {{ 9},{ 8}}, {{137},{ 8}}, {{ 73},{ 8}}, {{201},{ 8}},
  79380. {{ 41},{ 8}}, {{169},{ 8}}, {{105},{ 8}}, {{233},{ 8}}, {{ 25},{ 8}},
  79381. {{153},{ 8}}, {{ 89},{ 8}}, {{217},{ 8}}, {{ 57},{ 8}}, {{185},{ 8}},
  79382. {{121},{ 8}}, {{249},{ 8}}, {{ 5},{ 8}}, {{133},{ 8}}, {{ 69},{ 8}},
  79383. {{197},{ 8}}, {{ 37},{ 8}}, {{165},{ 8}}, {{101},{ 8}}, {{229},{ 8}},
  79384. {{ 21},{ 8}}, {{149},{ 8}}, {{ 85},{ 8}}, {{213},{ 8}}, {{ 53},{ 8}},
  79385. {{181},{ 8}}, {{117},{ 8}}, {{245},{ 8}}, {{ 13},{ 8}}, {{141},{ 8}},
  79386. {{ 77},{ 8}}, {{205},{ 8}}, {{ 45},{ 8}}, {{173},{ 8}}, {{109},{ 8}},
  79387. {{237},{ 8}}, {{ 29},{ 8}}, {{157},{ 8}}, {{ 93},{ 8}}, {{221},{ 8}},
  79388. {{ 61},{ 8}}, {{189},{ 8}}, {{125},{ 8}}, {{253},{ 8}}, {{ 19},{ 9}},
  79389. {{275},{ 9}}, {{147},{ 9}}, {{403},{ 9}}, {{ 83},{ 9}}, {{339},{ 9}},
  79390. {{211},{ 9}}, {{467},{ 9}}, {{ 51},{ 9}}, {{307},{ 9}}, {{179},{ 9}},
  79391. {{435},{ 9}}, {{115},{ 9}}, {{371},{ 9}}, {{243},{ 9}}, {{499},{ 9}},
  79392. {{ 11},{ 9}}, {{267},{ 9}}, {{139},{ 9}}, {{395},{ 9}}, {{ 75},{ 9}},
  79393. {{331},{ 9}}, {{203},{ 9}}, {{459},{ 9}}, {{ 43},{ 9}}, {{299},{ 9}},
  79394. {{171},{ 9}}, {{427},{ 9}}, {{107},{ 9}}, {{363},{ 9}}, {{235},{ 9}},
  79395. {{491},{ 9}}, {{ 27},{ 9}}, {{283},{ 9}}, {{155},{ 9}}, {{411},{ 9}},
  79396. {{ 91},{ 9}}, {{347},{ 9}}, {{219},{ 9}}, {{475},{ 9}}, {{ 59},{ 9}},
  79397. {{315},{ 9}}, {{187},{ 9}}, {{443},{ 9}}, {{123},{ 9}}, {{379},{ 9}},
  79398. {{251},{ 9}}, {{507},{ 9}}, {{ 7},{ 9}}, {{263},{ 9}}, {{135},{ 9}},
  79399. {{391},{ 9}}, {{ 71},{ 9}}, {{327},{ 9}}, {{199},{ 9}}, {{455},{ 9}},
  79400. {{ 39},{ 9}}, {{295},{ 9}}, {{167},{ 9}}, {{423},{ 9}}, {{103},{ 9}},
  79401. {{359},{ 9}}, {{231},{ 9}}, {{487},{ 9}}, {{ 23},{ 9}}, {{279},{ 9}},
  79402. {{151},{ 9}}, {{407},{ 9}}, {{ 87},{ 9}}, {{343},{ 9}}, {{215},{ 9}},
  79403. {{471},{ 9}}, {{ 55},{ 9}}, {{311},{ 9}}, {{183},{ 9}}, {{439},{ 9}},
  79404. {{119},{ 9}}, {{375},{ 9}}, {{247},{ 9}}, {{503},{ 9}}, {{ 15},{ 9}},
  79405. {{271},{ 9}}, {{143},{ 9}}, {{399},{ 9}}, {{ 79},{ 9}}, {{335},{ 9}},
  79406. {{207},{ 9}}, {{463},{ 9}}, {{ 47},{ 9}}, {{303},{ 9}}, {{175},{ 9}},
  79407. {{431},{ 9}}, {{111},{ 9}}, {{367},{ 9}}, {{239},{ 9}}, {{495},{ 9}},
  79408. {{ 31},{ 9}}, {{287},{ 9}}, {{159},{ 9}}, {{415},{ 9}}, {{ 95},{ 9}},
  79409. {{351},{ 9}}, {{223},{ 9}}, {{479},{ 9}}, {{ 63},{ 9}}, {{319},{ 9}},
  79410. {{191},{ 9}}, {{447},{ 9}}, {{127},{ 9}}, {{383},{ 9}}, {{255},{ 9}},
  79411. {{511},{ 9}}, {{ 0},{ 7}}, {{ 64},{ 7}}, {{ 32},{ 7}}, {{ 96},{ 7}},
  79412. {{ 16},{ 7}}, {{ 80},{ 7}}, {{ 48},{ 7}}, {{112},{ 7}}, {{ 8},{ 7}},
  79413. {{ 72},{ 7}}, {{ 40},{ 7}}, {{104},{ 7}}, {{ 24},{ 7}}, {{ 88},{ 7}},
  79414. {{ 56},{ 7}}, {{120},{ 7}}, {{ 4},{ 7}}, {{ 68},{ 7}}, {{ 36},{ 7}},
  79415. {{100},{ 7}}, {{ 20},{ 7}}, {{ 84},{ 7}}, {{ 52},{ 7}}, {{116},{ 7}},
  79416. {{ 3},{ 8}}, {{131},{ 8}}, {{ 67},{ 8}}, {{195},{ 8}}, {{ 35},{ 8}},
  79417. {{163},{ 8}}, {{ 99},{ 8}}, {{227},{ 8}}
  79418. };
  79419. local const ct_data static_dtree[D_CODES] = {
  79420. {{ 0},{ 5}}, {{16},{ 5}}, {{ 8},{ 5}}, {{24},{ 5}}, {{ 4},{ 5}},
  79421. {{20},{ 5}}, {{12},{ 5}}, {{28},{ 5}}, {{ 2},{ 5}}, {{18},{ 5}},
  79422. {{10},{ 5}}, {{26},{ 5}}, {{ 6},{ 5}}, {{22},{ 5}}, {{14},{ 5}},
  79423. {{30},{ 5}}, {{ 1},{ 5}}, {{17},{ 5}}, {{ 9},{ 5}}, {{25},{ 5}},
  79424. {{ 5},{ 5}}, {{21},{ 5}}, {{13},{ 5}}, {{29},{ 5}}, {{ 3},{ 5}},
  79425. {{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}}
  79426. };
  79427. const uch _dist_code[DIST_CODE_LEN] = {
  79428. 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8,
  79429. 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10,
  79430. 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
  79431. 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
  79432. 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13,
  79433. 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
  79434. 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  79435. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  79436. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  79437. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15,
  79438. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  79439. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  79440. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 16, 17,
  79441. 18, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22,
  79442. 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  79443. 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
  79444. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
  79445. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27,
  79446. 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
  79447. 27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  79448. 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  79449. 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  79450. 28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  79451. 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  79452. 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  79453. 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29
  79454. };
  79455. const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {
  79456. 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12,
  79457. 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16,
  79458. 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19,
  79459. 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  79460. 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22,
  79461. 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23,
  79462. 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  79463. 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  79464. 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
  79465. 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26,
  79466. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
  79467. 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
  79468. 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28
  79469. };
  79470. local const int base_length[LENGTH_CODES] = {
  79471. 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56,
  79472. 64, 80, 96, 112, 128, 160, 192, 224, 0
  79473. };
  79474. local const int base_dist[D_CODES] = {
  79475. 0, 1, 2, 3, 4, 6, 8, 12, 16, 24,
  79476. 32, 48, 64, 96, 128, 192, 256, 384, 512, 768,
  79477. 1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576
  79478. };
  79479. /*** End of inlined file: trees.h ***/
  79480. #endif /* GEN_TREES_H */
  79481. struct static_tree_desc_s {
  79482. const ct_data *static_tree; /* static tree or NULL */
  79483. const intf *extra_bits; /* extra bits for each code or NULL */
  79484. int extra_base; /* base index for extra_bits */
  79485. int elems; /* max number of elements in the tree */
  79486. int max_length; /* max bit length for the codes */
  79487. };
  79488. local static_tree_desc static_l_desc =
  79489. {static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS};
  79490. local static_tree_desc static_d_desc =
  79491. {static_dtree, extra_dbits, 0, D_CODES, MAX_BITS};
  79492. local static_tree_desc static_bl_desc =
  79493. {(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS};
  79494. local void tr_static_init OF((void));
  79495. local void init_block OF((deflate_state *s));
  79496. local void pqdownheap OF((deflate_state *s, ct_data *tree, int k));
  79497. local void gen_bitlen OF((deflate_state *s, tree_desc *desc));
  79498. local void gen_codes OF((ct_data *tree, int max_code, ushf *bl_count));
  79499. local void build_tree OF((deflate_state *s, tree_desc *desc));
  79500. local void scan_tree OF((deflate_state *s, ct_data *tree, int max_code));
  79501. local void send_tree OF((deflate_state *s, ct_data *tree, int max_code));
  79502. local int build_bl_tree OF((deflate_state *s));
  79503. local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes,
  79504. int blcodes));
  79505. local void compress_block OF((deflate_state *s, ct_data *ltree,
  79506. ct_data *dtree));
  79507. local void set_data_type OF((deflate_state *s));
  79508. local unsigned bi_reverse OF((unsigned value, int length));
  79509. local void bi_windup OF((deflate_state *s));
  79510. local void bi_flush OF((deflate_state *s));
  79511. local void copy_block OF((deflate_state *s, charf *buf, unsigned len,
  79512. int header));
  79513. #ifdef GEN_TREES_H
  79514. local void gen_trees_header OF((void));
  79515. #endif
  79516. #ifndef DEBUG
  79517. # define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len)
  79518. #else /* DEBUG */
  79519. # define send_code(s, c, tree) \
  79520. { if (z_verbose>2) fprintf(stderr,"\ncd %3d ",(c)); \
  79521. send_bits(s, tree[c].Code, tree[c].Len); }
  79522. #endif
  79523. #define put_short(s, w) { \
  79524. put_byte(s, (uch)((w) & 0xff)); \
  79525. put_byte(s, (uch)((ush)(w) >> 8)); \
  79526. }
  79527. #ifdef DEBUG
  79528. local void send_bits OF((deflate_state *s, int value, int length));
  79529. local void send_bits (deflate_state *s, int value, int length)
  79530. {
  79531. Tracevv((stderr," l %2d v %4x ", length, value));
  79532. Assert(length > 0 && length <= 15, "invalid length");
  79533. s->bits_sent += (ulg)length;
  79534. if (s->bi_valid > (int)Buf_size - length) {
  79535. s->bi_buf |= (value << s->bi_valid);
  79536. put_short(s, s->bi_buf);
  79537. s->bi_buf = (ush)value >> (Buf_size - s->bi_valid);
  79538. s->bi_valid += length - Buf_size;
  79539. } else {
  79540. s->bi_buf |= value << s->bi_valid;
  79541. s->bi_valid += length;
  79542. }
  79543. }
  79544. #else /* !DEBUG */
  79545. #define send_bits(s, value, length) \
  79546. { int len = length;\
  79547. if (s->bi_valid > (int)Buf_size - len) {\
  79548. int val = value;\
  79549. s->bi_buf |= (val << s->bi_valid);\
  79550. put_short(s, s->bi_buf);\
  79551. s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\
  79552. s->bi_valid += len - Buf_size;\
  79553. } else {\
  79554. s->bi_buf |= (value) << s->bi_valid;\
  79555. s->bi_valid += len;\
  79556. }\
  79557. }
  79558. #endif /* DEBUG */
  79559. local void tr_static_init()
  79560. {
  79561. #if defined(GEN_TREES_H) || !defined(STDC)
  79562. static int static_init_done = 0;
  79563. int n; /* iterates over tree elements */
  79564. int bits; /* bit counter */
  79565. int length; /* length value */
  79566. int code; /* code value */
  79567. int dist; /* distance index */
  79568. ush bl_count[MAX_BITS+1];
  79569. if (static_init_done) return;
  79570. static_l_desc.static_tree = static_ltree;
  79571. static_l_desc.extra_bits = extra_lbits;
  79572. static_d_desc.static_tree = static_dtree;
  79573. static_d_desc.extra_bits = extra_dbits;
  79574. static_bl_desc.extra_bits = extra_blbits;
  79575. length = 0;
  79576. for (code = 0; code < LENGTH_CODES-1; code++) {
  79577. base_length[code] = length;
  79578. for (n = 0; n < (1<<extra_lbits[code]); n++) {
  79579. _length_code[length++] = (uch)code;
  79580. }
  79581. }
  79582. Assert (length == 256, "tr_static_init: length != 256");
  79583. _length_code[length-1] = (uch)code;
  79584. dist = 0;
  79585. for (code = 0 ; code < 16; code++) {
  79586. base_dist[code] = dist;
  79587. for (n = 0; n < (1<<extra_dbits[code]); n++) {
  79588. _dist_code[dist++] = (uch)code;
  79589. }
  79590. }
  79591. Assert (dist == 256, "tr_static_init: dist != 256");
  79592. dist >>= 7; /* from now on, all distances are divided by 128 */
  79593. for ( ; code < D_CODES; code++) {
  79594. base_dist[code] = dist << 7;
  79595. for (n = 0; n < (1<<(extra_dbits[code]-7)); n++) {
  79596. _dist_code[256 + dist++] = (uch)code;
  79597. }
  79598. }
  79599. Assert (dist == 256, "tr_static_init: 256+dist != 512");
  79600. for (bits = 0; bits <= MAX_BITS; bits++) bl_count[bits] = 0;
  79601. n = 0;
  79602. while (n <= 143) static_ltree[n++].Len = 8, bl_count[8]++;
  79603. while (n <= 255) static_ltree[n++].Len = 9, bl_count[9]++;
  79604. while (n <= 279) static_ltree[n++].Len = 7, bl_count[7]++;
  79605. while (n <= 287) static_ltree[n++].Len = 8, bl_count[8]++;
  79606. gen_codes((ct_data *)static_ltree, L_CODES+1, bl_count);
  79607. for (n = 0; n < D_CODES; n++) {
  79608. static_dtree[n].Len = 5;
  79609. static_dtree[n].Code = bi_reverse((unsigned)n, 5);
  79610. }
  79611. static_init_done = 1;
  79612. # ifdef GEN_TREES_H
  79613. gen_trees_header();
  79614. # endif
  79615. #endif /* defined(GEN_TREES_H) || !defined(STDC) */
  79616. }
  79617. #ifdef GEN_TREES_H
  79618. # ifndef DEBUG
  79619. # include <stdio.h>
  79620. # endif
  79621. # define SEPARATOR(i, last, width) \
  79622. ((i) == (last)? "\n};\n\n" : \
  79623. ((i) % (width) == (width)-1 ? ",\n" : ", "))
  79624. void gen_trees_header()
  79625. {
  79626. FILE *header = fopen("trees.h", "w");
  79627. int i;
  79628. Assert (header != NULL, "Can't open trees.h");
  79629. fprintf(header,
  79630. "/* header created automatically with -DGEN_TREES_H */\n\n");
  79631. fprintf(header, "local const ct_data static_ltree[L_CODES+2] = {\n");
  79632. for (i = 0; i < L_CODES+2; i++) {
  79633. fprintf(header, "{{%3u},{%3u}}%s", static_ltree[i].Code,
  79634. static_ltree[i].Len, SEPARATOR(i, L_CODES+1, 5));
  79635. }
  79636. fprintf(header, "local const ct_data static_dtree[D_CODES] = {\n");
  79637. for (i = 0; i < D_CODES; i++) {
  79638. fprintf(header, "{{%2u},{%2u}}%s", static_dtree[i].Code,
  79639. static_dtree[i].Len, SEPARATOR(i, D_CODES-1, 5));
  79640. }
  79641. fprintf(header, "const uch _dist_code[DIST_CODE_LEN] = {\n");
  79642. for (i = 0; i < DIST_CODE_LEN; i++) {
  79643. fprintf(header, "%2u%s", _dist_code[i],
  79644. SEPARATOR(i, DIST_CODE_LEN-1, 20));
  79645. }
  79646. fprintf(header, "const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {\n");
  79647. for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) {
  79648. fprintf(header, "%2u%s", _length_code[i],
  79649. SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20));
  79650. }
  79651. fprintf(header, "local const int base_length[LENGTH_CODES] = {\n");
  79652. for (i = 0; i < LENGTH_CODES; i++) {
  79653. fprintf(header, "%1u%s", base_length[i],
  79654. SEPARATOR(i, LENGTH_CODES-1, 20));
  79655. }
  79656. fprintf(header, "local const int base_dist[D_CODES] = {\n");
  79657. for (i = 0; i < D_CODES; i++) {
  79658. fprintf(header, "%5u%s", base_dist[i],
  79659. SEPARATOR(i, D_CODES-1, 10));
  79660. }
  79661. fclose(header);
  79662. }
  79663. #endif /* GEN_TREES_H */
  79664. void _tr_init(deflate_state *s)
  79665. {
  79666. tr_static_init();
  79667. s->l_desc.dyn_tree = s->dyn_ltree;
  79668. s->l_desc.stat_desc = &static_l_desc;
  79669. s->d_desc.dyn_tree = s->dyn_dtree;
  79670. s->d_desc.stat_desc = &static_d_desc;
  79671. s->bl_desc.dyn_tree = s->bl_tree;
  79672. s->bl_desc.stat_desc = &static_bl_desc;
  79673. s->bi_buf = 0;
  79674. s->bi_valid = 0;
  79675. s->last_eob_len = 8; /* enough lookahead for inflate */
  79676. #ifdef DEBUG
  79677. s->compressed_len = 0L;
  79678. s->bits_sent = 0L;
  79679. #endif
  79680. init_block(s);
  79681. }
  79682. local void init_block (deflate_state *s)
  79683. {
  79684. int n; /* iterates over tree elements */
  79685. for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0;
  79686. for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0;
  79687. for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0;
  79688. s->dyn_ltree[END_BLOCK].Freq = 1;
  79689. s->opt_len = s->static_len = 0L;
  79690. s->last_lit = s->matches = 0;
  79691. }
  79692. #define SMALLEST 1
  79693. #define pqremove(s, tree, top) \
  79694. {\
  79695. top = s->heap[SMALLEST]; \
  79696. s->heap[SMALLEST] = s->heap[s->heap_len--]; \
  79697. pqdownheap(s, tree, SMALLEST); \
  79698. }
  79699. #define smaller(tree, n, m, depth) \
  79700. (tree[n].Freq < tree[m].Freq || \
  79701. (tree[n].Freq == tree[m].Freq && depth[n] <= depth[m]))
  79702. local void pqdownheap (deflate_state *s,
  79703. ct_data *tree, /* the tree to restore */
  79704. int k) /* node to move down */
  79705. {
  79706. int v = s->heap[k];
  79707. int j = k << 1; /* left son of k */
  79708. while (j <= s->heap_len) {
  79709. if (j < s->heap_len &&
  79710. smaller(tree, s->heap[j+1], s->heap[j], s->depth)) {
  79711. j++;
  79712. }
  79713. if (smaller(tree, v, s->heap[j], s->depth)) break;
  79714. s->heap[k] = s->heap[j]; k = j;
  79715. j <<= 1;
  79716. }
  79717. s->heap[k] = v;
  79718. }
  79719. local void gen_bitlen (deflate_state *s, tree_desc *desc)
  79720. {
  79721. ct_data *tree = desc->dyn_tree;
  79722. int max_code = desc->max_code;
  79723. const ct_data *stree = desc->stat_desc->static_tree;
  79724. const intf *extra = desc->stat_desc->extra_bits;
  79725. int base = desc->stat_desc->extra_base;
  79726. int max_length = desc->stat_desc->max_length;
  79727. int h; /* heap index */
  79728. int n, m; /* iterate over the tree elements */
  79729. int bits; /* bit length */
  79730. int xbits; /* extra bits */
  79731. ush f; /* frequency */
  79732. int overflow = 0; /* number of elements with bit length too large */
  79733. for (bits = 0; bits <= MAX_BITS; bits++) s->bl_count[bits] = 0;
  79734. tree[s->heap[s->heap_max]].Len = 0; /* root of the heap */
  79735. for (h = s->heap_max+1; h < HEAP_SIZE; h++) {
  79736. n = s->heap[h];
  79737. bits = tree[tree[n].Dad].Len + 1;
  79738. if (bits > max_length) bits = max_length, overflow++;
  79739. tree[n].Len = (ush)bits;
  79740. if (n > max_code) continue; /* not a leaf node */
  79741. s->bl_count[bits]++;
  79742. xbits = 0;
  79743. if (n >= base) xbits = extra[n-base];
  79744. f = tree[n].Freq;
  79745. s->opt_len += (ulg)f * (bits + xbits);
  79746. if (stree) s->static_len += (ulg)f * (stree[n].Len + xbits);
  79747. }
  79748. if (overflow == 0) return;
  79749. Trace((stderr,"\nbit length overflow\n"));
  79750. do {
  79751. bits = max_length-1;
  79752. while (s->bl_count[bits] == 0) bits--;
  79753. s->bl_count[bits]--; /* move one leaf down the tree */
  79754. s->bl_count[bits+1] += 2; /* move one overflow item as its brother */
  79755. s->bl_count[max_length]--;
  79756. overflow -= 2;
  79757. } while (overflow > 0);
  79758. for (bits = max_length; bits != 0; bits--) {
  79759. n = s->bl_count[bits];
  79760. while (n != 0) {
  79761. m = s->heap[--h];
  79762. if (m > max_code) continue;
  79763. if ((unsigned) tree[m].Len != (unsigned) bits) {
  79764. Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
  79765. s->opt_len += ((long)bits - (long)tree[m].Len)
  79766. *(long)tree[m].Freq;
  79767. tree[m].Len = (ush)bits;
  79768. }
  79769. n--;
  79770. }
  79771. }
  79772. }
  79773. local void gen_codes (ct_data *tree, /* the tree to decorate */
  79774. int max_code, /* largest code with non zero frequency */
  79775. ushf *bl_count) /* number of codes at each bit length */
  79776. {
  79777. ush next_code[MAX_BITS+1]; /* next code value for each bit length */
  79778. ush code = 0; /* running code value */
  79779. int bits; /* bit index */
  79780. int n; /* code index */
  79781. for (bits = 1; bits <= MAX_BITS; bits++) {
  79782. next_code[bits] = code = (code + bl_count[bits-1]) << 1;
  79783. }
  79784. Assert (code + bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1,
  79785. "inconsistent bit counts");
  79786. Tracev((stderr,"\ngen_codes: max_code %d ", max_code));
  79787. for (n = 0; n <= max_code; n++) {
  79788. int len = tree[n].Len;
  79789. if (len == 0) continue;
  79790. tree[n].Code = bi_reverse(next_code[len]++, len);
  79791. Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
  79792. n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1));
  79793. }
  79794. }
  79795. local void build_tree (deflate_state *s,
  79796. tree_desc *desc) /* the tree descriptor */
  79797. {
  79798. ct_data *tree = desc->dyn_tree;
  79799. const ct_data *stree = desc->stat_desc->static_tree;
  79800. int elems = desc->stat_desc->elems;
  79801. int n, m; /* iterate over heap elements */
  79802. int max_code = -1; /* largest code with non zero frequency */
  79803. int node; /* new node being created */
  79804. s->heap_len = 0, s->heap_max = HEAP_SIZE;
  79805. for (n = 0; n < elems; n++) {
  79806. if (tree[n].Freq != 0) {
  79807. s->heap[++(s->heap_len)] = max_code = n;
  79808. s->depth[n] = 0;
  79809. } else {
  79810. tree[n].Len = 0;
  79811. }
  79812. }
  79813. while (s->heap_len < 2) {
  79814. node = s->heap[++(s->heap_len)] = (max_code < 2 ? ++max_code : 0);
  79815. tree[node].Freq = 1;
  79816. s->depth[node] = 0;
  79817. s->opt_len--; if (stree) s->static_len -= stree[node].Len;
  79818. }
  79819. desc->max_code = max_code;
  79820. for (n = s->heap_len/2; n >= 1; n--) pqdownheap(s, tree, n);
  79821. node = elems; /* next internal node of the tree */
  79822. do {
  79823. pqremove(s, tree, n); /* n = node of least frequency */
  79824. m = s->heap[SMALLEST]; /* m = node of next least frequency */
  79825. s->heap[--(s->heap_max)] = n; /* keep the nodes sorted by frequency */
  79826. s->heap[--(s->heap_max)] = m;
  79827. tree[node].Freq = tree[n].Freq + tree[m].Freq;
  79828. s->depth[node] = (uch)((s->depth[n] >= s->depth[m] ?
  79829. s->depth[n] : s->depth[m]) + 1);
  79830. tree[n].Dad = tree[m].Dad = (ush)node;
  79831. #ifdef DUMP_BL_TREE
  79832. if (tree == s->bl_tree) {
  79833. fprintf(stderr,"\nnode %d(%d), sons %d(%d) %d(%d)",
  79834. node, tree[node].Freq, n, tree[n].Freq, m, tree[m].Freq);
  79835. }
  79836. #endif
  79837. s->heap[SMALLEST] = node++;
  79838. pqdownheap(s, tree, SMALLEST);
  79839. } while (s->heap_len >= 2);
  79840. s->heap[--(s->heap_max)] = s->heap[SMALLEST];
  79841. gen_bitlen(s, (tree_desc *)desc);
  79842. gen_codes ((ct_data *)tree, max_code, s->bl_count);
  79843. }
  79844. local void scan_tree (deflate_state *s,
  79845. ct_data *tree, /* the tree to be scanned */
  79846. int max_code) /* and its largest code of non zero frequency */
  79847. {
  79848. int n; /* iterates over all tree elements */
  79849. int prevlen = -1; /* last emitted length */
  79850. int curlen; /* length of current code */
  79851. int nextlen = tree[0].Len; /* length of next code */
  79852. int count = 0; /* repeat count of the current code */
  79853. int max_count = 7; /* max repeat count */
  79854. int min_count = 4; /* min repeat count */
  79855. if (nextlen == 0) max_count = 138, min_count = 3;
  79856. tree[max_code+1].Len = (ush)0xffff; /* guard */
  79857. for (n = 0; n <= max_code; n++) {
  79858. curlen = nextlen; nextlen = tree[n+1].Len;
  79859. if (++count < max_count && curlen == nextlen) {
  79860. continue;
  79861. } else if (count < min_count) {
  79862. s->bl_tree[curlen].Freq += count;
  79863. } else if (curlen != 0) {
  79864. if (curlen != prevlen) s->bl_tree[curlen].Freq++;
  79865. s->bl_tree[REP_3_6].Freq++;
  79866. } else if (count <= 10) {
  79867. s->bl_tree[REPZ_3_10].Freq++;
  79868. } else {
  79869. s->bl_tree[REPZ_11_138].Freq++;
  79870. }
  79871. count = 0; prevlen = curlen;
  79872. if (nextlen == 0) {
  79873. max_count = 138, min_count = 3;
  79874. } else if (curlen == nextlen) {
  79875. max_count = 6, min_count = 3;
  79876. } else {
  79877. max_count = 7, min_count = 4;
  79878. }
  79879. }
  79880. }
  79881. local void send_tree (deflate_state *s,
  79882. ct_data *tree, /* the tree to be scanned */
  79883. int max_code) /* and its largest code of non zero frequency */
  79884. {
  79885. int n; /* iterates over all tree elements */
  79886. int prevlen = -1; /* last emitted length */
  79887. int curlen; /* length of current code */
  79888. int nextlen = tree[0].Len; /* length of next code */
  79889. int count = 0; /* repeat count of the current code */
  79890. int max_count = 7; /* max repeat count */
  79891. int min_count = 4; /* min repeat count */
  79892. /* guard already set */
  79893. if (nextlen == 0) max_count = 138, min_count = 3;
  79894. for (n = 0; n <= max_code; n++) {
  79895. curlen = nextlen; nextlen = tree[n+1].Len;
  79896. if (++count < max_count && curlen == nextlen) {
  79897. continue;
  79898. } else if (count < min_count) {
  79899. do { send_code(s, curlen, s->bl_tree); } while (--count != 0);
  79900. } else if (curlen != 0) {
  79901. if (curlen != prevlen) {
  79902. send_code(s, curlen, s->bl_tree); count--;
  79903. }
  79904. Assert(count >= 3 && count <= 6, " 3_6?");
  79905. send_code(s, REP_3_6, s->bl_tree); send_bits(s, count-3, 2);
  79906. } else if (count <= 10) {
  79907. send_code(s, REPZ_3_10, s->bl_tree); send_bits(s, count-3, 3);
  79908. } else {
  79909. send_code(s, REPZ_11_138, s->bl_tree); send_bits(s, count-11, 7);
  79910. }
  79911. count = 0; prevlen = curlen;
  79912. if (nextlen == 0) {
  79913. max_count = 138, min_count = 3;
  79914. } else if (curlen == nextlen) {
  79915. max_count = 6, min_count = 3;
  79916. } else {
  79917. max_count = 7, min_count = 4;
  79918. }
  79919. }
  79920. }
  79921. local int build_bl_tree (deflate_state *s)
  79922. {
  79923. int max_blindex; /* index of last bit length code of non zero freq */
  79924. scan_tree(s, (ct_data *)s->dyn_ltree, s->l_desc.max_code);
  79925. scan_tree(s, (ct_data *)s->dyn_dtree, s->d_desc.max_code);
  79926. build_tree(s, (tree_desc *)(&(s->bl_desc)));
  79927. for (max_blindex = BL_CODES-1; max_blindex >= 3; max_blindex--) {
  79928. if (s->bl_tree[bl_order[max_blindex]].Len != 0) break;
  79929. }
  79930. s->opt_len += 3*(max_blindex+1) + 5+5+4;
  79931. Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld",
  79932. s->opt_len, s->static_len));
  79933. return max_blindex;
  79934. }
  79935. local void send_all_trees (deflate_state *s,
  79936. int lcodes, int dcodes, int blcodes) /* number of codes for each tree */
  79937. {
  79938. int rank; /* index in bl_order */
  79939. Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");
  79940. Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES,
  79941. "too many codes");
  79942. Tracev((stderr, "\nbl counts: "));
  79943. send_bits(s, lcodes-257, 5); /* not +255 as stated in appnote.txt */
  79944. send_bits(s, dcodes-1, 5);
  79945. send_bits(s, blcodes-4, 4); /* not -3 as stated in appnote.txt */
  79946. for (rank = 0; rank < blcodes; rank++) {
  79947. Tracev((stderr, "\nbl code %2d ", bl_order[rank]));
  79948. send_bits(s, s->bl_tree[bl_order[rank]].Len, 3);
  79949. }
  79950. Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent));
  79951. send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */
  79952. Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent));
  79953. send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */
  79954. Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent));
  79955. }
  79956. void _tr_stored_block (deflate_state *s, charf *buf, ulg stored_len, int eof)
  79957. {
  79958. send_bits(s, (STORED_BLOCK<<1)+eof, 3); /* send block type */
  79959. #ifdef DEBUG
  79960. s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L;
  79961. s->compressed_len += (stored_len + 4) << 3;
  79962. #endif
  79963. copy_block(s, buf, (unsigned)stored_len, 1); /* with header */
  79964. }
  79965. void _tr_align (deflate_state *s)
  79966. {
  79967. send_bits(s, STATIC_TREES<<1, 3);
  79968. send_code(s, END_BLOCK, static_ltree);
  79969. #ifdef DEBUG
  79970. s->compressed_len += 10L; /* 3 for block type, 7 for EOB */
  79971. #endif
  79972. bi_flush(s);
  79973. if (1 + s->last_eob_len + 10 - s->bi_valid < 9) {
  79974. send_bits(s, STATIC_TREES<<1, 3);
  79975. send_code(s, END_BLOCK, static_ltree);
  79976. #ifdef DEBUG
  79977. s->compressed_len += 10L;
  79978. #endif
  79979. bi_flush(s);
  79980. }
  79981. s->last_eob_len = 7;
  79982. }
  79983. void _tr_flush_block (deflate_state *s,
  79984. charf *buf, /* input block, or NULL if too old */
  79985. ulg stored_len, /* length of input block */
  79986. int eof) /* true if this is the last block for a file */
  79987. {
  79988. ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */
  79989. int max_blindex = 0; /* index of last bit length code of non zero freq */
  79990. if (s->level > 0) {
  79991. if (stored_len > 0 && s->strm->data_type == Z_UNKNOWN)
  79992. set_data_type(s);
  79993. build_tree(s, (tree_desc *)(&(s->l_desc)));
  79994. Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len,
  79995. s->static_len));
  79996. build_tree(s, (tree_desc *)(&(s->d_desc)));
  79997. Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len,
  79998. s->static_len));
  79999. max_blindex = build_bl_tree(s);
  80000. opt_lenb = (s->opt_len+3+7)>>3;
  80001. static_lenb = (s->static_len+3+7)>>3;
  80002. Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ",
  80003. opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
  80004. s->last_lit));
  80005. if (static_lenb <= opt_lenb) opt_lenb = static_lenb;
  80006. } else {
  80007. Assert(buf != (char*)0, "lost buf");
  80008. opt_lenb = static_lenb = stored_len + 5; /* force a stored block */
  80009. }
  80010. #ifdef FORCE_STORED
  80011. if (buf != (char*)0) { /* force stored block */
  80012. #else
  80013. if (stored_len+4 <= opt_lenb && buf != (char*)0) {
  80014. #endif
  80015. _tr_stored_block(s, buf, stored_len, eof);
  80016. #ifdef FORCE_STATIC
  80017. } else if (static_lenb >= 0) { /* force static trees */
  80018. #else
  80019. } else if (s->strategy == Z_FIXED || static_lenb == opt_lenb) {
  80020. #endif
  80021. send_bits(s, (STATIC_TREES<<1)+eof, 3);
  80022. compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree);
  80023. #ifdef DEBUG
  80024. s->compressed_len += 3 + s->static_len;
  80025. #endif
  80026. } else {
  80027. send_bits(s, (DYN_TREES<<1)+eof, 3);
  80028. send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1,
  80029. max_blindex+1);
  80030. compress_block(s, (ct_data *)s->dyn_ltree, (ct_data *)s->dyn_dtree);
  80031. #ifdef DEBUG
  80032. s->compressed_len += 3 + s->opt_len;
  80033. #endif
  80034. }
  80035. Assert (s->compressed_len == s->bits_sent, "bad compressed size");
  80036. init_block(s);
  80037. if (eof) {
  80038. bi_windup(s);
  80039. #ifdef DEBUG
  80040. s->compressed_len += 7; /* align on byte boundary */
  80041. #endif
  80042. }
  80043. Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3,
  80044. s->compressed_len-7*eof));
  80045. }
  80046. int _tr_tally (deflate_state *s,
  80047. unsigned dist, /* distance of matched string */
  80048. unsigned lc) /* match length-MIN_MATCH or unmatched char (if dist==0) */
  80049. {
  80050. s->d_buf[s->last_lit] = (ush)dist;
  80051. s->l_buf[s->last_lit++] = (uch)lc;
  80052. if (dist == 0) {
  80053. s->dyn_ltree[lc].Freq++;
  80054. } else {
  80055. s->matches++;
  80056. dist--; /* dist = match distance - 1 */
  80057. Assert((ush)dist < (ush)MAX_DIST(s) &&
  80058. (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) &&
  80059. (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match");
  80060. s->dyn_ltree[_length_code[lc]+LITERALS+1].Freq++;
  80061. s->dyn_dtree[d_code(dist)].Freq++;
  80062. }
  80063. #ifdef TRUNCATE_BLOCK
  80064. if ((s->last_lit & 0x1fff) == 0 && s->level > 2) {
  80065. ulg out_length = (ulg)s->last_lit*8L;
  80066. ulg in_length = (ulg)((long)s->strstart - s->block_start);
  80067. int dcode;
  80068. for (dcode = 0; dcode < D_CODES; dcode++) {
  80069. out_length += (ulg)s->dyn_dtree[dcode].Freq *
  80070. (5L+extra_dbits[dcode]);
  80071. }
  80072. out_length >>= 3;
  80073. Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ",
  80074. s->last_lit, in_length, out_length,
  80075. 100L - out_length*100L/in_length));
  80076. if (s->matches < s->last_lit/2 && out_length < in_length/2) return 1;
  80077. }
  80078. #endif
  80079. return (s->last_lit == s->lit_bufsize-1);
  80080. }
  80081. local void compress_block (deflate_state *s,
  80082. ct_data *ltree, /* literal tree */
  80083. ct_data *dtree) /* distance tree */
  80084. {
  80085. unsigned dist; /* distance of matched string */
  80086. int lc; /* match length or unmatched char (if dist == 0) */
  80087. unsigned lx = 0; /* running index in l_buf */
  80088. unsigned code; /* the code to send */
  80089. int extra; /* number of extra bits to send */
  80090. if (s->last_lit != 0) do {
  80091. dist = s->d_buf[lx];
  80092. lc = s->l_buf[lx++];
  80093. if (dist == 0) {
  80094. send_code(s, lc, ltree); /* send a literal byte */
  80095. Tracecv(isgraph(lc), (stderr," '%c' ", lc));
  80096. } else {
  80097. code = _length_code[lc];
  80098. send_code(s, code+LITERALS+1, ltree); /* send the length code */
  80099. extra = extra_lbits[code];
  80100. if (extra != 0) {
  80101. lc -= base_length[code];
  80102. send_bits(s, lc, extra); /* send the extra length bits */
  80103. }
  80104. dist--; /* dist is now the match distance - 1 */
  80105. code = d_code(dist);
  80106. Assert (code < D_CODES, "bad d_code");
  80107. send_code(s, code, dtree); /* send the distance code */
  80108. extra = extra_dbits[code];
  80109. if (extra != 0) {
  80110. dist -= base_dist[code];
  80111. send_bits(s, dist, extra); /* send the extra distance bits */
  80112. }
  80113. } /* literal or match pair ? */
  80114. Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx,
  80115. "pendingBuf overflow");
  80116. } while (lx < s->last_lit);
  80117. send_code(s, END_BLOCK, ltree);
  80118. s->last_eob_len = ltree[END_BLOCK].Len;
  80119. }
  80120. local void set_data_type (deflate_state *s)
  80121. {
  80122. int n;
  80123. for (n = 0; n < 9; n++)
  80124. if (s->dyn_ltree[n].Freq != 0)
  80125. break;
  80126. if (n == 9)
  80127. for (n = 14; n < 32; n++)
  80128. if (s->dyn_ltree[n].Freq != 0)
  80129. break;
  80130. s->strm->data_type = (n == 32) ? Z_TEXT : Z_BINARY;
  80131. }
  80132. local unsigned bi_reverse (unsigned code, int len)
  80133. {
  80134. register unsigned res = 0;
  80135. do {
  80136. res |= code & 1;
  80137. code >>= 1, res <<= 1;
  80138. } while (--len > 0);
  80139. return res >> 1;
  80140. }
  80141. local void bi_flush (deflate_state *s)
  80142. {
  80143. if (s->bi_valid == 16) {
  80144. put_short(s, s->bi_buf);
  80145. s->bi_buf = 0;
  80146. s->bi_valid = 0;
  80147. } else if (s->bi_valid >= 8) {
  80148. put_byte(s, (Byte)s->bi_buf);
  80149. s->bi_buf >>= 8;
  80150. s->bi_valid -= 8;
  80151. }
  80152. }
  80153. local void bi_windup (deflate_state *s)
  80154. {
  80155. if (s->bi_valid > 8) {
  80156. put_short(s, s->bi_buf);
  80157. } else if (s->bi_valid > 0) {
  80158. put_byte(s, (Byte)s->bi_buf);
  80159. }
  80160. s->bi_buf = 0;
  80161. s->bi_valid = 0;
  80162. #ifdef DEBUG
  80163. s->bits_sent = (s->bits_sent+7) & ~7;
  80164. #endif
  80165. }
  80166. local void copy_block(deflate_state *s,
  80167. charf *buf, /* the input data */
  80168. unsigned len, /* its length */
  80169. int header) /* true if block header must be written */
  80170. {
  80171. bi_windup(s); /* align on byte boundary */
  80172. s->last_eob_len = 8; /* enough lookahead for inflate */
  80173. if (header) {
  80174. put_short(s, (ush)len);
  80175. put_short(s, (ush)~len);
  80176. #ifdef DEBUG
  80177. s->bits_sent += 2*16;
  80178. #endif
  80179. }
  80180. #ifdef DEBUG
  80181. s->bits_sent += (ulg)len<<3;
  80182. #endif
  80183. while (len--) {
  80184. put_byte(s, *buf++);
  80185. }
  80186. }
  80187. /*** End of inlined file: trees.c ***/
  80188. /*** Start of inlined file: zutil.c ***/
  80189. #ifndef NO_DUMMY_DECL
  80190. struct internal_state {int dummy;}; /* for buggy compilers */
  80191. #endif
  80192. const char * const z_errmsg[10] = {
  80193. "need dictionary", /* Z_NEED_DICT 2 */
  80194. "stream end", /* Z_STREAM_END 1 */
  80195. "", /* Z_OK 0 */
  80196. "file error", /* Z_ERRNO (-1) */
  80197. "stream error", /* Z_STREAM_ERROR (-2) */
  80198. "data error", /* Z_DATA_ERROR (-3) */
  80199. "insufficient memory", /* Z_MEM_ERROR (-4) */
  80200. "buffer error", /* Z_BUF_ERROR (-5) */
  80201. "incompatible version",/* Z_VERSION_ERROR (-6) */
  80202. ""};
  80203. #ifdef DEBUG
  80204. # ifndef verbose
  80205. # define verbose 0
  80206. # endif
  80207. int z_verbose = verbose;
  80208. void z_error (const char *m)
  80209. {
  80210. fprintf(stderr, "%s\n", m);
  80211. exit(1);
  80212. }
  80213. #endif
  80214. const char * ZEXPORT zError(int err)
  80215. {
  80216. return ERR_MSG(err);
  80217. }
  80218. #if defined(_WIN32_WCE)
  80219. int errno = 0;
  80220. #endif
  80221. #ifndef HAVE_MEMCPY
  80222. void zmemcpy(dest, source, len)
  80223. Bytef* dest;
  80224. const Bytef* source;
  80225. uInt len;
  80226. {
  80227. if (len == 0) return;
  80228. do {
  80229. *dest++ = *source++; /* ??? to be unrolled */
  80230. } while (--len != 0);
  80231. }
  80232. int zmemcmp(s1, s2, len)
  80233. const Bytef* s1;
  80234. const Bytef* s2;
  80235. uInt len;
  80236. {
  80237. uInt j;
  80238. for (j = 0; j < len; j++) {
  80239. if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
  80240. }
  80241. return 0;
  80242. }
  80243. void zmemzero(dest, len)
  80244. Bytef* dest;
  80245. uInt len;
  80246. {
  80247. if (len == 0) return;
  80248. do {
  80249. *dest++ = 0; /* ??? to be unrolled */
  80250. } while (--len != 0);
  80251. }
  80252. #endif
  80253. #ifdef SYS16BIT
  80254. #ifdef __TURBOC__
  80255. # define MY_ZCALLOC
  80256. #define MAX_PTR 10
  80257. local int next_ptr = 0;
  80258. typedef struct ptr_table_s {
  80259. voidpf org_ptr;
  80260. voidpf new_ptr;
  80261. } ptr_table;
  80262. local ptr_table table[MAX_PTR];
  80263. voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  80264. {
  80265. voidpf buf = opaque; /* just to make some compilers happy */
  80266. ulg bsize = (ulg)items*size;
  80267. if (bsize < 65520L) {
  80268. buf = farmalloc(bsize);
  80269. if (*(ush*)&buf != 0) return buf;
  80270. } else {
  80271. buf = farmalloc(bsize + 16L);
  80272. }
  80273. if (buf == NULL || next_ptr >= MAX_PTR) return NULL;
  80274. table[next_ptr].org_ptr = buf;
  80275. *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4;
  80276. *(ush*)&buf = 0;
  80277. table[next_ptr++].new_ptr = buf;
  80278. return buf;
  80279. }
  80280. void zcfree (voidpf opaque, voidpf ptr)
  80281. {
  80282. int n;
  80283. if (*(ush*)&ptr != 0) { /* object < 64K */
  80284. farfree(ptr);
  80285. return;
  80286. }
  80287. for (n = 0; n < next_ptr; n++) {
  80288. if (ptr != table[n].new_ptr) continue;
  80289. farfree(table[n].org_ptr);
  80290. while (++n < next_ptr) {
  80291. table[n-1] = table[n];
  80292. }
  80293. next_ptr--;
  80294. return;
  80295. }
  80296. ptr = opaque; /* just to make some compilers happy */
  80297. Assert(0, "zcfree: ptr not found");
  80298. }
  80299. #endif /* __TURBOC__ */
  80300. #ifdef M_I86
  80301. # define MY_ZCALLOC
  80302. #if (!defined(_MSC_VER) || (_MSC_VER <= 600))
  80303. # define _halloc halloc
  80304. # define _hfree hfree
  80305. #endif
  80306. voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  80307. {
  80308. if (opaque) opaque = 0; /* to make compiler happy */
  80309. return _halloc((long)items, size);
  80310. }
  80311. void zcfree (voidpf opaque, voidpf ptr)
  80312. {
  80313. if (opaque) opaque = 0; /* to make compiler happy */
  80314. _hfree(ptr);
  80315. }
  80316. #endif /* M_I86 */
  80317. #endif /* SYS16BIT */
  80318. #ifndef MY_ZCALLOC /* Any system without a special alloc function */
  80319. #ifndef STDC
  80320. extern voidp malloc OF((uInt size));
  80321. extern voidp calloc OF((uInt items, uInt size));
  80322. extern void free OF((voidpf ptr));
  80323. #endif
  80324. voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  80325. {
  80326. if (opaque) items += size - size; /* make compiler happy */
  80327. return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) :
  80328. (voidpf)calloc(items, size);
  80329. }
  80330. void zcfree (voidpf opaque, voidpf ptr)
  80331. {
  80332. free(ptr);
  80333. if (opaque) return; /* make compiler happy */
  80334. }
  80335. #endif /* MY_ZCALLOC */
  80336. /*** End of inlined file: zutil.c ***/
  80337. #undef Byte
  80338. }
  80339. #else
  80340. #include <zlib.h>
  80341. #endif
  80342. }
  80343. #if JUCE_MSVC
  80344. #pragma warning (pop)
  80345. #endif
  80346. BEGIN_JUCE_NAMESPACE
  80347. using namespace zlibNamespace;
  80348. // internal helper object that holds the zlib structures so they don't have to be
  80349. // included publicly.
  80350. class GZIPDecompressHelper
  80351. {
  80352. public:
  80353. GZIPDecompressHelper (const bool noWrap) throw()
  80354. : data (0),
  80355. dataSize (0),
  80356. finished (true),
  80357. needsDictionary (false),
  80358. error (true),
  80359. streamIsValid (false)
  80360. {
  80361. zerostruct (stream);
  80362. streamIsValid = (inflateInit2 (&stream, noWrap ? -MAX_WBITS : MAX_WBITS) == Z_OK);
  80363. finished = error = ! streamIsValid;
  80364. }
  80365. ~GZIPDecompressHelper() throw()
  80366. {
  80367. if (streamIsValid)
  80368. inflateEnd (&stream);
  80369. }
  80370. bool needsInput() const throw() { return dataSize <= 0; }
  80371. void setInput (uint8* const data_, const int size) throw()
  80372. {
  80373. data = data_;
  80374. dataSize = size;
  80375. }
  80376. int doNextBlock (uint8* const dest, const int destSize) throw()
  80377. {
  80378. if (streamIsValid && data != 0 && ! finished)
  80379. {
  80380. stream.next_in = data;
  80381. stream.next_out = dest;
  80382. stream.avail_in = dataSize;
  80383. stream.avail_out = destSize;
  80384. switch (inflate (&stream, Z_PARTIAL_FLUSH))
  80385. {
  80386. case Z_STREAM_END:
  80387. finished = true;
  80388. // deliberate fall-through
  80389. case Z_OK:
  80390. data += dataSize - stream.avail_in;
  80391. dataSize = stream.avail_in;
  80392. return destSize - stream.avail_out;
  80393. case Z_NEED_DICT:
  80394. needsDictionary = true;
  80395. data += dataSize - stream.avail_in;
  80396. dataSize = stream.avail_in;
  80397. break;
  80398. case Z_DATA_ERROR:
  80399. case Z_MEM_ERROR:
  80400. error = true;
  80401. default:
  80402. break;
  80403. }
  80404. }
  80405. return 0;
  80406. }
  80407. private:
  80408. z_stream stream;
  80409. uint8* data;
  80410. int dataSize;
  80411. public:
  80412. bool finished, needsDictionary, error, streamIsValid;
  80413. };
  80414. const int gzipDecompBufferSize = 32768;
  80415. GZIPDecompressorInputStream::GZIPDecompressorInputStream (InputStream* const sourceStream_,
  80416. const bool deleteSourceWhenDestroyed,
  80417. const bool noWrap_,
  80418. const int64 uncompressedStreamLength_)
  80419. : sourceStream (sourceStream_),
  80420. streamToDelete (deleteSourceWhenDestroyed ? sourceStream_ : 0),
  80421. uncompressedStreamLength (uncompressedStreamLength_),
  80422. noWrap (noWrap_),
  80423. isEof (false),
  80424. activeBufferSize (0),
  80425. originalSourcePos (sourceStream_->getPosition()),
  80426. currentPos (0),
  80427. buffer (gzipDecompBufferSize),
  80428. helper (new GZIPDecompressHelper (noWrap_))
  80429. {
  80430. }
  80431. GZIPDecompressorInputStream::~GZIPDecompressorInputStream()
  80432. {
  80433. }
  80434. int64 GZIPDecompressorInputStream::getTotalLength()
  80435. {
  80436. return uncompressedStreamLength;
  80437. }
  80438. int GZIPDecompressorInputStream::read (void* destBuffer, int howMany)
  80439. {
  80440. if ((howMany > 0) && ! isEof)
  80441. {
  80442. jassert (destBuffer != 0);
  80443. if (destBuffer != 0)
  80444. {
  80445. int numRead = 0;
  80446. uint8* d = (uint8*) destBuffer;
  80447. while (! helper->error)
  80448. {
  80449. const int n = helper->doNextBlock (d, howMany);
  80450. currentPos += n;
  80451. if (n == 0)
  80452. {
  80453. if (helper->finished || helper->needsDictionary)
  80454. {
  80455. isEof = true;
  80456. return numRead;
  80457. }
  80458. if (helper->needsInput())
  80459. {
  80460. activeBufferSize = sourceStream->read (buffer, gzipDecompBufferSize);
  80461. if (activeBufferSize > 0)
  80462. {
  80463. helper->setInput ((uint8*) buffer, activeBufferSize);
  80464. }
  80465. else
  80466. {
  80467. isEof = true;
  80468. return numRead;
  80469. }
  80470. }
  80471. }
  80472. else
  80473. {
  80474. numRead += n;
  80475. howMany -= n;
  80476. d += n;
  80477. if (howMany <= 0)
  80478. return numRead;
  80479. }
  80480. }
  80481. }
  80482. }
  80483. return 0;
  80484. }
  80485. bool GZIPDecompressorInputStream::isExhausted()
  80486. {
  80487. return helper->error || isEof;
  80488. }
  80489. int64 GZIPDecompressorInputStream::getPosition()
  80490. {
  80491. return currentPos;
  80492. }
  80493. bool GZIPDecompressorInputStream::setPosition (int64 newPos)
  80494. {
  80495. if (newPos < currentPos)
  80496. {
  80497. // to go backwards, reset the stream and start again..
  80498. isEof = false;
  80499. activeBufferSize = 0;
  80500. currentPos = 0;
  80501. helper = new GZIPDecompressHelper (noWrap);
  80502. sourceStream->setPosition (originalSourcePos);
  80503. }
  80504. skipNextBytes (newPos - currentPos);
  80505. return true;
  80506. }
  80507. END_JUCE_NAMESPACE
  80508. /*** End of inlined file: juce_GZIPDecompressorInputStream.cpp ***/
  80509. #endif
  80510. #if JUCE_BUILD_NATIVE && ! JUCE_ONLY_BUILD_CORE_LIBRARY
  80511. /*** Start of inlined file: juce_FlacAudioFormat.cpp ***/
  80512. #if JUCE_USE_FLAC
  80513. #if JUCE_WINDOWS
  80514. #include <windows.h>
  80515. #endif
  80516. #ifdef _MSC_VER
  80517. #pragma warning (disable : 4505)
  80518. #pragma warning (push)
  80519. #endif
  80520. namespace FlacNamespace
  80521. {
  80522. #if JUCE_INCLUDE_FLAC_CODE
  80523. #define FLAC__NO_DLL 1
  80524. #if ! defined (SIZE_MAX)
  80525. #define SIZE_MAX 0xffffffff
  80526. #endif
  80527. #define __STDC_LIMIT_MACROS 1
  80528. /*** Start of inlined file: all.h ***/
  80529. #ifndef FLAC__ALL_H
  80530. #define FLAC__ALL_H
  80531. /*** Start of inlined file: export.h ***/
  80532. #ifndef FLAC__EXPORT_H
  80533. #define FLAC__EXPORT_H
  80534. #if defined(FLAC__NO_DLL) || !defined(_MSC_VER)
  80535. #define FLAC_API
  80536. #else
  80537. #ifdef FLAC_API_EXPORTS
  80538. #define FLAC_API _declspec(dllexport)
  80539. #else
  80540. #define FLAC_API _declspec(dllimport)
  80541. #endif
  80542. #endif
  80543. #define FLAC_API_VERSION_CURRENT 10
  80544. #define FLAC_API_VERSION_REVISION 0 /**< see above */
  80545. #define FLAC_API_VERSION_AGE 2 /**< see above */
  80546. #ifdef __cplusplus
  80547. extern "C" {
  80548. #endif
  80549. extern FLAC_API int FLAC_API_SUPPORTS_OGG_FLAC;
  80550. #ifdef __cplusplus
  80551. }
  80552. #endif
  80553. #endif
  80554. /*** End of inlined file: export.h ***/
  80555. /*** Start of inlined file: assert.h ***/
  80556. #ifndef FLAC__ASSERT_H
  80557. #define FLAC__ASSERT_H
  80558. /* we need this since some compilers (like MSVC) leave assert()s on release code (and we don't want to use their ASSERT) */
  80559. #ifdef DEBUG
  80560. #include <assert.h>
  80561. #define FLAC__ASSERT(x) assert(x)
  80562. #define FLAC__ASSERT_DECLARATION(x) x
  80563. #else
  80564. #define FLAC__ASSERT(x)
  80565. #define FLAC__ASSERT_DECLARATION(x)
  80566. #endif
  80567. #endif
  80568. /*** End of inlined file: assert.h ***/
  80569. /*** Start of inlined file: callback.h ***/
  80570. #ifndef FLAC__CALLBACK_H
  80571. #define FLAC__CALLBACK_H
  80572. /*** Start of inlined file: ordinals.h ***/
  80573. #ifndef FLAC__ORDINALS_H
  80574. #define FLAC__ORDINALS_H
  80575. #if !(defined(_MSC_VER) || defined(__BORLANDC__) || defined(__EMX__))
  80576. #include <inttypes.h>
  80577. #endif
  80578. typedef signed char FLAC__int8;
  80579. typedef unsigned char FLAC__uint8;
  80580. #if defined(_MSC_VER) || defined(__BORLANDC__)
  80581. typedef __int16 FLAC__int16;
  80582. typedef __int32 FLAC__int32;
  80583. typedef __int64 FLAC__int64;
  80584. typedef unsigned __int16 FLAC__uint16;
  80585. typedef unsigned __int32 FLAC__uint32;
  80586. typedef unsigned __int64 FLAC__uint64;
  80587. #elif defined(__EMX__)
  80588. typedef short FLAC__int16;
  80589. typedef long FLAC__int32;
  80590. typedef long long FLAC__int64;
  80591. typedef unsigned short FLAC__uint16;
  80592. typedef unsigned long FLAC__uint32;
  80593. typedef unsigned long long FLAC__uint64;
  80594. #else
  80595. typedef int16_t FLAC__int16;
  80596. typedef int32_t FLAC__int32;
  80597. typedef int64_t FLAC__int64;
  80598. typedef uint16_t FLAC__uint16;
  80599. typedef uint32_t FLAC__uint32;
  80600. typedef uint64_t FLAC__uint64;
  80601. #endif
  80602. typedef int FLAC__bool;
  80603. typedef FLAC__uint8 FLAC__byte;
  80604. #ifdef true
  80605. #undef true
  80606. #endif
  80607. #ifdef false
  80608. #undef false
  80609. #endif
  80610. #ifndef __cplusplus
  80611. #define true 1
  80612. #define false 0
  80613. #endif
  80614. #endif
  80615. /*** End of inlined file: ordinals.h ***/
  80616. #include <stdlib.h> /* for size_t */
  80617. #ifdef __cplusplus
  80618. extern "C" {
  80619. #endif
  80620. typedef void* FLAC__IOHandle;
  80621. typedef size_t (*FLAC__IOCallback_Read) (void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle);
  80622. typedef size_t (*FLAC__IOCallback_Write) (const void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle);
  80623. typedef int (*FLAC__IOCallback_Seek) (FLAC__IOHandle handle, FLAC__int64 offset, int whence);
  80624. typedef FLAC__int64 (*FLAC__IOCallback_Tell) (FLAC__IOHandle handle);
  80625. typedef int (*FLAC__IOCallback_Eof) (FLAC__IOHandle handle);
  80626. typedef int (*FLAC__IOCallback_Close) (FLAC__IOHandle handle);
  80627. typedef struct {
  80628. FLAC__IOCallback_Read read;
  80629. FLAC__IOCallback_Write write;
  80630. FLAC__IOCallback_Seek seek;
  80631. FLAC__IOCallback_Tell tell;
  80632. FLAC__IOCallback_Eof eof;
  80633. FLAC__IOCallback_Close close;
  80634. } FLAC__IOCallbacks;
  80635. #ifdef __cplusplus
  80636. }
  80637. #endif
  80638. #endif
  80639. /*** End of inlined file: callback.h ***/
  80640. /*** Start of inlined file: format.h ***/
  80641. #ifndef FLAC__FORMAT_H
  80642. #define FLAC__FORMAT_H
  80643. #ifdef __cplusplus
  80644. extern "C" {
  80645. #endif
  80646. #define FLAC__MAX_METADATA_TYPE_CODE (126u)
  80647. #define FLAC__MIN_BLOCK_SIZE (16u)
  80648. #define FLAC__MAX_BLOCK_SIZE (65535u)
  80649. #define FLAC__SUBSET_MAX_BLOCK_SIZE_48000HZ (4608u)
  80650. #define FLAC__MAX_CHANNELS (8u)
  80651. #define FLAC__MIN_BITS_PER_SAMPLE (4u)
  80652. #define FLAC__MAX_BITS_PER_SAMPLE (32u)
  80653. #define FLAC__REFERENCE_CODEC_MAX_BITS_PER_SAMPLE (24u)
  80654. #define FLAC__MAX_SAMPLE_RATE (655350u)
  80655. #define FLAC__MAX_LPC_ORDER (32u)
  80656. #define FLAC__SUBSET_MAX_LPC_ORDER_48000HZ (12u)
  80657. #define FLAC__MIN_QLP_COEFF_PRECISION (5u)
  80658. #define FLAC__MAX_QLP_COEFF_PRECISION (15u)
  80659. #define FLAC__MAX_FIXED_ORDER (4u)
  80660. #define FLAC__MAX_RICE_PARTITION_ORDER (15u)
  80661. #define FLAC__SUBSET_MAX_RICE_PARTITION_ORDER (8u)
  80662. extern FLAC_API const char *FLAC__VERSION_STRING;
  80663. extern FLAC_API const char *FLAC__VENDOR_STRING;
  80664. extern FLAC_API const FLAC__byte FLAC__STREAM_SYNC_STRING[4]; /* = "fLaC" */
  80665. extern FLAC_API const unsigned FLAC__STREAM_SYNC; /* = 0x664C6143 */
  80666. extern FLAC_API const unsigned FLAC__STREAM_SYNC_LEN; /* = 32 bits */
  80667. #define FLAC__STREAM_SYNC_LENGTH (4u)
  80668. typedef enum {
  80669. FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE = 0,
  80670. FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2 = 1
  80671. } FLAC__EntropyCodingMethodType;
  80672. extern FLAC_API const char * const FLAC__EntropyCodingMethodTypeString[];
  80673. typedef struct {
  80674. unsigned *parameters;
  80675. unsigned *raw_bits;
  80676. unsigned capacity_by_order;
  80677. } FLAC__EntropyCodingMethod_PartitionedRiceContents;
  80678. typedef struct {
  80679. unsigned order;
  80680. const FLAC__EntropyCodingMethod_PartitionedRiceContents *contents;
  80681. } FLAC__EntropyCodingMethod_PartitionedRice;
  80682. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN; /**< == 4 (bits) */
  80683. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN; /**< == 4 (bits) */
  80684. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN; /**< == 5 (bits) */
  80685. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN; /**< == 5 (bits) */
  80686. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  80687. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER;
  80688. typedef struct {
  80689. FLAC__EntropyCodingMethodType type;
  80690. union {
  80691. FLAC__EntropyCodingMethod_PartitionedRice partitioned_rice;
  80692. } data;
  80693. } FLAC__EntropyCodingMethod;
  80694. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_TYPE_LEN; /**< == 2 (bits) */
  80695. typedef enum {
  80696. FLAC__SUBFRAME_TYPE_CONSTANT = 0, /**< constant signal */
  80697. FLAC__SUBFRAME_TYPE_VERBATIM = 1, /**< uncompressed signal */
  80698. FLAC__SUBFRAME_TYPE_FIXED = 2, /**< fixed polynomial prediction */
  80699. FLAC__SUBFRAME_TYPE_LPC = 3 /**< linear prediction */
  80700. } FLAC__SubframeType;
  80701. extern FLAC_API const char * const FLAC__SubframeTypeString[];
  80702. typedef struct {
  80703. FLAC__int32 value; /**< The constant signal value. */
  80704. } FLAC__Subframe_Constant;
  80705. typedef struct {
  80706. const FLAC__int32 *data; /**< A pointer to verbatim signal. */
  80707. } FLAC__Subframe_Verbatim;
  80708. typedef struct {
  80709. FLAC__EntropyCodingMethod entropy_coding_method;
  80710. unsigned order;
  80711. FLAC__int32 warmup[FLAC__MAX_FIXED_ORDER];
  80712. const FLAC__int32 *residual;
  80713. } FLAC__Subframe_Fixed;
  80714. typedef struct {
  80715. FLAC__EntropyCodingMethod entropy_coding_method;
  80716. unsigned order;
  80717. unsigned qlp_coeff_precision;
  80718. int quantization_level;
  80719. FLAC__int32 qlp_coeff[FLAC__MAX_LPC_ORDER];
  80720. FLAC__int32 warmup[FLAC__MAX_LPC_ORDER];
  80721. const FLAC__int32 *residual;
  80722. } FLAC__Subframe_LPC;
  80723. extern FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN; /**< == 4 (bits) */
  80724. extern FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN; /**< == 5 (bits) */
  80725. typedef struct {
  80726. FLAC__SubframeType type;
  80727. union {
  80728. FLAC__Subframe_Constant constant;
  80729. FLAC__Subframe_Fixed fixed;
  80730. FLAC__Subframe_LPC lpc;
  80731. FLAC__Subframe_Verbatim verbatim;
  80732. } data;
  80733. unsigned wasted_bits;
  80734. } FLAC__Subframe;
  80735. extern FLAC_API const unsigned FLAC__SUBFRAME_ZERO_PAD_LEN;
  80736. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LEN; /**< == 6 (bits) */
  80737. extern FLAC_API const unsigned FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN; /**< == 1 (bit) */
  80738. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_CONSTANT_BYTE_ALIGNED_MASK; /**< = 0x00 */
  80739. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_VERBATIM_BYTE_ALIGNED_MASK; /**< = 0x02 */
  80740. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_FIXED_BYTE_ALIGNED_MASK; /**< = 0x10 */
  80741. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LPC_BYTE_ALIGNED_MASK; /**< = 0x40 */
  80742. typedef enum {
  80743. FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT = 0, /**< independent channels */
  80744. FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE = 1, /**< left+side stereo */
  80745. FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE = 2, /**< right+side stereo */
  80746. FLAC__CHANNEL_ASSIGNMENT_MID_SIDE = 3 /**< mid+side stereo */
  80747. } FLAC__ChannelAssignment;
  80748. extern FLAC_API const char * const FLAC__ChannelAssignmentString[];
  80749. typedef enum {
  80750. FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER, /**< number contains the frame number */
  80751. FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER /**< number contains the sample number of first sample in frame */
  80752. } FLAC__FrameNumberType;
  80753. extern FLAC_API const char * const FLAC__FrameNumberTypeString[];
  80754. typedef struct {
  80755. unsigned blocksize;
  80756. unsigned sample_rate;
  80757. unsigned channels;
  80758. FLAC__ChannelAssignment channel_assignment;
  80759. unsigned bits_per_sample;
  80760. FLAC__FrameNumberType number_type;
  80761. union {
  80762. FLAC__uint32 frame_number;
  80763. FLAC__uint64 sample_number;
  80764. } number;
  80765. FLAC__uint8 crc;
  80766. } FLAC__FrameHeader;
  80767. extern FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC; /**< == 0x3ffe; the frame header sync code */
  80768. extern FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC_LEN; /**< == 14 (bits) */
  80769. extern FLAC_API const unsigned FLAC__FRAME_HEADER_RESERVED_LEN; /**< == 1 (bits) */
  80770. extern FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN; /**< == 1 (bits) */
  80771. extern FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCK_SIZE_LEN; /**< == 4 (bits) */
  80772. extern FLAC_API const unsigned FLAC__FRAME_HEADER_SAMPLE_RATE_LEN; /**< == 4 (bits) */
  80773. extern FLAC_API const unsigned FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN; /**< == 4 (bits) */
  80774. extern FLAC_API const unsigned FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN; /**< == 3 (bits) */
  80775. extern FLAC_API const unsigned FLAC__FRAME_HEADER_ZERO_PAD_LEN; /**< == 1 (bit) */
  80776. extern FLAC_API const unsigned FLAC__FRAME_HEADER_CRC_LEN; /**< == 8 (bits) */
  80777. typedef struct {
  80778. FLAC__uint16 crc;
  80779. } FLAC__FrameFooter;
  80780. extern FLAC_API const unsigned FLAC__FRAME_FOOTER_CRC_LEN; /**< == 16 (bits) */
  80781. typedef struct {
  80782. FLAC__FrameHeader header;
  80783. FLAC__Subframe subframes[FLAC__MAX_CHANNELS];
  80784. FLAC__FrameFooter footer;
  80785. } FLAC__Frame;
  80786. typedef enum {
  80787. FLAC__METADATA_TYPE_STREAMINFO = 0,
  80788. FLAC__METADATA_TYPE_PADDING = 1,
  80789. FLAC__METADATA_TYPE_APPLICATION = 2,
  80790. FLAC__METADATA_TYPE_SEEKTABLE = 3,
  80791. FLAC__METADATA_TYPE_VORBIS_COMMENT = 4,
  80792. FLAC__METADATA_TYPE_CUESHEET = 5,
  80793. FLAC__METADATA_TYPE_PICTURE = 6,
  80794. FLAC__METADATA_TYPE_UNDEFINED = 7
  80795. } FLAC__MetadataType;
  80796. extern FLAC_API const char * const FLAC__MetadataTypeString[];
  80797. typedef struct {
  80798. unsigned min_blocksize, max_blocksize;
  80799. unsigned min_framesize, max_framesize;
  80800. unsigned sample_rate;
  80801. unsigned channels;
  80802. unsigned bits_per_sample;
  80803. FLAC__uint64 total_samples;
  80804. FLAC__byte md5sum[16];
  80805. } FLAC__StreamMetadata_StreamInfo;
  80806. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN; /**< == 16 (bits) */
  80807. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN; /**< == 16 (bits) */
  80808. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN; /**< == 24 (bits) */
  80809. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN; /**< == 24 (bits) */
  80810. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN; /**< == 20 (bits) */
  80811. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN; /**< == 3 (bits) */
  80812. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN; /**< == 5 (bits) */
  80813. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN; /**< == 36 (bits) */
  80814. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MD5SUM_LEN; /**< == 128 (bits) */
  80815. #define FLAC__STREAM_METADATA_STREAMINFO_LENGTH (34u)
  80816. typedef struct {
  80817. int dummy;
  80818. } FLAC__StreamMetadata_Padding;
  80819. typedef struct {
  80820. FLAC__byte id[4];
  80821. FLAC__byte *data;
  80822. } FLAC__StreamMetadata_Application;
  80823. extern FLAC_API const unsigned FLAC__STREAM_METADATA_APPLICATION_ID_LEN; /**< == 32 (bits) */
  80824. typedef struct {
  80825. FLAC__uint64 sample_number;
  80826. FLAC__uint64 stream_offset;
  80827. unsigned frame_samples;
  80828. } FLAC__StreamMetadata_SeekPoint;
  80829. extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN; /**< == 64 (bits) */
  80830. extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN; /**< == 64 (bits) */
  80831. extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN; /**< == 16 (bits) */
  80832. #define FLAC__STREAM_METADATA_SEEKPOINT_LENGTH (18u)
  80833. extern FLAC_API const FLAC__uint64 FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
  80834. typedef struct {
  80835. unsigned num_points;
  80836. FLAC__StreamMetadata_SeekPoint *points;
  80837. } FLAC__StreamMetadata_SeekTable;
  80838. typedef struct {
  80839. FLAC__uint32 length;
  80840. FLAC__byte *entry;
  80841. } FLAC__StreamMetadata_VorbisComment_Entry;
  80842. extern FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN; /**< == 32 (bits) */
  80843. typedef struct {
  80844. FLAC__StreamMetadata_VorbisComment_Entry vendor_string;
  80845. FLAC__uint32 num_comments;
  80846. FLAC__StreamMetadata_VorbisComment_Entry *comments;
  80847. } FLAC__StreamMetadata_VorbisComment;
  80848. extern FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN; /**< == 32 (bits) */
  80849. typedef struct {
  80850. FLAC__uint64 offset;
  80851. FLAC__byte number;
  80852. } FLAC__StreamMetadata_CueSheet_Index;
  80853. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN; /**< == 64 (bits) */
  80854. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN; /**< == 8 (bits) */
  80855. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN; /**< == 3*8 (bits) */
  80856. typedef struct {
  80857. FLAC__uint64 offset;
  80858. FLAC__byte number;
  80859. char isrc[13];
  80860. unsigned type:1;
  80861. unsigned pre_emphasis:1;
  80862. FLAC__byte num_indices;
  80863. FLAC__StreamMetadata_CueSheet_Index *indices;
  80864. } FLAC__StreamMetadata_CueSheet_Track;
  80865. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN; /**< == 64 (bits) */
  80866. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN; /**< == 8 (bits) */
  80867. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN; /**< == 12*8 (bits) */
  80868. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN; /**< == 1 (bit) */
  80869. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN; /**< == 1 (bit) */
  80870. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN; /**< == 6+13*8 (bits) */
  80871. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN; /**< == 8 (bits) */
  80872. typedef struct {
  80873. char media_catalog_number[129];
  80874. FLAC__uint64 lead_in;
  80875. FLAC__bool is_cd;
  80876. unsigned num_tracks;
  80877. FLAC__StreamMetadata_CueSheet_Track *tracks;
  80878. } FLAC__StreamMetadata_CueSheet;
  80879. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN; /**< == 128*8 (bits) */
  80880. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN; /**< == 64 (bits) */
  80881. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN; /**< == 1 (bit) */
  80882. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN; /**< == 7+258*8 (bits) */
  80883. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN; /**< == 8 (bits) */
  80884. typedef enum {
  80885. FLAC__STREAM_METADATA_PICTURE_TYPE_OTHER = 0, /**< Other */
  80886. FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD = 1, /**< 32x32 pixels 'file icon' (PNG only) */
  80887. FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON = 2, /**< Other file icon */
  80888. FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER = 3, /**< Cover (front) */
  80889. FLAC__STREAM_METADATA_PICTURE_TYPE_BACK_COVER = 4, /**< Cover (back) */
  80890. FLAC__STREAM_METADATA_PICTURE_TYPE_LEAFLET_PAGE = 5, /**< Leaflet page */
  80891. FLAC__STREAM_METADATA_PICTURE_TYPE_MEDIA = 6, /**< Media (e.g. label side of CD) */
  80892. FLAC__STREAM_METADATA_PICTURE_TYPE_LEAD_ARTIST = 7, /**< Lead artist/lead performer/soloist */
  80893. FLAC__STREAM_METADATA_PICTURE_TYPE_ARTIST = 8, /**< Artist/performer */
  80894. FLAC__STREAM_METADATA_PICTURE_TYPE_CONDUCTOR = 9, /**< Conductor */
  80895. FLAC__STREAM_METADATA_PICTURE_TYPE_BAND = 10, /**< Band/Orchestra */
  80896. FLAC__STREAM_METADATA_PICTURE_TYPE_COMPOSER = 11, /**< Composer */
  80897. FLAC__STREAM_METADATA_PICTURE_TYPE_LYRICIST = 12, /**< Lyricist/text writer */
  80898. FLAC__STREAM_METADATA_PICTURE_TYPE_RECORDING_LOCATION = 13, /**< Recording Location */
  80899. FLAC__STREAM_METADATA_PICTURE_TYPE_DURING_RECORDING = 14, /**< During recording */
  80900. FLAC__STREAM_METADATA_PICTURE_TYPE_DURING_PERFORMANCE = 15, /**< During performance */
  80901. FLAC__STREAM_METADATA_PICTURE_TYPE_VIDEO_SCREEN_CAPTURE = 16, /**< Movie/video screen capture */
  80902. FLAC__STREAM_METADATA_PICTURE_TYPE_FISH = 17, /**< A bright coloured fish */
  80903. FLAC__STREAM_METADATA_PICTURE_TYPE_ILLUSTRATION = 18, /**< Illustration */
  80904. FLAC__STREAM_METADATA_PICTURE_TYPE_BAND_LOGOTYPE = 19, /**< Band/artist logotype */
  80905. FLAC__STREAM_METADATA_PICTURE_TYPE_PUBLISHER_LOGOTYPE = 20, /**< Publisher/Studio logotype */
  80906. FLAC__STREAM_METADATA_PICTURE_TYPE_UNDEFINED
  80907. } FLAC__StreamMetadata_Picture_Type;
  80908. extern FLAC_API const char * const FLAC__StreamMetadata_Picture_TypeString[];
  80909. typedef struct {
  80910. FLAC__StreamMetadata_Picture_Type type;
  80911. char *mime_type;
  80912. FLAC__byte *description;
  80913. FLAC__uint32 width;
  80914. FLAC__uint32 height;
  80915. FLAC__uint32 depth;
  80916. FLAC__uint32 colors;
  80917. FLAC__uint32 data_length;
  80918. FLAC__byte *data;
  80919. } FLAC__StreamMetadata_Picture;
  80920. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_TYPE_LEN; /**< == 32 (bits) */
  80921. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN; /**< == 32 (bits) */
  80922. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN; /**< == 32 (bits) */
  80923. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN; /**< == 32 (bits) */
  80924. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN; /**< == 32 (bits) */
  80925. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN; /**< == 32 (bits) */
  80926. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_COLORS_LEN; /**< == 32 (bits) */
  80927. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN; /**< == 32 (bits) */
  80928. typedef struct {
  80929. FLAC__byte *data;
  80930. } FLAC__StreamMetadata_Unknown;
  80931. typedef struct {
  80932. FLAC__MetadataType type;
  80933. FLAC__bool is_last;
  80934. unsigned length;
  80935. union {
  80936. FLAC__StreamMetadata_StreamInfo stream_info;
  80937. FLAC__StreamMetadata_Padding padding;
  80938. FLAC__StreamMetadata_Application application;
  80939. FLAC__StreamMetadata_SeekTable seek_table;
  80940. FLAC__StreamMetadata_VorbisComment vorbis_comment;
  80941. FLAC__StreamMetadata_CueSheet cue_sheet;
  80942. FLAC__StreamMetadata_Picture picture;
  80943. FLAC__StreamMetadata_Unknown unknown;
  80944. } data;
  80945. } FLAC__StreamMetadata;
  80946. extern FLAC_API const unsigned FLAC__STREAM_METADATA_IS_LAST_LEN; /**< == 1 (bit) */
  80947. extern FLAC_API const unsigned FLAC__STREAM_METADATA_TYPE_LEN; /**< == 7 (bits) */
  80948. extern FLAC_API const unsigned FLAC__STREAM_METADATA_LENGTH_LEN; /**< == 24 (bits) */
  80949. #define FLAC__STREAM_METADATA_HEADER_LENGTH (4u)
  80950. FLAC_API FLAC__bool FLAC__format_sample_rate_is_valid(unsigned sample_rate);
  80951. FLAC_API FLAC__bool FLAC__format_sample_rate_is_subset(unsigned sample_rate);
  80952. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_name_is_legal(const char *name);
  80953. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_value_is_legal(const FLAC__byte *value, unsigned length);
  80954. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_is_legal(const FLAC__byte *entry, unsigned length);
  80955. FLAC_API FLAC__bool FLAC__format_seektable_is_legal(const FLAC__StreamMetadata_SeekTable *seek_table);
  80956. FLAC_API unsigned FLAC__format_seektable_sort(FLAC__StreamMetadata_SeekTable *seek_table);
  80957. FLAC_API FLAC__bool FLAC__format_cuesheet_is_legal(const FLAC__StreamMetadata_CueSheet *cue_sheet, FLAC__bool check_cd_da_subset, const char **violation);
  80958. FLAC_API FLAC__bool FLAC__format_picture_is_legal(const FLAC__StreamMetadata_Picture *picture, const char **violation);
  80959. #ifdef __cplusplus
  80960. }
  80961. #endif
  80962. #endif
  80963. /*** End of inlined file: format.h ***/
  80964. /*** Start of inlined file: metadata.h ***/
  80965. #ifndef FLAC__METADATA_H
  80966. #define FLAC__METADATA_H
  80967. #include <sys/types.h> /* for off_t */
  80968. #ifdef __cplusplus
  80969. extern "C" {
  80970. #endif
  80971. FLAC_API FLAC__bool FLAC__metadata_get_streaminfo(const char *filename, FLAC__StreamMetadata *streaminfo);
  80972. FLAC_API FLAC__bool FLAC__metadata_get_tags(const char *filename, FLAC__StreamMetadata **tags);
  80973. FLAC_API FLAC__bool FLAC__metadata_get_cuesheet(const char *filename, FLAC__StreamMetadata **cuesheet);
  80974. 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);
  80975. struct FLAC__Metadata_SimpleIterator;
  80976. typedef struct FLAC__Metadata_SimpleIterator FLAC__Metadata_SimpleIterator;
  80977. typedef enum {
  80978. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK = 0,
  80979. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ILLEGAL_INPUT,
  80980. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ERROR_OPENING_FILE,
  80981. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_A_FLAC_FILE,
  80982. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_WRITABLE,
  80983. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_BAD_METADATA,
  80984. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR,
  80985. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR,
  80986. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR,
  80987. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_RENAME_ERROR,
  80988. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_UNLINK_ERROR,
  80989. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR,
  80990. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_INTERNAL_ERROR
  80991. } FLAC__Metadata_SimpleIteratorStatus;
  80992. extern FLAC_API const char * const FLAC__Metadata_SimpleIteratorStatusString[];
  80993. FLAC_API FLAC__Metadata_SimpleIterator *FLAC__metadata_simple_iterator_new(void);
  80994. FLAC_API void FLAC__metadata_simple_iterator_delete(FLAC__Metadata_SimpleIterator *iterator);
  80995. FLAC_API FLAC__Metadata_SimpleIteratorStatus FLAC__metadata_simple_iterator_status(FLAC__Metadata_SimpleIterator *iterator);
  80996. 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);
  80997. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_is_writable(const FLAC__Metadata_SimpleIterator *iterator);
  80998. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_next(FLAC__Metadata_SimpleIterator *iterator);
  80999. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_prev(FLAC__Metadata_SimpleIterator *iterator);
  81000. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_is_last(const FLAC__Metadata_SimpleIterator *iterator);
  81001. FLAC_API off_t FLAC__metadata_simple_iterator_get_block_offset(const FLAC__Metadata_SimpleIterator *iterator);
  81002. FLAC_API FLAC__MetadataType FLAC__metadata_simple_iterator_get_block_type(const FLAC__Metadata_SimpleIterator *iterator);
  81003. FLAC_API unsigned FLAC__metadata_simple_iterator_get_block_length(const FLAC__Metadata_SimpleIterator *iterator);
  81004. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_get_application_id(FLAC__Metadata_SimpleIterator *iterator, FLAC__byte *id);
  81005. FLAC_API FLAC__StreamMetadata *FLAC__metadata_simple_iterator_get_block(FLAC__Metadata_SimpleIterator *iterator);
  81006. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_set_block(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool use_padding);
  81007. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_insert_block_after(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool use_padding);
  81008. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_delete_block(FLAC__Metadata_SimpleIterator *iterator, FLAC__bool use_padding);
  81009. struct FLAC__Metadata_Chain;
  81010. typedef struct FLAC__Metadata_Chain FLAC__Metadata_Chain;
  81011. struct FLAC__Metadata_Iterator;
  81012. typedef struct FLAC__Metadata_Iterator FLAC__Metadata_Iterator;
  81013. typedef enum {
  81014. FLAC__METADATA_CHAIN_STATUS_OK = 0,
  81015. FLAC__METADATA_CHAIN_STATUS_ILLEGAL_INPUT,
  81016. FLAC__METADATA_CHAIN_STATUS_ERROR_OPENING_FILE,
  81017. FLAC__METADATA_CHAIN_STATUS_NOT_A_FLAC_FILE,
  81018. FLAC__METADATA_CHAIN_STATUS_NOT_WRITABLE,
  81019. FLAC__METADATA_CHAIN_STATUS_BAD_METADATA,
  81020. FLAC__METADATA_CHAIN_STATUS_READ_ERROR,
  81021. FLAC__METADATA_CHAIN_STATUS_SEEK_ERROR,
  81022. FLAC__METADATA_CHAIN_STATUS_WRITE_ERROR,
  81023. FLAC__METADATA_CHAIN_STATUS_RENAME_ERROR,
  81024. FLAC__METADATA_CHAIN_STATUS_UNLINK_ERROR,
  81025. FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR,
  81026. FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR,
  81027. FLAC__METADATA_CHAIN_STATUS_INVALID_CALLBACKS,
  81028. FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH,
  81029. FLAC__METADATA_CHAIN_STATUS_WRONG_WRITE_CALL
  81030. } FLAC__Metadata_ChainStatus;
  81031. extern FLAC_API const char * const FLAC__Metadata_ChainStatusString[];
  81032. FLAC_API FLAC__Metadata_Chain *FLAC__metadata_chain_new(void);
  81033. FLAC_API void FLAC__metadata_chain_delete(FLAC__Metadata_Chain *chain);
  81034. FLAC_API FLAC__Metadata_ChainStatus FLAC__metadata_chain_status(FLAC__Metadata_Chain *chain);
  81035. FLAC_API FLAC__bool FLAC__metadata_chain_read(FLAC__Metadata_Chain *chain, const char *filename);
  81036. FLAC_API FLAC__bool FLAC__metadata_chain_read_ogg(FLAC__Metadata_Chain *chain, const char *filename);
  81037. FLAC_API FLAC__bool FLAC__metadata_chain_read_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
  81038. FLAC_API FLAC__bool FLAC__metadata_chain_read_ogg_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
  81039. FLAC_API FLAC__bool FLAC__metadata_chain_check_if_tempfile_needed(FLAC__Metadata_Chain *chain, FLAC__bool use_padding);
  81040. FLAC_API FLAC__bool FLAC__metadata_chain_write(FLAC__Metadata_Chain *chain, FLAC__bool use_padding, FLAC__bool preserve_file_stats);
  81041. FLAC_API FLAC__bool FLAC__metadata_chain_write_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__bool use_padding, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
  81042. 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);
  81043. FLAC_API void FLAC__metadata_chain_merge_padding(FLAC__Metadata_Chain *chain);
  81044. FLAC_API void FLAC__metadata_chain_sort_padding(FLAC__Metadata_Chain *chain);
  81045. FLAC_API FLAC__Metadata_Iterator *FLAC__metadata_iterator_new(void);
  81046. FLAC_API void FLAC__metadata_iterator_delete(FLAC__Metadata_Iterator *iterator);
  81047. FLAC_API void FLAC__metadata_iterator_init(FLAC__Metadata_Iterator *iterator, FLAC__Metadata_Chain *chain);
  81048. FLAC_API FLAC__bool FLAC__metadata_iterator_next(FLAC__Metadata_Iterator *iterator);
  81049. FLAC_API FLAC__bool FLAC__metadata_iterator_prev(FLAC__Metadata_Iterator *iterator);
  81050. FLAC_API FLAC__MetadataType FLAC__metadata_iterator_get_block_type(const FLAC__Metadata_Iterator *iterator);
  81051. FLAC_API FLAC__StreamMetadata *FLAC__metadata_iterator_get_block(FLAC__Metadata_Iterator *iterator);
  81052. FLAC_API FLAC__bool FLAC__metadata_iterator_set_block(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
  81053. FLAC_API FLAC__bool FLAC__metadata_iterator_delete_block(FLAC__Metadata_Iterator *iterator, FLAC__bool replace_with_padding);
  81054. FLAC_API FLAC__bool FLAC__metadata_iterator_insert_block_before(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
  81055. FLAC_API FLAC__bool FLAC__metadata_iterator_insert_block_after(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
  81056. FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_new(FLAC__MetadataType type);
  81057. FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_clone(const FLAC__StreamMetadata *object);
  81058. FLAC_API void FLAC__metadata_object_delete(FLAC__StreamMetadata *object);
  81059. FLAC_API FLAC__bool FLAC__metadata_object_is_equal(const FLAC__StreamMetadata *block1, const FLAC__StreamMetadata *block2);
  81060. FLAC_API FLAC__bool FLAC__metadata_object_application_set_data(FLAC__StreamMetadata *object, FLAC__byte *data, unsigned length, FLAC__bool copy);
  81061. FLAC_API FLAC__bool FLAC__metadata_object_seektable_resize_points(FLAC__StreamMetadata *object, unsigned new_num_points);
  81062. FLAC_API void FLAC__metadata_object_seektable_set_point(FLAC__StreamMetadata *object, unsigned point_num, FLAC__StreamMetadata_SeekPoint point);
  81063. FLAC_API FLAC__bool FLAC__metadata_object_seektable_insert_point(FLAC__StreamMetadata *object, unsigned point_num, FLAC__StreamMetadata_SeekPoint point);
  81064. FLAC_API FLAC__bool FLAC__metadata_object_seektable_delete_point(FLAC__StreamMetadata *object, unsigned point_num);
  81065. FLAC_API FLAC__bool FLAC__metadata_object_seektable_is_legal(const FLAC__StreamMetadata *object);
  81066. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_placeholders(FLAC__StreamMetadata *object, unsigned num);
  81067. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_point(FLAC__StreamMetadata *object, FLAC__uint64 sample_number);
  81068. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_points(FLAC__StreamMetadata *object, FLAC__uint64 sample_numbers[], unsigned num);
  81069. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points(FLAC__StreamMetadata *object, unsigned num, FLAC__uint64 total_samples);
  81070. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points_by_samples(FLAC__StreamMetadata *object, unsigned samples, FLAC__uint64 total_samples);
  81071. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_sort(FLAC__StreamMetadata *object, FLAC__bool compact);
  81072. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_set_vendor_string(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  81073. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_resize_comments(FLAC__StreamMetadata *object, unsigned new_num_comments);
  81074. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_set_comment(FLAC__StreamMetadata *object, unsigned comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  81075. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_insert_comment(FLAC__StreamMetadata *object, unsigned comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  81076. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_append_comment(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  81077. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_replace_comment(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool all, FLAC__bool copy);
  81078. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_delete_comment(FLAC__StreamMetadata *object, unsigned comment_num);
  81079. 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);
  81080. 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);
  81081. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_entry_matches(const FLAC__StreamMetadata_VorbisComment_Entry entry, const char *field_name, unsigned field_name_length);
  81082. FLAC_API int FLAC__metadata_object_vorbiscomment_find_entry_from(const FLAC__StreamMetadata *object, unsigned offset, const char *field_name);
  81083. FLAC_API int FLAC__metadata_object_vorbiscomment_remove_entry_matching(FLAC__StreamMetadata *object, const char *field_name);
  81084. FLAC_API int FLAC__metadata_object_vorbiscomment_remove_entries_matching(FLAC__StreamMetadata *object, const char *field_name);
  81085. FLAC_API FLAC__StreamMetadata_CueSheet_Track *FLAC__metadata_object_cuesheet_track_new(void);
  81086. FLAC_API FLAC__StreamMetadata_CueSheet_Track *FLAC__metadata_object_cuesheet_track_clone(const FLAC__StreamMetadata_CueSheet_Track *object);
  81087. FLAC_API void FLAC__metadata_object_cuesheet_track_delete(FLAC__StreamMetadata_CueSheet_Track *object);
  81088. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_resize_indices(FLAC__StreamMetadata *object, unsigned track_num, unsigned new_num_indices);
  81089. 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);
  81090. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_insert_blank_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num);
  81091. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_delete_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num);
  81092. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_resize_tracks(FLAC__StreamMetadata *object, unsigned new_num_tracks);
  81093. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_set_track(FLAC__StreamMetadata *object, unsigned track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy);
  81094. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_track(FLAC__StreamMetadata *object, unsigned track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy);
  81095. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_blank_track(FLAC__StreamMetadata *object, unsigned track_num);
  81096. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_delete_track(FLAC__StreamMetadata *object, unsigned track_num);
  81097. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_is_legal(const FLAC__StreamMetadata *object, FLAC__bool check_cd_da_subset, const char **violation);
  81098. FLAC_API FLAC__uint32 FLAC__metadata_object_cuesheet_calculate_cddb_id(const FLAC__StreamMetadata *object);
  81099. FLAC_API FLAC__bool FLAC__metadata_object_picture_set_mime_type(FLAC__StreamMetadata *object, char *mime_type, FLAC__bool copy);
  81100. FLAC_API FLAC__bool FLAC__metadata_object_picture_set_description(FLAC__StreamMetadata *object, FLAC__byte *description, FLAC__bool copy);
  81101. FLAC_API FLAC__bool FLAC__metadata_object_picture_set_data(FLAC__StreamMetadata *object, FLAC__byte *data, FLAC__uint32 length, FLAC__bool copy);
  81102. FLAC_API FLAC__bool FLAC__metadata_object_picture_is_legal(const FLAC__StreamMetadata *object, const char **violation);
  81103. #ifdef __cplusplus
  81104. }
  81105. #endif
  81106. #endif
  81107. /*** End of inlined file: metadata.h ***/
  81108. /*** Start of inlined file: stream_decoder.h ***/
  81109. #ifndef FLAC__STREAM_DECODER_H
  81110. #define FLAC__STREAM_DECODER_H
  81111. #include <stdio.h> /* for FILE */
  81112. #ifdef __cplusplus
  81113. extern "C" {
  81114. #endif
  81115. typedef enum {
  81116. FLAC__STREAM_DECODER_SEARCH_FOR_METADATA = 0,
  81117. FLAC__STREAM_DECODER_READ_METADATA,
  81118. FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC,
  81119. FLAC__STREAM_DECODER_READ_FRAME,
  81120. FLAC__STREAM_DECODER_END_OF_STREAM,
  81121. FLAC__STREAM_DECODER_OGG_ERROR,
  81122. FLAC__STREAM_DECODER_SEEK_ERROR,
  81123. FLAC__STREAM_DECODER_ABORTED,
  81124. FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR,
  81125. FLAC__STREAM_DECODER_UNINITIALIZED
  81126. } FLAC__StreamDecoderState;
  81127. extern FLAC_API const char * const FLAC__StreamDecoderStateString[];
  81128. typedef enum {
  81129. FLAC__STREAM_DECODER_INIT_STATUS_OK = 0,
  81130. FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER,
  81131. FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS,
  81132. FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR,
  81133. FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE,
  81134. FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED
  81135. } FLAC__StreamDecoderInitStatus;
  81136. extern FLAC_API const char * const FLAC__StreamDecoderInitStatusString[];
  81137. typedef enum {
  81138. FLAC__STREAM_DECODER_READ_STATUS_CONTINUE,
  81139. FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM,
  81140. FLAC__STREAM_DECODER_READ_STATUS_ABORT
  81141. } FLAC__StreamDecoderReadStatus;
  81142. extern FLAC_API const char * const FLAC__StreamDecoderReadStatusString[];
  81143. typedef enum {
  81144. FLAC__STREAM_DECODER_SEEK_STATUS_OK,
  81145. FLAC__STREAM_DECODER_SEEK_STATUS_ERROR,
  81146. FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED
  81147. } FLAC__StreamDecoderSeekStatus;
  81148. extern FLAC_API const char * const FLAC__StreamDecoderSeekStatusString[];
  81149. typedef enum {
  81150. FLAC__STREAM_DECODER_TELL_STATUS_OK,
  81151. FLAC__STREAM_DECODER_TELL_STATUS_ERROR,
  81152. FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED
  81153. } FLAC__StreamDecoderTellStatus;
  81154. extern FLAC_API const char * const FLAC__StreamDecoderTellStatusString[];
  81155. typedef enum {
  81156. FLAC__STREAM_DECODER_LENGTH_STATUS_OK,
  81157. FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR,
  81158. FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED
  81159. } FLAC__StreamDecoderLengthStatus;
  81160. extern FLAC_API const char * const FLAC__StreamDecoderLengthStatusString[];
  81161. typedef enum {
  81162. FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE,
  81163. FLAC__STREAM_DECODER_WRITE_STATUS_ABORT
  81164. } FLAC__StreamDecoderWriteStatus;
  81165. extern FLAC_API const char * const FLAC__StreamDecoderWriteStatusString[];
  81166. typedef enum {
  81167. FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC,
  81168. FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER,
  81169. FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH,
  81170. FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM
  81171. } FLAC__StreamDecoderErrorStatus;
  81172. extern FLAC_API const char * const FLAC__StreamDecoderErrorStatusString[];
  81173. struct FLAC__StreamDecoderProtected;
  81174. struct FLAC__StreamDecoderPrivate;
  81175. typedef struct {
  81176. struct FLAC__StreamDecoderProtected *protected_; /* avoid the C++ keyword 'protected' */
  81177. struct FLAC__StreamDecoderPrivate *private_; /* avoid the C++ keyword 'private' */
  81178. } FLAC__StreamDecoder;
  81179. typedef FLAC__StreamDecoderReadStatus (*FLAC__StreamDecoderReadCallback)(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  81180. typedef FLAC__StreamDecoderSeekStatus (*FLAC__StreamDecoderSeekCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  81181. typedef FLAC__StreamDecoderTellStatus (*FLAC__StreamDecoderTellCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  81182. typedef FLAC__StreamDecoderLengthStatus (*FLAC__StreamDecoderLengthCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
  81183. typedef FLAC__bool (*FLAC__StreamDecoderEofCallback)(const FLAC__StreamDecoder *decoder, void *client_data);
  81184. typedef FLAC__StreamDecoderWriteStatus (*FLAC__StreamDecoderWriteCallback)(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
  81185. typedef void (*FLAC__StreamDecoderMetadataCallback)(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
  81186. typedef void (*FLAC__StreamDecoderErrorCallback)(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
  81187. FLAC_API FLAC__StreamDecoder *FLAC__stream_decoder_new(void);
  81188. FLAC_API void FLAC__stream_decoder_delete(FLAC__StreamDecoder *decoder);
  81189. FLAC_API FLAC__bool FLAC__stream_decoder_set_ogg_serial_number(FLAC__StreamDecoder *decoder, long serial_number);
  81190. FLAC_API FLAC__bool FLAC__stream_decoder_set_md5_checking(FLAC__StreamDecoder *decoder, FLAC__bool value);
  81191. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond(FLAC__StreamDecoder *decoder, FLAC__MetadataType type);
  81192. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4]);
  81193. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_all(FLAC__StreamDecoder *decoder);
  81194. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore(FLAC__StreamDecoder *decoder, FLAC__MetadataType type);
  81195. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4]);
  81196. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_all(FLAC__StreamDecoder *decoder);
  81197. FLAC_API FLAC__StreamDecoderState FLAC__stream_decoder_get_state(const FLAC__StreamDecoder *decoder);
  81198. FLAC_API const char *FLAC__stream_decoder_get_resolved_state_string(const FLAC__StreamDecoder *decoder);
  81199. FLAC_API FLAC__bool FLAC__stream_decoder_get_md5_checking(const FLAC__StreamDecoder *decoder);
  81200. FLAC_API FLAC__uint64 FLAC__stream_decoder_get_total_samples(const FLAC__StreamDecoder *decoder);
  81201. FLAC_API unsigned FLAC__stream_decoder_get_channels(const FLAC__StreamDecoder *decoder);
  81202. FLAC_API FLAC__ChannelAssignment FLAC__stream_decoder_get_channel_assignment(const FLAC__StreamDecoder *decoder);
  81203. FLAC_API unsigned FLAC__stream_decoder_get_bits_per_sample(const FLAC__StreamDecoder *decoder);
  81204. FLAC_API unsigned FLAC__stream_decoder_get_sample_rate(const FLAC__StreamDecoder *decoder);
  81205. FLAC_API unsigned FLAC__stream_decoder_get_blocksize(const FLAC__StreamDecoder *decoder);
  81206. FLAC_API FLAC__bool FLAC__stream_decoder_get_decode_position(const FLAC__StreamDecoder *decoder, FLAC__uint64 *position);
  81207. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_stream(
  81208. FLAC__StreamDecoder *decoder,
  81209. FLAC__StreamDecoderReadCallback read_callback,
  81210. FLAC__StreamDecoderSeekCallback seek_callback,
  81211. FLAC__StreamDecoderTellCallback tell_callback,
  81212. FLAC__StreamDecoderLengthCallback length_callback,
  81213. FLAC__StreamDecoderEofCallback eof_callback,
  81214. FLAC__StreamDecoderWriteCallback write_callback,
  81215. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81216. FLAC__StreamDecoderErrorCallback error_callback,
  81217. void *client_data
  81218. );
  81219. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_stream(
  81220. FLAC__StreamDecoder *decoder,
  81221. FLAC__StreamDecoderReadCallback read_callback,
  81222. FLAC__StreamDecoderSeekCallback seek_callback,
  81223. FLAC__StreamDecoderTellCallback tell_callback,
  81224. FLAC__StreamDecoderLengthCallback length_callback,
  81225. FLAC__StreamDecoderEofCallback eof_callback,
  81226. FLAC__StreamDecoderWriteCallback write_callback,
  81227. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81228. FLAC__StreamDecoderErrorCallback error_callback,
  81229. void *client_data
  81230. );
  81231. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_FILE(
  81232. FLAC__StreamDecoder *decoder,
  81233. FILE *file,
  81234. FLAC__StreamDecoderWriteCallback write_callback,
  81235. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81236. FLAC__StreamDecoderErrorCallback error_callback,
  81237. void *client_data
  81238. );
  81239. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_FILE(
  81240. FLAC__StreamDecoder *decoder,
  81241. FILE *file,
  81242. FLAC__StreamDecoderWriteCallback write_callback,
  81243. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81244. FLAC__StreamDecoderErrorCallback error_callback,
  81245. void *client_data
  81246. );
  81247. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_file(
  81248. FLAC__StreamDecoder *decoder,
  81249. const char *filename,
  81250. FLAC__StreamDecoderWriteCallback write_callback,
  81251. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81252. FLAC__StreamDecoderErrorCallback error_callback,
  81253. void *client_data
  81254. );
  81255. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_file(
  81256. FLAC__StreamDecoder *decoder,
  81257. const char *filename,
  81258. FLAC__StreamDecoderWriteCallback write_callback,
  81259. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81260. FLAC__StreamDecoderErrorCallback error_callback,
  81261. void *client_data
  81262. );
  81263. FLAC_API FLAC__bool FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder);
  81264. FLAC_API FLAC__bool FLAC__stream_decoder_flush(FLAC__StreamDecoder *decoder);
  81265. FLAC_API FLAC__bool FLAC__stream_decoder_reset(FLAC__StreamDecoder *decoder);
  81266. FLAC_API FLAC__bool FLAC__stream_decoder_process_single(FLAC__StreamDecoder *decoder);
  81267. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_metadata(FLAC__StreamDecoder *decoder);
  81268. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_stream(FLAC__StreamDecoder *decoder);
  81269. FLAC_API FLAC__bool FLAC__stream_decoder_skip_single_frame(FLAC__StreamDecoder *decoder);
  81270. FLAC_API FLAC__bool FLAC__stream_decoder_seek_absolute(FLAC__StreamDecoder *decoder, FLAC__uint64 sample);
  81271. #ifdef __cplusplus
  81272. }
  81273. #endif
  81274. #endif
  81275. /*** End of inlined file: stream_decoder.h ***/
  81276. /*** Start of inlined file: stream_encoder.h ***/
  81277. #ifndef FLAC__STREAM_ENCODER_H
  81278. #define FLAC__STREAM_ENCODER_H
  81279. #include <stdio.h> /* for FILE */
  81280. #ifdef __cplusplus
  81281. extern "C" {
  81282. #endif
  81283. typedef enum {
  81284. FLAC__STREAM_ENCODER_OK = 0,
  81285. FLAC__STREAM_ENCODER_UNINITIALIZED,
  81286. FLAC__STREAM_ENCODER_OGG_ERROR,
  81287. FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR,
  81288. FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA,
  81289. FLAC__STREAM_ENCODER_CLIENT_ERROR,
  81290. FLAC__STREAM_ENCODER_IO_ERROR,
  81291. FLAC__STREAM_ENCODER_FRAMING_ERROR,
  81292. FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR
  81293. } FLAC__StreamEncoderState;
  81294. extern FLAC_API const char * const FLAC__StreamEncoderStateString[];
  81295. typedef enum {
  81296. FLAC__STREAM_ENCODER_INIT_STATUS_OK = 0,
  81297. FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR,
  81298. FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER,
  81299. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS,
  81300. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS,
  81301. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE,
  81302. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE,
  81303. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE,
  81304. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER,
  81305. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION,
  81306. FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER,
  81307. FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE,
  81308. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA,
  81309. FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED
  81310. } FLAC__StreamEncoderInitStatus;
  81311. extern FLAC_API const char * const FLAC__StreamEncoderInitStatusString[];
  81312. typedef enum {
  81313. FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE,
  81314. FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM,
  81315. FLAC__STREAM_ENCODER_READ_STATUS_ABORT,
  81316. FLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED
  81317. } FLAC__StreamEncoderReadStatus;
  81318. extern FLAC_API const char * const FLAC__StreamEncoderReadStatusString[];
  81319. typedef enum {
  81320. FLAC__STREAM_ENCODER_WRITE_STATUS_OK = 0,
  81321. FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR
  81322. } FLAC__StreamEncoderWriteStatus;
  81323. extern FLAC_API const char * const FLAC__StreamEncoderWriteStatusString[];
  81324. typedef enum {
  81325. FLAC__STREAM_ENCODER_SEEK_STATUS_OK,
  81326. FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR,
  81327. FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED
  81328. } FLAC__StreamEncoderSeekStatus;
  81329. extern FLAC_API const char * const FLAC__StreamEncoderSeekStatusString[];
  81330. typedef enum {
  81331. FLAC__STREAM_ENCODER_TELL_STATUS_OK,
  81332. FLAC__STREAM_ENCODER_TELL_STATUS_ERROR,
  81333. FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED
  81334. } FLAC__StreamEncoderTellStatus;
  81335. extern FLAC_API const char * const FLAC__StreamEncoderTellStatusString[];
  81336. struct FLAC__StreamEncoderProtected;
  81337. struct FLAC__StreamEncoderPrivate;
  81338. typedef struct {
  81339. struct FLAC__StreamEncoderProtected *protected_; /* avoid the C++ keyword 'protected' */
  81340. struct FLAC__StreamEncoderPrivate *private_; /* avoid the C++ keyword 'private' */
  81341. } FLAC__StreamEncoder;
  81342. typedef FLAC__StreamEncoderReadStatus (*FLAC__StreamEncoderReadCallback)(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  81343. typedef FLAC__StreamEncoderWriteStatus (*FLAC__StreamEncoderWriteCallback)(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame, void *client_data);
  81344. typedef FLAC__StreamEncoderSeekStatus (*FLAC__StreamEncoderSeekCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  81345. typedef FLAC__StreamEncoderTellStatus (*FLAC__StreamEncoderTellCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  81346. typedef void (*FLAC__StreamEncoderMetadataCallback)(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetadata *metadata, void *client_data);
  81347. 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);
  81348. FLAC_API FLAC__StreamEncoder *FLAC__stream_encoder_new(void);
  81349. FLAC_API void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder);
  81350. FLAC_API FLAC__bool FLAC__stream_encoder_set_ogg_serial_number(FLAC__StreamEncoder *encoder, long serial_number);
  81351. FLAC_API FLAC__bool FLAC__stream_encoder_set_verify(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81352. FLAC_API FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81353. FLAC_API FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder *encoder, unsigned value);
  81354. FLAC_API FLAC__bool FLAC__stream_encoder_set_bits_per_sample(FLAC__StreamEncoder *encoder, unsigned value);
  81355. FLAC_API FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *encoder, unsigned value);
  81356. FLAC_API FLAC__bool FLAC__stream_encoder_set_compression_level(FLAC__StreamEncoder *encoder, unsigned value);
  81357. FLAC_API FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *encoder, unsigned value);
  81358. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81359. FLAC_API FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81360. FLAC_API FLAC__bool FLAC__stream_encoder_set_apodization(FLAC__StreamEncoder *encoder, const char *specification);
  81361. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_lpc_order(FLAC__StreamEncoder *encoder, unsigned value);
  81362. FLAC_API FLAC__bool FLAC__stream_encoder_set_qlp_coeff_precision(FLAC__StreamEncoder *encoder, unsigned value);
  81363. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_qlp_coeff_prec_search(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81364. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_escape_coding(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81365. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_exhaustive_model_search(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81366. FLAC_API FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value);
  81367. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value);
  81368. FLAC_API FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(FLAC__StreamEncoder *encoder, unsigned value);
  81369. FLAC_API FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__StreamEncoder *encoder, FLAC__uint64 value);
  81370. FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, unsigned num_blocks);
  81371. FLAC_API FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder);
  81372. FLAC_API FLAC__StreamDecoderState FLAC__stream_encoder_get_verify_decoder_state(const FLAC__StreamEncoder *encoder);
  81373. FLAC_API const char *FLAC__stream_encoder_get_resolved_state_string(const FLAC__StreamEncoder *encoder);
  81374. 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);
  81375. FLAC_API FLAC__bool FLAC__stream_encoder_get_verify(const FLAC__StreamEncoder *encoder);
  81376. FLAC_API FLAC__bool FLAC__stream_encoder_get_streamable_subset(const FLAC__StreamEncoder *encoder);
  81377. FLAC_API unsigned FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder);
  81378. FLAC_API unsigned FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder *encoder);
  81379. FLAC_API unsigned FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder *encoder);
  81380. FLAC_API unsigned FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder);
  81381. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder);
  81382. FLAC_API FLAC__bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder);
  81383. FLAC_API unsigned FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder);
  81384. FLAC_API unsigned FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder *encoder);
  81385. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder);
  81386. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_escape_coding(const FLAC__StreamEncoder *encoder);
  81387. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder);
  81388. FLAC_API unsigned FLAC__stream_encoder_get_min_residual_partition_order(const FLAC__StreamEncoder *encoder);
  81389. FLAC_API unsigned FLAC__stream_encoder_get_max_residual_partition_order(const FLAC__StreamEncoder *encoder);
  81390. FLAC_API unsigned FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder);
  81391. FLAC_API FLAC__uint64 FLAC__stream_encoder_get_total_samples_estimate(const FLAC__StreamEncoder *encoder);
  81392. 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);
  81393. 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);
  81394. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_FILE(FLAC__StreamEncoder *encoder, FILE *file, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81395. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_FILE(FLAC__StreamEncoder *encoder, FILE *file, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81396. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_file(FLAC__StreamEncoder *encoder, const char *filename, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81397. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_file(FLAC__StreamEncoder *encoder, const char *filename, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81398. FLAC_API FLAC__bool FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder);
  81399. FLAC_API FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, const FLAC__int32 * const buffer[], unsigned samples);
  81400. FLAC_API FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder *encoder, const FLAC__int32 buffer[], unsigned samples);
  81401. #ifdef __cplusplus
  81402. }
  81403. #endif
  81404. #endif
  81405. /*** End of inlined file: stream_encoder.h ***/
  81406. #ifdef _MSC_VER
  81407. static _inline FLAC__uint32 local_swap32_(FLAC__uint32 x)
  81408. {
  81409. x = ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);
  81410. return (x>>16) | (x<<16);
  81411. }
  81412. #endif
  81413. #if defined(_MSC_VER) && defined(_X86_)
  81414. static void local_swap32_block_(FLAC__uint32 *start, FLAC__uint32 len)
  81415. {
  81416. __asm {
  81417. mov edx, start
  81418. mov ecx, len
  81419. test ecx, ecx
  81420. loop1:
  81421. jz done1
  81422. mov eax, [edx]
  81423. bswap eax
  81424. mov [edx], eax
  81425. add edx, 4
  81426. dec ecx
  81427. jmp short loop1
  81428. done1:
  81429. }
  81430. }
  81431. #endif
  81432. #endif
  81433. /*** End of inlined file: all.h ***/
  81434. /*** Start of inlined file: bitmath.c ***/
  81435. /*** Start of inlined file: juce_FlacHeader.h ***/
  81436. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  81437. // tasks..
  81438. #define VERSION "1.2.1"
  81439. #define FLAC__NO_DLL 1
  81440. #if JUCE_MSVC
  81441. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  81442. #endif
  81443. #if JUCE_MAC
  81444. #define FLAC__SYS_DARWIN 1
  81445. #endif
  81446. /*** End of inlined file: juce_FlacHeader.h ***/
  81447. #if JUCE_USE_FLAC
  81448. #if HAVE_CONFIG_H
  81449. # include <config.h>
  81450. #endif
  81451. /*** Start of inlined file: bitmath.h ***/
  81452. #ifndef FLAC__PRIVATE__BITMATH_H
  81453. #define FLAC__PRIVATE__BITMATH_H
  81454. unsigned FLAC__bitmath_ilog2(FLAC__uint32 v);
  81455. unsigned FLAC__bitmath_ilog2_wide(FLAC__uint64 v);
  81456. unsigned FLAC__bitmath_silog2(int v);
  81457. unsigned FLAC__bitmath_silog2_wide(FLAC__int64 v);
  81458. #endif
  81459. /*** End of inlined file: bitmath.h ***/
  81460. unsigned FLAC__bitmath_ilog2(FLAC__uint32 v)
  81461. {
  81462. unsigned l = 0;
  81463. FLAC__ASSERT(v > 0);
  81464. while(v >>= 1)
  81465. l++;
  81466. return l;
  81467. }
  81468. unsigned FLAC__bitmath_ilog2_wide(FLAC__uint64 v)
  81469. {
  81470. unsigned l = 0;
  81471. FLAC__ASSERT(v > 0);
  81472. while(v >>= 1)
  81473. l++;
  81474. return l;
  81475. }
  81476. unsigned FLAC__bitmath_silog2(int v)
  81477. {
  81478. while(1) {
  81479. if(v == 0) {
  81480. return 0;
  81481. }
  81482. else if(v > 0) {
  81483. unsigned l = 0;
  81484. while(v) {
  81485. l++;
  81486. v >>= 1;
  81487. }
  81488. return l+1;
  81489. }
  81490. else if(v == -1) {
  81491. return 2;
  81492. }
  81493. else {
  81494. v++;
  81495. v = -v;
  81496. }
  81497. }
  81498. }
  81499. unsigned FLAC__bitmath_silog2_wide(FLAC__int64 v)
  81500. {
  81501. while(1) {
  81502. if(v == 0) {
  81503. return 0;
  81504. }
  81505. else if(v > 0) {
  81506. unsigned l = 0;
  81507. while(v) {
  81508. l++;
  81509. v >>= 1;
  81510. }
  81511. return l+1;
  81512. }
  81513. else if(v == -1) {
  81514. return 2;
  81515. }
  81516. else {
  81517. v++;
  81518. v = -v;
  81519. }
  81520. }
  81521. }
  81522. #endif
  81523. /*** End of inlined file: bitmath.c ***/
  81524. /*** Start of inlined file: bitreader.c ***/
  81525. /*** Start of inlined file: juce_FlacHeader.h ***/
  81526. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  81527. // tasks..
  81528. #define VERSION "1.2.1"
  81529. #define FLAC__NO_DLL 1
  81530. #if JUCE_MSVC
  81531. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  81532. #endif
  81533. #if JUCE_MAC
  81534. #define FLAC__SYS_DARWIN 1
  81535. #endif
  81536. /*** End of inlined file: juce_FlacHeader.h ***/
  81537. #if JUCE_USE_FLAC
  81538. #if HAVE_CONFIG_H
  81539. # include <config.h>
  81540. #endif
  81541. #include <stdlib.h> /* for malloc() */
  81542. #include <string.h> /* for memcpy(), memset() */
  81543. #ifdef _MSC_VER
  81544. #include <winsock.h> /* for ntohl() */
  81545. #elif defined FLAC__SYS_DARWIN
  81546. #include <machine/endian.h> /* for ntohl() */
  81547. #elif defined __MINGW32__
  81548. #include <winsock.h> /* for ntohl() */
  81549. #else
  81550. #include <netinet/in.h> /* for ntohl() */
  81551. #endif
  81552. /*** Start of inlined file: bitreader.h ***/
  81553. #ifndef FLAC__PRIVATE__BITREADER_H
  81554. #define FLAC__PRIVATE__BITREADER_H
  81555. #include <stdio.h> /* for FILE */
  81556. /*** Start of inlined file: cpu.h ***/
  81557. #ifndef FLAC__PRIVATE__CPU_H
  81558. #define FLAC__PRIVATE__CPU_H
  81559. #ifdef HAVE_CONFIG_H
  81560. #include <config.h>
  81561. #endif
  81562. typedef enum {
  81563. FLAC__CPUINFO_TYPE_IA32,
  81564. FLAC__CPUINFO_TYPE_PPC,
  81565. FLAC__CPUINFO_TYPE_UNKNOWN
  81566. } FLAC__CPUInfo_Type;
  81567. typedef struct {
  81568. FLAC__bool cpuid;
  81569. FLAC__bool bswap;
  81570. FLAC__bool cmov;
  81571. FLAC__bool mmx;
  81572. FLAC__bool fxsr;
  81573. FLAC__bool sse;
  81574. FLAC__bool sse2;
  81575. FLAC__bool sse3;
  81576. FLAC__bool ssse3;
  81577. FLAC__bool _3dnow;
  81578. FLAC__bool ext3dnow;
  81579. FLAC__bool extmmx;
  81580. } FLAC__CPUInfo_IA32;
  81581. typedef struct {
  81582. FLAC__bool altivec;
  81583. FLAC__bool ppc64;
  81584. } FLAC__CPUInfo_PPC;
  81585. typedef struct {
  81586. FLAC__bool use_asm;
  81587. FLAC__CPUInfo_Type type;
  81588. union {
  81589. FLAC__CPUInfo_IA32 ia32;
  81590. FLAC__CPUInfo_PPC ppc;
  81591. } data;
  81592. } FLAC__CPUInfo;
  81593. void FLAC__cpu_info(FLAC__CPUInfo *info);
  81594. #ifndef FLAC__NO_ASM
  81595. #ifdef FLAC__CPU_IA32
  81596. #ifdef FLAC__HAS_NASM
  81597. FLAC__uint32 FLAC__cpu_have_cpuid_asm_ia32(void);
  81598. void FLAC__cpu_info_asm_ia32(FLAC__uint32 *flags_edx, FLAC__uint32 *flags_ecx);
  81599. FLAC__uint32 FLAC__cpu_info_extended_amd_asm_ia32(void);
  81600. #endif
  81601. #endif
  81602. #endif
  81603. #endif
  81604. /*** End of inlined file: cpu.h ***/
  81605. struct FLAC__BitReader;
  81606. typedef struct FLAC__BitReader FLAC__BitReader;
  81607. typedef FLAC__bool (*FLAC__BitReaderReadCallback)(FLAC__byte buffer[], size_t *bytes, void *client_data);
  81608. FLAC__BitReader *FLAC__bitreader_new(void);
  81609. void FLAC__bitreader_delete(FLAC__BitReader *br);
  81610. FLAC__bool FLAC__bitreader_init(FLAC__BitReader *br, FLAC__CPUInfo cpu, FLAC__BitReaderReadCallback rcb, void *cd);
  81611. void FLAC__bitreader_free(FLAC__BitReader *br); /* does not 'free(br)' */
  81612. FLAC__bool FLAC__bitreader_clear(FLAC__BitReader *br);
  81613. void FLAC__bitreader_dump(const FLAC__BitReader *br, FILE *out);
  81614. void FLAC__bitreader_reset_read_crc16(FLAC__BitReader *br, FLAC__uint16 seed);
  81615. FLAC__uint16 FLAC__bitreader_get_read_crc16(FLAC__BitReader *br);
  81616. FLAC__bool FLAC__bitreader_is_consumed_byte_aligned(const FLAC__BitReader *br);
  81617. unsigned FLAC__bitreader_bits_left_for_byte_alignment(const FLAC__BitReader *br);
  81618. unsigned FLAC__bitreader_get_input_bits_unconsumed(const FLAC__BitReader *br);
  81619. FLAC__bool FLAC__bitreader_read_raw_uint32(FLAC__BitReader *br, FLAC__uint32 *val, unsigned bits);
  81620. FLAC__bool FLAC__bitreader_read_raw_int32(FLAC__BitReader *br, FLAC__int32 *val, unsigned bits);
  81621. FLAC__bool FLAC__bitreader_read_raw_uint64(FLAC__BitReader *br, FLAC__uint64 *val, unsigned bits);
  81622. FLAC__bool FLAC__bitreader_read_uint32_little_endian(FLAC__BitReader *br, FLAC__uint32 *val); /*only for bits=32*/
  81623. FLAC__bool FLAC__bitreader_skip_bits_no_crc(FLAC__BitReader *br, unsigned bits); /* WATCHOUT: does not CRC the skipped data! */ /*@@@@ add to unit tests */
  81624. FLAC__bool FLAC__bitreader_skip_byte_block_aligned_no_crc(FLAC__BitReader *br, unsigned nvals); /* WATCHOUT: does not CRC the read data! */
  81625. 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! */
  81626. FLAC__bool FLAC__bitreader_read_unary_unsigned(FLAC__BitReader *br, unsigned *val);
  81627. FLAC__bool FLAC__bitreader_read_rice_signed(FLAC__BitReader *br, int *val, unsigned parameter);
  81628. FLAC__bool FLAC__bitreader_read_rice_signed_block(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter);
  81629. #ifndef FLAC__NO_ASM
  81630. # ifdef FLAC__CPU_IA32
  81631. # ifdef FLAC__HAS_NASM
  81632. FLAC__bool FLAC__bitreader_read_rice_signed_block_asm_ia32_bswap(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter);
  81633. # endif
  81634. # endif
  81635. #endif
  81636. #if 0 /* UNUSED */
  81637. FLAC__bool FLAC__bitreader_read_golomb_signed(FLAC__BitReader *br, int *val, unsigned parameter);
  81638. FLAC__bool FLAC__bitreader_read_golomb_unsigned(FLAC__BitReader *br, unsigned *val, unsigned parameter);
  81639. #endif
  81640. FLAC__bool FLAC__bitreader_read_utf8_uint32(FLAC__BitReader *br, FLAC__uint32 *val, FLAC__byte *raw, unsigned *rawlen);
  81641. FLAC__bool FLAC__bitreader_read_utf8_uint64(FLAC__BitReader *br, FLAC__uint64 *val, FLAC__byte *raw, unsigned *rawlen);
  81642. FLAC__bool bitreader_read_from_client_(FLAC__BitReader *br);
  81643. #endif
  81644. /*** End of inlined file: bitreader.h ***/
  81645. /*** Start of inlined file: crc.h ***/
  81646. #ifndef FLAC__PRIVATE__CRC_H
  81647. #define FLAC__PRIVATE__CRC_H
  81648. extern FLAC__byte const FLAC__crc8_table[256];
  81649. #define FLAC__CRC8_UPDATE(data, crc) (crc) = FLAC__crc8_table[(crc) ^ (data)];
  81650. void FLAC__crc8_update(const FLAC__byte data, FLAC__uint8 *crc);
  81651. void FLAC__crc8_update_block(const FLAC__byte *data, unsigned len, FLAC__uint8 *crc);
  81652. FLAC__uint8 FLAC__crc8(const FLAC__byte *data, unsigned len);
  81653. extern unsigned FLAC__crc16_table[256];
  81654. #define FLAC__CRC16_UPDATE(data, crc) (((((crc)<<8) & 0xffff) ^ FLAC__crc16_table[((crc)>>8) ^ (data)]))
  81655. #if 0
  81656. #define FLAC__CRC16_UPDATE(data, crc) ((((crc)<<8) ^ FLAC__crc16_table[((crc)>>8) ^ (data)]) & 0xffff)
  81657. #endif
  81658. unsigned FLAC__crc16(const FLAC__byte *data, unsigned len);
  81659. #endif
  81660. /*** End of inlined file: crc.h ***/
  81661. typedef FLAC__uint32 brword;
  81662. #define FLAC__BYTES_PER_WORD 4
  81663. #define FLAC__BITS_PER_WORD 32
  81664. #define FLAC__WORD_ALL_ONES ((FLAC__uint32)0xffffffff)
  81665. #if WORDS_BIGENDIAN
  81666. #define SWAP_BE_WORD_TO_HOST(x) (x)
  81667. #else
  81668. #if defined (_MSC_VER) && defined (_X86_)
  81669. #define SWAP_BE_WORD_TO_HOST(x) local_swap32_(x)
  81670. #else
  81671. #define SWAP_BE_WORD_TO_HOST(x) ntohl(x)
  81672. #endif
  81673. #endif
  81674. #define COUNT_ZERO_MSBS(word) ( \
  81675. (word) <= 0xffff ? \
  81676. ( (word) <= 0xff? byte_to_unary_table[word] + 24 : byte_to_unary_table[(word) >> 8] + 16 ) : \
  81677. ( (word) <= 0xffffff? byte_to_unary_table[word >> 16] + 8 : byte_to_unary_table[(word) >> 24] ) \
  81678. )
  81679. #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])) )
  81680. static const unsigned FLAC__BITREADER_DEFAULT_CAPACITY = 65536u / FLAC__BITS_PER_WORD; /* in words */
  81681. static const unsigned char byte_to_unary_table[] = {
  81682. 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4,
  81683. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  81684. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  81685. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  81686. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  81687. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  81688. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  81689. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  81690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  81698. };
  81699. #ifdef min
  81700. #undef min
  81701. #endif
  81702. #define min(x,y) ((x)<(y)?(x):(y))
  81703. #ifdef max
  81704. #undef max
  81705. #endif
  81706. #define max(x,y) ((x)>(y)?(x):(y))
  81707. #ifdef _MSC_VER
  81708. #define FLAC__U64L(x) x
  81709. #else
  81710. #define FLAC__U64L(x) x##LLU
  81711. #endif
  81712. #ifndef FLaC__INLINE
  81713. #define FLaC__INLINE
  81714. #endif
  81715. struct FLAC__BitReader {
  81716. brword *buffer;
  81717. unsigned capacity; /* in words */
  81718. unsigned words; /* # of completed words in buffer */
  81719. unsigned bytes; /* # of bytes in incomplete word at buffer[words] */
  81720. unsigned consumed_words; /* #words ... */
  81721. unsigned consumed_bits; /* ... + (#bits of head word) already consumed from the front of buffer */
  81722. unsigned read_crc16; /* the running frame CRC */
  81723. unsigned crc16_align; /* the number of bits in the current consumed word that should not be CRC'd */
  81724. FLAC__BitReaderReadCallback read_callback;
  81725. void *client_data;
  81726. FLAC__CPUInfo cpu_info;
  81727. };
  81728. static FLaC__INLINE void crc16_update_word_(FLAC__BitReader *br, brword word)
  81729. {
  81730. register unsigned crc = br->read_crc16;
  81731. #if FLAC__BYTES_PER_WORD == 4
  81732. switch(br->crc16_align) {
  81733. case 0: crc = FLAC__CRC16_UPDATE((unsigned)(word >> 24), crc);
  81734. case 8: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 16) & 0xff), crc);
  81735. case 16: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 8) & 0xff), crc);
  81736. case 24: br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)(word & 0xff), crc);
  81737. }
  81738. #elif FLAC__BYTES_PER_WORD == 8
  81739. switch(br->crc16_align) {
  81740. case 0: crc = FLAC__CRC16_UPDATE((unsigned)(word >> 56), crc);
  81741. case 8: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 48) & 0xff), crc);
  81742. case 16: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 40) & 0xff), crc);
  81743. case 24: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 32) & 0xff), crc);
  81744. case 32: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 24) & 0xff), crc);
  81745. case 40: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 16) & 0xff), crc);
  81746. case 48: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 8) & 0xff), crc);
  81747. case 56: br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)(word & 0xff), crc);
  81748. }
  81749. #else
  81750. for( ; br->crc16_align < FLAC__BITS_PER_WORD; br->crc16_align += 8)
  81751. crc = FLAC__CRC16_UPDATE((unsigned)((word >> (FLAC__BITS_PER_WORD-8-br->crc16_align)) & 0xff), crc);
  81752. br->read_crc16 = crc;
  81753. #endif
  81754. br->crc16_align = 0;
  81755. }
  81756. FLAC__bool bitreader_read_from_client_(FLAC__BitReader *br)
  81757. {
  81758. unsigned start, end;
  81759. size_t bytes;
  81760. FLAC__byte *target;
  81761. if(br->consumed_words > 0) {
  81762. start = br->consumed_words;
  81763. end = br->words + (br->bytes? 1:0);
  81764. memmove(br->buffer, br->buffer+start, FLAC__BYTES_PER_WORD * (end - start));
  81765. br->words -= start;
  81766. br->consumed_words = 0;
  81767. }
  81768. bytes = (br->capacity - br->words) * FLAC__BYTES_PER_WORD - br->bytes;
  81769. if(bytes == 0)
  81770. return false; /* no space left, buffer is too small; see note for FLAC__BITREADER_DEFAULT_CAPACITY */
  81771. target = ((FLAC__byte*)(br->buffer+br->words)) + br->bytes;
  81772. #if WORDS_BIGENDIAN
  81773. #else
  81774. if(br->bytes)
  81775. br->buffer[br->words] = SWAP_BE_WORD_TO_HOST(br->buffer[br->words]);
  81776. #endif
  81777. if(!br->read_callback(target, &bytes, br->client_data))
  81778. return false;
  81779. #if WORDS_BIGENDIAN
  81780. #else
  81781. end = (br->words*FLAC__BYTES_PER_WORD + br->bytes + bytes + (FLAC__BYTES_PER_WORD-1)) / FLAC__BYTES_PER_WORD;
  81782. # if defined(_MSC_VER) && defined (_X86_) && (FLAC__BYTES_PER_WORD == 4)
  81783. if(br->cpu_info.type == FLAC__CPUINFO_TYPE_IA32 && br->cpu_info.data.ia32.bswap) {
  81784. start = br->words;
  81785. local_swap32_block_(br->buffer + start, end - start);
  81786. }
  81787. else
  81788. # endif
  81789. for(start = br->words; start < end; start++)
  81790. br->buffer[start] = SWAP_BE_WORD_TO_HOST(br->buffer[start]);
  81791. #endif
  81792. end = br->words*FLAC__BYTES_PER_WORD + br->bytes + bytes;
  81793. br->words = end / FLAC__BYTES_PER_WORD;
  81794. br->bytes = end % FLAC__BYTES_PER_WORD;
  81795. return true;
  81796. }
  81797. FLAC__BitReader *FLAC__bitreader_new(void)
  81798. {
  81799. FLAC__BitReader *br = (FLAC__BitReader*)calloc(1, sizeof(FLAC__BitReader));
  81800. return br;
  81801. }
  81802. void FLAC__bitreader_delete(FLAC__BitReader *br)
  81803. {
  81804. FLAC__ASSERT(0 != br);
  81805. FLAC__bitreader_free(br);
  81806. free(br);
  81807. }
  81808. FLAC__bool FLAC__bitreader_init(FLAC__BitReader *br, FLAC__CPUInfo cpu, FLAC__BitReaderReadCallback rcb, void *cd)
  81809. {
  81810. FLAC__ASSERT(0 != br);
  81811. br->words = br->bytes = 0;
  81812. br->consumed_words = br->consumed_bits = 0;
  81813. br->capacity = FLAC__BITREADER_DEFAULT_CAPACITY;
  81814. br->buffer = (brword*)malloc(sizeof(brword) * br->capacity);
  81815. if(br->buffer == 0)
  81816. return false;
  81817. br->read_callback = rcb;
  81818. br->client_data = cd;
  81819. br->cpu_info = cpu;
  81820. return true;
  81821. }
  81822. void FLAC__bitreader_free(FLAC__BitReader *br)
  81823. {
  81824. FLAC__ASSERT(0 != br);
  81825. if(0 != br->buffer)
  81826. free(br->buffer);
  81827. br->buffer = 0;
  81828. br->capacity = 0;
  81829. br->words = br->bytes = 0;
  81830. br->consumed_words = br->consumed_bits = 0;
  81831. br->read_callback = 0;
  81832. br->client_data = 0;
  81833. }
  81834. FLAC__bool FLAC__bitreader_clear(FLAC__BitReader *br)
  81835. {
  81836. br->words = br->bytes = 0;
  81837. br->consumed_words = br->consumed_bits = 0;
  81838. return true;
  81839. }
  81840. void FLAC__bitreader_dump(const FLAC__BitReader *br, FILE *out)
  81841. {
  81842. unsigned i, j;
  81843. if(br == 0) {
  81844. fprintf(out, "bitreader is NULL\n");
  81845. }
  81846. else {
  81847. 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);
  81848. for(i = 0; i < br->words; i++) {
  81849. fprintf(out, "%08X: ", i);
  81850. for(j = 0; j < FLAC__BITS_PER_WORD; j++)
  81851. if(i < br->consumed_words || (i == br->consumed_words && j < br->consumed_bits))
  81852. fprintf(out, ".");
  81853. else
  81854. fprintf(out, "%01u", br->buffer[i] & (1 << (FLAC__BITS_PER_WORD-j-1)) ? 1:0);
  81855. fprintf(out, "\n");
  81856. }
  81857. if(br->bytes > 0) {
  81858. fprintf(out, "%08X: ", i);
  81859. for(j = 0; j < br->bytes*8; j++)
  81860. if(i < br->consumed_words || (i == br->consumed_words && j < br->consumed_bits))
  81861. fprintf(out, ".");
  81862. else
  81863. fprintf(out, "%01u", br->buffer[i] & (1 << (br->bytes*8-j-1)) ? 1:0);
  81864. fprintf(out, "\n");
  81865. }
  81866. }
  81867. }
  81868. void FLAC__bitreader_reset_read_crc16(FLAC__BitReader *br, FLAC__uint16 seed)
  81869. {
  81870. FLAC__ASSERT(0 != br);
  81871. FLAC__ASSERT(0 != br->buffer);
  81872. FLAC__ASSERT((br->consumed_bits & 7) == 0);
  81873. br->read_crc16 = (unsigned)seed;
  81874. br->crc16_align = br->consumed_bits;
  81875. }
  81876. FLAC__uint16 FLAC__bitreader_get_read_crc16(FLAC__BitReader *br)
  81877. {
  81878. FLAC__ASSERT(0 != br);
  81879. FLAC__ASSERT(0 != br->buffer);
  81880. FLAC__ASSERT((br->consumed_bits & 7) == 0);
  81881. FLAC__ASSERT(br->crc16_align <= br->consumed_bits);
  81882. if(br->consumed_bits) {
  81883. const brword tail = br->buffer[br->consumed_words];
  81884. for( ; br->crc16_align < br->consumed_bits; br->crc16_align += 8)
  81885. br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)((tail >> (FLAC__BITS_PER_WORD-8-br->crc16_align)) & 0xff), br->read_crc16);
  81886. }
  81887. return br->read_crc16;
  81888. }
  81889. FLaC__INLINE FLAC__bool FLAC__bitreader_is_consumed_byte_aligned(const FLAC__BitReader *br)
  81890. {
  81891. return ((br->consumed_bits & 7) == 0);
  81892. }
  81893. FLaC__INLINE unsigned FLAC__bitreader_bits_left_for_byte_alignment(const FLAC__BitReader *br)
  81894. {
  81895. return 8 - (br->consumed_bits & 7);
  81896. }
  81897. FLaC__INLINE unsigned FLAC__bitreader_get_input_bits_unconsumed(const FLAC__BitReader *br)
  81898. {
  81899. return (br->words-br->consumed_words)*FLAC__BITS_PER_WORD + br->bytes*8 - br->consumed_bits;
  81900. }
  81901. FLaC__INLINE FLAC__bool FLAC__bitreader_read_raw_uint32(FLAC__BitReader *br, FLAC__uint32 *val, unsigned bits)
  81902. {
  81903. FLAC__ASSERT(0 != br);
  81904. FLAC__ASSERT(0 != br->buffer);
  81905. FLAC__ASSERT(bits <= 32);
  81906. FLAC__ASSERT((br->capacity*FLAC__BITS_PER_WORD) * 2 >= bits);
  81907. FLAC__ASSERT(br->consumed_words <= br->words);
  81908. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  81909. if(bits == 0) { /* OPT: investigate if this can ever happen, maybe change to assertion */
  81910. *val = 0;
  81911. return true;
  81912. }
  81913. while((br->words-br->consumed_words)*FLAC__BITS_PER_WORD + br->bytes*8 - br->consumed_bits < bits) {
  81914. if(!bitreader_read_from_client_(br))
  81915. return false;
  81916. }
  81917. if(br->consumed_words < br->words) { /* if we've not consumed up to a partial tail word... */
  81918. if(br->consumed_bits) {
  81919. const unsigned n = FLAC__BITS_PER_WORD - br->consumed_bits;
  81920. const brword word = br->buffer[br->consumed_words];
  81921. if(bits < n) {
  81922. *val = (word & (FLAC__WORD_ALL_ONES >> br->consumed_bits)) >> (n-bits);
  81923. br->consumed_bits += bits;
  81924. return true;
  81925. }
  81926. *val = word & (FLAC__WORD_ALL_ONES >> br->consumed_bits);
  81927. bits -= n;
  81928. crc16_update_word_(br, word);
  81929. br->consumed_words++;
  81930. br->consumed_bits = 0;
  81931. 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 */
  81932. *val <<= bits;
  81933. *val |= (br->buffer[br->consumed_words] >> (FLAC__BITS_PER_WORD-bits));
  81934. br->consumed_bits = bits;
  81935. }
  81936. return true;
  81937. }
  81938. else {
  81939. const brword word = br->buffer[br->consumed_words];
  81940. if(bits < FLAC__BITS_PER_WORD) {
  81941. *val = word >> (FLAC__BITS_PER_WORD-bits);
  81942. br->consumed_bits = bits;
  81943. return true;
  81944. }
  81945. *val = word;
  81946. crc16_update_word_(br, word);
  81947. br->consumed_words++;
  81948. return true;
  81949. }
  81950. }
  81951. else {
  81952. if(br->consumed_bits) {
  81953. FLAC__ASSERT(br->consumed_bits + bits <= br->bytes*8);
  81954. *val = (br->buffer[br->consumed_words] & (FLAC__WORD_ALL_ONES >> br->consumed_bits)) >> (FLAC__BITS_PER_WORD-br->consumed_bits-bits);
  81955. br->consumed_bits += bits;
  81956. return true;
  81957. }
  81958. else {
  81959. *val = br->buffer[br->consumed_words] >> (FLAC__BITS_PER_WORD-bits);
  81960. br->consumed_bits += bits;
  81961. return true;
  81962. }
  81963. }
  81964. }
  81965. FLAC__bool FLAC__bitreader_read_raw_int32(FLAC__BitReader *br, FLAC__int32 *val, unsigned bits)
  81966. {
  81967. if(!FLAC__bitreader_read_raw_uint32(br, (FLAC__uint32*)val, bits))
  81968. return false;
  81969. *val <<= (32-bits);
  81970. *val >>= (32-bits);
  81971. return true;
  81972. }
  81973. FLAC__bool FLAC__bitreader_read_raw_uint64(FLAC__BitReader *br, FLAC__uint64 *val, unsigned bits)
  81974. {
  81975. FLAC__uint32 hi, lo;
  81976. if(bits > 32) {
  81977. if(!FLAC__bitreader_read_raw_uint32(br, &hi, bits-32))
  81978. return false;
  81979. if(!FLAC__bitreader_read_raw_uint32(br, &lo, 32))
  81980. return false;
  81981. *val = hi;
  81982. *val <<= 32;
  81983. *val |= lo;
  81984. }
  81985. else {
  81986. if(!FLAC__bitreader_read_raw_uint32(br, &lo, bits))
  81987. return false;
  81988. *val = lo;
  81989. }
  81990. return true;
  81991. }
  81992. FLaC__INLINE FLAC__bool FLAC__bitreader_read_uint32_little_endian(FLAC__BitReader *br, FLAC__uint32 *val)
  81993. {
  81994. FLAC__uint32 x8, x32 = 0;
  81995. if(!FLAC__bitreader_read_raw_uint32(br, &x32, 8))
  81996. return false;
  81997. if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8))
  81998. return false;
  81999. x32 |= (x8 << 8);
  82000. if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8))
  82001. return false;
  82002. x32 |= (x8 << 16);
  82003. if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8))
  82004. return false;
  82005. x32 |= (x8 << 24);
  82006. *val = x32;
  82007. return true;
  82008. }
  82009. FLAC__bool FLAC__bitreader_skip_bits_no_crc(FLAC__BitReader *br, unsigned bits)
  82010. {
  82011. FLAC__ASSERT(0 != br);
  82012. FLAC__ASSERT(0 != br->buffer);
  82013. if(bits > 0) {
  82014. const unsigned n = br->consumed_bits & 7;
  82015. unsigned m;
  82016. FLAC__uint32 x;
  82017. if(n != 0) {
  82018. m = min(8-n, bits);
  82019. if(!FLAC__bitreader_read_raw_uint32(br, &x, m))
  82020. return false;
  82021. bits -= m;
  82022. }
  82023. m = bits / 8;
  82024. if(m > 0) {
  82025. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(br, m))
  82026. return false;
  82027. bits %= 8;
  82028. }
  82029. if(bits > 0) {
  82030. if(!FLAC__bitreader_read_raw_uint32(br, &x, bits))
  82031. return false;
  82032. }
  82033. }
  82034. return true;
  82035. }
  82036. FLAC__bool FLAC__bitreader_skip_byte_block_aligned_no_crc(FLAC__BitReader *br, unsigned nvals)
  82037. {
  82038. FLAC__uint32 x;
  82039. FLAC__ASSERT(0 != br);
  82040. FLAC__ASSERT(0 != br->buffer);
  82041. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(br));
  82042. while(nvals && br->consumed_bits) { /* i.e. run until we read 'nvals' bytes or we hit the end of the head word */
  82043. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82044. return false;
  82045. nvals--;
  82046. }
  82047. if(0 == nvals)
  82048. return true;
  82049. while(nvals >= FLAC__BYTES_PER_WORD) {
  82050. if(br->consumed_words < br->words) {
  82051. br->consumed_words++;
  82052. nvals -= FLAC__BYTES_PER_WORD;
  82053. }
  82054. else if(!bitreader_read_from_client_(br))
  82055. return false;
  82056. }
  82057. while(nvals) {
  82058. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82059. return false;
  82060. nvals--;
  82061. }
  82062. return true;
  82063. }
  82064. FLAC__bool FLAC__bitreader_read_byte_block_aligned_no_crc(FLAC__BitReader *br, FLAC__byte *val, unsigned nvals)
  82065. {
  82066. FLAC__uint32 x;
  82067. FLAC__ASSERT(0 != br);
  82068. FLAC__ASSERT(0 != br->buffer);
  82069. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(br));
  82070. while(nvals && br->consumed_bits) { /* i.e. run until we read 'nvals' bytes or we hit the end of the head word */
  82071. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82072. return false;
  82073. *val++ = (FLAC__byte)x;
  82074. nvals--;
  82075. }
  82076. if(0 == nvals)
  82077. return true;
  82078. while(nvals >= FLAC__BYTES_PER_WORD) {
  82079. if(br->consumed_words < br->words) {
  82080. const brword word = br->buffer[br->consumed_words++];
  82081. #if FLAC__BYTES_PER_WORD == 4
  82082. val[0] = (FLAC__byte)(word >> 24);
  82083. val[1] = (FLAC__byte)(word >> 16);
  82084. val[2] = (FLAC__byte)(word >> 8);
  82085. val[3] = (FLAC__byte)word;
  82086. #elif FLAC__BYTES_PER_WORD == 8
  82087. val[0] = (FLAC__byte)(word >> 56);
  82088. val[1] = (FLAC__byte)(word >> 48);
  82089. val[2] = (FLAC__byte)(word >> 40);
  82090. val[3] = (FLAC__byte)(word >> 32);
  82091. val[4] = (FLAC__byte)(word >> 24);
  82092. val[5] = (FLAC__byte)(word >> 16);
  82093. val[6] = (FLAC__byte)(word >> 8);
  82094. val[7] = (FLAC__byte)word;
  82095. #else
  82096. for(x = 0; x < FLAC__BYTES_PER_WORD; x++)
  82097. val[x] = (FLAC__byte)(word >> (8*(FLAC__BYTES_PER_WORD-x-1)));
  82098. #endif
  82099. val += FLAC__BYTES_PER_WORD;
  82100. nvals -= FLAC__BYTES_PER_WORD;
  82101. }
  82102. else if(!bitreader_read_from_client_(br))
  82103. return false;
  82104. }
  82105. while(nvals) {
  82106. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82107. return false;
  82108. *val++ = (FLAC__byte)x;
  82109. nvals--;
  82110. }
  82111. return true;
  82112. }
  82113. FLaC__INLINE FLAC__bool FLAC__bitreader_read_unary_unsigned(FLAC__BitReader *br, unsigned *val)
  82114. #if 0 /* slow but readable version */
  82115. {
  82116. unsigned bit;
  82117. FLAC__ASSERT(0 != br);
  82118. FLAC__ASSERT(0 != br->buffer);
  82119. *val = 0;
  82120. while(1) {
  82121. if(!FLAC__bitreader_read_bit(br, &bit))
  82122. return false;
  82123. if(bit)
  82124. break;
  82125. else
  82126. *val++;
  82127. }
  82128. return true;
  82129. }
  82130. #else
  82131. {
  82132. unsigned i;
  82133. FLAC__ASSERT(0 != br);
  82134. FLAC__ASSERT(0 != br->buffer);
  82135. *val = 0;
  82136. while(1) {
  82137. while(br->consumed_words < br->words) { /* if we've not consumed up to a partial tail word... */
  82138. brword b = br->buffer[br->consumed_words] << br->consumed_bits;
  82139. if(b) {
  82140. i = COUNT_ZERO_MSBS(b);
  82141. *val += i;
  82142. i++;
  82143. br->consumed_bits += i;
  82144. if(br->consumed_bits >= FLAC__BITS_PER_WORD) { /* faster way of testing if(br->consumed_bits == FLAC__BITS_PER_WORD) */
  82145. crc16_update_word_(br, br->buffer[br->consumed_words]);
  82146. br->consumed_words++;
  82147. br->consumed_bits = 0;
  82148. }
  82149. return true;
  82150. }
  82151. else {
  82152. *val += FLAC__BITS_PER_WORD - br->consumed_bits;
  82153. crc16_update_word_(br, br->buffer[br->consumed_words]);
  82154. br->consumed_words++;
  82155. br->consumed_bits = 0;
  82156. }
  82157. }
  82158. if(br->bytes) {
  82159. const unsigned end = br->bytes * 8;
  82160. brword b = (br->buffer[br->consumed_words] & (FLAC__WORD_ALL_ONES << (FLAC__BITS_PER_WORD-end))) << br->consumed_bits;
  82161. if(b) {
  82162. i = COUNT_ZERO_MSBS(b);
  82163. *val += i;
  82164. i++;
  82165. br->consumed_bits += i;
  82166. FLAC__ASSERT(br->consumed_bits < FLAC__BITS_PER_WORD);
  82167. return true;
  82168. }
  82169. else {
  82170. *val += end - br->consumed_bits;
  82171. br->consumed_bits += end;
  82172. FLAC__ASSERT(br->consumed_bits < FLAC__BITS_PER_WORD);
  82173. }
  82174. }
  82175. if(!bitreader_read_from_client_(br))
  82176. return false;
  82177. }
  82178. }
  82179. #endif
  82180. FLAC__bool FLAC__bitreader_read_rice_signed(FLAC__BitReader *br, int *val, unsigned parameter)
  82181. {
  82182. FLAC__uint32 lsbs = 0, msbs = 0;
  82183. unsigned uval;
  82184. FLAC__ASSERT(0 != br);
  82185. FLAC__ASSERT(0 != br->buffer);
  82186. FLAC__ASSERT(parameter <= 31);
  82187. if(!FLAC__bitreader_read_unary_unsigned(br, (unsigned int*) &msbs))
  82188. return false;
  82189. if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, parameter))
  82190. return false;
  82191. uval = (msbs << parameter) | lsbs;
  82192. if(uval & 1)
  82193. *val = -((int)(uval >> 1)) - 1;
  82194. else
  82195. *val = (int)(uval >> 1);
  82196. return true;
  82197. }
  82198. FLAC__bool FLAC__bitreader_read_rice_signed_block(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter)
  82199. #ifdef _MSC_VER
  82200. {
  82201. unsigned i;
  82202. unsigned uval = 0;
  82203. unsigned bits; /* the # of binary LSBs left to read to finish a rice codeword */
  82204. register unsigned cwords;
  82205. register unsigned cbits;
  82206. FLAC__ASSERT(0 != br);
  82207. FLAC__ASSERT(0 != br->buffer);
  82208. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  82209. FLAC__ASSERT(parameter < 32);
  82210. if(nvals == 0)
  82211. return true;
  82212. cbits = br->consumed_bits;
  82213. cwords = br->consumed_words;
  82214. while(1) {
  82215. while(1) {
  82216. while(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82217. brword b = br->buffer[cwords] << cbits;
  82218. if(b) {
  82219. #if 0 /* slower, probably due to bad register allocation... */ && defined FLAC__CPU_IA32 && !defined FLAC__NO_ASM && FLAC__BITS_PER_WORD == 32
  82220. __asm {
  82221. bsr eax, b
  82222. not eax
  82223. and eax, 31
  82224. mov i, eax
  82225. }
  82226. #else
  82227. i = COUNT_ZERO_MSBS(b);
  82228. #endif
  82229. uval += i;
  82230. bits = parameter;
  82231. i++;
  82232. cbits += i;
  82233. if(cbits == FLAC__BITS_PER_WORD) {
  82234. crc16_update_word_(br, br->buffer[cwords]);
  82235. cwords++;
  82236. cbits = 0;
  82237. }
  82238. goto break1;
  82239. }
  82240. else {
  82241. uval += FLAC__BITS_PER_WORD - cbits;
  82242. crc16_update_word_(br, br->buffer[cwords]);
  82243. cwords++;
  82244. cbits = 0;
  82245. }
  82246. }
  82247. if(br->bytes) {
  82248. const unsigned end = br->bytes * 8;
  82249. brword b = (br->buffer[cwords] & (FLAC__WORD_ALL_ONES << (FLAC__BITS_PER_WORD-end))) << cbits;
  82250. if(b) {
  82251. i = COUNT_ZERO_MSBS(b);
  82252. uval += i;
  82253. bits = parameter;
  82254. i++;
  82255. cbits += i;
  82256. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82257. goto break1;
  82258. }
  82259. else {
  82260. uval += end - cbits;
  82261. cbits += end;
  82262. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82263. }
  82264. }
  82265. br->consumed_bits = cbits;
  82266. br->consumed_words = cwords;
  82267. if(!bitreader_read_from_client_(br))
  82268. return false;
  82269. cwords = br->consumed_words;
  82270. }
  82271. break1:
  82272. FLAC__ASSERT(cwords <= br->words);
  82273. if(bits) {
  82274. while((br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits < bits) {
  82275. br->consumed_bits = cbits;
  82276. br->consumed_words = cwords;
  82277. if(!bitreader_read_from_client_(br))
  82278. return false;
  82279. cwords = br->consumed_words;
  82280. }
  82281. if(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82282. if(cbits) {
  82283. const unsigned n = FLAC__BITS_PER_WORD - cbits;
  82284. const brword word = br->buffer[cwords];
  82285. if(bits < n) {
  82286. uval <<= bits;
  82287. uval |= (word & (FLAC__WORD_ALL_ONES >> cbits)) >> (n-bits);
  82288. cbits += bits;
  82289. goto break2;
  82290. }
  82291. uval <<= n;
  82292. uval |= word & (FLAC__WORD_ALL_ONES >> cbits);
  82293. bits -= n;
  82294. crc16_update_word_(br, word);
  82295. cwords++;
  82296. cbits = 0;
  82297. 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 */
  82298. uval <<= bits;
  82299. uval |= (br->buffer[cwords] >> (FLAC__BITS_PER_WORD-bits));
  82300. cbits = bits;
  82301. }
  82302. goto break2;
  82303. }
  82304. else {
  82305. FLAC__ASSERT(bits < FLAC__BITS_PER_WORD);
  82306. uval <<= bits;
  82307. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-bits);
  82308. cbits = bits;
  82309. goto break2;
  82310. }
  82311. }
  82312. else {
  82313. uval <<= bits;
  82314. if(cbits) {
  82315. FLAC__ASSERT(cbits + bits <= br->bytes*8);
  82316. uval |= (br->buffer[cwords] & (FLAC__WORD_ALL_ONES >> cbits)) >> (FLAC__BITS_PER_WORD-cbits-bits);
  82317. cbits += bits;
  82318. goto break2;
  82319. }
  82320. else {
  82321. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-bits);
  82322. cbits += bits;
  82323. goto break2;
  82324. }
  82325. }
  82326. }
  82327. break2:
  82328. *vals = (int)(uval >> 1 ^ -(int)(uval & 1));
  82329. --nvals;
  82330. if(nvals == 0) {
  82331. br->consumed_bits = cbits;
  82332. br->consumed_words = cwords;
  82333. return true;
  82334. }
  82335. uval = 0;
  82336. ++vals;
  82337. }
  82338. }
  82339. #else
  82340. {
  82341. unsigned i;
  82342. unsigned uval = 0;
  82343. register unsigned cwords;
  82344. register unsigned cbits;
  82345. unsigned ucbits; /* keep track of the number of unconsumed bits in the buffer */
  82346. FLAC__ASSERT(0 != br);
  82347. FLAC__ASSERT(0 != br->buffer);
  82348. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  82349. FLAC__ASSERT(parameter < 32);
  82350. if(nvals == 0)
  82351. return true;
  82352. cbits = br->consumed_bits;
  82353. cwords = br->consumed_words;
  82354. ucbits = (br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits;
  82355. while(1) {
  82356. while(1) {
  82357. while(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82358. brword b = br->buffer[cwords] << cbits;
  82359. if(b) {
  82360. #if 0 /* is not discernably faster... */ && defined FLAC__CPU_IA32 && !defined FLAC__NO_ASM && FLAC__BITS_PER_WORD == 32 && defined __GNUC__
  82361. asm volatile (
  82362. "bsrl %1, %0;"
  82363. "notl %0;"
  82364. "andl $31, %0;"
  82365. : "=r"(i)
  82366. : "r"(b)
  82367. );
  82368. #else
  82369. i = COUNT_ZERO_MSBS(b);
  82370. #endif
  82371. uval += i;
  82372. cbits += i;
  82373. cbits++; /* skip over stop bit */
  82374. if(cbits >= FLAC__BITS_PER_WORD) { /* faster way of testing if(cbits == FLAC__BITS_PER_WORD) */
  82375. crc16_update_word_(br, br->buffer[cwords]);
  82376. cwords++;
  82377. cbits = 0;
  82378. }
  82379. goto break1;
  82380. }
  82381. else {
  82382. uval += FLAC__BITS_PER_WORD - cbits;
  82383. crc16_update_word_(br, br->buffer[cwords]);
  82384. cwords++;
  82385. cbits = 0;
  82386. }
  82387. }
  82388. if(br->bytes) {
  82389. const unsigned end = br->bytes * 8;
  82390. brword b = (br->buffer[cwords] & ~(FLAC__WORD_ALL_ONES >> end)) << cbits;
  82391. if(b) {
  82392. i = COUNT_ZERO_MSBS(b);
  82393. uval += i;
  82394. cbits += i;
  82395. cbits++; /* skip over stop bit */
  82396. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82397. goto break1;
  82398. }
  82399. else {
  82400. uval += end - cbits;
  82401. cbits += end;
  82402. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82403. }
  82404. }
  82405. br->consumed_bits = cbits;
  82406. br->consumed_words = cwords;
  82407. if(!bitreader_read_from_client_(br))
  82408. return false;
  82409. cwords = br->consumed_words;
  82410. ucbits = (br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits + uval;
  82411. }
  82412. break1:
  82413. ucbits -= uval;
  82414. ucbits--; /* account for stop bit */
  82415. FLAC__ASSERT(cwords <= br->words);
  82416. if(parameter) {
  82417. while(ucbits < parameter) {
  82418. br->consumed_bits = cbits;
  82419. br->consumed_words = cwords;
  82420. if(!bitreader_read_from_client_(br))
  82421. return false;
  82422. cwords = br->consumed_words;
  82423. ucbits = (br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits;
  82424. }
  82425. if(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82426. if(cbits) {
  82427. const unsigned n = FLAC__BITS_PER_WORD - cbits;
  82428. const brword word = br->buffer[cwords];
  82429. if(parameter < n) {
  82430. uval <<= parameter;
  82431. uval |= (word & (FLAC__WORD_ALL_ONES >> cbits)) >> (n-parameter);
  82432. cbits += parameter;
  82433. }
  82434. else {
  82435. uval <<= n;
  82436. uval |= word & (FLAC__WORD_ALL_ONES >> cbits);
  82437. crc16_update_word_(br, word);
  82438. cwords++;
  82439. cbits = parameter - n;
  82440. 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 */
  82441. uval <<= cbits;
  82442. uval |= (br->buffer[cwords] >> (FLAC__BITS_PER_WORD-cbits));
  82443. }
  82444. }
  82445. }
  82446. else {
  82447. cbits = parameter;
  82448. uval <<= parameter;
  82449. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-cbits);
  82450. }
  82451. }
  82452. else {
  82453. uval <<= parameter;
  82454. if(cbits) {
  82455. FLAC__ASSERT(cbits + parameter <= br->bytes*8);
  82456. uval |= (br->buffer[cwords] & (FLAC__WORD_ALL_ONES >> cbits)) >> (FLAC__BITS_PER_WORD-cbits-parameter);
  82457. cbits += parameter;
  82458. }
  82459. else {
  82460. cbits = parameter;
  82461. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-cbits);
  82462. }
  82463. }
  82464. }
  82465. ucbits -= parameter;
  82466. *vals = (int)(uval >> 1 ^ -(int)(uval & 1));
  82467. --nvals;
  82468. if(nvals == 0) {
  82469. br->consumed_bits = cbits;
  82470. br->consumed_words = cwords;
  82471. return true;
  82472. }
  82473. uval = 0;
  82474. ++vals;
  82475. }
  82476. }
  82477. #endif
  82478. #if 0 /* UNUSED */
  82479. FLAC__bool FLAC__bitreader_read_golomb_signed(FLAC__BitReader *br, int *val, unsigned parameter)
  82480. {
  82481. FLAC__uint32 lsbs = 0, msbs = 0;
  82482. unsigned bit, uval, k;
  82483. FLAC__ASSERT(0 != br);
  82484. FLAC__ASSERT(0 != br->buffer);
  82485. k = FLAC__bitmath_ilog2(parameter);
  82486. if(!FLAC__bitreader_read_unary_unsigned(br, &msbs))
  82487. return false;
  82488. if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, k))
  82489. return false;
  82490. if(parameter == 1u<<k) {
  82491. uval = (msbs << k) | lsbs;
  82492. }
  82493. else {
  82494. unsigned d = (1 << (k+1)) - parameter;
  82495. if(lsbs >= d) {
  82496. if(!FLAC__bitreader_read_bit(br, &bit))
  82497. return false;
  82498. lsbs <<= 1;
  82499. lsbs |= bit;
  82500. lsbs -= d;
  82501. }
  82502. uval = msbs * parameter + lsbs;
  82503. }
  82504. if(uval & 1)
  82505. *val = -((int)(uval >> 1)) - 1;
  82506. else
  82507. *val = (int)(uval >> 1);
  82508. return true;
  82509. }
  82510. FLAC__bool FLAC__bitreader_read_golomb_unsigned(FLAC__BitReader *br, unsigned *val, unsigned parameter)
  82511. {
  82512. FLAC__uint32 lsbs, msbs = 0;
  82513. unsigned bit, k;
  82514. FLAC__ASSERT(0 != br);
  82515. FLAC__ASSERT(0 != br->buffer);
  82516. k = FLAC__bitmath_ilog2(parameter);
  82517. if(!FLAC__bitreader_read_unary_unsigned(br, &msbs))
  82518. return false;
  82519. if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, k))
  82520. return false;
  82521. if(parameter == 1u<<k) {
  82522. *val = (msbs << k) | lsbs;
  82523. }
  82524. else {
  82525. unsigned d = (1 << (k+1)) - parameter;
  82526. if(lsbs >= d) {
  82527. if(!FLAC__bitreader_read_bit(br, &bit))
  82528. return false;
  82529. lsbs <<= 1;
  82530. lsbs |= bit;
  82531. lsbs -= d;
  82532. }
  82533. *val = msbs * parameter + lsbs;
  82534. }
  82535. return true;
  82536. }
  82537. #endif /* UNUSED */
  82538. FLAC__bool FLAC__bitreader_read_utf8_uint32(FLAC__BitReader *br, FLAC__uint32 *val, FLAC__byte *raw, unsigned *rawlen)
  82539. {
  82540. FLAC__uint32 v = 0;
  82541. FLAC__uint32 x;
  82542. unsigned i;
  82543. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82544. return false;
  82545. if(raw)
  82546. raw[(*rawlen)++] = (FLAC__byte)x;
  82547. if(!(x & 0x80)) { /* 0xxxxxxx */
  82548. v = x;
  82549. i = 0;
  82550. }
  82551. else if(x & 0xC0 && !(x & 0x20)) { /* 110xxxxx */
  82552. v = x & 0x1F;
  82553. i = 1;
  82554. }
  82555. else if(x & 0xE0 && !(x & 0x10)) { /* 1110xxxx */
  82556. v = x & 0x0F;
  82557. i = 2;
  82558. }
  82559. else if(x & 0xF0 && !(x & 0x08)) { /* 11110xxx */
  82560. v = x & 0x07;
  82561. i = 3;
  82562. }
  82563. else if(x & 0xF8 && !(x & 0x04)) { /* 111110xx */
  82564. v = x & 0x03;
  82565. i = 4;
  82566. }
  82567. else if(x & 0xFC && !(x & 0x02)) { /* 1111110x */
  82568. v = x & 0x01;
  82569. i = 5;
  82570. }
  82571. else {
  82572. *val = 0xffffffff;
  82573. return true;
  82574. }
  82575. for( ; i; i--) {
  82576. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82577. return false;
  82578. if(raw)
  82579. raw[(*rawlen)++] = (FLAC__byte)x;
  82580. if(!(x & 0x80) || (x & 0x40)) { /* 10xxxxxx */
  82581. *val = 0xffffffff;
  82582. return true;
  82583. }
  82584. v <<= 6;
  82585. v |= (x & 0x3F);
  82586. }
  82587. *val = v;
  82588. return true;
  82589. }
  82590. FLAC__bool FLAC__bitreader_read_utf8_uint64(FLAC__BitReader *br, FLAC__uint64 *val, FLAC__byte *raw, unsigned *rawlen)
  82591. {
  82592. FLAC__uint64 v = 0;
  82593. FLAC__uint32 x;
  82594. unsigned i;
  82595. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82596. return false;
  82597. if(raw)
  82598. raw[(*rawlen)++] = (FLAC__byte)x;
  82599. if(!(x & 0x80)) { /* 0xxxxxxx */
  82600. v = x;
  82601. i = 0;
  82602. }
  82603. else if(x & 0xC0 && !(x & 0x20)) { /* 110xxxxx */
  82604. v = x & 0x1F;
  82605. i = 1;
  82606. }
  82607. else if(x & 0xE0 && !(x & 0x10)) { /* 1110xxxx */
  82608. v = x & 0x0F;
  82609. i = 2;
  82610. }
  82611. else if(x & 0xF0 && !(x & 0x08)) { /* 11110xxx */
  82612. v = x & 0x07;
  82613. i = 3;
  82614. }
  82615. else if(x & 0xF8 && !(x & 0x04)) { /* 111110xx */
  82616. v = x & 0x03;
  82617. i = 4;
  82618. }
  82619. else if(x & 0xFC && !(x & 0x02)) { /* 1111110x */
  82620. v = x & 0x01;
  82621. i = 5;
  82622. }
  82623. else if(x & 0xFE && !(x & 0x01)) { /* 11111110 */
  82624. v = 0;
  82625. i = 6;
  82626. }
  82627. else {
  82628. *val = FLAC__U64L(0xffffffffffffffff);
  82629. return true;
  82630. }
  82631. for( ; i; i--) {
  82632. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82633. return false;
  82634. if(raw)
  82635. raw[(*rawlen)++] = (FLAC__byte)x;
  82636. if(!(x & 0x80) || (x & 0x40)) { /* 10xxxxxx */
  82637. *val = FLAC__U64L(0xffffffffffffffff);
  82638. return true;
  82639. }
  82640. v <<= 6;
  82641. v |= (x & 0x3F);
  82642. }
  82643. *val = v;
  82644. return true;
  82645. }
  82646. #endif
  82647. /*** End of inlined file: bitreader.c ***/
  82648. /*** Start of inlined file: bitwriter.c ***/
  82649. /*** Start of inlined file: juce_FlacHeader.h ***/
  82650. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  82651. // tasks..
  82652. #define VERSION "1.2.1"
  82653. #define FLAC__NO_DLL 1
  82654. #if JUCE_MSVC
  82655. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  82656. #endif
  82657. #if JUCE_MAC
  82658. #define FLAC__SYS_DARWIN 1
  82659. #endif
  82660. /*** End of inlined file: juce_FlacHeader.h ***/
  82661. #if JUCE_USE_FLAC
  82662. #if HAVE_CONFIG_H
  82663. # include <config.h>
  82664. #endif
  82665. #include <stdlib.h> /* for malloc() */
  82666. #include <string.h> /* for memcpy(), memset() */
  82667. #ifdef _MSC_VER
  82668. #include <winsock.h> /* for ntohl() */
  82669. #elif defined FLAC__SYS_DARWIN
  82670. #include <machine/endian.h> /* for ntohl() */
  82671. #elif defined __MINGW32__
  82672. #include <winsock.h> /* for ntohl() */
  82673. #else
  82674. #include <netinet/in.h> /* for ntohl() */
  82675. #endif
  82676. #if 0 /* UNUSED */
  82677. #endif
  82678. /*** Start of inlined file: bitwriter.h ***/
  82679. #ifndef FLAC__PRIVATE__BITWRITER_H
  82680. #define FLAC__PRIVATE__BITWRITER_H
  82681. #include <stdio.h> /* for FILE */
  82682. struct FLAC__BitWriter;
  82683. typedef struct FLAC__BitWriter FLAC__BitWriter;
  82684. FLAC__BitWriter *FLAC__bitwriter_new(void);
  82685. void FLAC__bitwriter_delete(FLAC__BitWriter *bw);
  82686. FLAC__bool FLAC__bitwriter_init(FLAC__BitWriter *bw);
  82687. void FLAC__bitwriter_free(FLAC__BitWriter *bw); /* does not 'free(buffer)' */
  82688. void FLAC__bitwriter_clear(FLAC__BitWriter *bw);
  82689. void FLAC__bitwriter_dump(const FLAC__BitWriter *bw, FILE *out);
  82690. FLAC__bool FLAC__bitwriter_get_write_crc16(FLAC__BitWriter *bw, FLAC__uint16 *crc);
  82691. FLAC__bool FLAC__bitwriter_get_write_crc8(FLAC__BitWriter *bw, FLAC__byte *crc);
  82692. FLAC__bool FLAC__bitwriter_is_byte_aligned(const FLAC__BitWriter *bw);
  82693. unsigned FLAC__bitwriter_get_input_bits_unconsumed(const FLAC__BitWriter *bw); /* can be called anytime, returns total # of bits unconsumed */
  82694. FLAC__bool FLAC__bitwriter_get_buffer(FLAC__BitWriter *bw, const FLAC__byte **buffer, size_t *bytes);
  82695. void FLAC__bitwriter_release_buffer(FLAC__BitWriter *bw);
  82696. FLAC__bool FLAC__bitwriter_write_zeroes(FLAC__BitWriter *bw, unsigned bits);
  82697. FLAC__bool FLAC__bitwriter_write_raw_uint32(FLAC__BitWriter *bw, FLAC__uint32 val, unsigned bits);
  82698. FLAC__bool FLAC__bitwriter_write_raw_int32(FLAC__BitWriter *bw, FLAC__int32 val, unsigned bits);
  82699. FLAC__bool FLAC__bitwriter_write_raw_uint64(FLAC__BitWriter *bw, FLAC__uint64 val, unsigned bits);
  82700. FLAC__bool FLAC__bitwriter_write_raw_uint32_little_endian(FLAC__BitWriter *bw, FLAC__uint32 val); /*only for bits=32*/
  82701. FLAC__bool FLAC__bitwriter_write_byte_block(FLAC__BitWriter *bw, const FLAC__byte vals[], unsigned nvals);
  82702. FLAC__bool FLAC__bitwriter_write_unary_unsigned(FLAC__BitWriter *bw, unsigned val);
  82703. unsigned FLAC__bitwriter_rice_bits(FLAC__int32 val, unsigned parameter);
  82704. #if 0 /* UNUSED */
  82705. unsigned FLAC__bitwriter_golomb_bits_signed(int val, unsigned parameter);
  82706. unsigned FLAC__bitwriter_golomb_bits_unsigned(unsigned val, unsigned parameter);
  82707. #endif
  82708. FLAC__bool FLAC__bitwriter_write_rice_signed(FLAC__BitWriter *bw, FLAC__int32 val, unsigned parameter);
  82709. FLAC__bool FLAC__bitwriter_write_rice_signed_block(FLAC__BitWriter *bw, const FLAC__int32 *vals, unsigned nvals, unsigned parameter);
  82710. #if 0 /* UNUSED */
  82711. FLAC__bool FLAC__bitwriter_write_golomb_signed(FLAC__BitWriter *bw, int val, unsigned parameter);
  82712. FLAC__bool FLAC__bitwriter_write_golomb_unsigned(FLAC__BitWriter *bw, unsigned val, unsigned parameter);
  82713. #endif
  82714. FLAC__bool FLAC__bitwriter_write_utf8_uint32(FLAC__BitWriter *bw, FLAC__uint32 val);
  82715. FLAC__bool FLAC__bitwriter_write_utf8_uint64(FLAC__BitWriter *bw, FLAC__uint64 val);
  82716. FLAC__bool FLAC__bitwriter_zero_pad_to_byte_boundary(FLAC__BitWriter *bw);
  82717. #endif
  82718. /*** End of inlined file: bitwriter.h ***/
  82719. /*** Start of inlined file: alloc.h ***/
  82720. #ifndef FLAC__SHARE__ALLOC_H
  82721. #define FLAC__SHARE__ALLOC_H
  82722. #if HAVE_CONFIG_H
  82723. # include <config.h>
  82724. #endif
  82725. #include <limits.h> /* for SIZE_MAX */
  82726. #if !defined _MSC_VER && !defined __MINGW32__ && !defined __EMX__
  82727. #include <stdint.h> /* for SIZE_MAX in case limits.h didn't get it */
  82728. #endif
  82729. #include <stdlib.h> /* for size_t, malloc(), etc */
  82730. #ifndef SIZE_MAX
  82731. # ifndef SIZE_T_MAX
  82732. # ifdef _MSC_VER
  82733. # define SIZE_T_MAX UINT_MAX
  82734. # else
  82735. # error
  82736. # endif
  82737. # endif
  82738. # define SIZE_MAX SIZE_T_MAX
  82739. #endif
  82740. #ifndef FLaC__INLINE
  82741. #define FLaC__INLINE
  82742. #endif
  82743. static FLaC__INLINE void *safe_malloc_(size_t size)
  82744. {
  82745. if(!size)
  82746. size++;
  82747. return malloc(size);
  82748. }
  82749. static FLaC__INLINE void *safe_calloc_(size_t nmemb, size_t size)
  82750. {
  82751. if(!nmemb || !size)
  82752. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  82753. return calloc(nmemb, size);
  82754. }
  82755. static FLaC__INLINE void *safe_malloc_add_2op_(size_t size1, size_t size2)
  82756. {
  82757. size2 += size1;
  82758. if(size2 < size1)
  82759. return 0;
  82760. return safe_malloc_(size2);
  82761. }
  82762. static FLaC__INLINE void *safe_malloc_add_3op_(size_t size1, size_t size2, size_t size3)
  82763. {
  82764. size2 += size1;
  82765. if(size2 < size1)
  82766. return 0;
  82767. size3 += size2;
  82768. if(size3 < size2)
  82769. return 0;
  82770. return safe_malloc_(size3);
  82771. }
  82772. static FLaC__INLINE void *safe_malloc_add_4op_(size_t size1, size_t size2, size_t size3, size_t size4)
  82773. {
  82774. size2 += size1;
  82775. if(size2 < size1)
  82776. return 0;
  82777. size3 += size2;
  82778. if(size3 < size2)
  82779. return 0;
  82780. size4 += size3;
  82781. if(size4 < size3)
  82782. return 0;
  82783. return safe_malloc_(size4);
  82784. }
  82785. static FLaC__INLINE void *safe_malloc_mul_2op_(size_t size1, size_t size2)
  82786. #if 0
  82787. needs support for cases where sizeof(size_t) != 4
  82788. {
  82789. if(sizeof(size_t) == 4) {
  82790. if ((double)size1 * (double)size2 < 4294967296.0)
  82791. return malloc(size1*size2);
  82792. }
  82793. return 0;
  82794. }
  82795. #else
  82796. {
  82797. if(!size1 || !size2)
  82798. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  82799. if(size1 > SIZE_MAX / size2)
  82800. return 0;
  82801. return malloc(size1*size2);
  82802. }
  82803. #endif
  82804. static FLaC__INLINE void *safe_malloc_mul_3op_(size_t size1, size_t size2, size_t size3)
  82805. {
  82806. if(!size1 || !size2 || !size3)
  82807. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  82808. if(size1 > SIZE_MAX / size2)
  82809. return 0;
  82810. size1 *= size2;
  82811. if(size1 > SIZE_MAX / size3)
  82812. return 0;
  82813. return malloc(size1*size3);
  82814. }
  82815. static FLaC__INLINE void *safe_malloc_mul2add_(size_t size1, size_t size2, size_t size3)
  82816. {
  82817. if(!size1 || !size2)
  82818. return safe_malloc_(size3);
  82819. if(size1 > SIZE_MAX / size2)
  82820. return 0;
  82821. return safe_malloc_add_2op_(size1*size2, size3);
  82822. }
  82823. static FLaC__INLINE void *safe_malloc_muladd2_(size_t size1, size_t size2, size_t size3)
  82824. {
  82825. if(!size1 || (!size2 && !size3))
  82826. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  82827. size2 += size3;
  82828. if(size2 < size3)
  82829. return 0;
  82830. return safe_malloc_mul_2op_(size1, size2);
  82831. }
  82832. static FLaC__INLINE void *safe_realloc_add_2op_(void *ptr, size_t size1, size_t size2)
  82833. {
  82834. size2 += size1;
  82835. if(size2 < size1)
  82836. return 0;
  82837. return realloc(ptr, size2);
  82838. }
  82839. static FLaC__INLINE void *safe_realloc_add_3op_(void *ptr, size_t size1, size_t size2, size_t size3)
  82840. {
  82841. size2 += size1;
  82842. if(size2 < size1)
  82843. return 0;
  82844. size3 += size2;
  82845. if(size3 < size2)
  82846. return 0;
  82847. return realloc(ptr, size3);
  82848. }
  82849. static FLaC__INLINE void *safe_realloc_add_4op_(void *ptr, size_t size1, size_t size2, size_t size3, size_t size4)
  82850. {
  82851. size2 += size1;
  82852. if(size2 < size1)
  82853. return 0;
  82854. size3 += size2;
  82855. if(size3 < size2)
  82856. return 0;
  82857. size4 += size3;
  82858. if(size4 < size3)
  82859. return 0;
  82860. return realloc(ptr, size4);
  82861. }
  82862. static FLaC__INLINE void *safe_realloc_mul_2op_(void *ptr, size_t size1, size_t size2)
  82863. {
  82864. if(!size1 || !size2)
  82865. return realloc(ptr, 0); /* preserve POSIX realloc(ptr, 0) semantics */
  82866. if(size1 > SIZE_MAX / size2)
  82867. return 0;
  82868. return realloc(ptr, size1*size2);
  82869. }
  82870. static FLaC__INLINE void *safe_realloc_muladd2_(void *ptr, size_t size1, size_t size2, size_t size3)
  82871. {
  82872. if(!size1 || (!size2 && !size3))
  82873. return realloc(ptr, 0); /* preserve POSIX realloc(ptr, 0) semantics */
  82874. size2 += size3;
  82875. if(size2 < size3)
  82876. return 0;
  82877. return safe_realloc_mul_2op_(ptr, size1, size2);
  82878. }
  82879. #endif
  82880. /*** End of inlined file: alloc.h ***/
  82881. typedef FLAC__uint32 bwword;
  82882. #define FLAC__BYTES_PER_WORD 4
  82883. #define FLAC__BITS_PER_WORD 32
  82884. #define FLAC__WORD_ALL_ONES ((FLAC__uint32)0xffffffff)
  82885. #if WORDS_BIGENDIAN
  82886. #define SWAP_BE_WORD_TO_HOST(x) (x)
  82887. #else
  82888. #ifdef _MSC_VER
  82889. #define SWAP_BE_WORD_TO_HOST(x) local_swap32_(x)
  82890. #else
  82891. #define SWAP_BE_WORD_TO_HOST(x) ntohl(x)
  82892. #endif
  82893. #endif
  82894. static const unsigned FLAC__BITWRITER_DEFAULT_CAPACITY = 32768u / sizeof(bwword); /* size in words */
  82895. static const unsigned FLAC__BITWRITER_DEFAULT_INCREMENT = 4096u / sizeof(bwword); /* size in words */
  82896. #define FLAC__WORDS_TO_BITS(words) ((words) * FLAC__BITS_PER_WORD)
  82897. #define FLAC__TOTAL_BITS(bw) (FLAC__WORDS_TO_BITS((bw)->words) + (bw)->bits)
  82898. #ifdef min
  82899. #undef min
  82900. #endif
  82901. #define min(x,y) ((x)<(y)?(x):(y))
  82902. #ifdef _MSC_VER
  82903. #define FLAC__U64L(x) x
  82904. #else
  82905. #define FLAC__U64L(x) x##LLU
  82906. #endif
  82907. #ifndef FLaC__INLINE
  82908. #define FLaC__INLINE
  82909. #endif
  82910. struct FLAC__BitWriter {
  82911. bwword *buffer;
  82912. bwword accum; /* accumulator; bits are right-justified; when full, accum is appended to buffer */
  82913. unsigned capacity; /* capacity of buffer in words */
  82914. unsigned words; /* # of complete words in buffer */
  82915. unsigned bits; /* # of used bits in accum */
  82916. };
  82917. static FLAC__bool bitwriter_grow_(FLAC__BitWriter *bw, unsigned bits_to_add)
  82918. {
  82919. unsigned new_capacity;
  82920. bwword *new_buffer;
  82921. FLAC__ASSERT(0 != bw);
  82922. FLAC__ASSERT(0 != bw->buffer);
  82923. new_capacity = bw->words + ((bw->bits + bits_to_add + FLAC__BITS_PER_WORD - 1) / FLAC__BITS_PER_WORD);
  82924. if(bw->capacity >= new_capacity)
  82925. return true;
  82926. if((new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT)
  82927. new_capacity += FLAC__BITWRITER_DEFAULT_INCREMENT - ((new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT);
  82928. FLAC__ASSERT(0 == (new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT);
  82929. FLAC__ASSERT(new_capacity > bw->capacity);
  82930. FLAC__ASSERT(new_capacity >= bw->words + ((bw->bits + bits_to_add + FLAC__BITS_PER_WORD - 1) / FLAC__BITS_PER_WORD));
  82931. new_buffer = (bwword*)safe_realloc_mul_2op_(bw->buffer, sizeof(bwword), /*times*/new_capacity);
  82932. if(new_buffer == 0)
  82933. return false;
  82934. bw->buffer = new_buffer;
  82935. bw->capacity = new_capacity;
  82936. return true;
  82937. }
  82938. FLAC__BitWriter *FLAC__bitwriter_new(void)
  82939. {
  82940. FLAC__BitWriter *bw = (FLAC__BitWriter*)calloc(1, sizeof(FLAC__BitWriter));
  82941. return bw;
  82942. }
  82943. void FLAC__bitwriter_delete(FLAC__BitWriter *bw)
  82944. {
  82945. FLAC__ASSERT(0 != bw);
  82946. FLAC__bitwriter_free(bw);
  82947. free(bw);
  82948. }
  82949. FLAC__bool FLAC__bitwriter_init(FLAC__BitWriter *bw)
  82950. {
  82951. FLAC__ASSERT(0 != bw);
  82952. bw->words = bw->bits = 0;
  82953. bw->capacity = FLAC__BITWRITER_DEFAULT_CAPACITY;
  82954. bw->buffer = (bwword*)malloc(sizeof(bwword) * bw->capacity);
  82955. if(bw->buffer == 0)
  82956. return false;
  82957. return true;
  82958. }
  82959. void FLAC__bitwriter_free(FLAC__BitWriter *bw)
  82960. {
  82961. FLAC__ASSERT(0 != bw);
  82962. if(0 != bw->buffer)
  82963. free(bw->buffer);
  82964. bw->buffer = 0;
  82965. bw->capacity = 0;
  82966. bw->words = bw->bits = 0;
  82967. }
  82968. void FLAC__bitwriter_clear(FLAC__BitWriter *bw)
  82969. {
  82970. bw->words = bw->bits = 0;
  82971. }
  82972. void FLAC__bitwriter_dump(const FLAC__BitWriter *bw, FILE *out)
  82973. {
  82974. unsigned i, j;
  82975. if(bw == 0) {
  82976. fprintf(out, "bitwriter is NULL\n");
  82977. }
  82978. else {
  82979. fprintf(out, "bitwriter: capacity=%u words=%u bits=%u total_bits=%u\n", bw->capacity, bw->words, bw->bits, FLAC__TOTAL_BITS(bw));
  82980. for(i = 0; i < bw->words; i++) {
  82981. fprintf(out, "%08X: ", i);
  82982. for(j = 0; j < FLAC__BITS_PER_WORD; j++)
  82983. fprintf(out, "%01u", bw->buffer[i] & (1 << (FLAC__BITS_PER_WORD-j-1)) ? 1:0);
  82984. fprintf(out, "\n");
  82985. }
  82986. if(bw->bits > 0) {
  82987. fprintf(out, "%08X: ", i);
  82988. for(j = 0; j < bw->bits; j++)
  82989. fprintf(out, "%01u", bw->accum & (1 << (bw->bits-j-1)) ? 1:0);
  82990. fprintf(out, "\n");
  82991. }
  82992. }
  82993. }
  82994. FLAC__bool FLAC__bitwriter_get_write_crc16(FLAC__BitWriter *bw, FLAC__uint16 *crc)
  82995. {
  82996. const FLAC__byte *buffer;
  82997. size_t bytes;
  82998. FLAC__ASSERT((bw->bits & 7) == 0); /* assert that we're byte-aligned */
  82999. if(!FLAC__bitwriter_get_buffer(bw, &buffer, &bytes))
  83000. return false;
  83001. *crc = (FLAC__uint16)FLAC__crc16(buffer, bytes);
  83002. FLAC__bitwriter_release_buffer(bw);
  83003. return true;
  83004. }
  83005. FLAC__bool FLAC__bitwriter_get_write_crc8(FLAC__BitWriter *bw, FLAC__byte *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__crc8(buffer, bytes);
  83013. FLAC__bitwriter_release_buffer(bw);
  83014. return true;
  83015. }
  83016. FLAC__bool FLAC__bitwriter_is_byte_aligned(const FLAC__BitWriter *bw)
  83017. {
  83018. return ((bw->bits & 7) == 0);
  83019. }
  83020. unsigned FLAC__bitwriter_get_input_bits_unconsumed(const FLAC__BitWriter *bw)
  83021. {
  83022. return FLAC__TOTAL_BITS(bw);
  83023. }
  83024. FLAC__bool FLAC__bitwriter_get_buffer(FLAC__BitWriter *bw, const FLAC__byte **buffer, size_t *bytes)
  83025. {
  83026. FLAC__ASSERT((bw->bits & 7) == 0);
  83027. if(bw->bits & 7)
  83028. return false;
  83029. if(bw->bits) {
  83030. FLAC__ASSERT(bw->words <= bw->capacity);
  83031. if(bw->words == bw->capacity && !bitwriter_grow_(bw, FLAC__BITS_PER_WORD))
  83032. return false;
  83033. bw->buffer[bw->words] = SWAP_BE_WORD_TO_HOST(bw->accum << (FLAC__BITS_PER_WORD-bw->bits));
  83034. }
  83035. *buffer = (FLAC__byte*)bw->buffer;
  83036. *bytes = (FLAC__BYTES_PER_WORD * bw->words) + (bw->bits >> 3);
  83037. return true;
  83038. }
  83039. void FLAC__bitwriter_release_buffer(FLAC__BitWriter *bw)
  83040. {
  83041. (void)bw;
  83042. }
  83043. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_zeroes(FLAC__BitWriter *bw, unsigned bits)
  83044. {
  83045. unsigned n;
  83046. FLAC__ASSERT(0 != bw);
  83047. FLAC__ASSERT(0 != bw->buffer);
  83048. if(bits == 0)
  83049. return true;
  83050. if(bw->capacity <= bw->words + bits && !bitwriter_grow_(bw, bits))
  83051. return false;
  83052. if(bw->bits) {
  83053. n = min(FLAC__BITS_PER_WORD - bw->bits, bits);
  83054. bw->accum <<= n;
  83055. bits -= n;
  83056. bw->bits += n;
  83057. if(bw->bits == FLAC__BITS_PER_WORD) {
  83058. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83059. bw->bits = 0;
  83060. }
  83061. else
  83062. return true;
  83063. }
  83064. while(bits >= FLAC__BITS_PER_WORD) {
  83065. bw->buffer[bw->words++] = 0;
  83066. bits -= FLAC__BITS_PER_WORD;
  83067. }
  83068. if(bits > 0) {
  83069. bw->accum = 0;
  83070. bw->bits = bits;
  83071. }
  83072. return true;
  83073. }
  83074. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_uint32(FLAC__BitWriter *bw, FLAC__uint32 val, unsigned bits)
  83075. {
  83076. register unsigned left;
  83077. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  83078. FLAC__ASSERT(0 != bw);
  83079. FLAC__ASSERT(0 != bw->buffer);
  83080. FLAC__ASSERT(bits <= 32);
  83081. if(bits == 0)
  83082. return true;
  83083. if(bw->capacity <= bw->words + bits && !bitwriter_grow_(bw, bits))
  83084. return false;
  83085. left = FLAC__BITS_PER_WORD - bw->bits;
  83086. if(bits < left) {
  83087. bw->accum <<= bits;
  83088. bw->accum |= val;
  83089. bw->bits += bits;
  83090. }
  83091. 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 */
  83092. bw->accum <<= left;
  83093. bw->accum |= val >> (bw->bits = bits - left);
  83094. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83095. bw->accum = val;
  83096. }
  83097. else {
  83098. bw->accum = val;
  83099. bw->bits = 0;
  83100. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(val);
  83101. }
  83102. return true;
  83103. }
  83104. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_int32(FLAC__BitWriter *bw, FLAC__int32 val, unsigned bits)
  83105. {
  83106. if(bits < 32)
  83107. val &= (~(0xffffffff << bits));
  83108. return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, bits);
  83109. }
  83110. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_uint64(FLAC__BitWriter *bw, FLAC__uint64 val, unsigned bits)
  83111. {
  83112. if(bits > 32) {
  83113. return
  83114. FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)(val>>32), bits-32) &&
  83115. FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, 32);
  83116. }
  83117. else
  83118. return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, bits);
  83119. }
  83120. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_uint32_little_endian(FLAC__BitWriter *bw, FLAC__uint32 val)
  83121. {
  83122. if(!FLAC__bitwriter_write_raw_uint32(bw, val & 0xff, 8))
  83123. return false;
  83124. if(!FLAC__bitwriter_write_raw_uint32(bw, (val>>8) & 0xff, 8))
  83125. return false;
  83126. if(!FLAC__bitwriter_write_raw_uint32(bw, (val>>16) & 0xff, 8))
  83127. return false;
  83128. if(!FLAC__bitwriter_write_raw_uint32(bw, val>>24, 8))
  83129. return false;
  83130. return true;
  83131. }
  83132. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_byte_block(FLAC__BitWriter *bw, const FLAC__byte vals[], unsigned nvals)
  83133. {
  83134. unsigned i;
  83135. for(i = 0; i < nvals; i++) {
  83136. if(!FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)(vals[i]), 8))
  83137. return false;
  83138. }
  83139. return true;
  83140. }
  83141. FLAC__bool FLAC__bitwriter_write_unary_unsigned(FLAC__BitWriter *bw, unsigned val)
  83142. {
  83143. if(val < 32)
  83144. return FLAC__bitwriter_write_raw_uint32(bw, 1, ++val);
  83145. else
  83146. return
  83147. FLAC__bitwriter_write_zeroes(bw, val) &&
  83148. FLAC__bitwriter_write_raw_uint32(bw, 1, 1);
  83149. }
  83150. unsigned FLAC__bitwriter_rice_bits(FLAC__int32 val, unsigned parameter)
  83151. {
  83152. FLAC__uint32 uval;
  83153. FLAC__ASSERT(parameter < sizeof(unsigned)*8);
  83154. uval = (val<<1) ^ (val>>31);
  83155. return 1 + parameter + (uval >> parameter);
  83156. }
  83157. #if 0 /* UNUSED */
  83158. unsigned FLAC__bitwriter_golomb_bits_signed(int val, unsigned parameter)
  83159. {
  83160. unsigned bits, msbs, uval;
  83161. unsigned k;
  83162. FLAC__ASSERT(parameter > 0);
  83163. if(val < 0)
  83164. uval = (unsigned)(((-(++val)) << 1) + 1);
  83165. else
  83166. uval = (unsigned)(val << 1);
  83167. k = FLAC__bitmath_ilog2(parameter);
  83168. if(parameter == 1u<<k) {
  83169. FLAC__ASSERT(k <= 30);
  83170. msbs = uval >> k;
  83171. bits = 1 + k + msbs;
  83172. }
  83173. else {
  83174. unsigned q, r, d;
  83175. d = (1 << (k+1)) - parameter;
  83176. q = uval / parameter;
  83177. r = uval - (q * parameter);
  83178. bits = 1 + q + k;
  83179. if(r >= d)
  83180. bits++;
  83181. }
  83182. return bits;
  83183. }
  83184. unsigned FLAC__bitwriter_golomb_bits_unsigned(unsigned uval, unsigned parameter)
  83185. {
  83186. unsigned bits, msbs;
  83187. unsigned k;
  83188. FLAC__ASSERT(parameter > 0);
  83189. k = FLAC__bitmath_ilog2(parameter);
  83190. if(parameter == 1u<<k) {
  83191. FLAC__ASSERT(k <= 30);
  83192. msbs = uval >> k;
  83193. bits = 1 + k + msbs;
  83194. }
  83195. else {
  83196. unsigned q, r, d;
  83197. d = (1 << (k+1)) - parameter;
  83198. q = uval / parameter;
  83199. r = uval - (q * parameter);
  83200. bits = 1 + q + k;
  83201. if(r >= d)
  83202. bits++;
  83203. }
  83204. return bits;
  83205. }
  83206. #endif /* UNUSED */
  83207. FLAC__bool FLAC__bitwriter_write_rice_signed(FLAC__BitWriter *bw, FLAC__int32 val, unsigned parameter)
  83208. {
  83209. unsigned total_bits, interesting_bits, msbs;
  83210. FLAC__uint32 uval, pattern;
  83211. FLAC__ASSERT(0 != bw);
  83212. FLAC__ASSERT(0 != bw->buffer);
  83213. FLAC__ASSERT(parameter < 8*sizeof(uval));
  83214. uval = (val<<1) ^ (val>>31);
  83215. msbs = uval >> parameter;
  83216. interesting_bits = 1 + parameter;
  83217. total_bits = interesting_bits + msbs;
  83218. pattern = 1 << parameter; /* the unary end bit */
  83219. pattern |= (uval & ((1<<parameter)-1)); /* the binary LSBs */
  83220. if(total_bits <= 32)
  83221. return FLAC__bitwriter_write_raw_uint32(bw, pattern, total_bits);
  83222. else
  83223. return
  83224. FLAC__bitwriter_write_zeroes(bw, msbs) && /* write the unary MSBs */
  83225. FLAC__bitwriter_write_raw_uint32(bw, pattern, interesting_bits); /* write the unary end bit and binary LSBs */
  83226. }
  83227. FLAC__bool FLAC__bitwriter_write_rice_signed_block(FLAC__BitWriter *bw, const FLAC__int32 *vals, unsigned nvals, unsigned parameter)
  83228. {
  83229. const FLAC__uint32 mask1 = FLAC__WORD_ALL_ONES << parameter; /* we val|=mask1 to set the stop bit above it... */
  83230. const FLAC__uint32 mask2 = FLAC__WORD_ALL_ONES >> (31-parameter); /* ...then mask off the bits above the stop bit with val&=mask2*/
  83231. FLAC__uint32 uval;
  83232. unsigned left;
  83233. const unsigned lsbits = 1 + parameter;
  83234. unsigned msbits;
  83235. FLAC__ASSERT(0 != bw);
  83236. FLAC__ASSERT(0 != bw->buffer);
  83237. FLAC__ASSERT(parameter < 8*sizeof(bwword)-1);
  83238. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  83239. while(nvals) {
  83240. uval = (*vals<<1) ^ (*vals>>31);
  83241. msbits = uval >> parameter;
  83242. #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) */
  83243. if(bw->bits && bw->bits + msbits + lsbits <= FLAC__BITS_PER_WORD) { /* i.e. if the whole thing fits in the current bwword */
  83244. bw->bits = bw->bits + msbits + lsbits;
  83245. uval |= mask1; /* set stop bit */
  83246. uval &= mask2; /* mask off unused top bits */
  83247. bw->accum <<= msbits;
  83248. bw->accum <<= lsbits;
  83249. bw->accum |= uval;
  83250. if(bw->bits == FLAC__BITS_PER_WORD) {
  83251. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83252. bw->bits = 0;
  83253. if(bw->capacity <= bw->words && nvals > 1 && !bitwriter_grow_(bw, 1)) {
  83254. FLAC__ASSERT(bw->capacity == bw->words);
  83255. return false;
  83256. }
  83257. }
  83258. }
  83259. else {
  83260. #elif 1 /*@@@@@@ OPT: try this version with MSVC6 to see if better, not much difference for gcc-4 */
  83261. if(bw->bits && bw->bits + msbits + lsbits < FLAC__BITS_PER_WORD) { /* i.e. if the whole thing fits in the current bwword */
  83262. bw->bits = bw->bits + msbits + lsbits;
  83263. uval |= mask1; /* set stop bit */
  83264. uval &= mask2; /* mask off unused top bits */
  83265. bw->accum <<= msbits + lsbits;
  83266. bw->accum |= uval;
  83267. }
  83268. else {
  83269. #endif
  83270. if(bw->capacity <= bw->words + bw->bits + msbits + 1/*lsbits always fit in 1 bwword*/ && !bitwriter_grow_(bw, msbits+lsbits))
  83271. return false;
  83272. if(msbits) {
  83273. if(bw->bits) {
  83274. left = FLAC__BITS_PER_WORD - bw->bits;
  83275. if(msbits < left) {
  83276. bw->accum <<= msbits;
  83277. bw->bits += msbits;
  83278. goto break1;
  83279. }
  83280. else {
  83281. bw->accum <<= left;
  83282. msbits -= left;
  83283. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83284. bw->bits = 0;
  83285. }
  83286. }
  83287. while(msbits >= FLAC__BITS_PER_WORD) {
  83288. bw->buffer[bw->words++] = 0;
  83289. msbits -= FLAC__BITS_PER_WORD;
  83290. }
  83291. if(msbits > 0) {
  83292. bw->accum = 0;
  83293. bw->bits = msbits;
  83294. }
  83295. }
  83296. break1:
  83297. uval |= mask1; /* set stop bit */
  83298. uval &= mask2; /* mask off unused top bits */
  83299. left = FLAC__BITS_PER_WORD - bw->bits;
  83300. if(lsbits < left) {
  83301. bw->accum <<= lsbits;
  83302. bw->accum |= uval;
  83303. bw->bits += lsbits;
  83304. }
  83305. else {
  83306. FLAC__ASSERT(bw->bits);
  83307. FLAC__ASSERT(left < FLAC__BITS_PER_WORD);
  83308. bw->accum <<= left;
  83309. bw->accum |= uval >> (bw->bits = lsbits - left);
  83310. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83311. bw->accum = uval;
  83312. }
  83313. #if 1
  83314. }
  83315. #endif
  83316. vals++;
  83317. nvals--;
  83318. }
  83319. return true;
  83320. }
  83321. #if 0 /* UNUSED */
  83322. FLAC__bool FLAC__bitwriter_write_golomb_signed(FLAC__BitWriter *bw, int val, unsigned parameter)
  83323. {
  83324. unsigned total_bits, msbs, uval;
  83325. unsigned k;
  83326. FLAC__ASSERT(0 != bw);
  83327. FLAC__ASSERT(0 != bw->buffer);
  83328. FLAC__ASSERT(parameter > 0);
  83329. if(val < 0)
  83330. uval = (unsigned)(((-(++val)) << 1) + 1);
  83331. else
  83332. uval = (unsigned)(val << 1);
  83333. k = FLAC__bitmath_ilog2(parameter);
  83334. if(parameter == 1u<<k) {
  83335. unsigned pattern;
  83336. FLAC__ASSERT(k <= 30);
  83337. msbs = uval >> k;
  83338. total_bits = 1 + k + msbs;
  83339. pattern = 1 << k; /* the unary end bit */
  83340. pattern |= (uval & ((1u<<k)-1)); /* the binary LSBs */
  83341. if(total_bits <= 32) {
  83342. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, total_bits))
  83343. return false;
  83344. }
  83345. else {
  83346. if(!FLAC__bitwriter_write_zeroes(bw, msbs))
  83347. return false;
  83348. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, k+1))
  83349. return false;
  83350. }
  83351. }
  83352. else {
  83353. unsigned q, r, d;
  83354. d = (1 << (k+1)) - parameter;
  83355. q = uval / parameter;
  83356. r = uval - (q * parameter);
  83357. if(!FLAC__bitwriter_write_zeroes(bw, q))
  83358. return false;
  83359. if(!FLAC__bitwriter_write_raw_uint32(bw, 1, 1))
  83360. return false;
  83361. if(r >= d) {
  83362. if(!FLAC__bitwriter_write_raw_uint32(bw, r+d, k+1))
  83363. return false;
  83364. }
  83365. else {
  83366. if(!FLAC__bitwriter_write_raw_uint32(bw, r, k))
  83367. return false;
  83368. }
  83369. }
  83370. return true;
  83371. }
  83372. FLAC__bool FLAC__bitwriter_write_golomb_unsigned(FLAC__BitWriter *bw, unsigned uval, unsigned parameter)
  83373. {
  83374. unsigned total_bits, msbs;
  83375. unsigned k;
  83376. FLAC__ASSERT(0 != bw);
  83377. FLAC__ASSERT(0 != bw->buffer);
  83378. FLAC__ASSERT(parameter > 0);
  83379. k = FLAC__bitmath_ilog2(parameter);
  83380. if(parameter == 1u<<k) {
  83381. unsigned pattern;
  83382. FLAC__ASSERT(k <= 30);
  83383. msbs = uval >> k;
  83384. total_bits = 1 + k + msbs;
  83385. pattern = 1 << k; /* the unary end bit */
  83386. pattern |= (uval & ((1u<<k)-1)); /* the binary LSBs */
  83387. if(total_bits <= 32) {
  83388. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, total_bits))
  83389. return false;
  83390. }
  83391. else {
  83392. if(!FLAC__bitwriter_write_zeroes(bw, msbs))
  83393. return false;
  83394. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, k+1))
  83395. return false;
  83396. }
  83397. }
  83398. else {
  83399. unsigned q, r, d;
  83400. d = (1 << (k+1)) - parameter;
  83401. q = uval / parameter;
  83402. r = uval - (q * parameter);
  83403. if(!FLAC__bitwriter_write_zeroes(bw, q))
  83404. return false;
  83405. if(!FLAC__bitwriter_write_raw_uint32(bw, 1, 1))
  83406. return false;
  83407. if(r >= d) {
  83408. if(!FLAC__bitwriter_write_raw_uint32(bw, r+d, k+1))
  83409. return false;
  83410. }
  83411. else {
  83412. if(!FLAC__bitwriter_write_raw_uint32(bw, r, k))
  83413. return false;
  83414. }
  83415. }
  83416. return true;
  83417. }
  83418. #endif /* UNUSED */
  83419. FLAC__bool FLAC__bitwriter_write_utf8_uint32(FLAC__BitWriter *bw, FLAC__uint32 val)
  83420. {
  83421. FLAC__bool ok = 1;
  83422. FLAC__ASSERT(0 != bw);
  83423. FLAC__ASSERT(0 != bw->buffer);
  83424. FLAC__ASSERT(!(val & 0x80000000)); /* this version only handles 31 bits */
  83425. if(val < 0x80) {
  83426. return FLAC__bitwriter_write_raw_uint32(bw, val, 8);
  83427. }
  83428. else if(val < 0x800) {
  83429. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xC0 | (val>>6), 8);
  83430. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83431. }
  83432. else if(val < 0x10000) {
  83433. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xE0 | (val>>12), 8);
  83434. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83435. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83436. }
  83437. else if(val < 0x200000) {
  83438. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF0 | (val>>18), 8);
  83439. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
  83440. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83441. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83442. }
  83443. else if(val < 0x4000000) {
  83444. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF8 | (val>>24), 8);
  83445. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>18)&0x3F), 8);
  83446. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
  83447. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83448. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83449. }
  83450. else {
  83451. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFC | (val>>30), 8);
  83452. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>24)&0x3F), 8);
  83453. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>18)&0x3F), 8);
  83454. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
  83455. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83456. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83457. }
  83458. return ok;
  83459. }
  83460. FLAC__bool FLAC__bitwriter_write_utf8_uint64(FLAC__BitWriter *bw, FLAC__uint64 val)
  83461. {
  83462. FLAC__bool ok = 1;
  83463. FLAC__ASSERT(0 != bw);
  83464. FLAC__ASSERT(0 != bw->buffer);
  83465. FLAC__ASSERT(!(val & FLAC__U64L(0xFFFFFFF000000000))); /* this version only handles 36 bits */
  83466. if(val < 0x80) {
  83467. return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, 8);
  83468. }
  83469. else if(val < 0x800) {
  83470. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xC0 | (FLAC__uint32)(val>>6), 8);
  83471. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83472. }
  83473. else if(val < 0x10000) {
  83474. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xE0 | (FLAC__uint32)(val>>12), 8);
  83475. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83476. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83477. }
  83478. else if(val < 0x200000) {
  83479. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF0 | (FLAC__uint32)(val>>18), 8);
  83480. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83481. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83482. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83483. }
  83484. else if(val < 0x4000000) {
  83485. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF8 | (FLAC__uint32)(val>>24), 8);
  83486. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
  83487. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83488. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83489. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83490. }
  83491. else if(val < 0x80000000) {
  83492. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFC | (FLAC__uint32)(val>>30), 8);
  83493. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>24)&0x3F), 8);
  83494. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
  83495. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83496. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83497. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83498. }
  83499. else {
  83500. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFE, 8);
  83501. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>30)&0x3F), 8);
  83502. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>24)&0x3F), 8);
  83503. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
  83504. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83505. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83506. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83507. }
  83508. return ok;
  83509. }
  83510. FLAC__bool FLAC__bitwriter_zero_pad_to_byte_boundary(FLAC__BitWriter *bw)
  83511. {
  83512. if(bw->bits & 7u)
  83513. return FLAC__bitwriter_write_zeroes(bw, 8 - (bw->bits & 7u));
  83514. else
  83515. return true;
  83516. }
  83517. #endif
  83518. /*** End of inlined file: bitwriter.c ***/
  83519. /*** Start of inlined file: cpu.c ***/
  83520. /*** Start of inlined file: juce_FlacHeader.h ***/
  83521. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  83522. // tasks..
  83523. #define VERSION "1.2.1"
  83524. #define FLAC__NO_DLL 1
  83525. #if JUCE_MSVC
  83526. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  83527. #endif
  83528. #if JUCE_MAC
  83529. #define FLAC__SYS_DARWIN 1
  83530. #endif
  83531. /*** End of inlined file: juce_FlacHeader.h ***/
  83532. #if JUCE_USE_FLAC
  83533. #if HAVE_CONFIG_H
  83534. # include <config.h>
  83535. #endif
  83536. #include <stdlib.h>
  83537. #include <stdio.h>
  83538. #if defined FLAC__CPU_IA32
  83539. # include <signal.h>
  83540. #elif defined FLAC__CPU_PPC
  83541. # if !defined FLAC__NO_ASM
  83542. # if defined FLAC__SYS_DARWIN
  83543. # include <sys/sysctl.h>
  83544. # include <mach/mach.h>
  83545. # include <mach/mach_host.h>
  83546. # include <mach/host_info.h>
  83547. # include <mach/machine.h>
  83548. # ifndef CPU_SUBTYPE_POWERPC_970
  83549. # define CPU_SUBTYPE_POWERPC_970 ((cpu_subtype_t) 100)
  83550. # endif
  83551. # else /* FLAC__SYS_DARWIN */
  83552. # include <signal.h>
  83553. # include <setjmp.h>
  83554. static sigjmp_buf jmpbuf;
  83555. static volatile sig_atomic_t canjump = 0;
  83556. static void sigill_handler (int sig)
  83557. {
  83558. if (!canjump) {
  83559. signal (sig, SIG_DFL);
  83560. raise (sig);
  83561. }
  83562. canjump = 0;
  83563. siglongjmp (jmpbuf, 1);
  83564. }
  83565. # endif /* FLAC__SYS_DARWIN */
  83566. # endif /* FLAC__NO_ASM */
  83567. #endif /* FLAC__CPU_PPC */
  83568. #if defined (__NetBSD__) || defined(__OpenBSD__)
  83569. #include <sys/param.h>
  83570. #include <sys/sysctl.h>
  83571. #include <machine/cpu.h>
  83572. #endif
  83573. #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
  83574. #include <sys/types.h>
  83575. #include <sys/sysctl.h>
  83576. #endif
  83577. #if defined(__APPLE__)
  83578. #endif
  83579. static const unsigned FLAC__CPUINFO_IA32_CPUID_CMOV = 0x00008000;
  83580. static const unsigned FLAC__CPUINFO_IA32_CPUID_MMX = 0x00800000;
  83581. static const unsigned FLAC__CPUINFO_IA32_CPUID_FXSR = 0x01000000;
  83582. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE = 0x02000000;
  83583. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE2 = 0x04000000;
  83584. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE3 = 0x00000001;
  83585. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSSE3 = 0x00000200;
  83586. static const unsigned FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_3DNOW = 0x80000000;
  83587. static const unsigned FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXT3DNOW = 0x40000000;
  83588. static const unsigned FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXTMMX = 0x00400000;
  83589. #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM && !defined FLAC__NO_SSE_OS && !defined FLAC__SSE_OS
  83590. # if defined(__linux__)
  83591. # undef USE_OBSOLETE_SIGCONTEXT_FLAVOR /* #define this to use the older signal handler method */
  83592. # ifdef USE_OBSOLETE_SIGCONTEXT_FLAVOR
  83593. static void sigill_handler_sse_os(int signal, struct sigcontext sc)
  83594. {
  83595. (void)signal;
  83596. sc.eip += 3 + 3 + 6;
  83597. }
  83598. # else
  83599. # include <sys/ucontext.h>
  83600. static void sigill_handler_sse_os(int signal, siginfo_t *si, void *uc)
  83601. {
  83602. (void)signal, (void)si;
  83603. ((ucontext_t*)uc)->uc_mcontext.gregs[14/*REG_EIP*/] += 3 + 3 + 6;
  83604. }
  83605. # endif
  83606. # elif defined(_MSC_VER)
  83607. # include <windows.h>
  83608. # undef USE_TRY_CATCH_FLAVOR /* #define this to use the try/catch method for catching illegal opcode exception */
  83609. # ifdef USE_TRY_CATCH_FLAVOR
  83610. # else
  83611. LONG CALLBACK sigill_handler_sse_os(EXCEPTION_POINTERS *ep)
  83612. {
  83613. if(ep->ExceptionRecord->ExceptionCode == EXCEPTION_ILLEGAL_INSTRUCTION) {
  83614. ep->ContextRecord->Eip += 3 + 3 + 6;
  83615. return EXCEPTION_CONTINUE_EXECUTION;
  83616. }
  83617. return EXCEPTION_CONTINUE_SEARCH;
  83618. }
  83619. # endif
  83620. # endif
  83621. #endif
  83622. void FLAC__cpu_info(FLAC__CPUInfo *info)
  83623. {
  83624. #ifdef FLAC__CPU_IA32
  83625. info->type = FLAC__CPUINFO_TYPE_IA32;
  83626. #if !defined FLAC__NO_ASM && defined FLAC__HAS_NASM
  83627. info->use_asm = true; /* we assume a minimum of 80386 with FLAC__CPU_IA32 */
  83628. info->data.ia32.cpuid = FLAC__cpu_have_cpuid_asm_ia32()? true : false;
  83629. info->data.ia32.bswap = info->data.ia32.cpuid; /* CPUID => BSWAP since it came after */
  83630. info->data.ia32.cmov = false;
  83631. info->data.ia32.mmx = false;
  83632. info->data.ia32.fxsr = false;
  83633. info->data.ia32.sse = false;
  83634. info->data.ia32.sse2 = false;
  83635. info->data.ia32.sse3 = false;
  83636. info->data.ia32.ssse3 = false;
  83637. info->data.ia32._3dnow = false;
  83638. info->data.ia32.ext3dnow = false;
  83639. info->data.ia32.extmmx = false;
  83640. if(info->data.ia32.cpuid) {
  83641. FLAC__uint32 flags_edx, flags_ecx;
  83642. FLAC__cpu_info_asm_ia32(&flags_edx, &flags_ecx);
  83643. info->data.ia32.cmov = (flags_edx & FLAC__CPUINFO_IA32_CPUID_CMOV )? true : false;
  83644. info->data.ia32.mmx = (flags_edx & FLAC__CPUINFO_IA32_CPUID_MMX )? true : false;
  83645. info->data.ia32.fxsr = (flags_edx & FLAC__CPUINFO_IA32_CPUID_FXSR )? true : false;
  83646. info->data.ia32.sse = (flags_edx & FLAC__CPUINFO_IA32_CPUID_SSE )? true : false;
  83647. info->data.ia32.sse2 = (flags_edx & FLAC__CPUINFO_IA32_CPUID_SSE2 )? true : false;
  83648. info->data.ia32.sse3 = (flags_ecx & FLAC__CPUINFO_IA32_CPUID_SSE3 )? true : false;
  83649. info->data.ia32.ssse3 = (flags_ecx & FLAC__CPUINFO_IA32_CPUID_SSSE3)? true : false;
  83650. #ifdef FLAC__USE_3DNOW
  83651. flags_edx = FLAC__cpu_info_extended_amd_asm_ia32();
  83652. info->data.ia32._3dnow = (flags_edx & FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_3DNOW )? true : false;
  83653. info->data.ia32.ext3dnow = (flags_edx & FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXT3DNOW)? true : false;
  83654. info->data.ia32.extmmx = (flags_edx & FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXTMMX )? true : false;
  83655. #else
  83656. info->data.ia32._3dnow = info->data.ia32.ext3dnow = info->data.ia32.extmmx = false;
  83657. #endif
  83658. #ifdef DEBUG
  83659. fprintf(stderr, "CPU info (IA-32):\n");
  83660. fprintf(stderr, " CPUID ...... %c\n", info->data.ia32.cpuid ? 'Y' : 'n');
  83661. fprintf(stderr, " BSWAP ...... %c\n", info->data.ia32.bswap ? 'Y' : 'n');
  83662. fprintf(stderr, " CMOV ....... %c\n", info->data.ia32.cmov ? 'Y' : 'n');
  83663. fprintf(stderr, " MMX ........ %c\n", info->data.ia32.mmx ? 'Y' : 'n');
  83664. fprintf(stderr, " FXSR ....... %c\n", info->data.ia32.fxsr ? 'Y' : 'n');
  83665. fprintf(stderr, " SSE ........ %c\n", info->data.ia32.sse ? 'Y' : 'n');
  83666. fprintf(stderr, " SSE2 ....... %c\n", info->data.ia32.sse2 ? 'Y' : 'n');
  83667. fprintf(stderr, " SSE3 ....... %c\n", info->data.ia32.sse3 ? 'Y' : 'n');
  83668. fprintf(stderr, " SSSE3 ...... %c\n", info->data.ia32.ssse3 ? 'Y' : 'n');
  83669. fprintf(stderr, " 3DNow! ..... %c\n", info->data.ia32._3dnow ? 'Y' : 'n');
  83670. fprintf(stderr, " 3DNow!-ext . %c\n", info->data.ia32.ext3dnow? 'Y' : 'n');
  83671. fprintf(stderr, " 3DNow!-MMX . %c\n", info->data.ia32.extmmx ? 'Y' : 'n');
  83672. #endif
  83673. if(info->data.ia32.fxsr || info->data.ia32.sse || info->data.ia32.sse2) {
  83674. #if defined FLAC__NO_SSE_OS
  83675. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83676. #elif defined FLAC__SSE_OS
  83677. #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) || defined(__APPLE__)
  83678. int sse = 0;
  83679. size_t len;
  83680. len = sizeof(sse); sse = sse || (sysctlbyname("hw.instruction_sse", &sse, &len, NULL, 0) == 0 && sse);
  83681. len = sizeof(sse); sse = sse || (sysctlbyname("hw.optional.sse" , &sse, &len, NULL, 0) == 0 && sse); /* __APPLE__ ? */
  83682. if(!sse)
  83683. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83684. #elif defined(__NetBSD__) || defined (__OpenBSD__)
  83685. # if __NetBSD_Version__ >= 105250000 || (defined __OpenBSD__)
  83686. int val = 0, mib[2] = { CTL_MACHDEP, CPU_SSE };
  83687. size_t len = sizeof(val);
  83688. if(sysctl(mib, 2, &val, &len, NULL, 0) < 0 || !val)
  83689. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83690. else { /* double-check SSE2 */
  83691. mib[1] = CPU_SSE2;
  83692. len = sizeof(val);
  83693. if(sysctl(mib, 2, &val, &len, NULL, 0) < 0 || !val)
  83694. info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83695. }
  83696. # else
  83697. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83698. # endif
  83699. #elif defined(__linux__)
  83700. int sse = 0;
  83701. struct sigaction sigill_save;
  83702. #ifdef USE_OBSOLETE_SIGCONTEXT_FLAVOR
  83703. if(0 == sigaction(SIGILL, NULL, &sigill_save) && signal(SIGILL, (void (*)(int))sigill_handler_sse_os) != SIG_ERR)
  83704. #else
  83705. struct sigaction sigill_sse;
  83706. sigill_sse.sa_sigaction = sigill_handler_sse_os;
  83707. __sigemptyset(&sigill_sse.sa_mask);
  83708. 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 */
  83709. if(0 == sigaction(SIGILL, &sigill_sse, &sigill_save))
  83710. #endif
  83711. {
  83712. asm volatile (
  83713. "xorl %0,%0\n\t" /* for some reason, still need to do this to clear 'sse' var */
  83714. "xorps %%xmm0,%%xmm0\n\t" /* will cause SIGILL if unsupported by OS */
  83715. "incl %0\n\t" /* SIGILL handler will jump over this */
  83716. "nop\n\t" /* SIGILL jump lands here if "inc" is 9 bytes */
  83717. "nop\n\t"
  83718. "nop\n\t"
  83719. "nop\n\t"
  83720. "nop\n\t"
  83721. "nop\n\t"
  83722. "nop\n\t" /* SIGILL jump lands here if "inc" is 3 bytes (expected) */
  83723. "nop\n\t"
  83724. "nop" /* SIGILL jump lands here if "inc" is 1 byte */
  83725. : "=r"(sse)
  83726. : "r"(sse)
  83727. );
  83728. sigaction(SIGILL, &sigill_save, NULL);
  83729. }
  83730. if(!sse)
  83731. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83732. #elif defined(_MSC_VER)
  83733. # ifdef USE_TRY_CATCH_FLAVOR
  83734. _try {
  83735. __asm {
  83736. # if _MSC_VER <= 1200
  83737. _emit 0x0F
  83738. _emit 0x57
  83739. _emit 0xC0
  83740. # else
  83741. xorps xmm0,xmm0
  83742. # endif
  83743. }
  83744. }
  83745. _except(EXCEPTION_EXECUTE_HANDLER) {
  83746. if (_exception_code() == STATUS_ILLEGAL_INSTRUCTION)
  83747. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83748. }
  83749. # else
  83750. int sse = 0;
  83751. LPTOP_LEVEL_EXCEPTION_FILTER save = SetUnhandledExceptionFilter(sigill_handler_sse_os);
  83752. __asm {
  83753. # if _MSC_VER <= 1200
  83754. _emit 0x0F
  83755. _emit 0x57
  83756. _emit 0xC0
  83757. # else
  83758. xorps xmm0,xmm0
  83759. # endif
  83760. inc sse
  83761. nop
  83762. nop
  83763. nop
  83764. nop
  83765. nop
  83766. nop
  83767. nop
  83768. nop
  83769. nop
  83770. }
  83771. SetUnhandledExceptionFilter(save);
  83772. if(!sse)
  83773. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83774. # endif
  83775. #else
  83776. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83777. #endif
  83778. #ifdef DEBUG
  83779. fprintf(stderr, " SSE OS sup . %c\n", info->data.ia32.sse ? 'Y' : 'n');
  83780. #endif
  83781. }
  83782. }
  83783. #else
  83784. info->use_asm = false;
  83785. #endif
  83786. #elif defined FLAC__CPU_PPC
  83787. info->type = FLAC__CPUINFO_TYPE_PPC;
  83788. # if !defined FLAC__NO_ASM
  83789. info->use_asm = true;
  83790. # ifdef FLAC__USE_ALTIVEC
  83791. # if defined FLAC__SYS_DARWIN
  83792. {
  83793. int val = 0, mib[2] = { CTL_HW, HW_VECTORUNIT };
  83794. size_t len = sizeof(val);
  83795. info->data.ppc.altivec = !(sysctl(mib, 2, &val, &len, NULL, 0) || !val);
  83796. }
  83797. {
  83798. host_basic_info_data_t hostInfo;
  83799. mach_msg_type_number_t infoCount;
  83800. infoCount = HOST_BASIC_INFO_COUNT;
  83801. host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&hostInfo, &infoCount);
  83802. info->data.ppc.ppc64 = (hostInfo.cpu_type == CPU_TYPE_POWERPC) && (hostInfo.cpu_subtype == CPU_SUBTYPE_POWERPC_970);
  83803. }
  83804. # else /* FLAC__USE_ALTIVEC && !FLAC__SYS_DARWIN */
  83805. {
  83806. info->data.ppc.altivec = 0;
  83807. info->data.ppc.ppc64 = 0;
  83808. signal (SIGILL, sigill_handler);
  83809. canjump = 0;
  83810. if (!sigsetjmp (jmpbuf, 1)) {
  83811. canjump = 1;
  83812. asm volatile (
  83813. "mtspr 256, %0\n\t"
  83814. "vand %%v0, %%v0, %%v0"
  83815. :
  83816. : "r" (-1)
  83817. );
  83818. info->data.ppc.altivec = 1;
  83819. }
  83820. canjump = 0;
  83821. if (!sigsetjmp (jmpbuf, 1)) {
  83822. int x = 0;
  83823. canjump = 1;
  83824. asm volatile ("cntlzd %0, %1" : "=r" (x) : "r" (x) );
  83825. info->data.ppc.ppc64 = 1;
  83826. }
  83827. signal (SIGILL, SIG_DFL); /*@@@@@@ should save and restore old signal */
  83828. }
  83829. # endif
  83830. # else /* !FLAC__USE_ALTIVEC */
  83831. info->data.ppc.altivec = 0;
  83832. info->data.ppc.ppc64 = 0;
  83833. # endif
  83834. # else
  83835. info->use_asm = false;
  83836. # endif
  83837. #else
  83838. info->type = FLAC__CPUINFO_TYPE_UNKNOWN;
  83839. info->use_asm = false;
  83840. #endif
  83841. }
  83842. #endif
  83843. /*** End of inlined file: cpu.c ***/
  83844. /*** Start of inlined file: crc.c ***/
  83845. /*** Start of inlined file: juce_FlacHeader.h ***/
  83846. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  83847. // tasks..
  83848. #define VERSION "1.2.1"
  83849. #define FLAC__NO_DLL 1
  83850. #if JUCE_MSVC
  83851. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  83852. #endif
  83853. #if JUCE_MAC
  83854. #define FLAC__SYS_DARWIN 1
  83855. #endif
  83856. /*** End of inlined file: juce_FlacHeader.h ***/
  83857. #if JUCE_USE_FLAC
  83858. #if HAVE_CONFIG_H
  83859. # include <config.h>
  83860. #endif
  83861. FLAC__byte const FLAC__crc8_table[256] = {
  83862. 0x00, 0x07, 0x0E, 0x09, 0x1C, 0x1B, 0x12, 0x15,
  83863. 0x38, 0x3F, 0x36, 0x31, 0x24, 0x23, 0x2A, 0x2D,
  83864. 0x70, 0x77, 0x7E, 0x79, 0x6C, 0x6B, 0x62, 0x65,
  83865. 0x48, 0x4F, 0x46, 0x41, 0x54, 0x53, 0x5A, 0x5D,
  83866. 0xE0, 0xE7, 0xEE, 0xE9, 0xFC, 0xFB, 0xF2, 0xF5,
  83867. 0xD8, 0xDF, 0xD6, 0xD1, 0xC4, 0xC3, 0xCA, 0xCD,
  83868. 0x90, 0x97, 0x9E, 0x99, 0x8C, 0x8B, 0x82, 0x85,
  83869. 0xA8, 0xAF, 0xA6, 0xA1, 0xB4, 0xB3, 0xBA, 0xBD,
  83870. 0xC7, 0xC0, 0xC9, 0xCE, 0xDB, 0xDC, 0xD5, 0xD2,
  83871. 0xFF, 0xF8, 0xF1, 0xF6, 0xE3, 0xE4, 0xED, 0xEA,
  83872. 0xB7, 0xB0, 0xB9, 0xBE, 0xAB, 0xAC, 0xA5, 0xA2,
  83873. 0x8F, 0x88, 0x81, 0x86, 0x93, 0x94, 0x9D, 0x9A,
  83874. 0x27, 0x20, 0x29, 0x2E, 0x3B, 0x3C, 0x35, 0x32,
  83875. 0x1F, 0x18, 0x11, 0x16, 0x03, 0x04, 0x0D, 0x0A,
  83876. 0x57, 0x50, 0x59, 0x5E, 0x4B, 0x4C, 0x45, 0x42,
  83877. 0x6F, 0x68, 0x61, 0x66, 0x73, 0x74, 0x7D, 0x7A,
  83878. 0x89, 0x8E, 0x87, 0x80, 0x95, 0x92, 0x9B, 0x9C,
  83879. 0xB1, 0xB6, 0xBF, 0xB8, 0xAD, 0xAA, 0xA3, 0xA4,
  83880. 0xF9, 0xFE, 0xF7, 0xF0, 0xE5, 0xE2, 0xEB, 0xEC,
  83881. 0xC1, 0xC6, 0xCF, 0xC8, 0xDD, 0xDA, 0xD3, 0xD4,
  83882. 0x69, 0x6E, 0x67, 0x60, 0x75, 0x72, 0x7B, 0x7C,
  83883. 0x51, 0x56, 0x5F, 0x58, 0x4D, 0x4A, 0x43, 0x44,
  83884. 0x19, 0x1E, 0x17, 0x10, 0x05, 0x02, 0x0B, 0x0C,
  83885. 0x21, 0x26, 0x2F, 0x28, 0x3D, 0x3A, 0x33, 0x34,
  83886. 0x4E, 0x49, 0x40, 0x47, 0x52, 0x55, 0x5C, 0x5B,
  83887. 0x76, 0x71, 0x78, 0x7F, 0x6A, 0x6D, 0x64, 0x63,
  83888. 0x3E, 0x39, 0x30, 0x37, 0x22, 0x25, 0x2C, 0x2B,
  83889. 0x06, 0x01, 0x08, 0x0F, 0x1A, 0x1D, 0x14, 0x13,
  83890. 0xAE, 0xA9, 0xA0, 0xA7, 0xB2, 0xB5, 0xBC, 0xBB,
  83891. 0x96, 0x91, 0x98, 0x9F, 0x8A, 0x8D, 0x84, 0x83,
  83892. 0xDE, 0xD9, 0xD0, 0xD7, 0xC2, 0xC5, 0xCC, 0xCB,
  83893. 0xE6, 0xE1, 0xE8, 0xEF, 0xFA, 0xFD, 0xF4, 0xF3
  83894. };
  83895. unsigned FLAC__crc16_table[256] = {
  83896. 0x0000, 0x8005, 0x800f, 0x000a, 0x801b, 0x001e, 0x0014, 0x8011,
  83897. 0x8033, 0x0036, 0x003c, 0x8039, 0x0028, 0x802d, 0x8027, 0x0022,
  83898. 0x8063, 0x0066, 0x006c, 0x8069, 0x0078, 0x807d, 0x8077, 0x0072,
  83899. 0x0050, 0x8055, 0x805f, 0x005a, 0x804b, 0x004e, 0x0044, 0x8041,
  83900. 0x80c3, 0x00c6, 0x00cc, 0x80c9, 0x00d8, 0x80dd, 0x80d7, 0x00d2,
  83901. 0x00f0, 0x80f5, 0x80ff, 0x00fa, 0x80eb, 0x00ee, 0x00e4, 0x80e1,
  83902. 0x00a0, 0x80a5, 0x80af, 0x00aa, 0x80bb, 0x00be, 0x00b4, 0x80b1,
  83903. 0x8093, 0x0096, 0x009c, 0x8099, 0x0088, 0x808d, 0x8087, 0x0082,
  83904. 0x8183, 0x0186, 0x018c, 0x8189, 0x0198, 0x819d, 0x8197, 0x0192,
  83905. 0x01b0, 0x81b5, 0x81bf, 0x01ba, 0x81ab, 0x01ae, 0x01a4, 0x81a1,
  83906. 0x01e0, 0x81e5, 0x81ef, 0x01ea, 0x81fb, 0x01fe, 0x01f4, 0x81f1,
  83907. 0x81d3, 0x01d6, 0x01dc, 0x81d9, 0x01c8, 0x81cd, 0x81c7, 0x01c2,
  83908. 0x0140, 0x8145, 0x814f, 0x014a, 0x815b, 0x015e, 0x0154, 0x8151,
  83909. 0x8173, 0x0176, 0x017c, 0x8179, 0x0168, 0x816d, 0x8167, 0x0162,
  83910. 0x8123, 0x0126, 0x012c, 0x8129, 0x0138, 0x813d, 0x8137, 0x0132,
  83911. 0x0110, 0x8115, 0x811f, 0x011a, 0x810b, 0x010e, 0x0104, 0x8101,
  83912. 0x8303, 0x0306, 0x030c, 0x8309, 0x0318, 0x831d, 0x8317, 0x0312,
  83913. 0x0330, 0x8335, 0x833f, 0x033a, 0x832b, 0x032e, 0x0324, 0x8321,
  83914. 0x0360, 0x8365, 0x836f, 0x036a, 0x837b, 0x037e, 0x0374, 0x8371,
  83915. 0x8353, 0x0356, 0x035c, 0x8359, 0x0348, 0x834d, 0x8347, 0x0342,
  83916. 0x03c0, 0x83c5, 0x83cf, 0x03ca, 0x83db, 0x03de, 0x03d4, 0x83d1,
  83917. 0x83f3, 0x03f6, 0x03fc, 0x83f9, 0x03e8, 0x83ed, 0x83e7, 0x03e2,
  83918. 0x83a3, 0x03a6, 0x03ac, 0x83a9, 0x03b8, 0x83bd, 0x83b7, 0x03b2,
  83919. 0x0390, 0x8395, 0x839f, 0x039a, 0x838b, 0x038e, 0x0384, 0x8381,
  83920. 0x0280, 0x8285, 0x828f, 0x028a, 0x829b, 0x029e, 0x0294, 0x8291,
  83921. 0x82b3, 0x02b6, 0x02bc, 0x82b9, 0x02a8, 0x82ad, 0x82a7, 0x02a2,
  83922. 0x82e3, 0x02e6, 0x02ec, 0x82e9, 0x02f8, 0x82fd, 0x82f7, 0x02f2,
  83923. 0x02d0, 0x82d5, 0x82df, 0x02da, 0x82cb, 0x02ce, 0x02c4, 0x82c1,
  83924. 0x8243, 0x0246, 0x024c, 0x8249, 0x0258, 0x825d, 0x8257, 0x0252,
  83925. 0x0270, 0x8275, 0x827f, 0x027a, 0x826b, 0x026e, 0x0264, 0x8261,
  83926. 0x0220, 0x8225, 0x822f, 0x022a, 0x823b, 0x023e, 0x0234, 0x8231,
  83927. 0x8213, 0x0216, 0x021c, 0x8219, 0x0208, 0x820d, 0x8207, 0x0202
  83928. };
  83929. void FLAC__crc8_update(const FLAC__byte data, FLAC__uint8 *crc)
  83930. {
  83931. *crc = FLAC__crc8_table[*crc ^ data];
  83932. }
  83933. void FLAC__crc8_update_block(const FLAC__byte *data, unsigned len, FLAC__uint8 *crc)
  83934. {
  83935. while(len--)
  83936. *crc = FLAC__crc8_table[*crc ^ *data++];
  83937. }
  83938. FLAC__uint8 FLAC__crc8(const FLAC__byte *data, unsigned len)
  83939. {
  83940. FLAC__uint8 crc = 0;
  83941. while(len--)
  83942. crc = FLAC__crc8_table[crc ^ *data++];
  83943. return crc;
  83944. }
  83945. unsigned FLAC__crc16(const FLAC__byte *data, unsigned len)
  83946. {
  83947. unsigned crc = 0;
  83948. while(len--)
  83949. crc = ((crc<<8) ^ FLAC__crc16_table[(crc>>8) ^ *data++]) & 0xffff;
  83950. return crc;
  83951. }
  83952. #endif
  83953. /*** End of inlined file: crc.c ***/
  83954. /*** Start of inlined file: fixed.c ***/
  83955. /*** Start of inlined file: juce_FlacHeader.h ***/
  83956. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  83957. // tasks..
  83958. #define VERSION "1.2.1"
  83959. #define FLAC__NO_DLL 1
  83960. #if JUCE_MSVC
  83961. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  83962. #endif
  83963. #if JUCE_MAC
  83964. #define FLAC__SYS_DARWIN 1
  83965. #endif
  83966. /*** End of inlined file: juce_FlacHeader.h ***/
  83967. #if JUCE_USE_FLAC
  83968. #if HAVE_CONFIG_H
  83969. # include <config.h>
  83970. #endif
  83971. #include <math.h>
  83972. #include <string.h>
  83973. /*** Start of inlined file: fixed.h ***/
  83974. #ifndef FLAC__PRIVATE__FIXED_H
  83975. #define FLAC__PRIVATE__FIXED_H
  83976. #ifdef HAVE_CONFIG_H
  83977. #include <config.h>
  83978. #endif
  83979. /*** Start of inlined file: float.h ***/
  83980. #ifndef FLAC__PRIVATE__FLOAT_H
  83981. #define FLAC__PRIVATE__FLOAT_H
  83982. #ifdef HAVE_CONFIG_H
  83983. #include <config.h>
  83984. #endif
  83985. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  83986. typedef double FLAC__double;
  83987. typedef float FLAC__float;
  83988. typedef float FLAC__real;
  83989. #else
  83990. typedef FLAC__int32 FLAC__fixedpoint;
  83991. extern const FLAC__fixedpoint FLAC__FP_ZERO;
  83992. extern const FLAC__fixedpoint FLAC__FP_ONE_HALF;
  83993. extern const FLAC__fixedpoint FLAC__FP_ONE;
  83994. extern const FLAC__fixedpoint FLAC__FP_LN2;
  83995. extern const FLAC__fixedpoint FLAC__FP_E;
  83996. #define FLAC__fixedpoint_trunc(x) ((x)>>16)
  83997. #define FLAC__fixedpoint_mul(x, y) ( (FLAC__fixedpoint) ( ((FLAC__int64)(x)*(FLAC__int64)(y)) >> 16 ) )
  83998. #define FLAC__fixedpoint_div(x, y) ( (FLAC__fixedpoint) ( ( ((FLAC__int64)(x)<<32) / (FLAC__int64)(y) ) >> 16 ) )
  83999. FLAC__uint32 FLAC__fixedpoint_log2(FLAC__uint32 x, unsigned fracbits, unsigned precision);
  84000. #endif
  84001. #endif
  84002. /*** End of inlined file: float.h ***/
  84003. /*** Start of inlined file: format.h ***/
  84004. #ifndef FLAC__PRIVATE__FORMAT_H
  84005. #define FLAC__PRIVATE__FORMAT_H
  84006. unsigned FLAC__format_get_max_rice_partition_order(unsigned blocksize, unsigned predictor_order);
  84007. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize(unsigned blocksize);
  84008. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(unsigned limit, unsigned blocksize, unsigned predictor_order);
  84009. void FLAC__format_entropy_coding_method_partitioned_rice_contents_init(FLAC__EntropyCodingMethod_PartitionedRiceContents *object);
  84010. void FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(FLAC__EntropyCodingMethod_PartitionedRiceContents *object);
  84011. FLAC__bool FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(FLAC__EntropyCodingMethod_PartitionedRiceContents *object, unsigned max_partition_order);
  84012. #endif
  84013. /*** End of inlined file: format.h ***/
  84014. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84015. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  84016. # ifndef FLAC__NO_ASM
  84017. # ifdef FLAC__CPU_IA32
  84018. # ifdef FLAC__HAS_NASM
  84019. 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]);
  84020. # endif
  84021. # endif
  84022. # endif
  84023. 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]);
  84024. #else
  84025. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  84026. 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]);
  84027. #endif
  84028. void FLAC__fixed_compute_residual(const FLAC__int32 data[], unsigned data_len, unsigned order, FLAC__int32 residual[]);
  84029. void FLAC__fixed_restore_signal(const FLAC__int32 residual[], unsigned data_len, unsigned order, FLAC__int32 data[]);
  84030. #endif
  84031. /*** End of inlined file: fixed.h ***/
  84032. #ifndef M_LN2
  84033. #define M_LN2 0.69314718055994530942
  84034. #endif
  84035. #ifdef min
  84036. #undef min
  84037. #endif
  84038. #define min(x,y) ((x) < (y)? (x) : (y))
  84039. #ifdef local_abs
  84040. #undef local_abs
  84041. #endif
  84042. #define local_abs(x) ((unsigned)((x)<0? -(x) : (x)))
  84043. #ifdef FLAC__INTEGER_ONLY_LIBRARY
  84044. static FLAC__fixedpoint local__compute_rbps_integerized(FLAC__uint32 err, FLAC__uint32 n)
  84045. {
  84046. FLAC__uint32 rbps;
  84047. unsigned bits; /* the number of bits required to represent a number */
  84048. int fracbits; /* the number of bits of rbps that comprise the fractional part */
  84049. FLAC__ASSERT(sizeof(rbps) == sizeof(FLAC__fixedpoint));
  84050. FLAC__ASSERT(err > 0);
  84051. FLAC__ASSERT(n > 0);
  84052. FLAC__ASSERT(n <= FLAC__MAX_BLOCK_SIZE);
  84053. if(err <= n)
  84054. return 0;
  84055. fracbits = (8*sizeof(err)) - (FLAC__bitmath_ilog2(err)+1);
  84056. err <<= fracbits;
  84057. err /= n;
  84058. FLAC__ASSERT(err > 0);
  84059. bits = FLAC__bitmath_ilog2(err)+1;
  84060. if(bits > 16) {
  84061. err >>= (bits-16);
  84062. fracbits -= (bits-16);
  84063. }
  84064. rbps = (FLAC__uint32)err;
  84065. rbps *= FLAC__FP_LN2;
  84066. fracbits += 16;
  84067. FLAC__ASSERT(fracbits >= 0);
  84068. {
  84069. const int f = fracbits & 3;
  84070. if(f) {
  84071. rbps >>= f;
  84072. fracbits -= f;
  84073. }
  84074. }
  84075. rbps = FLAC__fixedpoint_log2(rbps, fracbits, (unsigned)(-1));
  84076. if(rbps == 0)
  84077. return 0;
  84078. FLAC__ASSERT((int)FLAC__bitmath_ilog2(rbps)+1 <= fracbits + 6);
  84079. FLAC__ASSERT(fracbits >= -3);
  84080. if(fracbits < 16)
  84081. return rbps << (16-fracbits);
  84082. else if(fracbits > 16)
  84083. return rbps >> (fracbits-16);
  84084. else
  84085. return rbps;
  84086. }
  84087. static FLAC__fixedpoint local__compute_rbps_wide_integerized(FLAC__uint64 err, FLAC__uint32 n)
  84088. {
  84089. FLAC__uint32 rbps;
  84090. unsigned bits; /* the number of bits required to represent a number */
  84091. int fracbits; /* the number of bits of rbps that comprise the fractional part */
  84092. FLAC__ASSERT(sizeof(rbps) == sizeof(FLAC__fixedpoint));
  84093. FLAC__ASSERT(err > 0);
  84094. FLAC__ASSERT(n > 0);
  84095. FLAC__ASSERT(n <= FLAC__MAX_BLOCK_SIZE);
  84096. if(err <= n)
  84097. return 0;
  84098. fracbits = (8*sizeof(err)) - (FLAC__bitmath_ilog2_wide(err)+1);
  84099. err <<= fracbits;
  84100. err /= n;
  84101. FLAC__ASSERT(err > 0);
  84102. bits = FLAC__bitmath_ilog2_wide(err)+1;
  84103. if(bits > 16) {
  84104. err >>= (bits-16);
  84105. fracbits -= (bits-16);
  84106. }
  84107. rbps = (FLAC__uint32)err;
  84108. rbps *= FLAC__FP_LN2;
  84109. fracbits += 16;
  84110. FLAC__ASSERT(fracbits >= 0);
  84111. {
  84112. const int f = fracbits & 3;
  84113. if(f) {
  84114. rbps >>= f;
  84115. fracbits -= f;
  84116. }
  84117. }
  84118. rbps = FLAC__fixedpoint_log2(rbps, fracbits, (unsigned)(-1));
  84119. if(rbps == 0)
  84120. return 0;
  84121. FLAC__ASSERT((int)FLAC__bitmath_ilog2(rbps)+1 <= fracbits + 6);
  84122. FLAC__ASSERT(fracbits >= -3);
  84123. if(fracbits < 16)
  84124. return rbps << (16-fracbits);
  84125. else if(fracbits > 16)
  84126. return rbps >> (fracbits-16);
  84127. else
  84128. return rbps;
  84129. }
  84130. #endif
  84131. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84132. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1])
  84133. #else
  84134. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1])
  84135. #endif
  84136. {
  84137. FLAC__int32 last_error_0 = data[-1];
  84138. FLAC__int32 last_error_1 = data[-1] - data[-2];
  84139. FLAC__int32 last_error_2 = last_error_1 - (data[-2] - data[-3]);
  84140. FLAC__int32 last_error_3 = last_error_2 - (data[-2] - 2*data[-3] + data[-4]);
  84141. FLAC__int32 error, save;
  84142. FLAC__uint32 total_error_0 = 0, total_error_1 = 0, total_error_2 = 0, total_error_3 = 0, total_error_4 = 0;
  84143. unsigned i, order;
  84144. for(i = 0; i < data_len; i++) {
  84145. error = data[i] ; total_error_0 += local_abs(error); save = error;
  84146. error -= last_error_0; total_error_1 += local_abs(error); last_error_0 = save; save = error;
  84147. error -= last_error_1; total_error_2 += local_abs(error); last_error_1 = save; save = error;
  84148. error -= last_error_2; total_error_3 += local_abs(error); last_error_2 = save; save = error;
  84149. error -= last_error_3; total_error_4 += local_abs(error); last_error_3 = save;
  84150. }
  84151. if(total_error_0 < min(min(min(total_error_1, total_error_2), total_error_3), total_error_4))
  84152. order = 0;
  84153. else if(total_error_1 < min(min(total_error_2, total_error_3), total_error_4))
  84154. order = 1;
  84155. else if(total_error_2 < min(total_error_3, total_error_4))
  84156. order = 2;
  84157. else if(total_error_3 < total_error_4)
  84158. order = 3;
  84159. else
  84160. order = 4;
  84161. FLAC__ASSERT(data_len > 0 || total_error_0 == 0);
  84162. FLAC__ASSERT(data_len > 0 || total_error_1 == 0);
  84163. FLAC__ASSERT(data_len > 0 || total_error_2 == 0);
  84164. FLAC__ASSERT(data_len > 0 || total_error_3 == 0);
  84165. FLAC__ASSERT(data_len > 0 || total_error_4 == 0);
  84166. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84167. 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);
  84168. 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);
  84169. 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);
  84170. 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);
  84171. 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);
  84172. #else
  84173. residual_bits_per_sample[0] = (total_error_0 > 0) ? local__compute_rbps_integerized(total_error_0, data_len) : 0;
  84174. residual_bits_per_sample[1] = (total_error_1 > 0) ? local__compute_rbps_integerized(total_error_1, data_len) : 0;
  84175. residual_bits_per_sample[2] = (total_error_2 > 0) ? local__compute_rbps_integerized(total_error_2, data_len) : 0;
  84176. residual_bits_per_sample[3] = (total_error_3 > 0) ? local__compute_rbps_integerized(total_error_3, data_len) : 0;
  84177. residual_bits_per_sample[4] = (total_error_4 > 0) ? local__compute_rbps_integerized(total_error_4, data_len) : 0;
  84178. #endif
  84179. return order;
  84180. }
  84181. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84182. 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])
  84183. #else
  84184. 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])
  84185. #endif
  84186. {
  84187. FLAC__int32 last_error_0 = data[-1];
  84188. FLAC__int32 last_error_1 = data[-1] - data[-2];
  84189. FLAC__int32 last_error_2 = last_error_1 - (data[-2] - data[-3]);
  84190. FLAC__int32 last_error_3 = last_error_2 - (data[-2] - 2*data[-3] + data[-4]);
  84191. FLAC__int32 error, save;
  84192. FLAC__uint64 total_error_0 = 0, total_error_1 = 0, total_error_2 = 0, total_error_3 = 0, total_error_4 = 0;
  84193. unsigned i, order;
  84194. for(i = 0; i < data_len; i++) {
  84195. error = data[i] ; total_error_0 += local_abs(error); save = error;
  84196. error -= last_error_0; total_error_1 += local_abs(error); last_error_0 = save; save = error;
  84197. error -= last_error_1; total_error_2 += local_abs(error); last_error_1 = save; save = error;
  84198. error -= last_error_2; total_error_3 += local_abs(error); last_error_2 = save; save = error;
  84199. error -= last_error_3; total_error_4 += local_abs(error); last_error_3 = save;
  84200. }
  84201. if(total_error_0 < min(min(min(total_error_1, total_error_2), total_error_3), total_error_4))
  84202. order = 0;
  84203. else if(total_error_1 < min(min(total_error_2, total_error_3), total_error_4))
  84204. order = 1;
  84205. else if(total_error_2 < min(total_error_3, total_error_4))
  84206. order = 2;
  84207. else if(total_error_3 < total_error_4)
  84208. order = 3;
  84209. else
  84210. order = 4;
  84211. FLAC__ASSERT(data_len > 0 || total_error_0 == 0);
  84212. FLAC__ASSERT(data_len > 0 || total_error_1 == 0);
  84213. FLAC__ASSERT(data_len > 0 || total_error_2 == 0);
  84214. FLAC__ASSERT(data_len > 0 || total_error_3 == 0);
  84215. FLAC__ASSERT(data_len > 0 || total_error_4 == 0);
  84216. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84217. #if defined _MSC_VER || defined __MINGW32__
  84218. 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);
  84219. 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);
  84220. 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);
  84221. 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);
  84222. 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);
  84223. #else
  84224. 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);
  84225. 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);
  84226. 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);
  84227. 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);
  84228. 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);
  84229. #endif
  84230. #else
  84231. residual_bits_per_sample[0] = (total_error_0 > 0) ? local__compute_rbps_wide_integerized(total_error_0, data_len) : 0;
  84232. residual_bits_per_sample[1] = (total_error_1 > 0) ? local__compute_rbps_wide_integerized(total_error_1, data_len) : 0;
  84233. residual_bits_per_sample[2] = (total_error_2 > 0) ? local__compute_rbps_wide_integerized(total_error_2, data_len) : 0;
  84234. residual_bits_per_sample[3] = (total_error_3 > 0) ? local__compute_rbps_wide_integerized(total_error_3, data_len) : 0;
  84235. residual_bits_per_sample[4] = (total_error_4 > 0) ? local__compute_rbps_wide_integerized(total_error_4, data_len) : 0;
  84236. #endif
  84237. return order;
  84238. }
  84239. void FLAC__fixed_compute_residual(const FLAC__int32 data[], unsigned data_len, unsigned order, FLAC__int32 residual[])
  84240. {
  84241. const int idata_len = (int)data_len;
  84242. int i;
  84243. switch(order) {
  84244. case 0:
  84245. FLAC__ASSERT(sizeof(residual[0]) == sizeof(data[0]));
  84246. memcpy(residual, data, sizeof(residual[0])*data_len);
  84247. break;
  84248. case 1:
  84249. for(i = 0; i < idata_len; i++)
  84250. residual[i] = data[i] - data[i-1];
  84251. break;
  84252. case 2:
  84253. for(i = 0; i < idata_len; i++)
  84254. #if 1 /* OPT: may be faster with some compilers on some systems */
  84255. residual[i] = data[i] - (data[i-1] << 1) + data[i-2];
  84256. #else
  84257. residual[i] = data[i] - 2*data[i-1] + data[i-2];
  84258. #endif
  84259. break;
  84260. case 3:
  84261. for(i = 0; i < idata_len; i++)
  84262. #if 1 /* OPT: may be faster with some compilers on some systems */
  84263. residual[i] = data[i] - (((data[i-1]-data[i-2])<<1) + (data[i-1]-data[i-2])) - data[i-3];
  84264. #else
  84265. residual[i] = data[i] - 3*data[i-1] + 3*data[i-2] - data[i-3];
  84266. #endif
  84267. break;
  84268. case 4:
  84269. for(i = 0; i < idata_len; i++)
  84270. #if 1 /* OPT: may be faster with some compilers on some systems */
  84271. residual[i] = data[i] - ((data[i-1]+data[i-3])<<2) + ((data[i-2]<<2) + (data[i-2]<<1)) + data[i-4];
  84272. #else
  84273. residual[i] = data[i] - 4*data[i-1] + 6*data[i-2] - 4*data[i-3] + data[i-4];
  84274. #endif
  84275. break;
  84276. default:
  84277. FLAC__ASSERT(0);
  84278. }
  84279. }
  84280. void FLAC__fixed_restore_signal(const FLAC__int32 residual[], unsigned data_len, unsigned order, FLAC__int32 data[])
  84281. {
  84282. int i, idata_len = (int)data_len;
  84283. switch(order) {
  84284. case 0:
  84285. FLAC__ASSERT(sizeof(residual[0]) == sizeof(data[0]));
  84286. memcpy(data, residual, sizeof(residual[0])*data_len);
  84287. break;
  84288. case 1:
  84289. for(i = 0; i < idata_len; i++)
  84290. data[i] = residual[i] + data[i-1];
  84291. break;
  84292. case 2:
  84293. for(i = 0; i < idata_len; i++)
  84294. #if 1 /* OPT: may be faster with some compilers on some systems */
  84295. data[i] = residual[i] + (data[i-1]<<1) - data[i-2];
  84296. #else
  84297. data[i] = residual[i] + 2*data[i-1] - data[i-2];
  84298. #endif
  84299. break;
  84300. case 3:
  84301. for(i = 0; i < idata_len; i++)
  84302. #if 1 /* OPT: may be faster with some compilers on some systems */
  84303. data[i] = residual[i] + (((data[i-1]-data[i-2])<<1) + (data[i-1]-data[i-2])) + data[i-3];
  84304. #else
  84305. data[i] = residual[i] + 3*data[i-1] - 3*data[i-2] + data[i-3];
  84306. #endif
  84307. break;
  84308. case 4:
  84309. for(i = 0; i < idata_len; i++)
  84310. #if 1 /* OPT: may be faster with some compilers on some systems */
  84311. data[i] = residual[i] + ((data[i-1]+data[i-3])<<2) - ((data[i-2]<<2) + (data[i-2]<<1)) - data[i-4];
  84312. #else
  84313. data[i] = residual[i] + 4*data[i-1] - 6*data[i-2] + 4*data[i-3] - data[i-4];
  84314. #endif
  84315. break;
  84316. default:
  84317. FLAC__ASSERT(0);
  84318. }
  84319. }
  84320. #endif
  84321. /*** End of inlined file: fixed.c ***/
  84322. /*** Start of inlined file: float.c ***/
  84323. /*** Start of inlined file: juce_FlacHeader.h ***/
  84324. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84325. // tasks..
  84326. #define VERSION "1.2.1"
  84327. #define FLAC__NO_DLL 1
  84328. #if JUCE_MSVC
  84329. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84330. #endif
  84331. #if JUCE_MAC
  84332. #define FLAC__SYS_DARWIN 1
  84333. #endif
  84334. /*** End of inlined file: juce_FlacHeader.h ***/
  84335. #if JUCE_USE_FLAC
  84336. #if HAVE_CONFIG_H
  84337. # include <config.h>
  84338. #endif
  84339. #ifdef FLAC__INTEGER_ONLY_LIBRARY
  84340. #ifdef _MSC_VER
  84341. #define FLAC__U64L(x) x
  84342. #else
  84343. #define FLAC__U64L(x) x##LLU
  84344. #endif
  84345. const FLAC__fixedpoint FLAC__FP_ZERO = 0;
  84346. const FLAC__fixedpoint FLAC__FP_ONE_HALF = 0x00008000;
  84347. const FLAC__fixedpoint FLAC__FP_ONE = 0x00010000;
  84348. const FLAC__fixedpoint FLAC__FP_LN2 = 45426;
  84349. const FLAC__fixedpoint FLAC__FP_E = 178145;
  84350. #define LOG2_LOOKUP_PRECISION 16
  84351. static const FLAC__uint32 log2_lookup[][LOG2_LOOKUP_PRECISION] = {
  84352. {
  84353. 0x00000000,
  84354. 0x00000001,
  84355. 0x00000000,
  84356. 0x00000000,
  84357. 0x00000000,
  84358. 0x00000000,
  84359. 0x00000000,
  84360. 0x00000000,
  84361. 0x00000000,
  84362. 0x00000000,
  84363. 0x00000000,
  84364. 0x00000000,
  84365. 0x00000000,
  84366. 0x00000000,
  84367. 0x00000000,
  84368. 0x00000000
  84369. },
  84370. {
  84371. 0x00000000,
  84372. 0x00000010,
  84373. 0x00000007,
  84374. 0x00000003,
  84375. 0x00000001,
  84376. 0x00000001,
  84377. 0x00000000,
  84378. 0x00000000,
  84379. 0x00000000,
  84380. 0x00000000,
  84381. 0x00000000,
  84382. 0x00000000,
  84383. 0x00000000,
  84384. 0x00000000,
  84385. 0x00000000,
  84386. 0x00000000
  84387. },
  84388. {
  84389. 0x00000000,
  84390. 0x00000100,
  84391. 0x0000006a,
  84392. 0x00000031,
  84393. 0x00000018,
  84394. 0x0000000c,
  84395. 0x00000006,
  84396. 0x00000003,
  84397. 0x00000001,
  84398. 0x00000001,
  84399. 0x00000000,
  84400. 0x00000000,
  84401. 0x00000000,
  84402. 0x00000000,
  84403. 0x00000000,
  84404. 0x00000000
  84405. },
  84406. {
  84407. 0x00000000,
  84408. 0x00001000,
  84409. 0x000006a4,
  84410. 0x00000315,
  84411. 0x0000017d,
  84412. 0x000000bc,
  84413. 0x0000005d,
  84414. 0x0000002e,
  84415. 0x00000017,
  84416. 0x0000000c,
  84417. 0x00000006,
  84418. 0x00000003,
  84419. 0x00000001,
  84420. 0x00000001,
  84421. 0x00000000,
  84422. 0x00000000
  84423. },
  84424. {
  84425. 0x00000000,
  84426. 0x00010000,
  84427. 0x00006a40,
  84428. 0x00003151,
  84429. 0x000017d6,
  84430. 0x00000bba,
  84431. 0x000005d1,
  84432. 0x000002e6,
  84433. 0x00000172,
  84434. 0x000000b9,
  84435. 0x0000005c,
  84436. 0x0000002e,
  84437. 0x00000017,
  84438. 0x0000000c,
  84439. 0x00000006,
  84440. 0x00000003
  84441. },
  84442. {
  84443. 0x00000000,
  84444. 0x00100000,
  84445. 0x0006a3fe,
  84446. 0x00031513,
  84447. 0x00017d60,
  84448. 0x0000bb9d,
  84449. 0x00005d10,
  84450. 0x00002e59,
  84451. 0x00001721,
  84452. 0x00000b8e,
  84453. 0x000005c6,
  84454. 0x000002e3,
  84455. 0x00000171,
  84456. 0x000000b9,
  84457. 0x0000005c,
  84458. 0x0000002e
  84459. },
  84460. {
  84461. 0x00000000,
  84462. 0x01000000,
  84463. 0x006a3fe6,
  84464. 0x00315130,
  84465. 0x0017d605,
  84466. 0x000bb9ca,
  84467. 0x0005d0fc,
  84468. 0x0002e58f,
  84469. 0x0001720e,
  84470. 0x0000b8d8,
  84471. 0x00005c61,
  84472. 0x00002e2d,
  84473. 0x00001716,
  84474. 0x00000b8b,
  84475. 0x000005c5,
  84476. 0x000002e3
  84477. },
  84478. {
  84479. 0x00000000,
  84480. 0x10000000,
  84481. 0x06a3fe5c,
  84482. 0x03151301,
  84483. 0x017d6049,
  84484. 0x00bb9ca6,
  84485. 0x005d0fba,
  84486. 0x002e58f7,
  84487. 0x001720da,
  84488. 0x000b8d87,
  84489. 0x0005c60b,
  84490. 0x0002e2d7,
  84491. 0x00017160,
  84492. 0x0000b8ad,
  84493. 0x00005c56,
  84494. 0x00002e2b
  84495. }
  84496. };
  84497. #if 0
  84498. static const FLAC__uint64 log2_lookup_wide[] = {
  84499. {
  84500. 0x00000000,
  84501. FLAC__U64L(0x100000000),
  84502. FLAC__U64L(0x6a3fe5c6),
  84503. FLAC__U64L(0x31513015),
  84504. FLAC__U64L(0x17d60497),
  84505. FLAC__U64L(0x0bb9ca65),
  84506. FLAC__U64L(0x05d0fba2),
  84507. FLAC__U64L(0x02e58f74),
  84508. FLAC__U64L(0x01720d9c),
  84509. FLAC__U64L(0x00b8d875),
  84510. FLAC__U64L(0x005c60aa),
  84511. FLAC__U64L(0x002e2d72),
  84512. FLAC__U64L(0x00171600),
  84513. FLAC__U64L(0x000b8ad2),
  84514. FLAC__U64L(0x0005c55d),
  84515. FLAC__U64L(0x0002e2ac)
  84516. },
  84517. {
  84518. 0x00000000,
  84519. FLAC__U64L(0x1000000000000),
  84520. FLAC__U64L(0x6a3fe5c60429),
  84521. FLAC__U64L(0x315130157f7a),
  84522. FLAC__U64L(0x17d60496cfbb),
  84523. FLAC__U64L(0xbb9ca64ecac),
  84524. FLAC__U64L(0x5d0fba187cd),
  84525. FLAC__U64L(0x2e58f7441ee),
  84526. FLAC__U64L(0x1720d9c06a8),
  84527. FLAC__U64L(0xb8d8752173),
  84528. FLAC__U64L(0x5c60aa252e),
  84529. FLAC__U64L(0x2e2d71b0d8),
  84530. FLAC__U64L(0x1716001719),
  84531. FLAC__U64L(0xb8ad1de1b),
  84532. FLAC__U64L(0x5c55d640d),
  84533. FLAC__U64L(0x2e2abcf52)
  84534. }
  84535. };
  84536. #endif
  84537. FLAC__uint32 FLAC__fixedpoint_log2(FLAC__uint32 x, unsigned fracbits, unsigned precision)
  84538. {
  84539. const FLAC__uint32 ONE = (1u << fracbits);
  84540. const FLAC__uint32 *table = log2_lookup[fracbits >> 2];
  84541. FLAC__ASSERT(fracbits < 32);
  84542. FLAC__ASSERT((fracbits & 0x3) == 0);
  84543. if(x < ONE)
  84544. return 0;
  84545. if(precision > LOG2_LOOKUP_PRECISION)
  84546. precision = LOG2_LOOKUP_PRECISION;
  84547. {
  84548. FLAC__uint32 y = 0;
  84549. FLAC__uint32 z = x >> 1, k = 1;
  84550. while (x > ONE && k < precision) {
  84551. if (x - z >= ONE) {
  84552. x -= z;
  84553. z = x >> k;
  84554. y += table[k];
  84555. }
  84556. else {
  84557. z >>= 1;
  84558. k++;
  84559. }
  84560. }
  84561. return y;
  84562. }
  84563. }
  84564. #endif /* defined FLAC__INTEGER_ONLY_LIBRARY */
  84565. #endif
  84566. /*** End of inlined file: float.c ***/
  84567. /*** Start of inlined file: format.c ***/
  84568. /*** Start of inlined file: juce_FlacHeader.h ***/
  84569. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84570. // tasks..
  84571. #define VERSION "1.2.1"
  84572. #define FLAC__NO_DLL 1
  84573. #if JUCE_MSVC
  84574. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84575. #endif
  84576. #if JUCE_MAC
  84577. #define FLAC__SYS_DARWIN 1
  84578. #endif
  84579. /*** End of inlined file: juce_FlacHeader.h ***/
  84580. #if JUCE_USE_FLAC
  84581. #if HAVE_CONFIG_H
  84582. # include <config.h>
  84583. #endif
  84584. #include <stdio.h>
  84585. #include <stdlib.h> /* for qsort() */
  84586. #include <string.h> /* for memset() */
  84587. #ifndef FLaC__INLINE
  84588. #define FLaC__INLINE
  84589. #endif
  84590. #ifdef min
  84591. #undef min
  84592. #endif
  84593. #define min(a,b) ((a)<(b)?(a):(b))
  84594. #ifdef _MSC_VER
  84595. #define FLAC__U64L(x) x
  84596. #else
  84597. #define FLAC__U64L(x) x##LLU
  84598. #endif
  84599. FLAC_API const char *FLAC__VERSION_STRING = VERSION
  84600. ;
  84601. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINW32__
  84602. FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC 1.2.1 20070917";
  84603. #else
  84604. FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC " VERSION " 20070917";
  84605. #endif
  84606. FLAC_API const FLAC__byte FLAC__STREAM_SYNC_STRING[4] = { 'f','L','a','C' };
  84607. FLAC_API const unsigned FLAC__STREAM_SYNC = 0x664C6143;
  84608. FLAC_API const unsigned FLAC__STREAM_SYNC_LEN = 32; /* bits */
  84609. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN = 16; /* bits */
  84610. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN = 16; /* bits */
  84611. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN = 24; /* bits */
  84612. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN = 24; /* bits */
  84613. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN = 20; /* bits */
  84614. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN = 3; /* bits */
  84615. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN = 5; /* bits */
  84616. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN = 36; /* bits */
  84617. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MD5SUM_LEN = 128; /* bits */
  84618. FLAC_API const unsigned FLAC__STREAM_METADATA_APPLICATION_ID_LEN = 32; /* bits */
  84619. FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN = 64; /* bits */
  84620. FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN = 64; /* bits */
  84621. FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN = 16; /* bits */
  84622. FLAC_API const FLAC__uint64 FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER = FLAC__U64L(0xffffffffffffffff);
  84623. FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN = 32; /* bits */
  84624. FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN = 32; /* bits */
  84625. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN = 64; /* bits */
  84626. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN = 8; /* bits */
  84627. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN = 3*8; /* bits */
  84628. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN = 64; /* bits */
  84629. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN = 8; /* bits */
  84630. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN = 12*8; /* bits */
  84631. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN = 1; /* bit */
  84632. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN = 1; /* bit */
  84633. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN = 6+13*8; /* bits */
  84634. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN = 8; /* bits */
  84635. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN = 128*8; /* bits */
  84636. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN = 64; /* bits */
  84637. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN = 1; /* bit */
  84638. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN = 7+258*8; /* bits */
  84639. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN = 8; /* bits */
  84640. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_TYPE_LEN = 32; /* bits */
  84641. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN = 32; /* bits */
  84642. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN = 32; /* bits */
  84643. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN = 32; /* bits */
  84644. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN = 32; /* bits */
  84645. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN = 32; /* bits */
  84646. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_COLORS_LEN = 32; /* bits */
  84647. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN = 32; /* bits */
  84648. FLAC_API const unsigned FLAC__STREAM_METADATA_IS_LAST_LEN = 1; /* bits */
  84649. FLAC_API const unsigned FLAC__STREAM_METADATA_TYPE_LEN = 7; /* bits */
  84650. FLAC_API const unsigned FLAC__STREAM_METADATA_LENGTH_LEN = 24; /* bits */
  84651. FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC = 0x3ffe;
  84652. FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC_LEN = 14; /* bits */
  84653. FLAC_API const unsigned FLAC__FRAME_HEADER_RESERVED_LEN = 1; /* bits */
  84654. FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN = 1; /* bits */
  84655. FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCK_SIZE_LEN = 4; /* bits */
  84656. FLAC_API const unsigned FLAC__FRAME_HEADER_SAMPLE_RATE_LEN = 4; /* bits */
  84657. FLAC_API const unsigned FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN = 4; /* bits */
  84658. FLAC_API const unsigned FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN = 3; /* bits */
  84659. FLAC_API const unsigned FLAC__FRAME_HEADER_ZERO_PAD_LEN = 1; /* bits */
  84660. FLAC_API const unsigned FLAC__FRAME_HEADER_CRC_LEN = 8; /* bits */
  84661. FLAC_API const unsigned FLAC__FRAME_FOOTER_CRC_LEN = 16; /* bits */
  84662. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_TYPE_LEN = 2; /* bits */
  84663. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN = 4; /* bits */
  84664. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN = 4; /* bits */
  84665. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN = 5; /* bits */
  84666. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN = 5; /* bits */
  84667. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER = 15; /* == (1<<FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN)-1 */
  84668. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER = 31; /* == (1<<FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN)-1 */
  84669. FLAC_API const char * const FLAC__EntropyCodingMethodTypeString[] = {
  84670. "PARTITIONED_RICE",
  84671. "PARTITIONED_RICE2"
  84672. };
  84673. FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN = 4; /* bits */
  84674. FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN = 5; /* bits */
  84675. FLAC_API const unsigned FLAC__SUBFRAME_ZERO_PAD_LEN = 1; /* bits */
  84676. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LEN = 6; /* bits */
  84677. FLAC_API const unsigned FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN = 1; /* bits */
  84678. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_CONSTANT_BYTE_ALIGNED_MASK = 0x00;
  84679. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_VERBATIM_BYTE_ALIGNED_MASK = 0x02;
  84680. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_FIXED_BYTE_ALIGNED_MASK = 0x10;
  84681. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LPC_BYTE_ALIGNED_MASK = 0x40;
  84682. FLAC_API const char * const FLAC__SubframeTypeString[] = {
  84683. "CONSTANT",
  84684. "VERBATIM",
  84685. "FIXED",
  84686. "LPC"
  84687. };
  84688. FLAC_API const char * const FLAC__ChannelAssignmentString[] = {
  84689. "INDEPENDENT",
  84690. "LEFT_SIDE",
  84691. "RIGHT_SIDE",
  84692. "MID_SIDE"
  84693. };
  84694. FLAC_API const char * const FLAC__FrameNumberTypeString[] = {
  84695. "FRAME_NUMBER_TYPE_FRAME_NUMBER",
  84696. "FRAME_NUMBER_TYPE_SAMPLE_NUMBER"
  84697. };
  84698. FLAC_API const char * const FLAC__MetadataTypeString[] = {
  84699. "STREAMINFO",
  84700. "PADDING",
  84701. "APPLICATION",
  84702. "SEEKTABLE",
  84703. "VORBIS_COMMENT",
  84704. "CUESHEET",
  84705. "PICTURE"
  84706. };
  84707. FLAC_API const char * const FLAC__StreamMetadata_Picture_TypeString[] = {
  84708. "Other",
  84709. "32x32 pixels 'file icon' (PNG only)",
  84710. "Other file icon",
  84711. "Cover (front)",
  84712. "Cover (back)",
  84713. "Leaflet page",
  84714. "Media (e.g. label side of CD)",
  84715. "Lead artist/lead performer/soloist",
  84716. "Artist/performer",
  84717. "Conductor",
  84718. "Band/Orchestra",
  84719. "Composer",
  84720. "Lyricist/text writer",
  84721. "Recording Location",
  84722. "During recording",
  84723. "During performance",
  84724. "Movie/video screen capture",
  84725. "A bright coloured fish",
  84726. "Illustration",
  84727. "Band/artist logotype",
  84728. "Publisher/Studio logotype"
  84729. };
  84730. FLAC_API FLAC__bool FLAC__format_sample_rate_is_valid(unsigned sample_rate)
  84731. {
  84732. if(sample_rate == 0 || sample_rate > FLAC__MAX_SAMPLE_RATE) {
  84733. return false;
  84734. }
  84735. else
  84736. return true;
  84737. }
  84738. FLAC_API FLAC__bool FLAC__format_sample_rate_is_subset(unsigned sample_rate)
  84739. {
  84740. if(
  84741. !FLAC__format_sample_rate_is_valid(sample_rate) ||
  84742. (
  84743. sample_rate >= (1u << 16) &&
  84744. !(sample_rate % 1000 == 0 || sample_rate % 10 == 0)
  84745. )
  84746. ) {
  84747. return false;
  84748. }
  84749. else
  84750. return true;
  84751. }
  84752. FLAC_API FLAC__bool FLAC__format_seektable_is_legal(const FLAC__StreamMetadata_SeekTable *seek_table)
  84753. {
  84754. unsigned i;
  84755. FLAC__uint64 prev_sample_number = 0;
  84756. FLAC__bool got_prev = false;
  84757. FLAC__ASSERT(0 != seek_table);
  84758. for(i = 0; i < seek_table->num_points; i++) {
  84759. if(got_prev) {
  84760. if(
  84761. seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER &&
  84762. seek_table->points[i].sample_number <= prev_sample_number
  84763. )
  84764. return false;
  84765. }
  84766. prev_sample_number = seek_table->points[i].sample_number;
  84767. got_prev = true;
  84768. }
  84769. return true;
  84770. }
  84771. static int seekpoint_compare_(const FLAC__StreamMetadata_SeekPoint *l, const FLAC__StreamMetadata_SeekPoint *r)
  84772. {
  84773. if(l->sample_number == r->sample_number)
  84774. return 0;
  84775. else if(l->sample_number < r->sample_number)
  84776. return -1;
  84777. else
  84778. return 1;
  84779. }
  84780. FLAC_API unsigned FLAC__format_seektable_sort(FLAC__StreamMetadata_SeekTable *seek_table)
  84781. {
  84782. unsigned i, j;
  84783. FLAC__bool first;
  84784. FLAC__ASSERT(0 != seek_table);
  84785. qsort(seek_table->points, seek_table->num_points, sizeof(FLAC__StreamMetadata_SeekPoint), (int (*)(const void *, const void *))seekpoint_compare_);
  84786. first = true;
  84787. for(i = j = 0; i < seek_table->num_points; i++) {
  84788. if(seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER) {
  84789. if(!first) {
  84790. if(seek_table->points[i].sample_number == seek_table->points[j-1].sample_number)
  84791. continue;
  84792. }
  84793. }
  84794. first = false;
  84795. seek_table->points[j++] = seek_table->points[i];
  84796. }
  84797. for(i = j; i < seek_table->num_points; i++) {
  84798. seek_table->points[i].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
  84799. seek_table->points[i].stream_offset = 0;
  84800. seek_table->points[i].frame_samples = 0;
  84801. }
  84802. return j;
  84803. }
  84804. static FLaC__INLINE unsigned utf8len_(const FLAC__byte *utf8)
  84805. {
  84806. FLAC__ASSERT(0 != utf8);
  84807. if ((utf8[0] & 0x80) == 0) {
  84808. return 1;
  84809. }
  84810. else if ((utf8[0] & 0xE0) == 0xC0 && (utf8[1] & 0xC0) == 0x80) {
  84811. if ((utf8[0] & 0xFE) == 0xC0) /* overlong sequence check */
  84812. return 0;
  84813. return 2;
  84814. }
  84815. else if ((utf8[0] & 0xF0) == 0xE0 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80) {
  84816. if (utf8[0] == 0xE0 && (utf8[1] & 0xE0) == 0x80) /* overlong sequence check */
  84817. return 0;
  84818. if (utf8[0] == 0xED && (utf8[1] & 0xE0) == 0xA0) /* D800-DFFF */
  84819. return 0;
  84820. if (utf8[0] == 0xEF && utf8[1] == 0xBF && (utf8[2] & 0xFE) == 0xBE) /* FFFE-FFFF */
  84821. return 0;
  84822. return 3;
  84823. }
  84824. else if ((utf8[0] & 0xF8) == 0xF0 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80 && (utf8[3] & 0xC0) == 0x80) {
  84825. if (utf8[0] == 0xF0 && (utf8[1] & 0xF0) == 0x80) /* overlong sequence check */
  84826. return 0;
  84827. return 4;
  84828. }
  84829. else if ((utf8[0] & 0xFC) == 0xF8 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80 && (utf8[3] & 0xC0) == 0x80 && (utf8[4] & 0xC0) == 0x80) {
  84830. if (utf8[0] == 0xF8 && (utf8[1] & 0xF8) == 0x80) /* overlong sequence check */
  84831. return 0;
  84832. return 5;
  84833. }
  84834. 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) {
  84835. if (utf8[0] == 0xFC && (utf8[1] & 0xFC) == 0x80) /* overlong sequence check */
  84836. return 0;
  84837. return 6;
  84838. }
  84839. else {
  84840. return 0;
  84841. }
  84842. }
  84843. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_name_is_legal(const char *name)
  84844. {
  84845. char c;
  84846. for(c = *name; c; c = *(++name))
  84847. if(c < 0x20 || c == 0x3d || c > 0x7d)
  84848. return false;
  84849. return true;
  84850. }
  84851. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_value_is_legal(const FLAC__byte *value, unsigned length)
  84852. {
  84853. if(length == (unsigned)(-1)) {
  84854. while(*value) {
  84855. unsigned n = utf8len_(value);
  84856. if(n == 0)
  84857. return false;
  84858. value += n;
  84859. }
  84860. }
  84861. else {
  84862. const FLAC__byte *end = value + length;
  84863. while(value < end) {
  84864. unsigned n = utf8len_(value);
  84865. if(n == 0)
  84866. return false;
  84867. value += n;
  84868. }
  84869. if(value != end)
  84870. return false;
  84871. }
  84872. return true;
  84873. }
  84874. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_is_legal(const FLAC__byte *entry, unsigned length)
  84875. {
  84876. const FLAC__byte *s, *end;
  84877. for(s = entry, end = s + length; s < end && *s != '='; s++) {
  84878. if(*s < 0x20 || *s > 0x7D)
  84879. return false;
  84880. }
  84881. if(s == end)
  84882. return false;
  84883. s++; /* skip '=' */
  84884. while(s < end) {
  84885. unsigned n = utf8len_(s);
  84886. if(n == 0)
  84887. return false;
  84888. s += n;
  84889. }
  84890. if(s != end)
  84891. return false;
  84892. return true;
  84893. }
  84894. FLAC_API FLAC__bool FLAC__format_cuesheet_is_legal(const FLAC__StreamMetadata_CueSheet *cue_sheet, FLAC__bool check_cd_da_subset, const char **violation)
  84895. {
  84896. unsigned i, j;
  84897. if(check_cd_da_subset) {
  84898. if(cue_sheet->lead_in < 2 * 44100) {
  84899. if(violation) *violation = "CD-DA cue sheet must have a lead-in length of at least 2 seconds";
  84900. return false;
  84901. }
  84902. if(cue_sheet->lead_in % 588 != 0) {
  84903. if(violation) *violation = "CD-DA cue sheet lead-in length must be evenly divisible by 588 samples";
  84904. return false;
  84905. }
  84906. }
  84907. if(cue_sheet->num_tracks == 0) {
  84908. if(violation) *violation = "cue sheet must have at least one track (the lead-out)";
  84909. return false;
  84910. }
  84911. if(check_cd_da_subset && cue_sheet->tracks[cue_sheet->num_tracks-1].number != 170) {
  84912. if(violation) *violation = "CD-DA cue sheet must have a lead-out track number 170 (0xAA)";
  84913. return false;
  84914. }
  84915. for(i = 0; i < cue_sheet->num_tracks; i++) {
  84916. if(cue_sheet->tracks[i].number == 0) {
  84917. if(violation) *violation = "cue sheet may not have a track number 0";
  84918. return false;
  84919. }
  84920. if(check_cd_da_subset) {
  84921. if(!((cue_sheet->tracks[i].number >= 1 && cue_sheet->tracks[i].number <= 99) || cue_sheet->tracks[i].number == 170)) {
  84922. if(violation) *violation = "CD-DA cue sheet track number must be 1-99 or 170";
  84923. return false;
  84924. }
  84925. }
  84926. if(check_cd_da_subset && cue_sheet->tracks[i].offset % 588 != 0) {
  84927. if(violation) {
  84928. if(i == cue_sheet->num_tracks-1) /* the lead-out track... */
  84929. *violation = "CD-DA cue sheet lead-out offset must be evenly divisible by 588 samples";
  84930. else
  84931. *violation = "CD-DA cue sheet track offset must be evenly divisible by 588 samples";
  84932. }
  84933. return false;
  84934. }
  84935. if(i < cue_sheet->num_tracks - 1) {
  84936. if(cue_sheet->tracks[i].num_indices == 0) {
  84937. if(violation) *violation = "cue sheet track must have at least one index point";
  84938. return false;
  84939. }
  84940. if(cue_sheet->tracks[i].indices[0].number > 1) {
  84941. if(violation) *violation = "cue sheet track's first index number must be 0 or 1";
  84942. return false;
  84943. }
  84944. }
  84945. for(j = 0; j < cue_sheet->tracks[i].num_indices; j++) {
  84946. if(check_cd_da_subset && cue_sheet->tracks[i].indices[j].offset % 588 != 0) {
  84947. if(violation) *violation = "CD-DA cue sheet track index offset must be evenly divisible by 588 samples";
  84948. return false;
  84949. }
  84950. if(j > 0) {
  84951. if(cue_sheet->tracks[i].indices[j].number != cue_sheet->tracks[i].indices[j-1].number + 1) {
  84952. if(violation) *violation = "cue sheet track index numbers must increase by 1";
  84953. return false;
  84954. }
  84955. }
  84956. }
  84957. }
  84958. return true;
  84959. }
  84960. FLAC_API FLAC__bool FLAC__format_picture_is_legal(const FLAC__StreamMetadata_Picture *picture, const char **violation)
  84961. {
  84962. char *p;
  84963. FLAC__byte *b;
  84964. for(p = picture->mime_type; *p; p++) {
  84965. if(*p < 0x20 || *p > 0x7e) {
  84966. if(violation) *violation = "MIME type string must contain only printable ASCII characters (0x20-0x7e)";
  84967. return false;
  84968. }
  84969. }
  84970. for(b = picture->description; *b; ) {
  84971. unsigned n = utf8len_(b);
  84972. if(n == 0) {
  84973. if(violation) *violation = "description string must be valid UTF-8";
  84974. return false;
  84975. }
  84976. b += n;
  84977. }
  84978. return true;
  84979. }
  84980. unsigned FLAC__format_get_max_rice_partition_order(unsigned blocksize, unsigned predictor_order)
  84981. {
  84982. return
  84983. FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(
  84984. FLAC__format_get_max_rice_partition_order_from_blocksize(blocksize),
  84985. blocksize,
  84986. predictor_order
  84987. );
  84988. }
  84989. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize(unsigned blocksize)
  84990. {
  84991. unsigned max_rice_partition_order = 0;
  84992. while(!(blocksize & 1)) {
  84993. max_rice_partition_order++;
  84994. blocksize >>= 1;
  84995. }
  84996. return min(FLAC__MAX_RICE_PARTITION_ORDER, max_rice_partition_order);
  84997. }
  84998. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(unsigned limit, unsigned blocksize, unsigned predictor_order)
  84999. {
  85000. unsigned max_rice_partition_order = limit;
  85001. while(max_rice_partition_order > 0 && (blocksize >> max_rice_partition_order) <= predictor_order)
  85002. max_rice_partition_order--;
  85003. FLAC__ASSERT(
  85004. (max_rice_partition_order == 0 && blocksize >= predictor_order) ||
  85005. (max_rice_partition_order > 0 && blocksize >> max_rice_partition_order > predictor_order)
  85006. );
  85007. return max_rice_partition_order;
  85008. }
  85009. void FLAC__format_entropy_coding_method_partitioned_rice_contents_init(FLAC__EntropyCodingMethod_PartitionedRiceContents *object)
  85010. {
  85011. FLAC__ASSERT(0 != object);
  85012. object->parameters = 0;
  85013. object->raw_bits = 0;
  85014. object->capacity_by_order = 0;
  85015. }
  85016. void FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(FLAC__EntropyCodingMethod_PartitionedRiceContents *object)
  85017. {
  85018. FLAC__ASSERT(0 != object);
  85019. if(0 != object->parameters)
  85020. free(object->parameters);
  85021. if(0 != object->raw_bits)
  85022. free(object->raw_bits);
  85023. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(object);
  85024. }
  85025. FLAC__bool FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(FLAC__EntropyCodingMethod_PartitionedRiceContents *object, unsigned max_partition_order)
  85026. {
  85027. FLAC__ASSERT(0 != object);
  85028. FLAC__ASSERT(object->capacity_by_order > 0 || (0 == object->parameters && 0 == object->raw_bits));
  85029. if(object->capacity_by_order < max_partition_order) {
  85030. if(0 == (object->parameters = (unsigned*)realloc(object->parameters, sizeof(unsigned)*(1 << max_partition_order))))
  85031. return false;
  85032. if(0 == (object->raw_bits = (unsigned*)realloc(object->raw_bits, sizeof(unsigned)*(1 << max_partition_order))))
  85033. return false;
  85034. memset(object->raw_bits, 0, sizeof(unsigned)*(1 << max_partition_order));
  85035. object->capacity_by_order = max_partition_order;
  85036. }
  85037. return true;
  85038. }
  85039. #endif
  85040. /*** End of inlined file: format.c ***/
  85041. /*** Start of inlined file: lpc_flac.c ***/
  85042. /*** Start of inlined file: juce_FlacHeader.h ***/
  85043. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  85044. // tasks..
  85045. #define VERSION "1.2.1"
  85046. #define FLAC__NO_DLL 1
  85047. #if JUCE_MSVC
  85048. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  85049. #endif
  85050. #if JUCE_MAC
  85051. #define FLAC__SYS_DARWIN 1
  85052. #endif
  85053. /*** End of inlined file: juce_FlacHeader.h ***/
  85054. #if JUCE_USE_FLAC
  85055. #if HAVE_CONFIG_H
  85056. # include <config.h>
  85057. #endif
  85058. #include <math.h>
  85059. /*** Start of inlined file: lpc.h ***/
  85060. #ifndef FLAC__PRIVATE__LPC_H
  85061. #define FLAC__PRIVATE__LPC_H
  85062. #ifdef HAVE_CONFIG_H
  85063. #include <config.h>
  85064. #endif
  85065. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  85066. void FLAC__lpc_window_data(const FLAC__int32 in[], const FLAC__real window[], FLAC__real out[], unsigned data_len);
  85067. void FLAC__lpc_compute_autocorrelation(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85068. #ifndef FLAC__NO_ASM
  85069. # ifdef FLAC__CPU_IA32
  85070. # ifdef FLAC__HAS_NASM
  85071. void FLAC__lpc_compute_autocorrelation_asm_ia32(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85072. void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_4(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85073. void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_8(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85074. void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_12(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85075. void FLAC__lpc_compute_autocorrelation_asm_ia32_3dnow(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85076. # endif
  85077. # endif
  85078. #endif
  85079. void FLAC__lpc_compute_lp_coefficients(const FLAC__real autoc[], unsigned *max_order, FLAC__real lp_coeff[][FLAC__MAX_LPC_ORDER], FLAC__double error[]);
  85080. int FLAC__lpc_quantize_coefficients(const FLAC__real lp_coeff[], unsigned order, unsigned precision, FLAC__int32 qlp_coeff[], int *shift);
  85081. 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[]);
  85082. 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[]);
  85083. #ifndef FLAC__NO_ASM
  85084. # ifdef FLAC__CPU_IA32
  85085. # ifdef FLAC__HAS_NASM
  85086. 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[]);
  85087. 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[]);
  85088. # endif
  85089. # endif
  85090. #endif
  85091. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  85092. 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[]);
  85093. 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[]);
  85094. #ifndef FLAC__NO_ASM
  85095. # ifdef FLAC__CPU_IA32
  85096. # ifdef FLAC__HAS_NASM
  85097. 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[]);
  85098. 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[]);
  85099. # endif /* FLAC__HAS_NASM */
  85100. # elif defined FLAC__CPU_PPC
  85101. 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[]);
  85102. 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[]);
  85103. # endif/* FLAC__CPU_IA32 || FLAC__CPU_PPC */
  85104. #endif /* FLAC__NO_ASM */
  85105. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  85106. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample(FLAC__double lpc_error, unsigned total_samples);
  85107. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(FLAC__double lpc_error, FLAC__double error_scale);
  85108. unsigned FLAC__lpc_compute_best_order(const FLAC__double lpc_error[], unsigned max_order, unsigned total_samples, unsigned overhead_bits_per_order);
  85109. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  85110. #endif
  85111. /*** End of inlined file: lpc.h ***/
  85112. #if defined DEBUG || defined FLAC__OVERFLOW_DETECT || defined FLAC__OVERFLOW_DETECT_VERBOSE
  85113. #include <stdio.h>
  85114. #endif
  85115. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  85116. #ifndef M_LN2
  85117. #define M_LN2 0.69314718055994530942
  85118. #endif
  85119. #define FLAC__LPC_UNROLLED_FILTER_LOOPS
  85120. void FLAC__lpc_window_data(const FLAC__int32 in[], const FLAC__real window[], FLAC__real out[], unsigned data_len)
  85121. {
  85122. unsigned i;
  85123. for(i = 0; i < data_len; i++)
  85124. out[i] = in[i] * window[i];
  85125. }
  85126. void FLAC__lpc_compute_autocorrelation(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[])
  85127. {
  85128. #if 0
  85129. FLAC__real d;
  85130. unsigned i;
  85131. FLAC__ASSERT(lag > 0);
  85132. FLAC__ASSERT(lag <= data_len);
  85133. while(lag--) {
  85134. for(i = lag, d = 0.0; i < data_len; i++)
  85135. d += data[i] * data[i - lag];
  85136. autoc[lag] = d;
  85137. }
  85138. #endif
  85139. FLAC__real d;
  85140. unsigned sample, coeff;
  85141. const unsigned limit = data_len - lag;
  85142. FLAC__ASSERT(lag > 0);
  85143. FLAC__ASSERT(lag <= data_len);
  85144. for(coeff = 0; coeff < lag; coeff++)
  85145. autoc[coeff] = 0.0;
  85146. for(sample = 0; sample <= limit; sample++) {
  85147. d = data[sample];
  85148. for(coeff = 0; coeff < lag; coeff++)
  85149. autoc[coeff] += d * data[sample+coeff];
  85150. }
  85151. for(; sample < data_len; sample++) {
  85152. d = data[sample];
  85153. for(coeff = 0; coeff < data_len - sample; coeff++)
  85154. autoc[coeff] += d * data[sample+coeff];
  85155. }
  85156. }
  85157. void FLAC__lpc_compute_lp_coefficients(const FLAC__real autoc[], unsigned *max_order, FLAC__real lp_coeff[][FLAC__MAX_LPC_ORDER], FLAC__double error[])
  85158. {
  85159. unsigned i, j;
  85160. FLAC__double r, err, ref[FLAC__MAX_LPC_ORDER], lpc[FLAC__MAX_LPC_ORDER];
  85161. FLAC__ASSERT(0 != max_order);
  85162. FLAC__ASSERT(0 < *max_order);
  85163. FLAC__ASSERT(*max_order <= FLAC__MAX_LPC_ORDER);
  85164. FLAC__ASSERT(autoc[0] != 0.0);
  85165. err = autoc[0];
  85166. for(i = 0; i < *max_order; i++) {
  85167. r = -autoc[i+1];
  85168. for(j = 0; j < i; j++)
  85169. r -= lpc[j] * autoc[i-j];
  85170. ref[i] = (r/=err);
  85171. lpc[i]=r;
  85172. for(j = 0; j < (i>>1); j++) {
  85173. FLAC__double tmp = lpc[j];
  85174. lpc[j] += r * lpc[i-1-j];
  85175. lpc[i-1-j] += r * tmp;
  85176. }
  85177. if(i & 1)
  85178. lpc[j] += lpc[j] * r;
  85179. err *= (1.0 - r * r);
  85180. for(j = 0; j <= i; j++)
  85181. lp_coeff[i][j] = (FLAC__real)(-lpc[j]); /* negate FIR filter coeff to get predictor coeff */
  85182. error[i] = err;
  85183. if(err == 0.0) {
  85184. *max_order = i+1;
  85185. return;
  85186. }
  85187. }
  85188. }
  85189. int FLAC__lpc_quantize_coefficients(const FLAC__real lp_coeff[], unsigned order, unsigned precision, FLAC__int32 qlp_coeff[], int *shift)
  85190. {
  85191. unsigned i;
  85192. FLAC__double cmax;
  85193. FLAC__int32 qmax, qmin;
  85194. FLAC__ASSERT(precision > 0);
  85195. FLAC__ASSERT(precision >= FLAC__MIN_QLP_COEFF_PRECISION);
  85196. precision--;
  85197. qmax = 1 << precision;
  85198. qmin = -qmax;
  85199. qmax--;
  85200. cmax = 0.0;
  85201. for(i = 0; i < order; i++) {
  85202. const FLAC__double d = fabs(lp_coeff[i]);
  85203. if(d > cmax)
  85204. cmax = d;
  85205. }
  85206. if(cmax <= 0.0) {
  85207. return 2;
  85208. }
  85209. else {
  85210. const int max_shiftlimit = (1 << (FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN-1)) - 1;
  85211. const int min_shiftlimit = -max_shiftlimit - 1;
  85212. int log2cmax;
  85213. (void)frexp(cmax, &log2cmax);
  85214. log2cmax--;
  85215. *shift = (int)precision - log2cmax - 1;
  85216. if(*shift > max_shiftlimit)
  85217. *shift = max_shiftlimit;
  85218. else if(*shift < min_shiftlimit)
  85219. return 1;
  85220. }
  85221. if(*shift >= 0) {
  85222. FLAC__double error = 0.0;
  85223. FLAC__int32 q;
  85224. for(i = 0; i < order; i++) {
  85225. error += lp_coeff[i] * (1 << *shift);
  85226. #if 1 /* unfortunately lround() is C99 */
  85227. if(error >= 0.0)
  85228. q = (FLAC__int32)(error + 0.5);
  85229. else
  85230. q = (FLAC__int32)(error - 0.5);
  85231. #else
  85232. q = lround(error);
  85233. #endif
  85234. #ifdef FLAC__OVERFLOW_DETECT
  85235. if(q > qmax+1) /* we expect q==qmax+1 occasionally due to rounding */
  85236. 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]);
  85237. else if(q < qmin)
  85238. 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]);
  85239. #endif
  85240. if(q > qmax)
  85241. q = qmax;
  85242. else if(q < qmin)
  85243. q = qmin;
  85244. error -= q;
  85245. qlp_coeff[i] = q;
  85246. }
  85247. }
  85248. else {
  85249. const int nshift = -(*shift);
  85250. FLAC__double error = 0.0;
  85251. FLAC__int32 q;
  85252. #ifdef DEBUG
  85253. fprintf(stderr,"FLAC__lpc_quantize_coefficients: negative shift=%d order=%u cmax=%f\n", *shift, order, cmax);
  85254. #endif
  85255. for(i = 0; i < order; i++) {
  85256. error += lp_coeff[i] / (1 << nshift);
  85257. #if 1 /* unfortunately lround() is C99 */
  85258. if(error >= 0.0)
  85259. q = (FLAC__int32)(error + 0.5);
  85260. else
  85261. q = (FLAC__int32)(error - 0.5);
  85262. #else
  85263. q = lround(error);
  85264. #endif
  85265. #ifdef FLAC__OVERFLOW_DETECT
  85266. if(q > qmax+1) /* we expect q==qmax+1 occasionally due to rounding */
  85267. 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]);
  85268. else if(q < qmin)
  85269. 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]);
  85270. #endif
  85271. if(q > qmax)
  85272. q = qmax;
  85273. else if(q < qmin)
  85274. q = qmin;
  85275. error -= q;
  85276. qlp_coeff[i] = q;
  85277. }
  85278. *shift = 0;
  85279. }
  85280. return 0;
  85281. }
  85282. 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[])
  85283. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  85284. {
  85285. FLAC__int64 sumo;
  85286. unsigned i, j;
  85287. FLAC__int32 sum;
  85288. const FLAC__int32 *history;
  85289. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  85290. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  85291. for(i=0;i<order;i++)
  85292. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  85293. fprintf(stderr,"\n");
  85294. #endif
  85295. FLAC__ASSERT(order > 0);
  85296. for(i = 0; i < data_len; i++) {
  85297. sumo = 0;
  85298. sum = 0;
  85299. history = data;
  85300. for(j = 0; j < order; j++) {
  85301. sum += qlp_coeff[j] * (*(--history));
  85302. sumo += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*history);
  85303. #if defined _MSC_VER
  85304. if(sumo > 2147483647I64 || sumo < -2147483648I64)
  85305. 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);
  85306. #else
  85307. if(sumo > 2147483647ll || sumo < -2147483648ll)
  85308. 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);
  85309. #endif
  85310. }
  85311. *(residual++) = *(data++) - (sum >> lp_quantization);
  85312. }
  85313. }
  85314. #else /* fully unrolled version for normal use */
  85315. {
  85316. int i;
  85317. FLAC__int32 sum;
  85318. FLAC__ASSERT(order > 0);
  85319. FLAC__ASSERT(order <= 32);
  85320. if(order <= 12) {
  85321. if(order > 8) {
  85322. if(order > 10) {
  85323. if(order == 12) {
  85324. for(i = 0; i < (int)data_len; i++) {
  85325. sum = 0;
  85326. sum += qlp_coeff[11] * data[i-12];
  85327. sum += qlp_coeff[10] * data[i-11];
  85328. sum += qlp_coeff[9] * data[i-10];
  85329. sum += qlp_coeff[8] * data[i-9];
  85330. sum += qlp_coeff[7] * data[i-8];
  85331. sum += qlp_coeff[6] * data[i-7];
  85332. sum += qlp_coeff[5] * data[i-6];
  85333. sum += qlp_coeff[4] * data[i-5];
  85334. sum += qlp_coeff[3] * data[i-4];
  85335. sum += qlp_coeff[2] * data[i-3];
  85336. sum += qlp_coeff[1] * data[i-2];
  85337. sum += qlp_coeff[0] * data[i-1];
  85338. residual[i] = data[i] - (sum >> lp_quantization);
  85339. }
  85340. }
  85341. else { /* order == 11 */
  85342. for(i = 0; i < (int)data_len; i++) {
  85343. sum = 0;
  85344. sum += qlp_coeff[10] * data[i-11];
  85345. sum += qlp_coeff[9] * data[i-10];
  85346. sum += qlp_coeff[8] * data[i-9];
  85347. sum += qlp_coeff[7] * data[i-8];
  85348. sum += qlp_coeff[6] * data[i-7];
  85349. sum += qlp_coeff[5] * data[i-6];
  85350. sum += qlp_coeff[4] * data[i-5];
  85351. sum += qlp_coeff[3] * data[i-4];
  85352. sum += qlp_coeff[2] * data[i-3];
  85353. sum += qlp_coeff[1] * data[i-2];
  85354. sum += qlp_coeff[0] * data[i-1];
  85355. residual[i] = data[i] - (sum >> lp_quantization);
  85356. }
  85357. }
  85358. }
  85359. else {
  85360. if(order == 10) {
  85361. for(i = 0; i < (int)data_len; i++) {
  85362. sum = 0;
  85363. sum += qlp_coeff[9] * data[i-10];
  85364. sum += qlp_coeff[8] * data[i-9];
  85365. sum += qlp_coeff[7] * data[i-8];
  85366. sum += qlp_coeff[6] * data[i-7];
  85367. sum += qlp_coeff[5] * data[i-6];
  85368. sum += qlp_coeff[4] * data[i-5];
  85369. sum += qlp_coeff[3] * data[i-4];
  85370. sum += qlp_coeff[2] * data[i-3];
  85371. sum += qlp_coeff[1] * data[i-2];
  85372. sum += qlp_coeff[0] * data[i-1];
  85373. residual[i] = data[i] - (sum >> lp_quantization);
  85374. }
  85375. }
  85376. else { /* order == 9 */
  85377. for(i = 0; i < (int)data_len; i++) {
  85378. sum = 0;
  85379. sum += qlp_coeff[8] * data[i-9];
  85380. sum += qlp_coeff[7] * data[i-8];
  85381. sum += qlp_coeff[6] * data[i-7];
  85382. sum += qlp_coeff[5] * data[i-6];
  85383. sum += qlp_coeff[4] * data[i-5];
  85384. sum += qlp_coeff[3] * data[i-4];
  85385. sum += qlp_coeff[2] * data[i-3];
  85386. sum += qlp_coeff[1] * data[i-2];
  85387. sum += qlp_coeff[0] * data[i-1];
  85388. residual[i] = data[i] - (sum >> lp_quantization);
  85389. }
  85390. }
  85391. }
  85392. }
  85393. else if(order > 4) {
  85394. if(order > 6) {
  85395. if(order == 8) {
  85396. for(i = 0; i < (int)data_len; i++) {
  85397. sum = 0;
  85398. sum += qlp_coeff[7] * data[i-8];
  85399. sum += qlp_coeff[6] * data[i-7];
  85400. sum += qlp_coeff[5] * data[i-6];
  85401. sum += qlp_coeff[4] * data[i-5];
  85402. sum += qlp_coeff[3] * data[i-4];
  85403. sum += qlp_coeff[2] * data[i-3];
  85404. sum += qlp_coeff[1] * data[i-2];
  85405. sum += qlp_coeff[0] * data[i-1];
  85406. residual[i] = data[i] - (sum >> lp_quantization);
  85407. }
  85408. }
  85409. else { /* order == 7 */
  85410. for(i = 0; i < (int)data_len; i++) {
  85411. sum = 0;
  85412. sum += qlp_coeff[6] * data[i-7];
  85413. sum += qlp_coeff[5] * data[i-6];
  85414. sum += qlp_coeff[4] * data[i-5];
  85415. sum += qlp_coeff[3] * data[i-4];
  85416. sum += qlp_coeff[2] * data[i-3];
  85417. sum += qlp_coeff[1] * data[i-2];
  85418. sum += qlp_coeff[0] * data[i-1];
  85419. residual[i] = data[i] - (sum >> lp_quantization);
  85420. }
  85421. }
  85422. }
  85423. else {
  85424. if(order == 6) {
  85425. for(i = 0; i < (int)data_len; i++) {
  85426. sum = 0;
  85427. sum += qlp_coeff[5] * data[i-6];
  85428. sum += qlp_coeff[4] * data[i-5];
  85429. sum += qlp_coeff[3] * data[i-4];
  85430. sum += qlp_coeff[2] * data[i-3];
  85431. sum += qlp_coeff[1] * data[i-2];
  85432. sum += qlp_coeff[0] * data[i-1];
  85433. residual[i] = data[i] - (sum >> lp_quantization);
  85434. }
  85435. }
  85436. else { /* order == 5 */
  85437. for(i = 0; i < (int)data_len; i++) {
  85438. sum = 0;
  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. }
  85448. }
  85449. else {
  85450. if(order > 2) {
  85451. if(order == 4) {
  85452. for(i = 0; i < (int)data_len; i++) {
  85453. sum = 0;
  85454. sum += qlp_coeff[3] * data[i-4];
  85455. sum += qlp_coeff[2] * data[i-3];
  85456. sum += qlp_coeff[1] * data[i-2];
  85457. sum += qlp_coeff[0] * data[i-1];
  85458. residual[i] = data[i] - (sum >> lp_quantization);
  85459. }
  85460. }
  85461. else { /* order == 3 */
  85462. for(i = 0; i < (int)data_len; i++) {
  85463. sum = 0;
  85464. sum += qlp_coeff[2] * data[i-3];
  85465. sum += qlp_coeff[1] * data[i-2];
  85466. sum += qlp_coeff[0] * data[i-1];
  85467. residual[i] = data[i] - (sum >> lp_quantization);
  85468. }
  85469. }
  85470. }
  85471. else {
  85472. if(order == 2) {
  85473. for(i = 0; i < (int)data_len; i++) {
  85474. sum = 0;
  85475. sum += qlp_coeff[1] * data[i-2];
  85476. sum += qlp_coeff[0] * data[i-1];
  85477. residual[i] = data[i] - (sum >> lp_quantization);
  85478. }
  85479. }
  85480. else { /* order == 1 */
  85481. for(i = 0; i < (int)data_len; i++)
  85482. residual[i] = data[i] - ((qlp_coeff[0] * data[i-1]) >> lp_quantization);
  85483. }
  85484. }
  85485. }
  85486. }
  85487. else { /* order > 12 */
  85488. for(i = 0; i < (int)data_len; i++) {
  85489. sum = 0;
  85490. switch(order) {
  85491. case 32: sum += qlp_coeff[31] * data[i-32];
  85492. case 31: sum += qlp_coeff[30] * data[i-31];
  85493. case 30: sum += qlp_coeff[29] * data[i-30];
  85494. case 29: sum += qlp_coeff[28] * data[i-29];
  85495. case 28: sum += qlp_coeff[27] * data[i-28];
  85496. case 27: sum += qlp_coeff[26] * data[i-27];
  85497. case 26: sum += qlp_coeff[25] * data[i-26];
  85498. case 25: sum += qlp_coeff[24] * data[i-25];
  85499. case 24: sum += qlp_coeff[23] * data[i-24];
  85500. case 23: sum += qlp_coeff[22] * data[i-23];
  85501. case 22: sum += qlp_coeff[21] * data[i-22];
  85502. case 21: sum += qlp_coeff[20] * data[i-21];
  85503. case 20: sum += qlp_coeff[19] * data[i-20];
  85504. case 19: sum += qlp_coeff[18] * data[i-19];
  85505. case 18: sum += qlp_coeff[17] * data[i-18];
  85506. case 17: sum += qlp_coeff[16] * data[i-17];
  85507. case 16: sum += qlp_coeff[15] * data[i-16];
  85508. case 15: sum += qlp_coeff[14] * data[i-15];
  85509. case 14: sum += qlp_coeff[13] * data[i-14];
  85510. case 13: sum += qlp_coeff[12] * data[i-13];
  85511. sum += qlp_coeff[11] * data[i-12];
  85512. sum += qlp_coeff[10] * data[i-11];
  85513. sum += qlp_coeff[ 9] * data[i-10];
  85514. sum += qlp_coeff[ 8] * data[i- 9];
  85515. sum += qlp_coeff[ 7] * data[i- 8];
  85516. sum += qlp_coeff[ 6] * data[i- 7];
  85517. sum += qlp_coeff[ 5] * data[i- 6];
  85518. sum += qlp_coeff[ 4] * data[i- 5];
  85519. sum += qlp_coeff[ 3] * data[i- 4];
  85520. sum += qlp_coeff[ 2] * data[i- 3];
  85521. sum += qlp_coeff[ 1] * data[i- 2];
  85522. sum += qlp_coeff[ 0] * data[i- 1];
  85523. }
  85524. residual[i] = data[i] - (sum >> lp_quantization);
  85525. }
  85526. }
  85527. }
  85528. #endif
  85529. 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[])
  85530. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  85531. {
  85532. unsigned i, j;
  85533. FLAC__int64 sum;
  85534. const FLAC__int32 *history;
  85535. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  85536. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  85537. for(i=0;i<order;i++)
  85538. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  85539. fprintf(stderr,"\n");
  85540. #endif
  85541. FLAC__ASSERT(order > 0);
  85542. for(i = 0; i < data_len; i++) {
  85543. sum = 0;
  85544. history = data;
  85545. for(j = 0; j < order; j++)
  85546. sum += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*(--history));
  85547. if(FLAC__bitmath_silog2_wide(sum >> lp_quantization) > 32) {
  85548. #if defined _MSC_VER
  85549. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: OVERFLOW, i=%u, sum=%I64d\n", i, sum >> lp_quantization);
  85550. #else
  85551. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: OVERFLOW, i=%u, sum=%lld\n", i, (long long)(sum >> lp_quantization));
  85552. #endif
  85553. break;
  85554. }
  85555. if(FLAC__bitmath_silog2_wide((FLAC__int64)(*data) - (sum >> lp_quantization)) > 32) {
  85556. #if defined _MSC_VER
  85557. 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));
  85558. #else
  85559. 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)));
  85560. #endif
  85561. break;
  85562. }
  85563. *(residual++) = *(data++) - (FLAC__int32)(sum >> lp_quantization);
  85564. }
  85565. }
  85566. #else /* fully unrolled version for normal use */
  85567. {
  85568. int i;
  85569. FLAC__int64 sum;
  85570. FLAC__ASSERT(order > 0);
  85571. FLAC__ASSERT(order <= 32);
  85572. if(order <= 12) {
  85573. if(order > 8) {
  85574. if(order > 10) {
  85575. if(order == 12) {
  85576. for(i = 0; i < (int)data_len; i++) {
  85577. sum = 0;
  85578. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  85579. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  85580. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85581. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85582. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85583. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85584. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85585. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85586. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85587. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85588. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85589. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85590. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85591. }
  85592. }
  85593. else { /* order == 11 */
  85594. for(i = 0; i < (int)data_len; i++) {
  85595. sum = 0;
  85596. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  85597. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85598. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85599. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85600. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85601. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85602. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85603. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85604. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85605. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85606. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85607. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85608. }
  85609. }
  85610. }
  85611. else {
  85612. if(order == 10) {
  85613. for(i = 0; i < (int)data_len; i++) {
  85614. sum = 0;
  85615. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85616. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85617. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85618. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85619. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85620. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85621. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85622. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85623. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85624. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85625. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85626. }
  85627. }
  85628. else { /* order == 9 */
  85629. for(i = 0; i < (int)data_len; i++) {
  85630. sum = 0;
  85631. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85632. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85633. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85634. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85635. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85636. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85637. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85638. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85639. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85640. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85641. }
  85642. }
  85643. }
  85644. }
  85645. else if(order > 4) {
  85646. if(order > 6) {
  85647. if(order == 8) {
  85648. for(i = 0; i < (int)data_len; i++) {
  85649. sum = 0;
  85650. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85651. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85652. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85653. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85654. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85655. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85656. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85657. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85658. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85659. }
  85660. }
  85661. else { /* order == 7 */
  85662. for(i = 0; i < (int)data_len; i++) {
  85663. sum = 0;
  85664. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85665. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85666. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85667. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85668. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85669. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85670. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85671. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85672. }
  85673. }
  85674. }
  85675. else {
  85676. if(order == 6) {
  85677. for(i = 0; i < (int)data_len; i++) {
  85678. sum = 0;
  85679. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85680. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85681. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85682. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85683. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85684. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85685. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85686. }
  85687. }
  85688. else { /* order == 5 */
  85689. for(i = 0; i < (int)data_len; i++) {
  85690. sum = 0;
  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. }
  85700. }
  85701. else {
  85702. if(order > 2) {
  85703. if(order == 4) {
  85704. for(i = 0; i < (int)data_len; i++) {
  85705. sum = 0;
  85706. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85707. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85708. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85709. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85710. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85711. }
  85712. }
  85713. else { /* order == 3 */
  85714. for(i = 0; i < (int)data_len; i++) {
  85715. sum = 0;
  85716. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85717. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85718. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85719. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85720. }
  85721. }
  85722. }
  85723. else {
  85724. if(order == 2) {
  85725. for(i = 0; i < (int)data_len; i++) {
  85726. sum = 0;
  85727. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85728. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85729. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85730. }
  85731. }
  85732. else { /* order == 1 */
  85733. for(i = 0; i < (int)data_len; i++)
  85734. residual[i] = data[i] - (FLAC__int32)((qlp_coeff[0] * (FLAC__int64)data[i-1]) >> lp_quantization);
  85735. }
  85736. }
  85737. }
  85738. }
  85739. else { /* order > 12 */
  85740. for(i = 0; i < (int)data_len; i++) {
  85741. sum = 0;
  85742. switch(order) {
  85743. case 32: sum += qlp_coeff[31] * (FLAC__int64)data[i-32];
  85744. case 31: sum += qlp_coeff[30] * (FLAC__int64)data[i-31];
  85745. case 30: sum += qlp_coeff[29] * (FLAC__int64)data[i-30];
  85746. case 29: sum += qlp_coeff[28] * (FLAC__int64)data[i-29];
  85747. case 28: sum += qlp_coeff[27] * (FLAC__int64)data[i-28];
  85748. case 27: sum += qlp_coeff[26] * (FLAC__int64)data[i-27];
  85749. case 26: sum += qlp_coeff[25] * (FLAC__int64)data[i-26];
  85750. case 25: sum += qlp_coeff[24] * (FLAC__int64)data[i-25];
  85751. case 24: sum += qlp_coeff[23] * (FLAC__int64)data[i-24];
  85752. case 23: sum += qlp_coeff[22] * (FLAC__int64)data[i-23];
  85753. case 22: sum += qlp_coeff[21] * (FLAC__int64)data[i-22];
  85754. case 21: sum += qlp_coeff[20] * (FLAC__int64)data[i-21];
  85755. case 20: sum += qlp_coeff[19] * (FLAC__int64)data[i-20];
  85756. case 19: sum += qlp_coeff[18] * (FLAC__int64)data[i-19];
  85757. case 18: sum += qlp_coeff[17] * (FLAC__int64)data[i-18];
  85758. case 17: sum += qlp_coeff[16] * (FLAC__int64)data[i-17];
  85759. case 16: sum += qlp_coeff[15] * (FLAC__int64)data[i-16];
  85760. case 15: sum += qlp_coeff[14] * (FLAC__int64)data[i-15];
  85761. case 14: sum += qlp_coeff[13] * (FLAC__int64)data[i-14];
  85762. case 13: sum += qlp_coeff[12] * (FLAC__int64)data[i-13];
  85763. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  85764. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  85765. sum += qlp_coeff[ 9] * (FLAC__int64)data[i-10];
  85766. sum += qlp_coeff[ 8] * (FLAC__int64)data[i- 9];
  85767. sum += qlp_coeff[ 7] * (FLAC__int64)data[i- 8];
  85768. sum += qlp_coeff[ 6] * (FLAC__int64)data[i- 7];
  85769. sum += qlp_coeff[ 5] * (FLAC__int64)data[i- 6];
  85770. sum += qlp_coeff[ 4] * (FLAC__int64)data[i- 5];
  85771. sum += qlp_coeff[ 3] * (FLAC__int64)data[i- 4];
  85772. sum += qlp_coeff[ 2] * (FLAC__int64)data[i- 3];
  85773. sum += qlp_coeff[ 1] * (FLAC__int64)data[i- 2];
  85774. sum += qlp_coeff[ 0] * (FLAC__int64)data[i- 1];
  85775. }
  85776. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85777. }
  85778. }
  85779. }
  85780. #endif
  85781. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  85782. 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[])
  85783. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  85784. {
  85785. FLAC__int64 sumo;
  85786. unsigned i, j;
  85787. FLAC__int32 sum;
  85788. const FLAC__int32 *r = residual, *history;
  85789. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  85790. fprintf(stderr,"FLAC__lpc_restore_signal: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  85791. for(i=0;i<order;i++)
  85792. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  85793. fprintf(stderr,"\n");
  85794. #endif
  85795. FLAC__ASSERT(order > 0);
  85796. for(i = 0; i < data_len; i++) {
  85797. sumo = 0;
  85798. sum = 0;
  85799. history = data;
  85800. for(j = 0; j < order; j++) {
  85801. sum += qlp_coeff[j] * (*(--history));
  85802. sumo += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*history);
  85803. #if defined _MSC_VER
  85804. if(sumo > 2147483647I64 || sumo < -2147483648I64)
  85805. 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);
  85806. #else
  85807. if(sumo > 2147483647ll || sumo < -2147483648ll)
  85808. 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);
  85809. #endif
  85810. }
  85811. *(data++) = *(r++) + (sum >> lp_quantization);
  85812. }
  85813. }
  85814. #else /* fully unrolled version for normal use */
  85815. {
  85816. int i;
  85817. FLAC__int32 sum;
  85818. FLAC__ASSERT(order > 0);
  85819. FLAC__ASSERT(order <= 32);
  85820. if(order <= 12) {
  85821. if(order > 8) {
  85822. if(order > 10) {
  85823. if(order == 12) {
  85824. for(i = 0; i < (int)data_len; i++) {
  85825. sum = 0;
  85826. sum += qlp_coeff[11] * data[i-12];
  85827. sum += qlp_coeff[10] * data[i-11];
  85828. sum += qlp_coeff[9] * data[i-10];
  85829. sum += qlp_coeff[8] * data[i-9];
  85830. sum += qlp_coeff[7] * data[i-8];
  85831. sum += qlp_coeff[6] * data[i-7];
  85832. sum += qlp_coeff[5] * data[i-6];
  85833. sum += qlp_coeff[4] * data[i-5];
  85834. sum += qlp_coeff[3] * data[i-4];
  85835. sum += qlp_coeff[2] * data[i-3];
  85836. sum += qlp_coeff[1] * data[i-2];
  85837. sum += qlp_coeff[0] * data[i-1];
  85838. data[i] = residual[i] + (sum >> lp_quantization);
  85839. }
  85840. }
  85841. else { /* order == 11 */
  85842. for(i = 0; i < (int)data_len; i++) {
  85843. sum = 0;
  85844. sum += qlp_coeff[10] * data[i-11];
  85845. sum += qlp_coeff[9] * data[i-10];
  85846. sum += qlp_coeff[8] * data[i-9];
  85847. sum += qlp_coeff[7] * data[i-8];
  85848. sum += qlp_coeff[6] * data[i-7];
  85849. sum += qlp_coeff[5] * data[i-6];
  85850. sum += qlp_coeff[4] * data[i-5];
  85851. sum += qlp_coeff[3] * data[i-4];
  85852. sum += qlp_coeff[2] * data[i-3];
  85853. sum += qlp_coeff[1] * data[i-2];
  85854. sum += qlp_coeff[0] * data[i-1];
  85855. data[i] = residual[i] + (sum >> lp_quantization);
  85856. }
  85857. }
  85858. }
  85859. else {
  85860. if(order == 10) {
  85861. for(i = 0; i < (int)data_len; i++) {
  85862. sum = 0;
  85863. sum += qlp_coeff[9] * data[i-10];
  85864. sum += qlp_coeff[8] * data[i-9];
  85865. sum += qlp_coeff[7] * data[i-8];
  85866. sum += qlp_coeff[6] * data[i-7];
  85867. sum += qlp_coeff[5] * data[i-6];
  85868. sum += qlp_coeff[4] * data[i-5];
  85869. sum += qlp_coeff[3] * data[i-4];
  85870. sum += qlp_coeff[2] * data[i-3];
  85871. sum += qlp_coeff[1] * data[i-2];
  85872. sum += qlp_coeff[0] * data[i-1];
  85873. data[i] = residual[i] + (sum >> lp_quantization);
  85874. }
  85875. }
  85876. else { /* order == 9 */
  85877. for(i = 0; i < (int)data_len; i++) {
  85878. sum = 0;
  85879. sum += qlp_coeff[8] * data[i-9];
  85880. sum += qlp_coeff[7] * data[i-8];
  85881. sum += qlp_coeff[6] * data[i-7];
  85882. sum += qlp_coeff[5] * data[i-6];
  85883. sum += qlp_coeff[4] * data[i-5];
  85884. sum += qlp_coeff[3] * data[i-4];
  85885. sum += qlp_coeff[2] * data[i-3];
  85886. sum += qlp_coeff[1] * data[i-2];
  85887. sum += qlp_coeff[0] * data[i-1];
  85888. data[i] = residual[i] + (sum >> lp_quantization);
  85889. }
  85890. }
  85891. }
  85892. }
  85893. else if(order > 4) {
  85894. if(order > 6) {
  85895. if(order == 8) {
  85896. for(i = 0; i < (int)data_len; i++) {
  85897. sum = 0;
  85898. sum += qlp_coeff[7] * data[i-8];
  85899. sum += qlp_coeff[6] * data[i-7];
  85900. sum += qlp_coeff[5] * data[i-6];
  85901. sum += qlp_coeff[4] * data[i-5];
  85902. sum += qlp_coeff[3] * data[i-4];
  85903. sum += qlp_coeff[2] * data[i-3];
  85904. sum += qlp_coeff[1] * data[i-2];
  85905. sum += qlp_coeff[0] * data[i-1];
  85906. data[i] = residual[i] + (sum >> lp_quantization);
  85907. }
  85908. }
  85909. else { /* order == 7 */
  85910. for(i = 0; i < (int)data_len; i++) {
  85911. sum = 0;
  85912. sum += qlp_coeff[6] * data[i-7];
  85913. sum += qlp_coeff[5] * data[i-6];
  85914. sum += qlp_coeff[4] * data[i-5];
  85915. sum += qlp_coeff[3] * data[i-4];
  85916. sum += qlp_coeff[2] * data[i-3];
  85917. sum += qlp_coeff[1] * data[i-2];
  85918. sum += qlp_coeff[0] * data[i-1];
  85919. data[i] = residual[i] + (sum >> lp_quantization);
  85920. }
  85921. }
  85922. }
  85923. else {
  85924. if(order == 6) {
  85925. for(i = 0; i < (int)data_len; i++) {
  85926. sum = 0;
  85927. sum += qlp_coeff[5] * data[i-6];
  85928. sum += qlp_coeff[4] * data[i-5];
  85929. sum += qlp_coeff[3] * data[i-4];
  85930. sum += qlp_coeff[2] * data[i-3];
  85931. sum += qlp_coeff[1] * data[i-2];
  85932. sum += qlp_coeff[0] * data[i-1];
  85933. data[i] = residual[i] + (sum >> lp_quantization);
  85934. }
  85935. }
  85936. else { /* order == 5 */
  85937. for(i = 0; i < (int)data_len; i++) {
  85938. sum = 0;
  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. }
  85948. }
  85949. else {
  85950. if(order > 2) {
  85951. if(order == 4) {
  85952. for(i = 0; i < (int)data_len; i++) {
  85953. sum = 0;
  85954. sum += qlp_coeff[3] * data[i-4];
  85955. sum += qlp_coeff[2] * data[i-3];
  85956. sum += qlp_coeff[1] * data[i-2];
  85957. sum += qlp_coeff[0] * data[i-1];
  85958. data[i] = residual[i] + (sum >> lp_quantization);
  85959. }
  85960. }
  85961. else { /* order == 3 */
  85962. for(i = 0; i < (int)data_len; i++) {
  85963. sum = 0;
  85964. sum += qlp_coeff[2] * data[i-3];
  85965. sum += qlp_coeff[1] * data[i-2];
  85966. sum += qlp_coeff[0] * data[i-1];
  85967. data[i] = residual[i] + (sum >> lp_quantization);
  85968. }
  85969. }
  85970. }
  85971. else {
  85972. if(order == 2) {
  85973. for(i = 0; i < (int)data_len; i++) {
  85974. sum = 0;
  85975. sum += qlp_coeff[1] * data[i-2];
  85976. sum += qlp_coeff[0] * data[i-1];
  85977. data[i] = residual[i] + (sum >> lp_quantization);
  85978. }
  85979. }
  85980. else { /* order == 1 */
  85981. for(i = 0; i < (int)data_len; i++)
  85982. data[i] = residual[i] + ((qlp_coeff[0] * data[i-1]) >> lp_quantization);
  85983. }
  85984. }
  85985. }
  85986. }
  85987. else { /* order > 12 */
  85988. for(i = 0; i < (int)data_len; i++) {
  85989. sum = 0;
  85990. switch(order) {
  85991. case 32: sum += qlp_coeff[31] * data[i-32];
  85992. case 31: sum += qlp_coeff[30] * data[i-31];
  85993. case 30: sum += qlp_coeff[29] * data[i-30];
  85994. case 29: sum += qlp_coeff[28] * data[i-29];
  85995. case 28: sum += qlp_coeff[27] * data[i-28];
  85996. case 27: sum += qlp_coeff[26] * data[i-27];
  85997. case 26: sum += qlp_coeff[25] * data[i-26];
  85998. case 25: sum += qlp_coeff[24] * data[i-25];
  85999. case 24: sum += qlp_coeff[23] * data[i-24];
  86000. case 23: sum += qlp_coeff[22] * data[i-23];
  86001. case 22: sum += qlp_coeff[21] * data[i-22];
  86002. case 21: sum += qlp_coeff[20] * data[i-21];
  86003. case 20: sum += qlp_coeff[19] * data[i-20];
  86004. case 19: sum += qlp_coeff[18] * data[i-19];
  86005. case 18: sum += qlp_coeff[17] * data[i-18];
  86006. case 17: sum += qlp_coeff[16] * data[i-17];
  86007. case 16: sum += qlp_coeff[15] * data[i-16];
  86008. case 15: sum += qlp_coeff[14] * data[i-15];
  86009. case 14: sum += qlp_coeff[13] * data[i-14];
  86010. case 13: sum += qlp_coeff[12] * data[i-13];
  86011. sum += qlp_coeff[11] * data[i-12];
  86012. sum += qlp_coeff[10] * data[i-11];
  86013. sum += qlp_coeff[ 9] * data[i-10];
  86014. sum += qlp_coeff[ 8] * data[i- 9];
  86015. sum += qlp_coeff[ 7] * data[i- 8];
  86016. sum += qlp_coeff[ 6] * data[i- 7];
  86017. sum += qlp_coeff[ 5] * data[i- 6];
  86018. sum += qlp_coeff[ 4] * data[i- 5];
  86019. sum += qlp_coeff[ 3] * data[i- 4];
  86020. sum += qlp_coeff[ 2] * data[i- 3];
  86021. sum += qlp_coeff[ 1] * data[i- 2];
  86022. sum += qlp_coeff[ 0] * data[i- 1];
  86023. }
  86024. data[i] = residual[i] + (sum >> lp_quantization);
  86025. }
  86026. }
  86027. }
  86028. #endif
  86029. 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[])
  86030. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  86031. {
  86032. unsigned i, j;
  86033. FLAC__int64 sum;
  86034. const FLAC__int32 *r = residual, *history;
  86035. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  86036. fprintf(stderr,"FLAC__lpc_restore_signal_wide: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  86037. for(i=0;i<order;i++)
  86038. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  86039. fprintf(stderr,"\n");
  86040. #endif
  86041. FLAC__ASSERT(order > 0);
  86042. for(i = 0; i < data_len; i++) {
  86043. sum = 0;
  86044. history = data;
  86045. for(j = 0; j < order; j++)
  86046. sum += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*(--history));
  86047. if(FLAC__bitmath_silog2_wide(sum >> lp_quantization) > 32) {
  86048. #ifdef _MSC_VER
  86049. fprintf(stderr,"FLAC__lpc_restore_signal_wide: OVERFLOW, i=%u, sum=%I64d\n", i, sum >> lp_quantization);
  86050. #else
  86051. fprintf(stderr,"FLAC__lpc_restore_signal_wide: OVERFLOW, i=%u, sum=%lld\n", i, (long long)(sum >> lp_quantization));
  86052. #endif
  86053. break;
  86054. }
  86055. if(FLAC__bitmath_silog2_wide((FLAC__int64)(*r) + (sum >> lp_quantization)) > 32) {
  86056. #ifdef _MSC_VER
  86057. 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));
  86058. #else
  86059. 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)));
  86060. #endif
  86061. break;
  86062. }
  86063. *(data++) = *(r++) + (FLAC__int32)(sum >> lp_quantization);
  86064. }
  86065. }
  86066. #else /* fully unrolled version for normal use */
  86067. {
  86068. int i;
  86069. FLAC__int64 sum;
  86070. FLAC__ASSERT(order > 0);
  86071. FLAC__ASSERT(order <= 32);
  86072. if(order <= 12) {
  86073. if(order > 8) {
  86074. if(order > 10) {
  86075. if(order == 12) {
  86076. for(i = 0; i < (int)data_len; i++) {
  86077. sum = 0;
  86078. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  86079. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  86080. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  86081. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86082. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86083. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86084. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86085. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86086. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86087. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86088. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86089. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86090. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86091. }
  86092. }
  86093. else { /* order == 11 */
  86094. for(i = 0; i < (int)data_len; i++) {
  86095. sum = 0;
  86096. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  86097. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  86098. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86099. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86100. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86101. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86102. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86103. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86104. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86105. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86106. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86107. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86108. }
  86109. }
  86110. }
  86111. else {
  86112. if(order == 10) {
  86113. for(i = 0; i < (int)data_len; i++) {
  86114. sum = 0;
  86115. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  86116. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86117. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86118. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86119. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86120. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86121. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86122. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86123. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86124. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86125. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86126. }
  86127. }
  86128. else { /* order == 9 */
  86129. for(i = 0; i < (int)data_len; i++) {
  86130. sum = 0;
  86131. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86132. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86133. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86134. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86135. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86136. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86137. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86138. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86139. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86140. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86141. }
  86142. }
  86143. }
  86144. }
  86145. else if(order > 4) {
  86146. if(order > 6) {
  86147. if(order == 8) {
  86148. for(i = 0; i < (int)data_len; i++) {
  86149. sum = 0;
  86150. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86151. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86152. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86153. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86154. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86155. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86156. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86157. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86158. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86159. }
  86160. }
  86161. else { /* order == 7 */
  86162. for(i = 0; i < (int)data_len; i++) {
  86163. sum = 0;
  86164. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86165. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86166. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86167. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86168. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86169. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86170. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86171. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86172. }
  86173. }
  86174. }
  86175. else {
  86176. if(order == 6) {
  86177. for(i = 0; i < (int)data_len; i++) {
  86178. sum = 0;
  86179. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86180. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86181. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86182. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86183. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86184. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86185. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86186. }
  86187. }
  86188. else { /* order == 5 */
  86189. for(i = 0; i < (int)data_len; i++) {
  86190. sum = 0;
  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. }
  86200. }
  86201. else {
  86202. if(order > 2) {
  86203. if(order == 4) {
  86204. for(i = 0; i < (int)data_len; i++) {
  86205. sum = 0;
  86206. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86207. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86208. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86209. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86210. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86211. }
  86212. }
  86213. else { /* order == 3 */
  86214. for(i = 0; i < (int)data_len; i++) {
  86215. sum = 0;
  86216. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86217. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86218. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86219. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86220. }
  86221. }
  86222. }
  86223. else {
  86224. if(order == 2) {
  86225. for(i = 0; i < (int)data_len; i++) {
  86226. sum = 0;
  86227. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86228. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86229. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86230. }
  86231. }
  86232. else { /* order == 1 */
  86233. for(i = 0; i < (int)data_len; i++)
  86234. data[i] = residual[i] + (FLAC__int32)((qlp_coeff[0] * (FLAC__int64)data[i-1]) >> lp_quantization);
  86235. }
  86236. }
  86237. }
  86238. }
  86239. else { /* order > 12 */
  86240. for(i = 0; i < (int)data_len; i++) {
  86241. sum = 0;
  86242. switch(order) {
  86243. case 32: sum += qlp_coeff[31] * (FLAC__int64)data[i-32];
  86244. case 31: sum += qlp_coeff[30] * (FLAC__int64)data[i-31];
  86245. case 30: sum += qlp_coeff[29] * (FLAC__int64)data[i-30];
  86246. case 29: sum += qlp_coeff[28] * (FLAC__int64)data[i-29];
  86247. case 28: sum += qlp_coeff[27] * (FLAC__int64)data[i-28];
  86248. case 27: sum += qlp_coeff[26] * (FLAC__int64)data[i-27];
  86249. case 26: sum += qlp_coeff[25] * (FLAC__int64)data[i-26];
  86250. case 25: sum += qlp_coeff[24] * (FLAC__int64)data[i-25];
  86251. case 24: sum += qlp_coeff[23] * (FLAC__int64)data[i-24];
  86252. case 23: sum += qlp_coeff[22] * (FLAC__int64)data[i-23];
  86253. case 22: sum += qlp_coeff[21] * (FLAC__int64)data[i-22];
  86254. case 21: sum += qlp_coeff[20] * (FLAC__int64)data[i-21];
  86255. case 20: sum += qlp_coeff[19] * (FLAC__int64)data[i-20];
  86256. case 19: sum += qlp_coeff[18] * (FLAC__int64)data[i-19];
  86257. case 18: sum += qlp_coeff[17] * (FLAC__int64)data[i-18];
  86258. case 17: sum += qlp_coeff[16] * (FLAC__int64)data[i-17];
  86259. case 16: sum += qlp_coeff[15] * (FLAC__int64)data[i-16];
  86260. case 15: sum += qlp_coeff[14] * (FLAC__int64)data[i-15];
  86261. case 14: sum += qlp_coeff[13] * (FLAC__int64)data[i-14];
  86262. case 13: sum += qlp_coeff[12] * (FLAC__int64)data[i-13];
  86263. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  86264. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  86265. sum += qlp_coeff[ 9] * (FLAC__int64)data[i-10];
  86266. sum += qlp_coeff[ 8] * (FLAC__int64)data[i- 9];
  86267. sum += qlp_coeff[ 7] * (FLAC__int64)data[i- 8];
  86268. sum += qlp_coeff[ 6] * (FLAC__int64)data[i- 7];
  86269. sum += qlp_coeff[ 5] * (FLAC__int64)data[i- 6];
  86270. sum += qlp_coeff[ 4] * (FLAC__int64)data[i- 5];
  86271. sum += qlp_coeff[ 3] * (FLAC__int64)data[i- 4];
  86272. sum += qlp_coeff[ 2] * (FLAC__int64)data[i- 3];
  86273. sum += qlp_coeff[ 1] * (FLAC__int64)data[i- 2];
  86274. sum += qlp_coeff[ 0] * (FLAC__int64)data[i- 1];
  86275. }
  86276. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86277. }
  86278. }
  86279. }
  86280. #endif
  86281. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  86282. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample(FLAC__double lpc_error, unsigned total_samples)
  86283. {
  86284. FLAC__double error_scale;
  86285. FLAC__ASSERT(total_samples > 0);
  86286. error_scale = 0.5 * M_LN2 * M_LN2 / (FLAC__double)total_samples;
  86287. return FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(lpc_error, error_scale);
  86288. }
  86289. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(FLAC__double lpc_error, FLAC__double error_scale)
  86290. {
  86291. if(lpc_error > 0.0) {
  86292. FLAC__double bps = (FLAC__double)0.5 * log(error_scale * lpc_error) / M_LN2;
  86293. if(bps >= 0.0)
  86294. return bps;
  86295. else
  86296. return 0.0;
  86297. }
  86298. else if(lpc_error < 0.0) { /* error should not be negative but can happen due to inadequate floating-point resolution */
  86299. return 1e32;
  86300. }
  86301. else {
  86302. return 0.0;
  86303. }
  86304. }
  86305. unsigned FLAC__lpc_compute_best_order(const FLAC__double lpc_error[], unsigned max_order, unsigned total_samples, unsigned overhead_bits_per_order)
  86306. {
  86307. 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 */
  86308. FLAC__double bits, best_bits, error_scale;
  86309. FLAC__ASSERT(max_order > 0);
  86310. FLAC__ASSERT(total_samples > 0);
  86311. error_scale = 0.5 * M_LN2 * M_LN2 / (FLAC__double)total_samples;
  86312. best_index = 0;
  86313. best_bits = (unsigned)(-1);
  86314. for(index = 0, order = 1; index < max_order; index++, order++) {
  86315. 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);
  86316. if(bits < best_bits) {
  86317. best_index = index;
  86318. best_bits = bits;
  86319. }
  86320. }
  86321. return best_index+1; /* +1 since index of lpc_error[] is order-1 */
  86322. }
  86323. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  86324. #endif
  86325. /*** End of inlined file: lpc_flac.c ***/
  86326. /*** Start of inlined file: md5.c ***/
  86327. /*** Start of inlined file: juce_FlacHeader.h ***/
  86328. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  86329. // tasks..
  86330. #define VERSION "1.2.1"
  86331. #define FLAC__NO_DLL 1
  86332. #if JUCE_MSVC
  86333. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  86334. #endif
  86335. #if JUCE_MAC
  86336. #define FLAC__SYS_DARWIN 1
  86337. #endif
  86338. /*** End of inlined file: juce_FlacHeader.h ***/
  86339. #if JUCE_USE_FLAC
  86340. #if HAVE_CONFIG_H
  86341. # include <config.h>
  86342. #endif
  86343. #include <stdlib.h> /* for malloc() */
  86344. #include <string.h> /* for memcpy() */
  86345. /*** Start of inlined file: md5.h ***/
  86346. #ifndef FLAC__PRIVATE__MD5_H
  86347. #define FLAC__PRIVATE__MD5_H
  86348. typedef struct {
  86349. FLAC__uint32 in[16];
  86350. FLAC__uint32 buf[4];
  86351. FLAC__uint32 bytes[2];
  86352. FLAC__byte *internal_buf;
  86353. size_t capacity;
  86354. } FLAC__MD5Context;
  86355. void FLAC__MD5Init(FLAC__MD5Context *context);
  86356. void FLAC__MD5Final(FLAC__byte digest[16], FLAC__MD5Context *context);
  86357. FLAC__bool FLAC__MD5Accumulate(FLAC__MD5Context *ctx, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample);
  86358. #endif
  86359. /*** End of inlined file: md5.h ***/
  86360. #ifndef FLaC__INLINE
  86361. #define FLaC__INLINE
  86362. #endif
  86363. #define F1(x, y, z) (z ^ (x & (y ^ z)))
  86364. #define F2(x, y, z) F1(z, x, y)
  86365. #define F3(x, y, z) (x ^ y ^ z)
  86366. #define F4(x, y, z) (y ^ (x | ~z))
  86367. #define MD5STEP(f,w,x,y,z,in,s) \
  86368. (w += f(x,y,z) + in, w = (w<<s | w>>(32-s)) + x)
  86369. static void FLAC__MD5Transform(FLAC__uint32 buf[4], FLAC__uint32 const in[16])
  86370. {
  86371. register FLAC__uint32 a, b, c, d;
  86372. a = buf[0];
  86373. b = buf[1];
  86374. c = buf[2];
  86375. d = buf[3];
  86376. MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
  86377. MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
  86378. MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
  86379. MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
  86380. MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
  86381. MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
  86382. MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
  86383. MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
  86384. MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
  86385. MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
  86386. MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
  86387. MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
  86388. MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
  86389. MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
  86390. MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
  86391. MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
  86392. MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
  86393. MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
  86394. MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
  86395. MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
  86396. MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
  86397. MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
  86398. MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
  86399. MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
  86400. MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
  86401. MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
  86402. MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
  86403. MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
  86404. MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
  86405. MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
  86406. MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
  86407. MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
  86408. MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
  86409. MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
  86410. MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
  86411. MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
  86412. MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
  86413. MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
  86414. MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
  86415. MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
  86416. MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
  86417. MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
  86418. MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
  86419. MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
  86420. MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
  86421. MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
  86422. MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
  86423. MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
  86424. MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
  86425. MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
  86426. MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
  86427. MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
  86428. MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
  86429. MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
  86430. MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
  86431. MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
  86432. MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
  86433. MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
  86434. MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
  86435. MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
  86436. MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
  86437. MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
  86438. MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
  86439. MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
  86440. buf[0] += a;
  86441. buf[1] += b;
  86442. buf[2] += c;
  86443. buf[3] += d;
  86444. }
  86445. #if WORDS_BIGENDIAN
  86446. //@@@@@@ OPT: use bswap/intrinsics
  86447. static void byteSwap(FLAC__uint32 *buf, unsigned words)
  86448. {
  86449. register FLAC__uint32 x;
  86450. do {
  86451. x = *buf;
  86452. x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff);
  86453. *buf++ = (x >> 16) | (x << 16);
  86454. } while (--words);
  86455. }
  86456. static void byteSwapX16(FLAC__uint32 *buf)
  86457. {
  86458. register FLAC__uint32 x;
  86459. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86460. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86461. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86462. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86463. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86464. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86465. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86466. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86467. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86468. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86469. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  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. }
  86476. #else
  86477. #define byteSwap(buf, words)
  86478. #define byteSwapX16(buf)
  86479. #endif
  86480. static void FLAC__MD5Update(FLAC__MD5Context *ctx, FLAC__byte const *buf, unsigned len)
  86481. {
  86482. FLAC__uint32 t;
  86483. t = ctx->bytes[0];
  86484. if ((ctx->bytes[0] = t + len) < t)
  86485. ctx->bytes[1]++; /* Carry from low to high */
  86486. t = 64 - (t & 0x3f); /* Space available in ctx->in (at least 1) */
  86487. if (t > len) {
  86488. memcpy((FLAC__byte *)ctx->in + 64 - t, buf, len);
  86489. return;
  86490. }
  86491. memcpy((FLAC__byte *)ctx->in + 64 - t, buf, t);
  86492. byteSwapX16(ctx->in);
  86493. FLAC__MD5Transform(ctx->buf, ctx->in);
  86494. buf += t;
  86495. len -= t;
  86496. while (len >= 64) {
  86497. memcpy(ctx->in, buf, 64);
  86498. byteSwapX16(ctx->in);
  86499. FLAC__MD5Transform(ctx->buf, ctx->in);
  86500. buf += 64;
  86501. len -= 64;
  86502. }
  86503. memcpy(ctx->in, buf, len);
  86504. }
  86505. void FLAC__MD5Init(FLAC__MD5Context *ctx)
  86506. {
  86507. ctx->buf[0] = 0x67452301;
  86508. ctx->buf[1] = 0xefcdab89;
  86509. ctx->buf[2] = 0x98badcfe;
  86510. ctx->buf[3] = 0x10325476;
  86511. ctx->bytes[0] = 0;
  86512. ctx->bytes[1] = 0;
  86513. ctx->internal_buf = 0;
  86514. ctx->capacity = 0;
  86515. }
  86516. void FLAC__MD5Final(FLAC__byte digest[16], FLAC__MD5Context *ctx)
  86517. {
  86518. int count = ctx->bytes[0] & 0x3f; /* Number of bytes in ctx->in */
  86519. FLAC__byte *p = (FLAC__byte *)ctx->in + count;
  86520. *p++ = 0x80;
  86521. count = 56 - 1 - count;
  86522. if (count < 0) { /* Padding forces an extra block */
  86523. memset(p, 0, count + 8);
  86524. byteSwapX16(ctx->in);
  86525. FLAC__MD5Transform(ctx->buf, ctx->in);
  86526. p = (FLAC__byte *)ctx->in;
  86527. count = 56;
  86528. }
  86529. memset(p, 0, count);
  86530. byteSwap(ctx->in, 14);
  86531. ctx->in[14] = ctx->bytes[0] << 3;
  86532. ctx->in[15] = ctx->bytes[1] << 3 | ctx->bytes[0] >> 29;
  86533. FLAC__MD5Transform(ctx->buf, ctx->in);
  86534. byteSwap(ctx->buf, 4);
  86535. memcpy(digest, ctx->buf, 16);
  86536. memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */
  86537. if(0 != ctx->internal_buf) {
  86538. free(ctx->internal_buf);
  86539. ctx->internal_buf = 0;
  86540. ctx->capacity = 0;
  86541. }
  86542. }
  86543. static void format_input_(FLAC__byte *buf, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample)
  86544. {
  86545. unsigned channel, sample;
  86546. register FLAC__int32 a_word;
  86547. register FLAC__byte *buf_ = buf;
  86548. #if WORDS_BIGENDIAN
  86549. #else
  86550. if(channels == 2 && bytes_per_sample == 2) {
  86551. FLAC__int16 *buf1_ = ((FLAC__int16*)buf_) + 1;
  86552. memcpy(buf_, signal[0], sizeof(FLAC__int32) * samples);
  86553. for(sample = 0; sample < samples; sample++, buf1_+=2)
  86554. *buf1_ = (FLAC__int16)signal[1][sample];
  86555. }
  86556. else if(channels == 1 && bytes_per_sample == 2) {
  86557. FLAC__int16 *buf1_ = (FLAC__int16*)buf_;
  86558. for(sample = 0; sample < samples; sample++)
  86559. *buf1_++ = (FLAC__int16)signal[0][sample];
  86560. }
  86561. else
  86562. #endif
  86563. if(bytes_per_sample == 2) {
  86564. if(channels == 2) {
  86565. for(sample = 0; sample < samples; sample++) {
  86566. a_word = signal[0][sample];
  86567. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86568. *buf_++ = (FLAC__byte)a_word;
  86569. a_word = signal[1][sample];
  86570. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86571. *buf_++ = (FLAC__byte)a_word;
  86572. }
  86573. }
  86574. else if(channels == 1) {
  86575. for(sample = 0; sample < samples; sample++) {
  86576. a_word = signal[0][sample];
  86577. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86578. *buf_++ = (FLAC__byte)a_word;
  86579. }
  86580. }
  86581. else {
  86582. for(sample = 0; sample < samples; sample++) {
  86583. for(channel = 0; channel < channels; channel++) {
  86584. a_word = signal[channel][sample];
  86585. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86586. *buf_++ = (FLAC__byte)a_word;
  86587. }
  86588. }
  86589. }
  86590. }
  86591. else if(bytes_per_sample == 3) {
  86592. if(channels == 2) {
  86593. for(sample = 0; sample < samples; sample++) {
  86594. a_word = signal[0][sample];
  86595. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86596. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86597. *buf_++ = (FLAC__byte)a_word;
  86598. a_word = signal[1][sample];
  86599. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86600. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86601. *buf_++ = (FLAC__byte)a_word;
  86602. }
  86603. }
  86604. else if(channels == 1) {
  86605. for(sample = 0; sample < samples; sample++) {
  86606. a_word = signal[0][sample];
  86607. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86608. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86609. *buf_++ = (FLAC__byte)a_word;
  86610. }
  86611. }
  86612. else {
  86613. for(sample = 0; sample < samples; sample++) {
  86614. for(channel = 0; channel < channels; channel++) {
  86615. a_word = signal[channel][sample];
  86616. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86617. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86618. *buf_++ = (FLAC__byte)a_word;
  86619. }
  86620. }
  86621. }
  86622. }
  86623. else if(bytes_per_sample == 1) {
  86624. if(channels == 2) {
  86625. for(sample = 0; sample < samples; sample++) {
  86626. a_word = signal[0][sample];
  86627. *buf_++ = (FLAC__byte)a_word;
  86628. a_word = signal[1][sample];
  86629. *buf_++ = (FLAC__byte)a_word;
  86630. }
  86631. }
  86632. else if(channels == 1) {
  86633. for(sample = 0; sample < samples; sample++) {
  86634. a_word = signal[0][sample];
  86635. *buf_++ = (FLAC__byte)a_word;
  86636. }
  86637. }
  86638. else {
  86639. for(sample = 0; sample < samples; sample++) {
  86640. for(channel = 0; channel < channels; channel++) {
  86641. a_word = signal[channel][sample];
  86642. *buf_++ = (FLAC__byte)a_word;
  86643. }
  86644. }
  86645. }
  86646. }
  86647. else { /* bytes_per_sample == 4, maybe optimize more later */
  86648. for(sample = 0; sample < samples; sample++) {
  86649. for(channel = 0; channel < channels; channel++) {
  86650. a_word = signal[channel][sample];
  86651. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86652. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86653. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86654. *buf_++ = (FLAC__byte)a_word;
  86655. }
  86656. }
  86657. }
  86658. }
  86659. FLAC__bool FLAC__MD5Accumulate(FLAC__MD5Context *ctx, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample)
  86660. {
  86661. const size_t bytes_needed = (size_t)channels * (size_t)samples * (size_t)bytes_per_sample;
  86662. if((size_t)channels > SIZE_MAX / (size_t)bytes_per_sample)
  86663. return false;
  86664. if((size_t)channels * (size_t)bytes_per_sample > SIZE_MAX / (size_t)samples)
  86665. return false;
  86666. if(ctx->capacity < bytes_needed) {
  86667. FLAC__byte *tmp = (FLAC__byte*)realloc(ctx->internal_buf, bytes_needed);
  86668. if(0 == tmp) {
  86669. free(ctx->internal_buf);
  86670. if(0 == (ctx->internal_buf = (FLAC__byte*)safe_malloc_(bytes_needed)))
  86671. return false;
  86672. }
  86673. ctx->internal_buf = tmp;
  86674. ctx->capacity = bytes_needed;
  86675. }
  86676. format_input_(ctx->internal_buf, signal, channels, samples, bytes_per_sample);
  86677. FLAC__MD5Update(ctx, ctx->internal_buf, bytes_needed);
  86678. return true;
  86679. }
  86680. #endif
  86681. /*** End of inlined file: md5.c ***/
  86682. /*** Start of inlined file: memory.c ***/
  86683. /*** Start of inlined file: juce_FlacHeader.h ***/
  86684. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  86685. // tasks..
  86686. #define VERSION "1.2.1"
  86687. #define FLAC__NO_DLL 1
  86688. #if JUCE_MSVC
  86689. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  86690. #endif
  86691. #if JUCE_MAC
  86692. #define FLAC__SYS_DARWIN 1
  86693. #endif
  86694. /*** End of inlined file: juce_FlacHeader.h ***/
  86695. #if JUCE_USE_FLAC
  86696. #if HAVE_CONFIG_H
  86697. # include <config.h>
  86698. #endif
  86699. /*** Start of inlined file: memory.h ***/
  86700. #ifndef FLAC__PRIVATE__MEMORY_H
  86701. #define FLAC__PRIVATE__MEMORY_H
  86702. #ifdef HAVE_CONFIG_H
  86703. #include <config.h>
  86704. #endif
  86705. #include <stdlib.h> /* for size_t */
  86706. void *FLAC__memory_alloc_aligned(size_t bytes, void **aligned_address);
  86707. FLAC__bool FLAC__memory_alloc_aligned_int32_array(unsigned elements, FLAC__int32 **unaligned_pointer, FLAC__int32 **aligned_pointer);
  86708. FLAC__bool FLAC__memory_alloc_aligned_uint32_array(unsigned elements, FLAC__uint32 **unaligned_pointer, FLAC__uint32 **aligned_pointer);
  86709. FLAC__bool FLAC__memory_alloc_aligned_uint64_array(unsigned elements, FLAC__uint64 **unaligned_pointer, FLAC__uint64 **aligned_pointer);
  86710. FLAC__bool FLAC__memory_alloc_aligned_unsigned_array(unsigned elements, unsigned **unaligned_pointer, unsigned **aligned_pointer);
  86711. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  86712. FLAC__bool FLAC__memory_alloc_aligned_real_array(unsigned elements, FLAC__real **unaligned_pointer, FLAC__real **aligned_pointer);
  86713. #endif
  86714. #endif
  86715. /*** End of inlined file: memory.h ***/
  86716. void *FLAC__memory_alloc_aligned(size_t bytes, void **aligned_address)
  86717. {
  86718. void *x;
  86719. FLAC__ASSERT(0 != aligned_address);
  86720. #ifdef FLAC__ALIGN_MALLOC_DATA
  86721. x = safe_malloc_add_2op_(bytes, /*+*/31);
  86722. #ifdef SIZEOF_VOIDP
  86723. #if SIZEOF_VOIDP == 4
  86724. *aligned_address = (void*)(((unsigned)x + 31) & -32);
  86725. #elif SIZEOF_VOIDP == 8
  86726. *aligned_address = (void*)(((FLAC__uint64)x + 31) & (FLAC__uint64)(-((FLAC__int64)32)));
  86727. #else
  86728. # error Unsupported sizeof(void*)
  86729. #endif
  86730. #else
  86731. if(sizeof(void*) == sizeof(unsigned))
  86732. *aligned_address = (void*)(((unsigned)x + 31) & -32);
  86733. else if(sizeof(void*) == sizeof(FLAC__uint64))
  86734. *aligned_address = (void*)(((FLAC__uint64)x + 31) & (FLAC__uint64)(-((FLAC__int64)32)));
  86735. else
  86736. return 0;
  86737. #endif
  86738. #else
  86739. x = safe_malloc_(bytes);
  86740. *aligned_address = x;
  86741. #endif
  86742. return x;
  86743. }
  86744. FLAC__bool FLAC__memory_alloc_aligned_int32_array(unsigned elements, FLAC__int32 **unaligned_pointer, FLAC__int32 **aligned_pointer)
  86745. {
  86746. FLAC__int32 *pu; /* unaligned pointer */
  86747. union { /* union needed to comply with C99 pointer aliasing rules */
  86748. FLAC__int32 *pa; /* aligned pointer */
  86749. void *pv; /* aligned pointer alias */
  86750. } u;
  86751. FLAC__ASSERT(elements > 0);
  86752. FLAC__ASSERT(0 != unaligned_pointer);
  86753. FLAC__ASSERT(0 != aligned_pointer);
  86754. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  86755. pu = (FLAC__int32*)FLAC__memory_alloc_aligned(sizeof(*pu) * (size_t)elements, &u.pv);
  86756. if(0 == pu) {
  86757. return false;
  86758. }
  86759. else {
  86760. if(*unaligned_pointer != 0)
  86761. free(*unaligned_pointer);
  86762. *unaligned_pointer = pu;
  86763. *aligned_pointer = u.pa;
  86764. return true;
  86765. }
  86766. }
  86767. FLAC__bool FLAC__memory_alloc_aligned_uint32_array(unsigned elements, FLAC__uint32 **unaligned_pointer, FLAC__uint32 **aligned_pointer)
  86768. {
  86769. FLAC__uint32 *pu; /* unaligned pointer */
  86770. union { /* union needed to comply with C99 pointer aliasing rules */
  86771. FLAC__uint32 *pa; /* aligned pointer */
  86772. void *pv; /* aligned pointer alias */
  86773. } u;
  86774. FLAC__ASSERT(elements > 0);
  86775. FLAC__ASSERT(0 != unaligned_pointer);
  86776. FLAC__ASSERT(0 != aligned_pointer);
  86777. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  86778. pu = (FLAC__uint32*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  86779. if(0 == pu) {
  86780. return false;
  86781. }
  86782. else {
  86783. if(*unaligned_pointer != 0)
  86784. free(*unaligned_pointer);
  86785. *unaligned_pointer = pu;
  86786. *aligned_pointer = u.pa;
  86787. return true;
  86788. }
  86789. }
  86790. FLAC__bool FLAC__memory_alloc_aligned_uint64_array(unsigned elements, FLAC__uint64 **unaligned_pointer, FLAC__uint64 **aligned_pointer)
  86791. {
  86792. FLAC__uint64 *pu; /* unaligned pointer */
  86793. union { /* union needed to comply with C99 pointer aliasing rules */
  86794. FLAC__uint64 *pa; /* aligned pointer */
  86795. void *pv; /* aligned pointer alias */
  86796. } u;
  86797. FLAC__ASSERT(elements > 0);
  86798. FLAC__ASSERT(0 != unaligned_pointer);
  86799. FLAC__ASSERT(0 != aligned_pointer);
  86800. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  86801. pu = (FLAC__uint64*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  86802. if(0 == pu) {
  86803. return false;
  86804. }
  86805. else {
  86806. if(*unaligned_pointer != 0)
  86807. free(*unaligned_pointer);
  86808. *unaligned_pointer = pu;
  86809. *aligned_pointer = u.pa;
  86810. return true;
  86811. }
  86812. }
  86813. FLAC__bool FLAC__memory_alloc_aligned_unsigned_array(unsigned elements, unsigned **unaligned_pointer, unsigned **aligned_pointer)
  86814. {
  86815. unsigned *pu; /* unaligned pointer */
  86816. union { /* union needed to comply with C99 pointer aliasing rules */
  86817. unsigned *pa; /* aligned pointer */
  86818. void *pv; /* aligned pointer alias */
  86819. } u;
  86820. FLAC__ASSERT(elements > 0);
  86821. FLAC__ASSERT(0 != unaligned_pointer);
  86822. FLAC__ASSERT(0 != aligned_pointer);
  86823. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  86824. pu = (unsigned*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  86825. if(0 == pu) {
  86826. return false;
  86827. }
  86828. else {
  86829. if(*unaligned_pointer != 0)
  86830. free(*unaligned_pointer);
  86831. *unaligned_pointer = pu;
  86832. *aligned_pointer = u.pa;
  86833. return true;
  86834. }
  86835. }
  86836. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  86837. FLAC__bool FLAC__memory_alloc_aligned_real_array(unsigned elements, FLAC__real **unaligned_pointer, FLAC__real **aligned_pointer)
  86838. {
  86839. FLAC__real *pu; /* unaligned pointer */
  86840. union { /* union needed to comply with C99 pointer aliasing rules */
  86841. FLAC__real *pa; /* aligned pointer */
  86842. void *pv; /* aligned pointer alias */
  86843. } u;
  86844. FLAC__ASSERT(elements > 0);
  86845. FLAC__ASSERT(0 != unaligned_pointer);
  86846. FLAC__ASSERT(0 != aligned_pointer);
  86847. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  86848. pu = (FLAC__real*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  86849. if(0 == pu) {
  86850. return false;
  86851. }
  86852. else {
  86853. if(*unaligned_pointer != 0)
  86854. free(*unaligned_pointer);
  86855. *unaligned_pointer = pu;
  86856. *aligned_pointer = u.pa;
  86857. return true;
  86858. }
  86859. }
  86860. #endif
  86861. #endif
  86862. /*** End of inlined file: memory.c ***/
  86863. /*** Start of inlined file: stream_decoder.c ***/
  86864. /*** Start of inlined file: juce_FlacHeader.h ***/
  86865. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  86866. // tasks..
  86867. #define VERSION "1.2.1"
  86868. #define FLAC__NO_DLL 1
  86869. #if JUCE_MSVC
  86870. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  86871. #endif
  86872. #if JUCE_MAC
  86873. #define FLAC__SYS_DARWIN 1
  86874. #endif
  86875. /*** End of inlined file: juce_FlacHeader.h ***/
  86876. #if JUCE_USE_FLAC
  86877. #if HAVE_CONFIG_H
  86878. # include <config.h>
  86879. #endif
  86880. #if defined _MSC_VER || defined __MINGW32__
  86881. #include <io.h> /* for _setmode() */
  86882. #include <fcntl.h> /* for _O_BINARY */
  86883. #endif
  86884. #if defined __CYGWIN__ || defined __EMX__
  86885. #include <io.h> /* for setmode(), O_BINARY */
  86886. #include <fcntl.h> /* for _O_BINARY */
  86887. #endif
  86888. #include <stdio.h>
  86889. #include <stdlib.h> /* for malloc() */
  86890. #include <string.h> /* for memset/memcpy() */
  86891. #include <sys/stat.h> /* for stat() */
  86892. #include <sys/types.h> /* for off_t */
  86893. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINGW32__
  86894. #if _MSC_VER <= 1600 || defined __BORLANDC__ /* @@@ [2G limit] */
  86895. #define fseeko fseek
  86896. #define ftello ftell
  86897. #endif
  86898. #endif
  86899. /*** Start of inlined file: stream_decoder.h ***/
  86900. #ifndef FLAC__PROTECTED__STREAM_DECODER_H
  86901. #define FLAC__PROTECTED__STREAM_DECODER_H
  86902. #if FLAC__HAS_OGG
  86903. #include "include/private/ogg_decoder_aspect.h"
  86904. #endif
  86905. typedef struct FLAC__StreamDecoderProtected {
  86906. FLAC__StreamDecoderState state;
  86907. unsigned channels;
  86908. FLAC__ChannelAssignment channel_assignment;
  86909. unsigned bits_per_sample;
  86910. unsigned sample_rate; /* in Hz */
  86911. unsigned blocksize; /* in samples (per channel) */
  86912. FLAC__bool md5_checking; /* if true, generate MD5 signature of decoded data and compare against signature in the STREAMINFO metadata block */
  86913. #if FLAC__HAS_OGG
  86914. FLAC__OggDecoderAspect ogg_decoder_aspect;
  86915. #endif
  86916. } FLAC__StreamDecoderProtected;
  86917. unsigned FLAC__stream_decoder_get_input_bytes_unconsumed(const FLAC__StreamDecoder *decoder);
  86918. #endif
  86919. /*** End of inlined file: stream_decoder.h ***/
  86920. #ifdef max
  86921. #undef max
  86922. #endif
  86923. #define max(a,b) ((a)>(b)?(a):(b))
  86924. #ifdef _MSC_VER
  86925. #define FLAC__U64L(x) x
  86926. #else
  86927. #define FLAC__U64L(x) x##LLU
  86928. #endif
  86929. FLAC_API int FLAC_API_SUPPORTS_OGG_FLAC =
  86930. #if FLAC__HAS_OGG
  86931. 1
  86932. #else
  86933. 0
  86934. #endif
  86935. ;
  86936. static FLAC__byte ID3V2_TAG_[3] = { 'I', 'D', '3' };
  86937. static void set_defaults_dec(FLAC__StreamDecoder *decoder);
  86938. static FILE *get_binary_stdin_(void);
  86939. static FLAC__bool allocate_output_(FLAC__StreamDecoder *decoder, unsigned size, unsigned channels);
  86940. static FLAC__bool has_id_filtered_(FLAC__StreamDecoder *decoder, FLAC__byte *id);
  86941. static FLAC__bool find_metadata_(FLAC__StreamDecoder *decoder);
  86942. static FLAC__bool read_metadata_(FLAC__StreamDecoder *decoder);
  86943. static FLAC__bool read_metadata_streaminfo_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length);
  86944. static FLAC__bool read_metadata_seektable_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length);
  86945. static FLAC__bool read_metadata_vorbiscomment_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_VorbisComment *obj);
  86946. static FLAC__bool read_metadata_cuesheet_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_CueSheet *obj);
  86947. static FLAC__bool read_metadata_picture_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_Picture *obj);
  86948. static FLAC__bool skip_id3v2_tag_(FLAC__StreamDecoder *decoder);
  86949. static FLAC__bool frame_sync_(FLAC__StreamDecoder *decoder);
  86950. static FLAC__bool read_frame_(FLAC__StreamDecoder *decoder, FLAC__bool *got_a_frame, FLAC__bool do_full_decode);
  86951. static FLAC__bool read_frame_header_(FLAC__StreamDecoder *decoder);
  86952. static FLAC__bool read_subframe_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
  86953. static FLAC__bool read_subframe_constant_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
  86954. static FLAC__bool read_subframe_fixed_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode);
  86955. static FLAC__bool read_subframe_lpc_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode);
  86956. static FLAC__bool read_subframe_verbatim_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
  86957. 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);
  86958. static FLAC__bool read_zero_padding_(FLAC__StreamDecoder *decoder);
  86959. static FLAC__bool read_callback_(FLAC__byte buffer[], size_t *bytes, void *client_data);
  86960. #if FLAC__HAS_OGG
  86961. static FLAC__StreamDecoderReadStatus read_callback_ogg_aspect_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes);
  86962. static FLAC__OggDecoderAspectReadStatus read_callback_proxy_(const void *void_decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  86963. #endif
  86964. static FLAC__StreamDecoderWriteStatus write_audio_frame_to_client_(FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[]);
  86965. static void send_error_to_client_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status);
  86966. static FLAC__bool seek_to_absolute_sample_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample);
  86967. #if FLAC__HAS_OGG
  86968. static FLAC__bool seek_to_absolute_sample_ogg_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample);
  86969. #endif
  86970. static FLAC__StreamDecoderReadStatus file_read_callback_dec (const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  86971. static FLAC__StreamDecoderSeekStatus file_seek_callback_dec (const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  86972. static FLAC__StreamDecoderTellStatus file_tell_callback_dec (const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  86973. static FLAC__StreamDecoderLengthStatus file_length_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
  86974. static FLAC__bool file_eof_callback_(const FLAC__StreamDecoder *decoder, void *client_data);
  86975. typedef struct FLAC__StreamDecoderPrivate {
  86976. #if FLAC__HAS_OGG
  86977. FLAC__bool is_ogg;
  86978. #endif
  86979. FLAC__StreamDecoderReadCallback read_callback;
  86980. FLAC__StreamDecoderSeekCallback seek_callback;
  86981. FLAC__StreamDecoderTellCallback tell_callback;
  86982. FLAC__StreamDecoderLengthCallback length_callback;
  86983. FLAC__StreamDecoderEofCallback eof_callback;
  86984. FLAC__StreamDecoderWriteCallback write_callback;
  86985. FLAC__StreamDecoderMetadataCallback metadata_callback;
  86986. FLAC__StreamDecoderErrorCallback error_callback;
  86987. 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[]);
  86988. 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[]);
  86989. 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[]);
  86990. 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[]);
  86991. FLAC__bool (*local_bitreader_read_rice_signed_block)(FLAC__BitReader *br, int* vals, unsigned nvals, unsigned parameter);
  86992. void *client_data;
  86993. FILE *file; /* only used if FLAC__stream_decoder_init_file()/FLAC__stream_decoder_init_file() called, else NULL */
  86994. FLAC__BitReader *input;
  86995. FLAC__int32 *output[FLAC__MAX_CHANNELS];
  86996. FLAC__int32 *residual[FLAC__MAX_CHANNELS]; /* WATCHOUT: these are the aligned pointers; the real pointers that should be free()'d are residual_unaligned[] below */
  86997. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents[FLAC__MAX_CHANNELS];
  86998. unsigned output_capacity, output_channels;
  86999. FLAC__uint32 fixed_block_size, next_fixed_block_size;
  87000. FLAC__uint64 samples_decoded;
  87001. FLAC__bool has_stream_info, has_seek_table;
  87002. FLAC__StreamMetadata stream_info;
  87003. FLAC__StreamMetadata seek_table;
  87004. FLAC__bool metadata_filter[128]; /* MAGIC number 128 == total number of metadata block types == 1 << 7 */
  87005. FLAC__byte *metadata_filter_ids;
  87006. size_t metadata_filter_ids_count, metadata_filter_ids_capacity; /* units for both are IDs, not bytes */
  87007. FLAC__Frame frame;
  87008. FLAC__bool cached; /* true if there is a byte in lookahead */
  87009. FLAC__CPUInfo cpuinfo;
  87010. FLAC__byte header_warmup[2]; /* contains the sync code and reserved bits */
  87011. FLAC__byte lookahead; /* temp storage when we need to look ahead one byte in the stream */
  87012. FLAC__int32 *residual_unaligned[FLAC__MAX_CHANNELS];
  87013. 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 */
  87014. FLAC__bool internal_reset_hack; /* used only during init() so we can call reset to set up the decoder without rewinding the input */
  87015. FLAC__bool is_seeking;
  87016. FLAC__MD5Context md5context;
  87017. FLAC__byte computed_md5sum[16]; /* this is the sum we computed from the decoded data */
  87018. FLAC__Frame last_frame; /* holds the info of the last frame we seeked to */
  87019. FLAC__uint64 first_frame_offset; /* hint to the seek routine of where in the stream the first audio frame starts */
  87020. FLAC__uint64 target_sample;
  87021. unsigned unparseable_frame_count; /* used to tell whether we're decoding a future version of FLAC or just got a bad sync */
  87022. #if FLAC__HAS_OGG
  87023. FLAC__bool got_a_frame; /* hack needed in Ogg FLAC seek routine to check when process_single() actually writes a frame */
  87024. #endif
  87025. } FLAC__StreamDecoderPrivate;
  87026. FLAC_API const char * const FLAC__StreamDecoderStateString[] = {
  87027. "FLAC__STREAM_DECODER_SEARCH_FOR_METADATA",
  87028. "FLAC__STREAM_DECODER_READ_METADATA",
  87029. "FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC",
  87030. "FLAC__STREAM_DECODER_READ_FRAME",
  87031. "FLAC__STREAM_DECODER_END_OF_STREAM",
  87032. "FLAC__STREAM_DECODER_OGG_ERROR",
  87033. "FLAC__STREAM_DECODER_SEEK_ERROR",
  87034. "FLAC__STREAM_DECODER_ABORTED",
  87035. "FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR",
  87036. "FLAC__STREAM_DECODER_UNINITIALIZED"
  87037. };
  87038. FLAC_API const char * const FLAC__StreamDecoderInitStatusString[] = {
  87039. "FLAC__STREAM_DECODER_INIT_STATUS_OK",
  87040. "FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER",
  87041. "FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS",
  87042. "FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR",
  87043. "FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE",
  87044. "FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED"
  87045. };
  87046. FLAC_API const char * const FLAC__StreamDecoderReadStatusString[] = {
  87047. "FLAC__STREAM_DECODER_READ_STATUS_CONTINUE",
  87048. "FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM",
  87049. "FLAC__STREAM_DECODER_READ_STATUS_ABORT"
  87050. };
  87051. FLAC_API const char * const FLAC__StreamDecoderSeekStatusString[] = {
  87052. "FLAC__STREAM_DECODER_SEEK_STATUS_OK",
  87053. "FLAC__STREAM_DECODER_SEEK_STATUS_ERROR",
  87054. "FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED"
  87055. };
  87056. FLAC_API const char * const FLAC__StreamDecoderTellStatusString[] = {
  87057. "FLAC__STREAM_DECODER_TELL_STATUS_OK",
  87058. "FLAC__STREAM_DECODER_TELL_STATUS_ERROR",
  87059. "FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED"
  87060. };
  87061. FLAC_API const char * const FLAC__StreamDecoderLengthStatusString[] = {
  87062. "FLAC__STREAM_DECODER_LENGTH_STATUS_OK",
  87063. "FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR",
  87064. "FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED"
  87065. };
  87066. FLAC_API const char * const FLAC__StreamDecoderWriteStatusString[] = {
  87067. "FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE",
  87068. "FLAC__STREAM_DECODER_WRITE_STATUS_ABORT"
  87069. };
  87070. FLAC_API const char * const FLAC__StreamDecoderErrorStatusString[] = {
  87071. "FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC",
  87072. "FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER",
  87073. "FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH",
  87074. "FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM"
  87075. };
  87076. FLAC_API FLAC__StreamDecoder *FLAC__stream_decoder_new(void)
  87077. {
  87078. FLAC__StreamDecoder *decoder;
  87079. unsigned i;
  87080. FLAC__ASSERT(sizeof(int) >= 4); /* we want to die right away if this is not true */
  87081. decoder = (FLAC__StreamDecoder*)calloc(1, sizeof(FLAC__StreamDecoder));
  87082. if(decoder == 0) {
  87083. return 0;
  87084. }
  87085. decoder->protected_ = (FLAC__StreamDecoderProtected*)calloc(1, sizeof(FLAC__StreamDecoderProtected));
  87086. if(decoder->protected_ == 0) {
  87087. free(decoder);
  87088. return 0;
  87089. }
  87090. decoder->private_ = (FLAC__StreamDecoderPrivate*)calloc(1, sizeof(FLAC__StreamDecoderPrivate));
  87091. if(decoder->private_ == 0) {
  87092. free(decoder->protected_);
  87093. free(decoder);
  87094. return 0;
  87095. }
  87096. decoder->private_->input = FLAC__bitreader_new();
  87097. if(decoder->private_->input == 0) {
  87098. free(decoder->private_);
  87099. free(decoder->protected_);
  87100. free(decoder);
  87101. return 0;
  87102. }
  87103. decoder->private_->metadata_filter_ids_capacity = 16;
  87104. if(0 == (decoder->private_->metadata_filter_ids = (FLAC__byte*)malloc((FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8) * decoder->private_->metadata_filter_ids_capacity))) {
  87105. FLAC__bitreader_delete(decoder->private_->input);
  87106. free(decoder->private_);
  87107. free(decoder->protected_);
  87108. free(decoder);
  87109. return 0;
  87110. }
  87111. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  87112. decoder->private_->output[i] = 0;
  87113. decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0;
  87114. }
  87115. decoder->private_->output_capacity = 0;
  87116. decoder->private_->output_channels = 0;
  87117. decoder->private_->has_seek_table = false;
  87118. for(i = 0; i < FLAC__MAX_CHANNELS; i++)
  87119. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&decoder->private_->partitioned_rice_contents[i]);
  87120. decoder->private_->file = 0;
  87121. set_defaults_dec(decoder);
  87122. decoder->protected_->state = FLAC__STREAM_DECODER_UNINITIALIZED;
  87123. return decoder;
  87124. }
  87125. FLAC_API void FLAC__stream_decoder_delete(FLAC__StreamDecoder *decoder)
  87126. {
  87127. unsigned i;
  87128. FLAC__ASSERT(0 != decoder);
  87129. FLAC__ASSERT(0 != decoder->protected_);
  87130. FLAC__ASSERT(0 != decoder->private_);
  87131. FLAC__ASSERT(0 != decoder->private_->input);
  87132. (void)FLAC__stream_decoder_finish(decoder);
  87133. if(0 != decoder->private_->metadata_filter_ids)
  87134. free(decoder->private_->metadata_filter_ids);
  87135. FLAC__bitreader_delete(decoder->private_->input);
  87136. for(i = 0; i < FLAC__MAX_CHANNELS; i++)
  87137. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&decoder->private_->partitioned_rice_contents[i]);
  87138. free(decoder->private_);
  87139. free(decoder->protected_);
  87140. free(decoder);
  87141. }
  87142. static FLAC__StreamDecoderInitStatus init_stream_internal_dec(
  87143. FLAC__StreamDecoder *decoder,
  87144. FLAC__StreamDecoderReadCallback read_callback,
  87145. FLAC__StreamDecoderSeekCallback seek_callback,
  87146. FLAC__StreamDecoderTellCallback tell_callback,
  87147. FLAC__StreamDecoderLengthCallback length_callback,
  87148. FLAC__StreamDecoderEofCallback eof_callback,
  87149. FLAC__StreamDecoderWriteCallback write_callback,
  87150. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87151. FLAC__StreamDecoderErrorCallback error_callback,
  87152. void *client_data,
  87153. FLAC__bool is_ogg
  87154. )
  87155. {
  87156. FLAC__ASSERT(0 != decoder);
  87157. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87158. return FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED;
  87159. #if !FLAC__HAS_OGG
  87160. if(is_ogg)
  87161. return FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER;
  87162. #endif
  87163. if(
  87164. 0 == read_callback ||
  87165. 0 == write_callback ||
  87166. 0 == error_callback ||
  87167. (seek_callback && (0 == tell_callback || 0 == length_callback || 0 == eof_callback))
  87168. )
  87169. return FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS;
  87170. #if FLAC__HAS_OGG
  87171. decoder->private_->is_ogg = is_ogg;
  87172. if(is_ogg && !FLAC__ogg_decoder_aspect_init(&decoder->protected_->ogg_decoder_aspect))
  87173. return decoder->protected_->state = FLAC__STREAM_DECODER_OGG_ERROR;
  87174. #endif
  87175. FLAC__cpu_info(&decoder->private_->cpuinfo);
  87176. decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal;
  87177. decoder->private_->local_lpc_restore_signal_64bit = FLAC__lpc_restore_signal_wide;
  87178. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal;
  87179. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal;
  87180. decoder->private_->local_bitreader_read_rice_signed_block = FLAC__bitreader_read_rice_signed_block;
  87181. #ifndef FLAC__NO_ASM
  87182. if(decoder->private_->cpuinfo.use_asm) {
  87183. #ifdef FLAC__CPU_IA32
  87184. FLAC__ASSERT(decoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_IA32);
  87185. #ifdef FLAC__HAS_NASM
  87186. #if 1 /*@@@@@@ OPT: not clearly faster, needs more testing */
  87187. if(decoder->private_->cpuinfo.data.ia32.bswap)
  87188. decoder->private_->local_bitreader_read_rice_signed_block = FLAC__bitreader_read_rice_signed_block_asm_ia32_bswap;
  87189. #endif
  87190. if(decoder->private_->cpuinfo.data.ia32.mmx) {
  87191. decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal_asm_ia32;
  87192. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ia32_mmx;
  87193. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ia32_mmx;
  87194. }
  87195. else {
  87196. decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal_asm_ia32;
  87197. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ia32;
  87198. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ia32;
  87199. }
  87200. #endif
  87201. #elif defined FLAC__CPU_PPC
  87202. FLAC__ASSERT(decoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_PPC);
  87203. if(decoder->private_->cpuinfo.data.ppc.altivec) {
  87204. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ppc_altivec_16;
  87205. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ppc_altivec_16_order8;
  87206. }
  87207. #endif
  87208. }
  87209. #endif
  87210. if(!FLAC__bitreader_init(decoder->private_->input, decoder->private_->cpuinfo, read_callback_, decoder)) {
  87211. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87212. return FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR;
  87213. }
  87214. decoder->private_->read_callback = read_callback;
  87215. decoder->private_->seek_callback = seek_callback;
  87216. decoder->private_->tell_callback = tell_callback;
  87217. decoder->private_->length_callback = length_callback;
  87218. decoder->private_->eof_callback = eof_callback;
  87219. decoder->private_->write_callback = write_callback;
  87220. decoder->private_->metadata_callback = metadata_callback;
  87221. decoder->private_->error_callback = error_callback;
  87222. decoder->private_->client_data = client_data;
  87223. decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size = 0;
  87224. decoder->private_->samples_decoded = 0;
  87225. decoder->private_->has_stream_info = false;
  87226. decoder->private_->cached = false;
  87227. decoder->private_->do_md5_checking = decoder->protected_->md5_checking;
  87228. decoder->private_->is_seeking = false;
  87229. decoder->private_->internal_reset_hack = true; /* so the following reset does not try to rewind the input */
  87230. if(!FLAC__stream_decoder_reset(decoder)) {
  87231. return FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR;
  87232. }
  87233. return FLAC__STREAM_DECODER_INIT_STATUS_OK;
  87234. }
  87235. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_stream(
  87236. FLAC__StreamDecoder *decoder,
  87237. FLAC__StreamDecoderReadCallback read_callback,
  87238. FLAC__StreamDecoderSeekCallback seek_callback,
  87239. FLAC__StreamDecoderTellCallback tell_callback,
  87240. FLAC__StreamDecoderLengthCallback length_callback,
  87241. FLAC__StreamDecoderEofCallback eof_callback,
  87242. FLAC__StreamDecoderWriteCallback write_callback,
  87243. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87244. FLAC__StreamDecoderErrorCallback error_callback,
  87245. void *client_data
  87246. )
  87247. {
  87248. return init_stream_internal_dec(
  87249. decoder,
  87250. read_callback,
  87251. seek_callback,
  87252. tell_callback,
  87253. length_callback,
  87254. eof_callback,
  87255. write_callback,
  87256. metadata_callback,
  87257. error_callback,
  87258. client_data,
  87259. false
  87260. );
  87261. }
  87262. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_stream(
  87263. FLAC__StreamDecoder *decoder,
  87264. FLAC__StreamDecoderReadCallback read_callback,
  87265. FLAC__StreamDecoderSeekCallback seek_callback,
  87266. FLAC__StreamDecoderTellCallback tell_callback,
  87267. FLAC__StreamDecoderLengthCallback length_callback,
  87268. FLAC__StreamDecoderEofCallback eof_callback,
  87269. FLAC__StreamDecoderWriteCallback write_callback,
  87270. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87271. FLAC__StreamDecoderErrorCallback error_callback,
  87272. void *client_data
  87273. )
  87274. {
  87275. return init_stream_internal_dec(
  87276. decoder,
  87277. read_callback,
  87278. seek_callback,
  87279. tell_callback,
  87280. length_callback,
  87281. eof_callback,
  87282. write_callback,
  87283. metadata_callback,
  87284. error_callback,
  87285. client_data,
  87286. true
  87287. );
  87288. }
  87289. static FLAC__StreamDecoderInitStatus init_FILE_internal_(
  87290. FLAC__StreamDecoder *decoder,
  87291. FILE *file,
  87292. FLAC__StreamDecoderWriteCallback write_callback,
  87293. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87294. FLAC__StreamDecoderErrorCallback error_callback,
  87295. void *client_data,
  87296. FLAC__bool is_ogg
  87297. )
  87298. {
  87299. FLAC__ASSERT(0 != decoder);
  87300. FLAC__ASSERT(0 != file);
  87301. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87302. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED);
  87303. if(0 == write_callback || 0 == error_callback)
  87304. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS);
  87305. if(file == stdin)
  87306. file = get_binary_stdin_(); /* just to be safe */
  87307. decoder->private_->file = file;
  87308. return init_stream_internal_dec(
  87309. decoder,
  87310. file_read_callback_dec,
  87311. decoder->private_->file == stdin? 0: file_seek_callback_dec,
  87312. decoder->private_->file == stdin? 0: file_tell_callback_dec,
  87313. decoder->private_->file == stdin? 0: file_length_callback_,
  87314. file_eof_callback_,
  87315. write_callback,
  87316. metadata_callback,
  87317. error_callback,
  87318. client_data,
  87319. is_ogg
  87320. );
  87321. }
  87322. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_FILE(
  87323. FLAC__StreamDecoder *decoder,
  87324. FILE *file,
  87325. FLAC__StreamDecoderWriteCallback write_callback,
  87326. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87327. FLAC__StreamDecoderErrorCallback error_callback,
  87328. void *client_data
  87329. )
  87330. {
  87331. return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/false);
  87332. }
  87333. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_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=*/true);
  87343. }
  87344. static FLAC__StreamDecoderInitStatus init_file_internal_(
  87345. FLAC__StreamDecoder *decoder,
  87346. const char *filename,
  87347. FLAC__StreamDecoderWriteCallback write_callback,
  87348. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87349. FLAC__StreamDecoderErrorCallback error_callback,
  87350. void *client_data,
  87351. FLAC__bool is_ogg
  87352. )
  87353. {
  87354. FILE *file;
  87355. FLAC__ASSERT(0 != decoder);
  87356. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87357. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED);
  87358. if(0 == write_callback || 0 == error_callback)
  87359. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS);
  87360. file = filename? fopen(filename, "rb") : stdin;
  87361. if(0 == file)
  87362. return FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE;
  87363. return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, is_ogg);
  87364. }
  87365. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_file(
  87366. FLAC__StreamDecoder *decoder,
  87367. const char *filename,
  87368. FLAC__StreamDecoderWriteCallback write_callback,
  87369. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87370. FLAC__StreamDecoderErrorCallback error_callback,
  87371. void *client_data
  87372. )
  87373. {
  87374. return init_file_internal_(decoder, filename, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/false);
  87375. }
  87376. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_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=*/true);
  87386. }
  87387. FLAC_API FLAC__bool FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder)
  87388. {
  87389. FLAC__bool md5_failed = false;
  87390. unsigned i;
  87391. FLAC__ASSERT(0 != decoder);
  87392. FLAC__ASSERT(0 != decoder->private_);
  87393. FLAC__ASSERT(0 != decoder->protected_);
  87394. if(decoder->protected_->state == FLAC__STREAM_DECODER_UNINITIALIZED)
  87395. return true;
  87396. FLAC__MD5Final(decoder->private_->computed_md5sum, &decoder->private_->md5context);
  87397. if(decoder->private_->has_seek_table && 0 != decoder->private_->seek_table.data.seek_table.points) {
  87398. free(decoder->private_->seek_table.data.seek_table.points);
  87399. decoder->private_->seek_table.data.seek_table.points = 0;
  87400. decoder->private_->has_seek_table = false;
  87401. }
  87402. FLAC__bitreader_free(decoder->private_->input);
  87403. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  87404. if(0 != decoder->private_->output[i]) {
  87405. free(decoder->private_->output[i]-4);
  87406. decoder->private_->output[i] = 0;
  87407. }
  87408. if(0 != decoder->private_->residual_unaligned[i]) {
  87409. free(decoder->private_->residual_unaligned[i]);
  87410. decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0;
  87411. }
  87412. }
  87413. decoder->private_->output_capacity = 0;
  87414. decoder->private_->output_channels = 0;
  87415. #if FLAC__HAS_OGG
  87416. if(decoder->private_->is_ogg)
  87417. FLAC__ogg_decoder_aspect_finish(&decoder->protected_->ogg_decoder_aspect);
  87418. #endif
  87419. if(0 != decoder->private_->file) {
  87420. if(decoder->private_->file != stdin)
  87421. fclose(decoder->private_->file);
  87422. decoder->private_->file = 0;
  87423. }
  87424. if(decoder->private_->do_md5_checking) {
  87425. if(memcmp(decoder->private_->stream_info.data.stream_info.md5sum, decoder->private_->computed_md5sum, 16))
  87426. md5_failed = true;
  87427. }
  87428. decoder->private_->is_seeking = false;
  87429. set_defaults_dec(decoder);
  87430. decoder->protected_->state = FLAC__STREAM_DECODER_UNINITIALIZED;
  87431. return !md5_failed;
  87432. }
  87433. FLAC_API FLAC__bool FLAC__stream_decoder_set_ogg_serial_number(FLAC__StreamDecoder *decoder, long value)
  87434. {
  87435. FLAC__ASSERT(0 != decoder);
  87436. FLAC__ASSERT(0 != decoder->private_);
  87437. FLAC__ASSERT(0 != decoder->protected_);
  87438. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87439. return false;
  87440. #if FLAC__HAS_OGG
  87441. FLAC__ogg_decoder_aspect_set_serial_number(&decoder->protected_->ogg_decoder_aspect, value);
  87442. return true;
  87443. #else
  87444. (void)value;
  87445. return false;
  87446. #endif
  87447. }
  87448. FLAC_API FLAC__bool FLAC__stream_decoder_set_md5_checking(FLAC__StreamDecoder *decoder, FLAC__bool value)
  87449. {
  87450. FLAC__ASSERT(0 != decoder);
  87451. FLAC__ASSERT(0 != decoder->protected_);
  87452. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87453. return false;
  87454. decoder->protected_->md5_checking = value;
  87455. return true;
  87456. }
  87457. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond(FLAC__StreamDecoder *decoder, FLAC__MetadataType type)
  87458. {
  87459. FLAC__ASSERT(0 != decoder);
  87460. FLAC__ASSERT(0 != decoder->private_);
  87461. FLAC__ASSERT(0 != decoder->protected_);
  87462. FLAC__ASSERT((unsigned)type <= FLAC__MAX_METADATA_TYPE_CODE);
  87463. if((unsigned)type > FLAC__MAX_METADATA_TYPE_CODE)
  87464. return false;
  87465. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87466. return false;
  87467. decoder->private_->metadata_filter[type] = true;
  87468. if(type == FLAC__METADATA_TYPE_APPLICATION)
  87469. decoder->private_->metadata_filter_ids_count = 0;
  87470. return true;
  87471. }
  87472. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4])
  87473. {
  87474. FLAC__ASSERT(0 != decoder);
  87475. FLAC__ASSERT(0 != decoder->private_);
  87476. FLAC__ASSERT(0 != decoder->protected_);
  87477. FLAC__ASSERT(0 != id);
  87478. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87479. return false;
  87480. if(decoder->private_->metadata_filter[FLAC__METADATA_TYPE_APPLICATION])
  87481. return true;
  87482. FLAC__ASSERT(0 != decoder->private_->metadata_filter_ids);
  87483. if(decoder->private_->metadata_filter_ids_count == decoder->private_->metadata_filter_ids_capacity) {
  87484. 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))) {
  87485. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87486. return false;
  87487. }
  87488. decoder->private_->metadata_filter_ids_capacity *= 2;
  87489. }
  87490. 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));
  87491. decoder->private_->metadata_filter_ids_count++;
  87492. return true;
  87493. }
  87494. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_all(FLAC__StreamDecoder *decoder)
  87495. {
  87496. unsigned i;
  87497. FLAC__ASSERT(0 != decoder);
  87498. FLAC__ASSERT(0 != decoder->private_);
  87499. FLAC__ASSERT(0 != decoder->protected_);
  87500. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87501. return false;
  87502. for(i = 0; i < sizeof(decoder->private_->metadata_filter) / sizeof(decoder->private_->metadata_filter[0]); i++)
  87503. decoder->private_->metadata_filter[i] = true;
  87504. decoder->private_->metadata_filter_ids_count = 0;
  87505. return true;
  87506. }
  87507. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore(FLAC__StreamDecoder *decoder, FLAC__MetadataType type)
  87508. {
  87509. FLAC__ASSERT(0 != decoder);
  87510. FLAC__ASSERT(0 != decoder->private_);
  87511. FLAC__ASSERT(0 != decoder->protected_);
  87512. FLAC__ASSERT((unsigned)type <= FLAC__MAX_METADATA_TYPE_CODE);
  87513. if((unsigned)type > FLAC__MAX_METADATA_TYPE_CODE)
  87514. return false;
  87515. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87516. return false;
  87517. decoder->private_->metadata_filter[type] = false;
  87518. if(type == FLAC__METADATA_TYPE_APPLICATION)
  87519. decoder->private_->metadata_filter_ids_count = 0;
  87520. return true;
  87521. }
  87522. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4])
  87523. {
  87524. FLAC__ASSERT(0 != decoder);
  87525. FLAC__ASSERT(0 != decoder->private_);
  87526. FLAC__ASSERT(0 != decoder->protected_);
  87527. FLAC__ASSERT(0 != id);
  87528. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87529. return false;
  87530. if(!decoder->private_->metadata_filter[FLAC__METADATA_TYPE_APPLICATION])
  87531. return true;
  87532. FLAC__ASSERT(0 != decoder->private_->metadata_filter_ids);
  87533. if(decoder->private_->metadata_filter_ids_count == decoder->private_->metadata_filter_ids_capacity) {
  87534. 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))) {
  87535. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87536. return false;
  87537. }
  87538. decoder->private_->metadata_filter_ids_capacity *= 2;
  87539. }
  87540. 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));
  87541. decoder->private_->metadata_filter_ids_count++;
  87542. return true;
  87543. }
  87544. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_all(FLAC__StreamDecoder *decoder)
  87545. {
  87546. FLAC__ASSERT(0 != decoder);
  87547. FLAC__ASSERT(0 != decoder->private_);
  87548. FLAC__ASSERT(0 != decoder->protected_);
  87549. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87550. return false;
  87551. memset(decoder->private_->metadata_filter, 0, sizeof(decoder->private_->metadata_filter));
  87552. decoder->private_->metadata_filter_ids_count = 0;
  87553. return true;
  87554. }
  87555. FLAC_API FLAC__StreamDecoderState FLAC__stream_decoder_get_state(const FLAC__StreamDecoder *decoder)
  87556. {
  87557. FLAC__ASSERT(0 != decoder);
  87558. FLAC__ASSERT(0 != decoder->protected_);
  87559. return decoder->protected_->state;
  87560. }
  87561. FLAC_API const char *FLAC__stream_decoder_get_resolved_state_string(const FLAC__StreamDecoder *decoder)
  87562. {
  87563. return FLAC__StreamDecoderStateString[decoder->protected_->state];
  87564. }
  87565. FLAC_API FLAC__bool FLAC__stream_decoder_get_md5_checking(const FLAC__StreamDecoder *decoder)
  87566. {
  87567. FLAC__ASSERT(0 != decoder);
  87568. FLAC__ASSERT(0 != decoder->protected_);
  87569. return decoder->protected_->md5_checking;
  87570. }
  87571. FLAC_API FLAC__uint64 FLAC__stream_decoder_get_total_samples(const FLAC__StreamDecoder *decoder)
  87572. {
  87573. FLAC__ASSERT(0 != decoder);
  87574. FLAC__ASSERT(0 != decoder->protected_);
  87575. return decoder->private_->has_stream_info? decoder->private_->stream_info.data.stream_info.total_samples : 0;
  87576. }
  87577. FLAC_API unsigned FLAC__stream_decoder_get_channels(const FLAC__StreamDecoder *decoder)
  87578. {
  87579. FLAC__ASSERT(0 != decoder);
  87580. FLAC__ASSERT(0 != decoder->protected_);
  87581. return decoder->protected_->channels;
  87582. }
  87583. FLAC_API FLAC__ChannelAssignment FLAC__stream_decoder_get_channel_assignment(const FLAC__StreamDecoder *decoder)
  87584. {
  87585. FLAC__ASSERT(0 != decoder);
  87586. FLAC__ASSERT(0 != decoder->protected_);
  87587. return decoder->protected_->channel_assignment;
  87588. }
  87589. FLAC_API unsigned FLAC__stream_decoder_get_bits_per_sample(const FLAC__StreamDecoder *decoder)
  87590. {
  87591. FLAC__ASSERT(0 != decoder);
  87592. FLAC__ASSERT(0 != decoder->protected_);
  87593. return decoder->protected_->bits_per_sample;
  87594. }
  87595. FLAC_API unsigned FLAC__stream_decoder_get_sample_rate(const FLAC__StreamDecoder *decoder)
  87596. {
  87597. FLAC__ASSERT(0 != decoder);
  87598. FLAC__ASSERT(0 != decoder->protected_);
  87599. return decoder->protected_->sample_rate;
  87600. }
  87601. FLAC_API unsigned FLAC__stream_decoder_get_blocksize(const FLAC__StreamDecoder *decoder)
  87602. {
  87603. FLAC__ASSERT(0 != decoder);
  87604. FLAC__ASSERT(0 != decoder->protected_);
  87605. return decoder->protected_->blocksize;
  87606. }
  87607. FLAC_API FLAC__bool FLAC__stream_decoder_get_decode_position(const FLAC__StreamDecoder *decoder, FLAC__uint64 *position)
  87608. {
  87609. FLAC__ASSERT(0 != decoder);
  87610. FLAC__ASSERT(0 != decoder->private_);
  87611. FLAC__ASSERT(0 != position);
  87612. #if FLAC__HAS_OGG
  87613. if(decoder->private_->is_ogg)
  87614. return false;
  87615. #endif
  87616. if(0 == decoder->private_->tell_callback)
  87617. return false;
  87618. if(decoder->private_->tell_callback(decoder, position, decoder->private_->client_data) != FLAC__STREAM_DECODER_TELL_STATUS_OK)
  87619. return false;
  87620. if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input))
  87621. return false;
  87622. FLAC__ASSERT(*position >= FLAC__stream_decoder_get_input_bytes_unconsumed(decoder));
  87623. *position -= FLAC__stream_decoder_get_input_bytes_unconsumed(decoder);
  87624. return true;
  87625. }
  87626. FLAC_API FLAC__bool FLAC__stream_decoder_flush(FLAC__StreamDecoder *decoder)
  87627. {
  87628. FLAC__ASSERT(0 != decoder);
  87629. FLAC__ASSERT(0 != decoder->private_);
  87630. FLAC__ASSERT(0 != decoder->protected_);
  87631. decoder->private_->samples_decoded = 0;
  87632. decoder->private_->do_md5_checking = false;
  87633. #if FLAC__HAS_OGG
  87634. if(decoder->private_->is_ogg)
  87635. FLAC__ogg_decoder_aspect_flush(&decoder->protected_->ogg_decoder_aspect);
  87636. #endif
  87637. if(!FLAC__bitreader_clear(decoder->private_->input)) {
  87638. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87639. return false;
  87640. }
  87641. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  87642. return true;
  87643. }
  87644. FLAC_API FLAC__bool FLAC__stream_decoder_reset(FLAC__StreamDecoder *decoder)
  87645. {
  87646. FLAC__ASSERT(0 != decoder);
  87647. FLAC__ASSERT(0 != decoder->private_);
  87648. FLAC__ASSERT(0 != decoder->protected_);
  87649. if(!FLAC__stream_decoder_flush(decoder)) {
  87650. return false;
  87651. }
  87652. #if FLAC__HAS_OGG
  87653. if(decoder->private_->is_ogg)
  87654. FLAC__ogg_decoder_aspect_reset(&decoder->protected_->ogg_decoder_aspect);
  87655. #endif
  87656. if(!decoder->private_->internal_reset_hack) {
  87657. if(decoder->private_->file == stdin)
  87658. return false; /* can't rewind stdin, reset fails */
  87659. if(decoder->private_->seek_callback && decoder->private_->seek_callback(decoder, 0, decoder->private_->client_data) == FLAC__STREAM_DECODER_SEEK_STATUS_ERROR)
  87660. return false; /* seekable and seek fails, reset fails */
  87661. }
  87662. else
  87663. decoder->private_->internal_reset_hack = false;
  87664. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_METADATA;
  87665. decoder->private_->has_stream_info = false;
  87666. if(decoder->private_->has_seek_table && 0 != decoder->private_->seek_table.data.seek_table.points) {
  87667. free(decoder->private_->seek_table.data.seek_table.points);
  87668. decoder->private_->seek_table.data.seek_table.points = 0;
  87669. decoder->private_->has_seek_table = false;
  87670. }
  87671. decoder->private_->do_md5_checking = decoder->protected_->md5_checking;
  87672. decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size = 0;
  87673. FLAC__MD5Init(&decoder->private_->md5context);
  87674. decoder->private_->first_frame_offset = 0;
  87675. decoder->private_->unparseable_frame_count = 0;
  87676. return true;
  87677. }
  87678. FLAC_API FLAC__bool FLAC__stream_decoder_process_single(FLAC__StreamDecoder *decoder)
  87679. {
  87680. FLAC__bool got_a_frame;
  87681. FLAC__ASSERT(0 != decoder);
  87682. FLAC__ASSERT(0 != decoder->protected_);
  87683. while(1) {
  87684. switch(decoder->protected_->state) {
  87685. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  87686. if(!find_metadata_(decoder))
  87687. return false; /* above function sets the status for us */
  87688. break;
  87689. case FLAC__STREAM_DECODER_READ_METADATA:
  87690. if(!read_metadata_(decoder))
  87691. return false; /* above function sets the status for us */
  87692. else
  87693. return true;
  87694. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  87695. if(!frame_sync_(decoder))
  87696. return true; /* above function sets the status for us */
  87697. break;
  87698. case FLAC__STREAM_DECODER_READ_FRAME:
  87699. if(!read_frame_(decoder, &got_a_frame, /*do_full_decode=*/true))
  87700. return false; /* above function sets the status for us */
  87701. if(got_a_frame)
  87702. return true; /* above function sets the status for us */
  87703. break;
  87704. case FLAC__STREAM_DECODER_END_OF_STREAM:
  87705. case FLAC__STREAM_DECODER_ABORTED:
  87706. return true;
  87707. default:
  87708. FLAC__ASSERT(0);
  87709. return false;
  87710. }
  87711. }
  87712. }
  87713. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_metadata(FLAC__StreamDecoder *decoder)
  87714. {
  87715. FLAC__ASSERT(0 != decoder);
  87716. FLAC__ASSERT(0 != decoder->protected_);
  87717. while(1) {
  87718. switch(decoder->protected_->state) {
  87719. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  87720. if(!find_metadata_(decoder))
  87721. return false; /* above function sets the status for us */
  87722. break;
  87723. case FLAC__STREAM_DECODER_READ_METADATA:
  87724. if(!read_metadata_(decoder))
  87725. return false; /* above function sets the status for us */
  87726. break;
  87727. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  87728. case FLAC__STREAM_DECODER_READ_FRAME:
  87729. case FLAC__STREAM_DECODER_END_OF_STREAM:
  87730. case FLAC__STREAM_DECODER_ABORTED:
  87731. return true;
  87732. default:
  87733. FLAC__ASSERT(0);
  87734. return false;
  87735. }
  87736. }
  87737. }
  87738. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_stream(FLAC__StreamDecoder *decoder)
  87739. {
  87740. FLAC__bool dummy;
  87741. FLAC__ASSERT(0 != decoder);
  87742. FLAC__ASSERT(0 != decoder->protected_);
  87743. while(1) {
  87744. switch(decoder->protected_->state) {
  87745. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  87746. if(!find_metadata_(decoder))
  87747. return false; /* above function sets the status for us */
  87748. break;
  87749. case FLAC__STREAM_DECODER_READ_METADATA:
  87750. if(!read_metadata_(decoder))
  87751. return false; /* above function sets the status for us */
  87752. break;
  87753. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  87754. if(!frame_sync_(decoder))
  87755. return true; /* above function sets the status for us */
  87756. break;
  87757. case FLAC__STREAM_DECODER_READ_FRAME:
  87758. if(!read_frame_(decoder, &dummy, /*do_full_decode=*/true))
  87759. return false; /* above function sets the status for us */
  87760. break;
  87761. case FLAC__STREAM_DECODER_END_OF_STREAM:
  87762. case FLAC__STREAM_DECODER_ABORTED:
  87763. return true;
  87764. default:
  87765. FLAC__ASSERT(0);
  87766. return false;
  87767. }
  87768. }
  87769. }
  87770. FLAC_API FLAC__bool FLAC__stream_decoder_skip_single_frame(FLAC__StreamDecoder *decoder)
  87771. {
  87772. FLAC__bool got_a_frame;
  87773. FLAC__ASSERT(0 != decoder);
  87774. FLAC__ASSERT(0 != decoder->protected_);
  87775. while(1) {
  87776. switch(decoder->protected_->state) {
  87777. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  87778. case FLAC__STREAM_DECODER_READ_METADATA:
  87779. return false; /* above function sets the status for us */
  87780. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  87781. if(!frame_sync_(decoder))
  87782. return true; /* above function sets the status for us */
  87783. break;
  87784. case FLAC__STREAM_DECODER_READ_FRAME:
  87785. if(!read_frame_(decoder, &got_a_frame, /*do_full_decode=*/false))
  87786. return false; /* above function sets the status for us */
  87787. if(got_a_frame)
  87788. return true; /* above function sets the status for us */
  87789. break;
  87790. case FLAC__STREAM_DECODER_END_OF_STREAM:
  87791. case FLAC__STREAM_DECODER_ABORTED:
  87792. return true;
  87793. default:
  87794. FLAC__ASSERT(0);
  87795. return false;
  87796. }
  87797. }
  87798. }
  87799. FLAC_API FLAC__bool FLAC__stream_decoder_seek_absolute(FLAC__StreamDecoder *decoder, FLAC__uint64 sample)
  87800. {
  87801. FLAC__uint64 length;
  87802. FLAC__ASSERT(0 != decoder);
  87803. if(
  87804. decoder->protected_->state != FLAC__STREAM_DECODER_SEARCH_FOR_METADATA &&
  87805. decoder->protected_->state != FLAC__STREAM_DECODER_READ_METADATA &&
  87806. decoder->protected_->state != FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC &&
  87807. decoder->protected_->state != FLAC__STREAM_DECODER_READ_FRAME &&
  87808. decoder->protected_->state != FLAC__STREAM_DECODER_END_OF_STREAM
  87809. )
  87810. return false;
  87811. if(0 == decoder->private_->seek_callback)
  87812. return false;
  87813. FLAC__ASSERT(decoder->private_->seek_callback);
  87814. FLAC__ASSERT(decoder->private_->tell_callback);
  87815. FLAC__ASSERT(decoder->private_->length_callback);
  87816. FLAC__ASSERT(decoder->private_->eof_callback);
  87817. if(FLAC__stream_decoder_get_total_samples(decoder) > 0 && sample >= FLAC__stream_decoder_get_total_samples(decoder))
  87818. return false;
  87819. decoder->private_->is_seeking = true;
  87820. decoder->private_->do_md5_checking = false;
  87821. if(decoder->private_->length_callback(decoder, &length, decoder->private_->client_data) != FLAC__STREAM_DECODER_LENGTH_STATUS_OK) {
  87822. decoder->private_->is_seeking = false;
  87823. return false;
  87824. }
  87825. if(
  87826. decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_METADATA ||
  87827. decoder->protected_->state == FLAC__STREAM_DECODER_READ_METADATA
  87828. ) {
  87829. if(!FLAC__stream_decoder_process_until_end_of_metadata(decoder)) {
  87830. decoder->private_->is_seeking = false;
  87831. return false;
  87832. }
  87833. if(FLAC__stream_decoder_get_total_samples(decoder) > 0 && sample >= FLAC__stream_decoder_get_total_samples(decoder)) {
  87834. decoder->private_->is_seeking = false;
  87835. return false;
  87836. }
  87837. }
  87838. {
  87839. const FLAC__bool ok =
  87840. #if FLAC__HAS_OGG
  87841. decoder->private_->is_ogg?
  87842. seek_to_absolute_sample_ogg_(decoder, length, sample) :
  87843. #endif
  87844. seek_to_absolute_sample_(decoder, length, sample)
  87845. ;
  87846. decoder->private_->is_seeking = false;
  87847. return ok;
  87848. }
  87849. }
  87850. unsigned FLAC__stream_decoder_get_input_bytes_unconsumed(const FLAC__StreamDecoder *decoder)
  87851. {
  87852. FLAC__ASSERT(0 != decoder);
  87853. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  87854. FLAC__ASSERT(!(FLAC__bitreader_get_input_bits_unconsumed(decoder->private_->input) & 7));
  87855. return FLAC__bitreader_get_input_bits_unconsumed(decoder->private_->input) / 8;
  87856. }
  87857. void set_defaults_dec(FLAC__StreamDecoder *decoder)
  87858. {
  87859. #if FLAC__HAS_OGG
  87860. decoder->private_->is_ogg = false;
  87861. #endif
  87862. decoder->private_->read_callback = 0;
  87863. decoder->private_->seek_callback = 0;
  87864. decoder->private_->tell_callback = 0;
  87865. decoder->private_->length_callback = 0;
  87866. decoder->private_->eof_callback = 0;
  87867. decoder->private_->write_callback = 0;
  87868. decoder->private_->metadata_callback = 0;
  87869. decoder->private_->error_callback = 0;
  87870. decoder->private_->client_data = 0;
  87871. memset(decoder->private_->metadata_filter, 0, sizeof(decoder->private_->metadata_filter));
  87872. decoder->private_->metadata_filter[FLAC__METADATA_TYPE_STREAMINFO] = true;
  87873. decoder->private_->metadata_filter_ids_count = 0;
  87874. decoder->protected_->md5_checking = false;
  87875. #if FLAC__HAS_OGG
  87876. FLAC__ogg_decoder_aspect_set_defaults(&decoder->protected_->ogg_decoder_aspect);
  87877. #endif
  87878. }
  87879. FILE *get_binary_stdin_(void)
  87880. {
  87881. #if defined _MSC_VER || defined __MINGW32__
  87882. _setmode(_fileno(stdin), _O_BINARY);
  87883. #elif defined __CYGWIN__
  87884. setmode(_fileno(stdin), _O_BINARY);
  87885. #elif defined __EMX__
  87886. setmode(fileno(stdin), O_BINARY);
  87887. #endif
  87888. return stdin;
  87889. }
  87890. FLAC__bool allocate_output_(FLAC__StreamDecoder *decoder, unsigned size, unsigned channels)
  87891. {
  87892. unsigned i;
  87893. FLAC__int32 *tmp;
  87894. if(size <= decoder->private_->output_capacity && channels <= decoder->private_->output_channels)
  87895. return true;
  87896. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  87897. if(0 != decoder->private_->output[i]) {
  87898. free(decoder->private_->output[i]-4);
  87899. decoder->private_->output[i] = 0;
  87900. }
  87901. if(0 != decoder->private_->residual_unaligned[i]) {
  87902. free(decoder->private_->residual_unaligned[i]);
  87903. decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0;
  87904. }
  87905. }
  87906. for(i = 0; i < channels; i++) {
  87907. tmp = (FLAC__int32*)safe_malloc_muladd2_(sizeof(FLAC__int32), /*times (*/size, /*+*/4/*)*/);
  87908. if(tmp == 0) {
  87909. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87910. return false;
  87911. }
  87912. memset(tmp, 0, sizeof(FLAC__int32)*4);
  87913. decoder->private_->output[i] = tmp + 4;
  87914. if(!FLAC__memory_alloc_aligned_int32_array(size, &decoder->private_->residual_unaligned[i], &decoder->private_->residual[i])) {
  87915. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87916. return false;
  87917. }
  87918. }
  87919. decoder->private_->output_capacity = size;
  87920. decoder->private_->output_channels = channels;
  87921. return true;
  87922. }
  87923. FLAC__bool has_id_filtered_(FLAC__StreamDecoder *decoder, FLAC__byte *id)
  87924. {
  87925. size_t i;
  87926. FLAC__ASSERT(0 != decoder);
  87927. FLAC__ASSERT(0 != decoder->private_);
  87928. for(i = 0; i < decoder->private_->metadata_filter_ids_count; i++)
  87929. if(0 == memcmp(decoder->private_->metadata_filter_ids + i * (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8), id, (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8)))
  87930. return true;
  87931. return false;
  87932. }
  87933. FLAC__bool find_metadata_(FLAC__StreamDecoder *decoder)
  87934. {
  87935. FLAC__uint32 x;
  87936. unsigned i, id_;
  87937. FLAC__bool first = true;
  87938. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  87939. for(i = id_ = 0; i < 4; ) {
  87940. if(decoder->private_->cached) {
  87941. x = (FLAC__uint32)decoder->private_->lookahead;
  87942. decoder->private_->cached = false;
  87943. }
  87944. else {
  87945. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  87946. return false; /* read_callback_ sets the state for us */
  87947. }
  87948. if(x == FLAC__STREAM_SYNC_STRING[i]) {
  87949. first = true;
  87950. i++;
  87951. id_ = 0;
  87952. continue;
  87953. }
  87954. if(x == ID3V2_TAG_[id_]) {
  87955. id_++;
  87956. i = 0;
  87957. if(id_ == 3) {
  87958. if(!skip_id3v2_tag_(decoder))
  87959. return false; /* skip_id3v2_tag_ sets the state for us */
  87960. }
  87961. continue;
  87962. }
  87963. id_ = 0;
  87964. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  87965. decoder->private_->header_warmup[0] = (FLAC__byte)x;
  87966. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  87967. return false; /* read_callback_ sets the state for us */
  87968. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  87969. decoder->private_->lookahead = (FLAC__byte)x;
  87970. decoder->private_->cached = true;
  87971. }
  87972. else if(x >> 2 == 0x3e) { /* MAGIC NUMBER for the last 6 sync bits */
  87973. decoder->private_->header_warmup[1] = (FLAC__byte)x;
  87974. decoder->protected_->state = FLAC__STREAM_DECODER_READ_FRAME;
  87975. return true;
  87976. }
  87977. }
  87978. i = 0;
  87979. if(first) {
  87980. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  87981. first = false;
  87982. }
  87983. }
  87984. decoder->protected_->state = FLAC__STREAM_DECODER_READ_METADATA;
  87985. return true;
  87986. }
  87987. FLAC__bool read_metadata_(FLAC__StreamDecoder *decoder)
  87988. {
  87989. FLAC__bool is_last;
  87990. FLAC__uint32 i, x, type, length;
  87991. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  87992. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_IS_LAST_LEN))
  87993. return false; /* read_callback_ sets the state for us */
  87994. is_last = x? true : false;
  87995. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &type, FLAC__STREAM_METADATA_TYPE_LEN))
  87996. return false; /* read_callback_ sets the state for us */
  87997. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &length, FLAC__STREAM_METADATA_LENGTH_LEN))
  87998. return false; /* read_callback_ sets the state for us */
  87999. if(type == FLAC__METADATA_TYPE_STREAMINFO) {
  88000. if(!read_metadata_streaminfo_(decoder, is_last, length))
  88001. return false;
  88002. decoder->private_->has_stream_info = true;
  88003. 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))
  88004. decoder->private_->do_md5_checking = false;
  88005. if(!decoder->private_->is_seeking && decoder->private_->metadata_filter[FLAC__METADATA_TYPE_STREAMINFO] && decoder->private_->metadata_callback)
  88006. decoder->private_->metadata_callback(decoder, &decoder->private_->stream_info, decoder->private_->client_data);
  88007. }
  88008. else if(type == FLAC__METADATA_TYPE_SEEKTABLE) {
  88009. if(!read_metadata_seektable_(decoder, is_last, length))
  88010. return false;
  88011. decoder->private_->has_seek_table = true;
  88012. if(!decoder->private_->is_seeking && decoder->private_->metadata_filter[FLAC__METADATA_TYPE_SEEKTABLE] && decoder->private_->metadata_callback)
  88013. decoder->private_->metadata_callback(decoder, &decoder->private_->seek_table, decoder->private_->client_data);
  88014. }
  88015. else {
  88016. FLAC__bool skip_it = !decoder->private_->metadata_filter[type];
  88017. unsigned real_length = length;
  88018. FLAC__StreamMetadata block;
  88019. block.is_last = is_last;
  88020. block.type = (FLAC__MetadataType)type;
  88021. block.length = length;
  88022. if(type == FLAC__METADATA_TYPE_APPLICATION) {
  88023. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.application.id, FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8))
  88024. return false; /* read_callback_ sets the state for us */
  88025. if(real_length < FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8) { /* underflow check */
  88026. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;/*@@@@@@ maybe wrong error? need to resync?*/
  88027. return false;
  88028. }
  88029. real_length -= FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8;
  88030. if(decoder->private_->metadata_filter_ids_count > 0 && has_id_filtered_(decoder, block.data.application.id))
  88031. skip_it = !skip_it;
  88032. }
  88033. if(skip_it) {
  88034. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, real_length))
  88035. return false; /* read_callback_ sets the state for us */
  88036. }
  88037. else {
  88038. switch(type) {
  88039. case FLAC__METADATA_TYPE_PADDING:
  88040. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, real_length))
  88041. return false; /* read_callback_ sets the state for us */
  88042. break;
  88043. case FLAC__METADATA_TYPE_APPLICATION:
  88044. if(real_length > 0) {
  88045. if(0 == (block.data.application.data = (FLAC__byte*)malloc(real_length))) {
  88046. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88047. return false;
  88048. }
  88049. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.application.data, real_length))
  88050. return false; /* read_callback_ sets the state for us */
  88051. }
  88052. else
  88053. block.data.application.data = 0;
  88054. break;
  88055. case FLAC__METADATA_TYPE_VORBIS_COMMENT:
  88056. if(!read_metadata_vorbiscomment_(decoder, &block.data.vorbis_comment))
  88057. return false;
  88058. break;
  88059. case FLAC__METADATA_TYPE_CUESHEET:
  88060. if(!read_metadata_cuesheet_(decoder, &block.data.cue_sheet))
  88061. return false;
  88062. break;
  88063. case FLAC__METADATA_TYPE_PICTURE:
  88064. if(!read_metadata_picture_(decoder, &block.data.picture))
  88065. return false;
  88066. break;
  88067. case FLAC__METADATA_TYPE_STREAMINFO:
  88068. case FLAC__METADATA_TYPE_SEEKTABLE:
  88069. FLAC__ASSERT(0);
  88070. break;
  88071. default:
  88072. if(real_length > 0) {
  88073. if(0 == (block.data.unknown.data = (FLAC__byte*)malloc(real_length))) {
  88074. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88075. return false;
  88076. }
  88077. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.unknown.data, real_length))
  88078. return false; /* read_callback_ sets the state for us */
  88079. }
  88080. else
  88081. block.data.unknown.data = 0;
  88082. break;
  88083. }
  88084. if(!decoder->private_->is_seeking && decoder->private_->metadata_callback)
  88085. decoder->private_->metadata_callback(decoder, &block, decoder->private_->client_data);
  88086. switch(type) {
  88087. case FLAC__METADATA_TYPE_PADDING:
  88088. break;
  88089. case FLAC__METADATA_TYPE_APPLICATION:
  88090. if(0 != block.data.application.data)
  88091. free(block.data.application.data);
  88092. break;
  88093. case FLAC__METADATA_TYPE_VORBIS_COMMENT:
  88094. if(0 != block.data.vorbis_comment.vendor_string.entry)
  88095. free(block.data.vorbis_comment.vendor_string.entry);
  88096. if(block.data.vorbis_comment.num_comments > 0)
  88097. for(i = 0; i < block.data.vorbis_comment.num_comments; i++)
  88098. if(0 != block.data.vorbis_comment.comments[i].entry)
  88099. free(block.data.vorbis_comment.comments[i].entry);
  88100. if(0 != block.data.vorbis_comment.comments)
  88101. free(block.data.vorbis_comment.comments);
  88102. break;
  88103. case FLAC__METADATA_TYPE_CUESHEET:
  88104. if(block.data.cue_sheet.num_tracks > 0)
  88105. for(i = 0; i < block.data.cue_sheet.num_tracks; i++)
  88106. if(0 != block.data.cue_sheet.tracks[i].indices)
  88107. free(block.data.cue_sheet.tracks[i].indices);
  88108. if(0 != block.data.cue_sheet.tracks)
  88109. free(block.data.cue_sheet.tracks);
  88110. break;
  88111. case FLAC__METADATA_TYPE_PICTURE:
  88112. if(0 != block.data.picture.mime_type)
  88113. free(block.data.picture.mime_type);
  88114. if(0 != block.data.picture.description)
  88115. free(block.data.picture.description);
  88116. if(0 != block.data.picture.data)
  88117. free(block.data.picture.data);
  88118. break;
  88119. case FLAC__METADATA_TYPE_STREAMINFO:
  88120. case FLAC__METADATA_TYPE_SEEKTABLE:
  88121. FLAC__ASSERT(0);
  88122. default:
  88123. if(0 != block.data.unknown.data)
  88124. free(block.data.unknown.data);
  88125. break;
  88126. }
  88127. }
  88128. }
  88129. if(is_last) {
  88130. if(!FLAC__stream_decoder_get_decode_position(decoder, &decoder->private_->first_frame_offset))
  88131. decoder->private_->first_frame_offset = 0;
  88132. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88133. }
  88134. return true;
  88135. }
  88136. FLAC__bool read_metadata_streaminfo_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length)
  88137. {
  88138. FLAC__uint32 x;
  88139. unsigned bits, used_bits = 0;
  88140. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88141. decoder->private_->stream_info.type = FLAC__METADATA_TYPE_STREAMINFO;
  88142. decoder->private_->stream_info.is_last = is_last;
  88143. decoder->private_->stream_info.length = length;
  88144. bits = FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN;
  88145. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, bits))
  88146. return false; /* read_callback_ sets the state for us */
  88147. decoder->private_->stream_info.data.stream_info.min_blocksize = x;
  88148. used_bits += bits;
  88149. bits = FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN;
  88150. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN))
  88151. return false; /* read_callback_ sets the state for us */
  88152. decoder->private_->stream_info.data.stream_info.max_blocksize = x;
  88153. used_bits += bits;
  88154. bits = FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN;
  88155. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN))
  88156. return false; /* read_callback_ sets the state for us */
  88157. decoder->private_->stream_info.data.stream_info.min_framesize = x;
  88158. used_bits += bits;
  88159. bits = FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN;
  88160. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN))
  88161. return false; /* read_callback_ sets the state for us */
  88162. decoder->private_->stream_info.data.stream_info.max_framesize = x;
  88163. used_bits += bits;
  88164. bits = FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN;
  88165. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN))
  88166. return false; /* read_callback_ sets the state for us */
  88167. decoder->private_->stream_info.data.stream_info.sample_rate = x;
  88168. used_bits += bits;
  88169. bits = FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN;
  88170. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN))
  88171. return false; /* read_callback_ sets the state for us */
  88172. decoder->private_->stream_info.data.stream_info.channels = x+1;
  88173. used_bits += bits;
  88174. bits = FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN;
  88175. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN))
  88176. return false; /* read_callback_ sets the state for us */
  88177. decoder->private_->stream_info.data.stream_info.bits_per_sample = x+1;
  88178. used_bits += bits;
  88179. bits = FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN;
  88180. 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))
  88181. return false; /* read_callback_ sets the state for us */
  88182. used_bits += bits;
  88183. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, decoder->private_->stream_info.data.stream_info.md5sum, 16))
  88184. return false; /* read_callback_ sets the state for us */
  88185. used_bits += 16*8;
  88186. FLAC__ASSERT(used_bits % 8 == 0);
  88187. length -= (used_bits / 8);
  88188. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, length))
  88189. return false; /* read_callback_ sets the state for us */
  88190. return true;
  88191. }
  88192. FLAC__bool read_metadata_seektable_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length)
  88193. {
  88194. FLAC__uint32 i, x;
  88195. FLAC__uint64 xx;
  88196. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88197. decoder->private_->seek_table.type = FLAC__METADATA_TYPE_SEEKTABLE;
  88198. decoder->private_->seek_table.is_last = is_last;
  88199. decoder->private_->seek_table.length = length;
  88200. decoder->private_->seek_table.data.seek_table.num_points = length / FLAC__STREAM_METADATA_SEEKPOINT_LENGTH;
  88201. 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)))) {
  88202. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88203. return false;
  88204. }
  88205. for(i = 0; i < decoder->private_->seek_table.data.seek_table.num_points; i++) {
  88206. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &xx, FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN))
  88207. return false; /* read_callback_ sets the state for us */
  88208. decoder->private_->seek_table.data.seek_table.points[i].sample_number = xx;
  88209. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &xx, FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN))
  88210. return false; /* read_callback_ sets the state for us */
  88211. decoder->private_->seek_table.data.seek_table.points[i].stream_offset = xx;
  88212. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN))
  88213. return false; /* read_callback_ sets the state for us */
  88214. decoder->private_->seek_table.data.seek_table.points[i].frame_samples = x;
  88215. }
  88216. length -= (decoder->private_->seek_table.data.seek_table.num_points * FLAC__STREAM_METADATA_SEEKPOINT_LENGTH);
  88217. if(length > 0) {
  88218. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, length))
  88219. return false; /* read_callback_ sets the state for us */
  88220. }
  88221. return true;
  88222. }
  88223. FLAC__bool read_metadata_vorbiscomment_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_VorbisComment *obj)
  88224. {
  88225. FLAC__uint32 i;
  88226. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88227. FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN == 32);
  88228. if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->vendor_string.length))
  88229. return false; /* read_callback_ sets the state for us */
  88230. if(obj->vendor_string.length > 0) {
  88231. if(0 == (obj->vendor_string.entry = (FLAC__byte*)safe_malloc_add_2op_(obj->vendor_string.length, /*+*/1))) {
  88232. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88233. return false;
  88234. }
  88235. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->vendor_string.entry, obj->vendor_string.length))
  88236. return false; /* read_callback_ sets the state for us */
  88237. obj->vendor_string.entry[obj->vendor_string.length] = '\0';
  88238. }
  88239. else
  88240. obj->vendor_string.entry = 0;
  88241. FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN == 32);
  88242. if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->num_comments))
  88243. return false; /* read_callback_ sets the state for us */
  88244. if(obj->num_comments > 0) {
  88245. if(0 == (obj->comments = (FLAC__StreamMetadata_VorbisComment_Entry*)safe_malloc_mul_2op_(obj->num_comments, /*times*/sizeof(FLAC__StreamMetadata_VorbisComment_Entry)))) {
  88246. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88247. return false;
  88248. }
  88249. for(i = 0; i < obj->num_comments; i++) {
  88250. FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN == 32);
  88251. if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->comments[i].length))
  88252. return false; /* read_callback_ sets the state for us */
  88253. if(obj->comments[i].length > 0) {
  88254. if(0 == (obj->comments[i].entry = (FLAC__byte*)safe_malloc_add_2op_(obj->comments[i].length, /*+*/1))) {
  88255. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88256. return false;
  88257. }
  88258. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->comments[i].entry, obj->comments[i].length))
  88259. return false; /* read_callback_ sets the state for us */
  88260. obj->comments[i].entry[obj->comments[i].length] = '\0';
  88261. }
  88262. else
  88263. obj->comments[i].entry = 0;
  88264. }
  88265. }
  88266. else {
  88267. obj->comments = 0;
  88268. }
  88269. return true;
  88270. }
  88271. FLAC__bool read_metadata_cuesheet_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_CueSheet *obj)
  88272. {
  88273. FLAC__uint32 i, j, x;
  88274. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88275. memset(obj, 0, sizeof(FLAC__StreamMetadata_CueSheet));
  88276. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN % 8 == 0);
  88277. 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))
  88278. return false; /* read_callback_ sets the state for us */
  88279. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &obj->lead_in, FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN))
  88280. return false; /* read_callback_ sets the state for us */
  88281. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN))
  88282. return false; /* read_callback_ sets the state for us */
  88283. obj->is_cd = x? true : false;
  88284. if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN))
  88285. return false; /* read_callback_ sets the state for us */
  88286. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN))
  88287. return false; /* read_callback_ sets the state for us */
  88288. obj->num_tracks = x;
  88289. if(obj->num_tracks > 0) {
  88290. if(0 == (obj->tracks = (FLAC__StreamMetadata_CueSheet_Track*)safe_calloc_(obj->num_tracks, sizeof(FLAC__StreamMetadata_CueSheet_Track)))) {
  88291. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88292. return false;
  88293. }
  88294. for(i = 0; i < obj->num_tracks; i++) {
  88295. FLAC__StreamMetadata_CueSheet_Track *track = &obj->tracks[i];
  88296. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &track->offset, FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN))
  88297. return false; /* read_callback_ sets the state for us */
  88298. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN))
  88299. return false; /* read_callback_ sets the state for us */
  88300. track->number = (FLAC__byte)x;
  88301. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN % 8 == 0);
  88302. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, (FLAC__byte*)track->isrc, FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN/8))
  88303. return false; /* read_callback_ sets the state for us */
  88304. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN))
  88305. return false; /* read_callback_ sets the state for us */
  88306. track->type = x;
  88307. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN))
  88308. return false; /* read_callback_ sets the state for us */
  88309. track->pre_emphasis = x;
  88310. if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN))
  88311. return false; /* read_callback_ sets the state for us */
  88312. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN))
  88313. return false; /* read_callback_ sets the state for us */
  88314. track->num_indices = (FLAC__byte)x;
  88315. if(track->num_indices > 0) {
  88316. if(0 == (track->indices = (FLAC__StreamMetadata_CueSheet_Index*)safe_calloc_(track->num_indices, sizeof(FLAC__StreamMetadata_CueSheet_Index)))) {
  88317. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88318. return false;
  88319. }
  88320. for(j = 0; j < track->num_indices; j++) {
  88321. FLAC__StreamMetadata_CueSheet_Index *index = &track->indices[j];
  88322. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &index->offset, FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN))
  88323. return false; /* read_callback_ sets the state for us */
  88324. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN))
  88325. return false; /* read_callback_ sets the state for us */
  88326. index->number = (FLAC__byte)x;
  88327. if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN))
  88328. return false; /* read_callback_ sets the state for us */
  88329. }
  88330. }
  88331. }
  88332. }
  88333. return true;
  88334. }
  88335. FLAC__bool read_metadata_picture_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_Picture *obj)
  88336. {
  88337. FLAC__uint32 x;
  88338. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88339. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_TYPE_LEN))
  88340. return false; /* read_callback_ sets the state for us */
  88341. obj->type = (FLAC__StreamMetadata_Picture_Type) x;
  88342. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN))
  88343. return false; /* read_callback_ sets the state for us */
  88344. if(0 == (obj->mime_type = (char*)safe_malloc_add_2op_(x, /*+*/1))) {
  88345. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88346. return false;
  88347. }
  88348. if(x > 0) {
  88349. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, (FLAC__byte*)obj->mime_type, x))
  88350. return false; /* read_callback_ sets the state for us */
  88351. }
  88352. obj->mime_type[x] = '\0';
  88353. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN))
  88354. return false; /* read_callback_ sets the state for us */
  88355. if(0 == (obj->description = (FLAC__byte*)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, obj->description, x))
  88361. return false; /* read_callback_ sets the state for us */
  88362. }
  88363. obj->description[x] = '\0';
  88364. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->width, FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN))
  88365. return false; /* read_callback_ sets the state for us */
  88366. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->height, FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN))
  88367. return false; /* read_callback_ sets the state for us */
  88368. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->depth, FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN))
  88369. return false; /* read_callback_ sets the state for us */
  88370. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->colors, FLAC__STREAM_METADATA_PICTURE_COLORS_LEN))
  88371. return false; /* read_callback_ sets the state for us */
  88372. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &(obj->data_length), FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN))
  88373. return false; /* read_callback_ sets the state for us */
  88374. if(0 == (obj->data = (FLAC__byte*)safe_malloc_(obj->data_length))) {
  88375. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88376. return false;
  88377. }
  88378. if(obj->data_length > 0) {
  88379. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->data, obj->data_length))
  88380. return false; /* read_callback_ sets the state for us */
  88381. }
  88382. return true;
  88383. }
  88384. FLAC__bool skip_id3v2_tag_(FLAC__StreamDecoder *decoder)
  88385. {
  88386. FLAC__uint32 x;
  88387. unsigned i, skip;
  88388. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 24))
  88389. return false; /* read_callback_ sets the state for us */
  88390. skip = 0;
  88391. for(i = 0; i < 4; i++) {
  88392. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88393. return false; /* read_callback_ sets the state for us */
  88394. skip <<= 7;
  88395. skip |= (x & 0x7f);
  88396. }
  88397. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, skip))
  88398. return false; /* read_callback_ sets the state for us */
  88399. return true;
  88400. }
  88401. FLAC__bool frame_sync_(FLAC__StreamDecoder *decoder)
  88402. {
  88403. FLAC__uint32 x;
  88404. FLAC__bool first = true;
  88405. if(FLAC__stream_decoder_get_total_samples(decoder) > 0) {
  88406. if(decoder->private_->samples_decoded >= FLAC__stream_decoder_get_total_samples(decoder)) {
  88407. decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
  88408. return true;
  88409. }
  88410. }
  88411. if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input)) {
  88412. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__bitreader_bits_left_for_byte_alignment(decoder->private_->input)))
  88413. return false; /* read_callback_ sets the state for us */
  88414. }
  88415. while(1) {
  88416. if(decoder->private_->cached) {
  88417. x = (FLAC__uint32)decoder->private_->lookahead;
  88418. decoder->private_->cached = false;
  88419. }
  88420. else {
  88421. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88422. return false; /* read_callback_ sets the state for us */
  88423. }
  88424. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88425. decoder->private_->header_warmup[0] = (FLAC__byte)x;
  88426. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88427. return false; /* read_callback_ sets the state for us */
  88428. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88429. decoder->private_->lookahead = (FLAC__byte)x;
  88430. decoder->private_->cached = true;
  88431. }
  88432. else if(x >> 2 == 0x3e) { /* MAGIC NUMBER for the last 6 sync bits */
  88433. decoder->private_->header_warmup[1] = (FLAC__byte)x;
  88434. decoder->protected_->state = FLAC__STREAM_DECODER_READ_FRAME;
  88435. return true;
  88436. }
  88437. }
  88438. if(first) {
  88439. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88440. first = false;
  88441. }
  88442. }
  88443. return true;
  88444. }
  88445. FLAC__bool read_frame_(FLAC__StreamDecoder *decoder, FLAC__bool *got_a_frame, FLAC__bool do_full_decode)
  88446. {
  88447. unsigned channel;
  88448. unsigned i;
  88449. FLAC__int32 mid, side;
  88450. unsigned frame_crc; /* the one we calculate from the input stream */
  88451. FLAC__uint32 x;
  88452. *got_a_frame = false;
  88453. frame_crc = 0;
  88454. frame_crc = FLAC__CRC16_UPDATE(decoder->private_->header_warmup[0], frame_crc);
  88455. frame_crc = FLAC__CRC16_UPDATE(decoder->private_->header_warmup[1], frame_crc);
  88456. FLAC__bitreader_reset_read_crc16(decoder->private_->input, (FLAC__uint16)frame_crc);
  88457. if(!read_frame_header_(decoder))
  88458. return false;
  88459. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means we didn't sync on a valid header */
  88460. return true;
  88461. if(!allocate_output_(decoder, decoder->private_->frame.header.blocksize, decoder->private_->frame.header.channels))
  88462. return false;
  88463. for(channel = 0; channel < decoder->private_->frame.header.channels; channel++) {
  88464. unsigned bps = decoder->private_->frame.header.bits_per_sample;
  88465. switch(decoder->private_->frame.header.channel_assignment) {
  88466. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  88467. break;
  88468. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  88469. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88470. if(channel == 1)
  88471. bps++;
  88472. break;
  88473. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  88474. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88475. if(channel == 0)
  88476. bps++;
  88477. break;
  88478. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  88479. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88480. if(channel == 1)
  88481. bps++;
  88482. break;
  88483. default:
  88484. FLAC__ASSERT(0);
  88485. }
  88486. if(!read_subframe_(decoder, channel, bps, do_full_decode))
  88487. return false;
  88488. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption */
  88489. return true;
  88490. }
  88491. if(!read_zero_padding_(decoder))
  88492. return false;
  88493. 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) */
  88494. return true;
  88495. frame_crc = FLAC__bitreader_get_read_crc16(decoder->private_->input);
  88496. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__FRAME_FOOTER_CRC_LEN))
  88497. return false; /* read_callback_ sets the state for us */
  88498. if(frame_crc == x) {
  88499. if(do_full_decode) {
  88500. switch(decoder->private_->frame.header.channel_assignment) {
  88501. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  88502. break;
  88503. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  88504. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88505. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  88506. decoder->private_->output[1][i] = decoder->private_->output[0][i] - decoder->private_->output[1][i];
  88507. break;
  88508. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  88509. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88510. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  88511. decoder->private_->output[0][i] += decoder->private_->output[1][i];
  88512. break;
  88513. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  88514. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88515. for(i = 0; i < decoder->private_->frame.header.blocksize; i++) {
  88516. #if 1
  88517. mid = decoder->private_->output[0][i];
  88518. side = decoder->private_->output[1][i];
  88519. mid <<= 1;
  88520. mid |= (side & 1); /* i.e. if 'side' is odd... */
  88521. decoder->private_->output[0][i] = (mid + side) >> 1;
  88522. decoder->private_->output[1][i] = (mid - side) >> 1;
  88523. #else
  88524. mid = (decoder->private_->output[0][i] << 1) | (decoder->private_->output[1][i] & 1); /* i.e. if 'side' is odd... */
  88525. decoder->private_->output[0][i] = (mid + decoder->private_->output[1][i]) >> 1;
  88526. decoder->private_->output[1][i] = (mid - decoder->private_->output[1][i]) >> 1;
  88527. #endif
  88528. }
  88529. break;
  88530. default:
  88531. FLAC__ASSERT(0);
  88532. break;
  88533. }
  88534. }
  88535. }
  88536. else {
  88537. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH);
  88538. if(do_full_decode) {
  88539. for(channel = 0; channel < decoder->private_->frame.header.channels; channel++) {
  88540. memset(decoder->private_->output[channel], 0, sizeof(FLAC__int32) * decoder->private_->frame.header.blocksize);
  88541. }
  88542. }
  88543. }
  88544. *got_a_frame = true;
  88545. if(decoder->private_->next_fixed_block_size)
  88546. decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size;
  88547. decoder->protected_->channels = decoder->private_->frame.header.channels;
  88548. decoder->protected_->channel_assignment = decoder->private_->frame.header.channel_assignment;
  88549. decoder->protected_->bits_per_sample = decoder->private_->frame.header.bits_per_sample;
  88550. decoder->protected_->sample_rate = decoder->private_->frame.header.sample_rate;
  88551. decoder->protected_->blocksize = decoder->private_->frame.header.blocksize;
  88552. FLAC__ASSERT(decoder->private_->frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  88553. decoder->private_->samples_decoded = decoder->private_->frame.header.number.sample_number + decoder->private_->frame.header.blocksize;
  88554. if(do_full_decode) {
  88555. if(write_audio_frame_to_client_(decoder, &decoder->private_->frame, (const FLAC__int32 * const *)decoder->private_->output) != FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE)
  88556. return false;
  88557. }
  88558. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88559. return true;
  88560. }
  88561. FLAC__bool read_frame_header_(FLAC__StreamDecoder *decoder)
  88562. {
  88563. FLAC__uint32 x;
  88564. FLAC__uint64 xx;
  88565. unsigned i, blocksize_hint = 0, sample_rate_hint = 0;
  88566. FLAC__byte crc8, raw_header[16]; /* MAGIC NUMBER based on the maximum frame header size, including CRC */
  88567. unsigned raw_header_len;
  88568. FLAC__bool is_unparseable = false;
  88569. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88570. raw_header[0] = decoder->private_->header_warmup[0];
  88571. raw_header[1] = decoder->private_->header_warmup[1];
  88572. raw_header_len = 2;
  88573. if(raw_header[1] & 0x02) /* MAGIC NUMBER */
  88574. is_unparseable = true;
  88575. for(i = 0; i < 2; i++) {
  88576. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88577. return false; /* read_callback_ sets the state for us */
  88578. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88579. decoder->private_->lookahead = (FLAC__byte)x;
  88580. decoder->private_->cached = true;
  88581. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88582. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88583. return true;
  88584. }
  88585. raw_header[raw_header_len++] = (FLAC__byte)x;
  88586. }
  88587. switch(x = raw_header[2] >> 4) {
  88588. case 0:
  88589. is_unparseable = true;
  88590. break;
  88591. case 1:
  88592. decoder->private_->frame.header.blocksize = 192;
  88593. break;
  88594. case 2:
  88595. case 3:
  88596. case 4:
  88597. case 5:
  88598. decoder->private_->frame.header.blocksize = 576 << (x-2);
  88599. break;
  88600. case 6:
  88601. case 7:
  88602. blocksize_hint = x;
  88603. break;
  88604. case 8:
  88605. case 9:
  88606. case 10:
  88607. case 11:
  88608. case 12:
  88609. case 13:
  88610. case 14:
  88611. case 15:
  88612. decoder->private_->frame.header.blocksize = 256 << (x-8);
  88613. break;
  88614. default:
  88615. FLAC__ASSERT(0);
  88616. break;
  88617. }
  88618. switch(x = raw_header[2] & 0x0f) {
  88619. case 0:
  88620. if(decoder->private_->has_stream_info)
  88621. decoder->private_->frame.header.sample_rate = decoder->private_->stream_info.data.stream_info.sample_rate;
  88622. else
  88623. is_unparseable = true;
  88624. break;
  88625. case 1:
  88626. decoder->private_->frame.header.sample_rate = 88200;
  88627. break;
  88628. case 2:
  88629. decoder->private_->frame.header.sample_rate = 176400;
  88630. break;
  88631. case 3:
  88632. decoder->private_->frame.header.sample_rate = 192000;
  88633. break;
  88634. case 4:
  88635. decoder->private_->frame.header.sample_rate = 8000;
  88636. break;
  88637. case 5:
  88638. decoder->private_->frame.header.sample_rate = 16000;
  88639. break;
  88640. case 6:
  88641. decoder->private_->frame.header.sample_rate = 22050;
  88642. break;
  88643. case 7:
  88644. decoder->private_->frame.header.sample_rate = 24000;
  88645. break;
  88646. case 8:
  88647. decoder->private_->frame.header.sample_rate = 32000;
  88648. break;
  88649. case 9:
  88650. decoder->private_->frame.header.sample_rate = 44100;
  88651. break;
  88652. case 10:
  88653. decoder->private_->frame.header.sample_rate = 48000;
  88654. break;
  88655. case 11:
  88656. decoder->private_->frame.header.sample_rate = 96000;
  88657. break;
  88658. case 12:
  88659. case 13:
  88660. case 14:
  88661. sample_rate_hint = x;
  88662. break;
  88663. case 15:
  88664. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88665. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88666. return true;
  88667. default:
  88668. FLAC__ASSERT(0);
  88669. }
  88670. x = (unsigned)(raw_header[3] >> 4);
  88671. if(x & 8) {
  88672. decoder->private_->frame.header.channels = 2;
  88673. switch(x & 7) {
  88674. case 0:
  88675. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE;
  88676. break;
  88677. case 1:
  88678. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE;
  88679. break;
  88680. case 2:
  88681. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_MID_SIDE;
  88682. break;
  88683. default:
  88684. is_unparseable = true;
  88685. break;
  88686. }
  88687. }
  88688. else {
  88689. decoder->private_->frame.header.channels = (unsigned)x + 1;
  88690. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT;
  88691. }
  88692. switch(x = (unsigned)(raw_header[3] & 0x0e) >> 1) {
  88693. case 0:
  88694. if(decoder->private_->has_stream_info)
  88695. decoder->private_->frame.header.bits_per_sample = decoder->private_->stream_info.data.stream_info.bits_per_sample;
  88696. else
  88697. is_unparseable = true;
  88698. break;
  88699. case 1:
  88700. decoder->private_->frame.header.bits_per_sample = 8;
  88701. break;
  88702. case 2:
  88703. decoder->private_->frame.header.bits_per_sample = 12;
  88704. break;
  88705. case 4:
  88706. decoder->private_->frame.header.bits_per_sample = 16;
  88707. break;
  88708. case 5:
  88709. decoder->private_->frame.header.bits_per_sample = 20;
  88710. break;
  88711. case 6:
  88712. decoder->private_->frame.header.bits_per_sample = 24;
  88713. break;
  88714. case 3:
  88715. case 7:
  88716. is_unparseable = true;
  88717. break;
  88718. default:
  88719. FLAC__ASSERT(0);
  88720. break;
  88721. }
  88722. if(raw_header[3] & 0x01) /* MAGIC NUMBER */
  88723. is_unparseable = true;
  88724. if(
  88725. raw_header[1] & 0x01 ||
  88726. (decoder->private_->has_stream_info && decoder->private_->stream_info.data.stream_info.min_blocksize != decoder->private_->stream_info.data.stream_info.max_blocksize)
  88727. ) { /* variable blocksize */
  88728. if(!FLAC__bitreader_read_utf8_uint64(decoder->private_->input, &xx, raw_header, &raw_header_len))
  88729. return false; /* read_callback_ sets the state for us */
  88730. if(xx == FLAC__U64L(0xffffffffffffffff)) { /* i.e. non-UTF8 code... */
  88731. decoder->private_->lookahead = raw_header[raw_header_len-1]; /* back up as much as we can */
  88732. decoder->private_->cached = true;
  88733. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88734. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88735. return true;
  88736. }
  88737. decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER;
  88738. decoder->private_->frame.header.number.sample_number = xx;
  88739. }
  88740. else { /* fixed blocksize */
  88741. if(!FLAC__bitreader_read_utf8_uint32(decoder->private_->input, &x, raw_header, &raw_header_len))
  88742. return false; /* read_callback_ sets the state for us */
  88743. if(x == 0xffffffff) { /* i.e. non-UTF8 code... */
  88744. decoder->private_->lookahead = raw_header[raw_header_len-1]; /* back up as much as we can */
  88745. decoder->private_->cached = true;
  88746. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88747. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88748. return true;
  88749. }
  88750. decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER;
  88751. decoder->private_->frame.header.number.frame_number = x;
  88752. }
  88753. if(blocksize_hint) {
  88754. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88755. return false; /* read_callback_ sets the state for us */
  88756. raw_header[raw_header_len++] = (FLAC__byte)x;
  88757. if(blocksize_hint == 7) {
  88758. FLAC__uint32 _x;
  88759. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &_x, 8))
  88760. return false; /* read_callback_ sets the state for us */
  88761. raw_header[raw_header_len++] = (FLAC__byte)_x;
  88762. x = (x << 8) | _x;
  88763. }
  88764. decoder->private_->frame.header.blocksize = x+1;
  88765. }
  88766. if(sample_rate_hint) {
  88767. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88768. return false; /* read_callback_ sets the state for us */
  88769. raw_header[raw_header_len++] = (FLAC__byte)x;
  88770. if(sample_rate_hint != 12) {
  88771. FLAC__uint32 _x;
  88772. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &_x, 8))
  88773. return false; /* read_callback_ sets the state for us */
  88774. raw_header[raw_header_len++] = (FLAC__byte)_x;
  88775. x = (x << 8) | _x;
  88776. }
  88777. if(sample_rate_hint == 12)
  88778. decoder->private_->frame.header.sample_rate = x*1000;
  88779. else if(sample_rate_hint == 13)
  88780. decoder->private_->frame.header.sample_rate = x;
  88781. else
  88782. decoder->private_->frame.header.sample_rate = x*10;
  88783. }
  88784. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88785. return false; /* read_callback_ sets the state for us */
  88786. crc8 = (FLAC__byte)x;
  88787. if(FLAC__crc8(raw_header, raw_header_len) != crc8) {
  88788. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88789. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88790. return true;
  88791. }
  88792. decoder->private_->next_fixed_block_size = 0;
  88793. if(decoder->private_->frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER) {
  88794. x = decoder->private_->frame.header.number.frame_number;
  88795. decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER;
  88796. if(decoder->private_->fixed_block_size)
  88797. decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->fixed_block_size * (FLAC__uint64)x;
  88798. else if(decoder->private_->has_stream_info) {
  88799. if(decoder->private_->stream_info.data.stream_info.min_blocksize == decoder->private_->stream_info.data.stream_info.max_blocksize) {
  88800. decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->stream_info.data.stream_info.min_blocksize * (FLAC__uint64)x;
  88801. decoder->private_->next_fixed_block_size = decoder->private_->stream_info.data.stream_info.max_blocksize;
  88802. }
  88803. else
  88804. is_unparseable = true;
  88805. }
  88806. else if(x == 0) {
  88807. decoder->private_->frame.header.number.sample_number = 0;
  88808. decoder->private_->next_fixed_block_size = decoder->private_->frame.header.blocksize;
  88809. }
  88810. else {
  88811. decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->frame.header.blocksize * (FLAC__uint64)x;
  88812. }
  88813. }
  88814. if(is_unparseable) {
  88815. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  88816. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88817. return true;
  88818. }
  88819. return true;
  88820. }
  88821. FLAC__bool read_subframe_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
  88822. {
  88823. FLAC__uint32 x;
  88824. FLAC__bool wasted_bits;
  88825. unsigned i;
  88826. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8)) /* MAGIC NUMBER */
  88827. return false; /* read_callback_ sets the state for us */
  88828. wasted_bits = (x & 1);
  88829. x &= 0xfe;
  88830. if(wasted_bits) {
  88831. unsigned u;
  88832. if(!FLAC__bitreader_read_unary_unsigned(decoder->private_->input, &u))
  88833. return false; /* read_callback_ sets the state for us */
  88834. decoder->private_->frame.subframes[channel].wasted_bits = u+1;
  88835. bps -= decoder->private_->frame.subframes[channel].wasted_bits;
  88836. }
  88837. else
  88838. decoder->private_->frame.subframes[channel].wasted_bits = 0;
  88839. if(x & 0x80) {
  88840. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88841. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88842. return true;
  88843. }
  88844. else if(x == 0) {
  88845. if(!read_subframe_constant_(decoder, channel, bps, do_full_decode))
  88846. return false;
  88847. }
  88848. else if(x == 2) {
  88849. if(!read_subframe_verbatim_(decoder, channel, bps, do_full_decode))
  88850. return false;
  88851. }
  88852. else if(x < 16) {
  88853. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  88854. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88855. return true;
  88856. }
  88857. else if(x <= 24) {
  88858. if(!read_subframe_fixed_(decoder, channel, bps, (x>>1)&7, do_full_decode))
  88859. return false;
  88860. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption */
  88861. return true;
  88862. }
  88863. else if(x < 64) {
  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 {
  88869. if(!read_subframe_lpc_(decoder, channel, bps, ((x>>1)&31)+1, 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. if(wasted_bits && do_full_decode) {
  88875. x = decoder->private_->frame.subframes[channel].wasted_bits;
  88876. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  88877. decoder->private_->output[channel][i] <<= x;
  88878. }
  88879. return true;
  88880. }
  88881. FLAC__bool read_subframe_constant_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
  88882. {
  88883. FLAC__Subframe_Constant *subframe = &decoder->private_->frame.subframes[channel].data.constant;
  88884. FLAC__int32 x;
  88885. unsigned i;
  88886. FLAC__int32 *output = decoder->private_->output[channel];
  88887. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_CONSTANT;
  88888. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &x, bps))
  88889. return false; /* read_callback_ sets the state for us */
  88890. subframe->value = x;
  88891. if(do_full_decode) {
  88892. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  88893. output[i] = x;
  88894. }
  88895. return true;
  88896. }
  88897. FLAC__bool read_subframe_fixed_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode)
  88898. {
  88899. FLAC__Subframe_Fixed *subframe = &decoder->private_->frame.subframes[channel].data.fixed;
  88900. FLAC__int32 i32;
  88901. FLAC__uint32 u32;
  88902. unsigned u;
  88903. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_FIXED;
  88904. subframe->residual = decoder->private_->residual[channel];
  88905. subframe->order = order;
  88906. for(u = 0; u < order; u++) {
  88907. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, bps))
  88908. return false; /* read_callback_ sets the state for us */
  88909. subframe->warmup[u] = i32;
  88910. }
  88911. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN))
  88912. return false; /* read_callback_ sets the state for us */
  88913. subframe->entropy_coding_method.type = (FLAC__EntropyCodingMethodType)u32;
  88914. switch(subframe->entropy_coding_method.type) {
  88915. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  88916. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  88917. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  88918. return false; /* read_callback_ sets the state for us */
  88919. subframe->entropy_coding_method.data.partitioned_rice.order = u32;
  88920. subframe->entropy_coding_method.data.partitioned_rice.contents = &decoder->private_->partitioned_rice_contents[channel];
  88921. break;
  88922. default:
  88923. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  88924. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88925. return true;
  88926. }
  88927. switch(subframe->entropy_coding_method.type) {
  88928. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  88929. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  88930. 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))
  88931. return false;
  88932. break;
  88933. default:
  88934. FLAC__ASSERT(0);
  88935. }
  88936. if(do_full_decode) {
  88937. memcpy(decoder->private_->output[channel], subframe->warmup, sizeof(FLAC__int32) * order);
  88938. FLAC__fixed_restore_signal(decoder->private_->residual[channel], decoder->private_->frame.header.blocksize-order, order, decoder->private_->output[channel]+order);
  88939. }
  88940. return true;
  88941. }
  88942. FLAC__bool read_subframe_lpc_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode)
  88943. {
  88944. FLAC__Subframe_LPC *subframe = &decoder->private_->frame.subframes[channel].data.lpc;
  88945. FLAC__int32 i32;
  88946. FLAC__uint32 u32;
  88947. unsigned u;
  88948. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_LPC;
  88949. subframe->residual = decoder->private_->residual[channel];
  88950. subframe->order = order;
  88951. for(u = 0; u < order; u++) {
  88952. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, bps))
  88953. return false; /* read_callback_ sets the state for us */
  88954. subframe->warmup[u] = i32;
  88955. }
  88956. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN))
  88957. return false; /* read_callback_ sets the state for us */
  88958. if(u32 == (1u << FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN) - 1) {
  88959. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88960. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88961. return true;
  88962. }
  88963. subframe->qlp_coeff_precision = u32+1;
  88964. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN))
  88965. return false; /* read_callback_ sets the state for us */
  88966. subframe->quantization_level = i32;
  88967. for(u = 0; u < order; u++) {
  88968. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, subframe->qlp_coeff_precision))
  88969. return false; /* read_callback_ sets the state for us */
  88970. subframe->qlp_coeff[u] = i32;
  88971. }
  88972. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN))
  88973. return false; /* read_callback_ sets the state for us */
  88974. subframe->entropy_coding_method.type = (FLAC__EntropyCodingMethodType)u32;
  88975. switch(subframe->entropy_coding_method.type) {
  88976. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  88977. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  88978. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  88979. return false; /* read_callback_ sets the state for us */
  88980. subframe->entropy_coding_method.data.partitioned_rice.order = u32;
  88981. subframe->entropy_coding_method.data.partitioned_rice.contents = &decoder->private_->partitioned_rice_contents[channel];
  88982. break;
  88983. default:
  88984. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  88985. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88986. return true;
  88987. }
  88988. switch(subframe->entropy_coding_method.type) {
  88989. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  88990. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  88991. 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))
  88992. return false;
  88993. break;
  88994. default:
  88995. FLAC__ASSERT(0);
  88996. }
  88997. if(do_full_decode) {
  88998. memcpy(decoder->private_->output[channel], subframe->warmup, sizeof(FLAC__int32) * order);
  88999. if(bps + subframe->qlp_coeff_precision + FLAC__bitmath_ilog2(order) <= 32)
  89000. if(bps <= 16 && subframe->qlp_coeff_precision <= 16) {
  89001. if(order <= 8)
  89002. 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);
  89003. else
  89004. 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);
  89005. }
  89006. else
  89007. 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);
  89008. else
  89009. 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);
  89010. }
  89011. return true;
  89012. }
  89013. FLAC__bool read_subframe_verbatim_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
  89014. {
  89015. FLAC__Subframe_Verbatim *subframe = &decoder->private_->frame.subframes[channel].data.verbatim;
  89016. FLAC__int32 x, *residual = decoder->private_->residual[channel];
  89017. unsigned i;
  89018. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_VERBATIM;
  89019. subframe->data = residual;
  89020. for(i = 0; i < decoder->private_->frame.header.blocksize; i++) {
  89021. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &x, bps))
  89022. return false; /* read_callback_ sets the state for us */
  89023. residual[i] = x;
  89024. }
  89025. if(do_full_decode)
  89026. memcpy(decoder->private_->output[channel], subframe->data, sizeof(FLAC__int32) * decoder->private_->frame.header.blocksize);
  89027. return true;
  89028. }
  89029. 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)
  89030. {
  89031. FLAC__uint32 rice_parameter;
  89032. int i;
  89033. unsigned partition, sample, u;
  89034. const unsigned partitions = 1u << partition_order;
  89035. const unsigned partition_samples = partition_order > 0? decoder->private_->frame.header.blocksize >> partition_order : decoder->private_->frame.header.blocksize - predictor_order;
  89036. const unsigned plen = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN;
  89037. const unsigned pesc = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  89038. if(partition_order == 0) {
  89039. if(decoder->private_->frame.header.blocksize < predictor_order) {
  89040. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  89041. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89042. return true;
  89043. }
  89044. }
  89045. else {
  89046. if(partition_samples < predictor_order) {
  89047. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  89048. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89049. return true;
  89050. }
  89051. }
  89052. if(!FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(partitioned_rice_contents, max(6, partition_order))) {
  89053. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  89054. return false;
  89055. }
  89056. sample = 0;
  89057. for(partition = 0; partition < partitions; partition++) {
  89058. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &rice_parameter, plen))
  89059. return false; /* read_callback_ sets the state for us */
  89060. partitioned_rice_contents->parameters[partition] = rice_parameter;
  89061. if(rice_parameter < pesc) {
  89062. partitioned_rice_contents->raw_bits[partition] = 0;
  89063. u = (partition_order == 0 || partition > 0)? partition_samples : partition_samples - predictor_order;
  89064. if(!decoder->private_->local_bitreader_read_rice_signed_block(decoder->private_->input, (int*) residual + sample, u, rice_parameter))
  89065. return false; /* read_callback_ sets the state for us */
  89066. sample += u;
  89067. }
  89068. else {
  89069. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &rice_parameter, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN))
  89070. return false; /* read_callback_ sets the state for us */
  89071. partitioned_rice_contents->raw_bits[partition] = rice_parameter;
  89072. for(u = (partition_order == 0 || partition > 0)? 0 : predictor_order; u < partition_samples; u++, sample++) {
  89073. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, (FLAC__int32*) &i, rice_parameter))
  89074. return false; /* read_callback_ sets the state for us */
  89075. residual[sample] = i;
  89076. }
  89077. }
  89078. }
  89079. return true;
  89080. }
  89081. FLAC__bool read_zero_padding_(FLAC__StreamDecoder *decoder)
  89082. {
  89083. if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input)) {
  89084. FLAC__uint32 zero = 0;
  89085. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &zero, FLAC__bitreader_bits_left_for_byte_alignment(decoder->private_->input)))
  89086. return false; /* read_callback_ sets the state for us */
  89087. if(zero != 0) {
  89088. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  89089. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89090. }
  89091. }
  89092. return true;
  89093. }
  89094. FLAC__bool read_callback_(FLAC__byte buffer[], size_t *bytes, void *client_data)
  89095. {
  89096. FLAC__StreamDecoder *decoder = (FLAC__StreamDecoder *)client_data;
  89097. if(
  89098. #if FLAC__HAS_OGG
  89099. !decoder->private_->is_ogg &&
  89100. #endif
  89101. decoder->private_->eof_callback && decoder->private_->eof_callback(decoder, decoder->private_->client_data)
  89102. ) {
  89103. *bytes = 0;
  89104. decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
  89105. return false;
  89106. }
  89107. else if(*bytes > 0) {
  89108. if(decoder->private_->is_seeking && decoder->private_->unparseable_frame_count > 20) {
  89109. decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
  89110. return false;
  89111. }
  89112. else {
  89113. const FLAC__StreamDecoderReadStatus status =
  89114. #if FLAC__HAS_OGG
  89115. decoder->private_->is_ogg?
  89116. read_callback_ogg_aspect_(decoder, buffer, bytes) :
  89117. #endif
  89118. decoder->private_->read_callback(decoder, buffer, bytes, decoder->private_->client_data)
  89119. ;
  89120. if(status == FLAC__STREAM_DECODER_READ_STATUS_ABORT) {
  89121. decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
  89122. return false;
  89123. }
  89124. else if(*bytes == 0) {
  89125. if(
  89126. status == FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM ||
  89127. (
  89128. #if FLAC__HAS_OGG
  89129. !decoder->private_->is_ogg &&
  89130. #endif
  89131. decoder->private_->eof_callback && decoder->private_->eof_callback(decoder, decoder->private_->client_data)
  89132. )
  89133. ) {
  89134. decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
  89135. return false;
  89136. }
  89137. else
  89138. return true;
  89139. }
  89140. else
  89141. return true;
  89142. }
  89143. }
  89144. else {
  89145. decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
  89146. return false;
  89147. }
  89148. }
  89149. #if FLAC__HAS_OGG
  89150. FLAC__StreamDecoderReadStatus read_callback_ogg_aspect_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes)
  89151. {
  89152. switch(FLAC__ogg_decoder_aspect_read_callback_wrapper(&decoder->protected_->ogg_decoder_aspect, buffer, bytes, read_callback_proxy_, decoder, decoder->private_->client_data)) {
  89153. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_OK:
  89154. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  89155. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_LOST_SYNC:
  89156. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  89157. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM:
  89158. return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
  89159. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_NOT_FLAC:
  89160. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_UNSUPPORTED_MAPPING_VERSION:
  89161. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT:
  89162. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_ERROR:
  89163. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_MEMORY_ALLOCATION_ERROR:
  89164. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  89165. default:
  89166. FLAC__ASSERT(0);
  89167. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  89168. }
  89169. }
  89170. FLAC__OggDecoderAspectReadStatus read_callback_proxy_(const void *void_decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  89171. {
  89172. FLAC__StreamDecoder *decoder = (FLAC__StreamDecoder*)void_decoder;
  89173. switch(decoder->private_->read_callback(decoder, buffer, bytes, client_data)) {
  89174. case FLAC__STREAM_DECODER_READ_STATUS_CONTINUE:
  89175. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_OK;
  89176. case FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM:
  89177. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM;
  89178. case FLAC__STREAM_DECODER_READ_STATUS_ABORT:
  89179. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT;
  89180. default:
  89181. FLAC__ASSERT(0);
  89182. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT;
  89183. }
  89184. }
  89185. #endif
  89186. FLAC__StreamDecoderWriteStatus write_audio_frame_to_client_(FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[])
  89187. {
  89188. if(decoder->private_->is_seeking) {
  89189. FLAC__uint64 this_frame_sample = frame->header.number.sample_number;
  89190. FLAC__uint64 next_frame_sample = this_frame_sample + (FLAC__uint64)frame->header.blocksize;
  89191. FLAC__uint64 target_sample = decoder->private_->target_sample;
  89192. FLAC__ASSERT(frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  89193. #if FLAC__HAS_OGG
  89194. decoder->private_->got_a_frame = true;
  89195. #endif
  89196. decoder->private_->last_frame = *frame; /* save the frame */
  89197. if(this_frame_sample <= target_sample && target_sample < next_frame_sample) { /* we hit our target frame */
  89198. unsigned delta = (unsigned)(target_sample - this_frame_sample);
  89199. decoder->private_->is_seeking = false;
  89200. if(delta > 0) {
  89201. unsigned channel;
  89202. const FLAC__int32 *newbuffer[FLAC__MAX_CHANNELS];
  89203. for(channel = 0; channel < frame->header.channels; channel++)
  89204. newbuffer[channel] = buffer[channel] + delta;
  89205. decoder->private_->last_frame.header.blocksize -= delta;
  89206. decoder->private_->last_frame.header.number.sample_number += (FLAC__uint64)delta;
  89207. return decoder->private_->write_callback(decoder, &decoder->private_->last_frame, newbuffer, decoder->private_->client_data);
  89208. }
  89209. else {
  89210. return decoder->private_->write_callback(decoder, frame, buffer, decoder->private_->client_data);
  89211. }
  89212. }
  89213. return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  89214. }
  89215. if(!decoder->private_->has_stream_info)
  89216. decoder->private_->do_md5_checking = false;
  89217. if(decoder->private_->do_md5_checking) {
  89218. if(!FLAC__MD5Accumulate(&decoder->private_->md5context, buffer, frame->header.channels, frame->header.blocksize, (frame->header.bits_per_sample+7) / 8))
  89219. return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
  89220. }
  89221. return decoder->private_->write_callback(decoder, frame, buffer, decoder->private_->client_data);
  89222. }
  89223. void send_error_to_client_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status)
  89224. {
  89225. if(!decoder->private_->is_seeking)
  89226. decoder->private_->error_callback(decoder, status, decoder->private_->client_data);
  89227. else if(status == FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM)
  89228. decoder->private_->unparseable_frame_count++;
  89229. }
  89230. FLAC__bool seek_to_absolute_sample_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample)
  89231. {
  89232. FLAC__uint64 first_frame_offset = decoder->private_->first_frame_offset, lower_bound, upper_bound, lower_bound_sample, upper_bound_sample, this_frame_sample;
  89233. FLAC__int64 pos = -1;
  89234. int i;
  89235. unsigned approx_bytes_per_frame;
  89236. FLAC__bool first_seek = true;
  89237. const FLAC__uint64 total_samples = FLAC__stream_decoder_get_total_samples(decoder);
  89238. const unsigned min_blocksize = decoder->private_->stream_info.data.stream_info.min_blocksize;
  89239. const unsigned max_blocksize = decoder->private_->stream_info.data.stream_info.max_blocksize;
  89240. const unsigned max_framesize = decoder->private_->stream_info.data.stream_info.max_framesize;
  89241. const unsigned min_framesize = decoder->private_->stream_info.data.stream_info.min_framesize;
  89242. unsigned channels = FLAC__stream_decoder_get_channels(decoder);
  89243. unsigned bps = FLAC__stream_decoder_get_bits_per_sample(decoder);
  89244. const FLAC__StreamMetadata_SeekTable *seek_table = decoder->private_->has_seek_table? &decoder->private_->seek_table.data.seek_table : 0;
  89245. if(channels == 0)
  89246. channels = decoder->private_->stream_info.data.stream_info.channels;
  89247. if(bps == 0)
  89248. bps = decoder->private_->stream_info.data.stream_info.bits_per_sample;
  89249. if(max_framesize > 0)
  89250. approx_bytes_per_frame = (max_framesize + min_framesize) / 2 + 1;
  89251. else if(min_blocksize == max_blocksize && min_blocksize > 0) {
  89252. approx_bytes_per_frame = min_blocksize * channels * bps/8 + 64;
  89253. }
  89254. else
  89255. approx_bytes_per_frame = 4096 * channels * bps/8 + 64;
  89256. lower_bound = first_frame_offset;
  89257. lower_bound_sample = 0;
  89258. upper_bound = stream_length;
  89259. upper_bound_sample = total_samples > 0 ? total_samples : target_sample /*estimate it*/;
  89260. if(seek_table) {
  89261. FLAC__uint64 new_lower_bound = lower_bound;
  89262. FLAC__uint64 new_upper_bound = upper_bound;
  89263. FLAC__uint64 new_lower_bound_sample = lower_bound_sample;
  89264. FLAC__uint64 new_upper_bound_sample = upper_bound_sample;
  89265. for(i = (int)seek_table->num_points - 1; i >= 0; i--) {
  89266. if(
  89267. seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER &&
  89268. seek_table->points[i].frame_samples > 0 && /* defense against bad seekpoints */
  89269. (total_samples <= 0 || seek_table->points[i].sample_number < total_samples) && /* defense against bad seekpoints */
  89270. seek_table->points[i].sample_number <= target_sample
  89271. )
  89272. break;
  89273. }
  89274. if(i >= 0) { /* i.e. we found a suitable seek point... */
  89275. new_lower_bound = first_frame_offset + seek_table->points[i].stream_offset;
  89276. new_lower_bound_sample = seek_table->points[i].sample_number;
  89277. }
  89278. for(i = 0; i < (int)seek_table->num_points; i++) {
  89279. if(
  89280. seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER &&
  89281. seek_table->points[i].frame_samples > 0 && /* defense against bad seekpoints */
  89282. (total_samples <= 0 || seek_table->points[i].sample_number < total_samples) && /* defense against bad seekpoints */
  89283. seek_table->points[i].sample_number > target_sample
  89284. )
  89285. break;
  89286. }
  89287. if(i < (int)seek_table->num_points) { /* i.e. we found a suitable seek point... */
  89288. new_upper_bound = first_frame_offset + seek_table->points[i].stream_offset;
  89289. new_upper_bound_sample = seek_table->points[i].sample_number;
  89290. }
  89291. if(new_upper_bound >= new_lower_bound) {
  89292. lower_bound = new_lower_bound;
  89293. upper_bound = new_upper_bound;
  89294. lower_bound_sample = new_lower_bound_sample;
  89295. upper_bound_sample = new_upper_bound_sample;
  89296. }
  89297. }
  89298. FLAC__ASSERT(upper_bound_sample >= lower_bound_sample);
  89299. if(upper_bound_sample == lower_bound_sample)
  89300. upper_bound_sample++;
  89301. decoder->private_->target_sample = target_sample;
  89302. while(1) {
  89303. if (lower_bound_sample >= upper_bound_sample || lower_bound > upper_bound) {
  89304. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89305. return false;
  89306. }
  89307. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89308. #if defined _MSC_VER || defined __MINGW32__
  89309. 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;
  89310. #else
  89311. 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;
  89312. #endif
  89313. #else
  89314. if(upper_bound - lower_bound < 0xffffffff)
  89315. 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;
  89316. else /* @@@ WATCHOUT, ~2TB limit */
  89317. 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;
  89318. #endif
  89319. if(pos >= (FLAC__int64)upper_bound)
  89320. pos = (FLAC__int64)upper_bound - 1;
  89321. if(pos < (FLAC__int64)lower_bound)
  89322. pos = (FLAC__int64)lower_bound;
  89323. if(decoder->private_->seek_callback(decoder, (FLAC__uint64)pos, decoder->private_->client_data) != FLAC__STREAM_DECODER_SEEK_STATUS_OK) {
  89324. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89325. return false;
  89326. }
  89327. if(!FLAC__stream_decoder_flush(decoder)) {
  89328. return false;
  89329. }
  89330. decoder->private_->unparseable_frame_count = 0;
  89331. if(!FLAC__stream_decoder_process_single(decoder)) {
  89332. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89333. return false;
  89334. }
  89335. #if 0
  89336. if(decoder->protected_->state != FLAC__SEEKABLE_STREAM_DECODER_SEEKING && decoder->protected_->state != FLAC__STREAM_DECODER_END_OF_STREAM)
  89337. break;
  89338. #endif
  89339. if(!decoder->private_->is_seeking)
  89340. break;
  89341. FLAC__ASSERT(decoder->private_->last_frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  89342. this_frame_sample = decoder->private_->last_frame.header.number.sample_number;
  89343. if (0 == decoder->private_->samples_decoded || (this_frame_sample + decoder->private_->last_frame.header.blocksize >= upper_bound_sample && !first_seek)) {
  89344. if (pos == (FLAC__int64)lower_bound) {
  89345. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89346. return false;
  89347. }
  89348. approx_bytes_per_frame = approx_bytes_per_frame? approx_bytes_per_frame * 2 : 16;
  89349. continue;
  89350. }
  89351. first_seek = false;
  89352. if (this_frame_sample < lower_bound_sample) {
  89353. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89354. return false;
  89355. }
  89356. if(target_sample < this_frame_sample) {
  89357. upper_bound_sample = this_frame_sample + decoder->private_->last_frame.header.blocksize;
  89358. if(!FLAC__stream_decoder_get_decode_position(decoder, &upper_bound)) {
  89359. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89360. return false;
  89361. }
  89362. approx_bytes_per_frame = (unsigned)(2 * (upper_bound - pos) / 3 + 16);
  89363. }
  89364. else { /* target_sample >= this_frame_sample + this frame's blocksize */
  89365. lower_bound_sample = this_frame_sample + decoder->private_->last_frame.header.blocksize;
  89366. if(!FLAC__stream_decoder_get_decode_position(decoder, &lower_bound)) {
  89367. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89368. return false;
  89369. }
  89370. approx_bytes_per_frame = (unsigned)(2 * (lower_bound - pos) / 3 + 16);
  89371. }
  89372. }
  89373. return true;
  89374. }
  89375. #if FLAC__HAS_OGG
  89376. FLAC__bool seek_to_absolute_sample_ogg_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample)
  89377. {
  89378. FLAC__uint64 left_pos = 0, right_pos = stream_length;
  89379. FLAC__uint64 left_sample = 0, right_sample = FLAC__stream_decoder_get_total_samples(decoder);
  89380. FLAC__uint64 this_frame_sample = (FLAC__uint64)0 - 1;
  89381. FLAC__uint64 pos = 0; /* only initialized to avoid compiler warning */
  89382. FLAC__bool did_a_seek;
  89383. unsigned iteration = 0;
  89384. unsigned BINARY_SEARCH_AFTER_ITERATION = 2;
  89385. static const FLAC__uint64 LINEAR_SEARCH_WITHIN_SAMPLES = FLAC__MAX_BLOCK_SIZE * 2;
  89386. if(right_sample == 0) {
  89387. right_sample = (FLAC__uint64)(-1);
  89388. BINARY_SEARCH_AFTER_ITERATION = 0;
  89389. }
  89390. decoder->private_->target_sample = target_sample;
  89391. for( ; ; iteration++) {
  89392. if (iteration == 0 || this_frame_sample > target_sample || target_sample - this_frame_sample > LINEAR_SEARCH_WITHIN_SAMPLES) {
  89393. if (iteration >= BINARY_SEARCH_AFTER_ITERATION) {
  89394. pos = (right_pos + left_pos) / 2;
  89395. }
  89396. else {
  89397. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89398. #if defined _MSC_VER || defined __MINGW32__
  89399. 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));
  89400. #else
  89401. pos = (FLAC__uint64)((FLAC__double)(target_sample - left_sample) / (FLAC__double)(right_sample - left_sample) * (FLAC__double)(right_pos - left_pos));
  89402. #endif
  89403. #else
  89404. if ((target_sample-left_sample <= 0xffffffff) && (right_pos-left_pos <= 0xffffffff))
  89405. pos = (FLAC__int64)(((target_sample-left_sample) * (right_pos-left_pos)) / (right_sample-left_sample));
  89406. else /* @@@ WATCHOUT, ~2TB limit */
  89407. pos = (FLAC__int64)((((target_sample-left_sample)>>8) * ((right_pos-left_pos)>>8)) / ((right_sample-left_sample)>>16));
  89408. #endif
  89409. }
  89410. if(decoder->private_->seek_callback((FLAC__StreamDecoder*)decoder, (FLAC__uint64)pos, decoder->private_->client_data) != FLAC__STREAM_DECODER_SEEK_STATUS_OK) {
  89411. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89412. return false;
  89413. }
  89414. if(!FLAC__stream_decoder_flush(decoder)) {
  89415. return false;
  89416. }
  89417. did_a_seek = true;
  89418. }
  89419. else
  89420. did_a_seek = false;
  89421. decoder->private_->got_a_frame = false;
  89422. if(!FLAC__stream_decoder_process_single(decoder)) {
  89423. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89424. return false;
  89425. }
  89426. if(!decoder->private_->got_a_frame) {
  89427. if(did_a_seek) {
  89428. right_pos = pos;
  89429. BINARY_SEARCH_AFTER_ITERATION = 0;
  89430. }
  89431. else {
  89432. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89433. return false;
  89434. }
  89435. }
  89436. else if(!decoder->private_->is_seeking) {
  89437. break;
  89438. }
  89439. else {
  89440. this_frame_sample = decoder->private_->last_frame.header.number.sample_number;
  89441. FLAC__ASSERT(decoder->private_->last_frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  89442. if (did_a_seek) {
  89443. if (this_frame_sample <= target_sample) {
  89444. FLAC__ASSERT(this_frame_sample != target_sample);
  89445. left_sample = this_frame_sample;
  89446. if (left_pos == pos) {
  89447. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89448. return false;
  89449. }
  89450. left_pos = pos;
  89451. }
  89452. else if(this_frame_sample > target_sample) {
  89453. right_sample = this_frame_sample;
  89454. if (right_pos == pos) {
  89455. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89456. return false;
  89457. }
  89458. right_pos = pos;
  89459. }
  89460. }
  89461. }
  89462. }
  89463. return true;
  89464. }
  89465. #endif
  89466. FLAC__StreamDecoderReadStatus file_read_callback_dec(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  89467. {
  89468. (void)client_data;
  89469. if(*bytes > 0) {
  89470. *bytes = fread(buffer, sizeof(FLAC__byte), *bytes, decoder->private_->file);
  89471. if(ferror(decoder->private_->file))
  89472. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  89473. else if(*bytes == 0)
  89474. return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
  89475. else
  89476. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  89477. }
  89478. else
  89479. return FLAC__STREAM_DECODER_READ_STATUS_ABORT; /* abort to avoid a deadlock */
  89480. }
  89481. FLAC__StreamDecoderSeekStatus file_seek_callback_dec(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data)
  89482. {
  89483. (void)client_data;
  89484. if(decoder->private_->file == stdin)
  89485. return FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED;
  89486. else if(fseeko(decoder->private_->file, (off_t)absolute_byte_offset, SEEK_SET) < 0)
  89487. return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR;
  89488. else
  89489. return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
  89490. }
  89491. FLAC__StreamDecoderTellStatus file_tell_callback_dec(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
  89492. {
  89493. off_t pos;
  89494. (void)client_data;
  89495. if(decoder->private_->file == stdin)
  89496. return FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED;
  89497. else if((pos = ftello(decoder->private_->file)) < 0)
  89498. return FLAC__STREAM_DECODER_TELL_STATUS_ERROR;
  89499. else {
  89500. *absolute_byte_offset = (FLAC__uint64)pos;
  89501. return FLAC__STREAM_DECODER_TELL_STATUS_OK;
  89502. }
  89503. }
  89504. FLAC__StreamDecoderLengthStatus file_length_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data)
  89505. {
  89506. struct stat filestats;
  89507. (void)client_data;
  89508. if(decoder->private_->file == stdin)
  89509. return FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED;
  89510. else if(fstat(fileno(decoder->private_->file), &filestats) != 0)
  89511. return FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR;
  89512. else {
  89513. *stream_length = (FLAC__uint64)filestats.st_size;
  89514. return FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
  89515. }
  89516. }
  89517. FLAC__bool file_eof_callback_(const FLAC__StreamDecoder *decoder, void *client_data)
  89518. {
  89519. (void)client_data;
  89520. return feof(decoder->private_->file)? true : false;
  89521. }
  89522. #endif
  89523. /*** End of inlined file: stream_decoder.c ***/
  89524. /*** Start of inlined file: stream_encoder.c ***/
  89525. /*** Start of inlined file: juce_FlacHeader.h ***/
  89526. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  89527. // tasks..
  89528. #define VERSION "1.2.1"
  89529. #define FLAC__NO_DLL 1
  89530. #if JUCE_MSVC
  89531. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  89532. #endif
  89533. #if JUCE_MAC
  89534. #define FLAC__SYS_DARWIN 1
  89535. #endif
  89536. /*** End of inlined file: juce_FlacHeader.h ***/
  89537. #if JUCE_USE_FLAC
  89538. #if HAVE_CONFIG_H
  89539. # include <config.h>
  89540. #endif
  89541. #if defined _MSC_VER || defined __MINGW32__
  89542. #include <io.h> /* for _setmode() */
  89543. #include <fcntl.h> /* for _O_BINARY */
  89544. #endif
  89545. #if defined __CYGWIN__ || defined __EMX__
  89546. #include <io.h> /* for setmode(), O_BINARY */
  89547. #include <fcntl.h> /* for _O_BINARY */
  89548. #endif
  89549. #include <limits.h>
  89550. #include <stdio.h>
  89551. #include <stdlib.h> /* for malloc() */
  89552. #include <string.h> /* for memcpy() */
  89553. #include <sys/types.h> /* for off_t */
  89554. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINGW32__
  89555. #if _MSC_VER <= 1600 || defined __BORLANDC__ /* @@@ [2G limit] */
  89556. #define fseeko fseek
  89557. #define ftello ftell
  89558. #endif
  89559. #endif
  89560. /*** Start of inlined file: stream_encoder.h ***/
  89561. #ifndef FLAC__PROTECTED__STREAM_ENCODER_H
  89562. #define FLAC__PROTECTED__STREAM_ENCODER_H
  89563. #if FLAC__HAS_OGG
  89564. #include "private/ogg_encoder_aspect.h"
  89565. #endif
  89566. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89567. #define FLAC__MAX_APODIZATION_FUNCTIONS 32
  89568. typedef enum {
  89569. FLAC__APODIZATION_BARTLETT,
  89570. FLAC__APODIZATION_BARTLETT_HANN,
  89571. FLAC__APODIZATION_BLACKMAN,
  89572. FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE,
  89573. FLAC__APODIZATION_CONNES,
  89574. FLAC__APODIZATION_FLATTOP,
  89575. FLAC__APODIZATION_GAUSS,
  89576. FLAC__APODIZATION_HAMMING,
  89577. FLAC__APODIZATION_HANN,
  89578. FLAC__APODIZATION_KAISER_BESSEL,
  89579. FLAC__APODIZATION_NUTTALL,
  89580. FLAC__APODIZATION_RECTANGLE,
  89581. FLAC__APODIZATION_TRIANGLE,
  89582. FLAC__APODIZATION_TUKEY,
  89583. FLAC__APODIZATION_WELCH
  89584. } FLAC__ApodizationFunction;
  89585. typedef struct {
  89586. FLAC__ApodizationFunction type;
  89587. union {
  89588. struct {
  89589. FLAC__real stddev;
  89590. } gauss;
  89591. struct {
  89592. FLAC__real p;
  89593. } tukey;
  89594. } parameters;
  89595. } FLAC__ApodizationSpecification;
  89596. #endif // #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89597. typedef struct FLAC__StreamEncoderProtected {
  89598. FLAC__StreamEncoderState state;
  89599. FLAC__bool verify;
  89600. FLAC__bool streamable_subset;
  89601. FLAC__bool do_md5;
  89602. FLAC__bool do_mid_side_stereo;
  89603. FLAC__bool loose_mid_side_stereo;
  89604. unsigned channels;
  89605. unsigned bits_per_sample;
  89606. unsigned sample_rate;
  89607. unsigned blocksize;
  89608. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89609. unsigned num_apodizations;
  89610. FLAC__ApodizationSpecification apodizations[FLAC__MAX_APODIZATION_FUNCTIONS];
  89611. #endif
  89612. unsigned max_lpc_order;
  89613. unsigned qlp_coeff_precision;
  89614. FLAC__bool do_qlp_coeff_prec_search;
  89615. FLAC__bool do_exhaustive_model_search;
  89616. FLAC__bool do_escape_coding;
  89617. unsigned min_residual_partition_order;
  89618. unsigned max_residual_partition_order;
  89619. unsigned rice_parameter_search_dist;
  89620. FLAC__uint64 total_samples_estimate;
  89621. FLAC__StreamMetadata **metadata;
  89622. unsigned num_metadata_blocks;
  89623. FLAC__uint64 streaminfo_offset, seektable_offset, audio_offset;
  89624. #if FLAC__HAS_OGG
  89625. FLAC__OggEncoderAspect ogg_encoder_aspect;
  89626. #endif
  89627. } FLAC__StreamEncoderProtected;
  89628. #endif
  89629. /*** End of inlined file: stream_encoder.h ***/
  89630. #if FLAC__HAS_OGG
  89631. #include "include/private/ogg_helper.h"
  89632. #include "include/private/ogg_mapping.h"
  89633. #endif
  89634. /*** Start of inlined file: stream_encoder_framing.h ***/
  89635. #ifndef FLAC__PRIVATE__STREAM_ENCODER_FRAMING_H
  89636. #define FLAC__PRIVATE__STREAM_ENCODER_FRAMING_H
  89637. FLAC__bool FLAC__add_metadata_block(const FLAC__StreamMetadata *metadata, FLAC__BitWriter *bw);
  89638. FLAC__bool FLAC__frame_add_header(const FLAC__FrameHeader *header, FLAC__BitWriter *bw);
  89639. FLAC__bool FLAC__subframe_add_constant(const FLAC__Subframe_Constant *subframe, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  89640. FLAC__bool FLAC__subframe_add_fixed(const FLAC__Subframe_Fixed *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  89641. FLAC__bool FLAC__subframe_add_lpc(const FLAC__Subframe_LPC *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  89642. FLAC__bool FLAC__subframe_add_verbatim(const FLAC__Subframe_Verbatim *subframe, unsigned samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  89643. #endif
  89644. /*** End of inlined file: stream_encoder_framing.h ***/
  89645. /*** Start of inlined file: window.h ***/
  89646. #ifndef FLAC__PRIVATE__WINDOW_H
  89647. #define FLAC__PRIVATE__WINDOW_H
  89648. #ifdef HAVE_CONFIG_H
  89649. #include <config.h>
  89650. #endif
  89651. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89652. void FLAC__window_bartlett(FLAC__real *window, const FLAC__int32 L);
  89653. void FLAC__window_bartlett_hann(FLAC__real *window, const FLAC__int32 L);
  89654. void FLAC__window_blackman(FLAC__real *window, const FLAC__int32 L);
  89655. void FLAC__window_blackman_harris_4term_92db_sidelobe(FLAC__real *window, const FLAC__int32 L);
  89656. void FLAC__window_connes(FLAC__real *window, const FLAC__int32 L);
  89657. void FLAC__window_flattop(FLAC__real *window, const FLAC__int32 L);
  89658. void FLAC__window_gauss(FLAC__real *window, const FLAC__int32 L, const FLAC__real stddev); /* 0.0 < stddev <= 0.5 */
  89659. void FLAC__window_hamming(FLAC__real *window, const FLAC__int32 L);
  89660. void FLAC__window_hann(FLAC__real *window, const FLAC__int32 L);
  89661. void FLAC__window_kaiser_bessel(FLAC__real *window, const FLAC__int32 L);
  89662. void FLAC__window_nuttall(FLAC__real *window, const FLAC__int32 L);
  89663. void FLAC__window_rectangle(FLAC__real *window, const FLAC__int32 L);
  89664. void FLAC__window_triangle(FLAC__real *window, const FLAC__int32 L);
  89665. void FLAC__window_tukey(FLAC__real *window, const FLAC__int32 L, const FLAC__real p);
  89666. void FLAC__window_welch(FLAC__real *window, const FLAC__int32 L);
  89667. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  89668. #endif
  89669. /*** End of inlined file: window.h ***/
  89670. #ifndef FLaC__INLINE
  89671. #define FLaC__INLINE
  89672. #endif
  89673. #ifdef min
  89674. #undef min
  89675. #endif
  89676. #define min(x,y) ((x)<(y)?(x):(y))
  89677. #ifdef max
  89678. #undef max
  89679. #endif
  89680. #define max(x,y) ((x)>(y)?(x):(y))
  89681. #undef EXACT_RICE_BITS_CALCULATION
  89682. #undef ENABLE_RICE_PARAMETER_SEARCH
  89683. typedef struct {
  89684. FLAC__int32 *data[FLAC__MAX_CHANNELS];
  89685. unsigned size; /* of each data[] in samples */
  89686. unsigned tail;
  89687. } verify_input_fifo;
  89688. typedef struct {
  89689. const FLAC__byte *data;
  89690. unsigned capacity;
  89691. unsigned bytes;
  89692. } verify_output;
  89693. typedef enum {
  89694. ENCODER_IN_MAGIC = 0,
  89695. ENCODER_IN_METADATA = 1,
  89696. ENCODER_IN_AUDIO = 2
  89697. } EncoderStateHint;
  89698. static struct CompressionLevels {
  89699. FLAC__bool do_mid_side_stereo;
  89700. FLAC__bool loose_mid_side_stereo;
  89701. unsigned max_lpc_order;
  89702. unsigned qlp_coeff_precision;
  89703. FLAC__bool do_qlp_coeff_prec_search;
  89704. FLAC__bool do_escape_coding;
  89705. FLAC__bool do_exhaustive_model_search;
  89706. unsigned min_residual_partition_order;
  89707. unsigned max_residual_partition_order;
  89708. unsigned rice_parameter_search_dist;
  89709. } compression_levels_[] = {
  89710. { false, false, 0, 0, false, false, false, 0, 3, 0 },
  89711. { true , true , 0, 0, false, false, false, 0, 3, 0 },
  89712. { true , false, 0, 0, false, false, false, 0, 3, 0 },
  89713. { false, false, 6, 0, false, false, false, 0, 4, 0 },
  89714. { true , true , 8, 0, false, false, false, 0, 4, 0 },
  89715. { true , false, 8, 0, false, false, false, 0, 5, 0 },
  89716. { true , false, 8, 0, false, false, false, 0, 6, 0 },
  89717. { true , false, 8, 0, false, false, true , 0, 6, 0 },
  89718. { true , false, 12, 0, false, false, true , 0, 6, 0 }
  89719. };
  89720. static void set_defaults_enc(FLAC__StreamEncoder *encoder);
  89721. static void free_(FLAC__StreamEncoder *encoder);
  89722. static FLAC__bool resize_buffers_(FLAC__StreamEncoder *encoder, unsigned new_blocksize);
  89723. static FLAC__bool write_bitbuffer_(FLAC__StreamEncoder *encoder, unsigned samples, FLAC__bool is_last_block);
  89724. static FLAC__StreamEncoderWriteStatus write_frame_(FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, FLAC__bool is_last_block);
  89725. static void update_metadata_(const FLAC__StreamEncoder *encoder);
  89726. #if FLAC__HAS_OGG
  89727. static void update_ogg_metadata_(FLAC__StreamEncoder *encoder);
  89728. #endif
  89729. static FLAC__bool process_frame_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block, FLAC__bool is_last_block);
  89730. static FLAC__bool process_subframes_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block);
  89731. static FLAC__bool process_subframe_(
  89732. FLAC__StreamEncoder *encoder,
  89733. unsigned min_partition_order,
  89734. unsigned max_partition_order,
  89735. const FLAC__FrameHeader *frame_header,
  89736. unsigned subframe_bps,
  89737. const FLAC__int32 integer_signal[],
  89738. FLAC__Subframe *subframe[2],
  89739. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents[2],
  89740. FLAC__int32 *residual[2],
  89741. unsigned *best_subframe,
  89742. unsigned *best_bits
  89743. );
  89744. static FLAC__bool add_subframe_(
  89745. FLAC__StreamEncoder *encoder,
  89746. unsigned blocksize,
  89747. unsigned subframe_bps,
  89748. const FLAC__Subframe *subframe,
  89749. FLAC__BitWriter *frame
  89750. );
  89751. static unsigned evaluate_constant_subframe_(
  89752. FLAC__StreamEncoder *encoder,
  89753. const FLAC__int32 signal,
  89754. unsigned blocksize,
  89755. unsigned subframe_bps,
  89756. FLAC__Subframe *subframe
  89757. );
  89758. static unsigned evaluate_fixed_subframe_(
  89759. FLAC__StreamEncoder *encoder,
  89760. const FLAC__int32 signal[],
  89761. FLAC__int32 residual[],
  89762. FLAC__uint64 abs_residual_partition_sums[],
  89763. unsigned raw_bits_per_partition[],
  89764. unsigned blocksize,
  89765. unsigned subframe_bps,
  89766. unsigned order,
  89767. unsigned rice_parameter,
  89768. unsigned rice_parameter_limit,
  89769. unsigned min_partition_order,
  89770. unsigned max_partition_order,
  89771. FLAC__bool do_escape_coding,
  89772. unsigned rice_parameter_search_dist,
  89773. FLAC__Subframe *subframe,
  89774. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  89775. );
  89776. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89777. static unsigned evaluate_lpc_subframe_(
  89778. FLAC__StreamEncoder *encoder,
  89779. const FLAC__int32 signal[],
  89780. FLAC__int32 residual[],
  89781. FLAC__uint64 abs_residual_partition_sums[],
  89782. unsigned raw_bits_per_partition[],
  89783. const FLAC__real lp_coeff[],
  89784. unsigned blocksize,
  89785. unsigned subframe_bps,
  89786. unsigned order,
  89787. unsigned qlp_coeff_precision,
  89788. unsigned rice_parameter,
  89789. unsigned rice_parameter_limit,
  89790. unsigned min_partition_order,
  89791. unsigned max_partition_order,
  89792. FLAC__bool do_escape_coding,
  89793. unsigned rice_parameter_search_dist,
  89794. FLAC__Subframe *subframe,
  89795. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  89796. );
  89797. #endif
  89798. static unsigned evaluate_verbatim_subframe_(
  89799. FLAC__StreamEncoder *encoder,
  89800. const FLAC__int32 signal[],
  89801. unsigned blocksize,
  89802. unsigned subframe_bps,
  89803. FLAC__Subframe *subframe
  89804. );
  89805. static unsigned find_best_partition_order_(
  89806. struct FLAC__StreamEncoderPrivate *private_,
  89807. const FLAC__int32 residual[],
  89808. FLAC__uint64 abs_residual_partition_sums[],
  89809. unsigned raw_bits_per_partition[],
  89810. unsigned residual_samples,
  89811. unsigned predictor_order,
  89812. unsigned rice_parameter,
  89813. unsigned rice_parameter_limit,
  89814. unsigned min_partition_order,
  89815. unsigned max_partition_order,
  89816. unsigned bps,
  89817. FLAC__bool do_escape_coding,
  89818. unsigned rice_parameter_search_dist,
  89819. FLAC__EntropyCodingMethod *best_ecm
  89820. );
  89821. static void precompute_partition_info_sums_(
  89822. const FLAC__int32 residual[],
  89823. FLAC__uint64 abs_residual_partition_sums[],
  89824. unsigned residual_samples,
  89825. unsigned predictor_order,
  89826. unsigned min_partition_order,
  89827. unsigned max_partition_order,
  89828. unsigned bps
  89829. );
  89830. static void precompute_partition_info_escapes_(
  89831. const FLAC__int32 residual[],
  89832. unsigned raw_bits_per_partition[],
  89833. unsigned residual_samples,
  89834. unsigned predictor_order,
  89835. unsigned min_partition_order,
  89836. unsigned max_partition_order
  89837. );
  89838. static FLAC__bool set_partitioned_rice_(
  89839. #ifdef EXACT_RICE_BITS_CALCULATION
  89840. const FLAC__int32 residual[],
  89841. #endif
  89842. const FLAC__uint64 abs_residual_partition_sums[],
  89843. const unsigned raw_bits_per_partition[],
  89844. const unsigned residual_samples,
  89845. const unsigned predictor_order,
  89846. const unsigned suggested_rice_parameter,
  89847. const unsigned rice_parameter_limit,
  89848. const unsigned rice_parameter_search_dist,
  89849. const unsigned partition_order,
  89850. const FLAC__bool search_for_escapes,
  89851. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents,
  89852. unsigned *bits
  89853. );
  89854. static unsigned get_wasted_bits_(FLAC__int32 signal[], unsigned samples);
  89855. static void append_to_verify_fifo_(
  89856. verify_input_fifo *fifo,
  89857. const FLAC__int32 * const input[],
  89858. unsigned input_offset,
  89859. unsigned channels,
  89860. unsigned wide_samples
  89861. );
  89862. static void append_to_verify_fifo_interleaved_(
  89863. verify_input_fifo *fifo,
  89864. const FLAC__int32 input[],
  89865. unsigned input_offset,
  89866. unsigned channels,
  89867. unsigned wide_samples
  89868. );
  89869. static FLAC__StreamDecoderReadStatus verify_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  89870. static FLAC__StreamDecoderWriteStatus verify_write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
  89871. static void verify_metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
  89872. static void verify_error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
  89873. static FLAC__StreamEncoderReadStatus file_read_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  89874. static FLAC__StreamEncoderSeekStatus file_seek_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  89875. static FLAC__StreamEncoderTellStatus file_tell_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  89876. 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);
  89877. static FILE *get_binary_stdout_(void);
  89878. typedef struct FLAC__StreamEncoderPrivate {
  89879. unsigned input_capacity; /* current size (in samples) of the signal and residual buffers */
  89880. FLAC__int32 *integer_signal[FLAC__MAX_CHANNELS]; /* the integer version of the input signal */
  89881. FLAC__int32 *integer_signal_mid_side[2]; /* the integer version of the mid-side input signal (stereo only) */
  89882. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89883. FLAC__real *real_signal[FLAC__MAX_CHANNELS]; /* (@@@ currently unused) the floating-point version of the input signal */
  89884. FLAC__real *real_signal_mid_side[2]; /* (@@@ currently unused) the floating-point version of the mid-side input signal (stereo only) */
  89885. FLAC__real *window[FLAC__MAX_APODIZATION_FUNCTIONS]; /* the pre-computed floating-point window for each apodization function */
  89886. FLAC__real *windowed_signal; /* the integer_signal[] * current window[] */
  89887. #endif
  89888. unsigned subframe_bps[FLAC__MAX_CHANNELS]; /* the effective bits per sample of the input signal (stream bps - wasted bits) */
  89889. unsigned subframe_bps_mid_side[2]; /* the effective bits per sample of the mid-side input signal (stream bps - wasted bits + 0/1) */
  89890. FLAC__int32 *residual_workspace[FLAC__MAX_CHANNELS][2]; /* each channel has a candidate and best workspace where the subframe residual signals will be stored */
  89891. FLAC__int32 *residual_workspace_mid_side[2][2];
  89892. FLAC__Subframe subframe_workspace[FLAC__MAX_CHANNELS][2];
  89893. FLAC__Subframe subframe_workspace_mid_side[2][2];
  89894. FLAC__Subframe *subframe_workspace_ptr[FLAC__MAX_CHANNELS][2];
  89895. FLAC__Subframe *subframe_workspace_ptr_mid_side[2][2];
  89896. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_workspace[FLAC__MAX_CHANNELS][2];
  89897. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_workspace_mid_side[FLAC__MAX_CHANNELS][2];
  89898. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents_workspace_ptr[FLAC__MAX_CHANNELS][2];
  89899. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents_workspace_ptr_mid_side[FLAC__MAX_CHANNELS][2];
  89900. unsigned best_subframe[FLAC__MAX_CHANNELS]; /* index (0 or 1) into 2nd dimension of the above workspaces */
  89901. unsigned best_subframe_mid_side[2];
  89902. unsigned best_subframe_bits[FLAC__MAX_CHANNELS]; /* size in bits of the best subframe for each channel */
  89903. unsigned best_subframe_bits_mid_side[2];
  89904. FLAC__uint64 *abs_residual_partition_sums; /* workspace where the sum of abs(candidate residual) for each partition is stored */
  89905. unsigned *raw_bits_per_partition; /* workspace where the sum of silog2(candidate residual) for each partition is stored */
  89906. FLAC__BitWriter *frame; /* the current frame being worked on */
  89907. unsigned loose_mid_side_stereo_frames; /* rounded number of frames the encoder will use before trying both independent and mid/side frames again */
  89908. unsigned loose_mid_side_stereo_frame_count; /* number of frames using the current channel assignment */
  89909. FLAC__ChannelAssignment last_channel_assignment;
  89910. FLAC__StreamMetadata streaminfo; /* scratchpad for STREAMINFO as it is built */
  89911. FLAC__StreamMetadata_SeekTable *seek_table; /* pointer into encoder->protected_->metadata_ where the seek table is */
  89912. unsigned current_sample_number;
  89913. unsigned current_frame_number;
  89914. FLAC__MD5Context md5context;
  89915. FLAC__CPUInfo cpuinfo;
  89916. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89917. unsigned (*local_fixed_compute_best_predictor)(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  89918. #else
  89919. unsigned (*local_fixed_compute_best_predictor)(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  89920. #endif
  89921. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89922. void (*local_lpc_compute_autocorrelation)(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  89923. 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[]);
  89924. 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[]);
  89925. 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[]);
  89926. #endif
  89927. FLAC__bool use_wide_by_block; /* use slow 64-bit versions of some functions because of the block size */
  89928. FLAC__bool use_wide_by_partition; /* use slow 64-bit versions of some functions because of the min partition order and blocksize */
  89929. FLAC__bool use_wide_by_order; /* use slow 64-bit versions of some functions because of the lpc order */
  89930. FLAC__bool disable_constant_subframes;
  89931. FLAC__bool disable_fixed_subframes;
  89932. FLAC__bool disable_verbatim_subframes;
  89933. #if FLAC__HAS_OGG
  89934. FLAC__bool is_ogg;
  89935. #endif
  89936. FLAC__StreamEncoderReadCallback read_callback; /* currently only needed for Ogg FLAC */
  89937. FLAC__StreamEncoderSeekCallback seek_callback;
  89938. FLAC__StreamEncoderTellCallback tell_callback;
  89939. FLAC__StreamEncoderWriteCallback write_callback;
  89940. FLAC__StreamEncoderMetadataCallback metadata_callback;
  89941. FLAC__StreamEncoderProgressCallback progress_callback;
  89942. void *client_data;
  89943. unsigned first_seekpoint_to_check;
  89944. FILE *file; /* only used when encoding to a file */
  89945. FLAC__uint64 bytes_written;
  89946. FLAC__uint64 samples_written;
  89947. unsigned frames_written;
  89948. unsigned total_frames_estimate;
  89949. FLAC__int32 *integer_signal_unaligned[FLAC__MAX_CHANNELS];
  89950. FLAC__int32 *integer_signal_mid_side_unaligned[2];
  89951. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89952. FLAC__real *real_signal_unaligned[FLAC__MAX_CHANNELS]; /* (@@@ currently unused) */
  89953. FLAC__real *real_signal_mid_side_unaligned[2]; /* (@@@ currently unused) */
  89954. FLAC__real *window_unaligned[FLAC__MAX_APODIZATION_FUNCTIONS];
  89955. FLAC__real *windowed_signal_unaligned;
  89956. #endif
  89957. FLAC__int32 *residual_workspace_unaligned[FLAC__MAX_CHANNELS][2];
  89958. FLAC__int32 *residual_workspace_mid_side_unaligned[2][2];
  89959. FLAC__uint64 *abs_residual_partition_sums_unaligned;
  89960. unsigned *raw_bits_per_partition_unaligned;
  89961. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89962. FLAC__real lp_coeff[FLAC__MAX_LPC_ORDER][FLAC__MAX_LPC_ORDER]; /* from process_subframe_() */
  89963. #endif
  89964. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_extra[2]; /* from find_best_partition_order_() */
  89965. struct {
  89966. FLAC__StreamDecoder *decoder;
  89967. EncoderStateHint state_hint;
  89968. FLAC__bool needs_magic_hack;
  89969. verify_input_fifo input_fifo;
  89970. verify_output output;
  89971. struct {
  89972. FLAC__uint64 absolute_sample;
  89973. unsigned frame_number;
  89974. unsigned channel;
  89975. unsigned sample;
  89976. FLAC__int32 expected;
  89977. FLAC__int32 got;
  89978. } error_stats;
  89979. } verify;
  89980. FLAC__bool is_being_deleted; /* if true, call to ..._finish() from ..._delete() will not call the callbacks */
  89981. } FLAC__StreamEncoderPrivate;
  89982. FLAC_API const char * const FLAC__StreamEncoderStateString[] = {
  89983. "FLAC__STREAM_ENCODER_OK",
  89984. "FLAC__STREAM_ENCODER_UNINITIALIZED",
  89985. "FLAC__STREAM_ENCODER_OGG_ERROR",
  89986. "FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR",
  89987. "FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA",
  89988. "FLAC__STREAM_ENCODER_CLIENT_ERROR",
  89989. "FLAC__STREAM_ENCODER_IO_ERROR",
  89990. "FLAC__STREAM_ENCODER_FRAMING_ERROR",
  89991. "FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR"
  89992. };
  89993. FLAC_API const char * const FLAC__StreamEncoderInitStatusString[] = {
  89994. "FLAC__STREAM_ENCODER_INIT_STATUS_OK",
  89995. "FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR",
  89996. "FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER",
  89997. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS",
  89998. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS",
  89999. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE",
  90000. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE",
  90001. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE",
  90002. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER",
  90003. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION",
  90004. "FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER",
  90005. "FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE",
  90006. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA",
  90007. "FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED"
  90008. };
  90009. FLAC_API const char * const FLAC__treamEncoderReadStatusString[] = {
  90010. "FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE",
  90011. "FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM",
  90012. "FLAC__STREAM_ENCODER_READ_STATUS_ABORT",
  90013. "FLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED"
  90014. };
  90015. FLAC_API const char * const FLAC__StreamEncoderWriteStatusString[] = {
  90016. "FLAC__STREAM_ENCODER_WRITE_STATUS_OK",
  90017. "FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR"
  90018. };
  90019. FLAC_API const char * const FLAC__StreamEncoderSeekStatusString[] = {
  90020. "FLAC__STREAM_ENCODER_SEEK_STATUS_OK",
  90021. "FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR",
  90022. "FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED"
  90023. };
  90024. FLAC_API const char * const FLAC__StreamEncoderTellStatusString[] = {
  90025. "FLAC__STREAM_ENCODER_TELL_STATUS_OK",
  90026. "FLAC__STREAM_ENCODER_TELL_STATUS_ERROR",
  90027. "FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED"
  90028. };
  90029. static const unsigned OVERREAD_ = 1;
  90030. FLAC_API FLAC__StreamEncoder *FLAC__stream_encoder_new(void)
  90031. {
  90032. FLAC__StreamEncoder *encoder;
  90033. unsigned i;
  90034. FLAC__ASSERT(sizeof(int) >= 4); /* we want to die right away if this is not true */
  90035. encoder = (FLAC__StreamEncoder*)calloc(1, sizeof(FLAC__StreamEncoder));
  90036. if(encoder == 0) {
  90037. return 0;
  90038. }
  90039. encoder->protected_ = (FLAC__StreamEncoderProtected*)calloc(1, sizeof(FLAC__StreamEncoderProtected));
  90040. if(encoder->protected_ == 0) {
  90041. free(encoder);
  90042. return 0;
  90043. }
  90044. encoder->private_ = (FLAC__StreamEncoderPrivate*)calloc(1, sizeof(FLAC__StreamEncoderPrivate));
  90045. if(encoder->private_ == 0) {
  90046. free(encoder->protected_);
  90047. free(encoder);
  90048. return 0;
  90049. }
  90050. encoder->private_->frame = FLAC__bitwriter_new();
  90051. if(encoder->private_->frame == 0) {
  90052. free(encoder->private_);
  90053. free(encoder->protected_);
  90054. free(encoder);
  90055. return 0;
  90056. }
  90057. encoder->private_->file = 0;
  90058. set_defaults_enc(encoder);
  90059. encoder->private_->is_being_deleted = false;
  90060. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  90061. encoder->private_->subframe_workspace_ptr[i][0] = &encoder->private_->subframe_workspace[i][0];
  90062. encoder->private_->subframe_workspace_ptr[i][1] = &encoder->private_->subframe_workspace[i][1];
  90063. }
  90064. for(i = 0; i < 2; i++) {
  90065. encoder->private_->subframe_workspace_ptr_mid_side[i][0] = &encoder->private_->subframe_workspace_mid_side[i][0];
  90066. encoder->private_->subframe_workspace_ptr_mid_side[i][1] = &encoder->private_->subframe_workspace_mid_side[i][1];
  90067. }
  90068. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  90069. encoder->private_->partitioned_rice_contents_workspace_ptr[i][0] = &encoder->private_->partitioned_rice_contents_workspace[i][0];
  90070. encoder->private_->partitioned_rice_contents_workspace_ptr[i][1] = &encoder->private_->partitioned_rice_contents_workspace[i][1];
  90071. }
  90072. for(i = 0; i < 2; i++) {
  90073. encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[i][0] = &encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0];
  90074. encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[i][1] = &encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1];
  90075. }
  90076. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  90077. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace[i][0]);
  90078. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace[i][1]);
  90079. }
  90080. for(i = 0; i < 2; i++) {
  90081. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0]);
  90082. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1]);
  90083. }
  90084. for(i = 0; i < 2; i++)
  90085. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_extra[i]);
  90086. encoder->protected_->state = FLAC__STREAM_ENCODER_UNINITIALIZED;
  90087. return encoder;
  90088. }
  90089. FLAC_API void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder)
  90090. {
  90091. unsigned i;
  90092. FLAC__ASSERT(0 != encoder);
  90093. FLAC__ASSERT(0 != encoder->protected_);
  90094. FLAC__ASSERT(0 != encoder->private_);
  90095. FLAC__ASSERT(0 != encoder->private_->frame);
  90096. encoder->private_->is_being_deleted = true;
  90097. (void)FLAC__stream_encoder_finish(encoder);
  90098. if(0 != encoder->private_->verify.decoder)
  90099. FLAC__stream_decoder_delete(encoder->private_->verify.decoder);
  90100. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  90101. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace[i][0]);
  90102. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace[i][1]);
  90103. }
  90104. for(i = 0; i < 2; i++) {
  90105. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0]);
  90106. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1]);
  90107. }
  90108. for(i = 0; i < 2; i++)
  90109. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_extra[i]);
  90110. FLAC__bitwriter_delete(encoder->private_->frame);
  90111. free(encoder->private_);
  90112. free(encoder->protected_);
  90113. free(encoder);
  90114. }
  90115. static FLAC__StreamEncoderInitStatus init_stream_internal_enc(
  90116. FLAC__StreamEncoder *encoder,
  90117. FLAC__StreamEncoderReadCallback read_callback,
  90118. FLAC__StreamEncoderWriteCallback write_callback,
  90119. FLAC__StreamEncoderSeekCallback seek_callback,
  90120. FLAC__StreamEncoderTellCallback tell_callback,
  90121. FLAC__StreamEncoderMetadataCallback metadata_callback,
  90122. void *client_data,
  90123. FLAC__bool is_ogg
  90124. )
  90125. {
  90126. unsigned i;
  90127. FLAC__bool metadata_has_seektable, metadata_has_vorbis_comment, metadata_picture_has_type1, metadata_picture_has_type2;
  90128. FLAC__ASSERT(0 != encoder);
  90129. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90130. return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
  90131. #if !FLAC__HAS_OGG
  90132. if(is_ogg)
  90133. return FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER;
  90134. #endif
  90135. if(0 == write_callback || (seek_callback && 0 == tell_callback))
  90136. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS;
  90137. if(encoder->protected_->channels == 0 || encoder->protected_->channels > FLAC__MAX_CHANNELS)
  90138. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS;
  90139. if(encoder->protected_->channels != 2) {
  90140. encoder->protected_->do_mid_side_stereo = false;
  90141. encoder->protected_->loose_mid_side_stereo = false;
  90142. }
  90143. else if(!encoder->protected_->do_mid_side_stereo)
  90144. encoder->protected_->loose_mid_side_stereo = false;
  90145. if(encoder->protected_->bits_per_sample >= 32)
  90146. encoder->protected_->do_mid_side_stereo = false; /* since we currenty do 32-bit math, the side channel would have 33 bps and overflow */
  90147. if(encoder->protected_->bits_per_sample < FLAC__MIN_BITS_PER_SAMPLE || encoder->protected_->bits_per_sample > FLAC__REFERENCE_CODEC_MAX_BITS_PER_SAMPLE)
  90148. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE;
  90149. if(!FLAC__format_sample_rate_is_valid(encoder->protected_->sample_rate))
  90150. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE;
  90151. if(encoder->protected_->blocksize == 0) {
  90152. if(encoder->protected_->max_lpc_order == 0)
  90153. encoder->protected_->blocksize = 1152;
  90154. else
  90155. encoder->protected_->blocksize = 4096;
  90156. }
  90157. if(encoder->protected_->blocksize < FLAC__MIN_BLOCK_SIZE || encoder->protected_->blocksize > FLAC__MAX_BLOCK_SIZE)
  90158. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE;
  90159. if(encoder->protected_->max_lpc_order > FLAC__MAX_LPC_ORDER)
  90160. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER;
  90161. if(encoder->protected_->blocksize < encoder->protected_->max_lpc_order)
  90162. return FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER;
  90163. if(encoder->protected_->qlp_coeff_precision == 0) {
  90164. if(encoder->protected_->bits_per_sample < 16) {
  90165. encoder->protected_->qlp_coeff_precision = max(FLAC__MIN_QLP_COEFF_PRECISION, 2 + encoder->protected_->bits_per_sample / 2);
  90166. }
  90167. else if(encoder->protected_->bits_per_sample == 16) {
  90168. if(encoder->protected_->blocksize <= 192)
  90169. encoder->protected_->qlp_coeff_precision = 7;
  90170. else if(encoder->protected_->blocksize <= 384)
  90171. encoder->protected_->qlp_coeff_precision = 8;
  90172. else if(encoder->protected_->blocksize <= 576)
  90173. encoder->protected_->qlp_coeff_precision = 9;
  90174. else if(encoder->protected_->blocksize <= 1152)
  90175. encoder->protected_->qlp_coeff_precision = 10;
  90176. else if(encoder->protected_->blocksize <= 2304)
  90177. encoder->protected_->qlp_coeff_precision = 11;
  90178. else if(encoder->protected_->blocksize <= 4608)
  90179. encoder->protected_->qlp_coeff_precision = 12;
  90180. else
  90181. encoder->protected_->qlp_coeff_precision = 13;
  90182. }
  90183. else {
  90184. if(encoder->protected_->blocksize <= 384)
  90185. encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION-2;
  90186. else if(encoder->protected_->blocksize <= 1152)
  90187. encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION-1;
  90188. else
  90189. encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION;
  90190. }
  90191. FLAC__ASSERT(encoder->protected_->qlp_coeff_precision <= FLAC__MAX_QLP_COEFF_PRECISION);
  90192. }
  90193. else if(encoder->protected_->qlp_coeff_precision < FLAC__MIN_QLP_COEFF_PRECISION || encoder->protected_->qlp_coeff_precision > FLAC__MAX_QLP_COEFF_PRECISION)
  90194. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION;
  90195. if(encoder->protected_->streamable_subset) {
  90196. if(
  90197. encoder->protected_->blocksize != 192 &&
  90198. encoder->protected_->blocksize != 576 &&
  90199. encoder->protected_->blocksize != 1152 &&
  90200. encoder->protected_->blocksize != 2304 &&
  90201. encoder->protected_->blocksize != 4608 &&
  90202. encoder->protected_->blocksize != 256 &&
  90203. encoder->protected_->blocksize != 512 &&
  90204. encoder->protected_->blocksize != 1024 &&
  90205. encoder->protected_->blocksize != 2048 &&
  90206. encoder->protected_->blocksize != 4096 &&
  90207. encoder->protected_->blocksize != 8192 &&
  90208. encoder->protected_->blocksize != 16384
  90209. )
  90210. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90211. if(!FLAC__format_sample_rate_is_subset(encoder->protected_->sample_rate))
  90212. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90213. if(
  90214. encoder->protected_->bits_per_sample != 8 &&
  90215. encoder->protected_->bits_per_sample != 12 &&
  90216. encoder->protected_->bits_per_sample != 16 &&
  90217. encoder->protected_->bits_per_sample != 20 &&
  90218. encoder->protected_->bits_per_sample != 24
  90219. )
  90220. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90221. if(encoder->protected_->max_residual_partition_order > FLAC__SUBSET_MAX_RICE_PARTITION_ORDER)
  90222. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90223. if(
  90224. encoder->protected_->sample_rate <= 48000 &&
  90225. (
  90226. encoder->protected_->blocksize > FLAC__SUBSET_MAX_BLOCK_SIZE_48000HZ ||
  90227. encoder->protected_->max_lpc_order > FLAC__SUBSET_MAX_LPC_ORDER_48000HZ
  90228. )
  90229. ) {
  90230. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90231. }
  90232. }
  90233. if(encoder->protected_->max_residual_partition_order >= (1u << FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  90234. encoder->protected_->max_residual_partition_order = (1u << FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN) - 1;
  90235. if(encoder->protected_->min_residual_partition_order >= encoder->protected_->max_residual_partition_order)
  90236. encoder->protected_->min_residual_partition_order = encoder->protected_->max_residual_partition_order;
  90237. #if FLAC__HAS_OGG
  90238. if(is_ogg && 0 != encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 1) {
  90239. unsigned i;
  90240. for(i = 1; i < encoder->protected_->num_metadata_blocks; i++) {
  90241. if(0 != encoder->protected_->metadata[i] && encoder->protected_->metadata[i]->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
  90242. FLAC__StreamMetadata *vc = encoder->protected_->metadata[i];
  90243. for( ; i > 0; i--)
  90244. encoder->protected_->metadata[i] = encoder->protected_->metadata[i-1];
  90245. encoder->protected_->metadata[0] = vc;
  90246. break;
  90247. }
  90248. }
  90249. }
  90250. #endif
  90251. if(0 != encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 0) {
  90252. unsigned i;
  90253. for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
  90254. if(0 != encoder->protected_->metadata[i] && encoder->protected_->metadata[i]->type == FLAC__METADATA_TYPE_SEEKTABLE) {
  90255. encoder->private_->seek_table = &encoder->protected_->metadata[i]->data.seek_table;
  90256. break; /* take only the first one */
  90257. }
  90258. }
  90259. }
  90260. if(0 == encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 0)
  90261. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90262. metadata_has_seektable = false;
  90263. metadata_has_vorbis_comment = false;
  90264. metadata_picture_has_type1 = false;
  90265. metadata_picture_has_type2 = false;
  90266. for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
  90267. const FLAC__StreamMetadata *m = encoder->protected_->metadata[i];
  90268. if(m->type == FLAC__METADATA_TYPE_STREAMINFO)
  90269. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90270. else if(m->type == FLAC__METADATA_TYPE_SEEKTABLE) {
  90271. if(metadata_has_seektable) /* only one is allowed */
  90272. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90273. metadata_has_seektable = true;
  90274. if(!FLAC__format_seektable_is_legal(&m->data.seek_table))
  90275. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90276. }
  90277. else if(m->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
  90278. if(metadata_has_vorbis_comment) /* only one is allowed */
  90279. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90280. metadata_has_vorbis_comment = true;
  90281. }
  90282. else if(m->type == FLAC__METADATA_TYPE_CUESHEET) {
  90283. if(!FLAC__format_cuesheet_is_legal(&m->data.cue_sheet, m->data.cue_sheet.is_cd, /*violation=*/0))
  90284. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90285. }
  90286. else if(m->type == FLAC__METADATA_TYPE_PICTURE) {
  90287. if(!FLAC__format_picture_is_legal(&m->data.picture, /*violation=*/0))
  90288. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90289. if(m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD) {
  90290. if(metadata_picture_has_type1) /* there should only be 1 per stream */
  90291. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90292. metadata_picture_has_type1 = true;
  90293. if(
  90294. m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD &&
  90295. (
  90296. (strcmp(m->data.picture.mime_type, "image/png") && strcmp(m->data.picture.mime_type, "-->")) ||
  90297. m->data.picture.width != 32 ||
  90298. m->data.picture.height != 32
  90299. )
  90300. )
  90301. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90302. }
  90303. else if(m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON) {
  90304. if(metadata_picture_has_type2) /* there should only be 1 per stream */
  90305. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90306. metadata_picture_has_type2 = true;
  90307. }
  90308. }
  90309. }
  90310. encoder->private_->input_capacity = 0;
  90311. for(i = 0; i < encoder->protected_->channels; i++) {
  90312. encoder->private_->integer_signal_unaligned[i] = encoder->private_->integer_signal[i] = 0;
  90313. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90314. encoder->private_->real_signal_unaligned[i] = encoder->private_->real_signal[i] = 0;
  90315. #endif
  90316. }
  90317. for(i = 0; i < 2; i++) {
  90318. encoder->private_->integer_signal_mid_side_unaligned[i] = encoder->private_->integer_signal_mid_side[i] = 0;
  90319. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90320. encoder->private_->real_signal_mid_side_unaligned[i] = encoder->private_->real_signal_mid_side[i] = 0;
  90321. #endif
  90322. }
  90323. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90324. for(i = 0; i < encoder->protected_->num_apodizations; i++)
  90325. encoder->private_->window_unaligned[i] = encoder->private_->window[i] = 0;
  90326. encoder->private_->windowed_signal_unaligned = encoder->private_->windowed_signal = 0;
  90327. #endif
  90328. for(i = 0; i < encoder->protected_->channels; i++) {
  90329. encoder->private_->residual_workspace_unaligned[i][0] = encoder->private_->residual_workspace[i][0] = 0;
  90330. encoder->private_->residual_workspace_unaligned[i][1] = encoder->private_->residual_workspace[i][1] = 0;
  90331. encoder->private_->best_subframe[i] = 0;
  90332. }
  90333. for(i = 0; i < 2; i++) {
  90334. encoder->private_->residual_workspace_mid_side_unaligned[i][0] = encoder->private_->residual_workspace_mid_side[i][0] = 0;
  90335. encoder->private_->residual_workspace_mid_side_unaligned[i][1] = encoder->private_->residual_workspace_mid_side[i][1] = 0;
  90336. encoder->private_->best_subframe_mid_side[i] = 0;
  90337. }
  90338. encoder->private_->abs_residual_partition_sums_unaligned = encoder->private_->abs_residual_partition_sums = 0;
  90339. encoder->private_->raw_bits_per_partition_unaligned = encoder->private_->raw_bits_per_partition = 0;
  90340. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90341. encoder->private_->loose_mid_side_stereo_frames = (unsigned)((FLAC__double)encoder->protected_->sample_rate * 0.4 / (FLAC__double)encoder->protected_->blocksize + 0.5);
  90342. #else
  90343. FLAC__ASSERT(FLAC__MAX_SAMPLE_RATE <= 655350);
  90344. FLAC__ASSERT(FLAC__MAX_BLOCK_SIZE <= 65535);
  90345. FLAC__ASSERT(encoder->protected_->sample_rate <= 655350);
  90346. FLAC__ASSERT(encoder->protected_->blocksize <= 65535);
  90347. 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);
  90348. #endif
  90349. if(encoder->private_->loose_mid_side_stereo_frames == 0)
  90350. encoder->private_->loose_mid_side_stereo_frames = 1;
  90351. encoder->private_->loose_mid_side_stereo_frame_count = 0;
  90352. encoder->private_->current_sample_number = 0;
  90353. encoder->private_->current_frame_number = 0;
  90354. encoder->private_->use_wide_by_block = (encoder->protected_->bits_per_sample + FLAC__bitmath_ilog2(encoder->protected_->blocksize)+1 > 30);
  90355. 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? */
  90356. encoder->private_->use_wide_by_partition = (false); /*@@@ need to set this */
  90357. FLAC__cpu_info(&encoder->private_->cpuinfo);
  90358. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90359. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation;
  90360. #endif
  90361. encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor;
  90362. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90363. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients;
  90364. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_64bit = FLAC__lpc_compute_residual_from_qlp_coefficients_wide;
  90365. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients;
  90366. #endif
  90367. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90368. # ifndef FLAC__NO_ASM
  90369. if(encoder->private_->cpuinfo.use_asm) {
  90370. # ifdef FLAC__CPU_IA32
  90371. FLAC__ASSERT(encoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_IA32);
  90372. # ifdef FLAC__HAS_NASM
  90373. if(encoder->private_->cpuinfo.data.ia32.sse) {
  90374. if(encoder->protected_->max_lpc_order < 4)
  90375. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_4;
  90376. else if(encoder->protected_->max_lpc_order < 8)
  90377. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_8;
  90378. else if(encoder->protected_->max_lpc_order < 12)
  90379. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_12;
  90380. else
  90381. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32;
  90382. }
  90383. else if(encoder->private_->cpuinfo.data.ia32._3dnow)
  90384. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_3dnow;
  90385. else
  90386. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32;
  90387. if(encoder->private_->cpuinfo.data.ia32.mmx) {
  90388. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
  90389. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32_mmx;
  90390. }
  90391. else {
  90392. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
  90393. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
  90394. }
  90395. if(encoder->private_->cpuinfo.data.ia32.mmx && encoder->private_->cpuinfo.data.ia32.cmov)
  90396. encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor_asm_ia32_mmx_cmov;
  90397. # endif /* FLAC__HAS_NASM */
  90398. # endif /* FLAC__CPU_IA32 */
  90399. }
  90400. # endif /* !FLAC__NO_ASM */
  90401. #endif /* !FLAC__INTEGER_ONLY_LIBRARY */
  90402. if(encoder->private_->use_wide_by_block) {
  90403. encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor_wide;
  90404. }
  90405. encoder->protected_->state = FLAC__STREAM_ENCODER_OK;
  90406. #if FLAC__HAS_OGG
  90407. encoder->private_->is_ogg = is_ogg;
  90408. if(is_ogg && !FLAC__ogg_encoder_aspect_init(&encoder->protected_->ogg_encoder_aspect)) {
  90409. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  90410. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90411. }
  90412. #endif
  90413. encoder->private_->read_callback = read_callback;
  90414. encoder->private_->write_callback = write_callback;
  90415. encoder->private_->seek_callback = seek_callback;
  90416. encoder->private_->tell_callback = tell_callback;
  90417. encoder->private_->metadata_callback = metadata_callback;
  90418. encoder->private_->client_data = client_data;
  90419. if(!resize_buffers_(encoder, encoder->protected_->blocksize)) {
  90420. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90421. }
  90422. if(!FLAC__bitwriter_init(encoder->private_->frame)) {
  90423. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  90424. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90425. }
  90426. if(encoder->protected_->verify) {
  90427. encoder->private_->verify.input_fifo.size = encoder->protected_->blocksize+OVERREAD_;
  90428. for(i = 0; i < encoder->protected_->channels; i++) {
  90429. 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))) {
  90430. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  90431. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90432. }
  90433. }
  90434. encoder->private_->verify.input_fifo.tail = 0;
  90435. encoder->private_->verify.decoder = FLAC__stream_decoder_new();
  90436. if(0 == encoder->private_->verify.decoder) {
  90437. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  90438. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90439. }
  90440. 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) {
  90441. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  90442. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90443. }
  90444. }
  90445. encoder->private_->verify.error_stats.absolute_sample = 0;
  90446. encoder->private_->verify.error_stats.frame_number = 0;
  90447. encoder->private_->verify.error_stats.channel = 0;
  90448. encoder->private_->verify.error_stats.sample = 0;
  90449. encoder->private_->verify.error_stats.expected = 0;
  90450. encoder->private_->verify.error_stats.got = 0;
  90451. encoder->private_->first_seekpoint_to_check = 0;
  90452. encoder->private_->samples_written = 0;
  90453. encoder->protected_->streaminfo_offset = 0;
  90454. encoder->protected_->seektable_offset = 0;
  90455. encoder->protected_->audio_offset = 0;
  90456. if(encoder->protected_->verify)
  90457. encoder->private_->verify.state_hint = ENCODER_IN_MAGIC;
  90458. if(!FLAC__bitwriter_write_raw_uint32(encoder->private_->frame, FLAC__STREAM_SYNC, FLAC__STREAM_SYNC_LEN)) {
  90459. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90460. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90461. }
  90462. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90463. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90464. }
  90465. if(encoder->protected_->verify)
  90466. encoder->private_->verify.state_hint = ENCODER_IN_METADATA;
  90467. encoder->private_->streaminfo.type = FLAC__METADATA_TYPE_STREAMINFO;
  90468. encoder->private_->streaminfo.is_last = false; /* we will have at a minimum a VORBIS_COMMENT afterwards */
  90469. encoder->private_->streaminfo.length = FLAC__STREAM_METADATA_STREAMINFO_LENGTH;
  90470. encoder->private_->streaminfo.data.stream_info.min_blocksize = encoder->protected_->blocksize; /* this encoder uses the same blocksize for the whole stream */
  90471. encoder->private_->streaminfo.data.stream_info.max_blocksize = encoder->protected_->blocksize;
  90472. encoder->private_->streaminfo.data.stream_info.min_framesize = 0; /* we don't know this yet; have to fill it in later */
  90473. encoder->private_->streaminfo.data.stream_info.max_framesize = 0; /* we don't know this yet; have to fill it in later */
  90474. encoder->private_->streaminfo.data.stream_info.sample_rate = encoder->protected_->sample_rate;
  90475. encoder->private_->streaminfo.data.stream_info.channels = encoder->protected_->channels;
  90476. encoder->private_->streaminfo.data.stream_info.bits_per_sample = encoder->protected_->bits_per_sample;
  90477. encoder->private_->streaminfo.data.stream_info.total_samples = encoder->protected_->total_samples_estimate; /* we will replace this later with the real total */
  90478. memset(encoder->private_->streaminfo.data.stream_info.md5sum, 0, 16); /* we don't know this yet; have to fill it in later */
  90479. if(encoder->protected_->do_md5)
  90480. FLAC__MD5Init(&encoder->private_->md5context);
  90481. if(!FLAC__add_metadata_block(&encoder->private_->streaminfo, encoder->private_->frame)) {
  90482. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90483. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90484. }
  90485. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90486. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90487. }
  90488. encoder->private_->streaminfo.data.stream_info.min_framesize = (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN) - 1;
  90489. encoder->private_->streaminfo.data.stream_info.total_samples = 0;
  90490. if(!metadata_has_vorbis_comment) {
  90491. FLAC__StreamMetadata vorbis_comment;
  90492. vorbis_comment.type = FLAC__METADATA_TYPE_VORBIS_COMMENT;
  90493. vorbis_comment.is_last = (encoder->protected_->num_metadata_blocks == 0);
  90494. vorbis_comment.length = 4 + 4; /* MAGIC NUMBER */
  90495. vorbis_comment.data.vorbis_comment.vendor_string.length = 0;
  90496. vorbis_comment.data.vorbis_comment.vendor_string.entry = 0;
  90497. vorbis_comment.data.vorbis_comment.num_comments = 0;
  90498. vorbis_comment.data.vorbis_comment.comments = 0;
  90499. if(!FLAC__add_metadata_block(&vorbis_comment, encoder->private_->frame)) {
  90500. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90501. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90502. }
  90503. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90504. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90505. }
  90506. }
  90507. for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
  90508. encoder->protected_->metadata[i]->is_last = (i == encoder->protected_->num_metadata_blocks - 1);
  90509. if(!FLAC__add_metadata_block(encoder->protected_->metadata[i], encoder->private_->frame)) {
  90510. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90511. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90512. }
  90513. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90514. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90515. }
  90516. }
  90517. 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 */
  90518. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  90519. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90520. }
  90521. if(encoder->protected_->verify)
  90522. encoder->private_->verify.state_hint = ENCODER_IN_AUDIO;
  90523. return FLAC__STREAM_ENCODER_INIT_STATUS_OK;
  90524. }
  90525. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_stream(
  90526. FLAC__StreamEncoder *encoder,
  90527. FLAC__StreamEncoderWriteCallback write_callback,
  90528. FLAC__StreamEncoderSeekCallback seek_callback,
  90529. FLAC__StreamEncoderTellCallback tell_callback,
  90530. FLAC__StreamEncoderMetadataCallback metadata_callback,
  90531. void *client_data
  90532. )
  90533. {
  90534. return init_stream_internal_enc(
  90535. encoder,
  90536. 0,
  90537. write_callback,
  90538. seek_callback,
  90539. tell_callback,
  90540. metadata_callback,
  90541. client_data,
  90542. false
  90543. );
  90544. }
  90545. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_stream(
  90546. FLAC__StreamEncoder *encoder,
  90547. FLAC__StreamEncoderReadCallback read_callback,
  90548. FLAC__StreamEncoderWriteCallback write_callback,
  90549. FLAC__StreamEncoderSeekCallback seek_callback,
  90550. FLAC__StreamEncoderTellCallback tell_callback,
  90551. FLAC__StreamEncoderMetadataCallback metadata_callback,
  90552. void *client_data
  90553. )
  90554. {
  90555. return init_stream_internal_enc(
  90556. encoder,
  90557. read_callback,
  90558. write_callback,
  90559. seek_callback,
  90560. tell_callback,
  90561. metadata_callback,
  90562. client_data,
  90563. true
  90564. );
  90565. }
  90566. static FLAC__StreamEncoderInitStatus init_FILE_internal_enc(
  90567. FLAC__StreamEncoder *encoder,
  90568. FILE *file,
  90569. FLAC__StreamEncoderProgressCallback progress_callback,
  90570. void *client_data,
  90571. FLAC__bool is_ogg
  90572. )
  90573. {
  90574. FLAC__StreamEncoderInitStatus init_status;
  90575. FLAC__ASSERT(0 != encoder);
  90576. FLAC__ASSERT(0 != file);
  90577. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90578. return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
  90579. if(file == 0) {
  90580. encoder->protected_->state = FLAC__STREAM_ENCODER_IO_ERROR;
  90581. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90582. }
  90583. if(file == stdout)
  90584. file = get_binary_stdout_(); /* just to be safe */
  90585. encoder->private_->file = file;
  90586. encoder->private_->progress_callback = progress_callback;
  90587. encoder->private_->bytes_written = 0;
  90588. encoder->private_->samples_written = 0;
  90589. encoder->private_->frames_written = 0;
  90590. init_status = init_stream_internal_enc(
  90591. encoder,
  90592. encoder->private_->file == stdout? 0 : is_ogg? file_read_callback_enc : 0,
  90593. file_write_callback_,
  90594. encoder->private_->file == stdout? 0 : file_seek_callback_enc,
  90595. encoder->private_->file == stdout? 0 : file_tell_callback_enc,
  90596. 0,
  90597. client_data,
  90598. is_ogg
  90599. );
  90600. if(init_status != FLAC__STREAM_ENCODER_INIT_STATUS_OK) {
  90601. return init_status;
  90602. }
  90603. {
  90604. unsigned blocksize = FLAC__stream_encoder_get_blocksize(encoder);
  90605. FLAC__ASSERT(blocksize != 0);
  90606. encoder->private_->total_frames_estimate = (unsigned)((FLAC__stream_encoder_get_total_samples_estimate(encoder) + blocksize - 1) / blocksize);
  90607. }
  90608. return init_status;
  90609. }
  90610. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_FILE(
  90611. FLAC__StreamEncoder *encoder,
  90612. FILE *file,
  90613. FLAC__StreamEncoderProgressCallback progress_callback,
  90614. void *client_data
  90615. )
  90616. {
  90617. return init_FILE_internal_enc(encoder, file, progress_callback, client_data, /*is_ogg=*/false);
  90618. }
  90619. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_FILE(
  90620. FLAC__StreamEncoder *encoder,
  90621. FILE *file,
  90622. FLAC__StreamEncoderProgressCallback progress_callback,
  90623. void *client_data
  90624. )
  90625. {
  90626. return init_FILE_internal_enc(encoder, file, progress_callback, client_data, /*is_ogg=*/true);
  90627. }
  90628. static FLAC__StreamEncoderInitStatus init_file_internal_enc(
  90629. FLAC__StreamEncoder *encoder,
  90630. const char *filename,
  90631. FLAC__StreamEncoderProgressCallback progress_callback,
  90632. void *client_data,
  90633. FLAC__bool is_ogg
  90634. )
  90635. {
  90636. FILE *file;
  90637. FLAC__ASSERT(0 != encoder);
  90638. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90639. return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
  90640. file = filename? fopen(filename, "w+b") : stdout;
  90641. if(file == 0) {
  90642. encoder->protected_->state = FLAC__STREAM_ENCODER_IO_ERROR;
  90643. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90644. }
  90645. return init_FILE_internal_enc(encoder, file, progress_callback, client_data, is_ogg);
  90646. }
  90647. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_file(
  90648. FLAC__StreamEncoder *encoder,
  90649. const char *filename,
  90650. FLAC__StreamEncoderProgressCallback progress_callback,
  90651. void *client_data
  90652. )
  90653. {
  90654. return init_file_internal_enc(encoder, filename, progress_callback, client_data, /*is_ogg=*/false);
  90655. }
  90656. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_file(
  90657. FLAC__StreamEncoder *encoder,
  90658. const char *filename,
  90659. FLAC__StreamEncoderProgressCallback progress_callback,
  90660. void *client_data
  90661. )
  90662. {
  90663. return init_file_internal_enc(encoder, filename, progress_callback, client_data, /*is_ogg=*/true);
  90664. }
  90665. FLAC_API FLAC__bool FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder)
  90666. {
  90667. FLAC__bool error = false;
  90668. FLAC__ASSERT(0 != encoder);
  90669. FLAC__ASSERT(0 != encoder->private_);
  90670. FLAC__ASSERT(0 != encoder->protected_);
  90671. if(encoder->protected_->state == FLAC__STREAM_ENCODER_UNINITIALIZED)
  90672. return true;
  90673. if(encoder->protected_->state == FLAC__STREAM_ENCODER_OK && !encoder->private_->is_being_deleted) {
  90674. if(encoder->private_->current_sample_number != 0) {
  90675. const FLAC__bool is_fractional_block = encoder->protected_->blocksize != encoder->private_->current_sample_number;
  90676. encoder->protected_->blocksize = encoder->private_->current_sample_number;
  90677. if(!process_frame_(encoder, is_fractional_block, /*is_last_block=*/true))
  90678. error = true;
  90679. }
  90680. }
  90681. if(encoder->protected_->do_md5)
  90682. FLAC__MD5Final(encoder->private_->streaminfo.data.stream_info.md5sum, &encoder->private_->md5context);
  90683. if(!encoder->private_->is_being_deleted) {
  90684. if(encoder->protected_->state == FLAC__STREAM_ENCODER_OK) {
  90685. if(encoder->private_->seek_callback) {
  90686. #if FLAC__HAS_OGG
  90687. if(encoder->private_->is_ogg)
  90688. update_ogg_metadata_(encoder);
  90689. else
  90690. #endif
  90691. update_metadata_(encoder);
  90692. if(encoder->protected_->state != FLAC__STREAM_ENCODER_OK)
  90693. error = true;
  90694. }
  90695. if(encoder->private_->metadata_callback)
  90696. encoder->private_->metadata_callback(encoder, &encoder->private_->streaminfo, encoder->private_->client_data);
  90697. }
  90698. if(encoder->protected_->verify && 0 != encoder->private_->verify.decoder && !FLAC__stream_decoder_finish(encoder->private_->verify.decoder)) {
  90699. if(!error)
  90700. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA;
  90701. error = true;
  90702. }
  90703. }
  90704. if(0 != encoder->private_->file) {
  90705. if(encoder->private_->file != stdout)
  90706. fclose(encoder->private_->file);
  90707. encoder->private_->file = 0;
  90708. }
  90709. #if FLAC__HAS_OGG
  90710. if(encoder->private_->is_ogg)
  90711. FLAC__ogg_encoder_aspect_finish(&encoder->protected_->ogg_encoder_aspect);
  90712. #endif
  90713. free_(encoder);
  90714. set_defaults_enc(encoder);
  90715. if(!error)
  90716. encoder->protected_->state = FLAC__STREAM_ENCODER_UNINITIALIZED;
  90717. return !error;
  90718. }
  90719. FLAC_API FLAC__bool FLAC__stream_encoder_set_ogg_serial_number(FLAC__StreamEncoder *encoder, long value)
  90720. {
  90721. FLAC__ASSERT(0 != encoder);
  90722. FLAC__ASSERT(0 != encoder->private_);
  90723. FLAC__ASSERT(0 != encoder->protected_);
  90724. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90725. return false;
  90726. #if FLAC__HAS_OGG
  90727. FLAC__ogg_encoder_aspect_set_serial_number(&encoder->protected_->ogg_encoder_aspect, value);
  90728. return true;
  90729. #else
  90730. (void)value;
  90731. return false;
  90732. #endif
  90733. }
  90734. FLAC_API FLAC__bool FLAC__stream_encoder_set_verify(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90735. {
  90736. FLAC__ASSERT(0 != encoder);
  90737. FLAC__ASSERT(0 != encoder->private_);
  90738. FLAC__ASSERT(0 != encoder->protected_);
  90739. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90740. return false;
  90741. #ifndef FLAC__MANDATORY_VERIFY_WHILE_ENCODING
  90742. encoder->protected_->verify = value;
  90743. #endif
  90744. return true;
  90745. }
  90746. FLAC_API FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90747. {
  90748. FLAC__ASSERT(0 != encoder);
  90749. FLAC__ASSERT(0 != encoder->private_);
  90750. FLAC__ASSERT(0 != encoder->protected_);
  90751. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90752. return false;
  90753. encoder->protected_->streamable_subset = value;
  90754. return true;
  90755. }
  90756. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_md5(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90757. {
  90758. FLAC__ASSERT(0 != encoder);
  90759. FLAC__ASSERT(0 != encoder->private_);
  90760. FLAC__ASSERT(0 != encoder->protected_);
  90761. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90762. return false;
  90763. encoder->protected_->do_md5 = value;
  90764. return true;
  90765. }
  90766. FLAC_API FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder *encoder, unsigned value)
  90767. {
  90768. FLAC__ASSERT(0 != encoder);
  90769. FLAC__ASSERT(0 != encoder->private_);
  90770. FLAC__ASSERT(0 != encoder->protected_);
  90771. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90772. return false;
  90773. encoder->protected_->channels = value;
  90774. return true;
  90775. }
  90776. FLAC_API FLAC__bool FLAC__stream_encoder_set_bits_per_sample(FLAC__StreamEncoder *encoder, unsigned value)
  90777. {
  90778. FLAC__ASSERT(0 != encoder);
  90779. FLAC__ASSERT(0 != encoder->private_);
  90780. FLAC__ASSERT(0 != encoder->protected_);
  90781. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90782. return false;
  90783. encoder->protected_->bits_per_sample = value;
  90784. return true;
  90785. }
  90786. FLAC_API FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *encoder, unsigned value)
  90787. {
  90788. FLAC__ASSERT(0 != encoder);
  90789. FLAC__ASSERT(0 != encoder->private_);
  90790. FLAC__ASSERT(0 != encoder->protected_);
  90791. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90792. return false;
  90793. encoder->protected_->sample_rate = value;
  90794. return true;
  90795. }
  90796. FLAC_API FLAC__bool FLAC__stream_encoder_set_compression_level(FLAC__StreamEncoder *encoder, unsigned value)
  90797. {
  90798. FLAC__bool ok = true;
  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. if(value >= sizeof(compression_levels_)/sizeof(compression_levels_[0]))
  90805. value = sizeof(compression_levels_)/sizeof(compression_levels_[0]) - 1;
  90806. ok &= FLAC__stream_encoder_set_do_mid_side_stereo (encoder, compression_levels_[value].do_mid_side_stereo);
  90807. ok &= FLAC__stream_encoder_set_loose_mid_side_stereo (encoder, compression_levels_[value].loose_mid_side_stereo);
  90808. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90809. #if 0
  90810. ok &= FLAC__stream_encoder_set_apodization (encoder, compression_levels_[value].apodization);
  90811. #else
  90812. encoder->protected_->num_apodizations = 1;
  90813. encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
  90814. encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
  90815. #endif
  90816. #endif
  90817. ok &= FLAC__stream_encoder_set_max_lpc_order (encoder, compression_levels_[value].max_lpc_order);
  90818. ok &= FLAC__stream_encoder_set_qlp_coeff_precision (encoder, compression_levels_[value].qlp_coeff_precision);
  90819. ok &= FLAC__stream_encoder_set_do_qlp_coeff_prec_search (encoder, compression_levels_[value].do_qlp_coeff_prec_search);
  90820. ok &= FLAC__stream_encoder_set_do_escape_coding (encoder, compression_levels_[value].do_escape_coding);
  90821. ok &= FLAC__stream_encoder_set_do_exhaustive_model_search (encoder, compression_levels_[value].do_exhaustive_model_search);
  90822. ok &= FLAC__stream_encoder_set_min_residual_partition_order(encoder, compression_levels_[value].min_residual_partition_order);
  90823. ok &= FLAC__stream_encoder_set_max_residual_partition_order(encoder, compression_levels_[value].max_residual_partition_order);
  90824. ok &= FLAC__stream_encoder_set_rice_parameter_search_dist (encoder, compression_levels_[value].rice_parameter_search_dist);
  90825. return ok;
  90826. }
  90827. FLAC_API FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *encoder, unsigned value)
  90828. {
  90829. FLAC__ASSERT(0 != encoder);
  90830. FLAC__ASSERT(0 != encoder->private_);
  90831. FLAC__ASSERT(0 != encoder->protected_);
  90832. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90833. return false;
  90834. encoder->protected_->blocksize = value;
  90835. return true;
  90836. }
  90837. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90838. {
  90839. FLAC__ASSERT(0 != encoder);
  90840. FLAC__ASSERT(0 != encoder->private_);
  90841. FLAC__ASSERT(0 != encoder->protected_);
  90842. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90843. return false;
  90844. encoder->protected_->do_mid_side_stereo = value;
  90845. return true;
  90846. }
  90847. FLAC_API FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90848. {
  90849. FLAC__ASSERT(0 != encoder);
  90850. FLAC__ASSERT(0 != encoder->private_);
  90851. FLAC__ASSERT(0 != encoder->protected_);
  90852. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90853. return false;
  90854. encoder->protected_->loose_mid_side_stereo = value;
  90855. return true;
  90856. }
  90857. FLAC_API FLAC__bool FLAC__stream_encoder_set_apodization(FLAC__StreamEncoder *encoder, const char *specification)
  90858. {
  90859. FLAC__ASSERT(0 != encoder);
  90860. FLAC__ASSERT(0 != encoder->private_);
  90861. FLAC__ASSERT(0 != encoder->protected_);
  90862. FLAC__ASSERT(0 != specification);
  90863. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90864. return false;
  90865. #ifdef FLAC__INTEGER_ONLY_LIBRARY
  90866. (void)specification; /* silently ignore since we haven't integerized; will always use a rectangular window */
  90867. #else
  90868. encoder->protected_->num_apodizations = 0;
  90869. while(1) {
  90870. const char *s = strchr(specification, ';');
  90871. const size_t n = s? (size_t)(s - specification) : strlen(specification);
  90872. if (n==8 && 0 == strncmp("bartlett" , specification, n))
  90873. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BARTLETT;
  90874. else if(n==13 && 0 == strncmp("bartlett_hann", specification, n))
  90875. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BARTLETT_HANN;
  90876. else if(n==8 && 0 == strncmp("blackman" , specification, n))
  90877. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BLACKMAN;
  90878. else if(n==26 && 0 == strncmp("blackman_harris_4term_92db", specification, n))
  90879. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE;
  90880. else if(n==6 && 0 == strncmp("connes" , specification, n))
  90881. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_CONNES;
  90882. else if(n==7 && 0 == strncmp("flattop" , specification, n))
  90883. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_FLATTOP;
  90884. else if(n>7 && 0 == strncmp("gauss(" , specification, 6)) {
  90885. FLAC__real stddev = (FLAC__real)strtod(specification+6, 0);
  90886. if (stddev > 0.0 && stddev <= 0.5) {
  90887. encoder->protected_->apodizations[encoder->protected_->num_apodizations].parameters.gauss.stddev = stddev;
  90888. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_GAUSS;
  90889. }
  90890. }
  90891. else if(n==7 && 0 == strncmp("hamming" , specification, n))
  90892. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_HAMMING;
  90893. else if(n==4 && 0 == strncmp("hann" , specification, n))
  90894. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_HANN;
  90895. else if(n==13 && 0 == strncmp("kaiser_bessel", specification, n))
  90896. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_KAISER_BESSEL;
  90897. else if(n==7 && 0 == strncmp("nuttall" , specification, n))
  90898. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_NUTTALL;
  90899. else if(n==9 && 0 == strncmp("rectangle" , specification, n))
  90900. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_RECTANGLE;
  90901. else if(n==8 && 0 == strncmp("triangle" , specification, n))
  90902. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_TRIANGLE;
  90903. else if(n>7 && 0 == strncmp("tukey(" , specification, 6)) {
  90904. FLAC__real p = (FLAC__real)strtod(specification+6, 0);
  90905. if (p >= 0.0 && p <= 1.0) {
  90906. encoder->protected_->apodizations[encoder->protected_->num_apodizations].parameters.tukey.p = p;
  90907. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_TUKEY;
  90908. }
  90909. }
  90910. else if(n==5 && 0 == strncmp("welch" , specification, n))
  90911. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_WELCH;
  90912. if (encoder->protected_->num_apodizations == 32)
  90913. break;
  90914. if (s)
  90915. specification = s+1;
  90916. else
  90917. break;
  90918. }
  90919. if(encoder->protected_->num_apodizations == 0) {
  90920. encoder->protected_->num_apodizations = 1;
  90921. encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
  90922. encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
  90923. }
  90924. #endif
  90925. return true;
  90926. }
  90927. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_lpc_order(FLAC__StreamEncoder *encoder, unsigned value)
  90928. {
  90929. FLAC__ASSERT(0 != encoder);
  90930. FLAC__ASSERT(0 != encoder->private_);
  90931. FLAC__ASSERT(0 != encoder->protected_);
  90932. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90933. return false;
  90934. encoder->protected_->max_lpc_order = value;
  90935. return true;
  90936. }
  90937. FLAC_API FLAC__bool FLAC__stream_encoder_set_qlp_coeff_precision(FLAC__StreamEncoder *encoder, unsigned value)
  90938. {
  90939. FLAC__ASSERT(0 != encoder);
  90940. FLAC__ASSERT(0 != encoder->private_);
  90941. FLAC__ASSERT(0 != encoder->protected_);
  90942. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90943. return false;
  90944. encoder->protected_->qlp_coeff_precision = value;
  90945. return true;
  90946. }
  90947. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_qlp_coeff_prec_search(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90948. {
  90949. FLAC__ASSERT(0 != encoder);
  90950. FLAC__ASSERT(0 != encoder->private_);
  90951. FLAC__ASSERT(0 != encoder->protected_);
  90952. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90953. return false;
  90954. encoder->protected_->do_qlp_coeff_prec_search = value;
  90955. return true;
  90956. }
  90957. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_escape_coding(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90958. {
  90959. FLAC__ASSERT(0 != encoder);
  90960. FLAC__ASSERT(0 != encoder->private_);
  90961. FLAC__ASSERT(0 != encoder->protected_);
  90962. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90963. return false;
  90964. #if 0
  90965. encoder->protected_->do_escape_coding = value;
  90966. #else
  90967. (void)value;
  90968. #endif
  90969. return true;
  90970. }
  90971. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_exhaustive_model_search(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90972. {
  90973. FLAC__ASSERT(0 != encoder);
  90974. FLAC__ASSERT(0 != encoder->private_);
  90975. FLAC__ASSERT(0 != encoder->protected_);
  90976. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90977. return false;
  90978. encoder->protected_->do_exhaustive_model_search = value;
  90979. return true;
  90980. }
  90981. FLAC_API FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value)
  90982. {
  90983. FLAC__ASSERT(0 != encoder);
  90984. FLAC__ASSERT(0 != encoder->private_);
  90985. FLAC__ASSERT(0 != encoder->protected_);
  90986. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90987. return false;
  90988. encoder->protected_->min_residual_partition_order = value;
  90989. return true;
  90990. }
  90991. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value)
  90992. {
  90993. FLAC__ASSERT(0 != encoder);
  90994. FLAC__ASSERT(0 != encoder->private_);
  90995. FLAC__ASSERT(0 != encoder->protected_);
  90996. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90997. return false;
  90998. encoder->protected_->max_residual_partition_order = value;
  90999. return true;
  91000. }
  91001. FLAC_API FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(FLAC__StreamEncoder *encoder, unsigned value)
  91002. {
  91003. FLAC__ASSERT(0 != encoder);
  91004. FLAC__ASSERT(0 != encoder->private_);
  91005. FLAC__ASSERT(0 != encoder->protected_);
  91006. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91007. return false;
  91008. #if 0
  91009. encoder->protected_->rice_parameter_search_dist = value;
  91010. #else
  91011. (void)value;
  91012. #endif
  91013. return true;
  91014. }
  91015. FLAC_API FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__StreamEncoder *encoder, FLAC__uint64 value)
  91016. {
  91017. FLAC__ASSERT(0 != encoder);
  91018. FLAC__ASSERT(0 != encoder->private_);
  91019. FLAC__ASSERT(0 != encoder->protected_);
  91020. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91021. return false;
  91022. encoder->protected_->total_samples_estimate = value;
  91023. return true;
  91024. }
  91025. FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, unsigned num_blocks)
  91026. {
  91027. FLAC__ASSERT(0 != encoder);
  91028. FLAC__ASSERT(0 != encoder->private_);
  91029. FLAC__ASSERT(0 != encoder->protected_);
  91030. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91031. return false;
  91032. if(0 == metadata)
  91033. num_blocks = 0;
  91034. if(0 == num_blocks)
  91035. metadata = 0;
  91036. if(encoder->protected_->metadata) {
  91037. free(encoder->protected_->metadata);
  91038. encoder->protected_->metadata = 0;
  91039. encoder->protected_->num_metadata_blocks = 0;
  91040. }
  91041. if(num_blocks) {
  91042. FLAC__StreamMetadata **m;
  91043. if(0 == (m = (FLAC__StreamMetadata**)safe_malloc_mul_2op_(sizeof(m[0]), /*times*/num_blocks)))
  91044. return false;
  91045. memcpy(m, metadata, sizeof(m[0]) * num_blocks);
  91046. encoder->protected_->metadata = m;
  91047. encoder->protected_->num_metadata_blocks = num_blocks;
  91048. }
  91049. #if FLAC__HAS_OGG
  91050. if(!FLAC__ogg_encoder_aspect_set_num_metadata(&encoder->protected_->ogg_encoder_aspect, num_blocks))
  91051. return false;
  91052. #endif
  91053. return true;
  91054. }
  91055. FLAC_API FLAC__bool FLAC__stream_encoder_disable_constant_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91056. {
  91057. FLAC__ASSERT(0 != encoder);
  91058. FLAC__ASSERT(0 != encoder->private_);
  91059. FLAC__ASSERT(0 != encoder->protected_);
  91060. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91061. return false;
  91062. encoder->private_->disable_constant_subframes = value;
  91063. return true;
  91064. }
  91065. FLAC_API FLAC__bool FLAC__stream_encoder_disable_fixed_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91066. {
  91067. FLAC__ASSERT(0 != encoder);
  91068. FLAC__ASSERT(0 != encoder->private_);
  91069. FLAC__ASSERT(0 != encoder->protected_);
  91070. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91071. return false;
  91072. encoder->private_->disable_fixed_subframes = value;
  91073. return true;
  91074. }
  91075. FLAC_API FLAC__bool FLAC__stream_encoder_disable_verbatim_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91076. {
  91077. FLAC__ASSERT(0 != encoder);
  91078. FLAC__ASSERT(0 != encoder->private_);
  91079. FLAC__ASSERT(0 != encoder->protected_);
  91080. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91081. return false;
  91082. encoder->private_->disable_verbatim_subframes = value;
  91083. return true;
  91084. }
  91085. FLAC_API FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder)
  91086. {
  91087. FLAC__ASSERT(0 != encoder);
  91088. FLAC__ASSERT(0 != encoder->private_);
  91089. FLAC__ASSERT(0 != encoder->protected_);
  91090. return encoder->protected_->state;
  91091. }
  91092. FLAC_API FLAC__StreamDecoderState FLAC__stream_encoder_get_verify_decoder_state(const FLAC__StreamEncoder *encoder)
  91093. {
  91094. FLAC__ASSERT(0 != encoder);
  91095. FLAC__ASSERT(0 != encoder->private_);
  91096. FLAC__ASSERT(0 != encoder->protected_);
  91097. if(encoder->protected_->verify)
  91098. return FLAC__stream_decoder_get_state(encoder->private_->verify.decoder);
  91099. else
  91100. return FLAC__STREAM_DECODER_UNINITIALIZED;
  91101. }
  91102. FLAC_API const char *FLAC__stream_encoder_get_resolved_state_string(const FLAC__StreamEncoder *encoder)
  91103. {
  91104. FLAC__ASSERT(0 != encoder);
  91105. FLAC__ASSERT(0 != encoder->private_);
  91106. FLAC__ASSERT(0 != encoder->protected_);
  91107. if(encoder->protected_->state != FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR)
  91108. return FLAC__StreamEncoderStateString[encoder->protected_->state];
  91109. else
  91110. return FLAC__stream_decoder_get_resolved_state_string(encoder->private_->verify.decoder);
  91111. }
  91112. 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)
  91113. {
  91114. FLAC__ASSERT(0 != encoder);
  91115. FLAC__ASSERT(0 != encoder->private_);
  91116. FLAC__ASSERT(0 != encoder->protected_);
  91117. if(0 != absolute_sample)
  91118. *absolute_sample = encoder->private_->verify.error_stats.absolute_sample;
  91119. if(0 != frame_number)
  91120. *frame_number = encoder->private_->verify.error_stats.frame_number;
  91121. if(0 != channel)
  91122. *channel = encoder->private_->verify.error_stats.channel;
  91123. if(0 != sample)
  91124. *sample = encoder->private_->verify.error_stats.sample;
  91125. if(0 != expected)
  91126. *expected = encoder->private_->verify.error_stats.expected;
  91127. if(0 != got)
  91128. *got = encoder->private_->verify.error_stats.got;
  91129. }
  91130. FLAC_API FLAC__bool FLAC__stream_encoder_get_verify(const FLAC__StreamEncoder *encoder)
  91131. {
  91132. FLAC__ASSERT(0 != encoder);
  91133. FLAC__ASSERT(0 != encoder->private_);
  91134. FLAC__ASSERT(0 != encoder->protected_);
  91135. return encoder->protected_->verify;
  91136. }
  91137. FLAC_API FLAC__bool FLAC__stream_encoder_get_streamable_subset(const FLAC__StreamEncoder *encoder)
  91138. {
  91139. FLAC__ASSERT(0 != encoder);
  91140. FLAC__ASSERT(0 != encoder->private_);
  91141. FLAC__ASSERT(0 != encoder->protected_);
  91142. return encoder->protected_->streamable_subset;
  91143. }
  91144. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_md5(const FLAC__StreamEncoder *encoder)
  91145. {
  91146. FLAC__ASSERT(0 != encoder);
  91147. FLAC__ASSERT(0 != encoder->private_);
  91148. FLAC__ASSERT(0 != encoder->protected_);
  91149. return encoder->protected_->do_md5;
  91150. }
  91151. FLAC_API unsigned FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder)
  91152. {
  91153. FLAC__ASSERT(0 != encoder);
  91154. FLAC__ASSERT(0 != encoder->private_);
  91155. FLAC__ASSERT(0 != encoder->protected_);
  91156. return encoder->protected_->channels;
  91157. }
  91158. FLAC_API unsigned FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder *encoder)
  91159. {
  91160. FLAC__ASSERT(0 != encoder);
  91161. FLAC__ASSERT(0 != encoder->private_);
  91162. FLAC__ASSERT(0 != encoder->protected_);
  91163. return encoder->protected_->bits_per_sample;
  91164. }
  91165. FLAC_API unsigned FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder *encoder)
  91166. {
  91167. FLAC__ASSERT(0 != encoder);
  91168. FLAC__ASSERT(0 != encoder->private_);
  91169. FLAC__ASSERT(0 != encoder->protected_);
  91170. return encoder->protected_->sample_rate;
  91171. }
  91172. FLAC_API unsigned FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder)
  91173. {
  91174. FLAC__ASSERT(0 != encoder);
  91175. FLAC__ASSERT(0 != encoder->private_);
  91176. FLAC__ASSERT(0 != encoder->protected_);
  91177. return encoder->protected_->blocksize;
  91178. }
  91179. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder)
  91180. {
  91181. FLAC__ASSERT(0 != encoder);
  91182. FLAC__ASSERT(0 != encoder->private_);
  91183. FLAC__ASSERT(0 != encoder->protected_);
  91184. return encoder->protected_->do_mid_side_stereo;
  91185. }
  91186. FLAC_API FLAC__bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder)
  91187. {
  91188. FLAC__ASSERT(0 != encoder);
  91189. FLAC__ASSERT(0 != encoder->private_);
  91190. FLAC__ASSERT(0 != encoder->protected_);
  91191. return encoder->protected_->loose_mid_side_stereo;
  91192. }
  91193. FLAC_API unsigned FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder)
  91194. {
  91195. FLAC__ASSERT(0 != encoder);
  91196. FLAC__ASSERT(0 != encoder->private_);
  91197. FLAC__ASSERT(0 != encoder->protected_);
  91198. return encoder->protected_->max_lpc_order;
  91199. }
  91200. FLAC_API unsigned FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder *encoder)
  91201. {
  91202. FLAC__ASSERT(0 != encoder);
  91203. FLAC__ASSERT(0 != encoder->private_);
  91204. FLAC__ASSERT(0 != encoder->protected_);
  91205. return encoder->protected_->qlp_coeff_precision;
  91206. }
  91207. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder)
  91208. {
  91209. FLAC__ASSERT(0 != encoder);
  91210. FLAC__ASSERT(0 != encoder->private_);
  91211. FLAC__ASSERT(0 != encoder->protected_);
  91212. return encoder->protected_->do_qlp_coeff_prec_search;
  91213. }
  91214. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_escape_coding(const FLAC__StreamEncoder *encoder)
  91215. {
  91216. FLAC__ASSERT(0 != encoder);
  91217. FLAC__ASSERT(0 != encoder->private_);
  91218. FLAC__ASSERT(0 != encoder->protected_);
  91219. return encoder->protected_->do_escape_coding;
  91220. }
  91221. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder)
  91222. {
  91223. FLAC__ASSERT(0 != encoder);
  91224. FLAC__ASSERT(0 != encoder->private_);
  91225. FLAC__ASSERT(0 != encoder->protected_);
  91226. return encoder->protected_->do_exhaustive_model_search;
  91227. }
  91228. FLAC_API unsigned FLAC__stream_encoder_get_min_residual_partition_order(const FLAC__StreamEncoder *encoder)
  91229. {
  91230. FLAC__ASSERT(0 != encoder);
  91231. FLAC__ASSERT(0 != encoder->private_);
  91232. FLAC__ASSERT(0 != encoder->protected_);
  91233. return encoder->protected_->min_residual_partition_order;
  91234. }
  91235. FLAC_API unsigned FLAC__stream_encoder_get_max_residual_partition_order(const FLAC__StreamEncoder *encoder)
  91236. {
  91237. FLAC__ASSERT(0 != encoder);
  91238. FLAC__ASSERT(0 != encoder->private_);
  91239. FLAC__ASSERT(0 != encoder->protected_);
  91240. return encoder->protected_->max_residual_partition_order;
  91241. }
  91242. FLAC_API unsigned FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder)
  91243. {
  91244. FLAC__ASSERT(0 != encoder);
  91245. FLAC__ASSERT(0 != encoder->private_);
  91246. FLAC__ASSERT(0 != encoder->protected_);
  91247. return encoder->protected_->rice_parameter_search_dist;
  91248. }
  91249. FLAC_API FLAC__uint64 FLAC__stream_encoder_get_total_samples_estimate(const FLAC__StreamEncoder *encoder)
  91250. {
  91251. FLAC__ASSERT(0 != encoder);
  91252. FLAC__ASSERT(0 != encoder->private_);
  91253. FLAC__ASSERT(0 != encoder->protected_);
  91254. return encoder->protected_->total_samples_estimate;
  91255. }
  91256. FLAC_API FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, const FLAC__int32 * const buffer[], unsigned samples)
  91257. {
  91258. unsigned i, j = 0, channel;
  91259. const unsigned channels = encoder->protected_->channels, blocksize = encoder->protected_->blocksize;
  91260. FLAC__ASSERT(0 != encoder);
  91261. FLAC__ASSERT(0 != encoder->private_);
  91262. FLAC__ASSERT(0 != encoder->protected_);
  91263. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91264. do {
  91265. const unsigned n = min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j);
  91266. if(encoder->protected_->verify)
  91267. append_to_verify_fifo_(&encoder->private_->verify.input_fifo, buffer, j, channels, n);
  91268. for(channel = 0; channel < channels; channel++)
  91269. memcpy(&encoder->private_->integer_signal[channel][encoder->private_->current_sample_number], &buffer[channel][j], sizeof(buffer[channel][0]) * n);
  91270. if(encoder->protected_->do_mid_side_stereo) {
  91271. FLAC__ASSERT(channels == 2);
  91272. for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
  91273. encoder->private_->integer_signal_mid_side[1][i] = buffer[0][j] - buffer[1][j];
  91274. 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' ! */
  91275. }
  91276. }
  91277. else
  91278. j += n;
  91279. encoder->private_->current_sample_number += n;
  91280. if(encoder->private_->current_sample_number > blocksize) {
  91281. FLAC__ASSERT(encoder->private_->current_sample_number == blocksize+OVERREAD_);
  91282. FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
  91283. if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
  91284. return false;
  91285. for(channel = 0; channel < channels; channel++)
  91286. encoder->private_->integer_signal[channel][0] = encoder->private_->integer_signal[channel][blocksize];
  91287. if(encoder->protected_->do_mid_side_stereo) {
  91288. encoder->private_->integer_signal_mid_side[0][0] = encoder->private_->integer_signal_mid_side[0][blocksize];
  91289. encoder->private_->integer_signal_mid_side[1][0] = encoder->private_->integer_signal_mid_side[1][blocksize];
  91290. }
  91291. encoder->private_->current_sample_number = 1;
  91292. }
  91293. } while(j < samples);
  91294. return true;
  91295. }
  91296. FLAC_API FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder *encoder, const FLAC__int32 buffer[], unsigned samples)
  91297. {
  91298. unsigned i, j, k, channel;
  91299. FLAC__int32 x, mid, side;
  91300. const unsigned channels = encoder->protected_->channels, blocksize = encoder->protected_->blocksize;
  91301. FLAC__ASSERT(0 != encoder);
  91302. FLAC__ASSERT(0 != encoder->private_);
  91303. FLAC__ASSERT(0 != encoder->protected_);
  91304. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91305. j = k = 0;
  91306. if(encoder->protected_->do_mid_side_stereo && channels == 2) {
  91307. do {
  91308. if(encoder->protected_->verify)
  91309. append_to_verify_fifo_interleaved_(&encoder->private_->verify.input_fifo, buffer, j, channels, min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j));
  91310. for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
  91311. encoder->private_->integer_signal[0][i] = mid = side = buffer[k++];
  91312. x = buffer[k++];
  91313. encoder->private_->integer_signal[1][i] = x;
  91314. mid += x;
  91315. side -= x;
  91316. mid >>= 1; /* NOTE: not the same as 'mid = (left + right) / 2' ! */
  91317. encoder->private_->integer_signal_mid_side[1][i] = side;
  91318. encoder->private_->integer_signal_mid_side[0][i] = mid;
  91319. }
  91320. encoder->private_->current_sample_number = i;
  91321. if(i > blocksize) {
  91322. if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
  91323. return false;
  91324. /* move unprocessed overread samples to beginnings of arrays */
  91325. FLAC__ASSERT(i == blocksize+OVERREAD_);
  91326. FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
  91327. encoder->private_->integer_signal[0][0] = encoder->private_->integer_signal[0][blocksize];
  91328. encoder->private_->integer_signal[1][0] = encoder->private_->integer_signal[1][blocksize];
  91329. encoder->private_->integer_signal_mid_side[0][0] = encoder->private_->integer_signal_mid_side[0][blocksize];
  91330. encoder->private_->integer_signal_mid_side[1][0] = encoder->private_->integer_signal_mid_side[1][blocksize];
  91331. encoder->private_->current_sample_number = 1;
  91332. }
  91333. } while(j < samples);
  91334. }
  91335. else {
  91336. do {
  91337. if(encoder->protected_->verify)
  91338. append_to_verify_fifo_interleaved_(&encoder->private_->verify.input_fifo, buffer, j, channels, min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j));
  91339. for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
  91340. for(channel = 0; channel < channels; channel++)
  91341. encoder->private_->integer_signal[channel][i] = buffer[k++];
  91342. }
  91343. encoder->private_->current_sample_number = i;
  91344. if(i > blocksize) {
  91345. if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
  91346. return false;
  91347. /* move unprocessed overread samples to beginnings of arrays */
  91348. FLAC__ASSERT(i == blocksize+OVERREAD_);
  91349. FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
  91350. for(channel = 0; channel < channels; channel++)
  91351. encoder->private_->integer_signal[channel][0] = encoder->private_->integer_signal[channel][blocksize];
  91352. encoder->private_->current_sample_number = 1;
  91353. }
  91354. } while(j < samples);
  91355. }
  91356. return true;
  91357. }
  91358. void set_defaults_enc(FLAC__StreamEncoder *encoder)
  91359. {
  91360. FLAC__ASSERT(0 != encoder);
  91361. #ifdef FLAC__MANDATORY_VERIFY_WHILE_ENCODING
  91362. encoder->protected_->verify = true;
  91363. #else
  91364. encoder->protected_->verify = false;
  91365. #endif
  91366. encoder->protected_->streamable_subset = true;
  91367. encoder->protected_->do_md5 = true;
  91368. encoder->protected_->do_mid_side_stereo = false;
  91369. encoder->protected_->loose_mid_side_stereo = false;
  91370. encoder->protected_->channels = 2;
  91371. encoder->protected_->bits_per_sample = 16;
  91372. encoder->protected_->sample_rate = 44100;
  91373. encoder->protected_->blocksize = 0;
  91374. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91375. encoder->protected_->num_apodizations = 1;
  91376. encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
  91377. encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
  91378. #endif
  91379. encoder->protected_->max_lpc_order = 0;
  91380. encoder->protected_->qlp_coeff_precision = 0;
  91381. encoder->protected_->do_qlp_coeff_prec_search = false;
  91382. encoder->protected_->do_exhaustive_model_search = false;
  91383. encoder->protected_->do_escape_coding = false;
  91384. encoder->protected_->min_residual_partition_order = 0;
  91385. encoder->protected_->max_residual_partition_order = 0;
  91386. encoder->protected_->rice_parameter_search_dist = 0;
  91387. encoder->protected_->total_samples_estimate = 0;
  91388. encoder->protected_->metadata = 0;
  91389. encoder->protected_->num_metadata_blocks = 0;
  91390. encoder->private_->seek_table = 0;
  91391. encoder->private_->disable_constant_subframes = false;
  91392. encoder->private_->disable_fixed_subframes = false;
  91393. encoder->private_->disable_verbatim_subframes = false;
  91394. #if FLAC__HAS_OGG
  91395. encoder->private_->is_ogg = false;
  91396. #endif
  91397. encoder->private_->read_callback = 0;
  91398. encoder->private_->write_callback = 0;
  91399. encoder->private_->seek_callback = 0;
  91400. encoder->private_->tell_callback = 0;
  91401. encoder->private_->metadata_callback = 0;
  91402. encoder->private_->progress_callback = 0;
  91403. encoder->private_->client_data = 0;
  91404. #if FLAC__HAS_OGG
  91405. FLAC__ogg_encoder_aspect_set_defaults(&encoder->protected_->ogg_encoder_aspect);
  91406. #endif
  91407. }
  91408. void free_(FLAC__StreamEncoder *encoder)
  91409. {
  91410. unsigned i, channel;
  91411. FLAC__ASSERT(0 != encoder);
  91412. if(encoder->protected_->metadata) {
  91413. free(encoder->protected_->metadata);
  91414. encoder->protected_->metadata = 0;
  91415. encoder->protected_->num_metadata_blocks = 0;
  91416. }
  91417. for(i = 0; i < encoder->protected_->channels; i++) {
  91418. if(0 != encoder->private_->integer_signal_unaligned[i]) {
  91419. free(encoder->private_->integer_signal_unaligned[i]);
  91420. encoder->private_->integer_signal_unaligned[i] = 0;
  91421. }
  91422. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91423. if(0 != encoder->private_->real_signal_unaligned[i]) {
  91424. free(encoder->private_->real_signal_unaligned[i]);
  91425. encoder->private_->real_signal_unaligned[i] = 0;
  91426. }
  91427. #endif
  91428. }
  91429. for(i = 0; i < 2; i++) {
  91430. if(0 != encoder->private_->integer_signal_mid_side_unaligned[i]) {
  91431. free(encoder->private_->integer_signal_mid_side_unaligned[i]);
  91432. encoder->private_->integer_signal_mid_side_unaligned[i] = 0;
  91433. }
  91434. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91435. if(0 != encoder->private_->real_signal_mid_side_unaligned[i]) {
  91436. free(encoder->private_->real_signal_mid_side_unaligned[i]);
  91437. encoder->private_->real_signal_mid_side_unaligned[i] = 0;
  91438. }
  91439. #endif
  91440. }
  91441. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91442. for(i = 0; i < encoder->protected_->num_apodizations; i++) {
  91443. if(0 != encoder->private_->window_unaligned[i]) {
  91444. free(encoder->private_->window_unaligned[i]);
  91445. encoder->private_->window_unaligned[i] = 0;
  91446. }
  91447. }
  91448. if(0 != encoder->private_->windowed_signal_unaligned) {
  91449. free(encoder->private_->windowed_signal_unaligned);
  91450. encoder->private_->windowed_signal_unaligned = 0;
  91451. }
  91452. #endif
  91453. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  91454. for(i = 0; i < 2; i++) {
  91455. if(0 != encoder->private_->residual_workspace_unaligned[channel][i]) {
  91456. free(encoder->private_->residual_workspace_unaligned[channel][i]);
  91457. encoder->private_->residual_workspace_unaligned[channel][i] = 0;
  91458. }
  91459. }
  91460. }
  91461. for(channel = 0; channel < 2; channel++) {
  91462. for(i = 0; i < 2; i++) {
  91463. if(0 != encoder->private_->residual_workspace_mid_side_unaligned[channel][i]) {
  91464. free(encoder->private_->residual_workspace_mid_side_unaligned[channel][i]);
  91465. encoder->private_->residual_workspace_mid_side_unaligned[channel][i] = 0;
  91466. }
  91467. }
  91468. }
  91469. if(0 != encoder->private_->abs_residual_partition_sums_unaligned) {
  91470. free(encoder->private_->abs_residual_partition_sums_unaligned);
  91471. encoder->private_->abs_residual_partition_sums_unaligned = 0;
  91472. }
  91473. if(0 != encoder->private_->raw_bits_per_partition_unaligned) {
  91474. free(encoder->private_->raw_bits_per_partition_unaligned);
  91475. encoder->private_->raw_bits_per_partition_unaligned = 0;
  91476. }
  91477. if(encoder->protected_->verify) {
  91478. for(i = 0; i < encoder->protected_->channels; i++) {
  91479. if(0 != encoder->private_->verify.input_fifo.data[i]) {
  91480. free(encoder->private_->verify.input_fifo.data[i]);
  91481. encoder->private_->verify.input_fifo.data[i] = 0;
  91482. }
  91483. }
  91484. }
  91485. FLAC__bitwriter_free(encoder->private_->frame);
  91486. }
  91487. FLAC__bool resize_buffers_(FLAC__StreamEncoder *encoder, unsigned new_blocksize)
  91488. {
  91489. FLAC__bool ok;
  91490. unsigned i, channel;
  91491. FLAC__ASSERT(new_blocksize > 0);
  91492. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91493. FLAC__ASSERT(encoder->private_->current_sample_number == 0);
  91494. if(new_blocksize <= encoder->private_->input_capacity)
  91495. return true;
  91496. ok = true;
  91497. for(i = 0; ok && i < encoder->protected_->channels; i++) {
  91498. ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize+4+OVERREAD_, &encoder->private_->integer_signal_unaligned[i], &encoder->private_->integer_signal[i]);
  91499. memset(encoder->private_->integer_signal[i], 0, sizeof(FLAC__int32)*4);
  91500. encoder->private_->integer_signal[i] += 4;
  91501. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91502. #if 0 /* @@@ currently unused */
  91503. if(encoder->protected_->max_lpc_order > 0)
  91504. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize+OVERREAD_, &encoder->private_->real_signal_unaligned[i], &encoder->private_->real_signal[i]);
  91505. #endif
  91506. #endif
  91507. }
  91508. for(i = 0; ok && i < 2; i++) {
  91509. 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]);
  91510. memset(encoder->private_->integer_signal_mid_side[i], 0, sizeof(FLAC__int32)*4);
  91511. encoder->private_->integer_signal_mid_side[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_mid_side_unaligned[i], &encoder->private_->real_signal_mid_side[i]);
  91516. #endif
  91517. #endif
  91518. }
  91519. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91520. if(ok && encoder->protected_->max_lpc_order > 0) {
  91521. for(i = 0; ok && i < encoder->protected_->num_apodizations; i++)
  91522. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize, &encoder->private_->window_unaligned[i], &encoder->private_->window[i]);
  91523. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize, &encoder->private_->windowed_signal_unaligned, &encoder->private_->windowed_signal);
  91524. }
  91525. #endif
  91526. for(channel = 0; ok && channel < encoder->protected_->channels; channel++) {
  91527. for(i = 0; ok && i < 2; i++) {
  91528. ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize, &encoder->private_->residual_workspace_unaligned[channel][i], &encoder->private_->residual_workspace[channel][i]);
  91529. }
  91530. }
  91531. for(channel = 0; ok && channel < 2; channel++) {
  91532. for(i = 0; ok && i < 2; i++) {
  91533. 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]);
  91534. }
  91535. }
  91536. ok = ok && FLAC__memory_alloc_aligned_uint64_array(new_blocksize * 2, &encoder->private_->abs_residual_partition_sums_unaligned, &encoder->private_->abs_residual_partition_sums);
  91537. if(encoder->protected_->do_escape_coding)
  91538. ok = ok && FLAC__memory_alloc_aligned_unsigned_array(new_blocksize * 2, &encoder->private_->raw_bits_per_partition_unaligned, &encoder->private_->raw_bits_per_partition);
  91539. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91540. if(ok && new_blocksize != encoder->private_->input_capacity && encoder->protected_->max_lpc_order > 0) {
  91541. for(i = 0; ok && i < encoder->protected_->num_apodizations; i++) {
  91542. switch(encoder->protected_->apodizations[i].type) {
  91543. case FLAC__APODIZATION_BARTLETT:
  91544. FLAC__window_bartlett(encoder->private_->window[i], new_blocksize);
  91545. break;
  91546. case FLAC__APODIZATION_BARTLETT_HANN:
  91547. FLAC__window_bartlett_hann(encoder->private_->window[i], new_blocksize);
  91548. break;
  91549. case FLAC__APODIZATION_BLACKMAN:
  91550. FLAC__window_blackman(encoder->private_->window[i], new_blocksize);
  91551. break;
  91552. case FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE:
  91553. FLAC__window_blackman_harris_4term_92db_sidelobe(encoder->private_->window[i], new_blocksize);
  91554. break;
  91555. case FLAC__APODIZATION_CONNES:
  91556. FLAC__window_connes(encoder->private_->window[i], new_blocksize);
  91557. break;
  91558. case FLAC__APODIZATION_FLATTOP:
  91559. FLAC__window_flattop(encoder->private_->window[i], new_blocksize);
  91560. break;
  91561. case FLAC__APODIZATION_GAUSS:
  91562. FLAC__window_gauss(encoder->private_->window[i], new_blocksize, encoder->protected_->apodizations[i].parameters.gauss.stddev);
  91563. break;
  91564. case FLAC__APODIZATION_HAMMING:
  91565. FLAC__window_hamming(encoder->private_->window[i], new_blocksize);
  91566. break;
  91567. case FLAC__APODIZATION_HANN:
  91568. FLAC__window_hann(encoder->private_->window[i], new_blocksize);
  91569. break;
  91570. case FLAC__APODIZATION_KAISER_BESSEL:
  91571. FLAC__window_kaiser_bessel(encoder->private_->window[i], new_blocksize);
  91572. break;
  91573. case FLAC__APODIZATION_NUTTALL:
  91574. FLAC__window_nuttall(encoder->private_->window[i], new_blocksize);
  91575. break;
  91576. case FLAC__APODIZATION_RECTANGLE:
  91577. FLAC__window_rectangle(encoder->private_->window[i], new_blocksize);
  91578. break;
  91579. case FLAC__APODIZATION_TRIANGLE:
  91580. FLAC__window_triangle(encoder->private_->window[i], new_blocksize);
  91581. break;
  91582. case FLAC__APODIZATION_TUKEY:
  91583. FLAC__window_tukey(encoder->private_->window[i], new_blocksize, encoder->protected_->apodizations[i].parameters.tukey.p);
  91584. break;
  91585. case FLAC__APODIZATION_WELCH:
  91586. FLAC__window_welch(encoder->private_->window[i], new_blocksize);
  91587. break;
  91588. default:
  91589. FLAC__ASSERT(0);
  91590. FLAC__window_hann(encoder->private_->window[i], new_blocksize);
  91591. break;
  91592. }
  91593. }
  91594. }
  91595. #endif
  91596. if(ok)
  91597. encoder->private_->input_capacity = new_blocksize;
  91598. else
  91599. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91600. return ok;
  91601. }
  91602. FLAC__bool write_bitbuffer_(FLAC__StreamEncoder *encoder, unsigned samples, FLAC__bool is_last_block)
  91603. {
  91604. const FLAC__byte *buffer;
  91605. size_t bytes;
  91606. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(encoder->private_->frame));
  91607. if(!FLAC__bitwriter_get_buffer(encoder->private_->frame, &buffer, &bytes)) {
  91608. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91609. return false;
  91610. }
  91611. if(encoder->protected_->verify) {
  91612. encoder->private_->verify.output.data = buffer;
  91613. encoder->private_->verify.output.bytes = bytes;
  91614. if(encoder->private_->verify.state_hint == ENCODER_IN_MAGIC) {
  91615. encoder->private_->verify.needs_magic_hack = true;
  91616. }
  91617. else {
  91618. if(!FLAC__stream_decoder_process_single(encoder->private_->verify.decoder)) {
  91619. FLAC__bitwriter_release_buffer(encoder->private_->frame);
  91620. FLAC__bitwriter_clear(encoder->private_->frame);
  91621. if(encoder->protected_->state != FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA)
  91622. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  91623. return false;
  91624. }
  91625. }
  91626. }
  91627. if(write_frame_(encoder, buffer, bytes, samples, is_last_block) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91628. FLAC__bitwriter_release_buffer(encoder->private_->frame);
  91629. FLAC__bitwriter_clear(encoder->private_->frame);
  91630. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91631. return false;
  91632. }
  91633. FLAC__bitwriter_release_buffer(encoder->private_->frame);
  91634. FLAC__bitwriter_clear(encoder->private_->frame);
  91635. if(samples > 0) {
  91636. encoder->private_->streaminfo.data.stream_info.min_framesize = min(bytes, encoder->private_->streaminfo.data.stream_info.min_framesize);
  91637. encoder->private_->streaminfo.data.stream_info.max_framesize = max(bytes, encoder->private_->streaminfo.data.stream_info.max_framesize);
  91638. }
  91639. return true;
  91640. }
  91641. FLAC__StreamEncoderWriteStatus write_frame_(FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, FLAC__bool is_last_block)
  91642. {
  91643. FLAC__StreamEncoderWriteStatus status;
  91644. FLAC__uint64 output_position = 0;
  91645. if(encoder->private_->tell_callback && encoder->private_->tell_callback(encoder, &output_position, encoder->private_->client_data) == FLAC__STREAM_ENCODER_TELL_STATUS_ERROR) {
  91646. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91647. return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
  91648. }
  91649. if(samples == 0) {
  91650. FLAC__MetadataType type = (FLAC__MetadataType) (buffer[0] & 0x7f);
  91651. if(type == FLAC__METADATA_TYPE_STREAMINFO)
  91652. encoder->protected_->streaminfo_offset = output_position;
  91653. else if(type == FLAC__METADATA_TYPE_SEEKTABLE && encoder->protected_->seektable_offset == 0)
  91654. encoder->protected_->seektable_offset = output_position;
  91655. }
  91656. if(0 != encoder->private_->seek_table && encoder->protected_->audio_offset > 0 && encoder->private_->seek_table->num_points > 0) {
  91657. const unsigned blocksize = FLAC__stream_encoder_get_blocksize(encoder);
  91658. const FLAC__uint64 frame_first_sample = encoder->private_->samples_written;
  91659. const FLAC__uint64 frame_last_sample = frame_first_sample + (FLAC__uint64)blocksize - 1;
  91660. FLAC__uint64 test_sample;
  91661. unsigned i;
  91662. for(i = encoder->private_->first_seekpoint_to_check; i < encoder->private_->seek_table->num_points; i++) {
  91663. test_sample = encoder->private_->seek_table->points[i].sample_number;
  91664. if(test_sample > frame_last_sample) {
  91665. break;
  91666. }
  91667. else if(test_sample >= frame_first_sample) {
  91668. encoder->private_->seek_table->points[i].sample_number = frame_first_sample;
  91669. encoder->private_->seek_table->points[i].stream_offset = output_position - encoder->protected_->audio_offset;
  91670. encoder->private_->seek_table->points[i].frame_samples = blocksize;
  91671. encoder->private_->first_seekpoint_to_check++;
  91672. }
  91673. else {
  91674. encoder->private_->first_seekpoint_to_check++;
  91675. }
  91676. }
  91677. }
  91678. #if FLAC__HAS_OGG
  91679. if(encoder->private_->is_ogg) {
  91680. status = FLAC__ogg_encoder_aspect_write_callback_wrapper(
  91681. &encoder->protected_->ogg_encoder_aspect,
  91682. buffer,
  91683. bytes,
  91684. samples,
  91685. encoder->private_->current_frame_number,
  91686. is_last_block,
  91687. (FLAC__OggEncoderAspectWriteCallbackProxy)encoder->private_->write_callback,
  91688. encoder,
  91689. encoder->private_->client_data
  91690. );
  91691. }
  91692. else
  91693. #endif
  91694. status = encoder->private_->write_callback(encoder, buffer, bytes, samples, encoder->private_->current_frame_number, encoder->private_->client_data);
  91695. if(status == FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91696. encoder->private_->bytes_written += bytes;
  91697. encoder->private_->samples_written += samples;
  91698. encoder->private_->frames_written = max(encoder->private_->frames_written, encoder->private_->current_frame_number+1);
  91699. }
  91700. else
  91701. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91702. return status;
  91703. }
  91704. void update_metadata_(const FLAC__StreamEncoder *encoder)
  91705. {
  91706. FLAC__byte b[max(6, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)];
  91707. const FLAC__StreamMetadata *metadata = &encoder->private_->streaminfo;
  91708. const FLAC__uint64 samples = metadata->data.stream_info.total_samples;
  91709. const unsigned min_framesize = metadata->data.stream_info.min_framesize;
  91710. const unsigned max_framesize = metadata->data.stream_info.max_framesize;
  91711. const unsigned bps = metadata->data.stream_info.bits_per_sample;
  91712. FLAC__StreamEncoderSeekStatus seek_status;
  91713. FLAC__ASSERT(metadata->type == FLAC__METADATA_TYPE_STREAMINFO);
  91714. {
  91715. const unsigned md5_offset =
  91716. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91717. (
  91718. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91719. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  91720. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  91721. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  91722. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  91723. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  91724. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN +
  91725. FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN
  91726. ) / 8;
  91727. if((seek_status = encoder->private_->seek_callback(encoder, encoder->protected_->streaminfo_offset + md5_offset, encoder->private_->client_data)) != FLAC__STREAM_ENCODER_SEEK_STATUS_OK) {
  91728. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  91729. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91730. return;
  91731. }
  91732. if(encoder->private_->write_callback(encoder, metadata->data.stream_info.md5sum, 16, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91733. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91734. return;
  91735. }
  91736. }
  91737. {
  91738. const unsigned total_samples_byte_offset =
  91739. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91740. (
  91741. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91742. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  91743. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  91744. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  91745. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  91746. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  91747. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN
  91748. - 4
  91749. ) / 8;
  91750. b[0] = ((FLAC__byte)(bps-1) << 4) | (FLAC__byte)((samples >> 32) & 0x0F);
  91751. b[1] = (FLAC__byte)((samples >> 24) & 0xFF);
  91752. b[2] = (FLAC__byte)((samples >> 16) & 0xFF);
  91753. b[3] = (FLAC__byte)((samples >> 8) & 0xFF);
  91754. b[4] = (FLAC__byte)(samples & 0xFF);
  91755. 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) {
  91756. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  91757. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91758. return;
  91759. }
  91760. if(encoder->private_->write_callback(encoder, b, 5, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91761. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91762. return;
  91763. }
  91764. }
  91765. {
  91766. const unsigned min_framesize_offset =
  91767. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91768. (
  91769. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91770. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN
  91771. ) / 8;
  91772. b[0] = (FLAC__byte)((min_framesize >> 16) & 0xFF);
  91773. b[1] = (FLAC__byte)((min_framesize >> 8) & 0xFF);
  91774. b[2] = (FLAC__byte)(min_framesize & 0xFF);
  91775. b[3] = (FLAC__byte)((max_framesize >> 16) & 0xFF);
  91776. b[4] = (FLAC__byte)((max_framesize >> 8) & 0xFF);
  91777. b[5] = (FLAC__byte)(max_framesize & 0xFF);
  91778. 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) {
  91779. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  91780. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91781. return;
  91782. }
  91783. if(encoder->private_->write_callback(encoder, b, 6, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91784. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91785. return;
  91786. }
  91787. }
  91788. if(0 != encoder->private_->seek_table && encoder->private_->seek_table->num_points > 0 && encoder->protected_->seektable_offset > 0) {
  91789. unsigned i;
  91790. FLAC__format_seektable_sort(encoder->private_->seek_table);
  91791. FLAC__ASSERT(FLAC__format_seektable_is_legal(encoder->private_->seek_table));
  91792. 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) {
  91793. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  91794. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91795. return;
  91796. }
  91797. for(i = 0; i < encoder->private_->seek_table->num_points; i++) {
  91798. FLAC__uint64 xx;
  91799. unsigned x;
  91800. xx = encoder->private_->seek_table->points[i].sample_number;
  91801. b[7] = (FLAC__byte)xx; xx >>= 8;
  91802. b[6] = (FLAC__byte)xx; xx >>= 8;
  91803. b[5] = (FLAC__byte)xx; xx >>= 8;
  91804. b[4] = (FLAC__byte)xx; xx >>= 8;
  91805. b[3] = (FLAC__byte)xx; xx >>= 8;
  91806. b[2] = (FLAC__byte)xx; xx >>= 8;
  91807. b[1] = (FLAC__byte)xx; xx >>= 8;
  91808. b[0] = (FLAC__byte)xx; xx >>= 8;
  91809. xx = encoder->private_->seek_table->points[i].stream_offset;
  91810. b[15] = (FLAC__byte)xx; xx >>= 8;
  91811. b[14] = (FLAC__byte)xx; xx >>= 8;
  91812. b[13] = (FLAC__byte)xx; xx >>= 8;
  91813. b[12] = (FLAC__byte)xx; xx >>= 8;
  91814. b[11] = (FLAC__byte)xx; xx >>= 8;
  91815. b[10] = (FLAC__byte)xx; xx >>= 8;
  91816. b[9] = (FLAC__byte)xx; xx >>= 8;
  91817. b[8] = (FLAC__byte)xx; xx >>= 8;
  91818. x = encoder->private_->seek_table->points[i].frame_samples;
  91819. b[17] = (FLAC__byte)x; x >>= 8;
  91820. b[16] = (FLAC__byte)x; x >>= 8;
  91821. if(encoder->private_->write_callback(encoder, b, 18, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91822. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91823. return;
  91824. }
  91825. }
  91826. }
  91827. }
  91828. #if FLAC__HAS_OGG
  91829. void update_ogg_metadata_(FLAC__StreamEncoder *encoder)
  91830. {
  91831. static const unsigned FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH =
  91832. FLAC__OGG_MAPPING_PACKET_TYPE_LENGTH +
  91833. FLAC__OGG_MAPPING_MAGIC_LENGTH +
  91834. FLAC__OGG_MAPPING_VERSION_MAJOR_LENGTH +
  91835. FLAC__OGG_MAPPING_VERSION_MINOR_LENGTH +
  91836. FLAC__OGG_MAPPING_NUM_HEADERS_LENGTH +
  91837. FLAC__STREAM_SYNC_LENGTH
  91838. ;
  91839. FLAC__byte b[max(6, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)];
  91840. const FLAC__StreamMetadata *metadata = &encoder->private_->streaminfo;
  91841. const FLAC__uint64 samples = metadata->data.stream_info.total_samples;
  91842. const unsigned min_framesize = metadata->data.stream_info.min_framesize;
  91843. const unsigned max_framesize = metadata->data.stream_info.max_framesize;
  91844. ogg_page page;
  91845. FLAC__ASSERT(metadata->type == FLAC__METADATA_TYPE_STREAMINFO);
  91846. FLAC__ASSERT(0 != encoder->private_->seek_callback);
  91847. if(encoder->private_->seek_callback(encoder, 0, encoder->private_->client_data) == FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED)
  91848. return;
  91849. simple_ogg_page__init(&page);
  91850. if(!simple_ogg_page__get_at(encoder, encoder->protected_->streaminfo_offset, &page, encoder->private_->seek_callback, encoder->private_->read_callback, encoder->private_->client_data)) {
  91851. simple_ogg_page__clear(&page);
  91852. return; /* state already set */
  91853. }
  91854. {
  91855. const unsigned md5_offset =
  91856. FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
  91857. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91858. (
  91859. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91860. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  91861. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  91862. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  91863. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  91864. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  91865. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN +
  91866. FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN
  91867. ) / 8;
  91868. if(md5_offset + 16 > (unsigned)page.body_len) {
  91869. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  91870. simple_ogg_page__clear(&page);
  91871. return;
  91872. }
  91873. memcpy(page.body + md5_offset, metadata->data.stream_info.md5sum, 16);
  91874. }
  91875. {
  91876. const unsigned total_samples_byte_offset =
  91877. FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
  91878. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91879. (
  91880. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91881. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  91882. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  91883. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  91884. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  91885. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  91886. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN
  91887. - 4
  91888. ) / 8;
  91889. if(total_samples_byte_offset + 5 > (unsigned)page.body_len) {
  91890. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  91891. simple_ogg_page__clear(&page);
  91892. return;
  91893. }
  91894. b[0] = (FLAC__byte)page.body[total_samples_byte_offset] & 0xF0;
  91895. b[0] |= (FLAC__byte)((samples >> 32) & 0x0F);
  91896. b[1] = (FLAC__byte)((samples >> 24) & 0xFF);
  91897. b[2] = (FLAC__byte)((samples >> 16) & 0xFF);
  91898. b[3] = (FLAC__byte)((samples >> 8) & 0xFF);
  91899. b[4] = (FLAC__byte)(samples & 0xFF);
  91900. memcpy(page.body + total_samples_byte_offset, b, 5);
  91901. }
  91902. {
  91903. const unsigned min_framesize_offset =
  91904. FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
  91905. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91906. (
  91907. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91908. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN
  91909. ) / 8;
  91910. if(min_framesize_offset + 6 > (unsigned)page.body_len) {
  91911. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  91912. simple_ogg_page__clear(&page);
  91913. return;
  91914. }
  91915. b[0] = (FLAC__byte)((min_framesize >> 16) & 0xFF);
  91916. b[1] = (FLAC__byte)((min_framesize >> 8) & 0xFF);
  91917. b[2] = (FLAC__byte)(min_framesize & 0xFF);
  91918. b[3] = (FLAC__byte)((max_framesize >> 16) & 0xFF);
  91919. b[4] = (FLAC__byte)((max_framesize >> 8) & 0xFF);
  91920. b[5] = (FLAC__byte)(max_framesize & 0xFF);
  91921. memcpy(page.body + min_framesize_offset, b, 6);
  91922. }
  91923. if(!simple_ogg_page__set_at(encoder, encoder->protected_->streaminfo_offset, &page, encoder->private_->seek_callback, encoder->private_->write_callback, encoder->private_->client_data)) {
  91924. simple_ogg_page__clear(&page);
  91925. return; /* state already set */
  91926. }
  91927. simple_ogg_page__clear(&page);
  91928. if(0 != encoder->private_->seek_table && encoder->private_->seek_table->num_points > 0 && encoder->protected_->seektable_offset > 0) {
  91929. unsigned i;
  91930. FLAC__byte *p;
  91931. FLAC__format_seektable_sort(encoder->private_->seek_table);
  91932. FLAC__ASSERT(FLAC__format_seektable_is_legal(encoder->private_->seek_table));
  91933. simple_ogg_page__init(&page);
  91934. if(!simple_ogg_page__get_at(encoder, encoder->protected_->seektable_offset, &page, encoder->private_->seek_callback, encoder->private_->read_callback, encoder->private_->client_data)) {
  91935. simple_ogg_page__clear(&page);
  91936. return; /* state already set */
  91937. }
  91938. if((FLAC__STREAM_METADATA_HEADER_LENGTH + 18*encoder->private_->seek_table->num_points) != (unsigned)page.body_len) {
  91939. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  91940. simple_ogg_page__clear(&page);
  91941. return;
  91942. }
  91943. for(i = 0, p = page.body + FLAC__STREAM_METADATA_HEADER_LENGTH; i < encoder->private_->seek_table->num_points; i++, p += 18) {
  91944. FLAC__uint64 xx;
  91945. unsigned x;
  91946. xx = encoder->private_->seek_table->points[i].sample_number;
  91947. b[7] = (FLAC__byte)xx; xx >>= 8;
  91948. b[6] = (FLAC__byte)xx; xx >>= 8;
  91949. b[5] = (FLAC__byte)xx; xx >>= 8;
  91950. b[4] = (FLAC__byte)xx; xx >>= 8;
  91951. b[3] = (FLAC__byte)xx; xx >>= 8;
  91952. b[2] = (FLAC__byte)xx; xx >>= 8;
  91953. b[1] = (FLAC__byte)xx; xx >>= 8;
  91954. b[0] = (FLAC__byte)xx; xx >>= 8;
  91955. xx = encoder->private_->seek_table->points[i].stream_offset;
  91956. b[15] = (FLAC__byte)xx; xx >>= 8;
  91957. b[14] = (FLAC__byte)xx; xx >>= 8;
  91958. b[13] = (FLAC__byte)xx; xx >>= 8;
  91959. b[12] = (FLAC__byte)xx; xx >>= 8;
  91960. b[11] = (FLAC__byte)xx; xx >>= 8;
  91961. b[10] = (FLAC__byte)xx; xx >>= 8;
  91962. b[9] = (FLAC__byte)xx; xx >>= 8;
  91963. b[8] = (FLAC__byte)xx; xx >>= 8;
  91964. x = encoder->private_->seek_table->points[i].frame_samples;
  91965. b[17] = (FLAC__byte)x; x >>= 8;
  91966. b[16] = (FLAC__byte)x; x >>= 8;
  91967. memcpy(p, b, 18);
  91968. }
  91969. if(!simple_ogg_page__set_at(encoder, encoder->protected_->seektable_offset, &page, encoder->private_->seek_callback, encoder->private_->write_callback, encoder->private_->client_data)) {
  91970. simple_ogg_page__clear(&page);
  91971. return; /* state already set */
  91972. }
  91973. simple_ogg_page__clear(&page);
  91974. }
  91975. }
  91976. #endif
  91977. FLAC__bool process_frame_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block, FLAC__bool is_last_block)
  91978. {
  91979. FLAC__uint16 crc;
  91980. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91981. 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)) {
  91982. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91983. return false;
  91984. }
  91985. if(!process_subframes_(encoder, is_fractional_block)) {
  91986. return false;
  91987. }
  91988. if(!FLAC__bitwriter_zero_pad_to_byte_boundary(encoder->private_->frame)) {
  91989. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91990. return false;
  91991. }
  91992. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(encoder->private_->frame));
  91993. if(
  91994. !FLAC__bitwriter_get_write_crc16(encoder->private_->frame, &crc) ||
  91995. !FLAC__bitwriter_write_raw_uint32(encoder->private_->frame, crc, FLAC__FRAME_FOOTER_CRC_LEN)
  91996. ) {
  91997. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91998. return false;
  91999. }
  92000. if(!write_bitbuffer_(encoder, encoder->protected_->blocksize, is_last_block)) {
  92001. return false;
  92002. }
  92003. encoder->private_->current_sample_number = 0;
  92004. encoder->private_->current_frame_number++;
  92005. encoder->private_->streaminfo.data.stream_info.total_samples += (FLAC__uint64)encoder->protected_->blocksize;
  92006. return true;
  92007. }
  92008. FLAC__bool process_subframes_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block)
  92009. {
  92010. FLAC__FrameHeader frame_header;
  92011. unsigned channel, min_partition_order = encoder->protected_->min_residual_partition_order, max_partition_order;
  92012. FLAC__bool do_independent, do_mid_side;
  92013. if(is_fractional_block) {
  92014. max_partition_order = 0;
  92015. }
  92016. else {
  92017. max_partition_order = FLAC__format_get_max_rice_partition_order_from_blocksize(encoder->protected_->blocksize);
  92018. max_partition_order = min(max_partition_order, encoder->protected_->max_residual_partition_order);
  92019. }
  92020. min_partition_order = min(min_partition_order, max_partition_order);
  92021. frame_header.blocksize = encoder->protected_->blocksize;
  92022. frame_header.sample_rate = encoder->protected_->sample_rate;
  92023. frame_header.channels = encoder->protected_->channels;
  92024. frame_header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT; /* the default unless the encoder determines otherwise */
  92025. frame_header.bits_per_sample = encoder->protected_->bits_per_sample;
  92026. frame_header.number_type = FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER;
  92027. frame_header.number.frame_number = encoder->private_->current_frame_number;
  92028. if(encoder->protected_->do_mid_side_stereo) {
  92029. if(encoder->protected_->loose_mid_side_stereo) {
  92030. if(encoder->private_->loose_mid_side_stereo_frame_count == 0) {
  92031. do_independent = true;
  92032. do_mid_side = true;
  92033. }
  92034. else {
  92035. do_independent = (encoder->private_->last_channel_assignment == FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT);
  92036. do_mid_side = !do_independent;
  92037. }
  92038. }
  92039. else {
  92040. do_independent = true;
  92041. do_mid_side = true;
  92042. }
  92043. }
  92044. else {
  92045. do_independent = true;
  92046. do_mid_side = false;
  92047. }
  92048. FLAC__ASSERT(do_independent || do_mid_side);
  92049. if(do_independent) {
  92050. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  92051. const unsigned w = get_wasted_bits_(encoder->private_->integer_signal[channel], encoder->protected_->blocksize);
  92052. encoder->private_->subframe_workspace[channel][0].wasted_bits = encoder->private_->subframe_workspace[channel][1].wasted_bits = w;
  92053. encoder->private_->subframe_bps[channel] = encoder->protected_->bits_per_sample - w;
  92054. }
  92055. }
  92056. if(do_mid_side) {
  92057. FLAC__ASSERT(encoder->protected_->channels == 2);
  92058. for(channel = 0; channel < 2; channel++) {
  92059. const unsigned w = get_wasted_bits_(encoder->private_->integer_signal_mid_side[channel], encoder->protected_->blocksize);
  92060. encoder->private_->subframe_workspace_mid_side[channel][0].wasted_bits = encoder->private_->subframe_workspace_mid_side[channel][1].wasted_bits = w;
  92061. encoder->private_->subframe_bps_mid_side[channel] = encoder->protected_->bits_per_sample - w + (channel==0? 0:1);
  92062. }
  92063. }
  92064. if(do_independent) {
  92065. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  92066. if(!
  92067. process_subframe_(
  92068. encoder,
  92069. min_partition_order,
  92070. max_partition_order,
  92071. &frame_header,
  92072. encoder->private_->subframe_bps[channel],
  92073. encoder->private_->integer_signal[channel],
  92074. encoder->private_->subframe_workspace_ptr[channel],
  92075. encoder->private_->partitioned_rice_contents_workspace_ptr[channel],
  92076. encoder->private_->residual_workspace[channel],
  92077. encoder->private_->best_subframe+channel,
  92078. encoder->private_->best_subframe_bits+channel
  92079. )
  92080. )
  92081. return false;
  92082. }
  92083. }
  92084. if(do_mid_side) {
  92085. FLAC__ASSERT(encoder->protected_->channels == 2);
  92086. for(channel = 0; channel < 2; channel++) {
  92087. if(!
  92088. process_subframe_(
  92089. encoder,
  92090. min_partition_order,
  92091. max_partition_order,
  92092. &frame_header,
  92093. encoder->private_->subframe_bps_mid_side[channel],
  92094. encoder->private_->integer_signal_mid_side[channel],
  92095. encoder->private_->subframe_workspace_ptr_mid_side[channel],
  92096. encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[channel],
  92097. encoder->private_->residual_workspace_mid_side[channel],
  92098. encoder->private_->best_subframe_mid_side+channel,
  92099. encoder->private_->best_subframe_bits_mid_side+channel
  92100. )
  92101. )
  92102. return false;
  92103. }
  92104. }
  92105. if(do_mid_side) {
  92106. unsigned left_bps = 0, right_bps = 0; /* initialized only to prevent superfluous compiler warning */
  92107. FLAC__Subframe *left_subframe = 0, *right_subframe = 0; /* initialized only to prevent superfluous compiler warning */
  92108. FLAC__ChannelAssignment channel_assignment;
  92109. FLAC__ASSERT(encoder->protected_->channels == 2);
  92110. if(encoder->protected_->loose_mid_side_stereo && encoder->private_->loose_mid_side_stereo_frame_count > 0) {
  92111. channel_assignment = (encoder->private_->last_channel_assignment == FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT? FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT : FLAC__CHANNEL_ASSIGNMENT_MID_SIDE);
  92112. }
  92113. else {
  92114. unsigned bits[4]; /* WATCHOUT - indexed by FLAC__ChannelAssignment */
  92115. unsigned min_bits;
  92116. int ca;
  92117. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT == 0);
  92118. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE == 1);
  92119. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE == 2);
  92120. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_MID_SIDE == 3);
  92121. FLAC__ASSERT(do_independent && do_mid_side);
  92122. bits[FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT] = encoder->private_->best_subframe_bits [0] + encoder->private_->best_subframe_bits [1];
  92123. bits[FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE ] = encoder->private_->best_subframe_bits [0] + encoder->private_->best_subframe_bits_mid_side[1];
  92124. bits[FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE ] = encoder->private_->best_subframe_bits [1] + encoder->private_->best_subframe_bits_mid_side[1];
  92125. bits[FLAC__CHANNEL_ASSIGNMENT_MID_SIDE ] = encoder->private_->best_subframe_bits_mid_side[0] + encoder->private_->best_subframe_bits_mid_side[1];
  92126. channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT;
  92127. min_bits = bits[channel_assignment];
  92128. for(ca = 1; ca <= 3; ca++) {
  92129. if(bits[ca] < min_bits) {
  92130. min_bits = bits[ca];
  92131. channel_assignment = (FLAC__ChannelAssignment)ca;
  92132. }
  92133. }
  92134. }
  92135. frame_header.channel_assignment = channel_assignment;
  92136. if(!FLAC__frame_add_header(&frame_header, encoder->private_->frame)) {
  92137. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92138. return false;
  92139. }
  92140. switch(channel_assignment) {
  92141. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  92142. left_subframe = &encoder->private_->subframe_workspace [0][encoder->private_->best_subframe [0]];
  92143. right_subframe = &encoder->private_->subframe_workspace [1][encoder->private_->best_subframe [1]];
  92144. break;
  92145. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  92146. left_subframe = &encoder->private_->subframe_workspace [0][encoder->private_->best_subframe [0]];
  92147. right_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
  92148. break;
  92149. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  92150. left_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
  92151. right_subframe = &encoder->private_->subframe_workspace [1][encoder->private_->best_subframe [1]];
  92152. break;
  92153. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  92154. left_subframe = &encoder->private_->subframe_workspace_mid_side[0][encoder->private_->best_subframe_mid_side[0]];
  92155. right_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
  92156. break;
  92157. default:
  92158. FLAC__ASSERT(0);
  92159. }
  92160. switch(channel_assignment) {
  92161. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  92162. left_bps = encoder->private_->subframe_bps [0];
  92163. right_bps = encoder->private_->subframe_bps [1];
  92164. break;
  92165. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  92166. left_bps = encoder->private_->subframe_bps [0];
  92167. right_bps = encoder->private_->subframe_bps_mid_side[1];
  92168. break;
  92169. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  92170. left_bps = encoder->private_->subframe_bps_mid_side[1];
  92171. right_bps = encoder->private_->subframe_bps [1];
  92172. break;
  92173. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  92174. left_bps = encoder->private_->subframe_bps_mid_side[0];
  92175. right_bps = encoder->private_->subframe_bps_mid_side[1];
  92176. break;
  92177. default:
  92178. FLAC__ASSERT(0);
  92179. }
  92180. if(!add_subframe_(encoder, frame_header.blocksize, left_bps , left_subframe , encoder->private_->frame))
  92181. return false;
  92182. if(!add_subframe_(encoder, frame_header.blocksize, right_bps, right_subframe, encoder->private_->frame))
  92183. return false;
  92184. }
  92185. else {
  92186. if(!FLAC__frame_add_header(&frame_header, encoder->private_->frame)) {
  92187. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92188. return false;
  92189. }
  92190. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  92191. 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)) {
  92192. return false;
  92193. }
  92194. }
  92195. }
  92196. if(encoder->protected_->loose_mid_side_stereo) {
  92197. encoder->private_->loose_mid_side_stereo_frame_count++;
  92198. if(encoder->private_->loose_mid_side_stereo_frame_count >= encoder->private_->loose_mid_side_stereo_frames)
  92199. encoder->private_->loose_mid_side_stereo_frame_count = 0;
  92200. }
  92201. encoder->private_->last_channel_assignment = frame_header.channel_assignment;
  92202. return true;
  92203. }
  92204. FLAC__bool process_subframe_(
  92205. FLAC__StreamEncoder *encoder,
  92206. unsigned min_partition_order,
  92207. unsigned max_partition_order,
  92208. const FLAC__FrameHeader *frame_header,
  92209. unsigned subframe_bps,
  92210. const FLAC__int32 integer_signal[],
  92211. FLAC__Subframe *subframe[2],
  92212. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents[2],
  92213. FLAC__int32 *residual[2],
  92214. unsigned *best_subframe,
  92215. unsigned *best_bits
  92216. )
  92217. {
  92218. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92219. FLAC__float fixed_residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1];
  92220. #else
  92221. FLAC__fixedpoint fixed_residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1];
  92222. #endif
  92223. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92224. FLAC__double lpc_residual_bits_per_sample;
  92225. 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 */
  92226. FLAC__double lpc_error[FLAC__MAX_LPC_ORDER];
  92227. unsigned min_lpc_order, max_lpc_order, lpc_order;
  92228. unsigned min_qlp_coeff_precision, max_qlp_coeff_precision, qlp_coeff_precision;
  92229. #endif
  92230. unsigned min_fixed_order, max_fixed_order, guess_fixed_order, fixed_order;
  92231. unsigned rice_parameter;
  92232. unsigned _candidate_bits, _best_bits;
  92233. unsigned _best_subframe;
  92234. 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;
  92235. FLAC__ASSERT(frame_header->blocksize > 0);
  92236. _best_subframe = 0;
  92237. if(encoder->private_->disable_verbatim_subframes && frame_header->blocksize >= FLAC__MAX_FIXED_ORDER)
  92238. _best_bits = UINT_MAX;
  92239. else
  92240. _best_bits = evaluate_verbatim_subframe_(encoder, integer_signal, frame_header->blocksize, subframe_bps, subframe[_best_subframe]);
  92241. if(frame_header->blocksize >= FLAC__MAX_FIXED_ORDER) {
  92242. unsigned signal_is_constant = false;
  92243. 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);
  92244. if(
  92245. !encoder->private_->disable_constant_subframes &&
  92246. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92247. fixed_residual_bits_per_sample[1] == 0.0
  92248. #else
  92249. fixed_residual_bits_per_sample[1] == FLAC__FP_ZERO
  92250. #endif
  92251. ) {
  92252. unsigned i;
  92253. signal_is_constant = true;
  92254. for(i = 1; i < frame_header->blocksize; i++) {
  92255. if(integer_signal[0] != integer_signal[i]) {
  92256. signal_is_constant = false;
  92257. break;
  92258. }
  92259. }
  92260. }
  92261. if(signal_is_constant) {
  92262. _candidate_bits = evaluate_constant_subframe_(encoder, integer_signal[0], frame_header->blocksize, subframe_bps, subframe[!_best_subframe]);
  92263. if(_candidate_bits < _best_bits) {
  92264. _best_subframe = !_best_subframe;
  92265. _best_bits = _candidate_bits;
  92266. }
  92267. }
  92268. else {
  92269. if(!encoder->private_->disable_fixed_subframes || (encoder->protected_->max_lpc_order == 0 && _best_bits == UINT_MAX)) {
  92270. if(encoder->protected_->do_exhaustive_model_search) {
  92271. min_fixed_order = 0;
  92272. max_fixed_order = FLAC__MAX_FIXED_ORDER;
  92273. }
  92274. else {
  92275. min_fixed_order = max_fixed_order = guess_fixed_order;
  92276. }
  92277. if(max_fixed_order >= frame_header->blocksize)
  92278. max_fixed_order = frame_header->blocksize - 1;
  92279. for(fixed_order = min_fixed_order; fixed_order <= max_fixed_order; fixed_order++) {
  92280. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92281. if(fixed_residual_bits_per_sample[fixed_order] >= (FLAC__float)subframe_bps)
  92282. continue; /* don't even try */
  92283. 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 */
  92284. #else
  92285. if(FLAC__fixedpoint_trunc(fixed_residual_bits_per_sample[fixed_order]) >= (int)subframe_bps)
  92286. continue; /* don't even try */
  92287. 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 */
  92288. #endif
  92289. rice_parameter++; /* to account for the signed->unsigned conversion during rice coding */
  92290. if(rice_parameter >= rice_parameter_limit) {
  92291. #ifdef DEBUG_VERBOSE
  92292. fprintf(stderr, "clipping rice_parameter (%u -> %u) @0\n", rice_parameter, rice_parameter_limit - 1);
  92293. #endif
  92294. rice_parameter = rice_parameter_limit - 1;
  92295. }
  92296. _candidate_bits =
  92297. evaluate_fixed_subframe_(
  92298. encoder,
  92299. integer_signal,
  92300. residual[!_best_subframe],
  92301. encoder->private_->abs_residual_partition_sums,
  92302. encoder->private_->raw_bits_per_partition,
  92303. frame_header->blocksize,
  92304. subframe_bps,
  92305. fixed_order,
  92306. rice_parameter,
  92307. rice_parameter_limit,
  92308. min_partition_order,
  92309. max_partition_order,
  92310. encoder->protected_->do_escape_coding,
  92311. encoder->protected_->rice_parameter_search_dist,
  92312. subframe[!_best_subframe],
  92313. partitioned_rice_contents[!_best_subframe]
  92314. );
  92315. if(_candidate_bits < _best_bits) {
  92316. _best_subframe = !_best_subframe;
  92317. _best_bits = _candidate_bits;
  92318. }
  92319. }
  92320. }
  92321. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92322. if(encoder->protected_->max_lpc_order > 0) {
  92323. if(encoder->protected_->max_lpc_order >= frame_header->blocksize)
  92324. max_lpc_order = frame_header->blocksize-1;
  92325. else
  92326. max_lpc_order = encoder->protected_->max_lpc_order;
  92327. if(max_lpc_order > 0) {
  92328. unsigned a;
  92329. for (a = 0; a < encoder->protected_->num_apodizations; a++) {
  92330. FLAC__lpc_window_data(integer_signal, encoder->private_->window[a], encoder->private_->windowed_signal, frame_header->blocksize);
  92331. encoder->private_->local_lpc_compute_autocorrelation(encoder->private_->windowed_signal, frame_header->blocksize, max_lpc_order+1, autoc);
  92332. if(autoc[0] != 0.0) {
  92333. FLAC__lpc_compute_lp_coefficients(autoc, &max_lpc_order, encoder->private_->lp_coeff, lpc_error);
  92334. if(encoder->protected_->do_exhaustive_model_search) {
  92335. min_lpc_order = 1;
  92336. }
  92337. else {
  92338. const unsigned guess_lpc_order =
  92339. FLAC__lpc_compute_best_order(
  92340. lpc_error,
  92341. max_lpc_order,
  92342. frame_header->blocksize,
  92343. subframe_bps + (
  92344. encoder->protected_->do_qlp_coeff_prec_search?
  92345. FLAC__MIN_QLP_COEFF_PRECISION : /* have to guess; use the min possible size to avoid accidentally favoring lower orders */
  92346. encoder->protected_->qlp_coeff_precision
  92347. )
  92348. );
  92349. min_lpc_order = max_lpc_order = guess_lpc_order;
  92350. }
  92351. if(max_lpc_order >= frame_header->blocksize)
  92352. max_lpc_order = frame_header->blocksize - 1;
  92353. for(lpc_order = min_lpc_order; lpc_order <= max_lpc_order; lpc_order++) {
  92354. lpc_residual_bits_per_sample = FLAC__lpc_compute_expected_bits_per_residual_sample(lpc_error[lpc_order-1], frame_header->blocksize-lpc_order);
  92355. if(lpc_residual_bits_per_sample >= (FLAC__double)subframe_bps)
  92356. continue; /* don't even try */
  92357. rice_parameter = (lpc_residual_bits_per_sample > 0.0)? (unsigned)(lpc_residual_bits_per_sample+0.5) : 0; /* 0.5 is for rounding */
  92358. rice_parameter++; /* to account for the signed->unsigned conversion during rice coding */
  92359. if(rice_parameter >= rice_parameter_limit) {
  92360. #ifdef DEBUG_VERBOSE
  92361. fprintf(stderr, "clipping rice_parameter (%u -> %u) @1\n", rice_parameter, rice_parameter_limit - 1);
  92362. #endif
  92363. rice_parameter = rice_parameter_limit - 1;
  92364. }
  92365. if(encoder->protected_->do_qlp_coeff_prec_search) {
  92366. min_qlp_coeff_precision = FLAC__MIN_QLP_COEFF_PRECISION;
  92367. if(subframe_bps <= 17) {
  92368. max_qlp_coeff_precision = min(32 - subframe_bps - lpc_order, FLAC__MAX_QLP_COEFF_PRECISION);
  92369. max_qlp_coeff_precision = max(max_qlp_coeff_precision, min_qlp_coeff_precision);
  92370. }
  92371. else
  92372. max_qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION;
  92373. }
  92374. else {
  92375. min_qlp_coeff_precision = max_qlp_coeff_precision = encoder->protected_->qlp_coeff_precision;
  92376. }
  92377. for(qlp_coeff_precision = min_qlp_coeff_precision; qlp_coeff_precision <= max_qlp_coeff_precision; qlp_coeff_precision++) {
  92378. _candidate_bits =
  92379. evaluate_lpc_subframe_(
  92380. encoder,
  92381. integer_signal,
  92382. residual[!_best_subframe],
  92383. encoder->private_->abs_residual_partition_sums,
  92384. encoder->private_->raw_bits_per_partition,
  92385. encoder->private_->lp_coeff[lpc_order-1],
  92386. frame_header->blocksize,
  92387. subframe_bps,
  92388. lpc_order,
  92389. qlp_coeff_precision,
  92390. rice_parameter,
  92391. rice_parameter_limit,
  92392. min_partition_order,
  92393. max_partition_order,
  92394. encoder->protected_->do_escape_coding,
  92395. encoder->protected_->rice_parameter_search_dist,
  92396. subframe[!_best_subframe],
  92397. partitioned_rice_contents[!_best_subframe]
  92398. );
  92399. if(_candidate_bits > 0) { /* if == 0, there was a problem quantizing the lpcoeffs */
  92400. if(_candidate_bits < _best_bits) {
  92401. _best_subframe = !_best_subframe;
  92402. _best_bits = _candidate_bits;
  92403. }
  92404. }
  92405. }
  92406. }
  92407. }
  92408. }
  92409. }
  92410. }
  92411. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  92412. }
  92413. }
  92414. if(_best_bits == UINT_MAX) {
  92415. FLAC__ASSERT(_best_subframe == 0);
  92416. _best_bits = evaluate_verbatim_subframe_(encoder, integer_signal, frame_header->blocksize, subframe_bps, subframe[_best_subframe]);
  92417. }
  92418. *best_subframe = _best_subframe;
  92419. *best_bits = _best_bits;
  92420. return true;
  92421. }
  92422. FLAC__bool add_subframe_(
  92423. FLAC__StreamEncoder *encoder,
  92424. unsigned blocksize,
  92425. unsigned subframe_bps,
  92426. const FLAC__Subframe *subframe,
  92427. FLAC__BitWriter *frame
  92428. )
  92429. {
  92430. switch(subframe->type) {
  92431. case FLAC__SUBFRAME_TYPE_CONSTANT:
  92432. if(!FLAC__subframe_add_constant(&(subframe->data.constant), subframe_bps, subframe->wasted_bits, frame)) {
  92433. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92434. return false;
  92435. }
  92436. break;
  92437. case FLAC__SUBFRAME_TYPE_FIXED:
  92438. if(!FLAC__subframe_add_fixed(&(subframe->data.fixed), blocksize - subframe->data.fixed.order, subframe_bps, subframe->wasted_bits, frame)) {
  92439. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92440. return false;
  92441. }
  92442. break;
  92443. case FLAC__SUBFRAME_TYPE_LPC:
  92444. if(!FLAC__subframe_add_lpc(&(subframe->data.lpc), blocksize - subframe->data.lpc.order, subframe_bps, subframe->wasted_bits, frame)) {
  92445. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92446. return false;
  92447. }
  92448. break;
  92449. case FLAC__SUBFRAME_TYPE_VERBATIM:
  92450. if(!FLAC__subframe_add_verbatim(&(subframe->data.verbatim), blocksize, subframe_bps, subframe->wasted_bits, frame)) {
  92451. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92452. return false;
  92453. }
  92454. break;
  92455. default:
  92456. FLAC__ASSERT(0);
  92457. }
  92458. return true;
  92459. }
  92460. #define SPOTCHECK_ESTIMATE 0
  92461. #if SPOTCHECK_ESTIMATE
  92462. static void spotcheck_subframe_estimate_(
  92463. FLAC__StreamEncoder *encoder,
  92464. unsigned blocksize,
  92465. unsigned subframe_bps,
  92466. const FLAC__Subframe *subframe,
  92467. unsigned estimate
  92468. )
  92469. {
  92470. FLAC__bool ret;
  92471. FLAC__BitWriter *frame = FLAC__bitwriter_new();
  92472. if(frame == 0) {
  92473. fprintf(stderr, "EST: can't allocate frame\n");
  92474. return;
  92475. }
  92476. if(!FLAC__bitwriter_init(frame)) {
  92477. fprintf(stderr, "EST: can't init frame\n");
  92478. return;
  92479. }
  92480. ret = add_subframe_(encoder, blocksize, subframe_bps, subframe, frame);
  92481. FLAC__ASSERT(ret);
  92482. {
  92483. const unsigned actual = FLAC__bitwriter_get_input_bits_unconsumed(frame);
  92484. if(estimate != actual)
  92485. 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);
  92486. }
  92487. FLAC__bitwriter_delete(frame);
  92488. }
  92489. #endif
  92490. unsigned evaluate_constant_subframe_(
  92491. FLAC__StreamEncoder *encoder,
  92492. const FLAC__int32 signal,
  92493. unsigned blocksize,
  92494. unsigned subframe_bps,
  92495. FLAC__Subframe *subframe
  92496. )
  92497. {
  92498. unsigned estimate;
  92499. subframe->type = FLAC__SUBFRAME_TYPE_CONSTANT;
  92500. subframe->data.constant.value = signal;
  92501. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + subframe_bps;
  92502. #if SPOTCHECK_ESTIMATE
  92503. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92504. #else
  92505. (void)encoder, (void)blocksize;
  92506. #endif
  92507. return estimate;
  92508. }
  92509. unsigned evaluate_fixed_subframe_(
  92510. FLAC__StreamEncoder *encoder,
  92511. const FLAC__int32 signal[],
  92512. FLAC__int32 residual[],
  92513. FLAC__uint64 abs_residual_partition_sums[],
  92514. unsigned raw_bits_per_partition[],
  92515. unsigned blocksize,
  92516. unsigned subframe_bps,
  92517. unsigned order,
  92518. unsigned rice_parameter,
  92519. unsigned rice_parameter_limit,
  92520. unsigned min_partition_order,
  92521. unsigned max_partition_order,
  92522. FLAC__bool do_escape_coding,
  92523. unsigned rice_parameter_search_dist,
  92524. FLAC__Subframe *subframe,
  92525. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  92526. )
  92527. {
  92528. unsigned i, residual_bits, estimate;
  92529. const unsigned residual_samples = blocksize - order;
  92530. FLAC__fixed_compute_residual(signal+order, residual_samples, order, residual);
  92531. subframe->type = FLAC__SUBFRAME_TYPE_FIXED;
  92532. subframe->data.fixed.entropy_coding_method.type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE;
  92533. subframe->data.fixed.entropy_coding_method.data.partitioned_rice.contents = partitioned_rice_contents;
  92534. subframe->data.fixed.residual = residual;
  92535. residual_bits =
  92536. find_best_partition_order_(
  92537. encoder->private_,
  92538. residual,
  92539. abs_residual_partition_sums,
  92540. raw_bits_per_partition,
  92541. residual_samples,
  92542. order,
  92543. rice_parameter,
  92544. rice_parameter_limit,
  92545. min_partition_order,
  92546. max_partition_order,
  92547. subframe_bps,
  92548. do_escape_coding,
  92549. rice_parameter_search_dist,
  92550. &subframe->data.fixed.entropy_coding_method
  92551. );
  92552. subframe->data.fixed.order = order;
  92553. for(i = 0; i < order; i++)
  92554. subframe->data.fixed.warmup[i] = signal[i];
  92555. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + (order * subframe_bps) + residual_bits;
  92556. #if SPOTCHECK_ESTIMATE
  92557. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92558. #endif
  92559. return estimate;
  92560. }
  92561. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92562. unsigned evaluate_lpc_subframe_(
  92563. FLAC__StreamEncoder *encoder,
  92564. const FLAC__int32 signal[],
  92565. FLAC__int32 residual[],
  92566. FLAC__uint64 abs_residual_partition_sums[],
  92567. unsigned raw_bits_per_partition[],
  92568. const FLAC__real lp_coeff[],
  92569. unsigned blocksize,
  92570. unsigned subframe_bps,
  92571. unsigned order,
  92572. unsigned qlp_coeff_precision,
  92573. unsigned rice_parameter,
  92574. unsigned rice_parameter_limit,
  92575. unsigned min_partition_order,
  92576. unsigned max_partition_order,
  92577. FLAC__bool do_escape_coding,
  92578. unsigned rice_parameter_search_dist,
  92579. FLAC__Subframe *subframe,
  92580. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  92581. )
  92582. {
  92583. FLAC__int32 qlp_coeff[FLAC__MAX_LPC_ORDER];
  92584. unsigned i, residual_bits, estimate;
  92585. int quantization, ret;
  92586. const unsigned residual_samples = blocksize - order;
  92587. if(subframe_bps <= 16) {
  92588. FLAC__ASSERT(order > 0);
  92589. FLAC__ASSERT(order <= FLAC__MAX_LPC_ORDER);
  92590. qlp_coeff_precision = min(qlp_coeff_precision, 32 - subframe_bps - FLAC__bitmath_ilog2(order));
  92591. }
  92592. ret = FLAC__lpc_quantize_coefficients(lp_coeff, order, qlp_coeff_precision, qlp_coeff, &quantization);
  92593. if(ret != 0)
  92594. return 0; /* this is a hack to indicate to the caller that we can't do lp at this order on this subframe */
  92595. if(subframe_bps + qlp_coeff_precision + FLAC__bitmath_ilog2(order) <= 32)
  92596. if(subframe_bps <= 16 && qlp_coeff_precision <= 16)
  92597. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
  92598. else
  92599. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
  92600. else
  92601. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_64bit(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
  92602. subframe->type = FLAC__SUBFRAME_TYPE_LPC;
  92603. subframe->data.lpc.entropy_coding_method.type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE;
  92604. subframe->data.lpc.entropy_coding_method.data.partitioned_rice.contents = partitioned_rice_contents;
  92605. subframe->data.lpc.residual = residual;
  92606. residual_bits =
  92607. find_best_partition_order_(
  92608. encoder->private_,
  92609. residual,
  92610. abs_residual_partition_sums,
  92611. raw_bits_per_partition,
  92612. residual_samples,
  92613. order,
  92614. rice_parameter,
  92615. rice_parameter_limit,
  92616. min_partition_order,
  92617. max_partition_order,
  92618. subframe_bps,
  92619. do_escape_coding,
  92620. rice_parameter_search_dist,
  92621. &subframe->data.lpc.entropy_coding_method
  92622. );
  92623. subframe->data.lpc.order = order;
  92624. subframe->data.lpc.qlp_coeff_precision = qlp_coeff_precision;
  92625. subframe->data.lpc.quantization_level = quantization;
  92626. memcpy(subframe->data.lpc.qlp_coeff, qlp_coeff, sizeof(FLAC__int32)*FLAC__MAX_LPC_ORDER);
  92627. for(i = 0; i < order; i++)
  92628. subframe->data.lpc.warmup[i] = signal[i];
  92629. 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;
  92630. #if SPOTCHECK_ESTIMATE
  92631. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92632. #endif
  92633. return estimate;
  92634. }
  92635. #endif
  92636. unsigned evaluate_verbatim_subframe_(
  92637. FLAC__StreamEncoder *encoder,
  92638. const FLAC__int32 signal[],
  92639. unsigned blocksize,
  92640. unsigned subframe_bps,
  92641. FLAC__Subframe *subframe
  92642. )
  92643. {
  92644. unsigned estimate;
  92645. subframe->type = FLAC__SUBFRAME_TYPE_VERBATIM;
  92646. subframe->data.verbatim.data = signal;
  92647. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + (blocksize * subframe_bps);
  92648. #if SPOTCHECK_ESTIMATE
  92649. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92650. #else
  92651. (void)encoder;
  92652. #endif
  92653. return estimate;
  92654. }
  92655. unsigned find_best_partition_order_(
  92656. FLAC__StreamEncoderPrivate *private_,
  92657. const FLAC__int32 residual[],
  92658. FLAC__uint64 abs_residual_partition_sums[],
  92659. unsigned raw_bits_per_partition[],
  92660. unsigned residual_samples,
  92661. unsigned predictor_order,
  92662. unsigned rice_parameter,
  92663. unsigned rice_parameter_limit,
  92664. unsigned min_partition_order,
  92665. unsigned max_partition_order,
  92666. unsigned bps,
  92667. FLAC__bool do_escape_coding,
  92668. unsigned rice_parameter_search_dist,
  92669. FLAC__EntropyCodingMethod *best_ecm
  92670. )
  92671. {
  92672. unsigned residual_bits, best_residual_bits = 0;
  92673. unsigned best_parameters_index = 0;
  92674. unsigned best_partition_order = 0;
  92675. const unsigned blocksize = residual_samples + predictor_order;
  92676. max_partition_order = FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(max_partition_order, blocksize, predictor_order);
  92677. min_partition_order = min(min_partition_order, max_partition_order);
  92678. precompute_partition_info_sums_(residual, abs_residual_partition_sums, residual_samples, predictor_order, min_partition_order, max_partition_order, bps);
  92679. if(do_escape_coding)
  92680. precompute_partition_info_escapes_(residual, raw_bits_per_partition, residual_samples, predictor_order, min_partition_order, max_partition_order);
  92681. {
  92682. int partition_order;
  92683. unsigned sum;
  92684. for(partition_order = (int)max_partition_order, sum = 0; partition_order >= (int)min_partition_order; partition_order--) {
  92685. if(!
  92686. set_partitioned_rice_(
  92687. #ifdef EXACT_RICE_BITS_CALCULATION
  92688. residual,
  92689. #endif
  92690. abs_residual_partition_sums+sum,
  92691. raw_bits_per_partition+sum,
  92692. residual_samples,
  92693. predictor_order,
  92694. rice_parameter,
  92695. rice_parameter_limit,
  92696. rice_parameter_search_dist,
  92697. (unsigned)partition_order,
  92698. do_escape_coding,
  92699. &private_->partitioned_rice_contents_extra[!best_parameters_index],
  92700. &residual_bits
  92701. )
  92702. )
  92703. {
  92704. FLAC__ASSERT(best_residual_bits != 0);
  92705. break;
  92706. }
  92707. sum += 1u << partition_order;
  92708. if(best_residual_bits == 0 || residual_bits < best_residual_bits) {
  92709. best_residual_bits = residual_bits;
  92710. best_parameters_index = !best_parameters_index;
  92711. best_partition_order = partition_order;
  92712. }
  92713. }
  92714. }
  92715. best_ecm->data.partitioned_rice.order = best_partition_order;
  92716. {
  92717. FLAC__EntropyCodingMethod_PartitionedRiceContents* prc = (FLAC__EntropyCodingMethod_PartitionedRiceContents*)best_ecm->data.partitioned_rice.contents;
  92718. unsigned partition;
  92719. FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(prc, max(6, best_partition_order));
  92720. memcpy(prc->parameters, private_->partitioned_rice_contents_extra[best_parameters_index].parameters, sizeof(unsigned)*(1<<(best_partition_order)));
  92721. if(do_escape_coding)
  92722. memcpy(prc->raw_bits, private_->partitioned_rice_contents_extra[best_parameters_index].raw_bits, sizeof(unsigned)*(1<<(best_partition_order)));
  92723. for(partition = 0; partition < (1u<<best_partition_order); partition++) {
  92724. if(prc->parameters[partition] >= FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER) {
  92725. best_ecm->type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2;
  92726. break;
  92727. }
  92728. }
  92729. }
  92730. return best_residual_bits;
  92731. }
  92732. #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM
  92733. extern void precompute_partition_info_sums_32bit_asm_ia32_(
  92734. const FLAC__int32 residual[],
  92735. FLAC__uint64 abs_residual_partition_sums[],
  92736. unsigned blocksize,
  92737. unsigned predictor_order,
  92738. unsigned min_partition_order,
  92739. unsigned max_partition_order
  92740. );
  92741. #endif
  92742. void precompute_partition_info_sums_(
  92743. const FLAC__int32 residual[],
  92744. FLAC__uint64 abs_residual_partition_sums[],
  92745. unsigned residual_samples,
  92746. unsigned predictor_order,
  92747. unsigned min_partition_order,
  92748. unsigned max_partition_order,
  92749. unsigned bps
  92750. )
  92751. {
  92752. const unsigned default_partition_samples = (residual_samples + predictor_order) >> max_partition_order;
  92753. unsigned partitions = 1u << max_partition_order;
  92754. FLAC__ASSERT(default_partition_samples > predictor_order);
  92755. #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM
  92756. if(FLAC__bitmath_ilog2(default_partition_samples) + bps < 32) {
  92757. precompute_partition_info_sums_32bit_asm_ia32_(residual, abs_residual_partition_sums, residual_samples + predictor_order, predictor_order, min_partition_order, max_partition_order);
  92758. return;
  92759. }
  92760. #endif
  92761. {
  92762. unsigned partition, residual_sample, end = (unsigned)(-(int)predictor_order);
  92763. if(FLAC__bitmath_ilog2(default_partition_samples) + bps < 32) {
  92764. FLAC__uint32 abs_residual_partition_sum;
  92765. for(partition = residual_sample = 0; partition < partitions; partition++) {
  92766. end += default_partition_samples;
  92767. abs_residual_partition_sum = 0;
  92768. for( ; residual_sample < end; residual_sample++)
  92769. abs_residual_partition_sum += abs(residual[residual_sample]); /* abs(INT_MIN) is undefined, but if the residual is INT_MIN we have bigger problems */
  92770. abs_residual_partition_sums[partition] = abs_residual_partition_sum;
  92771. }
  92772. }
  92773. else { /* have to pessimistically use 64 bits for accumulator */
  92774. FLAC__uint64 abs_residual_partition_sum;
  92775. for(partition = residual_sample = 0; partition < partitions; partition++) {
  92776. end += default_partition_samples;
  92777. abs_residual_partition_sum = 0;
  92778. for( ; residual_sample < end; residual_sample++)
  92779. abs_residual_partition_sum += abs(residual[residual_sample]); /* abs(INT_MIN) is undefined, but if the residual is INT_MIN we have bigger problems */
  92780. abs_residual_partition_sums[partition] = abs_residual_partition_sum;
  92781. }
  92782. }
  92783. }
  92784. {
  92785. unsigned from_partition = 0, to_partition = partitions;
  92786. int partition_order;
  92787. for(partition_order = (int)max_partition_order - 1; partition_order >= (int)min_partition_order; partition_order--) {
  92788. unsigned i;
  92789. partitions >>= 1;
  92790. for(i = 0; i < partitions; i++) {
  92791. abs_residual_partition_sums[to_partition++] =
  92792. abs_residual_partition_sums[from_partition ] +
  92793. abs_residual_partition_sums[from_partition+1];
  92794. from_partition += 2;
  92795. }
  92796. }
  92797. }
  92798. }
  92799. void precompute_partition_info_escapes_(
  92800. const FLAC__int32 residual[],
  92801. unsigned raw_bits_per_partition[],
  92802. unsigned residual_samples,
  92803. unsigned predictor_order,
  92804. unsigned min_partition_order,
  92805. unsigned max_partition_order
  92806. )
  92807. {
  92808. int partition_order;
  92809. unsigned from_partition, to_partition = 0;
  92810. const unsigned blocksize = residual_samples + predictor_order;
  92811. for(partition_order = (int)max_partition_order; partition_order >= 0; partition_order--) {
  92812. FLAC__int32 r;
  92813. FLAC__uint32 rmax;
  92814. unsigned partition, partition_sample, partition_samples, residual_sample;
  92815. const unsigned partitions = 1u << partition_order;
  92816. const unsigned default_partition_samples = blocksize >> partition_order;
  92817. FLAC__ASSERT(default_partition_samples > predictor_order);
  92818. for(partition = residual_sample = 0; partition < partitions; partition++) {
  92819. partition_samples = default_partition_samples;
  92820. if(partition == 0)
  92821. partition_samples -= predictor_order;
  92822. rmax = 0;
  92823. for(partition_sample = 0; partition_sample < partition_samples; partition_sample++) {
  92824. r = residual[residual_sample++];
  92825. if(r < 0)
  92826. rmax |= ~r;
  92827. else
  92828. rmax |= r;
  92829. }
  92830. raw_bits_per_partition[partition] = rmax? FLAC__bitmath_ilog2(rmax) + 2 : 1;
  92831. }
  92832. to_partition = partitions;
  92833. break; /*@@@ yuck, should remove the 'for' loop instead */
  92834. }
  92835. for(from_partition = 0, --partition_order; partition_order >= (int)min_partition_order; partition_order--) {
  92836. unsigned m;
  92837. unsigned i;
  92838. const unsigned partitions = 1u << partition_order;
  92839. for(i = 0; i < partitions; i++) {
  92840. m = raw_bits_per_partition[from_partition];
  92841. from_partition++;
  92842. raw_bits_per_partition[to_partition] = max(m, raw_bits_per_partition[from_partition]);
  92843. from_partition++;
  92844. to_partition++;
  92845. }
  92846. }
  92847. }
  92848. #ifdef EXACT_RICE_BITS_CALCULATION
  92849. static FLaC__INLINE unsigned count_rice_bits_in_partition_(
  92850. const unsigned rice_parameter,
  92851. const unsigned partition_samples,
  92852. const FLAC__int32 *residual
  92853. )
  92854. {
  92855. unsigned i, partition_bits =
  92856. 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 */
  92857. (1+rice_parameter) * partition_samples /* 1 for unary stop bit + rice_parameter for the binary portion */
  92858. ;
  92859. for(i = 0; i < partition_samples; i++)
  92860. partition_bits += ( (FLAC__uint32)((residual[i]<<1)^(residual[i]>>31)) >> rice_parameter );
  92861. return partition_bits;
  92862. }
  92863. #else
  92864. static FLaC__INLINE unsigned count_rice_bits_in_partition_(
  92865. const unsigned rice_parameter,
  92866. const unsigned partition_samples,
  92867. const FLAC__uint64 abs_residual_partition_sum
  92868. )
  92869. {
  92870. return
  92871. 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 */
  92872. (1+rice_parameter) * partition_samples + /* 1 for unary stop bit + rice_parameter for the binary portion */
  92873. (
  92874. rice_parameter?
  92875. (unsigned)(abs_residual_partition_sum >> (rice_parameter-1)) /* rice_parameter-1 because the real coder sign-folds instead of using a sign bit */
  92876. : (unsigned)(abs_residual_partition_sum << 1) /* can't shift by negative number, so reverse */
  92877. )
  92878. - (partition_samples >> 1)
  92879. ;
  92880. }
  92881. #endif
  92882. FLAC__bool set_partitioned_rice_(
  92883. #ifdef EXACT_RICE_BITS_CALCULATION
  92884. const FLAC__int32 residual[],
  92885. #endif
  92886. const FLAC__uint64 abs_residual_partition_sums[],
  92887. const unsigned raw_bits_per_partition[],
  92888. const unsigned residual_samples,
  92889. const unsigned predictor_order,
  92890. const unsigned suggested_rice_parameter,
  92891. const unsigned rice_parameter_limit,
  92892. const unsigned rice_parameter_search_dist,
  92893. const unsigned partition_order,
  92894. const FLAC__bool search_for_escapes,
  92895. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents,
  92896. unsigned *bits
  92897. )
  92898. {
  92899. unsigned rice_parameter, partition_bits;
  92900. unsigned best_partition_bits, best_rice_parameter = 0;
  92901. unsigned bits_ = FLAC__ENTROPY_CODING_METHOD_TYPE_LEN + FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN;
  92902. unsigned *parameters, *raw_bits;
  92903. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  92904. unsigned min_rice_parameter, max_rice_parameter;
  92905. #else
  92906. (void)rice_parameter_search_dist;
  92907. #endif
  92908. FLAC__ASSERT(suggested_rice_parameter < FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER);
  92909. FLAC__ASSERT(rice_parameter_limit <= FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER);
  92910. FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(partitioned_rice_contents, max(6, partition_order));
  92911. parameters = partitioned_rice_contents->parameters;
  92912. raw_bits = partitioned_rice_contents->raw_bits;
  92913. if(partition_order == 0) {
  92914. best_partition_bits = (unsigned)(-1);
  92915. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  92916. if(rice_parameter_search_dist) {
  92917. if(suggested_rice_parameter < rice_parameter_search_dist)
  92918. min_rice_parameter = 0;
  92919. else
  92920. min_rice_parameter = suggested_rice_parameter - rice_parameter_search_dist;
  92921. max_rice_parameter = suggested_rice_parameter + rice_parameter_search_dist;
  92922. if(max_rice_parameter >= rice_parameter_limit) {
  92923. #ifdef DEBUG_VERBOSE
  92924. fprintf(stderr, "clipping rice_parameter (%u -> %u) @5\n", max_rice_parameter, rice_parameter_limit - 1);
  92925. #endif
  92926. max_rice_parameter = rice_parameter_limit - 1;
  92927. }
  92928. }
  92929. else
  92930. min_rice_parameter = max_rice_parameter = suggested_rice_parameter;
  92931. for(rice_parameter = min_rice_parameter; rice_parameter <= max_rice_parameter; rice_parameter++) {
  92932. #else
  92933. rice_parameter = suggested_rice_parameter;
  92934. #endif
  92935. #ifdef EXACT_RICE_BITS_CALCULATION
  92936. partition_bits = count_rice_bits_in_partition_(rice_parameter, residual_samples, residual);
  92937. #else
  92938. partition_bits = count_rice_bits_in_partition_(rice_parameter, residual_samples, abs_residual_partition_sums[0]);
  92939. #endif
  92940. if(partition_bits < best_partition_bits) {
  92941. best_rice_parameter = rice_parameter;
  92942. best_partition_bits = partition_bits;
  92943. }
  92944. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  92945. }
  92946. #endif
  92947. if(search_for_escapes) {
  92948. 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;
  92949. if(partition_bits <= best_partition_bits) {
  92950. raw_bits[0] = raw_bits_per_partition[0];
  92951. best_rice_parameter = 0; /* will be converted to appropriate escape parameter later */
  92952. best_partition_bits = partition_bits;
  92953. }
  92954. else
  92955. raw_bits[0] = 0;
  92956. }
  92957. parameters[0] = best_rice_parameter;
  92958. bits_ += best_partition_bits;
  92959. }
  92960. else {
  92961. unsigned partition, residual_sample;
  92962. unsigned partition_samples;
  92963. FLAC__uint64 mean, k;
  92964. const unsigned partitions = 1u << partition_order;
  92965. for(partition = residual_sample = 0; partition < partitions; partition++) {
  92966. partition_samples = (residual_samples+predictor_order) >> partition_order;
  92967. if(partition == 0) {
  92968. if(partition_samples <= predictor_order)
  92969. return false;
  92970. else
  92971. partition_samples -= predictor_order;
  92972. }
  92973. mean = abs_residual_partition_sums[partition];
  92974. for(rice_parameter = 0, k = partition_samples; k < mean; rice_parameter++, k <<= 1)
  92975. ;
  92976. if(rice_parameter >= rice_parameter_limit) {
  92977. #ifdef DEBUG_VERBOSE
  92978. fprintf(stderr, "clipping rice_parameter (%u -> %u) @6\n", rice_parameter, rice_parameter_limit - 1);
  92979. #endif
  92980. rice_parameter = rice_parameter_limit - 1;
  92981. }
  92982. best_partition_bits = (unsigned)(-1);
  92983. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  92984. if(rice_parameter_search_dist) {
  92985. if(rice_parameter < rice_parameter_search_dist)
  92986. min_rice_parameter = 0;
  92987. else
  92988. min_rice_parameter = rice_parameter - rice_parameter_search_dist;
  92989. max_rice_parameter = rice_parameter + rice_parameter_search_dist;
  92990. if(max_rice_parameter >= rice_parameter_limit) {
  92991. #ifdef DEBUG_VERBOSE
  92992. fprintf(stderr, "clipping rice_parameter (%u -> %u) @7\n", max_rice_parameter, rice_parameter_limit - 1);
  92993. #endif
  92994. max_rice_parameter = rice_parameter_limit - 1;
  92995. }
  92996. }
  92997. else
  92998. min_rice_parameter = max_rice_parameter = rice_parameter;
  92999. for(rice_parameter = min_rice_parameter; rice_parameter <= max_rice_parameter; rice_parameter++) {
  93000. #endif
  93001. #ifdef EXACT_RICE_BITS_CALCULATION
  93002. partition_bits = count_rice_bits_in_partition_(rice_parameter, partition_samples, residual+residual_sample);
  93003. #else
  93004. partition_bits = count_rice_bits_in_partition_(rice_parameter, partition_samples, abs_residual_partition_sums[partition]);
  93005. #endif
  93006. if(partition_bits < best_partition_bits) {
  93007. best_rice_parameter = rice_parameter;
  93008. best_partition_bits = partition_bits;
  93009. }
  93010. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  93011. }
  93012. #endif
  93013. if(search_for_escapes) {
  93014. 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;
  93015. if(partition_bits <= best_partition_bits) {
  93016. raw_bits[partition] = raw_bits_per_partition[partition];
  93017. best_rice_parameter = 0; /* will be converted to appropriate escape parameter later */
  93018. best_partition_bits = partition_bits;
  93019. }
  93020. else
  93021. raw_bits[partition] = 0;
  93022. }
  93023. parameters[partition] = best_rice_parameter;
  93024. bits_ += best_partition_bits;
  93025. residual_sample += partition_samples;
  93026. }
  93027. }
  93028. *bits = bits_;
  93029. return true;
  93030. }
  93031. unsigned get_wasted_bits_(FLAC__int32 signal[], unsigned samples)
  93032. {
  93033. unsigned i, shift;
  93034. FLAC__int32 x = 0;
  93035. for(i = 0; i < samples && !(x&1); i++)
  93036. x |= signal[i];
  93037. if(x == 0) {
  93038. shift = 0;
  93039. }
  93040. else {
  93041. for(shift = 0; !(x&1); shift++)
  93042. x >>= 1;
  93043. }
  93044. if(shift > 0) {
  93045. for(i = 0; i < samples; i++)
  93046. signal[i] >>= shift;
  93047. }
  93048. return shift;
  93049. }
  93050. void append_to_verify_fifo_(verify_input_fifo *fifo, const FLAC__int32 * const input[], unsigned input_offset, unsigned channels, unsigned wide_samples)
  93051. {
  93052. unsigned channel;
  93053. for(channel = 0; channel < channels; channel++)
  93054. memcpy(&fifo->data[channel][fifo->tail], &input[channel][input_offset], sizeof(FLAC__int32) * wide_samples);
  93055. fifo->tail += wide_samples;
  93056. FLAC__ASSERT(fifo->tail <= fifo->size);
  93057. }
  93058. void append_to_verify_fifo_interleaved_(verify_input_fifo *fifo, const FLAC__int32 input[], unsigned input_offset, unsigned channels, unsigned wide_samples)
  93059. {
  93060. unsigned channel;
  93061. unsigned sample, wide_sample;
  93062. unsigned tail = fifo->tail;
  93063. sample = input_offset * channels;
  93064. for(wide_sample = 0; wide_sample < wide_samples; wide_sample++) {
  93065. for(channel = 0; channel < channels; channel++)
  93066. fifo->data[channel][tail] = input[sample++];
  93067. tail++;
  93068. }
  93069. fifo->tail = tail;
  93070. FLAC__ASSERT(fifo->tail <= fifo->size);
  93071. }
  93072. FLAC__StreamDecoderReadStatus verify_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  93073. {
  93074. FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder*)client_data;
  93075. const size_t encoded_bytes = encoder->private_->verify.output.bytes;
  93076. (void)decoder;
  93077. if(encoder->private_->verify.needs_magic_hack) {
  93078. FLAC__ASSERT(*bytes >= FLAC__STREAM_SYNC_LENGTH);
  93079. *bytes = FLAC__STREAM_SYNC_LENGTH;
  93080. memcpy(buffer, FLAC__STREAM_SYNC_STRING, *bytes);
  93081. encoder->private_->verify.needs_magic_hack = false;
  93082. }
  93083. else {
  93084. if(encoded_bytes == 0) {
  93085. FLAC__ASSERT(0);
  93086. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  93087. }
  93088. else if(encoded_bytes < *bytes)
  93089. *bytes = encoded_bytes;
  93090. memcpy(buffer, encoder->private_->verify.output.data, *bytes);
  93091. encoder->private_->verify.output.data += *bytes;
  93092. encoder->private_->verify.output.bytes -= *bytes;
  93093. }
  93094. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  93095. }
  93096. FLAC__StreamDecoderWriteStatus verify_write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data)
  93097. {
  93098. FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder *)client_data;
  93099. unsigned channel;
  93100. const unsigned channels = frame->header.channels;
  93101. const unsigned blocksize = frame->header.blocksize;
  93102. const unsigned bytes_per_block = sizeof(FLAC__int32) * blocksize;
  93103. (void)decoder;
  93104. for(channel = 0; channel < channels; channel++) {
  93105. if(0 != memcmp(buffer[channel], encoder->private_->verify.input_fifo.data[channel], bytes_per_block)) {
  93106. unsigned i, sample = 0;
  93107. FLAC__int32 expect = 0, got = 0;
  93108. for(i = 0; i < blocksize; i++) {
  93109. if(buffer[channel][i] != encoder->private_->verify.input_fifo.data[channel][i]) {
  93110. sample = i;
  93111. expect = (FLAC__int32)encoder->private_->verify.input_fifo.data[channel][i];
  93112. got = (FLAC__int32)buffer[channel][i];
  93113. break;
  93114. }
  93115. }
  93116. FLAC__ASSERT(i < blocksize);
  93117. FLAC__ASSERT(frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  93118. encoder->private_->verify.error_stats.absolute_sample = frame->header.number.sample_number + sample;
  93119. encoder->private_->verify.error_stats.frame_number = (unsigned)(frame->header.number.sample_number / blocksize);
  93120. encoder->private_->verify.error_stats.channel = channel;
  93121. encoder->private_->verify.error_stats.sample = sample;
  93122. encoder->private_->verify.error_stats.expected = expect;
  93123. encoder->private_->verify.error_stats.got = got;
  93124. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA;
  93125. return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
  93126. }
  93127. }
  93128. encoder->private_->verify.input_fifo.tail -= blocksize;
  93129. FLAC__ASSERT(encoder->private_->verify.input_fifo.tail <= OVERREAD_);
  93130. for(channel = 0; channel < channels; channel++)
  93131. 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]));
  93132. return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  93133. }
  93134. void verify_metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data)
  93135. {
  93136. (void)decoder, (void)metadata, (void)client_data;
  93137. }
  93138. void verify_error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data)
  93139. {
  93140. FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder*)client_data;
  93141. (void)decoder, (void)status;
  93142. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  93143. }
  93144. FLAC__StreamEncoderReadStatus file_read_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  93145. {
  93146. (void)client_data;
  93147. *bytes = fread(buffer, 1, *bytes, encoder->private_->file);
  93148. if (*bytes == 0) {
  93149. if (feof(encoder->private_->file))
  93150. return FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM;
  93151. else if (ferror(encoder->private_->file))
  93152. return FLAC__STREAM_ENCODER_READ_STATUS_ABORT;
  93153. }
  93154. return FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE;
  93155. }
  93156. FLAC__StreamEncoderSeekStatus file_seek_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data)
  93157. {
  93158. (void)client_data;
  93159. if(fseeko(encoder->private_->file, (off_t)absolute_byte_offset, SEEK_SET) < 0)
  93160. return FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR;
  93161. else
  93162. return FLAC__STREAM_ENCODER_SEEK_STATUS_OK;
  93163. }
  93164. FLAC__StreamEncoderTellStatus file_tell_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
  93165. {
  93166. off_t offset;
  93167. (void)client_data;
  93168. offset = ftello(encoder->private_->file);
  93169. if(offset < 0) {
  93170. return FLAC__STREAM_ENCODER_TELL_STATUS_ERROR;
  93171. }
  93172. else {
  93173. *absolute_byte_offset = (FLAC__uint64)offset;
  93174. return FLAC__STREAM_ENCODER_TELL_STATUS_OK;
  93175. }
  93176. }
  93177. #ifdef FLAC__VALGRIND_TESTING
  93178. static size_t local__fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
  93179. {
  93180. size_t ret = fwrite(ptr, size, nmemb, stream);
  93181. if(!ferror(stream))
  93182. fflush(stream);
  93183. return ret;
  93184. }
  93185. #else
  93186. #define local__fwrite fwrite
  93187. #endif
  93188. FLAC__StreamEncoderWriteStatus file_write_callback_(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame, void *client_data)
  93189. {
  93190. (void)client_data, (void)current_frame;
  93191. if(local__fwrite(buffer, sizeof(FLAC__byte), bytes, encoder->private_->file) == bytes) {
  93192. FLAC__bool call_it = 0 != encoder->private_->progress_callback && (
  93193. #if FLAC__HAS_OGG
  93194. encoder->private_->is_ogg? true :
  93195. #endif
  93196. samples > 0
  93197. );
  93198. if(call_it) {
  93199. 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);
  93200. }
  93201. return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
  93202. }
  93203. else
  93204. return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
  93205. }
  93206. FILE *get_binary_stdout_(void)
  93207. {
  93208. #if defined _MSC_VER || defined __MINGW32__
  93209. _setmode(_fileno(stdout), _O_BINARY);
  93210. #elif defined __CYGWIN__
  93211. setmode(_fileno(stdout), _O_BINARY);
  93212. #elif defined __EMX__
  93213. setmode(fileno(stdout), O_BINARY);
  93214. #endif
  93215. return stdout;
  93216. }
  93217. #endif
  93218. /*** End of inlined file: stream_encoder.c ***/
  93219. /*** Start of inlined file: stream_encoder_framing.c ***/
  93220. /*** Start of inlined file: juce_FlacHeader.h ***/
  93221. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  93222. // tasks..
  93223. #define VERSION "1.2.1"
  93224. #define FLAC__NO_DLL 1
  93225. #if JUCE_MSVC
  93226. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  93227. #endif
  93228. #if JUCE_MAC
  93229. #define FLAC__SYS_DARWIN 1
  93230. #endif
  93231. /*** End of inlined file: juce_FlacHeader.h ***/
  93232. #if JUCE_USE_FLAC
  93233. #if HAVE_CONFIG_H
  93234. # include <config.h>
  93235. #endif
  93236. #include <stdio.h>
  93237. #include <string.h> /* for strlen() */
  93238. #ifdef max
  93239. #undef max
  93240. #endif
  93241. #define max(x,y) ((x)>(y)?(x):(y))
  93242. static FLAC__bool add_entropy_coding_method_(FLAC__BitWriter *bw, const FLAC__EntropyCodingMethod *method);
  93243. 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);
  93244. FLAC__bool FLAC__add_metadata_block(const FLAC__StreamMetadata *metadata, FLAC__BitWriter *bw)
  93245. {
  93246. unsigned i, j;
  93247. const unsigned vendor_string_length = (unsigned)strlen(FLAC__VENDOR_STRING);
  93248. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->is_last, FLAC__STREAM_METADATA_IS_LAST_LEN))
  93249. return false;
  93250. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->type, FLAC__STREAM_METADATA_TYPE_LEN))
  93251. return false;
  93252. i = metadata->length;
  93253. if(metadata->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
  93254. FLAC__ASSERT(metadata->data.vorbis_comment.vendor_string.length == 0 || 0 != metadata->data.vorbis_comment.vendor_string.entry);
  93255. i -= metadata->data.vorbis_comment.vendor_string.length;
  93256. i += vendor_string_length;
  93257. }
  93258. FLAC__ASSERT(i < (1u << FLAC__STREAM_METADATA_LENGTH_LEN));
  93259. if(!FLAC__bitwriter_write_raw_uint32(bw, i, FLAC__STREAM_METADATA_LENGTH_LEN))
  93260. return false;
  93261. switch(metadata->type) {
  93262. case FLAC__METADATA_TYPE_STREAMINFO:
  93263. FLAC__ASSERT(metadata->data.stream_info.min_blocksize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN));
  93264. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.min_blocksize, FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN))
  93265. return false;
  93266. FLAC__ASSERT(metadata->data.stream_info.max_blocksize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN));
  93267. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.max_blocksize, FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN))
  93268. return false;
  93269. FLAC__ASSERT(metadata->data.stream_info.min_framesize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN));
  93270. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.min_framesize, FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN))
  93271. return false;
  93272. FLAC__ASSERT(metadata->data.stream_info.max_framesize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN));
  93273. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.max_framesize, FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN))
  93274. return false;
  93275. FLAC__ASSERT(FLAC__format_sample_rate_is_valid(metadata->data.stream_info.sample_rate));
  93276. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.sample_rate, FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN))
  93277. return false;
  93278. FLAC__ASSERT(metadata->data.stream_info.channels > 0);
  93279. FLAC__ASSERT(metadata->data.stream_info.channels <= (1u << FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN));
  93280. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.channels-1, FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN))
  93281. return false;
  93282. FLAC__ASSERT(metadata->data.stream_info.bits_per_sample > 0);
  93283. FLAC__ASSERT(metadata->data.stream_info.bits_per_sample <= (1u << FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN));
  93284. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.bits_per_sample-1, FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN))
  93285. return false;
  93286. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.stream_info.total_samples, FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN))
  93287. return false;
  93288. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.stream_info.md5sum, 16))
  93289. return false;
  93290. break;
  93291. case FLAC__METADATA_TYPE_PADDING:
  93292. if(!FLAC__bitwriter_write_zeroes(bw, metadata->length * 8))
  93293. return false;
  93294. break;
  93295. case FLAC__METADATA_TYPE_APPLICATION:
  93296. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.application.id, FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8))
  93297. return false;
  93298. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.application.data, metadata->length - (FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8)))
  93299. return false;
  93300. break;
  93301. case FLAC__METADATA_TYPE_SEEKTABLE:
  93302. for(i = 0; i < metadata->data.seek_table.num_points; i++) {
  93303. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.seek_table.points[i].sample_number, FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN))
  93304. return false;
  93305. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.seek_table.points[i].stream_offset, FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN))
  93306. return false;
  93307. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.seek_table.points[i].frame_samples, FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN))
  93308. return false;
  93309. }
  93310. break;
  93311. case FLAC__METADATA_TYPE_VORBIS_COMMENT:
  93312. if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, vendor_string_length))
  93313. return false;
  93314. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)FLAC__VENDOR_STRING, vendor_string_length))
  93315. return false;
  93316. if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, metadata->data.vorbis_comment.num_comments))
  93317. return false;
  93318. for(i = 0; i < metadata->data.vorbis_comment.num_comments; i++) {
  93319. if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, metadata->data.vorbis_comment.comments[i].length))
  93320. return false;
  93321. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.vorbis_comment.comments[i].entry, metadata->data.vorbis_comment.comments[i].length))
  93322. return false;
  93323. }
  93324. break;
  93325. case FLAC__METADATA_TYPE_CUESHEET:
  93326. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN % 8 == 0);
  93327. 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))
  93328. return false;
  93329. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.cue_sheet.lead_in, FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN))
  93330. return false;
  93331. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.cue_sheet.is_cd? 1 : 0, FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN))
  93332. return false;
  93333. if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN))
  93334. return false;
  93335. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.cue_sheet.num_tracks, FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN))
  93336. return false;
  93337. for(i = 0; i < metadata->data.cue_sheet.num_tracks; i++) {
  93338. const FLAC__StreamMetadata_CueSheet_Track *track = metadata->data.cue_sheet.tracks + i;
  93339. if(!FLAC__bitwriter_write_raw_uint64(bw, track->offset, FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN))
  93340. return false;
  93341. if(!FLAC__bitwriter_write_raw_uint32(bw, track->number, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN))
  93342. return false;
  93343. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN % 8 == 0);
  93344. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)track->isrc, FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN/8))
  93345. return false;
  93346. if(!FLAC__bitwriter_write_raw_uint32(bw, track->type, FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN))
  93347. return false;
  93348. if(!FLAC__bitwriter_write_raw_uint32(bw, track->pre_emphasis, FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN))
  93349. return false;
  93350. if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN))
  93351. return false;
  93352. if(!FLAC__bitwriter_write_raw_uint32(bw, track->num_indices, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN))
  93353. return false;
  93354. for(j = 0; j < track->num_indices; j++) {
  93355. const FLAC__StreamMetadata_CueSheet_Index *index = track->indices + j;
  93356. if(!FLAC__bitwriter_write_raw_uint64(bw, index->offset, FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN))
  93357. return false;
  93358. if(!FLAC__bitwriter_write_raw_uint32(bw, index->number, FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN))
  93359. return false;
  93360. if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN))
  93361. return false;
  93362. }
  93363. }
  93364. break;
  93365. case FLAC__METADATA_TYPE_PICTURE:
  93366. {
  93367. size_t len;
  93368. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.type, FLAC__STREAM_METADATA_PICTURE_TYPE_LEN))
  93369. return false;
  93370. len = strlen(metadata->data.picture.mime_type);
  93371. if(!FLAC__bitwriter_write_raw_uint32(bw, len, FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN))
  93372. return false;
  93373. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)metadata->data.picture.mime_type, len))
  93374. return false;
  93375. len = strlen((const char *)metadata->data.picture.description);
  93376. if(!FLAC__bitwriter_write_raw_uint32(bw, len, FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN))
  93377. return false;
  93378. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.picture.description, len))
  93379. return false;
  93380. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.width, FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN))
  93381. return false;
  93382. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.height, FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN))
  93383. return false;
  93384. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.depth, FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN))
  93385. return false;
  93386. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.colors, FLAC__STREAM_METADATA_PICTURE_COLORS_LEN))
  93387. return false;
  93388. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.data_length, FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN))
  93389. return false;
  93390. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.picture.data, metadata->data.picture.data_length))
  93391. return false;
  93392. }
  93393. break;
  93394. default:
  93395. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.unknown.data, metadata->length))
  93396. return false;
  93397. break;
  93398. }
  93399. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(bw));
  93400. return true;
  93401. }
  93402. FLAC__bool FLAC__frame_add_header(const FLAC__FrameHeader *header, FLAC__BitWriter *bw)
  93403. {
  93404. unsigned u, blocksize_hint, sample_rate_hint;
  93405. FLAC__byte crc;
  93406. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(bw));
  93407. if(!FLAC__bitwriter_write_raw_uint32(bw, FLAC__FRAME_HEADER_SYNC, FLAC__FRAME_HEADER_SYNC_LEN))
  93408. return false;
  93409. if(!FLAC__bitwriter_write_raw_uint32(bw, 0, FLAC__FRAME_HEADER_RESERVED_LEN))
  93410. return false;
  93411. if(!FLAC__bitwriter_write_raw_uint32(bw, (header->number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER)? 0 : 1, FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN))
  93412. return false;
  93413. FLAC__ASSERT(header->blocksize > 0 && header->blocksize <= FLAC__MAX_BLOCK_SIZE);
  93414. FLAC__ASSERT(FLAC__MAX_BLOCK_SIZE <= 65535u);
  93415. blocksize_hint = 0;
  93416. switch(header->blocksize) {
  93417. case 192: u = 1; break;
  93418. case 576: u = 2; break;
  93419. case 1152: u = 3; break;
  93420. case 2304: u = 4; break;
  93421. case 4608: u = 5; break;
  93422. case 256: u = 8; break;
  93423. case 512: u = 9; break;
  93424. case 1024: u = 10; break;
  93425. case 2048: u = 11; break;
  93426. case 4096: u = 12; break;
  93427. case 8192: u = 13; break;
  93428. case 16384: u = 14; break;
  93429. case 32768: u = 15; break;
  93430. default:
  93431. if(header->blocksize <= 0x100)
  93432. blocksize_hint = u = 6;
  93433. else
  93434. blocksize_hint = u = 7;
  93435. break;
  93436. }
  93437. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_BLOCK_SIZE_LEN))
  93438. return false;
  93439. FLAC__ASSERT(FLAC__format_sample_rate_is_valid(header->sample_rate));
  93440. sample_rate_hint = 0;
  93441. switch(header->sample_rate) {
  93442. case 88200: u = 1; break;
  93443. case 176400: u = 2; break;
  93444. case 192000: u = 3; break;
  93445. case 8000: u = 4; break;
  93446. case 16000: u = 5; break;
  93447. case 22050: u = 6; break;
  93448. case 24000: u = 7; break;
  93449. case 32000: u = 8; break;
  93450. case 44100: u = 9; break;
  93451. case 48000: u = 10; break;
  93452. case 96000: u = 11; break;
  93453. default:
  93454. if(header->sample_rate <= 255000 && header->sample_rate % 1000 == 0)
  93455. sample_rate_hint = u = 12;
  93456. else if(header->sample_rate % 10 == 0)
  93457. sample_rate_hint = u = 14;
  93458. else if(header->sample_rate <= 0xffff)
  93459. sample_rate_hint = u = 13;
  93460. else
  93461. u = 0;
  93462. break;
  93463. }
  93464. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_SAMPLE_RATE_LEN))
  93465. return false;
  93466. FLAC__ASSERT(header->channels > 0 && header->channels <= (1u << FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN) && header->channels <= FLAC__MAX_CHANNELS);
  93467. switch(header->channel_assignment) {
  93468. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  93469. u = header->channels - 1;
  93470. break;
  93471. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  93472. FLAC__ASSERT(header->channels == 2);
  93473. u = 8;
  93474. break;
  93475. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  93476. FLAC__ASSERT(header->channels == 2);
  93477. u = 9;
  93478. break;
  93479. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  93480. FLAC__ASSERT(header->channels == 2);
  93481. u = 10;
  93482. break;
  93483. default:
  93484. FLAC__ASSERT(0);
  93485. }
  93486. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN))
  93487. return false;
  93488. FLAC__ASSERT(header->bits_per_sample > 0 && header->bits_per_sample <= (1u << FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN));
  93489. switch(header->bits_per_sample) {
  93490. case 8 : u = 1; break;
  93491. case 12: u = 2; break;
  93492. case 16: u = 4; break;
  93493. case 20: u = 5; break;
  93494. case 24: u = 6; break;
  93495. default: u = 0; break;
  93496. }
  93497. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN))
  93498. return false;
  93499. if(!FLAC__bitwriter_write_raw_uint32(bw, 0, FLAC__FRAME_HEADER_ZERO_PAD_LEN))
  93500. return false;
  93501. if(header->number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER) {
  93502. if(!FLAC__bitwriter_write_utf8_uint32(bw, header->number.frame_number))
  93503. return false;
  93504. }
  93505. else {
  93506. if(!FLAC__bitwriter_write_utf8_uint64(bw, header->number.sample_number))
  93507. return false;
  93508. }
  93509. if(blocksize_hint)
  93510. if(!FLAC__bitwriter_write_raw_uint32(bw, header->blocksize-1, (blocksize_hint==6)? 8:16))
  93511. return false;
  93512. switch(sample_rate_hint) {
  93513. case 12:
  93514. if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate / 1000, 8))
  93515. return false;
  93516. break;
  93517. case 13:
  93518. if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate, 16))
  93519. return false;
  93520. break;
  93521. case 14:
  93522. if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate / 10, 16))
  93523. return false;
  93524. break;
  93525. }
  93526. if(!FLAC__bitwriter_get_write_crc8(bw, &crc))
  93527. return false;
  93528. if(!FLAC__bitwriter_write_raw_uint32(bw, crc, FLAC__FRAME_HEADER_CRC_LEN))
  93529. return false;
  93530. return true;
  93531. }
  93532. FLAC__bool FLAC__subframe_add_constant(const FLAC__Subframe_Constant *subframe, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93533. {
  93534. FLAC__bool ok;
  93535. ok =
  93536. 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) &&
  93537. (wasted_bits? FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1) : true) &&
  93538. FLAC__bitwriter_write_raw_int32(bw, subframe->value, subframe_bps)
  93539. ;
  93540. return ok;
  93541. }
  93542. FLAC__bool FLAC__subframe_add_fixed(const FLAC__Subframe_Fixed *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93543. {
  93544. unsigned i;
  93545. 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))
  93546. return false;
  93547. if(wasted_bits)
  93548. if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1))
  93549. return false;
  93550. for(i = 0; i < subframe->order; i++)
  93551. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->warmup[i], subframe_bps))
  93552. return false;
  93553. if(!add_entropy_coding_method_(bw, &subframe->entropy_coding_method))
  93554. return false;
  93555. switch(subframe->entropy_coding_method.type) {
  93556. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  93557. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  93558. if(!add_residual_partitioned_rice_(
  93559. bw,
  93560. subframe->residual,
  93561. residual_samples,
  93562. subframe->order,
  93563. subframe->entropy_coding_method.data.partitioned_rice.contents->parameters,
  93564. subframe->entropy_coding_method.data.partitioned_rice.contents->raw_bits,
  93565. subframe->entropy_coding_method.data.partitioned_rice.order,
  93566. subframe->entropy_coding_method.type == FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2
  93567. ))
  93568. return false;
  93569. break;
  93570. default:
  93571. FLAC__ASSERT(0);
  93572. }
  93573. return true;
  93574. }
  93575. FLAC__bool FLAC__subframe_add_lpc(const FLAC__Subframe_LPC *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93576. {
  93577. unsigned i;
  93578. 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))
  93579. return false;
  93580. if(wasted_bits)
  93581. if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1))
  93582. return false;
  93583. for(i = 0; i < subframe->order; i++)
  93584. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->warmup[i], subframe_bps))
  93585. return false;
  93586. if(!FLAC__bitwriter_write_raw_uint32(bw, subframe->qlp_coeff_precision-1, FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN))
  93587. return false;
  93588. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->quantization_level, FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN))
  93589. return false;
  93590. for(i = 0; i < subframe->order; i++)
  93591. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->qlp_coeff[i], subframe->qlp_coeff_precision))
  93592. return false;
  93593. if(!add_entropy_coding_method_(bw, &subframe->entropy_coding_method))
  93594. return false;
  93595. switch(subframe->entropy_coding_method.type) {
  93596. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  93597. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  93598. if(!add_residual_partitioned_rice_(
  93599. bw,
  93600. subframe->residual,
  93601. residual_samples,
  93602. subframe->order,
  93603. subframe->entropy_coding_method.data.partitioned_rice.contents->parameters,
  93604. subframe->entropy_coding_method.data.partitioned_rice.contents->raw_bits,
  93605. subframe->entropy_coding_method.data.partitioned_rice.order,
  93606. subframe->entropy_coding_method.type == FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2
  93607. ))
  93608. return false;
  93609. break;
  93610. default:
  93611. FLAC__ASSERT(0);
  93612. }
  93613. return true;
  93614. }
  93615. FLAC__bool FLAC__subframe_add_verbatim(const FLAC__Subframe_Verbatim *subframe, unsigned samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93616. {
  93617. unsigned i;
  93618. const FLAC__int32 *signal = subframe->data;
  93619. 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))
  93620. return false;
  93621. if(wasted_bits)
  93622. if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1))
  93623. return false;
  93624. for(i = 0; i < samples; i++)
  93625. if(!FLAC__bitwriter_write_raw_int32(bw, signal[i], subframe_bps))
  93626. return false;
  93627. return true;
  93628. }
  93629. FLAC__bool add_entropy_coding_method_(FLAC__BitWriter *bw, const FLAC__EntropyCodingMethod *method)
  93630. {
  93631. if(!FLAC__bitwriter_write_raw_uint32(bw, method->type, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN))
  93632. return false;
  93633. switch(method->type) {
  93634. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  93635. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  93636. if(!FLAC__bitwriter_write_raw_uint32(bw, method->data.partitioned_rice.order, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  93637. return false;
  93638. break;
  93639. default:
  93640. FLAC__ASSERT(0);
  93641. }
  93642. return true;
  93643. }
  93644. 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)
  93645. {
  93646. const unsigned plen = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN;
  93647. const unsigned pesc = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  93648. if(partition_order == 0) {
  93649. unsigned i;
  93650. if(raw_bits[0] == 0) {
  93651. if(!FLAC__bitwriter_write_raw_uint32(bw, rice_parameters[0], plen))
  93652. return false;
  93653. if(!FLAC__bitwriter_write_rice_signed_block(bw, residual, residual_samples, rice_parameters[0]))
  93654. return false;
  93655. }
  93656. else {
  93657. FLAC__ASSERT(rice_parameters[0] == 0);
  93658. if(!FLAC__bitwriter_write_raw_uint32(bw, pesc, plen))
  93659. return false;
  93660. if(!FLAC__bitwriter_write_raw_uint32(bw, raw_bits[0], FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN))
  93661. return false;
  93662. for(i = 0; i < residual_samples; i++) {
  93663. if(!FLAC__bitwriter_write_raw_int32(bw, residual[i], raw_bits[0]))
  93664. return false;
  93665. }
  93666. }
  93667. return true;
  93668. }
  93669. else {
  93670. unsigned i, j, k = 0, k_last = 0;
  93671. unsigned partition_samples;
  93672. const unsigned default_partition_samples = (residual_samples+predictor_order) >> partition_order;
  93673. for(i = 0; i < (1u<<partition_order); i++) {
  93674. partition_samples = default_partition_samples;
  93675. if(i == 0)
  93676. partition_samples -= predictor_order;
  93677. k += partition_samples;
  93678. if(raw_bits[i] == 0) {
  93679. if(!FLAC__bitwriter_write_raw_uint32(bw, rice_parameters[i], plen))
  93680. return false;
  93681. if(!FLAC__bitwriter_write_rice_signed_block(bw, residual+k_last, k-k_last, rice_parameters[i]))
  93682. return false;
  93683. }
  93684. else {
  93685. if(!FLAC__bitwriter_write_raw_uint32(bw, pesc, plen))
  93686. return false;
  93687. if(!FLAC__bitwriter_write_raw_uint32(bw, raw_bits[i], FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN))
  93688. return false;
  93689. for(j = k_last; j < k; j++) {
  93690. if(!FLAC__bitwriter_write_raw_int32(bw, residual[j], raw_bits[i]))
  93691. return false;
  93692. }
  93693. }
  93694. k_last = k;
  93695. }
  93696. return true;
  93697. }
  93698. }
  93699. #endif
  93700. /*** End of inlined file: stream_encoder_framing.c ***/
  93701. /*** Start of inlined file: window_flac.c ***/
  93702. /*** Start of inlined file: juce_FlacHeader.h ***/
  93703. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  93704. // tasks..
  93705. #define VERSION "1.2.1"
  93706. #define FLAC__NO_DLL 1
  93707. #if JUCE_MSVC
  93708. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  93709. #endif
  93710. #if JUCE_MAC
  93711. #define FLAC__SYS_DARWIN 1
  93712. #endif
  93713. /*** End of inlined file: juce_FlacHeader.h ***/
  93714. #if JUCE_USE_FLAC
  93715. #if HAVE_CONFIG_H
  93716. # include <config.h>
  93717. #endif
  93718. #include <math.h>
  93719. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  93720. #ifndef M_PI
  93721. #define M_PI 3.14159265358979323846
  93722. #endif
  93723. void FLAC__window_bartlett(FLAC__real *window, const FLAC__int32 L)
  93724. {
  93725. const FLAC__int32 N = L - 1;
  93726. FLAC__int32 n;
  93727. if (L & 1) {
  93728. for (n = 0; n <= N/2; n++)
  93729. window[n] = 2.0f * n / (float)N;
  93730. for (; n <= N; n++)
  93731. window[n] = 2.0f - 2.0f * n / (float)N;
  93732. }
  93733. else {
  93734. for (n = 0; n <= L/2-1; n++)
  93735. window[n] = 2.0f * n / (float)N;
  93736. for (; n <= N; n++)
  93737. window[n] = 2.0f - 2.0f * (N-n) / (float)N;
  93738. }
  93739. }
  93740. void FLAC__window_bartlett_hann(FLAC__real *window, const FLAC__int32 L)
  93741. {
  93742. const FLAC__int32 N = L - 1;
  93743. FLAC__int32 n;
  93744. for (n = 0; n < L; n++)
  93745. 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)));
  93746. }
  93747. void FLAC__window_blackman(FLAC__real *window, const FLAC__int32 L)
  93748. {
  93749. const FLAC__int32 N = L - 1;
  93750. FLAC__int32 n;
  93751. for (n = 0; n < L; n++)
  93752. window[n] = (FLAC__real)(0.42f - 0.5f * cos(2.0f * M_PI * n / N) + 0.08f * cos(4.0f * M_PI * n / N));
  93753. }
  93754. void FLAC__window_blackman_harris_4term_92db_sidelobe(FLAC__real *window, const FLAC__int32 L)
  93755. {
  93756. const FLAC__int32 N = L - 1;
  93757. FLAC__int32 n;
  93758. for (n = 0; n <= N; n++)
  93759. 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));
  93760. }
  93761. void FLAC__window_connes(FLAC__real *window, const FLAC__int32 L)
  93762. {
  93763. const FLAC__int32 N = L - 1;
  93764. const double N2 = (double)N / 2.;
  93765. FLAC__int32 n;
  93766. for (n = 0; n <= N; n++) {
  93767. double k = ((double)n - N2) / N2;
  93768. k = 1.0f - k * k;
  93769. window[n] = (FLAC__real)(k * k);
  93770. }
  93771. }
  93772. void FLAC__window_flattop(FLAC__real *window, const FLAC__int32 L)
  93773. {
  93774. const FLAC__int32 N = L - 1;
  93775. FLAC__int32 n;
  93776. for (n = 0; n < L; n++)
  93777. 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));
  93778. }
  93779. void FLAC__window_gauss(FLAC__real *window, const FLAC__int32 L, const FLAC__real stddev)
  93780. {
  93781. const FLAC__int32 N = L - 1;
  93782. const double N2 = (double)N / 2.;
  93783. FLAC__int32 n;
  93784. for (n = 0; n <= N; n++) {
  93785. const double k = ((double)n - N2) / (stddev * N2);
  93786. window[n] = (FLAC__real)exp(-0.5f * k * k);
  93787. }
  93788. }
  93789. void FLAC__window_hamming(FLAC__real *window, const FLAC__int32 L)
  93790. {
  93791. const FLAC__int32 N = L - 1;
  93792. FLAC__int32 n;
  93793. for (n = 0; n < L; n++)
  93794. window[n] = (FLAC__real)(0.54f - 0.46f * cos(2.0f * M_PI * n / N));
  93795. }
  93796. void FLAC__window_hann(FLAC__real *window, const FLAC__int32 L)
  93797. {
  93798. const FLAC__int32 N = L - 1;
  93799. FLAC__int32 n;
  93800. for (n = 0; n < L; n++)
  93801. window[n] = (FLAC__real)(0.5f - 0.5f * cos(2.0f * M_PI * n / N));
  93802. }
  93803. void FLAC__window_kaiser_bessel(FLAC__real *window, const FLAC__int32 L)
  93804. {
  93805. const FLAC__int32 N = L - 1;
  93806. FLAC__int32 n;
  93807. for (n = 0; n < L; n++)
  93808. 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));
  93809. }
  93810. void FLAC__window_nuttall(FLAC__real *window, const FLAC__int32 L)
  93811. {
  93812. const FLAC__int32 N = L - 1;
  93813. FLAC__int32 n;
  93814. for (n = 0; n < L; n++)
  93815. 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));
  93816. }
  93817. void FLAC__window_rectangle(FLAC__real *window, const FLAC__int32 L)
  93818. {
  93819. FLAC__int32 n;
  93820. for (n = 0; n < L; n++)
  93821. window[n] = 1.0f;
  93822. }
  93823. void FLAC__window_triangle(FLAC__real *window, const FLAC__int32 L)
  93824. {
  93825. FLAC__int32 n;
  93826. if (L & 1) {
  93827. for (n = 1; n <= L+1/2; n++)
  93828. window[n-1] = 2.0f * n / ((float)L + 1.0f);
  93829. for (; n <= L; n++)
  93830. window[n-1] = - (float)(2 * (L - n + 1)) / ((float)L + 1.0f);
  93831. }
  93832. else {
  93833. for (n = 1; n <= L/2; n++)
  93834. window[n-1] = 2.0f * n / (float)L;
  93835. for (; n <= L; n++)
  93836. window[n-1] = ((float)(2 * (L - n)) + 1.0f) / (float)L;
  93837. }
  93838. }
  93839. void FLAC__window_tukey(FLAC__real *window, const FLAC__int32 L, const FLAC__real p)
  93840. {
  93841. if (p <= 0.0)
  93842. FLAC__window_rectangle(window, L);
  93843. else if (p >= 1.0)
  93844. FLAC__window_hann(window, L);
  93845. else {
  93846. const FLAC__int32 Np = (FLAC__int32)(p / 2.0f * L) - 1;
  93847. FLAC__int32 n;
  93848. FLAC__window_rectangle(window, L);
  93849. if (Np > 0) {
  93850. for (n = 0; n <= Np; n++) {
  93851. window[n] = (FLAC__real)(0.5f - 0.5f * cos(M_PI * n / Np));
  93852. window[L-Np-1+n] = (FLAC__real)(0.5f - 0.5f * cos(M_PI * (n+Np) / Np));
  93853. }
  93854. }
  93855. }
  93856. }
  93857. void FLAC__window_welch(FLAC__real *window, const FLAC__int32 L)
  93858. {
  93859. const FLAC__int32 N = L - 1;
  93860. const double N2 = (double)N / 2.;
  93861. FLAC__int32 n;
  93862. for (n = 0; n <= N; n++) {
  93863. const double k = ((double)n - N2) / N2;
  93864. window[n] = (FLAC__real)(1.0f - k * k);
  93865. }
  93866. }
  93867. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  93868. #endif
  93869. /*** End of inlined file: window_flac.c ***/
  93870. #else
  93871. #include <FLAC/all.h>
  93872. #endif
  93873. }
  93874. #ifdef _MSC_VER
  93875. #pragma warning (pop)
  93876. #endif
  93877. BEGIN_JUCE_NAMESPACE
  93878. using namespace FlacNamespace;
  93879. static const char* const flacFormatName = "FLAC file";
  93880. static const tchar* const flacExtensions[] = { T(".flac"), 0 };
  93881. class FlacReader : public AudioFormatReader
  93882. {
  93883. FLAC__StreamDecoder* decoder;
  93884. AudioSampleBuffer reservoir;
  93885. int reservoirStart, samplesInReservoir;
  93886. bool ok, scanningForLength;
  93887. public:
  93888. FlacReader (InputStream* const in)
  93889. : AudioFormatReader (in, TRANS (flacFormatName)),
  93890. reservoir (2, 0),
  93891. reservoirStart (0),
  93892. samplesInReservoir (0),
  93893. scanningForLength (false)
  93894. {
  93895. using namespace FlacNamespace;
  93896. lengthInSamples = 0;
  93897. decoder = FLAC__stream_decoder_new();
  93898. ok = FLAC__stream_decoder_init_stream (decoder,
  93899. readCallback_, seekCallback_, tellCallback_, lengthCallback_,
  93900. eofCallback_, writeCallback_, metadataCallback_, errorCallback_,
  93901. (void*) this) == FLAC__STREAM_DECODER_INIT_STATUS_OK;
  93902. if (ok)
  93903. {
  93904. FLAC__stream_decoder_process_until_end_of_metadata (decoder);
  93905. if (lengthInSamples == 0 && sampleRate > 0)
  93906. {
  93907. // the length hasn't been stored in the metadata, so we'll need to
  93908. // work it out the length the hard way, by scanning the whole file..
  93909. scanningForLength = true;
  93910. FLAC__stream_decoder_process_until_end_of_stream (decoder);
  93911. scanningForLength = false;
  93912. const int64 tempLength = lengthInSamples;
  93913. FLAC__stream_decoder_reset (decoder);
  93914. FLAC__stream_decoder_process_until_end_of_metadata (decoder);
  93915. lengthInSamples = tempLength;
  93916. }
  93917. }
  93918. }
  93919. ~FlacReader()
  93920. {
  93921. FLAC__stream_decoder_delete (decoder);
  93922. }
  93923. void useMetadata (const FLAC__StreamMetadata_StreamInfo& info)
  93924. {
  93925. sampleRate = info.sample_rate;
  93926. bitsPerSample = info.bits_per_sample;
  93927. lengthInSamples = (unsigned int) info.total_samples;
  93928. numChannels = info.channels;
  93929. reservoir.setSize (numChannels, 2 * info.max_blocksize, false, false, true);
  93930. }
  93931. // returns the number of samples read
  93932. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  93933. int64 startSampleInFile, int numSamples)
  93934. {
  93935. using namespace FlacNamespace;
  93936. if (! ok)
  93937. return false;
  93938. while (numSamples > 0)
  93939. {
  93940. if (startSampleInFile >= reservoirStart
  93941. && startSampleInFile < reservoirStart + samplesInReservoir)
  93942. {
  93943. const int num = (int) jmin ((int64) numSamples,
  93944. reservoirStart + samplesInReservoir - startSampleInFile);
  93945. jassert (num > 0);
  93946. for (int i = jmin (numDestChannels, reservoir.getNumChannels()); --i >= 0;)
  93947. if (destSamples[i] != 0)
  93948. memcpy (destSamples[i] + startOffsetInDestBuffer,
  93949. reservoir.getSampleData (i, (int) (startSampleInFile - reservoirStart)),
  93950. sizeof (int) * num);
  93951. startOffsetInDestBuffer += num;
  93952. startSampleInFile += num;
  93953. numSamples -= num;
  93954. }
  93955. else
  93956. {
  93957. if (startSampleInFile >= (int) lengthInSamples)
  93958. {
  93959. samplesInReservoir = 0;
  93960. }
  93961. else if (startSampleInFile < reservoirStart
  93962. || startSampleInFile > reservoirStart + jmax (samplesInReservoir, 511))
  93963. {
  93964. // had some problems with flac crashing if the read pos is aligned more
  93965. // accurately than this. Probably fixed in newer versions of the library, though.
  93966. reservoirStart = (int) (startSampleInFile & ~511);
  93967. samplesInReservoir = 0;
  93968. FLAC__stream_decoder_seek_absolute (decoder, (FLAC__uint64) reservoirStart);
  93969. }
  93970. else
  93971. {
  93972. reservoirStart += samplesInReservoir;
  93973. samplesInReservoir = 0;
  93974. FLAC__stream_decoder_process_single (decoder);
  93975. }
  93976. if (samplesInReservoir == 0)
  93977. break;
  93978. }
  93979. }
  93980. if (numSamples > 0)
  93981. {
  93982. for (int i = numDestChannels; --i >= 0;)
  93983. if (destSamples[i] != 0)
  93984. zeromem (destSamples[i] + startOffsetInDestBuffer,
  93985. sizeof (int) * numSamples);
  93986. }
  93987. return true;
  93988. }
  93989. void useSamples (const FLAC__int32* const buffer[], int numSamples)
  93990. {
  93991. if (scanningForLength)
  93992. {
  93993. lengthInSamples += numSamples;
  93994. }
  93995. else
  93996. {
  93997. if (numSamples > reservoir.getNumSamples())
  93998. reservoir.setSize (numChannels, numSamples, false, false, true);
  93999. const int bitsToShift = 32 - bitsPerSample;
  94000. for (int i = 0; i < (int) numChannels; ++i)
  94001. {
  94002. const FLAC__int32* src = buffer[i];
  94003. int n = i;
  94004. while (src == 0 && n > 0)
  94005. src = buffer [--n];
  94006. if (src != 0)
  94007. {
  94008. int* dest = (int*) reservoir.getSampleData(i);
  94009. for (int j = 0; j < numSamples; ++j)
  94010. dest[j] = src[j] << bitsToShift;
  94011. }
  94012. }
  94013. samplesInReservoir = numSamples;
  94014. }
  94015. }
  94016. static FLAC__StreamDecoderReadStatus readCallback_ (const FLAC__StreamDecoder*, FLAC__byte buffer[], size_t* bytes, void* client_data)
  94017. {
  94018. *bytes = (unsigned int) ((const FlacReader*) client_data)->input->read (buffer, (int) *bytes);
  94019. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  94020. }
  94021. static FLAC__StreamDecoderSeekStatus seekCallback_ (const FLAC__StreamDecoder*, FLAC__uint64 absolute_byte_offset, void* client_data)
  94022. {
  94023. ((const FlacReader*) client_data)->input->setPosition ((int) absolute_byte_offset);
  94024. return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
  94025. }
  94026. static FLAC__StreamDecoderTellStatus tellCallback_ (const FLAC__StreamDecoder*, FLAC__uint64* absolute_byte_offset, void* client_data)
  94027. {
  94028. *absolute_byte_offset = ((const FlacReader*) client_data)->input->getPosition();
  94029. return FLAC__STREAM_DECODER_TELL_STATUS_OK;
  94030. }
  94031. static FLAC__StreamDecoderLengthStatus lengthCallback_ (const FLAC__StreamDecoder*, FLAC__uint64* stream_length, void* client_data)
  94032. {
  94033. *stream_length = ((const FlacReader*) client_data)->input->getTotalLength();
  94034. return FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
  94035. }
  94036. static FLAC__bool eofCallback_ (const FLAC__StreamDecoder*, void* client_data)
  94037. {
  94038. return ((const FlacReader*) client_data)->input->isExhausted();
  94039. }
  94040. static FLAC__StreamDecoderWriteStatus writeCallback_ (const FLAC__StreamDecoder*,
  94041. const FLAC__Frame* frame,
  94042. const FLAC__int32* const buffer[],
  94043. void* client_data)
  94044. {
  94045. ((FlacReader*) client_data)->useSamples (buffer, frame->header.blocksize);
  94046. return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  94047. }
  94048. static void metadataCallback_ (const FLAC__StreamDecoder*,
  94049. const FLAC__StreamMetadata* metadata,
  94050. void* client_data)
  94051. {
  94052. ((FlacReader*) client_data)->useMetadata (metadata->data.stream_info);
  94053. }
  94054. static void errorCallback_ (const FLAC__StreamDecoder*, FLAC__StreamDecoderErrorStatus, void*)
  94055. {
  94056. }
  94057. juce_UseDebuggingNewOperator
  94058. };
  94059. class FlacWriter : public AudioFormatWriter
  94060. {
  94061. FLAC__StreamEncoder* encoder;
  94062. MemoryBlock temp;
  94063. public:
  94064. bool ok;
  94065. FlacWriter (OutputStream* const out,
  94066. const double sampleRate_,
  94067. const int numChannels_,
  94068. const int bitsPerSample_)
  94069. : AudioFormatWriter (out, TRANS (flacFormatName),
  94070. sampleRate_,
  94071. numChannels_,
  94072. bitsPerSample_)
  94073. {
  94074. using namespace FlacNamespace;
  94075. encoder = FLAC__stream_encoder_new();
  94076. FLAC__stream_encoder_set_do_mid_side_stereo (encoder, numChannels == 2);
  94077. FLAC__stream_encoder_set_loose_mid_side_stereo (encoder, numChannels == 2);
  94078. FLAC__stream_encoder_set_channels (encoder, numChannels);
  94079. FLAC__stream_encoder_set_bits_per_sample (encoder, jmin ((unsigned int) 24, bitsPerSample));
  94080. FLAC__stream_encoder_set_sample_rate (encoder, (unsigned int) sampleRate);
  94081. FLAC__stream_encoder_set_blocksize (encoder, 2048);
  94082. FLAC__stream_encoder_set_do_escape_coding (encoder, true);
  94083. ok = FLAC__stream_encoder_init_stream (encoder,
  94084. encodeWriteCallback, encodeSeekCallback,
  94085. encodeTellCallback, encodeMetadataCallback,
  94086. (void*) this) == FLAC__STREAM_ENCODER_INIT_STATUS_OK;
  94087. }
  94088. ~FlacWriter()
  94089. {
  94090. if (ok)
  94091. {
  94092. FLAC__stream_encoder_finish (encoder);
  94093. output->flush();
  94094. }
  94095. else
  94096. {
  94097. output = 0; // to stop the base class deleting this, as it needs to be returned
  94098. // to the caller of createWriter()
  94099. }
  94100. FLAC__stream_encoder_delete (encoder);
  94101. }
  94102. bool write (const int** samplesToWrite, int numSamples)
  94103. {
  94104. if (! ok)
  94105. return false;
  94106. int* buf[3];
  94107. const int bitsToShift = 32 - bitsPerSample;
  94108. if (bitsToShift > 0)
  94109. {
  94110. const int numChannelsToWrite = (samplesToWrite[1] == 0) ? 1 : 2;
  94111. temp.setSize (sizeof (int) * numSamples * numChannelsToWrite);
  94112. buf[0] = (int*) temp.getData();
  94113. buf[1] = buf[0] + numSamples;
  94114. buf[2] = 0;
  94115. for (int i = numChannelsToWrite; --i >= 0;)
  94116. {
  94117. if (samplesToWrite[i] != 0)
  94118. {
  94119. for (int j = 0; j < numSamples; ++j)
  94120. buf [i][j] = (samplesToWrite [i][j] >> bitsToShift);
  94121. }
  94122. }
  94123. samplesToWrite = (const int**) buf;
  94124. }
  94125. return FLAC__stream_encoder_process (encoder,
  94126. (const FLAC__int32**) samplesToWrite,
  94127. numSamples) != 0;
  94128. }
  94129. bool writeData (const void* const data, const int size) const
  94130. {
  94131. return output->write (data, size);
  94132. }
  94133. static void packUint32 (FLAC__uint32 val, FLAC__byte* b, const int bytes)
  94134. {
  94135. b += bytes;
  94136. for (int i = 0; i < bytes; ++i)
  94137. {
  94138. *(--b) = (FLAC__byte) (val & 0xff);
  94139. val >>= 8;
  94140. }
  94141. }
  94142. void writeMetaData (const FLAC__StreamMetadata* metadata)
  94143. {
  94144. using namespace FlacNamespace;
  94145. const FLAC__StreamMetadata_StreamInfo& info = metadata->data.stream_info;
  94146. unsigned char buffer [FLAC__STREAM_METADATA_STREAMINFO_LENGTH];
  94147. const unsigned int channelsMinus1 = info.channels - 1;
  94148. const unsigned int bitsMinus1 = info.bits_per_sample - 1;
  94149. packUint32 (info.min_blocksize, buffer, 2);
  94150. packUint32 (info.max_blocksize, buffer + 2, 2);
  94151. packUint32 (info.min_framesize, buffer + 4, 3);
  94152. packUint32 (info.max_framesize, buffer + 7, 3);
  94153. buffer[10] = (uint8) ((info.sample_rate >> 12) & 0xff);
  94154. buffer[11] = (uint8) ((info.sample_rate >> 4) & 0xff);
  94155. buffer[12] = (uint8) (((info.sample_rate & 0x0f) << 4) | (channelsMinus1 << 1) | (bitsMinus1 >> 4));
  94156. buffer[13] = (FLAC__byte) (((bitsMinus1 & 0x0f) << 4) | (unsigned int) ((info.total_samples >> 32) & 0x0f));
  94157. packUint32 ((FLAC__uint32) info.total_samples, buffer + 14, 4);
  94158. memcpy (buffer + 18, info.md5sum, 16);
  94159. const bool seekOk = output->setPosition (4);
  94160. (void) seekOk;
  94161. // if this fails, you've given it an output stream that can't seek! It needs
  94162. // to be able to seek back to write the header
  94163. jassert (seekOk);
  94164. output->writeIntBigEndian (FLAC__STREAM_METADATA_STREAMINFO_LENGTH);
  94165. output->write (buffer, FLAC__STREAM_METADATA_STREAMINFO_LENGTH);
  94166. }
  94167. static FLAC__StreamEncoderWriteStatus encodeWriteCallback (const FLAC__StreamEncoder*,
  94168. const FLAC__byte buffer[],
  94169. size_t bytes,
  94170. unsigned int /*samples*/,
  94171. unsigned int /*current_frame*/,
  94172. void* client_data)
  94173. {
  94174. using namespace FlacNamespace;
  94175. return ((FlacWriter*) client_data)->writeData (buffer, (int) bytes)
  94176. ? FLAC__STREAM_ENCODER_WRITE_STATUS_OK
  94177. : FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
  94178. }
  94179. static FLAC__StreamEncoderSeekStatus encodeSeekCallback (const FLAC__StreamEncoder*, FLAC__uint64, void*)
  94180. {
  94181. return FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED;
  94182. }
  94183. static FLAC__StreamEncoderTellStatus encodeTellCallback (const FLAC__StreamEncoder*, FLAC__uint64* absolute_byte_offset, void* client_data)
  94184. {
  94185. if (client_data == 0)
  94186. return FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED;
  94187. *absolute_byte_offset = (FLAC__uint64) ((FlacWriter*) client_data)->output->getPosition();
  94188. return FLAC__STREAM_ENCODER_TELL_STATUS_OK;
  94189. }
  94190. static void encodeMetadataCallback (const FLAC__StreamEncoder*,
  94191. const FLAC__StreamMetadata* metadata,
  94192. void* client_data)
  94193. {
  94194. ((FlacWriter*) client_data)->writeMetaData (metadata);
  94195. }
  94196. juce_UseDebuggingNewOperator
  94197. };
  94198. FlacAudioFormat::FlacAudioFormat()
  94199. : AudioFormat (TRANS (flacFormatName), (const tchar**) flacExtensions)
  94200. {
  94201. }
  94202. FlacAudioFormat::~FlacAudioFormat()
  94203. {
  94204. }
  94205. const Array <int> FlacAudioFormat::getPossibleSampleRates()
  94206. {
  94207. const int rates[] = { 22050, 32000, 44100, 48000, 88200, 96000, 0 };
  94208. return Array <int> (rates);
  94209. }
  94210. const Array <int> FlacAudioFormat::getPossibleBitDepths()
  94211. {
  94212. const int depths[] = { 16, 24, 0 };
  94213. return Array <int> (depths);
  94214. }
  94215. bool FlacAudioFormat::canDoStereo()
  94216. {
  94217. return true;
  94218. }
  94219. bool FlacAudioFormat::canDoMono()
  94220. {
  94221. return true;
  94222. }
  94223. bool FlacAudioFormat::isCompressed()
  94224. {
  94225. return true;
  94226. }
  94227. AudioFormatReader* FlacAudioFormat::createReaderFor (InputStream* in,
  94228. const bool deleteStreamIfOpeningFails)
  94229. {
  94230. ScopedPointer <FlacReader> r (new FlacReader (in));
  94231. if (r->sampleRate != 0)
  94232. return r.release();
  94233. if (! deleteStreamIfOpeningFails)
  94234. r->input = 0;
  94235. return 0;
  94236. }
  94237. AudioFormatWriter* FlacAudioFormat::createWriterFor (OutputStream* out,
  94238. double sampleRate,
  94239. unsigned int numberOfChannels,
  94240. int bitsPerSample,
  94241. const StringPairArray& /*metadataValues*/,
  94242. int /*qualityOptionIndex*/)
  94243. {
  94244. if (getPossibleBitDepths().contains (bitsPerSample))
  94245. {
  94246. ScopedPointer <FlacWriter> w (new FlacWriter (out,
  94247. sampleRate,
  94248. numberOfChannels,
  94249. bitsPerSample));
  94250. if (w->ok)
  94251. return w.release();
  94252. }
  94253. return 0;
  94254. }
  94255. END_JUCE_NAMESPACE
  94256. #endif
  94257. /*** End of inlined file: juce_FlacAudioFormat.cpp ***/
  94258. /*** Start of inlined file: juce_OggVorbisAudioFormat.cpp ***/
  94259. #if JUCE_USE_OGGVORBIS
  94260. #if JUCE_MAC
  94261. #define __MACOSX__ 1
  94262. #endif
  94263. namespace OggVorbisNamespace
  94264. {
  94265. #if JUCE_INCLUDE_OGGVORBIS_CODE
  94266. /*** Start of inlined file: vorbisenc.h ***/
  94267. #ifndef _OV_ENC_H_
  94268. #define _OV_ENC_H_
  94269. #ifdef __cplusplus
  94270. extern "C"
  94271. {
  94272. #endif /* __cplusplus */
  94273. /*** Start of inlined file: codec.h ***/
  94274. #ifndef _vorbis_codec_h_
  94275. #define _vorbis_codec_h_
  94276. #ifdef __cplusplus
  94277. extern "C"
  94278. {
  94279. #endif /* __cplusplus */
  94280. /*** Start of inlined file: ogg.h ***/
  94281. #ifndef _OGG_H
  94282. #define _OGG_H
  94283. #ifdef __cplusplus
  94284. extern "C" {
  94285. #endif
  94286. /*** Start of inlined file: os_types.h ***/
  94287. #ifndef _OS_TYPES_H
  94288. #define _OS_TYPES_H
  94289. #define _ogg_malloc malloc
  94290. #define _ogg_calloc calloc
  94291. #define _ogg_realloc realloc
  94292. #define _ogg_free free
  94293. #if defined(_WIN32)
  94294. # if defined(__CYGWIN__)
  94295. # include <_G_config.h>
  94296. typedef _G_int64_t ogg_int64_t;
  94297. typedef _G_int32_t ogg_int32_t;
  94298. typedef _G_uint32_t ogg_uint32_t;
  94299. typedef _G_int16_t ogg_int16_t;
  94300. typedef _G_uint16_t ogg_uint16_t;
  94301. # elif defined(__MINGW32__)
  94302. typedef short ogg_int16_t;
  94303. typedef unsigned short ogg_uint16_t;
  94304. typedef int ogg_int32_t;
  94305. typedef unsigned int ogg_uint32_t;
  94306. typedef long long ogg_int64_t;
  94307. typedef unsigned long long ogg_uint64_t;
  94308. # elif defined(__MWERKS__)
  94309. typedef long long ogg_int64_t;
  94310. typedef int ogg_int32_t;
  94311. typedef unsigned int ogg_uint32_t;
  94312. typedef short ogg_int16_t;
  94313. typedef unsigned short ogg_uint16_t;
  94314. # else
  94315. typedef __int64 ogg_int64_t;
  94316. typedef __int32 ogg_int32_t;
  94317. typedef unsigned __int32 ogg_uint32_t;
  94318. typedef __int16 ogg_int16_t;
  94319. typedef unsigned __int16 ogg_uint16_t;
  94320. # endif
  94321. #elif defined(__MACOS__)
  94322. # include <sys/types.h>
  94323. typedef SInt16 ogg_int16_t;
  94324. typedef UInt16 ogg_uint16_t;
  94325. typedef SInt32 ogg_int32_t;
  94326. typedef UInt32 ogg_uint32_t;
  94327. typedef SInt64 ogg_int64_t;
  94328. #elif defined(__MACOSX__) /* MacOS X Framework build */
  94329. # include <sys/types.h>
  94330. typedef int16_t ogg_int16_t;
  94331. typedef u_int16_t ogg_uint16_t;
  94332. typedef int32_t ogg_int32_t;
  94333. typedef u_int32_t ogg_uint32_t;
  94334. typedef int64_t ogg_int64_t;
  94335. #elif defined(__BEOS__)
  94336. # include <inttypes.h>
  94337. typedef int16_t ogg_int16_t;
  94338. typedef u_int16_t ogg_uint16_t;
  94339. typedef int32_t ogg_int32_t;
  94340. typedef u_int32_t ogg_uint32_t;
  94341. typedef int64_t ogg_int64_t;
  94342. #elif defined (__EMX__)
  94343. typedef short ogg_int16_t;
  94344. typedef unsigned short ogg_uint16_t;
  94345. typedef int ogg_int32_t;
  94346. typedef unsigned int ogg_uint32_t;
  94347. typedef long long ogg_int64_t;
  94348. #elif defined (DJGPP)
  94349. typedef short ogg_int16_t;
  94350. typedef int ogg_int32_t;
  94351. typedef unsigned int ogg_uint32_t;
  94352. typedef long long ogg_int64_t;
  94353. #elif defined(R5900)
  94354. typedef long ogg_int64_t;
  94355. typedef int ogg_int32_t;
  94356. typedef unsigned ogg_uint32_t;
  94357. typedef short ogg_int16_t;
  94358. #elif defined(__SYMBIAN32__)
  94359. typedef signed short ogg_int16_t;
  94360. typedef unsigned short ogg_uint16_t;
  94361. typedef signed int ogg_int32_t;
  94362. typedef unsigned int ogg_uint32_t;
  94363. typedef long long int ogg_int64_t;
  94364. #else
  94365. # include <sys/types.h>
  94366. /*** Start of inlined file: config_types.h ***/
  94367. #ifndef __CONFIG_TYPES_H__
  94368. #define __CONFIG_TYPES_H__
  94369. typedef int16_t ogg_int16_t;
  94370. typedef unsigned short ogg_uint16_t;
  94371. typedef int32_t ogg_int32_t;
  94372. typedef unsigned int ogg_uint32_t;
  94373. typedef int64_t ogg_int64_t;
  94374. #endif
  94375. /*** End of inlined file: config_types.h ***/
  94376. #endif
  94377. #endif /* _OS_TYPES_H */
  94378. /*** End of inlined file: os_types.h ***/
  94379. typedef struct {
  94380. long endbyte;
  94381. int endbit;
  94382. unsigned char *buffer;
  94383. unsigned char *ptr;
  94384. long storage;
  94385. } oggpack_buffer;
  94386. typedef struct {
  94387. unsigned char *header;
  94388. long header_len;
  94389. unsigned char *body;
  94390. long body_len;
  94391. } ogg_page;
  94392. ogg_uint32_t ogg_bitreverse(ogg_uint32_t x){
  94393. x= ((x>>16)&0x0000ffffUL) | ((x<<16)&0xffff0000UL);
  94394. x= ((x>> 8)&0x00ff00ffUL) | ((x<< 8)&0xff00ff00UL);
  94395. x= ((x>> 4)&0x0f0f0f0fUL) | ((x<< 4)&0xf0f0f0f0UL);
  94396. x= ((x>> 2)&0x33333333UL) | ((x<< 2)&0xccccccccUL);
  94397. return((x>> 1)&0x55555555UL) | ((x<< 1)&0xaaaaaaaaUL);
  94398. }
  94399. typedef struct {
  94400. unsigned char *body_data; /* bytes from packet bodies */
  94401. long body_storage; /* storage elements allocated */
  94402. long body_fill; /* elements stored; fill mark */
  94403. long body_returned; /* elements of fill returned */
  94404. int *lacing_vals; /* The values that will go to the segment table */
  94405. ogg_int64_t *granule_vals; /* granulepos values for headers. Not compact
  94406. this way, but it is simple coupled to the
  94407. lacing fifo */
  94408. long lacing_storage;
  94409. long lacing_fill;
  94410. long lacing_packet;
  94411. long lacing_returned;
  94412. unsigned char header[282]; /* working space for header encode */
  94413. int header_fill;
  94414. int e_o_s; /* set when we have buffered the last packet in the
  94415. logical bitstream */
  94416. int b_o_s; /* set after we've written the initial page
  94417. of a logical bitstream */
  94418. long serialno;
  94419. long pageno;
  94420. ogg_int64_t packetno; /* sequence number for decode; the framing
  94421. knows where there's a hole in the data,
  94422. but we need coupling so that the codec
  94423. (which is in a seperate abstraction
  94424. layer) also knows about the gap */
  94425. ogg_int64_t granulepos;
  94426. } ogg_stream_state;
  94427. typedef struct {
  94428. unsigned char *packet;
  94429. long bytes;
  94430. long b_o_s;
  94431. long e_o_s;
  94432. ogg_int64_t granulepos;
  94433. ogg_int64_t packetno; /* sequence number for decode; the framing
  94434. knows where there's a hole in the data,
  94435. but we need coupling so that the codec
  94436. (which is in a seperate abstraction
  94437. layer) also knows about the gap */
  94438. } ogg_packet;
  94439. typedef struct {
  94440. unsigned char *data;
  94441. int storage;
  94442. int fill;
  94443. int returned;
  94444. int unsynced;
  94445. int headerbytes;
  94446. int bodybytes;
  94447. } ogg_sync_state;
  94448. extern void oggpack_writeinit(oggpack_buffer *b);
  94449. extern void oggpack_writetrunc(oggpack_buffer *b,long bits);
  94450. extern void oggpack_writealign(oggpack_buffer *b);
  94451. extern void oggpack_writecopy(oggpack_buffer *b,void *source,long bits);
  94452. extern void oggpack_reset(oggpack_buffer *b);
  94453. extern void oggpack_writeclear(oggpack_buffer *b);
  94454. extern void oggpack_readinit(oggpack_buffer *b,unsigned char *buf,int bytes);
  94455. extern void oggpack_write(oggpack_buffer *b,unsigned long value,int bits);
  94456. extern long oggpack_look(oggpack_buffer *b,int bits);
  94457. extern long oggpack_look1(oggpack_buffer *b);
  94458. extern void oggpack_adv(oggpack_buffer *b,int bits);
  94459. extern void oggpack_adv1(oggpack_buffer *b);
  94460. extern long oggpack_read(oggpack_buffer *b,int bits);
  94461. extern long oggpack_read1(oggpack_buffer *b);
  94462. extern long oggpack_bytes(oggpack_buffer *b);
  94463. extern long oggpack_bits(oggpack_buffer *b);
  94464. extern unsigned char *oggpack_get_buffer(oggpack_buffer *b);
  94465. extern void oggpackB_writeinit(oggpack_buffer *b);
  94466. extern void oggpackB_writetrunc(oggpack_buffer *b,long bits);
  94467. extern void oggpackB_writealign(oggpack_buffer *b);
  94468. extern void oggpackB_writecopy(oggpack_buffer *b,void *source,long bits);
  94469. extern void oggpackB_reset(oggpack_buffer *b);
  94470. extern void oggpackB_writeclear(oggpack_buffer *b);
  94471. extern void oggpackB_readinit(oggpack_buffer *b,unsigned char *buf,int bytes);
  94472. extern void oggpackB_write(oggpack_buffer *b,unsigned long value,int bits);
  94473. extern long oggpackB_look(oggpack_buffer *b,int bits);
  94474. extern long oggpackB_look1(oggpack_buffer *b);
  94475. extern void oggpackB_adv(oggpack_buffer *b,int bits);
  94476. extern void oggpackB_adv1(oggpack_buffer *b);
  94477. extern long oggpackB_read(oggpack_buffer *b,int bits);
  94478. extern long oggpackB_read1(oggpack_buffer *b);
  94479. extern long oggpackB_bytes(oggpack_buffer *b);
  94480. extern long oggpackB_bits(oggpack_buffer *b);
  94481. extern unsigned char *oggpackB_get_buffer(oggpack_buffer *b);
  94482. extern int ogg_stream_packetin(ogg_stream_state *os, ogg_packet *op);
  94483. extern int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og);
  94484. extern int ogg_stream_flush(ogg_stream_state *os, ogg_page *og);
  94485. extern int ogg_sync_init(ogg_sync_state *oy);
  94486. extern int ogg_sync_clear(ogg_sync_state *oy);
  94487. extern int ogg_sync_reset(ogg_sync_state *oy);
  94488. extern int ogg_sync_destroy(ogg_sync_state *oy);
  94489. extern char *ogg_sync_buffer(ogg_sync_state *oy, long size);
  94490. extern int ogg_sync_wrote(ogg_sync_state *oy, long bytes);
  94491. extern long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og);
  94492. extern int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og);
  94493. extern int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og);
  94494. extern int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op);
  94495. extern int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op);
  94496. extern int ogg_stream_init(ogg_stream_state *os,int serialno);
  94497. extern int ogg_stream_clear(ogg_stream_state *os);
  94498. extern int ogg_stream_reset(ogg_stream_state *os);
  94499. extern int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno);
  94500. extern int ogg_stream_destroy(ogg_stream_state *os);
  94501. extern int ogg_stream_eos(ogg_stream_state *os);
  94502. extern void ogg_page_checksum_set(ogg_page *og);
  94503. extern int ogg_page_version(ogg_page *og);
  94504. extern int ogg_page_continued(ogg_page *og);
  94505. extern int ogg_page_bos(ogg_page *og);
  94506. extern int ogg_page_eos(ogg_page *og);
  94507. extern ogg_int64_t ogg_page_granulepos(ogg_page *og);
  94508. extern int ogg_page_serialno(ogg_page *og);
  94509. extern long ogg_page_pageno(ogg_page *og);
  94510. extern int ogg_page_packets(ogg_page *og);
  94511. extern void ogg_packet_clear(ogg_packet *op);
  94512. #ifdef __cplusplus
  94513. }
  94514. #endif
  94515. #endif /* _OGG_H */
  94516. /*** End of inlined file: ogg.h ***/
  94517. typedef struct vorbis_info{
  94518. int version;
  94519. int channels;
  94520. long rate;
  94521. long bitrate_upper;
  94522. long bitrate_nominal;
  94523. long bitrate_lower;
  94524. long bitrate_window;
  94525. void *codec_setup;
  94526. } vorbis_info;
  94527. typedef struct vorbis_dsp_state{
  94528. int analysisp;
  94529. vorbis_info *vi;
  94530. float **pcm;
  94531. float **pcmret;
  94532. int pcm_storage;
  94533. int pcm_current;
  94534. int pcm_returned;
  94535. int preextrapolate;
  94536. int eofflag;
  94537. long lW;
  94538. long W;
  94539. long nW;
  94540. long centerW;
  94541. ogg_int64_t granulepos;
  94542. ogg_int64_t sequence;
  94543. ogg_int64_t glue_bits;
  94544. ogg_int64_t time_bits;
  94545. ogg_int64_t floor_bits;
  94546. ogg_int64_t res_bits;
  94547. void *backend_state;
  94548. } vorbis_dsp_state;
  94549. typedef struct vorbis_block{
  94550. float **pcm; /* this is a pointer into local storage */
  94551. oggpack_buffer opb;
  94552. long lW;
  94553. long W;
  94554. long nW;
  94555. int pcmend;
  94556. int mode;
  94557. int eofflag;
  94558. ogg_int64_t granulepos;
  94559. ogg_int64_t sequence;
  94560. vorbis_dsp_state *vd; /* For read-only access of configuration */
  94561. void *localstore;
  94562. long localtop;
  94563. long localalloc;
  94564. long totaluse;
  94565. struct alloc_chain *reap;
  94566. long glue_bits;
  94567. long time_bits;
  94568. long floor_bits;
  94569. long res_bits;
  94570. void *internal;
  94571. } vorbis_block;
  94572. struct alloc_chain{
  94573. void *ptr;
  94574. struct alloc_chain *next;
  94575. };
  94576. typedef struct vorbis_comment{
  94577. char **user_comments;
  94578. int *comment_lengths;
  94579. int comments;
  94580. char *vendor;
  94581. } vorbis_comment;
  94582. extern void vorbis_info_init(vorbis_info *vi);
  94583. extern void vorbis_info_clear(vorbis_info *vi);
  94584. extern int vorbis_info_blocksize(vorbis_info *vi,int zo);
  94585. extern void vorbis_comment_init(vorbis_comment *vc);
  94586. extern void vorbis_comment_add(vorbis_comment *vc, char *comment);
  94587. extern void vorbis_comment_add_tag(vorbis_comment *vc,
  94588. const char *tag, char *contents);
  94589. extern char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count);
  94590. extern int vorbis_comment_query_count(vorbis_comment *vc, char *tag);
  94591. extern void vorbis_comment_clear(vorbis_comment *vc);
  94592. extern int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb);
  94593. extern int vorbis_block_clear(vorbis_block *vb);
  94594. extern void vorbis_dsp_clear(vorbis_dsp_state *v);
  94595. extern double vorbis_granule_time(vorbis_dsp_state *v,
  94596. ogg_int64_t granulepos);
  94597. extern int vorbis_analysis_init(vorbis_dsp_state *v,vorbis_info *vi);
  94598. extern int vorbis_commentheader_out(vorbis_comment *vc, ogg_packet *op);
  94599. extern int vorbis_analysis_headerout(vorbis_dsp_state *v,
  94600. vorbis_comment *vc,
  94601. ogg_packet *op,
  94602. ogg_packet *op_comm,
  94603. ogg_packet *op_code);
  94604. extern float **vorbis_analysis_buffer(vorbis_dsp_state *v,int vals);
  94605. extern int vorbis_analysis_wrote(vorbis_dsp_state *v,int vals);
  94606. extern int vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb);
  94607. extern int vorbis_analysis(vorbis_block *vb,ogg_packet *op);
  94608. extern int vorbis_bitrate_addblock(vorbis_block *vb);
  94609. extern int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd,
  94610. ogg_packet *op);
  94611. extern int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,
  94612. ogg_packet *op);
  94613. extern int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi);
  94614. extern int vorbis_synthesis_restart(vorbis_dsp_state *v);
  94615. extern int vorbis_synthesis(vorbis_block *vb,ogg_packet *op);
  94616. extern int vorbis_synthesis_trackonly(vorbis_block *vb,ogg_packet *op);
  94617. extern int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb);
  94618. extern int vorbis_synthesis_pcmout(vorbis_dsp_state *v,float ***pcm);
  94619. extern int vorbis_synthesis_lapout(vorbis_dsp_state *v,float ***pcm);
  94620. extern int vorbis_synthesis_read(vorbis_dsp_state *v,int samples);
  94621. extern long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op);
  94622. extern int vorbis_synthesis_halfrate(vorbis_info *v,int flag);
  94623. extern int vorbis_synthesis_halfrate_p(vorbis_info *v);
  94624. #define OV_FALSE -1
  94625. #define OV_EOF -2
  94626. #define OV_HOLE -3
  94627. #define OV_EREAD -128
  94628. #define OV_EFAULT -129
  94629. #define OV_EIMPL -130
  94630. #define OV_EINVAL -131
  94631. #define OV_ENOTVORBIS -132
  94632. #define OV_EBADHEADER -133
  94633. #define OV_EVERSION -134
  94634. #define OV_ENOTAUDIO -135
  94635. #define OV_EBADPACKET -136
  94636. #define OV_EBADLINK -137
  94637. #define OV_ENOSEEK -138
  94638. #ifdef __cplusplus
  94639. }
  94640. #endif /* __cplusplus */
  94641. #endif
  94642. /*** End of inlined file: codec.h ***/
  94643. extern int vorbis_encode_init(vorbis_info *vi,
  94644. long channels,
  94645. long rate,
  94646. long max_bitrate,
  94647. long nominal_bitrate,
  94648. long min_bitrate);
  94649. extern int vorbis_encode_setup_managed(vorbis_info *vi,
  94650. long channels,
  94651. long rate,
  94652. long max_bitrate,
  94653. long nominal_bitrate,
  94654. long min_bitrate);
  94655. extern int vorbis_encode_setup_vbr(vorbis_info *vi,
  94656. long channels,
  94657. long rate,
  94658. float quality /* quality level from 0. (lo) to 1. (hi) */
  94659. );
  94660. extern int vorbis_encode_init_vbr(vorbis_info *vi,
  94661. long channels,
  94662. long rate,
  94663. float base_quality /* quality level from 0. (lo) to 1. (hi) */
  94664. );
  94665. extern int vorbis_encode_setup_init(vorbis_info *vi);
  94666. extern int vorbis_encode_ctl(vorbis_info *vi,int number,void *arg);
  94667. #define OV_ECTL_RATEMANAGE_GET 0x10
  94668. #define OV_ECTL_RATEMANAGE_SET 0x11
  94669. #define OV_ECTL_RATEMANAGE_AVG 0x12
  94670. #define OV_ECTL_RATEMANAGE_HARD 0x13
  94671. struct ovectl_ratemanage_arg {
  94672. int management_active;
  94673. long bitrate_hard_min;
  94674. long bitrate_hard_max;
  94675. double bitrate_hard_window;
  94676. long bitrate_av_lo;
  94677. long bitrate_av_hi;
  94678. double bitrate_av_window;
  94679. double bitrate_av_window_center;
  94680. };
  94681. #define OV_ECTL_RATEMANAGE2_GET 0x14
  94682. #define OV_ECTL_RATEMANAGE2_SET 0x15
  94683. struct ovectl_ratemanage2_arg {
  94684. int management_active;
  94685. long bitrate_limit_min_kbps;
  94686. long bitrate_limit_max_kbps;
  94687. long bitrate_limit_reservoir_bits;
  94688. double bitrate_limit_reservoir_bias;
  94689. long bitrate_average_kbps;
  94690. double bitrate_average_damping;
  94691. };
  94692. #define OV_ECTL_LOWPASS_GET 0x20
  94693. #define OV_ECTL_LOWPASS_SET 0x21
  94694. #define OV_ECTL_IBLOCK_GET 0x30
  94695. #define OV_ECTL_IBLOCK_SET 0x31
  94696. #ifdef __cplusplus
  94697. }
  94698. #endif /* __cplusplus */
  94699. #endif
  94700. /*** End of inlined file: vorbisenc.h ***/
  94701. /*** Start of inlined file: vorbisfile.h ***/
  94702. #ifndef _OV_FILE_H_
  94703. #define _OV_FILE_H_
  94704. #ifdef __cplusplus
  94705. extern "C"
  94706. {
  94707. #endif /* __cplusplus */
  94708. #include <stdio.h>
  94709. typedef struct {
  94710. size_t (*read_func) (void *ptr, size_t size, size_t nmemb, void *datasource);
  94711. int (*seek_func) (void *datasource, ogg_int64_t offset, int whence);
  94712. int (*close_func) (void *datasource);
  94713. long (*tell_func) (void *datasource);
  94714. } ov_callbacks;
  94715. #define NOTOPEN 0
  94716. #define PARTOPEN 1
  94717. #define OPENED 2
  94718. #define STREAMSET 3
  94719. #define INITSET 4
  94720. typedef struct OggVorbis_File {
  94721. void *datasource; /* Pointer to a FILE *, etc. */
  94722. int seekable;
  94723. ogg_int64_t offset;
  94724. ogg_int64_t end;
  94725. ogg_sync_state oy;
  94726. int links;
  94727. ogg_int64_t *offsets;
  94728. ogg_int64_t *dataoffsets;
  94729. long *serialnos;
  94730. ogg_int64_t *pcmlengths; /* overloaded to maintain binary
  94731. compatability; x2 size, stores both
  94732. beginning and end values */
  94733. vorbis_info *vi;
  94734. vorbis_comment *vc;
  94735. ogg_int64_t pcm_offset;
  94736. int ready_state;
  94737. long current_serialno;
  94738. int current_link;
  94739. double bittrack;
  94740. double samptrack;
  94741. ogg_stream_state os; /* take physical pages, weld into a logical
  94742. stream of packets */
  94743. vorbis_dsp_state vd; /* central working state for the packet->PCM decoder */
  94744. vorbis_block vb; /* local working space for packet->PCM decode */
  94745. ov_callbacks callbacks;
  94746. } OggVorbis_File;
  94747. extern int ov_clear(OggVorbis_File *vf);
  94748. extern int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
  94749. extern int ov_open_callbacks(void *datasource, OggVorbis_File *vf,
  94750. char *initial, long ibytes, ov_callbacks callbacks);
  94751. extern int ov_test(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
  94752. extern int ov_test_callbacks(void *datasource, OggVorbis_File *vf,
  94753. char *initial, long ibytes, ov_callbacks callbacks);
  94754. extern int ov_test_open(OggVorbis_File *vf);
  94755. extern long ov_bitrate(OggVorbis_File *vf,int i);
  94756. extern long ov_bitrate_instant(OggVorbis_File *vf);
  94757. extern long ov_streams(OggVorbis_File *vf);
  94758. extern long ov_seekable(OggVorbis_File *vf);
  94759. extern long ov_serialnumber(OggVorbis_File *vf,int i);
  94760. extern ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i);
  94761. extern ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i);
  94762. extern double ov_time_total(OggVorbis_File *vf,int i);
  94763. extern int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos);
  94764. extern int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos);
  94765. extern int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos);
  94766. extern int ov_time_seek(OggVorbis_File *vf,double pos);
  94767. extern int ov_time_seek_page(OggVorbis_File *vf,double pos);
  94768. extern int ov_raw_seek_lap(OggVorbis_File *vf,ogg_int64_t pos);
  94769. extern int ov_pcm_seek_lap(OggVorbis_File *vf,ogg_int64_t pos);
  94770. extern int ov_pcm_seek_page_lap(OggVorbis_File *vf,ogg_int64_t pos);
  94771. extern int ov_time_seek_lap(OggVorbis_File *vf,double pos);
  94772. extern int ov_time_seek_page_lap(OggVorbis_File *vf,double pos);
  94773. extern ogg_int64_t ov_raw_tell(OggVorbis_File *vf);
  94774. extern ogg_int64_t ov_pcm_tell(OggVorbis_File *vf);
  94775. extern double ov_time_tell(OggVorbis_File *vf);
  94776. extern vorbis_info *ov_info(OggVorbis_File *vf,int link);
  94777. extern vorbis_comment *ov_comment(OggVorbis_File *vf,int link);
  94778. extern long ov_read_float(OggVorbis_File *vf,float ***pcm_channels,int samples,
  94779. int *bitstream);
  94780. extern long ov_read(OggVorbis_File *vf,char *buffer,int length,
  94781. int bigendianp,int word,int sgned,int *bitstream);
  94782. extern int ov_crosslap(OggVorbis_File *vf1,OggVorbis_File *vf2);
  94783. extern int ov_halfrate(OggVorbis_File *vf,int flag);
  94784. extern int ov_halfrate_p(OggVorbis_File *vf);
  94785. #ifdef __cplusplus
  94786. }
  94787. #endif /* __cplusplus */
  94788. #endif
  94789. /*** End of inlined file: vorbisfile.h ***/
  94790. /*** Start of inlined file: bitwise.c ***/
  94791. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  94792. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  94793. // tasks..
  94794. #if JUCE_MSVC
  94795. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  94796. #endif
  94797. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  94798. #if JUCE_USE_OGGVORBIS
  94799. #include <string.h>
  94800. #include <stdlib.h>
  94801. #define BUFFER_INCREMENT 256
  94802. static const unsigned long mask[]=
  94803. {0x00000000,0x00000001,0x00000003,0x00000007,0x0000000f,
  94804. 0x0000001f,0x0000003f,0x0000007f,0x000000ff,0x000001ff,
  94805. 0x000003ff,0x000007ff,0x00000fff,0x00001fff,0x00003fff,
  94806. 0x00007fff,0x0000ffff,0x0001ffff,0x0003ffff,0x0007ffff,
  94807. 0x000fffff,0x001fffff,0x003fffff,0x007fffff,0x00ffffff,
  94808. 0x01ffffff,0x03ffffff,0x07ffffff,0x0fffffff,0x1fffffff,
  94809. 0x3fffffff,0x7fffffff,0xffffffff };
  94810. static const unsigned int mask8B[]=
  94811. {0x00,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff};
  94812. void oggpack_writeinit(oggpack_buffer *b){
  94813. memset(b,0,sizeof(*b));
  94814. b->ptr=b->buffer=(unsigned char*) _ogg_malloc(BUFFER_INCREMENT);
  94815. b->buffer[0]='\0';
  94816. b->storage=BUFFER_INCREMENT;
  94817. }
  94818. void oggpackB_writeinit(oggpack_buffer *b){
  94819. oggpack_writeinit(b);
  94820. }
  94821. void oggpack_writetrunc(oggpack_buffer *b,long bits){
  94822. long bytes=bits>>3;
  94823. bits-=bytes*8;
  94824. b->ptr=b->buffer+bytes;
  94825. b->endbit=bits;
  94826. b->endbyte=bytes;
  94827. *b->ptr&=mask[bits];
  94828. }
  94829. void oggpackB_writetrunc(oggpack_buffer *b,long bits){
  94830. long bytes=bits>>3;
  94831. bits-=bytes*8;
  94832. b->ptr=b->buffer+bytes;
  94833. b->endbit=bits;
  94834. b->endbyte=bytes;
  94835. *b->ptr&=mask8B[bits];
  94836. }
  94837. void oggpack_write(oggpack_buffer *b,unsigned long value,int bits){
  94838. if(b->endbyte+4>=b->storage){
  94839. b->buffer=(unsigned char*) _ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT);
  94840. b->storage+=BUFFER_INCREMENT;
  94841. b->ptr=b->buffer+b->endbyte;
  94842. }
  94843. value&=mask[bits];
  94844. bits+=b->endbit;
  94845. b->ptr[0]|=value<<b->endbit;
  94846. if(bits>=8){
  94847. b->ptr[1]=(unsigned char)(value>>(8-b->endbit));
  94848. if(bits>=16){
  94849. b->ptr[2]=(unsigned char)(value>>(16-b->endbit));
  94850. if(bits>=24){
  94851. b->ptr[3]=(unsigned char)(value>>(24-b->endbit));
  94852. if(bits>=32){
  94853. if(b->endbit)
  94854. b->ptr[4]=(unsigned char)(value>>(32-b->endbit));
  94855. else
  94856. b->ptr[4]=0;
  94857. }
  94858. }
  94859. }
  94860. }
  94861. b->endbyte+=bits/8;
  94862. b->ptr+=bits/8;
  94863. b->endbit=bits&7;
  94864. }
  94865. void oggpackB_write(oggpack_buffer *b,unsigned long value,int bits){
  94866. if(b->endbyte+4>=b->storage){
  94867. b->buffer=(unsigned char*) _ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT);
  94868. b->storage+=BUFFER_INCREMENT;
  94869. b->ptr=b->buffer+b->endbyte;
  94870. }
  94871. value=(value&mask[bits])<<(32-bits);
  94872. bits+=b->endbit;
  94873. b->ptr[0]|=value>>(24+b->endbit);
  94874. if(bits>=8){
  94875. b->ptr[1]=(unsigned char)(value>>(16+b->endbit));
  94876. if(bits>=16){
  94877. b->ptr[2]=(unsigned char)(value>>(8+b->endbit));
  94878. if(bits>=24){
  94879. b->ptr[3]=(unsigned char)(value>>(b->endbit));
  94880. if(bits>=32){
  94881. if(b->endbit)
  94882. b->ptr[4]=(unsigned char)(value<<(8-b->endbit));
  94883. else
  94884. b->ptr[4]=0;
  94885. }
  94886. }
  94887. }
  94888. }
  94889. b->endbyte+=bits/8;
  94890. b->ptr+=bits/8;
  94891. b->endbit=bits&7;
  94892. }
  94893. void oggpack_writealign(oggpack_buffer *b){
  94894. int bits=8-b->endbit;
  94895. if(bits<8)
  94896. oggpack_write(b,0,bits);
  94897. }
  94898. void oggpackB_writealign(oggpack_buffer *b){
  94899. int bits=8-b->endbit;
  94900. if(bits<8)
  94901. oggpackB_write(b,0,bits);
  94902. }
  94903. static void oggpack_writecopy_helper(oggpack_buffer *b,
  94904. void *source,
  94905. long bits,
  94906. void (*w)(oggpack_buffer *,
  94907. unsigned long,
  94908. int),
  94909. int msb){
  94910. unsigned char *ptr=(unsigned char *)source;
  94911. long bytes=bits/8;
  94912. bits-=bytes*8;
  94913. if(b->endbit){
  94914. int i;
  94915. for(i=0;i<bytes;i++)
  94916. w(b,(unsigned long)(ptr[i]),8);
  94917. }else{
  94918. if(b->endbyte+bytes+1>=b->storage){
  94919. b->storage=b->endbyte+bytes+BUFFER_INCREMENT;
  94920. b->buffer=(unsigned char*) _ogg_realloc(b->buffer,b->storage);
  94921. b->ptr=b->buffer+b->endbyte;
  94922. }
  94923. memmove(b->ptr,source,bytes);
  94924. b->ptr+=bytes;
  94925. b->endbyte+=bytes;
  94926. *b->ptr=0;
  94927. }
  94928. if(bits){
  94929. if(msb)
  94930. w(b,(unsigned long)(ptr[bytes]>>(8-bits)),bits);
  94931. else
  94932. w(b,(unsigned long)(ptr[bytes]),bits);
  94933. }
  94934. }
  94935. void oggpack_writecopy(oggpack_buffer *b,void *source,long bits){
  94936. oggpack_writecopy_helper(b,source,bits,oggpack_write,0);
  94937. }
  94938. void oggpackB_writecopy(oggpack_buffer *b,void *source,long bits){
  94939. oggpack_writecopy_helper(b,source,bits,oggpackB_write,1);
  94940. }
  94941. void oggpack_reset(oggpack_buffer *b){
  94942. b->ptr=b->buffer;
  94943. b->buffer[0]=0;
  94944. b->endbit=b->endbyte=0;
  94945. }
  94946. void oggpackB_reset(oggpack_buffer *b){
  94947. oggpack_reset(b);
  94948. }
  94949. void oggpack_writeclear(oggpack_buffer *b){
  94950. _ogg_free(b->buffer);
  94951. memset(b,0,sizeof(*b));
  94952. }
  94953. void oggpackB_writeclear(oggpack_buffer *b){
  94954. oggpack_writeclear(b);
  94955. }
  94956. void oggpack_readinit(oggpack_buffer *b,unsigned char *buf,int bytes){
  94957. memset(b,0,sizeof(*b));
  94958. b->buffer=b->ptr=buf;
  94959. b->storage=bytes;
  94960. }
  94961. void oggpackB_readinit(oggpack_buffer *b,unsigned char *buf,int bytes){
  94962. oggpack_readinit(b,buf,bytes);
  94963. }
  94964. long oggpack_look(oggpack_buffer *b,int bits){
  94965. unsigned long ret;
  94966. unsigned long m=mask[bits];
  94967. bits+=b->endbit;
  94968. if(b->endbyte+4>=b->storage){
  94969. if(b->endbyte*8+bits>b->storage*8)return(-1);
  94970. }
  94971. ret=b->ptr[0]>>b->endbit;
  94972. if(bits>8){
  94973. ret|=b->ptr[1]<<(8-b->endbit);
  94974. if(bits>16){
  94975. ret|=b->ptr[2]<<(16-b->endbit);
  94976. if(bits>24){
  94977. ret|=b->ptr[3]<<(24-b->endbit);
  94978. if(bits>32 && b->endbit)
  94979. ret|=b->ptr[4]<<(32-b->endbit);
  94980. }
  94981. }
  94982. }
  94983. return(m&ret);
  94984. }
  94985. long oggpackB_look(oggpack_buffer *b,int bits){
  94986. unsigned long ret;
  94987. int m=32-bits;
  94988. bits+=b->endbit;
  94989. if(b->endbyte+4>=b->storage){
  94990. if(b->endbyte*8+bits>b->storage*8)return(-1);
  94991. }
  94992. ret=b->ptr[0]<<(24+b->endbit);
  94993. if(bits>8){
  94994. ret|=b->ptr[1]<<(16+b->endbit);
  94995. if(bits>16){
  94996. ret|=b->ptr[2]<<(8+b->endbit);
  94997. if(bits>24){
  94998. ret|=b->ptr[3]<<(b->endbit);
  94999. if(bits>32 && b->endbit)
  95000. ret|=b->ptr[4]>>(8-b->endbit);
  95001. }
  95002. }
  95003. }
  95004. return ((ret&0xffffffff)>>(m>>1))>>((m+1)>>1);
  95005. }
  95006. long oggpack_look1(oggpack_buffer *b){
  95007. if(b->endbyte>=b->storage)return(-1);
  95008. return((b->ptr[0]>>b->endbit)&1);
  95009. }
  95010. long oggpackB_look1(oggpack_buffer *b){
  95011. if(b->endbyte>=b->storage)return(-1);
  95012. return((b->ptr[0]>>(7-b->endbit))&1);
  95013. }
  95014. void oggpack_adv(oggpack_buffer *b,int bits){
  95015. bits+=b->endbit;
  95016. b->ptr+=bits/8;
  95017. b->endbyte+=bits/8;
  95018. b->endbit=bits&7;
  95019. }
  95020. void oggpackB_adv(oggpack_buffer *b,int bits){
  95021. oggpack_adv(b,bits);
  95022. }
  95023. void oggpack_adv1(oggpack_buffer *b){
  95024. if(++(b->endbit)>7){
  95025. b->endbit=0;
  95026. b->ptr++;
  95027. b->endbyte++;
  95028. }
  95029. }
  95030. void oggpackB_adv1(oggpack_buffer *b){
  95031. oggpack_adv1(b);
  95032. }
  95033. long oggpack_read(oggpack_buffer *b,int bits){
  95034. long ret;
  95035. unsigned long m=mask[bits];
  95036. bits+=b->endbit;
  95037. if(b->endbyte+4>=b->storage){
  95038. ret=-1L;
  95039. if(b->endbyte*8+bits>b->storage*8)goto overflow;
  95040. }
  95041. ret=b->ptr[0]>>b->endbit;
  95042. if(bits>8){
  95043. ret|=b->ptr[1]<<(8-b->endbit);
  95044. if(bits>16){
  95045. ret|=b->ptr[2]<<(16-b->endbit);
  95046. if(bits>24){
  95047. ret|=b->ptr[3]<<(24-b->endbit);
  95048. if(bits>32 && b->endbit){
  95049. ret|=b->ptr[4]<<(32-b->endbit);
  95050. }
  95051. }
  95052. }
  95053. }
  95054. ret&=m;
  95055. overflow:
  95056. b->ptr+=bits/8;
  95057. b->endbyte+=bits/8;
  95058. b->endbit=bits&7;
  95059. return(ret);
  95060. }
  95061. long oggpackB_read(oggpack_buffer *b,int bits){
  95062. long ret;
  95063. long m=32-bits;
  95064. bits+=b->endbit;
  95065. if(b->endbyte+4>=b->storage){
  95066. ret=-1L;
  95067. if(b->endbyte*8+bits>b->storage*8)goto overflow;
  95068. }
  95069. ret=b->ptr[0]<<(24+b->endbit);
  95070. if(bits>8){
  95071. ret|=b->ptr[1]<<(16+b->endbit);
  95072. if(bits>16){
  95073. ret|=b->ptr[2]<<(8+b->endbit);
  95074. if(bits>24){
  95075. ret|=b->ptr[3]<<(b->endbit);
  95076. if(bits>32 && b->endbit)
  95077. ret|=b->ptr[4]>>(8-b->endbit);
  95078. }
  95079. }
  95080. }
  95081. ret=((ret&0xffffffffUL)>>(m>>1))>>((m+1)>>1);
  95082. overflow:
  95083. b->ptr+=bits/8;
  95084. b->endbyte+=bits/8;
  95085. b->endbit=bits&7;
  95086. return(ret);
  95087. }
  95088. long oggpack_read1(oggpack_buffer *b){
  95089. long ret;
  95090. if(b->endbyte>=b->storage){
  95091. ret=-1L;
  95092. goto overflow;
  95093. }
  95094. ret=(b->ptr[0]>>b->endbit)&1;
  95095. overflow:
  95096. b->endbit++;
  95097. if(b->endbit>7){
  95098. b->endbit=0;
  95099. b->ptr++;
  95100. b->endbyte++;
  95101. }
  95102. return(ret);
  95103. }
  95104. long oggpackB_read1(oggpack_buffer *b){
  95105. long ret;
  95106. if(b->endbyte>=b->storage){
  95107. ret=-1L;
  95108. goto overflow;
  95109. }
  95110. ret=(b->ptr[0]>>(7-b->endbit))&1;
  95111. overflow:
  95112. b->endbit++;
  95113. if(b->endbit>7){
  95114. b->endbit=0;
  95115. b->ptr++;
  95116. b->endbyte++;
  95117. }
  95118. return(ret);
  95119. }
  95120. long oggpack_bytes(oggpack_buffer *b){
  95121. return(b->endbyte+(b->endbit+7)/8);
  95122. }
  95123. long oggpack_bits(oggpack_buffer *b){
  95124. return(b->endbyte*8+b->endbit);
  95125. }
  95126. long oggpackB_bytes(oggpack_buffer *b){
  95127. return oggpack_bytes(b);
  95128. }
  95129. long oggpackB_bits(oggpack_buffer *b){
  95130. return oggpack_bits(b);
  95131. }
  95132. unsigned char *oggpack_get_buffer(oggpack_buffer *b){
  95133. return(b->buffer);
  95134. }
  95135. unsigned char *oggpackB_get_buffer(oggpack_buffer *b){
  95136. return oggpack_get_buffer(b);
  95137. }
  95138. #ifdef _V_SELFTEST
  95139. #include <stdio.h>
  95140. static int ilog(unsigned int v){
  95141. int ret=0;
  95142. while(v){
  95143. ret++;
  95144. v>>=1;
  95145. }
  95146. return(ret);
  95147. }
  95148. oggpack_buffer o;
  95149. oggpack_buffer r;
  95150. void report(char *in){
  95151. fprintf(stderr,"%s",in);
  95152. exit(1);
  95153. }
  95154. void cliptest(unsigned long *b,int vals,int bits,int *comp,int compsize){
  95155. long bytes,i;
  95156. unsigned char *buffer;
  95157. oggpack_reset(&o);
  95158. for(i=0;i<vals;i++)
  95159. oggpack_write(&o,b[i],bits?bits:ilog(b[i]));
  95160. buffer=oggpack_get_buffer(&o);
  95161. bytes=oggpack_bytes(&o);
  95162. if(bytes!=compsize)report("wrong number of bytes!\n");
  95163. for(i=0;i<bytes;i++)if(buffer[i]!=comp[i]){
  95164. for(i=0;i<bytes;i++)fprintf(stderr,"%x %x\n",(int)buffer[i],(int)comp[i]);
  95165. report("wrote incorrect value!\n");
  95166. }
  95167. oggpack_readinit(&r,buffer,bytes);
  95168. for(i=0;i<vals;i++){
  95169. int tbit=bits?bits:ilog(b[i]);
  95170. if(oggpack_look(&r,tbit)==-1)
  95171. report("out of data!\n");
  95172. if(oggpack_look(&r,tbit)!=(b[i]&mask[tbit]))
  95173. report("looked at incorrect value!\n");
  95174. if(tbit==1)
  95175. if(oggpack_look1(&r)!=(b[i]&mask[tbit]))
  95176. report("looked at single bit incorrect value!\n");
  95177. if(tbit==1){
  95178. if(oggpack_read1(&r)!=(b[i]&mask[tbit]))
  95179. report("read incorrect single bit value!\n");
  95180. }else{
  95181. if(oggpack_read(&r,tbit)!=(b[i]&mask[tbit]))
  95182. report("read incorrect value!\n");
  95183. }
  95184. }
  95185. if(oggpack_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95186. }
  95187. void cliptestB(unsigned long *b,int vals,int bits,int *comp,int compsize){
  95188. long bytes,i;
  95189. unsigned char *buffer;
  95190. oggpackB_reset(&o);
  95191. for(i=0;i<vals;i++)
  95192. oggpackB_write(&o,b[i],bits?bits:ilog(b[i]));
  95193. buffer=oggpackB_get_buffer(&o);
  95194. bytes=oggpackB_bytes(&o);
  95195. if(bytes!=compsize)report("wrong number of bytes!\n");
  95196. for(i=0;i<bytes;i++)if(buffer[i]!=comp[i]){
  95197. for(i=0;i<bytes;i++)fprintf(stderr,"%x %x\n",(int)buffer[i],(int)comp[i]);
  95198. report("wrote incorrect value!\n");
  95199. }
  95200. oggpackB_readinit(&r,buffer,bytes);
  95201. for(i=0;i<vals;i++){
  95202. int tbit=bits?bits:ilog(b[i]);
  95203. if(oggpackB_look(&r,tbit)==-1)
  95204. report("out of data!\n");
  95205. if(oggpackB_look(&r,tbit)!=(b[i]&mask[tbit]))
  95206. report("looked at incorrect value!\n");
  95207. if(tbit==1)
  95208. if(oggpackB_look1(&r)!=(b[i]&mask[tbit]))
  95209. report("looked at single bit incorrect value!\n");
  95210. if(tbit==1){
  95211. if(oggpackB_read1(&r)!=(b[i]&mask[tbit]))
  95212. report("read incorrect single bit value!\n");
  95213. }else{
  95214. if(oggpackB_read(&r,tbit)!=(b[i]&mask[tbit]))
  95215. report("read incorrect value!\n");
  95216. }
  95217. }
  95218. if(oggpackB_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95219. }
  95220. int main(void){
  95221. unsigned char *buffer;
  95222. long bytes,i;
  95223. static unsigned long testbuffer1[]=
  95224. {18,12,103948,4325,543,76,432,52,3,65,4,56,32,42,34,21,1,23,32,546,456,7,
  95225. 567,56,8,8,55,3,52,342,341,4,265,7,67,86,2199,21,7,1,5,1,4};
  95226. int test1size=43;
  95227. static unsigned long testbuffer2[]=
  95228. {216531625L,1237861823,56732452,131,3212421,12325343,34547562,12313212,
  95229. 1233432,534,5,346435231,14436467,7869299,76326614,167548585,
  95230. 85525151,0,12321,1,349528352};
  95231. int test2size=21;
  95232. static unsigned long testbuffer3[]=
  95233. {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,
  95234. 0,1,30,1,1,1,0,0,1,0,0,0,12,0,11,0,1,0,0,1};
  95235. int test3size=56;
  95236. static unsigned long large[]=
  95237. {2136531625L,2137861823,56732452,131,3212421,12325343,34547562,12313212,
  95238. 1233432,534,5,2146435231,14436467,7869299,76326614,167548585,
  95239. 85525151,0,12321,1,2146528352};
  95240. int onesize=33;
  95241. static int one[33]={146,25,44,151,195,15,153,176,233,131,196,65,85,172,47,40,
  95242. 34,242,223,136,35,222,211,86,171,50,225,135,214,75,172,
  95243. 223,4};
  95244. static int oneB[33]={150,101,131,33,203,15,204,216,105,193,156,65,84,85,222,
  95245. 8,139,145,227,126,34,55,244,171,85,100,39,195,173,18,
  95246. 245,251,128};
  95247. int twosize=6;
  95248. static int two[6]={61,255,255,251,231,29};
  95249. static int twoB[6]={247,63,255,253,249,120};
  95250. int threesize=54;
  95251. static int three[54]={169,2,232,252,91,132,156,36,89,13,123,176,144,32,254,
  95252. 142,224,85,59,121,144,79,124,23,67,90,90,216,79,23,83,
  95253. 58,135,196,61,55,129,183,54,101,100,170,37,127,126,10,
  95254. 100,52,4,14,18,86,77,1};
  95255. static int threeB[54]={206,128,42,153,57,8,183,251,13,89,36,30,32,144,183,
  95256. 130,59,240,121,59,85,223,19,228,180,134,33,107,74,98,
  95257. 233,253,196,135,63,2,110,114,50,155,90,127,37,170,104,
  95258. 200,20,254,4,58,106,176,144,0};
  95259. int foursize=38;
  95260. static int four[38]={18,6,163,252,97,194,104,131,32,1,7,82,137,42,129,11,72,
  95261. 132,60,220,112,8,196,109,64,179,86,9,137,195,208,122,169,
  95262. 28,2,133,0,1};
  95263. static int fourB[38]={36,48,102,83,243,24,52,7,4,35,132,10,145,21,2,93,2,41,
  95264. 1,219,184,16,33,184,54,149,170,132,18,30,29,98,229,67,
  95265. 129,10,4,32};
  95266. int fivesize=45;
  95267. static int five[45]={169,2,126,139,144,172,30,4,80,72,240,59,130,218,73,62,
  95268. 241,24,210,44,4,20,0,248,116,49,135,100,110,130,181,169,
  95269. 84,75,159,2,1,0,132,192,8,0,0,18,22};
  95270. static int fiveB[45]={1,84,145,111,245,100,128,8,56,36,40,71,126,78,213,226,
  95271. 124,105,12,0,133,128,0,162,233,242,67,152,77,205,77,
  95272. 172,150,169,129,79,128,0,6,4,32,0,27,9,0};
  95273. int sixsize=7;
  95274. static int six[7]={17,177,170,242,169,19,148};
  95275. static int sixB[7]={136,141,85,79,149,200,41};
  95276. oggpack_writeinit(&o);
  95277. fprintf(stderr,"\nSmall preclipped packing (LSb): ");
  95278. cliptest(testbuffer1,test1size,0,one,onesize);
  95279. fprintf(stderr,"ok.");
  95280. fprintf(stderr,"\nNull bit call (LSb): ");
  95281. cliptest(testbuffer3,test3size,0,two,twosize);
  95282. fprintf(stderr,"ok.");
  95283. fprintf(stderr,"\nLarge preclipped packing (LSb): ");
  95284. cliptest(testbuffer2,test2size,0,three,threesize);
  95285. fprintf(stderr,"ok.");
  95286. fprintf(stderr,"\n32 bit preclipped packing (LSb): ");
  95287. oggpack_reset(&o);
  95288. for(i=0;i<test2size;i++)
  95289. oggpack_write(&o,large[i],32);
  95290. buffer=oggpack_get_buffer(&o);
  95291. bytes=oggpack_bytes(&o);
  95292. oggpack_readinit(&r,buffer,bytes);
  95293. for(i=0;i<test2size;i++){
  95294. if(oggpack_look(&r,32)==-1)report("out of data. failed!");
  95295. if(oggpack_look(&r,32)!=large[i]){
  95296. fprintf(stderr,"%ld != %ld (%lx!=%lx):",oggpack_look(&r,32),large[i],
  95297. oggpack_look(&r,32),large[i]);
  95298. report("read incorrect value!\n");
  95299. }
  95300. oggpack_adv(&r,32);
  95301. }
  95302. if(oggpack_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95303. fprintf(stderr,"ok.");
  95304. fprintf(stderr,"\nSmall unclipped packing (LSb): ");
  95305. cliptest(testbuffer1,test1size,7,four,foursize);
  95306. fprintf(stderr,"ok.");
  95307. fprintf(stderr,"\nLarge unclipped packing (LSb): ");
  95308. cliptest(testbuffer2,test2size,17,five,fivesize);
  95309. fprintf(stderr,"ok.");
  95310. fprintf(stderr,"\nSingle bit unclipped packing (LSb): ");
  95311. cliptest(testbuffer3,test3size,1,six,sixsize);
  95312. fprintf(stderr,"ok.");
  95313. fprintf(stderr,"\nTesting read past end (LSb): ");
  95314. oggpack_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95315. for(i=0;i<64;i++){
  95316. if(oggpack_read(&r,1)!=0){
  95317. fprintf(stderr,"failed; got -1 prematurely.\n");
  95318. exit(1);
  95319. }
  95320. }
  95321. if(oggpack_look(&r,1)!=-1 ||
  95322. oggpack_read(&r,1)!=-1){
  95323. fprintf(stderr,"failed; read past end without -1.\n");
  95324. exit(1);
  95325. }
  95326. oggpack_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95327. if(oggpack_read(&r,30)!=0 || oggpack_read(&r,16)!=0){
  95328. fprintf(stderr,"failed 2; got -1 prematurely.\n");
  95329. exit(1);
  95330. }
  95331. if(oggpack_look(&r,18)!=0 ||
  95332. oggpack_look(&r,18)!=0){
  95333. fprintf(stderr,"failed 3; got -1 prematurely.\n");
  95334. exit(1);
  95335. }
  95336. if(oggpack_look(&r,19)!=-1 ||
  95337. oggpack_look(&r,19)!=-1){
  95338. fprintf(stderr,"failed; read past end without -1.\n");
  95339. exit(1);
  95340. }
  95341. if(oggpack_look(&r,32)!=-1 ||
  95342. oggpack_look(&r,32)!=-1){
  95343. fprintf(stderr,"failed; read past end without -1.\n");
  95344. exit(1);
  95345. }
  95346. oggpack_writeclear(&o);
  95347. fprintf(stderr,"ok.\n");
  95348. oggpackB_writeinit(&o);
  95349. fprintf(stderr,"\nSmall preclipped packing (MSb): ");
  95350. cliptestB(testbuffer1,test1size,0,oneB,onesize);
  95351. fprintf(stderr,"ok.");
  95352. fprintf(stderr,"\nNull bit call (MSb): ");
  95353. cliptestB(testbuffer3,test3size,0,twoB,twosize);
  95354. fprintf(stderr,"ok.");
  95355. fprintf(stderr,"\nLarge preclipped packing (MSb): ");
  95356. cliptestB(testbuffer2,test2size,0,threeB,threesize);
  95357. fprintf(stderr,"ok.");
  95358. fprintf(stderr,"\n32 bit preclipped packing (MSb): ");
  95359. oggpackB_reset(&o);
  95360. for(i=0;i<test2size;i++)
  95361. oggpackB_write(&o,large[i],32);
  95362. buffer=oggpackB_get_buffer(&o);
  95363. bytes=oggpackB_bytes(&o);
  95364. oggpackB_readinit(&r,buffer,bytes);
  95365. for(i=0;i<test2size;i++){
  95366. if(oggpackB_look(&r,32)==-1)report("out of data. failed!");
  95367. if(oggpackB_look(&r,32)!=large[i]){
  95368. fprintf(stderr,"%ld != %ld (%lx!=%lx):",oggpackB_look(&r,32),large[i],
  95369. oggpackB_look(&r,32),large[i]);
  95370. report("read incorrect value!\n");
  95371. }
  95372. oggpackB_adv(&r,32);
  95373. }
  95374. if(oggpackB_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95375. fprintf(stderr,"ok.");
  95376. fprintf(stderr,"\nSmall unclipped packing (MSb): ");
  95377. cliptestB(testbuffer1,test1size,7,fourB,foursize);
  95378. fprintf(stderr,"ok.");
  95379. fprintf(stderr,"\nLarge unclipped packing (MSb): ");
  95380. cliptestB(testbuffer2,test2size,17,fiveB,fivesize);
  95381. fprintf(stderr,"ok.");
  95382. fprintf(stderr,"\nSingle bit unclipped packing (MSb): ");
  95383. cliptestB(testbuffer3,test3size,1,sixB,sixsize);
  95384. fprintf(stderr,"ok.");
  95385. fprintf(stderr,"\nTesting read past end (MSb): ");
  95386. oggpackB_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95387. for(i=0;i<64;i++){
  95388. if(oggpackB_read(&r,1)!=0){
  95389. fprintf(stderr,"failed; got -1 prematurely.\n");
  95390. exit(1);
  95391. }
  95392. }
  95393. if(oggpackB_look(&r,1)!=-1 ||
  95394. oggpackB_read(&r,1)!=-1){
  95395. fprintf(stderr,"failed; read past end without -1.\n");
  95396. exit(1);
  95397. }
  95398. oggpackB_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95399. if(oggpackB_read(&r,30)!=0 || oggpackB_read(&r,16)!=0){
  95400. fprintf(stderr,"failed 2; got -1 prematurely.\n");
  95401. exit(1);
  95402. }
  95403. if(oggpackB_look(&r,18)!=0 ||
  95404. oggpackB_look(&r,18)!=0){
  95405. fprintf(stderr,"failed 3; got -1 prematurely.\n");
  95406. exit(1);
  95407. }
  95408. if(oggpackB_look(&r,19)!=-1 ||
  95409. oggpackB_look(&r,19)!=-1){
  95410. fprintf(stderr,"failed; read past end without -1.\n");
  95411. exit(1);
  95412. }
  95413. if(oggpackB_look(&r,32)!=-1 ||
  95414. oggpackB_look(&r,32)!=-1){
  95415. fprintf(stderr,"failed; read past end without -1.\n");
  95416. exit(1);
  95417. }
  95418. oggpackB_writeclear(&o);
  95419. fprintf(stderr,"ok.\n\n");
  95420. return(0);
  95421. }
  95422. #endif /* _V_SELFTEST */
  95423. #undef BUFFER_INCREMENT
  95424. #endif
  95425. /*** End of inlined file: bitwise.c ***/
  95426. /*** Start of inlined file: framing.c ***/
  95427. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  95428. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  95429. // tasks..
  95430. #if JUCE_MSVC
  95431. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  95432. #endif
  95433. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  95434. #if JUCE_USE_OGGVORBIS
  95435. #include <stdlib.h>
  95436. #include <string.h>
  95437. int ogg_page_version(ogg_page *og){
  95438. return((int)(og->header[4]));
  95439. }
  95440. int ogg_page_continued(ogg_page *og){
  95441. return((int)(og->header[5]&0x01));
  95442. }
  95443. int ogg_page_bos(ogg_page *og){
  95444. return((int)(og->header[5]&0x02));
  95445. }
  95446. int ogg_page_eos(ogg_page *og){
  95447. return((int)(og->header[5]&0x04));
  95448. }
  95449. ogg_int64_t ogg_page_granulepos(ogg_page *og){
  95450. unsigned char *page=og->header;
  95451. ogg_int64_t granulepos=page[13]&(0xff);
  95452. granulepos= (granulepos<<8)|(page[12]&0xff);
  95453. granulepos= (granulepos<<8)|(page[11]&0xff);
  95454. granulepos= (granulepos<<8)|(page[10]&0xff);
  95455. granulepos= (granulepos<<8)|(page[9]&0xff);
  95456. granulepos= (granulepos<<8)|(page[8]&0xff);
  95457. granulepos= (granulepos<<8)|(page[7]&0xff);
  95458. granulepos= (granulepos<<8)|(page[6]&0xff);
  95459. return(granulepos);
  95460. }
  95461. int ogg_page_serialno(ogg_page *og){
  95462. return(og->header[14] |
  95463. (og->header[15]<<8) |
  95464. (og->header[16]<<16) |
  95465. (og->header[17]<<24));
  95466. }
  95467. long ogg_page_pageno(ogg_page *og){
  95468. return(og->header[18] |
  95469. (og->header[19]<<8) |
  95470. (og->header[20]<<16) |
  95471. (og->header[21]<<24));
  95472. }
  95473. int ogg_page_packets(ogg_page *og){
  95474. int i,n=og->header[26],count=0;
  95475. for(i=0;i<n;i++)
  95476. if(og->header[27+i]<255)count++;
  95477. return(count);
  95478. }
  95479. #if 0
  95480. static ogg_uint32_t _ogg_crc_entry(unsigned long index){
  95481. int i;
  95482. unsigned long r;
  95483. r = index << 24;
  95484. for (i=0; i<8; i++)
  95485. if (r & 0x80000000UL)
  95486. r = (r << 1) ^ 0x04c11db7; /* The same as the ethernet generator
  95487. polynomial, although we use an
  95488. unreflected alg and an init/final
  95489. of 0, not 0xffffffff */
  95490. else
  95491. r<<=1;
  95492. return (r & 0xffffffffUL);
  95493. }
  95494. #endif
  95495. static const ogg_uint32_t crc_lookup[256]={
  95496. 0x00000000,0x04c11db7,0x09823b6e,0x0d4326d9,
  95497. 0x130476dc,0x17c56b6b,0x1a864db2,0x1e475005,
  95498. 0x2608edb8,0x22c9f00f,0x2f8ad6d6,0x2b4bcb61,
  95499. 0x350c9b64,0x31cd86d3,0x3c8ea00a,0x384fbdbd,
  95500. 0x4c11db70,0x48d0c6c7,0x4593e01e,0x4152fda9,
  95501. 0x5f15adac,0x5bd4b01b,0x569796c2,0x52568b75,
  95502. 0x6a1936c8,0x6ed82b7f,0x639b0da6,0x675a1011,
  95503. 0x791d4014,0x7ddc5da3,0x709f7b7a,0x745e66cd,
  95504. 0x9823b6e0,0x9ce2ab57,0x91a18d8e,0x95609039,
  95505. 0x8b27c03c,0x8fe6dd8b,0x82a5fb52,0x8664e6e5,
  95506. 0xbe2b5b58,0xbaea46ef,0xb7a96036,0xb3687d81,
  95507. 0xad2f2d84,0xa9ee3033,0xa4ad16ea,0xa06c0b5d,
  95508. 0xd4326d90,0xd0f37027,0xddb056fe,0xd9714b49,
  95509. 0xc7361b4c,0xc3f706fb,0xceb42022,0xca753d95,
  95510. 0xf23a8028,0xf6fb9d9f,0xfbb8bb46,0xff79a6f1,
  95511. 0xe13ef6f4,0xe5ffeb43,0xe8bccd9a,0xec7dd02d,
  95512. 0x34867077,0x30476dc0,0x3d044b19,0x39c556ae,
  95513. 0x278206ab,0x23431b1c,0x2e003dc5,0x2ac12072,
  95514. 0x128e9dcf,0x164f8078,0x1b0ca6a1,0x1fcdbb16,
  95515. 0x018aeb13,0x054bf6a4,0x0808d07d,0x0cc9cdca,
  95516. 0x7897ab07,0x7c56b6b0,0x71159069,0x75d48dde,
  95517. 0x6b93dddb,0x6f52c06c,0x6211e6b5,0x66d0fb02,
  95518. 0x5e9f46bf,0x5a5e5b08,0x571d7dd1,0x53dc6066,
  95519. 0x4d9b3063,0x495a2dd4,0x44190b0d,0x40d816ba,
  95520. 0xaca5c697,0xa864db20,0xa527fdf9,0xa1e6e04e,
  95521. 0xbfa1b04b,0xbb60adfc,0xb6238b25,0xb2e29692,
  95522. 0x8aad2b2f,0x8e6c3698,0x832f1041,0x87ee0df6,
  95523. 0x99a95df3,0x9d684044,0x902b669d,0x94ea7b2a,
  95524. 0xe0b41de7,0xe4750050,0xe9362689,0xedf73b3e,
  95525. 0xf3b06b3b,0xf771768c,0xfa325055,0xfef34de2,
  95526. 0xc6bcf05f,0xc27dede8,0xcf3ecb31,0xcbffd686,
  95527. 0xd5b88683,0xd1799b34,0xdc3abded,0xd8fba05a,
  95528. 0x690ce0ee,0x6dcdfd59,0x608edb80,0x644fc637,
  95529. 0x7a089632,0x7ec98b85,0x738aad5c,0x774bb0eb,
  95530. 0x4f040d56,0x4bc510e1,0x46863638,0x42472b8f,
  95531. 0x5c007b8a,0x58c1663d,0x558240e4,0x51435d53,
  95532. 0x251d3b9e,0x21dc2629,0x2c9f00f0,0x285e1d47,
  95533. 0x36194d42,0x32d850f5,0x3f9b762c,0x3b5a6b9b,
  95534. 0x0315d626,0x07d4cb91,0x0a97ed48,0x0e56f0ff,
  95535. 0x1011a0fa,0x14d0bd4d,0x19939b94,0x1d528623,
  95536. 0xf12f560e,0xf5ee4bb9,0xf8ad6d60,0xfc6c70d7,
  95537. 0xe22b20d2,0xe6ea3d65,0xeba91bbc,0xef68060b,
  95538. 0xd727bbb6,0xd3e6a601,0xdea580d8,0xda649d6f,
  95539. 0xc423cd6a,0xc0e2d0dd,0xcda1f604,0xc960ebb3,
  95540. 0xbd3e8d7e,0xb9ff90c9,0xb4bcb610,0xb07daba7,
  95541. 0xae3afba2,0xaafbe615,0xa7b8c0cc,0xa379dd7b,
  95542. 0x9b3660c6,0x9ff77d71,0x92b45ba8,0x9675461f,
  95543. 0x8832161a,0x8cf30bad,0x81b02d74,0x857130c3,
  95544. 0x5d8a9099,0x594b8d2e,0x5408abf7,0x50c9b640,
  95545. 0x4e8ee645,0x4a4ffbf2,0x470cdd2b,0x43cdc09c,
  95546. 0x7b827d21,0x7f436096,0x7200464f,0x76c15bf8,
  95547. 0x68860bfd,0x6c47164a,0x61043093,0x65c52d24,
  95548. 0x119b4be9,0x155a565e,0x18197087,0x1cd86d30,
  95549. 0x029f3d35,0x065e2082,0x0b1d065b,0x0fdc1bec,
  95550. 0x3793a651,0x3352bbe6,0x3e119d3f,0x3ad08088,
  95551. 0x2497d08d,0x2056cd3a,0x2d15ebe3,0x29d4f654,
  95552. 0xc5a92679,0xc1683bce,0xcc2b1d17,0xc8ea00a0,
  95553. 0xd6ad50a5,0xd26c4d12,0xdf2f6bcb,0xdbee767c,
  95554. 0xe3a1cbc1,0xe760d676,0xea23f0af,0xeee2ed18,
  95555. 0xf0a5bd1d,0xf464a0aa,0xf9278673,0xfde69bc4,
  95556. 0x89b8fd09,0x8d79e0be,0x803ac667,0x84fbdbd0,
  95557. 0x9abc8bd5,0x9e7d9662,0x933eb0bb,0x97ffad0c,
  95558. 0xafb010b1,0xab710d06,0xa6322bdf,0xa2f33668,
  95559. 0xbcb4666d,0xb8757bda,0xb5365d03,0xb1f740b4};
  95560. int ogg_stream_init(ogg_stream_state *os,int serialno){
  95561. if(os){
  95562. memset(os,0,sizeof(*os));
  95563. os->body_storage=16*1024;
  95564. os->body_data=(unsigned char*) _ogg_malloc(os->body_storage*sizeof(*os->body_data));
  95565. os->lacing_storage=1024;
  95566. os->lacing_vals=(int*) _ogg_malloc(os->lacing_storage*sizeof(*os->lacing_vals));
  95567. os->granule_vals=(ogg_int64_t*) _ogg_malloc(os->lacing_storage*sizeof(*os->granule_vals));
  95568. os->serialno=serialno;
  95569. return(0);
  95570. }
  95571. return(-1);
  95572. }
  95573. int ogg_stream_clear(ogg_stream_state *os){
  95574. if(os){
  95575. if(os->body_data)_ogg_free(os->body_data);
  95576. if(os->lacing_vals)_ogg_free(os->lacing_vals);
  95577. if(os->granule_vals)_ogg_free(os->granule_vals);
  95578. memset(os,0,sizeof(*os));
  95579. }
  95580. return(0);
  95581. }
  95582. int ogg_stream_destroy(ogg_stream_state *os){
  95583. if(os){
  95584. ogg_stream_clear(os);
  95585. _ogg_free(os);
  95586. }
  95587. return(0);
  95588. }
  95589. static void _os_body_expand(ogg_stream_state *os,int needed){
  95590. if(os->body_storage<=os->body_fill+needed){
  95591. os->body_storage+=(needed+1024);
  95592. os->body_data=(unsigned char*) _ogg_realloc(os->body_data,os->body_storage*sizeof(*os->body_data));
  95593. }
  95594. }
  95595. static void _os_lacing_expand(ogg_stream_state *os,int needed){
  95596. if(os->lacing_storage<=os->lacing_fill+needed){
  95597. os->lacing_storage+=(needed+32);
  95598. os->lacing_vals=(int*)_ogg_realloc(os->lacing_vals,os->lacing_storage*sizeof(*os->lacing_vals));
  95599. os->granule_vals=(ogg_int64_t*)_ogg_realloc(os->granule_vals,os->lacing_storage*sizeof(*os->granule_vals));
  95600. }
  95601. }
  95602. void ogg_page_checksum_set(ogg_page *og){
  95603. if(og){
  95604. ogg_uint32_t crc_reg=0;
  95605. int i;
  95606. og->header[22]=0;
  95607. og->header[23]=0;
  95608. og->header[24]=0;
  95609. og->header[25]=0;
  95610. for(i=0;i<og->header_len;i++)
  95611. crc_reg=(crc_reg<<8)^crc_lookup[((crc_reg >> 24)&0xff)^og->header[i]];
  95612. for(i=0;i<og->body_len;i++)
  95613. crc_reg=(crc_reg<<8)^crc_lookup[((crc_reg >> 24)&0xff)^og->body[i]];
  95614. og->header[22]=(unsigned char)(crc_reg&0xff);
  95615. og->header[23]=(unsigned char)((crc_reg>>8)&0xff);
  95616. og->header[24]=(unsigned char)((crc_reg>>16)&0xff);
  95617. og->header[25]=(unsigned char)((crc_reg>>24)&0xff);
  95618. }
  95619. }
  95620. int ogg_stream_packetin(ogg_stream_state *os,ogg_packet *op){
  95621. int lacing_vals=op->bytes/255+1,i;
  95622. if(os->body_returned){
  95623. os->body_fill-=os->body_returned;
  95624. if(os->body_fill)
  95625. memmove(os->body_data,os->body_data+os->body_returned,
  95626. os->body_fill);
  95627. os->body_returned=0;
  95628. }
  95629. _os_body_expand(os,op->bytes);
  95630. _os_lacing_expand(os,lacing_vals);
  95631. memcpy(os->body_data+os->body_fill,op->packet,op->bytes);
  95632. os->body_fill+=op->bytes;
  95633. for(i=0;i<lacing_vals-1;i++){
  95634. os->lacing_vals[os->lacing_fill+i]=255;
  95635. os->granule_vals[os->lacing_fill+i]=os->granulepos;
  95636. }
  95637. os->lacing_vals[os->lacing_fill+i]=(op->bytes)%255;
  95638. os->granulepos=os->granule_vals[os->lacing_fill+i]=op->granulepos;
  95639. os->lacing_vals[os->lacing_fill]|= 0x100;
  95640. os->lacing_fill+=lacing_vals;
  95641. os->packetno++;
  95642. if(op->e_o_s)os->e_o_s=1;
  95643. return(0);
  95644. }
  95645. int ogg_stream_flush(ogg_stream_state *os,ogg_page *og){
  95646. int i;
  95647. int vals=0;
  95648. int maxvals=(os->lacing_fill>255?255:os->lacing_fill);
  95649. int bytes=0;
  95650. long acc=0;
  95651. ogg_int64_t granule_pos=-1;
  95652. if(maxvals==0)return(0);
  95653. if(os->b_o_s==0){ /* 'initial header page' case */
  95654. granule_pos=0;
  95655. for(vals=0;vals<maxvals;vals++){
  95656. if((os->lacing_vals[vals]&0x0ff)<255){
  95657. vals++;
  95658. break;
  95659. }
  95660. }
  95661. }else{
  95662. for(vals=0;vals<maxvals;vals++){
  95663. if(acc>4096)break;
  95664. acc+=os->lacing_vals[vals]&0x0ff;
  95665. if((os->lacing_vals[vals]&0xff)<255)
  95666. granule_pos=os->granule_vals[vals];
  95667. }
  95668. }
  95669. memcpy(os->header,"OggS",4);
  95670. os->header[4]=0x00;
  95671. os->header[5]=0x00;
  95672. if((os->lacing_vals[0]&0x100)==0)os->header[5]|=0x01;
  95673. if(os->b_o_s==0)os->header[5]|=0x02;
  95674. if(os->e_o_s && os->lacing_fill==vals)os->header[5]|=0x04;
  95675. os->b_o_s=1;
  95676. for(i=6;i<14;i++){
  95677. os->header[i]=(unsigned char)(granule_pos&0xff);
  95678. granule_pos>>=8;
  95679. }
  95680. {
  95681. long serialno=os->serialno;
  95682. for(i=14;i<18;i++){
  95683. os->header[i]=(unsigned char)(serialno&0xff);
  95684. serialno>>=8;
  95685. }
  95686. }
  95687. if(os->pageno==-1)os->pageno=0; /* because someone called
  95688. stream_reset; this would be a
  95689. strange thing to do in an
  95690. encode stream, but it has
  95691. plausible uses */
  95692. {
  95693. long pageno=os->pageno++;
  95694. for(i=18;i<22;i++){
  95695. os->header[i]=(unsigned char)(pageno&0xff);
  95696. pageno>>=8;
  95697. }
  95698. }
  95699. os->header[22]=0;
  95700. os->header[23]=0;
  95701. os->header[24]=0;
  95702. os->header[25]=0;
  95703. os->header[26]=(unsigned char)(vals&0xff);
  95704. for(i=0;i<vals;i++)
  95705. bytes+=os->header[i+27]=(unsigned char)(os->lacing_vals[i]&0xff);
  95706. og->header=os->header;
  95707. og->header_len=os->header_fill=vals+27;
  95708. og->body=os->body_data+os->body_returned;
  95709. og->body_len=bytes;
  95710. os->lacing_fill-=vals;
  95711. memmove(os->lacing_vals,os->lacing_vals+vals,os->lacing_fill*sizeof(*os->lacing_vals));
  95712. memmove(os->granule_vals,os->granule_vals+vals,os->lacing_fill*sizeof(*os->granule_vals));
  95713. os->body_returned+=bytes;
  95714. ogg_page_checksum_set(og);
  95715. return(1);
  95716. }
  95717. int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og){
  95718. if((os->e_o_s&&os->lacing_fill) || /* 'were done, now flush' case */
  95719. os->body_fill-os->body_returned > 4096 ||/* 'page nominal size' case */
  95720. os->lacing_fill>=255 || /* 'segment table full' case */
  95721. (os->lacing_fill&&!os->b_o_s)){ /* 'initial header page' case */
  95722. return(ogg_stream_flush(os,og));
  95723. }
  95724. return(0);
  95725. }
  95726. int ogg_stream_eos(ogg_stream_state *os){
  95727. return os->e_o_s;
  95728. }
  95729. int ogg_sync_init(ogg_sync_state *oy){
  95730. if(oy){
  95731. memset(oy,0,sizeof(*oy));
  95732. }
  95733. return(0);
  95734. }
  95735. int ogg_sync_clear(ogg_sync_state *oy){
  95736. if(oy){
  95737. if(oy->data)_ogg_free(oy->data);
  95738. ogg_sync_init(oy);
  95739. }
  95740. return(0);
  95741. }
  95742. int ogg_sync_destroy(ogg_sync_state *oy){
  95743. if(oy){
  95744. ogg_sync_clear(oy);
  95745. _ogg_free(oy);
  95746. }
  95747. return(0);
  95748. }
  95749. char *ogg_sync_buffer(ogg_sync_state *oy, long size){
  95750. if(oy->returned){
  95751. oy->fill-=oy->returned;
  95752. if(oy->fill>0)
  95753. memmove(oy->data,oy->data+oy->returned,oy->fill);
  95754. oy->returned=0;
  95755. }
  95756. if(size>oy->storage-oy->fill){
  95757. long newsize=size+oy->fill+4096; /* an extra page to be nice */
  95758. if(oy->data)
  95759. oy->data=(unsigned char*) _ogg_realloc(oy->data,newsize);
  95760. else
  95761. oy->data=(unsigned char*) _ogg_malloc(newsize);
  95762. oy->storage=newsize;
  95763. }
  95764. return((char *)oy->data+oy->fill);
  95765. }
  95766. int ogg_sync_wrote(ogg_sync_state *oy, long bytes){
  95767. if(oy->fill+bytes>oy->storage)return(-1);
  95768. oy->fill+=bytes;
  95769. return(0);
  95770. }
  95771. long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og){
  95772. unsigned char *page=oy->data+oy->returned;
  95773. unsigned char *next;
  95774. long bytes=oy->fill-oy->returned;
  95775. if(oy->headerbytes==0){
  95776. int headerbytes,i;
  95777. if(bytes<27)return(0); /* not enough for a header */
  95778. if(memcmp(page,"OggS",4))goto sync_fail;
  95779. headerbytes=page[26]+27;
  95780. if(bytes<headerbytes)return(0); /* not enough for header + seg table */
  95781. for(i=0;i<page[26];i++)
  95782. oy->bodybytes+=page[27+i];
  95783. oy->headerbytes=headerbytes;
  95784. }
  95785. if(oy->bodybytes+oy->headerbytes>bytes)return(0);
  95786. {
  95787. char chksum[4];
  95788. ogg_page log;
  95789. memcpy(chksum,page+22,4);
  95790. memset(page+22,0,4);
  95791. log.header=page;
  95792. log.header_len=oy->headerbytes;
  95793. log.body=page+oy->headerbytes;
  95794. log.body_len=oy->bodybytes;
  95795. ogg_page_checksum_set(&log);
  95796. if(memcmp(chksum,page+22,4)){
  95797. memcpy(page+22,chksum,4);
  95798. goto sync_fail;
  95799. }
  95800. }
  95801. {
  95802. unsigned char *page=oy->data+oy->returned;
  95803. long bytes;
  95804. if(og){
  95805. og->header=page;
  95806. og->header_len=oy->headerbytes;
  95807. og->body=page+oy->headerbytes;
  95808. og->body_len=oy->bodybytes;
  95809. }
  95810. oy->unsynced=0;
  95811. oy->returned+=(bytes=oy->headerbytes+oy->bodybytes);
  95812. oy->headerbytes=0;
  95813. oy->bodybytes=0;
  95814. return(bytes);
  95815. }
  95816. sync_fail:
  95817. oy->headerbytes=0;
  95818. oy->bodybytes=0;
  95819. next=(unsigned char*)memchr(page+1,'O',bytes-1);
  95820. if(!next)
  95821. next=oy->data+oy->fill;
  95822. oy->returned=next-oy->data;
  95823. return(-(next-page));
  95824. }
  95825. int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og){
  95826. for(;;){
  95827. long ret=ogg_sync_pageseek(oy,og);
  95828. if(ret>0){
  95829. return(1);
  95830. }
  95831. if(ret==0){
  95832. return(0);
  95833. }
  95834. if(!oy->unsynced){
  95835. oy->unsynced=1;
  95836. return(-1);
  95837. }
  95838. }
  95839. }
  95840. int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og){
  95841. unsigned char *header=og->header;
  95842. unsigned char *body=og->body;
  95843. long bodysize=og->body_len;
  95844. int segptr=0;
  95845. int version=ogg_page_version(og);
  95846. int continued=ogg_page_continued(og);
  95847. int bos=ogg_page_bos(og);
  95848. int eos=ogg_page_eos(og);
  95849. ogg_int64_t granulepos=ogg_page_granulepos(og);
  95850. int serialno=ogg_page_serialno(og);
  95851. long pageno=ogg_page_pageno(og);
  95852. int segments=header[26];
  95853. {
  95854. long lr=os->lacing_returned;
  95855. long br=os->body_returned;
  95856. if(br){
  95857. os->body_fill-=br;
  95858. if(os->body_fill)
  95859. memmove(os->body_data,os->body_data+br,os->body_fill);
  95860. os->body_returned=0;
  95861. }
  95862. if(lr){
  95863. if(os->lacing_fill-lr){
  95864. memmove(os->lacing_vals,os->lacing_vals+lr,
  95865. (os->lacing_fill-lr)*sizeof(*os->lacing_vals));
  95866. memmove(os->granule_vals,os->granule_vals+lr,
  95867. (os->lacing_fill-lr)*sizeof(*os->granule_vals));
  95868. }
  95869. os->lacing_fill-=lr;
  95870. os->lacing_packet-=lr;
  95871. os->lacing_returned=0;
  95872. }
  95873. }
  95874. if(serialno!=os->serialno)return(-1);
  95875. if(version>0)return(-1);
  95876. _os_lacing_expand(os,segments+1);
  95877. if(pageno!=os->pageno){
  95878. int i;
  95879. for(i=os->lacing_packet;i<os->lacing_fill;i++)
  95880. os->body_fill-=os->lacing_vals[i]&0xff;
  95881. os->lacing_fill=os->lacing_packet;
  95882. if(os->pageno!=-1){
  95883. os->lacing_vals[os->lacing_fill++]=0x400;
  95884. os->lacing_packet++;
  95885. }
  95886. }
  95887. if(continued){
  95888. if(os->lacing_fill<1 ||
  95889. os->lacing_vals[os->lacing_fill-1]==0x400){
  95890. bos=0;
  95891. for(;segptr<segments;segptr++){
  95892. int val=header[27+segptr];
  95893. body+=val;
  95894. bodysize-=val;
  95895. if(val<255){
  95896. segptr++;
  95897. break;
  95898. }
  95899. }
  95900. }
  95901. }
  95902. if(bodysize){
  95903. _os_body_expand(os,bodysize);
  95904. memcpy(os->body_data+os->body_fill,body,bodysize);
  95905. os->body_fill+=bodysize;
  95906. }
  95907. {
  95908. int saved=-1;
  95909. while(segptr<segments){
  95910. int val=header[27+segptr];
  95911. os->lacing_vals[os->lacing_fill]=val;
  95912. os->granule_vals[os->lacing_fill]=-1;
  95913. if(bos){
  95914. os->lacing_vals[os->lacing_fill]|=0x100;
  95915. bos=0;
  95916. }
  95917. if(val<255)saved=os->lacing_fill;
  95918. os->lacing_fill++;
  95919. segptr++;
  95920. if(val<255)os->lacing_packet=os->lacing_fill;
  95921. }
  95922. if(saved!=-1){
  95923. os->granule_vals[saved]=granulepos;
  95924. }
  95925. }
  95926. if(eos){
  95927. os->e_o_s=1;
  95928. if(os->lacing_fill>0)
  95929. os->lacing_vals[os->lacing_fill-1]|=0x200;
  95930. }
  95931. os->pageno=pageno+1;
  95932. return(0);
  95933. }
  95934. int ogg_sync_reset(ogg_sync_state *oy){
  95935. oy->fill=0;
  95936. oy->returned=0;
  95937. oy->unsynced=0;
  95938. oy->headerbytes=0;
  95939. oy->bodybytes=0;
  95940. return(0);
  95941. }
  95942. int ogg_stream_reset(ogg_stream_state *os){
  95943. os->body_fill=0;
  95944. os->body_returned=0;
  95945. os->lacing_fill=0;
  95946. os->lacing_packet=0;
  95947. os->lacing_returned=0;
  95948. os->header_fill=0;
  95949. os->e_o_s=0;
  95950. os->b_o_s=0;
  95951. os->pageno=-1;
  95952. os->packetno=0;
  95953. os->granulepos=0;
  95954. return(0);
  95955. }
  95956. int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno){
  95957. ogg_stream_reset(os);
  95958. os->serialno=serialno;
  95959. return(0);
  95960. }
  95961. static int _packetout(ogg_stream_state *os,ogg_packet *op,int adv){
  95962. int ptr=os->lacing_returned;
  95963. if(os->lacing_packet<=ptr)return(0);
  95964. if(os->lacing_vals[ptr]&0x400){
  95965. os->lacing_returned++;
  95966. os->packetno++;
  95967. return(-1);
  95968. }
  95969. if(!op && !adv)return(1); /* just using peek as an inexpensive way
  95970. to ask if there's a whole packet
  95971. waiting */
  95972. {
  95973. int size=os->lacing_vals[ptr]&0xff;
  95974. int bytes=size;
  95975. int eos=os->lacing_vals[ptr]&0x200; /* last packet of the stream? */
  95976. int bos=os->lacing_vals[ptr]&0x100; /* first packet of the stream? */
  95977. while(size==255){
  95978. int val=os->lacing_vals[++ptr];
  95979. size=val&0xff;
  95980. if(val&0x200)eos=0x200;
  95981. bytes+=size;
  95982. }
  95983. if(op){
  95984. op->e_o_s=eos;
  95985. op->b_o_s=bos;
  95986. op->packet=os->body_data+os->body_returned;
  95987. op->packetno=os->packetno;
  95988. op->granulepos=os->granule_vals[ptr];
  95989. op->bytes=bytes;
  95990. }
  95991. if(adv){
  95992. os->body_returned+=bytes;
  95993. os->lacing_returned=ptr+1;
  95994. os->packetno++;
  95995. }
  95996. }
  95997. return(1);
  95998. }
  95999. int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op){
  96000. return _packetout(os,op,1);
  96001. }
  96002. int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op){
  96003. return _packetout(os,op,0);
  96004. }
  96005. void ogg_packet_clear(ogg_packet *op) {
  96006. _ogg_free(op->packet);
  96007. memset(op, 0, sizeof(*op));
  96008. }
  96009. #ifdef _V_SELFTEST
  96010. #include <stdio.h>
  96011. ogg_stream_state os_en, os_de;
  96012. ogg_sync_state oy;
  96013. void checkpacket(ogg_packet *op,int len, int no, int pos){
  96014. long j;
  96015. static int sequence=0;
  96016. static int lastno=0;
  96017. if(op->bytes!=len){
  96018. fprintf(stderr,"incorrect packet length!\n");
  96019. exit(1);
  96020. }
  96021. if(op->granulepos!=pos){
  96022. fprintf(stderr,"incorrect packet position!\n");
  96023. exit(1);
  96024. }
  96025. if(no==0){
  96026. sequence=0;
  96027. }else{
  96028. sequence++;
  96029. if(no>lastno+1)
  96030. sequence++;
  96031. }
  96032. lastno=no;
  96033. if(op->packetno!=sequence){
  96034. fprintf(stderr,"incorrect packet sequence %ld != %d\n",
  96035. (long)(op->packetno),sequence);
  96036. exit(1);
  96037. }
  96038. for(j=0;j<op->bytes;j++)
  96039. if(op->packet[j]!=((j+no)&0xff)){
  96040. fprintf(stderr,"body data mismatch (1) at pos %ld: %x!=%lx!\n\n",
  96041. j,op->packet[j],(j+no)&0xff);
  96042. exit(1);
  96043. }
  96044. }
  96045. void check_page(unsigned char *data,const int *header,ogg_page *og){
  96046. long j;
  96047. for(j=0;j<og->body_len;j++)
  96048. if(og->body[j]!=data[j]){
  96049. fprintf(stderr,"body data mismatch (2) at pos %ld: %x!=%x!\n\n",
  96050. j,data[j],og->body[j]);
  96051. exit(1);
  96052. }
  96053. for(j=0;j<og->header_len;j++){
  96054. if(og->header[j]!=header[j]){
  96055. fprintf(stderr,"header content mismatch at pos %ld:\n",j);
  96056. for(j=0;j<header[26]+27;j++)
  96057. fprintf(stderr," (%ld)%02x:%02x",j,header[j],og->header[j]);
  96058. fprintf(stderr,"\n");
  96059. exit(1);
  96060. }
  96061. }
  96062. if(og->header_len!=header[26]+27){
  96063. fprintf(stderr,"header length incorrect! (%ld!=%d)\n",
  96064. og->header_len,header[26]+27);
  96065. exit(1);
  96066. }
  96067. }
  96068. void print_header(ogg_page *og){
  96069. int j;
  96070. fprintf(stderr,"\nHEADER:\n");
  96071. fprintf(stderr," capture: %c %c %c %c version: %d flags: %x\n",
  96072. og->header[0],og->header[1],og->header[2],og->header[3],
  96073. (int)og->header[4],(int)og->header[5]);
  96074. fprintf(stderr," granulepos: %d serialno: %d pageno: %ld\n",
  96075. (og->header[9]<<24)|(og->header[8]<<16)|
  96076. (og->header[7]<<8)|og->header[6],
  96077. (og->header[17]<<24)|(og->header[16]<<16)|
  96078. (og->header[15]<<8)|og->header[14],
  96079. ((long)(og->header[21])<<24)|(og->header[20]<<16)|
  96080. (og->header[19]<<8)|og->header[18]);
  96081. fprintf(stderr," checksum: %02x:%02x:%02x:%02x\n segments: %d (",
  96082. (int)og->header[22],(int)og->header[23],
  96083. (int)og->header[24],(int)og->header[25],
  96084. (int)og->header[26]);
  96085. for(j=27;j<og->header_len;j++)
  96086. fprintf(stderr,"%d ",(int)og->header[j]);
  96087. fprintf(stderr,")\n\n");
  96088. }
  96089. void copy_page(ogg_page *og){
  96090. unsigned char *temp=_ogg_malloc(og->header_len);
  96091. memcpy(temp,og->header,og->header_len);
  96092. og->header=temp;
  96093. temp=_ogg_malloc(og->body_len);
  96094. memcpy(temp,og->body,og->body_len);
  96095. og->body=temp;
  96096. }
  96097. void free_page(ogg_page *og){
  96098. _ogg_free (og->header);
  96099. _ogg_free (og->body);
  96100. }
  96101. void error(void){
  96102. fprintf(stderr,"error!\n");
  96103. exit(1);
  96104. }
  96105. const int head1_0[] = {0x4f,0x67,0x67,0x53,0,0x06,
  96106. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96107. 0x01,0x02,0x03,0x04,0,0,0,0,
  96108. 0x15,0xed,0xec,0x91,
  96109. 1,
  96110. 17};
  96111. const int head1_1[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96112. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96113. 0x01,0x02,0x03,0x04,0,0,0,0,
  96114. 0x59,0x10,0x6c,0x2c,
  96115. 1,
  96116. 17};
  96117. const int head2_1[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96118. 0x07,0x18,0x00,0x00,0x00,0x00,0x00,0x00,
  96119. 0x01,0x02,0x03,0x04,1,0,0,0,
  96120. 0x89,0x33,0x85,0xce,
  96121. 13,
  96122. 254,255,0,255,1,255,245,255,255,0,
  96123. 255,255,90};
  96124. const int head1_2[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96125. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96126. 0x01,0x02,0x03,0x04,0,0,0,0,
  96127. 0xff,0x7b,0x23,0x17,
  96128. 1,
  96129. 0};
  96130. const int head2_2[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96131. 0x07,0x28,0x00,0x00,0x00,0x00,0x00,0x00,
  96132. 0x01,0x02,0x03,0x04,1,0,0,0,
  96133. 0x5c,0x3f,0x66,0xcb,
  96134. 17,
  96135. 17,254,255,0,0,255,1,0,255,245,255,255,0,
  96136. 255,255,90,0};
  96137. const int head1_3[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96138. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96139. 0x01,0x02,0x03,0x04,0,0,0,0,
  96140. 0x01,0x27,0x31,0xaa,
  96141. 18,
  96142. 255,255,255,255,255,255,255,255,
  96143. 255,255,255,255,255,255,255,255,255,10};
  96144. const int head2_3[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96145. 0x07,0x08,0x00,0x00,0x00,0x00,0x00,0x00,
  96146. 0x01,0x02,0x03,0x04,1,0,0,0,
  96147. 0x7f,0x4e,0x8a,0xd2,
  96148. 4,
  96149. 255,4,255,0};
  96150. const int head1_4[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96151. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96152. 0x01,0x02,0x03,0x04,0,0,0,0,
  96153. 0xff,0x7b,0x23,0x17,
  96154. 1,
  96155. 0};
  96156. const int head2_4[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96157. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  96158. 0x01,0x02,0x03,0x04,1,0,0,0,
  96159. 0x54,0x05,0x51,0xc8,
  96160. 17,
  96161. 255,255,255,255,255,255,255,255,
  96162. 255,255,255,255,255,255,255,255,255};
  96163. const int head3_4[] = {0x4f,0x67,0x67,0x53,0,0x05,
  96164. 0x07,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,
  96165. 0x01,0x02,0x03,0x04,2,0,0,0,
  96166. 0xc8,0xc3,0xcb,0xed,
  96167. 5,
  96168. 10,255,4,255,0};
  96169. const int head1_5[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96170. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96171. 0x01,0x02,0x03,0x04,0,0,0,0,
  96172. 0xff,0x7b,0x23,0x17,
  96173. 1,
  96174. 0};
  96175. const int head2_5[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96176. 0x07,0xfc,0x03,0x00,0x00,0x00,0x00,0x00,
  96177. 0x01,0x02,0x03,0x04,1,0,0,0,
  96178. 0xed,0x2a,0x2e,0xa7,
  96179. 255,
  96180. 10,10,10,10,10,10,10,10,
  96181. 10,10,10,10,10,10,10,10,
  96182. 10,10,10,10,10,10,10,10,
  96183. 10,10,10,10,10,10,10,10,
  96184. 10,10,10,10,10,10,10,10,
  96185. 10,10,10,10,10,10,10,10,
  96186. 10,10,10,10,10,10,10,10,
  96187. 10,10,10,10,10,10,10,10,
  96188. 10,10,10,10,10,10,10,10,
  96189. 10,10,10,10,10,10,10,10,
  96190. 10,10,10,10,10,10,10,10,
  96191. 10,10,10,10,10,10,10,10,
  96192. 10,10,10,10,10,10,10,10,
  96193. 10,10,10,10,10,10,10,10,
  96194. 10,10,10,10,10,10,10,10,
  96195. 10,10,10,10,10,10,10,10,
  96196. 10,10,10,10,10,10,10,10,
  96197. 10,10,10,10,10,10,10,10,
  96198. 10,10,10,10,10,10,10,10,
  96199. 10,10,10,10,10,10,10,10,
  96200. 10,10,10,10,10,10,10,10,
  96201. 10,10,10,10,10,10,10,10,
  96202. 10,10,10,10,10,10,10,10,
  96203. 10,10,10,10,10,10,10,10,
  96204. 10,10,10,10,10,10,10,10,
  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};
  96212. const int head3_5[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96213. 0x07,0x00,0x04,0x00,0x00,0x00,0x00,0x00,
  96214. 0x01,0x02,0x03,0x04,2,0,0,0,
  96215. 0x6c,0x3b,0x82,0x3d,
  96216. 1,
  96217. 50};
  96218. const int head1_6[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96219. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96220. 0x01,0x02,0x03,0x04,0,0,0,0,
  96221. 0xff,0x7b,0x23,0x17,
  96222. 1,
  96223. 0};
  96224. const int head2_6[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96225. 0x07,0x04,0x00,0x00,0x00,0x00,0x00,0x00,
  96226. 0x01,0x02,0x03,0x04,1,0,0,0,
  96227. 0x3c,0xd9,0x4d,0x3f,
  96228. 17,
  96229. 100,255,255,255,255,255,255,255,255,
  96230. 255,255,255,255,255,255,255,255};
  96231. const int head3_6[] = {0x4f,0x67,0x67,0x53,0,0x01,
  96232. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  96233. 0x01,0x02,0x03,0x04,2,0,0,0,
  96234. 0x01,0xd2,0xe5,0xe5,
  96235. 17,
  96236. 255,255,255,255,255,255,255,255,
  96237. 255,255,255,255,255,255,255,255,255};
  96238. const int head4_6[] = {0x4f,0x67,0x67,0x53,0,0x05,
  96239. 0x07,0x10,0x00,0x00,0x00,0x00,0x00,0x00,
  96240. 0x01,0x02,0x03,0x04,3,0,0,0,
  96241. 0xef,0xdd,0x88,0xde,
  96242. 7,
  96243. 255,255,75,255,4,255,0};
  96244. const int head1_7[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96245. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96246. 0x01,0x02,0x03,0x04,0,0,0,0,
  96247. 0xff,0x7b,0x23,0x17,
  96248. 1,
  96249. 0};
  96250. const int head2_7[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96251. 0x07,0x04,0x00,0x00,0x00,0x00,0x00,0x00,
  96252. 0x01,0x02,0x03,0x04,1,0,0,0,
  96253. 0x3c,0xd9,0x4d,0x3f,
  96254. 17,
  96255. 100,255,255,255,255,255,255,255,255,
  96256. 255,255,255,255,255,255,255,255};
  96257. const int head3_7[] = {0x4f,0x67,0x67,0x53,0,0x05,
  96258. 0x07,0x08,0x00,0x00,0x00,0x00,0x00,0x00,
  96259. 0x01,0x02,0x03,0x04,2,0,0,0,
  96260. 0xd4,0xe0,0x60,0xe5,
  96261. 1,0};
  96262. void test_pack(const int *pl, const int **headers, int byteskip,
  96263. int pageskip, int packetskip){
  96264. unsigned char *data=_ogg_malloc(1024*1024); /* for scripted test cases only */
  96265. long inptr=0;
  96266. long outptr=0;
  96267. long deptr=0;
  96268. long depacket=0;
  96269. long granule_pos=7,pageno=0;
  96270. int i,j,packets,pageout=pageskip;
  96271. int eosflag=0;
  96272. int bosflag=0;
  96273. int byteskipcount=0;
  96274. ogg_stream_reset(&os_en);
  96275. ogg_stream_reset(&os_de);
  96276. ogg_sync_reset(&oy);
  96277. for(packets=0;packets<packetskip;packets++)
  96278. depacket+=pl[packets];
  96279. for(packets=0;;packets++)if(pl[packets]==-1)break;
  96280. for(i=0;i<packets;i++){
  96281. ogg_packet op;
  96282. int len=pl[i];
  96283. op.packet=data+inptr;
  96284. op.bytes=len;
  96285. op.e_o_s=(pl[i+1]<0?1:0);
  96286. op.granulepos=granule_pos;
  96287. granule_pos+=1024;
  96288. for(j=0;j<len;j++)data[inptr++]=i+j;
  96289. ogg_stream_packetin(&os_en,&op);
  96290. {
  96291. ogg_page og;
  96292. while(ogg_stream_pageout(&os_en,&og)){
  96293. fprintf(stderr,"%ld, ",pageno);
  96294. if(headers[pageno]==NULL){
  96295. fprintf(stderr,"coded too many pages!\n");
  96296. exit(1);
  96297. }
  96298. check_page(data+outptr,headers[pageno],&og);
  96299. outptr+=og.body_len;
  96300. pageno++;
  96301. if(pageskip){
  96302. bosflag=1;
  96303. pageskip--;
  96304. deptr+=og.body_len;
  96305. }
  96306. {
  96307. ogg_page og_de;
  96308. ogg_packet op_de,op_de2;
  96309. char *buf=ogg_sync_buffer(&oy,og.header_len+og.body_len);
  96310. char *next=buf;
  96311. byteskipcount+=og.header_len;
  96312. if(byteskipcount>byteskip){
  96313. memcpy(next,og.header,byteskipcount-byteskip);
  96314. next+=byteskipcount-byteskip;
  96315. byteskipcount=byteskip;
  96316. }
  96317. byteskipcount+=og.body_len;
  96318. if(byteskipcount>byteskip){
  96319. memcpy(next,og.body,byteskipcount-byteskip);
  96320. next+=byteskipcount-byteskip;
  96321. byteskipcount=byteskip;
  96322. }
  96323. ogg_sync_wrote(&oy,next-buf);
  96324. while(1){
  96325. int ret=ogg_sync_pageout(&oy,&og_de);
  96326. if(ret==0)break;
  96327. if(ret<0)continue;
  96328. fprintf(stderr,"(%ld), ",pageout);
  96329. check_page(data+deptr,headers[pageout],&og_de);
  96330. deptr+=og_de.body_len;
  96331. pageout++;
  96332. ogg_stream_pagein(&os_de,&og_de);
  96333. while(ogg_stream_packetpeek(&os_de,&op_de2)>0){
  96334. ogg_stream_packetpeek(&os_de,NULL);
  96335. ogg_stream_packetout(&os_de,&op_de); /* just catching them all */
  96336. if(memcmp(&op_de,&op_de2,sizeof(op_de))){
  96337. fprintf(stderr,"packetout != packetpeek! pos=%ld\n",
  96338. depacket);
  96339. exit(1);
  96340. }
  96341. if(memcmp(data+depacket,op_de.packet,op_de.bytes)){
  96342. fprintf(stderr,"packet data mismatch in decode! pos=%ld\n",
  96343. depacket);
  96344. exit(1);
  96345. }
  96346. if(bosflag==0 && op_de.b_o_s==0){
  96347. fprintf(stderr,"b_o_s flag not set on packet!\n");
  96348. exit(1);
  96349. }
  96350. if(bosflag && op_de.b_o_s){
  96351. fprintf(stderr,"b_o_s flag incorrectly set on packet!\n");
  96352. exit(1);
  96353. }
  96354. bosflag=1;
  96355. depacket+=op_de.bytes;
  96356. if(eosflag){
  96357. fprintf(stderr,"Multiple decoded packets with eos flag!\n");
  96358. exit(1);
  96359. }
  96360. if(op_de.e_o_s)eosflag=1;
  96361. if(op_de.granulepos!=-1){
  96362. fprintf(stderr," granule:%ld ",(long)op_de.granulepos);
  96363. }
  96364. }
  96365. }
  96366. }
  96367. }
  96368. }
  96369. }
  96370. _ogg_free(data);
  96371. if(headers[pageno]!=NULL){
  96372. fprintf(stderr,"did not write last page!\n");
  96373. exit(1);
  96374. }
  96375. if(headers[pageout]!=NULL){
  96376. fprintf(stderr,"did not decode last page!\n");
  96377. exit(1);
  96378. }
  96379. if(inptr!=outptr){
  96380. fprintf(stderr,"encoded page data incomplete!\n");
  96381. exit(1);
  96382. }
  96383. if(inptr!=deptr){
  96384. fprintf(stderr,"decoded page data incomplete!\n");
  96385. exit(1);
  96386. }
  96387. if(inptr!=depacket){
  96388. fprintf(stderr,"decoded packet data incomplete!\n");
  96389. exit(1);
  96390. }
  96391. if(!eosflag){
  96392. fprintf(stderr,"Never got a packet with EOS set!\n");
  96393. exit(1);
  96394. }
  96395. fprintf(stderr,"ok.\n");
  96396. }
  96397. int main(void){
  96398. ogg_stream_init(&os_en,0x04030201);
  96399. ogg_stream_init(&os_de,0x04030201);
  96400. ogg_sync_init(&oy);
  96401. {
  96402. const int packets[]={17, -1};
  96403. const int *headret[]={head1_0,NULL};
  96404. fprintf(stderr,"testing single page encoding... ");
  96405. test_pack(packets,headret,0,0,0);
  96406. }
  96407. {
  96408. const int packets[]={17, 254, 255, 256, 500, 510, 600, -1};
  96409. const int *headret[]={head1_1,head2_1,NULL};
  96410. fprintf(stderr,"testing basic page encoding... ");
  96411. test_pack(packets,headret,0,0,0);
  96412. }
  96413. {
  96414. const int packets[]={0,17, 254, 255, 0, 256, 0, 500, 510, 600, 0, -1};
  96415. const int *headret[]={head1_2,head2_2,NULL};
  96416. fprintf(stderr,"testing basic nil packets... ");
  96417. test_pack(packets,headret,0,0,0);
  96418. }
  96419. {
  96420. const int packets[]={4345,259,255,-1};
  96421. const int *headret[]={head1_3,head2_3,NULL};
  96422. fprintf(stderr,"testing initial-packet lacing > 4k... ");
  96423. test_pack(packets,headret,0,0,0);
  96424. }
  96425. {
  96426. const int packets[]={0,4345,259,255,-1};
  96427. const int *headret[]={head1_4,head2_4,head3_4,NULL};
  96428. fprintf(stderr,"testing single packet page span... ");
  96429. test_pack(packets,headret,0,0,0);
  96430. }
  96431. {
  96432. const int packets[]={0,10,10,10,10,10,10,10,10,
  96433. 10,10,10,10,10,10,10,10,
  96434. 10,10,10,10,10,10,10,10,
  96435. 10,10,10,10,10,10,10,10,
  96436. 10,10,10,10,10,10,10,10,
  96437. 10,10,10,10,10,10,10,10,
  96438. 10,10,10,10,10,10,10,10,
  96439. 10,10,10,10,10,10,10,10,
  96440. 10,10,10,10,10,10,10,10,
  96441. 10,10,10,10,10,10,10,10,
  96442. 10,10,10,10,10,10,10,10,
  96443. 10,10,10,10,10,10,10,10,
  96444. 10,10,10,10,10,10,10,10,
  96445. 10,10,10,10,10,10,10,10,
  96446. 10,10,10,10,10,10,10,10,
  96447. 10,10,10,10,10,10,10,10,
  96448. 10,10,10,10,10,10,10,10,
  96449. 10,10,10,10,10,10,10,10,
  96450. 10,10,10,10,10,10,10,10,
  96451. 10,10,10,10,10,10,10,10,
  96452. 10,10,10,10,10,10,10,10,
  96453. 10,10,10,10,10,10,10,10,
  96454. 10,10,10,10,10,10,10,10,
  96455. 10,10,10,10,10,10,10,10,
  96456. 10,10,10,10,10,10,10,10,
  96457. 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,50,-1};
  96464. const int *headret[]={head1_5,head2_5,head3_5,NULL};
  96465. fprintf(stderr,"testing max packet segments... ");
  96466. test_pack(packets,headret,0,0,0);
  96467. }
  96468. {
  96469. const int packets[]={0,100,9000,259,255,-1};
  96470. const int *headret[]={head1_6,head2_6,head3_6,head4_6,NULL};
  96471. fprintf(stderr,"testing very large packets... ");
  96472. test_pack(packets,headret,0,0,0);
  96473. }
  96474. {
  96475. const int packets[]={0,100,9000,259,255,-1};
  96476. const int *headret[]={head1_6,head2_6,head3_6,head4_6,NULL};
  96477. fprintf(stderr,"testing continuation resync in very large packets... ");
  96478. test_pack(packets,headret,100,2,3);
  96479. }
  96480. {
  96481. const int packets[]={0,100,4080,-1};
  96482. const int *headret[]={head1_7,head2_7,head3_7,NULL};
  96483. fprintf(stderr,"testing zero data page (1 nil packet)... ");
  96484. test_pack(packets,headret,0,0,0);
  96485. }
  96486. {
  96487. unsigned char *data=_ogg_malloc(1024*1024);
  96488. int pl[]={0,100,4079,2956,2057,76,34,912,0,234,1000,1000,1000,300,-1};
  96489. int inptr=0,i,j;
  96490. ogg_page og[5];
  96491. ogg_stream_reset(&os_en);
  96492. for(i=0;pl[i]!=-1;i++){
  96493. ogg_packet op;
  96494. int len=pl[i];
  96495. op.packet=data+inptr;
  96496. op.bytes=len;
  96497. op.e_o_s=(pl[i+1]<0?1:0);
  96498. op.granulepos=(i+1)*1000;
  96499. for(j=0;j<len;j++)data[inptr++]=i+j;
  96500. ogg_stream_packetin(&os_en,&op);
  96501. }
  96502. _ogg_free(data);
  96503. for(i=0;i<5;i++){
  96504. if(ogg_stream_pageout(&os_en,&og[i])==0){
  96505. fprintf(stderr,"Too few pages output building sync tests!\n");
  96506. exit(1);
  96507. }
  96508. copy_page(&og[i]);
  96509. }
  96510. {
  96511. ogg_page temp;
  96512. ogg_packet test;
  96513. fprintf(stderr,"Testing loss of pages... ");
  96514. ogg_sync_reset(&oy);
  96515. ogg_stream_reset(&os_de);
  96516. for(i=0;i<5;i++){
  96517. memcpy(ogg_sync_buffer(&oy,og[i].header_len),og[i].header,
  96518. og[i].header_len);
  96519. ogg_sync_wrote(&oy,og[i].header_len);
  96520. memcpy(ogg_sync_buffer(&oy,og[i].body_len),og[i].body,og[i].body_len);
  96521. ogg_sync_wrote(&oy,og[i].body_len);
  96522. }
  96523. ogg_sync_pageout(&oy,&temp);
  96524. ogg_stream_pagein(&os_de,&temp);
  96525. ogg_sync_pageout(&oy,&temp);
  96526. ogg_stream_pagein(&os_de,&temp);
  96527. ogg_sync_pageout(&oy,&temp);
  96528. ogg_sync_pageout(&oy,&temp);
  96529. ogg_stream_pagein(&os_de,&temp);
  96530. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96531. checkpacket(&test,0,0,0);
  96532. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96533. checkpacket(&test,100,1,-1);
  96534. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96535. checkpacket(&test,4079,2,3000);
  96536. if(ogg_stream_packetout(&os_de,&test)!=-1){
  96537. fprintf(stderr,"Error: loss of page did not return error\n");
  96538. exit(1);
  96539. }
  96540. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96541. checkpacket(&test,76,5,-1);
  96542. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96543. checkpacket(&test,34,6,-1);
  96544. fprintf(stderr,"ok.\n");
  96545. }
  96546. {
  96547. ogg_page temp;
  96548. ogg_packet test;
  96549. fprintf(stderr,"Testing loss of pages (rollback required)... ");
  96550. ogg_sync_reset(&oy);
  96551. ogg_stream_reset(&os_de);
  96552. for(i=0;i<5;i++){
  96553. memcpy(ogg_sync_buffer(&oy,og[i].header_len),og[i].header,
  96554. og[i].header_len);
  96555. ogg_sync_wrote(&oy,og[i].header_len);
  96556. memcpy(ogg_sync_buffer(&oy,og[i].body_len),og[i].body,og[i].body_len);
  96557. ogg_sync_wrote(&oy,og[i].body_len);
  96558. }
  96559. ogg_sync_pageout(&oy,&temp);
  96560. ogg_stream_pagein(&os_de,&temp);
  96561. ogg_sync_pageout(&oy,&temp);
  96562. ogg_stream_pagein(&os_de,&temp);
  96563. ogg_sync_pageout(&oy,&temp);
  96564. ogg_stream_pagein(&os_de,&temp);
  96565. ogg_sync_pageout(&oy,&temp);
  96566. ogg_sync_pageout(&oy,&temp);
  96567. ogg_stream_pagein(&os_de,&temp);
  96568. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96569. checkpacket(&test,0,0,0);
  96570. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96571. checkpacket(&test,100,1,-1);
  96572. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96573. checkpacket(&test,4079,2,3000);
  96574. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96575. checkpacket(&test,2956,3,4000);
  96576. if(ogg_stream_packetout(&os_de,&test)!=-1){
  96577. fprintf(stderr,"Error: loss of page did not return error\n");
  96578. exit(1);
  96579. }
  96580. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96581. checkpacket(&test,300,13,14000);
  96582. fprintf(stderr,"ok.\n");
  96583. }
  96584. {
  96585. ogg_page og_de;
  96586. fprintf(stderr,"Testing sync on partial inputs... ");
  96587. ogg_sync_reset(&oy);
  96588. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96589. 3);
  96590. ogg_sync_wrote(&oy,3);
  96591. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96592. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+3,
  96593. 20);
  96594. ogg_sync_wrote(&oy,20);
  96595. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96596. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+23,
  96597. 5);
  96598. ogg_sync_wrote(&oy,5);
  96599. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96600. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+28,
  96601. og[1].header_len-28);
  96602. ogg_sync_wrote(&oy,og[1].header_len-28);
  96603. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96604. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,1000);
  96605. ogg_sync_wrote(&oy,1000);
  96606. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96607. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body+1000,
  96608. og[1].body_len-1000);
  96609. ogg_sync_wrote(&oy,og[1].body_len-1000);
  96610. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96611. fprintf(stderr,"ok.\n");
  96612. }
  96613. {
  96614. ogg_page og_de;
  96615. fprintf(stderr,"Testing sync on 1+partial inputs... ");
  96616. ogg_sync_reset(&oy);
  96617. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96618. og[1].header_len);
  96619. ogg_sync_wrote(&oy,og[1].header_len);
  96620. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96621. og[1].body_len);
  96622. ogg_sync_wrote(&oy,og[1].body_len);
  96623. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96624. 20);
  96625. ogg_sync_wrote(&oy,20);
  96626. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96627. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96628. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+20,
  96629. og[1].header_len-20);
  96630. ogg_sync_wrote(&oy,og[1].header_len-20);
  96631. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96632. og[1].body_len);
  96633. ogg_sync_wrote(&oy,og[1].body_len);
  96634. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96635. fprintf(stderr,"ok.\n");
  96636. }
  96637. {
  96638. ogg_page og_de;
  96639. fprintf(stderr,"Testing search for capture... ");
  96640. ogg_sync_reset(&oy);
  96641. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96642. og[1].body_len);
  96643. ogg_sync_wrote(&oy,og[1].body_len);
  96644. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96645. og[1].header_len);
  96646. ogg_sync_wrote(&oy,og[1].header_len);
  96647. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96648. og[1].body_len);
  96649. ogg_sync_wrote(&oy,og[1].body_len);
  96650. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,
  96651. 20);
  96652. ogg_sync_wrote(&oy,20);
  96653. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96654. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96655. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96656. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header+20,
  96657. og[2].header_len-20);
  96658. ogg_sync_wrote(&oy,og[2].header_len-20);
  96659. memcpy(ogg_sync_buffer(&oy,og[2].body_len),og[2].body,
  96660. og[2].body_len);
  96661. ogg_sync_wrote(&oy,og[2].body_len);
  96662. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96663. fprintf(stderr,"ok.\n");
  96664. }
  96665. {
  96666. ogg_page og_de;
  96667. fprintf(stderr,"Testing recapture... ");
  96668. ogg_sync_reset(&oy);
  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. og[2].header_len);
  96677. ogg_sync_wrote(&oy,og[2].header_len);
  96678. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,
  96679. og[2].header_len);
  96680. ogg_sync_wrote(&oy,og[2].header_len);
  96681. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96682. memcpy(ogg_sync_buffer(&oy,og[2].body_len),og[2].body,
  96683. og[2].body_len-5);
  96684. ogg_sync_wrote(&oy,og[2].body_len-5);
  96685. memcpy(ogg_sync_buffer(&oy,og[3].header_len),og[3].header,
  96686. og[3].header_len);
  96687. ogg_sync_wrote(&oy,og[3].header_len);
  96688. memcpy(ogg_sync_buffer(&oy,og[3].body_len),og[3].body,
  96689. og[3].body_len);
  96690. ogg_sync_wrote(&oy,og[3].body_len);
  96691. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96692. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96693. fprintf(stderr,"ok.\n");
  96694. }
  96695. {
  96696. for(i=0;i<5;i++){
  96697. free_page(&og[i]);
  96698. }
  96699. }
  96700. }
  96701. return(0);
  96702. }
  96703. #endif
  96704. #endif
  96705. /*** End of inlined file: framing.c ***/
  96706. /*** Start of inlined file: analysis.c ***/
  96707. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  96708. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  96709. // tasks..
  96710. #if JUCE_MSVC
  96711. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  96712. #endif
  96713. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  96714. #if JUCE_USE_OGGVORBIS
  96715. #include <stdio.h>
  96716. #include <string.h>
  96717. #include <math.h>
  96718. /*** Start of inlined file: codec_internal.h ***/
  96719. #ifndef _V_CODECI_H_
  96720. #define _V_CODECI_H_
  96721. /*** Start of inlined file: envelope.h ***/
  96722. #ifndef _V_ENVELOPE_
  96723. #define _V_ENVELOPE_
  96724. /*** Start of inlined file: mdct.h ***/
  96725. #ifndef _OGG_mdct_H_
  96726. #define _OGG_mdct_H_
  96727. #ifdef MDCT_INTEGERIZED
  96728. #define DATA_TYPE int
  96729. #define REG_TYPE register int
  96730. #define TRIGBITS 14
  96731. #define cPI3_8 6270
  96732. #define cPI2_8 11585
  96733. #define cPI1_8 15137
  96734. #define FLOAT_CONV(x) ((int)((x)*(1<<TRIGBITS)+.5))
  96735. #define MULT_NORM(x) ((x)>>TRIGBITS)
  96736. #define HALVE(x) ((x)>>1)
  96737. #else
  96738. #define DATA_TYPE float
  96739. #define REG_TYPE float
  96740. #define cPI3_8 .38268343236508977175F
  96741. #define cPI2_8 .70710678118654752441F
  96742. #define cPI1_8 .92387953251128675613F
  96743. #define FLOAT_CONV(x) (x)
  96744. #define MULT_NORM(x) (x)
  96745. #define HALVE(x) ((x)*.5f)
  96746. #endif
  96747. typedef struct {
  96748. int n;
  96749. int log2n;
  96750. DATA_TYPE *trig;
  96751. int *bitrev;
  96752. DATA_TYPE scale;
  96753. } mdct_lookup;
  96754. extern void mdct_init(mdct_lookup *lookup,int n);
  96755. extern void mdct_clear(mdct_lookup *l);
  96756. extern void mdct_forward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out);
  96757. extern void mdct_backward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out);
  96758. #endif
  96759. /*** End of inlined file: mdct.h ***/
  96760. #define VE_PRE 16
  96761. #define VE_WIN 4
  96762. #define VE_POST 2
  96763. #define VE_AMP (VE_PRE+VE_POST-1)
  96764. #define VE_BANDS 7
  96765. #define VE_NEARDC 15
  96766. #define VE_MINSTRETCH 2 /* a bit less than short block */
  96767. #define VE_MAXSTRETCH 12 /* one-third full block */
  96768. typedef struct {
  96769. float ampbuf[VE_AMP];
  96770. int ampptr;
  96771. float nearDC[VE_NEARDC];
  96772. float nearDC_acc;
  96773. float nearDC_partialacc;
  96774. int nearptr;
  96775. } envelope_filter_state;
  96776. typedef struct {
  96777. int begin;
  96778. int end;
  96779. float *window;
  96780. float total;
  96781. } envelope_band;
  96782. typedef struct {
  96783. int ch;
  96784. int winlength;
  96785. int searchstep;
  96786. float minenergy;
  96787. mdct_lookup mdct;
  96788. float *mdct_win;
  96789. envelope_band band[VE_BANDS];
  96790. envelope_filter_state *filter;
  96791. int stretch;
  96792. int *mark;
  96793. long storage;
  96794. long current;
  96795. long curmark;
  96796. long cursor;
  96797. } envelope_lookup;
  96798. extern void _ve_envelope_init(envelope_lookup *e,vorbis_info *vi);
  96799. extern void _ve_envelope_clear(envelope_lookup *e);
  96800. extern long _ve_envelope_search(vorbis_dsp_state *v);
  96801. extern void _ve_envelope_shift(envelope_lookup *e,long shift);
  96802. extern int _ve_envelope_mark(vorbis_dsp_state *v);
  96803. #endif
  96804. /*** End of inlined file: envelope.h ***/
  96805. /*** Start of inlined file: codebook.h ***/
  96806. #ifndef _V_CODEBOOK_H_
  96807. #define _V_CODEBOOK_H_
  96808. typedef struct static_codebook{
  96809. long dim; /* codebook dimensions (elements per vector) */
  96810. long entries; /* codebook entries */
  96811. long *lengthlist; /* codeword lengths in bits */
  96812. int maptype; /* 0=none
  96813. 1=implicitly populated values from map column
  96814. 2=listed arbitrary values */
  96815. long q_min; /* packed 32 bit float; quant value 0 maps to minval */
  96816. long q_delta; /* packed 32 bit float; val 1 - val 0 == delta */
  96817. int q_quant; /* bits: 0 < quant <= 16 */
  96818. int q_sequencep; /* bitflag */
  96819. long *quantlist; /* map == 1: (int)(entries^(1/dim)) element column map
  96820. map == 2: list of dim*entries quantized entry vals
  96821. */
  96822. struct encode_aux_nearestmatch *nearest_tree;
  96823. struct encode_aux_threshmatch *thresh_tree;
  96824. struct encode_aux_pigeonhole *pigeon_tree;
  96825. int allocedp;
  96826. } static_codebook;
  96827. typedef struct encode_aux_nearestmatch{
  96828. long *ptr0;
  96829. long *ptr1;
  96830. long *p; /* decision points (each is an entry) */
  96831. long *q; /* decision points (each is an entry) */
  96832. long aux; /* number of tree entries */
  96833. long alloc;
  96834. } encode_aux_nearestmatch;
  96835. typedef struct encode_aux_threshmatch{
  96836. float *quantthresh;
  96837. long *quantmap;
  96838. int quantvals;
  96839. int threshvals;
  96840. } encode_aux_threshmatch;
  96841. typedef struct encode_aux_pigeonhole{
  96842. float min;
  96843. float del;
  96844. int mapentries;
  96845. int quantvals;
  96846. long *pigeonmap;
  96847. long fittotal;
  96848. long *fitlist;
  96849. long *fitmap;
  96850. long *fitlength;
  96851. } encode_aux_pigeonhole;
  96852. typedef struct codebook{
  96853. long dim; /* codebook dimensions (elements per vector) */
  96854. long entries; /* codebook entries */
  96855. long used_entries; /* populated codebook entries */
  96856. const static_codebook *c;
  96857. float *valuelist; /* list of dim*entries actual entry values */
  96858. ogg_uint32_t *codelist; /* list of bitstream codewords for each entry */
  96859. int *dec_index; /* only used if sparseness collapsed */
  96860. char *dec_codelengths;
  96861. ogg_uint32_t *dec_firsttable;
  96862. int dec_firsttablen;
  96863. int dec_maxlength;
  96864. } codebook;
  96865. extern void vorbis_staticbook_clear(static_codebook *b);
  96866. extern void vorbis_staticbook_destroy(static_codebook *b);
  96867. extern int vorbis_book_init_encode(codebook *dest,const static_codebook *source);
  96868. extern int vorbis_book_init_decode(codebook *dest,const static_codebook *source);
  96869. extern void vorbis_book_clear(codebook *b);
  96870. extern float *_book_unquantize(const static_codebook *b,int n,int *map);
  96871. extern float *_book_logdist(const static_codebook *b,float *vals);
  96872. extern float _float32_unpack(long val);
  96873. extern long _float32_pack(float val);
  96874. extern int _best(codebook *book, float *a, int step);
  96875. extern int _ilog(unsigned int v);
  96876. extern long _book_maptype1_quantvals(const static_codebook *b);
  96877. extern int vorbis_book_besterror(codebook *book,float *a,int step,int addmul);
  96878. extern long vorbis_book_codeword(codebook *book,int entry);
  96879. extern long vorbis_book_codelen(codebook *book,int entry);
  96880. extern int vorbis_staticbook_pack(const static_codebook *c,oggpack_buffer *b);
  96881. extern int vorbis_staticbook_unpack(oggpack_buffer *b,static_codebook *c);
  96882. extern int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b);
  96883. extern int vorbis_book_errorv(codebook *book, float *a);
  96884. extern int vorbis_book_encodev(codebook *book, int best,float *a,
  96885. oggpack_buffer *b);
  96886. extern long vorbis_book_decode(codebook *book, oggpack_buffer *b);
  96887. extern long vorbis_book_decodevs_add(codebook *book, float *a,
  96888. oggpack_buffer *b,int n);
  96889. extern long vorbis_book_decodev_set(codebook *book, float *a,
  96890. oggpack_buffer *b,int n);
  96891. extern long vorbis_book_decodev_add(codebook *book, float *a,
  96892. oggpack_buffer *b,int n);
  96893. extern long vorbis_book_decodevv_add(codebook *book, float **a,
  96894. long off,int ch,
  96895. oggpack_buffer *b,int n);
  96896. #endif
  96897. /*** End of inlined file: codebook.h ***/
  96898. #define BLOCKTYPE_IMPULSE 0
  96899. #define BLOCKTYPE_PADDING 1
  96900. #define BLOCKTYPE_TRANSITION 0
  96901. #define BLOCKTYPE_LONG 1
  96902. #define PACKETBLOBS 15
  96903. typedef struct vorbis_block_internal{
  96904. float **pcmdelay; /* this is a pointer into local storage */
  96905. float ampmax;
  96906. int blocktype;
  96907. oggpack_buffer *packetblob[PACKETBLOBS]; /* initialized, must be freed;
  96908. blob [PACKETBLOBS/2] points to
  96909. the oggpack_buffer in the
  96910. main vorbis_block */
  96911. } vorbis_block_internal;
  96912. typedef void vorbis_look_floor;
  96913. typedef void vorbis_look_residue;
  96914. typedef void vorbis_look_transform;
  96915. typedef struct {
  96916. int blockflag;
  96917. int windowtype;
  96918. int transformtype;
  96919. int mapping;
  96920. } vorbis_info_mode;
  96921. typedef void vorbis_info_floor;
  96922. typedef void vorbis_info_residue;
  96923. typedef void vorbis_info_mapping;
  96924. /*** Start of inlined file: psy.h ***/
  96925. #ifndef _V_PSY_H_
  96926. #define _V_PSY_H_
  96927. /*** Start of inlined file: smallft.h ***/
  96928. #ifndef _V_SMFT_H_
  96929. #define _V_SMFT_H_
  96930. typedef struct {
  96931. int n;
  96932. float *trigcache;
  96933. int *splitcache;
  96934. } drft_lookup;
  96935. extern void drft_forward(drft_lookup *l,float *data);
  96936. extern void drft_backward(drft_lookup *l,float *data);
  96937. extern void drft_init(drft_lookup *l,int n);
  96938. extern void drft_clear(drft_lookup *l);
  96939. #endif
  96940. /*** End of inlined file: smallft.h ***/
  96941. /*** Start of inlined file: backends.h ***/
  96942. #ifndef _vorbis_backend_h_
  96943. #define _vorbis_backend_h_
  96944. typedef struct{
  96945. void (*pack) (vorbis_info_floor *,oggpack_buffer *);
  96946. vorbis_info_floor *(*unpack)(vorbis_info *,oggpack_buffer *);
  96947. vorbis_look_floor *(*look) (vorbis_dsp_state *,vorbis_info_floor *);
  96948. void (*free_info) (vorbis_info_floor *);
  96949. void (*free_look) (vorbis_look_floor *);
  96950. void *(*inverse1) (struct vorbis_block *,vorbis_look_floor *);
  96951. int (*inverse2) (struct vorbis_block *,vorbis_look_floor *,
  96952. void *buffer,float *);
  96953. } vorbis_func_floor;
  96954. typedef struct{
  96955. int order;
  96956. long rate;
  96957. long barkmap;
  96958. int ampbits;
  96959. int ampdB;
  96960. int numbooks; /* <= 16 */
  96961. int books[16];
  96962. float lessthan; /* encode-only config setting hacks for libvorbis */
  96963. float greaterthan; /* encode-only config setting hacks for libvorbis */
  96964. } vorbis_info_floor0;
  96965. #define VIF_POSIT 63
  96966. #define VIF_CLASS 16
  96967. #define VIF_PARTS 31
  96968. typedef struct{
  96969. int partitions; /* 0 to 31 */
  96970. int partitionclass[VIF_PARTS]; /* 0 to 15 */
  96971. int class_dim[VIF_CLASS]; /* 1 to 8 */
  96972. int class_subs[VIF_CLASS]; /* 0,1,2,3 (bits: 1<<n poss) */
  96973. int class_book[VIF_CLASS]; /* subs ^ dim entries */
  96974. int class_subbook[VIF_CLASS][8]; /* [VIF_CLASS][subs] */
  96975. int mult; /* 1 2 3 or 4 */
  96976. int postlist[VIF_POSIT+2]; /* first two implicit */
  96977. float maxover;
  96978. float maxunder;
  96979. float maxerr;
  96980. float twofitweight;
  96981. float twofitatten;
  96982. int n;
  96983. } vorbis_info_floor1;
  96984. typedef struct{
  96985. void (*pack) (vorbis_info_residue *,oggpack_buffer *);
  96986. vorbis_info_residue *(*unpack)(vorbis_info *,oggpack_buffer *);
  96987. vorbis_look_residue *(*look) (vorbis_dsp_state *,
  96988. vorbis_info_residue *);
  96989. void (*free_info) (vorbis_info_residue *);
  96990. void (*free_look) (vorbis_look_residue *);
  96991. long **(*classx) (struct vorbis_block *,vorbis_look_residue *,
  96992. float **,int *,int);
  96993. int (*forward) (oggpack_buffer *,struct vorbis_block *,
  96994. vorbis_look_residue *,
  96995. float **,float **,int *,int,long **);
  96996. int (*inverse) (struct vorbis_block *,vorbis_look_residue *,
  96997. float **,int *,int);
  96998. } vorbis_func_residue;
  96999. typedef struct vorbis_info_residue0{
  97000. long begin;
  97001. long end;
  97002. int grouping; /* group n vectors per partition */
  97003. int partitions; /* possible codebooks for a partition */
  97004. int groupbook; /* huffbook for partitioning */
  97005. int secondstages[64]; /* expanded out to pointers in lookup */
  97006. int booklist[256]; /* list of second stage books */
  97007. float classmetric1[64];
  97008. float classmetric2[64];
  97009. } vorbis_info_residue0;
  97010. typedef struct{
  97011. void (*pack) (vorbis_info *,vorbis_info_mapping *,
  97012. oggpack_buffer *);
  97013. vorbis_info_mapping *(*unpack)(vorbis_info *,oggpack_buffer *);
  97014. void (*free_info) (vorbis_info_mapping *);
  97015. int (*forward) (struct vorbis_block *vb);
  97016. int (*inverse) (struct vorbis_block *vb,vorbis_info_mapping *);
  97017. } vorbis_func_mapping;
  97018. typedef struct vorbis_info_mapping0{
  97019. int submaps; /* <= 16 */
  97020. int chmuxlist[256]; /* up to 256 channels in a Vorbis stream */
  97021. int floorsubmap[16]; /* [mux] submap to floors */
  97022. int residuesubmap[16]; /* [mux] submap to residue */
  97023. int coupling_steps;
  97024. int coupling_mag[256];
  97025. int coupling_ang[256];
  97026. } vorbis_info_mapping0;
  97027. #endif
  97028. /*** End of inlined file: backends.h ***/
  97029. #ifndef EHMER_MAX
  97030. #define EHMER_MAX 56
  97031. #endif
  97032. #define P_BANDS 17 /* 62Hz to 16kHz */
  97033. #define P_LEVELS 8 /* 30dB to 100dB */
  97034. #define P_LEVEL_0 30. /* 30 dB */
  97035. #define P_NOISECURVES 3
  97036. #define NOISE_COMPAND_LEVELS 40
  97037. typedef struct vorbis_info_psy{
  97038. int blockflag;
  97039. float ath_adjatt;
  97040. float ath_maxatt;
  97041. float tone_masteratt[P_NOISECURVES];
  97042. float tone_centerboost;
  97043. float tone_decay;
  97044. float tone_abs_limit;
  97045. float toneatt[P_BANDS];
  97046. int noisemaskp;
  97047. float noisemaxsupp;
  97048. float noisewindowlo;
  97049. float noisewindowhi;
  97050. int noisewindowlomin;
  97051. int noisewindowhimin;
  97052. int noisewindowfixed;
  97053. float noiseoff[P_NOISECURVES][P_BANDS];
  97054. float noisecompand[NOISE_COMPAND_LEVELS];
  97055. float max_curve_dB;
  97056. int normal_channel_p;
  97057. int normal_point_p;
  97058. int normal_start;
  97059. int normal_partition;
  97060. double normal_thresh;
  97061. } vorbis_info_psy;
  97062. typedef struct{
  97063. int eighth_octave_lines;
  97064. float preecho_thresh[VE_BANDS];
  97065. float postecho_thresh[VE_BANDS];
  97066. float stretch_penalty;
  97067. float preecho_minenergy;
  97068. float ampmax_att_per_sec;
  97069. int coupling_pkHz[PACKETBLOBS];
  97070. int coupling_pointlimit[2][PACKETBLOBS];
  97071. int coupling_prepointamp[PACKETBLOBS];
  97072. int coupling_postpointamp[PACKETBLOBS];
  97073. int sliding_lowpass[2][PACKETBLOBS];
  97074. } vorbis_info_psy_global;
  97075. typedef struct {
  97076. float ampmax;
  97077. int channels;
  97078. vorbis_info_psy_global *gi;
  97079. int coupling_pointlimit[2][P_NOISECURVES];
  97080. } vorbis_look_psy_global;
  97081. typedef struct {
  97082. int n;
  97083. struct vorbis_info_psy *vi;
  97084. float ***tonecurves;
  97085. float **noiseoffset;
  97086. float *ath;
  97087. long *octave; /* in n.ocshift format */
  97088. long *bark;
  97089. long firstoc;
  97090. long shiftoc;
  97091. int eighth_octave_lines; /* power of two, please */
  97092. int total_octave_lines;
  97093. long rate; /* cache it */
  97094. float m_val; /* Masking compensation value */
  97095. } vorbis_look_psy;
  97096. extern void _vp_psy_init(vorbis_look_psy *p,vorbis_info_psy *vi,
  97097. vorbis_info_psy_global *gi,int n,long rate);
  97098. extern void _vp_psy_clear(vorbis_look_psy *p);
  97099. extern void *_vi_psy_dup(void *source);
  97100. extern void _vi_psy_free(vorbis_info_psy *i);
  97101. extern vorbis_info_psy *_vi_psy_copy(vorbis_info_psy *i);
  97102. extern void _vp_remove_floor(vorbis_look_psy *p,
  97103. float *mdct,
  97104. int *icodedflr,
  97105. float *residue,
  97106. int sliding_lowpass);
  97107. extern void _vp_noisemask(vorbis_look_psy *p,
  97108. float *logmdct,
  97109. float *logmask);
  97110. extern void _vp_tonemask(vorbis_look_psy *p,
  97111. float *logfft,
  97112. float *logmask,
  97113. float global_specmax,
  97114. float local_specmax);
  97115. extern void _vp_offset_and_mix(vorbis_look_psy *p,
  97116. float *noise,
  97117. float *tone,
  97118. int offset_select,
  97119. float *logmask,
  97120. float *mdct,
  97121. float *logmdct);
  97122. extern float _vp_ampmax_decay(float amp,vorbis_dsp_state *vd);
  97123. extern float **_vp_quantize_couple_memo(vorbis_block *vb,
  97124. vorbis_info_psy_global *g,
  97125. vorbis_look_psy *p,
  97126. vorbis_info_mapping0 *vi,
  97127. float **mdct);
  97128. extern void _vp_couple(int blobno,
  97129. vorbis_info_psy_global *g,
  97130. vorbis_look_psy *p,
  97131. vorbis_info_mapping0 *vi,
  97132. float **res,
  97133. float **mag_memo,
  97134. int **mag_sort,
  97135. int **ifloor,
  97136. int *nonzero,
  97137. int sliding_lowpass);
  97138. extern void _vp_noise_normalize(vorbis_look_psy *p,
  97139. float *in,float *out,int *sortedindex);
  97140. extern void _vp_noise_normalize_sort(vorbis_look_psy *p,
  97141. float *magnitudes,int *sortedindex);
  97142. extern int **_vp_quantize_couple_sort(vorbis_block *vb,
  97143. vorbis_look_psy *p,
  97144. vorbis_info_mapping0 *vi,
  97145. float **mags);
  97146. extern void hf_reduction(vorbis_info_psy_global *g,
  97147. vorbis_look_psy *p,
  97148. vorbis_info_mapping0 *vi,
  97149. float **mdct);
  97150. #endif
  97151. /*** End of inlined file: psy.h ***/
  97152. /*** Start of inlined file: bitrate.h ***/
  97153. #ifndef _V_BITRATE_H_
  97154. #define _V_BITRATE_H_
  97155. /*** Start of inlined file: os.h ***/
  97156. #ifndef _OS_H
  97157. #define _OS_H
  97158. #ifdef HAVE_CONFIG_H
  97159. #include "config.h"
  97160. #endif
  97161. #include <math.h>
  97162. /*** Start of inlined file: misc.h ***/
  97163. #ifndef _V_RANDOM_H_
  97164. #define _V_RANDOM_H_
  97165. extern int analysis_noisy;
  97166. extern void *_vorbis_block_alloc(vorbis_block *vb,long bytes);
  97167. extern void _vorbis_block_ripcord(vorbis_block *vb);
  97168. extern void _analysis_output(char *base,int i,float *v,int n,int bark,int dB,
  97169. ogg_int64_t off);
  97170. #ifdef DEBUG_MALLOC
  97171. #define _VDBG_GRAPHFILE "malloc.m"
  97172. extern void *_VDBG_malloc(void *ptr,long bytes,char *file,long line);
  97173. extern void _VDBG_free(void *ptr,char *file,long line);
  97174. #ifndef MISC_C
  97175. #undef _ogg_malloc
  97176. #undef _ogg_calloc
  97177. #undef _ogg_realloc
  97178. #undef _ogg_free
  97179. #define _ogg_malloc(x) _VDBG_malloc(NULL,(x),__FILE__,__LINE__)
  97180. #define _ogg_calloc(x,y) _VDBG_malloc(NULL,(x)*(y),__FILE__,__LINE__)
  97181. #define _ogg_realloc(x,y) _VDBG_malloc((x),(y),__FILE__,__LINE__)
  97182. #define _ogg_free(x) _VDBG_free((x),__FILE__,__LINE__)
  97183. #endif
  97184. #endif
  97185. #endif
  97186. /*** End of inlined file: misc.h ***/
  97187. #ifndef _V_IFDEFJAIL_H_
  97188. # define _V_IFDEFJAIL_H_
  97189. # ifdef __GNUC__
  97190. # define STIN static __inline__
  97191. # elif _WIN32
  97192. # define STIN static __inline
  97193. # else
  97194. # define STIN static
  97195. # endif
  97196. #ifdef DJGPP
  97197. # define rint(x) (floor((x)+0.5f))
  97198. #endif
  97199. #ifndef M_PI
  97200. # define M_PI (3.1415926536f)
  97201. #endif
  97202. #if defined(_WIN32) && !defined(__SYMBIAN32__)
  97203. # include <malloc.h>
  97204. # define rint(x) (floor((x)+0.5f))
  97205. # define NO_FLOAT_MATH_LIB
  97206. # define FAST_HYPOT(a, b) sqrt((a)*(a) + (b)*(b))
  97207. #endif
  97208. #if defined(__SYMBIAN32__) && defined(__WINS__)
  97209. void *_alloca(size_t size);
  97210. # define alloca _alloca
  97211. #endif
  97212. #ifndef FAST_HYPOT
  97213. # define FAST_HYPOT hypot
  97214. #endif
  97215. #endif
  97216. #ifdef HAVE_ALLOCA_H
  97217. # include <alloca.h>
  97218. #endif
  97219. #ifdef USE_MEMORY_H
  97220. # include <memory.h>
  97221. #endif
  97222. #ifndef min
  97223. # define min(x,y) ((x)>(y)?(y):(x))
  97224. #endif
  97225. #ifndef max
  97226. # define max(x,y) ((x)<(y)?(y):(x))
  97227. #endif
  97228. #if defined(__i386__) && defined(__GNUC__) && !defined(__BEOS__)
  97229. # define VORBIS_FPU_CONTROL
  97230. typedef ogg_int16_t vorbis_fpu_control;
  97231. static inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
  97232. ogg_int16_t ret;
  97233. ogg_int16_t temp;
  97234. __asm__ __volatile__("fnstcw %0\n\t"
  97235. "movw %0,%%dx\n\t"
  97236. "orw $62463,%%dx\n\t"
  97237. "movw %%dx,%1\n\t"
  97238. "fldcw %1\n\t":"=m"(ret):"m"(temp): "dx");
  97239. *fpu=ret;
  97240. }
  97241. static inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
  97242. __asm__ __volatile__("fldcw %0":: "m"(fpu));
  97243. }
  97244. static inline int vorbis_ftoi(double f){ /* yes, double! Otherwise,
  97245. we get extra fst/fld to
  97246. truncate precision */
  97247. int i;
  97248. __asm__("fistl %0": "=m"(i) : "t"(f));
  97249. return(i);
  97250. }
  97251. #endif
  97252. #if defined(_WIN32) && defined(_X86_) && !defined(__GNUC__) && !defined(__BORLANDC__)
  97253. # define VORBIS_FPU_CONTROL
  97254. typedef ogg_int16_t vorbis_fpu_control;
  97255. static __inline int vorbis_ftoi(double f){
  97256. int i;
  97257. __asm{
  97258. fld f
  97259. fistp i
  97260. }
  97261. return i;
  97262. }
  97263. static __inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
  97264. }
  97265. static __inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
  97266. }
  97267. #endif
  97268. #ifndef VORBIS_FPU_CONTROL
  97269. typedef int vorbis_fpu_control;
  97270. static int vorbis_ftoi(double f){
  97271. return (int)(f+.5);
  97272. }
  97273. # define vorbis_fpu_setround(vorbis_fpu_control) {}
  97274. # define vorbis_fpu_restore(vorbis_fpu_control) {}
  97275. #endif
  97276. #endif /* _OS_H */
  97277. /*** End of inlined file: os.h ***/
  97278. typedef struct bitrate_manager_state {
  97279. int managed;
  97280. long avg_reservoir;
  97281. long minmax_reservoir;
  97282. long avg_bitsper;
  97283. long min_bitsper;
  97284. long max_bitsper;
  97285. long short_per_long;
  97286. double avgfloat;
  97287. vorbis_block *vb;
  97288. int choice;
  97289. } bitrate_manager_state;
  97290. typedef struct bitrate_manager_info{
  97291. long avg_rate;
  97292. long min_rate;
  97293. long max_rate;
  97294. long reservoir_bits;
  97295. double reservoir_bias;
  97296. double slew_damp;
  97297. } bitrate_manager_info;
  97298. extern void vorbis_bitrate_init(vorbis_info *vi,bitrate_manager_state *bs);
  97299. extern void vorbis_bitrate_clear(bitrate_manager_state *bs);
  97300. extern int vorbis_bitrate_managed(vorbis_block *vb);
  97301. extern int vorbis_bitrate_addblock(vorbis_block *vb);
  97302. extern int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd, ogg_packet *op);
  97303. #endif
  97304. /*** End of inlined file: bitrate.h ***/
  97305. static int ilog(unsigned int v){
  97306. int ret=0;
  97307. while(v){
  97308. ret++;
  97309. v>>=1;
  97310. }
  97311. return(ret);
  97312. }
  97313. static int ilog2(unsigned int v){
  97314. int ret=0;
  97315. if(v)--v;
  97316. while(v){
  97317. ret++;
  97318. v>>=1;
  97319. }
  97320. return(ret);
  97321. }
  97322. typedef struct private_state {
  97323. envelope_lookup *ve; /* envelope lookup */
  97324. int window[2];
  97325. vorbis_look_transform **transform[2]; /* block, type */
  97326. drft_lookup fft_look[2];
  97327. int modebits;
  97328. vorbis_look_floor **flr;
  97329. vorbis_look_residue **residue;
  97330. vorbis_look_psy *psy;
  97331. vorbis_look_psy_global *psy_g_look;
  97332. unsigned char *header;
  97333. unsigned char *header1;
  97334. unsigned char *header2;
  97335. bitrate_manager_state bms;
  97336. ogg_int64_t sample_count;
  97337. } private_state;
  97338. /*** Start of inlined file: highlevel.h ***/
  97339. typedef struct highlevel_byblocktype {
  97340. double tone_mask_setting;
  97341. double tone_peaklimit_setting;
  97342. double noise_bias_setting;
  97343. double noise_compand_setting;
  97344. } highlevel_byblocktype;
  97345. typedef struct highlevel_encode_setup {
  97346. void *setup;
  97347. int set_in_stone;
  97348. double base_setting;
  97349. double long_setting;
  97350. double short_setting;
  97351. double impulse_noisetune;
  97352. int managed;
  97353. long bitrate_min;
  97354. long bitrate_av;
  97355. double bitrate_av_damp;
  97356. long bitrate_max;
  97357. long bitrate_reservoir;
  97358. double bitrate_reservoir_bias;
  97359. int impulse_block_p;
  97360. int noise_normalize_p;
  97361. double stereo_point_setting;
  97362. double lowpass_kHz;
  97363. double ath_floating_dB;
  97364. double ath_absolute_dB;
  97365. double amplitude_track_dBpersec;
  97366. double trigger_setting;
  97367. highlevel_byblocktype block[4]; /* padding, impulse, transition, long */
  97368. } highlevel_encode_setup;
  97369. /*** End of inlined file: highlevel.h ***/
  97370. typedef struct codec_setup_info {
  97371. long blocksizes[2];
  97372. int modes;
  97373. int maps;
  97374. int floors;
  97375. int residues;
  97376. int books;
  97377. int psys; /* encode only */
  97378. vorbis_info_mode *mode_param[64];
  97379. int map_type[64];
  97380. vorbis_info_mapping *map_param[64];
  97381. int floor_type[64];
  97382. vorbis_info_floor *floor_param[64];
  97383. int residue_type[64];
  97384. vorbis_info_residue *residue_param[64];
  97385. static_codebook *book_param[256];
  97386. codebook *fullbooks;
  97387. vorbis_info_psy *psy_param[4]; /* encode only */
  97388. vorbis_info_psy_global psy_g_param;
  97389. bitrate_manager_info bi;
  97390. highlevel_encode_setup hi; /* used only by vorbisenc.c. It's a
  97391. highly redundant structure, but
  97392. improves clarity of program flow. */
  97393. int halfrate_flag; /* painless downsample for decode */
  97394. } codec_setup_info;
  97395. extern vorbis_look_psy_global *_vp_global_look(vorbis_info *vi);
  97396. extern void _vp_global_free(vorbis_look_psy_global *look);
  97397. #endif
  97398. /*** End of inlined file: codec_internal.h ***/
  97399. /*** Start of inlined file: registry.h ***/
  97400. #ifndef _V_REG_H_
  97401. #define _V_REG_H_
  97402. #define VI_TRANSFORMB 1
  97403. #define VI_WINDOWB 1
  97404. #define VI_TIMEB 1
  97405. #define VI_FLOORB 2
  97406. #define VI_RESB 3
  97407. #define VI_MAPB 1
  97408. extern vorbis_func_floor *_floor_P[];
  97409. extern vorbis_func_residue *_residue_P[];
  97410. extern vorbis_func_mapping *_mapping_P[];
  97411. #endif
  97412. /*** End of inlined file: registry.h ***/
  97413. /*** Start of inlined file: scales.h ***/
  97414. #ifndef _V_SCALES_H_
  97415. #define _V_SCALES_H_
  97416. #include <math.h>
  97417. #define VORBIS_IEEE_FLOAT32 1
  97418. #ifdef VORBIS_IEEE_FLOAT32
  97419. static float unitnorm(float x){
  97420. union {
  97421. ogg_uint32_t i;
  97422. float f;
  97423. } ix;
  97424. ix.f = x;
  97425. ix.i = (ix.i & 0x80000000U) | (0x3f800000U);
  97426. return ix.f;
  97427. }
  97428. static float todB(const float *x){
  97429. union {
  97430. ogg_uint32_t i;
  97431. float f;
  97432. } ix;
  97433. ix.f = *x;
  97434. ix.i = ix.i&0x7fffffff;
  97435. return (float)(ix.i * 7.17711438e-7f -764.6161886f);
  97436. }
  97437. #define todB_nn(x) todB(x)
  97438. #else
  97439. static float unitnorm(float x){
  97440. if(x<0)return(-1.f);
  97441. return(1.f);
  97442. }
  97443. #define todB(x) (*(x)==0?-400.f:log(*(x)**(x))*4.34294480f)
  97444. #define todB_nn(x) (*(x)==0.f?-400.f:log(*(x))*8.6858896f)
  97445. #endif
  97446. #define fromdB(x) (exp((x)*.11512925f))
  97447. #define toBARK(n) (13.1f*atan(.00074f*(n))+2.24f*atan((n)*(n)*1.85e-8f)+1e-4f*(n))
  97448. #define fromBARK(z) (102.f*(z)-2.f*pow(z,2.f)+.4f*pow(z,3.f)+pow(1.46f,z)-1.f)
  97449. #define toMEL(n) (log(1.f+(n)*.001f)*1442.695f)
  97450. #define fromMEL(m) (1000.f*exp((m)/1442.695f)-1000.f)
  97451. #define toOC(n) (log(n)*1.442695f-5.965784f)
  97452. #define fromOC(o) (exp(((o)+5.965784f)*.693147f))
  97453. #endif
  97454. /*** End of inlined file: scales.h ***/
  97455. int analysis_noisy=1;
  97456. int vorbis_analysis(vorbis_block *vb, ogg_packet *op){
  97457. int ret,i;
  97458. vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
  97459. vb->glue_bits=0;
  97460. vb->time_bits=0;
  97461. vb->floor_bits=0;
  97462. vb->res_bits=0;
  97463. for(i=0;i<PACKETBLOBS;i++)
  97464. oggpack_reset(vbi->packetblob[i]);
  97465. if((ret=_mapping_P[0]->forward(vb)))
  97466. return(ret);
  97467. if(op){
  97468. if(vorbis_bitrate_managed(vb))
  97469. return(OV_EINVAL);
  97470. op->packet=oggpack_get_buffer(&vb->opb);
  97471. op->bytes=oggpack_bytes(&vb->opb);
  97472. op->b_o_s=0;
  97473. op->e_o_s=vb->eofflag;
  97474. op->granulepos=vb->granulepos;
  97475. op->packetno=vb->sequence; /* for sake of completeness */
  97476. }
  97477. return(0);
  97478. }
  97479. void _analysis_output_always(const char *base,int i,float *v,int n,int bark,int dB,ogg_int64_t off){
  97480. int j;
  97481. FILE *of;
  97482. char buffer[80];
  97483. sprintf(buffer,"%s_%d.m",base,i);
  97484. of=fopen(buffer,"w");
  97485. if(!of)perror("failed to open data dump file");
  97486. for(j=0;j<n;j++){
  97487. if(bark){
  97488. float b=toBARK((4000.f*j/n)+.25);
  97489. fprintf(of,"%f ",b);
  97490. }else
  97491. if(off!=0)
  97492. fprintf(of,"%f ",(double)(j+off)/8000.);
  97493. else
  97494. fprintf(of,"%f ",(double)j);
  97495. if(dB){
  97496. float val;
  97497. if(v[j]==0.)
  97498. val=-140.;
  97499. else
  97500. val=todB(v+j);
  97501. fprintf(of,"%f\n",val);
  97502. }else{
  97503. fprintf(of,"%f\n",v[j]);
  97504. }
  97505. }
  97506. fclose(of);
  97507. }
  97508. void _analysis_output(char *base,int i,float *v,int n,int bark,int dB,
  97509. ogg_int64_t off){
  97510. if(analysis_noisy)_analysis_output_always(base,i,v,n,bark,dB,off);
  97511. }
  97512. #endif
  97513. /*** End of inlined file: analysis.c ***/
  97514. /*** Start of inlined file: bitrate.c ***/
  97515. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  97516. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  97517. // tasks..
  97518. #if JUCE_MSVC
  97519. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  97520. #endif
  97521. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  97522. #if JUCE_USE_OGGVORBIS
  97523. #include <stdlib.h>
  97524. #include <string.h>
  97525. #include <math.h>
  97526. void vorbis_bitrate_init(vorbis_info *vi,bitrate_manager_state *bm){
  97527. codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
  97528. bitrate_manager_info *bi=&ci->bi;
  97529. memset(bm,0,sizeof(*bm));
  97530. if(bi && (bi->reservoir_bits>0)){
  97531. long ratesamples=vi->rate;
  97532. int halfsamples=ci->blocksizes[0]>>1;
  97533. bm->short_per_long=ci->blocksizes[1]/ci->blocksizes[0];
  97534. bm->managed=1;
  97535. bm->avg_bitsper= rint(1.*bi->avg_rate*halfsamples/ratesamples);
  97536. bm->min_bitsper= rint(1.*bi->min_rate*halfsamples/ratesamples);
  97537. bm->max_bitsper= rint(1.*bi->max_rate*halfsamples/ratesamples);
  97538. bm->avgfloat=PACKETBLOBS/2;
  97539. {
  97540. long desired_fill=bi->reservoir_bits*bi->reservoir_bias;
  97541. bm->minmax_reservoir=desired_fill;
  97542. bm->avg_reservoir=desired_fill;
  97543. }
  97544. }
  97545. }
  97546. void vorbis_bitrate_clear(bitrate_manager_state *bm){
  97547. memset(bm,0,sizeof(*bm));
  97548. return;
  97549. }
  97550. int vorbis_bitrate_managed(vorbis_block *vb){
  97551. vorbis_dsp_state *vd=vb->vd;
  97552. private_state *b=(private_state*)vd->backend_state;
  97553. bitrate_manager_state *bm=&b->bms;
  97554. if(bm && bm->managed)return(1);
  97555. return(0);
  97556. }
  97557. int vorbis_bitrate_addblock(vorbis_block *vb){
  97558. vorbis_block_internal *vbi=(vorbis_block_internal*)vb->internal;
  97559. vorbis_dsp_state *vd=vb->vd;
  97560. private_state *b=(private_state*)vd->backend_state;
  97561. bitrate_manager_state *bm=&b->bms;
  97562. vorbis_info *vi=vd->vi;
  97563. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  97564. bitrate_manager_info *bi=&ci->bi;
  97565. int choice=rint(bm->avgfloat);
  97566. long this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97567. long min_target_bits=(vb->W?bm->min_bitsper*bm->short_per_long:bm->min_bitsper);
  97568. long max_target_bits=(vb->W?bm->max_bitsper*bm->short_per_long:bm->max_bitsper);
  97569. int samples=ci->blocksizes[vb->W]>>1;
  97570. long desired_fill=bi->reservoir_bits*bi->reservoir_bias;
  97571. if(!bm->managed){
  97572. if(bm->vb)return(-1); /* one has been submitted without
  97573. being claimed */
  97574. bm->vb=vb;
  97575. return(0);
  97576. }
  97577. bm->vb=vb;
  97578. if(bm->avg_bitsper>0){
  97579. double slew=0.;
  97580. long avg_target_bits=(vb->W?bm->avg_bitsper*bm->short_per_long:bm->avg_bitsper);
  97581. double slewlimit= 15./bi->slew_damp;
  97582. if(bm->avg_reservoir+(this_bits-avg_target_bits)>desired_fill){
  97583. while(choice>0 && this_bits>avg_target_bits &&
  97584. bm->avg_reservoir+(this_bits-avg_target_bits)>desired_fill){
  97585. choice--;
  97586. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97587. }
  97588. }else if(bm->avg_reservoir+(this_bits-avg_target_bits)<desired_fill){
  97589. while(choice+1<PACKETBLOBS && this_bits<avg_target_bits &&
  97590. bm->avg_reservoir+(this_bits-avg_target_bits)<desired_fill){
  97591. choice++;
  97592. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97593. }
  97594. }
  97595. slew=rint(choice-bm->avgfloat)/samples*vi->rate;
  97596. if(slew<-slewlimit)slew=-slewlimit;
  97597. if(slew>slewlimit)slew=slewlimit;
  97598. choice=rint(bm->avgfloat+= slew/vi->rate*samples);
  97599. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97600. }
  97601. if(bm->min_bitsper>0){
  97602. if(this_bits<min_target_bits){
  97603. while(bm->minmax_reservoir-(min_target_bits-this_bits)<0){
  97604. choice++;
  97605. if(choice>=PACKETBLOBS)break;
  97606. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97607. }
  97608. }
  97609. }
  97610. if(bm->max_bitsper>0){
  97611. if(this_bits>max_target_bits){
  97612. while(bm->minmax_reservoir+(this_bits-max_target_bits)>bi->reservoir_bits){
  97613. choice--;
  97614. if(choice<0)break;
  97615. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97616. }
  97617. }
  97618. }
  97619. if(choice<0){
  97620. long maxsize=(max_target_bits+(bi->reservoir_bits-bm->minmax_reservoir))/8;
  97621. bm->choice=choice=0;
  97622. if(oggpack_bytes(vbi->packetblob[choice])>maxsize){
  97623. oggpack_writetrunc(vbi->packetblob[choice],maxsize*8);
  97624. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97625. }
  97626. }else{
  97627. long minsize=(min_target_bits-bm->minmax_reservoir+7)/8;
  97628. if(choice>=PACKETBLOBS)
  97629. choice=PACKETBLOBS-1;
  97630. bm->choice=choice;
  97631. minsize-=oggpack_bytes(vbi->packetblob[choice]);
  97632. while(minsize-->0)oggpack_write(vbi->packetblob[choice],0,8);
  97633. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97634. }
  97635. if(bm->min_bitsper>0 || bm->max_bitsper>0){
  97636. if(max_target_bits>0 && this_bits>max_target_bits){
  97637. bm->minmax_reservoir+=(this_bits-max_target_bits);
  97638. }else if(min_target_bits>0 && this_bits<min_target_bits){
  97639. bm->minmax_reservoir+=(this_bits-min_target_bits);
  97640. }else{
  97641. if(bm->minmax_reservoir>desired_fill){
  97642. if(max_target_bits>0){ /* logical bulletproofing against initialization state */
  97643. bm->minmax_reservoir+=(this_bits-max_target_bits);
  97644. if(bm->minmax_reservoir<desired_fill)bm->minmax_reservoir=desired_fill;
  97645. }else{
  97646. bm->minmax_reservoir=desired_fill;
  97647. }
  97648. }else{
  97649. if(min_target_bits>0){ /* logical bulletproofing against initialization state */
  97650. bm->minmax_reservoir+=(this_bits-min_target_bits);
  97651. if(bm->minmax_reservoir>desired_fill)bm->minmax_reservoir=desired_fill;
  97652. }else{
  97653. bm->minmax_reservoir=desired_fill;
  97654. }
  97655. }
  97656. }
  97657. }
  97658. if(bm->avg_bitsper>0){
  97659. long avg_target_bits=(vb->W?bm->avg_bitsper*bm->short_per_long:bm->avg_bitsper);
  97660. bm->avg_reservoir+=this_bits-avg_target_bits;
  97661. }
  97662. return(0);
  97663. }
  97664. int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd,ogg_packet *op){
  97665. private_state *b=(private_state*)vd->backend_state;
  97666. bitrate_manager_state *bm=&b->bms;
  97667. vorbis_block *vb=bm->vb;
  97668. int choice=PACKETBLOBS/2;
  97669. if(!vb)return 0;
  97670. if(op){
  97671. vorbis_block_internal *vbi=(vorbis_block_internal*)vb->internal;
  97672. if(vorbis_bitrate_managed(vb))
  97673. choice=bm->choice;
  97674. op->packet=oggpack_get_buffer(vbi->packetblob[choice]);
  97675. op->bytes=oggpack_bytes(vbi->packetblob[choice]);
  97676. op->b_o_s=0;
  97677. op->e_o_s=vb->eofflag;
  97678. op->granulepos=vb->granulepos;
  97679. op->packetno=vb->sequence; /* for sake of completeness */
  97680. }
  97681. bm->vb=0;
  97682. return(1);
  97683. }
  97684. #endif
  97685. /*** End of inlined file: bitrate.c ***/
  97686. /*** Start of inlined file: block.c ***/
  97687. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  97688. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  97689. // tasks..
  97690. #if JUCE_MSVC
  97691. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  97692. #endif
  97693. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  97694. #if JUCE_USE_OGGVORBIS
  97695. #include <stdio.h>
  97696. #include <stdlib.h>
  97697. #include <string.h>
  97698. /*** Start of inlined file: window.h ***/
  97699. #ifndef _V_WINDOW_
  97700. #define _V_WINDOW_
  97701. extern float *_vorbis_window_get(int n);
  97702. extern void _vorbis_apply_window(float *d,int *winno,long *blocksizes,
  97703. int lW,int W,int nW);
  97704. #endif
  97705. /*** End of inlined file: window.h ***/
  97706. /*** Start of inlined file: lpc.h ***/
  97707. #ifndef _V_LPC_H_
  97708. #define _V_LPC_H_
  97709. extern float vorbis_lpc_from_data(float *data,float *lpc,int n,int m);
  97710. extern void vorbis_lpc_predict(float *coeff,float *prime,int m,
  97711. float *data,long n);
  97712. #endif
  97713. /*** End of inlined file: lpc.h ***/
  97714. #ifndef WORD_ALIGN
  97715. #define WORD_ALIGN 8
  97716. #endif
  97717. int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb){
  97718. int i;
  97719. memset(vb,0,sizeof(*vb));
  97720. vb->vd=v;
  97721. vb->localalloc=0;
  97722. vb->localstore=NULL;
  97723. if(v->analysisp){
  97724. vorbis_block_internal *vbi=(vorbis_block_internal*)
  97725. (vb->internal=(vorbis_block_internal*)_ogg_calloc(1,sizeof(vorbis_block_internal)));
  97726. vbi->ampmax=-9999;
  97727. for(i=0;i<PACKETBLOBS;i++){
  97728. if(i==PACKETBLOBS/2){
  97729. vbi->packetblob[i]=&vb->opb;
  97730. }else{
  97731. vbi->packetblob[i]=
  97732. (oggpack_buffer*) _ogg_calloc(1,sizeof(oggpack_buffer));
  97733. }
  97734. oggpack_writeinit(vbi->packetblob[i]);
  97735. }
  97736. }
  97737. return(0);
  97738. }
  97739. void *_vorbis_block_alloc(vorbis_block *vb,long bytes){
  97740. bytes=(bytes+(WORD_ALIGN-1)) & ~(WORD_ALIGN-1);
  97741. if(bytes+vb->localtop>vb->localalloc){
  97742. if(vb->localstore){
  97743. struct alloc_chain *link=(struct alloc_chain*)_ogg_malloc(sizeof(*link));
  97744. vb->totaluse+=vb->localtop;
  97745. link->next=vb->reap;
  97746. link->ptr=vb->localstore;
  97747. vb->reap=link;
  97748. }
  97749. vb->localalloc=bytes;
  97750. vb->localstore=_ogg_malloc(vb->localalloc);
  97751. vb->localtop=0;
  97752. }
  97753. {
  97754. void *ret=(void *)(((char *)vb->localstore)+vb->localtop);
  97755. vb->localtop+=bytes;
  97756. return ret;
  97757. }
  97758. }
  97759. void _vorbis_block_ripcord(vorbis_block *vb){
  97760. struct alloc_chain *reap=vb->reap;
  97761. while(reap){
  97762. struct alloc_chain *next=reap->next;
  97763. _ogg_free(reap->ptr);
  97764. memset(reap,0,sizeof(*reap));
  97765. _ogg_free(reap);
  97766. reap=next;
  97767. }
  97768. if(vb->totaluse){
  97769. vb->localstore=_ogg_realloc(vb->localstore,vb->totaluse+vb->localalloc);
  97770. vb->localalloc+=vb->totaluse;
  97771. vb->totaluse=0;
  97772. }
  97773. vb->localtop=0;
  97774. vb->reap=NULL;
  97775. }
  97776. int vorbis_block_clear(vorbis_block *vb){
  97777. int i;
  97778. vorbis_block_internal *vbi=(vorbis_block_internal*)vb->internal;
  97779. _vorbis_block_ripcord(vb);
  97780. if(vb->localstore)_ogg_free(vb->localstore);
  97781. if(vbi){
  97782. for(i=0;i<PACKETBLOBS;i++){
  97783. oggpack_writeclear(vbi->packetblob[i]);
  97784. if(i!=PACKETBLOBS/2)_ogg_free(vbi->packetblob[i]);
  97785. }
  97786. _ogg_free(vbi);
  97787. }
  97788. memset(vb,0,sizeof(*vb));
  97789. return(0);
  97790. }
  97791. static int _vds_shared_init(vorbis_dsp_state *v,vorbis_info *vi,int encp){
  97792. int i;
  97793. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  97794. private_state *b=NULL;
  97795. int hs;
  97796. if(ci==NULL) return 1;
  97797. hs=ci->halfrate_flag;
  97798. memset(v,0,sizeof(*v));
  97799. b=(private_state*) (v->backend_state=(private_state*)_ogg_calloc(1,sizeof(*b)));
  97800. v->vi=vi;
  97801. b->modebits=ilog2(ci->modes);
  97802. b->transform[0]=(vorbis_look_transform**)_ogg_calloc(VI_TRANSFORMB,sizeof(*b->transform[0]));
  97803. b->transform[1]=(vorbis_look_transform**)_ogg_calloc(VI_TRANSFORMB,sizeof(*b->transform[1]));
  97804. b->transform[0][0]=_ogg_calloc(1,sizeof(mdct_lookup));
  97805. b->transform[1][0]=_ogg_calloc(1,sizeof(mdct_lookup));
  97806. mdct_init((mdct_lookup*)b->transform[0][0],ci->blocksizes[0]>>hs);
  97807. mdct_init((mdct_lookup*)b->transform[1][0],ci->blocksizes[1]>>hs);
  97808. b->window[0]=ilog2(ci->blocksizes[0])-6;
  97809. b->window[1]=ilog2(ci->blocksizes[1])-6;
  97810. if(encp){ /* encode/decode differ here */
  97811. drft_init(&b->fft_look[0],ci->blocksizes[0]);
  97812. drft_init(&b->fft_look[1],ci->blocksizes[1]);
  97813. if(!ci->fullbooks){
  97814. ci->fullbooks=(codebook*) _ogg_calloc(ci->books,sizeof(*ci->fullbooks));
  97815. for(i=0;i<ci->books;i++)
  97816. vorbis_book_init_encode(ci->fullbooks+i,ci->book_param[i]);
  97817. }
  97818. b->psy=(vorbis_look_psy*)_ogg_calloc(ci->psys,sizeof(*b->psy));
  97819. for(i=0;i<ci->psys;i++){
  97820. _vp_psy_init(b->psy+i,
  97821. ci->psy_param[i],
  97822. &ci->psy_g_param,
  97823. ci->blocksizes[ci->psy_param[i]->blockflag]/2,
  97824. vi->rate);
  97825. }
  97826. v->analysisp=1;
  97827. }else{
  97828. if(!ci->fullbooks){
  97829. ci->fullbooks=(codebook*) _ogg_calloc(ci->books,sizeof(*ci->fullbooks));
  97830. for(i=0;i<ci->books;i++){
  97831. vorbis_book_init_decode(ci->fullbooks+i,ci->book_param[i]);
  97832. vorbis_staticbook_destroy(ci->book_param[i]);
  97833. ci->book_param[i]=NULL;
  97834. }
  97835. }
  97836. }
  97837. v->pcm_storage=ci->blocksizes[1];
  97838. v->pcm=(float**)_ogg_malloc(vi->channels*sizeof(*v->pcm));
  97839. v->pcmret=(float**)_ogg_malloc(vi->channels*sizeof(*v->pcmret));
  97840. {
  97841. int i;
  97842. for(i=0;i<vi->channels;i++)
  97843. v->pcm[i]=(float*)_ogg_calloc(v->pcm_storage,sizeof(*v->pcm[i]));
  97844. }
  97845. v->lW=0; /* previous window size */
  97846. v->W=0; /* current window size */
  97847. v->centerW=ci->blocksizes[1]/2;
  97848. v->pcm_current=v->centerW;
  97849. b->flr=(vorbis_look_floor**)_ogg_calloc(ci->floors,sizeof(*b->flr));
  97850. b->residue=(vorbis_look_residue**)_ogg_calloc(ci->residues,sizeof(*b->residue));
  97851. for(i=0;i<ci->floors;i++)
  97852. b->flr[i]=_floor_P[ci->floor_type[i]]->
  97853. look(v,ci->floor_param[i]);
  97854. for(i=0;i<ci->residues;i++)
  97855. b->residue[i]=_residue_P[ci->residue_type[i]]->
  97856. look(v,ci->residue_param[i]);
  97857. return 0;
  97858. }
  97859. int vorbis_analysis_init(vorbis_dsp_state *v,vorbis_info *vi){
  97860. private_state *b=NULL;
  97861. if(_vds_shared_init(v,vi,1))return 1;
  97862. b=(private_state*)v->backend_state;
  97863. b->psy_g_look=_vp_global_look(vi);
  97864. b->ve=(envelope_lookup*)_ogg_calloc(1,sizeof(*b->ve));
  97865. _ve_envelope_init(b->ve,vi);
  97866. vorbis_bitrate_init(vi,&b->bms);
  97867. v->sequence=3;
  97868. return(0);
  97869. }
  97870. void vorbis_dsp_clear(vorbis_dsp_state *v){
  97871. int i;
  97872. if(v){
  97873. vorbis_info *vi=v->vi;
  97874. codec_setup_info *ci=(codec_setup_info*)(vi?vi->codec_setup:NULL);
  97875. private_state *b=(private_state*)v->backend_state;
  97876. if(b){
  97877. if(b->ve){
  97878. _ve_envelope_clear(b->ve);
  97879. _ogg_free(b->ve);
  97880. }
  97881. if(b->transform[0]){
  97882. mdct_clear((mdct_lookup*) b->transform[0][0]);
  97883. _ogg_free(b->transform[0][0]);
  97884. _ogg_free(b->transform[0]);
  97885. }
  97886. if(b->transform[1]){
  97887. mdct_clear((mdct_lookup*) b->transform[1][0]);
  97888. _ogg_free(b->transform[1][0]);
  97889. _ogg_free(b->transform[1]);
  97890. }
  97891. if(b->flr){
  97892. for(i=0;i<ci->floors;i++)
  97893. _floor_P[ci->floor_type[i]]->
  97894. free_look(b->flr[i]);
  97895. _ogg_free(b->flr);
  97896. }
  97897. if(b->residue){
  97898. for(i=0;i<ci->residues;i++)
  97899. _residue_P[ci->residue_type[i]]->
  97900. free_look(b->residue[i]);
  97901. _ogg_free(b->residue);
  97902. }
  97903. if(b->psy){
  97904. for(i=0;i<ci->psys;i++)
  97905. _vp_psy_clear(b->psy+i);
  97906. _ogg_free(b->psy);
  97907. }
  97908. if(b->psy_g_look)_vp_global_free(b->psy_g_look);
  97909. vorbis_bitrate_clear(&b->bms);
  97910. drft_clear(&b->fft_look[0]);
  97911. drft_clear(&b->fft_look[1]);
  97912. }
  97913. if(v->pcm){
  97914. for(i=0;i<vi->channels;i++)
  97915. if(v->pcm[i])_ogg_free(v->pcm[i]);
  97916. _ogg_free(v->pcm);
  97917. if(v->pcmret)_ogg_free(v->pcmret);
  97918. }
  97919. if(b){
  97920. if(b->header)_ogg_free(b->header);
  97921. if(b->header1)_ogg_free(b->header1);
  97922. if(b->header2)_ogg_free(b->header2);
  97923. _ogg_free(b);
  97924. }
  97925. memset(v,0,sizeof(*v));
  97926. }
  97927. }
  97928. float **vorbis_analysis_buffer(vorbis_dsp_state *v, int vals){
  97929. int i;
  97930. vorbis_info *vi=v->vi;
  97931. private_state *b=(private_state*)v->backend_state;
  97932. if(b->header)_ogg_free(b->header);b->header=NULL;
  97933. if(b->header1)_ogg_free(b->header1);b->header1=NULL;
  97934. if(b->header2)_ogg_free(b->header2);b->header2=NULL;
  97935. if(v->pcm_current+vals>=v->pcm_storage){
  97936. v->pcm_storage=v->pcm_current+vals*2;
  97937. for(i=0;i<vi->channels;i++){
  97938. v->pcm[i]=(float*)_ogg_realloc(v->pcm[i],v->pcm_storage*sizeof(*v->pcm[i]));
  97939. }
  97940. }
  97941. for(i=0;i<vi->channels;i++)
  97942. v->pcmret[i]=v->pcm[i]+v->pcm_current;
  97943. return(v->pcmret);
  97944. }
  97945. static void _preextrapolate_helper(vorbis_dsp_state *v){
  97946. int i;
  97947. int order=32;
  97948. float *lpc=(float*)alloca(order*sizeof(*lpc));
  97949. float *work=(float*)alloca(v->pcm_current*sizeof(*work));
  97950. long j;
  97951. v->preextrapolate=1;
  97952. if(v->pcm_current-v->centerW>order*2){ /* safety */
  97953. for(i=0;i<v->vi->channels;i++){
  97954. for(j=0;j<v->pcm_current;j++)
  97955. work[j]=v->pcm[i][v->pcm_current-j-1];
  97956. vorbis_lpc_from_data(work,lpc,v->pcm_current-v->centerW,order);
  97957. vorbis_lpc_predict(lpc,work+v->pcm_current-v->centerW-order,
  97958. order,
  97959. work+v->pcm_current-v->centerW,
  97960. v->centerW);
  97961. for(j=0;j<v->pcm_current;j++)
  97962. v->pcm[i][v->pcm_current-j-1]=work[j];
  97963. }
  97964. }
  97965. }
  97966. int vorbis_analysis_wrote(vorbis_dsp_state *v, int vals){
  97967. vorbis_info *vi=v->vi;
  97968. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  97969. if(vals<=0){
  97970. int order=32;
  97971. int i;
  97972. float *lpc=(float*) alloca(order*sizeof(*lpc));
  97973. if(!v->preextrapolate)
  97974. _preextrapolate_helper(v);
  97975. vorbis_analysis_buffer(v,ci->blocksizes[1]*3);
  97976. v->eofflag=v->pcm_current;
  97977. v->pcm_current+=ci->blocksizes[1]*3;
  97978. for(i=0;i<vi->channels;i++){
  97979. if(v->eofflag>order*2){
  97980. long n;
  97981. n=v->eofflag;
  97982. if(n>ci->blocksizes[1])n=ci->blocksizes[1];
  97983. vorbis_lpc_from_data(v->pcm[i]+v->eofflag-n,lpc,n,order);
  97984. vorbis_lpc_predict(lpc,v->pcm[i]+v->eofflag-order,order,
  97985. v->pcm[i]+v->eofflag,v->pcm_current-v->eofflag);
  97986. }else{
  97987. memset(v->pcm[i]+v->eofflag,0,
  97988. (v->pcm_current-v->eofflag)*sizeof(*v->pcm[i]));
  97989. }
  97990. }
  97991. }else{
  97992. if(v->pcm_current+vals>v->pcm_storage)
  97993. return(OV_EINVAL);
  97994. v->pcm_current+=vals;
  97995. if(!v->preextrapolate && v->pcm_current-v->centerW>ci->blocksizes[1])
  97996. _preextrapolate_helper(v);
  97997. }
  97998. return(0);
  97999. }
  98000. int vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb){
  98001. int i;
  98002. vorbis_info *vi=v->vi;
  98003. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98004. private_state *b=(private_state*)v->backend_state;
  98005. vorbis_look_psy_global *g=b->psy_g_look;
  98006. long beginW=v->centerW-ci->blocksizes[v->W]/2,centerNext;
  98007. vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
  98008. if(!v->preextrapolate)return(0);
  98009. if(v->eofflag==-1)return(0);
  98010. {
  98011. long bp=_ve_envelope_search(v);
  98012. if(bp==-1){
  98013. if(v->eofflag==0)return(0); /* not enough data currently to search for a
  98014. full long block */
  98015. v->nW=0;
  98016. }else{
  98017. if(ci->blocksizes[0]==ci->blocksizes[1])
  98018. v->nW=0;
  98019. else
  98020. v->nW=bp;
  98021. }
  98022. }
  98023. centerNext=v->centerW+ci->blocksizes[v->W]/4+ci->blocksizes[v->nW]/4;
  98024. {
  98025. long blockbound=centerNext+ci->blocksizes[v->nW]/2;
  98026. if(v->pcm_current<blockbound)return(0); /* not enough data yet;
  98027. although this check is
  98028. less strict that the
  98029. _ve_envelope_search,
  98030. the search is not run
  98031. if we only use one
  98032. block size */
  98033. }
  98034. _vorbis_block_ripcord(vb);
  98035. vb->lW=v->lW;
  98036. vb->W=v->W;
  98037. vb->nW=v->nW;
  98038. if(v->W){
  98039. if(!v->lW || !v->nW){
  98040. vbi->blocktype=BLOCKTYPE_TRANSITION;
  98041. }else{
  98042. vbi->blocktype=BLOCKTYPE_LONG;
  98043. }
  98044. }else{
  98045. if(_ve_envelope_mark(v)){
  98046. vbi->blocktype=BLOCKTYPE_IMPULSE;
  98047. }else{
  98048. vbi->blocktype=BLOCKTYPE_PADDING;
  98049. }
  98050. }
  98051. vb->vd=v;
  98052. vb->sequence=v->sequence++;
  98053. vb->granulepos=v->granulepos;
  98054. vb->pcmend=ci->blocksizes[v->W];
  98055. if(vbi->ampmax>g->ampmax)g->ampmax=vbi->ampmax;
  98056. g->ampmax=_vp_ampmax_decay(g->ampmax,v);
  98057. vbi->ampmax=g->ampmax;
  98058. vb->pcm=(float**)_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels);
  98059. vbi->pcmdelay=(float**)_vorbis_block_alloc(vb,sizeof(*vbi->pcmdelay)*vi->channels);
  98060. for(i=0;i<vi->channels;i++){
  98061. vbi->pcmdelay[i]=
  98062. (float*) _vorbis_block_alloc(vb,(vb->pcmend+beginW)*sizeof(*vbi->pcmdelay[i]));
  98063. memcpy(vbi->pcmdelay[i],v->pcm[i],(vb->pcmend+beginW)*sizeof(*vbi->pcmdelay[i]));
  98064. vb->pcm[i]=vbi->pcmdelay[i]+beginW;
  98065. }
  98066. if(v->eofflag){
  98067. if(v->centerW>=v->eofflag){
  98068. v->eofflag=-1;
  98069. vb->eofflag=1;
  98070. return(1);
  98071. }
  98072. }
  98073. {
  98074. int new_centerNext=ci->blocksizes[1]/2;
  98075. int movementW=centerNext-new_centerNext;
  98076. if(movementW>0){
  98077. _ve_envelope_shift(b->ve,movementW);
  98078. v->pcm_current-=movementW;
  98079. for(i=0;i<vi->channels;i++)
  98080. memmove(v->pcm[i],v->pcm[i]+movementW,
  98081. v->pcm_current*sizeof(*v->pcm[i]));
  98082. v->lW=v->W;
  98083. v->W=v->nW;
  98084. v->centerW=new_centerNext;
  98085. if(v->eofflag){
  98086. v->eofflag-=movementW;
  98087. if(v->eofflag<=0)v->eofflag=-1;
  98088. if(v->centerW>=v->eofflag){
  98089. v->granulepos+=movementW-(v->centerW-v->eofflag);
  98090. }else{
  98091. v->granulepos+=movementW;
  98092. }
  98093. }else{
  98094. v->granulepos+=movementW;
  98095. }
  98096. }
  98097. }
  98098. return(1);
  98099. }
  98100. int vorbis_synthesis_restart(vorbis_dsp_state *v){
  98101. vorbis_info *vi=v->vi;
  98102. codec_setup_info *ci;
  98103. int hs;
  98104. if(!v->backend_state)return -1;
  98105. if(!vi)return -1;
  98106. ci=(codec_setup_info*) vi->codec_setup;
  98107. if(!ci)return -1;
  98108. hs=ci->halfrate_flag;
  98109. v->centerW=ci->blocksizes[1]>>(hs+1);
  98110. v->pcm_current=v->centerW>>hs;
  98111. v->pcm_returned=-1;
  98112. v->granulepos=-1;
  98113. v->sequence=-1;
  98114. v->eofflag=0;
  98115. ((private_state *)(v->backend_state))->sample_count=-1;
  98116. return(0);
  98117. }
  98118. int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi){
  98119. if(_vds_shared_init(v,vi,0)) return 1;
  98120. vorbis_synthesis_restart(v);
  98121. return 0;
  98122. }
  98123. int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb){
  98124. vorbis_info *vi=v->vi;
  98125. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98126. private_state *b=(private_state*)v->backend_state;
  98127. int hs=ci->halfrate_flag;
  98128. int i,j;
  98129. if(!vb)return(OV_EINVAL);
  98130. if(v->pcm_current>v->pcm_returned && v->pcm_returned!=-1)return(OV_EINVAL);
  98131. v->lW=v->W;
  98132. v->W=vb->W;
  98133. v->nW=-1;
  98134. if((v->sequence==-1)||
  98135. (v->sequence+1 != vb->sequence)){
  98136. v->granulepos=-1; /* out of sequence; lose count */
  98137. b->sample_count=-1;
  98138. }
  98139. v->sequence=vb->sequence;
  98140. if(vb->pcm){ /* no pcm to process if vorbis_synthesis_trackonly
  98141. was called on block */
  98142. int n=ci->blocksizes[v->W]>>(hs+1);
  98143. int n0=ci->blocksizes[0]>>(hs+1);
  98144. int n1=ci->blocksizes[1]>>(hs+1);
  98145. int thisCenter;
  98146. int prevCenter;
  98147. v->glue_bits+=vb->glue_bits;
  98148. v->time_bits+=vb->time_bits;
  98149. v->floor_bits+=vb->floor_bits;
  98150. v->res_bits+=vb->res_bits;
  98151. if(v->centerW){
  98152. thisCenter=n1;
  98153. prevCenter=0;
  98154. }else{
  98155. thisCenter=0;
  98156. prevCenter=n1;
  98157. }
  98158. for(j=0;j<vi->channels;j++){
  98159. if(v->lW){
  98160. if(v->W){
  98161. float *w=_vorbis_window_get(b->window[1]-hs);
  98162. float *pcm=v->pcm[j]+prevCenter;
  98163. float *p=vb->pcm[j];
  98164. for(i=0;i<n1;i++)
  98165. pcm[i]=pcm[i]*w[n1-i-1] + p[i]*w[i];
  98166. }else{
  98167. float *w=_vorbis_window_get(b->window[0]-hs);
  98168. float *pcm=v->pcm[j]+prevCenter+n1/2-n0/2;
  98169. float *p=vb->pcm[j];
  98170. for(i=0;i<n0;i++)
  98171. pcm[i]=pcm[i]*w[n0-i-1] +p[i]*w[i];
  98172. }
  98173. }else{
  98174. if(v->W){
  98175. float *w=_vorbis_window_get(b->window[0]-hs);
  98176. float *pcm=v->pcm[j]+prevCenter;
  98177. float *p=vb->pcm[j]+n1/2-n0/2;
  98178. for(i=0;i<n0;i++)
  98179. pcm[i]=pcm[i]*w[n0-i-1] +p[i]*w[i];
  98180. for(;i<n1/2+n0/2;i++)
  98181. pcm[i]=p[i];
  98182. }else{
  98183. float *w=_vorbis_window_get(b->window[0]-hs);
  98184. float *pcm=v->pcm[j]+prevCenter;
  98185. float *p=vb->pcm[j];
  98186. for(i=0;i<n0;i++)
  98187. pcm[i]=pcm[i]*w[n0-i-1] +p[i]*w[i];
  98188. }
  98189. }
  98190. {
  98191. float *pcm=v->pcm[j]+thisCenter;
  98192. float *p=vb->pcm[j]+n;
  98193. for(i=0;i<n;i++)
  98194. pcm[i]=p[i];
  98195. }
  98196. }
  98197. if(v->centerW)
  98198. v->centerW=0;
  98199. else
  98200. v->centerW=n1;
  98201. if(v->pcm_returned==-1){
  98202. v->pcm_returned=thisCenter;
  98203. v->pcm_current=thisCenter;
  98204. }else{
  98205. v->pcm_returned=prevCenter;
  98206. v->pcm_current=prevCenter+
  98207. ((ci->blocksizes[v->lW]/4+
  98208. ci->blocksizes[v->W]/4)>>hs);
  98209. }
  98210. }
  98211. if(b->sample_count==-1){
  98212. b->sample_count=0;
  98213. }else{
  98214. b->sample_count+=ci->blocksizes[v->lW]/4+ci->blocksizes[v->W]/4;
  98215. }
  98216. if(v->granulepos==-1){
  98217. if(vb->granulepos!=-1){ /* only set if we have a position to set to */
  98218. v->granulepos=vb->granulepos;
  98219. if(b->sample_count>v->granulepos){
  98220. if(vb->eofflag){
  98221. v->pcm_current-=(b->sample_count-v->granulepos)>>hs;
  98222. }else{
  98223. v->pcm_returned+=(b->sample_count-v->granulepos)>>hs;
  98224. if(v->pcm_returned>v->pcm_current)
  98225. v->pcm_returned=v->pcm_current;
  98226. }
  98227. }
  98228. }
  98229. }else{
  98230. v->granulepos+=ci->blocksizes[v->lW]/4+ci->blocksizes[v->W]/4;
  98231. if(vb->granulepos!=-1 && v->granulepos!=vb->granulepos){
  98232. if(v->granulepos>vb->granulepos){
  98233. long extra=v->granulepos-vb->granulepos;
  98234. if(extra)
  98235. if(vb->eofflag){
  98236. v->pcm_current-=extra>>hs;
  98237. } /* else {Shouldn't happen *unless* the bitstream is out of
  98238. spec. Either way, believe the bitstream } */
  98239. } /* else {Shouldn't happen *unless* the bitstream is out of
  98240. spec. Either way, believe the bitstream } */
  98241. v->granulepos=vb->granulepos;
  98242. }
  98243. }
  98244. if(vb->eofflag)v->eofflag=1;
  98245. return(0);
  98246. }
  98247. int vorbis_synthesis_pcmout(vorbis_dsp_state *v,float ***pcm){
  98248. vorbis_info *vi=v->vi;
  98249. if(v->pcm_returned>-1 && v->pcm_returned<v->pcm_current){
  98250. if(pcm){
  98251. int i;
  98252. for(i=0;i<vi->channels;i++)
  98253. v->pcmret[i]=v->pcm[i]+v->pcm_returned;
  98254. *pcm=v->pcmret;
  98255. }
  98256. return(v->pcm_current-v->pcm_returned);
  98257. }
  98258. return(0);
  98259. }
  98260. int vorbis_synthesis_read(vorbis_dsp_state *v,int n){
  98261. if(n && v->pcm_returned+n>v->pcm_current)return(OV_EINVAL);
  98262. v->pcm_returned+=n;
  98263. return(0);
  98264. }
  98265. int vorbis_synthesis_lapout(vorbis_dsp_state *v,float ***pcm){
  98266. vorbis_info *vi=v->vi;
  98267. codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
  98268. int hs=ci->halfrate_flag;
  98269. int n=ci->blocksizes[v->W]>>(hs+1);
  98270. int n0=ci->blocksizes[0]>>(hs+1);
  98271. int n1=ci->blocksizes[1]>>(hs+1);
  98272. int i,j;
  98273. if(v->pcm_returned<0)return 0;
  98274. if(v->centerW==n1){
  98275. for(j=0;j<vi->channels;j++){
  98276. float *p=v->pcm[j];
  98277. for(i=0;i<n1;i++){
  98278. float temp=p[i];
  98279. p[i]=p[i+n1];
  98280. p[i+n1]=temp;
  98281. }
  98282. }
  98283. v->pcm_current-=n1;
  98284. v->pcm_returned-=n1;
  98285. v->centerW=0;
  98286. }
  98287. if((v->lW^v->W)==1){
  98288. for(j=0;j<vi->channels;j++){
  98289. float *s=v->pcm[j];
  98290. float *d=v->pcm[j]+(n1-n0)/2;
  98291. for(i=(n1+n0)/2-1;i>=0;--i)
  98292. d[i]=s[i];
  98293. }
  98294. v->pcm_returned+=(n1-n0)/2;
  98295. v->pcm_current+=(n1-n0)/2;
  98296. }else{
  98297. if(v->lW==0){
  98298. for(j=0;j<vi->channels;j++){
  98299. float *s=v->pcm[j];
  98300. float *d=v->pcm[j]+n1-n0;
  98301. for(i=n0-1;i>=0;--i)
  98302. d[i]=s[i];
  98303. }
  98304. v->pcm_returned+=n1-n0;
  98305. v->pcm_current+=n1-n0;
  98306. }
  98307. }
  98308. if(pcm){
  98309. int i;
  98310. for(i=0;i<vi->channels;i++)
  98311. v->pcmret[i]=v->pcm[i]+v->pcm_returned;
  98312. *pcm=v->pcmret;
  98313. }
  98314. return(n1+n-v->pcm_returned);
  98315. }
  98316. float *vorbis_window(vorbis_dsp_state *v,int W){
  98317. vorbis_info *vi=v->vi;
  98318. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  98319. int hs=ci->halfrate_flag;
  98320. private_state *b=(private_state*)v->backend_state;
  98321. if(b->window[W]-1<0)return NULL;
  98322. return _vorbis_window_get(b->window[W]-hs);
  98323. }
  98324. #endif
  98325. /*** End of inlined file: block.c ***/
  98326. /*** Start of inlined file: codebook.c ***/
  98327. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  98328. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  98329. // tasks..
  98330. #if JUCE_MSVC
  98331. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  98332. #endif
  98333. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  98334. #if JUCE_USE_OGGVORBIS
  98335. #include <stdlib.h>
  98336. #include <string.h>
  98337. #include <math.h>
  98338. int vorbis_staticbook_pack(const static_codebook *c,oggpack_buffer *opb){
  98339. long i,j;
  98340. int ordered=0;
  98341. oggpack_write(opb,0x564342,24);
  98342. oggpack_write(opb,c->dim,16);
  98343. oggpack_write(opb,c->entries,24);
  98344. for(i=1;i<c->entries;i++)
  98345. if(c->lengthlist[i-1]==0 || c->lengthlist[i]<c->lengthlist[i-1])break;
  98346. if(i==c->entries)ordered=1;
  98347. if(ordered){
  98348. long count=0;
  98349. oggpack_write(opb,1,1); /* ordered */
  98350. oggpack_write(opb,c->lengthlist[0]-1,5); /* 1 to 32 */
  98351. for(i=1;i<c->entries;i++){
  98352. long thisx=c->lengthlist[i];
  98353. long last=c->lengthlist[i-1];
  98354. if(thisx>last){
  98355. for(j=last;j<thisx;j++){
  98356. oggpack_write(opb,i-count,_ilog(c->entries-count));
  98357. count=i;
  98358. }
  98359. }
  98360. }
  98361. oggpack_write(opb,i-count,_ilog(c->entries-count));
  98362. }else{
  98363. oggpack_write(opb,0,1); /* unordered */
  98364. for(i=0;i<c->entries;i++)
  98365. if(c->lengthlist[i]==0)break;
  98366. if(i==c->entries){
  98367. oggpack_write(opb,0,1); /* no unused entries */
  98368. for(i=0;i<c->entries;i++)
  98369. oggpack_write(opb,c->lengthlist[i]-1,5);
  98370. }else{
  98371. oggpack_write(opb,1,1); /* we have unused entries; thus we tag */
  98372. for(i=0;i<c->entries;i++){
  98373. if(c->lengthlist[i]==0){
  98374. oggpack_write(opb,0,1);
  98375. }else{
  98376. oggpack_write(opb,1,1);
  98377. oggpack_write(opb,c->lengthlist[i]-1,5);
  98378. }
  98379. }
  98380. }
  98381. }
  98382. oggpack_write(opb,c->maptype,4);
  98383. switch(c->maptype){
  98384. case 0:
  98385. break;
  98386. case 1:case 2:
  98387. if(!c->quantlist){
  98388. return(-1);
  98389. }
  98390. oggpack_write(opb,c->q_min,32);
  98391. oggpack_write(opb,c->q_delta,32);
  98392. oggpack_write(opb,c->q_quant-1,4);
  98393. oggpack_write(opb,c->q_sequencep,1);
  98394. {
  98395. int quantvals;
  98396. switch(c->maptype){
  98397. case 1:
  98398. quantvals=_book_maptype1_quantvals(c);
  98399. break;
  98400. case 2:
  98401. quantvals=c->entries*c->dim;
  98402. break;
  98403. default: /* NOT_REACHABLE */
  98404. quantvals=-1;
  98405. }
  98406. for(i=0;i<quantvals;i++)
  98407. oggpack_write(opb,labs(c->quantlist[i]),c->q_quant);
  98408. }
  98409. break;
  98410. default:
  98411. return(-1);
  98412. }
  98413. return(0);
  98414. }
  98415. int vorbis_staticbook_unpack(oggpack_buffer *opb,static_codebook *s){
  98416. long i,j;
  98417. memset(s,0,sizeof(*s));
  98418. s->allocedp=1;
  98419. if(oggpack_read(opb,24)!=0x564342)goto _eofout;
  98420. s->dim=oggpack_read(opb,16);
  98421. s->entries=oggpack_read(opb,24);
  98422. if(s->entries==-1)goto _eofout;
  98423. switch((int)oggpack_read(opb,1)){
  98424. case 0:
  98425. s->lengthlist=(long*)_ogg_malloc(sizeof(*s->lengthlist)*s->entries);
  98426. if(oggpack_read(opb,1)){
  98427. for(i=0;i<s->entries;i++){
  98428. if(oggpack_read(opb,1)){
  98429. long num=oggpack_read(opb,5);
  98430. if(num==-1)goto _eofout;
  98431. s->lengthlist[i]=num+1;
  98432. }else
  98433. s->lengthlist[i]=0;
  98434. }
  98435. }else{
  98436. for(i=0;i<s->entries;i++){
  98437. long num=oggpack_read(opb,5);
  98438. if(num==-1)goto _eofout;
  98439. s->lengthlist[i]=num+1;
  98440. }
  98441. }
  98442. break;
  98443. case 1:
  98444. {
  98445. long length=oggpack_read(opb,5)+1;
  98446. s->lengthlist=(long*)_ogg_malloc(sizeof(*s->lengthlist)*s->entries);
  98447. for(i=0;i<s->entries;){
  98448. long num=oggpack_read(opb,_ilog(s->entries-i));
  98449. if(num==-1)goto _eofout;
  98450. for(j=0;j<num && i<s->entries;j++,i++)
  98451. s->lengthlist[i]=length;
  98452. length++;
  98453. }
  98454. }
  98455. break;
  98456. default:
  98457. return(-1);
  98458. }
  98459. switch((s->maptype=oggpack_read(opb,4))){
  98460. case 0:
  98461. break;
  98462. case 1: case 2:
  98463. s->q_min=oggpack_read(opb,32);
  98464. s->q_delta=oggpack_read(opb,32);
  98465. s->q_quant=oggpack_read(opb,4)+1;
  98466. s->q_sequencep=oggpack_read(opb,1);
  98467. {
  98468. int quantvals=0;
  98469. switch(s->maptype){
  98470. case 1:
  98471. quantvals=_book_maptype1_quantvals(s);
  98472. break;
  98473. case 2:
  98474. quantvals=s->entries*s->dim;
  98475. break;
  98476. }
  98477. s->quantlist=(long*)_ogg_malloc(sizeof(*s->quantlist)*quantvals);
  98478. for(i=0;i<quantvals;i++)
  98479. s->quantlist[i]=oggpack_read(opb,s->q_quant);
  98480. if(quantvals&&s->quantlist[quantvals-1]==-1)goto _eofout;
  98481. }
  98482. break;
  98483. default:
  98484. goto _errout;
  98485. }
  98486. return(0);
  98487. _errout:
  98488. _eofout:
  98489. vorbis_staticbook_clear(s);
  98490. return(-1);
  98491. }
  98492. int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b){
  98493. oggpack_write(b,book->codelist[a],book->c->lengthlist[a]);
  98494. return(book->c->lengthlist[a]);
  98495. }
  98496. int vorbis_book_errorv(codebook *book,float *a){
  98497. int dim=book->dim,k;
  98498. int best=_best(book,a,1);
  98499. for(k=0;k<dim;k++)
  98500. a[k]=(book->valuelist+best*dim)[k];
  98501. return(best);
  98502. }
  98503. int vorbis_book_encodev(codebook *book,int best,float *a,oggpack_buffer *b){
  98504. int k,dim=book->dim;
  98505. for(k=0;k<dim;k++)
  98506. a[k]=(book->valuelist+best*dim)[k];
  98507. return(vorbis_book_encode(book,best,b));
  98508. }
  98509. STIN long decode_packed_entry_number(codebook *book, oggpack_buffer *b){
  98510. int read=book->dec_maxlength;
  98511. long lo,hi;
  98512. long lok = oggpack_look(b,book->dec_firsttablen);
  98513. if (lok >= 0) {
  98514. long entry = book->dec_firsttable[lok];
  98515. if(entry&0x80000000UL){
  98516. lo=(entry>>15)&0x7fff;
  98517. hi=book->used_entries-(entry&0x7fff);
  98518. }else{
  98519. oggpack_adv(b, book->dec_codelengths[entry-1]);
  98520. return(entry-1);
  98521. }
  98522. }else{
  98523. lo=0;
  98524. hi=book->used_entries;
  98525. }
  98526. lok = oggpack_look(b, read);
  98527. while(lok<0 && read>1)
  98528. lok = oggpack_look(b, --read);
  98529. if(lok<0)return -1;
  98530. {
  98531. ogg_uint32_t testword=ogg_bitreverse((ogg_uint32_t)lok);
  98532. while(hi-lo>1){
  98533. long p=(hi-lo)>>1;
  98534. long test=book->codelist[lo+p]>testword;
  98535. lo+=p&(test-1);
  98536. hi-=p&(-test);
  98537. }
  98538. if(book->dec_codelengths[lo]<=read){
  98539. oggpack_adv(b, book->dec_codelengths[lo]);
  98540. return(lo);
  98541. }
  98542. }
  98543. oggpack_adv(b, read);
  98544. return(-1);
  98545. }
  98546. long vorbis_book_decode(codebook *book, oggpack_buffer *b){
  98547. long packed_entry=decode_packed_entry_number(book,b);
  98548. if(packed_entry>=0)
  98549. return(book->dec_index[packed_entry]);
  98550. return(packed_entry);
  98551. }
  98552. long vorbis_book_decodevs_add(codebook *book,float *a,oggpack_buffer *b,int n){
  98553. int step=n/book->dim;
  98554. long *entry = (long*)alloca(sizeof(*entry)*step);
  98555. float **t = (float**)alloca(sizeof(*t)*step);
  98556. int i,j,o;
  98557. for (i = 0; i < step; i++) {
  98558. entry[i]=decode_packed_entry_number(book,b);
  98559. if(entry[i]==-1)return(-1);
  98560. t[i] = book->valuelist+entry[i]*book->dim;
  98561. }
  98562. for(i=0,o=0;i<book->dim;i++,o+=step)
  98563. for (j=0;j<step;j++)
  98564. a[o+j]+=t[j][i];
  98565. return(0);
  98566. }
  98567. long vorbis_book_decodev_add(codebook *book,float *a,oggpack_buffer *b,int n){
  98568. int i,j,entry;
  98569. float *t;
  98570. if(book->dim>8){
  98571. for(i=0;i<n;){
  98572. entry = decode_packed_entry_number(book,b);
  98573. if(entry==-1)return(-1);
  98574. t = book->valuelist+entry*book->dim;
  98575. for (j=0;j<book->dim;)
  98576. a[i++]+=t[j++];
  98577. }
  98578. }else{
  98579. for(i=0;i<n;){
  98580. entry = decode_packed_entry_number(book,b);
  98581. if(entry==-1)return(-1);
  98582. t = book->valuelist+entry*book->dim;
  98583. j=0;
  98584. switch((int)book->dim){
  98585. case 8:
  98586. a[i++]+=t[j++];
  98587. case 7:
  98588. a[i++]+=t[j++];
  98589. case 6:
  98590. a[i++]+=t[j++];
  98591. case 5:
  98592. a[i++]+=t[j++];
  98593. case 4:
  98594. a[i++]+=t[j++];
  98595. case 3:
  98596. a[i++]+=t[j++];
  98597. case 2:
  98598. a[i++]+=t[j++];
  98599. case 1:
  98600. a[i++]+=t[j++];
  98601. case 0:
  98602. break;
  98603. }
  98604. }
  98605. }
  98606. return(0);
  98607. }
  98608. long vorbis_book_decodev_set(codebook *book,float *a,oggpack_buffer *b,int n){
  98609. int i,j,entry;
  98610. float *t;
  98611. for(i=0;i<n;){
  98612. entry = decode_packed_entry_number(book,b);
  98613. if(entry==-1)return(-1);
  98614. t = book->valuelist+entry*book->dim;
  98615. for (j=0;j<book->dim;)
  98616. a[i++]=t[j++];
  98617. }
  98618. return(0);
  98619. }
  98620. long vorbis_book_decodevv_add(codebook *book,float **a,long offset,int ch,
  98621. oggpack_buffer *b,int n){
  98622. long i,j,entry;
  98623. int chptr=0;
  98624. for(i=offset/ch;i<(offset+n)/ch;){
  98625. entry = decode_packed_entry_number(book,b);
  98626. if(entry==-1)return(-1);
  98627. {
  98628. const float *t = book->valuelist+entry*book->dim;
  98629. for (j=0;j<book->dim;j++){
  98630. a[chptr++][i]+=t[j];
  98631. if(chptr==ch){
  98632. chptr=0;
  98633. i++;
  98634. }
  98635. }
  98636. }
  98637. }
  98638. return(0);
  98639. }
  98640. #ifdef _V_SELFTEST
  98641. #include <stdio.h>
  98642. #include "vorbis/book/lsp20_0.vqh"
  98643. #include "vorbis/book/res0a_13.vqh"
  98644. #define TESTSIZE 40
  98645. float test1[TESTSIZE]={
  98646. 0.105939f,
  98647. 0.215373f,
  98648. 0.429117f,
  98649. 0.587974f,
  98650. 0.181173f,
  98651. 0.296583f,
  98652. 0.515707f,
  98653. 0.715261f,
  98654. 0.162327f,
  98655. 0.263834f,
  98656. 0.342876f,
  98657. 0.406025f,
  98658. 0.103571f,
  98659. 0.223561f,
  98660. 0.368513f,
  98661. 0.540313f,
  98662. 0.136672f,
  98663. 0.395882f,
  98664. 0.587183f,
  98665. 0.652476f,
  98666. 0.114338f,
  98667. 0.417300f,
  98668. 0.525486f,
  98669. 0.698679f,
  98670. 0.147492f,
  98671. 0.324481f,
  98672. 0.643089f,
  98673. 0.757582f,
  98674. 0.139556f,
  98675. 0.215795f,
  98676. 0.324559f,
  98677. 0.399387f,
  98678. 0.120236f,
  98679. 0.267420f,
  98680. 0.446940f,
  98681. 0.608760f,
  98682. 0.115587f,
  98683. 0.287234f,
  98684. 0.571081f,
  98685. 0.708603f,
  98686. };
  98687. float test3[TESTSIZE]={
  98688. 0,1,-2,3,4,-5,6,7,8,9,
  98689. 8,-2,7,-1,4,6,8,3,1,-9,
  98690. 10,11,12,13,14,15,26,17,18,19,
  98691. 30,-25,-30,-1,-5,-32,4,3,-2,0};
  98692. static_codebook *testlist[]={&_vq_book_lsp20_0,
  98693. &_vq_book_res0a_13,NULL};
  98694. float *testvec[]={test1,test3};
  98695. int main(){
  98696. oggpack_buffer write;
  98697. oggpack_buffer read;
  98698. long ptr=0,i;
  98699. oggpack_writeinit(&write);
  98700. fprintf(stderr,"Testing codebook abstraction...:\n");
  98701. while(testlist[ptr]){
  98702. codebook c;
  98703. static_codebook s;
  98704. float *qv=alloca(sizeof(*qv)*TESTSIZE);
  98705. float *iv=alloca(sizeof(*iv)*TESTSIZE);
  98706. memcpy(qv,testvec[ptr],sizeof(*qv)*TESTSIZE);
  98707. memset(iv,0,sizeof(*iv)*TESTSIZE);
  98708. fprintf(stderr,"\tpacking/coding %ld... ",ptr);
  98709. oggpack_reset(&write);
  98710. vorbis_book_init_encode(&c,testlist[ptr]); /* get it into memory
  98711. we can write */
  98712. vorbis_staticbook_pack(testlist[ptr],&write);
  98713. fprintf(stderr,"Codebook size %ld bytes... ",oggpack_bytes(&write));
  98714. for(i=0;i<TESTSIZE;i+=c.dim){
  98715. int best=_best(&c,qv+i,1);
  98716. vorbis_book_encodev(&c,best,qv+i,&write);
  98717. }
  98718. vorbis_book_clear(&c);
  98719. fprintf(stderr,"OK.\n");
  98720. fprintf(stderr,"\tunpacking/decoding %ld... ",ptr);
  98721. oggpack_readinit(&read,oggpack_get_buffer(&write),oggpack_bytes(&write));
  98722. if(vorbis_staticbook_unpack(&read,&s)){
  98723. fprintf(stderr,"Error unpacking codebook.\n");
  98724. exit(1);
  98725. }
  98726. if(vorbis_book_init_decode(&c,&s)){
  98727. fprintf(stderr,"Error initializing codebook.\n");
  98728. exit(1);
  98729. }
  98730. for(i=0;i<TESTSIZE;i+=c.dim)
  98731. if(vorbis_book_decodev_set(&c,iv+i,&read,c.dim)==-1){
  98732. fprintf(stderr,"Error reading codebook test data (EOP).\n");
  98733. exit(1);
  98734. }
  98735. for(i=0;i<TESTSIZE;i++)
  98736. if(fabs(qv[i]-iv[i])>.000001){
  98737. fprintf(stderr,"read (%g) != written (%g) at position (%ld)\n",
  98738. iv[i],qv[i],i);
  98739. exit(1);
  98740. }
  98741. fprintf(stderr,"OK\n");
  98742. ptr++;
  98743. }
  98744. exit(0);
  98745. }
  98746. #endif
  98747. #endif
  98748. /*** End of inlined file: codebook.c ***/
  98749. /*** Start of inlined file: envelope.c ***/
  98750. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  98751. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  98752. // tasks..
  98753. #if JUCE_MSVC
  98754. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  98755. #endif
  98756. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  98757. #if JUCE_USE_OGGVORBIS
  98758. #include <stdlib.h>
  98759. #include <string.h>
  98760. #include <stdio.h>
  98761. #include <math.h>
  98762. void _ve_envelope_init(envelope_lookup *e,vorbis_info *vi){
  98763. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98764. vorbis_info_psy_global *gi=&ci->psy_g_param;
  98765. int ch=vi->channels;
  98766. int i,j;
  98767. int n=e->winlength=128;
  98768. e->searchstep=64; /* not random */
  98769. e->minenergy=gi->preecho_minenergy;
  98770. e->ch=ch;
  98771. e->storage=128;
  98772. e->cursor=ci->blocksizes[1]/2;
  98773. e->mdct_win=(float*)_ogg_calloc(n,sizeof(*e->mdct_win));
  98774. mdct_init(&e->mdct,n);
  98775. for(i=0;i<n;i++){
  98776. e->mdct_win[i]=sin(i/(n-1.)*M_PI);
  98777. e->mdct_win[i]*=e->mdct_win[i];
  98778. }
  98779. e->band[0].begin=2; e->band[0].end=4;
  98780. e->band[1].begin=4; e->band[1].end=5;
  98781. e->band[2].begin=6; e->band[2].end=6;
  98782. e->band[3].begin=9; e->band[3].end=8;
  98783. e->band[4].begin=13; e->band[4].end=8;
  98784. e->band[5].begin=17; e->band[5].end=8;
  98785. e->band[6].begin=22; e->band[6].end=8;
  98786. for(j=0;j<VE_BANDS;j++){
  98787. n=e->band[j].end;
  98788. e->band[j].window=(float*)_ogg_malloc(n*sizeof(*e->band[0].window));
  98789. for(i=0;i<n;i++){
  98790. e->band[j].window[i]=sin((i+.5)/n*M_PI);
  98791. e->band[j].total+=e->band[j].window[i];
  98792. }
  98793. e->band[j].total=1./e->band[j].total;
  98794. }
  98795. e->filter=(envelope_filter_state*)_ogg_calloc(VE_BANDS*ch,sizeof(*e->filter));
  98796. e->mark=(int*)_ogg_calloc(e->storage,sizeof(*e->mark));
  98797. }
  98798. void _ve_envelope_clear(envelope_lookup *e){
  98799. int i;
  98800. mdct_clear(&e->mdct);
  98801. for(i=0;i<VE_BANDS;i++)
  98802. _ogg_free(e->band[i].window);
  98803. _ogg_free(e->mdct_win);
  98804. _ogg_free(e->filter);
  98805. _ogg_free(e->mark);
  98806. memset(e,0,sizeof(*e));
  98807. }
  98808. static int _ve_amp(envelope_lookup *ve,
  98809. vorbis_info_psy_global *gi,
  98810. float *data,
  98811. envelope_band *bands,
  98812. envelope_filter_state *filters,
  98813. long pos){
  98814. long n=ve->winlength;
  98815. int ret=0;
  98816. long i,j;
  98817. float decay;
  98818. float minV=ve->minenergy;
  98819. float *vec=(float*) alloca(n*sizeof(*vec));
  98820. int stretch=max(VE_MINSTRETCH,ve->stretch/2);
  98821. float penalty=gi->stretch_penalty-(ve->stretch/2-VE_MINSTRETCH);
  98822. if(penalty<0.f)penalty=0.f;
  98823. if(penalty>gi->stretch_penalty)penalty=gi->stretch_penalty;
  98824. for(i=0;i<n;i++)
  98825. vec[i]=data[i]*ve->mdct_win[i];
  98826. mdct_forward(&ve->mdct,vec,vec);
  98827. {
  98828. float temp=vec[0]*vec[0]+.7*vec[1]*vec[1]+.2*vec[2]*vec[2];
  98829. int ptr=filters->nearptr;
  98830. if(ptr==0){
  98831. decay=filters->nearDC_acc=filters->nearDC_partialacc+temp;
  98832. filters->nearDC_partialacc=temp;
  98833. }else{
  98834. decay=filters->nearDC_acc+=temp;
  98835. filters->nearDC_partialacc+=temp;
  98836. }
  98837. filters->nearDC_acc-=filters->nearDC[ptr];
  98838. filters->nearDC[ptr]=temp;
  98839. decay*=(1./(VE_NEARDC+1));
  98840. filters->nearptr++;
  98841. if(filters->nearptr>=VE_NEARDC)filters->nearptr=0;
  98842. decay=todB(&decay)*.5-15.f;
  98843. }
  98844. for(i=0;i<n/2;i+=2){
  98845. float val=vec[i]*vec[i]+vec[i+1]*vec[i+1];
  98846. val=todB(&val)*.5f;
  98847. if(val<decay)val=decay;
  98848. if(val<minV)val=minV;
  98849. vec[i>>1]=val;
  98850. decay-=8.;
  98851. }
  98852. for(j=0;j<VE_BANDS;j++){
  98853. float acc=0.;
  98854. float valmax,valmin;
  98855. for(i=0;i<bands[j].end;i++)
  98856. acc+=vec[i+bands[j].begin]*bands[j].window[i];
  98857. acc*=bands[j].total;
  98858. {
  98859. int p,thisx=filters[j].ampptr;
  98860. float postmax,postmin,premax=-99999.f,premin=99999.f;
  98861. p=thisx;
  98862. p--;
  98863. if(p<0)p+=VE_AMP;
  98864. postmax=max(acc,filters[j].ampbuf[p]);
  98865. postmin=min(acc,filters[j].ampbuf[p]);
  98866. for(i=0;i<stretch;i++){
  98867. p--;
  98868. if(p<0)p+=VE_AMP;
  98869. premax=max(premax,filters[j].ampbuf[p]);
  98870. premin=min(premin,filters[j].ampbuf[p]);
  98871. }
  98872. valmin=postmin-premin;
  98873. valmax=postmax-premax;
  98874. filters[j].ampbuf[thisx]=acc;
  98875. filters[j].ampptr++;
  98876. if(filters[j].ampptr>=VE_AMP)filters[j].ampptr=0;
  98877. }
  98878. if(valmax>gi->preecho_thresh[j]+penalty){
  98879. ret|=1;
  98880. ret|=4;
  98881. }
  98882. if(valmin<gi->postecho_thresh[j]-penalty)ret|=2;
  98883. }
  98884. return(ret);
  98885. }
  98886. #if 0
  98887. static int seq=0;
  98888. static ogg_int64_t totalshift=-1024;
  98889. #endif
  98890. long _ve_envelope_search(vorbis_dsp_state *v){
  98891. vorbis_info *vi=v->vi;
  98892. codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
  98893. vorbis_info_psy_global *gi=&ci->psy_g_param;
  98894. envelope_lookup *ve=((private_state *)(v->backend_state))->ve;
  98895. long i,j;
  98896. int first=ve->current/ve->searchstep;
  98897. int last=v->pcm_current/ve->searchstep-VE_WIN;
  98898. if(first<0)first=0;
  98899. if(last+VE_WIN+VE_POST>ve->storage){
  98900. ve->storage=last+VE_WIN+VE_POST; /* be sure */
  98901. ve->mark=(int*)_ogg_realloc(ve->mark,ve->storage*sizeof(*ve->mark));
  98902. }
  98903. for(j=first;j<last;j++){
  98904. int ret=0;
  98905. ve->stretch++;
  98906. if(ve->stretch>VE_MAXSTRETCH*2)
  98907. ve->stretch=VE_MAXSTRETCH*2;
  98908. for(i=0;i<ve->ch;i++){
  98909. float *pcm=v->pcm[i]+ve->searchstep*(j);
  98910. ret|=_ve_amp(ve,gi,pcm,ve->band,ve->filter+i*VE_BANDS,j);
  98911. }
  98912. ve->mark[j+VE_POST]=0;
  98913. if(ret&1){
  98914. ve->mark[j]=1;
  98915. ve->mark[j+1]=1;
  98916. }
  98917. if(ret&2){
  98918. ve->mark[j]=1;
  98919. if(j>0)ve->mark[j-1]=1;
  98920. }
  98921. if(ret&4)ve->stretch=-1;
  98922. }
  98923. ve->current=last*ve->searchstep;
  98924. {
  98925. long centerW=v->centerW;
  98926. long testW=
  98927. centerW+
  98928. ci->blocksizes[v->W]/4+
  98929. ci->blocksizes[1]/2+
  98930. ci->blocksizes[0]/4;
  98931. j=ve->cursor;
  98932. while(j<ve->current-(ve->searchstep)){/* account for postecho
  98933. working back one window */
  98934. if(j>=testW)return(1);
  98935. ve->cursor=j;
  98936. if(ve->mark[j/ve->searchstep]){
  98937. if(j>centerW){
  98938. #if 0
  98939. if(j>ve->curmark){
  98940. float *marker=alloca(v->pcm_current*sizeof(*marker));
  98941. int l,m;
  98942. memset(marker,0,sizeof(*marker)*v->pcm_current);
  98943. fprintf(stderr,"mark! seq=%d, cursor:%fs time:%fs\n",
  98944. seq,
  98945. (totalshift+ve->cursor)/44100.,
  98946. (totalshift+j)/44100.);
  98947. _analysis_output_always("pcmL",seq,v->pcm[0],v->pcm_current,0,0,totalshift);
  98948. _analysis_output_always("pcmR",seq,v->pcm[1],v->pcm_current,0,0,totalshift);
  98949. _analysis_output_always("markL",seq,v->pcm[0],j,0,0,totalshift);
  98950. _analysis_output_always("markR",seq,v->pcm[1],j,0,0,totalshift);
  98951. for(m=0;m<VE_BANDS;m++){
  98952. char buf[80];
  98953. sprintf(buf,"delL%d",m);
  98954. for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->filter[m].markers[l]*.1;
  98955. _analysis_output_always(buf,seq,marker,v->pcm_current,0,0,totalshift);
  98956. }
  98957. for(m=0;m<VE_BANDS;m++){
  98958. char buf[80];
  98959. sprintf(buf,"delR%d",m);
  98960. for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->filter[m+VE_BANDS].markers[l]*.1;
  98961. _analysis_output_always(buf,seq,marker,v->pcm_current,0,0,totalshift);
  98962. }
  98963. for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->mark[l]*.4;
  98964. _analysis_output_always("mark",seq,marker,v->pcm_current,0,0,totalshift);
  98965. seq++;
  98966. }
  98967. #endif
  98968. ve->curmark=j;
  98969. if(j>=testW)return(1);
  98970. return(0);
  98971. }
  98972. }
  98973. j+=ve->searchstep;
  98974. }
  98975. }
  98976. return(-1);
  98977. }
  98978. int _ve_envelope_mark(vorbis_dsp_state *v){
  98979. envelope_lookup *ve=((private_state *)(v->backend_state))->ve;
  98980. vorbis_info *vi=v->vi;
  98981. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98982. long centerW=v->centerW;
  98983. long beginW=centerW-ci->blocksizes[v->W]/4;
  98984. long endW=centerW+ci->blocksizes[v->W]/4;
  98985. if(v->W){
  98986. beginW-=ci->blocksizes[v->lW]/4;
  98987. endW+=ci->blocksizes[v->nW]/4;
  98988. }else{
  98989. beginW-=ci->blocksizes[0]/4;
  98990. endW+=ci->blocksizes[0]/4;
  98991. }
  98992. if(ve->curmark>=beginW && ve->curmark<endW)return(1);
  98993. {
  98994. long first=beginW/ve->searchstep;
  98995. long last=endW/ve->searchstep;
  98996. long i;
  98997. for(i=first;i<last;i++)
  98998. if(ve->mark[i])return(1);
  98999. }
  99000. return(0);
  99001. }
  99002. void _ve_envelope_shift(envelope_lookup *e,long shift){
  99003. int smallsize=e->current/e->searchstep+VE_POST; /* adjust for placing marks
  99004. ahead of ve->current */
  99005. int smallshift=shift/e->searchstep;
  99006. memmove(e->mark,e->mark+smallshift,(smallsize-smallshift)*sizeof(*e->mark));
  99007. #if 0
  99008. for(i=0;i<VE_BANDS*e->ch;i++)
  99009. memmove(e->filter[i].markers,
  99010. e->filter[i].markers+smallshift,
  99011. (1024-smallshift)*sizeof(*(*e->filter).markers));
  99012. totalshift+=shift;
  99013. #endif
  99014. e->current-=shift;
  99015. if(e->curmark>=0)
  99016. e->curmark-=shift;
  99017. e->cursor-=shift;
  99018. }
  99019. #endif
  99020. /*** End of inlined file: envelope.c ***/
  99021. /*** Start of inlined file: floor0.c ***/
  99022. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  99023. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  99024. // tasks..
  99025. #if JUCE_MSVC
  99026. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  99027. #endif
  99028. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  99029. #if JUCE_USE_OGGVORBIS
  99030. #include <stdlib.h>
  99031. #include <string.h>
  99032. #include <math.h>
  99033. /*** Start of inlined file: lsp.h ***/
  99034. #ifndef _V_LSP_H_
  99035. #define _V_LSP_H_
  99036. extern int vorbis_lpc_to_lsp(float *lpc,float *lsp,int m);
  99037. extern void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,
  99038. float *lsp,int m,
  99039. float amp,float ampoffset);
  99040. #endif
  99041. /*** End of inlined file: lsp.h ***/
  99042. #include <stdio.h>
  99043. typedef struct {
  99044. int ln;
  99045. int m;
  99046. int **linearmap;
  99047. int n[2];
  99048. vorbis_info_floor0 *vi;
  99049. long bits;
  99050. long frames;
  99051. } vorbis_look_floor0;
  99052. static void floor0_free_info(vorbis_info_floor *i){
  99053. vorbis_info_floor0 *info=(vorbis_info_floor0 *)i;
  99054. if(info){
  99055. memset(info,0,sizeof(*info));
  99056. _ogg_free(info);
  99057. }
  99058. }
  99059. static void floor0_free_look(vorbis_look_floor *i){
  99060. vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
  99061. if(look){
  99062. if(look->linearmap){
  99063. if(look->linearmap[0])_ogg_free(look->linearmap[0]);
  99064. if(look->linearmap[1])_ogg_free(look->linearmap[1]);
  99065. _ogg_free(look->linearmap);
  99066. }
  99067. memset(look,0,sizeof(*look));
  99068. _ogg_free(look);
  99069. }
  99070. }
  99071. static vorbis_info_floor *floor0_unpack (vorbis_info *vi,oggpack_buffer *opb){
  99072. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99073. int j;
  99074. vorbis_info_floor0 *info=(vorbis_info_floor0*)_ogg_malloc(sizeof(*info));
  99075. info->order=oggpack_read(opb,8);
  99076. info->rate=oggpack_read(opb,16);
  99077. info->barkmap=oggpack_read(opb,16);
  99078. info->ampbits=oggpack_read(opb,6);
  99079. info->ampdB=oggpack_read(opb,8);
  99080. info->numbooks=oggpack_read(opb,4)+1;
  99081. if(info->order<1)goto err_out;
  99082. if(info->rate<1)goto err_out;
  99083. if(info->barkmap<1)goto err_out;
  99084. if(info->numbooks<1)goto err_out;
  99085. for(j=0;j<info->numbooks;j++){
  99086. info->books[j]=oggpack_read(opb,8);
  99087. if(info->books[j]<0 || info->books[j]>=ci->books)goto err_out;
  99088. }
  99089. return(info);
  99090. err_out:
  99091. floor0_free_info(info);
  99092. return(NULL);
  99093. }
  99094. static void floor0_map_lazy_init(vorbis_block *vb,
  99095. vorbis_info_floor *infoX,
  99096. vorbis_look_floor0 *look){
  99097. if(!look->linearmap[vb->W]){
  99098. vorbis_dsp_state *vd=vb->vd;
  99099. vorbis_info *vi=vd->vi;
  99100. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99101. vorbis_info_floor0 *info=(vorbis_info_floor0 *)infoX;
  99102. int W=vb->W;
  99103. int n=ci->blocksizes[W]/2,j;
  99104. float scale=look->ln/toBARK(info->rate/2.f);
  99105. look->linearmap[W]=(int*)_ogg_malloc((n+1)*sizeof(**look->linearmap));
  99106. for(j=0;j<n;j++){
  99107. int val=floor( toBARK((info->rate/2.f)/n*j)
  99108. *scale); /* bark numbers represent band edges */
  99109. if(val>=look->ln)val=look->ln-1; /* guard against the approximation */
  99110. look->linearmap[W][j]=val;
  99111. }
  99112. look->linearmap[W][j]=-1;
  99113. look->n[W]=n;
  99114. }
  99115. }
  99116. static vorbis_look_floor *floor0_look(vorbis_dsp_state *vd,
  99117. vorbis_info_floor *i){
  99118. vorbis_info_floor0 *info=(vorbis_info_floor0*)i;
  99119. vorbis_look_floor0 *look=(vorbis_look_floor0*)_ogg_calloc(1,sizeof(*look));
  99120. look->m=info->order;
  99121. look->ln=info->barkmap;
  99122. look->vi=info;
  99123. look->linearmap=(int**)_ogg_calloc(2,sizeof(*look->linearmap));
  99124. return look;
  99125. }
  99126. static void *floor0_inverse1(vorbis_block *vb,vorbis_look_floor *i){
  99127. vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
  99128. vorbis_info_floor0 *info=look->vi;
  99129. int j,k;
  99130. int ampraw=oggpack_read(&vb->opb,info->ampbits);
  99131. if(ampraw>0){ /* also handles the -1 out of data case */
  99132. long maxval=(1<<info->ampbits)-1;
  99133. float amp=(float)ampraw/maxval*info->ampdB;
  99134. int booknum=oggpack_read(&vb->opb,_ilog(info->numbooks));
  99135. if(booknum!=-1 && booknum<info->numbooks){ /* be paranoid */
  99136. codec_setup_info *ci=(codec_setup_info *)vb->vd->vi->codec_setup;
  99137. codebook *b=ci->fullbooks+info->books[booknum];
  99138. float last=0.f;
  99139. float *lsp=(float*)_vorbis_block_alloc(vb,sizeof(*lsp)*(look->m+b->dim+1));
  99140. for(j=0;j<look->m;j+=b->dim)
  99141. if(vorbis_book_decodev_set(b,lsp+j,&vb->opb,b->dim)==-1)goto eop;
  99142. for(j=0;j<look->m;){
  99143. for(k=0;k<b->dim;k++,j++)lsp[j]+=last;
  99144. last=lsp[j-1];
  99145. }
  99146. lsp[look->m]=amp;
  99147. return(lsp);
  99148. }
  99149. }
  99150. eop:
  99151. return(NULL);
  99152. }
  99153. static int floor0_inverse2(vorbis_block *vb,vorbis_look_floor *i,
  99154. void *memo,float *out){
  99155. vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
  99156. vorbis_info_floor0 *info=look->vi;
  99157. floor0_map_lazy_init(vb,info,look);
  99158. if(memo){
  99159. float *lsp=(float *)memo;
  99160. float amp=lsp[look->m];
  99161. vorbis_lsp_to_curve(out,
  99162. look->linearmap[vb->W],
  99163. look->n[vb->W],
  99164. look->ln,
  99165. lsp,look->m,amp,(float)info->ampdB);
  99166. return(1);
  99167. }
  99168. memset(out,0,sizeof(*out)*look->n[vb->W]);
  99169. return(0);
  99170. }
  99171. vorbis_func_floor floor0_exportbundle={
  99172. NULL,&floor0_unpack,&floor0_look,&floor0_free_info,
  99173. &floor0_free_look,&floor0_inverse1,&floor0_inverse2
  99174. };
  99175. #endif
  99176. /*** End of inlined file: floor0.c ***/
  99177. /*** Start of inlined file: floor1.c ***/
  99178. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  99179. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  99180. // tasks..
  99181. #if JUCE_MSVC
  99182. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  99183. #endif
  99184. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  99185. #if JUCE_USE_OGGVORBIS
  99186. #include <stdlib.h>
  99187. #include <string.h>
  99188. #include <math.h>
  99189. #include <stdio.h>
  99190. #define floor1_rangedB 140 /* floor 1 fixed at -140dB to 0dB range */
  99191. typedef struct {
  99192. int sorted_index[VIF_POSIT+2];
  99193. int forward_index[VIF_POSIT+2];
  99194. int reverse_index[VIF_POSIT+2];
  99195. int hineighbor[VIF_POSIT];
  99196. int loneighbor[VIF_POSIT];
  99197. int posts;
  99198. int n;
  99199. int quant_q;
  99200. vorbis_info_floor1 *vi;
  99201. long phrasebits;
  99202. long postbits;
  99203. long frames;
  99204. } vorbis_look_floor1;
  99205. typedef struct lsfit_acc{
  99206. long x0;
  99207. long x1;
  99208. long xa;
  99209. long ya;
  99210. long x2a;
  99211. long y2a;
  99212. long xya;
  99213. long an;
  99214. } lsfit_acc;
  99215. static void floor1_free_info(vorbis_info_floor *i){
  99216. vorbis_info_floor1 *info=(vorbis_info_floor1 *)i;
  99217. if(info){
  99218. memset(info,0,sizeof(*info));
  99219. _ogg_free(info);
  99220. }
  99221. }
  99222. static void floor1_free_look(vorbis_look_floor *i){
  99223. vorbis_look_floor1 *look=(vorbis_look_floor1 *)i;
  99224. if(look){
  99225. memset(look,0,sizeof(*look));
  99226. _ogg_free(look);
  99227. }
  99228. }
  99229. static void floor1_pack (vorbis_info_floor *i,oggpack_buffer *opb){
  99230. vorbis_info_floor1 *info=(vorbis_info_floor1 *)i;
  99231. int j,k;
  99232. int count=0;
  99233. int rangebits;
  99234. int maxposit=info->postlist[1];
  99235. int maxclass=-1;
  99236. oggpack_write(opb,info->partitions,5); /* only 0 to 31 legal */
  99237. for(j=0;j<info->partitions;j++){
  99238. oggpack_write(opb,info->partitionclass[j],4); /* only 0 to 15 legal */
  99239. if(maxclass<info->partitionclass[j])maxclass=info->partitionclass[j];
  99240. }
  99241. for(j=0;j<maxclass+1;j++){
  99242. oggpack_write(opb,info->class_dim[j]-1,3); /* 1 to 8 */
  99243. oggpack_write(opb,info->class_subs[j],2); /* 0 to 3 */
  99244. if(info->class_subs[j])oggpack_write(opb,info->class_book[j],8);
  99245. for(k=0;k<(1<<info->class_subs[j]);k++)
  99246. oggpack_write(opb,info->class_subbook[j][k]+1,8);
  99247. }
  99248. oggpack_write(opb,info->mult-1,2); /* only 1,2,3,4 legal now */
  99249. oggpack_write(opb,ilog2(maxposit),4);
  99250. rangebits=ilog2(maxposit);
  99251. for(j=0,k=0;j<info->partitions;j++){
  99252. count+=info->class_dim[info->partitionclass[j]];
  99253. for(;k<count;k++)
  99254. oggpack_write(opb,info->postlist[k+2],rangebits);
  99255. }
  99256. }
  99257. static vorbis_info_floor *floor1_unpack (vorbis_info *vi,oggpack_buffer *opb){
  99258. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99259. int j,k,count=0,maxclass=-1,rangebits;
  99260. vorbis_info_floor1 *info=(vorbis_info_floor1*)_ogg_calloc(1,sizeof(*info));
  99261. info->partitions=oggpack_read(opb,5); /* only 0 to 31 legal */
  99262. for(j=0;j<info->partitions;j++){
  99263. info->partitionclass[j]=oggpack_read(opb,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. info->class_dim[j]=oggpack_read(opb,3)+1; /* 1 to 8 */
  99268. info->class_subs[j]=oggpack_read(opb,2); /* 0,1,2,3 bits */
  99269. if(info->class_subs[j]<0)
  99270. goto err_out;
  99271. if(info->class_subs[j])info->class_book[j]=oggpack_read(opb,8);
  99272. if(info->class_book[j]<0 || info->class_book[j]>=ci->books)
  99273. goto err_out;
  99274. for(k=0;k<(1<<info->class_subs[j]);k++){
  99275. info->class_subbook[j][k]=oggpack_read(opb,8)-1;
  99276. if(info->class_subbook[j][k]<-1 || info->class_subbook[j][k]>=ci->books)
  99277. goto err_out;
  99278. }
  99279. }
  99280. info->mult=oggpack_read(opb,2)+1; /* only 1,2,3,4 legal now */
  99281. rangebits=oggpack_read(opb,4);
  99282. for(j=0,k=0;j<info->partitions;j++){
  99283. count+=info->class_dim[info->partitionclass[j]];
  99284. for(;k<count;k++){
  99285. int t=info->postlist[k+2]=oggpack_read(opb,rangebits);
  99286. if(t<0 || t>=(1<<rangebits))
  99287. goto err_out;
  99288. }
  99289. }
  99290. info->postlist[0]=0;
  99291. info->postlist[1]=1<<rangebits;
  99292. return(info);
  99293. err_out:
  99294. floor1_free_info(info);
  99295. return(NULL);
  99296. }
  99297. static int icomp(const void *a,const void *b){
  99298. return(**(int **)a-**(int **)b);
  99299. }
  99300. static vorbis_look_floor *floor1_look(vorbis_dsp_state *vd,
  99301. vorbis_info_floor *in){
  99302. int *sortpointer[VIF_POSIT+2];
  99303. vorbis_info_floor1 *info=(vorbis_info_floor1*)in;
  99304. vorbis_look_floor1 *look=(vorbis_look_floor1*)_ogg_calloc(1,sizeof(*look));
  99305. int i,j,n=0;
  99306. look->vi=info;
  99307. look->n=info->postlist[1];
  99308. for(i=0;i<info->partitions;i++)n+=info->class_dim[info->partitionclass[i]];
  99309. n+=2;
  99310. look->posts=n;
  99311. for(i=0;i<n;i++)sortpointer[i]=info->postlist+i;
  99312. qsort(sortpointer,n,sizeof(*sortpointer),icomp);
  99313. for(i=0;i<n;i++)look->forward_index[i]=sortpointer[i]-info->postlist;
  99314. for(i=0;i<n;i++)look->reverse_index[look->forward_index[i]]=i;
  99315. for(i=0;i<n;i++)look->sorted_index[i]=info->postlist[look->forward_index[i]];
  99316. switch(info->mult){
  99317. case 1: /* 1024 -> 256 */
  99318. look->quant_q=256;
  99319. break;
  99320. case 2: /* 1024 -> 128 */
  99321. look->quant_q=128;
  99322. break;
  99323. case 3: /* 1024 -> 86 */
  99324. look->quant_q=86;
  99325. break;
  99326. case 4: /* 1024 -> 64 */
  99327. look->quant_q=64;
  99328. break;
  99329. }
  99330. for(i=0;i<n-2;i++){
  99331. int lo=0;
  99332. int hi=1;
  99333. int lx=0;
  99334. int hx=look->n;
  99335. int currentx=info->postlist[i+2];
  99336. for(j=0;j<i+2;j++){
  99337. int x=info->postlist[j];
  99338. if(x>lx && x<currentx){
  99339. lo=j;
  99340. lx=x;
  99341. }
  99342. if(x<hx && x>currentx){
  99343. hi=j;
  99344. hx=x;
  99345. }
  99346. }
  99347. look->loneighbor[i]=lo;
  99348. look->hineighbor[i]=hi;
  99349. }
  99350. return(look);
  99351. }
  99352. static int render_point(int x0,int x1,int y0,int y1,int x){
  99353. y0&=0x7fff; /* mask off flag */
  99354. y1&=0x7fff;
  99355. {
  99356. int dy=y1-y0;
  99357. int adx=x1-x0;
  99358. int ady=abs(dy);
  99359. int err=ady*(x-x0);
  99360. int off=err/adx;
  99361. if(dy<0)return(y0-off);
  99362. return(y0+off);
  99363. }
  99364. }
  99365. static int vorbis_dBquant(const float *x){
  99366. int i= *x*7.3142857f+1023.5f;
  99367. if(i>1023)return(1023);
  99368. if(i<0)return(0);
  99369. return i;
  99370. }
  99371. static float FLOOR1_fromdB_LOOKUP[256]={
  99372. 1.0649863e-07F, 1.1341951e-07F, 1.2079015e-07F, 1.2863978e-07F,
  99373. 1.3699951e-07F, 1.4590251e-07F, 1.5538408e-07F, 1.6548181e-07F,
  99374. 1.7623575e-07F, 1.8768855e-07F, 1.9988561e-07F, 2.128753e-07F,
  99375. 2.2670913e-07F, 2.4144197e-07F, 2.5713223e-07F, 2.7384213e-07F,
  99376. 2.9163793e-07F, 3.1059021e-07F, 3.3077411e-07F, 3.5226968e-07F,
  99377. 3.7516214e-07F, 3.9954229e-07F, 4.2550680e-07F, 4.5315863e-07F,
  99378. 4.8260743e-07F, 5.1396998e-07F, 5.4737065e-07F, 5.8294187e-07F,
  99379. 6.2082472e-07F, 6.6116941e-07F, 7.0413592e-07F, 7.4989464e-07F,
  99380. 7.9862701e-07F, 8.5052630e-07F, 9.0579828e-07F, 9.6466216e-07F,
  99381. 1.0273513e-06F, 1.0941144e-06F, 1.1652161e-06F, 1.2409384e-06F,
  99382. 1.3215816e-06F, 1.4074654e-06F, 1.4989305e-06F, 1.5963394e-06F,
  99383. 1.7000785e-06F, 1.8105592e-06F, 1.9282195e-06F, 2.0535261e-06F,
  99384. 2.1869758e-06F, 2.3290978e-06F, 2.4804557e-06F, 2.6416497e-06F,
  99385. 2.8133190e-06F, 2.9961443e-06F, 3.1908506e-06F, 3.3982101e-06F,
  99386. 3.6190449e-06F, 3.8542308e-06F, 4.1047004e-06F, 4.3714470e-06F,
  99387. 4.6555282e-06F, 4.9580707e-06F, 5.2802740e-06F, 5.6234160e-06F,
  99388. 5.9888572e-06F, 6.3780469e-06F, 6.7925283e-06F, 7.2339451e-06F,
  99389. 7.7040476e-06F, 8.2047000e-06F, 8.7378876e-06F, 9.3057248e-06F,
  99390. 9.9104632e-06F, 1.0554501e-05F, 1.1240392e-05F, 1.1970856e-05F,
  99391. 1.2748789e-05F, 1.3577278e-05F, 1.4459606e-05F, 1.5399272e-05F,
  99392. 1.6400004e-05F, 1.7465768e-05F, 1.8600792e-05F, 1.9809576e-05F,
  99393. 2.1096914e-05F, 2.2467911e-05F, 2.3928002e-05F, 2.5482978e-05F,
  99394. 2.7139006e-05F, 2.8902651e-05F, 3.0780908e-05F, 3.2781225e-05F,
  99395. 3.4911534e-05F, 3.7180282e-05F, 3.9596466e-05F, 4.2169667e-05F,
  99396. 4.4910090e-05F, 4.7828601e-05F, 5.0936773e-05F, 5.4246931e-05F,
  99397. 5.7772202e-05F, 6.1526565e-05F, 6.5524908e-05F, 6.9783085e-05F,
  99398. 7.4317983e-05F, 7.9147585e-05F, 8.4291040e-05F, 8.9768747e-05F,
  99399. 9.5602426e-05F, 0.00010181521F, 0.00010843174F, 0.00011547824F,
  99400. 0.00012298267F, 0.00013097477F, 0.00013948625F, 0.00014855085F,
  99401. 0.00015820453F, 0.00016848555F, 0.00017943469F, 0.00019109536F,
  99402. 0.00020351382F, 0.00021673929F, 0.00023082423F, 0.00024582449F,
  99403. 0.00026179955F, 0.00027881276F, 0.00029693158F, 0.00031622787F,
  99404. 0.00033677814F, 0.00035866388F, 0.00038197188F, 0.00040679456F,
  99405. 0.00043323036F, 0.00046138411F, 0.00049136745F, 0.00052329927F,
  99406. 0.00055730621F, 0.00059352311F, 0.00063209358F, 0.00067317058F,
  99407. 0.00071691700F, 0.00076350630F, 0.00081312324F, 0.00086596457F,
  99408. 0.00092223983F, 0.00098217216F, 0.0010459992F, 0.0011139742F,
  99409. 0.0011863665F, 0.0012634633F, 0.0013455702F, 0.0014330129F,
  99410. 0.0015261382F, 0.0016253153F, 0.0017309374F, 0.0018434235F,
  99411. 0.0019632195F, 0.0020908006F, 0.0022266726F, 0.0023713743F,
  99412. 0.0025254795F, 0.0026895994F, 0.0028643847F, 0.0030505286F,
  99413. 0.0032487691F, 0.0034598925F, 0.0036847358F, 0.0039241906F,
  99414. 0.0041792066F, 0.0044507950F, 0.0047400328F, 0.0050480668F,
  99415. 0.0053761186F, 0.0057254891F, 0.0060975636F, 0.0064938176F,
  99416. 0.0069158225F, 0.0073652516F, 0.0078438871F, 0.0083536271F,
  99417. 0.0088964928F, 0.009474637F, 0.010090352F, 0.010746080F,
  99418. 0.011444421F, 0.012188144F, 0.012980198F, 0.013823725F,
  99419. 0.014722068F, 0.015678791F, 0.016697687F, 0.017782797F,
  99420. 0.018938423F, 0.020169149F, 0.021479854F, 0.022875735F,
  99421. 0.024362330F, 0.025945531F, 0.027631618F, 0.029427276F,
  99422. 0.031339626F, 0.033376252F, 0.035545228F, 0.037855157F,
  99423. 0.040315199F, 0.042935108F, 0.045725273F, 0.048696758F,
  99424. 0.051861348F, 0.055231591F, 0.058820850F, 0.062643361F,
  99425. 0.066714279F, 0.071049749F, 0.075666962F, 0.080584227F,
  99426. 0.085821044F, 0.091398179F, 0.097337747F, 0.10366330F,
  99427. 0.11039993F, 0.11757434F, 0.12521498F, 0.13335215F,
  99428. 0.14201813F, 0.15124727F, 0.16107617F, 0.17154380F,
  99429. 0.18269168F, 0.19456402F, 0.20720788F, 0.22067342F,
  99430. 0.23501402F, 0.25028656F, 0.26655159F, 0.28387361F,
  99431. 0.30232132F, 0.32196786F, 0.34289114F, 0.36517414F,
  99432. 0.38890521F, 0.41417847F, 0.44109412F, 0.46975890F,
  99433. 0.50028648F, 0.53279791F, 0.56742212F, 0.60429640F,
  99434. 0.64356699F, 0.68538959F, 0.72993007F, 0.77736504F,
  99435. 0.82788260F, 0.88168307F, 0.9389798F, 1.F,
  99436. };
  99437. static void render_line(int x0,int x1,int y0,int y1,float *d){
  99438. int dy=y1-y0;
  99439. int adx=x1-x0;
  99440. int ady=abs(dy);
  99441. int base=dy/adx;
  99442. int sy=(dy<0?base-1:base+1);
  99443. int x=x0;
  99444. int y=y0;
  99445. int err=0;
  99446. ady-=abs(base*adx);
  99447. d[x]*=FLOOR1_fromdB_LOOKUP[y];
  99448. while(++x<x1){
  99449. err=err+ady;
  99450. if(err>=adx){
  99451. err-=adx;
  99452. y+=sy;
  99453. }else{
  99454. y+=base;
  99455. }
  99456. d[x]*=FLOOR1_fromdB_LOOKUP[y];
  99457. }
  99458. }
  99459. static void render_line0(int x0,int x1,int y0,int y1,int *d){
  99460. int dy=y1-y0;
  99461. int adx=x1-x0;
  99462. int ady=abs(dy);
  99463. int base=dy/adx;
  99464. int sy=(dy<0?base-1:base+1);
  99465. int x=x0;
  99466. int y=y0;
  99467. int err=0;
  99468. ady-=abs(base*adx);
  99469. d[x]=y;
  99470. while(++x<x1){
  99471. err=err+ady;
  99472. if(err>=adx){
  99473. err-=adx;
  99474. y+=sy;
  99475. }else{
  99476. y+=base;
  99477. }
  99478. d[x]=y;
  99479. }
  99480. }
  99481. static int accumulate_fit(const float *flr,const float *mdct,
  99482. int x0, int x1,lsfit_acc *a,
  99483. int n,vorbis_info_floor1 *info){
  99484. long i;
  99485. 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;
  99486. memset(a,0,sizeof(*a));
  99487. a->x0=x0;
  99488. a->x1=x1;
  99489. if(x1>=n)x1=n-1;
  99490. for(i=x0;i<=x1;i++){
  99491. int quantized=vorbis_dBquant(flr+i);
  99492. if(quantized){
  99493. if(mdct[i]+info->twofitatten>=flr[i]){
  99494. xa += i;
  99495. ya += quantized;
  99496. x2a += i*i;
  99497. y2a += quantized*quantized;
  99498. xya += i*quantized;
  99499. na++;
  99500. }else{
  99501. xb += i;
  99502. yb += quantized;
  99503. x2b += i*i;
  99504. y2b += quantized*quantized;
  99505. xyb += i*quantized;
  99506. nb++;
  99507. }
  99508. }
  99509. }
  99510. xb+=xa;
  99511. yb+=ya;
  99512. x2b+=x2a;
  99513. y2b+=y2a;
  99514. xyb+=xya;
  99515. nb+=na;
  99516. {
  99517. int weight=nb*info->twofitweight/(na+1);
  99518. a->xa=xa*weight+xb;
  99519. a->ya=ya*weight+yb;
  99520. a->x2a=x2a*weight+x2b;
  99521. a->y2a=y2a*weight+y2b;
  99522. a->xya=xya*weight+xyb;
  99523. a->an=na*weight+nb;
  99524. }
  99525. return(na);
  99526. }
  99527. static void fit_line(lsfit_acc *a,int fits,int *y0,int *y1){
  99528. long x=0,y=0,x2=0,y2=0,xy=0,an=0,i;
  99529. long x0=a[0].x0;
  99530. long x1=a[fits-1].x1;
  99531. for(i=0;i<fits;i++){
  99532. x+=a[i].xa;
  99533. y+=a[i].ya;
  99534. x2+=a[i].x2a;
  99535. y2+=a[i].y2a;
  99536. xy+=a[i].xya;
  99537. an+=a[i].an;
  99538. }
  99539. if(*y0>=0){
  99540. x+= x0;
  99541. y+= *y0;
  99542. x2+= x0 * x0;
  99543. y2+= *y0 * *y0;
  99544. xy+= *y0 * x0;
  99545. an++;
  99546. }
  99547. if(*y1>=0){
  99548. x+= x1;
  99549. y+= *y1;
  99550. x2+= x1 * x1;
  99551. y2+= *y1 * *y1;
  99552. xy+= *y1 * x1;
  99553. an++;
  99554. }
  99555. if(an){
  99556. double fx=x;
  99557. double fy=y;
  99558. double fx2=x2;
  99559. double fxy=xy;
  99560. double denom=1./(an*fx2-fx*fx);
  99561. double a=(fy*fx2-fxy*fx)*denom;
  99562. double b=(an*fxy-fx*fy)*denom;
  99563. *y0=rint(a+b*x0);
  99564. *y1=rint(a+b*x1);
  99565. if(*y0>1023)*y0=1023;
  99566. if(*y1>1023)*y1=1023;
  99567. if(*y0<0)*y0=0;
  99568. if(*y1<0)*y1=0;
  99569. }else{
  99570. *y0=0;
  99571. *y1=0;
  99572. }
  99573. }
  99574. static int inspect_error(int x0,int x1,int y0,int y1,const float *mask,
  99575. const float *mdct,
  99576. vorbis_info_floor1 *info){
  99577. int dy=y1-y0;
  99578. int adx=x1-x0;
  99579. int ady=abs(dy);
  99580. int base=dy/adx;
  99581. int sy=(dy<0?base-1:base+1);
  99582. int x=x0;
  99583. int y=y0;
  99584. int err=0;
  99585. int val=vorbis_dBquant(mask+x);
  99586. int mse=0;
  99587. int n=0;
  99588. ady-=abs(base*adx);
  99589. mse=(y-val);
  99590. mse*=mse;
  99591. n++;
  99592. if(mdct[x]+info->twofitatten>=mask[x]){
  99593. if(y+info->maxover<val)return(1);
  99594. if(y-info->maxunder>val)return(1);
  99595. }
  99596. while(++x<x1){
  99597. err=err+ady;
  99598. if(err>=adx){
  99599. err-=adx;
  99600. y+=sy;
  99601. }else{
  99602. y+=base;
  99603. }
  99604. val=vorbis_dBquant(mask+x);
  99605. mse+=((y-val)*(y-val));
  99606. n++;
  99607. if(mdct[x]+info->twofitatten>=mask[x]){
  99608. if(val){
  99609. if(y+info->maxover<val)return(1);
  99610. if(y-info->maxunder>val)return(1);
  99611. }
  99612. }
  99613. }
  99614. if(info->maxover*info->maxover/n>info->maxerr)return(0);
  99615. if(info->maxunder*info->maxunder/n>info->maxerr)return(0);
  99616. if(mse/n>info->maxerr)return(1);
  99617. return(0);
  99618. }
  99619. static int post_Y(int *A,int *B,int pos){
  99620. if(A[pos]<0)
  99621. return B[pos];
  99622. if(B[pos]<0)
  99623. return A[pos];
  99624. return (A[pos]+B[pos])>>1;
  99625. }
  99626. int *floor1_fit(vorbis_block *vb,void *look_,
  99627. const float *logmdct, /* in */
  99628. const float *logmask){
  99629. long i,j;
  99630. vorbis_look_floor1 *look = (vorbis_look_floor1*) look_;
  99631. vorbis_info_floor1 *info=look->vi;
  99632. long n=look->n;
  99633. long posts=look->posts;
  99634. long nonzero=0;
  99635. lsfit_acc fits[VIF_POSIT+1];
  99636. int fit_valueA[VIF_POSIT+2]; /* index by range list position */
  99637. int fit_valueB[VIF_POSIT+2]; /* index by range list position */
  99638. int loneighbor[VIF_POSIT+2]; /* sorted index of range list position (+2) */
  99639. int hineighbor[VIF_POSIT+2];
  99640. int *output=NULL;
  99641. int memo[VIF_POSIT+2];
  99642. for(i=0;i<posts;i++)fit_valueA[i]=-200; /* mark all unused */
  99643. for(i=0;i<posts;i++)fit_valueB[i]=-200; /* mark all unused */
  99644. for(i=0;i<posts;i++)loneighbor[i]=0; /* 0 for the implicit 0 post */
  99645. for(i=0;i<posts;i++)hineighbor[i]=1; /* 1 for the implicit post at n */
  99646. for(i=0;i<posts;i++)memo[i]=-1; /* no neighbor yet */
  99647. if(posts==0){
  99648. nonzero+=accumulate_fit(logmask,logmdct,0,n,fits,n,info);
  99649. }else{
  99650. for(i=0;i<posts-1;i++)
  99651. nonzero+=accumulate_fit(logmask,logmdct,look->sorted_index[i],
  99652. look->sorted_index[i+1],fits+i,
  99653. n,info);
  99654. }
  99655. if(nonzero){
  99656. int y0=-200;
  99657. int y1=-200;
  99658. fit_line(fits,posts-1,&y0,&y1);
  99659. fit_valueA[0]=y0;
  99660. fit_valueB[0]=y0;
  99661. fit_valueB[1]=y1;
  99662. fit_valueA[1]=y1;
  99663. for(i=2;i<posts;i++){
  99664. int sortpos=look->reverse_index[i];
  99665. int ln=loneighbor[sortpos];
  99666. int hn=hineighbor[sortpos];
  99667. if(memo[ln]!=hn){
  99668. int lsortpos=look->reverse_index[ln];
  99669. int hsortpos=look->reverse_index[hn];
  99670. memo[ln]=hn;
  99671. {
  99672. int lx=info->postlist[ln];
  99673. int hx=info->postlist[hn];
  99674. int ly=post_Y(fit_valueA,fit_valueB,ln);
  99675. int hy=post_Y(fit_valueA,fit_valueB,hn);
  99676. if(ly==-1 || hy==-1){
  99677. exit(1);
  99678. }
  99679. if(inspect_error(lx,hx,ly,hy,logmask,logmdct,info)){
  99680. int ly0=-200;
  99681. int ly1=-200;
  99682. int hy0=-200;
  99683. int hy1=-200;
  99684. fit_line(fits+lsortpos,sortpos-lsortpos,&ly0,&ly1);
  99685. fit_line(fits+sortpos,hsortpos-sortpos,&hy0,&hy1);
  99686. fit_valueB[ln]=ly0;
  99687. if(ln==0)fit_valueA[ln]=ly0;
  99688. fit_valueA[i]=ly1;
  99689. fit_valueB[i]=hy0;
  99690. fit_valueA[hn]=hy1;
  99691. if(hn==1)fit_valueB[hn]=hy1;
  99692. if(ly1>=0 || hy0>=0){
  99693. for(j=sortpos-1;j>=0;j--)
  99694. if(hineighbor[j]==hn)
  99695. hineighbor[j]=i;
  99696. else
  99697. break;
  99698. for(j=sortpos+1;j<posts;j++)
  99699. if(loneighbor[j]==ln)
  99700. loneighbor[j]=i;
  99701. else
  99702. break;
  99703. }
  99704. }else{
  99705. fit_valueA[i]=-200;
  99706. fit_valueB[i]=-200;
  99707. }
  99708. }
  99709. }
  99710. }
  99711. output=(int*)_vorbis_block_alloc(vb,sizeof(*output)*posts);
  99712. output[0]=post_Y(fit_valueA,fit_valueB,0);
  99713. output[1]=post_Y(fit_valueA,fit_valueB,1);
  99714. for(i=2;i<posts;i++){
  99715. int ln=look->loneighbor[i-2];
  99716. int hn=look->hineighbor[i-2];
  99717. int x0=info->postlist[ln];
  99718. int x1=info->postlist[hn];
  99719. int y0=output[ln];
  99720. int y1=output[hn];
  99721. int predicted=render_point(x0,x1,y0,y1,info->postlist[i]);
  99722. int vx=post_Y(fit_valueA,fit_valueB,i);
  99723. if(vx>=0 && predicted!=vx){
  99724. output[i]=vx;
  99725. }else{
  99726. output[i]= predicted|0x8000;
  99727. }
  99728. }
  99729. }
  99730. return(output);
  99731. }
  99732. int *floor1_interpolate_fit(vorbis_block *vb,void *look_,
  99733. int *A,int *B,
  99734. int del){
  99735. long i;
  99736. vorbis_look_floor1* look = (vorbis_look_floor1*) look_;
  99737. long posts=look->posts;
  99738. int *output=NULL;
  99739. if(A && B){
  99740. output=(int*)_vorbis_block_alloc(vb,sizeof(*output)*posts);
  99741. for(i=0;i<posts;i++){
  99742. output[i]=((65536-del)*(A[i]&0x7fff)+del*(B[i]&0x7fff)+32768)>>16;
  99743. if(A[i]&0x8000 && B[i]&0x8000)output[i]|=0x8000;
  99744. }
  99745. }
  99746. return(output);
  99747. }
  99748. int floor1_encode(oggpack_buffer *opb,vorbis_block *vb,
  99749. void*look_,
  99750. int *post,int *ilogmask){
  99751. long i,j;
  99752. vorbis_look_floor1 *look = (vorbis_look_floor1 *) look_;
  99753. vorbis_info_floor1 *info=look->vi;
  99754. long posts=look->posts;
  99755. codec_setup_info *ci=(codec_setup_info*)vb->vd->vi->codec_setup;
  99756. int out[VIF_POSIT+2];
  99757. static_codebook **sbooks=ci->book_param;
  99758. codebook *books=ci->fullbooks;
  99759. static long seq=0;
  99760. if(post){
  99761. for(i=0;i<posts;i++){
  99762. int val=post[i]&0x7fff;
  99763. switch(info->mult){
  99764. case 1: /* 1024 -> 256 */
  99765. val>>=2;
  99766. break;
  99767. case 2: /* 1024 -> 128 */
  99768. val>>=3;
  99769. break;
  99770. case 3: /* 1024 -> 86 */
  99771. val/=12;
  99772. break;
  99773. case 4: /* 1024 -> 64 */
  99774. val>>=4;
  99775. break;
  99776. }
  99777. post[i]=val | (post[i]&0x8000);
  99778. }
  99779. out[0]=post[0];
  99780. out[1]=post[1];
  99781. for(i=2;i<posts;i++){
  99782. int ln=look->loneighbor[i-2];
  99783. int hn=look->hineighbor[i-2];
  99784. int x0=info->postlist[ln];
  99785. int x1=info->postlist[hn];
  99786. int y0=post[ln];
  99787. int y1=post[hn];
  99788. int predicted=render_point(x0,x1,y0,y1,info->postlist[i]);
  99789. if((post[i]&0x8000) || (predicted==post[i])){
  99790. post[i]=predicted|0x8000; /* in case there was roundoff jitter
  99791. in interpolation */
  99792. out[i]=0;
  99793. }else{
  99794. int headroom=(look->quant_q-predicted<predicted?
  99795. look->quant_q-predicted:predicted);
  99796. int val=post[i]-predicted;
  99797. if(val<0)
  99798. if(val<-headroom)
  99799. val=headroom-val-1;
  99800. else
  99801. val=-1-(val<<1);
  99802. else
  99803. if(val>=headroom)
  99804. val= val+headroom;
  99805. else
  99806. val<<=1;
  99807. out[i]=val;
  99808. post[ln]&=0x7fff;
  99809. post[hn]&=0x7fff;
  99810. }
  99811. }
  99812. oggpack_write(opb,1,1);
  99813. look->frames++;
  99814. look->postbits+=ilog(look->quant_q-1)*2;
  99815. oggpack_write(opb,out[0],ilog(look->quant_q-1));
  99816. oggpack_write(opb,out[1],ilog(look->quant_q-1));
  99817. for(i=0,j=2;i<info->partitions;i++){
  99818. int classx=info->partitionclass[i];
  99819. int cdim=info->class_dim[classx];
  99820. int csubbits=info->class_subs[classx];
  99821. int csub=1<<csubbits;
  99822. int bookas[8]={0,0,0,0,0,0,0,0};
  99823. int cval=0;
  99824. int cshift=0;
  99825. int k,l;
  99826. if(csubbits){
  99827. int maxval[8];
  99828. for(k=0;k<csub;k++){
  99829. int booknum=info->class_subbook[classx][k];
  99830. if(booknum<0){
  99831. maxval[k]=1;
  99832. }else{
  99833. maxval[k]=sbooks[info->class_subbook[classx][k]]->entries;
  99834. }
  99835. }
  99836. for(k=0;k<cdim;k++){
  99837. for(l=0;l<csub;l++){
  99838. int val=out[j+k];
  99839. if(val<maxval[l]){
  99840. bookas[k]=l;
  99841. break;
  99842. }
  99843. }
  99844. cval|= bookas[k]<<cshift;
  99845. cshift+=csubbits;
  99846. }
  99847. look->phrasebits+=
  99848. vorbis_book_encode(books+info->class_book[classx],cval,opb);
  99849. #ifdef TRAIN_FLOOR1
  99850. {
  99851. FILE *of;
  99852. char buffer[80];
  99853. sprintf(buffer,"line_%dx%ld_class%d.vqd",
  99854. vb->pcmend/2,posts-2,class);
  99855. of=fopen(buffer,"a");
  99856. fprintf(of,"%d\n",cval);
  99857. fclose(of);
  99858. }
  99859. #endif
  99860. }
  99861. for(k=0;k<cdim;k++){
  99862. int book=info->class_subbook[classx][bookas[k]];
  99863. if(book>=0){
  99864. if(out[j+k]<(books+book)->entries)
  99865. look->postbits+=vorbis_book_encode(books+book,
  99866. out[j+k],opb);
  99867. #ifdef TRAIN_FLOOR1
  99868. {
  99869. FILE *of;
  99870. char buffer[80];
  99871. sprintf(buffer,"line_%dx%ld_%dsub%d.vqd",
  99872. vb->pcmend/2,posts-2,class,bookas[k]);
  99873. of=fopen(buffer,"a");
  99874. fprintf(of,"%d\n",out[j+k]);
  99875. fclose(of);
  99876. }
  99877. #endif
  99878. }
  99879. }
  99880. j+=cdim;
  99881. }
  99882. {
  99883. int hx=0;
  99884. int lx=0;
  99885. int ly=post[0]*info->mult;
  99886. for(j=1;j<look->posts;j++){
  99887. int current=look->forward_index[j];
  99888. int hy=post[current]&0x7fff;
  99889. if(hy==post[current]){
  99890. hy*=info->mult;
  99891. hx=info->postlist[current];
  99892. render_line0(lx,hx,ly,hy,ilogmask);
  99893. lx=hx;
  99894. ly=hy;
  99895. }
  99896. }
  99897. for(j=hx;j<vb->pcmend/2;j++)ilogmask[j]=ly; /* be certain */
  99898. seq++;
  99899. return(1);
  99900. }
  99901. }else{
  99902. oggpack_write(opb,0,1);
  99903. memset(ilogmask,0,vb->pcmend/2*sizeof(*ilogmask));
  99904. seq++;
  99905. return(0);
  99906. }
  99907. }
  99908. static void *floor1_inverse1(vorbis_block *vb,vorbis_look_floor *in){
  99909. vorbis_look_floor1 *look=(vorbis_look_floor1 *)in;
  99910. vorbis_info_floor1 *info=look->vi;
  99911. codec_setup_info *ci=(codec_setup_info*)vb->vd->vi->codec_setup;
  99912. int i,j,k;
  99913. codebook *books=ci->fullbooks;
  99914. if(oggpack_read(&vb->opb,1)==1){
  99915. int *fit_value=(int*)_vorbis_block_alloc(vb,(look->posts)*sizeof(*fit_value));
  99916. fit_value[0]=oggpack_read(&vb->opb,ilog(look->quant_q-1));
  99917. fit_value[1]=oggpack_read(&vb->opb,ilog(look->quant_q-1));
  99918. for(i=0,j=2;i<info->partitions;i++){
  99919. int classx=info->partitionclass[i];
  99920. int cdim=info->class_dim[classx];
  99921. int csubbits=info->class_subs[classx];
  99922. int csub=1<<csubbits;
  99923. int cval=0;
  99924. if(csubbits){
  99925. cval=vorbis_book_decode(books+info->class_book[classx],&vb->opb);
  99926. if(cval==-1)goto eop;
  99927. }
  99928. for(k=0;k<cdim;k++){
  99929. int book=info->class_subbook[classx][cval&(csub-1)];
  99930. cval>>=csubbits;
  99931. if(book>=0){
  99932. if((fit_value[j+k]=vorbis_book_decode(books+book,&vb->opb))==-1)
  99933. goto eop;
  99934. }else{
  99935. fit_value[j+k]=0;
  99936. }
  99937. }
  99938. j+=cdim;
  99939. }
  99940. for(i=2;i<look->posts;i++){
  99941. int predicted=render_point(info->postlist[look->loneighbor[i-2]],
  99942. info->postlist[look->hineighbor[i-2]],
  99943. fit_value[look->loneighbor[i-2]],
  99944. fit_value[look->hineighbor[i-2]],
  99945. info->postlist[i]);
  99946. int hiroom=look->quant_q-predicted;
  99947. int loroom=predicted;
  99948. int room=(hiroom<loroom?hiroom:loroom)<<1;
  99949. int val=fit_value[i];
  99950. if(val){
  99951. if(val>=room){
  99952. if(hiroom>loroom){
  99953. val = val-loroom;
  99954. }else{
  99955. val = -1-(val-hiroom);
  99956. }
  99957. }else{
  99958. if(val&1){
  99959. val= -((val+1)>>1);
  99960. }else{
  99961. val>>=1;
  99962. }
  99963. }
  99964. fit_value[i]=val+predicted;
  99965. fit_value[look->loneighbor[i-2]]&=0x7fff;
  99966. fit_value[look->hineighbor[i-2]]&=0x7fff;
  99967. }else{
  99968. fit_value[i]=predicted|0x8000;
  99969. }
  99970. }
  99971. return(fit_value);
  99972. }
  99973. eop:
  99974. return(NULL);
  99975. }
  99976. static int floor1_inverse2(vorbis_block *vb,vorbis_look_floor *in,void *memo,
  99977. float *out){
  99978. vorbis_look_floor1 *look=(vorbis_look_floor1 *)in;
  99979. vorbis_info_floor1 *info=look->vi;
  99980. codec_setup_info *ci=(codec_setup_info*)vb->vd->vi->codec_setup;
  99981. int n=ci->blocksizes[vb->W]/2;
  99982. int j;
  99983. if(memo){
  99984. int *fit_value=(int *)memo;
  99985. int hx=0;
  99986. int lx=0;
  99987. int ly=fit_value[0]*info->mult;
  99988. for(j=1;j<look->posts;j++){
  99989. int current=look->forward_index[j];
  99990. int hy=fit_value[current]&0x7fff;
  99991. if(hy==fit_value[current]){
  99992. hy*=info->mult;
  99993. hx=info->postlist[current];
  99994. render_line(lx,hx,ly,hy,out);
  99995. lx=hx;
  99996. ly=hy;
  99997. }
  99998. }
  99999. for(j=hx;j<n;j++)out[j]*=FLOOR1_fromdB_LOOKUP[ly]; /* be certain */
  100000. return(1);
  100001. }
  100002. memset(out,0,sizeof(*out)*n);
  100003. return(0);
  100004. }
  100005. vorbis_func_floor floor1_exportbundle={
  100006. &floor1_pack,&floor1_unpack,&floor1_look,&floor1_free_info,
  100007. &floor1_free_look,&floor1_inverse1,&floor1_inverse2
  100008. };
  100009. #endif
  100010. /*** End of inlined file: floor1.c ***/
  100011. /*** Start of inlined file: info.c ***/
  100012. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100013. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100014. // tasks..
  100015. #if JUCE_MSVC
  100016. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100017. #endif
  100018. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100019. #if JUCE_USE_OGGVORBIS
  100020. #include <stdlib.h>
  100021. #include <string.h>
  100022. #include <ctype.h>
  100023. static void _v_writestring(oggpack_buffer *o, const char *s, int bytes){
  100024. while(bytes--){
  100025. oggpack_write(o,*s++,8);
  100026. }
  100027. }
  100028. static void _v_readstring(oggpack_buffer *o,char *buf,int bytes){
  100029. while(bytes--){
  100030. *buf++=oggpack_read(o,8);
  100031. }
  100032. }
  100033. void vorbis_comment_init(vorbis_comment *vc){
  100034. memset(vc,0,sizeof(*vc));
  100035. }
  100036. void vorbis_comment_add(vorbis_comment *vc,char *comment){
  100037. vc->user_comments=(char**)_ogg_realloc(vc->user_comments,
  100038. (vc->comments+2)*sizeof(*vc->user_comments));
  100039. vc->comment_lengths=(int*)_ogg_realloc(vc->comment_lengths,
  100040. (vc->comments+2)*sizeof(*vc->comment_lengths));
  100041. vc->comment_lengths[vc->comments]=strlen(comment);
  100042. vc->user_comments[vc->comments]=(char*)_ogg_malloc(vc->comment_lengths[vc->comments]+1);
  100043. strcpy(vc->user_comments[vc->comments], comment);
  100044. vc->comments++;
  100045. vc->user_comments[vc->comments]=NULL;
  100046. }
  100047. void vorbis_comment_add_tag(vorbis_comment *vc, const char *tag, char *contents){
  100048. char *comment=(char*)alloca(strlen(tag)+strlen(contents)+2); /* +2 for = and \0 */
  100049. strcpy(comment, tag);
  100050. strcat(comment, "=");
  100051. strcat(comment, contents);
  100052. vorbis_comment_add(vc, comment);
  100053. }
  100054. static int tagcompare(const char *s1, const char *s2, int n){
  100055. int c=0;
  100056. while(c < n){
  100057. if(toupper(s1[c]) != toupper(s2[c]))
  100058. return !0;
  100059. c++;
  100060. }
  100061. return 0;
  100062. }
  100063. char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count){
  100064. long i;
  100065. int found = 0;
  100066. int taglen = strlen(tag)+1; /* +1 for the = we append */
  100067. char *fulltag = (char*)alloca(taglen+ 1);
  100068. strcpy(fulltag, tag);
  100069. strcat(fulltag, "=");
  100070. for(i=0;i<vc->comments;i++){
  100071. if(!tagcompare(vc->user_comments[i], fulltag, taglen)){
  100072. if(count == found)
  100073. return vc->user_comments[i] + taglen;
  100074. else
  100075. found++;
  100076. }
  100077. }
  100078. return NULL; /* didn't find anything */
  100079. }
  100080. int vorbis_comment_query_count(vorbis_comment *vc, char *tag){
  100081. int i,count=0;
  100082. int taglen = strlen(tag)+1; /* +1 for the = we append */
  100083. char *fulltag = (char*)alloca(taglen+1);
  100084. strcpy(fulltag,tag);
  100085. strcat(fulltag, "=");
  100086. for(i=0;i<vc->comments;i++){
  100087. if(!tagcompare(vc->user_comments[i], fulltag, taglen))
  100088. count++;
  100089. }
  100090. return count;
  100091. }
  100092. void vorbis_comment_clear(vorbis_comment *vc){
  100093. if(vc){
  100094. long i;
  100095. for(i=0;i<vc->comments;i++)
  100096. if(vc->user_comments[i])_ogg_free(vc->user_comments[i]);
  100097. if(vc->user_comments)_ogg_free(vc->user_comments);
  100098. if(vc->comment_lengths)_ogg_free(vc->comment_lengths);
  100099. if(vc->vendor)_ogg_free(vc->vendor);
  100100. }
  100101. memset(vc,0,sizeof(*vc));
  100102. }
  100103. int vorbis_info_blocksize(vorbis_info *vi,int zo){
  100104. codec_setup_info *ci = (codec_setup_info*)vi->codec_setup;
  100105. return ci ? ci->blocksizes[zo] : -1;
  100106. }
  100107. void vorbis_info_init(vorbis_info *vi){
  100108. memset(vi,0,sizeof(*vi));
  100109. vi->codec_setup=_ogg_calloc(1,sizeof(codec_setup_info));
  100110. }
  100111. void vorbis_info_clear(vorbis_info *vi){
  100112. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100113. int i;
  100114. if(ci){
  100115. for(i=0;i<ci->modes;i++)
  100116. if(ci->mode_param[i])_ogg_free(ci->mode_param[i]);
  100117. for(i=0;i<ci->maps;i++) /* unpack does the range checking */
  100118. _mapping_P[ci->map_type[i]]->free_info(ci->map_param[i]);
  100119. for(i=0;i<ci->floors;i++) /* unpack does the range checking */
  100120. _floor_P[ci->floor_type[i]]->free_info(ci->floor_param[i]);
  100121. for(i=0;i<ci->residues;i++) /* unpack does the range checking */
  100122. _residue_P[ci->residue_type[i]]->free_info(ci->residue_param[i]);
  100123. for(i=0;i<ci->books;i++){
  100124. if(ci->book_param[i]){
  100125. vorbis_staticbook_destroy(ci->book_param[i]);
  100126. }
  100127. if(ci->fullbooks)
  100128. vorbis_book_clear(ci->fullbooks+i);
  100129. }
  100130. if(ci->fullbooks)
  100131. _ogg_free(ci->fullbooks);
  100132. for(i=0;i<ci->psys;i++)
  100133. _vi_psy_free(ci->psy_param[i]);
  100134. _ogg_free(ci);
  100135. }
  100136. memset(vi,0,sizeof(*vi));
  100137. }
  100138. static int _vorbis_unpack_info(vorbis_info *vi,oggpack_buffer *opb){
  100139. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100140. if(!ci)return(OV_EFAULT);
  100141. vi->version=oggpack_read(opb,32);
  100142. if(vi->version!=0)return(OV_EVERSION);
  100143. vi->channels=oggpack_read(opb,8);
  100144. vi->rate=oggpack_read(opb,32);
  100145. vi->bitrate_upper=oggpack_read(opb,32);
  100146. vi->bitrate_nominal=oggpack_read(opb,32);
  100147. vi->bitrate_lower=oggpack_read(opb,32);
  100148. ci->blocksizes[0]=1<<oggpack_read(opb,4);
  100149. ci->blocksizes[1]=1<<oggpack_read(opb,4);
  100150. if(vi->rate<1)goto err_out;
  100151. if(vi->channels<1)goto err_out;
  100152. if(ci->blocksizes[0]<8)goto err_out;
  100153. if(ci->blocksizes[1]<ci->blocksizes[0])goto err_out;
  100154. if(oggpack_read(opb,1)!=1)goto err_out; /* EOP check */
  100155. return(0);
  100156. err_out:
  100157. vorbis_info_clear(vi);
  100158. return(OV_EBADHEADER);
  100159. }
  100160. static int _vorbis_unpack_comment(vorbis_comment *vc,oggpack_buffer *opb){
  100161. int i;
  100162. int vendorlen=oggpack_read(opb,32);
  100163. if(vendorlen<0)goto err_out;
  100164. vc->vendor=(char*)_ogg_calloc(vendorlen+1,1);
  100165. _v_readstring(opb,vc->vendor,vendorlen);
  100166. vc->comments=oggpack_read(opb,32);
  100167. if(vc->comments<0)goto err_out;
  100168. vc->user_comments=(char**)_ogg_calloc(vc->comments+1,sizeof(*vc->user_comments));
  100169. vc->comment_lengths=(int*)_ogg_calloc(vc->comments+1, sizeof(*vc->comment_lengths));
  100170. for(i=0;i<vc->comments;i++){
  100171. int len=oggpack_read(opb,32);
  100172. if(len<0)goto err_out;
  100173. vc->comment_lengths[i]=len;
  100174. vc->user_comments[i]=(char*)_ogg_calloc(len+1,1);
  100175. _v_readstring(opb,vc->user_comments[i],len);
  100176. }
  100177. if(oggpack_read(opb,1)!=1)goto err_out; /* EOP check */
  100178. return(0);
  100179. err_out:
  100180. vorbis_comment_clear(vc);
  100181. return(OV_EBADHEADER);
  100182. }
  100183. static int _vorbis_unpack_books(vorbis_info *vi,oggpack_buffer *opb){
  100184. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100185. int i;
  100186. if(!ci)return(OV_EFAULT);
  100187. ci->books=oggpack_read(opb,8)+1;
  100188. for(i=0;i<ci->books;i++){
  100189. ci->book_param[i]=(static_codebook*)_ogg_calloc(1,sizeof(*ci->book_param[i]));
  100190. if(vorbis_staticbook_unpack(opb,ci->book_param[i]))goto err_out;
  100191. }
  100192. {
  100193. int times=oggpack_read(opb,6)+1;
  100194. for(i=0;i<times;i++){
  100195. int test=oggpack_read(opb,16);
  100196. if(test<0 || test>=VI_TIMEB)goto err_out;
  100197. }
  100198. }
  100199. ci->floors=oggpack_read(opb,6)+1;
  100200. for(i=0;i<ci->floors;i++){
  100201. ci->floor_type[i]=oggpack_read(opb,16);
  100202. if(ci->floor_type[i]<0 || ci->floor_type[i]>=VI_FLOORB)goto err_out;
  100203. ci->floor_param[i]=_floor_P[ci->floor_type[i]]->unpack(vi,opb);
  100204. if(!ci->floor_param[i])goto err_out;
  100205. }
  100206. ci->residues=oggpack_read(opb,6)+1;
  100207. for(i=0;i<ci->residues;i++){
  100208. ci->residue_type[i]=oggpack_read(opb,16);
  100209. if(ci->residue_type[i]<0 || ci->residue_type[i]>=VI_RESB)goto err_out;
  100210. ci->residue_param[i]=_residue_P[ci->residue_type[i]]->unpack(vi,opb);
  100211. if(!ci->residue_param[i])goto err_out;
  100212. }
  100213. ci->maps=oggpack_read(opb,6)+1;
  100214. for(i=0;i<ci->maps;i++){
  100215. ci->map_type[i]=oggpack_read(opb,16);
  100216. if(ci->map_type[i]<0 || ci->map_type[i]>=VI_MAPB)goto err_out;
  100217. ci->map_param[i]=_mapping_P[ci->map_type[i]]->unpack(vi,opb);
  100218. if(!ci->map_param[i])goto err_out;
  100219. }
  100220. ci->modes=oggpack_read(opb,6)+1;
  100221. for(i=0;i<ci->modes;i++){
  100222. ci->mode_param[i]=(vorbis_info_mode*)_ogg_calloc(1,sizeof(*ci->mode_param[i]));
  100223. ci->mode_param[i]->blockflag=oggpack_read(opb,1);
  100224. ci->mode_param[i]->windowtype=oggpack_read(opb,16);
  100225. ci->mode_param[i]->transformtype=oggpack_read(opb,16);
  100226. ci->mode_param[i]->mapping=oggpack_read(opb,8);
  100227. if(ci->mode_param[i]->windowtype>=VI_WINDOWB)goto err_out;
  100228. if(ci->mode_param[i]->transformtype>=VI_WINDOWB)goto err_out;
  100229. if(ci->mode_param[i]->mapping>=ci->maps)goto err_out;
  100230. }
  100231. if(oggpack_read(opb,1)!=1)goto err_out; /* top level EOP check */
  100232. return(0);
  100233. err_out:
  100234. vorbis_info_clear(vi);
  100235. return(OV_EBADHEADER);
  100236. }
  100237. int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,ogg_packet *op){
  100238. oggpack_buffer opb;
  100239. if(op){
  100240. oggpack_readinit(&opb,op->packet,op->bytes);
  100241. {
  100242. char buffer[6];
  100243. int packtype=oggpack_read(&opb,8);
  100244. memset(buffer,0,6);
  100245. _v_readstring(&opb,buffer,6);
  100246. if(memcmp(buffer,"vorbis",6)){
  100247. return(OV_ENOTVORBIS);
  100248. }
  100249. switch(packtype){
  100250. case 0x01: /* least significant *bit* is read first */
  100251. if(!op->b_o_s){
  100252. return(OV_EBADHEADER);
  100253. }
  100254. if(vi->rate!=0){
  100255. return(OV_EBADHEADER);
  100256. }
  100257. return(_vorbis_unpack_info(vi,&opb));
  100258. case 0x03: /* least significant *bit* is read first */
  100259. if(vi->rate==0){
  100260. return(OV_EBADHEADER);
  100261. }
  100262. return(_vorbis_unpack_comment(vc,&opb));
  100263. case 0x05: /* least significant *bit* is read first */
  100264. if(vi->rate==0 || vc->vendor==NULL){
  100265. return(OV_EBADHEADER);
  100266. }
  100267. return(_vorbis_unpack_books(vi,&opb));
  100268. default:
  100269. return(OV_EBADHEADER);
  100270. break;
  100271. }
  100272. }
  100273. }
  100274. return(OV_EBADHEADER);
  100275. }
  100276. static int _vorbis_pack_info(oggpack_buffer *opb,vorbis_info *vi){
  100277. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100278. if(!ci)return(OV_EFAULT);
  100279. oggpack_write(opb,0x01,8);
  100280. _v_writestring(opb,"vorbis", 6);
  100281. oggpack_write(opb,0x00,32);
  100282. oggpack_write(opb,vi->channels,8);
  100283. oggpack_write(opb,vi->rate,32);
  100284. oggpack_write(opb,vi->bitrate_upper,32);
  100285. oggpack_write(opb,vi->bitrate_nominal,32);
  100286. oggpack_write(opb,vi->bitrate_lower,32);
  100287. oggpack_write(opb,ilog2(ci->blocksizes[0]),4);
  100288. oggpack_write(opb,ilog2(ci->blocksizes[1]),4);
  100289. oggpack_write(opb,1,1);
  100290. return(0);
  100291. }
  100292. static int _vorbis_pack_comment(oggpack_buffer *opb,vorbis_comment *vc){
  100293. char temp[]="Xiph.Org libVorbis I 20050304";
  100294. int bytes = strlen(temp);
  100295. oggpack_write(opb,0x03,8);
  100296. _v_writestring(opb,"vorbis", 6);
  100297. oggpack_write(opb,bytes,32);
  100298. _v_writestring(opb,temp, bytes);
  100299. oggpack_write(opb,vc->comments,32);
  100300. if(vc->comments){
  100301. int i;
  100302. for(i=0;i<vc->comments;i++){
  100303. if(vc->user_comments[i]){
  100304. oggpack_write(opb,vc->comment_lengths[i],32);
  100305. _v_writestring(opb,vc->user_comments[i], vc->comment_lengths[i]);
  100306. }else{
  100307. oggpack_write(opb,0,32);
  100308. }
  100309. }
  100310. }
  100311. oggpack_write(opb,1,1);
  100312. return(0);
  100313. }
  100314. static int _vorbis_pack_books(oggpack_buffer *opb,vorbis_info *vi){
  100315. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100316. int i;
  100317. if(!ci)return(OV_EFAULT);
  100318. oggpack_write(opb,0x05,8);
  100319. _v_writestring(opb,"vorbis", 6);
  100320. oggpack_write(opb,ci->books-1,8);
  100321. for(i=0;i<ci->books;i++)
  100322. if(vorbis_staticbook_pack(ci->book_param[i],opb))goto err_out;
  100323. oggpack_write(opb,0,6);
  100324. oggpack_write(opb,0,16);
  100325. oggpack_write(opb,ci->floors-1,6);
  100326. for(i=0;i<ci->floors;i++){
  100327. oggpack_write(opb,ci->floor_type[i],16);
  100328. if(_floor_P[ci->floor_type[i]]->pack)
  100329. _floor_P[ci->floor_type[i]]->pack(ci->floor_param[i],opb);
  100330. else
  100331. goto err_out;
  100332. }
  100333. oggpack_write(opb,ci->residues-1,6);
  100334. for(i=0;i<ci->residues;i++){
  100335. oggpack_write(opb,ci->residue_type[i],16);
  100336. _residue_P[ci->residue_type[i]]->pack(ci->residue_param[i],opb);
  100337. }
  100338. oggpack_write(opb,ci->maps-1,6);
  100339. for(i=0;i<ci->maps;i++){
  100340. oggpack_write(opb,ci->map_type[i],16);
  100341. _mapping_P[ci->map_type[i]]->pack(vi,ci->map_param[i],opb);
  100342. }
  100343. oggpack_write(opb,ci->modes-1,6);
  100344. for(i=0;i<ci->modes;i++){
  100345. oggpack_write(opb,ci->mode_param[i]->blockflag,1);
  100346. oggpack_write(opb,ci->mode_param[i]->windowtype,16);
  100347. oggpack_write(opb,ci->mode_param[i]->transformtype,16);
  100348. oggpack_write(opb,ci->mode_param[i]->mapping,8);
  100349. }
  100350. oggpack_write(opb,1,1);
  100351. return(0);
  100352. err_out:
  100353. return(-1);
  100354. }
  100355. int vorbis_commentheader_out(vorbis_comment *vc,
  100356. ogg_packet *op){
  100357. oggpack_buffer opb;
  100358. oggpack_writeinit(&opb);
  100359. if(_vorbis_pack_comment(&opb,vc)) return OV_EIMPL;
  100360. op->packet = (unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100361. memcpy(op->packet, opb.buffer, oggpack_bytes(&opb));
  100362. op->bytes=oggpack_bytes(&opb);
  100363. op->b_o_s=0;
  100364. op->e_o_s=0;
  100365. op->granulepos=0;
  100366. op->packetno=1;
  100367. return 0;
  100368. }
  100369. int vorbis_analysis_headerout(vorbis_dsp_state *v,
  100370. vorbis_comment *vc,
  100371. ogg_packet *op,
  100372. ogg_packet *op_comm,
  100373. ogg_packet *op_code){
  100374. int ret=OV_EIMPL;
  100375. vorbis_info *vi=v->vi;
  100376. oggpack_buffer opb;
  100377. private_state *b=(private_state*)v->backend_state;
  100378. if(!b){
  100379. ret=OV_EFAULT;
  100380. goto err_out;
  100381. }
  100382. oggpack_writeinit(&opb);
  100383. if(_vorbis_pack_info(&opb,vi))goto err_out;
  100384. if(b->header)_ogg_free(b->header);
  100385. b->header=(unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100386. memcpy(b->header,opb.buffer,oggpack_bytes(&opb));
  100387. op->packet=b->header;
  100388. op->bytes=oggpack_bytes(&opb);
  100389. op->b_o_s=1;
  100390. op->e_o_s=0;
  100391. op->granulepos=0;
  100392. op->packetno=0;
  100393. oggpack_reset(&opb);
  100394. if(_vorbis_pack_comment(&opb,vc))goto err_out;
  100395. if(b->header1)_ogg_free(b->header1);
  100396. b->header1=(unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100397. memcpy(b->header1,opb.buffer,oggpack_bytes(&opb));
  100398. op_comm->packet=b->header1;
  100399. op_comm->bytes=oggpack_bytes(&opb);
  100400. op_comm->b_o_s=0;
  100401. op_comm->e_o_s=0;
  100402. op_comm->granulepos=0;
  100403. op_comm->packetno=1;
  100404. oggpack_reset(&opb);
  100405. if(_vorbis_pack_books(&opb,vi))goto err_out;
  100406. if(b->header2)_ogg_free(b->header2);
  100407. b->header2=(unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100408. memcpy(b->header2,opb.buffer,oggpack_bytes(&opb));
  100409. op_code->packet=b->header2;
  100410. op_code->bytes=oggpack_bytes(&opb);
  100411. op_code->b_o_s=0;
  100412. op_code->e_o_s=0;
  100413. op_code->granulepos=0;
  100414. op_code->packetno=2;
  100415. oggpack_writeclear(&opb);
  100416. return(0);
  100417. err_out:
  100418. oggpack_writeclear(&opb);
  100419. memset(op,0,sizeof(*op));
  100420. memset(op_comm,0,sizeof(*op_comm));
  100421. memset(op_code,0,sizeof(*op_code));
  100422. if(b->header)_ogg_free(b->header);
  100423. if(b->header1)_ogg_free(b->header1);
  100424. if(b->header2)_ogg_free(b->header2);
  100425. b->header=NULL;
  100426. b->header1=NULL;
  100427. b->header2=NULL;
  100428. return(ret);
  100429. }
  100430. double vorbis_granule_time(vorbis_dsp_state *v,ogg_int64_t granulepos){
  100431. if(granulepos>=0)
  100432. return((double)granulepos/v->vi->rate);
  100433. return(-1);
  100434. }
  100435. #endif
  100436. /*** End of inlined file: info.c ***/
  100437. /*** Start of inlined file: lpc.c ***/
  100438. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100439. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100440. // tasks..
  100441. #if JUCE_MSVC
  100442. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100443. #endif
  100444. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100445. #if JUCE_USE_OGGVORBIS
  100446. #include <stdlib.h>
  100447. #include <string.h>
  100448. #include <math.h>
  100449. float vorbis_lpc_from_data(float *data,float *lpci,int n,int m){
  100450. double *aut=(double*)alloca(sizeof(*aut)*(m+1));
  100451. double *lpc=(double*)alloca(sizeof(*lpc)*(m));
  100452. double error;
  100453. int i,j;
  100454. j=m+1;
  100455. while(j--){
  100456. double d=0; /* double needed for accumulator depth */
  100457. for(i=j;i<n;i++)d+=(double)data[i]*data[i-j];
  100458. aut[j]=d;
  100459. }
  100460. error=aut[0];
  100461. for(i=0;i<m;i++){
  100462. double r= -aut[i+1];
  100463. if(error==0){
  100464. memset(lpci,0,m*sizeof(*lpci));
  100465. return 0;
  100466. }
  100467. for(j=0;j<i;j++)r-=lpc[j]*aut[i-j];
  100468. r/=error;
  100469. lpc[i]=r;
  100470. for(j=0;j<i/2;j++){
  100471. double tmp=lpc[j];
  100472. lpc[j]+=r*lpc[i-1-j];
  100473. lpc[i-1-j]+=r*tmp;
  100474. }
  100475. if(i%2)lpc[j]+=lpc[j]*r;
  100476. error*=1.f-r*r;
  100477. }
  100478. for(j=0;j<m;j++)lpci[j]=(float)lpc[j];
  100479. return error;
  100480. }
  100481. void vorbis_lpc_predict(float *coeff,float *prime,int m,
  100482. float *data,long n){
  100483. long i,j,o,p;
  100484. float y;
  100485. float *work=(float*)alloca(sizeof(*work)*(m+n));
  100486. if(!prime)
  100487. for(i=0;i<m;i++)
  100488. work[i]=0.f;
  100489. else
  100490. for(i=0;i<m;i++)
  100491. work[i]=prime[i];
  100492. for(i=0;i<n;i++){
  100493. y=0;
  100494. o=i;
  100495. p=m;
  100496. for(j=0;j<m;j++)
  100497. y-=work[o++]*coeff[--p];
  100498. data[i]=work[o]=y;
  100499. }
  100500. }
  100501. #endif
  100502. /*** End of inlined file: lpc.c ***/
  100503. /*** Start of inlined file: lsp.c ***/
  100504. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100505. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100506. // tasks..
  100507. #if JUCE_MSVC
  100508. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100509. #endif
  100510. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100511. #if JUCE_USE_OGGVORBIS
  100512. #include <math.h>
  100513. #include <string.h>
  100514. #include <stdlib.h>
  100515. /*** Start of inlined file: lookup.h ***/
  100516. #ifndef _V_LOOKUP_H_
  100517. #ifdef FLOAT_LOOKUP
  100518. extern float vorbis_coslook(float a);
  100519. extern float vorbis_invsqlook(float a);
  100520. extern float vorbis_invsq2explook(int a);
  100521. extern float vorbis_fromdBlook(float a);
  100522. #endif
  100523. #ifdef INT_LOOKUP
  100524. extern long vorbis_invsqlook_i(long a,long e);
  100525. extern long vorbis_coslook_i(long a);
  100526. extern float vorbis_fromdBlook_i(long a);
  100527. #endif
  100528. #endif
  100529. /*** End of inlined file: lookup.h ***/
  100530. #define FLOAT_LOOKUP
  100531. #undef INT_LOOKUP
  100532. #ifdef FLOAT_LOOKUP
  100533. /*** Start of inlined file: lookup.c ***/
  100534. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100535. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100536. // tasks..
  100537. #if JUCE_MSVC
  100538. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100539. #endif
  100540. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100541. #if JUCE_USE_OGGVORBIS
  100542. #include <math.h>
  100543. /*** Start of inlined file: lookup.h ***/
  100544. #ifndef _V_LOOKUP_H_
  100545. #ifdef FLOAT_LOOKUP
  100546. extern float vorbis_coslook(float a);
  100547. extern float vorbis_invsqlook(float a);
  100548. extern float vorbis_invsq2explook(int a);
  100549. extern float vorbis_fromdBlook(float a);
  100550. #endif
  100551. #ifdef INT_LOOKUP
  100552. extern long vorbis_invsqlook_i(long a,long e);
  100553. extern long vorbis_coslook_i(long a);
  100554. extern float vorbis_fromdBlook_i(long a);
  100555. #endif
  100556. #endif
  100557. /*** End of inlined file: lookup.h ***/
  100558. /*** Start of inlined file: lookup_data.h ***/
  100559. #ifndef _V_LOOKUP_DATA_H_
  100560. #ifdef FLOAT_LOOKUP
  100561. #define COS_LOOKUP_SZ 128
  100562. static float COS_LOOKUP[COS_LOOKUP_SZ+1]={
  100563. +1.0000000000000f,+0.9996988186962f,+0.9987954562052f,+0.9972904566787f,
  100564. +0.9951847266722f,+0.9924795345987f,+0.9891765099648f,+0.9852776423889f,
  100565. +0.9807852804032f,+0.9757021300385f,+0.9700312531945f,+0.9637760657954f,
  100566. +0.9569403357322f,+0.9495281805930f,+0.9415440651830f,+0.9329927988347f,
  100567. +0.9238795325113f,+0.9142097557035f,+0.9039892931234f,+0.8932243011955f,
  100568. +0.8819212643484f,+0.8700869911087f,+0.8577286100003f,+0.8448535652497f,
  100569. +0.8314696123025f,+0.8175848131516f,+0.8032075314806f,+0.7883464276266f,
  100570. +0.7730104533627f,+0.7572088465065f,+0.7409511253550f,+0.7242470829515f,
  100571. +0.7071067811865f,+0.6895405447371f,+0.6715589548470f,+0.6531728429538f,
  100572. +0.6343932841636f,+0.6152315905806f,+0.5956993044924f,+0.5758081914178f,
  100573. +0.5555702330196f,+0.5349976198871f,+0.5141027441932f,+0.4928981922298f,
  100574. +0.4713967368260f,+0.4496113296546f,+0.4275550934303f,+0.4052413140050f,
  100575. +0.3826834323651f,+0.3598950365350f,+0.3368898533922f,+0.3136817403989f,
  100576. +0.2902846772545f,+0.2667127574749f,+0.2429801799033f,+0.2191012401569f,
  100577. +0.1950903220161f,+0.1709618887603f,+0.1467304744554f,+0.1224106751992f,
  100578. +0.0980171403296f,+0.0735645635997f,+0.0490676743274f,+0.0245412285229f,
  100579. +0.0000000000000f,-0.0245412285229f,-0.0490676743274f,-0.0735645635997f,
  100580. -0.0980171403296f,-0.1224106751992f,-0.1467304744554f,-0.1709618887603f,
  100581. -0.1950903220161f,-0.2191012401569f,-0.2429801799033f,-0.2667127574749f,
  100582. -0.2902846772545f,-0.3136817403989f,-0.3368898533922f,-0.3598950365350f,
  100583. -0.3826834323651f,-0.4052413140050f,-0.4275550934303f,-0.4496113296546f,
  100584. -0.4713967368260f,-0.4928981922298f,-0.5141027441932f,-0.5349976198871f,
  100585. -0.5555702330196f,-0.5758081914178f,-0.5956993044924f,-0.6152315905806f,
  100586. -0.6343932841636f,-0.6531728429538f,-0.6715589548470f,-0.6895405447371f,
  100587. -0.7071067811865f,-0.7242470829515f,-0.7409511253550f,-0.7572088465065f,
  100588. -0.7730104533627f,-0.7883464276266f,-0.8032075314806f,-0.8175848131516f,
  100589. -0.8314696123025f,-0.8448535652497f,-0.8577286100003f,-0.8700869911087f,
  100590. -0.8819212643484f,-0.8932243011955f,-0.9039892931234f,-0.9142097557035f,
  100591. -0.9238795325113f,-0.9329927988347f,-0.9415440651830f,-0.9495281805930f,
  100592. -0.9569403357322f,-0.9637760657954f,-0.9700312531945f,-0.9757021300385f,
  100593. -0.9807852804032f,-0.9852776423889f,-0.9891765099648f,-0.9924795345987f,
  100594. -0.9951847266722f,-0.9972904566787f,-0.9987954562052f,-0.9996988186962f,
  100595. -1.0000000000000f,
  100596. };
  100597. #define INVSQ_LOOKUP_SZ 32
  100598. static float INVSQ_LOOKUP[INVSQ_LOOKUP_SZ+1]={
  100599. 1.414213562373f,1.392621247646f,1.371988681140f,1.352246807566f,
  100600. 1.333333333333f,1.315191898443f,1.297771369046f,1.281025230441f,
  100601. 1.264911064067f,1.249390095109f,1.234426799697f,1.219988562661f,
  100602. 1.206045378311f,1.192569588000f,1.179535649239f,1.166919931983f,
  100603. 1.154700538379f,1.142857142857f,1.131370849898f,1.120224067222f,
  100604. 1.109400392450f,1.098884511590f,1.088662107904f,1.078719779941f,
  100605. 1.069044967650f,1.059625885652f,1.050451462878f,1.041511287847f,
  100606. 1.032795558989f,1.024295039463f,1.016001016002f,1.007905261358f,
  100607. 1.000000000000f,
  100608. };
  100609. #define INVSQ2EXP_LOOKUP_MIN (-32)
  100610. #define INVSQ2EXP_LOOKUP_MAX 32
  100611. static float INVSQ2EXP_LOOKUP[INVSQ2EXP_LOOKUP_MAX-\
  100612. INVSQ2EXP_LOOKUP_MIN+1]={
  100613. 65536.f, 46340.95001f, 32768.f, 23170.47501f,
  100614. 16384.f, 11585.2375f, 8192.f, 5792.618751f,
  100615. 4096.f, 2896.309376f, 2048.f, 1448.154688f,
  100616. 1024.f, 724.0773439f, 512.f, 362.038672f,
  100617. 256.f, 181.019336f, 128.f, 90.50966799f,
  100618. 64.f, 45.254834f, 32.f, 22.627417f,
  100619. 16.f, 11.3137085f, 8.f, 5.656854249f,
  100620. 4.f, 2.828427125f, 2.f, 1.414213562f,
  100621. 1.f, 0.7071067812f, 0.5f, 0.3535533906f,
  100622. 0.25f, 0.1767766953f, 0.125f, 0.08838834765f,
  100623. 0.0625f, 0.04419417382f, 0.03125f, 0.02209708691f,
  100624. 0.015625f, 0.01104854346f, 0.0078125f, 0.005524271728f,
  100625. 0.00390625f, 0.002762135864f, 0.001953125f, 0.001381067932f,
  100626. 0.0009765625f, 0.000690533966f, 0.00048828125f, 0.000345266983f,
  100627. 0.000244140625f,0.0001726334915f,0.0001220703125f,8.631674575e-05f,
  100628. 6.103515625e-05f,4.315837288e-05f,3.051757812e-05f,2.157918644e-05f,
  100629. 1.525878906e-05f,
  100630. };
  100631. #endif
  100632. #define FROMdB_LOOKUP_SZ 35
  100633. #define FROMdB2_LOOKUP_SZ 32
  100634. #define FROMdB_SHIFT 5
  100635. #define FROMdB2_SHIFT 3
  100636. #define FROMdB2_MASK 31
  100637. static float FROMdB_LOOKUP[FROMdB_LOOKUP_SZ]={
  100638. 1.f, 0.6309573445f, 0.3981071706f, 0.2511886432f,
  100639. 0.1584893192f, 0.1f, 0.06309573445f, 0.03981071706f,
  100640. 0.02511886432f, 0.01584893192f, 0.01f, 0.006309573445f,
  100641. 0.003981071706f, 0.002511886432f, 0.001584893192f, 0.001f,
  100642. 0.0006309573445f,0.0003981071706f,0.0002511886432f,0.0001584893192f,
  100643. 0.0001f,6.309573445e-05f,3.981071706e-05f,2.511886432e-05f,
  100644. 1.584893192e-05f, 1e-05f,6.309573445e-06f,3.981071706e-06f,
  100645. 2.511886432e-06f,1.584893192e-06f, 1e-06f,6.309573445e-07f,
  100646. 3.981071706e-07f,2.511886432e-07f,1.584893192e-07f,
  100647. };
  100648. static float FROMdB2_LOOKUP[FROMdB2_LOOKUP_SZ]={
  100649. 0.9928302478f, 0.9786445908f, 0.9646616199f, 0.9508784391f,
  100650. 0.9372921937f, 0.92390007f, 0.9106992942f, 0.8976871324f,
  100651. 0.8848608897f, 0.8722179097f, 0.8597555737f, 0.8474713009f,
  100652. 0.835362547f, 0.8234268041f, 0.8116616003f, 0.8000644989f,
  100653. 0.7886330981f, 0.7773650302f, 0.7662579617f, 0.755309592f,
  100654. 0.7445176537f, 0.7338799116f, 0.7233941627f, 0.7130582353f,
  100655. 0.7028699885f, 0.6928273125f, 0.6829281272f, 0.6731703824f,
  100656. 0.6635520573f, 0.6540711597f, 0.6447257262f, 0.6355138211f,
  100657. };
  100658. #ifdef INT_LOOKUP
  100659. #define INVSQ_LOOKUP_I_SHIFT 10
  100660. #define INVSQ_LOOKUP_I_MASK 1023
  100661. static long INVSQ_LOOKUP_I[64+1]={
  100662. 92682l, 91966l, 91267l, 90583l,
  100663. 89915l, 89261l, 88621l, 87995l,
  100664. 87381l, 86781l, 86192l, 85616l,
  100665. 85051l, 84497l, 83953l, 83420l,
  100666. 82897l, 82384l, 81880l, 81385l,
  100667. 80899l, 80422l, 79953l, 79492l,
  100668. 79039l, 78594l, 78156l, 77726l,
  100669. 77302l, 76885l, 76475l, 76072l,
  100670. 75674l, 75283l, 74898l, 74519l,
  100671. 74146l, 73778l, 73415l, 73058l,
  100672. 72706l, 72359l, 72016l, 71679l,
  100673. 71347l, 71019l, 70695l, 70376l,
  100674. 70061l, 69750l, 69444l, 69141l,
  100675. 68842l, 68548l, 68256l, 67969l,
  100676. 67685l, 67405l, 67128l, 66855l,
  100677. 66585l, 66318l, 66054l, 65794l,
  100678. 65536l,
  100679. };
  100680. #define COS_LOOKUP_I_SHIFT 9
  100681. #define COS_LOOKUP_I_MASK 511
  100682. #define COS_LOOKUP_I_SZ 128
  100683. static long COS_LOOKUP_I[COS_LOOKUP_I_SZ+1]={
  100684. 16384l, 16379l, 16364l, 16340l,
  100685. 16305l, 16261l, 16207l, 16143l,
  100686. 16069l, 15986l, 15893l, 15791l,
  100687. 15679l, 15557l, 15426l, 15286l,
  100688. 15137l, 14978l, 14811l, 14635l,
  100689. 14449l, 14256l, 14053l, 13842l,
  100690. 13623l, 13395l, 13160l, 12916l,
  100691. 12665l, 12406l, 12140l, 11866l,
  100692. 11585l, 11297l, 11003l, 10702l,
  100693. 10394l, 10080l, 9760l, 9434l,
  100694. 9102l, 8765l, 8423l, 8076l,
  100695. 7723l, 7366l, 7005l, 6639l,
  100696. 6270l, 5897l, 5520l, 5139l,
  100697. 4756l, 4370l, 3981l, 3590l,
  100698. 3196l, 2801l, 2404l, 2006l,
  100699. 1606l, 1205l, 804l, 402l,
  100700. 0l, -401l, -803l, -1204l,
  100701. -1605l, -2005l, -2403l, -2800l,
  100702. -3195l, -3589l, -3980l, -4369l,
  100703. -4755l, -5138l, -5519l, -5896l,
  100704. -6269l, -6638l, -7004l, -7365l,
  100705. -7722l, -8075l, -8422l, -8764l,
  100706. -9101l, -9433l, -9759l, -10079l,
  100707. -10393l, -10701l, -11002l, -11296l,
  100708. -11584l, -11865l, -12139l, -12405l,
  100709. -12664l, -12915l, -13159l, -13394l,
  100710. -13622l, -13841l, -14052l, -14255l,
  100711. -14448l, -14634l, -14810l, -14977l,
  100712. -15136l, -15285l, -15425l, -15556l,
  100713. -15678l, -15790l, -15892l, -15985l,
  100714. -16068l, -16142l, -16206l, -16260l,
  100715. -16304l, -16339l, -16363l, -16378l,
  100716. -16383l,
  100717. };
  100718. #endif
  100719. #endif
  100720. /*** End of inlined file: lookup_data.h ***/
  100721. #ifdef FLOAT_LOOKUP
  100722. float vorbis_coslook(float a){
  100723. double d=a*(.31830989*(float)COS_LOOKUP_SZ);
  100724. int i=vorbis_ftoi(d-.5);
  100725. return COS_LOOKUP[i]+ (d-i)*(COS_LOOKUP[i+1]-COS_LOOKUP[i]);
  100726. }
  100727. float vorbis_invsqlook(float a){
  100728. double d=a*(2.f*(float)INVSQ_LOOKUP_SZ)-(float)INVSQ_LOOKUP_SZ;
  100729. int i=vorbis_ftoi(d-.5f);
  100730. return INVSQ_LOOKUP[i]+ (d-i)*(INVSQ_LOOKUP[i+1]-INVSQ_LOOKUP[i]);
  100731. }
  100732. float vorbis_invsq2explook(int a){
  100733. return INVSQ2EXP_LOOKUP[a-INVSQ2EXP_LOOKUP_MIN];
  100734. }
  100735. #include <stdio.h>
  100736. float vorbis_fromdBlook(float a){
  100737. int i=vorbis_ftoi(a*((float)(-(1<<FROMdB2_SHIFT)))-.5f);
  100738. return (i<0)?1.f:
  100739. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  100740. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  100741. }
  100742. #endif
  100743. #ifdef INT_LOOKUP
  100744. long vorbis_invsqlook_i(long a,long e){
  100745. long i=(a&0x7fff)>>(INVSQ_LOOKUP_I_SHIFT-1);
  100746. long d=(a&INVSQ_LOOKUP_I_MASK)<<(16-INVSQ_LOOKUP_I_SHIFT); /* 0.16 */
  100747. long val=INVSQ_LOOKUP_I[i]- /* 1.16 */
  100748. (((INVSQ_LOOKUP_I[i]-INVSQ_LOOKUP_I[i+1])* /* 0.16 */
  100749. d)>>16); /* result 1.16 */
  100750. e+=32;
  100751. if(e&1)val=(val*5792)>>13; /* multiply val by 1/sqrt(2) */
  100752. e=(e>>1)-8;
  100753. return(val>>e);
  100754. }
  100755. float vorbis_fromdBlook_i(long a){
  100756. int i=(-a)>>(12-FROMdB2_SHIFT);
  100757. return (i<0)?1.f:
  100758. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  100759. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  100760. }
  100761. long vorbis_coslook_i(long a){
  100762. int i=a>>COS_LOOKUP_I_SHIFT;
  100763. int d=a&COS_LOOKUP_I_MASK;
  100764. return COS_LOOKUP_I[i]- ((d*(COS_LOOKUP_I[i]-COS_LOOKUP_I[i+1]))>>
  100765. COS_LOOKUP_I_SHIFT);
  100766. }
  100767. #endif
  100768. #endif
  100769. /*** End of inlined file: lookup.c ***/
  100770. /* catch this in the build system; we #include for
  100771. compilers (like gcc) that can't inline across
  100772. modules */
  100773. void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
  100774. float amp,float ampoffset){
  100775. int i;
  100776. float wdel=M_PI/ln;
  100777. vorbis_fpu_control fpu;
  100778. (void) fpu; // to avoid an unused variable warning
  100779. vorbis_fpu_setround(&fpu);
  100780. for(i=0;i<m;i++)lsp[i]=vorbis_coslook(lsp[i]);
  100781. i=0;
  100782. while(i<n){
  100783. int k=map[i];
  100784. int qexp;
  100785. float p=.7071067812f;
  100786. float q=.7071067812f;
  100787. float w=vorbis_coslook(wdel*k);
  100788. float *ftmp=lsp;
  100789. int c=m>>1;
  100790. do{
  100791. q*=ftmp[0]-w;
  100792. p*=ftmp[1]-w;
  100793. ftmp+=2;
  100794. }while(--c);
  100795. if(m&1){
  100796. q*=ftmp[0]-w;
  100797. q*=q;
  100798. p*=p*(1.f-w*w);
  100799. }else{
  100800. q*=q*(1.f+w);
  100801. p*=p*(1.f-w);
  100802. }
  100803. q=frexp(p+q,&qexp);
  100804. q=vorbis_fromdBlook(amp*
  100805. vorbis_invsqlook(q)*
  100806. vorbis_invsq2explook(qexp+m)-
  100807. ampoffset);
  100808. do{
  100809. curve[i++]*=q;
  100810. }while(map[i]==k);
  100811. }
  100812. vorbis_fpu_restore(fpu);
  100813. }
  100814. #else
  100815. #ifdef INT_LOOKUP
  100816. /*** Start of inlined file: lookup.c ***/
  100817. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100818. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100819. // tasks..
  100820. #if JUCE_MSVC
  100821. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100822. #endif
  100823. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100824. #if JUCE_USE_OGGVORBIS
  100825. #include <math.h>
  100826. /*** Start of inlined file: lookup.h ***/
  100827. #ifndef _V_LOOKUP_H_
  100828. #ifdef FLOAT_LOOKUP
  100829. extern float vorbis_coslook(float a);
  100830. extern float vorbis_invsqlook(float a);
  100831. extern float vorbis_invsq2explook(int a);
  100832. extern float vorbis_fromdBlook(float a);
  100833. #endif
  100834. #ifdef INT_LOOKUP
  100835. extern long vorbis_invsqlook_i(long a,long e);
  100836. extern long vorbis_coslook_i(long a);
  100837. extern float vorbis_fromdBlook_i(long a);
  100838. #endif
  100839. #endif
  100840. /*** End of inlined file: lookup.h ***/
  100841. /*** Start of inlined file: lookup_data.h ***/
  100842. #ifndef _V_LOOKUP_DATA_H_
  100843. #ifdef FLOAT_LOOKUP
  100844. #define COS_LOOKUP_SZ 128
  100845. static float COS_LOOKUP[COS_LOOKUP_SZ+1]={
  100846. +1.0000000000000f,+0.9996988186962f,+0.9987954562052f,+0.9972904566787f,
  100847. +0.9951847266722f,+0.9924795345987f,+0.9891765099648f,+0.9852776423889f,
  100848. +0.9807852804032f,+0.9757021300385f,+0.9700312531945f,+0.9637760657954f,
  100849. +0.9569403357322f,+0.9495281805930f,+0.9415440651830f,+0.9329927988347f,
  100850. +0.9238795325113f,+0.9142097557035f,+0.9039892931234f,+0.8932243011955f,
  100851. +0.8819212643484f,+0.8700869911087f,+0.8577286100003f,+0.8448535652497f,
  100852. +0.8314696123025f,+0.8175848131516f,+0.8032075314806f,+0.7883464276266f,
  100853. +0.7730104533627f,+0.7572088465065f,+0.7409511253550f,+0.7242470829515f,
  100854. +0.7071067811865f,+0.6895405447371f,+0.6715589548470f,+0.6531728429538f,
  100855. +0.6343932841636f,+0.6152315905806f,+0.5956993044924f,+0.5758081914178f,
  100856. +0.5555702330196f,+0.5349976198871f,+0.5141027441932f,+0.4928981922298f,
  100857. +0.4713967368260f,+0.4496113296546f,+0.4275550934303f,+0.4052413140050f,
  100858. +0.3826834323651f,+0.3598950365350f,+0.3368898533922f,+0.3136817403989f,
  100859. +0.2902846772545f,+0.2667127574749f,+0.2429801799033f,+0.2191012401569f,
  100860. +0.1950903220161f,+0.1709618887603f,+0.1467304744554f,+0.1224106751992f,
  100861. +0.0980171403296f,+0.0735645635997f,+0.0490676743274f,+0.0245412285229f,
  100862. +0.0000000000000f,-0.0245412285229f,-0.0490676743274f,-0.0735645635997f,
  100863. -0.0980171403296f,-0.1224106751992f,-0.1467304744554f,-0.1709618887603f,
  100864. -0.1950903220161f,-0.2191012401569f,-0.2429801799033f,-0.2667127574749f,
  100865. -0.2902846772545f,-0.3136817403989f,-0.3368898533922f,-0.3598950365350f,
  100866. -0.3826834323651f,-0.4052413140050f,-0.4275550934303f,-0.4496113296546f,
  100867. -0.4713967368260f,-0.4928981922298f,-0.5141027441932f,-0.5349976198871f,
  100868. -0.5555702330196f,-0.5758081914178f,-0.5956993044924f,-0.6152315905806f,
  100869. -0.6343932841636f,-0.6531728429538f,-0.6715589548470f,-0.6895405447371f,
  100870. -0.7071067811865f,-0.7242470829515f,-0.7409511253550f,-0.7572088465065f,
  100871. -0.7730104533627f,-0.7883464276266f,-0.8032075314806f,-0.8175848131516f,
  100872. -0.8314696123025f,-0.8448535652497f,-0.8577286100003f,-0.8700869911087f,
  100873. -0.8819212643484f,-0.8932243011955f,-0.9039892931234f,-0.9142097557035f,
  100874. -0.9238795325113f,-0.9329927988347f,-0.9415440651830f,-0.9495281805930f,
  100875. -0.9569403357322f,-0.9637760657954f,-0.9700312531945f,-0.9757021300385f,
  100876. -0.9807852804032f,-0.9852776423889f,-0.9891765099648f,-0.9924795345987f,
  100877. -0.9951847266722f,-0.9972904566787f,-0.9987954562052f,-0.9996988186962f,
  100878. -1.0000000000000f,
  100879. };
  100880. #define INVSQ_LOOKUP_SZ 32
  100881. static float INVSQ_LOOKUP[INVSQ_LOOKUP_SZ+1]={
  100882. 1.414213562373f,1.392621247646f,1.371988681140f,1.352246807566f,
  100883. 1.333333333333f,1.315191898443f,1.297771369046f,1.281025230441f,
  100884. 1.264911064067f,1.249390095109f,1.234426799697f,1.219988562661f,
  100885. 1.206045378311f,1.192569588000f,1.179535649239f,1.166919931983f,
  100886. 1.154700538379f,1.142857142857f,1.131370849898f,1.120224067222f,
  100887. 1.109400392450f,1.098884511590f,1.088662107904f,1.078719779941f,
  100888. 1.069044967650f,1.059625885652f,1.050451462878f,1.041511287847f,
  100889. 1.032795558989f,1.024295039463f,1.016001016002f,1.007905261358f,
  100890. 1.000000000000f,
  100891. };
  100892. #define INVSQ2EXP_LOOKUP_MIN (-32)
  100893. #define INVSQ2EXP_LOOKUP_MAX 32
  100894. static float INVSQ2EXP_LOOKUP[INVSQ2EXP_LOOKUP_MAX-\
  100895. INVSQ2EXP_LOOKUP_MIN+1]={
  100896. 65536.f, 46340.95001f, 32768.f, 23170.47501f,
  100897. 16384.f, 11585.2375f, 8192.f, 5792.618751f,
  100898. 4096.f, 2896.309376f, 2048.f, 1448.154688f,
  100899. 1024.f, 724.0773439f, 512.f, 362.038672f,
  100900. 256.f, 181.019336f, 128.f, 90.50966799f,
  100901. 64.f, 45.254834f, 32.f, 22.627417f,
  100902. 16.f, 11.3137085f, 8.f, 5.656854249f,
  100903. 4.f, 2.828427125f, 2.f, 1.414213562f,
  100904. 1.f, 0.7071067812f, 0.5f, 0.3535533906f,
  100905. 0.25f, 0.1767766953f, 0.125f, 0.08838834765f,
  100906. 0.0625f, 0.04419417382f, 0.03125f, 0.02209708691f,
  100907. 0.015625f, 0.01104854346f, 0.0078125f, 0.005524271728f,
  100908. 0.00390625f, 0.002762135864f, 0.001953125f, 0.001381067932f,
  100909. 0.0009765625f, 0.000690533966f, 0.00048828125f, 0.000345266983f,
  100910. 0.000244140625f,0.0001726334915f,0.0001220703125f,8.631674575e-05f,
  100911. 6.103515625e-05f,4.315837288e-05f,3.051757812e-05f,2.157918644e-05f,
  100912. 1.525878906e-05f,
  100913. };
  100914. #endif
  100915. #define FROMdB_LOOKUP_SZ 35
  100916. #define FROMdB2_LOOKUP_SZ 32
  100917. #define FROMdB_SHIFT 5
  100918. #define FROMdB2_SHIFT 3
  100919. #define FROMdB2_MASK 31
  100920. static float FROMdB_LOOKUP[FROMdB_LOOKUP_SZ]={
  100921. 1.f, 0.6309573445f, 0.3981071706f, 0.2511886432f,
  100922. 0.1584893192f, 0.1f, 0.06309573445f, 0.03981071706f,
  100923. 0.02511886432f, 0.01584893192f, 0.01f, 0.006309573445f,
  100924. 0.003981071706f, 0.002511886432f, 0.001584893192f, 0.001f,
  100925. 0.0006309573445f,0.0003981071706f,0.0002511886432f,0.0001584893192f,
  100926. 0.0001f,6.309573445e-05f,3.981071706e-05f,2.511886432e-05f,
  100927. 1.584893192e-05f, 1e-05f,6.309573445e-06f,3.981071706e-06f,
  100928. 2.511886432e-06f,1.584893192e-06f, 1e-06f,6.309573445e-07f,
  100929. 3.981071706e-07f,2.511886432e-07f,1.584893192e-07f,
  100930. };
  100931. static float FROMdB2_LOOKUP[FROMdB2_LOOKUP_SZ]={
  100932. 0.9928302478f, 0.9786445908f, 0.9646616199f, 0.9508784391f,
  100933. 0.9372921937f, 0.92390007f, 0.9106992942f, 0.8976871324f,
  100934. 0.8848608897f, 0.8722179097f, 0.8597555737f, 0.8474713009f,
  100935. 0.835362547f, 0.8234268041f, 0.8116616003f, 0.8000644989f,
  100936. 0.7886330981f, 0.7773650302f, 0.7662579617f, 0.755309592f,
  100937. 0.7445176537f, 0.7338799116f, 0.7233941627f, 0.7130582353f,
  100938. 0.7028699885f, 0.6928273125f, 0.6829281272f, 0.6731703824f,
  100939. 0.6635520573f, 0.6540711597f, 0.6447257262f, 0.6355138211f,
  100940. };
  100941. #ifdef INT_LOOKUP
  100942. #define INVSQ_LOOKUP_I_SHIFT 10
  100943. #define INVSQ_LOOKUP_I_MASK 1023
  100944. static long INVSQ_LOOKUP_I[64+1]={
  100945. 92682l, 91966l, 91267l, 90583l,
  100946. 89915l, 89261l, 88621l, 87995l,
  100947. 87381l, 86781l, 86192l, 85616l,
  100948. 85051l, 84497l, 83953l, 83420l,
  100949. 82897l, 82384l, 81880l, 81385l,
  100950. 80899l, 80422l, 79953l, 79492l,
  100951. 79039l, 78594l, 78156l, 77726l,
  100952. 77302l, 76885l, 76475l, 76072l,
  100953. 75674l, 75283l, 74898l, 74519l,
  100954. 74146l, 73778l, 73415l, 73058l,
  100955. 72706l, 72359l, 72016l, 71679l,
  100956. 71347l, 71019l, 70695l, 70376l,
  100957. 70061l, 69750l, 69444l, 69141l,
  100958. 68842l, 68548l, 68256l, 67969l,
  100959. 67685l, 67405l, 67128l, 66855l,
  100960. 66585l, 66318l, 66054l, 65794l,
  100961. 65536l,
  100962. };
  100963. #define COS_LOOKUP_I_SHIFT 9
  100964. #define COS_LOOKUP_I_MASK 511
  100965. #define COS_LOOKUP_I_SZ 128
  100966. static long COS_LOOKUP_I[COS_LOOKUP_I_SZ+1]={
  100967. 16384l, 16379l, 16364l, 16340l,
  100968. 16305l, 16261l, 16207l, 16143l,
  100969. 16069l, 15986l, 15893l, 15791l,
  100970. 15679l, 15557l, 15426l, 15286l,
  100971. 15137l, 14978l, 14811l, 14635l,
  100972. 14449l, 14256l, 14053l, 13842l,
  100973. 13623l, 13395l, 13160l, 12916l,
  100974. 12665l, 12406l, 12140l, 11866l,
  100975. 11585l, 11297l, 11003l, 10702l,
  100976. 10394l, 10080l, 9760l, 9434l,
  100977. 9102l, 8765l, 8423l, 8076l,
  100978. 7723l, 7366l, 7005l, 6639l,
  100979. 6270l, 5897l, 5520l, 5139l,
  100980. 4756l, 4370l, 3981l, 3590l,
  100981. 3196l, 2801l, 2404l, 2006l,
  100982. 1606l, 1205l, 804l, 402l,
  100983. 0l, -401l, -803l, -1204l,
  100984. -1605l, -2005l, -2403l, -2800l,
  100985. -3195l, -3589l, -3980l, -4369l,
  100986. -4755l, -5138l, -5519l, -5896l,
  100987. -6269l, -6638l, -7004l, -7365l,
  100988. -7722l, -8075l, -8422l, -8764l,
  100989. -9101l, -9433l, -9759l, -10079l,
  100990. -10393l, -10701l, -11002l, -11296l,
  100991. -11584l, -11865l, -12139l, -12405l,
  100992. -12664l, -12915l, -13159l, -13394l,
  100993. -13622l, -13841l, -14052l, -14255l,
  100994. -14448l, -14634l, -14810l, -14977l,
  100995. -15136l, -15285l, -15425l, -15556l,
  100996. -15678l, -15790l, -15892l, -15985l,
  100997. -16068l, -16142l, -16206l, -16260l,
  100998. -16304l, -16339l, -16363l, -16378l,
  100999. -16383l,
  101000. };
  101001. #endif
  101002. #endif
  101003. /*** End of inlined file: lookup_data.h ***/
  101004. #ifdef FLOAT_LOOKUP
  101005. float vorbis_coslook(float a){
  101006. double d=a*(.31830989*(float)COS_LOOKUP_SZ);
  101007. int i=vorbis_ftoi(d-.5);
  101008. return COS_LOOKUP[i]+ (d-i)*(COS_LOOKUP[i+1]-COS_LOOKUP[i]);
  101009. }
  101010. float vorbis_invsqlook(float a){
  101011. double d=a*(2.f*(float)INVSQ_LOOKUP_SZ)-(float)INVSQ_LOOKUP_SZ;
  101012. int i=vorbis_ftoi(d-.5f);
  101013. return INVSQ_LOOKUP[i]+ (d-i)*(INVSQ_LOOKUP[i+1]-INVSQ_LOOKUP[i]);
  101014. }
  101015. float vorbis_invsq2explook(int a){
  101016. return INVSQ2EXP_LOOKUP[a-INVSQ2EXP_LOOKUP_MIN];
  101017. }
  101018. #include <stdio.h>
  101019. float vorbis_fromdBlook(float a){
  101020. int i=vorbis_ftoi(a*((float)(-(1<<FROMdB2_SHIFT)))-.5f);
  101021. return (i<0)?1.f:
  101022. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  101023. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  101024. }
  101025. #endif
  101026. #ifdef INT_LOOKUP
  101027. long vorbis_invsqlook_i(long a,long e){
  101028. long i=(a&0x7fff)>>(INVSQ_LOOKUP_I_SHIFT-1);
  101029. long d=(a&INVSQ_LOOKUP_I_MASK)<<(16-INVSQ_LOOKUP_I_SHIFT); /* 0.16 */
  101030. long val=INVSQ_LOOKUP_I[i]- /* 1.16 */
  101031. (((INVSQ_LOOKUP_I[i]-INVSQ_LOOKUP_I[i+1])* /* 0.16 */
  101032. d)>>16); /* result 1.16 */
  101033. e+=32;
  101034. if(e&1)val=(val*5792)>>13; /* multiply val by 1/sqrt(2) */
  101035. e=(e>>1)-8;
  101036. return(val>>e);
  101037. }
  101038. float vorbis_fromdBlook_i(long a){
  101039. int i=(-a)>>(12-FROMdB2_SHIFT);
  101040. return (i<0)?1.f:
  101041. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  101042. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  101043. }
  101044. long vorbis_coslook_i(long a){
  101045. int i=a>>COS_LOOKUP_I_SHIFT;
  101046. int d=a&COS_LOOKUP_I_MASK;
  101047. return COS_LOOKUP_I[i]- ((d*(COS_LOOKUP_I[i]-COS_LOOKUP_I[i+1]))>>
  101048. COS_LOOKUP_I_SHIFT);
  101049. }
  101050. #endif
  101051. #endif
  101052. /*** End of inlined file: lookup.c ***/
  101053. /* catch this in the build system; we #include for
  101054. compilers (like gcc) that can't inline across
  101055. modules */
  101056. static int MLOOP_1[64]={
  101057. 0,10,11,11, 12,12,12,12, 13,13,13,13, 13,13,13,13,
  101058. 14,14,14,14, 14,14,14,14, 14,14,14,14, 14,14,14,14,
  101059. 15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
  101060. 15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
  101061. };
  101062. static int MLOOP_2[64]={
  101063. 0,4,5,5, 6,6,6,6, 7,7,7,7, 7,7,7,7,
  101064. 8,8,8,8, 8,8,8,8, 8,8,8,8, 8,8,8,8,
  101065. 9,9,9,9, 9,9,9,9, 9,9,9,9, 9,9,9,9,
  101066. 9,9,9,9, 9,9,9,9, 9,9,9,9, 9,9,9,9,
  101067. };
  101068. static int MLOOP_3[8]={0,1,2,2,3,3,3,3};
  101069. void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
  101070. float amp,float ampoffset){
  101071. int i;
  101072. int ampoffseti=rint(ampoffset*4096.f);
  101073. int ampi=rint(amp*16.f);
  101074. long *ilsp=alloca(m*sizeof(*ilsp));
  101075. for(i=0;i<m;i++)ilsp[i]=vorbis_coslook_i(lsp[i]/M_PI*65536.f+.5f);
  101076. i=0;
  101077. while(i<n){
  101078. int j,k=map[i];
  101079. unsigned long pi=46341; /* 2**-.5 in 0.16 */
  101080. unsigned long qi=46341;
  101081. int qexp=0,shift;
  101082. long wi=vorbis_coslook_i(k*65536/ln);
  101083. qi*=labs(ilsp[0]-wi);
  101084. pi*=labs(ilsp[1]-wi);
  101085. for(j=3;j<m;j+=2){
  101086. if(!(shift=MLOOP_1[(pi|qi)>>25]))
  101087. if(!(shift=MLOOP_2[(pi|qi)>>19]))
  101088. shift=MLOOP_3[(pi|qi)>>16];
  101089. qi=(qi>>shift)*labs(ilsp[j-1]-wi);
  101090. pi=(pi>>shift)*labs(ilsp[j]-wi);
  101091. qexp+=shift;
  101092. }
  101093. if(!(shift=MLOOP_1[(pi|qi)>>25]))
  101094. if(!(shift=MLOOP_2[(pi|qi)>>19]))
  101095. shift=MLOOP_3[(pi|qi)>>16];
  101096. if(m&1){
  101097. qi=(qi>>shift)*labs(ilsp[j-1]-wi);
  101098. pi=(pi>>shift)<<14;
  101099. qexp+=shift;
  101100. if(!(shift=MLOOP_1[(pi|qi)>>25]))
  101101. if(!(shift=MLOOP_2[(pi|qi)>>19]))
  101102. shift=MLOOP_3[(pi|qi)>>16];
  101103. pi>>=shift;
  101104. qi>>=shift;
  101105. qexp+=shift-14*((m+1)>>1);
  101106. pi=((pi*pi)>>16);
  101107. qi=((qi*qi)>>16);
  101108. qexp=qexp*2+m;
  101109. pi*=(1<<14)-((wi*wi)>>14);
  101110. qi+=pi>>14;
  101111. }else{
  101112. pi>>=shift;
  101113. qi>>=shift;
  101114. qexp+=shift-7*m;
  101115. pi=((pi*pi)>>16);
  101116. qi=((qi*qi)>>16);
  101117. qexp=qexp*2+m;
  101118. pi*=(1<<14)-wi;
  101119. qi*=(1<<14)+wi;
  101120. qi=(qi+pi)>>14;
  101121. }
  101122. if(qi&0xffff0000){ /* checks for 1.xxxxxxxxxxxxxxxx */
  101123. qi>>=1; qexp++;
  101124. }else
  101125. while(qi && !(qi&0x8000)){ /* checks for 0.0xxxxxxxxxxxxxxx or less*/
  101126. qi<<=1; qexp--;
  101127. }
  101128. amp=vorbis_fromdBlook_i(ampi* /* n.4 */
  101129. vorbis_invsqlook_i(qi,qexp)-
  101130. ampoffseti); /* 8.12[0] */
  101131. curve[i]*=amp;
  101132. while(map[++i]==k)curve[i]*=amp;
  101133. }
  101134. }
  101135. #else
  101136. void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
  101137. float amp,float ampoffset){
  101138. int i;
  101139. float wdel=M_PI/ln;
  101140. for(i=0;i<m;i++)lsp[i]=2.f*cos(lsp[i]);
  101141. i=0;
  101142. while(i<n){
  101143. int j,k=map[i];
  101144. float p=.5f;
  101145. float q=.5f;
  101146. float w=2.f*cos(wdel*k);
  101147. for(j=1;j<m;j+=2){
  101148. q *= w-lsp[j-1];
  101149. p *= w-lsp[j];
  101150. }
  101151. if(j==m){
  101152. q*=w-lsp[j-1];
  101153. p*=p*(4.f-w*w);
  101154. q*=q;
  101155. }else{
  101156. p*=p*(2.f-w);
  101157. q*=q*(2.f+w);
  101158. }
  101159. q=fromdB(amp/sqrt(p+q)-ampoffset);
  101160. curve[i]*=q;
  101161. while(map[++i]==k)curve[i]*=q;
  101162. }
  101163. }
  101164. #endif
  101165. #endif
  101166. static void cheby(float *g, int ord) {
  101167. int i, j;
  101168. g[0] *= .5f;
  101169. for(i=2; i<= ord; i++) {
  101170. for(j=ord; j >= i; j--) {
  101171. g[j-2] -= g[j];
  101172. g[j] += g[j];
  101173. }
  101174. }
  101175. }
  101176. static int comp(const void *a,const void *b){
  101177. return (*(float *)a<*(float *)b)-(*(float *)a>*(float *)b);
  101178. }
  101179. #define EPSILON 10e-7
  101180. static int Laguerre_With_Deflation(float *a,int ord,float *r){
  101181. int i,m;
  101182. double lastdelta=0.f;
  101183. double *defl=(double*)alloca(sizeof(*defl)*(ord+1));
  101184. for(i=0;i<=ord;i++)defl[i]=a[i];
  101185. for(m=ord;m>0;m--){
  101186. double newx=0.f,delta;
  101187. while(1){
  101188. double p=defl[m],pp=0.f,ppp=0.f,denom;
  101189. for(i=m;i>0;i--){
  101190. ppp = newx*ppp + pp;
  101191. pp = newx*pp + p;
  101192. p = newx*p + defl[i-1];
  101193. }
  101194. denom=(m-1) * ((m-1)*pp*pp - m*p*ppp);
  101195. if(denom<0)
  101196. return(-1); /* complex root! The LPC generator handed us a bad filter */
  101197. if(pp>0){
  101198. denom = pp + sqrt(denom);
  101199. if(denom<EPSILON)denom=EPSILON;
  101200. }else{
  101201. denom = pp - sqrt(denom);
  101202. if(denom>-(EPSILON))denom=-(EPSILON);
  101203. }
  101204. delta = m*p/denom;
  101205. newx -= delta;
  101206. if(delta<0.f)delta*=-1;
  101207. if(fabs(delta/newx)<10e-12)break;
  101208. lastdelta=delta;
  101209. }
  101210. r[m-1]=newx;
  101211. for(i=m;i>0;i--)
  101212. defl[i-1]+=newx*defl[i];
  101213. defl++;
  101214. }
  101215. return(0);
  101216. }
  101217. static int Newton_Raphson(float *a,int ord,float *r){
  101218. int i, k, count=0;
  101219. double error=1.f;
  101220. double *root=(double*)alloca(ord*sizeof(*root));
  101221. for(i=0; i<ord;i++) root[i] = r[i];
  101222. while(error>1e-20){
  101223. error=0;
  101224. for(i=0; i<ord; i++) { /* Update each point. */
  101225. double pp=0.,delta;
  101226. double rooti=root[i];
  101227. double p=a[ord];
  101228. for(k=ord-1; k>= 0; k--) {
  101229. pp= pp* rooti + p;
  101230. p = p * rooti + a[k];
  101231. }
  101232. delta = p/pp;
  101233. root[i] -= delta;
  101234. error+= delta*delta;
  101235. }
  101236. if(count>40)return(-1);
  101237. count++;
  101238. }
  101239. for(i=0; i<ord;i++) r[i] = root[i];
  101240. return(0);
  101241. }
  101242. int vorbis_lpc_to_lsp(float *lpc,float *lsp,int m){
  101243. int order2=(m+1)>>1;
  101244. int g1_order,g2_order;
  101245. float *g1=(float*)alloca(sizeof(*g1)*(order2+1));
  101246. float *g2=(float*)alloca(sizeof(*g2)*(order2+1));
  101247. float *g1r=(float*)alloca(sizeof(*g1r)*(order2+1));
  101248. float *g2r=(float*)alloca(sizeof(*g2r)*(order2+1));
  101249. int i;
  101250. g1_order=(m+1)>>1;
  101251. g2_order=(m) >>1;
  101252. g1[g1_order] = 1.f;
  101253. for(i=1;i<=g1_order;i++) g1[g1_order-i] = lpc[i-1]+lpc[m-i];
  101254. g2[g2_order] = 1.f;
  101255. for(i=1;i<=g2_order;i++) g2[g2_order-i] = lpc[i-1]-lpc[m-i];
  101256. if(g1_order>g2_order){
  101257. for(i=2; i<=g2_order;i++) g2[g2_order-i] += g2[g2_order-i+2];
  101258. }else{
  101259. for(i=1; i<=g1_order;i++) g1[g1_order-i] -= g1[g1_order-i+1];
  101260. for(i=1; i<=g2_order;i++) g2[g2_order-i] += g2[g2_order-i+1];
  101261. }
  101262. cheby(g1,g1_order);
  101263. cheby(g2,g2_order);
  101264. if(Laguerre_With_Deflation(g1,g1_order,g1r) ||
  101265. Laguerre_With_Deflation(g2,g2_order,g2r))
  101266. return(-1);
  101267. Newton_Raphson(g1,g1_order,g1r); /* if it fails, it leaves g1r alone */
  101268. Newton_Raphson(g2,g2_order,g2r); /* if it fails, it leaves g2r alone */
  101269. qsort(g1r,g1_order,sizeof(*g1r),comp);
  101270. qsort(g2r,g2_order,sizeof(*g2r),comp);
  101271. for(i=0;i<g1_order;i++)
  101272. lsp[i*2] = acos(g1r[i]);
  101273. for(i=0;i<g2_order;i++)
  101274. lsp[i*2+1] = acos(g2r[i]);
  101275. return(0);
  101276. }
  101277. #endif
  101278. /*** End of inlined file: lsp.c ***/
  101279. /*** Start of inlined file: mapping0.c ***/
  101280. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  101281. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  101282. // tasks..
  101283. #if JUCE_MSVC
  101284. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  101285. #endif
  101286. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  101287. #if JUCE_USE_OGGVORBIS
  101288. #include <stdlib.h>
  101289. #include <stdio.h>
  101290. #include <string.h>
  101291. #include <math.h>
  101292. static void mapping0_free_info(vorbis_info_mapping *i){
  101293. vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)i;
  101294. if(info){
  101295. memset(info,0,sizeof(*info));
  101296. _ogg_free(info);
  101297. }
  101298. }
  101299. static int ilog3(unsigned int v){
  101300. int ret=0;
  101301. if(v)--v;
  101302. while(v){
  101303. ret++;
  101304. v>>=1;
  101305. }
  101306. return(ret);
  101307. }
  101308. static void mapping0_pack(vorbis_info *vi,vorbis_info_mapping *vm,
  101309. oggpack_buffer *opb){
  101310. int i;
  101311. vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)vm;
  101312. if(info->submaps>1){
  101313. oggpack_write(opb,1,1);
  101314. oggpack_write(opb,info->submaps-1,4);
  101315. }else
  101316. oggpack_write(opb,0,1);
  101317. if(info->coupling_steps>0){
  101318. oggpack_write(opb,1,1);
  101319. oggpack_write(opb,info->coupling_steps-1,8);
  101320. for(i=0;i<info->coupling_steps;i++){
  101321. oggpack_write(opb,info->coupling_mag[i],ilog3(vi->channels));
  101322. oggpack_write(opb,info->coupling_ang[i],ilog3(vi->channels));
  101323. }
  101324. }else
  101325. oggpack_write(opb,0,1);
  101326. oggpack_write(opb,0,2); /* 2,3:reserved */
  101327. if(info->submaps>1){
  101328. for(i=0;i<vi->channels;i++)
  101329. oggpack_write(opb,info->chmuxlist[i],4);
  101330. }
  101331. for(i=0;i<info->submaps;i++){
  101332. oggpack_write(opb,0,8); /* time submap unused */
  101333. oggpack_write(opb,info->floorsubmap[i],8);
  101334. oggpack_write(opb,info->residuesubmap[i],8);
  101335. }
  101336. }
  101337. static vorbis_info_mapping *mapping0_unpack(vorbis_info *vi,oggpack_buffer *opb){
  101338. int i;
  101339. vorbis_info_mapping0 *info=(vorbis_info_mapping0*)_ogg_calloc(1,sizeof(*info));
  101340. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  101341. memset(info,0,sizeof(*info));
  101342. if(oggpack_read(opb,1))
  101343. info->submaps=oggpack_read(opb,4)+1;
  101344. else
  101345. info->submaps=1;
  101346. if(oggpack_read(opb,1)){
  101347. info->coupling_steps=oggpack_read(opb,8)+1;
  101348. for(i=0;i<info->coupling_steps;i++){
  101349. int testM=info->coupling_mag[i]=oggpack_read(opb,ilog3(vi->channels));
  101350. int testA=info->coupling_ang[i]=oggpack_read(opb,ilog3(vi->channels));
  101351. if(testM<0 ||
  101352. testA<0 ||
  101353. testM==testA ||
  101354. testM>=vi->channels ||
  101355. testA>=vi->channels) goto err_out;
  101356. }
  101357. }
  101358. if(oggpack_read(opb,2)>0)goto err_out; /* 2,3:reserved */
  101359. if(info->submaps>1){
  101360. for(i=0;i<vi->channels;i++){
  101361. info->chmuxlist[i]=oggpack_read(opb,4);
  101362. if(info->chmuxlist[i]>=info->submaps)goto err_out;
  101363. }
  101364. }
  101365. for(i=0;i<info->submaps;i++){
  101366. oggpack_read(opb,8); /* time submap unused */
  101367. info->floorsubmap[i]=oggpack_read(opb,8);
  101368. if(info->floorsubmap[i]>=ci->floors)goto err_out;
  101369. info->residuesubmap[i]=oggpack_read(opb,8);
  101370. if(info->residuesubmap[i]>=ci->residues)goto err_out;
  101371. }
  101372. return info;
  101373. err_out:
  101374. mapping0_free_info(info);
  101375. return(NULL);
  101376. }
  101377. #if 0
  101378. static long seq=0;
  101379. static ogg_int64_t total=0;
  101380. static float FLOOR1_fromdB_LOOKUP[256]={
  101381. 1.0649863e-07F, 1.1341951e-07F, 1.2079015e-07F, 1.2863978e-07F,
  101382. 1.3699951e-07F, 1.4590251e-07F, 1.5538408e-07F, 1.6548181e-07F,
  101383. 1.7623575e-07F, 1.8768855e-07F, 1.9988561e-07F, 2.128753e-07F,
  101384. 2.2670913e-07F, 2.4144197e-07F, 2.5713223e-07F, 2.7384213e-07F,
  101385. 2.9163793e-07F, 3.1059021e-07F, 3.3077411e-07F, 3.5226968e-07F,
  101386. 3.7516214e-07F, 3.9954229e-07F, 4.2550680e-07F, 4.5315863e-07F,
  101387. 4.8260743e-07F, 5.1396998e-07F, 5.4737065e-07F, 5.8294187e-07F,
  101388. 6.2082472e-07F, 6.6116941e-07F, 7.0413592e-07F, 7.4989464e-07F,
  101389. 7.9862701e-07F, 8.5052630e-07F, 9.0579828e-07F, 9.6466216e-07F,
  101390. 1.0273513e-06F, 1.0941144e-06F, 1.1652161e-06F, 1.2409384e-06F,
  101391. 1.3215816e-06F, 1.4074654e-06F, 1.4989305e-06F, 1.5963394e-06F,
  101392. 1.7000785e-06F, 1.8105592e-06F, 1.9282195e-06F, 2.0535261e-06F,
  101393. 2.1869758e-06F, 2.3290978e-06F, 2.4804557e-06F, 2.6416497e-06F,
  101394. 2.8133190e-06F, 2.9961443e-06F, 3.1908506e-06F, 3.3982101e-06F,
  101395. 3.6190449e-06F, 3.8542308e-06F, 4.1047004e-06F, 4.3714470e-06F,
  101396. 4.6555282e-06F, 4.9580707e-06F, 5.2802740e-06F, 5.6234160e-06F,
  101397. 5.9888572e-06F, 6.3780469e-06F, 6.7925283e-06F, 7.2339451e-06F,
  101398. 7.7040476e-06F, 8.2047000e-06F, 8.7378876e-06F, 9.3057248e-06F,
  101399. 9.9104632e-06F, 1.0554501e-05F, 1.1240392e-05F, 1.1970856e-05F,
  101400. 1.2748789e-05F, 1.3577278e-05F, 1.4459606e-05F, 1.5399272e-05F,
  101401. 1.6400004e-05F, 1.7465768e-05F, 1.8600792e-05F, 1.9809576e-05F,
  101402. 2.1096914e-05F, 2.2467911e-05F, 2.3928002e-05F, 2.5482978e-05F,
  101403. 2.7139006e-05F, 2.8902651e-05F, 3.0780908e-05F, 3.2781225e-05F,
  101404. 3.4911534e-05F, 3.7180282e-05F, 3.9596466e-05F, 4.2169667e-05F,
  101405. 4.4910090e-05F, 4.7828601e-05F, 5.0936773e-05F, 5.4246931e-05F,
  101406. 5.7772202e-05F, 6.1526565e-05F, 6.5524908e-05F, 6.9783085e-05F,
  101407. 7.4317983e-05F, 7.9147585e-05F, 8.4291040e-05F, 8.9768747e-05F,
  101408. 9.5602426e-05F, 0.00010181521F, 0.00010843174F, 0.00011547824F,
  101409. 0.00012298267F, 0.00013097477F, 0.00013948625F, 0.00014855085F,
  101410. 0.00015820453F, 0.00016848555F, 0.00017943469F, 0.00019109536F,
  101411. 0.00020351382F, 0.00021673929F, 0.00023082423F, 0.00024582449F,
  101412. 0.00026179955F, 0.00027881276F, 0.00029693158F, 0.00031622787F,
  101413. 0.00033677814F, 0.00035866388F, 0.00038197188F, 0.00040679456F,
  101414. 0.00043323036F, 0.00046138411F, 0.00049136745F, 0.00052329927F,
  101415. 0.00055730621F, 0.00059352311F, 0.00063209358F, 0.00067317058F,
  101416. 0.00071691700F, 0.00076350630F, 0.00081312324F, 0.00086596457F,
  101417. 0.00092223983F, 0.00098217216F, 0.0010459992F, 0.0011139742F,
  101418. 0.0011863665F, 0.0012634633F, 0.0013455702F, 0.0014330129F,
  101419. 0.0015261382F, 0.0016253153F, 0.0017309374F, 0.0018434235F,
  101420. 0.0019632195F, 0.0020908006F, 0.0022266726F, 0.0023713743F,
  101421. 0.0025254795F, 0.0026895994F, 0.0028643847F, 0.0030505286F,
  101422. 0.0032487691F, 0.0034598925F, 0.0036847358F, 0.0039241906F,
  101423. 0.0041792066F, 0.0044507950F, 0.0047400328F, 0.0050480668F,
  101424. 0.0053761186F, 0.0057254891F, 0.0060975636F, 0.0064938176F,
  101425. 0.0069158225F, 0.0073652516F, 0.0078438871F, 0.0083536271F,
  101426. 0.0088964928F, 0.009474637F, 0.010090352F, 0.010746080F,
  101427. 0.011444421F, 0.012188144F, 0.012980198F, 0.013823725F,
  101428. 0.014722068F, 0.015678791F, 0.016697687F, 0.017782797F,
  101429. 0.018938423F, 0.020169149F, 0.021479854F, 0.022875735F,
  101430. 0.024362330F, 0.025945531F, 0.027631618F, 0.029427276F,
  101431. 0.031339626F, 0.033376252F, 0.035545228F, 0.037855157F,
  101432. 0.040315199F, 0.042935108F, 0.045725273F, 0.048696758F,
  101433. 0.051861348F, 0.055231591F, 0.058820850F, 0.062643361F,
  101434. 0.066714279F, 0.071049749F, 0.075666962F, 0.080584227F,
  101435. 0.085821044F, 0.091398179F, 0.097337747F, 0.10366330F,
  101436. 0.11039993F, 0.11757434F, 0.12521498F, 0.13335215F,
  101437. 0.14201813F, 0.15124727F, 0.16107617F, 0.17154380F,
  101438. 0.18269168F, 0.19456402F, 0.20720788F, 0.22067342F,
  101439. 0.23501402F, 0.25028656F, 0.26655159F, 0.28387361F,
  101440. 0.30232132F, 0.32196786F, 0.34289114F, 0.36517414F,
  101441. 0.38890521F, 0.41417847F, 0.44109412F, 0.46975890F,
  101442. 0.50028648F, 0.53279791F, 0.56742212F, 0.60429640F,
  101443. 0.64356699F, 0.68538959F, 0.72993007F, 0.77736504F,
  101444. 0.82788260F, 0.88168307F, 0.9389798F, 1.F,
  101445. };
  101446. #endif
  101447. extern int *floor1_fit(vorbis_block *vb,void *look,
  101448. const float *logmdct, /* in */
  101449. const float *logmask);
  101450. extern int *floor1_interpolate_fit(vorbis_block *vb,void *look,
  101451. int *A,int *B,
  101452. int del);
  101453. extern int floor1_encode(oggpack_buffer *opb,vorbis_block *vb,
  101454. void*look,
  101455. int *post,int *ilogmask);
  101456. static int mapping0_forward(vorbis_block *vb){
  101457. vorbis_dsp_state *vd=vb->vd;
  101458. vorbis_info *vi=vd->vi;
  101459. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  101460. private_state *b=(private_state*)vb->vd->backend_state;
  101461. vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
  101462. int n=vb->pcmend;
  101463. int i,j,k;
  101464. int *nonzero = (int*) alloca(sizeof(*nonzero)*vi->channels);
  101465. float **gmdct = (float**) _vorbis_block_alloc(vb,vi->channels*sizeof(*gmdct));
  101466. int **ilogmaskch= (int**) _vorbis_block_alloc(vb,vi->channels*sizeof(*ilogmaskch));
  101467. int ***floor_posts = (int***) _vorbis_block_alloc(vb,vi->channels*sizeof(*floor_posts));
  101468. float global_ampmax=vbi->ampmax;
  101469. float *local_ampmax=(float*)alloca(sizeof(*local_ampmax)*vi->channels);
  101470. int blocktype=vbi->blocktype;
  101471. int modenumber=vb->W;
  101472. vorbis_info_mapping0 *info=(vorbis_info_mapping0*)ci->map_param[modenumber];
  101473. vorbis_look_psy *psy_look=
  101474. b->psy+blocktype+(vb->W?2:0);
  101475. vb->mode=modenumber;
  101476. for(i=0;i<vi->channels;i++){
  101477. float scale=4.f/n;
  101478. float scale_dB;
  101479. float *pcm =vb->pcm[i];
  101480. float *logfft =pcm;
  101481. gmdct[i]=(float*)_vorbis_block_alloc(vb,n/2*sizeof(**gmdct));
  101482. scale_dB=todB(&scale) + .345; /* + .345 is a hack; the original
  101483. todB estimation used on IEEE 754
  101484. compliant machines had a bug that
  101485. returned dB values about a third
  101486. of a decibel too high. The bug
  101487. was harmless because tunings
  101488. implicitly took that into
  101489. account. However, fixing the bug
  101490. in the estimator requires
  101491. changing all the tunings as well.
  101492. For now, it's easier to sync
  101493. things back up here, and
  101494. recalibrate the tunings in the
  101495. next major model upgrade. */
  101496. #if 0
  101497. if(vi->channels==2)
  101498. if(i==0)
  101499. _analysis_output("pcmL",seq,pcm,n,0,0,total-n/2);
  101500. else
  101501. _analysis_output("pcmR",seq,pcm,n,0,0,total-n/2);
  101502. #endif
  101503. _vorbis_apply_window(pcm,b->window,ci->blocksizes,vb->lW,vb->W,vb->nW);
  101504. #if 0
  101505. if(vi->channels==2)
  101506. if(i==0)
  101507. _analysis_output("windowedL",seq,pcm,n,0,0,total-n/2);
  101508. else
  101509. _analysis_output("windowedR",seq,pcm,n,0,0,total-n/2);
  101510. #endif
  101511. mdct_forward((mdct_lookup*) b->transform[vb->W][0],pcm,gmdct[i]);
  101512. drft_forward(&b->fft_look[vb->W],pcm);
  101513. logfft[0]=scale_dB+todB(pcm) + .345; /* + .345 is a hack; the
  101514. original todB estimation used on
  101515. IEEE 754 compliant machines had a
  101516. bug that returned dB values about
  101517. a third of a decibel too high.
  101518. The bug was harmless because
  101519. tunings implicitly took that into
  101520. account. However, fixing the bug
  101521. in the estimator requires
  101522. changing all the tunings as well.
  101523. For now, it's easier to sync
  101524. things back up here, and
  101525. recalibrate the tunings in the
  101526. next major model upgrade. */
  101527. local_ampmax[i]=logfft[0];
  101528. for(j=1;j<n-1;j+=2){
  101529. float temp=pcm[j]*pcm[j]+pcm[j+1]*pcm[j+1];
  101530. temp=logfft[(j+1)>>1]=scale_dB+.5f*todB(&temp) + .345; /* +
  101531. .345 is a hack; the original todB
  101532. estimation used on IEEE 754
  101533. compliant machines had a bug that
  101534. returned dB values about a third
  101535. of a decibel too high. The bug
  101536. was harmless because tunings
  101537. implicitly took that into
  101538. account. However, fixing the bug
  101539. in the estimator requires
  101540. changing all the tunings as well.
  101541. For now, it's easier to sync
  101542. things back up here, and
  101543. recalibrate the tunings in the
  101544. next major model upgrade. */
  101545. if(temp>local_ampmax[i])local_ampmax[i]=temp;
  101546. }
  101547. if(local_ampmax[i]>0.f)local_ampmax[i]=0.f;
  101548. if(local_ampmax[i]>global_ampmax)global_ampmax=local_ampmax[i];
  101549. #if 0
  101550. if(vi->channels==2){
  101551. if(i==0){
  101552. _analysis_output("fftL",seq,logfft,n/2,1,0,0);
  101553. }else{
  101554. _analysis_output("fftR",seq,logfft,n/2,1,0,0);
  101555. }
  101556. }
  101557. #endif
  101558. }
  101559. {
  101560. float *noise = (float*) _vorbis_block_alloc(vb,n/2*sizeof(*noise));
  101561. float *tone = (float*) _vorbis_block_alloc(vb,n/2*sizeof(*tone));
  101562. for(i=0;i<vi->channels;i++){
  101563. int submap=info->chmuxlist[i];
  101564. float *mdct =gmdct[i];
  101565. float *logfft =vb->pcm[i];
  101566. float *logmdct =logfft+n/2;
  101567. float *logmask =logfft;
  101568. vb->mode=modenumber;
  101569. floor_posts[i]=(int**) _vorbis_block_alloc(vb,PACKETBLOBS*sizeof(**floor_posts));
  101570. memset(floor_posts[i],0,sizeof(**floor_posts)*PACKETBLOBS);
  101571. for(j=0;j<n/2;j++)
  101572. logmdct[j]=todB(mdct+j) + .345; /* + .345 is a hack; the original
  101573. todB estimation used on IEEE 754
  101574. compliant machines had a bug that
  101575. returned dB values about a third
  101576. of a decibel too high. The bug
  101577. was harmless because tunings
  101578. implicitly took that into
  101579. account. However, fixing the bug
  101580. in the estimator requires
  101581. changing all the tunings as well.
  101582. For now, it's easier to sync
  101583. things back up here, and
  101584. recalibrate the tunings in the
  101585. next major model upgrade. */
  101586. #if 0
  101587. if(vi->channels==2){
  101588. if(i==0)
  101589. _analysis_output("mdctL",seq,logmdct,n/2,1,0,0);
  101590. else
  101591. _analysis_output("mdctR",seq,logmdct,n/2,1,0,0);
  101592. }else{
  101593. _analysis_output("mdct",seq,logmdct,n/2,1,0,0);
  101594. }
  101595. #endif
  101596. _vp_noisemask(psy_look,
  101597. logmdct,
  101598. noise); /* noise does not have by-frequency offset
  101599. bias applied yet */
  101600. #if 0
  101601. if(vi->channels==2){
  101602. if(i==0)
  101603. _analysis_output("noiseL",seq,noise,n/2,1,0,0);
  101604. else
  101605. _analysis_output("noiseR",seq,noise,n/2,1,0,0);
  101606. }
  101607. #endif
  101608. _vp_tonemask(psy_look,
  101609. logfft,
  101610. tone,
  101611. global_ampmax,
  101612. local_ampmax[i]);
  101613. #if 0
  101614. if(vi->channels==2){
  101615. if(i==0)
  101616. _analysis_output("toneL",seq,tone,n/2,1,0,0);
  101617. else
  101618. _analysis_output("toneR",seq,tone,n/2,1,0,0);
  101619. }
  101620. #endif
  101621. #if 0
  101622. {
  101623. float aotuv[psy_look->n];
  101624. #endif
  101625. _vp_offset_and_mix(psy_look,
  101626. noise,
  101627. tone,
  101628. 1,
  101629. logmask,
  101630. mdct,
  101631. logmdct);
  101632. #if 0
  101633. if(vi->channels==2){
  101634. if(i==0)
  101635. _analysis_output("aotuvM1_L",seq,aotuv,psy_look->n,1,1,0);
  101636. else
  101637. _analysis_output("aotuvM1_R",seq,aotuv,psy_look->n,1,1,0);
  101638. }
  101639. }
  101640. #endif
  101641. #if 0
  101642. if(vi->channels==2){
  101643. if(i==0)
  101644. _analysis_output("mask1L",seq,logmask,n/2,1,0,0);
  101645. else
  101646. _analysis_output("mask1R",seq,logmask,n/2,1,0,0);
  101647. }
  101648. #endif
  101649. if(ci->floor_type[info->floorsubmap[submap]]!=1)return(-1);
  101650. floor_posts[i][PACKETBLOBS/2]=
  101651. floor1_fit(vb,b->flr[info->floorsubmap[submap]],
  101652. logmdct,
  101653. logmask);
  101654. if(vorbis_bitrate_managed(vb) && floor_posts[i][PACKETBLOBS/2]){
  101655. _vp_offset_and_mix(psy_look,
  101656. noise,
  101657. tone,
  101658. 2,
  101659. logmask,
  101660. mdct,
  101661. logmdct);
  101662. #if 0
  101663. if(vi->channels==2){
  101664. if(i==0)
  101665. _analysis_output("mask2L",seq,logmask,n/2,1,0,0);
  101666. else
  101667. _analysis_output("mask2R",seq,logmask,n/2,1,0,0);
  101668. }
  101669. #endif
  101670. floor_posts[i][PACKETBLOBS-1]=
  101671. floor1_fit(vb,b->flr[info->floorsubmap[submap]],
  101672. logmdct,
  101673. logmask);
  101674. _vp_offset_and_mix(psy_look,
  101675. noise,
  101676. tone,
  101677. 0,
  101678. logmask,
  101679. mdct,
  101680. logmdct);
  101681. #if 0
  101682. if(vi->channels==2)
  101683. if(i==0)
  101684. _analysis_output("mask0L",seq,logmask,n/2,1,0,0);
  101685. else
  101686. _analysis_output("mask0R",seq,logmask,n/2,1,0,0);
  101687. #endif
  101688. floor_posts[i][0]=
  101689. floor1_fit(vb,b->flr[info->floorsubmap[submap]],
  101690. logmdct,
  101691. logmask);
  101692. for(k=1;k<PACKETBLOBS/2;k++)
  101693. floor_posts[i][k]=
  101694. floor1_interpolate_fit(vb,b->flr[info->floorsubmap[submap]],
  101695. floor_posts[i][0],
  101696. floor_posts[i][PACKETBLOBS/2],
  101697. k*65536/(PACKETBLOBS/2));
  101698. for(k=PACKETBLOBS/2+1;k<PACKETBLOBS-1;k++)
  101699. floor_posts[i][k]=
  101700. floor1_interpolate_fit(vb,b->flr[info->floorsubmap[submap]],
  101701. floor_posts[i][PACKETBLOBS/2],
  101702. floor_posts[i][PACKETBLOBS-1],
  101703. (k-PACKETBLOBS/2)*65536/(PACKETBLOBS/2));
  101704. }
  101705. }
  101706. }
  101707. vbi->ampmax=global_ampmax;
  101708. {
  101709. float **res_bundle=(float**) alloca(sizeof(*res_bundle)*vi->channels);
  101710. float **couple_bundle=(float**) alloca(sizeof(*couple_bundle)*vi->channels);
  101711. int *zerobundle=(int*) alloca(sizeof(*zerobundle)*vi->channels);
  101712. int **sortindex=(int**) alloca(sizeof(*sortindex)*vi->channels);
  101713. float **mag_memo;
  101714. int **mag_sort;
  101715. if(info->coupling_steps){
  101716. mag_memo=_vp_quantize_couple_memo(vb,
  101717. &ci->psy_g_param,
  101718. psy_look,
  101719. info,
  101720. gmdct);
  101721. mag_sort=_vp_quantize_couple_sort(vb,
  101722. psy_look,
  101723. info,
  101724. mag_memo);
  101725. hf_reduction(&ci->psy_g_param,
  101726. psy_look,
  101727. info,
  101728. mag_memo);
  101729. }
  101730. memset(sortindex,0,sizeof(*sortindex)*vi->channels);
  101731. if(psy_look->vi->normal_channel_p){
  101732. for(i=0;i<vi->channels;i++){
  101733. float *mdct =gmdct[i];
  101734. sortindex[i]=(int*) alloca(sizeof(**sortindex)*n/2);
  101735. _vp_noise_normalize_sort(psy_look,mdct,sortindex[i]);
  101736. }
  101737. }
  101738. for(k=(vorbis_bitrate_managed(vb)?0:PACKETBLOBS/2);
  101739. k<=(vorbis_bitrate_managed(vb)?PACKETBLOBS-1:PACKETBLOBS/2);
  101740. k++){
  101741. oggpack_buffer *opb=vbi->packetblob[k];
  101742. oggpack_write(opb,0,1);
  101743. oggpack_write(opb,modenumber,b->modebits);
  101744. if(vb->W){
  101745. oggpack_write(opb,vb->lW,1);
  101746. oggpack_write(opb,vb->nW,1);
  101747. }
  101748. for(i=0;i<vi->channels;i++){
  101749. int submap=info->chmuxlist[i];
  101750. float *mdct =gmdct[i];
  101751. float *res =vb->pcm[i];
  101752. int *ilogmask=ilogmaskch[i]=
  101753. (int*) _vorbis_block_alloc(vb,n/2*sizeof(**gmdct));
  101754. nonzero[i]=floor1_encode(opb,vb,b->flr[info->floorsubmap[submap]],
  101755. floor_posts[i][k],
  101756. ilogmask);
  101757. #if 0
  101758. {
  101759. char buf[80];
  101760. sprintf(buf,"maskI%c%d",i?'R':'L',k);
  101761. float work[n/2];
  101762. for(j=0;j<n/2;j++)
  101763. work[j]=FLOOR1_fromdB_LOOKUP[ilogmask[j]];
  101764. _analysis_output(buf,seq,work,n/2,1,1,0);
  101765. }
  101766. #endif
  101767. _vp_remove_floor(psy_look,
  101768. mdct,
  101769. ilogmask,
  101770. res,
  101771. ci->psy_g_param.sliding_lowpass[vb->W][k]);
  101772. _vp_noise_normalize(psy_look,res,res+n/2,sortindex[i]);
  101773. #if 0
  101774. {
  101775. char buf[80];
  101776. float work[n/2];
  101777. for(j=0;j<n/2;j++)
  101778. work[j]=FLOOR1_fromdB_LOOKUP[ilogmask[j]]*(res+n/2)[j];
  101779. sprintf(buf,"resI%c%d",i?'R':'L',k);
  101780. _analysis_output(buf,seq,work,n/2,1,1,0);
  101781. }
  101782. #endif
  101783. }
  101784. if(info->coupling_steps){
  101785. _vp_couple(k,
  101786. &ci->psy_g_param,
  101787. psy_look,
  101788. info,
  101789. vb->pcm,
  101790. mag_memo,
  101791. mag_sort,
  101792. ilogmaskch,
  101793. nonzero,
  101794. ci->psy_g_param.sliding_lowpass[vb->W][k]);
  101795. }
  101796. for(i=0;i<info->submaps;i++){
  101797. int ch_in_bundle=0;
  101798. long **classifications;
  101799. int resnum=info->residuesubmap[i];
  101800. for(j=0;j<vi->channels;j++){
  101801. if(info->chmuxlist[j]==i){
  101802. zerobundle[ch_in_bundle]=0;
  101803. if(nonzero[j])zerobundle[ch_in_bundle]=1;
  101804. res_bundle[ch_in_bundle]=vb->pcm[j];
  101805. couple_bundle[ch_in_bundle++]=vb->pcm[j]+n/2;
  101806. }
  101807. }
  101808. classifications=_residue_P[ci->residue_type[resnum]]->
  101809. classx(vb,b->residue[resnum],couple_bundle,zerobundle,ch_in_bundle);
  101810. _residue_P[ci->residue_type[resnum]]->
  101811. forward(opb,vb,b->residue[resnum],
  101812. couple_bundle,NULL,zerobundle,ch_in_bundle,classifications);
  101813. }
  101814. }
  101815. }
  101816. #if 0
  101817. seq++;
  101818. total+=ci->blocksizes[vb->W]/4+ci->blocksizes[vb->nW]/4;
  101819. #endif
  101820. return(0);
  101821. }
  101822. static int mapping0_inverse(vorbis_block *vb,vorbis_info_mapping *l){
  101823. vorbis_dsp_state *vd=vb->vd;
  101824. vorbis_info *vi=vd->vi;
  101825. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  101826. private_state *b=(private_state*)vd->backend_state;
  101827. vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)l;
  101828. int i,j;
  101829. long n=vb->pcmend=ci->blocksizes[vb->W];
  101830. float **pcmbundle=(float**) alloca(sizeof(*pcmbundle)*vi->channels);
  101831. int *zerobundle=(int*) alloca(sizeof(*zerobundle)*vi->channels);
  101832. int *nonzero =(int*) alloca(sizeof(*nonzero)*vi->channels);
  101833. void **floormemo=(void**) alloca(sizeof(*floormemo)*vi->channels);
  101834. for(i=0;i<vi->channels;i++){
  101835. int submap=info->chmuxlist[i];
  101836. floormemo[i]=_floor_P[ci->floor_type[info->floorsubmap[submap]]]->
  101837. inverse1(vb,b->flr[info->floorsubmap[submap]]);
  101838. if(floormemo[i])
  101839. nonzero[i]=1;
  101840. else
  101841. nonzero[i]=0;
  101842. memset(vb->pcm[i],0,sizeof(*vb->pcm[i])*n/2);
  101843. }
  101844. for(i=0;i<info->coupling_steps;i++){
  101845. if(nonzero[info->coupling_mag[i]] ||
  101846. nonzero[info->coupling_ang[i]]){
  101847. nonzero[info->coupling_mag[i]]=1;
  101848. nonzero[info->coupling_ang[i]]=1;
  101849. }
  101850. }
  101851. for(i=0;i<info->submaps;i++){
  101852. int ch_in_bundle=0;
  101853. for(j=0;j<vi->channels;j++){
  101854. if(info->chmuxlist[j]==i){
  101855. if(nonzero[j])
  101856. zerobundle[ch_in_bundle]=1;
  101857. else
  101858. zerobundle[ch_in_bundle]=0;
  101859. pcmbundle[ch_in_bundle++]=vb->pcm[j];
  101860. }
  101861. }
  101862. _residue_P[ci->residue_type[info->residuesubmap[i]]]->
  101863. inverse(vb,b->residue[info->residuesubmap[i]],
  101864. pcmbundle,zerobundle,ch_in_bundle);
  101865. }
  101866. for(i=info->coupling_steps-1;i>=0;i--){
  101867. float *pcmM=vb->pcm[info->coupling_mag[i]];
  101868. float *pcmA=vb->pcm[info->coupling_ang[i]];
  101869. for(j=0;j<n/2;j++){
  101870. float mag=pcmM[j];
  101871. float ang=pcmA[j];
  101872. if(mag>0)
  101873. if(ang>0){
  101874. pcmM[j]=mag;
  101875. pcmA[j]=mag-ang;
  101876. }else{
  101877. pcmA[j]=mag;
  101878. pcmM[j]=mag+ang;
  101879. }
  101880. else
  101881. if(ang>0){
  101882. pcmM[j]=mag;
  101883. pcmA[j]=mag+ang;
  101884. }else{
  101885. pcmA[j]=mag;
  101886. pcmM[j]=mag-ang;
  101887. }
  101888. }
  101889. }
  101890. for(i=0;i<vi->channels;i++){
  101891. float *pcm=vb->pcm[i];
  101892. int submap=info->chmuxlist[i];
  101893. _floor_P[ci->floor_type[info->floorsubmap[submap]]]->
  101894. inverse2(vb,b->flr[info->floorsubmap[submap]],
  101895. floormemo[i],pcm);
  101896. }
  101897. for(i=0;i<vi->channels;i++){
  101898. float *pcm=vb->pcm[i];
  101899. mdct_backward((mdct_lookup*) b->transform[vb->W][0],pcm,pcm);
  101900. }
  101901. return(0);
  101902. }
  101903. vorbis_func_mapping mapping0_exportbundle={
  101904. &mapping0_pack,
  101905. &mapping0_unpack,
  101906. &mapping0_free_info,
  101907. &mapping0_forward,
  101908. &mapping0_inverse
  101909. };
  101910. #endif
  101911. /*** End of inlined file: mapping0.c ***/
  101912. /*** Start of inlined file: mdct.c ***/
  101913. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  101914. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  101915. // tasks..
  101916. #if JUCE_MSVC
  101917. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  101918. #endif
  101919. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  101920. #if JUCE_USE_OGGVORBIS
  101921. #include <stdio.h>
  101922. #include <stdlib.h>
  101923. #include <string.h>
  101924. #include <math.h>
  101925. void mdct_init(mdct_lookup *lookup,int n){
  101926. int *bitrev=(int*) _ogg_malloc(sizeof(*bitrev)*(n/4));
  101927. DATA_TYPE *T=(DATA_TYPE*) _ogg_malloc(sizeof(*T)*(n+n/4));
  101928. int i;
  101929. int n2=n>>1;
  101930. int log2n=lookup->log2n=rint(log((float)n)/log(2.f));
  101931. lookup->n=n;
  101932. lookup->trig=T;
  101933. lookup->bitrev=bitrev;
  101934. for(i=0;i<n/4;i++){
  101935. T[i*2]=FLOAT_CONV(cos((M_PI/n)*(4*i)));
  101936. T[i*2+1]=FLOAT_CONV(-sin((M_PI/n)*(4*i)));
  101937. T[n2+i*2]=FLOAT_CONV(cos((M_PI/(2*n))*(2*i+1)));
  101938. T[n2+i*2+1]=FLOAT_CONV(sin((M_PI/(2*n))*(2*i+1)));
  101939. }
  101940. for(i=0;i<n/8;i++){
  101941. T[n+i*2]=FLOAT_CONV(cos((M_PI/n)*(4*i+2))*.5);
  101942. T[n+i*2+1]=FLOAT_CONV(-sin((M_PI/n)*(4*i+2))*.5);
  101943. }
  101944. {
  101945. int mask=(1<<(log2n-1))-1,i,j;
  101946. int msb=1<<(log2n-2);
  101947. for(i=0;i<n/8;i++){
  101948. int acc=0;
  101949. for(j=0;msb>>j;j++)
  101950. if((msb>>j)&i)acc|=1<<j;
  101951. bitrev[i*2]=((~acc)&mask)-1;
  101952. bitrev[i*2+1]=acc;
  101953. }
  101954. }
  101955. lookup->scale=FLOAT_CONV(4.f/n);
  101956. }
  101957. STIN void mdct_butterfly_8(DATA_TYPE *x){
  101958. REG_TYPE r0 = x[6] + x[2];
  101959. REG_TYPE r1 = x[6] - x[2];
  101960. REG_TYPE r2 = x[4] + x[0];
  101961. REG_TYPE r3 = x[4] - x[0];
  101962. x[6] = r0 + r2;
  101963. x[4] = r0 - r2;
  101964. r0 = x[5] - x[1];
  101965. r2 = x[7] - x[3];
  101966. x[0] = r1 + r0;
  101967. x[2] = r1 - r0;
  101968. r0 = x[5] + x[1];
  101969. r1 = x[7] + x[3];
  101970. x[3] = r2 + r3;
  101971. x[1] = r2 - r3;
  101972. x[7] = r1 + r0;
  101973. x[5] = r1 - r0;
  101974. }
  101975. STIN void mdct_butterfly_16(DATA_TYPE *x){
  101976. REG_TYPE r0 = x[1] - x[9];
  101977. REG_TYPE r1 = x[0] - x[8];
  101978. x[8] += x[0];
  101979. x[9] += x[1];
  101980. x[0] = MULT_NORM((r0 + r1) * cPI2_8);
  101981. x[1] = MULT_NORM((r0 - r1) * cPI2_8);
  101982. r0 = x[3] - x[11];
  101983. r1 = x[10] - x[2];
  101984. x[10] += x[2];
  101985. x[11] += x[3];
  101986. x[2] = r0;
  101987. x[3] = r1;
  101988. r0 = x[12] - x[4];
  101989. r1 = x[13] - x[5];
  101990. x[12] += x[4];
  101991. x[13] += x[5];
  101992. x[4] = MULT_NORM((r0 - r1) * cPI2_8);
  101993. x[5] = MULT_NORM((r0 + r1) * cPI2_8);
  101994. r0 = x[14] - x[6];
  101995. r1 = x[15] - x[7];
  101996. x[14] += x[6];
  101997. x[15] += x[7];
  101998. x[6] = r0;
  101999. x[7] = r1;
  102000. mdct_butterfly_8(x);
  102001. mdct_butterfly_8(x+8);
  102002. }
  102003. STIN void mdct_butterfly_32(DATA_TYPE *x){
  102004. REG_TYPE r0 = x[30] - x[14];
  102005. REG_TYPE r1 = x[31] - x[15];
  102006. x[30] += x[14];
  102007. x[31] += x[15];
  102008. x[14] = r0;
  102009. x[15] = r1;
  102010. r0 = x[28] - x[12];
  102011. r1 = x[29] - x[13];
  102012. x[28] += x[12];
  102013. x[29] += x[13];
  102014. x[12] = MULT_NORM( r0 * cPI1_8 - r1 * cPI3_8 );
  102015. x[13] = MULT_NORM( r0 * cPI3_8 + r1 * cPI1_8 );
  102016. r0 = x[26] - x[10];
  102017. r1 = x[27] - x[11];
  102018. x[26] += x[10];
  102019. x[27] += x[11];
  102020. x[10] = MULT_NORM(( r0 - r1 ) * cPI2_8);
  102021. x[11] = MULT_NORM(( r0 + r1 ) * cPI2_8);
  102022. r0 = x[24] - x[8];
  102023. r1 = x[25] - x[9];
  102024. x[24] += x[8];
  102025. x[25] += x[9];
  102026. x[8] = MULT_NORM( r0 * cPI3_8 - r1 * cPI1_8 );
  102027. x[9] = MULT_NORM( r1 * cPI3_8 + r0 * cPI1_8 );
  102028. r0 = x[22] - x[6];
  102029. r1 = x[7] - x[23];
  102030. x[22] += x[6];
  102031. x[23] += x[7];
  102032. x[6] = r1;
  102033. x[7] = r0;
  102034. r0 = x[4] - x[20];
  102035. r1 = x[5] - x[21];
  102036. x[20] += x[4];
  102037. x[21] += x[5];
  102038. x[4] = MULT_NORM( r1 * cPI1_8 + r0 * cPI3_8 );
  102039. x[5] = MULT_NORM( r1 * cPI3_8 - r0 * cPI1_8 );
  102040. r0 = x[2] - x[18];
  102041. r1 = x[3] - x[19];
  102042. x[18] += x[2];
  102043. x[19] += x[3];
  102044. x[2] = MULT_NORM(( r1 + r0 ) * cPI2_8);
  102045. x[3] = MULT_NORM(( r1 - r0 ) * cPI2_8);
  102046. r0 = x[0] - x[16];
  102047. r1 = x[1] - x[17];
  102048. x[16] += x[0];
  102049. x[17] += x[1];
  102050. x[0] = MULT_NORM( r1 * cPI3_8 + r0 * cPI1_8 );
  102051. x[1] = MULT_NORM( r1 * cPI1_8 - r0 * cPI3_8 );
  102052. mdct_butterfly_16(x);
  102053. mdct_butterfly_16(x+16);
  102054. }
  102055. STIN void mdct_butterfly_first(DATA_TYPE *T,
  102056. DATA_TYPE *x,
  102057. int points){
  102058. DATA_TYPE *x1 = x + points - 8;
  102059. DATA_TYPE *x2 = x + (points>>1) - 8;
  102060. REG_TYPE r0;
  102061. REG_TYPE r1;
  102062. do{
  102063. r0 = x1[6] - x2[6];
  102064. r1 = x1[7] - x2[7];
  102065. x1[6] += x2[6];
  102066. x1[7] += x2[7];
  102067. x2[6] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102068. x2[7] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102069. r0 = x1[4] - x2[4];
  102070. r1 = x1[5] - x2[5];
  102071. x1[4] += x2[4];
  102072. x1[5] += x2[5];
  102073. x2[4] = MULT_NORM(r1 * T[5] + r0 * T[4]);
  102074. x2[5] = MULT_NORM(r1 * T[4] - r0 * T[5]);
  102075. r0 = x1[2] - x2[2];
  102076. r1 = x1[3] - x2[3];
  102077. x1[2] += x2[2];
  102078. x1[3] += x2[3];
  102079. x2[2] = MULT_NORM(r1 * T[9] + r0 * T[8]);
  102080. x2[3] = MULT_NORM(r1 * T[8] - r0 * T[9]);
  102081. r0 = x1[0] - x2[0];
  102082. r1 = x1[1] - x2[1];
  102083. x1[0] += x2[0];
  102084. x1[1] += x2[1];
  102085. x2[0] = MULT_NORM(r1 * T[13] + r0 * T[12]);
  102086. x2[1] = MULT_NORM(r1 * T[12] - r0 * T[13]);
  102087. x1-=8;
  102088. x2-=8;
  102089. T+=16;
  102090. }while(x2>=x);
  102091. }
  102092. STIN void mdct_butterfly_generic(DATA_TYPE *T,
  102093. DATA_TYPE *x,
  102094. int points,
  102095. int trigint){
  102096. DATA_TYPE *x1 = x + points - 8;
  102097. DATA_TYPE *x2 = x + (points>>1) - 8;
  102098. REG_TYPE r0;
  102099. REG_TYPE r1;
  102100. do{
  102101. r0 = x1[6] - x2[6];
  102102. r1 = x1[7] - x2[7];
  102103. x1[6] += x2[6];
  102104. x1[7] += x2[7];
  102105. x2[6] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102106. x2[7] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102107. T+=trigint;
  102108. r0 = x1[4] - x2[4];
  102109. r1 = x1[5] - x2[5];
  102110. x1[4] += x2[4];
  102111. x1[5] += x2[5];
  102112. x2[4] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102113. x2[5] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102114. T+=trigint;
  102115. r0 = x1[2] - x2[2];
  102116. r1 = x1[3] - x2[3];
  102117. x1[2] += x2[2];
  102118. x1[3] += x2[3];
  102119. x2[2] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102120. x2[3] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102121. T+=trigint;
  102122. r0 = x1[0] - x2[0];
  102123. r1 = x1[1] - x2[1];
  102124. x1[0] += x2[0];
  102125. x1[1] += x2[1];
  102126. x2[0] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102127. x2[1] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102128. T+=trigint;
  102129. x1-=8;
  102130. x2-=8;
  102131. }while(x2>=x);
  102132. }
  102133. STIN void mdct_butterflies(mdct_lookup *init,
  102134. DATA_TYPE *x,
  102135. int points){
  102136. DATA_TYPE *T=init->trig;
  102137. int stages=init->log2n-5;
  102138. int i,j;
  102139. if(--stages>0){
  102140. mdct_butterfly_first(T,x,points);
  102141. }
  102142. for(i=1;--stages>0;i++){
  102143. for(j=0;j<(1<<i);j++)
  102144. mdct_butterfly_generic(T,x+(points>>i)*j,points>>i,4<<i);
  102145. }
  102146. for(j=0;j<points;j+=32)
  102147. mdct_butterfly_32(x+j);
  102148. }
  102149. void mdct_clear(mdct_lookup *l){
  102150. if(l){
  102151. if(l->trig)_ogg_free(l->trig);
  102152. if(l->bitrev)_ogg_free(l->bitrev);
  102153. memset(l,0,sizeof(*l));
  102154. }
  102155. }
  102156. STIN void mdct_bitreverse(mdct_lookup *init,
  102157. DATA_TYPE *x){
  102158. int n = init->n;
  102159. int *bit = init->bitrev;
  102160. DATA_TYPE *w0 = x;
  102161. DATA_TYPE *w1 = x = w0+(n>>1);
  102162. DATA_TYPE *T = init->trig+n;
  102163. do{
  102164. DATA_TYPE *x0 = x+bit[0];
  102165. DATA_TYPE *x1 = x+bit[1];
  102166. REG_TYPE r0 = x0[1] - x1[1];
  102167. REG_TYPE r1 = x0[0] + x1[0];
  102168. REG_TYPE r2 = MULT_NORM(r1 * T[0] + r0 * T[1]);
  102169. REG_TYPE r3 = MULT_NORM(r1 * T[1] - r0 * T[0]);
  102170. w1 -= 4;
  102171. r0 = HALVE(x0[1] + x1[1]);
  102172. r1 = HALVE(x0[0] - x1[0]);
  102173. w0[0] = r0 + r2;
  102174. w1[2] = r0 - r2;
  102175. w0[1] = r1 + r3;
  102176. w1[3] = r3 - r1;
  102177. x0 = x+bit[2];
  102178. x1 = x+bit[3];
  102179. r0 = x0[1] - x1[1];
  102180. r1 = x0[0] + x1[0];
  102181. r2 = MULT_NORM(r1 * T[2] + r0 * T[3]);
  102182. r3 = MULT_NORM(r1 * T[3] - r0 * T[2]);
  102183. r0 = HALVE(x0[1] + x1[1]);
  102184. r1 = HALVE(x0[0] - x1[0]);
  102185. w0[2] = r0 + r2;
  102186. w1[0] = r0 - r2;
  102187. w0[3] = r1 + r3;
  102188. w1[1] = r3 - r1;
  102189. T += 4;
  102190. bit += 4;
  102191. w0 += 4;
  102192. }while(w0<w1);
  102193. }
  102194. void mdct_backward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out){
  102195. int n=init->n;
  102196. int n2=n>>1;
  102197. int n4=n>>2;
  102198. DATA_TYPE *iX = in+n2-7;
  102199. DATA_TYPE *oX = out+n2+n4;
  102200. DATA_TYPE *T = init->trig+n4;
  102201. do{
  102202. oX -= 4;
  102203. oX[0] = MULT_NORM(-iX[2] * T[3] - iX[0] * T[2]);
  102204. oX[1] = MULT_NORM (iX[0] * T[3] - iX[2] * T[2]);
  102205. oX[2] = MULT_NORM(-iX[6] * T[1] - iX[4] * T[0]);
  102206. oX[3] = MULT_NORM (iX[4] * T[1] - iX[6] * T[0]);
  102207. iX -= 8;
  102208. T += 4;
  102209. }while(iX>=in);
  102210. iX = in+n2-8;
  102211. oX = out+n2+n4;
  102212. T = init->trig+n4;
  102213. do{
  102214. T -= 4;
  102215. oX[0] = MULT_NORM (iX[4] * T[3] + iX[6] * T[2]);
  102216. oX[1] = MULT_NORM (iX[4] * T[2] - iX[6] * T[3]);
  102217. oX[2] = MULT_NORM (iX[0] * T[1] + iX[2] * T[0]);
  102218. oX[3] = MULT_NORM (iX[0] * T[0] - iX[2] * T[1]);
  102219. iX -= 8;
  102220. oX += 4;
  102221. }while(iX>=in);
  102222. mdct_butterflies(init,out+n2,n2);
  102223. mdct_bitreverse(init,out);
  102224. {
  102225. DATA_TYPE *oX1=out+n2+n4;
  102226. DATA_TYPE *oX2=out+n2+n4;
  102227. DATA_TYPE *iX =out;
  102228. T =init->trig+n2;
  102229. do{
  102230. oX1-=4;
  102231. oX1[3] = MULT_NORM (iX[0] * T[1] - iX[1] * T[0]);
  102232. oX2[0] = -MULT_NORM (iX[0] * T[0] + iX[1] * T[1]);
  102233. oX1[2] = MULT_NORM (iX[2] * T[3] - iX[3] * T[2]);
  102234. oX2[1] = -MULT_NORM (iX[2] * T[2] + iX[3] * T[3]);
  102235. oX1[1] = MULT_NORM (iX[4] * T[5] - iX[5] * T[4]);
  102236. oX2[2] = -MULT_NORM (iX[4] * T[4] + iX[5] * T[5]);
  102237. oX1[0] = MULT_NORM (iX[6] * T[7] - iX[7] * T[6]);
  102238. oX2[3] = -MULT_NORM (iX[6] * T[6] + iX[7] * T[7]);
  102239. oX2+=4;
  102240. iX += 8;
  102241. T += 8;
  102242. }while(iX<oX1);
  102243. iX=out+n2+n4;
  102244. oX1=out+n4;
  102245. oX2=oX1;
  102246. do{
  102247. oX1-=4;
  102248. iX-=4;
  102249. oX2[0] = -(oX1[3] = iX[3]);
  102250. oX2[1] = -(oX1[2] = iX[2]);
  102251. oX2[2] = -(oX1[1] = iX[1]);
  102252. oX2[3] = -(oX1[0] = iX[0]);
  102253. oX2+=4;
  102254. }while(oX2<iX);
  102255. iX=out+n2+n4;
  102256. oX1=out+n2+n4;
  102257. oX2=out+n2;
  102258. do{
  102259. oX1-=4;
  102260. oX1[0]= iX[3];
  102261. oX1[1]= iX[2];
  102262. oX1[2]= iX[1];
  102263. oX1[3]= iX[0];
  102264. iX+=4;
  102265. }while(oX1>oX2);
  102266. }
  102267. }
  102268. void mdct_forward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out){
  102269. int n=init->n;
  102270. int n2=n>>1;
  102271. int n4=n>>2;
  102272. int n8=n>>3;
  102273. DATA_TYPE *w=(DATA_TYPE*) alloca(n*sizeof(*w)); /* forward needs working space */
  102274. DATA_TYPE *w2=w+n2;
  102275. REG_TYPE r0;
  102276. REG_TYPE r1;
  102277. DATA_TYPE *x0=in+n2+n4;
  102278. DATA_TYPE *x1=x0+1;
  102279. DATA_TYPE *T=init->trig+n2;
  102280. int i=0;
  102281. for(i=0;i<n8;i+=2){
  102282. x0 -=4;
  102283. T-=2;
  102284. r0= x0[2] + x1[0];
  102285. r1= x0[0] + x1[2];
  102286. w2[i]= MULT_NORM(r1*T[1] + r0*T[0]);
  102287. w2[i+1]= MULT_NORM(r1*T[0] - r0*T[1]);
  102288. x1 +=4;
  102289. }
  102290. x1=in+1;
  102291. for(;i<n2-n8;i+=2){
  102292. T-=2;
  102293. x0 -=4;
  102294. r0= x0[2] - x1[0];
  102295. r1= x0[0] - x1[2];
  102296. w2[i]= MULT_NORM(r1*T[1] + r0*T[0]);
  102297. w2[i+1]= MULT_NORM(r1*T[0] - r0*T[1]);
  102298. x1 +=4;
  102299. }
  102300. x0=in+n;
  102301. for(;i<n2;i+=2){
  102302. T-=2;
  102303. x0 -=4;
  102304. r0= -x0[2] - x1[0];
  102305. r1= -x0[0] - x1[2];
  102306. w2[i]= MULT_NORM(r1*T[1] + r0*T[0]);
  102307. w2[i+1]= MULT_NORM(r1*T[0] - r0*T[1]);
  102308. x1 +=4;
  102309. }
  102310. mdct_butterflies(init,w+n2,n2);
  102311. mdct_bitreverse(init,w);
  102312. T=init->trig+n2;
  102313. x0=out+n2;
  102314. for(i=0;i<n4;i++){
  102315. x0--;
  102316. out[i] =MULT_NORM((w[0]*T[0]+w[1]*T[1])*init->scale);
  102317. x0[0] =MULT_NORM((w[0]*T[1]-w[1]*T[0])*init->scale);
  102318. w+=2;
  102319. T+=2;
  102320. }
  102321. }
  102322. #endif
  102323. /*** End of inlined file: mdct.c ***/
  102324. /*** Start of inlined file: psy.c ***/
  102325. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  102326. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  102327. // tasks..
  102328. #if JUCE_MSVC
  102329. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  102330. #endif
  102331. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  102332. #if JUCE_USE_OGGVORBIS
  102333. #include <stdlib.h>
  102334. #include <math.h>
  102335. #include <string.h>
  102336. /*** Start of inlined file: masking.h ***/
  102337. #ifndef _V_MASKING_H_
  102338. #define _V_MASKING_H_
  102339. #define MAX_ATH 88
  102340. static float ATH[]={
  102341. -51, -52, -53, -54, -55, -56, -57, -58,
  102342. -59, -60, -61, -62, -63, -64, -65, -66,
  102343. -67, -68, -69, -70, -71, -72, -73, -74,
  102344. -75, -76, -77, -78, -80, -81, -82, -83,
  102345. -84, -85, -86, -87, -88, -88, -89, -89,
  102346. -90, -91, -91, -92, -93, -94, -95, -96,
  102347. -96, -97, -98, -98, -99, -99,-100,-100,
  102348. -101,-102,-103,-104,-106,-107,-107,-107,
  102349. -107,-105,-103,-102,-101, -99, -98, -96,
  102350. -95, -95, -96, -97, -96, -95, -93, -90,
  102351. -80, -70, -50, -40, -30, -30, -30, -30
  102352. };
  102353. #define EHMER_OFFSET 16
  102354. #define EHMER_MAX 56
  102355. static float tonemasks[P_BANDS][6][EHMER_MAX]={
  102356. {{ -60, -60, -60, -60, -60, -60, -60, -60,
  102357. -60, -60, -60, -60, -62, -62, -65, -73,
  102358. -69, -68, -68, -67, -70, -70, -72, -74,
  102359. -75, -79, -79, -80, -83, -88, -93, -100,
  102360. -110, -999, -999, -999, -999, -999, -999, -999,
  102361. -999, -999, -999, -999, -999, -999, -999, -999,
  102362. -999, -999, -999, -999, -999, -999, -999, -999},
  102363. { -48, -48, -48, -48, -48, -48, -48, -48,
  102364. -48, -48, -48, -48, -48, -53, -61, -66,
  102365. -66, -68, -67, -70, -76, -76, -72, -73,
  102366. -75, -76, -78, -79, -83, -88, -93, -100,
  102367. -110, -999, -999, -999, -999, -999, -999, -999,
  102368. -999, -999, -999, -999, -999, -999, -999, -999,
  102369. -999, -999, -999, -999, -999, -999, -999, -999},
  102370. { -37, -37, -37, -37, -37, -37, -37, -37,
  102371. -38, -40, -42, -46, -48, -53, -55, -62,
  102372. -65, -58, -56, -56, -61, -60, -65, -67,
  102373. -69, -71, -77, -77, -78, -80, -82, -84,
  102374. -88, -93, -98, -106, -112, -999, -999, -999,
  102375. -999, -999, -999, -999, -999, -999, -999, -999,
  102376. -999, -999, -999, -999, -999, -999, -999, -999},
  102377. { -25, -25, -25, -25, -25, -25, -25, -25,
  102378. -25, -26, -27, -29, -32, -38, -48, -52,
  102379. -52, -50, -48, -48, -51, -52, -54, -60,
  102380. -67, -67, -66, -68, -69, -73, -73, -76,
  102381. -80, -81, -81, -85, -85, -86, -88, -93,
  102382. -100, -110, -999, -999, -999, -999, -999, -999,
  102383. -999, -999, -999, -999, -999, -999, -999, -999},
  102384. { -16, -16, -16, -16, -16, -16, -16, -16,
  102385. -17, -19, -20, -22, -26, -28, -31, -40,
  102386. -47, -39, -39, -40, -42, -43, -47, -51,
  102387. -57, -52, -55, -55, -60, -58, -62, -63,
  102388. -70, -67, -69, -72, -73, -77, -80, -82,
  102389. -83, -87, -90, -94, -98, -104, -115, -999,
  102390. -999, -999, -999, -999, -999, -999, -999, -999},
  102391. { -8, -8, -8, -8, -8, -8, -8, -8,
  102392. -8, -8, -10, -11, -15, -19, -25, -30,
  102393. -34, -31, -30, -31, -29, -32, -35, -42,
  102394. -48, -42, -44, -46, -50, -50, -51, -52,
  102395. -59, -54, -55, -55, -58, -62, -63, -66,
  102396. -72, -73, -76, -75, -78, -80, -80, -81,
  102397. -84, -88, -90, -94, -98, -101, -106, -110}},
  102398. {{ -66, -66, -66, -66, -66, -66, -66, -66,
  102399. -66, -66, -66, -66, -66, -67, -67, -67,
  102400. -76, -72, -71, -74, -76, -76, -75, -78,
  102401. -79, -79, -81, -83, -86, -89, -93, -97,
  102402. -100, -105, -110, -999, -999, -999, -999, -999,
  102403. -999, -999, -999, -999, -999, -999, -999, -999,
  102404. -999, -999, -999, -999, -999, -999, -999, -999},
  102405. { -47, -47, -47, -47, -47, -47, -47, -47,
  102406. -47, -47, -47, -48, -51, -55, -59, -66,
  102407. -66, -66, -67, -66, -68, -69, -70, -74,
  102408. -79, -77, -77, -78, -80, -81, -82, -84,
  102409. -86, -88, -91, -95, -100, -108, -116, -999,
  102410. -999, -999, -999, -999, -999, -999, -999, -999,
  102411. -999, -999, -999, -999, -999, -999, -999, -999},
  102412. { -36, -36, -36, -36, -36, -36, -36, -36,
  102413. -36, -37, -37, -41, -44, -48, -51, -58,
  102414. -62, -60, -57, -59, -59, -60, -63, -65,
  102415. -72, -71, -70, -72, -74, -77, -76, -78,
  102416. -81, -81, -80, -83, -86, -91, -96, -100,
  102417. -105, -110, -999, -999, -999, -999, -999, -999,
  102418. -999, -999, -999, -999, -999, -999, -999, -999},
  102419. { -28, -28, -28, -28, -28, -28, -28, -28,
  102420. -28, -30, -32, -32, -33, -35, -41, -49,
  102421. -50, -49, -47, -48, -48, -52, -51, -57,
  102422. -65, -61, -59, -61, -64, -69, -70, -74,
  102423. -77, -77, -78, -81, -84, -85, -87, -90,
  102424. -92, -96, -100, -107, -112, -999, -999, -999,
  102425. -999, -999, -999, -999, -999, -999, -999, -999},
  102426. { -19, -19, -19, -19, -19, -19, -19, -19,
  102427. -20, -21, -23, -27, -30, -35, -36, -41,
  102428. -46, -44, -42, -40, -41, -41, -43, -48,
  102429. -55, -53, -52, -53, -56, -59, -58, -60,
  102430. -67, -66, -69, -71, -72, -75, -79, -81,
  102431. -84, -87, -90, -93, -97, -101, -107, -114,
  102432. -999, -999, -999, -999, -999, -999, -999, -999},
  102433. { -9, -9, -9, -9, -9, -9, -9, -9,
  102434. -11, -12, -12, -15, -16, -20, -23, -30,
  102435. -37, -34, -33, -34, -31, -32, -32, -38,
  102436. -47, -44, -41, -40, -47, -49, -46, -46,
  102437. -58, -50, -50, -54, -58, -62, -64, -67,
  102438. -67, -70, -72, -76, -79, -83, -87, -91,
  102439. -96, -100, -104, -110, -999, -999, -999, -999}},
  102440. {{ -62, -62, -62, -62, -62, -62, -62, -62,
  102441. -62, -62, -63, -64, -66, -67, -66, -68,
  102442. -75, -72, -76, -75, -76, -78, -79, -82,
  102443. -84, -85, -90, -94, -101, -110, -999, -999,
  102444. -999, -999, -999, -999, -999, -999, -999, -999,
  102445. -999, -999, -999, -999, -999, -999, -999, -999,
  102446. -999, -999, -999, -999, -999, -999, -999, -999},
  102447. { -59, -59, -59, -59, -59, -59, -59, -59,
  102448. -59, -59, -59, -60, -60, -61, -63, -66,
  102449. -71, -68, -70, -70, -71, -72, -72, -75,
  102450. -81, -78, -79, -82, -83, -86, -90, -97,
  102451. -103, -113, -999, -999, -999, -999, -999, -999,
  102452. -999, -999, -999, -999, -999, -999, -999, -999,
  102453. -999, -999, -999, -999, -999, -999, -999, -999},
  102454. { -53, -53, -53, -53, -53, -53, -53, -53,
  102455. -53, -54, -55, -57, -56, -57, -55, -61,
  102456. -65, -60, -60, -62, -63, -63, -66, -68,
  102457. -74, -73, -75, -75, -78, -80, -80, -82,
  102458. -85, -90, -96, -101, -108, -999, -999, -999,
  102459. -999, -999, -999, -999, -999, -999, -999, -999,
  102460. -999, -999, -999, -999, -999, -999, -999, -999},
  102461. { -46, -46, -46, -46, -46, -46, -46, -46,
  102462. -46, -46, -47, -47, -47, -47, -48, -51,
  102463. -57, -51, -49, -50, -51, -53, -54, -59,
  102464. -66, -60, -62, -67, -67, -70, -72, -75,
  102465. -76, -78, -81, -85, -88, -94, -97, -104,
  102466. -112, -999, -999, -999, -999, -999, -999, -999,
  102467. -999, -999, -999, -999, -999, -999, -999, -999},
  102468. { -36, -36, -36, -36, -36, -36, -36, -36,
  102469. -39, -41, -42, -42, -39, -38, -41, -43,
  102470. -52, -44, -40, -39, -37, -37, -40, -47,
  102471. -54, -50, -48, -50, -55, -61, -59, -62,
  102472. -66, -66, -66, -69, -69, -73, -74, -74,
  102473. -75, -77, -79, -82, -87, -91, -95, -100,
  102474. -108, -115, -999, -999, -999, -999, -999, -999},
  102475. { -28, -26, -24, -22, -20, -20, -23, -29,
  102476. -30, -31, -28, -27, -28, -28, -28, -35,
  102477. -40, -33, -32, -29, -30, -30, -30, -37,
  102478. -45, -41, -37, -38, -45, -47, -47, -48,
  102479. -53, -49, -48, -50, -49, -49, -51, -52,
  102480. -58, -56, -57, -56, -60, -61, -62, -70,
  102481. -72, -74, -78, -83, -88, -93, -100, -106}},
  102482. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102483. -999, -110, -105, -100, -95, -91, -87, -83,
  102484. -80, -78, -76, -78, -78, -81, -83, -85,
  102485. -86, -85, -86, -87, -90, -97, -107, -999,
  102486. -999, -999, -999, -999, -999, -999, -999, -999,
  102487. -999, -999, -999, -999, -999, -999, -999, -999,
  102488. -999, -999, -999, -999, -999, -999, -999, -999},
  102489. {-999, -999, -999, -110, -105, -100, -95, -90,
  102490. -85, -81, -77, -73, -70, -67, -67, -68,
  102491. -75, -73, -70, -69, -70, -72, -75, -79,
  102492. -84, -83, -84, -86, -88, -89, -89, -93,
  102493. -98, -105, -112, -999, -999, -999, -999, -999,
  102494. -999, -999, -999, -999, -999, -999, -999, -999,
  102495. -999, -999, -999, -999, -999, -999, -999, -999},
  102496. {-105, -100, -95, -90, -85, -80, -76, -71,
  102497. -68, -68, -65, -63, -63, -62, -62, -64,
  102498. -65, -64, -61, -62, -63, -64, -66, -68,
  102499. -73, -73, -74, -75, -76, -81, -83, -85,
  102500. -88, -89, -92, -95, -100, -108, -999, -999,
  102501. -999, -999, -999, -999, -999, -999, -999, -999,
  102502. -999, -999, -999, -999, -999, -999, -999, -999},
  102503. { -80, -75, -71, -68, -65, -63, -62, -61,
  102504. -61, -61, -61, -59, -56, -57, -53, -50,
  102505. -58, -52, -50, -50, -52, -53, -54, -58,
  102506. -67, -63, -67, -68, -72, -75, -78, -80,
  102507. -81, -81, -82, -85, -89, -90, -93, -97,
  102508. -101, -107, -114, -999, -999, -999, -999, -999,
  102509. -999, -999, -999, -999, -999, -999, -999, -999},
  102510. { -65, -61, -59, -57, -56, -55, -55, -56,
  102511. -56, -57, -55, -53, -52, -47, -44, -44,
  102512. -50, -44, -41, -39, -39, -42, -40, -46,
  102513. -51, -49, -50, -53, -54, -63, -60, -61,
  102514. -62, -66, -66, -66, -70, -73, -74, -75,
  102515. -76, -75, -79, -85, -89, -91, -96, -102,
  102516. -110, -999, -999, -999, -999, -999, -999, -999},
  102517. { -52, -50, -49, -49, -48, -48, -48, -49,
  102518. -50, -50, -49, -46, -43, -39, -35, -33,
  102519. -38, -36, -32, -29, -32, -32, -32, -35,
  102520. -44, -39, -38, -38, -46, -50, -45, -46,
  102521. -53, -50, -50, -50, -54, -54, -53, -53,
  102522. -56, -57, -59, -66, -70, -72, -74, -79,
  102523. -83, -85, -90, -97, -114, -999, -999, -999}},
  102524. {{-999, -999, -999, -999, -999, -999, -110, -105,
  102525. -100, -95, -90, -86, -80, -75, -75, -79,
  102526. -80, -79, -80, -81, -82, -88, -95, -103,
  102527. -110, -999, -999, -999, -999, -999, -999, -999,
  102528. -999, -999, -999, -999, -999, -999, -999, -999,
  102529. -999, -999, -999, -999, -999, -999, -999, -999,
  102530. -999, -999, -999, -999, -999, -999, -999, -999},
  102531. {-999, -999, -999, -999, -108, -103, -98, -93,
  102532. -88, -83, -79, -78, -75, -71, -67, -68,
  102533. -73, -73, -72, -73, -75, -77, -80, -82,
  102534. -88, -93, -100, -107, -114, -999, -999, -999,
  102535. -999, -999, -999, -999, -999, -999, -999, -999,
  102536. -999, -999, -999, -999, -999, -999, -999, -999,
  102537. -999, -999, -999, -999, -999, -999, -999, -999},
  102538. {-999, -999, -999, -110, -105, -101, -96, -90,
  102539. -86, -81, -77, -73, -69, -66, -61, -62,
  102540. -66, -64, -62, -65, -66, -70, -72, -76,
  102541. -81, -80, -84, -90, -95, -102, -110, -999,
  102542. -999, -999, -999, -999, -999, -999, -999, -999,
  102543. -999, -999, -999, -999, -999, -999, -999, -999,
  102544. -999, -999, -999, -999, -999, -999, -999, -999},
  102545. {-999, -999, -999, -107, -103, -97, -92, -88,
  102546. -83, -79, -74, -70, -66, -59, -53, -58,
  102547. -62, -55, -54, -54, -54, -58, -61, -62,
  102548. -72, -70, -72, -75, -78, -80, -81, -80,
  102549. -83, -83, -88, -93, -100, -107, -115, -999,
  102550. -999, -999, -999, -999, -999, -999, -999, -999,
  102551. -999, -999, -999, -999, -999, -999, -999, -999},
  102552. {-999, -999, -999, -105, -100, -95, -90, -85,
  102553. -80, -75, -70, -66, -62, -56, -48, -44,
  102554. -48, -46, -46, -43, -46, -48, -48, -51,
  102555. -58, -58, -59, -60, -62, -62, -61, -61,
  102556. -65, -64, -65, -68, -70, -74, -75, -78,
  102557. -81, -86, -95, -110, -999, -999, -999, -999,
  102558. -999, -999, -999, -999, -999, -999, -999, -999},
  102559. {-999, -999, -105, -100, -95, -90, -85, -80,
  102560. -75, -70, -65, -61, -55, -49, -39, -33,
  102561. -40, -35, -32, -38, -40, -33, -35, -37,
  102562. -46, -41, -45, -44, -46, -42, -45, -46,
  102563. -52, -50, -50, -50, -54, -54, -55, -57,
  102564. -62, -64, -66, -68, -70, -76, -81, -90,
  102565. -100, -110, -999, -999, -999, -999, -999, -999}},
  102566. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102567. -105, -98, -90, -85, -82, -83, -80, -78,
  102568. -84, -79, -80, -83, -87, -89, -91, -93,
  102569. -99, -106, -117, -999, -999, -999, -999, -999,
  102570. -999, -999, -999, -999, -999, -999, -999, -999,
  102571. -999, -999, -999, -999, -999, -999, -999, -999,
  102572. -999, -999, -999, -999, -999, -999, -999, -999},
  102573. {-999, -999, -999, -999, -999, -999, -999, -999,
  102574. -105, -98, -90, -85, -80, -75, -70, -68,
  102575. -74, -72, -74, -77, -80, -82, -85, -87,
  102576. -92, -89, -91, -95, -100, -106, -112, -999,
  102577. -999, -999, -999, -999, -999, -999, -999, -999,
  102578. -999, -999, -999, -999, -999, -999, -999, -999,
  102579. -999, -999, -999, -999, -999, -999, -999, -999},
  102580. {-999, -999, -999, -999, -999, -999, -999, -999,
  102581. -105, -98, -90, -83, -75, -71, -63, -64,
  102582. -67, -62, -64, -67, -70, -73, -77, -81,
  102583. -84, -83, -85, -89, -90, -93, -98, -104,
  102584. -109, -114, -999, -999, -999, -999, -999, -999,
  102585. -999, -999, -999, -999, -999, -999, -999, -999,
  102586. -999, -999, -999, -999, -999, -999, -999, -999},
  102587. {-999, -999, -999, -999, -999, -999, -999, -999,
  102588. -103, -96, -88, -81, -75, -68, -58, -54,
  102589. -56, -54, -56, -56, -58, -60, -63, -66,
  102590. -74, -69, -72, -72, -75, -74, -77, -81,
  102591. -81, -82, -84, -87, -93, -96, -99, -104,
  102592. -110, -999, -999, -999, -999, -999, -999, -999,
  102593. -999, -999, -999, -999, -999, -999, -999, -999},
  102594. {-999, -999, -999, -999, -999, -108, -102, -96,
  102595. -91, -85, -80, -74, -68, -60, -51, -46,
  102596. -48, -46, -43, -45, -47, -47, -49, -48,
  102597. -56, -53, -55, -58, -57, -63, -58, -60,
  102598. -66, -64, -67, -70, -70, -74, -77, -84,
  102599. -86, -89, -91, -93, -94, -101, -109, -118,
  102600. -999, -999, -999, -999, -999, -999, -999, -999},
  102601. {-999, -999, -999, -108, -103, -98, -93, -88,
  102602. -83, -78, -73, -68, -60, -53, -44, -35,
  102603. -38, -38, -34, -34, -36, -40, -41, -44,
  102604. -51, -45, -46, -47, -46, -54, -50, -49,
  102605. -50, -50, -50, -51, -54, -57, -58, -60,
  102606. -66, -66, -66, -64, -65, -68, -77, -82,
  102607. -87, -95, -110, -999, -999, -999, -999, -999}},
  102608. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102609. -107, -102, -97, -92, -87, -83, -78, -75,
  102610. -82, -79, -83, -85, -89, -92, -95, -98,
  102611. -101, -105, -109, -113, -999, -999, -999, -999,
  102612. -999, -999, -999, -999, -999, -999, -999, -999,
  102613. -999, -999, -999, -999, -999, -999, -999, -999,
  102614. -999, -999, -999, -999, -999, -999, -999, -999},
  102615. {-999, -999, -999, -999, -999, -999, -999, -106,
  102616. -100, -95, -90, -86, -81, -78, -74, -69,
  102617. -74, -74, -76, -79, -83, -84, -86, -89,
  102618. -92, -97, -93, -100, -103, -107, -110, -999,
  102619. -999, -999, -999, -999, -999, -999, -999, -999,
  102620. -999, -999, -999, -999, -999, -999, -999, -999,
  102621. -999, -999, -999, -999, -999, -999, -999, -999},
  102622. {-999, -999, -999, -999, -999, -999, -106, -100,
  102623. -95, -90, -87, -83, -80, -75, -69, -60,
  102624. -66, -66, -68, -70, -74, -78, -79, -81,
  102625. -81, -83, -84, -87, -93, -96, -99, -103,
  102626. -107, -110, -999, -999, -999, -999, -999, -999,
  102627. -999, -999, -999, -999, -999, -999, -999, -999,
  102628. -999, -999, -999, -999, -999, -999, -999, -999},
  102629. {-999, -999, -999, -999, -999, -108, -103, -98,
  102630. -93, -89, -85, -82, -78, -71, -62, -55,
  102631. -58, -58, -54, -54, -55, -59, -61, -62,
  102632. -70, -66, -66, -67, -70, -72, -75, -78,
  102633. -84, -84, -84, -88, -91, -90, -95, -98,
  102634. -102, -103, -106, -110, -999, -999, -999, -999,
  102635. -999, -999, -999, -999, -999, -999, -999, -999},
  102636. {-999, -999, -999, -999, -108, -103, -98, -94,
  102637. -90, -87, -82, -79, -73, -67, -58, -47,
  102638. -50, -45, -41, -45, -48, -44, -44, -49,
  102639. -54, -51, -48, -47, -49, -50, -51, -57,
  102640. -58, -60, -63, -69, -70, -69, -71, -74,
  102641. -78, -82, -90, -95, -101, -105, -110, -999,
  102642. -999, -999, -999, -999, -999, -999, -999, -999},
  102643. {-999, -999, -999, -105, -101, -97, -93, -90,
  102644. -85, -80, -77, -72, -65, -56, -48, -37,
  102645. -40, -36, -34, -40, -50, -47, -38, -41,
  102646. -47, -38, -35, -39, -38, -43, -40, -45,
  102647. -50, -45, -44, -47, -50, -55, -48, -48,
  102648. -52, -66, -70, -76, -82, -90, -97, -105,
  102649. -110, -999, -999, -999, -999, -999, -999, -999}},
  102650. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102651. -999, -108, -103, -98, -93, -86, -79, -76,
  102652. -83, -81, -85, -87, -89, -93, -98, -102,
  102653. -107, -112, -999, -999, -999, -999, -999, -999,
  102654. -999, -999, -999, -999, -999, -999, -999, -999,
  102655. -999, -999, -999, -999, -999, -999, -999, -999,
  102656. -999, -999, -999, -999, -999, -999, -999, -999},
  102657. {-999, -999, -999, -999, -999, -999, -999, -999,
  102658. -999, -108, -103, -98, -93, -86, -79, -71,
  102659. -77, -74, -77, -79, -81, -84, -85, -90,
  102660. -92, -93, -92, -98, -101, -108, -112, -999,
  102661. -999, -999, -999, -999, -999, -999, -999, -999,
  102662. -999, -999, -999, -999, -999, -999, -999, -999,
  102663. -999, -999, -999, -999, -999, -999, -999, -999},
  102664. {-999, -999, -999, -999, -999, -999, -999, -999,
  102665. -108, -103, -98, -93, -87, -78, -68, -65,
  102666. -66, -62, -65, -67, -70, -73, -75, -78,
  102667. -82, -82, -83, -84, -91, -93, -98, -102,
  102668. -106, -110, -999, -999, -999, -999, -999, -999,
  102669. -999, -999, -999, -999, -999, -999, -999, -999,
  102670. -999, -999, -999, -999, -999, -999, -999, -999},
  102671. {-999, -999, -999, -999, -999, -999, -999, -999,
  102672. -105, -100, -95, -90, -82, -74, -62, -57,
  102673. -58, -56, -51, -52, -52, -54, -54, -58,
  102674. -66, -59, -60, -63, -66, -69, -73, -79,
  102675. -83, -84, -80, -81, -81, -82, -88, -92,
  102676. -98, -105, -113, -999, -999, -999, -999, -999,
  102677. -999, -999, -999, -999, -999, -999, -999, -999},
  102678. {-999, -999, -999, -999, -999, -999, -999, -107,
  102679. -102, -97, -92, -84, -79, -69, -57, -47,
  102680. -52, -47, -44, -45, -50, -52, -42, -42,
  102681. -53, -43, -43, -48, -51, -56, -55, -52,
  102682. -57, -59, -61, -62, -67, -71, -78, -83,
  102683. -86, -94, -98, -103, -110, -999, -999, -999,
  102684. -999, -999, -999, -999, -999, -999, -999, -999},
  102685. {-999, -999, -999, -999, -999, -999, -105, -100,
  102686. -95, -90, -84, -78, -70, -61, -51, -41,
  102687. -40, -38, -40, -46, -52, -51, -41, -40,
  102688. -46, -40, -38, -38, -41, -46, -41, -46,
  102689. -47, -43, -43, -45, -41, -45, -56, -67,
  102690. -68, -83, -87, -90, -95, -102, -107, -113,
  102691. -999, -999, -999, -999, -999, -999, -999, -999}},
  102692. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102693. -999, -109, -105, -101, -96, -91, -84, -77,
  102694. -82, -82, -85, -89, -94, -100, -106, -110,
  102695. -999, -999, -999, -999, -999, -999, -999, -999,
  102696. -999, -999, -999, -999, -999, -999, -999, -999,
  102697. -999, -999, -999, -999, -999, -999, -999, -999,
  102698. -999, -999, -999, -999, -999, -999, -999, -999},
  102699. {-999, -999, -999, -999, -999, -999, -999, -999,
  102700. -999, -106, -103, -98, -92, -85, -80, -71,
  102701. -75, -72, -76, -80, -84, -86, -89, -93,
  102702. -100, -107, -113, -999, -999, -999, -999, -999,
  102703. -999, -999, -999, -999, -999, -999, -999, -999,
  102704. -999, -999, -999, -999, -999, -999, -999, -999,
  102705. -999, -999, -999, -999, -999, -999, -999, -999},
  102706. {-999, -999, -999, -999, -999, -999, -999, -107,
  102707. -104, -101, -97, -92, -88, -84, -80, -64,
  102708. -66, -63, -64, -66, -69, -73, -77, -83,
  102709. -83, -86, -91, -98, -104, -111, -999, -999,
  102710. -999, -999, -999, -999, -999, -999, -999, -999,
  102711. -999, -999, -999, -999, -999, -999, -999, -999,
  102712. -999, -999, -999, -999, -999, -999, -999, -999},
  102713. {-999, -999, -999, -999, -999, -999, -999, -107,
  102714. -104, -101, -97, -92, -90, -84, -74, -57,
  102715. -58, -52, -55, -54, -50, -52, -50, -52,
  102716. -63, -62, -69, -76, -77, -78, -78, -79,
  102717. -82, -88, -94, -100, -106, -111, -999, -999,
  102718. -999, -999, -999, -999, -999, -999, -999, -999,
  102719. -999, -999, -999, -999, -999, -999, -999, -999},
  102720. {-999, -999, -999, -999, -999, -999, -106, -102,
  102721. -98, -95, -90, -85, -83, -78, -70, -50,
  102722. -50, -41, -44, -49, -47, -50, -50, -44,
  102723. -55, -46, -47, -48, -48, -54, -49, -49,
  102724. -58, -62, -71, -81, -87, -92, -97, -102,
  102725. -108, -114, -999, -999, -999, -999, -999, -999,
  102726. -999, -999, -999, -999, -999, -999, -999, -999},
  102727. {-999, -999, -999, -999, -999, -999, -106, -102,
  102728. -98, -95, -90, -85, -83, -78, -70, -45,
  102729. -43, -41, -47, -50, -51, -50, -49, -45,
  102730. -47, -41, -44, -41, -39, -43, -38, -37,
  102731. -40, -41, -44, -50, -58, -65, -73, -79,
  102732. -85, -92, -97, -101, -105, -109, -113, -999,
  102733. -999, -999, -999, -999, -999, -999, -999, -999}},
  102734. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102735. -999, -999, -999, -107, -100, -95, -87, -81,
  102736. -85, -83, -88, -93, -100, -107, -114, -999,
  102737. -999, -999, -999, -999, -999, -999, -999, -999,
  102738. -999, -999, -999, -999, -999, -999, -999, -999,
  102739. -999, -999, -999, -999, -999, -999, -999, -999,
  102740. -999, -999, -999, -999, -999, -999, -999, -999},
  102741. {-999, -999, -999, -999, -999, -999, -999, -999,
  102742. -999, -999, -107, -101, -95, -88, -83, -76,
  102743. -73, -72, -79, -84, -90, -95, -100, -105,
  102744. -110, -115, -999, -999, -999, -999, -999, -999,
  102745. -999, -999, -999, -999, -999, -999, -999, -999,
  102746. -999, -999, -999, -999, -999, -999, -999, -999,
  102747. -999, -999, -999, -999, -999, -999, -999, -999},
  102748. {-999, -999, -999, -999, -999, -999, -999, -999,
  102749. -999, -999, -104, -98, -92, -87, -81, -70,
  102750. -65, -62, -67, -71, -74, -80, -85, -91,
  102751. -95, -99, -103, -108, -111, -114, -999, -999,
  102752. -999, -999, -999, -999, -999, -999, -999, -999,
  102753. -999, -999, -999, -999, -999, -999, -999, -999,
  102754. -999, -999, -999, -999, -999, -999, -999, -999},
  102755. {-999, -999, -999, -999, -999, -999, -999, -999,
  102756. -999, -999, -103, -97, -90, -85, -76, -60,
  102757. -56, -54, -60, -62, -61, -56, -63, -65,
  102758. -73, -74, -77, -75, -78, -81, -86, -87,
  102759. -88, -91, -94, -98, -103, -110, -999, -999,
  102760. -999, -999, -999, -999, -999, -999, -999, -999,
  102761. -999, -999, -999, -999, -999, -999, -999, -999},
  102762. {-999, -999, -999, -999, -999, -999, -999, -105,
  102763. -100, -97, -92, -86, -81, -79, -70, -57,
  102764. -51, -47, -51, -58, -60, -56, -53, -50,
  102765. -58, -52, -50, -50, -53, -55, -64, -69,
  102766. -71, -85, -82, -78, -81, -85, -95, -102,
  102767. -112, -999, -999, -999, -999, -999, -999, -999,
  102768. -999, -999, -999, -999, -999, -999, -999, -999},
  102769. {-999, -999, -999, -999, -999, -999, -999, -105,
  102770. -100, -97, -92, -85, -83, -79, -72, -49,
  102771. -40, -43, -43, -54, -56, -51, -50, -40,
  102772. -43, -38, -36, -35, -37, -38, -37, -44,
  102773. -54, -60, -57, -60, -70, -75, -84, -92,
  102774. -103, -112, -999, -999, -999, -999, -999, -999,
  102775. -999, -999, -999, -999, -999, -999, -999, -999}},
  102776. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102777. -999, -999, -999, -110, -102, -95, -89, -82,
  102778. -83, -84, -90, -92, -99, -107, -113, -999,
  102779. -999, -999, -999, -999, -999, -999, -999, -999,
  102780. -999, -999, -999, -999, -999, -999, -999, -999,
  102781. -999, -999, -999, -999, -999, -999, -999, -999,
  102782. -999, -999, -999, -999, -999, -999, -999, -999},
  102783. {-999, -999, -999, -999, -999, -999, -999, -999,
  102784. -999, -999, -107, -101, -95, -89, -83, -72,
  102785. -74, -78, -85, -88, -88, -90, -92, -98,
  102786. -105, -111, -999, -999, -999, -999, -999, -999,
  102787. -999, -999, -999, -999, -999, -999, -999, -999,
  102788. -999, -999, -999, -999, -999, -999, -999, -999,
  102789. -999, -999, -999, -999, -999, -999, -999, -999},
  102790. {-999, -999, -999, -999, -999, -999, -999, -999,
  102791. -999, -109, -103, -97, -93, -87, -81, -70,
  102792. -70, -67, -75, -73, -76, -79, -81, -83,
  102793. -88, -89, -97, -103, -110, -999, -999, -999,
  102794. -999, -999, -999, -999, -999, -999, -999, -999,
  102795. -999, -999, -999, -999, -999, -999, -999, -999,
  102796. -999, -999, -999, -999, -999, -999, -999, -999},
  102797. {-999, -999, -999, -999, -999, -999, -999, -999,
  102798. -999, -107, -100, -94, -88, -83, -75, -63,
  102799. -59, -59, -63, -66, -60, -62, -67, -67,
  102800. -77, -76, -81, -88, -86, -92, -96, -102,
  102801. -109, -116, -999, -999, -999, -999, -999, -999,
  102802. -999, -999, -999, -999, -999, -999, -999, -999,
  102803. -999, -999, -999, -999, -999, -999, -999, -999},
  102804. {-999, -999, -999, -999, -999, -999, -999, -999,
  102805. -999, -105, -98, -92, -86, -81, -73, -56,
  102806. -52, -47, -55, -60, -58, -52, -51, -45,
  102807. -49, -50, -53, -54, -61, -71, -70, -69,
  102808. -78, -79, -87, -90, -96, -104, -112, -999,
  102809. -999, -999, -999, -999, -999, -999, -999, -999,
  102810. -999, -999, -999, -999, -999, -999, -999, -999},
  102811. {-999, -999, -999, -999, -999, -999, -999, -999,
  102812. -999, -103, -96, -90, -86, -78, -70, -51,
  102813. -42, -47, -48, -55, -54, -54, -53, -42,
  102814. -35, -28, -33, -38, -37, -44, -47, -49,
  102815. -54, -63, -68, -78, -82, -89, -94, -99,
  102816. -104, -109, -114, -999, -999, -999, -999, -999,
  102817. -999, -999, -999, -999, -999, -999, -999, -999}},
  102818. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102819. -999, -999, -999, -999, -110, -100, -90, -79,
  102820. -85, -81, -82, -82, -89, -94, -99, -103,
  102821. -109, -115, -999, -999, -999, -999, -999, -999,
  102822. -999, -999, -999, -999, -999, -999, -999, -999,
  102823. -999, -999, -999, -999, -999, -999, -999, -999,
  102824. -999, -999, -999, -999, -999, -999, -999, -999},
  102825. {-999, -999, -999, -999, -999, -999, -999, -999,
  102826. -999, -999, -999, -999, -105, -97, -85, -72,
  102827. -74, -70, -70, -70, -76, -85, -91, -93,
  102828. -97, -103, -109, -115, -999, -999, -999, -999,
  102829. -999, -999, -999, -999, -999, -999, -999, -999,
  102830. -999, -999, -999, -999, -999, -999, -999, -999,
  102831. -999, -999, -999, -999, -999, -999, -999, -999},
  102832. {-999, -999, -999, -999, -999, -999, -999, -999,
  102833. -999, -999, -999, -999, -112, -93, -81, -68,
  102834. -62, -60, -60, -57, -63, -70, -77, -82,
  102835. -90, -93, -98, -104, -109, -113, -999, -999,
  102836. -999, -999, -999, -999, -999, -999, -999, -999,
  102837. -999, -999, -999, -999, -999, -999, -999, -999,
  102838. -999, -999, -999, -999, -999, -999, -999, -999},
  102839. {-999, -999, -999, -999, -999, -999, -999, -999,
  102840. -999, -999, -999, -113, -100, -93, -84, -63,
  102841. -58, -48, -53, -54, -52, -52, -57, -64,
  102842. -66, -76, -83, -81, -85, -85, -90, -95,
  102843. -98, -101, -103, -106, -108, -111, -999, -999,
  102844. -999, -999, -999, -999, -999, -999, -999, -999,
  102845. -999, -999, -999, -999, -999, -999, -999, -999},
  102846. {-999, -999, -999, -999, -999, -999, -999, -999,
  102847. -999, -999, -999, -105, -95, -86, -74, -53,
  102848. -50, -38, -43, -49, -43, -42, -39, -39,
  102849. -46, -52, -57, -56, -72, -69, -74, -81,
  102850. -87, -92, -94, -97, -99, -102, -105, -108,
  102851. -999, -999, -999, -999, -999, -999, -999, -999,
  102852. -999, -999, -999, -999, -999, -999, -999, -999},
  102853. {-999, -999, -999, -999, -999, -999, -999, -999,
  102854. -999, -999, -108, -99, -90, -76, -66, -45,
  102855. -43, -41, -44, -47, -43, -47, -40, -30,
  102856. -31, -31, -39, -33, -40, -41, -43, -53,
  102857. -59, -70, -73, -77, -79, -82, -84, -87,
  102858. -999, -999, -999, -999, -999, -999, -999, -999,
  102859. -999, -999, -999, -999, -999, -999, -999, -999}},
  102860. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102861. -999, -999, -999, -999, -999, -110, -91, -76,
  102862. -75, -85, -93, -98, -104, -110, -999, -999,
  102863. -999, -999, -999, -999, -999, -999, -999, -999,
  102864. -999, -999, -999, -999, -999, -999, -999, -999,
  102865. -999, -999, -999, -999, -999, -999, -999, -999,
  102866. -999, -999, -999, -999, -999, -999, -999, -999},
  102867. {-999, -999, -999, -999, -999, -999, -999, -999,
  102868. -999, -999, -999, -999, -999, -110, -91, -70,
  102869. -70, -75, -86, -89, -94, -98, -101, -106,
  102870. -110, -999, -999, -999, -999, -999, -999, -999,
  102871. -999, -999, -999, -999, -999, -999, -999, -999,
  102872. -999, -999, -999, -999, -999, -999, -999, -999,
  102873. -999, -999, -999, -999, -999, -999, -999, -999},
  102874. {-999, -999, -999, -999, -999, -999, -999, -999,
  102875. -999, -999, -999, -999, -110, -95, -80, -60,
  102876. -65, -64, -74, -83, -88, -91, -95, -99,
  102877. -103, -107, -110, -999, -999, -999, -999, -999,
  102878. -999, -999, -999, -999, -999, -999, -999, -999,
  102879. -999, -999, -999, -999, -999, -999, -999, -999,
  102880. -999, -999, -999, -999, -999, -999, -999, -999},
  102881. {-999, -999, -999, -999, -999, -999, -999, -999,
  102882. -999, -999, -999, -999, -110, -95, -80, -58,
  102883. -55, -49, -66, -68, -71, -78, -78, -80,
  102884. -88, -85, -89, -97, -100, -105, -110, -999,
  102885. -999, -999, -999, -999, -999, -999, -999, -999,
  102886. -999, -999, -999, -999, -999, -999, -999, -999,
  102887. -999, -999, -999, -999, -999, -999, -999, -999},
  102888. {-999, -999, -999, -999, -999, -999, -999, -999,
  102889. -999, -999, -999, -999, -110, -95, -80, -53,
  102890. -52, -41, -59, -59, -49, -58, -56, -63,
  102891. -86, -79, -90, -93, -98, -103, -107, -112,
  102892. -999, -999, -999, -999, -999, -999, -999, -999,
  102893. -999, -999, -999, -999, -999, -999, -999, -999,
  102894. -999, -999, -999, -999, -999, -999, -999, -999},
  102895. {-999, -999, -999, -999, -999, -999, -999, -999,
  102896. -999, -999, -999, -110, -97, -91, -73, -45,
  102897. -40, -33, -53, -61, -49, -54, -50, -50,
  102898. -60, -52, -67, -74, -81, -92, -96, -100,
  102899. -105, -110, -999, -999, -999, -999, -999, -999,
  102900. -999, -999, -999, -999, -999, -999, -999, -999,
  102901. -999, -999, -999, -999, -999, -999, -999, -999}},
  102902. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102903. -999, -999, -999, -113, -106, -99, -92, -77,
  102904. -80, -88, -97, -106, -115, -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, -999, -999, -999, -999,
  102908. -999, -999, -999, -999, -999, -999, -999, -999},
  102909. {-999, -999, -999, -999, -999, -999, -999, -999,
  102910. -999, -999, -116, -109, -102, -95, -89, -74,
  102911. -72, -88, -87, -95, -102, -109, -116, -999,
  102912. -999, -999, -999, -999, -999, -999, -999, -999,
  102913. -999, -999, -999, -999, -999, -999, -999, -999,
  102914. -999, -999, -999, -999, -999, -999, -999, -999,
  102915. -999, -999, -999, -999, -999, -999, -999, -999},
  102916. {-999, -999, -999, -999, -999, -999, -999, -999,
  102917. -999, -999, -116, -109, -102, -95, -89, -75,
  102918. -66, -74, -77, -78, -86, -87, -90, -96,
  102919. -105, -115, -999, -999, -999, -999, -999, -999,
  102920. -999, -999, -999, -999, -999, -999, -999, -999,
  102921. -999, -999, -999, -999, -999, -999, -999, -999,
  102922. -999, -999, -999, -999, -999, -999, -999, -999},
  102923. {-999, -999, -999, -999, -999, -999, -999, -999,
  102924. -999, -999, -115, -108, -101, -94, -88, -66,
  102925. -56, -61, -70, -65, -78, -72, -83, -84,
  102926. -93, -98, -105, -110, -999, -999, -999, -999,
  102927. -999, -999, -999, -999, -999, -999, -999, -999,
  102928. -999, -999, -999, -999, -999, -999, -999, -999,
  102929. -999, -999, -999, -999, -999, -999, -999, -999},
  102930. {-999, -999, -999, -999, -999, -999, -999, -999,
  102931. -999, -999, -110, -105, -95, -89, -82, -57,
  102932. -52, -52, -59, -56, -59, -58, -69, -67,
  102933. -88, -82, -82, -89, -94, -100, -108, -999,
  102934. -999, -999, -999, -999, -999, -999, -999, -999,
  102935. -999, -999, -999, -999, -999, -999, -999, -999,
  102936. -999, -999, -999, -999, -999, -999, -999, -999},
  102937. {-999, -999, -999, -999, -999, -999, -999, -999,
  102938. -999, -110, -101, -96, -90, -83, -77, -54,
  102939. -43, -38, -50, -48, -52, -48, -42, -42,
  102940. -51, -52, -53, -59, -65, -71, -78, -85,
  102941. -95, -999, -999, -999, -999, -999, -999, -999,
  102942. -999, -999, -999, -999, -999, -999, -999, -999,
  102943. -999, -999, -999, -999, -999, -999, -999, -999}},
  102944. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102945. -999, -999, -999, -999, -120, -105, -86, -68,
  102946. -78, -79, -90, -100, -110, -999, -999, -999,
  102947. -999, -999, -999, -999, -999, -999, -999, -999,
  102948. -999, -999, -999, -999, -999, -999, -999, -999,
  102949. -999, -999, -999, -999, -999, -999, -999, -999,
  102950. -999, -999, -999, -999, -999, -999, -999, -999},
  102951. {-999, -999, -999, -999, -999, -999, -999, -999,
  102952. -999, -999, -999, -999, -120, -105, -86, -66,
  102953. -73, -77, -88, -96, -105, -115, -999, -999,
  102954. -999, -999, -999, -999, -999, -999, -999, -999,
  102955. -999, -999, -999, -999, -999, -999, -999, -999,
  102956. -999, -999, -999, -999, -999, -999, -999, -999,
  102957. -999, -999, -999, -999, -999, -999, -999, -999},
  102958. {-999, -999, -999, -999, -999, -999, -999, -999,
  102959. -999, -999, -999, -120, -105, -92, -80, -61,
  102960. -64, -68, -80, -87, -92, -100, -110, -999,
  102961. -999, -999, -999, -999, -999, -999, -999, -999,
  102962. -999, -999, -999, -999, -999, -999, -999, -999,
  102963. -999, -999, -999, -999, -999, -999, -999, -999,
  102964. -999, -999, -999, -999, -999, -999, -999, -999},
  102965. {-999, -999, -999, -999, -999, -999, -999, -999,
  102966. -999, -999, -999, -120, -104, -91, -79, -52,
  102967. -60, -54, -64, -69, -77, -80, -82, -84,
  102968. -85, -87, -88, -90, -999, -999, -999, -999,
  102969. -999, -999, -999, -999, -999, -999, -999, -999,
  102970. -999, -999, -999, -999, -999, -999, -999, -999,
  102971. -999, -999, -999, -999, -999, -999, -999, -999},
  102972. {-999, -999, -999, -999, -999, -999, -999, -999,
  102973. -999, -999, -999, -118, -100, -87, -77, -49,
  102974. -50, -44, -58, -61, -61, -67, -65, -62,
  102975. -62, -62, -65, -68, -999, -999, -999, -999,
  102976. -999, -999, -999, -999, -999, -999, -999, -999,
  102977. -999, -999, -999, -999, -999, -999, -999, -999,
  102978. -999, -999, -999, -999, -999, -999, -999, -999},
  102979. {-999, -999, -999, -999, -999, -999, -999, -999,
  102980. -999, -999, -999, -115, -98, -84, -62, -49,
  102981. -44, -38, -46, -49, -49, -46, -39, -37,
  102982. -39, -40, -42, -43, -999, -999, -999, -999,
  102983. -999, -999, -999, -999, -999, -999, -999, -999,
  102984. -999, -999, -999, -999, -999, -999, -999, -999,
  102985. -999, -999, -999, -999, -999, -999, -999, -999}},
  102986. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102987. -999, -999, -999, -999, -999, -110, -88, -74,
  102988. -77, -82, -82, -85, -90, -94, -99, -104,
  102989. -999, -999, -999, -999, -999, -999, -999, -999,
  102990. -999, -999, -999, -999, -999, -999, -999, -999,
  102991. -999, -999, -999, -999, -999, -999, -999, -999,
  102992. -999, -999, -999, -999, -999, -999, -999, -999},
  102993. {-999, -999, -999, -999, -999, -999, -999, -999,
  102994. -999, -999, -999, -999, -999, -110, -88, -66,
  102995. -70, -81, -80, -81, -84, -88, -91, -93,
  102996. -999, -999, -999, -999, -999, -999, -999, -999,
  102997. -999, -999, -999, -999, -999, -999, -999, -999,
  102998. -999, -999, -999, -999, -999, -999, -999, -999,
  102999. -999, -999, -999, -999, -999, -999, -999, -999},
  103000. {-999, -999, -999, -999, -999, -999, -999, -999,
  103001. -999, -999, -999, -999, -999, -110, -88, -61,
  103002. -63, -70, -71, -74, -77, -80, -83, -85,
  103003. -999, -999, -999, -999, -999, -999, -999, -999,
  103004. -999, -999, -999, -999, -999, -999, -999, -999,
  103005. -999, -999, -999, -999, -999, -999, -999, -999,
  103006. -999, -999, -999, -999, -999, -999, -999, -999},
  103007. {-999, -999, -999, -999, -999, -999, -999, -999,
  103008. -999, -999, -999, -999, -999, -110, -86, -62,
  103009. -63, -62, -62, -58, -52, -50, -50, -52,
  103010. -54, -999, -999, -999, -999, -999, -999, -999,
  103011. -999, -999, -999, -999, -999, -999, -999, -999,
  103012. -999, -999, -999, -999, -999, -999, -999, -999,
  103013. -999, -999, -999, -999, -999, -999, -999, -999},
  103014. {-999, -999, -999, -999, -999, -999, -999, -999,
  103015. -999, -999, -999, -999, -118, -108, -84, -53,
  103016. -50, -50, -50, -55, -47, -45, -40, -40,
  103017. -40, -999, -999, -999, -999, -999, -999, -999,
  103018. -999, -999, -999, -999, -999, -999, -999, -999,
  103019. -999, -999, -999, -999, -999, -999, -999, -999,
  103020. -999, -999, -999, -999, -999, -999, -999, -999},
  103021. {-999, -999, -999, -999, -999, -999, -999, -999,
  103022. -999, -999, -999, -999, -118, -100, -73, -43,
  103023. -37, -42, -43, -53, -38, -37, -35, -35,
  103024. -38, -999, -999, -999, -999, -999, -999, -999,
  103025. -999, -999, -999, -999, -999, -999, -999, -999,
  103026. -999, -999, -999, -999, -999, -999, -999, -999,
  103027. -999, -999, -999, -999, -999, -999, -999, -999}},
  103028. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103029. -999, -999, -999, -110, -100, -91, -84, -74,
  103030. -80, -80, -80, -80, -80, -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, -999, -999, -999,
  103034. -999, -999, -999, -999, -999, -999, -999, -999},
  103035. {-999, -999, -999, -999, -999, -999, -999, -999,
  103036. -999, -999, -999, -110, -100, -91, -84, -74,
  103037. -68, -68, -68, -68, -68, -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, -999, -999, -999, -999,
  103041. -999, -999, -999, -999, -999, -999, -999, -999},
  103042. {-999, -999, -999, -999, -999, -999, -999, -999,
  103043. -999, -999, -999, -110, -100, -86, -78, -70,
  103044. -60, -45, -30, -21, -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, -999, -999, -999, -999,
  103048. -999, -999, -999, -999, -999, -999, -999, -999},
  103049. {-999, -999, -999, -999, -999, -999, -999, -999,
  103050. -999, -999, -999, -110, -100, -87, -78, -67,
  103051. -48, -38, -29, -21, -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, -999, -999, -999, -999, -999,
  103055. -999, -999, -999, -999, -999, -999, -999, -999},
  103056. {-999, -999, -999, -999, -999, -999, -999, -999,
  103057. -999, -999, -999, -110, -100, -86, -69, -56,
  103058. -45, -35, -33, -29, -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, -999, -999, -999, -999, -999,
  103062. -999, -999, -999, -999, -999, -999, -999, -999},
  103063. {-999, -999, -999, -999, -999, -999, -999, -999,
  103064. -999, -999, -999, -110, -100, -83, -71, -48,
  103065. -27, -38, -37, -34, -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, -999, -999, -999, -999, -999,
  103069. -999, -999, -999, -999, -999, -999, -999, -999}}
  103070. };
  103071. #endif
  103072. /*** End of inlined file: masking.h ***/
  103073. #define NEGINF -9999.f
  103074. static double stereo_threshholds[]={0.0, .5, 1.0, 1.5, 2.5, 4.5, 8.5, 16.5, 9e10};
  103075. static double stereo_threshholds_limited[]={0.0, .5, 1.0, 1.5, 2.0, 2.5, 4.5, 8.5, 9e10};
  103076. vorbis_look_psy_global *_vp_global_look(vorbis_info *vi){
  103077. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  103078. vorbis_info_psy_global *gi=&ci->psy_g_param;
  103079. vorbis_look_psy_global *look=(vorbis_look_psy_global*)_ogg_calloc(1,sizeof(*look));
  103080. look->channels=vi->channels;
  103081. look->ampmax=-9999.;
  103082. look->gi=gi;
  103083. return(look);
  103084. }
  103085. void _vp_global_free(vorbis_look_psy_global *look){
  103086. if(look){
  103087. memset(look,0,sizeof(*look));
  103088. _ogg_free(look);
  103089. }
  103090. }
  103091. void _vi_gpsy_free(vorbis_info_psy_global *i){
  103092. if(i){
  103093. memset(i,0,sizeof(*i));
  103094. _ogg_free(i);
  103095. }
  103096. }
  103097. void _vi_psy_free(vorbis_info_psy *i){
  103098. if(i){
  103099. memset(i,0,sizeof(*i));
  103100. _ogg_free(i);
  103101. }
  103102. }
  103103. static void min_curve(float *c,
  103104. float *c2){
  103105. int i;
  103106. for(i=0;i<EHMER_MAX;i++)if(c2[i]<c[i])c[i]=c2[i];
  103107. }
  103108. static void max_curve(float *c,
  103109. float *c2){
  103110. int i;
  103111. for(i=0;i<EHMER_MAX;i++)if(c2[i]>c[i])c[i]=c2[i];
  103112. }
  103113. static void attenuate_curve(float *c,float att){
  103114. int i;
  103115. for(i=0;i<EHMER_MAX;i++)
  103116. c[i]+=att;
  103117. }
  103118. static float ***setup_tone_curves(float curveatt_dB[P_BANDS],float binHz,int n,
  103119. float center_boost, float center_decay_rate){
  103120. int i,j,k,m;
  103121. float ath[EHMER_MAX];
  103122. float workc[P_BANDS][P_LEVELS][EHMER_MAX];
  103123. float athc[P_LEVELS][EHMER_MAX];
  103124. float *brute_buffer=(float*) alloca(n*sizeof(*brute_buffer));
  103125. float ***ret=(float***) _ogg_malloc(sizeof(*ret)*P_BANDS);
  103126. memset(workc,0,sizeof(workc));
  103127. for(i=0;i<P_BANDS;i++){
  103128. int ath_offset=i*4;
  103129. for(j=0;j<EHMER_MAX;j++){
  103130. float min=999.;
  103131. for(k=0;k<4;k++)
  103132. if(j+k+ath_offset<MAX_ATH){
  103133. if(min>ATH[j+k+ath_offset])min=ATH[j+k+ath_offset];
  103134. }else{
  103135. if(min>ATH[MAX_ATH-1])min=ATH[MAX_ATH-1];
  103136. }
  103137. ath[j]=min;
  103138. }
  103139. for(j=0;j<6;j++)
  103140. memcpy(workc[i][j+2],tonemasks[i][j],EHMER_MAX*sizeof(*tonemasks[i][j]));
  103141. memcpy(workc[i][0],tonemasks[i][0],EHMER_MAX*sizeof(*tonemasks[i][0]));
  103142. memcpy(workc[i][1],tonemasks[i][0],EHMER_MAX*sizeof(*tonemasks[i][0]));
  103143. for(j=0;j<P_LEVELS;j++){
  103144. for(k=0;k<EHMER_MAX;k++){
  103145. float adj=center_boost+abs(EHMER_OFFSET-k)*center_decay_rate;
  103146. if(adj<0. && center_boost>0)adj=0.;
  103147. if(adj>0. && center_boost<0)adj=0.;
  103148. workc[i][j][k]+=adj;
  103149. }
  103150. }
  103151. for(j=0;j<P_LEVELS;j++){
  103152. attenuate_curve(workc[i][j],curveatt_dB[i]+100.-(j<2?2:j)*10.-P_LEVEL_0);
  103153. memcpy(athc[j],ath,EHMER_MAX*sizeof(**athc));
  103154. attenuate_curve(athc[j],+100.-j*10.f-P_LEVEL_0);
  103155. max_curve(athc[j],workc[i][j]);
  103156. }
  103157. for(j=1;j<P_LEVELS;j++){
  103158. min_curve(athc[j],athc[j-1]);
  103159. min_curve(workc[i][j],athc[j]);
  103160. }
  103161. }
  103162. for(i=0;i<P_BANDS;i++){
  103163. int hi_curve,lo_curve,bin;
  103164. ret[i]=(float**)_ogg_malloc(sizeof(**ret)*P_LEVELS);
  103165. bin=floor(fromOC(i*.5)/binHz);
  103166. lo_curve= ceil(toOC(bin*binHz+1)*2);
  103167. hi_curve= floor(toOC((bin+1)*binHz)*2);
  103168. if(lo_curve>i)lo_curve=i;
  103169. if(lo_curve<0)lo_curve=0;
  103170. if(hi_curve>=P_BANDS)hi_curve=P_BANDS-1;
  103171. for(m=0;m<P_LEVELS;m++){
  103172. ret[i][m]=(float*)_ogg_malloc(sizeof(***ret)*(EHMER_MAX+2));
  103173. for(j=0;j<n;j++)brute_buffer[j]=999.;
  103174. for(k=lo_curve;k<=hi_curve;k++){
  103175. int l=0;
  103176. for(j=0;j<EHMER_MAX;j++){
  103177. int lo_bin= fromOC(j*.125+k*.5-2.0625)/binHz;
  103178. int hi_bin= fromOC(j*.125+k*.5-1.9375)/binHz+1;
  103179. if(lo_bin<0)lo_bin=0;
  103180. if(lo_bin>n)lo_bin=n;
  103181. if(lo_bin<l)l=lo_bin;
  103182. if(hi_bin<0)hi_bin=0;
  103183. if(hi_bin>n)hi_bin=n;
  103184. for(;l<hi_bin && l<n;l++)
  103185. if(brute_buffer[l]>workc[k][m][j])
  103186. brute_buffer[l]=workc[k][m][j];
  103187. }
  103188. for(;l<n;l++)
  103189. if(brute_buffer[l]>workc[k][m][EHMER_MAX-1])
  103190. brute_buffer[l]=workc[k][m][EHMER_MAX-1];
  103191. }
  103192. if(i+1<P_BANDS){
  103193. int l=0;
  103194. k=i+1;
  103195. for(j=0;j<EHMER_MAX;j++){
  103196. int lo_bin= fromOC(j*.125+i*.5-2.0625)/binHz;
  103197. int hi_bin= fromOC(j*.125+i*.5-1.9375)/binHz+1;
  103198. if(lo_bin<0)lo_bin=0;
  103199. if(lo_bin>n)lo_bin=n;
  103200. if(lo_bin<l)l=lo_bin;
  103201. if(hi_bin<0)hi_bin=0;
  103202. if(hi_bin>n)hi_bin=n;
  103203. for(;l<hi_bin && l<n;l++)
  103204. if(brute_buffer[l]>workc[k][m][j])
  103205. brute_buffer[l]=workc[k][m][j];
  103206. }
  103207. for(;l<n;l++)
  103208. if(brute_buffer[l]>workc[k][m][EHMER_MAX-1])
  103209. brute_buffer[l]=workc[k][m][EHMER_MAX-1];
  103210. }
  103211. for(j=0;j<EHMER_MAX;j++){
  103212. int bin=fromOC(j*.125+i*.5-2.)/binHz;
  103213. if(bin<0){
  103214. ret[i][m][j+2]=-999.;
  103215. }else{
  103216. if(bin>=n){
  103217. ret[i][m][j+2]=-999.;
  103218. }else{
  103219. ret[i][m][j+2]=brute_buffer[bin];
  103220. }
  103221. }
  103222. }
  103223. for(j=0;j<EHMER_OFFSET;j++)
  103224. if(ret[i][m][j+2]>-200.f)break;
  103225. ret[i][m][0]=j;
  103226. for(j=EHMER_MAX-1;j>EHMER_OFFSET+1;j--)
  103227. if(ret[i][m][j+2]>-200.f)
  103228. break;
  103229. ret[i][m][1]=j;
  103230. }
  103231. }
  103232. return(ret);
  103233. }
  103234. void _vp_psy_init(vorbis_look_psy *p,vorbis_info_psy *vi,
  103235. vorbis_info_psy_global *gi,int n,long rate){
  103236. long i,j,lo=-99,hi=1;
  103237. long maxoc;
  103238. memset(p,0,sizeof(*p));
  103239. p->eighth_octave_lines=gi->eighth_octave_lines;
  103240. p->shiftoc=rint(log(gi->eighth_octave_lines*8.f)/log(2.f))-1;
  103241. p->firstoc=toOC(.25f*rate*.5/n)*(1<<(p->shiftoc+1))-gi->eighth_octave_lines;
  103242. maxoc=toOC((n+.25f)*rate*.5/n)*(1<<(p->shiftoc+1))+.5f;
  103243. p->total_octave_lines=maxoc-p->firstoc+1;
  103244. p->ath=(float*)_ogg_malloc(n*sizeof(*p->ath));
  103245. p->octave=(long*)_ogg_malloc(n*sizeof(*p->octave));
  103246. p->bark=(long*)_ogg_malloc(n*sizeof(*p->bark));
  103247. p->vi=vi;
  103248. p->n=n;
  103249. p->rate=rate;
  103250. p->m_val = 1.;
  103251. if(rate < 26000) p->m_val = 0;
  103252. else if(rate < 38000) p->m_val = .94; /* 32kHz */
  103253. else if(rate > 46000) p->m_val = 1.275; /* 48kHz */
  103254. for(i=0,j=0;i<MAX_ATH-1;i++){
  103255. int endpos=rint(fromOC((i+1)*.125-2.)*2*n/rate);
  103256. float base=ATH[i];
  103257. if(j<endpos){
  103258. float delta=(ATH[i+1]-base)/(endpos-j);
  103259. for(;j<endpos && j<n;j++){
  103260. p->ath[j]=base+100.;
  103261. base+=delta;
  103262. }
  103263. }
  103264. }
  103265. for(i=0;i<n;i++){
  103266. float bark=toBARK(rate/(2*n)*i);
  103267. for(;lo+vi->noisewindowlomin<i &&
  103268. toBARK(rate/(2*n)*lo)<(bark-vi->noisewindowlo);lo++);
  103269. for(;hi<=n && (hi<i+vi->noisewindowhimin ||
  103270. toBARK(rate/(2*n)*hi)<(bark+vi->noisewindowhi));hi++);
  103271. p->bark[i]=((lo-1)<<16)+(hi-1);
  103272. }
  103273. for(i=0;i<n;i++)
  103274. p->octave[i]=toOC((i+.25f)*.5*rate/n)*(1<<(p->shiftoc+1))+.5f;
  103275. p->tonecurves=setup_tone_curves(vi->toneatt,rate*.5/n,n,
  103276. vi->tone_centerboost,vi->tone_decay);
  103277. p->noiseoffset=(float**)_ogg_malloc(P_NOISECURVES*sizeof(*p->noiseoffset));
  103278. for(i=0;i<P_NOISECURVES;i++)
  103279. p->noiseoffset[i]=(float*)_ogg_malloc(n*sizeof(**p->noiseoffset));
  103280. for(i=0;i<n;i++){
  103281. float halfoc=toOC((i+.5)*rate/(2.*n))*2.;
  103282. int inthalfoc;
  103283. float del;
  103284. if(halfoc<0)halfoc=0;
  103285. if(halfoc>=P_BANDS-1)halfoc=P_BANDS-1;
  103286. inthalfoc=(int)halfoc;
  103287. del=halfoc-inthalfoc;
  103288. for(j=0;j<P_NOISECURVES;j++)
  103289. p->noiseoffset[j][i]=
  103290. p->vi->noiseoff[j][inthalfoc]*(1.-del) +
  103291. p->vi->noiseoff[j][inthalfoc+1]*del;
  103292. }
  103293. #if 0
  103294. {
  103295. static int ls=0;
  103296. _analysis_output_always("noiseoff0",ls,p->noiseoffset[0],n,1,0,0);
  103297. _analysis_output_always("noiseoff1",ls,p->noiseoffset[1],n,1,0,0);
  103298. _analysis_output_always("noiseoff2",ls++,p->noiseoffset[2],n,1,0,0);
  103299. }
  103300. #endif
  103301. }
  103302. void _vp_psy_clear(vorbis_look_psy *p){
  103303. int i,j;
  103304. if(p){
  103305. if(p->ath)_ogg_free(p->ath);
  103306. if(p->octave)_ogg_free(p->octave);
  103307. if(p->bark)_ogg_free(p->bark);
  103308. if(p->tonecurves){
  103309. for(i=0;i<P_BANDS;i++){
  103310. for(j=0;j<P_LEVELS;j++){
  103311. _ogg_free(p->tonecurves[i][j]);
  103312. }
  103313. _ogg_free(p->tonecurves[i]);
  103314. }
  103315. _ogg_free(p->tonecurves);
  103316. }
  103317. if(p->noiseoffset){
  103318. for(i=0;i<P_NOISECURVES;i++){
  103319. _ogg_free(p->noiseoffset[i]);
  103320. }
  103321. _ogg_free(p->noiseoffset);
  103322. }
  103323. memset(p,0,sizeof(*p));
  103324. }
  103325. }
  103326. static void seed_curve(float *seed,
  103327. const float **curves,
  103328. float amp,
  103329. int oc, int n,
  103330. int linesper,float dBoffset){
  103331. int i,post1;
  103332. int seedptr;
  103333. const float *posts,*curve;
  103334. int choice=(int)((amp+dBoffset-P_LEVEL_0)*.1f);
  103335. choice=max(choice,0);
  103336. choice=min(choice,P_LEVELS-1);
  103337. posts=curves[choice];
  103338. curve=posts+2;
  103339. post1=(int)posts[1];
  103340. seedptr=oc+(posts[0]-EHMER_OFFSET)*linesper-(linesper>>1);
  103341. for(i=posts[0];i<post1;i++){
  103342. if(seedptr>0){
  103343. float lin=amp+curve[i];
  103344. if(seed[seedptr]<lin)seed[seedptr]=lin;
  103345. }
  103346. seedptr+=linesper;
  103347. if(seedptr>=n)break;
  103348. }
  103349. }
  103350. static void seed_loop(vorbis_look_psy *p,
  103351. const float ***curves,
  103352. const float *f,
  103353. const float *flr,
  103354. float *seed,
  103355. float specmax){
  103356. vorbis_info_psy *vi=p->vi;
  103357. long n=p->n,i;
  103358. float dBoffset=vi->max_curve_dB-specmax;
  103359. for(i=0;i<n;i++){
  103360. float max=f[i];
  103361. long oc=p->octave[i];
  103362. while(i+1<n && p->octave[i+1]==oc){
  103363. i++;
  103364. if(f[i]>max)max=f[i];
  103365. }
  103366. if(max+6.f>flr[i]){
  103367. oc=oc>>p->shiftoc;
  103368. if(oc>=P_BANDS)oc=P_BANDS-1;
  103369. if(oc<0)oc=0;
  103370. seed_curve(seed,
  103371. curves[oc],
  103372. max,
  103373. p->octave[i]-p->firstoc,
  103374. p->total_octave_lines,
  103375. p->eighth_octave_lines,
  103376. dBoffset);
  103377. }
  103378. }
  103379. }
  103380. static void seed_chase(float *seeds, int linesper, long n){
  103381. long *posstack=(long*)alloca(n*sizeof(*posstack));
  103382. float *ampstack=(float*)alloca(n*sizeof(*ampstack));
  103383. long stack=0;
  103384. long pos=0;
  103385. long i;
  103386. for(i=0;i<n;i++){
  103387. if(stack<2){
  103388. posstack[stack]=i;
  103389. ampstack[stack++]=seeds[i];
  103390. }else{
  103391. while(1){
  103392. if(seeds[i]<ampstack[stack-1]){
  103393. posstack[stack]=i;
  103394. ampstack[stack++]=seeds[i];
  103395. break;
  103396. }else{
  103397. if(i<posstack[stack-1]+linesper){
  103398. if(stack>1 && ampstack[stack-1]<=ampstack[stack-2] &&
  103399. i<posstack[stack-2]+linesper){
  103400. stack--;
  103401. continue;
  103402. }
  103403. }
  103404. posstack[stack]=i;
  103405. ampstack[stack++]=seeds[i];
  103406. break;
  103407. }
  103408. }
  103409. }
  103410. }
  103411. for(i=0;i<stack;i++){
  103412. long endpos;
  103413. if(i<stack-1 && ampstack[i+1]>ampstack[i]){
  103414. endpos=posstack[i+1];
  103415. }else{
  103416. endpos=posstack[i]+linesper+1; /* +1 is important, else bin 0 is
  103417. discarded in short frames */
  103418. }
  103419. if(endpos>n)endpos=n;
  103420. for(;pos<endpos;pos++)
  103421. seeds[pos]=ampstack[i];
  103422. }
  103423. }
  103424. #include<stdio.h>
  103425. static void max_seeds(vorbis_look_psy *p,
  103426. float *seed,
  103427. float *flr){
  103428. long n=p->total_octave_lines;
  103429. int linesper=p->eighth_octave_lines;
  103430. long linpos=0;
  103431. long pos;
  103432. seed_chase(seed,linesper,n); /* for masking */
  103433. pos=p->octave[0]-p->firstoc-(linesper>>1);
  103434. while(linpos+1<p->n){
  103435. float minV=seed[pos];
  103436. long end=((p->octave[linpos]+p->octave[linpos+1])>>1)-p->firstoc;
  103437. if(minV>p->vi->tone_abs_limit)minV=p->vi->tone_abs_limit;
  103438. while(pos+1<=end){
  103439. pos++;
  103440. if((seed[pos]>NEGINF && seed[pos]<minV) || minV==NEGINF)
  103441. minV=seed[pos];
  103442. }
  103443. end=pos+p->firstoc;
  103444. for(;linpos<p->n && p->octave[linpos]<=end;linpos++)
  103445. if(flr[linpos]<minV)flr[linpos]=minV;
  103446. }
  103447. {
  103448. float minV=seed[p->total_octave_lines-1];
  103449. for(;linpos<p->n;linpos++)
  103450. if(flr[linpos]<minV)flr[linpos]=minV;
  103451. }
  103452. }
  103453. static void bark_noise_hybridmp(int n,const long *b,
  103454. const float *f,
  103455. float *noise,
  103456. const float offset,
  103457. const int fixed){
  103458. float *N=(float*) alloca(n*sizeof(*N));
  103459. float *X=(float*) alloca(n*sizeof(*N));
  103460. float *XX=(float*) alloca(n*sizeof(*N));
  103461. float *Y=(float*) alloca(n*sizeof(*N));
  103462. float *XY=(float*) alloca(n*sizeof(*N));
  103463. float tN, tX, tXX, tY, tXY;
  103464. int i;
  103465. int lo, hi;
  103466. float R, A, B, D;
  103467. float w, x, y;
  103468. tN = tX = tXX = tY = tXY = 0.f;
  103469. y = f[0] + offset;
  103470. if (y < 1.f) y = 1.f;
  103471. w = y * y * .5;
  103472. tN += w;
  103473. tX += w;
  103474. tY += w * y;
  103475. N[0] = tN;
  103476. X[0] = tX;
  103477. XX[0] = tXX;
  103478. Y[0] = tY;
  103479. XY[0] = tXY;
  103480. for (i = 1, x = 1.f; i < n; i++, x += 1.f) {
  103481. y = f[i] + offset;
  103482. if (y < 1.f) y = 1.f;
  103483. w = y * y;
  103484. tN += w;
  103485. tX += w * x;
  103486. tXX += w * x * x;
  103487. tY += w * y;
  103488. tXY += w * x * y;
  103489. N[i] = tN;
  103490. X[i] = tX;
  103491. XX[i] = tXX;
  103492. Y[i] = tY;
  103493. XY[i] = tXY;
  103494. }
  103495. for (i = 0, x = 0.f;; i++, x += 1.f) {
  103496. lo = b[i] >> 16;
  103497. if( lo>=0 ) break;
  103498. hi = b[i] & 0xffff;
  103499. tN = N[hi] + N[-lo];
  103500. tX = X[hi] - X[-lo];
  103501. tXX = XX[hi] + XX[-lo];
  103502. tY = Y[hi] + Y[-lo];
  103503. tXY = XY[hi] - XY[-lo];
  103504. A = tY * tXX - tX * tXY;
  103505. B = tN * tXY - tX * tY;
  103506. D = tN * tXX - tX * tX;
  103507. R = (A + x * B) / D;
  103508. if (R < 0.f)
  103509. R = 0.f;
  103510. noise[i] = R - offset;
  103511. }
  103512. for ( ;; i++, x += 1.f) {
  103513. lo = b[i] >> 16;
  103514. hi = b[i] & 0xffff;
  103515. if(hi>=n)break;
  103516. tN = N[hi] - N[lo];
  103517. tX = X[hi] - X[lo];
  103518. tXX = XX[hi] - XX[lo];
  103519. tY = Y[hi] - Y[lo];
  103520. tXY = XY[hi] - XY[lo];
  103521. A = tY * tXX - tX * tXY;
  103522. B = tN * tXY - tX * tY;
  103523. D = tN * tXX - tX * tX;
  103524. R = (A + x * B) / D;
  103525. if (R < 0.f) R = 0.f;
  103526. noise[i] = R - offset;
  103527. }
  103528. for ( ; i < n; i++, x += 1.f) {
  103529. R = (A + x * B) / D;
  103530. if (R < 0.f) R = 0.f;
  103531. noise[i] = R - offset;
  103532. }
  103533. if (fixed <= 0) return;
  103534. for (i = 0, x = 0.f;; i++, x += 1.f) {
  103535. hi = i + fixed / 2;
  103536. lo = hi - fixed;
  103537. if(lo>=0)break;
  103538. tN = N[hi] + N[-lo];
  103539. tX = X[hi] - X[-lo];
  103540. tXX = XX[hi] + XX[-lo];
  103541. tY = Y[hi] + Y[-lo];
  103542. tXY = XY[hi] - XY[-lo];
  103543. A = tY * tXX - tX * tXY;
  103544. B = tN * tXY - tX * tY;
  103545. D = tN * tXX - tX * tX;
  103546. R = (A + x * B) / D;
  103547. if (R - offset < noise[i]) noise[i] = R - offset;
  103548. }
  103549. for ( ;; i++, x += 1.f) {
  103550. hi = i + fixed / 2;
  103551. lo = hi - fixed;
  103552. if(hi>=n)break;
  103553. tN = N[hi] - N[lo];
  103554. tX = X[hi] - X[lo];
  103555. tXX = XX[hi] - XX[lo];
  103556. tY = Y[hi] - Y[lo];
  103557. tXY = XY[hi] - XY[lo];
  103558. A = tY * tXX - tX * tXY;
  103559. B = tN * tXY - tX * tY;
  103560. D = tN * tXX - tX * tX;
  103561. R = (A + x * B) / D;
  103562. if (R - offset < noise[i]) noise[i] = R - offset;
  103563. }
  103564. for ( ; i < n; i++, x += 1.f) {
  103565. R = (A + x * B) / D;
  103566. if (R - offset < noise[i]) noise[i] = R - offset;
  103567. }
  103568. }
  103569. static float FLOOR1_fromdB_INV_LOOKUP[256]={
  103570. 0.F, 8.81683e+06F, 8.27882e+06F, 7.77365e+06F,
  103571. 7.29930e+06F, 6.85389e+06F, 6.43567e+06F, 6.04296e+06F,
  103572. 5.67422e+06F, 5.32798e+06F, 5.00286e+06F, 4.69759e+06F,
  103573. 4.41094e+06F, 4.14178e+06F, 3.88905e+06F, 3.65174e+06F,
  103574. 3.42891e+06F, 3.21968e+06F, 3.02321e+06F, 2.83873e+06F,
  103575. 2.66551e+06F, 2.50286e+06F, 2.35014e+06F, 2.20673e+06F,
  103576. 2.07208e+06F, 1.94564e+06F, 1.82692e+06F, 1.71544e+06F,
  103577. 1.61076e+06F, 1.51247e+06F, 1.42018e+06F, 1.33352e+06F,
  103578. 1.25215e+06F, 1.17574e+06F, 1.10400e+06F, 1.03663e+06F,
  103579. 973377.F, 913981.F, 858210.F, 805842.F,
  103580. 756669.F, 710497.F, 667142.F, 626433.F,
  103581. 588208.F, 552316.F, 518613.F, 486967.F,
  103582. 457252.F, 429351.F, 403152.F, 378551.F,
  103583. 355452.F, 333762.F, 313396.F, 294273.F,
  103584. 276316.F, 259455.F, 243623.F, 228757.F,
  103585. 214798.F, 201691.F, 189384.F, 177828.F,
  103586. 166977.F, 156788.F, 147221.F, 138237.F,
  103587. 129802.F, 121881.F, 114444.F, 107461.F,
  103588. 100903.F, 94746.3F, 88964.9F, 83536.2F,
  103589. 78438.8F, 73652.5F, 69158.2F, 64938.1F,
  103590. 60975.6F, 57254.9F, 53761.2F, 50480.6F,
  103591. 47400.3F, 44507.9F, 41792.0F, 39241.9F,
  103592. 36847.3F, 34598.9F, 32487.7F, 30505.3F,
  103593. 28643.8F, 26896.0F, 25254.8F, 23713.7F,
  103594. 22266.7F, 20908.0F, 19632.2F, 18434.2F,
  103595. 17309.4F, 16253.1F, 15261.4F, 14330.1F,
  103596. 13455.7F, 12634.6F, 11863.7F, 11139.7F,
  103597. 10460.0F, 9821.72F, 9222.39F, 8659.64F,
  103598. 8131.23F, 7635.06F, 7169.17F, 6731.70F,
  103599. 6320.93F, 5935.23F, 5573.06F, 5232.99F,
  103600. 4913.67F, 4613.84F, 4332.30F, 4067.94F,
  103601. 3819.72F, 3586.64F, 3367.78F, 3162.28F,
  103602. 2969.31F, 2788.13F, 2617.99F, 2458.24F,
  103603. 2308.24F, 2167.39F, 2035.14F, 1910.95F,
  103604. 1794.35F, 1684.85F, 1582.04F, 1485.51F,
  103605. 1394.86F, 1309.75F, 1229.83F, 1154.78F,
  103606. 1084.32F, 1018.15F, 956.024F, 897.687F,
  103607. 842.910F, 791.475F, 743.179F, 697.830F,
  103608. 655.249F, 615.265F, 577.722F, 542.469F,
  103609. 509.367F, 478.286F, 449.101F, 421.696F,
  103610. 395.964F, 371.803F, 349.115F, 327.812F,
  103611. 307.809F, 289.026F, 271.390F, 254.830F,
  103612. 239.280F, 224.679F, 210.969F, 198.096F,
  103613. 186.008F, 174.658F, 164.000F, 153.993F,
  103614. 144.596F, 135.773F, 127.488F, 119.708F,
  103615. 112.404F, 105.545F, 99.1046F, 93.0572F,
  103616. 87.3788F, 82.0469F, 77.0404F, 72.3394F,
  103617. 67.9252F, 63.7804F, 59.8885F, 56.2341F,
  103618. 52.8027F, 49.5807F, 46.5553F, 43.7144F,
  103619. 41.0470F, 38.5423F, 36.1904F, 33.9821F,
  103620. 31.9085F, 29.9614F, 28.1332F, 26.4165F,
  103621. 24.8045F, 23.2910F, 21.8697F, 20.5352F,
  103622. 19.2822F, 18.1056F, 17.0008F, 15.9634F,
  103623. 14.9893F, 14.0746F, 13.2158F, 12.4094F,
  103624. 11.6522F, 10.9411F, 10.2735F, 9.64662F,
  103625. 9.05798F, 8.50526F, 7.98626F, 7.49894F,
  103626. 7.04135F, 6.61169F, 6.20824F, 5.82941F,
  103627. 5.47370F, 5.13970F, 4.82607F, 4.53158F,
  103628. 4.25507F, 3.99542F, 3.75162F, 3.52269F,
  103629. 3.30774F, 3.10590F, 2.91638F, 2.73842F,
  103630. 2.57132F, 2.41442F, 2.26709F, 2.12875F,
  103631. 1.99885F, 1.87688F, 1.76236F, 1.65482F,
  103632. 1.55384F, 1.45902F, 1.36999F, 1.28640F,
  103633. 1.20790F, 1.13419F, 1.06499F, 1.F
  103634. };
  103635. void _vp_remove_floor(vorbis_look_psy *p,
  103636. float *mdct,
  103637. int *codedflr,
  103638. float *residue,
  103639. int sliding_lowpass){
  103640. int i,n=p->n;
  103641. if(sliding_lowpass>n)sliding_lowpass=n;
  103642. for(i=0;i<sliding_lowpass;i++){
  103643. residue[i]=
  103644. mdct[i]*FLOOR1_fromdB_INV_LOOKUP[codedflr[i]];
  103645. }
  103646. for(;i<n;i++)
  103647. residue[i]=0.;
  103648. }
  103649. void _vp_noisemask(vorbis_look_psy *p,
  103650. float *logmdct,
  103651. float *logmask){
  103652. int i,n=p->n;
  103653. float *work=(float*) alloca(n*sizeof(*work));
  103654. bark_noise_hybridmp(n,p->bark,logmdct,logmask,
  103655. 140.,-1);
  103656. for(i=0;i<n;i++)work[i]=logmdct[i]-logmask[i];
  103657. bark_noise_hybridmp(n,p->bark,work,logmask,0.,
  103658. p->vi->noisewindowfixed);
  103659. for(i=0;i<n;i++)work[i]=logmdct[i]-work[i];
  103660. #if 0
  103661. {
  103662. static int seq=0;
  103663. float work2[n];
  103664. for(i=0;i<n;i++){
  103665. work2[i]=logmask[i]+work[i];
  103666. }
  103667. if(seq&1)
  103668. _analysis_output("median2R",seq/2,work,n,1,0,0);
  103669. else
  103670. _analysis_output("median2L",seq/2,work,n,1,0,0);
  103671. if(seq&1)
  103672. _analysis_output("envelope2R",seq/2,work2,n,1,0,0);
  103673. else
  103674. _analysis_output("envelope2L",seq/2,work2,n,1,0,0);
  103675. seq++;
  103676. }
  103677. #endif
  103678. for(i=0;i<n;i++){
  103679. int dB=logmask[i]+.5;
  103680. if(dB>=NOISE_COMPAND_LEVELS)dB=NOISE_COMPAND_LEVELS-1;
  103681. if(dB<0)dB=0;
  103682. logmask[i]= work[i]+p->vi->noisecompand[dB];
  103683. }
  103684. }
  103685. void _vp_tonemask(vorbis_look_psy *p,
  103686. float *logfft,
  103687. float *logmask,
  103688. float global_specmax,
  103689. float local_specmax){
  103690. int i,n=p->n;
  103691. float *seed=(float*) alloca(sizeof(*seed)*p->total_octave_lines);
  103692. float att=local_specmax+p->vi->ath_adjatt;
  103693. for(i=0;i<p->total_octave_lines;i++)seed[i]=NEGINF;
  103694. if(att<p->vi->ath_maxatt)att=p->vi->ath_maxatt;
  103695. for(i=0;i<n;i++)
  103696. logmask[i]=p->ath[i]+att;
  103697. seed_loop(p,(const float ***)p->tonecurves,logfft,logmask,seed,global_specmax);
  103698. max_seeds(p,seed,logmask);
  103699. }
  103700. void _vp_offset_and_mix(vorbis_look_psy *p,
  103701. float *noise,
  103702. float *tone,
  103703. int offset_select,
  103704. float *logmask,
  103705. float *mdct,
  103706. float *logmdct){
  103707. int i,n=p->n;
  103708. float de, coeffi, cx;/* AoTuV */
  103709. float toneatt=p->vi->tone_masteratt[offset_select];
  103710. cx = p->m_val;
  103711. for(i=0;i<n;i++){
  103712. float val= noise[i]+p->noiseoffset[offset_select][i];
  103713. if(val>p->vi->noisemaxsupp)val=p->vi->noisemaxsupp;
  103714. logmask[i]=max(val,tone[i]+toneatt);
  103715. if(offset_select == 1) {
  103716. coeffi = -17.2; /* coeffi is a -17.2dB threshold */
  103717. val = val - logmdct[i]; /* val == mdct line value relative to floor in dB */
  103718. if(val > coeffi){
  103719. de = 1.0-((val-coeffi)*0.005*cx);
  103720. if(de < 0) de = 0.0001;
  103721. }else
  103722. de = 1.0-((val-coeffi)*0.0003*cx);
  103723. mdct[i] *= de;
  103724. }
  103725. }
  103726. }
  103727. float _vp_ampmax_decay(float amp,vorbis_dsp_state *vd){
  103728. vorbis_info *vi=vd->vi;
  103729. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  103730. vorbis_info_psy_global *gi=&ci->psy_g_param;
  103731. int n=ci->blocksizes[vd->W]/2;
  103732. float secs=(float)n/vi->rate;
  103733. amp+=secs*gi->ampmax_att_per_sec;
  103734. if(amp<-9999)amp=-9999;
  103735. return(amp);
  103736. }
  103737. static void couple_lossless(float A, float B,
  103738. float *qA, float *qB){
  103739. int test1=fabs(*qA)>fabs(*qB);
  103740. test1-= fabs(*qA)<fabs(*qB);
  103741. if(!test1)test1=((fabs(A)>fabs(B))<<1)-1;
  103742. if(test1==1){
  103743. *qB=(*qA>0.f?*qA-*qB:*qB-*qA);
  103744. }else{
  103745. float temp=*qB;
  103746. *qB=(*qB>0.f?*qA-*qB:*qB-*qA);
  103747. *qA=temp;
  103748. }
  103749. if(*qB>fabs(*qA)*1.9999f){
  103750. *qB= -fabs(*qA)*2.f;
  103751. *qA= -*qA;
  103752. }
  103753. }
  103754. static float hypot_lookup[32]={
  103755. -0.009935, -0.011245, -0.012726, -0.014397,
  103756. -0.016282, -0.018407, -0.020800, -0.023494,
  103757. -0.026522, -0.029923, -0.033737, -0.038010,
  103758. -0.042787, -0.048121, -0.054064, -0.060671,
  103759. -0.068000, -0.076109, -0.085054, -0.094892,
  103760. -0.105675, -0.117451, -0.130260, -0.144134,
  103761. -0.159093, -0.175146, -0.192286, -0.210490,
  103762. -0.229718, -0.249913, -0.271001, -0.292893};
  103763. static void precomputed_couple_point(float premag,
  103764. int floorA,int floorB,
  103765. float *mag, float *ang){
  103766. int test=(floorA>floorB)-1;
  103767. int offset=31-abs(floorA-floorB);
  103768. float floormag=hypot_lookup[((offset<0)-1)&offset]+1.f;
  103769. floormag*=FLOOR1_fromdB_INV_LOOKUP[(floorB&test)|(floorA&(~test))];
  103770. *mag=premag*floormag;
  103771. *ang=0.f;
  103772. }
  103773. static float dipole_hypot(float a, float b){
  103774. if(a>0.){
  103775. if(b>0.)return sqrt(a*a+b*b);
  103776. if(a>-b)return sqrt(a*a-b*b);
  103777. return -sqrt(b*b-a*a);
  103778. }
  103779. if(b<0.)return -sqrt(a*a+b*b);
  103780. if(-a>b)return -sqrt(a*a-b*b);
  103781. return sqrt(b*b-a*a);
  103782. }
  103783. static float round_hypot(float a, float b){
  103784. if(a>0.){
  103785. if(b>0.)return sqrt(a*a+b*b);
  103786. if(a>-b)return sqrt(a*a+b*b);
  103787. return -sqrt(b*b+a*a);
  103788. }
  103789. if(b<0.)return -sqrt(a*a+b*b);
  103790. if(-a>b)return -sqrt(a*a+b*b);
  103791. return sqrt(b*b+a*a);
  103792. }
  103793. float **_vp_quantize_couple_memo(vorbis_block *vb,
  103794. vorbis_info_psy_global *g,
  103795. vorbis_look_psy *p,
  103796. vorbis_info_mapping0 *vi,
  103797. float **mdct){
  103798. int i,j,n=p->n;
  103799. float **ret=(float**) _vorbis_block_alloc(vb,vi->coupling_steps*sizeof(*ret));
  103800. int limit=g->coupling_pointlimit[p->vi->blockflag][PACKETBLOBS/2];
  103801. for(i=0;i<vi->coupling_steps;i++){
  103802. float *mdctM=mdct[vi->coupling_mag[i]];
  103803. float *mdctA=mdct[vi->coupling_ang[i]];
  103804. ret[i]=(float*) _vorbis_block_alloc(vb,n*sizeof(**ret));
  103805. for(j=0;j<limit;j++)
  103806. ret[i][j]=dipole_hypot(mdctM[j],mdctA[j]);
  103807. for(;j<n;j++)
  103808. ret[i][j]=round_hypot(mdctM[j],mdctA[j]);
  103809. }
  103810. return(ret);
  103811. }
  103812. static int apsort(const void *a, const void *b){
  103813. float f1=fabs(**(float**)a);
  103814. float f2=fabs(**(float**)b);
  103815. return (f1<f2)-(f1>f2);
  103816. }
  103817. int **_vp_quantize_couple_sort(vorbis_block *vb,
  103818. vorbis_look_psy *p,
  103819. vorbis_info_mapping0 *vi,
  103820. float **mags){
  103821. if(p->vi->normal_point_p){
  103822. int i,j,k,n=p->n;
  103823. int **ret=(int**) _vorbis_block_alloc(vb,vi->coupling_steps*sizeof(*ret));
  103824. int partition=p->vi->normal_partition;
  103825. float **work=(float**) alloca(sizeof(*work)*partition);
  103826. for(i=0;i<vi->coupling_steps;i++){
  103827. ret[i]=(int*) _vorbis_block_alloc(vb,n*sizeof(**ret));
  103828. for(j=0;j<n;j+=partition){
  103829. for(k=0;k<partition;k++)work[k]=mags[i]+k+j;
  103830. qsort(work,partition,sizeof(*work),apsort);
  103831. for(k=0;k<partition;k++)ret[i][k+j]=work[k]-mags[i];
  103832. }
  103833. }
  103834. return(ret);
  103835. }
  103836. return(NULL);
  103837. }
  103838. void _vp_noise_normalize_sort(vorbis_look_psy *p,
  103839. float *magnitudes,int *sortedindex){
  103840. int i,j,n=p->n;
  103841. vorbis_info_psy *vi=p->vi;
  103842. int partition=vi->normal_partition;
  103843. float **work=(float**) alloca(sizeof(*work)*partition);
  103844. int start=vi->normal_start;
  103845. for(j=start;j<n;j+=partition){
  103846. if(j+partition>n)partition=n-j;
  103847. for(i=0;i<partition;i++)work[i]=magnitudes+i+j;
  103848. qsort(work,partition,sizeof(*work),apsort);
  103849. for(i=0;i<partition;i++){
  103850. sortedindex[i+j-start]=work[i]-magnitudes;
  103851. }
  103852. }
  103853. }
  103854. void _vp_noise_normalize(vorbis_look_psy *p,
  103855. float *in,float *out,int *sortedindex){
  103856. int flag=0,i,j=0,n=p->n;
  103857. vorbis_info_psy *vi=p->vi;
  103858. int partition=vi->normal_partition;
  103859. int start=vi->normal_start;
  103860. if(start>n)start=n;
  103861. if(vi->normal_channel_p){
  103862. for(;j<start;j++)
  103863. out[j]=rint(in[j]);
  103864. for(;j+partition<=n;j+=partition){
  103865. float acc=0.;
  103866. int k;
  103867. for(i=j;i<j+partition;i++)
  103868. acc+=in[i]*in[i];
  103869. for(i=0;i<partition;i++){
  103870. k=sortedindex[i+j-start];
  103871. if(in[k]*in[k]>=.25f){
  103872. out[k]=rint(in[k]);
  103873. acc-=in[k]*in[k];
  103874. flag=1;
  103875. }else{
  103876. if(acc<vi->normal_thresh)break;
  103877. out[k]=unitnorm(in[k]);
  103878. acc-=1.;
  103879. }
  103880. }
  103881. for(;i<partition;i++){
  103882. k=sortedindex[i+j-start];
  103883. out[k]=0.;
  103884. }
  103885. }
  103886. }
  103887. for(;j<n;j++)
  103888. out[j]=rint(in[j]);
  103889. }
  103890. void _vp_couple(int blobno,
  103891. vorbis_info_psy_global *g,
  103892. vorbis_look_psy *p,
  103893. vorbis_info_mapping0 *vi,
  103894. float **res,
  103895. float **mag_memo,
  103896. int **mag_sort,
  103897. int **ifloor,
  103898. int *nonzero,
  103899. int sliding_lowpass){
  103900. int i,j,k,n=p->n;
  103901. for(i=0;i<vi->coupling_steps;i++){
  103902. if(nonzero[vi->coupling_mag[i]] ||
  103903. nonzero[vi->coupling_ang[i]]){
  103904. float *rM=res[vi->coupling_mag[i]];
  103905. float *rA=res[vi->coupling_ang[i]];
  103906. float *qM=rM+n;
  103907. float *qA=rA+n;
  103908. int *floorM=ifloor[vi->coupling_mag[i]];
  103909. int *floorA=ifloor[vi->coupling_ang[i]];
  103910. float prepoint=stereo_threshholds[g->coupling_prepointamp[blobno]];
  103911. float postpoint=stereo_threshholds[g->coupling_postpointamp[blobno]];
  103912. int partition=(p->vi->normal_point_p?p->vi->normal_partition:p->n);
  103913. int limit=g->coupling_pointlimit[p->vi->blockflag][blobno];
  103914. int pointlimit=limit;
  103915. nonzero[vi->coupling_mag[i]]=1;
  103916. nonzero[vi->coupling_ang[i]]=1;
  103917. if(n > 1000)
  103918. postpoint=stereo_threshholds_limited[g->coupling_postpointamp[blobno]];
  103919. for(j=0;j<p->n;j+=partition){
  103920. float acc=0.f;
  103921. for(k=0;k<partition;k++){
  103922. int l=k+j;
  103923. if(l<sliding_lowpass){
  103924. if((l>=limit && fabs(rM[l])<postpoint && fabs(rA[l])<postpoint) ||
  103925. (fabs(rM[l])<prepoint && fabs(rA[l])<prepoint)){
  103926. precomputed_couple_point(mag_memo[i][l],
  103927. floorM[l],floorA[l],
  103928. qM+l,qA+l);
  103929. if(rint(qM[l])==0.f)acc+=qM[l]*qM[l];
  103930. }else{
  103931. couple_lossless(rM[l],rA[l],qM+l,qA+l);
  103932. }
  103933. }else{
  103934. qM[l]=0.;
  103935. qA[l]=0.;
  103936. }
  103937. }
  103938. if(p->vi->normal_point_p){
  103939. for(k=0;k<partition && acc>=p->vi->normal_thresh;k++){
  103940. int l=mag_sort[i][j+k];
  103941. if(l<sliding_lowpass && l>=pointlimit && rint(qM[l])==0.f){
  103942. qM[l]=unitnorm(qM[l]);
  103943. acc-=1.f;
  103944. }
  103945. }
  103946. }
  103947. }
  103948. }
  103949. }
  103950. }
  103951. void hf_reduction(vorbis_info_psy_global *g,
  103952. vorbis_look_psy *p,
  103953. vorbis_info_mapping0 *vi,
  103954. float **mdct){
  103955. int i,j,n=p->n, de=0.3*p->m_val;
  103956. int limit=g->coupling_pointlimit[p->vi->blockflag][PACKETBLOBS/2];
  103957. for(i=0; i<vi->coupling_steps; i++){
  103958. for(j=limit; j<n; j++)
  103959. mdct[i][j] *= (1.0 - de*((float)(j-limit) / (float)(n-limit)));
  103960. }
  103961. }
  103962. #endif
  103963. /*** End of inlined file: psy.c ***/
  103964. /*** Start of inlined file: registry.c ***/
  103965. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  103966. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  103967. // tasks..
  103968. #if JUCE_MSVC
  103969. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  103970. #endif
  103971. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  103972. #if JUCE_USE_OGGVORBIS
  103973. extern vorbis_func_floor floor0_exportbundle;
  103974. extern vorbis_func_floor floor1_exportbundle;
  103975. extern vorbis_func_residue residue0_exportbundle;
  103976. extern vorbis_func_residue residue1_exportbundle;
  103977. extern vorbis_func_residue residue2_exportbundle;
  103978. extern vorbis_func_mapping mapping0_exportbundle;
  103979. vorbis_func_floor *_floor_P[]={
  103980. &floor0_exportbundle,
  103981. &floor1_exportbundle,
  103982. };
  103983. vorbis_func_residue *_residue_P[]={
  103984. &residue0_exportbundle,
  103985. &residue1_exportbundle,
  103986. &residue2_exportbundle,
  103987. };
  103988. vorbis_func_mapping *_mapping_P[]={
  103989. &mapping0_exportbundle,
  103990. };
  103991. #endif
  103992. /*** End of inlined file: registry.c ***/
  103993. /*** Start of inlined file: res0.c ***/
  103994. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  103995. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  103996. // tasks..
  103997. #if JUCE_MSVC
  103998. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  103999. #endif
  104000. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  104001. #if JUCE_USE_OGGVORBIS
  104002. #include <stdlib.h>
  104003. #include <string.h>
  104004. #include <math.h>
  104005. #if defined(TRAIN_RES) || defined (TRAIN_RESAUX)
  104006. #include <stdio.h>
  104007. #endif
  104008. typedef struct {
  104009. vorbis_info_residue0 *info;
  104010. int parts;
  104011. int stages;
  104012. codebook *fullbooks;
  104013. codebook *phrasebook;
  104014. codebook ***partbooks;
  104015. int partvals;
  104016. int **decodemap;
  104017. long postbits;
  104018. long phrasebits;
  104019. long frames;
  104020. #if defined(TRAIN_RES) || defined(TRAIN_RESAUX)
  104021. int train_seq;
  104022. long *training_data[8][64];
  104023. float training_max[8][64];
  104024. float training_min[8][64];
  104025. float tmin;
  104026. float tmax;
  104027. #endif
  104028. } vorbis_look_residue0;
  104029. void res0_free_info(vorbis_info_residue *i){
  104030. vorbis_info_residue0 *info=(vorbis_info_residue0 *)i;
  104031. if(info){
  104032. memset(info,0,sizeof(*info));
  104033. _ogg_free(info);
  104034. }
  104035. }
  104036. void res0_free_look(vorbis_look_residue *i){
  104037. int j;
  104038. if(i){
  104039. vorbis_look_residue0 *look=(vorbis_look_residue0 *)i;
  104040. #ifdef TRAIN_RES
  104041. {
  104042. int j,k,l;
  104043. for(j=0;j<look->parts;j++){
  104044. for(k=0;k<8;k++)
  104045. if(look->training_data[k][j]){
  104046. char buffer[80];
  104047. FILE *of;
  104048. codebook *statebook=look->partbooks[j][k];
  104049. sprintf(buffer,"res_part%d_pass%d.vqd",j,k);
  104050. of=fopen(buffer,"a");
  104051. for(l=0;l<statebook->entries;l++)
  104052. fprintf(of,"%d:%ld\n",l,look->training_data[k][j][l]);
  104053. fclose(of);
  104054. _ogg_free(look->training_data[k][j]);
  104055. look->training_data[k][j]=NULL;
  104056. }
  104057. }
  104058. }
  104059. fprintf(stderr,"min/max residue: %g::%g\n",look->tmin,look->tmax);
  104060. #endif
  104061. for(j=0;j<look->parts;j++)
  104062. if(look->partbooks[j])_ogg_free(look->partbooks[j]);
  104063. _ogg_free(look->partbooks);
  104064. for(j=0;j<look->partvals;j++)
  104065. _ogg_free(look->decodemap[j]);
  104066. _ogg_free(look->decodemap);
  104067. memset(look,0,sizeof(*look));
  104068. _ogg_free(look);
  104069. }
  104070. }
  104071. static int icount(unsigned int v){
  104072. int ret=0;
  104073. while(v){
  104074. ret+=v&1;
  104075. v>>=1;
  104076. }
  104077. return(ret);
  104078. }
  104079. void res0_pack(vorbis_info_residue *vr,oggpack_buffer *opb){
  104080. vorbis_info_residue0 *info=(vorbis_info_residue0 *)vr;
  104081. int j,acc=0;
  104082. oggpack_write(opb,info->begin,24);
  104083. oggpack_write(opb,info->end,24);
  104084. oggpack_write(opb,info->grouping-1,24); /* residue vectors to group and
  104085. code with a partitioned book */
  104086. oggpack_write(opb,info->partitions-1,6); /* possible partition choices */
  104087. oggpack_write(opb,info->groupbook,8); /* group huffman book */
  104088. for(j=0;j<info->partitions;j++){
  104089. if(ilog(info->secondstages[j])>3){
  104090. oggpack_write(opb,info->secondstages[j],3);
  104091. oggpack_write(opb,1,1);
  104092. oggpack_write(opb,info->secondstages[j]>>3,5);
  104093. }else
  104094. oggpack_write(opb,info->secondstages[j],4); /* trailing zero */
  104095. acc+=icount(info->secondstages[j]);
  104096. }
  104097. for(j=0;j<acc;j++)
  104098. oggpack_write(opb,info->booklist[j],8);
  104099. }
  104100. vorbis_info_residue *res0_unpack(vorbis_info *vi,oggpack_buffer *opb){
  104101. int j,acc=0;
  104102. vorbis_info_residue0 *info=(vorbis_info_residue0*) _ogg_calloc(1,sizeof(*info));
  104103. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  104104. info->begin=oggpack_read(opb,24);
  104105. info->end=oggpack_read(opb,24);
  104106. info->grouping=oggpack_read(opb,24)+1;
  104107. info->partitions=oggpack_read(opb,6)+1;
  104108. info->groupbook=oggpack_read(opb,8);
  104109. for(j=0;j<info->partitions;j++){
  104110. int cascade=oggpack_read(opb,3);
  104111. if(oggpack_read(opb,1))
  104112. cascade|=(oggpack_read(opb,5)<<3);
  104113. info->secondstages[j]=cascade;
  104114. acc+=icount(cascade);
  104115. }
  104116. for(j=0;j<acc;j++)
  104117. info->booklist[j]=oggpack_read(opb,8);
  104118. if(info->groupbook>=ci->books)goto errout;
  104119. for(j=0;j<acc;j++)
  104120. if(info->booklist[j]>=ci->books)goto errout;
  104121. return(info);
  104122. errout:
  104123. res0_free_info(info);
  104124. return(NULL);
  104125. }
  104126. vorbis_look_residue *res0_look(vorbis_dsp_state *vd,
  104127. vorbis_info_residue *vr){
  104128. vorbis_info_residue0 *info=(vorbis_info_residue0 *)vr;
  104129. vorbis_look_residue0 *look=(vorbis_look_residue0 *)_ogg_calloc(1,sizeof(*look));
  104130. codec_setup_info *ci=(codec_setup_info*)vd->vi->codec_setup;
  104131. int j,k,acc=0;
  104132. int dim;
  104133. int maxstage=0;
  104134. look->info=info;
  104135. look->parts=info->partitions;
  104136. look->fullbooks=ci->fullbooks;
  104137. look->phrasebook=ci->fullbooks+info->groupbook;
  104138. dim=look->phrasebook->dim;
  104139. look->partbooks=(codebook***)_ogg_calloc(look->parts,sizeof(*look->partbooks));
  104140. for(j=0;j<look->parts;j++){
  104141. int stages=ilog(info->secondstages[j]);
  104142. if(stages){
  104143. if(stages>maxstage)maxstage=stages;
  104144. look->partbooks[j]=(codebook**) _ogg_calloc(stages,sizeof(*look->partbooks[j]));
  104145. for(k=0;k<stages;k++)
  104146. if(info->secondstages[j]&(1<<k)){
  104147. look->partbooks[j][k]=ci->fullbooks+info->booklist[acc++];
  104148. #ifdef TRAIN_RES
  104149. look->training_data[k][j]=_ogg_calloc(look->partbooks[j][k]->entries,
  104150. sizeof(***look->training_data));
  104151. #endif
  104152. }
  104153. }
  104154. }
  104155. look->partvals=rint(pow((float)look->parts,(float)dim));
  104156. look->stages=maxstage;
  104157. look->decodemap=(int**)_ogg_malloc(look->partvals*sizeof(*look->decodemap));
  104158. for(j=0;j<look->partvals;j++){
  104159. long val=j;
  104160. long mult=look->partvals/look->parts;
  104161. look->decodemap[j]=(int*)_ogg_malloc(dim*sizeof(*look->decodemap[j]));
  104162. for(k=0;k<dim;k++){
  104163. long deco=val/mult;
  104164. val-=deco*mult;
  104165. mult/=look->parts;
  104166. look->decodemap[j][k]=deco;
  104167. }
  104168. }
  104169. #if defined(TRAIN_RES) || defined (TRAIN_RESAUX)
  104170. {
  104171. static int train_seq=0;
  104172. look->train_seq=train_seq++;
  104173. }
  104174. #endif
  104175. return(look);
  104176. }
  104177. static int local_book_besterror(codebook *book,float *a){
  104178. int dim=book->dim,i,k,o;
  104179. int best=0;
  104180. encode_aux_threshmatch *tt=book->c->thresh_tree;
  104181. for(k=0,o=dim;k<dim;++k){
  104182. float val=a[--o];
  104183. i=tt->threshvals>>1;
  104184. if(val<tt->quantthresh[i]){
  104185. if(val<tt->quantthresh[i-1]){
  104186. for(--i;i>0;--i)
  104187. if(val>=tt->quantthresh[i-1])
  104188. break;
  104189. }
  104190. }else{
  104191. for(++i;i<tt->threshvals-1;++i)
  104192. if(val<tt->quantthresh[i])break;
  104193. }
  104194. best=(best*tt->quantvals)+tt->quantmap[i];
  104195. }
  104196. if(book->c->lengthlist[best]<=0){
  104197. const static_codebook *c=book->c;
  104198. int i,j;
  104199. float bestf=0.f;
  104200. float *e=book->valuelist;
  104201. best=-1;
  104202. for(i=0;i<book->entries;i++){
  104203. if(c->lengthlist[i]>0){
  104204. float thisx=0.f;
  104205. for(j=0;j<dim;j++){
  104206. float val=(e[j]-a[j]);
  104207. thisx+=val*val;
  104208. }
  104209. if(best==-1 || thisx<bestf){
  104210. bestf=thisx;
  104211. best=i;
  104212. }
  104213. }
  104214. e+=dim;
  104215. }
  104216. }
  104217. {
  104218. float *ptr=book->valuelist+best*dim;
  104219. for(i=0;i<dim;i++)
  104220. *a++ -= *ptr++;
  104221. }
  104222. return(best);
  104223. }
  104224. static int _encodepart(oggpack_buffer *opb,float *vec, int n,
  104225. codebook *book,long *acc){
  104226. int i,bits=0;
  104227. int dim=book->dim;
  104228. int step=n/dim;
  104229. for(i=0;i<step;i++){
  104230. int entry=local_book_besterror(book,vec+i*dim);
  104231. #ifdef TRAIN_RES
  104232. acc[entry]++;
  104233. #endif
  104234. bits+=vorbis_book_encode(book,entry,opb);
  104235. }
  104236. return(bits);
  104237. }
  104238. static long **_01class(vorbis_block *vb,vorbis_look_residue *vl,
  104239. float **in,int ch){
  104240. long i,j,k;
  104241. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104242. vorbis_info_residue0 *info=look->info;
  104243. int samples_per_partition=info->grouping;
  104244. int possible_partitions=info->partitions;
  104245. int n=info->end-info->begin;
  104246. int partvals=n/samples_per_partition;
  104247. long **partword=(long**)_vorbis_block_alloc(vb,ch*sizeof(*partword));
  104248. float scale=100./samples_per_partition;
  104249. for(i=0;i<ch;i++){
  104250. partword[i]=(long*)_vorbis_block_alloc(vb,n/samples_per_partition*sizeof(*partword[i]));
  104251. memset(partword[i],0,n/samples_per_partition*sizeof(*partword[i]));
  104252. }
  104253. for(i=0;i<partvals;i++){
  104254. int offset=i*samples_per_partition+info->begin;
  104255. for(j=0;j<ch;j++){
  104256. float max=0.;
  104257. float ent=0.;
  104258. for(k=0;k<samples_per_partition;k++){
  104259. if(fabs(in[j][offset+k])>max)max=fabs(in[j][offset+k]);
  104260. ent+=fabs(rint(in[j][offset+k]));
  104261. }
  104262. ent*=scale;
  104263. for(k=0;k<possible_partitions-1;k++)
  104264. if(max<=info->classmetric1[k] &&
  104265. (info->classmetric2[k]<0 || (int)ent<info->classmetric2[k]))
  104266. break;
  104267. partword[j][i]=k;
  104268. }
  104269. }
  104270. #ifdef TRAIN_RESAUX
  104271. {
  104272. FILE *of;
  104273. char buffer[80];
  104274. for(i=0;i<ch;i++){
  104275. sprintf(buffer,"resaux_%d.vqd",look->train_seq);
  104276. of=fopen(buffer,"a");
  104277. for(j=0;j<partvals;j++)
  104278. fprintf(of,"%ld, ",partword[i][j]);
  104279. fprintf(of,"\n");
  104280. fclose(of);
  104281. }
  104282. }
  104283. #endif
  104284. look->frames++;
  104285. return(partword);
  104286. }
  104287. static long **_2class(vorbis_block *vb,vorbis_look_residue *vl,float **in,
  104288. int ch){
  104289. long i,j,k,l;
  104290. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104291. vorbis_info_residue0 *info=look->info;
  104292. int samples_per_partition=info->grouping;
  104293. int possible_partitions=info->partitions;
  104294. int n=info->end-info->begin;
  104295. int partvals=n/samples_per_partition;
  104296. long **partword=(long**)_vorbis_block_alloc(vb,sizeof(*partword));
  104297. #if defined(TRAIN_RES) || defined (TRAIN_RESAUX)
  104298. FILE *of;
  104299. char buffer[80];
  104300. #endif
  104301. partword[0]=(long*)_vorbis_block_alloc(vb,n*ch/samples_per_partition*sizeof(*partword[0]));
  104302. memset(partword[0],0,n*ch/samples_per_partition*sizeof(*partword[0]));
  104303. for(i=0,l=info->begin/ch;i<partvals;i++){
  104304. float magmax=0.f;
  104305. float angmax=0.f;
  104306. for(j=0;j<samples_per_partition;j+=ch){
  104307. if(fabs(in[0][l])>magmax)magmax=fabs(in[0][l]);
  104308. for(k=1;k<ch;k++)
  104309. if(fabs(in[k][l])>angmax)angmax=fabs(in[k][l]);
  104310. l++;
  104311. }
  104312. for(j=0;j<possible_partitions-1;j++)
  104313. if(magmax<=info->classmetric1[j] &&
  104314. angmax<=info->classmetric2[j])
  104315. break;
  104316. partword[0][i]=j;
  104317. }
  104318. #ifdef TRAIN_RESAUX
  104319. sprintf(buffer,"resaux_%d.vqd",look->train_seq);
  104320. of=fopen(buffer,"a");
  104321. for(i=0;i<partvals;i++)
  104322. fprintf(of,"%ld, ",partword[0][i]);
  104323. fprintf(of,"\n");
  104324. fclose(of);
  104325. #endif
  104326. look->frames++;
  104327. return(partword);
  104328. }
  104329. static int _01forward(oggpack_buffer *opb,
  104330. vorbis_block *vb,vorbis_look_residue *vl,
  104331. float **in,int ch,
  104332. long **partword,
  104333. int (*encode)(oggpack_buffer *,float *,int,
  104334. codebook *,long *)){
  104335. long i,j,k,s;
  104336. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104337. vorbis_info_residue0 *info=look->info;
  104338. int samples_per_partition=info->grouping;
  104339. int possible_partitions=info->partitions;
  104340. int partitions_per_word=look->phrasebook->dim;
  104341. int n=info->end-info->begin;
  104342. int partvals=n/samples_per_partition;
  104343. long resbits[128];
  104344. long resvals[128];
  104345. #ifdef TRAIN_RES
  104346. for(i=0;i<ch;i++)
  104347. for(j=info->begin;j<info->end;j++){
  104348. if(in[i][j]>look->tmax)look->tmax=in[i][j];
  104349. if(in[i][j]<look->tmin)look->tmin=in[i][j];
  104350. }
  104351. #endif
  104352. memset(resbits,0,sizeof(resbits));
  104353. memset(resvals,0,sizeof(resvals));
  104354. for(s=0;s<look->stages;s++){
  104355. for(i=0;i<partvals;){
  104356. if(s==0){
  104357. for(j=0;j<ch;j++){
  104358. long val=partword[j][i];
  104359. for(k=1;k<partitions_per_word;k++){
  104360. val*=possible_partitions;
  104361. if(i+k<partvals)
  104362. val+=partword[j][i+k];
  104363. }
  104364. if(val<look->phrasebook->entries)
  104365. look->phrasebits+=vorbis_book_encode(look->phrasebook,val,opb);
  104366. #if 0 /*def TRAIN_RES*/
  104367. else
  104368. fprintf(stderr,"!");
  104369. #endif
  104370. }
  104371. }
  104372. for(k=0;k<partitions_per_word && i<partvals;k++,i++){
  104373. long offset=i*samples_per_partition+info->begin;
  104374. for(j=0;j<ch;j++){
  104375. if(s==0)resvals[partword[j][i]]+=samples_per_partition;
  104376. if(info->secondstages[partword[j][i]]&(1<<s)){
  104377. codebook *statebook=look->partbooks[partword[j][i]][s];
  104378. if(statebook){
  104379. int ret;
  104380. long *accumulator=NULL;
  104381. #ifdef TRAIN_RES
  104382. accumulator=look->training_data[s][partword[j][i]];
  104383. {
  104384. int l;
  104385. float *samples=in[j]+offset;
  104386. for(l=0;l<samples_per_partition;l++){
  104387. if(samples[l]<look->training_min[s][partword[j][i]])
  104388. look->training_min[s][partword[j][i]]=samples[l];
  104389. if(samples[l]>look->training_max[s][partword[j][i]])
  104390. look->training_max[s][partword[j][i]]=samples[l];
  104391. }
  104392. }
  104393. #endif
  104394. ret=encode(opb,in[j]+offset,samples_per_partition,
  104395. statebook,accumulator);
  104396. look->postbits+=ret;
  104397. resbits[partword[j][i]]+=ret;
  104398. }
  104399. }
  104400. }
  104401. }
  104402. }
  104403. }
  104404. return(0);
  104405. }
  104406. static int _01inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104407. float **in,int ch,
  104408. long (*decodepart)(codebook *, float *,
  104409. oggpack_buffer *,int)){
  104410. long i,j,k,l,s;
  104411. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104412. vorbis_info_residue0 *info=look->info;
  104413. int samples_per_partition=info->grouping;
  104414. int partitions_per_word=look->phrasebook->dim;
  104415. int n=info->end-info->begin;
  104416. int partvals=n/samples_per_partition;
  104417. int partwords=(partvals+partitions_per_word-1)/partitions_per_word;
  104418. int ***partword=(int***)alloca(ch*sizeof(*partword));
  104419. for(j=0;j<ch;j++)
  104420. partword[j]=(int**)_vorbis_block_alloc(vb,partwords*sizeof(*partword[j]));
  104421. for(s=0;s<look->stages;s++){
  104422. for(i=0,l=0;i<partvals;l++){
  104423. if(s==0){
  104424. for(j=0;j<ch;j++){
  104425. int temp=vorbis_book_decode(look->phrasebook,&vb->opb);
  104426. if(temp==-1)goto eopbreak;
  104427. partword[j][l]=look->decodemap[temp];
  104428. if(partword[j][l]==NULL)goto errout;
  104429. }
  104430. }
  104431. for(k=0;k<partitions_per_word && i<partvals;k++,i++)
  104432. for(j=0;j<ch;j++){
  104433. long offset=info->begin+i*samples_per_partition;
  104434. if(info->secondstages[partword[j][l][k]]&(1<<s)){
  104435. codebook *stagebook=look->partbooks[partword[j][l][k]][s];
  104436. if(stagebook){
  104437. if(decodepart(stagebook,in[j]+offset,&vb->opb,
  104438. samples_per_partition)==-1)goto eopbreak;
  104439. }
  104440. }
  104441. }
  104442. }
  104443. }
  104444. errout:
  104445. eopbreak:
  104446. return(0);
  104447. }
  104448. #if 0
  104449. long **res0_class(vorbis_block *vb,vorbis_look_residue *vl,
  104450. float **in,int *nonzero,int ch){
  104451. int i,used=0;
  104452. for(i=0;i<ch;i++)
  104453. if(nonzero[i])
  104454. in[used++]=in[i];
  104455. if(used)
  104456. return(_01class(vb,vl,in,used));
  104457. else
  104458. return(0);
  104459. }
  104460. int res0_forward(vorbis_block *vb,vorbis_look_residue *vl,
  104461. float **in,float **out,int *nonzero,int ch,
  104462. long **partword){
  104463. int i,j,used=0,n=vb->pcmend/2;
  104464. for(i=0;i<ch;i++)
  104465. if(nonzero[i]){
  104466. if(out)
  104467. for(j=0;j<n;j++)
  104468. out[i][j]+=in[i][j];
  104469. in[used++]=in[i];
  104470. }
  104471. if(used){
  104472. int ret=_01forward(vb,vl,in,used,partword,
  104473. _interleaved_encodepart);
  104474. if(out){
  104475. used=0;
  104476. for(i=0;i<ch;i++)
  104477. if(nonzero[i]){
  104478. for(j=0;j<n;j++)
  104479. out[i][j]-=in[used][j];
  104480. used++;
  104481. }
  104482. }
  104483. return(ret);
  104484. }else{
  104485. return(0);
  104486. }
  104487. }
  104488. #endif
  104489. int res0_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104490. float **in,int *nonzero,int ch){
  104491. int i,used=0;
  104492. for(i=0;i<ch;i++)
  104493. if(nonzero[i])
  104494. in[used++]=in[i];
  104495. if(used)
  104496. return(_01inverse(vb,vl,in,used,vorbis_book_decodevs_add));
  104497. else
  104498. return(0);
  104499. }
  104500. int res1_forward(oggpack_buffer *opb,vorbis_block *vb,vorbis_look_residue *vl,
  104501. float **in,float **out,int *nonzero,int ch,
  104502. long **partword){
  104503. int i,j,used=0,n=vb->pcmend/2;
  104504. for(i=0;i<ch;i++)
  104505. if(nonzero[i]){
  104506. if(out)
  104507. for(j=0;j<n;j++)
  104508. out[i][j]+=in[i][j];
  104509. in[used++]=in[i];
  104510. }
  104511. if(used){
  104512. int ret=_01forward(opb,vb,vl,in,used,partword,_encodepart);
  104513. if(out){
  104514. used=0;
  104515. for(i=0;i<ch;i++)
  104516. if(nonzero[i]){
  104517. for(j=0;j<n;j++)
  104518. out[i][j]-=in[used][j];
  104519. used++;
  104520. }
  104521. }
  104522. return(ret);
  104523. }else{
  104524. return(0);
  104525. }
  104526. }
  104527. long **res1_class(vorbis_block *vb,vorbis_look_residue *vl,
  104528. float **in,int *nonzero,int ch){
  104529. int i,used=0;
  104530. for(i=0;i<ch;i++)
  104531. if(nonzero[i])
  104532. in[used++]=in[i];
  104533. if(used)
  104534. return(_01class(vb,vl,in,used));
  104535. else
  104536. return(0);
  104537. }
  104538. int res1_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104539. float **in,int *nonzero,int ch){
  104540. int i,used=0;
  104541. for(i=0;i<ch;i++)
  104542. if(nonzero[i])
  104543. in[used++]=in[i];
  104544. if(used)
  104545. return(_01inverse(vb,vl,in,used,vorbis_book_decodev_add));
  104546. else
  104547. return(0);
  104548. }
  104549. long **res2_class(vorbis_block *vb,vorbis_look_residue *vl,
  104550. float **in,int *nonzero,int ch){
  104551. int i,used=0;
  104552. for(i=0;i<ch;i++)
  104553. if(nonzero[i])used++;
  104554. if(used)
  104555. return(_2class(vb,vl,in,ch));
  104556. else
  104557. return(0);
  104558. }
  104559. int res2_forward(oggpack_buffer *opb,
  104560. vorbis_block *vb,vorbis_look_residue *vl,
  104561. float **in,float **out,int *nonzero,int ch,
  104562. long **partword){
  104563. long i,j,k,n=vb->pcmend/2,used=0;
  104564. float *work=(float*)_vorbis_block_alloc(vb,ch*n*sizeof(*work));
  104565. for(i=0;i<ch;i++){
  104566. float *pcm=in[i];
  104567. if(nonzero[i])used++;
  104568. for(j=0,k=i;j<n;j++,k+=ch)
  104569. work[k]=pcm[j];
  104570. }
  104571. if(used){
  104572. int ret=_01forward(opb,vb,vl,&work,1,partword,_encodepart);
  104573. if(out){
  104574. for(i=0;i<ch;i++){
  104575. float *pcm=in[i];
  104576. float *sofar=out[i];
  104577. for(j=0,k=i;j<n;j++,k+=ch)
  104578. sofar[j]+=pcm[j]-work[k];
  104579. }
  104580. }
  104581. return(ret);
  104582. }else{
  104583. return(0);
  104584. }
  104585. }
  104586. int res2_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104587. float **in,int *nonzero,int ch){
  104588. long i,k,l,s;
  104589. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104590. vorbis_info_residue0 *info=look->info;
  104591. int samples_per_partition=info->grouping;
  104592. int partitions_per_word=look->phrasebook->dim;
  104593. int n=info->end-info->begin;
  104594. int partvals=n/samples_per_partition;
  104595. int partwords=(partvals+partitions_per_word-1)/partitions_per_word;
  104596. int **partword=(int**)_vorbis_block_alloc(vb,partwords*sizeof(*partword));
  104597. for(i=0;i<ch;i++)if(nonzero[i])break;
  104598. if(i==ch)return(0); /* no nonzero vectors */
  104599. for(s=0;s<look->stages;s++){
  104600. for(i=0,l=0;i<partvals;l++){
  104601. if(s==0){
  104602. int temp=vorbis_book_decode(look->phrasebook,&vb->opb);
  104603. if(temp==-1)goto eopbreak;
  104604. partword[l]=look->decodemap[temp];
  104605. if(partword[l]==NULL)goto errout;
  104606. }
  104607. for(k=0;k<partitions_per_word && i<partvals;k++,i++)
  104608. if(info->secondstages[partword[l][k]]&(1<<s)){
  104609. codebook *stagebook=look->partbooks[partword[l][k]][s];
  104610. if(stagebook){
  104611. if(vorbis_book_decodevv_add(stagebook,in,
  104612. i*samples_per_partition+info->begin,ch,
  104613. &vb->opb,samples_per_partition)==-1)
  104614. goto eopbreak;
  104615. }
  104616. }
  104617. }
  104618. }
  104619. errout:
  104620. eopbreak:
  104621. return(0);
  104622. }
  104623. vorbis_func_residue residue0_exportbundle={
  104624. NULL,
  104625. &res0_unpack,
  104626. &res0_look,
  104627. &res0_free_info,
  104628. &res0_free_look,
  104629. NULL,
  104630. NULL,
  104631. &res0_inverse
  104632. };
  104633. vorbis_func_residue residue1_exportbundle={
  104634. &res0_pack,
  104635. &res0_unpack,
  104636. &res0_look,
  104637. &res0_free_info,
  104638. &res0_free_look,
  104639. &res1_class,
  104640. &res1_forward,
  104641. &res1_inverse
  104642. };
  104643. vorbis_func_residue residue2_exportbundle={
  104644. &res0_pack,
  104645. &res0_unpack,
  104646. &res0_look,
  104647. &res0_free_info,
  104648. &res0_free_look,
  104649. &res2_class,
  104650. &res2_forward,
  104651. &res2_inverse
  104652. };
  104653. #endif
  104654. /*** End of inlined file: res0.c ***/
  104655. /*** Start of inlined file: sharedbook.c ***/
  104656. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  104657. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  104658. // tasks..
  104659. #if JUCE_MSVC
  104660. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  104661. #endif
  104662. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  104663. #if JUCE_USE_OGGVORBIS
  104664. #include <stdlib.h>
  104665. #include <math.h>
  104666. #include <string.h>
  104667. int _ilog(unsigned int v){
  104668. int ret=0;
  104669. while(v){
  104670. ret++;
  104671. v>>=1;
  104672. }
  104673. return(ret);
  104674. }
  104675. #define VQ_FEXP 10
  104676. #define VQ_FMAN 21
  104677. #define VQ_FEXP_BIAS 768 /* bias toward values smaller than 1. */
  104678. long _float32_pack(float val){
  104679. int sign=0;
  104680. long exp;
  104681. long mant;
  104682. if(val<0){
  104683. sign=0x80000000;
  104684. val= -val;
  104685. }
  104686. exp= floor(log(val)/log(2.f));
  104687. mant=rint(ldexp(val,(VQ_FMAN-1)-exp));
  104688. exp=(exp+VQ_FEXP_BIAS)<<VQ_FMAN;
  104689. return(sign|exp|mant);
  104690. }
  104691. float _float32_unpack(long val){
  104692. double mant=val&0x1fffff;
  104693. int sign=val&0x80000000;
  104694. long exp =(val&0x7fe00000L)>>VQ_FMAN;
  104695. if(sign)mant= -mant;
  104696. return(ldexp(mant,exp-(VQ_FMAN-1)-VQ_FEXP_BIAS));
  104697. }
  104698. ogg_uint32_t *_make_words(long *l,long n,long sparsecount){
  104699. long i,j,count=0;
  104700. ogg_uint32_t marker[33];
  104701. ogg_uint32_t *r=(ogg_uint32_t*)_ogg_malloc((sparsecount?sparsecount:n)*sizeof(*r));
  104702. memset(marker,0,sizeof(marker));
  104703. for(i=0;i<n;i++){
  104704. long length=l[i];
  104705. if(length>0){
  104706. ogg_uint32_t entry=marker[length];
  104707. if(length<32 && (entry>>length)){
  104708. _ogg_free(r);
  104709. return(NULL);
  104710. }
  104711. r[count++]=entry;
  104712. {
  104713. for(j=length;j>0;j--){
  104714. if(marker[j]&1){
  104715. if(j==1)
  104716. marker[1]++;
  104717. else
  104718. marker[j]=marker[j-1]<<1;
  104719. break; /* invariant says next upper marker would already
  104720. have been moved if it was on the same path */
  104721. }
  104722. marker[j]++;
  104723. }
  104724. }
  104725. for(j=length+1;j<33;j++)
  104726. if((marker[j]>>1) == entry){
  104727. entry=marker[j];
  104728. marker[j]=marker[j-1]<<1;
  104729. }else
  104730. break;
  104731. }else
  104732. if(sparsecount==0)count++;
  104733. }
  104734. for(i=0,count=0;i<n;i++){
  104735. ogg_uint32_t temp=0;
  104736. for(j=0;j<l[i];j++){
  104737. temp<<=1;
  104738. temp|=(r[count]>>j)&1;
  104739. }
  104740. if(sparsecount){
  104741. if(l[i])
  104742. r[count++]=temp;
  104743. }else
  104744. r[count++]=temp;
  104745. }
  104746. return(r);
  104747. }
  104748. long _book_maptype1_quantvals(const static_codebook *b){
  104749. long vals=floor(pow((float)b->entries,1.f/b->dim));
  104750. while(1){
  104751. long acc=1;
  104752. long acc1=1;
  104753. int i;
  104754. for(i=0;i<b->dim;i++){
  104755. acc*=vals;
  104756. acc1*=vals+1;
  104757. }
  104758. if(acc<=b->entries && acc1>b->entries){
  104759. return(vals);
  104760. }else{
  104761. if(acc>b->entries){
  104762. vals--;
  104763. }else{
  104764. vals++;
  104765. }
  104766. }
  104767. }
  104768. }
  104769. float *_book_unquantize(const static_codebook *b,int n,int *sparsemap){
  104770. long j,k,count=0;
  104771. if(b->maptype==1 || b->maptype==2){
  104772. int quantvals;
  104773. float mindel=_float32_unpack(b->q_min);
  104774. float delta=_float32_unpack(b->q_delta);
  104775. float *r=(float*)_ogg_calloc(n*b->dim,sizeof(*r));
  104776. switch(b->maptype){
  104777. case 1:
  104778. quantvals=_book_maptype1_quantvals(b);
  104779. for(j=0;j<b->entries;j++){
  104780. if((sparsemap && b->lengthlist[j]) || !sparsemap){
  104781. float last=0.f;
  104782. int indexdiv=1;
  104783. for(k=0;k<b->dim;k++){
  104784. int index= (j/indexdiv)%quantvals;
  104785. float val=b->quantlist[index];
  104786. val=fabs(val)*delta+mindel+last;
  104787. if(b->q_sequencep)last=val;
  104788. if(sparsemap)
  104789. r[sparsemap[count]*b->dim+k]=val;
  104790. else
  104791. r[count*b->dim+k]=val;
  104792. indexdiv*=quantvals;
  104793. }
  104794. count++;
  104795. }
  104796. }
  104797. break;
  104798. case 2:
  104799. for(j=0;j<b->entries;j++){
  104800. if((sparsemap && b->lengthlist[j]) || !sparsemap){
  104801. float last=0.f;
  104802. for(k=0;k<b->dim;k++){
  104803. float val=b->quantlist[j*b->dim+k];
  104804. val=fabs(val)*delta+mindel+last;
  104805. if(b->q_sequencep)last=val;
  104806. if(sparsemap)
  104807. r[sparsemap[count]*b->dim+k]=val;
  104808. else
  104809. r[count*b->dim+k]=val;
  104810. }
  104811. count++;
  104812. }
  104813. }
  104814. break;
  104815. }
  104816. return(r);
  104817. }
  104818. return(NULL);
  104819. }
  104820. void vorbis_staticbook_clear(static_codebook *b){
  104821. if(b->allocedp){
  104822. if(b->quantlist)_ogg_free(b->quantlist);
  104823. if(b->lengthlist)_ogg_free(b->lengthlist);
  104824. if(b->nearest_tree){
  104825. _ogg_free(b->nearest_tree->ptr0);
  104826. _ogg_free(b->nearest_tree->ptr1);
  104827. _ogg_free(b->nearest_tree->p);
  104828. _ogg_free(b->nearest_tree->q);
  104829. memset(b->nearest_tree,0,sizeof(*b->nearest_tree));
  104830. _ogg_free(b->nearest_tree);
  104831. }
  104832. if(b->thresh_tree){
  104833. _ogg_free(b->thresh_tree->quantthresh);
  104834. _ogg_free(b->thresh_tree->quantmap);
  104835. memset(b->thresh_tree,0,sizeof(*b->thresh_tree));
  104836. _ogg_free(b->thresh_tree);
  104837. }
  104838. memset(b,0,sizeof(*b));
  104839. }
  104840. }
  104841. void vorbis_staticbook_destroy(static_codebook *b){
  104842. if(b->allocedp){
  104843. vorbis_staticbook_clear(b);
  104844. _ogg_free(b);
  104845. }
  104846. }
  104847. void vorbis_book_clear(codebook *b){
  104848. if(b->valuelist)_ogg_free(b->valuelist);
  104849. if(b->codelist)_ogg_free(b->codelist);
  104850. if(b->dec_index)_ogg_free(b->dec_index);
  104851. if(b->dec_codelengths)_ogg_free(b->dec_codelengths);
  104852. if(b->dec_firsttable)_ogg_free(b->dec_firsttable);
  104853. memset(b,0,sizeof(*b));
  104854. }
  104855. int vorbis_book_init_encode(codebook *c,const static_codebook *s){
  104856. memset(c,0,sizeof(*c));
  104857. c->c=s;
  104858. c->entries=s->entries;
  104859. c->used_entries=s->entries;
  104860. c->dim=s->dim;
  104861. c->codelist=_make_words(s->lengthlist,s->entries,0);
  104862. c->valuelist=_book_unquantize(s,s->entries,NULL);
  104863. return(0);
  104864. }
  104865. static int sort32a(const void *a,const void *b){
  104866. return ( **(ogg_uint32_t **)a>**(ogg_uint32_t **)b)-
  104867. ( **(ogg_uint32_t **)a<**(ogg_uint32_t **)b);
  104868. }
  104869. int vorbis_book_init_decode(codebook *c,const static_codebook *s){
  104870. int i,j,n=0,tabn;
  104871. int *sortindex;
  104872. memset(c,0,sizeof(*c));
  104873. for(i=0;i<s->entries;i++)
  104874. if(s->lengthlist[i]>0)
  104875. n++;
  104876. c->entries=s->entries;
  104877. c->used_entries=n;
  104878. c->dim=s->dim;
  104879. {
  104880. ogg_uint32_t *codes=_make_words(s->lengthlist,s->entries,c->used_entries);
  104881. ogg_uint32_t **codep=(ogg_uint32_t**)alloca(sizeof(*codep)*n);
  104882. if(codes==NULL)goto err_out;
  104883. for(i=0;i<n;i++){
  104884. codes[i]=ogg_bitreverse(codes[i]);
  104885. codep[i]=codes+i;
  104886. }
  104887. qsort(codep,n,sizeof(*codep),sort32a);
  104888. sortindex=(int*)alloca(n*sizeof(*sortindex));
  104889. c->codelist=(ogg_uint32_t*)_ogg_malloc(n*sizeof(*c->codelist));
  104890. for(i=0;i<n;i++){
  104891. int position=codep[i]-codes;
  104892. sortindex[position]=i;
  104893. }
  104894. for(i=0;i<n;i++)
  104895. c->codelist[sortindex[i]]=codes[i];
  104896. _ogg_free(codes);
  104897. }
  104898. c->valuelist=_book_unquantize(s,n,sortindex);
  104899. c->dec_index=(int*)_ogg_malloc(n*sizeof(*c->dec_index));
  104900. for(n=0,i=0;i<s->entries;i++)
  104901. if(s->lengthlist[i]>0)
  104902. c->dec_index[sortindex[n++]]=i;
  104903. c->dec_codelengths=(char*)_ogg_malloc(n*sizeof(*c->dec_codelengths));
  104904. for(n=0,i=0;i<s->entries;i++)
  104905. if(s->lengthlist[i]>0)
  104906. c->dec_codelengths[sortindex[n++]]=s->lengthlist[i];
  104907. c->dec_firsttablen=_ilog(c->used_entries)-4; /* this is magic */
  104908. if(c->dec_firsttablen<5)c->dec_firsttablen=5;
  104909. if(c->dec_firsttablen>8)c->dec_firsttablen=8;
  104910. tabn=1<<c->dec_firsttablen;
  104911. c->dec_firsttable=(ogg_uint32_t*)_ogg_calloc(tabn,sizeof(*c->dec_firsttable));
  104912. c->dec_maxlength=0;
  104913. for(i=0;i<n;i++){
  104914. if(c->dec_maxlength<c->dec_codelengths[i])
  104915. c->dec_maxlength=c->dec_codelengths[i];
  104916. if(c->dec_codelengths[i]<=c->dec_firsttablen){
  104917. ogg_uint32_t orig=ogg_bitreverse(c->codelist[i]);
  104918. for(j=0;j<(1<<(c->dec_firsttablen-c->dec_codelengths[i]));j++)
  104919. c->dec_firsttable[orig|(j<<c->dec_codelengths[i])]=i+1;
  104920. }
  104921. }
  104922. {
  104923. ogg_uint32_t mask=0xfffffffeUL<<(31-c->dec_firsttablen);
  104924. long lo=0,hi=0;
  104925. for(i=0;i<tabn;i++){
  104926. ogg_uint32_t word=i<<(32-c->dec_firsttablen);
  104927. if(c->dec_firsttable[ogg_bitreverse(word)]==0){
  104928. while((lo+1)<n && c->codelist[lo+1]<=word)lo++;
  104929. while( hi<n && word>=(c->codelist[hi]&mask))hi++;
  104930. {
  104931. unsigned long loval=lo;
  104932. unsigned long hival=n-hi;
  104933. if(loval>0x7fff)loval=0x7fff;
  104934. if(hival>0x7fff)hival=0x7fff;
  104935. c->dec_firsttable[ogg_bitreverse(word)]=
  104936. 0x80000000UL | (loval<<15) | hival;
  104937. }
  104938. }
  104939. }
  104940. }
  104941. return(0);
  104942. err_out:
  104943. vorbis_book_clear(c);
  104944. return(-1);
  104945. }
  104946. static float _dist(int el,float *ref, float *b,int step){
  104947. int i;
  104948. float acc=0.f;
  104949. for(i=0;i<el;i++){
  104950. float val=(ref[i]-b[i*step]);
  104951. acc+=val*val;
  104952. }
  104953. return(acc);
  104954. }
  104955. int _best(codebook *book, float *a, int step){
  104956. encode_aux_threshmatch *tt=book->c->thresh_tree;
  104957. #if 0
  104958. encode_aux_nearestmatch *nt=book->c->nearest_tree;
  104959. encode_aux_pigeonhole *pt=book->c->pigeon_tree;
  104960. #endif
  104961. int dim=book->dim;
  104962. int k,o;
  104963. if(tt){
  104964. int index=0,i;
  104965. for(k=0,o=step*(dim-1);k<dim;k++,o-=step){
  104966. i=tt->threshvals>>1;
  104967. if(a[o]<tt->quantthresh[i]){
  104968. for(;i>0;i--)
  104969. if(a[o]>=tt->quantthresh[i-1])
  104970. break;
  104971. }else{
  104972. for(i++;i<tt->threshvals-1;i++)
  104973. if(a[o]<tt->quantthresh[i])break;
  104974. }
  104975. index=(index*tt->quantvals)+tt->quantmap[i];
  104976. }
  104977. if(book->c->lengthlist[index]>0) /* is this unused? If so, we'll
  104978. use a decision tree after all
  104979. and fall through*/
  104980. return(index);
  104981. }
  104982. #if 0
  104983. if(pt){
  104984. const static_codebook *c=book->c;
  104985. int i,besti=-1;
  104986. float best=0.f;
  104987. int entry=0;
  104988. if(c->q_sequencep){
  104989. int pv;
  104990. long mul=1;
  104991. float qlast=0;
  104992. for(k=0,o=0;k<dim;k++,o+=step){
  104993. pv=(int)((a[o]-qlast-pt->min)/pt->del);
  104994. if(pv<0 || pv>=pt->mapentries)break;
  104995. entry+=pt->pigeonmap[pv]*mul;
  104996. mul*=pt->quantvals;
  104997. qlast+=pv*pt->del+pt->min;
  104998. }
  104999. }else{
  105000. for(k=0,o=step*(dim-1);k<dim;k++,o-=step){
  105001. int pv=(int)((a[o]-pt->min)/pt->del);
  105002. if(pv<0 || pv>=pt->mapentries)break;
  105003. entry=entry*pt->quantvals+pt->pigeonmap[pv];
  105004. }
  105005. }
  105006. if(k==dim && pt->fitlength[entry]){
  105007. long *list=pt->fitlist+pt->fitmap[entry];
  105008. for(i=0;i<pt->fitlength[entry];i++){
  105009. float this=_dist(dim,book->valuelist+list[i]*dim,a,step);
  105010. if(besti==-1 || this<best){
  105011. best=this;
  105012. besti=list[i];
  105013. }
  105014. }
  105015. return(besti);
  105016. }
  105017. }
  105018. if(nt){
  105019. while(1){
  105020. float c=0.f;
  105021. float *p=book->valuelist+nt->p[ptr];
  105022. float *q=book->valuelist+nt->q[ptr];
  105023. for(k=0,o=0;k<dim;k++,o+=step)
  105024. c+=(p[k]-q[k])*(a[o]-(p[k]+q[k])*.5);
  105025. if(c>0.f) /* in A */
  105026. ptr= -nt->ptr0[ptr];
  105027. else /* in B */
  105028. ptr= -nt->ptr1[ptr];
  105029. if(ptr<=0)break;
  105030. }
  105031. return(-ptr);
  105032. }
  105033. #endif
  105034. {
  105035. const static_codebook *c=book->c;
  105036. int i,besti=-1;
  105037. float best=0.f;
  105038. float *e=book->valuelist;
  105039. for(i=0;i<book->entries;i++){
  105040. if(c->lengthlist[i]>0){
  105041. float thisx=_dist(dim,e,a,step);
  105042. if(besti==-1 || thisx<best){
  105043. best=thisx;
  105044. besti=i;
  105045. }
  105046. }
  105047. e+=dim;
  105048. }
  105049. return(besti);
  105050. }
  105051. }
  105052. long vorbis_book_codeword(codebook *book,int entry){
  105053. if(book->c) /* only use with encode; decode optimizations are
  105054. allowed to break this */
  105055. return book->codelist[entry];
  105056. return -1;
  105057. }
  105058. long vorbis_book_codelen(codebook *book,int entry){
  105059. if(book->c) /* only use with encode; decode optimizations are
  105060. allowed to break this */
  105061. return book->c->lengthlist[entry];
  105062. return -1;
  105063. }
  105064. #ifdef _V_SELFTEST
  105065. #include <stdio.h>
  105066. static long full_quantlist1[]={0,1,2,3, 4,5,6,7, 8,3,6,1};
  105067. static long partial_quantlist1[]={0,7,2};
  105068. static_codebook test1={
  105069. 4,16,
  105070. NULL,
  105071. 0,
  105072. 0,0,0,0,
  105073. NULL,
  105074. NULL,NULL
  105075. };
  105076. static float *test1_result=NULL;
  105077. static_codebook test2={
  105078. 4,3,
  105079. NULL,
  105080. 2,
  105081. -533200896,1611661312,4,0,
  105082. full_quantlist1,
  105083. NULL,NULL
  105084. };
  105085. static float test2_result[]={-3,-2,-1,0, 1,2,3,4, 5,0,3,-2};
  105086. static_codebook test3={
  105087. 4,3,
  105088. NULL,
  105089. 2,
  105090. -533200896,1611661312,4,1,
  105091. full_quantlist1,
  105092. NULL,NULL
  105093. };
  105094. static float test3_result[]={-3,-5,-6,-6, 1,3,6,10, 5,5,8,6};
  105095. static_codebook test4={
  105096. 3,27,
  105097. NULL,
  105098. 1,
  105099. -533200896,1611661312,4,0,
  105100. partial_quantlist1,
  105101. NULL,NULL
  105102. };
  105103. static float test4_result[]={-3,-3,-3, 4,-3,-3, -1,-3,-3,
  105104. -3, 4,-3, 4, 4,-3, -1, 4,-3,
  105105. -3,-1,-3, 4,-1,-3, -1,-1,-3,
  105106. -3,-3, 4, 4,-3, 4, -1,-3, 4,
  105107. -3, 4, 4, 4, 4, 4, -1, 4, 4,
  105108. -3,-1, 4, 4,-1, 4, -1,-1, 4,
  105109. -3,-3,-1, 4,-3,-1, -1,-3,-1,
  105110. -3, 4,-1, 4, 4,-1, -1, 4,-1,
  105111. -3,-1,-1, 4,-1,-1, -1,-1,-1};
  105112. static_codebook test5={
  105113. 3,27,
  105114. NULL,
  105115. 1,
  105116. -533200896,1611661312,4,1,
  105117. partial_quantlist1,
  105118. NULL,NULL
  105119. };
  105120. static float test5_result[]={-3,-6,-9, 4, 1,-2, -1,-4,-7,
  105121. -3, 1,-2, 4, 8, 5, -1, 3, 0,
  105122. -3,-4,-7, 4, 3, 0, -1,-2,-5,
  105123. -3,-6,-2, 4, 1, 5, -1,-4, 0,
  105124. -3, 1, 5, 4, 8,12, -1, 3, 7,
  105125. -3,-4, 0, 4, 3, 7, -1,-2, 2,
  105126. -3,-6,-7, 4, 1, 0, -1,-4,-5,
  105127. -3, 1, 0, 4, 8, 7, -1, 3, 2,
  105128. -3,-4,-5, 4, 3, 2, -1,-2,-3};
  105129. void run_test(static_codebook *b,float *comp){
  105130. float *out=_book_unquantize(b,b->entries,NULL);
  105131. int i;
  105132. if(comp){
  105133. if(!out){
  105134. fprintf(stderr,"_book_unquantize incorrectly returned NULL\n");
  105135. exit(1);
  105136. }
  105137. for(i=0;i<b->entries*b->dim;i++)
  105138. if(fabs(out[i]-comp[i])>.0001){
  105139. fprintf(stderr,"disagreement in unquantized and reference data:\n"
  105140. "position %d, %g != %g\n",i,out[i],comp[i]);
  105141. exit(1);
  105142. }
  105143. }else{
  105144. if(out){
  105145. fprintf(stderr,"_book_unquantize returned a value array: \n"
  105146. " correct result should have been NULL\n");
  105147. exit(1);
  105148. }
  105149. }
  105150. }
  105151. int main(){
  105152. fprintf(stderr,"Dequant test 1... ");
  105153. run_test(&test1,test1_result);
  105154. fprintf(stderr,"OK\nDequant test 2... ");
  105155. run_test(&test2,test2_result);
  105156. fprintf(stderr,"OK\nDequant test 3... ");
  105157. run_test(&test3,test3_result);
  105158. fprintf(stderr,"OK\nDequant test 4... ");
  105159. run_test(&test4,test4_result);
  105160. fprintf(stderr,"OK\nDequant test 5... ");
  105161. run_test(&test5,test5_result);
  105162. fprintf(stderr,"OK\n\n");
  105163. return(0);
  105164. }
  105165. #endif
  105166. #endif
  105167. /*** End of inlined file: sharedbook.c ***/
  105168. /*** Start of inlined file: smallft.c ***/
  105169. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  105170. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  105171. // tasks..
  105172. #if JUCE_MSVC
  105173. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  105174. #endif
  105175. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  105176. #if JUCE_USE_OGGVORBIS
  105177. #include <stdlib.h>
  105178. #include <string.h>
  105179. #include <math.h>
  105180. static void drfti1(int n, float *wa, int *ifac){
  105181. static int ntryh[4] = { 4,2,3,5 };
  105182. static float tpi = 6.28318530717958648f;
  105183. float arg,argh,argld,fi;
  105184. int ntry=0,i,j=-1;
  105185. int k1, l1, l2, ib;
  105186. int ld, ii, ip, is, nq, nr;
  105187. int ido, ipm, nfm1;
  105188. int nl=n;
  105189. int nf=0;
  105190. L101:
  105191. j++;
  105192. if (j < 4)
  105193. ntry=ntryh[j];
  105194. else
  105195. ntry+=2;
  105196. L104:
  105197. nq=nl/ntry;
  105198. nr=nl-ntry*nq;
  105199. if (nr!=0) goto L101;
  105200. nf++;
  105201. ifac[nf+1]=ntry;
  105202. nl=nq;
  105203. if(ntry!=2)goto L107;
  105204. if(nf==1)goto L107;
  105205. for (i=1;i<nf;i++){
  105206. ib=nf-i+1;
  105207. ifac[ib+1]=ifac[ib];
  105208. }
  105209. ifac[2] = 2;
  105210. L107:
  105211. if(nl!=1)goto L104;
  105212. ifac[0]=n;
  105213. ifac[1]=nf;
  105214. argh=tpi/n;
  105215. is=0;
  105216. nfm1=nf-1;
  105217. l1=1;
  105218. if(nfm1==0)return;
  105219. for (k1=0;k1<nfm1;k1++){
  105220. ip=ifac[k1+2];
  105221. ld=0;
  105222. l2=l1*ip;
  105223. ido=n/l2;
  105224. ipm=ip-1;
  105225. for (j=0;j<ipm;j++){
  105226. ld+=l1;
  105227. i=is;
  105228. argld=(float)ld*argh;
  105229. fi=0.f;
  105230. for (ii=2;ii<ido;ii+=2){
  105231. fi+=1.f;
  105232. arg=fi*argld;
  105233. wa[i++]=cos(arg);
  105234. wa[i++]=sin(arg);
  105235. }
  105236. is+=ido;
  105237. }
  105238. l1=l2;
  105239. }
  105240. }
  105241. static void fdrffti(int n, float *wsave, int *ifac){
  105242. if (n == 1) return;
  105243. drfti1(n, wsave+n, ifac);
  105244. }
  105245. static void dradf2(int ido,int l1,float *cc,float *ch,float *wa1){
  105246. int i,k;
  105247. float ti2,tr2;
  105248. int t0,t1,t2,t3,t4,t5,t6;
  105249. t1=0;
  105250. t0=(t2=l1*ido);
  105251. t3=ido<<1;
  105252. for(k=0;k<l1;k++){
  105253. ch[t1<<1]=cc[t1]+cc[t2];
  105254. ch[(t1<<1)+t3-1]=cc[t1]-cc[t2];
  105255. t1+=ido;
  105256. t2+=ido;
  105257. }
  105258. if(ido<2)return;
  105259. if(ido==2)goto L105;
  105260. t1=0;
  105261. t2=t0;
  105262. for(k=0;k<l1;k++){
  105263. t3=t2;
  105264. t4=(t1<<1)+(ido<<1);
  105265. t5=t1;
  105266. t6=t1+t1;
  105267. for(i=2;i<ido;i+=2){
  105268. t3+=2;
  105269. t4-=2;
  105270. t5+=2;
  105271. t6+=2;
  105272. tr2=wa1[i-2]*cc[t3-1]+wa1[i-1]*cc[t3];
  105273. ti2=wa1[i-2]*cc[t3]-wa1[i-1]*cc[t3-1];
  105274. ch[t6]=cc[t5]+ti2;
  105275. ch[t4]=ti2-cc[t5];
  105276. ch[t6-1]=cc[t5-1]+tr2;
  105277. ch[t4-1]=cc[t5-1]-tr2;
  105278. }
  105279. t1+=ido;
  105280. t2+=ido;
  105281. }
  105282. if(ido%2==1)return;
  105283. L105:
  105284. t3=(t2=(t1=ido)-1);
  105285. t2+=t0;
  105286. for(k=0;k<l1;k++){
  105287. ch[t1]=-cc[t2];
  105288. ch[t1-1]=cc[t3];
  105289. t1+=ido<<1;
  105290. t2+=ido;
  105291. t3+=ido;
  105292. }
  105293. }
  105294. static void dradf4(int ido,int l1,float *cc,float *ch,float *wa1,
  105295. float *wa2,float *wa3){
  105296. static float hsqt2 = .70710678118654752f;
  105297. int i,k,t0,t1,t2,t3,t4,t5,t6;
  105298. float ci2,ci3,ci4,cr2,cr3,cr4,ti1,ti2,ti3,ti4,tr1,tr2,tr3,tr4;
  105299. t0=l1*ido;
  105300. t1=t0;
  105301. t4=t1<<1;
  105302. t2=t1+(t1<<1);
  105303. t3=0;
  105304. for(k=0;k<l1;k++){
  105305. tr1=cc[t1]+cc[t2];
  105306. tr2=cc[t3]+cc[t4];
  105307. ch[t5=t3<<2]=tr1+tr2;
  105308. ch[(ido<<2)+t5-1]=tr2-tr1;
  105309. ch[(t5+=(ido<<1))-1]=cc[t3]-cc[t4];
  105310. ch[t5]=cc[t2]-cc[t1];
  105311. t1+=ido;
  105312. t2+=ido;
  105313. t3+=ido;
  105314. t4+=ido;
  105315. }
  105316. if(ido<2)return;
  105317. if(ido==2)goto L105;
  105318. t1=0;
  105319. for(k=0;k<l1;k++){
  105320. t2=t1;
  105321. t4=t1<<2;
  105322. t5=(t6=ido<<1)+t4;
  105323. for(i=2;i<ido;i+=2){
  105324. t3=(t2+=2);
  105325. t4+=2;
  105326. t5-=2;
  105327. t3+=t0;
  105328. cr2=wa1[i-2]*cc[t3-1]+wa1[i-1]*cc[t3];
  105329. ci2=wa1[i-2]*cc[t3]-wa1[i-1]*cc[t3-1];
  105330. t3+=t0;
  105331. cr3=wa2[i-2]*cc[t3-1]+wa2[i-1]*cc[t3];
  105332. ci3=wa2[i-2]*cc[t3]-wa2[i-1]*cc[t3-1];
  105333. t3+=t0;
  105334. cr4=wa3[i-2]*cc[t3-1]+wa3[i-1]*cc[t3];
  105335. ci4=wa3[i-2]*cc[t3]-wa3[i-1]*cc[t3-1];
  105336. tr1=cr2+cr4;
  105337. tr4=cr4-cr2;
  105338. ti1=ci2+ci4;
  105339. ti4=ci2-ci4;
  105340. ti2=cc[t2]+ci3;
  105341. ti3=cc[t2]-ci3;
  105342. tr2=cc[t2-1]+cr3;
  105343. tr3=cc[t2-1]-cr3;
  105344. ch[t4-1]=tr1+tr2;
  105345. ch[t4]=ti1+ti2;
  105346. ch[t5-1]=tr3-ti4;
  105347. ch[t5]=tr4-ti3;
  105348. ch[t4+t6-1]=ti4+tr3;
  105349. ch[t4+t6]=tr4+ti3;
  105350. ch[t5+t6-1]=tr2-tr1;
  105351. ch[t5+t6]=ti1-ti2;
  105352. }
  105353. t1+=ido;
  105354. }
  105355. if(ido&1)return;
  105356. L105:
  105357. t2=(t1=t0+ido-1)+(t0<<1);
  105358. t3=ido<<2;
  105359. t4=ido;
  105360. t5=ido<<1;
  105361. t6=ido;
  105362. for(k=0;k<l1;k++){
  105363. ti1=-hsqt2*(cc[t1]+cc[t2]);
  105364. tr1=hsqt2*(cc[t1]-cc[t2]);
  105365. ch[t4-1]=tr1+cc[t6-1];
  105366. ch[t4+t5-1]=cc[t6-1]-tr1;
  105367. ch[t4]=ti1-cc[t1+t0];
  105368. ch[t4+t5]=ti1+cc[t1+t0];
  105369. t1+=ido;
  105370. t2+=ido;
  105371. t4+=t3;
  105372. t6+=ido;
  105373. }
  105374. }
  105375. static void dradfg(int ido,int ip,int l1,int idl1,float *cc,float *c1,
  105376. float *c2,float *ch,float *ch2,float *wa){
  105377. static float tpi=6.283185307179586f;
  105378. int idij,ipph,i,j,k,l,ic,ik,is;
  105379. int t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
  105380. float dc2,ai1,ai2,ar1,ar2,ds2;
  105381. int nbd;
  105382. float dcp,arg,dsp,ar1h,ar2h;
  105383. int idp2,ipp2;
  105384. arg=tpi/(float)ip;
  105385. dcp=cos(arg);
  105386. dsp=sin(arg);
  105387. ipph=(ip+1)>>1;
  105388. ipp2=ip;
  105389. idp2=ido;
  105390. nbd=(ido-1)>>1;
  105391. t0=l1*ido;
  105392. t10=ip*ido;
  105393. if(ido==1)goto L119;
  105394. for(ik=0;ik<idl1;ik++)ch2[ik]=c2[ik];
  105395. t1=0;
  105396. for(j=1;j<ip;j++){
  105397. t1+=t0;
  105398. t2=t1;
  105399. for(k=0;k<l1;k++){
  105400. ch[t2]=c1[t2];
  105401. t2+=ido;
  105402. }
  105403. }
  105404. is=-ido;
  105405. t1=0;
  105406. if(nbd>l1){
  105407. for(j=1;j<ip;j++){
  105408. t1+=t0;
  105409. is+=ido;
  105410. t2= -ido+t1;
  105411. for(k=0;k<l1;k++){
  105412. idij=is-1;
  105413. t2+=ido;
  105414. t3=t2;
  105415. for(i=2;i<ido;i+=2){
  105416. idij+=2;
  105417. t3+=2;
  105418. ch[t3-1]=wa[idij-1]*c1[t3-1]+wa[idij]*c1[t3];
  105419. ch[t3]=wa[idij-1]*c1[t3]-wa[idij]*c1[t3-1];
  105420. }
  105421. }
  105422. }
  105423. }else{
  105424. for(j=1;j<ip;j++){
  105425. is+=ido;
  105426. idij=is-1;
  105427. t1+=t0;
  105428. t2=t1;
  105429. for(i=2;i<ido;i+=2){
  105430. idij+=2;
  105431. t2+=2;
  105432. t3=t2;
  105433. for(k=0;k<l1;k++){
  105434. ch[t3-1]=wa[idij-1]*c1[t3-1]+wa[idij]*c1[t3];
  105435. ch[t3]=wa[idij-1]*c1[t3]-wa[idij]*c1[t3-1];
  105436. t3+=ido;
  105437. }
  105438. }
  105439. }
  105440. }
  105441. t1=0;
  105442. t2=ipp2*t0;
  105443. if(nbd<l1){
  105444. for(j=1;j<ipph;j++){
  105445. t1+=t0;
  105446. t2-=t0;
  105447. t3=t1;
  105448. t4=t2;
  105449. for(i=2;i<ido;i+=2){
  105450. t3+=2;
  105451. t4+=2;
  105452. t5=t3-ido;
  105453. t6=t4-ido;
  105454. for(k=0;k<l1;k++){
  105455. t5+=ido;
  105456. t6+=ido;
  105457. c1[t5-1]=ch[t5-1]+ch[t6-1];
  105458. c1[t6-1]=ch[t5]-ch[t6];
  105459. c1[t5]=ch[t5]+ch[t6];
  105460. c1[t6]=ch[t6-1]-ch[t5-1];
  105461. }
  105462. }
  105463. }
  105464. }else{
  105465. for(j=1;j<ipph;j++){
  105466. t1+=t0;
  105467. t2-=t0;
  105468. t3=t1;
  105469. t4=t2;
  105470. for(k=0;k<l1;k++){
  105471. t5=t3;
  105472. t6=t4;
  105473. for(i=2;i<ido;i+=2){
  105474. t5+=2;
  105475. t6+=2;
  105476. c1[t5-1]=ch[t5-1]+ch[t6-1];
  105477. c1[t6-1]=ch[t5]-ch[t6];
  105478. c1[t5]=ch[t5]+ch[t6];
  105479. c1[t6]=ch[t6-1]-ch[t5-1];
  105480. }
  105481. t3+=ido;
  105482. t4+=ido;
  105483. }
  105484. }
  105485. }
  105486. L119:
  105487. for(ik=0;ik<idl1;ik++)c2[ik]=ch2[ik];
  105488. t1=0;
  105489. t2=ipp2*idl1;
  105490. for(j=1;j<ipph;j++){
  105491. t1+=t0;
  105492. t2-=t0;
  105493. t3=t1-ido;
  105494. t4=t2-ido;
  105495. for(k=0;k<l1;k++){
  105496. t3+=ido;
  105497. t4+=ido;
  105498. c1[t3]=ch[t3]+ch[t4];
  105499. c1[t4]=ch[t4]-ch[t3];
  105500. }
  105501. }
  105502. ar1=1.f;
  105503. ai1=0.f;
  105504. t1=0;
  105505. t2=ipp2*idl1;
  105506. t3=(ip-1)*idl1;
  105507. for(l=1;l<ipph;l++){
  105508. t1+=idl1;
  105509. t2-=idl1;
  105510. ar1h=dcp*ar1-dsp*ai1;
  105511. ai1=dcp*ai1+dsp*ar1;
  105512. ar1=ar1h;
  105513. t4=t1;
  105514. t5=t2;
  105515. t6=t3;
  105516. t7=idl1;
  105517. for(ik=0;ik<idl1;ik++){
  105518. ch2[t4++]=c2[ik]+ar1*c2[t7++];
  105519. ch2[t5++]=ai1*c2[t6++];
  105520. }
  105521. dc2=ar1;
  105522. ds2=ai1;
  105523. ar2=ar1;
  105524. ai2=ai1;
  105525. t4=idl1;
  105526. t5=(ipp2-1)*idl1;
  105527. for(j=2;j<ipph;j++){
  105528. t4+=idl1;
  105529. t5-=idl1;
  105530. ar2h=dc2*ar2-ds2*ai2;
  105531. ai2=dc2*ai2+ds2*ar2;
  105532. ar2=ar2h;
  105533. t6=t1;
  105534. t7=t2;
  105535. t8=t4;
  105536. t9=t5;
  105537. for(ik=0;ik<idl1;ik++){
  105538. ch2[t6++]+=ar2*c2[t8++];
  105539. ch2[t7++]+=ai2*c2[t9++];
  105540. }
  105541. }
  105542. }
  105543. t1=0;
  105544. for(j=1;j<ipph;j++){
  105545. t1+=idl1;
  105546. t2=t1;
  105547. for(ik=0;ik<idl1;ik++)ch2[ik]+=c2[t2++];
  105548. }
  105549. if(ido<l1)goto L132;
  105550. t1=0;
  105551. t2=0;
  105552. for(k=0;k<l1;k++){
  105553. t3=t1;
  105554. t4=t2;
  105555. for(i=0;i<ido;i++)cc[t4++]=ch[t3++];
  105556. t1+=ido;
  105557. t2+=t10;
  105558. }
  105559. goto L135;
  105560. L132:
  105561. for(i=0;i<ido;i++){
  105562. t1=i;
  105563. t2=i;
  105564. for(k=0;k<l1;k++){
  105565. cc[t2]=ch[t1];
  105566. t1+=ido;
  105567. t2+=t10;
  105568. }
  105569. }
  105570. L135:
  105571. t1=0;
  105572. t2=ido<<1;
  105573. t3=0;
  105574. t4=ipp2*t0;
  105575. for(j=1;j<ipph;j++){
  105576. t1+=t2;
  105577. t3+=t0;
  105578. t4-=t0;
  105579. t5=t1;
  105580. t6=t3;
  105581. t7=t4;
  105582. for(k=0;k<l1;k++){
  105583. cc[t5-1]=ch[t6];
  105584. cc[t5]=ch[t7];
  105585. t5+=t10;
  105586. t6+=ido;
  105587. t7+=ido;
  105588. }
  105589. }
  105590. if(ido==1)return;
  105591. if(nbd<l1)goto L141;
  105592. t1=-ido;
  105593. t3=0;
  105594. t4=0;
  105595. t5=ipp2*t0;
  105596. for(j=1;j<ipph;j++){
  105597. t1+=t2;
  105598. t3+=t2;
  105599. t4+=t0;
  105600. t5-=t0;
  105601. t6=t1;
  105602. t7=t3;
  105603. t8=t4;
  105604. t9=t5;
  105605. for(k=0;k<l1;k++){
  105606. for(i=2;i<ido;i+=2){
  105607. ic=idp2-i;
  105608. cc[i+t7-1]=ch[i+t8-1]+ch[i+t9-1];
  105609. cc[ic+t6-1]=ch[i+t8-1]-ch[i+t9-1];
  105610. cc[i+t7]=ch[i+t8]+ch[i+t9];
  105611. cc[ic+t6]=ch[i+t9]-ch[i+t8];
  105612. }
  105613. t6+=t10;
  105614. t7+=t10;
  105615. t8+=ido;
  105616. t9+=ido;
  105617. }
  105618. }
  105619. return;
  105620. L141:
  105621. t1=-ido;
  105622. t3=0;
  105623. t4=0;
  105624. t5=ipp2*t0;
  105625. for(j=1;j<ipph;j++){
  105626. t1+=t2;
  105627. t3+=t2;
  105628. t4+=t0;
  105629. t5-=t0;
  105630. for(i=2;i<ido;i+=2){
  105631. t6=idp2+t1-i;
  105632. t7=i+t3;
  105633. t8=i+t4;
  105634. t9=i+t5;
  105635. for(k=0;k<l1;k++){
  105636. cc[t7-1]=ch[t8-1]+ch[t9-1];
  105637. cc[t6-1]=ch[t8-1]-ch[t9-1];
  105638. cc[t7]=ch[t8]+ch[t9];
  105639. cc[t6]=ch[t9]-ch[t8];
  105640. t6+=t10;
  105641. t7+=t10;
  105642. t8+=ido;
  105643. t9+=ido;
  105644. }
  105645. }
  105646. }
  105647. }
  105648. static void drftf1(int n,float *c,float *ch,float *wa,int *ifac){
  105649. int i,k1,l1,l2;
  105650. int na,kh,nf;
  105651. int ip,iw,ido,idl1,ix2,ix3;
  105652. nf=ifac[1];
  105653. na=1;
  105654. l2=n;
  105655. iw=n;
  105656. for(k1=0;k1<nf;k1++){
  105657. kh=nf-k1;
  105658. ip=ifac[kh+1];
  105659. l1=l2/ip;
  105660. ido=n/l2;
  105661. idl1=ido*l1;
  105662. iw-=(ip-1)*ido;
  105663. na=1-na;
  105664. if(ip!=4)goto L102;
  105665. ix2=iw+ido;
  105666. ix3=ix2+ido;
  105667. if(na!=0)
  105668. dradf4(ido,l1,ch,c,wa+iw-1,wa+ix2-1,wa+ix3-1);
  105669. else
  105670. dradf4(ido,l1,c,ch,wa+iw-1,wa+ix2-1,wa+ix3-1);
  105671. goto L110;
  105672. L102:
  105673. if(ip!=2)goto L104;
  105674. if(na!=0)goto L103;
  105675. dradf2(ido,l1,c,ch,wa+iw-1);
  105676. goto L110;
  105677. L103:
  105678. dradf2(ido,l1,ch,c,wa+iw-1);
  105679. goto L110;
  105680. L104:
  105681. if(ido==1)na=1-na;
  105682. if(na!=0)goto L109;
  105683. dradfg(ido,ip,l1,idl1,c,c,c,ch,ch,wa+iw-1);
  105684. na=1;
  105685. goto L110;
  105686. L109:
  105687. dradfg(ido,ip,l1,idl1,ch,ch,ch,c,c,wa+iw-1);
  105688. na=0;
  105689. L110:
  105690. l2=l1;
  105691. }
  105692. if(na==1)return;
  105693. for(i=0;i<n;i++)c[i]=ch[i];
  105694. }
  105695. static void dradb2(int ido,int l1,float *cc,float *ch,float *wa1){
  105696. int i,k,t0,t1,t2,t3,t4,t5,t6;
  105697. float ti2,tr2;
  105698. t0=l1*ido;
  105699. t1=0;
  105700. t2=0;
  105701. t3=(ido<<1)-1;
  105702. for(k=0;k<l1;k++){
  105703. ch[t1]=cc[t2]+cc[t3+t2];
  105704. ch[t1+t0]=cc[t2]-cc[t3+t2];
  105705. t2=(t1+=ido)<<1;
  105706. }
  105707. if(ido<2)return;
  105708. if(ido==2)goto L105;
  105709. t1=0;
  105710. t2=0;
  105711. for(k=0;k<l1;k++){
  105712. t3=t1;
  105713. t5=(t4=t2)+(ido<<1);
  105714. t6=t0+t1;
  105715. for(i=2;i<ido;i+=2){
  105716. t3+=2;
  105717. t4+=2;
  105718. t5-=2;
  105719. t6+=2;
  105720. ch[t3-1]=cc[t4-1]+cc[t5-1];
  105721. tr2=cc[t4-1]-cc[t5-1];
  105722. ch[t3]=cc[t4]-cc[t5];
  105723. ti2=cc[t4]+cc[t5];
  105724. ch[t6-1]=wa1[i-2]*tr2-wa1[i-1]*ti2;
  105725. ch[t6]=wa1[i-2]*ti2+wa1[i-1]*tr2;
  105726. }
  105727. t2=(t1+=ido)<<1;
  105728. }
  105729. if(ido%2==1)return;
  105730. L105:
  105731. t1=ido-1;
  105732. t2=ido-1;
  105733. for(k=0;k<l1;k++){
  105734. ch[t1]=cc[t2]+cc[t2];
  105735. ch[t1+t0]=-(cc[t2+1]+cc[t2+1]);
  105736. t1+=ido;
  105737. t2+=ido<<1;
  105738. }
  105739. }
  105740. static void dradb3(int ido,int l1,float *cc,float *ch,float *wa1,
  105741. float *wa2){
  105742. static float taur = -.5f;
  105743. static float taui = .8660254037844386f;
  105744. int i,k,t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
  105745. float ci2,ci3,di2,di3,cr2,cr3,dr2,dr3,ti2,tr2;
  105746. t0=l1*ido;
  105747. t1=0;
  105748. t2=t0<<1;
  105749. t3=ido<<1;
  105750. t4=ido+(ido<<1);
  105751. t5=0;
  105752. for(k=0;k<l1;k++){
  105753. tr2=cc[t3-1]+cc[t3-1];
  105754. cr2=cc[t5]+(taur*tr2);
  105755. ch[t1]=cc[t5]+tr2;
  105756. ci3=taui*(cc[t3]+cc[t3]);
  105757. ch[t1+t0]=cr2-ci3;
  105758. ch[t1+t2]=cr2+ci3;
  105759. t1+=ido;
  105760. t3+=t4;
  105761. t5+=t4;
  105762. }
  105763. if(ido==1)return;
  105764. t1=0;
  105765. t3=ido<<1;
  105766. for(k=0;k<l1;k++){
  105767. t7=t1+(t1<<1);
  105768. t6=(t5=t7+t3);
  105769. t8=t1;
  105770. t10=(t9=t1+t0)+t0;
  105771. for(i=2;i<ido;i+=2){
  105772. t5+=2;
  105773. t6-=2;
  105774. t7+=2;
  105775. t8+=2;
  105776. t9+=2;
  105777. t10+=2;
  105778. tr2=cc[t5-1]+cc[t6-1];
  105779. cr2=cc[t7-1]+(taur*tr2);
  105780. ch[t8-1]=cc[t7-1]+tr2;
  105781. ti2=cc[t5]-cc[t6];
  105782. ci2=cc[t7]+(taur*ti2);
  105783. ch[t8]=cc[t7]+ti2;
  105784. cr3=taui*(cc[t5-1]-cc[t6-1]);
  105785. ci3=taui*(cc[t5]+cc[t6]);
  105786. dr2=cr2-ci3;
  105787. dr3=cr2+ci3;
  105788. di2=ci2+cr3;
  105789. di3=ci2-cr3;
  105790. ch[t9-1]=wa1[i-2]*dr2-wa1[i-1]*di2;
  105791. ch[t9]=wa1[i-2]*di2+wa1[i-1]*dr2;
  105792. ch[t10-1]=wa2[i-2]*dr3-wa2[i-1]*di3;
  105793. ch[t10]=wa2[i-2]*di3+wa2[i-1]*dr3;
  105794. }
  105795. t1+=ido;
  105796. }
  105797. }
  105798. static void dradb4(int ido,int l1,float *cc,float *ch,float *wa1,
  105799. float *wa2,float *wa3){
  105800. static float sqrt2=1.414213562373095f;
  105801. int i,k,t0,t1,t2,t3,t4,t5,t6,t7,t8;
  105802. float ci2,ci3,ci4,cr2,cr3,cr4,ti1,ti2,ti3,ti4,tr1,tr2,tr3,tr4;
  105803. t0=l1*ido;
  105804. t1=0;
  105805. t2=ido<<2;
  105806. t3=0;
  105807. t6=ido<<1;
  105808. for(k=0;k<l1;k++){
  105809. t4=t3+t6;
  105810. t5=t1;
  105811. tr3=cc[t4-1]+cc[t4-1];
  105812. tr4=cc[t4]+cc[t4];
  105813. tr1=cc[t3]-cc[(t4+=t6)-1];
  105814. tr2=cc[t3]+cc[t4-1];
  105815. ch[t5]=tr2+tr3;
  105816. ch[t5+=t0]=tr1-tr4;
  105817. ch[t5+=t0]=tr2-tr3;
  105818. ch[t5+=t0]=tr1+tr4;
  105819. t1+=ido;
  105820. t3+=t2;
  105821. }
  105822. if(ido<2)return;
  105823. if(ido==2)goto L105;
  105824. t1=0;
  105825. for(k=0;k<l1;k++){
  105826. t5=(t4=(t3=(t2=t1<<2)+t6))+t6;
  105827. t7=t1;
  105828. for(i=2;i<ido;i+=2){
  105829. t2+=2;
  105830. t3+=2;
  105831. t4-=2;
  105832. t5-=2;
  105833. t7+=2;
  105834. ti1=cc[t2]+cc[t5];
  105835. ti2=cc[t2]-cc[t5];
  105836. ti3=cc[t3]-cc[t4];
  105837. tr4=cc[t3]+cc[t4];
  105838. tr1=cc[t2-1]-cc[t5-1];
  105839. tr2=cc[t2-1]+cc[t5-1];
  105840. ti4=cc[t3-1]-cc[t4-1];
  105841. tr3=cc[t3-1]+cc[t4-1];
  105842. ch[t7-1]=tr2+tr3;
  105843. cr3=tr2-tr3;
  105844. ch[t7]=ti2+ti3;
  105845. ci3=ti2-ti3;
  105846. cr2=tr1-tr4;
  105847. cr4=tr1+tr4;
  105848. ci2=ti1+ti4;
  105849. ci4=ti1-ti4;
  105850. ch[(t8=t7+t0)-1]=wa1[i-2]*cr2-wa1[i-1]*ci2;
  105851. ch[t8]=wa1[i-2]*ci2+wa1[i-1]*cr2;
  105852. ch[(t8+=t0)-1]=wa2[i-2]*cr3-wa2[i-1]*ci3;
  105853. ch[t8]=wa2[i-2]*ci3+wa2[i-1]*cr3;
  105854. ch[(t8+=t0)-1]=wa3[i-2]*cr4-wa3[i-1]*ci4;
  105855. ch[t8]=wa3[i-2]*ci4+wa3[i-1]*cr4;
  105856. }
  105857. t1+=ido;
  105858. }
  105859. if(ido%2 == 1)return;
  105860. L105:
  105861. t1=ido;
  105862. t2=ido<<2;
  105863. t3=ido-1;
  105864. t4=ido+(ido<<1);
  105865. for(k=0;k<l1;k++){
  105866. t5=t3;
  105867. ti1=cc[t1]+cc[t4];
  105868. ti2=cc[t4]-cc[t1];
  105869. tr1=cc[t1-1]-cc[t4-1];
  105870. tr2=cc[t1-1]+cc[t4-1];
  105871. ch[t5]=tr2+tr2;
  105872. ch[t5+=t0]=sqrt2*(tr1-ti1);
  105873. ch[t5+=t0]=ti2+ti2;
  105874. ch[t5+=t0]=-sqrt2*(tr1+ti1);
  105875. t3+=ido;
  105876. t1+=t2;
  105877. t4+=t2;
  105878. }
  105879. }
  105880. static void dradbg(int ido,int ip,int l1,int idl1,float *cc,float *c1,
  105881. float *c2,float *ch,float *ch2,float *wa){
  105882. static float tpi=6.283185307179586f;
  105883. int idij,ipph,i,j,k,l,ik,is,t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,
  105884. t11,t12;
  105885. float dc2,ai1,ai2,ar1,ar2,ds2;
  105886. int nbd;
  105887. float dcp,arg,dsp,ar1h,ar2h;
  105888. int ipp2;
  105889. t10=ip*ido;
  105890. t0=l1*ido;
  105891. arg=tpi/(float)ip;
  105892. dcp=cos(arg);
  105893. dsp=sin(arg);
  105894. nbd=(ido-1)>>1;
  105895. ipp2=ip;
  105896. ipph=(ip+1)>>1;
  105897. if(ido<l1)goto L103;
  105898. t1=0;
  105899. t2=0;
  105900. for(k=0;k<l1;k++){
  105901. t3=t1;
  105902. t4=t2;
  105903. for(i=0;i<ido;i++){
  105904. ch[t3]=cc[t4];
  105905. t3++;
  105906. t4++;
  105907. }
  105908. t1+=ido;
  105909. t2+=t10;
  105910. }
  105911. goto L106;
  105912. L103:
  105913. t1=0;
  105914. for(i=0;i<ido;i++){
  105915. t2=t1;
  105916. t3=t1;
  105917. for(k=0;k<l1;k++){
  105918. ch[t2]=cc[t3];
  105919. t2+=ido;
  105920. t3+=t10;
  105921. }
  105922. t1++;
  105923. }
  105924. L106:
  105925. t1=0;
  105926. t2=ipp2*t0;
  105927. t7=(t5=ido<<1);
  105928. for(j=1;j<ipph;j++){
  105929. t1+=t0;
  105930. t2-=t0;
  105931. t3=t1;
  105932. t4=t2;
  105933. t6=t5;
  105934. for(k=0;k<l1;k++){
  105935. ch[t3]=cc[t6-1]+cc[t6-1];
  105936. ch[t4]=cc[t6]+cc[t6];
  105937. t3+=ido;
  105938. t4+=ido;
  105939. t6+=t10;
  105940. }
  105941. t5+=t7;
  105942. }
  105943. if (ido == 1)goto L116;
  105944. if(nbd<l1)goto L112;
  105945. t1=0;
  105946. t2=ipp2*t0;
  105947. t7=0;
  105948. for(j=1;j<ipph;j++){
  105949. t1+=t0;
  105950. t2-=t0;
  105951. t3=t1;
  105952. t4=t2;
  105953. t7+=(ido<<1);
  105954. t8=t7;
  105955. for(k=0;k<l1;k++){
  105956. t5=t3;
  105957. t6=t4;
  105958. t9=t8;
  105959. t11=t8;
  105960. for(i=2;i<ido;i+=2){
  105961. t5+=2;
  105962. t6+=2;
  105963. t9+=2;
  105964. t11-=2;
  105965. ch[t5-1]=cc[t9-1]+cc[t11-1];
  105966. ch[t6-1]=cc[t9-1]-cc[t11-1];
  105967. ch[t5]=cc[t9]-cc[t11];
  105968. ch[t6]=cc[t9]+cc[t11];
  105969. }
  105970. t3+=ido;
  105971. t4+=ido;
  105972. t8+=t10;
  105973. }
  105974. }
  105975. goto L116;
  105976. L112:
  105977. t1=0;
  105978. t2=ipp2*t0;
  105979. t7=0;
  105980. for(j=1;j<ipph;j++){
  105981. t1+=t0;
  105982. t2-=t0;
  105983. t3=t1;
  105984. t4=t2;
  105985. t7+=(ido<<1);
  105986. t8=t7;
  105987. t9=t7;
  105988. for(i=2;i<ido;i+=2){
  105989. t3+=2;
  105990. t4+=2;
  105991. t8+=2;
  105992. t9-=2;
  105993. t5=t3;
  105994. t6=t4;
  105995. t11=t8;
  105996. t12=t9;
  105997. for(k=0;k<l1;k++){
  105998. ch[t5-1]=cc[t11-1]+cc[t12-1];
  105999. ch[t6-1]=cc[t11-1]-cc[t12-1];
  106000. ch[t5]=cc[t11]-cc[t12];
  106001. ch[t6]=cc[t11]+cc[t12];
  106002. t5+=ido;
  106003. t6+=ido;
  106004. t11+=t10;
  106005. t12+=t10;
  106006. }
  106007. }
  106008. }
  106009. L116:
  106010. ar1=1.f;
  106011. ai1=0.f;
  106012. t1=0;
  106013. t9=(t2=ipp2*idl1);
  106014. t3=(ip-1)*idl1;
  106015. for(l=1;l<ipph;l++){
  106016. t1+=idl1;
  106017. t2-=idl1;
  106018. ar1h=dcp*ar1-dsp*ai1;
  106019. ai1=dcp*ai1+dsp*ar1;
  106020. ar1=ar1h;
  106021. t4=t1;
  106022. t5=t2;
  106023. t6=0;
  106024. t7=idl1;
  106025. t8=t3;
  106026. for(ik=0;ik<idl1;ik++){
  106027. c2[t4++]=ch2[t6++]+ar1*ch2[t7++];
  106028. c2[t5++]=ai1*ch2[t8++];
  106029. }
  106030. dc2=ar1;
  106031. ds2=ai1;
  106032. ar2=ar1;
  106033. ai2=ai1;
  106034. t6=idl1;
  106035. t7=t9-idl1;
  106036. for(j=2;j<ipph;j++){
  106037. t6+=idl1;
  106038. t7-=idl1;
  106039. ar2h=dc2*ar2-ds2*ai2;
  106040. ai2=dc2*ai2+ds2*ar2;
  106041. ar2=ar2h;
  106042. t4=t1;
  106043. t5=t2;
  106044. t11=t6;
  106045. t12=t7;
  106046. for(ik=0;ik<idl1;ik++){
  106047. c2[t4++]+=ar2*ch2[t11++];
  106048. c2[t5++]+=ai2*ch2[t12++];
  106049. }
  106050. }
  106051. }
  106052. t1=0;
  106053. for(j=1;j<ipph;j++){
  106054. t1+=idl1;
  106055. t2=t1;
  106056. for(ik=0;ik<idl1;ik++)ch2[ik]+=ch2[t2++];
  106057. }
  106058. t1=0;
  106059. t2=ipp2*t0;
  106060. for(j=1;j<ipph;j++){
  106061. t1+=t0;
  106062. t2-=t0;
  106063. t3=t1;
  106064. t4=t2;
  106065. for(k=0;k<l1;k++){
  106066. ch[t3]=c1[t3]-c1[t4];
  106067. ch[t4]=c1[t3]+c1[t4];
  106068. t3+=ido;
  106069. t4+=ido;
  106070. }
  106071. }
  106072. if(ido==1)goto L132;
  106073. if(nbd<l1)goto L128;
  106074. t1=0;
  106075. t2=ipp2*t0;
  106076. for(j=1;j<ipph;j++){
  106077. t1+=t0;
  106078. t2-=t0;
  106079. t3=t1;
  106080. t4=t2;
  106081. for(k=0;k<l1;k++){
  106082. t5=t3;
  106083. t6=t4;
  106084. for(i=2;i<ido;i+=2){
  106085. t5+=2;
  106086. t6+=2;
  106087. ch[t5-1]=c1[t5-1]-c1[t6];
  106088. ch[t6-1]=c1[t5-1]+c1[t6];
  106089. ch[t5]=c1[t5]+c1[t6-1];
  106090. ch[t6]=c1[t5]-c1[t6-1];
  106091. }
  106092. t3+=ido;
  106093. t4+=ido;
  106094. }
  106095. }
  106096. goto L132;
  106097. L128:
  106098. t1=0;
  106099. t2=ipp2*t0;
  106100. for(j=1;j<ipph;j++){
  106101. t1+=t0;
  106102. t2-=t0;
  106103. t3=t1;
  106104. t4=t2;
  106105. for(i=2;i<ido;i+=2){
  106106. t3+=2;
  106107. t4+=2;
  106108. t5=t3;
  106109. t6=t4;
  106110. for(k=0;k<l1;k++){
  106111. ch[t5-1]=c1[t5-1]-c1[t6];
  106112. ch[t6-1]=c1[t5-1]+c1[t6];
  106113. ch[t5]=c1[t5]+c1[t6-1];
  106114. ch[t6]=c1[t5]-c1[t6-1];
  106115. t5+=ido;
  106116. t6+=ido;
  106117. }
  106118. }
  106119. }
  106120. L132:
  106121. if(ido==1)return;
  106122. for(ik=0;ik<idl1;ik++)c2[ik]=ch2[ik];
  106123. t1=0;
  106124. for(j=1;j<ip;j++){
  106125. t2=(t1+=t0);
  106126. for(k=0;k<l1;k++){
  106127. c1[t2]=ch[t2];
  106128. t2+=ido;
  106129. }
  106130. }
  106131. if(nbd>l1)goto L139;
  106132. is= -ido-1;
  106133. t1=0;
  106134. for(j=1;j<ip;j++){
  106135. is+=ido;
  106136. t1+=t0;
  106137. idij=is;
  106138. t2=t1;
  106139. for(i=2;i<ido;i+=2){
  106140. t2+=2;
  106141. idij+=2;
  106142. t3=t2;
  106143. for(k=0;k<l1;k++){
  106144. c1[t3-1]=wa[idij-1]*ch[t3-1]-wa[idij]*ch[t3];
  106145. c1[t3]=wa[idij-1]*ch[t3]+wa[idij]*ch[t3-1];
  106146. t3+=ido;
  106147. }
  106148. }
  106149. }
  106150. return;
  106151. L139:
  106152. is= -ido-1;
  106153. t1=0;
  106154. for(j=1;j<ip;j++){
  106155. is+=ido;
  106156. t1+=t0;
  106157. t2=t1;
  106158. for(k=0;k<l1;k++){
  106159. idij=is;
  106160. t3=t2;
  106161. for(i=2;i<ido;i+=2){
  106162. idij+=2;
  106163. t3+=2;
  106164. c1[t3-1]=wa[idij-1]*ch[t3-1]-wa[idij]*ch[t3];
  106165. c1[t3]=wa[idij-1]*ch[t3]+wa[idij]*ch[t3-1];
  106166. }
  106167. t2+=ido;
  106168. }
  106169. }
  106170. }
  106171. static void drftb1(int n, float *c, float *ch, float *wa, int *ifac){
  106172. int i,k1,l1,l2;
  106173. int na;
  106174. int nf,ip,iw,ix2,ix3,ido,idl1;
  106175. nf=ifac[1];
  106176. na=0;
  106177. l1=1;
  106178. iw=1;
  106179. for(k1=0;k1<nf;k1++){
  106180. ip=ifac[k1 + 2];
  106181. l2=ip*l1;
  106182. ido=n/l2;
  106183. idl1=ido*l1;
  106184. if(ip!=4)goto L103;
  106185. ix2=iw+ido;
  106186. ix3=ix2+ido;
  106187. if(na!=0)
  106188. dradb4(ido,l1,ch,c,wa+iw-1,wa+ix2-1,wa+ix3-1);
  106189. else
  106190. dradb4(ido,l1,c,ch,wa+iw-1,wa+ix2-1,wa+ix3-1);
  106191. na=1-na;
  106192. goto L115;
  106193. L103:
  106194. if(ip!=2)goto L106;
  106195. if(na!=0)
  106196. dradb2(ido,l1,ch,c,wa+iw-1);
  106197. else
  106198. dradb2(ido,l1,c,ch,wa+iw-1);
  106199. na=1-na;
  106200. goto L115;
  106201. L106:
  106202. if(ip!=3)goto L109;
  106203. ix2=iw+ido;
  106204. if(na!=0)
  106205. dradb3(ido,l1,ch,c,wa+iw-1,wa+ix2-1);
  106206. else
  106207. dradb3(ido,l1,c,ch,wa+iw-1,wa+ix2-1);
  106208. na=1-na;
  106209. goto L115;
  106210. L109:
  106211. if(na!=0)
  106212. dradbg(ido,ip,l1,idl1,ch,ch,ch,c,c,wa+iw-1);
  106213. else
  106214. dradbg(ido,ip,l1,idl1,c,c,c,ch,ch,wa+iw-1);
  106215. if(ido==1)na=1-na;
  106216. L115:
  106217. l1=l2;
  106218. iw+=(ip-1)*ido;
  106219. }
  106220. if(na==0)return;
  106221. for(i=0;i<n;i++)c[i]=ch[i];
  106222. }
  106223. void drft_forward(drft_lookup *l,float *data){
  106224. if(l->n==1)return;
  106225. drftf1(l->n,data,l->trigcache,l->trigcache+l->n,l->splitcache);
  106226. }
  106227. void drft_backward(drft_lookup *l,float *data){
  106228. if (l->n==1)return;
  106229. drftb1(l->n,data,l->trigcache,l->trigcache+l->n,l->splitcache);
  106230. }
  106231. void drft_init(drft_lookup *l,int n){
  106232. l->n=n;
  106233. l->trigcache=(float*)_ogg_calloc(3*n,sizeof(*l->trigcache));
  106234. l->splitcache=(int*)_ogg_calloc(32,sizeof(*l->splitcache));
  106235. fdrffti(n, l->trigcache, l->splitcache);
  106236. }
  106237. void drft_clear(drft_lookup *l){
  106238. if(l){
  106239. if(l->trigcache)_ogg_free(l->trigcache);
  106240. if(l->splitcache)_ogg_free(l->splitcache);
  106241. memset(l,0,sizeof(*l));
  106242. }
  106243. }
  106244. #endif
  106245. /*** End of inlined file: smallft.c ***/
  106246. /*** Start of inlined file: synthesis.c ***/
  106247. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  106248. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  106249. // tasks..
  106250. #if JUCE_MSVC
  106251. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  106252. #endif
  106253. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  106254. #if JUCE_USE_OGGVORBIS
  106255. #include <stdio.h>
  106256. int vorbis_synthesis(vorbis_block *vb,ogg_packet *op){
  106257. vorbis_dsp_state *vd=vb->vd;
  106258. private_state *b=(private_state*)vd->backend_state;
  106259. vorbis_info *vi=vd->vi;
  106260. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  106261. oggpack_buffer *opb=&vb->opb;
  106262. int type,mode,i;
  106263. _vorbis_block_ripcord(vb);
  106264. oggpack_readinit(opb,op->packet,op->bytes);
  106265. if(oggpack_read(opb,1)!=0){
  106266. return(OV_ENOTAUDIO);
  106267. }
  106268. mode=oggpack_read(opb,b->modebits);
  106269. if(mode==-1)return(OV_EBADPACKET);
  106270. vb->mode=mode;
  106271. vb->W=ci->mode_param[mode]->blockflag;
  106272. if(vb->W){
  106273. vb->lW=oggpack_read(opb,1);
  106274. vb->nW=oggpack_read(opb,1);
  106275. if(vb->nW==-1) return(OV_EBADPACKET);
  106276. }else{
  106277. vb->lW=0;
  106278. vb->nW=0;
  106279. }
  106280. vb->granulepos=op->granulepos;
  106281. vb->sequence=op->packetno;
  106282. vb->eofflag=op->e_o_s;
  106283. vb->pcmend=ci->blocksizes[vb->W];
  106284. vb->pcm=(float**)_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels);
  106285. for(i=0;i<vi->channels;i++)
  106286. vb->pcm[i]=(float*)_vorbis_block_alloc(vb,vb->pcmend*sizeof(*vb->pcm[i]));
  106287. type=ci->map_type[ci->mode_param[mode]->mapping];
  106288. return(_mapping_P[type]->inverse(vb,ci->map_param[ci->mode_param[mode]->
  106289. mapping]));
  106290. }
  106291. int vorbis_synthesis_trackonly(vorbis_block *vb,ogg_packet *op){
  106292. vorbis_dsp_state *vd=vb->vd;
  106293. private_state *b=(private_state*)vd->backend_state;
  106294. vorbis_info *vi=vd->vi;
  106295. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106296. oggpack_buffer *opb=&vb->opb;
  106297. int mode;
  106298. _vorbis_block_ripcord(vb);
  106299. oggpack_readinit(opb,op->packet,op->bytes);
  106300. if(oggpack_read(opb,1)!=0){
  106301. return(OV_ENOTAUDIO);
  106302. }
  106303. mode=oggpack_read(opb,b->modebits);
  106304. if(mode==-1)return(OV_EBADPACKET);
  106305. vb->mode=mode;
  106306. vb->W=ci->mode_param[mode]->blockflag;
  106307. if(vb->W){
  106308. vb->lW=oggpack_read(opb,1);
  106309. vb->nW=oggpack_read(opb,1);
  106310. if(vb->nW==-1) return(OV_EBADPACKET);
  106311. }else{
  106312. vb->lW=0;
  106313. vb->nW=0;
  106314. }
  106315. vb->granulepos=op->granulepos;
  106316. vb->sequence=op->packetno;
  106317. vb->eofflag=op->e_o_s;
  106318. vb->pcmend=0;
  106319. vb->pcm=NULL;
  106320. return(0);
  106321. }
  106322. long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op){
  106323. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106324. oggpack_buffer opb;
  106325. int mode;
  106326. oggpack_readinit(&opb,op->packet,op->bytes);
  106327. if(oggpack_read(&opb,1)!=0){
  106328. return(OV_ENOTAUDIO);
  106329. }
  106330. {
  106331. int modebits=0;
  106332. int v=ci->modes;
  106333. while(v>1){
  106334. modebits++;
  106335. v>>=1;
  106336. }
  106337. mode=oggpack_read(&opb,modebits);
  106338. }
  106339. if(mode==-1)return(OV_EBADPACKET);
  106340. return(ci->blocksizes[ci->mode_param[mode]->blockflag]);
  106341. }
  106342. int vorbis_synthesis_halfrate(vorbis_info *vi,int flag){
  106343. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106344. if(ci->blocksizes[0]<=64 && flag)return -1;
  106345. ci->halfrate_flag=(flag?1:0);
  106346. return 0;
  106347. }
  106348. int vorbis_synthesis_halfrate_p(vorbis_info *vi){
  106349. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106350. return ci->halfrate_flag;
  106351. }
  106352. #endif
  106353. /*** End of inlined file: synthesis.c ***/
  106354. /*** Start of inlined file: vorbisenc.c ***/
  106355. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  106356. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  106357. // tasks..
  106358. #if JUCE_MSVC
  106359. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  106360. #endif
  106361. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  106362. #if JUCE_USE_OGGVORBIS
  106363. #include <stdlib.h>
  106364. #include <string.h>
  106365. #include <math.h>
  106366. typedef struct {
  106367. static_codebook *books[12][3];
  106368. } static_bookblock;
  106369. typedef struct {
  106370. int res_type;
  106371. int limit_type; /* 0 lowpass limited, 1 point stereo limited */
  106372. vorbis_info_residue0 *res;
  106373. static_codebook *book_aux;
  106374. static_codebook *book_aux_managed;
  106375. static_bookblock *books_base;
  106376. static_bookblock *books_base_managed;
  106377. } vorbis_residue_template;
  106378. typedef struct {
  106379. vorbis_info_mapping0 *map;
  106380. vorbis_residue_template *res;
  106381. } vorbis_mapping_template;
  106382. typedef struct vp_adjblock{
  106383. int block[P_BANDS];
  106384. } vp_adjblock;
  106385. typedef struct {
  106386. int data[NOISE_COMPAND_LEVELS];
  106387. } compandblock;
  106388. typedef struct {
  106389. int att[P_NOISECURVES];
  106390. float boost;
  106391. float decay;
  106392. } att3;
  106393. typedef struct { int data[P_NOISECURVES]; } adj3;
  106394. typedef struct {
  106395. int pre[PACKETBLOBS];
  106396. int post[PACKETBLOBS];
  106397. float kHz[PACKETBLOBS];
  106398. float lowpasskHz[PACKETBLOBS];
  106399. } adj_stereo;
  106400. typedef struct {
  106401. int lo;
  106402. int hi;
  106403. int fixed;
  106404. } noiseguard;
  106405. typedef struct {
  106406. int data[P_NOISECURVES][17];
  106407. } noise3;
  106408. typedef struct {
  106409. int mappings;
  106410. double *rate_mapping;
  106411. double *quality_mapping;
  106412. int coupling_restriction;
  106413. long samplerate_min_restriction;
  106414. long samplerate_max_restriction;
  106415. int *blocksize_short;
  106416. int *blocksize_long;
  106417. att3 *psy_tone_masteratt;
  106418. int *psy_tone_0dB;
  106419. int *psy_tone_dBsuppress;
  106420. vp_adjblock *psy_tone_adj_impulse;
  106421. vp_adjblock *psy_tone_adj_long;
  106422. vp_adjblock *psy_tone_adj_other;
  106423. noiseguard *psy_noiseguards;
  106424. noise3 *psy_noise_bias_impulse;
  106425. noise3 *psy_noise_bias_padding;
  106426. noise3 *psy_noise_bias_trans;
  106427. noise3 *psy_noise_bias_long;
  106428. int *psy_noise_dBsuppress;
  106429. compandblock *psy_noise_compand;
  106430. double *psy_noise_compand_short_mapping;
  106431. double *psy_noise_compand_long_mapping;
  106432. int *psy_noise_normal_start[2];
  106433. int *psy_noise_normal_partition[2];
  106434. double *psy_noise_normal_thresh;
  106435. int *psy_ath_float;
  106436. int *psy_ath_abs;
  106437. double *psy_lowpass;
  106438. vorbis_info_psy_global *global_params;
  106439. double *global_mapping;
  106440. adj_stereo *stereo_modes;
  106441. static_codebook ***floor_books;
  106442. vorbis_info_floor1 *floor_params;
  106443. int *floor_short_mapping;
  106444. int *floor_long_mapping;
  106445. vorbis_mapping_template *maps;
  106446. } ve_setup_data_template;
  106447. static vorbis_info_mode _mode_template[2]={
  106448. {0,0,0,0},
  106449. {1,0,0,1}
  106450. };
  106451. static vorbis_info_mapping0 _map_nominal[2]={
  106452. {1, {0,0}, {0}, {0}, 1,{0},{1}},
  106453. {1, {0,0}, {1}, {1}, 1,{0},{1}}
  106454. };
  106455. /*** Start of inlined file: setup_44.h ***/
  106456. /*** Start of inlined file: floor_all.h ***/
  106457. /*** Start of inlined file: floor_books.h ***/
  106458. static long _huff_lengthlist_line_256x7_0sub1[] = {
  106459. 0, 2, 3, 3, 3, 3, 4, 3, 4,
  106460. };
  106461. static static_codebook _huff_book_line_256x7_0sub1 = {
  106462. 1, 9,
  106463. _huff_lengthlist_line_256x7_0sub1,
  106464. 0, 0, 0, 0, 0,
  106465. NULL,
  106466. NULL,
  106467. NULL,
  106468. NULL,
  106469. 0
  106470. };
  106471. static long _huff_lengthlist_line_256x7_0sub2[] = {
  106472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 3, 4, 3, 5, 3,
  106473. 6, 3, 6, 4, 6, 4, 7, 5, 7,
  106474. };
  106475. static static_codebook _huff_book_line_256x7_0sub2 = {
  106476. 1, 25,
  106477. _huff_lengthlist_line_256x7_0sub2,
  106478. 0, 0, 0, 0, 0,
  106479. NULL,
  106480. NULL,
  106481. NULL,
  106482. NULL,
  106483. 0
  106484. };
  106485. static long _huff_lengthlist_line_256x7_0sub3[] = {
  106486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 2, 5, 3, 5, 3,
  106488. 6, 3, 6, 4, 7, 6, 7, 8, 7, 9, 8, 9, 9, 9,10, 9,
  106489. 11,13,11,13,10,10,13,13,13,13,13,13,12,12,12,12,
  106490. };
  106491. static static_codebook _huff_book_line_256x7_0sub3 = {
  106492. 1, 64,
  106493. _huff_lengthlist_line_256x7_0sub3,
  106494. 0, 0, 0, 0, 0,
  106495. NULL,
  106496. NULL,
  106497. NULL,
  106498. NULL,
  106499. 0
  106500. };
  106501. static long _huff_lengthlist_line_256x7_1sub1[] = {
  106502. 0, 3, 3, 3, 3, 2, 4, 3, 4,
  106503. };
  106504. static static_codebook _huff_book_line_256x7_1sub1 = {
  106505. 1, 9,
  106506. _huff_lengthlist_line_256x7_1sub1,
  106507. 0, 0, 0, 0, 0,
  106508. NULL,
  106509. NULL,
  106510. NULL,
  106511. NULL,
  106512. 0
  106513. };
  106514. static long _huff_lengthlist_line_256x7_1sub2[] = {
  106515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 3, 4, 3, 4, 4,
  106516. 5, 4, 6, 5, 6, 7, 6, 8, 8,
  106517. };
  106518. static static_codebook _huff_book_line_256x7_1sub2 = {
  106519. 1, 25,
  106520. _huff_lengthlist_line_256x7_1sub2,
  106521. 0, 0, 0, 0, 0,
  106522. NULL,
  106523. NULL,
  106524. NULL,
  106525. NULL,
  106526. 0
  106527. };
  106528. static long _huff_lengthlist_line_256x7_1sub3[] = {
  106529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 2, 4, 3, 6, 3, 7,
  106531. 3, 8, 5, 8, 6, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  106532. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7,
  106533. };
  106534. static static_codebook _huff_book_line_256x7_1sub3 = {
  106535. 1, 64,
  106536. _huff_lengthlist_line_256x7_1sub3,
  106537. 0, 0, 0, 0, 0,
  106538. NULL,
  106539. NULL,
  106540. NULL,
  106541. NULL,
  106542. 0
  106543. };
  106544. static long _huff_lengthlist_line_256x7_class0[] = {
  106545. 7, 5, 5, 9, 9, 6, 6, 9,12, 8, 7, 8,11, 8, 9,15,
  106546. 6, 3, 3, 7, 7, 4, 3, 6, 9, 6, 5, 6, 8, 6, 8,15,
  106547. 8, 5, 5, 9, 8, 5, 4, 6,10, 7, 5, 5,11, 8, 7,15,
  106548. 14,15,13,13,13,13, 8,11,15,10, 7, 6,11, 9,10,15,
  106549. };
  106550. static static_codebook _huff_book_line_256x7_class0 = {
  106551. 1, 64,
  106552. _huff_lengthlist_line_256x7_class0,
  106553. 0, 0, 0, 0, 0,
  106554. NULL,
  106555. NULL,
  106556. NULL,
  106557. NULL,
  106558. 0
  106559. };
  106560. static long _huff_lengthlist_line_256x7_class1[] = {
  106561. 5, 6, 8,15, 6, 9,10,15,10,11,12,15,15,15,15,15,
  106562. 4, 6, 7,15, 6, 7, 8,15, 9, 8, 9,15,15,15,15,15,
  106563. 6, 8, 9,15, 7, 7, 8,15,10, 9,10,15,15,15,15,15,
  106564. 15,13,15,15,15,10,11,15,15,13,13,15,15,15,15,15,
  106565. 4, 6, 7,15, 6, 8, 9,15,10,10,12,15,15,15,15,15,
  106566. 2, 5, 6,15, 5, 6, 7,15, 8, 6, 7,15,15,15,15,15,
  106567. 5, 6, 8,15, 5, 6, 7,15, 9, 6, 7,15,15,15,15,15,
  106568. 14,12,13,15,12,10,11,15,15,15,15,15,15,15,15,15,
  106569. 7, 8, 9,15, 9,10,10,15,15,14,14,15,15,15,15,15,
  106570. 5, 6, 7,15, 7, 8, 9,15,12, 9,10,15,15,15,15,15,
  106571. 7, 7, 9,15, 7, 7, 8,15,12, 8, 9,15,15,15,15,15,
  106572. 13,13,14,15,12,11,12,15,15,15,15,15,15,15,15,15,
  106573. 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
  106574. 13,13,13,15,15,15,15,15,15,15,15,15,15,15,15,15,
  106575. 15,12,13,15,15,12,13,15,15,14,15,15,15,15,15,15,
  106576. 15,15,15,15,15,15,13,15,15,15,15,15,15,15,15,15,
  106577. };
  106578. static static_codebook _huff_book_line_256x7_class1 = {
  106579. 1, 256,
  106580. _huff_lengthlist_line_256x7_class1,
  106581. 0, 0, 0, 0, 0,
  106582. NULL,
  106583. NULL,
  106584. NULL,
  106585. NULL,
  106586. 0
  106587. };
  106588. static long _huff_lengthlist_line_512x17_0sub0[] = {
  106589. 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  106590. 5, 6, 5, 6, 6, 6, 6, 5, 6, 6, 7, 6, 7, 6, 7, 6,
  106591. 7, 6, 8, 7, 8, 7, 8, 7, 8, 7, 8, 7, 9, 7, 9, 7,
  106592. 9, 7, 9, 8, 9, 8,10, 8,10, 8,10, 7,10, 6,10, 8,
  106593. 10, 8,11, 7,10, 7,11, 8,11,11,12,12,11,11,12,11,
  106594. 13,11,13,11,13,12,15,12,13,13,14,14,14,14,14,15,
  106595. 15,15,16,14,17,19,19,18,18,18,18,18,18,18,18,18,
  106596. 18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,
  106597. };
  106598. static static_codebook _huff_book_line_512x17_0sub0 = {
  106599. 1, 128,
  106600. _huff_lengthlist_line_512x17_0sub0,
  106601. 0, 0, 0, 0, 0,
  106602. NULL,
  106603. NULL,
  106604. NULL,
  106605. NULL,
  106606. 0
  106607. };
  106608. static long _huff_lengthlist_line_512x17_1sub0[] = {
  106609. 2, 4, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 6, 5,
  106610. 6, 5, 6, 6, 7, 6, 7, 6, 8, 7, 8, 7, 8, 7, 8, 7,
  106611. };
  106612. static static_codebook _huff_book_line_512x17_1sub0 = {
  106613. 1, 32,
  106614. _huff_lengthlist_line_512x17_1sub0,
  106615. 0, 0, 0, 0, 0,
  106616. NULL,
  106617. NULL,
  106618. NULL,
  106619. NULL,
  106620. 0
  106621. };
  106622. static long _huff_lengthlist_line_512x17_1sub1[] = {
  106623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106625. 4, 3, 5, 3, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 6, 5,
  106626. 6, 5, 7, 5, 8, 6, 8, 6, 8, 6, 8, 6, 8, 7, 9, 7,
  106627. 9, 7,11, 9,11,11,12,11,14,12,14,16,14,16,13,16,
  106628. 14,16,12,15,13,16,14,16,13,14,12,15,13,15,13,13,
  106629. 13,15,12,14,14,15,13,15,12,15,15,15,15,15,15,15,
  106630. 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
  106631. };
  106632. static static_codebook _huff_book_line_512x17_1sub1 = {
  106633. 1, 128,
  106634. _huff_lengthlist_line_512x17_1sub1,
  106635. 0, 0, 0, 0, 0,
  106636. NULL,
  106637. NULL,
  106638. NULL,
  106639. NULL,
  106640. 0
  106641. };
  106642. static long _huff_lengthlist_line_512x17_2sub1[] = {
  106643. 0, 4, 5, 4, 4, 4, 5, 4, 4, 4, 5, 4, 5, 4, 5, 3,
  106644. 5, 3,
  106645. };
  106646. static static_codebook _huff_book_line_512x17_2sub1 = {
  106647. 1, 18,
  106648. _huff_lengthlist_line_512x17_2sub1,
  106649. 0, 0, 0, 0, 0,
  106650. NULL,
  106651. NULL,
  106652. NULL,
  106653. NULL,
  106654. 0
  106655. };
  106656. static long _huff_lengthlist_line_512x17_2sub2[] = {
  106657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106658. 0, 0, 4, 3, 4, 3, 4, 4, 5, 4, 5, 4, 6, 4, 6, 5,
  106659. 6, 5, 7, 5, 7, 6, 8, 6, 8, 6, 8, 7, 8, 7, 9, 7,
  106660. 9, 8,
  106661. };
  106662. static static_codebook _huff_book_line_512x17_2sub2 = {
  106663. 1, 50,
  106664. _huff_lengthlist_line_512x17_2sub2,
  106665. 0, 0, 0, 0, 0,
  106666. NULL,
  106667. NULL,
  106668. NULL,
  106669. NULL,
  106670. 0
  106671. };
  106672. static long _huff_lengthlist_line_512x17_2sub3[] = {
  106673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106676. 0, 0, 3, 3, 3, 3, 4, 3, 4, 4, 5, 5, 6, 6, 7, 7,
  106677. 7, 8, 8,11, 8, 9, 9, 9,10,11,11,11, 9,10,10,11,
  106678. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,
  106679. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  106680. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  106681. };
  106682. static static_codebook _huff_book_line_512x17_2sub3 = {
  106683. 1, 128,
  106684. _huff_lengthlist_line_512x17_2sub3,
  106685. 0, 0, 0, 0, 0,
  106686. NULL,
  106687. NULL,
  106688. NULL,
  106689. NULL,
  106690. 0
  106691. };
  106692. static long _huff_lengthlist_line_512x17_3sub1[] = {
  106693. 0, 4, 4, 4, 4, 4, 4, 3, 4, 4, 4, 4, 4, 5, 4, 5,
  106694. 5, 5,
  106695. };
  106696. static static_codebook _huff_book_line_512x17_3sub1 = {
  106697. 1, 18,
  106698. _huff_lengthlist_line_512x17_3sub1,
  106699. 0, 0, 0, 0, 0,
  106700. NULL,
  106701. NULL,
  106702. NULL,
  106703. NULL,
  106704. 0
  106705. };
  106706. static long _huff_lengthlist_line_512x17_3sub2[] = {
  106707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106708. 0, 0, 2, 3, 3, 4, 3, 5, 4, 6, 4, 6, 5, 7, 6, 7,
  106709. 6, 8, 6, 8, 7, 9, 8,10, 8,12, 9,13,10,15,10,15,
  106710. 11,14,
  106711. };
  106712. static static_codebook _huff_book_line_512x17_3sub2 = {
  106713. 1, 50,
  106714. _huff_lengthlist_line_512x17_3sub2,
  106715. 0, 0, 0, 0, 0,
  106716. NULL,
  106717. NULL,
  106718. NULL,
  106719. NULL,
  106720. 0
  106721. };
  106722. static long _huff_lengthlist_line_512x17_3sub3[] = {
  106723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106726. 0, 0, 4, 8, 4, 8, 4, 8, 4, 8, 5, 8, 5, 8, 6, 8,
  106727. 4, 8, 4, 8, 5, 8, 5, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  106728. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  106729. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  106730. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  106731. };
  106732. static static_codebook _huff_book_line_512x17_3sub3 = {
  106733. 1, 128,
  106734. _huff_lengthlist_line_512x17_3sub3,
  106735. 0, 0, 0, 0, 0,
  106736. NULL,
  106737. NULL,
  106738. NULL,
  106739. NULL,
  106740. 0
  106741. };
  106742. static long _huff_lengthlist_line_512x17_class1[] = {
  106743. 1, 2, 3, 6, 5, 4, 7, 7,
  106744. };
  106745. static static_codebook _huff_book_line_512x17_class1 = {
  106746. 1, 8,
  106747. _huff_lengthlist_line_512x17_class1,
  106748. 0, 0, 0, 0, 0,
  106749. NULL,
  106750. NULL,
  106751. NULL,
  106752. NULL,
  106753. 0
  106754. };
  106755. static long _huff_lengthlist_line_512x17_class2[] = {
  106756. 3, 3, 3,14, 5, 4, 4,11, 8, 6, 6,10,17,12,11,17,
  106757. 6, 5, 5,15, 5, 3, 4,11, 8, 5, 5, 8,16, 9,10,14,
  106758. 10, 8, 9,17, 8, 6, 6,13,10, 7, 7,10,16,11,13,14,
  106759. 17,17,17,17,17,16,16,16,16,15,16,16,16,16,16,16,
  106760. };
  106761. static static_codebook _huff_book_line_512x17_class2 = {
  106762. 1, 64,
  106763. _huff_lengthlist_line_512x17_class2,
  106764. 0, 0, 0, 0, 0,
  106765. NULL,
  106766. NULL,
  106767. NULL,
  106768. NULL,
  106769. 0
  106770. };
  106771. static long _huff_lengthlist_line_512x17_class3[] = {
  106772. 2, 4, 6,17, 4, 5, 7,17, 8, 7,10,17,17,17,17,17,
  106773. 3, 4, 6,15, 3, 3, 6,15, 7, 6, 9,17,17,17,17,17,
  106774. 6, 8,10,17, 6, 6, 8,16, 9, 8,10,17,17,15,16,17,
  106775. 17,17,17,17,12,15,15,16,12,15,15,16,16,16,16,16,
  106776. };
  106777. static static_codebook _huff_book_line_512x17_class3 = {
  106778. 1, 64,
  106779. _huff_lengthlist_line_512x17_class3,
  106780. 0, 0, 0, 0, 0,
  106781. NULL,
  106782. NULL,
  106783. NULL,
  106784. NULL,
  106785. 0
  106786. };
  106787. static long _huff_lengthlist_line_128x4_class0[] = {
  106788. 7, 7, 7,11, 6, 6, 7,11, 7, 6, 6,10,12,10,10,13,
  106789. 7, 7, 8,11, 7, 7, 7,11, 7, 6, 7,10,11,10,10,13,
  106790. 10,10, 9,12, 9, 9, 9,11, 8, 8, 8,11,13,11,10,14,
  106791. 15,15,14,15,15,14,13,14,15,12,12,17,17,17,17,17,
  106792. 7, 7, 6, 9, 6, 6, 6, 9, 7, 6, 6, 8,11,11,10,12,
  106793. 7, 7, 7, 9, 7, 6, 6, 9, 7, 6, 6, 9,13,10,10,11,
  106794. 10, 9, 8,10, 9, 8, 8,10, 8, 8, 7, 9,13,12,10,11,
  106795. 17,14,14,13,15,14,12,13,17,13,12,15,17,17,14,17,
  106796. 7, 6, 6, 7, 6, 6, 5, 7, 6, 6, 6, 6,11, 9, 9, 9,
  106797. 7, 7, 6, 7, 7, 6, 6, 7, 6, 6, 6, 6,10, 9, 8, 9,
  106798. 10, 9, 8, 8, 9, 8, 7, 8, 8, 7, 6, 8,11,10, 9,10,
  106799. 17,17,12,15,15,15,12,14,14,14,10,12,15,13,12,13,
  106800. 11,10, 8,10,11,10, 8, 8,10, 9, 7, 7,10, 9, 9,11,
  106801. 11,11, 9,10,11,10, 8, 9,10, 8, 6, 8,10, 9, 9,11,
  106802. 14,13,10,12,12,11,10,10, 8, 7, 8,10,10,11,11,12,
  106803. 17,17,15,17,17,17,17,17,17,13,12,17,17,17,14,17,
  106804. };
  106805. static static_codebook _huff_book_line_128x4_class0 = {
  106806. 1, 256,
  106807. _huff_lengthlist_line_128x4_class0,
  106808. 0, 0, 0, 0, 0,
  106809. NULL,
  106810. NULL,
  106811. NULL,
  106812. NULL,
  106813. 0
  106814. };
  106815. static long _huff_lengthlist_line_128x4_0sub0[] = {
  106816. 2, 2, 2, 2,
  106817. };
  106818. static static_codebook _huff_book_line_128x4_0sub0 = {
  106819. 1, 4,
  106820. _huff_lengthlist_line_128x4_0sub0,
  106821. 0, 0, 0, 0, 0,
  106822. NULL,
  106823. NULL,
  106824. NULL,
  106825. NULL,
  106826. 0
  106827. };
  106828. static long _huff_lengthlist_line_128x4_0sub1[] = {
  106829. 0, 0, 0, 0, 3, 2, 3, 2, 3, 3,
  106830. };
  106831. static static_codebook _huff_book_line_128x4_0sub1 = {
  106832. 1, 10,
  106833. _huff_lengthlist_line_128x4_0sub1,
  106834. 0, 0, 0, 0, 0,
  106835. NULL,
  106836. NULL,
  106837. NULL,
  106838. NULL,
  106839. 0
  106840. };
  106841. static long _huff_lengthlist_line_128x4_0sub2[] = {
  106842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 4, 3, 4, 3,
  106843. 4, 4, 5, 4, 5, 4, 6, 5, 6,
  106844. };
  106845. static static_codebook _huff_book_line_128x4_0sub2 = {
  106846. 1, 25,
  106847. _huff_lengthlist_line_128x4_0sub2,
  106848. 0, 0, 0, 0, 0,
  106849. NULL,
  106850. NULL,
  106851. NULL,
  106852. NULL,
  106853. 0
  106854. };
  106855. static long _huff_lengthlist_line_128x4_0sub3[] = {
  106856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 3, 5, 3, 5, 3,
  106858. 5, 4, 6, 5, 6, 5, 7, 6, 6, 7, 7, 9, 9,11,11,16,
  106859. 11,14,10,11,11,13,16,15,15,15,15,15,15,15,15,15,
  106860. };
  106861. static static_codebook _huff_book_line_128x4_0sub3 = {
  106862. 1, 64,
  106863. _huff_lengthlist_line_128x4_0sub3,
  106864. 0, 0, 0, 0, 0,
  106865. NULL,
  106866. NULL,
  106867. NULL,
  106868. NULL,
  106869. 0
  106870. };
  106871. static long _huff_lengthlist_line_256x4_class0[] = {
  106872. 6, 7, 7,12, 6, 6, 7,12, 7, 6, 6,10,15,12,11,13,
  106873. 7, 7, 8,13, 7, 7, 8,12, 7, 7, 7,11,12,12,11,13,
  106874. 10, 9, 9,11, 9, 9, 9,10,10, 8, 8,12,14,12,12,14,
  106875. 11,11,12,14,11,12,11,15,15,12,13,15,15,15,15,15,
  106876. 6, 6, 7,10, 6, 6, 6,11, 7, 6, 6, 9,14,12,11,13,
  106877. 7, 7, 7,10, 6, 6, 7, 9, 7, 7, 6,10,13,12,10,12,
  106878. 9, 9, 9,11, 9, 9, 8, 9, 9, 8, 8,10,13,12,10,12,
  106879. 12,12,11,13,12,12,11,12,15,13,12,15,15,15,14,14,
  106880. 6, 6, 6, 8, 6, 6, 5, 6, 7, 7, 6, 5,11,10, 9, 8,
  106881. 7, 6, 6, 7, 6, 6, 5, 6, 7, 7, 6, 6,11,10, 9, 8,
  106882. 8, 8, 8, 9, 8, 8, 7, 8, 8, 8, 6, 7,11,10, 9, 9,
  106883. 14,11,10,14,14,11,10,15,13,11, 9,11,15,12,12,11,
  106884. 11, 9, 8, 8,10, 9, 8, 9,11,10, 9, 8,12,11,12,11,
  106885. 13,10, 8, 9,11,10, 8, 9,10, 9, 8, 9,10, 8,12,12,
  106886. 15,11,10,10,13,11,10,10, 8, 8, 7,12,10, 9,11,12,
  106887. 15,12,11,15,13,11,11,15,12,14,11,13,15,15,13,13,
  106888. };
  106889. static static_codebook _huff_book_line_256x4_class0 = {
  106890. 1, 256,
  106891. _huff_lengthlist_line_256x4_class0,
  106892. 0, 0, 0, 0, 0,
  106893. NULL,
  106894. NULL,
  106895. NULL,
  106896. NULL,
  106897. 0
  106898. };
  106899. static long _huff_lengthlist_line_256x4_0sub0[] = {
  106900. 2, 2, 2, 2,
  106901. };
  106902. static static_codebook _huff_book_line_256x4_0sub0 = {
  106903. 1, 4,
  106904. _huff_lengthlist_line_256x4_0sub0,
  106905. 0, 0, 0, 0, 0,
  106906. NULL,
  106907. NULL,
  106908. NULL,
  106909. NULL,
  106910. 0
  106911. };
  106912. static long _huff_lengthlist_line_256x4_0sub1[] = {
  106913. 0, 0, 0, 0, 2, 2, 3, 3, 3, 3,
  106914. };
  106915. static static_codebook _huff_book_line_256x4_0sub1 = {
  106916. 1, 10,
  106917. _huff_lengthlist_line_256x4_0sub1,
  106918. 0, 0, 0, 0, 0,
  106919. NULL,
  106920. NULL,
  106921. NULL,
  106922. NULL,
  106923. 0
  106924. };
  106925. static long _huff_lengthlist_line_256x4_0sub2[] = {
  106926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 3, 4, 3, 4, 3,
  106927. 5, 3, 5, 4, 5, 4, 6, 4, 6,
  106928. };
  106929. static static_codebook _huff_book_line_256x4_0sub2 = {
  106930. 1, 25,
  106931. _huff_lengthlist_line_256x4_0sub2,
  106932. 0, 0, 0, 0, 0,
  106933. NULL,
  106934. NULL,
  106935. NULL,
  106936. NULL,
  106937. 0
  106938. };
  106939. static long _huff_lengthlist_line_256x4_0sub3[] = {
  106940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 3, 5, 3, 5, 3,
  106942. 6, 4, 7, 4, 7, 5, 7, 6, 7, 6, 7, 8,10,13,13,13,
  106943. 13,13,13,13,13,13,13,13,13,13,13,12,12,12,12,12,
  106944. };
  106945. static static_codebook _huff_book_line_256x4_0sub3 = {
  106946. 1, 64,
  106947. _huff_lengthlist_line_256x4_0sub3,
  106948. 0, 0, 0, 0, 0,
  106949. NULL,
  106950. NULL,
  106951. NULL,
  106952. NULL,
  106953. 0
  106954. };
  106955. static long _huff_lengthlist_line_128x7_class0[] = {
  106956. 10, 7, 8,13, 9, 6, 7,11,10, 8, 8,12,17,17,17,17,
  106957. 7, 5, 5, 9, 6, 4, 4, 8, 8, 5, 5, 8,16,14,13,16,
  106958. 7, 5, 5, 7, 6, 3, 3, 5, 8, 5, 4, 7,14,12,12,15,
  106959. 10, 7, 8, 9, 7, 5, 5, 6, 9, 6, 5, 5,15,12, 9,10,
  106960. };
  106961. static static_codebook _huff_book_line_128x7_class0 = {
  106962. 1, 64,
  106963. _huff_lengthlist_line_128x7_class0,
  106964. 0, 0, 0, 0, 0,
  106965. NULL,
  106966. NULL,
  106967. NULL,
  106968. NULL,
  106969. 0
  106970. };
  106971. static long _huff_lengthlist_line_128x7_class1[] = {
  106972. 8,13,17,17, 8,11,17,17,11,13,17,17,17,17,17,17,
  106973. 6,10,16,17, 6,10,15,17, 8,10,16,17,17,17,17,17,
  106974. 9,13,15,17, 8,11,17,17,10,12,17,17,17,17,17,17,
  106975. 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
  106976. 6,11,15,17, 7,10,15,17, 8,10,17,17,17,15,17,17,
  106977. 4, 8,13,17, 4, 7,13,17, 6, 8,15,17,16,15,17,17,
  106978. 6,11,15,17, 6, 9,13,17, 8,10,17,17,15,17,17,17,
  106979. 16,17,17,17,12,14,15,17,13,14,15,17,17,17,17,17,
  106980. 5,10,14,17, 5, 9,14,17, 7, 9,15,17,15,15,17,17,
  106981. 3, 7,12,17, 3, 6,11,17, 5, 7,13,17,12,12,17,17,
  106982. 5, 9,14,17, 3, 7,11,17, 5, 8,13,17,13,11,16,17,
  106983. 12,17,17,17, 9,14,15,17,10,11,14,17,16,14,17,17,
  106984. 8,12,17,17, 8,12,17,17,10,12,17,17,17,17,17,17,
  106985. 5,10,17,17, 5, 9,15,17, 7, 9,17,17,13,13,17,17,
  106986. 7,11,17,17, 6,10,15,17, 7, 9,15,17,12,11,17,17,
  106987. 12,15,17,17,11,14,17,17,11,10,15,17,17,16,17,17,
  106988. };
  106989. static static_codebook _huff_book_line_128x7_class1 = {
  106990. 1, 256,
  106991. _huff_lengthlist_line_128x7_class1,
  106992. 0, 0, 0, 0, 0,
  106993. NULL,
  106994. NULL,
  106995. NULL,
  106996. NULL,
  106997. 0
  106998. };
  106999. static long _huff_lengthlist_line_128x7_0sub1[] = {
  107000. 0, 3, 3, 3, 3, 3, 3, 3, 3,
  107001. };
  107002. static static_codebook _huff_book_line_128x7_0sub1 = {
  107003. 1, 9,
  107004. _huff_lengthlist_line_128x7_0sub1,
  107005. 0, 0, 0, 0, 0,
  107006. NULL,
  107007. NULL,
  107008. NULL,
  107009. NULL,
  107010. 0
  107011. };
  107012. static long _huff_lengthlist_line_128x7_0sub2[] = {
  107013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 4, 4, 4, 4,
  107014. 5, 4, 5, 4, 5, 4, 6, 4, 6,
  107015. };
  107016. static static_codebook _huff_book_line_128x7_0sub2 = {
  107017. 1, 25,
  107018. _huff_lengthlist_line_128x7_0sub2,
  107019. 0, 0, 0, 0, 0,
  107020. NULL,
  107021. NULL,
  107022. NULL,
  107023. NULL,
  107024. 0
  107025. };
  107026. static long _huff_lengthlist_line_128x7_0sub3[] = {
  107027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 3, 5, 3, 5, 4,
  107029. 5, 4, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107030. 7, 8, 9,11,13,13,13,13,13,13,13,13,13,13,13,13,
  107031. };
  107032. static static_codebook _huff_book_line_128x7_0sub3 = {
  107033. 1, 64,
  107034. _huff_lengthlist_line_128x7_0sub3,
  107035. 0, 0, 0, 0, 0,
  107036. NULL,
  107037. NULL,
  107038. NULL,
  107039. NULL,
  107040. 0
  107041. };
  107042. static long _huff_lengthlist_line_128x7_1sub1[] = {
  107043. 0, 3, 3, 2, 3, 3, 4, 3, 4,
  107044. };
  107045. static static_codebook _huff_book_line_128x7_1sub1 = {
  107046. 1, 9,
  107047. _huff_lengthlist_line_128x7_1sub1,
  107048. 0, 0, 0, 0, 0,
  107049. NULL,
  107050. NULL,
  107051. NULL,
  107052. NULL,
  107053. 0
  107054. };
  107055. static long _huff_lengthlist_line_128x7_1sub2[] = {
  107056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 3, 6, 3, 6, 3,
  107057. 6, 3, 7, 3, 8, 4, 9, 4, 9,
  107058. };
  107059. static static_codebook _huff_book_line_128x7_1sub2 = {
  107060. 1, 25,
  107061. _huff_lengthlist_line_128x7_1sub2,
  107062. 0, 0, 0, 0, 0,
  107063. NULL,
  107064. NULL,
  107065. NULL,
  107066. NULL,
  107067. 0
  107068. };
  107069. static long _huff_lengthlist_line_128x7_1sub3[] = {
  107070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 7, 2, 7, 3, 8, 4,
  107072. 9, 5, 9, 8,10,11,11,12,14,14,14,14,14,14,14,14,
  107073. 14,14,14,14,14,14,14,14,14,14,14,14,13,13,13,13,
  107074. };
  107075. static static_codebook _huff_book_line_128x7_1sub3 = {
  107076. 1, 64,
  107077. _huff_lengthlist_line_128x7_1sub3,
  107078. 0, 0, 0, 0, 0,
  107079. NULL,
  107080. NULL,
  107081. NULL,
  107082. NULL,
  107083. 0
  107084. };
  107085. static long _huff_lengthlist_line_128x11_class1[] = {
  107086. 1, 6, 3, 7, 2, 4, 5, 7,
  107087. };
  107088. static static_codebook _huff_book_line_128x11_class1 = {
  107089. 1, 8,
  107090. _huff_lengthlist_line_128x11_class1,
  107091. 0, 0, 0, 0, 0,
  107092. NULL,
  107093. NULL,
  107094. NULL,
  107095. NULL,
  107096. 0
  107097. };
  107098. static long _huff_lengthlist_line_128x11_class2[] = {
  107099. 1, 6,12,16, 4,12,15,16, 9,15,16,16,16,16,16,16,
  107100. 2, 5,11,16, 5,11,13,16, 9,13,16,16,16,16,16,16,
  107101. 4, 8,12,16, 5, 9,12,16, 9,13,15,16,16,16,16,16,
  107102. 15,16,16,16,11,14,13,16,12,15,16,16,16,16,16,15,
  107103. };
  107104. static static_codebook _huff_book_line_128x11_class2 = {
  107105. 1, 64,
  107106. _huff_lengthlist_line_128x11_class2,
  107107. 0, 0, 0, 0, 0,
  107108. NULL,
  107109. NULL,
  107110. NULL,
  107111. NULL,
  107112. 0
  107113. };
  107114. static long _huff_lengthlist_line_128x11_class3[] = {
  107115. 7, 6, 9,17, 7, 6, 8,17,12, 9,11,16,16,16,16,16,
  107116. 5, 4, 7,16, 5, 3, 6,14, 9, 6, 8,15,16,16,16,16,
  107117. 5, 4, 6,13, 3, 2, 4,11, 7, 4, 6,13,16,11,10,14,
  107118. 12,12,12,16, 9, 7,10,15,12, 9,11,16,16,15,15,16,
  107119. };
  107120. static static_codebook _huff_book_line_128x11_class3 = {
  107121. 1, 64,
  107122. _huff_lengthlist_line_128x11_class3,
  107123. 0, 0, 0, 0, 0,
  107124. NULL,
  107125. NULL,
  107126. NULL,
  107127. NULL,
  107128. 0
  107129. };
  107130. static long _huff_lengthlist_line_128x11_0sub0[] = {
  107131. 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107132. 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 6, 6, 6, 7, 6,
  107133. 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 8, 6, 8, 6, 8, 7,
  107134. 8, 7, 8, 7, 8, 7, 9, 7, 9, 8, 9, 8, 9, 8,10, 8,
  107135. 10, 9,10, 9,10, 9,11, 9,11, 9,10,10,11,10,11,10,
  107136. 11,11,11,11,11,11,12,13,14,14,14,15,15,16,16,16,
  107137. 17,15,16,15,16,16,17,17,16,17,17,17,17,17,17,17,
  107138. 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
  107139. };
  107140. static static_codebook _huff_book_line_128x11_0sub0 = {
  107141. 1, 128,
  107142. _huff_lengthlist_line_128x11_0sub0,
  107143. 0, 0, 0, 0, 0,
  107144. NULL,
  107145. NULL,
  107146. NULL,
  107147. NULL,
  107148. 0
  107149. };
  107150. static long _huff_lengthlist_line_128x11_1sub0[] = {
  107151. 2, 5, 5, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5, 5, 5, 5,
  107152. 6, 5, 6, 5, 6, 5, 7, 6, 7, 6, 7, 6, 8, 6, 8, 6,
  107153. };
  107154. static static_codebook _huff_book_line_128x11_1sub0 = {
  107155. 1, 32,
  107156. _huff_lengthlist_line_128x11_1sub0,
  107157. 0, 0, 0, 0, 0,
  107158. NULL,
  107159. NULL,
  107160. NULL,
  107161. NULL,
  107162. 0
  107163. };
  107164. static long _huff_lengthlist_line_128x11_1sub1[] = {
  107165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107167. 5, 3, 5, 3, 6, 4, 6, 4, 7, 4, 7, 4, 7, 4, 8, 4,
  107168. 8, 4, 9, 5, 9, 5, 9, 5, 9, 6,10, 6,10, 6,11, 7,
  107169. 10, 7,10, 8,11, 9,11, 9,11,10,11,11,12,11,11,12,
  107170. 15,15,12,14,11,14,12,14,11,14,13,14,12,14,11,14,
  107171. 11,14,12,14,11,14,11,14,13,13,14,14,14,14,14,14,
  107172. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  107173. };
  107174. static static_codebook _huff_book_line_128x11_1sub1 = {
  107175. 1, 128,
  107176. _huff_lengthlist_line_128x11_1sub1,
  107177. 0, 0, 0, 0, 0,
  107178. NULL,
  107179. NULL,
  107180. NULL,
  107181. NULL,
  107182. 0
  107183. };
  107184. static long _huff_lengthlist_line_128x11_2sub1[] = {
  107185. 0, 4, 5, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4, 4, 4,
  107186. 5, 5,
  107187. };
  107188. static static_codebook _huff_book_line_128x11_2sub1 = {
  107189. 1, 18,
  107190. _huff_lengthlist_line_128x11_2sub1,
  107191. 0, 0, 0, 0, 0,
  107192. NULL,
  107193. NULL,
  107194. NULL,
  107195. NULL,
  107196. 0
  107197. };
  107198. static long _huff_lengthlist_line_128x11_2sub2[] = {
  107199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107200. 0, 0, 3, 3, 3, 4, 4, 4, 4, 5, 4, 5, 4, 6, 5, 7,
  107201. 5, 7, 6, 8, 6, 8, 6, 9, 7, 9, 7,10, 7, 9, 8,11,
  107202. 8,11,
  107203. };
  107204. static static_codebook _huff_book_line_128x11_2sub2 = {
  107205. 1, 50,
  107206. _huff_lengthlist_line_128x11_2sub2,
  107207. 0, 0, 0, 0, 0,
  107208. NULL,
  107209. NULL,
  107210. NULL,
  107211. NULL,
  107212. 0
  107213. };
  107214. static long _huff_lengthlist_line_128x11_2sub3[] = {
  107215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107218. 0, 0, 4, 8, 3, 8, 4, 8, 4, 8, 6, 8, 5, 8, 4, 8,
  107219. 4, 8, 6, 8, 7, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107220. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107221. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107222. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107223. };
  107224. static static_codebook _huff_book_line_128x11_2sub3 = {
  107225. 1, 128,
  107226. _huff_lengthlist_line_128x11_2sub3,
  107227. 0, 0, 0, 0, 0,
  107228. NULL,
  107229. NULL,
  107230. NULL,
  107231. NULL,
  107232. 0
  107233. };
  107234. static long _huff_lengthlist_line_128x11_3sub1[] = {
  107235. 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 4,
  107236. 5, 4,
  107237. };
  107238. static static_codebook _huff_book_line_128x11_3sub1 = {
  107239. 1, 18,
  107240. _huff_lengthlist_line_128x11_3sub1,
  107241. 0, 0, 0, 0, 0,
  107242. NULL,
  107243. NULL,
  107244. NULL,
  107245. NULL,
  107246. 0
  107247. };
  107248. static long _huff_lengthlist_line_128x11_3sub2[] = {
  107249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107250. 0, 0, 5, 3, 5, 4, 6, 4, 6, 4, 7, 4, 7, 4, 8, 4,
  107251. 8, 4, 9, 4, 9, 4,10, 4,10, 5,10, 5,11, 5,12, 6,
  107252. 12, 6,
  107253. };
  107254. static static_codebook _huff_book_line_128x11_3sub2 = {
  107255. 1, 50,
  107256. _huff_lengthlist_line_128x11_3sub2,
  107257. 0, 0, 0, 0, 0,
  107258. NULL,
  107259. NULL,
  107260. NULL,
  107261. NULL,
  107262. 0
  107263. };
  107264. static long _huff_lengthlist_line_128x11_3sub3[] = {
  107265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107268. 0, 0, 7, 1, 6, 3, 7, 3, 8, 4, 8, 5, 8, 8, 8, 9,
  107269. 7, 8, 8, 7, 7, 7, 8, 9,10, 9, 9,10,10,10,10,10,
  107270. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  107271. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  107272. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9,
  107273. };
  107274. static static_codebook _huff_book_line_128x11_3sub3 = {
  107275. 1, 128,
  107276. _huff_lengthlist_line_128x11_3sub3,
  107277. 0, 0, 0, 0, 0,
  107278. NULL,
  107279. NULL,
  107280. NULL,
  107281. NULL,
  107282. 0
  107283. };
  107284. static long _huff_lengthlist_line_128x17_class1[] = {
  107285. 1, 3, 4, 7, 2, 5, 6, 7,
  107286. };
  107287. static static_codebook _huff_book_line_128x17_class1 = {
  107288. 1, 8,
  107289. _huff_lengthlist_line_128x17_class1,
  107290. 0, 0, 0, 0, 0,
  107291. NULL,
  107292. NULL,
  107293. NULL,
  107294. NULL,
  107295. 0
  107296. };
  107297. static long _huff_lengthlist_line_128x17_class2[] = {
  107298. 1, 4,10,19, 3, 8,13,19, 7,12,19,19,19,19,19,19,
  107299. 2, 6,11,19, 8,13,19,19, 9,11,19,19,19,19,19,19,
  107300. 6, 7,13,19, 9,13,19,19,10,13,18,18,18,18,18,18,
  107301. 18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,
  107302. };
  107303. static static_codebook _huff_book_line_128x17_class2 = {
  107304. 1, 64,
  107305. _huff_lengthlist_line_128x17_class2,
  107306. 0, 0, 0, 0, 0,
  107307. NULL,
  107308. NULL,
  107309. NULL,
  107310. NULL,
  107311. 0
  107312. };
  107313. static long _huff_lengthlist_line_128x17_class3[] = {
  107314. 3, 6,10,17, 4, 8,11,20, 8,10,11,20,20,20,20,20,
  107315. 2, 4, 8,18, 4, 6, 8,17, 7, 8,10,20,20,17,20,20,
  107316. 3, 5, 8,17, 3, 4, 6,17, 8, 8,10,17,17,12,16,20,
  107317. 13,13,15,20,10,10,12,20,15,14,15,20,20,20,19,19,
  107318. };
  107319. static static_codebook _huff_book_line_128x17_class3 = {
  107320. 1, 64,
  107321. _huff_lengthlist_line_128x17_class3,
  107322. 0, 0, 0, 0, 0,
  107323. NULL,
  107324. NULL,
  107325. NULL,
  107326. NULL,
  107327. 0
  107328. };
  107329. static long _huff_lengthlist_line_128x17_0sub0[] = {
  107330. 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107331. 7, 5, 7, 5, 7, 5, 7, 5, 7, 5, 7, 5, 8, 5, 8, 5,
  107332. 8, 5, 8, 5, 8, 6, 8, 6, 8, 6, 9, 6, 9, 6, 9, 6,
  107333. 9, 6, 9, 7, 9, 7, 9, 7, 9, 7,10, 7,10, 8,10, 8,
  107334. 10, 8,10, 8,10, 8,11, 8,11, 8,11, 8,11, 8,11, 9,
  107335. 12, 9,12, 9,12, 9,12, 9,12,10,12,10,13,11,13,11,
  107336. 14,12,14,13,15,14,16,14,17,15,18,16,20,20,20,20,
  107337. 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
  107338. };
  107339. static static_codebook _huff_book_line_128x17_0sub0 = {
  107340. 1, 128,
  107341. _huff_lengthlist_line_128x17_0sub0,
  107342. 0, 0, 0, 0, 0,
  107343. NULL,
  107344. NULL,
  107345. NULL,
  107346. NULL,
  107347. 0
  107348. };
  107349. static long _huff_lengthlist_line_128x17_1sub0[] = {
  107350. 2, 5, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 6, 5,
  107351. 6, 5, 6, 5, 7, 6, 7, 6, 7, 6, 8, 6, 9, 7, 9, 7,
  107352. };
  107353. static static_codebook _huff_book_line_128x17_1sub0 = {
  107354. 1, 32,
  107355. _huff_lengthlist_line_128x17_1sub0,
  107356. 0, 0, 0, 0, 0,
  107357. NULL,
  107358. NULL,
  107359. NULL,
  107360. NULL,
  107361. 0
  107362. };
  107363. static long _huff_lengthlist_line_128x17_1sub1[] = {
  107364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107366. 4, 3, 5, 3, 5, 3, 6, 3, 6, 4, 6, 4, 7, 4, 7, 5,
  107367. 8, 5, 8, 6, 9, 7, 9, 7, 9, 8,10, 9,10, 9,11,10,
  107368. 11,11,11,11,11,11,12,12,12,13,12,13,12,14,12,15,
  107369. 12,14,12,16,13,17,13,17,14,17,14,16,13,17,14,17,
  107370. 14,17,15,17,15,15,16,17,17,17,17,17,17,17,17,17,
  107371. 17,17,17,17,17,17,16,16,16,16,16,16,16,16,16,16,
  107372. };
  107373. static static_codebook _huff_book_line_128x17_1sub1 = {
  107374. 1, 128,
  107375. _huff_lengthlist_line_128x17_1sub1,
  107376. 0, 0, 0, 0, 0,
  107377. NULL,
  107378. NULL,
  107379. NULL,
  107380. NULL,
  107381. 0
  107382. };
  107383. static long _huff_lengthlist_line_128x17_2sub1[] = {
  107384. 0, 4, 5, 4, 6, 4, 8, 3, 9, 3, 9, 2, 9, 3, 8, 4,
  107385. 9, 4,
  107386. };
  107387. static static_codebook _huff_book_line_128x17_2sub1 = {
  107388. 1, 18,
  107389. _huff_lengthlist_line_128x17_2sub1,
  107390. 0, 0, 0, 0, 0,
  107391. NULL,
  107392. NULL,
  107393. NULL,
  107394. NULL,
  107395. 0
  107396. };
  107397. static long _huff_lengthlist_line_128x17_2sub2[] = {
  107398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107399. 0, 0, 5, 1, 5, 3, 5, 3, 5, 4, 7, 5,10, 7,10, 7,
  107400. 12,10,14,10,14, 9,14,11,14,14,14,13,13,13,13,13,
  107401. 13,13,
  107402. };
  107403. static static_codebook _huff_book_line_128x17_2sub2 = {
  107404. 1, 50,
  107405. _huff_lengthlist_line_128x17_2sub2,
  107406. 0, 0, 0, 0, 0,
  107407. NULL,
  107408. NULL,
  107409. NULL,
  107410. NULL,
  107411. 0
  107412. };
  107413. static long _huff_lengthlist_line_128x17_2sub3[] = {
  107414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107417. 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107418. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6,
  107419. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107420. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107421. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107422. };
  107423. static static_codebook _huff_book_line_128x17_2sub3 = {
  107424. 1, 128,
  107425. _huff_lengthlist_line_128x17_2sub3,
  107426. 0, 0, 0, 0, 0,
  107427. NULL,
  107428. NULL,
  107429. NULL,
  107430. NULL,
  107431. 0
  107432. };
  107433. static long _huff_lengthlist_line_128x17_3sub1[] = {
  107434. 0, 4, 4, 4, 4, 4, 4, 4, 5, 3, 5, 3, 5, 4, 6, 4,
  107435. 6, 4,
  107436. };
  107437. static static_codebook _huff_book_line_128x17_3sub1 = {
  107438. 1, 18,
  107439. _huff_lengthlist_line_128x17_3sub1,
  107440. 0, 0, 0, 0, 0,
  107441. NULL,
  107442. NULL,
  107443. NULL,
  107444. NULL,
  107445. 0
  107446. };
  107447. static long _huff_lengthlist_line_128x17_3sub2[] = {
  107448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107449. 0, 0, 5, 3, 6, 3, 6, 4, 7, 4, 7, 4, 7, 4, 8, 4,
  107450. 8, 4, 8, 4, 8, 4, 9, 4, 9, 5,10, 5,10, 7,10, 8,
  107451. 10, 8,
  107452. };
  107453. static static_codebook _huff_book_line_128x17_3sub2 = {
  107454. 1, 50,
  107455. _huff_lengthlist_line_128x17_3sub2,
  107456. 0, 0, 0, 0, 0,
  107457. NULL,
  107458. NULL,
  107459. NULL,
  107460. NULL,
  107461. 0
  107462. };
  107463. static long _huff_lengthlist_line_128x17_3sub3[] = {
  107464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107467. 0, 0, 3, 2, 4, 3, 4, 4, 4, 5, 4, 7, 5, 8, 5,11,
  107468. 6,10, 6,12, 7,12, 7,12, 8,12, 8,12,10,12,12,12,
  107469. 12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107470. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107471. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107472. };
  107473. static static_codebook _huff_book_line_128x17_3sub3 = {
  107474. 1, 128,
  107475. _huff_lengthlist_line_128x17_3sub3,
  107476. 0, 0, 0, 0, 0,
  107477. NULL,
  107478. NULL,
  107479. NULL,
  107480. NULL,
  107481. 0
  107482. };
  107483. static long _huff_lengthlist_line_1024x27_class1[] = {
  107484. 2,10, 8,14, 7,12,11,14, 1, 5, 3, 7, 4, 9, 7,13,
  107485. };
  107486. static static_codebook _huff_book_line_1024x27_class1 = {
  107487. 1, 16,
  107488. _huff_lengthlist_line_1024x27_class1,
  107489. 0, 0, 0, 0, 0,
  107490. NULL,
  107491. NULL,
  107492. NULL,
  107493. NULL,
  107494. 0
  107495. };
  107496. static long _huff_lengthlist_line_1024x27_class2[] = {
  107497. 1, 4, 2, 6, 3, 7, 5, 7,
  107498. };
  107499. static static_codebook _huff_book_line_1024x27_class2 = {
  107500. 1, 8,
  107501. _huff_lengthlist_line_1024x27_class2,
  107502. 0, 0, 0, 0, 0,
  107503. NULL,
  107504. NULL,
  107505. NULL,
  107506. NULL,
  107507. 0
  107508. };
  107509. static long _huff_lengthlist_line_1024x27_class3[] = {
  107510. 1, 5, 7,21, 5, 8, 9,21,10, 9,12,20,20,16,20,20,
  107511. 4, 8, 9,20, 6, 8, 9,20,11,11,13,20,20,15,17,20,
  107512. 9,11,14,20, 8,10,15,20,11,13,15,20,20,20,20,20,
  107513. 20,20,20,20,13,20,20,20,18,18,20,20,20,20,20,20,
  107514. 3, 6, 8,20, 6, 7, 9,20,10, 9,12,20,20,20,20,20,
  107515. 5, 7, 9,20, 6, 6, 9,20,10, 9,12,20,20,20,20,20,
  107516. 8,10,13,20, 8, 9,12,20,11,10,12,20,20,20,20,20,
  107517. 18,20,20,20,15,17,18,20,18,17,18,20,20,20,20,20,
  107518. 7,10,12,20, 8, 9,11,20,14,13,14,20,20,20,20,20,
  107519. 6, 9,12,20, 7, 8,11,20,12,11,13,20,20,20,20,20,
  107520. 9,11,15,20, 8,10,14,20,12,11,14,20,20,20,20,20,
  107521. 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
  107522. 11,16,18,20,15,15,17,20,20,17,20,20,20,20,20,20,
  107523. 9,14,16,20,12,12,15,20,17,15,18,20,20,20,20,20,
  107524. 16,19,18,20,15,16,20,20,17,17,20,20,20,20,20,20,
  107525. 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
  107526. };
  107527. static static_codebook _huff_book_line_1024x27_class3 = {
  107528. 1, 256,
  107529. _huff_lengthlist_line_1024x27_class3,
  107530. 0, 0, 0, 0, 0,
  107531. NULL,
  107532. NULL,
  107533. NULL,
  107534. NULL,
  107535. 0
  107536. };
  107537. static long _huff_lengthlist_line_1024x27_class4[] = {
  107538. 2, 3, 7,13, 4, 4, 7,15, 8, 6, 9,17,21,16,15,21,
  107539. 2, 5, 7,11, 5, 5, 7,14, 9, 7,10,16,17,15,16,21,
  107540. 4, 7,10,17, 7, 7, 9,15,11, 9,11,16,21,18,15,21,
  107541. 18,21,21,21,15,17,17,19,21,19,18,20,21,21,21,20,
  107542. };
  107543. static static_codebook _huff_book_line_1024x27_class4 = {
  107544. 1, 64,
  107545. _huff_lengthlist_line_1024x27_class4,
  107546. 0, 0, 0, 0, 0,
  107547. NULL,
  107548. NULL,
  107549. NULL,
  107550. NULL,
  107551. 0
  107552. };
  107553. static long _huff_lengthlist_line_1024x27_0sub0[] = {
  107554. 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107555. 6, 5, 6, 5, 6, 5, 6, 5, 7, 5, 7, 5, 7, 5, 7, 5,
  107556. 8, 6, 8, 6, 8, 6, 9, 6, 9, 6,10, 6,10, 6,11, 6,
  107557. 11, 7,11, 7,12, 7,12, 7,12, 7,12, 7,12, 7,12, 7,
  107558. 12, 7,12, 8,13, 8,12, 8,12, 8,13, 8,13, 9,13, 9,
  107559. 13, 9,13, 9,12,10,12,10,13,10,14,11,14,12,14,13,
  107560. 14,13,14,14,15,16,15,15,15,14,15,17,21,22,22,21,
  107561. 22,22,22,22,22,22,21,21,21,21,21,21,21,21,21,21,
  107562. };
  107563. static static_codebook _huff_book_line_1024x27_0sub0 = {
  107564. 1, 128,
  107565. _huff_lengthlist_line_1024x27_0sub0,
  107566. 0, 0, 0, 0, 0,
  107567. NULL,
  107568. NULL,
  107569. NULL,
  107570. NULL,
  107571. 0
  107572. };
  107573. static long _huff_lengthlist_line_1024x27_1sub0[] = {
  107574. 2, 5, 5, 4, 5, 4, 5, 4, 5, 4, 6, 5, 6, 5, 6, 5,
  107575. 6, 5, 7, 5, 7, 6, 8, 6, 8, 6, 8, 6, 9, 6, 9, 6,
  107576. };
  107577. static static_codebook _huff_book_line_1024x27_1sub0 = {
  107578. 1, 32,
  107579. _huff_lengthlist_line_1024x27_1sub0,
  107580. 0, 0, 0, 0, 0,
  107581. NULL,
  107582. NULL,
  107583. NULL,
  107584. NULL,
  107585. 0
  107586. };
  107587. static long _huff_lengthlist_line_1024x27_1sub1[] = {
  107588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107590. 8, 5, 8, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 4,
  107591. 9, 4, 9, 4, 9, 4, 8, 4, 8, 4, 9, 5, 9, 5, 9, 5,
  107592. 9, 5, 9, 6,10, 6,10, 7,10, 8,11, 9,11,11,12,13,
  107593. 12,14,13,15,13,15,14,16,14,17,15,17,15,15,16,16,
  107594. 15,16,16,16,15,18,16,15,17,17,19,19,19,19,19,19,
  107595. 19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,
  107596. };
  107597. static static_codebook _huff_book_line_1024x27_1sub1 = {
  107598. 1, 128,
  107599. _huff_lengthlist_line_1024x27_1sub1,
  107600. 0, 0, 0, 0, 0,
  107601. NULL,
  107602. NULL,
  107603. NULL,
  107604. NULL,
  107605. 0
  107606. };
  107607. static long _huff_lengthlist_line_1024x27_2sub0[] = {
  107608. 1, 5, 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107609. 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 9, 8,10, 9,10, 9,
  107610. };
  107611. static static_codebook _huff_book_line_1024x27_2sub0 = {
  107612. 1, 32,
  107613. _huff_lengthlist_line_1024x27_2sub0,
  107614. 0, 0, 0, 0, 0,
  107615. NULL,
  107616. NULL,
  107617. NULL,
  107618. NULL,
  107619. 0
  107620. };
  107621. static long _huff_lengthlist_line_1024x27_2sub1[] = {
  107622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107624. 4, 3, 4, 3, 4, 4, 5, 4, 5, 4, 5, 5, 6, 5, 6, 5,
  107625. 7, 5, 7, 6, 7, 6, 8, 7, 8, 7, 8, 7, 9, 8, 9, 9,
  107626. 9, 9,10,10,10,11, 9,12, 9,12, 9,15,10,14, 9,13,
  107627. 10,13,10,12,10,12,10,13,10,12,11,13,11,14,12,13,
  107628. 13,14,14,13,14,15,14,16,13,13,14,16,16,16,16,16,
  107629. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,15,15,
  107630. };
  107631. static static_codebook _huff_book_line_1024x27_2sub1 = {
  107632. 1, 128,
  107633. _huff_lengthlist_line_1024x27_2sub1,
  107634. 0, 0, 0, 0, 0,
  107635. NULL,
  107636. NULL,
  107637. NULL,
  107638. NULL,
  107639. 0
  107640. };
  107641. static long _huff_lengthlist_line_1024x27_3sub1[] = {
  107642. 0, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4, 4, 4, 4, 5,
  107643. 5, 5,
  107644. };
  107645. static static_codebook _huff_book_line_1024x27_3sub1 = {
  107646. 1, 18,
  107647. _huff_lengthlist_line_1024x27_3sub1,
  107648. 0, 0, 0, 0, 0,
  107649. NULL,
  107650. NULL,
  107651. NULL,
  107652. NULL,
  107653. 0
  107654. };
  107655. static long _huff_lengthlist_line_1024x27_3sub2[] = {
  107656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107657. 0, 0, 3, 3, 4, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6,
  107658. 5, 7, 5, 8, 6, 8, 6, 9, 7,10, 7,10, 8,10, 8,11,
  107659. 9,11,
  107660. };
  107661. static static_codebook _huff_book_line_1024x27_3sub2 = {
  107662. 1, 50,
  107663. _huff_lengthlist_line_1024x27_3sub2,
  107664. 0, 0, 0, 0, 0,
  107665. NULL,
  107666. NULL,
  107667. NULL,
  107668. NULL,
  107669. 0
  107670. };
  107671. static long _huff_lengthlist_line_1024x27_3sub3[] = {
  107672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107675. 0, 0, 3, 7, 3, 8, 3,10, 3, 8, 3, 9, 3, 8, 4, 9,
  107676. 4, 9, 5, 9, 6,10, 6, 9, 7,11, 7,12, 9,13,10,13,
  107677. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  107678. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  107679. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  107680. };
  107681. static static_codebook _huff_book_line_1024x27_3sub3 = {
  107682. 1, 128,
  107683. _huff_lengthlist_line_1024x27_3sub3,
  107684. 0, 0, 0, 0, 0,
  107685. NULL,
  107686. NULL,
  107687. NULL,
  107688. NULL,
  107689. 0
  107690. };
  107691. static long _huff_lengthlist_line_1024x27_4sub1[] = {
  107692. 0, 4, 5, 4, 5, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4,
  107693. 5, 4,
  107694. };
  107695. static static_codebook _huff_book_line_1024x27_4sub1 = {
  107696. 1, 18,
  107697. _huff_lengthlist_line_1024x27_4sub1,
  107698. 0, 0, 0, 0, 0,
  107699. NULL,
  107700. NULL,
  107701. NULL,
  107702. NULL,
  107703. 0
  107704. };
  107705. static long _huff_lengthlist_line_1024x27_4sub2[] = {
  107706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107707. 0, 0, 4, 2, 4, 2, 5, 3, 5, 4, 6, 6, 6, 7, 7, 8,
  107708. 7, 8, 7, 8, 7, 9, 8, 9, 8, 9, 8,10, 8,11, 9,12,
  107709. 9,12,
  107710. };
  107711. static static_codebook _huff_book_line_1024x27_4sub2 = {
  107712. 1, 50,
  107713. _huff_lengthlist_line_1024x27_4sub2,
  107714. 0, 0, 0, 0, 0,
  107715. NULL,
  107716. NULL,
  107717. NULL,
  107718. NULL,
  107719. 0
  107720. };
  107721. static long _huff_lengthlist_line_1024x27_4sub3[] = {
  107722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107725. 0, 0, 2, 5, 2, 6, 3, 6, 4, 7, 4, 7, 5, 9, 5,11,
  107726. 6,11, 6,11, 7,11, 6,11, 6,11, 9,11, 8,11,11,11,
  107727. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107728. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107729. 11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,
  107730. };
  107731. static static_codebook _huff_book_line_1024x27_4sub3 = {
  107732. 1, 128,
  107733. _huff_lengthlist_line_1024x27_4sub3,
  107734. 0, 0, 0, 0, 0,
  107735. NULL,
  107736. NULL,
  107737. NULL,
  107738. NULL,
  107739. 0
  107740. };
  107741. static long _huff_lengthlist_line_2048x27_class1[] = {
  107742. 2, 6, 8, 9, 7,11,13,13, 1, 3, 5, 5, 6, 6,12,10,
  107743. };
  107744. static static_codebook _huff_book_line_2048x27_class1 = {
  107745. 1, 16,
  107746. _huff_lengthlist_line_2048x27_class1,
  107747. 0, 0, 0, 0, 0,
  107748. NULL,
  107749. NULL,
  107750. NULL,
  107751. NULL,
  107752. 0
  107753. };
  107754. static long _huff_lengthlist_line_2048x27_class2[] = {
  107755. 1, 2, 3, 6, 4, 7, 5, 7,
  107756. };
  107757. static static_codebook _huff_book_line_2048x27_class2 = {
  107758. 1, 8,
  107759. _huff_lengthlist_line_2048x27_class2,
  107760. 0, 0, 0, 0, 0,
  107761. NULL,
  107762. NULL,
  107763. NULL,
  107764. NULL,
  107765. 0
  107766. };
  107767. static long _huff_lengthlist_line_2048x27_class3[] = {
  107768. 3, 3, 6,16, 5, 5, 7,16, 9, 8,11,16,16,16,16,16,
  107769. 5, 5, 8,16, 5, 5, 7,16, 8, 7, 9,16,16,16,16,16,
  107770. 9, 9,12,16, 6, 8,11,16, 9,10,11,16,16,16,16,16,
  107771. 16,16,16,16,13,16,16,16,15,16,16,16,16,16,16,16,
  107772. 5, 4, 7,16, 6, 5, 8,16, 9, 8,10,16,16,16,16,16,
  107773. 5, 5, 7,15, 5, 4, 6,15, 7, 6, 8,16,16,16,16,16,
  107774. 9, 9,11,15, 7, 7, 9,16, 8, 8, 9,16,16,16,16,16,
  107775. 16,16,16,16,15,15,15,16,15,15,14,16,16,16,16,16,
  107776. 8, 8,11,16, 8, 9,10,16,11,10,14,16,16,16,16,16,
  107777. 6, 8,10,16, 6, 7,10,16, 8, 8,11,16,14,16,16,16,
  107778. 10,11,14,16, 9, 9,11,16,10,10,11,16,16,16,16,16,
  107779. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  107780. 16,16,16,16,15,16,16,16,16,16,16,16,16,16,16,16,
  107781. 12,16,15,16,12,14,16,16,16,16,16,16,16,16,16,16,
  107782. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  107783. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  107784. };
  107785. static static_codebook _huff_book_line_2048x27_class3 = {
  107786. 1, 256,
  107787. _huff_lengthlist_line_2048x27_class3,
  107788. 0, 0, 0, 0, 0,
  107789. NULL,
  107790. NULL,
  107791. NULL,
  107792. NULL,
  107793. 0
  107794. };
  107795. static long _huff_lengthlist_line_2048x27_class4[] = {
  107796. 2, 4, 7,13, 4, 5, 7,15, 8, 7,10,16,16,14,16,16,
  107797. 2, 4, 7,16, 3, 4, 7,14, 8, 8,10,16,16,16,15,16,
  107798. 6, 8,11,16, 7, 7, 9,16,11, 9,13,16,16,16,15,16,
  107799. 16,16,16,16,14,16,16,16,16,16,16,16,16,16,16,16,
  107800. };
  107801. static static_codebook _huff_book_line_2048x27_class4 = {
  107802. 1, 64,
  107803. _huff_lengthlist_line_2048x27_class4,
  107804. 0, 0, 0, 0, 0,
  107805. NULL,
  107806. NULL,
  107807. NULL,
  107808. NULL,
  107809. 0
  107810. };
  107811. static long _huff_lengthlist_line_2048x27_0sub0[] = {
  107812. 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107813. 6, 5, 7, 5, 7, 5, 7, 5, 8, 5, 8, 5, 8, 5, 9, 5,
  107814. 9, 6,10, 6,10, 6,11, 6,11, 6,11, 6,11, 6,11, 6,
  107815. 11, 6,11, 6,12, 7,11, 7,11, 7,11, 7,11, 7,10, 7,
  107816. 11, 7,11, 7,12, 7,11, 8,11, 8,11, 8,11, 8,13, 8,
  107817. 12, 9,11, 9,11, 9,11,10,12,10,12, 9,12,10,12,11,
  107818. 14,12,16,12,12,11,14,16,17,17,17,17,17,17,17,17,
  107819. 17,17,17,17,17,17,17,17,17,17,17,17,16,16,16,16,
  107820. };
  107821. static static_codebook _huff_book_line_2048x27_0sub0 = {
  107822. 1, 128,
  107823. _huff_lengthlist_line_2048x27_0sub0,
  107824. 0, 0, 0, 0, 0,
  107825. NULL,
  107826. NULL,
  107827. NULL,
  107828. NULL,
  107829. 0
  107830. };
  107831. static long _huff_lengthlist_line_2048x27_1sub0[] = {
  107832. 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5,
  107833. 5, 5, 6, 6, 6, 6, 6, 6, 7, 6, 7, 6, 7, 6, 7, 6,
  107834. };
  107835. static static_codebook _huff_book_line_2048x27_1sub0 = {
  107836. 1, 32,
  107837. _huff_lengthlist_line_2048x27_1sub0,
  107838. 0, 0, 0, 0, 0,
  107839. NULL,
  107840. NULL,
  107841. NULL,
  107842. NULL,
  107843. 0
  107844. };
  107845. static long _huff_lengthlist_line_2048x27_1sub1[] = {
  107846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107848. 6, 5, 7, 5, 7, 4, 7, 4, 8, 4, 8, 4, 8, 4, 8, 3,
  107849. 8, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 5, 9, 5, 9, 6,
  107850. 9, 7, 9, 8, 9, 9, 9,10, 9,11, 9,14, 9,15,10,15,
  107851. 10,15,10,15,10,15,11,15,10,14,12,14,11,14,13,14,
  107852. 13,15,15,15,12,15,15,15,13,15,13,15,13,15,15,15,
  107853. 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,14,
  107854. };
  107855. static static_codebook _huff_book_line_2048x27_1sub1 = {
  107856. 1, 128,
  107857. _huff_lengthlist_line_2048x27_1sub1,
  107858. 0, 0, 0, 0, 0,
  107859. NULL,
  107860. NULL,
  107861. NULL,
  107862. NULL,
  107863. 0
  107864. };
  107865. static long _huff_lengthlist_line_2048x27_2sub0[] = {
  107866. 2, 4, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 6, 5,
  107867. 6, 5, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,
  107868. };
  107869. static static_codebook _huff_book_line_2048x27_2sub0 = {
  107870. 1, 32,
  107871. _huff_lengthlist_line_2048x27_2sub0,
  107872. 0, 0, 0, 0, 0,
  107873. NULL,
  107874. NULL,
  107875. NULL,
  107876. NULL,
  107877. 0
  107878. };
  107879. static long _huff_lengthlist_line_2048x27_2sub1[] = {
  107880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107882. 3, 4, 3, 4, 3, 4, 4, 5, 4, 5, 5, 5, 6, 6, 6, 7,
  107883. 6, 8, 6, 8, 6, 9, 7,10, 7,10, 7,10, 7,12, 7,12,
  107884. 7,12, 9,12,11,12,10,12,10,12,11,12,12,12,10,12,
  107885. 10,12,10,12, 9,12,11,12,12,12,12,12,11,12,11,12,
  107886. 12,12,12,12,12,12,12,12,10,10,12,12,12,12,12,10,
  107887. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  107888. };
  107889. static static_codebook _huff_book_line_2048x27_2sub1 = {
  107890. 1, 128,
  107891. _huff_lengthlist_line_2048x27_2sub1,
  107892. 0, 0, 0, 0, 0,
  107893. NULL,
  107894. NULL,
  107895. NULL,
  107896. NULL,
  107897. 0
  107898. };
  107899. static long _huff_lengthlist_line_2048x27_3sub1[] = {
  107900. 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  107901. 5, 5,
  107902. };
  107903. static static_codebook _huff_book_line_2048x27_3sub1 = {
  107904. 1, 18,
  107905. _huff_lengthlist_line_2048x27_3sub1,
  107906. 0, 0, 0, 0, 0,
  107907. NULL,
  107908. NULL,
  107909. NULL,
  107910. NULL,
  107911. 0
  107912. };
  107913. static long _huff_lengthlist_line_2048x27_3sub2[] = {
  107914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107915. 0, 0, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6,
  107916. 6, 7, 6, 7, 6, 8, 6, 9, 7, 9, 7, 9, 9,11, 9,12,
  107917. 10,12,
  107918. };
  107919. static static_codebook _huff_book_line_2048x27_3sub2 = {
  107920. 1, 50,
  107921. _huff_lengthlist_line_2048x27_3sub2,
  107922. 0, 0, 0, 0, 0,
  107923. NULL,
  107924. NULL,
  107925. NULL,
  107926. NULL,
  107927. 0
  107928. };
  107929. static long _huff_lengthlist_line_2048x27_3sub3[] = {
  107930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107933. 0, 0, 3, 6, 3, 7, 3, 7, 5, 7, 7, 7, 7, 7, 6, 7,
  107934. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107935. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107936. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107937. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107938. };
  107939. static static_codebook _huff_book_line_2048x27_3sub3 = {
  107940. 1, 128,
  107941. _huff_lengthlist_line_2048x27_3sub3,
  107942. 0, 0, 0, 0, 0,
  107943. NULL,
  107944. NULL,
  107945. NULL,
  107946. NULL,
  107947. 0
  107948. };
  107949. static long _huff_lengthlist_line_2048x27_4sub1[] = {
  107950. 0, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 4, 5, 4, 5, 4,
  107951. 4, 5,
  107952. };
  107953. static static_codebook _huff_book_line_2048x27_4sub1 = {
  107954. 1, 18,
  107955. _huff_lengthlist_line_2048x27_4sub1,
  107956. 0, 0, 0, 0, 0,
  107957. NULL,
  107958. NULL,
  107959. NULL,
  107960. NULL,
  107961. 0
  107962. };
  107963. static long _huff_lengthlist_line_2048x27_4sub2[] = {
  107964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107965. 0, 0, 3, 2, 4, 3, 4, 4, 4, 5, 5, 6, 5, 6, 5, 7,
  107966. 6, 6, 6, 7, 7, 7, 8, 9, 9, 9,12,10,11,10,10,12,
  107967. 10,10,
  107968. };
  107969. static static_codebook _huff_book_line_2048x27_4sub2 = {
  107970. 1, 50,
  107971. _huff_lengthlist_line_2048x27_4sub2,
  107972. 0, 0, 0, 0, 0,
  107973. NULL,
  107974. NULL,
  107975. NULL,
  107976. NULL,
  107977. 0
  107978. };
  107979. static long _huff_lengthlist_line_2048x27_4sub3[] = {
  107980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107983. 0, 0, 3, 6, 5, 7, 5, 7, 7, 7, 7, 7, 5, 7, 5, 7,
  107984. 5, 7, 5, 7, 7, 7, 7, 7, 4, 7, 7, 7, 7, 7, 7, 7,
  107985. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107986. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107987. 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107988. };
  107989. static static_codebook _huff_book_line_2048x27_4sub3 = {
  107990. 1, 128,
  107991. _huff_lengthlist_line_2048x27_4sub3,
  107992. 0, 0, 0, 0, 0,
  107993. NULL,
  107994. NULL,
  107995. NULL,
  107996. NULL,
  107997. 0
  107998. };
  107999. static long _huff_lengthlist_line_256x4low_class0[] = {
  108000. 4, 5, 6,11, 5, 5, 6,10, 7, 7, 6, 6,14,13, 9, 9,
  108001. 6, 6, 6,10, 6, 6, 6, 9, 8, 7, 7, 9,14,12, 8,11,
  108002. 8, 7, 7,11, 8, 8, 7,11, 9, 9, 7, 9,13,11, 9,13,
  108003. 19,19,18,19,15,16,16,19,11,11,10,13,10,10, 9,15,
  108004. 5, 5, 6,13, 6, 6, 6,11, 8, 7, 6, 7,14,11,10,11,
  108005. 6, 6, 6,12, 7, 6, 6,11, 8, 7, 7,11,13,11, 9,11,
  108006. 9, 7, 6,12, 8, 7, 6,12, 9, 8, 8,11,13,10, 7,13,
  108007. 19,19,17,19,17,14,14,19,12,10, 8,12,13,10, 9,16,
  108008. 7, 8, 7,12, 7, 7, 7,11, 8, 7, 7, 8,12,12,11,11,
  108009. 8, 8, 7,12, 8, 7, 6,11, 8, 7, 7,10,10,11,10,11,
  108010. 9, 8, 8,13, 9, 8, 7,12,10, 9, 7,11, 9, 8, 7,11,
  108011. 18,18,15,18,18,16,17,18,15,11,10,18,11, 9, 9,18,
  108012. 16,16,13,16,12,11,10,16,12,11, 9, 6,15,12,11,13,
  108013. 16,16,14,14,13,11,12,16,12, 9, 9,13,13,10,10,12,
  108014. 17,18,17,17,14,15,14,16,14,12,14,15,12,10,11,12,
  108015. 18,18,18,18,18,18,18,18,18,12,13,18,16,11, 9,18,
  108016. };
  108017. static static_codebook _huff_book_line_256x4low_class0 = {
  108018. 1, 256,
  108019. _huff_lengthlist_line_256x4low_class0,
  108020. 0, 0, 0, 0, 0,
  108021. NULL,
  108022. NULL,
  108023. NULL,
  108024. NULL,
  108025. 0
  108026. };
  108027. static long _huff_lengthlist_line_256x4low_0sub0[] = {
  108028. 1, 3, 2, 3,
  108029. };
  108030. static static_codebook _huff_book_line_256x4low_0sub0 = {
  108031. 1, 4,
  108032. _huff_lengthlist_line_256x4low_0sub0,
  108033. 0, 0, 0, 0, 0,
  108034. NULL,
  108035. NULL,
  108036. NULL,
  108037. NULL,
  108038. 0
  108039. };
  108040. static long _huff_lengthlist_line_256x4low_0sub1[] = {
  108041. 0, 0, 0, 0, 2, 3, 2, 3, 3, 3,
  108042. };
  108043. static static_codebook _huff_book_line_256x4low_0sub1 = {
  108044. 1, 10,
  108045. _huff_lengthlist_line_256x4low_0sub1,
  108046. 0, 0, 0, 0, 0,
  108047. NULL,
  108048. NULL,
  108049. NULL,
  108050. NULL,
  108051. 0
  108052. };
  108053. static long _huff_lengthlist_line_256x4low_0sub2[] = {
  108054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 4, 3, 4,
  108055. 4, 4, 4, 4, 5, 5, 5, 6, 6,
  108056. };
  108057. static static_codebook _huff_book_line_256x4low_0sub2 = {
  108058. 1, 25,
  108059. _huff_lengthlist_line_256x4low_0sub2,
  108060. 0, 0, 0, 0, 0,
  108061. NULL,
  108062. NULL,
  108063. NULL,
  108064. NULL,
  108065. 0
  108066. };
  108067. static long _huff_lengthlist_line_256x4low_0sub3[] = {
  108068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 2, 4, 3, 5, 4,
  108070. 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 7, 8, 6, 9,
  108071. 7,12,11,16,13,16,12,15,13,15,12,14,12,15,15,15,
  108072. };
  108073. static static_codebook _huff_book_line_256x4low_0sub3 = {
  108074. 1, 64,
  108075. _huff_lengthlist_line_256x4low_0sub3,
  108076. 0, 0, 0, 0, 0,
  108077. NULL,
  108078. NULL,
  108079. NULL,
  108080. NULL,
  108081. 0
  108082. };
  108083. /*** End of inlined file: floor_books.h ***/
  108084. static static_codebook *_floor_128x4_books[]={
  108085. &_huff_book_line_128x4_class0,
  108086. &_huff_book_line_128x4_0sub0,
  108087. &_huff_book_line_128x4_0sub1,
  108088. &_huff_book_line_128x4_0sub2,
  108089. &_huff_book_line_128x4_0sub3,
  108090. };
  108091. static static_codebook *_floor_256x4_books[]={
  108092. &_huff_book_line_256x4_class0,
  108093. &_huff_book_line_256x4_0sub0,
  108094. &_huff_book_line_256x4_0sub1,
  108095. &_huff_book_line_256x4_0sub2,
  108096. &_huff_book_line_256x4_0sub3,
  108097. };
  108098. static static_codebook *_floor_128x7_books[]={
  108099. &_huff_book_line_128x7_class0,
  108100. &_huff_book_line_128x7_class1,
  108101. &_huff_book_line_128x7_0sub1,
  108102. &_huff_book_line_128x7_0sub2,
  108103. &_huff_book_line_128x7_0sub3,
  108104. &_huff_book_line_128x7_1sub1,
  108105. &_huff_book_line_128x7_1sub2,
  108106. &_huff_book_line_128x7_1sub3,
  108107. };
  108108. static static_codebook *_floor_256x7_books[]={
  108109. &_huff_book_line_256x7_class0,
  108110. &_huff_book_line_256x7_class1,
  108111. &_huff_book_line_256x7_0sub1,
  108112. &_huff_book_line_256x7_0sub2,
  108113. &_huff_book_line_256x7_0sub3,
  108114. &_huff_book_line_256x7_1sub1,
  108115. &_huff_book_line_256x7_1sub2,
  108116. &_huff_book_line_256x7_1sub3,
  108117. };
  108118. static static_codebook *_floor_128x11_books[]={
  108119. &_huff_book_line_128x11_class1,
  108120. &_huff_book_line_128x11_class2,
  108121. &_huff_book_line_128x11_class3,
  108122. &_huff_book_line_128x11_0sub0,
  108123. &_huff_book_line_128x11_1sub0,
  108124. &_huff_book_line_128x11_1sub1,
  108125. &_huff_book_line_128x11_2sub1,
  108126. &_huff_book_line_128x11_2sub2,
  108127. &_huff_book_line_128x11_2sub3,
  108128. &_huff_book_line_128x11_3sub1,
  108129. &_huff_book_line_128x11_3sub2,
  108130. &_huff_book_line_128x11_3sub3,
  108131. };
  108132. static static_codebook *_floor_128x17_books[]={
  108133. &_huff_book_line_128x17_class1,
  108134. &_huff_book_line_128x17_class2,
  108135. &_huff_book_line_128x17_class3,
  108136. &_huff_book_line_128x17_0sub0,
  108137. &_huff_book_line_128x17_1sub0,
  108138. &_huff_book_line_128x17_1sub1,
  108139. &_huff_book_line_128x17_2sub1,
  108140. &_huff_book_line_128x17_2sub2,
  108141. &_huff_book_line_128x17_2sub3,
  108142. &_huff_book_line_128x17_3sub1,
  108143. &_huff_book_line_128x17_3sub2,
  108144. &_huff_book_line_128x17_3sub3,
  108145. };
  108146. static static_codebook *_floor_256x4low_books[]={
  108147. &_huff_book_line_256x4low_class0,
  108148. &_huff_book_line_256x4low_0sub0,
  108149. &_huff_book_line_256x4low_0sub1,
  108150. &_huff_book_line_256x4low_0sub2,
  108151. &_huff_book_line_256x4low_0sub3,
  108152. };
  108153. static static_codebook *_floor_1024x27_books[]={
  108154. &_huff_book_line_1024x27_class1,
  108155. &_huff_book_line_1024x27_class2,
  108156. &_huff_book_line_1024x27_class3,
  108157. &_huff_book_line_1024x27_class4,
  108158. &_huff_book_line_1024x27_0sub0,
  108159. &_huff_book_line_1024x27_1sub0,
  108160. &_huff_book_line_1024x27_1sub1,
  108161. &_huff_book_line_1024x27_2sub0,
  108162. &_huff_book_line_1024x27_2sub1,
  108163. &_huff_book_line_1024x27_3sub1,
  108164. &_huff_book_line_1024x27_3sub2,
  108165. &_huff_book_line_1024x27_3sub3,
  108166. &_huff_book_line_1024x27_4sub1,
  108167. &_huff_book_line_1024x27_4sub2,
  108168. &_huff_book_line_1024x27_4sub3,
  108169. };
  108170. static static_codebook *_floor_2048x27_books[]={
  108171. &_huff_book_line_2048x27_class1,
  108172. &_huff_book_line_2048x27_class2,
  108173. &_huff_book_line_2048x27_class3,
  108174. &_huff_book_line_2048x27_class4,
  108175. &_huff_book_line_2048x27_0sub0,
  108176. &_huff_book_line_2048x27_1sub0,
  108177. &_huff_book_line_2048x27_1sub1,
  108178. &_huff_book_line_2048x27_2sub0,
  108179. &_huff_book_line_2048x27_2sub1,
  108180. &_huff_book_line_2048x27_3sub1,
  108181. &_huff_book_line_2048x27_3sub2,
  108182. &_huff_book_line_2048x27_3sub3,
  108183. &_huff_book_line_2048x27_4sub1,
  108184. &_huff_book_line_2048x27_4sub2,
  108185. &_huff_book_line_2048x27_4sub3,
  108186. };
  108187. static static_codebook *_floor_512x17_books[]={
  108188. &_huff_book_line_512x17_class1,
  108189. &_huff_book_line_512x17_class2,
  108190. &_huff_book_line_512x17_class3,
  108191. &_huff_book_line_512x17_0sub0,
  108192. &_huff_book_line_512x17_1sub0,
  108193. &_huff_book_line_512x17_1sub1,
  108194. &_huff_book_line_512x17_2sub1,
  108195. &_huff_book_line_512x17_2sub2,
  108196. &_huff_book_line_512x17_2sub3,
  108197. &_huff_book_line_512x17_3sub1,
  108198. &_huff_book_line_512x17_3sub2,
  108199. &_huff_book_line_512x17_3sub3,
  108200. };
  108201. static static_codebook **_floor_books[10]={
  108202. _floor_128x4_books,
  108203. _floor_256x4_books,
  108204. _floor_128x7_books,
  108205. _floor_256x7_books,
  108206. _floor_128x11_books,
  108207. _floor_128x17_books,
  108208. _floor_256x4low_books,
  108209. _floor_1024x27_books,
  108210. _floor_2048x27_books,
  108211. _floor_512x17_books,
  108212. };
  108213. static vorbis_info_floor1 _floor[10]={
  108214. {
  108215. 1,{0},{4},{2},{0},
  108216. {{1,2,3,4}},
  108217. 4,{0,128, 33,8,16,70},
  108218. 60,30,500, 1.,18., -1
  108219. },
  108220. {
  108221. 1,{0},{4},{2},{0},
  108222. {{1,2,3,4}},
  108223. 4,{0,256, 66,16,32,140},
  108224. 60,30,500, 1.,18., -1
  108225. },
  108226. {
  108227. 2,{0,1},{3,4},{2,2},{0,1},
  108228. {{-1,2,3,4},{-1,5,6,7}},
  108229. 4,{0,128, 14,4,58, 2,8,28,90},
  108230. 60,30,500, 1.,18., -1
  108231. },
  108232. {
  108233. 2,{0,1},{3,4},{2,2},{0,1},
  108234. {{-1,2,3,4},{-1,5,6,7}},
  108235. 4,{0,256, 28,8,116, 4,16,56,180},
  108236. 60,30,500, 1.,18., -1
  108237. },
  108238. {
  108239. 4,{0,1,2,3},{2,3,3,3},{0,1,2,2},{-1,0,1,2},
  108240. {{3},{4,5},{-1,6,7,8},{-1,9,10,11}},
  108241. 2,{0,128, 8,33, 4,16,70, 2,6,12, 23,46,90},
  108242. 60,30,500, 1,18., -1
  108243. },
  108244. {
  108245. 6,{0,1,1,2,3,3},{2,3,3,3},{0,1,2,2},{-1,0,1,2},
  108246. {{3},{4,5},{-1,6,7,8},{-1,9,10,11}},
  108247. 2,{0,128, 12,46, 4,8,16, 23,33,70, 2,6,10, 14,19,28, 39,58,90},
  108248. 60,30,500, 1,18., -1
  108249. },
  108250. {
  108251. 1,{0},{4},{2},{0},
  108252. {{1,2,3,4}},
  108253. 4,{0,256, 66,16,32,140},
  108254. 60,30,500, 1.,18., -1
  108255. },
  108256. {
  108257. 8,{0,1,2,2,3,3,4,4},{3,4,3,4,3},{0,1,1,2,2},{-1,0,1,2,3},
  108258. {{4},{5,6},{7,8},{-1,9,10,11},{-1,12,13,14}},
  108259. 2,{0,1024, 93,23,372, 6,46,186,750, 14,33,65, 130,260,556,
  108260. 3,10,18,28, 39,55,79,111, 158,220,312, 464,650,850},
  108261. 60,30,500, 3,18., -1 /* lowpass */
  108262. },
  108263. {
  108264. 8,{0,1,2,2,3,3,4,4},{3,4,3,4,3},{0,1,1,2,2},{-1,0,1,2,3},
  108265. {{4},{5,6},{7,8},{-1,9,10,11},{-1,12,13,14}},
  108266. 2,{0,2048, 186,46,744, 12,92,372,1500, 28,66,130, 260,520,1112,
  108267. 6,20,36,56, 78,110,158,222, 316,440,624, 928,1300,1700},
  108268. 60,30,500, 3,18., -1 /* lowpass */
  108269. },
  108270. {
  108271. 6,{0,1,1,2,3,3},{2,3,3,3},{0,1,2,2},{-1,0,1,2},
  108272. {{3},{4,5},{-1,6,7,8},{-1,9,10,11}},
  108273. 2,{0,512, 46,186, 16,33,65, 93,130,278,
  108274. 7,23,39, 55,79,110, 156,232,360},
  108275. 60,30,500, 1,18., -1 /* lowpass! */
  108276. },
  108277. };
  108278. /*** End of inlined file: floor_all.h ***/
  108279. /*** Start of inlined file: residue_44.h ***/
  108280. /*** Start of inlined file: res_books_stereo.h ***/
  108281. static long _vq_quantlist__16c0_s_p1_0[] = {
  108282. 1,
  108283. 0,
  108284. 2,
  108285. };
  108286. static long _vq_lengthlist__16c0_s_p1_0[] = {
  108287. 1, 4, 4, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  108288. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108292. 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9,10, 0, 0, 0,
  108293. 0, 0, 0, 7, 9,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108297. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  108298. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  108333. 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 8,10,10, 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, 7,10,10, 0, 0, 0,
  108338. 0, 0, 0, 9, 9,12, 0, 0, 0, 0, 0, 0,10,12,11, 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, 7,10,10, 0, 0,
  108343. 0, 0, 0, 0, 9,12,10, 0, 0, 0, 0, 0, 0,10,11,12,
  108344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108378. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0,
  108379. 0, 0, 0, 0, 8,10,10, 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, 7,10,10, 0, 0, 0, 0, 0, 0,10,12,11, 0,
  108384. 0, 0, 0, 0, 0, 9,10,12, 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, 7,10,10, 0, 0, 0, 0, 0, 0,10,11,12,
  108389. 0, 0, 0, 0, 0, 0, 9,12, 9, 0, 0, 0, 0, 0, 0, 0,
  108390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108620. 0, 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,
  108698. };
  108699. static float _vq_quantthresh__16c0_s_p1_0[] = {
  108700. -0.5, 0.5,
  108701. };
  108702. static long _vq_quantmap__16c0_s_p1_0[] = {
  108703. 1, 0, 2,
  108704. };
  108705. static encode_aux_threshmatch _vq_auxt__16c0_s_p1_0 = {
  108706. _vq_quantthresh__16c0_s_p1_0,
  108707. _vq_quantmap__16c0_s_p1_0,
  108708. 3,
  108709. 3
  108710. };
  108711. static static_codebook _16c0_s_p1_0 = {
  108712. 8, 6561,
  108713. _vq_lengthlist__16c0_s_p1_0,
  108714. 1, -535822336, 1611661312, 2, 0,
  108715. _vq_quantlist__16c0_s_p1_0,
  108716. NULL,
  108717. &_vq_auxt__16c0_s_p1_0,
  108718. NULL,
  108719. 0
  108720. };
  108721. static long _vq_quantlist__16c0_s_p2_0[] = {
  108722. 2,
  108723. 1,
  108724. 3,
  108725. 0,
  108726. 4,
  108727. };
  108728. static long _vq_lengthlist__16c0_s_p2_0[] = {
  108729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108768. 0,
  108769. };
  108770. static float _vq_quantthresh__16c0_s_p2_0[] = {
  108771. -1.5, -0.5, 0.5, 1.5,
  108772. };
  108773. static long _vq_quantmap__16c0_s_p2_0[] = {
  108774. 3, 1, 0, 2, 4,
  108775. };
  108776. static encode_aux_threshmatch _vq_auxt__16c0_s_p2_0 = {
  108777. _vq_quantthresh__16c0_s_p2_0,
  108778. _vq_quantmap__16c0_s_p2_0,
  108779. 5,
  108780. 5
  108781. };
  108782. static static_codebook _16c0_s_p2_0 = {
  108783. 4, 625,
  108784. _vq_lengthlist__16c0_s_p2_0,
  108785. 1, -533725184, 1611661312, 3, 0,
  108786. _vq_quantlist__16c0_s_p2_0,
  108787. NULL,
  108788. &_vq_auxt__16c0_s_p2_0,
  108789. NULL,
  108790. 0
  108791. };
  108792. static long _vq_quantlist__16c0_s_p3_0[] = {
  108793. 2,
  108794. 1,
  108795. 3,
  108796. 0,
  108797. 4,
  108798. };
  108799. static long _vq_lengthlist__16c0_s_p3_0[] = {
  108800. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 6, 6, 7, 6, 0, 0,
  108802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108803. 0, 0, 4, 6, 6, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  108805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108806. 0, 0, 0, 0, 6, 6, 6, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  108807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108839. 0,
  108840. };
  108841. static float _vq_quantthresh__16c0_s_p3_0[] = {
  108842. -1.5, -0.5, 0.5, 1.5,
  108843. };
  108844. static long _vq_quantmap__16c0_s_p3_0[] = {
  108845. 3, 1, 0, 2, 4,
  108846. };
  108847. static encode_aux_threshmatch _vq_auxt__16c0_s_p3_0 = {
  108848. _vq_quantthresh__16c0_s_p3_0,
  108849. _vq_quantmap__16c0_s_p3_0,
  108850. 5,
  108851. 5
  108852. };
  108853. static static_codebook _16c0_s_p3_0 = {
  108854. 4, 625,
  108855. _vq_lengthlist__16c0_s_p3_0,
  108856. 1, -533725184, 1611661312, 3, 0,
  108857. _vq_quantlist__16c0_s_p3_0,
  108858. NULL,
  108859. &_vq_auxt__16c0_s_p3_0,
  108860. NULL,
  108861. 0
  108862. };
  108863. static long _vq_quantlist__16c0_s_p4_0[] = {
  108864. 4,
  108865. 3,
  108866. 5,
  108867. 2,
  108868. 6,
  108869. 1,
  108870. 7,
  108871. 0,
  108872. 8,
  108873. };
  108874. static long _vq_lengthlist__16c0_s_p4_0[] = {
  108875. 1, 3, 2, 7, 8, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  108876. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  108877. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  108878. 8, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  108879. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108880. 0,
  108881. };
  108882. static float _vq_quantthresh__16c0_s_p4_0[] = {
  108883. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  108884. };
  108885. static long _vq_quantmap__16c0_s_p4_0[] = {
  108886. 7, 5, 3, 1, 0, 2, 4, 6,
  108887. 8,
  108888. };
  108889. static encode_aux_threshmatch _vq_auxt__16c0_s_p4_0 = {
  108890. _vq_quantthresh__16c0_s_p4_0,
  108891. _vq_quantmap__16c0_s_p4_0,
  108892. 9,
  108893. 9
  108894. };
  108895. static static_codebook _16c0_s_p4_0 = {
  108896. 2, 81,
  108897. _vq_lengthlist__16c0_s_p4_0,
  108898. 1, -531628032, 1611661312, 4, 0,
  108899. _vq_quantlist__16c0_s_p4_0,
  108900. NULL,
  108901. &_vq_auxt__16c0_s_p4_0,
  108902. NULL,
  108903. 0
  108904. };
  108905. static long _vq_quantlist__16c0_s_p5_0[] = {
  108906. 4,
  108907. 3,
  108908. 5,
  108909. 2,
  108910. 6,
  108911. 1,
  108912. 7,
  108913. 0,
  108914. 8,
  108915. };
  108916. static long _vq_lengthlist__16c0_s_p5_0[] = {
  108917. 1, 3, 3, 6, 6, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  108918. 8, 8, 0, 0, 0, 7, 7, 7, 7, 8, 8, 0, 0, 0, 7, 7,
  108919. 8, 8, 9, 9, 0, 0, 0, 7, 7, 8, 8, 9, 9, 0, 0, 0,
  108920. 8, 9, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  108921. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  108922. 10,
  108923. };
  108924. static float _vq_quantthresh__16c0_s_p5_0[] = {
  108925. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  108926. };
  108927. static long _vq_quantmap__16c0_s_p5_0[] = {
  108928. 7, 5, 3, 1, 0, 2, 4, 6,
  108929. 8,
  108930. };
  108931. static encode_aux_threshmatch _vq_auxt__16c0_s_p5_0 = {
  108932. _vq_quantthresh__16c0_s_p5_0,
  108933. _vq_quantmap__16c0_s_p5_0,
  108934. 9,
  108935. 9
  108936. };
  108937. static static_codebook _16c0_s_p5_0 = {
  108938. 2, 81,
  108939. _vq_lengthlist__16c0_s_p5_0,
  108940. 1, -531628032, 1611661312, 4, 0,
  108941. _vq_quantlist__16c0_s_p5_0,
  108942. NULL,
  108943. &_vq_auxt__16c0_s_p5_0,
  108944. NULL,
  108945. 0
  108946. };
  108947. static long _vq_quantlist__16c0_s_p6_0[] = {
  108948. 8,
  108949. 7,
  108950. 9,
  108951. 6,
  108952. 10,
  108953. 5,
  108954. 11,
  108955. 4,
  108956. 12,
  108957. 3,
  108958. 13,
  108959. 2,
  108960. 14,
  108961. 1,
  108962. 15,
  108963. 0,
  108964. 16,
  108965. };
  108966. static long _vq_lengthlist__16c0_s_p6_0[] = {
  108967. 1, 3, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  108968. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,11,
  108969. 11,11, 0, 0, 0, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,
  108970. 11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  108971. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  108972. 10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  108973. 11,11,12,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  108974. 10,11,11,12,12,12,13, 0, 0, 0, 9, 9, 9, 9,10,10,
  108975. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,10,10,10,
  108976. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  108977. 10,10,11,11,12,12,13,13,13,13, 0, 0, 0, 0, 0, 9,
  108978. 9,10,10,11,11,12,12,13,13,13,14, 0, 0, 0, 0, 0,
  108979. 10,10,10,11,11,11,12,12,13,13,13,14, 0, 0, 0, 0,
  108980. 0, 0, 0,10,10,11,11,12,12,13,13,14,14, 0, 0, 0,
  108981. 0, 0, 0, 0,11,11,12,12,13,13,13,13,14,14, 0, 0,
  108982. 0, 0, 0, 0, 0,11,11,12,12,12,13,13,14,15,14, 0,
  108983. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,14,14,15,
  108984. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,14,13,14,
  108985. 14,
  108986. };
  108987. static float _vq_quantthresh__16c0_s_p6_0[] = {
  108988. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  108989. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  108990. };
  108991. static long _vq_quantmap__16c0_s_p6_0[] = {
  108992. 15, 13, 11, 9, 7, 5, 3, 1,
  108993. 0, 2, 4, 6, 8, 10, 12, 14,
  108994. 16,
  108995. };
  108996. static encode_aux_threshmatch _vq_auxt__16c0_s_p6_0 = {
  108997. _vq_quantthresh__16c0_s_p6_0,
  108998. _vq_quantmap__16c0_s_p6_0,
  108999. 17,
  109000. 17
  109001. };
  109002. static static_codebook _16c0_s_p6_0 = {
  109003. 2, 289,
  109004. _vq_lengthlist__16c0_s_p6_0,
  109005. 1, -529530880, 1611661312, 5, 0,
  109006. _vq_quantlist__16c0_s_p6_0,
  109007. NULL,
  109008. &_vq_auxt__16c0_s_p6_0,
  109009. NULL,
  109010. 0
  109011. };
  109012. static long _vq_quantlist__16c0_s_p7_0[] = {
  109013. 1,
  109014. 0,
  109015. 2,
  109016. };
  109017. static long _vq_lengthlist__16c0_s_p7_0[] = {
  109018. 1, 4, 4, 6, 6, 6, 7, 6, 6, 4, 7, 7,11,10,10,11,
  109019. 11,10, 4, 7, 7,10,10,10,11,10,10, 6,10,10,11,11,
  109020. 11,11,11,10, 6, 9, 9,11,12,12,11, 9, 9, 6, 9,10,
  109021. 11,12,12,11, 9,10, 7,11,11,11,11,11,12,13,12, 6,
  109022. 9,10,11,10,10,12,13,13, 6,10, 9,11,10,10,11,12,
  109023. 13,
  109024. };
  109025. static float _vq_quantthresh__16c0_s_p7_0[] = {
  109026. -5.5, 5.5,
  109027. };
  109028. static long _vq_quantmap__16c0_s_p7_0[] = {
  109029. 1, 0, 2,
  109030. };
  109031. static encode_aux_threshmatch _vq_auxt__16c0_s_p7_0 = {
  109032. _vq_quantthresh__16c0_s_p7_0,
  109033. _vq_quantmap__16c0_s_p7_0,
  109034. 3,
  109035. 3
  109036. };
  109037. static static_codebook _16c0_s_p7_0 = {
  109038. 4, 81,
  109039. _vq_lengthlist__16c0_s_p7_0,
  109040. 1, -529137664, 1618345984, 2, 0,
  109041. _vq_quantlist__16c0_s_p7_0,
  109042. NULL,
  109043. &_vq_auxt__16c0_s_p7_0,
  109044. NULL,
  109045. 0
  109046. };
  109047. static long _vq_quantlist__16c0_s_p7_1[] = {
  109048. 5,
  109049. 4,
  109050. 6,
  109051. 3,
  109052. 7,
  109053. 2,
  109054. 8,
  109055. 1,
  109056. 9,
  109057. 0,
  109058. 10,
  109059. };
  109060. static long _vq_lengthlist__16c0_s_p7_1[] = {
  109061. 1, 3, 4, 6, 6, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7,
  109062. 8, 8, 8, 9, 9, 9,10,10,10, 6, 7, 8, 8, 8, 8, 9,
  109063. 8,10,10,10, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10, 7,
  109064. 7, 8, 8, 9, 9, 8, 9,10,10,10, 8, 8, 9, 9, 9, 9,
  109065. 9, 9,11,11,11, 8, 8, 9, 9, 9, 9, 9,10,10,11,11,
  109066. 9, 9, 9, 9, 9, 9, 9,10,11,11,11,10,11, 9, 9, 9,
  109067. 9,10, 9,11,11,11,10,11,10,10, 9, 9,10,10,11,11,
  109068. 11,11,11, 9, 9, 9, 9,10,10,
  109069. };
  109070. static float _vq_quantthresh__16c0_s_p7_1[] = {
  109071. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  109072. 3.5, 4.5,
  109073. };
  109074. static long _vq_quantmap__16c0_s_p7_1[] = {
  109075. 9, 7, 5, 3, 1, 0, 2, 4,
  109076. 6, 8, 10,
  109077. };
  109078. static encode_aux_threshmatch _vq_auxt__16c0_s_p7_1 = {
  109079. _vq_quantthresh__16c0_s_p7_1,
  109080. _vq_quantmap__16c0_s_p7_1,
  109081. 11,
  109082. 11
  109083. };
  109084. static static_codebook _16c0_s_p7_1 = {
  109085. 2, 121,
  109086. _vq_lengthlist__16c0_s_p7_1,
  109087. 1, -531365888, 1611661312, 4, 0,
  109088. _vq_quantlist__16c0_s_p7_1,
  109089. NULL,
  109090. &_vq_auxt__16c0_s_p7_1,
  109091. NULL,
  109092. 0
  109093. };
  109094. static long _vq_quantlist__16c0_s_p8_0[] = {
  109095. 6,
  109096. 5,
  109097. 7,
  109098. 4,
  109099. 8,
  109100. 3,
  109101. 9,
  109102. 2,
  109103. 10,
  109104. 1,
  109105. 11,
  109106. 0,
  109107. 12,
  109108. };
  109109. static long _vq_lengthlist__16c0_s_p8_0[] = {
  109110. 1, 4, 4, 7, 7, 7, 7, 7, 6, 8, 8,10,10, 6, 5, 6,
  109111. 8, 8, 8, 8, 8, 8, 8, 9,10,10, 7, 6, 6, 8, 8, 8,
  109112. 8, 8, 8, 8, 8,10,10, 0, 8, 8, 8, 8, 9, 8, 9, 9,
  109113. 9,10,10,10, 0, 9, 8, 8, 8, 9, 9, 8, 8, 9, 9,10,
  109114. 10, 0,12,11, 8, 8, 9, 9, 9, 9,10,10,11,10, 0,12,
  109115. 13, 8, 8, 9,10, 9, 9,11,11,11,12, 0, 0, 0, 8, 8,
  109116. 8, 8,10, 9,12,13,12,14, 0, 0, 0, 8, 8, 8, 9,10,
  109117. 10,12,12,13,14, 0, 0, 0,13,13, 9, 9,11,11, 0, 0,
  109118. 14, 0, 0, 0, 0,14,14,10,10,12,11,12,14,14,14, 0,
  109119. 0, 0, 0, 0,11,11,13,13,14,13,14,14, 0, 0, 0, 0,
  109120. 0,12,13,13,12,13,14,14,14,
  109121. };
  109122. static float _vq_quantthresh__16c0_s_p8_0[] = {
  109123. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  109124. 12.5, 17.5, 22.5, 27.5,
  109125. };
  109126. static long _vq_quantmap__16c0_s_p8_0[] = {
  109127. 11, 9, 7, 5, 3, 1, 0, 2,
  109128. 4, 6, 8, 10, 12,
  109129. };
  109130. static encode_aux_threshmatch _vq_auxt__16c0_s_p8_0 = {
  109131. _vq_quantthresh__16c0_s_p8_0,
  109132. _vq_quantmap__16c0_s_p8_0,
  109133. 13,
  109134. 13
  109135. };
  109136. static static_codebook _16c0_s_p8_0 = {
  109137. 2, 169,
  109138. _vq_lengthlist__16c0_s_p8_0,
  109139. 1, -526516224, 1616117760, 4, 0,
  109140. _vq_quantlist__16c0_s_p8_0,
  109141. NULL,
  109142. &_vq_auxt__16c0_s_p8_0,
  109143. NULL,
  109144. 0
  109145. };
  109146. static long _vq_quantlist__16c0_s_p8_1[] = {
  109147. 2,
  109148. 1,
  109149. 3,
  109150. 0,
  109151. 4,
  109152. };
  109153. static long _vq_lengthlist__16c0_s_p8_1[] = {
  109154. 1, 4, 3, 5, 5, 7, 7, 7, 6, 6, 7, 7, 7, 5, 5, 7,
  109155. 7, 7, 6, 6, 7, 7, 7, 6, 6,
  109156. };
  109157. static float _vq_quantthresh__16c0_s_p8_1[] = {
  109158. -1.5, -0.5, 0.5, 1.5,
  109159. };
  109160. static long _vq_quantmap__16c0_s_p8_1[] = {
  109161. 3, 1, 0, 2, 4,
  109162. };
  109163. static encode_aux_threshmatch _vq_auxt__16c0_s_p8_1 = {
  109164. _vq_quantthresh__16c0_s_p8_1,
  109165. _vq_quantmap__16c0_s_p8_1,
  109166. 5,
  109167. 5
  109168. };
  109169. static static_codebook _16c0_s_p8_1 = {
  109170. 2, 25,
  109171. _vq_lengthlist__16c0_s_p8_1,
  109172. 1, -533725184, 1611661312, 3, 0,
  109173. _vq_quantlist__16c0_s_p8_1,
  109174. NULL,
  109175. &_vq_auxt__16c0_s_p8_1,
  109176. NULL,
  109177. 0
  109178. };
  109179. static long _vq_quantlist__16c0_s_p9_0[] = {
  109180. 1,
  109181. 0,
  109182. 2,
  109183. };
  109184. static long _vq_lengthlist__16c0_s_p9_0[] = {
  109185. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  109186. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  109187. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  109188. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  109189. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  109190. 7,
  109191. };
  109192. static float _vq_quantthresh__16c0_s_p9_0[] = {
  109193. -157.5, 157.5,
  109194. };
  109195. static long _vq_quantmap__16c0_s_p9_0[] = {
  109196. 1, 0, 2,
  109197. };
  109198. static encode_aux_threshmatch _vq_auxt__16c0_s_p9_0 = {
  109199. _vq_quantthresh__16c0_s_p9_0,
  109200. _vq_quantmap__16c0_s_p9_0,
  109201. 3,
  109202. 3
  109203. };
  109204. static static_codebook _16c0_s_p9_0 = {
  109205. 4, 81,
  109206. _vq_lengthlist__16c0_s_p9_0,
  109207. 1, -518803456, 1628680192, 2, 0,
  109208. _vq_quantlist__16c0_s_p9_0,
  109209. NULL,
  109210. &_vq_auxt__16c0_s_p9_0,
  109211. NULL,
  109212. 0
  109213. };
  109214. static long _vq_quantlist__16c0_s_p9_1[] = {
  109215. 7,
  109216. 6,
  109217. 8,
  109218. 5,
  109219. 9,
  109220. 4,
  109221. 10,
  109222. 3,
  109223. 11,
  109224. 2,
  109225. 12,
  109226. 1,
  109227. 13,
  109228. 0,
  109229. 14,
  109230. };
  109231. static long _vq_lengthlist__16c0_s_p9_1[] = {
  109232. 1, 5, 5, 5, 5, 9,11,11,10,10,10,10,10,10,10, 7,
  109233. 6, 6, 6, 6,10,10,10,10,10,10,10,10,10,10, 7, 6,
  109234. 6, 6, 6,10, 9,10,10,10,10,10,10,10,10,10, 7, 7,
  109235. 8, 9,10,10,10,10,10,10,10,10,10,10,10, 8, 7,10,
  109236. 10,10, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109237. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109238. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109239. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109240. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109241. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109242. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109243. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109244. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109245. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109246. 10,
  109247. };
  109248. static float _vq_quantthresh__16c0_s_p9_1[] = {
  109249. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  109250. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  109251. };
  109252. static long _vq_quantmap__16c0_s_p9_1[] = {
  109253. 13, 11, 9, 7, 5, 3, 1, 0,
  109254. 2, 4, 6, 8, 10, 12, 14,
  109255. };
  109256. static encode_aux_threshmatch _vq_auxt__16c0_s_p9_1 = {
  109257. _vq_quantthresh__16c0_s_p9_1,
  109258. _vq_quantmap__16c0_s_p9_1,
  109259. 15,
  109260. 15
  109261. };
  109262. static static_codebook _16c0_s_p9_1 = {
  109263. 2, 225,
  109264. _vq_lengthlist__16c0_s_p9_1,
  109265. 1, -520986624, 1620377600, 4, 0,
  109266. _vq_quantlist__16c0_s_p9_1,
  109267. NULL,
  109268. &_vq_auxt__16c0_s_p9_1,
  109269. NULL,
  109270. 0
  109271. };
  109272. static long _vq_quantlist__16c0_s_p9_2[] = {
  109273. 10,
  109274. 9,
  109275. 11,
  109276. 8,
  109277. 12,
  109278. 7,
  109279. 13,
  109280. 6,
  109281. 14,
  109282. 5,
  109283. 15,
  109284. 4,
  109285. 16,
  109286. 3,
  109287. 17,
  109288. 2,
  109289. 18,
  109290. 1,
  109291. 19,
  109292. 0,
  109293. 20,
  109294. };
  109295. static long _vq_lengthlist__16c0_s_p9_2[] = {
  109296. 1, 5, 5, 7, 8, 8, 7, 9, 9, 9,12,12,11,12,12,10,
  109297. 10,11,12,12,12,11,12,12, 8, 9, 8, 7, 9,10,10,11,
  109298. 11,10,11,12,10,12,10,12,12,12,11,12,11, 9, 8, 8,
  109299. 9,10, 9, 8, 9,10,12,12,11,11,12,11,10,11,12,11,
  109300. 12,12, 8, 9, 9, 9,10,11,12,11,12,11,11,11,11,12,
  109301. 12,11,11,12,12,11,11, 9, 9, 8, 9, 9,11, 9, 9,10,
  109302. 9,11,11,11,11,12,11,11,10,12,12,12, 9,12,11,10,
  109303. 11,11,11,11,12,12,12,11,11,11,12,10,12,12,12,10,
  109304. 10, 9,10, 9,10,10, 9, 9, 9,10,10,12,10,11,11, 9,
  109305. 11,11,10,11,11,11,10,10,10, 9, 9,10,10, 9, 9,10,
  109306. 11,11,10,11,10,11,10,11,11,10,11,11,11,10, 9,10,
  109307. 10, 9,10, 9, 9,11, 9, 9,11,10,10,11,11,10,10,11,
  109308. 10,11, 8, 9,11,11,10, 9,10,11,11,10,11,11,10,10,
  109309. 10,11,10, 9,10,10,11, 9,10,10, 9,11,10,10,10,10,
  109310. 11,10,11,11, 9,11,10,11,10,10,11,11,10,10,10, 9,
  109311. 10,10,11,11,11, 9,10,10,10,10,10,11,10,10,10, 9,
  109312. 10,10,11,10,10,10,10,10, 9,10,11,10,10,10,10,11,
  109313. 11,11,10,10,10,10,10,11,10,11,10,11,10,10,10, 9,
  109314. 11,11,10,10,10,11,11,10,10,10,10,10,10,10,10,11,
  109315. 11, 9,10,10,10,11,10,11,10,10,10,11, 9,10,11,10,
  109316. 11,10,10, 9,10,10,10,11,10,11,10,10,10,10,10,11,
  109317. 11,10,11,11,10,10,11,11,10, 9, 9,10,10,10,10,10,
  109318. 9,11, 9,10,10,10,11,11,10,10,10,10,11,11,11,10,
  109319. 9, 9,10,10,11,10,10,10,10,10,11,11,11,10,10,10,
  109320. 11,11,11, 9,10,10,10,10, 9,10, 9,10,11,10,11,10,
  109321. 10,11,11,10,11,11,11,11,11,10,11,10,10,10, 9,11,
  109322. 11,10,11,11,11,11,11,11,11,11,11,10,11,10,10,10,
  109323. 10,11,10,10,11, 9,10,10,10,
  109324. };
  109325. static float _vq_quantthresh__16c0_s_p9_2[] = {
  109326. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  109327. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  109328. 6.5, 7.5, 8.5, 9.5,
  109329. };
  109330. static long _vq_quantmap__16c0_s_p9_2[] = {
  109331. 19, 17, 15, 13, 11, 9, 7, 5,
  109332. 3, 1, 0, 2, 4, 6, 8, 10,
  109333. 12, 14, 16, 18, 20,
  109334. };
  109335. static encode_aux_threshmatch _vq_auxt__16c0_s_p9_2 = {
  109336. _vq_quantthresh__16c0_s_p9_2,
  109337. _vq_quantmap__16c0_s_p9_2,
  109338. 21,
  109339. 21
  109340. };
  109341. static static_codebook _16c0_s_p9_2 = {
  109342. 2, 441,
  109343. _vq_lengthlist__16c0_s_p9_2,
  109344. 1, -529268736, 1611661312, 5, 0,
  109345. _vq_quantlist__16c0_s_p9_2,
  109346. NULL,
  109347. &_vq_auxt__16c0_s_p9_2,
  109348. NULL,
  109349. 0
  109350. };
  109351. static long _huff_lengthlist__16c0_s_single[] = {
  109352. 3, 4,19, 7, 9, 7, 8,11, 9,12, 4, 1,19, 6, 7, 7,
  109353. 8,10,11,13,18,18,18,18,18,18,18,18,18,18, 8, 6,
  109354. 18, 8, 9, 9,11,12,14,18, 9, 6,18, 9, 7, 8, 9,11,
  109355. 12,18, 7, 6,18, 8, 7, 7, 7, 9,11,17, 8, 8,18, 9,
  109356. 7, 6, 6, 8,11,17,10,10,18,12, 9, 8, 7, 9,12,18,
  109357. 13,15,18,15,13,11,10,11,15,18,14,18,18,18,18,18,
  109358. 16,16,18,18,
  109359. };
  109360. static static_codebook _huff_book__16c0_s_single = {
  109361. 2, 100,
  109362. _huff_lengthlist__16c0_s_single,
  109363. 0, 0, 0, 0, 0,
  109364. NULL,
  109365. NULL,
  109366. NULL,
  109367. NULL,
  109368. 0
  109369. };
  109370. static long _huff_lengthlist__16c1_s_long[] = {
  109371. 2, 5,20, 7,10, 7, 8,10,11,11, 4, 2,20, 5, 8, 6,
  109372. 7, 9,10,10,20,20,20,20,19,19,19,19,19,19, 7, 5,
  109373. 19, 6,10, 7, 9,11,13,17,11, 8,19,10, 7, 7, 8,10,
  109374. 11,15, 7, 5,19, 7, 7, 5, 6, 9,11,16, 7, 6,19, 8,
  109375. 7, 6, 6, 7, 9,13, 9, 9,19,11, 9, 8, 6, 7, 8,13,
  109376. 12,14,19,16,13,10, 9, 8, 9,13,14,17,19,18,18,17,
  109377. 12,11,11,13,
  109378. };
  109379. static static_codebook _huff_book__16c1_s_long = {
  109380. 2, 100,
  109381. _huff_lengthlist__16c1_s_long,
  109382. 0, 0, 0, 0, 0,
  109383. NULL,
  109384. NULL,
  109385. NULL,
  109386. NULL,
  109387. 0
  109388. };
  109389. static long _vq_quantlist__16c1_s_p1_0[] = {
  109390. 1,
  109391. 0,
  109392. 2,
  109393. };
  109394. static long _vq_lengthlist__16c1_s_p1_0[] = {
  109395. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  109396. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109400. 0, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  109401. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109405. 0, 0, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  109406. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 0,
  109441. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 7, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  109446. 0, 0, 0, 9, 9,11, 0, 0, 0, 0, 0, 0, 9,11,10, 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, 7, 9, 9, 0, 0,
  109451. 0, 0, 0, 0, 8,11, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  109452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109486. 0, 0, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  109487. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  109492. 0, 0, 0, 0, 0, 8, 9,11, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  109497. 0, 0, 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0, 0,
  109498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109728. 0, 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,
  109806. };
  109807. static float _vq_quantthresh__16c1_s_p1_0[] = {
  109808. -0.5, 0.5,
  109809. };
  109810. static long _vq_quantmap__16c1_s_p1_0[] = {
  109811. 1, 0, 2,
  109812. };
  109813. static encode_aux_threshmatch _vq_auxt__16c1_s_p1_0 = {
  109814. _vq_quantthresh__16c1_s_p1_0,
  109815. _vq_quantmap__16c1_s_p1_0,
  109816. 3,
  109817. 3
  109818. };
  109819. static static_codebook _16c1_s_p1_0 = {
  109820. 8, 6561,
  109821. _vq_lengthlist__16c1_s_p1_0,
  109822. 1, -535822336, 1611661312, 2, 0,
  109823. _vq_quantlist__16c1_s_p1_0,
  109824. NULL,
  109825. &_vq_auxt__16c1_s_p1_0,
  109826. NULL,
  109827. 0
  109828. };
  109829. static long _vq_quantlist__16c1_s_p2_0[] = {
  109830. 2,
  109831. 1,
  109832. 3,
  109833. 0,
  109834. 4,
  109835. };
  109836. static long _vq_lengthlist__16c1_s_p2_0[] = {
  109837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109876. 0,
  109877. };
  109878. static float _vq_quantthresh__16c1_s_p2_0[] = {
  109879. -1.5, -0.5, 0.5, 1.5,
  109880. };
  109881. static long _vq_quantmap__16c1_s_p2_0[] = {
  109882. 3, 1, 0, 2, 4,
  109883. };
  109884. static encode_aux_threshmatch _vq_auxt__16c1_s_p2_0 = {
  109885. _vq_quantthresh__16c1_s_p2_0,
  109886. _vq_quantmap__16c1_s_p2_0,
  109887. 5,
  109888. 5
  109889. };
  109890. static static_codebook _16c1_s_p2_0 = {
  109891. 4, 625,
  109892. _vq_lengthlist__16c1_s_p2_0,
  109893. 1, -533725184, 1611661312, 3, 0,
  109894. _vq_quantlist__16c1_s_p2_0,
  109895. NULL,
  109896. &_vq_auxt__16c1_s_p2_0,
  109897. NULL,
  109898. 0
  109899. };
  109900. static long _vq_quantlist__16c1_s_p3_0[] = {
  109901. 2,
  109902. 1,
  109903. 3,
  109904. 0,
  109905. 4,
  109906. };
  109907. static long _vq_lengthlist__16c1_s_p3_0[] = {
  109908. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  109910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109911. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7, 9, 9,
  109913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109914. 0, 0, 0, 0, 6, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  109915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109947. 0,
  109948. };
  109949. static float _vq_quantthresh__16c1_s_p3_0[] = {
  109950. -1.5, -0.5, 0.5, 1.5,
  109951. };
  109952. static long _vq_quantmap__16c1_s_p3_0[] = {
  109953. 3, 1, 0, 2, 4,
  109954. };
  109955. static encode_aux_threshmatch _vq_auxt__16c1_s_p3_0 = {
  109956. _vq_quantthresh__16c1_s_p3_0,
  109957. _vq_quantmap__16c1_s_p3_0,
  109958. 5,
  109959. 5
  109960. };
  109961. static static_codebook _16c1_s_p3_0 = {
  109962. 4, 625,
  109963. _vq_lengthlist__16c1_s_p3_0,
  109964. 1, -533725184, 1611661312, 3, 0,
  109965. _vq_quantlist__16c1_s_p3_0,
  109966. NULL,
  109967. &_vq_auxt__16c1_s_p3_0,
  109968. NULL,
  109969. 0
  109970. };
  109971. static long _vq_quantlist__16c1_s_p4_0[] = {
  109972. 4,
  109973. 3,
  109974. 5,
  109975. 2,
  109976. 6,
  109977. 1,
  109978. 7,
  109979. 0,
  109980. 8,
  109981. };
  109982. static long _vq_lengthlist__16c1_s_p4_0[] = {
  109983. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  109984. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  109985. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  109986. 8, 8, 0, 0, 0, 0, 0, 0, 0, 8, 9, 0, 0, 0, 0, 0,
  109987. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109988. 0,
  109989. };
  109990. static float _vq_quantthresh__16c1_s_p4_0[] = {
  109991. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  109992. };
  109993. static long _vq_quantmap__16c1_s_p4_0[] = {
  109994. 7, 5, 3, 1, 0, 2, 4, 6,
  109995. 8,
  109996. };
  109997. static encode_aux_threshmatch _vq_auxt__16c1_s_p4_0 = {
  109998. _vq_quantthresh__16c1_s_p4_0,
  109999. _vq_quantmap__16c1_s_p4_0,
  110000. 9,
  110001. 9
  110002. };
  110003. static static_codebook _16c1_s_p4_0 = {
  110004. 2, 81,
  110005. _vq_lengthlist__16c1_s_p4_0,
  110006. 1, -531628032, 1611661312, 4, 0,
  110007. _vq_quantlist__16c1_s_p4_0,
  110008. NULL,
  110009. &_vq_auxt__16c1_s_p4_0,
  110010. NULL,
  110011. 0
  110012. };
  110013. static long _vq_quantlist__16c1_s_p5_0[] = {
  110014. 4,
  110015. 3,
  110016. 5,
  110017. 2,
  110018. 6,
  110019. 1,
  110020. 7,
  110021. 0,
  110022. 8,
  110023. };
  110024. static long _vq_lengthlist__16c1_s_p5_0[] = {
  110025. 1, 3, 3, 5, 5, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  110026. 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0, 8, 8,
  110027. 8, 8, 9, 9, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  110028. 9, 9, 8, 8,10,10, 0, 0, 0, 9, 9, 8, 8,10,10, 0,
  110029. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  110030. 10,
  110031. };
  110032. static float _vq_quantthresh__16c1_s_p5_0[] = {
  110033. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  110034. };
  110035. static long _vq_quantmap__16c1_s_p5_0[] = {
  110036. 7, 5, 3, 1, 0, 2, 4, 6,
  110037. 8,
  110038. };
  110039. static encode_aux_threshmatch _vq_auxt__16c1_s_p5_0 = {
  110040. _vq_quantthresh__16c1_s_p5_0,
  110041. _vq_quantmap__16c1_s_p5_0,
  110042. 9,
  110043. 9
  110044. };
  110045. static static_codebook _16c1_s_p5_0 = {
  110046. 2, 81,
  110047. _vq_lengthlist__16c1_s_p5_0,
  110048. 1, -531628032, 1611661312, 4, 0,
  110049. _vq_quantlist__16c1_s_p5_0,
  110050. NULL,
  110051. &_vq_auxt__16c1_s_p5_0,
  110052. NULL,
  110053. 0
  110054. };
  110055. static long _vq_quantlist__16c1_s_p6_0[] = {
  110056. 8,
  110057. 7,
  110058. 9,
  110059. 6,
  110060. 10,
  110061. 5,
  110062. 11,
  110063. 4,
  110064. 12,
  110065. 3,
  110066. 13,
  110067. 2,
  110068. 14,
  110069. 1,
  110070. 15,
  110071. 0,
  110072. 16,
  110073. };
  110074. static long _vq_lengthlist__16c1_s_p6_0[] = {
  110075. 1, 3, 3, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,11,12,
  110076. 12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  110077. 12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  110078. 11,12,12, 0, 0, 0, 8, 8, 8, 9,10, 9,10,10,10,10,
  110079. 11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,11,
  110080. 11,11,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  110081. 11,11,12,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  110082. 10,11,11,12,12,13,13, 0, 0, 0, 9, 9, 9, 9,10,10,
  110083. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,10,
  110084. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  110085. 10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0, 0, 9,
  110086. 9,10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0, 0,
  110087. 10,10,11,10,11,11,12,12,13,13,13,13, 0, 0, 0, 0,
  110088. 0, 0, 0,10,10,11,11,12,12,13,13,13,13, 0, 0, 0,
  110089. 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14, 0, 0,
  110090. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14, 0,
  110091. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  110092. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,13,13,14,
  110093. 14,
  110094. };
  110095. static float _vq_quantthresh__16c1_s_p6_0[] = {
  110096. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  110097. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  110098. };
  110099. static long _vq_quantmap__16c1_s_p6_0[] = {
  110100. 15, 13, 11, 9, 7, 5, 3, 1,
  110101. 0, 2, 4, 6, 8, 10, 12, 14,
  110102. 16,
  110103. };
  110104. static encode_aux_threshmatch _vq_auxt__16c1_s_p6_0 = {
  110105. _vq_quantthresh__16c1_s_p6_0,
  110106. _vq_quantmap__16c1_s_p6_0,
  110107. 17,
  110108. 17
  110109. };
  110110. static static_codebook _16c1_s_p6_0 = {
  110111. 2, 289,
  110112. _vq_lengthlist__16c1_s_p6_0,
  110113. 1, -529530880, 1611661312, 5, 0,
  110114. _vq_quantlist__16c1_s_p6_0,
  110115. NULL,
  110116. &_vq_auxt__16c1_s_p6_0,
  110117. NULL,
  110118. 0
  110119. };
  110120. static long _vq_quantlist__16c1_s_p7_0[] = {
  110121. 1,
  110122. 0,
  110123. 2,
  110124. };
  110125. static long _vq_lengthlist__16c1_s_p7_0[] = {
  110126. 1, 4, 4, 6, 6, 6, 7, 6, 6, 4, 7, 7,10, 9,10,10,
  110127. 10, 9, 4, 7, 7,10,10,10,11,10,10, 6,10,10,11,11,
  110128. 11,11,10,10, 6,10, 9,11,11,11,11,10,10, 6,10,10,
  110129. 11,11,11,11,10,10, 7,11,11,11,11,11,12,12,11, 6,
  110130. 10,10,11,10,10,11,11,11, 6,10,10,10,11,10,11,11,
  110131. 11,
  110132. };
  110133. static float _vq_quantthresh__16c1_s_p7_0[] = {
  110134. -5.5, 5.5,
  110135. };
  110136. static long _vq_quantmap__16c1_s_p7_0[] = {
  110137. 1, 0, 2,
  110138. };
  110139. static encode_aux_threshmatch _vq_auxt__16c1_s_p7_0 = {
  110140. _vq_quantthresh__16c1_s_p7_0,
  110141. _vq_quantmap__16c1_s_p7_0,
  110142. 3,
  110143. 3
  110144. };
  110145. static static_codebook _16c1_s_p7_0 = {
  110146. 4, 81,
  110147. _vq_lengthlist__16c1_s_p7_0,
  110148. 1, -529137664, 1618345984, 2, 0,
  110149. _vq_quantlist__16c1_s_p7_0,
  110150. NULL,
  110151. &_vq_auxt__16c1_s_p7_0,
  110152. NULL,
  110153. 0
  110154. };
  110155. static long _vq_quantlist__16c1_s_p7_1[] = {
  110156. 5,
  110157. 4,
  110158. 6,
  110159. 3,
  110160. 7,
  110161. 2,
  110162. 8,
  110163. 1,
  110164. 9,
  110165. 0,
  110166. 10,
  110167. };
  110168. static long _vq_lengthlist__16c1_s_p7_1[] = {
  110169. 2, 3, 3, 5, 6, 7, 7, 7, 7, 8, 8,10,10,10, 6, 6,
  110170. 7, 7, 8, 8, 8, 8,10,10,10, 6, 6, 7, 7, 8, 8, 8,
  110171. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  110172. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  110173. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  110174. 8, 8, 8, 8, 8, 8, 9, 9,10,10,10,10,10, 8, 8, 8,
  110175. 8, 9, 9,10,10,10,10,10, 9, 9, 8, 8, 9, 9,10,10,
  110176. 10,10,10, 8, 8, 8, 8, 9, 9,
  110177. };
  110178. static float _vq_quantthresh__16c1_s_p7_1[] = {
  110179. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  110180. 3.5, 4.5,
  110181. };
  110182. static long _vq_quantmap__16c1_s_p7_1[] = {
  110183. 9, 7, 5, 3, 1, 0, 2, 4,
  110184. 6, 8, 10,
  110185. };
  110186. static encode_aux_threshmatch _vq_auxt__16c1_s_p7_1 = {
  110187. _vq_quantthresh__16c1_s_p7_1,
  110188. _vq_quantmap__16c1_s_p7_1,
  110189. 11,
  110190. 11
  110191. };
  110192. static static_codebook _16c1_s_p7_1 = {
  110193. 2, 121,
  110194. _vq_lengthlist__16c1_s_p7_1,
  110195. 1, -531365888, 1611661312, 4, 0,
  110196. _vq_quantlist__16c1_s_p7_1,
  110197. NULL,
  110198. &_vq_auxt__16c1_s_p7_1,
  110199. NULL,
  110200. 0
  110201. };
  110202. static long _vq_quantlist__16c1_s_p8_0[] = {
  110203. 6,
  110204. 5,
  110205. 7,
  110206. 4,
  110207. 8,
  110208. 3,
  110209. 9,
  110210. 2,
  110211. 10,
  110212. 1,
  110213. 11,
  110214. 0,
  110215. 12,
  110216. };
  110217. static long _vq_lengthlist__16c1_s_p8_0[] = {
  110218. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 6, 5, 5,
  110219. 7, 8, 8, 9, 8, 8, 9, 9,10,11, 6, 5, 5, 8, 8, 9,
  110220. 9, 8, 8, 9,10,10,11, 0, 8, 8, 8, 9, 9, 9, 9, 9,
  110221. 10,10,11,11, 0, 9, 9, 9, 8, 9, 9, 9, 9,10,10,11,
  110222. 11, 0,13,13, 9, 9,10,10,10,10,11,11,12,12, 0,14,
  110223. 13, 9, 9,10,10,10,10,11,11,12,12, 0, 0, 0,10,10,
  110224. 9, 9,11,11,12,12,13,12, 0, 0, 0,10,10, 9, 9,10,
  110225. 10,12,12,13,13, 0, 0, 0,13,14,11,10,11,11,12,12,
  110226. 13,14, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  110227. 0, 0, 0, 0,12,12,12,12,13,13,14,15, 0, 0, 0, 0,
  110228. 0,12,12,12,12,13,13,14,15,
  110229. };
  110230. static float _vq_quantthresh__16c1_s_p8_0[] = {
  110231. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  110232. 12.5, 17.5, 22.5, 27.5,
  110233. };
  110234. static long _vq_quantmap__16c1_s_p8_0[] = {
  110235. 11, 9, 7, 5, 3, 1, 0, 2,
  110236. 4, 6, 8, 10, 12,
  110237. };
  110238. static encode_aux_threshmatch _vq_auxt__16c1_s_p8_0 = {
  110239. _vq_quantthresh__16c1_s_p8_0,
  110240. _vq_quantmap__16c1_s_p8_0,
  110241. 13,
  110242. 13
  110243. };
  110244. static static_codebook _16c1_s_p8_0 = {
  110245. 2, 169,
  110246. _vq_lengthlist__16c1_s_p8_0,
  110247. 1, -526516224, 1616117760, 4, 0,
  110248. _vq_quantlist__16c1_s_p8_0,
  110249. NULL,
  110250. &_vq_auxt__16c1_s_p8_0,
  110251. NULL,
  110252. 0
  110253. };
  110254. static long _vq_quantlist__16c1_s_p8_1[] = {
  110255. 2,
  110256. 1,
  110257. 3,
  110258. 0,
  110259. 4,
  110260. };
  110261. static long _vq_lengthlist__16c1_s_p8_1[] = {
  110262. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  110263. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  110264. };
  110265. static float _vq_quantthresh__16c1_s_p8_1[] = {
  110266. -1.5, -0.5, 0.5, 1.5,
  110267. };
  110268. static long _vq_quantmap__16c1_s_p8_1[] = {
  110269. 3, 1, 0, 2, 4,
  110270. };
  110271. static encode_aux_threshmatch _vq_auxt__16c1_s_p8_1 = {
  110272. _vq_quantthresh__16c1_s_p8_1,
  110273. _vq_quantmap__16c1_s_p8_1,
  110274. 5,
  110275. 5
  110276. };
  110277. static static_codebook _16c1_s_p8_1 = {
  110278. 2, 25,
  110279. _vq_lengthlist__16c1_s_p8_1,
  110280. 1, -533725184, 1611661312, 3, 0,
  110281. _vq_quantlist__16c1_s_p8_1,
  110282. NULL,
  110283. &_vq_auxt__16c1_s_p8_1,
  110284. NULL,
  110285. 0
  110286. };
  110287. static long _vq_quantlist__16c1_s_p9_0[] = {
  110288. 6,
  110289. 5,
  110290. 7,
  110291. 4,
  110292. 8,
  110293. 3,
  110294. 9,
  110295. 2,
  110296. 10,
  110297. 1,
  110298. 11,
  110299. 0,
  110300. 12,
  110301. };
  110302. static long _vq_lengthlist__16c1_s_p9_0[] = {
  110303. 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110304. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110305. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110306. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110307. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110308. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110309. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110310. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110311. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110312. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110313. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110314. };
  110315. static float _vq_quantthresh__16c1_s_p9_0[] = {
  110316. -1732.5, -1417.5, -1102.5, -787.5, -472.5, -157.5, 157.5, 472.5,
  110317. 787.5, 1102.5, 1417.5, 1732.5,
  110318. };
  110319. static long _vq_quantmap__16c1_s_p9_0[] = {
  110320. 11, 9, 7, 5, 3, 1, 0, 2,
  110321. 4, 6, 8, 10, 12,
  110322. };
  110323. static encode_aux_threshmatch _vq_auxt__16c1_s_p9_0 = {
  110324. _vq_quantthresh__16c1_s_p9_0,
  110325. _vq_quantmap__16c1_s_p9_0,
  110326. 13,
  110327. 13
  110328. };
  110329. static static_codebook _16c1_s_p9_0 = {
  110330. 2, 169,
  110331. _vq_lengthlist__16c1_s_p9_0,
  110332. 1, -513964032, 1628680192, 4, 0,
  110333. _vq_quantlist__16c1_s_p9_0,
  110334. NULL,
  110335. &_vq_auxt__16c1_s_p9_0,
  110336. NULL,
  110337. 0
  110338. };
  110339. static long _vq_quantlist__16c1_s_p9_1[] = {
  110340. 7,
  110341. 6,
  110342. 8,
  110343. 5,
  110344. 9,
  110345. 4,
  110346. 10,
  110347. 3,
  110348. 11,
  110349. 2,
  110350. 12,
  110351. 1,
  110352. 13,
  110353. 0,
  110354. 14,
  110355. };
  110356. static long _vq_lengthlist__16c1_s_p9_1[] = {
  110357. 1, 4, 4, 4, 4, 8, 8,12,13,14,14,14,14,14,14, 6,
  110358. 6, 6, 6, 6,10, 9,14,14,14,14,14,14,14,14, 7, 6,
  110359. 5, 6, 6,10, 9,12,13,13,13,13,13,13,13,13, 7, 7,
  110360. 9, 9,11,11,12,13,13,13,13,13,13,13,13, 7, 7, 8,
  110361. 8,11,12,13,13,13,13,13,13,13,13,13,12,12,10,10,
  110362. 13,12,13,13,13,13,13,13,13,13,13,12,12,10,10,13,
  110363. 13,13,13,13,13,13,13,13,13,13,13,13,13,12,13,12,
  110364. 13,13,13,13,13,13,13,13,13,13,13,13,12,13,13,13,
  110365. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110366. 13,13,13,13,13,13,13,13,13,13,13,13,12,13,13,13,
  110367. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110368. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110369. 13,13,13,13,13,13,13,13,13,12,13,13,13,13,13,13,
  110370. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110371. 13,
  110372. };
  110373. static float _vq_quantthresh__16c1_s_p9_1[] = {
  110374. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  110375. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  110376. };
  110377. static long _vq_quantmap__16c1_s_p9_1[] = {
  110378. 13, 11, 9, 7, 5, 3, 1, 0,
  110379. 2, 4, 6, 8, 10, 12, 14,
  110380. };
  110381. static encode_aux_threshmatch _vq_auxt__16c1_s_p9_1 = {
  110382. _vq_quantthresh__16c1_s_p9_1,
  110383. _vq_quantmap__16c1_s_p9_1,
  110384. 15,
  110385. 15
  110386. };
  110387. static static_codebook _16c1_s_p9_1 = {
  110388. 2, 225,
  110389. _vq_lengthlist__16c1_s_p9_1,
  110390. 1, -520986624, 1620377600, 4, 0,
  110391. _vq_quantlist__16c1_s_p9_1,
  110392. NULL,
  110393. &_vq_auxt__16c1_s_p9_1,
  110394. NULL,
  110395. 0
  110396. };
  110397. static long _vq_quantlist__16c1_s_p9_2[] = {
  110398. 10,
  110399. 9,
  110400. 11,
  110401. 8,
  110402. 12,
  110403. 7,
  110404. 13,
  110405. 6,
  110406. 14,
  110407. 5,
  110408. 15,
  110409. 4,
  110410. 16,
  110411. 3,
  110412. 17,
  110413. 2,
  110414. 18,
  110415. 1,
  110416. 19,
  110417. 0,
  110418. 20,
  110419. };
  110420. static long _vq_lengthlist__16c1_s_p9_2[] = {
  110421. 1, 4, 4, 6, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9,10,
  110422. 10,10, 9,10,10,11,12,12, 8, 8, 8, 8, 9, 9, 9, 9,
  110423. 10,10,10,10,10,11,11,10,12,11,11,13,11, 7, 7, 8,
  110424. 8, 8, 8, 9, 9, 9,10,10,10,10, 9,10,10,11,11,12,
  110425. 11,11, 8, 8, 8, 8, 9, 9,10,10,10,10,11,11,11,11,
  110426. 11,11,11,12,11,12,12, 8, 8, 9, 9, 9, 9, 9,10,10,
  110427. 10,10,10,10,11,11,11,11,11,11,12,11, 9, 9, 9, 9,
  110428. 10,10,10,10,11,10,11,11,11,11,11,11,12,12,12,12,
  110429. 11, 9, 9, 9, 9,10,10,10,10,11,11,11,11,11,11,11,
  110430. 11,11,12,12,12,13, 9,10,10, 9,11,10,10,10,10,11,
  110431. 11,11,11,11,10,11,12,11,12,12,11,12,11,10, 9,10,
  110432. 10,11,10,11,11,11,11,11,11,11,11,11,12,12,11,12,
  110433. 12,12,10,10,10,11,10,11,11,11,11,11,11,11,11,11,
  110434. 11,11,12,13,12,12,11, 9,10,10,11,11,10,11,11,11,
  110435. 12,11,11,11,11,11,12,12,13,13,12,13,10,10,12,10,
  110436. 11,11,11,11,11,11,11,11,11,12,12,11,13,12,12,12,
  110437. 12,13,12,11,11,11,11,11,11,12,11,12,11,11,11,11,
  110438. 12,12,13,12,11,12,12,11,11,11,11,11,12,11,11,11,
  110439. 11,12,11,11,12,11,12,13,13,12,12,12,12,11,11,11,
  110440. 11,11,12,11,11,12,11,12,11,11,11,11,13,12,12,12,
  110441. 12,13,11,11,11,12,12,11,11,11,12,11,12,12,12,11,
  110442. 12,13,12,11,11,12,12,11,12,11,11,11,12,12,11,12,
  110443. 11,11,11,12,12,12,12,13,12,13,12,12,12,12,11,11,
  110444. 12,11,11,11,11,11,11,12,12,12,13,12,11,13,13,12,
  110445. 12,11,12,10,11,11,11,11,12,11,12,12,11,12,12,13,
  110446. 12,12,13,12,12,12,12,12,11,12,12,12,11,12,11,11,
  110447. 11,12,13,12,13,13,13,13,13,12,13,13,12,12,13,11,
  110448. 11,11,11,11,12,11,11,12,11,
  110449. };
  110450. static float _vq_quantthresh__16c1_s_p9_2[] = {
  110451. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  110452. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  110453. 6.5, 7.5, 8.5, 9.5,
  110454. };
  110455. static long _vq_quantmap__16c1_s_p9_2[] = {
  110456. 19, 17, 15, 13, 11, 9, 7, 5,
  110457. 3, 1, 0, 2, 4, 6, 8, 10,
  110458. 12, 14, 16, 18, 20,
  110459. };
  110460. static encode_aux_threshmatch _vq_auxt__16c1_s_p9_2 = {
  110461. _vq_quantthresh__16c1_s_p9_2,
  110462. _vq_quantmap__16c1_s_p9_2,
  110463. 21,
  110464. 21
  110465. };
  110466. static static_codebook _16c1_s_p9_2 = {
  110467. 2, 441,
  110468. _vq_lengthlist__16c1_s_p9_2,
  110469. 1, -529268736, 1611661312, 5, 0,
  110470. _vq_quantlist__16c1_s_p9_2,
  110471. NULL,
  110472. &_vq_auxt__16c1_s_p9_2,
  110473. NULL,
  110474. 0
  110475. };
  110476. static long _huff_lengthlist__16c1_s_short[] = {
  110477. 5, 6,17, 8,12, 9,10,10,12,13, 5, 2,17, 4, 9, 5,
  110478. 7, 8,11,13,16,16,16,16,16,16,16,16,16,16, 6, 4,
  110479. 16, 5,10, 5, 7,10,14,16,13, 9,16,11, 8, 7, 8, 9,
  110480. 13,16, 7, 4,16, 5, 7, 4, 6, 8,11,13, 8, 6,16, 7,
  110481. 8, 5, 5, 7, 9,13, 9, 8,16, 9, 8, 6, 6, 7, 9,13,
  110482. 11,11,16,10,10, 7, 7, 7, 9,13,13,13,16,13,13, 9,
  110483. 9, 9,10,13,
  110484. };
  110485. static static_codebook _huff_book__16c1_s_short = {
  110486. 2, 100,
  110487. _huff_lengthlist__16c1_s_short,
  110488. 0, 0, 0, 0, 0,
  110489. NULL,
  110490. NULL,
  110491. NULL,
  110492. NULL,
  110493. 0
  110494. };
  110495. static long _huff_lengthlist__16c2_s_long[] = {
  110496. 4, 7, 9, 9, 9, 8, 9,10,15,19, 5, 4, 5, 6, 7, 7,
  110497. 8, 9,14,16, 6, 5, 4, 5, 6, 7, 8,10,12,19, 7, 6,
  110498. 5, 4, 5, 6, 7, 9,11,18, 8, 7, 6, 5, 5, 5, 7, 9,
  110499. 10,17, 8, 7, 7, 5, 5, 5, 6, 7,12,18, 8, 8, 8, 7,
  110500. 7, 5, 5, 7,12,18, 8, 9,10, 9, 9, 7, 6, 7,12,17,
  110501. 14,18,16,16,15,12,11,10,12,18,15,17,18,18,18,15,
  110502. 14,14,16,18,
  110503. };
  110504. static static_codebook _huff_book__16c2_s_long = {
  110505. 2, 100,
  110506. _huff_lengthlist__16c2_s_long,
  110507. 0, 0, 0, 0, 0,
  110508. NULL,
  110509. NULL,
  110510. NULL,
  110511. NULL,
  110512. 0
  110513. };
  110514. static long _vq_quantlist__16c2_s_p1_0[] = {
  110515. 1,
  110516. 0,
  110517. 2,
  110518. };
  110519. static long _vq_lengthlist__16c2_s_p1_0[] = {
  110520. 1, 3, 3, 0, 0, 0, 0, 0, 0, 4, 5, 5, 0, 0, 0, 0,
  110521. 0, 0, 4, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110525. 0,
  110526. };
  110527. static float _vq_quantthresh__16c2_s_p1_0[] = {
  110528. -0.5, 0.5,
  110529. };
  110530. static long _vq_quantmap__16c2_s_p1_0[] = {
  110531. 1, 0, 2,
  110532. };
  110533. static encode_aux_threshmatch _vq_auxt__16c2_s_p1_0 = {
  110534. _vq_quantthresh__16c2_s_p1_0,
  110535. _vq_quantmap__16c2_s_p1_0,
  110536. 3,
  110537. 3
  110538. };
  110539. static static_codebook _16c2_s_p1_0 = {
  110540. 4, 81,
  110541. _vq_lengthlist__16c2_s_p1_0,
  110542. 1, -535822336, 1611661312, 2, 0,
  110543. _vq_quantlist__16c2_s_p1_0,
  110544. NULL,
  110545. &_vq_auxt__16c2_s_p1_0,
  110546. NULL,
  110547. 0
  110548. };
  110549. static long _vq_quantlist__16c2_s_p2_0[] = {
  110550. 2,
  110551. 1,
  110552. 3,
  110553. 0,
  110554. 4,
  110555. };
  110556. static long _vq_lengthlist__16c2_s_p2_0[] = {
  110557. 2, 4, 3, 7, 7, 0, 0, 0, 7, 8, 0, 0, 0, 8, 8, 0,
  110558. 0, 0, 8, 8, 0, 0, 0, 8, 8, 4, 5, 4, 8, 8, 0, 0,
  110559. 0, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0, 9, 9, 0, 0, 0,
  110560. 9, 9, 4, 4, 5, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0, 8,
  110561. 8, 0, 0, 0, 9, 9, 0, 0, 0, 9, 9, 7, 8, 8,10,10,
  110562. 0, 0, 0,12,11, 0, 0, 0,11,11, 0, 0, 0,14,13, 0,
  110563. 0, 0,14,13, 7, 8, 8, 9,10, 0, 0, 0,11,12, 0, 0,
  110564. 0,11,11, 0, 0, 0,14,14, 0, 0, 0,13,14, 0, 0, 0,
  110565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110569. 0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 8,11,11, 0, 0, 0,
  110570. 11,11, 0, 0, 0,12,11, 0, 0, 0,12,12, 0, 0, 0,13,
  110571. 13, 8, 8, 8,11,11, 0, 0, 0,11,11, 0, 0, 0,11,12,
  110572. 0, 0, 0,12,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0,
  110573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110577. 0, 0, 0, 0, 0, 8, 8, 8,12,11, 0, 0, 0,12,11, 0,
  110578. 0, 0,11,11, 0, 0, 0,13,13, 0, 0, 0,13,12, 8, 8,
  110579. 8,11,12, 0, 0, 0,11,12, 0, 0, 0,11,11, 0, 0, 0,
  110580. 13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110585. 0, 0, 8, 9, 9,14,13, 0, 0, 0,13,12, 0, 0, 0,13,
  110586. 13, 0, 0, 0,13,12, 0, 0, 0,13,13, 8, 9, 9,13,14,
  110587. 0, 0, 0,12,13, 0, 0, 0,13,13, 0, 0, 0,12,13, 0,
  110588. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 8,
  110593. 9, 9,14,13, 0, 0, 0,13,13, 0, 0, 0,13,12, 0, 0,
  110594. 0,13,13, 0, 0, 0,13,12, 8, 9, 9,14,14, 0, 0, 0,
  110595. 13,13, 0, 0, 0,12,13, 0, 0, 0,13,13, 0, 0, 0,12,
  110596. 13,
  110597. };
  110598. static float _vq_quantthresh__16c2_s_p2_0[] = {
  110599. -1.5, -0.5, 0.5, 1.5,
  110600. };
  110601. static long _vq_quantmap__16c2_s_p2_0[] = {
  110602. 3, 1, 0, 2, 4,
  110603. };
  110604. static encode_aux_threshmatch _vq_auxt__16c2_s_p2_0 = {
  110605. _vq_quantthresh__16c2_s_p2_0,
  110606. _vq_quantmap__16c2_s_p2_0,
  110607. 5,
  110608. 5
  110609. };
  110610. static static_codebook _16c2_s_p2_0 = {
  110611. 4, 625,
  110612. _vq_lengthlist__16c2_s_p2_0,
  110613. 1, -533725184, 1611661312, 3, 0,
  110614. _vq_quantlist__16c2_s_p2_0,
  110615. NULL,
  110616. &_vq_auxt__16c2_s_p2_0,
  110617. NULL,
  110618. 0
  110619. };
  110620. static long _vq_quantlist__16c2_s_p3_0[] = {
  110621. 4,
  110622. 3,
  110623. 5,
  110624. 2,
  110625. 6,
  110626. 1,
  110627. 7,
  110628. 0,
  110629. 8,
  110630. };
  110631. static long _vq_lengthlist__16c2_s_p3_0[] = {
  110632. 1, 3, 3, 6, 6, 7, 7, 8, 8, 0, 0, 0, 6, 6, 7, 7,
  110633. 9, 9, 0, 0, 0, 6, 6, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  110634. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  110635. 7, 7, 9, 9,10,10, 0, 0, 0, 7, 7, 9, 9,10,10, 0,
  110636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110637. 0,
  110638. };
  110639. static float _vq_quantthresh__16c2_s_p3_0[] = {
  110640. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  110641. };
  110642. static long _vq_quantmap__16c2_s_p3_0[] = {
  110643. 7, 5, 3, 1, 0, 2, 4, 6,
  110644. 8,
  110645. };
  110646. static encode_aux_threshmatch _vq_auxt__16c2_s_p3_0 = {
  110647. _vq_quantthresh__16c2_s_p3_0,
  110648. _vq_quantmap__16c2_s_p3_0,
  110649. 9,
  110650. 9
  110651. };
  110652. static static_codebook _16c2_s_p3_0 = {
  110653. 2, 81,
  110654. _vq_lengthlist__16c2_s_p3_0,
  110655. 1, -531628032, 1611661312, 4, 0,
  110656. _vq_quantlist__16c2_s_p3_0,
  110657. NULL,
  110658. &_vq_auxt__16c2_s_p3_0,
  110659. NULL,
  110660. 0
  110661. };
  110662. static long _vq_quantlist__16c2_s_p4_0[] = {
  110663. 8,
  110664. 7,
  110665. 9,
  110666. 6,
  110667. 10,
  110668. 5,
  110669. 11,
  110670. 4,
  110671. 12,
  110672. 3,
  110673. 13,
  110674. 2,
  110675. 14,
  110676. 1,
  110677. 15,
  110678. 0,
  110679. 16,
  110680. };
  110681. static long _vq_lengthlist__16c2_s_p4_0[] = {
  110682. 2, 3, 3, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9,10,
  110683. 10, 0, 0, 0, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,
  110684. 11,11, 0, 0, 0, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,
  110685. 10,10,11, 0, 0, 0, 6, 6, 8, 8, 8, 8, 9, 9,10,10,
  110686. 10,11,11,11, 0, 0, 0, 6, 6, 8, 8, 9, 9, 9, 9,10,
  110687. 10,11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,
  110688. 10,10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9,
  110689. 9,10,10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  110690. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 8, 8, 9,
  110691. 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 0, 0,
  110692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110700. 0,
  110701. };
  110702. static float _vq_quantthresh__16c2_s_p4_0[] = {
  110703. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  110704. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  110705. };
  110706. static long _vq_quantmap__16c2_s_p4_0[] = {
  110707. 15, 13, 11, 9, 7, 5, 3, 1,
  110708. 0, 2, 4, 6, 8, 10, 12, 14,
  110709. 16,
  110710. };
  110711. static encode_aux_threshmatch _vq_auxt__16c2_s_p4_0 = {
  110712. _vq_quantthresh__16c2_s_p4_0,
  110713. _vq_quantmap__16c2_s_p4_0,
  110714. 17,
  110715. 17
  110716. };
  110717. static static_codebook _16c2_s_p4_0 = {
  110718. 2, 289,
  110719. _vq_lengthlist__16c2_s_p4_0,
  110720. 1, -529530880, 1611661312, 5, 0,
  110721. _vq_quantlist__16c2_s_p4_0,
  110722. NULL,
  110723. &_vq_auxt__16c2_s_p4_0,
  110724. NULL,
  110725. 0
  110726. };
  110727. static long _vq_quantlist__16c2_s_p5_0[] = {
  110728. 1,
  110729. 0,
  110730. 2,
  110731. };
  110732. static long _vq_lengthlist__16c2_s_p5_0[] = {
  110733. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 6, 6,10,10,10,10,
  110734. 10,10, 4, 7, 6,10,10,10,10,10,10, 5, 9, 9, 9,12,
  110735. 11,10,11,12, 7,10,10,12,12,12,12,12,12, 7,10,10,
  110736. 11,12,12,12,12,13, 6,10,10,10,12,12,10,12,12, 7,
  110737. 10,10,11,13,12,12,12,12, 7,10,10,11,12,12,12,12,
  110738. 12,
  110739. };
  110740. static float _vq_quantthresh__16c2_s_p5_0[] = {
  110741. -5.5, 5.5,
  110742. };
  110743. static long _vq_quantmap__16c2_s_p5_0[] = {
  110744. 1, 0, 2,
  110745. };
  110746. static encode_aux_threshmatch _vq_auxt__16c2_s_p5_0 = {
  110747. _vq_quantthresh__16c2_s_p5_0,
  110748. _vq_quantmap__16c2_s_p5_0,
  110749. 3,
  110750. 3
  110751. };
  110752. static static_codebook _16c2_s_p5_0 = {
  110753. 4, 81,
  110754. _vq_lengthlist__16c2_s_p5_0,
  110755. 1, -529137664, 1618345984, 2, 0,
  110756. _vq_quantlist__16c2_s_p5_0,
  110757. NULL,
  110758. &_vq_auxt__16c2_s_p5_0,
  110759. NULL,
  110760. 0
  110761. };
  110762. static long _vq_quantlist__16c2_s_p5_1[] = {
  110763. 5,
  110764. 4,
  110765. 6,
  110766. 3,
  110767. 7,
  110768. 2,
  110769. 8,
  110770. 1,
  110771. 9,
  110772. 0,
  110773. 10,
  110774. };
  110775. static long _vq_lengthlist__16c2_s_p5_1[] = {
  110776. 2, 3, 3, 6, 6, 7, 7, 7, 7, 8, 8,11,11,11, 6, 6,
  110777. 7, 7, 8, 8, 8, 8,11,11,11, 6, 6, 7, 7, 8, 8, 8,
  110778. 8,11,11,11, 6, 6, 8, 8, 8, 8, 9, 9,11,11,11, 6,
  110779. 6, 8, 8, 8, 8, 9, 9,11,11,11, 7, 7, 8, 8, 8, 8,
  110780. 8, 8,11,11,11, 7, 7, 8, 8, 8, 8, 8, 9,11,11,11,
  110781. 8, 8, 8, 8, 8, 8, 8, 8,11,11,11,11,11, 8, 8, 8,
  110782. 8, 8, 8,11,11,11,11,11, 8, 8, 8, 8, 8, 8,11,11,
  110783. 11,11,11, 7, 7, 8, 8, 8, 8,
  110784. };
  110785. static float _vq_quantthresh__16c2_s_p5_1[] = {
  110786. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  110787. 3.5, 4.5,
  110788. };
  110789. static long _vq_quantmap__16c2_s_p5_1[] = {
  110790. 9, 7, 5, 3, 1, 0, 2, 4,
  110791. 6, 8, 10,
  110792. };
  110793. static encode_aux_threshmatch _vq_auxt__16c2_s_p5_1 = {
  110794. _vq_quantthresh__16c2_s_p5_1,
  110795. _vq_quantmap__16c2_s_p5_1,
  110796. 11,
  110797. 11
  110798. };
  110799. static static_codebook _16c2_s_p5_1 = {
  110800. 2, 121,
  110801. _vq_lengthlist__16c2_s_p5_1,
  110802. 1, -531365888, 1611661312, 4, 0,
  110803. _vq_quantlist__16c2_s_p5_1,
  110804. NULL,
  110805. &_vq_auxt__16c2_s_p5_1,
  110806. NULL,
  110807. 0
  110808. };
  110809. static long _vq_quantlist__16c2_s_p6_0[] = {
  110810. 6,
  110811. 5,
  110812. 7,
  110813. 4,
  110814. 8,
  110815. 3,
  110816. 9,
  110817. 2,
  110818. 10,
  110819. 1,
  110820. 11,
  110821. 0,
  110822. 12,
  110823. };
  110824. static long _vq_lengthlist__16c2_s_p6_0[] = {
  110825. 1, 4, 4, 7, 6, 8, 8, 9, 9,10,10,11,11, 5, 5, 5,
  110826. 7, 7, 9, 9, 9, 9,11,11,12,12, 6, 5, 5, 7, 7, 9,
  110827. 9,10,10,11,11,12,12, 0, 6, 6, 7, 7, 9, 9,10,10,
  110828. 11,11,12,12, 0, 7, 7, 7, 7, 9, 9,10,10,11,12,12,
  110829. 12, 0,11,11, 8, 8,10,10,11,11,12,12,13,13, 0,11,
  110830. 12, 8, 8,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  110831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110835. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110836. };
  110837. static float _vq_quantthresh__16c2_s_p6_0[] = {
  110838. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  110839. 12.5, 17.5, 22.5, 27.5,
  110840. };
  110841. static long _vq_quantmap__16c2_s_p6_0[] = {
  110842. 11, 9, 7, 5, 3, 1, 0, 2,
  110843. 4, 6, 8, 10, 12,
  110844. };
  110845. static encode_aux_threshmatch _vq_auxt__16c2_s_p6_0 = {
  110846. _vq_quantthresh__16c2_s_p6_0,
  110847. _vq_quantmap__16c2_s_p6_0,
  110848. 13,
  110849. 13
  110850. };
  110851. static static_codebook _16c2_s_p6_0 = {
  110852. 2, 169,
  110853. _vq_lengthlist__16c2_s_p6_0,
  110854. 1, -526516224, 1616117760, 4, 0,
  110855. _vq_quantlist__16c2_s_p6_0,
  110856. NULL,
  110857. &_vq_auxt__16c2_s_p6_0,
  110858. NULL,
  110859. 0
  110860. };
  110861. static long _vq_quantlist__16c2_s_p6_1[] = {
  110862. 2,
  110863. 1,
  110864. 3,
  110865. 0,
  110866. 4,
  110867. };
  110868. static long _vq_lengthlist__16c2_s_p6_1[] = {
  110869. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  110870. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  110871. };
  110872. static float _vq_quantthresh__16c2_s_p6_1[] = {
  110873. -1.5, -0.5, 0.5, 1.5,
  110874. };
  110875. static long _vq_quantmap__16c2_s_p6_1[] = {
  110876. 3, 1, 0, 2, 4,
  110877. };
  110878. static encode_aux_threshmatch _vq_auxt__16c2_s_p6_1 = {
  110879. _vq_quantthresh__16c2_s_p6_1,
  110880. _vq_quantmap__16c2_s_p6_1,
  110881. 5,
  110882. 5
  110883. };
  110884. static static_codebook _16c2_s_p6_1 = {
  110885. 2, 25,
  110886. _vq_lengthlist__16c2_s_p6_1,
  110887. 1, -533725184, 1611661312, 3, 0,
  110888. _vq_quantlist__16c2_s_p6_1,
  110889. NULL,
  110890. &_vq_auxt__16c2_s_p6_1,
  110891. NULL,
  110892. 0
  110893. };
  110894. static long _vq_quantlist__16c2_s_p7_0[] = {
  110895. 6,
  110896. 5,
  110897. 7,
  110898. 4,
  110899. 8,
  110900. 3,
  110901. 9,
  110902. 2,
  110903. 10,
  110904. 1,
  110905. 11,
  110906. 0,
  110907. 12,
  110908. };
  110909. static long _vq_lengthlist__16c2_s_p7_0[] = {
  110910. 1, 4, 4, 7, 7, 8, 8, 9, 9,10,10,11,11, 5, 5, 5,
  110911. 8, 8, 9, 9,10,10,11,11,12,12, 6, 5, 5, 8, 8, 9,
  110912. 9,10,10,11,11,12,13,18, 6, 6, 7, 7, 9, 9,10,10,
  110913. 12,12,13,13,18, 6, 6, 7, 7, 9, 9,10,10,12,12,13,
  110914. 13,18,11,10, 8, 8,10,10,11,11,12,12,13,13,18,11,
  110915. 11, 8, 8,10,10,11,11,12,13,13,13,18,18,18,10,11,
  110916. 11,11,12,12,13,13,14,14,18,18,18,11,11,11,11,12,
  110917. 12,13,13,14,14,18,18,18,14,14,12,12,12,12,14,14,
  110918. 15,14,18,18,18,15,15,11,12,12,12,13,13,15,15,18,
  110919. 18,18,18,18,13,13,13,13,13,14,17,16,18,18,18,18,
  110920. 18,13,14,13,13,14,13,15,14,
  110921. };
  110922. static float _vq_quantthresh__16c2_s_p7_0[] = {
  110923. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  110924. 27.5, 38.5, 49.5, 60.5,
  110925. };
  110926. static long _vq_quantmap__16c2_s_p7_0[] = {
  110927. 11, 9, 7, 5, 3, 1, 0, 2,
  110928. 4, 6, 8, 10, 12,
  110929. };
  110930. static encode_aux_threshmatch _vq_auxt__16c2_s_p7_0 = {
  110931. _vq_quantthresh__16c2_s_p7_0,
  110932. _vq_quantmap__16c2_s_p7_0,
  110933. 13,
  110934. 13
  110935. };
  110936. static static_codebook _16c2_s_p7_0 = {
  110937. 2, 169,
  110938. _vq_lengthlist__16c2_s_p7_0,
  110939. 1, -523206656, 1618345984, 4, 0,
  110940. _vq_quantlist__16c2_s_p7_0,
  110941. NULL,
  110942. &_vq_auxt__16c2_s_p7_0,
  110943. NULL,
  110944. 0
  110945. };
  110946. static long _vq_quantlist__16c2_s_p7_1[] = {
  110947. 5,
  110948. 4,
  110949. 6,
  110950. 3,
  110951. 7,
  110952. 2,
  110953. 8,
  110954. 1,
  110955. 9,
  110956. 0,
  110957. 10,
  110958. };
  110959. static long _vq_lengthlist__16c2_s_p7_1[] = {
  110960. 2, 4, 4, 6, 6, 7, 7, 7, 7, 7, 7, 9, 9, 9, 6, 6,
  110961. 7, 7, 8, 8, 8, 8, 9, 9, 9, 6, 6, 7, 7, 8, 8, 8,
  110962. 8, 9, 9, 9, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 7,
  110963. 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 7, 7, 7, 7, 8, 8,
  110964. 8, 8, 9, 9, 9, 7, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9,
  110965. 7, 7, 8, 8, 7, 7, 8, 8, 9, 9, 9, 9, 9, 7, 7, 7,
  110966. 7, 8, 8, 9, 9, 9, 9, 9, 8, 8, 7, 7, 8, 8, 9, 9,
  110967. 9, 9, 9, 7, 7, 7, 7, 8, 8,
  110968. };
  110969. static float _vq_quantthresh__16c2_s_p7_1[] = {
  110970. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  110971. 3.5, 4.5,
  110972. };
  110973. static long _vq_quantmap__16c2_s_p7_1[] = {
  110974. 9, 7, 5, 3, 1, 0, 2, 4,
  110975. 6, 8, 10,
  110976. };
  110977. static encode_aux_threshmatch _vq_auxt__16c2_s_p7_1 = {
  110978. _vq_quantthresh__16c2_s_p7_1,
  110979. _vq_quantmap__16c2_s_p7_1,
  110980. 11,
  110981. 11
  110982. };
  110983. static static_codebook _16c2_s_p7_1 = {
  110984. 2, 121,
  110985. _vq_lengthlist__16c2_s_p7_1,
  110986. 1, -531365888, 1611661312, 4, 0,
  110987. _vq_quantlist__16c2_s_p7_1,
  110988. NULL,
  110989. &_vq_auxt__16c2_s_p7_1,
  110990. NULL,
  110991. 0
  110992. };
  110993. static long _vq_quantlist__16c2_s_p8_0[] = {
  110994. 7,
  110995. 6,
  110996. 8,
  110997. 5,
  110998. 9,
  110999. 4,
  111000. 10,
  111001. 3,
  111002. 11,
  111003. 2,
  111004. 12,
  111005. 1,
  111006. 13,
  111007. 0,
  111008. 14,
  111009. };
  111010. static long _vq_lengthlist__16c2_s_p8_0[] = {
  111011. 1, 4, 4, 7, 6, 7, 7, 6, 6, 8, 8, 9, 9,10,10, 6,
  111012. 6, 6, 8, 8, 9, 8, 8, 8, 9, 9,11,10,11,11, 7, 6,
  111013. 6, 8, 8, 9, 8, 7, 7, 9, 9,10,10,12,11,14, 8, 8,
  111014. 8, 9, 9, 9, 9, 9,10, 9,10,10,11,13,14, 8, 8, 8,
  111015. 8, 9, 9, 8, 8, 9, 9,10,10,11,12,14,13,11, 9, 9,
  111016. 9, 9, 9, 9, 9,10,11,10,13,12,14,11,13, 8, 9, 9,
  111017. 9, 9, 9,10,10,11,10,13,12,14,14,14, 8, 9, 9, 9,
  111018. 11,11,11,11,11,12,13,13,14,14,14, 9, 8, 9, 9,10,
  111019. 10,12,10,11,12,12,14,14,14,14,11,12,10,10,12,12,
  111020. 12,12,13,14,12,12,14,14,14,12,12, 9,10,11,11,12,
  111021. 14,12,14,14,14,14,14,14,14,14,11,11,12,11,12,14,
  111022. 14,14,14,14,14,14,14,14,14,12,11,11,11,11,14,14,
  111023. 14,14,14,14,14,14,14,14,14,14,13,12,14,14,14,14,
  111024. 14,14,14,14,14,14,14,14,14,12,12,12,13,14,14,13,
  111025. 13,
  111026. };
  111027. static float _vq_quantthresh__16c2_s_p8_0[] = {
  111028. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  111029. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  111030. };
  111031. static long _vq_quantmap__16c2_s_p8_0[] = {
  111032. 13, 11, 9, 7, 5, 3, 1, 0,
  111033. 2, 4, 6, 8, 10, 12, 14,
  111034. };
  111035. static encode_aux_threshmatch _vq_auxt__16c2_s_p8_0 = {
  111036. _vq_quantthresh__16c2_s_p8_0,
  111037. _vq_quantmap__16c2_s_p8_0,
  111038. 15,
  111039. 15
  111040. };
  111041. static static_codebook _16c2_s_p8_0 = {
  111042. 2, 225,
  111043. _vq_lengthlist__16c2_s_p8_0,
  111044. 1, -520986624, 1620377600, 4, 0,
  111045. _vq_quantlist__16c2_s_p8_0,
  111046. NULL,
  111047. &_vq_auxt__16c2_s_p8_0,
  111048. NULL,
  111049. 0
  111050. };
  111051. static long _vq_quantlist__16c2_s_p8_1[] = {
  111052. 10,
  111053. 9,
  111054. 11,
  111055. 8,
  111056. 12,
  111057. 7,
  111058. 13,
  111059. 6,
  111060. 14,
  111061. 5,
  111062. 15,
  111063. 4,
  111064. 16,
  111065. 3,
  111066. 17,
  111067. 2,
  111068. 18,
  111069. 1,
  111070. 19,
  111071. 0,
  111072. 20,
  111073. };
  111074. static long _vq_lengthlist__16c2_s_p8_1[] = {
  111075. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 8, 8, 8,
  111076. 8, 8, 8, 8, 8,11,12,11, 7, 7, 8, 8, 8, 8, 9, 9,
  111077. 9, 9, 9, 9, 9, 9, 9,10, 9, 9,11,11,10, 7, 7, 8,
  111078. 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  111079. 11,11, 8, 7, 8, 8, 9, 9, 9, 9, 9, 9,10,10, 9,10,
  111080. 10, 9,10,10,11,11,12, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  111081. 9, 9, 9,10, 9,10,10,10,10,11,11,11, 8, 8, 9, 9,
  111082. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,11,11,
  111083. 11, 8, 8, 9, 8, 9, 9, 9, 9,10, 9, 9, 9,10,10,10,
  111084. 10, 9,10,11,11,11, 9, 9, 9, 9,10, 9, 9, 9,10,10,
  111085. 9,10, 9,10,10,10,10,10,11,12,11,11,11, 9, 9, 9,
  111086. 9, 9,10,10, 9,10,10,10,10,10,10,10,10,12,11,13,
  111087. 13,11, 9, 9, 9, 9,10,10, 9,10,10,10,10,11,10,10,
  111088. 10,10,11,12,11,12,11, 9, 9, 9,10,10, 9,10,10,10,
  111089. 10,10,10,10,10,10,10,11,11,11,12,11, 9,10,10,10,
  111090. 10,10,10,10,10,10,10,10,10,10,10,10,11,12,12,12,
  111091. 11,11,11,10, 9,10,10,10,10,10,10,10,10,11,10,10,
  111092. 10,11,11,11,11,11,11,11,10,10,10,11,10,10,10,10,
  111093. 10,10,10,10,10,10,11,11,11,11,12,12,11,10,10,10,
  111094. 10,10,10,10,10,11,10,10,10,11,10,12,11,11,12,11,
  111095. 11,11,10,10,10,10,10,11,10,10,10,10,10,11,10,10,
  111096. 11,11,11,12,11,12,11,11,12,10,10,10,10,10,10,10,
  111097. 11,10,10,11,10,12,11,11,11,12,11,11,11,11,10,10,
  111098. 10,10,10,10,10,11,11,11,10,11,12,11,11,11,12,11,
  111099. 12,11,12,10,11,10,10,10,10,11,10,10,10,10,10,10,
  111100. 12,11,11,11,11,11,12,12,10,10,10,10,10,11,10,10,
  111101. 11,10,11,11,11,11,11,11,11,11,11,11,11,11,12,11,
  111102. 10,11,10,10,10,10,10,10,10,
  111103. };
  111104. static float _vq_quantthresh__16c2_s_p8_1[] = {
  111105. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  111106. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  111107. 6.5, 7.5, 8.5, 9.5,
  111108. };
  111109. static long _vq_quantmap__16c2_s_p8_1[] = {
  111110. 19, 17, 15, 13, 11, 9, 7, 5,
  111111. 3, 1, 0, 2, 4, 6, 8, 10,
  111112. 12, 14, 16, 18, 20,
  111113. };
  111114. static encode_aux_threshmatch _vq_auxt__16c2_s_p8_1 = {
  111115. _vq_quantthresh__16c2_s_p8_1,
  111116. _vq_quantmap__16c2_s_p8_1,
  111117. 21,
  111118. 21
  111119. };
  111120. static static_codebook _16c2_s_p8_1 = {
  111121. 2, 441,
  111122. _vq_lengthlist__16c2_s_p8_1,
  111123. 1, -529268736, 1611661312, 5, 0,
  111124. _vq_quantlist__16c2_s_p8_1,
  111125. NULL,
  111126. &_vq_auxt__16c2_s_p8_1,
  111127. NULL,
  111128. 0
  111129. };
  111130. static long _vq_quantlist__16c2_s_p9_0[] = {
  111131. 6,
  111132. 5,
  111133. 7,
  111134. 4,
  111135. 8,
  111136. 3,
  111137. 9,
  111138. 2,
  111139. 10,
  111140. 1,
  111141. 11,
  111142. 0,
  111143. 12,
  111144. };
  111145. static long _vq_lengthlist__16c2_s_p9_0[] = {
  111146. 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111147. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111148. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111149. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111150. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111151. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111152. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111153. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111154. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111155. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111156. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111157. };
  111158. static float _vq_quantthresh__16c2_s_p9_0[] = {
  111159. -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -465.5, 465.5, 1396.5,
  111160. 2327.5, 3258.5, 4189.5, 5120.5,
  111161. };
  111162. static long _vq_quantmap__16c2_s_p9_0[] = {
  111163. 11, 9, 7, 5, 3, 1, 0, 2,
  111164. 4, 6, 8, 10, 12,
  111165. };
  111166. static encode_aux_threshmatch _vq_auxt__16c2_s_p9_0 = {
  111167. _vq_quantthresh__16c2_s_p9_0,
  111168. _vq_quantmap__16c2_s_p9_0,
  111169. 13,
  111170. 13
  111171. };
  111172. static static_codebook _16c2_s_p9_0 = {
  111173. 2, 169,
  111174. _vq_lengthlist__16c2_s_p9_0,
  111175. 1, -510275072, 1631393792, 4, 0,
  111176. _vq_quantlist__16c2_s_p9_0,
  111177. NULL,
  111178. &_vq_auxt__16c2_s_p9_0,
  111179. NULL,
  111180. 0
  111181. };
  111182. static long _vq_quantlist__16c2_s_p9_1[] = {
  111183. 8,
  111184. 7,
  111185. 9,
  111186. 6,
  111187. 10,
  111188. 5,
  111189. 11,
  111190. 4,
  111191. 12,
  111192. 3,
  111193. 13,
  111194. 2,
  111195. 14,
  111196. 1,
  111197. 15,
  111198. 0,
  111199. 16,
  111200. };
  111201. static long _vq_lengthlist__16c2_s_p9_1[] = {
  111202. 1, 5, 5, 9, 8, 7, 7, 7, 6,10,11,11,11,11,11,11,
  111203. 11, 8, 7, 6, 8, 8,10, 9,10,10,10, 9,11,10,10,10,
  111204. 10,10, 8, 6, 6, 8, 8, 9, 8, 9, 8, 9,10,10,10,10,
  111205. 10,10,10,10, 8,10, 9, 9, 9, 9,10,10,10,10,10,10,
  111206. 10,10,10,10,10, 8, 9, 9, 9,10,10, 9,10,10,10,10,
  111207. 10,10,10,10,10,10,10,10, 9, 8, 9, 9,10,10,10,10,
  111208. 10,10,10,10,10,10,10,10, 9, 8, 8, 9, 9,10,10,10,
  111209. 10,10,10,10,10,10,10,10,10,10, 9,10, 9, 9,10,10,
  111210. 10,10,10,10,10,10,10,10,10,10,10, 9, 8, 9, 9,10,
  111211. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  111212. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111213. 8,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111214. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111215. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111216. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111217. 10,10,10,10, 9,10, 9,10,10,10,10,10,10,10,10,10,
  111218. 10,10,10,10,10,10,10,10,10, 9,10,10,10,10,10,10,
  111219. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111220. 10,
  111221. };
  111222. static float _vq_quantthresh__16c2_s_p9_1[] = {
  111223. -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5, -24.5,
  111224. 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5, 367.5,
  111225. };
  111226. static long _vq_quantmap__16c2_s_p9_1[] = {
  111227. 15, 13, 11, 9, 7, 5, 3, 1,
  111228. 0, 2, 4, 6, 8, 10, 12, 14,
  111229. 16,
  111230. };
  111231. static encode_aux_threshmatch _vq_auxt__16c2_s_p9_1 = {
  111232. _vq_quantthresh__16c2_s_p9_1,
  111233. _vq_quantmap__16c2_s_p9_1,
  111234. 17,
  111235. 17
  111236. };
  111237. static static_codebook _16c2_s_p9_1 = {
  111238. 2, 289,
  111239. _vq_lengthlist__16c2_s_p9_1,
  111240. 1, -518488064, 1622704128, 5, 0,
  111241. _vq_quantlist__16c2_s_p9_1,
  111242. NULL,
  111243. &_vq_auxt__16c2_s_p9_1,
  111244. NULL,
  111245. 0
  111246. };
  111247. static long _vq_quantlist__16c2_s_p9_2[] = {
  111248. 13,
  111249. 12,
  111250. 14,
  111251. 11,
  111252. 15,
  111253. 10,
  111254. 16,
  111255. 9,
  111256. 17,
  111257. 8,
  111258. 18,
  111259. 7,
  111260. 19,
  111261. 6,
  111262. 20,
  111263. 5,
  111264. 21,
  111265. 4,
  111266. 22,
  111267. 3,
  111268. 23,
  111269. 2,
  111270. 24,
  111271. 1,
  111272. 25,
  111273. 0,
  111274. 26,
  111275. };
  111276. static long _vq_lengthlist__16c2_s_p9_2[] = {
  111277. 1, 4, 4, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7,
  111278. 7, 7, 7, 7, 8, 7, 8, 7, 7, 4, 4,
  111279. };
  111280. static float _vq_quantthresh__16c2_s_p9_2[] = {
  111281. -12.5, -11.5, -10.5, -9.5, -8.5, -7.5, -6.5, -5.5,
  111282. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  111283. 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5,
  111284. 11.5, 12.5,
  111285. };
  111286. static long _vq_quantmap__16c2_s_p9_2[] = {
  111287. 25, 23, 21, 19, 17, 15, 13, 11,
  111288. 9, 7, 5, 3, 1, 0, 2, 4,
  111289. 6, 8, 10, 12, 14, 16, 18, 20,
  111290. 22, 24, 26,
  111291. };
  111292. static encode_aux_threshmatch _vq_auxt__16c2_s_p9_2 = {
  111293. _vq_quantthresh__16c2_s_p9_2,
  111294. _vq_quantmap__16c2_s_p9_2,
  111295. 27,
  111296. 27
  111297. };
  111298. static static_codebook _16c2_s_p9_2 = {
  111299. 1, 27,
  111300. _vq_lengthlist__16c2_s_p9_2,
  111301. 1, -528875520, 1611661312, 5, 0,
  111302. _vq_quantlist__16c2_s_p9_2,
  111303. NULL,
  111304. &_vq_auxt__16c2_s_p9_2,
  111305. NULL,
  111306. 0
  111307. };
  111308. static long _huff_lengthlist__16c2_s_short[] = {
  111309. 7,10,11,11,11,14,15,15,17,14, 8, 6, 7, 7, 8, 9,
  111310. 11,11,14,17, 9, 6, 6, 6, 7, 7,10,11,15,16, 9, 6,
  111311. 6, 4, 4, 5, 8, 9,12,16,10, 6, 6, 4, 4, 4, 6, 9,
  111312. 13,16,10, 7, 6, 5, 4, 3, 5, 7,13,16,11, 9, 8, 7,
  111313. 6, 5, 5, 6,12,15,10,10,10, 9, 7, 6, 6, 7,11,15,
  111314. 13,13,13,13,11,10,10, 9,12,16,16,16,16,14,16,15,
  111315. 15,12,14,14,
  111316. };
  111317. static static_codebook _huff_book__16c2_s_short = {
  111318. 2, 100,
  111319. _huff_lengthlist__16c2_s_short,
  111320. 0, 0, 0, 0, 0,
  111321. NULL,
  111322. NULL,
  111323. NULL,
  111324. NULL,
  111325. 0
  111326. };
  111327. static long _vq_quantlist__8c0_s_p1_0[] = {
  111328. 1,
  111329. 0,
  111330. 2,
  111331. };
  111332. static long _vq_lengthlist__8c0_s_p1_0[] = {
  111333. 1, 5, 4, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  111334. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111338. 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 9, 0, 0, 0,
  111339. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111343. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  111344. 0, 0, 0, 0, 7, 9, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  111379. 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 7,10, 9, 0, 0, 0,
  111384. 0, 0, 0, 8, 9,11, 0, 0, 0, 0, 0, 0, 9,11,11, 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, 7, 9,10, 0, 0,
  111389. 0, 0, 0, 0, 9,11,10, 0, 0, 0, 0, 0, 0, 9,11,11,
  111390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111424. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  111425. 0, 0, 0, 0, 8, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,11, 0,
  111430. 0, 0, 0, 0, 0, 9,10,11, 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, 7, 9,10, 0, 0, 0, 0, 0, 0, 9,11,11,
  111435. 0, 0, 0, 0, 0, 0, 8,11, 9, 0, 0, 0, 0, 0, 0, 0,
  111436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111666. 0, 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,
  111744. };
  111745. static float _vq_quantthresh__8c0_s_p1_0[] = {
  111746. -0.5, 0.5,
  111747. };
  111748. static long _vq_quantmap__8c0_s_p1_0[] = {
  111749. 1, 0, 2,
  111750. };
  111751. static encode_aux_threshmatch _vq_auxt__8c0_s_p1_0 = {
  111752. _vq_quantthresh__8c0_s_p1_0,
  111753. _vq_quantmap__8c0_s_p1_0,
  111754. 3,
  111755. 3
  111756. };
  111757. static static_codebook _8c0_s_p1_0 = {
  111758. 8, 6561,
  111759. _vq_lengthlist__8c0_s_p1_0,
  111760. 1, -535822336, 1611661312, 2, 0,
  111761. _vq_quantlist__8c0_s_p1_0,
  111762. NULL,
  111763. &_vq_auxt__8c0_s_p1_0,
  111764. NULL,
  111765. 0
  111766. };
  111767. static long _vq_quantlist__8c0_s_p2_0[] = {
  111768. 2,
  111769. 1,
  111770. 3,
  111771. 0,
  111772. 4,
  111773. };
  111774. static long _vq_lengthlist__8c0_s_p2_0[] = {
  111775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111814. 0,
  111815. };
  111816. static float _vq_quantthresh__8c0_s_p2_0[] = {
  111817. -1.5, -0.5, 0.5, 1.5,
  111818. };
  111819. static long _vq_quantmap__8c0_s_p2_0[] = {
  111820. 3, 1, 0, 2, 4,
  111821. };
  111822. static encode_aux_threshmatch _vq_auxt__8c0_s_p2_0 = {
  111823. _vq_quantthresh__8c0_s_p2_0,
  111824. _vq_quantmap__8c0_s_p2_0,
  111825. 5,
  111826. 5
  111827. };
  111828. static static_codebook _8c0_s_p2_0 = {
  111829. 4, 625,
  111830. _vq_lengthlist__8c0_s_p2_0,
  111831. 1, -533725184, 1611661312, 3, 0,
  111832. _vq_quantlist__8c0_s_p2_0,
  111833. NULL,
  111834. &_vq_auxt__8c0_s_p2_0,
  111835. NULL,
  111836. 0
  111837. };
  111838. static long _vq_quantlist__8c0_s_p3_0[] = {
  111839. 2,
  111840. 1,
  111841. 3,
  111842. 0,
  111843. 4,
  111844. };
  111845. static long _vq_lengthlist__8c0_s_p3_0[] = {
  111846. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 6, 7, 7, 0, 0,
  111848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111849. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 8, 8,
  111851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111852. 0, 0, 0, 0, 6, 7, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  111853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111885. 0,
  111886. };
  111887. static float _vq_quantthresh__8c0_s_p3_0[] = {
  111888. -1.5, -0.5, 0.5, 1.5,
  111889. };
  111890. static long _vq_quantmap__8c0_s_p3_0[] = {
  111891. 3, 1, 0, 2, 4,
  111892. };
  111893. static encode_aux_threshmatch _vq_auxt__8c0_s_p3_0 = {
  111894. _vq_quantthresh__8c0_s_p3_0,
  111895. _vq_quantmap__8c0_s_p3_0,
  111896. 5,
  111897. 5
  111898. };
  111899. static static_codebook _8c0_s_p3_0 = {
  111900. 4, 625,
  111901. _vq_lengthlist__8c0_s_p3_0,
  111902. 1, -533725184, 1611661312, 3, 0,
  111903. _vq_quantlist__8c0_s_p3_0,
  111904. NULL,
  111905. &_vq_auxt__8c0_s_p3_0,
  111906. NULL,
  111907. 0
  111908. };
  111909. static long _vq_quantlist__8c0_s_p4_0[] = {
  111910. 4,
  111911. 3,
  111912. 5,
  111913. 2,
  111914. 6,
  111915. 1,
  111916. 7,
  111917. 0,
  111918. 8,
  111919. };
  111920. static long _vq_lengthlist__8c0_s_p4_0[] = {
  111921. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  111922. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  111923. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  111924. 8, 8, 0, 0, 0, 0, 0, 0, 0, 9, 8, 0, 0, 0, 0, 0,
  111925. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111926. 0,
  111927. };
  111928. static float _vq_quantthresh__8c0_s_p4_0[] = {
  111929. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  111930. };
  111931. static long _vq_quantmap__8c0_s_p4_0[] = {
  111932. 7, 5, 3, 1, 0, 2, 4, 6,
  111933. 8,
  111934. };
  111935. static encode_aux_threshmatch _vq_auxt__8c0_s_p4_0 = {
  111936. _vq_quantthresh__8c0_s_p4_0,
  111937. _vq_quantmap__8c0_s_p4_0,
  111938. 9,
  111939. 9
  111940. };
  111941. static static_codebook _8c0_s_p4_0 = {
  111942. 2, 81,
  111943. _vq_lengthlist__8c0_s_p4_0,
  111944. 1, -531628032, 1611661312, 4, 0,
  111945. _vq_quantlist__8c0_s_p4_0,
  111946. NULL,
  111947. &_vq_auxt__8c0_s_p4_0,
  111948. NULL,
  111949. 0
  111950. };
  111951. static long _vq_quantlist__8c0_s_p5_0[] = {
  111952. 4,
  111953. 3,
  111954. 5,
  111955. 2,
  111956. 6,
  111957. 1,
  111958. 7,
  111959. 0,
  111960. 8,
  111961. };
  111962. static long _vq_lengthlist__8c0_s_p5_0[] = {
  111963. 1, 3, 3, 5, 5, 7, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  111964. 8, 8, 0, 0, 0, 7, 7, 7, 7, 8, 9, 0, 0, 0, 8, 8,
  111965. 8, 8, 9, 9, 0, 0, 0, 8, 8, 8, 8, 9, 9, 0, 0, 0,
  111966. 9, 9, 8, 8,10,10, 0, 0, 0, 9, 9, 8, 8,10,10, 0,
  111967. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  111968. 10,
  111969. };
  111970. static float _vq_quantthresh__8c0_s_p5_0[] = {
  111971. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  111972. };
  111973. static long _vq_quantmap__8c0_s_p5_0[] = {
  111974. 7, 5, 3, 1, 0, 2, 4, 6,
  111975. 8,
  111976. };
  111977. static encode_aux_threshmatch _vq_auxt__8c0_s_p5_0 = {
  111978. _vq_quantthresh__8c0_s_p5_0,
  111979. _vq_quantmap__8c0_s_p5_0,
  111980. 9,
  111981. 9
  111982. };
  111983. static static_codebook _8c0_s_p5_0 = {
  111984. 2, 81,
  111985. _vq_lengthlist__8c0_s_p5_0,
  111986. 1, -531628032, 1611661312, 4, 0,
  111987. _vq_quantlist__8c0_s_p5_0,
  111988. NULL,
  111989. &_vq_auxt__8c0_s_p5_0,
  111990. NULL,
  111991. 0
  111992. };
  111993. static long _vq_quantlist__8c0_s_p6_0[] = {
  111994. 8,
  111995. 7,
  111996. 9,
  111997. 6,
  111998. 10,
  111999. 5,
  112000. 11,
  112001. 4,
  112002. 12,
  112003. 3,
  112004. 13,
  112005. 2,
  112006. 14,
  112007. 1,
  112008. 15,
  112009. 0,
  112010. 16,
  112011. };
  112012. static long _vq_lengthlist__8c0_s_p6_0[] = {
  112013. 1, 3, 3, 6, 6, 8, 8, 9, 9, 8, 8,10, 9,10,10,11,
  112014. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  112015. 11,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  112016. 11,12,11, 0, 0, 0, 8, 8, 9, 9,10,10, 9, 9,10,10,
  112017. 11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10, 9, 9,11,
  112018. 10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,10,10,
  112019. 11,11,11,12,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,10,
  112020. 10,11,11,12,12,13,13, 0, 0, 0,10,10,10,10,11,11,
  112021. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,10, 9,10,
  112022. 11,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  112023. 10, 9,10,11,12,12,13,13,14,13, 0, 0, 0, 0, 0, 9,
  112024. 9, 9,10,10,10,11,11,13,12,13,13, 0, 0, 0, 0, 0,
  112025. 10,10,10,10,11,11,12,12,13,13,14,14, 0, 0, 0, 0,
  112026. 0, 0, 0,10,10,11,11,12,12,13,13,13,14, 0, 0, 0,
  112027. 0, 0, 0, 0,11,11,11,11,12,12,13,14,14,14, 0, 0,
  112028. 0, 0, 0, 0, 0,11,11,11,11,12,12,13,13,14,13, 0,
  112029. 0, 0, 0, 0, 0, 0,11,11,12,12,13,13,14,14,14,14,
  112030. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  112031. 14,
  112032. };
  112033. static float _vq_quantthresh__8c0_s_p6_0[] = {
  112034. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  112035. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  112036. };
  112037. static long _vq_quantmap__8c0_s_p6_0[] = {
  112038. 15, 13, 11, 9, 7, 5, 3, 1,
  112039. 0, 2, 4, 6, 8, 10, 12, 14,
  112040. 16,
  112041. };
  112042. static encode_aux_threshmatch _vq_auxt__8c0_s_p6_0 = {
  112043. _vq_quantthresh__8c0_s_p6_0,
  112044. _vq_quantmap__8c0_s_p6_0,
  112045. 17,
  112046. 17
  112047. };
  112048. static static_codebook _8c0_s_p6_0 = {
  112049. 2, 289,
  112050. _vq_lengthlist__8c0_s_p6_0,
  112051. 1, -529530880, 1611661312, 5, 0,
  112052. _vq_quantlist__8c0_s_p6_0,
  112053. NULL,
  112054. &_vq_auxt__8c0_s_p6_0,
  112055. NULL,
  112056. 0
  112057. };
  112058. static long _vq_quantlist__8c0_s_p7_0[] = {
  112059. 1,
  112060. 0,
  112061. 2,
  112062. };
  112063. static long _vq_lengthlist__8c0_s_p7_0[] = {
  112064. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,11, 9,10,12,
  112065. 9,10, 4, 7, 7,10,10,10,11, 9, 9, 6,11,10,11,11,
  112066. 12,11,11,11, 6,10,10,11,11,12,11,10,10, 6, 9,10,
  112067. 11,11,11,11,10,10, 7,10,11,12,11,11,12,11,12, 6,
  112068. 9, 9,10, 9, 9,11,10,10, 6, 9, 9,10,10,10,11,10,
  112069. 10,
  112070. };
  112071. static float _vq_quantthresh__8c0_s_p7_0[] = {
  112072. -5.5, 5.5,
  112073. };
  112074. static long _vq_quantmap__8c0_s_p7_0[] = {
  112075. 1, 0, 2,
  112076. };
  112077. static encode_aux_threshmatch _vq_auxt__8c0_s_p7_0 = {
  112078. _vq_quantthresh__8c0_s_p7_0,
  112079. _vq_quantmap__8c0_s_p7_0,
  112080. 3,
  112081. 3
  112082. };
  112083. static static_codebook _8c0_s_p7_0 = {
  112084. 4, 81,
  112085. _vq_lengthlist__8c0_s_p7_0,
  112086. 1, -529137664, 1618345984, 2, 0,
  112087. _vq_quantlist__8c0_s_p7_0,
  112088. NULL,
  112089. &_vq_auxt__8c0_s_p7_0,
  112090. NULL,
  112091. 0
  112092. };
  112093. static long _vq_quantlist__8c0_s_p7_1[] = {
  112094. 5,
  112095. 4,
  112096. 6,
  112097. 3,
  112098. 7,
  112099. 2,
  112100. 8,
  112101. 1,
  112102. 9,
  112103. 0,
  112104. 10,
  112105. };
  112106. static long _vq_lengthlist__8c0_s_p7_1[] = {
  112107. 1, 3, 3, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10, 7, 7,
  112108. 8, 8, 9, 9, 9, 9,10,10, 9, 7, 7, 8, 8, 9, 9, 9,
  112109. 9,10,10,10, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10, 8,
  112110. 8, 9, 9, 9, 9, 8, 9,10,10,10, 8, 8, 9, 9, 9,10,
  112111. 10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,10,11,10,11,
  112112. 9, 9, 9, 9,10,10,10,10,11,11,11,10,10, 9, 9,10,
  112113. 10,10, 9,11,10,10,10,10,10,10, 9, 9,10,10,11,11,
  112114. 10,10,10, 9, 9, 9,10,10,10,
  112115. };
  112116. static float _vq_quantthresh__8c0_s_p7_1[] = {
  112117. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  112118. 3.5, 4.5,
  112119. };
  112120. static long _vq_quantmap__8c0_s_p7_1[] = {
  112121. 9, 7, 5, 3, 1, 0, 2, 4,
  112122. 6, 8, 10,
  112123. };
  112124. static encode_aux_threshmatch _vq_auxt__8c0_s_p7_1 = {
  112125. _vq_quantthresh__8c0_s_p7_1,
  112126. _vq_quantmap__8c0_s_p7_1,
  112127. 11,
  112128. 11
  112129. };
  112130. static static_codebook _8c0_s_p7_1 = {
  112131. 2, 121,
  112132. _vq_lengthlist__8c0_s_p7_1,
  112133. 1, -531365888, 1611661312, 4, 0,
  112134. _vq_quantlist__8c0_s_p7_1,
  112135. NULL,
  112136. &_vq_auxt__8c0_s_p7_1,
  112137. NULL,
  112138. 0
  112139. };
  112140. static long _vq_quantlist__8c0_s_p8_0[] = {
  112141. 6,
  112142. 5,
  112143. 7,
  112144. 4,
  112145. 8,
  112146. 3,
  112147. 9,
  112148. 2,
  112149. 10,
  112150. 1,
  112151. 11,
  112152. 0,
  112153. 12,
  112154. };
  112155. static long _vq_lengthlist__8c0_s_p8_0[] = {
  112156. 1, 4, 4, 7, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 6, 6,
  112157. 7, 7, 8, 8, 7, 7, 8, 9,10,10, 7, 6, 6, 7, 7, 8,
  112158. 7, 7, 7, 9, 9,10,12, 0, 8, 8, 8, 8, 8, 9, 8, 8,
  112159. 9, 9,10,10, 0, 8, 8, 8, 8, 8, 9, 8, 9, 9, 9,11,
  112160. 10, 0, 0,13, 9, 8, 9, 9, 9, 9,10,10,11,11, 0,13,
  112161. 0, 9, 9, 9, 9, 9, 9,11,10,11,11, 0, 0, 0, 8, 9,
  112162. 10, 9,10,10,13,11,12,12, 0, 0, 0, 8, 9, 9, 9,10,
  112163. 10,13,12,12,13, 0, 0, 0,12, 0,10,10,12,11,10,11,
  112164. 12,12, 0, 0, 0,13,13,10,10,10,11,12, 0,13, 0, 0,
  112165. 0, 0, 0, 0,13,11, 0,12,12,12,13,12, 0, 0, 0, 0,
  112166. 0, 0,13,13,11,13,13,11,12,
  112167. };
  112168. static float _vq_quantthresh__8c0_s_p8_0[] = {
  112169. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  112170. 12.5, 17.5, 22.5, 27.5,
  112171. };
  112172. static long _vq_quantmap__8c0_s_p8_0[] = {
  112173. 11, 9, 7, 5, 3, 1, 0, 2,
  112174. 4, 6, 8, 10, 12,
  112175. };
  112176. static encode_aux_threshmatch _vq_auxt__8c0_s_p8_0 = {
  112177. _vq_quantthresh__8c0_s_p8_0,
  112178. _vq_quantmap__8c0_s_p8_0,
  112179. 13,
  112180. 13
  112181. };
  112182. static static_codebook _8c0_s_p8_0 = {
  112183. 2, 169,
  112184. _vq_lengthlist__8c0_s_p8_0,
  112185. 1, -526516224, 1616117760, 4, 0,
  112186. _vq_quantlist__8c0_s_p8_0,
  112187. NULL,
  112188. &_vq_auxt__8c0_s_p8_0,
  112189. NULL,
  112190. 0
  112191. };
  112192. static long _vq_quantlist__8c0_s_p8_1[] = {
  112193. 2,
  112194. 1,
  112195. 3,
  112196. 0,
  112197. 4,
  112198. };
  112199. static long _vq_lengthlist__8c0_s_p8_1[] = {
  112200. 1, 3, 4, 5, 5, 7, 6, 6, 6, 5, 7, 7, 7, 6, 6, 7,
  112201. 7, 7, 6, 6, 7, 7, 7, 6, 6,
  112202. };
  112203. static float _vq_quantthresh__8c0_s_p8_1[] = {
  112204. -1.5, -0.5, 0.5, 1.5,
  112205. };
  112206. static long _vq_quantmap__8c0_s_p8_1[] = {
  112207. 3, 1, 0, 2, 4,
  112208. };
  112209. static encode_aux_threshmatch _vq_auxt__8c0_s_p8_1 = {
  112210. _vq_quantthresh__8c0_s_p8_1,
  112211. _vq_quantmap__8c0_s_p8_1,
  112212. 5,
  112213. 5
  112214. };
  112215. static static_codebook _8c0_s_p8_1 = {
  112216. 2, 25,
  112217. _vq_lengthlist__8c0_s_p8_1,
  112218. 1, -533725184, 1611661312, 3, 0,
  112219. _vq_quantlist__8c0_s_p8_1,
  112220. NULL,
  112221. &_vq_auxt__8c0_s_p8_1,
  112222. NULL,
  112223. 0
  112224. };
  112225. static long _vq_quantlist__8c0_s_p9_0[] = {
  112226. 1,
  112227. 0,
  112228. 2,
  112229. };
  112230. static long _vq_lengthlist__8c0_s_p9_0[] = {
  112231. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  112232. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  112233. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  112234. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  112235. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  112236. 7,
  112237. };
  112238. static float _vq_quantthresh__8c0_s_p9_0[] = {
  112239. -157.5, 157.5,
  112240. };
  112241. static long _vq_quantmap__8c0_s_p9_0[] = {
  112242. 1, 0, 2,
  112243. };
  112244. static encode_aux_threshmatch _vq_auxt__8c0_s_p9_0 = {
  112245. _vq_quantthresh__8c0_s_p9_0,
  112246. _vq_quantmap__8c0_s_p9_0,
  112247. 3,
  112248. 3
  112249. };
  112250. static static_codebook _8c0_s_p9_0 = {
  112251. 4, 81,
  112252. _vq_lengthlist__8c0_s_p9_0,
  112253. 1, -518803456, 1628680192, 2, 0,
  112254. _vq_quantlist__8c0_s_p9_0,
  112255. NULL,
  112256. &_vq_auxt__8c0_s_p9_0,
  112257. NULL,
  112258. 0
  112259. };
  112260. static long _vq_quantlist__8c0_s_p9_1[] = {
  112261. 7,
  112262. 6,
  112263. 8,
  112264. 5,
  112265. 9,
  112266. 4,
  112267. 10,
  112268. 3,
  112269. 11,
  112270. 2,
  112271. 12,
  112272. 1,
  112273. 13,
  112274. 0,
  112275. 14,
  112276. };
  112277. static long _vq_lengthlist__8c0_s_p9_1[] = {
  112278. 1, 4, 4, 5, 5,10, 8,11,11,11,11,11,11,11,11, 6,
  112279. 6, 6, 7, 6,11,10,11,11,11,11,11,11,11,11, 7, 5,
  112280. 6, 6, 6, 8, 7,11,11,11,11,11,11,11,11,11, 7, 8,
  112281. 8, 8, 9, 9,11,11,11,11,11,11,11,11,11, 9, 8, 7,
  112282. 8, 9,11,11,11,11,11,11,11,11,11,11,11,10,11,11,
  112283. 11,11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,
  112284. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112285. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112286. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112287. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112288. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112289. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112290. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112291. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112292. 11,
  112293. };
  112294. static float _vq_quantthresh__8c0_s_p9_1[] = {
  112295. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  112296. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  112297. };
  112298. static long _vq_quantmap__8c0_s_p9_1[] = {
  112299. 13, 11, 9, 7, 5, 3, 1, 0,
  112300. 2, 4, 6, 8, 10, 12, 14,
  112301. };
  112302. static encode_aux_threshmatch _vq_auxt__8c0_s_p9_1 = {
  112303. _vq_quantthresh__8c0_s_p9_1,
  112304. _vq_quantmap__8c0_s_p9_1,
  112305. 15,
  112306. 15
  112307. };
  112308. static static_codebook _8c0_s_p9_1 = {
  112309. 2, 225,
  112310. _vq_lengthlist__8c0_s_p9_1,
  112311. 1, -520986624, 1620377600, 4, 0,
  112312. _vq_quantlist__8c0_s_p9_1,
  112313. NULL,
  112314. &_vq_auxt__8c0_s_p9_1,
  112315. NULL,
  112316. 0
  112317. };
  112318. static long _vq_quantlist__8c0_s_p9_2[] = {
  112319. 10,
  112320. 9,
  112321. 11,
  112322. 8,
  112323. 12,
  112324. 7,
  112325. 13,
  112326. 6,
  112327. 14,
  112328. 5,
  112329. 15,
  112330. 4,
  112331. 16,
  112332. 3,
  112333. 17,
  112334. 2,
  112335. 18,
  112336. 1,
  112337. 19,
  112338. 0,
  112339. 20,
  112340. };
  112341. static long _vq_lengthlist__8c0_s_p9_2[] = {
  112342. 1, 5, 5, 7, 7, 8, 7, 8, 8,10,10, 9, 9,10,10,10,
  112343. 11,11,10,12,11,12,12,12, 9, 8, 8, 8, 8, 8, 9,10,
  112344. 10,10,10,11,11,11,10,11,11,12,12,11,12, 8, 8, 7,
  112345. 7, 8, 9,10,10,10, 9,10,10, 9,10,10,11,11,11,11,
  112346. 11,11, 9, 9, 9, 9, 8, 9,10,10,11,10,10,11,11,12,
  112347. 10,10,12,12,11,11,10, 9, 9,10, 8, 9,10,10,10, 9,
  112348. 10,10,11,11,10,11,10,10,10,12,12,12, 9,10, 9,10,
  112349. 9, 9,10,10,11,11,11,11,10,10,10,11,12,11,12,11,
  112350. 12,10,11,10,11, 9,10, 9,10, 9,10,10, 9,10,10,11,
  112351. 10,11,11,11,11,12,11, 9,10,10,10,10,11,11,11,11,
  112352. 11,10,11,11,11,11,10,12,10,12,12,11,12,10,10,11,
  112353. 10, 9,11,10,11, 9,10,11,10,10,10,11,11,11,11,12,
  112354. 12,10, 9, 9,11,10, 9,12,11,10,12,12,11,11,11,11,
  112355. 10,11,11,12,11,10,12, 9,11,10,11,10,10,11,10,11,
  112356. 9,10,10,10,11,12,11,11,12,11,10,10,11,11, 9,10,
  112357. 10,12,10,11,10,10,10, 9,10,10,10,10, 9,10,10,11,
  112358. 11,11,11,12,11,10,10,10,10,11,11,10,11,11, 9,11,
  112359. 10,12,10,12,11,10,11,10,10,10,11,10,10,11,11,10,
  112360. 11,10,10,10,10,11,11,12,10,10,10,11,10,11,12,11,
  112361. 10,11,10,10,11,11,10,12,10, 9,10,10,11,11,11,10,
  112362. 12,10,10,11,11,11,10,10,11,10,10,10,11,10,11,10,
  112363. 12,11,11,10,10,10,12,10,10,11, 9,10,11,11,11,10,
  112364. 10,11,10,10, 9,11,11,12,12,11,12,11,11,11,11,11,
  112365. 11, 9,10,11,10,12,10,10,10,10,11,10,10,11,10,10,
  112366. 12,10,10,10,10,10, 9,12,10,10,10,10,12, 9,11,10,
  112367. 10,11,10,12,12,10,12,12,12,10,10,10,10, 9,10,11,
  112368. 10,10,12,10,10,12,11,10,11,10,10,12,11,10,12,10,
  112369. 10,11, 9,11,10, 9,10, 9,10,
  112370. };
  112371. static float _vq_quantthresh__8c0_s_p9_2[] = {
  112372. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  112373. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  112374. 6.5, 7.5, 8.5, 9.5,
  112375. };
  112376. static long _vq_quantmap__8c0_s_p9_2[] = {
  112377. 19, 17, 15, 13, 11, 9, 7, 5,
  112378. 3, 1, 0, 2, 4, 6, 8, 10,
  112379. 12, 14, 16, 18, 20,
  112380. };
  112381. static encode_aux_threshmatch _vq_auxt__8c0_s_p9_2 = {
  112382. _vq_quantthresh__8c0_s_p9_2,
  112383. _vq_quantmap__8c0_s_p9_2,
  112384. 21,
  112385. 21
  112386. };
  112387. static static_codebook _8c0_s_p9_2 = {
  112388. 2, 441,
  112389. _vq_lengthlist__8c0_s_p9_2,
  112390. 1, -529268736, 1611661312, 5, 0,
  112391. _vq_quantlist__8c0_s_p9_2,
  112392. NULL,
  112393. &_vq_auxt__8c0_s_p9_2,
  112394. NULL,
  112395. 0
  112396. };
  112397. static long _huff_lengthlist__8c0_s_single[] = {
  112398. 4, 5,18, 7,10, 6, 7, 8, 9,10, 5, 2,18, 5, 7, 5,
  112399. 6, 7, 8,11,17,17,17,17,17,17,17,17,17,17, 7, 4,
  112400. 17, 6, 9, 6, 8,10,12,15,11, 7,17, 9, 6, 6, 7, 9,
  112401. 11,15, 6, 4,17, 6, 6, 4, 5, 8,11,16, 6, 6,17, 8,
  112402. 6, 5, 6, 9,13,16, 8, 9,17,11, 9, 8, 8,11,13,17,
  112403. 9,12,17,15,14,13,12,13,14,17,12,15,17,17,17,17,
  112404. 17,16,17,17,
  112405. };
  112406. static static_codebook _huff_book__8c0_s_single = {
  112407. 2, 100,
  112408. _huff_lengthlist__8c0_s_single,
  112409. 0, 0, 0, 0, 0,
  112410. NULL,
  112411. NULL,
  112412. NULL,
  112413. NULL,
  112414. 0
  112415. };
  112416. static long _vq_quantlist__8c1_s_p1_0[] = {
  112417. 1,
  112418. 0,
  112419. 2,
  112420. };
  112421. static long _vq_lengthlist__8c1_s_p1_0[] = {
  112422. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  112423. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112427. 0, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 8, 9, 0, 0, 0,
  112428. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112432. 0, 0, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  112433. 0, 0, 0, 0, 7, 9, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  112468. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  112473. 0, 0, 0, 8, 8,10, 0, 0, 0, 0, 0, 0, 9,10,10, 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, 7, 9, 9, 0, 0,
  112478. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  112479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112513. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  112514. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  112519. 0, 0, 0, 0, 0, 8, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  112524. 0, 0, 0, 0, 0, 0, 8,10, 8, 0, 0, 0, 0, 0, 0, 0,
  112525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112755. 0, 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,
  112833. };
  112834. static float _vq_quantthresh__8c1_s_p1_0[] = {
  112835. -0.5, 0.5,
  112836. };
  112837. static long _vq_quantmap__8c1_s_p1_0[] = {
  112838. 1, 0, 2,
  112839. };
  112840. static encode_aux_threshmatch _vq_auxt__8c1_s_p1_0 = {
  112841. _vq_quantthresh__8c1_s_p1_0,
  112842. _vq_quantmap__8c1_s_p1_0,
  112843. 3,
  112844. 3
  112845. };
  112846. static static_codebook _8c1_s_p1_0 = {
  112847. 8, 6561,
  112848. _vq_lengthlist__8c1_s_p1_0,
  112849. 1, -535822336, 1611661312, 2, 0,
  112850. _vq_quantlist__8c1_s_p1_0,
  112851. NULL,
  112852. &_vq_auxt__8c1_s_p1_0,
  112853. NULL,
  112854. 0
  112855. };
  112856. static long _vq_quantlist__8c1_s_p2_0[] = {
  112857. 2,
  112858. 1,
  112859. 3,
  112860. 0,
  112861. 4,
  112862. };
  112863. static long _vq_lengthlist__8c1_s_p2_0[] = {
  112864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112903. 0,
  112904. };
  112905. static float _vq_quantthresh__8c1_s_p2_0[] = {
  112906. -1.5, -0.5, 0.5, 1.5,
  112907. };
  112908. static long _vq_quantmap__8c1_s_p2_0[] = {
  112909. 3, 1, 0, 2, 4,
  112910. };
  112911. static encode_aux_threshmatch _vq_auxt__8c1_s_p2_0 = {
  112912. _vq_quantthresh__8c1_s_p2_0,
  112913. _vq_quantmap__8c1_s_p2_0,
  112914. 5,
  112915. 5
  112916. };
  112917. static static_codebook _8c1_s_p2_0 = {
  112918. 4, 625,
  112919. _vq_lengthlist__8c1_s_p2_0,
  112920. 1, -533725184, 1611661312, 3, 0,
  112921. _vq_quantlist__8c1_s_p2_0,
  112922. NULL,
  112923. &_vq_auxt__8c1_s_p2_0,
  112924. NULL,
  112925. 0
  112926. };
  112927. static long _vq_quantlist__8c1_s_p3_0[] = {
  112928. 2,
  112929. 1,
  112930. 3,
  112931. 0,
  112932. 4,
  112933. };
  112934. static long _vq_lengthlist__8c1_s_p3_0[] = {
  112935. 2, 4, 4, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  112937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112938. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 7, 7,
  112940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112941. 0, 0, 0, 0, 6, 6, 6, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  112942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112974. 0,
  112975. };
  112976. static float _vq_quantthresh__8c1_s_p3_0[] = {
  112977. -1.5, -0.5, 0.5, 1.5,
  112978. };
  112979. static long _vq_quantmap__8c1_s_p3_0[] = {
  112980. 3, 1, 0, 2, 4,
  112981. };
  112982. static encode_aux_threshmatch _vq_auxt__8c1_s_p3_0 = {
  112983. _vq_quantthresh__8c1_s_p3_0,
  112984. _vq_quantmap__8c1_s_p3_0,
  112985. 5,
  112986. 5
  112987. };
  112988. static static_codebook _8c1_s_p3_0 = {
  112989. 4, 625,
  112990. _vq_lengthlist__8c1_s_p3_0,
  112991. 1, -533725184, 1611661312, 3, 0,
  112992. _vq_quantlist__8c1_s_p3_0,
  112993. NULL,
  112994. &_vq_auxt__8c1_s_p3_0,
  112995. NULL,
  112996. 0
  112997. };
  112998. static long _vq_quantlist__8c1_s_p4_0[] = {
  112999. 4,
  113000. 3,
  113001. 5,
  113002. 2,
  113003. 6,
  113004. 1,
  113005. 7,
  113006. 0,
  113007. 8,
  113008. };
  113009. static long _vq_lengthlist__8c1_s_p4_0[] = {
  113010. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  113011. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  113012. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  113013. 8, 8, 0, 0, 0, 0, 0, 0, 0, 9, 8, 0, 0, 0, 0, 0,
  113014. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113015. 0,
  113016. };
  113017. static float _vq_quantthresh__8c1_s_p4_0[] = {
  113018. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  113019. };
  113020. static long _vq_quantmap__8c1_s_p4_0[] = {
  113021. 7, 5, 3, 1, 0, 2, 4, 6,
  113022. 8,
  113023. };
  113024. static encode_aux_threshmatch _vq_auxt__8c1_s_p4_0 = {
  113025. _vq_quantthresh__8c1_s_p4_0,
  113026. _vq_quantmap__8c1_s_p4_0,
  113027. 9,
  113028. 9
  113029. };
  113030. static static_codebook _8c1_s_p4_0 = {
  113031. 2, 81,
  113032. _vq_lengthlist__8c1_s_p4_0,
  113033. 1, -531628032, 1611661312, 4, 0,
  113034. _vq_quantlist__8c1_s_p4_0,
  113035. NULL,
  113036. &_vq_auxt__8c1_s_p4_0,
  113037. NULL,
  113038. 0
  113039. };
  113040. static long _vq_quantlist__8c1_s_p5_0[] = {
  113041. 4,
  113042. 3,
  113043. 5,
  113044. 2,
  113045. 6,
  113046. 1,
  113047. 7,
  113048. 0,
  113049. 8,
  113050. };
  113051. static long _vq_lengthlist__8c1_s_p5_0[] = {
  113052. 1, 3, 3, 4, 5, 6, 6, 8, 8, 0, 0, 0, 8, 8, 7, 7,
  113053. 9, 9, 0, 0, 0, 8, 8, 7, 7, 9, 9, 0, 0, 0, 9,10,
  113054. 8, 8, 9, 9, 0, 0, 0,10,10, 8, 8, 9, 9, 0, 0, 0,
  113055. 11,10, 8, 8,10,10, 0, 0, 0,11,11, 8, 8,10,10, 0,
  113056. 0, 0,12,12, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  113057. 10,
  113058. };
  113059. static float _vq_quantthresh__8c1_s_p5_0[] = {
  113060. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  113061. };
  113062. static long _vq_quantmap__8c1_s_p5_0[] = {
  113063. 7, 5, 3, 1, 0, 2, 4, 6,
  113064. 8,
  113065. };
  113066. static encode_aux_threshmatch _vq_auxt__8c1_s_p5_0 = {
  113067. _vq_quantthresh__8c1_s_p5_0,
  113068. _vq_quantmap__8c1_s_p5_0,
  113069. 9,
  113070. 9
  113071. };
  113072. static static_codebook _8c1_s_p5_0 = {
  113073. 2, 81,
  113074. _vq_lengthlist__8c1_s_p5_0,
  113075. 1, -531628032, 1611661312, 4, 0,
  113076. _vq_quantlist__8c1_s_p5_0,
  113077. NULL,
  113078. &_vq_auxt__8c1_s_p5_0,
  113079. NULL,
  113080. 0
  113081. };
  113082. static long _vq_quantlist__8c1_s_p6_0[] = {
  113083. 8,
  113084. 7,
  113085. 9,
  113086. 6,
  113087. 10,
  113088. 5,
  113089. 11,
  113090. 4,
  113091. 12,
  113092. 3,
  113093. 13,
  113094. 2,
  113095. 14,
  113096. 1,
  113097. 15,
  113098. 0,
  113099. 16,
  113100. };
  113101. static long _vq_lengthlist__8c1_s_p6_0[] = {
  113102. 1, 3, 3, 5, 5, 8, 8, 8, 8, 9, 9,10,10,11,11,11,
  113103. 11, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,11,
  113104. 12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  113105. 11,12,12, 0, 0, 0, 9, 9, 8, 8,10,10,10,10,11,11,
  113106. 12,12,12,12, 0, 0, 0, 9, 9, 8, 8,10,10,10,10,11,
  113107. 11,12,12,12,12, 0, 0, 0,10,10, 9, 9,10,10,10,10,
  113108. 11,11,12,12,13,13, 0, 0, 0,10,10, 9, 9,10,10,10,
  113109. 10,11,11,12,12,13,13, 0, 0, 0,11,11, 9, 9,10,10,
  113110. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,10,
  113111. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  113112. 10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0, 0, 9,
  113113. 9,10,10,11,11,12,11,12,12,13,13, 0, 0, 0, 0, 0,
  113114. 10,10,11,11,11,11,12,12,13,12,13,13, 0, 0, 0, 0,
  113115. 0, 0, 0,11,10,11,11,12,12,13,13,13,13, 0, 0, 0,
  113116. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0, 0,
  113117. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,13, 0,
  113118. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  113119. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,13,13,14,
  113120. 14,
  113121. };
  113122. static float _vq_quantthresh__8c1_s_p6_0[] = {
  113123. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  113124. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  113125. };
  113126. static long _vq_quantmap__8c1_s_p6_0[] = {
  113127. 15, 13, 11, 9, 7, 5, 3, 1,
  113128. 0, 2, 4, 6, 8, 10, 12, 14,
  113129. 16,
  113130. };
  113131. static encode_aux_threshmatch _vq_auxt__8c1_s_p6_0 = {
  113132. _vq_quantthresh__8c1_s_p6_0,
  113133. _vq_quantmap__8c1_s_p6_0,
  113134. 17,
  113135. 17
  113136. };
  113137. static static_codebook _8c1_s_p6_0 = {
  113138. 2, 289,
  113139. _vq_lengthlist__8c1_s_p6_0,
  113140. 1, -529530880, 1611661312, 5, 0,
  113141. _vq_quantlist__8c1_s_p6_0,
  113142. NULL,
  113143. &_vq_auxt__8c1_s_p6_0,
  113144. NULL,
  113145. 0
  113146. };
  113147. static long _vq_quantlist__8c1_s_p7_0[] = {
  113148. 1,
  113149. 0,
  113150. 2,
  113151. };
  113152. static long _vq_lengthlist__8c1_s_p7_0[] = {
  113153. 1, 4, 4, 6, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,10,
  113154. 9, 9, 5, 7, 7,10, 9, 9,10, 9, 9, 6,10,10,10,10,
  113155. 10,11,10,10, 6, 9, 9,10, 9,10,11,10,10, 6, 9, 9,
  113156. 10, 9, 9,11, 9,10, 7,10,10,11,11,11,11,10,10, 6,
  113157. 9, 9,10,10,10,11, 9, 9, 6, 9, 9,10,10,10,10, 9,
  113158. 9,
  113159. };
  113160. static float _vq_quantthresh__8c1_s_p7_0[] = {
  113161. -5.5, 5.5,
  113162. };
  113163. static long _vq_quantmap__8c1_s_p7_0[] = {
  113164. 1, 0, 2,
  113165. };
  113166. static encode_aux_threshmatch _vq_auxt__8c1_s_p7_0 = {
  113167. _vq_quantthresh__8c1_s_p7_0,
  113168. _vq_quantmap__8c1_s_p7_0,
  113169. 3,
  113170. 3
  113171. };
  113172. static static_codebook _8c1_s_p7_0 = {
  113173. 4, 81,
  113174. _vq_lengthlist__8c1_s_p7_0,
  113175. 1, -529137664, 1618345984, 2, 0,
  113176. _vq_quantlist__8c1_s_p7_0,
  113177. NULL,
  113178. &_vq_auxt__8c1_s_p7_0,
  113179. NULL,
  113180. 0
  113181. };
  113182. static long _vq_quantlist__8c1_s_p7_1[] = {
  113183. 5,
  113184. 4,
  113185. 6,
  113186. 3,
  113187. 7,
  113188. 2,
  113189. 8,
  113190. 1,
  113191. 9,
  113192. 0,
  113193. 10,
  113194. };
  113195. static long _vq_lengthlist__8c1_s_p7_1[] = {
  113196. 2, 3, 3, 5, 5, 7, 7, 7, 7, 7, 7,10,10, 9, 7, 7,
  113197. 7, 7, 8, 8, 8, 8, 9, 9, 9, 7, 7, 7, 7, 8, 8, 8,
  113198. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  113199. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  113200. 8, 8,10,10,10, 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  113201. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  113202. 8, 8, 8,10,10,10,10,10, 8, 8, 8, 8, 8, 8,10,10,
  113203. 10,10,10, 8, 8, 8, 8, 8, 8,
  113204. };
  113205. static float _vq_quantthresh__8c1_s_p7_1[] = {
  113206. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  113207. 3.5, 4.5,
  113208. };
  113209. static long _vq_quantmap__8c1_s_p7_1[] = {
  113210. 9, 7, 5, 3, 1, 0, 2, 4,
  113211. 6, 8, 10,
  113212. };
  113213. static encode_aux_threshmatch _vq_auxt__8c1_s_p7_1 = {
  113214. _vq_quantthresh__8c1_s_p7_1,
  113215. _vq_quantmap__8c1_s_p7_1,
  113216. 11,
  113217. 11
  113218. };
  113219. static static_codebook _8c1_s_p7_1 = {
  113220. 2, 121,
  113221. _vq_lengthlist__8c1_s_p7_1,
  113222. 1, -531365888, 1611661312, 4, 0,
  113223. _vq_quantlist__8c1_s_p7_1,
  113224. NULL,
  113225. &_vq_auxt__8c1_s_p7_1,
  113226. NULL,
  113227. 0
  113228. };
  113229. static long _vq_quantlist__8c1_s_p8_0[] = {
  113230. 6,
  113231. 5,
  113232. 7,
  113233. 4,
  113234. 8,
  113235. 3,
  113236. 9,
  113237. 2,
  113238. 10,
  113239. 1,
  113240. 11,
  113241. 0,
  113242. 12,
  113243. };
  113244. static long _vq_lengthlist__8c1_s_p8_0[] = {
  113245. 1, 4, 4, 6, 6, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 5,
  113246. 7, 7, 8, 8, 8, 8, 9,10,11,11, 7, 5, 5, 7, 7, 8,
  113247. 8, 9, 9,10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  113248. 9,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  113249. 11, 0,12,12, 9, 9, 9, 9,10, 9,10,11,11,11, 0,13,
  113250. 12, 9, 8, 9, 9,10,10,11,11,12,11, 0, 0, 0, 9, 9,
  113251. 9, 9,10,10,11,11,12,12, 0, 0, 0,10,10, 9, 9,10,
  113252. 10,11,11,12,12, 0, 0, 0,13,13,10,10,11,11,12,11,
  113253. 13,12, 0, 0, 0,14,14,10,10,11,10,11,11,12,12, 0,
  113254. 0, 0, 0, 0,12,12,11,11,12,12,13,13, 0, 0, 0, 0,
  113255. 0,12,12,11,10,12,11,13,12,
  113256. };
  113257. static float _vq_quantthresh__8c1_s_p8_0[] = {
  113258. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  113259. 12.5, 17.5, 22.5, 27.5,
  113260. };
  113261. static long _vq_quantmap__8c1_s_p8_0[] = {
  113262. 11, 9, 7, 5, 3, 1, 0, 2,
  113263. 4, 6, 8, 10, 12,
  113264. };
  113265. static encode_aux_threshmatch _vq_auxt__8c1_s_p8_0 = {
  113266. _vq_quantthresh__8c1_s_p8_0,
  113267. _vq_quantmap__8c1_s_p8_0,
  113268. 13,
  113269. 13
  113270. };
  113271. static static_codebook _8c1_s_p8_0 = {
  113272. 2, 169,
  113273. _vq_lengthlist__8c1_s_p8_0,
  113274. 1, -526516224, 1616117760, 4, 0,
  113275. _vq_quantlist__8c1_s_p8_0,
  113276. NULL,
  113277. &_vq_auxt__8c1_s_p8_0,
  113278. NULL,
  113279. 0
  113280. };
  113281. static long _vq_quantlist__8c1_s_p8_1[] = {
  113282. 2,
  113283. 1,
  113284. 3,
  113285. 0,
  113286. 4,
  113287. };
  113288. static long _vq_lengthlist__8c1_s_p8_1[] = {
  113289. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  113290. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  113291. };
  113292. static float _vq_quantthresh__8c1_s_p8_1[] = {
  113293. -1.5, -0.5, 0.5, 1.5,
  113294. };
  113295. static long _vq_quantmap__8c1_s_p8_1[] = {
  113296. 3, 1, 0, 2, 4,
  113297. };
  113298. static encode_aux_threshmatch _vq_auxt__8c1_s_p8_1 = {
  113299. _vq_quantthresh__8c1_s_p8_1,
  113300. _vq_quantmap__8c1_s_p8_1,
  113301. 5,
  113302. 5
  113303. };
  113304. static static_codebook _8c1_s_p8_1 = {
  113305. 2, 25,
  113306. _vq_lengthlist__8c1_s_p8_1,
  113307. 1, -533725184, 1611661312, 3, 0,
  113308. _vq_quantlist__8c1_s_p8_1,
  113309. NULL,
  113310. &_vq_auxt__8c1_s_p8_1,
  113311. NULL,
  113312. 0
  113313. };
  113314. static long _vq_quantlist__8c1_s_p9_0[] = {
  113315. 6,
  113316. 5,
  113317. 7,
  113318. 4,
  113319. 8,
  113320. 3,
  113321. 9,
  113322. 2,
  113323. 10,
  113324. 1,
  113325. 11,
  113326. 0,
  113327. 12,
  113328. };
  113329. static long _vq_lengthlist__8c1_s_p9_0[] = {
  113330. 1, 3, 3,10,10,10,10,10,10,10,10,10,10, 5, 6, 6,
  113331. 10,10,10,10,10,10,10,10,10,10, 6, 7, 8,10,10,10,
  113332. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113333. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113334. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113335. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113336. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113337. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113338. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113339. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113340. 10,10,10,10,10, 9, 9, 9, 9,
  113341. };
  113342. static float _vq_quantthresh__8c1_s_p9_0[] = {
  113343. -1732.5, -1417.5, -1102.5, -787.5, -472.5, -157.5, 157.5, 472.5,
  113344. 787.5, 1102.5, 1417.5, 1732.5,
  113345. };
  113346. static long _vq_quantmap__8c1_s_p9_0[] = {
  113347. 11, 9, 7, 5, 3, 1, 0, 2,
  113348. 4, 6, 8, 10, 12,
  113349. };
  113350. static encode_aux_threshmatch _vq_auxt__8c1_s_p9_0 = {
  113351. _vq_quantthresh__8c1_s_p9_0,
  113352. _vq_quantmap__8c1_s_p9_0,
  113353. 13,
  113354. 13
  113355. };
  113356. static static_codebook _8c1_s_p9_0 = {
  113357. 2, 169,
  113358. _vq_lengthlist__8c1_s_p9_0,
  113359. 1, -513964032, 1628680192, 4, 0,
  113360. _vq_quantlist__8c1_s_p9_0,
  113361. NULL,
  113362. &_vq_auxt__8c1_s_p9_0,
  113363. NULL,
  113364. 0
  113365. };
  113366. static long _vq_quantlist__8c1_s_p9_1[] = {
  113367. 7,
  113368. 6,
  113369. 8,
  113370. 5,
  113371. 9,
  113372. 4,
  113373. 10,
  113374. 3,
  113375. 11,
  113376. 2,
  113377. 12,
  113378. 1,
  113379. 13,
  113380. 0,
  113381. 14,
  113382. };
  113383. static long _vq_lengthlist__8c1_s_p9_1[] = {
  113384. 1, 4, 4, 5, 5, 7, 7, 9, 9,11,11,12,12,13,13, 6,
  113385. 5, 5, 6, 6, 9, 9,10,10,12,12,12,13,15,14, 6, 5,
  113386. 5, 7, 7, 9, 9,10,10,12,12,12,13,14,13,17, 7, 7,
  113387. 8, 8,10,10,11,11,12,13,13,13,13,13,17, 7, 7, 8,
  113388. 8,10,10,11,11,13,13,13,13,14,14,17,11,11, 9, 9,
  113389. 11,11,12,12,12,13,13,14,15,13,17,12,12, 9, 9,11,
  113390. 11,12,12,13,13,13,13,14,16,17,17,17,11,12,12,12,
  113391. 13,13,13,14,15,14,15,15,17,17,17,12,12,11,11,13,
  113392. 13,14,14,15,14,15,15,17,17,17,15,15,13,13,14,14,
  113393. 15,14,15,15,16,15,17,17,17,15,15,13,13,13,14,14,
  113394. 15,15,15,15,16,17,17,17,17,16,14,15,14,14,15,14,
  113395. 14,15,15,15,17,17,17,17,17,14,14,16,14,15,15,15,
  113396. 15,15,15,17,17,17,17,17,17,16,16,15,17,15,15,14,
  113397. 17,15,17,16,17,17,17,17,16,15,14,15,15,15,15,15,
  113398. 15,
  113399. };
  113400. static float _vq_quantthresh__8c1_s_p9_1[] = {
  113401. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  113402. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  113403. };
  113404. static long _vq_quantmap__8c1_s_p9_1[] = {
  113405. 13, 11, 9, 7, 5, 3, 1, 0,
  113406. 2, 4, 6, 8, 10, 12, 14,
  113407. };
  113408. static encode_aux_threshmatch _vq_auxt__8c1_s_p9_1 = {
  113409. _vq_quantthresh__8c1_s_p9_1,
  113410. _vq_quantmap__8c1_s_p9_1,
  113411. 15,
  113412. 15
  113413. };
  113414. static static_codebook _8c1_s_p9_1 = {
  113415. 2, 225,
  113416. _vq_lengthlist__8c1_s_p9_1,
  113417. 1, -520986624, 1620377600, 4, 0,
  113418. _vq_quantlist__8c1_s_p9_1,
  113419. NULL,
  113420. &_vq_auxt__8c1_s_p9_1,
  113421. NULL,
  113422. 0
  113423. };
  113424. static long _vq_quantlist__8c1_s_p9_2[] = {
  113425. 10,
  113426. 9,
  113427. 11,
  113428. 8,
  113429. 12,
  113430. 7,
  113431. 13,
  113432. 6,
  113433. 14,
  113434. 5,
  113435. 15,
  113436. 4,
  113437. 16,
  113438. 3,
  113439. 17,
  113440. 2,
  113441. 18,
  113442. 1,
  113443. 19,
  113444. 0,
  113445. 20,
  113446. };
  113447. static long _vq_lengthlist__8c1_s_p9_2[] = {
  113448. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 9, 9, 9,
  113449. 9, 9, 9, 9, 9,11,11,12, 7, 7, 7, 7, 8, 8, 9, 9,
  113450. 9, 9,10,10,10,10,10,10,10,10,11,11,11, 7, 7, 7,
  113451. 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,11,
  113452. 11,12, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,10,
  113453. 10,10,10,10,11,11,11, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  113454. 9,10,10,10,10,10,10,10,10,11,11,11, 8, 8, 8, 8,
  113455. 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,11,11,
  113456. 11, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,10,
  113457. 10,10,10,11,12,11, 9, 9, 8, 9, 9, 9, 9, 9,10,10,
  113458. 10,10,10,10,10,10,10,10,11,11,11,11,11, 8, 8, 9,
  113459. 9, 9, 9,10,10,10,10,10,10,10,10,10,10,11,12,11,
  113460. 12,11, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  113461. 10,10,11,11,11,11,11, 9, 9, 9, 9,10,10,10,10,10,
  113462. 10,10,10,10,10,10,10,12,11,12,11,11, 9, 9, 9,10,
  113463. 10,10,10,10,10,10,10,10,10,10,10,10,12,11,11,11,
  113464. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113465. 11,11,11,12,11,11,12,11,10,10,10,10,10,10,10,10,
  113466. 10,10,10,10,11,10,11,11,11,11,11,11,11,10,10,10,
  113467. 10,10,10,10,10,10,10,10,10,10,10,11,11,12,11,12,
  113468. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113469. 11,11,12,11,12,11,11,11,11,10,10,10,10,10,10,10,
  113470. 10,10,10,10,10,11,11,12,11,11,12,11,11,12,10,10,
  113471. 11,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
  113472. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,12,
  113473. 12,11,12,11,11,12,12,12,11,11,10,10,10,10,10,10,
  113474. 10,10,10,11,12,12,11,12,12,11,12,11,11,11,11,10,
  113475. 10,10,10,10,10,10,10,10,10,
  113476. };
  113477. static float _vq_quantthresh__8c1_s_p9_2[] = {
  113478. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  113479. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  113480. 6.5, 7.5, 8.5, 9.5,
  113481. };
  113482. static long _vq_quantmap__8c1_s_p9_2[] = {
  113483. 19, 17, 15, 13, 11, 9, 7, 5,
  113484. 3, 1, 0, 2, 4, 6, 8, 10,
  113485. 12, 14, 16, 18, 20,
  113486. };
  113487. static encode_aux_threshmatch _vq_auxt__8c1_s_p9_2 = {
  113488. _vq_quantthresh__8c1_s_p9_2,
  113489. _vq_quantmap__8c1_s_p9_2,
  113490. 21,
  113491. 21
  113492. };
  113493. static static_codebook _8c1_s_p9_2 = {
  113494. 2, 441,
  113495. _vq_lengthlist__8c1_s_p9_2,
  113496. 1, -529268736, 1611661312, 5, 0,
  113497. _vq_quantlist__8c1_s_p9_2,
  113498. NULL,
  113499. &_vq_auxt__8c1_s_p9_2,
  113500. NULL,
  113501. 0
  113502. };
  113503. static long _huff_lengthlist__8c1_s_single[] = {
  113504. 4, 6,18, 8,11, 8, 8, 9, 9,10, 4, 4,18, 5, 9, 5,
  113505. 6, 7, 8,10,18,18,18,18,17,17,17,17,17,17, 7, 5,
  113506. 17, 6,11, 6, 7, 8, 9,12,12, 9,17,12, 8, 8, 9,10,
  113507. 10,13, 7, 5,17, 6, 8, 4, 5, 6, 8,10, 6, 5,17, 6,
  113508. 8, 5, 4, 5, 7, 9, 7, 7,17, 8, 9, 6, 5, 5, 6, 8,
  113509. 8, 8,17, 9,11, 8, 6, 6, 6, 7, 9,10,17,12,12,10,
  113510. 9, 7, 7, 8,
  113511. };
  113512. static static_codebook _huff_book__8c1_s_single = {
  113513. 2, 100,
  113514. _huff_lengthlist__8c1_s_single,
  113515. 0, 0, 0, 0, 0,
  113516. NULL,
  113517. NULL,
  113518. NULL,
  113519. NULL,
  113520. 0
  113521. };
  113522. static long _huff_lengthlist__44c2_s_long[] = {
  113523. 6, 6,12,10,10,10, 9,10,12,12, 6, 1,10, 5, 6, 6,
  113524. 7, 9,11,14,12, 9, 8,11, 7, 8, 9,11,13,15,10, 5,
  113525. 12, 7, 8, 7, 9,12,14,15,10, 6, 7, 8, 5, 6, 7, 9,
  113526. 12,14, 9, 6, 8, 7, 6, 6, 7, 9,12,12, 9, 7, 9, 9,
  113527. 7, 6, 6, 7,10,10,10, 9,10,11, 8, 7, 6, 6, 8,10,
  113528. 12,11,13,13,11,10, 8, 8, 8,10,11,13,15,15,14,13,
  113529. 10, 8, 8, 9,
  113530. };
  113531. static static_codebook _huff_book__44c2_s_long = {
  113532. 2, 100,
  113533. _huff_lengthlist__44c2_s_long,
  113534. 0, 0, 0, 0, 0,
  113535. NULL,
  113536. NULL,
  113537. NULL,
  113538. NULL,
  113539. 0
  113540. };
  113541. static long _vq_quantlist__44c2_s_p1_0[] = {
  113542. 1,
  113543. 0,
  113544. 2,
  113545. };
  113546. static long _vq_lengthlist__44c2_s_p1_0[] = {
  113547. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0,
  113548. 0, 0, 5, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113552. 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  113553. 0, 0, 0, 6, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113557. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0,
  113558. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  113593. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 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, 7, 8, 8, 0, 0, 0,
  113598. 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 6, 8, 8, 0, 0,
  113603. 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  113604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113638. 0, 0, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  113639. 0, 0, 0, 0, 7, 8, 8, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  113644. 0, 0, 0, 0, 0, 8, 8, 9, 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, 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  113649. 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  113650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113880. 0, 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,
  113958. };
  113959. static float _vq_quantthresh__44c2_s_p1_0[] = {
  113960. -0.5, 0.5,
  113961. };
  113962. static long _vq_quantmap__44c2_s_p1_0[] = {
  113963. 1, 0, 2,
  113964. };
  113965. static encode_aux_threshmatch _vq_auxt__44c2_s_p1_0 = {
  113966. _vq_quantthresh__44c2_s_p1_0,
  113967. _vq_quantmap__44c2_s_p1_0,
  113968. 3,
  113969. 3
  113970. };
  113971. static static_codebook _44c2_s_p1_0 = {
  113972. 8, 6561,
  113973. _vq_lengthlist__44c2_s_p1_0,
  113974. 1, -535822336, 1611661312, 2, 0,
  113975. _vq_quantlist__44c2_s_p1_0,
  113976. NULL,
  113977. &_vq_auxt__44c2_s_p1_0,
  113978. NULL,
  113979. 0
  113980. };
  113981. static long _vq_quantlist__44c2_s_p2_0[] = {
  113982. 2,
  113983. 1,
  113984. 3,
  113985. 0,
  113986. 4,
  113987. };
  113988. static long _vq_lengthlist__44c2_s_p2_0[] = {
  113989. 1, 4, 4, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0,
  113990. 8, 8, 0, 0, 0, 0, 0, 0, 0, 4, 6, 6, 0, 0, 0, 8,
  113991. 8, 0, 0, 0, 8, 8, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0,
  113992. 0, 0, 4, 6, 6, 0, 0, 0, 8, 8, 0, 0, 0, 8, 8, 0,
  113993. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113998. 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,11,11, 0, 0,
  113999. 0,11,11, 0, 0, 0,12,11, 0, 0, 0, 0, 0, 0, 0, 7,
  114000. 8, 8, 0, 0, 0,10,11, 0, 0, 0,11,11, 0, 0, 0,11,
  114001. 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114006. 0, 0, 0, 6, 8, 8, 0, 0, 0,11,11, 0, 0, 0,11,11,
  114007. 0, 0, 0,12,12, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0,
  114008. 0, 0,10,11, 0, 0, 0,10,11, 0, 0, 0,11,11, 0, 0,
  114009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114014. 8, 9, 9, 0, 0, 0,11,12, 0, 0, 0,11,12, 0, 0, 0,
  114015. 12,11, 0, 0, 0, 0, 0, 0, 0, 8,10, 9, 0, 0, 0,12,
  114016. 11, 0, 0, 0,12,11, 0, 0, 0,11,12, 0, 0, 0, 0, 0,
  114017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114028. 0,
  114029. };
  114030. static float _vq_quantthresh__44c2_s_p2_0[] = {
  114031. -1.5, -0.5, 0.5, 1.5,
  114032. };
  114033. static long _vq_quantmap__44c2_s_p2_0[] = {
  114034. 3, 1, 0, 2, 4,
  114035. };
  114036. static encode_aux_threshmatch _vq_auxt__44c2_s_p2_0 = {
  114037. _vq_quantthresh__44c2_s_p2_0,
  114038. _vq_quantmap__44c2_s_p2_0,
  114039. 5,
  114040. 5
  114041. };
  114042. static static_codebook _44c2_s_p2_0 = {
  114043. 4, 625,
  114044. _vq_lengthlist__44c2_s_p2_0,
  114045. 1, -533725184, 1611661312, 3, 0,
  114046. _vq_quantlist__44c2_s_p2_0,
  114047. NULL,
  114048. &_vq_auxt__44c2_s_p2_0,
  114049. NULL,
  114050. 0
  114051. };
  114052. static long _vq_quantlist__44c2_s_p3_0[] = {
  114053. 2,
  114054. 1,
  114055. 3,
  114056. 0,
  114057. 4,
  114058. };
  114059. static long _vq_lengthlist__44c2_s_p3_0[] = {
  114060. 2, 4, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  114062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114063. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  114065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114066. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  114067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114094. 0, 0, 0, 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,
  114100. };
  114101. static float _vq_quantthresh__44c2_s_p3_0[] = {
  114102. -1.5, -0.5, 0.5, 1.5,
  114103. };
  114104. static long _vq_quantmap__44c2_s_p3_0[] = {
  114105. 3, 1, 0, 2, 4,
  114106. };
  114107. static encode_aux_threshmatch _vq_auxt__44c2_s_p3_0 = {
  114108. _vq_quantthresh__44c2_s_p3_0,
  114109. _vq_quantmap__44c2_s_p3_0,
  114110. 5,
  114111. 5
  114112. };
  114113. static static_codebook _44c2_s_p3_0 = {
  114114. 4, 625,
  114115. _vq_lengthlist__44c2_s_p3_0,
  114116. 1, -533725184, 1611661312, 3, 0,
  114117. _vq_quantlist__44c2_s_p3_0,
  114118. NULL,
  114119. &_vq_auxt__44c2_s_p3_0,
  114120. NULL,
  114121. 0
  114122. };
  114123. static long _vq_quantlist__44c2_s_p4_0[] = {
  114124. 4,
  114125. 3,
  114126. 5,
  114127. 2,
  114128. 6,
  114129. 1,
  114130. 7,
  114131. 0,
  114132. 8,
  114133. };
  114134. static long _vq_lengthlist__44c2_s_p4_0[] = {
  114135. 1, 3, 3, 6, 6, 0, 0, 0, 0, 0, 6, 6, 6, 6, 0, 0,
  114136. 0, 0, 0, 6, 6, 6, 6, 0, 0, 0, 0, 0, 7, 7, 6, 6,
  114137. 0, 0, 0, 0, 0, 0, 0, 6, 7, 0, 0, 0, 0, 0, 0, 0,
  114138. 7, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  114139. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114140. 0,
  114141. };
  114142. static float _vq_quantthresh__44c2_s_p4_0[] = {
  114143. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  114144. };
  114145. static long _vq_quantmap__44c2_s_p4_0[] = {
  114146. 7, 5, 3, 1, 0, 2, 4, 6,
  114147. 8,
  114148. };
  114149. static encode_aux_threshmatch _vq_auxt__44c2_s_p4_0 = {
  114150. _vq_quantthresh__44c2_s_p4_0,
  114151. _vq_quantmap__44c2_s_p4_0,
  114152. 9,
  114153. 9
  114154. };
  114155. static static_codebook _44c2_s_p4_0 = {
  114156. 2, 81,
  114157. _vq_lengthlist__44c2_s_p4_0,
  114158. 1, -531628032, 1611661312, 4, 0,
  114159. _vq_quantlist__44c2_s_p4_0,
  114160. NULL,
  114161. &_vq_auxt__44c2_s_p4_0,
  114162. NULL,
  114163. 0
  114164. };
  114165. static long _vq_quantlist__44c2_s_p5_0[] = {
  114166. 4,
  114167. 3,
  114168. 5,
  114169. 2,
  114170. 6,
  114171. 1,
  114172. 7,
  114173. 0,
  114174. 8,
  114175. };
  114176. static long _vq_lengthlist__44c2_s_p5_0[] = {
  114177. 1, 3, 3, 6, 6, 7, 7, 9, 9, 0, 7, 7, 7, 7, 7, 7,
  114178. 9, 9, 0, 7, 7, 7, 7, 7, 7, 9, 9, 0, 8, 8, 7, 7,
  114179. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  114180. 9, 9, 8, 8,10,10, 0, 0, 0, 9, 9, 8, 8,10,10, 0,
  114181. 0, 0,10,10, 9, 9,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  114182. 11,
  114183. };
  114184. static float _vq_quantthresh__44c2_s_p5_0[] = {
  114185. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  114186. };
  114187. static long _vq_quantmap__44c2_s_p5_0[] = {
  114188. 7, 5, 3, 1, 0, 2, 4, 6,
  114189. 8,
  114190. };
  114191. static encode_aux_threshmatch _vq_auxt__44c2_s_p5_0 = {
  114192. _vq_quantthresh__44c2_s_p5_0,
  114193. _vq_quantmap__44c2_s_p5_0,
  114194. 9,
  114195. 9
  114196. };
  114197. static static_codebook _44c2_s_p5_0 = {
  114198. 2, 81,
  114199. _vq_lengthlist__44c2_s_p5_0,
  114200. 1, -531628032, 1611661312, 4, 0,
  114201. _vq_quantlist__44c2_s_p5_0,
  114202. NULL,
  114203. &_vq_auxt__44c2_s_p5_0,
  114204. NULL,
  114205. 0
  114206. };
  114207. static long _vq_quantlist__44c2_s_p6_0[] = {
  114208. 8,
  114209. 7,
  114210. 9,
  114211. 6,
  114212. 10,
  114213. 5,
  114214. 11,
  114215. 4,
  114216. 12,
  114217. 3,
  114218. 13,
  114219. 2,
  114220. 14,
  114221. 1,
  114222. 15,
  114223. 0,
  114224. 16,
  114225. };
  114226. static long _vq_lengthlist__44c2_s_p6_0[] = {
  114227. 1, 4, 3, 6, 6, 8, 8, 9, 9, 9, 9, 9, 9,10,10,11,
  114228. 11, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  114229. 12,11, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  114230. 11,11,12, 0, 8, 8, 7, 7, 9, 9,10,10, 9, 9,10,10,
  114231. 11,11,12,12, 0, 0, 0, 7, 7, 9, 9,10,10,10, 9,10,
  114232. 10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  114233. 11,11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  114234. 10,11,11,12,12,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  114235. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  114236. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  114237. 10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  114238. 9,10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  114239. 10,10,10,10,11,11,12,12,13,12,13,13, 0, 0, 0, 0,
  114240. 0, 0, 0,10,10,11,11,12,12,13,13,13,13, 0, 0, 0,
  114241. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0, 0,
  114242. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0,
  114243. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  114244. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,13,13,14,
  114245. 14,
  114246. };
  114247. static float _vq_quantthresh__44c2_s_p6_0[] = {
  114248. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  114249. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  114250. };
  114251. static long _vq_quantmap__44c2_s_p6_0[] = {
  114252. 15, 13, 11, 9, 7, 5, 3, 1,
  114253. 0, 2, 4, 6, 8, 10, 12, 14,
  114254. 16,
  114255. };
  114256. static encode_aux_threshmatch _vq_auxt__44c2_s_p6_0 = {
  114257. _vq_quantthresh__44c2_s_p6_0,
  114258. _vq_quantmap__44c2_s_p6_0,
  114259. 17,
  114260. 17
  114261. };
  114262. static static_codebook _44c2_s_p6_0 = {
  114263. 2, 289,
  114264. _vq_lengthlist__44c2_s_p6_0,
  114265. 1, -529530880, 1611661312, 5, 0,
  114266. _vq_quantlist__44c2_s_p6_0,
  114267. NULL,
  114268. &_vq_auxt__44c2_s_p6_0,
  114269. NULL,
  114270. 0
  114271. };
  114272. static long _vq_quantlist__44c2_s_p7_0[] = {
  114273. 1,
  114274. 0,
  114275. 2,
  114276. };
  114277. static long _vq_lengthlist__44c2_s_p7_0[] = {
  114278. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  114279. 9, 9, 4, 7, 7,10, 9, 9,10, 9, 9, 7,10,10,11,10,
  114280. 11,11,10,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  114281. 11,10,11,11,10,10, 7,11,10,11,11,11,12,11,11, 6,
  114282. 9, 9,11,10,10,11,11,10, 6, 9, 9,11,10,10,12,10,
  114283. 11,
  114284. };
  114285. static float _vq_quantthresh__44c2_s_p7_0[] = {
  114286. -5.5, 5.5,
  114287. };
  114288. static long _vq_quantmap__44c2_s_p7_0[] = {
  114289. 1, 0, 2,
  114290. };
  114291. static encode_aux_threshmatch _vq_auxt__44c2_s_p7_0 = {
  114292. _vq_quantthresh__44c2_s_p7_0,
  114293. _vq_quantmap__44c2_s_p7_0,
  114294. 3,
  114295. 3
  114296. };
  114297. static static_codebook _44c2_s_p7_0 = {
  114298. 4, 81,
  114299. _vq_lengthlist__44c2_s_p7_0,
  114300. 1, -529137664, 1618345984, 2, 0,
  114301. _vq_quantlist__44c2_s_p7_0,
  114302. NULL,
  114303. &_vq_auxt__44c2_s_p7_0,
  114304. NULL,
  114305. 0
  114306. };
  114307. static long _vq_quantlist__44c2_s_p7_1[] = {
  114308. 5,
  114309. 4,
  114310. 6,
  114311. 3,
  114312. 7,
  114313. 2,
  114314. 8,
  114315. 1,
  114316. 9,
  114317. 0,
  114318. 10,
  114319. };
  114320. static long _vq_lengthlist__44c2_s_p7_1[] = {
  114321. 2, 3, 4, 6, 6, 7, 7, 7, 7, 7, 7, 9, 7, 7, 6, 6,
  114322. 7, 7, 8, 8, 8, 8, 9, 6, 6, 6, 6, 7, 7, 8, 8, 8,
  114323. 8,10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  114324. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  114325. 8, 8,10,10,10, 7, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  114326. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  114327. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  114328. 10,10,10, 8, 8, 8, 8, 8, 8,
  114329. };
  114330. static float _vq_quantthresh__44c2_s_p7_1[] = {
  114331. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  114332. 3.5, 4.5,
  114333. };
  114334. static long _vq_quantmap__44c2_s_p7_1[] = {
  114335. 9, 7, 5, 3, 1, 0, 2, 4,
  114336. 6, 8, 10,
  114337. };
  114338. static encode_aux_threshmatch _vq_auxt__44c2_s_p7_1 = {
  114339. _vq_quantthresh__44c2_s_p7_1,
  114340. _vq_quantmap__44c2_s_p7_1,
  114341. 11,
  114342. 11
  114343. };
  114344. static static_codebook _44c2_s_p7_1 = {
  114345. 2, 121,
  114346. _vq_lengthlist__44c2_s_p7_1,
  114347. 1, -531365888, 1611661312, 4, 0,
  114348. _vq_quantlist__44c2_s_p7_1,
  114349. NULL,
  114350. &_vq_auxt__44c2_s_p7_1,
  114351. NULL,
  114352. 0
  114353. };
  114354. static long _vq_quantlist__44c2_s_p8_0[] = {
  114355. 6,
  114356. 5,
  114357. 7,
  114358. 4,
  114359. 8,
  114360. 3,
  114361. 9,
  114362. 2,
  114363. 10,
  114364. 1,
  114365. 11,
  114366. 0,
  114367. 12,
  114368. };
  114369. static long _vq_lengthlist__44c2_s_p8_0[] = {
  114370. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 6, 5, 5,
  114371. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 6, 5, 7, 7, 8,
  114372. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  114373. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  114374. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  114375. 13, 9, 9,10,10,10,10,11,11,12,12, 0, 0, 0,10,10,
  114376. 10,10,11,11,12,12,12,13, 0, 0, 0,10,10,10,10,11,
  114377. 11,12,12,12,12, 0, 0, 0,14,14,10,11,11,11,12,12,
  114378. 13,13, 0, 0, 0,14,14,11,10,11,11,13,12,13,13, 0,
  114379. 0, 0, 0, 0,12,12,11,12,13,12,14,14, 0, 0, 0, 0,
  114380. 0,12,12,12,12,13,12,14,14,
  114381. };
  114382. static float _vq_quantthresh__44c2_s_p8_0[] = {
  114383. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  114384. 12.5, 17.5, 22.5, 27.5,
  114385. };
  114386. static long _vq_quantmap__44c2_s_p8_0[] = {
  114387. 11, 9, 7, 5, 3, 1, 0, 2,
  114388. 4, 6, 8, 10, 12,
  114389. };
  114390. static encode_aux_threshmatch _vq_auxt__44c2_s_p8_0 = {
  114391. _vq_quantthresh__44c2_s_p8_0,
  114392. _vq_quantmap__44c2_s_p8_0,
  114393. 13,
  114394. 13
  114395. };
  114396. static static_codebook _44c2_s_p8_0 = {
  114397. 2, 169,
  114398. _vq_lengthlist__44c2_s_p8_0,
  114399. 1, -526516224, 1616117760, 4, 0,
  114400. _vq_quantlist__44c2_s_p8_0,
  114401. NULL,
  114402. &_vq_auxt__44c2_s_p8_0,
  114403. NULL,
  114404. 0
  114405. };
  114406. static long _vq_quantlist__44c2_s_p8_1[] = {
  114407. 2,
  114408. 1,
  114409. 3,
  114410. 0,
  114411. 4,
  114412. };
  114413. static long _vq_lengthlist__44c2_s_p8_1[] = {
  114414. 2, 4, 4, 5, 4, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  114415. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  114416. };
  114417. static float _vq_quantthresh__44c2_s_p8_1[] = {
  114418. -1.5, -0.5, 0.5, 1.5,
  114419. };
  114420. static long _vq_quantmap__44c2_s_p8_1[] = {
  114421. 3, 1, 0, 2, 4,
  114422. };
  114423. static encode_aux_threshmatch _vq_auxt__44c2_s_p8_1 = {
  114424. _vq_quantthresh__44c2_s_p8_1,
  114425. _vq_quantmap__44c2_s_p8_1,
  114426. 5,
  114427. 5
  114428. };
  114429. static static_codebook _44c2_s_p8_1 = {
  114430. 2, 25,
  114431. _vq_lengthlist__44c2_s_p8_1,
  114432. 1, -533725184, 1611661312, 3, 0,
  114433. _vq_quantlist__44c2_s_p8_1,
  114434. NULL,
  114435. &_vq_auxt__44c2_s_p8_1,
  114436. NULL,
  114437. 0
  114438. };
  114439. static long _vq_quantlist__44c2_s_p9_0[] = {
  114440. 6,
  114441. 5,
  114442. 7,
  114443. 4,
  114444. 8,
  114445. 3,
  114446. 9,
  114447. 2,
  114448. 10,
  114449. 1,
  114450. 11,
  114451. 0,
  114452. 12,
  114453. };
  114454. static long _vq_lengthlist__44c2_s_p9_0[] = {
  114455. 1, 5, 4,12,12,12,12,12,12,12,12,12,12, 4, 9, 8,
  114456. 11,11,11,11,11,11,11,11,11,11, 2, 8, 7,11,11,11,
  114457. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114458. 11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,
  114459. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114460. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114461. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114462. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114463. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114464. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114465. 11,11,11,11,11,11,11,11,11,
  114466. };
  114467. static float _vq_quantthresh__44c2_s_p9_0[] = {
  114468. -1215.5, -994.5, -773.5, -552.5, -331.5, -110.5, 110.5, 331.5,
  114469. 552.5, 773.5, 994.5, 1215.5,
  114470. };
  114471. static long _vq_quantmap__44c2_s_p9_0[] = {
  114472. 11, 9, 7, 5, 3, 1, 0, 2,
  114473. 4, 6, 8, 10, 12,
  114474. };
  114475. static encode_aux_threshmatch _vq_auxt__44c2_s_p9_0 = {
  114476. _vq_quantthresh__44c2_s_p9_0,
  114477. _vq_quantmap__44c2_s_p9_0,
  114478. 13,
  114479. 13
  114480. };
  114481. static static_codebook _44c2_s_p9_0 = {
  114482. 2, 169,
  114483. _vq_lengthlist__44c2_s_p9_0,
  114484. 1, -514541568, 1627103232, 4, 0,
  114485. _vq_quantlist__44c2_s_p9_0,
  114486. NULL,
  114487. &_vq_auxt__44c2_s_p9_0,
  114488. NULL,
  114489. 0
  114490. };
  114491. static long _vq_quantlist__44c2_s_p9_1[] = {
  114492. 6,
  114493. 5,
  114494. 7,
  114495. 4,
  114496. 8,
  114497. 3,
  114498. 9,
  114499. 2,
  114500. 10,
  114501. 1,
  114502. 11,
  114503. 0,
  114504. 12,
  114505. };
  114506. static long _vq_lengthlist__44c2_s_p9_1[] = {
  114507. 1, 4, 4, 6, 6, 7, 6, 8, 8,10, 9,10,10, 6, 5, 5,
  114508. 7, 7, 8, 7,10, 9,11,11,12,13, 6, 5, 5, 7, 7, 8,
  114509. 8,10,10,11,11,13,13,18, 8, 8, 8, 8, 9, 9,10,10,
  114510. 12,12,12,13,18, 8, 8, 8, 8, 9, 9,10,10,12,12,13,
  114511. 13,18,11,11, 8, 8,10,10,11,11,12,11,13,12,18,11,
  114512. 11, 9, 7,10,10,11,11,11,12,12,13,17,17,17,10,10,
  114513. 11,11,12,12,12,10,12,12,17,17,17,11,10,11,10,13,
  114514. 12,11,12,12,12,17,17,17,15,14,11,11,12,11,13,10,
  114515. 13,12,17,17,17,14,14,12,10,11,11,13,13,13,13,17,
  114516. 17,16,17,16,13,13,12,10,13,10,14,13,17,16,17,16,
  114517. 17,13,12,12,10,13,11,14,14,
  114518. };
  114519. static float _vq_quantthresh__44c2_s_p9_1[] = {
  114520. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  114521. 42.5, 59.5, 76.5, 93.5,
  114522. };
  114523. static long _vq_quantmap__44c2_s_p9_1[] = {
  114524. 11, 9, 7, 5, 3, 1, 0, 2,
  114525. 4, 6, 8, 10, 12,
  114526. };
  114527. static encode_aux_threshmatch _vq_auxt__44c2_s_p9_1 = {
  114528. _vq_quantthresh__44c2_s_p9_1,
  114529. _vq_quantmap__44c2_s_p9_1,
  114530. 13,
  114531. 13
  114532. };
  114533. static static_codebook _44c2_s_p9_1 = {
  114534. 2, 169,
  114535. _vq_lengthlist__44c2_s_p9_1,
  114536. 1, -522616832, 1620115456, 4, 0,
  114537. _vq_quantlist__44c2_s_p9_1,
  114538. NULL,
  114539. &_vq_auxt__44c2_s_p9_1,
  114540. NULL,
  114541. 0
  114542. };
  114543. static long _vq_quantlist__44c2_s_p9_2[] = {
  114544. 8,
  114545. 7,
  114546. 9,
  114547. 6,
  114548. 10,
  114549. 5,
  114550. 11,
  114551. 4,
  114552. 12,
  114553. 3,
  114554. 13,
  114555. 2,
  114556. 14,
  114557. 1,
  114558. 15,
  114559. 0,
  114560. 16,
  114561. };
  114562. static long _vq_lengthlist__44c2_s_p9_2[] = {
  114563. 2, 4, 4, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8,
  114564. 8,10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  114565. 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9,
  114566. 9, 9, 9,10, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,
  114567. 9, 9, 9, 9,10,10,10, 8, 7, 8, 8, 8, 8, 9, 9, 9,
  114568. 9, 9, 9, 9, 9,10,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  114569. 9, 9,10, 9, 9, 9,10,11,10, 8, 8, 8, 8, 9, 9, 9,
  114570. 9, 9, 9, 9,10,10,10,10,11,10, 8, 8, 9, 9, 9, 9,
  114571. 9, 9,10, 9, 9,10, 9,10,11,10,11,11,11, 8, 8, 9,
  114572. 9, 9, 9, 9, 9, 9, 9,10,10,11,11,11,11,11, 9, 9,
  114573. 9, 9, 9, 9,10, 9, 9, 9,10,10,11,11,11,11,11, 9,
  114574. 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,11,11,11,11,11,
  114575. 9, 9, 9, 9,10,10, 9, 9, 9,10,10,10,11,11,11,11,
  114576. 11,11,11, 9, 9, 9,10, 9, 9,10,10,10,10,11,11,10,
  114577. 11,11,11,11,10, 9,10,10, 9, 9, 9, 9,10,10,11,10,
  114578. 11,11,11,11,11, 9, 9, 9, 9,10, 9,10,10,10,10,11,
  114579. 10,11,11,11,11,11,10,10, 9, 9,10, 9,10,10,10,10,
  114580. 10,10,10,11,11,11,11,11,11, 9, 9,10, 9,10, 9,10,
  114581. 10,
  114582. };
  114583. static float _vq_quantthresh__44c2_s_p9_2[] = {
  114584. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  114585. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  114586. };
  114587. static long _vq_quantmap__44c2_s_p9_2[] = {
  114588. 15, 13, 11, 9, 7, 5, 3, 1,
  114589. 0, 2, 4, 6, 8, 10, 12, 14,
  114590. 16,
  114591. };
  114592. static encode_aux_threshmatch _vq_auxt__44c2_s_p9_2 = {
  114593. _vq_quantthresh__44c2_s_p9_2,
  114594. _vq_quantmap__44c2_s_p9_2,
  114595. 17,
  114596. 17
  114597. };
  114598. static static_codebook _44c2_s_p9_2 = {
  114599. 2, 289,
  114600. _vq_lengthlist__44c2_s_p9_2,
  114601. 1, -529530880, 1611661312, 5, 0,
  114602. _vq_quantlist__44c2_s_p9_2,
  114603. NULL,
  114604. &_vq_auxt__44c2_s_p9_2,
  114605. NULL,
  114606. 0
  114607. };
  114608. static long _huff_lengthlist__44c2_s_short[] = {
  114609. 11, 9,13,12,12,11,12,12,13,15, 8, 2,11, 4, 8, 5,
  114610. 7,10,12,15,13, 7,10, 9, 8, 8,10,13,17,17,11, 4,
  114611. 12, 5, 9, 5, 8,11,14,16,12, 6, 8, 7, 6, 6, 8,11,
  114612. 13,16,11, 4, 9, 5, 6, 4, 6,10,13,16,11, 6,11, 7,
  114613. 7, 6, 7,10,13,15,13, 9,12, 9, 8, 6, 8,10,12,14,
  114614. 14,10,10, 8, 6, 5, 6, 9,11,13,15,11,11, 9, 6, 5,
  114615. 6, 8, 9,12,
  114616. };
  114617. static static_codebook _huff_book__44c2_s_short = {
  114618. 2, 100,
  114619. _huff_lengthlist__44c2_s_short,
  114620. 0, 0, 0, 0, 0,
  114621. NULL,
  114622. NULL,
  114623. NULL,
  114624. NULL,
  114625. 0
  114626. };
  114627. static long _huff_lengthlist__44c3_s_long[] = {
  114628. 5, 6,11,11,11,11,10,10,12,11, 5, 2,11, 5, 6, 6,
  114629. 7, 9,11,13,13,10, 7,11, 6, 7, 8, 9,10,12,11, 5,
  114630. 11, 6, 8, 7, 9,11,14,15,11, 6, 6, 8, 4, 5, 7, 8,
  114631. 10,13,10, 5, 7, 7, 5, 5, 6, 8,10,11,10, 7, 7, 8,
  114632. 6, 5, 5, 7, 9, 9,11, 8, 8,11, 8, 7, 6, 6, 7, 9,
  114633. 12,11,10,13, 9, 9, 7, 7, 7, 9,11,13,12,15,12,11,
  114634. 9, 8, 8, 8,
  114635. };
  114636. static static_codebook _huff_book__44c3_s_long = {
  114637. 2, 100,
  114638. _huff_lengthlist__44c3_s_long,
  114639. 0, 0, 0, 0, 0,
  114640. NULL,
  114641. NULL,
  114642. NULL,
  114643. NULL,
  114644. 0
  114645. };
  114646. static long _vq_quantlist__44c3_s_p1_0[] = {
  114647. 1,
  114648. 0,
  114649. 2,
  114650. };
  114651. static long _vq_lengthlist__44c3_s_p1_0[] = {
  114652. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0,
  114653. 0, 0, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114657. 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  114658. 0, 0, 0, 6, 7, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114662. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0,
  114663. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  114698. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 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, 7, 8, 8, 0, 0, 0,
  114703. 0, 0, 0, 8, 8, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 6, 8, 8, 0, 0,
  114708. 0, 0, 0, 0, 7, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  114709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114743. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  114744. 0, 0, 0, 0, 7, 8, 8, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  114749. 0, 0, 0, 0, 0, 7, 8, 9, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  114754. 0, 0, 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 0,
  114755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114985. 0, 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,
  115063. };
  115064. static float _vq_quantthresh__44c3_s_p1_0[] = {
  115065. -0.5, 0.5,
  115066. };
  115067. static long _vq_quantmap__44c3_s_p1_0[] = {
  115068. 1, 0, 2,
  115069. };
  115070. static encode_aux_threshmatch _vq_auxt__44c3_s_p1_0 = {
  115071. _vq_quantthresh__44c3_s_p1_0,
  115072. _vq_quantmap__44c3_s_p1_0,
  115073. 3,
  115074. 3
  115075. };
  115076. static static_codebook _44c3_s_p1_0 = {
  115077. 8, 6561,
  115078. _vq_lengthlist__44c3_s_p1_0,
  115079. 1, -535822336, 1611661312, 2, 0,
  115080. _vq_quantlist__44c3_s_p1_0,
  115081. NULL,
  115082. &_vq_auxt__44c3_s_p1_0,
  115083. NULL,
  115084. 0
  115085. };
  115086. static long _vq_quantlist__44c3_s_p2_0[] = {
  115087. 2,
  115088. 1,
  115089. 3,
  115090. 0,
  115091. 4,
  115092. };
  115093. static long _vq_lengthlist__44c3_s_p2_0[] = {
  115094. 2, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0,
  115095. 7, 8, 0, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 7,
  115096. 7, 0, 0, 0, 7, 7, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  115097. 0, 0, 5, 6, 6, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0,
  115098. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115103. 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0,
  115104. 0, 7, 7, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5,
  115105. 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9,
  115106. 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115111. 0, 0, 0, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7,
  115112. 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0,
  115113. 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9, 9, 0, 0,
  115114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115119. 8,10,10, 0, 0, 0, 9, 9, 0, 0, 0, 9, 9, 0, 0, 0,
  115120. 10,10, 0, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0, 0, 9,
  115121. 9, 0, 0, 0, 9, 9, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  115122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115133. 0,
  115134. };
  115135. static float _vq_quantthresh__44c3_s_p2_0[] = {
  115136. -1.5, -0.5, 0.5, 1.5,
  115137. };
  115138. static long _vq_quantmap__44c3_s_p2_0[] = {
  115139. 3, 1, 0, 2, 4,
  115140. };
  115141. static encode_aux_threshmatch _vq_auxt__44c3_s_p2_0 = {
  115142. _vq_quantthresh__44c3_s_p2_0,
  115143. _vq_quantmap__44c3_s_p2_0,
  115144. 5,
  115145. 5
  115146. };
  115147. static static_codebook _44c3_s_p2_0 = {
  115148. 4, 625,
  115149. _vq_lengthlist__44c3_s_p2_0,
  115150. 1, -533725184, 1611661312, 3, 0,
  115151. _vq_quantlist__44c3_s_p2_0,
  115152. NULL,
  115153. &_vq_auxt__44c3_s_p2_0,
  115154. NULL,
  115155. 0
  115156. };
  115157. static long _vq_quantlist__44c3_s_p3_0[] = {
  115158. 2,
  115159. 1,
  115160. 3,
  115161. 0,
  115162. 4,
  115163. };
  115164. static long _vq_lengthlist__44c3_s_p3_0[] = {
  115165. 2, 4, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  115167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115168. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  115170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115171. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  115172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115199. 0, 0, 0, 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,
  115205. };
  115206. static float _vq_quantthresh__44c3_s_p3_0[] = {
  115207. -1.5, -0.5, 0.5, 1.5,
  115208. };
  115209. static long _vq_quantmap__44c3_s_p3_0[] = {
  115210. 3, 1, 0, 2, 4,
  115211. };
  115212. static encode_aux_threshmatch _vq_auxt__44c3_s_p3_0 = {
  115213. _vq_quantthresh__44c3_s_p3_0,
  115214. _vq_quantmap__44c3_s_p3_0,
  115215. 5,
  115216. 5
  115217. };
  115218. static static_codebook _44c3_s_p3_0 = {
  115219. 4, 625,
  115220. _vq_lengthlist__44c3_s_p3_0,
  115221. 1, -533725184, 1611661312, 3, 0,
  115222. _vq_quantlist__44c3_s_p3_0,
  115223. NULL,
  115224. &_vq_auxt__44c3_s_p3_0,
  115225. NULL,
  115226. 0
  115227. };
  115228. static long _vq_quantlist__44c3_s_p4_0[] = {
  115229. 4,
  115230. 3,
  115231. 5,
  115232. 2,
  115233. 6,
  115234. 1,
  115235. 7,
  115236. 0,
  115237. 8,
  115238. };
  115239. static long _vq_lengthlist__44c3_s_p4_0[] = {
  115240. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0,
  115241. 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, 6, 6,
  115242. 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0,
  115243. 7, 8, 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0,
  115244. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115245. 0,
  115246. };
  115247. static float _vq_quantthresh__44c3_s_p4_0[] = {
  115248. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  115249. };
  115250. static long _vq_quantmap__44c3_s_p4_0[] = {
  115251. 7, 5, 3, 1, 0, 2, 4, 6,
  115252. 8,
  115253. };
  115254. static encode_aux_threshmatch _vq_auxt__44c3_s_p4_0 = {
  115255. _vq_quantthresh__44c3_s_p4_0,
  115256. _vq_quantmap__44c3_s_p4_0,
  115257. 9,
  115258. 9
  115259. };
  115260. static static_codebook _44c3_s_p4_0 = {
  115261. 2, 81,
  115262. _vq_lengthlist__44c3_s_p4_0,
  115263. 1, -531628032, 1611661312, 4, 0,
  115264. _vq_quantlist__44c3_s_p4_0,
  115265. NULL,
  115266. &_vq_auxt__44c3_s_p4_0,
  115267. NULL,
  115268. 0
  115269. };
  115270. static long _vq_quantlist__44c3_s_p5_0[] = {
  115271. 4,
  115272. 3,
  115273. 5,
  115274. 2,
  115275. 6,
  115276. 1,
  115277. 7,
  115278. 0,
  115279. 8,
  115280. };
  115281. static long _vq_lengthlist__44c3_s_p5_0[] = {
  115282. 1, 3, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 7, 8,
  115283. 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  115284. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  115285. 9, 9, 9, 9,10,10, 0, 0, 0, 9, 9, 9, 9,10,10, 0,
  115286. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0,10,10,11,
  115287. 11,
  115288. };
  115289. static float _vq_quantthresh__44c3_s_p5_0[] = {
  115290. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  115291. };
  115292. static long _vq_quantmap__44c3_s_p5_0[] = {
  115293. 7, 5, 3, 1, 0, 2, 4, 6,
  115294. 8,
  115295. };
  115296. static encode_aux_threshmatch _vq_auxt__44c3_s_p5_0 = {
  115297. _vq_quantthresh__44c3_s_p5_0,
  115298. _vq_quantmap__44c3_s_p5_0,
  115299. 9,
  115300. 9
  115301. };
  115302. static static_codebook _44c3_s_p5_0 = {
  115303. 2, 81,
  115304. _vq_lengthlist__44c3_s_p5_0,
  115305. 1, -531628032, 1611661312, 4, 0,
  115306. _vq_quantlist__44c3_s_p5_0,
  115307. NULL,
  115308. &_vq_auxt__44c3_s_p5_0,
  115309. NULL,
  115310. 0
  115311. };
  115312. static long _vq_quantlist__44c3_s_p6_0[] = {
  115313. 8,
  115314. 7,
  115315. 9,
  115316. 6,
  115317. 10,
  115318. 5,
  115319. 11,
  115320. 4,
  115321. 12,
  115322. 3,
  115323. 13,
  115324. 2,
  115325. 14,
  115326. 1,
  115327. 15,
  115328. 0,
  115329. 16,
  115330. };
  115331. static long _vq_lengthlist__44c3_s_p6_0[] = {
  115332. 2, 3, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  115333. 10, 0, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,
  115334. 11,11, 0, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  115335. 10,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  115336. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  115337. 10,11,11,11,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  115338. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9,
  115339. 9,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  115340. 10,10,11,10,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  115341. 10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 8,
  115342. 9, 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 8,
  115343. 8, 9, 9,10,10,11,11,12,11,12,12, 0, 0, 0, 0, 0,
  115344. 9,10,10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0,
  115345. 0, 0, 0,10,10,10,10,11,11,12,12,13,13, 0, 0, 0,
  115346. 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0, 0,
  115347. 0, 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0,
  115348. 0, 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,13,
  115349. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,
  115350. 13,
  115351. };
  115352. static float _vq_quantthresh__44c3_s_p6_0[] = {
  115353. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  115354. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  115355. };
  115356. static long _vq_quantmap__44c3_s_p6_0[] = {
  115357. 15, 13, 11, 9, 7, 5, 3, 1,
  115358. 0, 2, 4, 6, 8, 10, 12, 14,
  115359. 16,
  115360. };
  115361. static encode_aux_threshmatch _vq_auxt__44c3_s_p6_0 = {
  115362. _vq_quantthresh__44c3_s_p6_0,
  115363. _vq_quantmap__44c3_s_p6_0,
  115364. 17,
  115365. 17
  115366. };
  115367. static static_codebook _44c3_s_p6_0 = {
  115368. 2, 289,
  115369. _vq_lengthlist__44c3_s_p6_0,
  115370. 1, -529530880, 1611661312, 5, 0,
  115371. _vq_quantlist__44c3_s_p6_0,
  115372. NULL,
  115373. &_vq_auxt__44c3_s_p6_0,
  115374. NULL,
  115375. 0
  115376. };
  115377. static long _vq_quantlist__44c3_s_p7_0[] = {
  115378. 1,
  115379. 0,
  115380. 2,
  115381. };
  115382. static long _vq_lengthlist__44c3_s_p7_0[] = {
  115383. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  115384. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  115385. 10,12,11,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  115386. 11,10,10,11,10,10, 7,11,11,11,11,11,12,11,11, 6,
  115387. 9, 9,11,10,10,11,10,10, 6, 9, 9,11,10,10,11,10,
  115388. 10,
  115389. };
  115390. static float _vq_quantthresh__44c3_s_p7_0[] = {
  115391. -5.5, 5.5,
  115392. };
  115393. static long _vq_quantmap__44c3_s_p7_0[] = {
  115394. 1, 0, 2,
  115395. };
  115396. static encode_aux_threshmatch _vq_auxt__44c3_s_p7_0 = {
  115397. _vq_quantthresh__44c3_s_p7_0,
  115398. _vq_quantmap__44c3_s_p7_0,
  115399. 3,
  115400. 3
  115401. };
  115402. static static_codebook _44c3_s_p7_0 = {
  115403. 4, 81,
  115404. _vq_lengthlist__44c3_s_p7_0,
  115405. 1, -529137664, 1618345984, 2, 0,
  115406. _vq_quantlist__44c3_s_p7_0,
  115407. NULL,
  115408. &_vq_auxt__44c3_s_p7_0,
  115409. NULL,
  115410. 0
  115411. };
  115412. static long _vq_quantlist__44c3_s_p7_1[] = {
  115413. 5,
  115414. 4,
  115415. 6,
  115416. 3,
  115417. 7,
  115418. 2,
  115419. 8,
  115420. 1,
  115421. 9,
  115422. 0,
  115423. 10,
  115424. };
  115425. static long _vq_lengthlist__44c3_s_p7_1[] = {
  115426. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  115427. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  115428. 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  115429. 7, 8, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  115430. 8, 8,10,10,10, 7, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  115431. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  115432. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 9, 8,10,10,
  115433. 10,10,10, 8, 8, 8, 8, 8, 8,
  115434. };
  115435. static float _vq_quantthresh__44c3_s_p7_1[] = {
  115436. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  115437. 3.5, 4.5,
  115438. };
  115439. static long _vq_quantmap__44c3_s_p7_1[] = {
  115440. 9, 7, 5, 3, 1, 0, 2, 4,
  115441. 6, 8, 10,
  115442. };
  115443. static encode_aux_threshmatch _vq_auxt__44c3_s_p7_1 = {
  115444. _vq_quantthresh__44c3_s_p7_1,
  115445. _vq_quantmap__44c3_s_p7_1,
  115446. 11,
  115447. 11
  115448. };
  115449. static static_codebook _44c3_s_p7_1 = {
  115450. 2, 121,
  115451. _vq_lengthlist__44c3_s_p7_1,
  115452. 1, -531365888, 1611661312, 4, 0,
  115453. _vq_quantlist__44c3_s_p7_1,
  115454. NULL,
  115455. &_vq_auxt__44c3_s_p7_1,
  115456. NULL,
  115457. 0
  115458. };
  115459. static long _vq_quantlist__44c3_s_p8_0[] = {
  115460. 6,
  115461. 5,
  115462. 7,
  115463. 4,
  115464. 8,
  115465. 3,
  115466. 9,
  115467. 2,
  115468. 10,
  115469. 1,
  115470. 11,
  115471. 0,
  115472. 12,
  115473. };
  115474. static long _vq_lengthlist__44c3_s_p8_0[] = {
  115475. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  115476. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 5, 7, 7, 8,
  115477. 8, 8, 8, 9, 9,11,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  115478. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  115479. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,12, 0,13,
  115480. 13, 9, 9,10,10,10,10,11,11,12,12, 0, 0, 0,10,10,
  115481. 10,10,11,11,12,12,12,12, 0, 0, 0,10,10,10,10,11,
  115482. 11,12,12,12,12, 0, 0, 0,14,14,11,11,11,11,12,12,
  115483. 13,13, 0, 0, 0,14,14,11,11,11,11,12,12,13,13, 0,
  115484. 0, 0, 0, 0,12,12,12,12,13,13,14,13, 0, 0, 0, 0,
  115485. 0,13,13,12,12,13,12,14,13,
  115486. };
  115487. static float _vq_quantthresh__44c3_s_p8_0[] = {
  115488. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  115489. 12.5, 17.5, 22.5, 27.5,
  115490. };
  115491. static long _vq_quantmap__44c3_s_p8_0[] = {
  115492. 11, 9, 7, 5, 3, 1, 0, 2,
  115493. 4, 6, 8, 10, 12,
  115494. };
  115495. static encode_aux_threshmatch _vq_auxt__44c3_s_p8_0 = {
  115496. _vq_quantthresh__44c3_s_p8_0,
  115497. _vq_quantmap__44c3_s_p8_0,
  115498. 13,
  115499. 13
  115500. };
  115501. static static_codebook _44c3_s_p8_0 = {
  115502. 2, 169,
  115503. _vq_lengthlist__44c3_s_p8_0,
  115504. 1, -526516224, 1616117760, 4, 0,
  115505. _vq_quantlist__44c3_s_p8_0,
  115506. NULL,
  115507. &_vq_auxt__44c3_s_p8_0,
  115508. NULL,
  115509. 0
  115510. };
  115511. static long _vq_quantlist__44c3_s_p8_1[] = {
  115512. 2,
  115513. 1,
  115514. 3,
  115515. 0,
  115516. 4,
  115517. };
  115518. static long _vq_lengthlist__44c3_s_p8_1[] = {
  115519. 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 4, 5, 5, 5, 6,
  115520. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  115521. };
  115522. static float _vq_quantthresh__44c3_s_p8_1[] = {
  115523. -1.5, -0.5, 0.5, 1.5,
  115524. };
  115525. static long _vq_quantmap__44c3_s_p8_1[] = {
  115526. 3, 1, 0, 2, 4,
  115527. };
  115528. static encode_aux_threshmatch _vq_auxt__44c3_s_p8_1 = {
  115529. _vq_quantthresh__44c3_s_p8_1,
  115530. _vq_quantmap__44c3_s_p8_1,
  115531. 5,
  115532. 5
  115533. };
  115534. static static_codebook _44c3_s_p8_1 = {
  115535. 2, 25,
  115536. _vq_lengthlist__44c3_s_p8_1,
  115537. 1, -533725184, 1611661312, 3, 0,
  115538. _vq_quantlist__44c3_s_p8_1,
  115539. NULL,
  115540. &_vq_auxt__44c3_s_p8_1,
  115541. NULL,
  115542. 0
  115543. };
  115544. static long _vq_quantlist__44c3_s_p9_0[] = {
  115545. 6,
  115546. 5,
  115547. 7,
  115548. 4,
  115549. 8,
  115550. 3,
  115551. 9,
  115552. 2,
  115553. 10,
  115554. 1,
  115555. 11,
  115556. 0,
  115557. 12,
  115558. };
  115559. static long _vq_lengthlist__44c3_s_p9_0[] = {
  115560. 1, 4, 4,12,12,12,12,12,12,12,12,12,12, 4, 9, 8,
  115561. 12,12,12,12,12,12,12,12,12,12, 2, 9, 7,12,12,12,
  115562. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115563. 12,12,12,12,12,12,11,12,12,12,12,12,12,12,12,12,
  115564. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115565. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115566. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115567. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115568. 12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,
  115569. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  115570. 11,11,11,11,11,11,11,11,11,
  115571. };
  115572. static float _vq_quantthresh__44c3_s_p9_0[] = {
  115573. -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5, 382.5,
  115574. 637.5, 892.5, 1147.5, 1402.5,
  115575. };
  115576. static long _vq_quantmap__44c3_s_p9_0[] = {
  115577. 11, 9, 7, 5, 3, 1, 0, 2,
  115578. 4, 6, 8, 10, 12,
  115579. };
  115580. static encode_aux_threshmatch _vq_auxt__44c3_s_p9_0 = {
  115581. _vq_quantthresh__44c3_s_p9_0,
  115582. _vq_quantmap__44c3_s_p9_0,
  115583. 13,
  115584. 13
  115585. };
  115586. static static_codebook _44c3_s_p9_0 = {
  115587. 2, 169,
  115588. _vq_lengthlist__44c3_s_p9_0,
  115589. 1, -514332672, 1627381760, 4, 0,
  115590. _vq_quantlist__44c3_s_p9_0,
  115591. NULL,
  115592. &_vq_auxt__44c3_s_p9_0,
  115593. NULL,
  115594. 0
  115595. };
  115596. static long _vq_quantlist__44c3_s_p9_1[] = {
  115597. 7,
  115598. 6,
  115599. 8,
  115600. 5,
  115601. 9,
  115602. 4,
  115603. 10,
  115604. 3,
  115605. 11,
  115606. 2,
  115607. 12,
  115608. 1,
  115609. 13,
  115610. 0,
  115611. 14,
  115612. };
  115613. static long _vq_lengthlist__44c3_s_p9_1[] = {
  115614. 1, 4, 4, 6, 6, 7, 7, 8, 7, 9, 9,10,10,10,10, 6,
  115615. 5, 5, 7, 7, 8, 8,10, 8,11,10,12,12,13,13, 6, 5,
  115616. 5, 7, 7, 8, 8,10, 9,11,11,12,12,13,12,18, 8, 8,
  115617. 8, 8, 9, 9,10, 9,11,10,12,12,13,13,18, 8, 8, 8,
  115618. 8, 9, 9,10,10,11,11,13,12,14,13,18,11,11, 9, 9,
  115619. 10,10,11,11,11,12,13,12,13,14,18,11,11, 9, 8,11,
  115620. 10,11,11,11,11,12,12,14,13,18,18,18,10,11,10,11,
  115621. 12,12,12,12,13,12,14,13,18,18,18,10,11,11, 9,12,
  115622. 11,12,12,12,13,13,13,18,18,17,14,14,11,11,12,12,
  115623. 13,12,14,12,14,13,18,18,18,14,14,11,10,12, 9,12,
  115624. 13,13,13,13,13,18,18,17,16,18,13,13,12,12,13,11,
  115625. 14,12,14,14,17,18,18,17,18,13,12,13,10,12,11,14,
  115626. 14,14,14,17,18,18,18,18,15,16,12,12,13,10,14,12,
  115627. 14,15,18,18,18,16,17,16,14,12,11,13,10,13,13,14,
  115628. 15,
  115629. };
  115630. static float _vq_quantthresh__44c3_s_p9_1[] = {
  115631. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  115632. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  115633. };
  115634. static long _vq_quantmap__44c3_s_p9_1[] = {
  115635. 13, 11, 9, 7, 5, 3, 1, 0,
  115636. 2, 4, 6, 8, 10, 12, 14,
  115637. };
  115638. static encode_aux_threshmatch _vq_auxt__44c3_s_p9_1 = {
  115639. _vq_quantthresh__44c3_s_p9_1,
  115640. _vq_quantmap__44c3_s_p9_1,
  115641. 15,
  115642. 15
  115643. };
  115644. static static_codebook _44c3_s_p9_1 = {
  115645. 2, 225,
  115646. _vq_lengthlist__44c3_s_p9_1,
  115647. 1, -522338304, 1620115456, 4, 0,
  115648. _vq_quantlist__44c3_s_p9_1,
  115649. NULL,
  115650. &_vq_auxt__44c3_s_p9_1,
  115651. NULL,
  115652. 0
  115653. };
  115654. static long _vq_quantlist__44c3_s_p9_2[] = {
  115655. 8,
  115656. 7,
  115657. 9,
  115658. 6,
  115659. 10,
  115660. 5,
  115661. 11,
  115662. 4,
  115663. 12,
  115664. 3,
  115665. 13,
  115666. 2,
  115667. 14,
  115668. 1,
  115669. 15,
  115670. 0,
  115671. 16,
  115672. };
  115673. static long _vq_lengthlist__44c3_s_p9_2[] = {
  115674. 2, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8,
  115675. 8,10, 6, 6, 7, 7, 8, 7, 8, 8, 8, 8, 8, 9, 9, 9,
  115676. 9, 9,10, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  115677. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  115678. 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 9, 9, 9, 9,
  115679. 9, 9, 9, 9, 9,11,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  115680. 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  115681. 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 9, 9, 9, 9, 9,
  115682. 9, 9, 9, 9, 9, 9,10, 9,10,10,10,11,11, 9, 9, 9,
  115683. 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,11,11,11, 9, 9,
  115684. 9, 9, 9, 9,10,10, 9, 9,10, 9,11,10,11,11,11, 9,
  115685. 9, 9, 9, 9, 9, 9, 9,10,10,10, 9,11,11,11,11,11,
  115686. 9, 9, 9, 9,10,10, 9, 9, 9, 9,10, 9,11,11,11,11,
  115687. 11,11,11, 9, 9, 9, 9, 9, 9,10,10,10,10,11,11,11,
  115688. 11,11,11,11,10, 9,10,10, 9,10, 9, 9,10, 9,11,10,
  115689. 10,11,11,11,11, 9,10, 9, 9, 9, 9,10,10,10,10,11,
  115690. 11,11,11,11,11,10,10,10, 9, 9,10, 9,10, 9,10,10,
  115691. 10,10,11,11,11,11,11,11,11, 9, 9, 9, 9, 9,10,10,
  115692. 10,
  115693. };
  115694. static float _vq_quantthresh__44c3_s_p9_2[] = {
  115695. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  115696. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  115697. };
  115698. static long _vq_quantmap__44c3_s_p9_2[] = {
  115699. 15, 13, 11, 9, 7, 5, 3, 1,
  115700. 0, 2, 4, 6, 8, 10, 12, 14,
  115701. 16,
  115702. };
  115703. static encode_aux_threshmatch _vq_auxt__44c3_s_p9_2 = {
  115704. _vq_quantthresh__44c3_s_p9_2,
  115705. _vq_quantmap__44c3_s_p9_2,
  115706. 17,
  115707. 17
  115708. };
  115709. static static_codebook _44c3_s_p9_2 = {
  115710. 2, 289,
  115711. _vq_lengthlist__44c3_s_p9_2,
  115712. 1, -529530880, 1611661312, 5, 0,
  115713. _vq_quantlist__44c3_s_p9_2,
  115714. NULL,
  115715. &_vq_auxt__44c3_s_p9_2,
  115716. NULL,
  115717. 0
  115718. };
  115719. static long _huff_lengthlist__44c3_s_short[] = {
  115720. 10, 9,13,11,14,10,12,13,13,14, 7, 2,12, 5,10, 5,
  115721. 7,10,12,14,12, 6, 9, 8, 7, 7, 9,11,13,16,10, 4,
  115722. 12, 5,10, 6, 8,12,14,16,12, 6, 8, 7, 6, 5, 7,11,
  115723. 12,16,10, 4, 8, 5, 6, 4, 6, 9,13,16,10, 6,10, 7,
  115724. 7, 6, 7, 9,13,15,12, 9,11, 9, 8, 6, 7,10,12,14,
  115725. 14,11,10, 9, 6, 5, 6, 9,11,13,15,13,11,10, 6, 5,
  115726. 6, 8, 9,11,
  115727. };
  115728. static static_codebook _huff_book__44c3_s_short = {
  115729. 2, 100,
  115730. _huff_lengthlist__44c3_s_short,
  115731. 0, 0, 0, 0, 0,
  115732. NULL,
  115733. NULL,
  115734. NULL,
  115735. NULL,
  115736. 0
  115737. };
  115738. static long _huff_lengthlist__44c4_s_long[] = {
  115739. 4, 7,11,11,11,11,10,11,12,11, 5, 2,11, 5, 6, 6,
  115740. 7, 9,11,12,11, 9, 6,10, 6, 7, 8, 9,10,11,11, 5,
  115741. 11, 7, 8, 8, 9,11,13,14,11, 6, 5, 8, 4, 5, 7, 8,
  115742. 10,11,10, 6, 7, 7, 5, 5, 6, 8, 9,11,10, 7, 8, 9,
  115743. 6, 6, 6, 7, 8, 9,11, 9, 9,11, 7, 7, 6, 6, 7, 9,
  115744. 12,12,10,13, 9, 8, 7, 7, 7, 8,11,13,11,14,11,10,
  115745. 9, 8, 7, 7,
  115746. };
  115747. static static_codebook _huff_book__44c4_s_long = {
  115748. 2, 100,
  115749. _huff_lengthlist__44c4_s_long,
  115750. 0, 0, 0, 0, 0,
  115751. NULL,
  115752. NULL,
  115753. NULL,
  115754. NULL,
  115755. 0
  115756. };
  115757. static long _vq_quantlist__44c4_s_p1_0[] = {
  115758. 1,
  115759. 0,
  115760. 2,
  115761. };
  115762. static long _vq_lengthlist__44c4_s_p1_0[] = {
  115763. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0,
  115764. 0, 0, 5, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115768. 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  115769. 0, 0, 0, 6, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115773. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0,
  115774. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  115809. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 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, 7, 8, 8, 0, 0, 0,
  115814. 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 6, 8, 8, 0, 0,
  115819. 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  115820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115854. 0, 0, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  115855. 0, 0, 0, 0, 7, 8, 8, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  115860. 0, 0, 0, 0, 0, 8, 8, 9, 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, 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  115865. 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  115866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116096. 0, 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,
  116174. };
  116175. static float _vq_quantthresh__44c4_s_p1_0[] = {
  116176. -0.5, 0.5,
  116177. };
  116178. static long _vq_quantmap__44c4_s_p1_0[] = {
  116179. 1, 0, 2,
  116180. };
  116181. static encode_aux_threshmatch _vq_auxt__44c4_s_p1_0 = {
  116182. _vq_quantthresh__44c4_s_p1_0,
  116183. _vq_quantmap__44c4_s_p1_0,
  116184. 3,
  116185. 3
  116186. };
  116187. static static_codebook _44c4_s_p1_0 = {
  116188. 8, 6561,
  116189. _vq_lengthlist__44c4_s_p1_0,
  116190. 1, -535822336, 1611661312, 2, 0,
  116191. _vq_quantlist__44c4_s_p1_0,
  116192. NULL,
  116193. &_vq_auxt__44c4_s_p1_0,
  116194. NULL,
  116195. 0
  116196. };
  116197. static long _vq_quantlist__44c4_s_p2_0[] = {
  116198. 2,
  116199. 1,
  116200. 3,
  116201. 0,
  116202. 4,
  116203. };
  116204. static long _vq_lengthlist__44c4_s_p2_0[] = {
  116205. 2, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0,
  116206. 7, 7, 0, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 7,
  116207. 7, 0, 0, 0, 7, 7, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  116208. 0, 0, 5, 6, 6, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0,
  116209. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116214. 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 7, 7, 0, 0,
  116215. 0, 7, 7, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5,
  116216. 7, 8, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9,
  116217. 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116222. 0, 0, 0, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7,
  116223. 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0,
  116224. 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9, 9, 0, 0,
  116225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116230. 7,10,10, 0, 0, 0, 9, 9, 0, 0, 0, 9, 9, 0, 0, 0,
  116231. 10,10, 0, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0, 0, 9,
  116232. 9, 0, 0, 0, 9, 9, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  116233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116244. 0,
  116245. };
  116246. static float _vq_quantthresh__44c4_s_p2_0[] = {
  116247. -1.5, -0.5, 0.5, 1.5,
  116248. };
  116249. static long _vq_quantmap__44c4_s_p2_0[] = {
  116250. 3, 1, 0, 2, 4,
  116251. };
  116252. static encode_aux_threshmatch _vq_auxt__44c4_s_p2_0 = {
  116253. _vq_quantthresh__44c4_s_p2_0,
  116254. _vq_quantmap__44c4_s_p2_0,
  116255. 5,
  116256. 5
  116257. };
  116258. static static_codebook _44c4_s_p2_0 = {
  116259. 4, 625,
  116260. _vq_lengthlist__44c4_s_p2_0,
  116261. 1, -533725184, 1611661312, 3, 0,
  116262. _vq_quantlist__44c4_s_p2_0,
  116263. NULL,
  116264. &_vq_auxt__44c4_s_p2_0,
  116265. NULL,
  116266. 0
  116267. };
  116268. static long _vq_quantlist__44c4_s_p3_0[] = {
  116269. 2,
  116270. 1,
  116271. 3,
  116272. 0,
  116273. 4,
  116274. };
  116275. static long _vq_lengthlist__44c4_s_p3_0[] = {
  116276. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 4, 6, 6, 0, 0,
  116278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116279. 0, 0, 4, 4, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  116281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116282. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  116283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116310. 0, 0, 0, 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,
  116316. };
  116317. static float _vq_quantthresh__44c4_s_p3_0[] = {
  116318. -1.5, -0.5, 0.5, 1.5,
  116319. };
  116320. static long _vq_quantmap__44c4_s_p3_0[] = {
  116321. 3, 1, 0, 2, 4,
  116322. };
  116323. static encode_aux_threshmatch _vq_auxt__44c4_s_p3_0 = {
  116324. _vq_quantthresh__44c4_s_p3_0,
  116325. _vq_quantmap__44c4_s_p3_0,
  116326. 5,
  116327. 5
  116328. };
  116329. static static_codebook _44c4_s_p3_0 = {
  116330. 4, 625,
  116331. _vq_lengthlist__44c4_s_p3_0,
  116332. 1, -533725184, 1611661312, 3, 0,
  116333. _vq_quantlist__44c4_s_p3_0,
  116334. NULL,
  116335. &_vq_auxt__44c4_s_p3_0,
  116336. NULL,
  116337. 0
  116338. };
  116339. static long _vq_quantlist__44c4_s_p4_0[] = {
  116340. 4,
  116341. 3,
  116342. 5,
  116343. 2,
  116344. 6,
  116345. 1,
  116346. 7,
  116347. 0,
  116348. 8,
  116349. };
  116350. static long _vq_lengthlist__44c4_s_p4_0[] = {
  116351. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0,
  116352. 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, 6, 6,
  116353. 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0,
  116354. 7, 8, 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0,
  116355. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116356. 0,
  116357. };
  116358. static float _vq_quantthresh__44c4_s_p4_0[] = {
  116359. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  116360. };
  116361. static long _vq_quantmap__44c4_s_p4_0[] = {
  116362. 7, 5, 3, 1, 0, 2, 4, 6,
  116363. 8,
  116364. };
  116365. static encode_aux_threshmatch _vq_auxt__44c4_s_p4_0 = {
  116366. _vq_quantthresh__44c4_s_p4_0,
  116367. _vq_quantmap__44c4_s_p4_0,
  116368. 9,
  116369. 9
  116370. };
  116371. static static_codebook _44c4_s_p4_0 = {
  116372. 2, 81,
  116373. _vq_lengthlist__44c4_s_p4_0,
  116374. 1, -531628032, 1611661312, 4, 0,
  116375. _vq_quantlist__44c4_s_p4_0,
  116376. NULL,
  116377. &_vq_auxt__44c4_s_p4_0,
  116378. NULL,
  116379. 0
  116380. };
  116381. static long _vq_quantlist__44c4_s_p5_0[] = {
  116382. 4,
  116383. 3,
  116384. 5,
  116385. 2,
  116386. 6,
  116387. 1,
  116388. 7,
  116389. 0,
  116390. 8,
  116391. };
  116392. static long _vq_lengthlist__44c4_s_p5_0[] = {
  116393. 2, 3, 3, 6, 6, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  116394. 9, 9, 0, 4, 5, 6, 6, 7, 7, 9, 9, 0, 6, 6, 7, 7,
  116395. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10, 9, 0, 0, 0,
  116396. 9, 8, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  116397. 0, 0,10,10, 9, 9,11,11, 0, 0, 0, 0, 0, 9, 9,10,
  116398. 10,
  116399. };
  116400. static float _vq_quantthresh__44c4_s_p5_0[] = {
  116401. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  116402. };
  116403. static long _vq_quantmap__44c4_s_p5_0[] = {
  116404. 7, 5, 3, 1, 0, 2, 4, 6,
  116405. 8,
  116406. };
  116407. static encode_aux_threshmatch _vq_auxt__44c4_s_p5_0 = {
  116408. _vq_quantthresh__44c4_s_p5_0,
  116409. _vq_quantmap__44c4_s_p5_0,
  116410. 9,
  116411. 9
  116412. };
  116413. static static_codebook _44c4_s_p5_0 = {
  116414. 2, 81,
  116415. _vq_lengthlist__44c4_s_p5_0,
  116416. 1, -531628032, 1611661312, 4, 0,
  116417. _vq_quantlist__44c4_s_p5_0,
  116418. NULL,
  116419. &_vq_auxt__44c4_s_p5_0,
  116420. NULL,
  116421. 0
  116422. };
  116423. static long _vq_quantlist__44c4_s_p6_0[] = {
  116424. 8,
  116425. 7,
  116426. 9,
  116427. 6,
  116428. 10,
  116429. 5,
  116430. 11,
  116431. 4,
  116432. 12,
  116433. 3,
  116434. 13,
  116435. 2,
  116436. 14,
  116437. 1,
  116438. 15,
  116439. 0,
  116440. 16,
  116441. };
  116442. static long _vq_lengthlist__44c4_s_p6_0[] = {
  116443. 2, 4, 4, 6, 6, 8, 8, 9, 9, 8, 8, 9, 9,10,10,11,
  116444. 11, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,11,
  116445. 11,11, 0, 4, 4, 7, 6, 8, 8, 9, 9, 9, 9,10,10,11,
  116446. 11,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  116447. 11,11,11,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  116448. 10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  116449. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9,
  116450. 9,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  116451. 10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  116452. 10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,
  116453. 9,10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9,
  116454. 9, 9, 9,10,10,11,11,11,12,12,12, 0, 0, 0, 0, 0,
  116455. 10,10,10,10,11,11,11,11,12,12,13,12, 0, 0, 0, 0,
  116456. 0, 0, 0,10,10,11,11,11,11,12,12,12,12, 0, 0, 0,
  116457. 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0, 0,
  116458. 0, 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0,
  116459. 0, 0, 0, 0, 0, 0,12,12,12,12,12,12,13,13,13,13,
  116460. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,12,13,13,
  116461. 13,
  116462. };
  116463. static float _vq_quantthresh__44c4_s_p6_0[] = {
  116464. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  116465. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  116466. };
  116467. static long _vq_quantmap__44c4_s_p6_0[] = {
  116468. 15, 13, 11, 9, 7, 5, 3, 1,
  116469. 0, 2, 4, 6, 8, 10, 12, 14,
  116470. 16,
  116471. };
  116472. static encode_aux_threshmatch _vq_auxt__44c4_s_p6_0 = {
  116473. _vq_quantthresh__44c4_s_p6_0,
  116474. _vq_quantmap__44c4_s_p6_0,
  116475. 17,
  116476. 17
  116477. };
  116478. static static_codebook _44c4_s_p6_0 = {
  116479. 2, 289,
  116480. _vq_lengthlist__44c4_s_p6_0,
  116481. 1, -529530880, 1611661312, 5, 0,
  116482. _vq_quantlist__44c4_s_p6_0,
  116483. NULL,
  116484. &_vq_auxt__44c4_s_p6_0,
  116485. NULL,
  116486. 0
  116487. };
  116488. static long _vq_quantlist__44c4_s_p7_0[] = {
  116489. 1,
  116490. 0,
  116491. 2,
  116492. };
  116493. static long _vq_lengthlist__44c4_s_p7_0[] = {
  116494. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  116495. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  116496. 10,11,11,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  116497. 11,10,10,11,10,10, 7,11,11,12,11,11,12,11,11, 6,
  116498. 9, 9,11,10,10,11,10,10, 6, 9, 9,11,10,10,11,10,
  116499. 10,
  116500. };
  116501. static float _vq_quantthresh__44c4_s_p7_0[] = {
  116502. -5.5, 5.5,
  116503. };
  116504. static long _vq_quantmap__44c4_s_p7_0[] = {
  116505. 1, 0, 2,
  116506. };
  116507. static encode_aux_threshmatch _vq_auxt__44c4_s_p7_0 = {
  116508. _vq_quantthresh__44c4_s_p7_0,
  116509. _vq_quantmap__44c4_s_p7_0,
  116510. 3,
  116511. 3
  116512. };
  116513. static static_codebook _44c4_s_p7_0 = {
  116514. 4, 81,
  116515. _vq_lengthlist__44c4_s_p7_0,
  116516. 1, -529137664, 1618345984, 2, 0,
  116517. _vq_quantlist__44c4_s_p7_0,
  116518. NULL,
  116519. &_vq_auxt__44c4_s_p7_0,
  116520. NULL,
  116521. 0
  116522. };
  116523. static long _vq_quantlist__44c4_s_p7_1[] = {
  116524. 5,
  116525. 4,
  116526. 6,
  116527. 3,
  116528. 7,
  116529. 2,
  116530. 8,
  116531. 1,
  116532. 9,
  116533. 0,
  116534. 10,
  116535. };
  116536. static long _vq_lengthlist__44c4_s_p7_1[] = {
  116537. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  116538. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  116539. 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  116540. 7, 8, 8, 8, 8, 8, 8,10,10,10, 8, 7, 8, 8, 8, 8,
  116541. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  116542. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  116543. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 9, 8,10,10,
  116544. 10,10,10, 8, 8, 8, 8, 9, 9,
  116545. };
  116546. static float _vq_quantthresh__44c4_s_p7_1[] = {
  116547. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  116548. 3.5, 4.5,
  116549. };
  116550. static long _vq_quantmap__44c4_s_p7_1[] = {
  116551. 9, 7, 5, 3, 1, 0, 2, 4,
  116552. 6, 8, 10,
  116553. };
  116554. static encode_aux_threshmatch _vq_auxt__44c4_s_p7_1 = {
  116555. _vq_quantthresh__44c4_s_p7_1,
  116556. _vq_quantmap__44c4_s_p7_1,
  116557. 11,
  116558. 11
  116559. };
  116560. static static_codebook _44c4_s_p7_1 = {
  116561. 2, 121,
  116562. _vq_lengthlist__44c4_s_p7_1,
  116563. 1, -531365888, 1611661312, 4, 0,
  116564. _vq_quantlist__44c4_s_p7_1,
  116565. NULL,
  116566. &_vq_auxt__44c4_s_p7_1,
  116567. NULL,
  116568. 0
  116569. };
  116570. static long _vq_quantlist__44c4_s_p8_0[] = {
  116571. 6,
  116572. 5,
  116573. 7,
  116574. 4,
  116575. 8,
  116576. 3,
  116577. 9,
  116578. 2,
  116579. 10,
  116580. 1,
  116581. 11,
  116582. 0,
  116583. 12,
  116584. };
  116585. static long _vq_lengthlist__44c4_s_p8_0[] = {
  116586. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  116587. 7, 7, 8, 8, 8, 8, 9,10,11,11, 7, 5, 5, 7, 7, 8,
  116588. 8, 9, 9,10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  116589. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  116590. 11, 0,12,12, 9, 9, 9, 9,10,10,10,10,11,11, 0,13,
  116591. 13, 9, 9,10, 9,10,10,11,11,11,12, 0, 0, 0,10,10,
  116592. 10,10,10,10,11,11,12,12, 0, 0, 0,10,10,10,10,10,
  116593. 10,11,11,12,12, 0, 0, 0,14,14,11,11,11,11,12,12,
  116594. 12,12, 0, 0, 0,14,14,11,11,11,11,12,12,12,13, 0,
  116595. 0, 0, 0, 0,12,12,12,12,12,12,13,13, 0, 0, 0, 0,
  116596. 0,13,12,12,12,12,12,13,13,
  116597. };
  116598. static float _vq_quantthresh__44c4_s_p8_0[] = {
  116599. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  116600. 12.5, 17.5, 22.5, 27.5,
  116601. };
  116602. static long _vq_quantmap__44c4_s_p8_0[] = {
  116603. 11, 9, 7, 5, 3, 1, 0, 2,
  116604. 4, 6, 8, 10, 12,
  116605. };
  116606. static encode_aux_threshmatch _vq_auxt__44c4_s_p8_0 = {
  116607. _vq_quantthresh__44c4_s_p8_0,
  116608. _vq_quantmap__44c4_s_p8_0,
  116609. 13,
  116610. 13
  116611. };
  116612. static static_codebook _44c4_s_p8_0 = {
  116613. 2, 169,
  116614. _vq_lengthlist__44c4_s_p8_0,
  116615. 1, -526516224, 1616117760, 4, 0,
  116616. _vq_quantlist__44c4_s_p8_0,
  116617. NULL,
  116618. &_vq_auxt__44c4_s_p8_0,
  116619. NULL,
  116620. 0
  116621. };
  116622. static long _vq_quantlist__44c4_s_p8_1[] = {
  116623. 2,
  116624. 1,
  116625. 3,
  116626. 0,
  116627. 4,
  116628. };
  116629. static long _vq_lengthlist__44c4_s_p8_1[] = {
  116630. 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 5, 4, 5, 5, 6,
  116631. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  116632. };
  116633. static float _vq_quantthresh__44c4_s_p8_1[] = {
  116634. -1.5, -0.5, 0.5, 1.5,
  116635. };
  116636. static long _vq_quantmap__44c4_s_p8_1[] = {
  116637. 3, 1, 0, 2, 4,
  116638. };
  116639. static encode_aux_threshmatch _vq_auxt__44c4_s_p8_1 = {
  116640. _vq_quantthresh__44c4_s_p8_1,
  116641. _vq_quantmap__44c4_s_p8_1,
  116642. 5,
  116643. 5
  116644. };
  116645. static static_codebook _44c4_s_p8_1 = {
  116646. 2, 25,
  116647. _vq_lengthlist__44c4_s_p8_1,
  116648. 1, -533725184, 1611661312, 3, 0,
  116649. _vq_quantlist__44c4_s_p8_1,
  116650. NULL,
  116651. &_vq_auxt__44c4_s_p8_1,
  116652. NULL,
  116653. 0
  116654. };
  116655. static long _vq_quantlist__44c4_s_p9_0[] = {
  116656. 6,
  116657. 5,
  116658. 7,
  116659. 4,
  116660. 8,
  116661. 3,
  116662. 9,
  116663. 2,
  116664. 10,
  116665. 1,
  116666. 11,
  116667. 0,
  116668. 12,
  116669. };
  116670. static long _vq_lengthlist__44c4_s_p9_0[] = {
  116671. 1, 3, 3,12,12,12,12,12,12,12,12,12,12, 4, 7, 7,
  116672. 12,12,12,12,12,12,12,12,12,12, 3, 8, 8,12,12,12,
  116673. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116674. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116675. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116676. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116677. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116678. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116679. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116680. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116681. 12,12,12,12,12,12,12,12,12,
  116682. };
  116683. static float _vq_quantthresh__44c4_s_p9_0[] = {
  116684. -1732.5, -1417.5, -1102.5, -787.5, -472.5, -157.5, 157.5, 472.5,
  116685. 787.5, 1102.5, 1417.5, 1732.5,
  116686. };
  116687. static long _vq_quantmap__44c4_s_p9_0[] = {
  116688. 11, 9, 7, 5, 3, 1, 0, 2,
  116689. 4, 6, 8, 10, 12,
  116690. };
  116691. static encode_aux_threshmatch _vq_auxt__44c4_s_p9_0 = {
  116692. _vq_quantthresh__44c4_s_p9_0,
  116693. _vq_quantmap__44c4_s_p9_0,
  116694. 13,
  116695. 13
  116696. };
  116697. static static_codebook _44c4_s_p9_0 = {
  116698. 2, 169,
  116699. _vq_lengthlist__44c4_s_p9_0,
  116700. 1, -513964032, 1628680192, 4, 0,
  116701. _vq_quantlist__44c4_s_p9_0,
  116702. NULL,
  116703. &_vq_auxt__44c4_s_p9_0,
  116704. NULL,
  116705. 0
  116706. };
  116707. static long _vq_quantlist__44c4_s_p9_1[] = {
  116708. 7,
  116709. 6,
  116710. 8,
  116711. 5,
  116712. 9,
  116713. 4,
  116714. 10,
  116715. 3,
  116716. 11,
  116717. 2,
  116718. 12,
  116719. 1,
  116720. 13,
  116721. 0,
  116722. 14,
  116723. };
  116724. static long _vq_lengthlist__44c4_s_p9_1[] = {
  116725. 1, 4, 4, 5, 5, 7, 7, 9, 8,10, 9,10,10,10,10, 6,
  116726. 5, 5, 7, 7, 9, 8,10, 9,11,10,12,12,13,13, 6, 5,
  116727. 5, 7, 7, 9, 9,10,10,11,11,12,12,12,13,19, 8, 8,
  116728. 8, 8, 9, 9,10,10,12,11,12,12,13,13,19, 8, 8, 8,
  116729. 8, 9, 9,11,11,12,12,13,13,13,13,19,12,12, 9, 9,
  116730. 11,11,11,11,12,11,13,12,13,13,18,12,12, 9, 9,11,
  116731. 10,11,11,12,12,12,13,13,14,19,18,18,11,11,11,11,
  116732. 12,12,13,12,13,13,14,14,16,18,18,11,11,11,10,12,
  116733. 11,13,13,13,13,13,14,17,18,18,14,15,11,12,12,13,
  116734. 13,13,13,14,14,14,18,18,18,15,15,12,10,13,10,13,
  116735. 13,13,13,13,14,18,17,18,17,18,12,13,12,13,13,13,
  116736. 14,14,16,14,18,17,18,18,17,13,12,13,10,12,12,14,
  116737. 14,14,14,17,18,18,18,18,14,15,12,12,13,12,14,14,
  116738. 15,15,18,18,18,17,18,15,14,12,11,12,12,14,14,14,
  116739. 15,
  116740. };
  116741. static float _vq_quantthresh__44c4_s_p9_1[] = {
  116742. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  116743. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  116744. };
  116745. static long _vq_quantmap__44c4_s_p9_1[] = {
  116746. 13, 11, 9, 7, 5, 3, 1, 0,
  116747. 2, 4, 6, 8, 10, 12, 14,
  116748. };
  116749. static encode_aux_threshmatch _vq_auxt__44c4_s_p9_1 = {
  116750. _vq_quantthresh__44c4_s_p9_1,
  116751. _vq_quantmap__44c4_s_p9_1,
  116752. 15,
  116753. 15
  116754. };
  116755. static static_codebook _44c4_s_p9_1 = {
  116756. 2, 225,
  116757. _vq_lengthlist__44c4_s_p9_1,
  116758. 1, -520986624, 1620377600, 4, 0,
  116759. _vq_quantlist__44c4_s_p9_1,
  116760. NULL,
  116761. &_vq_auxt__44c4_s_p9_1,
  116762. NULL,
  116763. 0
  116764. };
  116765. static long _vq_quantlist__44c4_s_p9_2[] = {
  116766. 10,
  116767. 9,
  116768. 11,
  116769. 8,
  116770. 12,
  116771. 7,
  116772. 13,
  116773. 6,
  116774. 14,
  116775. 5,
  116776. 15,
  116777. 4,
  116778. 16,
  116779. 3,
  116780. 17,
  116781. 2,
  116782. 18,
  116783. 1,
  116784. 19,
  116785. 0,
  116786. 20,
  116787. };
  116788. static long _vq_lengthlist__44c4_s_p9_2[] = {
  116789. 2, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  116790. 8, 9, 9, 9, 9,11, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  116791. 9, 9, 9, 9, 9, 9,10,10,10,10,11, 6, 6, 7, 7, 8,
  116792. 8, 8, 8, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,11,
  116793. 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  116794. 10,10,10,10,12,11,11, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  116795. 9,10,10,10,10,10,10,10,10,12,11,12, 8, 8, 8, 8,
  116796. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,11,11,
  116797. 11, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,10,10,10,10,
  116798. 10,10,10,11,11,12, 9, 9, 9, 9, 9, 9,10, 9,10,10,
  116799. 10,10,10,10,10,10,10,10,11,11,11,11,11, 9, 9, 9,
  116800. 9,10,10,10,10,10,10,10,10,10,10,10,10,11,12,11,
  116801. 11,11, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  116802. 10,10,11,11,11,11,11, 9, 9, 9, 9,10,10,10,10,10,
  116803. 10,10,10,10,10,10,10,11,11,11,12,12,10,10,10,10,
  116804. 10,10,10,10,10,10,10,10,10,10,10,10,11,12,11,12,
  116805. 11,11,11, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  116806. 10,11,12,11,11,11,11,11,10,10,10,10,10,10,10,10,
  116807. 10,10,10,10,10,10,11,11,11,12,11,11,11,10,10,10,
  116808. 10,10,10,10,10,10,10,10,10,10,10,12,11,11,12,11,
  116809. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  116810. 11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
  116811. 10,10,10,10,10,11,11,11,11,12,12,11,11,11,11,11,
  116812. 11,11,10,10,10,10,10,10,10,10,12,12,12,11,11,11,
  116813. 12,11,11,11,10,10,10,10,10,10,10,10,10,10,10,12,
  116814. 11,12,12,12,12,12,11,12,11,11,10,10,10,10,10,10,
  116815. 10,10,10,10,12,12,12,12,11,11,11,11,11,11,11,10,
  116816. 10,10,10,10,10,10,10,10,10,
  116817. };
  116818. static float _vq_quantthresh__44c4_s_p9_2[] = {
  116819. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  116820. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  116821. 6.5, 7.5, 8.5, 9.5,
  116822. };
  116823. static long _vq_quantmap__44c4_s_p9_2[] = {
  116824. 19, 17, 15, 13, 11, 9, 7, 5,
  116825. 3, 1, 0, 2, 4, 6, 8, 10,
  116826. 12, 14, 16, 18, 20,
  116827. };
  116828. static encode_aux_threshmatch _vq_auxt__44c4_s_p9_2 = {
  116829. _vq_quantthresh__44c4_s_p9_2,
  116830. _vq_quantmap__44c4_s_p9_2,
  116831. 21,
  116832. 21
  116833. };
  116834. static static_codebook _44c4_s_p9_2 = {
  116835. 2, 441,
  116836. _vq_lengthlist__44c4_s_p9_2,
  116837. 1, -529268736, 1611661312, 5, 0,
  116838. _vq_quantlist__44c4_s_p9_2,
  116839. NULL,
  116840. &_vq_auxt__44c4_s_p9_2,
  116841. NULL,
  116842. 0
  116843. };
  116844. static long _huff_lengthlist__44c4_s_short[] = {
  116845. 4, 7,14,10,15,10,12,15,16,15, 4, 2,11, 5,10, 6,
  116846. 8,11,14,14,14,10, 7,11, 6, 8,10,11,13,15, 9, 4,
  116847. 11, 5, 9, 6, 9,12,14,15,14, 9, 6, 9, 4, 5, 7,10,
  116848. 12,13, 9, 5, 7, 6, 5, 5, 7,10,13,13,10, 8, 9, 8,
  116849. 7, 6, 8,10,14,14,13,11,10,10, 7, 7, 8,11,14,15,
  116850. 13,12, 9, 9, 6, 5, 7,10,14,17,15,13,11,10, 6, 6,
  116851. 7, 9,12,17,
  116852. };
  116853. static static_codebook _huff_book__44c4_s_short = {
  116854. 2, 100,
  116855. _huff_lengthlist__44c4_s_short,
  116856. 0, 0, 0, 0, 0,
  116857. NULL,
  116858. NULL,
  116859. NULL,
  116860. NULL,
  116861. 0
  116862. };
  116863. static long _huff_lengthlist__44c5_s_long[] = {
  116864. 3, 8, 9,13,10,12,12,12,12,12, 6, 4, 6, 8, 6, 8,
  116865. 10,10,11,12, 8, 5, 4,10, 4, 7, 8, 9,10,11,13, 8,
  116866. 10, 8, 9, 9,11,12,13,14,10, 6, 4, 9, 3, 5, 6, 8,
  116867. 10,11,11, 8, 6, 9, 5, 5, 6, 7, 9,11,12, 9, 7,11,
  116868. 6, 6, 6, 7, 8,10,12,11, 9,12, 7, 7, 6, 6, 7, 9,
  116869. 13,12,10,13, 9, 8, 7, 7, 7, 8,11,15,11,15,11,10,
  116870. 9, 8, 7, 7,
  116871. };
  116872. static static_codebook _huff_book__44c5_s_long = {
  116873. 2, 100,
  116874. _huff_lengthlist__44c5_s_long,
  116875. 0, 0, 0, 0, 0,
  116876. NULL,
  116877. NULL,
  116878. NULL,
  116879. NULL,
  116880. 0
  116881. };
  116882. static long _vq_quantlist__44c5_s_p1_0[] = {
  116883. 1,
  116884. 0,
  116885. 2,
  116886. };
  116887. static long _vq_lengthlist__44c5_s_p1_0[] = {
  116888. 2, 4, 4, 0, 0, 0, 0, 0, 0, 4, 7, 7, 0, 0, 0, 0,
  116889. 0, 0, 4, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116893. 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  116894. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116898. 0, 0, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  116899. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 7, 7, 0, 0, 0, 0,
  116934. 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 7, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  116939. 0, 0, 0, 9,10,11, 0, 0, 0, 0, 0, 0, 9,10,10, 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, 7, 9, 9, 0, 0,
  116944. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  116945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116979. 0, 0, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  116980. 0, 0, 0, 0, 7, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  116985. 0, 0, 0, 0, 0, 8, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  116990. 0, 0, 0, 0, 0, 0, 9,11,10, 0, 0, 0, 0, 0, 0, 0,
  116991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117221. 0, 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,
  117299. };
  117300. static float _vq_quantthresh__44c5_s_p1_0[] = {
  117301. -0.5, 0.5,
  117302. };
  117303. static long _vq_quantmap__44c5_s_p1_0[] = {
  117304. 1, 0, 2,
  117305. };
  117306. static encode_aux_threshmatch _vq_auxt__44c5_s_p1_0 = {
  117307. _vq_quantthresh__44c5_s_p1_0,
  117308. _vq_quantmap__44c5_s_p1_0,
  117309. 3,
  117310. 3
  117311. };
  117312. static static_codebook _44c5_s_p1_0 = {
  117313. 8, 6561,
  117314. _vq_lengthlist__44c5_s_p1_0,
  117315. 1, -535822336, 1611661312, 2, 0,
  117316. _vq_quantlist__44c5_s_p1_0,
  117317. NULL,
  117318. &_vq_auxt__44c5_s_p1_0,
  117319. NULL,
  117320. 0
  117321. };
  117322. static long _vq_quantlist__44c5_s_p2_0[] = {
  117323. 2,
  117324. 1,
  117325. 3,
  117326. 0,
  117327. 4,
  117328. };
  117329. static long _vq_lengthlist__44c5_s_p2_0[] = {
  117330. 2, 4, 4, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0,
  117331. 8, 7, 0, 0, 0, 0, 0, 0, 0, 4, 6, 6, 0, 0, 0, 8,
  117332. 8, 0, 0, 0, 8, 7, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  117333. 0, 0, 4, 6, 6, 0, 0, 0, 8, 8, 0, 0, 0, 7, 8, 0,
  117334. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117339. 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 8, 8, 0, 0,
  117340. 0, 8, 8, 0, 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 5,
  117341. 7, 8, 0, 0, 0, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0,10,
  117342. 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117347. 0, 0, 0, 5, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0, 8, 8,
  117348. 0, 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0,
  117349. 0, 0, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0,10,10, 0, 0,
  117350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117355. 8,10,10, 0, 0, 0,10,10, 0, 0, 0, 9,10, 0, 0, 0,
  117356. 11,10, 0, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0, 0,10,
  117357. 10, 0, 0, 0,10,10, 0, 0, 0,10,11, 0, 0, 0, 0, 0,
  117358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117369. 0,
  117370. };
  117371. static float _vq_quantthresh__44c5_s_p2_0[] = {
  117372. -1.5, -0.5, 0.5, 1.5,
  117373. };
  117374. static long _vq_quantmap__44c5_s_p2_0[] = {
  117375. 3, 1, 0, 2, 4,
  117376. };
  117377. static encode_aux_threshmatch _vq_auxt__44c5_s_p2_0 = {
  117378. _vq_quantthresh__44c5_s_p2_0,
  117379. _vq_quantmap__44c5_s_p2_0,
  117380. 5,
  117381. 5
  117382. };
  117383. static static_codebook _44c5_s_p2_0 = {
  117384. 4, 625,
  117385. _vq_lengthlist__44c5_s_p2_0,
  117386. 1, -533725184, 1611661312, 3, 0,
  117387. _vq_quantlist__44c5_s_p2_0,
  117388. NULL,
  117389. &_vq_auxt__44c5_s_p2_0,
  117390. NULL,
  117391. 0
  117392. };
  117393. static long _vq_quantlist__44c5_s_p3_0[] = {
  117394. 2,
  117395. 1,
  117396. 3,
  117397. 0,
  117398. 4,
  117399. };
  117400. static long _vq_lengthlist__44c5_s_p3_0[] = {
  117401. 2, 4, 3, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 6, 6, 0, 0,
  117403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117404. 0, 0, 3, 5, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 8, 8,
  117406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117407. 0, 0, 0, 0, 5, 6, 6, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  117408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117435. 0, 0, 0, 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,
  117441. };
  117442. static float _vq_quantthresh__44c5_s_p3_0[] = {
  117443. -1.5, -0.5, 0.5, 1.5,
  117444. };
  117445. static long _vq_quantmap__44c5_s_p3_0[] = {
  117446. 3, 1, 0, 2, 4,
  117447. };
  117448. static encode_aux_threshmatch _vq_auxt__44c5_s_p3_0 = {
  117449. _vq_quantthresh__44c5_s_p3_0,
  117450. _vq_quantmap__44c5_s_p3_0,
  117451. 5,
  117452. 5
  117453. };
  117454. static static_codebook _44c5_s_p3_0 = {
  117455. 4, 625,
  117456. _vq_lengthlist__44c5_s_p3_0,
  117457. 1, -533725184, 1611661312, 3, 0,
  117458. _vq_quantlist__44c5_s_p3_0,
  117459. NULL,
  117460. &_vq_auxt__44c5_s_p3_0,
  117461. NULL,
  117462. 0
  117463. };
  117464. static long _vq_quantlist__44c5_s_p4_0[] = {
  117465. 4,
  117466. 3,
  117467. 5,
  117468. 2,
  117469. 6,
  117470. 1,
  117471. 7,
  117472. 0,
  117473. 8,
  117474. };
  117475. static long _vq_lengthlist__44c5_s_p4_0[] = {
  117476. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0,
  117477. 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, 6, 6,
  117478. 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0,
  117479. 7, 7, 0, 0, 0, 0, 0, 0, 0, 8, 7, 0, 0, 0, 0, 0,
  117480. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117481. 0,
  117482. };
  117483. static float _vq_quantthresh__44c5_s_p4_0[] = {
  117484. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  117485. };
  117486. static long _vq_quantmap__44c5_s_p4_0[] = {
  117487. 7, 5, 3, 1, 0, 2, 4, 6,
  117488. 8,
  117489. };
  117490. static encode_aux_threshmatch _vq_auxt__44c5_s_p4_0 = {
  117491. _vq_quantthresh__44c5_s_p4_0,
  117492. _vq_quantmap__44c5_s_p4_0,
  117493. 9,
  117494. 9
  117495. };
  117496. static static_codebook _44c5_s_p4_0 = {
  117497. 2, 81,
  117498. _vq_lengthlist__44c5_s_p4_0,
  117499. 1, -531628032, 1611661312, 4, 0,
  117500. _vq_quantlist__44c5_s_p4_0,
  117501. NULL,
  117502. &_vq_auxt__44c5_s_p4_0,
  117503. NULL,
  117504. 0
  117505. };
  117506. static long _vq_quantlist__44c5_s_p5_0[] = {
  117507. 4,
  117508. 3,
  117509. 5,
  117510. 2,
  117511. 6,
  117512. 1,
  117513. 7,
  117514. 0,
  117515. 8,
  117516. };
  117517. static long _vq_lengthlist__44c5_s_p5_0[] = {
  117518. 2, 4, 3, 6, 6, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  117519. 9, 9, 0, 4, 4, 6, 6, 7, 7, 9, 9, 0, 6, 6, 7, 7,
  117520. 7, 7, 9, 9, 0, 0, 0, 7, 6, 7, 7, 9, 9, 0, 0, 0,
  117521. 8, 8, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  117522. 0, 0, 9, 9, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  117523. 10,
  117524. };
  117525. static float _vq_quantthresh__44c5_s_p5_0[] = {
  117526. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  117527. };
  117528. static long _vq_quantmap__44c5_s_p5_0[] = {
  117529. 7, 5, 3, 1, 0, 2, 4, 6,
  117530. 8,
  117531. };
  117532. static encode_aux_threshmatch _vq_auxt__44c5_s_p5_0 = {
  117533. _vq_quantthresh__44c5_s_p5_0,
  117534. _vq_quantmap__44c5_s_p5_0,
  117535. 9,
  117536. 9
  117537. };
  117538. static static_codebook _44c5_s_p5_0 = {
  117539. 2, 81,
  117540. _vq_lengthlist__44c5_s_p5_0,
  117541. 1, -531628032, 1611661312, 4, 0,
  117542. _vq_quantlist__44c5_s_p5_0,
  117543. NULL,
  117544. &_vq_auxt__44c5_s_p5_0,
  117545. NULL,
  117546. 0
  117547. };
  117548. static long _vq_quantlist__44c5_s_p6_0[] = {
  117549. 8,
  117550. 7,
  117551. 9,
  117552. 6,
  117553. 10,
  117554. 5,
  117555. 11,
  117556. 4,
  117557. 12,
  117558. 3,
  117559. 13,
  117560. 2,
  117561. 14,
  117562. 1,
  117563. 15,
  117564. 0,
  117565. 16,
  117566. };
  117567. static long _vq_lengthlist__44c5_s_p6_0[] = {
  117568. 2, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,10,11,
  117569. 11, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,11,
  117570. 12,12, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,
  117571. 11,12,12, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  117572. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  117573. 10,11,11,12,12, 0, 0, 0, 7, 7, 9, 9,10,10,10,10,
  117574. 11,11,11,11,12,12, 0, 0, 0, 7, 7, 8, 9,10,10,10,
  117575. 10,11,11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,
  117576. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  117577. 10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,
  117578. 10,10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9,
  117579. 9, 9,10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0,
  117580. 10,10,10,10,11,11,11,12,12,12,13,13, 0, 0, 0, 0,
  117581. 0, 0, 0,10,10,11,11,11,11,12,12,13,13, 0, 0, 0,
  117582. 0, 0, 0, 0,11,11,11,11,12,12,12,13,13,13, 0, 0,
  117583. 0, 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0,
  117584. 0, 0, 0, 0, 0, 0,12,12,12,12,13,12,13,13,13,13,
  117585. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,
  117586. 13,
  117587. };
  117588. static float _vq_quantthresh__44c5_s_p6_0[] = {
  117589. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  117590. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  117591. };
  117592. static long _vq_quantmap__44c5_s_p6_0[] = {
  117593. 15, 13, 11, 9, 7, 5, 3, 1,
  117594. 0, 2, 4, 6, 8, 10, 12, 14,
  117595. 16,
  117596. };
  117597. static encode_aux_threshmatch _vq_auxt__44c5_s_p6_0 = {
  117598. _vq_quantthresh__44c5_s_p6_0,
  117599. _vq_quantmap__44c5_s_p6_0,
  117600. 17,
  117601. 17
  117602. };
  117603. static static_codebook _44c5_s_p6_0 = {
  117604. 2, 289,
  117605. _vq_lengthlist__44c5_s_p6_0,
  117606. 1, -529530880, 1611661312, 5, 0,
  117607. _vq_quantlist__44c5_s_p6_0,
  117608. NULL,
  117609. &_vq_auxt__44c5_s_p6_0,
  117610. NULL,
  117611. 0
  117612. };
  117613. static long _vq_quantlist__44c5_s_p7_0[] = {
  117614. 1,
  117615. 0,
  117616. 2,
  117617. };
  117618. static long _vq_lengthlist__44c5_s_p7_0[] = {
  117619. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  117620. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  117621. 10,11,11,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  117622. 11,10,10,11,10,10, 7,11,11,12,11,11,12,11,11, 6,
  117623. 9, 9,11,10,10,11,10,10, 6, 9, 9,11,10,10,11,10,
  117624. 10,
  117625. };
  117626. static float _vq_quantthresh__44c5_s_p7_0[] = {
  117627. -5.5, 5.5,
  117628. };
  117629. static long _vq_quantmap__44c5_s_p7_0[] = {
  117630. 1, 0, 2,
  117631. };
  117632. static encode_aux_threshmatch _vq_auxt__44c5_s_p7_0 = {
  117633. _vq_quantthresh__44c5_s_p7_0,
  117634. _vq_quantmap__44c5_s_p7_0,
  117635. 3,
  117636. 3
  117637. };
  117638. static static_codebook _44c5_s_p7_0 = {
  117639. 4, 81,
  117640. _vq_lengthlist__44c5_s_p7_0,
  117641. 1, -529137664, 1618345984, 2, 0,
  117642. _vq_quantlist__44c5_s_p7_0,
  117643. NULL,
  117644. &_vq_auxt__44c5_s_p7_0,
  117645. NULL,
  117646. 0
  117647. };
  117648. static long _vq_quantlist__44c5_s_p7_1[] = {
  117649. 5,
  117650. 4,
  117651. 6,
  117652. 3,
  117653. 7,
  117654. 2,
  117655. 8,
  117656. 1,
  117657. 9,
  117658. 0,
  117659. 10,
  117660. };
  117661. static long _vq_lengthlist__44c5_s_p7_1[] = {
  117662. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6,
  117663. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  117664. 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  117665. 7, 8, 8, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  117666. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  117667. 8, 8, 8, 8, 8, 8, 8, 9,10,10,10,10,10, 8, 8, 8,
  117668. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  117669. 10,10,10, 8, 8, 8, 8, 8, 8,
  117670. };
  117671. static float _vq_quantthresh__44c5_s_p7_1[] = {
  117672. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  117673. 3.5, 4.5,
  117674. };
  117675. static long _vq_quantmap__44c5_s_p7_1[] = {
  117676. 9, 7, 5, 3, 1, 0, 2, 4,
  117677. 6, 8, 10,
  117678. };
  117679. static encode_aux_threshmatch _vq_auxt__44c5_s_p7_1 = {
  117680. _vq_quantthresh__44c5_s_p7_1,
  117681. _vq_quantmap__44c5_s_p7_1,
  117682. 11,
  117683. 11
  117684. };
  117685. static static_codebook _44c5_s_p7_1 = {
  117686. 2, 121,
  117687. _vq_lengthlist__44c5_s_p7_1,
  117688. 1, -531365888, 1611661312, 4, 0,
  117689. _vq_quantlist__44c5_s_p7_1,
  117690. NULL,
  117691. &_vq_auxt__44c5_s_p7_1,
  117692. NULL,
  117693. 0
  117694. };
  117695. static long _vq_quantlist__44c5_s_p8_0[] = {
  117696. 6,
  117697. 5,
  117698. 7,
  117699. 4,
  117700. 8,
  117701. 3,
  117702. 9,
  117703. 2,
  117704. 10,
  117705. 1,
  117706. 11,
  117707. 0,
  117708. 12,
  117709. };
  117710. static long _vq_lengthlist__44c5_s_p8_0[] = {
  117711. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  117712. 7, 7, 8, 8, 8, 9,10,10,10,10, 7, 5, 5, 7, 7, 8,
  117713. 8, 9, 9,10,10,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  117714. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  117715. 11, 0,12,12, 9, 9, 9,10,10,10,10,10,11,11, 0,13,
  117716. 13, 9, 9, 9, 9,10,10,11,11,11,11, 0, 0, 0,10,10,
  117717. 10,10,10,10,11,11,11,11, 0, 0, 0,10,10,10,10,10,
  117718. 10,11,11,12,12, 0, 0, 0,14,14,11,11,11,11,12,12,
  117719. 12,12, 0, 0, 0,14,14,11,11,11,11,12,12,12,12, 0,
  117720. 0, 0, 0, 0,12,12,12,12,12,12,13,13, 0, 0, 0, 0,
  117721. 0,12,12,12,12,12,12,13,13,
  117722. };
  117723. static float _vq_quantthresh__44c5_s_p8_0[] = {
  117724. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  117725. 12.5, 17.5, 22.5, 27.5,
  117726. };
  117727. static long _vq_quantmap__44c5_s_p8_0[] = {
  117728. 11, 9, 7, 5, 3, 1, 0, 2,
  117729. 4, 6, 8, 10, 12,
  117730. };
  117731. static encode_aux_threshmatch _vq_auxt__44c5_s_p8_0 = {
  117732. _vq_quantthresh__44c5_s_p8_0,
  117733. _vq_quantmap__44c5_s_p8_0,
  117734. 13,
  117735. 13
  117736. };
  117737. static static_codebook _44c5_s_p8_0 = {
  117738. 2, 169,
  117739. _vq_lengthlist__44c5_s_p8_0,
  117740. 1, -526516224, 1616117760, 4, 0,
  117741. _vq_quantlist__44c5_s_p8_0,
  117742. NULL,
  117743. &_vq_auxt__44c5_s_p8_0,
  117744. NULL,
  117745. 0
  117746. };
  117747. static long _vq_quantlist__44c5_s_p8_1[] = {
  117748. 2,
  117749. 1,
  117750. 3,
  117751. 0,
  117752. 4,
  117753. };
  117754. static long _vq_lengthlist__44c5_s_p8_1[] = {
  117755. 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 4, 5, 5, 5, 6,
  117756. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  117757. };
  117758. static float _vq_quantthresh__44c5_s_p8_1[] = {
  117759. -1.5, -0.5, 0.5, 1.5,
  117760. };
  117761. static long _vq_quantmap__44c5_s_p8_1[] = {
  117762. 3, 1, 0, 2, 4,
  117763. };
  117764. static encode_aux_threshmatch _vq_auxt__44c5_s_p8_1 = {
  117765. _vq_quantthresh__44c5_s_p8_1,
  117766. _vq_quantmap__44c5_s_p8_1,
  117767. 5,
  117768. 5
  117769. };
  117770. static static_codebook _44c5_s_p8_1 = {
  117771. 2, 25,
  117772. _vq_lengthlist__44c5_s_p8_1,
  117773. 1, -533725184, 1611661312, 3, 0,
  117774. _vq_quantlist__44c5_s_p8_1,
  117775. NULL,
  117776. &_vq_auxt__44c5_s_p8_1,
  117777. NULL,
  117778. 0
  117779. };
  117780. static long _vq_quantlist__44c5_s_p9_0[] = {
  117781. 7,
  117782. 6,
  117783. 8,
  117784. 5,
  117785. 9,
  117786. 4,
  117787. 10,
  117788. 3,
  117789. 11,
  117790. 2,
  117791. 12,
  117792. 1,
  117793. 13,
  117794. 0,
  117795. 14,
  117796. };
  117797. static long _vq_lengthlist__44c5_s_p9_0[] = {
  117798. 1, 3, 3,13,13,13,13,13,13,13,13,13,13,13,13, 4,
  117799. 7, 7,13,13,13,13,13,13,13,13,13,13,13,13, 3, 8,
  117800. 6,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117801. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117802. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117803. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117804. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117805. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117806. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117807. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117808. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117809. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117810. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117811. 13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,
  117812. 12,
  117813. };
  117814. static float _vq_quantthresh__44c5_s_p9_0[] = {
  117815. -2320.5, -1963.5, -1606.5, -1249.5, -892.5, -535.5, -178.5, 178.5,
  117816. 535.5, 892.5, 1249.5, 1606.5, 1963.5, 2320.5,
  117817. };
  117818. static long _vq_quantmap__44c5_s_p9_0[] = {
  117819. 13, 11, 9, 7, 5, 3, 1, 0,
  117820. 2, 4, 6, 8, 10, 12, 14,
  117821. };
  117822. static encode_aux_threshmatch _vq_auxt__44c5_s_p9_0 = {
  117823. _vq_quantthresh__44c5_s_p9_0,
  117824. _vq_quantmap__44c5_s_p9_0,
  117825. 15,
  117826. 15
  117827. };
  117828. static static_codebook _44c5_s_p9_0 = {
  117829. 2, 225,
  117830. _vq_lengthlist__44c5_s_p9_0,
  117831. 1, -512522752, 1628852224, 4, 0,
  117832. _vq_quantlist__44c5_s_p9_0,
  117833. NULL,
  117834. &_vq_auxt__44c5_s_p9_0,
  117835. NULL,
  117836. 0
  117837. };
  117838. static long _vq_quantlist__44c5_s_p9_1[] = {
  117839. 8,
  117840. 7,
  117841. 9,
  117842. 6,
  117843. 10,
  117844. 5,
  117845. 11,
  117846. 4,
  117847. 12,
  117848. 3,
  117849. 13,
  117850. 2,
  117851. 14,
  117852. 1,
  117853. 15,
  117854. 0,
  117855. 16,
  117856. };
  117857. static long _vq_lengthlist__44c5_s_p9_1[] = {
  117858. 1, 4, 4, 5, 5, 7, 7, 9, 8,10, 9,10,10,11,10,11,
  117859. 11, 6, 5, 5, 7, 7, 8, 9,10,10,11,10,12,11,12,11,
  117860. 13,12, 6, 5, 5, 7, 7, 9, 9,10,10,11,11,12,12,13,
  117861. 12,13,13,18, 8, 8, 8, 8, 9, 9,10,11,11,11,12,11,
  117862. 13,11,13,12,18, 8, 8, 8, 8,10,10,11,11,12,12,13,
  117863. 13,13,13,13,14,18,12,12, 9, 9,11,11,11,11,12,12,
  117864. 13,12,13,12,13,13,20,13,12, 9, 9,11,11,11,11,12,
  117865. 12,13,13,13,14,14,13,20,18,19,11,12,11,11,12,12,
  117866. 13,13,13,13,13,13,14,13,18,19,19,12,11,11,11,12,
  117867. 12,13,12,13,13,13,14,14,13,18,17,19,14,15,12,12,
  117868. 12,13,13,13,14,14,14,14,14,14,19,19,19,16,15,12,
  117869. 11,13,12,14,14,14,13,13,14,14,14,19,18,19,18,19,
  117870. 13,13,13,13,14,14,14,13,14,14,14,14,18,17,19,19,
  117871. 19,13,13,13,11,13,11,13,14,14,14,14,14,19,17,17,
  117872. 18,18,16,16,13,13,13,13,14,13,15,15,14,14,19,19,
  117873. 17,17,18,16,16,13,11,14,10,13,12,14,14,14,14,19,
  117874. 19,19,19,19,18,17,13,14,13,11,14,13,14,14,15,15,
  117875. 19,19,19,17,19,18,18,14,13,12,11,14,11,15,15,15,
  117876. 15,
  117877. };
  117878. static float _vq_quantthresh__44c5_s_p9_1[] = {
  117879. -157.5, -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5,
  117880. 10.5, 31.5, 52.5, 73.5, 94.5, 115.5, 136.5, 157.5,
  117881. };
  117882. static long _vq_quantmap__44c5_s_p9_1[] = {
  117883. 15, 13, 11, 9, 7, 5, 3, 1,
  117884. 0, 2, 4, 6, 8, 10, 12, 14,
  117885. 16,
  117886. };
  117887. static encode_aux_threshmatch _vq_auxt__44c5_s_p9_1 = {
  117888. _vq_quantthresh__44c5_s_p9_1,
  117889. _vq_quantmap__44c5_s_p9_1,
  117890. 17,
  117891. 17
  117892. };
  117893. static static_codebook _44c5_s_p9_1 = {
  117894. 2, 289,
  117895. _vq_lengthlist__44c5_s_p9_1,
  117896. 1, -520814592, 1620377600, 5, 0,
  117897. _vq_quantlist__44c5_s_p9_1,
  117898. NULL,
  117899. &_vq_auxt__44c5_s_p9_1,
  117900. NULL,
  117901. 0
  117902. };
  117903. static long _vq_quantlist__44c5_s_p9_2[] = {
  117904. 10,
  117905. 9,
  117906. 11,
  117907. 8,
  117908. 12,
  117909. 7,
  117910. 13,
  117911. 6,
  117912. 14,
  117913. 5,
  117914. 15,
  117915. 4,
  117916. 16,
  117917. 3,
  117918. 17,
  117919. 2,
  117920. 18,
  117921. 1,
  117922. 19,
  117923. 0,
  117924. 20,
  117925. };
  117926. static long _vq_lengthlist__44c5_s_p9_2[] = {
  117927. 3, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  117928. 8, 8, 8, 8, 9,11, 5, 6, 7, 7, 8, 7, 8, 8, 8, 8,
  117929. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11, 5, 5, 7, 7, 7,
  117930. 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  117931. 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  117932. 9,10, 9,10,11,11,11, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  117933. 9, 9, 9,10,10,10,10,10,10,11,11,11, 8, 8, 8, 8,
  117934. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,11,11,
  117935. 11, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,10,
  117936. 10,10,10,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  117937. 10,10,10,10,10,10,10,10,11,11,11,11,11, 9, 9, 9,
  117938. 9, 9, 9,10, 9,10,10,10,10,10,10,10,10,11,11,11,
  117939. 11,11, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,
  117940. 10,10,11,11,11,11,11, 9, 9, 9, 9, 9, 9,10,10,10,
  117941. 10,10,10,10,10,10,10,11,11,11,11,11, 9, 9,10, 9,
  117942. 10,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,
  117943. 11,11,11, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  117944. 10,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,
  117945. 10,10,10,10,10,10,11,11,11,11,11,11,11,10,10,10,
  117946. 10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,
  117947. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  117948. 11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
  117949. 10,10,10,10,10,11,11,11,11,11,11,11,11,11,10,10,
  117950. 10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
  117951. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,11,
  117952. 11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,
  117953. 10,10,10,10,11,11,11,11,11,11,11,11,11,11,11,10,
  117954. 10,10,10,10,10,10,10,10,10,
  117955. };
  117956. static float _vq_quantthresh__44c5_s_p9_2[] = {
  117957. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  117958. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  117959. 6.5, 7.5, 8.5, 9.5,
  117960. };
  117961. static long _vq_quantmap__44c5_s_p9_2[] = {
  117962. 19, 17, 15, 13, 11, 9, 7, 5,
  117963. 3, 1, 0, 2, 4, 6, 8, 10,
  117964. 12, 14, 16, 18, 20,
  117965. };
  117966. static encode_aux_threshmatch _vq_auxt__44c5_s_p9_2 = {
  117967. _vq_quantthresh__44c5_s_p9_2,
  117968. _vq_quantmap__44c5_s_p9_2,
  117969. 21,
  117970. 21
  117971. };
  117972. static static_codebook _44c5_s_p9_2 = {
  117973. 2, 441,
  117974. _vq_lengthlist__44c5_s_p9_2,
  117975. 1, -529268736, 1611661312, 5, 0,
  117976. _vq_quantlist__44c5_s_p9_2,
  117977. NULL,
  117978. &_vq_auxt__44c5_s_p9_2,
  117979. NULL,
  117980. 0
  117981. };
  117982. static long _huff_lengthlist__44c5_s_short[] = {
  117983. 5, 8,10,14,11,11,12,16,15,17, 5, 5, 7, 9, 7, 8,
  117984. 10,13,17,17, 7, 5, 5,10, 5, 7, 8,11,13,15,10, 8,
  117985. 10, 8, 8, 8,11,15,18,18, 8, 5, 5, 8, 3, 4, 6,10,
  117986. 14,16, 9, 7, 6, 7, 4, 3, 5, 9,14,18,10, 9, 8,10,
  117987. 6, 5, 6, 9,14,18,12,12,11,12, 8, 7, 8,11,14,18,
  117988. 14,13,12,10, 7, 5, 6, 9,14,18,14,14,13,10, 6, 5,
  117989. 6, 8,11,16,
  117990. };
  117991. static static_codebook _huff_book__44c5_s_short = {
  117992. 2, 100,
  117993. _huff_lengthlist__44c5_s_short,
  117994. 0, 0, 0, 0, 0,
  117995. NULL,
  117996. NULL,
  117997. NULL,
  117998. NULL,
  117999. 0
  118000. };
  118001. static long _huff_lengthlist__44c6_s_long[] = {
  118002. 3, 8,11,13,14,14,13,13,16,14, 6, 3, 4, 7, 9, 9,
  118003. 10,11,14,13,10, 4, 3, 5, 7, 7, 9,10,13,15,12, 7,
  118004. 4, 4, 6, 6, 8,10,13,15,12, 8, 6, 6, 6, 6, 8,10,
  118005. 13,14,11, 9, 7, 6, 6, 6, 7, 8,12,11,13,10, 9, 8,
  118006. 7, 6, 6, 7,11,11,13,11,10, 9, 9, 7, 7, 6,10,11,
  118007. 13,13,13,13,13,11, 9, 8,10,12,12,15,15,16,15,12,
  118008. 11,10,10,12,
  118009. };
  118010. static static_codebook _huff_book__44c6_s_long = {
  118011. 2, 100,
  118012. _huff_lengthlist__44c6_s_long,
  118013. 0, 0, 0, 0, 0,
  118014. NULL,
  118015. NULL,
  118016. NULL,
  118017. NULL,
  118018. 0
  118019. };
  118020. static long _vq_quantlist__44c6_s_p1_0[] = {
  118021. 1,
  118022. 0,
  118023. 2,
  118024. };
  118025. static long _vq_lengthlist__44c6_s_p1_0[] = {
  118026. 1, 5, 5, 0, 5, 5, 0, 5, 5, 5, 8, 7, 0, 9, 9, 0,
  118027. 9, 8, 5, 7, 8, 0, 9, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  118028. 0, 0, 0, 0, 5, 9, 8, 0, 8, 8, 0, 8, 8, 5, 8, 9,
  118029. 0, 8, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  118030. 9, 9, 0, 8, 8, 0, 8, 8, 5, 9, 9, 0, 8, 8, 0, 8,
  118031. 8,
  118032. };
  118033. static float _vq_quantthresh__44c6_s_p1_0[] = {
  118034. -0.5, 0.5,
  118035. };
  118036. static long _vq_quantmap__44c6_s_p1_0[] = {
  118037. 1, 0, 2,
  118038. };
  118039. static encode_aux_threshmatch _vq_auxt__44c6_s_p1_0 = {
  118040. _vq_quantthresh__44c6_s_p1_0,
  118041. _vq_quantmap__44c6_s_p1_0,
  118042. 3,
  118043. 3
  118044. };
  118045. static static_codebook _44c6_s_p1_0 = {
  118046. 4, 81,
  118047. _vq_lengthlist__44c6_s_p1_0,
  118048. 1, -535822336, 1611661312, 2, 0,
  118049. _vq_quantlist__44c6_s_p1_0,
  118050. NULL,
  118051. &_vq_auxt__44c6_s_p1_0,
  118052. NULL,
  118053. 0
  118054. };
  118055. static long _vq_quantlist__44c6_s_p2_0[] = {
  118056. 2,
  118057. 1,
  118058. 3,
  118059. 0,
  118060. 4,
  118061. };
  118062. static long _vq_lengthlist__44c6_s_p2_0[] = {
  118063. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  118064. 7, 7, 9, 9, 0, 0, 0, 9, 9, 5, 7, 7, 9, 9, 0, 8,
  118065. 8,10,10, 0, 8, 7,10, 9, 0,10,10,11,11, 0, 0, 0,
  118066. 11,11, 5, 7, 7, 9, 9, 0, 8, 8,10,10, 0, 7, 8, 9,
  118067. 10, 0,10,10,11,11, 0, 0, 0,11,11, 8, 9, 9,11,11,
  118068. 0,11,11,12,12, 0,11,10,12,12, 0,13,14,14,14, 0,
  118069. 0, 0,14,13, 8, 9, 9,11,11, 0,11,11,12,12, 0,10,
  118070. 11,12,12, 0,14,13,14,14, 0, 0, 0,13,14, 0, 0, 0,
  118071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118072. 0, 0, 0, 0, 0, 0, 5, 8, 7,11,10, 0, 7, 7,10,10,
  118073. 0, 7, 7,10,10, 0, 9, 9,11,10, 0, 0, 0,11,11, 5,
  118074. 7, 8,10,11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9,
  118075. 9,10,11, 0, 0, 0,11,11, 8,10, 9,12,12, 0,10,10,
  118076. 12,12, 0,10,10,12,12, 0,12,12,13,13, 0, 0, 0,13,
  118077. 13, 8, 9,10,12,12, 0,10,10,11,12, 0,10,10,12,12,
  118078. 0,12,12,13,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0,
  118079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118080. 0, 0, 0, 5, 8, 8,11,11, 0, 7, 7,10,10, 0, 7, 7,
  118081. 10,10, 0, 9, 9,10,11, 0, 0, 0,11,10, 5, 8, 8,11,
  118082. 11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9, 9,11,11,
  118083. 0, 0, 0,10,11, 8,10,10,12,12, 0,10,10,12,12, 0,
  118084. 10,10,12,12, 0,12,13,13,13, 0, 0, 0,14,13, 8,10,
  118085. 10,12,12, 0,10,10,12,12, 0,10,10,12,12, 0,13,12,
  118086. 13,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118088. 7,10,10,14,13, 0, 9, 9,13,12, 0, 9, 9,12,12, 0,
  118089. 10,10,12,12, 0, 0, 0,12,12, 7,10,10,13,14, 0, 9,
  118090. 9,12,13, 0, 9, 9,12,12, 0,10,10,12,12, 0, 0, 0,
  118091. 12,12, 9,11,11,14,13, 0,11,10,14,13, 0,11,11,13,
  118092. 13, 0,12,12,13,13, 0, 0, 0,13,13, 9,11,11,13,14,
  118093. 0,10,11,13,14, 0,11,11,13,13, 0,12,12,13,13, 0,
  118094. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  118099. 11,11,14,14, 0,11,11,13,13, 0,11,10,13,13, 0,12,
  118100. 12,13,13, 0, 0, 0,13,13, 9,11,11,14,14, 0,11,11,
  118101. 13,13, 0,10,11,13,13, 0,12,12,14,13, 0, 0, 0,13,
  118102. 13,
  118103. };
  118104. static float _vq_quantthresh__44c6_s_p2_0[] = {
  118105. -1.5, -0.5, 0.5, 1.5,
  118106. };
  118107. static long _vq_quantmap__44c6_s_p2_0[] = {
  118108. 3, 1, 0, 2, 4,
  118109. };
  118110. static encode_aux_threshmatch _vq_auxt__44c6_s_p2_0 = {
  118111. _vq_quantthresh__44c6_s_p2_0,
  118112. _vq_quantmap__44c6_s_p2_0,
  118113. 5,
  118114. 5
  118115. };
  118116. static static_codebook _44c6_s_p2_0 = {
  118117. 4, 625,
  118118. _vq_lengthlist__44c6_s_p2_0,
  118119. 1, -533725184, 1611661312, 3, 0,
  118120. _vq_quantlist__44c6_s_p2_0,
  118121. NULL,
  118122. &_vq_auxt__44c6_s_p2_0,
  118123. NULL,
  118124. 0
  118125. };
  118126. static long _vq_quantlist__44c6_s_p3_0[] = {
  118127. 4,
  118128. 3,
  118129. 5,
  118130. 2,
  118131. 6,
  118132. 1,
  118133. 7,
  118134. 0,
  118135. 8,
  118136. };
  118137. static long _vq_lengthlist__44c6_s_p3_0[] = {
  118138. 2, 3, 4, 6, 6, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  118139. 9,10, 0, 4, 4, 6, 6, 7, 7,10, 9, 0, 5, 5, 7, 7,
  118140. 8, 8,10,10, 0, 0, 0, 7, 6, 8, 8,10,10, 0, 0, 0,
  118141. 7, 7, 9, 9,11,11, 0, 0, 0, 7, 7, 9, 9,11,11, 0,
  118142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118143. 0,
  118144. };
  118145. static float _vq_quantthresh__44c6_s_p3_0[] = {
  118146. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  118147. };
  118148. static long _vq_quantmap__44c6_s_p3_0[] = {
  118149. 7, 5, 3, 1, 0, 2, 4, 6,
  118150. 8,
  118151. };
  118152. static encode_aux_threshmatch _vq_auxt__44c6_s_p3_0 = {
  118153. _vq_quantthresh__44c6_s_p3_0,
  118154. _vq_quantmap__44c6_s_p3_0,
  118155. 9,
  118156. 9
  118157. };
  118158. static static_codebook _44c6_s_p3_0 = {
  118159. 2, 81,
  118160. _vq_lengthlist__44c6_s_p3_0,
  118161. 1, -531628032, 1611661312, 4, 0,
  118162. _vq_quantlist__44c6_s_p3_0,
  118163. NULL,
  118164. &_vq_auxt__44c6_s_p3_0,
  118165. NULL,
  118166. 0
  118167. };
  118168. static long _vq_quantlist__44c6_s_p4_0[] = {
  118169. 8,
  118170. 7,
  118171. 9,
  118172. 6,
  118173. 10,
  118174. 5,
  118175. 11,
  118176. 4,
  118177. 12,
  118178. 3,
  118179. 13,
  118180. 2,
  118181. 14,
  118182. 1,
  118183. 15,
  118184. 0,
  118185. 16,
  118186. };
  118187. static long _vq_lengthlist__44c6_s_p4_0[] = {
  118188. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9,10,10,
  118189. 10, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,10,
  118190. 11,11, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,
  118191. 10,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  118192. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  118193. 10,11,11,11,11, 0, 0, 0, 7, 7, 9, 9,10,10,10,10,
  118194. 11,11,11,11,12,12, 0, 0, 0, 7, 7, 9, 9,10,10,10,
  118195. 10,11,11,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  118196. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 8, 8, 9,
  118197. 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 0, 0,
  118198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118206. 0,
  118207. };
  118208. static float _vq_quantthresh__44c6_s_p4_0[] = {
  118209. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  118210. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  118211. };
  118212. static long _vq_quantmap__44c6_s_p4_0[] = {
  118213. 15, 13, 11, 9, 7, 5, 3, 1,
  118214. 0, 2, 4, 6, 8, 10, 12, 14,
  118215. 16,
  118216. };
  118217. static encode_aux_threshmatch _vq_auxt__44c6_s_p4_0 = {
  118218. _vq_quantthresh__44c6_s_p4_0,
  118219. _vq_quantmap__44c6_s_p4_0,
  118220. 17,
  118221. 17
  118222. };
  118223. static static_codebook _44c6_s_p4_0 = {
  118224. 2, 289,
  118225. _vq_lengthlist__44c6_s_p4_0,
  118226. 1, -529530880, 1611661312, 5, 0,
  118227. _vq_quantlist__44c6_s_p4_0,
  118228. NULL,
  118229. &_vq_auxt__44c6_s_p4_0,
  118230. NULL,
  118231. 0
  118232. };
  118233. static long _vq_quantlist__44c6_s_p5_0[] = {
  118234. 1,
  118235. 0,
  118236. 2,
  118237. };
  118238. static long _vq_lengthlist__44c6_s_p5_0[] = {
  118239. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 6, 6, 9, 9,10,10,
  118240. 10, 9, 4, 6, 6, 9,10, 9,10, 9,10, 6, 9, 9,10,12,
  118241. 11,10,11,11, 7,10, 9,11,12,12,12,12,12, 7,10,10,
  118242. 11,12,12,12,12,12, 6,10,10,10,12,12,11,12,12, 7,
  118243. 9,10,11,12,12,12,12,12, 7,10, 9,12,12,12,12,12,
  118244. 12,
  118245. };
  118246. static float _vq_quantthresh__44c6_s_p5_0[] = {
  118247. -5.5, 5.5,
  118248. };
  118249. static long _vq_quantmap__44c6_s_p5_0[] = {
  118250. 1, 0, 2,
  118251. };
  118252. static encode_aux_threshmatch _vq_auxt__44c6_s_p5_0 = {
  118253. _vq_quantthresh__44c6_s_p5_0,
  118254. _vq_quantmap__44c6_s_p5_0,
  118255. 3,
  118256. 3
  118257. };
  118258. static static_codebook _44c6_s_p5_0 = {
  118259. 4, 81,
  118260. _vq_lengthlist__44c6_s_p5_0,
  118261. 1, -529137664, 1618345984, 2, 0,
  118262. _vq_quantlist__44c6_s_p5_0,
  118263. NULL,
  118264. &_vq_auxt__44c6_s_p5_0,
  118265. NULL,
  118266. 0
  118267. };
  118268. static long _vq_quantlist__44c6_s_p5_1[] = {
  118269. 5,
  118270. 4,
  118271. 6,
  118272. 3,
  118273. 7,
  118274. 2,
  118275. 8,
  118276. 1,
  118277. 9,
  118278. 0,
  118279. 10,
  118280. };
  118281. static long _vq_lengthlist__44c6_s_p5_1[] = {
  118282. 3, 5, 4, 6, 6, 7, 7, 8, 8, 8, 8,11, 4, 4, 6, 6,
  118283. 7, 7, 8, 8, 8, 8,11, 4, 4, 6, 6, 7, 7, 8, 8, 8,
  118284. 8,11, 6, 6, 6, 6, 8, 8, 8, 8, 9, 9,11,11,11, 6,
  118285. 6, 7, 8, 8, 8, 8, 9,11,11,11, 7, 7, 8, 8, 8, 8,
  118286. 8, 8,11,11,11, 7, 7, 8, 8, 8, 8, 8, 8,11,11,11,
  118287. 8, 8, 8, 8, 8, 8, 8, 8,11,11,11,10,10, 8, 8, 8,
  118288. 8, 8, 8,11,11,11,10,10, 8, 8, 8, 8, 8, 8,11,11,
  118289. 11,10,10, 7, 7, 8, 8, 8, 8,
  118290. };
  118291. static float _vq_quantthresh__44c6_s_p5_1[] = {
  118292. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  118293. 3.5, 4.5,
  118294. };
  118295. static long _vq_quantmap__44c6_s_p5_1[] = {
  118296. 9, 7, 5, 3, 1, 0, 2, 4,
  118297. 6, 8, 10,
  118298. };
  118299. static encode_aux_threshmatch _vq_auxt__44c6_s_p5_1 = {
  118300. _vq_quantthresh__44c6_s_p5_1,
  118301. _vq_quantmap__44c6_s_p5_1,
  118302. 11,
  118303. 11
  118304. };
  118305. static static_codebook _44c6_s_p5_1 = {
  118306. 2, 121,
  118307. _vq_lengthlist__44c6_s_p5_1,
  118308. 1, -531365888, 1611661312, 4, 0,
  118309. _vq_quantlist__44c6_s_p5_1,
  118310. NULL,
  118311. &_vq_auxt__44c6_s_p5_1,
  118312. NULL,
  118313. 0
  118314. };
  118315. static long _vq_quantlist__44c6_s_p6_0[] = {
  118316. 6,
  118317. 5,
  118318. 7,
  118319. 4,
  118320. 8,
  118321. 3,
  118322. 9,
  118323. 2,
  118324. 10,
  118325. 1,
  118326. 11,
  118327. 0,
  118328. 12,
  118329. };
  118330. static long _vq_lengthlist__44c6_s_p6_0[] = {
  118331. 1, 4, 4, 6, 6, 8, 8, 8, 8,10, 9,10,10, 6, 5, 5,
  118332. 7, 7, 9, 9, 9, 9,10,10,11,11, 6, 5, 5, 7, 7, 9,
  118333. 9,10, 9,11,10,11,11, 0, 6, 6, 7, 7, 9, 9,10,10,
  118334. 11,11,12,12, 0, 7, 7, 7, 7, 9, 9,10,10,11,11,12,
  118335. 12, 0,11,11, 8, 8,10,10,11,11,12,12,12,12, 0,11,
  118336. 12, 9, 8,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  118337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118341. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118342. };
  118343. static float _vq_quantthresh__44c6_s_p6_0[] = {
  118344. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  118345. 12.5, 17.5, 22.5, 27.5,
  118346. };
  118347. static long _vq_quantmap__44c6_s_p6_0[] = {
  118348. 11, 9, 7, 5, 3, 1, 0, 2,
  118349. 4, 6, 8, 10, 12,
  118350. };
  118351. static encode_aux_threshmatch _vq_auxt__44c6_s_p6_0 = {
  118352. _vq_quantthresh__44c6_s_p6_0,
  118353. _vq_quantmap__44c6_s_p6_0,
  118354. 13,
  118355. 13
  118356. };
  118357. static static_codebook _44c6_s_p6_0 = {
  118358. 2, 169,
  118359. _vq_lengthlist__44c6_s_p6_0,
  118360. 1, -526516224, 1616117760, 4, 0,
  118361. _vq_quantlist__44c6_s_p6_0,
  118362. NULL,
  118363. &_vq_auxt__44c6_s_p6_0,
  118364. NULL,
  118365. 0
  118366. };
  118367. static long _vq_quantlist__44c6_s_p6_1[] = {
  118368. 2,
  118369. 1,
  118370. 3,
  118371. 0,
  118372. 4,
  118373. };
  118374. static long _vq_lengthlist__44c6_s_p6_1[] = {
  118375. 3, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 6,
  118376. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  118377. };
  118378. static float _vq_quantthresh__44c6_s_p6_1[] = {
  118379. -1.5, -0.5, 0.5, 1.5,
  118380. };
  118381. static long _vq_quantmap__44c6_s_p6_1[] = {
  118382. 3, 1, 0, 2, 4,
  118383. };
  118384. static encode_aux_threshmatch _vq_auxt__44c6_s_p6_1 = {
  118385. _vq_quantthresh__44c6_s_p6_1,
  118386. _vq_quantmap__44c6_s_p6_1,
  118387. 5,
  118388. 5
  118389. };
  118390. static static_codebook _44c6_s_p6_1 = {
  118391. 2, 25,
  118392. _vq_lengthlist__44c6_s_p6_1,
  118393. 1, -533725184, 1611661312, 3, 0,
  118394. _vq_quantlist__44c6_s_p6_1,
  118395. NULL,
  118396. &_vq_auxt__44c6_s_p6_1,
  118397. NULL,
  118398. 0
  118399. };
  118400. static long _vq_quantlist__44c6_s_p7_0[] = {
  118401. 6,
  118402. 5,
  118403. 7,
  118404. 4,
  118405. 8,
  118406. 3,
  118407. 9,
  118408. 2,
  118409. 10,
  118410. 1,
  118411. 11,
  118412. 0,
  118413. 12,
  118414. };
  118415. static long _vq_lengthlist__44c6_s_p7_0[] = {
  118416. 1, 4, 4, 6, 6, 8, 8, 8, 8,10,10,11,10, 6, 5, 5,
  118417. 7, 7, 8, 8, 9, 9,10,10,12,11, 6, 5, 5, 7, 7, 8,
  118418. 8, 9, 9,10,10,12,11,21, 7, 7, 7, 7, 9, 9,10,10,
  118419. 11,11,12,12,21, 7, 7, 7, 7, 9, 9,10,10,11,11,12,
  118420. 12,21,12,12, 9, 9,10,10,11,11,11,11,12,12,21,12,
  118421. 12, 9, 9,10,10,11,11,12,12,12,12,21,21,21,11,11,
  118422. 10,10,11,12,12,12,13,13,21,21,21,11,11,10,10,12,
  118423. 12,12,12,13,13,21,21,21,15,15,11,11,12,12,13,13,
  118424. 13,13,21,21,21,15,16,11,11,12,12,13,13,14,14,21,
  118425. 21,21,21,20,13,13,13,13,13,13,14,14,20,20,20,20,
  118426. 20,13,13,13,13,13,13,14,14,
  118427. };
  118428. static float _vq_quantthresh__44c6_s_p7_0[] = {
  118429. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  118430. 27.5, 38.5, 49.5, 60.5,
  118431. };
  118432. static long _vq_quantmap__44c6_s_p7_0[] = {
  118433. 11, 9, 7, 5, 3, 1, 0, 2,
  118434. 4, 6, 8, 10, 12,
  118435. };
  118436. static encode_aux_threshmatch _vq_auxt__44c6_s_p7_0 = {
  118437. _vq_quantthresh__44c6_s_p7_0,
  118438. _vq_quantmap__44c6_s_p7_0,
  118439. 13,
  118440. 13
  118441. };
  118442. static static_codebook _44c6_s_p7_0 = {
  118443. 2, 169,
  118444. _vq_lengthlist__44c6_s_p7_0,
  118445. 1, -523206656, 1618345984, 4, 0,
  118446. _vq_quantlist__44c6_s_p7_0,
  118447. NULL,
  118448. &_vq_auxt__44c6_s_p7_0,
  118449. NULL,
  118450. 0
  118451. };
  118452. static long _vq_quantlist__44c6_s_p7_1[] = {
  118453. 5,
  118454. 4,
  118455. 6,
  118456. 3,
  118457. 7,
  118458. 2,
  118459. 8,
  118460. 1,
  118461. 9,
  118462. 0,
  118463. 10,
  118464. };
  118465. static long _vq_lengthlist__44c6_s_p7_1[] = {
  118466. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 9, 5, 5, 6, 6,
  118467. 7, 7, 7, 7, 8, 7, 8, 5, 5, 6, 6, 7, 7, 7, 7, 7,
  118468. 7, 9, 6, 6, 7, 7, 7, 7, 8, 7, 7, 8, 9, 9, 9, 7,
  118469. 7, 7, 7, 7, 7, 7, 8, 9, 9, 9, 7, 7, 7, 7, 8, 8,
  118470. 8, 8, 9, 9, 9, 7, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9,
  118471. 8, 8, 8, 8, 7, 7, 8, 8, 9, 9, 9, 9, 8, 8, 8, 7,
  118472. 7, 8, 8, 9, 9, 9, 8, 8, 8, 8, 7, 7, 8, 8, 9, 9,
  118473. 9, 8, 8, 7, 7, 7, 7, 8, 8,
  118474. };
  118475. static float _vq_quantthresh__44c6_s_p7_1[] = {
  118476. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  118477. 3.5, 4.5,
  118478. };
  118479. static long _vq_quantmap__44c6_s_p7_1[] = {
  118480. 9, 7, 5, 3, 1, 0, 2, 4,
  118481. 6, 8, 10,
  118482. };
  118483. static encode_aux_threshmatch _vq_auxt__44c6_s_p7_1 = {
  118484. _vq_quantthresh__44c6_s_p7_1,
  118485. _vq_quantmap__44c6_s_p7_1,
  118486. 11,
  118487. 11
  118488. };
  118489. static static_codebook _44c6_s_p7_1 = {
  118490. 2, 121,
  118491. _vq_lengthlist__44c6_s_p7_1,
  118492. 1, -531365888, 1611661312, 4, 0,
  118493. _vq_quantlist__44c6_s_p7_1,
  118494. NULL,
  118495. &_vq_auxt__44c6_s_p7_1,
  118496. NULL,
  118497. 0
  118498. };
  118499. static long _vq_quantlist__44c6_s_p8_0[] = {
  118500. 7,
  118501. 6,
  118502. 8,
  118503. 5,
  118504. 9,
  118505. 4,
  118506. 10,
  118507. 3,
  118508. 11,
  118509. 2,
  118510. 12,
  118511. 1,
  118512. 13,
  118513. 0,
  118514. 14,
  118515. };
  118516. static long _vq_lengthlist__44c6_s_p8_0[] = {
  118517. 1, 4, 4, 7, 7, 8, 8, 7, 7, 8, 7, 9, 8,10, 9, 6,
  118518. 5, 5, 8, 8, 9, 9, 8, 8, 9, 9,11,10,11,10, 6, 5,
  118519. 5, 8, 8, 9, 9, 8, 8, 9, 9,10,10,11,11,18, 8, 8,
  118520. 9, 8,10,10, 9, 9,10,10,10,10,11,10,18, 8, 8, 9,
  118521. 9,10,10, 9, 9,10,10,11,11,12,12,18,12,13, 9,10,
  118522. 10,10, 9,10,10,10,11,11,12,11,18,13,13, 9, 9,10,
  118523. 10,10,10,10,10,11,11,12,12,18,18,18,10,10, 9, 9,
  118524. 11,11,11,11,11,12,12,12,18,18,18,10, 9,10, 9,11,
  118525. 10,11,11,11,11,13,12,18,18,18,14,13,10,10,11,11,
  118526. 12,12,12,12,12,12,18,18,18,14,13,10,10,11,10,12,
  118527. 12,12,12,12,12,18,18,18,18,18,12,12,11,11,12,12,
  118528. 13,13,13,14,18,18,18,18,18,12,12,11,11,12,11,13,
  118529. 13,14,13,18,18,18,18,18,16,16,11,12,12,13,13,13,
  118530. 14,13,18,18,18,18,18,16,15,12,11,12,11,13,11,15,
  118531. 14,
  118532. };
  118533. static float _vq_quantthresh__44c6_s_p8_0[] = {
  118534. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  118535. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  118536. };
  118537. static long _vq_quantmap__44c6_s_p8_0[] = {
  118538. 13, 11, 9, 7, 5, 3, 1, 0,
  118539. 2, 4, 6, 8, 10, 12, 14,
  118540. };
  118541. static encode_aux_threshmatch _vq_auxt__44c6_s_p8_0 = {
  118542. _vq_quantthresh__44c6_s_p8_0,
  118543. _vq_quantmap__44c6_s_p8_0,
  118544. 15,
  118545. 15
  118546. };
  118547. static static_codebook _44c6_s_p8_0 = {
  118548. 2, 225,
  118549. _vq_lengthlist__44c6_s_p8_0,
  118550. 1, -520986624, 1620377600, 4, 0,
  118551. _vq_quantlist__44c6_s_p8_0,
  118552. NULL,
  118553. &_vq_auxt__44c6_s_p8_0,
  118554. NULL,
  118555. 0
  118556. };
  118557. static long _vq_quantlist__44c6_s_p8_1[] = {
  118558. 10,
  118559. 9,
  118560. 11,
  118561. 8,
  118562. 12,
  118563. 7,
  118564. 13,
  118565. 6,
  118566. 14,
  118567. 5,
  118568. 15,
  118569. 4,
  118570. 16,
  118571. 3,
  118572. 17,
  118573. 2,
  118574. 18,
  118575. 1,
  118576. 19,
  118577. 0,
  118578. 20,
  118579. };
  118580. static long _vq_lengthlist__44c6_s_p8_1[] = {
  118581. 3, 5, 5, 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 8, 8, 8,
  118582. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,
  118583. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  118584. 8, 8, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9,10,
  118585. 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  118586. 9, 9, 9, 9,10,11,11, 8, 7, 8, 8, 8, 9, 9, 9, 9,
  118587. 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,11, 8, 8, 8, 8,
  118588. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,
  118589. 11, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  118590. 9, 9, 9,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  118591. 9, 9, 9, 9, 9, 9, 9, 9,11,11,11,11,11, 9, 9, 9,
  118592. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,11,11,11,
  118593. 11,11, 9, 9, 9, 9, 9, 9,10, 9, 9,10, 9,10, 9, 9,
  118594. 10, 9,11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9,10,10,
  118595. 10,10, 9,10,10, 9,10,11,11,11,11,11, 9, 9, 9, 9,
  118596. 10,10,10, 9,10,10,10,10, 9,10,10, 9,11,11,11,11,
  118597. 11,11,11, 9, 9, 9, 9,10,10,10,10, 9,10,10,10,10,
  118598. 10,11,11,11,11,11,11,11,10, 9,10,10,10,10,10,10,
  118599. 10, 9,10, 9,10,10,11,11,11,11,11,11,11,10, 9,10,
  118600. 9,10,10, 9,10,10,10,10,10,10,10,11,11,11,11,11,
  118601. 11,11,10,10,10,10,10,10,10, 9,10,10,10,10,10, 9,
  118602. 11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
  118603. 10,10,10,10,10,11,11,11,11,11,11,11,11,11,10,10,
  118604. 10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
  118605. 11,11,11,10,10,10,10,10,10,10,10,10, 9,10,10,11,
  118606. 11,11,11,11,11,11,11,11,10,10,10, 9,10,10,10,10,
  118607. 10,10,10,10,10,11,11,11,11,11,11,11,11,10,11, 9,
  118608. 10,10,10,10,10,10,10,10,10,
  118609. };
  118610. static float _vq_quantthresh__44c6_s_p8_1[] = {
  118611. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  118612. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  118613. 6.5, 7.5, 8.5, 9.5,
  118614. };
  118615. static long _vq_quantmap__44c6_s_p8_1[] = {
  118616. 19, 17, 15, 13, 11, 9, 7, 5,
  118617. 3, 1, 0, 2, 4, 6, 8, 10,
  118618. 12, 14, 16, 18, 20,
  118619. };
  118620. static encode_aux_threshmatch _vq_auxt__44c6_s_p8_1 = {
  118621. _vq_quantthresh__44c6_s_p8_1,
  118622. _vq_quantmap__44c6_s_p8_1,
  118623. 21,
  118624. 21
  118625. };
  118626. static static_codebook _44c6_s_p8_1 = {
  118627. 2, 441,
  118628. _vq_lengthlist__44c6_s_p8_1,
  118629. 1, -529268736, 1611661312, 5, 0,
  118630. _vq_quantlist__44c6_s_p8_1,
  118631. NULL,
  118632. &_vq_auxt__44c6_s_p8_1,
  118633. NULL,
  118634. 0
  118635. };
  118636. static long _vq_quantlist__44c6_s_p9_0[] = {
  118637. 6,
  118638. 5,
  118639. 7,
  118640. 4,
  118641. 8,
  118642. 3,
  118643. 9,
  118644. 2,
  118645. 10,
  118646. 1,
  118647. 11,
  118648. 0,
  118649. 12,
  118650. };
  118651. static long _vq_lengthlist__44c6_s_p9_0[] = {
  118652. 1, 3, 3,11,11,11,11,11,11,11,11,11,11, 4, 7, 7,
  118653. 11,11,11,11,11,11,11,11,11,11, 5, 8, 9,11,11,11,
  118654. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  118655. 11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,10,
  118656. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118657. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118658. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118659. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118660. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118661. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118662. 10,10,10,10,10,10,10,10,10,
  118663. };
  118664. static float _vq_quantthresh__44c6_s_p9_0[] = {
  118665. -3503.5, -2866.5, -2229.5, -1592.5, -955.5, -318.5, 318.5, 955.5,
  118666. 1592.5, 2229.5, 2866.5, 3503.5,
  118667. };
  118668. static long _vq_quantmap__44c6_s_p9_0[] = {
  118669. 11, 9, 7, 5, 3, 1, 0, 2,
  118670. 4, 6, 8, 10, 12,
  118671. };
  118672. static encode_aux_threshmatch _vq_auxt__44c6_s_p9_0 = {
  118673. _vq_quantthresh__44c6_s_p9_0,
  118674. _vq_quantmap__44c6_s_p9_0,
  118675. 13,
  118676. 13
  118677. };
  118678. static static_codebook _44c6_s_p9_0 = {
  118679. 2, 169,
  118680. _vq_lengthlist__44c6_s_p9_0,
  118681. 1, -511845376, 1630791680, 4, 0,
  118682. _vq_quantlist__44c6_s_p9_0,
  118683. NULL,
  118684. &_vq_auxt__44c6_s_p9_0,
  118685. NULL,
  118686. 0
  118687. };
  118688. static long _vq_quantlist__44c6_s_p9_1[] = {
  118689. 6,
  118690. 5,
  118691. 7,
  118692. 4,
  118693. 8,
  118694. 3,
  118695. 9,
  118696. 2,
  118697. 10,
  118698. 1,
  118699. 11,
  118700. 0,
  118701. 12,
  118702. };
  118703. static long _vq_lengthlist__44c6_s_p9_1[] = {
  118704. 1, 4, 4, 7, 7, 7, 7, 7, 6, 8, 8, 8, 8, 6, 6, 6,
  118705. 8, 8, 8, 8, 8, 7, 9, 8,10,10, 5, 6, 6, 8, 8, 9,
  118706. 9, 8, 8,10,10,10,10,16, 9, 9, 9, 9, 9, 9, 9, 8,
  118707. 10, 9,11,11,16, 8, 9, 9, 9, 9, 9, 9, 9,10,10,11,
  118708. 11,16,13,13, 9, 9,10, 9, 9,10,11,11,11,12,16,13,
  118709. 14, 9, 8,10, 8, 9, 9,10,10,12,11,16,14,16, 9, 9,
  118710. 9, 9,11,11,12,11,12,11,16,16,16, 9, 7, 9, 6,11,
  118711. 11,11,10,11,11,16,16,16,11,12, 9,10,11,11,12,11,
  118712. 13,13,16,16,16,12,11,10, 7,12,10,12,12,12,12,16,
  118713. 16,15,16,16,10,11,10,11,13,13,14,12,16,16,16,15,
  118714. 15,12,10,11,11,13,11,12,13,
  118715. };
  118716. static float _vq_quantthresh__44c6_s_p9_1[] = {
  118717. -269.5, -220.5, -171.5, -122.5, -73.5, -24.5, 24.5, 73.5,
  118718. 122.5, 171.5, 220.5, 269.5,
  118719. };
  118720. static long _vq_quantmap__44c6_s_p9_1[] = {
  118721. 11, 9, 7, 5, 3, 1, 0, 2,
  118722. 4, 6, 8, 10, 12,
  118723. };
  118724. static encode_aux_threshmatch _vq_auxt__44c6_s_p9_1 = {
  118725. _vq_quantthresh__44c6_s_p9_1,
  118726. _vq_quantmap__44c6_s_p9_1,
  118727. 13,
  118728. 13
  118729. };
  118730. static static_codebook _44c6_s_p9_1 = {
  118731. 2, 169,
  118732. _vq_lengthlist__44c6_s_p9_1,
  118733. 1, -518889472, 1622704128, 4, 0,
  118734. _vq_quantlist__44c6_s_p9_1,
  118735. NULL,
  118736. &_vq_auxt__44c6_s_p9_1,
  118737. NULL,
  118738. 0
  118739. };
  118740. static long _vq_quantlist__44c6_s_p9_2[] = {
  118741. 24,
  118742. 23,
  118743. 25,
  118744. 22,
  118745. 26,
  118746. 21,
  118747. 27,
  118748. 20,
  118749. 28,
  118750. 19,
  118751. 29,
  118752. 18,
  118753. 30,
  118754. 17,
  118755. 31,
  118756. 16,
  118757. 32,
  118758. 15,
  118759. 33,
  118760. 14,
  118761. 34,
  118762. 13,
  118763. 35,
  118764. 12,
  118765. 36,
  118766. 11,
  118767. 37,
  118768. 10,
  118769. 38,
  118770. 9,
  118771. 39,
  118772. 8,
  118773. 40,
  118774. 7,
  118775. 41,
  118776. 6,
  118777. 42,
  118778. 5,
  118779. 43,
  118780. 4,
  118781. 44,
  118782. 3,
  118783. 45,
  118784. 2,
  118785. 46,
  118786. 1,
  118787. 47,
  118788. 0,
  118789. 48,
  118790. };
  118791. static long _vq_lengthlist__44c6_s_p9_2[] = {
  118792. 2, 4, 3, 4, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  118793. 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  118794. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  118795. 7,
  118796. };
  118797. static float _vq_quantthresh__44c6_s_p9_2[] = {
  118798. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  118799. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  118800. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  118801. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  118802. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  118803. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  118804. };
  118805. static long _vq_quantmap__44c6_s_p9_2[] = {
  118806. 47, 45, 43, 41, 39, 37, 35, 33,
  118807. 31, 29, 27, 25, 23, 21, 19, 17,
  118808. 15, 13, 11, 9, 7, 5, 3, 1,
  118809. 0, 2, 4, 6, 8, 10, 12, 14,
  118810. 16, 18, 20, 22, 24, 26, 28, 30,
  118811. 32, 34, 36, 38, 40, 42, 44, 46,
  118812. 48,
  118813. };
  118814. static encode_aux_threshmatch _vq_auxt__44c6_s_p9_2 = {
  118815. _vq_quantthresh__44c6_s_p9_2,
  118816. _vq_quantmap__44c6_s_p9_2,
  118817. 49,
  118818. 49
  118819. };
  118820. static static_codebook _44c6_s_p9_2 = {
  118821. 1, 49,
  118822. _vq_lengthlist__44c6_s_p9_2,
  118823. 1, -526909440, 1611661312, 6, 0,
  118824. _vq_quantlist__44c6_s_p9_2,
  118825. NULL,
  118826. &_vq_auxt__44c6_s_p9_2,
  118827. NULL,
  118828. 0
  118829. };
  118830. static long _huff_lengthlist__44c6_s_short[] = {
  118831. 3, 9,11,11,13,14,19,17,17,19, 5, 4, 5, 8,10,10,
  118832. 13,16,18,19, 7, 4, 4, 5, 8, 9,12,14,17,19, 8, 6,
  118833. 5, 5, 7, 7,10,13,16,18,10, 8, 7, 6, 5, 5, 8,11,
  118834. 17,19,11, 9, 7, 7, 5, 4, 5, 8,17,19,13,11, 8, 7,
  118835. 7, 5, 5, 7,16,18,14,13, 8, 6, 6, 5, 5, 7,16,18,
  118836. 18,16,10, 8, 8, 7, 7, 9,16,18,18,18,12,10,10, 9,
  118837. 9,10,17,18,
  118838. };
  118839. static static_codebook _huff_book__44c6_s_short = {
  118840. 2, 100,
  118841. _huff_lengthlist__44c6_s_short,
  118842. 0, 0, 0, 0, 0,
  118843. NULL,
  118844. NULL,
  118845. NULL,
  118846. NULL,
  118847. 0
  118848. };
  118849. static long _huff_lengthlist__44c7_s_long[] = {
  118850. 3, 8,11,13,15,14,14,13,15,14, 6, 4, 5, 7, 9,10,
  118851. 11,11,14,13,10, 4, 3, 5, 7, 8, 9,10,13,13,12, 7,
  118852. 4, 4, 5, 6, 8, 9,12,14,13, 9, 6, 5, 5, 6, 8, 9,
  118853. 12,14,12, 9, 7, 6, 5, 5, 6, 8,11,11,12,11, 9, 8,
  118854. 7, 6, 6, 7,10,11,13,11,10, 9, 8, 7, 6, 6, 9,11,
  118855. 13,13,12,12,12,10, 9, 8, 9,11,12,14,15,15,14,12,
  118856. 11,10,10,12,
  118857. };
  118858. static static_codebook _huff_book__44c7_s_long = {
  118859. 2, 100,
  118860. _huff_lengthlist__44c7_s_long,
  118861. 0, 0, 0, 0, 0,
  118862. NULL,
  118863. NULL,
  118864. NULL,
  118865. NULL,
  118866. 0
  118867. };
  118868. static long _vq_quantlist__44c7_s_p1_0[] = {
  118869. 1,
  118870. 0,
  118871. 2,
  118872. };
  118873. static long _vq_lengthlist__44c7_s_p1_0[] = {
  118874. 1, 5, 5, 0, 5, 5, 0, 5, 5, 5, 8, 7, 0, 9, 9, 0,
  118875. 9, 8, 5, 7, 8, 0, 9, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  118876. 0, 0, 0, 0, 5, 9, 9, 0, 8, 8, 0, 8, 8, 5, 8, 9,
  118877. 0, 8, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  118878. 9, 9, 0, 8, 8, 0, 8, 8, 5, 8, 9, 0, 8, 8, 0, 8,
  118879. 8,
  118880. };
  118881. static float _vq_quantthresh__44c7_s_p1_0[] = {
  118882. -0.5, 0.5,
  118883. };
  118884. static long _vq_quantmap__44c7_s_p1_0[] = {
  118885. 1, 0, 2,
  118886. };
  118887. static encode_aux_threshmatch _vq_auxt__44c7_s_p1_0 = {
  118888. _vq_quantthresh__44c7_s_p1_0,
  118889. _vq_quantmap__44c7_s_p1_0,
  118890. 3,
  118891. 3
  118892. };
  118893. static static_codebook _44c7_s_p1_0 = {
  118894. 4, 81,
  118895. _vq_lengthlist__44c7_s_p1_0,
  118896. 1, -535822336, 1611661312, 2, 0,
  118897. _vq_quantlist__44c7_s_p1_0,
  118898. NULL,
  118899. &_vq_auxt__44c7_s_p1_0,
  118900. NULL,
  118901. 0
  118902. };
  118903. static long _vq_quantlist__44c7_s_p2_0[] = {
  118904. 2,
  118905. 1,
  118906. 3,
  118907. 0,
  118908. 4,
  118909. };
  118910. static long _vq_lengthlist__44c7_s_p2_0[] = {
  118911. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  118912. 7, 7, 9, 9, 0, 0, 0, 9, 9, 5, 7, 7, 9, 9, 0, 8,
  118913. 8,10,10, 0, 8, 7,10, 9, 0,10,10,11,11, 0, 0, 0,
  118914. 11,11, 5, 7, 7, 9, 9, 0, 8, 8,10,10, 0, 7, 8, 9,
  118915. 10, 0,10,10,11,11, 0, 0, 0,11,11, 8, 9, 9,11,10,
  118916. 0,11,11,12,12, 0,11,10,12,12, 0,13,14,14,14, 0,
  118917. 0, 0,14,13, 8, 9, 9,10,11, 0,11,11,12,12, 0,10,
  118918. 11,12,12, 0,13,13,14,14, 0, 0, 0,13,14, 0, 0, 0,
  118919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118920. 0, 0, 0, 0, 0, 0, 5, 8, 7,11,10, 0, 7, 7,10,10,
  118921. 0, 7, 7,10,10, 0, 9, 9,11,10, 0, 0, 0,11,11, 5,
  118922. 7, 8,10,11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9,
  118923. 9,10,11, 0, 0, 0,11,11, 8,10, 9,12,12, 0,10,10,
  118924. 12,12, 0,10,10,12,12, 0,12,12,13,13, 0, 0, 0,13,
  118925. 13, 8, 9,10,12,12, 0,10,10,12,12, 0,10,10,11,12,
  118926. 0,12,12,13,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0,
  118927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118928. 0, 0, 0, 5, 8, 8,11,11, 0, 7, 7,10,10, 0, 7, 7,
  118929. 10,10, 0, 9, 9,10,11, 0, 0, 0,11,10, 5, 8, 8,10,
  118930. 11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9, 9,11,10,
  118931. 0, 0, 0,10,11, 9,10,10,12,12, 0,10,10,12,12, 0,
  118932. 10,10,12,12, 0,12,13,13,13, 0, 0, 0,13,12, 9,10,
  118933. 10,12,12, 0,10,10,12,12, 0,10,10,12,12, 0,13,12,
  118934. 13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118936. 7,10,10,14,13, 0, 9, 9,12,12, 0, 9, 9,12,12, 0,
  118937. 10,10,12,12, 0, 0, 0,12,12, 7,10,10,13,14, 0, 9,
  118938. 9,12,13, 0, 9, 9,12,12, 0,10,10,12,12, 0, 0, 0,
  118939. 12,12, 9,11,11,14,13, 0,11,10,13,12, 0,11,11,13,
  118940. 13, 0,12,12,13,13, 0, 0, 0,13,13, 9,11,11,13,14,
  118941. 0,10,11,12,13, 0,11,11,13,13, 0,12,12,13,13, 0,
  118942. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  118947. 11,11,14,14, 0,10,11,13,13, 0,11,10,13,13, 0,12,
  118948. 12,13,13, 0, 0, 0,13,12, 9,11,11,14,14, 0,11,10,
  118949. 13,13, 0,10,11,13,13, 0,12,12,14,13, 0, 0, 0,13,
  118950. 13,
  118951. };
  118952. static float _vq_quantthresh__44c7_s_p2_0[] = {
  118953. -1.5, -0.5, 0.5, 1.5,
  118954. };
  118955. static long _vq_quantmap__44c7_s_p2_0[] = {
  118956. 3, 1, 0, 2, 4,
  118957. };
  118958. static encode_aux_threshmatch _vq_auxt__44c7_s_p2_0 = {
  118959. _vq_quantthresh__44c7_s_p2_0,
  118960. _vq_quantmap__44c7_s_p2_0,
  118961. 5,
  118962. 5
  118963. };
  118964. static static_codebook _44c7_s_p2_0 = {
  118965. 4, 625,
  118966. _vq_lengthlist__44c7_s_p2_0,
  118967. 1, -533725184, 1611661312, 3, 0,
  118968. _vq_quantlist__44c7_s_p2_0,
  118969. NULL,
  118970. &_vq_auxt__44c7_s_p2_0,
  118971. NULL,
  118972. 0
  118973. };
  118974. static long _vq_quantlist__44c7_s_p3_0[] = {
  118975. 4,
  118976. 3,
  118977. 5,
  118978. 2,
  118979. 6,
  118980. 1,
  118981. 7,
  118982. 0,
  118983. 8,
  118984. };
  118985. static long _vq_lengthlist__44c7_s_p3_0[] = {
  118986. 2, 4, 4, 5, 5, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  118987. 9, 9, 0, 4, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 6, 6,
  118988. 8, 8,10,10, 0, 0, 0, 6, 6, 8, 8,10,10, 0, 0, 0,
  118989. 7, 7, 9, 9,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0,
  118990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118991. 0,
  118992. };
  118993. static float _vq_quantthresh__44c7_s_p3_0[] = {
  118994. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  118995. };
  118996. static long _vq_quantmap__44c7_s_p3_0[] = {
  118997. 7, 5, 3, 1, 0, 2, 4, 6,
  118998. 8,
  118999. };
  119000. static encode_aux_threshmatch _vq_auxt__44c7_s_p3_0 = {
  119001. _vq_quantthresh__44c7_s_p3_0,
  119002. _vq_quantmap__44c7_s_p3_0,
  119003. 9,
  119004. 9
  119005. };
  119006. static static_codebook _44c7_s_p3_0 = {
  119007. 2, 81,
  119008. _vq_lengthlist__44c7_s_p3_0,
  119009. 1, -531628032, 1611661312, 4, 0,
  119010. _vq_quantlist__44c7_s_p3_0,
  119011. NULL,
  119012. &_vq_auxt__44c7_s_p3_0,
  119013. NULL,
  119014. 0
  119015. };
  119016. static long _vq_quantlist__44c7_s_p4_0[] = {
  119017. 8,
  119018. 7,
  119019. 9,
  119020. 6,
  119021. 10,
  119022. 5,
  119023. 11,
  119024. 4,
  119025. 12,
  119026. 3,
  119027. 13,
  119028. 2,
  119029. 14,
  119030. 1,
  119031. 15,
  119032. 0,
  119033. 16,
  119034. };
  119035. static long _vq_lengthlist__44c7_s_p4_0[] = {
  119036. 3, 4, 4, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  119037. 11, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,
  119038. 12,12, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  119039. 11,12,12, 0, 5, 5, 6, 6, 8, 8, 9, 9, 9, 9,10,10,
  119040. 11,12,12,12, 0, 0, 0, 6, 6, 8, 7, 9, 9, 9, 9,10,
  119041. 10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,10,
  119042. 11,11,12,12,13,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,
  119043. 10,11,11,12,12,12,13, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  119044. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 8, 8, 9,
  119045. 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 0, 0,
  119046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119054. 0,
  119055. };
  119056. static float _vq_quantthresh__44c7_s_p4_0[] = {
  119057. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  119058. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  119059. };
  119060. static long _vq_quantmap__44c7_s_p4_0[] = {
  119061. 15, 13, 11, 9, 7, 5, 3, 1,
  119062. 0, 2, 4, 6, 8, 10, 12, 14,
  119063. 16,
  119064. };
  119065. static encode_aux_threshmatch _vq_auxt__44c7_s_p4_0 = {
  119066. _vq_quantthresh__44c7_s_p4_0,
  119067. _vq_quantmap__44c7_s_p4_0,
  119068. 17,
  119069. 17
  119070. };
  119071. static static_codebook _44c7_s_p4_0 = {
  119072. 2, 289,
  119073. _vq_lengthlist__44c7_s_p4_0,
  119074. 1, -529530880, 1611661312, 5, 0,
  119075. _vq_quantlist__44c7_s_p4_0,
  119076. NULL,
  119077. &_vq_auxt__44c7_s_p4_0,
  119078. NULL,
  119079. 0
  119080. };
  119081. static long _vq_quantlist__44c7_s_p5_0[] = {
  119082. 1,
  119083. 0,
  119084. 2,
  119085. };
  119086. static long _vq_lengthlist__44c7_s_p5_0[] = {
  119087. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 6, 7,10,10,10,10,
  119088. 10, 9, 4, 6, 6,10,10,10,10, 9,10, 5,10,10, 9,11,
  119089. 12,10,11,12, 7,10,10,11,12,12,12,12,12, 7,10,10,
  119090. 11,12,12,12,12,12, 6,10,10,10,12,12,11,12,12, 7,
  119091. 10,10,12,12,12,12,11,12, 7,10,10,11,12,12,12,12,
  119092. 12,
  119093. };
  119094. static float _vq_quantthresh__44c7_s_p5_0[] = {
  119095. -5.5, 5.5,
  119096. };
  119097. static long _vq_quantmap__44c7_s_p5_0[] = {
  119098. 1, 0, 2,
  119099. };
  119100. static encode_aux_threshmatch _vq_auxt__44c7_s_p5_0 = {
  119101. _vq_quantthresh__44c7_s_p5_0,
  119102. _vq_quantmap__44c7_s_p5_0,
  119103. 3,
  119104. 3
  119105. };
  119106. static static_codebook _44c7_s_p5_0 = {
  119107. 4, 81,
  119108. _vq_lengthlist__44c7_s_p5_0,
  119109. 1, -529137664, 1618345984, 2, 0,
  119110. _vq_quantlist__44c7_s_p5_0,
  119111. NULL,
  119112. &_vq_auxt__44c7_s_p5_0,
  119113. NULL,
  119114. 0
  119115. };
  119116. static long _vq_quantlist__44c7_s_p5_1[] = {
  119117. 5,
  119118. 4,
  119119. 6,
  119120. 3,
  119121. 7,
  119122. 2,
  119123. 8,
  119124. 1,
  119125. 9,
  119126. 0,
  119127. 10,
  119128. };
  119129. static long _vq_lengthlist__44c7_s_p5_1[] = {
  119130. 3, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8,11, 4, 4, 6, 6,
  119131. 7, 7, 8, 8, 9, 9,11, 4, 4, 6, 6, 7, 7, 8, 8, 9,
  119132. 9,12, 5, 5, 6, 6, 7, 7, 9, 9, 9, 9,12,12,12, 6,
  119133. 6, 7, 7, 9, 9, 9, 9,11,11,11, 7, 7, 7, 7, 8, 8,
  119134. 9, 9,11,11,11, 7, 7, 7, 7, 8, 8, 9, 9,11,11,11,
  119135. 7, 7, 8, 8, 8, 8, 9, 9,11,11,11,11,11, 8, 8, 8,
  119136. 8, 8, 9,11,11,11,11,11, 8, 8, 8, 8, 8, 8,11,11,
  119137. 11,11,11, 7, 7, 8, 8, 8, 8,
  119138. };
  119139. static float _vq_quantthresh__44c7_s_p5_1[] = {
  119140. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  119141. 3.5, 4.5,
  119142. };
  119143. static long _vq_quantmap__44c7_s_p5_1[] = {
  119144. 9, 7, 5, 3, 1, 0, 2, 4,
  119145. 6, 8, 10,
  119146. };
  119147. static encode_aux_threshmatch _vq_auxt__44c7_s_p5_1 = {
  119148. _vq_quantthresh__44c7_s_p5_1,
  119149. _vq_quantmap__44c7_s_p5_1,
  119150. 11,
  119151. 11
  119152. };
  119153. static static_codebook _44c7_s_p5_1 = {
  119154. 2, 121,
  119155. _vq_lengthlist__44c7_s_p5_1,
  119156. 1, -531365888, 1611661312, 4, 0,
  119157. _vq_quantlist__44c7_s_p5_1,
  119158. NULL,
  119159. &_vq_auxt__44c7_s_p5_1,
  119160. NULL,
  119161. 0
  119162. };
  119163. static long _vq_quantlist__44c7_s_p6_0[] = {
  119164. 6,
  119165. 5,
  119166. 7,
  119167. 4,
  119168. 8,
  119169. 3,
  119170. 9,
  119171. 2,
  119172. 10,
  119173. 1,
  119174. 11,
  119175. 0,
  119176. 12,
  119177. };
  119178. static long _vq_lengthlist__44c7_s_p6_0[] = {
  119179. 1, 4, 4, 6, 6, 7, 7, 8, 7, 9, 8,10,10, 6, 5, 5,
  119180. 7, 7, 8, 8, 9, 9, 9,10,11,11, 7, 5, 5, 7, 7, 8,
  119181. 8, 9, 9,10,10,11,11, 0, 7, 7, 7, 7, 9, 8, 9, 9,
  119182. 10,10,11,11, 0, 8, 8, 7, 7, 8, 9, 9, 9,10,10,11,
  119183. 11, 0,11,11, 9, 9,10,10,11,10,11,11,12,12, 0,12,
  119184. 12, 9, 9,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0,
  119185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119189. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119190. };
  119191. static float _vq_quantthresh__44c7_s_p6_0[] = {
  119192. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  119193. 12.5, 17.5, 22.5, 27.5,
  119194. };
  119195. static long _vq_quantmap__44c7_s_p6_0[] = {
  119196. 11, 9, 7, 5, 3, 1, 0, 2,
  119197. 4, 6, 8, 10, 12,
  119198. };
  119199. static encode_aux_threshmatch _vq_auxt__44c7_s_p6_0 = {
  119200. _vq_quantthresh__44c7_s_p6_0,
  119201. _vq_quantmap__44c7_s_p6_0,
  119202. 13,
  119203. 13
  119204. };
  119205. static static_codebook _44c7_s_p6_0 = {
  119206. 2, 169,
  119207. _vq_lengthlist__44c7_s_p6_0,
  119208. 1, -526516224, 1616117760, 4, 0,
  119209. _vq_quantlist__44c7_s_p6_0,
  119210. NULL,
  119211. &_vq_auxt__44c7_s_p6_0,
  119212. NULL,
  119213. 0
  119214. };
  119215. static long _vq_quantlist__44c7_s_p6_1[] = {
  119216. 2,
  119217. 1,
  119218. 3,
  119219. 0,
  119220. 4,
  119221. };
  119222. static long _vq_lengthlist__44c7_s_p6_1[] = {
  119223. 3, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 6,
  119224. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  119225. };
  119226. static float _vq_quantthresh__44c7_s_p6_1[] = {
  119227. -1.5, -0.5, 0.5, 1.5,
  119228. };
  119229. static long _vq_quantmap__44c7_s_p6_1[] = {
  119230. 3, 1, 0, 2, 4,
  119231. };
  119232. static encode_aux_threshmatch _vq_auxt__44c7_s_p6_1 = {
  119233. _vq_quantthresh__44c7_s_p6_1,
  119234. _vq_quantmap__44c7_s_p6_1,
  119235. 5,
  119236. 5
  119237. };
  119238. static static_codebook _44c7_s_p6_1 = {
  119239. 2, 25,
  119240. _vq_lengthlist__44c7_s_p6_1,
  119241. 1, -533725184, 1611661312, 3, 0,
  119242. _vq_quantlist__44c7_s_p6_1,
  119243. NULL,
  119244. &_vq_auxt__44c7_s_p6_1,
  119245. NULL,
  119246. 0
  119247. };
  119248. static long _vq_quantlist__44c7_s_p7_0[] = {
  119249. 6,
  119250. 5,
  119251. 7,
  119252. 4,
  119253. 8,
  119254. 3,
  119255. 9,
  119256. 2,
  119257. 10,
  119258. 1,
  119259. 11,
  119260. 0,
  119261. 12,
  119262. };
  119263. static long _vq_lengthlist__44c7_s_p7_0[] = {
  119264. 1, 4, 4, 6, 6, 7, 8, 9, 9,10,10,12,11, 6, 5, 5,
  119265. 7, 7, 8, 8, 9,10,11,11,12,12, 7, 5, 5, 7, 7, 8,
  119266. 8,10,10,11,11,12,12,20, 7, 7, 7, 7, 8, 9,10,10,
  119267. 11,11,12,13,20, 7, 7, 7, 7, 9, 9,10,10,11,12,13,
  119268. 13,20,11,11, 8, 8, 9, 9,11,11,12,12,13,13,20,11,
  119269. 11, 8, 8, 9, 9,11,11,12,12,13,13,20,20,20,10,10,
  119270. 10,10,12,12,13,13,13,13,20,20,20,10,10,10,10,12,
  119271. 12,13,13,13,14,20,20,20,14,14,11,11,12,12,13,13,
  119272. 14,14,20,20,20,14,14,11,11,12,12,13,13,14,14,20,
  119273. 20,20,20,19,13,13,13,13,14,14,15,14,19,19,19,19,
  119274. 19,13,13,13,13,14,14,15,15,
  119275. };
  119276. static float _vq_quantthresh__44c7_s_p7_0[] = {
  119277. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  119278. 27.5, 38.5, 49.5, 60.5,
  119279. };
  119280. static long _vq_quantmap__44c7_s_p7_0[] = {
  119281. 11, 9, 7, 5, 3, 1, 0, 2,
  119282. 4, 6, 8, 10, 12,
  119283. };
  119284. static encode_aux_threshmatch _vq_auxt__44c7_s_p7_0 = {
  119285. _vq_quantthresh__44c7_s_p7_0,
  119286. _vq_quantmap__44c7_s_p7_0,
  119287. 13,
  119288. 13
  119289. };
  119290. static static_codebook _44c7_s_p7_0 = {
  119291. 2, 169,
  119292. _vq_lengthlist__44c7_s_p7_0,
  119293. 1, -523206656, 1618345984, 4, 0,
  119294. _vq_quantlist__44c7_s_p7_0,
  119295. NULL,
  119296. &_vq_auxt__44c7_s_p7_0,
  119297. NULL,
  119298. 0
  119299. };
  119300. static long _vq_quantlist__44c7_s_p7_1[] = {
  119301. 5,
  119302. 4,
  119303. 6,
  119304. 3,
  119305. 7,
  119306. 2,
  119307. 8,
  119308. 1,
  119309. 9,
  119310. 0,
  119311. 10,
  119312. };
  119313. static long _vq_lengthlist__44c7_s_p7_1[] = {
  119314. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 8, 6, 6, 7, 7,
  119315. 7, 7, 7, 7, 7, 7, 8, 6, 6, 6, 7, 7, 7, 7, 7, 7,
  119316. 7, 8, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7,
  119317. 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7,
  119318. 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  119319. 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  119320. 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 8, 8,
  119321. 8, 8, 8, 7, 7, 7, 7, 7, 7,
  119322. };
  119323. static float _vq_quantthresh__44c7_s_p7_1[] = {
  119324. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  119325. 3.5, 4.5,
  119326. };
  119327. static long _vq_quantmap__44c7_s_p7_1[] = {
  119328. 9, 7, 5, 3, 1, 0, 2, 4,
  119329. 6, 8, 10,
  119330. };
  119331. static encode_aux_threshmatch _vq_auxt__44c7_s_p7_1 = {
  119332. _vq_quantthresh__44c7_s_p7_1,
  119333. _vq_quantmap__44c7_s_p7_1,
  119334. 11,
  119335. 11
  119336. };
  119337. static static_codebook _44c7_s_p7_1 = {
  119338. 2, 121,
  119339. _vq_lengthlist__44c7_s_p7_1,
  119340. 1, -531365888, 1611661312, 4, 0,
  119341. _vq_quantlist__44c7_s_p7_1,
  119342. NULL,
  119343. &_vq_auxt__44c7_s_p7_1,
  119344. NULL,
  119345. 0
  119346. };
  119347. static long _vq_quantlist__44c7_s_p8_0[] = {
  119348. 7,
  119349. 6,
  119350. 8,
  119351. 5,
  119352. 9,
  119353. 4,
  119354. 10,
  119355. 3,
  119356. 11,
  119357. 2,
  119358. 12,
  119359. 1,
  119360. 13,
  119361. 0,
  119362. 14,
  119363. };
  119364. static long _vq_lengthlist__44c7_s_p8_0[] = {
  119365. 1, 4, 4, 7, 7, 8, 8, 8, 7, 9, 8, 9, 9,10,10, 6,
  119366. 5, 5, 7, 7, 9, 9, 8, 8,10, 9,11,10,12,11, 6, 5,
  119367. 5, 8, 7, 9, 9, 8, 8,10,10,11,11,12,11,19, 8, 8,
  119368. 8, 8,10,10, 9, 9,10,10,11,11,12,11,19, 8, 8, 8,
  119369. 8,10,10, 9, 9,10,10,11,11,12,12,19,12,12, 9, 9,
  119370. 10,10, 9,10,10,10,11,11,12,12,19,12,12, 9, 9,10,
  119371. 10,10,10,10,10,12,12,12,12,19,19,19, 9, 9, 9, 9,
  119372. 11,10,11,11,12,11,13,13,19,19,19, 9, 9, 9, 9,11,
  119373. 10,11,11,11,12,13,13,19,19,19,13,13,10,10,11,11,
  119374. 12,12,12,12,13,12,19,19,19,14,13,10,10,11,11,12,
  119375. 12,12,13,13,13,19,19,19,19,19,12,12,12,11,12,13,
  119376. 14,13,13,13,19,19,19,19,19,12,12,12,11,12,12,13,
  119377. 14,13,14,19,19,19,19,19,16,16,12,13,12,13,13,14,
  119378. 15,14,19,18,18,18,18,16,15,12,11,12,11,14,12,14,
  119379. 14,
  119380. };
  119381. static float _vq_quantthresh__44c7_s_p8_0[] = {
  119382. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  119383. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  119384. };
  119385. static long _vq_quantmap__44c7_s_p8_0[] = {
  119386. 13, 11, 9, 7, 5, 3, 1, 0,
  119387. 2, 4, 6, 8, 10, 12, 14,
  119388. };
  119389. static encode_aux_threshmatch _vq_auxt__44c7_s_p8_0 = {
  119390. _vq_quantthresh__44c7_s_p8_0,
  119391. _vq_quantmap__44c7_s_p8_0,
  119392. 15,
  119393. 15
  119394. };
  119395. static static_codebook _44c7_s_p8_0 = {
  119396. 2, 225,
  119397. _vq_lengthlist__44c7_s_p8_0,
  119398. 1, -520986624, 1620377600, 4, 0,
  119399. _vq_quantlist__44c7_s_p8_0,
  119400. NULL,
  119401. &_vq_auxt__44c7_s_p8_0,
  119402. NULL,
  119403. 0
  119404. };
  119405. static long _vq_quantlist__44c7_s_p8_1[] = {
  119406. 10,
  119407. 9,
  119408. 11,
  119409. 8,
  119410. 12,
  119411. 7,
  119412. 13,
  119413. 6,
  119414. 14,
  119415. 5,
  119416. 15,
  119417. 4,
  119418. 16,
  119419. 3,
  119420. 17,
  119421. 2,
  119422. 18,
  119423. 1,
  119424. 19,
  119425. 0,
  119426. 20,
  119427. };
  119428. static long _vq_lengthlist__44c7_s_p8_1[] = {
  119429. 3, 5, 5, 7, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  119430. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  119431. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  119432. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,
  119433. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119434. 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  119435. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 9,
  119436. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  119437. 10, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119438. 9, 9, 9,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119439. 9, 9, 9, 9, 9, 9, 9, 9,10,11,10,10,10, 9, 9, 9,
  119440. 9, 9, 9, 9, 9, 9, 9,10, 9, 9,10, 9, 9,10,11,10,
  119441. 11,10, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9,10, 9, 9,
  119442. 9, 9,11,10,11,10,10, 9, 9, 9, 9, 9, 9,10, 9, 9,
  119443. 10, 9, 9,10, 9, 9,10,11,10,10,11,10, 9, 9, 9, 9,
  119444. 9,10,10, 9,10,10,10,10, 9,10,10,10,10,10,10,11,
  119445. 11,11,10, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,
  119446. 10,10,10,11,11,10,10,10,10,10,10,10,10,10,10,10,
  119447. 10, 9,10,10, 9,10,11,11,10,11,10,11,10, 9,10,10,
  119448. 9,10,10,10,10,10,10,10,10,10,10,11,11,11,11,10,
  119449. 11,11,10,10,10,10,10,10, 9,10, 9,10,10, 9,10, 9,
  119450. 10,10,10,11,10,11,10,11,11,10,10,10,10,10,10, 9,
  119451. 10,10,10,10,10,10,10,11,10,10,10,10,10,10,10,10,
  119452. 10,10,10,10,10,10,10,10,10,10,10,10,10,11,10,11,
  119453. 11,10,10,10,10, 9, 9,10,10, 9, 9,10, 9,10,10,10,
  119454. 10,11,11,10,10,10,10,10,10,10, 9, 9,10,10,10, 9,
  119455. 9,10,10,10,10,10,11,10,11,10,10,10,10,10,10, 9,
  119456. 10,10,10,10,10,10,10,10,10,
  119457. };
  119458. static float _vq_quantthresh__44c7_s_p8_1[] = {
  119459. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  119460. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  119461. 6.5, 7.5, 8.5, 9.5,
  119462. };
  119463. static long _vq_quantmap__44c7_s_p8_1[] = {
  119464. 19, 17, 15, 13, 11, 9, 7, 5,
  119465. 3, 1, 0, 2, 4, 6, 8, 10,
  119466. 12, 14, 16, 18, 20,
  119467. };
  119468. static encode_aux_threshmatch _vq_auxt__44c7_s_p8_1 = {
  119469. _vq_quantthresh__44c7_s_p8_1,
  119470. _vq_quantmap__44c7_s_p8_1,
  119471. 21,
  119472. 21
  119473. };
  119474. static static_codebook _44c7_s_p8_1 = {
  119475. 2, 441,
  119476. _vq_lengthlist__44c7_s_p8_1,
  119477. 1, -529268736, 1611661312, 5, 0,
  119478. _vq_quantlist__44c7_s_p8_1,
  119479. NULL,
  119480. &_vq_auxt__44c7_s_p8_1,
  119481. NULL,
  119482. 0
  119483. };
  119484. static long _vq_quantlist__44c7_s_p9_0[] = {
  119485. 6,
  119486. 5,
  119487. 7,
  119488. 4,
  119489. 8,
  119490. 3,
  119491. 9,
  119492. 2,
  119493. 10,
  119494. 1,
  119495. 11,
  119496. 0,
  119497. 12,
  119498. };
  119499. static long _vq_lengthlist__44c7_s_p9_0[] = {
  119500. 1, 3, 3,11,11,11,11,11,11,11,11,11,11, 4, 6, 6,
  119501. 11,11,11,11,11,11,11,11,11,11, 4, 7, 7,11,11,11,
  119502. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119503. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119504. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119505. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119506. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119507. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119508. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119509. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119510. 11,11,11,11,11,11,11,11,11,
  119511. };
  119512. static float _vq_quantthresh__44c7_s_p9_0[] = {
  119513. -3503.5, -2866.5, -2229.5, -1592.5, -955.5, -318.5, 318.5, 955.5,
  119514. 1592.5, 2229.5, 2866.5, 3503.5,
  119515. };
  119516. static long _vq_quantmap__44c7_s_p9_0[] = {
  119517. 11, 9, 7, 5, 3, 1, 0, 2,
  119518. 4, 6, 8, 10, 12,
  119519. };
  119520. static encode_aux_threshmatch _vq_auxt__44c7_s_p9_0 = {
  119521. _vq_quantthresh__44c7_s_p9_0,
  119522. _vq_quantmap__44c7_s_p9_0,
  119523. 13,
  119524. 13
  119525. };
  119526. static static_codebook _44c7_s_p9_0 = {
  119527. 2, 169,
  119528. _vq_lengthlist__44c7_s_p9_0,
  119529. 1, -511845376, 1630791680, 4, 0,
  119530. _vq_quantlist__44c7_s_p9_0,
  119531. NULL,
  119532. &_vq_auxt__44c7_s_p9_0,
  119533. NULL,
  119534. 0
  119535. };
  119536. static long _vq_quantlist__44c7_s_p9_1[] = {
  119537. 6,
  119538. 5,
  119539. 7,
  119540. 4,
  119541. 8,
  119542. 3,
  119543. 9,
  119544. 2,
  119545. 10,
  119546. 1,
  119547. 11,
  119548. 0,
  119549. 12,
  119550. };
  119551. static long _vq_lengthlist__44c7_s_p9_1[] = {
  119552. 1, 4, 4, 7, 7, 7, 7, 7, 6, 8, 8, 8, 8, 6, 6, 6,
  119553. 8, 8, 9, 8, 8, 7, 9, 8,11,10, 5, 6, 6, 8, 8, 9,
  119554. 8, 8, 8,10, 9,11,11,16, 8, 8, 9, 8, 9, 9, 9, 8,
  119555. 10, 9,11,10,16, 8, 8, 9, 9,10,10, 9, 9,10,10,11,
  119556. 11,16,13,13, 9, 9,10,10, 9,10,11,11,12,11,16,13,
  119557. 13, 9, 8,10, 9,10,10,10,10,11,11,16,14,16, 8, 9,
  119558. 9, 9,11,10,11,11,12,11,16,16,16, 9, 7,10, 7,11,
  119559. 10,11,11,12,11,16,16,16,12,12, 9,10,11,11,12,11,
  119560. 12,12,16,16,16,12,10,10, 7,11, 8,12,11,12,12,16,
  119561. 16,15,16,16,11,12,10,10,12,11,12,12,16,16,16,15,
  119562. 15,11,11,10,10,12,12,12,12,
  119563. };
  119564. static float _vq_quantthresh__44c7_s_p9_1[] = {
  119565. -269.5, -220.5, -171.5, -122.5, -73.5, -24.5, 24.5, 73.5,
  119566. 122.5, 171.5, 220.5, 269.5,
  119567. };
  119568. static long _vq_quantmap__44c7_s_p9_1[] = {
  119569. 11, 9, 7, 5, 3, 1, 0, 2,
  119570. 4, 6, 8, 10, 12,
  119571. };
  119572. static encode_aux_threshmatch _vq_auxt__44c7_s_p9_1 = {
  119573. _vq_quantthresh__44c7_s_p9_1,
  119574. _vq_quantmap__44c7_s_p9_1,
  119575. 13,
  119576. 13
  119577. };
  119578. static static_codebook _44c7_s_p9_1 = {
  119579. 2, 169,
  119580. _vq_lengthlist__44c7_s_p9_1,
  119581. 1, -518889472, 1622704128, 4, 0,
  119582. _vq_quantlist__44c7_s_p9_1,
  119583. NULL,
  119584. &_vq_auxt__44c7_s_p9_1,
  119585. NULL,
  119586. 0
  119587. };
  119588. static long _vq_quantlist__44c7_s_p9_2[] = {
  119589. 24,
  119590. 23,
  119591. 25,
  119592. 22,
  119593. 26,
  119594. 21,
  119595. 27,
  119596. 20,
  119597. 28,
  119598. 19,
  119599. 29,
  119600. 18,
  119601. 30,
  119602. 17,
  119603. 31,
  119604. 16,
  119605. 32,
  119606. 15,
  119607. 33,
  119608. 14,
  119609. 34,
  119610. 13,
  119611. 35,
  119612. 12,
  119613. 36,
  119614. 11,
  119615. 37,
  119616. 10,
  119617. 38,
  119618. 9,
  119619. 39,
  119620. 8,
  119621. 40,
  119622. 7,
  119623. 41,
  119624. 6,
  119625. 42,
  119626. 5,
  119627. 43,
  119628. 4,
  119629. 44,
  119630. 3,
  119631. 45,
  119632. 2,
  119633. 46,
  119634. 1,
  119635. 47,
  119636. 0,
  119637. 48,
  119638. };
  119639. static long _vq_lengthlist__44c7_s_p9_2[] = {
  119640. 2, 4, 3, 4, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  119641. 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  119642. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  119643. 7,
  119644. };
  119645. static float _vq_quantthresh__44c7_s_p9_2[] = {
  119646. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  119647. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  119648. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  119649. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  119650. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  119651. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  119652. };
  119653. static long _vq_quantmap__44c7_s_p9_2[] = {
  119654. 47, 45, 43, 41, 39, 37, 35, 33,
  119655. 31, 29, 27, 25, 23, 21, 19, 17,
  119656. 15, 13, 11, 9, 7, 5, 3, 1,
  119657. 0, 2, 4, 6, 8, 10, 12, 14,
  119658. 16, 18, 20, 22, 24, 26, 28, 30,
  119659. 32, 34, 36, 38, 40, 42, 44, 46,
  119660. 48,
  119661. };
  119662. static encode_aux_threshmatch _vq_auxt__44c7_s_p9_2 = {
  119663. _vq_quantthresh__44c7_s_p9_2,
  119664. _vq_quantmap__44c7_s_p9_2,
  119665. 49,
  119666. 49
  119667. };
  119668. static static_codebook _44c7_s_p9_2 = {
  119669. 1, 49,
  119670. _vq_lengthlist__44c7_s_p9_2,
  119671. 1, -526909440, 1611661312, 6, 0,
  119672. _vq_quantlist__44c7_s_p9_2,
  119673. NULL,
  119674. &_vq_auxt__44c7_s_p9_2,
  119675. NULL,
  119676. 0
  119677. };
  119678. static long _huff_lengthlist__44c7_s_short[] = {
  119679. 4,11,12,14,15,15,17,17,18,18, 5, 6, 6, 8, 9,10,
  119680. 13,17,18,19, 7, 5, 4, 6, 8, 9,11,15,19,19, 8, 6,
  119681. 5, 5, 6, 7,11,14,16,17, 9, 7, 7, 6, 7, 7,10,13,
  119682. 15,19,10, 8, 7, 6, 7, 6, 7, 9,14,16,12,10, 9, 7,
  119683. 7, 6, 4, 5,10,15,14,13,11, 7, 6, 6, 4, 2, 7,13,
  119684. 16,16,15, 9, 8, 8, 8, 6, 9,13,19,19,17,12,11,10,
  119685. 10, 9,11,14,
  119686. };
  119687. static static_codebook _huff_book__44c7_s_short = {
  119688. 2, 100,
  119689. _huff_lengthlist__44c7_s_short,
  119690. 0, 0, 0, 0, 0,
  119691. NULL,
  119692. NULL,
  119693. NULL,
  119694. NULL,
  119695. 0
  119696. };
  119697. static long _huff_lengthlist__44c8_s_long[] = {
  119698. 3, 8,12,13,14,14,14,13,14,14, 6, 4, 5, 8,10,10,
  119699. 11,11,14,13, 9, 5, 4, 5, 7, 8, 9,10,13,13,12, 7,
  119700. 5, 4, 5, 6, 8, 9,12,13,13, 9, 6, 5, 5, 5, 7, 9,
  119701. 11,14,12,10, 7, 6, 5, 4, 6, 7,10,11,12,11, 9, 8,
  119702. 7, 5, 5, 6,10,10,13,12,10, 9, 8, 6, 6, 5, 8,10,
  119703. 14,13,12,12,11,10, 9, 7, 8,10,12,13,14,14,13,12,
  119704. 11, 9, 9,10,
  119705. };
  119706. static static_codebook _huff_book__44c8_s_long = {
  119707. 2, 100,
  119708. _huff_lengthlist__44c8_s_long,
  119709. 0, 0, 0, 0, 0,
  119710. NULL,
  119711. NULL,
  119712. NULL,
  119713. NULL,
  119714. 0
  119715. };
  119716. static long _vq_quantlist__44c8_s_p1_0[] = {
  119717. 1,
  119718. 0,
  119719. 2,
  119720. };
  119721. static long _vq_lengthlist__44c8_s_p1_0[] = {
  119722. 1, 5, 5, 0, 5, 5, 0, 5, 5, 5, 7, 7, 0, 9, 8, 0,
  119723. 9, 8, 6, 7, 7, 0, 8, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  119724. 0, 0, 0, 0, 5, 9, 8, 0, 8, 8, 0, 8, 8, 5, 8, 9,
  119725. 0, 8, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  119726. 9, 8, 0, 8, 8, 0, 8, 8, 5, 8, 9, 0, 8, 8, 0, 8,
  119727. 8,
  119728. };
  119729. static float _vq_quantthresh__44c8_s_p1_0[] = {
  119730. -0.5, 0.5,
  119731. };
  119732. static long _vq_quantmap__44c8_s_p1_0[] = {
  119733. 1, 0, 2,
  119734. };
  119735. static encode_aux_threshmatch _vq_auxt__44c8_s_p1_0 = {
  119736. _vq_quantthresh__44c8_s_p1_0,
  119737. _vq_quantmap__44c8_s_p1_0,
  119738. 3,
  119739. 3
  119740. };
  119741. static static_codebook _44c8_s_p1_0 = {
  119742. 4, 81,
  119743. _vq_lengthlist__44c8_s_p1_0,
  119744. 1, -535822336, 1611661312, 2, 0,
  119745. _vq_quantlist__44c8_s_p1_0,
  119746. NULL,
  119747. &_vq_auxt__44c8_s_p1_0,
  119748. NULL,
  119749. 0
  119750. };
  119751. static long _vq_quantlist__44c8_s_p2_0[] = {
  119752. 2,
  119753. 1,
  119754. 3,
  119755. 0,
  119756. 4,
  119757. };
  119758. static long _vq_lengthlist__44c8_s_p2_0[] = {
  119759. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  119760. 7, 7, 9, 9, 0, 0, 0, 9, 9, 5, 7, 7, 9, 9, 0, 8,
  119761. 7,10, 9, 0, 8, 7,10, 9, 0,10,10,11,11, 0, 0, 0,
  119762. 11,11, 5, 7, 7, 9, 9, 0, 7, 8, 9,10, 0, 7, 8, 9,
  119763. 10, 0,10,10,11,11, 0, 0, 0,11,11, 8, 9, 9,11,10,
  119764. 0,11,10,12,11, 0,11,10,12,12, 0,13,13,14,14, 0,
  119765. 0, 0,14,13, 8, 9, 9,10,11, 0,10,11,12,12, 0,10,
  119766. 11,12,12, 0,13,13,14,14, 0, 0, 0,13,14, 0, 0, 0,
  119767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119768. 0, 0, 0, 0, 0, 0, 5, 8, 7,11,10, 0, 7, 7,10,10,
  119769. 0, 7, 7,10,10, 0, 9, 9,10,10, 0, 0, 0,11,10, 5,
  119770. 7, 8,10,11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9,
  119771. 9,10,10, 0, 0, 0,10,10, 8,10, 9,12,12, 0,10,10,
  119772. 12,11, 0,10,10,12,12, 0,12,12,13,12, 0, 0, 0,13,
  119773. 12, 8, 9,10,12,12, 0,10,10,11,12, 0,10,10,11,12,
  119774. 0,12,12,13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0,
  119775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119776. 0, 0, 0, 6, 8, 7,11,10, 0, 7, 7,10,10, 0, 7, 7,
  119777. 10,10, 0, 9, 9,10,11, 0, 0, 0,10,10, 6, 7, 8,10,
  119778. 11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9, 9,10,10,
  119779. 0, 0, 0,10,10, 9,10, 9,12,12, 0,10,10,12,12, 0,
  119780. 10,10,12,11, 0,12,12,13,13, 0, 0, 0,13,12, 8, 9,
  119781. 10,12,12, 0,10,10,12,12, 0,10,10,11,12, 0,12,12,
  119782. 13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119784. 7,10,10,13,13, 0, 9, 9,12,12, 0, 9, 9,12,12, 0,
  119785. 10,10,12,12, 0, 0, 0,12,12, 7,10,10,13,13, 0, 9,
  119786. 9,12,12, 0, 9, 9,12,12, 0,10,10,12,12, 0, 0, 0,
  119787. 12,12, 9,11,11,14,13, 0,10,10,13,12, 0,11,10,13,
  119788. 12, 0,12,12,13,12, 0, 0, 0,13,13, 9,11,11,13,14,
  119789. 0,10,11,12,13, 0,10,11,13,13, 0,12,12,12,13, 0,
  119790. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  119795. 11,11,14,14, 0,10,11,13,13, 0,11,10,13,13, 0,11,
  119796. 12,13,13, 0, 0, 0,13,12, 9,11,11,14,14, 0,11,10,
  119797. 13,13, 0,10,11,13,13, 0,12,12,13,13, 0, 0, 0,12,
  119798. 13,
  119799. };
  119800. static float _vq_quantthresh__44c8_s_p2_0[] = {
  119801. -1.5, -0.5, 0.5, 1.5,
  119802. };
  119803. static long _vq_quantmap__44c8_s_p2_0[] = {
  119804. 3, 1, 0, 2, 4,
  119805. };
  119806. static encode_aux_threshmatch _vq_auxt__44c8_s_p2_0 = {
  119807. _vq_quantthresh__44c8_s_p2_0,
  119808. _vq_quantmap__44c8_s_p2_0,
  119809. 5,
  119810. 5
  119811. };
  119812. static static_codebook _44c8_s_p2_0 = {
  119813. 4, 625,
  119814. _vq_lengthlist__44c8_s_p2_0,
  119815. 1, -533725184, 1611661312, 3, 0,
  119816. _vq_quantlist__44c8_s_p2_0,
  119817. NULL,
  119818. &_vq_auxt__44c8_s_p2_0,
  119819. NULL,
  119820. 0
  119821. };
  119822. static long _vq_quantlist__44c8_s_p3_0[] = {
  119823. 4,
  119824. 3,
  119825. 5,
  119826. 2,
  119827. 6,
  119828. 1,
  119829. 7,
  119830. 0,
  119831. 8,
  119832. };
  119833. static long _vq_lengthlist__44c8_s_p3_0[] = {
  119834. 2, 4, 4, 5, 5, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  119835. 9, 9, 0, 4, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 6, 6,
  119836. 8, 8,10,10, 0, 0, 0, 6, 6, 8, 8,10,10, 0, 0, 0,
  119837. 7, 7, 9, 9,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0,
  119838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119839. 0,
  119840. };
  119841. static float _vq_quantthresh__44c8_s_p3_0[] = {
  119842. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  119843. };
  119844. static long _vq_quantmap__44c8_s_p3_0[] = {
  119845. 7, 5, 3, 1, 0, 2, 4, 6,
  119846. 8,
  119847. };
  119848. static encode_aux_threshmatch _vq_auxt__44c8_s_p3_0 = {
  119849. _vq_quantthresh__44c8_s_p3_0,
  119850. _vq_quantmap__44c8_s_p3_0,
  119851. 9,
  119852. 9
  119853. };
  119854. static static_codebook _44c8_s_p3_0 = {
  119855. 2, 81,
  119856. _vq_lengthlist__44c8_s_p3_0,
  119857. 1, -531628032, 1611661312, 4, 0,
  119858. _vq_quantlist__44c8_s_p3_0,
  119859. NULL,
  119860. &_vq_auxt__44c8_s_p3_0,
  119861. NULL,
  119862. 0
  119863. };
  119864. static long _vq_quantlist__44c8_s_p4_0[] = {
  119865. 8,
  119866. 7,
  119867. 9,
  119868. 6,
  119869. 10,
  119870. 5,
  119871. 11,
  119872. 4,
  119873. 12,
  119874. 3,
  119875. 13,
  119876. 2,
  119877. 14,
  119878. 1,
  119879. 15,
  119880. 0,
  119881. 16,
  119882. };
  119883. static long _vq_lengthlist__44c8_s_p4_0[] = {
  119884. 3, 4, 4, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  119885. 11, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 8,10,10,11,11,
  119886. 11,11, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  119887. 11,11,11, 0, 6, 5, 6, 6, 7, 7, 9, 9, 9, 9,10,10,
  119888. 11,11,12,12, 0, 0, 0, 6, 6, 7, 7, 9, 9, 9, 9,10,
  119889. 10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,10,
  119890. 11,11,11,12,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,
  119891. 10,11,11,11,12,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  119892. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 8, 8, 9,
  119893. 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 0, 0,
  119894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119902. 0,
  119903. };
  119904. static float _vq_quantthresh__44c8_s_p4_0[] = {
  119905. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  119906. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  119907. };
  119908. static long _vq_quantmap__44c8_s_p4_0[] = {
  119909. 15, 13, 11, 9, 7, 5, 3, 1,
  119910. 0, 2, 4, 6, 8, 10, 12, 14,
  119911. 16,
  119912. };
  119913. static encode_aux_threshmatch _vq_auxt__44c8_s_p4_0 = {
  119914. _vq_quantthresh__44c8_s_p4_0,
  119915. _vq_quantmap__44c8_s_p4_0,
  119916. 17,
  119917. 17
  119918. };
  119919. static static_codebook _44c8_s_p4_0 = {
  119920. 2, 289,
  119921. _vq_lengthlist__44c8_s_p4_0,
  119922. 1, -529530880, 1611661312, 5, 0,
  119923. _vq_quantlist__44c8_s_p4_0,
  119924. NULL,
  119925. &_vq_auxt__44c8_s_p4_0,
  119926. NULL,
  119927. 0
  119928. };
  119929. static long _vq_quantlist__44c8_s_p5_0[] = {
  119930. 1,
  119931. 0,
  119932. 2,
  119933. };
  119934. static long _vq_lengthlist__44c8_s_p5_0[] = {
  119935. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 7, 6,10,10,10,10,
  119936. 10,10, 4, 6, 6,10,10,10,10, 9,10, 5,10,10, 9,11,
  119937. 11,10,11,11, 7,10,10,11,12,12,12,12,12, 7,10,10,
  119938. 11,12,12,12,12,12, 6,10,10,10,12,12,10,12,12, 7,
  119939. 10,10,11,12,12,12,12,12, 7,10,10,11,12,12,12,12,
  119940. 12,
  119941. };
  119942. static float _vq_quantthresh__44c8_s_p5_0[] = {
  119943. -5.5, 5.5,
  119944. };
  119945. static long _vq_quantmap__44c8_s_p5_0[] = {
  119946. 1, 0, 2,
  119947. };
  119948. static encode_aux_threshmatch _vq_auxt__44c8_s_p5_0 = {
  119949. _vq_quantthresh__44c8_s_p5_0,
  119950. _vq_quantmap__44c8_s_p5_0,
  119951. 3,
  119952. 3
  119953. };
  119954. static static_codebook _44c8_s_p5_0 = {
  119955. 4, 81,
  119956. _vq_lengthlist__44c8_s_p5_0,
  119957. 1, -529137664, 1618345984, 2, 0,
  119958. _vq_quantlist__44c8_s_p5_0,
  119959. NULL,
  119960. &_vq_auxt__44c8_s_p5_0,
  119961. NULL,
  119962. 0
  119963. };
  119964. static long _vq_quantlist__44c8_s_p5_1[] = {
  119965. 5,
  119966. 4,
  119967. 6,
  119968. 3,
  119969. 7,
  119970. 2,
  119971. 8,
  119972. 1,
  119973. 9,
  119974. 0,
  119975. 10,
  119976. };
  119977. static long _vq_lengthlist__44c8_s_p5_1[] = {
  119978. 3, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8,11, 4, 5, 6, 6,
  119979. 7, 7, 8, 8, 8, 8,11, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  119980. 9,12, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,12,12,12, 6,
  119981. 6, 7, 7, 8, 8, 9, 9,11,11,11, 6, 6, 7, 7, 8, 8,
  119982. 8, 8,11,11,11, 6, 6, 7, 7, 8, 8, 8, 8,11,11,11,
  119983. 7, 7, 7, 8, 8, 8, 8, 8,11,11,11,11,11, 7, 7, 8,
  119984. 8, 8, 8,11,11,11,11,11, 7, 7, 7, 7, 8, 8,11,11,
  119985. 11,11,11, 7, 7, 7, 7, 8, 8,
  119986. };
  119987. static float _vq_quantthresh__44c8_s_p5_1[] = {
  119988. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  119989. 3.5, 4.5,
  119990. };
  119991. static long _vq_quantmap__44c8_s_p5_1[] = {
  119992. 9, 7, 5, 3, 1, 0, 2, 4,
  119993. 6, 8, 10,
  119994. };
  119995. static encode_aux_threshmatch _vq_auxt__44c8_s_p5_1 = {
  119996. _vq_quantthresh__44c8_s_p5_1,
  119997. _vq_quantmap__44c8_s_p5_1,
  119998. 11,
  119999. 11
  120000. };
  120001. static static_codebook _44c8_s_p5_1 = {
  120002. 2, 121,
  120003. _vq_lengthlist__44c8_s_p5_1,
  120004. 1, -531365888, 1611661312, 4, 0,
  120005. _vq_quantlist__44c8_s_p5_1,
  120006. NULL,
  120007. &_vq_auxt__44c8_s_p5_1,
  120008. NULL,
  120009. 0
  120010. };
  120011. static long _vq_quantlist__44c8_s_p6_0[] = {
  120012. 6,
  120013. 5,
  120014. 7,
  120015. 4,
  120016. 8,
  120017. 3,
  120018. 9,
  120019. 2,
  120020. 10,
  120021. 1,
  120022. 11,
  120023. 0,
  120024. 12,
  120025. };
  120026. static long _vq_lengthlist__44c8_s_p6_0[] = {
  120027. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  120028. 7, 7, 8, 8, 9, 9,10,10,11,11, 6, 5, 5, 7, 7, 8,
  120029. 8, 9, 9,10,10,11,11, 0, 7, 7, 7, 7, 9, 9,10,10,
  120030. 10,10,11,11, 0, 7, 7, 7, 7, 9, 9,10,10,10,10,11,
  120031. 11, 0,11,11, 9, 9,10,10,11,11,11,11,12,12, 0,12,
  120032. 12, 9, 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0,
  120033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120037. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120038. };
  120039. static float _vq_quantthresh__44c8_s_p6_0[] = {
  120040. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  120041. 12.5, 17.5, 22.5, 27.5,
  120042. };
  120043. static long _vq_quantmap__44c8_s_p6_0[] = {
  120044. 11, 9, 7, 5, 3, 1, 0, 2,
  120045. 4, 6, 8, 10, 12,
  120046. };
  120047. static encode_aux_threshmatch _vq_auxt__44c8_s_p6_0 = {
  120048. _vq_quantthresh__44c8_s_p6_0,
  120049. _vq_quantmap__44c8_s_p6_0,
  120050. 13,
  120051. 13
  120052. };
  120053. static static_codebook _44c8_s_p6_0 = {
  120054. 2, 169,
  120055. _vq_lengthlist__44c8_s_p6_0,
  120056. 1, -526516224, 1616117760, 4, 0,
  120057. _vq_quantlist__44c8_s_p6_0,
  120058. NULL,
  120059. &_vq_auxt__44c8_s_p6_0,
  120060. NULL,
  120061. 0
  120062. };
  120063. static long _vq_quantlist__44c8_s_p6_1[] = {
  120064. 2,
  120065. 1,
  120066. 3,
  120067. 0,
  120068. 4,
  120069. };
  120070. static long _vq_lengthlist__44c8_s_p6_1[] = {
  120071. 3, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 6,
  120072. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  120073. };
  120074. static float _vq_quantthresh__44c8_s_p6_1[] = {
  120075. -1.5, -0.5, 0.5, 1.5,
  120076. };
  120077. static long _vq_quantmap__44c8_s_p6_1[] = {
  120078. 3, 1, 0, 2, 4,
  120079. };
  120080. static encode_aux_threshmatch _vq_auxt__44c8_s_p6_1 = {
  120081. _vq_quantthresh__44c8_s_p6_1,
  120082. _vq_quantmap__44c8_s_p6_1,
  120083. 5,
  120084. 5
  120085. };
  120086. static static_codebook _44c8_s_p6_1 = {
  120087. 2, 25,
  120088. _vq_lengthlist__44c8_s_p6_1,
  120089. 1, -533725184, 1611661312, 3, 0,
  120090. _vq_quantlist__44c8_s_p6_1,
  120091. NULL,
  120092. &_vq_auxt__44c8_s_p6_1,
  120093. NULL,
  120094. 0
  120095. };
  120096. static long _vq_quantlist__44c8_s_p7_0[] = {
  120097. 6,
  120098. 5,
  120099. 7,
  120100. 4,
  120101. 8,
  120102. 3,
  120103. 9,
  120104. 2,
  120105. 10,
  120106. 1,
  120107. 11,
  120108. 0,
  120109. 12,
  120110. };
  120111. static long _vq_lengthlist__44c8_s_p7_0[] = {
  120112. 1, 4, 4, 6, 6, 8, 7, 9, 9,10,10,12,12, 6, 5, 5,
  120113. 7, 7, 8, 8,10,10,11,11,12,12, 7, 5, 5, 7, 7, 8,
  120114. 8,10,10,11,11,12,12,21, 7, 7, 7, 7, 8, 9,10,10,
  120115. 11,11,12,12,21, 7, 7, 7, 7, 9, 9,10,10,12,12,13,
  120116. 13,21,11,11, 8, 8, 9, 9,11,11,12,12,13,13,21,11,
  120117. 11, 8, 8, 9, 9,11,11,12,12,13,13,21,21,21,10,10,
  120118. 10,10,11,11,12,13,13,13,21,21,21,10,10,10,10,11,
  120119. 11,13,13,14,13,21,21,21,13,13,11,11,12,12,13,13,
  120120. 14,14,21,21,21,14,14,11,11,12,12,13,13,14,14,21,
  120121. 21,21,21,20,13,13,13,12,14,14,16,15,20,20,20,20,
  120122. 20,13,13,13,13,14,13,15,15,
  120123. };
  120124. static float _vq_quantthresh__44c8_s_p7_0[] = {
  120125. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  120126. 27.5, 38.5, 49.5, 60.5,
  120127. };
  120128. static long _vq_quantmap__44c8_s_p7_0[] = {
  120129. 11, 9, 7, 5, 3, 1, 0, 2,
  120130. 4, 6, 8, 10, 12,
  120131. };
  120132. static encode_aux_threshmatch _vq_auxt__44c8_s_p7_0 = {
  120133. _vq_quantthresh__44c8_s_p7_0,
  120134. _vq_quantmap__44c8_s_p7_0,
  120135. 13,
  120136. 13
  120137. };
  120138. static static_codebook _44c8_s_p7_0 = {
  120139. 2, 169,
  120140. _vq_lengthlist__44c8_s_p7_0,
  120141. 1, -523206656, 1618345984, 4, 0,
  120142. _vq_quantlist__44c8_s_p7_0,
  120143. NULL,
  120144. &_vq_auxt__44c8_s_p7_0,
  120145. NULL,
  120146. 0
  120147. };
  120148. static long _vq_quantlist__44c8_s_p7_1[] = {
  120149. 5,
  120150. 4,
  120151. 6,
  120152. 3,
  120153. 7,
  120154. 2,
  120155. 8,
  120156. 1,
  120157. 9,
  120158. 0,
  120159. 10,
  120160. };
  120161. static long _vq_lengthlist__44c8_s_p7_1[] = {
  120162. 4, 5, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 6, 6, 6, 7,
  120163. 7, 7, 7, 7, 7, 7, 8, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  120164. 7, 8, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7,
  120165. 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7,
  120166. 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  120167. 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  120168. 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 8, 8,
  120169. 8, 8, 8, 7, 7, 7, 7, 7, 7,
  120170. };
  120171. static float _vq_quantthresh__44c8_s_p7_1[] = {
  120172. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  120173. 3.5, 4.5,
  120174. };
  120175. static long _vq_quantmap__44c8_s_p7_1[] = {
  120176. 9, 7, 5, 3, 1, 0, 2, 4,
  120177. 6, 8, 10,
  120178. };
  120179. static encode_aux_threshmatch _vq_auxt__44c8_s_p7_1 = {
  120180. _vq_quantthresh__44c8_s_p7_1,
  120181. _vq_quantmap__44c8_s_p7_1,
  120182. 11,
  120183. 11
  120184. };
  120185. static static_codebook _44c8_s_p7_1 = {
  120186. 2, 121,
  120187. _vq_lengthlist__44c8_s_p7_1,
  120188. 1, -531365888, 1611661312, 4, 0,
  120189. _vq_quantlist__44c8_s_p7_1,
  120190. NULL,
  120191. &_vq_auxt__44c8_s_p7_1,
  120192. NULL,
  120193. 0
  120194. };
  120195. static long _vq_quantlist__44c8_s_p8_0[] = {
  120196. 7,
  120197. 6,
  120198. 8,
  120199. 5,
  120200. 9,
  120201. 4,
  120202. 10,
  120203. 3,
  120204. 11,
  120205. 2,
  120206. 12,
  120207. 1,
  120208. 13,
  120209. 0,
  120210. 14,
  120211. };
  120212. static long _vq_lengthlist__44c8_s_p8_0[] = {
  120213. 1, 4, 4, 7, 6, 8, 8, 8, 7, 9, 8,10,10,11,10, 6,
  120214. 5, 5, 7, 7, 9, 9, 8, 8,10,10,11,11,12,11, 6, 5,
  120215. 5, 7, 7, 9, 9, 9, 9,10,10,11,11,12,12,20, 8, 8,
  120216. 8, 8, 9, 9, 9, 9,10,10,11,11,12,12,20, 8, 8, 8,
  120217. 8,10, 9, 9, 9,10,10,11,11,12,12,20,12,12, 9, 9,
  120218. 10,10,10,10,10,11,12,12,12,12,20,12,12, 9, 9,10,
  120219. 10,10,10,11,11,12,12,13,13,20,20,20, 9, 9, 9, 9,
  120220. 11,10,11,11,12,12,12,13,20,19,19, 9, 9, 9, 9,11,
  120221. 11,11,12,12,12,13,13,19,19,19,13,13,10,10,11,11,
  120222. 12,12,13,13,13,13,19,19,19,14,13,11,10,11,11,12,
  120223. 12,12,13,13,13,19,19,19,19,19,12,12,12,12,13,13,
  120224. 13,13,14,13,19,19,19,19,19,12,12,12,11,12,12,13,
  120225. 14,14,14,19,19,19,19,19,16,15,13,12,13,13,13,14,
  120226. 14,14,19,19,19,19,19,17,17,13,12,13,11,14,13,15,
  120227. 15,
  120228. };
  120229. static float _vq_quantthresh__44c8_s_p8_0[] = {
  120230. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  120231. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  120232. };
  120233. static long _vq_quantmap__44c8_s_p8_0[] = {
  120234. 13, 11, 9, 7, 5, 3, 1, 0,
  120235. 2, 4, 6, 8, 10, 12, 14,
  120236. };
  120237. static encode_aux_threshmatch _vq_auxt__44c8_s_p8_0 = {
  120238. _vq_quantthresh__44c8_s_p8_0,
  120239. _vq_quantmap__44c8_s_p8_0,
  120240. 15,
  120241. 15
  120242. };
  120243. static static_codebook _44c8_s_p8_0 = {
  120244. 2, 225,
  120245. _vq_lengthlist__44c8_s_p8_0,
  120246. 1, -520986624, 1620377600, 4, 0,
  120247. _vq_quantlist__44c8_s_p8_0,
  120248. NULL,
  120249. &_vq_auxt__44c8_s_p8_0,
  120250. NULL,
  120251. 0
  120252. };
  120253. static long _vq_quantlist__44c8_s_p8_1[] = {
  120254. 10,
  120255. 9,
  120256. 11,
  120257. 8,
  120258. 12,
  120259. 7,
  120260. 13,
  120261. 6,
  120262. 14,
  120263. 5,
  120264. 15,
  120265. 4,
  120266. 16,
  120267. 3,
  120268. 17,
  120269. 2,
  120270. 18,
  120271. 1,
  120272. 19,
  120273. 0,
  120274. 20,
  120275. };
  120276. static long _vq_lengthlist__44c8_s_p8_1[] = {
  120277. 4, 5, 5, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  120278. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  120279. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  120280. 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,
  120281. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120282. 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  120283. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 9,
  120284. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  120285. 10, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120286. 9, 9, 9,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120287. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9,
  120288. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  120289. 10,10, 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9, 9, 9,
  120290. 9, 9,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120291. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9, 9,
  120292. 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,10,10,10,10,
  120293. 10,10,10, 9, 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,
  120294. 9,10,10,10,10,10,10,10, 9,10,10, 9,10,10,10,10,
  120295. 9,10, 9,10,10, 9,10,10,10,10,10,10,10, 9,10,10,
  120296. 10,10,10,10, 9, 9,10,10, 9,10,10,10,10,10,10,10,
  120297. 10,10,10,10,10,10,10,10, 9, 9, 9,10, 9, 9, 9, 9,
  120298. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9,
  120299. 10, 9,10, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  120300. 10,10,10,10, 9, 9,10, 9, 9, 9,10,10,10,10,10,10,
  120301. 10,10,10,10,10, 9, 9, 9, 9, 9, 9,10, 9, 9,10,10,
  120302. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9,10, 9,
  120303. 9,10, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  120304. 10, 9, 9,10,10, 9,10, 9, 9,
  120305. };
  120306. static float _vq_quantthresh__44c8_s_p8_1[] = {
  120307. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  120308. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  120309. 6.5, 7.5, 8.5, 9.5,
  120310. };
  120311. static long _vq_quantmap__44c8_s_p8_1[] = {
  120312. 19, 17, 15, 13, 11, 9, 7, 5,
  120313. 3, 1, 0, 2, 4, 6, 8, 10,
  120314. 12, 14, 16, 18, 20,
  120315. };
  120316. static encode_aux_threshmatch _vq_auxt__44c8_s_p8_1 = {
  120317. _vq_quantthresh__44c8_s_p8_1,
  120318. _vq_quantmap__44c8_s_p8_1,
  120319. 21,
  120320. 21
  120321. };
  120322. static static_codebook _44c8_s_p8_1 = {
  120323. 2, 441,
  120324. _vq_lengthlist__44c8_s_p8_1,
  120325. 1, -529268736, 1611661312, 5, 0,
  120326. _vq_quantlist__44c8_s_p8_1,
  120327. NULL,
  120328. &_vq_auxt__44c8_s_p8_1,
  120329. NULL,
  120330. 0
  120331. };
  120332. static long _vq_quantlist__44c8_s_p9_0[] = {
  120333. 8,
  120334. 7,
  120335. 9,
  120336. 6,
  120337. 10,
  120338. 5,
  120339. 11,
  120340. 4,
  120341. 12,
  120342. 3,
  120343. 13,
  120344. 2,
  120345. 14,
  120346. 1,
  120347. 15,
  120348. 0,
  120349. 16,
  120350. };
  120351. static long _vq_lengthlist__44c8_s_p9_0[] = {
  120352. 1, 4, 3,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120353. 11, 4, 7, 7,11,11,11,11,11,11,11,11,11,11,11,11,
  120354. 11,11, 4, 8,11,11,11,11,11,11,11,11,11,11,11,11,
  120355. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120356. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120357. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120358. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120359. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120360. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120361. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120362. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120363. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120364. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120365. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120366. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120367. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120368. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120369. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120370. 10,
  120371. };
  120372. static float _vq_quantthresh__44c8_s_p9_0[] = {
  120373. -6982.5, -6051.5, -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -465.5,
  120374. 465.5, 1396.5, 2327.5, 3258.5, 4189.5, 5120.5, 6051.5, 6982.5,
  120375. };
  120376. static long _vq_quantmap__44c8_s_p9_0[] = {
  120377. 15, 13, 11, 9, 7, 5, 3, 1,
  120378. 0, 2, 4, 6, 8, 10, 12, 14,
  120379. 16,
  120380. };
  120381. static encode_aux_threshmatch _vq_auxt__44c8_s_p9_0 = {
  120382. _vq_quantthresh__44c8_s_p9_0,
  120383. _vq_quantmap__44c8_s_p9_0,
  120384. 17,
  120385. 17
  120386. };
  120387. static static_codebook _44c8_s_p9_0 = {
  120388. 2, 289,
  120389. _vq_lengthlist__44c8_s_p9_0,
  120390. 1, -509798400, 1631393792, 5, 0,
  120391. _vq_quantlist__44c8_s_p9_0,
  120392. NULL,
  120393. &_vq_auxt__44c8_s_p9_0,
  120394. NULL,
  120395. 0
  120396. };
  120397. static long _vq_quantlist__44c8_s_p9_1[] = {
  120398. 9,
  120399. 8,
  120400. 10,
  120401. 7,
  120402. 11,
  120403. 6,
  120404. 12,
  120405. 5,
  120406. 13,
  120407. 4,
  120408. 14,
  120409. 3,
  120410. 15,
  120411. 2,
  120412. 16,
  120413. 1,
  120414. 17,
  120415. 0,
  120416. 18,
  120417. };
  120418. static long _vq_lengthlist__44c8_s_p9_1[] = {
  120419. 1, 4, 4, 7, 6, 7, 7, 7, 7, 8, 8, 9, 9,10,10,10,
  120420. 10,11,11, 6, 6, 6, 8, 8, 9, 8, 8, 7,10, 8,11,10,
  120421. 12,11,12,12,13,13, 5, 5, 6, 8, 8, 9, 9, 8, 8,10,
  120422. 9,11,11,12,12,13,13,13,13,17, 8, 8, 9, 9, 9, 9,
  120423. 9, 9,10, 9,12,10,12,12,13,12,13,13,17, 9, 8, 9,
  120424. 9, 9, 9, 9, 9,10,10,12,12,12,12,13,13,13,13,17,
  120425. 13,13, 9, 9,10,10,10,10,11,11,12,11,13,12,13,13,
  120426. 14,15,17,13,13, 9, 8,10, 9,10,10,11,11,12,12,14,
  120427. 13,15,13,14,15,17,17,17, 9,10, 9,10,11,11,12,12,
  120428. 12,12,13,13,14,14,15,15,17,17,17, 9, 8, 9, 8,11,
  120429. 11,12,12,12,12,14,13,14,14,14,15,17,17,17,12,14,
  120430. 9,10,11,11,12,12,14,13,13,14,15,13,15,15,17,17,
  120431. 17,13,11,10, 8,11, 9,13,12,13,13,13,13,13,14,14,
  120432. 14,17,17,17,17,17,11,12,11,11,13,13,14,13,15,14,
  120433. 13,15,16,15,17,17,17,17,17,11,11,12, 8,13,12,14,
  120434. 13,17,14,15,14,15,14,17,17,17,17,17,15,15,12,12,
  120435. 12,12,13,14,14,14,15,14,17,14,17,17,17,17,17,16,
  120436. 17,12,12,13,12,13,13,14,14,14,14,14,14,17,17,17,
  120437. 17,17,17,17,14,14,13,12,13,13,15,15,14,13,15,17,
  120438. 17,17,17,17,17,17,17,13,14,13,13,13,13,14,15,15,
  120439. 15,14,15,17,17,17,17,17,17,17,16,15,13,14,13,13,
  120440. 14,14,15,14,14,16,17,17,17,17,17,17,17,16,16,13,
  120441. 14,13,13,14,14,15,14,15,14,
  120442. };
  120443. static float _vq_quantthresh__44c8_s_p9_1[] = {
  120444. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  120445. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  120446. 367.5, 416.5,
  120447. };
  120448. static long _vq_quantmap__44c8_s_p9_1[] = {
  120449. 17, 15, 13, 11, 9, 7, 5, 3,
  120450. 1, 0, 2, 4, 6, 8, 10, 12,
  120451. 14, 16, 18,
  120452. };
  120453. static encode_aux_threshmatch _vq_auxt__44c8_s_p9_1 = {
  120454. _vq_quantthresh__44c8_s_p9_1,
  120455. _vq_quantmap__44c8_s_p9_1,
  120456. 19,
  120457. 19
  120458. };
  120459. static static_codebook _44c8_s_p9_1 = {
  120460. 2, 361,
  120461. _vq_lengthlist__44c8_s_p9_1,
  120462. 1, -518287360, 1622704128, 5, 0,
  120463. _vq_quantlist__44c8_s_p9_1,
  120464. NULL,
  120465. &_vq_auxt__44c8_s_p9_1,
  120466. NULL,
  120467. 0
  120468. };
  120469. static long _vq_quantlist__44c8_s_p9_2[] = {
  120470. 24,
  120471. 23,
  120472. 25,
  120473. 22,
  120474. 26,
  120475. 21,
  120476. 27,
  120477. 20,
  120478. 28,
  120479. 19,
  120480. 29,
  120481. 18,
  120482. 30,
  120483. 17,
  120484. 31,
  120485. 16,
  120486. 32,
  120487. 15,
  120488. 33,
  120489. 14,
  120490. 34,
  120491. 13,
  120492. 35,
  120493. 12,
  120494. 36,
  120495. 11,
  120496. 37,
  120497. 10,
  120498. 38,
  120499. 9,
  120500. 39,
  120501. 8,
  120502. 40,
  120503. 7,
  120504. 41,
  120505. 6,
  120506. 42,
  120507. 5,
  120508. 43,
  120509. 4,
  120510. 44,
  120511. 3,
  120512. 45,
  120513. 2,
  120514. 46,
  120515. 1,
  120516. 47,
  120517. 0,
  120518. 48,
  120519. };
  120520. static long _vq_lengthlist__44c8_s_p9_2[] = {
  120521. 2, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
  120522. 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  120523. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  120524. 7,
  120525. };
  120526. static float _vq_quantthresh__44c8_s_p9_2[] = {
  120527. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  120528. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  120529. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  120530. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  120531. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  120532. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  120533. };
  120534. static long _vq_quantmap__44c8_s_p9_2[] = {
  120535. 47, 45, 43, 41, 39, 37, 35, 33,
  120536. 31, 29, 27, 25, 23, 21, 19, 17,
  120537. 15, 13, 11, 9, 7, 5, 3, 1,
  120538. 0, 2, 4, 6, 8, 10, 12, 14,
  120539. 16, 18, 20, 22, 24, 26, 28, 30,
  120540. 32, 34, 36, 38, 40, 42, 44, 46,
  120541. 48,
  120542. };
  120543. static encode_aux_threshmatch _vq_auxt__44c8_s_p9_2 = {
  120544. _vq_quantthresh__44c8_s_p9_2,
  120545. _vq_quantmap__44c8_s_p9_2,
  120546. 49,
  120547. 49
  120548. };
  120549. static static_codebook _44c8_s_p9_2 = {
  120550. 1, 49,
  120551. _vq_lengthlist__44c8_s_p9_2,
  120552. 1, -526909440, 1611661312, 6, 0,
  120553. _vq_quantlist__44c8_s_p9_2,
  120554. NULL,
  120555. &_vq_auxt__44c8_s_p9_2,
  120556. NULL,
  120557. 0
  120558. };
  120559. static long _huff_lengthlist__44c8_s_short[] = {
  120560. 4,11,13,14,15,15,18,17,19,17, 5, 6, 8, 9,10,10,
  120561. 12,15,19,19, 6, 6, 6, 6, 8, 8,11,14,18,19, 8, 6,
  120562. 5, 4, 6, 7,10,13,16,17, 9, 7, 6, 5, 6, 7, 9,12,
  120563. 15,19,10, 8, 7, 6, 6, 6, 7, 9,13,15,12,10, 9, 8,
  120564. 7, 6, 4, 5,10,15,13,13,11, 8, 6, 6, 4, 2, 7,12,
  120565. 17,15,16,10, 8, 8, 7, 6, 9,12,19,18,17,13,11,10,
  120566. 10, 9,11,14,
  120567. };
  120568. static static_codebook _huff_book__44c8_s_short = {
  120569. 2, 100,
  120570. _huff_lengthlist__44c8_s_short,
  120571. 0, 0, 0, 0, 0,
  120572. NULL,
  120573. NULL,
  120574. NULL,
  120575. NULL,
  120576. 0
  120577. };
  120578. static long _huff_lengthlist__44c9_s_long[] = {
  120579. 3, 8,12,14,15,15,15,13,15,15, 6, 5, 8,10,12,12,
  120580. 13,12,14,13,10, 6, 5, 6, 8, 9,11,11,13,13,13, 8,
  120581. 5, 4, 5, 6, 8,10,11,13,14,10, 7, 5, 4, 5, 7, 9,
  120582. 11,12,13,11, 8, 6, 5, 4, 5, 7, 9,11,12,11,10, 8,
  120583. 7, 5, 4, 5, 9,10,13,13,11,10, 8, 6, 5, 4, 7, 9,
  120584. 15,14,13,12,10, 9, 8, 7, 8, 9,12,12,14,13,12,11,
  120585. 10, 9, 8, 9,
  120586. };
  120587. static static_codebook _huff_book__44c9_s_long = {
  120588. 2, 100,
  120589. _huff_lengthlist__44c9_s_long,
  120590. 0, 0, 0, 0, 0,
  120591. NULL,
  120592. NULL,
  120593. NULL,
  120594. NULL,
  120595. 0
  120596. };
  120597. static long _vq_quantlist__44c9_s_p1_0[] = {
  120598. 1,
  120599. 0,
  120600. 2,
  120601. };
  120602. static long _vq_lengthlist__44c9_s_p1_0[] = {
  120603. 1, 5, 5, 0, 5, 5, 0, 5, 5, 6, 8, 8, 0, 9, 8, 0,
  120604. 9, 8, 6, 8, 8, 0, 8, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  120605. 0, 0, 0, 0, 5, 8, 8, 0, 7, 7, 0, 8, 8, 5, 8, 8,
  120606. 0, 7, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  120607. 9, 8, 0, 8, 8, 0, 7, 7, 5, 8, 9, 0, 8, 8, 0, 7,
  120608. 7,
  120609. };
  120610. static float _vq_quantthresh__44c9_s_p1_0[] = {
  120611. -0.5, 0.5,
  120612. };
  120613. static long _vq_quantmap__44c9_s_p1_0[] = {
  120614. 1, 0, 2,
  120615. };
  120616. static encode_aux_threshmatch _vq_auxt__44c9_s_p1_0 = {
  120617. _vq_quantthresh__44c9_s_p1_0,
  120618. _vq_quantmap__44c9_s_p1_0,
  120619. 3,
  120620. 3
  120621. };
  120622. static static_codebook _44c9_s_p1_0 = {
  120623. 4, 81,
  120624. _vq_lengthlist__44c9_s_p1_0,
  120625. 1, -535822336, 1611661312, 2, 0,
  120626. _vq_quantlist__44c9_s_p1_0,
  120627. NULL,
  120628. &_vq_auxt__44c9_s_p1_0,
  120629. NULL,
  120630. 0
  120631. };
  120632. static long _vq_quantlist__44c9_s_p2_0[] = {
  120633. 2,
  120634. 1,
  120635. 3,
  120636. 0,
  120637. 4,
  120638. };
  120639. static long _vq_lengthlist__44c9_s_p2_0[] = {
  120640. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  120641. 7, 7, 9, 9, 0, 0, 0, 9, 9, 6, 7, 7, 9, 8, 0, 8,
  120642. 8, 9, 9, 0, 8, 7, 9, 9, 0, 9,10,10,10, 0, 0, 0,
  120643. 11,10, 6, 7, 7, 8, 9, 0, 8, 8, 9, 9, 0, 7, 8, 9,
  120644. 9, 0,10, 9,11,10, 0, 0, 0,10,10, 8, 9, 8,10,10,
  120645. 0,10,10,12,11, 0,10,10,11,11, 0,12,13,13,13, 0,
  120646. 0, 0,13,12, 8, 8, 9,10,10, 0,10,10,11,12, 0,10,
  120647. 10,11,11, 0,13,12,13,13, 0, 0, 0,13,13, 0, 0, 0,
  120648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120649. 0, 0, 0, 0, 0, 0, 6, 8, 7,10,10, 0, 7, 7,10, 9,
  120650. 0, 7, 7,10,10, 0, 9, 9,10,10, 0, 0, 0,10,10, 6,
  120651. 7, 8,10,10, 0, 7, 7, 9,10, 0, 7, 7,10,10, 0, 9,
  120652. 9,10,10, 0, 0, 0,10,10, 8, 9, 9,11,11, 0,10,10,
  120653. 11,11, 0,10,10,11,11, 0,12,12,12,12, 0, 0, 0,12,
  120654. 12, 8, 9,10,11,11, 0, 9,10,11,11, 0,10,10,11,11,
  120655. 0,12,12,12,12, 0, 0, 0,12,12, 0, 0, 0, 0, 0, 0,
  120656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120657. 0, 0, 0, 5, 8, 7,10,10, 0, 7, 7,10,10, 0, 7, 7,
  120658. 10, 9, 0, 9, 9,10,10, 0, 0, 0,10,10, 6, 7, 8,10,
  120659. 10, 0, 7, 7,10,10, 0, 7, 7, 9,10, 0, 9, 9,10,10,
  120660. 0, 0, 0,10,10, 8,10, 9,12,11, 0,10,10,12,11, 0,
  120661. 10, 9,11,11, 0,11,12,12,12, 0, 0, 0,12,12, 8, 9,
  120662. 10,11,12, 0,10,10,11,11, 0, 9,10,11,11, 0,12,11,
  120663. 12,12, 0, 0, 0,12,12, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120665. 7,10, 9,12,12, 0, 9, 9,12,11, 0, 9, 9,11,11, 0,
  120666. 10,10,12,11, 0, 0, 0,11,12, 7, 9,10,12,12, 0, 9,
  120667. 9,11,12, 0, 9, 9,11,11, 0,10,10,11,12, 0, 0, 0,
  120668. 11,11, 9,11,10,13,12, 0,10,10,12,12, 0,10,10,12,
  120669. 12, 0,11,11,12,12, 0, 0, 0,13,12, 9,10,11,12,13,
  120670. 0,10,10,12,12, 0,10,10,12,12, 0,11,12,12,12, 0,
  120671. 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  120676. 11,10,13,13, 0,10,10,12,12, 0,10,10,12,12, 0,11,
  120677. 12,12,12, 0, 0, 0,12,12, 9,10,11,13,13, 0,10,10,
  120678. 12,12, 0,10,10,12,12, 0,12,11,13,12, 0, 0, 0,12,
  120679. 12,
  120680. };
  120681. static float _vq_quantthresh__44c9_s_p2_0[] = {
  120682. -1.5, -0.5, 0.5, 1.5,
  120683. };
  120684. static long _vq_quantmap__44c9_s_p2_0[] = {
  120685. 3, 1, 0, 2, 4,
  120686. };
  120687. static encode_aux_threshmatch _vq_auxt__44c9_s_p2_0 = {
  120688. _vq_quantthresh__44c9_s_p2_0,
  120689. _vq_quantmap__44c9_s_p2_0,
  120690. 5,
  120691. 5
  120692. };
  120693. static static_codebook _44c9_s_p2_0 = {
  120694. 4, 625,
  120695. _vq_lengthlist__44c9_s_p2_0,
  120696. 1, -533725184, 1611661312, 3, 0,
  120697. _vq_quantlist__44c9_s_p2_0,
  120698. NULL,
  120699. &_vq_auxt__44c9_s_p2_0,
  120700. NULL,
  120701. 0
  120702. };
  120703. static long _vq_quantlist__44c9_s_p3_0[] = {
  120704. 4,
  120705. 3,
  120706. 5,
  120707. 2,
  120708. 6,
  120709. 1,
  120710. 7,
  120711. 0,
  120712. 8,
  120713. };
  120714. static long _vq_lengthlist__44c9_s_p3_0[] = {
  120715. 3, 4, 4, 5, 5, 6, 6, 8, 8, 0, 4, 4, 5, 5, 6, 7,
  120716. 8, 8, 0, 4, 4, 5, 5, 7, 7, 8, 8, 0, 5, 5, 6, 6,
  120717. 7, 7, 9, 9, 0, 0, 0, 6, 6, 7, 7, 9, 9, 0, 0, 0,
  120718. 7, 7, 8, 8, 9, 9, 0, 0, 0, 7, 7, 8, 8, 9, 9, 0,
  120719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120720. 0,
  120721. };
  120722. static float _vq_quantthresh__44c9_s_p3_0[] = {
  120723. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  120724. };
  120725. static long _vq_quantmap__44c9_s_p3_0[] = {
  120726. 7, 5, 3, 1, 0, 2, 4, 6,
  120727. 8,
  120728. };
  120729. static encode_aux_threshmatch _vq_auxt__44c9_s_p3_0 = {
  120730. _vq_quantthresh__44c9_s_p3_0,
  120731. _vq_quantmap__44c9_s_p3_0,
  120732. 9,
  120733. 9
  120734. };
  120735. static static_codebook _44c9_s_p3_0 = {
  120736. 2, 81,
  120737. _vq_lengthlist__44c9_s_p3_0,
  120738. 1, -531628032, 1611661312, 4, 0,
  120739. _vq_quantlist__44c9_s_p3_0,
  120740. NULL,
  120741. &_vq_auxt__44c9_s_p3_0,
  120742. NULL,
  120743. 0
  120744. };
  120745. static long _vq_quantlist__44c9_s_p4_0[] = {
  120746. 8,
  120747. 7,
  120748. 9,
  120749. 6,
  120750. 10,
  120751. 5,
  120752. 11,
  120753. 4,
  120754. 12,
  120755. 3,
  120756. 13,
  120757. 2,
  120758. 14,
  120759. 1,
  120760. 15,
  120761. 0,
  120762. 16,
  120763. };
  120764. static long _vq_lengthlist__44c9_s_p4_0[] = {
  120765. 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,10,
  120766. 10, 0, 5, 4, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10,10,
  120767. 11,11, 0, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,
  120768. 10,11,11, 0, 6, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,
  120769. 11,11,11,12, 0, 0, 0, 6, 6, 7, 7, 8, 8, 9, 9,10,
  120770. 10,11,11,12,12, 0, 0, 0, 7, 7, 7, 7, 9, 9, 9, 9,
  120771. 10,10,11,11,12,12, 0, 0, 0, 7, 7, 7, 8, 9, 9, 9,
  120772. 9,10,10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  120773. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 8, 8, 9,
  120774. 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 0, 0,
  120775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120783. 0,
  120784. };
  120785. static float _vq_quantthresh__44c9_s_p4_0[] = {
  120786. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  120787. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  120788. };
  120789. static long _vq_quantmap__44c9_s_p4_0[] = {
  120790. 15, 13, 11, 9, 7, 5, 3, 1,
  120791. 0, 2, 4, 6, 8, 10, 12, 14,
  120792. 16,
  120793. };
  120794. static encode_aux_threshmatch _vq_auxt__44c9_s_p4_0 = {
  120795. _vq_quantthresh__44c9_s_p4_0,
  120796. _vq_quantmap__44c9_s_p4_0,
  120797. 17,
  120798. 17
  120799. };
  120800. static static_codebook _44c9_s_p4_0 = {
  120801. 2, 289,
  120802. _vq_lengthlist__44c9_s_p4_0,
  120803. 1, -529530880, 1611661312, 5, 0,
  120804. _vq_quantlist__44c9_s_p4_0,
  120805. NULL,
  120806. &_vq_auxt__44c9_s_p4_0,
  120807. NULL,
  120808. 0
  120809. };
  120810. static long _vq_quantlist__44c9_s_p5_0[] = {
  120811. 1,
  120812. 0,
  120813. 2,
  120814. };
  120815. static long _vq_lengthlist__44c9_s_p5_0[] = {
  120816. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 7, 6, 9,10,10,10,
  120817. 10, 9, 4, 6, 7, 9,10,10,10, 9,10, 5, 9, 9, 9,11,
  120818. 11,10,11,11, 7,10, 9,11,12,11,12,12,12, 7, 9,10,
  120819. 11,11,12,12,12,12, 6,10,10,10,12,12,10,12,11, 7,
  120820. 10,10,11,12,12,11,12,12, 7,10,10,11,12,12,12,12,
  120821. 12,
  120822. };
  120823. static float _vq_quantthresh__44c9_s_p5_0[] = {
  120824. -5.5, 5.5,
  120825. };
  120826. static long _vq_quantmap__44c9_s_p5_0[] = {
  120827. 1, 0, 2,
  120828. };
  120829. static encode_aux_threshmatch _vq_auxt__44c9_s_p5_0 = {
  120830. _vq_quantthresh__44c9_s_p5_0,
  120831. _vq_quantmap__44c9_s_p5_0,
  120832. 3,
  120833. 3
  120834. };
  120835. static static_codebook _44c9_s_p5_0 = {
  120836. 4, 81,
  120837. _vq_lengthlist__44c9_s_p5_0,
  120838. 1, -529137664, 1618345984, 2, 0,
  120839. _vq_quantlist__44c9_s_p5_0,
  120840. NULL,
  120841. &_vq_auxt__44c9_s_p5_0,
  120842. NULL,
  120843. 0
  120844. };
  120845. static long _vq_quantlist__44c9_s_p5_1[] = {
  120846. 5,
  120847. 4,
  120848. 6,
  120849. 3,
  120850. 7,
  120851. 2,
  120852. 8,
  120853. 1,
  120854. 9,
  120855. 0,
  120856. 10,
  120857. };
  120858. static long _vq_lengthlist__44c9_s_p5_1[] = {
  120859. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7,11, 5, 5, 6, 6,
  120860. 7, 7, 7, 7, 8, 8,11, 5, 5, 6, 6, 7, 7, 7, 7, 8,
  120861. 8,11, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8,11,11,11, 6,
  120862. 6, 7, 7, 7, 8, 8, 8,11,11,11, 6, 6, 7, 7, 7, 8,
  120863. 8, 8,11,11,11, 6, 6, 7, 7, 7, 7, 8, 8,11,11,11,
  120864. 7, 7, 7, 7, 7, 7, 8, 8,11,11,11,10,10, 7, 7, 7,
  120865. 7, 8, 8,11,11,11,11,11, 7, 7, 7, 7, 7, 7,11,11,
  120866. 11,11,11, 7, 7, 7, 7, 7, 7,
  120867. };
  120868. static float _vq_quantthresh__44c9_s_p5_1[] = {
  120869. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  120870. 3.5, 4.5,
  120871. };
  120872. static long _vq_quantmap__44c9_s_p5_1[] = {
  120873. 9, 7, 5, 3, 1, 0, 2, 4,
  120874. 6, 8, 10,
  120875. };
  120876. static encode_aux_threshmatch _vq_auxt__44c9_s_p5_1 = {
  120877. _vq_quantthresh__44c9_s_p5_1,
  120878. _vq_quantmap__44c9_s_p5_1,
  120879. 11,
  120880. 11
  120881. };
  120882. static static_codebook _44c9_s_p5_1 = {
  120883. 2, 121,
  120884. _vq_lengthlist__44c9_s_p5_1,
  120885. 1, -531365888, 1611661312, 4, 0,
  120886. _vq_quantlist__44c9_s_p5_1,
  120887. NULL,
  120888. &_vq_auxt__44c9_s_p5_1,
  120889. NULL,
  120890. 0
  120891. };
  120892. static long _vq_quantlist__44c9_s_p6_0[] = {
  120893. 6,
  120894. 5,
  120895. 7,
  120896. 4,
  120897. 8,
  120898. 3,
  120899. 9,
  120900. 2,
  120901. 10,
  120902. 1,
  120903. 11,
  120904. 0,
  120905. 12,
  120906. };
  120907. static long _vq_lengthlist__44c9_s_p6_0[] = {
  120908. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 5, 4, 4,
  120909. 6, 6, 8, 8, 9, 9, 9, 9,10,10, 6, 4, 4, 6, 6, 8,
  120910. 8, 9, 9, 9, 9,10,10, 0, 6, 6, 7, 7, 8, 8, 9, 9,
  120911. 10,10,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  120912. 11, 0,10,10, 8, 8, 9, 9,10,10,11,11,12,12, 0,11,
  120913. 11, 8, 8, 9, 9,10,10,11,11,12,12, 0, 0, 0, 0, 0,
  120914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120918. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120919. };
  120920. static float _vq_quantthresh__44c9_s_p6_0[] = {
  120921. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  120922. 12.5, 17.5, 22.5, 27.5,
  120923. };
  120924. static long _vq_quantmap__44c9_s_p6_0[] = {
  120925. 11, 9, 7, 5, 3, 1, 0, 2,
  120926. 4, 6, 8, 10, 12,
  120927. };
  120928. static encode_aux_threshmatch _vq_auxt__44c9_s_p6_0 = {
  120929. _vq_quantthresh__44c9_s_p6_0,
  120930. _vq_quantmap__44c9_s_p6_0,
  120931. 13,
  120932. 13
  120933. };
  120934. static static_codebook _44c9_s_p6_0 = {
  120935. 2, 169,
  120936. _vq_lengthlist__44c9_s_p6_0,
  120937. 1, -526516224, 1616117760, 4, 0,
  120938. _vq_quantlist__44c9_s_p6_0,
  120939. NULL,
  120940. &_vq_auxt__44c9_s_p6_0,
  120941. NULL,
  120942. 0
  120943. };
  120944. static long _vq_quantlist__44c9_s_p6_1[] = {
  120945. 2,
  120946. 1,
  120947. 3,
  120948. 0,
  120949. 4,
  120950. };
  120951. static long _vq_lengthlist__44c9_s_p6_1[] = {
  120952. 4, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5,
  120953. 5, 5, 5, 5, 5, 5, 5, 5, 5,
  120954. };
  120955. static float _vq_quantthresh__44c9_s_p6_1[] = {
  120956. -1.5, -0.5, 0.5, 1.5,
  120957. };
  120958. static long _vq_quantmap__44c9_s_p6_1[] = {
  120959. 3, 1, 0, 2, 4,
  120960. };
  120961. static encode_aux_threshmatch _vq_auxt__44c9_s_p6_1 = {
  120962. _vq_quantthresh__44c9_s_p6_1,
  120963. _vq_quantmap__44c9_s_p6_1,
  120964. 5,
  120965. 5
  120966. };
  120967. static static_codebook _44c9_s_p6_1 = {
  120968. 2, 25,
  120969. _vq_lengthlist__44c9_s_p6_1,
  120970. 1, -533725184, 1611661312, 3, 0,
  120971. _vq_quantlist__44c9_s_p6_1,
  120972. NULL,
  120973. &_vq_auxt__44c9_s_p6_1,
  120974. NULL,
  120975. 0
  120976. };
  120977. static long _vq_quantlist__44c9_s_p7_0[] = {
  120978. 6,
  120979. 5,
  120980. 7,
  120981. 4,
  120982. 8,
  120983. 3,
  120984. 9,
  120985. 2,
  120986. 10,
  120987. 1,
  120988. 11,
  120989. 0,
  120990. 12,
  120991. };
  120992. static long _vq_lengthlist__44c9_s_p7_0[] = {
  120993. 2, 4, 4, 6, 6, 7, 7, 8, 8,10,10,11,11, 6, 4, 4,
  120994. 6, 6, 8, 8, 9, 9,10,10,12,12, 6, 4, 5, 6, 6, 8,
  120995. 8, 9, 9,10,10,12,12,20, 6, 6, 6, 6, 8, 8, 9,10,
  120996. 11,11,12,12,20, 6, 6, 6, 6, 8, 8,10,10,11,11,12,
  120997. 12,20,10,10, 7, 7, 9, 9,10,10,11,11,12,12,20,11,
  120998. 11, 7, 7, 9, 9,10,10,11,11,12,12,20,20,20, 9, 9,
  120999. 9, 9,11,11,12,12,13,13,20,20,20, 9, 9, 9, 9,11,
  121000. 11,12,12,13,13,20,20,20,13,13,10,10,11,11,12,13,
  121001. 13,13,20,20,20,13,13,10,10,11,11,12,13,13,13,20,
  121002. 20,20,20,19,12,12,12,12,13,13,14,15,19,19,19,19,
  121003. 19,12,12,12,12,13,13,14,14,
  121004. };
  121005. static float _vq_quantthresh__44c9_s_p7_0[] = {
  121006. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  121007. 27.5, 38.5, 49.5, 60.5,
  121008. };
  121009. static long _vq_quantmap__44c9_s_p7_0[] = {
  121010. 11, 9, 7, 5, 3, 1, 0, 2,
  121011. 4, 6, 8, 10, 12,
  121012. };
  121013. static encode_aux_threshmatch _vq_auxt__44c9_s_p7_0 = {
  121014. _vq_quantthresh__44c9_s_p7_0,
  121015. _vq_quantmap__44c9_s_p7_0,
  121016. 13,
  121017. 13
  121018. };
  121019. static static_codebook _44c9_s_p7_0 = {
  121020. 2, 169,
  121021. _vq_lengthlist__44c9_s_p7_0,
  121022. 1, -523206656, 1618345984, 4, 0,
  121023. _vq_quantlist__44c9_s_p7_0,
  121024. NULL,
  121025. &_vq_auxt__44c9_s_p7_0,
  121026. NULL,
  121027. 0
  121028. };
  121029. static long _vq_quantlist__44c9_s_p7_1[] = {
  121030. 5,
  121031. 4,
  121032. 6,
  121033. 3,
  121034. 7,
  121035. 2,
  121036. 8,
  121037. 1,
  121038. 9,
  121039. 0,
  121040. 10,
  121041. };
  121042. static long _vq_lengthlist__44c9_s_p7_1[] = {
  121043. 5, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6,
  121044. 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  121045. 7, 8, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 6,
  121046. 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7,
  121047. 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  121048. 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  121049. 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 8, 8,
  121050. 8, 8, 8, 7, 7, 7, 7, 7, 7,
  121051. };
  121052. static float _vq_quantthresh__44c9_s_p7_1[] = {
  121053. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  121054. 3.5, 4.5,
  121055. };
  121056. static long _vq_quantmap__44c9_s_p7_1[] = {
  121057. 9, 7, 5, 3, 1, 0, 2, 4,
  121058. 6, 8, 10,
  121059. };
  121060. static encode_aux_threshmatch _vq_auxt__44c9_s_p7_1 = {
  121061. _vq_quantthresh__44c9_s_p7_1,
  121062. _vq_quantmap__44c9_s_p7_1,
  121063. 11,
  121064. 11
  121065. };
  121066. static static_codebook _44c9_s_p7_1 = {
  121067. 2, 121,
  121068. _vq_lengthlist__44c9_s_p7_1,
  121069. 1, -531365888, 1611661312, 4, 0,
  121070. _vq_quantlist__44c9_s_p7_1,
  121071. NULL,
  121072. &_vq_auxt__44c9_s_p7_1,
  121073. NULL,
  121074. 0
  121075. };
  121076. static long _vq_quantlist__44c9_s_p8_0[] = {
  121077. 7,
  121078. 6,
  121079. 8,
  121080. 5,
  121081. 9,
  121082. 4,
  121083. 10,
  121084. 3,
  121085. 11,
  121086. 2,
  121087. 12,
  121088. 1,
  121089. 13,
  121090. 0,
  121091. 14,
  121092. };
  121093. static long _vq_lengthlist__44c9_s_p8_0[] = {
  121094. 1, 4, 4, 7, 6, 8, 8, 8, 8, 9, 9,10,10,11,10, 6,
  121095. 5, 5, 7, 7, 9, 9, 8, 9,10,10,11,11,12,12, 6, 5,
  121096. 5, 7, 7, 9, 9, 9, 9,10,10,11,11,12,12,21, 7, 8,
  121097. 8, 8, 9, 9, 9, 9,10,10,11,11,12,12,21, 8, 8, 8,
  121098. 8, 9, 9, 9, 9,10,10,11,11,12,12,21,11,12, 9, 9,
  121099. 10,10,10,10,10,11,11,12,12,12,21,12,12, 9, 8,10,
  121100. 10,10,10,11,11,12,12,13,13,21,21,21, 9, 9, 9, 9,
  121101. 11,11,11,11,12,12,12,13,21,20,20, 9, 9, 9, 9,10,
  121102. 11,11,11,12,12,13,13,20,20,20,13,13,10,10,11,11,
  121103. 12,12,13,13,13,13,20,20,20,13,13,10,10,11,11,12,
  121104. 12,13,13,13,13,20,20,20,20,20,12,12,12,12,12,12,
  121105. 13,13,14,14,20,20,20,20,20,12,12,12,11,13,12,13,
  121106. 13,14,14,20,20,20,20,20,15,16,13,12,13,13,14,13,
  121107. 14,14,20,20,20,20,20,16,15,12,12,13,12,14,13,14,
  121108. 14,
  121109. };
  121110. static float _vq_quantthresh__44c9_s_p8_0[] = {
  121111. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  121112. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  121113. };
  121114. static long _vq_quantmap__44c9_s_p8_0[] = {
  121115. 13, 11, 9, 7, 5, 3, 1, 0,
  121116. 2, 4, 6, 8, 10, 12, 14,
  121117. };
  121118. static encode_aux_threshmatch _vq_auxt__44c9_s_p8_0 = {
  121119. _vq_quantthresh__44c9_s_p8_0,
  121120. _vq_quantmap__44c9_s_p8_0,
  121121. 15,
  121122. 15
  121123. };
  121124. static static_codebook _44c9_s_p8_0 = {
  121125. 2, 225,
  121126. _vq_lengthlist__44c9_s_p8_0,
  121127. 1, -520986624, 1620377600, 4, 0,
  121128. _vq_quantlist__44c9_s_p8_0,
  121129. NULL,
  121130. &_vq_auxt__44c9_s_p8_0,
  121131. NULL,
  121132. 0
  121133. };
  121134. static long _vq_quantlist__44c9_s_p8_1[] = {
  121135. 10,
  121136. 9,
  121137. 11,
  121138. 8,
  121139. 12,
  121140. 7,
  121141. 13,
  121142. 6,
  121143. 14,
  121144. 5,
  121145. 15,
  121146. 4,
  121147. 16,
  121148. 3,
  121149. 17,
  121150. 2,
  121151. 18,
  121152. 1,
  121153. 19,
  121154. 0,
  121155. 20,
  121156. };
  121157. static long _vq_lengthlist__44c9_s_p8_1[] = {
  121158. 4, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  121159. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  121160. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  121161. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,
  121162. 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121163. 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  121164. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8,
  121165. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  121166. 10, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121167. 9, 9, 9,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121168. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9,
  121169. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  121170. 10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121171. 9, 9,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121172. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9, 9,
  121173. 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,10,10,10,10,
  121174. 10,10,10, 9, 9, 9, 9, 9, 9,10, 9, 9, 9, 9, 9, 9,
  121175. 9,10,10,10,10,10,10,10, 9, 9, 9,10,10,10,10,10,
  121176. 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10, 9, 9,10,
  121177. 9,10, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,
  121178. 10,10,10,10, 9, 9,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  121179. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  121180. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  121181. 10,10, 9, 9,10, 9, 9, 9, 9, 9,10,10,10,10,10,10,
  121182. 10,10,10,10,10, 9, 9,10,10, 9, 9,10, 9, 9, 9,10,
  121183. 10,10,10,10,10,10,10,10,10,10, 9, 9,10, 9, 9, 9,
  121184. 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10, 9,
  121185. 9, 9, 9,10, 9, 9, 9, 9, 9,
  121186. };
  121187. static float _vq_quantthresh__44c9_s_p8_1[] = {
  121188. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  121189. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  121190. 6.5, 7.5, 8.5, 9.5,
  121191. };
  121192. static long _vq_quantmap__44c9_s_p8_1[] = {
  121193. 19, 17, 15, 13, 11, 9, 7, 5,
  121194. 3, 1, 0, 2, 4, 6, 8, 10,
  121195. 12, 14, 16, 18, 20,
  121196. };
  121197. static encode_aux_threshmatch _vq_auxt__44c9_s_p8_1 = {
  121198. _vq_quantthresh__44c9_s_p8_1,
  121199. _vq_quantmap__44c9_s_p8_1,
  121200. 21,
  121201. 21
  121202. };
  121203. static static_codebook _44c9_s_p8_1 = {
  121204. 2, 441,
  121205. _vq_lengthlist__44c9_s_p8_1,
  121206. 1, -529268736, 1611661312, 5, 0,
  121207. _vq_quantlist__44c9_s_p8_1,
  121208. NULL,
  121209. &_vq_auxt__44c9_s_p8_1,
  121210. NULL,
  121211. 0
  121212. };
  121213. static long _vq_quantlist__44c9_s_p9_0[] = {
  121214. 9,
  121215. 8,
  121216. 10,
  121217. 7,
  121218. 11,
  121219. 6,
  121220. 12,
  121221. 5,
  121222. 13,
  121223. 4,
  121224. 14,
  121225. 3,
  121226. 15,
  121227. 2,
  121228. 16,
  121229. 1,
  121230. 17,
  121231. 0,
  121232. 18,
  121233. };
  121234. static long _vq_lengthlist__44c9_s_p9_0[] = {
  121235. 1, 4, 3,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121236. 12,12,12, 4, 5, 6,12,12,12,12,12,12,12,12,12,12,
  121237. 12,12,12,12,12,12, 4, 6, 6,12,12,12,12,12,12,12,
  121238. 12,12,12,12,12,12,12,12,12,12,12,11,12,12,12,12,
  121239. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121240. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121241. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121242. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121243. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121244. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121245. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121246. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121247. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121248. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121249. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121250. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121251. 12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,
  121252. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121253. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121254. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121255. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121256. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121257. 11,11,11,11,11,11,11,11,11,
  121258. };
  121259. static float _vq_quantthresh__44c9_s_p9_0[] = {
  121260. -7913.5, -6982.5, -6051.5, -5120.5, -4189.5, -3258.5, -2327.5, -1396.5,
  121261. -465.5, 465.5, 1396.5, 2327.5, 3258.5, 4189.5, 5120.5, 6051.5,
  121262. 6982.5, 7913.5,
  121263. };
  121264. static long _vq_quantmap__44c9_s_p9_0[] = {
  121265. 17, 15, 13, 11, 9, 7, 5, 3,
  121266. 1, 0, 2, 4, 6, 8, 10, 12,
  121267. 14, 16, 18,
  121268. };
  121269. static encode_aux_threshmatch _vq_auxt__44c9_s_p9_0 = {
  121270. _vq_quantthresh__44c9_s_p9_0,
  121271. _vq_quantmap__44c9_s_p9_0,
  121272. 19,
  121273. 19
  121274. };
  121275. static static_codebook _44c9_s_p9_0 = {
  121276. 2, 361,
  121277. _vq_lengthlist__44c9_s_p9_0,
  121278. 1, -508535424, 1631393792, 5, 0,
  121279. _vq_quantlist__44c9_s_p9_0,
  121280. NULL,
  121281. &_vq_auxt__44c9_s_p9_0,
  121282. NULL,
  121283. 0
  121284. };
  121285. static long _vq_quantlist__44c9_s_p9_1[] = {
  121286. 9,
  121287. 8,
  121288. 10,
  121289. 7,
  121290. 11,
  121291. 6,
  121292. 12,
  121293. 5,
  121294. 13,
  121295. 4,
  121296. 14,
  121297. 3,
  121298. 15,
  121299. 2,
  121300. 16,
  121301. 1,
  121302. 17,
  121303. 0,
  121304. 18,
  121305. };
  121306. static long _vq_lengthlist__44c9_s_p9_1[] = {
  121307. 1, 4, 4, 7, 7, 7, 7, 8, 7, 9, 8, 9, 9,10,10,11,
  121308. 11,11,11, 6, 5, 5, 8, 8, 9, 9, 9, 8,10, 9,11,10,
  121309. 12,12,13,12,13,13, 5, 5, 5, 8, 8, 9, 9, 9, 9,10,
  121310. 10,11,11,12,12,13,12,13,13,17, 8, 8, 9, 9, 9, 9,
  121311. 9, 9,10,10,12,11,13,12,13,13,13,13,18, 8, 8, 9,
  121312. 9, 9, 9, 9, 9,11,11,12,12,13,13,13,13,13,13,17,
  121313. 13,12, 9, 9,10,10,10,10,11,11,12,12,12,13,13,13,
  121314. 14,14,18,13,12, 9, 9,10,10,10,10,11,11,12,12,13,
  121315. 13,13,14,14,14,17,18,18,10,10,10,10,11,11,11,12,
  121316. 12,12,14,13,14,13,13,14,18,18,18,10, 9,10, 9,11,
  121317. 11,12,12,12,12,13,13,15,14,14,14,18,18,16,13,14,
  121318. 10,11,11,11,12,13,13,13,13,14,13,13,14,14,18,18,
  121319. 18,14,12,11, 9,11,10,13,12,13,13,13,14,14,14,13,
  121320. 14,18,18,17,18,18,11,12,12,12,13,13,14,13,14,14,
  121321. 13,14,14,14,18,18,18,18,17,12,10,12, 9,13,11,13,
  121322. 14,14,14,14,14,15,14,18,18,17,17,18,14,15,12,13,
  121323. 13,13,14,13,14,14,15,14,15,14,18,17,18,18,18,15,
  121324. 15,12,10,14,10,14,14,13,13,14,14,14,14,18,16,18,
  121325. 18,18,18,17,14,14,13,14,14,13,13,14,14,14,15,15,
  121326. 18,18,18,18,17,17,17,14,14,14,12,14,13,14,14,15,
  121327. 14,15,14,18,18,18,18,18,18,18,17,16,13,13,13,14,
  121328. 14,14,14,15,16,15,18,18,18,18,18,18,18,17,17,13,
  121329. 13,13,13,14,13,14,15,15,15,
  121330. };
  121331. static float _vq_quantthresh__44c9_s_p9_1[] = {
  121332. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  121333. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  121334. 367.5, 416.5,
  121335. };
  121336. static long _vq_quantmap__44c9_s_p9_1[] = {
  121337. 17, 15, 13, 11, 9, 7, 5, 3,
  121338. 1, 0, 2, 4, 6, 8, 10, 12,
  121339. 14, 16, 18,
  121340. };
  121341. static encode_aux_threshmatch _vq_auxt__44c9_s_p9_1 = {
  121342. _vq_quantthresh__44c9_s_p9_1,
  121343. _vq_quantmap__44c9_s_p9_1,
  121344. 19,
  121345. 19
  121346. };
  121347. static static_codebook _44c9_s_p9_1 = {
  121348. 2, 361,
  121349. _vq_lengthlist__44c9_s_p9_1,
  121350. 1, -518287360, 1622704128, 5, 0,
  121351. _vq_quantlist__44c9_s_p9_1,
  121352. NULL,
  121353. &_vq_auxt__44c9_s_p9_1,
  121354. NULL,
  121355. 0
  121356. };
  121357. static long _vq_quantlist__44c9_s_p9_2[] = {
  121358. 24,
  121359. 23,
  121360. 25,
  121361. 22,
  121362. 26,
  121363. 21,
  121364. 27,
  121365. 20,
  121366. 28,
  121367. 19,
  121368. 29,
  121369. 18,
  121370. 30,
  121371. 17,
  121372. 31,
  121373. 16,
  121374. 32,
  121375. 15,
  121376. 33,
  121377. 14,
  121378. 34,
  121379. 13,
  121380. 35,
  121381. 12,
  121382. 36,
  121383. 11,
  121384. 37,
  121385. 10,
  121386. 38,
  121387. 9,
  121388. 39,
  121389. 8,
  121390. 40,
  121391. 7,
  121392. 41,
  121393. 6,
  121394. 42,
  121395. 5,
  121396. 43,
  121397. 4,
  121398. 44,
  121399. 3,
  121400. 45,
  121401. 2,
  121402. 46,
  121403. 1,
  121404. 47,
  121405. 0,
  121406. 48,
  121407. };
  121408. static long _vq_lengthlist__44c9_s_p9_2[] = {
  121409. 2, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
  121410. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  121411. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  121412. 7,
  121413. };
  121414. static float _vq_quantthresh__44c9_s_p9_2[] = {
  121415. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  121416. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  121417. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  121418. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  121419. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  121420. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  121421. };
  121422. static long _vq_quantmap__44c9_s_p9_2[] = {
  121423. 47, 45, 43, 41, 39, 37, 35, 33,
  121424. 31, 29, 27, 25, 23, 21, 19, 17,
  121425. 15, 13, 11, 9, 7, 5, 3, 1,
  121426. 0, 2, 4, 6, 8, 10, 12, 14,
  121427. 16, 18, 20, 22, 24, 26, 28, 30,
  121428. 32, 34, 36, 38, 40, 42, 44, 46,
  121429. 48,
  121430. };
  121431. static encode_aux_threshmatch _vq_auxt__44c9_s_p9_2 = {
  121432. _vq_quantthresh__44c9_s_p9_2,
  121433. _vq_quantmap__44c9_s_p9_2,
  121434. 49,
  121435. 49
  121436. };
  121437. static static_codebook _44c9_s_p9_2 = {
  121438. 1, 49,
  121439. _vq_lengthlist__44c9_s_p9_2,
  121440. 1, -526909440, 1611661312, 6, 0,
  121441. _vq_quantlist__44c9_s_p9_2,
  121442. NULL,
  121443. &_vq_auxt__44c9_s_p9_2,
  121444. NULL,
  121445. 0
  121446. };
  121447. static long _huff_lengthlist__44c9_s_short[] = {
  121448. 5,13,18,16,17,17,19,18,19,19, 5, 7,10,11,12,12,
  121449. 13,16,17,18, 6, 6, 7, 7, 9, 9,10,14,17,19, 8, 7,
  121450. 6, 5, 6, 7, 9,12,19,17, 8, 7, 7, 6, 5, 6, 8,11,
  121451. 15,19, 9, 8, 7, 6, 5, 5, 6, 8,13,15,11,10, 8, 8,
  121452. 7, 5, 4, 4,10,14,12,13,11, 9, 7, 6, 4, 2, 6,12,
  121453. 18,16,16,13, 8, 7, 7, 5, 8,13,16,17,18,15,11, 9,
  121454. 9, 8,10,13,
  121455. };
  121456. static static_codebook _huff_book__44c9_s_short = {
  121457. 2, 100,
  121458. _huff_lengthlist__44c9_s_short,
  121459. 0, 0, 0, 0, 0,
  121460. NULL,
  121461. NULL,
  121462. NULL,
  121463. NULL,
  121464. 0
  121465. };
  121466. static long _huff_lengthlist__44c0_s_long[] = {
  121467. 5, 4, 8, 9, 8, 9,10,12,15, 4, 1, 5, 5, 6, 8,11,
  121468. 12,12, 8, 5, 8, 9, 9,11,13,12,12, 9, 5, 8, 5, 7,
  121469. 9,12,13,13, 8, 6, 8, 7, 7, 9,11,11,11, 9, 7, 9,
  121470. 7, 7, 7, 7,10,12,10,10,11, 9, 8, 7, 7, 9,11,11,
  121471. 12,13,12,11, 9, 8, 9,11,13,16,16,15,15,12,10,11,
  121472. 12,
  121473. };
  121474. static static_codebook _huff_book__44c0_s_long = {
  121475. 2, 81,
  121476. _huff_lengthlist__44c0_s_long,
  121477. 0, 0, 0, 0, 0,
  121478. NULL,
  121479. NULL,
  121480. NULL,
  121481. NULL,
  121482. 0
  121483. };
  121484. static long _vq_quantlist__44c0_s_p1_0[] = {
  121485. 1,
  121486. 0,
  121487. 2,
  121488. };
  121489. static long _vq_lengthlist__44c0_s_p1_0[] = {
  121490. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  121491. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121495. 0, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  121496. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121500. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  121501. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  121536. 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 7, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  121541. 0, 0, 0, 9,10,11, 0, 0, 0, 0, 0, 0, 9,11,10, 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, 7, 9, 9, 0, 0,
  121546. 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  121547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121581. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  121582. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  121587. 0, 0, 0, 0, 0, 9, 9,11, 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, 7, 9,10, 0, 0, 0, 0, 0, 0, 9,10,11,
  121592. 0, 0, 0, 0, 0, 0, 9,11,10, 0, 0, 0, 0, 0, 0, 0,
  121593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121823. 0, 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,
  121901. };
  121902. static float _vq_quantthresh__44c0_s_p1_0[] = {
  121903. -0.5, 0.5,
  121904. };
  121905. static long _vq_quantmap__44c0_s_p1_0[] = {
  121906. 1, 0, 2,
  121907. };
  121908. static encode_aux_threshmatch _vq_auxt__44c0_s_p1_0 = {
  121909. _vq_quantthresh__44c0_s_p1_0,
  121910. _vq_quantmap__44c0_s_p1_0,
  121911. 3,
  121912. 3
  121913. };
  121914. static static_codebook _44c0_s_p1_0 = {
  121915. 8, 6561,
  121916. _vq_lengthlist__44c0_s_p1_0,
  121917. 1, -535822336, 1611661312, 2, 0,
  121918. _vq_quantlist__44c0_s_p1_0,
  121919. NULL,
  121920. &_vq_auxt__44c0_s_p1_0,
  121921. NULL,
  121922. 0
  121923. };
  121924. static long _vq_quantlist__44c0_s_p2_0[] = {
  121925. 2,
  121926. 1,
  121927. 3,
  121928. 0,
  121929. 4,
  121930. };
  121931. static long _vq_lengthlist__44c0_s_p2_0[] = {
  121932. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 6, 0, 0,
  121934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121935. 0, 0, 4, 5, 6, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  121937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121938. 0, 0, 0, 0, 6, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  121939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121971. 0,
  121972. };
  121973. static float _vq_quantthresh__44c0_s_p2_0[] = {
  121974. -1.5, -0.5, 0.5, 1.5,
  121975. };
  121976. static long _vq_quantmap__44c0_s_p2_0[] = {
  121977. 3, 1, 0, 2, 4,
  121978. };
  121979. static encode_aux_threshmatch _vq_auxt__44c0_s_p2_0 = {
  121980. _vq_quantthresh__44c0_s_p2_0,
  121981. _vq_quantmap__44c0_s_p2_0,
  121982. 5,
  121983. 5
  121984. };
  121985. static static_codebook _44c0_s_p2_0 = {
  121986. 4, 625,
  121987. _vq_lengthlist__44c0_s_p2_0,
  121988. 1, -533725184, 1611661312, 3, 0,
  121989. _vq_quantlist__44c0_s_p2_0,
  121990. NULL,
  121991. &_vq_auxt__44c0_s_p2_0,
  121992. NULL,
  121993. 0
  121994. };
  121995. static long _vq_quantlist__44c0_s_p3_0[] = {
  121996. 4,
  121997. 3,
  121998. 5,
  121999. 2,
  122000. 6,
  122001. 1,
  122002. 7,
  122003. 0,
  122004. 8,
  122005. };
  122006. static long _vq_lengthlist__44c0_s_p3_0[] = {
  122007. 1, 3, 2, 8, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  122008. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  122009. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  122010. 8, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  122011. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122012. 0,
  122013. };
  122014. static float _vq_quantthresh__44c0_s_p3_0[] = {
  122015. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  122016. };
  122017. static long _vq_quantmap__44c0_s_p3_0[] = {
  122018. 7, 5, 3, 1, 0, 2, 4, 6,
  122019. 8,
  122020. };
  122021. static encode_aux_threshmatch _vq_auxt__44c0_s_p3_0 = {
  122022. _vq_quantthresh__44c0_s_p3_0,
  122023. _vq_quantmap__44c0_s_p3_0,
  122024. 9,
  122025. 9
  122026. };
  122027. static static_codebook _44c0_s_p3_0 = {
  122028. 2, 81,
  122029. _vq_lengthlist__44c0_s_p3_0,
  122030. 1, -531628032, 1611661312, 4, 0,
  122031. _vq_quantlist__44c0_s_p3_0,
  122032. NULL,
  122033. &_vq_auxt__44c0_s_p3_0,
  122034. NULL,
  122035. 0
  122036. };
  122037. static long _vq_quantlist__44c0_s_p4_0[] = {
  122038. 4,
  122039. 3,
  122040. 5,
  122041. 2,
  122042. 6,
  122043. 1,
  122044. 7,
  122045. 0,
  122046. 8,
  122047. };
  122048. static long _vq_lengthlist__44c0_s_p4_0[] = {
  122049. 1, 3, 3, 6, 6, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  122050. 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  122051. 7, 8, 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0,
  122052. 9, 9, 8, 8,10,10, 0, 0, 0, 8, 9, 8, 8,10,10, 0,
  122053. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  122054. 10,
  122055. };
  122056. static float _vq_quantthresh__44c0_s_p4_0[] = {
  122057. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  122058. };
  122059. static long _vq_quantmap__44c0_s_p4_0[] = {
  122060. 7, 5, 3, 1, 0, 2, 4, 6,
  122061. 8,
  122062. };
  122063. static encode_aux_threshmatch _vq_auxt__44c0_s_p4_0 = {
  122064. _vq_quantthresh__44c0_s_p4_0,
  122065. _vq_quantmap__44c0_s_p4_0,
  122066. 9,
  122067. 9
  122068. };
  122069. static static_codebook _44c0_s_p4_0 = {
  122070. 2, 81,
  122071. _vq_lengthlist__44c0_s_p4_0,
  122072. 1, -531628032, 1611661312, 4, 0,
  122073. _vq_quantlist__44c0_s_p4_0,
  122074. NULL,
  122075. &_vq_auxt__44c0_s_p4_0,
  122076. NULL,
  122077. 0
  122078. };
  122079. static long _vq_quantlist__44c0_s_p5_0[] = {
  122080. 8,
  122081. 7,
  122082. 9,
  122083. 6,
  122084. 10,
  122085. 5,
  122086. 11,
  122087. 4,
  122088. 12,
  122089. 3,
  122090. 13,
  122091. 2,
  122092. 14,
  122093. 1,
  122094. 15,
  122095. 0,
  122096. 16,
  122097. };
  122098. static long _vq_lengthlist__44c0_s_p5_0[] = {
  122099. 1, 4, 3, 6, 6, 8, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  122100. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9, 9,10,10,10,
  122101. 11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  122102. 10,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  122103. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  122104. 10,11,11,11,11, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,10,
  122105. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,
  122106. 10,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  122107. 10,10,11,11,11,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  122108. 10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,
  122109. 10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  122110. 9,10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  122111. 10,10,11,11,11,11,11,12,12,12,13,13, 0, 0, 0, 0,
  122112. 0, 0, 0,11,10,11,11,11,11,12,12,13,13, 0, 0, 0,
  122113. 0, 0, 0, 0,11,11,12,11,12,12,12,12,13,13, 0, 0,
  122114. 0, 0, 0, 0, 0,11,11,11,12,12,12,12,13,13,13, 0,
  122115. 0, 0, 0, 0, 0, 0,12,12,12,12,12,13,13,13,14,14,
  122116. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  122117. 14,
  122118. };
  122119. static float _vq_quantthresh__44c0_s_p5_0[] = {
  122120. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  122121. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  122122. };
  122123. static long _vq_quantmap__44c0_s_p5_0[] = {
  122124. 15, 13, 11, 9, 7, 5, 3, 1,
  122125. 0, 2, 4, 6, 8, 10, 12, 14,
  122126. 16,
  122127. };
  122128. static encode_aux_threshmatch _vq_auxt__44c0_s_p5_0 = {
  122129. _vq_quantthresh__44c0_s_p5_0,
  122130. _vq_quantmap__44c0_s_p5_0,
  122131. 17,
  122132. 17
  122133. };
  122134. static static_codebook _44c0_s_p5_0 = {
  122135. 2, 289,
  122136. _vq_lengthlist__44c0_s_p5_0,
  122137. 1, -529530880, 1611661312, 5, 0,
  122138. _vq_quantlist__44c0_s_p5_0,
  122139. NULL,
  122140. &_vq_auxt__44c0_s_p5_0,
  122141. NULL,
  122142. 0
  122143. };
  122144. static long _vq_quantlist__44c0_s_p6_0[] = {
  122145. 1,
  122146. 0,
  122147. 2,
  122148. };
  122149. static long _vq_lengthlist__44c0_s_p6_0[] = {
  122150. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,10,
  122151. 9, 9, 4, 6, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  122152. 11,12,10,11, 6, 9, 9,11,10,11,11,10,10, 6, 9, 9,
  122153. 11,10,11,11,10,10, 7,11,10,12,11,11,11,11,11, 7,
  122154. 9, 9,10,10,10,11,11,10, 6, 9, 9,11,10,10,11,10,
  122155. 10,
  122156. };
  122157. static float _vq_quantthresh__44c0_s_p6_0[] = {
  122158. -5.5, 5.5,
  122159. };
  122160. static long _vq_quantmap__44c0_s_p6_0[] = {
  122161. 1, 0, 2,
  122162. };
  122163. static encode_aux_threshmatch _vq_auxt__44c0_s_p6_0 = {
  122164. _vq_quantthresh__44c0_s_p6_0,
  122165. _vq_quantmap__44c0_s_p6_0,
  122166. 3,
  122167. 3
  122168. };
  122169. static static_codebook _44c0_s_p6_0 = {
  122170. 4, 81,
  122171. _vq_lengthlist__44c0_s_p6_0,
  122172. 1, -529137664, 1618345984, 2, 0,
  122173. _vq_quantlist__44c0_s_p6_0,
  122174. NULL,
  122175. &_vq_auxt__44c0_s_p6_0,
  122176. NULL,
  122177. 0
  122178. };
  122179. static long _vq_quantlist__44c0_s_p6_1[] = {
  122180. 5,
  122181. 4,
  122182. 6,
  122183. 3,
  122184. 7,
  122185. 2,
  122186. 8,
  122187. 1,
  122188. 9,
  122189. 0,
  122190. 10,
  122191. };
  122192. static long _vq_lengthlist__44c0_s_p6_1[] = {
  122193. 2, 3, 3, 6, 6, 7, 7, 7, 7, 7, 8,10,10,10, 6, 6,
  122194. 7, 7, 8, 8, 8, 8,10,10,10, 6, 6, 7, 7, 8, 8, 8,
  122195. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  122196. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 7, 8, 8, 8, 8,
  122197. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  122198. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  122199. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  122200. 10,10,10, 8, 8, 8, 8, 8, 8,
  122201. };
  122202. static float _vq_quantthresh__44c0_s_p6_1[] = {
  122203. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  122204. 3.5, 4.5,
  122205. };
  122206. static long _vq_quantmap__44c0_s_p6_1[] = {
  122207. 9, 7, 5, 3, 1, 0, 2, 4,
  122208. 6, 8, 10,
  122209. };
  122210. static encode_aux_threshmatch _vq_auxt__44c0_s_p6_1 = {
  122211. _vq_quantthresh__44c0_s_p6_1,
  122212. _vq_quantmap__44c0_s_p6_1,
  122213. 11,
  122214. 11
  122215. };
  122216. static static_codebook _44c0_s_p6_1 = {
  122217. 2, 121,
  122218. _vq_lengthlist__44c0_s_p6_1,
  122219. 1, -531365888, 1611661312, 4, 0,
  122220. _vq_quantlist__44c0_s_p6_1,
  122221. NULL,
  122222. &_vq_auxt__44c0_s_p6_1,
  122223. NULL,
  122224. 0
  122225. };
  122226. static long _vq_quantlist__44c0_s_p7_0[] = {
  122227. 6,
  122228. 5,
  122229. 7,
  122230. 4,
  122231. 8,
  122232. 3,
  122233. 9,
  122234. 2,
  122235. 10,
  122236. 1,
  122237. 11,
  122238. 0,
  122239. 12,
  122240. };
  122241. static long _vq_lengthlist__44c0_s_p7_0[] = {
  122242. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 5, 5,
  122243. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 6, 7, 7, 8,
  122244. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  122245. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  122246. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  122247. 13, 9, 9, 9, 9,10,10,11,11,11,12, 0, 0, 0,10,10,
  122248. 10,10,11,11,11,11,12,12, 0, 0, 0,10,10, 9, 9,11,
  122249. 11,11,12,12,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  122250. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  122251. 0, 0, 0, 0,11,11,11,11,13,12,13,13, 0, 0, 0, 0,
  122252. 0,12,12,11,11,12,12,13,13,
  122253. };
  122254. static float _vq_quantthresh__44c0_s_p7_0[] = {
  122255. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  122256. 12.5, 17.5, 22.5, 27.5,
  122257. };
  122258. static long _vq_quantmap__44c0_s_p7_0[] = {
  122259. 11, 9, 7, 5, 3, 1, 0, 2,
  122260. 4, 6, 8, 10, 12,
  122261. };
  122262. static encode_aux_threshmatch _vq_auxt__44c0_s_p7_0 = {
  122263. _vq_quantthresh__44c0_s_p7_0,
  122264. _vq_quantmap__44c0_s_p7_0,
  122265. 13,
  122266. 13
  122267. };
  122268. static static_codebook _44c0_s_p7_0 = {
  122269. 2, 169,
  122270. _vq_lengthlist__44c0_s_p7_0,
  122271. 1, -526516224, 1616117760, 4, 0,
  122272. _vq_quantlist__44c0_s_p7_0,
  122273. NULL,
  122274. &_vq_auxt__44c0_s_p7_0,
  122275. NULL,
  122276. 0
  122277. };
  122278. static long _vq_quantlist__44c0_s_p7_1[] = {
  122279. 2,
  122280. 1,
  122281. 3,
  122282. 0,
  122283. 4,
  122284. };
  122285. static long _vq_lengthlist__44c0_s_p7_1[] = {
  122286. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  122287. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  122288. };
  122289. static float _vq_quantthresh__44c0_s_p7_1[] = {
  122290. -1.5, -0.5, 0.5, 1.5,
  122291. };
  122292. static long _vq_quantmap__44c0_s_p7_1[] = {
  122293. 3, 1, 0, 2, 4,
  122294. };
  122295. static encode_aux_threshmatch _vq_auxt__44c0_s_p7_1 = {
  122296. _vq_quantthresh__44c0_s_p7_1,
  122297. _vq_quantmap__44c0_s_p7_1,
  122298. 5,
  122299. 5
  122300. };
  122301. static static_codebook _44c0_s_p7_1 = {
  122302. 2, 25,
  122303. _vq_lengthlist__44c0_s_p7_1,
  122304. 1, -533725184, 1611661312, 3, 0,
  122305. _vq_quantlist__44c0_s_p7_1,
  122306. NULL,
  122307. &_vq_auxt__44c0_s_p7_1,
  122308. NULL,
  122309. 0
  122310. };
  122311. static long _vq_quantlist__44c0_s_p8_0[] = {
  122312. 2,
  122313. 1,
  122314. 3,
  122315. 0,
  122316. 4,
  122317. };
  122318. static long _vq_lengthlist__44c0_s_p8_0[] = {
  122319. 1, 5, 5,10,10, 6, 9, 8,10,10, 6,10, 9,10,10,10,
  122320. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122321. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122322. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122323. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122324. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122325. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122326. 10,10,10,10,10,10,10,10,10,10,10,10,10, 8,10,10,
  122327. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122328. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122329. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122330. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122331. 10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,
  122332. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122333. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122334. 11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,
  122335. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122336. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122337. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122338. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122339. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122340. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122341. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122342. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122343. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122344. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122345. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122346. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122347. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122348. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122349. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122350. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122351. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122352. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122353. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122354. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122355. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122356. 11,11,11,11,11,11,11,11,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,
  122359. };
  122360. static float _vq_quantthresh__44c0_s_p8_0[] = {
  122361. -331.5, -110.5, 110.5, 331.5,
  122362. };
  122363. static long _vq_quantmap__44c0_s_p8_0[] = {
  122364. 3, 1, 0, 2, 4,
  122365. };
  122366. static encode_aux_threshmatch _vq_auxt__44c0_s_p8_0 = {
  122367. _vq_quantthresh__44c0_s_p8_0,
  122368. _vq_quantmap__44c0_s_p8_0,
  122369. 5,
  122370. 5
  122371. };
  122372. static static_codebook _44c0_s_p8_0 = {
  122373. 4, 625,
  122374. _vq_lengthlist__44c0_s_p8_0,
  122375. 1, -518283264, 1627103232, 3, 0,
  122376. _vq_quantlist__44c0_s_p8_0,
  122377. NULL,
  122378. &_vq_auxt__44c0_s_p8_0,
  122379. NULL,
  122380. 0
  122381. };
  122382. static long _vq_quantlist__44c0_s_p8_1[] = {
  122383. 6,
  122384. 5,
  122385. 7,
  122386. 4,
  122387. 8,
  122388. 3,
  122389. 9,
  122390. 2,
  122391. 10,
  122392. 1,
  122393. 11,
  122394. 0,
  122395. 12,
  122396. };
  122397. static long _vq_lengthlist__44c0_s_p8_1[] = {
  122398. 1, 4, 4, 6, 6, 7, 7, 9, 9,11,12,13,12, 6, 5, 5,
  122399. 7, 7, 8, 8,10, 9,12,12,12,12, 6, 5, 5, 7, 7, 8,
  122400. 8,10, 9,12,11,11,13,16, 7, 7, 8, 8, 9, 9,10,10,
  122401. 12,12,13,12,16, 7, 7, 8, 7, 9, 9,10,10,11,12,12,
  122402. 13,16,10,10, 8, 8,10,10,11,12,12,12,13,13,16,11,
  122403. 10, 8, 7,11,10,11,11,12,11,13,13,16,16,16,10,10,
  122404. 10,10,11,11,13,12,13,13,16,16,16,11, 9,11, 9,15,
  122405. 13,12,13,13,13,16,16,16,15,13,11,11,12,13,12,12,
  122406. 14,13,16,16,16,14,13,11,11,13,12,14,13,13,13,16,
  122407. 16,16,16,16,13,13,13,12,14,13,14,14,16,16,16,16,
  122408. 16,13,13,12,12,14,14,15,13,
  122409. };
  122410. static float _vq_quantthresh__44c0_s_p8_1[] = {
  122411. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  122412. 42.5, 59.5, 76.5, 93.5,
  122413. };
  122414. static long _vq_quantmap__44c0_s_p8_1[] = {
  122415. 11, 9, 7, 5, 3, 1, 0, 2,
  122416. 4, 6, 8, 10, 12,
  122417. };
  122418. static encode_aux_threshmatch _vq_auxt__44c0_s_p8_1 = {
  122419. _vq_quantthresh__44c0_s_p8_1,
  122420. _vq_quantmap__44c0_s_p8_1,
  122421. 13,
  122422. 13
  122423. };
  122424. static static_codebook _44c0_s_p8_1 = {
  122425. 2, 169,
  122426. _vq_lengthlist__44c0_s_p8_1,
  122427. 1, -522616832, 1620115456, 4, 0,
  122428. _vq_quantlist__44c0_s_p8_1,
  122429. NULL,
  122430. &_vq_auxt__44c0_s_p8_1,
  122431. NULL,
  122432. 0
  122433. };
  122434. static long _vq_quantlist__44c0_s_p8_2[] = {
  122435. 8,
  122436. 7,
  122437. 9,
  122438. 6,
  122439. 10,
  122440. 5,
  122441. 11,
  122442. 4,
  122443. 12,
  122444. 3,
  122445. 13,
  122446. 2,
  122447. 14,
  122448. 1,
  122449. 15,
  122450. 0,
  122451. 16,
  122452. };
  122453. static long _vq_lengthlist__44c0_s_p8_2[] = {
  122454. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  122455. 8,10,10,10, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  122456. 9, 9,10,10,10, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  122457. 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  122458. 9,10, 9, 9,10,10,10, 7, 7, 8, 8, 9, 8, 9, 9, 9,
  122459. 9,10, 9, 9,10,10,10,10, 8, 8, 8, 8, 9, 8, 9, 9,
  122460. 9, 9, 9,10, 9,10,10,10,10, 7, 7, 8, 8, 9, 9, 9,
  122461. 9, 9, 9,10, 9,10,10,10,10,10, 8, 8, 8, 9, 9, 9,
  122462. 9, 9, 9, 9,10,10,10, 9,11,10,10,10,10, 8, 8, 9,
  122463. 9, 9, 9, 9,10, 9, 9, 9,10,10,10,10,11,11, 9, 9,
  122464. 9, 9, 9, 9, 9, 9,10, 9, 9,10,11,10,10,11,11, 9,
  122465. 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,11,10,11,11,
  122466. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,10,10,11,
  122467. 11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  122468. 11,11,11,11, 9,10, 9,10, 9, 9, 9, 9,10, 9,10,11,
  122469. 10,11,10,10,10,10,10, 9, 9, 9,10, 9, 9, 9,10,11,
  122470. 11,10,11,11,10,11,10,10,10, 9, 9, 9, 9,10, 9, 9,
  122471. 10,11,10,11,11,11,11,10,11,10,10, 9,10, 9, 9, 9,
  122472. 10,
  122473. };
  122474. static float _vq_quantthresh__44c0_s_p8_2[] = {
  122475. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  122476. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  122477. };
  122478. static long _vq_quantmap__44c0_s_p8_2[] = {
  122479. 15, 13, 11, 9, 7, 5, 3, 1,
  122480. 0, 2, 4, 6, 8, 10, 12, 14,
  122481. 16,
  122482. };
  122483. static encode_aux_threshmatch _vq_auxt__44c0_s_p8_2 = {
  122484. _vq_quantthresh__44c0_s_p8_2,
  122485. _vq_quantmap__44c0_s_p8_2,
  122486. 17,
  122487. 17
  122488. };
  122489. static static_codebook _44c0_s_p8_2 = {
  122490. 2, 289,
  122491. _vq_lengthlist__44c0_s_p8_2,
  122492. 1, -529530880, 1611661312, 5, 0,
  122493. _vq_quantlist__44c0_s_p8_2,
  122494. NULL,
  122495. &_vq_auxt__44c0_s_p8_2,
  122496. NULL,
  122497. 0
  122498. };
  122499. static long _huff_lengthlist__44c0_s_short[] = {
  122500. 9, 8,12,11,12,13,14,14,16, 6, 1, 5, 6, 6, 9,12,
  122501. 14,17, 9, 4, 5, 9, 7, 9,13,15,16, 8, 5, 8, 6, 8,
  122502. 10,13,17,17, 9, 6, 7, 7, 8, 9,13,15,17,11, 8, 9,
  122503. 9, 9,10,12,16,16,13, 7, 8, 7, 7, 9,12,14,15,13,
  122504. 6, 7, 5, 5, 7,10,13,13,14, 7, 8, 5, 6, 7, 9,10,
  122505. 12,
  122506. };
  122507. static static_codebook _huff_book__44c0_s_short = {
  122508. 2, 81,
  122509. _huff_lengthlist__44c0_s_short,
  122510. 0, 0, 0, 0, 0,
  122511. NULL,
  122512. NULL,
  122513. NULL,
  122514. NULL,
  122515. 0
  122516. };
  122517. static long _huff_lengthlist__44c0_sm_long[] = {
  122518. 5, 4, 9,10, 9,10,11,12,13, 4, 1, 5, 7, 7, 9,11,
  122519. 12,14, 8, 5, 7, 9, 8,10,13,13,13,10, 7, 9, 4, 6,
  122520. 7,10,12,14, 9, 6, 7, 6, 6, 7,10,12,12, 9, 8, 9,
  122521. 7, 6, 7, 8,11,12,11,11,11, 9, 8, 7, 8,10,12,12,
  122522. 13,14,12,11, 9, 9, 9,12,12,17,17,15,16,12,10,11,
  122523. 13,
  122524. };
  122525. static static_codebook _huff_book__44c0_sm_long = {
  122526. 2, 81,
  122527. _huff_lengthlist__44c0_sm_long,
  122528. 0, 0, 0, 0, 0,
  122529. NULL,
  122530. NULL,
  122531. NULL,
  122532. NULL,
  122533. 0
  122534. };
  122535. static long _vq_quantlist__44c0_sm_p1_0[] = {
  122536. 1,
  122537. 0,
  122538. 2,
  122539. };
  122540. static long _vq_lengthlist__44c0_sm_p1_0[] = {
  122541. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  122542. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122546. 0, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  122547. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122551. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  122552. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 0,
  122587. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  122592. 0, 0, 0, 9,10,10, 0, 0, 0, 0, 0, 0, 9,10,10, 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, 7, 9, 9, 0, 0,
  122597. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  122598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122632. 0, 0, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  122633. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  122638. 0, 0, 0, 0, 0, 9, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  122643. 0, 0, 0, 0, 0, 0, 9,10,10, 0, 0, 0, 0, 0, 0, 0,
  122644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122874. 0, 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,
  122952. };
  122953. static float _vq_quantthresh__44c0_sm_p1_0[] = {
  122954. -0.5, 0.5,
  122955. };
  122956. static long _vq_quantmap__44c0_sm_p1_0[] = {
  122957. 1, 0, 2,
  122958. };
  122959. static encode_aux_threshmatch _vq_auxt__44c0_sm_p1_0 = {
  122960. _vq_quantthresh__44c0_sm_p1_0,
  122961. _vq_quantmap__44c0_sm_p1_0,
  122962. 3,
  122963. 3
  122964. };
  122965. static static_codebook _44c0_sm_p1_0 = {
  122966. 8, 6561,
  122967. _vq_lengthlist__44c0_sm_p1_0,
  122968. 1, -535822336, 1611661312, 2, 0,
  122969. _vq_quantlist__44c0_sm_p1_0,
  122970. NULL,
  122971. &_vq_auxt__44c0_sm_p1_0,
  122972. NULL,
  122973. 0
  122974. };
  122975. static long _vq_quantlist__44c0_sm_p2_0[] = {
  122976. 2,
  122977. 1,
  122978. 3,
  122979. 0,
  122980. 4,
  122981. };
  122982. static long _vq_lengthlist__44c0_sm_p2_0[] = {
  122983. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  122985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122986. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  122988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122989. 0, 0, 0, 0, 7, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  122990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123022. 0,
  123023. };
  123024. static float _vq_quantthresh__44c0_sm_p2_0[] = {
  123025. -1.5, -0.5, 0.5, 1.5,
  123026. };
  123027. static long _vq_quantmap__44c0_sm_p2_0[] = {
  123028. 3, 1, 0, 2, 4,
  123029. };
  123030. static encode_aux_threshmatch _vq_auxt__44c0_sm_p2_0 = {
  123031. _vq_quantthresh__44c0_sm_p2_0,
  123032. _vq_quantmap__44c0_sm_p2_0,
  123033. 5,
  123034. 5
  123035. };
  123036. static static_codebook _44c0_sm_p2_0 = {
  123037. 4, 625,
  123038. _vq_lengthlist__44c0_sm_p2_0,
  123039. 1, -533725184, 1611661312, 3, 0,
  123040. _vq_quantlist__44c0_sm_p2_0,
  123041. NULL,
  123042. &_vq_auxt__44c0_sm_p2_0,
  123043. NULL,
  123044. 0
  123045. };
  123046. static long _vq_quantlist__44c0_sm_p3_0[] = {
  123047. 4,
  123048. 3,
  123049. 5,
  123050. 2,
  123051. 6,
  123052. 1,
  123053. 7,
  123054. 0,
  123055. 8,
  123056. };
  123057. static long _vq_lengthlist__44c0_sm_p3_0[] = {
  123058. 1, 3, 3, 7, 7, 0, 0, 0, 0, 0, 5, 4, 7, 7, 0, 0,
  123059. 0, 0, 0, 5, 5, 7, 7, 0, 0, 0, 0, 0, 6, 7, 8, 8,
  123060. 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  123061. 9,10, 0, 0, 0, 0, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0,
  123062. 0, 0,11,11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123063. 0,
  123064. };
  123065. static float _vq_quantthresh__44c0_sm_p3_0[] = {
  123066. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  123067. };
  123068. static long _vq_quantmap__44c0_sm_p3_0[] = {
  123069. 7, 5, 3, 1, 0, 2, 4, 6,
  123070. 8,
  123071. };
  123072. static encode_aux_threshmatch _vq_auxt__44c0_sm_p3_0 = {
  123073. _vq_quantthresh__44c0_sm_p3_0,
  123074. _vq_quantmap__44c0_sm_p3_0,
  123075. 9,
  123076. 9
  123077. };
  123078. static static_codebook _44c0_sm_p3_0 = {
  123079. 2, 81,
  123080. _vq_lengthlist__44c0_sm_p3_0,
  123081. 1, -531628032, 1611661312, 4, 0,
  123082. _vq_quantlist__44c0_sm_p3_0,
  123083. NULL,
  123084. &_vq_auxt__44c0_sm_p3_0,
  123085. NULL,
  123086. 0
  123087. };
  123088. static long _vq_quantlist__44c0_sm_p4_0[] = {
  123089. 4,
  123090. 3,
  123091. 5,
  123092. 2,
  123093. 6,
  123094. 1,
  123095. 7,
  123096. 0,
  123097. 8,
  123098. };
  123099. static long _vq_lengthlist__44c0_sm_p4_0[] = {
  123100. 1, 4, 3, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 8, 7,
  123101. 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  123102. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  123103. 9, 9, 9, 9,11,11, 0, 0, 0, 9, 9, 9, 9,11,11, 0,
  123104. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  123105. 11,
  123106. };
  123107. static float _vq_quantthresh__44c0_sm_p4_0[] = {
  123108. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  123109. };
  123110. static long _vq_quantmap__44c0_sm_p4_0[] = {
  123111. 7, 5, 3, 1, 0, 2, 4, 6,
  123112. 8,
  123113. };
  123114. static encode_aux_threshmatch _vq_auxt__44c0_sm_p4_0 = {
  123115. _vq_quantthresh__44c0_sm_p4_0,
  123116. _vq_quantmap__44c0_sm_p4_0,
  123117. 9,
  123118. 9
  123119. };
  123120. static static_codebook _44c0_sm_p4_0 = {
  123121. 2, 81,
  123122. _vq_lengthlist__44c0_sm_p4_0,
  123123. 1, -531628032, 1611661312, 4, 0,
  123124. _vq_quantlist__44c0_sm_p4_0,
  123125. NULL,
  123126. &_vq_auxt__44c0_sm_p4_0,
  123127. NULL,
  123128. 0
  123129. };
  123130. static long _vq_quantlist__44c0_sm_p5_0[] = {
  123131. 8,
  123132. 7,
  123133. 9,
  123134. 6,
  123135. 10,
  123136. 5,
  123137. 11,
  123138. 4,
  123139. 12,
  123140. 3,
  123141. 13,
  123142. 2,
  123143. 14,
  123144. 1,
  123145. 15,
  123146. 0,
  123147. 16,
  123148. };
  123149. static long _vq_lengthlist__44c0_sm_p5_0[] = {
  123150. 1, 4, 4, 6, 6, 8, 8, 8, 8, 8, 8, 9, 9,10,10,11,
  123151. 11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,11,
  123152. 11,11, 0, 5, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  123153. 11,11,11, 0, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,
  123154. 11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,
  123155. 10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  123156. 11,11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  123157. 10,11,11,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  123158. 10,10,11,11,12,12,12,13, 0, 0, 0, 0, 0, 9, 9,10,
  123159. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  123160. 10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  123161. 9,10,10,11,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  123162. 10,10,10,10,11,11,12,12,12,13,13,13, 0, 0, 0, 0,
  123163. 0, 0, 0,10,10,11,11,12,12,12,13,13,13, 0, 0, 0,
  123164. 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14, 0, 0,
  123165. 0, 0, 0, 0, 0,11,11,12,11,12,12,13,13,13,13, 0,
  123166. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  123167. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  123168. 14,
  123169. };
  123170. static float _vq_quantthresh__44c0_sm_p5_0[] = {
  123171. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  123172. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  123173. };
  123174. static long _vq_quantmap__44c0_sm_p5_0[] = {
  123175. 15, 13, 11, 9, 7, 5, 3, 1,
  123176. 0, 2, 4, 6, 8, 10, 12, 14,
  123177. 16,
  123178. };
  123179. static encode_aux_threshmatch _vq_auxt__44c0_sm_p5_0 = {
  123180. _vq_quantthresh__44c0_sm_p5_0,
  123181. _vq_quantmap__44c0_sm_p5_0,
  123182. 17,
  123183. 17
  123184. };
  123185. static static_codebook _44c0_sm_p5_0 = {
  123186. 2, 289,
  123187. _vq_lengthlist__44c0_sm_p5_0,
  123188. 1, -529530880, 1611661312, 5, 0,
  123189. _vq_quantlist__44c0_sm_p5_0,
  123190. NULL,
  123191. &_vq_auxt__44c0_sm_p5_0,
  123192. NULL,
  123193. 0
  123194. };
  123195. static long _vq_quantlist__44c0_sm_p6_0[] = {
  123196. 1,
  123197. 0,
  123198. 2,
  123199. };
  123200. static long _vq_lengthlist__44c0_sm_p6_0[] = {
  123201. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  123202. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,10,11,
  123203. 11,11,10,10, 6, 9, 9,11,11,10,11,10,10, 6, 9, 9,
  123204. 11,10,11,11,10,10, 7,11,10,11,11,11,11,11,11, 6,
  123205. 9, 9,11,10,10,11,11,10, 6, 9, 9,11,10,10,11,10,
  123206. 11,
  123207. };
  123208. static float _vq_quantthresh__44c0_sm_p6_0[] = {
  123209. -5.5, 5.5,
  123210. };
  123211. static long _vq_quantmap__44c0_sm_p6_0[] = {
  123212. 1, 0, 2,
  123213. };
  123214. static encode_aux_threshmatch _vq_auxt__44c0_sm_p6_0 = {
  123215. _vq_quantthresh__44c0_sm_p6_0,
  123216. _vq_quantmap__44c0_sm_p6_0,
  123217. 3,
  123218. 3
  123219. };
  123220. static static_codebook _44c0_sm_p6_0 = {
  123221. 4, 81,
  123222. _vq_lengthlist__44c0_sm_p6_0,
  123223. 1, -529137664, 1618345984, 2, 0,
  123224. _vq_quantlist__44c0_sm_p6_0,
  123225. NULL,
  123226. &_vq_auxt__44c0_sm_p6_0,
  123227. NULL,
  123228. 0
  123229. };
  123230. static long _vq_quantlist__44c0_sm_p6_1[] = {
  123231. 5,
  123232. 4,
  123233. 6,
  123234. 3,
  123235. 7,
  123236. 2,
  123237. 8,
  123238. 1,
  123239. 9,
  123240. 0,
  123241. 10,
  123242. };
  123243. static long _vq_lengthlist__44c0_sm_p6_1[] = {
  123244. 2, 4, 4, 6, 6, 7, 7, 7, 7, 7, 8, 9, 5, 5, 6, 6,
  123245. 7, 7, 8, 8, 8, 8, 9, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  123246. 8,10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  123247. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  123248. 8, 8,10,10,10, 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  123249. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  123250. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  123251. 10,10,10, 8, 8, 8, 8, 8, 8,
  123252. };
  123253. static float _vq_quantthresh__44c0_sm_p6_1[] = {
  123254. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  123255. 3.5, 4.5,
  123256. };
  123257. static long _vq_quantmap__44c0_sm_p6_1[] = {
  123258. 9, 7, 5, 3, 1, 0, 2, 4,
  123259. 6, 8, 10,
  123260. };
  123261. static encode_aux_threshmatch _vq_auxt__44c0_sm_p6_1 = {
  123262. _vq_quantthresh__44c0_sm_p6_1,
  123263. _vq_quantmap__44c0_sm_p6_1,
  123264. 11,
  123265. 11
  123266. };
  123267. static static_codebook _44c0_sm_p6_1 = {
  123268. 2, 121,
  123269. _vq_lengthlist__44c0_sm_p6_1,
  123270. 1, -531365888, 1611661312, 4, 0,
  123271. _vq_quantlist__44c0_sm_p6_1,
  123272. NULL,
  123273. &_vq_auxt__44c0_sm_p6_1,
  123274. NULL,
  123275. 0
  123276. };
  123277. static long _vq_quantlist__44c0_sm_p7_0[] = {
  123278. 6,
  123279. 5,
  123280. 7,
  123281. 4,
  123282. 8,
  123283. 3,
  123284. 9,
  123285. 2,
  123286. 10,
  123287. 1,
  123288. 11,
  123289. 0,
  123290. 12,
  123291. };
  123292. static long _vq_lengthlist__44c0_sm_p7_0[] = {
  123293. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 5, 5,
  123294. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 6, 5, 7, 7, 8,
  123295. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  123296. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  123297. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  123298. 13, 9, 9, 9, 9,10,10,11,11,11,12, 0, 0, 0, 9,10,
  123299. 10,10,11,11,12,11,12,12, 0, 0, 0,10,10, 9, 9,11,
  123300. 11,12,12,12,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  123301. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  123302. 0, 0, 0, 0,11,12,11,11,13,12,13,13, 0, 0, 0, 0,
  123303. 0,12,12,11,11,13,12,14,14,
  123304. };
  123305. static float _vq_quantthresh__44c0_sm_p7_0[] = {
  123306. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  123307. 12.5, 17.5, 22.5, 27.5,
  123308. };
  123309. static long _vq_quantmap__44c0_sm_p7_0[] = {
  123310. 11, 9, 7, 5, 3, 1, 0, 2,
  123311. 4, 6, 8, 10, 12,
  123312. };
  123313. static encode_aux_threshmatch _vq_auxt__44c0_sm_p7_0 = {
  123314. _vq_quantthresh__44c0_sm_p7_0,
  123315. _vq_quantmap__44c0_sm_p7_0,
  123316. 13,
  123317. 13
  123318. };
  123319. static static_codebook _44c0_sm_p7_0 = {
  123320. 2, 169,
  123321. _vq_lengthlist__44c0_sm_p7_0,
  123322. 1, -526516224, 1616117760, 4, 0,
  123323. _vq_quantlist__44c0_sm_p7_0,
  123324. NULL,
  123325. &_vq_auxt__44c0_sm_p7_0,
  123326. NULL,
  123327. 0
  123328. };
  123329. static long _vq_quantlist__44c0_sm_p7_1[] = {
  123330. 2,
  123331. 1,
  123332. 3,
  123333. 0,
  123334. 4,
  123335. };
  123336. static long _vq_lengthlist__44c0_sm_p7_1[] = {
  123337. 2, 4, 4, 4, 4, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  123338. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  123339. };
  123340. static float _vq_quantthresh__44c0_sm_p7_1[] = {
  123341. -1.5, -0.5, 0.5, 1.5,
  123342. };
  123343. static long _vq_quantmap__44c0_sm_p7_1[] = {
  123344. 3, 1, 0, 2, 4,
  123345. };
  123346. static encode_aux_threshmatch _vq_auxt__44c0_sm_p7_1 = {
  123347. _vq_quantthresh__44c0_sm_p7_1,
  123348. _vq_quantmap__44c0_sm_p7_1,
  123349. 5,
  123350. 5
  123351. };
  123352. static static_codebook _44c0_sm_p7_1 = {
  123353. 2, 25,
  123354. _vq_lengthlist__44c0_sm_p7_1,
  123355. 1, -533725184, 1611661312, 3, 0,
  123356. _vq_quantlist__44c0_sm_p7_1,
  123357. NULL,
  123358. &_vq_auxt__44c0_sm_p7_1,
  123359. NULL,
  123360. 0
  123361. };
  123362. static long _vq_quantlist__44c0_sm_p8_0[] = {
  123363. 4,
  123364. 3,
  123365. 5,
  123366. 2,
  123367. 6,
  123368. 1,
  123369. 7,
  123370. 0,
  123371. 8,
  123372. };
  123373. static long _vq_lengthlist__44c0_sm_p8_0[] = {
  123374. 1, 3, 3,11,11,11,11,11,11, 3, 7, 6,11,11,11,11,
  123375. 11,11, 4, 8, 7,11,11,11,11,11,11,11,11,11,11,11,
  123376. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123377. 11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  123378. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  123379. 12,
  123380. };
  123381. static float _vq_quantthresh__44c0_sm_p8_0[] = {
  123382. -773.5, -552.5, -331.5, -110.5, 110.5, 331.5, 552.5, 773.5,
  123383. };
  123384. static long _vq_quantmap__44c0_sm_p8_0[] = {
  123385. 7, 5, 3, 1, 0, 2, 4, 6,
  123386. 8,
  123387. };
  123388. static encode_aux_threshmatch _vq_auxt__44c0_sm_p8_0 = {
  123389. _vq_quantthresh__44c0_sm_p8_0,
  123390. _vq_quantmap__44c0_sm_p8_0,
  123391. 9,
  123392. 9
  123393. };
  123394. static static_codebook _44c0_sm_p8_0 = {
  123395. 2, 81,
  123396. _vq_lengthlist__44c0_sm_p8_0,
  123397. 1, -516186112, 1627103232, 4, 0,
  123398. _vq_quantlist__44c0_sm_p8_0,
  123399. NULL,
  123400. &_vq_auxt__44c0_sm_p8_0,
  123401. NULL,
  123402. 0
  123403. };
  123404. static long _vq_quantlist__44c0_sm_p8_1[] = {
  123405. 6,
  123406. 5,
  123407. 7,
  123408. 4,
  123409. 8,
  123410. 3,
  123411. 9,
  123412. 2,
  123413. 10,
  123414. 1,
  123415. 11,
  123416. 0,
  123417. 12,
  123418. };
  123419. static long _vq_lengthlist__44c0_sm_p8_1[] = {
  123420. 1, 4, 4, 6, 6, 7, 7, 9, 9,10,11,12,12, 6, 5, 5,
  123421. 7, 7, 8, 8,10,10,12,11,12,12, 6, 5, 5, 7, 7, 8,
  123422. 8,10,10,12,11,12,12,17, 7, 7, 8, 8, 9, 9,10,10,
  123423. 12,12,13,13,18, 7, 7, 8, 7, 9, 9,10,10,12,12,12,
  123424. 13,19,10,10, 8, 8,10,10,11,11,12,12,13,14,19,11,
  123425. 10, 8, 7,10,10,11,11,12,12,13,12,19,19,19,10,10,
  123426. 10,10,11,11,12,12,13,13,19,19,19,11, 9,11, 9,14,
  123427. 12,13,12,13,13,19,20,18,13,14,11,11,12,12,13,13,
  123428. 14,13,20,20,20,15,13,11,10,13,11,13,13,14,13,20,
  123429. 20,20,20,20,13,14,12,12,13,13,13,13,20,20,20,20,
  123430. 20,13,13,12,12,16,13,15,13,
  123431. };
  123432. static float _vq_quantthresh__44c0_sm_p8_1[] = {
  123433. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  123434. 42.5, 59.5, 76.5, 93.5,
  123435. };
  123436. static long _vq_quantmap__44c0_sm_p8_1[] = {
  123437. 11, 9, 7, 5, 3, 1, 0, 2,
  123438. 4, 6, 8, 10, 12,
  123439. };
  123440. static encode_aux_threshmatch _vq_auxt__44c0_sm_p8_1 = {
  123441. _vq_quantthresh__44c0_sm_p8_1,
  123442. _vq_quantmap__44c0_sm_p8_1,
  123443. 13,
  123444. 13
  123445. };
  123446. static static_codebook _44c0_sm_p8_1 = {
  123447. 2, 169,
  123448. _vq_lengthlist__44c0_sm_p8_1,
  123449. 1, -522616832, 1620115456, 4, 0,
  123450. _vq_quantlist__44c0_sm_p8_1,
  123451. NULL,
  123452. &_vq_auxt__44c0_sm_p8_1,
  123453. NULL,
  123454. 0
  123455. };
  123456. static long _vq_quantlist__44c0_sm_p8_2[] = {
  123457. 8,
  123458. 7,
  123459. 9,
  123460. 6,
  123461. 10,
  123462. 5,
  123463. 11,
  123464. 4,
  123465. 12,
  123466. 3,
  123467. 13,
  123468. 2,
  123469. 14,
  123470. 1,
  123471. 15,
  123472. 0,
  123473. 16,
  123474. };
  123475. static long _vq_lengthlist__44c0_sm_p8_2[] = {
  123476. 2, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  123477. 8,10, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  123478. 9, 9,10, 6, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  123479. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  123480. 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 9, 8, 9, 9, 9,
  123481. 9,10, 9, 9,10,10,10,11, 8, 8, 8, 8, 9, 9, 9, 9,
  123482. 9, 9, 9,10, 9,10,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  123483. 9, 9, 9, 9, 9,10,10,11,10,10, 8, 8, 9, 9, 9, 9,
  123484. 9, 9, 9, 9, 9, 9,10,10,10,10,10,11,11, 8, 8, 9,
  123485. 9, 9, 9, 9, 9, 9, 9, 9,10,11,11,11,11,11, 9, 9,
  123486. 9, 9, 9, 9, 9, 9,10, 9,10, 9,11,11,10,11,11, 9,
  123487. 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,11,10,11,11,
  123488. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,10,11,11,
  123489. 11,11,11, 9, 9,10, 9, 9, 9, 9, 9, 9, 9,10,11,10,
  123490. 11,11,11,11,10,10,10,10, 9, 9, 9, 9, 9, 9,10,11,
  123491. 11,11,11,11,11, 9,10, 9, 9, 9, 9, 9, 9, 9, 9,11,
  123492. 11,10,11,11,11,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  123493. 10,11,10,11,11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9,
  123494. 9,
  123495. };
  123496. static float _vq_quantthresh__44c0_sm_p8_2[] = {
  123497. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  123498. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  123499. };
  123500. static long _vq_quantmap__44c0_sm_p8_2[] = {
  123501. 15, 13, 11, 9, 7, 5, 3, 1,
  123502. 0, 2, 4, 6, 8, 10, 12, 14,
  123503. 16,
  123504. };
  123505. static encode_aux_threshmatch _vq_auxt__44c0_sm_p8_2 = {
  123506. _vq_quantthresh__44c0_sm_p8_2,
  123507. _vq_quantmap__44c0_sm_p8_2,
  123508. 17,
  123509. 17
  123510. };
  123511. static static_codebook _44c0_sm_p8_2 = {
  123512. 2, 289,
  123513. _vq_lengthlist__44c0_sm_p8_2,
  123514. 1, -529530880, 1611661312, 5, 0,
  123515. _vq_quantlist__44c0_sm_p8_2,
  123516. NULL,
  123517. &_vq_auxt__44c0_sm_p8_2,
  123518. NULL,
  123519. 0
  123520. };
  123521. static long _huff_lengthlist__44c0_sm_short[] = {
  123522. 6, 6,12,13,13,14,16,17,17, 4, 2, 5, 8, 7, 9,12,
  123523. 15,15, 9, 4, 5, 9, 7, 9,12,16,18,11, 6, 7, 4, 6,
  123524. 8,11,14,18,10, 5, 6, 5, 5, 7,10,14,17,10, 5, 7,
  123525. 7, 6, 7,10,13,16,11, 5, 7, 7, 7, 8,10,12,15,13,
  123526. 6, 7, 5, 5, 7, 9,12,13,16, 8, 9, 6, 6, 7, 9,10,
  123527. 12,
  123528. };
  123529. static static_codebook _huff_book__44c0_sm_short = {
  123530. 2, 81,
  123531. _huff_lengthlist__44c0_sm_short,
  123532. 0, 0, 0, 0, 0,
  123533. NULL,
  123534. NULL,
  123535. NULL,
  123536. NULL,
  123537. 0
  123538. };
  123539. static long _huff_lengthlist__44c1_s_long[] = {
  123540. 5, 5, 9,10, 9, 9,10,11,12, 5, 1, 5, 6, 6, 7,10,
  123541. 12,14, 9, 5, 6, 8, 8,10,12,14,14,10, 5, 8, 5, 6,
  123542. 8,11,13,14, 9, 5, 7, 6, 6, 8,10,12,11, 9, 7, 9,
  123543. 7, 6, 6, 7,10,10,10, 9,12, 9, 8, 7, 7,10,12,11,
  123544. 11,13,12,10, 9, 8, 9,11,11,14,15,15,13,11, 9, 9,
  123545. 11,
  123546. };
  123547. static static_codebook _huff_book__44c1_s_long = {
  123548. 2, 81,
  123549. _huff_lengthlist__44c1_s_long,
  123550. 0, 0, 0, 0, 0,
  123551. NULL,
  123552. NULL,
  123553. NULL,
  123554. NULL,
  123555. 0
  123556. };
  123557. static long _vq_quantlist__44c1_s_p1_0[] = {
  123558. 1,
  123559. 0,
  123560. 2,
  123561. };
  123562. static long _vq_lengthlist__44c1_s_p1_0[] = {
  123563. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 7, 6, 0, 0, 0, 0,
  123564. 0, 0, 5, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123568. 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  123569. 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123573. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  123574. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 7, 7, 0, 0, 0, 0,
  123609. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 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, 7, 8, 8, 0, 0, 0,
  123614. 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 6, 8, 8, 0, 0,
  123619. 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  123620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123654. 0, 0, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  123655. 0, 0, 0, 0, 7, 8, 9, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8,10, 9, 0,
  123660. 0, 0, 0, 0, 0, 8, 8, 9, 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, 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  123665. 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  123666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123896. 0, 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,
  123974. };
  123975. static float _vq_quantthresh__44c1_s_p1_0[] = {
  123976. -0.5, 0.5,
  123977. };
  123978. static long _vq_quantmap__44c1_s_p1_0[] = {
  123979. 1, 0, 2,
  123980. };
  123981. static encode_aux_threshmatch _vq_auxt__44c1_s_p1_0 = {
  123982. _vq_quantthresh__44c1_s_p1_0,
  123983. _vq_quantmap__44c1_s_p1_0,
  123984. 3,
  123985. 3
  123986. };
  123987. static static_codebook _44c1_s_p1_0 = {
  123988. 8, 6561,
  123989. _vq_lengthlist__44c1_s_p1_0,
  123990. 1, -535822336, 1611661312, 2, 0,
  123991. _vq_quantlist__44c1_s_p1_0,
  123992. NULL,
  123993. &_vq_auxt__44c1_s_p1_0,
  123994. NULL,
  123995. 0
  123996. };
  123997. static long _vq_quantlist__44c1_s_p2_0[] = {
  123998. 2,
  123999. 1,
  124000. 3,
  124001. 0,
  124002. 4,
  124003. };
  124004. static long _vq_lengthlist__44c1_s_p2_0[] = {
  124005. 2, 3, 4, 6, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  124007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124008. 0, 0, 4, 4, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 8, 8,
  124010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124011. 0, 0, 0, 0, 6, 6, 6, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  124012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124044. 0,
  124045. };
  124046. static float _vq_quantthresh__44c1_s_p2_0[] = {
  124047. -1.5, -0.5, 0.5, 1.5,
  124048. };
  124049. static long _vq_quantmap__44c1_s_p2_0[] = {
  124050. 3, 1, 0, 2, 4,
  124051. };
  124052. static encode_aux_threshmatch _vq_auxt__44c1_s_p2_0 = {
  124053. _vq_quantthresh__44c1_s_p2_0,
  124054. _vq_quantmap__44c1_s_p2_0,
  124055. 5,
  124056. 5
  124057. };
  124058. static static_codebook _44c1_s_p2_0 = {
  124059. 4, 625,
  124060. _vq_lengthlist__44c1_s_p2_0,
  124061. 1, -533725184, 1611661312, 3, 0,
  124062. _vq_quantlist__44c1_s_p2_0,
  124063. NULL,
  124064. &_vq_auxt__44c1_s_p2_0,
  124065. NULL,
  124066. 0
  124067. };
  124068. static long _vq_quantlist__44c1_s_p3_0[] = {
  124069. 4,
  124070. 3,
  124071. 5,
  124072. 2,
  124073. 6,
  124074. 1,
  124075. 7,
  124076. 0,
  124077. 8,
  124078. };
  124079. static long _vq_lengthlist__44c1_s_p3_0[] = {
  124080. 1, 3, 2, 7, 7, 0, 0, 0, 0, 0,13,13, 6, 6, 0, 0,
  124081. 0, 0, 0,12, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  124082. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  124083. 8, 9, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  124084. 0, 0,11,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124085. 0,
  124086. };
  124087. static float _vq_quantthresh__44c1_s_p3_0[] = {
  124088. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  124089. };
  124090. static long _vq_quantmap__44c1_s_p3_0[] = {
  124091. 7, 5, 3, 1, 0, 2, 4, 6,
  124092. 8,
  124093. };
  124094. static encode_aux_threshmatch _vq_auxt__44c1_s_p3_0 = {
  124095. _vq_quantthresh__44c1_s_p3_0,
  124096. _vq_quantmap__44c1_s_p3_0,
  124097. 9,
  124098. 9
  124099. };
  124100. static static_codebook _44c1_s_p3_0 = {
  124101. 2, 81,
  124102. _vq_lengthlist__44c1_s_p3_0,
  124103. 1, -531628032, 1611661312, 4, 0,
  124104. _vq_quantlist__44c1_s_p3_0,
  124105. NULL,
  124106. &_vq_auxt__44c1_s_p3_0,
  124107. NULL,
  124108. 0
  124109. };
  124110. static long _vq_quantlist__44c1_s_p4_0[] = {
  124111. 4,
  124112. 3,
  124113. 5,
  124114. 2,
  124115. 6,
  124116. 1,
  124117. 7,
  124118. 0,
  124119. 8,
  124120. };
  124121. static long _vq_lengthlist__44c1_s_p4_0[] = {
  124122. 1, 3, 3, 6, 5, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  124123. 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  124124. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  124125. 9, 9, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  124126. 0, 0,10,10, 9, 9,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  124127. 11,
  124128. };
  124129. static float _vq_quantthresh__44c1_s_p4_0[] = {
  124130. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  124131. };
  124132. static long _vq_quantmap__44c1_s_p4_0[] = {
  124133. 7, 5, 3, 1, 0, 2, 4, 6,
  124134. 8,
  124135. };
  124136. static encode_aux_threshmatch _vq_auxt__44c1_s_p4_0 = {
  124137. _vq_quantthresh__44c1_s_p4_0,
  124138. _vq_quantmap__44c1_s_p4_0,
  124139. 9,
  124140. 9
  124141. };
  124142. static static_codebook _44c1_s_p4_0 = {
  124143. 2, 81,
  124144. _vq_lengthlist__44c1_s_p4_0,
  124145. 1, -531628032, 1611661312, 4, 0,
  124146. _vq_quantlist__44c1_s_p4_0,
  124147. NULL,
  124148. &_vq_auxt__44c1_s_p4_0,
  124149. NULL,
  124150. 0
  124151. };
  124152. static long _vq_quantlist__44c1_s_p5_0[] = {
  124153. 8,
  124154. 7,
  124155. 9,
  124156. 6,
  124157. 10,
  124158. 5,
  124159. 11,
  124160. 4,
  124161. 12,
  124162. 3,
  124163. 13,
  124164. 2,
  124165. 14,
  124166. 1,
  124167. 15,
  124168. 0,
  124169. 16,
  124170. };
  124171. static long _vq_lengthlist__44c1_s_p5_0[] = {
  124172. 1, 4, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  124173. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,
  124174. 11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  124175. 10,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  124176. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  124177. 10,11,11,12,11, 0, 0, 0, 8, 8, 9, 9, 9,10,10,10,
  124178. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10, 9,10,
  124179. 10,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  124180. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  124181. 10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,
  124182. 10,10,10,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  124183. 9,10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  124184. 10,10,10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0,
  124185. 0, 0, 0,10,10,11,11,12,12,12,12,13,13, 0, 0, 0,
  124186. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,13, 0, 0,
  124187. 0, 0, 0, 0, 0,11,11,11,11,12,12,13,13,13,13, 0,
  124188. 0, 0, 0, 0, 0, 0,12,12,12,12,12,12,13,13,14,14,
  124189. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  124190. 14,
  124191. };
  124192. static float _vq_quantthresh__44c1_s_p5_0[] = {
  124193. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  124194. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  124195. };
  124196. static long _vq_quantmap__44c1_s_p5_0[] = {
  124197. 15, 13, 11, 9, 7, 5, 3, 1,
  124198. 0, 2, 4, 6, 8, 10, 12, 14,
  124199. 16,
  124200. };
  124201. static encode_aux_threshmatch _vq_auxt__44c1_s_p5_0 = {
  124202. _vq_quantthresh__44c1_s_p5_0,
  124203. _vq_quantmap__44c1_s_p5_0,
  124204. 17,
  124205. 17
  124206. };
  124207. static static_codebook _44c1_s_p5_0 = {
  124208. 2, 289,
  124209. _vq_lengthlist__44c1_s_p5_0,
  124210. 1, -529530880, 1611661312, 5, 0,
  124211. _vq_quantlist__44c1_s_p5_0,
  124212. NULL,
  124213. &_vq_auxt__44c1_s_p5_0,
  124214. NULL,
  124215. 0
  124216. };
  124217. static long _vq_quantlist__44c1_s_p6_0[] = {
  124218. 1,
  124219. 0,
  124220. 2,
  124221. };
  124222. static long _vq_lengthlist__44c1_s_p6_0[] = {
  124223. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  124224. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 6,10,10,11,11,
  124225. 11,11,10,10, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  124226. 11,10,11,11,10,10, 7,11,10,11,11,11,12,11,11, 7,
  124227. 9, 9,11,10,10,11,11,10, 6, 9, 9,10,10,10,12,10,
  124228. 11,
  124229. };
  124230. static float _vq_quantthresh__44c1_s_p6_0[] = {
  124231. -5.5, 5.5,
  124232. };
  124233. static long _vq_quantmap__44c1_s_p6_0[] = {
  124234. 1, 0, 2,
  124235. };
  124236. static encode_aux_threshmatch _vq_auxt__44c1_s_p6_0 = {
  124237. _vq_quantthresh__44c1_s_p6_0,
  124238. _vq_quantmap__44c1_s_p6_0,
  124239. 3,
  124240. 3
  124241. };
  124242. static static_codebook _44c1_s_p6_0 = {
  124243. 4, 81,
  124244. _vq_lengthlist__44c1_s_p6_0,
  124245. 1, -529137664, 1618345984, 2, 0,
  124246. _vq_quantlist__44c1_s_p6_0,
  124247. NULL,
  124248. &_vq_auxt__44c1_s_p6_0,
  124249. NULL,
  124250. 0
  124251. };
  124252. static long _vq_quantlist__44c1_s_p6_1[] = {
  124253. 5,
  124254. 4,
  124255. 6,
  124256. 3,
  124257. 7,
  124258. 2,
  124259. 8,
  124260. 1,
  124261. 9,
  124262. 0,
  124263. 10,
  124264. };
  124265. static long _vq_lengthlist__44c1_s_p6_1[] = {
  124266. 2, 3, 3, 6, 6, 7, 7, 7, 7, 8, 8,10,10,10, 6, 6,
  124267. 7, 7, 8, 8, 8, 8,10,10,10, 6, 6, 7, 7, 8, 8, 8,
  124268. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  124269. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  124270. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  124271. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  124272. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  124273. 10,10,10, 8, 8, 8, 8, 8, 8,
  124274. };
  124275. static float _vq_quantthresh__44c1_s_p6_1[] = {
  124276. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  124277. 3.5, 4.5,
  124278. };
  124279. static long _vq_quantmap__44c1_s_p6_1[] = {
  124280. 9, 7, 5, 3, 1, 0, 2, 4,
  124281. 6, 8, 10,
  124282. };
  124283. static encode_aux_threshmatch _vq_auxt__44c1_s_p6_1 = {
  124284. _vq_quantthresh__44c1_s_p6_1,
  124285. _vq_quantmap__44c1_s_p6_1,
  124286. 11,
  124287. 11
  124288. };
  124289. static static_codebook _44c1_s_p6_1 = {
  124290. 2, 121,
  124291. _vq_lengthlist__44c1_s_p6_1,
  124292. 1, -531365888, 1611661312, 4, 0,
  124293. _vq_quantlist__44c1_s_p6_1,
  124294. NULL,
  124295. &_vq_auxt__44c1_s_p6_1,
  124296. NULL,
  124297. 0
  124298. };
  124299. static long _vq_quantlist__44c1_s_p7_0[] = {
  124300. 6,
  124301. 5,
  124302. 7,
  124303. 4,
  124304. 8,
  124305. 3,
  124306. 9,
  124307. 2,
  124308. 10,
  124309. 1,
  124310. 11,
  124311. 0,
  124312. 12,
  124313. };
  124314. static long _vq_lengthlist__44c1_s_p7_0[] = {
  124315. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 9, 7, 5, 6,
  124316. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 5, 7, 7, 8,
  124317. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  124318. 10,10,11,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  124319. 11, 0,12,12, 9, 9, 9,10,10,10,11,11,11,11, 0,13,
  124320. 13, 9, 9, 9, 9,10,10,11,11,11,11, 0, 0, 0,10,10,
  124321. 10,10,11,11,12,11,12,12, 0, 0, 0,10,10,10, 9,11,
  124322. 11,12,11,13,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  124323. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  124324. 0, 0, 0, 0,11,12,11,11,12,12,14,13, 0, 0, 0, 0,
  124325. 0,12,11,11,11,13,10,14,13,
  124326. };
  124327. static float _vq_quantthresh__44c1_s_p7_0[] = {
  124328. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  124329. 12.5, 17.5, 22.5, 27.5,
  124330. };
  124331. static long _vq_quantmap__44c1_s_p7_0[] = {
  124332. 11, 9, 7, 5, 3, 1, 0, 2,
  124333. 4, 6, 8, 10, 12,
  124334. };
  124335. static encode_aux_threshmatch _vq_auxt__44c1_s_p7_0 = {
  124336. _vq_quantthresh__44c1_s_p7_0,
  124337. _vq_quantmap__44c1_s_p7_0,
  124338. 13,
  124339. 13
  124340. };
  124341. static static_codebook _44c1_s_p7_0 = {
  124342. 2, 169,
  124343. _vq_lengthlist__44c1_s_p7_0,
  124344. 1, -526516224, 1616117760, 4, 0,
  124345. _vq_quantlist__44c1_s_p7_0,
  124346. NULL,
  124347. &_vq_auxt__44c1_s_p7_0,
  124348. NULL,
  124349. 0
  124350. };
  124351. static long _vq_quantlist__44c1_s_p7_1[] = {
  124352. 2,
  124353. 1,
  124354. 3,
  124355. 0,
  124356. 4,
  124357. };
  124358. static long _vq_lengthlist__44c1_s_p7_1[] = {
  124359. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  124360. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  124361. };
  124362. static float _vq_quantthresh__44c1_s_p7_1[] = {
  124363. -1.5, -0.5, 0.5, 1.5,
  124364. };
  124365. static long _vq_quantmap__44c1_s_p7_1[] = {
  124366. 3, 1, 0, 2, 4,
  124367. };
  124368. static encode_aux_threshmatch _vq_auxt__44c1_s_p7_1 = {
  124369. _vq_quantthresh__44c1_s_p7_1,
  124370. _vq_quantmap__44c1_s_p7_1,
  124371. 5,
  124372. 5
  124373. };
  124374. static static_codebook _44c1_s_p7_1 = {
  124375. 2, 25,
  124376. _vq_lengthlist__44c1_s_p7_1,
  124377. 1, -533725184, 1611661312, 3, 0,
  124378. _vq_quantlist__44c1_s_p7_1,
  124379. NULL,
  124380. &_vq_auxt__44c1_s_p7_1,
  124381. NULL,
  124382. 0
  124383. };
  124384. static long _vq_quantlist__44c1_s_p8_0[] = {
  124385. 6,
  124386. 5,
  124387. 7,
  124388. 4,
  124389. 8,
  124390. 3,
  124391. 9,
  124392. 2,
  124393. 10,
  124394. 1,
  124395. 11,
  124396. 0,
  124397. 12,
  124398. };
  124399. static long _vq_lengthlist__44c1_s_p8_0[] = {
  124400. 1, 4, 3,10,10,10,10,10,10,10,10,10,10, 4, 8, 6,
  124401. 10,10,10,10,10,10,10,10,10,10, 4, 8, 7,10,10,10,
  124402. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124403. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124404. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124405. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124406. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124407. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124408. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124409. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124410. 10,10,10,10,10,10,10,10,10,
  124411. };
  124412. static float _vq_quantthresh__44c1_s_p8_0[] = {
  124413. -1215.5, -994.5, -773.5, -552.5, -331.5, -110.5, 110.5, 331.5,
  124414. 552.5, 773.5, 994.5, 1215.5,
  124415. };
  124416. static long _vq_quantmap__44c1_s_p8_0[] = {
  124417. 11, 9, 7, 5, 3, 1, 0, 2,
  124418. 4, 6, 8, 10, 12,
  124419. };
  124420. static encode_aux_threshmatch _vq_auxt__44c1_s_p8_0 = {
  124421. _vq_quantthresh__44c1_s_p8_0,
  124422. _vq_quantmap__44c1_s_p8_0,
  124423. 13,
  124424. 13
  124425. };
  124426. static static_codebook _44c1_s_p8_0 = {
  124427. 2, 169,
  124428. _vq_lengthlist__44c1_s_p8_0,
  124429. 1, -514541568, 1627103232, 4, 0,
  124430. _vq_quantlist__44c1_s_p8_0,
  124431. NULL,
  124432. &_vq_auxt__44c1_s_p8_0,
  124433. NULL,
  124434. 0
  124435. };
  124436. static long _vq_quantlist__44c1_s_p8_1[] = {
  124437. 6,
  124438. 5,
  124439. 7,
  124440. 4,
  124441. 8,
  124442. 3,
  124443. 9,
  124444. 2,
  124445. 10,
  124446. 1,
  124447. 11,
  124448. 0,
  124449. 12,
  124450. };
  124451. static long _vq_lengthlist__44c1_s_p8_1[] = {
  124452. 1, 4, 4, 6, 5, 7, 7, 9, 9,10,10,12,12, 6, 5, 5,
  124453. 7, 7, 8, 8,10,10,12,11,12,12, 6, 5, 5, 7, 7, 8,
  124454. 8,10,10,11,11,12,12,15, 7, 7, 8, 8, 9, 9,11,11,
  124455. 12,12,13,12,15, 8, 8, 8, 7, 9, 9,10,10,12,12,13,
  124456. 13,16,11,10, 8, 8,10,10,11,11,12,12,13,13,16,11,
  124457. 11, 9, 8,11,10,11,11,12,12,13,12,16,16,16,10,11,
  124458. 10,11,12,12,12,12,13,13,16,16,16,11, 9,11, 9,14,
  124459. 12,12,12,13,13,16,16,16,12,14,11,12,12,12,13,13,
  124460. 14,13,16,16,16,15,13,12,10,13,10,13,14,13,13,16,
  124461. 16,16,16,16,13,14,12,13,13,12,13,13,16,16,16,16,
  124462. 16,13,12,12,11,14,12,15,13,
  124463. };
  124464. static float _vq_quantthresh__44c1_s_p8_1[] = {
  124465. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  124466. 42.5, 59.5, 76.5, 93.5,
  124467. };
  124468. static long _vq_quantmap__44c1_s_p8_1[] = {
  124469. 11, 9, 7, 5, 3, 1, 0, 2,
  124470. 4, 6, 8, 10, 12,
  124471. };
  124472. static encode_aux_threshmatch _vq_auxt__44c1_s_p8_1 = {
  124473. _vq_quantthresh__44c1_s_p8_1,
  124474. _vq_quantmap__44c1_s_p8_1,
  124475. 13,
  124476. 13
  124477. };
  124478. static static_codebook _44c1_s_p8_1 = {
  124479. 2, 169,
  124480. _vq_lengthlist__44c1_s_p8_1,
  124481. 1, -522616832, 1620115456, 4, 0,
  124482. _vq_quantlist__44c1_s_p8_1,
  124483. NULL,
  124484. &_vq_auxt__44c1_s_p8_1,
  124485. NULL,
  124486. 0
  124487. };
  124488. static long _vq_quantlist__44c1_s_p8_2[] = {
  124489. 8,
  124490. 7,
  124491. 9,
  124492. 6,
  124493. 10,
  124494. 5,
  124495. 11,
  124496. 4,
  124497. 12,
  124498. 3,
  124499. 13,
  124500. 2,
  124501. 14,
  124502. 1,
  124503. 15,
  124504. 0,
  124505. 16,
  124506. };
  124507. static long _vq_lengthlist__44c1_s_p8_2[] = {
  124508. 2, 4, 4, 6, 6, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  124509. 8,10,10,10, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  124510. 9, 9,10,10,10, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  124511. 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  124512. 9,10, 9, 9,10,10,10, 7, 7, 8, 8, 9, 8, 9, 9, 9,
  124513. 9,10, 9, 9,10,10,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  124514. 9, 9,10, 9, 9,10,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  124515. 9, 9, 9, 9, 9,10,10,11,11,11, 8, 8, 9, 9, 9, 9,
  124516. 9, 9, 9, 9, 9, 9,10,10,10,10,11,11,11, 8, 8, 9,
  124517. 9, 9, 9,10, 9, 9, 9, 9, 9,11,11,11,11,11, 9, 9,
  124518. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,10,11,11, 9,
  124519. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,11,10,11,11,
  124520. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,10,10,11,11,
  124521. 11,11,11, 9, 9, 9,10, 9, 9, 9, 9, 9, 9,10,11,11,
  124522. 11,11,11,11,10,10,10,10, 9, 9, 9, 9, 9, 9,10,11,
  124523. 11,11,11,11,11, 9,10, 9, 9, 9, 9,10, 9, 9, 9,11,
  124524. 11,11,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9,10, 9,
  124525. 11,11,10,11,11,11,11,10,11, 9, 9, 9, 9, 9, 9, 9,
  124526. 9,
  124527. };
  124528. static float _vq_quantthresh__44c1_s_p8_2[] = {
  124529. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  124530. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  124531. };
  124532. static long _vq_quantmap__44c1_s_p8_2[] = {
  124533. 15, 13, 11, 9, 7, 5, 3, 1,
  124534. 0, 2, 4, 6, 8, 10, 12, 14,
  124535. 16,
  124536. };
  124537. static encode_aux_threshmatch _vq_auxt__44c1_s_p8_2 = {
  124538. _vq_quantthresh__44c1_s_p8_2,
  124539. _vq_quantmap__44c1_s_p8_2,
  124540. 17,
  124541. 17
  124542. };
  124543. static static_codebook _44c1_s_p8_2 = {
  124544. 2, 289,
  124545. _vq_lengthlist__44c1_s_p8_2,
  124546. 1, -529530880, 1611661312, 5, 0,
  124547. _vq_quantlist__44c1_s_p8_2,
  124548. NULL,
  124549. &_vq_auxt__44c1_s_p8_2,
  124550. NULL,
  124551. 0
  124552. };
  124553. static long _huff_lengthlist__44c1_s_short[] = {
  124554. 6, 8,13,12,13,14,15,16,16, 4, 2, 4, 7, 6, 8,11,
  124555. 13,15,10, 4, 4, 8, 6, 8,11,14,17,11, 5, 6, 5, 6,
  124556. 8,12,14,17,11, 5, 5, 6, 5, 7,10,13,16,12, 6, 7,
  124557. 8, 7, 8,10,13,15,13, 8, 8, 7, 7, 8,10,12,15,15,
  124558. 7, 7, 5, 5, 7, 9,12,14,15, 8, 8, 6, 6, 7, 8,10,
  124559. 11,
  124560. };
  124561. static static_codebook _huff_book__44c1_s_short = {
  124562. 2, 81,
  124563. _huff_lengthlist__44c1_s_short,
  124564. 0, 0, 0, 0, 0,
  124565. NULL,
  124566. NULL,
  124567. NULL,
  124568. NULL,
  124569. 0
  124570. };
  124571. static long _huff_lengthlist__44c1_sm_long[] = {
  124572. 5, 4, 8,10, 9, 9,10,11,12, 4, 2, 5, 6, 6, 8,10,
  124573. 11,13, 8, 4, 6, 8, 7, 9,12,12,14,10, 6, 8, 4, 5,
  124574. 6, 9,11,12, 9, 5, 6, 5, 5, 6, 9,11,11, 9, 7, 9,
  124575. 6, 5, 5, 7,10,10,10, 9,11, 8, 7, 6, 7, 9,11,11,
  124576. 12,13,10,10, 9, 8, 9,11,11,15,15,12,13,11, 9,10,
  124577. 11,
  124578. };
  124579. static static_codebook _huff_book__44c1_sm_long = {
  124580. 2, 81,
  124581. _huff_lengthlist__44c1_sm_long,
  124582. 0, 0, 0, 0, 0,
  124583. NULL,
  124584. NULL,
  124585. NULL,
  124586. NULL,
  124587. 0
  124588. };
  124589. static long _vq_quantlist__44c1_sm_p1_0[] = {
  124590. 1,
  124591. 0,
  124592. 2,
  124593. };
  124594. static long _vq_lengthlist__44c1_sm_p1_0[] = {
  124595. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  124596. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124600. 0, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  124601. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124605. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  124606. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 0,
  124641. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  124646. 0, 0, 0, 9, 9,10, 0, 0, 0, 0, 0, 0, 9,10,10, 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, 7, 9, 9, 0, 0,
  124651. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  124652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124686. 0, 0, 5, 7, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  124687. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  124692. 0, 0, 0, 0, 0, 8, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  124697. 0, 0, 0, 0, 0, 0, 9,10, 9, 0, 0, 0, 0, 0, 0, 0,
  124698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124928. 0, 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,
  125006. };
  125007. static float _vq_quantthresh__44c1_sm_p1_0[] = {
  125008. -0.5, 0.5,
  125009. };
  125010. static long _vq_quantmap__44c1_sm_p1_0[] = {
  125011. 1, 0, 2,
  125012. };
  125013. static encode_aux_threshmatch _vq_auxt__44c1_sm_p1_0 = {
  125014. _vq_quantthresh__44c1_sm_p1_0,
  125015. _vq_quantmap__44c1_sm_p1_0,
  125016. 3,
  125017. 3
  125018. };
  125019. static static_codebook _44c1_sm_p1_0 = {
  125020. 8, 6561,
  125021. _vq_lengthlist__44c1_sm_p1_0,
  125022. 1, -535822336, 1611661312, 2, 0,
  125023. _vq_quantlist__44c1_sm_p1_0,
  125024. NULL,
  125025. &_vq_auxt__44c1_sm_p1_0,
  125026. NULL,
  125027. 0
  125028. };
  125029. static long _vq_quantlist__44c1_sm_p2_0[] = {
  125030. 2,
  125031. 1,
  125032. 3,
  125033. 0,
  125034. 4,
  125035. };
  125036. static long _vq_lengthlist__44c1_sm_p2_0[] = {
  125037. 2, 3, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  125039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125040. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  125042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125043. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  125044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125076. 0,
  125077. };
  125078. static float _vq_quantthresh__44c1_sm_p2_0[] = {
  125079. -1.5, -0.5, 0.5, 1.5,
  125080. };
  125081. static long _vq_quantmap__44c1_sm_p2_0[] = {
  125082. 3, 1, 0, 2, 4,
  125083. };
  125084. static encode_aux_threshmatch _vq_auxt__44c1_sm_p2_0 = {
  125085. _vq_quantthresh__44c1_sm_p2_0,
  125086. _vq_quantmap__44c1_sm_p2_0,
  125087. 5,
  125088. 5
  125089. };
  125090. static static_codebook _44c1_sm_p2_0 = {
  125091. 4, 625,
  125092. _vq_lengthlist__44c1_sm_p2_0,
  125093. 1, -533725184, 1611661312, 3, 0,
  125094. _vq_quantlist__44c1_sm_p2_0,
  125095. NULL,
  125096. &_vq_auxt__44c1_sm_p2_0,
  125097. NULL,
  125098. 0
  125099. };
  125100. static long _vq_quantlist__44c1_sm_p3_0[] = {
  125101. 4,
  125102. 3,
  125103. 5,
  125104. 2,
  125105. 6,
  125106. 1,
  125107. 7,
  125108. 0,
  125109. 8,
  125110. };
  125111. static long _vq_lengthlist__44c1_sm_p3_0[] = {
  125112. 1, 3, 3, 7, 7, 0, 0, 0, 0, 0, 5, 5, 6, 6, 0, 0,
  125113. 0, 0, 0, 5, 5, 7, 7, 0, 0, 0, 0, 0, 7, 7, 7, 7,
  125114. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  125115. 8, 9, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  125116. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125117. 0,
  125118. };
  125119. static float _vq_quantthresh__44c1_sm_p3_0[] = {
  125120. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  125121. };
  125122. static long _vq_quantmap__44c1_sm_p3_0[] = {
  125123. 7, 5, 3, 1, 0, 2, 4, 6,
  125124. 8,
  125125. };
  125126. static encode_aux_threshmatch _vq_auxt__44c1_sm_p3_0 = {
  125127. _vq_quantthresh__44c1_sm_p3_0,
  125128. _vq_quantmap__44c1_sm_p3_0,
  125129. 9,
  125130. 9
  125131. };
  125132. static static_codebook _44c1_sm_p3_0 = {
  125133. 2, 81,
  125134. _vq_lengthlist__44c1_sm_p3_0,
  125135. 1, -531628032, 1611661312, 4, 0,
  125136. _vq_quantlist__44c1_sm_p3_0,
  125137. NULL,
  125138. &_vq_auxt__44c1_sm_p3_0,
  125139. NULL,
  125140. 0
  125141. };
  125142. static long _vq_quantlist__44c1_sm_p4_0[] = {
  125143. 4,
  125144. 3,
  125145. 5,
  125146. 2,
  125147. 6,
  125148. 1,
  125149. 7,
  125150. 0,
  125151. 8,
  125152. };
  125153. static long _vq_lengthlist__44c1_sm_p4_0[] = {
  125154. 1, 3, 3, 6, 6, 7, 7, 9, 9, 0, 6, 6, 7, 7, 8, 8,
  125155. 9, 9, 0, 6, 6, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  125156. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  125157. 8, 8, 9, 9,11,11, 0, 0, 0, 9, 9, 9, 9,11,11, 0,
  125158. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  125159. 11,
  125160. };
  125161. static float _vq_quantthresh__44c1_sm_p4_0[] = {
  125162. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  125163. };
  125164. static long _vq_quantmap__44c1_sm_p4_0[] = {
  125165. 7, 5, 3, 1, 0, 2, 4, 6,
  125166. 8,
  125167. };
  125168. static encode_aux_threshmatch _vq_auxt__44c1_sm_p4_0 = {
  125169. _vq_quantthresh__44c1_sm_p4_0,
  125170. _vq_quantmap__44c1_sm_p4_0,
  125171. 9,
  125172. 9
  125173. };
  125174. static static_codebook _44c1_sm_p4_0 = {
  125175. 2, 81,
  125176. _vq_lengthlist__44c1_sm_p4_0,
  125177. 1, -531628032, 1611661312, 4, 0,
  125178. _vq_quantlist__44c1_sm_p4_0,
  125179. NULL,
  125180. &_vq_auxt__44c1_sm_p4_0,
  125181. NULL,
  125182. 0
  125183. };
  125184. static long _vq_quantlist__44c1_sm_p5_0[] = {
  125185. 8,
  125186. 7,
  125187. 9,
  125188. 6,
  125189. 10,
  125190. 5,
  125191. 11,
  125192. 4,
  125193. 12,
  125194. 3,
  125195. 13,
  125196. 2,
  125197. 14,
  125198. 1,
  125199. 15,
  125200. 0,
  125201. 16,
  125202. };
  125203. static long _vq_lengthlist__44c1_sm_p5_0[] = {
  125204. 2, 3, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  125205. 11, 0, 5, 5, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,10,
  125206. 11,11, 0, 5, 5, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,
  125207. 10,11,11, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  125208. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  125209. 10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9,10,10,
  125210. 10,11,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9,10,
  125211. 10,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  125212. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  125213. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  125214. 9, 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  125215. 9, 9, 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  125216. 9, 9,10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0,
  125217. 0, 0, 0,10,10,11,11,12,12,12,12,13,13, 0, 0, 0,
  125218. 0, 0, 0, 0,11,11,11,11,12,12,13,13,13,13, 0, 0,
  125219. 0, 0, 0, 0, 0,11,11,11,11,12,12,13,13,13,13, 0,
  125220. 0, 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14,
  125221. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  125222. 14,
  125223. };
  125224. static float _vq_quantthresh__44c1_sm_p5_0[] = {
  125225. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  125226. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  125227. };
  125228. static long _vq_quantmap__44c1_sm_p5_0[] = {
  125229. 15, 13, 11, 9, 7, 5, 3, 1,
  125230. 0, 2, 4, 6, 8, 10, 12, 14,
  125231. 16,
  125232. };
  125233. static encode_aux_threshmatch _vq_auxt__44c1_sm_p5_0 = {
  125234. _vq_quantthresh__44c1_sm_p5_0,
  125235. _vq_quantmap__44c1_sm_p5_0,
  125236. 17,
  125237. 17
  125238. };
  125239. static static_codebook _44c1_sm_p5_0 = {
  125240. 2, 289,
  125241. _vq_lengthlist__44c1_sm_p5_0,
  125242. 1, -529530880, 1611661312, 5, 0,
  125243. _vq_quantlist__44c1_sm_p5_0,
  125244. NULL,
  125245. &_vq_auxt__44c1_sm_p5_0,
  125246. NULL,
  125247. 0
  125248. };
  125249. static long _vq_quantlist__44c1_sm_p6_0[] = {
  125250. 1,
  125251. 0,
  125252. 2,
  125253. };
  125254. static long _vq_lengthlist__44c1_sm_p6_0[] = {
  125255. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  125256. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,10,11,
  125257. 11,11,10,10, 6, 9, 9,11,11,10,11,10,10, 6, 9, 9,
  125258. 11,10,11,11,10,10, 7,11,11,11,11,11,11,11,11, 6,
  125259. 9, 9,11,10,10,11,11,10, 6, 9, 9,10,10,10,11,10,
  125260. 11,
  125261. };
  125262. static float _vq_quantthresh__44c1_sm_p6_0[] = {
  125263. -5.5, 5.5,
  125264. };
  125265. static long _vq_quantmap__44c1_sm_p6_0[] = {
  125266. 1, 0, 2,
  125267. };
  125268. static encode_aux_threshmatch _vq_auxt__44c1_sm_p6_0 = {
  125269. _vq_quantthresh__44c1_sm_p6_0,
  125270. _vq_quantmap__44c1_sm_p6_0,
  125271. 3,
  125272. 3
  125273. };
  125274. static static_codebook _44c1_sm_p6_0 = {
  125275. 4, 81,
  125276. _vq_lengthlist__44c1_sm_p6_0,
  125277. 1, -529137664, 1618345984, 2, 0,
  125278. _vq_quantlist__44c1_sm_p6_0,
  125279. NULL,
  125280. &_vq_auxt__44c1_sm_p6_0,
  125281. NULL,
  125282. 0
  125283. };
  125284. static long _vq_quantlist__44c1_sm_p6_1[] = {
  125285. 5,
  125286. 4,
  125287. 6,
  125288. 3,
  125289. 7,
  125290. 2,
  125291. 8,
  125292. 1,
  125293. 9,
  125294. 0,
  125295. 10,
  125296. };
  125297. static long _vq_lengthlist__44c1_sm_p6_1[] = {
  125298. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  125299. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  125300. 8,10, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  125301. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  125302. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  125303. 8, 8, 8, 8, 8, 8, 9, 8,10,10,10,10,10, 8, 8, 8,
  125304. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  125305. 10,10,10, 8, 8, 8, 8, 8, 8,
  125306. };
  125307. static float _vq_quantthresh__44c1_sm_p6_1[] = {
  125308. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  125309. 3.5, 4.5,
  125310. };
  125311. static long _vq_quantmap__44c1_sm_p6_1[] = {
  125312. 9, 7, 5, 3, 1, 0, 2, 4,
  125313. 6, 8, 10,
  125314. };
  125315. static encode_aux_threshmatch _vq_auxt__44c1_sm_p6_1 = {
  125316. _vq_quantthresh__44c1_sm_p6_1,
  125317. _vq_quantmap__44c1_sm_p6_1,
  125318. 11,
  125319. 11
  125320. };
  125321. static static_codebook _44c1_sm_p6_1 = {
  125322. 2, 121,
  125323. _vq_lengthlist__44c1_sm_p6_1,
  125324. 1, -531365888, 1611661312, 4, 0,
  125325. _vq_quantlist__44c1_sm_p6_1,
  125326. NULL,
  125327. &_vq_auxt__44c1_sm_p6_1,
  125328. NULL,
  125329. 0
  125330. };
  125331. static long _vq_quantlist__44c1_sm_p7_0[] = {
  125332. 6,
  125333. 5,
  125334. 7,
  125335. 4,
  125336. 8,
  125337. 3,
  125338. 9,
  125339. 2,
  125340. 10,
  125341. 1,
  125342. 11,
  125343. 0,
  125344. 12,
  125345. };
  125346. static long _vq_lengthlist__44c1_sm_p7_0[] = {
  125347. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 5, 5,
  125348. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 6, 7, 7, 8,
  125349. 8, 8, 8, 9, 9,11,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  125350. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  125351. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  125352. 13, 9, 9, 9, 9,10,10,11,11,12,12, 0, 0, 0, 9,10,
  125353. 9,10,11,11,12,11,13,12, 0, 0, 0,10,10, 9, 9,11,
  125354. 11,12,12,13,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  125355. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  125356. 0, 0, 0, 0,11,12,11,11,12,13,14,13, 0, 0, 0, 0,
  125357. 0,12,12,11,11,13,12,14,13,
  125358. };
  125359. static float _vq_quantthresh__44c1_sm_p7_0[] = {
  125360. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  125361. 12.5, 17.5, 22.5, 27.5,
  125362. };
  125363. static long _vq_quantmap__44c1_sm_p7_0[] = {
  125364. 11, 9, 7, 5, 3, 1, 0, 2,
  125365. 4, 6, 8, 10, 12,
  125366. };
  125367. static encode_aux_threshmatch _vq_auxt__44c1_sm_p7_0 = {
  125368. _vq_quantthresh__44c1_sm_p7_0,
  125369. _vq_quantmap__44c1_sm_p7_0,
  125370. 13,
  125371. 13
  125372. };
  125373. static static_codebook _44c1_sm_p7_0 = {
  125374. 2, 169,
  125375. _vq_lengthlist__44c1_sm_p7_0,
  125376. 1, -526516224, 1616117760, 4, 0,
  125377. _vq_quantlist__44c1_sm_p7_0,
  125378. NULL,
  125379. &_vq_auxt__44c1_sm_p7_0,
  125380. NULL,
  125381. 0
  125382. };
  125383. static long _vq_quantlist__44c1_sm_p7_1[] = {
  125384. 2,
  125385. 1,
  125386. 3,
  125387. 0,
  125388. 4,
  125389. };
  125390. static long _vq_lengthlist__44c1_sm_p7_1[] = {
  125391. 2, 4, 4, 4, 5, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  125392. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  125393. };
  125394. static float _vq_quantthresh__44c1_sm_p7_1[] = {
  125395. -1.5, -0.5, 0.5, 1.5,
  125396. };
  125397. static long _vq_quantmap__44c1_sm_p7_1[] = {
  125398. 3, 1, 0, 2, 4,
  125399. };
  125400. static encode_aux_threshmatch _vq_auxt__44c1_sm_p7_1 = {
  125401. _vq_quantthresh__44c1_sm_p7_1,
  125402. _vq_quantmap__44c1_sm_p7_1,
  125403. 5,
  125404. 5
  125405. };
  125406. static static_codebook _44c1_sm_p7_1 = {
  125407. 2, 25,
  125408. _vq_lengthlist__44c1_sm_p7_1,
  125409. 1, -533725184, 1611661312, 3, 0,
  125410. _vq_quantlist__44c1_sm_p7_1,
  125411. NULL,
  125412. &_vq_auxt__44c1_sm_p7_1,
  125413. NULL,
  125414. 0
  125415. };
  125416. static long _vq_quantlist__44c1_sm_p8_0[] = {
  125417. 6,
  125418. 5,
  125419. 7,
  125420. 4,
  125421. 8,
  125422. 3,
  125423. 9,
  125424. 2,
  125425. 10,
  125426. 1,
  125427. 11,
  125428. 0,
  125429. 12,
  125430. };
  125431. static long _vq_lengthlist__44c1_sm_p8_0[] = {
  125432. 1, 3, 3,13,13,13,13,13,13,13,13,13,13, 3, 6, 6,
  125433. 13,13,13,13,13,13,13,13,13,13, 4, 8, 7,13,13,13,
  125434. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125435. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125436. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125437. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125438. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125439. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125440. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125441. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125442. 13,13,13,13,13,13,13,13,13,
  125443. };
  125444. static float _vq_quantthresh__44c1_sm_p8_0[] = {
  125445. -1215.5, -994.5, -773.5, -552.5, -331.5, -110.5, 110.5, 331.5,
  125446. 552.5, 773.5, 994.5, 1215.5,
  125447. };
  125448. static long _vq_quantmap__44c1_sm_p8_0[] = {
  125449. 11, 9, 7, 5, 3, 1, 0, 2,
  125450. 4, 6, 8, 10, 12,
  125451. };
  125452. static encode_aux_threshmatch _vq_auxt__44c1_sm_p8_0 = {
  125453. _vq_quantthresh__44c1_sm_p8_0,
  125454. _vq_quantmap__44c1_sm_p8_0,
  125455. 13,
  125456. 13
  125457. };
  125458. static static_codebook _44c1_sm_p8_0 = {
  125459. 2, 169,
  125460. _vq_lengthlist__44c1_sm_p8_0,
  125461. 1, -514541568, 1627103232, 4, 0,
  125462. _vq_quantlist__44c1_sm_p8_0,
  125463. NULL,
  125464. &_vq_auxt__44c1_sm_p8_0,
  125465. NULL,
  125466. 0
  125467. };
  125468. static long _vq_quantlist__44c1_sm_p8_1[] = {
  125469. 6,
  125470. 5,
  125471. 7,
  125472. 4,
  125473. 8,
  125474. 3,
  125475. 9,
  125476. 2,
  125477. 10,
  125478. 1,
  125479. 11,
  125480. 0,
  125481. 12,
  125482. };
  125483. static long _vq_lengthlist__44c1_sm_p8_1[] = {
  125484. 1, 4, 4, 6, 6, 7, 7, 9, 9,10,11,12,12, 6, 5, 5,
  125485. 7, 7, 8, 7,10,10,11,11,12,12, 6, 5, 5, 7, 7, 8,
  125486. 8,10,10,11,11,12,12,16, 7, 7, 8, 8, 9, 9,11,11,
  125487. 12,12,13,13,17, 7, 7, 8, 7, 9, 9,11,10,12,12,13,
  125488. 13,19,11,10, 8, 8,10,10,11,11,12,12,13,13,19,11,
  125489. 11, 9, 7,11,10,11,11,12,12,13,12,19,19,19,10,10,
  125490. 10,10,11,12,12,12,13,14,18,19,19,11, 9,11, 9,13,
  125491. 12,12,12,13,13,19,20,19,13,15,11,11,12,12,13,13,
  125492. 14,13,18,19,20,15,13,12,10,13,10,13,13,13,14,20,
  125493. 20,20,20,20,13,14,12,12,13,12,13,13,20,20,20,20,
  125494. 20,13,12,12,12,14,12,14,13,
  125495. };
  125496. static float _vq_quantthresh__44c1_sm_p8_1[] = {
  125497. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  125498. 42.5, 59.5, 76.5, 93.5,
  125499. };
  125500. static long _vq_quantmap__44c1_sm_p8_1[] = {
  125501. 11, 9, 7, 5, 3, 1, 0, 2,
  125502. 4, 6, 8, 10, 12,
  125503. };
  125504. static encode_aux_threshmatch _vq_auxt__44c1_sm_p8_1 = {
  125505. _vq_quantthresh__44c1_sm_p8_1,
  125506. _vq_quantmap__44c1_sm_p8_1,
  125507. 13,
  125508. 13
  125509. };
  125510. static static_codebook _44c1_sm_p8_1 = {
  125511. 2, 169,
  125512. _vq_lengthlist__44c1_sm_p8_1,
  125513. 1, -522616832, 1620115456, 4, 0,
  125514. _vq_quantlist__44c1_sm_p8_1,
  125515. NULL,
  125516. &_vq_auxt__44c1_sm_p8_1,
  125517. NULL,
  125518. 0
  125519. };
  125520. static long _vq_quantlist__44c1_sm_p8_2[] = {
  125521. 8,
  125522. 7,
  125523. 9,
  125524. 6,
  125525. 10,
  125526. 5,
  125527. 11,
  125528. 4,
  125529. 12,
  125530. 3,
  125531. 13,
  125532. 2,
  125533. 14,
  125534. 1,
  125535. 15,
  125536. 0,
  125537. 16,
  125538. };
  125539. static long _vq_lengthlist__44c1_sm_p8_2[] = {
  125540. 2, 5, 5, 6, 6, 7, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  125541. 8,10, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  125542. 9, 9,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  125543. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  125544. 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  125545. 9, 9, 9, 9, 9,10,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  125546. 9, 9,10,10, 9,10,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  125547. 9, 9, 9, 9, 9,10,10,11,10,10, 8, 8, 9, 9, 9, 9,
  125548. 9, 9, 9, 9, 9, 9,10, 9,10,10,10,11,11, 8, 8, 9,
  125549. 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,11,11,11, 9, 9,
  125550. 9, 9, 9, 9, 9, 9,10, 9,10, 9,11,11,11,11,11, 9,
  125551. 8, 9, 9, 9, 9, 9, 9, 9,10,10, 9,11,11,10,11,11,
  125552. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,11,11,11,11,
  125553. 11,11,11, 9, 9,10, 9, 9, 9, 9,10, 9,10,10,11,10,
  125554. 11,11,11,11, 9,10,10,10, 9, 9, 9, 9, 9, 9,10,11,
  125555. 11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,
  125556. 11,10,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9,10, 9,
  125557. 10,11,10,11,11,11,11,11,11, 9, 9,10, 9, 9, 9, 9,
  125558. 9,
  125559. };
  125560. static float _vq_quantthresh__44c1_sm_p8_2[] = {
  125561. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  125562. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  125563. };
  125564. static long _vq_quantmap__44c1_sm_p8_2[] = {
  125565. 15, 13, 11, 9, 7, 5, 3, 1,
  125566. 0, 2, 4, 6, 8, 10, 12, 14,
  125567. 16,
  125568. };
  125569. static encode_aux_threshmatch _vq_auxt__44c1_sm_p8_2 = {
  125570. _vq_quantthresh__44c1_sm_p8_2,
  125571. _vq_quantmap__44c1_sm_p8_2,
  125572. 17,
  125573. 17
  125574. };
  125575. static static_codebook _44c1_sm_p8_2 = {
  125576. 2, 289,
  125577. _vq_lengthlist__44c1_sm_p8_2,
  125578. 1, -529530880, 1611661312, 5, 0,
  125579. _vq_quantlist__44c1_sm_p8_2,
  125580. NULL,
  125581. &_vq_auxt__44c1_sm_p8_2,
  125582. NULL,
  125583. 0
  125584. };
  125585. static long _huff_lengthlist__44c1_sm_short[] = {
  125586. 4, 7,13,14,14,15,16,18,18, 4, 2, 5, 8, 7, 9,12,
  125587. 15,15,10, 4, 5,10, 6, 8,11,15,17,12, 5, 7, 5, 6,
  125588. 8,11,14,17,11, 5, 6, 6, 5, 6, 9,13,17,12, 6, 7,
  125589. 6, 5, 6, 8,12,14,14, 7, 8, 6, 6, 7, 9,11,14,14,
  125590. 8, 9, 6, 5, 6, 9,11,13,16,10,10, 7, 6, 7, 8,10,
  125591. 11,
  125592. };
  125593. static static_codebook _huff_book__44c1_sm_short = {
  125594. 2, 81,
  125595. _huff_lengthlist__44c1_sm_short,
  125596. 0, 0, 0, 0, 0,
  125597. NULL,
  125598. NULL,
  125599. NULL,
  125600. NULL,
  125601. 0
  125602. };
  125603. static long _huff_lengthlist__44cn1_s_long[] = {
  125604. 4, 4, 7, 8, 7, 8,10,12,17, 3, 1, 6, 6, 7, 8,10,
  125605. 12,15, 7, 6, 9, 9, 9,11,12,14,17, 8, 6, 9, 6, 7,
  125606. 9,11,13,17, 7, 6, 9, 7, 7, 8, 9,12,15, 8, 8,10,
  125607. 8, 7, 7, 7,10,14, 9,10,12,10, 8, 8, 8,10,14,11,
  125608. 13,15,13,12,11,11,12,16,17,18,18,19,20,18,16,16,
  125609. 20,
  125610. };
  125611. static static_codebook _huff_book__44cn1_s_long = {
  125612. 2, 81,
  125613. _huff_lengthlist__44cn1_s_long,
  125614. 0, 0, 0, 0, 0,
  125615. NULL,
  125616. NULL,
  125617. NULL,
  125618. NULL,
  125619. 0
  125620. };
  125621. static long _vq_quantlist__44cn1_s_p1_0[] = {
  125622. 1,
  125623. 0,
  125624. 2,
  125625. };
  125626. static long _vq_lengthlist__44cn1_s_p1_0[] = {
  125627. 1, 4, 4, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  125628. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125632. 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0,
  125633. 0, 0, 0, 7, 9,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125637. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7,10, 9, 0, 0,
  125638. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  125673. 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 8, 9,10, 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, 7,10,10, 0, 0, 0,
  125678. 0, 0, 0, 9, 9,11, 0, 0, 0, 0, 0, 0,10,11,11, 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, 7,10,10, 0, 0,
  125683. 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0,10,11,11,
  125684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125718. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0,
  125719. 0, 0, 0, 0, 8,10,10, 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, 7,10,10, 0, 0, 0, 0, 0, 0,10,11,11, 0,
  125724. 0, 0, 0, 0, 0, 9, 9,11, 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, 7,10,10, 0, 0, 0, 0, 0, 0,10,11,11,
  125729. 0, 0, 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0, 0,
  125730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125960. 0, 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,
  126038. };
  126039. static float _vq_quantthresh__44cn1_s_p1_0[] = {
  126040. -0.5, 0.5,
  126041. };
  126042. static long _vq_quantmap__44cn1_s_p1_0[] = {
  126043. 1, 0, 2,
  126044. };
  126045. static encode_aux_threshmatch _vq_auxt__44cn1_s_p1_0 = {
  126046. _vq_quantthresh__44cn1_s_p1_0,
  126047. _vq_quantmap__44cn1_s_p1_0,
  126048. 3,
  126049. 3
  126050. };
  126051. static static_codebook _44cn1_s_p1_0 = {
  126052. 8, 6561,
  126053. _vq_lengthlist__44cn1_s_p1_0,
  126054. 1, -535822336, 1611661312, 2, 0,
  126055. _vq_quantlist__44cn1_s_p1_0,
  126056. NULL,
  126057. &_vq_auxt__44cn1_s_p1_0,
  126058. NULL,
  126059. 0
  126060. };
  126061. static long _vq_quantlist__44cn1_s_p2_0[] = {
  126062. 2,
  126063. 1,
  126064. 3,
  126065. 0,
  126066. 4,
  126067. };
  126068. static long _vq_lengthlist__44cn1_s_p2_0[] = {
  126069. 1, 4, 4, 7, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  126071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126072. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  126074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126075. 0, 0, 0, 0, 6, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  126076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126108. 0,
  126109. };
  126110. static float _vq_quantthresh__44cn1_s_p2_0[] = {
  126111. -1.5, -0.5, 0.5, 1.5,
  126112. };
  126113. static long _vq_quantmap__44cn1_s_p2_0[] = {
  126114. 3, 1, 0, 2, 4,
  126115. };
  126116. static encode_aux_threshmatch _vq_auxt__44cn1_s_p2_0 = {
  126117. _vq_quantthresh__44cn1_s_p2_0,
  126118. _vq_quantmap__44cn1_s_p2_0,
  126119. 5,
  126120. 5
  126121. };
  126122. static static_codebook _44cn1_s_p2_0 = {
  126123. 4, 625,
  126124. _vq_lengthlist__44cn1_s_p2_0,
  126125. 1, -533725184, 1611661312, 3, 0,
  126126. _vq_quantlist__44cn1_s_p2_0,
  126127. NULL,
  126128. &_vq_auxt__44cn1_s_p2_0,
  126129. NULL,
  126130. 0
  126131. };
  126132. static long _vq_quantlist__44cn1_s_p3_0[] = {
  126133. 4,
  126134. 3,
  126135. 5,
  126136. 2,
  126137. 6,
  126138. 1,
  126139. 7,
  126140. 0,
  126141. 8,
  126142. };
  126143. static long _vq_lengthlist__44cn1_s_p3_0[] = {
  126144. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  126145. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  126146. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  126147. 9, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  126148. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126149. 0,
  126150. };
  126151. static float _vq_quantthresh__44cn1_s_p3_0[] = {
  126152. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  126153. };
  126154. static long _vq_quantmap__44cn1_s_p3_0[] = {
  126155. 7, 5, 3, 1, 0, 2, 4, 6,
  126156. 8,
  126157. };
  126158. static encode_aux_threshmatch _vq_auxt__44cn1_s_p3_0 = {
  126159. _vq_quantthresh__44cn1_s_p3_0,
  126160. _vq_quantmap__44cn1_s_p3_0,
  126161. 9,
  126162. 9
  126163. };
  126164. static static_codebook _44cn1_s_p3_0 = {
  126165. 2, 81,
  126166. _vq_lengthlist__44cn1_s_p3_0,
  126167. 1, -531628032, 1611661312, 4, 0,
  126168. _vq_quantlist__44cn1_s_p3_0,
  126169. NULL,
  126170. &_vq_auxt__44cn1_s_p3_0,
  126171. NULL,
  126172. 0
  126173. };
  126174. static long _vq_quantlist__44cn1_s_p4_0[] = {
  126175. 4,
  126176. 3,
  126177. 5,
  126178. 2,
  126179. 6,
  126180. 1,
  126181. 7,
  126182. 0,
  126183. 8,
  126184. };
  126185. static long _vq_lengthlist__44cn1_s_p4_0[] = {
  126186. 1, 3, 3, 6, 6, 6, 6, 8, 8, 0, 0, 0, 6, 6, 7, 7,
  126187. 9, 9, 0, 0, 0, 6, 6, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  126188. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  126189. 9, 9, 9, 9,10,10, 0, 0, 0, 9, 9, 9, 9,10,10, 0,
  126190. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0,10,10,11,
  126191. 11,
  126192. };
  126193. static float _vq_quantthresh__44cn1_s_p4_0[] = {
  126194. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  126195. };
  126196. static long _vq_quantmap__44cn1_s_p4_0[] = {
  126197. 7, 5, 3, 1, 0, 2, 4, 6,
  126198. 8,
  126199. };
  126200. static encode_aux_threshmatch _vq_auxt__44cn1_s_p4_0 = {
  126201. _vq_quantthresh__44cn1_s_p4_0,
  126202. _vq_quantmap__44cn1_s_p4_0,
  126203. 9,
  126204. 9
  126205. };
  126206. static static_codebook _44cn1_s_p4_0 = {
  126207. 2, 81,
  126208. _vq_lengthlist__44cn1_s_p4_0,
  126209. 1, -531628032, 1611661312, 4, 0,
  126210. _vq_quantlist__44cn1_s_p4_0,
  126211. NULL,
  126212. &_vq_auxt__44cn1_s_p4_0,
  126213. NULL,
  126214. 0
  126215. };
  126216. static long _vq_quantlist__44cn1_s_p5_0[] = {
  126217. 8,
  126218. 7,
  126219. 9,
  126220. 6,
  126221. 10,
  126222. 5,
  126223. 11,
  126224. 4,
  126225. 12,
  126226. 3,
  126227. 13,
  126228. 2,
  126229. 14,
  126230. 1,
  126231. 15,
  126232. 0,
  126233. 16,
  126234. };
  126235. static long _vq_lengthlist__44cn1_s_p5_0[] = {
  126236. 1, 4, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,10,
  126237. 10, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,
  126238. 11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  126239. 10,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  126240. 11,11,11,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  126241. 10,11,11,11,11, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,10,
  126242. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,
  126243. 10,10,11,11,11,12,12, 0, 0, 0, 9, 9,10, 9,10,10,
  126244. 10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  126245. 10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,
  126246. 10,10,10,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  126247. 9,10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  126248. 10,10,11,10,11,11,11,12,13,12,13,13, 0, 0, 0, 0,
  126249. 0, 0, 0,11,10,11,11,12,12,12,12,13,13, 0, 0, 0,
  126250. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0, 0,
  126251. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0,
  126252. 0, 0, 0, 0, 0, 0,12,12,12,13,13,13,13,13,14,14,
  126253. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,12,13,13,14,
  126254. 14,
  126255. };
  126256. static float _vq_quantthresh__44cn1_s_p5_0[] = {
  126257. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  126258. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  126259. };
  126260. static long _vq_quantmap__44cn1_s_p5_0[] = {
  126261. 15, 13, 11, 9, 7, 5, 3, 1,
  126262. 0, 2, 4, 6, 8, 10, 12, 14,
  126263. 16,
  126264. };
  126265. static encode_aux_threshmatch _vq_auxt__44cn1_s_p5_0 = {
  126266. _vq_quantthresh__44cn1_s_p5_0,
  126267. _vq_quantmap__44cn1_s_p5_0,
  126268. 17,
  126269. 17
  126270. };
  126271. static static_codebook _44cn1_s_p5_0 = {
  126272. 2, 289,
  126273. _vq_lengthlist__44cn1_s_p5_0,
  126274. 1, -529530880, 1611661312, 5, 0,
  126275. _vq_quantlist__44cn1_s_p5_0,
  126276. NULL,
  126277. &_vq_auxt__44cn1_s_p5_0,
  126278. NULL,
  126279. 0
  126280. };
  126281. static long _vq_quantlist__44cn1_s_p6_0[] = {
  126282. 1,
  126283. 0,
  126284. 2,
  126285. };
  126286. static long _vq_lengthlist__44cn1_s_p6_0[] = {
  126287. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 6, 6,10, 9, 9,11,
  126288. 9, 9, 4, 6, 6,10, 9, 9,10, 9, 9, 7,10,10,11,11,
  126289. 11,12,11,11, 7, 9, 9,11,11,10,11,10,10, 7, 9, 9,
  126290. 11,10,11,11,10,10, 7,10,10,11,11,11,12,11,11, 7,
  126291. 9, 9,11,10,10,11,10,10, 7, 9, 9,11,10,10,11,10,
  126292. 10,
  126293. };
  126294. static float _vq_quantthresh__44cn1_s_p6_0[] = {
  126295. -5.5, 5.5,
  126296. };
  126297. static long _vq_quantmap__44cn1_s_p6_0[] = {
  126298. 1, 0, 2,
  126299. };
  126300. static encode_aux_threshmatch _vq_auxt__44cn1_s_p6_0 = {
  126301. _vq_quantthresh__44cn1_s_p6_0,
  126302. _vq_quantmap__44cn1_s_p6_0,
  126303. 3,
  126304. 3
  126305. };
  126306. static static_codebook _44cn1_s_p6_0 = {
  126307. 4, 81,
  126308. _vq_lengthlist__44cn1_s_p6_0,
  126309. 1, -529137664, 1618345984, 2, 0,
  126310. _vq_quantlist__44cn1_s_p6_0,
  126311. NULL,
  126312. &_vq_auxt__44cn1_s_p6_0,
  126313. NULL,
  126314. 0
  126315. };
  126316. static long _vq_quantlist__44cn1_s_p6_1[] = {
  126317. 5,
  126318. 4,
  126319. 6,
  126320. 3,
  126321. 7,
  126322. 2,
  126323. 8,
  126324. 1,
  126325. 9,
  126326. 0,
  126327. 10,
  126328. };
  126329. static long _vq_lengthlist__44cn1_s_p6_1[] = {
  126330. 1, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8,10,10,10, 7, 6,
  126331. 8, 8, 8, 8, 8, 8,10,10,10, 7, 6, 7, 7, 8, 8, 8,
  126332. 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  126333. 7, 8, 8, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 9, 9,
  126334. 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,
  126335. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9,
  126336. 9, 9, 9,10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,10,
  126337. 10,10,10, 9, 9, 9, 9, 9, 9,
  126338. };
  126339. static float _vq_quantthresh__44cn1_s_p6_1[] = {
  126340. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  126341. 3.5, 4.5,
  126342. };
  126343. static long _vq_quantmap__44cn1_s_p6_1[] = {
  126344. 9, 7, 5, 3, 1, 0, 2, 4,
  126345. 6, 8, 10,
  126346. };
  126347. static encode_aux_threshmatch _vq_auxt__44cn1_s_p6_1 = {
  126348. _vq_quantthresh__44cn1_s_p6_1,
  126349. _vq_quantmap__44cn1_s_p6_1,
  126350. 11,
  126351. 11
  126352. };
  126353. static static_codebook _44cn1_s_p6_1 = {
  126354. 2, 121,
  126355. _vq_lengthlist__44cn1_s_p6_1,
  126356. 1, -531365888, 1611661312, 4, 0,
  126357. _vq_quantlist__44cn1_s_p6_1,
  126358. NULL,
  126359. &_vq_auxt__44cn1_s_p6_1,
  126360. NULL,
  126361. 0
  126362. };
  126363. static long _vq_quantlist__44cn1_s_p7_0[] = {
  126364. 6,
  126365. 5,
  126366. 7,
  126367. 4,
  126368. 8,
  126369. 3,
  126370. 9,
  126371. 2,
  126372. 10,
  126373. 1,
  126374. 11,
  126375. 0,
  126376. 12,
  126377. };
  126378. static long _vq_lengthlist__44cn1_s_p7_0[] = {
  126379. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  126380. 7, 7, 8, 8, 8, 8, 9, 9,11,11, 7, 5, 5, 7, 7, 8,
  126381. 8, 8, 8, 9,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  126382. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  126383. 11, 0,12,12, 9, 9, 9,10,10,10,11,11,11,12, 0,13,
  126384. 13, 9, 9, 9, 9,10,10,11,11,11,12, 0, 0, 0,10,10,
  126385. 10,10,11,11,12,12,12,13, 0, 0, 0,10,10,10,10,11,
  126386. 11,12,12,13,12, 0, 0, 0,14,14,11,10,11,12,12,13,
  126387. 13,14, 0, 0, 0,15,15,11,11,12,11,12,12,14,13, 0,
  126388. 0, 0, 0, 0,12,12,12,12,13,13,14,14, 0, 0, 0, 0,
  126389. 0,13,13,12,12,13,13,13,14,
  126390. };
  126391. static float _vq_quantthresh__44cn1_s_p7_0[] = {
  126392. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  126393. 12.5, 17.5, 22.5, 27.5,
  126394. };
  126395. static long _vq_quantmap__44cn1_s_p7_0[] = {
  126396. 11, 9, 7, 5, 3, 1, 0, 2,
  126397. 4, 6, 8, 10, 12,
  126398. };
  126399. static encode_aux_threshmatch _vq_auxt__44cn1_s_p7_0 = {
  126400. _vq_quantthresh__44cn1_s_p7_0,
  126401. _vq_quantmap__44cn1_s_p7_0,
  126402. 13,
  126403. 13
  126404. };
  126405. static static_codebook _44cn1_s_p7_0 = {
  126406. 2, 169,
  126407. _vq_lengthlist__44cn1_s_p7_0,
  126408. 1, -526516224, 1616117760, 4, 0,
  126409. _vq_quantlist__44cn1_s_p7_0,
  126410. NULL,
  126411. &_vq_auxt__44cn1_s_p7_0,
  126412. NULL,
  126413. 0
  126414. };
  126415. static long _vq_quantlist__44cn1_s_p7_1[] = {
  126416. 2,
  126417. 1,
  126418. 3,
  126419. 0,
  126420. 4,
  126421. };
  126422. static long _vq_lengthlist__44cn1_s_p7_1[] = {
  126423. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  126424. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  126425. };
  126426. static float _vq_quantthresh__44cn1_s_p7_1[] = {
  126427. -1.5, -0.5, 0.5, 1.5,
  126428. };
  126429. static long _vq_quantmap__44cn1_s_p7_1[] = {
  126430. 3, 1, 0, 2, 4,
  126431. };
  126432. static encode_aux_threshmatch _vq_auxt__44cn1_s_p7_1 = {
  126433. _vq_quantthresh__44cn1_s_p7_1,
  126434. _vq_quantmap__44cn1_s_p7_1,
  126435. 5,
  126436. 5
  126437. };
  126438. static static_codebook _44cn1_s_p7_1 = {
  126439. 2, 25,
  126440. _vq_lengthlist__44cn1_s_p7_1,
  126441. 1, -533725184, 1611661312, 3, 0,
  126442. _vq_quantlist__44cn1_s_p7_1,
  126443. NULL,
  126444. &_vq_auxt__44cn1_s_p7_1,
  126445. NULL,
  126446. 0
  126447. };
  126448. static long _vq_quantlist__44cn1_s_p8_0[] = {
  126449. 2,
  126450. 1,
  126451. 3,
  126452. 0,
  126453. 4,
  126454. };
  126455. static long _vq_lengthlist__44cn1_s_p8_0[] = {
  126456. 1, 7, 7,11,11, 8,11,11,11,11, 4,11, 3,11,11,11,
  126457. 11,11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,
  126458. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126459. 11,11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,
  126460. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126461. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126462. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126463. 11,11,11,11,11,11,11,11,11,11,11,11,11, 7,11,11,
  126464. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126465. 11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,
  126466. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
  126467. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126468. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126469. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126470. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126471. 11,11,11,11,11,11,11,11,11,11, 8,11,11,11,11,11,
  126472. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126473. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126474. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126475. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126476. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126477. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126478. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126479. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126480. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126481. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126482. 11,11,11,11,11,11,11,11,11,11,11,11,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,11,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,11,11,11,
  126489. 11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,
  126490. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126491. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126492. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126493. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126494. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126495. 12,
  126496. };
  126497. static float _vq_quantthresh__44cn1_s_p8_0[] = {
  126498. -331.5, -110.5, 110.5, 331.5,
  126499. };
  126500. static long _vq_quantmap__44cn1_s_p8_0[] = {
  126501. 3, 1, 0, 2, 4,
  126502. };
  126503. static encode_aux_threshmatch _vq_auxt__44cn1_s_p8_0 = {
  126504. _vq_quantthresh__44cn1_s_p8_0,
  126505. _vq_quantmap__44cn1_s_p8_0,
  126506. 5,
  126507. 5
  126508. };
  126509. static static_codebook _44cn1_s_p8_0 = {
  126510. 4, 625,
  126511. _vq_lengthlist__44cn1_s_p8_0,
  126512. 1, -518283264, 1627103232, 3, 0,
  126513. _vq_quantlist__44cn1_s_p8_0,
  126514. NULL,
  126515. &_vq_auxt__44cn1_s_p8_0,
  126516. NULL,
  126517. 0
  126518. };
  126519. static long _vq_quantlist__44cn1_s_p8_1[] = {
  126520. 6,
  126521. 5,
  126522. 7,
  126523. 4,
  126524. 8,
  126525. 3,
  126526. 9,
  126527. 2,
  126528. 10,
  126529. 1,
  126530. 11,
  126531. 0,
  126532. 12,
  126533. };
  126534. static long _vq_lengthlist__44cn1_s_p8_1[] = {
  126535. 1, 4, 4, 6, 6, 8, 8, 9,10,10,11,11,11, 6, 5, 5,
  126536. 7, 7, 8, 8, 9,10, 9,11,11,12, 5, 5, 5, 7, 7, 8,
  126537. 9,10,10,12,12,14,13,15, 7, 7, 8, 8, 9,10,11,11,
  126538. 10,12,10,11,15, 7, 8, 8, 8, 9, 9,11,11,13,12,12,
  126539. 13,15,10,10, 8, 8,10,10,12,12,11,14,10,10,15,11,
  126540. 11, 8, 8,10,10,12,13,13,14,15,13,15,15,15,10,10,
  126541. 10,10,12,12,13,12,13,10,15,15,15,10,10,11,10,13,
  126542. 11,13,13,15,13,15,15,15,13,13,10,11,11,11,12,10,
  126543. 14,11,15,15,14,14,13,10,10,12,11,13,13,14,14,15,
  126544. 15,15,15,15,11,11,11,11,12,11,15,12,15,15,15,15,
  126545. 15,12,12,11,11,14,12,13,14,
  126546. };
  126547. static float _vq_quantthresh__44cn1_s_p8_1[] = {
  126548. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  126549. 42.5, 59.5, 76.5, 93.5,
  126550. };
  126551. static long _vq_quantmap__44cn1_s_p8_1[] = {
  126552. 11, 9, 7, 5, 3, 1, 0, 2,
  126553. 4, 6, 8, 10, 12,
  126554. };
  126555. static encode_aux_threshmatch _vq_auxt__44cn1_s_p8_1 = {
  126556. _vq_quantthresh__44cn1_s_p8_1,
  126557. _vq_quantmap__44cn1_s_p8_1,
  126558. 13,
  126559. 13
  126560. };
  126561. static static_codebook _44cn1_s_p8_1 = {
  126562. 2, 169,
  126563. _vq_lengthlist__44cn1_s_p8_1,
  126564. 1, -522616832, 1620115456, 4, 0,
  126565. _vq_quantlist__44cn1_s_p8_1,
  126566. NULL,
  126567. &_vq_auxt__44cn1_s_p8_1,
  126568. NULL,
  126569. 0
  126570. };
  126571. static long _vq_quantlist__44cn1_s_p8_2[] = {
  126572. 8,
  126573. 7,
  126574. 9,
  126575. 6,
  126576. 10,
  126577. 5,
  126578. 11,
  126579. 4,
  126580. 12,
  126581. 3,
  126582. 13,
  126583. 2,
  126584. 14,
  126585. 1,
  126586. 15,
  126587. 0,
  126588. 16,
  126589. };
  126590. static long _vq_lengthlist__44cn1_s_p8_2[] = {
  126591. 3, 4, 3, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  126592. 9,10,11,11, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  126593. 9, 9,10,10,10, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  126594. 9, 9, 9,10,10,10, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9,
  126595. 9, 9,10, 9,10,11,10, 7, 6, 7, 7, 8, 8, 9, 9, 9,
  126596. 9, 9, 9, 9,10,10,10,11, 7, 7, 8, 8, 8, 8, 9, 9,
  126597. 9, 9, 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 8, 9,
  126598. 9, 9, 9, 9, 9, 9,10,11,11,11, 8, 8, 8, 8, 8, 8,
  126599. 9, 9, 9, 9, 9, 9, 9, 9,11,10,10,11,11, 8, 8, 8,
  126600. 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,11,11, 9, 9,
  126601. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,10,11,11, 9,
  126602. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,11,10,11,11,
  126603. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,10,11,
  126604. 11,11,11, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,11,11,
  126605. 10,11,11,11, 9,10,10, 9, 9, 9, 9, 9, 9, 9,10,11,
  126606. 11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  126607. 11,11,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  126608. 11,11,11,10,11,11,11,11,11, 9, 9, 9,10, 9, 9, 9,
  126609. 9,
  126610. };
  126611. static float _vq_quantthresh__44cn1_s_p8_2[] = {
  126612. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  126613. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  126614. };
  126615. static long _vq_quantmap__44cn1_s_p8_2[] = {
  126616. 15, 13, 11, 9, 7, 5, 3, 1,
  126617. 0, 2, 4, 6, 8, 10, 12, 14,
  126618. 16,
  126619. };
  126620. static encode_aux_threshmatch _vq_auxt__44cn1_s_p8_2 = {
  126621. _vq_quantthresh__44cn1_s_p8_2,
  126622. _vq_quantmap__44cn1_s_p8_2,
  126623. 17,
  126624. 17
  126625. };
  126626. static static_codebook _44cn1_s_p8_2 = {
  126627. 2, 289,
  126628. _vq_lengthlist__44cn1_s_p8_2,
  126629. 1, -529530880, 1611661312, 5, 0,
  126630. _vq_quantlist__44cn1_s_p8_2,
  126631. NULL,
  126632. &_vq_auxt__44cn1_s_p8_2,
  126633. NULL,
  126634. 0
  126635. };
  126636. static long _huff_lengthlist__44cn1_s_short[] = {
  126637. 10, 9,12,15,12,13,16,14,16, 7, 1, 5,14, 7,10,13,
  126638. 16,16, 9, 4, 6,16, 8,11,16,16,16,14, 4, 7,16, 9,
  126639. 12,14,16,16,10, 5, 7,14, 9,12,14,15,15,13, 8, 9,
  126640. 14,10,12,13,14,15,13, 9, 9, 7, 6, 8,11,12,12,14,
  126641. 8, 8, 5, 4, 5, 8,11,12,16,10,10, 6, 5, 6, 8, 9,
  126642. 10,
  126643. };
  126644. static static_codebook _huff_book__44cn1_s_short = {
  126645. 2, 81,
  126646. _huff_lengthlist__44cn1_s_short,
  126647. 0, 0, 0, 0, 0,
  126648. NULL,
  126649. NULL,
  126650. NULL,
  126651. NULL,
  126652. 0
  126653. };
  126654. static long _huff_lengthlist__44cn1_sm_long[] = {
  126655. 3, 3, 8, 8, 8, 8,10,12,14, 3, 2, 6, 7, 7, 8,10,
  126656. 12,16, 7, 6, 7, 9, 8,10,12,14,16, 8, 6, 8, 4, 5,
  126657. 7, 9,11,13, 7, 6, 8, 5, 6, 7, 9,11,14, 8, 8,10,
  126658. 7, 7, 6, 8,10,13, 9,11,12, 9, 9, 7, 8,10,12,10,
  126659. 13,15,11,11,10, 9,10,13,13,16,17,14,15,14,13,14,
  126660. 17,
  126661. };
  126662. static static_codebook _huff_book__44cn1_sm_long = {
  126663. 2, 81,
  126664. _huff_lengthlist__44cn1_sm_long,
  126665. 0, 0, 0, 0, 0,
  126666. NULL,
  126667. NULL,
  126668. NULL,
  126669. NULL,
  126670. 0
  126671. };
  126672. static long _vq_quantlist__44cn1_sm_p1_0[] = {
  126673. 1,
  126674. 0,
  126675. 2,
  126676. };
  126677. static long _vq_lengthlist__44cn1_sm_p1_0[] = {
  126678. 1, 4, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  126679. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126683. 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0,
  126684. 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126688. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  126689. 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  126724. 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 7,10, 9, 0, 0, 0,
  126729. 0, 0, 0, 9, 9,10, 0, 0, 0, 0, 0, 0, 9,10,10, 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, 7, 9, 9, 0, 0,
  126734. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  126735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126769. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  126770. 0, 0, 0, 0, 8, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  126775. 0, 0, 0, 0, 0, 8, 9,10, 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, 7, 9,10, 0, 0, 0, 0, 0, 0, 9,10,10,
  126780. 0, 0, 0, 0, 0, 0, 9,10, 9, 0, 0, 0, 0, 0, 0, 0,
  126781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127011. 0, 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,
  127089. };
  127090. static float _vq_quantthresh__44cn1_sm_p1_0[] = {
  127091. -0.5, 0.5,
  127092. };
  127093. static long _vq_quantmap__44cn1_sm_p1_0[] = {
  127094. 1, 0, 2,
  127095. };
  127096. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p1_0 = {
  127097. _vq_quantthresh__44cn1_sm_p1_0,
  127098. _vq_quantmap__44cn1_sm_p1_0,
  127099. 3,
  127100. 3
  127101. };
  127102. static static_codebook _44cn1_sm_p1_0 = {
  127103. 8, 6561,
  127104. _vq_lengthlist__44cn1_sm_p1_0,
  127105. 1, -535822336, 1611661312, 2, 0,
  127106. _vq_quantlist__44cn1_sm_p1_0,
  127107. NULL,
  127108. &_vq_auxt__44cn1_sm_p1_0,
  127109. NULL,
  127110. 0
  127111. };
  127112. static long _vq_quantlist__44cn1_sm_p2_0[] = {
  127113. 2,
  127114. 1,
  127115. 3,
  127116. 0,
  127117. 4,
  127118. };
  127119. static long _vq_lengthlist__44cn1_sm_p2_0[] = {
  127120. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  127122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127123. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  127125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127126. 0, 0, 0, 0, 7, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  127127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127159. 0,
  127160. };
  127161. static float _vq_quantthresh__44cn1_sm_p2_0[] = {
  127162. -1.5, -0.5, 0.5, 1.5,
  127163. };
  127164. static long _vq_quantmap__44cn1_sm_p2_0[] = {
  127165. 3, 1, 0, 2, 4,
  127166. };
  127167. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p2_0 = {
  127168. _vq_quantthresh__44cn1_sm_p2_0,
  127169. _vq_quantmap__44cn1_sm_p2_0,
  127170. 5,
  127171. 5
  127172. };
  127173. static static_codebook _44cn1_sm_p2_0 = {
  127174. 4, 625,
  127175. _vq_lengthlist__44cn1_sm_p2_0,
  127176. 1, -533725184, 1611661312, 3, 0,
  127177. _vq_quantlist__44cn1_sm_p2_0,
  127178. NULL,
  127179. &_vq_auxt__44cn1_sm_p2_0,
  127180. NULL,
  127181. 0
  127182. };
  127183. static long _vq_quantlist__44cn1_sm_p3_0[] = {
  127184. 4,
  127185. 3,
  127186. 5,
  127187. 2,
  127188. 6,
  127189. 1,
  127190. 7,
  127191. 0,
  127192. 8,
  127193. };
  127194. static long _vq_lengthlist__44cn1_sm_p3_0[] = {
  127195. 1, 3, 4, 7, 7, 0, 0, 0, 0, 0, 4, 4, 7, 7, 0, 0,
  127196. 0, 0, 0, 4, 5, 7, 7, 0, 0, 0, 0, 0, 6, 7, 8, 8,
  127197. 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  127198. 9, 9, 0, 0, 0, 0, 0, 0, 0,10, 9, 0, 0, 0, 0, 0,
  127199. 0, 0,11,11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127200. 0,
  127201. };
  127202. static float _vq_quantthresh__44cn1_sm_p3_0[] = {
  127203. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  127204. };
  127205. static long _vq_quantmap__44cn1_sm_p3_0[] = {
  127206. 7, 5, 3, 1, 0, 2, 4, 6,
  127207. 8,
  127208. };
  127209. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p3_0 = {
  127210. _vq_quantthresh__44cn1_sm_p3_0,
  127211. _vq_quantmap__44cn1_sm_p3_0,
  127212. 9,
  127213. 9
  127214. };
  127215. static static_codebook _44cn1_sm_p3_0 = {
  127216. 2, 81,
  127217. _vq_lengthlist__44cn1_sm_p3_0,
  127218. 1, -531628032, 1611661312, 4, 0,
  127219. _vq_quantlist__44cn1_sm_p3_0,
  127220. NULL,
  127221. &_vq_auxt__44cn1_sm_p3_0,
  127222. NULL,
  127223. 0
  127224. };
  127225. static long _vq_quantlist__44cn1_sm_p4_0[] = {
  127226. 4,
  127227. 3,
  127228. 5,
  127229. 2,
  127230. 6,
  127231. 1,
  127232. 7,
  127233. 0,
  127234. 8,
  127235. };
  127236. static long _vq_lengthlist__44cn1_sm_p4_0[] = {
  127237. 1, 4, 3, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 8, 7,
  127238. 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  127239. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  127240. 9, 9, 9, 9,10,10, 0, 0, 0, 9, 9, 9, 9,10,10, 0,
  127241. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0,10,10,11,
  127242. 11,
  127243. };
  127244. static float _vq_quantthresh__44cn1_sm_p4_0[] = {
  127245. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  127246. };
  127247. static long _vq_quantmap__44cn1_sm_p4_0[] = {
  127248. 7, 5, 3, 1, 0, 2, 4, 6,
  127249. 8,
  127250. };
  127251. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p4_0 = {
  127252. _vq_quantthresh__44cn1_sm_p4_0,
  127253. _vq_quantmap__44cn1_sm_p4_0,
  127254. 9,
  127255. 9
  127256. };
  127257. static static_codebook _44cn1_sm_p4_0 = {
  127258. 2, 81,
  127259. _vq_lengthlist__44cn1_sm_p4_0,
  127260. 1, -531628032, 1611661312, 4, 0,
  127261. _vq_quantlist__44cn1_sm_p4_0,
  127262. NULL,
  127263. &_vq_auxt__44cn1_sm_p4_0,
  127264. NULL,
  127265. 0
  127266. };
  127267. static long _vq_quantlist__44cn1_sm_p5_0[] = {
  127268. 8,
  127269. 7,
  127270. 9,
  127271. 6,
  127272. 10,
  127273. 5,
  127274. 11,
  127275. 4,
  127276. 12,
  127277. 3,
  127278. 13,
  127279. 2,
  127280. 14,
  127281. 1,
  127282. 15,
  127283. 0,
  127284. 16,
  127285. };
  127286. static long _vq_lengthlist__44cn1_sm_p5_0[] = {
  127287. 1, 4, 4, 6, 6, 8, 8, 9, 9, 8, 8, 9, 9,10,10,11,
  127288. 11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  127289. 12,12, 0, 6, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  127290. 11,12,12, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  127291. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,10,11,
  127292. 11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  127293. 11,11,12,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  127294. 10,11,11,12,12,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  127295. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,10,
  127296. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  127297. 10,10,11,11,12,12,13,13,13,13, 0, 0, 0, 0, 0, 9,
  127298. 9,10,10,11,11,12,12,12,13,13,13, 0, 0, 0, 0, 0,
  127299. 10,10,11,11,11,11,12,12,13,13,14,14, 0, 0, 0, 0,
  127300. 0, 0, 0,11,11,11,11,12,12,13,13,14,14, 0, 0, 0,
  127301. 0, 0, 0, 0,11,11,12,12,13,13,13,13,14,14, 0, 0,
  127302. 0, 0, 0, 0, 0,11,11,12,12,13,13,13,13,14,14, 0,
  127303. 0, 0, 0, 0, 0, 0,12,12,12,13,13,13,14,14,14,14,
  127304. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,14,14,14,
  127305. 14,
  127306. };
  127307. static float _vq_quantthresh__44cn1_sm_p5_0[] = {
  127308. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  127309. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  127310. };
  127311. static long _vq_quantmap__44cn1_sm_p5_0[] = {
  127312. 15, 13, 11, 9, 7, 5, 3, 1,
  127313. 0, 2, 4, 6, 8, 10, 12, 14,
  127314. 16,
  127315. };
  127316. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p5_0 = {
  127317. _vq_quantthresh__44cn1_sm_p5_0,
  127318. _vq_quantmap__44cn1_sm_p5_0,
  127319. 17,
  127320. 17
  127321. };
  127322. static static_codebook _44cn1_sm_p5_0 = {
  127323. 2, 289,
  127324. _vq_lengthlist__44cn1_sm_p5_0,
  127325. 1, -529530880, 1611661312, 5, 0,
  127326. _vq_quantlist__44cn1_sm_p5_0,
  127327. NULL,
  127328. &_vq_auxt__44cn1_sm_p5_0,
  127329. NULL,
  127330. 0
  127331. };
  127332. static long _vq_quantlist__44cn1_sm_p6_0[] = {
  127333. 1,
  127334. 0,
  127335. 2,
  127336. };
  127337. static long _vq_lengthlist__44cn1_sm_p6_0[] = {
  127338. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 6,10, 9, 9,11,
  127339. 9, 9, 4, 6, 7,10, 9, 9,11, 9, 9, 7,10,10,10,11,
  127340. 11,11,11,10, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  127341. 11,10,11,11,10,10, 7,11,11,11,11,11,12,11,11, 7,
  127342. 9, 9,11,10,10,12,10,10, 7, 9, 9,11,10,10,11,10,
  127343. 10,
  127344. };
  127345. static float _vq_quantthresh__44cn1_sm_p6_0[] = {
  127346. -5.5, 5.5,
  127347. };
  127348. static long _vq_quantmap__44cn1_sm_p6_0[] = {
  127349. 1, 0, 2,
  127350. };
  127351. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p6_0 = {
  127352. _vq_quantthresh__44cn1_sm_p6_0,
  127353. _vq_quantmap__44cn1_sm_p6_0,
  127354. 3,
  127355. 3
  127356. };
  127357. static static_codebook _44cn1_sm_p6_0 = {
  127358. 4, 81,
  127359. _vq_lengthlist__44cn1_sm_p6_0,
  127360. 1, -529137664, 1618345984, 2, 0,
  127361. _vq_quantlist__44cn1_sm_p6_0,
  127362. NULL,
  127363. &_vq_auxt__44cn1_sm_p6_0,
  127364. NULL,
  127365. 0
  127366. };
  127367. static long _vq_quantlist__44cn1_sm_p6_1[] = {
  127368. 5,
  127369. 4,
  127370. 6,
  127371. 3,
  127372. 7,
  127373. 2,
  127374. 8,
  127375. 1,
  127376. 9,
  127377. 0,
  127378. 10,
  127379. };
  127380. static long _vq_lengthlist__44cn1_sm_p6_1[] = {
  127381. 2, 4, 4, 5, 5, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  127382. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  127383. 8,10, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  127384. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  127385. 8, 8,10,10,10, 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  127386. 8, 8, 8, 8, 8, 8, 9, 9,10,10,10,10,10, 8, 8, 8,
  127387. 8, 9, 9,10,10,10,10,10, 9, 9, 9, 9, 8, 9,10,10,
  127388. 10,10,10, 8, 9, 8, 8, 9, 8,
  127389. };
  127390. static float _vq_quantthresh__44cn1_sm_p6_1[] = {
  127391. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  127392. 3.5, 4.5,
  127393. };
  127394. static long _vq_quantmap__44cn1_sm_p6_1[] = {
  127395. 9, 7, 5, 3, 1, 0, 2, 4,
  127396. 6, 8, 10,
  127397. };
  127398. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p6_1 = {
  127399. _vq_quantthresh__44cn1_sm_p6_1,
  127400. _vq_quantmap__44cn1_sm_p6_1,
  127401. 11,
  127402. 11
  127403. };
  127404. static static_codebook _44cn1_sm_p6_1 = {
  127405. 2, 121,
  127406. _vq_lengthlist__44cn1_sm_p6_1,
  127407. 1, -531365888, 1611661312, 4, 0,
  127408. _vq_quantlist__44cn1_sm_p6_1,
  127409. NULL,
  127410. &_vq_auxt__44cn1_sm_p6_1,
  127411. NULL,
  127412. 0
  127413. };
  127414. static long _vq_quantlist__44cn1_sm_p7_0[] = {
  127415. 6,
  127416. 5,
  127417. 7,
  127418. 4,
  127419. 8,
  127420. 3,
  127421. 9,
  127422. 2,
  127423. 10,
  127424. 1,
  127425. 11,
  127426. 0,
  127427. 12,
  127428. };
  127429. static long _vq_lengthlist__44cn1_sm_p7_0[] = {
  127430. 1, 4, 4, 6, 6, 7, 7, 7, 7, 9, 9,10,10, 7, 5, 5,
  127431. 7, 7, 8, 8, 8, 8,10, 9,11,10, 7, 5, 5, 7, 7, 8,
  127432. 8, 8, 8, 9,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  127433. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  127434. 11, 0,12,12, 9, 9, 9,10,10,10,11,11,12,12, 0,13,
  127435. 13, 9, 9, 9, 9,10,10,11,11,12,12, 0, 0, 0,10,10,
  127436. 10,10,11,11,12,12,12,13, 0, 0, 0,10,10,10,10,11,
  127437. 11,12,12,12,12, 0, 0, 0,14,14,11,11,11,11,12,13,
  127438. 13,13, 0, 0, 0,14,14,11,10,11,11,12,12,13,13, 0,
  127439. 0, 0, 0, 0,12,12,12,12,13,13,13,14, 0, 0, 0, 0,
  127440. 0,13,12,12,12,13,13,13,14,
  127441. };
  127442. static float _vq_quantthresh__44cn1_sm_p7_0[] = {
  127443. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  127444. 12.5, 17.5, 22.5, 27.5,
  127445. };
  127446. static long _vq_quantmap__44cn1_sm_p7_0[] = {
  127447. 11, 9, 7, 5, 3, 1, 0, 2,
  127448. 4, 6, 8, 10, 12,
  127449. };
  127450. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p7_0 = {
  127451. _vq_quantthresh__44cn1_sm_p7_0,
  127452. _vq_quantmap__44cn1_sm_p7_0,
  127453. 13,
  127454. 13
  127455. };
  127456. static static_codebook _44cn1_sm_p7_0 = {
  127457. 2, 169,
  127458. _vq_lengthlist__44cn1_sm_p7_0,
  127459. 1, -526516224, 1616117760, 4, 0,
  127460. _vq_quantlist__44cn1_sm_p7_0,
  127461. NULL,
  127462. &_vq_auxt__44cn1_sm_p7_0,
  127463. NULL,
  127464. 0
  127465. };
  127466. static long _vq_quantlist__44cn1_sm_p7_1[] = {
  127467. 2,
  127468. 1,
  127469. 3,
  127470. 0,
  127471. 4,
  127472. };
  127473. static long _vq_lengthlist__44cn1_sm_p7_1[] = {
  127474. 2, 4, 4, 4, 5, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  127475. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  127476. };
  127477. static float _vq_quantthresh__44cn1_sm_p7_1[] = {
  127478. -1.5, -0.5, 0.5, 1.5,
  127479. };
  127480. static long _vq_quantmap__44cn1_sm_p7_1[] = {
  127481. 3, 1, 0, 2, 4,
  127482. };
  127483. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p7_1 = {
  127484. _vq_quantthresh__44cn1_sm_p7_1,
  127485. _vq_quantmap__44cn1_sm_p7_1,
  127486. 5,
  127487. 5
  127488. };
  127489. static static_codebook _44cn1_sm_p7_1 = {
  127490. 2, 25,
  127491. _vq_lengthlist__44cn1_sm_p7_1,
  127492. 1, -533725184, 1611661312, 3, 0,
  127493. _vq_quantlist__44cn1_sm_p7_1,
  127494. NULL,
  127495. &_vq_auxt__44cn1_sm_p7_1,
  127496. NULL,
  127497. 0
  127498. };
  127499. static long _vq_quantlist__44cn1_sm_p8_0[] = {
  127500. 4,
  127501. 3,
  127502. 5,
  127503. 2,
  127504. 6,
  127505. 1,
  127506. 7,
  127507. 0,
  127508. 8,
  127509. };
  127510. static long _vq_lengthlist__44cn1_sm_p8_0[] = {
  127511. 1, 4, 4,12,11,13,13,14,14, 4, 7, 7,11,13,14,14,
  127512. 14,14, 3, 8, 3,14,14,14,14,14,14,14,10,12,14,14,
  127513. 14,14,14,14,14,14, 5,14, 8,14,14,14,14,14,12,14,
  127514. 13,14,14,14,14,14,14,14,13,14,10,14,14,14,14,14,
  127515. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  127516. 14,
  127517. };
  127518. static float _vq_quantthresh__44cn1_sm_p8_0[] = {
  127519. -773.5, -552.5, -331.5, -110.5, 110.5, 331.5, 552.5, 773.5,
  127520. };
  127521. static long _vq_quantmap__44cn1_sm_p8_0[] = {
  127522. 7, 5, 3, 1, 0, 2, 4, 6,
  127523. 8,
  127524. };
  127525. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p8_0 = {
  127526. _vq_quantthresh__44cn1_sm_p8_0,
  127527. _vq_quantmap__44cn1_sm_p8_0,
  127528. 9,
  127529. 9
  127530. };
  127531. static static_codebook _44cn1_sm_p8_0 = {
  127532. 2, 81,
  127533. _vq_lengthlist__44cn1_sm_p8_0,
  127534. 1, -516186112, 1627103232, 4, 0,
  127535. _vq_quantlist__44cn1_sm_p8_0,
  127536. NULL,
  127537. &_vq_auxt__44cn1_sm_p8_0,
  127538. NULL,
  127539. 0
  127540. };
  127541. static long _vq_quantlist__44cn1_sm_p8_1[] = {
  127542. 6,
  127543. 5,
  127544. 7,
  127545. 4,
  127546. 8,
  127547. 3,
  127548. 9,
  127549. 2,
  127550. 10,
  127551. 1,
  127552. 11,
  127553. 0,
  127554. 12,
  127555. };
  127556. static long _vq_lengthlist__44cn1_sm_p8_1[] = {
  127557. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,11,11,11, 6, 5, 5,
  127558. 7, 7, 8, 8,10,10,10,11,11,11, 6, 5, 5, 7, 7, 8,
  127559. 8,10,10,11,12,12,12,14, 7, 7, 7, 8, 9, 9,11,11,
  127560. 11,12,11,12,17, 7, 7, 8, 7, 9, 9,11,11,12,12,12,
  127561. 12,14,11,11, 8, 8,10,10,11,12,12,13,11,12,14,11,
  127562. 11, 8, 8,10,10,11,12,12,13,13,12,14,15,14,10,10,
  127563. 10,10,11,12,12,12,12,11,14,13,16,10,10,10, 9,12,
  127564. 11,12,12,13,14,14,15,14,14,13,10,10,11,11,12,11,
  127565. 13,11,14,12,15,13,14,11,10,12,10,12,12,13,13,13,
  127566. 13,14,15,15,12,12,11,11,12,11,13,12,14,14,14,14,
  127567. 17,12,12,11,10,13,11,13,13,
  127568. };
  127569. static float _vq_quantthresh__44cn1_sm_p8_1[] = {
  127570. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  127571. 42.5, 59.5, 76.5, 93.5,
  127572. };
  127573. static long _vq_quantmap__44cn1_sm_p8_1[] = {
  127574. 11, 9, 7, 5, 3, 1, 0, 2,
  127575. 4, 6, 8, 10, 12,
  127576. };
  127577. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p8_1 = {
  127578. _vq_quantthresh__44cn1_sm_p8_1,
  127579. _vq_quantmap__44cn1_sm_p8_1,
  127580. 13,
  127581. 13
  127582. };
  127583. static static_codebook _44cn1_sm_p8_1 = {
  127584. 2, 169,
  127585. _vq_lengthlist__44cn1_sm_p8_1,
  127586. 1, -522616832, 1620115456, 4, 0,
  127587. _vq_quantlist__44cn1_sm_p8_1,
  127588. NULL,
  127589. &_vq_auxt__44cn1_sm_p8_1,
  127590. NULL,
  127591. 0
  127592. };
  127593. static long _vq_quantlist__44cn1_sm_p8_2[] = {
  127594. 8,
  127595. 7,
  127596. 9,
  127597. 6,
  127598. 10,
  127599. 5,
  127600. 11,
  127601. 4,
  127602. 12,
  127603. 3,
  127604. 13,
  127605. 2,
  127606. 14,
  127607. 1,
  127608. 15,
  127609. 0,
  127610. 16,
  127611. };
  127612. static long _vq_lengthlist__44cn1_sm_p8_2[] = {
  127613. 3, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  127614. 9,10, 6, 6, 6, 6, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  127615. 9, 9,10, 6, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  127616. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  127617. 9, 9, 9, 9,10,10,10, 7, 7, 7, 8, 8, 8, 9, 9, 9,
  127618. 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 8, 8, 9, 9,
  127619. 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 8, 8, 9,
  127620. 9, 9, 9, 9, 9, 9, 9,11,10,11, 8, 8, 8, 8, 8, 8,
  127621. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,11,11, 8, 8, 8,
  127622. 8, 9, 9, 9, 9, 9, 9, 9, 9,11,10,11,11,11, 9, 9,
  127623. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,11,10,11,11, 9,
  127624. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,11,11,10,11,11,
  127625. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,11,11,
  127626. 11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,11,11,
  127627. 11,11,11,11, 9,10,10,10, 9, 9, 9, 9, 9, 9,11,10,
  127628. 11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  127629. 11,11,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  127630. 10,11,11,11,11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9,
  127631. 9,
  127632. };
  127633. static float _vq_quantthresh__44cn1_sm_p8_2[] = {
  127634. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  127635. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  127636. };
  127637. static long _vq_quantmap__44cn1_sm_p8_2[] = {
  127638. 15, 13, 11, 9, 7, 5, 3, 1,
  127639. 0, 2, 4, 6, 8, 10, 12, 14,
  127640. 16,
  127641. };
  127642. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p8_2 = {
  127643. _vq_quantthresh__44cn1_sm_p8_2,
  127644. _vq_quantmap__44cn1_sm_p8_2,
  127645. 17,
  127646. 17
  127647. };
  127648. static static_codebook _44cn1_sm_p8_2 = {
  127649. 2, 289,
  127650. _vq_lengthlist__44cn1_sm_p8_2,
  127651. 1, -529530880, 1611661312, 5, 0,
  127652. _vq_quantlist__44cn1_sm_p8_2,
  127653. NULL,
  127654. &_vq_auxt__44cn1_sm_p8_2,
  127655. NULL,
  127656. 0
  127657. };
  127658. static long _huff_lengthlist__44cn1_sm_short[] = {
  127659. 5, 6,12,14,12,14,16,17,18, 4, 2, 5,11, 7,10,12,
  127660. 14,15, 9, 4, 5,11, 7,10,13,15,18,15, 6, 7, 5, 6,
  127661. 8,11,13,16,11, 5, 6, 5, 5, 6, 9,13,15,12, 5, 7,
  127662. 6, 5, 6, 9,12,14,12, 6, 7, 8, 6, 7, 9,12,13,14,
  127663. 8, 8, 7, 5, 5, 8,10,12,16, 9, 9, 8, 6, 6, 7, 9,
  127664. 9,
  127665. };
  127666. static static_codebook _huff_book__44cn1_sm_short = {
  127667. 2, 81,
  127668. _huff_lengthlist__44cn1_sm_short,
  127669. 0, 0, 0, 0, 0,
  127670. NULL,
  127671. NULL,
  127672. NULL,
  127673. NULL,
  127674. 0
  127675. };
  127676. /*** End of inlined file: res_books_stereo.h ***/
  127677. static vorbis_info_residue0 _residue_44_low={
  127678. 0,-1, -1, 9,-1,
  127679. {0},
  127680. {-1},
  127681. { .5, 1.5, 2.5, 2.5, 4.5, 8.5, 16.5, 32.5},
  127682. { .5, .5, .5, 999., 4.5, 8.5, 16.5, 32.5},
  127683. };
  127684. static vorbis_info_residue0 _residue_44_mid={
  127685. 0,-1, -1, 10,-1,
  127686. {0},
  127687. {-1},
  127688. { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 8.5, 16.5, 32.5},
  127689. { .5, .5, 999., .5, 999., 4.5, 8.5, 16.5, 32.5},
  127690. };
  127691. static vorbis_info_residue0 _residue_44_high={
  127692. 0,-1, -1, 10,-1,
  127693. {0},
  127694. {-1},
  127695. { .5, 1.5, 2.5, 4.5, 8.5, 16.5, 32.5, 71.5,157.5},
  127696. { .5, 1.5, 2.5, 3.5, 4.5, 8.5, 16.5, 71.5,157.5},
  127697. };
  127698. static static_bookblock _resbook_44s_n1={
  127699. {
  127700. {0},{0,0,&_44cn1_s_p1_0},{0,0,&_44cn1_s_p2_0},
  127701. {0,0,&_44cn1_s_p3_0},{0,0,&_44cn1_s_p4_0},{0,0,&_44cn1_s_p5_0},
  127702. {&_44cn1_s_p6_0,&_44cn1_s_p6_1},{&_44cn1_s_p7_0,&_44cn1_s_p7_1},
  127703. {&_44cn1_s_p8_0,&_44cn1_s_p8_1,&_44cn1_s_p8_2}
  127704. }
  127705. };
  127706. static static_bookblock _resbook_44sm_n1={
  127707. {
  127708. {0},{0,0,&_44cn1_sm_p1_0},{0,0,&_44cn1_sm_p2_0},
  127709. {0,0,&_44cn1_sm_p3_0},{0,0,&_44cn1_sm_p4_0},{0,0,&_44cn1_sm_p5_0},
  127710. {&_44cn1_sm_p6_0,&_44cn1_sm_p6_1},{&_44cn1_sm_p7_0,&_44cn1_sm_p7_1},
  127711. {&_44cn1_sm_p8_0,&_44cn1_sm_p8_1,&_44cn1_sm_p8_2}
  127712. }
  127713. };
  127714. static static_bookblock _resbook_44s_0={
  127715. {
  127716. {0},{0,0,&_44c0_s_p1_0},{0,0,&_44c0_s_p2_0},
  127717. {0,0,&_44c0_s_p3_0},{0,0,&_44c0_s_p4_0},{0,0,&_44c0_s_p5_0},
  127718. {&_44c0_s_p6_0,&_44c0_s_p6_1},{&_44c0_s_p7_0,&_44c0_s_p7_1},
  127719. {&_44c0_s_p8_0,&_44c0_s_p8_1,&_44c0_s_p8_2}
  127720. }
  127721. };
  127722. static static_bookblock _resbook_44sm_0={
  127723. {
  127724. {0},{0,0,&_44c0_sm_p1_0},{0,0,&_44c0_sm_p2_0},
  127725. {0,0,&_44c0_sm_p3_0},{0,0,&_44c0_sm_p4_0},{0,0,&_44c0_sm_p5_0},
  127726. {&_44c0_sm_p6_0,&_44c0_sm_p6_1},{&_44c0_sm_p7_0,&_44c0_sm_p7_1},
  127727. {&_44c0_sm_p8_0,&_44c0_sm_p8_1,&_44c0_sm_p8_2}
  127728. }
  127729. };
  127730. static static_bookblock _resbook_44s_1={
  127731. {
  127732. {0},{0,0,&_44c1_s_p1_0},{0,0,&_44c1_s_p2_0},
  127733. {0,0,&_44c1_s_p3_0},{0,0,&_44c1_s_p4_0},{0,0,&_44c1_s_p5_0},
  127734. {&_44c1_s_p6_0,&_44c1_s_p6_1},{&_44c1_s_p7_0,&_44c1_s_p7_1},
  127735. {&_44c1_s_p8_0,&_44c1_s_p8_1,&_44c1_s_p8_2}
  127736. }
  127737. };
  127738. static static_bookblock _resbook_44sm_1={
  127739. {
  127740. {0},{0,0,&_44c1_sm_p1_0},{0,0,&_44c1_sm_p2_0},
  127741. {0,0,&_44c1_sm_p3_0},{0,0,&_44c1_sm_p4_0},{0,0,&_44c1_sm_p5_0},
  127742. {&_44c1_sm_p6_0,&_44c1_sm_p6_1},{&_44c1_sm_p7_0,&_44c1_sm_p7_1},
  127743. {&_44c1_sm_p8_0,&_44c1_sm_p8_1,&_44c1_sm_p8_2}
  127744. }
  127745. };
  127746. static static_bookblock _resbook_44s_2={
  127747. {
  127748. {0},{0,0,&_44c2_s_p1_0},{0,0,&_44c2_s_p2_0},{0,0,&_44c2_s_p3_0},
  127749. {0,0,&_44c2_s_p4_0},{0,0,&_44c2_s_p5_0},{0,0,&_44c2_s_p6_0},
  127750. {&_44c2_s_p7_0,&_44c2_s_p7_1},{&_44c2_s_p8_0,&_44c2_s_p8_1},
  127751. {&_44c2_s_p9_0,&_44c2_s_p9_1,&_44c2_s_p9_2}
  127752. }
  127753. };
  127754. static static_bookblock _resbook_44s_3={
  127755. {
  127756. {0},{0,0,&_44c3_s_p1_0},{0,0,&_44c3_s_p2_0},{0,0,&_44c3_s_p3_0},
  127757. {0,0,&_44c3_s_p4_0},{0,0,&_44c3_s_p5_0},{0,0,&_44c3_s_p6_0},
  127758. {&_44c3_s_p7_0,&_44c3_s_p7_1},{&_44c3_s_p8_0,&_44c3_s_p8_1},
  127759. {&_44c3_s_p9_0,&_44c3_s_p9_1,&_44c3_s_p9_2}
  127760. }
  127761. };
  127762. static static_bookblock _resbook_44s_4={
  127763. {
  127764. {0},{0,0,&_44c4_s_p1_0},{0,0,&_44c4_s_p2_0},{0,0,&_44c4_s_p3_0},
  127765. {0,0,&_44c4_s_p4_0},{0,0,&_44c4_s_p5_0},{0,0,&_44c4_s_p6_0},
  127766. {&_44c4_s_p7_0,&_44c4_s_p7_1},{&_44c4_s_p8_0,&_44c4_s_p8_1},
  127767. {&_44c4_s_p9_0,&_44c4_s_p9_1,&_44c4_s_p9_2}
  127768. }
  127769. };
  127770. static static_bookblock _resbook_44s_5={
  127771. {
  127772. {0},{0,0,&_44c5_s_p1_0},{0,0,&_44c5_s_p2_0},{0,0,&_44c5_s_p3_0},
  127773. {0,0,&_44c5_s_p4_0},{0,0,&_44c5_s_p5_0},{0,0,&_44c5_s_p6_0},
  127774. {&_44c5_s_p7_0,&_44c5_s_p7_1},{&_44c5_s_p8_0,&_44c5_s_p8_1},
  127775. {&_44c5_s_p9_0,&_44c5_s_p9_1,&_44c5_s_p9_2}
  127776. }
  127777. };
  127778. static static_bookblock _resbook_44s_6={
  127779. {
  127780. {0},{0,0,&_44c6_s_p1_0},{0,0,&_44c6_s_p2_0},{0,0,&_44c6_s_p3_0},
  127781. {0,0,&_44c6_s_p4_0},
  127782. {&_44c6_s_p5_0,&_44c6_s_p5_1},
  127783. {&_44c6_s_p6_0,&_44c6_s_p6_1},
  127784. {&_44c6_s_p7_0,&_44c6_s_p7_1},
  127785. {&_44c6_s_p8_0,&_44c6_s_p8_1},
  127786. {&_44c6_s_p9_0,&_44c6_s_p9_1,&_44c6_s_p9_2}
  127787. }
  127788. };
  127789. static static_bookblock _resbook_44s_7={
  127790. {
  127791. {0},{0,0,&_44c7_s_p1_0},{0,0,&_44c7_s_p2_0},{0,0,&_44c7_s_p3_0},
  127792. {0,0,&_44c7_s_p4_0},
  127793. {&_44c7_s_p5_0,&_44c7_s_p5_1},
  127794. {&_44c7_s_p6_0,&_44c7_s_p6_1},
  127795. {&_44c7_s_p7_0,&_44c7_s_p7_1},
  127796. {&_44c7_s_p8_0,&_44c7_s_p8_1},
  127797. {&_44c7_s_p9_0,&_44c7_s_p9_1,&_44c7_s_p9_2}
  127798. }
  127799. };
  127800. static static_bookblock _resbook_44s_8={
  127801. {
  127802. {0},{0,0,&_44c8_s_p1_0},{0,0,&_44c8_s_p2_0},{0,0,&_44c8_s_p3_0},
  127803. {0,0,&_44c8_s_p4_0},
  127804. {&_44c8_s_p5_0,&_44c8_s_p5_1},
  127805. {&_44c8_s_p6_0,&_44c8_s_p6_1},
  127806. {&_44c8_s_p7_0,&_44c8_s_p7_1},
  127807. {&_44c8_s_p8_0,&_44c8_s_p8_1},
  127808. {&_44c8_s_p9_0,&_44c8_s_p9_1,&_44c8_s_p9_2}
  127809. }
  127810. };
  127811. static static_bookblock _resbook_44s_9={
  127812. {
  127813. {0},{0,0,&_44c9_s_p1_0},{0,0,&_44c9_s_p2_0},{0,0,&_44c9_s_p3_0},
  127814. {0,0,&_44c9_s_p4_0},
  127815. {&_44c9_s_p5_0,&_44c9_s_p5_1},
  127816. {&_44c9_s_p6_0,&_44c9_s_p6_1},
  127817. {&_44c9_s_p7_0,&_44c9_s_p7_1},
  127818. {&_44c9_s_p8_0,&_44c9_s_p8_1},
  127819. {&_44c9_s_p9_0,&_44c9_s_p9_1,&_44c9_s_p9_2}
  127820. }
  127821. };
  127822. static vorbis_residue_template _res_44s_n1[]={
  127823. {2,0, &_residue_44_low,
  127824. &_huff_book__44cn1_s_short,&_huff_book__44cn1_sm_short,
  127825. &_resbook_44s_n1,&_resbook_44sm_n1},
  127826. {2,0, &_residue_44_low,
  127827. &_huff_book__44cn1_s_long,&_huff_book__44cn1_sm_long,
  127828. &_resbook_44s_n1,&_resbook_44sm_n1}
  127829. };
  127830. static vorbis_residue_template _res_44s_0[]={
  127831. {2,0, &_residue_44_low,
  127832. &_huff_book__44c0_s_short,&_huff_book__44c0_sm_short,
  127833. &_resbook_44s_0,&_resbook_44sm_0},
  127834. {2,0, &_residue_44_low,
  127835. &_huff_book__44c0_s_long,&_huff_book__44c0_sm_long,
  127836. &_resbook_44s_0,&_resbook_44sm_0}
  127837. };
  127838. static vorbis_residue_template _res_44s_1[]={
  127839. {2,0, &_residue_44_low,
  127840. &_huff_book__44c1_s_short,&_huff_book__44c1_sm_short,
  127841. &_resbook_44s_1,&_resbook_44sm_1},
  127842. {2,0, &_residue_44_low,
  127843. &_huff_book__44c1_s_long,&_huff_book__44c1_sm_long,
  127844. &_resbook_44s_1,&_resbook_44sm_1}
  127845. };
  127846. static vorbis_residue_template _res_44s_2[]={
  127847. {2,0, &_residue_44_mid,
  127848. &_huff_book__44c2_s_short,&_huff_book__44c2_s_short,
  127849. &_resbook_44s_2,&_resbook_44s_2},
  127850. {2,0, &_residue_44_mid,
  127851. &_huff_book__44c2_s_long,&_huff_book__44c2_s_long,
  127852. &_resbook_44s_2,&_resbook_44s_2}
  127853. };
  127854. static vorbis_residue_template _res_44s_3[]={
  127855. {2,0, &_residue_44_mid,
  127856. &_huff_book__44c3_s_short,&_huff_book__44c3_s_short,
  127857. &_resbook_44s_3,&_resbook_44s_3},
  127858. {2,0, &_residue_44_mid,
  127859. &_huff_book__44c3_s_long,&_huff_book__44c3_s_long,
  127860. &_resbook_44s_3,&_resbook_44s_3}
  127861. };
  127862. static vorbis_residue_template _res_44s_4[]={
  127863. {2,0, &_residue_44_mid,
  127864. &_huff_book__44c4_s_short,&_huff_book__44c4_s_short,
  127865. &_resbook_44s_4,&_resbook_44s_4},
  127866. {2,0, &_residue_44_mid,
  127867. &_huff_book__44c4_s_long,&_huff_book__44c4_s_long,
  127868. &_resbook_44s_4,&_resbook_44s_4}
  127869. };
  127870. static vorbis_residue_template _res_44s_5[]={
  127871. {2,0, &_residue_44_mid,
  127872. &_huff_book__44c5_s_short,&_huff_book__44c5_s_short,
  127873. &_resbook_44s_5,&_resbook_44s_5},
  127874. {2,0, &_residue_44_mid,
  127875. &_huff_book__44c5_s_long,&_huff_book__44c5_s_long,
  127876. &_resbook_44s_5,&_resbook_44s_5}
  127877. };
  127878. static vorbis_residue_template _res_44s_6[]={
  127879. {2,0, &_residue_44_high,
  127880. &_huff_book__44c6_s_short,&_huff_book__44c6_s_short,
  127881. &_resbook_44s_6,&_resbook_44s_6},
  127882. {2,0, &_residue_44_high,
  127883. &_huff_book__44c6_s_long,&_huff_book__44c6_s_long,
  127884. &_resbook_44s_6,&_resbook_44s_6}
  127885. };
  127886. static vorbis_residue_template _res_44s_7[]={
  127887. {2,0, &_residue_44_high,
  127888. &_huff_book__44c7_s_short,&_huff_book__44c7_s_short,
  127889. &_resbook_44s_7,&_resbook_44s_7},
  127890. {2,0, &_residue_44_high,
  127891. &_huff_book__44c7_s_long,&_huff_book__44c7_s_long,
  127892. &_resbook_44s_7,&_resbook_44s_7}
  127893. };
  127894. static vorbis_residue_template _res_44s_8[]={
  127895. {2,0, &_residue_44_high,
  127896. &_huff_book__44c8_s_short,&_huff_book__44c8_s_short,
  127897. &_resbook_44s_8,&_resbook_44s_8},
  127898. {2,0, &_residue_44_high,
  127899. &_huff_book__44c8_s_long,&_huff_book__44c8_s_long,
  127900. &_resbook_44s_8,&_resbook_44s_8}
  127901. };
  127902. static vorbis_residue_template _res_44s_9[]={
  127903. {2,0, &_residue_44_high,
  127904. &_huff_book__44c9_s_short,&_huff_book__44c9_s_short,
  127905. &_resbook_44s_9,&_resbook_44s_9},
  127906. {2,0, &_residue_44_high,
  127907. &_huff_book__44c9_s_long,&_huff_book__44c9_s_long,
  127908. &_resbook_44s_9,&_resbook_44s_9}
  127909. };
  127910. static vorbis_mapping_template _mapres_template_44_stereo[]={
  127911. { _map_nominal, _res_44s_n1 }, /* -1 */
  127912. { _map_nominal, _res_44s_0 }, /* 0 */
  127913. { _map_nominal, _res_44s_1 }, /* 1 */
  127914. { _map_nominal, _res_44s_2 }, /* 2 */
  127915. { _map_nominal, _res_44s_3 }, /* 3 */
  127916. { _map_nominal, _res_44s_4 }, /* 4 */
  127917. { _map_nominal, _res_44s_5 }, /* 5 */
  127918. { _map_nominal, _res_44s_6 }, /* 6 */
  127919. { _map_nominal, _res_44s_7 }, /* 7 */
  127920. { _map_nominal, _res_44s_8 }, /* 8 */
  127921. { _map_nominal, _res_44s_9 }, /* 9 */
  127922. };
  127923. /*** End of inlined file: residue_44.h ***/
  127924. /*** Start of inlined file: psych_44.h ***/
  127925. static vorbis_info_psy_global _psy_global_44[5]={
  127926. {8, /* lines per eighth octave */
  127927. {20.f,14.f,12.f,12.f,12.f,12.f,12.f},
  127928. {-60.f,-30.f,-40.f,-40.f,-40.f,-40.f,-40.f}, 2,-75.f,
  127929. -6.f,
  127930. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  127931. },
  127932. {8, /* lines per eighth octave */
  127933. {14.f,10.f,10.f,10.f,10.f,10.f,10.f},
  127934. {-40.f,-30.f,-25.f,-25.f,-25.f,-25.f,-25.f}, 2,-80.f,
  127935. -6.f,
  127936. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  127937. },
  127938. {8, /* lines per eighth octave */
  127939. {12.f,10.f,10.f,10.f,10.f,10.f,10.f},
  127940. {-20.f,-20.f,-15.f,-15.f,-15.f,-15.f,-15.f}, 0,-80.f,
  127941. -6.f,
  127942. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  127943. },
  127944. {8, /* lines per eighth octave */
  127945. {10.f,8.f,8.f,8.f,8.f,8.f,8.f},
  127946. {-20.f,-15.f,-12.f,-12.f,-12.f,-12.f,-12.f}, 0,-80.f,
  127947. -6.f,
  127948. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  127949. },
  127950. {8, /* lines per eighth octave */
  127951. {10.f,6.f,6.f,6.f,6.f,6.f,6.f},
  127952. {-15.f,-15.f,-12.f,-12.f,-12.f,-12.f,-12.f}, 0,-85.f,
  127953. -6.f,
  127954. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  127955. },
  127956. };
  127957. static compandblock _psy_compand_44[6]={
  127958. {{
  127959. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  127960. 8, 9,10,11,12,13,14, 15, /* 15dB */
  127961. 16,17,18,19,20,21,22, 23, /* 23dB */
  127962. 24,25,26,27,28,29,30, 31, /* 31dB */
  127963. 32,33,34,35,36,37,38, 39, /* 39dB */
  127964. }},
  127965. {{
  127966. 0, 1, 2, 3, 4, 5, 6, 6, /* 7dB */
  127967. 7, 7, 7, 7, 6, 6, 6, 7, /* 15dB */
  127968. 7, 8, 9,10,11,12,13, 14, /* 23dB */
  127969. 15,16,17,17,17,18,18, 19, /* 31dB */
  127970. 19,19,20,21,22,23,24, 25, /* 39dB */
  127971. }},
  127972. {{
  127973. 0, 1, 2, 3, 4, 5, 5, 5, /* 7dB */
  127974. 6, 6, 6, 5, 4, 4, 4, 4, /* 15dB */
  127975. 4, 4, 5, 5, 5, 6, 6, 6, /* 23dB */
  127976. 7, 7, 7, 8, 8, 8, 9, 10, /* 31dB */
  127977. 11,12,13,14,15,16,17, 18, /* 39dB */
  127978. }},
  127979. {{
  127980. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  127981. 8, 9,10,11,12,13,14, 15, /* 15dB */
  127982. 16,17,18,19,20,21,22, 23, /* 23dB */
  127983. 24,25,26,27,28,29,30, 31, /* 31dB */
  127984. 32,33,34,35,36,37,38, 39, /* 39dB */
  127985. }},
  127986. {{
  127987. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  127988. 8, 9,10,11,12,12,13, 13, /* 15dB */
  127989. 13,14,14,14,15,15,15, 15, /* 23dB */
  127990. 16,16,17,17,17,18,18, 19, /* 31dB */
  127991. 19,19,20,21,22,23,24, 25, /* 39dB */
  127992. }},
  127993. {{
  127994. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  127995. 8, 8, 7, 6, 5, 4, 4, 4, /* 15dB */
  127996. 4, 4, 5, 5, 5, 6, 6, 6, /* 23dB */
  127997. 7, 7, 7, 8, 8, 8, 9, 10, /* 31dB */
  127998. 11,12,13,14,15,16,17, 18, /* 39dB */
  127999. }}
  128000. };
  128001. static vp_adjblock _vp_tonemask_adj_longblock[12]={
  128002. {{ -3, -8,-13,-15,-10,-10,-10,-10,-10,-10,-10, 0, 0, 0, 0, 0, 0}}, /* -1 */
  128003. {{ -4,-10,-14,-16,-15,-14,-13,-12,-12,-12,-11, -1, -1, -1, -1, -1, 0}}, /* 0 */
  128004. {{ -6,-12,-14,-16,-15,-15,-14,-13,-13,-12,-12, -2, -2, -1, -1, -1, 0}}, /* 1 */
  128005. {{-12,-13,-14,-16,-16,-16,-15,-14,-13,-12,-12, -6, -3, -1, -1, -1, 0}}, /* 2 */
  128006. {{-15,-15,-15,-16,-16,-16,-16,-14,-13,-13,-13,-10, -4, -2, -1, -1, 0}}, /* 3 */
  128007. /* 4 */
  128008. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 4 */
  128009. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 5 */
  128010. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -8, -4, -2, -2, 0}}, /* 6 */
  128011. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 7 */
  128012. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 8 */
  128013. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 9 */
  128014. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 10 */
  128015. };
  128016. static vp_adjblock _vp_tonemask_adj_otherblock[12]={
  128017. {{ -3, -8,-13,-15,-10,-10, -9, -9, -9, -9, -9, 1, 1, 1, 1, 1, 1}}, /* -1 */
  128018. {{ -4,-10,-14,-16,-14,-13,-12,-12,-11,-11,-10, 0, 0, 0, 0, 0, 0}}, /* 0 */
  128019. {{ -6,-12,-14,-16,-15,-15,-14,-13,-13,-12,-12, -2, -2, -1, 0, 0, 0}}, /* 1 */
  128020. {{-12,-13,-14,-16,-16,-16,-15,-14,-13,-12,-12, -5, -2, -1, 0, 0, 0}}, /* 2 */
  128021. {{-15,-15,-15,-16,-16,-16,-16,-14,-13,-13,-13,-10, -4, -2, 0, 0, 0}}, /* 3 */
  128022. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 4 */
  128023. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 5 */
  128024. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -8, -4, -2, -2, 0}}, /* 6 */
  128025. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 7 */
  128026. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 8 */
  128027. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 9 */
  128028. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 10 */
  128029. };
  128030. static noise3 _psy_noisebias_trans[12]={
  128031. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  128032. {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2, 2, 2, 3, 6, 6, 15},
  128033. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  128034. {{{-15,-15,-15,-15,-15,-12, -6, -4, 0, 2, 4, 4, 5, 5, 5, 8, 10},
  128035. {-30,-30,-30,-30,-26,-22,-20,-14, -8, -4, 0, 0, 0, 0, 2, 3, 6},
  128036. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -6, -4, -4, -4, -2}}},
  128037. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 5, 8, 10},
  128038. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -2, -2, -2, -2, 0, 1, 4},
  128039. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -6, -6, -6, -4}}},
  128040. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 2, 2, 4, 4, 5, 6, 10},
  128041. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -2, -1, 0, 3},
  128042. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -7, -4}}},
  128043. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 2, 2, 4, 4, 4, 5, 8},
  128044. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -3, -2, 0, 2},
  128045. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
  128046. {{{-20,-20,-20,-20,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  128047. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -3, -2, -1, 1},
  128048. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
  128049. {{{-24,-24,-24,-24,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  128050. {-32,-32,-32,-32,-28,-24,-22,-16,-12, -6, -4, -4, -4, -4, -3, -1, 0},
  128051. {-34,-34,-34,-34,-30,-24,-24,-18,-14,-12,-12,-12,-12,-10,-10, -9, -5}}},
  128052. {{{-24,-24,-24,-24,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  128053. {-32,-32,-32,-32,-28,-24,-24,-18,-14, -8, -6, -6, -6, -6, -5, -2, 0},
  128054. {-34,-34,-34,-34,-30,-26,-26,-24,-22,-19,-19,-19,-19,-18,-17,-16,-12}}},
  128055. {{{-24,-24,-24,-24,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  128056. {-32,-32,-32,-32,-28,-24,-24,-24,-18,-14,-12,-10,-10,-10, -8, -6, -2},
  128057. {-34,-34,-34,-34,-30,-26,-26,-26,-24,-24,-24,-24,-24,-24,-24,-20,-16}}},
  128058. {{{-24,-24,-24,-24,-22,-20,-15,-10, -8, -2, 0, 0, 0, 1, 2, 3, 7},
  128059. {-36,-36,-36,-36,-30,-30,-30,-24,-20,-16,-16,-16,-16,-14,-12,-10, -7},
  128060. {-36,-36,-36,-36,-34,-30,-28,-26,-24,-30,-30,-30,-30,-30,-30,-24,-20}}},
  128061. {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -4, -4, -4, -4, -4, -2, 2},
  128062. {-38,-38,-38,-38,-36,-34,-34,-30,-24,-20,-20,-20,-20,-18,-16,-12,-10},
  128063. {-40,-40,-40,-40,-40,-40,-40,-38,-35,-35,-35,-35,-35,-35,-35,-35,-30}}},
  128064. {{{-30,-30,-30,-30,-30,-30,-30,-28,-20,-14,-14,-14,-14,-14,-14,-12,-10},
  128065. {-40,-40,-40,-40,-40,-40,-40,-40,-35,-30,-30,-30,-30,-30,-30,-30,-20},
  128066. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  128067. };
  128068. static noise3 _psy_noisebias_long[12]={
  128069. {{{-10,-10,-10,-10,-10, -4, 0, 0, 0, 6, 6, 6, 6, 10, 10, 12, 20},
  128070. {-20,-20,-20,-20,-20,-20,-10, -2, 0, 0, 0, 0, 0, 2, 4, 6, 15},
  128071. {-20,-20,-20,-20,-20,-20,-20,-10, -6, -6, -6, -6, -6, -4, -4, -4, -2}}},
  128072. {{{-10,-10,-10,-10,-10,-10, -8, 2, 2, 2, 4, 4, 5, 5, 5, 8, 10},
  128073. {-20,-20,-20,-20,-20,-20,-20,-14, -6, 0, 0, 0, 0, 0, 2, 3, 6},
  128074. {-20,-20,-20,-20,-20,-20,-20,-14, -8, -6, -6, -6, -6, -4, -4, -4, -2}}},
  128075. {{{-10,-10,-10,-10,-10,-10, -8, -4, 0, 2, 4, 4, 5, 5, 5, 8, 10},
  128076. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -2, -2, -2, -2, 0, 1, 4},
  128077. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -8, -8, -8, -8, -6, -6, -6, -4}}},
  128078. {{{-10,-10,-10,-10,-10,-10,-10, -8, 0, 2, 2, 2, 4, 4, 5, 6, 10},
  128079. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -2, -1, 0, 3},
  128080. {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
  128081. {{{-10,-10,-10,-10,-10,-10,-10, -8, 0, 2, 2, 2, 4, 4, 4, 5, 8},
  128082. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -3, -2, 0, 2},
  128083. {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -5}}},
  128084. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  128085. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -3, -2, -1, 1},
  128086. {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -7}}},
  128087. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  128088. {-22,-22,-22,-22,-22,-22,-22,-16,-12, -6, -4, -4, -4, -4, -3, -1, 0},
  128089. {-24,-24,-24,-24,-24,-24,-24,-18,-14,-12,-12,-12,-12,-10,-10, -9, -8}}},
  128090. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  128091. {-24,-24,-24,-24,-24,-24,-24,-18,-14, -8, -6, -6, -6, -6, -5, -2, 0},
  128092. {-26,-26,-26,-26,-26,-26,-26,-18,-16,-15,-15,-15,-15,-13,-13,-12,-10}}},
  128093. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  128094. {-24,-24,-24,-24,-24,-24,-24,-18,-14,-10, -8, -8, -8, -8, -6, -4, 0},
  128095. {-26,-26,-26,-26,-26,-26,-26,-22,-20,-19,-19,-19,-19,-18,-17,-16,-12}}},
  128096. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 0, 0, 0, 0, 1, 2, 3, 7},
  128097. {-26,-26,-26,-26,-26,-26,-26,-20,-16,-12,-10,-10,-10,-10, -8, -6, -2},
  128098. {-28,-28,-28,-28,-28,-28,-28,-26,-24,-24,-24,-24,-24,-24,-24,-20,-16}}},
  128099. {{{-22,-22,-22,-22,-22,-22,-22,-18,-14, -8, -4, -4, -4, -4, -4, -2, 2},
  128100. {-26,-26,-26,-26,-26,-26,-26,-22,-18,-16,-16,-16,-16,-14,-12,-10, -7},
  128101. {-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-24,-20}}},
  128102. {{{-24,-24,-24,-24,-24,-24,-24,-24,-24,-18,-14,-14,-14,-14,-14,-12,-10},
  128103. {-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-20},
  128104. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  128105. };
  128106. static noise3 _psy_noisebias_impulse[12]={
  128107. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  128108. {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2, 2, 2, 3, 6, 6, 15},
  128109. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  128110. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 4, 8, 8, 8, 10, 12, 14, 20},
  128111. {-30,-30,-30,-30,-26,-22,-20,-14, -6, -2, 0, 0, 0, 0, 2, 3, 6},
  128112. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  128113. {{{-12,-12,-12,-12,-12, -8, -6, -4, 0, 4, 4, 4, 4, 10, 12, 14, 20},
  128114. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -4, -4, -2, -2, -2, -2, 2},
  128115. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8,-10,-10, -8, -8, -8, -6, -4}}},
  128116. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 8, 10, 10, 16},
  128117. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -4, -4, -4, -2, 0},
  128118. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
  128119. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 6, 8, 8, 14},
  128120. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -4, -4, -4, -2, 0},
  128121. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
  128122. {{{-16,-16,-16,-16,-16,-12,-10, -6, -2, 0, 0, 0, 0, 4, 6, 6, 12},
  128123. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -4, -4, -4, -2, 0},
  128124. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
  128125. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 4, 6, 11},
  128126. {-32,-32,-32,-32,-28,-24,-22,-16,-10, -6, -8, -8, -6, -6, -6, -4, -2},
  128127. {-34,-34,-34,-34,-30,-26,-24,-18,-14,-12,-12,-12,-12,-12,-10, -9, -5}}},
  128128. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 4, 6, 11},
  128129. {-34,-34,-34,-34,-30,-30,-30,-24,-16,-16,-16,-16,-16,-16,-14,-14,-12},
  128130. {-36,-36,-36,-36,-36,-34,-28,-24,-20,-20,-20,-20,-20,-20,-20,-18,-16}}},
  128131. {{{-22,-22,-22,-22,-22,-20,-14,-10, -6, 0, 0, 0, 0, 4, 4, 6, 11},
  128132. {-34,-34,-34,-34,-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-24,-22},
  128133. {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-30,-24}}},
  128134. {{{-24,-24,-24,-24,-24,-22,-14,-10, -6, -1, -1, -1, -1, 3, 3, 5, 10},
  128135. {-34,-34,-34,-34,-34,-32,-32,-30,-26,-26,-26,-26,-26,-26,-26,-26,-24},
  128136. {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-30,-24}}},
  128137. {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -4, -4, -4, -4, -4, -2, 2},
  128138. {-36,-36,-36,-36,-34,-32,-32,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26},
  128139. {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-24,-20}}},
  128140. {{{-30,-30,-30,-30,-30,-26,-24,-24,-24,-20,-16,-16,-16,-16,-16,-14,-12},
  128141. {-40,-40,-40,-40,-40,-40,-40,-40,-35,-30,-30,-30,-30,-30,-30,-30,-26},
  128142. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  128143. };
  128144. static noise3 _psy_noisebias_padding[12]={
  128145. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  128146. {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2, 2, 2, 3, 6, 6, 15},
  128147. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  128148. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  128149. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -2, 2, 3, 6, 6, 8, 10},
  128150. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -4, -4, -4, -4, -2, 0, 2}}},
  128151. {{{-12,-12,-12,-12,-12, -8, -6, -4, 0, 4, 4, 4, 4, 10, 12, 14, 20},
  128152. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, 0, 0, 0, 2, 2, 4, 8},
  128153. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -6, -6, -4, -2, 0}}},
  128154. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 8, 10, 10, 16},
  128155. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, 0, 0, 2, 6},
  128156. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
  128157. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 6, 8, 8, 14},
  128158. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, 0, 0, 2, 6},
  128159. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
  128160. {{{-16,-16,-16,-16,-16,-12,-10, -6, -2, 0, 0, 0, 0, 4, 6, 6, 12},
  128161. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, -1, 0, 2, 6},
  128162. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
  128163. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 6, 6, 12},
  128164. {-32,-32,-32,-32,-28,-24,-22,-16,-12, -6, -3, -3, -3, -3, -2, 0, 4},
  128165. {-34,-34,-34,-34,-30,-26,-24,-18,-14,-10,-10,-10,-10,-10, -8, -5, -3}}},
  128166. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 6, 6, 12},
  128167. {-34,-34,-34,-34,-30,-30,-24,-20,-14, -8, -4, -4, -4, -4, -3, -1, 4},
  128168. {-34,-34,-34,-34,-34,-30,-26,-20,-16,-13,-13,-13,-13,-13,-11, -8, -6}}},
  128169. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 6, 6, 12},
  128170. {-34,-34,-34,-34,-30,-30,-30,-24,-16,-10, -8, -6, -6, -6, -5, -3, 1},
  128171. {-34,-34,-34,-34,-32,-32,-28,-22,-18,-16,-16,-16,-16,-16,-14,-12,-10}}},
  128172. {{{-22,-22,-22,-22,-22,-20,-14,-10, -4, 0, 0, 0, 0, 3, 5, 5, 11},
  128173. {-34,-34,-34,-34,-30,-30,-30,-24,-16,-12,-10, -8, -8, -8, -7, -5, -2},
  128174. {-36,-36,-36,-36,-36,-34,-28,-22,-20,-20,-20,-20,-20,-20,-20,-16,-14}}},
  128175. {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -2, -2, -2, -2, 0, 2, 6},
  128176. {-36,-36,-36,-36,-34,-32,-32,-24,-16,-12,-12,-12,-12,-12,-10, -8, -5},
  128177. {-40,-40,-40,-40,-40,-40,-40,-32,-26,-24,-24,-24,-24,-24,-24,-20,-18}}},
  128178. {{{-30,-30,-30,-30,-30,-26,-24,-24,-24,-20,-12,-12,-12,-12,-12,-10, -8},
  128179. {-40,-40,-40,-40,-40,-40,-40,-40,-35,-30,-25,-25,-25,-25,-25,-25,-15},
  128180. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  128181. };
  128182. static noiseguard _psy_noiseguards_44[4]={
  128183. {3,3,15},
  128184. {3,3,15},
  128185. {10,10,100},
  128186. {10,10,100},
  128187. };
  128188. static int _psy_tone_suppress[12]={
  128189. -20,-20,-20,-20,-20,-24,-30,-40,-40,-45,-45,-45,
  128190. };
  128191. static int _psy_tone_0dB[12]={
  128192. 90,90,95,95,95,95,105,105,105,105,105,105,
  128193. };
  128194. static int _psy_noise_suppress[12]={
  128195. -20,-20,-24,-24,-24,-24,-30,-40,-40,-45,-45,-45,
  128196. };
  128197. static vorbis_info_psy _psy_info_template={
  128198. -1,
  128199. -140.,-140.,
  128200. {0.f,0.f,0.f}, 0.,0., -40.f, {0.},
  128201. 1, -0.f, .5f, .5f, 0,0,0,
  128202. {{-1},{-1},{-1}},{-1},105.f,
  128203. 0,0,-1,-1,0.,
  128204. };
  128205. static int _psy_ath_floater[12]={
  128206. -100,-100,-100,-100,-100,-100,-105,-105,-105,-105,-110,-120,
  128207. };
  128208. static int _psy_ath_abs[12]={
  128209. -130,-130,-130,-130,-140,-140,-140,-140,-140,-140,-140,-150,
  128210. };
  128211. static adj_stereo _psy_stereo_modes_44[12]={
  128212. {{ 4, 4, 4, 4, 4, 4, 4, 3, 2, 2, 1, 0, 0, 0, 0},
  128213. { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 5, 4, 3},
  128214. { 1, 2, 3, 4, 4, 4, 4, 4, 4, 5, 6, 7, 8, 8, 8},
  128215. { 12,12.5, 13,13.5, 14,14.5, 15, 99, 99, 99, 99, 99, 99, 99, 99}},
  128216. {{ 4, 4, 4, 4, 4, 4, 4, 3, 2, 1, 0, 0, 0, 0, 0},
  128217. { 8, 8, 8, 8, 6, 6, 5, 5, 5, 5, 5, 5, 5, 4, 3},
  128218. { 1, 2, 3, 4, 4, 5, 6, 6, 6, 6, 6, 8, 8, 8, 8},
  128219. { 12,12.5, 13,13.5, 14,14.5, 15, 99, 99, 99, 99, 99, 99, 99, 99}},
  128220. {{ 3, 3, 3, 3, 3, 3, 3, 3, 2, 1, 0, 0, 0, 0, 0},
  128221. { 8, 8, 8, 8, 6, 6, 5, 5, 5, 5, 5, 5, 5, 4, 3},
  128222. { 1, 2, 3, 4, 4, 5, 6, 6, 6, 6, 6, 8, 8, 8, 8},
  128223. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128224. {{ 3, 3, 3, 3, 3, 3, 3, 2, 1, 1, 0, 0, 0, 0, 0},
  128225. { 8, 8, 6, 6, 5, 5, 4, 4, 4, 4, 4, 4, 3, 2, 1},
  128226. { 3, 4, 4, 5, 5, 6, 6, 6, 6, 6, 6, 8, 8, 8, 8},
  128227. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128228. {{ 2, 2, 2, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0},
  128229. { 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 2, 1},
  128230. { 4, 4, 5, 6, 6, 6, 6, 6, 8, 8, 10, 10, 10, 10, 10},
  128231. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128232. {{ 2, 2, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128233. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 2, 1, 0},
  128234. { 6, 6, 6, 8, 8, 8, 8, 8, 8, 8, 10, 10, 10, 10, 10},
  128235. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128236. {{ 2, 2, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128237. { 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0},
  128238. { 6, 7, 8, 8, 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12},
  128239. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128240. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128241. { 3, 3, 3, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128242. { 8, 8, 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
  128243. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128244. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128245. { 3, 3, 3, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128246. { 8, 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
  128247. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128248. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128249. { 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128250. { 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
  128251. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128252. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128253. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128254. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  128255. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128256. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128257. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128258. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  128259. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128260. };
  128261. static att3 _psy_tone_masteratt_44[12]={
  128262. {{ 35, 21, 9}, 0, 0}, /* -1 */
  128263. {{ 30, 20, 8}, -2, 1.25}, /* 0 */
  128264. /* 1 */
  128265. {{ 25, 12, 2}, 0, 0}, /* 1 */
  128266. /* 2 */
  128267. {{ 20, 9, -3}, 0, 0}, /* 2 */
  128268. {{ 20, 9, -4}, 0, 0}, /* 3 */
  128269. {{ 20, 9, -4}, 0, 0}, /* 4 */
  128270. {{ 20, 6, -6}, 0, 0}, /* 5 */
  128271. {{ 20, 3, -10}, 0, 0}, /* 6 */
  128272. {{ 18, 1, -14}, 0, 0}, /* 7 */
  128273. {{ 18, 0, -16}, 0, 0}, /* 8 */
  128274. {{ 18, -2, -16}, 0, 0}, /* 9 */
  128275. {{ 12, -2, -20}, 0, 0}, /* 10 */
  128276. };
  128277. static double _psy_lowpass_44[12]={
  128278. 13.9,15.1,15.8,16.5,17.2,18.9,20.1,48.,999.,999.,999.,999.
  128279. };
  128280. static int _noise_start_short_44[11]={
  128281. 32,16,16,16,32,9999,9999,9999,9999,9999,9999
  128282. };
  128283. static int _noise_start_long_44[11]={
  128284. 256,128,128,256,512,9999,9999,9999,9999,9999,9999
  128285. };
  128286. static int _noise_part_short_44[11]={
  128287. 8,8,8,8,8,8,8,8,8,8,8
  128288. };
  128289. static int _noise_part_long_44[11]={
  128290. 32,32,32,32,32,32,32,32,32,32,32
  128291. };
  128292. static double _noise_thresh_44[11]={
  128293. .2,.2,.2,.4,.6,9999.,9999.,9999.,9999.,9999.,9999.,
  128294. };
  128295. static double _noise_thresh_5only[2]={
  128296. .5,.5,
  128297. };
  128298. /*** End of inlined file: psych_44.h ***/
  128299. static double rate_mapping_44_stereo[12]={
  128300. 22500.,32000.,40000.,48000.,56000.,64000.,
  128301. 80000.,96000.,112000.,128000.,160000.,250001.
  128302. };
  128303. static double quality_mapping_44[12]={
  128304. -.1,.0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1.0
  128305. };
  128306. static int blocksize_short_44[11]={
  128307. 512,256,256,256,256,256,256,256,256,256,256
  128308. };
  128309. static int blocksize_long_44[11]={
  128310. 4096,2048,2048,2048,2048,2048,2048,2048,2048,2048,2048
  128311. };
  128312. static double _psy_compand_short_mapping[12]={
  128313. 0.5, 1., 1., 1.3, 1.6, 2., 2., 2., 2., 2., 2., 2.
  128314. };
  128315. static double _psy_compand_long_mapping[12]={
  128316. 3.5, 4., 4., 4.3, 4.6, 5., 5., 5., 5., 5., 5., 5.
  128317. };
  128318. static double _global_mapping_44[12]={
  128319. 0., 1., 1., 1.5, 2., 2., 2.5, 2.7, 3.0, 3.7, 4., 4.
  128320. };
  128321. static int _floor_short_mapping_44[11]={
  128322. 1,0,0,2,2,4,5,5,5,5,5
  128323. };
  128324. static int _floor_long_mapping_44[11]={
  128325. 8,7,7,7,7,7,7,7,7,7,7
  128326. };
  128327. ve_setup_data_template ve_setup_44_stereo={
  128328. 11,
  128329. rate_mapping_44_stereo,
  128330. quality_mapping_44,
  128331. 2,
  128332. 40000,
  128333. 50000,
  128334. blocksize_short_44,
  128335. blocksize_long_44,
  128336. _psy_tone_masteratt_44,
  128337. _psy_tone_0dB,
  128338. _psy_tone_suppress,
  128339. _vp_tonemask_adj_otherblock,
  128340. _vp_tonemask_adj_longblock,
  128341. _vp_tonemask_adj_otherblock,
  128342. _psy_noiseguards_44,
  128343. _psy_noisebias_impulse,
  128344. _psy_noisebias_padding,
  128345. _psy_noisebias_trans,
  128346. _psy_noisebias_long,
  128347. _psy_noise_suppress,
  128348. _psy_compand_44,
  128349. _psy_compand_short_mapping,
  128350. _psy_compand_long_mapping,
  128351. {_noise_start_short_44,_noise_start_long_44},
  128352. {_noise_part_short_44,_noise_part_long_44},
  128353. _noise_thresh_44,
  128354. _psy_ath_floater,
  128355. _psy_ath_abs,
  128356. _psy_lowpass_44,
  128357. _psy_global_44,
  128358. _global_mapping_44,
  128359. _psy_stereo_modes_44,
  128360. _floor_books,
  128361. _floor,
  128362. _floor_short_mapping_44,
  128363. _floor_long_mapping_44,
  128364. _mapres_template_44_stereo
  128365. };
  128366. /*** End of inlined file: setup_44.h ***/
  128367. /*** Start of inlined file: setup_44u.h ***/
  128368. /*** Start of inlined file: residue_44u.h ***/
  128369. /*** Start of inlined file: res_books_uncoupled.h ***/
  128370. static long _vq_quantlist__16u0__p1_0[] = {
  128371. 1,
  128372. 0,
  128373. 2,
  128374. };
  128375. static long _vq_lengthlist__16u0__p1_0[] = {
  128376. 1, 4, 4, 5, 7, 7, 5, 7, 8, 5, 8, 8, 8,10,10, 8,
  128377. 10,11, 5, 8, 8, 8,10,10, 8,10,10, 4, 9, 9, 9,12,
  128378. 11, 8,11,11, 8,12,11,10,12,14,10,13,13, 7,11,11,
  128379. 10,14,12,11,14,14, 4, 9, 9, 8,11,11, 9,11,12, 7,
  128380. 11,11,10,13,14,10,12,14, 8,11,12,10,14,14,10,13,
  128381. 12,
  128382. };
  128383. static float _vq_quantthresh__16u0__p1_0[] = {
  128384. -0.5, 0.5,
  128385. };
  128386. static long _vq_quantmap__16u0__p1_0[] = {
  128387. 1, 0, 2,
  128388. };
  128389. static encode_aux_threshmatch _vq_auxt__16u0__p1_0 = {
  128390. _vq_quantthresh__16u0__p1_0,
  128391. _vq_quantmap__16u0__p1_0,
  128392. 3,
  128393. 3
  128394. };
  128395. static static_codebook _16u0__p1_0 = {
  128396. 4, 81,
  128397. _vq_lengthlist__16u0__p1_0,
  128398. 1, -535822336, 1611661312, 2, 0,
  128399. _vq_quantlist__16u0__p1_0,
  128400. NULL,
  128401. &_vq_auxt__16u0__p1_0,
  128402. NULL,
  128403. 0
  128404. };
  128405. static long _vq_quantlist__16u0__p2_0[] = {
  128406. 1,
  128407. 0,
  128408. 2,
  128409. };
  128410. static long _vq_lengthlist__16u0__p2_0[] = {
  128411. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 9, 7,
  128412. 8, 9, 5, 7, 7, 7, 9, 8, 7, 9, 7, 4, 7, 7, 7, 9,
  128413. 9, 7, 8, 8, 6, 9, 8, 7, 8,11, 9,11,10, 6, 8, 9,
  128414. 8,11, 8, 9,10,11, 4, 7, 7, 7, 8, 8, 7, 9, 9, 6,
  128415. 9, 8, 9,11,10, 8, 8,11, 6, 8, 9, 9,10,11, 8,11,
  128416. 8,
  128417. };
  128418. static float _vq_quantthresh__16u0__p2_0[] = {
  128419. -0.5, 0.5,
  128420. };
  128421. static long _vq_quantmap__16u0__p2_0[] = {
  128422. 1, 0, 2,
  128423. };
  128424. static encode_aux_threshmatch _vq_auxt__16u0__p2_0 = {
  128425. _vq_quantthresh__16u0__p2_0,
  128426. _vq_quantmap__16u0__p2_0,
  128427. 3,
  128428. 3
  128429. };
  128430. static static_codebook _16u0__p2_0 = {
  128431. 4, 81,
  128432. _vq_lengthlist__16u0__p2_0,
  128433. 1, -535822336, 1611661312, 2, 0,
  128434. _vq_quantlist__16u0__p2_0,
  128435. NULL,
  128436. &_vq_auxt__16u0__p2_0,
  128437. NULL,
  128438. 0
  128439. };
  128440. static long _vq_quantlist__16u0__p3_0[] = {
  128441. 2,
  128442. 1,
  128443. 3,
  128444. 0,
  128445. 4,
  128446. };
  128447. static long _vq_lengthlist__16u0__p3_0[] = {
  128448. 1, 5, 5, 7, 7, 6, 7, 7, 8, 8, 6, 7, 8, 8, 8, 8,
  128449. 9, 9,11,11, 8, 9, 9,11,11, 6, 9, 8,10,10, 8,10,
  128450. 10,11,11, 8,10,10,11,11,10,11,10,13,12, 9,11,10,
  128451. 13,13, 6, 8, 9,10,10, 8,10,10,11,11, 8,10,10,11,
  128452. 11, 9,10,11,13,12,10,10,11,12,12, 8,11,11,14,13,
  128453. 10,12,11,15,13, 9,12,11,15,14,12,14,13,16,14,12,
  128454. 13,13,17,14, 8,11,11,13,14, 9,11,12,14,15,10,11,
  128455. 12,13,15,11,13,13,14,16,12,13,14,14,16, 5, 9, 9,
  128456. 11,11, 9,11,11,12,12, 8,11,11,12,12,11,12,12,15,
  128457. 14,10,12,12,15,15, 8,11,11,13,12,10,12,12,13,13,
  128458. 10,12,12,14,13,12,12,13,14,15,11,13,13,17,16, 7,
  128459. 11,11,13,13,10,12,12,14,13,10,12,12,13,14,12,13,
  128460. 12,15,14,11,13,13,15,14, 9,12,12,16,15,11,13,13,
  128461. 17,16,10,13,13,16,16,13,14,15,15,16,13,15,14,19,
  128462. 17, 9,12,12,14,16,11,13,13,15,16,10,13,13,17,16,
  128463. 13,14,13,17,15,12,15,15,16,17, 5, 9, 9,11,11, 8,
  128464. 11,11,13,12, 9,11,11,12,12,10,12,12,14,15,11,12,
  128465. 12,14,14, 7,11,10,13,12,10,12,12,14,13,10,11,12,
  128466. 13,13,11,13,13,15,16,12,12,13,15,15, 7,11,11,13,
  128467. 13,10,13,13,14,14,10,12,12,13,13,11,13,13,16,15,
  128468. 12,13,13,15,14, 9,12,12,15,15,10,13,13,17,16,11,
  128469. 12,13,15,15,12,15,14,18,18,13,14,14,16,17, 9,12,
  128470. 12,15,16,10,13,13,15,16,11,13,13,15,16,13,15,15,
  128471. 17,17,13,15,14,16,15, 7,11,11,15,16,10,13,12,16,
  128472. 17,10,12,13,15,17,15,16,16,18,17,13,15,15,17,18,
  128473. 8,12,12,16,16,11,13,14,17,18,11,13,13,18,16,15,
  128474. 17,16,17,19,14,15,15,17,16, 8,12,12,16,15,11,14,
  128475. 13,18,17,11,13,14,18,17,15,16,16,18,17,13,16,16,
  128476. 18,18,11,15,14,18,17,13,14,15,18, 0,12,15,15, 0,
  128477. 17,17,16,17,17,18,14,16,18,18, 0,11,14,14,17, 0,
  128478. 12,15,14,17,19,12,15,14,18, 0,15,18,16, 0,17,14,
  128479. 18,16,18, 0, 7,11,11,16,15,10,12,12,18,16,10,13,
  128480. 13,16,15,13,15,14,17,17,14,16,16,19,18, 8,12,12,
  128481. 16,16,11,13,13,18,16,11,13,14,17,16,14,15,15,19,
  128482. 18,15,16,16, 0,19, 8,12,12,16,17,11,13,13,17,17,
  128483. 11,14,13,17,17,13,15,15,17,19,15,17,17,19, 0,11,
  128484. 14,15,19,17,12,15,16,18,18,12,14,15,19,17,14,16,
  128485. 17, 0,18,16,16,19,17, 0,11,14,14,18,19,12,15,14,
  128486. 17,17,13,16,14,17,16,14,17,16,18,18,15,18,15, 0,
  128487. 18,
  128488. };
  128489. static float _vq_quantthresh__16u0__p3_0[] = {
  128490. -1.5, -0.5, 0.5, 1.5,
  128491. };
  128492. static long _vq_quantmap__16u0__p3_0[] = {
  128493. 3, 1, 0, 2, 4,
  128494. };
  128495. static encode_aux_threshmatch _vq_auxt__16u0__p3_0 = {
  128496. _vq_quantthresh__16u0__p3_0,
  128497. _vq_quantmap__16u0__p3_0,
  128498. 5,
  128499. 5
  128500. };
  128501. static static_codebook _16u0__p3_0 = {
  128502. 4, 625,
  128503. _vq_lengthlist__16u0__p3_0,
  128504. 1, -533725184, 1611661312, 3, 0,
  128505. _vq_quantlist__16u0__p3_0,
  128506. NULL,
  128507. &_vq_auxt__16u0__p3_0,
  128508. NULL,
  128509. 0
  128510. };
  128511. static long _vq_quantlist__16u0__p4_0[] = {
  128512. 2,
  128513. 1,
  128514. 3,
  128515. 0,
  128516. 4,
  128517. };
  128518. static long _vq_lengthlist__16u0__p4_0[] = {
  128519. 3, 5, 5, 8, 8, 6, 6, 6, 9, 9, 6, 6, 6, 9, 9, 9,
  128520. 10, 9,11,11, 9, 9, 9,11,11, 6, 7, 7,10,10, 7, 7,
  128521. 8,10,10, 7, 7, 8,10,10,10,10,10,11,12, 9,10,10,
  128522. 11,12, 6, 7, 7,10,10, 7, 8, 7,10,10, 7, 8, 7,10,
  128523. 10,10,11,10,12,11,10,10,10,13,10, 9,10,10,12,12,
  128524. 10,11,10,14,12, 9,11,11,13,13,11,12,13,13,13,11,
  128525. 12,12,15,13, 9,10,10,12,13, 9,11,10,12,13,10,10,
  128526. 11,12,13,11,12,12,12,13,11,12,12,13,13, 5, 7, 7,
  128527. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,12,
  128528. 13,10,10,11,12,12, 6, 8, 8,11,10, 7, 8, 9,10,12,
  128529. 8, 9, 9,11,11,11,10,11,11,12,10,11,11,13,12, 7,
  128530. 8, 8,10,11, 8, 9, 8,11,10, 8, 9, 9,11,11,10,12,
  128531. 10,13,11,10,11,11,13,13,10,11,10,14,13,10,10,11,
  128532. 13,13,10,12,11,14,13,12,11,13,12,13,13,12,13,14,
  128533. 14,10,11,11,13,13,10,11,10,12,13,10,12,12,12,14,
  128534. 12,12,12,14,12,12,13,12,17,15, 5, 7, 7,10,10, 7,
  128535. 8, 8,10,10, 7, 8, 8,11,10,10,10,11,12,12,10,11,
  128536. 11,12,13, 6, 8, 8,11,10, 8, 9, 9,11,11, 7, 8, 9,
  128537. 10,11,11,11,11,12,12,10,10,11,12,13, 6, 8, 8,10,
  128538. 11, 8, 9, 9,11,11, 7, 9, 7,11,10,10,12,12,13,13,
  128539. 11,11,10,13,11, 9,11,10,14,13,11,11,11,15,13,10,
  128540. 10,11,13,13,12,13,13,14,14,12,11,12,12,13,10,11,
  128541. 11,12,13,10,11,12,13,13,10,11,10,13,12,12,12,13,
  128542. 14, 0,12,13,11,13,11, 8,10,10,13,13,10,11,11,14,
  128543. 13,10,11,11,13,12,13,14,14,14,15,12,12,12,15,14,
  128544. 9,11,10,13,12,10,10,11,13,14,11,11,11,15,12,13,
  128545. 12,14,15,16,13,13,13,14,13, 9,11,11,12,12,10,12,
  128546. 11,13,13,10,11,11,13,14,13,13,13,15,15,13,13,14,
  128547. 17,15,11,12,12,14,14,10,11,12,13,15,12,13,13, 0,
  128548. 15,13,11,14,12,16,14,16,14, 0,15,11,12,12,14,16,
  128549. 11,13,12,16,15,12,13,13,14,15,12,14,12,15,13,15,
  128550. 14,14,16,16, 8,10,10,13,13,10,11,10,13,14,10,11,
  128551. 11,13,13,13,13,12,14,14,14,13,13,16,17, 9,10,10,
  128552. 12,14,10,12,11,14,13,10,11,12,13,14,12,12,12,15,
  128553. 15,13,13,13,14,14, 9,10,10,13,13,10,11,12,12,14,
  128554. 10,11,10,13,13,13,13,13,14,16,13,13,13,14,14,11,
  128555. 12,13,15,13,12,14,13,14,16,12,12,13,13,14,13,14,
  128556. 14,17,15,13,12,17,13,16,11,12,13,14,15,12,13,14,
  128557. 14,17,11,12,11,14,14,13,16,14,16, 0,14,15,11,15,
  128558. 11,
  128559. };
  128560. static float _vq_quantthresh__16u0__p4_0[] = {
  128561. -1.5, -0.5, 0.5, 1.5,
  128562. };
  128563. static long _vq_quantmap__16u0__p4_0[] = {
  128564. 3, 1, 0, 2, 4,
  128565. };
  128566. static encode_aux_threshmatch _vq_auxt__16u0__p4_0 = {
  128567. _vq_quantthresh__16u0__p4_0,
  128568. _vq_quantmap__16u0__p4_0,
  128569. 5,
  128570. 5
  128571. };
  128572. static static_codebook _16u0__p4_0 = {
  128573. 4, 625,
  128574. _vq_lengthlist__16u0__p4_0,
  128575. 1, -533725184, 1611661312, 3, 0,
  128576. _vq_quantlist__16u0__p4_0,
  128577. NULL,
  128578. &_vq_auxt__16u0__p4_0,
  128579. NULL,
  128580. 0
  128581. };
  128582. static long _vq_quantlist__16u0__p5_0[] = {
  128583. 4,
  128584. 3,
  128585. 5,
  128586. 2,
  128587. 6,
  128588. 1,
  128589. 7,
  128590. 0,
  128591. 8,
  128592. };
  128593. static long _vq_lengthlist__16u0__p5_0[] = {
  128594. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  128595. 9, 9, 4, 6, 6, 8, 8, 8, 8, 9, 9, 7, 8, 8, 9, 9,
  128596. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,11, 7, 8, 8,
  128597. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  128598. 9, 9,10,10,11,11,12,12, 9, 9, 9,10,10,11,11,12,
  128599. 12,
  128600. };
  128601. static float _vq_quantthresh__16u0__p5_0[] = {
  128602. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  128603. };
  128604. static long _vq_quantmap__16u0__p5_0[] = {
  128605. 7, 5, 3, 1, 0, 2, 4, 6,
  128606. 8,
  128607. };
  128608. static encode_aux_threshmatch _vq_auxt__16u0__p5_0 = {
  128609. _vq_quantthresh__16u0__p5_0,
  128610. _vq_quantmap__16u0__p5_0,
  128611. 9,
  128612. 9
  128613. };
  128614. static static_codebook _16u0__p5_0 = {
  128615. 2, 81,
  128616. _vq_lengthlist__16u0__p5_0,
  128617. 1, -531628032, 1611661312, 4, 0,
  128618. _vq_quantlist__16u0__p5_0,
  128619. NULL,
  128620. &_vq_auxt__16u0__p5_0,
  128621. NULL,
  128622. 0
  128623. };
  128624. static long _vq_quantlist__16u0__p6_0[] = {
  128625. 6,
  128626. 5,
  128627. 7,
  128628. 4,
  128629. 8,
  128630. 3,
  128631. 9,
  128632. 2,
  128633. 10,
  128634. 1,
  128635. 11,
  128636. 0,
  128637. 12,
  128638. };
  128639. static long _vq_lengthlist__16u0__p6_0[] = {
  128640. 1, 4, 4, 7, 7,10,10,12,12,13,13,18,17, 3, 6, 6,
  128641. 9, 9,11,11,13,13,14,14,18,17, 3, 6, 6, 9, 9,11,
  128642. 11,13,13,14,14,17,18, 7, 9, 9,11,11,13,13,14,14,
  128643. 15,15, 0, 0, 7, 9, 9,11,11,13,13,14,14,15,16,19,
  128644. 18,10,11,11,13,13,14,14,16,15,17,18, 0, 0,10,11,
  128645. 11,13,13,14,14,15,15,16,18, 0, 0,11,13,13,14,14,
  128646. 15,15,17,17, 0,19, 0, 0,11,13,13,14,14,14,15,16,
  128647. 18, 0,19, 0, 0,13,14,14,15,15,18,17,18,18, 0,19,
  128648. 0, 0,13,14,14,15,16,16,16,18,18,19, 0, 0, 0,16,
  128649. 17,17, 0,17,19,19, 0,19, 0, 0, 0, 0,16,19,16,17,
  128650. 18, 0,19, 0, 0, 0, 0, 0, 0,
  128651. };
  128652. static float _vq_quantthresh__16u0__p6_0[] = {
  128653. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  128654. 12.5, 17.5, 22.5, 27.5,
  128655. };
  128656. static long _vq_quantmap__16u0__p6_0[] = {
  128657. 11, 9, 7, 5, 3, 1, 0, 2,
  128658. 4, 6, 8, 10, 12,
  128659. };
  128660. static encode_aux_threshmatch _vq_auxt__16u0__p6_0 = {
  128661. _vq_quantthresh__16u0__p6_0,
  128662. _vq_quantmap__16u0__p6_0,
  128663. 13,
  128664. 13
  128665. };
  128666. static static_codebook _16u0__p6_0 = {
  128667. 2, 169,
  128668. _vq_lengthlist__16u0__p6_0,
  128669. 1, -526516224, 1616117760, 4, 0,
  128670. _vq_quantlist__16u0__p6_0,
  128671. NULL,
  128672. &_vq_auxt__16u0__p6_0,
  128673. NULL,
  128674. 0
  128675. };
  128676. static long _vq_quantlist__16u0__p6_1[] = {
  128677. 2,
  128678. 1,
  128679. 3,
  128680. 0,
  128681. 4,
  128682. };
  128683. static long _vq_lengthlist__16u0__p6_1[] = {
  128684. 1, 4, 5, 6, 6, 4, 6, 6, 6, 6, 4, 6, 6, 6, 6, 6,
  128685. 6, 6, 7, 7, 6, 6, 6, 7, 7,
  128686. };
  128687. static float _vq_quantthresh__16u0__p6_1[] = {
  128688. -1.5, -0.5, 0.5, 1.5,
  128689. };
  128690. static long _vq_quantmap__16u0__p6_1[] = {
  128691. 3, 1, 0, 2, 4,
  128692. };
  128693. static encode_aux_threshmatch _vq_auxt__16u0__p6_1 = {
  128694. _vq_quantthresh__16u0__p6_1,
  128695. _vq_quantmap__16u0__p6_1,
  128696. 5,
  128697. 5
  128698. };
  128699. static static_codebook _16u0__p6_1 = {
  128700. 2, 25,
  128701. _vq_lengthlist__16u0__p6_1,
  128702. 1, -533725184, 1611661312, 3, 0,
  128703. _vq_quantlist__16u0__p6_1,
  128704. NULL,
  128705. &_vq_auxt__16u0__p6_1,
  128706. NULL,
  128707. 0
  128708. };
  128709. static long _vq_quantlist__16u0__p7_0[] = {
  128710. 1,
  128711. 0,
  128712. 2,
  128713. };
  128714. static long _vq_lengthlist__16u0__p7_0[] = {
  128715. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  128716. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  128717. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  128718. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  128719. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  128720. 7,
  128721. };
  128722. static float _vq_quantthresh__16u0__p7_0[] = {
  128723. -157.5, 157.5,
  128724. };
  128725. static long _vq_quantmap__16u0__p7_0[] = {
  128726. 1, 0, 2,
  128727. };
  128728. static encode_aux_threshmatch _vq_auxt__16u0__p7_0 = {
  128729. _vq_quantthresh__16u0__p7_0,
  128730. _vq_quantmap__16u0__p7_0,
  128731. 3,
  128732. 3
  128733. };
  128734. static static_codebook _16u0__p7_0 = {
  128735. 4, 81,
  128736. _vq_lengthlist__16u0__p7_0,
  128737. 1, -518803456, 1628680192, 2, 0,
  128738. _vq_quantlist__16u0__p7_0,
  128739. NULL,
  128740. &_vq_auxt__16u0__p7_0,
  128741. NULL,
  128742. 0
  128743. };
  128744. static long _vq_quantlist__16u0__p7_1[] = {
  128745. 7,
  128746. 6,
  128747. 8,
  128748. 5,
  128749. 9,
  128750. 4,
  128751. 10,
  128752. 3,
  128753. 11,
  128754. 2,
  128755. 12,
  128756. 1,
  128757. 13,
  128758. 0,
  128759. 14,
  128760. };
  128761. static long _vq_lengthlist__16u0__p7_1[] = {
  128762. 1, 5, 5, 6, 5, 9,10,11,11,10,10,10,10,10,10, 5,
  128763. 8, 8, 8,10,10,10,10,10,10,10,10,10,10,10, 5, 8,
  128764. 9, 9, 9,10,10,10,10,10,10,10,10,10,10, 5,10, 8,
  128765. 10,10,10,10,10,10,10,10,10,10,10,10, 4, 8, 9,10,
  128766. 10,10,10,10,10,10,10,10,10,10,10, 9,10,10,10,10,
  128767. 10,10,10,10,10,10,10,10,10,10, 9,10,10,10,10,10,
  128768. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128769. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128770. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128771. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128772. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128773. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128774. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128775. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128776. 10,
  128777. };
  128778. static float _vq_quantthresh__16u0__p7_1[] = {
  128779. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  128780. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  128781. };
  128782. static long _vq_quantmap__16u0__p7_1[] = {
  128783. 13, 11, 9, 7, 5, 3, 1, 0,
  128784. 2, 4, 6, 8, 10, 12, 14,
  128785. };
  128786. static encode_aux_threshmatch _vq_auxt__16u0__p7_1 = {
  128787. _vq_quantthresh__16u0__p7_1,
  128788. _vq_quantmap__16u0__p7_1,
  128789. 15,
  128790. 15
  128791. };
  128792. static static_codebook _16u0__p7_1 = {
  128793. 2, 225,
  128794. _vq_lengthlist__16u0__p7_1,
  128795. 1, -520986624, 1620377600, 4, 0,
  128796. _vq_quantlist__16u0__p7_1,
  128797. NULL,
  128798. &_vq_auxt__16u0__p7_1,
  128799. NULL,
  128800. 0
  128801. };
  128802. static long _vq_quantlist__16u0__p7_2[] = {
  128803. 10,
  128804. 9,
  128805. 11,
  128806. 8,
  128807. 12,
  128808. 7,
  128809. 13,
  128810. 6,
  128811. 14,
  128812. 5,
  128813. 15,
  128814. 4,
  128815. 16,
  128816. 3,
  128817. 17,
  128818. 2,
  128819. 18,
  128820. 1,
  128821. 19,
  128822. 0,
  128823. 20,
  128824. };
  128825. static long _vq_lengthlist__16u0__p7_2[] = {
  128826. 1, 6, 6, 7, 8, 7, 7,10, 9,10, 9,11,10, 9,11,10,
  128827. 9, 9, 9, 9,10, 6, 8, 7, 9, 9, 8, 8,10,10, 9,11,
  128828. 11,12,12,10, 9,11, 9,12,10, 9, 6, 9, 8, 9,12, 8,
  128829. 8,11, 9,11,11,12,11,12,12,10,11,11,10,10,11, 7,
  128830. 10, 9, 9, 9, 9, 9,10, 9,10, 9,10,10,12,10,10,10,
  128831. 11,12,10,10, 7, 9, 9, 9,10, 9, 9,10,10, 9, 9, 9,
  128832. 11,11,10,10,10,10, 9, 9,12, 7, 9,10, 9,11, 9,10,
  128833. 9,10,11,11,11,10,11,12, 9,12,11,10,10,10, 7, 9,
  128834. 9, 9, 9,10,12,10, 9,11,12,10,11,12,12,11, 9,10,
  128835. 11,10,11, 7, 9,10,10,11,10, 9,10,11,11,11,10,12,
  128836. 12,12,11,11,10,11,11,12, 8, 9,10,12,11,10,10,12,
  128837. 12,12,12,12,10,11,11, 9,11,10,12,11,11, 8, 9,10,
  128838. 10,11,12,11,11,10,10,10,12,12,12, 9,10,12,12,12,
  128839. 12,12, 8,10,11,10,10,12, 9,11,12,12,11,12,12,12,
  128840. 12,10,12,10,10,10,10, 8,12,11,11,11,10,10,11,12,
  128841. 12,12,12,11,12,12,12,11,11,11,12,10, 9,10,10,12,
  128842. 10,12,10,12,12,10,10,10,11,12,12,12,11,12,12,12,
  128843. 11,10,11,12,12,12,11,12,12,11,12,12,11,12,12,12,
  128844. 12,11,12,12,10,10,10,10,11,11,12,11,12,12,12,12,
  128845. 12,12,12,11,12,11,10,11,11,12,11,11, 9,10,10,10,
  128846. 12,10,10,11, 9,11,12,11,12,11,12,12,10,11,10,12,
  128847. 9, 9, 9,12,11,10,11,10,12,10,12,10,12,12,12,11,
  128848. 11,11,11,11,10, 9,10,10,11,10,11,11,12,11,10,11,
  128849. 12,12,12,11,11, 9,12,10,12, 9,10,12,10,10,11,10,
  128850. 11,11,12,11,10,11,10,11,11,11,11,12,11,11,10, 9,
  128851. 10,10,10, 9,11,11,10, 9,12,10,11,12,11,12,12,11,
  128852. 12,11,12,11,10,11,10,12,11,12,11,12,11,12,10,11,
  128853. 10,10,12,11,10,11,11,11,10,
  128854. };
  128855. static float _vq_quantthresh__16u0__p7_2[] = {
  128856. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  128857. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  128858. 6.5, 7.5, 8.5, 9.5,
  128859. };
  128860. static long _vq_quantmap__16u0__p7_2[] = {
  128861. 19, 17, 15, 13, 11, 9, 7, 5,
  128862. 3, 1, 0, 2, 4, 6, 8, 10,
  128863. 12, 14, 16, 18, 20,
  128864. };
  128865. static encode_aux_threshmatch _vq_auxt__16u0__p7_2 = {
  128866. _vq_quantthresh__16u0__p7_2,
  128867. _vq_quantmap__16u0__p7_2,
  128868. 21,
  128869. 21
  128870. };
  128871. static static_codebook _16u0__p7_2 = {
  128872. 2, 441,
  128873. _vq_lengthlist__16u0__p7_2,
  128874. 1, -529268736, 1611661312, 5, 0,
  128875. _vq_quantlist__16u0__p7_2,
  128876. NULL,
  128877. &_vq_auxt__16u0__p7_2,
  128878. NULL,
  128879. 0
  128880. };
  128881. static long _huff_lengthlist__16u0__single[] = {
  128882. 3, 5, 8, 7,14, 8, 9,19, 5, 2, 5, 5, 9, 6, 9,19,
  128883. 8, 4, 5, 7, 8, 9,13,19, 7, 4, 6, 5, 9, 6, 9,19,
  128884. 12, 8, 7, 9,10,11,13,19, 8, 5, 8, 6, 9, 6, 7,19,
  128885. 8, 8,10, 7, 7, 4, 5,19,12,17,19,15,18,13,11,18,
  128886. };
  128887. static static_codebook _huff_book__16u0__single = {
  128888. 2, 64,
  128889. _huff_lengthlist__16u0__single,
  128890. 0, 0, 0, 0, 0,
  128891. NULL,
  128892. NULL,
  128893. NULL,
  128894. NULL,
  128895. 0
  128896. };
  128897. static long _huff_lengthlist__16u1__long[] = {
  128898. 3, 6,10, 8,12, 8,14, 8,14,19, 5, 3, 5, 5, 7, 6,
  128899. 11, 7,16,19, 7, 5, 6, 7, 7, 9,11,12,19,19, 6, 4,
  128900. 7, 5, 7, 6,10, 7,18,18, 8, 6, 7, 7, 7, 7, 8, 9,
  128901. 18,18, 7, 5, 8, 5, 7, 5, 8, 6,18,18,12, 9,10, 9,
  128902. 9, 9, 8, 9,18,18, 8, 7,10, 6, 8, 5, 6, 4,11,18,
  128903. 11,15,16,12,11, 8, 8, 6, 9,18,14,18,18,18,16,16,
  128904. 16,13,16,18,
  128905. };
  128906. static static_codebook _huff_book__16u1__long = {
  128907. 2, 100,
  128908. _huff_lengthlist__16u1__long,
  128909. 0, 0, 0, 0, 0,
  128910. NULL,
  128911. NULL,
  128912. NULL,
  128913. NULL,
  128914. 0
  128915. };
  128916. static long _vq_quantlist__16u1__p1_0[] = {
  128917. 1,
  128918. 0,
  128919. 2,
  128920. };
  128921. static long _vq_lengthlist__16u1__p1_0[] = {
  128922. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 7, 7,10,10, 7,
  128923. 9,10, 5, 7, 8, 7,10, 9, 7,10,10, 5, 8, 8, 8,10,
  128924. 10, 8,10,10, 7,10,10,10,11,12,10,12,13, 7,10,10,
  128925. 9,13,11,10,12,13, 5, 8, 8, 8,10,10, 8,10,10, 7,
  128926. 10,10,10,12,12, 9,11,12, 7,10,11,10,12,12,10,13,
  128927. 11,
  128928. };
  128929. static float _vq_quantthresh__16u1__p1_0[] = {
  128930. -0.5, 0.5,
  128931. };
  128932. static long _vq_quantmap__16u1__p1_0[] = {
  128933. 1, 0, 2,
  128934. };
  128935. static encode_aux_threshmatch _vq_auxt__16u1__p1_0 = {
  128936. _vq_quantthresh__16u1__p1_0,
  128937. _vq_quantmap__16u1__p1_0,
  128938. 3,
  128939. 3
  128940. };
  128941. static static_codebook _16u1__p1_0 = {
  128942. 4, 81,
  128943. _vq_lengthlist__16u1__p1_0,
  128944. 1, -535822336, 1611661312, 2, 0,
  128945. _vq_quantlist__16u1__p1_0,
  128946. NULL,
  128947. &_vq_auxt__16u1__p1_0,
  128948. NULL,
  128949. 0
  128950. };
  128951. static long _vq_quantlist__16u1__p2_0[] = {
  128952. 1,
  128953. 0,
  128954. 2,
  128955. };
  128956. static long _vq_lengthlist__16u1__p2_0[] = {
  128957. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 7, 8, 6,
  128958. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 7, 5, 6, 6, 6, 8,
  128959. 8, 6, 8, 8, 6, 8, 8, 7, 7,10, 8, 9, 9, 6, 8, 8,
  128960. 7, 9, 8, 8, 9,10, 5, 6, 6, 6, 8, 8, 7, 8, 8, 6,
  128961. 8, 8, 8,10, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 7,10,
  128962. 8,
  128963. };
  128964. static float _vq_quantthresh__16u1__p2_0[] = {
  128965. -0.5, 0.5,
  128966. };
  128967. static long _vq_quantmap__16u1__p2_0[] = {
  128968. 1, 0, 2,
  128969. };
  128970. static encode_aux_threshmatch _vq_auxt__16u1__p2_0 = {
  128971. _vq_quantthresh__16u1__p2_0,
  128972. _vq_quantmap__16u1__p2_0,
  128973. 3,
  128974. 3
  128975. };
  128976. static static_codebook _16u1__p2_0 = {
  128977. 4, 81,
  128978. _vq_lengthlist__16u1__p2_0,
  128979. 1, -535822336, 1611661312, 2, 0,
  128980. _vq_quantlist__16u1__p2_0,
  128981. NULL,
  128982. &_vq_auxt__16u1__p2_0,
  128983. NULL,
  128984. 0
  128985. };
  128986. static long _vq_quantlist__16u1__p3_0[] = {
  128987. 2,
  128988. 1,
  128989. 3,
  128990. 0,
  128991. 4,
  128992. };
  128993. static long _vq_lengthlist__16u1__p3_0[] = {
  128994. 1, 5, 5, 8, 8, 6, 7, 7, 9, 9, 5, 7, 7, 9, 9, 9,
  128995. 10, 9,11,11, 9, 9,10,11,11, 6, 8, 8,10,10, 8, 9,
  128996. 10,11,11, 8, 9,10,11,11,10,11,11,12,13,10,11,11,
  128997. 13,13, 6, 8, 8,10,10, 8,10, 9,11,11, 8,10, 9,11,
  128998. 11,10,11,11,13,13,10,11,11,13,12, 9,11,11,14,13,
  128999. 10,12,12,15,14,10,12,11,14,13,12,13,13,15,15,12,
  129000. 13,13,16,14, 9,11,11,13,14,10,11,12,14,14,10,12,
  129001. 12,14,15,12,13,13,14,15,12,13,14,15,16, 5, 8, 8,
  129002. 11,11, 8,10,10,12,12, 8,10,10,12,12,11,12,12,14,
  129003. 14,11,12,12,14,14, 8,10,10,12,12, 9,11,12,12,13,
  129004. 10,12,12,13,13,12,12,13,14,15,11,13,13,15,15, 7,
  129005. 10,10,12,12, 9,12,11,13,12,10,11,12,13,13,12,13,
  129006. 12,15,14,11,12,13,15,15,10,12,12,15,14,11,13,13,
  129007. 16,15,11,13,13,16,15,14,13,14,15,16,13,15,15,17,
  129008. 17,10,12,12,14,15,11,12,12,15,15,11,13,13,15,16,
  129009. 13,15,13,16,15,13,15,15,16,17, 5, 8, 8,11,11, 8,
  129010. 10,10,12,12, 8,10,10,12,12,11,12,12,14,14,11,12,
  129011. 12,14,14, 7,10,10,12,12,10,12,12,14,13, 9,11,12,
  129012. 12,13,12,13,13,15,15,12,12,13,13,15, 7,10,10,12,
  129013. 13,10,11,12,13,13,10,12,11,13,13,11,13,13,15,15,
  129014. 12,13,12,15,14, 9,12,12,15,14,11,13,13,15,15,11,
  129015. 12,13,15,15,13,14,14,17,19,13,13,14,16,16,10,12,
  129016. 12,14,15,11,13,13,15,16,11,13,12,16,15,13,15,15,
  129017. 17,18,14,15,13,16,15, 8,11,11,15,14,10,12,12,16,
  129018. 15,10,12,12,16,16,14,15,15,18,17,13,14,15,16,18,
  129019. 9,12,12,15,15,11,12,14,16,17,11,13,13,16,15,15,
  129020. 15,15,17,18,14,15,16,17,17, 9,12,12,15,15,11,14,
  129021. 13,16,16,11,13,13,16,16,15,16,15,17,18,14,16,15,
  129022. 17,16,12,14,14,17,16,12,14,15,18,17,13,15,15,17,
  129023. 17,15,15,18,16,20,15,16,17,18,18,11,14,14,16,17,
  129024. 13,15,14,18,17,13,15,15,17,17,15,17,15,18,17,15,
  129025. 17,16,19,18, 8,11,11,14,15,10,12,12,15,15,10,12,
  129026. 12,16,16,13,14,14,17,16,14,15,15,17,17, 9,12,12,
  129027. 15,16,11,13,13,16,16,11,12,13,16,16,14,16,15,20,
  129028. 17,14,16,16,17,17, 9,12,12,15,16,11,13,13,16,17,
  129029. 11,13,13,17,16,14,15,15,17,18,15,15,15,18,18,11,
  129030. 14,14,17,16,13,15,15,17,17,13,14,14,18,17,15,16,
  129031. 16,18,19,15,15,17,17,19,11,14,14,16,17,13,15,14,
  129032. 17,19,13,15,14,18,17,15,17,16,18,18,15,17,15,18,
  129033. 16,
  129034. };
  129035. static float _vq_quantthresh__16u1__p3_0[] = {
  129036. -1.5, -0.5, 0.5, 1.5,
  129037. };
  129038. static long _vq_quantmap__16u1__p3_0[] = {
  129039. 3, 1, 0, 2, 4,
  129040. };
  129041. static encode_aux_threshmatch _vq_auxt__16u1__p3_0 = {
  129042. _vq_quantthresh__16u1__p3_0,
  129043. _vq_quantmap__16u1__p3_0,
  129044. 5,
  129045. 5
  129046. };
  129047. static static_codebook _16u1__p3_0 = {
  129048. 4, 625,
  129049. _vq_lengthlist__16u1__p3_0,
  129050. 1, -533725184, 1611661312, 3, 0,
  129051. _vq_quantlist__16u1__p3_0,
  129052. NULL,
  129053. &_vq_auxt__16u1__p3_0,
  129054. NULL,
  129055. 0
  129056. };
  129057. static long _vq_quantlist__16u1__p4_0[] = {
  129058. 2,
  129059. 1,
  129060. 3,
  129061. 0,
  129062. 4,
  129063. };
  129064. static long _vq_lengthlist__16u1__p4_0[] = {
  129065. 4, 5, 5, 8, 8, 6, 6, 7, 9, 9, 6, 6, 6, 9, 9, 9,
  129066. 10, 9,11,11, 9, 9,10,11,11, 6, 7, 7,10, 9, 7, 7,
  129067. 8, 9,10, 7, 7, 8,10,10,10,10,10,10,12, 9, 9,10,
  129068. 11,12, 6, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 7,10,
  129069. 10, 9,10, 9,12,11,10,10, 9,12,10, 9,10,10,12,11,
  129070. 10,10,10,12,12, 9,10,10,12,12,12,11,12,13,13,11,
  129071. 11,12,12,13, 9,10,10,11,12, 9,10,10,12,12,10,10,
  129072. 10,12,12,11,12,11,14,13,11,12,12,14,13, 5, 7, 7,
  129073. 10,10, 7, 8, 8,10,10, 7, 8, 7,10,10,10,10,10,12,
  129074. 12,10,10,10,12,12, 6, 8, 7,10,10, 7, 7, 9,10,11,
  129075. 8, 9, 9,11,10,10,10,11,11,13,10,10,11,12,13, 6,
  129076. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,10,11,10,11,
  129077. 10,13,11,10,11,10,12,12,10,11,10,12,11,10,10,10,
  129078. 12,13,10,11,11,13,12,11,11,13,11,14,12,12,13,14,
  129079. 14, 9,10,10,12,13,10,11,10,13,12,10,11,11,12,13,
  129080. 11,12,11,14,12,12,13,13,15,14, 5, 7, 7,10,10, 7,
  129081. 7, 8,10,10, 7, 8, 8,10,10,10,10,10,11,12,10,10,
  129082. 10,12,12, 7, 8, 8,10,10, 8, 9, 8,11,10, 7, 8, 9,
  129083. 10,11,10,11,11,12,12,10,10,11,11,13, 7, 7, 8,10,
  129084. 10, 8, 8, 9,10,11, 7, 9, 7,11,10,10,11,11,13,12,
  129085. 11,11,10,13,11, 9,10,10,12,12,10,11,11,13,12,10,
  129086. 10,11,12,12,12,13,13,14,14,11,11,12,12,14,10,10,
  129087. 11,12,12,10,11,11,12,13,10,10,10,13,12,12,13,13,
  129088. 15,14,12,13,10,14,11, 8,10,10,12,12,10,11,10,13,
  129089. 13, 9,10,10,12,12,12,13,13,15,14,11,12,12,13,13,
  129090. 9,10,10,13,12,10,10,11,13,13,10,11,10,13,12,12,
  129091. 12,13,14,15,12,13,12,15,13, 9,10,10,12,13,10,11,
  129092. 10,13,12,10,10,11,12,13,12,14,12,15,13,12,12,13,
  129093. 14,15,11,12,11,14,13,11,11,12,14,15,12,13,12,15,
  129094. 14,13,11,15,11,16,13,14,14,16,15,11,12,12,14,14,
  129095. 11,12,11,14,13,12,12,13,14,15,13,14,12,16,12,14,
  129096. 14,14,15,15, 8,10,10,12,12, 9,10,10,12,12,10,10,
  129097. 11,13,13,11,12,12,13,13,12,13,13,14,15, 9,10,10,
  129098. 13,12,10,11,11,13,12,10,10,11,13,13,12,13,12,15,
  129099. 14,12,12,13,13,16, 9, 9,10,12,13,10,10,11,12,13,
  129100. 10,11,10,13,13,12,12,13,13,15,13,13,12,15,13,11,
  129101. 12,12,14,14,12,13,12,15,14,11,11,12,13,14,14,14,
  129102. 14,16,15,13,12,15,12,16,11,11,12,13,14,12,13,13,
  129103. 14,15,10,12,11,14,13,14,15,14,16,16,13,14,11,15,
  129104. 11,
  129105. };
  129106. static float _vq_quantthresh__16u1__p4_0[] = {
  129107. -1.5, -0.5, 0.5, 1.5,
  129108. };
  129109. static long _vq_quantmap__16u1__p4_0[] = {
  129110. 3, 1, 0, 2, 4,
  129111. };
  129112. static encode_aux_threshmatch _vq_auxt__16u1__p4_0 = {
  129113. _vq_quantthresh__16u1__p4_0,
  129114. _vq_quantmap__16u1__p4_0,
  129115. 5,
  129116. 5
  129117. };
  129118. static static_codebook _16u1__p4_0 = {
  129119. 4, 625,
  129120. _vq_lengthlist__16u1__p4_0,
  129121. 1, -533725184, 1611661312, 3, 0,
  129122. _vq_quantlist__16u1__p4_0,
  129123. NULL,
  129124. &_vq_auxt__16u1__p4_0,
  129125. NULL,
  129126. 0
  129127. };
  129128. static long _vq_quantlist__16u1__p5_0[] = {
  129129. 4,
  129130. 3,
  129131. 5,
  129132. 2,
  129133. 6,
  129134. 1,
  129135. 7,
  129136. 0,
  129137. 8,
  129138. };
  129139. static long _vq_lengthlist__16u1__p5_0[] = {
  129140. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  129141. 10,10, 4, 5, 6, 8, 8, 8, 8,10,10, 7, 8, 8, 9, 9,
  129142. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 7, 8, 8,
  129143. 10, 9,11,11,12,11, 7, 8, 8, 9, 9,11,11,12,12, 9,
  129144. 10,10,11,11,12,12,13,12, 9,10,10,11,11,12,12,12,
  129145. 13,
  129146. };
  129147. static float _vq_quantthresh__16u1__p5_0[] = {
  129148. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  129149. };
  129150. static long _vq_quantmap__16u1__p5_0[] = {
  129151. 7, 5, 3, 1, 0, 2, 4, 6,
  129152. 8,
  129153. };
  129154. static encode_aux_threshmatch _vq_auxt__16u1__p5_0 = {
  129155. _vq_quantthresh__16u1__p5_0,
  129156. _vq_quantmap__16u1__p5_0,
  129157. 9,
  129158. 9
  129159. };
  129160. static static_codebook _16u1__p5_0 = {
  129161. 2, 81,
  129162. _vq_lengthlist__16u1__p5_0,
  129163. 1, -531628032, 1611661312, 4, 0,
  129164. _vq_quantlist__16u1__p5_0,
  129165. NULL,
  129166. &_vq_auxt__16u1__p5_0,
  129167. NULL,
  129168. 0
  129169. };
  129170. static long _vq_quantlist__16u1__p6_0[] = {
  129171. 4,
  129172. 3,
  129173. 5,
  129174. 2,
  129175. 6,
  129176. 1,
  129177. 7,
  129178. 0,
  129179. 8,
  129180. };
  129181. static long _vq_lengthlist__16u1__p6_0[] = {
  129182. 3, 4, 4, 6, 6, 7, 7, 9, 9, 4, 4, 4, 6, 6, 8, 8,
  129183. 9, 9, 4, 4, 4, 6, 6, 7, 7, 9, 9, 6, 6, 6, 7, 7,
  129184. 8, 8,10, 9, 6, 6, 6, 7, 7, 8, 8, 9,10, 7, 8, 7,
  129185. 8, 8, 9, 9,10,10, 7, 8, 8, 8, 8, 9, 9,10,10, 9,
  129186. 9, 9,10,10,10,10,11,11, 9, 9, 9,10,10,10,10,11,
  129187. 11,
  129188. };
  129189. static float _vq_quantthresh__16u1__p6_0[] = {
  129190. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  129191. };
  129192. static long _vq_quantmap__16u1__p6_0[] = {
  129193. 7, 5, 3, 1, 0, 2, 4, 6,
  129194. 8,
  129195. };
  129196. static encode_aux_threshmatch _vq_auxt__16u1__p6_0 = {
  129197. _vq_quantthresh__16u1__p6_0,
  129198. _vq_quantmap__16u1__p6_0,
  129199. 9,
  129200. 9
  129201. };
  129202. static static_codebook _16u1__p6_0 = {
  129203. 2, 81,
  129204. _vq_lengthlist__16u1__p6_0,
  129205. 1, -531628032, 1611661312, 4, 0,
  129206. _vq_quantlist__16u1__p6_0,
  129207. NULL,
  129208. &_vq_auxt__16u1__p6_0,
  129209. NULL,
  129210. 0
  129211. };
  129212. static long _vq_quantlist__16u1__p7_0[] = {
  129213. 1,
  129214. 0,
  129215. 2,
  129216. };
  129217. static long _vq_lengthlist__16u1__p7_0[] = {
  129218. 1, 4, 4, 4, 8, 8, 4, 8, 8, 5,11, 9, 8,12,11, 8,
  129219. 12,11, 5,10,11, 8,11,12, 8,11,12, 4,11,11,11,14,
  129220. 13,10,13,13, 8,14,13,12,14,16,12,16,15, 8,14,14,
  129221. 13,16,14,12,15,16, 4,11,11,10,14,13,11,14,14, 8,
  129222. 15,14,12,15,15,12,14,16, 8,14,14,11,16,15,12,15,
  129223. 13,
  129224. };
  129225. static float _vq_quantthresh__16u1__p7_0[] = {
  129226. -5.5, 5.5,
  129227. };
  129228. static long _vq_quantmap__16u1__p7_0[] = {
  129229. 1, 0, 2,
  129230. };
  129231. static encode_aux_threshmatch _vq_auxt__16u1__p7_0 = {
  129232. _vq_quantthresh__16u1__p7_0,
  129233. _vq_quantmap__16u1__p7_0,
  129234. 3,
  129235. 3
  129236. };
  129237. static static_codebook _16u1__p7_0 = {
  129238. 4, 81,
  129239. _vq_lengthlist__16u1__p7_0,
  129240. 1, -529137664, 1618345984, 2, 0,
  129241. _vq_quantlist__16u1__p7_0,
  129242. NULL,
  129243. &_vq_auxt__16u1__p7_0,
  129244. NULL,
  129245. 0
  129246. };
  129247. static long _vq_quantlist__16u1__p7_1[] = {
  129248. 5,
  129249. 4,
  129250. 6,
  129251. 3,
  129252. 7,
  129253. 2,
  129254. 8,
  129255. 1,
  129256. 9,
  129257. 0,
  129258. 10,
  129259. };
  129260. static long _vq_lengthlist__16u1__p7_1[] = {
  129261. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 6, 5, 7, 7,
  129262. 8, 8, 8, 8, 8, 8, 4, 5, 6, 7, 7, 8, 8, 8, 8, 8,
  129263. 8, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8,
  129264. 8, 8, 8, 9, 9, 9, 9, 7, 8, 8, 8, 8, 9, 9, 9,10,
  129265. 9,10, 7, 8, 8, 8, 8, 9, 9, 9, 9,10, 9, 8, 8, 8,
  129266. 9, 9,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9,10,
  129267. 10,10,10, 8, 8, 8, 9, 9, 9,10,10,10,10,10, 8, 8,
  129268. 8, 9, 9,10,10,10,10,10,10,
  129269. };
  129270. static float _vq_quantthresh__16u1__p7_1[] = {
  129271. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  129272. 3.5, 4.5,
  129273. };
  129274. static long _vq_quantmap__16u1__p7_1[] = {
  129275. 9, 7, 5, 3, 1, 0, 2, 4,
  129276. 6, 8, 10,
  129277. };
  129278. static encode_aux_threshmatch _vq_auxt__16u1__p7_1 = {
  129279. _vq_quantthresh__16u1__p7_1,
  129280. _vq_quantmap__16u1__p7_1,
  129281. 11,
  129282. 11
  129283. };
  129284. static static_codebook _16u1__p7_1 = {
  129285. 2, 121,
  129286. _vq_lengthlist__16u1__p7_1,
  129287. 1, -531365888, 1611661312, 4, 0,
  129288. _vq_quantlist__16u1__p7_1,
  129289. NULL,
  129290. &_vq_auxt__16u1__p7_1,
  129291. NULL,
  129292. 0
  129293. };
  129294. static long _vq_quantlist__16u1__p8_0[] = {
  129295. 5,
  129296. 4,
  129297. 6,
  129298. 3,
  129299. 7,
  129300. 2,
  129301. 8,
  129302. 1,
  129303. 9,
  129304. 0,
  129305. 10,
  129306. };
  129307. static long _vq_lengthlist__16u1__p8_0[] = {
  129308. 1, 4, 4, 5, 5, 8, 8,10,10,12,12, 4, 7, 7, 8, 8,
  129309. 9, 9,12,11,14,13, 4, 7, 7, 7, 8, 9,10,11,11,13,
  129310. 12, 5, 8, 8, 9, 9,11,11,12,13,15,14, 5, 7, 8, 9,
  129311. 9,11,11,13,13,17,15, 8, 9,10,11,11,12,13,17,14,
  129312. 17,16, 8,10, 9,11,11,12,12,13,15,15,17,10,11,11,
  129313. 12,13,14,15,15,16,16,17, 9,11,11,12,12,14,15,17,
  129314. 15,15,16,11,14,12,14,15,16,15,16,16,16,15,11,13,
  129315. 13,14,14,15,15,16,16,15,16,
  129316. };
  129317. static float _vq_quantthresh__16u1__p8_0[] = {
  129318. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  129319. 38.5, 49.5,
  129320. };
  129321. static long _vq_quantmap__16u1__p8_0[] = {
  129322. 9, 7, 5, 3, 1, 0, 2, 4,
  129323. 6, 8, 10,
  129324. };
  129325. static encode_aux_threshmatch _vq_auxt__16u1__p8_0 = {
  129326. _vq_quantthresh__16u1__p8_0,
  129327. _vq_quantmap__16u1__p8_0,
  129328. 11,
  129329. 11
  129330. };
  129331. static static_codebook _16u1__p8_0 = {
  129332. 2, 121,
  129333. _vq_lengthlist__16u1__p8_0,
  129334. 1, -524582912, 1618345984, 4, 0,
  129335. _vq_quantlist__16u1__p8_0,
  129336. NULL,
  129337. &_vq_auxt__16u1__p8_0,
  129338. NULL,
  129339. 0
  129340. };
  129341. static long _vq_quantlist__16u1__p8_1[] = {
  129342. 5,
  129343. 4,
  129344. 6,
  129345. 3,
  129346. 7,
  129347. 2,
  129348. 8,
  129349. 1,
  129350. 9,
  129351. 0,
  129352. 10,
  129353. };
  129354. static long _vq_lengthlist__16u1__p8_1[] = {
  129355. 2, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 4, 6, 6, 7, 7,
  129356. 8, 7, 8, 8, 8, 8, 4, 6, 6, 7, 7, 7, 7, 8, 8, 8,
  129357. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 9, 6, 7, 7, 7,
  129358. 7, 8, 8, 8, 8, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9,
  129359. 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8,
  129360. 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9,
  129361. 9, 9, 9, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 8, 8,
  129362. 8, 9, 9, 9, 9, 9, 9, 9, 9,
  129363. };
  129364. static float _vq_quantthresh__16u1__p8_1[] = {
  129365. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  129366. 3.5, 4.5,
  129367. };
  129368. static long _vq_quantmap__16u1__p8_1[] = {
  129369. 9, 7, 5, 3, 1, 0, 2, 4,
  129370. 6, 8, 10,
  129371. };
  129372. static encode_aux_threshmatch _vq_auxt__16u1__p8_1 = {
  129373. _vq_quantthresh__16u1__p8_1,
  129374. _vq_quantmap__16u1__p8_1,
  129375. 11,
  129376. 11
  129377. };
  129378. static static_codebook _16u1__p8_1 = {
  129379. 2, 121,
  129380. _vq_lengthlist__16u1__p8_1,
  129381. 1, -531365888, 1611661312, 4, 0,
  129382. _vq_quantlist__16u1__p8_1,
  129383. NULL,
  129384. &_vq_auxt__16u1__p8_1,
  129385. NULL,
  129386. 0
  129387. };
  129388. static long _vq_quantlist__16u1__p9_0[] = {
  129389. 7,
  129390. 6,
  129391. 8,
  129392. 5,
  129393. 9,
  129394. 4,
  129395. 10,
  129396. 3,
  129397. 11,
  129398. 2,
  129399. 12,
  129400. 1,
  129401. 13,
  129402. 0,
  129403. 14,
  129404. };
  129405. static long _vq_lengthlist__16u1__p9_0[] = {
  129406. 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129407. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129408. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129409. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129410. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129411. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129412. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129413. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129414. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129415. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129416. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129417. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129418. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  129419. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  129420. 8,
  129421. };
  129422. static float _vq_quantthresh__16u1__p9_0[] = {
  129423. -1657.5, -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5,
  129424. 382.5, 637.5, 892.5, 1147.5, 1402.5, 1657.5,
  129425. };
  129426. static long _vq_quantmap__16u1__p9_0[] = {
  129427. 13, 11, 9, 7, 5, 3, 1, 0,
  129428. 2, 4, 6, 8, 10, 12, 14,
  129429. };
  129430. static encode_aux_threshmatch _vq_auxt__16u1__p9_0 = {
  129431. _vq_quantthresh__16u1__p9_0,
  129432. _vq_quantmap__16u1__p9_0,
  129433. 15,
  129434. 15
  129435. };
  129436. static static_codebook _16u1__p9_0 = {
  129437. 2, 225,
  129438. _vq_lengthlist__16u1__p9_0,
  129439. 1, -514071552, 1627381760, 4, 0,
  129440. _vq_quantlist__16u1__p9_0,
  129441. NULL,
  129442. &_vq_auxt__16u1__p9_0,
  129443. NULL,
  129444. 0
  129445. };
  129446. static long _vq_quantlist__16u1__p9_1[] = {
  129447. 7,
  129448. 6,
  129449. 8,
  129450. 5,
  129451. 9,
  129452. 4,
  129453. 10,
  129454. 3,
  129455. 11,
  129456. 2,
  129457. 12,
  129458. 1,
  129459. 13,
  129460. 0,
  129461. 14,
  129462. };
  129463. static long _vq_lengthlist__16u1__p9_1[] = {
  129464. 1, 6, 5, 9, 9,10,10, 6, 7, 9, 9,10,10,10,10, 5,
  129465. 10, 8,10, 8,10,10, 8, 8,10, 9,10,10,10,10, 5, 8,
  129466. 9,10,10,10,10, 8,10,10,10,10,10,10,10, 9,10,10,
  129467. 10,10,10,10, 9, 9,10,10,10,10,10,10, 9, 9, 8, 9,
  129468. 10,10,10, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  129469. 10,10,10,10,10,10,10,10,10,10,10, 8,10,10,10,10,
  129470. 10,10,10,10,10,10,10,10,10, 6, 8, 8,10,10,10, 8,
  129471. 10,10,10,10,10,10,10,10, 5, 8, 8,10,10,10, 9, 9,
  129472. 10,10,10,10,10,10,10,10, 9,10,10,10,10,10,10,10,
  129473. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129474. 10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  129475. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129476. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129477. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129478. 9,
  129479. };
  129480. static float _vq_quantthresh__16u1__p9_1[] = {
  129481. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  129482. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  129483. };
  129484. static long _vq_quantmap__16u1__p9_1[] = {
  129485. 13, 11, 9, 7, 5, 3, 1, 0,
  129486. 2, 4, 6, 8, 10, 12, 14,
  129487. };
  129488. static encode_aux_threshmatch _vq_auxt__16u1__p9_1 = {
  129489. _vq_quantthresh__16u1__p9_1,
  129490. _vq_quantmap__16u1__p9_1,
  129491. 15,
  129492. 15
  129493. };
  129494. static static_codebook _16u1__p9_1 = {
  129495. 2, 225,
  129496. _vq_lengthlist__16u1__p9_1,
  129497. 1, -522338304, 1620115456, 4, 0,
  129498. _vq_quantlist__16u1__p9_1,
  129499. NULL,
  129500. &_vq_auxt__16u1__p9_1,
  129501. NULL,
  129502. 0
  129503. };
  129504. static long _vq_quantlist__16u1__p9_2[] = {
  129505. 8,
  129506. 7,
  129507. 9,
  129508. 6,
  129509. 10,
  129510. 5,
  129511. 11,
  129512. 4,
  129513. 12,
  129514. 3,
  129515. 13,
  129516. 2,
  129517. 14,
  129518. 1,
  129519. 15,
  129520. 0,
  129521. 16,
  129522. };
  129523. static long _vq_lengthlist__16u1__p9_2[] = {
  129524. 1, 6, 6, 7, 8, 8,11,10, 9, 9,11, 9,10, 9,11,11,
  129525. 9, 6, 7, 6,11, 8,11, 9,10,10,11, 9,11,10,10,10,
  129526. 11, 9, 5, 7, 7, 8, 8,10,11, 8, 8,11, 9, 9,10,11,
  129527. 9,10,11, 8, 9, 6, 8, 8, 9, 9,10,10,11,11,11, 9,
  129528. 11,10, 9,11, 8, 8, 8, 9, 8, 9,10,11, 9, 9,11,11,
  129529. 10, 9, 9,11,10, 8,11, 8, 9, 8,11, 9,10, 9,10,11,
  129530. 11,10,10, 9,10,10, 8, 8, 9,10,10,10, 9,11, 9,10,
  129531. 11,11,11,11,10, 9,11, 9, 9,11,11,10, 8,11,11,11,
  129532. 9,10,10,11,10,11,11, 9,11,10, 9,11,10,10,10,10,
  129533. 9,11,10,11,10, 9, 9,10,11, 9, 8,10,11,11,10,10,
  129534. 11, 9,11,10,11,11,10,11, 9, 9, 8,10, 8, 9,11, 9,
  129535. 8,10,10, 9,11,10,11,10,11, 9,11, 8,10,11,11,11,
  129536. 11,10,10,11,11,11,11,10,11,11,10, 9, 8,10,10, 9,
  129537. 11,10,11,11,11, 9, 9, 9,11,11,11,10,10, 9, 9,10,
  129538. 9,11,11,11,11, 8,10,11,10,11,11,10,11,11, 9, 9,
  129539. 9,10, 9,11, 9,11,11,11,11,11,10,11,11,10,11,10,
  129540. 11,11, 9,11,10,11,10, 9,10, 9,10,10,11,11,11,11,
  129541. 9,10, 9,10,11,11,10,11,11,11,11,11,11,10,11,11,
  129542. 10,
  129543. };
  129544. static float _vq_quantthresh__16u1__p9_2[] = {
  129545. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  129546. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  129547. };
  129548. static long _vq_quantmap__16u1__p9_2[] = {
  129549. 15, 13, 11, 9, 7, 5, 3, 1,
  129550. 0, 2, 4, 6, 8, 10, 12, 14,
  129551. 16,
  129552. };
  129553. static encode_aux_threshmatch _vq_auxt__16u1__p9_2 = {
  129554. _vq_quantthresh__16u1__p9_2,
  129555. _vq_quantmap__16u1__p9_2,
  129556. 17,
  129557. 17
  129558. };
  129559. static static_codebook _16u1__p9_2 = {
  129560. 2, 289,
  129561. _vq_lengthlist__16u1__p9_2,
  129562. 1, -529530880, 1611661312, 5, 0,
  129563. _vq_quantlist__16u1__p9_2,
  129564. NULL,
  129565. &_vq_auxt__16u1__p9_2,
  129566. NULL,
  129567. 0
  129568. };
  129569. static long _huff_lengthlist__16u1__short[] = {
  129570. 5, 7,10, 9,11,10,15,11,13,16, 6, 4, 6, 6, 7, 7,
  129571. 10, 9,12,16,10, 6, 5, 6, 6, 7,10,11,16,16, 9, 6,
  129572. 7, 6, 7, 7,10, 8,14,16,11, 6, 5, 4, 5, 6, 8, 9,
  129573. 15,16, 9, 6, 6, 5, 6, 6, 9, 8,14,16,12, 7, 6, 6,
  129574. 5, 6, 6, 7,13,16, 8, 6, 7, 6, 5, 5, 4, 4,11,16,
  129575. 9, 8, 9, 9, 7, 7, 6, 5,13,16,14,14,16,15,16,15,
  129576. 16,16,16,16,
  129577. };
  129578. static static_codebook _huff_book__16u1__short = {
  129579. 2, 100,
  129580. _huff_lengthlist__16u1__short,
  129581. 0, 0, 0, 0, 0,
  129582. NULL,
  129583. NULL,
  129584. NULL,
  129585. NULL,
  129586. 0
  129587. };
  129588. static long _huff_lengthlist__16u2__long[] = {
  129589. 5, 7,10,10,10,11,11,13,18,19, 6, 5, 5, 6, 7, 8,
  129590. 9,12,19,19, 8, 5, 4, 4, 6, 7, 9,13,19,19, 8, 5,
  129591. 4, 4, 5, 6, 8,12,17,19, 7, 5, 5, 4, 4, 5, 7,12,
  129592. 18,18, 8, 7, 7, 6, 5, 5, 6,10,18,18, 9, 9, 9, 8,
  129593. 6, 5, 6, 9,18,18,11,13,13,13, 8, 7, 7, 9,16,18,
  129594. 13,17,18,16,11, 9, 9, 9,17,18,15,18,18,18,15,13,
  129595. 13,14,18,18,
  129596. };
  129597. static static_codebook _huff_book__16u2__long = {
  129598. 2, 100,
  129599. _huff_lengthlist__16u2__long,
  129600. 0, 0, 0, 0, 0,
  129601. NULL,
  129602. NULL,
  129603. NULL,
  129604. NULL,
  129605. 0
  129606. };
  129607. static long _huff_lengthlist__16u2__short[] = {
  129608. 8,11,12,12,14,15,16,16,16,16, 9, 7, 7, 8, 9,11,
  129609. 13,14,16,16,13, 7, 6, 6, 7, 9,12,13,15,16,15, 7,
  129610. 6, 5, 4, 6,10,11,14,16,12, 8, 7, 4, 2, 4, 7,10,
  129611. 14,16,11, 9, 7, 5, 3, 4, 6, 9,14,16,11,10, 9, 7,
  129612. 5, 5, 6, 9,16,16,10,10, 9, 8, 6, 6, 7,10,16,16,
  129613. 11,11,11,10,10,10,11,14,16,16,16,14,14,13,14,16,
  129614. 16,16,16,16,
  129615. };
  129616. static static_codebook _huff_book__16u2__short = {
  129617. 2, 100,
  129618. _huff_lengthlist__16u2__short,
  129619. 0, 0, 0, 0, 0,
  129620. NULL,
  129621. NULL,
  129622. NULL,
  129623. NULL,
  129624. 0
  129625. };
  129626. static long _vq_quantlist__16u2_p1_0[] = {
  129627. 1,
  129628. 0,
  129629. 2,
  129630. };
  129631. static long _vq_lengthlist__16u2_p1_0[] = {
  129632. 1, 5, 5, 5, 7, 7, 5, 7, 7, 5, 7, 7, 7, 9, 9, 7,
  129633. 9, 9, 5, 7, 7, 7, 9, 9, 7, 9, 9, 5, 7, 7, 8, 9,
  129634. 9, 7, 9, 9, 7, 9, 9, 9,10,10, 9,10,10, 7, 9, 9,
  129635. 9,10,10, 9,10,11, 5, 7, 8, 8, 9, 9, 8, 9, 9, 7,
  129636. 9, 9, 9,10,10, 9, 9,10, 7, 9, 9, 9,10,10, 9,11,
  129637. 10,
  129638. };
  129639. static float _vq_quantthresh__16u2_p1_0[] = {
  129640. -0.5, 0.5,
  129641. };
  129642. static long _vq_quantmap__16u2_p1_0[] = {
  129643. 1, 0, 2,
  129644. };
  129645. static encode_aux_threshmatch _vq_auxt__16u2_p1_0 = {
  129646. _vq_quantthresh__16u2_p1_0,
  129647. _vq_quantmap__16u2_p1_0,
  129648. 3,
  129649. 3
  129650. };
  129651. static static_codebook _16u2_p1_0 = {
  129652. 4, 81,
  129653. _vq_lengthlist__16u2_p1_0,
  129654. 1, -535822336, 1611661312, 2, 0,
  129655. _vq_quantlist__16u2_p1_0,
  129656. NULL,
  129657. &_vq_auxt__16u2_p1_0,
  129658. NULL,
  129659. 0
  129660. };
  129661. static long _vq_quantlist__16u2_p2_0[] = {
  129662. 2,
  129663. 1,
  129664. 3,
  129665. 0,
  129666. 4,
  129667. };
  129668. static long _vq_lengthlist__16u2_p2_0[] = {
  129669. 3, 5, 5, 8, 8, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 9,
  129670. 10, 9,11,11, 9, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  129671. 8,10,10, 7, 8, 8,10,10,10,10,10,12,12, 9,10,10,
  129672. 11,12, 5, 7, 7, 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,
  129673. 10, 9,10,10,12,11,10,10,10,12,12, 9,10,10,12,12,
  129674. 10,11,10,13,12, 9,10,10,12,12,12,12,12,14,14,11,
  129675. 12,12,13,14, 9,10,10,12,12, 9,10,10,12,12,10,10,
  129676. 10,12,12,11,12,12,14,13,12,13,12,14,14, 5, 7, 7,
  129677. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,12,
  129678. 12,10,10,11,12,12, 7, 8, 8,10,10, 8, 9, 9,11,11,
  129679. 8, 9, 9,11,11,11,11,11,12,13,10,11,11,12,13, 7,
  129680. 8, 8,10,10, 8, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  129681. 10,13,12,10,11,11,13,13, 9,11,10,13,13,10,11,11,
  129682. 13,13,10,11,11,13,13,12,12,13,13,15,12,12,13,14,
  129683. 15, 9,10,10,12,12,10,11,10,13,12,10,11,11,13,13,
  129684. 11,13,11,14,13,12,13,13,15,15, 5, 7, 7, 9, 9, 7,
  129685. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,12,10,10,
  129686. 11,12,12, 7, 8, 8,10,10, 8, 9, 9,11,11, 8, 8, 9,
  129687. 10,11,10,11,11,13,13,10,10,11,12,13, 7, 8, 8,10,
  129688. 11, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,11,13,12,
  129689. 11,11,11,13,12, 9,10,10,12,12,10,11,11,13,13,10,
  129690. 10,11,12,13,12,13,13,15,14,11,11,13,12,14,10,10,
  129691. 11,13,13,10,11,11,13,13,10,11,11,13,13,12,13,13,
  129692. 14,14,12,13,12,14,13, 8,10, 9,12,12, 9,11,10,13,
  129693. 13, 9,10,10,12,13,12,13,13,14,14,12,12,13,14,14,
  129694. 9,11,10,13,13,10,11,11,13,13,10,11,11,13,13,12,
  129695. 13,13,15,15,13,13,13,14,15, 9,10,10,12,13,10,11,
  129696. 10,13,12,10,11,11,13,13,12,13,12,15,14,13,13,13,
  129697. 14,15,11,12,12,15,14,12,12,13,15,15,12,13,13,15,
  129698. 14,14,13,15,14,16,13,14,15,16,16,11,12,12,14,14,
  129699. 11,12,12,15,14,12,13,13,15,15,13,14,13,16,14,14,
  129700. 14,14,16,16, 8, 9, 9,12,12, 9,10,10,13,12, 9,10,
  129701. 10,13,13,12,12,12,14,14,12,12,13,15,15, 9,10,10,
  129702. 13,12,10,11,11,13,13,10,10,11,13,14,12,13,13,15,
  129703. 15,12,12,13,14,15, 9,10,10,13,13,10,11,11,13,13,
  129704. 10,11,11,13,13,12,13,13,14,14,13,14,13,15,14,11,
  129705. 12,12,14,14,12,13,13,15,14,11,12,12,14,15,14,14,
  129706. 14,16,15,13,12,14,14,16,11,12,13,14,15,12,13,13,
  129707. 14,16,12,13,12,15,14,13,15,14,16,16,14,15,13,16,
  129708. 13,
  129709. };
  129710. static float _vq_quantthresh__16u2_p2_0[] = {
  129711. -1.5, -0.5, 0.5, 1.5,
  129712. };
  129713. static long _vq_quantmap__16u2_p2_0[] = {
  129714. 3, 1, 0, 2, 4,
  129715. };
  129716. static encode_aux_threshmatch _vq_auxt__16u2_p2_0 = {
  129717. _vq_quantthresh__16u2_p2_0,
  129718. _vq_quantmap__16u2_p2_0,
  129719. 5,
  129720. 5
  129721. };
  129722. static static_codebook _16u2_p2_0 = {
  129723. 4, 625,
  129724. _vq_lengthlist__16u2_p2_0,
  129725. 1, -533725184, 1611661312, 3, 0,
  129726. _vq_quantlist__16u2_p2_0,
  129727. NULL,
  129728. &_vq_auxt__16u2_p2_0,
  129729. NULL,
  129730. 0
  129731. };
  129732. static long _vq_quantlist__16u2_p3_0[] = {
  129733. 4,
  129734. 3,
  129735. 5,
  129736. 2,
  129737. 6,
  129738. 1,
  129739. 7,
  129740. 0,
  129741. 8,
  129742. };
  129743. static long _vq_lengthlist__16u2_p3_0[] = {
  129744. 2, 4, 4, 6, 6, 7, 7, 9, 9, 4, 5, 5, 6, 6, 8, 7,
  129745. 9, 9, 4, 5, 5, 6, 6, 7, 8, 9, 9, 6, 6, 6, 7, 7,
  129746. 8, 8,10,10, 6, 6, 6, 7, 7, 8, 8, 9,10, 7, 8, 7,
  129747. 8, 8, 9, 9,10,10, 7, 8, 8, 8, 8, 9, 9,10,10, 9,
  129748. 9, 9,10, 9,10,10,11,11, 9, 9, 9,10,10,10,10,11,
  129749. 11,
  129750. };
  129751. static float _vq_quantthresh__16u2_p3_0[] = {
  129752. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  129753. };
  129754. static long _vq_quantmap__16u2_p3_0[] = {
  129755. 7, 5, 3, 1, 0, 2, 4, 6,
  129756. 8,
  129757. };
  129758. static encode_aux_threshmatch _vq_auxt__16u2_p3_0 = {
  129759. _vq_quantthresh__16u2_p3_0,
  129760. _vq_quantmap__16u2_p3_0,
  129761. 9,
  129762. 9
  129763. };
  129764. static static_codebook _16u2_p3_0 = {
  129765. 2, 81,
  129766. _vq_lengthlist__16u2_p3_0,
  129767. 1, -531628032, 1611661312, 4, 0,
  129768. _vq_quantlist__16u2_p3_0,
  129769. NULL,
  129770. &_vq_auxt__16u2_p3_0,
  129771. NULL,
  129772. 0
  129773. };
  129774. static long _vq_quantlist__16u2_p4_0[] = {
  129775. 8,
  129776. 7,
  129777. 9,
  129778. 6,
  129779. 10,
  129780. 5,
  129781. 11,
  129782. 4,
  129783. 12,
  129784. 3,
  129785. 13,
  129786. 2,
  129787. 14,
  129788. 1,
  129789. 15,
  129790. 0,
  129791. 16,
  129792. };
  129793. static long _vq_lengthlist__16u2_p4_0[] = {
  129794. 2, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,11,
  129795. 11, 5, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  129796. 12,11, 5, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  129797. 11,12,12, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  129798. 11,11,12,12, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,
  129799. 10,11,11,12,12, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,
  129800. 11,11,12,12,12,12, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,
  129801. 10,11,11,11,12,12,12, 9, 9, 9, 9, 9, 9,10,10,10,
  129802. 10,10,11,11,12,12,13,13, 8, 9, 9, 9, 9,10, 9,10,
  129803. 10,10,10,11,11,12,12,13,13, 9, 9, 9, 9, 9,10,10,
  129804. 10,10,11,11,11,12,12,12,13,13, 9, 9, 9, 9, 9,10,
  129805. 10,10,10,11,11,12,11,12,12,13,13,10,10,10,10,10,
  129806. 11,11,11,11,11,12,12,12,12,13,13,14,10,10,10,10,
  129807. 10,11,11,11,11,12,11,12,12,13,12,13,13,11,11,11,
  129808. 11,11,12,12,12,12,12,12,13,13,13,13,14,14,11,11,
  129809. 11,11,11,12,12,12,12,12,12,13,12,13,13,14,14,11,
  129810. 12,12,12,12,12,12,13,13,13,13,13,13,14,14,14,14,
  129811. 11,12,12,12,12,12,12,13,13,13,13,14,13,14,14,14,
  129812. 14,
  129813. };
  129814. static float _vq_quantthresh__16u2_p4_0[] = {
  129815. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  129816. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  129817. };
  129818. static long _vq_quantmap__16u2_p4_0[] = {
  129819. 15, 13, 11, 9, 7, 5, 3, 1,
  129820. 0, 2, 4, 6, 8, 10, 12, 14,
  129821. 16,
  129822. };
  129823. static encode_aux_threshmatch _vq_auxt__16u2_p4_0 = {
  129824. _vq_quantthresh__16u2_p4_0,
  129825. _vq_quantmap__16u2_p4_0,
  129826. 17,
  129827. 17
  129828. };
  129829. static static_codebook _16u2_p4_0 = {
  129830. 2, 289,
  129831. _vq_lengthlist__16u2_p4_0,
  129832. 1, -529530880, 1611661312, 5, 0,
  129833. _vq_quantlist__16u2_p4_0,
  129834. NULL,
  129835. &_vq_auxt__16u2_p4_0,
  129836. NULL,
  129837. 0
  129838. };
  129839. static long _vq_quantlist__16u2_p5_0[] = {
  129840. 1,
  129841. 0,
  129842. 2,
  129843. };
  129844. static long _vq_lengthlist__16u2_p5_0[] = {
  129845. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 8, 7,10, 9, 7,
  129846. 10, 9, 5, 8, 9, 7, 9,10, 7, 9,10, 4, 9, 9, 9,11,
  129847. 11, 8,11,11, 7,11,11,10,10,13,10,14,13, 7,11,11,
  129848. 10,13,11,10,13,14, 5, 9, 9, 8,11,11, 9,11,11, 7,
  129849. 11,11,10,14,13,10,12,14, 7,11,11,10,13,13,10,13,
  129850. 10,
  129851. };
  129852. static float _vq_quantthresh__16u2_p5_0[] = {
  129853. -5.5, 5.5,
  129854. };
  129855. static long _vq_quantmap__16u2_p5_0[] = {
  129856. 1, 0, 2,
  129857. };
  129858. static encode_aux_threshmatch _vq_auxt__16u2_p5_0 = {
  129859. _vq_quantthresh__16u2_p5_0,
  129860. _vq_quantmap__16u2_p5_0,
  129861. 3,
  129862. 3
  129863. };
  129864. static static_codebook _16u2_p5_0 = {
  129865. 4, 81,
  129866. _vq_lengthlist__16u2_p5_0,
  129867. 1, -529137664, 1618345984, 2, 0,
  129868. _vq_quantlist__16u2_p5_0,
  129869. NULL,
  129870. &_vq_auxt__16u2_p5_0,
  129871. NULL,
  129872. 0
  129873. };
  129874. static long _vq_quantlist__16u2_p5_1[] = {
  129875. 5,
  129876. 4,
  129877. 6,
  129878. 3,
  129879. 7,
  129880. 2,
  129881. 8,
  129882. 1,
  129883. 9,
  129884. 0,
  129885. 10,
  129886. };
  129887. static long _vq_lengthlist__16u2_p5_1[] = {
  129888. 2, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 5, 5, 5, 7, 7,
  129889. 7, 7, 8, 8, 8, 8, 5, 5, 6, 7, 7, 7, 7, 8, 8, 8,
  129890. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7,
  129891. 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 9, 9,
  129892. 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8,
  129893. 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9,
  129894. 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8,
  129895. 8, 8, 8, 9, 9, 9, 9, 9, 9,
  129896. };
  129897. static float _vq_quantthresh__16u2_p5_1[] = {
  129898. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  129899. 3.5, 4.5,
  129900. };
  129901. static long _vq_quantmap__16u2_p5_1[] = {
  129902. 9, 7, 5, 3, 1, 0, 2, 4,
  129903. 6, 8, 10,
  129904. };
  129905. static encode_aux_threshmatch _vq_auxt__16u2_p5_1 = {
  129906. _vq_quantthresh__16u2_p5_1,
  129907. _vq_quantmap__16u2_p5_1,
  129908. 11,
  129909. 11
  129910. };
  129911. static static_codebook _16u2_p5_1 = {
  129912. 2, 121,
  129913. _vq_lengthlist__16u2_p5_1,
  129914. 1, -531365888, 1611661312, 4, 0,
  129915. _vq_quantlist__16u2_p5_1,
  129916. NULL,
  129917. &_vq_auxt__16u2_p5_1,
  129918. NULL,
  129919. 0
  129920. };
  129921. static long _vq_quantlist__16u2_p6_0[] = {
  129922. 6,
  129923. 5,
  129924. 7,
  129925. 4,
  129926. 8,
  129927. 3,
  129928. 9,
  129929. 2,
  129930. 10,
  129931. 1,
  129932. 11,
  129933. 0,
  129934. 12,
  129935. };
  129936. static long _vq_lengthlist__16u2_p6_0[] = {
  129937. 1, 4, 4, 7, 7, 8, 8, 8, 8, 9, 9,10,10, 4, 6, 6,
  129938. 8, 8, 9, 9, 9, 9,10,10,12,11, 4, 6, 6, 8, 8, 9,
  129939. 9, 9, 9,10,10,11,12, 7, 8, 8, 9, 9,10,10,10,10,
  129940. 12,12,13,12, 7, 8, 8, 9, 9,10,10,10,10,11,12,12,
  129941. 12, 8, 9, 9,10,10,11,11,11,11,12,12,13,13, 8, 9,
  129942. 9,10,10,11,11,11,11,12,13,13,13, 8, 9, 9,10,10,
  129943. 11,11,12,12,13,13,14,14, 8, 9, 9,10,10,11,11,12,
  129944. 12,13,13,14,14, 9,10,10,11,12,13,12,13,14,14,14,
  129945. 14,14, 9,10,10,11,12,12,13,13,13,14,14,14,14,10,
  129946. 11,11,12,12,13,13,14,14,15,15,15,15,10,11,11,12,
  129947. 12,13,13,14,14,14,14,15,15,
  129948. };
  129949. static float _vq_quantthresh__16u2_p6_0[] = {
  129950. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  129951. 12.5, 17.5, 22.5, 27.5,
  129952. };
  129953. static long _vq_quantmap__16u2_p6_0[] = {
  129954. 11, 9, 7, 5, 3, 1, 0, 2,
  129955. 4, 6, 8, 10, 12,
  129956. };
  129957. static encode_aux_threshmatch _vq_auxt__16u2_p6_0 = {
  129958. _vq_quantthresh__16u2_p6_0,
  129959. _vq_quantmap__16u2_p6_0,
  129960. 13,
  129961. 13
  129962. };
  129963. static static_codebook _16u2_p6_0 = {
  129964. 2, 169,
  129965. _vq_lengthlist__16u2_p6_0,
  129966. 1, -526516224, 1616117760, 4, 0,
  129967. _vq_quantlist__16u2_p6_0,
  129968. NULL,
  129969. &_vq_auxt__16u2_p6_0,
  129970. NULL,
  129971. 0
  129972. };
  129973. static long _vq_quantlist__16u2_p6_1[] = {
  129974. 2,
  129975. 1,
  129976. 3,
  129977. 0,
  129978. 4,
  129979. };
  129980. static long _vq_lengthlist__16u2_p6_1[] = {
  129981. 2, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  129982. 5, 5, 6, 6, 5, 5, 5, 6, 6,
  129983. };
  129984. static float _vq_quantthresh__16u2_p6_1[] = {
  129985. -1.5, -0.5, 0.5, 1.5,
  129986. };
  129987. static long _vq_quantmap__16u2_p6_1[] = {
  129988. 3, 1, 0, 2, 4,
  129989. };
  129990. static encode_aux_threshmatch _vq_auxt__16u2_p6_1 = {
  129991. _vq_quantthresh__16u2_p6_1,
  129992. _vq_quantmap__16u2_p6_1,
  129993. 5,
  129994. 5
  129995. };
  129996. static static_codebook _16u2_p6_1 = {
  129997. 2, 25,
  129998. _vq_lengthlist__16u2_p6_1,
  129999. 1, -533725184, 1611661312, 3, 0,
  130000. _vq_quantlist__16u2_p6_1,
  130001. NULL,
  130002. &_vq_auxt__16u2_p6_1,
  130003. NULL,
  130004. 0
  130005. };
  130006. static long _vq_quantlist__16u2_p7_0[] = {
  130007. 6,
  130008. 5,
  130009. 7,
  130010. 4,
  130011. 8,
  130012. 3,
  130013. 9,
  130014. 2,
  130015. 10,
  130016. 1,
  130017. 11,
  130018. 0,
  130019. 12,
  130020. };
  130021. static long _vq_lengthlist__16u2_p7_0[] = {
  130022. 1, 4, 4, 7, 7, 7, 7, 8, 8, 9, 9,10,10, 4, 6, 6,
  130023. 9, 9, 9, 9, 9, 9,10,10,11,11, 4, 6, 6, 8, 9, 9,
  130024. 9, 9, 9,10,11,12,11, 7, 8, 9,10,10,10,10,11,10,
  130025. 11,12,12,13, 7, 9, 9,10,10,10,10,10,10,11,12,13,
  130026. 13, 7, 9, 8,10,10,11,11,11,12,12,13,13,14, 7, 9,
  130027. 9,10,10,11,11,11,12,13,13,13,13, 8, 9, 9,10,11,
  130028. 11,12,12,12,13,13,13,13, 8, 9, 9,10,11,11,11,12,
  130029. 12,13,13,14,14, 9,10,10,12,11,12,13,13,13,14,13,
  130030. 13,13, 9,10,10,11,11,12,12,13,14,13,13,14,13,10,
  130031. 11,11,12,13,14,14,14,15,14,14,14,14,10,11,11,12,
  130032. 12,13,13,13,14,14,14,15,14,
  130033. };
  130034. static float _vq_quantthresh__16u2_p7_0[] = {
  130035. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  130036. 27.5, 38.5, 49.5, 60.5,
  130037. };
  130038. static long _vq_quantmap__16u2_p7_0[] = {
  130039. 11, 9, 7, 5, 3, 1, 0, 2,
  130040. 4, 6, 8, 10, 12,
  130041. };
  130042. static encode_aux_threshmatch _vq_auxt__16u2_p7_0 = {
  130043. _vq_quantthresh__16u2_p7_0,
  130044. _vq_quantmap__16u2_p7_0,
  130045. 13,
  130046. 13
  130047. };
  130048. static static_codebook _16u2_p7_0 = {
  130049. 2, 169,
  130050. _vq_lengthlist__16u2_p7_0,
  130051. 1, -523206656, 1618345984, 4, 0,
  130052. _vq_quantlist__16u2_p7_0,
  130053. NULL,
  130054. &_vq_auxt__16u2_p7_0,
  130055. NULL,
  130056. 0
  130057. };
  130058. static long _vq_quantlist__16u2_p7_1[] = {
  130059. 5,
  130060. 4,
  130061. 6,
  130062. 3,
  130063. 7,
  130064. 2,
  130065. 8,
  130066. 1,
  130067. 9,
  130068. 0,
  130069. 10,
  130070. };
  130071. static long _vq_lengthlist__16u2_p7_1[] = {
  130072. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7,
  130073. 7, 7, 7, 7, 8, 8, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8,
  130074. 8, 6, 6, 7, 7, 7, 8, 7, 8, 8, 8, 8, 6, 7, 7, 7,
  130075. 7, 7, 7, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8, 8,
  130076. 8, 8, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7,
  130077. 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8,
  130078. 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8,
  130079. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  130080. };
  130081. static float _vq_quantthresh__16u2_p7_1[] = {
  130082. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  130083. 3.5, 4.5,
  130084. };
  130085. static long _vq_quantmap__16u2_p7_1[] = {
  130086. 9, 7, 5, 3, 1, 0, 2, 4,
  130087. 6, 8, 10,
  130088. };
  130089. static encode_aux_threshmatch _vq_auxt__16u2_p7_1 = {
  130090. _vq_quantthresh__16u2_p7_1,
  130091. _vq_quantmap__16u2_p7_1,
  130092. 11,
  130093. 11
  130094. };
  130095. static static_codebook _16u2_p7_1 = {
  130096. 2, 121,
  130097. _vq_lengthlist__16u2_p7_1,
  130098. 1, -531365888, 1611661312, 4, 0,
  130099. _vq_quantlist__16u2_p7_1,
  130100. NULL,
  130101. &_vq_auxt__16u2_p7_1,
  130102. NULL,
  130103. 0
  130104. };
  130105. static long _vq_quantlist__16u2_p8_0[] = {
  130106. 7,
  130107. 6,
  130108. 8,
  130109. 5,
  130110. 9,
  130111. 4,
  130112. 10,
  130113. 3,
  130114. 11,
  130115. 2,
  130116. 12,
  130117. 1,
  130118. 13,
  130119. 0,
  130120. 14,
  130121. };
  130122. static long _vq_lengthlist__16u2_p8_0[] = {
  130123. 1, 5, 5, 7, 7, 8, 8, 7, 7, 8, 8,10, 9,11,11, 4,
  130124. 6, 6, 8, 8,10, 9, 9, 8, 9, 9,10,10,12,14, 4, 6,
  130125. 7, 8, 9, 9,10, 9, 8, 9, 9,10,12,12,11, 7, 8, 8,
  130126. 10,10,10,10, 9, 9,10,10,11,13,13,12, 7, 8, 8, 9,
  130127. 11,11,10, 9, 9,11,10,12,11,11,14, 8, 9, 9,11,10,
  130128. 11,11,10,10,11,11,13,12,14,12, 8, 9, 9,11,12,11,
  130129. 11,10,10,12,11,12,12,12,14, 7, 8, 8, 9, 9,10,10,
  130130. 10,11,12,11,13,13,14,12, 7, 8, 9, 9, 9,10,10,11,
  130131. 11,11,12,12,14,14,14, 8,10, 9,10,11,11,11,11,14,
  130132. 12,12,13,14,14,13, 9, 9, 9,10,11,11,11,12,12,12,
  130133. 14,12,14,13,14,10,10,10,12,11,12,11,14,13,14,13,
  130134. 14,14,13,14, 9,10,10,11,12,11,13,12,13,13,14,14,
  130135. 14,13,14,10,13,13,12,12,11,12,14,13,14,13,14,12,
  130136. 14,13,10,11,11,12,11,12,12,14,14,14,13,14,14,14,
  130137. 14,
  130138. };
  130139. static float _vq_quantthresh__16u2_p8_0[] = {
  130140. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  130141. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  130142. };
  130143. static long _vq_quantmap__16u2_p8_0[] = {
  130144. 13, 11, 9, 7, 5, 3, 1, 0,
  130145. 2, 4, 6, 8, 10, 12, 14,
  130146. };
  130147. static encode_aux_threshmatch _vq_auxt__16u2_p8_0 = {
  130148. _vq_quantthresh__16u2_p8_0,
  130149. _vq_quantmap__16u2_p8_0,
  130150. 15,
  130151. 15
  130152. };
  130153. static static_codebook _16u2_p8_0 = {
  130154. 2, 225,
  130155. _vq_lengthlist__16u2_p8_0,
  130156. 1, -520986624, 1620377600, 4, 0,
  130157. _vq_quantlist__16u2_p8_0,
  130158. NULL,
  130159. &_vq_auxt__16u2_p8_0,
  130160. NULL,
  130161. 0
  130162. };
  130163. static long _vq_quantlist__16u2_p8_1[] = {
  130164. 10,
  130165. 9,
  130166. 11,
  130167. 8,
  130168. 12,
  130169. 7,
  130170. 13,
  130171. 6,
  130172. 14,
  130173. 5,
  130174. 15,
  130175. 4,
  130176. 16,
  130177. 3,
  130178. 17,
  130179. 2,
  130180. 18,
  130181. 1,
  130182. 19,
  130183. 0,
  130184. 20,
  130185. };
  130186. static long _vq_lengthlist__16u2_p8_1[] = {
  130187. 2, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10, 9,10, 9, 9,
  130188. 9,10,10,10,10, 5, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,
  130189. 10, 9,10,10,10,10,10,10,11,10, 5, 6, 6, 7, 7, 8,
  130190. 8, 8, 9, 9,10,10,10,10,10,10,10,10,10,10,10, 7,
  130191. 7, 7, 8, 8, 9, 8, 9, 9,10, 9,10,10,10,10,10,10,
  130192. 11,10,11,10, 7, 7, 7, 8, 8, 8, 9, 9, 9,10, 9,10,
  130193. 10,10,10,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9,
  130194. 10, 9,10,10,10,10,10,10,10,11,10,10,11,10, 8, 8,
  130195. 8, 8, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,11,
  130196. 11,10,10, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,
  130197. 11,10,11,10,11,10,11,10, 8, 9, 9, 9, 9, 9,10,10,
  130198. 10,10,10,10,10,10,10,10,11,11,10,10,10, 9,10, 9,
  130199. 9,10,10,10,11,10,10,10,10,10,10,10,10,11,11,11,
  130200. 11,11, 9, 9, 9,10, 9,10,10,10,10,10,10,11,10,11,
  130201. 10,11,11,11,11,10,10, 9,10, 9,10,10,10,10,11,10,
  130202. 10,10,10,10,11,10,11,10,11,10,10,11, 9,10,10,10,
  130203. 10,10,10,10,10,10,11,10,10,11,11,10,11,11,11,11,
  130204. 11, 9, 9,10,10,10,10,10,11,10,10,11,10,10,11,10,
  130205. 10,11,11,11,11,11, 9,10,10,10,10,10,10,10,11,10,
  130206. 11,10,11,10,11,11,11,11,11,10,11,10,10,10,10,10,
  130207. 10,10,10,10,11,11,11,11,11,11,11,11,11,10,11,11,
  130208. 10,10,10,10,10,11,10,10,10,11,10,11,11,11,11,10,
  130209. 12,11,11,11,10,10,10,10,10,10,11,10,10,10,11,11,
  130210. 12,11,11,11,11,11,11,11,11,11,10,10,10,11,10,11,
  130211. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
  130212. 10,10,11,10,11,10,10,11,11,11,11,11,11,11,11,11,
  130213. 11,11,11,10,10,10,10,10,10,10,11,11,10,11,11,10,
  130214. 11,11,10,11,11,11,10,11,11,
  130215. };
  130216. static float _vq_quantthresh__16u2_p8_1[] = {
  130217. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  130218. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  130219. 6.5, 7.5, 8.5, 9.5,
  130220. };
  130221. static long _vq_quantmap__16u2_p8_1[] = {
  130222. 19, 17, 15, 13, 11, 9, 7, 5,
  130223. 3, 1, 0, 2, 4, 6, 8, 10,
  130224. 12, 14, 16, 18, 20,
  130225. };
  130226. static encode_aux_threshmatch _vq_auxt__16u2_p8_1 = {
  130227. _vq_quantthresh__16u2_p8_1,
  130228. _vq_quantmap__16u2_p8_1,
  130229. 21,
  130230. 21
  130231. };
  130232. static static_codebook _16u2_p8_1 = {
  130233. 2, 441,
  130234. _vq_lengthlist__16u2_p8_1,
  130235. 1, -529268736, 1611661312, 5, 0,
  130236. _vq_quantlist__16u2_p8_1,
  130237. NULL,
  130238. &_vq_auxt__16u2_p8_1,
  130239. NULL,
  130240. 0
  130241. };
  130242. static long _vq_quantlist__16u2_p9_0[] = {
  130243. 5586,
  130244. 4655,
  130245. 6517,
  130246. 3724,
  130247. 7448,
  130248. 2793,
  130249. 8379,
  130250. 1862,
  130251. 9310,
  130252. 931,
  130253. 10241,
  130254. 0,
  130255. 11172,
  130256. 5521,
  130257. 5651,
  130258. };
  130259. static long _vq_lengthlist__16u2_p9_0[] = {
  130260. 1,10,10,10,10,10,10,10,10,10,10,10,10, 5, 4,10,
  130261. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130262. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130263. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130264. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130265. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130266. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130267. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130268. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130269. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130270. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130271. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130272. 10,10,10, 4,10,10,10,10,10,10,10,10,10,10,10,10,
  130273. 6, 6, 5,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 5,
  130274. 5,
  130275. };
  130276. static float _vq_quantthresh__16u2_p9_0[] = {
  130277. -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -498, -32.5, 32.5,
  130278. 498, 1396.5, 2327.5, 3258.5, 4189.5, 5120.5,
  130279. };
  130280. static long _vq_quantmap__16u2_p9_0[] = {
  130281. 11, 9, 7, 5, 3, 1, 13, 0,
  130282. 14, 2, 4, 6, 8, 10, 12,
  130283. };
  130284. static encode_aux_threshmatch _vq_auxt__16u2_p9_0 = {
  130285. _vq_quantthresh__16u2_p9_0,
  130286. _vq_quantmap__16u2_p9_0,
  130287. 15,
  130288. 15
  130289. };
  130290. static static_codebook _16u2_p9_0 = {
  130291. 2, 225,
  130292. _vq_lengthlist__16u2_p9_0,
  130293. 1, -510275072, 1611661312, 14, 0,
  130294. _vq_quantlist__16u2_p9_0,
  130295. NULL,
  130296. &_vq_auxt__16u2_p9_0,
  130297. NULL,
  130298. 0
  130299. };
  130300. static long _vq_quantlist__16u2_p9_1[] = {
  130301. 392,
  130302. 343,
  130303. 441,
  130304. 294,
  130305. 490,
  130306. 245,
  130307. 539,
  130308. 196,
  130309. 588,
  130310. 147,
  130311. 637,
  130312. 98,
  130313. 686,
  130314. 49,
  130315. 735,
  130316. 0,
  130317. 784,
  130318. 388,
  130319. 396,
  130320. };
  130321. static long _vq_lengthlist__16u2_p9_1[] = {
  130322. 1,12,10,12,10,12,10,12,11,12,12,12,12,12,12,12,
  130323. 12, 5, 5, 9,10,12,11,11,12,12,12,12,12,12,12,12,
  130324. 12,12,12,12,10, 9, 9,11, 9,11,11,12,11,12,12,12,
  130325. 12,12,12,12,12,12,12, 8, 8,10,11, 9,12,11,12,12,
  130326. 12,12,12,12,12,12,12,12,12,12, 9, 8,10,11,12,11,
  130327. 12,11,12,12,12,12,12,12,12,12,12,12,12, 8, 9,11,
  130328. 11,10,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130329. 9,10,11,12,11,12,11,12,12,12,12,12,12,12,12,12,
  130330. 12,12,12, 9, 9,11,12,12,12,12,12,12,12,12,12,12,
  130331. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130332. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130333. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130334. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130335. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130336. 12,12,12,12,11,11,11,11,11,11,11,11,11,11,11,11,
  130337. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130338. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130339. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130340. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130341. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130342. 11,11,11, 5, 8, 9, 9, 8,11, 9,11,11,11,11,11,11,
  130343. 11,11,11,11, 5, 5, 4, 8, 8, 8, 8,10, 9,10,10,11,
  130344. 11,11,11,11,11,11,11, 5, 4,
  130345. };
  130346. static float _vq_quantthresh__16u2_p9_1[] = {
  130347. -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5, -26.5,
  130348. -2, 2, 26.5, 73.5, 122.5, 171.5, 220.5, 269.5,
  130349. 318.5, 367.5,
  130350. };
  130351. static long _vq_quantmap__16u2_p9_1[] = {
  130352. 15, 13, 11, 9, 7, 5, 3, 1,
  130353. 17, 0, 18, 2, 4, 6, 8, 10,
  130354. 12, 14, 16,
  130355. };
  130356. static encode_aux_threshmatch _vq_auxt__16u2_p9_1 = {
  130357. _vq_quantthresh__16u2_p9_1,
  130358. _vq_quantmap__16u2_p9_1,
  130359. 19,
  130360. 19
  130361. };
  130362. static static_codebook _16u2_p9_1 = {
  130363. 2, 361,
  130364. _vq_lengthlist__16u2_p9_1,
  130365. 1, -518488064, 1611661312, 10, 0,
  130366. _vq_quantlist__16u2_p9_1,
  130367. NULL,
  130368. &_vq_auxt__16u2_p9_1,
  130369. NULL,
  130370. 0
  130371. };
  130372. static long _vq_quantlist__16u2_p9_2[] = {
  130373. 24,
  130374. 23,
  130375. 25,
  130376. 22,
  130377. 26,
  130378. 21,
  130379. 27,
  130380. 20,
  130381. 28,
  130382. 19,
  130383. 29,
  130384. 18,
  130385. 30,
  130386. 17,
  130387. 31,
  130388. 16,
  130389. 32,
  130390. 15,
  130391. 33,
  130392. 14,
  130393. 34,
  130394. 13,
  130395. 35,
  130396. 12,
  130397. 36,
  130398. 11,
  130399. 37,
  130400. 10,
  130401. 38,
  130402. 9,
  130403. 39,
  130404. 8,
  130405. 40,
  130406. 7,
  130407. 41,
  130408. 6,
  130409. 42,
  130410. 5,
  130411. 43,
  130412. 4,
  130413. 44,
  130414. 3,
  130415. 45,
  130416. 2,
  130417. 46,
  130418. 1,
  130419. 47,
  130420. 0,
  130421. 48,
  130422. };
  130423. static long _vq_lengthlist__16u2_p9_2[] = {
  130424. 1, 3, 3, 4, 7, 7, 7, 8, 7, 7, 7, 7, 8, 8, 8, 8,
  130425. 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 9, 9, 8, 9, 9,
  130426. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,12,12,10,
  130427. 11,
  130428. };
  130429. static float _vq_quantthresh__16u2_p9_2[] = {
  130430. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  130431. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  130432. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  130433. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  130434. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  130435. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  130436. };
  130437. static long _vq_quantmap__16u2_p9_2[] = {
  130438. 47, 45, 43, 41, 39, 37, 35, 33,
  130439. 31, 29, 27, 25, 23, 21, 19, 17,
  130440. 15, 13, 11, 9, 7, 5, 3, 1,
  130441. 0, 2, 4, 6, 8, 10, 12, 14,
  130442. 16, 18, 20, 22, 24, 26, 28, 30,
  130443. 32, 34, 36, 38, 40, 42, 44, 46,
  130444. 48,
  130445. };
  130446. static encode_aux_threshmatch _vq_auxt__16u2_p9_2 = {
  130447. _vq_quantthresh__16u2_p9_2,
  130448. _vq_quantmap__16u2_p9_2,
  130449. 49,
  130450. 49
  130451. };
  130452. static static_codebook _16u2_p9_2 = {
  130453. 1, 49,
  130454. _vq_lengthlist__16u2_p9_2,
  130455. 1, -526909440, 1611661312, 6, 0,
  130456. _vq_quantlist__16u2_p9_2,
  130457. NULL,
  130458. &_vq_auxt__16u2_p9_2,
  130459. NULL,
  130460. 0
  130461. };
  130462. static long _vq_quantlist__8u0__p1_0[] = {
  130463. 1,
  130464. 0,
  130465. 2,
  130466. };
  130467. static long _vq_lengthlist__8u0__p1_0[] = {
  130468. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  130469. 10,10, 5, 8, 8, 7,10,10, 8,10,10, 4, 9, 8, 8,11,
  130470. 11, 8,11,11, 7,11,11,10,11,13,10,13,13, 7,11,11,
  130471. 10,13,12,10,13,13, 5, 9, 8, 8,11,11, 8,11,11, 7,
  130472. 11,11, 9,13,13,10,12,13, 7,11,11,10,13,13,10,13,
  130473. 11,
  130474. };
  130475. static float _vq_quantthresh__8u0__p1_0[] = {
  130476. -0.5, 0.5,
  130477. };
  130478. static long _vq_quantmap__8u0__p1_0[] = {
  130479. 1, 0, 2,
  130480. };
  130481. static encode_aux_threshmatch _vq_auxt__8u0__p1_0 = {
  130482. _vq_quantthresh__8u0__p1_0,
  130483. _vq_quantmap__8u0__p1_0,
  130484. 3,
  130485. 3
  130486. };
  130487. static static_codebook _8u0__p1_0 = {
  130488. 4, 81,
  130489. _vq_lengthlist__8u0__p1_0,
  130490. 1, -535822336, 1611661312, 2, 0,
  130491. _vq_quantlist__8u0__p1_0,
  130492. NULL,
  130493. &_vq_auxt__8u0__p1_0,
  130494. NULL,
  130495. 0
  130496. };
  130497. static long _vq_quantlist__8u0__p2_0[] = {
  130498. 1,
  130499. 0,
  130500. 2,
  130501. };
  130502. static long _vq_lengthlist__8u0__p2_0[] = {
  130503. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 6, 7, 8, 6,
  130504. 7, 8, 5, 7, 7, 6, 8, 8, 7, 9, 7, 5, 7, 7, 7, 9,
  130505. 9, 7, 8, 8, 6, 9, 8, 7, 7,10, 8,10,10, 6, 8, 8,
  130506. 8,10, 8, 8,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 9, 6,
  130507. 8, 8, 8,10,10, 8, 8,10, 6, 8, 9, 8,10,10, 7,10,
  130508. 8,
  130509. };
  130510. static float _vq_quantthresh__8u0__p2_0[] = {
  130511. -0.5, 0.5,
  130512. };
  130513. static long _vq_quantmap__8u0__p2_0[] = {
  130514. 1, 0, 2,
  130515. };
  130516. static encode_aux_threshmatch _vq_auxt__8u0__p2_0 = {
  130517. _vq_quantthresh__8u0__p2_0,
  130518. _vq_quantmap__8u0__p2_0,
  130519. 3,
  130520. 3
  130521. };
  130522. static static_codebook _8u0__p2_0 = {
  130523. 4, 81,
  130524. _vq_lengthlist__8u0__p2_0,
  130525. 1, -535822336, 1611661312, 2, 0,
  130526. _vq_quantlist__8u0__p2_0,
  130527. NULL,
  130528. &_vq_auxt__8u0__p2_0,
  130529. NULL,
  130530. 0
  130531. };
  130532. static long _vq_quantlist__8u0__p3_0[] = {
  130533. 2,
  130534. 1,
  130535. 3,
  130536. 0,
  130537. 4,
  130538. };
  130539. static long _vq_lengthlist__8u0__p3_0[] = {
  130540. 1, 5, 5, 7, 7, 6, 7, 7, 9, 9, 6, 7, 7, 9, 9, 8,
  130541. 10, 9,11,11, 8, 9, 9,11,11, 6, 8, 8,10,10, 8,10,
  130542. 10,11,11, 8,10,10,11,11,10,11,11,12,12,10,11,11,
  130543. 12,13, 6, 8, 8,10,10, 8,10,10,11,11, 8,10,10,11,
  130544. 11, 9,10,11,12,12,10,11,11,12,12, 8,11,11,14,13,
  130545. 10,12,11,15,13,10,12,11,14,14,12,13,12,16,14,12,
  130546. 14,12,16,15, 8,11,11,13,14,10,11,12,13,15,10,11,
  130547. 12,13,15,11,12,13,14,15,12,12,14,14,16, 5, 8, 8,
  130548. 11,11, 9,11,11,12,12, 8,10,11,12,12,11,12,12,15,
  130549. 14,11,12,12,14,14, 7,11,10,13,12,10,11,12,13,14,
  130550. 10,12,12,14,13,12,13,13,14,15,12,13,13,15,15, 7,
  130551. 10,11,12,13,10,12,11,14,13,10,12,13,13,15,12,13,
  130552. 12,14,14,11,13,13,15,16, 9,12,12,15,14,11,13,13,
  130553. 15,16,11,13,13,16,16,13,14,15,15,15,12,14,15,17,
  130554. 16, 9,12,12,14,15,11,13,13,15,16,11,13,13,16,18,
  130555. 13,14,14,17,16,13,15,15,17,18, 5, 8, 9,11,11, 8,
  130556. 11,11,12,12, 8,10,11,12,12,11,12,12,14,14,11,12,
  130557. 12,14,15, 7,11,10,12,13,10,12,12,14,13,10,11,12,
  130558. 13,14,11,13,13,15,14,12,13,13,14,15, 7,10,11,13,
  130559. 13,10,12,12,13,14,10,12,12,13,13,11,13,13,16,16,
  130560. 12,13,13,15,14, 9,12,12,16,15,10,13,13,15,15,11,
  130561. 13,13,17,15,12,15,15,18,17,13,14,14,15,16, 9,12,
  130562. 12,15,15,11,13,13,15,16,11,13,13,15,15,12,15,15,
  130563. 16,16,13,15,14,17,15, 7,11,11,15,15,10,13,13,16,
  130564. 15,10,13,13,15,16,14,15,15,17,19,13,15,14,15,18,
  130565. 9,12,12,16,16,11,13,14,17,16,11,13,13,17,16,15,
  130566. 15,16,17,19,13,15,16, 0,18, 9,12,12,16,15,11,14,
  130567. 13,17,17,11,13,14,16,16,15,16,16,19,18,13,15,15,
  130568. 17,19,11,14,14,19,16,12,14,15, 0,18,12,16,15,18,
  130569. 17,15,15,18,16,19,14,15,17,19,19,11,14,14,18,19,
  130570. 13,15,14,19,19,12,16,15,18,17,15,17,15, 0,16,14,
  130571. 17,16,19, 0, 7,11,11,14,14,10,12,12,15,15,10,13,
  130572. 13,16,15,13,15,15,17, 0,14,15,15,16,19, 9,12,12,
  130573. 16,16,11,14,14,16,16,11,13,13,16,16,14,17,16,19,
  130574. 0,14,18,17,17,19, 9,12,12,15,16,11,13,13,15,17,
  130575. 12,14,13,19,16,13,15,15,17,19,15,17,16,17,19,11,
  130576. 14,14,19,16,12,15,15,19,17,13,14,15,17,19,14,16,
  130577. 17,19,19,16,15,16,17,19,11,15,14,16,16,12,15,15,
  130578. 19, 0,12,14,15,19,19,14,16,16, 0,18,15,19,14,18,
  130579. 16,
  130580. };
  130581. static float _vq_quantthresh__8u0__p3_0[] = {
  130582. -1.5, -0.5, 0.5, 1.5,
  130583. };
  130584. static long _vq_quantmap__8u0__p3_0[] = {
  130585. 3, 1, 0, 2, 4,
  130586. };
  130587. static encode_aux_threshmatch _vq_auxt__8u0__p3_0 = {
  130588. _vq_quantthresh__8u0__p3_0,
  130589. _vq_quantmap__8u0__p3_0,
  130590. 5,
  130591. 5
  130592. };
  130593. static static_codebook _8u0__p3_0 = {
  130594. 4, 625,
  130595. _vq_lengthlist__8u0__p3_0,
  130596. 1, -533725184, 1611661312, 3, 0,
  130597. _vq_quantlist__8u0__p3_0,
  130598. NULL,
  130599. &_vq_auxt__8u0__p3_0,
  130600. NULL,
  130601. 0
  130602. };
  130603. static long _vq_quantlist__8u0__p4_0[] = {
  130604. 2,
  130605. 1,
  130606. 3,
  130607. 0,
  130608. 4,
  130609. };
  130610. static long _vq_lengthlist__8u0__p4_0[] = {
  130611. 3, 5, 5, 8, 8, 5, 6, 7, 9, 9, 6, 7, 6, 9, 9, 9,
  130612. 9, 9,10,11, 9, 9, 9,11,10, 6, 7, 7,10,10, 7, 7,
  130613. 8,10,10, 7, 8, 8,10,10,10,10,10,10,11, 9,10,10,
  130614. 11,12, 6, 7, 7,10,10, 7, 8, 8,10,10, 7, 8, 7,10,
  130615. 10, 9,10,10,12,11,10,10,10,11,10, 9,10,10,12,11,
  130616. 10,10,10,13,11, 9,10,10,12,12,11,11,12,12,13,11,
  130617. 11,11,12,13, 9,10,10,12,12,10,10,11,12,12,10,10,
  130618. 11,12,12,11,11,11,13,13,11,12,12,13,13, 5, 7, 7,
  130619. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,11,12,
  130620. 12,10,11,10,12,12, 7, 8, 8,11,11, 7, 8, 9,10,11,
  130621. 8, 9, 9,11,11,11,10,11,10,12,10,11,11,12,13, 7,
  130622. 8, 8,10,11, 8, 9, 8,12,10, 8, 9, 9,11,12,10,11,
  130623. 10,13,11,10,11,11,13,12, 9,11,10,13,12,10,10,11,
  130624. 12,12,10,11,11,13,13,12,10,13,11,14,11,12,12,15,
  130625. 13, 9,11,11,13,13,10,11,11,13,12,10,11,11,12,14,
  130626. 12,13,11,14,12,12,12,12,14,14, 5, 7, 7,10,10, 7,
  130627. 8, 8,10,10, 7, 8, 8,11,10,10,11,11,12,12,10,11,
  130628. 10,12,12, 7, 8, 8,10,11, 8, 9, 9,12,11, 8, 8, 9,
  130629. 10,11,10,11,11,12,13,11,10,11,11,13, 6, 8, 8,10,
  130630. 11, 8, 9, 9,11,11, 7, 9, 7,11,10,10,11,11,12,12,
  130631. 10,11,10,13,10, 9,11,10,13,12,10,12,11,13,13,10,
  130632. 10,11,12,13,11,12,13,15,14,11,11,13,12,13, 9,10,
  130633. 11,12,13,10,11,11,12,13,10,11,10,13,12,12,13,13,
  130634. 13,14,12,12,11,14,11, 8,10,10,12,13,10,11,11,13,
  130635. 13,10,11,10,13,13,12,13,14,15,14,12,12,12,14,13,
  130636. 9,10,10,13,12,10,10,12,13,13,10,11,11,15,12,12,
  130637. 12,13,15,14,12,13,13,15,13, 9,10,11,12,13,10,12,
  130638. 10,13,12,10,11,11,12,13,12,14,12,15,13,12,12,12,
  130639. 15,14,11,12,11,14,13,11,11,12,14,14,12,13,13,14,
  130640. 13,13,11,15,11,15,14,14,14,16,15,11,12,12,13,14,
  130641. 11,13,11,14,14,12,12,13,14,15,12,14,12,15,12,13,
  130642. 15,14,16,15, 8,10,10,12,12,10,10,10,12,13,10,11,
  130643. 11,13,13,12,12,12,13,14,13,13,13,15,15, 9,10,10,
  130644. 12,12,10,11,11,13,12,10,10,11,13,13,12,12,12,14,
  130645. 14,12,12,13,15,14, 9,10,10,13,12,10,10,12,12,13,
  130646. 10,11,10,13,13,12,13,13,14,14,12,13,12,14,13,11,
  130647. 12,12,14,13,12,13,12,14,14,10,12,12,14,14,14,14,
  130648. 14,16,14,13,12,14,12,15,10,12,12,14,15,12,13,13,
  130649. 14,16,11,12,11,15,14,13,14,14,14,15,13,14,11,14,
  130650. 12,
  130651. };
  130652. static float _vq_quantthresh__8u0__p4_0[] = {
  130653. -1.5, -0.5, 0.5, 1.5,
  130654. };
  130655. static long _vq_quantmap__8u0__p4_0[] = {
  130656. 3, 1, 0, 2, 4,
  130657. };
  130658. static encode_aux_threshmatch _vq_auxt__8u0__p4_0 = {
  130659. _vq_quantthresh__8u0__p4_0,
  130660. _vq_quantmap__8u0__p4_0,
  130661. 5,
  130662. 5
  130663. };
  130664. static static_codebook _8u0__p4_0 = {
  130665. 4, 625,
  130666. _vq_lengthlist__8u0__p4_0,
  130667. 1, -533725184, 1611661312, 3, 0,
  130668. _vq_quantlist__8u0__p4_0,
  130669. NULL,
  130670. &_vq_auxt__8u0__p4_0,
  130671. NULL,
  130672. 0
  130673. };
  130674. static long _vq_quantlist__8u0__p5_0[] = {
  130675. 4,
  130676. 3,
  130677. 5,
  130678. 2,
  130679. 6,
  130680. 1,
  130681. 7,
  130682. 0,
  130683. 8,
  130684. };
  130685. static long _vq_lengthlist__8u0__p5_0[] = {
  130686. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 7, 8, 8,
  130687. 10,10, 4, 6, 6, 8, 8, 8, 8,10,10, 6, 8, 8, 9, 9,
  130688. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 7, 8, 8,
  130689. 9, 9,10,10,12,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  130690. 10,10,11,11,11,12,12,12, 9,10,10,11,11,12,12,12,
  130691. 12,
  130692. };
  130693. static float _vq_quantthresh__8u0__p5_0[] = {
  130694. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  130695. };
  130696. static long _vq_quantmap__8u0__p5_0[] = {
  130697. 7, 5, 3, 1, 0, 2, 4, 6,
  130698. 8,
  130699. };
  130700. static encode_aux_threshmatch _vq_auxt__8u0__p5_0 = {
  130701. _vq_quantthresh__8u0__p5_0,
  130702. _vq_quantmap__8u0__p5_0,
  130703. 9,
  130704. 9
  130705. };
  130706. static static_codebook _8u0__p5_0 = {
  130707. 2, 81,
  130708. _vq_lengthlist__8u0__p5_0,
  130709. 1, -531628032, 1611661312, 4, 0,
  130710. _vq_quantlist__8u0__p5_0,
  130711. NULL,
  130712. &_vq_auxt__8u0__p5_0,
  130713. NULL,
  130714. 0
  130715. };
  130716. static long _vq_quantlist__8u0__p6_0[] = {
  130717. 6,
  130718. 5,
  130719. 7,
  130720. 4,
  130721. 8,
  130722. 3,
  130723. 9,
  130724. 2,
  130725. 10,
  130726. 1,
  130727. 11,
  130728. 0,
  130729. 12,
  130730. };
  130731. static long _vq_lengthlist__8u0__p6_0[] = {
  130732. 1, 4, 4, 7, 7, 9, 9,11,11,12,12,16,16, 3, 6, 6,
  130733. 9, 9,11,11,12,12,13,14,18,16, 3, 6, 7, 9, 9,11,
  130734. 11,13,12,14,14,17,16, 7, 9, 9,11,11,12,12,14,14,
  130735. 14,14,17,16, 7, 9, 9,11,11,13,12,13,13,14,14,17,
  130736. 0, 9,11,11,12,13,14,14,14,13,15,14,17,17, 9,11,
  130737. 11,12,12,14,14,13,14,14,15, 0, 0,11,12,12,15,14,
  130738. 15,14,15,14,15,16,17, 0,11,12,13,13,13,14,14,15,
  130739. 14,15,15, 0, 0,12,14,14,15,15,14,16,15,15,17,16,
  130740. 0,18,13,14,14,15,14,15,14,15,16,17,16, 0, 0,17,
  130741. 17,18, 0,16,18,16, 0, 0, 0,17, 0, 0,16, 0, 0,16,
  130742. 16, 0,15, 0,17, 0, 0, 0, 0,
  130743. };
  130744. static float _vq_quantthresh__8u0__p6_0[] = {
  130745. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  130746. 12.5, 17.5, 22.5, 27.5,
  130747. };
  130748. static long _vq_quantmap__8u0__p6_0[] = {
  130749. 11, 9, 7, 5, 3, 1, 0, 2,
  130750. 4, 6, 8, 10, 12,
  130751. };
  130752. static encode_aux_threshmatch _vq_auxt__8u0__p6_0 = {
  130753. _vq_quantthresh__8u0__p6_0,
  130754. _vq_quantmap__8u0__p6_0,
  130755. 13,
  130756. 13
  130757. };
  130758. static static_codebook _8u0__p6_0 = {
  130759. 2, 169,
  130760. _vq_lengthlist__8u0__p6_0,
  130761. 1, -526516224, 1616117760, 4, 0,
  130762. _vq_quantlist__8u0__p6_0,
  130763. NULL,
  130764. &_vq_auxt__8u0__p6_0,
  130765. NULL,
  130766. 0
  130767. };
  130768. static long _vq_quantlist__8u0__p6_1[] = {
  130769. 2,
  130770. 1,
  130771. 3,
  130772. 0,
  130773. 4,
  130774. };
  130775. static long _vq_lengthlist__8u0__p6_1[] = {
  130776. 1, 4, 4, 6, 6, 4, 6, 5, 7, 7, 4, 5, 6, 7, 7, 6,
  130777. 7, 7, 7, 7, 6, 7, 7, 7, 7,
  130778. };
  130779. static float _vq_quantthresh__8u0__p6_1[] = {
  130780. -1.5, -0.5, 0.5, 1.5,
  130781. };
  130782. static long _vq_quantmap__8u0__p6_1[] = {
  130783. 3, 1, 0, 2, 4,
  130784. };
  130785. static encode_aux_threshmatch _vq_auxt__8u0__p6_1 = {
  130786. _vq_quantthresh__8u0__p6_1,
  130787. _vq_quantmap__8u0__p6_1,
  130788. 5,
  130789. 5
  130790. };
  130791. static static_codebook _8u0__p6_1 = {
  130792. 2, 25,
  130793. _vq_lengthlist__8u0__p6_1,
  130794. 1, -533725184, 1611661312, 3, 0,
  130795. _vq_quantlist__8u0__p6_1,
  130796. NULL,
  130797. &_vq_auxt__8u0__p6_1,
  130798. NULL,
  130799. 0
  130800. };
  130801. static long _vq_quantlist__8u0__p7_0[] = {
  130802. 1,
  130803. 0,
  130804. 2,
  130805. };
  130806. static long _vq_lengthlist__8u0__p7_0[] = {
  130807. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  130808. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  130809. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  130810. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  130811. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  130812. 7,
  130813. };
  130814. static float _vq_quantthresh__8u0__p7_0[] = {
  130815. -157.5, 157.5,
  130816. };
  130817. static long _vq_quantmap__8u0__p7_0[] = {
  130818. 1, 0, 2,
  130819. };
  130820. static encode_aux_threshmatch _vq_auxt__8u0__p7_0 = {
  130821. _vq_quantthresh__8u0__p7_0,
  130822. _vq_quantmap__8u0__p7_0,
  130823. 3,
  130824. 3
  130825. };
  130826. static static_codebook _8u0__p7_0 = {
  130827. 4, 81,
  130828. _vq_lengthlist__8u0__p7_0,
  130829. 1, -518803456, 1628680192, 2, 0,
  130830. _vq_quantlist__8u0__p7_0,
  130831. NULL,
  130832. &_vq_auxt__8u0__p7_0,
  130833. NULL,
  130834. 0
  130835. };
  130836. static long _vq_quantlist__8u0__p7_1[] = {
  130837. 7,
  130838. 6,
  130839. 8,
  130840. 5,
  130841. 9,
  130842. 4,
  130843. 10,
  130844. 3,
  130845. 11,
  130846. 2,
  130847. 12,
  130848. 1,
  130849. 13,
  130850. 0,
  130851. 14,
  130852. };
  130853. static long _vq_lengthlist__8u0__p7_1[] = {
  130854. 1, 5, 5, 5, 5,10,10,11,11,11,11,11,11,11,11, 5,
  130855. 7, 6, 8, 8, 9,10,11,11,11,11,11,11,11,11, 6, 6,
  130856. 7, 9, 7,11,10,11,11,11,11,11,11,11,11, 5, 6, 6,
  130857. 11, 8,11,11,11,11,11,11,11,11,11,11, 5, 6, 6, 9,
  130858. 10,11,10,11,11,11,11,11,11,11,11, 7,10,10,11,11,
  130859. 11,11,11,11,11,11,11,11,11,11, 7,11, 8,11,11,11,
  130860. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130861. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130862. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130863. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130864. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130865. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130866. 11,11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,
  130867. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130868. 10,
  130869. };
  130870. static float _vq_quantthresh__8u0__p7_1[] = {
  130871. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  130872. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  130873. };
  130874. static long _vq_quantmap__8u0__p7_1[] = {
  130875. 13, 11, 9, 7, 5, 3, 1, 0,
  130876. 2, 4, 6, 8, 10, 12, 14,
  130877. };
  130878. static encode_aux_threshmatch _vq_auxt__8u0__p7_1 = {
  130879. _vq_quantthresh__8u0__p7_1,
  130880. _vq_quantmap__8u0__p7_1,
  130881. 15,
  130882. 15
  130883. };
  130884. static static_codebook _8u0__p7_1 = {
  130885. 2, 225,
  130886. _vq_lengthlist__8u0__p7_1,
  130887. 1, -520986624, 1620377600, 4, 0,
  130888. _vq_quantlist__8u0__p7_1,
  130889. NULL,
  130890. &_vq_auxt__8u0__p7_1,
  130891. NULL,
  130892. 0
  130893. };
  130894. static long _vq_quantlist__8u0__p7_2[] = {
  130895. 10,
  130896. 9,
  130897. 11,
  130898. 8,
  130899. 12,
  130900. 7,
  130901. 13,
  130902. 6,
  130903. 14,
  130904. 5,
  130905. 15,
  130906. 4,
  130907. 16,
  130908. 3,
  130909. 17,
  130910. 2,
  130911. 18,
  130912. 1,
  130913. 19,
  130914. 0,
  130915. 20,
  130916. };
  130917. static long _vq_lengthlist__8u0__p7_2[] = {
  130918. 1, 6, 5, 7, 7, 9, 9, 9, 9,10,12,12,10,11,11,10,
  130919. 11,11,11,10,11, 6, 8, 8, 9, 9,10,10, 9,10,11,11,
  130920. 10,11,11,11,11,10,11,11,11,11, 6, 7, 8, 9, 9, 9,
  130921. 10,11,10,11,12,11,10,11,11,11,11,11,11,12,10, 8,
  130922. 9, 9,10, 9,10,10, 9,10,10,10,10,10, 9,10,10,10,
  130923. 10, 9,10,10, 9, 9, 9, 9,10,10, 9, 9,10,10,11,10,
  130924. 9,12,10,11,10, 9,10,10,10, 8, 9, 9,10, 9,10, 9,
  130925. 9,10,10, 9,10, 9,11,10,10,10,10,10, 9,10, 8, 8,
  130926. 9, 9,10, 9,11, 9, 8, 9, 9,10,11,10,10,10,11,12,
  130927. 9, 9,11, 8, 9, 8,11,10,11,10,10, 9,11,10,10,10,
  130928. 10,10,10,10,11,11,11,11, 8, 9, 9, 9,10,10,10,11,
  130929. 11,12,11,12,11,10,10,10,12,11,11,11,10, 8,10, 9,
  130930. 11,10,10,11,12,10,11,12,11,11,12,11,12,12,10,11,
  130931. 11,10, 9, 9,10,11,12,10,10,10,11,10,11,11,10,12,
  130932. 12,10,11,10,11,12,10, 9,10,10,11,10,11,11,11,11,
  130933. 11,12,11,11,11, 9,11,10,11,10,11,10, 9, 9,10,11,
  130934. 11,11,10,10,11,12,12,11,12,11,11,11,12,12,12,12,
  130935. 11, 9,11,11,12,10,11,11,11,11,11,11,12,11,11,12,
  130936. 11,11,11,10,11,11, 9,11,10,11,11,11,10,10,10,11,
  130937. 11,11,12,10,11,10,11,11,11,11,12, 9,11,10,11,11,
  130938. 10,10,11,11, 9,11,11,12,10,10,10,10,10,11,11,10,
  130939. 9,10,11,11,12,11,10,10,12,11,11,12,11,12,11,11,
  130940. 10,10,11,11,10,12,11,10,11,10,11,10,10,10,11,11,
  130941. 10,10,11,11,11,11,10,10,10,12,11,11,11,11,10, 9,
  130942. 10,11,11,11,12,11,11,11,12,10,11,11,11, 9,10,11,
  130943. 11,11,11,11,11,10,10,11,11,12,11,10,11,12,11,10,
  130944. 10,11, 9,10,11,11,11,11,11,10,11,11,10,12,11,11,
  130945. 11,12,11,11,11,10,10,11,11,
  130946. };
  130947. static float _vq_quantthresh__8u0__p7_2[] = {
  130948. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  130949. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  130950. 6.5, 7.5, 8.5, 9.5,
  130951. };
  130952. static long _vq_quantmap__8u0__p7_2[] = {
  130953. 19, 17, 15, 13, 11, 9, 7, 5,
  130954. 3, 1, 0, 2, 4, 6, 8, 10,
  130955. 12, 14, 16, 18, 20,
  130956. };
  130957. static encode_aux_threshmatch _vq_auxt__8u0__p7_2 = {
  130958. _vq_quantthresh__8u0__p7_2,
  130959. _vq_quantmap__8u0__p7_2,
  130960. 21,
  130961. 21
  130962. };
  130963. static static_codebook _8u0__p7_2 = {
  130964. 2, 441,
  130965. _vq_lengthlist__8u0__p7_2,
  130966. 1, -529268736, 1611661312, 5, 0,
  130967. _vq_quantlist__8u0__p7_2,
  130968. NULL,
  130969. &_vq_auxt__8u0__p7_2,
  130970. NULL,
  130971. 0
  130972. };
  130973. static long _huff_lengthlist__8u0__single[] = {
  130974. 4, 7,11, 9,12, 8, 7,10, 6, 4, 5, 5, 7, 5, 6,16,
  130975. 9, 5, 5, 6, 7, 7, 9,16, 7, 4, 6, 5, 7, 5, 7,17,
  130976. 10, 7, 7, 8, 7, 7, 8,18, 7, 5, 6, 4, 5, 4, 5,15,
  130977. 7, 6, 7, 5, 6, 4, 5,15,12,13,18,12,17,11, 9,17,
  130978. };
  130979. static static_codebook _huff_book__8u0__single = {
  130980. 2, 64,
  130981. _huff_lengthlist__8u0__single,
  130982. 0, 0, 0, 0, 0,
  130983. NULL,
  130984. NULL,
  130985. NULL,
  130986. NULL,
  130987. 0
  130988. };
  130989. static long _vq_quantlist__8u1__p1_0[] = {
  130990. 1,
  130991. 0,
  130992. 2,
  130993. };
  130994. static long _vq_lengthlist__8u1__p1_0[] = {
  130995. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 7, 9,10, 7,
  130996. 9, 9, 5, 8, 8, 7,10, 9, 7, 9, 9, 5, 8, 8, 8,10,
  130997. 10, 8,10,10, 7,10,10, 9,10,12,10,12,12, 7,10,10,
  130998. 9,12,11,10,12,12, 5, 8, 8, 8,10,10, 8,10,10, 7,
  130999. 10,10,10,12,12, 9,11,12, 7,10,10,10,12,12, 9,12,
  131000. 10,
  131001. };
  131002. static float _vq_quantthresh__8u1__p1_0[] = {
  131003. -0.5, 0.5,
  131004. };
  131005. static long _vq_quantmap__8u1__p1_0[] = {
  131006. 1, 0, 2,
  131007. };
  131008. static encode_aux_threshmatch _vq_auxt__8u1__p1_0 = {
  131009. _vq_quantthresh__8u1__p1_0,
  131010. _vq_quantmap__8u1__p1_0,
  131011. 3,
  131012. 3
  131013. };
  131014. static static_codebook _8u1__p1_0 = {
  131015. 4, 81,
  131016. _vq_lengthlist__8u1__p1_0,
  131017. 1, -535822336, 1611661312, 2, 0,
  131018. _vq_quantlist__8u1__p1_0,
  131019. NULL,
  131020. &_vq_auxt__8u1__p1_0,
  131021. NULL,
  131022. 0
  131023. };
  131024. static long _vq_quantlist__8u1__p2_0[] = {
  131025. 1,
  131026. 0,
  131027. 2,
  131028. };
  131029. static long _vq_lengthlist__8u1__p2_0[] = {
  131030. 3, 4, 5, 5, 6, 6, 5, 6, 6, 5, 7, 6, 6, 7, 8, 6,
  131031. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 7, 5, 6, 6, 7, 8,
  131032. 8, 6, 7, 7, 6, 8, 7, 7, 7, 9, 8, 9, 9, 6, 7, 8,
  131033. 7, 9, 7, 8, 9, 9, 5, 6, 6, 6, 7, 7, 7, 8, 8, 6,
  131034. 8, 7, 8, 9, 9, 7, 7, 9, 6, 7, 8, 8, 9, 9, 7, 9,
  131035. 7,
  131036. };
  131037. static float _vq_quantthresh__8u1__p2_0[] = {
  131038. -0.5, 0.5,
  131039. };
  131040. static long _vq_quantmap__8u1__p2_0[] = {
  131041. 1, 0, 2,
  131042. };
  131043. static encode_aux_threshmatch _vq_auxt__8u1__p2_0 = {
  131044. _vq_quantthresh__8u1__p2_0,
  131045. _vq_quantmap__8u1__p2_0,
  131046. 3,
  131047. 3
  131048. };
  131049. static static_codebook _8u1__p2_0 = {
  131050. 4, 81,
  131051. _vq_lengthlist__8u1__p2_0,
  131052. 1, -535822336, 1611661312, 2, 0,
  131053. _vq_quantlist__8u1__p2_0,
  131054. NULL,
  131055. &_vq_auxt__8u1__p2_0,
  131056. NULL,
  131057. 0
  131058. };
  131059. static long _vq_quantlist__8u1__p3_0[] = {
  131060. 2,
  131061. 1,
  131062. 3,
  131063. 0,
  131064. 4,
  131065. };
  131066. static long _vq_lengthlist__8u1__p3_0[] = {
  131067. 1, 5, 5, 7, 7, 6, 7, 7, 9, 9, 6, 7, 7, 9, 9, 8,
  131068. 10, 9,11,11, 9, 9, 9,11,11, 6, 8, 8,10,10, 8,10,
  131069. 10,11,11, 8, 9,10,11,11,10,11,11,12,12,10,11,11,
  131070. 12,13, 6, 8, 8,10,10, 8,10, 9,11,11, 8,10, 9,11,
  131071. 11,10,11,11,12,12,10,11,11,12,12, 9,11,11,14,13,
  131072. 10,12,11,14,14,10,12,11,14,13,12,13,13,15,14,12,
  131073. 13,13,15,14, 8,11,11,13,14,10,11,12,13,15,10,11,
  131074. 12,14,14,12,13,13,14,15,12,13,13,14,15, 5, 8, 8,
  131075. 11,11, 8,10,10,12,12, 8,10,10,12,12,11,12,12,14,
  131076. 13,11,12,12,13,14, 8,10,10,12,12, 9,11,12,13,14,
  131077. 10,12,12,13,13,12,12,13,14,14,11,13,13,15,15, 7,
  131078. 10,10,12,12, 9,12,11,14,12,10,11,12,13,14,12,13,
  131079. 12,14,14,12,13,13,15,16,10,12,12,15,14,11,12,13,
  131080. 15,15,11,13,13,15,16,14,14,15,15,16,13,14,15,17,
  131081. 15, 9,12,12,14,15,11,13,12,15,15,11,13,13,15,15,
  131082. 13,14,13,15,14,13,14,14,17, 0, 5, 8, 8,11,11, 8,
  131083. 10,10,12,12, 8,10,10,12,12,11,12,12,14,14,11,12,
  131084. 12,14,14, 7,10,10,12,12,10,12,12,13,13, 9,11,12,
  131085. 12,13,11,12,13,15,15,11,12,13,14,15, 8,10,10,12,
  131086. 12,10,12,11,13,13,10,12,11,13,13,11,13,13,15,14,
  131087. 12,13,12,15,13, 9,12,12,14,14,11,13,13,16,15,11,
  131088. 12,13,16,15,13,14,15,16,16,13,13,15,15,16,10,12,
  131089. 12,15,14,11,13,13,14,16,11,13,13,15,16,13,15,15,
  131090. 16,17,13,15,14,16,15, 8,11,11,14,15,10,12,12,15,
  131091. 15,10,12,12,15,16,14,15,15,16,17,13,14,14,16,16,
  131092. 9,12,12,15,15,11,13,14,15,17,11,13,13,15,16,14,
  131093. 15,16,19,17,13,15,15, 0,17, 9,12,12,15,15,11,14,
  131094. 13,16,15,11,13,13,15,16,15,15,15,18,17,13,15,15,
  131095. 17,17,11,15,14,18,16,12,14,15,17,17,12,15,15,18,
  131096. 18,15,15,16,15,19,14,16,16, 0, 0,11,14,14,16,17,
  131097. 12,15,14,18,17,12,15,15,18,18,15,17,15,18,16,14,
  131098. 16,16,18,18, 7,11,11,14,14,10,12,12,15,15,10,12,
  131099. 13,15,15,13,14,15,16,16,14,15,15,18,18, 9,12,12,
  131100. 15,15,11,13,13,16,15,11,12,13,16,16,14,15,15,17,
  131101. 16,15,16,16,17,17, 9,12,12,15,15,11,13,13,15,17,
  131102. 11,14,13,16,15,13,15,15,17,17,15,15,15,18,17,11,
  131103. 14,14,17,15,12,14,15,17,18,13,13,15,17,17,14,16,
  131104. 16,19,18,16,15,17,17, 0,11,14,14,17,17,12,15,15,
  131105. 18, 0,12,15,14,18,16,14,17,17,19, 0,16,18,15, 0,
  131106. 16,
  131107. };
  131108. static float _vq_quantthresh__8u1__p3_0[] = {
  131109. -1.5, -0.5, 0.5, 1.5,
  131110. };
  131111. static long _vq_quantmap__8u1__p3_0[] = {
  131112. 3, 1, 0, 2, 4,
  131113. };
  131114. static encode_aux_threshmatch _vq_auxt__8u1__p3_0 = {
  131115. _vq_quantthresh__8u1__p3_0,
  131116. _vq_quantmap__8u1__p3_0,
  131117. 5,
  131118. 5
  131119. };
  131120. static static_codebook _8u1__p3_0 = {
  131121. 4, 625,
  131122. _vq_lengthlist__8u1__p3_0,
  131123. 1, -533725184, 1611661312, 3, 0,
  131124. _vq_quantlist__8u1__p3_0,
  131125. NULL,
  131126. &_vq_auxt__8u1__p3_0,
  131127. NULL,
  131128. 0
  131129. };
  131130. static long _vq_quantlist__8u1__p4_0[] = {
  131131. 2,
  131132. 1,
  131133. 3,
  131134. 0,
  131135. 4,
  131136. };
  131137. static long _vq_lengthlist__8u1__p4_0[] = {
  131138. 4, 5, 5, 9, 9, 6, 7, 7, 9, 9, 6, 7, 7, 9, 9, 9,
  131139. 9, 9,11,11, 9, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 7,
  131140. 8, 9,10, 7, 7, 8, 9,10, 9, 9,10,10,11, 9, 9,10,
  131141. 10,12, 6, 7, 7, 9, 9, 7, 8, 7,10, 9, 7, 8, 7,10,
  131142. 9, 9,10, 9,12,11,10,10, 9,12,10, 9,10,10,12,11,
  131143. 9,10,10,12,11, 9,10,10,12,12,11,11,12,12,13,11,
  131144. 11,12,12,13, 9, 9,10,12,11, 9,10,10,12,12,10,10,
  131145. 10,12,12,11,12,11,13,12,11,12,11,13,12, 6, 7, 7,
  131146. 9, 9, 7, 8, 8,10,10, 7, 8, 7,10, 9,10,10,10,12,
  131147. 12,10,10,10,12,11, 7, 8, 7,10,10, 7, 7, 9,10,11,
  131148. 8, 9, 9,11,10,10,10,11,10,12,10,10,11,12,12, 7,
  131149. 8, 8,10,10, 7, 9, 8,11,10, 8, 8, 9,11,11,10,11,
  131150. 10,12,11,10,11,11,12,12, 9,10,10,12,12, 9,10,10,
  131151. 12,12,10,11,11,13,12,11,10,12,10,14,12,12,12,13,
  131152. 14, 9,10,10,12,12, 9,11,10,12,12,10,11,11,12,12,
  131153. 11,12,11,14,12,12,12,12,14,14, 5, 7, 7, 9, 9, 7,
  131154. 7, 7, 9,10, 7, 8, 8,10,10,10,10,10,11,11,10,10,
  131155. 10,12,12, 7, 8, 8,10,10, 8, 9, 8,11,10, 7, 8, 9,
  131156. 10,11,10,10,10,11,12,10,10,11,11,13, 6, 7, 8,10,
  131157. 10, 8, 9, 9,10,10, 7, 9, 7,11,10,10,11,10,12,12,
  131158. 10,11,10,12,10, 9,10,10,12,12,10,11,11,13,12, 9,
  131159. 10,10,12,12,12,12,12,14,13,11,11,12,11,14, 9,10,
  131160. 10,11,12,10,11,11,12,13, 9,10,10,12,12,12,12,12,
  131161. 14,13,11,12,10,14,11, 9, 9,10,11,12, 9,10,10,12,
  131162. 12, 9,10,10,12,12,12,12,12,14,14,11,12,12,13,12,
  131163. 9,10, 9,12,12, 9,10,11,12,13,10,11,10,13,11,12,
  131164. 12,13,13,14,12,12,12,13,13, 9,10,10,12,12,10,11,
  131165. 10,13,12,10,10,11,12,13,12,13,12,14,13,12,12,12,
  131166. 13,14,11,12,11,14,13,10,10,11,13,13,12,12,12,14,
  131167. 13,12,10,14,10,15,13,14,14,14,14,11,11,12,13,14,
  131168. 10,12,11,13,13,12,12,12,13,15,12,13,11,15,12,13,
  131169. 13,14,14,14, 9,10, 9,12,12, 9,10,10,12,12,10,10,
  131170. 10,12,12,11,11,12,12,13,12,12,12,14,14, 9,10,10,
  131171. 12,12,10,11,10,13,12,10,10,11,12,13,12,12,12,14,
  131172. 13,12,12,13,13,14, 9,10,10,12,13,10,10,11,11,12,
  131173. 9,11,10,13,12,12,12,12,13,14,12,13,12,14,13,11,
  131174. 12,11,13,13,12,13,12,14,13,10,11,12,13,13,13,13,
  131175. 13,14,15,12,11,14,12,14,11,11,12,12,13,12,12,12,
  131176. 13,14,10,12,10,14,13,13,13,13,14,15,12,14,11,15,
  131177. 10,
  131178. };
  131179. static float _vq_quantthresh__8u1__p4_0[] = {
  131180. -1.5, -0.5, 0.5, 1.5,
  131181. };
  131182. static long _vq_quantmap__8u1__p4_0[] = {
  131183. 3, 1, 0, 2, 4,
  131184. };
  131185. static encode_aux_threshmatch _vq_auxt__8u1__p4_0 = {
  131186. _vq_quantthresh__8u1__p4_0,
  131187. _vq_quantmap__8u1__p4_0,
  131188. 5,
  131189. 5
  131190. };
  131191. static static_codebook _8u1__p4_0 = {
  131192. 4, 625,
  131193. _vq_lengthlist__8u1__p4_0,
  131194. 1, -533725184, 1611661312, 3, 0,
  131195. _vq_quantlist__8u1__p4_0,
  131196. NULL,
  131197. &_vq_auxt__8u1__p4_0,
  131198. NULL,
  131199. 0
  131200. };
  131201. static long _vq_quantlist__8u1__p5_0[] = {
  131202. 4,
  131203. 3,
  131204. 5,
  131205. 2,
  131206. 6,
  131207. 1,
  131208. 7,
  131209. 0,
  131210. 8,
  131211. };
  131212. static long _vq_lengthlist__8u1__p5_0[] = {
  131213. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 5, 8, 7, 8, 8,
  131214. 10,10, 4, 6, 6, 8, 8, 8, 8,10,10, 7, 8, 8, 9, 9,
  131215. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 8, 8, 8,
  131216. 9, 9,10,10,12,11, 8, 8, 8, 9, 9,10,10,11,11, 9,
  131217. 10,10,11,11,11,11,13,12, 9,10,10,11,11,12,12,12,
  131218. 13,
  131219. };
  131220. static float _vq_quantthresh__8u1__p5_0[] = {
  131221. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  131222. };
  131223. static long _vq_quantmap__8u1__p5_0[] = {
  131224. 7, 5, 3, 1, 0, 2, 4, 6,
  131225. 8,
  131226. };
  131227. static encode_aux_threshmatch _vq_auxt__8u1__p5_0 = {
  131228. _vq_quantthresh__8u1__p5_0,
  131229. _vq_quantmap__8u1__p5_0,
  131230. 9,
  131231. 9
  131232. };
  131233. static static_codebook _8u1__p5_0 = {
  131234. 2, 81,
  131235. _vq_lengthlist__8u1__p5_0,
  131236. 1, -531628032, 1611661312, 4, 0,
  131237. _vq_quantlist__8u1__p5_0,
  131238. NULL,
  131239. &_vq_auxt__8u1__p5_0,
  131240. NULL,
  131241. 0
  131242. };
  131243. static long _vq_quantlist__8u1__p6_0[] = {
  131244. 4,
  131245. 3,
  131246. 5,
  131247. 2,
  131248. 6,
  131249. 1,
  131250. 7,
  131251. 0,
  131252. 8,
  131253. };
  131254. static long _vq_lengthlist__8u1__p6_0[] = {
  131255. 3, 4, 4, 6, 6, 7, 7, 9, 9, 4, 4, 5, 6, 6, 7, 7,
  131256. 9, 9, 4, 4, 4, 6, 6, 7, 7, 9, 9, 6, 6, 6, 7, 7,
  131257. 8, 8, 9, 9, 6, 6, 6, 7, 7, 8, 8, 9, 9, 7, 7, 7,
  131258. 8, 8, 8, 9,10,10, 7, 7, 7, 8, 8, 9, 8,10,10, 9,
  131259. 9, 9, 9, 9,10,10,10,10, 9, 9, 9, 9, 9,10,10,10,
  131260. 10,
  131261. };
  131262. static float _vq_quantthresh__8u1__p6_0[] = {
  131263. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  131264. };
  131265. static long _vq_quantmap__8u1__p6_0[] = {
  131266. 7, 5, 3, 1, 0, 2, 4, 6,
  131267. 8,
  131268. };
  131269. static encode_aux_threshmatch _vq_auxt__8u1__p6_0 = {
  131270. _vq_quantthresh__8u1__p6_0,
  131271. _vq_quantmap__8u1__p6_0,
  131272. 9,
  131273. 9
  131274. };
  131275. static static_codebook _8u1__p6_0 = {
  131276. 2, 81,
  131277. _vq_lengthlist__8u1__p6_0,
  131278. 1, -531628032, 1611661312, 4, 0,
  131279. _vq_quantlist__8u1__p6_0,
  131280. NULL,
  131281. &_vq_auxt__8u1__p6_0,
  131282. NULL,
  131283. 0
  131284. };
  131285. static long _vq_quantlist__8u1__p7_0[] = {
  131286. 1,
  131287. 0,
  131288. 2,
  131289. };
  131290. static long _vq_lengthlist__8u1__p7_0[] = {
  131291. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 9, 8,10,10, 8,
  131292. 10,10, 5, 9, 9, 7,10,10, 8,10,10, 4,10,10, 9,12,
  131293. 12, 9,11,11, 7,12,11,10,11,13,10,13,13, 7,12,12,
  131294. 10,13,12,10,13,13, 4,10,10, 9,12,12, 9,12,12, 7,
  131295. 12,12,10,13,13,10,12,13, 7,11,12,10,13,13,10,13,
  131296. 11,
  131297. };
  131298. static float _vq_quantthresh__8u1__p7_0[] = {
  131299. -5.5, 5.5,
  131300. };
  131301. static long _vq_quantmap__8u1__p7_0[] = {
  131302. 1, 0, 2,
  131303. };
  131304. static encode_aux_threshmatch _vq_auxt__8u1__p7_0 = {
  131305. _vq_quantthresh__8u1__p7_0,
  131306. _vq_quantmap__8u1__p7_0,
  131307. 3,
  131308. 3
  131309. };
  131310. static static_codebook _8u1__p7_0 = {
  131311. 4, 81,
  131312. _vq_lengthlist__8u1__p7_0,
  131313. 1, -529137664, 1618345984, 2, 0,
  131314. _vq_quantlist__8u1__p7_0,
  131315. NULL,
  131316. &_vq_auxt__8u1__p7_0,
  131317. NULL,
  131318. 0
  131319. };
  131320. static long _vq_quantlist__8u1__p7_1[] = {
  131321. 5,
  131322. 4,
  131323. 6,
  131324. 3,
  131325. 7,
  131326. 2,
  131327. 8,
  131328. 1,
  131329. 9,
  131330. 0,
  131331. 10,
  131332. };
  131333. static long _vq_lengthlist__8u1__p7_1[] = {
  131334. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 7, 7,
  131335. 8, 8, 9, 9, 9, 9, 4, 5, 5, 7, 7, 8, 8, 9, 9, 9,
  131336. 9, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8,
  131337. 8, 8, 8, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9,
  131338. 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 9, 9,
  131339. 9, 9, 9, 9,10,10,10,10, 8, 9, 9, 9, 9, 9, 9,10,
  131340. 10,10,10, 8, 9, 9, 9, 9, 9, 9,10,10,10,10, 8, 9,
  131341. 9, 9, 9, 9, 9,10,10,10,10,
  131342. };
  131343. static float _vq_quantthresh__8u1__p7_1[] = {
  131344. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  131345. 3.5, 4.5,
  131346. };
  131347. static long _vq_quantmap__8u1__p7_1[] = {
  131348. 9, 7, 5, 3, 1, 0, 2, 4,
  131349. 6, 8, 10,
  131350. };
  131351. static encode_aux_threshmatch _vq_auxt__8u1__p7_1 = {
  131352. _vq_quantthresh__8u1__p7_1,
  131353. _vq_quantmap__8u1__p7_1,
  131354. 11,
  131355. 11
  131356. };
  131357. static static_codebook _8u1__p7_1 = {
  131358. 2, 121,
  131359. _vq_lengthlist__8u1__p7_1,
  131360. 1, -531365888, 1611661312, 4, 0,
  131361. _vq_quantlist__8u1__p7_1,
  131362. NULL,
  131363. &_vq_auxt__8u1__p7_1,
  131364. NULL,
  131365. 0
  131366. };
  131367. static long _vq_quantlist__8u1__p8_0[] = {
  131368. 5,
  131369. 4,
  131370. 6,
  131371. 3,
  131372. 7,
  131373. 2,
  131374. 8,
  131375. 1,
  131376. 9,
  131377. 0,
  131378. 10,
  131379. };
  131380. static long _vq_lengthlist__8u1__p8_0[] = {
  131381. 1, 4, 4, 6, 6, 8, 8,10,10,11,11, 4, 6, 6, 7, 7,
  131382. 9, 9,11,11,13,12, 4, 6, 6, 7, 7, 9, 9,11,11,12,
  131383. 12, 6, 7, 7, 9, 9,11,11,12,12,13,13, 6, 7, 7, 9,
  131384. 9,11,11,12,12,13,13, 8, 9, 9,11,11,12,12,13,13,
  131385. 14,14, 8, 9, 9,11,11,12,12,13,13,14,14, 9,11,11,
  131386. 12,12,13,13,14,14,15,15, 9,11,11,12,12,13,13,14,
  131387. 14,15,14,11,12,12,13,13,14,14,15,15,16,16,11,12,
  131388. 12,13,13,14,14,15,15,15,15,
  131389. };
  131390. static float _vq_quantthresh__8u1__p8_0[] = {
  131391. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  131392. 38.5, 49.5,
  131393. };
  131394. static long _vq_quantmap__8u1__p8_0[] = {
  131395. 9, 7, 5, 3, 1, 0, 2, 4,
  131396. 6, 8, 10,
  131397. };
  131398. static encode_aux_threshmatch _vq_auxt__8u1__p8_0 = {
  131399. _vq_quantthresh__8u1__p8_0,
  131400. _vq_quantmap__8u1__p8_0,
  131401. 11,
  131402. 11
  131403. };
  131404. static static_codebook _8u1__p8_0 = {
  131405. 2, 121,
  131406. _vq_lengthlist__8u1__p8_0,
  131407. 1, -524582912, 1618345984, 4, 0,
  131408. _vq_quantlist__8u1__p8_0,
  131409. NULL,
  131410. &_vq_auxt__8u1__p8_0,
  131411. NULL,
  131412. 0
  131413. };
  131414. static long _vq_quantlist__8u1__p8_1[] = {
  131415. 5,
  131416. 4,
  131417. 6,
  131418. 3,
  131419. 7,
  131420. 2,
  131421. 8,
  131422. 1,
  131423. 9,
  131424. 0,
  131425. 10,
  131426. };
  131427. static long _vq_lengthlist__8u1__p8_1[] = {
  131428. 2, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 5, 6, 6, 7, 7,
  131429. 7, 7, 8, 8, 8, 8, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8,
  131430. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7,
  131431. 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8,
  131432. 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  131433. 8, 8, 8, 8, 9, 8, 9, 9, 7, 8, 8, 8, 8, 8, 8, 9,
  131434. 8, 9, 9, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8,
  131435. 8, 8, 8, 8, 8, 9, 9, 9, 9,
  131436. };
  131437. static float _vq_quantthresh__8u1__p8_1[] = {
  131438. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  131439. 3.5, 4.5,
  131440. };
  131441. static long _vq_quantmap__8u1__p8_1[] = {
  131442. 9, 7, 5, 3, 1, 0, 2, 4,
  131443. 6, 8, 10,
  131444. };
  131445. static encode_aux_threshmatch _vq_auxt__8u1__p8_1 = {
  131446. _vq_quantthresh__8u1__p8_1,
  131447. _vq_quantmap__8u1__p8_1,
  131448. 11,
  131449. 11
  131450. };
  131451. static static_codebook _8u1__p8_1 = {
  131452. 2, 121,
  131453. _vq_lengthlist__8u1__p8_1,
  131454. 1, -531365888, 1611661312, 4, 0,
  131455. _vq_quantlist__8u1__p8_1,
  131456. NULL,
  131457. &_vq_auxt__8u1__p8_1,
  131458. NULL,
  131459. 0
  131460. };
  131461. static long _vq_quantlist__8u1__p9_0[] = {
  131462. 7,
  131463. 6,
  131464. 8,
  131465. 5,
  131466. 9,
  131467. 4,
  131468. 10,
  131469. 3,
  131470. 11,
  131471. 2,
  131472. 12,
  131473. 1,
  131474. 13,
  131475. 0,
  131476. 14,
  131477. };
  131478. static long _vq_lengthlist__8u1__p9_0[] = {
  131479. 1, 4, 4,11,11,11,11,11,11,11,11,11,11,11,11, 3,
  131480. 11, 8,11,11,11,11,11,11,11,11,11,11,11,11, 3, 9,
  131481. 9,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131482. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131483. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131484. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131485. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131486. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131487. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131488. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131489. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131490. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131491. 11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,
  131492. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131493. 10,
  131494. };
  131495. static float _vq_quantthresh__8u1__p9_0[] = {
  131496. -1657.5, -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5,
  131497. 382.5, 637.5, 892.5, 1147.5, 1402.5, 1657.5,
  131498. };
  131499. static long _vq_quantmap__8u1__p9_0[] = {
  131500. 13, 11, 9, 7, 5, 3, 1, 0,
  131501. 2, 4, 6, 8, 10, 12, 14,
  131502. };
  131503. static encode_aux_threshmatch _vq_auxt__8u1__p9_0 = {
  131504. _vq_quantthresh__8u1__p9_0,
  131505. _vq_quantmap__8u1__p9_0,
  131506. 15,
  131507. 15
  131508. };
  131509. static static_codebook _8u1__p9_0 = {
  131510. 2, 225,
  131511. _vq_lengthlist__8u1__p9_0,
  131512. 1, -514071552, 1627381760, 4, 0,
  131513. _vq_quantlist__8u1__p9_0,
  131514. NULL,
  131515. &_vq_auxt__8u1__p9_0,
  131516. NULL,
  131517. 0
  131518. };
  131519. static long _vq_quantlist__8u1__p9_1[] = {
  131520. 7,
  131521. 6,
  131522. 8,
  131523. 5,
  131524. 9,
  131525. 4,
  131526. 10,
  131527. 3,
  131528. 11,
  131529. 2,
  131530. 12,
  131531. 1,
  131532. 13,
  131533. 0,
  131534. 14,
  131535. };
  131536. static long _vq_lengthlist__8u1__p9_1[] = {
  131537. 1, 4, 4, 7, 7, 9, 9, 7, 7, 8, 8,10,10,11,11, 4,
  131538. 7, 7, 9, 9,10,10, 8, 8,10,10,10,11,10,11, 4, 7,
  131539. 7, 9, 9,10,10, 8, 8,10, 9,11,11,11,11, 7, 9, 9,
  131540. 12,12,11,12,10,10,11,10,12,11,11,11, 7, 9, 9,11,
  131541. 11,13,12, 9, 9,11,10,11,11,12,11, 9,10,10,12,12,
  131542. 14,14,10,10,11,12,12,11,11,11, 9,10,11,11,13,14,
  131543. 13,10,11,11,11,12,11,12,12, 7, 8, 8,10, 9,11,10,
  131544. 11,12,12,11,12,14,12,13, 7, 8, 8, 9,10,10,11,12,
  131545. 12,12,11,12,12,12,13, 9, 9, 9,11,11,13,12,12,12,
  131546. 12,11,12,12,13,12, 8,10,10,11,10,11,12,12,12,12,
  131547. 12,12,14,12,12, 9,11,11,11,12,12,12,12,13,13,12,
  131548. 12,13,13,12,10,11,11,12,11,12,12,12,11,12,13,12,
  131549. 12,12,13,11,11,12,12,12,13,12,12,11,12,13,13,12,
  131550. 12,13,12,11,12,12,13,13,12,13,12,13,13,13,13,14,
  131551. 13,
  131552. };
  131553. static float _vq_quantthresh__8u1__p9_1[] = {
  131554. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  131555. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  131556. };
  131557. static long _vq_quantmap__8u1__p9_1[] = {
  131558. 13, 11, 9, 7, 5, 3, 1, 0,
  131559. 2, 4, 6, 8, 10, 12, 14,
  131560. };
  131561. static encode_aux_threshmatch _vq_auxt__8u1__p9_1 = {
  131562. _vq_quantthresh__8u1__p9_1,
  131563. _vq_quantmap__8u1__p9_1,
  131564. 15,
  131565. 15
  131566. };
  131567. static static_codebook _8u1__p9_1 = {
  131568. 2, 225,
  131569. _vq_lengthlist__8u1__p9_1,
  131570. 1, -522338304, 1620115456, 4, 0,
  131571. _vq_quantlist__8u1__p9_1,
  131572. NULL,
  131573. &_vq_auxt__8u1__p9_1,
  131574. NULL,
  131575. 0
  131576. };
  131577. static long _vq_quantlist__8u1__p9_2[] = {
  131578. 8,
  131579. 7,
  131580. 9,
  131581. 6,
  131582. 10,
  131583. 5,
  131584. 11,
  131585. 4,
  131586. 12,
  131587. 3,
  131588. 13,
  131589. 2,
  131590. 14,
  131591. 1,
  131592. 15,
  131593. 0,
  131594. 16,
  131595. };
  131596. static long _vq_lengthlist__8u1__p9_2[] = {
  131597. 2, 5, 4, 6, 6, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  131598. 9, 5, 6, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  131599. 9, 9, 5, 6, 6, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  131600. 9, 9, 9, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  131601. 9,10,10, 9, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  131602. 9, 9, 9,10,10, 8, 8, 8, 9, 9, 9, 9,10,10,10, 9,
  131603. 10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  131604. 10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,10,
  131605. 10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,10,10,
  131606. 10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,
  131607. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  131608. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,10,
  131609. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  131610. 9,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  131611. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,10,
  131612. 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  131613. 10, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131614. 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131615. 10,
  131616. };
  131617. static float _vq_quantthresh__8u1__p9_2[] = {
  131618. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  131619. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  131620. };
  131621. static long _vq_quantmap__8u1__p9_2[] = {
  131622. 15, 13, 11, 9, 7, 5, 3, 1,
  131623. 0, 2, 4, 6, 8, 10, 12, 14,
  131624. 16,
  131625. };
  131626. static encode_aux_threshmatch _vq_auxt__8u1__p9_2 = {
  131627. _vq_quantthresh__8u1__p9_2,
  131628. _vq_quantmap__8u1__p9_2,
  131629. 17,
  131630. 17
  131631. };
  131632. static static_codebook _8u1__p9_2 = {
  131633. 2, 289,
  131634. _vq_lengthlist__8u1__p9_2,
  131635. 1, -529530880, 1611661312, 5, 0,
  131636. _vq_quantlist__8u1__p9_2,
  131637. NULL,
  131638. &_vq_auxt__8u1__p9_2,
  131639. NULL,
  131640. 0
  131641. };
  131642. static long _huff_lengthlist__8u1__single[] = {
  131643. 4, 7,13, 9,15, 9,16, 8,10,13, 7, 5, 8, 6, 9, 7,
  131644. 10, 7,10,11,11, 6, 7, 8, 8, 9, 9, 9,12,16, 8, 5,
  131645. 8, 6, 8, 6, 9, 7,10,12,11, 7, 7, 7, 6, 7, 7, 7,
  131646. 11,15, 7, 5, 8, 6, 7, 5, 7, 6, 9,13,13, 9, 9, 8,
  131647. 6, 6, 5, 5, 9,14, 8, 6, 8, 6, 6, 4, 5, 3, 5,13,
  131648. 9, 9,11, 8,10, 7, 8, 4, 5,12,11,16,17,15,17,12,
  131649. 13, 8, 8,15,
  131650. };
  131651. static static_codebook _huff_book__8u1__single = {
  131652. 2, 100,
  131653. _huff_lengthlist__8u1__single,
  131654. 0, 0, 0, 0, 0,
  131655. NULL,
  131656. NULL,
  131657. NULL,
  131658. NULL,
  131659. 0
  131660. };
  131661. static long _huff_lengthlist__44u0__long[] = {
  131662. 5, 8,13,10,17,11,11,15, 7, 2, 4, 5, 8, 7, 9,16,
  131663. 13, 4, 3, 5, 6, 8,11,20,10, 4, 5, 5, 7, 6, 8,18,
  131664. 15, 7, 6, 7, 8,10,14,20,10, 6, 7, 6, 9, 7, 8,17,
  131665. 9, 8,10, 8,10, 5, 4,11,12,17,19,14,16,10, 7,12,
  131666. };
  131667. static static_codebook _huff_book__44u0__long = {
  131668. 2, 64,
  131669. _huff_lengthlist__44u0__long,
  131670. 0, 0, 0, 0, 0,
  131671. NULL,
  131672. NULL,
  131673. NULL,
  131674. NULL,
  131675. 0
  131676. };
  131677. static long _vq_quantlist__44u0__p1_0[] = {
  131678. 1,
  131679. 0,
  131680. 2,
  131681. };
  131682. static long _vq_lengthlist__44u0__p1_0[] = {
  131683. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,11,11, 8,
  131684. 10,10, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  131685. 11, 8,11,11, 8,12,11,11,13,13,11,13,14, 7,11,11,
  131686. 10,13,12,11,13,14, 4, 8, 8, 8,11,11, 8,11,12, 8,
  131687. 11,11,11,13,13,10,12,13, 8,11,11,11,14,13,11,14,
  131688. 13,
  131689. };
  131690. static float _vq_quantthresh__44u0__p1_0[] = {
  131691. -0.5, 0.5,
  131692. };
  131693. static long _vq_quantmap__44u0__p1_0[] = {
  131694. 1, 0, 2,
  131695. };
  131696. static encode_aux_threshmatch _vq_auxt__44u0__p1_0 = {
  131697. _vq_quantthresh__44u0__p1_0,
  131698. _vq_quantmap__44u0__p1_0,
  131699. 3,
  131700. 3
  131701. };
  131702. static static_codebook _44u0__p1_0 = {
  131703. 4, 81,
  131704. _vq_lengthlist__44u0__p1_0,
  131705. 1, -535822336, 1611661312, 2, 0,
  131706. _vq_quantlist__44u0__p1_0,
  131707. NULL,
  131708. &_vq_auxt__44u0__p1_0,
  131709. NULL,
  131710. 0
  131711. };
  131712. static long _vq_quantlist__44u0__p2_0[] = {
  131713. 1,
  131714. 0,
  131715. 2,
  131716. };
  131717. static long _vq_lengthlist__44u0__p2_0[] = {
  131718. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 8, 6,
  131719. 8, 8, 5, 7, 7, 6, 8, 8, 7, 8, 8, 4, 7, 7, 7, 8,
  131720. 8, 7, 8, 8, 7, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  131721. 8,10, 8, 8,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 8, 6,
  131722. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  131723. 9,
  131724. };
  131725. static float _vq_quantthresh__44u0__p2_0[] = {
  131726. -0.5, 0.5,
  131727. };
  131728. static long _vq_quantmap__44u0__p2_0[] = {
  131729. 1, 0, 2,
  131730. };
  131731. static encode_aux_threshmatch _vq_auxt__44u0__p2_0 = {
  131732. _vq_quantthresh__44u0__p2_0,
  131733. _vq_quantmap__44u0__p2_0,
  131734. 3,
  131735. 3
  131736. };
  131737. static static_codebook _44u0__p2_0 = {
  131738. 4, 81,
  131739. _vq_lengthlist__44u0__p2_0,
  131740. 1, -535822336, 1611661312, 2, 0,
  131741. _vq_quantlist__44u0__p2_0,
  131742. NULL,
  131743. &_vq_auxt__44u0__p2_0,
  131744. NULL,
  131745. 0
  131746. };
  131747. static long _vq_quantlist__44u0__p3_0[] = {
  131748. 2,
  131749. 1,
  131750. 3,
  131751. 0,
  131752. 4,
  131753. };
  131754. static long _vq_lengthlist__44u0__p3_0[] = {
  131755. 1, 5, 5, 8, 8, 5, 8, 7, 9, 9, 5, 7, 8, 9, 9, 9,
  131756. 10, 9,12,12, 9, 9,10,12,12, 6, 8, 8,11,10, 8,10,
  131757. 10,11,11, 8, 9,10,11,11,10,11,11,14,13,10,11,11,
  131758. 13,13, 5, 8, 8,10,10, 8,10,10,11,11, 8,10,10,11,
  131759. 11,10,11,11,13,13,10,11,11,13,13, 9,11,11,15,14,
  131760. 10,12,12,15,14,10,12,11,15,14,13,14,14,16,16,12,
  131761. 14,13,17,15, 9,11,11,14,15,10,11,12,14,16,10,11,
  131762. 12,14,16,12,13,14,16,16,13,13,15,15,18, 5, 8, 8,
  131763. 11,11, 8,10,10,12,12, 8,10,10,12,13,11,12,12,14,
  131764. 14,11,12,12,15,15, 8,10,10,13,13,10,12,12,13,13,
  131765. 10,12,12,14,14,12,13,13,15,15,12,13,13,16,16, 7,
  131766. 10,10,12,12,10,12,11,13,13,10,12,12,13,14,12,13,
  131767. 12,15,14,12,13,13,16,16,10,12,12,17,16,12,13,13,
  131768. 16,15,11,13,13,17,17,15,15,15,16,17,14,15,15,19,
  131769. 19,10,12,12,15,16,11,13,12,15,18,11,13,13,16,16,
  131770. 14,15,15,17,17,14,15,15,17,19, 5, 8, 8,11,11, 8,
  131771. 10,10,12,12, 8,10,10,12,12,11,12,12,16,15,11,12,
  131772. 12,14,15, 7,10,10,13,13,10,12,12,14,13,10,11,12,
  131773. 13,13,12,13,13,16,16,12,12,13,15,15, 8,10,10,13,
  131774. 13,10,12,12,14,14,10,12,12,13,13,12,13,13,16,16,
  131775. 12,13,13,15,15,10,12,12,16,15,11,13,13,17,16,11,
  131776. 12,13,16,15,13,15,15,19,17,14,15,14,17,16,10,12,
  131777. 12,16,16,11,13,13,16,17,12,13,13,15,17,14,15,15,
  131778. 17,19,14,15,15,17,17, 8,11,11,16,16,10,13,12,17,
  131779. 17,10,12,13,16,16,15,17,16,20,19,14,15,17,18,19,
  131780. 9,12,12,16,17,11,13,14,17,18,11,13,13,19,18,16,
  131781. 17,18,19,19,15,16,16,19,19, 9,12,12,16,17,11,14,
  131782. 13,18,17,11,13,13,17,17,16,17,16,20,19,14,16,16,
  131783. 18,18,12,15,15,19,17,14,15,16, 0,20,13,15,16,20,
  131784. 17,18,16,20, 0, 0,15,16,19,20, 0,12,15,14,18,19,
  131785. 13,16,15,20,19,13,16,15,20,18,17,18,17, 0,20,16,
  131786. 17,16, 0, 0, 8,11,11,16,15,10,12,12,17,17,10,13,
  131787. 13,17,16,14,16,15,18,20,15,16,16,19,19, 9,12,12,
  131788. 16,16,11,13,13,17,16,11,13,14,17,18,15,15,16,20,
  131789. 20,16,16,17,19,19, 9,13,12,16,17,11,14,13,17,17,
  131790. 11,14,14,18,17,14,16,15,18,19,16,17,18,18,19,12,
  131791. 14,15,19,18,13,15,16,18, 0,13,14,15, 0, 0,16,16,
  131792. 17,20, 0,17,17,20,20, 0,12,15,15,19,20,13,15,15,
  131793. 0, 0,14,16,15, 0, 0,15,18,16, 0, 0,17,18,16, 0,
  131794. 19,
  131795. };
  131796. static float _vq_quantthresh__44u0__p3_0[] = {
  131797. -1.5, -0.5, 0.5, 1.5,
  131798. };
  131799. static long _vq_quantmap__44u0__p3_0[] = {
  131800. 3, 1, 0, 2, 4,
  131801. };
  131802. static encode_aux_threshmatch _vq_auxt__44u0__p3_0 = {
  131803. _vq_quantthresh__44u0__p3_0,
  131804. _vq_quantmap__44u0__p3_0,
  131805. 5,
  131806. 5
  131807. };
  131808. static static_codebook _44u0__p3_0 = {
  131809. 4, 625,
  131810. _vq_lengthlist__44u0__p3_0,
  131811. 1, -533725184, 1611661312, 3, 0,
  131812. _vq_quantlist__44u0__p3_0,
  131813. NULL,
  131814. &_vq_auxt__44u0__p3_0,
  131815. NULL,
  131816. 0
  131817. };
  131818. static long _vq_quantlist__44u0__p4_0[] = {
  131819. 2,
  131820. 1,
  131821. 3,
  131822. 0,
  131823. 4,
  131824. };
  131825. static long _vq_lengthlist__44u0__p4_0[] = {
  131826. 4, 5, 5, 9, 9, 5, 6, 6, 9, 9, 5, 6, 6, 9, 9, 9,
  131827. 10, 9,12,12, 9, 9,10,12,12, 5, 7, 7,10,10, 7, 7,
  131828. 8,10,10, 6, 7, 8,10,10,10,10,10,11,13,10, 9,10,
  131829. 12,13, 5, 7, 7,10,10, 6, 8, 7,10,10, 7, 8, 7,10,
  131830. 10, 9,10,10,12,12,10,10,10,13,11, 9,10,10,13,13,
  131831. 10,11,10,13,13,10,10,10,13,13,12,12,13,14,14,12,
  131832. 12,13,14,14, 9,10,10,13,13,10,10,10,13,13,10,10,
  131833. 10,13,13,12,13,12,15,14,12,13,12,15,15, 5, 7, 6,
  131834. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,13,
  131835. 13,10,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,10,11,
  131836. 8, 9, 9,11,11,11,10,11,11,14,11,11,11,13,13, 6,
  131837. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  131838. 10,14,11,10,11,11,13,13,10,11,11,14,13,10,10,11,
  131839. 14,13,10,11,11,14,14,12,11,13,12,16,13,14,14,15,
  131840. 15,10,10,11,13,14,10,11,10,14,13,10,11,11,14,14,
  131841. 12,13,12,15,13,13,13,14,15,16, 5, 7, 7,10,10, 7,
  131842. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,13,13,10,10,
  131843. 11,12,13, 6, 8, 8,11,10, 8, 9, 9,11,11, 7, 8, 9,
  131844. 10,11,10,11,11,13,13,10,10,11,11,13, 6, 8, 8,10,
  131845. 11, 8, 9, 9,11,11, 8, 9, 8,12,10,10,11,11,13,13,
  131846. 10,11,10,14,11,10,10,10,14,13,10,11,11,14,13,10,
  131847. 10,11,13,13,12,14,14,16,16,12,12,13,13,15,10,11,
  131848. 11,13,14,10,11,11,14,15,10,11,10,13,13,13,14,13,
  131849. 16,16,12,13,11,15,12, 9,10,10,13,13,10,11,11,14,
  131850. 13,10,10,11,13,14,13,14,13,16,16,13,13,13,15,16,
  131851. 9,10,10,13,13,10,10,11,13,14,10,11,11,15,13,13,
  131852. 13,14,14,18,13,13,14,16,15, 9,10,10,13,14,10,11,
  131853. 10,14,13,10,11,11,13,14,13,14,13,16,15,13,13,14,
  131854. 15,16,12,13,12,16,14,11,11,13,15,15,13,14,13,16,
  131855. 15,15,12,16,12,17,14,15,15,17,17,12,13,13,14,16,
  131856. 11,13,11,16,15,12,13,14,15,16,14,15,13, 0,14,14,
  131857. 16,16, 0, 0, 9,10,10,13,13,10,11,10,14,14,10,11,
  131858. 11,13,13,12,13,13,14,16,13,14,14,16,16, 9,10,10,
  131859. 14,14,11,11,11,14,13,10,10,11,14,14,13,13,13,16,
  131860. 16,13,13,14,14,17, 9,10,10,13,14,10,11,11,13,15,
  131861. 10,11,10,14,14,13,13,13,14,17,13,14,13,17,14,12,
  131862. 13,13,16,14,13,14,13,16,15,12,12,13,15,16,15,15,
  131863. 16,18,16,15,13,15,14, 0,12,12,13,14,16,13,13,14,
  131864. 15,16,11,12,11,16,14,15,16,16,17,17,14,15,12,17,
  131865. 12,
  131866. };
  131867. static float _vq_quantthresh__44u0__p4_0[] = {
  131868. -1.5, -0.5, 0.5, 1.5,
  131869. };
  131870. static long _vq_quantmap__44u0__p4_0[] = {
  131871. 3, 1, 0, 2, 4,
  131872. };
  131873. static encode_aux_threshmatch _vq_auxt__44u0__p4_0 = {
  131874. _vq_quantthresh__44u0__p4_0,
  131875. _vq_quantmap__44u0__p4_0,
  131876. 5,
  131877. 5
  131878. };
  131879. static static_codebook _44u0__p4_0 = {
  131880. 4, 625,
  131881. _vq_lengthlist__44u0__p4_0,
  131882. 1, -533725184, 1611661312, 3, 0,
  131883. _vq_quantlist__44u0__p4_0,
  131884. NULL,
  131885. &_vq_auxt__44u0__p4_0,
  131886. NULL,
  131887. 0
  131888. };
  131889. static long _vq_quantlist__44u0__p5_0[] = {
  131890. 4,
  131891. 3,
  131892. 5,
  131893. 2,
  131894. 6,
  131895. 1,
  131896. 7,
  131897. 0,
  131898. 8,
  131899. };
  131900. static long _vq_lengthlist__44u0__p5_0[] = {
  131901. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  131902. 9, 9, 4, 6, 6, 8, 8, 8, 8, 9, 9, 7, 8, 8, 9, 9,
  131903. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,10, 7, 8, 8,
  131904. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  131905. 9, 9,10,10,11,11,12,12, 9, 9, 9,10,11,11,11,12,
  131906. 12,
  131907. };
  131908. static float _vq_quantthresh__44u0__p5_0[] = {
  131909. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  131910. };
  131911. static long _vq_quantmap__44u0__p5_0[] = {
  131912. 7, 5, 3, 1, 0, 2, 4, 6,
  131913. 8,
  131914. };
  131915. static encode_aux_threshmatch _vq_auxt__44u0__p5_0 = {
  131916. _vq_quantthresh__44u0__p5_0,
  131917. _vq_quantmap__44u0__p5_0,
  131918. 9,
  131919. 9
  131920. };
  131921. static static_codebook _44u0__p5_0 = {
  131922. 2, 81,
  131923. _vq_lengthlist__44u0__p5_0,
  131924. 1, -531628032, 1611661312, 4, 0,
  131925. _vq_quantlist__44u0__p5_0,
  131926. NULL,
  131927. &_vq_auxt__44u0__p5_0,
  131928. NULL,
  131929. 0
  131930. };
  131931. static long _vq_quantlist__44u0__p6_0[] = {
  131932. 6,
  131933. 5,
  131934. 7,
  131935. 4,
  131936. 8,
  131937. 3,
  131938. 9,
  131939. 2,
  131940. 10,
  131941. 1,
  131942. 11,
  131943. 0,
  131944. 12,
  131945. };
  131946. static long _vq_lengthlist__44u0__p6_0[] = {
  131947. 1, 4, 4, 6, 6, 8, 8,10, 9,11,10,14,13, 4, 6, 5,
  131948. 8, 8, 9, 9,11,10,11,11,14,14, 4, 5, 6, 8, 8, 9,
  131949. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  131950. 12,12,16,15, 7, 8, 8, 9, 9,10,10,11,11,12,12,15,
  131951. 15, 9,10,10,10,10,11,11,12,12,12,12,15,15, 9,10,
  131952. 9,10,11,11,11,12,12,12,13,15,15,10,10,11,11,11,
  131953. 12,12,13,12,13,13,16,15,10,11,11,11,11,12,12,13,
  131954. 12,13,13,16,17,11,11,12,12,12,13,13,13,14,14,15,
  131955. 17,17,11,11,12,12,12,13,13,13,14,14,14,16,18,14,
  131956. 15,15,15,15,16,16,16,16,17,18, 0, 0,14,15,15,15,
  131957. 15,17,16,17,18,17,17,18, 0,
  131958. };
  131959. static float _vq_quantthresh__44u0__p6_0[] = {
  131960. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  131961. 12.5, 17.5, 22.5, 27.5,
  131962. };
  131963. static long _vq_quantmap__44u0__p6_0[] = {
  131964. 11, 9, 7, 5, 3, 1, 0, 2,
  131965. 4, 6, 8, 10, 12,
  131966. };
  131967. static encode_aux_threshmatch _vq_auxt__44u0__p6_0 = {
  131968. _vq_quantthresh__44u0__p6_0,
  131969. _vq_quantmap__44u0__p6_0,
  131970. 13,
  131971. 13
  131972. };
  131973. static static_codebook _44u0__p6_0 = {
  131974. 2, 169,
  131975. _vq_lengthlist__44u0__p6_0,
  131976. 1, -526516224, 1616117760, 4, 0,
  131977. _vq_quantlist__44u0__p6_0,
  131978. NULL,
  131979. &_vq_auxt__44u0__p6_0,
  131980. NULL,
  131981. 0
  131982. };
  131983. static long _vq_quantlist__44u0__p6_1[] = {
  131984. 2,
  131985. 1,
  131986. 3,
  131987. 0,
  131988. 4,
  131989. };
  131990. static long _vq_lengthlist__44u0__p6_1[] = {
  131991. 2, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5,
  131992. 6, 6, 6, 6, 5, 6, 6, 6, 6,
  131993. };
  131994. static float _vq_quantthresh__44u0__p6_1[] = {
  131995. -1.5, -0.5, 0.5, 1.5,
  131996. };
  131997. static long _vq_quantmap__44u0__p6_1[] = {
  131998. 3, 1, 0, 2, 4,
  131999. };
  132000. static encode_aux_threshmatch _vq_auxt__44u0__p6_1 = {
  132001. _vq_quantthresh__44u0__p6_1,
  132002. _vq_quantmap__44u0__p6_1,
  132003. 5,
  132004. 5
  132005. };
  132006. static static_codebook _44u0__p6_1 = {
  132007. 2, 25,
  132008. _vq_lengthlist__44u0__p6_1,
  132009. 1, -533725184, 1611661312, 3, 0,
  132010. _vq_quantlist__44u0__p6_1,
  132011. NULL,
  132012. &_vq_auxt__44u0__p6_1,
  132013. NULL,
  132014. 0
  132015. };
  132016. static long _vq_quantlist__44u0__p7_0[] = {
  132017. 2,
  132018. 1,
  132019. 3,
  132020. 0,
  132021. 4,
  132022. };
  132023. static long _vq_lengthlist__44u0__p7_0[] = {
  132024. 1, 4, 4,11,11, 9,11,11,11,11,11,11,11,11,11,11,
  132025. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132026. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132027. 11,11, 9,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132028. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132029. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132030. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132031. 11,11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,
  132032. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132033. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132034. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132035. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132036. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132037. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132038. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132039. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132040. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132041. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132042. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132043. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132044. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132045. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132046. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132047. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132048. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132049. 11,11,11,11,11,11,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,11,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,10,10,10,10,10,10,10,10,10,10,
  132055. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132056. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132057. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132058. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132059. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132060. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132061. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132062. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132063. 10,
  132064. };
  132065. static float _vq_quantthresh__44u0__p7_0[] = {
  132066. -253.5, -84.5, 84.5, 253.5,
  132067. };
  132068. static long _vq_quantmap__44u0__p7_0[] = {
  132069. 3, 1, 0, 2, 4,
  132070. };
  132071. static encode_aux_threshmatch _vq_auxt__44u0__p7_0 = {
  132072. _vq_quantthresh__44u0__p7_0,
  132073. _vq_quantmap__44u0__p7_0,
  132074. 5,
  132075. 5
  132076. };
  132077. static static_codebook _44u0__p7_0 = {
  132078. 4, 625,
  132079. _vq_lengthlist__44u0__p7_0,
  132080. 1, -518709248, 1626677248, 3, 0,
  132081. _vq_quantlist__44u0__p7_0,
  132082. NULL,
  132083. &_vq_auxt__44u0__p7_0,
  132084. NULL,
  132085. 0
  132086. };
  132087. static long _vq_quantlist__44u0__p7_1[] = {
  132088. 6,
  132089. 5,
  132090. 7,
  132091. 4,
  132092. 8,
  132093. 3,
  132094. 9,
  132095. 2,
  132096. 10,
  132097. 1,
  132098. 11,
  132099. 0,
  132100. 12,
  132101. };
  132102. static long _vq_lengthlist__44u0__p7_1[] = {
  132103. 1, 4, 4, 6, 6, 6, 6, 7, 7, 8, 8, 9, 9, 5, 7, 7,
  132104. 8, 7, 7, 7, 9, 8,10, 9,10,11, 5, 7, 7, 8, 8, 7,
  132105. 7, 8, 9,10,10,11,11, 6, 8, 8, 9, 9, 9, 9,11,10,
  132106. 12,12,15,12, 6, 8, 8, 9, 9, 9, 9,11,11,12,11,14,
  132107. 12, 7, 8, 8,10,10,12,12,13,13,13,15,13,13, 7, 8,
  132108. 8,10,10,11,11,13,12,14,15,15,15, 9,10,10,11,12,
  132109. 13,13,14,15,14,15,14,15, 8,10,10,12,12,14,14,15,
  132110. 14,14,15,15,14,10,12,12,14,14,15,14,15,15,15,14,
  132111. 15,15,10,12,12,13,14,15,14,15,15,14,15,15,15,12,
  132112. 15,13,15,14,15,15,15,15,15,15,15,15,13,13,15,15,
  132113. 15,15,15,15,15,15,15,15,15,
  132114. };
  132115. static float _vq_quantthresh__44u0__p7_1[] = {
  132116. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  132117. 32.5, 45.5, 58.5, 71.5,
  132118. };
  132119. static long _vq_quantmap__44u0__p7_1[] = {
  132120. 11, 9, 7, 5, 3, 1, 0, 2,
  132121. 4, 6, 8, 10, 12,
  132122. };
  132123. static encode_aux_threshmatch _vq_auxt__44u0__p7_1 = {
  132124. _vq_quantthresh__44u0__p7_1,
  132125. _vq_quantmap__44u0__p7_1,
  132126. 13,
  132127. 13
  132128. };
  132129. static static_codebook _44u0__p7_1 = {
  132130. 2, 169,
  132131. _vq_lengthlist__44u0__p7_1,
  132132. 1, -523010048, 1618608128, 4, 0,
  132133. _vq_quantlist__44u0__p7_1,
  132134. NULL,
  132135. &_vq_auxt__44u0__p7_1,
  132136. NULL,
  132137. 0
  132138. };
  132139. static long _vq_quantlist__44u0__p7_2[] = {
  132140. 6,
  132141. 5,
  132142. 7,
  132143. 4,
  132144. 8,
  132145. 3,
  132146. 9,
  132147. 2,
  132148. 10,
  132149. 1,
  132150. 11,
  132151. 0,
  132152. 12,
  132153. };
  132154. static long _vq_lengthlist__44u0__p7_2[] = {
  132155. 2, 5, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 5, 5, 6,
  132156. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 5, 6, 5, 7, 7, 8,
  132157. 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8, 8, 8, 8, 9, 8,
  132158. 9, 9, 9, 9, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  132159. 9, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 7, 8,
  132160. 8, 9, 8, 9, 8, 9, 9, 9, 9, 9, 9, 8, 9, 8, 9, 9,
  132161. 9, 9, 9, 9, 9, 9,10,10, 8, 8, 9, 9, 9, 9, 9, 9,
  132162. 9, 9,10, 9,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132163. 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132164. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,
  132165. 9, 9, 9,10, 9, 9,10,10, 9,
  132166. };
  132167. static float _vq_quantthresh__44u0__p7_2[] = {
  132168. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  132169. 2.5, 3.5, 4.5, 5.5,
  132170. };
  132171. static long _vq_quantmap__44u0__p7_2[] = {
  132172. 11, 9, 7, 5, 3, 1, 0, 2,
  132173. 4, 6, 8, 10, 12,
  132174. };
  132175. static encode_aux_threshmatch _vq_auxt__44u0__p7_2 = {
  132176. _vq_quantthresh__44u0__p7_2,
  132177. _vq_quantmap__44u0__p7_2,
  132178. 13,
  132179. 13
  132180. };
  132181. static static_codebook _44u0__p7_2 = {
  132182. 2, 169,
  132183. _vq_lengthlist__44u0__p7_2,
  132184. 1, -531103744, 1611661312, 4, 0,
  132185. _vq_quantlist__44u0__p7_2,
  132186. NULL,
  132187. &_vq_auxt__44u0__p7_2,
  132188. NULL,
  132189. 0
  132190. };
  132191. static long _huff_lengthlist__44u0__short[] = {
  132192. 12,13,14,13,17,12,15,17, 5, 5, 6,10,10,11,15,16,
  132193. 4, 3, 3, 7, 5, 7,10,16, 7, 7, 7,10, 9,11,12,16,
  132194. 6, 5, 5, 9, 5, 6,10,16, 8, 7, 7, 9, 6, 7, 9,16,
  132195. 11, 7, 3, 6, 4, 5, 8,16,12, 9, 4, 8, 5, 7, 9,16,
  132196. };
  132197. static static_codebook _huff_book__44u0__short = {
  132198. 2, 64,
  132199. _huff_lengthlist__44u0__short,
  132200. 0, 0, 0, 0, 0,
  132201. NULL,
  132202. NULL,
  132203. NULL,
  132204. NULL,
  132205. 0
  132206. };
  132207. static long _huff_lengthlist__44u1__long[] = {
  132208. 5, 8,13,10,17,11,11,15, 7, 2, 4, 5, 8, 7, 9,16,
  132209. 13, 4, 3, 5, 6, 8,11,20,10, 4, 5, 5, 7, 6, 8,18,
  132210. 15, 7, 6, 7, 8,10,14,20,10, 6, 7, 6, 9, 7, 8,17,
  132211. 9, 8,10, 8,10, 5, 4,11,12,17,19,14,16,10, 7,12,
  132212. };
  132213. static static_codebook _huff_book__44u1__long = {
  132214. 2, 64,
  132215. _huff_lengthlist__44u1__long,
  132216. 0, 0, 0, 0, 0,
  132217. NULL,
  132218. NULL,
  132219. NULL,
  132220. NULL,
  132221. 0
  132222. };
  132223. static long _vq_quantlist__44u1__p1_0[] = {
  132224. 1,
  132225. 0,
  132226. 2,
  132227. };
  132228. static long _vq_lengthlist__44u1__p1_0[] = {
  132229. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,11,11, 8,
  132230. 10,10, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  132231. 11, 8,11,11, 8,12,11,11,13,13,11,13,14, 7,11,11,
  132232. 10,13,12,11,13,14, 4, 8, 8, 8,11,11, 8,11,12, 8,
  132233. 11,11,11,13,13,10,12,13, 8,11,11,11,14,13,11,14,
  132234. 13,
  132235. };
  132236. static float _vq_quantthresh__44u1__p1_0[] = {
  132237. -0.5, 0.5,
  132238. };
  132239. static long _vq_quantmap__44u1__p1_0[] = {
  132240. 1, 0, 2,
  132241. };
  132242. static encode_aux_threshmatch _vq_auxt__44u1__p1_0 = {
  132243. _vq_quantthresh__44u1__p1_0,
  132244. _vq_quantmap__44u1__p1_0,
  132245. 3,
  132246. 3
  132247. };
  132248. static static_codebook _44u1__p1_0 = {
  132249. 4, 81,
  132250. _vq_lengthlist__44u1__p1_0,
  132251. 1, -535822336, 1611661312, 2, 0,
  132252. _vq_quantlist__44u1__p1_0,
  132253. NULL,
  132254. &_vq_auxt__44u1__p1_0,
  132255. NULL,
  132256. 0
  132257. };
  132258. static long _vq_quantlist__44u1__p2_0[] = {
  132259. 1,
  132260. 0,
  132261. 2,
  132262. };
  132263. static long _vq_lengthlist__44u1__p2_0[] = {
  132264. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 8, 6,
  132265. 8, 8, 5, 7, 7, 6, 8, 8, 7, 8, 8, 4, 7, 7, 7, 8,
  132266. 8, 7, 8, 8, 7, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  132267. 8,10, 8, 8,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 8, 6,
  132268. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  132269. 9,
  132270. };
  132271. static float _vq_quantthresh__44u1__p2_0[] = {
  132272. -0.5, 0.5,
  132273. };
  132274. static long _vq_quantmap__44u1__p2_0[] = {
  132275. 1, 0, 2,
  132276. };
  132277. static encode_aux_threshmatch _vq_auxt__44u1__p2_0 = {
  132278. _vq_quantthresh__44u1__p2_0,
  132279. _vq_quantmap__44u1__p2_0,
  132280. 3,
  132281. 3
  132282. };
  132283. static static_codebook _44u1__p2_0 = {
  132284. 4, 81,
  132285. _vq_lengthlist__44u1__p2_0,
  132286. 1, -535822336, 1611661312, 2, 0,
  132287. _vq_quantlist__44u1__p2_0,
  132288. NULL,
  132289. &_vq_auxt__44u1__p2_0,
  132290. NULL,
  132291. 0
  132292. };
  132293. static long _vq_quantlist__44u1__p3_0[] = {
  132294. 2,
  132295. 1,
  132296. 3,
  132297. 0,
  132298. 4,
  132299. };
  132300. static long _vq_lengthlist__44u1__p3_0[] = {
  132301. 1, 5, 5, 8, 8, 5, 8, 7, 9, 9, 5, 7, 8, 9, 9, 9,
  132302. 10, 9,12,12, 9, 9,10,12,12, 6, 8, 8,11,10, 8,10,
  132303. 10,11,11, 8, 9,10,11,11,10,11,11,14,13,10,11,11,
  132304. 13,13, 5, 8, 8,10,10, 8,10,10,11,11, 8,10,10,11,
  132305. 11,10,11,11,13,13,10,11,11,13,13, 9,11,11,15,14,
  132306. 10,12,12,15,14,10,12,11,15,14,13,14,14,16,16,12,
  132307. 14,13,17,15, 9,11,11,14,15,10,11,12,14,16,10,11,
  132308. 12,14,16,12,13,14,16,16,13,13,15,15,18, 5, 8, 8,
  132309. 11,11, 8,10,10,12,12, 8,10,10,12,13,11,12,12,14,
  132310. 14,11,12,12,15,15, 8,10,10,13,13,10,12,12,13,13,
  132311. 10,12,12,14,14,12,13,13,15,15,12,13,13,16,16, 7,
  132312. 10,10,12,12,10,12,11,13,13,10,12,12,13,14,12,13,
  132313. 12,15,14,12,13,13,16,16,10,12,12,17,16,12,13,13,
  132314. 16,15,11,13,13,17,17,15,15,15,16,17,14,15,15,19,
  132315. 19,10,12,12,15,16,11,13,12,15,18,11,13,13,16,16,
  132316. 14,15,15,17,17,14,15,15,17,19, 5, 8, 8,11,11, 8,
  132317. 10,10,12,12, 8,10,10,12,12,11,12,12,16,15,11,12,
  132318. 12,14,15, 7,10,10,13,13,10,12,12,14,13,10,11,12,
  132319. 13,13,12,13,13,16,16,12,12,13,15,15, 8,10,10,13,
  132320. 13,10,12,12,14,14,10,12,12,13,13,12,13,13,16,16,
  132321. 12,13,13,15,15,10,12,12,16,15,11,13,13,17,16,11,
  132322. 12,13,16,15,13,15,15,19,17,14,15,14,17,16,10,12,
  132323. 12,16,16,11,13,13,16,17,12,13,13,15,17,14,15,15,
  132324. 17,19,14,15,15,17,17, 8,11,11,16,16,10,13,12,17,
  132325. 17,10,12,13,16,16,15,17,16,20,19,14,15,17,18,19,
  132326. 9,12,12,16,17,11,13,14,17,18,11,13,13,19,18,16,
  132327. 17,18,19,19,15,16,16,19,19, 9,12,12,16,17,11,14,
  132328. 13,18,17,11,13,13,17,17,16,17,16,20,19,14,16,16,
  132329. 18,18,12,15,15,19,17,14,15,16, 0,20,13,15,16,20,
  132330. 17,18,16,20, 0, 0,15,16,19,20, 0,12,15,14,18,19,
  132331. 13,16,15,20,19,13,16,15,20,18,17,18,17, 0,20,16,
  132332. 17,16, 0, 0, 8,11,11,16,15,10,12,12,17,17,10,13,
  132333. 13,17,16,14,16,15,18,20,15,16,16,19,19, 9,12,12,
  132334. 16,16,11,13,13,17,16,11,13,14,17,18,15,15,16,20,
  132335. 20,16,16,17,19,19, 9,13,12,16,17,11,14,13,17,17,
  132336. 11,14,14,18,17,14,16,15,18,19,16,17,18,18,19,12,
  132337. 14,15,19,18,13,15,16,18, 0,13,14,15, 0, 0,16,16,
  132338. 17,20, 0,17,17,20,20, 0,12,15,15,19,20,13,15,15,
  132339. 0, 0,14,16,15, 0, 0,15,18,16, 0, 0,17,18,16, 0,
  132340. 19,
  132341. };
  132342. static float _vq_quantthresh__44u1__p3_0[] = {
  132343. -1.5, -0.5, 0.5, 1.5,
  132344. };
  132345. static long _vq_quantmap__44u1__p3_0[] = {
  132346. 3, 1, 0, 2, 4,
  132347. };
  132348. static encode_aux_threshmatch _vq_auxt__44u1__p3_0 = {
  132349. _vq_quantthresh__44u1__p3_0,
  132350. _vq_quantmap__44u1__p3_0,
  132351. 5,
  132352. 5
  132353. };
  132354. static static_codebook _44u1__p3_0 = {
  132355. 4, 625,
  132356. _vq_lengthlist__44u1__p3_0,
  132357. 1, -533725184, 1611661312, 3, 0,
  132358. _vq_quantlist__44u1__p3_0,
  132359. NULL,
  132360. &_vq_auxt__44u1__p3_0,
  132361. NULL,
  132362. 0
  132363. };
  132364. static long _vq_quantlist__44u1__p4_0[] = {
  132365. 2,
  132366. 1,
  132367. 3,
  132368. 0,
  132369. 4,
  132370. };
  132371. static long _vq_lengthlist__44u1__p4_0[] = {
  132372. 4, 5, 5, 9, 9, 5, 6, 6, 9, 9, 5, 6, 6, 9, 9, 9,
  132373. 10, 9,12,12, 9, 9,10,12,12, 5, 7, 7,10,10, 7, 7,
  132374. 8,10,10, 6, 7, 8,10,10,10,10,10,11,13,10, 9,10,
  132375. 12,13, 5, 7, 7,10,10, 6, 8, 7,10,10, 7, 8, 7,10,
  132376. 10, 9,10,10,12,12,10,10,10,13,11, 9,10,10,13,13,
  132377. 10,11,10,13,13,10,10,10,13,13,12,12,13,14,14,12,
  132378. 12,13,14,14, 9,10,10,13,13,10,10,10,13,13,10,10,
  132379. 10,13,13,12,13,12,15,14,12,13,12,15,15, 5, 7, 6,
  132380. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,13,
  132381. 13,10,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,10,11,
  132382. 8, 9, 9,11,11,11,10,11,11,14,11,11,11,13,13, 6,
  132383. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  132384. 10,14,11,10,11,11,13,13,10,11,11,14,13,10,10,11,
  132385. 14,13,10,11,11,14,14,12,11,13,12,16,13,14,14,15,
  132386. 15,10,10,11,13,14,10,11,10,14,13,10,11,11,14,14,
  132387. 12,13,12,15,13,13,13,14,15,16, 5, 7, 7,10,10, 7,
  132388. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,13,13,10,10,
  132389. 11,12,13, 6, 8, 8,11,10, 8, 9, 9,11,11, 7, 8, 9,
  132390. 10,11,10,11,11,13,13,10,10,11,11,13, 6, 8, 8,10,
  132391. 11, 8, 9, 9,11,11, 8, 9, 8,12,10,10,11,11,13,13,
  132392. 10,11,10,14,11,10,10,10,14,13,10,11,11,14,13,10,
  132393. 10,11,13,13,12,14,14,16,16,12,12,13,13,15,10,11,
  132394. 11,13,14,10,11,11,14,15,10,11,10,13,13,13,14,13,
  132395. 16,16,12,13,11,15,12, 9,10,10,13,13,10,11,11,14,
  132396. 13,10,10,11,13,14,13,14,13,16,16,13,13,13,15,16,
  132397. 9,10,10,13,13,10,10,11,13,14,10,11,11,15,13,13,
  132398. 13,14,14,18,13,13,14,16,15, 9,10,10,13,14,10,11,
  132399. 10,14,13,10,11,11,13,14,13,14,13,16,15,13,13,14,
  132400. 15,16,12,13,12,16,14,11,11,13,15,15,13,14,13,16,
  132401. 15,15,12,16,12,17,14,15,15,17,17,12,13,13,14,16,
  132402. 11,13,11,16,15,12,13,14,15,16,14,15,13, 0,14,14,
  132403. 16,16, 0, 0, 9,10,10,13,13,10,11,10,14,14,10,11,
  132404. 11,13,13,12,13,13,14,16,13,14,14,16,16, 9,10,10,
  132405. 14,14,11,11,11,14,13,10,10,11,14,14,13,13,13,16,
  132406. 16,13,13,14,14,17, 9,10,10,13,14,10,11,11,13,15,
  132407. 10,11,10,14,14,13,13,13,14,17,13,14,13,17,14,12,
  132408. 13,13,16,14,13,14,13,16,15,12,12,13,15,16,15,15,
  132409. 16,18,16,15,13,15,14, 0,12,12,13,14,16,13,13,14,
  132410. 15,16,11,12,11,16,14,15,16,16,17,17,14,15,12,17,
  132411. 12,
  132412. };
  132413. static float _vq_quantthresh__44u1__p4_0[] = {
  132414. -1.5, -0.5, 0.5, 1.5,
  132415. };
  132416. static long _vq_quantmap__44u1__p4_0[] = {
  132417. 3, 1, 0, 2, 4,
  132418. };
  132419. static encode_aux_threshmatch _vq_auxt__44u1__p4_0 = {
  132420. _vq_quantthresh__44u1__p4_0,
  132421. _vq_quantmap__44u1__p4_0,
  132422. 5,
  132423. 5
  132424. };
  132425. static static_codebook _44u1__p4_0 = {
  132426. 4, 625,
  132427. _vq_lengthlist__44u1__p4_0,
  132428. 1, -533725184, 1611661312, 3, 0,
  132429. _vq_quantlist__44u1__p4_0,
  132430. NULL,
  132431. &_vq_auxt__44u1__p4_0,
  132432. NULL,
  132433. 0
  132434. };
  132435. static long _vq_quantlist__44u1__p5_0[] = {
  132436. 4,
  132437. 3,
  132438. 5,
  132439. 2,
  132440. 6,
  132441. 1,
  132442. 7,
  132443. 0,
  132444. 8,
  132445. };
  132446. static long _vq_lengthlist__44u1__p5_0[] = {
  132447. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  132448. 9, 9, 4, 6, 6, 8, 8, 8, 8, 9, 9, 7, 8, 8, 9, 9,
  132449. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,10, 7, 8, 8,
  132450. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  132451. 9, 9,10,10,11,11,12,12, 9, 9, 9,10,11,11,11,12,
  132452. 12,
  132453. };
  132454. static float _vq_quantthresh__44u1__p5_0[] = {
  132455. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  132456. };
  132457. static long _vq_quantmap__44u1__p5_0[] = {
  132458. 7, 5, 3, 1, 0, 2, 4, 6,
  132459. 8,
  132460. };
  132461. static encode_aux_threshmatch _vq_auxt__44u1__p5_0 = {
  132462. _vq_quantthresh__44u1__p5_0,
  132463. _vq_quantmap__44u1__p5_0,
  132464. 9,
  132465. 9
  132466. };
  132467. static static_codebook _44u1__p5_0 = {
  132468. 2, 81,
  132469. _vq_lengthlist__44u1__p5_0,
  132470. 1, -531628032, 1611661312, 4, 0,
  132471. _vq_quantlist__44u1__p5_0,
  132472. NULL,
  132473. &_vq_auxt__44u1__p5_0,
  132474. NULL,
  132475. 0
  132476. };
  132477. static long _vq_quantlist__44u1__p6_0[] = {
  132478. 6,
  132479. 5,
  132480. 7,
  132481. 4,
  132482. 8,
  132483. 3,
  132484. 9,
  132485. 2,
  132486. 10,
  132487. 1,
  132488. 11,
  132489. 0,
  132490. 12,
  132491. };
  132492. static long _vq_lengthlist__44u1__p6_0[] = {
  132493. 1, 4, 4, 6, 6, 8, 8,10, 9,11,10,14,13, 4, 6, 5,
  132494. 8, 8, 9, 9,11,10,11,11,14,14, 4, 5, 6, 8, 8, 9,
  132495. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  132496. 12,12,16,15, 7, 8, 8, 9, 9,10,10,11,11,12,12,15,
  132497. 15, 9,10,10,10,10,11,11,12,12,12,12,15,15, 9,10,
  132498. 9,10,11,11,11,12,12,12,13,15,15,10,10,11,11,11,
  132499. 12,12,13,12,13,13,16,15,10,11,11,11,11,12,12,13,
  132500. 12,13,13,16,17,11,11,12,12,12,13,13,13,14,14,15,
  132501. 17,17,11,11,12,12,12,13,13,13,14,14,14,16,18,14,
  132502. 15,15,15,15,16,16,16,16,17,18, 0, 0,14,15,15,15,
  132503. 15,17,16,17,18,17,17,18, 0,
  132504. };
  132505. static float _vq_quantthresh__44u1__p6_0[] = {
  132506. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  132507. 12.5, 17.5, 22.5, 27.5,
  132508. };
  132509. static long _vq_quantmap__44u1__p6_0[] = {
  132510. 11, 9, 7, 5, 3, 1, 0, 2,
  132511. 4, 6, 8, 10, 12,
  132512. };
  132513. static encode_aux_threshmatch _vq_auxt__44u1__p6_0 = {
  132514. _vq_quantthresh__44u1__p6_0,
  132515. _vq_quantmap__44u1__p6_0,
  132516. 13,
  132517. 13
  132518. };
  132519. static static_codebook _44u1__p6_0 = {
  132520. 2, 169,
  132521. _vq_lengthlist__44u1__p6_0,
  132522. 1, -526516224, 1616117760, 4, 0,
  132523. _vq_quantlist__44u1__p6_0,
  132524. NULL,
  132525. &_vq_auxt__44u1__p6_0,
  132526. NULL,
  132527. 0
  132528. };
  132529. static long _vq_quantlist__44u1__p6_1[] = {
  132530. 2,
  132531. 1,
  132532. 3,
  132533. 0,
  132534. 4,
  132535. };
  132536. static long _vq_lengthlist__44u1__p6_1[] = {
  132537. 2, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5,
  132538. 6, 6, 6, 6, 5, 6, 6, 6, 6,
  132539. };
  132540. static float _vq_quantthresh__44u1__p6_1[] = {
  132541. -1.5, -0.5, 0.5, 1.5,
  132542. };
  132543. static long _vq_quantmap__44u1__p6_1[] = {
  132544. 3, 1, 0, 2, 4,
  132545. };
  132546. static encode_aux_threshmatch _vq_auxt__44u1__p6_1 = {
  132547. _vq_quantthresh__44u1__p6_1,
  132548. _vq_quantmap__44u1__p6_1,
  132549. 5,
  132550. 5
  132551. };
  132552. static static_codebook _44u1__p6_1 = {
  132553. 2, 25,
  132554. _vq_lengthlist__44u1__p6_1,
  132555. 1, -533725184, 1611661312, 3, 0,
  132556. _vq_quantlist__44u1__p6_1,
  132557. NULL,
  132558. &_vq_auxt__44u1__p6_1,
  132559. NULL,
  132560. 0
  132561. };
  132562. static long _vq_quantlist__44u1__p7_0[] = {
  132563. 3,
  132564. 2,
  132565. 4,
  132566. 1,
  132567. 5,
  132568. 0,
  132569. 6,
  132570. };
  132571. static long _vq_lengthlist__44u1__p7_0[] = {
  132572. 1, 3, 2, 9, 9, 7, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132573. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132574. 9, 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  132575. 8,
  132576. };
  132577. static float _vq_quantthresh__44u1__p7_0[] = {
  132578. -422.5, -253.5, -84.5, 84.5, 253.5, 422.5,
  132579. };
  132580. static long _vq_quantmap__44u1__p7_0[] = {
  132581. 5, 3, 1, 0, 2, 4, 6,
  132582. };
  132583. static encode_aux_threshmatch _vq_auxt__44u1__p7_0 = {
  132584. _vq_quantthresh__44u1__p7_0,
  132585. _vq_quantmap__44u1__p7_0,
  132586. 7,
  132587. 7
  132588. };
  132589. static static_codebook _44u1__p7_0 = {
  132590. 2, 49,
  132591. _vq_lengthlist__44u1__p7_0,
  132592. 1, -518017024, 1626677248, 3, 0,
  132593. _vq_quantlist__44u1__p7_0,
  132594. NULL,
  132595. &_vq_auxt__44u1__p7_0,
  132596. NULL,
  132597. 0
  132598. };
  132599. static long _vq_quantlist__44u1__p7_1[] = {
  132600. 6,
  132601. 5,
  132602. 7,
  132603. 4,
  132604. 8,
  132605. 3,
  132606. 9,
  132607. 2,
  132608. 10,
  132609. 1,
  132610. 11,
  132611. 0,
  132612. 12,
  132613. };
  132614. static long _vq_lengthlist__44u1__p7_1[] = {
  132615. 1, 4, 4, 6, 6, 6, 6, 7, 7, 8, 8, 9, 9, 5, 7, 7,
  132616. 8, 7, 7, 7, 9, 8,10, 9,10,11, 5, 7, 7, 8, 8, 7,
  132617. 7, 8, 9,10,10,11,11, 6, 8, 8, 9, 9, 9, 9,11,10,
  132618. 12,12,15,12, 6, 8, 8, 9, 9, 9, 9,11,11,12,11,14,
  132619. 12, 7, 8, 8,10,10,12,12,13,13,13,15,13,13, 7, 8,
  132620. 8,10,10,11,11,13,12,14,15,15,15, 9,10,10,11,12,
  132621. 13,13,14,15,14,15,14,15, 8,10,10,12,12,14,14,15,
  132622. 14,14,15,15,14,10,12,12,14,14,15,14,15,15,15,14,
  132623. 15,15,10,12,12,13,14,15,14,15,15,14,15,15,15,12,
  132624. 15,13,15,14,15,15,15,15,15,15,15,15,13,13,15,15,
  132625. 15,15,15,15,15,15,15,15,15,
  132626. };
  132627. static float _vq_quantthresh__44u1__p7_1[] = {
  132628. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  132629. 32.5, 45.5, 58.5, 71.5,
  132630. };
  132631. static long _vq_quantmap__44u1__p7_1[] = {
  132632. 11, 9, 7, 5, 3, 1, 0, 2,
  132633. 4, 6, 8, 10, 12,
  132634. };
  132635. static encode_aux_threshmatch _vq_auxt__44u1__p7_1 = {
  132636. _vq_quantthresh__44u1__p7_1,
  132637. _vq_quantmap__44u1__p7_1,
  132638. 13,
  132639. 13
  132640. };
  132641. static static_codebook _44u1__p7_1 = {
  132642. 2, 169,
  132643. _vq_lengthlist__44u1__p7_1,
  132644. 1, -523010048, 1618608128, 4, 0,
  132645. _vq_quantlist__44u1__p7_1,
  132646. NULL,
  132647. &_vq_auxt__44u1__p7_1,
  132648. NULL,
  132649. 0
  132650. };
  132651. static long _vq_quantlist__44u1__p7_2[] = {
  132652. 6,
  132653. 5,
  132654. 7,
  132655. 4,
  132656. 8,
  132657. 3,
  132658. 9,
  132659. 2,
  132660. 10,
  132661. 1,
  132662. 11,
  132663. 0,
  132664. 12,
  132665. };
  132666. static long _vq_lengthlist__44u1__p7_2[] = {
  132667. 2, 5, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 5, 5, 6,
  132668. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 5, 6, 5, 7, 7, 8,
  132669. 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8, 8, 8, 8, 9, 8,
  132670. 9, 9, 9, 9, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  132671. 9, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 7, 8,
  132672. 8, 9, 8, 9, 8, 9, 9, 9, 9, 9, 9, 8, 9, 8, 9, 9,
  132673. 9, 9, 9, 9, 9, 9,10,10, 8, 8, 9, 9, 9, 9, 9, 9,
  132674. 9, 9,10, 9,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132675. 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132676. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,
  132677. 9, 9, 9,10, 9, 9,10,10, 9,
  132678. };
  132679. static float _vq_quantthresh__44u1__p7_2[] = {
  132680. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  132681. 2.5, 3.5, 4.5, 5.5,
  132682. };
  132683. static long _vq_quantmap__44u1__p7_2[] = {
  132684. 11, 9, 7, 5, 3, 1, 0, 2,
  132685. 4, 6, 8, 10, 12,
  132686. };
  132687. static encode_aux_threshmatch _vq_auxt__44u1__p7_2 = {
  132688. _vq_quantthresh__44u1__p7_2,
  132689. _vq_quantmap__44u1__p7_2,
  132690. 13,
  132691. 13
  132692. };
  132693. static static_codebook _44u1__p7_2 = {
  132694. 2, 169,
  132695. _vq_lengthlist__44u1__p7_2,
  132696. 1, -531103744, 1611661312, 4, 0,
  132697. _vq_quantlist__44u1__p7_2,
  132698. NULL,
  132699. &_vq_auxt__44u1__p7_2,
  132700. NULL,
  132701. 0
  132702. };
  132703. static long _huff_lengthlist__44u1__short[] = {
  132704. 12,13,14,13,17,12,15,17, 5, 5, 6,10,10,11,15,16,
  132705. 4, 3, 3, 7, 5, 7,10,16, 7, 7, 7,10, 9,11,12,16,
  132706. 6, 5, 5, 9, 5, 6,10,16, 8, 7, 7, 9, 6, 7, 9,16,
  132707. 11, 7, 3, 6, 4, 5, 8,16,12, 9, 4, 8, 5, 7, 9,16,
  132708. };
  132709. static static_codebook _huff_book__44u1__short = {
  132710. 2, 64,
  132711. _huff_lengthlist__44u1__short,
  132712. 0, 0, 0, 0, 0,
  132713. NULL,
  132714. NULL,
  132715. NULL,
  132716. NULL,
  132717. 0
  132718. };
  132719. static long _huff_lengthlist__44u2__long[] = {
  132720. 5, 9,14,12,15,13,10,13, 7, 4, 5, 6, 8, 7, 8,12,
  132721. 13, 4, 3, 5, 5, 6, 9,15,12, 6, 5, 6, 6, 6, 7,14,
  132722. 14, 7, 4, 6, 4, 6, 8,15,12, 6, 6, 5, 5, 5, 6,14,
  132723. 9, 7, 8, 6, 7, 5, 4,10,10,13,14,14,15,10, 6, 8,
  132724. };
  132725. static static_codebook _huff_book__44u2__long = {
  132726. 2, 64,
  132727. _huff_lengthlist__44u2__long,
  132728. 0, 0, 0, 0, 0,
  132729. NULL,
  132730. NULL,
  132731. NULL,
  132732. NULL,
  132733. 0
  132734. };
  132735. static long _vq_quantlist__44u2__p1_0[] = {
  132736. 1,
  132737. 0,
  132738. 2,
  132739. };
  132740. static long _vq_lengthlist__44u2__p1_0[] = {
  132741. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,11,11, 8,
  132742. 10,11, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  132743. 11, 8,11,11, 8,11,11,11,13,14,11,13,13, 7,11,11,
  132744. 10,13,12,11,14,14, 4, 8, 8, 8,11,11, 8,11,11, 8,
  132745. 11,11,11,14,13,10,12,13, 8,11,11,11,13,13,11,13,
  132746. 13,
  132747. };
  132748. static float _vq_quantthresh__44u2__p1_0[] = {
  132749. -0.5, 0.5,
  132750. };
  132751. static long _vq_quantmap__44u2__p1_0[] = {
  132752. 1, 0, 2,
  132753. };
  132754. static encode_aux_threshmatch _vq_auxt__44u2__p1_0 = {
  132755. _vq_quantthresh__44u2__p1_0,
  132756. _vq_quantmap__44u2__p1_0,
  132757. 3,
  132758. 3
  132759. };
  132760. static static_codebook _44u2__p1_0 = {
  132761. 4, 81,
  132762. _vq_lengthlist__44u2__p1_0,
  132763. 1, -535822336, 1611661312, 2, 0,
  132764. _vq_quantlist__44u2__p1_0,
  132765. NULL,
  132766. &_vq_auxt__44u2__p1_0,
  132767. NULL,
  132768. 0
  132769. };
  132770. static long _vq_quantlist__44u2__p2_0[] = {
  132771. 1,
  132772. 0,
  132773. 2,
  132774. };
  132775. static long _vq_lengthlist__44u2__p2_0[] = {
  132776. 2, 5, 5, 5, 6, 6, 5, 6, 6, 5, 6, 6, 7, 8, 8, 6,
  132777. 8, 8, 5, 6, 6, 6, 8, 7, 7, 8, 8, 5, 6, 6, 7, 8,
  132778. 8, 6, 8, 8, 6, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  132779. 7,10, 8, 8,10,10, 5, 6, 6, 6, 8, 8, 7, 8, 8, 6,
  132780. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  132781. 9,
  132782. };
  132783. static float _vq_quantthresh__44u2__p2_0[] = {
  132784. -0.5, 0.5,
  132785. };
  132786. static long _vq_quantmap__44u2__p2_0[] = {
  132787. 1, 0, 2,
  132788. };
  132789. static encode_aux_threshmatch _vq_auxt__44u2__p2_0 = {
  132790. _vq_quantthresh__44u2__p2_0,
  132791. _vq_quantmap__44u2__p2_0,
  132792. 3,
  132793. 3
  132794. };
  132795. static static_codebook _44u2__p2_0 = {
  132796. 4, 81,
  132797. _vq_lengthlist__44u2__p2_0,
  132798. 1, -535822336, 1611661312, 2, 0,
  132799. _vq_quantlist__44u2__p2_0,
  132800. NULL,
  132801. &_vq_auxt__44u2__p2_0,
  132802. NULL,
  132803. 0
  132804. };
  132805. static long _vq_quantlist__44u2__p3_0[] = {
  132806. 2,
  132807. 1,
  132808. 3,
  132809. 0,
  132810. 4,
  132811. };
  132812. static long _vq_lengthlist__44u2__p3_0[] = {
  132813. 2, 4, 4, 7, 8, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 8,
  132814. 9, 9,12,11, 8, 9, 9,11,12, 5, 7, 7,10,10, 7, 9,
  132815. 9,11,11, 7, 9, 9,10,11,10,11,11,13,13, 9,10,11,
  132816. 12,13, 5, 7, 7,10,10, 7, 9, 9,11,10, 7, 9, 9,11,
  132817. 11, 9,11,10,13,13,10,11,11,13,13, 8,10,10,14,13,
  132818. 10,11,11,15,14, 9,11,11,15,14,13,14,13,16,14,12,
  132819. 13,13,15,16, 8,10,10,13,14, 9,11,11,14,15,10,11,
  132820. 11,14,15,12,13,13,15,15,12,13,14,15,16, 5, 7, 7,
  132821. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,12,10,11,11,14,
  132822. 13,10,11,11,14,14, 7, 9, 9,12,12, 9,11,11,13,13,
  132823. 9,11,11,13,13,12,13,12,14,14,11,12,13,15,15, 7,
  132824. 9, 9,12,12, 8,11,10,13,12, 9,11,11,13,13,11,13,
  132825. 12,15,13,11,13,13,15,16, 9,12,11,15,15,11,12,12,
  132826. 16,15,11,12,13,16,16,13,14,15,16,15,13,15,15,17,
  132827. 17, 9,11,11,14,15,10,12,12,15,15,11,13,12,15,16,
  132828. 13,15,14,16,16,13,15,15,17,19, 5, 7, 7,10,10, 7,
  132829. 9, 9,12,11, 7, 9, 9,11,11,10,11,11,14,14,10,11,
  132830. 11,13,14, 7, 9, 9,12,12, 9,11,11,13,13, 9,10,11,
  132831. 12,13,11,13,12,16,15,11,12,12,14,15, 7, 9, 9,12,
  132832. 12, 9,11,11,13,13, 9,11,11,13,12,11,13,12,15,16,
  132833. 12,13,13,15,14, 9,11,11,15,14,11,13,12,16,15,10,
  132834. 11,12,15,15,13,14,14,18,17,13,14,14,15,17,10,11,
  132835. 11,14,15,11,13,12,15,17,11,13,12,15,16,13,15,14,
  132836. 18,17,14,15,15,16,18, 7,10,10,14,14,10,12,12,15,
  132837. 15,10,12,12,15,15,14,15,15,18,17,13,15,15,16,16,
  132838. 9,11,11,16,15,11,13,13,16,18,11,13,13,16,16,15,
  132839. 16,16, 0, 0,14,15,16,18,17, 9,11,11,15,15,10,13,
  132840. 12,17,16,11,12,13,16,17,14,15,16,19,19,14,15,15,
  132841. 0,20,12,14,14, 0, 0,13,14,16,19,18,13,15,16,20,
  132842. 17,16,18, 0, 0, 0,15,16,17,18,19,11,14,14, 0,19,
  132843. 12,15,14,17,17,13,15,15, 0, 0,16,17,15,20,19,15,
  132844. 17,16,19, 0, 8,10,10,14,15,10,12,11,15,15,10,11,
  132845. 12,16,15,13,14,14,19,17,14,15,15, 0, 0, 9,11,11,
  132846. 16,15,11,13,13,17,16,10,12,13,16,17,14,15,15,18,
  132847. 18,14,15,16,20,19, 9,12,12, 0,15,11,13,13,16,17,
  132848. 11,13,13,19,17,14,16,16,18,17,15,16,16,17,19,11,
  132849. 14,14,18,18,13,14,15, 0, 0,12,14,15,19,18,15,16,
  132850. 19, 0,19,15,16,19,19,17,12,14,14,16,19,13,15,15,
  132851. 0,17,13,15,14,18,18,15,16,15, 0,18,16,17,17, 0,
  132852. 0,
  132853. };
  132854. static float _vq_quantthresh__44u2__p3_0[] = {
  132855. -1.5, -0.5, 0.5, 1.5,
  132856. };
  132857. static long _vq_quantmap__44u2__p3_0[] = {
  132858. 3, 1, 0, 2, 4,
  132859. };
  132860. static encode_aux_threshmatch _vq_auxt__44u2__p3_0 = {
  132861. _vq_quantthresh__44u2__p3_0,
  132862. _vq_quantmap__44u2__p3_0,
  132863. 5,
  132864. 5
  132865. };
  132866. static static_codebook _44u2__p3_0 = {
  132867. 4, 625,
  132868. _vq_lengthlist__44u2__p3_0,
  132869. 1, -533725184, 1611661312, 3, 0,
  132870. _vq_quantlist__44u2__p3_0,
  132871. NULL,
  132872. &_vq_auxt__44u2__p3_0,
  132873. NULL,
  132874. 0
  132875. };
  132876. static long _vq_quantlist__44u2__p4_0[] = {
  132877. 2,
  132878. 1,
  132879. 3,
  132880. 0,
  132881. 4,
  132882. };
  132883. static long _vq_lengthlist__44u2__p4_0[] = {
  132884. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 9,
  132885. 9, 9,11,11, 9, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  132886. 8,10,10, 7, 7, 8,10,10,10,10,10,11,12, 9,10,10,
  132887. 11,12, 5, 7, 7, 9, 9, 6, 8, 7,10,10, 7, 8, 8,10,
  132888. 10, 9,10,10,12,11, 9,10,10,12,11, 9,10,10,12,12,
  132889. 10,10,10,13,12, 9,10,10,12,13,12,12,12,14,14,11,
  132890. 12,12,13,14, 9,10,10,12,12, 9,10,10,12,13,10,10,
  132891. 10,12,13,11,12,12,14,13,12,12,12,14,13, 5, 7, 7,
  132892. 10, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,
  132893. 12,10,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,11,11,
  132894. 8, 9, 9,11,11,10,11,11,12,13,10,11,11,13,13, 6,
  132895. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  132896. 10,13,11,10,11,11,13,13, 9,10,10,13,13,10,11,11,
  132897. 13,13,10,11,11,14,13,12,11,13,12,15,12,13,13,15,
  132898. 15, 9,10,10,12,13,10,11,10,13,13,10,11,11,13,13,
  132899. 12,13,11,15,13,12,13,13,15,15, 5, 7, 7, 9,10, 7,
  132900. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,12,10,10,
  132901. 11,12,12, 6, 8, 8,10,10, 8, 9, 9,11,11, 7, 8, 9,
  132902. 10,11,10,11,11,13,13,10,10,11,11,13, 7, 8, 8,10,
  132903. 11, 8, 9, 9,11,11, 8, 9, 8,11,11,10,11,11,13,13,
  132904. 10,11,11,13,12, 9,10,10,13,12,10,11,11,14,13,10,
  132905. 10,11,13,13,12,13,13,15,15,12,11,13,12,14, 9,10,
  132906. 10,12,13,10,11,11,13,14,10,11,11,13,13,12,13,13,
  132907. 15,15,12,13,12,15,12, 8, 9, 9,12,12, 9,11,10,13,
  132908. 13, 9,10,10,13,13,12,13,13,15,15,12,12,12,14,14,
  132909. 9,10,10,13,13,10,11,11,13,14,10,11,11,14,12,13,
  132910. 13,14,14,16,12,13,13,15,14, 9,10,10,13,13,10,11,
  132911. 10,14,13,10,11,11,13,14,12,14,13,16,14,13,13,13,
  132912. 14,15,11,13,12,15,14,11,12,13,14,15,12,13,13,16,
  132913. 15,14,12,15,12,16,14,15,15,17,16,11,12,12,14,15,
  132914. 11,13,11,15,14,12,13,13,15,16,13,15,12,17,13,14,
  132915. 15,15,16,16, 8, 9, 9,12,12, 9,10,10,13,13, 9,10,
  132916. 10,13,13,12,13,12,14,14,12,13,13,15,15, 9,10,10,
  132917. 13,13,10,11,11,14,13,10,10,11,13,14,12,13,13,15,
  132918. 14,12,12,14,14,16, 9,10,10,13,13,10,11,11,13,14,
  132919. 10,11,11,14,13,13,13,13,15,15,13,14,13,16,14,11,
  132920. 12,12,14,14,12,13,13,16,15,11,12,13,14,15,14,15,
  132921. 15,16,16,14,13,15,13,17,11,12,12,14,15,12,13,13,
  132922. 15,16,11,13,12,15,15,14,15,14,16,16,14,15,12,17,
  132923. 13,
  132924. };
  132925. static float _vq_quantthresh__44u2__p4_0[] = {
  132926. -1.5, -0.5, 0.5, 1.5,
  132927. };
  132928. static long _vq_quantmap__44u2__p4_0[] = {
  132929. 3, 1, 0, 2, 4,
  132930. };
  132931. static encode_aux_threshmatch _vq_auxt__44u2__p4_0 = {
  132932. _vq_quantthresh__44u2__p4_0,
  132933. _vq_quantmap__44u2__p4_0,
  132934. 5,
  132935. 5
  132936. };
  132937. static static_codebook _44u2__p4_0 = {
  132938. 4, 625,
  132939. _vq_lengthlist__44u2__p4_0,
  132940. 1, -533725184, 1611661312, 3, 0,
  132941. _vq_quantlist__44u2__p4_0,
  132942. NULL,
  132943. &_vq_auxt__44u2__p4_0,
  132944. NULL,
  132945. 0
  132946. };
  132947. static long _vq_quantlist__44u2__p5_0[] = {
  132948. 4,
  132949. 3,
  132950. 5,
  132951. 2,
  132952. 6,
  132953. 1,
  132954. 7,
  132955. 0,
  132956. 8,
  132957. };
  132958. static long _vq_lengthlist__44u2__p5_0[] = {
  132959. 1, 4, 4, 7, 7, 8, 8, 9, 9, 4, 6, 5, 8, 8, 8, 8,
  132960. 10,10, 4, 5, 6, 8, 8, 8, 8,10,10, 7, 8, 8, 9, 9,
  132961. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 8, 8, 8,
  132962. 9, 9,10,11,12,12, 8, 8, 8, 9, 9,10,10,12,12,10,
  132963. 10,10,11,11,12,12,13,13,10,10,10,11,11,12,12,13,
  132964. 13,
  132965. };
  132966. static float _vq_quantthresh__44u2__p5_0[] = {
  132967. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  132968. };
  132969. static long _vq_quantmap__44u2__p5_0[] = {
  132970. 7, 5, 3, 1, 0, 2, 4, 6,
  132971. 8,
  132972. };
  132973. static encode_aux_threshmatch _vq_auxt__44u2__p5_0 = {
  132974. _vq_quantthresh__44u2__p5_0,
  132975. _vq_quantmap__44u2__p5_0,
  132976. 9,
  132977. 9
  132978. };
  132979. static static_codebook _44u2__p5_0 = {
  132980. 2, 81,
  132981. _vq_lengthlist__44u2__p5_0,
  132982. 1, -531628032, 1611661312, 4, 0,
  132983. _vq_quantlist__44u2__p5_0,
  132984. NULL,
  132985. &_vq_auxt__44u2__p5_0,
  132986. NULL,
  132987. 0
  132988. };
  132989. static long _vq_quantlist__44u2__p6_0[] = {
  132990. 6,
  132991. 5,
  132992. 7,
  132993. 4,
  132994. 8,
  132995. 3,
  132996. 9,
  132997. 2,
  132998. 10,
  132999. 1,
  133000. 11,
  133001. 0,
  133002. 12,
  133003. };
  133004. static long _vq_lengthlist__44u2__p6_0[] = {
  133005. 1, 4, 4, 6, 6, 8, 8,10,10,11,11,14,13, 4, 6, 5,
  133006. 8, 8, 9, 9,11,10,12,11,15,14, 4, 5, 6, 8, 8, 9,
  133007. 9,11,11,11,11,14,14, 6, 8, 8,10, 9,11,11,11,11,
  133008. 12,12,15,15, 6, 8, 8, 9, 9,11,11,11,12,12,12,15,
  133009. 15, 8,10,10,11,11,11,11,12,12,13,13,15,16, 8,10,
  133010. 10,11,11,11,11,12,12,13,13,16,16,10,11,11,12,12,
  133011. 12,12,13,13,13,13,17,16,10,11,11,12,12,12,12,13,
  133012. 13,13,14,16,17,11,12,12,13,13,13,13,14,14,15,14,
  133013. 18,17,11,12,12,13,13,13,13,14,14,14,15,19,18,14,
  133014. 15,15,15,15,16,16,18,19,18,18, 0, 0,14,15,15,16,
  133015. 15,17,17,16,18,17,18, 0, 0,
  133016. };
  133017. static float _vq_quantthresh__44u2__p6_0[] = {
  133018. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  133019. 12.5, 17.5, 22.5, 27.5,
  133020. };
  133021. static long _vq_quantmap__44u2__p6_0[] = {
  133022. 11, 9, 7, 5, 3, 1, 0, 2,
  133023. 4, 6, 8, 10, 12,
  133024. };
  133025. static encode_aux_threshmatch _vq_auxt__44u2__p6_0 = {
  133026. _vq_quantthresh__44u2__p6_0,
  133027. _vq_quantmap__44u2__p6_0,
  133028. 13,
  133029. 13
  133030. };
  133031. static static_codebook _44u2__p6_0 = {
  133032. 2, 169,
  133033. _vq_lengthlist__44u2__p6_0,
  133034. 1, -526516224, 1616117760, 4, 0,
  133035. _vq_quantlist__44u2__p6_0,
  133036. NULL,
  133037. &_vq_auxt__44u2__p6_0,
  133038. NULL,
  133039. 0
  133040. };
  133041. static long _vq_quantlist__44u2__p6_1[] = {
  133042. 2,
  133043. 1,
  133044. 3,
  133045. 0,
  133046. 4,
  133047. };
  133048. static long _vq_lengthlist__44u2__p6_1[] = {
  133049. 2, 4, 4, 5, 5, 4, 5, 5, 6, 5, 4, 5, 5, 5, 6, 5,
  133050. 6, 5, 6, 6, 5, 5, 6, 6, 6,
  133051. };
  133052. static float _vq_quantthresh__44u2__p6_1[] = {
  133053. -1.5, -0.5, 0.5, 1.5,
  133054. };
  133055. static long _vq_quantmap__44u2__p6_1[] = {
  133056. 3, 1, 0, 2, 4,
  133057. };
  133058. static encode_aux_threshmatch _vq_auxt__44u2__p6_1 = {
  133059. _vq_quantthresh__44u2__p6_1,
  133060. _vq_quantmap__44u2__p6_1,
  133061. 5,
  133062. 5
  133063. };
  133064. static static_codebook _44u2__p6_1 = {
  133065. 2, 25,
  133066. _vq_lengthlist__44u2__p6_1,
  133067. 1, -533725184, 1611661312, 3, 0,
  133068. _vq_quantlist__44u2__p6_1,
  133069. NULL,
  133070. &_vq_auxt__44u2__p6_1,
  133071. NULL,
  133072. 0
  133073. };
  133074. static long _vq_quantlist__44u2__p7_0[] = {
  133075. 4,
  133076. 3,
  133077. 5,
  133078. 2,
  133079. 6,
  133080. 1,
  133081. 7,
  133082. 0,
  133083. 8,
  133084. };
  133085. static long _vq_lengthlist__44u2__p7_0[] = {
  133086. 1, 3, 2,12,12,12,12,12,12, 4,12,12,12,12,12,12,
  133087. 12,12, 5,12,12,12,12,12,12,12,12,12,12,11,11,11,
  133088. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133089. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133090. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133091. 11,
  133092. };
  133093. static float _vq_quantthresh__44u2__p7_0[] = {
  133094. -591.5, -422.5, -253.5, -84.5, 84.5, 253.5, 422.5, 591.5,
  133095. };
  133096. static long _vq_quantmap__44u2__p7_0[] = {
  133097. 7, 5, 3, 1, 0, 2, 4, 6,
  133098. 8,
  133099. };
  133100. static encode_aux_threshmatch _vq_auxt__44u2__p7_0 = {
  133101. _vq_quantthresh__44u2__p7_0,
  133102. _vq_quantmap__44u2__p7_0,
  133103. 9,
  133104. 9
  133105. };
  133106. static static_codebook _44u2__p7_0 = {
  133107. 2, 81,
  133108. _vq_lengthlist__44u2__p7_0,
  133109. 1, -516612096, 1626677248, 4, 0,
  133110. _vq_quantlist__44u2__p7_0,
  133111. NULL,
  133112. &_vq_auxt__44u2__p7_0,
  133113. NULL,
  133114. 0
  133115. };
  133116. static long _vq_quantlist__44u2__p7_1[] = {
  133117. 6,
  133118. 5,
  133119. 7,
  133120. 4,
  133121. 8,
  133122. 3,
  133123. 9,
  133124. 2,
  133125. 10,
  133126. 1,
  133127. 11,
  133128. 0,
  133129. 12,
  133130. };
  133131. static long _vq_lengthlist__44u2__p7_1[] = {
  133132. 1, 4, 4, 7, 6, 7, 6, 8, 7, 9, 7, 9, 8, 4, 7, 6,
  133133. 8, 8, 9, 8,10, 9,10,10,11,11, 4, 7, 7, 8, 8, 8,
  133134. 8, 9,10,11,11,11,11, 6, 8, 8,10,10,10,10,11,11,
  133135. 12,12,12,12, 7, 8, 8,10,10,10,10,11,11,12,12,13,
  133136. 13, 7, 9, 9,11,10,12,12,13,13,14,13,14,14, 7, 9,
  133137. 9,10,11,11,12,13,13,13,13,16,14, 9,10,10,12,12,
  133138. 13,13,14,14,15,16,15,16, 9,10,10,12,12,12,13,14,
  133139. 14,14,15,16,15,10,12,12,13,13,15,13,16,16,15,17,
  133140. 17,17,10,11,11,12,14,14,14,15,15,17,17,15,17,11,
  133141. 12,12,14,14,14,15,15,15,17,16,17,17,10,12,12,13,
  133142. 14,14,14,17,15,17,17,17,17,
  133143. };
  133144. static float _vq_quantthresh__44u2__p7_1[] = {
  133145. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  133146. 32.5, 45.5, 58.5, 71.5,
  133147. };
  133148. static long _vq_quantmap__44u2__p7_1[] = {
  133149. 11, 9, 7, 5, 3, 1, 0, 2,
  133150. 4, 6, 8, 10, 12,
  133151. };
  133152. static encode_aux_threshmatch _vq_auxt__44u2__p7_1 = {
  133153. _vq_quantthresh__44u2__p7_1,
  133154. _vq_quantmap__44u2__p7_1,
  133155. 13,
  133156. 13
  133157. };
  133158. static static_codebook _44u2__p7_1 = {
  133159. 2, 169,
  133160. _vq_lengthlist__44u2__p7_1,
  133161. 1, -523010048, 1618608128, 4, 0,
  133162. _vq_quantlist__44u2__p7_1,
  133163. NULL,
  133164. &_vq_auxt__44u2__p7_1,
  133165. NULL,
  133166. 0
  133167. };
  133168. static long _vq_quantlist__44u2__p7_2[] = {
  133169. 6,
  133170. 5,
  133171. 7,
  133172. 4,
  133173. 8,
  133174. 3,
  133175. 9,
  133176. 2,
  133177. 10,
  133178. 1,
  133179. 11,
  133180. 0,
  133181. 12,
  133182. };
  133183. static long _vq_lengthlist__44u2__p7_2[] = {
  133184. 2, 5, 5, 6, 6, 7, 7, 8, 7, 8, 8, 8, 8, 5, 6, 6,
  133185. 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 5, 6, 6, 7, 7, 8,
  133186. 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7, 8, 8, 8, 8, 8,
  133187. 9, 9, 9, 9, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  133188. 9, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 7, 8,
  133189. 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 9,
  133190. 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9,
  133191. 9, 9, 9, 9, 9, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133192. 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8,
  133193. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9, 9,
  133194. 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133195. };
  133196. static float _vq_quantthresh__44u2__p7_2[] = {
  133197. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  133198. 2.5, 3.5, 4.5, 5.5,
  133199. };
  133200. static long _vq_quantmap__44u2__p7_2[] = {
  133201. 11, 9, 7, 5, 3, 1, 0, 2,
  133202. 4, 6, 8, 10, 12,
  133203. };
  133204. static encode_aux_threshmatch _vq_auxt__44u2__p7_2 = {
  133205. _vq_quantthresh__44u2__p7_2,
  133206. _vq_quantmap__44u2__p7_2,
  133207. 13,
  133208. 13
  133209. };
  133210. static static_codebook _44u2__p7_2 = {
  133211. 2, 169,
  133212. _vq_lengthlist__44u2__p7_2,
  133213. 1, -531103744, 1611661312, 4, 0,
  133214. _vq_quantlist__44u2__p7_2,
  133215. NULL,
  133216. &_vq_auxt__44u2__p7_2,
  133217. NULL,
  133218. 0
  133219. };
  133220. static long _huff_lengthlist__44u2__short[] = {
  133221. 13,15,17,17,15,15,12,17,11, 9, 7,10,10, 9,12,17,
  133222. 10, 6, 3, 6, 5, 7,10,17,15,10, 6, 9, 8, 9,11,17,
  133223. 15, 8, 4, 7, 3, 5, 9,16,16,10, 5, 8, 4, 5, 8,16,
  133224. 13,11, 5, 8, 3, 3, 5,14,13,12, 7,10, 5, 5, 7,14,
  133225. };
  133226. static static_codebook _huff_book__44u2__short = {
  133227. 2, 64,
  133228. _huff_lengthlist__44u2__short,
  133229. 0, 0, 0, 0, 0,
  133230. NULL,
  133231. NULL,
  133232. NULL,
  133233. NULL,
  133234. 0
  133235. };
  133236. static long _huff_lengthlist__44u3__long[] = {
  133237. 6, 9,13,12,14,11,10,13, 8, 4, 5, 7, 8, 7, 8,12,
  133238. 11, 4, 3, 5, 5, 7, 9,14,11, 6, 5, 6, 6, 6, 7,13,
  133239. 13, 7, 5, 6, 4, 5, 7,14,11, 7, 6, 6, 5, 5, 6,13,
  133240. 9, 7, 8, 6, 7, 5, 3, 9, 9,12,13,12,14,10, 6, 7,
  133241. };
  133242. static static_codebook _huff_book__44u3__long = {
  133243. 2, 64,
  133244. _huff_lengthlist__44u3__long,
  133245. 0, 0, 0, 0, 0,
  133246. NULL,
  133247. NULL,
  133248. NULL,
  133249. NULL,
  133250. 0
  133251. };
  133252. static long _vq_quantlist__44u3__p1_0[] = {
  133253. 1,
  133254. 0,
  133255. 2,
  133256. };
  133257. static long _vq_lengthlist__44u3__p1_0[] = {
  133258. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,10,11, 8,
  133259. 10,11, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  133260. 11, 8,11,11, 8,11,11,11,13,14,11,14,14, 8,11,11,
  133261. 10,14,12,11,14,14, 4, 8, 8, 8,11,11, 8,11,11, 7,
  133262. 11,11,11,14,14,10,12,14, 8,11,11,11,14,14,11,14,
  133263. 13,
  133264. };
  133265. static float _vq_quantthresh__44u3__p1_0[] = {
  133266. -0.5, 0.5,
  133267. };
  133268. static long _vq_quantmap__44u3__p1_0[] = {
  133269. 1, 0, 2,
  133270. };
  133271. static encode_aux_threshmatch _vq_auxt__44u3__p1_0 = {
  133272. _vq_quantthresh__44u3__p1_0,
  133273. _vq_quantmap__44u3__p1_0,
  133274. 3,
  133275. 3
  133276. };
  133277. static static_codebook _44u3__p1_0 = {
  133278. 4, 81,
  133279. _vq_lengthlist__44u3__p1_0,
  133280. 1, -535822336, 1611661312, 2, 0,
  133281. _vq_quantlist__44u3__p1_0,
  133282. NULL,
  133283. &_vq_auxt__44u3__p1_0,
  133284. NULL,
  133285. 0
  133286. };
  133287. static long _vq_quantlist__44u3__p2_0[] = {
  133288. 1,
  133289. 0,
  133290. 2,
  133291. };
  133292. static long _vq_lengthlist__44u3__p2_0[] = {
  133293. 2, 5, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 7, 8, 8, 6,
  133294. 8, 8, 5, 6, 6, 6, 8, 8, 7, 8, 8, 5, 7, 6, 7, 8,
  133295. 8, 6, 8, 8, 7, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  133296. 8,10, 8, 8,10,10, 5, 6, 6, 6, 8, 8, 7, 8, 8, 6,
  133297. 8, 8, 8,10,10, 8, 8,10, 7, 8, 8, 8,10,10, 8,10,
  133298. 9,
  133299. };
  133300. static float _vq_quantthresh__44u3__p2_0[] = {
  133301. -0.5, 0.5,
  133302. };
  133303. static long _vq_quantmap__44u3__p2_0[] = {
  133304. 1, 0, 2,
  133305. };
  133306. static encode_aux_threshmatch _vq_auxt__44u3__p2_0 = {
  133307. _vq_quantthresh__44u3__p2_0,
  133308. _vq_quantmap__44u3__p2_0,
  133309. 3,
  133310. 3
  133311. };
  133312. static static_codebook _44u3__p2_0 = {
  133313. 4, 81,
  133314. _vq_lengthlist__44u3__p2_0,
  133315. 1, -535822336, 1611661312, 2, 0,
  133316. _vq_quantlist__44u3__p2_0,
  133317. NULL,
  133318. &_vq_auxt__44u3__p2_0,
  133319. NULL,
  133320. 0
  133321. };
  133322. static long _vq_quantlist__44u3__p3_0[] = {
  133323. 2,
  133324. 1,
  133325. 3,
  133326. 0,
  133327. 4,
  133328. };
  133329. static long _vq_lengthlist__44u3__p3_0[] = {
  133330. 2, 4, 4, 7, 7, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 8,
  133331. 9, 9,12,12, 8, 9, 9,11,12, 5, 7, 7,10,10, 7, 9,
  133332. 9,11,11, 7, 9, 9,10,11,10,11,11,13,13, 9,10,11,
  133333. 13,13, 5, 7, 7,10,10, 7, 9, 9,11,10, 7, 9, 9,11,
  133334. 11, 9,11,10,13,13,10,11,11,14,13, 8,10,10,14,13,
  133335. 10,11,11,15,14, 9,11,11,14,14,13,14,13,16,16,12,
  133336. 13,13,15,15, 8,10,10,13,14, 9,11,11,14,14,10,11,
  133337. 11,14,15,12,13,13,15,15,13,14,14,15,16, 5, 7, 7,
  133338. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,12,10,11,11,14,
  133339. 14,10,11,11,14,14, 7, 9, 9,12,12, 9,11,11,13,13,
  133340. 9,11,11,13,13,12,12,13,15,15,11,12,13,15,16, 7,
  133341. 9, 9,11,11, 8,11,10,13,12, 9,11,11,13,13,11,13,
  133342. 12,15,13,11,13,13,15,16, 9,12,11,15,14,11,12,13,
  133343. 16,15,11,13,13,15,16,14,14,15,17,16,13,15,16, 0,
  133344. 17, 9,11,11,15,15,10,13,12,15,15,11,13,13,15,16,
  133345. 13,15,13,16,15,14,16,15, 0,19, 5, 7, 7,10,10, 7,
  133346. 9, 9,11,11, 7, 9, 9,11,11,10,12,11,14,14,10,11,
  133347. 12,14,14, 7, 9, 9,12,12, 9,11,11,14,13, 9,10,11,
  133348. 12,13,11,13,13,16,16,11,12,13,13,16, 7, 9, 9,12,
  133349. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,13,15,15,
  133350. 12,13,12,15,14, 9,11,11,15,14,11,13,12,16,16,10,
  133351. 12,12,15,15,13,15,15,17,19,13,14,15,16,17,10,12,
  133352. 12,15,15,11,13,13,16,16,11,13,13,15,16,13,15,15,
  133353. 0, 0,14,15,15,16,16, 8,10,10,14,14,10,12,12,15,
  133354. 15,10,12,11,15,16,14,15,15,19,20,13,14,14,18,16,
  133355. 9,11,11,15,15,11,13,13,17,16,11,13,13,16,16,15,
  133356. 17,17,20,20,14,15,16,17,20, 9,11,11,15,15,10,13,
  133357. 12,16,15,11,13,13,15,17,14,16,15,18, 0,14,16,15,
  133358. 18,20,12,14,14, 0, 0,14,14,16, 0, 0,13,16,15, 0,
  133359. 0,17,17,18, 0, 0,16,17,19,19, 0,12,14,14,18, 0,
  133360. 12,16,14, 0,17,13,15,15,18, 0,16,18,17, 0,17,16,
  133361. 18,17, 0, 0, 7,10,10,14,14,10,12,11,15,15,10,12,
  133362. 12,16,15,13,15,15,18, 0,14,15,15,17, 0, 9,11,11,
  133363. 15,15,11,13,13,16,16,11,12,13,16,16,14,15,16,17,
  133364. 17,14,16,16,16,18, 9,11,12,16,16,11,13,13,17,17,
  133365. 11,14,13,20,17,15,16,16,19, 0,15,16,17, 0,19,11,
  133366. 13,14,17,16,14,15,15,20,18,13,14,15,17,19,16,18,
  133367. 18, 0,20,16,16,19,17, 0,12,15,14,17, 0,14,15,15,
  133368. 18,19,13,16,15,19,20,15,18,18, 0,20,17, 0,16, 0,
  133369. 0,
  133370. };
  133371. static float _vq_quantthresh__44u3__p3_0[] = {
  133372. -1.5, -0.5, 0.5, 1.5,
  133373. };
  133374. static long _vq_quantmap__44u3__p3_0[] = {
  133375. 3, 1, 0, 2, 4,
  133376. };
  133377. static encode_aux_threshmatch _vq_auxt__44u3__p3_0 = {
  133378. _vq_quantthresh__44u3__p3_0,
  133379. _vq_quantmap__44u3__p3_0,
  133380. 5,
  133381. 5
  133382. };
  133383. static static_codebook _44u3__p3_0 = {
  133384. 4, 625,
  133385. _vq_lengthlist__44u3__p3_0,
  133386. 1, -533725184, 1611661312, 3, 0,
  133387. _vq_quantlist__44u3__p3_0,
  133388. NULL,
  133389. &_vq_auxt__44u3__p3_0,
  133390. NULL,
  133391. 0
  133392. };
  133393. static long _vq_quantlist__44u3__p4_0[] = {
  133394. 2,
  133395. 1,
  133396. 3,
  133397. 0,
  133398. 4,
  133399. };
  133400. static long _vq_lengthlist__44u3__p4_0[] = {
  133401. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 9,
  133402. 9, 9,11,11, 9, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  133403. 8,10,10, 7, 7, 8,10,10, 9,10,10,11,12, 9,10,10,
  133404. 11,12, 5, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 8,10,
  133405. 10, 9,10, 9,12,11, 9,10,10,12,11, 9,10, 9,12,12,
  133406. 9,10,10,13,12, 9,10,10,12,13,12,12,12,14,14,11,
  133407. 12,12,13,14, 9, 9,10,12,12, 9,10,10,12,12, 9,10,
  133408. 10,12,13,11,12,11,14,13,12,12,12,14,13, 5, 7, 7,
  133409. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,
  133410. 12, 9,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,11,11,
  133411. 8, 9, 9,11,11,11,11,11,12,13,10,11,11,13,13, 6,
  133412. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  133413. 10,13,11,10,11,11,13,13, 9,11,10,13,12,10,11,11,
  133414. 13,13,10,11,11,13,13,12,12,13,12,15,12,13,13,15,
  133415. 15, 9,10,10,12,13,10,11,10,13,12,10,11,11,13,14,
  133416. 12,13,11,15,13,12,13,13,15,15, 5, 7, 7, 9, 9, 7,
  133417. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12,10,10,
  133418. 11,12,12, 6, 8, 8,10,10, 8, 9, 9,11,11, 7, 8, 9,
  133419. 10,11,10,11,11,13,13,10,10,11,11,13, 7, 8, 8,10,
  133420. 10, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,11,13,13,
  133421. 11,11,11,13,12, 9,10,10,13,12,10,11,11,14,13,10,
  133422. 10,11,12,13,12,13,13,15,15,12,11,13,13,14, 9,10,
  133423. 11,12,13,10,11,11,13,13,10,11,11,13,13,12,13,13,
  133424. 15,15,12,13,12,15,12, 8, 9, 9,12,12, 9,11,10,13,
  133425. 13, 9,10,10,13,13,12,13,13,15,14,12,12,12,14,13,
  133426. 9,10,10,13,12,10,11,11,13,13,10,11,11,14,12,13,
  133427. 13,14,14,16,12,13,13,15,15, 9,10,10,13,13,10,11,
  133428. 10,14,13,10,11,11,13,14,12,14,13,15,14,13,13,13,
  133429. 15,15,11,13,12,15,14,11,12,13,14,15,12,13,13,16,
  133430. 14,14,12,15,12,16,14,15,15,17,15,11,12,12,14,14,
  133431. 11,13,11,15,14,12,13,13,15,15,13,15,12,17,13,14,
  133432. 15,15,16,16, 8, 9, 9,12,12, 9,10,10,12,13, 9,10,
  133433. 10,13,13,12,12,12,14,14,12,13,13,15,15, 9,10,10,
  133434. 13,12,10,11,11,14,13,10,10,11,13,14,12,13,13,15,
  133435. 15,12,12,13,14,16, 9,10,10,13,13,10,11,11,13,14,
  133436. 10,11,11,14,13,12,13,13,14,15,13,14,13,16,14,11,
  133437. 12,12,14,14,12,13,13,15,14,11,12,13,14,15,14,15,
  133438. 15,16,16,13,13,15,13,16,11,12,12,14,15,12,13,13,
  133439. 14,15,11,13,12,15,14,14,15,15,16,16,14,15,12,16,
  133440. 13,
  133441. };
  133442. static float _vq_quantthresh__44u3__p4_0[] = {
  133443. -1.5, -0.5, 0.5, 1.5,
  133444. };
  133445. static long _vq_quantmap__44u3__p4_0[] = {
  133446. 3, 1, 0, 2, 4,
  133447. };
  133448. static encode_aux_threshmatch _vq_auxt__44u3__p4_0 = {
  133449. _vq_quantthresh__44u3__p4_0,
  133450. _vq_quantmap__44u3__p4_0,
  133451. 5,
  133452. 5
  133453. };
  133454. static static_codebook _44u3__p4_0 = {
  133455. 4, 625,
  133456. _vq_lengthlist__44u3__p4_0,
  133457. 1, -533725184, 1611661312, 3, 0,
  133458. _vq_quantlist__44u3__p4_0,
  133459. NULL,
  133460. &_vq_auxt__44u3__p4_0,
  133461. NULL,
  133462. 0
  133463. };
  133464. static long _vq_quantlist__44u3__p5_0[] = {
  133465. 4,
  133466. 3,
  133467. 5,
  133468. 2,
  133469. 6,
  133470. 1,
  133471. 7,
  133472. 0,
  133473. 8,
  133474. };
  133475. static long _vq_lengthlist__44u3__p5_0[] = {
  133476. 2, 3, 3, 6, 6, 7, 7, 9, 9, 4, 5, 5, 7, 7, 8, 8,
  133477. 10,10, 4, 5, 5, 7, 7, 8, 8,10,10, 6, 7, 7, 8, 8,
  133478. 9, 9,11,10, 6, 7, 7, 8, 8, 9, 9,10,10, 7, 8, 8,
  133479. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  133480. 10,10,11,10,11,11,12,12, 9,10,10,10,10,11,11,12,
  133481. 12,
  133482. };
  133483. static float _vq_quantthresh__44u3__p5_0[] = {
  133484. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  133485. };
  133486. static long _vq_quantmap__44u3__p5_0[] = {
  133487. 7, 5, 3, 1, 0, 2, 4, 6,
  133488. 8,
  133489. };
  133490. static encode_aux_threshmatch _vq_auxt__44u3__p5_0 = {
  133491. _vq_quantthresh__44u3__p5_0,
  133492. _vq_quantmap__44u3__p5_0,
  133493. 9,
  133494. 9
  133495. };
  133496. static static_codebook _44u3__p5_0 = {
  133497. 2, 81,
  133498. _vq_lengthlist__44u3__p5_0,
  133499. 1, -531628032, 1611661312, 4, 0,
  133500. _vq_quantlist__44u3__p5_0,
  133501. NULL,
  133502. &_vq_auxt__44u3__p5_0,
  133503. NULL,
  133504. 0
  133505. };
  133506. static long _vq_quantlist__44u3__p6_0[] = {
  133507. 6,
  133508. 5,
  133509. 7,
  133510. 4,
  133511. 8,
  133512. 3,
  133513. 9,
  133514. 2,
  133515. 10,
  133516. 1,
  133517. 11,
  133518. 0,
  133519. 12,
  133520. };
  133521. static long _vq_lengthlist__44u3__p6_0[] = {
  133522. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,11,13,14, 4, 6, 5,
  133523. 8, 8, 9, 9,10,10,11,11,14,14, 4, 6, 6, 8, 8, 9,
  133524. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  133525. 12,12,15,15, 6, 8, 8, 9, 9,10,11,11,11,12,12,15,
  133526. 15, 8, 9, 9,11,10,11,11,12,12,13,13,15,16, 8, 9,
  133527. 9,10,11,11,11,12,12,13,13,16,16,10,10,11,11,11,
  133528. 12,12,13,13,13,14,17,16, 9,10,11,12,11,12,12,13,
  133529. 13,13,13,16,18,11,12,11,12,12,13,13,13,14,15,14,
  133530. 17,17,11,11,12,12,12,13,13,13,14,14,15,18,17,14,
  133531. 15,15,15,15,16,16,17,17,19,18, 0,20,14,15,14,15,
  133532. 15,16,16,16,17,18,16,20,18,
  133533. };
  133534. static float _vq_quantthresh__44u3__p6_0[] = {
  133535. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  133536. 12.5, 17.5, 22.5, 27.5,
  133537. };
  133538. static long _vq_quantmap__44u3__p6_0[] = {
  133539. 11, 9, 7, 5, 3, 1, 0, 2,
  133540. 4, 6, 8, 10, 12,
  133541. };
  133542. static encode_aux_threshmatch _vq_auxt__44u3__p6_0 = {
  133543. _vq_quantthresh__44u3__p6_0,
  133544. _vq_quantmap__44u3__p6_0,
  133545. 13,
  133546. 13
  133547. };
  133548. static static_codebook _44u3__p6_0 = {
  133549. 2, 169,
  133550. _vq_lengthlist__44u3__p6_0,
  133551. 1, -526516224, 1616117760, 4, 0,
  133552. _vq_quantlist__44u3__p6_0,
  133553. NULL,
  133554. &_vq_auxt__44u3__p6_0,
  133555. NULL,
  133556. 0
  133557. };
  133558. static long _vq_quantlist__44u3__p6_1[] = {
  133559. 2,
  133560. 1,
  133561. 3,
  133562. 0,
  133563. 4,
  133564. };
  133565. static long _vq_lengthlist__44u3__p6_1[] = {
  133566. 2, 4, 4, 5, 5, 4, 5, 5, 6, 5, 4, 5, 5, 5, 6, 5,
  133567. 6, 5, 6, 6, 5, 5, 6, 6, 6,
  133568. };
  133569. static float _vq_quantthresh__44u3__p6_1[] = {
  133570. -1.5, -0.5, 0.5, 1.5,
  133571. };
  133572. static long _vq_quantmap__44u3__p6_1[] = {
  133573. 3, 1, 0, 2, 4,
  133574. };
  133575. static encode_aux_threshmatch _vq_auxt__44u3__p6_1 = {
  133576. _vq_quantthresh__44u3__p6_1,
  133577. _vq_quantmap__44u3__p6_1,
  133578. 5,
  133579. 5
  133580. };
  133581. static static_codebook _44u3__p6_1 = {
  133582. 2, 25,
  133583. _vq_lengthlist__44u3__p6_1,
  133584. 1, -533725184, 1611661312, 3, 0,
  133585. _vq_quantlist__44u3__p6_1,
  133586. NULL,
  133587. &_vq_auxt__44u3__p6_1,
  133588. NULL,
  133589. 0
  133590. };
  133591. static long _vq_quantlist__44u3__p7_0[] = {
  133592. 4,
  133593. 3,
  133594. 5,
  133595. 2,
  133596. 6,
  133597. 1,
  133598. 7,
  133599. 0,
  133600. 8,
  133601. };
  133602. static long _vq_lengthlist__44u3__p7_0[] = {
  133603. 1, 3, 3,10,10,10,10,10,10, 4,10,10,10,10,10,10,
  133604. 10,10, 4,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  133605. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133606. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133607. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133608. 9,
  133609. };
  133610. static float _vq_quantthresh__44u3__p7_0[] = {
  133611. -892.5, -637.5, -382.5, -127.5, 127.5, 382.5, 637.5, 892.5,
  133612. };
  133613. static long _vq_quantmap__44u3__p7_0[] = {
  133614. 7, 5, 3, 1, 0, 2, 4, 6,
  133615. 8,
  133616. };
  133617. static encode_aux_threshmatch _vq_auxt__44u3__p7_0 = {
  133618. _vq_quantthresh__44u3__p7_0,
  133619. _vq_quantmap__44u3__p7_0,
  133620. 9,
  133621. 9
  133622. };
  133623. static static_codebook _44u3__p7_0 = {
  133624. 2, 81,
  133625. _vq_lengthlist__44u3__p7_0,
  133626. 1, -515907584, 1627381760, 4, 0,
  133627. _vq_quantlist__44u3__p7_0,
  133628. NULL,
  133629. &_vq_auxt__44u3__p7_0,
  133630. NULL,
  133631. 0
  133632. };
  133633. static long _vq_quantlist__44u3__p7_1[] = {
  133634. 7,
  133635. 6,
  133636. 8,
  133637. 5,
  133638. 9,
  133639. 4,
  133640. 10,
  133641. 3,
  133642. 11,
  133643. 2,
  133644. 12,
  133645. 1,
  133646. 13,
  133647. 0,
  133648. 14,
  133649. };
  133650. static long _vq_lengthlist__44u3__p7_1[] = {
  133651. 1, 4, 4, 6, 6, 7, 6, 8, 7, 9, 8,10, 9,11,11, 4,
  133652. 7, 7, 8, 7, 9, 9,10,10,11,11,11,11,12,12, 4, 7,
  133653. 7, 7, 7, 9, 9,10,10,11,11,12,12,12,11, 6, 8, 8,
  133654. 9, 9,10,10,11,11,12,12,13,12,13,13, 6, 8, 8, 9,
  133655. 9,10,11,11,11,12,12,13,14,13,13, 8, 9, 9,11,11,
  133656. 12,12,12,13,14,13,14,14,14,15, 8, 9, 9,11,11,11,
  133657. 12,13,14,13,14,15,17,14,15, 9,10,10,12,12,13,13,
  133658. 13,14,15,15,15,16,16,16, 9,11,11,12,12,13,13,14,
  133659. 14,14,15,16,16,16,16,10,12,12,13,13,14,14,15,15,
  133660. 15,16,17,17,17,17,10,12,11,13,13,15,14,15,14,16,
  133661. 17,16,16,16,16,11,13,12,14,14,14,14,15,16,17,16,
  133662. 17,17,17,17,11,13,12,14,14,14,15,17,16,17,17,17,
  133663. 17,17,17,12,13,13,15,16,15,16,17,17,16,16,17,17,
  133664. 17,17,12,13,13,15,15,15,16,17,17,17,16,17,16,17,
  133665. 17,
  133666. };
  133667. static float _vq_quantthresh__44u3__p7_1[] = {
  133668. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  133669. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  133670. };
  133671. static long _vq_quantmap__44u3__p7_1[] = {
  133672. 13, 11, 9, 7, 5, 3, 1, 0,
  133673. 2, 4, 6, 8, 10, 12, 14,
  133674. };
  133675. static encode_aux_threshmatch _vq_auxt__44u3__p7_1 = {
  133676. _vq_quantthresh__44u3__p7_1,
  133677. _vq_quantmap__44u3__p7_1,
  133678. 15,
  133679. 15
  133680. };
  133681. static static_codebook _44u3__p7_1 = {
  133682. 2, 225,
  133683. _vq_lengthlist__44u3__p7_1,
  133684. 1, -522338304, 1620115456, 4, 0,
  133685. _vq_quantlist__44u3__p7_1,
  133686. NULL,
  133687. &_vq_auxt__44u3__p7_1,
  133688. NULL,
  133689. 0
  133690. };
  133691. static long _vq_quantlist__44u3__p7_2[] = {
  133692. 8,
  133693. 7,
  133694. 9,
  133695. 6,
  133696. 10,
  133697. 5,
  133698. 11,
  133699. 4,
  133700. 12,
  133701. 3,
  133702. 13,
  133703. 2,
  133704. 14,
  133705. 1,
  133706. 15,
  133707. 0,
  133708. 16,
  133709. };
  133710. static long _vq_lengthlist__44u3__p7_2[] = {
  133711. 2, 5, 5, 7, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  133712. 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  133713. 10,10, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 9, 9, 9,
  133714. 9,10, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  133715. 10,10,10,10, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,
  133716. 9,10,10,10,10, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  133717. 10,10,10,10,10,10, 7, 8, 8, 9, 8, 9, 9, 9, 9,10,
  133718. 9,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  133719. 9,10,10,10,10,10,10,10, 8, 9, 8, 9, 9, 9, 9,10,
  133720. 9,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,
  133721. 9,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  133722. 9,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,10, 9,
  133723. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,10,
  133724. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  133725. 10,10,10,10,10,10,10,10,10,10,10,10,10,11, 9,10,
  133726. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,11, 9,
  133727. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  133728. 9,10,10,10,10,10,10,10,10,10,10,10,11,11,11,10,
  133729. 11,
  133730. };
  133731. static float _vq_quantthresh__44u3__p7_2[] = {
  133732. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  133733. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  133734. };
  133735. static long _vq_quantmap__44u3__p7_2[] = {
  133736. 15, 13, 11, 9, 7, 5, 3, 1,
  133737. 0, 2, 4, 6, 8, 10, 12, 14,
  133738. 16,
  133739. };
  133740. static encode_aux_threshmatch _vq_auxt__44u3__p7_2 = {
  133741. _vq_quantthresh__44u3__p7_2,
  133742. _vq_quantmap__44u3__p7_2,
  133743. 17,
  133744. 17
  133745. };
  133746. static static_codebook _44u3__p7_2 = {
  133747. 2, 289,
  133748. _vq_lengthlist__44u3__p7_2,
  133749. 1, -529530880, 1611661312, 5, 0,
  133750. _vq_quantlist__44u3__p7_2,
  133751. NULL,
  133752. &_vq_auxt__44u3__p7_2,
  133753. NULL,
  133754. 0
  133755. };
  133756. static long _huff_lengthlist__44u3__short[] = {
  133757. 14,14,14,15,13,15,12,16,10, 8, 7, 9, 9, 8,12,16,
  133758. 10, 5, 4, 6, 5, 6, 9,16,14, 8, 6, 8, 7, 8,10,16,
  133759. 14, 7, 4, 6, 3, 5, 8,16,15, 9, 5, 7, 4, 4, 7,16,
  133760. 13,10, 6, 7, 4, 3, 4,13,13,12, 7, 9, 5, 5, 6,12,
  133761. };
  133762. static static_codebook _huff_book__44u3__short = {
  133763. 2, 64,
  133764. _huff_lengthlist__44u3__short,
  133765. 0, 0, 0, 0, 0,
  133766. NULL,
  133767. NULL,
  133768. NULL,
  133769. NULL,
  133770. 0
  133771. };
  133772. static long _huff_lengthlist__44u4__long[] = {
  133773. 3, 8,12,12,13,12,11,13, 5, 4, 6, 7, 8, 8, 9,13,
  133774. 9, 5, 4, 5, 5, 7, 9,13, 9, 6, 5, 6, 6, 7, 8,12,
  133775. 12, 7, 5, 6, 4, 5, 8,13,11, 7, 6, 6, 5, 5, 6,12,
  133776. 10, 8, 8, 7, 7, 5, 3, 8,10,12,13,12,12, 9, 6, 7,
  133777. };
  133778. static static_codebook _huff_book__44u4__long = {
  133779. 2, 64,
  133780. _huff_lengthlist__44u4__long,
  133781. 0, 0, 0, 0, 0,
  133782. NULL,
  133783. NULL,
  133784. NULL,
  133785. NULL,
  133786. 0
  133787. };
  133788. static long _vq_quantlist__44u4__p1_0[] = {
  133789. 1,
  133790. 0,
  133791. 2,
  133792. };
  133793. static long _vq_lengthlist__44u4__p1_0[] = {
  133794. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,10,11, 8,
  133795. 10,11, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  133796. 11, 8,11,11, 8,11,11,11,13,14,11,15,14, 8,11,11,
  133797. 10,13,12,11,14,14, 4, 8, 8, 8,11,11, 8,11,11, 7,
  133798. 11,11,11,15,14,10,12,14, 8,11,11,11,14,14,11,14,
  133799. 13,
  133800. };
  133801. static float _vq_quantthresh__44u4__p1_0[] = {
  133802. -0.5, 0.5,
  133803. };
  133804. static long _vq_quantmap__44u4__p1_0[] = {
  133805. 1, 0, 2,
  133806. };
  133807. static encode_aux_threshmatch _vq_auxt__44u4__p1_0 = {
  133808. _vq_quantthresh__44u4__p1_0,
  133809. _vq_quantmap__44u4__p1_0,
  133810. 3,
  133811. 3
  133812. };
  133813. static static_codebook _44u4__p1_0 = {
  133814. 4, 81,
  133815. _vq_lengthlist__44u4__p1_0,
  133816. 1, -535822336, 1611661312, 2, 0,
  133817. _vq_quantlist__44u4__p1_0,
  133818. NULL,
  133819. &_vq_auxt__44u4__p1_0,
  133820. NULL,
  133821. 0
  133822. };
  133823. static long _vq_quantlist__44u4__p2_0[] = {
  133824. 1,
  133825. 0,
  133826. 2,
  133827. };
  133828. static long _vq_lengthlist__44u4__p2_0[] = {
  133829. 2, 5, 5, 5, 6, 6, 5, 6, 6, 5, 6, 6, 7, 8, 8, 6,
  133830. 8, 8, 5, 6, 6, 6, 8, 8, 7, 8, 8, 5, 7, 6, 6, 8,
  133831. 8, 6, 8, 8, 6, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  133832. 8,10, 8, 8,10,10, 5, 6, 6, 6, 8, 8, 6, 8, 8, 6,
  133833. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  133834. 9,
  133835. };
  133836. static float _vq_quantthresh__44u4__p2_0[] = {
  133837. -0.5, 0.5,
  133838. };
  133839. static long _vq_quantmap__44u4__p2_0[] = {
  133840. 1, 0, 2,
  133841. };
  133842. static encode_aux_threshmatch _vq_auxt__44u4__p2_0 = {
  133843. _vq_quantthresh__44u4__p2_0,
  133844. _vq_quantmap__44u4__p2_0,
  133845. 3,
  133846. 3
  133847. };
  133848. static static_codebook _44u4__p2_0 = {
  133849. 4, 81,
  133850. _vq_lengthlist__44u4__p2_0,
  133851. 1, -535822336, 1611661312, 2, 0,
  133852. _vq_quantlist__44u4__p2_0,
  133853. NULL,
  133854. &_vq_auxt__44u4__p2_0,
  133855. NULL,
  133856. 0
  133857. };
  133858. static long _vq_quantlist__44u4__p3_0[] = {
  133859. 2,
  133860. 1,
  133861. 3,
  133862. 0,
  133863. 4,
  133864. };
  133865. static long _vq_lengthlist__44u4__p3_0[] = {
  133866. 2, 4, 4, 8, 8, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 8,
  133867. 10, 9,12,12, 8, 9,10,12,12, 5, 7, 7,10,10, 7, 9,
  133868. 9,11,11, 7, 9, 9,11,11,10,12,11,14,14, 9,10,11,
  133869. 13,14, 5, 7, 7,10,10, 7, 9, 9,11,11, 7, 9, 9,11,
  133870. 11, 9,11,10,14,13,10,11,11,14,14, 8,10,10,14,13,
  133871. 10,12,12,15,14, 9,11,11,15,14,13,14,14,17,17,12,
  133872. 14,14,16,16, 8,10,10,14,14, 9,11,11,14,15,10,12,
  133873. 12,14,15,12,14,13,16,16,13,14,15,15,18, 4, 7, 7,
  133874. 10,10, 7, 9, 9,12,11, 7, 9, 9,11,12,10,12,11,15,
  133875. 14,10,11,12,14,15, 7, 9, 9,12,12, 9,11,12,13,13,
  133876. 9,11,12,13,13,12,13,13,15,16,11,13,13,15,16, 7,
  133877. 9, 9,12,12, 9,11,10,13,12, 9,11,12,13,14,11,13,
  133878. 12,16,14,12,13,13,15,16,10,12,12,16,15,11,13,13,
  133879. 17,16,11,13,13,17,16,14,15,15,17,17,14,16,16,18,
  133880. 20, 9,11,11,15,16,11,13,12,16,16,11,13,13,16,17,
  133881. 14,15,14,18,16,14,16,16,17,20, 5, 7, 7,10,10, 7,
  133882. 9, 9,12,11, 7, 9,10,11,12,10,12,11,15,15,10,12,
  133883. 12,14,14, 7, 9, 9,12,12, 9,12,11,14,13, 9,10,11,
  133884. 12,13,12,13,14,16,16,11,12,13,14,16, 7, 9, 9,12,
  133885. 12, 9,12,11,13,13, 9,12,11,13,13,11,13,13,16,16,
  133886. 12,13,13,16,15, 9,11,11,16,14,11,13,13,16,16,11,
  133887. 12,13,16,16,14,16,16,17,17,13,14,15,16,17,10,12,
  133888. 12,15,15,11,13,13,16,17,11,13,13,16,16,14,16,15,
  133889. 19,19,14,15,15,17,18, 8,10,10,14,14,10,12,12,15,
  133890. 15,10,12,12,16,16,14,16,15,20,19,13,15,15,17,16,
  133891. 9,12,12,16,16,11,13,13,16,18,11,14,13,16,17,16,
  133892. 17,16,20, 0,15,16,18,18,20, 9,11,11,15,15,11,14,
  133893. 12,17,16,11,13,13,17,17,15,17,15,20,20,14,16,16,
  133894. 17, 0,13,15,14,18,16,14,15,16, 0,18,14,16,16, 0,
  133895. 0,18,16, 0, 0,20,16,18,18, 0, 0,12,14,14,17,18,
  133896. 13,15,14,20,18,14,16,15,19,19,16,20,16, 0,18,16,
  133897. 19,17,19, 0, 8,10,10,14,14,10,12,12,16,15,10,12,
  133898. 12,16,16,13,15,15,18,17,14,16,16,19, 0, 9,11,11,
  133899. 16,15,11,14,13,18,17,11,12,13,17,18,14,17,16,18,
  133900. 18,15,16,17,18,18, 9,12,12,16,16,11,13,13,16,18,
  133901. 11,14,13,17,17,15,16,16,18,20,16,17,17,20,20,12,
  133902. 14,14,18,17,14,16,16, 0,19,13,14,15,18, 0,16, 0,
  133903. 0, 0, 0,16,16, 0,19,20,13,15,14, 0, 0,14,16,16,
  133904. 18,19,14,16,15, 0,20,16,20,18, 0,20,17,20,17, 0,
  133905. 0,
  133906. };
  133907. static float _vq_quantthresh__44u4__p3_0[] = {
  133908. -1.5, -0.5, 0.5, 1.5,
  133909. };
  133910. static long _vq_quantmap__44u4__p3_0[] = {
  133911. 3, 1, 0, 2, 4,
  133912. };
  133913. static encode_aux_threshmatch _vq_auxt__44u4__p3_0 = {
  133914. _vq_quantthresh__44u4__p3_0,
  133915. _vq_quantmap__44u4__p3_0,
  133916. 5,
  133917. 5
  133918. };
  133919. static static_codebook _44u4__p3_0 = {
  133920. 4, 625,
  133921. _vq_lengthlist__44u4__p3_0,
  133922. 1, -533725184, 1611661312, 3, 0,
  133923. _vq_quantlist__44u4__p3_0,
  133924. NULL,
  133925. &_vq_auxt__44u4__p3_0,
  133926. NULL,
  133927. 0
  133928. };
  133929. static long _vq_quantlist__44u4__p4_0[] = {
  133930. 2,
  133931. 1,
  133932. 3,
  133933. 0,
  133934. 4,
  133935. };
  133936. static long _vq_lengthlist__44u4__p4_0[] = {
  133937. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 9,
  133938. 9, 9,11,11, 8, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  133939. 8,10,10, 7, 7, 8,10,10, 9,10,10,11,12, 9,10,10,
  133940. 11,12, 5, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 8,10,
  133941. 10, 9,10,10,12,11, 9,10,10,12,11, 9,10, 9,12,12,
  133942. 9,10,10,13,12, 9,10,10,12,12,12,12,12,14,14,11,
  133943. 12,12,13,14, 9, 9,10,12,12, 9,10,10,13,13, 9,10,
  133944. 10,12,13,11,12,12,14,13,11,12,12,14,14, 5, 7, 7,
  133945. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,
  133946. 12, 9,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,11,11,
  133947. 8, 9, 9,11,11,11,11,11,12,13,10,11,11,13,13, 6,
  133948. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  133949. 10,13,11,10,11,11,13,13, 9,11,10,13,12,10,11,11,
  133950. 13,14,10,11,11,14,13,12,12,13,12,15,12,13,13,15,
  133951. 15, 9,10,10,12,13,10,11,10,13,12,10,11,11,13,14,
  133952. 12,13,11,15,13,13,13,13,15,15, 5, 7, 7, 9, 9, 7,
  133953. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12,10,10,
  133954. 11,12,13, 6, 8, 8,10,10, 8, 9, 9,11,11, 7, 8, 9,
  133955. 10,11,10,11,11,13,13,10,10,11,11,13, 7, 8, 8,10,
  133956. 11, 8, 9, 9,11,11, 8, 9, 8,11,11,10,11,11,13,13,
  133957. 11,12,11,13,12, 9,10,10,13,12,10,11,11,14,13,10,
  133958. 10,11,12,13,12,13,13,15,15,12,11,13,13,14, 9,10,
  133959. 11,12,13,10,11,11,13,14,10,11,11,13,13,12,13,13,
  133960. 15,15,12,13,12,15,12, 8, 9, 9,12,12, 9,11,10,13,
  133961. 13, 9,10,10,13,13,12,13,13,15,15,12,12,12,14,14,
  133962. 9,10,10,13,13,10,11,11,13,14,10,11,11,14,13,13,
  133963. 13,14,14,16,13,13,13,15,15, 9,10,10,13,13,10,11,
  133964. 10,14,13,10,11,11,13,14,12,14,13,16,14,12,13,13,
  133965. 14,15,11,12,12,15,14,11,12,13,14,15,12,13,13,16,
  133966. 15,14,12,15,12,16,14,15,15,16,16,11,12,12,14,14,
  133967. 11,13,12,15,14,12,13,13,15,16,13,15,13,17,13,14,
  133968. 15,15,16,17, 8, 9, 9,12,12, 9,10,10,12,13, 9,10,
  133969. 10,13,13,12,12,12,14,14,12,13,13,15,15, 9,10,10,
  133970. 13,12,10,11,11,14,13,10,10,11,13,14,13,13,13,15,
  133971. 15,12,13,14,14,16, 9,10,10,13,13,10,11,11,13,14,
  133972. 10,11,11,14,14,13,13,13,15,15,13,14,13,16,14,11,
  133973. 12,12,15,14,12,13,13,16,15,11,12,13,14,15,14,15,
  133974. 15,17,16,13,13,15,13,16,11,12,13,14,15,13,13,13,
  133975. 15,16,11,13,12,15,14,14,15,15,16,16,14,15,12,17,
  133976. 13,
  133977. };
  133978. static float _vq_quantthresh__44u4__p4_0[] = {
  133979. -1.5, -0.5, 0.5, 1.5,
  133980. };
  133981. static long _vq_quantmap__44u4__p4_0[] = {
  133982. 3, 1, 0, 2, 4,
  133983. };
  133984. static encode_aux_threshmatch _vq_auxt__44u4__p4_0 = {
  133985. _vq_quantthresh__44u4__p4_0,
  133986. _vq_quantmap__44u4__p4_0,
  133987. 5,
  133988. 5
  133989. };
  133990. static static_codebook _44u4__p4_0 = {
  133991. 4, 625,
  133992. _vq_lengthlist__44u4__p4_0,
  133993. 1, -533725184, 1611661312, 3, 0,
  133994. _vq_quantlist__44u4__p4_0,
  133995. NULL,
  133996. &_vq_auxt__44u4__p4_0,
  133997. NULL,
  133998. 0
  133999. };
  134000. static long _vq_quantlist__44u4__p5_0[] = {
  134001. 4,
  134002. 3,
  134003. 5,
  134004. 2,
  134005. 6,
  134006. 1,
  134007. 7,
  134008. 0,
  134009. 8,
  134010. };
  134011. static long _vq_lengthlist__44u4__p5_0[] = {
  134012. 2, 3, 3, 6, 6, 7, 7, 9, 9, 4, 5, 5, 7, 7, 8, 8,
  134013. 10, 9, 4, 5, 5, 7, 7, 8, 8,10,10, 6, 7, 7, 8, 8,
  134014. 9, 9,11,10, 6, 7, 7, 8, 8, 9, 9,10,11, 7, 8, 8,
  134015. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  134016. 10,10,11,10,11,11,12,12, 9,10,10,10,11,11,11,12,
  134017. 12,
  134018. };
  134019. static float _vq_quantthresh__44u4__p5_0[] = {
  134020. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  134021. };
  134022. static long _vq_quantmap__44u4__p5_0[] = {
  134023. 7, 5, 3, 1, 0, 2, 4, 6,
  134024. 8,
  134025. };
  134026. static encode_aux_threshmatch _vq_auxt__44u4__p5_0 = {
  134027. _vq_quantthresh__44u4__p5_0,
  134028. _vq_quantmap__44u4__p5_0,
  134029. 9,
  134030. 9
  134031. };
  134032. static static_codebook _44u4__p5_0 = {
  134033. 2, 81,
  134034. _vq_lengthlist__44u4__p5_0,
  134035. 1, -531628032, 1611661312, 4, 0,
  134036. _vq_quantlist__44u4__p5_0,
  134037. NULL,
  134038. &_vq_auxt__44u4__p5_0,
  134039. NULL,
  134040. 0
  134041. };
  134042. static long _vq_quantlist__44u4__p6_0[] = {
  134043. 6,
  134044. 5,
  134045. 7,
  134046. 4,
  134047. 8,
  134048. 3,
  134049. 9,
  134050. 2,
  134051. 10,
  134052. 1,
  134053. 11,
  134054. 0,
  134055. 12,
  134056. };
  134057. static long _vq_lengthlist__44u4__p6_0[] = {
  134058. 1, 4, 4, 6, 6, 8, 8, 9, 9,11,10,13,13, 4, 6, 5,
  134059. 8, 8, 9, 9,10,10,11,11,14,14, 4, 6, 6, 8, 8, 9,
  134060. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  134061. 12,12,15,15, 6, 8, 8, 9, 9,10,11,11,11,12,12,15,
  134062. 15, 8, 9, 9,11,10,11,11,12,12,13,13,16,16, 8, 9,
  134063. 9,10,10,11,11,12,12,13,13,16,16,10,10,10,12,11,
  134064. 12,12,13,13,14,14,16,16,10,10,10,11,12,12,12,13,
  134065. 13,13,14,16,17,11,12,11,12,12,13,13,14,14,15,14,
  134066. 18,17,11,11,12,12,12,13,13,14,14,14,15,19,18,14,
  134067. 15,14,15,15,17,16,17,17,17,17,21, 0,14,15,15,16,
  134068. 16,16,16,17,17,18,17,20,21,
  134069. };
  134070. static float _vq_quantthresh__44u4__p6_0[] = {
  134071. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  134072. 12.5, 17.5, 22.5, 27.5,
  134073. };
  134074. static long _vq_quantmap__44u4__p6_0[] = {
  134075. 11, 9, 7, 5, 3, 1, 0, 2,
  134076. 4, 6, 8, 10, 12,
  134077. };
  134078. static encode_aux_threshmatch _vq_auxt__44u4__p6_0 = {
  134079. _vq_quantthresh__44u4__p6_0,
  134080. _vq_quantmap__44u4__p6_0,
  134081. 13,
  134082. 13
  134083. };
  134084. static static_codebook _44u4__p6_0 = {
  134085. 2, 169,
  134086. _vq_lengthlist__44u4__p6_0,
  134087. 1, -526516224, 1616117760, 4, 0,
  134088. _vq_quantlist__44u4__p6_0,
  134089. NULL,
  134090. &_vq_auxt__44u4__p6_0,
  134091. NULL,
  134092. 0
  134093. };
  134094. static long _vq_quantlist__44u4__p6_1[] = {
  134095. 2,
  134096. 1,
  134097. 3,
  134098. 0,
  134099. 4,
  134100. };
  134101. static long _vq_lengthlist__44u4__p6_1[] = {
  134102. 2, 4, 4, 5, 5, 4, 5, 5, 6, 5, 4, 5, 5, 5, 6, 5,
  134103. 6, 5, 6, 6, 5, 5, 6, 6, 6,
  134104. };
  134105. static float _vq_quantthresh__44u4__p6_1[] = {
  134106. -1.5, -0.5, 0.5, 1.5,
  134107. };
  134108. static long _vq_quantmap__44u4__p6_1[] = {
  134109. 3, 1, 0, 2, 4,
  134110. };
  134111. static encode_aux_threshmatch _vq_auxt__44u4__p6_1 = {
  134112. _vq_quantthresh__44u4__p6_1,
  134113. _vq_quantmap__44u4__p6_1,
  134114. 5,
  134115. 5
  134116. };
  134117. static static_codebook _44u4__p6_1 = {
  134118. 2, 25,
  134119. _vq_lengthlist__44u4__p6_1,
  134120. 1, -533725184, 1611661312, 3, 0,
  134121. _vq_quantlist__44u4__p6_1,
  134122. NULL,
  134123. &_vq_auxt__44u4__p6_1,
  134124. NULL,
  134125. 0
  134126. };
  134127. static long _vq_quantlist__44u4__p7_0[] = {
  134128. 6,
  134129. 5,
  134130. 7,
  134131. 4,
  134132. 8,
  134133. 3,
  134134. 9,
  134135. 2,
  134136. 10,
  134137. 1,
  134138. 11,
  134139. 0,
  134140. 12,
  134141. };
  134142. static long _vq_lengthlist__44u4__p7_0[] = {
  134143. 1, 3, 3,12,12,12,12,12,12,12,12,12,12, 3,12,11,
  134144. 12,12,12,12,12,12,12,12,12,12, 4,11,10,12,12,12,
  134145. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  134146. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  134147. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  134148. 12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134149. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134150. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134151. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134152. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134153. 11,11,11,11,11,11,11,11,11,
  134154. };
  134155. static float _vq_quantthresh__44u4__p7_0[] = {
  134156. -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5, 382.5,
  134157. 637.5, 892.5, 1147.5, 1402.5,
  134158. };
  134159. static long _vq_quantmap__44u4__p7_0[] = {
  134160. 11, 9, 7, 5, 3, 1, 0, 2,
  134161. 4, 6, 8, 10, 12,
  134162. };
  134163. static encode_aux_threshmatch _vq_auxt__44u4__p7_0 = {
  134164. _vq_quantthresh__44u4__p7_0,
  134165. _vq_quantmap__44u4__p7_0,
  134166. 13,
  134167. 13
  134168. };
  134169. static static_codebook _44u4__p7_0 = {
  134170. 2, 169,
  134171. _vq_lengthlist__44u4__p7_0,
  134172. 1, -514332672, 1627381760, 4, 0,
  134173. _vq_quantlist__44u4__p7_0,
  134174. NULL,
  134175. &_vq_auxt__44u4__p7_0,
  134176. NULL,
  134177. 0
  134178. };
  134179. static long _vq_quantlist__44u4__p7_1[] = {
  134180. 7,
  134181. 6,
  134182. 8,
  134183. 5,
  134184. 9,
  134185. 4,
  134186. 10,
  134187. 3,
  134188. 11,
  134189. 2,
  134190. 12,
  134191. 1,
  134192. 13,
  134193. 0,
  134194. 14,
  134195. };
  134196. static long _vq_lengthlist__44u4__p7_1[] = {
  134197. 1, 4, 4, 6, 6, 7, 7, 9, 8,10, 8,10, 9,11,11, 4,
  134198. 7, 6, 8, 7, 9, 9,10,10,11,10,11,10,12,10, 4, 6,
  134199. 7, 8, 8, 9, 9,10,10,11,11,11,11,12,12, 6, 8, 8,
  134200. 10, 9,11,10,12,11,12,12,12,12,13,13, 6, 8, 8,10,
  134201. 10,10,11,11,11,12,12,13,12,13,13, 8, 9, 9,11,11,
  134202. 12,11,12,12,13,13,13,13,13,13, 8, 9, 9,11,11,11,
  134203. 12,12,12,13,13,13,13,13,13, 9,10,10,12,11,13,13,
  134204. 13,13,14,13,13,14,14,14, 9,10,11,11,12,12,13,13,
  134205. 13,13,13,14,15,14,14,10,11,11,12,12,13,13,14,14,
  134206. 14,14,14,15,16,16,10,11,11,12,13,13,13,13,15,14,
  134207. 14,15,16,15,16,10,12,12,13,13,14,14,14,15,15,15,
  134208. 15,15,15,16,11,12,12,13,13,14,14,14,15,15,15,16,
  134209. 15,17,16,11,12,12,13,13,13,15,15,14,16,16,16,16,
  134210. 16,17,11,12,12,13,13,14,14,15,14,15,15,17,17,16,
  134211. 16,
  134212. };
  134213. static float _vq_quantthresh__44u4__p7_1[] = {
  134214. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  134215. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  134216. };
  134217. static long _vq_quantmap__44u4__p7_1[] = {
  134218. 13, 11, 9, 7, 5, 3, 1, 0,
  134219. 2, 4, 6, 8, 10, 12, 14,
  134220. };
  134221. static encode_aux_threshmatch _vq_auxt__44u4__p7_1 = {
  134222. _vq_quantthresh__44u4__p7_1,
  134223. _vq_quantmap__44u4__p7_1,
  134224. 15,
  134225. 15
  134226. };
  134227. static static_codebook _44u4__p7_1 = {
  134228. 2, 225,
  134229. _vq_lengthlist__44u4__p7_1,
  134230. 1, -522338304, 1620115456, 4, 0,
  134231. _vq_quantlist__44u4__p7_1,
  134232. NULL,
  134233. &_vq_auxt__44u4__p7_1,
  134234. NULL,
  134235. 0
  134236. };
  134237. static long _vq_quantlist__44u4__p7_2[] = {
  134238. 8,
  134239. 7,
  134240. 9,
  134241. 6,
  134242. 10,
  134243. 5,
  134244. 11,
  134245. 4,
  134246. 12,
  134247. 3,
  134248. 13,
  134249. 2,
  134250. 14,
  134251. 1,
  134252. 15,
  134253. 0,
  134254. 16,
  134255. };
  134256. static long _vq_lengthlist__44u4__p7_2[] = {
  134257. 2, 5, 5, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134258. 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134259. 9, 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134260. 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134261. 10,10,10,10, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,
  134262. 9,10, 9,10,10, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134263. 10,10,10,10,10,10, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134264. 9,10,10,10,10,10,10, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  134265. 10,10,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9,
  134266. 10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,10,
  134267. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  134268. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,10,
  134269. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  134270. 10,10,10,10,10,10,10,10,10,11,10,10,10, 9, 9, 9,
  134271. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9,
  134272. 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  134273. 10, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  134274. 9,10, 9,10,10,10,10,10,10,10,10,10,10,11,10,10,
  134275. 10,
  134276. };
  134277. static float _vq_quantthresh__44u4__p7_2[] = {
  134278. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  134279. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  134280. };
  134281. static long _vq_quantmap__44u4__p7_2[] = {
  134282. 15, 13, 11, 9, 7, 5, 3, 1,
  134283. 0, 2, 4, 6, 8, 10, 12, 14,
  134284. 16,
  134285. };
  134286. static encode_aux_threshmatch _vq_auxt__44u4__p7_2 = {
  134287. _vq_quantthresh__44u4__p7_2,
  134288. _vq_quantmap__44u4__p7_2,
  134289. 17,
  134290. 17
  134291. };
  134292. static static_codebook _44u4__p7_2 = {
  134293. 2, 289,
  134294. _vq_lengthlist__44u4__p7_2,
  134295. 1, -529530880, 1611661312, 5, 0,
  134296. _vq_quantlist__44u4__p7_2,
  134297. NULL,
  134298. &_vq_auxt__44u4__p7_2,
  134299. NULL,
  134300. 0
  134301. };
  134302. static long _huff_lengthlist__44u4__short[] = {
  134303. 14,17,15,17,16,14,13,16,10, 7, 7,10,13,10,15,16,
  134304. 9, 4, 4, 6, 5, 7, 9,16,12, 8, 7, 8, 8, 8,11,16,
  134305. 14, 7, 4, 6, 3, 5, 8,15,13, 8, 5, 7, 4, 5, 7,16,
  134306. 12, 9, 6, 8, 3, 3, 5,16,14,13, 7,10, 5, 5, 7,15,
  134307. };
  134308. static static_codebook _huff_book__44u4__short = {
  134309. 2, 64,
  134310. _huff_lengthlist__44u4__short,
  134311. 0, 0, 0, 0, 0,
  134312. NULL,
  134313. NULL,
  134314. NULL,
  134315. NULL,
  134316. 0
  134317. };
  134318. static long _huff_lengthlist__44u5__long[] = {
  134319. 3, 8,13,12,14,12,16,11,13,14, 5, 4, 5, 6, 7, 8,
  134320. 10, 9,12,15,10, 5, 5, 5, 6, 8, 9, 9,13,15,10, 5,
  134321. 5, 6, 6, 7, 8, 8,11,13,12, 7, 5, 6, 4, 6, 7, 7,
  134322. 11,14,11, 7, 7, 6, 6, 6, 7, 6,10,14,14, 9, 8, 8,
  134323. 6, 7, 7, 7,11,16,11, 8, 8, 7, 6, 6, 7, 4, 7,12,
  134324. 10,10,12,10,10, 9,10, 5, 6, 9,10,12,15,13,14,14,
  134325. 14, 8, 7, 8,
  134326. };
  134327. static static_codebook _huff_book__44u5__long = {
  134328. 2, 100,
  134329. _huff_lengthlist__44u5__long,
  134330. 0, 0, 0, 0, 0,
  134331. NULL,
  134332. NULL,
  134333. NULL,
  134334. NULL,
  134335. 0
  134336. };
  134337. static long _vq_quantlist__44u5__p1_0[] = {
  134338. 1,
  134339. 0,
  134340. 2,
  134341. };
  134342. static long _vq_lengthlist__44u5__p1_0[] = {
  134343. 1, 4, 4, 5, 8, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  134344. 9,10, 5, 8, 8, 7,10, 9, 8,10,10, 5, 8, 8, 8,10,
  134345. 10, 8,10,10, 8,10,10,10,12,13,10,13,13, 7,10,10,
  134346. 10,13,11,10,13,13, 4, 8, 8, 8,11,10, 8,10,10, 7,
  134347. 10,10,10,13,13,10,11,13, 8,10,11,10,13,13,10,13,
  134348. 12,
  134349. };
  134350. static float _vq_quantthresh__44u5__p1_0[] = {
  134351. -0.5, 0.5,
  134352. };
  134353. static long _vq_quantmap__44u5__p1_0[] = {
  134354. 1, 0, 2,
  134355. };
  134356. static encode_aux_threshmatch _vq_auxt__44u5__p1_0 = {
  134357. _vq_quantthresh__44u5__p1_0,
  134358. _vq_quantmap__44u5__p1_0,
  134359. 3,
  134360. 3
  134361. };
  134362. static static_codebook _44u5__p1_0 = {
  134363. 4, 81,
  134364. _vq_lengthlist__44u5__p1_0,
  134365. 1, -535822336, 1611661312, 2, 0,
  134366. _vq_quantlist__44u5__p1_0,
  134367. NULL,
  134368. &_vq_auxt__44u5__p1_0,
  134369. NULL,
  134370. 0
  134371. };
  134372. static long _vq_quantlist__44u5__p2_0[] = {
  134373. 1,
  134374. 0,
  134375. 2,
  134376. };
  134377. static long _vq_lengthlist__44u5__p2_0[] = {
  134378. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 8, 8, 6,
  134379. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 8, 5, 6, 6, 6, 8,
  134380. 8, 6, 8, 8, 6, 8, 8, 8, 9, 9, 8, 9, 9, 6, 8, 7,
  134381. 7, 9, 8, 8, 9, 9, 5, 6, 6, 6, 8, 7, 6, 8, 8, 6,
  134382. 8, 7, 8, 9, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 8, 9,
  134383. 9,
  134384. };
  134385. static float _vq_quantthresh__44u5__p2_0[] = {
  134386. -0.5, 0.5,
  134387. };
  134388. static long _vq_quantmap__44u5__p2_0[] = {
  134389. 1, 0, 2,
  134390. };
  134391. static encode_aux_threshmatch _vq_auxt__44u5__p2_0 = {
  134392. _vq_quantthresh__44u5__p2_0,
  134393. _vq_quantmap__44u5__p2_0,
  134394. 3,
  134395. 3
  134396. };
  134397. static static_codebook _44u5__p2_0 = {
  134398. 4, 81,
  134399. _vq_lengthlist__44u5__p2_0,
  134400. 1, -535822336, 1611661312, 2, 0,
  134401. _vq_quantlist__44u5__p2_0,
  134402. NULL,
  134403. &_vq_auxt__44u5__p2_0,
  134404. NULL,
  134405. 0
  134406. };
  134407. static long _vq_quantlist__44u5__p3_0[] = {
  134408. 2,
  134409. 1,
  134410. 3,
  134411. 0,
  134412. 4,
  134413. };
  134414. static long _vq_lengthlist__44u5__p3_0[] = {
  134415. 2, 4, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  134416. 10, 9,13,12, 8, 9,10,12,12, 5, 7, 7,10,10, 7, 9,
  134417. 9,11,11, 6, 8, 9,11,11,10,11,11,14,14, 9,10,11,
  134418. 13,14, 5, 7, 7, 9,10, 7, 9, 8,11,11, 7, 9, 9,11,
  134419. 11, 9,11,10,14,13,10,11,11,14,14, 8,10,10,13,13,
  134420. 10,11,11,15,14, 9,11,11,14,14,13,14,14,17,16,12,
  134421. 13,13,15,16, 8,10,10,13,13, 9,11,11,14,15,10,11,
  134422. 11,14,15,12,14,13,16,16,13,15,14,15,17, 5, 7, 7,
  134423. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,11,10,11,11,14,
  134424. 14,10,11,12,14,14, 7, 9, 9,12,11, 9,11,11,13,13,
  134425. 9,11,11,13,13,12,13,13,15,16,11,12,13,15,16, 6,
  134426. 9, 9,11,11, 8,11,10,13,12, 9,11,11,13,14,11,13,
  134427. 12,16,14,11,13,13,16,17,10,12,11,15,15,11,13,13,
  134428. 16,16,11,13,13,17,16,14,15,15,17,17,14,16,16,17,
  134429. 18, 9,11,11,14,15,10,12,12,15,15,11,13,13,16,17,
  134430. 13,15,13,17,15,14,15,16,18, 0, 5, 7, 7,10,10, 7,
  134431. 9, 9,11,11, 7, 9, 9,11,11,10,11,11,14,14,10,11,
  134432. 12,14,15, 6, 9, 9,12,11, 9,11,11,13,13, 8,10,11,
  134433. 12,13,11,13,13,16,15,11,12,13,14,15, 7, 9, 9,11,
  134434. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,13,15,16,
  134435. 11,13,13,15,14, 9,11,11,15,14,11,13,13,17,15,10,
  134436. 12,12,15,15,14,16,16,17,17,13,13,15,15,17,10,11,
  134437. 12,15,15,11,13,13,16,16,11,13,13,15,15,14,15,15,
  134438. 18,18,14,15,15,17,17, 8,10,10,13,13,10,12,11,15,
  134439. 15,10,11,12,15,15,14,15,15,18,18,13,14,14,18,18,
  134440. 9,11,11,15,16,11,13,13,17,17,11,13,13,16,16,15,
  134441. 15,16,17, 0,14,15,17, 0, 0, 9,11,11,15,15,10,13,
  134442. 12,18,16,11,13,13,15,16,14,16,15,20,20,14,15,16,
  134443. 17, 0,13,14,14,20,16,14,15,16,19,18,14,15,15,19,
  134444. 0,18,16, 0,20,20,16,18,18, 0, 0,12,14,14,18,18,
  134445. 13,15,14,18,16,14,15,16,18,20,16,19,16, 0,17,17,
  134446. 18,18,19, 0, 8,10,10,14,14,10,11,11,14,15,10,11,
  134447. 12,15,15,13,15,14,19,17,13,15,15,17, 0, 9,11,11,
  134448. 16,15,11,13,13,16,16,10,12,13,15,17,14,16,16,18,
  134449. 18,14,15,15,18, 0, 9,11,11,15,15,11,13,13,16,17,
  134450. 11,13,13,18,17,14,18,16,18,18,15,17,17,18, 0,12,
  134451. 14,14,18,18,14,15,15,20, 0,13,14,15,17, 0,16,18,
  134452. 17, 0, 0,16,16, 0,17,20,12,14,14,18,18,14,16,15,
  134453. 0,18,14,16,15,18, 0,16,19,17, 0, 0,17,18,16, 0,
  134454. 0,
  134455. };
  134456. static float _vq_quantthresh__44u5__p3_0[] = {
  134457. -1.5, -0.5, 0.5, 1.5,
  134458. };
  134459. static long _vq_quantmap__44u5__p3_0[] = {
  134460. 3, 1, 0, 2, 4,
  134461. };
  134462. static encode_aux_threshmatch _vq_auxt__44u5__p3_0 = {
  134463. _vq_quantthresh__44u5__p3_0,
  134464. _vq_quantmap__44u5__p3_0,
  134465. 5,
  134466. 5
  134467. };
  134468. static static_codebook _44u5__p3_0 = {
  134469. 4, 625,
  134470. _vq_lengthlist__44u5__p3_0,
  134471. 1, -533725184, 1611661312, 3, 0,
  134472. _vq_quantlist__44u5__p3_0,
  134473. NULL,
  134474. &_vq_auxt__44u5__p3_0,
  134475. NULL,
  134476. 0
  134477. };
  134478. static long _vq_quantlist__44u5__p4_0[] = {
  134479. 2,
  134480. 1,
  134481. 3,
  134482. 0,
  134483. 4,
  134484. };
  134485. static long _vq_lengthlist__44u5__p4_0[] = {
  134486. 4, 5, 5, 8, 8, 6, 7, 6, 9, 9, 6, 6, 7, 9, 9, 8,
  134487. 9, 9,11,11, 8, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 8,
  134488. 8,10,10, 6, 7, 8, 9,10, 9,10,10,11,12, 9, 9,10,
  134489. 11,12, 6, 7, 7, 9, 9, 6, 8, 7,10, 9, 7, 8, 8,10,
  134490. 10, 9,10, 9,12,11, 9,10,10,12,11, 8, 9, 9,12,11,
  134491. 9,10,10,12,12, 9,10,10,12,12,11,12,12,13,14,11,
  134492. 11,12,13,14, 8, 9, 9,11,12, 9,10,10,12,12, 9,10,
  134493. 10,12,12,11,12,11,14,13,11,12,12,13,13, 5, 7, 7,
  134494. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,
  134495. 12, 9,10,10,12,12, 7, 8, 8,10,10, 8, 8, 9,10,11,
  134496. 8, 9, 9,11,11,10,10,11,11,13,10,11,11,12,13, 6,
  134497. 7, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  134498. 10,13,11,10,11,11,12,12, 9,10,10,12,12,10,10,11,
  134499. 12,13,10,11,11,13,13,12,11,13,12,15,12,13,13,14,
  134500. 15, 9,10,10,12,12, 9,11,10,13,12,10,11,11,13,13,
  134501. 11,13,11,14,12,12,13,13,14,15, 5, 7, 7, 9, 9, 7,
  134502. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12, 9,10,
  134503. 10,12,12, 6, 8, 7,10,10, 8, 9, 9,11,11, 7, 8, 9,
  134504. 10,11,10,11,11,12,12,10,10,11,11,13, 7, 8, 8,10,
  134505. 10, 8, 9, 9,11,11, 8, 9, 8,11,10,10,11,11,13,12,
  134506. 10,11,10,13,11, 9,10,10,12,12,10,11,11,13,12, 9,
  134507. 10,10,12,13,12,13,13,14,15,11,11,13,12,14, 9,10,
  134508. 10,12,12,10,11,11,13,13,10,11,10,13,12,12,13,13,
  134509. 14,14,12,13,11,14,12, 8, 9, 9,12,12, 9,10,10,12,
  134510. 12, 9,10,10,12,12,12,12,12,14,14,11,12,12,14,13,
  134511. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,12,12,
  134512. 12,13,14,15,12,13,13,15,14, 9,10,10,12,12,10,11,
  134513. 10,13,12,10,11,11,12,13,12,13,12,15,13,12,13,13,
  134514. 14,15,11,12,12,14,13,11,12,12,14,15,12,13,13,15,
  134515. 14,13,12,14,12,16,13,14,14,15,15,11,11,12,14,14,
  134516. 11,12,11,14,13,12,13,13,14,15,13,14,12,16,12,14,
  134517. 14,15,16,16, 8, 9, 9,11,12, 9,10,10,12,12, 9,10,
  134518. 10,12,13,11,12,12,13,13,12,12,13,14,14, 9,10,10,
  134519. 12,12,10,11,10,13,12,10,10,11,12,13,12,13,13,15,
  134520. 14,12,12,13,13,15, 9,10,10,12,13,10,11,11,12,13,
  134521. 10,11,11,13,13,12,13,13,14,15,12,13,12,15,14,11,
  134522. 12,11,14,13,12,13,13,15,14,11,11,12,13,14,14,15,
  134523. 14,16,15,13,12,14,13,16,11,12,12,13,14,12,13,13,
  134524. 14,15,11,12,11,14,14,14,14,14,15,16,13,15,12,16,
  134525. 12,
  134526. };
  134527. static float _vq_quantthresh__44u5__p4_0[] = {
  134528. -1.5, -0.5, 0.5, 1.5,
  134529. };
  134530. static long _vq_quantmap__44u5__p4_0[] = {
  134531. 3, 1, 0, 2, 4,
  134532. };
  134533. static encode_aux_threshmatch _vq_auxt__44u5__p4_0 = {
  134534. _vq_quantthresh__44u5__p4_0,
  134535. _vq_quantmap__44u5__p4_0,
  134536. 5,
  134537. 5
  134538. };
  134539. static static_codebook _44u5__p4_0 = {
  134540. 4, 625,
  134541. _vq_lengthlist__44u5__p4_0,
  134542. 1, -533725184, 1611661312, 3, 0,
  134543. _vq_quantlist__44u5__p4_0,
  134544. NULL,
  134545. &_vq_auxt__44u5__p4_0,
  134546. NULL,
  134547. 0
  134548. };
  134549. static long _vq_quantlist__44u5__p5_0[] = {
  134550. 4,
  134551. 3,
  134552. 5,
  134553. 2,
  134554. 6,
  134555. 1,
  134556. 7,
  134557. 0,
  134558. 8,
  134559. };
  134560. static long _vq_lengthlist__44u5__p5_0[] = {
  134561. 2, 3, 3, 6, 6, 8, 8,10,10, 4, 5, 5, 8, 7, 8, 8,
  134562. 11,10, 3, 5, 5, 7, 8, 8, 8,10,11, 6, 8, 7,10, 9,
  134563. 10,10,11,11, 6, 7, 8, 9, 9, 9,10,11,12, 8, 8, 8,
  134564. 10,10,11,11,13,12, 8, 8, 9, 9,10,11,11,12,13,10,
  134565. 11,10,12,11,13,12,14,14,10,10,11,11,12,12,13,14,
  134566. 14,
  134567. };
  134568. static float _vq_quantthresh__44u5__p5_0[] = {
  134569. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  134570. };
  134571. static long _vq_quantmap__44u5__p5_0[] = {
  134572. 7, 5, 3, 1, 0, 2, 4, 6,
  134573. 8,
  134574. };
  134575. static encode_aux_threshmatch _vq_auxt__44u5__p5_0 = {
  134576. _vq_quantthresh__44u5__p5_0,
  134577. _vq_quantmap__44u5__p5_0,
  134578. 9,
  134579. 9
  134580. };
  134581. static static_codebook _44u5__p5_0 = {
  134582. 2, 81,
  134583. _vq_lengthlist__44u5__p5_0,
  134584. 1, -531628032, 1611661312, 4, 0,
  134585. _vq_quantlist__44u5__p5_0,
  134586. NULL,
  134587. &_vq_auxt__44u5__p5_0,
  134588. NULL,
  134589. 0
  134590. };
  134591. static long _vq_quantlist__44u5__p6_0[] = {
  134592. 4,
  134593. 3,
  134594. 5,
  134595. 2,
  134596. 6,
  134597. 1,
  134598. 7,
  134599. 0,
  134600. 8,
  134601. };
  134602. static long _vq_lengthlist__44u5__p6_0[] = {
  134603. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 7, 7,
  134604. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  134605. 8, 8,10,10, 6, 6, 6, 7, 7, 8, 8,10,10, 7, 7, 7,
  134606. 8, 8, 9, 9,11,10, 7, 7, 7, 8, 8, 9, 9,10,11, 9,
  134607. 9, 9,10,10,11,10,11,11, 9, 9, 9,10,10,11,10,11,
  134608. 11,
  134609. };
  134610. static float _vq_quantthresh__44u5__p6_0[] = {
  134611. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  134612. };
  134613. static long _vq_quantmap__44u5__p6_0[] = {
  134614. 7, 5, 3, 1, 0, 2, 4, 6,
  134615. 8,
  134616. };
  134617. static encode_aux_threshmatch _vq_auxt__44u5__p6_0 = {
  134618. _vq_quantthresh__44u5__p6_0,
  134619. _vq_quantmap__44u5__p6_0,
  134620. 9,
  134621. 9
  134622. };
  134623. static static_codebook _44u5__p6_0 = {
  134624. 2, 81,
  134625. _vq_lengthlist__44u5__p6_0,
  134626. 1, -531628032, 1611661312, 4, 0,
  134627. _vq_quantlist__44u5__p6_0,
  134628. NULL,
  134629. &_vq_auxt__44u5__p6_0,
  134630. NULL,
  134631. 0
  134632. };
  134633. static long _vq_quantlist__44u5__p7_0[] = {
  134634. 1,
  134635. 0,
  134636. 2,
  134637. };
  134638. static long _vq_lengthlist__44u5__p7_0[] = {
  134639. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 9, 8,11,10, 7,
  134640. 11,10, 5, 9, 9, 7,10,10, 8,10,11, 4, 9, 9, 9,12,
  134641. 12, 9,12,12, 8,12,12,11,12,12,10,12,13, 7,12,12,
  134642. 11,12,12,10,12,13, 4, 9, 9, 9,12,12, 9,12,12, 7,
  134643. 12,11,10,13,13,11,12,12, 7,12,12,10,13,13,11,12,
  134644. 12,
  134645. };
  134646. static float _vq_quantthresh__44u5__p7_0[] = {
  134647. -5.5, 5.5,
  134648. };
  134649. static long _vq_quantmap__44u5__p7_0[] = {
  134650. 1, 0, 2,
  134651. };
  134652. static encode_aux_threshmatch _vq_auxt__44u5__p7_0 = {
  134653. _vq_quantthresh__44u5__p7_0,
  134654. _vq_quantmap__44u5__p7_0,
  134655. 3,
  134656. 3
  134657. };
  134658. static static_codebook _44u5__p7_0 = {
  134659. 4, 81,
  134660. _vq_lengthlist__44u5__p7_0,
  134661. 1, -529137664, 1618345984, 2, 0,
  134662. _vq_quantlist__44u5__p7_0,
  134663. NULL,
  134664. &_vq_auxt__44u5__p7_0,
  134665. NULL,
  134666. 0
  134667. };
  134668. static long _vq_quantlist__44u5__p7_1[] = {
  134669. 5,
  134670. 4,
  134671. 6,
  134672. 3,
  134673. 7,
  134674. 2,
  134675. 8,
  134676. 1,
  134677. 9,
  134678. 0,
  134679. 10,
  134680. };
  134681. static long _vq_lengthlist__44u5__p7_1[] = {
  134682. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 7, 7,
  134683. 8, 8, 9, 8, 8, 9, 4, 5, 5, 7, 7, 8, 8, 9, 9, 8,
  134684. 9, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 6, 7, 7, 8,
  134685. 8, 9, 9, 9, 9, 9, 9, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  134686. 9, 9, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9,
  134687. 9, 9, 9, 9,10,10,10,10, 8, 9, 9, 9, 9, 9, 9,10,
  134688. 10,10,10, 8, 9, 9, 9, 9, 9, 9,10,10,10,10, 8, 9,
  134689. 9, 9, 9, 9, 9,10,10,10,10,
  134690. };
  134691. static float _vq_quantthresh__44u5__p7_1[] = {
  134692. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  134693. 3.5, 4.5,
  134694. };
  134695. static long _vq_quantmap__44u5__p7_1[] = {
  134696. 9, 7, 5, 3, 1, 0, 2, 4,
  134697. 6, 8, 10,
  134698. };
  134699. static encode_aux_threshmatch _vq_auxt__44u5__p7_1 = {
  134700. _vq_quantthresh__44u5__p7_1,
  134701. _vq_quantmap__44u5__p7_1,
  134702. 11,
  134703. 11
  134704. };
  134705. static static_codebook _44u5__p7_1 = {
  134706. 2, 121,
  134707. _vq_lengthlist__44u5__p7_1,
  134708. 1, -531365888, 1611661312, 4, 0,
  134709. _vq_quantlist__44u5__p7_1,
  134710. NULL,
  134711. &_vq_auxt__44u5__p7_1,
  134712. NULL,
  134713. 0
  134714. };
  134715. static long _vq_quantlist__44u5__p8_0[] = {
  134716. 5,
  134717. 4,
  134718. 6,
  134719. 3,
  134720. 7,
  134721. 2,
  134722. 8,
  134723. 1,
  134724. 9,
  134725. 0,
  134726. 10,
  134727. };
  134728. static long _vq_lengthlist__44u5__p8_0[] = {
  134729. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,10, 4, 6, 6, 7, 7,
  134730. 9, 9,10,10,11,11, 4, 6, 6, 7, 7, 9, 9,10,10,11,
  134731. 11, 6, 8, 7, 9, 9,10,10,11,11,13,12, 6, 8, 8, 9,
  134732. 9,10,10,11,11,12,13, 8, 9, 9,10,10,12,12,13,12,
  134733. 14,13, 8, 9, 9,10,10,12,12,13,13,14,14, 9,11,11,
  134734. 12,12,13,13,14,14,15,14, 9,11,11,12,12,13,13,14,
  134735. 14,15,14,11,12,12,13,13,14,14,15,14,15,14,11,11,
  134736. 12,13,13,14,14,14,14,15,15,
  134737. };
  134738. static float _vq_quantthresh__44u5__p8_0[] = {
  134739. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  134740. 38.5, 49.5,
  134741. };
  134742. static long _vq_quantmap__44u5__p8_0[] = {
  134743. 9, 7, 5, 3, 1, 0, 2, 4,
  134744. 6, 8, 10,
  134745. };
  134746. static encode_aux_threshmatch _vq_auxt__44u5__p8_0 = {
  134747. _vq_quantthresh__44u5__p8_0,
  134748. _vq_quantmap__44u5__p8_0,
  134749. 11,
  134750. 11
  134751. };
  134752. static static_codebook _44u5__p8_0 = {
  134753. 2, 121,
  134754. _vq_lengthlist__44u5__p8_0,
  134755. 1, -524582912, 1618345984, 4, 0,
  134756. _vq_quantlist__44u5__p8_0,
  134757. NULL,
  134758. &_vq_auxt__44u5__p8_0,
  134759. NULL,
  134760. 0
  134761. };
  134762. static long _vq_quantlist__44u5__p8_1[] = {
  134763. 5,
  134764. 4,
  134765. 6,
  134766. 3,
  134767. 7,
  134768. 2,
  134769. 8,
  134770. 1,
  134771. 9,
  134772. 0,
  134773. 10,
  134774. };
  134775. static long _vq_lengthlist__44u5__p8_1[] = {
  134776. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 5, 7, 6,
  134777. 7, 7, 8, 8, 8, 8, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  134778. 8, 6, 7, 6, 7, 7, 8, 8, 8, 8, 8, 8, 6, 6, 7, 7,
  134779. 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8,
  134780. 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8,
  134781. 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8,
  134782. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  134783. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  134784. };
  134785. static float _vq_quantthresh__44u5__p8_1[] = {
  134786. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  134787. 3.5, 4.5,
  134788. };
  134789. static long _vq_quantmap__44u5__p8_1[] = {
  134790. 9, 7, 5, 3, 1, 0, 2, 4,
  134791. 6, 8, 10,
  134792. };
  134793. static encode_aux_threshmatch _vq_auxt__44u5__p8_1 = {
  134794. _vq_quantthresh__44u5__p8_1,
  134795. _vq_quantmap__44u5__p8_1,
  134796. 11,
  134797. 11
  134798. };
  134799. static static_codebook _44u5__p8_1 = {
  134800. 2, 121,
  134801. _vq_lengthlist__44u5__p8_1,
  134802. 1, -531365888, 1611661312, 4, 0,
  134803. _vq_quantlist__44u5__p8_1,
  134804. NULL,
  134805. &_vq_auxt__44u5__p8_1,
  134806. NULL,
  134807. 0
  134808. };
  134809. static long _vq_quantlist__44u5__p9_0[] = {
  134810. 6,
  134811. 5,
  134812. 7,
  134813. 4,
  134814. 8,
  134815. 3,
  134816. 9,
  134817. 2,
  134818. 10,
  134819. 1,
  134820. 11,
  134821. 0,
  134822. 12,
  134823. };
  134824. static long _vq_lengthlist__44u5__p9_0[] = {
  134825. 1, 3, 2,12,10,13,13,13,13,13,13,13,13, 4, 9, 9,
  134826. 13,13,13,13,13,13,13,13,13,13, 5,10, 9,13,13,13,
  134827. 13,13,13,13,13,13,13,12,13,13,13,13,13,13,13,13,
  134828. 13,13,13,13,11,13,13,13,13,13,13,13,13,13,13,13,
  134829. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  134830. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  134831. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  134832. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  134833. 13,13,13,13,13,13,13,13,13,13,13,13,13,12,12,12,
  134834. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  134835. 12,12,12,12,12,12,12,12,12,
  134836. };
  134837. static float _vq_quantthresh__44u5__p9_0[] = {
  134838. -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5, 382.5,
  134839. 637.5, 892.5, 1147.5, 1402.5,
  134840. };
  134841. static long _vq_quantmap__44u5__p9_0[] = {
  134842. 11, 9, 7, 5, 3, 1, 0, 2,
  134843. 4, 6, 8, 10, 12,
  134844. };
  134845. static encode_aux_threshmatch _vq_auxt__44u5__p9_0 = {
  134846. _vq_quantthresh__44u5__p9_0,
  134847. _vq_quantmap__44u5__p9_0,
  134848. 13,
  134849. 13
  134850. };
  134851. static static_codebook _44u5__p9_0 = {
  134852. 2, 169,
  134853. _vq_lengthlist__44u5__p9_0,
  134854. 1, -514332672, 1627381760, 4, 0,
  134855. _vq_quantlist__44u5__p9_0,
  134856. NULL,
  134857. &_vq_auxt__44u5__p9_0,
  134858. NULL,
  134859. 0
  134860. };
  134861. static long _vq_quantlist__44u5__p9_1[] = {
  134862. 7,
  134863. 6,
  134864. 8,
  134865. 5,
  134866. 9,
  134867. 4,
  134868. 10,
  134869. 3,
  134870. 11,
  134871. 2,
  134872. 12,
  134873. 1,
  134874. 13,
  134875. 0,
  134876. 14,
  134877. };
  134878. static long _vq_lengthlist__44u5__p9_1[] = {
  134879. 1, 4, 4, 7, 7, 8, 8, 8, 7, 8, 7, 9, 8, 9, 9, 4,
  134880. 7, 6, 9, 8,10,10, 9, 8, 9, 9, 9, 9, 9, 8, 5, 6,
  134881. 6, 8, 9,10,10, 9, 9, 9,10,10,10,10,11, 7, 8, 8,
  134882. 10,10,11,11,10,10,11,11,11,12,11,11, 7, 8, 8,10,
  134883. 10,11,11,10,10,11,11,12,11,11,11, 8, 9, 9,11,11,
  134884. 12,12,11,11,12,11,12,12,12,12, 8, 9,10,11,11,12,
  134885. 12,11,11,12,12,12,12,12,12, 8, 9, 9,10,10,12,11,
  134886. 12,12,12,12,12,12,12,13, 8, 9, 9,11,11,11,11,12,
  134887. 12,12,12,13,12,13,13, 9,10,10,11,11,12,12,12,13,
  134888. 12,13,13,13,14,13, 9,10,10,11,11,12,12,12,13,13,
  134889. 12,13,13,14,13, 9,11,10,12,11,13,12,12,13,13,13,
  134890. 13,13,13,14, 9,10,10,12,12,12,12,12,13,13,13,13,
  134891. 13,14,14,10,11,11,12,12,12,13,13,13,14,14,13,14,
  134892. 14,14,10,11,11,12,12,12,12,13,12,13,14,13,14,14,
  134893. 14,
  134894. };
  134895. static float _vq_quantthresh__44u5__p9_1[] = {
  134896. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  134897. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  134898. };
  134899. static long _vq_quantmap__44u5__p9_1[] = {
  134900. 13, 11, 9, 7, 5, 3, 1, 0,
  134901. 2, 4, 6, 8, 10, 12, 14,
  134902. };
  134903. static encode_aux_threshmatch _vq_auxt__44u5__p9_1 = {
  134904. _vq_quantthresh__44u5__p9_1,
  134905. _vq_quantmap__44u5__p9_1,
  134906. 15,
  134907. 15
  134908. };
  134909. static static_codebook _44u5__p9_1 = {
  134910. 2, 225,
  134911. _vq_lengthlist__44u5__p9_1,
  134912. 1, -522338304, 1620115456, 4, 0,
  134913. _vq_quantlist__44u5__p9_1,
  134914. NULL,
  134915. &_vq_auxt__44u5__p9_1,
  134916. NULL,
  134917. 0
  134918. };
  134919. static long _vq_quantlist__44u5__p9_2[] = {
  134920. 8,
  134921. 7,
  134922. 9,
  134923. 6,
  134924. 10,
  134925. 5,
  134926. 11,
  134927. 4,
  134928. 12,
  134929. 3,
  134930. 13,
  134931. 2,
  134932. 14,
  134933. 1,
  134934. 15,
  134935. 0,
  134936. 16,
  134937. };
  134938. static long _vq_lengthlist__44u5__p9_2[] = {
  134939. 2, 5, 5, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134940. 9, 5, 6, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  134941. 9, 9, 5, 6, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9,
  134942. 9, 9, 9, 7, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  134943. 9, 9, 9, 9, 7, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9,
  134944. 9, 9, 9, 9, 9, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  134945. 9,10, 9,10,10,10, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9,
  134946. 9, 9,10, 9,10, 9,10, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  134947. 9,10, 9,10,10,10,10,10, 8, 9, 9, 9, 9, 9, 9,10,
  134948. 9,10, 9,10,10,10,10,10,10, 9, 9, 9, 9, 9,10, 9,
  134949. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9,
  134950. 9,10, 9,10, 9,10,10,10,10,10,10, 9, 9, 9, 9, 9,
  134951. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  134952. 9, 9,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  134953. 9,10,10, 9,10,10,10,10,10,10,10,10,10,10, 9, 9,
  134954. 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  134955. 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  134956. 9, 9, 9,10, 9,10,10,10,10,10,10,10,10,10,10,10,
  134957. 10,
  134958. };
  134959. static float _vq_quantthresh__44u5__p9_2[] = {
  134960. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  134961. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  134962. };
  134963. static long _vq_quantmap__44u5__p9_2[] = {
  134964. 15, 13, 11, 9, 7, 5, 3, 1,
  134965. 0, 2, 4, 6, 8, 10, 12, 14,
  134966. 16,
  134967. };
  134968. static encode_aux_threshmatch _vq_auxt__44u5__p9_2 = {
  134969. _vq_quantthresh__44u5__p9_2,
  134970. _vq_quantmap__44u5__p9_2,
  134971. 17,
  134972. 17
  134973. };
  134974. static static_codebook _44u5__p9_2 = {
  134975. 2, 289,
  134976. _vq_lengthlist__44u5__p9_2,
  134977. 1, -529530880, 1611661312, 5, 0,
  134978. _vq_quantlist__44u5__p9_2,
  134979. NULL,
  134980. &_vq_auxt__44u5__p9_2,
  134981. NULL,
  134982. 0
  134983. };
  134984. static long _huff_lengthlist__44u5__short[] = {
  134985. 4,10,17,13,17,13,17,17,17,17, 3, 6, 8, 9,11, 9,
  134986. 15,12,16,17, 6, 5, 5, 7, 7, 8,10,11,17,17, 7, 8,
  134987. 7, 9, 9,10,13,13,17,17, 8, 6, 5, 7, 4, 7, 5, 8,
  134988. 14,17, 9, 9, 8, 9, 7, 9, 8,10,16,17,12,10, 7, 8,
  134989. 4, 7, 4, 7,16,17,12,11, 9,10, 6, 9, 5, 7,14,17,
  134990. 14,13,10,15, 4, 8, 3, 5,14,17,17,14,11,15, 6,10,
  134991. 6, 8,15,17,
  134992. };
  134993. static static_codebook _huff_book__44u5__short = {
  134994. 2, 100,
  134995. _huff_lengthlist__44u5__short,
  134996. 0, 0, 0, 0, 0,
  134997. NULL,
  134998. NULL,
  134999. NULL,
  135000. NULL,
  135001. 0
  135002. };
  135003. static long _huff_lengthlist__44u6__long[] = {
  135004. 3, 9,14,13,14,13,16,12,13,14, 5, 4, 6, 6, 8, 9,
  135005. 11,10,12,15,10, 5, 5, 6, 6, 8,10,10,13,16,10, 6,
  135006. 6, 6, 6, 8, 9, 9,12,14,13, 7, 6, 6, 4, 6, 6, 7,
  135007. 11,14,10, 7, 7, 7, 6, 6, 6, 7,10,13,15,10, 9, 8,
  135008. 5, 6, 5, 6,10,14,10, 9, 8, 8, 6, 6, 5, 4, 6,11,
  135009. 11,11,12,11,10, 9, 9, 5, 5, 9,10,12,15,13,13,13,
  135010. 13, 8, 7, 7,
  135011. };
  135012. static static_codebook _huff_book__44u6__long = {
  135013. 2, 100,
  135014. _huff_lengthlist__44u6__long,
  135015. 0, 0, 0, 0, 0,
  135016. NULL,
  135017. NULL,
  135018. NULL,
  135019. NULL,
  135020. 0
  135021. };
  135022. static long _vq_quantlist__44u6__p1_0[] = {
  135023. 1,
  135024. 0,
  135025. 2,
  135026. };
  135027. static long _vq_lengthlist__44u6__p1_0[] = {
  135028. 1, 4, 4, 4, 8, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  135029. 9,10, 5, 8, 8, 7,10, 9, 8,10,10, 5, 8, 8, 8,10,
  135030. 10, 8,10,10, 8,10,10,10,12,13,10,13,13, 7,10,10,
  135031. 10,13,11,10,13,13, 5, 8, 8, 8,11,10, 8,10,10, 7,
  135032. 10,10,10,13,13,10,11,13, 8,10,11,10,13,13,10,13,
  135033. 12,
  135034. };
  135035. static float _vq_quantthresh__44u6__p1_0[] = {
  135036. -0.5, 0.5,
  135037. };
  135038. static long _vq_quantmap__44u6__p1_0[] = {
  135039. 1, 0, 2,
  135040. };
  135041. static encode_aux_threshmatch _vq_auxt__44u6__p1_0 = {
  135042. _vq_quantthresh__44u6__p1_0,
  135043. _vq_quantmap__44u6__p1_0,
  135044. 3,
  135045. 3
  135046. };
  135047. static static_codebook _44u6__p1_0 = {
  135048. 4, 81,
  135049. _vq_lengthlist__44u6__p1_0,
  135050. 1, -535822336, 1611661312, 2, 0,
  135051. _vq_quantlist__44u6__p1_0,
  135052. NULL,
  135053. &_vq_auxt__44u6__p1_0,
  135054. NULL,
  135055. 0
  135056. };
  135057. static long _vq_quantlist__44u6__p2_0[] = {
  135058. 1,
  135059. 0,
  135060. 2,
  135061. };
  135062. static long _vq_lengthlist__44u6__p2_0[] = {
  135063. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 8, 8, 6,
  135064. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 8, 5, 6, 6, 6, 8,
  135065. 8, 6, 8, 8, 6, 8, 8, 8, 9, 9, 8, 9, 9, 6, 7, 7,
  135066. 7, 9, 8, 8, 9, 9, 5, 6, 6, 6, 8, 7, 6, 8, 8, 6,
  135067. 8, 8, 8, 9, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 8, 9,
  135068. 9,
  135069. };
  135070. static float _vq_quantthresh__44u6__p2_0[] = {
  135071. -0.5, 0.5,
  135072. };
  135073. static long _vq_quantmap__44u6__p2_0[] = {
  135074. 1, 0, 2,
  135075. };
  135076. static encode_aux_threshmatch _vq_auxt__44u6__p2_0 = {
  135077. _vq_quantthresh__44u6__p2_0,
  135078. _vq_quantmap__44u6__p2_0,
  135079. 3,
  135080. 3
  135081. };
  135082. static static_codebook _44u6__p2_0 = {
  135083. 4, 81,
  135084. _vq_lengthlist__44u6__p2_0,
  135085. 1, -535822336, 1611661312, 2, 0,
  135086. _vq_quantlist__44u6__p2_0,
  135087. NULL,
  135088. &_vq_auxt__44u6__p2_0,
  135089. NULL,
  135090. 0
  135091. };
  135092. static long _vq_quantlist__44u6__p3_0[] = {
  135093. 2,
  135094. 1,
  135095. 3,
  135096. 0,
  135097. 4,
  135098. };
  135099. static long _vq_lengthlist__44u6__p3_0[] = {
  135100. 2, 5, 4, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  135101. 9, 9,13,12, 8, 9,10,12,13, 5, 7, 7,10, 9, 7, 9,
  135102. 9,11,11, 7, 8, 9,11,11,10,11,11,14,14, 9,10,11,
  135103. 13,14, 5, 7, 7, 9,10, 6, 9, 8,11,11, 7, 9, 9,11,
  135104. 11, 9,11,10,14,13,10,11,11,14,13, 8,10,10,13,13,
  135105. 10,11,11,15,15, 9,11,11,14,14,13,14,14,17,16,12,
  135106. 13,14,16,16, 8,10,10,13,14, 9,11,11,14,15,10,11,
  135107. 12,14,15,12,14,13,16,15,13,14,14,15,17, 5, 7, 7,
  135108. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,11,10,12,11,14,
  135109. 14,10,11,11,14,14, 7, 9, 9,12,11, 9,11,11,13,13,
  135110. 9,11,11,13,13,11,13,13,14,15,11,12,13,15,16, 6,
  135111. 9, 9,11,12, 8,11,10,13,12, 9,11,11,13,14,11,13,
  135112. 12,16,14,11,13,13,15,16,10,12,11,14,15,11,13,13,
  135113. 15,17,11,13,13,17,16,15,15,16,17,16,14,15,16,18,
  135114. 0, 9,11,11,14,15,10,12,12,16,15,11,13,13,16,16,
  135115. 13,15,14,18,15,14,16,16, 0, 0, 5, 7, 7,10,10, 7,
  135116. 9, 9,11,11, 7, 9, 9,11,11,10,11,11,14,14,10,11,
  135117. 12,14,14, 6, 9, 9,11,11, 9,11,11,13,13, 8,10,11,
  135118. 12,13,11,13,13,16,15,11,12,13,14,16, 7, 9, 9,11,
  135119. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,13,16,15,
  135120. 11,13,12,15,15, 9,11,11,15,14,11,13,13,17,16,10,
  135121. 12,13,15,16,14,16,16, 0,18,14,14,15,15,17,10,11,
  135122. 12,15,15,11,13,13,16,16,11,13,13,16,16,14,16,16,
  135123. 19,17,14,15,15,17,17, 8,10,10,14,14,10,12,11,15,
  135124. 15,10,11,12,16,15,14,15,15,18,20,13,14,16,17,18,
  135125. 9,11,11,15,16,11,13,13,17,17,11,13,13,17,16,15,
  135126. 16,16, 0, 0,15,16,16, 0, 0, 9,11,11,15,15,10,13,
  135127. 12,17,15,11,13,13,17,16,15,17,15,20,19,15,16,16,
  135128. 19, 0,13,15,14, 0,17,14,15,16, 0,20,15,16,16, 0,
  135129. 19,17,18, 0, 0, 0,16,17,18, 0, 0,12,14,14,19,18,
  135130. 13,15,14, 0,17,14,15,16,19,19,16,18,16, 0,19,19,
  135131. 20,17,20, 0, 8,10,10,13,14,10,11,11,15,15,10,12,
  135132. 12,15,16,14,15,14,19,16,14,15,15, 0,18, 9,11,11,
  135133. 16,15,11,13,13, 0,16,11,12,13,16,17,14,16,17, 0,
  135134. 19,15,16,16,18, 0, 9,11,11,15,16,11,13,13,16,16,
  135135. 11,14,13,18,17,15,16,16,18,20,15,17,19, 0, 0,12,
  135136. 14,14,17,17,14,16,15, 0, 0,13,14,15,19, 0,16,18,
  135137. 20, 0, 0,16,16,18,18, 0,12,14,14,17,20,14,16,16,
  135138. 19, 0,14,16,14, 0,20,16,20,17, 0, 0,17, 0,15, 0,
  135139. 19,
  135140. };
  135141. static float _vq_quantthresh__44u6__p3_0[] = {
  135142. -1.5, -0.5, 0.5, 1.5,
  135143. };
  135144. static long _vq_quantmap__44u6__p3_0[] = {
  135145. 3, 1, 0, 2, 4,
  135146. };
  135147. static encode_aux_threshmatch _vq_auxt__44u6__p3_0 = {
  135148. _vq_quantthresh__44u6__p3_0,
  135149. _vq_quantmap__44u6__p3_0,
  135150. 5,
  135151. 5
  135152. };
  135153. static static_codebook _44u6__p3_0 = {
  135154. 4, 625,
  135155. _vq_lengthlist__44u6__p3_0,
  135156. 1, -533725184, 1611661312, 3, 0,
  135157. _vq_quantlist__44u6__p3_0,
  135158. NULL,
  135159. &_vq_auxt__44u6__p3_0,
  135160. NULL,
  135161. 0
  135162. };
  135163. static long _vq_quantlist__44u6__p4_0[] = {
  135164. 2,
  135165. 1,
  135166. 3,
  135167. 0,
  135168. 4,
  135169. };
  135170. static long _vq_lengthlist__44u6__p4_0[] = {
  135171. 4, 5, 5, 8, 8, 6, 7, 6, 9, 9, 6, 6, 7, 9, 9, 8,
  135172. 9, 9,11,11, 8, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 8,
  135173. 8,10,10, 7, 7, 8, 9,10, 9,10,10,11,11, 9, 9,10,
  135174. 11,12, 6, 7, 7, 9, 9, 7, 8, 7,10, 9, 7, 8, 8,10,
  135175. 10, 9,10, 9,12,11, 9,10,10,12,11, 8, 9, 9,11,11,
  135176. 9,10,10,12,12, 9,10,10,12,12,11,12,12,14,13,11,
  135177. 11,12,13,13, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  135178. 10,12,12,11,12,11,13,12,11,12,12,13,13, 5, 7, 7,
  135179. 9, 9, 7, 8, 7,10,10, 7, 7, 8,10,10, 9,10,10,12,
  135180. 11, 9,10,10,11,12, 7, 8, 8,10,10, 8, 8, 9,11,11,
  135181. 8, 9, 9,11,11,10,10,11,12,13,10,10,11,12,12, 6,
  135182. 7, 7,10,10, 7, 9, 8,11,10, 8, 8, 9,10,11,10,11,
  135183. 10,13,11,10,11,11,12,12, 9,10,10,12,12,10,10,11,
  135184. 13,13,10,11,11,12,13,12,12,12,13,14,12,12,13,14,
  135185. 14, 9,10,10,12,12, 9,10,10,13,12,10,11,11,13,13,
  135186. 11,12,11,14,12,12,13,13,14,14, 6, 7, 7, 9, 9, 7,
  135187. 8, 7,10,10, 7, 8, 8,10,10, 9,10,10,12,11, 9,10,
  135188. 10,11,12, 6, 7, 7,10,10, 8, 9, 8,11,10, 7, 8, 9,
  135189. 10,11,10,11,11,12,12,10,10,11,11,13, 7, 8, 8,10,
  135190. 10, 8, 9, 9,11,11, 8, 9, 8,11,11,10,11,10,13,12,
  135191. 10,11,11,13,12, 9,10,10,12,12,10,11,11,13,12, 9,
  135192. 10,10,12,13,12,13,12,14,14,11,11,12,12,14, 9,10,
  135193. 10,12,12,10,11,11,13,13,10,11,10,13,12,12,12,12,
  135194. 14,14,12,13,12,14,13, 8, 9, 9,11,11, 9,10,10,12,
  135195. 12, 9,10,10,12,12,11,12,12,14,13,11,12,12,13,14,
  135196. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,13,12,
  135197. 12,13,14,15,12,12,13,14,14, 9,10,10,12,12, 9,11,
  135198. 10,13,12,10,10,11,12,13,12,13,12,14,13,12,12,13,
  135199. 14,15,11,12,12,14,13,11,12,12,14,14,12,13,13,14,
  135200. 14,13,13,14,14,16,13,14,14,15,15,11,12,11,13,13,
  135201. 11,12,11,14,13,12,12,13,14,15,12,14,12,15,12,13,
  135202. 14,15,15,16, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  135203. 10,12,12,11,12,12,14,13,11,12,12,13,13, 9,10,10,
  135204. 12,12,10,11,10,13,12, 9,10,11,12,13,12,13,12,14,
  135205. 14,12,12,13,13,14, 9,10,10,12,12,10,11,11,13,13,
  135206. 10,11,11,13,13,12,13,12,14,14,12,13,13,14,14,11,
  135207. 11,11,13,13,12,13,12,14,14,11,11,12,13,14,14,14,
  135208. 14,16,15,12,12,14,12,15,11,12,12,13,14,12,13,13,
  135209. 14,15,11,12,12,14,14,13,14,14,16,16,13,14,13,16,
  135210. 13,
  135211. };
  135212. static float _vq_quantthresh__44u6__p4_0[] = {
  135213. -1.5, -0.5, 0.5, 1.5,
  135214. };
  135215. static long _vq_quantmap__44u6__p4_0[] = {
  135216. 3, 1, 0, 2, 4,
  135217. };
  135218. static encode_aux_threshmatch _vq_auxt__44u6__p4_0 = {
  135219. _vq_quantthresh__44u6__p4_0,
  135220. _vq_quantmap__44u6__p4_0,
  135221. 5,
  135222. 5
  135223. };
  135224. static static_codebook _44u6__p4_0 = {
  135225. 4, 625,
  135226. _vq_lengthlist__44u6__p4_0,
  135227. 1, -533725184, 1611661312, 3, 0,
  135228. _vq_quantlist__44u6__p4_0,
  135229. NULL,
  135230. &_vq_auxt__44u6__p4_0,
  135231. NULL,
  135232. 0
  135233. };
  135234. static long _vq_quantlist__44u6__p5_0[] = {
  135235. 4,
  135236. 3,
  135237. 5,
  135238. 2,
  135239. 6,
  135240. 1,
  135241. 7,
  135242. 0,
  135243. 8,
  135244. };
  135245. static long _vq_lengthlist__44u6__p5_0[] = {
  135246. 2, 3, 3, 6, 6, 8, 8,10,10, 4, 5, 5, 8, 7, 8, 8,
  135247. 11,11, 3, 5, 5, 7, 8, 8, 8,11,11, 6, 8, 7, 9, 9,
  135248. 10, 9,12,11, 6, 7, 8, 9, 9, 9,10,11,12, 8, 8, 8,
  135249. 10, 9,12,11,13,13, 8, 8, 9, 9,10,11,12,13,13,10,
  135250. 11,11,12,12,13,13,14,14,10,10,11,11,12,13,13,14,
  135251. 14,
  135252. };
  135253. static float _vq_quantthresh__44u6__p5_0[] = {
  135254. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135255. };
  135256. static long _vq_quantmap__44u6__p5_0[] = {
  135257. 7, 5, 3, 1, 0, 2, 4, 6,
  135258. 8,
  135259. };
  135260. static encode_aux_threshmatch _vq_auxt__44u6__p5_0 = {
  135261. _vq_quantthresh__44u6__p5_0,
  135262. _vq_quantmap__44u6__p5_0,
  135263. 9,
  135264. 9
  135265. };
  135266. static static_codebook _44u6__p5_0 = {
  135267. 2, 81,
  135268. _vq_lengthlist__44u6__p5_0,
  135269. 1, -531628032, 1611661312, 4, 0,
  135270. _vq_quantlist__44u6__p5_0,
  135271. NULL,
  135272. &_vq_auxt__44u6__p5_0,
  135273. NULL,
  135274. 0
  135275. };
  135276. static long _vq_quantlist__44u6__p6_0[] = {
  135277. 4,
  135278. 3,
  135279. 5,
  135280. 2,
  135281. 6,
  135282. 1,
  135283. 7,
  135284. 0,
  135285. 8,
  135286. };
  135287. static long _vq_lengthlist__44u6__p6_0[] = {
  135288. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 7, 7,
  135289. 9, 9, 4, 4, 5, 6, 6, 7, 8, 9, 9, 5, 6, 6, 7, 7,
  135290. 8, 8,10,10, 5, 6, 6, 7, 7, 8, 8,10,10, 7, 8, 7,
  135291. 8, 8,10, 9,11,11, 7, 7, 8, 8, 8, 9,10,10,11, 9,
  135292. 9, 9,10,10,11,11,12,11, 9, 9, 9,10,10,11,11,11,
  135293. 12,
  135294. };
  135295. static float _vq_quantthresh__44u6__p6_0[] = {
  135296. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135297. };
  135298. static long _vq_quantmap__44u6__p6_0[] = {
  135299. 7, 5, 3, 1, 0, 2, 4, 6,
  135300. 8,
  135301. };
  135302. static encode_aux_threshmatch _vq_auxt__44u6__p6_0 = {
  135303. _vq_quantthresh__44u6__p6_0,
  135304. _vq_quantmap__44u6__p6_0,
  135305. 9,
  135306. 9
  135307. };
  135308. static static_codebook _44u6__p6_0 = {
  135309. 2, 81,
  135310. _vq_lengthlist__44u6__p6_0,
  135311. 1, -531628032, 1611661312, 4, 0,
  135312. _vq_quantlist__44u6__p6_0,
  135313. NULL,
  135314. &_vq_auxt__44u6__p6_0,
  135315. NULL,
  135316. 0
  135317. };
  135318. static long _vq_quantlist__44u6__p7_0[] = {
  135319. 1,
  135320. 0,
  135321. 2,
  135322. };
  135323. static long _vq_lengthlist__44u6__p7_0[] = {
  135324. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 8, 7,10,10, 8,
  135325. 10,10, 5, 8, 9, 7,10,10, 7,10, 9, 4, 8, 8, 9,11,
  135326. 11, 8,11,11, 7,11,11,10,10,13,10,13,13, 7,11,11,
  135327. 10,13,12,10,13,13, 5, 9, 8, 8,11,11, 9,11,11, 7,
  135328. 11,11,10,13,13,10,12,13, 7,11,11,10,13,13, 9,13,
  135329. 10,
  135330. };
  135331. static float _vq_quantthresh__44u6__p7_0[] = {
  135332. -5.5, 5.5,
  135333. };
  135334. static long _vq_quantmap__44u6__p7_0[] = {
  135335. 1, 0, 2,
  135336. };
  135337. static encode_aux_threshmatch _vq_auxt__44u6__p7_0 = {
  135338. _vq_quantthresh__44u6__p7_0,
  135339. _vq_quantmap__44u6__p7_0,
  135340. 3,
  135341. 3
  135342. };
  135343. static static_codebook _44u6__p7_0 = {
  135344. 4, 81,
  135345. _vq_lengthlist__44u6__p7_0,
  135346. 1, -529137664, 1618345984, 2, 0,
  135347. _vq_quantlist__44u6__p7_0,
  135348. NULL,
  135349. &_vq_auxt__44u6__p7_0,
  135350. NULL,
  135351. 0
  135352. };
  135353. static long _vq_quantlist__44u6__p7_1[] = {
  135354. 5,
  135355. 4,
  135356. 6,
  135357. 3,
  135358. 7,
  135359. 2,
  135360. 8,
  135361. 1,
  135362. 9,
  135363. 0,
  135364. 10,
  135365. };
  135366. static long _vq_lengthlist__44u6__p7_1[] = {
  135367. 3, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 7, 6,
  135368. 8, 8, 8, 8, 8, 8, 4, 5, 5, 6, 7, 8, 8, 8, 8, 8,
  135369. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7,
  135370. 7, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 9, 9,
  135371. 9, 9, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8,
  135372. 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9,
  135373. 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8,
  135374. 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135375. };
  135376. static float _vq_quantthresh__44u6__p7_1[] = {
  135377. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135378. 3.5, 4.5,
  135379. };
  135380. static long _vq_quantmap__44u6__p7_1[] = {
  135381. 9, 7, 5, 3, 1, 0, 2, 4,
  135382. 6, 8, 10,
  135383. };
  135384. static encode_aux_threshmatch _vq_auxt__44u6__p7_1 = {
  135385. _vq_quantthresh__44u6__p7_1,
  135386. _vq_quantmap__44u6__p7_1,
  135387. 11,
  135388. 11
  135389. };
  135390. static static_codebook _44u6__p7_1 = {
  135391. 2, 121,
  135392. _vq_lengthlist__44u6__p7_1,
  135393. 1, -531365888, 1611661312, 4, 0,
  135394. _vq_quantlist__44u6__p7_1,
  135395. NULL,
  135396. &_vq_auxt__44u6__p7_1,
  135397. NULL,
  135398. 0
  135399. };
  135400. static long _vq_quantlist__44u6__p8_0[] = {
  135401. 5,
  135402. 4,
  135403. 6,
  135404. 3,
  135405. 7,
  135406. 2,
  135407. 8,
  135408. 1,
  135409. 9,
  135410. 0,
  135411. 10,
  135412. };
  135413. static long _vq_lengthlist__44u6__p8_0[] = {
  135414. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,10, 4, 6, 6, 7, 7,
  135415. 9, 9,10,10,11,11, 4, 6, 6, 7, 7, 9, 9,10,10,11,
  135416. 11, 6, 8, 8, 9, 9,10,10,11,11,12,12, 6, 8, 8, 9,
  135417. 9,10,10,11,11,12,12, 8, 9, 9,10,10,11,11,12,12,
  135418. 13,13, 8, 9, 9,10,10,11,11,12,12,13,13,10,10,10,
  135419. 11,11,13,13,13,13,15,14, 9,10,10,12,11,12,13,13,
  135420. 13,14,15,11,12,12,13,13,13,13,15,14,15,15,11,11,
  135421. 12,13,13,14,14,14,15,15,15,
  135422. };
  135423. static float _vq_quantthresh__44u6__p8_0[] = {
  135424. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  135425. 38.5, 49.5,
  135426. };
  135427. static long _vq_quantmap__44u6__p8_0[] = {
  135428. 9, 7, 5, 3, 1, 0, 2, 4,
  135429. 6, 8, 10,
  135430. };
  135431. static encode_aux_threshmatch _vq_auxt__44u6__p8_0 = {
  135432. _vq_quantthresh__44u6__p8_0,
  135433. _vq_quantmap__44u6__p8_0,
  135434. 11,
  135435. 11
  135436. };
  135437. static static_codebook _44u6__p8_0 = {
  135438. 2, 121,
  135439. _vq_lengthlist__44u6__p8_0,
  135440. 1, -524582912, 1618345984, 4, 0,
  135441. _vq_quantlist__44u6__p8_0,
  135442. NULL,
  135443. &_vq_auxt__44u6__p8_0,
  135444. NULL,
  135445. 0
  135446. };
  135447. static long _vq_quantlist__44u6__p8_1[] = {
  135448. 5,
  135449. 4,
  135450. 6,
  135451. 3,
  135452. 7,
  135453. 2,
  135454. 8,
  135455. 1,
  135456. 9,
  135457. 0,
  135458. 10,
  135459. };
  135460. static long _vq_lengthlist__44u6__p8_1[] = {
  135461. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 5, 7, 7,
  135462. 7, 7, 8, 7, 8, 8, 5, 5, 6, 6, 7, 7, 7, 7, 7, 8,
  135463. 8, 6, 7, 7, 7, 7, 8, 7, 8, 8, 8, 8, 6, 6, 7, 7,
  135464. 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8,
  135465. 8, 8, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7,
  135466. 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8,
  135467. 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8,
  135468. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  135469. };
  135470. static float _vq_quantthresh__44u6__p8_1[] = {
  135471. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135472. 3.5, 4.5,
  135473. };
  135474. static long _vq_quantmap__44u6__p8_1[] = {
  135475. 9, 7, 5, 3, 1, 0, 2, 4,
  135476. 6, 8, 10,
  135477. };
  135478. static encode_aux_threshmatch _vq_auxt__44u6__p8_1 = {
  135479. _vq_quantthresh__44u6__p8_1,
  135480. _vq_quantmap__44u6__p8_1,
  135481. 11,
  135482. 11
  135483. };
  135484. static static_codebook _44u6__p8_1 = {
  135485. 2, 121,
  135486. _vq_lengthlist__44u6__p8_1,
  135487. 1, -531365888, 1611661312, 4, 0,
  135488. _vq_quantlist__44u6__p8_1,
  135489. NULL,
  135490. &_vq_auxt__44u6__p8_1,
  135491. NULL,
  135492. 0
  135493. };
  135494. static long _vq_quantlist__44u6__p9_0[] = {
  135495. 7,
  135496. 6,
  135497. 8,
  135498. 5,
  135499. 9,
  135500. 4,
  135501. 10,
  135502. 3,
  135503. 11,
  135504. 2,
  135505. 12,
  135506. 1,
  135507. 13,
  135508. 0,
  135509. 14,
  135510. };
  135511. static long _vq_lengthlist__44u6__p9_0[] = {
  135512. 1, 3, 2, 9, 8,15,15,15,15,15,15,15,15,15,15, 4,
  135513. 8, 9,13,14,14,14,14,14,14,14,14,14,14,14, 5, 8,
  135514. 9,14,14,14,14,14,14,14,14,14,14,14,14,11,14,14,
  135515. 14,14,14,14,14,14,14,14,14,14,14,14,11,14,14,14,
  135516. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135517. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135518. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135519. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135520. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135521. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135522. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135523. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135524. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135525. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135526. 14,
  135527. };
  135528. static float _vq_quantthresh__44u6__p9_0[] = {
  135529. -1657.5, -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5,
  135530. 382.5, 637.5, 892.5, 1147.5, 1402.5, 1657.5,
  135531. };
  135532. static long _vq_quantmap__44u6__p9_0[] = {
  135533. 13, 11, 9, 7, 5, 3, 1, 0,
  135534. 2, 4, 6, 8, 10, 12, 14,
  135535. };
  135536. static encode_aux_threshmatch _vq_auxt__44u6__p9_0 = {
  135537. _vq_quantthresh__44u6__p9_0,
  135538. _vq_quantmap__44u6__p9_0,
  135539. 15,
  135540. 15
  135541. };
  135542. static static_codebook _44u6__p9_0 = {
  135543. 2, 225,
  135544. _vq_lengthlist__44u6__p9_0,
  135545. 1, -514071552, 1627381760, 4, 0,
  135546. _vq_quantlist__44u6__p9_0,
  135547. NULL,
  135548. &_vq_auxt__44u6__p9_0,
  135549. NULL,
  135550. 0
  135551. };
  135552. static long _vq_quantlist__44u6__p9_1[] = {
  135553. 7,
  135554. 6,
  135555. 8,
  135556. 5,
  135557. 9,
  135558. 4,
  135559. 10,
  135560. 3,
  135561. 11,
  135562. 2,
  135563. 12,
  135564. 1,
  135565. 13,
  135566. 0,
  135567. 14,
  135568. };
  135569. static long _vq_lengthlist__44u6__p9_1[] = {
  135570. 1, 4, 4, 7, 7, 8, 9, 8, 8, 9, 8, 9, 8, 9, 9, 4,
  135571. 7, 6, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 4, 7,
  135572. 6, 9, 9,10,10, 9, 9,10,10,10,10,11,11, 7, 9, 8,
  135573. 10,10,11,11,10,10,11,11,11,11,11,11, 7, 8, 9,10,
  135574. 10,11,11,10,10,11,11,11,11,11,12, 8,10,10,11,11,
  135575. 12,12,11,11,12,12,12,12,13,12, 8,10,10,11,11,12,
  135576. 11,11,11,11,12,12,12,12,13, 8, 9, 9,11,10,11,11,
  135577. 12,12,12,12,13,12,13,12, 8, 9, 9,11,11,11,11,12,
  135578. 12,12,12,12,13,13,13, 9,10,10,11,12,12,12,12,12,
  135579. 13,13,13,13,13,13, 9,10,10,11,11,12,12,12,12,13,
  135580. 13,13,13,14,13,10,10,10,12,11,12,12,13,13,13,13,
  135581. 13,13,13,13,10,10,11,11,11,12,12,13,13,13,13,13,
  135582. 13,13,13,10,11,11,12,12,13,12,12,13,13,13,13,13,
  135583. 13,14,10,11,11,12,12,13,12,13,13,13,14,13,13,14,
  135584. 13,
  135585. };
  135586. static float _vq_quantthresh__44u6__p9_1[] = {
  135587. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  135588. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  135589. };
  135590. static long _vq_quantmap__44u6__p9_1[] = {
  135591. 13, 11, 9, 7, 5, 3, 1, 0,
  135592. 2, 4, 6, 8, 10, 12, 14,
  135593. };
  135594. static encode_aux_threshmatch _vq_auxt__44u6__p9_1 = {
  135595. _vq_quantthresh__44u6__p9_1,
  135596. _vq_quantmap__44u6__p9_1,
  135597. 15,
  135598. 15
  135599. };
  135600. static static_codebook _44u6__p9_1 = {
  135601. 2, 225,
  135602. _vq_lengthlist__44u6__p9_1,
  135603. 1, -522338304, 1620115456, 4, 0,
  135604. _vq_quantlist__44u6__p9_1,
  135605. NULL,
  135606. &_vq_auxt__44u6__p9_1,
  135607. NULL,
  135608. 0
  135609. };
  135610. static long _vq_quantlist__44u6__p9_2[] = {
  135611. 8,
  135612. 7,
  135613. 9,
  135614. 6,
  135615. 10,
  135616. 5,
  135617. 11,
  135618. 4,
  135619. 12,
  135620. 3,
  135621. 13,
  135622. 2,
  135623. 14,
  135624. 1,
  135625. 15,
  135626. 0,
  135627. 16,
  135628. };
  135629. static long _vq_lengthlist__44u6__p9_2[] = {
  135630. 3, 5, 5, 7, 7, 8, 8, 8, 8, 8, 8, 9, 8, 8, 9, 9,
  135631. 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,
  135632. 9, 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9,
  135633. 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135634. 9, 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  135635. 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135636. 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  135637. 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135638. 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9,
  135639. 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9, 9, 9, 9, 9,
  135640. 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 8, 9, 9, 9, 9, 9,
  135641. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  135642. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9, 9, 9, 9, 9,
  135643. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,
  135644. 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,10, 9, 9, 9,
  135645. 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,10, 9, 9,10, 9,
  135646. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9,10, 9,10,10,
  135647. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,10,10, 9, 9,
  135648. 10,
  135649. };
  135650. static float _vq_quantthresh__44u6__p9_2[] = {
  135651. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  135652. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  135653. };
  135654. static long _vq_quantmap__44u6__p9_2[] = {
  135655. 15, 13, 11, 9, 7, 5, 3, 1,
  135656. 0, 2, 4, 6, 8, 10, 12, 14,
  135657. 16,
  135658. };
  135659. static encode_aux_threshmatch _vq_auxt__44u6__p9_2 = {
  135660. _vq_quantthresh__44u6__p9_2,
  135661. _vq_quantmap__44u6__p9_2,
  135662. 17,
  135663. 17
  135664. };
  135665. static static_codebook _44u6__p9_2 = {
  135666. 2, 289,
  135667. _vq_lengthlist__44u6__p9_2,
  135668. 1, -529530880, 1611661312, 5, 0,
  135669. _vq_quantlist__44u6__p9_2,
  135670. NULL,
  135671. &_vq_auxt__44u6__p9_2,
  135672. NULL,
  135673. 0
  135674. };
  135675. static long _huff_lengthlist__44u6__short[] = {
  135676. 4,11,16,13,17,13,17,16,17,17, 4, 7, 9, 9,13,10,
  135677. 16,12,16,17, 7, 6, 5, 7, 8, 9,12,12,16,17, 6, 9,
  135678. 7, 9,10,10,15,15,17,17, 6, 7, 5, 7, 5, 7, 7,10,
  135679. 16,17, 7, 9, 8, 9, 8,10,11,11,15,17, 7, 7, 7, 8,
  135680. 5, 8, 8, 9,15,17, 8, 7, 9, 9, 7, 8, 7, 2, 7,15,
  135681. 14,13,13,15, 5,10, 4, 3, 6,17,17,15,13,17, 7,11,
  135682. 7, 6, 9,16,
  135683. };
  135684. static static_codebook _huff_book__44u6__short = {
  135685. 2, 100,
  135686. _huff_lengthlist__44u6__short,
  135687. 0, 0, 0, 0, 0,
  135688. NULL,
  135689. NULL,
  135690. NULL,
  135691. NULL,
  135692. 0
  135693. };
  135694. static long _huff_lengthlist__44u7__long[] = {
  135695. 3, 9,14,13,15,14,16,13,13,14, 5, 5, 7, 7, 8, 9,
  135696. 11,10,12,15,10, 6, 5, 6, 6, 9,10,10,13,16,10, 6,
  135697. 6, 6, 6, 8, 9, 9,12,15,14, 7, 6, 6, 5, 6, 6, 8,
  135698. 12,15,10, 8, 7, 7, 6, 7, 7, 7,11,13,14,10, 9, 8,
  135699. 5, 6, 4, 5, 9,12,10, 9, 9, 8, 6, 6, 5, 3, 6,11,
  135700. 12,11,12,12,10, 9, 8, 5, 5, 8,10,11,15,13,13,13,
  135701. 12, 8, 6, 7,
  135702. };
  135703. static static_codebook _huff_book__44u7__long = {
  135704. 2, 100,
  135705. _huff_lengthlist__44u7__long,
  135706. 0, 0, 0, 0, 0,
  135707. NULL,
  135708. NULL,
  135709. NULL,
  135710. NULL,
  135711. 0
  135712. };
  135713. static long _vq_quantlist__44u7__p1_0[] = {
  135714. 1,
  135715. 0,
  135716. 2,
  135717. };
  135718. static long _vq_lengthlist__44u7__p1_0[] = {
  135719. 1, 4, 4, 4, 7, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  135720. 10,10, 5, 8, 8, 7,10,10, 8,10,10, 5, 8, 8, 8,11,
  135721. 10, 8,10,10, 8,10,10,10,12,13,10,13,13, 7,10,10,
  135722. 10,13,12,10,13,13, 5, 8, 8, 8,11,10, 8,10,11, 7,
  135723. 10,10,10,13,13,10,12,13, 8,11,11,10,13,13,10,13,
  135724. 12,
  135725. };
  135726. static float _vq_quantthresh__44u7__p1_0[] = {
  135727. -0.5, 0.5,
  135728. };
  135729. static long _vq_quantmap__44u7__p1_0[] = {
  135730. 1, 0, 2,
  135731. };
  135732. static encode_aux_threshmatch _vq_auxt__44u7__p1_0 = {
  135733. _vq_quantthresh__44u7__p1_0,
  135734. _vq_quantmap__44u7__p1_0,
  135735. 3,
  135736. 3
  135737. };
  135738. static static_codebook _44u7__p1_0 = {
  135739. 4, 81,
  135740. _vq_lengthlist__44u7__p1_0,
  135741. 1, -535822336, 1611661312, 2, 0,
  135742. _vq_quantlist__44u7__p1_0,
  135743. NULL,
  135744. &_vq_auxt__44u7__p1_0,
  135745. NULL,
  135746. 0
  135747. };
  135748. static long _vq_quantlist__44u7__p2_0[] = {
  135749. 1,
  135750. 0,
  135751. 2,
  135752. };
  135753. static long _vq_lengthlist__44u7__p2_0[] = {
  135754. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 8, 8, 6,
  135755. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 8, 5, 6, 6, 6, 8,
  135756. 7, 6, 8, 8, 6, 8, 8, 8, 9, 9, 8, 9, 9, 6, 8, 7,
  135757. 7, 9, 8, 8, 9, 9, 5, 6, 6, 6, 8, 7, 6, 8, 8, 6,
  135758. 8, 8, 8, 9, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 8, 9,
  135759. 9,
  135760. };
  135761. static float _vq_quantthresh__44u7__p2_0[] = {
  135762. -0.5, 0.5,
  135763. };
  135764. static long _vq_quantmap__44u7__p2_0[] = {
  135765. 1, 0, 2,
  135766. };
  135767. static encode_aux_threshmatch _vq_auxt__44u7__p2_0 = {
  135768. _vq_quantthresh__44u7__p2_0,
  135769. _vq_quantmap__44u7__p2_0,
  135770. 3,
  135771. 3
  135772. };
  135773. static static_codebook _44u7__p2_0 = {
  135774. 4, 81,
  135775. _vq_lengthlist__44u7__p2_0,
  135776. 1, -535822336, 1611661312, 2, 0,
  135777. _vq_quantlist__44u7__p2_0,
  135778. NULL,
  135779. &_vq_auxt__44u7__p2_0,
  135780. NULL,
  135781. 0
  135782. };
  135783. static long _vq_quantlist__44u7__p3_0[] = {
  135784. 2,
  135785. 1,
  135786. 3,
  135787. 0,
  135788. 4,
  135789. };
  135790. static long _vq_lengthlist__44u7__p3_0[] = {
  135791. 2, 5, 4, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  135792. 9, 9,13,12, 8, 9,10,12,13, 5, 7, 7,10, 9, 7, 9,
  135793. 9,11,11, 6, 8, 9,11,11,10,11,11,14,14, 9,10,11,
  135794. 13,14, 5, 7, 7, 9, 9, 7, 9, 8,11,11, 7, 9, 9,11,
  135795. 11, 9,11,10,14,13,10,11,11,14,14, 8,10,10,14,13,
  135796. 10,11,12,15,14, 9,11,11,15,14,13,14,14,16,16,12,
  135797. 13,14,17,16, 8,10,10,13,13, 9,11,11,14,15,10,11,
  135798. 12,14,15,12,14,13,16,16,13,14,15,15,17, 5, 7, 7,
  135799. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,11,10,12,11,15,
  135800. 14,10,11,12,14,14, 7, 9, 9,12,12, 9,11,11,13,13,
  135801. 9,11,11,13,13,11,13,13,14,17,11,13,13,15,16, 6,
  135802. 9, 9,11,11, 8,11,10,13,12, 9,11,11,13,13,11,13,
  135803. 12,16,14,11,13,13,16,16,10,12,12,15,15,11,13,13,
  135804. 16,16,11,13,13,16,15,14,16,17,17,19,14,16,16,18,
  135805. 0, 9,11,11,14,15,10,13,12,16,15,11,13,13,16,16,
  135806. 14,15,14, 0,16,14,16,16,18, 0, 5, 7, 7,10,10, 7,
  135807. 9, 9,12,11, 7, 9, 9,11,12,10,11,11,15,14,10,11,
  135808. 12,14,14, 6, 9, 9,11,11, 9,11,11,13,13, 8,10,11,
  135809. 12,13,11,13,13,17,15,11,12,13,14,15, 7, 9, 9,11,
  135810. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,12,16,16,
  135811. 11,13,13,15,14, 9,11,11,14,15,11,13,13,16,15,10,
  135812. 12,13,16,16,15,16,16, 0, 0,14,13,15,16,18,10,11,
  135813. 11,15,15,11,13,14,16,18,11,13,13,16,15,15,16,16,
  135814. 19, 0,14,15,15,16,16, 8,10,10,13,13,10,12,11,16,
  135815. 15,10,11,11,16,15,13,15,16,18, 0,13,14,15,17,17,
  135816. 9,11,11,15,15,11,13,13,16,18,11,13,13,16,17,15,
  135817. 16,16, 0, 0,15,18,16, 0,17, 9,11,11,15,15,11,13,
  135818. 12,17,15,11,13,14,16,17,15,18,15, 0,17,15,16,16,
  135819. 18,19,13,15,14, 0,18,14,16,16,19,18,14,16,15,19,
  135820. 19,16,18,19, 0, 0,16,17, 0, 0, 0,12,14,14,17,17,
  135821. 13,16,14, 0,18,14,16,15,18, 0,16,18,16,19,17,18,
  135822. 19,17, 0, 0, 8,10,10,14,14, 9,12,11,15,15,10,11,
  135823. 12,15,17,13,15,15,18,16,14,16,15,18,17, 9,11,11,
  135824. 16,15,11,13,13, 0,16,11,12,13,16,15,15,16,16, 0,
  135825. 17,15,15,16,18,17, 9,12,11,15,17,11,13,13,16,16,
  135826. 11,14,13,16,16,15,15,16,18,19,16,18,16, 0, 0,12,
  135827. 14,14, 0,16,14,16,16, 0,18,13,14,15,16, 0,17,16,
  135828. 18, 0, 0,16,16,17,19, 0,13,14,14,17, 0,14,17,16,
  135829. 0,19,14,15,15,18,19,17,16,18, 0, 0,15,19,16, 0,
  135830. 0,
  135831. };
  135832. static float _vq_quantthresh__44u7__p3_0[] = {
  135833. -1.5, -0.5, 0.5, 1.5,
  135834. };
  135835. static long _vq_quantmap__44u7__p3_0[] = {
  135836. 3, 1, 0, 2, 4,
  135837. };
  135838. static encode_aux_threshmatch _vq_auxt__44u7__p3_0 = {
  135839. _vq_quantthresh__44u7__p3_0,
  135840. _vq_quantmap__44u7__p3_0,
  135841. 5,
  135842. 5
  135843. };
  135844. static static_codebook _44u7__p3_0 = {
  135845. 4, 625,
  135846. _vq_lengthlist__44u7__p3_0,
  135847. 1, -533725184, 1611661312, 3, 0,
  135848. _vq_quantlist__44u7__p3_0,
  135849. NULL,
  135850. &_vq_auxt__44u7__p3_0,
  135851. NULL,
  135852. 0
  135853. };
  135854. static long _vq_quantlist__44u7__p4_0[] = {
  135855. 2,
  135856. 1,
  135857. 3,
  135858. 0,
  135859. 4,
  135860. };
  135861. static long _vq_lengthlist__44u7__p4_0[] = {
  135862. 4, 5, 5, 8, 8, 6, 7, 6, 9, 9, 6, 6, 7, 9, 9, 8,
  135863. 9, 9,11,11, 8, 9, 9,10,11, 6, 7, 7, 9, 9, 7, 8,
  135864. 8,10,10, 6, 7, 8, 9,10, 9,10,10,12,12, 9, 9,10,
  135865. 11,12, 6, 7, 7, 9, 9, 6, 8, 7,10, 9, 7, 8, 8,10,
  135866. 10, 9,10, 9,12,11, 9,10,10,12,11, 8, 9, 9,11,11,
  135867. 9,10,10,12,12, 9,10,10,12,12,11,12,12,13,14,11,
  135868. 11,12,13,13, 8, 9, 9,11,11, 9,10,10,12,11, 9,10,
  135869. 10,12,12,11,12,11,13,13,11,12,12,13,13, 6, 7, 7,
  135870. 9, 9, 7, 8, 7,10,10, 7, 7, 8,10,10, 9,10,10,12,
  135871. 11, 9,10,10,12,12, 7, 8, 8,10,10, 8, 8, 9,11,11,
  135872. 8, 9, 9,11,11,10,11,11,12,12,10,10,11,12,13, 6,
  135873. 7, 7,10,10, 7, 9, 8,11,10, 8, 8, 9,10,11,10,11,
  135874. 10,13,11,10,11,11,12,12, 9,10,10,12,12,10,10,11,
  135875. 13,13,10,11,11,13,12,12,12,13,13,14,12,12,13,14,
  135876. 14, 9,10,10,12,12, 9,10,10,12,12,10,11,11,13,13,
  135877. 11,12,11,14,12,12,13,13,14,14, 6, 7, 7, 9, 9, 7,
  135878. 8, 7,10,10, 7, 7, 8,10,10, 9,10,10,12,11, 9,10,
  135879. 10,11,12, 6, 7, 7,10,10, 8, 9, 8,11,10, 7, 8, 9,
  135880. 10,11,10,11,11,13,12,10,10,11,11,13, 7, 8, 8,10,
  135881. 10, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,10,13,12,
  135882. 10,11,11,12,12, 9,10,10,12,12,10,11,11,13,12, 9,
  135883. 10,10,12,13,12,13,12,14,14,11,11,12,12,14, 9,10,
  135884. 10,12,12,10,11,11,13,13,10,11,11,13,13,12,13,12,
  135885. 14,14,12,13,12,14,13, 8, 9, 9,11,11, 9,10,10,12,
  135886. 12, 9,10,10,12,12,11,12,12,14,13,11,12,12,13,13,
  135887. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,12,12,
  135888. 13,13,14,14,12,12,13,14,14, 9,10,10,12,12, 9,11,
  135889. 10,13,12,10,10,11,12,13,11,13,12,14,13,12,12,13,
  135890. 14,14,11,12,12,13,13,11,12,13,14,14,12,13,13,14,
  135891. 14,13,13,14,14,16,13,14,14,16,16,11,11,11,13,13,
  135892. 11,12,11,14,13,12,12,13,14,15,13,14,12,16,13,14,
  135893. 14,14,15,16, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  135894. 10,12,12,11,12,12,14,13,11,12,12,13,14, 9,10,10,
  135895. 12,12,10,11,10,13,12, 9,10,11,12,13,12,13,12,14,
  135896. 14,12,12,13,13,14, 9,10,10,12,12,10,11,11,12,13,
  135897. 10,11,11,13,13,12,13,12,14,14,12,13,13,14,14,11,
  135898. 12,12,13,13,12,13,12,14,14,11,11,12,13,14,13,15,
  135899. 14,16,15,13,12,14,13,16,11,12,12,13,13,12,13,13,
  135900. 14,14,12,12,12,14,14,13,14,14,15,15,13,14,13,16,
  135901. 14,
  135902. };
  135903. static float _vq_quantthresh__44u7__p4_0[] = {
  135904. -1.5, -0.5, 0.5, 1.5,
  135905. };
  135906. static long _vq_quantmap__44u7__p4_0[] = {
  135907. 3, 1, 0, 2, 4,
  135908. };
  135909. static encode_aux_threshmatch _vq_auxt__44u7__p4_0 = {
  135910. _vq_quantthresh__44u7__p4_0,
  135911. _vq_quantmap__44u7__p4_0,
  135912. 5,
  135913. 5
  135914. };
  135915. static static_codebook _44u7__p4_0 = {
  135916. 4, 625,
  135917. _vq_lengthlist__44u7__p4_0,
  135918. 1, -533725184, 1611661312, 3, 0,
  135919. _vq_quantlist__44u7__p4_0,
  135920. NULL,
  135921. &_vq_auxt__44u7__p4_0,
  135922. NULL,
  135923. 0
  135924. };
  135925. static long _vq_quantlist__44u7__p5_0[] = {
  135926. 4,
  135927. 3,
  135928. 5,
  135929. 2,
  135930. 6,
  135931. 1,
  135932. 7,
  135933. 0,
  135934. 8,
  135935. };
  135936. static long _vq_lengthlist__44u7__p5_0[] = {
  135937. 2, 3, 3, 6, 6, 7, 8,10,10, 4, 5, 5, 8, 7, 8, 8,
  135938. 11,11, 3, 5, 5, 7, 7, 8, 9,11,11, 6, 8, 7, 9, 9,
  135939. 10,10,12,12, 6, 7, 8, 9,10,10,10,12,12, 8, 8, 8,
  135940. 10,10,12,11,13,13, 8, 8, 9,10,10,11,11,13,13,10,
  135941. 11,11,12,12,13,13,14,14,10,11,11,12,12,13,13,14,
  135942. 14,
  135943. };
  135944. static float _vq_quantthresh__44u7__p5_0[] = {
  135945. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135946. };
  135947. static long _vq_quantmap__44u7__p5_0[] = {
  135948. 7, 5, 3, 1, 0, 2, 4, 6,
  135949. 8,
  135950. };
  135951. static encode_aux_threshmatch _vq_auxt__44u7__p5_0 = {
  135952. _vq_quantthresh__44u7__p5_0,
  135953. _vq_quantmap__44u7__p5_0,
  135954. 9,
  135955. 9
  135956. };
  135957. static static_codebook _44u7__p5_0 = {
  135958. 2, 81,
  135959. _vq_lengthlist__44u7__p5_0,
  135960. 1, -531628032, 1611661312, 4, 0,
  135961. _vq_quantlist__44u7__p5_0,
  135962. NULL,
  135963. &_vq_auxt__44u7__p5_0,
  135964. NULL,
  135965. 0
  135966. };
  135967. static long _vq_quantlist__44u7__p6_0[] = {
  135968. 4,
  135969. 3,
  135970. 5,
  135971. 2,
  135972. 6,
  135973. 1,
  135974. 7,
  135975. 0,
  135976. 8,
  135977. };
  135978. static long _vq_lengthlist__44u7__p6_0[] = {
  135979. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 8, 7,
  135980. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  135981. 8, 8,10,10, 5, 6, 6, 7, 7, 8, 8,10,10, 7, 8, 7,
  135982. 8, 8,10, 9,11,11, 7, 7, 8, 8, 8, 9,10,11,11, 9,
  135983. 9, 9,10,10,11,10,12,11, 9, 9, 9,10,10,11,11,11,
  135984. 12,
  135985. };
  135986. static float _vq_quantthresh__44u7__p6_0[] = {
  135987. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135988. };
  135989. static long _vq_quantmap__44u7__p6_0[] = {
  135990. 7, 5, 3, 1, 0, 2, 4, 6,
  135991. 8,
  135992. };
  135993. static encode_aux_threshmatch _vq_auxt__44u7__p6_0 = {
  135994. _vq_quantthresh__44u7__p6_0,
  135995. _vq_quantmap__44u7__p6_0,
  135996. 9,
  135997. 9
  135998. };
  135999. static static_codebook _44u7__p6_0 = {
  136000. 2, 81,
  136001. _vq_lengthlist__44u7__p6_0,
  136002. 1, -531628032, 1611661312, 4, 0,
  136003. _vq_quantlist__44u7__p6_0,
  136004. NULL,
  136005. &_vq_auxt__44u7__p6_0,
  136006. NULL,
  136007. 0
  136008. };
  136009. static long _vq_quantlist__44u7__p7_0[] = {
  136010. 1,
  136011. 0,
  136012. 2,
  136013. };
  136014. static long _vq_lengthlist__44u7__p7_0[] = {
  136015. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 8, 8, 9, 9, 7,
  136016. 10,10, 5, 8, 9, 7, 9,10, 8, 9, 9, 4, 9, 9, 9,11,
  136017. 10, 8,10,10, 7,11,10,10,10,12,10,12,12, 7,10,10,
  136018. 10,12,11,10,12,12, 5, 9, 9, 8,10,10, 9,11,11, 7,
  136019. 11,10,10,12,12,10,11,12, 7,10,11,10,12,12,10,12,
  136020. 10,
  136021. };
  136022. static float _vq_quantthresh__44u7__p7_0[] = {
  136023. -5.5, 5.5,
  136024. };
  136025. static long _vq_quantmap__44u7__p7_0[] = {
  136026. 1, 0, 2,
  136027. };
  136028. static encode_aux_threshmatch _vq_auxt__44u7__p7_0 = {
  136029. _vq_quantthresh__44u7__p7_0,
  136030. _vq_quantmap__44u7__p7_0,
  136031. 3,
  136032. 3
  136033. };
  136034. static static_codebook _44u7__p7_0 = {
  136035. 4, 81,
  136036. _vq_lengthlist__44u7__p7_0,
  136037. 1, -529137664, 1618345984, 2, 0,
  136038. _vq_quantlist__44u7__p7_0,
  136039. NULL,
  136040. &_vq_auxt__44u7__p7_0,
  136041. NULL,
  136042. 0
  136043. };
  136044. static long _vq_quantlist__44u7__p7_1[] = {
  136045. 5,
  136046. 4,
  136047. 6,
  136048. 3,
  136049. 7,
  136050. 2,
  136051. 8,
  136052. 1,
  136053. 9,
  136054. 0,
  136055. 10,
  136056. };
  136057. static long _vq_lengthlist__44u7__p7_1[] = {
  136058. 3, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 6, 6,
  136059. 8, 7, 8, 8, 8, 8, 4, 5, 5, 6, 6, 7, 8, 8, 8, 8,
  136060. 8, 6, 7, 6, 7, 7, 8, 8, 9, 9, 9, 9, 6, 6, 7, 7,
  136061. 7, 8, 8, 9, 9, 9, 9, 7, 8, 7, 8, 8, 9, 9, 9, 9,
  136062. 9, 9, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8,
  136063. 9, 9, 9, 9,10, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9,
  136064. 9, 9,10, 8, 8, 8, 9, 9, 9, 9,10, 9,10,10, 8, 8,
  136065. 8, 9, 9, 9, 9, 9,10,10,10,
  136066. };
  136067. static float _vq_quantthresh__44u7__p7_1[] = {
  136068. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  136069. 3.5, 4.5,
  136070. };
  136071. static long _vq_quantmap__44u7__p7_1[] = {
  136072. 9, 7, 5, 3, 1, 0, 2, 4,
  136073. 6, 8, 10,
  136074. };
  136075. static encode_aux_threshmatch _vq_auxt__44u7__p7_1 = {
  136076. _vq_quantthresh__44u7__p7_1,
  136077. _vq_quantmap__44u7__p7_1,
  136078. 11,
  136079. 11
  136080. };
  136081. static static_codebook _44u7__p7_1 = {
  136082. 2, 121,
  136083. _vq_lengthlist__44u7__p7_1,
  136084. 1, -531365888, 1611661312, 4, 0,
  136085. _vq_quantlist__44u7__p7_1,
  136086. NULL,
  136087. &_vq_auxt__44u7__p7_1,
  136088. NULL,
  136089. 0
  136090. };
  136091. static long _vq_quantlist__44u7__p8_0[] = {
  136092. 5,
  136093. 4,
  136094. 6,
  136095. 3,
  136096. 7,
  136097. 2,
  136098. 8,
  136099. 1,
  136100. 9,
  136101. 0,
  136102. 10,
  136103. };
  136104. static long _vq_lengthlist__44u7__p8_0[] = {
  136105. 1, 4, 4, 6, 6, 8, 8,10,10,11,11, 4, 6, 6, 7, 7,
  136106. 9, 9,11,10,12,12, 5, 6, 5, 7, 7, 9, 9,10,11,12,
  136107. 12, 6, 7, 7, 8, 8,10,10,11,11,13,13, 6, 7, 7, 8,
  136108. 8,10,10,11,12,13,13, 8, 9, 9,10,10,11,11,12,12,
  136109. 14,14, 8, 9, 9,10,10,11,11,12,12,14,14,10,10,10,
  136110. 11,11,13,12,14,14,15,15,10,10,10,12,12,13,13,14,
  136111. 14,15,15,11,12,12,13,13,14,14,15,14,16,15,11,12,
  136112. 12,13,13,14,14,15,15,15,16,
  136113. };
  136114. static float _vq_quantthresh__44u7__p8_0[] = {
  136115. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  136116. 38.5, 49.5,
  136117. };
  136118. static long _vq_quantmap__44u7__p8_0[] = {
  136119. 9, 7, 5, 3, 1, 0, 2, 4,
  136120. 6, 8, 10,
  136121. };
  136122. static encode_aux_threshmatch _vq_auxt__44u7__p8_0 = {
  136123. _vq_quantthresh__44u7__p8_0,
  136124. _vq_quantmap__44u7__p8_0,
  136125. 11,
  136126. 11
  136127. };
  136128. static static_codebook _44u7__p8_0 = {
  136129. 2, 121,
  136130. _vq_lengthlist__44u7__p8_0,
  136131. 1, -524582912, 1618345984, 4, 0,
  136132. _vq_quantlist__44u7__p8_0,
  136133. NULL,
  136134. &_vq_auxt__44u7__p8_0,
  136135. NULL,
  136136. 0
  136137. };
  136138. static long _vq_quantlist__44u7__p8_1[] = {
  136139. 5,
  136140. 4,
  136141. 6,
  136142. 3,
  136143. 7,
  136144. 2,
  136145. 8,
  136146. 1,
  136147. 9,
  136148. 0,
  136149. 10,
  136150. };
  136151. static long _vq_lengthlist__44u7__p8_1[] = {
  136152. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7,
  136153. 7, 7, 7, 7, 7, 7, 5, 6, 6, 6, 7, 7, 7, 7, 7, 7,
  136154. 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 6, 7, 7, 7,
  136155. 7, 7, 7, 7, 7, 8, 8, 7, 7, 7, 7, 7, 8, 7, 8, 8,
  136156. 8, 8, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  136157. 7, 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8,
  136158. 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7,
  136159. 7, 8, 8, 8, 8, 8, 8, 8, 8,
  136160. };
  136161. static float _vq_quantthresh__44u7__p8_1[] = {
  136162. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  136163. 3.5, 4.5,
  136164. };
  136165. static long _vq_quantmap__44u7__p8_1[] = {
  136166. 9, 7, 5, 3, 1, 0, 2, 4,
  136167. 6, 8, 10,
  136168. };
  136169. static encode_aux_threshmatch _vq_auxt__44u7__p8_1 = {
  136170. _vq_quantthresh__44u7__p8_1,
  136171. _vq_quantmap__44u7__p8_1,
  136172. 11,
  136173. 11
  136174. };
  136175. static static_codebook _44u7__p8_1 = {
  136176. 2, 121,
  136177. _vq_lengthlist__44u7__p8_1,
  136178. 1, -531365888, 1611661312, 4, 0,
  136179. _vq_quantlist__44u7__p8_1,
  136180. NULL,
  136181. &_vq_auxt__44u7__p8_1,
  136182. NULL,
  136183. 0
  136184. };
  136185. static long _vq_quantlist__44u7__p9_0[] = {
  136186. 5,
  136187. 4,
  136188. 6,
  136189. 3,
  136190. 7,
  136191. 2,
  136192. 8,
  136193. 1,
  136194. 9,
  136195. 0,
  136196. 10,
  136197. };
  136198. static long _vq_lengthlist__44u7__p9_0[] = {
  136199. 1, 3, 3,10,10,10,10,10,10,10,10, 4,10,10,10,10,
  136200. 10,10,10,10,10,10, 4,10,10,10,10,10,10,10,10,10,
  136201. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136202. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136203. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136204. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136205. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  136206. 9, 9, 9, 9, 9, 9, 9, 9, 9,
  136207. };
  136208. static float _vq_quantthresh__44u7__p9_0[] = {
  136209. -2866.5, -2229.5, -1592.5, -955.5, -318.5, 318.5, 955.5, 1592.5,
  136210. 2229.5, 2866.5,
  136211. };
  136212. static long _vq_quantmap__44u7__p9_0[] = {
  136213. 9, 7, 5, 3, 1, 0, 2, 4,
  136214. 6, 8, 10,
  136215. };
  136216. static encode_aux_threshmatch _vq_auxt__44u7__p9_0 = {
  136217. _vq_quantthresh__44u7__p9_0,
  136218. _vq_quantmap__44u7__p9_0,
  136219. 11,
  136220. 11
  136221. };
  136222. static static_codebook _44u7__p9_0 = {
  136223. 2, 121,
  136224. _vq_lengthlist__44u7__p9_0,
  136225. 1, -512171520, 1630791680, 4, 0,
  136226. _vq_quantlist__44u7__p9_0,
  136227. NULL,
  136228. &_vq_auxt__44u7__p9_0,
  136229. NULL,
  136230. 0
  136231. };
  136232. static long _vq_quantlist__44u7__p9_1[] = {
  136233. 6,
  136234. 5,
  136235. 7,
  136236. 4,
  136237. 8,
  136238. 3,
  136239. 9,
  136240. 2,
  136241. 10,
  136242. 1,
  136243. 11,
  136244. 0,
  136245. 12,
  136246. };
  136247. static long _vq_lengthlist__44u7__p9_1[] = {
  136248. 1, 4, 4, 6, 5, 8, 6, 9, 8,10, 9,11,10, 4, 6, 6,
  136249. 8, 8, 9, 9,11,10,11,11,11,11, 4, 6, 6, 8, 8,10,
  136250. 9,11,11,11,11,11,12, 6, 8, 8,10,10,11,11,12,12,
  136251. 13,12,13,13, 6, 8, 8,10,10,11,11,12,12,12,13,14,
  136252. 13, 8,10,10,11,11,12,13,14,14,14,14,15,15, 8,10,
  136253. 10,11,12,12,13,13,14,14,14,14,15, 9,11,11,13,13,
  136254. 14,14,15,14,16,15,17,15, 9,11,11,12,13,14,14,15,
  136255. 14,15,15,15,16,10,12,12,13,14,15,15,15,15,16,17,
  136256. 16,17,10,13,12,13,14,14,16,16,16,16,15,16,17,11,
  136257. 13,13,14,15,14,17,15,16,17,17,17,17,11,13,13,14,
  136258. 15,15,15,15,17,17,16,17,16,
  136259. };
  136260. static float _vq_quantthresh__44u7__p9_1[] = {
  136261. -269.5, -220.5, -171.5, -122.5, -73.5, -24.5, 24.5, 73.5,
  136262. 122.5, 171.5, 220.5, 269.5,
  136263. };
  136264. static long _vq_quantmap__44u7__p9_1[] = {
  136265. 11, 9, 7, 5, 3, 1, 0, 2,
  136266. 4, 6, 8, 10, 12,
  136267. };
  136268. static encode_aux_threshmatch _vq_auxt__44u7__p9_1 = {
  136269. _vq_quantthresh__44u7__p9_1,
  136270. _vq_quantmap__44u7__p9_1,
  136271. 13,
  136272. 13
  136273. };
  136274. static static_codebook _44u7__p9_1 = {
  136275. 2, 169,
  136276. _vq_lengthlist__44u7__p9_1,
  136277. 1, -518889472, 1622704128, 4, 0,
  136278. _vq_quantlist__44u7__p9_1,
  136279. NULL,
  136280. &_vq_auxt__44u7__p9_1,
  136281. NULL,
  136282. 0
  136283. };
  136284. static long _vq_quantlist__44u7__p9_2[] = {
  136285. 24,
  136286. 23,
  136287. 25,
  136288. 22,
  136289. 26,
  136290. 21,
  136291. 27,
  136292. 20,
  136293. 28,
  136294. 19,
  136295. 29,
  136296. 18,
  136297. 30,
  136298. 17,
  136299. 31,
  136300. 16,
  136301. 32,
  136302. 15,
  136303. 33,
  136304. 14,
  136305. 34,
  136306. 13,
  136307. 35,
  136308. 12,
  136309. 36,
  136310. 11,
  136311. 37,
  136312. 10,
  136313. 38,
  136314. 9,
  136315. 39,
  136316. 8,
  136317. 40,
  136318. 7,
  136319. 41,
  136320. 6,
  136321. 42,
  136322. 5,
  136323. 43,
  136324. 4,
  136325. 44,
  136326. 3,
  136327. 45,
  136328. 2,
  136329. 46,
  136330. 1,
  136331. 47,
  136332. 0,
  136333. 48,
  136334. };
  136335. static long _vq_lengthlist__44u7__p9_2[] = {
  136336. 2, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6,
  136337. 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  136338. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  136339. 8,
  136340. };
  136341. static float _vq_quantthresh__44u7__p9_2[] = {
  136342. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  136343. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  136344. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  136345. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  136346. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  136347. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  136348. };
  136349. static long _vq_quantmap__44u7__p9_2[] = {
  136350. 47, 45, 43, 41, 39, 37, 35, 33,
  136351. 31, 29, 27, 25, 23, 21, 19, 17,
  136352. 15, 13, 11, 9, 7, 5, 3, 1,
  136353. 0, 2, 4, 6, 8, 10, 12, 14,
  136354. 16, 18, 20, 22, 24, 26, 28, 30,
  136355. 32, 34, 36, 38, 40, 42, 44, 46,
  136356. 48,
  136357. };
  136358. static encode_aux_threshmatch _vq_auxt__44u7__p9_2 = {
  136359. _vq_quantthresh__44u7__p9_2,
  136360. _vq_quantmap__44u7__p9_2,
  136361. 49,
  136362. 49
  136363. };
  136364. static static_codebook _44u7__p9_2 = {
  136365. 1, 49,
  136366. _vq_lengthlist__44u7__p9_2,
  136367. 1, -526909440, 1611661312, 6, 0,
  136368. _vq_quantlist__44u7__p9_2,
  136369. NULL,
  136370. &_vq_auxt__44u7__p9_2,
  136371. NULL,
  136372. 0
  136373. };
  136374. static long _huff_lengthlist__44u7__short[] = {
  136375. 5,12,17,16,16,17,17,17,17,17, 4, 7,11,11,12, 9,
  136376. 17,10,17,17, 7, 7, 8, 9, 7, 9,11,10,15,17, 7, 9,
  136377. 10,11,10,12,14,12,16,17, 7, 8, 5, 7, 4, 7, 7, 8,
  136378. 16,16, 6,10, 9,10, 7,10,11,11,16,17, 6, 8, 8, 9,
  136379. 5, 7, 5, 8,16,17, 5, 5, 8, 7, 6, 7, 7, 6, 6,14,
  136380. 12,10,12,11, 7,11, 4, 4, 2, 7,17,15,15,15, 8,15,
  136381. 6, 8, 5, 9,
  136382. };
  136383. static static_codebook _huff_book__44u7__short = {
  136384. 2, 100,
  136385. _huff_lengthlist__44u7__short,
  136386. 0, 0, 0, 0, 0,
  136387. NULL,
  136388. NULL,
  136389. NULL,
  136390. NULL,
  136391. 0
  136392. };
  136393. static long _huff_lengthlist__44u8__long[] = {
  136394. 3, 9,13,14,14,15,14,14,15,15, 5, 4, 6, 8,10,12,
  136395. 12,14,15,15, 9, 5, 4, 5, 8,10,11,13,16,16,10, 7,
  136396. 4, 3, 5, 7, 9,11,13,13,10, 9, 7, 4, 4, 6, 8,10,
  136397. 12,14,13,11, 9, 6, 5, 5, 6, 8,12,14,13,11,10, 8,
  136398. 7, 6, 6, 7,10,14,13,11,12,10, 8, 7, 6, 6, 9,13,
  136399. 12,11,14,12,11, 9, 8, 7, 9,11,11,12,14,13,14,11,
  136400. 10, 8, 8, 9,
  136401. };
  136402. static static_codebook _huff_book__44u8__long = {
  136403. 2, 100,
  136404. _huff_lengthlist__44u8__long,
  136405. 0, 0, 0, 0, 0,
  136406. NULL,
  136407. NULL,
  136408. NULL,
  136409. NULL,
  136410. 0
  136411. };
  136412. static long _huff_lengthlist__44u8__short[] = {
  136413. 6,14,18,18,17,17,17,17,17,17, 4, 7, 9, 9,10,13,
  136414. 15,17,17,17, 6, 7, 5, 6, 8,11,16,17,16,17, 5, 7,
  136415. 5, 4, 6,10,14,17,17,17, 6, 6, 6, 5, 7,10,13,16,
  136416. 17,17, 7, 6, 7, 7, 7, 8, 7,10,15,16,12, 9, 9, 6,
  136417. 6, 5, 3, 5,11,15,14,14,13, 5, 5, 7, 3, 4, 8,15,
  136418. 17,17,13, 7, 7,10, 6, 6,10,15,17,17,16,10,11,14,
  136419. 10,10,15,17,
  136420. };
  136421. static static_codebook _huff_book__44u8__short = {
  136422. 2, 100,
  136423. _huff_lengthlist__44u8__short,
  136424. 0, 0, 0, 0, 0,
  136425. NULL,
  136426. NULL,
  136427. NULL,
  136428. NULL,
  136429. 0
  136430. };
  136431. static long _vq_quantlist__44u8_p1_0[] = {
  136432. 1,
  136433. 0,
  136434. 2,
  136435. };
  136436. static long _vq_lengthlist__44u8_p1_0[] = {
  136437. 1, 5, 5, 5, 7, 7, 5, 7, 7, 5, 7, 7, 8, 9, 9, 7,
  136438. 9, 9, 5, 7, 7, 7, 9, 9, 8, 9, 9, 5, 7, 7, 7, 9,
  136439. 9, 7, 9, 9, 7, 9, 9, 9,10,11, 9,11,10, 7, 9, 9,
  136440. 9,11,10, 9,10,11, 5, 7, 7, 7, 9, 9, 7, 9, 9, 7,
  136441. 9, 9, 9,11,10, 9,10,10, 8, 9, 9, 9,11,11, 9,11,
  136442. 10,
  136443. };
  136444. static float _vq_quantthresh__44u8_p1_0[] = {
  136445. -0.5, 0.5,
  136446. };
  136447. static long _vq_quantmap__44u8_p1_0[] = {
  136448. 1, 0, 2,
  136449. };
  136450. static encode_aux_threshmatch _vq_auxt__44u8_p1_0 = {
  136451. _vq_quantthresh__44u8_p1_0,
  136452. _vq_quantmap__44u8_p1_0,
  136453. 3,
  136454. 3
  136455. };
  136456. static static_codebook _44u8_p1_0 = {
  136457. 4, 81,
  136458. _vq_lengthlist__44u8_p1_0,
  136459. 1, -535822336, 1611661312, 2, 0,
  136460. _vq_quantlist__44u8_p1_0,
  136461. NULL,
  136462. &_vq_auxt__44u8_p1_0,
  136463. NULL,
  136464. 0
  136465. };
  136466. static long _vq_quantlist__44u8_p2_0[] = {
  136467. 2,
  136468. 1,
  136469. 3,
  136470. 0,
  136471. 4,
  136472. };
  136473. static long _vq_lengthlist__44u8_p2_0[] = {
  136474. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  136475. 9, 9,11,11, 8, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  136476. 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12, 9,10,10,
  136477. 11,12, 5, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 8,10,
  136478. 10, 9,10, 9,12,11, 9,10,10,12,12, 8, 9, 9,12,11,
  136479. 9,10,10,12,12, 9,10,10,12,12,11,12,12,14,14,11,
  136480. 11,12,13,14, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  136481. 10,12,12,11,12,11,13,13,11,12,12,14,14, 5, 7, 7,
  136482. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,
  136483. 12, 9,10,10,11,12, 7, 8, 8,10,10, 8, 9, 9,11,11,
  136484. 8, 9, 9,11,11,10,11,11,12,13,10,11,11,12,13, 6,
  136485. 8, 8,10,10, 8, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  136486. 10,13,12,10,11,11,13,13, 9,10,10,12,12,10,11,11,
  136487. 13,13,10,11,11,13,13,12,12,13,13,14,12,13,13,14,
  136488. 14, 9,10,10,12,12,10,11,10,13,12,10,11,11,13,13,
  136489. 11,13,12,14,13,12,13,13,14,14, 5, 7, 7, 9, 9, 7,
  136490. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12, 9,10,
  136491. 10,12,12, 7, 8, 8,10,10, 8, 9, 9,11,11, 8, 8, 9,
  136492. 10,11,10,11,11,13,13,10,10,11,12,13, 7, 8, 8,10,
  136493. 10, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,11,13,13,
  136494. 10,11,11,13,12, 9,10,10,12,12,10,11,11,13,13,10,
  136495. 10,11,12,13,12,13,13,14,14,12,12,13,13,14, 9,10,
  136496. 10,12,12,10,11,11,13,13,10,11,11,13,13,12,13,13,
  136497. 15,14,12,13,13,14,13, 8, 9, 9,11,11, 9,10,10,12,
  136498. 12, 9,10,10,12,12,12,12,12,14,13,11,12,12,14,14,
  136499. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,13,12,
  136500. 13,13,14,15,12,13,13,14,15, 9,10,10,12,12,10,11,
  136501. 10,13,12,10,11,11,13,13,12,13,12,15,14,12,13,13,
  136502. 14,15,11,12,12,14,14,12,13,13,14,14,12,13,13,15,
  136503. 14,14,14,14,14,16,14,14,15,16,16,11,12,12,14,14,
  136504. 11,12,12,14,14,12,13,13,14,15,13,14,13,16,14,14,
  136505. 14,14,16,16, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  136506. 10,12,12,11,12,12,14,13,11,12,12,14,14, 9,10,10,
  136507. 12,12,10,11,11,13,13,10,10,11,12,13,12,13,13,15,
  136508. 14,12,12,13,13,14, 9,10,10,12,12,10,11,11,13,13,
  136509. 10,11,11,13,13,12,13,13,14,14,12,13,13,15,14,11,
  136510. 12,12,14,13,12,13,13,15,14,11,12,12,13,14,14,15,
  136511. 14,16,15,13,13,14,13,16,11,12,12,14,14,12,13,13,
  136512. 14,15,12,13,12,15,14,14,14,14,16,15,14,15,13,16,
  136513. 14,
  136514. };
  136515. static float _vq_quantthresh__44u8_p2_0[] = {
  136516. -1.5, -0.5, 0.5, 1.5,
  136517. };
  136518. static long _vq_quantmap__44u8_p2_0[] = {
  136519. 3, 1, 0, 2, 4,
  136520. };
  136521. static encode_aux_threshmatch _vq_auxt__44u8_p2_0 = {
  136522. _vq_quantthresh__44u8_p2_0,
  136523. _vq_quantmap__44u8_p2_0,
  136524. 5,
  136525. 5
  136526. };
  136527. static static_codebook _44u8_p2_0 = {
  136528. 4, 625,
  136529. _vq_lengthlist__44u8_p2_0,
  136530. 1, -533725184, 1611661312, 3, 0,
  136531. _vq_quantlist__44u8_p2_0,
  136532. NULL,
  136533. &_vq_auxt__44u8_p2_0,
  136534. NULL,
  136535. 0
  136536. };
  136537. static long _vq_quantlist__44u8_p3_0[] = {
  136538. 4,
  136539. 3,
  136540. 5,
  136541. 2,
  136542. 6,
  136543. 1,
  136544. 7,
  136545. 0,
  136546. 8,
  136547. };
  136548. static long _vq_lengthlist__44u8_p3_0[] = {
  136549. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 7, 7,
  136550. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  136551. 8, 8,10,10, 6, 6, 6, 7, 7, 8, 8,10,10, 7, 7, 7,
  136552. 8, 8, 9, 9,11,10, 7, 7, 7, 8, 8, 9, 9,10,11, 9,
  136553. 9, 9,10,10,11,10,12,11, 9, 9, 9, 9,10,11,11,11,
  136554. 12,
  136555. };
  136556. static float _vq_quantthresh__44u8_p3_0[] = {
  136557. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  136558. };
  136559. static long _vq_quantmap__44u8_p3_0[] = {
  136560. 7, 5, 3, 1, 0, 2, 4, 6,
  136561. 8,
  136562. };
  136563. static encode_aux_threshmatch _vq_auxt__44u8_p3_0 = {
  136564. _vq_quantthresh__44u8_p3_0,
  136565. _vq_quantmap__44u8_p3_0,
  136566. 9,
  136567. 9
  136568. };
  136569. static static_codebook _44u8_p3_0 = {
  136570. 2, 81,
  136571. _vq_lengthlist__44u8_p3_0,
  136572. 1, -531628032, 1611661312, 4, 0,
  136573. _vq_quantlist__44u8_p3_0,
  136574. NULL,
  136575. &_vq_auxt__44u8_p3_0,
  136576. NULL,
  136577. 0
  136578. };
  136579. static long _vq_quantlist__44u8_p4_0[] = {
  136580. 8,
  136581. 7,
  136582. 9,
  136583. 6,
  136584. 10,
  136585. 5,
  136586. 11,
  136587. 4,
  136588. 12,
  136589. 3,
  136590. 13,
  136591. 2,
  136592. 14,
  136593. 1,
  136594. 15,
  136595. 0,
  136596. 16,
  136597. };
  136598. static long _vq_lengthlist__44u8_p4_0[] = {
  136599. 4, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8,10,10,11,11,11,
  136600. 11, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,
  136601. 12,12, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  136602. 11,12,12, 6, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  136603. 11,11,12,12, 6, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,
  136604. 10,11,11,12,12, 7, 7, 7, 8, 8, 9, 8,10, 9,10, 9,
  136605. 11,10,12,11,13,12, 7, 7, 7, 8, 8, 8, 9, 9,10, 9,
  136606. 10,10,11,11,12,12,13, 8, 8, 8, 9, 9, 9, 9,10,10,
  136607. 11,10,11,11,12,12,13,13, 8, 8, 8, 9, 9, 9,10,10,
  136608. 10,10,11,11,11,12,12,12,13, 8, 9, 9, 9, 9,10, 9,
  136609. 11,10,11,11,12,11,13,12,13,13, 8, 9, 9, 9, 9, 9,
  136610. 10,10,11,11,11,11,12,12,13,13,13,10,10,10,10,10,
  136611. 11,10,11,11,12,11,13,12,13,13,14,13,10,10,10,10,
  136612. 10,10,11,11,11,11,12,12,13,13,13,13,14,11,11,11,
  136613. 11,11,12,11,12,12,13,12,13,13,14,13,14,14,11,11,
  136614. 11,11,11,11,12,12,12,12,13,13,13,13,14,14,14,11,
  136615. 12,12,12,12,13,12,13,12,13,13,14,13,14,14,14,14,
  136616. 11,12,12,12,12,12,12,13,13,13,13,13,14,14,14,14,
  136617. 14,
  136618. };
  136619. static float _vq_quantthresh__44u8_p4_0[] = {
  136620. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  136621. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  136622. };
  136623. static long _vq_quantmap__44u8_p4_0[] = {
  136624. 15, 13, 11, 9, 7, 5, 3, 1,
  136625. 0, 2, 4, 6, 8, 10, 12, 14,
  136626. 16,
  136627. };
  136628. static encode_aux_threshmatch _vq_auxt__44u8_p4_0 = {
  136629. _vq_quantthresh__44u8_p4_0,
  136630. _vq_quantmap__44u8_p4_0,
  136631. 17,
  136632. 17
  136633. };
  136634. static static_codebook _44u8_p4_0 = {
  136635. 2, 289,
  136636. _vq_lengthlist__44u8_p4_0,
  136637. 1, -529530880, 1611661312, 5, 0,
  136638. _vq_quantlist__44u8_p4_0,
  136639. NULL,
  136640. &_vq_auxt__44u8_p4_0,
  136641. NULL,
  136642. 0
  136643. };
  136644. static long _vq_quantlist__44u8_p5_0[] = {
  136645. 1,
  136646. 0,
  136647. 2,
  136648. };
  136649. static long _vq_lengthlist__44u8_p5_0[] = {
  136650. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 8, 9, 9, 7,
  136651. 9, 9, 5, 8, 8, 7, 9, 9, 8, 9, 9, 5, 8, 8, 8,10,
  136652. 10, 8,10,10, 7,10,10, 9,10,12, 9,12,11, 7,10,10,
  136653. 9,11,10, 9,11,12, 5, 8, 8, 8,10,10, 8,10,10, 7,
  136654. 10,10, 9,11,11, 9,10,11, 7,10,10, 9,11,11,10,12,
  136655. 10,
  136656. };
  136657. static float _vq_quantthresh__44u8_p5_0[] = {
  136658. -5.5, 5.5,
  136659. };
  136660. static long _vq_quantmap__44u8_p5_0[] = {
  136661. 1, 0, 2,
  136662. };
  136663. static encode_aux_threshmatch _vq_auxt__44u8_p5_0 = {
  136664. _vq_quantthresh__44u8_p5_0,
  136665. _vq_quantmap__44u8_p5_0,
  136666. 3,
  136667. 3
  136668. };
  136669. static static_codebook _44u8_p5_0 = {
  136670. 4, 81,
  136671. _vq_lengthlist__44u8_p5_0,
  136672. 1, -529137664, 1618345984, 2, 0,
  136673. _vq_quantlist__44u8_p5_0,
  136674. NULL,
  136675. &_vq_auxt__44u8_p5_0,
  136676. NULL,
  136677. 0
  136678. };
  136679. static long _vq_quantlist__44u8_p5_1[] = {
  136680. 5,
  136681. 4,
  136682. 6,
  136683. 3,
  136684. 7,
  136685. 2,
  136686. 8,
  136687. 1,
  136688. 9,
  136689. 0,
  136690. 10,
  136691. };
  136692. static long _vq_lengthlist__44u8_p5_1[] = {
  136693. 4, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 5, 5, 5, 6, 6,
  136694. 7, 7, 8, 8, 8, 8, 5, 5, 5, 6, 6, 7, 7, 7, 8, 8,
  136695. 8, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 6, 6, 6, 7,
  136696. 7, 7, 7, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8, 8,
  136697. 8, 8, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 7, 8, 7,
  136698. 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8,
  136699. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 8, 8,
  136700. 8, 8, 8, 8, 8, 8, 8, 9, 9,
  136701. };
  136702. static float _vq_quantthresh__44u8_p5_1[] = {
  136703. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  136704. 3.5, 4.5,
  136705. };
  136706. static long _vq_quantmap__44u8_p5_1[] = {
  136707. 9, 7, 5, 3, 1, 0, 2, 4,
  136708. 6, 8, 10,
  136709. };
  136710. static encode_aux_threshmatch _vq_auxt__44u8_p5_1 = {
  136711. _vq_quantthresh__44u8_p5_1,
  136712. _vq_quantmap__44u8_p5_1,
  136713. 11,
  136714. 11
  136715. };
  136716. static static_codebook _44u8_p5_1 = {
  136717. 2, 121,
  136718. _vq_lengthlist__44u8_p5_1,
  136719. 1, -531365888, 1611661312, 4, 0,
  136720. _vq_quantlist__44u8_p5_1,
  136721. NULL,
  136722. &_vq_auxt__44u8_p5_1,
  136723. NULL,
  136724. 0
  136725. };
  136726. static long _vq_quantlist__44u8_p6_0[] = {
  136727. 6,
  136728. 5,
  136729. 7,
  136730. 4,
  136731. 8,
  136732. 3,
  136733. 9,
  136734. 2,
  136735. 10,
  136736. 1,
  136737. 11,
  136738. 0,
  136739. 12,
  136740. };
  136741. static long _vq_lengthlist__44u8_p6_0[] = {
  136742. 2, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 4, 6, 5,
  136743. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 4, 6, 6, 7, 7, 8,
  136744. 8, 8, 8, 9, 9,10,10, 6, 7, 7, 7, 8, 8, 8, 8, 9,
  136745. 9,10,10,10, 6, 7, 7, 8, 8, 8, 8, 9, 8,10, 9,11,
  136746. 10, 7, 8, 8, 8, 8, 8, 9, 9, 9,10,10,11,11, 7, 8,
  136747. 8, 8, 8, 9, 8, 9, 9,10,10,11,11, 8, 8, 8, 9, 9,
  136748. 9, 9, 9,10,10,10,11,11, 8, 8, 8, 9, 9, 9, 9,10,
  136749. 9,10,10,11,11, 9, 9, 9, 9,10,10,10,10,10,10,11,
  136750. 11,12, 9, 9, 9,10, 9,10,10,10,10,11,10,12,11,10,
  136751. 10,10,10,10,11,11,11,11,11,12,12,12,10,10,10,10,
  136752. 11,11,11,11,11,12,11,12,12,
  136753. };
  136754. static float _vq_quantthresh__44u8_p6_0[] = {
  136755. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  136756. 12.5, 17.5, 22.5, 27.5,
  136757. };
  136758. static long _vq_quantmap__44u8_p6_0[] = {
  136759. 11, 9, 7, 5, 3, 1, 0, 2,
  136760. 4, 6, 8, 10, 12,
  136761. };
  136762. static encode_aux_threshmatch _vq_auxt__44u8_p6_0 = {
  136763. _vq_quantthresh__44u8_p6_0,
  136764. _vq_quantmap__44u8_p6_0,
  136765. 13,
  136766. 13
  136767. };
  136768. static static_codebook _44u8_p6_0 = {
  136769. 2, 169,
  136770. _vq_lengthlist__44u8_p6_0,
  136771. 1, -526516224, 1616117760, 4, 0,
  136772. _vq_quantlist__44u8_p6_0,
  136773. NULL,
  136774. &_vq_auxt__44u8_p6_0,
  136775. NULL,
  136776. 0
  136777. };
  136778. static long _vq_quantlist__44u8_p6_1[] = {
  136779. 2,
  136780. 1,
  136781. 3,
  136782. 0,
  136783. 4,
  136784. };
  136785. static long _vq_lengthlist__44u8_p6_1[] = {
  136786. 3, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5,
  136787. 5, 5, 5, 5, 5, 5, 5, 5, 5,
  136788. };
  136789. static float _vq_quantthresh__44u8_p6_1[] = {
  136790. -1.5, -0.5, 0.5, 1.5,
  136791. };
  136792. static long _vq_quantmap__44u8_p6_1[] = {
  136793. 3, 1, 0, 2, 4,
  136794. };
  136795. static encode_aux_threshmatch _vq_auxt__44u8_p6_1 = {
  136796. _vq_quantthresh__44u8_p6_1,
  136797. _vq_quantmap__44u8_p6_1,
  136798. 5,
  136799. 5
  136800. };
  136801. static static_codebook _44u8_p6_1 = {
  136802. 2, 25,
  136803. _vq_lengthlist__44u8_p6_1,
  136804. 1, -533725184, 1611661312, 3, 0,
  136805. _vq_quantlist__44u8_p6_1,
  136806. NULL,
  136807. &_vq_auxt__44u8_p6_1,
  136808. NULL,
  136809. 0
  136810. };
  136811. static long _vq_quantlist__44u8_p7_0[] = {
  136812. 6,
  136813. 5,
  136814. 7,
  136815. 4,
  136816. 8,
  136817. 3,
  136818. 9,
  136819. 2,
  136820. 10,
  136821. 1,
  136822. 11,
  136823. 0,
  136824. 12,
  136825. };
  136826. static long _vq_lengthlist__44u8_p7_0[] = {
  136827. 1, 4, 5, 6, 6, 7, 7, 8, 8,10,10,11,11, 5, 6, 6,
  136828. 7, 7, 8, 8, 9, 9,11,10,12,11, 5, 6, 6, 7, 7, 8,
  136829. 8, 9, 9,10,11,11,12, 6, 7, 7, 8, 8, 9, 9,10,10,
  136830. 11,11,12,12, 6, 7, 7, 8, 8, 9, 9,10,10,11,12,13,
  136831. 12, 7, 8, 8, 9, 9,10,10,11,11,12,12,13,13, 8, 8,
  136832. 8, 9, 9,10,10,11,11,12,12,13,13, 9, 9, 9,10,10,
  136833. 11,11,12,12,13,13,14,14, 9, 9, 9,10,10,11,11,12,
  136834. 12,13,13,14,14,10,11,11,12,11,13,12,13,13,14,14,
  136835. 15,15,10,11,11,11,12,12,13,13,14,14,14,15,15,11,
  136836. 12,12,13,13,14,13,15,14,15,15,16,15,11,11,12,13,
  136837. 13,13,14,14,14,15,15,15,16,
  136838. };
  136839. static float _vq_quantthresh__44u8_p7_0[] = {
  136840. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  136841. 27.5, 38.5, 49.5, 60.5,
  136842. };
  136843. static long _vq_quantmap__44u8_p7_0[] = {
  136844. 11, 9, 7, 5, 3, 1, 0, 2,
  136845. 4, 6, 8, 10, 12,
  136846. };
  136847. static encode_aux_threshmatch _vq_auxt__44u8_p7_0 = {
  136848. _vq_quantthresh__44u8_p7_0,
  136849. _vq_quantmap__44u8_p7_0,
  136850. 13,
  136851. 13
  136852. };
  136853. static static_codebook _44u8_p7_0 = {
  136854. 2, 169,
  136855. _vq_lengthlist__44u8_p7_0,
  136856. 1, -523206656, 1618345984, 4, 0,
  136857. _vq_quantlist__44u8_p7_0,
  136858. NULL,
  136859. &_vq_auxt__44u8_p7_0,
  136860. NULL,
  136861. 0
  136862. };
  136863. static long _vq_quantlist__44u8_p7_1[] = {
  136864. 5,
  136865. 4,
  136866. 6,
  136867. 3,
  136868. 7,
  136869. 2,
  136870. 8,
  136871. 1,
  136872. 9,
  136873. 0,
  136874. 10,
  136875. };
  136876. static long _vq_lengthlist__44u8_p7_1[] = {
  136877. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7,
  136878. 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7, 7, 7, 7, 7, 7,
  136879. 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 6, 7, 7, 7,
  136880. 7, 7, 7, 7, 7, 7, 8, 7, 7, 7, 7, 7, 7, 7, 8, 8,
  136881. 8, 8, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 7, 7, 7,
  136882. 8, 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8,
  136883. 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7,
  136884. 7, 8, 8, 8, 8, 8, 8, 8, 8,
  136885. };
  136886. static float _vq_quantthresh__44u8_p7_1[] = {
  136887. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  136888. 3.5, 4.5,
  136889. };
  136890. static long _vq_quantmap__44u8_p7_1[] = {
  136891. 9, 7, 5, 3, 1, 0, 2, 4,
  136892. 6, 8, 10,
  136893. };
  136894. static encode_aux_threshmatch _vq_auxt__44u8_p7_1 = {
  136895. _vq_quantthresh__44u8_p7_1,
  136896. _vq_quantmap__44u8_p7_1,
  136897. 11,
  136898. 11
  136899. };
  136900. static static_codebook _44u8_p7_1 = {
  136901. 2, 121,
  136902. _vq_lengthlist__44u8_p7_1,
  136903. 1, -531365888, 1611661312, 4, 0,
  136904. _vq_quantlist__44u8_p7_1,
  136905. NULL,
  136906. &_vq_auxt__44u8_p7_1,
  136907. NULL,
  136908. 0
  136909. };
  136910. static long _vq_quantlist__44u8_p8_0[] = {
  136911. 7,
  136912. 6,
  136913. 8,
  136914. 5,
  136915. 9,
  136916. 4,
  136917. 10,
  136918. 3,
  136919. 11,
  136920. 2,
  136921. 12,
  136922. 1,
  136923. 13,
  136924. 0,
  136925. 14,
  136926. };
  136927. static long _vq_lengthlist__44u8_p8_0[] = {
  136928. 1, 4, 4, 7, 7, 8, 8, 8, 7, 9, 8,10, 9,11,10, 4,
  136929. 6, 6, 8, 8,10, 9, 9, 9,10,10,11,10,12,10, 4, 6,
  136930. 6, 8, 8,10,10, 9, 9,10,10,11,11,11,12, 7, 8, 8,
  136931. 10,10,11,11,11,10,12,11,12,12,13,11, 7, 8, 8,10,
  136932. 10,11,11,10,10,11,11,12,12,13,13, 8,10,10,11,11,
  136933. 12,11,12,11,13,12,13,12,14,13, 8,10, 9,11,11,12,
  136934. 12,12,12,12,12,13,13,14,13, 8, 9, 9,11,10,12,11,
  136935. 13,12,13,13,14,13,14,13, 8, 9, 9,10,11,12,12,12,
  136936. 12,13,13,14,15,14,14, 9,10,10,12,11,13,12,13,13,
  136937. 14,13,14,14,14,14, 9,10,10,12,12,12,12,13,13,14,
  136938. 14,14,15,14,14,10,11,11,13,12,13,12,14,14,14,14,
  136939. 14,14,15,15,10,11,11,12,12,13,13,14,14,14,15,15,
  136940. 14,16,15,11,12,12,13,12,14,14,14,13,15,14,15,15,
  136941. 15,17,11,12,12,13,13,14,14,14,15,15,14,15,15,14,
  136942. 17,
  136943. };
  136944. static float _vq_quantthresh__44u8_p8_0[] = {
  136945. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  136946. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  136947. };
  136948. static long _vq_quantmap__44u8_p8_0[] = {
  136949. 13, 11, 9, 7, 5, 3, 1, 0,
  136950. 2, 4, 6, 8, 10, 12, 14,
  136951. };
  136952. static encode_aux_threshmatch _vq_auxt__44u8_p8_0 = {
  136953. _vq_quantthresh__44u8_p8_0,
  136954. _vq_quantmap__44u8_p8_0,
  136955. 15,
  136956. 15
  136957. };
  136958. static static_codebook _44u8_p8_0 = {
  136959. 2, 225,
  136960. _vq_lengthlist__44u8_p8_0,
  136961. 1, -520986624, 1620377600, 4, 0,
  136962. _vq_quantlist__44u8_p8_0,
  136963. NULL,
  136964. &_vq_auxt__44u8_p8_0,
  136965. NULL,
  136966. 0
  136967. };
  136968. static long _vq_quantlist__44u8_p8_1[] = {
  136969. 10,
  136970. 9,
  136971. 11,
  136972. 8,
  136973. 12,
  136974. 7,
  136975. 13,
  136976. 6,
  136977. 14,
  136978. 5,
  136979. 15,
  136980. 4,
  136981. 16,
  136982. 3,
  136983. 17,
  136984. 2,
  136985. 18,
  136986. 1,
  136987. 19,
  136988. 0,
  136989. 20,
  136990. };
  136991. static long _vq_lengthlist__44u8_p8_1[] = {
  136992. 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  136993. 9, 9, 9, 9, 9, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  136994. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 5, 6, 6, 7, 7, 8,
  136995. 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 7,
  136996. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  136997. 9, 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  136998. 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9,
  136999. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,10, 8, 8,
  137000. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,
  137001. 10, 9,10, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,
  137002. 10,10,10,10,10,10,10,10, 8, 9, 8, 9, 9, 9, 9, 9,
  137003. 9, 9, 9, 9, 9, 9,10,10,10,10, 9,10,10, 9, 9, 9,
  137004. 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,10,10,
  137005. 10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,
  137006. 10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9,10, 9,
  137007. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  137008. 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,
  137009. 10, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  137010. 10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  137011. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,
  137012. 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  137013. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  137014. 10,10,10,10,10, 9, 9, 9,10, 9,10,10,10,10,10,10,
  137015. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  137016. 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  137017. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  137018. 10,10,10,10, 9, 9, 9,10, 9,10, 9,10,10,10,10,10,
  137019. 10,10,10,10,10,10,10,10,10,
  137020. };
  137021. static float _vq_quantthresh__44u8_p8_1[] = {
  137022. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  137023. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  137024. 6.5, 7.5, 8.5, 9.5,
  137025. };
  137026. static long _vq_quantmap__44u8_p8_1[] = {
  137027. 19, 17, 15, 13, 11, 9, 7, 5,
  137028. 3, 1, 0, 2, 4, 6, 8, 10,
  137029. 12, 14, 16, 18, 20,
  137030. };
  137031. static encode_aux_threshmatch _vq_auxt__44u8_p8_1 = {
  137032. _vq_quantthresh__44u8_p8_1,
  137033. _vq_quantmap__44u8_p8_1,
  137034. 21,
  137035. 21
  137036. };
  137037. static static_codebook _44u8_p8_1 = {
  137038. 2, 441,
  137039. _vq_lengthlist__44u8_p8_1,
  137040. 1, -529268736, 1611661312, 5, 0,
  137041. _vq_quantlist__44u8_p8_1,
  137042. NULL,
  137043. &_vq_auxt__44u8_p8_1,
  137044. NULL,
  137045. 0
  137046. };
  137047. static long _vq_quantlist__44u8_p9_0[] = {
  137048. 4,
  137049. 3,
  137050. 5,
  137051. 2,
  137052. 6,
  137053. 1,
  137054. 7,
  137055. 0,
  137056. 8,
  137057. };
  137058. static long _vq_lengthlist__44u8_p9_0[] = {
  137059. 1, 3, 3, 9, 9, 9, 9, 9, 9, 4, 9, 9, 9, 9, 9, 9,
  137060. 9, 9, 5, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137061. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137062. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137063. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8,
  137064. 8,
  137065. };
  137066. static float _vq_quantthresh__44u8_p9_0[] = {
  137067. -3258.5, -2327.5, -1396.5, -465.5, 465.5, 1396.5, 2327.5, 3258.5,
  137068. };
  137069. static long _vq_quantmap__44u8_p9_0[] = {
  137070. 7, 5, 3, 1, 0, 2, 4, 6,
  137071. 8,
  137072. };
  137073. static encode_aux_threshmatch _vq_auxt__44u8_p9_0 = {
  137074. _vq_quantthresh__44u8_p9_0,
  137075. _vq_quantmap__44u8_p9_0,
  137076. 9,
  137077. 9
  137078. };
  137079. static static_codebook _44u8_p9_0 = {
  137080. 2, 81,
  137081. _vq_lengthlist__44u8_p9_0,
  137082. 1, -511895552, 1631393792, 4, 0,
  137083. _vq_quantlist__44u8_p9_0,
  137084. NULL,
  137085. &_vq_auxt__44u8_p9_0,
  137086. NULL,
  137087. 0
  137088. };
  137089. static long _vq_quantlist__44u8_p9_1[] = {
  137090. 9,
  137091. 8,
  137092. 10,
  137093. 7,
  137094. 11,
  137095. 6,
  137096. 12,
  137097. 5,
  137098. 13,
  137099. 4,
  137100. 14,
  137101. 3,
  137102. 15,
  137103. 2,
  137104. 16,
  137105. 1,
  137106. 17,
  137107. 0,
  137108. 18,
  137109. };
  137110. static long _vq_lengthlist__44u8_p9_1[] = {
  137111. 1, 4, 4, 7, 7, 8, 7, 8, 6, 9, 7,10, 8,11,10,11,
  137112. 11,11,11, 4, 7, 6, 9, 9,10, 9, 9, 9,10,10,11,10,
  137113. 11,10,11,11,13,11, 4, 7, 7, 9, 9, 9, 9, 9, 9,10,
  137114. 10,11,10,11,11,11,12,11,12, 7, 9, 8,11,11,11,11,
  137115. 10,10,11,11,12,12,12,12,12,12,14,13, 7, 8, 9,10,
  137116. 11,11,11,10,10,11,11,11,11,12,12,14,12,13,14, 8,
  137117. 9, 9,11,11,11,11,11,11,12,12,14,12,15,14,14,14,
  137118. 15,14, 8, 9, 9,11,11,11,11,12,11,12,12,13,13,13,
  137119. 13,13,13,14,14, 8, 9, 9,11,10,12,11,12,12,13,13,
  137120. 13,13,15,14,14,14,16,16, 8, 9, 9,10,11,11,12,12,
  137121. 12,13,13,13,14,14,14,15,16,15,15, 9,10,10,11,12,
  137122. 12,13,13,13,14,14,16,14,14,16,16,16,16,15, 9,10,
  137123. 10,11,11,12,13,13,14,15,14,16,14,15,16,16,16,16,
  137124. 15,10,11,11,12,13,13,14,15,15,15,15,15,16,15,16,
  137125. 15,16,15,15,10,11,11,13,13,14,13,13,15,14,15,15,
  137126. 16,15,15,15,16,15,16,10,12,12,14,14,14,14,14,16,
  137127. 16,15,15,15,16,16,16,16,16,16,11,12,12,14,14,14,
  137128. 14,15,15,16,15,16,15,16,15,16,16,16,16,12,12,13,
  137129. 14,14,15,16,16,16,16,16,16,15,16,16,16,16,16,16,
  137130. 12,13,13,14,14,14,14,15,16,15,16,16,16,16,16,16,
  137131. 16,16,16,12,13,14,14,14,16,15,16,15,16,16,16,16,
  137132. 16,16,16,16,16,16,12,14,13,14,15,15,15,16,15,16,
  137133. 16,15,16,16,16,16,16,16,16,
  137134. };
  137135. static float _vq_quantthresh__44u8_p9_1[] = {
  137136. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  137137. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  137138. 367.5, 416.5,
  137139. };
  137140. static long _vq_quantmap__44u8_p9_1[] = {
  137141. 17, 15, 13, 11, 9, 7, 5, 3,
  137142. 1, 0, 2, 4, 6, 8, 10, 12,
  137143. 14, 16, 18,
  137144. };
  137145. static encode_aux_threshmatch _vq_auxt__44u8_p9_1 = {
  137146. _vq_quantthresh__44u8_p9_1,
  137147. _vq_quantmap__44u8_p9_1,
  137148. 19,
  137149. 19
  137150. };
  137151. static static_codebook _44u8_p9_1 = {
  137152. 2, 361,
  137153. _vq_lengthlist__44u8_p9_1,
  137154. 1, -518287360, 1622704128, 5, 0,
  137155. _vq_quantlist__44u8_p9_1,
  137156. NULL,
  137157. &_vq_auxt__44u8_p9_1,
  137158. NULL,
  137159. 0
  137160. };
  137161. static long _vq_quantlist__44u8_p9_2[] = {
  137162. 24,
  137163. 23,
  137164. 25,
  137165. 22,
  137166. 26,
  137167. 21,
  137168. 27,
  137169. 20,
  137170. 28,
  137171. 19,
  137172. 29,
  137173. 18,
  137174. 30,
  137175. 17,
  137176. 31,
  137177. 16,
  137178. 32,
  137179. 15,
  137180. 33,
  137181. 14,
  137182. 34,
  137183. 13,
  137184. 35,
  137185. 12,
  137186. 36,
  137187. 11,
  137188. 37,
  137189. 10,
  137190. 38,
  137191. 9,
  137192. 39,
  137193. 8,
  137194. 40,
  137195. 7,
  137196. 41,
  137197. 6,
  137198. 42,
  137199. 5,
  137200. 43,
  137201. 4,
  137202. 44,
  137203. 3,
  137204. 45,
  137205. 2,
  137206. 46,
  137207. 1,
  137208. 47,
  137209. 0,
  137210. 48,
  137211. };
  137212. static long _vq_lengthlist__44u8_p9_2[] = {
  137213. 2, 3, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
  137214. 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137215. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137216. 7,
  137217. };
  137218. static float _vq_quantthresh__44u8_p9_2[] = {
  137219. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  137220. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  137221. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  137222. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  137223. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  137224. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  137225. };
  137226. static long _vq_quantmap__44u8_p9_2[] = {
  137227. 47, 45, 43, 41, 39, 37, 35, 33,
  137228. 31, 29, 27, 25, 23, 21, 19, 17,
  137229. 15, 13, 11, 9, 7, 5, 3, 1,
  137230. 0, 2, 4, 6, 8, 10, 12, 14,
  137231. 16, 18, 20, 22, 24, 26, 28, 30,
  137232. 32, 34, 36, 38, 40, 42, 44, 46,
  137233. 48,
  137234. };
  137235. static encode_aux_threshmatch _vq_auxt__44u8_p9_2 = {
  137236. _vq_quantthresh__44u8_p9_2,
  137237. _vq_quantmap__44u8_p9_2,
  137238. 49,
  137239. 49
  137240. };
  137241. static static_codebook _44u8_p9_2 = {
  137242. 1, 49,
  137243. _vq_lengthlist__44u8_p9_2,
  137244. 1, -526909440, 1611661312, 6, 0,
  137245. _vq_quantlist__44u8_p9_2,
  137246. NULL,
  137247. &_vq_auxt__44u8_p9_2,
  137248. NULL,
  137249. 0
  137250. };
  137251. static long _huff_lengthlist__44u9__long[] = {
  137252. 3, 9,13,13,14,15,14,14,15,15, 5, 5, 9,10,12,12,
  137253. 13,14,16,15,10, 6, 6, 6, 8,11,12,13,16,15,11, 7,
  137254. 5, 3, 5, 8,10,12,15,15,10,10, 7, 4, 3, 5, 8,10,
  137255. 12,12,12,12, 9, 7, 5, 4, 6, 8,10,13,13,12,11, 9,
  137256. 7, 5, 5, 6, 9,12,14,12,12,10, 8, 6, 6, 6, 7,11,
  137257. 13,12,14,13,10, 8, 7, 7, 7,10,11,11,12,13,12,11,
  137258. 10, 8, 8, 9,
  137259. };
  137260. static static_codebook _huff_book__44u9__long = {
  137261. 2, 100,
  137262. _huff_lengthlist__44u9__long,
  137263. 0, 0, 0, 0, 0,
  137264. NULL,
  137265. NULL,
  137266. NULL,
  137267. NULL,
  137268. 0
  137269. };
  137270. static long _huff_lengthlist__44u9__short[] = {
  137271. 9,16,18,18,17,17,17,17,17,17, 5, 8,11,12,11,12,
  137272. 17,17,16,16, 6, 6, 8, 8, 9,10,14,15,16,16, 6, 7,
  137273. 7, 4, 6, 9,13,16,16,16, 6, 6, 7, 4, 5, 8,11,15,
  137274. 17,16, 7, 6, 7, 6, 6, 8, 9,10,14,16,11, 8, 8, 7,
  137275. 6, 6, 3, 4,10,15,14,12,12,10, 5, 6, 3, 3, 8,13,
  137276. 15,17,15,11, 6, 8, 6, 6, 9,14,17,15,15,12, 8,10,
  137277. 9, 9,12,15,
  137278. };
  137279. static static_codebook _huff_book__44u9__short = {
  137280. 2, 100,
  137281. _huff_lengthlist__44u9__short,
  137282. 0, 0, 0, 0, 0,
  137283. NULL,
  137284. NULL,
  137285. NULL,
  137286. NULL,
  137287. 0
  137288. };
  137289. static long _vq_quantlist__44u9_p1_0[] = {
  137290. 1,
  137291. 0,
  137292. 2,
  137293. };
  137294. static long _vq_lengthlist__44u9_p1_0[] = {
  137295. 1, 5, 5, 5, 7, 7, 5, 7, 7, 5, 7, 7, 7, 9, 9, 7,
  137296. 9, 9, 5, 7, 7, 7, 9, 9, 7, 9, 9, 5, 7, 7, 7, 9,
  137297. 9, 7, 9, 9, 8, 9, 9, 9,10,11, 9,11,11, 7, 9, 9,
  137298. 9,11,10, 9,11,11, 5, 7, 7, 7, 9, 9, 8, 9,10, 7,
  137299. 9, 9, 9,11,11, 9,10,11, 7, 9,10, 9,11,11, 9,11,
  137300. 10,
  137301. };
  137302. static float _vq_quantthresh__44u9_p1_0[] = {
  137303. -0.5, 0.5,
  137304. };
  137305. static long _vq_quantmap__44u9_p1_0[] = {
  137306. 1, 0, 2,
  137307. };
  137308. static encode_aux_threshmatch _vq_auxt__44u9_p1_0 = {
  137309. _vq_quantthresh__44u9_p1_0,
  137310. _vq_quantmap__44u9_p1_0,
  137311. 3,
  137312. 3
  137313. };
  137314. static static_codebook _44u9_p1_0 = {
  137315. 4, 81,
  137316. _vq_lengthlist__44u9_p1_0,
  137317. 1, -535822336, 1611661312, 2, 0,
  137318. _vq_quantlist__44u9_p1_0,
  137319. NULL,
  137320. &_vq_auxt__44u9_p1_0,
  137321. NULL,
  137322. 0
  137323. };
  137324. static long _vq_quantlist__44u9_p2_0[] = {
  137325. 2,
  137326. 1,
  137327. 3,
  137328. 0,
  137329. 4,
  137330. };
  137331. static long _vq_lengthlist__44u9_p2_0[] = {
  137332. 3, 5, 5, 8, 8, 5, 7, 7, 9, 9, 6, 7, 7, 9, 9, 8,
  137333. 9, 9,11,10, 8, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 8,
  137334. 8,10,10, 7, 8, 8, 9,10, 9,10,10,11,11, 9, 9,10,
  137335. 11,11, 6, 7, 7, 9, 9, 7, 8, 8,10, 9, 7, 8, 8,10,
  137336. 10, 9,10, 9,11,11, 9,10,10,11,11, 8, 9, 9,11,11,
  137337. 9,10,10,12,11, 9,10,10,11,12,11,11,11,13,13,11,
  137338. 11,11,12,13, 8, 9, 9,11,11, 9,10,10,11,11, 9,10,
  137339. 10,12,11,11,12,11,13,12,11,11,12,13,13, 6, 7, 7,
  137340. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,
  137341. 11, 9,10,10,11,12, 7, 8, 8,10,10, 8, 9, 9,11,11,
  137342. 8, 9, 9,10,10,10,11,11,12,12,10,10,11,12,12, 7,
  137343. 8, 8,10,10, 8, 9, 8,10,10, 8, 9, 9,10,10,10,11,
  137344. 10,12,11,10,10,11,12,12, 9,10,10,11,12,10,11,11,
  137345. 12,12,10,11,10,12,12,12,12,12,13,13,11,12,12,13,
  137346. 13, 9,10,10,11,11, 9,10,10,12,12,10,11,11,12,13,
  137347. 11,12,11,13,12,12,12,12,13,14, 6, 7, 7, 9, 9, 7,
  137348. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,11,11, 9,10,
  137349. 10,11,12, 7, 8, 8,10,10, 8, 9, 9,11,10, 8, 8, 9,
  137350. 10,10,10,11,10,12,12,10,10,11,11,12, 7, 8, 8,10,
  137351. 10, 8, 9, 9,10,10, 8, 9, 9,10,10,10,11,10,12,12,
  137352. 10,11,10,12,12, 9,10,10,12,11,10,11,11,12,12, 9,
  137353. 10,10,12,12,12,12,12,13,13,11,11,12,12,14, 9,10,
  137354. 10,11,12,10,11,11,12,12,10,11,11,12,12,11,12,12,
  137355. 14,14,12,12,12,13,13, 8, 9, 9,11,11, 9,10,10,12,
  137356. 11, 9,10,10,12,12,11,12,11,13,13,11,11,12,13,13,
  137357. 9,10,10,12,12,10,11,11,12,12,10,11,11,12,12,12,
  137358. 12,12,14,14,12,12,12,13,13, 9,10,10,12,11,10,11,
  137359. 10,12,12,10,11,11,12,12,11,12,12,14,13,12,12,12,
  137360. 13,14,11,12,11,13,13,11,12,12,13,13,12,12,12,14,
  137361. 14,13,13,13,13,15,13,13,14,15,15,11,11,11,13,13,
  137362. 11,12,11,13,13,11,12,12,13,13,12,13,12,15,13,13,
  137363. 13,14,14,15, 8, 9, 9,11,11, 9,10,10,11,12, 9,10,
  137364. 10,11,12,11,12,11,13,13,11,12,12,13,13, 9,10,10,
  137365. 11,12,10,11,10,12,12,10,10,11,12,13,12,12,12,14,
  137366. 13,11,12,12,13,14, 9,10,10,12,12,10,11,11,12,12,
  137367. 10,11,11,12,12,12,12,12,14,13,12,12,12,14,13,11,
  137368. 11,11,13,13,11,12,12,14,13,11,11,12,13,13,13,13,
  137369. 13,15,14,12,12,13,13,15,11,12,12,13,13,12,12,12,
  137370. 13,14,11,12,12,13,13,13,13,14,14,15,13,13,13,14,
  137371. 14,
  137372. };
  137373. static float _vq_quantthresh__44u9_p2_0[] = {
  137374. -1.5, -0.5, 0.5, 1.5,
  137375. };
  137376. static long _vq_quantmap__44u9_p2_0[] = {
  137377. 3, 1, 0, 2, 4,
  137378. };
  137379. static encode_aux_threshmatch _vq_auxt__44u9_p2_0 = {
  137380. _vq_quantthresh__44u9_p2_0,
  137381. _vq_quantmap__44u9_p2_0,
  137382. 5,
  137383. 5
  137384. };
  137385. static static_codebook _44u9_p2_0 = {
  137386. 4, 625,
  137387. _vq_lengthlist__44u9_p2_0,
  137388. 1, -533725184, 1611661312, 3, 0,
  137389. _vq_quantlist__44u9_p2_0,
  137390. NULL,
  137391. &_vq_auxt__44u9_p2_0,
  137392. NULL,
  137393. 0
  137394. };
  137395. static long _vq_quantlist__44u9_p3_0[] = {
  137396. 4,
  137397. 3,
  137398. 5,
  137399. 2,
  137400. 6,
  137401. 1,
  137402. 7,
  137403. 0,
  137404. 8,
  137405. };
  137406. static long _vq_lengthlist__44u9_p3_0[] = {
  137407. 3, 4, 4, 5, 5, 7, 7, 8, 8, 4, 5, 5, 6, 6, 7, 7,
  137408. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  137409. 8, 8, 9, 9, 5, 6, 6, 7, 7, 8, 8, 9, 9, 7, 7, 7,
  137410. 8, 8, 9, 9,10,10, 7, 7, 7, 8, 8, 9, 9,10,10, 8,
  137411. 9, 9,10, 9,10,10,11,11, 8, 9, 9, 9,10,10,10,11,
  137412. 11,
  137413. };
  137414. static float _vq_quantthresh__44u9_p3_0[] = {
  137415. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  137416. };
  137417. static long _vq_quantmap__44u9_p3_0[] = {
  137418. 7, 5, 3, 1, 0, 2, 4, 6,
  137419. 8,
  137420. };
  137421. static encode_aux_threshmatch _vq_auxt__44u9_p3_0 = {
  137422. _vq_quantthresh__44u9_p3_0,
  137423. _vq_quantmap__44u9_p3_0,
  137424. 9,
  137425. 9
  137426. };
  137427. static static_codebook _44u9_p3_0 = {
  137428. 2, 81,
  137429. _vq_lengthlist__44u9_p3_0,
  137430. 1, -531628032, 1611661312, 4, 0,
  137431. _vq_quantlist__44u9_p3_0,
  137432. NULL,
  137433. &_vq_auxt__44u9_p3_0,
  137434. NULL,
  137435. 0
  137436. };
  137437. static long _vq_quantlist__44u9_p4_0[] = {
  137438. 8,
  137439. 7,
  137440. 9,
  137441. 6,
  137442. 10,
  137443. 5,
  137444. 11,
  137445. 4,
  137446. 12,
  137447. 3,
  137448. 13,
  137449. 2,
  137450. 14,
  137451. 1,
  137452. 15,
  137453. 0,
  137454. 16,
  137455. };
  137456. static long _vq_lengthlist__44u9_p4_0[] = {
  137457. 4, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  137458. 11, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,
  137459. 11,11, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,
  137460. 10,11,11, 6, 6, 6, 7, 6, 7, 7, 8, 8, 9, 9,10,10,
  137461. 11,11,12,11, 6, 6, 6, 6, 7, 7, 7, 8, 8, 9, 9,10,
  137462. 10,11,11,11,12, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,
  137463. 10,10,11,11,12,12, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9,
  137464. 9,10,10,11,11,12,12, 8, 8, 8, 8, 8, 9, 8,10, 9,
  137465. 10,10,11,10,12,11,13,12, 8, 8, 8, 8, 8, 9, 9, 9,
  137466. 10,10,10,10,11,11,12,12,12, 8, 8, 8, 9, 9, 9, 9,
  137467. 10,10,11,10,12,11,12,12,13,12, 8, 8, 8, 9, 9, 9,
  137468. 9,10,10,10,11,11,11,12,12,12,13, 9, 9, 9,10,10,
  137469. 10,10,11,10,11,11,12,11,13,12,13,13, 9, 9,10,10,
  137470. 10,10,10,10,11,11,11,11,12,12,13,13,13,10,11,10,
  137471. 11,11,11,11,12,11,12,12,13,12,13,13,14,13,10,10,
  137472. 10,11,11,11,11,11,12,12,12,12,13,13,13,13,14,11,
  137473. 11,11,12,11,12,12,12,12,13,13,13,13,14,13,14,14,
  137474. 11,11,11,11,12,12,12,12,12,12,13,13,13,13,14,14,
  137475. 14,
  137476. };
  137477. static float _vq_quantthresh__44u9_p4_0[] = {
  137478. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  137479. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  137480. };
  137481. static long _vq_quantmap__44u9_p4_0[] = {
  137482. 15, 13, 11, 9, 7, 5, 3, 1,
  137483. 0, 2, 4, 6, 8, 10, 12, 14,
  137484. 16,
  137485. };
  137486. static encode_aux_threshmatch _vq_auxt__44u9_p4_0 = {
  137487. _vq_quantthresh__44u9_p4_0,
  137488. _vq_quantmap__44u9_p4_0,
  137489. 17,
  137490. 17
  137491. };
  137492. static static_codebook _44u9_p4_0 = {
  137493. 2, 289,
  137494. _vq_lengthlist__44u9_p4_0,
  137495. 1, -529530880, 1611661312, 5, 0,
  137496. _vq_quantlist__44u9_p4_0,
  137497. NULL,
  137498. &_vq_auxt__44u9_p4_0,
  137499. NULL,
  137500. 0
  137501. };
  137502. static long _vq_quantlist__44u9_p5_0[] = {
  137503. 1,
  137504. 0,
  137505. 2,
  137506. };
  137507. static long _vq_lengthlist__44u9_p5_0[] = {
  137508. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 8, 9, 9, 7,
  137509. 9, 9, 5, 8, 8, 7, 9, 9, 8, 9, 9, 5, 8, 8, 8,10,
  137510. 10, 8,10,10, 7,10,10, 9,10,12, 9,11,11, 7,10,10,
  137511. 9,11,10, 9,11,12, 5, 8, 8, 8,10,10, 8,10,10, 7,
  137512. 10,10, 9,12,11, 9,10,11, 7,10,10, 9,11,11,10,12,
  137513. 10,
  137514. };
  137515. static float _vq_quantthresh__44u9_p5_0[] = {
  137516. -5.5, 5.5,
  137517. };
  137518. static long _vq_quantmap__44u9_p5_0[] = {
  137519. 1, 0, 2,
  137520. };
  137521. static encode_aux_threshmatch _vq_auxt__44u9_p5_0 = {
  137522. _vq_quantthresh__44u9_p5_0,
  137523. _vq_quantmap__44u9_p5_0,
  137524. 3,
  137525. 3
  137526. };
  137527. static static_codebook _44u9_p5_0 = {
  137528. 4, 81,
  137529. _vq_lengthlist__44u9_p5_0,
  137530. 1, -529137664, 1618345984, 2, 0,
  137531. _vq_quantlist__44u9_p5_0,
  137532. NULL,
  137533. &_vq_auxt__44u9_p5_0,
  137534. NULL,
  137535. 0
  137536. };
  137537. static long _vq_quantlist__44u9_p5_1[] = {
  137538. 5,
  137539. 4,
  137540. 6,
  137541. 3,
  137542. 7,
  137543. 2,
  137544. 8,
  137545. 1,
  137546. 9,
  137547. 0,
  137548. 10,
  137549. };
  137550. static long _vq_lengthlist__44u9_p5_1[] = {
  137551. 5, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 6, 6,
  137552. 7, 7, 7, 7, 8, 7, 5, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  137553. 7, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 6, 6, 6, 7,
  137554. 7, 7, 7, 7, 7, 8, 8, 7, 7, 7, 7, 7, 8, 7, 8, 8,
  137555. 8, 8, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  137556. 8, 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 8, 8, 8, 8,
  137557. 8, 8, 8, 7, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8,
  137558. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  137559. };
  137560. static float _vq_quantthresh__44u9_p5_1[] = {
  137561. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  137562. 3.5, 4.5,
  137563. };
  137564. static long _vq_quantmap__44u9_p5_1[] = {
  137565. 9, 7, 5, 3, 1, 0, 2, 4,
  137566. 6, 8, 10,
  137567. };
  137568. static encode_aux_threshmatch _vq_auxt__44u9_p5_1 = {
  137569. _vq_quantthresh__44u9_p5_1,
  137570. _vq_quantmap__44u9_p5_1,
  137571. 11,
  137572. 11
  137573. };
  137574. static static_codebook _44u9_p5_1 = {
  137575. 2, 121,
  137576. _vq_lengthlist__44u9_p5_1,
  137577. 1, -531365888, 1611661312, 4, 0,
  137578. _vq_quantlist__44u9_p5_1,
  137579. NULL,
  137580. &_vq_auxt__44u9_p5_1,
  137581. NULL,
  137582. 0
  137583. };
  137584. static long _vq_quantlist__44u9_p6_0[] = {
  137585. 6,
  137586. 5,
  137587. 7,
  137588. 4,
  137589. 8,
  137590. 3,
  137591. 9,
  137592. 2,
  137593. 10,
  137594. 1,
  137595. 11,
  137596. 0,
  137597. 12,
  137598. };
  137599. static long _vq_lengthlist__44u9_p6_0[] = {
  137600. 2, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 4, 6, 5,
  137601. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 4, 5, 6, 7, 7, 8,
  137602. 8, 8, 8, 9, 9,10,10, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  137603. 10,10,10,10, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,10,
  137604. 10, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,11, 7, 8,
  137605. 8, 8, 8, 9, 9, 9, 9,10,10,11,11, 8, 8, 8, 9, 9,
  137606. 9, 9, 9,10,10,10,11,11, 8, 8, 8, 9, 9, 9, 9,10,
  137607. 9,10,10,11,11, 9, 9, 9,10,10,10,10,10,11,11,11,
  137608. 11,12, 9, 9, 9,10,10,10,10,10,10,11,10,12,11,10,
  137609. 10,10,10,10,11,11,11,11,11,12,12,12,10,10,10,10,
  137610. 10,11,11,11,11,12,11,12,12,
  137611. };
  137612. static float _vq_quantthresh__44u9_p6_0[] = {
  137613. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  137614. 12.5, 17.5, 22.5, 27.5,
  137615. };
  137616. static long _vq_quantmap__44u9_p6_0[] = {
  137617. 11, 9, 7, 5, 3, 1, 0, 2,
  137618. 4, 6, 8, 10, 12,
  137619. };
  137620. static encode_aux_threshmatch _vq_auxt__44u9_p6_0 = {
  137621. _vq_quantthresh__44u9_p6_0,
  137622. _vq_quantmap__44u9_p6_0,
  137623. 13,
  137624. 13
  137625. };
  137626. static static_codebook _44u9_p6_0 = {
  137627. 2, 169,
  137628. _vq_lengthlist__44u9_p6_0,
  137629. 1, -526516224, 1616117760, 4, 0,
  137630. _vq_quantlist__44u9_p6_0,
  137631. NULL,
  137632. &_vq_auxt__44u9_p6_0,
  137633. NULL,
  137634. 0
  137635. };
  137636. static long _vq_quantlist__44u9_p6_1[] = {
  137637. 2,
  137638. 1,
  137639. 3,
  137640. 0,
  137641. 4,
  137642. };
  137643. static long _vq_lengthlist__44u9_p6_1[] = {
  137644. 4, 4, 4, 5, 5, 4, 5, 4, 5, 5, 4, 4, 5, 5, 5, 5,
  137645. 5, 5, 5, 5, 5, 5, 5, 5, 5,
  137646. };
  137647. static float _vq_quantthresh__44u9_p6_1[] = {
  137648. -1.5, -0.5, 0.5, 1.5,
  137649. };
  137650. static long _vq_quantmap__44u9_p6_1[] = {
  137651. 3, 1, 0, 2, 4,
  137652. };
  137653. static encode_aux_threshmatch _vq_auxt__44u9_p6_1 = {
  137654. _vq_quantthresh__44u9_p6_1,
  137655. _vq_quantmap__44u9_p6_1,
  137656. 5,
  137657. 5
  137658. };
  137659. static static_codebook _44u9_p6_1 = {
  137660. 2, 25,
  137661. _vq_lengthlist__44u9_p6_1,
  137662. 1, -533725184, 1611661312, 3, 0,
  137663. _vq_quantlist__44u9_p6_1,
  137664. NULL,
  137665. &_vq_auxt__44u9_p6_1,
  137666. NULL,
  137667. 0
  137668. };
  137669. static long _vq_quantlist__44u9_p7_0[] = {
  137670. 6,
  137671. 5,
  137672. 7,
  137673. 4,
  137674. 8,
  137675. 3,
  137676. 9,
  137677. 2,
  137678. 10,
  137679. 1,
  137680. 11,
  137681. 0,
  137682. 12,
  137683. };
  137684. static long _vq_lengthlist__44u9_p7_0[] = {
  137685. 1, 4, 5, 6, 6, 7, 7, 8, 9,10,10,11,11, 5, 6, 6,
  137686. 7, 7, 8, 8, 9, 9,10,10,11,11, 5, 6, 6, 7, 7, 8,
  137687. 8, 9, 9,10,10,11,11, 6, 7, 7, 8, 8, 9, 9,10,10,
  137688. 11,11,12,12, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,12,
  137689. 12, 8, 8, 8, 9, 9,10,10,11,11,12,12,13,13, 8, 8,
  137690. 8, 9, 9,10,10,11,11,12,12,13,13, 9, 9, 9,10,10,
  137691. 11,11,12,12,13,13,13,13, 9, 9, 9,10,10,11,11,12,
  137692. 12,13,13,14,14,10,10,10,11,11,12,12,13,13,14,13,
  137693. 15,14,10,10,10,11,11,12,12,13,13,14,14,14,14,11,
  137694. 11,12,12,12,13,13,14,14,14,14,15,15,11,11,12,12,
  137695. 12,13,13,14,14,14,15,15,15,
  137696. };
  137697. static float _vq_quantthresh__44u9_p7_0[] = {
  137698. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  137699. 27.5, 38.5, 49.5, 60.5,
  137700. };
  137701. static long _vq_quantmap__44u9_p7_0[] = {
  137702. 11, 9, 7, 5, 3, 1, 0, 2,
  137703. 4, 6, 8, 10, 12,
  137704. };
  137705. static encode_aux_threshmatch _vq_auxt__44u9_p7_0 = {
  137706. _vq_quantthresh__44u9_p7_0,
  137707. _vq_quantmap__44u9_p7_0,
  137708. 13,
  137709. 13
  137710. };
  137711. static static_codebook _44u9_p7_0 = {
  137712. 2, 169,
  137713. _vq_lengthlist__44u9_p7_0,
  137714. 1, -523206656, 1618345984, 4, 0,
  137715. _vq_quantlist__44u9_p7_0,
  137716. NULL,
  137717. &_vq_auxt__44u9_p7_0,
  137718. NULL,
  137719. 0
  137720. };
  137721. static long _vq_quantlist__44u9_p7_1[] = {
  137722. 5,
  137723. 4,
  137724. 6,
  137725. 3,
  137726. 7,
  137727. 2,
  137728. 8,
  137729. 1,
  137730. 9,
  137731. 0,
  137732. 10,
  137733. };
  137734. static long _vq_lengthlist__44u9_p7_1[] = {
  137735. 5, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 7, 7,
  137736. 7, 7, 7, 7, 7, 7, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7,
  137737. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 7, 7, 7,
  137738. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137739. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137740. 7, 7, 7, 7, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137741. 7, 8, 8, 7, 7, 7, 7, 7, 7, 7, 8, 7, 8, 8, 7, 7,
  137742. 7, 7, 7, 7, 7, 8, 8, 8, 8,
  137743. };
  137744. static float _vq_quantthresh__44u9_p7_1[] = {
  137745. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  137746. 3.5, 4.5,
  137747. };
  137748. static long _vq_quantmap__44u9_p7_1[] = {
  137749. 9, 7, 5, 3, 1, 0, 2, 4,
  137750. 6, 8, 10,
  137751. };
  137752. static encode_aux_threshmatch _vq_auxt__44u9_p7_1 = {
  137753. _vq_quantthresh__44u9_p7_1,
  137754. _vq_quantmap__44u9_p7_1,
  137755. 11,
  137756. 11
  137757. };
  137758. static static_codebook _44u9_p7_1 = {
  137759. 2, 121,
  137760. _vq_lengthlist__44u9_p7_1,
  137761. 1, -531365888, 1611661312, 4, 0,
  137762. _vq_quantlist__44u9_p7_1,
  137763. NULL,
  137764. &_vq_auxt__44u9_p7_1,
  137765. NULL,
  137766. 0
  137767. };
  137768. static long _vq_quantlist__44u9_p8_0[] = {
  137769. 7,
  137770. 6,
  137771. 8,
  137772. 5,
  137773. 9,
  137774. 4,
  137775. 10,
  137776. 3,
  137777. 11,
  137778. 2,
  137779. 12,
  137780. 1,
  137781. 13,
  137782. 0,
  137783. 14,
  137784. };
  137785. static long _vq_lengthlist__44u9_p8_0[] = {
  137786. 1, 4, 4, 7, 7, 8, 8, 8, 8, 9, 9,10, 9,11,10, 4,
  137787. 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,10,12,10, 4, 6,
  137788. 6, 8, 8, 9,10, 9, 9,10,10,11,11,12,12, 7, 8, 8,
  137789. 10,10,11,11,10,10,11,11,12,12,13,12, 7, 8, 8,10,
  137790. 10,11,11,10,10,11,11,12,12,12,13, 8,10, 9,11,11,
  137791. 12,12,11,11,12,12,13,13,14,13, 8, 9, 9,11,11,12,
  137792. 12,11,12,12,12,13,13,14,13, 8, 9, 9,10,10,12,11,
  137793. 13,12,13,13,14,13,15,14, 8, 9, 9,10,10,11,12,12,
  137794. 12,13,13,13,14,14,14, 9,10,10,12,11,13,12,13,13,
  137795. 14,13,14,14,14,15, 9,10,10,11,12,12,12,13,13,14,
  137796. 14,14,15,15,15,10,11,11,12,12,13,13,14,14,14,14,
  137797. 15,14,16,15,10,11,11,12,12,13,13,13,14,14,14,14,
  137798. 14,15,16,11,12,12,13,13,14,13,14,14,15,14,15,16,
  137799. 16,16,11,12,12,13,13,14,13,14,14,15,15,15,16,15,
  137800. 15,
  137801. };
  137802. static float _vq_quantthresh__44u9_p8_0[] = {
  137803. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  137804. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  137805. };
  137806. static long _vq_quantmap__44u9_p8_0[] = {
  137807. 13, 11, 9, 7, 5, 3, 1, 0,
  137808. 2, 4, 6, 8, 10, 12, 14,
  137809. };
  137810. static encode_aux_threshmatch _vq_auxt__44u9_p8_0 = {
  137811. _vq_quantthresh__44u9_p8_0,
  137812. _vq_quantmap__44u9_p8_0,
  137813. 15,
  137814. 15
  137815. };
  137816. static static_codebook _44u9_p8_0 = {
  137817. 2, 225,
  137818. _vq_lengthlist__44u9_p8_0,
  137819. 1, -520986624, 1620377600, 4, 0,
  137820. _vq_quantlist__44u9_p8_0,
  137821. NULL,
  137822. &_vq_auxt__44u9_p8_0,
  137823. NULL,
  137824. 0
  137825. };
  137826. static long _vq_quantlist__44u9_p8_1[] = {
  137827. 10,
  137828. 9,
  137829. 11,
  137830. 8,
  137831. 12,
  137832. 7,
  137833. 13,
  137834. 6,
  137835. 14,
  137836. 5,
  137837. 15,
  137838. 4,
  137839. 16,
  137840. 3,
  137841. 17,
  137842. 2,
  137843. 18,
  137844. 1,
  137845. 19,
  137846. 0,
  137847. 20,
  137848. };
  137849. static long _vq_lengthlist__44u9_p8_1[] = {
  137850. 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  137851. 9, 9, 9, 9, 9, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  137852. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 6, 6, 6, 7, 7, 8,
  137853. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 7,
  137854. 7, 7, 8, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  137855. 9, 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  137856. 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9,
  137857. 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10, 8, 8,
  137858. 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137859. 9,10,10, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137860. 10, 9,10, 9,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9,
  137861. 9, 9, 9, 9, 9,10,10, 9,10,10,10,10,10, 9, 9, 9,
  137862. 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,10,10,
  137863. 10,10, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  137864. 10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137865. 9, 9,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  137866. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  137867. 10, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,10,10,
  137868. 10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  137869. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,
  137870. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  137871. 9, 9, 9, 9,10, 9, 9,10,10,10,10,10,10,10,10,10,
  137872. 10,10,10,10,10, 9, 9, 9,10, 9,10, 9,10,10,10,10,
  137873. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9,10, 9,10,
  137874. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  137875. 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  137876. 10,10,10,10, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  137877. 10,10,10,10,10,10,10,10,10,
  137878. };
  137879. static float _vq_quantthresh__44u9_p8_1[] = {
  137880. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  137881. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  137882. 6.5, 7.5, 8.5, 9.5,
  137883. };
  137884. static long _vq_quantmap__44u9_p8_1[] = {
  137885. 19, 17, 15, 13, 11, 9, 7, 5,
  137886. 3, 1, 0, 2, 4, 6, 8, 10,
  137887. 12, 14, 16, 18, 20,
  137888. };
  137889. static encode_aux_threshmatch _vq_auxt__44u9_p8_1 = {
  137890. _vq_quantthresh__44u9_p8_1,
  137891. _vq_quantmap__44u9_p8_1,
  137892. 21,
  137893. 21
  137894. };
  137895. static static_codebook _44u9_p8_1 = {
  137896. 2, 441,
  137897. _vq_lengthlist__44u9_p8_1,
  137898. 1, -529268736, 1611661312, 5, 0,
  137899. _vq_quantlist__44u9_p8_1,
  137900. NULL,
  137901. &_vq_auxt__44u9_p8_1,
  137902. NULL,
  137903. 0
  137904. };
  137905. static long _vq_quantlist__44u9_p9_0[] = {
  137906. 7,
  137907. 6,
  137908. 8,
  137909. 5,
  137910. 9,
  137911. 4,
  137912. 10,
  137913. 3,
  137914. 11,
  137915. 2,
  137916. 12,
  137917. 1,
  137918. 13,
  137919. 0,
  137920. 14,
  137921. };
  137922. static long _vq_lengthlist__44u9_p9_0[] = {
  137923. 1, 3, 3,11,11,11,11,11,11,11,11,11,11,11,11, 4,
  137924. 10,11,11,11,11,11,11,11,11,11,11,11,11,11, 4,10,
  137925. 10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137926. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137927. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137928. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137929. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137930. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137931. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137932. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137933. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137934. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137935. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  137936. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  137937. 10,
  137938. };
  137939. static float _vq_quantthresh__44u9_p9_0[] = {
  137940. -6051.5, -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -465.5, 465.5,
  137941. 1396.5, 2327.5, 3258.5, 4189.5, 5120.5, 6051.5,
  137942. };
  137943. static long _vq_quantmap__44u9_p9_0[] = {
  137944. 13, 11, 9, 7, 5, 3, 1, 0,
  137945. 2, 4, 6, 8, 10, 12, 14,
  137946. };
  137947. static encode_aux_threshmatch _vq_auxt__44u9_p9_0 = {
  137948. _vq_quantthresh__44u9_p9_0,
  137949. _vq_quantmap__44u9_p9_0,
  137950. 15,
  137951. 15
  137952. };
  137953. static static_codebook _44u9_p9_0 = {
  137954. 2, 225,
  137955. _vq_lengthlist__44u9_p9_0,
  137956. 1, -510036736, 1631393792, 4, 0,
  137957. _vq_quantlist__44u9_p9_0,
  137958. NULL,
  137959. &_vq_auxt__44u9_p9_0,
  137960. NULL,
  137961. 0
  137962. };
  137963. static long _vq_quantlist__44u9_p9_1[] = {
  137964. 9,
  137965. 8,
  137966. 10,
  137967. 7,
  137968. 11,
  137969. 6,
  137970. 12,
  137971. 5,
  137972. 13,
  137973. 4,
  137974. 14,
  137975. 3,
  137976. 15,
  137977. 2,
  137978. 16,
  137979. 1,
  137980. 17,
  137981. 0,
  137982. 18,
  137983. };
  137984. static long _vq_lengthlist__44u9_p9_1[] = {
  137985. 1, 4, 4, 7, 7, 8, 7, 8, 7, 9, 8,10, 9,10,10,11,
  137986. 11,12,12, 4, 7, 6, 9, 9,10, 9, 9, 8,10,10,11,10,
  137987. 12,10,13,12,13,12, 4, 6, 6, 9, 9, 9, 9, 9, 9,10,
  137988. 10,11,11,11,12,12,12,12,12, 7, 9, 8,11,10,10,10,
  137989. 11,10,11,11,12,12,13,12,13,13,13,13, 7, 8, 9,10,
  137990. 10,11,11,10,10,11,11,11,12,13,13,13,13,14,14, 8,
  137991. 9, 9,11,11,12,11,12,12,13,12,12,13,13,14,15,14,
  137992. 14,14, 8, 9, 9,10,11,11,11,12,12,13,12,13,13,14,
  137993. 14,14,15,14,16, 8, 9, 9,11,10,12,12,12,12,15,13,
  137994. 13,13,17,14,15,15,15,14, 8, 9, 9,10,11,11,12,13,
  137995. 12,13,13,13,14,15,14,14,14,16,15, 9,11,10,12,12,
  137996. 13,13,13,13,14,14,16,15,14,14,14,15,15,17, 9,10,
  137997. 10,11,11,13,13,13,14,14,13,15,14,15,14,15,16,15,
  137998. 16,10,11,11,12,12,13,14,15,14,15,14,14,15,17,16,
  137999. 15,15,17,17,10,12,11,13,12,14,14,13,14,15,15,15,
  138000. 15,16,17,17,15,17,16,11,12,12,14,13,15,14,15,16,
  138001. 17,15,17,15,17,15,15,16,17,15,11,11,12,14,14,14,
  138002. 14,14,15,15,16,15,17,17,17,16,17,16,15,12,12,13,
  138003. 14,14,14,15,14,15,15,16,16,17,16,17,15,17,17,16,
  138004. 12,14,12,14,14,15,15,15,14,14,16,16,16,15,16,16,
  138005. 15,17,15,12,13,13,14,15,14,15,17,15,17,16,17,17,
  138006. 17,16,17,16,17,17,12,13,13,14,16,15,15,15,16,15,
  138007. 17,17,15,17,15,17,16,16,17,
  138008. };
  138009. static float _vq_quantthresh__44u9_p9_1[] = {
  138010. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  138011. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  138012. 367.5, 416.5,
  138013. };
  138014. static long _vq_quantmap__44u9_p9_1[] = {
  138015. 17, 15, 13, 11, 9, 7, 5, 3,
  138016. 1, 0, 2, 4, 6, 8, 10, 12,
  138017. 14, 16, 18,
  138018. };
  138019. static encode_aux_threshmatch _vq_auxt__44u9_p9_1 = {
  138020. _vq_quantthresh__44u9_p9_1,
  138021. _vq_quantmap__44u9_p9_1,
  138022. 19,
  138023. 19
  138024. };
  138025. static static_codebook _44u9_p9_1 = {
  138026. 2, 361,
  138027. _vq_lengthlist__44u9_p9_1,
  138028. 1, -518287360, 1622704128, 5, 0,
  138029. _vq_quantlist__44u9_p9_1,
  138030. NULL,
  138031. &_vq_auxt__44u9_p9_1,
  138032. NULL,
  138033. 0
  138034. };
  138035. static long _vq_quantlist__44u9_p9_2[] = {
  138036. 24,
  138037. 23,
  138038. 25,
  138039. 22,
  138040. 26,
  138041. 21,
  138042. 27,
  138043. 20,
  138044. 28,
  138045. 19,
  138046. 29,
  138047. 18,
  138048. 30,
  138049. 17,
  138050. 31,
  138051. 16,
  138052. 32,
  138053. 15,
  138054. 33,
  138055. 14,
  138056. 34,
  138057. 13,
  138058. 35,
  138059. 12,
  138060. 36,
  138061. 11,
  138062. 37,
  138063. 10,
  138064. 38,
  138065. 9,
  138066. 39,
  138067. 8,
  138068. 40,
  138069. 7,
  138070. 41,
  138071. 6,
  138072. 42,
  138073. 5,
  138074. 43,
  138075. 4,
  138076. 44,
  138077. 3,
  138078. 45,
  138079. 2,
  138080. 46,
  138081. 1,
  138082. 47,
  138083. 0,
  138084. 48,
  138085. };
  138086. static long _vq_lengthlist__44u9_p9_2[] = {
  138087. 2, 4, 4, 5, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6,
  138088. 6, 6, 6, 7, 6, 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  138089. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  138090. 7,
  138091. };
  138092. static float _vq_quantthresh__44u9_p9_2[] = {
  138093. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  138094. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  138095. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  138096. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  138097. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  138098. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  138099. };
  138100. static long _vq_quantmap__44u9_p9_2[] = {
  138101. 47, 45, 43, 41, 39, 37, 35, 33,
  138102. 31, 29, 27, 25, 23, 21, 19, 17,
  138103. 15, 13, 11, 9, 7, 5, 3, 1,
  138104. 0, 2, 4, 6, 8, 10, 12, 14,
  138105. 16, 18, 20, 22, 24, 26, 28, 30,
  138106. 32, 34, 36, 38, 40, 42, 44, 46,
  138107. 48,
  138108. };
  138109. static encode_aux_threshmatch _vq_auxt__44u9_p9_2 = {
  138110. _vq_quantthresh__44u9_p9_2,
  138111. _vq_quantmap__44u9_p9_2,
  138112. 49,
  138113. 49
  138114. };
  138115. static static_codebook _44u9_p9_2 = {
  138116. 1, 49,
  138117. _vq_lengthlist__44u9_p9_2,
  138118. 1, -526909440, 1611661312, 6, 0,
  138119. _vq_quantlist__44u9_p9_2,
  138120. NULL,
  138121. &_vq_auxt__44u9_p9_2,
  138122. NULL,
  138123. 0
  138124. };
  138125. static long _huff_lengthlist__44un1__long[] = {
  138126. 5, 6,12, 9,14, 9, 9,19, 6, 1, 5, 5, 8, 7, 9,19,
  138127. 12, 4, 4, 7, 7, 9,11,18, 9, 5, 6, 6, 8, 7, 8,17,
  138128. 14, 8, 7, 8, 8,10,12,18, 9, 6, 8, 6, 8, 6, 8,18,
  138129. 9, 8,11, 8,11, 7, 5,15,16,18,18,18,17,15,11,18,
  138130. };
  138131. static static_codebook _huff_book__44un1__long = {
  138132. 2, 64,
  138133. _huff_lengthlist__44un1__long,
  138134. 0, 0, 0, 0, 0,
  138135. NULL,
  138136. NULL,
  138137. NULL,
  138138. NULL,
  138139. 0
  138140. };
  138141. static long _vq_quantlist__44un1__p1_0[] = {
  138142. 1,
  138143. 0,
  138144. 2,
  138145. };
  138146. static long _vq_lengthlist__44un1__p1_0[] = {
  138147. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,10,11, 8,
  138148. 10,11, 5, 8, 8, 8,11,10, 8,11,10, 4, 9, 9, 8,11,
  138149. 11, 8,11,11, 8,12,11,10,12,14,11,13,13, 7,11,11,
  138150. 10,13,11,11,13,14, 4, 8, 9, 8,11,11, 8,11,12, 7,
  138151. 11,11,11,14,13,10,11,13, 8,11,12,11,13,13,10,14,
  138152. 12,
  138153. };
  138154. static float _vq_quantthresh__44un1__p1_0[] = {
  138155. -0.5, 0.5,
  138156. };
  138157. static long _vq_quantmap__44un1__p1_0[] = {
  138158. 1, 0, 2,
  138159. };
  138160. static encode_aux_threshmatch _vq_auxt__44un1__p1_0 = {
  138161. _vq_quantthresh__44un1__p1_0,
  138162. _vq_quantmap__44un1__p1_0,
  138163. 3,
  138164. 3
  138165. };
  138166. static static_codebook _44un1__p1_0 = {
  138167. 4, 81,
  138168. _vq_lengthlist__44un1__p1_0,
  138169. 1, -535822336, 1611661312, 2, 0,
  138170. _vq_quantlist__44un1__p1_0,
  138171. NULL,
  138172. &_vq_auxt__44un1__p1_0,
  138173. NULL,
  138174. 0
  138175. };
  138176. static long _vq_quantlist__44un1__p2_0[] = {
  138177. 1,
  138178. 0,
  138179. 2,
  138180. };
  138181. static long _vq_lengthlist__44un1__p2_0[] = {
  138182. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 8, 6,
  138183. 7, 9, 5, 7, 7, 6, 8, 7, 7, 9, 8, 4, 7, 7, 7, 9,
  138184. 8, 7, 8, 8, 7, 9, 8, 8, 8,10, 9,10,10, 6, 8, 8,
  138185. 7,10, 8, 9,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 9, 6,
  138186. 8, 8, 9,10,10, 7, 8,10, 6, 8, 9, 9,10,10, 8,10,
  138187. 8,
  138188. };
  138189. static float _vq_quantthresh__44un1__p2_0[] = {
  138190. -0.5, 0.5,
  138191. };
  138192. static long _vq_quantmap__44un1__p2_0[] = {
  138193. 1, 0, 2,
  138194. };
  138195. static encode_aux_threshmatch _vq_auxt__44un1__p2_0 = {
  138196. _vq_quantthresh__44un1__p2_0,
  138197. _vq_quantmap__44un1__p2_0,
  138198. 3,
  138199. 3
  138200. };
  138201. static static_codebook _44un1__p2_0 = {
  138202. 4, 81,
  138203. _vq_lengthlist__44un1__p2_0,
  138204. 1, -535822336, 1611661312, 2, 0,
  138205. _vq_quantlist__44un1__p2_0,
  138206. NULL,
  138207. &_vq_auxt__44un1__p2_0,
  138208. NULL,
  138209. 0
  138210. };
  138211. static long _vq_quantlist__44un1__p3_0[] = {
  138212. 2,
  138213. 1,
  138214. 3,
  138215. 0,
  138216. 4,
  138217. };
  138218. static long _vq_lengthlist__44un1__p3_0[] = {
  138219. 1, 5, 5, 8, 8, 5, 8, 7, 9, 9, 5, 7, 8, 9, 9, 9,
  138220. 10, 9,12,12, 9, 9,10,11,12, 6, 8, 8,10,10, 8,10,
  138221. 10,11,11, 8, 9,10,11,11,10,11,11,13,13,10,11,11,
  138222. 12,13, 6, 8, 8,10,10, 8,10, 9,11,11, 8,10,10,11,
  138223. 11,10,11,11,13,12,10,11,11,13,12, 9,11,11,15,13,
  138224. 10,12,11,15,13,10,11,11,15,14,12,14,13,16,15,12,
  138225. 13,13,17,16, 9,11,11,13,15,10,11,12,14,15,10,11,
  138226. 12,14,15,12,13,13,15,16,12,13,13,16,16, 5, 8, 8,
  138227. 11,11, 8,10,10,12,12, 8,10,10,12,12,11,12,12,14,
  138228. 14,11,12,12,14,14, 8,11,10,13,12,10,11,12,12,13,
  138229. 10,12,12,13,13,12,12,13,13,15,11,12,13,15,14, 7,
  138230. 10,10,12,12, 9,12,11,13,12,10,12,12,13,14,12,13,
  138231. 12,15,13,11,13,12,14,15,10,12,12,16,14,11,12,12,
  138232. 16,15,11,13,12,17,16,13,13,15,15,17,13,15,15,20,
  138233. 17,10,12,12,14,16,11,12,12,15,15,11,13,13,15,18,
  138234. 13,14,13,15,15,13,15,14,16,16, 5, 8, 8,11,11, 8,
  138235. 10,10,12,12, 8,10,10,12,12,11,12,12,14,14,11,12,
  138236. 12,14,15, 7,10,10,13,12,10,12,12,14,13, 9,10,12,
  138237. 12,13,11,13,13,15,15,11,12,13,13,15, 8,10,10,12,
  138238. 13,10,12,12,13,13,10,12,11,13,13,11,13,12,15,15,
  138239. 12,13,12,15,13,10,12,12,16,14,11,12,12,16,15,10,
  138240. 12,12,16,14,14,15,14,18,16,13,13,14,15,16,10,12,
  138241. 12,14,16,11,13,13,16,16,11,13,12,14,16,13,15,15,
  138242. 18,18,13,15,13,16,14, 8,11,11,16,16,10,13,13,17,
  138243. 16,10,12,12,16,15,14,16,15,20,17,13,14,14,17,17,
  138244. 9,12,12,16,16,11,13,14,16,17,11,13,13,16,16,15,
  138245. 15,19,18, 0,14,15,15,18,18, 9,12,12,17,16,11,13,
  138246. 12,17,16,11,12,13,15,17,15,16,15, 0,19,14,15,14,
  138247. 19,18,12,14,14, 0,16,13,14,14,19,18,13,15,16,17,
  138248. 16,15,15,17,18, 0,14,16,16,19, 0,12,14,14,16,18,
  138249. 13,15,13,17,18,13,15,14,17,18,15,18,14,18,18,16,
  138250. 17,16, 0,17, 8,11,11,15,15,10,12,12,16,16,10,13,
  138251. 13,16,16,13,15,14,17,17,14,15,17,17,18, 9,12,12,
  138252. 16,15,11,13,13,16,16,11,12,13,17,17,14,14,15,17,
  138253. 17,14,15,16, 0,18, 9,12,12,16,17,11,13,13,16,17,
  138254. 11,14,13,18,17,14,16,14,17,17,15,17,17,18,18,12,
  138255. 14,14, 0,16,13,15,15,19, 0,12,13,15, 0, 0,14,17,
  138256. 16,19, 0,16,15,18,18, 0,12,14,14,17, 0,13,14,14,
  138257. 17, 0,13,15,14, 0,18,15,16,16, 0,18,15,18,15, 0,
  138258. 17,
  138259. };
  138260. static float _vq_quantthresh__44un1__p3_0[] = {
  138261. -1.5, -0.5, 0.5, 1.5,
  138262. };
  138263. static long _vq_quantmap__44un1__p3_0[] = {
  138264. 3, 1, 0, 2, 4,
  138265. };
  138266. static encode_aux_threshmatch _vq_auxt__44un1__p3_0 = {
  138267. _vq_quantthresh__44un1__p3_0,
  138268. _vq_quantmap__44un1__p3_0,
  138269. 5,
  138270. 5
  138271. };
  138272. static static_codebook _44un1__p3_0 = {
  138273. 4, 625,
  138274. _vq_lengthlist__44un1__p3_0,
  138275. 1, -533725184, 1611661312, 3, 0,
  138276. _vq_quantlist__44un1__p3_0,
  138277. NULL,
  138278. &_vq_auxt__44un1__p3_0,
  138279. NULL,
  138280. 0
  138281. };
  138282. static long _vq_quantlist__44un1__p4_0[] = {
  138283. 2,
  138284. 1,
  138285. 3,
  138286. 0,
  138287. 4,
  138288. };
  138289. static long _vq_lengthlist__44un1__p4_0[] = {
  138290. 3, 5, 5, 9, 9, 5, 6, 6,10, 9, 5, 6, 6, 9,10,10,
  138291. 10,10,12,11, 9,10,10,12,12, 5, 7, 7,10,10, 7, 7,
  138292. 8,10,11, 7, 7, 8,10,11,10,10,11,11,13,10,10,11,
  138293. 11,13, 6, 7, 7,10,10, 7, 8, 7,11,10, 7, 8, 7,10,
  138294. 10,10,11, 9,13,11,10,11,10,13,11,10,10,10,14,13,
  138295. 10,11,11,14,13,10,10,11,13,14,12,12,13,15,15,12,
  138296. 12,13,13,14,10,10,10,12,13,10,11,10,13,13,10,11,
  138297. 11,13,13,12,13,12,14,13,12,13,13,14,13, 5, 7, 7,
  138298. 10,10, 7, 8, 8,11,10, 7, 8, 8,10,10,11,11,11,13,
  138299. 13,10,11,11,12,12, 7, 8, 8,11,11, 7, 8, 9,10,12,
  138300. 8, 9, 9,11,11,11,10,12,11,14,11,11,12,13,13, 6,
  138301. 8, 8,10,11, 7, 9, 7,12,10, 8, 9,10,11,12,10,12,
  138302. 10,14,11,11,12,11,13,13,10,11,11,14,14,10,10,11,
  138303. 13,14,11,12,12,15,13,12,11,14,12,16,12,13,14,15,
  138304. 16,10,10,11,13,14,10,11,10,14,12,11,12,12,13,14,
  138305. 12,13,11,15,12,14,14,14,15,15, 5, 7, 7,10,10, 7,
  138306. 8, 8,10,10, 7, 8, 8,10,11,10,11,10,12,12,10,11,
  138307. 11,12,13, 6, 8, 8,11,11, 8, 9, 9,12,11, 7, 7, 9,
  138308. 10,12,11,11,11,12,13,11,10,12,11,15, 7, 8, 8,11,
  138309. 11, 8, 9, 9,11,11, 7, 9, 8,12,10,11,12,11,13,12,
  138310. 11,12,10,15,11,10,11,10,14,12,11,12,11,14,13,10,
  138311. 10,11,13,14,13,13,13,17,15,12,11,14,12,15,10,10,
  138312. 11,13,14,11,12,12,14,14,10,11,10,14,13,13,14,13,
  138313. 16,17,12,14,11,16,12, 9,10,10,14,13,10,11,10,14,
  138314. 14,10,11,11,13,13,13,14,14,16,15,12,13,13,14,14,
  138315. 9,11,10,14,13,10,10,12,13,14,11,12,11,14,13,13,
  138316. 14,14,14,15,13,14,14,15,15, 9,10,11,13,14,10,11,
  138317. 10,15,13,11,11,12,12,15,13,14,12,15,14,13,13,14,
  138318. 14,15,12,13,12,16,14,11,11,12,15,14,13,15,13,16,
  138319. 14,13,12,15,12,17,15,16,15,16,16,12,12,13,13,15,
  138320. 11,13,11,15,14,13,13,14,15,17,13,14,12, 0,13,14,
  138321. 15,14,15, 0, 9,10,10,13,13,10,11,11,13,13,10,11,
  138322. 11,13,13,12,13,12,14,14,13,14,14,15,17, 9,10,10,
  138323. 13,13,11,12,11,15,12,10,10,11,13,16,13,14,13,15,
  138324. 14,13,13,14,15,16,10,10,11,13,14,11,11,12,13,14,
  138325. 10,12,11,14,14,13,13,13,14,15,13,15,13,16,15,12,
  138326. 13,12,15,13,12,15,13,15,15,11,11,13,14,15,15,15,
  138327. 15,15,17,13,12,14,13,17,12,12,14,14,15,13,13,14,
  138328. 14,16,11,13,11,16,15,14,16,16,17, 0,14,13,11,16,
  138329. 12,
  138330. };
  138331. static float _vq_quantthresh__44un1__p4_0[] = {
  138332. -1.5, -0.5, 0.5, 1.5,
  138333. };
  138334. static long _vq_quantmap__44un1__p4_0[] = {
  138335. 3, 1, 0, 2, 4,
  138336. };
  138337. static encode_aux_threshmatch _vq_auxt__44un1__p4_0 = {
  138338. _vq_quantthresh__44un1__p4_0,
  138339. _vq_quantmap__44un1__p4_0,
  138340. 5,
  138341. 5
  138342. };
  138343. static static_codebook _44un1__p4_0 = {
  138344. 4, 625,
  138345. _vq_lengthlist__44un1__p4_0,
  138346. 1, -533725184, 1611661312, 3, 0,
  138347. _vq_quantlist__44un1__p4_0,
  138348. NULL,
  138349. &_vq_auxt__44un1__p4_0,
  138350. NULL,
  138351. 0
  138352. };
  138353. static long _vq_quantlist__44un1__p5_0[] = {
  138354. 4,
  138355. 3,
  138356. 5,
  138357. 2,
  138358. 6,
  138359. 1,
  138360. 7,
  138361. 0,
  138362. 8,
  138363. };
  138364. static long _vq_lengthlist__44un1__p5_0[] = {
  138365. 1, 4, 4, 7, 7, 8, 8, 9, 9, 4, 6, 5, 8, 7, 8, 8,
  138366. 10, 9, 4, 6, 6, 8, 8, 8, 8,10,10, 7, 8, 7, 9, 9,
  138367. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,11, 8, 8, 8,
  138368. 9, 9,10,10,11,11, 8, 8, 8, 9, 9,10,10,11,11, 9,
  138369. 10,10,11,10,11,11,12,12, 9,10,10,10,11,11,11,12,
  138370. 12,
  138371. };
  138372. static float _vq_quantthresh__44un1__p5_0[] = {
  138373. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  138374. };
  138375. static long _vq_quantmap__44un1__p5_0[] = {
  138376. 7, 5, 3, 1, 0, 2, 4, 6,
  138377. 8,
  138378. };
  138379. static encode_aux_threshmatch _vq_auxt__44un1__p5_0 = {
  138380. _vq_quantthresh__44un1__p5_0,
  138381. _vq_quantmap__44un1__p5_0,
  138382. 9,
  138383. 9
  138384. };
  138385. static static_codebook _44un1__p5_0 = {
  138386. 2, 81,
  138387. _vq_lengthlist__44un1__p5_0,
  138388. 1, -531628032, 1611661312, 4, 0,
  138389. _vq_quantlist__44un1__p5_0,
  138390. NULL,
  138391. &_vq_auxt__44un1__p5_0,
  138392. NULL,
  138393. 0
  138394. };
  138395. static long _vq_quantlist__44un1__p6_0[] = {
  138396. 6,
  138397. 5,
  138398. 7,
  138399. 4,
  138400. 8,
  138401. 3,
  138402. 9,
  138403. 2,
  138404. 10,
  138405. 1,
  138406. 11,
  138407. 0,
  138408. 12,
  138409. };
  138410. static long _vq_lengthlist__44un1__p6_0[] = {
  138411. 1, 4, 4, 6, 6, 8, 8,10,10,11,11,15,15, 4, 5, 5,
  138412. 8, 8, 9, 9,11,11,12,12,16,16, 4, 5, 6, 8, 8, 9,
  138413. 9,11,11,12,12,14,14, 7, 8, 8, 9, 9,10,10,11,12,
  138414. 13,13,16,17, 7, 8, 8, 9, 9,10,10,12,12,12,13,15,
  138415. 15, 9,10,10,10,10,11,11,12,12,13,13,15,16, 9, 9,
  138416. 9,10,10,11,11,13,12,13,13,17,17,10,11,11,11,12,
  138417. 12,12,13,13,14,15, 0,18,10,11,11,12,12,12,13,14,
  138418. 13,14,14,17,16,11,12,12,13,13,14,14,14,14,15,16,
  138419. 17,16,11,12,12,13,13,14,14,14,14,15,15,17,17,14,
  138420. 15,15,16,16,16,17,17,16, 0,17, 0,18,14,15,15,16,
  138421. 16, 0,15,18,18, 0,16, 0, 0,
  138422. };
  138423. static float _vq_quantthresh__44un1__p6_0[] = {
  138424. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  138425. 12.5, 17.5, 22.5, 27.5,
  138426. };
  138427. static long _vq_quantmap__44un1__p6_0[] = {
  138428. 11, 9, 7, 5, 3, 1, 0, 2,
  138429. 4, 6, 8, 10, 12,
  138430. };
  138431. static encode_aux_threshmatch _vq_auxt__44un1__p6_0 = {
  138432. _vq_quantthresh__44un1__p6_0,
  138433. _vq_quantmap__44un1__p6_0,
  138434. 13,
  138435. 13
  138436. };
  138437. static static_codebook _44un1__p6_0 = {
  138438. 2, 169,
  138439. _vq_lengthlist__44un1__p6_0,
  138440. 1, -526516224, 1616117760, 4, 0,
  138441. _vq_quantlist__44un1__p6_0,
  138442. NULL,
  138443. &_vq_auxt__44un1__p6_0,
  138444. NULL,
  138445. 0
  138446. };
  138447. static long _vq_quantlist__44un1__p6_1[] = {
  138448. 2,
  138449. 1,
  138450. 3,
  138451. 0,
  138452. 4,
  138453. };
  138454. static long _vq_lengthlist__44un1__p6_1[] = {
  138455. 2, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 6, 5, 5,
  138456. 6, 5, 6, 6, 5, 6, 6, 6, 6,
  138457. };
  138458. static float _vq_quantthresh__44un1__p6_1[] = {
  138459. -1.5, -0.5, 0.5, 1.5,
  138460. };
  138461. static long _vq_quantmap__44un1__p6_1[] = {
  138462. 3, 1, 0, 2, 4,
  138463. };
  138464. static encode_aux_threshmatch _vq_auxt__44un1__p6_1 = {
  138465. _vq_quantthresh__44un1__p6_1,
  138466. _vq_quantmap__44un1__p6_1,
  138467. 5,
  138468. 5
  138469. };
  138470. static static_codebook _44un1__p6_1 = {
  138471. 2, 25,
  138472. _vq_lengthlist__44un1__p6_1,
  138473. 1, -533725184, 1611661312, 3, 0,
  138474. _vq_quantlist__44un1__p6_1,
  138475. NULL,
  138476. &_vq_auxt__44un1__p6_1,
  138477. NULL,
  138478. 0
  138479. };
  138480. static long _vq_quantlist__44un1__p7_0[] = {
  138481. 2,
  138482. 1,
  138483. 3,
  138484. 0,
  138485. 4,
  138486. };
  138487. static long _vq_lengthlist__44un1__p7_0[] = {
  138488. 1, 5, 3,11,11,11,11,11,11,11, 8,11,11,11,11,11,
  138489. 11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,
  138490. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138491. 11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138492. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138493. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138494. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138495. 11,11,11,11,11,11,11,11,11,11,11,11,11, 8,11,11,
  138496. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138497. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138498. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
  138499. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138500. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138501. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138502. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138503. 11,11,11,11,11,11,11,11,11,11, 7,11,11,11,11,11,
  138504. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138505. 11,11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,
  138506. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138507. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138508. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138509. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138510. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138511. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138512. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138513. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138514. 11,11,11,11,11,11,11,11,11,11,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,11,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,11,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,11,
  138524. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138525. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138526. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138527. 10,
  138528. };
  138529. static float _vq_quantthresh__44un1__p7_0[] = {
  138530. -253.5, -84.5, 84.5, 253.5,
  138531. };
  138532. static long _vq_quantmap__44un1__p7_0[] = {
  138533. 3, 1, 0, 2, 4,
  138534. };
  138535. static encode_aux_threshmatch _vq_auxt__44un1__p7_0 = {
  138536. _vq_quantthresh__44un1__p7_0,
  138537. _vq_quantmap__44un1__p7_0,
  138538. 5,
  138539. 5
  138540. };
  138541. static static_codebook _44un1__p7_0 = {
  138542. 4, 625,
  138543. _vq_lengthlist__44un1__p7_0,
  138544. 1, -518709248, 1626677248, 3, 0,
  138545. _vq_quantlist__44un1__p7_0,
  138546. NULL,
  138547. &_vq_auxt__44un1__p7_0,
  138548. NULL,
  138549. 0
  138550. };
  138551. static long _vq_quantlist__44un1__p7_1[] = {
  138552. 6,
  138553. 5,
  138554. 7,
  138555. 4,
  138556. 8,
  138557. 3,
  138558. 9,
  138559. 2,
  138560. 10,
  138561. 1,
  138562. 11,
  138563. 0,
  138564. 12,
  138565. };
  138566. static long _vq_lengthlist__44un1__p7_1[] = {
  138567. 1, 4, 4, 6, 6, 6, 6, 9, 8, 9, 8, 8, 8, 5, 7, 7,
  138568. 7, 7, 8, 8, 8,10, 8,10, 8, 9, 5, 7, 7, 8, 7, 7,
  138569. 8,10,10,11,10,12,11, 7, 8, 8, 9, 9, 9,10,11,11,
  138570. 11,11,11,11, 7, 8, 8, 8, 9, 9, 9,10,10,10,11,11,
  138571. 12, 7, 8, 8, 9, 9,10,11,11,12,11,12,11,11, 7, 8,
  138572. 8, 9, 9,10,10,11,11,11,12,12,11, 8,10,10,10,10,
  138573. 11,11,14,11,12,12,12,13, 9,10,10,10,10,12,11,14,
  138574. 11,14,11,12,13,10,11,11,11,11,13,11,14,14,13,13,
  138575. 13,14,11,11,11,12,11,12,12,12,13,14,14,13,14,12,
  138576. 11,12,12,12,12,13,13,13,14,13,14,14,11,12,12,14,
  138577. 12,13,13,12,13,13,14,14,14,
  138578. };
  138579. static float _vq_quantthresh__44un1__p7_1[] = {
  138580. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  138581. 32.5, 45.5, 58.5, 71.5,
  138582. };
  138583. static long _vq_quantmap__44un1__p7_1[] = {
  138584. 11, 9, 7, 5, 3, 1, 0, 2,
  138585. 4, 6, 8, 10, 12,
  138586. };
  138587. static encode_aux_threshmatch _vq_auxt__44un1__p7_1 = {
  138588. _vq_quantthresh__44un1__p7_1,
  138589. _vq_quantmap__44un1__p7_1,
  138590. 13,
  138591. 13
  138592. };
  138593. static static_codebook _44un1__p7_1 = {
  138594. 2, 169,
  138595. _vq_lengthlist__44un1__p7_1,
  138596. 1, -523010048, 1618608128, 4, 0,
  138597. _vq_quantlist__44un1__p7_1,
  138598. NULL,
  138599. &_vq_auxt__44un1__p7_1,
  138600. NULL,
  138601. 0
  138602. };
  138603. static long _vq_quantlist__44un1__p7_2[] = {
  138604. 6,
  138605. 5,
  138606. 7,
  138607. 4,
  138608. 8,
  138609. 3,
  138610. 9,
  138611. 2,
  138612. 10,
  138613. 1,
  138614. 11,
  138615. 0,
  138616. 12,
  138617. };
  138618. static long _vq_lengthlist__44un1__p7_2[] = {
  138619. 3, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9, 9, 8, 4, 5, 5,
  138620. 6, 6, 8, 8, 9, 8, 9, 9, 9, 9, 4, 5, 5, 7, 6, 8,
  138621. 8, 8, 8, 9, 8, 9, 8, 6, 7, 7, 7, 8, 8, 8, 9, 9,
  138622. 9, 9, 9, 9, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  138623. 9, 7, 8, 8, 8, 8, 9, 8, 9, 9,10, 9, 9,10, 7, 8,
  138624. 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10, 8, 9, 9, 9, 9,
  138625. 9, 9, 9, 9,10,10, 9,10, 8, 9, 9, 9, 9, 9, 9, 9,
  138626. 9, 9, 9,10,10, 9, 9, 9,10, 9, 9,10, 9, 9,10,10,
  138627. 10,10, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10, 9,
  138628. 9, 9,10, 9, 9,10,10, 9,10,10,10,10, 9, 9, 9,10,
  138629. 9, 9, 9,10,10,10,10,10,10,
  138630. };
  138631. static float _vq_quantthresh__44un1__p7_2[] = {
  138632. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  138633. 2.5, 3.5, 4.5, 5.5,
  138634. };
  138635. static long _vq_quantmap__44un1__p7_2[] = {
  138636. 11, 9, 7, 5, 3, 1, 0, 2,
  138637. 4, 6, 8, 10, 12,
  138638. };
  138639. static encode_aux_threshmatch _vq_auxt__44un1__p7_2 = {
  138640. _vq_quantthresh__44un1__p7_2,
  138641. _vq_quantmap__44un1__p7_2,
  138642. 13,
  138643. 13
  138644. };
  138645. static static_codebook _44un1__p7_2 = {
  138646. 2, 169,
  138647. _vq_lengthlist__44un1__p7_2,
  138648. 1, -531103744, 1611661312, 4, 0,
  138649. _vq_quantlist__44un1__p7_2,
  138650. NULL,
  138651. &_vq_auxt__44un1__p7_2,
  138652. NULL,
  138653. 0
  138654. };
  138655. static long _huff_lengthlist__44un1__short[] = {
  138656. 12,12,14,12,14,14,14,14,12, 6, 6, 8, 9, 9,11,14,
  138657. 12, 4, 2, 6, 6, 7,11,14,13, 6, 5, 7, 8, 9,11,14,
  138658. 13, 8, 5, 8, 6, 8,12,14,12, 7, 7, 8, 8, 8,10,14,
  138659. 12, 6, 3, 4, 4, 4, 7,14,11, 7, 4, 6, 6, 6, 8,14,
  138660. };
  138661. static static_codebook _huff_book__44un1__short = {
  138662. 2, 64,
  138663. _huff_lengthlist__44un1__short,
  138664. 0, 0, 0, 0, 0,
  138665. NULL,
  138666. NULL,
  138667. NULL,
  138668. NULL,
  138669. 0
  138670. };
  138671. /*** End of inlined file: res_books_uncoupled.h ***/
  138672. static vorbis_info_residue0 _residue_44_low_un={
  138673. 0,-1, -1, 8,-1,
  138674. {0},
  138675. {-1},
  138676. { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 28.5},
  138677. { -1, 25, -1, 45, -1, -1, -1}
  138678. };
  138679. static vorbis_info_residue0 _residue_44_mid_un={
  138680. 0,-1, -1, 10,-1,
  138681. {0},
  138682. {-1},
  138683. { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 4.5, 16.5, 60.5},
  138684. { -1, 30, -1, 50, -1, 80, -1, -1, -1}
  138685. };
  138686. static vorbis_info_residue0 _residue_44_hi_un={
  138687. 0,-1, -1, 10,-1,
  138688. {0},
  138689. {-1},
  138690. { .5, 1.5, 2.5, 4.5, 8.5, 16.5, 32.5, 71.5,157.5},
  138691. { -1, -1, -1, -1, -1, -1, -1, -1, -1}
  138692. };
  138693. static vorbis_info_mapping0 _map_nominal_u[2]={
  138694. {1, {0,0}, {0}, {0}, 0,{0},{0}},
  138695. {1, {0,0}, {1}, {1}, 0,{0},{0}}
  138696. };
  138697. static static_bookblock _resbook_44u_n1={
  138698. {
  138699. {0},
  138700. {0,0,&_44un1__p1_0},
  138701. {0,0,&_44un1__p2_0},
  138702. {0,0,&_44un1__p3_0},
  138703. {0,0,&_44un1__p4_0},
  138704. {0,0,&_44un1__p5_0},
  138705. {&_44un1__p6_0,&_44un1__p6_1},
  138706. {&_44un1__p7_0,&_44un1__p7_1,&_44un1__p7_2}
  138707. }
  138708. };
  138709. static static_bookblock _resbook_44u_0={
  138710. {
  138711. {0},
  138712. {0,0,&_44u0__p1_0},
  138713. {0,0,&_44u0__p2_0},
  138714. {0,0,&_44u0__p3_0},
  138715. {0,0,&_44u0__p4_0},
  138716. {0,0,&_44u0__p5_0},
  138717. {&_44u0__p6_0,&_44u0__p6_1},
  138718. {&_44u0__p7_0,&_44u0__p7_1,&_44u0__p7_2}
  138719. }
  138720. };
  138721. static static_bookblock _resbook_44u_1={
  138722. {
  138723. {0},
  138724. {0,0,&_44u1__p1_0},
  138725. {0,0,&_44u1__p2_0},
  138726. {0,0,&_44u1__p3_0},
  138727. {0,0,&_44u1__p4_0},
  138728. {0,0,&_44u1__p5_0},
  138729. {&_44u1__p6_0,&_44u1__p6_1},
  138730. {&_44u1__p7_0,&_44u1__p7_1,&_44u1__p7_2}
  138731. }
  138732. };
  138733. static static_bookblock _resbook_44u_2={
  138734. {
  138735. {0},
  138736. {0,0,&_44u2__p1_0},
  138737. {0,0,&_44u2__p2_0},
  138738. {0,0,&_44u2__p3_0},
  138739. {0,0,&_44u2__p4_0},
  138740. {0,0,&_44u2__p5_0},
  138741. {&_44u2__p6_0,&_44u2__p6_1},
  138742. {&_44u2__p7_0,&_44u2__p7_1,&_44u2__p7_2}
  138743. }
  138744. };
  138745. static static_bookblock _resbook_44u_3={
  138746. {
  138747. {0},
  138748. {0,0,&_44u3__p1_0},
  138749. {0,0,&_44u3__p2_0},
  138750. {0,0,&_44u3__p3_0},
  138751. {0,0,&_44u3__p4_0},
  138752. {0,0,&_44u3__p5_0},
  138753. {&_44u3__p6_0,&_44u3__p6_1},
  138754. {&_44u3__p7_0,&_44u3__p7_1,&_44u3__p7_2}
  138755. }
  138756. };
  138757. static static_bookblock _resbook_44u_4={
  138758. {
  138759. {0},
  138760. {0,0,&_44u4__p1_0},
  138761. {0,0,&_44u4__p2_0},
  138762. {0,0,&_44u4__p3_0},
  138763. {0,0,&_44u4__p4_0},
  138764. {0,0,&_44u4__p5_0},
  138765. {&_44u4__p6_0,&_44u4__p6_1},
  138766. {&_44u4__p7_0,&_44u4__p7_1,&_44u4__p7_2}
  138767. }
  138768. };
  138769. static static_bookblock _resbook_44u_5={
  138770. {
  138771. {0},
  138772. {0,0,&_44u5__p1_0},
  138773. {0,0,&_44u5__p2_0},
  138774. {0,0,&_44u5__p3_0},
  138775. {0,0,&_44u5__p4_0},
  138776. {0,0,&_44u5__p5_0},
  138777. {0,0,&_44u5__p6_0},
  138778. {&_44u5__p7_0,&_44u5__p7_1},
  138779. {&_44u5__p8_0,&_44u5__p8_1},
  138780. {&_44u5__p9_0,&_44u5__p9_1,&_44u5__p9_2}
  138781. }
  138782. };
  138783. static static_bookblock _resbook_44u_6={
  138784. {
  138785. {0},
  138786. {0,0,&_44u6__p1_0},
  138787. {0,0,&_44u6__p2_0},
  138788. {0,0,&_44u6__p3_0},
  138789. {0,0,&_44u6__p4_0},
  138790. {0,0,&_44u6__p5_0},
  138791. {0,0,&_44u6__p6_0},
  138792. {&_44u6__p7_0,&_44u6__p7_1},
  138793. {&_44u6__p8_0,&_44u6__p8_1},
  138794. {&_44u6__p9_0,&_44u6__p9_1,&_44u6__p9_2}
  138795. }
  138796. };
  138797. static static_bookblock _resbook_44u_7={
  138798. {
  138799. {0},
  138800. {0,0,&_44u7__p1_0},
  138801. {0,0,&_44u7__p2_0},
  138802. {0,0,&_44u7__p3_0},
  138803. {0,0,&_44u7__p4_0},
  138804. {0,0,&_44u7__p5_0},
  138805. {0,0,&_44u7__p6_0},
  138806. {&_44u7__p7_0,&_44u7__p7_1},
  138807. {&_44u7__p8_0,&_44u7__p8_1},
  138808. {&_44u7__p9_0,&_44u7__p9_1,&_44u7__p9_2}
  138809. }
  138810. };
  138811. static static_bookblock _resbook_44u_8={
  138812. {
  138813. {0},
  138814. {0,0,&_44u8_p1_0},
  138815. {0,0,&_44u8_p2_0},
  138816. {0,0,&_44u8_p3_0},
  138817. {0,0,&_44u8_p4_0},
  138818. {&_44u8_p5_0,&_44u8_p5_1},
  138819. {&_44u8_p6_0,&_44u8_p6_1},
  138820. {&_44u8_p7_0,&_44u8_p7_1},
  138821. {&_44u8_p8_0,&_44u8_p8_1},
  138822. {&_44u8_p9_0,&_44u8_p9_1,&_44u8_p9_2}
  138823. }
  138824. };
  138825. static static_bookblock _resbook_44u_9={
  138826. {
  138827. {0},
  138828. {0,0,&_44u9_p1_0},
  138829. {0,0,&_44u9_p2_0},
  138830. {0,0,&_44u9_p3_0},
  138831. {0,0,&_44u9_p4_0},
  138832. {&_44u9_p5_0,&_44u9_p5_1},
  138833. {&_44u9_p6_0,&_44u9_p6_1},
  138834. {&_44u9_p7_0,&_44u9_p7_1},
  138835. {&_44u9_p8_0,&_44u9_p8_1},
  138836. {&_44u9_p9_0,&_44u9_p9_1,&_44u9_p9_2}
  138837. }
  138838. };
  138839. static vorbis_residue_template _res_44u_n1[]={
  138840. {1,0, &_residue_44_low_un,
  138841. &_huff_book__44un1__short,&_huff_book__44un1__short,
  138842. &_resbook_44u_n1,&_resbook_44u_n1},
  138843. {1,0, &_residue_44_low_un,
  138844. &_huff_book__44un1__long,&_huff_book__44un1__long,
  138845. &_resbook_44u_n1,&_resbook_44u_n1}
  138846. };
  138847. static vorbis_residue_template _res_44u_0[]={
  138848. {1,0, &_residue_44_low_un,
  138849. &_huff_book__44u0__short,&_huff_book__44u0__short,
  138850. &_resbook_44u_0,&_resbook_44u_0},
  138851. {1,0, &_residue_44_low_un,
  138852. &_huff_book__44u0__long,&_huff_book__44u0__long,
  138853. &_resbook_44u_0,&_resbook_44u_0}
  138854. };
  138855. static vorbis_residue_template _res_44u_1[]={
  138856. {1,0, &_residue_44_low_un,
  138857. &_huff_book__44u1__short,&_huff_book__44u1__short,
  138858. &_resbook_44u_1,&_resbook_44u_1},
  138859. {1,0, &_residue_44_low_un,
  138860. &_huff_book__44u1__long,&_huff_book__44u1__long,
  138861. &_resbook_44u_1,&_resbook_44u_1}
  138862. };
  138863. static vorbis_residue_template _res_44u_2[]={
  138864. {1,0, &_residue_44_low_un,
  138865. &_huff_book__44u2__short,&_huff_book__44u2__short,
  138866. &_resbook_44u_2,&_resbook_44u_2},
  138867. {1,0, &_residue_44_low_un,
  138868. &_huff_book__44u2__long,&_huff_book__44u2__long,
  138869. &_resbook_44u_2,&_resbook_44u_2}
  138870. };
  138871. static vorbis_residue_template _res_44u_3[]={
  138872. {1,0, &_residue_44_low_un,
  138873. &_huff_book__44u3__short,&_huff_book__44u3__short,
  138874. &_resbook_44u_3,&_resbook_44u_3},
  138875. {1,0, &_residue_44_low_un,
  138876. &_huff_book__44u3__long,&_huff_book__44u3__long,
  138877. &_resbook_44u_3,&_resbook_44u_3}
  138878. };
  138879. static vorbis_residue_template _res_44u_4[]={
  138880. {1,0, &_residue_44_low_un,
  138881. &_huff_book__44u4__short,&_huff_book__44u4__short,
  138882. &_resbook_44u_4,&_resbook_44u_4},
  138883. {1,0, &_residue_44_low_un,
  138884. &_huff_book__44u4__long,&_huff_book__44u4__long,
  138885. &_resbook_44u_4,&_resbook_44u_4}
  138886. };
  138887. static vorbis_residue_template _res_44u_5[]={
  138888. {1,0, &_residue_44_mid_un,
  138889. &_huff_book__44u5__short,&_huff_book__44u5__short,
  138890. &_resbook_44u_5,&_resbook_44u_5},
  138891. {1,0, &_residue_44_mid_un,
  138892. &_huff_book__44u5__long,&_huff_book__44u5__long,
  138893. &_resbook_44u_5,&_resbook_44u_5}
  138894. };
  138895. static vorbis_residue_template _res_44u_6[]={
  138896. {1,0, &_residue_44_mid_un,
  138897. &_huff_book__44u6__short,&_huff_book__44u6__short,
  138898. &_resbook_44u_6,&_resbook_44u_6},
  138899. {1,0, &_residue_44_mid_un,
  138900. &_huff_book__44u6__long,&_huff_book__44u6__long,
  138901. &_resbook_44u_6,&_resbook_44u_6}
  138902. };
  138903. static vorbis_residue_template _res_44u_7[]={
  138904. {1,0, &_residue_44_mid_un,
  138905. &_huff_book__44u7__short,&_huff_book__44u7__short,
  138906. &_resbook_44u_7,&_resbook_44u_7},
  138907. {1,0, &_residue_44_mid_un,
  138908. &_huff_book__44u7__long,&_huff_book__44u7__long,
  138909. &_resbook_44u_7,&_resbook_44u_7}
  138910. };
  138911. static vorbis_residue_template _res_44u_8[]={
  138912. {1,0, &_residue_44_hi_un,
  138913. &_huff_book__44u8__short,&_huff_book__44u8__short,
  138914. &_resbook_44u_8,&_resbook_44u_8},
  138915. {1,0, &_residue_44_hi_un,
  138916. &_huff_book__44u8__long,&_huff_book__44u8__long,
  138917. &_resbook_44u_8,&_resbook_44u_8}
  138918. };
  138919. static vorbis_residue_template _res_44u_9[]={
  138920. {1,0, &_residue_44_hi_un,
  138921. &_huff_book__44u9__short,&_huff_book__44u9__short,
  138922. &_resbook_44u_9,&_resbook_44u_9},
  138923. {1,0, &_residue_44_hi_un,
  138924. &_huff_book__44u9__long,&_huff_book__44u9__long,
  138925. &_resbook_44u_9,&_resbook_44u_9}
  138926. };
  138927. static vorbis_mapping_template _mapres_template_44_uncoupled[]={
  138928. { _map_nominal_u, _res_44u_n1 }, /* -1 */
  138929. { _map_nominal_u, _res_44u_0 }, /* 0 */
  138930. { _map_nominal_u, _res_44u_1 }, /* 1 */
  138931. { _map_nominal_u, _res_44u_2 }, /* 2 */
  138932. { _map_nominal_u, _res_44u_3 }, /* 3 */
  138933. { _map_nominal_u, _res_44u_4 }, /* 4 */
  138934. { _map_nominal_u, _res_44u_5 }, /* 5 */
  138935. { _map_nominal_u, _res_44u_6 }, /* 6 */
  138936. { _map_nominal_u, _res_44u_7 }, /* 7 */
  138937. { _map_nominal_u, _res_44u_8 }, /* 8 */
  138938. { _map_nominal_u, _res_44u_9 }, /* 9 */
  138939. };
  138940. /*** End of inlined file: residue_44u.h ***/
  138941. static double rate_mapping_44_un[12]={
  138942. 32000.,48000.,60000.,70000.,80000.,86000.,
  138943. 96000.,110000.,120000.,140000.,160000.,240001.
  138944. };
  138945. ve_setup_data_template ve_setup_44_uncoupled={
  138946. 11,
  138947. rate_mapping_44_un,
  138948. quality_mapping_44,
  138949. -1,
  138950. 40000,
  138951. 50000,
  138952. blocksize_short_44,
  138953. blocksize_long_44,
  138954. _psy_tone_masteratt_44,
  138955. _psy_tone_0dB,
  138956. _psy_tone_suppress,
  138957. _vp_tonemask_adj_otherblock,
  138958. _vp_tonemask_adj_longblock,
  138959. _vp_tonemask_adj_otherblock,
  138960. _psy_noiseguards_44,
  138961. _psy_noisebias_impulse,
  138962. _psy_noisebias_padding,
  138963. _psy_noisebias_trans,
  138964. _psy_noisebias_long,
  138965. _psy_noise_suppress,
  138966. _psy_compand_44,
  138967. _psy_compand_short_mapping,
  138968. _psy_compand_long_mapping,
  138969. {_noise_start_short_44,_noise_start_long_44},
  138970. {_noise_part_short_44,_noise_part_long_44},
  138971. _noise_thresh_44,
  138972. _psy_ath_floater,
  138973. _psy_ath_abs,
  138974. _psy_lowpass_44,
  138975. _psy_global_44,
  138976. _global_mapping_44,
  138977. NULL,
  138978. _floor_books,
  138979. _floor,
  138980. _floor_short_mapping_44,
  138981. _floor_long_mapping_44,
  138982. _mapres_template_44_uncoupled
  138983. };
  138984. /*** End of inlined file: setup_44u.h ***/
  138985. /*** Start of inlined file: setup_32.h ***/
  138986. static double rate_mapping_32[12]={
  138987. 18000.,28000.,35000.,45000.,56000.,60000.,
  138988. 75000.,90000.,100000.,115000.,150000.,190000.,
  138989. };
  138990. static double rate_mapping_32_un[12]={
  138991. 30000.,42000.,52000.,64000.,72000.,78000.,
  138992. 86000.,92000.,110000.,120000.,140000.,190000.,
  138993. };
  138994. static double _psy_lowpass_32[12]={
  138995. 12.3,13.,13.,14.,15.,99.,99.,99.,99.,99.,99.,99.
  138996. };
  138997. ve_setup_data_template ve_setup_32_stereo={
  138998. 11,
  138999. rate_mapping_32,
  139000. quality_mapping_44,
  139001. 2,
  139002. 26000,
  139003. 40000,
  139004. blocksize_short_44,
  139005. blocksize_long_44,
  139006. _psy_tone_masteratt_44,
  139007. _psy_tone_0dB,
  139008. _psy_tone_suppress,
  139009. _vp_tonemask_adj_otherblock,
  139010. _vp_tonemask_adj_longblock,
  139011. _vp_tonemask_adj_otherblock,
  139012. _psy_noiseguards_44,
  139013. _psy_noisebias_impulse,
  139014. _psy_noisebias_padding,
  139015. _psy_noisebias_trans,
  139016. _psy_noisebias_long,
  139017. _psy_noise_suppress,
  139018. _psy_compand_44,
  139019. _psy_compand_short_mapping,
  139020. _psy_compand_long_mapping,
  139021. {_noise_start_short_44,_noise_start_long_44},
  139022. {_noise_part_short_44,_noise_part_long_44},
  139023. _noise_thresh_44,
  139024. _psy_ath_floater,
  139025. _psy_ath_abs,
  139026. _psy_lowpass_32,
  139027. _psy_global_44,
  139028. _global_mapping_44,
  139029. _psy_stereo_modes_44,
  139030. _floor_books,
  139031. _floor,
  139032. _floor_short_mapping_44,
  139033. _floor_long_mapping_44,
  139034. _mapres_template_44_stereo
  139035. };
  139036. ve_setup_data_template ve_setup_32_uncoupled={
  139037. 11,
  139038. rate_mapping_32_un,
  139039. quality_mapping_44,
  139040. -1,
  139041. 26000,
  139042. 40000,
  139043. blocksize_short_44,
  139044. blocksize_long_44,
  139045. _psy_tone_masteratt_44,
  139046. _psy_tone_0dB,
  139047. _psy_tone_suppress,
  139048. _vp_tonemask_adj_otherblock,
  139049. _vp_tonemask_adj_longblock,
  139050. _vp_tonemask_adj_otherblock,
  139051. _psy_noiseguards_44,
  139052. _psy_noisebias_impulse,
  139053. _psy_noisebias_padding,
  139054. _psy_noisebias_trans,
  139055. _psy_noisebias_long,
  139056. _psy_noise_suppress,
  139057. _psy_compand_44,
  139058. _psy_compand_short_mapping,
  139059. _psy_compand_long_mapping,
  139060. {_noise_start_short_44,_noise_start_long_44},
  139061. {_noise_part_short_44,_noise_part_long_44},
  139062. _noise_thresh_44,
  139063. _psy_ath_floater,
  139064. _psy_ath_abs,
  139065. _psy_lowpass_32,
  139066. _psy_global_44,
  139067. _global_mapping_44,
  139068. NULL,
  139069. _floor_books,
  139070. _floor,
  139071. _floor_short_mapping_44,
  139072. _floor_long_mapping_44,
  139073. _mapres_template_44_uncoupled
  139074. };
  139075. /*** End of inlined file: setup_32.h ***/
  139076. /*** Start of inlined file: setup_8.h ***/
  139077. /*** Start of inlined file: psych_8.h ***/
  139078. static att3 _psy_tone_masteratt_8[3]={
  139079. {{ 32, 25, 12}, 0, 0}, /* 0 */
  139080. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139081. {{ 20, 0, -14}, 0, 0}, /* 0 */
  139082. };
  139083. static vp_adjblock _vp_tonemask_adj_8[3]={
  139084. {{-15,-15,-15,-15,-10,-10, -6, 0, 0, 0, 0,10, 0, 0,99,99,99}}, /* 1 */
  139085. {{-15,-15,-15,-15,-10,-10, -6, 0, 0, 0, 0,10, 0, 0,99,99,99}}, /* 1 */
  139086. {{-15,-15,-15,-15,-10,-10, -6, 0, 0, 0, 0, 0, 0, 0,99,99,99}}, /* 1 */
  139087. };
  139088. static noise3 _psy_noisebias_8[3]={
  139089. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 8, 8, 8, 10, 10, 99, 99, 99},
  139090. {-10,-10,-10,-10, -5, -5, -5, 0, 0, 4, 4, 4, 4, 4, 99, 99, 99},
  139091. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139092. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 8, 8, 8, 10, 10, 99, 99, 99},
  139093. {-10,-10,-10,-10,-10,-10, -5, -5, -5, 0, 0, 0, 0, 0, 99, 99, 99},
  139094. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139095. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 99, 99, 99},
  139096. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10, 99, 99, 99},
  139097. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24, 99, 99, 99}}},
  139098. };
  139099. static adj_stereo _psy_stereo_modes_8[3]={
  139100. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139101. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139102. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  139103. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139104. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139105. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139106. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  139107. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139108. {{ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139109. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139110. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  139111. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139112. };
  139113. static noiseguard _psy_noiseguards_8[2]={
  139114. {10,10,-1},
  139115. {10,10,-1},
  139116. };
  139117. static compandblock _psy_compand_8[2]={
  139118. {{
  139119. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  139120. 8, 8, 9, 9,10,10,11, 11, /* 15dB */
  139121. 12,12,13,13,14,14,15, 15, /* 23dB */
  139122. 16,16,17,17,17,18,18, 19, /* 31dB */
  139123. 19,19,20,21,22,23,24, 25, /* 39dB */
  139124. }},
  139125. {{
  139126. 0, 1, 2, 3, 4, 5, 6, 6, /* 7dB */
  139127. 7, 7, 6, 6, 5, 5, 4, 4, /* 15dB */
  139128. 3, 3, 3, 4, 5, 6, 7, 8, /* 23dB */
  139129. 9,10,11,12,13,14,15, 16, /* 31dB */
  139130. 17,18,19,20,21,22,23, 24, /* 39dB */
  139131. }},
  139132. };
  139133. static double _psy_lowpass_8[3]={3.,4.,4.};
  139134. static int _noise_start_8[2]={
  139135. 64,64,
  139136. };
  139137. static int _noise_part_8[2]={
  139138. 8,8,
  139139. };
  139140. static int _psy_ath_floater_8[3]={
  139141. -100,-100,-105,
  139142. };
  139143. static int _psy_ath_abs_8[3]={
  139144. -130,-130,-140,
  139145. };
  139146. /*** End of inlined file: psych_8.h ***/
  139147. /*** Start of inlined file: residue_8.h ***/
  139148. static static_bookblock _resbook_8s_0={
  139149. {
  139150. {0},{0,0,&_8c0_s_p1_0},{0,0,&_8c0_s_p2_0},{0,0,&_8c0_s_p3_0},
  139151. {0,0,&_8c0_s_p4_0},{0,0,&_8c0_s_p5_0},{0,0,&_8c0_s_p6_0},
  139152. {&_8c0_s_p7_0,&_8c0_s_p7_1},{&_8c0_s_p8_0,&_8c0_s_p8_1},
  139153. {&_8c0_s_p9_0,&_8c0_s_p9_1,&_8c0_s_p9_2}
  139154. }
  139155. };
  139156. static static_bookblock _resbook_8s_1={
  139157. {
  139158. {0},{0,0,&_8c1_s_p1_0},{0,0,&_8c1_s_p2_0},{0,0,&_8c1_s_p3_0},
  139159. {0,0,&_8c1_s_p4_0},{0,0,&_8c1_s_p5_0},{0,0,&_8c1_s_p6_0},
  139160. {&_8c1_s_p7_0,&_8c1_s_p7_1},{&_8c1_s_p8_0,&_8c1_s_p8_1},
  139161. {&_8c1_s_p9_0,&_8c1_s_p9_1,&_8c1_s_p9_2}
  139162. }
  139163. };
  139164. static vorbis_residue_template _res_8s_0[]={
  139165. {2,0, &_residue_44_mid,
  139166. &_huff_book__8c0_s_single,&_huff_book__8c0_s_single,
  139167. &_resbook_8s_0,&_resbook_8s_0},
  139168. };
  139169. static vorbis_residue_template _res_8s_1[]={
  139170. {2,0, &_residue_44_mid,
  139171. &_huff_book__8c1_s_single,&_huff_book__8c1_s_single,
  139172. &_resbook_8s_1,&_resbook_8s_1},
  139173. };
  139174. static vorbis_mapping_template _mapres_template_8_stereo[2]={
  139175. { _map_nominal, _res_8s_0 }, /* 0 */
  139176. { _map_nominal, _res_8s_1 }, /* 1 */
  139177. };
  139178. static static_bookblock _resbook_8u_0={
  139179. {
  139180. {0},
  139181. {0,0,&_8u0__p1_0},
  139182. {0,0,&_8u0__p2_0},
  139183. {0,0,&_8u0__p3_0},
  139184. {0,0,&_8u0__p4_0},
  139185. {0,0,&_8u0__p5_0},
  139186. {&_8u0__p6_0,&_8u0__p6_1},
  139187. {&_8u0__p7_0,&_8u0__p7_1,&_8u0__p7_2}
  139188. }
  139189. };
  139190. static static_bookblock _resbook_8u_1={
  139191. {
  139192. {0},
  139193. {0,0,&_8u1__p1_0},
  139194. {0,0,&_8u1__p2_0},
  139195. {0,0,&_8u1__p3_0},
  139196. {0,0,&_8u1__p4_0},
  139197. {0,0,&_8u1__p5_0},
  139198. {0,0,&_8u1__p6_0},
  139199. {&_8u1__p7_0,&_8u1__p7_1},
  139200. {&_8u1__p8_0,&_8u1__p8_1},
  139201. {&_8u1__p9_0,&_8u1__p9_1,&_8u1__p9_2}
  139202. }
  139203. };
  139204. static vorbis_residue_template _res_8u_0[]={
  139205. {1,0, &_residue_44_low_un,
  139206. &_huff_book__8u0__single,&_huff_book__8u0__single,
  139207. &_resbook_8u_0,&_resbook_8u_0},
  139208. };
  139209. static vorbis_residue_template _res_8u_1[]={
  139210. {1,0, &_residue_44_mid_un,
  139211. &_huff_book__8u1__single,&_huff_book__8u1__single,
  139212. &_resbook_8u_1,&_resbook_8u_1},
  139213. };
  139214. static vorbis_mapping_template _mapres_template_8_uncoupled[2]={
  139215. { _map_nominal_u, _res_8u_0 }, /* 0 */
  139216. { _map_nominal_u, _res_8u_1 }, /* 1 */
  139217. };
  139218. /*** End of inlined file: residue_8.h ***/
  139219. static int blocksize_8[2]={
  139220. 512,512
  139221. };
  139222. static int _floor_mapping_8[2]={
  139223. 6,6,
  139224. };
  139225. static double rate_mapping_8[3]={
  139226. 6000.,9000.,32000.,
  139227. };
  139228. static double rate_mapping_8_uncoupled[3]={
  139229. 8000.,14000.,42000.,
  139230. };
  139231. static double quality_mapping_8[3]={
  139232. -.1,.0,1.
  139233. };
  139234. static double _psy_compand_8_mapping[3]={ 0., 1., 1.};
  139235. static double _global_mapping_8[3]={ 1., 2., 3. };
  139236. ve_setup_data_template ve_setup_8_stereo={
  139237. 2,
  139238. rate_mapping_8,
  139239. quality_mapping_8,
  139240. 2,
  139241. 8000,
  139242. 9000,
  139243. blocksize_8,
  139244. blocksize_8,
  139245. _psy_tone_masteratt_8,
  139246. _psy_tone_0dB,
  139247. _psy_tone_suppress,
  139248. _vp_tonemask_adj_8,
  139249. NULL,
  139250. _vp_tonemask_adj_8,
  139251. _psy_noiseguards_8,
  139252. _psy_noisebias_8,
  139253. _psy_noisebias_8,
  139254. NULL,
  139255. NULL,
  139256. _psy_noise_suppress,
  139257. _psy_compand_8,
  139258. _psy_compand_8_mapping,
  139259. NULL,
  139260. {_noise_start_8,_noise_start_8},
  139261. {_noise_part_8,_noise_part_8},
  139262. _noise_thresh_5only,
  139263. _psy_ath_floater_8,
  139264. _psy_ath_abs_8,
  139265. _psy_lowpass_8,
  139266. _psy_global_44,
  139267. _global_mapping_8,
  139268. _psy_stereo_modes_8,
  139269. _floor_books,
  139270. _floor,
  139271. _floor_mapping_8,
  139272. NULL,
  139273. _mapres_template_8_stereo
  139274. };
  139275. ve_setup_data_template ve_setup_8_uncoupled={
  139276. 2,
  139277. rate_mapping_8_uncoupled,
  139278. quality_mapping_8,
  139279. -1,
  139280. 8000,
  139281. 9000,
  139282. blocksize_8,
  139283. blocksize_8,
  139284. _psy_tone_masteratt_8,
  139285. _psy_tone_0dB,
  139286. _psy_tone_suppress,
  139287. _vp_tonemask_adj_8,
  139288. NULL,
  139289. _vp_tonemask_adj_8,
  139290. _psy_noiseguards_8,
  139291. _psy_noisebias_8,
  139292. _psy_noisebias_8,
  139293. NULL,
  139294. NULL,
  139295. _psy_noise_suppress,
  139296. _psy_compand_8,
  139297. _psy_compand_8_mapping,
  139298. NULL,
  139299. {_noise_start_8,_noise_start_8},
  139300. {_noise_part_8,_noise_part_8},
  139301. _noise_thresh_5only,
  139302. _psy_ath_floater_8,
  139303. _psy_ath_abs_8,
  139304. _psy_lowpass_8,
  139305. _psy_global_44,
  139306. _global_mapping_8,
  139307. _psy_stereo_modes_8,
  139308. _floor_books,
  139309. _floor,
  139310. _floor_mapping_8,
  139311. NULL,
  139312. _mapres_template_8_uncoupled
  139313. };
  139314. /*** End of inlined file: setup_8.h ***/
  139315. /*** Start of inlined file: setup_11.h ***/
  139316. /*** Start of inlined file: psych_11.h ***/
  139317. static double _psy_lowpass_11[3]={4.5,5.5,30.,};
  139318. static att3 _psy_tone_masteratt_11[3]={
  139319. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139320. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139321. {{ 20, 0, -14}, 0, 0}, /* 0 */
  139322. };
  139323. static vp_adjblock _vp_tonemask_adj_11[3]={
  139324. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0,10, 2, 0,99,99,99}}, /* 0 */
  139325. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 5, 0, 0,99,99,99}}, /* 1 */
  139326. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 0, 0, 0,99,99,99}}, /* 2 */
  139327. };
  139328. static noise3 _psy_noisebias_11[3]={
  139329. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 10, 10, 12, 12, 12, 99, 99, 99},
  139330. {-15,-15,-15,-15,-10,-10, -5, 0, 0, 4, 4, 5, 5, 10, 99, 99, 99},
  139331. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139332. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 10, 10, 12, 12, 12, 99, 99, 99},
  139333. {-15,-15,-15,-15,-10,-10, -5, -5, -5, 0, 0, 0, 0, 0, 99, 99, 99},
  139334. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139335. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 99, 99, 99},
  139336. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10, 99, 99, 99},
  139337. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24, 99, 99, 99}}},
  139338. };
  139339. static double _noise_thresh_11[3]={ .3,.5,.5 };
  139340. /*** End of inlined file: psych_11.h ***/
  139341. static int blocksize_11[2]={
  139342. 512,512
  139343. };
  139344. static int _floor_mapping_11[2]={
  139345. 6,6,
  139346. };
  139347. static double rate_mapping_11[3]={
  139348. 8000.,13000.,44000.,
  139349. };
  139350. static double rate_mapping_11_uncoupled[3]={
  139351. 12000.,20000.,50000.,
  139352. };
  139353. static double quality_mapping_11[3]={
  139354. -.1,.0,1.
  139355. };
  139356. ve_setup_data_template ve_setup_11_stereo={
  139357. 2,
  139358. rate_mapping_11,
  139359. quality_mapping_11,
  139360. 2,
  139361. 9000,
  139362. 15000,
  139363. blocksize_11,
  139364. blocksize_11,
  139365. _psy_tone_masteratt_11,
  139366. _psy_tone_0dB,
  139367. _psy_tone_suppress,
  139368. _vp_tonemask_adj_11,
  139369. NULL,
  139370. _vp_tonemask_adj_11,
  139371. _psy_noiseguards_8,
  139372. _psy_noisebias_11,
  139373. _psy_noisebias_11,
  139374. NULL,
  139375. NULL,
  139376. _psy_noise_suppress,
  139377. _psy_compand_8,
  139378. _psy_compand_8_mapping,
  139379. NULL,
  139380. {_noise_start_8,_noise_start_8},
  139381. {_noise_part_8,_noise_part_8},
  139382. _noise_thresh_11,
  139383. _psy_ath_floater_8,
  139384. _psy_ath_abs_8,
  139385. _psy_lowpass_11,
  139386. _psy_global_44,
  139387. _global_mapping_8,
  139388. _psy_stereo_modes_8,
  139389. _floor_books,
  139390. _floor,
  139391. _floor_mapping_11,
  139392. NULL,
  139393. _mapres_template_8_stereo
  139394. };
  139395. ve_setup_data_template ve_setup_11_uncoupled={
  139396. 2,
  139397. rate_mapping_11_uncoupled,
  139398. quality_mapping_11,
  139399. -1,
  139400. 9000,
  139401. 15000,
  139402. blocksize_11,
  139403. blocksize_11,
  139404. _psy_tone_masteratt_11,
  139405. _psy_tone_0dB,
  139406. _psy_tone_suppress,
  139407. _vp_tonemask_adj_11,
  139408. NULL,
  139409. _vp_tonemask_adj_11,
  139410. _psy_noiseguards_8,
  139411. _psy_noisebias_11,
  139412. _psy_noisebias_11,
  139413. NULL,
  139414. NULL,
  139415. _psy_noise_suppress,
  139416. _psy_compand_8,
  139417. _psy_compand_8_mapping,
  139418. NULL,
  139419. {_noise_start_8,_noise_start_8},
  139420. {_noise_part_8,_noise_part_8},
  139421. _noise_thresh_11,
  139422. _psy_ath_floater_8,
  139423. _psy_ath_abs_8,
  139424. _psy_lowpass_11,
  139425. _psy_global_44,
  139426. _global_mapping_8,
  139427. _psy_stereo_modes_8,
  139428. _floor_books,
  139429. _floor,
  139430. _floor_mapping_11,
  139431. NULL,
  139432. _mapres_template_8_uncoupled
  139433. };
  139434. /*** End of inlined file: setup_11.h ***/
  139435. /*** Start of inlined file: setup_16.h ***/
  139436. /*** Start of inlined file: psych_16.h ***/
  139437. static adj_stereo _psy_stereo_modes_16[4]={
  139438. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139439. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139440. { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 4, 4},
  139441. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139442. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139443. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139444. { 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 4, 4, 4, 4, 4},
  139445. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139446. {{ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139447. { 5, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139448. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139449. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139450. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  139451. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  139452. { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8},
  139453. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139454. };
  139455. static double _psy_lowpass_16[4]={6.5,8,30.,99.};
  139456. static att3 _psy_tone_masteratt_16[4]={
  139457. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139458. {{ 25, 22, 12}, 0, 0}, /* 0 */
  139459. {{ 20, 12, 0}, 0, 0}, /* 0 */
  139460. {{ 15, 0, -14}, 0, 0}, /* 0 */
  139461. };
  139462. static vp_adjblock _vp_tonemask_adj_16[4]={
  139463. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0,10, 0, 0, 0, 0, 0}}, /* 0 */
  139464. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0,10, 0, 0, 0, 0, 0}}, /* 1 */
  139465. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, /* 2 */
  139466. {{-30,-30,-30,-30,-30,-26,-20,-10, -5, 0, 0, 0, 0, 0, 0, 0, 0}}, /* 2 */
  139467. };
  139468. static noise3 _psy_noisebias_16_short[4]={
  139469. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 10, 10, 10, 10, 12, 12, 14, 20},
  139470. {-15,-15,-15,-15,-15,-10,-10, -5, 0, 0, 4, 5, 5, 6, 8, 8, 15},
  139471. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139472. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 6, 6, 6, 6, 8, 10, 12, 20},
  139473. {-15,-15,-15,-15,-15,-15,-15,-10, -5, -5, -5, 4, 5, 6, 8, 8, 15},
  139474. {-30,-30,-30,-30,-30,-24,-20,-14,-10,-10,-10,-10,-10,-10,-10,-10,-10}}},
  139475. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 5, 8, 12},
  139476. {-20,-20,-20,-20,-16,-12,-20,-14,-10,-10, -8, 0, 0, 0, 0, 2, 5},
  139477. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139478. {{{-15,-15,-15,-15,-15,-12,-10, -8, -5, -5, -5, -5, -5, 0, 0, 0, 6},
  139479. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10,-10,-10, -6},
  139480. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139481. };
  139482. static noise3 _psy_noisebias_16_impulse[4]={
  139483. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 10, 10, 10, 10, 12, 12, 14, 20},
  139484. {-15,-15,-15,-15,-15,-10,-10, -5, 0, 0, 4, 5, 5, 6, 8, 8, 15},
  139485. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139486. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 4, 4, 4, 5, 5, 6, 8, 15},
  139487. {-15,-15,-15,-15,-15,-15,-15,-10, -5, -5, -5, 0, 0, 0, 0, 4, 10},
  139488. {-30,-30,-30,-30,-30,-24,-20,-14,-10,-10,-10,-10,-10,-10,-10,-10,-10}}},
  139489. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 0, 0, 0, 0, 0, 0, 4, 10},
  139490. {-20,-20,-20,-20,-16,-12,-20,-14,-10,-10,-10,-10,-10,-10,-10, -7, -5},
  139491. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139492. {{{-15,-15,-15,-15,-15,-12,-10, -8, -5, -5, -5, -5, -5, 0, 0, 0, 6},
  139493. {-30,-30,-30,-30,-26,-22,-20,-18,-18,-18,-20,-20,-20,-20,-20,-20,-16},
  139494. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139495. };
  139496. static noise3 _psy_noisebias_16[4]={
  139497. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 6, 8, 8, 10, 10, 10, 14, 20},
  139498. {-10,-10,-10,-10,-10, -5, -2, -2, 0, 0, 0, 4, 5, 6, 8, 8, 15},
  139499. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139500. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 6, 6, 6, 6, 8, 10, 12, 20},
  139501. {-15,-15,-15,-15,-15,-10, -5, -5, 0, 0, 0, 4, 5, 6, 8, 8, 15},
  139502. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139503. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 5, 8, 12},
  139504. {-20,-20,-20,-20,-16,-12,-20,-10, -5, -5, 0, 0, 0, 0, 0, 2, 5},
  139505. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139506. {{{-15,-15,-15,-15,-15,-12,-10, -8, -5, -5, -5, -5, -5, 0, 0, 0, 6},
  139507. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10,-10,-10, -6},
  139508. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139509. };
  139510. static double _noise_thresh_16[4]={ .3,.5,.5,.5 };
  139511. static int _noise_start_16[3]={ 256,256,9999 };
  139512. static int _noise_part_16[4]={ 8,8,8,8 };
  139513. static int _psy_ath_floater_16[4]={
  139514. -100,-100,-100,-105,
  139515. };
  139516. static int _psy_ath_abs_16[4]={
  139517. -130,-130,-130,-140,
  139518. };
  139519. /*** End of inlined file: psych_16.h ***/
  139520. /*** Start of inlined file: residue_16.h ***/
  139521. static static_bookblock _resbook_16s_0={
  139522. {
  139523. {0},
  139524. {0,0,&_16c0_s_p1_0},
  139525. {0,0,&_16c0_s_p2_0},
  139526. {0,0,&_16c0_s_p3_0},
  139527. {0,0,&_16c0_s_p4_0},
  139528. {0,0,&_16c0_s_p5_0},
  139529. {0,0,&_16c0_s_p6_0},
  139530. {&_16c0_s_p7_0,&_16c0_s_p7_1},
  139531. {&_16c0_s_p8_0,&_16c0_s_p8_1},
  139532. {&_16c0_s_p9_0,&_16c0_s_p9_1,&_16c0_s_p9_2}
  139533. }
  139534. };
  139535. static static_bookblock _resbook_16s_1={
  139536. {
  139537. {0},
  139538. {0,0,&_16c1_s_p1_0},
  139539. {0,0,&_16c1_s_p2_0},
  139540. {0,0,&_16c1_s_p3_0},
  139541. {0,0,&_16c1_s_p4_0},
  139542. {0,0,&_16c1_s_p5_0},
  139543. {0,0,&_16c1_s_p6_0},
  139544. {&_16c1_s_p7_0,&_16c1_s_p7_1},
  139545. {&_16c1_s_p8_0,&_16c1_s_p8_1},
  139546. {&_16c1_s_p9_0,&_16c1_s_p9_1,&_16c1_s_p9_2}
  139547. }
  139548. };
  139549. static static_bookblock _resbook_16s_2={
  139550. {
  139551. {0},
  139552. {0,0,&_16c2_s_p1_0},
  139553. {0,0,&_16c2_s_p2_0},
  139554. {0,0,&_16c2_s_p3_0},
  139555. {0,0,&_16c2_s_p4_0},
  139556. {&_16c2_s_p5_0,&_16c2_s_p5_1},
  139557. {&_16c2_s_p6_0,&_16c2_s_p6_1},
  139558. {&_16c2_s_p7_0,&_16c2_s_p7_1},
  139559. {&_16c2_s_p8_0,&_16c2_s_p8_1},
  139560. {&_16c2_s_p9_0,&_16c2_s_p9_1,&_16c2_s_p9_2}
  139561. }
  139562. };
  139563. static vorbis_residue_template _res_16s_0[]={
  139564. {2,0, &_residue_44_mid,
  139565. &_huff_book__16c0_s_single,&_huff_book__16c0_s_single,
  139566. &_resbook_16s_0,&_resbook_16s_0},
  139567. };
  139568. static vorbis_residue_template _res_16s_1[]={
  139569. {2,0, &_residue_44_mid,
  139570. &_huff_book__16c1_s_short,&_huff_book__16c1_s_short,
  139571. &_resbook_16s_1,&_resbook_16s_1},
  139572. {2,0, &_residue_44_mid,
  139573. &_huff_book__16c1_s_long,&_huff_book__16c1_s_long,
  139574. &_resbook_16s_1,&_resbook_16s_1}
  139575. };
  139576. static vorbis_residue_template _res_16s_2[]={
  139577. {2,0, &_residue_44_high,
  139578. &_huff_book__16c2_s_short,&_huff_book__16c2_s_short,
  139579. &_resbook_16s_2,&_resbook_16s_2},
  139580. {2,0, &_residue_44_high,
  139581. &_huff_book__16c2_s_long,&_huff_book__16c2_s_long,
  139582. &_resbook_16s_2,&_resbook_16s_2}
  139583. };
  139584. static vorbis_mapping_template _mapres_template_16_stereo[3]={
  139585. { _map_nominal, _res_16s_0 }, /* 0 */
  139586. { _map_nominal, _res_16s_1 }, /* 1 */
  139587. { _map_nominal, _res_16s_2 }, /* 2 */
  139588. };
  139589. static static_bookblock _resbook_16u_0={
  139590. {
  139591. {0},
  139592. {0,0,&_16u0__p1_0},
  139593. {0,0,&_16u0__p2_0},
  139594. {0,0,&_16u0__p3_0},
  139595. {0,0,&_16u0__p4_0},
  139596. {0,0,&_16u0__p5_0},
  139597. {&_16u0__p6_0,&_16u0__p6_1},
  139598. {&_16u0__p7_0,&_16u0__p7_1,&_16u0__p7_2}
  139599. }
  139600. };
  139601. static static_bookblock _resbook_16u_1={
  139602. {
  139603. {0},
  139604. {0,0,&_16u1__p1_0},
  139605. {0,0,&_16u1__p2_0},
  139606. {0,0,&_16u1__p3_0},
  139607. {0,0,&_16u1__p4_0},
  139608. {0,0,&_16u1__p5_0},
  139609. {0,0,&_16u1__p6_0},
  139610. {&_16u1__p7_0,&_16u1__p7_1},
  139611. {&_16u1__p8_0,&_16u1__p8_1},
  139612. {&_16u1__p9_0,&_16u1__p9_1,&_16u1__p9_2}
  139613. }
  139614. };
  139615. static static_bookblock _resbook_16u_2={
  139616. {
  139617. {0},
  139618. {0,0,&_16u2_p1_0},
  139619. {0,0,&_16u2_p2_0},
  139620. {0,0,&_16u2_p3_0},
  139621. {0,0,&_16u2_p4_0},
  139622. {&_16u2_p5_0,&_16u2_p5_1},
  139623. {&_16u2_p6_0,&_16u2_p6_1},
  139624. {&_16u2_p7_0,&_16u2_p7_1},
  139625. {&_16u2_p8_0,&_16u2_p8_1},
  139626. {&_16u2_p9_0,&_16u2_p9_1,&_16u2_p9_2}
  139627. }
  139628. };
  139629. static vorbis_residue_template _res_16u_0[]={
  139630. {1,0, &_residue_44_low_un,
  139631. &_huff_book__16u0__single,&_huff_book__16u0__single,
  139632. &_resbook_16u_0,&_resbook_16u_0},
  139633. };
  139634. static vorbis_residue_template _res_16u_1[]={
  139635. {1,0, &_residue_44_mid_un,
  139636. &_huff_book__16u1__short,&_huff_book__16u1__short,
  139637. &_resbook_16u_1,&_resbook_16u_1},
  139638. {1,0, &_residue_44_mid_un,
  139639. &_huff_book__16u1__long,&_huff_book__16u1__long,
  139640. &_resbook_16u_1,&_resbook_16u_1}
  139641. };
  139642. static vorbis_residue_template _res_16u_2[]={
  139643. {1,0, &_residue_44_hi_un,
  139644. &_huff_book__16u2__short,&_huff_book__16u2__short,
  139645. &_resbook_16u_2,&_resbook_16u_2},
  139646. {1,0, &_residue_44_hi_un,
  139647. &_huff_book__16u2__long,&_huff_book__16u2__long,
  139648. &_resbook_16u_2,&_resbook_16u_2}
  139649. };
  139650. static vorbis_mapping_template _mapres_template_16_uncoupled[3]={
  139651. { _map_nominal_u, _res_16u_0 }, /* 0 */
  139652. { _map_nominal_u, _res_16u_1 }, /* 1 */
  139653. { _map_nominal_u, _res_16u_2 }, /* 2 */
  139654. };
  139655. /*** End of inlined file: residue_16.h ***/
  139656. static int blocksize_16_short[3]={
  139657. 1024,512,512
  139658. };
  139659. static int blocksize_16_long[3]={
  139660. 1024,1024,1024
  139661. };
  139662. static int _floor_mapping_16_short[3]={
  139663. 9,3,3
  139664. };
  139665. static int _floor_mapping_16[3]={
  139666. 9,9,9
  139667. };
  139668. static double rate_mapping_16[4]={
  139669. 12000.,20000.,44000.,86000.
  139670. };
  139671. static double rate_mapping_16_uncoupled[4]={
  139672. 16000.,28000.,64000.,100000.
  139673. };
  139674. static double _global_mapping_16[4]={ 1., 2., 3., 4. };
  139675. static double quality_mapping_16[4]={ -.1,.05,.5,1. };
  139676. static double _psy_compand_16_mapping[4]={ 0., .8, 1., 1.};
  139677. ve_setup_data_template ve_setup_16_stereo={
  139678. 3,
  139679. rate_mapping_16,
  139680. quality_mapping_16,
  139681. 2,
  139682. 15000,
  139683. 19000,
  139684. blocksize_16_short,
  139685. blocksize_16_long,
  139686. _psy_tone_masteratt_16,
  139687. _psy_tone_0dB,
  139688. _psy_tone_suppress,
  139689. _vp_tonemask_adj_16,
  139690. _vp_tonemask_adj_16,
  139691. _vp_tonemask_adj_16,
  139692. _psy_noiseguards_8,
  139693. _psy_noisebias_16_impulse,
  139694. _psy_noisebias_16_short,
  139695. _psy_noisebias_16_short,
  139696. _psy_noisebias_16,
  139697. _psy_noise_suppress,
  139698. _psy_compand_8,
  139699. _psy_compand_16_mapping,
  139700. _psy_compand_16_mapping,
  139701. {_noise_start_16,_noise_start_16},
  139702. { _noise_part_16, _noise_part_16},
  139703. _noise_thresh_16,
  139704. _psy_ath_floater_16,
  139705. _psy_ath_abs_16,
  139706. _psy_lowpass_16,
  139707. _psy_global_44,
  139708. _global_mapping_16,
  139709. _psy_stereo_modes_16,
  139710. _floor_books,
  139711. _floor,
  139712. _floor_mapping_16_short,
  139713. _floor_mapping_16,
  139714. _mapres_template_16_stereo
  139715. };
  139716. ve_setup_data_template ve_setup_16_uncoupled={
  139717. 3,
  139718. rate_mapping_16_uncoupled,
  139719. quality_mapping_16,
  139720. -1,
  139721. 15000,
  139722. 19000,
  139723. blocksize_16_short,
  139724. blocksize_16_long,
  139725. _psy_tone_masteratt_16,
  139726. _psy_tone_0dB,
  139727. _psy_tone_suppress,
  139728. _vp_tonemask_adj_16,
  139729. _vp_tonemask_adj_16,
  139730. _vp_tonemask_adj_16,
  139731. _psy_noiseguards_8,
  139732. _psy_noisebias_16_impulse,
  139733. _psy_noisebias_16_short,
  139734. _psy_noisebias_16_short,
  139735. _psy_noisebias_16,
  139736. _psy_noise_suppress,
  139737. _psy_compand_8,
  139738. _psy_compand_16_mapping,
  139739. _psy_compand_16_mapping,
  139740. {_noise_start_16,_noise_start_16},
  139741. { _noise_part_16, _noise_part_16},
  139742. _noise_thresh_16,
  139743. _psy_ath_floater_16,
  139744. _psy_ath_abs_16,
  139745. _psy_lowpass_16,
  139746. _psy_global_44,
  139747. _global_mapping_16,
  139748. _psy_stereo_modes_16,
  139749. _floor_books,
  139750. _floor,
  139751. _floor_mapping_16_short,
  139752. _floor_mapping_16,
  139753. _mapres_template_16_uncoupled
  139754. };
  139755. /*** End of inlined file: setup_16.h ***/
  139756. /*** Start of inlined file: setup_22.h ***/
  139757. static double rate_mapping_22[4]={
  139758. 15000.,20000.,44000.,86000.
  139759. };
  139760. static double rate_mapping_22_uncoupled[4]={
  139761. 16000.,28000.,50000.,90000.
  139762. };
  139763. static double _psy_lowpass_22[4]={9.5,11.,30.,99.};
  139764. ve_setup_data_template ve_setup_22_stereo={
  139765. 3,
  139766. rate_mapping_22,
  139767. quality_mapping_16,
  139768. 2,
  139769. 19000,
  139770. 26000,
  139771. blocksize_16_short,
  139772. blocksize_16_long,
  139773. _psy_tone_masteratt_16,
  139774. _psy_tone_0dB,
  139775. _psy_tone_suppress,
  139776. _vp_tonemask_adj_16,
  139777. _vp_tonemask_adj_16,
  139778. _vp_tonemask_adj_16,
  139779. _psy_noiseguards_8,
  139780. _psy_noisebias_16_impulse,
  139781. _psy_noisebias_16_short,
  139782. _psy_noisebias_16_short,
  139783. _psy_noisebias_16,
  139784. _psy_noise_suppress,
  139785. _psy_compand_8,
  139786. _psy_compand_8_mapping,
  139787. _psy_compand_8_mapping,
  139788. {_noise_start_16,_noise_start_16},
  139789. { _noise_part_16, _noise_part_16},
  139790. _noise_thresh_16,
  139791. _psy_ath_floater_16,
  139792. _psy_ath_abs_16,
  139793. _psy_lowpass_22,
  139794. _psy_global_44,
  139795. _global_mapping_16,
  139796. _psy_stereo_modes_16,
  139797. _floor_books,
  139798. _floor,
  139799. _floor_mapping_16_short,
  139800. _floor_mapping_16,
  139801. _mapres_template_16_stereo
  139802. };
  139803. ve_setup_data_template ve_setup_22_uncoupled={
  139804. 3,
  139805. rate_mapping_22_uncoupled,
  139806. quality_mapping_16,
  139807. -1,
  139808. 19000,
  139809. 26000,
  139810. blocksize_16_short,
  139811. blocksize_16_long,
  139812. _psy_tone_masteratt_16,
  139813. _psy_tone_0dB,
  139814. _psy_tone_suppress,
  139815. _vp_tonemask_adj_16,
  139816. _vp_tonemask_adj_16,
  139817. _vp_tonemask_adj_16,
  139818. _psy_noiseguards_8,
  139819. _psy_noisebias_16_impulse,
  139820. _psy_noisebias_16_short,
  139821. _psy_noisebias_16_short,
  139822. _psy_noisebias_16,
  139823. _psy_noise_suppress,
  139824. _psy_compand_8,
  139825. _psy_compand_8_mapping,
  139826. _psy_compand_8_mapping,
  139827. {_noise_start_16,_noise_start_16},
  139828. { _noise_part_16, _noise_part_16},
  139829. _noise_thresh_16,
  139830. _psy_ath_floater_16,
  139831. _psy_ath_abs_16,
  139832. _psy_lowpass_22,
  139833. _psy_global_44,
  139834. _global_mapping_16,
  139835. _psy_stereo_modes_16,
  139836. _floor_books,
  139837. _floor,
  139838. _floor_mapping_16_short,
  139839. _floor_mapping_16,
  139840. _mapres_template_16_uncoupled
  139841. };
  139842. /*** End of inlined file: setup_22.h ***/
  139843. /*** Start of inlined file: setup_X.h ***/
  139844. static double rate_mapping_X[12]={
  139845. -1.,-1.,-1.,-1.,-1.,-1.,
  139846. -1.,-1.,-1.,-1.,-1.,-1.
  139847. };
  139848. ve_setup_data_template ve_setup_X_stereo={
  139849. 11,
  139850. rate_mapping_X,
  139851. quality_mapping_44,
  139852. 2,
  139853. 50000,
  139854. 200000,
  139855. blocksize_short_44,
  139856. blocksize_long_44,
  139857. _psy_tone_masteratt_44,
  139858. _psy_tone_0dB,
  139859. _psy_tone_suppress,
  139860. _vp_tonemask_adj_otherblock,
  139861. _vp_tonemask_adj_longblock,
  139862. _vp_tonemask_adj_otherblock,
  139863. _psy_noiseguards_44,
  139864. _psy_noisebias_impulse,
  139865. _psy_noisebias_padding,
  139866. _psy_noisebias_trans,
  139867. _psy_noisebias_long,
  139868. _psy_noise_suppress,
  139869. _psy_compand_44,
  139870. _psy_compand_short_mapping,
  139871. _psy_compand_long_mapping,
  139872. {_noise_start_short_44,_noise_start_long_44},
  139873. {_noise_part_short_44,_noise_part_long_44},
  139874. _noise_thresh_44,
  139875. _psy_ath_floater,
  139876. _psy_ath_abs,
  139877. _psy_lowpass_44,
  139878. _psy_global_44,
  139879. _global_mapping_44,
  139880. _psy_stereo_modes_44,
  139881. _floor_books,
  139882. _floor,
  139883. _floor_short_mapping_44,
  139884. _floor_long_mapping_44,
  139885. _mapres_template_44_stereo
  139886. };
  139887. ve_setup_data_template ve_setup_X_uncoupled={
  139888. 11,
  139889. rate_mapping_X,
  139890. quality_mapping_44,
  139891. -1,
  139892. 50000,
  139893. 200000,
  139894. blocksize_short_44,
  139895. blocksize_long_44,
  139896. _psy_tone_masteratt_44,
  139897. _psy_tone_0dB,
  139898. _psy_tone_suppress,
  139899. _vp_tonemask_adj_otherblock,
  139900. _vp_tonemask_adj_longblock,
  139901. _vp_tonemask_adj_otherblock,
  139902. _psy_noiseguards_44,
  139903. _psy_noisebias_impulse,
  139904. _psy_noisebias_padding,
  139905. _psy_noisebias_trans,
  139906. _psy_noisebias_long,
  139907. _psy_noise_suppress,
  139908. _psy_compand_44,
  139909. _psy_compand_short_mapping,
  139910. _psy_compand_long_mapping,
  139911. {_noise_start_short_44,_noise_start_long_44},
  139912. {_noise_part_short_44,_noise_part_long_44},
  139913. _noise_thresh_44,
  139914. _psy_ath_floater,
  139915. _psy_ath_abs,
  139916. _psy_lowpass_44,
  139917. _psy_global_44,
  139918. _global_mapping_44,
  139919. NULL,
  139920. _floor_books,
  139921. _floor,
  139922. _floor_short_mapping_44,
  139923. _floor_long_mapping_44,
  139924. _mapres_template_44_uncoupled
  139925. };
  139926. ve_setup_data_template ve_setup_XX_stereo={
  139927. 2,
  139928. rate_mapping_X,
  139929. quality_mapping_8,
  139930. 2,
  139931. 0,
  139932. 8000,
  139933. blocksize_8,
  139934. blocksize_8,
  139935. _psy_tone_masteratt_8,
  139936. _psy_tone_0dB,
  139937. _psy_tone_suppress,
  139938. _vp_tonemask_adj_8,
  139939. NULL,
  139940. _vp_tonemask_adj_8,
  139941. _psy_noiseguards_8,
  139942. _psy_noisebias_8,
  139943. _psy_noisebias_8,
  139944. NULL,
  139945. NULL,
  139946. _psy_noise_suppress,
  139947. _psy_compand_8,
  139948. _psy_compand_8_mapping,
  139949. NULL,
  139950. {_noise_start_8,_noise_start_8},
  139951. {_noise_part_8,_noise_part_8},
  139952. _noise_thresh_5only,
  139953. _psy_ath_floater_8,
  139954. _psy_ath_abs_8,
  139955. _psy_lowpass_8,
  139956. _psy_global_44,
  139957. _global_mapping_8,
  139958. _psy_stereo_modes_8,
  139959. _floor_books,
  139960. _floor,
  139961. _floor_mapping_8,
  139962. NULL,
  139963. _mapres_template_8_stereo
  139964. };
  139965. ve_setup_data_template ve_setup_XX_uncoupled={
  139966. 2,
  139967. rate_mapping_X,
  139968. quality_mapping_8,
  139969. -1,
  139970. 0,
  139971. 8000,
  139972. blocksize_8,
  139973. blocksize_8,
  139974. _psy_tone_masteratt_8,
  139975. _psy_tone_0dB,
  139976. _psy_tone_suppress,
  139977. _vp_tonemask_adj_8,
  139978. NULL,
  139979. _vp_tonemask_adj_8,
  139980. _psy_noiseguards_8,
  139981. _psy_noisebias_8,
  139982. _psy_noisebias_8,
  139983. NULL,
  139984. NULL,
  139985. _psy_noise_suppress,
  139986. _psy_compand_8,
  139987. _psy_compand_8_mapping,
  139988. NULL,
  139989. {_noise_start_8,_noise_start_8},
  139990. {_noise_part_8,_noise_part_8},
  139991. _noise_thresh_5only,
  139992. _psy_ath_floater_8,
  139993. _psy_ath_abs_8,
  139994. _psy_lowpass_8,
  139995. _psy_global_44,
  139996. _global_mapping_8,
  139997. _psy_stereo_modes_8,
  139998. _floor_books,
  139999. _floor,
  140000. _floor_mapping_8,
  140001. NULL,
  140002. _mapres_template_8_uncoupled
  140003. };
  140004. /*** End of inlined file: setup_X.h ***/
  140005. static ve_setup_data_template *setup_list[]={
  140006. &ve_setup_44_stereo,
  140007. &ve_setup_44_uncoupled,
  140008. &ve_setup_32_stereo,
  140009. &ve_setup_32_uncoupled,
  140010. &ve_setup_22_stereo,
  140011. &ve_setup_22_uncoupled,
  140012. &ve_setup_16_stereo,
  140013. &ve_setup_16_uncoupled,
  140014. &ve_setup_11_stereo,
  140015. &ve_setup_11_uncoupled,
  140016. &ve_setup_8_stereo,
  140017. &ve_setup_8_uncoupled,
  140018. &ve_setup_X_stereo,
  140019. &ve_setup_X_uncoupled,
  140020. &ve_setup_XX_stereo,
  140021. &ve_setup_XX_uncoupled,
  140022. 0
  140023. };
  140024. static int vorbis_encode_toplevel_setup(vorbis_info *vi,int ch,long rate){
  140025. if(vi && vi->codec_setup){
  140026. vi->version=0;
  140027. vi->channels=ch;
  140028. vi->rate=rate;
  140029. return(0);
  140030. }
  140031. return(OV_EINVAL);
  140032. }
  140033. static void vorbis_encode_floor_setup(vorbis_info *vi,double s,int block,
  140034. static_codebook ***books,
  140035. vorbis_info_floor1 *in,
  140036. int *x){
  140037. int i,k,is=s;
  140038. vorbis_info_floor1 *f=(vorbis_info_floor1*) _ogg_calloc(1,sizeof(*f));
  140039. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140040. memcpy(f,in+x[is],sizeof(*f));
  140041. f->n=ci->blocksizes[block]>>1;
  140042. {
  140043. int partitions=f->partitions;
  140044. int maxclass=-1;
  140045. int maxbook=-1;
  140046. for(i=0;i<partitions;i++)
  140047. if(f->partitionclass[i]>maxclass)maxclass=f->partitionclass[i];
  140048. for(i=0;i<=maxclass;i++){
  140049. if(f->class_book[i]>maxbook)maxbook=f->class_book[i];
  140050. f->class_book[i]+=ci->books;
  140051. for(k=0;k<(1<<f->class_subs[i]);k++){
  140052. if(f->class_subbook[i][k]>maxbook)maxbook=f->class_subbook[i][k];
  140053. if(f->class_subbook[i][k]>=0)f->class_subbook[i][k]+=ci->books;
  140054. }
  140055. }
  140056. for(i=0;i<=maxbook;i++)
  140057. ci->book_param[ci->books++]=books[x[is]][i];
  140058. }
  140059. ci->floor_type[ci->floors]=1;
  140060. ci->floor_param[ci->floors]=f;
  140061. ci->floors++;
  140062. return;
  140063. }
  140064. static void vorbis_encode_global_psych_setup(vorbis_info *vi,double s,
  140065. vorbis_info_psy_global *in,
  140066. double *x){
  140067. int i,is=s;
  140068. double ds=s-is;
  140069. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140070. vorbis_info_psy_global *g=&ci->psy_g_param;
  140071. memcpy(g,in+(int)x[is],sizeof(*g));
  140072. ds=x[is]*(1.-ds)+x[is+1]*ds;
  140073. is=(int)ds;
  140074. ds-=is;
  140075. if(ds==0 && is>0){
  140076. is--;
  140077. ds=1.;
  140078. }
  140079. for(i=0;i<4;i++){
  140080. g->preecho_thresh[i]=in[is].preecho_thresh[i]*(1.-ds)+in[is+1].preecho_thresh[i]*ds;
  140081. g->postecho_thresh[i]=in[is].postecho_thresh[i]*(1.-ds)+in[is+1].postecho_thresh[i]*ds;
  140082. }
  140083. g->ampmax_att_per_sec=ci->hi.amplitude_track_dBpersec;
  140084. return;
  140085. }
  140086. static void vorbis_encode_global_stereo(vorbis_info *vi,
  140087. highlevel_encode_setup *hi,
  140088. adj_stereo *p){
  140089. float s=hi->stereo_point_setting;
  140090. int i,is=s;
  140091. double ds=s-is;
  140092. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140093. vorbis_info_psy_global *g=&ci->psy_g_param;
  140094. if(p){
  140095. memcpy(g->coupling_prepointamp,p[is].pre,sizeof(*p[is].pre)*PACKETBLOBS);
  140096. memcpy(g->coupling_postpointamp,p[is].post,sizeof(*p[is].post)*PACKETBLOBS);
  140097. if(hi->managed){
  140098. for(i=0;i<PACKETBLOBS;i++){
  140099. float kHz=p[is].kHz[i]*(1.-ds)+p[is+1].kHz[i]*ds;
  140100. g->coupling_pointlimit[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140101. g->coupling_pointlimit[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140102. g->coupling_pkHz[i]=kHz;
  140103. kHz=p[is].lowpasskHz[i]*(1.-ds)+p[is+1].lowpasskHz[i]*ds;
  140104. g->sliding_lowpass[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140105. g->sliding_lowpass[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140106. }
  140107. }else{
  140108. float kHz=p[is].kHz[PACKETBLOBS/2]*(1.-ds)+p[is+1].kHz[PACKETBLOBS/2]*ds;
  140109. for(i=0;i<PACKETBLOBS;i++){
  140110. g->coupling_pointlimit[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140111. g->coupling_pointlimit[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140112. g->coupling_pkHz[i]=kHz;
  140113. }
  140114. kHz=p[is].lowpasskHz[PACKETBLOBS/2]*(1.-ds)+p[is+1].lowpasskHz[PACKETBLOBS/2]*ds;
  140115. for(i=0;i<PACKETBLOBS;i++){
  140116. g->sliding_lowpass[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140117. g->sliding_lowpass[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140118. }
  140119. }
  140120. }else{
  140121. for(i=0;i<PACKETBLOBS;i++){
  140122. g->sliding_lowpass[0][i]=ci->blocksizes[0];
  140123. g->sliding_lowpass[1][i]=ci->blocksizes[1];
  140124. }
  140125. }
  140126. return;
  140127. }
  140128. static void vorbis_encode_psyset_setup(vorbis_info *vi,double s,
  140129. int *nn_start,
  140130. int *nn_partition,
  140131. double *nn_thresh,
  140132. int block){
  140133. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140134. vorbis_info_psy *p=ci->psy_param[block];
  140135. highlevel_encode_setup *hi=&ci->hi;
  140136. int is=s;
  140137. if(block>=ci->psys)
  140138. ci->psys=block+1;
  140139. if(!p){
  140140. p=(vorbis_info_psy*)_ogg_calloc(1,sizeof(*p));
  140141. ci->psy_param[block]=p;
  140142. }
  140143. memcpy(p,&_psy_info_template,sizeof(*p));
  140144. p->blockflag=block>>1;
  140145. if(hi->noise_normalize_p){
  140146. p->normal_channel_p=1;
  140147. p->normal_point_p=1;
  140148. p->normal_start=nn_start[is];
  140149. p->normal_partition=nn_partition[is];
  140150. p->normal_thresh=nn_thresh[is];
  140151. }
  140152. return;
  140153. }
  140154. static void vorbis_encode_tonemask_setup(vorbis_info *vi,double s,int block,
  140155. att3 *att,
  140156. int *max,
  140157. vp_adjblock *in){
  140158. int i,is=s;
  140159. double ds=s-is;
  140160. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140161. vorbis_info_psy *p=ci->psy_param[block];
  140162. p->tone_masteratt[0]=att[is].att[0]*(1.-ds)+att[is+1].att[0]*ds;
  140163. p->tone_masteratt[1]=att[is].att[1]*(1.-ds)+att[is+1].att[1]*ds;
  140164. p->tone_masteratt[2]=att[is].att[2]*(1.-ds)+att[is+1].att[2]*ds;
  140165. p->tone_centerboost=att[is].boost*(1.-ds)+att[is+1].boost*ds;
  140166. p->tone_decay=att[is].decay*(1.-ds)+att[is+1].decay*ds;
  140167. p->max_curve_dB=max[is]*(1.-ds)+max[is+1]*ds;
  140168. for(i=0;i<P_BANDS;i++)
  140169. p->toneatt[i]=in[is].block[i]*(1.-ds)+in[is+1].block[i]*ds;
  140170. return;
  140171. }
  140172. static void vorbis_encode_compand_setup(vorbis_info *vi,double s,int block,
  140173. compandblock *in, double *x){
  140174. int i,is=s;
  140175. double ds=s-is;
  140176. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140177. vorbis_info_psy *p=ci->psy_param[block];
  140178. ds=x[is]*(1.-ds)+x[is+1]*ds;
  140179. is=(int)ds;
  140180. ds-=is;
  140181. if(ds==0 && is>0){
  140182. is--;
  140183. ds=1.;
  140184. }
  140185. for(i=0;i<NOISE_COMPAND_LEVELS;i++)
  140186. p->noisecompand[i]=in[is].data[i]*(1.-ds)+in[is+1].data[i]*ds;
  140187. return;
  140188. }
  140189. static void vorbis_encode_peak_setup(vorbis_info *vi,double s,int block,
  140190. int *suppress){
  140191. int is=s;
  140192. double ds=s-is;
  140193. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140194. vorbis_info_psy *p=ci->psy_param[block];
  140195. p->tone_abs_limit=suppress[is]*(1.-ds)+suppress[is+1]*ds;
  140196. return;
  140197. }
  140198. static void vorbis_encode_noisebias_setup(vorbis_info *vi,double s,int block,
  140199. int *suppress,
  140200. noise3 *in,
  140201. noiseguard *guard,
  140202. double userbias){
  140203. int i,is=s,j;
  140204. double ds=s-is;
  140205. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140206. vorbis_info_psy *p=ci->psy_param[block];
  140207. p->noisemaxsupp=suppress[is]*(1.-ds)+suppress[is+1]*ds;
  140208. p->noisewindowlomin=guard[block].lo;
  140209. p->noisewindowhimin=guard[block].hi;
  140210. p->noisewindowfixed=guard[block].fixed;
  140211. for(j=0;j<P_NOISECURVES;j++)
  140212. for(i=0;i<P_BANDS;i++)
  140213. p->noiseoff[j][i]=in[is].data[j][i]*(1.-ds)+in[is+1].data[j][i]*ds;
  140214. for(j=0;j<P_NOISECURVES;j++){
  140215. float min=p->noiseoff[j][0]+6; /* the lowest it can go */
  140216. for(i=0;i<P_BANDS;i++){
  140217. p->noiseoff[j][i]+=userbias;
  140218. if(p->noiseoff[j][i]<min)p->noiseoff[j][i]=min;
  140219. }
  140220. }
  140221. return;
  140222. }
  140223. static void vorbis_encode_ath_setup(vorbis_info *vi,int block){
  140224. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140225. vorbis_info_psy *p=ci->psy_param[block];
  140226. p->ath_adjatt=ci->hi.ath_floating_dB;
  140227. p->ath_maxatt=ci->hi.ath_absolute_dB;
  140228. return;
  140229. }
  140230. static int book_dup_or_new(codec_setup_info *ci,static_codebook *book){
  140231. int i;
  140232. for(i=0;i<ci->books;i++)
  140233. if(ci->book_param[i]==book)return(i);
  140234. return(ci->books++);
  140235. }
  140236. static void vorbis_encode_blocksize_setup(vorbis_info *vi,double s,
  140237. int *shortb,int *longb){
  140238. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140239. int is=s;
  140240. int blockshort=shortb[is];
  140241. int blocklong=longb[is];
  140242. ci->blocksizes[0]=blockshort;
  140243. ci->blocksizes[1]=blocklong;
  140244. }
  140245. static void vorbis_encode_residue_setup(vorbis_info *vi,
  140246. int number, int block,
  140247. vorbis_residue_template *res){
  140248. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140249. int i,n;
  140250. vorbis_info_residue0 *r=(vorbis_info_residue0*)(ci->residue_param[number]=
  140251. (vorbis_info_residue0*)_ogg_malloc(sizeof(*r)));
  140252. memcpy(r,res->res,sizeof(*r));
  140253. if(ci->residues<=number)ci->residues=number+1;
  140254. switch(ci->blocksizes[block]){
  140255. case 64:case 128:case 256:
  140256. r->grouping=16;
  140257. break;
  140258. default:
  140259. r->grouping=32;
  140260. break;
  140261. }
  140262. ci->residue_type[number]=res->res_type;
  140263. n=r->end=ci->blocksizes[block]>>1;
  140264. if(res->res_type==2)
  140265. n=r->end*=vi->channels;
  140266. {
  140267. int booklist=0,k;
  140268. if(ci->hi.managed){
  140269. for(i=0;i<r->partitions;i++)
  140270. for(k=0;k<3;k++)
  140271. if(res->books_base_managed->books[i][k])
  140272. r->secondstages[i]|=(1<<k);
  140273. r->groupbook=book_dup_or_new(ci,res->book_aux_managed);
  140274. ci->book_param[r->groupbook]=res->book_aux_managed;
  140275. for(i=0;i<r->partitions;i++){
  140276. for(k=0;k<3;k++){
  140277. if(res->books_base_managed->books[i][k]){
  140278. int bookid=book_dup_or_new(ci,res->books_base_managed->books[i][k]);
  140279. r->booklist[booklist++]=bookid;
  140280. ci->book_param[bookid]=res->books_base_managed->books[i][k];
  140281. }
  140282. }
  140283. }
  140284. }else{
  140285. for(i=0;i<r->partitions;i++)
  140286. for(k=0;k<3;k++)
  140287. if(res->books_base->books[i][k])
  140288. r->secondstages[i]|=(1<<k);
  140289. r->groupbook=book_dup_or_new(ci,res->book_aux);
  140290. ci->book_param[r->groupbook]=res->book_aux;
  140291. for(i=0;i<r->partitions;i++){
  140292. for(k=0;k<3;k++){
  140293. if(res->books_base->books[i][k]){
  140294. int bookid=book_dup_or_new(ci,res->books_base->books[i][k]);
  140295. r->booklist[booklist++]=bookid;
  140296. ci->book_param[bookid]=res->books_base->books[i][k];
  140297. }
  140298. }
  140299. }
  140300. }
  140301. }
  140302. {
  140303. double freq=ci->hi.lowpass_kHz*1000.;
  140304. vorbis_info_floor1 *f=(vorbis_info_floor1*)ci->floor_param[block]; /* by convention */
  140305. double nyq=vi->rate/2.;
  140306. long blocksize=ci->blocksizes[block]>>1;
  140307. if(freq>nyq)freq=nyq;
  140308. f->n=freq/nyq*blocksize;
  140309. if(res->limit_type){
  140310. if(ci->hi.managed)
  140311. freq=ci->psy_g_param.coupling_pkHz[PACKETBLOBS-1]*1000.;
  140312. else
  140313. freq=ci->psy_g_param.coupling_pkHz[PACKETBLOBS/2]*1000.;
  140314. if(freq>nyq)freq=nyq;
  140315. }
  140316. if(ci->residue_type[block]==2)
  140317. r->end=(int)((freq/nyq*blocksize*2)/r->grouping+.9)* /* round up only if we're well past */
  140318. r->grouping;
  140319. else
  140320. r->end=(int)((freq/nyq*blocksize)/r->grouping+.9)* /* round up only if we're well past */
  140321. r->grouping;
  140322. }
  140323. }
  140324. static void vorbis_encode_map_n_res_setup(vorbis_info *vi,double s,
  140325. vorbis_mapping_template *maps){
  140326. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140327. int i,j,is=s,modes=2;
  140328. vorbis_info_mapping0 *map=maps[is].map;
  140329. vorbis_info_mode *mode=_mode_template;
  140330. vorbis_residue_template *res=maps[is].res;
  140331. if(ci->blocksizes[0]==ci->blocksizes[1])modes=1;
  140332. for(i=0;i<modes;i++){
  140333. ci->map_param[i]=_ogg_calloc(1,sizeof(*map));
  140334. ci->mode_param[i]=(vorbis_info_mode*)_ogg_calloc(1,sizeof(*mode));
  140335. memcpy(ci->mode_param[i],mode+i,sizeof(*_mode_template));
  140336. if(i>=ci->modes)ci->modes=i+1;
  140337. ci->map_type[i]=0;
  140338. memcpy(ci->map_param[i],map+i,sizeof(*map));
  140339. if(i>=ci->maps)ci->maps=i+1;
  140340. for(j=0;j<map[i].submaps;j++)
  140341. vorbis_encode_residue_setup(vi,map[i].residuesubmap[j],i
  140342. ,res+map[i].residuesubmap[j]);
  140343. }
  140344. }
  140345. static double setting_to_approx_bitrate(vorbis_info *vi){
  140346. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140347. highlevel_encode_setup *hi=&ci->hi;
  140348. ve_setup_data_template *setup=(ve_setup_data_template *)hi->setup;
  140349. int is=hi->base_setting;
  140350. double ds=hi->base_setting-is;
  140351. int ch=vi->channels;
  140352. double *r=setup->rate_mapping;
  140353. if(r==NULL)
  140354. return(-1);
  140355. return((r[is]*(1.-ds)+r[is+1]*ds)*ch);
  140356. }
  140357. static void get_setup_template(vorbis_info *vi,
  140358. long ch,long srate,
  140359. double req,int q_or_bitrate){
  140360. int i=0,j;
  140361. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140362. highlevel_encode_setup *hi=&ci->hi;
  140363. if(q_or_bitrate)req/=ch;
  140364. while(setup_list[i]){
  140365. if(setup_list[i]->coupling_restriction==-1 ||
  140366. setup_list[i]->coupling_restriction==ch){
  140367. if(srate>=setup_list[i]->samplerate_min_restriction &&
  140368. srate<=setup_list[i]->samplerate_max_restriction){
  140369. int mappings=setup_list[i]->mappings;
  140370. double *map=(q_or_bitrate?
  140371. setup_list[i]->rate_mapping:
  140372. setup_list[i]->quality_mapping);
  140373. if(req<map[0]){++i;continue;}
  140374. if(req>map[setup_list[i]->mappings]){++i;continue;}
  140375. for(j=0;j<mappings;j++)
  140376. if(req>=map[j] && req<map[j+1])break;
  140377. hi->setup=setup_list[i];
  140378. if(j==mappings)
  140379. hi->base_setting=j-.001;
  140380. else{
  140381. float low=map[j];
  140382. float high=map[j+1];
  140383. float del=(req-low)/(high-low);
  140384. hi->base_setting=j+del;
  140385. }
  140386. return;
  140387. }
  140388. }
  140389. i++;
  140390. }
  140391. hi->setup=NULL;
  140392. }
  140393. int vorbis_encode_setup_init(vorbis_info *vi){
  140394. int i0=0,singleblock=0;
  140395. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140396. ve_setup_data_template *setup=NULL;
  140397. highlevel_encode_setup *hi=&ci->hi;
  140398. if(ci==NULL)return(OV_EINVAL);
  140399. if(!hi->impulse_block_p)i0=1;
  140400. if(hi->ath_floating_dB>-80)hi->ath_floating_dB=-80;
  140401. if(hi->ath_floating_dB<-200)hi->ath_floating_dB=-200;
  140402. if(hi->amplitude_track_dBpersec>0.)hi->amplitude_track_dBpersec=0.;
  140403. if(hi->amplitude_track_dBpersec<-99999.)hi->amplitude_track_dBpersec=-99999.;
  140404. setup=(ve_setup_data_template *)hi->setup;
  140405. if(setup==NULL)return(OV_EINVAL);
  140406. hi->set_in_stone=1;
  140407. vorbis_encode_blocksize_setup(vi,hi->base_setting,
  140408. setup->blocksize_short,
  140409. setup->blocksize_long);
  140410. if(ci->blocksizes[0]==ci->blocksizes[1])singleblock=1;
  140411. vorbis_encode_floor_setup(vi,hi->short_setting,0,
  140412. setup->floor_books,
  140413. setup->floor_params,
  140414. setup->floor_short_mapping);
  140415. if(!singleblock)
  140416. vorbis_encode_floor_setup(vi,hi->long_setting,1,
  140417. setup->floor_books,
  140418. setup->floor_params,
  140419. setup->floor_long_mapping);
  140420. vorbis_encode_global_psych_setup(vi,hi->trigger_setting,
  140421. setup->global_params,
  140422. setup->global_mapping);
  140423. vorbis_encode_global_stereo(vi,hi,setup->stereo_modes);
  140424. vorbis_encode_psyset_setup(vi,hi->short_setting,
  140425. setup->psy_noise_normal_start[0],
  140426. setup->psy_noise_normal_partition[0],
  140427. setup->psy_noise_normal_thresh,
  140428. 0);
  140429. vorbis_encode_psyset_setup(vi,hi->short_setting,
  140430. setup->psy_noise_normal_start[0],
  140431. setup->psy_noise_normal_partition[0],
  140432. setup->psy_noise_normal_thresh,
  140433. 1);
  140434. if(!singleblock){
  140435. vorbis_encode_psyset_setup(vi,hi->long_setting,
  140436. setup->psy_noise_normal_start[1],
  140437. setup->psy_noise_normal_partition[1],
  140438. setup->psy_noise_normal_thresh,
  140439. 2);
  140440. vorbis_encode_psyset_setup(vi,hi->long_setting,
  140441. setup->psy_noise_normal_start[1],
  140442. setup->psy_noise_normal_partition[1],
  140443. setup->psy_noise_normal_thresh,
  140444. 3);
  140445. }
  140446. vorbis_encode_tonemask_setup(vi,hi->block[i0].tone_mask_setting,0,
  140447. setup->psy_tone_masteratt,
  140448. setup->psy_tone_0dB,
  140449. setup->psy_tone_adj_impulse);
  140450. vorbis_encode_tonemask_setup(vi,hi->block[1].tone_mask_setting,1,
  140451. setup->psy_tone_masteratt,
  140452. setup->psy_tone_0dB,
  140453. setup->psy_tone_adj_other);
  140454. if(!singleblock){
  140455. vorbis_encode_tonemask_setup(vi,hi->block[2].tone_mask_setting,2,
  140456. setup->psy_tone_masteratt,
  140457. setup->psy_tone_0dB,
  140458. setup->psy_tone_adj_other);
  140459. vorbis_encode_tonemask_setup(vi,hi->block[3].tone_mask_setting,3,
  140460. setup->psy_tone_masteratt,
  140461. setup->psy_tone_0dB,
  140462. setup->psy_tone_adj_long);
  140463. }
  140464. vorbis_encode_compand_setup(vi,hi->block[i0].noise_compand_setting,0,
  140465. setup->psy_noise_compand,
  140466. setup->psy_noise_compand_short_mapping);
  140467. vorbis_encode_compand_setup(vi,hi->block[1].noise_compand_setting,1,
  140468. setup->psy_noise_compand,
  140469. setup->psy_noise_compand_short_mapping);
  140470. if(!singleblock){
  140471. vorbis_encode_compand_setup(vi,hi->block[2].noise_compand_setting,2,
  140472. setup->psy_noise_compand,
  140473. setup->psy_noise_compand_long_mapping);
  140474. vorbis_encode_compand_setup(vi,hi->block[3].noise_compand_setting,3,
  140475. setup->psy_noise_compand,
  140476. setup->psy_noise_compand_long_mapping);
  140477. }
  140478. vorbis_encode_peak_setup(vi,hi->block[i0].tone_peaklimit_setting,0,
  140479. setup->psy_tone_dBsuppress);
  140480. vorbis_encode_peak_setup(vi,hi->block[1].tone_peaklimit_setting,1,
  140481. setup->psy_tone_dBsuppress);
  140482. if(!singleblock){
  140483. vorbis_encode_peak_setup(vi,hi->block[2].tone_peaklimit_setting,2,
  140484. setup->psy_tone_dBsuppress);
  140485. vorbis_encode_peak_setup(vi,hi->block[3].tone_peaklimit_setting,3,
  140486. setup->psy_tone_dBsuppress);
  140487. }
  140488. vorbis_encode_noisebias_setup(vi,hi->block[i0].noise_bias_setting,0,
  140489. setup->psy_noise_dBsuppress,
  140490. setup->psy_noise_bias_impulse,
  140491. setup->psy_noiseguards,
  140492. (i0==0?hi->impulse_noisetune:0.));
  140493. vorbis_encode_noisebias_setup(vi,hi->block[1].noise_bias_setting,1,
  140494. setup->psy_noise_dBsuppress,
  140495. setup->psy_noise_bias_padding,
  140496. setup->psy_noiseguards,0.);
  140497. if(!singleblock){
  140498. vorbis_encode_noisebias_setup(vi,hi->block[2].noise_bias_setting,2,
  140499. setup->psy_noise_dBsuppress,
  140500. setup->psy_noise_bias_trans,
  140501. setup->psy_noiseguards,0.);
  140502. vorbis_encode_noisebias_setup(vi,hi->block[3].noise_bias_setting,3,
  140503. setup->psy_noise_dBsuppress,
  140504. setup->psy_noise_bias_long,
  140505. setup->psy_noiseguards,0.);
  140506. }
  140507. vorbis_encode_ath_setup(vi,0);
  140508. vorbis_encode_ath_setup(vi,1);
  140509. if(!singleblock){
  140510. vorbis_encode_ath_setup(vi,2);
  140511. vorbis_encode_ath_setup(vi,3);
  140512. }
  140513. vorbis_encode_map_n_res_setup(vi,hi->base_setting,setup->maps);
  140514. if(hi->bitrate_av>0)
  140515. vi->bitrate_nominal=hi->bitrate_av;
  140516. else{
  140517. vi->bitrate_nominal=setting_to_approx_bitrate(vi);
  140518. }
  140519. vi->bitrate_lower=hi->bitrate_min;
  140520. vi->bitrate_upper=hi->bitrate_max;
  140521. if(hi->bitrate_av)
  140522. vi->bitrate_window=(double)hi->bitrate_reservoir/hi->bitrate_av;
  140523. else
  140524. vi->bitrate_window=0.;
  140525. if(hi->managed){
  140526. ci->bi.avg_rate=hi->bitrate_av;
  140527. ci->bi.min_rate=hi->bitrate_min;
  140528. ci->bi.max_rate=hi->bitrate_max;
  140529. ci->bi.reservoir_bits=hi->bitrate_reservoir;
  140530. ci->bi.reservoir_bias=
  140531. hi->bitrate_reservoir_bias;
  140532. ci->bi.slew_damp=hi->bitrate_av_damp;
  140533. }
  140534. return(0);
  140535. }
  140536. static int vorbis_encode_setup_setting(vorbis_info *vi,
  140537. long channels,
  140538. long rate){
  140539. int ret=0,i,is;
  140540. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140541. highlevel_encode_setup *hi=&ci->hi;
  140542. ve_setup_data_template *setup=(ve_setup_data_template*) hi->setup;
  140543. double ds;
  140544. ret=vorbis_encode_toplevel_setup(vi,channels,rate);
  140545. if(ret)return(ret);
  140546. is=hi->base_setting;
  140547. ds=hi->base_setting-is;
  140548. hi->short_setting=hi->base_setting;
  140549. hi->long_setting=hi->base_setting;
  140550. hi->managed=0;
  140551. hi->impulse_block_p=1;
  140552. hi->noise_normalize_p=1;
  140553. hi->stereo_point_setting=hi->base_setting;
  140554. hi->lowpass_kHz=
  140555. setup->psy_lowpass[is]*(1.-ds)+setup->psy_lowpass[is+1]*ds;
  140556. hi->ath_floating_dB=setup->psy_ath_float[is]*(1.-ds)+
  140557. setup->psy_ath_float[is+1]*ds;
  140558. hi->ath_absolute_dB=setup->psy_ath_abs[is]*(1.-ds)+
  140559. setup->psy_ath_abs[is+1]*ds;
  140560. hi->amplitude_track_dBpersec=-6.;
  140561. hi->trigger_setting=hi->base_setting;
  140562. for(i=0;i<4;i++){
  140563. hi->block[i].tone_mask_setting=hi->base_setting;
  140564. hi->block[i].tone_peaklimit_setting=hi->base_setting;
  140565. hi->block[i].noise_bias_setting=hi->base_setting;
  140566. hi->block[i].noise_compand_setting=hi->base_setting;
  140567. }
  140568. return(ret);
  140569. }
  140570. int vorbis_encode_setup_vbr(vorbis_info *vi,
  140571. long channels,
  140572. long rate,
  140573. float quality){
  140574. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140575. highlevel_encode_setup *hi=&ci->hi;
  140576. quality+=.0000001;
  140577. if(quality>=1.)quality=.9999;
  140578. get_setup_template(vi,channels,rate,quality,0);
  140579. if(!hi->setup)return OV_EIMPL;
  140580. return vorbis_encode_setup_setting(vi,channels,rate);
  140581. }
  140582. int vorbis_encode_init_vbr(vorbis_info *vi,
  140583. long channels,
  140584. long rate,
  140585. float base_quality /* 0. to 1. */
  140586. ){
  140587. int ret=0;
  140588. ret=vorbis_encode_setup_vbr(vi,channels,rate,base_quality);
  140589. if(ret){
  140590. vorbis_info_clear(vi);
  140591. return ret;
  140592. }
  140593. ret=vorbis_encode_setup_init(vi);
  140594. if(ret)
  140595. vorbis_info_clear(vi);
  140596. return(ret);
  140597. }
  140598. int vorbis_encode_setup_managed(vorbis_info *vi,
  140599. long channels,
  140600. long rate,
  140601. long max_bitrate,
  140602. long nominal_bitrate,
  140603. long min_bitrate){
  140604. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140605. highlevel_encode_setup *hi=&ci->hi;
  140606. double tnominal=nominal_bitrate;
  140607. int ret=0;
  140608. if(nominal_bitrate<=0.){
  140609. if(max_bitrate>0.){
  140610. if(min_bitrate>0.)
  140611. nominal_bitrate=(max_bitrate+min_bitrate)*.5;
  140612. else
  140613. nominal_bitrate=max_bitrate*.875;
  140614. }else{
  140615. if(min_bitrate>0.){
  140616. nominal_bitrate=min_bitrate;
  140617. }else{
  140618. return(OV_EINVAL);
  140619. }
  140620. }
  140621. }
  140622. get_setup_template(vi,channels,rate,nominal_bitrate,1);
  140623. if(!hi->setup)return OV_EIMPL;
  140624. ret=vorbis_encode_setup_setting(vi,channels,rate);
  140625. if(ret){
  140626. vorbis_info_clear(vi);
  140627. return ret;
  140628. }
  140629. hi->managed=1;
  140630. hi->bitrate_min=min_bitrate;
  140631. hi->bitrate_max=max_bitrate;
  140632. hi->bitrate_av=tnominal;
  140633. hi->bitrate_av_damp=1.5f; /* full range in no less than 1.5 second */
  140634. hi->bitrate_reservoir=nominal_bitrate*2;
  140635. hi->bitrate_reservoir_bias=.1; /* bias toward hoarding bits */
  140636. return(ret);
  140637. }
  140638. int vorbis_encode_init(vorbis_info *vi,
  140639. long channels,
  140640. long rate,
  140641. long max_bitrate,
  140642. long nominal_bitrate,
  140643. long min_bitrate){
  140644. int ret=vorbis_encode_setup_managed(vi,channels,rate,
  140645. max_bitrate,
  140646. nominal_bitrate,
  140647. min_bitrate);
  140648. if(ret){
  140649. vorbis_info_clear(vi);
  140650. return(ret);
  140651. }
  140652. ret=vorbis_encode_setup_init(vi);
  140653. if(ret)
  140654. vorbis_info_clear(vi);
  140655. return(ret);
  140656. }
  140657. int vorbis_encode_ctl(vorbis_info *vi,int number,void *arg){
  140658. if(vi){
  140659. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140660. highlevel_encode_setup *hi=&ci->hi;
  140661. int setp=(number&0xf); /* a read request has a low nibble of 0 */
  140662. if(setp && hi->set_in_stone)return(OV_EINVAL);
  140663. switch(number){
  140664. case OV_ECTL_RATEMANAGE_GET:
  140665. {
  140666. struct ovectl_ratemanage_arg *ai=
  140667. (struct ovectl_ratemanage_arg *)arg;
  140668. ai->management_active=hi->managed;
  140669. ai->bitrate_hard_window=ai->bitrate_av_window=
  140670. (double)hi->bitrate_reservoir/vi->rate;
  140671. ai->bitrate_av_window_center=1.;
  140672. ai->bitrate_hard_min=hi->bitrate_min;
  140673. ai->bitrate_hard_max=hi->bitrate_max;
  140674. ai->bitrate_av_lo=hi->bitrate_av;
  140675. ai->bitrate_av_hi=hi->bitrate_av;
  140676. }
  140677. return(0);
  140678. case OV_ECTL_RATEMANAGE_SET:
  140679. {
  140680. struct ovectl_ratemanage_arg *ai=
  140681. (struct ovectl_ratemanage_arg *)arg;
  140682. if(ai==NULL){
  140683. hi->managed=0;
  140684. }else{
  140685. hi->managed=ai->management_active;
  140686. vorbis_encode_ctl(vi,OV_ECTL_RATEMANAGE_AVG,arg);
  140687. vorbis_encode_ctl(vi,OV_ECTL_RATEMANAGE_HARD,arg);
  140688. }
  140689. }
  140690. return 0;
  140691. case OV_ECTL_RATEMANAGE_AVG:
  140692. {
  140693. struct ovectl_ratemanage_arg *ai=
  140694. (struct ovectl_ratemanage_arg *)arg;
  140695. if(ai==NULL){
  140696. hi->bitrate_av=0;
  140697. }else{
  140698. hi->bitrate_av=(ai->bitrate_av_lo+ai->bitrate_av_hi)*.5;
  140699. }
  140700. }
  140701. return(0);
  140702. case OV_ECTL_RATEMANAGE_HARD:
  140703. {
  140704. struct ovectl_ratemanage_arg *ai=
  140705. (struct ovectl_ratemanage_arg *)arg;
  140706. if(ai==NULL){
  140707. hi->bitrate_min=0;
  140708. hi->bitrate_max=0;
  140709. }else{
  140710. hi->bitrate_min=ai->bitrate_hard_min;
  140711. hi->bitrate_max=ai->bitrate_hard_max;
  140712. hi->bitrate_reservoir=ai->bitrate_hard_window*
  140713. (hi->bitrate_max+hi->bitrate_min)*.5;
  140714. }
  140715. if(hi->bitrate_reservoir<128.)
  140716. hi->bitrate_reservoir=128.;
  140717. }
  140718. return(0);
  140719. case OV_ECTL_RATEMANAGE2_GET:
  140720. {
  140721. struct ovectl_ratemanage2_arg *ai=
  140722. (struct ovectl_ratemanage2_arg *)arg;
  140723. if(ai==NULL)return OV_EINVAL;
  140724. ai->management_active=hi->managed;
  140725. ai->bitrate_limit_min_kbps=hi->bitrate_min/1000;
  140726. ai->bitrate_limit_max_kbps=hi->bitrate_max/1000;
  140727. ai->bitrate_average_kbps=hi->bitrate_av/1000;
  140728. ai->bitrate_average_damping=hi->bitrate_av_damp;
  140729. ai->bitrate_limit_reservoir_bits=hi->bitrate_reservoir;
  140730. ai->bitrate_limit_reservoir_bias=hi->bitrate_reservoir_bias;
  140731. }
  140732. return (0);
  140733. case OV_ECTL_RATEMANAGE2_SET:
  140734. {
  140735. struct ovectl_ratemanage2_arg *ai=
  140736. (struct ovectl_ratemanage2_arg *)arg;
  140737. if(ai==NULL){
  140738. hi->managed=0;
  140739. }else{
  140740. if(ai->bitrate_limit_min_kbps>0 &&
  140741. ai->bitrate_average_kbps>0 &&
  140742. ai->bitrate_limit_min_kbps>ai->bitrate_average_kbps)
  140743. return OV_EINVAL;
  140744. if(ai->bitrate_limit_max_kbps>0 &&
  140745. ai->bitrate_average_kbps>0 &&
  140746. ai->bitrate_limit_max_kbps<ai->bitrate_average_kbps)
  140747. return OV_EINVAL;
  140748. if(ai->bitrate_limit_min_kbps>0 &&
  140749. ai->bitrate_limit_max_kbps>0 &&
  140750. ai->bitrate_limit_min_kbps>ai->bitrate_limit_max_kbps)
  140751. return OV_EINVAL;
  140752. if(ai->bitrate_average_damping <= 0.)
  140753. return OV_EINVAL;
  140754. if(ai->bitrate_limit_reservoir_bits < 0)
  140755. return OV_EINVAL;
  140756. if(ai->bitrate_limit_reservoir_bias < 0.)
  140757. return OV_EINVAL;
  140758. if(ai->bitrate_limit_reservoir_bias > 1.)
  140759. return OV_EINVAL;
  140760. hi->managed=ai->management_active;
  140761. hi->bitrate_min=ai->bitrate_limit_min_kbps * 1000;
  140762. hi->bitrate_max=ai->bitrate_limit_max_kbps * 1000;
  140763. hi->bitrate_av=ai->bitrate_average_kbps * 1000;
  140764. hi->bitrate_av_damp=ai->bitrate_average_damping;
  140765. hi->bitrate_reservoir=ai->bitrate_limit_reservoir_bits;
  140766. hi->bitrate_reservoir_bias=ai->bitrate_limit_reservoir_bias;
  140767. }
  140768. }
  140769. return 0;
  140770. case OV_ECTL_LOWPASS_GET:
  140771. {
  140772. double *farg=(double *)arg;
  140773. *farg=hi->lowpass_kHz;
  140774. }
  140775. return(0);
  140776. case OV_ECTL_LOWPASS_SET:
  140777. {
  140778. double *farg=(double *)arg;
  140779. hi->lowpass_kHz=*farg;
  140780. if(hi->lowpass_kHz<2.)hi->lowpass_kHz=2.;
  140781. if(hi->lowpass_kHz>99.)hi->lowpass_kHz=99.;
  140782. }
  140783. return(0);
  140784. case OV_ECTL_IBLOCK_GET:
  140785. {
  140786. double *farg=(double *)arg;
  140787. *farg=hi->impulse_noisetune;
  140788. }
  140789. return(0);
  140790. case OV_ECTL_IBLOCK_SET:
  140791. {
  140792. double *farg=(double *)arg;
  140793. hi->impulse_noisetune=*farg;
  140794. if(hi->impulse_noisetune>0.)hi->impulse_noisetune=0.;
  140795. if(hi->impulse_noisetune<-15.)hi->impulse_noisetune=-15.;
  140796. }
  140797. return(0);
  140798. }
  140799. return(OV_EIMPL);
  140800. }
  140801. return(OV_EINVAL);
  140802. }
  140803. #endif
  140804. /*** End of inlined file: vorbisenc.c ***/
  140805. /*** Start of inlined file: vorbisfile.c ***/
  140806. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  140807. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  140808. // tasks..
  140809. #if JUCE_MSVC
  140810. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  140811. #endif
  140812. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  140813. #if JUCE_USE_OGGVORBIS
  140814. #include <stdlib.h>
  140815. #include <stdio.h>
  140816. #include <errno.h>
  140817. #include <string.h>
  140818. #include <math.h>
  140819. #define CHUNKSIZE 8500 /* a shade over 8k; anyone using pages well
  140820. over 8k gets what they deserve */
  140821. static long _get_data(OggVorbis_File *vf){
  140822. errno=0;
  140823. if(vf->datasource){
  140824. char *buffer=ogg_sync_buffer(&vf->oy,CHUNKSIZE);
  140825. long bytes=(vf->callbacks.read_func)(buffer,1,CHUNKSIZE,vf->datasource);
  140826. if(bytes>0)ogg_sync_wrote(&vf->oy,bytes);
  140827. if(bytes==0 && errno)return(-1);
  140828. return(bytes);
  140829. }else
  140830. return(0);
  140831. }
  140832. static void _seek_helper(OggVorbis_File *vf,ogg_int64_t offset){
  140833. if(vf->datasource){
  140834. (vf->callbacks.seek_func)(vf->datasource, offset, SEEK_SET);
  140835. vf->offset=offset;
  140836. ogg_sync_reset(&vf->oy);
  140837. }else{
  140838. return;
  140839. }
  140840. }
  140841. static ogg_int64_t _get_next_page(OggVorbis_File *vf,ogg_page *og,
  140842. ogg_int64_t boundary){
  140843. if(boundary>0)boundary+=vf->offset;
  140844. while(1){
  140845. long more;
  140846. if(boundary>0 && vf->offset>=boundary)return(OV_FALSE);
  140847. more=ogg_sync_pageseek(&vf->oy,og);
  140848. if(more<0){
  140849. vf->offset-=more;
  140850. }else{
  140851. if(more==0){
  140852. if(!boundary)return(OV_FALSE);
  140853. {
  140854. long ret=_get_data(vf);
  140855. if(ret==0)return(OV_EOF);
  140856. if(ret<0)return(OV_EREAD);
  140857. }
  140858. }else{
  140859. ogg_int64_t ret=vf->offset;
  140860. vf->offset+=more;
  140861. return(ret);
  140862. }
  140863. }
  140864. }
  140865. }
  140866. static ogg_int64_t _get_prev_page(OggVorbis_File *vf,ogg_page *og){
  140867. ogg_int64_t begin=vf->offset;
  140868. ogg_int64_t end=begin;
  140869. ogg_int64_t ret;
  140870. ogg_int64_t offset=-1;
  140871. while(offset==-1){
  140872. begin-=CHUNKSIZE;
  140873. if(begin<0)
  140874. begin=0;
  140875. _seek_helper(vf,begin);
  140876. while(vf->offset<end){
  140877. ret=_get_next_page(vf,og,end-vf->offset);
  140878. if(ret==OV_EREAD)return(OV_EREAD);
  140879. if(ret<0){
  140880. break;
  140881. }else{
  140882. offset=ret;
  140883. }
  140884. }
  140885. }
  140886. _seek_helper(vf,offset);
  140887. ret=_get_next_page(vf,og,CHUNKSIZE);
  140888. if(ret<0)
  140889. return(OV_EFAULT);
  140890. return(offset);
  140891. }
  140892. static int _bisect_forward_serialno(OggVorbis_File *vf,
  140893. ogg_int64_t begin,
  140894. ogg_int64_t searched,
  140895. ogg_int64_t end,
  140896. long currentno,
  140897. long m){
  140898. ogg_int64_t endsearched=end;
  140899. ogg_int64_t next=end;
  140900. ogg_page og;
  140901. ogg_int64_t ret;
  140902. while(searched<endsearched){
  140903. ogg_int64_t bisect;
  140904. if(endsearched-searched<CHUNKSIZE){
  140905. bisect=searched;
  140906. }else{
  140907. bisect=(searched+endsearched)/2;
  140908. }
  140909. _seek_helper(vf,bisect);
  140910. ret=_get_next_page(vf,&og,-1);
  140911. if(ret==OV_EREAD)return(OV_EREAD);
  140912. if(ret<0 || ogg_page_serialno(&og)!=currentno){
  140913. endsearched=bisect;
  140914. if(ret>=0)next=ret;
  140915. }else{
  140916. searched=ret+og.header_len+og.body_len;
  140917. }
  140918. }
  140919. _seek_helper(vf,next);
  140920. ret=_get_next_page(vf,&og,-1);
  140921. if(ret==OV_EREAD)return(OV_EREAD);
  140922. if(searched>=end || ret<0){
  140923. vf->links=m+1;
  140924. vf->offsets=(ogg_int64_t*)_ogg_malloc((vf->links+1)*sizeof(*vf->offsets));
  140925. vf->serialnos=(long*)_ogg_malloc(vf->links*sizeof(*vf->serialnos));
  140926. vf->offsets[m+1]=searched;
  140927. }else{
  140928. ret=_bisect_forward_serialno(vf,next,vf->offset,
  140929. end,ogg_page_serialno(&og),m+1);
  140930. if(ret==OV_EREAD)return(OV_EREAD);
  140931. }
  140932. vf->offsets[m]=begin;
  140933. vf->serialnos[m]=currentno;
  140934. return(0);
  140935. }
  140936. static int _fetch_headers(OggVorbis_File *vf,vorbis_info *vi,vorbis_comment *vc,
  140937. long *serialno,ogg_page *og_ptr){
  140938. ogg_page og;
  140939. ogg_packet op;
  140940. int i,ret;
  140941. if(!og_ptr){
  140942. ogg_int64_t llret=_get_next_page(vf,&og,CHUNKSIZE);
  140943. if(llret==OV_EREAD)return(OV_EREAD);
  140944. if(llret<0)return OV_ENOTVORBIS;
  140945. og_ptr=&og;
  140946. }
  140947. ogg_stream_reset_serialno(&vf->os,ogg_page_serialno(og_ptr));
  140948. if(serialno)*serialno=vf->os.serialno;
  140949. vf->ready_state=STREAMSET;
  140950. vorbis_info_init(vi);
  140951. vorbis_comment_init(vc);
  140952. i=0;
  140953. while(i<3){
  140954. ogg_stream_pagein(&vf->os,og_ptr);
  140955. while(i<3){
  140956. int result=ogg_stream_packetout(&vf->os,&op);
  140957. if(result==0)break;
  140958. if(result==-1){
  140959. ret=OV_EBADHEADER;
  140960. goto bail_header;
  140961. }
  140962. if((ret=vorbis_synthesis_headerin(vi,vc,&op))){
  140963. goto bail_header;
  140964. }
  140965. i++;
  140966. }
  140967. if(i<3)
  140968. if(_get_next_page(vf,og_ptr,CHUNKSIZE)<0){
  140969. ret=OV_EBADHEADER;
  140970. goto bail_header;
  140971. }
  140972. }
  140973. return 0;
  140974. bail_header:
  140975. vorbis_info_clear(vi);
  140976. vorbis_comment_clear(vc);
  140977. vf->ready_state=OPENED;
  140978. return ret;
  140979. }
  140980. static void _prefetch_all_headers(OggVorbis_File *vf, ogg_int64_t dataoffset){
  140981. ogg_page og;
  140982. int i;
  140983. ogg_int64_t ret;
  140984. vf->vi=(vorbis_info*) _ogg_realloc(vf->vi,vf->links*sizeof(*vf->vi));
  140985. vf->vc=(vorbis_comment*) _ogg_realloc(vf->vc,vf->links*sizeof(*vf->vc));
  140986. vf->dataoffsets=(ogg_int64_t*) _ogg_malloc(vf->links*sizeof(*vf->dataoffsets));
  140987. vf->pcmlengths=(ogg_int64_t*) _ogg_malloc(vf->links*2*sizeof(*vf->pcmlengths));
  140988. for(i=0;i<vf->links;i++){
  140989. if(i==0){
  140990. vf->dataoffsets[i]=dataoffset;
  140991. _seek_helper(vf,dataoffset);
  140992. }else{
  140993. _seek_helper(vf,vf->offsets[i]);
  140994. if(_fetch_headers(vf,vf->vi+i,vf->vc+i,NULL,NULL)<0){
  140995. vf->dataoffsets[i]=-1;
  140996. }else{
  140997. vf->dataoffsets[i]=vf->offset;
  140998. }
  140999. }
  141000. if(vf->dataoffsets[i]!=-1){
  141001. ogg_int64_t accumulated=0;
  141002. long lastblock=-1;
  141003. int result;
  141004. ogg_stream_reset_serialno(&vf->os,vf->serialnos[i]);
  141005. while(1){
  141006. ogg_packet op;
  141007. ret=_get_next_page(vf,&og,-1);
  141008. if(ret<0)
  141009. break;
  141010. if(ogg_page_serialno(&og)!=vf->serialnos[i])
  141011. break;
  141012. ogg_stream_pagein(&vf->os,&og);
  141013. while((result=ogg_stream_packetout(&vf->os,&op))){
  141014. if(result>0){ /* ignore holes */
  141015. long thisblock=vorbis_packet_blocksize(vf->vi+i,&op);
  141016. if(lastblock!=-1)
  141017. accumulated+=(lastblock+thisblock)>>2;
  141018. lastblock=thisblock;
  141019. }
  141020. }
  141021. if(ogg_page_granulepos(&og)!=-1){
  141022. accumulated= ogg_page_granulepos(&og)-accumulated;
  141023. break;
  141024. }
  141025. }
  141026. if(accumulated<0)accumulated=0;
  141027. vf->pcmlengths[i*2]=accumulated;
  141028. }
  141029. {
  141030. ogg_int64_t end=vf->offsets[i+1];
  141031. _seek_helper(vf,end);
  141032. while(1){
  141033. ret=_get_prev_page(vf,&og);
  141034. if(ret<0){
  141035. vorbis_info_clear(vf->vi+i);
  141036. vorbis_comment_clear(vf->vc+i);
  141037. break;
  141038. }
  141039. if(ogg_page_granulepos(&og)!=-1){
  141040. vf->pcmlengths[i*2+1]=ogg_page_granulepos(&og)-vf->pcmlengths[i*2];
  141041. break;
  141042. }
  141043. vf->offset=ret;
  141044. }
  141045. }
  141046. }
  141047. }
  141048. static int _make_decode_ready(OggVorbis_File *vf){
  141049. if(vf->ready_state>STREAMSET)return 0;
  141050. if(vf->ready_state<STREAMSET)return OV_EFAULT;
  141051. if(vf->seekable){
  141052. if(vorbis_synthesis_init(&vf->vd,vf->vi+vf->current_link))
  141053. return OV_EBADLINK;
  141054. }else{
  141055. if(vorbis_synthesis_init(&vf->vd,vf->vi))
  141056. return OV_EBADLINK;
  141057. }
  141058. vorbis_block_init(&vf->vd,&vf->vb);
  141059. vf->ready_state=INITSET;
  141060. vf->bittrack=0.f;
  141061. vf->samptrack=0.f;
  141062. return 0;
  141063. }
  141064. static int _open_seekable2(OggVorbis_File *vf){
  141065. long serialno=vf->current_serialno;
  141066. ogg_int64_t dataoffset=vf->offset, end;
  141067. ogg_page og;
  141068. (vf->callbacks.seek_func)(vf->datasource,0,SEEK_END);
  141069. vf->offset=vf->end=(vf->callbacks.tell_func)(vf->datasource);
  141070. end=_get_prev_page(vf,&og);
  141071. if(end<0)return(end);
  141072. if(ogg_page_serialno(&og)!=serialno){
  141073. if(_bisect_forward_serialno(vf,0,0,end+1,serialno,0)<0)return(OV_EREAD);
  141074. }else{
  141075. if(_bisect_forward_serialno(vf,0,end,end+1,serialno,0))return(OV_EREAD);
  141076. }
  141077. _prefetch_all_headers(vf,dataoffset);
  141078. return(ov_raw_seek(vf,0));
  141079. }
  141080. static void _decode_clear(OggVorbis_File *vf){
  141081. vorbis_dsp_clear(&vf->vd);
  141082. vorbis_block_clear(&vf->vb);
  141083. vf->ready_state=OPENED;
  141084. }
  141085. static int _fetch_and_process_packet(OggVorbis_File *vf,
  141086. ogg_packet *op_in,
  141087. int readp,
  141088. int spanp){
  141089. ogg_page og;
  141090. while(1){
  141091. if(vf->ready_state==INITSET){
  141092. while(1) {
  141093. ogg_packet op;
  141094. ogg_packet *op_ptr=(op_in?op_in:&op);
  141095. int result=ogg_stream_packetout(&vf->os,op_ptr);
  141096. ogg_int64_t granulepos;
  141097. op_in=NULL;
  141098. if(result==-1)return(OV_HOLE); /* hole in the data. */
  141099. if(result>0){
  141100. granulepos=op_ptr->granulepos;
  141101. if(!vorbis_synthesis(&vf->vb,op_ptr)){ /* lazy check for lazy
  141102. header handling. The
  141103. header packets aren't
  141104. audio, so if/when we
  141105. submit them,
  141106. vorbis_synthesis will
  141107. reject them */
  141108. {
  141109. int oldsamples=vorbis_synthesis_pcmout(&vf->vd,NULL);
  141110. if(oldsamples)return(OV_EFAULT);
  141111. vorbis_synthesis_blockin(&vf->vd,&vf->vb);
  141112. vf->samptrack+=vorbis_synthesis_pcmout(&vf->vd,NULL)-oldsamples;
  141113. vf->bittrack+=op_ptr->bytes*8;
  141114. }
  141115. if(granulepos!=-1 && !op_ptr->e_o_s){
  141116. int link=(vf->seekable?vf->current_link:0);
  141117. int i,samples;
  141118. if(vf->seekable && link>0)
  141119. granulepos-=vf->pcmlengths[link*2];
  141120. if(granulepos<0)granulepos=0; /* actually, this
  141121. shouldn't be possible
  141122. here unless the stream
  141123. is very broken */
  141124. samples=vorbis_synthesis_pcmout(&vf->vd,NULL);
  141125. granulepos-=samples;
  141126. for(i=0;i<link;i++)
  141127. granulepos+=vf->pcmlengths[i*2+1];
  141128. vf->pcm_offset=granulepos;
  141129. }
  141130. return(1);
  141131. }
  141132. }
  141133. else
  141134. break;
  141135. }
  141136. }
  141137. if(vf->ready_state>=OPENED){
  141138. ogg_int64_t ret;
  141139. if(!readp)return(0);
  141140. if((ret=_get_next_page(vf,&og,-1))<0){
  141141. return(OV_EOF); /* eof.
  141142. leave unitialized */
  141143. }
  141144. vf->bittrack+=og.header_len*8;
  141145. if(vf->ready_state==INITSET){
  141146. if(vf->current_serialno!=ogg_page_serialno(&og)){
  141147. if(!spanp)
  141148. return(OV_EOF);
  141149. _decode_clear(vf);
  141150. if(!vf->seekable){
  141151. vorbis_info_clear(vf->vi);
  141152. vorbis_comment_clear(vf->vc);
  141153. }
  141154. }
  141155. }
  141156. }
  141157. if(vf->ready_state!=INITSET){
  141158. int link;
  141159. if(vf->ready_state<STREAMSET){
  141160. if(vf->seekable){
  141161. vf->current_serialno=ogg_page_serialno(&og);
  141162. for(link=0;link<vf->links;link++)
  141163. if(vf->serialnos[link]==vf->current_serialno)break;
  141164. if(link==vf->links)return(OV_EBADLINK); /* sign of a bogus
  141165. stream. error out,
  141166. leave machine
  141167. uninitialized */
  141168. vf->current_link=link;
  141169. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141170. vf->ready_state=STREAMSET;
  141171. }else{
  141172. int ret=_fetch_headers(vf,vf->vi,vf->vc,&vf->current_serialno,&og);
  141173. if(ret)return(ret);
  141174. vf->current_link++;
  141175. link=0;
  141176. }
  141177. }
  141178. {
  141179. int ret=_make_decode_ready(vf);
  141180. if(ret<0)return ret;
  141181. }
  141182. }
  141183. ogg_stream_pagein(&vf->os,&og);
  141184. }
  141185. }
  141186. static int _fseek64_wrap(FILE *f,ogg_int64_t off,int whence){
  141187. if(f==NULL)return(-1);
  141188. return fseek(f,off,whence);
  141189. }
  141190. static int _ov_open1(void *f,OggVorbis_File *vf,char *initial,
  141191. long ibytes, ov_callbacks callbacks){
  141192. int offsettest=(f?callbacks.seek_func(f,0,SEEK_CUR):-1);
  141193. int ret;
  141194. memset(vf,0,sizeof(*vf));
  141195. vf->datasource=f;
  141196. vf->callbacks = callbacks;
  141197. ogg_sync_init(&vf->oy);
  141198. if(initial){
  141199. char *buffer=ogg_sync_buffer(&vf->oy,ibytes);
  141200. memcpy(buffer,initial,ibytes);
  141201. ogg_sync_wrote(&vf->oy,ibytes);
  141202. }
  141203. if(offsettest!=-1)vf->seekable=1;
  141204. vf->links=1;
  141205. vf->vi=(vorbis_info*) _ogg_calloc(vf->links,sizeof(*vf->vi));
  141206. vf->vc=(vorbis_comment*) _ogg_calloc(vf->links,sizeof(*vf->vc));
  141207. ogg_stream_init(&vf->os,-1); /* fill in the serialno later */
  141208. if((ret=_fetch_headers(vf,vf->vi,vf->vc,&vf->current_serialno,NULL))<0){
  141209. vf->datasource=NULL;
  141210. ov_clear(vf);
  141211. }else
  141212. vf->ready_state=PARTOPEN;
  141213. return(ret);
  141214. }
  141215. static int _ov_open2(OggVorbis_File *vf){
  141216. if(vf->ready_state != PARTOPEN) return OV_EINVAL;
  141217. vf->ready_state=OPENED;
  141218. if(vf->seekable){
  141219. int ret=_open_seekable2(vf);
  141220. if(ret){
  141221. vf->datasource=NULL;
  141222. ov_clear(vf);
  141223. }
  141224. return(ret);
  141225. }else
  141226. vf->ready_state=STREAMSET;
  141227. return 0;
  141228. }
  141229. int ov_clear(OggVorbis_File *vf){
  141230. if(vf){
  141231. vorbis_block_clear(&vf->vb);
  141232. vorbis_dsp_clear(&vf->vd);
  141233. ogg_stream_clear(&vf->os);
  141234. if(vf->vi && vf->links){
  141235. int i;
  141236. for(i=0;i<vf->links;i++){
  141237. vorbis_info_clear(vf->vi+i);
  141238. vorbis_comment_clear(vf->vc+i);
  141239. }
  141240. _ogg_free(vf->vi);
  141241. _ogg_free(vf->vc);
  141242. }
  141243. if(vf->dataoffsets)_ogg_free(vf->dataoffsets);
  141244. if(vf->pcmlengths)_ogg_free(vf->pcmlengths);
  141245. if(vf->serialnos)_ogg_free(vf->serialnos);
  141246. if(vf->offsets)_ogg_free(vf->offsets);
  141247. ogg_sync_clear(&vf->oy);
  141248. if(vf->datasource)(vf->callbacks.close_func)(vf->datasource);
  141249. memset(vf,0,sizeof(*vf));
  141250. }
  141251. #ifdef DEBUG_LEAKS
  141252. _VDBG_dump();
  141253. #endif
  141254. return(0);
  141255. }
  141256. int ov_open_callbacks(void *f,OggVorbis_File *vf,char *initial,long ibytes,
  141257. ov_callbacks callbacks){
  141258. int ret=_ov_open1(f,vf,initial,ibytes,callbacks);
  141259. if(ret)return ret;
  141260. return _ov_open2(vf);
  141261. }
  141262. int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes){
  141263. ov_callbacks callbacks = {
  141264. (size_t (*)(void *, size_t, size_t, void *)) fread,
  141265. (int (*)(void *, ogg_int64_t, int)) _fseek64_wrap,
  141266. (int (*)(void *)) fclose,
  141267. (long (*)(void *)) ftell
  141268. };
  141269. return ov_open_callbacks((void *)f, vf, initial, ibytes, callbacks);
  141270. }
  141271. int ov_halfrate(OggVorbis_File *vf,int flag){
  141272. int i;
  141273. if(vf->vi==NULL)return OV_EINVAL;
  141274. if(!vf->seekable)return OV_EINVAL;
  141275. if(vf->ready_state>=STREAMSET)
  141276. _decode_clear(vf); /* clear out stream state; later on libvorbis
  141277. will be able to swap this on the fly, but
  141278. for now dumping the decode machine is needed
  141279. to reinit the MDCT lookups. 1.1 libvorbis
  141280. is planned to be able to switch on the fly */
  141281. for(i=0;i<vf->links;i++){
  141282. if(vorbis_synthesis_halfrate(vf->vi+i,flag)){
  141283. ov_halfrate(vf,0);
  141284. return OV_EINVAL;
  141285. }
  141286. }
  141287. return 0;
  141288. }
  141289. int ov_halfrate_p(OggVorbis_File *vf){
  141290. if(vf->vi==NULL)return OV_EINVAL;
  141291. return vorbis_synthesis_halfrate_p(vf->vi);
  141292. }
  141293. int ov_test_callbacks(void *f,OggVorbis_File *vf,char *initial,long ibytes,
  141294. ov_callbacks callbacks)
  141295. {
  141296. return _ov_open1(f,vf,initial,ibytes,callbacks);
  141297. }
  141298. int ov_test(FILE *f,OggVorbis_File *vf,char *initial,long ibytes){
  141299. ov_callbacks callbacks = {
  141300. (size_t (*)(void *, size_t, size_t, void *)) fread,
  141301. (int (*)(void *, ogg_int64_t, int)) _fseek64_wrap,
  141302. (int (*)(void *)) fclose,
  141303. (long (*)(void *)) ftell
  141304. };
  141305. return ov_test_callbacks((void *)f, vf, initial, ibytes, callbacks);
  141306. }
  141307. int ov_test_open(OggVorbis_File *vf){
  141308. if(vf->ready_state!=PARTOPEN)return(OV_EINVAL);
  141309. return _ov_open2(vf);
  141310. }
  141311. long ov_streams(OggVorbis_File *vf){
  141312. return vf->links;
  141313. }
  141314. long ov_seekable(OggVorbis_File *vf){
  141315. return vf->seekable;
  141316. }
  141317. long ov_bitrate(OggVorbis_File *vf,int i){
  141318. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141319. if(i>=vf->links)return(OV_EINVAL);
  141320. if(!vf->seekable && i!=0)return(ov_bitrate(vf,0));
  141321. if(i<0){
  141322. ogg_int64_t bits=0;
  141323. int i;
  141324. float br;
  141325. for(i=0;i<vf->links;i++)
  141326. bits+=(vf->offsets[i+1]-vf->dataoffsets[i])*8;
  141327. br = bits/ov_time_total(vf,-1);
  141328. return(rint(br));
  141329. }else{
  141330. if(vf->seekable){
  141331. return(rint((vf->offsets[i+1]-vf->dataoffsets[i])*8/ov_time_total(vf,i)));
  141332. }else{
  141333. if(vf->vi[i].bitrate_nominal>0){
  141334. return vf->vi[i].bitrate_nominal;
  141335. }else{
  141336. if(vf->vi[i].bitrate_upper>0){
  141337. if(vf->vi[i].bitrate_lower>0){
  141338. return (vf->vi[i].bitrate_upper+vf->vi[i].bitrate_lower)/2;
  141339. }else{
  141340. return vf->vi[i].bitrate_upper;
  141341. }
  141342. }
  141343. return(OV_FALSE);
  141344. }
  141345. }
  141346. }
  141347. }
  141348. long ov_bitrate_instant(OggVorbis_File *vf){
  141349. int link=(vf->seekable?vf->current_link:0);
  141350. long ret;
  141351. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141352. if(vf->samptrack==0)return(OV_FALSE);
  141353. ret=vf->bittrack/vf->samptrack*vf->vi[link].rate+.5;
  141354. vf->bittrack=0.f;
  141355. vf->samptrack=0.f;
  141356. return(ret);
  141357. }
  141358. long ov_serialnumber(OggVorbis_File *vf,int i){
  141359. if(i>=vf->links)return(ov_serialnumber(vf,vf->links-1));
  141360. if(!vf->seekable && i>=0)return(ov_serialnumber(vf,-1));
  141361. if(i<0){
  141362. return(vf->current_serialno);
  141363. }else{
  141364. return(vf->serialnos[i]);
  141365. }
  141366. }
  141367. ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i){
  141368. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141369. if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
  141370. if(i<0){
  141371. ogg_int64_t acc=0;
  141372. int i;
  141373. for(i=0;i<vf->links;i++)
  141374. acc+=ov_raw_total(vf,i);
  141375. return(acc);
  141376. }else{
  141377. return(vf->offsets[i+1]-vf->offsets[i]);
  141378. }
  141379. }
  141380. ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i){
  141381. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141382. if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
  141383. if(i<0){
  141384. ogg_int64_t acc=0;
  141385. int i;
  141386. for(i=0;i<vf->links;i++)
  141387. acc+=ov_pcm_total(vf,i);
  141388. return(acc);
  141389. }else{
  141390. return(vf->pcmlengths[i*2+1]);
  141391. }
  141392. }
  141393. double ov_time_total(OggVorbis_File *vf,int i){
  141394. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141395. if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
  141396. if(i<0){
  141397. double acc=0;
  141398. int i;
  141399. for(i=0;i<vf->links;i++)
  141400. acc+=ov_time_total(vf,i);
  141401. return(acc);
  141402. }else{
  141403. return((double)(vf->pcmlengths[i*2+1])/vf->vi[i].rate);
  141404. }
  141405. }
  141406. int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos){
  141407. ogg_stream_state work_os;
  141408. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141409. if(!vf->seekable)
  141410. return(OV_ENOSEEK); /* don't dump machine if we can't seek */
  141411. if(pos<0 || pos>vf->end)return(OV_EINVAL);
  141412. vf->pcm_offset=-1;
  141413. ogg_stream_reset_serialno(&vf->os,
  141414. vf->current_serialno); /* must set serialno */
  141415. vorbis_synthesis_restart(&vf->vd);
  141416. _seek_helper(vf,pos);
  141417. {
  141418. ogg_page og;
  141419. ogg_packet op;
  141420. int lastblock=0;
  141421. int accblock=0;
  141422. int thisblock;
  141423. int eosflag;
  141424. ogg_stream_init(&work_os,vf->current_serialno); /* get the memory ready */
  141425. ogg_stream_reset(&work_os); /* eliminate the spurious OV_HOLE
  141426. return from not necessarily
  141427. starting from the beginning */
  141428. while(1){
  141429. if(vf->ready_state>=STREAMSET){
  141430. int result=ogg_stream_packetout(&work_os,&op);
  141431. if(result>0){
  141432. if(vf->vi[vf->current_link].codec_setup){
  141433. thisblock=vorbis_packet_blocksize(vf->vi+vf->current_link,&op);
  141434. if(thisblock<0){
  141435. ogg_stream_packetout(&vf->os,NULL);
  141436. thisblock=0;
  141437. }else{
  141438. if(eosflag)
  141439. ogg_stream_packetout(&vf->os,NULL);
  141440. else
  141441. if(lastblock)accblock+=(lastblock+thisblock)>>2;
  141442. }
  141443. if(op.granulepos!=-1){
  141444. int i,link=vf->current_link;
  141445. ogg_int64_t granulepos=op.granulepos-vf->pcmlengths[link*2];
  141446. if(granulepos<0)granulepos=0;
  141447. for(i=0;i<link;i++)
  141448. granulepos+=vf->pcmlengths[i*2+1];
  141449. vf->pcm_offset=granulepos-accblock;
  141450. break;
  141451. }
  141452. lastblock=thisblock;
  141453. continue;
  141454. }else
  141455. ogg_stream_packetout(&vf->os,NULL);
  141456. }
  141457. }
  141458. if(!lastblock){
  141459. if(_get_next_page(vf,&og,-1)<0){
  141460. vf->pcm_offset=ov_pcm_total(vf,-1);
  141461. break;
  141462. }
  141463. }else{
  141464. vf->pcm_offset=-1;
  141465. break;
  141466. }
  141467. if(vf->ready_state>=STREAMSET)
  141468. if(vf->current_serialno!=ogg_page_serialno(&og)){
  141469. _decode_clear(vf); /* clear out stream state */
  141470. ogg_stream_clear(&work_os);
  141471. }
  141472. if(vf->ready_state<STREAMSET){
  141473. int link;
  141474. vf->current_serialno=ogg_page_serialno(&og);
  141475. for(link=0;link<vf->links;link++)
  141476. if(vf->serialnos[link]==vf->current_serialno)break;
  141477. if(link==vf->links)goto seek_error; /* sign of a bogus stream.
  141478. error out, leave
  141479. machine uninitialized */
  141480. vf->current_link=link;
  141481. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141482. ogg_stream_reset_serialno(&work_os,vf->current_serialno);
  141483. vf->ready_state=STREAMSET;
  141484. }
  141485. ogg_stream_pagein(&vf->os,&og);
  141486. ogg_stream_pagein(&work_os,&og);
  141487. eosflag=ogg_page_eos(&og);
  141488. }
  141489. }
  141490. ogg_stream_clear(&work_os);
  141491. vf->bittrack=0.f;
  141492. vf->samptrack=0.f;
  141493. return(0);
  141494. seek_error:
  141495. vf->pcm_offset=-1;
  141496. ogg_stream_clear(&work_os);
  141497. _decode_clear(vf);
  141498. return OV_EBADLINK;
  141499. }
  141500. int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos){
  141501. int link=-1;
  141502. ogg_int64_t result=0;
  141503. ogg_int64_t total=ov_pcm_total(vf,-1);
  141504. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141505. if(!vf->seekable)return(OV_ENOSEEK);
  141506. if(pos<0 || pos>total)return(OV_EINVAL);
  141507. for(link=vf->links-1;link>=0;link--){
  141508. total-=vf->pcmlengths[link*2+1];
  141509. if(pos>=total)break;
  141510. }
  141511. {
  141512. ogg_int64_t end=vf->offsets[link+1];
  141513. ogg_int64_t begin=vf->offsets[link];
  141514. ogg_int64_t begintime = vf->pcmlengths[link*2];
  141515. ogg_int64_t endtime = vf->pcmlengths[link*2+1]+begintime;
  141516. ogg_int64_t target=pos-total+begintime;
  141517. ogg_int64_t best=begin;
  141518. ogg_page og;
  141519. while(begin<end){
  141520. ogg_int64_t bisect;
  141521. if(end-begin<CHUNKSIZE){
  141522. bisect=begin;
  141523. }else{
  141524. bisect=begin +
  141525. (target-begintime)*(end-begin)/(endtime-begintime) - CHUNKSIZE;
  141526. if(bisect<=begin)
  141527. bisect=begin+1;
  141528. }
  141529. _seek_helper(vf,bisect);
  141530. while(begin<end){
  141531. result=_get_next_page(vf,&og,end-vf->offset);
  141532. if(result==OV_EREAD) goto seek_error;
  141533. if(result<0){
  141534. if(bisect<=begin+1)
  141535. end=begin; /* found it */
  141536. else{
  141537. if(bisect==0) goto seek_error;
  141538. bisect-=CHUNKSIZE;
  141539. if(bisect<=begin)bisect=begin+1;
  141540. _seek_helper(vf,bisect);
  141541. }
  141542. }else{
  141543. ogg_int64_t granulepos=ogg_page_granulepos(&og);
  141544. if(granulepos==-1)continue;
  141545. if(granulepos<target){
  141546. best=result; /* raw offset of packet with granulepos */
  141547. begin=vf->offset; /* raw offset of next page */
  141548. begintime=granulepos;
  141549. if(target-begintime>44100)break;
  141550. bisect=begin; /* *not* begin + 1 */
  141551. }else{
  141552. if(bisect<=begin+1)
  141553. end=begin; /* found it */
  141554. else{
  141555. if(end==vf->offset){ /* we're pretty close - we'd be stuck in */
  141556. end=result;
  141557. bisect-=CHUNKSIZE; /* an endless loop otherwise. */
  141558. if(bisect<=begin)bisect=begin+1;
  141559. _seek_helper(vf,bisect);
  141560. }else{
  141561. end=result;
  141562. endtime=granulepos;
  141563. break;
  141564. }
  141565. }
  141566. }
  141567. }
  141568. }
  141569. }
  141570. {
  141571. ogg_page og;
  141572. ogg_packet op;
  141573. _seek_helper(vf,best);
  141574. vf->pcm_offset=-1;
  141575. if(_get_next_page(vf,&og,-1)<0)return(OV_EOF); /* shouldn't happen */
  141576. if(link!=vf->current_link){
  141577. _decode_clear(vf);
  141578. vf->current_link=link;
  141579. vf->current_serialno=ogg_page_serialno(&og);
  141580. vf->ready_state=STREAMSET;
  141581. }else{
  141582. vorbis_synthesis_restart(&vf->vd);
  141583. }
  141584. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141585. ogg_stream_pagein(&vf->os,&og);
  141586. while(1){
  141587. result=ogg_stream_packetpeek(&vf->os,&op);
  141588. if(result==0){
  141589. _seek_helper(vf,best);
  141590. while(1){
  141591. result=_get_prev_page(vf,&og);
  141592. if(result<0) goto seek_error;
  141593. if(ogg_page_granulepos(&og)>-1 ||
  141594. !ogg_page_continued(&og)){
  141595. return ov_raw_seek(vf,result);
  141596. }
  141597. vf->offset=result;
  141598. }
  141599. }
  141600. if(result<0){
  141601. result = OV_EBADPACKET;
  141602. goto seek_error;
  141603. }
  141604. if(op.granulepos!=-1){
  141605. vf->pcm_offset=op.granulepos-vf->pcmlengths[vf->current_link*2];
  141606. if(vf->pcm_offset<0)vf->pcm_offset=0;
  141607. vf->pcm_offset+=total;
  141608. break;
  141609. }else
  141610. result=ogg_stream_packetout(&vf->os,NULL);
  141611. }
  141612. }
  141613. }
  141614. if(vf->pcm_offset>pos || pos>ov_pcm_total(vf,-1)){
  141615. result=OV_EFAULT;
  141616. goto seek_error;
  141617. }
  141618. vf->bittrack=0.f;
  141619. vf->samptrack=0.f;
  141620. return(0);
  141621. seek_error:
  141622. vf->pcm_offset=-1;
  141623. _decode_clear(vf);
  141624. return (int)result;
  141625. }
  141626. int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos){
  141627. int thisblock,lastblock=0;
  141628. int ret=ov_pcm_seek_page(vf,pos);
  141629. if(ret<0)return(ret);
  141630. if((ret=_make_decode_ready(vf)))return ret;
  141631. while(1){
  141632. ogg_packet op;
  141633. ogg_page og;
  141634. int ret=ogg_stream_packetpeek(&vf->os,&op);
  141635. if(ret>0){
  141636. thisblock=vorbis_packet_blocksize(vf->vi+vf->current_link,&op);
  141637. if(thisblock<0){
  141638. ogg_stream_packetout(&vf->os,NULL);
  141639. continue; /* non audio packet */
  141640. }
  141641. if(lastblock)vf->pcm_offset+=(lastblock+thisblock)>>2;
  141642. if(vf->pcm_offset+((thisblock+
  141643. vorbis_info_blocksize(vf->vi,1))>>2)>=pos)break;
  141644. ogg_stream_packetout(&vf->os,NULL);
  141645. vorbis_synthesis_trackonly(&vf->vb,&op); /* set up a vb with
  141646. only tracking, no
  141647. pcm_decode */
  141648. vorbis_synthesis_blockin(&vf->vd,&vf->vb);
  141649. if(op.granulepos>-1){
  141650. int i;
  141651. vf->pcm_offset=op.granulepos-vf->pcmlengths[vf->current_link*2];
  141652. if(vf->pcm_offset<0)vf->pcm_offset=0;
  141653. for(i=0;i<vf->current_link;i++)
  141654. vf->pcm_offset+=vf->pcmlengths[i*2+1];
  141655. }
  141656. lastblock=thisblock;
  141657. }else{
  141658. if(ret<0 && ret!=OV_HOLE)break;
  141659. if(_get_next_page(vf,&og,-1)<0)break;
  141660. if(vf->current_serialno!=ogg_page_serialno(&og))_decode_clear(vf);
  141661. if(vf->ready_state<STREAMSET){
  141662. int link;
  141663. vf->current_serialno=ogg_page_serialno(&og);
  141664. for(link=0;link<vf->links;link++)
  141665. if(vf->serialnos[link]==vf->current_serialno)break;
  141666. if(link==vf->links)return(OV_EBADLINK);
  141667. vf->current_link=link;
  141668. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141669. vf->ready_state=STREAMSET;
  141670. ret=_make_decode_ready(vf);
  141671. if(ret)return ret;
  141672. lastblock=0;
  141673. }
  141674. ogg_stream_pagein(&vf->os,&og);
  141675. }
  141676. }
  141677. vf->bittrack=0.f;
  141678. vf->samptrack=0.f;
  141679. while(vf->pcm_offset<pos){
  141680. ogg_int64_t target=pos-vf->pcm_offset;
  141681. long samples=vorbis_synthesis_pcmout(&vf->vd,NULL);
  141682. if(samples>target)samples=target;
  141683. vorbis_synthesis_read(&vf->vd,samples);
  141684. vf->pcm_offset+=samples;
  141685. if(samples<target)
  141686. if(_fetch_and_process_packet(vf,NULL,1,1)<=0)
  141687. vf->pcm_offset=ov_pcm_total(vf,-1); /* eof */
  141688. }
  141689. return 0;
  141690. }
  141691. int ov_time_seek(OggVorbis_File *vf,double seconds){
  141692. int link=-1;
  141693. ogg_int64_t pcm_total=ov_pcm_total(vf,-1);
  141694. double time_total=ov_time_total(vf,-1);
  141695. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141696. if(!vf->seekable)return(OV_ENOSEEK);
  141697. if(seconds<0 || seconds>time_total)return(OV_EINVAL);
  141698. for(link=vf->links-1;link>=0;link--){
  141699. pcm_total-=vf->pcmlengths[link*2+1];
  141700. time_total-=ov_time_total(vf,link);
  141701. if(seconds>=time_total)break;
  141702. }
  141703. {
  141704. ogg_int64_t target=pcm_total+(seconds-time_total)*vf->vi[link].rate;
  141705. return(ov_pcm_seek(vf,target));
  141706. }
  141707. }
  141708. int ov_time_seek_page(OggVorbis_File *vf,double seconds){
  141709. int link=-1;
  141710. ogg_int64_t pcm_total=ov_pcm_total(vf,-1);
  141711. double time_total=ov_time_total(vf,-1);
  141712. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141713. if(!vf->seekable)return(OV_ENOSEEK);
  141714. if(seconds<0 || seconds>time_total)return(OV_EINVAL);
  141715. for(link=vf->links-1;link>=0;link--){
  141716. pcm_total-=vf->pcmlengths[link*2+1];
  141717. time_total-=ov_time_total(vf,link);
  141718. if(seconds>=time_total)break;
  141719. }
  141720. {
  141721. ogg_int64_t target=pcm_total+(seconds-time_total)*vf->vi[link].rate;
  141722. return(ov_pcm_seek_page(vf,target));
  141723. }
  141724. }
  141725. ogg_int64_t ov_raw_tell(OggVorbis_File *vf){
  141726. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141727. return(vf->offset);
  141728. }
  141729. ogg_int64_t ov_pcm_tell(OggVorbis_File *vf){
  141730. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141731. return(vf->pcm_offset);
  141732. }
  141733. double ov_time_tell(OggVorbis_File *vf){
  141734. int link=0;
  141735. ogg_int64_t pcm_total=0;
  141736. double time_total=0.f;
  141737. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141738. if(vf->seekable){
  141739. pcm_total=ov_pcm_total(vf,-1);
  141740. time_total=ov_time_total(vf,-1);
  141741. for(link=vf->links-1;link>=0;link--){
  141742. pcm_total-=vf->pcmlengths[link*2+1];
  141743. time_total-=ov_time_total(vf,link);
  141744. if(vf->pcm_offset>=pcm_total)break;
  141745. }
  141746. }
  141747. return((double)time_total+(double)(vf->pcm_offset-pcm_total)/vf->vi[link].rate);
  141748. }
  141749. vorbis_info *ov_info(OggVorbis_File *vf,int link){
  141750. if(vf->seekable){
  141751. if(link<0)
  141752. if(vf->ready_state>=STREAMSET)
  141753. return vf->vi+vf->current_link;
  141754. else
  141755. return vf->vi;
  141756. else
  141757. if(link>=vf->links)
  141758. return NULL;
  141759. else
  141760. return vf->vi+link;
  141761. }else{
  141762. return vf->vi;
  141763. }
  141764. }
  141765. vorbis_comment *ov_comment(OggVorbis_File *vf,int link){
  141766. if(vf->seekable){
  141767. if(link<0)
  141768. if(vf->ready_state>=STREAMSET)
  141769. return vf->vc+vf->current_link;
  141770. else
  141771. return vf->vc;
  141772. else
  141773. if(link>=vf->links)
  141774. return NULL;
  141775. else
  141776. return vf->vc+link;
  141777. }else{
  141778. return vf->vc;
  141779. }
  141780. }
  141781. static int host_is_big_endian() {
  141782. ogg_int32_t pattern = 0xfeedface; /* deadbeef */
  141783. unsigned char *bytewise = (unsigned char *)&pattern;
  141784. if (bytewise[0] == 0xfe) return 1;
  141785. return 0;
  141786. }
  141787. long ov_read(OggVorbis_File *vf,char *buffer,int length,
  141788. int bigendianp,int word,int sgned,int *bitstream){
  141789. int i,j;
  141790. int host_endian = host_is_big_endian();
  141791. float **pcm;
  141792. long samples;
  141793. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141794. while(1){
  141795. if(vf->ready_state==INITSET){
  141796. samples=vorbis_synthesis_pcmout(&vf->vd,&pcm);
  141797. if(samples)break;
  141798. }
  141799. {
  141800. int ret=_fetch_and_process_packet(vf,NULL,1,1);
  141801. if(ret==OV_EOF)
  141802. return(0);
  141803. if(ret<=0)
  141804. return(ret);
  141805. }
  141806. }
  141807. if(samples>0){
  141808. long channels=ov_info(vf,-1)->channels;
  141809. long bytespersample=word * channels;
  141810. vorbis_fpu_control fpu;
  141811. (void) fpu; // (to avoid a warning about it being unused)
  141812. if(samples>length/bytespersample)samples=length/bytespersample;
  141813. if(samples <= 0)
  141814. return OV_EINVAL;
  141815. {
  141816. int val;
  141817. if(word==1){
  141818. int off=(sgned?0:128);
  141819. vorbis_fpu_setround(&fpu);
  141820. for(j=0;j<samples;j++)
  141821. for(i=0;i<channels;i++){
  141822. val=vorbis_ftoi(pcm[i][j]*128.f);
  141823. if(val>127)val=127;
  141824. else if(val<-128)val=-128;
  141825. *buffer++=val+off;
  141826. }
  141827. vorbis_fpu_restore(fpu);
  141828. }else{
  141829. int off=(sgned?0:32768);
  141830. if(host_endian==bigendianp){
  141831. if(sgned){
  141832. vorbis_fpu_setround(&fpu);
  141833. for(i=0;i<channels;i++) { /* It's faster in this order */
  141834. float *src=pcm[i];
  141835. short *dest=((short *)buffer)+i;
  141836. for(j=0;j<samples;j++) {
  141837. val=vorbis_ftoi(src[j]*32768.f);
  141838. if(val>32767)val=32767;
  141839. else if(val<-32768)val=-32768;
  141840. *dest=val;
  141841. dest+=channels;
  141842. }
  141843. }
  141844. vorbis_fpu_restore(fpu);
  141845. }else{
  141846. vorbis_fpu_setround(&fpu);
  141847. for(i=0;i<channels;i++) {
  141848. float *src=pcm[i];
  141849. short *dest=((short *)buffer)+i;
  141850. for(j=0;j<samples;j++) {
  141851. val=vorbis_ftoi(src[j]*32768.f);
  141852. if(val>32767)val=32767;
  141853. else if(val<-32768)val=-32768;
  141854. *dest=val+off;
  141855. dest+=channels;
  141856. }
  141857. }
  141858. vorbis_fpu_restore(fpu);
  141859. }
  141860. }else if(bigendianp){
  141861. vorbis_fpu_setround(&fpu);
  141862. for(j=0;j<samples;j++)
  141863. for(i=0;i<channels;i++){
  141864. val=vorbis_ftoi(pcm[i][j]*32768.f);
  141865. if(val>32767)val=32767;
  141866. else if(val<-32768)val=-32768;
  141867. val+=off;
  141868. *buffer++=(val>>8);
  141869. *buffer++=(val&0xff);
  141870. }
  141871. vorbis_fpu_restore(fpu);
  141872. }else{
  141873. int val;
  141874. vorbis_fpu_setround(&fpu);
  141875. for(j=0;j<samples;j++)
  141876. for(i=0;i<channels;i++){
  141877. val=vorbis_ftoi(pcm[i][j]*32768.f);
  141878. if(val>32767)val=32767;
  141879. else if(val<-32768)val=-32768;
  141880. val+=off;
  141881. *buffer++=(val&0xff);
  141882. *buffer++=(val>>8);
  141883. }
  141884. vorbis_fpu_restore(fpu);
  141885. }
  141886. }
  141887. }
  141888. vorbis_synthesis_read(&vf->vd,samples);
  141889. vf->pcm_offset+=samples;
  141890. if(bitstream)*bitstream=vf->current_link;
  141891. return(samples*bytespersample);
  141892. }else{
  141893. return(samples);
  141894. }
  141895. }
  141896. long ov_read_float(OggVorbis_File *vf,float ***pcm_channels,int length,
  141897. int *bitstream){
  141898. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141899. while(1){
  141900. if(vf->ready_state==INITSET){
  141901. float **pcm;
  141902. long samples=vorbis_synthesis_pcmout(&vf->vd,&pcm);
  141903. if(samples){
  141904. if(pcm_channels)*pcm_channels=pcm;
  141905. if(samples>length)samples=length;
  141906. vorbis_synthesis_read(&vf->vd,samples);
  141907. vf->pcm_offset+=samples;
  141908. if(bitstream)*bitstream=vf->current_link;
  141909. return samples;
  141910. }
  141911. }
  141912. {
  141913. int ret=_fetch_and_process_packet(vf,NULL,1,1);
  141914. if(ret==OV_EOF)return(0);
  141915. if(ret<=0)return(ret);
  141916. }
  141917. }
  141918. }
  141919. extern float *vorbis_window(vorbis_dsp_state *v,int W);
  141920. extern void _analysis_output_always(const char *base,int i,float *v,int n,int bark,int dB,
  141921. ogg_int64_t off);
  141922. static void _ov_splice(float **pcm,float **lappcm,
  141923. int n1, int n2,
  141924. int ch1, int ch2,
  141925. float *w1, float *w2){
  141926. int i,j;
  141927. float *w=w1;
  141928. int n=n1;
  141929. if(n1>n2){
  141930. n=n2;
  141931. w=w2;
  141932. }
  141933. for(j=0;j<ch1 && j<ch2;j++){
  141934. float *s=lappcm[j];
  141935. float *d=pcm[j];
  141936. for(i=0;i<n;i++){
  141937. float wd=w[i]*w[i];
  141938. float ws=1.-wd;
  141939. d[i]=d[i]*wd + s[i]*ws;
  141940. }
  141941. }
  141942. for(;j<ch2;j++){
  141943. float *d=pcm[j];
  141944. for(i=0;i<n;i++){
  141945. float wd=w[i]*w[i];
  141946. d[i]=d[i]*wd;
  141947. }
  141948. }
  141949. }
  141950. static int _ov_initset(OggVorbis_File *vf){
  141951. while(1){
  141952. if(vf->ready_state==INITSET)break;
  141953. {
  141954. int ret=_fetch_and_process_packet(vf,NULL,1,0);
  141955. if(ret<0 && ret!=OV_HOLE)return(ret);
  141956. }
  141957. }
  141958. return 0;
  141959. }
  141960. static int _ov_initprime(OggVorbis_File *vf){
  141961. vorbis_dsp_state *vd=&vf->vd;
  141962. while(1){
  141963. if(vf->ready_state==INITSET)
  141964. if(vorbis_synthesis_pcmout(vd,NULL))break;
  141965. {
  141966. int ret=_fetch_and_process_packet(vf,NULL,1,0);
  141967. if(ret<0 && ret!=OV_HOLE)return(ret);
  141968. }
  141969. }
  141970. return 0;
  141971. }
  141972. static void _ov_getlap(OggVorbis_File *vf,vorbis_info *vi,vorbis_dsp_state *vd,
  141973. float **lappcm,int lapsize){
  141974. int lapcount=0,i;
  141975. float **pcm;
  141976. while(lapcount<lapsize){
  141977. int samples=vorbis_synthesis_pcmout(vd,&pcm);
  141978. if(samples){
  141979. if(samples>lapsize-lapcount)samples=lapsize-lapcount;
  141980. for(i=0;i<vi->channels;i++)
  141981. memcpy(lappcm[i]+lapcount,pcm[i],sizeof(**pcm)*samples);
  141982. lapcount+=samples;
  141983. vorbis_synthesis_read(vd,samples);
  141984. }else{
  141985. int ret=_fetch_and_process_packet(vf,NULL,1,0); /* do *not* span */
  141986. if(ret==OV_EOF)break;
  141987. }
  141988. }
  141989. if(lapcount<lapsize){
  141990. int samples=vorbis_synthesis_lapout(&vf->vd,&pcm);
  141991. if(samples==0){
  141992. for(i=0;i<vi->channels;i++)
  141993. memset(lappcm[i]+lapcount,0,sizeof(**pcm)*lapsize-lapcount);
  141994. lapcount=lapsize;
  141995. }else{
  141996. if(samples>lapsize-lapcount)samples=lapsize-lapcount;
  141997. for(i=0;i<vi->channels;i++)
  141998. memcpy(lappcm[i]+lapcount,pcm[i],sizeof(**pcm)*samples);
  141999. lapcount+=samples;
  142000. }
  142001. }
  142002. }
  142003. int ov_crosslap(OggVorbis_File *vf1, OggVorbis_File *vf2){
  142004. vorbis_info *vi1,*vi2;
  142005. float **lappcm;
  142006. float **pcm;
  142007. float *w1,*w2;
  142008. int n1,n2,i,ret,hs1,hs2;
  142009. if(vf1==vf2)return(0); /* degenerate case */
  142010. if(vf1->ready_state<OPENED)return(OV_EINVAL);
  142011. if(vf2->ready_state<OPENED)return(OV_EINVAL);
  142012. ret=_ov_initset(vf1);
  142013. if(ret)return(ret);
  142014. ret=_ov_initprime(vf2);
  142015. if(ret)return(ret);
  142016. vi1=ov_info(vf1,-1);
  142017. vi2=ov_info(vf2,-1);
  142018. hs1=ov_halfrate_p(vf1);
  142019. hs2=ov_halfrate_p(vf2);
  142020. lappcm=(float**) alloca(sizeof(*lappcm)*vi1->channels);
  142021. n1=vorbis_info_blocksize(vi1,0)>>(1+hs1);
  142022. n2=vorbis_info_blocksize(vi2,0)>>(1+hs2);
  142023. w1=vorbis_window(&vf1->vd,0);
  142024. w2=vorbis_window(&vf2->vd,0);
  142025. for(i=0;i<vi1->channels;i++)
  142026. lappcm[i]=(float*) alloca(sizeof(**lappcm)*n1);
  142027. _ov_getlap(vf1,vi1,&vf1->vd,lappcm,n1);
  142028. vorbis_synthesis_lapout(&vf2->vd,&pcm);
  142029. _analysis_output_always("pcmL",0,pcm[0],n1*2,0,0,0);
  142030. _analysis_output_always("pcmR",0,pcm[1],n1*2,0,0,0);
  142031. _ov_splice(pcm,lappcm,n1,n2,vi1->channels,vi2->channels,w1,w2);
  142032. return(0);
  142033. }
  142034. static int _ov_64_seek_lap(OggVorbis_File *vf,ogg_int64_t pos,
  142035. int (*localseek)(OggVorbis_File *,ogg_int64_t)){
  142036. vorbis_info *vi;
  142037. float **lappcm;
  142038. float **pcm;
  142039. float *w1,*w2;
  142040. int n1,n2,ch1,ch2,hs;
  142041. int i,ret;
  142042. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142043. ret=_ov_initset(vf);
  142044. if(ret)return(ret);
  142045. vi=ov_info(vf,-1);
  142046. hs=ov_halfrate_p(vf);
  142047. ch1=vi->channels;
  142048. n1=vorbis_info_blocksize(vi,0)>>(1+hs);
  142049. w1=vorbis_window(&vf->vd,0); /* window arrays from libvorbis are
  142050. persistent; even if the decode state
  142051. from this link gets dumped, this
  142052. window array continues to exist */
  142053. lappcm=(float**) alloca(sizeof(*lappcm)*ch1);
  142054. for(i=0;i<ch1;i++)
  142055. lappcm[i]=(float*) alloca(sizeof(**lappcm)*n1);
  142056. _ov_getlap(vf,vi,&vf->vd,lappcm,n1);
  142057. ret=localseek(vf,pos);
  142058. if(ret)return ret;
  142059. ret=_ov_initprime(vf);
  142060. if(ret)return(ret);
  142061. vi=ov_info(vf,-1);
  142062. ch2=vi->channels;
  142063. n2=vorbis_info_blocksize(vi,0)>>(1+hs);
  142064. w2=vorbis_window(&vf->vd,0);
  142065. vorbis_synthesis_lapout(&vf->vd,&pcm);
  142066. _ov_splice(pcm,lappcm,n1,n2,ch1,ch2,w1,w2);
  142067. return(0);
  142068. }
  142069. int ov_raw_seek_lap(OggVorbis_File *vf,ogg_int64_t pos){
  142070. return _ov_64_seek_lap(vf,pos,ov_raw_seek);
  142071. }
  142072. int ov_pcm_seek_lap(OggVorbis_File *vf,ogg_int64_t pos){
  142073. return _ov_64_seek_lap(vf,pos,ov_pcm_seek);
  142074. }
  142075. int ov_pcm_seek_page_lap(OggVorbis_File *vf,ogg_int64_t pos){
  142076. return _ov_64_seek_lap(vf,pos,ov_pcm_seek_page);
  142077. }
  142078. static int _ov_d_seek_lap(OggVorbis_File *vf,double pos,
  142079. int (*localseek)(OggVorbis_File *,double)){
  142080. vorbis_info *vi;
  142081. float **lappcm;
  142082. float **pcm;
  142083. float *w1,*w2;
  142084. int n1,n2,ch1,ch2,hs;
  142085. int i,ret;
  142086. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142087. ret=_ov_initset(vf);
  142088. if(ret)return(ret);
  142089. vi=ov_info(vf,-1);
  142090. hs=ov_halfrate_p(vf);
  142091. ch1=vi->channels;
  142092. n1=vorbis_info_blocksize(vi,0)>>(1+hs);
  142093. w1=vorbis_window(&vf->vd,0); /* window arrays from libvorbis are
  142094. persistent; even if the decode state
  142095. from this link gets dumped, this
  142096. window array continues to exist */
  142097. lappcm=(float**) alloca(sizeof(*lappcm)*ch1);
  142098. for(i=0;i<ch1;i++)
  142099. lappcm[i]=(float*) alloca(sizeof(**lappcm)*n1);
  142100. _ov_getlap(vf,vi,&vf->vd,lappcm,n1);
  142101. ret=localseek(vf,pos);
  142102. if(ret)return ret;
  142103. ret=_ov_initprime(vf);
  142104. if(ret)return(ret);
  142105. vi=ov_info(vf,-1);
  142106. ch2=vi->channels;
  142107. n2=vorbis_info_blocksize(vi,0)>>(1+hs);
  142108. w2=vorbis_window(&vf->vd,0);
  142109. vorbis_synthesis_lapout(&vf->vd,&pcm);
  142110. _ov_splice(pcm,lappcm,n1,n2,ch1,ch2,w1,w2);
  142111. return(0);
  142112. }
  142113. int ov_time_seek_lap(OggVorbis_File *vf,double pos){
  142114. return _ov_d_seek_lap(vf,pos,ov_time_seek);
  142115. }
  142116. int ov_time_seek_page_lap(OggVorbis_File *vf,double pos){
  142117. return _ov_d_seek_lap(vf,pos,ov_time_seek_page);
  142118. }
  142119. #endif
  142120. /*** End of inlined file: vorbisfile.c ***/
  142121. /*** Start of inlined file: window.c ***/
  142122. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  142123. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  142124. // tasks..
  142125. #if JUCE_MSVC
  142126. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  142127. #endif
  142128. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  142129. #if JUCE_USE_OGGVORBIS
  142130. #include <stdlib.h>
  142131. #include <math.h>
  142132. static float vwin64[32] = {
  142133. 0.0009460463F, 0.0085006468F, 0.0235352254F, 0.0458950567F,
  142134. 0.0753351908F, 0.1115073077F, 0.1539457973F, 0.2020557475F,
  142135. 0.2551056759F, 0.3122276645F, 0.3724270287F, 0.4346027792F,
  142136. 0.4975789974F, 0.5601459521F, 0.6211085051F, 0.6793382689F,
  142137. 0.7338252629F, 0.7837245849F, 0.8283939355F, 0.8674186656F,
  142138. 0.9006222429F, 0.9280614787F, 0.9500073081F, 0.9669131782F,
  142139. 0.9793740220F, 0.9880792941F, 0.9937636139F, 0.9971582668F,
  142140. 0.9989462667F, 0.9997230082F, 0.9999638688F, 0.9999995525F,
  142141. };
  142142. static float vwin128[64] = {
  142143. 0.0002365472F, 0.0021280687F, 0.0059065254F, 0.0115626550F,
  142144. 0.0190823442F, 0.0284463735F, 0.0396300935F, 0.0526030430F,
  142145. 0.0673285281F, 0.0837631763F, 0.1018564887F, 0.1215504095F,
  142146. 0.1427789367F, 0.1654677960F, 0.1895342001F, 0.2148867160F,
  142147. 0.2414252576F, 0.2690412240F, 0.2976177952F, 0.3270303960F,
  142148. 0.3571473350F, 0.3878306189F, 0.4189369387F, 0.4503188188F,
  142149. 0.4818259135F, 0.5133064334F, 0.5446086751F, 0.5755826278F,
  142150. 0.6060816248F, 0.6359640047F, 0.6650947483F, 0.6933470543F,
  142151. 0.7206038179F, 0.7467589810F, 0.7717187213F, 0.7954024542F,
  142152. 0.8177436264F, 0.8386902831F, 0.8582053981F, 0.8762669622F,
  142153. 0.8928678298F, 0.9080153310F, 0.9217306608F, 0.9340480615F,
  142154. 0.9450138200F, 0.9546851041F, 0.9631286621F, 0.9704194171F,
  142155. 0.9766389810F, 0.9818741197F, 0.9862151938F, 0.9897546035F,
  142156. 0.9925852598F, 0.9947991032F, 0.9964856900F, 0.9977308602F,
  142157. 0.9986155015F, 0.9992144193F, 0.9995953200F, 0.9998179155F,
  142158. 0.9999331503F, 0.9999825563F, 0.9999977357F, 0.9999999720F,
  142159. };
  142160. static float vwin256[128] = {
  142161. 0.0000591390F, 0.0005321979F, 0.0014780301F, 0.0028960636F,
  142162. 0.0047854363F, 0.0071449926F, 0.0099732775F, 0.0132685298F,
  142163. 0.0170286741F, 0.0212513119F, 0.0259337111F, 0.0310727950F,
  142164. 0.0366651302F, 0.0427069140F, 0.0491939614F, 0.0561216907F,
  142165. 0.0634851102F, 0.0712788035F, 0.0794969160F, 0.0881331402F,
  142166. 0.0971807028F, 0.1066323515F, 0.1164803426F, 0.1267164297F,
  142167. 0.1373318534F, 0.1483173323F, 0.1596630553F, 0.1713586755F,
  142168. 0.1833933062F, 0.1957555184F, 0.2084333404F, 0.2214142599F,
  142169. 0.2346852280F, 0.2482326664F, 0.2620424757F, 0.2761000481F,
  142170. 0.2903902813F, 0.3048975959F, 0.3196059553F, 0.3344988887F,
  142171. 0.3495595160F, 0.3647705766F, 0.3801144597F, 0.3955732382F,
  142172. 0.4111287047F, 0.4267624093F, 0.4424557009F, 0.4581897696F,
  142173. 0.4739456913F, 0.4897044744F, 0.5054471075F, 0.5211546088F,
  142174. 0.5368080763F, 0.5523887395F, 0.5678780103F, 0.5832575361F,
  142175. 0.5985092508F, 0.6136154277F, 0.6285587300F, 0.6433222619F,
  142176. 0.6578896175F, 0.6722449294F, 0.6863729144F, 0.7002589187F,
  142177. 0.7138889597F, 0.7272497662F, 0.7403288154F, 0.7531143679F,
  142178. 0.7655954985F, 0.7777621249F, 0.7896050322F, 0.8011158947F,
  142179. 0.8122872932F, 0.8231127294F, 0.8335866365F, 0.8437043850F,
  142180. 0.8534622861F, 0.8628575905F, 0.8718884835F, 0.8805540765F,
  142181. 0.8888543947F, 0.8967903616F, 0.9043637797F, 0.9115773078F,
  142182. 0.9184344360F, 0.9249394562F, 0.9310974312F, 0.9369141608F,
  142183. 0.9423961446F, 0.9475505439F, 0.9523851406F, 0.9569082947F,
  142184. 0.9611289005F, 0.9650563408F, 0.9687004405F, 0.9720714191F,
  142185. 0.9751798427F, 0.9780365753F, 0.9806527301F, 0.9830396204F,
  142186. 0.9852087111F, 0.9871715701F, 0.9889398207F, 0.9905250941F,
  142187. 0.9919389832F, 0.9931929973F, 0.9942985174F, 0.9952667537F,
  142188. 0.9961087037F, 0.9968351119F, 0.9974564312F, 0.9979827858F,
  142189. 0.9984239359F, 0.9987892441F, 0.9990876435F, 0.9993276081F,
  142190. 0.9995171241F, 0.9996636648F, 0.9997741654F, 0.9998550016F,
  142191. 0.9999119692F, 0.9999502656F, 0.9999744742F, 0.9999885497F,
  142192. 0.9999958064F, 0.9999989077F, 0.9999998584F, 0.9999999983F,
  142193. };
  142194. static float vwin512[256] = {
  142195. 0.0000147849F, 0.0001330607F, 0.0003695946F, 0.0007243509F,
  142196. 0.0011972759F, 0.0017882983F, 0.0024973285F, 0.0033242588F,
  142197. 0.0042689632F, 0.0053312973F, 0.0065110982F, 0.0078081841F,
  142198. 0.0092223540F, 0.0107533880F, 0.0124010466F, 0.0141650703F,
  142199. 0.0160451800F, 0.0180410758F, 0.0201524373F, 0.0223789233F,
  142200. 0.0247201710F, 0.0271757958F, 0.0297453914F, 0.0324285286F,
  142201. 0.0352247556F, 0.0381335972F, 0.0411545545F, 0.0442871045F,
  142202. 0.0475306997F, 0.0508847676F, 0.0543487103F, 0.0579219038F,
  142203. 0.0616036982F, 0.0653934164F, 0.0692903546F, 0.0732937809F,
  142204. 0.0774029356F, 0.0816170305F, 0.0859352485F, 0.0903567428F,
  142205. 0.0948806375F, 0.0995060259F, 0.1042319712F, 0.1090575056F,
  142206. 0.1139816300F, 0.1190033137F, 0.1241214941F, 0.1293350764F,
  142207. 0.1346429333F, 0.1400439046F, 0.1455367974F, 0.1511203852F,
  142208. 0.1567934083F, 0.1625545735F, 0.1684025537F, 0.1743359881F,
  142209. 0.1803534820F, 0.1864536069F, 0.1926349000F, 0.1988958650F,
  142210. 0.2052349715F, 0.2116506555F, 0.2181413191F, 0.2247053313F,
  142211. 0.2313410275F, 0.2380467105F, 0.2448206500F, 0.2516610835F,
  142212. 0.2585662164F, 0.2655342226F, 0.2725632448F, 0.2796513950F,
  142213. 0.2867967551F, 0.2939973773F, 0.3012512852F, 0.3085564739F,
  142214. 0.3159109111F, 0.3233125375F, 0.3307592680F, 0.3382489922F,
  142215. 0.3457795756F, 0.3533488602F, 0.3609546657F, 0.3685947904F,
  142216. 0.3762670121F, 0.3839690896F, 0.3916987634F, 0.3994537572F,
  142217. 0.4072317788F, 0.4150305215F, 0.4228476653F, 0.4306808783F,
  142218. 0.4385278181F, 0.4463861329F, 0.4542534630F, 0.4621274424F,
  142219. 0.4700057001F, 0.4778858615F, 0.4857655502F, 0.4936423891F,
  142220. 0.5015140023F, 0.5093780165F, 0.5172320626F, 0.5250737772F,
  142221. 0.5329008043F, 0.5407107971F, 0.5485014192F, 0.5562703465F,
  142222. 0.5640152688F, 0.5717338914F, 0.5794239366F, 0.5870831457F,
  142223. 0.5947092801F, 0.6023001235F, 0.6098534829F, 0.6173671907F,
  142224. 0.6248391059F, 0.6322671161F, 0.6396491384F, 0.6469831217F,
  142225. 0.6542670475F, 0.6614989319F, 0.6686768267F, 0.6757988210F,
  142226. 0.6828630426F, 0.6898676592F, 0.6968108799F, 0.7036909564F,
  142227. 0.7105061843F, 0.7172549043F, 0.7239355032F, 0.7305464154F,
  142228. 0.7370861235F, 0.7435531598F, 0.7499461068F, 0.7562635986F,
  142229. 0.7625043214F, 0.7686670148F, 0.7747504721F, 0.7807535410F,
  142230. 0.7866751247F, 0.7925141825F, 0.7982697296F, 0.8039408387F,
  142231. 0.8095266395F, 0.8150263196F, 0.8204391248F, 0.8257643590F,
  142232. 0.8310013848F, 0.8361496236F, 0.8412085555F, 0.8461777194F,
  142233. 0.8510567129F, 0.8558451924F, 0.8605428730F, 0.8651495278F,
  142234. 0.8696649882F, 0.8740891432F, 0.8784219392F, 0.8826633797F,
  142235. 0.8868135244F, 0.8908724888F, 0.8948404441F, 0.8987176157F,
  142236. 0.9025042831F, 0.9062007791F, 0.9098074886F, 0.9133248482F,
  142237. 0.9167533451F, 0.9200935163F, 0.9233459472F, 0.9265112712F,
  142238. 0.9295901680F, 0.9325833632F, 0.9354916263F, 0.9383157705F,
  142239. 0.9410566504F, 0.9437151618F, 0.9462922398F, 0.9487888576F,
  142240. 0.9512060252F, 0.9535447882F, 0.9558062262F, 0.9579914516F,
  142241. 0.9601016078F, 0.9621378683F, 0.9641014348F, 0.9659935361F,
  142242. 0.9678154261F, 0.9695683830F, 0.9712537071F, 0.9728727198F,
  142243. 0.9744267618F, 0.9759171916F, 0.9773453842F, 0.9787127293F,
  142244. 0.9800206298F, 0.9812705006F, 0.9824637665F, 0.9836018613F,
  142245. 0.9846862258F, 0.9857183066F, 0.9866995544F, 0.9876314227F,
  142246. 0.9885153662F, 0.9893528393F, 0.9901452948F, 0.9908941823F,
  142247. 0.9916009470F, 0.9922670279F, 0.9928938570F, 0.9934828574F,
  142248. 0.9940354423F, 0.9945530133F, 0.9950369595F, 0.9954886562F,
  142249. 0.9959094633F, 0.9963007242F, 0.9966637649F, 0.9969998925F,
  142250. 0.9973103939F, 0.9975965351F, 0.9978595598F, 0.9981006885F,
  142251. 0.9983211172F, 0.9985220166F, 0.9987045311F, 0.9988697776F,
  142252. 0.9990188449F, 0.9991527924F, 0.9992726499F, 0.9993794157F,
  142253. 0.9994740570F, 0.9995575079F, 0.9996306699F, 0.9996944099F,
  142254. 0.9997495605F, 0.9997969190F, 0.9998372465F, 0.9998712678F,
  142255. 0.9998996704F, 0.9999231041F, 0.9999421807F, 0.9999574732F,
  142256. 0.9999695157F, 0.9999788026F, 0.9999857885F, 0.9999908879F,
  142257. 0.9999944746F, 0.9999968817F, 0.9999984010F, 0.9999992833F,
  142258. 0.9999997377F, 0.9999999317F, 0.9999999911F, 0.9999999999F,
  142259. };
  142260. static float vwin1024[512] = {
  142261. 0.0000036962F, 0.0000332659F, 0.0000924041F, 0.0001811086F,
  142262. 0.0002993761F, 0.0004472021F, 0.0006245811F, 0.0008315063F,
  142263. 0.0010679699F, 0.0013339631F, 0.0016294757F, 0.0019544965F,
  142264. 0.0023090133F, 0.0026930125F, 0.0031064797F, 0.0035493989F,
  142265. 0.0040217533F, 0.0045235250F, 0.0050546946F, 0.0056152418F,
  142266. 0.0062051451F, 0.0068243817F, 0.0074729278F, 0.0081507582F,
  142267. 0.0088578466F, 0.0095941655F, 0.0103596863F, 0.0111543789F,
  142268. 0.0119782122F, 0.0128311538F, 0.0137131701F, 0.0146242260F,
  142269. 0.0155642855F, 0.0165333111F, 0.0175312640F, 0.0185581042F,
  142270. 0.0196137903F, 0.0206982797F, 0.0218115284F, 0.0229534910F,
  142271. 0.0241241208F, 0.0253233698F, 0.0265511886F, 0.0278075263F,
  142272. 0.0290923308F, 0.0304055484F, 0.0317471241F, 0.0331170013F,
  142273. 0.0345151222F, 0.0359414274F, 0.0373958560F, 0.0388783456F,
  142274. 0.0403888325F, 0.0419272511F, 0.0434935347F, 0.0450876148F,
  142275. 0.0467094213F, 0.0483588828F, 0.0500359261F, 0.0517404765F,
  142276. 0.0534724575F, 0.0552317913F, 0.0570183983F, 0.0588321971F,
  142277. 0.0606731048F, 0.0625410369F, 0.0644359070F, 0.0663576272F,
  142278. 0.0683061077F, 0.0702812571F, 0.0722829821F, 0.0743111878F,
  142279. 0.0763657775F, 0.0784466526F, 0.0805537129F, 0.0826868561F,
  142280. 0.0848459782F, 0.0870309736F, 0.0892417345F, 0.0914781514F,
  142281. 0.0937401128F, 0.0960275056F, 0.0983402145F, 0.1006781223F,
  142282. 0.1030411101F, 0.1054290568F, 0.1078418397F, 0.1102793336F,
  142283. 0.1127414119F, 0.1152279457F, 0.1177388042F, 0.1202738544F,
  142284. 0.1228329618F, 0.1254159892F, 0.1280227980F, 0.1306532471F,
  142285. 0.1333071937F, 0.1359844927F, 0.1386849970F, 0.1414085575F,
  142286. 0.1441550230F, 0.1469242403F, 0.1497160539F, 0.1525303063F,
  142287. 0.1553668381F, 0.1582254875F, 0.1611060909F, 0.1640084822F,
  142288. 0.1669324936F, 0.1698779549F, 0.1728446939F, 0.1758325362F,
  142289. 0.1788413055F, 0.1818708232F, 0.1849209084F, 0.1879913785F,
  142290. 0.1910820485F, 0.1941927312F, 0.1973232376F, 0.2004733764F,
  142291. 0.2036429541F, 0.2068317752F, 0.2100396421F, 0.2132663552F,
  142292. 0.2165117125F, 0.2197755102F, 0.2230575422F, 0.2263576007F,
  142293. 0.2296754753F, 0.2330109540F, 0.2363638225F, 0.2397338646F,
  142294. 0.2431208619F, 0.2465245941F, 0.2499448389F, 0.2533813719F,
  142295. 0.2568339669F, 0.2603023956F, 0.2637864277F, 0.2672858312F,
  142296. 0.2708003718F, 0.2743298135F, 0.2778739186F, 0.2814324472F,
  142297. 0.2850051576F, 0.2885918065F, 0.2921921485F, 0.2958059366F,
  142298. 0.2994329219F, 0.3030728538F, 0.3067254799F, 0.3103905462F,
  142299. 0.3140677969F, 0.3177569747F, 0.3214578205F, 0.3251700736F,
  142300. 0.3288934718F, 0.3326277513F, 0.3363726468F, 0.3401278914F,
  142301. 0.3438932168F, 0.3476683533F, 0.3514530297F, 0.3552469734F,
  142302. 0.3590499106F, 0.3628615659F, 0.3666816630F, 0.3705099239F,
  142303. 0.3743460698F, 0.3781898204F, 0.3820408945F, 0.3858990095F,
  142304. 0.3897638820F, 0.3936352274F, 0.3975127601F, 0.4013961936F,
  142305. 0.4052852405F, 0.4091796123F, 0.4130790198F, 0.4169831732F,
  142306. 0.4208917815F, 0.4248045534F, 0.4287211965F, 0.4326414181F,
  142307. 0.4365649248F, 0.4404914225F, 0.4444206167F, 0.4483522125F,
  142308. 0.4522859146F, 0.4562214270F, 0.4601584538F, 0.4640966984F,
  142309. 0.4680358644F, 0.4719756548F, 0.4759157726F, 0.4798559209F,
  142310. 0.4837958024F, 0.4877351199F, 0.4916735765F, 0.4956108751F,
  142311. 0.4995467188F, 0.5034808109F, 0.5074128550F, 0.5113425550F,
  142312. 0.5152696149F, 0.5191937395F, 0.5231146336F, 0.5270320028F,
  142313. 0.5309455530F, 0.5348549910F, 0.5387600239F, 0.5426603597F,
  142314. 0.5465557070F, 0.5504457754F, 0.5543302752F, 0.5582089175F,
  142315. 0.5620814145F, 0.5659474793F, 0.5698068262F, 0.5736591704F,
  142316. 0.5775042283F, 0.5813417176F, 0.5851713571F, 0.5889928670F,
  142317. 0.5928059689F, 0.5966103856F, 0.6004058415F, 0.6041920626F,
  142318. 0.6079687761F, 0.6117357113F, 0.6154925986F, 0.6192391705F,
  142319. 0.6229751612F, 0.6267003064F, 0.6304143441F, 0.6341170137F,
  142320. 0.6378080569F, 0.6414872173F, 0.6451542405F, 0.6488088741F,
  142321. 0.6524508681F, 0.6560799742F, 0.6596959469F, 0.6632985424F,
  142322. 0.6668875197F, 0.6704626398F, 0.6740236662F, 0.6775703649F,
  142323. 0.6811025043F, 0.6846198554F, 0.6881221916F, 0.6916092892F,
  142324. 0.6950809269F, 0.6985368861F, 0.7019769510F, 0.7054009085F,
  142325. 0.7088085484F, 0.7121996632F, 0.7155740484F, 0.7189315023F,
  142326. 0.7222718263F, 0.7255948245F, 0.7289003043F, 0.7321880760F,
  142327. 0.7354579530F, 0.7387097518F, 0.7419432921F, 0.7451583966F,
  142328. 0.7483548915F, 0.7515326059F, 0.7546913723F, 0.7578310265F,
  142329. 0.7609514077F, 0.7640523581F, 0.7671337237F, 0.7701953535F,
  142330. 0.7732371001F, 0.7762588195F, 0.7792603711F, 0.7822416178F,
  142331. 0.7852024259F, 0.7881426654F, 0.7910622097F, 0.7939609356F,
  142332. 0.7968387237F, 0.7996954579F, 0.8025310261F, 0.8053453193F,
  142333. 0.8081382324F, 0.8109096638F, 0.8136595156F, 0.8163876936F,
  142334. 0.8190941071F, 0.8217786690F, 0.8244412960F, 0.8270819086F,
  142335. 0.8297004305F, 0.8322967896F, 0.8348709171F, 0.8374227481F,
  142336. 0.8399522213F, 0.8424592789F, 0.8449438672F, 0.8474059356F,
  142337. 0.8498454378F, 0.8522623306F, 0.8546565748F, 0.8570281348F,
  142338. 0.8593769787F, 0.8617030779F, 0.8640064080F, 0.8662869477F,
  142339. 0.8685446796F, 0.8707795899F, 0.8729916682F, 0.8751809079F,
  142340. 0.8773473059F, 0.8794908626F, 0.8816115819F, 0.8837094713F,
  142341. 0.8857845418F, 0.8878368079F, 0.8898662874F, 0.8918730019F,
  142342. 0.8938569760F, 0.8958182380F, 0.8977568194F, 0.8996727552F,
  142343. 0.9015660837F, 0.9034368465F, 0.9052850885F, 0.9071108577F,
  142344. 0.9089142057F, 0.9106951869F, 0.9124538591F, 0.9141902832F,
  142345. 0.9159045233F, 0.9175966464F, 0.9192667228F, 0.9209148257F,
  142346. 0.9225410313F, 0.9241454187F, 0.9257280701F, 0.9272890704F,
  142347. 0.9288285075F, 0.9303464720F, 0.9318430576F, 0.9333183603F,
  142348. 0.9347724792F, 0.9362055158F, 0.9376175745F, 0.9390087622F,
  142349. 0.9403791881F, 0.9417289644F, 0.9430582055F, 0.9443670283F,
  142350. 0.9456555521F, 0.9469238986F, 0.9481721917F, 0.9494005577F,
  142351. 0.9506091252F, 0.9517980248F, 0.9529673894F, 0.9541173540F,
  142352. 0.9552480557F, 0.9563596334F, 0.9574522282F, 0.9585259830F,
  142353. 0.9595810428F, 0.9606175542F, 0.9616356656F, 0.9626355274F,
  142354. 0.9636172915F, 0.9645811114F, 0.9655271425F, 0.9664555414F,
  142355. 0.9673664664F, 0.9682600774F, 0.9691365355F, 0.9699960034F,
  142356. 0.9708386448F, 0.9716646250F, 0.9724741103F, 0.9732672685F,
  142357. 0.9740442683F, 0.9748052795F, 0.9755504729F, 0.9762800205F,
  142358. 0.9769940950F, 0.9776928703F, 0.9783765210F, 0.9790452223F,
  142359. 0.9796991504F, 0.9803384823F, 0.9809633954F, 0.9815740679F,
  142360. 0.9821706784F, 0.9827534063F, 0.9833224312F, 0.9838779332F,
  142361. 0.9844200928F, 0.9849490910F, 0.9854651087F, 0.9859683274F,
  142362. 0.9864589286F, 0.9869370940F, 0.9874030054F, 0.9878568447F,
  142363. 0.9882987937F, 0.9887290343F, 0.9891477481F, 0.9895551169F,
  142364. 0.9899513220F, 0.9903365446F, 0.9907109658F, 0.9910747662F,
  142365. 0.9914281260F, 0.9917712252F, 0.9921042433F, 0.9924273593F,
  142366. 0.9927407516F, 0.9930445982F, 0.9933390763F, 0.9936243626F,
  142367. 0.9939006331F, 0.9941680631F, 0.9944268269F, 0.9946770982F,
  142368. 0.9949190498F, 0.9951528537F, 0.9953786808F, 0.9955967011F,
  142369. 0.9958070836F, 0.9960099963F, 0.9962056061F, 0.9963940787F,
  142370. 0.9965755786F, 0.9967502693F, 0.9969183129F, 0.9970798704F,
  142371. 0.9972351013F, 0.9973841640F, 0.9975272151F, 0.9976644103F,
  142372. 0.9977959036F, 0.9979218476F, 0.9980423932F, 0.9981576901F,
  142373. 0.9982678862F, 0.9983731278F, 0.9984735596F, 0.9985693247F,
  142374. 0.9986605645F, 0.9987474186F, 0.9988300248F, 0.9989085193F,
  142375. 0.9989830364F, 0.9990537085F, 0.9991206662F, 0.9991840382F,
  142376. 0.9992439513F, 0.9993005303F, 0.9993538982F, 0.9994041757F,
  142377. 0.9994514817F, 0.9994959330F, 0.9995376444F, 0.9995767286F,
  142378. 0.9996132960F, 0.9996474550F, 0.9996793121F, 0.9997089710F,
  142379. 0.9997365339F, 0.9997621003F, 0.9997857677F, 0.9998076311F,
  142380. 0.9998277836F, 0.9998463156F, 0.9998633155F, 0.9998788692F,
  142381. 0.9998930603F, 0.9999059701F, 0.9999176774F, 0.9999282586F,
  142382. 0.9999377880F, 0.9999463370F, 0.9999539749F, 0.9999607685F,
  142383. 0.9999667820F, 0.9999720773F, 0.9999767136F, 0.9999807479F,
  142384. 0.9999842344F, 0.9999872249F, 0.9999897688F, 0.9999919127F,
  142385. 0.9999937009F, 0.9999951749F, 0.9999963738F, 0.9999973342F,
  142386. 0.9999980900F, 0.9999986724F, 0.9999991103F, 0.9999994297F,
  142387. 0.9999996543F, 0.9999998049F, 0.9999999000F, 0.9999999552F,
  142388. 0.9999999836F, 0.9999999957F, 0.9999999994F, 1.0000000000F,
  142389. };
  142390. static float vwin2048[1024] = {
  142391. 0.0000009241F, 0.0000083165F, 0.0000231014F, 0.0000452785F,
  142392. 0.0000748476F, 0.0001118085F, 0.0001561608F, 0.0002079041F,
  142393. 0.0002670379F, 0.0003335617F, 0.0004074748F, 0.0004887765F,
  142394. 0.0005774661F, 0.0006735427F, 0.0007770054F, 0.0008878533F,
  142395. 0.0010060853F, 0.0011317002F, 0.0012646969F, 0.0014050742F,
  142396. 0.0015528307F, 0.0017079650F, 0.0018704756F, 0.0020403610F,
  142397. 0.0022176196F, 0.0024022497F, 0.0025942495F, 0.0027936173F,
  142398. 0.0030003511F, 0.0032144490F, 0.0034359088F, 0.0036647286F,
  142399. 0.0039009061F, 0.0041444391F, 0.0043953253F, 0.0046535621F,
  142400. 0.0049191472F, 0.0051920781F, 0.0054723520F, 0.0057599664F,
  142401. 0.0060549184F, 0.0063572052F, 0.0066668239F, 0.0069837715F,
  142402. 0.0073080449F, 0.0076396410F, 0.0079785566F, 0.0083247884F,
  142403. 0.0086783330F, 0.0090391871F, 0.0094073470F, 0.0097828092F,
  142404. 0.0101655700F, 0.0105556258F, 0.0109529726F, 0.0113576065F,
  142405. 0.0117695237F, 0.0121887200F, 0.0126151913F, 0.0130489335F,
  142406. 0.0134899422F, 0.0139382130F, 0.0143937415F, 0.0148565233F,
  142407. 0.0153265536F, 0.0158038279F, 0.0162883413F, 0.0167800889F,
  142408. 0.0172790660F, 0.0177852675F, 0.0182986882F, 0.0188193231F,
  142409. 0.0193471668F, 0.0198822141F, 0.0204244594F, 0.0209738974F,
  142410. 0.0215305225F, 0.0220943289F, 0.0226653109F, 0.0232434627F,
  142411. 0.0238287784F, 0.0244212519F, 0.0250208772F, 0.0256276481F,
  142412. 0.0262415582F, 0.0268626014F, 0.0274907711F, 0.0281260608F,
  142413. 0.0287684638F, 0.0294179736F, 0.0300745833F, 0.0307382859F,
  142414. 0.0314090747F, 0.0320869424F, 0.0327718819F, 0.0334638860F,
  142415. 0.0341629474F, 0.0348690586F, 0.0355822122F, 0.0363024004F,
  142416. 0.0370296157F, 0.0377638502F, 0.0385050960F, 0.0392533451F,
  142417. 0.0400085896F, 0.0407708211F, 0.0415400315F, 0.0423162123F,
  142418. 0.0430993552F, 0.0438894515F, 0.0446864926F, 0.0454904698F,
  142419. 0.0463013742F, 0.0471191969F, 0.0479439288F, 0.0487755607F,
  142420. 0.0496140836F, 0.0504594879F, 0.0513117642F, 0.0521709031F,
  142421. 0.0530368949F, 0.0539097297F, 0.0547893979F, 0.0556758894F,
  142422. 0.0565691941F, 0.0574693019F, 0.0583762026F, 0.0592898858F,
  142423. 0.0602103410F, 0.0611375576F, 0.0620715250F, 0.0630122324F,
  142424. 0.0639596688F, 0.0649138234F, 0.0658746848F, 0.0668422421F,
  142425. 0.0678164838F, 0.0687973985F, 0.0697849746F, 0.0707792005F,
  142426. 0.0717800645F, 0.0727875547F, 0.0738016591F, 0.0748223656F,
  142427. 0.0758496620F, 0.0768835359F, 0.0779239751F, 0.0789709668F,
  142428. 0.0800244985F, 0.0810845574F, 0.0821511306F, 0.0832242052F,
  142429. 0.0843037679F, 0.0853898056F, 0.0864823050F, 0.0875812525F,
  142430. 0.0886866347F, 0.0897984378F, 0.0909166480F, 0.0920412513F,
  142431. 0.0931722338F, 0.0943095813F, 0.0954532795F, 0.0966033140F,
  142432. 0.0977596702F, 0.0989223336F, 0.1000912894F, 0.1012665227F,
  142433. 0.1024480185F, 0.1036357616F, 0.1048297369F, 0.1060299290F,
  142434. 0.1072363224F, 0.1084489014F, 0.1096676504F, 0.1108925534F,
  142435. 0.1121235946F, 0.1133607577F, 0.1146040267F, 0.1158533850F,
  142436. 0.1171088163F, 0.1183703040F, 0.1196378312F, 0.1209113812F,
  142437. 0.1221909370F, 0.1234764815F, 0.1247679974F, 0.1260654674F,
  142438. 0.1273688740F, 0.1286781995F, 0.1299934263F, 0.1313145365F,
  142439. 0.1326415121F, 0.1339743349F, 0.1353129866F, 0.1366574490F,
  142440. 0.1380077035F, 0.1393637315F, 0.1407255141F, 0.1420930325F,
  142441. 0.1434662677F, 0.1448452004F, 0.1462298115F, 0.1476200814F,
  142442. 0.1490159906F, 0.1504175195F, 0.1518246482F, 0.1532373569F,
  142443. 0.1546556253F, 0.1560794333F, 0.1575087606F, 0.1589435866F,
  142444. 0.1603838909F, 0.1618296526F, 0.1632808509F, 0.1647374648F,
  142445. 0.1661994731F, 0.1676668546F, 0.1691395880F, 0.1706176516F,
  142446. 0.1721010238F, 0.1735896829F, 0.1750836068F, 0.1765827736F,
  142447. 0.1780871610F, 0.1795967468F, 0.1811115084F, 0.1826314234F,
  142448. 0.1841564689F, 0.1856866221F, 0.1872218600F, 0.1887621595F,
  142449. 0.1903074974F, 0.1918578503F, 0.1934131947F, 0.1949735068F,
  142450. 0.1965387630F, 0.1981089393F, 0.1996840117F, 0.2012639560F,
  142451. 0.2028487479F, 0.2044383630F, 0.2060327766F, 0.2076319642F,
  142452. 0.2092359007F, 0.2108445614F, 0.2124579211F, 0.2140759545F,
  142453. 0.2156986364F, 0.2173259411F, 0.2189578432F, 0.2205943168F,
  142454. 0.2222353361F, 0.2238808751F, 0.2255309076F, 0.2271854073F,
  142455. 0.2288443480F, 0.2305077030F, 0.2321754457F, 0.2338475493F,
  142456. 0.2355239869F, 0.2372047315F, 0.2388897560F, 0.2405790329F,
  142457. 0.2422725350F, 0.2439702347F, 0.2456721043F, 0.2473781159F,
  142458. 0.2490882418F, 0.2508024539F, 0.2525207240F, 0.2542430237F,
  142459. 0.2559693248F, 0.2576995986F, 0.2594338166F, 0.2611719498F,
  142460. 0.2629139695F, 0.2646598466F, 0.2664095520F, 0.2681630564F,
  142461. 0.2699203304F, 0.2716813445F, 0.2734460691F, 0.2752144744F,
  142462. 0.2769865307F, 0.2787622079F, 0.2805414760F, 0.2823243047F,
  142463. 0.2841106637F, 0.2859005227F, 0.2876938509F, 0.2894906179F,
  142464. 0.2912907928F, 0.2930943447F, 0.2949012426F, 0.2967114554F,
  142465. 0.2985249520F, 0.3003417009F, 0.3021616708F, 0.3039848301F,
  142466. 0.3058111471F, 0.3076405901F, 0.3094731273F, 0.3113087266F,
  142467. 0.3131473560F, 0.3149889833F, 0.3168335762F, 0.3186811024F,
  142468. 0.3205315294F, 0.3223848245F, 0.3242409552F, 0.3260998886F,
  142469. 0.3279615918F, 0.3298260319F, 0.3316931758F, 0.3335629903F,
  142470. 0.3354354423F, 0.3373104982F, 0.3391881247F, 0.3410682882F,
  142471. 0.3429509551F, 0.3448360917F, 0.3467236642F, 0.3486136387F,
  142472. 0.3505059811F, 0.3524006575F, 0.3542976336F, 0.3561968753F,
  142473. 0.3580983482F, 0.3600020179F, 0.3619078499F, 0.3638158096F,
  142474. 0.3657258625F, 0.3676379737F, 0.3695521086F, 0.3714682321F,
  142475. 0.3733863094F, 0.3753063055F, 0.3772281852F, 0.3791519134F,
  142476. 0.3810774548F, 0.3830047742F, 0.3849338362F, 0.3868646053F,
  142477. 0.3887970459F, 0.3907311227F, 0.3926667998F, 0.3946040417F,
  142478. 0.3965428125F, 0.3984830765F, 0.4004247978F, 0.4023679403F,
  142479. 0.4043124683F, 0.4062583455F, 0.4082055359F, 0.4101540034F,
  142480. 0.4121037117F, 0.4140546246F, 0.4160067058F, 0.4179599190F,
  142481. 0.4199142277F, 0.4218695956F, 0.4238259861F, 0.4257833627F,
  142482. 0.4277416888F, 0.4297009279F, 0.4316610433F, 0.4336219983F,
  142483. 0.4355837562F, 0.4375462803F, 0.4395095337F, 0.4414734797F,
  142484. 0.4434380815F, 0.4454033021F, 0.4473691046F, 0.4493354521F,
  142485. 0.4513023078F, 0.4532696345F, 0.4552373954F, 0.4572055533F,
  142486. 0.4591740713F, 0.4611429123F, 0.4631120393F, 0.4650814151F,
  142487. 0.4670510028F, 0.4690207650F, 0.4709906649F, 0.4729606651F,
  142488. 0.4749307287F, 0.4769008185F, 0.4788708972F, 0.4808409279F,
  142489. 0.4828108732F, 0.4847806962F, 0.4867503597F, 0.4887198264F,
  142490. 0.4906890593F, 0.4926580213F, 0.4946266753F, 0.4965949840F,
  142491. 0.4985629105F, 0.5005304176F, 0.5024974683F, 0.5044640255F,
  142492. 0.5064300522F, 0.5083955114F, 0.5103603659F, 0.5123245790F,
  142493. 0.5142881136F, 0.5162509328F, 0.5182129997F, 0.5201742774F,
  142494. 0.5221347290F, 0.5240943178F, 0.5260530070F, 0.5280107598F,
  142495. 0.5299675395F, 0.5319233095F, 0.5338780330F, 0.5358316736F,
  142496. 0.5377841946F, 0.5397355596F, 0.5416857320F, 0.5436346755F,
  142497. 0.5455823538F, 0.5475287304F, 0.5494737691F, 0.5514174337F,
  142498. 0.5533596881F, 0.5553004962F, 0.5572398218F, 0.5591776291F,
  142499. 0.5611138821F, 0.5630485449F, 0.5649815818F, 0.5669129570F,
  142500. 0.5688426349F, 0.5707705799F, 0.5726967564F, 0.5746211290F,
  142501. 0.5765436624F, 0.5784643212F, 0.5803830702F, 0.5822998743F,
  142502. 0.5842146984F, 0.5861275076F, 0.5880382669F, 0.5899469416F,
  142503. 0.5918534968F, 0.5937578981F, 0.5956601107F, 0.5975601004F,
  142504. 0.5994578326F, 0.6013532732F, 0.6032463880F, 0.6051371429F,
  142505. 0.6070255039F, 0.6089114372F, 0.6107949090F, 0.6126758856F,
  142506. 0.6145543334F, 0.6164302191F, 0.6183035092F, 0.6201741706F,
  142507. 0.6220421700F, 0.6239074745F, 0.6257700513F, 0.6276298674F,
  142508. 0.6294868903F, 0.6313410873F, 0.6331924262F, 0.6350408745F,
  142509. 0.6368864001F, 0.6387289710F, 0.6405685552F, 0.6424051209F,
  142510. 0.6442386364F, 0.6460690702F, 0.6478963910F, 0.6497205673F,
  142511. 0.6515415682F, 0.6533593625F, 0.6551739194F, 0.6569852082F,
  142512. 0.6587931984F, 0.6605978593F, 0.6623991609F, 0.6641970728F,
  142513. 0.6659915652F, 0.6677826081F, 0.6695701718F, 0.6713542268F,
  142514. 0.6731347437F, 0.6749116932F, 0.6766850461F, 0.6784547736F,
  142515. 0.6802208469F, 0.6819832374F, 0.6837419164F, 0.6854968559F,
  142516. 0.6872480275F, 0.6889954034F, 0.6907389556F, 0.6924786566F,
  142517. 0.6942144788F, 0.6959463950F, 0.6976743780F, 0.6993984008F,
  142518. 0.7011184365F, 0.7028344587F, 0.7045464407F, 0.7062543564F,
  142519. 0.7079581796F, 0.7096578844F, 0.7113534450F, 0.7130448359F,
  142520. 0.7147320316F, 0.7164150070F, 0.7180937371F, 0.7197681970F,
  142521. 0.7214383620F, 0.7231042077F, 0.7247657098F, 0.7264228443F,
  142522. 0.7280755871F, 0.7297239147F, 0.7313678035F, 0.7330072301F,
  142523. 0.7346421715F, 0.7362726046F, 0.7378985069F, 0.7395198556F,
  142524. 0.7411366285F, 0.7427488034F, 0.7443563584F, 0.7459592717F,
  142525. 0.7475575218F, 0.7491510873F, 0.7507399471F, 0.7523240803F,
  142526. 0.7539034661F, 0.7554780839F, 0.7570479136F, 0.7586129349F,
  142527. 0.7601731279F, 0.7617284730F, 0.7632789506F, 0.7648245416F,
  142528. 0.7663652267F, 0.7679009872F, 0.7694318044F, 0.7709576599F,
  142529. 0.7724785354F, 0.7739944130F, 0.7755052749F, 0.7770111035F,
  142530. 0.7785118815F, 0.7800075916F, 0.7814982170F, 0.7829837410F,
  142531. 0.7844641472F, 0.7859394191F, 0.7874095408F, 0.7888744965F,
  142532. 0.7903342706F, 0.7917888476F, 0.7932382124F, 0.7946823501F,
  142533. 0.7961212460F, 0.7975548855F, 0.7989832544F, 0.8004063386F,
  142534. 0.8018241244F, 0.8032365981F, 0.8046437463F, 0.8060455560F,
  142535. 0.8074420141F, 0.8088331080F, 0.8102188253F, 0.8115991536F,
  142536. 0.8129740810F, 0.8143435957F, 0.8157076861F, 0.8170663409F,
  142537. 0.8184195489F, 0.8197672994F, 0.8211095817F, 0.8224463853F,
  142538. 0.8237777001F, 0.8251035161F, 0.8264238235F, 0.8277386129F,
  142539. 0.8290478750F, 0.8303516008F, 0.8316497814F, 0.8329424083F,
  142540. 0.8342294731F, 0.8355109677F, 0.8367868841F, 0.8380572148F,
  142541. 0.8393219523F, 0.8405810893F, 0.8418346190F, 0.8430825345F,
  142542. 0.8443248294F, 0.8455614974F, 0.8467925323F, 0.8480179285F,
  142543. 0.8492376802F, 0.8504517822F, 0.8516602292F, 0.8528630164F,
  142544. 0.8540601391F, 0.8552515928F, 0.8564373733F, 0.8576174766F,
  142545. 0.8587918990F, 0.8599606368F, 0.8611236868F, 0.8622810460F,
  142546. 0.8634327113F, 0.8645786802F, 0.8657189504F, 0.8668535195F,
  142547. 0.8679823857F, 0.8691055472F, 0.8702230025F, 0.8713347503F,
  142548. 0.8724407896F, 0.8735411194F, 0.8746357394F, 0.8757246489F,
  142549. 0.8768078479F, 0.8778853364F, 0.8789571146F, 0.8800231832F,
  142550. 0.8810835427F, 0.8821381942F, 0.8831871387F, 0.8842303777F,
  142551. 0.8852679127F, 0.8862997456F, 0.8873258784F, 0.8883463132F,
  142552. 0.8893610527F, 0.8903700994F, 0.8913734562F, 0.8923711263F,
  142553. 0.8933631129F, 0.8943494196F, 0.8953300500F, 0.8963050083F,
  142554. 0.8972742985F, 0.8982379249F, 0.8991958922F, 0.9001482052F,
  142555. 0.9010948688F, 0.9020358883F, 0.9029712690F, 0.9039010165F,
  142556. 0.9048251367F, 0.9057436357F, 0.9066565195F, 0.9075637946F,
  142557. 0.9084654678F, 0.9093615456F, 0.9102520353F, 0.9111369440F,
  142558. 0.9120162792F, 0.9128900484F, 0.9137582595F, 0.9146209204F,
  142559. 0.9154780394F, 0.9163296248F, 0.9171756853F, 0.9180162296F,
  142560. 0.9188512667F, 0.9196808057F, 0.9205048559F, 0.9213234270F,
  142561. 0.9221365285F, 0.9229441704F, 0.9237463629F, 0.9245431160F,
  142562. 0.9253344404F, 0.9261203465F, 0.9269008453F, 0.9276759477F,
  142563. 0.9284456648F, 0.9292100080F, 0.9299689889F, 0.9307226190F,
  142564. 0.9314709103F, 0.9322138747F, 0.9329515245F, 0.9336838721F,
  142565. 0.9344109300F, 0.9351327108F, 0.9358492275F, 0.9365604931F,
  142566. 0.9372665208F, 0.9379673239F, 0.9386629160F, 0.9393533107F,
  142567. 0.9400385220F, 0.9407185637F, 0.9413934501F, 0.9420631954F,
  142568. 0.9427278141F, 0.9433873208F, 0.9440417304F, 0.9446910576F,
  142569. 0.9453353176F, 0.9459745255F, 0.9466086968F, 0.9472378469F,
  142570. 0.9478619915F, 0.9484811463F, 0.9490953274F, 0.9497045506F,
  142571. 0.9503088323F, 0.9509081888F, 0.9515026365F, 0.9520921921F,
  142572. 0.9526768723F, 0.9532566940F, 0.9538316742F, 0.9544018300F,
  142573. 0.9549671786F, 0.9555277375F, 0.9560835241F, 0.9566345562F,
  142574. 0.9571808513F, 0.9577224275F, 0.9582593027F, 0.9587914949F,
  142575. 0.9593190225F, 0.9598419038F, 0.9603601571F, 0.9608738012F,
  142576. 0.9613828546F, 0.9618873361F, 0.9623872646F, 0.9628826591F,
  142577. 0.9633735388F, 0.9638599227F, 0.9643418303F, 0.9648192808F,
  142578. 0.9652922939F, 0.9657608890F, 0.9662250860F, 0.9666849046F,
  142579. 0.9671403646F, 0.9675914861F, 0.9680382891F, 0.9684807937F,
  142580. 0.9689190202F, 0.9693529890F, 0.9697827203F, 0.9702082347F,
  142581. 0.9706295529F, 0.9710466953F, 0.9714596828F, 0.9718685362F,
  142582. 0.9722732762F, 0.9726739240F, 0.9730705005F, 0.9734630267F,
  142583. 0.9738515239F, 0.9742360134F, 0.9746165163F, 0.9749930540F,
  142584. 0.9753656481F, 0.9757343198F, 0.9760990909F, 0.9764599829F,
  142585. 0.9768170175F, 0.9771702164F, 0.9775196013F, 0.9778651941F,
  142586. 0.9782070167F, 0.9785450909F, 0.9788794388F, 0.9792100824F,
  142587. 0.9795370437F, 0.9798603449F, 0.9801800080F, 0.9804960554F,
  142588. 0.9808085092F, 0.9811173916F, 0.9814227251F, 0.9817245318F,
  142589. 0.9820228343F, 0.9823176549F, 0.9826090160F, 0.9828969402F,
  142590. 0.9831814498F, 0.9834625674F, 0.9837403156F, 0.9840147169F,
  142591. 0.9842857939F, 0.9845535692F, 0.9848180654F, 0.9850793052F,
  142592. 0.9853373113F, 0.9855921062F, 0.9858437127F, 0.9860921535F,
  142593. 0.9863374512F, 0.9865796287F, 0.9868187085F, 0.9870547136F,
  142594. 0.9872876664F, 0.9875175899F, 0.9877445067F, 0.9879684396F,
  142595. 0.9881894112F, 0.9884074444F, 0.9886225619F, 0.9888347863F,
  142596. 0.9890441404F, 0.9892506468F, 0.9894543284F, 0.9896552077F,
  142597. 0.9898533074F, 0.9900486502F, 0.9902412587F, 0.9904311555F,
  142598. 0.9906183633F, 0.9908029045F, 0.9909848019F, 0.9911640779F,
  142599. 0.9913407550F, 0.9915148557F, 0.9916864025F, 0.9918554179F,
  142600. 0.9920219241F, 0.9921859437F, 0.9923474989F, 0.9925066120F,
  142601. 0.9926633054F, 0.9928176012F, 0.9929695218F, 0.9931190891F,
  142602. 0.9932663254F, 0.9934112527F, 0.9935538932F, 0.9936942686F,
  142603. 0.9938324012F, 0.9939683126F, 0.9941020248F, 0.9942335597F,
  142604. 0.9943629388F, 0.9944901841F, 0.9946153170F, 0.9947383593F,
  142605. 0.9948593325F, 0.9949782579F, 0.9950951572F, 0.9952100516F,
  142606. 0.9953229625F, 0.9954339111F, 0.9955429186F, 0.9956500062F,
  142607. 0.9957551948F, 0.9958585056F, 0.9959599593F, 0.9960595769F,
  142608. 0.9961573792F, 0.9962533869F, 0.9963476206F, 0.9964401009F,
  142609. 0.9965308483F, 0.9966198833F, 0.9967072261F, 0.9967928971F,
  142610. 0.9968769164F, 0.9969593041F, 0.9970400804F, 0.9971192651F,
  142611. 0.9971968781F, 0.9972729391F, 0.9973474680F, 0.9974204842F,
  142612. 0.9974920074F, 0.9975620569F, 0.9976306521F, 0.9976978122F,
  142613. 0.9977635565F, 0.9978279039F, 0.9978908736F, 0.9979524842F,
  142614. 0.9980127547F, 0.9980717037F, 0.9981293499F, 0.9981857116F,
  142615. 0.9982408073F, 0.9982946554F, 0.9983472739F, 0.9983986810F,
  142616. 0.9984488947F, 0.9984979328F, 0.9985458132F, 0.9985925534F,
  142617. 0.9986381711F, 0.9986826838F, 0.9987261086F, 0.9987684630F,
  142618. 0.9988097640F, 0.9988500286F, 0.9988892738F, 0.9989275163F,
  142619. 0.9989647727F, 0.9990010597F, 0.9990363938F, 0.9990707911F,
  142620. 0.9991042679F, 0.9991368404F, 0.9991685244F, 0.9991993358F,
  142621. 0.9992292905F, 0.9992584038F, 0.9992866914F, 0.9993141686F,
  142622. 0.9993408506F, 0.9993667526F, 0.9993918895F, 0.9994162761F,
  142623. 0.9994399273F, 0.9994628576F, 0.9994850815F, 0.9995066133F,
  142624. 0.9995274672F, 0.9995476574F, 0.9995671978F, 0.9995861021F,
  142625. 0.9996043841F, 0.9996220573F, 0.9996391352F, 0.9996556310F,
  142626. 0.9996715579F, 0.9996869288F, 0.9997017568F, 0.9997160543F,
  142627. 0.9997298342F, 0.9997431088F, 0.9997558905F, 0.9997681914F,
  142628. 0.9997800236F, 0.9997913990F, 0.9998023292F, 0.9998128261F,
  142629. 0.9998229009F, 0.9998325650F, 0.9998418296F, 0.9998507058F,
  142630. 0.9998592044F, 0.9998673362F, 0.9998751117F, 0.9998825415F,
  142631. 0.9998896358F, 0.9998964047F, 0.9999028584F, 0.9999090066F,
  142632. 0.9999148590F, 0.9999204253F, 0.9999257148F, 0.9999307368F,
  142633. 0.9999355003F, 0.9999400144F, 0.9999442878F, 0.9999483293F,
  142634. 0.9999521472F, 0.9999557499F, 0.9999591457F, 0.9999623426F,
  142635. 0.9999653483F, 0.9999681708F, 0.9999708175F, 0.9999732959F,
  142636. 0.9999756132F, 0.9999777765F, 0.9999797928F, 0.9999816688F,
  142637. 0.9999834113F, 0.9999850266F, 0.9999865211F, 0.9999879009F,
  142638. 0.9999891721F, 0.9999903405F, 0.9999914118F, 0.9999923914F,
  142639. 0.9999932849F, 0.9999940972F, 0.9999948336F, 0.9999954989F,
  142640. 0.9999960978F, 0.9999966349F, 0.9999971146F, 0.9999975411F,
  142641. 0.9999979185F, 0.9999982507F, 0.9999985414F, 0.9999987944F,
  142642. 0.9999990129F, 0.9999992003F, 0.9999993596F, 0.9999994939F,
  142643. 0.9999996059F, 0.9999996981F, 0.9999997732F, 0.9999998333F,
  142644. 0.9999998805F, 0.9999999170F, 0.9999999444F, 0.9999999643F,
  142645. 0.9999999784F, 0.9999999878F, 0.9999999937F, 0.9999999972F,
  142646. 0.9999999990F, 0.9999999997F, 1.0000000000F, 1.0000000000F,
  142647. };
  142648. static float vwin4096[2048] = {
  142649. 0.0000002310F, 0.0000020791F, 0.0000057754F, 0.0000113197F,
  142650. 0.0000187121F, 0.0000279526F, 0.0000390412F, 0.0000519777F,
  142651. 0.0000667623F, 0.0000833949F, 0.0001018753F, 0.0001222036F,
  142652. 0.0001443798F, 0.0001684037F, 0.0001942754F, 0.0002219947F,
  142653. 0.0002515616F, 0.0002829761F, 0.0003162380F, 0.0003513472F,
  142654. 0.0003883038F, 0.0004271076F, 0.0004677584F, 0.0005102563F,
  142655. 0.0005546011F, 0.0006007928F, 0.0006488311F, 0.0006987160F,
  142656. 0.0007504474F, 0.0008040251F, 0.0008594490F, 0.0009167191F,
  142657. 0.0009758351F, 0.0010367969F, 0.0010996044F, 0.0011642574F,
  142658. 0.0012307558F, 0.0012990994F, 0.0013692880F, 0.0014413216F,
  142659. 0.0015151998F, 0.0015909226F, 0.0016684898F, 0.0017479011F,
  142660. 0.0018291565F, 0.0019122556F, 0.0019971983F, 0.0020839845F,
  142661. 0.0021726138F, 0.0022630861F, 0.0023554012F, 0.0024495588F,
  142662. 0.0025455588F, 0.0026434008F, 0.0027430847F, 0.0028446103F,
  142663. 0.0029479772F, 0.0030531853F, 0.0031602342F, 0.0032691238F,
  142664. 0.0033798538F, 0.0034924239F, 0.0036068338F, 0.0037230833F,
  142665. 0.0038411721F, 0.0039610999F, 0.0040828664F, 0.0042064714F,
  142666. 0.0043319145F, 0.0044591954F, 0.0045883139F, 0.0047192696F,
  142667. 0.0048520622F, 0.0049866914F, 0.0051231569F, 0.0052614583F,
  142668. 0.0054015953F, 0.0055435676F, 0.0056873748F, 0.0058330166F,
  142669. 0.0059804926F, 0.0061298026F, 0.0062809460F, 0.0064339226F,
  142670. 0.0065887320F, 0.0067453738F, 0.0069038476F, 0.0070641531F,
  142671. 0.0072262899F, 0.0073902575F, 0.0075560556F, 0.0077236838F,
  142672. 0.0078931417F, 0.0080644288F, 0.0082375447F, 0.0084124891F,
  142673. 0.0085892615F, 0.0087678614F, 0.0089482885F, 0.0091305422F,
  142674. 0.0093146223F, 0.0095005281F, 0.0096882592F, 0.0098778153F,
  142675. 0.0100691958F, 0.0102624002F, 0.0104574281F, 0.0106542791F,
  142676. 0.0108529525F, 0.0110534480F, 0.0112557651F, 0.0114599032F,
  142677. 0.0116658618F, 0.0118736405F, 0.0120832387F, 0.0122946560F,
  142678. 0.0125078917F, 0.0127229454F, 0.0129398166F, 0.0131585046F,
  142679. 0.0133790090F, 0.0136013292F, 0.0138254647F, 0.0140514149F,
  142680. 0.0142791792F, 0.0145087572F, 0.0147401481F, 0.0149733515F,
  142681. 0.0152083667F, 0.0154451932F, 0.0156838304F, 0.0159242777F,
  142682. 0.0161665345F, 0.0164106001F, 0.0166564741F, 0.0169041557F,
  142683. 0.0171536443F, 0.0174049393F, 0.0176580401F, 0.0179129461F,
  142684. 0.0181696565F, 0.0184281708F, 0.0186884883F, 0.0189506084F,
  142685. 0.0192145303F, 0.0194802535F, 0.0197477772F, 0.0200171008F,
  142686. 0.0202882236F, 0.0205611449F, 0.0208358639F, 0.0211123801F,
  142687. 0.0213906927F, 0.0216708011F, 0.0219527043F, 0.0222364019F,
  142688. 0.0225218930F, 0.0228091769F, 0.0230982529F, 0.0233891203F,
  142689. 0.0236817782F, 0.0239762259F, 0.0242724628F, 0.0245704880F,
  142690. 0.0248703007F, 0.0251719002F, 0.0254752858F, 0.0257804565F,
  142691. 0.0260874117F, 0.0263961506F, 0.0267066722F, 0.0270189760F,
  142692. 0.0273330609F, 0.0276489263F, 0.0279665712F, 0.0282859949F,
  142693. 0.0286071966F, 0.0289301753F, 0.0292549303F, 0.0295814607F,
  142694. 0.0299097656F, 0.0302398442F, 0.0305716957F, 0.0309053191F,
  142695. 0.0312407135F, 0.0315778782F, 0.0319168122F, 0.0322575145F,
  142696. 0.0325999844F, 0.0329442209F, 0.0332902231F, 0.0336379900F,
  142697. 0.0339875208F, 0.0343388146F, 0.0346918703F, 0.0350466871F,
  142698. 0.0354032640F, 0.0357616000F, 0.0361216943F, 0.0364835458F,
  142699. 0.0368471535F, 0.0372125166F, 0.0375796339F, 0.0379485046F,
  142700. 0.0383191276F, 0.0386915020F, 0.0390656267F, 0.0394415008F,
  142701. 0.0398191231F, 0.0401984927F, 0.0405796086F, 0.0409624698F,
  142702. 0.0413470751F, 0.0417334235F, 0.0421215141F, 0.0425113457F,
  142703. 0.0429029172F, 0.0432962277F, 0.0436912760F, 0.0440880610F,
  142704. 0.0444865817F, 0.0448868370F, 0.0452888257F, 0.0456925468F,
  142705. 0.0460979992F, 0.0465051816F, 0.0469140931F, 0.0473247325F,
  142706. 0.0477370986F, 0.0481511902F, 0.0485670064F, 0.0489845458F,
  142707. 0.0494038074F, 0.0498247899F, 0.0502474922F, 0.0506719131F,
  142708. 0.0510980514F, 0.0515259060F, 0.0519554756F, 0.0523867590F,
  142709. 0.0528197550F, 0.0532544624F, 0.0536908800F, 0.0541290066F,
  142710. 0.0545688408F, 0.0550103815F, 0.0554536274F, 0.0558985772F,
  142711. 0.0563452297F, 0.0567935837F, 0.0572436377F, 0.0576953907F,
  142712. 0.0581488412F, 0.0586039880F, 0.0590608297F, 0.0595193651F,
  142713. 0.0599795929F, 0.0604415117F, 0.0609051202F, 0.0613704170F,
  142714. 0.0618374009F, 0.0623060704F, 0.0627764243F, 0.0632484611F,
  142715. 0.0637221795F, 0.0641975781F, 0.0646746555F, 0.0651534104F,
  142716. 0.0656338413F, 0.0661159469F, 0.0665997257F, 0.0670851763F,
  142717. 0.0675722973F, 0.0680610873F, 0.0685515448F, 0.0690436684F,
  142718. 0.0695374567F, 0.0700329081F, 0.0705300213F, 0.0710287947F,
  142719. 0.0715292269F, 0.0720313163F, 0.0725350616F, 0.0730404612F,
  142720. 0.0735475136F, 0.0740562172F, 0.0745665707F, 0.0750785723F,
  142721. 0.0755922207F, 0.0761075143F, 0.0766244515F, 0.0771430307F,
  142722. 0.0776632505F, 0.0781851092F, 0.0787086052F, 0.0792337371F,
  142723. 0.0797605032F, 0.0802889018F, 0.0808189315F, 0.0813505905F,
  142724. 0.0818838773F, 0.0824187903F, 0.0829553277F, 0.0834934881F,
  142725. 0.0840332697F, 0.0845746708F, 0.0851176899F, 0.0856623252F,
  142726. 0.0862085751F, 0.0867564379F, 0.0873059119F, 0.0878569954F,
  142727. 0.0884096867F, 0.0889639840F, 0.0895198858F, 0.0900773902F,
  142728. 0.0906364955F, 0.0911972000F, 0.0917595019F, 0.0923233995F,
  142729. 0.0928888909F, 0.0934559745F, 0.0940246485F, 0.0945949110F,
  142730. 0.0951667604F, 0.0957401946F, 0.0963152121F, 0.0968918109F,
  142731. 0.0974699893F, 0.0980497454F, 0.0986310773F, 0.0992139832F,
  142732. 0.0997984614F, 0.1003845098F, 0.1009721267F, 0.1015613101F,
  142733. 0.1021520582F, 0.1027443692F, 0.1033382410F, 0.1039336718F,
  142734. 0.1045306597F, 0.1051292027F, 0.1057292990F, 0.1063309466F,
  142735. 0.1069341435F, 0.1075388878F, 0.1081451776F, 0.1087530108F,
  142736. 0.1093623856F, 0.1099732998F, 0.1105857516F, 0.1111997389F,
  142737. 0.1118152597F, 0.1124323121F, 0.1130508939F, 0.1136710032F,
  142738. 0.1142926379F, 0.1149157960F, 0.1155404755F, 0.1161666742F,
  142739. 0.1167943901F, 0.1174236211F, 0.1180543652F, 0.1186866202F,
  142740. 0.1193203841F, 0.1199556548F, 0.1205924300F, 0.1212307078F,
  142741. 0.1218704860F, 0.1225117624F, 0.1231545349F, 0.1237988013F,
  142742. 0.1244445596F, 0.1250918074F, 0.1257405427F, 0.1263907632F,
  142743. 0.1270424667F, 0.1276956512F, 0.1283503142F, 0.1290064537F,
  142744. 0.1296640674F, 0.1303231530F, 0.1309837084F, 0.1316457312F,
  142745. 0.1323092193F, 0.1329741703F, 0.1336405820F, 0.1343084520F,
  142746. 0.1349777782F, 0.1356485582F, 0.1363207897F, 0.1369944704F,
  142747. 0.1376695979F, 0.1383461700F, 0.1390241842F, 0.1397036384F,
  142748. 0.1403845300F, 0.1410668567F, 0.1417506162F, 0.1424358061F,
  142749. 0.1431224240F, 0.1438104674F, 0.1444999341F, 0.1451908216F,
  142750. 0.1458831274F, 0.1465768492F, 0.1472719844F, 0.1479685308F,
  142751. 0.1486664857F, 0.1493658468F, 0.1500666115F, 0.1507687775F,
  142752. 0.1514723422F, 0.1521773031F, 0.1528836577F, 0.1535914035F,
  142753. 0.1543005380F, 0.1550110587F, 0.1557229631F, 0.1564362485F,
  142754. 0.1571509124F, 0.1578669524F, 0.1585843657F, 0.1593031499F,
  142755. 0.1600233024F, 0.1607448205F, 0.1614677017F, 0.1621919433F,
  142756. 0.1629175428F, 0.1636444975F, 0.1643728047F, 0.1651024619F,
  142757. 0.1658334665F, 0.1665658156F, 0.1672995067F, 0.1680345371F,
  142758. 0.1687709041F, 0.1695086050F, 0.1702476372F, 0.1709879978F,
  142759. 0.1717296843F, 0.1724726938F, 0.1732170237F, 0.1739626711F,
  142760. 0.1747096335F, 0.1754579079F, 0.1762074916F, 0.1769583819F,
  142761. 0.1777105760F, 0.1784640710F, 0.1792188642F, 0.1799749529F,
  142762. 0.1807323340F, 0.1814910049F, 0.1822509628F, 0.1830122046F,
  142763. 0.1837747277F, 0.1845385292F, 0.1853036062F, 0.1860699558F,
  142764. 0.1868375751F, 0.1876064613F, 0.1883766114F, 0.1891480226F,
  142765. 0.1899206919F, 0.1906946164F, 0.1914697932F, 0.1922462194F,
  142766. 0.1930238919F, 0.1938028079F, 0.1945829643F, 0.1953643583F,
  142767. 0.1961469868F, 0.1969308468F, 0.1977159353F, 0.1985022494F,
  142768. 0.1992897859F, 0.2000785420F, 0.2008685145F, 0.2016597005F,
  142769. 0.2024520968F, 0.2032457005F, 0.2040405084F, 0.2048365175F,
  142770. 0.2056337247F, 0.2064321269F, 0.2072317211F, 0.2080325041F,
  142771. 0.2088344727F, 0.2096376240F, 0.2104419547F, 0.2112474618F,
  142772. 0.2120541420F, 0.2128619923F, 0.2136710094F, 0.2144811902F,
  142773. 0.2152925315F, 0.2161050301F, 0.2169186829F, 0.2177334866F,
  142774. 0.2185494381F, 0.2193665340F, 0.2201847712F, 0.2210041465F,
  142775. 0.2218246565F, 0.2226462981F, 0.2234690680F, 0.2242929629F,
  142776. 0.2251179796F, 0.2259441147F, 0.2267713650F, 0.2275997272F,
  142777. 0.2284291979F, 0.2292597739F, 0.2300914518F, 0.2309242283F,
  142778. 0.2317581001F, 0.2325930638F, 0.2334291160F, 0.2342662534F,
  142779. 0.2351044727F, 0.2359437703F, 0.2367841431F, 0.2376255875F,
  142780. 0.2384681001F, 0.2393116776F, 0.2401563165F, 0.2410020134F,
  142781. 0.2418487649F, 0.2426965675F, 0.2435454178F, 0.2443953122F,
  142782. 0.2452462474F, 0.2460982199F, 0.2469512262F, 0.2478052628F,
  142783. 0.2486603262F, 0.2495164129F, 0.2503735194F, 0.2512316421F,
  142784. 0.2520907776F, 0.2529509222F, 0.2538120726F, 0.2546742250F,
  142785. 0.2555373760F, 0.2564015219F, 0.2572666593F, 0.2581327845F,
  142786. 0.2589998939F, 0.2598679840F, 0.2607370510F, 0.2616070916F,
  142787. 0.2624781019F, 0.2633500783F, 0.2642230173F, 0.2650969152F,
  142788. 0.2659717684F, 0.2668475731F, 0.2677243257F, 0.2686020226F,
  142789. 0.2694806601F, 0.2703602344F, 0.2712407419F, 0.2721221789F,
  142790. 0.2730045417F, 0.2738878265F, 0.2747720297F, 0.2756571474F,
  142791. 0.2765431760F, 0.2774301117F, 0.2783179508F, 0.2792066895F,
  142792. 0.2800963240F, 0.2809868505F, 0.2818782654F, 0.2827705647F,
  142793. 0.2836637447F, 0.2845578016F, 0.2854527315F, 0.2863485307F,
  142794. 0.2872451953F, 0.2881427215F, 0.2890411055F, 0.2899403433F,
  142795. 0.2908404312F, 0.2917413654F, 0.2926431418F, 0.2935457567F,
  142796. 0.2944492061F, 0.2953534863F, 0.2962585932F, 0.2971645230F,
  142797. 0.2980712717F, 0.2989788356F, 0.2998872105F, 0.3007963927F,
  142798. 0.3017063781F, 0.3026171629F, 0.3035287430F, 0.3044411145F,
  142799. 0.3053542736F, 0.3062682161F, 0.3071829381F, 0.3080984356F,
  142800. 0.3090147047F, 0.3099317413F, 0.3108495414F, 0.3117681011F,
  142801. 0.3126874163F, 0.3136074830F, 0.3145282972F, 0.3154498548F,
  142802. 0.3163721517F, 0.3172951841F, 0.3182189477F, 0.3191434385F,
  142803. 0.3200686525F, 0.3209945856F, 0.3219212336F, 0.3228485927F,
  142804. 0.3237766585F, 0.3247054271F, 0.3256348943F, 0.3265650560F,
  142805. 0.3274959081F, 0.3284274465F, 0.3293596671F, 0.3302925657F,
  142806. 0.3312261382F, 0.3321603804F, 0.3330952882F, 0.3340308574F,
  142807. 0.3349670838F, 0.3359039634F, 0.3368414919F, 0.3377796651F,
  142808. 0.3387184789F, 0.3396579290F, 0.3405980113F, 0.3415387216F,
  142809. 0.3424800556F, 0.3434220091F, 0.3443645779F, 0.3453077578F,
  142810. 0.3462515446F, 0.3471959340F, 0.3481409217F, 0.3490865036F,
  142811. 0.3500326754F, 0.3509794328F, 0.3519267715F, 0.3528746873F,
  142812. 0.3538231759F, 0.3547722330F, 0.3557218544F, 0.3566720357F,
  142813. 0.3576227727F, 0.3585740610F, 0.3595258964F, 0.3604782745F,
  142814. 0.3614311910F, 0.3623846417F, 0.3633386221F, 0.3642931280F,
  142815. 0.3652481549F, 0.3662036987F, 0.3671597548F, 0.3681163191F,
  142816. 0.3690733870F, 0.3700309544F, 0.3709890167F, 0.3719475696F,
  142817. 0.3729066089F, 0.3738661299F, 0.3748261285F, 0.3757866002F,
  142818. 0.3767475406F, 0.3777089453F, 0.3786708100F, 0.3796331302F,
  142819. 0.3805959014F, 0.3815591194F, 0.3825227796F, 0.3834868777F,
  142820. 0.3844514093F, 0.3854163698F, 0.3863817549F, 0.3873475601F,
  142821. 0.3883137810F, 0.3892804131F, 0.3902474521F, 0.3912148933F,
  142822. 0.3921827325F, 0.3931509650F, 0.3941195865F, 0.3950885925F,
  142823. 0.3960579785F, 0.3970277400F, 0.3979978725F, 0.3989683716F,
  142824. 0.3999392328F, 0.4009104516F, 0.4018820234F, 0.4028539438F,
  142825. 0.4038262084F, 0.4047988125F, 0.4057717516F, 0.4067450214F,
  142826. 0.4077186172F, 0.4086925345F, 0.4096667688F, 0.4106413155F,
  142827. 0.4116161703F, 0.4125913284F, 0.4135667854F, 0.4145425368F,
  142828. 0.4155185780F, 0.4164949044F, 0.4174715116F, 0.4184483949F,
  142829. 0.4194255498F, 0.4204029718F, 0.4213806563F, 0.4223585987F,
  142830. 0.4233367946F, 0.4243152392F, 0.4252939281F, 0.4262728566F,
  142831. 0.4272520202F, 0.4282314144F, 0.4292110345F, 0.4301908760F,
  142832. 0.4311709343F, 0.4321512047F, 0.4331316828F, 0.4341123639F,
  142833. 0.4350932435F, 0.4360743168F, 0.4370555794F, 0.4380370267F,
  142834. 0.4390186540F, 0.4400004567F, 0.4409824303F, 0.4419645701F,
  142835. 0.4429468716F, 0.4439293300F, 0.4449119409F, 0.4458946996F,
  142836. 0.4468776014F, 0.4478606418F, 0.4488438162F, 0.4498271199F,
  142837. 0.4508105483F, 0.4517940967F, 0.4527777607F, 0.4537615355F,
  142838. 0.4547454165F, 0.4557293991F, 0.4567134786F, 0.4576976505F,
  142839. 0.4586819101F, 0.4596662527F, 0.4606506738F, 0.4616351687F,
  142840. 0.4626197328F, 0.4636043614F, 0.4645890499F, 0.4655737936F,
  142841. 0.4665585880F, 0.4675434284F, 0.4685283101F, 0.4695132286F,
  142842. 0.4704981791F, 0.4714831570F, 0.4724681577F, 0.4734531766F,
  142843. 0.4744382089F, 0.4754232501F, 0.4764082956F, 0.4773933406F,
  142844. 0.4783783806F, 0.4793634108F, 0.4803484267F, 0.4813334237F,
  142845. 0.4823183969F, 0.4833033419F, 0.4842882540F, 0.4852731285F,
  142846. 0.4862579608F, 0.4872427462F, 0.4882274802F, 0.4892121580F,
  142847. 0.4901967751F, 0.4911813267F, 0.4921658083F, 0.4931502151F,
  142848. 0.4941345427F, 0.4951187863F, 0.4961029412F, 0.4970870029F,
  142849. 0.4980709667F, 0.4990548280F, 0.5000385822F, 0.5010222245F,
  142850. 0.5020057505F, 0.5029891553F, 0.5039724345F, 0.5049555834F,
  142851. 0.5059385973F, 0.5069214716F, 0.5079042018F, 0.5088867831F,
  142852. 0.5098692110F, 0.5108514808F, 0.5118335879F, 0.5128155277F,
  142853. 0.5137972956F, 0.5147788869F, 0.5157602971F, 0.5167415215F,
  142854. 0.5177225555F, 0.5187033945F, 0.5196840339F, 0.5206644692F,
  142855. 0.5216446956F, 0.5226247086F, 0.5236045035F, 0.5245840759F,
  142856. 0.5255634211F, 0.5265425344F, 0.5275214114F, 0.5285000474F,
  142857. 0.5294784378F, 0.5304565781F, 0.5314344637F, 0.5324120899F,
  142858. 0.5333894522F, 0.5343665461F, 0.5353433670F, 0.5363199102F,
  142859. 0.5372961713F, 0.5382721457F, 0.5392478287F, 0.5402232159F,
  142860. 0.5411983027F, 0.5421730845F, 0.5431475569F, 0.5441217151F,
  142861. 0.5450955548F, 0.5460690714F, 0.5470422602F, 0.5480151169F,
  142862. 0.5489876368F, 0.5499598155F, 0.5509316484F, 0.5519031310F,
  142863. 0.5528742587F, 0.5538450271F, 0.5548154317F, 0.5557854680F,
  142864. 0.5567551314F, 0.5577244174F, 0.5586933216F, 0.5596618395F,
  142865. 0.5606299665F, 0.5615976983F, 0.5625650302F, 0.5635319580F,
  142866. 0.5644984770F, 0.5654645828F, 0.5664302709F, 0.5673955370F,
  142867. 0.5683603765F, 0.5693247850F, 0.5702887580F, 0.5712522912F,
  142868. 0.5722153800F, 0.5731780200F, 0.5741402069F, 0.5751019362F,
  142869. 0.5760632034F, 0.5770240042F, 0.5779843341F, 0.5789441889F,
  142870. 0.5799035639F, 0.5808624549F, 0.5818208575F, 0.5827787673F,
  142871. 0.5837361800F, 0.5846930910F, 0.5856494961F, 0.5866053910F,
  142872. 0.5875607712F, 0.5885156324F, 0.5894699703F, 0.5904237804F,
  142873. 0.5913770586F, 0.5923298004F, 0.5932820016F, 0.5942336578F,
  142874. 0.5951847646F, 0.5961353179F, 0.5970853132F, 0.5980347464F,
  142875. 0.5989836131F, 0.5999319090F, 0.6008796298F, 0.6018267713F,
  142876. 0.6027733292F, 0.6037192993F, 0.6046646773F, 0.6056094589F,
  142877. 0.6065536400F, 0.6074972162F, 0.6084401833F, 0.6093825372F,
  142878. 0.6103242736F, 0.6112653884F, 0.6122058772F, 0.6131457359F,
  142879. 0.6140849604F, 0.6150235464F, 0.6159614897F, 0.6168987862F,
  142880. 0.6178354318F, 0.6187714223F, 0.6197067535F, 0.6206414213F,
  142881. 0.6215754215F, 0.6225087501F, 0.6234414028F, 0.6243733757F,
  142882. 0.6253046646F, 0.6262352654F, 0.6271651739F, 0.6280943862F,
  142883. 0.6290228982F, 0.6299507057F, 0.6308778048F, 0.6318041913F,
  142884. 0.6327298612F, 0.6336548105F, 0.6345790352F, 0.6355025312F,
  142885. 0.6364252945F, 0.6373473211F, 0.6382686070F, 0.6391891483F,
  142886. 0.6401089409F, 0.6410279808F, 0.6419462642F, 0.6428637869F,
  142887. 0.6437805452F, 0.6446965350F, 0.6456117524F, 0.6465261935F,
  142888. 0.6474398544F, 0.6483527311F, 0.6492648197F, 0.6501761165F,
  142889. 0.6510866174F, 0.6519963186F, 0.6529052162F, 0.6538133064F,
  142890. 0.6547205854F, 0.6556270492F, 0.6565326941F, 0.6574375162F,
  142891. 0.6583415117F, 0.6592446769F, 0.6601470079F, 0.6610485009F,
  142892. 0.6619491521F, 0.6628489578F, 0.6637479143F, 0.6646460177F,
  142893. 0.6655432643F, 0.6664396505F, 0.6673351724F, 0.6682298264F,
  142894. 0.6691236087F, 0.6700165157F, 0.6709085436F, 0.6717996889F,
  142895. 0.6726899478F, 0.6735793167F, 0.6744677918F, 0.6753553697F,
  142896. 0.6762420466F, 0.6771278190F, 0.6780126832F, 0.6788966357F,
  142897. 0.6797796728F, 0.6806617909F, 0.6815429866F, 0.6824232562F,
  142898. 0.6833025961F, 0.6841810030F, 0.6850584731F, 0.6859350031F,
  142899. 0.6868105894F, 0.6876852284F, 0.6885589168F, 0.6894316510F,
  142900. 0.6903034275F, 0.6911742430F, 0.6920440939F, 0.6929129769F,
  142901. 0.6937808884F, 0.6946478251F, 0.6955137837F, 0.6963787606F,
  142902. 0.6972427525F, 0.6981057560F, 0.6989677678F, 0.6998287845F,
  142903. 0.7006888028F, 0.7015478194F, 0.7024058309F, 0.7032628340F,
  142904. 0.7041188254F, 0.7049738019F, 0.7058277601F, 0.7066806969F,
  142905. 0.7075326089F, 0.7083834929F, 0.7092333457F, 0.7100821640F,
  142906. 0.7109299447F, 0.7117766846F, 0.7126223804F, 0.7134670291F,
  142907. 0.7143106273F, 0.7151531721F, 0.7159946602F, 0.7168350885F,
  142908. 0.7176744539F, 0.7185127534F, 0.7193499837F, 0.7201861418F,
  142909. 0.7210212247F, 0.7218552293F, 0.7226881526F, 0.7235199914F,
  142910. 0.7243507428F, 0.7251804039F, 0.7260089715F, 0.7268364426F,
  142911. 0.7276628144F, 0.7284880839F, 0.7293122481F, 0.7301353040F,
  142912. 0.7309572487F, 0.7317780794F, 0.7325977930F, 0.7334163868F,
  142913. 0.7342338579F, 0.7350502033F, 0.7358654202F, 0.7366795059F,
  142914. 0.7374924573F, 0.7383042718F, 0.7391149465F, 0.7399244787F,
  142915. 0.7407328655F, 0.7415401041F, 0.7423461920F, 0.7431511261F,
  142916. 0.7439549040F, 0.7447575227F, 0.7455589797F, 0.7463592723F,
  142917. 0.7471583976F, 0.7479563532F, 0.7487531363F, 0.7495487443F,
  142918. 0.7503431745F, 0.7511364244F, 0.7519284913F, 0.7527193726F,
  142919. 0.7535090658F, 0.7542975683F, 0.7550848776F, 0.7558709910F,
  142920. 0.7566559062F, 0.7574396205F, 0.7582221314F, 0.7590034366F,
  142921. 0.7597835334F, 0.7605624194F, 0.7613400923F, 0.7621165495F,
  142922. 0.7628917886F, 0.7636658072F, 0.7644386030F, 0.7652101735F,
  142923. 0.7659805164F, 0.7667496292F, 0.7675175098F, 0.7682841556F,
  142924. 0.7690495645F, 0.7698137341F, 0.7705766622F, 0.7713383463F,
  142925. 0.7720987844F, 0.7728579741F, 0.7736159132F, 0.7743725994F,
  142926. 0.7751280306F, 0.7758822046F, 0.7766351192F, 0.7773867722F,
  142927. 0.7781371614F, 0.7788862848F, 0.7796341401F, 0.7803807253F,
  142928. 0.7811260383F, 0.7818700769F, 0.7826128392F, 0.7833543230F,
  142929. 0.7840945263F, 0.7848334471F, 0.7855710833F, 0.7863074330F,
  142930. 0.7870424941F, 0.7877762647F, 0.7885087428F, 0.7892399264F,
  142931. 0.7899698137F, 0.7906984026F, 0.7914256914F, 0.7921516780F,
  142932. 0.7928763607F, 0.7935997375F, 0.7943218065F, 0.7950425661F,
  142933. 0.7957620142F, 0.7964801492F, 0.7971969692F, 0.7979124724F,
  142934. 0.7986266570F, 0.7993395214F, 0.8000510638F, 0.8007612823F,
  142935. 0.8014701754F, 0.8021777413F, 0.8028839784F, 0.8035888849F,
  142936. 0.8042924592F, 0.8049946997F, 0.8056956048F, 0.8063951727F,
  142937. 0.8070934020F, 0.8077902910F, 0.8084858381F, 0.8091800419F,
  142938. 0.8098729007F, 0.8105644130F, 0.8112545774F, 0.8119433922F,
  142939. 0.8126308561F, 0.8133169676F, 0.8140017251F, 0.8146851272F,
  142940. 0.8153671726F, 0.8160478598F, 0.8167271874F, 0.8174051539F,
  142941. 0.8180817582F, 0.8187569986F, 0.8194308741F, 0.8201033831F,
  142942. 0.8207745244F, 0.8214442966F, 0.8221126986F, 0.8227797290F,
  142943. 0.8234453865F, 0.8241096700F, 0.8247725781F, 0.8254341097F,
  142944. 0.8260942636F, 0.8267530385F, 0.8274104334F, 0.8280664470F,
  142945. 0.8287210782F, 0.8293743259F, 0.8300261889F, 0.8306766662F,
  142946. 0.8313257566F, 0.8319734591F, 0.8326197727F, 0.8332646963F,
  142947. 0.8339082288F, 0.8345503692F, 0.8351911167F, 0.8358304700F,
  142948. 0.8364684284F, 0.8371049907F, 0.8377401562F, 0.8383739238F,
  142949. 0.8390062927F, 0.8396372618F, 0.8402668305F, 0.8408949977F,
  142950. 0.8415217626F, 0.8421471245F, 0.8427710823F, 0.8433936354F,
  142951. 0.8440147830F, 0.8446345242F, 0.8452528582F, 0.8458697844F,
  142952. 0.8464853020F, 0.8470994102F, 0.8477121084F, 0.8483233958F,
  142953. 0.8489332718F, 0.8495417356F, 0.8501487866F, 0.8507544243F,
  142954. 0.8513586479F, 0.8519614568F, 0.8525628505F, 0.8531628283F,
  142955. 0.8537613897F, 0.8543585341F, 0.8549542611F, 0.8555485699F,
  142956. 0.8561414603F, 0.8567329315F, 0.8573229832F, 0.8579116149F,
  142957. 0.8584988262F, 0.8590846165F, 0.8596689855F, 0.8602519327F,
  142958. 0.8608334577F, 0.8614135603F, 0.8619922399F, 0.8625694962F,
  142959. 0.8631453289F, 0.8637197377F, 0.8642927222F, 0.8648642821F,
  142960. 0.8654344172F, 0.8660031272F, 0.8665704118F, 0.8671362708F,
  142961. 0.8677007039F, 0.8682637109F, 0.8688252917F, 0.8693854460F,
  142962. 0.8699441737F, 0.8705014745F, 0.8710573485F, 0.8716117953F,
  142963. 0.8721648150F, 0.8727164073F, 0.8732665723F, 0.8738153098F,
  142964. 0.8743626197F, 0.8749085021F, 0.8754529569F, 0.8759959840F,
  142965. 0.8765375835F, 0.8770777553F, 0.8776164996F, 0.8781538162F,
  142966. 0.8786897054F, 0.8792241670F, 0.8797572013F, 0.8802888082F,
  142967. 0.8808189880F, 0.8813477407F, 0.8818750664F, 0.8824009653F,
  142968. 0.8829254375F, 0.8834484833F, 0.8839701028F, 0.8844902961F,
  142969. 0.8850090636F, 0.8855264054F, 0.8860423218F, 0.8865568131F,
  142970. 0.8870698794F, 0.8875815212F, 0.8880917386F, 0.8886005319F,
  142971. 0.8891079016F, 0.8896138479F, 0.8901183712F, 0.8906214719F,
  142972. 0.8911231503F, 0.8916234067F, 0.8921222417F, 0.8926196556F,
  142973. 0.8931156489F, 0.8936102219F, 0.8941033752F, 0.8945951092F,
  142974. 0.8950854244F, 0.8955743212F, 0.8960618003F, 0.8965478621F,
  142975. 0.8970325071F, 0.8975157359F, 0.8979975490F, 0.8984779471F,
  142976. 0.8989569307F, 0.8994345004F, 0.8999106568F, 0.9003854005F,
  142977. 0.9008587323F, 0.9013306526F, 0.9018011623F, 0.9022702619F,
  142978. 0.9027379521F, 0.9032042337F, 0.9036691074F, 0.9041325739F,
  142979. 0.9045946339F, 0.9050552882F, 0.9055145376F, 0.9059723828F,
  142980. 0.9064288246F, 0.9068838638F, 0.9073375013F, 0.9077897379F,
  142981. 0.9082405743F, 0.9086900115F, 0.9091380503F, 0.9095846917F,
  142982. 0.9100299364F, 0.9104737854F, 0.9109162397F, 0.9113573001F,
  142983. 0.9117969675F, 0.9122352430F, 0.9126721275F, 0.9131076219F,
  142984. 0.9135417273F, 0.9139744447F, 0.9144057750F, 0.9148357194F,
  142985. 0.9152642787F, 0.9156914542F, 0.9161172468F, 0.9165416576F,
  142986. 0.9169646877F, 0.9173863382F, 0.9178066102F, 0.9182255048F,
  142987. 0.9186430232F, 0.9190591665F, 0.9194739359F, 0.9198873324F,
  142988. 0.9202993574F, 0.9207100120F, 0.9211192973F, 0.9215272147F,
  142989. 0.9219337653F, 0.9223389504F, 0.9227427713F, 0.9231452290F,
  142990. 0.9235463251F, 0.9239460607F, 0.9243444371F, 0.9247414557F,
  142991. 0.9251371177F, 0.9255314245F, 0.9259243774F, 0.9263159778F,
  142992. 0.9267062270F, 0.9270951264F, 0.9274826774F, 0.9278688814F,
  142993. 0.9282537398F, 0.9286372540F, 0.9290194254F, 0.9294002555F,
  142994. 0.9297797458F, 0.9301578976F, 0.9305347125F, 0.9309101919F,
  142995. 0.9312843373F, 0.9316571503F, 0.9320286323F, 0.9323987849F,
  142996. 0.9327676097F, 0.9331351080F, 0.9335012816F, 0.9338661320F,
  142997. 0.9342296607F, 0.9345918694F, 0.9349527596F, 0.9353123330F,
  142998. 0.9356705911F, 0.9360275357F, 0.9363831683F, 0.9367374905F,
  142999. 0.9370905042F, 0.9374422108F, 0.9377926122F, 0.9381417099F,
  143000. 0.9384895057F, 0.9388360014F, 0.9391811985F, 0.9395250989F,
  143001. 0.9398677043F, 0.9402090165F, 0.9405490371F, 0.9408877680F,
  143002. 0.9412252110F, 0.9415613678F, 0.9418962402F, 0.9422298301F,
  143003. 0.9425621392F, 0.9428931695F, 0.9432229226F, 0.9435514005F,
  143004. 0.9438786050F, 0.9442045381F, 0.9445292014F, 0.9448525971F,
  143005. 0.9451747268F, 0.9454955926F, 0.9458151963F, 0.9461335399F,
  143006. 0.9464506253F, 0.9467664545F, 0.9470810293F, 0.9473943517F,
  143007. 0.9477064238F, 0.9480172474F, 0.9483268246F, 0.9486351573F,
  143008. 0.9489422475F, 0.9492480973F, 0.9495527087F, 0.9498560837F,
  143009. 0.9501582243F, 0.9504591325F, 0.9507588105F, 0.9510572603F,
  143010. 0.9513544839F, 0.9516504834F, 0.9519452609F, 0.9522388186F,
  143011. 0.9525311584F, 0.9528222826F, 0.9531121932F, 0.9534008923F,
  143012. 0.9536883821F, 0.9539746647F, 0.9542597424F, 0.9545436171F,
  143013. 0.9548262912F, 0.9551077667F, 0.9553880459F, 0.9556671309F,
  143014. 0.9559450239F, 0.9562217272F, 0.9564972429F, 0.9567715733F,
  143015. 0.9570447206F, 0.9573166871F, 0.9575874749F, 0.9578570863F,
  143016. 0.9581255236F, 0.9583927890F, 0.9586588849F, 0.9589238134F,
  143017. 0.9591875769F, 0.9594501777F, 0.9597116180F, 0.9599719003F,
  143018. 0.9602310267F, 0.9604889995F, 0.9607458213F, 0.9610014942F,
  143019. 0.9612560206F, 0.9615094028F, 0.9617616433F, 0.9620127443F,
  143020. 0.9622627083F, 0.9625115376F, 0.9627592345F, 0.9630058016F,
  143021. 0.9632512411F, 0.9634955555F, 0.9637387471F, 0.9639808185F,
  143022. 0.9642217720F, 0.9644616100F, 0.9647003349F, 0.9649379493F,
  143023. 0.9651744556F, 0.9654098561F, 0.9656441534F, 0.9658773499F,
  143024. 0.9661094480F, 0.9663404504F, 0.9665703593F, 0.9667991774F,
  143025. 0.9670269071F, 0.9672535509F, 0.9674791114F, 0.9677035909F,
  143026. 0.9679269921F, 0.9681493174F, 0.9683705694F, 0.9685907506F,
  143027. 0.9688098636F, 0.9690279108F, 0.9692448948F, 0.9694608182F,
  143028. 0.9696756836F, 0.9698894934F, 0.9701022503F, 0.9703139569F,
  143029. 0.9705246156F, 0.9707342291F, 0.9709428000F, 0.9711503309F,
  143030. 0.9713568243F, 0.9715622829F, 0.9717667093F, 0.9719701060F,
  143031. 0.9721724757F, 0.9723738210F, 0.9725741446F, 0.9727734490F,
  143032. 0.9729717369F, 0.9731690109F, 0.9733652737F, 0.9735605279F,
  143033. 0.9737547762F, 0.9739480212F, 0.9741402656F, 0.9743315120F,
  143034. 0.9745217631F, 0.9747110216F, 0.9748992901F, 0.9750865714F,
  143035. 0.9752728681F, 0.9754581829F, 0.9756425184F, 0.9758258775F,
  143036. 0.9760082627F, 0.9761896768F, 0.9763701224F, 0.9765496024F,
  143037. 0.9767281193F, 0.9769056760F, 0.9770822751F, 0.9772579193F,
  143038. 0.9774326114F, 0.9776063542F, 0.9777791502F, 0.9779510023F,
  143039. 0.9781219133F, 0.9782918858F, 0.9784609226F, 0.9786290264F,
  143040. 0.9787962000F, 0.9789624461F, 0.9791277676F, 0.9792921671F,
  143041. 0.9794556474F, 0.9796182113F, 0.9797798615F, 0.9799406009F,
  143042. 0.9801004321F, 0.9802593580F, 0.9804173813F, 0.9805745049F,
  143043. 0.9807307314F, 0.9808860637F, 0.9810405046F, 0.9811940568F,
  143044. 0.9813467232F, 0.9814985065F, 0.9816494095F, 0.9817994351F,
  143045. 0.9819485860F, 0.9820968650F, 0.9822442750F, 0.9823908186F,
  143046. 0.9825364988F, 0.9826813184F, 0.9828252801F, 0.9829683868F,
  143047. 0.9831106413F, 0.9832520463F, 0.9833926048F, 0.9835323195F,
  143048. 0.9836711932F, 0.9838092288F, 0.9839464291F, 0.9840827969F,
  143049. 0.9842183351F, 0.9843530464F, 0.9844869337F, 0.9846199998F,
  143050. 0.9847522475F, 0.9848836798F, 0.9850142993F, 0.9851441090F,
  143051. 0.9852731117F, 0.9854013101F, 0.9855287073F, 0.9856553058F,
  143052. 0.9857811087F, 0.9859061188F, 0.9860303388F, 0.9861537717F,
  143053. 0.9862764202F, 0.9863982872F, 0.9865193756F, 0.9866396882F,
  143054. 0.9867592277F, 0.9868779972F, 0.9869959993F, 0.9871132370F,
  143055. 0.9872297131F, 0.9873454304F, 0.9874603918F, 0.9875746001F,
  143056. 0.9876880581F, 0.9878007688F, 0.9879127348F, 0.9880239592F,
  143057. 0.9881344447F, 0.9882441941F, 0.9883532104F, 0.9884614962F,
  143058. 0.9885690546F, 0.9886758883F, 0.9887820001F, 0.9888873930F,
  143059. 0.9889920697F, 0.9890960331F, 0.9891992859F, 0.9893018312F,
  143060. 0.9894036716F, 0.9895048100F, 0.9896052493F, 0.9897049923F,
  143061. 0.9898040418F, 0.9899024006F, 0.9900000717F, 0.9900970577F,
  143062. 0.9901933616F, 0.9902889862F, 0.9903839343F, 0.9904782087F,
  143063. 0.9905718122F, 0.9906647477F, 0.9907570180F, 0.9908486259F,
  143064. 0.9909395742F, 0.9910298658F, 0.9911195034F, 0.9912084899F,
  143065. 0.9912968281F, 0.9913845208F, 0.9914715708F, 0.9915579810F,
  143066. 0.9916437540F, 0.9917288928F, 0.9918134001F, 0.9918972788F,
  143067. 0.9919805316F, 0.9920631613F, 0.9921451707F, 0.9922265626F,
  143068. 0.9923073399F, 0.9923875052F, 0.9924670615F, 0.9925460114F,
  143069. 0.9926243577F, 0.9927021033F, 0.9927792508F, 0.9928558032F,
  143070. 0.9929317631F, 0.9930071333F, 0.9930819167F, 0.9931561158F,
  143071. 0.9932297337F, 0.9933027728F, 0.9933752362F, 0.9934471264F,
  143072. 0.9935184462F, 0.9935891985F, 0.9936593859F, 0.9937290112F,
  143073. 0.9937980771F, 0.9938665864F, 0.9939345418F, 0.9940019460F,
  143074. 0.9940688018F, 0.9941351118F, 0.9942008789F, 0.9942661057F,
  143075. 0.9943307950F, 0.9943949494F, 0.9944585717F, 0.9945216645F,
  143076. 0.9945842307F, 0.9946462728F, 0.9947077936F, 0.9947687957F,
  143077. 0.9948292820F, 0.9948892550F, 0.9949487174F, 0.9950076719F,
  143078. 0.9950661212F, 0.9951240679F, 0.9951815148F, 0.9952384645F,
  143079. 0.9952949196F, 0.9953508828F, 0.9954063568F, 0.9954613442F,
  143080. 0.9955158476F, 0.9955698697F, 0.9956234132F, 0.9956764806F,
  143081. 0.9957290746F, 0.9957811978F, 0.9958328528F, 0.9958840423F,
  143082. 0.9959347688F, 0.9959850351F, 0.9960348435F, 0.9960841969F,
  143083. 0.9961330977F, 0.9961815486F, 0.9962295521F, 0.9962771108F,
  143084. 0.9963242274F, 0.9963709043F, 0.9964171441F, 0.9964629494F,
  143085. 0.9965083228F, 0.9965532668F, 0.9965977840F, 0.9966418768F,
  143086. 0.9966855479F, 0.9967287998F, 0.9967716350F, 0.9968140559F,
  143087. 0.9968560653F, 0.9968976655F, 0.9969388591F, 0.9969796485F,
  143088. 0.9970200363F, 0.9970600250F, 0.9970996170F, 0.9971388149F,
  143089. 0.9971776211F, 0.9972160380F, 0.9972540683F, 0.9972917142F,
  143090. 0.9973289783F, 0.9973658631F, 0.9974023709F, 0.9974385042F,
  143091. 0.9974742655F, 0.9975096571F, 0.9975446816F, 0.9975793413F,
  143092. 0.9976136386F, 0.9976475759F, 0.9976811557F, 0.9977143803F,
  143093. 0.9977472521F, 0.9977797736F, 0.9978119470F, 0.9978437748F,
  143094. 0.9978752593F, 0.9979064029F, 0.9979372079F, 0.9979676768F,
  143095. 0.9979978117F, 0.9980276151F, 0.9980570893F, 0.9980862367F,
  143096. 0.9981150595F, 0.9981435600F, 0.9981717406F, 0.9981996035F,
  143097. 0.9982271511F, 0.9982543856F, 0.9982813093F, 0.9983079246F,
  143098. 0.9983342336F, 0.9983602386F, 0.9983859418F, 0.9984113456F,
  143099. 0.9984364522F, 0.9984612638F, 0.9984857825F, 0.9985100108F,
  143100. 0.9985339507F, 0.9985576044F, 0.9985809743F, 0.9986040624F,
  143101. 0.9986268710F, 0.9986494022F, 0.9986716583F, 0.9986936413F,
  143102. 0.9987153535F, 0.9987367969F, 0.9987579738F, 0.9987788864F,
  143103. 0.9987995366F, 0.9988199267F, 0.9988400587F, 0.9988599348F,
  143104. 0.9988795572F, 0.9988989278F, 0.9989180487F, 0.9989369222F,
  143105. 0.9989555501F, 0.9989739347F, 0.9989920780F, 0.9990099820F,
  143106. 0.9990276487F, 0.9990450803F, 0.9990622787F, 0.9990792460F,
  143107. 0.9990959841F, 0.9991124952F, 0.9991287812F, 0.9991448440F,
  143108. 0.9991606858F, 0.9991763084F, 0.9991917139F, 0.9992069042F,
  143109. 0.9992218813F, 0.9992366471F, 0.9992512035F, 0.9992655525F,
  143110. 0.9992796961F, 0.9992936361F, 0.9993073744F, 0.9993209131F,
  143111. 0.9993342538F, 0.9993473987F, 0.9993603494F, 0.9993731080F,
  143112. 0.9993856762F, 0.9993980559F, 0.9994102490F, 0.9994222573F,
  143113. 0.9994340827F, 0.9994457269F, 0.9994571918F, 0.9994684793F,
  143114. 0.9994795910F, 0.9994905288F, 0.9995012945F, 0.9995118898F,
  143115. 0.9995223165F, 0.9995325765F, 0.9995426713F, 0.9995526029F,
  143116. 0.9995623728F, 0.9995719829F, 0.9995814349F, 0.9995907304F,
  143117. 0.9995998712F, 0.9996088590F, 0.9996176954F, 0.9996263821F,
  143118. 0.9996349208F, 0.9996433132F, 0.9996515609F, 0.9996596656F,
  143119. 0.9996676288F, 0.9996754522F, 0.9996831375F, 0.9996906862F,
  143120. 0.9996981000F, 0.9997053804F, 0.9997125290F, 0.9997195474F,
  143121. 0.9997264371F, 0.9997331998F, 0.9997398369F, 0.9997463500F,
  143122. 0.9997527406F, 0.9997590103F, 0.9997651606F, 0.9997711930F,
  143123. 0.9997771089F, 0.9997829098F, 0.9997885973F, 0.9997941728F,
  143124. 0.9997996378F, 0.9998049936F, 0.9998102419F, 0.9998153839F,
  143125. 0.9998204211F, 0.9998253550F, 0.9998301868F, 0.9998349182F,
  143126. 0.9998395503F, 0.9998440847F, 0.9998485226F, 0.9998528654F,
  143127. 0.9998571146F, 0.9998612713F, 0.9998653370F, 0.9998693130F,
  143128. 0.9998732007F, 0.9998770012F, 0.9998807159F, 0.9998843461F,
  143129. 0.9998878931F, 0.9998913581F, 0.9998947424F, 0.9998980473F,
  143130. 0.9999012740F, 0.9999044237F, 0.9999074976F, 0.9999104971F,
  143131. 0.9999134231F, 0.9999162771F, 0.9999190601F, 0.9999217733F,
  143132. 0.9999244179F, 0.9999269950F, 0.9999295058F, 0.9999319515F,
  143133. 0.9999343332F, 0.9999366519F, 0.9999389088F, 0.9999411050F,
  143134. 0.9999432416F, 0.9999453196F, 0.9999473402F, 0.9999493044F,
  143135. 0.9999512132F, 0.9999530677F, 0.9999548690F, 0.9999566180F,
  143136. 0.9999583157F, 0.9999599633F, 0.9999615616F, 0.9999631116F,
  143137. 0.9999646144F, 0.9999660709F, 0.9999674820F, 0.9999688487F,
  143138. 0.9999701719F, 0.9999714526F, 0.9999726917F, 0.9999738900F,
  143139. 0.9999750486F, 0.9999761682F, 0.9999772497F, 0.9999782941F,
  143140. 0.9999793021F, 0.9999802747F, 0.9999812126F, 0.9999821167F,
  143141. 0.9999829878F, 0.9999838268F, 0.9999846343F, 0.9999854113F,
  143142. 0.9999861584F, 0.9999868765F, 0.9999875664F, 0.9999882287F,
  143143. 0.9999888642F, 0.9999894736F, 0.9999900577F, 0.9999906172F,
  143144. 0.9999911528F, 0.9999916651F, 0.9999921548F, 0.9999926227F,
  143145. 0.9999930693F, 0.9999934954F, 0.9999939015F, 0.9999942883F,
  143146. 0.9999946564F, 0.9999950064F, 0.9999953390F, 0.9999956547F,
  143147. 0.9999959541F, 0.9999962377F, 0.9999965062F, 0.9999967601F,
  143148. 0.9999969998F, 0.9999972260F, 0.9999974392F, 0.9999976399F,
  143149. 0.9999978285F, 0.9999980056F, 0.9999981716F, 0.9999983271F,
  143150. 0.9999984724F, 0.9999986081F, 0.9999987345F, 0.9999988521F,
  143151. 0.9999989613F, 0.9999990625F, 0.9999991562F, 0.9999992426F,
  143152. 0.9999993223F, 0.9999993954F, 0.9999994625F, 0.9999995239F,
  143153. 0.9999995798F, 0.9999996307F, 0.9999996768F, 0.9999997184F,
  143154. 0.9999997559F, 0.9999997895F, 0.9999998195F, 0.9999998462F,
  143155. 0.9999998698F, 0.9999998906F, 0.9999999088F, 0.9999999246F,
  143156. 0.9999999383F, 0.9999999500F, 0.9999999600F, 0.9999999684F,
  143157. 0.9999999754F, 0.9999999811F, 0.9999999858F, 0.9999999896F,
  143158. 0.9999999925F, 0.9999999948F, 0.9999999965F, 0.9999999978F,
  143159. 0.9999999986F, 0.9999999992F, 0.9999999996F, 0.9999999998F,
  143160. 0.9999999999F, 1.0000000000F, 1.0000000000F, 1.0000000000F,
  143161. };
  143162. static float vwin8192[4096] = {
  143163. 0.0000000578F, 0.0000005198F, 0.0000014438F, 0.0000028299F,
  143164. 0.0000046780F, 0.0000069882F, 0.0000097604F, 0.0000129945F,
  143165. 0.0000166908F, 0.0000208490F, 0.0000254692F, 0.0000305515F,
  143166. 0.0000360958F, 0.0000421021F, 0.0000485704F, 0.0000555006F,
  143167. 0.0000628929F, 0.0000707472F, 0.0000790635F, 0.0000878417F,
  143168. 0.0000970820F, 0.0001067842F, 0.0001169483F, 0.0001275744F,
  143169. 0.0001386625F, 0.0001502126F, 0.0001622245F, 0.0001746984F,
  143170. 0.0001876343F, 0.0002010320F, 0.0002148917F, 0.0002292132F,
  143171. 0.0002439967F, 0.0002592421F, 0.0002749493F, 0.0002911184F,
  143172. 0.0003077493F, 0.0003248421F, 0.0003423967F, 0.0003604132F,
  143173. 0.0003788915F, 0.0003978316F, 0.0004172335F, 0.0004370971F,
  143174. 0.0004574226F, 0.0004782098F, 0.0004994587F, 0.0005211694F,
  143175. 0.0005433418F, 0.0005659759F, 0.0005890717F, 0.0006126292F,
  143176. 0.0006366484F, 0.0006611292F, 0.0006860716F, 0.0007114757F,
  143177. 0.0007373414F, 0.0007636687F, 0.0007904576F, 0.0008177080F,
  143178. 0.0008454200F, 0.0008735935F, 0.0009022285F, 0.0009313250F,
  143179. 0.0009608830F, 0.0009909025F, 0.0010213834F, 0.0010523257F,
  143180. 0.0010837295F, 0.0011155946F, 0.0011479211F, 0.0011807090F,
  143181. 0.0012139582F, 0.0012476687F, 0.0012818405F, 0.0013164736F,
  143182. 0.0013515679F, 0.0013871235F, 0.0014231402F, 0.0014596182F,
  143183. 0.0014965573F, 0.0015339576F, 0.0015718190F, 0.0016101415F,
  143184. 0.0016489251F, 0.0016881698F, 0.0017278754F, 0.0017680421F,
  143185. 0.0018086698F, 0.0018497584F, 0.0018913080F, 0.0019333185F,
  143186. 0.0019757898F, 0.0020187221F, 0.0020621151F, 0.0021059690F,
  143187. 0.0021502837F, 0.0021950591F, 0.0022402953F, 0.0022859921F,
  143188. 0.0023321497F, 0.0023787679F, 0.0024258467F, 0.0024733861F,
  143189. 0.0025213861F, 0.0025698466F, 0.0026187676F, 0.0026681491F,
  143190. 0.0027179911F, 0.0027682935F, 0.0028190562F, 0.0028702794F,
  143191. 0.0029219628F, 0.0029741066F, 0.0030267107F, 0.0030797749F,
  143192. 0.0031332994F, 0.0031872841F, 0.0032417289F, 0.0032966338F,
  143193. 0.0033519988F, 0.0034078238F, 0.0034641089F, 0.0035208539F,
  143194. 0.0035780589F, 0.0036357237F, 0.0036938485F, 0.0037524331F,
  143195. 0.0038114775F, 0.0038709817F, 0.0039309456F, 0.0039913692F,
  143196. 0.0040522524F, 0.0041135953F, 0.0041753978F, 0.0042376599F,
  143197. 0.0043003814F, 0.0043635624F, 0.0044272029F, 0.0044913028F,
  143198. 0.0045558620F, 0.0046208806F, 0.0046863585F, 0.0047522955F,
  143199. 0.0048186919F, 0.0048855473F, 0.0049528619F, 0.0050206356F,
  143200. 0.0050888684F, 0.0051575601F, 0.0052267108F, 0.0052963204F,
  143201. 0.0053663890F, 0.0054369163F, 0.0055079025F, 0.0055793474F,
  143202. 0.0056512510F, 0.0057236133F, 0.0057964342F, 0.0058697137F,
  143203. 0.0059434517F, 0.0060176482F, 0.0060923032F, 0.0061674166F,
  143204. 0.0062429883F, 0.0063190183F, 0.0063955066F, 0.0064724532F,
  143205. 0.0065498579F, 0.0066277207F, 0.0067060416F, 0.0067848205F,
  143206. 0.0068640575F, 0.0069437523F, 0.0070239051F, 0.0071045157F,
  143207. 0.0071855840F, 0.0072671102F, 0.0073490940F, 0.0074315355F,
  143208. 0.0075144345F, 0.0075977911F, 0.0076816052F, 0.0077658768F,
  143209. 0.0078506057F, 0.0079357920F, 0.0080214355F, 0.0081075363F,
  143210. 0.0081940943F, 0.0082811094F, 0.0083685816F, 0.0084565108F,
  143211. 0.0085448970F, 0.0086337401F, 0.0087230401F, 0.0088127969F,
  143212. 0.0089030104F, 0.0089936807F, 0.0090848076F, 0.0091763911F,
  143213. 0.0092684311F, 0.0093609276F, 0.0094538805F, 0.0095472898F,
  143214. 0.0096411554F, 0.0097354772F, 0.0098302552F, 0.0099254894F,
  143215. 0.0100211796F, 0.0101173259F, 0.0102139281F, 0.0103109863F,
  143216. 0.0104085002F, 0.0105064700F, 0.0106048955F, 0.0107037766F,
  143217. 0.0108031133F, 0.0109029056F, 0.0110031534F, 0.0111038565F,
  143218. 0.0112050151F, 0.0113066289F, 0.0114086980F, 0.0115112222F,
  143219. 0.0116142015F, 0.0117176359F, 0.0118215252F, 0.0119258695F,
  143220. 0.0120306686F, 0.0121359225F, 0.0122416312F, 0.0123477944F,
  143221. 0.0124544123F, 0.0125614847F, 0.0126690116F, 0.0127769928F,
  143222. 0.0128854284F, 0.0129943182F, 0.0131036623F, 0.0132134604F,
  143223. 0.0133237126F, 0.0134344188F, 0.0135455790F, 0.0136571929F,
  143224. 0.0137692607F, 0.0138817821F, 0.0139947572F, 0.0141081859F,
  143225. 0.0142220681F, 0.0143364037F, 0.0144511927F, 0.0145664350F,
  143226. 0.0146821304F, 0.0147982791F, 0.0149148808F, 0.0150319355F,
  143227. 0.0151494431F, 0.0152674036F, 0.0153858168F, 0.0155046828F,
  143228. 0.0156240014F, 0.0157437726F, 0.0158639962F, 0.0159846723F,
  143229. 0.0161058007F, 0.0162273814F, 0.0163494142F, 0.0164718991F,
  143230. 0.0165948361F, 0.0167182250F, 0.0168420658F, 0.0169663584F,
  143231. 0.0170911027F, 0.0172162987F, 0.0173419462F, 0.0174680452F,
  143232. 0.0175945956F, 0.0177215974F, 0.0178490504F, 0.0179769545F,
  143233. 0.0181053098F, 0.0182341160F, 0.0183633732F, 0.0184930812F,
  143234. 0.0186232399F, 0.0187538494F, 0.0188849094F, 0.0190164200F,
  143235. 0.0191483809F, 0.0192807923F, 0.0194136539F, 0.0195469656F,
  143236. 0.0196807275F, 0.0198149394F, 0.0199496012F, 0.0200847128F,
  143237. 0.0202202742F, 0.0203562853F, 0.0204927460F, 0.0206296561F,
  143238. 0.0207670157F, 0.0209048245F, 0.0210430826F, 0.0211817899F,
  143239. 0.0213209462F, 0.0214605515F, 0.0216006057F, 0.0217411086F,
  143240. 0.0218820603F, 0.0220234605F, 0.0221653093F, 0.0223076066F,
  143241. 0.0224503521F, 0.0225935459F, 0.0227371879F, 0.0228812779F,
  143242. 0.0230258160F, 0.0231708018F, 0.0233162355F, 0.0234621169F,
  143243. 0.0236084459F, 0.0237552224F, 0.0239024462F, 0.0240501175F,
  143244. 0.0241982359F, 0.0243468015F, 0.0244958141F, 0.0246452736F,
  143245. 0.0247951800F, 0.0249455331F, 0.0250963329F, 0.0252475792F,
  143246. 0.0253992720F, 0.0255514111F, 0.0257039965F, 0.0258570281F,
  143247. 0.0260105057F, 0.0261644293F, 0.0263187987F, 0.0264736139F,
  143248. 0.0266288747F, 0.0267845811F, 0.0269407330F, 0.0270973302F,
  143249. 0.0272543727F, 0.0274118604F, 0.0275697930F, 0.0277281707F,
  143250. 0.0278869932F, 0.0280462604F, 0.0282059723F, 0.0283661287F,
  143251. 0.0285267295F, 0.0286877747F, 0.0288492641F, 0.0290111976F,
  143252. 0.0291735751F, 0.0293363965F, 0.0294996617F, 0.0296633706F,
  143253. 0.0298275231F, 0.0299921190F, 0.0301571583F, 0.0303226409F,
  143254. 0.0304885667F, 0.0306549354F, 0.0308217472F, 0.0309890017F,
  143255. 0.0311566989F, 0.0313248388F, 0.0314934211F, 0.0316624459F,
  143256. 0.0318319128F, 0.0320018220F, 0.0321721732F, 0.0323429663F,
  143257. 0.0325142013F, 0.0326858779F, 0.0328579962F, 0.0330305559F,
  143258. 0.0332035570F, 0.0333769994F, 0.0335508829F, 0.0337252074F,
  143259. 0.0338999728F, 0.0340751790F, 0.0342508259F, 0.0344269134F,
  143260. 0.0346034412F, 0.0347804094F, 0.0349578178F, 0.0351356663F,
  143261. 0.0353139548F, 0.0354926831F, 0.0356718511F, 0.0358514588F,
  143262. 0.0360315059F, 0.0362119924F, 0.0363929182F, 0.0365742831F,
  143263. 0.0367560870F, 0.0369383297F, 0.0371210113F, 0.0373041315F,
  143264. 0.0374876902F, 0.0376716873F, 0.0378561226F, 0.0380409961F,
  143265. 0.0382263077F, 0.0384120571F, 0.0385982443F, 0.0387848691F,
  143266. 0.0389719315F, 0.0391594313F, 0.0393473683F, 0.0395357425F,
  143267. 0.0397245537F, 0.0399138017F, 0.0401034866F, 0.0402936080F,
  143268. 0.0404841660F, 0.0406751603F, 0.0408665909F, 0.0410584576F,
  143269. 0.0412507603F, 0.0414434988F, 0.0416366731F, 0.0418302829F,
  143270. 0.0420243282F, 0.0422188088F, 0.0424137246F, 0.0426090755F,
  143271. 0.0428048613F, 0.0430010819F, 0.0431977371F, 0.0433948269F,
  143272. 0.0435923511F, 0.0437903095F, 0.0439887020F, 0.0441875285F,
  143273. 0.0443867889F, 0.0445864830F, 0.0447866106F, 0.0449871717F,
  143274. 0.0451881661F, 0.0453895936F, 0.0455914542F, 0.0457937477F,
  143275. 0.0459964738F, 0.0461996326F, 0.0464032239F, 0.0466072475F,
  143276. 0.0468117032F, 0.0470165910F, 0.0472219107F, 0.0474276622F,
  143277. 0.0476338452F, 0.0478404597F, 0.0480475056F, 0.0482549827F,
  143278. 0.0484628907F, 0.0486712297F, 0.0488799994F, 0.0490891998F,
  143279. 0.0492988306F, 0.0495088917F, 0.0497193830F, 0.0499303043F,
  143280. 0.0501416554F, 0.0503534363F, 0.0505656468F, 0.0507782867F,
  143281. 0.0509913559F, 0.0512048542F, 0.0514187815F, 0.0516331376F,
  143282. 0.0518479225F, 0.0520631358F, 0.0522787775F, 0.0524948475F,
  143283. 0.0527113455F, 0.0529282715F, 0.0531456252F, 0.0533634066F,
  143284. 0.0535816154F, 0.0538002515F, 0.0540193148F, 0.0542388051F,
  143285. 0.0544587222F, 0.0546790660F, 0.0548998364F, 0.0551210331F,
  143286. 0.0553426561F, 0.0555647051F, 0.0557871801F, 0.0560100807F,
  143287. 0.0562334070F, 0.0564571587F, 0.0566813357F, 0.0569059378F,
  143288. 0.0571309649F, 0.0573564168F, 0.0575822933F, 0.0578085942F,
  143289. 0.0580353195F, 0.0582624689F, 0.0584900423F, 0.0587180396F,
  143290. 0.0589464605F, 0.0591753049F, 0.0594045726F, 0.0596342635F,
  143291. 0.0598643774F, 0.0600949141F, 0.0603258735F, 0.0605572555F,
  143292. 0.0607890597F, 0.0610212862F, 0.0612539346F, 0.0614870049F,
  143293. 0.0617204968F, 0.0619544103F, 0.0621887451F, 0.0624235010F,
  143294. 0.0626586780F, 0.0628942758F, 0.0631302942F, 0.0633667331F,
  143295. 0.0636035923F, 0.0638408717F, 0.0640785710F, 0.0643166901F,
  143296. 0.0645552288F, 0.0647941870F, 0.0650335645F, 0.0652733610F,
  143297. 0.0655135765F, 0.0657542108F, 0.0659952636F, 0.0662367348F,
  143298. 0.0664786242F, 0.0667209316F, 0.0669636570F, 0.0672068000F,
  143299. 0.0674503605F, 0.0676943384F, 0.0679387334F, 0.0681835454F,
  143300. 0.0684287742F, 0.0686744196F, 0.0689204814F, 0.0691669595F,
  143301. 0.0694138536F, 0.0696611637F, 0.0699088894F, 0.0701570307F,
  143302. 0.0704055873F, 0.0706545590F, 0.0709039458F, 0.0711537473F,
  143303. 0.0714039634F, 0.0716545939F, 0.0719056387F, 0.0721570975F,
  143304. 0.0724089702F, 0.0726612565F, 0.0729139563F, 0.0731670694F,
  143305. 0.0734205956F, 0.0736745347F, 0.0739288866F, 0.0741836510F,
  143306. 0.0744388277F, 0.0746944166F, 0.0749504175F, 0.0752068301F,
  143307. 0.0754636543F, 0.0757208899F, 0.0759785367F, 0.0762365946F,
  143308. 0.0764950632F, 0.0767539424F, 0.0770132320F, 0.0772729319F,
  143309. 0.0775330418F, 0.0777935616F, 0.0780544909F, 0.0783158298F,
  143310. 0.0785775778F, 0.0788397349F, 0.0791023009F, 0.0793652755F,
  143311. 0.0796286585F, 0.0798924498F, 0.0801566492F, 0.0804212564F,
  143312. 0.0806862712F, 0.0809516935F, 0.0812175231F, 0.0814837597F,
  143313. 0.0817504031F, 0.0820174532F, 0.0822849097F, 0.0825527724F,
  143314. 0.0828210412F, 0.0830897158F, 0.0833587960F, 0.0836282816F,
  143315. 0.0838981724F, 0.0841684682F, 0.0844391688F, 0.0847102740F,
  143316. 0.0849817835F, 0.0852536973F, 0.0855260150F, 0.0857987364F,
  143317. 0.0860718614F, 0.0863453897F, 0.0866193211F, 0.0868936554F,
  143318. 0.0871683924F, 0.0874435319F, 0.0877190737F, 0.0879950175F,
  143319. 0.0882713632F, 0.0885481105F, 0.0888252592F, 0.0891028091F,
  143320. 0.0893807600F, 0.0896591117F, 0.0899378639F, 0.0902170165F,
  143321. 0.0904965692F, 0.0907765218F, 0.0910568740F, 0.0913376258F,
  143322. 0.0916187767F, 0.0919003268F, 0.0921822756F, 0.0924646230F,
  143323. 0.0927473687F, 0.0930305126F, 0.0933140545F, 0.0935979940F,
  143324. 0.0938823310F, 0.0941670653F, 0.0944521966F, 0.0947377247F,
  143325. 0.0950236494F, 0.0953099704F, 0.0955966876F, 0.0958838007F,
  143326. 0.0961713094F, 0.0964592136F, 0.0967475131F, 0.0970362075F,
  143327. 0.0973252967F, 0.0976147805F, 0.0979046585F, 0.0981949307F,
  143328. 0.0984855967F, 0.0987766563F, 0.0990681093F, 0.0993599555F,
  143329. 0.0996521945F, 0.0999448263F, 0.1002378506F, 0.1005312671F,
  143330. 0.1008250755F, 0.1011192757F, 0.1014138675F, 0.1017088505F,
  143331. 0.1020042246F, 0.1022999895F, 0.1025961450F, 0.1028926909F,
  143332. 0.1031896268F, 0.1034869526F, 0.1037846680F, 0.1040827729F,
  143333. 0.1043812668F, 0.1046801497F, 0.1049794213F, 0.1052790813F,
  143334. 0.1055791294F, 0.1058795656F, 0.1061803894F, 0.1064816006F,
  143335. 0.1067831991F, 0.1070851846F, 0.1073875568F, 0.1076903155F,
  143336. 0.1079934604F, 0.1082969913F, 0.1086009079F, 0.1089052101F,
  143337. 0.1092098975F, 0.1095149699F, 0.1098204270F, 0.1101262687F,
  143338. 0.1104324946F, 0.1107391045F, 0.1110460982F, 0.1113534754F,
  143339. 0.1116612359F, 0.1119693793F, 0.1122779055F, 0.1125868142F,
  143340. 0.1128961052F, 0.1132057781F, 0.1135158328F, 0.1138262690F,
  143341. 0.1141370863F, 0.1144482847F, 0.1147598638F, 0.1150718233F,
  143342. 0.1153841631F, 0.1156968828F, 0.1160099822F, 0.1163234610F,
  143343. 0.1166373190F, 0.1169515559F, 0.1172661714F, 0.1175811654F,
  143344. 0.1178965374F, 0.1182122874F, 0.1185284149F, 0.1188449198F,
  143345. 0.1191618018F, 0.1194790606F, 0.1197966960F, 0.1201147076F,
  143346. 0.1204330953F, 0.1207518587F, 0.1210709976F, 0.1213905118F,
  143347. 0.1217104009F, 0.1220306647F, 0.1223513029F, 0.1226723153F,
  143348. 0.1229937016F, 0.1233154615F, 0.1236375948F, 0.1239601011F,
  143349. 0.1242829803F, 0.1246062319F, 0.1249298559F, 0.1252538518F,
  143350. 0.1255782195F, 0.1259029586F, 0.1262280689F, 0.1265535501F,
  143351. 0.1268794019F, 0.1272056241F, 0.1275322163F, 0.1278591784F,
  143352. 0.1281865099F, 0.1285142108F, 0.1288422805F, 0.1291707190F,
  143353. 0.1294995259F, 0.1298287009F, 0.1301582437F, 0.1304881542F,
  143354. 0.1308184319F, 0.1311490766F, 0.1314800881F, 0.1318114660F,
  143355. 0.1321432100F, 0.1324753200F, 0.1328077955F, 0.1331406364F,
  143356. 0.1334738422F, 0.1338074129F, 0.1341413479F, 0.1344756472F,
  143357. 0.1348103103F, 0.1351453370F, 0.1354807270F, 0.1358164801F,
  143358. 0.1361525959F, 0.1364890741F, 0.1368259145F, 0.1371631167F,
  143359. 0.1375006805F, 0.1378386056F, 0.1381768917F, 0.1385155384F,
  143360. 0.1388545456F, 0.1391939129F, 0.1395336400F, 0.1398737266F,
  143361. 0.1402141724F, 0.1405549772F, 0.1408961406F, 0.1412376623F,
  143362. 0.1415795421F, 0.1419217797F, 0.1422643746F, 0.1426073268F,
  143363. 0.1429506358F, 0.1432943013F, 0.1436383231F, 0.1439827008F,
  143364. 0.1443274342F, 0.1446725229F, 0.1450179667F, 0.1453637652F,
  143365. 0.1457099181F, 0.1460564252F, 0.1464032861F, 0.1467505006F,
  143366. 0.1470980682F, 0.1474459888F, 0.1477942620F, 0.1481428875F,
  143367. 0.1484918651F, 0.1488411942F, 0.1491908748F, 0.1495409065F,
  143368. 0.1498912889F, 0.1502420218F, 0.1505931048F, 0.1509445376F,
  143369. 0.1512963200F, 0.1516484516F, 0.1520009321F, 0.1523537612F,
  143370. 0.1527069385F, 0.1530604638F, 0.1534143368F, 0.1537685571F,
  143371. 0.1541231244F, 0.1544780384F, 0.1548332987F, 0.1551889052F,
  143372. 0.1555448574F, 0.1559011550F, 0.1562577978F, 0.1566147853F,
  143373. 0.1569721173F, 0.1573297935F, 0.1576878135F, 0.1580461771F,
  143374. 0.1584048838F, 0.1587639334F, 0.1591233255F, 0.1594830599F,
  143375. 0.1598431361F, 0.1602035540F, 0.1605643131F, 0.1609254131F,
  143376. 0.1612868537F, 0.1616486346F, 0.1620107555F, 0.1623732160F,
  143377. 0.1627360158F, 0.1630991545F, 0.1634626319F, 0.1638264476F,
  143378. 0.1641906013F, 0.1645550926F, 0.1649199212F, 0.1652850869F,
  143379. 0.1656505892F, 0.1660164278F, 0.1663826024F, 0.1667491127F,
  143380. 0.1671159583F, 0.1674831388F, 0.1678506541F, 0.1682185036F,
  143381. 0.1685866872F, 0.1689552044F, 0.1693240549F, 0.1696932384F,
  143382. 0.1700627545F, 0.1704326029F, 0.1708027833F, 0.1711732952F,
  143383. 0.1715441385F, 0.1719153127F, 0.1722868175F, 0.1726586526F,
  143384. 0.1730308176F, 0.1734033121F, 0.1737761359F, 0.1741492886F,
  143385. 0.1745227698F, 0.1748965792F, 0.1752707164F, 0.1756451812F,
  143386. 0.1760199731F, 0.1763950918F, 0.1767705370F, 0.1771463083F,
  143387. 0.1775224054F, 0.1778988279F, 0.1782755754F, 0.1786526477F,
  143388. 0.1790300444F, 0.1794077651F, 0.1797858094F, 0.1801641771F,
  143389. 0.1805428677F, 0.1809218810F, 0.1813012165F, 0.1816808739F,
  143390. 0.1820608528F, 0.1824411530F, 0.1828217739F, 0.1832027154F,
  143391. 0.1835839770F, 0.1839655584F, 0.1843474592F, 0.1847296790F,
  143392. 0.1851122175F, 0.1854950744F, 0.1858782492F, 0.1862617417F,
  143393. 0.1866455514F, 0.1870296780F, 0.1874141211F, 0.1877988804F,
  143394. 0.1881839555F, 0.1885693461F, 0.1889550517F, 0.1893410721F,
  143395. 0.1897274068F, 0.1901140555F, 0.1905010178F, 0.1908882933F,
  143396. 0.1912758818F, 0.1916637828F, 0.1920519959F, 0.1924405208F,
  143397. 0.1928293571F, 0.1932185044F, 0.1936079625F, 0.1939977308F,
  143398. 0.1943878091F, 0.1947781969F, 0.1951688939F, 0.1955598998F,
  143399. 0.1959512141F, 0.1963428364F, 0.1967347665F, 0.1971270038F,
  143400. 0.1975195482F, 0.1979123990F, 0.1983055561F, 0.1986990190F,
  143401. 0.1990927873F, 0.1994868607F, 0.1998812388F, 0.2002759212F,
  143402. 0.2006709075F, 0.2010661974F, 0.2014617904F, 0.2018576862F,
  143403. 0.2022538844F, 0.2026503847F, 0.2030471865F, 0.2034442897F,
  143404. 0.2038416937F, 0.2042393982F, 0.2046374028F, 0.2050357071F,
  143405. 0.2054343107F, 0.2058332133F, 0.2062324145F, 0.2066319138F,
  143406. 0.2070317110F, 0.2074318055F, 0.2078321970F, 0.2082328852F,
  143407. 0.2086338696F, 0.2090351498F, 0.2094367255F, 0.2098385962F,
  143408. 0.2102407617F, 0.2106432213F, 0.2110459749F, 0.2114490220F,
  143409. 0.2118523621F, 0.2122559950F, 0.2126599202F, 0.2130641373F,
  143410. 0.2134686459F, 0.2138734456F, 0.2142785361F, 0.2146839168F,
  143411. 0.2150895875F, 0.2154955478F, 0.2159017972F, 0.2163083353F,
  143412. 0.2167151617F, 0.2171222761F, 0.2175296780F, 0.2179373670F,
  143413. 0.2183453428F, 0.2187536049F, 0.2191621529F, 0.2195709864F,
  143414. 0.2199801051F, 0.2203895085F, 0.2207991961F, 0.2212091677F,
  143415. 0.2216194228F, 0.2220299610F, 0.2224407818F, 0.2228518850F,
  143416. 0.2232632699F, 0.2236749364F, 0.2240868839F, 0.2244991121F,
  143417. 0.2249116204F, 0.2253244086F, 0.2257374763F, 0.2261508229F,
  143418. 0.2265644481F, 0.2269783514F, 0.2273925326F, 0.2278069911F,
  143419. 0.2282217265F, 0.2286367384F, 0.2290520265F, 0.2294675902F,
  143420. 0.2298834292F, 0.2302995431F, 0.2307159314F, 0.2311325937F,
  143421. 0.2315495297F, 0.2319667388F, 0.2323842207F, 0.2328019749F,
  143422. 0.2332200011F, 0.2336382988F, 0.2340568675F, 0.2344757070F,
  143423. 0.2348948166F, 0.2353141961F, 0.2357338450F, 0.2361537629F,
  143424. 0.2365739493F, 0.2369944038F, 0.2374151261F, 0.2378361156F,
  143425. 0.2382573720F, 0.2386788948F, 0.2391006836F, 0.2395227380F,
  143426. 0.2399450575F, 0.2403676417F, 0.2407904902F, 0.2412136026F,
  143427. 0.2416369783F, 0.2420606171F, 0.2424845185F, 0.2429086820F,
  143428. 0.2433331072F, 0.2437577936F, 0.2441827409F, 0.2446079486F,
  143429. 0.2450334163F, 0.2454591435F, 0.2458851298F, 0.2463113747F,
  143430. 0.2467378779F, 0.2471646389F, 0.2475916573F, 0.2480189325F,
  143431. 0.2484464643F, 0.2488742521F, 0.2493022955F, 0.2497305940F,
  143432. 0.2501591473F, 0.2505879549F, 0.2510170163F, 0.2514463311F,
  143433. 0.2518758989F, 0.2523057193F, 0.2527357916F, 0.2531661157F,
  143434. 0.2535966909F, 0.2540275169F, 0.2544585931F, 0.2548899193F,
  143435. 0.2553214948F, 0.2557533193F, 0.2561853924F, 0.2566177135F,
  143436. 0.2570502822F, 0.2574830981F, 0.2579161608F, 0.2583494697F,
  143437. 0.2587830245F, 0.2592168246F, 0.2596508697F, 0.2600851593F,
  143438. 0.2605196929F, 0.2609544701F, 0.2613894904F, 0.2618247534F,
  143439. 0.2622602586F, 0.2626960055F, 0.2631319938F, 0.2635682230F,
  143440. 0.2640046925F, 0.2644414021F, 0.2648783511F, 0.2653155391F,
  143441. 0.2657529657F, 0.2661906305F, 0.2666285329F, 0.2670666725F,
  143442. 0.2675050489F, 0.2679436616F, 0.2683825101F, 0.2688215940F,
  143443. 0.2692609127F, 0.2697004660F, 0.2701402532F, 0.2705802739F,
  143444. 0.2710205278F, 0.2714610142F, 0.2719017327F, 0.2723426830F,
  143445. 0.2727838644F, 0.2732252766F, 0.2736669191F, 0.2741087914F,
  143446. 0.2745508930F, 0.2749932235F, 0.2754357824F, 0.2758785693F,
  143447. 0.2763215837F, 0.2767648251F, 0.2772082930F, 0.2776519870F,
  143448. 0.2780959066F, 0.2785400513F, 0.2789844207F, 0.2794290143F,
  143449. 0.2798738316F, 0.2803188722F, 0.2807641355F, 0.2812096211F,
  143450. 0.2816553286F, 0.2821012574F, 0.2825474071F, 0.2829937773F,
  143451. 0.2834403673F, 0.2838871768F, 0.2843342053F, 0.2847814523F,
  143452. 0.2852289174F, 0.2856765999F, 0.2861244996F, 0.2865726159F,
  143453. 0.2870209482F, 0.2874694962F, 0.2879182594F, 0.2883672372F,
  143454. 0.2888164293F, 0.2892658350F, 0.2897154540F, 0.2901652858F,
  143455. 0.2906153298F, 0.2910655856F, 0.2915160527F, 0.2919667306F,
  143456. 0.2924176189F, 0.2928687171F, 0.2933200246F, 0.2937715409F,
  143457. 0.2942232657F, 0.2946751984F, 0.2951273386F, 0.2955796856F,
  143458. 0.2960322391F, 0.2964849986F, 0.2969379636F, 0.2973911335F,
  143459. 0.2978445080F, 0.2982980864F, 0.2987518684F, 0.2992058534F,
  143460. 0.2996600409F, 0.3001144305F, 0.3005690217F, 0.3010238139F,
  143461. 0.3014788067F, 0.3019339995F, 0.3023893920F, 0.3028449835F,
  143462. 0.3033007736F, 0.3037567618F, 0.3042129477F, 0.3046693306F,
  143463. 0.3051259102F, 0.3055826859F, 0.3060396572F, 0.3064968236F,
  143464. 0.3069541847F, 0.3074117399F, 0.3078694887F, 0.3083274307F,
  143465. 0.3087855653F, 0.3092438920F, 0.3097024104F, 0.3101611199F,
  143466. 0.3106200200F, 0.3110791103F, 0.3115383902F, 0.3119978592F,
  143467. 0.3124575169F, 0.3129173627F, 0.3133773961F, 0.3138376166F,
  143468. 0.3142980238F, 0.3147586170F, 0.3152193959F, 0.3156803598F,
  143469. 0.3161415084F, 0.3166028410F, 0.3170643573F, 0.3175260566F,
  143470. 0.3179879384F, 0.3184500023F, 0.3189122478F, 0.3193746743F,
  143471. 0.3198372814F, 0.3203000685F, 0.3207630351F, 0.3212261807F,
  143472. 0.3216895048F, 0.3221530069F, 0.3226166865F, 0.3230805430F,
  143473. 0.3235445760F, 0.3240087849F, 0.3244731693F, 0.3249377285F,
  143474. 0.3254024622F, 0.3258673698F, 0.3263324507F, 0.3267977045F,
  143475. 0.3272631306F, 0.3277287286F, 0.3281944978F, 0.3286604379F,
  143476. 0.3291265482F, 0.3295928284F, 0.3300592777F, 0.3305258958F,
  143477. 0.3309926821F, 0.3314596361F, 0.3319267573F, 0.3323940451F,
  143478. 0.3328614990F, 0.3333291186F, 0.3337969033F, 0.3342648525F,
  143479. 0.3347329658F, 0.3352012427F, 0.3356696825F, 0.3361382849F,
  143480. 0.3366070492F, 0.3370759749F, 0.3375450616F, 0.3380143087F,
  143481. 0.3384837156F, 0.3389532819F, 0.3394230071F, 0.3398928905F,
  143482. 0.3403629317F, 0.3408331302F, 0.3413034854F, 0.3417739967F,
  143483. 0.3422446638F, 0.3427154860F, 0.3431864628F, 0.3436575938F,
  143484. 0.3441288782F, 0.3446003158F, 0.3450719058F, 0.3455436478F,
  143485. 0.3460155412F, 0.3464875856F, 0.3469597804F, 0.3474321250F,
  143486. 0.3479046189F, 0.3483772617F, 0.3488500527F, 0.3493229914F,
  143487. 0.3497960774F, 0.3502693100F, 0.3507426887F, 0.3512162131F,
  143488. 0.3516898825F, 0.3521636965F, 0.3526376545F, 0.3531117559F,
  143489. 0.3535860003F, 0.3540603870F, 0.3545349157F, 0.3550095856F,
  143490. 0.3554843964F, 0.3559593474F, 0.3564344381F, 0.3569096680F,
  143491. 0.3573850366F, 0.3578605432F, 0.3583361875F, 0.3588119687F,
  143492. 0.3592878865F, 0.3597639402F, 0.3602401293F, 0.3607164533F,
  143493. 0.3611929117F, 0.3616695038F, 0.3621462292F, 0.3626230873F,
  143494. 0.3631000776F, 0.3635771995F, 0.3640544525F, 0.3645318360F,
  143495. 0.3650093496F, 0.3654869926F, 0.3659647645F, 0.3664426648F,
  143496. 0.3669206930F, 0.3673988484F, 0.3678771306F, 0.3683555390F,
  143497. 0.3688340731F, 0.3693127322F, 0.3697915160F, 0.3702704237F,
  143498. 0.3707494549F, 0.3712286091F, 0.3717078857F, 0.3721872840F,
  143499. 0.3726668037F, 0.3731464441F, 0.3736262047F, 0.3741060850F,
  143500. 0.3745860843F, 0.3750662023F, 0.3755464382F, 0.3760267915F,
  143501. 0.3765072618F, 0.3769878484F, 0.3774685509F, 0.3779493686F,
  143502. 0.3784303010F, 0.3789113475F, 0.3793925076F, 0.3798737809F,
  143503. 0.3803551666F, 0.3808366642F, 0.3813182733F, 0.3817999932F,
  143504. 0.3822818234F, 0.3827637633F, 0.3832458124F, 0.3837279702F,
  143505. 0.3842102360F, 0.3846926093F, 0.3851750897F, 0.3856576764F,
  143506. 0.3861403690F, 0.3866231670F, 0.3871060696F, 0.3875890765F,
  143507. 0.3880721870F, 0.3885554007F, 0.3890387168F, 0.3895221349F,
  143508. 0.3900056544F, 0.3904892748F, 0.3909729955F, 0.3914568160F,
  143509. 0.3919407356F, 0.3924247539F, 0.3929088702F, 0.3933930841F,
  143510. 0.3938773949F, 0.3943618021F, 0.3948463052F, 0.3953309035F,
  143511. 0.3958155966F, 0.3963003838F, 0.3967852646F, 0.3972702385F,
  143512. 0.3977553048F, 0.3982404631F, 0.3987257127F, 0.3992110531F,
  143513. 0.3996964838F, 0.4001820041F, 0.4006676136F, 0.4011533116F,
  143514. 0.4016390976F, 0.4021249710F, 0.4026109313F, 0.4030969779F,
  143515. 0.4035831102F, 0.4040693277F, 0.4045556299F, 0.4050420160F,
  143516. 0.4055284857F, 0.4060150383F, 0.4065016732F, 0.4069883899F,
  143517. 0.4074751879F, 0.4079620665F, 0.4084490252F, 0.4089360635F,
  143518. 0.4094231807F, 0.4099103763F, 0.4103976498F, 0.4108850005F,
  143519. 0.4113724280F, 0.4118599315F, 0.4123475107F, 0.4128351648F,
  143520. 0.4133228934F, 0.4138106959F, 0.4142985716F, 0.4147865201F,
  143521. 0.4152745408F, 0.4157626330F, 0.4162507963F, 0.4167390301F,
  143522. 0.4172273337F, 0.4177157067F, 0.4182041484F, 0.4186926583F,
  143523. 0.4191812359F, 0.4196698805F, 0.4201585915F, 0.4206473685F,
  143524. 0.4211362108F, 0.4216251179F, 0.4221140892F, 0.4226031241F,
  143525. 0.4230922221F, 0.4235813826F, 0.4240706050F, 0.4245598887F,
  143526. 0.4250492332F, 0.4255386379F, 0.4260281022F, 0.4265176256F,
  143527. 0.4270072075F, 0.4274968473F, 0.4279865445F, 0.4284762984F,
  143528. 0.4289661086F, 0.4294559743F, 0.4299458951F, 0.4304358704F,
  143529. 0.4309258996F, 0.4314159822F, 0.4319061175F, 0.4323963050F,
  143530. 0.4328865441F, 0.4333768342F, 0.4338671749F, 0.4343575654F,
  143531. 0.4348480052F, 0.4353384938F, 0.4358290306F, 0.4363196149F,
  143532. 0.4368102463F, 0.4373009241F, 0.4377916478F, 0.4382824168F,
  143533. 0.4387732305F, 0.4392640884F, 0.4397549899F, 0.4402459343F,
  143534. 0.4407369212F, 0.4412279499F, 0.4417190198F, 0.4422101305F,
  143535. 0.4427012813F, 0.4431924717F, 0.4436837010F, 0.4441749686F,
  143536. 0.4446662742F, 0.4451576169F, 0.4456489963F, 0.4461404118F,
  143537. 0.4466318628F, 0.4471233487F, 0.4476148690F, 0.4481064230F,
  143538. 0.4485980103F, 0.4490896302F, 0.4495812821F, 0.4500729654F,
  143539. 0.4505646797F, 0.4510564243F, 0.4515481986F, 0.4520400021F,
  143540. 0.4525318341F, 0.4530236942F, 0.4535155816F, 0.4540074959F,
  143541. 0.4544994365F, 0.4549914028F, 0.4554833941F, 0.4559754100F,
  143542. 0.4564674499F, 0.4569595131F, 0.4574515991F, 0.4579437074F,
  143543. 0.4584358372F, 0.4589279881F, 0.4594201595F, 0.4599123508F,
  143544. 0.4604045615F, 0.4608967908F, 0.4613890383F, 0.4618813034F,
  143545. 0.4623735855F, 0.4628658841F, 0.4633581984F, 0.4638505281F,
  143546. 0.4643428724F, 0.4648352308F, 0.4653276028F, 0.4658199877F,
  143547. 0.4663123849F, 0.4668047940F, 0.4672972143F, 0.4677896451F,
  143548. 0.4682820861F, 0.4687745365F, 0.4692669958F, 0.4697594634F,
  143549. 0.4702519387F, 0.4707444211F, 0.4712369102F, 0.4717294052F,
  143550. 0.4722219056F, 0.4727144109F, 0.4732069204F, 0.4736994336F,
  143551. 0.4741919498F, 0.4746844686F, 0.4751769893F, 0.4756695113F,
  143552. 0.4761620341F, 0.4766545571F, 0.4771470797F, 0.4776396013F,
  143553. 0.4781321213F, 0.4786246392F, 0.4791171544F, 0.4796096663F,
  143554. 0.4801021744F, 0.4805946779F, 0.4810871765F, 0.4815796694F,
  143555. 0.4820721561F, 0.4825646360F, 0.4830571086F, 0.4835495732F,
  143556. 0.4840420293F, 0.4845344763F, 0.4850269136F, 0.4855193407F,
  143557. 0.4860117569F, 0.4865041617F, 0.4869965545F, 0.4874889347F,
  143558. 0.4879813018F, 0.4884736551F, 0.4889659941F, 0.4894583182F,
  143559. 0.4899506268F, 0.4904429193F, 0.4909351952F, 0.4914274538F,
  143560. 0.4919196947F, 0.4924119172F, 0.4929041207F, 0.4933963046F,
  143561. 0.4938884685F, 0.4943806116F, 0.4948727335F, 0.4953648335F,
  143562. 0.4958569110F, 0.4963489656F, 0.4968409965F, 0.4973330032F,
  143563. 0.4978249852F, 0.4983169419F, 0.4988088726F, 0.4993007768F,
  143564. 0.4997926539F, 0.5002845034F, 0.5007763247F, 0.5012681171F,
  143565. 0.5017598801F, 0.5022516132F, 0.5027433157F, 0.5032349871F,
  143566. 0.5037266268F, 0.5042182341F, 0.5047098086F, 0.5052013497F,
  143567. 0.5056928567F, 0.5061843292F, 0.5066757664F, 0.5071671679F,
  143568. 0.5076585330F, 0.5081498613F, 0.5086411520F, 0.5091324047F,
  143569. 0.5096236187F, 0.5101147934F, 0.5106059284F, 0.5110970230F,
  143570. 0.5115880766F, 0.5120790887F, 0.5125700587F, 0.5130609860F,
  143571. 0.5135518700F, 0.5140427102F, 0.5145335059F, 0.5150242566F,
  143572. 0.5155149618F, 0.5160056208F, 0.5164962331F, 0.5169867980F,
  143573. 0.5174773151F, 0.5179677837F, 0.5184582033F, 0.5189485733F,
  143574. 0.5194388931F, 0.5199291621F, 0.5204193798F, 0.5209095455F,
  143575. 0.5213996588F, 0.5218897190F, 0.5223797256F, 0.5228696779F,
  143576. 0.5233595755F, 0.5238494177F, 0.5243392039F, 0.5248289337F,
  143577. 0.5253186063F, 0.5258082213F, 0.5262977781F, 0.5267872760F,
  143578. 0.5272767146F, 0.5277660932F, 0.5282554112F, 0.5287446682F,
  143579. 0.5292338635F, 0.5297229965F, 0.5302120667F, 0.5307010736F,
  143580. 0.5311900164F, 0.5316788947F, 0.5321677079F, 0.5326564554F,
  143581. 0.5331451366F, 0.5336337511F, 0.5341222981F, 0.5346107771F,
  143582. 0.5350991876F, 0.5355875290F, 0.5360758007F, 0.5365640021F,
  143583. 0.5370521327F, 0.5375401920F, 0.5380281792F, 0.5385160939F,
  143584. 0.5390039355F, 0.5394917034F, 0.5399793971F, 0.5404670159F,
  143585. 0.5409545594F, 0.5414420269F, 0.5419294179F, 0.5424167318F,
  143586. 0.5429039680F, 0.5433911261F, 0.5438782053F, 0.5443652051F,
  143587. 0.5448521250F, 0.5453389644F, 0.5458257228F, 0.5463123995F,
  143588. 0.5467989940F, 0.5472855057F, 0.5477719341F, 0.5482582786F,
  143589. 0.5487445387F, 0.5492307137F, 0.5497168031F, 0.5502028063F,
  143590. 0.5506887228F, 0.5511745520F, 0.5516602934F, 0.5521459463F,
  143591. 0.5526315103F, 0.5531169847F, 0.5536023690F, 0.5540876626F,
  143592. 0.5545728649F, 0.5550579755F, 0.5555429937F, 0.5560279189F,
  143593. 0.5565127507F, 0.5569974884F, 0.5574821315F, 0.5579666794F,
  143594. 0.5584511316F, 0.5589354875F, 0.5594197465F, 0.5599039080F,
  143595. 0.5603879716F, 0.5608719367F, 0.5613558026F, 0.5618395689F,
  143596. 0.5623232350F, 0.5628068002F, 0.5632902642F, 0.5637736262F,
  143597. 0.5642568858F, 0.5647400423F, 0.5652230953F, 0.5657060442F,
  143598. 0.5661888883F, 0.5666716272F, 0.5671542603F, 0.5676367870F,
  143599. 0.5681192069F, 0.5686015192F, 0.5690837235F, 0.5695658192F,
  143600. 0.5700478058F, 0.5705296827F, 0.5710114494F, 0.5714931052F,
  143601. 0.5719746497F, 0.5724560822F, 0.5729374023F, 0.5734186094F,
  143602. 0.5738997029F, 0.5743806823F, 0.5748615470F, 0.5753422965F,
  143603. 0.5758229301F, 0.5763034475F, 0.5767838480F, 0.5772641310F,
  143604. 0.5777442960F, 0.5782243426F, 0.5787042700F, 0.5791840778F,
  143605. 0.5796637654F, 0.5801433322F, 0.5806227778F, 0.5811021016F,
  143606. 0.5815813029F, 0.5820603814F, 0.5825393363F, 0.5830181673F,
  143607. 0.5834968737F, 0.5839754549F, 0.5844539105F, 0.5849322399F,
  143608. 0.5854104425F, 0.5858885179F, 0.5863664653F, 0.5868442844F,
  143609. 0.5873219746F, 0.5877995353F, 0.5882769660F, 0.5887542661F,
  143610. 0.5892314351F, 0.5897084724F, 0.5901853776F, 0.5906621500F,
  143611. 0.5911387892F, 0.5916152945F, 0.5920916655F, 0.5925679016F,
  143612. 0.5930440022F, 0.5935199669F, 0.5939957950F, 0.5944714861F,
  143613. 0.5949470396F, 0.5954224550F, 0.5958977317F, 0.5963728692F,
  143614. 0.5968478669F, 0.5973227244F, 0.5977974411F, 0.5982720163F,
  143615. 0.5987464497F, 0.5992207407F, 0.5996948887F, 0.6001688932F,
  143616. 0.6006427537F, 0.6011164696F, 0.6015900405F, 0.6020634657F,
  143617. 0.6025367447F, 0.6030098770F, 0.6034828621F, 0.6039556995F,
  143618. 0.6044283885F, 0.6049009288F, 0.6053733196F, 0.6058455606F,
  143619. 0.6063176512F, 0.6067895909F, 0.6072613790F, 0.6077330152F,
  143620. 0.6082044989F, 0.6086758295F, 0.6091470065F, 0.6096180294F,
  143621. 0.6100888977F, 0.6105596108F, 0.6110301682F, 0.6115005694F,
  143622. 0.6119708139F, 0.6124409011F, 0.6129108305F, 0.6133806017F,
  143623. 0.6138502139F, 0.6143196669F, 0.6147889599F, 0.6152580926F,
  143624. 0.6157270643F, 0.6161958746F, 0.6166645230F, 0.6171330088F,
  143625. 0.6176013317F, 0.6180694910F, 0.6185374863F, 0.6190053171F,
  143626. 0.6194729827F, 0.6199404828F, 0.6204078167F, 0.6208749841F,
  143627. 0.6213419842F, 0.6218088168F, 0.6222754811F, 0.6227419768F,
  143628. 0.6232083032F, 0.6236744600F, 0.6241404465F, 0.6246062622F,
  143629. 0.6250719067F, 0.6255373795F, 0.6260026799F, 0.6264678076F,
  143630. 0.6269327619F, 0.6273975425F, 0.6278621487F, 0.6283265800F,
  143631. 0.6287908361F, 0.6292549163F, 0.6297188201F, 0.6301825471F,
  143632. 0.6306460966F, 0.6311094683F, 0.6315726617F, 0.6320356761F,
  143633. 0.6324985111F, 0.6329611662F, 0.6334236410F, 0.6338859348F,
  143634. 0.6343480472F, 0.6348099777F, 0.6352717257F, 0.6357332909F,
  143635. 0.6361946726F, 0.6366558704F, 0.6371168837F, 0.6375777122F,
  143636. 0.6380383552F, 0.6384988123F, 0.6389590830F, 0.6394191668F,
  143637. 0.6398790631F, 0.6403387716F, 0.6407982916F, 0.6412576228F,
  143638. 0.6417167645F, 0.6421757163F, 0.6426344778F, 0.6430930483F,
  143639. 0.6435514275F, 0.6440096149F, 0.6444676098F, 0.6449254119F,
  143640. 0.6453830207F, 0.6458404356F, 0.6462976562F, 0.6467546820F,
  143641. 0.6472115125F, 0.6476681472F, 0.6481245856F, 0.6485808273F,
  143642. 0.6490368717F, 0.6494927183F, 0.6499483667F, 0.6504038164F,
  143643. 0.6508590670F, 0.6513141178F, 0.6517689684F, 0.6522236185F,
  143644. 0.6526780673F, 0.6531323146F, 0.6535863598F, 0.6540402024F,
  143645. 0.6544938419F, 0.6549472779F, 0.6554005099F, 0.6558535373F,
  143646. 0.6563063598F, 0.6567589769F, 0.6572113880F, 0.6576635927F,
  143647. 0.6581155906F, 0.6585673810F, 0.6590189637F, 0.6594703380F,
  143648. 0.6599215035F, 0.6603724598F, 0.6608232064F, 0.6612737427F,
  143649. 0.6617240684F, 0.6621741829F, 0.6626240859F, 0.6630737767F,
  143650. 0.6635232550F, 0.6639725202F, 0.6644215720F, 0.6648704098F,
  143651. 0.6653190332F, 0.6657674417F, 0.6662156348F, 0.6666636121F,
  143652. 0.6671113731F, 0.6675589174F, 0.6680062445F, 0.6684533538F,
  143653. 0.6689002450F, 0.6693469177F, 0.6697933712F, 0.6702396052F,
  143654. 0.6706856193F, 0.6711314129F, 0.6715769855F, 0.6720223369F,
  143655. 0.6724674664F, 0.6729123736F, 0.6733570581F, 0.6738015194F,
  143656. 0.6742457570F, 0.6746897706F, 0.6751335596F, 0.6755771236F,
  143657. 0.6760204621F, 0.6764635747F, 0.6769064609F, 0.6773491204F,
  143658. 0.6777915525F, 0.6782337570F, 0.6786757332F, 0.6791174809F,
  143659. 0.6795589995F, 0.6800002886F, 0.6804413477F, 0.6808821765F,
  143660. 0.6813227743F, 0.6817631409F, 0.6822032758F, 0.6826431785F,
  143661. 0.6830828485F, 0.6835222855F, 0.6839614890F, 0.6844004585F,
  143662. 0.6848391936F, 0.6852776939F, 0.6857159589F, 0.6861539883F,
  143663. 0.6865917815F, 0.6870293381F, 0.6874666576F, 0.6879037398F,
  143664. 0.6883405840F, 0.6887771899F, 0.6892135571F, 0.6896496850F,
  143665. 0.6900855733F, 0.6905212216F, 0.6909566294F, 0.6913917963F,
  143666. 0.6918267218F, 0.6922614055F, 0.6926958471F, 0.6931300459F,
  143667. 0.6935640018F, 0.6939977141F, 0.6944311825F, 0.6948644066F,
  143668. 0.6952973859F, 0.6957301200F, 0.6961626085F, 0.6965948510F,
  143669. 0.6970268470F, 0.6974585961F, 0.6978900980F, 0.6983213521F,
  143670. 0.6987523580F, 0.6991831154F, 0.6996136238F, 0.7000438828F,
  143671. 0.7004738921F, 0.7009036510F, 0.7013331594F, 0.7017624166F,
  143672. 0.7021914224F, 0.7026201763F, 0.7030486779F, 0.7034769268F,
  143673. 0.7039049226F, 0.7043326648F, 0.7047601531F, 0.7051873870F,
  143674. 0.7056143662F, 0.7060410902F, 0.7064675586F, 0.7068937711F,
  143675. 0.7073197271F, 0.7077454264F, 0.7081708684F, 0.7085960529F,
  143676. 0.7090209793F, 0.7094456474F, 0.7098700566F, 0.7102942066F,
  143677. 0.7107180970F, 0.7111417274F, 0.7115650974F, 0.7119882066F,
  143678. 0.7124110545F, 0.7128336409F, 0.7132559653F, 0.7136780272F,
  143679. 0.7140998264F, 0.7145213624F, 0.7149426348F, 0.7153636433F,
  143680. 0.7157843874F, 0.7162048668F, 0.7166250810F, 0.7170450296F,
  143681. 0.7174647124F, 0.7178841289F, 0.7183032786F, 0.7187221613F,
  143682. 0.7191407765F, 0.7195591239F, 0.7199772030F, 0.7203950135F,
  143683. 0.7208125550F, 0.7212298271F, 0.7216468294F, 0.7220635616F,
  143684. 0.7224800233F, 0.7228962140F, 0.7233121335F, 0.7237277813F,
  143685. 0.7241431571F, 0.7245582604F, 0.7249730910F, 0.7253876484F,
  143686. 0.7258019322F, 0.7262159422F, 0.7266296778F, 0.7270431388F,
  143687. 0.7274563247F, 0.7278692353F, 0.7282818700F, 0.7286942287F,
  143688. 0.7291063108F, 0.7295181160F, 0.7299296440F, 0.7303408944F,
  143689. 0.7307518669F, 0.7311625609F, 0.7315729763F, 0.7319831126F,
  143690. 0.7323929695F, 0.7328025466F, 0.7332118435F, 0.7336208600F,
  143691. 0.7340295955F, 0.7344380499F, 0.7348462226F, 0.7352541134F,
  143692. 0.7356617220F, 0.7360690478F, 0.7364760907F, 0.7368828502F,
  143693. 0.7372893259F, 0.7376955176F, 0.7381014249F, 0.7385070475F,
  143694. 0.7389123849F, 0.7393174368F, 0.7397222029F, 0.7401266829F,
  143695. 0.7405308763F, 0.7409347829F, 0.7413384023F, 0.7417417341F,
  143696. 0.7421447780F, 0.7425475338F, 0.7429500009F, 0.7433521791F,
  143697. 0.7437540681F, 0.7441556674F, 0.7445569769F, 0.7449579960F,
  143698. 0.7453587245F, 0.7457591621F, 0.7461593084F, 0.7465591631F,
  143699. 0.7469587259F, 0.7473579963F, 0.7477569741F, 0.7481556590F,
  143700. 0.7485540506F, 0.7489521486F, 0.7493499526F, 0.7497474623F,
  143701. 0.7501446775F, 0.7505415977F, 0.7509382227F, 0.7513345521F,
  143702. 0.7517305856F, 0.7521263229F, 0.7525217636F, 0.7529169074F,
  143703. 0.7533117541F, 0.7537063032F, 0.7541005545F, 0.7544945076F,
  143704. 0.7548881623F, 0.7552815182F, 0.7556745749F, 0.7560673323F,
  143705. 0.7564597899F, 0.7568519474F, 0.7572438046F, 0.7576353611F,
  143706. 0.7580266166F, 0.7584175708F, 0.7588082235F, 0.7591985741F,
  143707. 0.7595886226F, 0.7599783685F, 0.7603678116F, 0.7607569515F,
  143708. 0.7611457879F, 0.7615343206F, 0.7619225493F, 0.7623104735F,
  143709. 0.7626980931F, 0.7630854078F, 0.7634724171F, 0.7638591209F,
  143710. 0.7642455188F, 0.7646316106F, 0.7650173959F, 0.7654028744F,
  143711. 0.7657880459F, 0.7661729100F, 0.7665574664F, 0.7669417150F,
  143712. 0.7673256553F, 0.7677092871F, 0.7680926100F, 0.7684756239F,
  143713. 0.7688583284F, 0.7692407232F, 0.7696228080F, 0.7700045826F,
  143714. 0.7703860467F, 0.7707671999F, 0.7711480420F, 0.7715285728F,
  143715. 0.7719087918F, 0.7722886989F, 0.7726682938F, 0.7730475762F,
  143716. 0.7734265458F, 0.7738052023F, 0.7741835454F, 0.7745615750F,
  143717. 0.7749392906F, 0.7753166921F, 0.7756937791F, 0.7760705514F,
  143718. 0.7764470087F, 0.7768231508F, 0.7771989773F, 0.7775744880F,
  143719. 0.7779496827F, 0.7783245610F, 0.7786991227F, 0.7790733676F,
  143720. 0.7794472953F, 0.7798209056F, 0.7801941982F, 0.7805671729F,
  143721. 0.7809398294F, 0.7813121675F, 0.7816841869F, 0.7820558873F,
  143722. 0.7824272684F, 0.7827983301F, 0.7831690720F, 0.7835394940F,
  143723. 0.7839095957F, 0.7842793768F, 0.7846488373F, 0.7850179767F,
  143724. 0.7853867948F, 0.7857552914F, 0.7861234663F, 0.7864913191F,
  143725. 0.7868588497F, 0.7872260578F, 0.7875929431F, 0.7879595055F,
  143726. 0.7883257445F, 0.7886916601F, 0.7890572520F, 0.7894225198F,
  143727. 0.7897874635F, 0.7901520827F, 0.7905163772F, 0.7908803468F,
  143728. 0.7912439912F, 0.7916073102F, 0.7919703035F, 0.7923329710F,
  143729. 0.7926953124F, 0.7930573274F, 0.7934190158F, 0.7937803774F,
  143730. 0.7941414120F, 0.7945021193F, 0.7948624991F, 0.7952225511F,
  143731. 0.7955822752F, 0.7959416711F, 0.7963007387F, 0.7966594775F,
  143732. 0.7970178875F, 0.7973759685F, 0.7977337201F, 0.7980911422F,
  143733. 0.7984482346F, 0.7988049970F, 0.7991614292F, 0.7995175310F,
  143734. 0.7998733022F, 0.8002287426F, 0.8005838519F, 0.8009386299F,
  143735. 0.8012930765F, 0.8016471914F, 0.8020009744F, 0.8023544253F,
  143736. 0.8027075438F, 0.8030603298F, 0.8034127831F, 0.8037649035F,
  143737. 0.8041166906F, 0.8044681445F, 0.8048192647F, 0.8051700512F,
  143738. 0.8055205038F, 0.8058706222F, 0.8062204062F, 0.8065698556F,
  143739. 0.8069189702F, 0.8072677499F, 0.8076161944F, 0.8079643036F,
  143740. 0.8083120772F, 0.8086595151F, 0.8090066170F, 0.8093533827F,
  143741. 0.8096998122F, 0.8100459051F, 0.8103916613F, 0.8107370806F,
  143742. 0.8110821628F, 0.8114269077F, 0.8117713151F, 0.8121153849F,
  143743. 0.8124591169F, 0.8128025108F, 0.8131455666F, 0.8134882839F,
  143744. 0.8138306627F, 0.8141727027F, 0.8145144038F, 0.8148557658F,
  143745. 0.8151967886F, 0.8155374718F, 0.8158778154F, 0.8162178192F,
  143746. 0.8165574830F, 0.8168968067F, 0.8172357900F, 0.8175744328F,
  143747. 0.8179127349F, 0.8182506962F, 0.8185883164F, 0.8189255955F,
  143748. 0.8192625332F, 0.8195991295F, 0.8199353840F, 0.8202712967F,
  143749. 0.8206068673F, 0.8209420958F, 0.8212769820F, 0.8216115256F,
  143750. 0.8219457266F, 0.8222795848F, 0.8226131000F, 0.8229462721F,
  143751. 0.8232791009F, 0.8236115863F, 0.8239437280F, 0.8242755260F,
  143752. 0.8246069801F, 0.8249380901F, 0.8252688559F, 0.8255992774F,
  143753. 0.8259293544F, 0.8262590867F, 0.8265884741F, 0.8269175167F,
  143754. 0.8272462141F, 0.8275745663F, 0.8279025732F, 0.8282302344F,
  143755. 0.8285575501F, 0.8288845199F, 0.8292111437F, 0.8295374215F,
  143756. 0.8298633530F, 0.8301889382F, 0.8305141768F, 0.8308390688F,
  143757. 0.8311636141F, 0.8314878124F, 0.8318116637F, 0.8321351678F,
  143758. 0.8324583246F, 0.8327811340F, 0.8331035957F, 0.8334257098F,
  143759. 0.8337474761F, 0.8340688944F, 0.8343899647F, 0.8347106867F,
  143760. 0.8350310605F, 0.8353510857F, 0.8356707624F, 0.8359900904F,
  143761. 0.8363090696F, 0.8366276999F, 0.8369459811F, 0.8372639131F,
  143762. 0.8375814958F, 0.8378987292F, 0.8382156130F, 0.8385321472F,
  143763. 0.8388483316F, 0.8391641662F, 0.8394796508F, 0.8397947853F,
  143764. 0.8401095697F, 0.8404240037F, 0.8407380873F, 0.8410518204F,
  143765. 0.8413652029F, 0.8416782347F, 0.8419909156F, 0.8423032456F,
  143766. 0.8426152245F, 0.8429268523F, 0.8432381289F, 0.8435490541F,
  143767. 0.8438596279F, 0.8441698502F, 0.8444797208F, 0.8447892396F,
  143768. 0.8450984067F, 0.8454072218F, 0.8457156849F, 0.8460237959F,
  143769. 0.8463315547F, 0.8466389612F, 0.8469460154F, 0.8472527170F,
  143770. 0.8475590661F, 0.8478650625F, 0.8481707063F, 0.8484759971F,
  143771. 0.8487809351F, 0.8490855201F, 0.8493897521F, 0.8496936308F,
  143772. 0.8499971564F, 0.8503003286F, 0.8506031474F, 0.8509056128F,
  143773. 0.8512077246F, 0.8515094828F, 0.8518108872F, 0.8521119379F,
  143774. 0.8524126348F, 0.8527129777F, 0.8530129666F, 0.8533126015F,
  143775. 0.8536118822F, 0.8539108087F, 0.8542093809F, 0.8545075988F,
  143776. 0.8548054623F, 0.8551029712F, 0.8554001257F, 0.8556969255F,
  143777. 0.8559933707F, 0.8562894611F, 0.8565851968F, 0.8568805775F,
  143778. 0.8571756034F, 0.8574702743F, 0.8577645902F, 0.8580585509F,
  143779. 0.8583521566F, 0.8586454070F, 0.8589383021F, 0.8592308420F,
  143780. 0.8595230265F, 0.8598148556F, 0.8601063292F, 0.8603974473F,
  143781. 0.8606882098F, 0.8609786167F, 0.8612686680F, 0.8615583636F,
  143782. 0.8618477034F, 0.8621366874F, 0.8624253156F, 0.8627135878F,
  143783. 0.8630015042F, 0.8632890646F, 0.8635762690F, 0.8638631173F,
  143784. 0.8641496096F, 0.8644357457F, 0.8647215257F, 0.8650069495F,
  143785. 0.8652920171F, 0.8655767283F, 0.8658610833F, 0.8661450820F,
  143786. 0.8664287243F, 0.8667120102F, 0.8669949397F, 0.8672775127F,
  143787. 0.8675597293F, 0.8678415894F, 0.8681230929F, 0.8684042398F,
  143788. 0.8686850302F, 0.8689654640F, 0.8692455412F, 0.8695252617F,
  143789. 0.8698046255F, 0.8700836327F, 0.8703622831F, 0.8706405768F,
  143790. 0.8709185138F, 0.8711960940F, 0.8714733174F, 0.8717501840F,
  143791. 0.8720266939F, 0.8723028469F, 0.8725786430F, 0.8728540824F,
  143792. 0.8731291648F, 0.8734038905F, 0.8736782592F, 0.8739522711F,
  143793. 0.8742259261F, 0.8744992242F, 0.8747721653F, 0.8750447496F,
  143794. 0.8753169770F, 0.8755888475F, 0.8758603611F, 0.8761315177F,
  143795. 0.8764023175F, 0.8766727603F, 0.8769428462F, 0.8772125752F,
  143796. 0.8774819474F, 0.8777509626F, 0.8780196209F, 0.8782879224F,
  143797. 0.8785558669F, 0.8788234546F, 0.8790906854F, 0.8793575594F,
  143798. 0.8796240765F, 0.8798902368F, 0.8801560403F, 0.8804214870F,
  143799. 0.8806865768F, 0.8809513099F, 0.8812156863F, 0.8814797059F,
  143800. 0.8817433687F, 0.8820066749F, 0.8822696243F, 0.8825322171F,
  143801. 0.8827944532F, 0.8830563327F, 0.8833178556F, 0.8835790219F,
  143802. 0.8838398316F, 0.8841002848F, 0.8843603815F, 0.8846201217F,
  143803. 0.8848795054F, 0.8851385327F, 0.8853972036F, 0.8856555182F,
  143804. 0.8859134764F, 0.8861710783F, 0.8864283239F, 0.8866852133F,
  143805. 0.8869417464F, 0.8871979234F, 0.8874537443F, 0.8877092090F,
  143806. 0.8879643177F, 0.8882190704F, 0.8884734671F, 0.8887275078F,
  143807. 0.8889811927F, 0.8892345216F, 0.8894874948F, 0.8897401122F,
  143808. 0.8899923738F, 0.8902442798F, 0.8904958301F, 0.8907470248F,
  143809. 0.8909978640F, 0.8912483477F, 0.8914984759F, 0.8917482487F,
  143810. 0.8919976662F, 0.8922467284F, 0.8924954353F, 0.8927437871F,
  143811. 0.8929917837F, 0.8932394252F, 0.8934867118F, 0.8937336433F,
  143812. 0.8939802199F, 0.8942264417F, 0.8944723087F, 0.8947178210F,
  143813. 0.8949629785F, 0.8952077815F, 0.8954522299F, 0.8956963239F,
  143814. 0.8959400634F, 0.8961834486F, 0.8964264795F, 0.8966691561F,
  143815. 0.8969114786F, 0.8971534470F, 0.8973950614F, 0.8976363219F,
  143816. 0.8978772284F, 0.8981177812F, 0.8983579802F, 0.8985978256F,
  143817. 0.8988373174F, 0.8990764556F, 0.8993152405F, 0.8995536720F,
  143818. 0.8997917502F, 0.9000294751F, 0.9002668470F, 0.9005038658F,
  143819. 0.9007405317F, 0.9009768446F, 0.9012128048F, 0.9014484123F,
  143820. 0.9016836671F, 0.9019185693F, 0.9021531191F, 0.9023873165F,
  143821. 0.9026211616F, 0.9028546546F, 0.9030877954F, 0.9033205841F,
  143822. 0.9035530210F, 0.9037851059F, 0.9040168392F, 0.9042482207F,
  143823. 0.9044792507F, 0.9047099293F, 0.9049402564F, 0.9051702323F,
  143824. 0.9053998569F, 0.9056291305F, 0.9058580531F, 0.9060866248F,
  143825. 0.9063148457F, 0.9065427159F, 0.9067702355F, 0.9069974046F,
  143826. 0.9072242233F, 0.9074506917F, 0.9076768100F, 0.9079025782F,
  143827. 0.9081279964F, 0.9083530647F, 0.9085777833F, 0.9088021523F,
  143828. 0.9090261717F, 0.9092498417F, 0.9094731623F, 0.9096961338F,
  143829. 0.9099187561F, 0.9101410295F, 0.9103629540F, 0.9105845297F,
  143830. 0.9108057568F, 0.9110266354F, 0.9112471656F, 0.9114673475F,
  143831. 0.9116871812F, 0.9119066668F, 0.9121258046F, 0.9123445945F,
  143832. 0.9125630367F, 0.9127811314F, 0.9129988786F, 0.9132162785F,
  143833. 0.9134333312F, 0.9136500368F, 0.9138663954F, 0.9140824073F,
  143834. 0.9142980724F, 0.9145133910F, 0.9147283632F, 0.9149429890F,
  143835. 0.9151572687F, 0.9153712023F, 0.9155847900F, 0.9157980319F,
  143836. 0.9160109282F, 0.9162234790F, 0.9164356844F, 0.9166475445F,
  143837. 0.9168590595F, 0.9170702296F, 0.9172810548F, 0.9174915354F,
  143838. 0.9177016714F, 0.9179114629F, 0.9181209102F, 0.9183300134F,
  143839. 0.9185387726F, 0.9187471879F, 0.9189552595F, 0.9191629876F,
  143840. 0.9193703723F, 0.9195774136F, 0.9197841119F, 0.9199904672F,
  143841. 0.9201964797F, 0.9204021495F, 0.9206074767F, 0.9208124616F,
  143842. 0.9210171043F, 0.9212214049F, 0.9214253636F, 0.9216289805F,
  143843. 0.9218322558F, 0.9220351896F, 0.9222377821F, 0.9224400335F,
  143844. 0.9226419439F, 0.9228435134F, 0.9230447423F, 0.9232456307F,
  143845. 0.9234461787F, 0.9236463865F, 0.9238462543F, 0.9240457822F,
  143846. 0.9242449704F, 0.9244438190F, 0.9246423282F, 0.9248404983F,
  143847. 0.9250383293F, 0.9252358214F, 0.9254329747F, 0.9256297896F,
  143848. 0.9258262660F, 0.9260224042F, 0.9262182044F, 0.9264136667F,
  143849. 0.9266087913F, 0.9268035783F, 0.9269980280F, 0.9271921405F,
  143850. 0.9273859160F, 0.9275793546F, 0.9277724566F, 0.9279652221F,
  143851. 0.9281576513F, 0.9283497443F, 0.9285415014F, 0.9287329227F,
  143852. 0.9289240084F, 0.9291147586F, 0.9293051737F, 0.9294952536F,
  143853. 0.9296849987F, 0.9298744091F, 0.9300634850F, 0.9302522266F,
  143854. 0.9304406340F, 0.9306287074F, 0.9308164471F, 0.9310038532F,
  143855. 0.9311909259F, 0.9313776654F, 0.9315640719F, 0.9317501455F,
  143856. 0.9319358865F, 0.9321212951F, 0.9323063713F, 0.9324911155F,
  143857. 0.9326755279F, 0.9328596085F, 0.9330433577F, 0.9332267756F,
  143858. 0.9334098623F, 0.9335926182F, 0.9337750434F, 0.9339571380F,
  143859. 0.9341389023F, 0.9343203366F, 0.9345014409F, 0.9346822155F,
  143860. 0.9348626606F, 0.9350427763F, 0.9352225630F, 0.9354020207F,
  143861. 0.9355811498F, 0.9357599503F, 0.9359384226F, 0.9361165667F,
  143862. 0.9362943830F, 0.9364718716F, 0.9366490327F, 0.9368258666F,
  143863. 0.9370023733F, 0.9371785533F, 0.9373544066F, 0.9375299335F,
  143864. 0.9377051341F, 0.9378800087F, 0.9380545576F, 0.9382287809F,
  143865. 0.9384026787F, 0.9385762515F, 0.9387494993F, 0.9389224223F,
  143866. 0.9390950209F, 0.9392672951F, 0.9394392453F, 0.9396108716F,
  143867. 0.9397821743F, 0.9399531536F, 0.9401238096F, 0.9402941427F,
  143868. 0.9404641530F, 0.9406338407F, 0.9408032061F, 0.9409722495F,
  143869. 0.9411409709F, 0.9413093707F, 0.9414774491F, 0.9416452062F,
  143870. 0.9418126424F, 0.9419797579F, 0.9421465528F, 0.9423130274F,
  143871. 0.9424791819F, 0.9426450166F, 0.9428105317F, 0.9429757274F,
  143872. 0.9431406039F, 0.9433051616F, 0.9434694005F, 0.9436333209F,
  143873. 0.9437969232F, 0.9439602074F, 0.9441231739F, 0.9442858229F,
  143874. 0.9444481545F, 0.9446101691F, 0.9447718669F, 0.9449332481F,
  143875. 0.9450943129F, 0.9452550617F, 0.9454154945F, 0.9455756118F,
  143876. 0.9457354136F, 0.9458949003F, 0.9460540721F, 0.9462129292F,
  143877. 0.9463714719F, 0.9465297003F, 0.9466876149F, 0.9468452157F,
  143878. 0.9470025031F, 0.9471594772F, 0.9473161384F, 0.9474724869F,
  143879. 0.9476285229F, 0.9477842466F, 0.9479396584F, 0.9480947585F,
  143880. 0.9482495470F, 0.9484040243F, 0.9485581906F, 0.9487120462F,
  143881. 0.9488655913F, 0.9490188262F, 0.9491717511F, 0.9493243662F,
  143882. 0.9494766718F, 0.9496286683F, 0.9497803557F, 0.9499317345F,
  143883. 0.9500828047F, 0.9502335668F, 0.9503840209F, 0.9505341673F,
  143884. 0.9506840062F, 0.9508335380F, 0.9509827629F, 0.9511316810F,
  143885. 0.9512802928F, 0.9514285984F, 0.9515765982F, 0.9517242923F,
  143886. 0.9518716810F, 0.9520187646F, 0.9521655434F, 0.9523120176F,
  143887. 0.9524581875F, 0.9526040534F, 0.9527496154F, 0.9528948739F,
  143888. 0.9530398292F, 0.9531844814F, 0.9533288310F, 0.9534728780F,
  143889. 0.9536166229F, 0.9537600659F, 0.9539032071F, 0.9540460470F,
  143890. 0.9541885858F, 0.9543308237F, 0.9544727611F, 0.9546143981F,
  143891. 0.9547557351F, 0.9548967723F, 0.9550375100F, 0.9551779485F,
  143892. 0.9553180881F, 0.9554579290F, 0.9555974714F, 0.9557367158F,
  143893. 0.9558756623F, 0.9560143112F, 0.9561526628F, 0.9562907174F,
  143894. 0.9564284752F, 0.9565659366F, 0.9567031017F, 0.9568399710F,
  143895. 0.9569765446F, 0.9571128229F, 0.9572488061F, 0.9573844944F,
  143896. 0.9575198883F, 0.9576549879F, 0.9577897936F, 0.9579243056F,
  143897. 0.9580585242F, 0.9581924497F, 0.9583260824F, 0.9584594226F,
  143898. 0.9585924705F, 0.9587252264F, 0.9588576906F, 0.9589898634F,
  143899. 0.9591217452F, 0.9592533360F, 0.9593846364F, 0.9595156465F,
  143900. 0.9596463666F, 0.9597767971F, 0.9599069382F, 0.9600367901F,
  143901. 0.9601663533F, 0.9602956279F, 0.9604246143F, 0.9605533128F,
  143902. 0.9606817236F, 0.9608098471F, 0.9609376835F, 0.9610652332F,
  143903. 0.9611924963F, 0.9613194733F, 0.9614461644F, 0.9615725699F,
  143904. 0.9616986901F, 0.9618245253F, 0.9619500757F, 0.9620753418F,
  143905. 0.9622003238F, 0.9623250219F, 0.9624494365F, 0.9625735679F,
  143906. 0.9626974163F, 0.9628209821F, 0.9629442656F, 0.9630672671F,
  143907. 0.9631899868F, 0.9633124251F, 0.9634345822F, 0.9635564585F,
  143908. 0.9636780543F, 0.9637993699F, 0.9639204056F, 0.9640411616F,
  143909. 0.9641616383F, 0.9642818359F, 0.9644017549F, 0.9645213955F,
  143910. 0.9646407579F, 0.9647598426F, 0.9648786497F, 0.9649971797F,
  143911. 0.9651154328F, 0.9652334092F, 0.9653511095F, 0.9654685337F,
  143912. 0.9655856823F, 0.9657025556F, 0.9658191538F, 0.9659354773F,
  143913. 0.9660515263F, 0.9661673013F, 0.9662828024F, 0.9663980300F,
  143914. 0.9665129845F, 0.9666276660F, 0.9667420750F, 0.9668562118F,
  143915. 0.9669700766F, 0.9670836698F, 0.9671969917F, 0.9673100425F,
  143916. 0.9674228227F, 0.9675353325F, 0.9676475722F, 0.9677595422F,
  143917. 0.9678712428F, 0.9679826742F, 0.9680938368F, 0.9682047309F,
  143918. 0.9683153569F, 0.9684257150F, 0.9685358056F, 0.9686456289F,
  143919. 0.9687551853F, 0.9688644752F, 0.9689734987F, 0.9690822564F,
  143920. 0.9691907483F, 0.9692989750F, 0.9694069367F, 0.9695146337F,
  143921. 0.9696220663F, 0.9697292349F, 0.9698361398F, 0.9699427813F,
  143922. 0.9700491597F, 0.9701552754F, 0.9702611286F, 0.9703667197F,
  143923. 0.9704720490F, 0.9705771169F, 0.9706819236F, 0.9707864695F,
  143924. 0.9708907549F, 0.9709947802F, 0.9710985456F, 0.9712020514F,
  143925. 0.9713052981F, 0.9714082859F, 0.9715110151F, 0.9716134862F,
  143926. 0.9717156993F, 0.9718176549F, 0.9719193532F, 0.9720207946F,
  143927. 0.9721219794F, 0.9722229080F, 0.9723235806F, 0.9724239976F,
  143928. 0.9725241593F, 0.9726240661F, 0.9727237183F, 0.9728231161F,
  143929. 0.9729222601F, 0.9730211503F, 0.9731197873F, 0.9732181713F,
  143930. 0.9733163027F, 0.9734141817F, 0.9735118088F, 0.9736091842F,
  143931. 0.9737063083F, 0.9738031814F, 0.9738998039F, 0.9739961760F,
  143932. 0.9740922981F, 0.9741881706F, 0.9742837938F, 0.9743791680F,
  143933. 0.9744742935F, 0.9745691707F, 0.9746637999F, 0.9747581814F,
  143934. 0.9748523157F, 0.9749462029F, 0.9750398435F, 0.9751332378F,
  143935. 0.9752263861F, 0.9753192887F, 0.9754119461F, 0.9755043585F,
  143936. 0.9755965262F, 0.9756884496F, 0.9757801291F, 0.9758715650F,
  143937. 0.9759627575F, 0.9760537071F, 0.9761444141F, 0.9762348789F,
  143938. 0.9763251016F, 0.9764150828F, 0.9765048228F, 0.9765943218F,
  143939. 0.9766835802F, 0.9767725984F, 0.9768613767F, 0.9769499154F,
  143940. 0.9770382149F, 0.9771262755F, 0.9772140976F, 0.9773016815F,
  143941. 0.9773890275F, 0.9774761360F, 0.9775630073F, 0.9776496418F,
  143942. 0.9777360398F, 0.9778222016F, 0.9779081277F, 0.9779938182F,
  143943. 0.9780792736F, 0.9781644943F, 0.9782494805F, 0.9783342326F,
  143944. 0.9784187509F, 0.9785030359F, 0.9785870877F, 0.9786709069F,
  143945. 0.9787544936F, 0.9788378484F, 0.9789209714F, 0.9790038631F,
  143946. 0.9790865238F, 0.9791689538F, 0.9792511535F, 0.9793331232F,
  143947. 0.9794148633F, 0.9794963742F, 0.9795776561F, 0.9796587094F,
  143948. 0.9797395345F, 0.9798201316F, 0.9799005013F, 0.9799806437F,
  143949. 0.9800605593F, 0.9801402483F, 0.9802197112F, 0.9802989483F,
  143950. 0.9803779600F, 0.9804567465F, 0.9805353082F, 0.9806136455F,
  143951. 0.9806917587F, 0.9807696482F, 0.9808473143F, 0.9809247574F,
  143952. 0.9810019778F, 0.9810789759F, 0.9811557519F, 0.9812323064F,
  143953. 0.9813086395F, 0.9813847517F, 0.9814606433F, 0.9815363147F,
  143954. 0.9816117662F, 0.9816869981F, 0.9817620108F, 0.9818368047F,
  143955. 0.9819113801F, 0.9819857374F, 0.9820598769F, 0.9821337989F,
  143956. 0.9822075038F, 0.9822809920F, 0.9823542638F, 0.9824273195F,
  143957. 0.9825001596F, 0.9825727843F, 0.9826451940F, 0.9827173891F,
  143958. 0.9827893700F, 0.9828611368F, 0.9829326901F, 0.9830040302F,
  143959. 0.9830751574F, 0.9831460720F, 0.9832167745F, 0.9832872652F,
  143960. 0.9833575444F, 0.9834276124F, 0.9834974697F, 0.9835671166F,
  143961. 0.9836365535F, 0.9837057806F, 0.9837747983F, 0.9838436071F,
  143962. 0.9839122072F, 0.9839805990F, 0.9840487829F, 0.9841167591F,
  143963. 0.9841845282F, 0.9842520903F, 0.9843194459F, 0.9843865953F,
  143964. 0.9844535389F, 0.9845202771F, 0.9845868101F, 0.9846531383F,
  143965. 0.9847192622F, 0.9847851820F, 0.9848508980F, 0.9849164108F,
  143966. 0.9849817205F, 0.9850468276F, 0.9851117324F, 0.9851764352F,
  143967. 0.9852409365F, 0.9853052366F, 0.9853693358F, 0.9854332344F,
  143968. 0.9854969330F, 0.9855604317F, 0.9856237309F, 0.9856868310F,
  143969. 0.9857497325F, 0.9858124355F, 0.9858749404F, 0.9859372477F,
  143970. 0.9859993577F, 0.9860612707F, 0.9861229871F, 0.9861845072F,
  143971. 0.9862458315F, 0.9863069601F, 0.9863678936F, 0.9864286322F,
  143972. 0.9864891764F, 0.9865495264F, 0.9866096826F, 0.9866696454F,
  143973. 0.9867294152F, 0.9867889922F, 0.9868483769F, 0.9869075695F,
  143974. 0.9869665706F, 0.9870253803F, 0.9870839991F, 0.9871424273F,
  143975. 0.9872006653F, 0.9872587135F, 0.9873165721F, 0.9873742415F,
  143976. 0.9874317222F, 0.9874890144F, 0.9875461185F, 0.9876030348F,
  143977. 0.9876597638F, 0.9877163057F, 0.9877726610F, 0.9878288300F,
  143978. 0.9878848130F, 0.9879406104F, 0.9879962225F, 0.9880516497F,
  143979. 0.9881068924F, 0.9881619509F, 0.9882168256F, 0.9882715168F,
  143980. 0.9883260249F, 0.9883803502F, 0.9884344931F, 0.9884884539F,
  143981. 0.9885422331F, 0.9885958309F, 0.9886492477F, 0.9887024838F,
  143982. 0.9887555397F, 0.9888084157F, 0.9888611120F, 0.9889136292F,
  143983. 0.9889659675F, 0.9890181273F, 0.9890701089F, 0.9891219128F,
  143984. 0.9891735392F, 0.9892249885F, 0.9892762610F, 0.9893273572F,
  143985. 0.9893782774F, 0.9894290219F, 0.9894795911F, 0.9895299853F,
  143986. 0.9895802049F, 0.9896302502F, 0.9896801217F, 0.9897298196F,
  143987. 0.9897793443F, 0.9898286961F, 0.9898778755F, 0.9899268828F,
  143988. 0.9899757183F, 0.9900243823F, 0.9900728753F, 0.9901211976F,
  143989. 0.9901693495F, 0.9902173314F, 0.9902651436F, 0.9903127865F,
  143990. 0.9903602605F, 0.9904075659F, 0.9904547031F, 0.9905016723F,
  143991. 0.9905484740F, 0.9905951086F, 0.9906415763F, 0.9906878775F,
  143992. 0.9907340126F, 0.9907799819F, 0.9908257858F, 0.9908714247F,
  143993. 0.9909168988F, 0.9909622086F, 0.9910073543F, 0.9910523364F,
  143994. 0.9910971552F, 0.9911418110F, 0.9911863042F, 0.9912306351F,
  143995. 0.9912748042F, 0.9913188117F, 0.9913626580F, 0.9914063435F,
  143996. 0.9914498684F, 0.9914932333F, 0.9915364383F, 0.9915794839F,
  143997. 0.9916223703F, 0.9916650981F, 0.9917076674F, 0.9917500787F,
  143998. 0.9917923323F, 0.9918344286F, 0.9918763679F, 0.9919181505F,
  143999. 0.9919597769F, 0.9920012473F, 0.9920425621F, 0.9920837217F,
  144000. 0.9921247263F, 0.9921655765F, 0.9922062724F, 0.9922468145F,
  144001. 0.9922872030F, 0.9923274385F, 0.9923675211F, 0.9924074513F,
  144002. 0.9924472294F, 0.9924868557F, 0.9925263306F, 0.9925656544F,
  144003. 0.9926048275F, 0.9926438503F, 0.9926827230F, 0.9927214461F,
  144004. 0.9927600199F, 0.9927984446F, 0.9928367208F, 0.9928748486F,
  144005. 0.9929128285F, 0.9929506608F, 0.9929883459F, 0.9930258841F,
  144006. 0.9930632757F, 0.9931005211F, 0.9931376207F, 0.9931745747F,
  144007. 0.9932113836F, 0.9932480476F, 0.9932845671F, 0.9933209425F,
  144008. 0.9933571742F, 0.9933932623F, 0.9934292074F, 0.9934650097F,
  144009. 0.9935006696F, 0.9935361874F, 0.9935715635F, 0.9936067982F,
  144010. 0.9936418919F, 0.9936768448F, 0.9937116574F, 0.9937463300F,
  144011. 0.9937808629F, 0.9938152565F, 0.9938495111F, 0.9938836271F,
  144012. 0.9939176047F, 0.9939514444F, 0.9939851465F, 0.9940187112F,
  144013. 0.9940521391F, 0.9940854303F, 0.9941185853F, 0.9941516044F,
  144014. 0.9941844879F, 0.9942172361F, 0.9942498495F, 0.9942823283F,
  144015. 0.9943146729F, 0.9943468836F, 0.9943789608F, 0.9944109047F,
  144016. 0.9944427158F, 0.9944743944F, 0.9945059408F, 0.9945373553F,
  144017. 0.9945686384F, 0.9945997902F, 0.9946308112F, 0.9946617017F,
  144018. 0.9946924621F, 0.9947230926F, 0.9947535937F, 0.9947839656F,
  144019. 0.9948142086F, 0.9948443232F, 0.9948743097F, 0.9949041683F,
  144020. 0.9949338995F, 0.9949635035F, 0.9949929807F, 0.9950223315F,
  144021. 0.9950515561F, 0.9950806549F, 0.9951096282F, 0.9951384764F,
  144022. 0.9951671998F, 0.9951957987F, 0.9952242735F, 0.9952526245F,
  144023. 0.9952808520F, 0.9953089564F, 0.9953369380F, 0.9953647971F,
  144024. 0.9953925340F, 0.9954201491F, 0.9954476428F, 0.9954750153F,
  144025. 0.9955022670F, 0.9955293981F, 0.9955564092F, 0.9955833003F,
  144026. 0.9956100720F, 0.9956367245F, 0.9956632582F, 0.9956896733F,
  144027. 0.9957159703F, 0.9957421494F, 0.9957682110F, 0.9957941553F,
  144028. 0.9958199828F, 0.9958456937F, 0.9958712884F, 0.9958967672F,
  144029. 0.9959221305F, 0.9959473784F, 0.9959725115F, 0.9959975300F,
  144030. 0.9960224342F, 0.9960472244F, 0.9960719011F, 0.9960964644F,
  144031. 0.9961209148F, 0.9961452525F, 0.9961694779F, 0.9961935913F,
  144032. 0.9962175930F, 0.9962414834F, 0.9962652627F, 0.9962889313F,
  144033. 0.9963124895F, 0.9963359377F, 0.9963592761F, 0.9963825051F,
  144034. 0.9964056250F, 0.9964286361F, 0.9964515387F, 0.9964743332F,
  144035. 0.9964970198F, 0.9965195990F, 0.9965420709F, 0.9965644360F,
  144036. 0.9965866946F, 0.9966088469F, 0.9966308932F, 0.9966528340F,
  144037. 0.9966746695F, 0.9966964001F, 0.9967180260F, 0.9967395475F,
  144038. 0.9967609651F, 0.9967822789F, 0.9968034894F, 0.9968245968F,
  144039. 0.9968456014F, 0.9968665036F, 0.9968873037F, 0.9969080019F,
  144040. 0.9969285987F, 0.9969490942F, 0.9969694889F, 0.9969897830F,
  144041. 0.9970099769F, 0.9970300708F, 0.9970500651F, 0.9970699601F,
  144042. 0.9970897561F, 0.9971094533F, 0.9971290522F, 0.9971485531F,
  144043. 0.9971679561F, 0.9971872617F, 0.9972064702F, 0.9972255818F,
  144044. 0.9972445968F, 0.9972635157F, 0.9972823386F, 0.9973010659F,
  144045. 0.9973196980F, 0.9973382350F, 0.9973566773F, 0.9973750253F,
  144046. 0.9973932791F, 0.9974114392F, 0.9974295059F, 0.9974474793F,
  144047. 0.9974653599F, 0.9974831480F, 0.9975008438F, 0.9975184476F,
  144048. 0.9975359598F, 0.9975533806F, 0.9975707104F, 0.9975879495F,
  144049. 0.9976050981F, 0.9976221566F, 0.9976391252F, 0.9976560043F,
  144050. 0.9976727941F, 0.9976894950F, 0.9977061073F, 0.9977226312F,
  144051. 0.9977390671F, 0.9977554152F, 0.9977716759F, 0.9977878495F,
  144052. 0.9978039361F, 0.9978199363F, 0.9978358501F, 0.9978516780F,
  144053. 0.9978674202F, 0.9978830771F, 0.9978986488F, 0.9979141358F,
  144054. 0.9979295383F, 0.9979448566F, 0.9979600909F, 0.9979752417F,
  144055. 0.9979903091F, 0.9980052936F, 0.9980201952F, 0.9980350145F,
  144056. 0.9980497515F, 0.9980644067F, 0.9980789804F, 0.9980934727F,
  144057. 0.9981078841F, 0.9981222147F, 0.9981364649F, 0.9981506350F,
  144058. 0.9981647253F, 0.9981787360F, 0.9981926674F, 0.9982065199F,
  144059. 0.9982202936F, 0.9982339890F, 0.9982476062F, 0.9982611456F,
  144060. 0.9982746074F, 0.9982879920F, 0.9983012996F, 0.9983145304F,
  144061. 0.9983276849F, 0.9983407632F, 0.9983537657F, 0.9983666926F,
  144062. 0.9983795442F, 0.9983923208F, 0.9984050226F, 0.9984176501F,
  144063. 0.9984302033F, 0.9984426827F, 0.9984550884F, 0.9984674208F,
  144064. 0.9984796802F, 0.9984918667F, 0.9985039808F, 0.9985160227F,
  144065. 0.9985279926F, 0.9985398909F, 0.9985517177F, 0.9985634734F,
  144066. 0.9985751583F, 0.9985867727F, 0.9985983167F, 0.9986097907F,
  144067. 0.9986211949F, 0.9986325297F, 0.9986437953F, 0.9986549919F,
  144068. 0.9986661199F, 0.9986771795F, 0.9986881710F, 0.9986990946F,
  144069. 0.9987099507F, 0.9987207394F, 0.9987314611F, 0.9987421161F,
  144070. 0.9987527045F, 0.9987632267F, 0.9987736829F, 0.9987840734F,
  144071. 0.9987943985F, 0.9988046584F, 0.9988148534F, 0.9988249838F,
  144072. 0.9988350498F, 0.9988450516F, 0.9988549897F, 0.9988648641F,
  144073. 0.9988746753F, 0.9988844233F, 0.9988941086F, 0.9989037313F,
  144074. 0.9989132918F, 0.9989227902F, 0.9989322269F, 0.9989416021F,
  144075. 0.9989509160F, 0.9989601690F, 0.9989693613F, 0.9989784931F,
  144076. 0.9989875647F, 0.9989965763F, 0.9990055283F, 0.9990144208F,
  144077. 0.9990232541F, 0.9990320286F, 0.9990407443F, 0.9990494016F,
  144078. 0.9990580008F, 0.9990665421F, 0.9990750257F, 0.9990834519F,
  144079. 0.9990918209F, 0.9991001331F, 0.9991083886F, 0.9991165877F,
  144080. 0.9991247307F, 0.9991328177F, 0.9991408491F, 0.9991488251F,
  144081. 0.9991567460F, 0.9991646119F, 0.9991724232F, 0.9991801801F,
  144082. 0.9991878828F, 0.9991955316F, 0.9992031267F, 0.9992106684F,
  144083. 0.9992181569F, 0.9992255925F, 0.9992329753F, 0.9992403057F,
  144084. 0.9992475839F, 0.9992548101F, 0.9992619846F, 0.9992691076F,
  144085. 0.9992761793F, 0.9992832001F, 0.9992901701F, 0.9992970895F,
  144086. 0.9993039587F, 0.9993107777F, 0.9993175470F, 0.9993242667F,
  144087. 0.9993309371F, 0.9993375583F, 0.9993441307F, 0.9993506545F,
  144088. 0.9993571298F, 0.9993635570F, 0.9993699362F, 0.9993762678F,
  144089. 0.9993825519F, 0.9993887887F, 0.9993949785F, 0.9994011216F,
  144090. 0.9994072181F, 0.9994132683F, 0.9994192725F, 0.9994252307F,
  144091. 0.9994311434F, 0.9994370107F, 0.9994428327F, 0.9994486099F,
  144092. 0.9994543423F, 0.9994600303F, 0.9994656739F, 0.9994712736F,
  144093. 0.9994768294F, 0.9994823417F, 0.9994878105F, 0.9994932363F,
  144094. 0.9994986191F, 0.9995039592F, 0.9995092568F, 0.9995145122F,
  144095. 0.9995197256F, 0.9995248971F, 0.9995300270F, 0.9995351156F,
  144096. 0.9995401630F, 0.9995451695F, 0.9995501352F, 0.9995550604F,
  144097. 0.9995599454F, 0.9995647903F, 0.9995695953F, 0.9995743607F,
  144098. 0.9995790866F, 0.9995837734F, 0.9995884211F, 0.9995930300F,
  144099. 0.9995976004F, 0.9996021324F, 0.9996066263F, 0.9996110822F,
  144100. 0.9996155004F, 0.9996198810F, 0.9996242244F, 0.9996285306F,
  144101. 0.9996327999F, 0.9996370326F, 0.9996412287F, 0.9996453886F,
  144102. 0.9996495125F, 0.9996536004F, 0.9996576527F, 0.9996616696F,
  144103. 0.9996656512F, 0.9996695977F, 0.9996735094F, 0.9996773865F,
  144104. 0.9996812291F, 0.9996850374F, 0.9996888118F, 0.9996925523F,
  144105. 0.9996962591F, 0.9996999325F, 0.9997035727F, 0.9997071798F,
  144106. 0.9997107541F, 0.9997142957F, 0.9997178049F, 0.9997212818F,
  144107. 0.9997247266F, 0.9997281396F, 0.9997315209F, 0.9997348708F,
  144108. 0.9997381893F, 0.9997414767F, 0.9997447333F, 0.9997479591F,
  144109. 0.9997511544F, 0.9997543194F, 0.9997574542F, 0.9997605591F,
  144110. 0.9997636342F, 0.9997666797F, 0.9997696958F, 0.9997726828F,
  144111. 0.9997756407F, 0.9997785698F, 0.9997814703F, 0.9997843423F,
  144112. 0.9997871860F, 0.9997900016F, 0.9997927894F, 0.9997955494F,
  144113. 0.9997982818F, 0.9998009869F, 0.9998036648F, 0.9998063157F,
  144114. 0.9998089398F, 0.9998115373F, 0.9998141082F, 0.9998166529F,
  144115. 0.9998191715F, 0.9998216642F, 0.9998241311F, 0.9998265724F,
  144116. 0.9998289884F, 0.9998313790F, 0.9998337447F, 0.9998360854F,
  144117. 0.9998384015F, 0.9998406930F, 0.9998429602F, 0.9998452031F,
  144118. 0.9998474221F, 0.9998496171F, 0.9998517885F, 0.9998539364F,
  144119. 0.9998560610F, 0.9998581624F, 0.9998602407F, 0.9998622962F,
  144120. 0.9998643291F, 0.9998663394F, 0.9998683274F, 0.9998702932F,
  144121. 0.9998722370F, 0.9998741589F, 0.9998760591F, 0.9998779378F,
  144122. 0.9998797952F, 0.9998816313F, 0.9998834464F, 0.9998852406F,
  144123. 0.9998870141F, 0.9998887670F, 0.9998904995F, 0.9998922117F,
  144124. 0.9998939039F, 0.9998955761F, 0.9998972285F, 0.9998988613F,
  144125. 0.9999004746F, 0.9999020686F, 0.9999036434F, 0.9999051992F,
  144126. 0.9999067362F, 0.9999082544F, 0.9999097541F, 0.9999112354F,
  144127. 0.9999126984F, 0.9999141433F, 0.9999155703F, 0.9999169794F,
  144128. 0.9999183709F, 0.9999197449F, 0.9999211014F, 0.9999224408F,
  144129. 0.9999237631F, 0.9999250684F, 0.9999263570F, 0.9999276289F,
  144130. 0.9999288843F, 0.9999301233F, 0.9999313461F, 0.9999325529F,
  144131. 0.9999337437F, 0.9999349187F, 0.9999360780F, 0.9999372218F,
  144132. 0.9999383503F, 0.9999394635F, 0.9999405616F, 0.9999416447F,
  144133. 0.9999427129F, 0.9999437665F, 0.9999448055F, 0.9999458301F,
  144134. 0.9999468404F, 0.9999478365F, 0.9999488185F, 0.9999497867F,
  144135. 0.9999507411F, 0.9999516819F, 0.9999526091F, 0.9999535230F,
  144136. 0.9999544236F, 0.9999553111F, 0.9999561856F, 0.9999570472F,
  144137. 0.9999578960F, 0.9999587323F, 0.9999595560F, 0.9999603674F,
  144138. 0.9999611666F, 0.9999619536F, 0.9999627286F, 0.9999634917F,
  144139. 0.9999642431F, 0.9999649828F, 0.9999657110F, 0.9999664278F,
  144140. 0.9999671334F, 0.9999678278F, 0.9999685111F, 0.9999691835F,
  144141. 0.9999698451F, 0.9999704960F, 0.9999711364F, 0.9999717662F,
  144142. 0.9999723858F, 0.9999729950F, 0.9999735942F, 0.9999741834F,
  144143. 0.9999747626F, 0.9999753321F, 0.9999758919F, 0.9999764421F,
  144144. 0.9999769828F, 0.9999775143F, 0.9999780364F, 0.9999785495F,
  144145. 0.9999790535F, 0.9999795485F, 0.9999800348F, 0.9999805124F,
  144146. 0.9999809813F, 0.9999814417F, 0.9999818938F, 0.9999823375F,
  144147. 0.9999827731F, 0.9999832005F, 0.9999836200F, 0.9999840316F,
  144148. 0.9999844353F, 0.9999848314F, 0.9999852199F, 0.9999856008F,
  144149. 0.9999859744F, 0.9999863407F, 0.9999866997F, 0.9999870516F,
  144150. 0.9999873965F, 0.9999877345F, 0.9999880656F, 0.9999883900F,
  144151. 0.9999887078F, 0.9999890190F, 0.9999893237F, 0.9999896220F,
  144152. 0.9999899140F, 0.9999901999F, 0.9999904796F, 0.9999907533F,
  144153. 0.9999910211F, 0.9999912830F, 0.9999915391F, 0.9999917896F,
  144154. 0.9999920345F, 0.9999922738F, 0.9999925077F, 0.9999927363F,
  144155. 0.9999929596F, 0.9999931777F, 0.9999933907F, 0.9999935987F,
  144156. 0.9999938018F, 0.9999940000F, 0.9999941934F, 0.9999943820F,
  144157. 0.9999945661F, 0.9999947456F, 0.9999949206F, 0.9999950912F,
  144158. 0.9999952575F, 0.9999954195F, 0.9999955773F, 0.9999957311F,
  144159. 0.9999958807F, 0.9999960265F, 0.9999961683F, 0.9999963063F,
  144160. 0.9999964405F, 0.9999965710F, 0.9999966979F, 0.9999968213F,
  144161. 0.9999969412F, 0.9999970576F, 0.9999971707F, 0.9999972805F,
  144162. 0.9999973871F, 0.9999974905F, 0.9999975909F, 0.9999976881F,
  144163. 0.9999977824F, 0.9999978738F, 0.9999979624F, 0.9999980481F,
  144164. 0.9999981311F, 0.9999982115F, 0.9999982892F, 0.9999983644F,
  144165. 0.9999984370F, 0.9999985072F, 0.9999985750F, 0.9999986405F,
  144166. 0.9999987037F, 0.9999987647F, 0.9999988235F, 0.9999988802F,
  144167. 0.9999989348F, 0.9999989873F, 0.9999990379F, 0.9999990866F,
  144168. 0.9999991334F, 0.9999991784F, 0.9999992217F, 0.9999992632F,
  144169. 0.9999993030F, 0.9999993411F, 0.9999993777F, 0.9999994128F,
  144170. 0.9999994463F, 0.9999994784F, 0.9999995091F, 0.9999995384F,
  144171. 0.9999995663F, 0.9999995930F, 0.9999996184F, 0.9999996426F,
  144172. 0.9999996657F, 0.9999996876F, 0.9999997084F, 0.9999997282F,
  144173. 0.9999997469F, 0.9999997647F, 0.9999997815F, 0.9999997973F,
  144174. 0.9999998123F, 0.9999998265F, 0.9999998398F, 0.9999998524F,
  144175. 0.9999998642F, 0.9999998753F, 0.9999998857F, 0.9999998954F,
  144176. 0.9999999045F, 0.9999999130F, 0.9999999209F, 0.9999999282F,
  144177. 0.9999999351F, 0.9999999414F, 0.9999999472F, 0.9999999526F,
  144178. 0.9999999576F, 0.9999999622F, 0.9999999664F, 0.9999999702F,
  144179. 0.9999999737F, 0.9999999769F, 0.9999999798F, 0.9999999824F,
  144180. 0.9999999847F, 0.9999999868F, 0.9999999887F, 0.9999999904F,
  144181. 0.9999999919F, 0.9999999932F, 0.9999999943F, 0.9999999953F,
  144182. 0.9999999961F, 0.9999999969F, 0.9999999975F, 0.9999999980F,
  144183. 0.9999999985F, 0.9999999988F, 0.9999999991F, 0.9999999993F,
  144184. 0.9999999995F, 0.9999999997F, 0.9999999998F, 0.9999999999F,
  144185. 0.9999999999F, 1.0000000000F, 1.0000000000F, 1.0000000000F,
  144186. 1.0000000000F, 1.0000000000F, 1.0000000000F, 1.0000000000F,
  144187. };
  144188. static float *vwin[8] = {
  144189. vwin64,
  144190. vwin128,
  144191. vwin256,
  144192. vwin512,
  144193. vwin1024,
  144194. vwin2048,
  144195. vwin4096,
  144196. vwin8192,
  144197. };
  144198. float *_vorbis_window_get(int n){
  144199. return vwin[n];
  144200. }
  144201. void _vorbis_apply_window(float *d,int *winno,long *blocksizes,
  144202. int lW,int W,int nW){
  144203. lW=(W?lW:0);
  144204. nW=(W?nW:0);
  144205. {
  144206. float *windowLW=vwin[winno[lW]];
  144207. float *windowNW=vwin[winno[nW]];
  144208. long n=blocksizes[W];
  144209. long ln=blocksizes[lW];
  144210. long rn=blocksizes[nW];
  144211. long leftbegin=n/4-ln/4;
  144212. long leftend=leftbegin+ln/2;
  144213. long rightbegin=n/2+n/4-rn/4;
  144214. long rightend=rightbegin+rn/2;
  144215. int i,p;
  144216. for(i=0;i<leftbegin;i++)
  144217. d[i]=0.f;
  144218. for(p=0;i<leftend;i++,p++)
  144219. d[i]*=windowLW[p];
  144220. for(i=rightbegin,p=rn/2-1;i<rightend;i++,p--)
  144221. d[i]*=windowNW[p];
  144222. for(;i<n;i++)
  144223. d[i]=0.f;
  144224. }
  144225. }
  144226. #endif
  144227. /*** End of inlined file: window.c ***/
  144228. #else
  144229. #include <vorbis/vorbisenc.h>
  144230. #include <vorbis/codec.h>
  144231. #include <vorbis/vorbisfile.h>
  144232. #endif
  144233. }
  144234. BEGIN_JUCE_NAMESPACE
  144235. using namespace OggVorbisNamespace;
  144236. static const char* const oggFormatName = "Ogg-Vorbis file";
  144237. static const tchar* const oggExtensions[] = { T(".ogg"), 0 };
  144238. class OggReader : public AudioFormatReader
  144239. {
  144240. OggVorbis_File ovFile;
  144241. ov_callbacks callbacks;
  144242. AudioSampleBuffer reservoir;
  144243. int reservoirStart, samplesInReservoir;
  144244. public:
  144245. OggReader (InputStream* const inp)
  144246. : AudioFormatReader (inp, TRANS (oggFormatName)),
  144247. reservoir (2, 4096),
  144248. reservoirStart (0),
  144249. samplesInReservoir (0)
  144250. {
  144251. sampleRate = 0;
  144252. usesFloatingPointData = true;
  144253. callbacks.read_func = &oggReadCallback;
  144254. callbacks.seek_func = &oggSeekCallback;
  144255. callbacks.close_func = &oggCloseCallback;
  144256. callbacks.tell_func = &oggTellCallback;
  144257. const int err = ov_open_callbacks (input, &ovFile, 0, 0, callbacks);
  144258. if (err == 0)
  144259. {
  144260. vorbis_info* info = ov_info (&ovFile, -1);
  144261. lengthInSamples = (uint32) ov_pcm_total (&ovFile, -1);
  144262. numChannels = info->channels;
  144263. bitsPerSample = 16;
  144264. sampleRate = info->rate;
  144265. reservoir.setSize (numChannels,
  144266. (int) jmin (lengthInSamples, (int64) reservoir.getNumSamples()));
  144267. }
  144268. }
  144269. ~OggReader()
  144270. {
  144271. ov_clear (&ovFile);
  144272. }
  144273. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  144274. int64 startSampleInFile, int numSamples)
  144275. {
  144276. while (numSamples > 0)
  144277. {
  144278. const int numAvailable = reservoirStart + samplesInReservoir - startSampleInFile;
  144279. if (startSampleInFile >= reservoirStart && numAvailable > 0)
  144280. {
  144281. // got a few samples overlapping, so use them before seeking..
  144282. const int numToUse = jmin (numSamples, numAvailable);
  144283. for (int i = jmin (numDestChannels, reservoir.getNumChannels()); --i >= 0;)
  144284. if (destSamples[i] != 0)
  144285. memcpy (destSamples[i] + startOffsetInDestBuffer,
  144286. reservoir.getSampleData (i, (int) (startSampleInFile - reservoirStart)),
  144287. sizeof (float) * numToUse);
  144288. startSampleInFile += numToUse;
  144289. numSamples -= numToUse;
  144290. startOffsetInDestBuffer += numToUse;
  144291. if (numSamples == 0)
  144292. break;
  144293. }
  144294. if (startSampleInFile < reservoirStart
  144295. || startSampleInFile + numSamples > reservoirStart + samplesInReservoir)
  144296. {
  144297. // buffer miss, so refill the reservoir
  144298. int bitStream = 0;
  144299. reservoirStart = jmax (0, (int) startSampleInFile);
  144300. samplesInReservoir = reservoir.getNumSamples();
  144301. if (reservoirStart != (int) ov_pcm_tell (&ovFile))
  144302. ov_pcm_seek (&ovFile, reservoirStart);
  144303. int offset = 0;
  144304. int numToRead = samplesInReservoir;
  144305. while (numToRead > 0)
  144306. {
  144307. float** dataIn = 0;
  144308. const int samps = ov_read_float (&ovFile, &dataIn, numToRead, &bitStream);
  144309. if (samps <= 0)
  144310. break;
  144311. jassert (samps <= numToRead);
  144312. for (int i = jmin ((int) numChannels, reservoir.getNumChannels()); --i >= 0;)
  144313. {
  144314. memcpy (reservoir.getSampleData (i, offset),
  144315. dataIn[i],
  144316. sizeof (float) * samps);
  144317. }
  144318. numToRead -= samps;
  144319. offset += samps;
  144320. }
  144321. if (numToRead > 0)
  144322. reservoir.clear (offset, numToRead);
  144323. }
  144324. }
  144325. if (numSamples > 0)
  144326. {
  144327. for (int i = numDestChannels; --i >= 0;)
  144328. if (destSamples[i] != 0)
  144329. zeromem (destSamples[i] + startOffsetInDestBuffer,
  144330. sizeof (int) * numSamples);
  144331. }
  144332. return true;
  144333. }
  144334. static size_t oggReadCallback (void* ptr, size_t size, size_t nmemb, void* datasource)
  144335. {
  144336. return (size_t) (((InputStream*) datasource)->read (ptr, (int) (size * nmemb)) / size);
  144337. }
  144338. static int oggSeekCallback (void* datasource, ogg_int64_t offset, int whence)
  144339. {
  144340. InputStream* const in = (InputStream*) datasource;
  144341. if (whence == SEEK_CUR)
  144342. offset += in->getPosition();
  144343. else if (whence == SEEK_END)
  144344. offset += in->getTotalLength();
  144345. in->setPosition (offset);
  144346. return 0;
  144347. }
  144348. static int oggCloseCallback (void*)
  144349. {
  144350. return 0;
  144351. }
  144352. static long oggTellCallback (void* datasource)
  144353. {
  144354. return (long) ((InputStream*) datasource)->getPosition();
  144355. }
  144356. juce_UseDebuggingNewOperator
  144357. };
  144358. class OggWriter : public AudioFormatWriter
  144359. {
  144360. ogg_stream_state os;
  144361. ogg_page og;
  144362. ogg_packet op;
  144363. vorbis_info vi;
  144364. vorbis_comment vc;
  144365. vorbis_dsp_state vd;
  144366. vorbis_block vb;
  144367. public:
  144368. bool ok;
  144369. OggWriter (OutputStream* const out,
  144370. const double sampleRate,
  144371. const int numChannels,
  144372. const int bitsPerSample,
  144373. const int qualityIndex)
  144374. : AudioFormatWriter (out, TRANS (oggFormatName),
  144375. sampleRate,
  144376. numChannels,
  144377. bitsPerSample)
  144378. {
  144379. ok = false;
  144380. vorbis_info_init (&vi);
  144381. if (vorbis_encode_init_vbr (&vi,
  144382. numChannels,
  144383. (int) sampleRate,
  144384. jlimit (0.0f, 1.0f, qualityIndex * 0.5f)) == 0)
  144385. {
  144386. vorbis_comment_init (&vc);
  144387. if (JUCEApplication::getInstance() != 0)
  144388. vorbis_comment_add_tag (&vc, "ENCODER", const_cast <char*> (JUCEApplication::getInstance()->getApplicationName().toUTF8()));
  144389. vorbis_analysis_init (&vd, &vi);
  144390. vorbis_block_init (&vd, &vb);
  144391. ogg_stream_init (&os, Random::getSystemRandom().nextInt());
  144392. ogg_packet header;
  144393. ogg_packet header_comm;
  144394. ogg_packet header_code;
  144395. vorbis_analysis_headerout (&vd, &vc, &header, &header_comm, &header_code);
  144396. ogg_stream_packetin (&os, &header);
  144397. ogg_stream_packetin (&os, &header_comm);
  144398. ogg_stream_packetin (&os, &header_code);
  144399. for (;;)
  144400. {
  144401. if (ogg_stream_flush (&os, &og) == 0)
  144402. break;
  144403. output->write (og.header, og.header_len);
  144404. output->write (og.body, og.body_len);
  144405. }
  144406. ok = true;
  144407. }
  144408. }
  144409. ~OggWriter()
  144410. {
  144411. if (ok)
  144412. {
  144413. // write a zero-length packet to show ogg that we're finished..
  144414. write (0, 0);
  144415. ogg_stream_clear (&os);
  144416. vorbis_block_clear (&vb);
  144417. vorbis_dsp_clear (&vd);
  144418. vorbis_comment_clear (&vc);
  144419. vorbis_info_clear (&vi);
  144420. output->flush();
  144421. }
  144422. else
  144423. {
  144424. vorbis_info_clear (&vi);
  144425. output = 0; // to stop the base class deleting this, as it needs to be returned
  144426. // to the caller of createWriter()
  144427. }
  144428. }
  144429. bool write (const int** samplesToWrite, int numSamples)
  144430. {
  144431. if (! ok)
  144432. return false;
  144433. if (numSamples > 0)
  144434. {
  144435. const double gain = 1.0 / 0x80000000u;
  144436. float** const vorbisBuffer = vorbis_analysis_buffer (&vd, numSamples);
  144437. for (int i = numChannels; --i >= 0;)
  144438. {
  144439. float* const dst = vorbisBuffer[i];
  144440. const int* const src = samplesToWrite [i];
  144441. if (src != 0 && dst != 0)
  144442. {
  144443. for (int j = 0; j < numSamples; ++j)
  144444. dst[j] = (float) (src[j] * gain);
  144445. }
  144446. }
  144447. }
  144448. vorbis_analysis_wrote (&vd, numSamples);
  144449. while (vorbis_analysis_blockout (&vd, &vb) == 1)
  144450. {
  144451. vorbis_analysis (&vb, 0);
  144452. vorbis_bitrate_addblock (&vb);
  144453. while (vorbis_bitrate_flushpacket (&vd, &op))
  144454. {
  144455. ogg_stream_packetin (&os, &op);
  144456. for (;;)
  144457. {
  144458. if (ogg_stream_pageout (&os, &og) == 0)
  144459. break;
  144460. output->write (og.header, og.header_len);
  144461. output->write (og.body, og.body_len);
  144462. if (ogg_page_eos (&og))
  144463. break;
  144464. }
  144465. }
  144466. }
  144467. return true;
  144468. }
  144469. juce_UseDebuggingNewOperator
  144470. };
  144471. OggVorbisAudioFormat::OggVorbisAudioFormat()
  144472. : AudioFormat (TRANS (oggFormatName), (const tchar**) oggExtensions)
  144473. {
  144474. }
  144475. OggVorbisAudioFormat::~OggVorbisAudioFormat()
  144476. {
  144477. }
  144478. const Array <int> OggVorbisAudioFormat::getPossibleSampleRates()
  144479. {
  144480. const int rates[] = { 22050, 32000, 44100, 48000, 0 };
  144481. return Array <int> (rates);
  144482. }
  144483. const Array <int> OggVorbisAudioFormat::getPossibleBitDepths()
  144484. {
  144485. Array <int> depths;
  144486. depths.add (32);
  144487. return depths;
  144488. }
  144489. bool OggVorbisAudioFormat::canDoStereo()
  144490. {
  144491. return true;
  144492. }
  144493. bool OggVorbisAudioFormat::canDoMono()
  144494. {
  144495. return true;
  144496. }
  144497. AudioFormatReader* OggVorbisAudioFormat::createReaderFor (InputStream* in,
  144498. const bool deleteStreamIfOpeningFails)
  144499. {
  144500. ScopedPointer <OggReader> r (new OggReader (in));
  144501. if (r->sampleRate != 0)
  144502. return r.release();
  144503. if (! deleteStreamIfOpeningFails)
  144504. r->input = 0;
  144505. return 0;
  144506. }
  144507. AudioFormatWriter* OggVorbisAudioFormat::createWriterFor (OutputStream* out,
  144508. double sampleRate,
  144509. unsigned int numChannels,
  144510. int bitsPerSample,
  144511. const StringPairArray& /*metadataValues*/,
  144512. int qualityOptionIndex)
  144513. {
  144514. ScopedPointer <OggWriter> w (new OggWriter (out,
  144515. sampleRate,
  144516. numChannels,
  144517. bitsPerSample,
  144518. qualityOptionIndex));
  144519. return w->ok ? w.release() : 0;
  144520. }
  144521. bool OggVorbisAudioFormat::isCompressed()
  144522. {
  144523. return true;
  144524. }
  144525. const StringArray OggVorbisAudioFormat::getQualityOptions()
  144526. {
  144527. StringArray s;
  144528. s.add ("Low Quality");
  144529. s.add ("Medium Quality");
  144530. s.add ("High Quality");
  144531. return s;
  144532. }
  144533. int OggVorbisAudioFormat::estimateOggFileQuality (const File& source)
  144534. {
  144535. FileInputStream* const in = source.createInputStream();
  144536. if (in != 0)
  144537. {
  144538. ScopedPointer <AudioFormatReader> r (createReaderFor (in, true));
  144539. if (r != 0)
  144540. {
  144541. const int64 numSamps = r->lengthInSamples;
  144542. r = 0;
  144543. const int64 fileNumSamps = source.getSize() / 4;
  144544. const double ratio = numSamps / (double) fileNumSamps;
  144545. if (ratio > 12.0)
  144546. return 0;
  144547. else if (ratio > 6.0)
  144548. return 1;
  144549. else
  144550. return 2;
  144551. }
  144552. }
  144553. return 1;
  144554. }
  144555. END_JUCE_NAMESPACE
  144556. #endif
  144557. /*** End of inlined file: juce_OggVorbisAudioFormat.cpp ***/
  144558. #endif
  144559. #if JUCE_BUILD_CORE && ! JUCE_ONLY_BUILD_CORE_LIBRARY // do these in the core section to help balance the sizes
  144560. /*** Start of inlined file: juce_JPEGLoader.cpp ***/
  144561. #if JUCE_MSVC
  144562. #pragma warning (push)
  144563. #endif
  144564. namespace jpeglibNamespace
  144565. {
  144566. #if JUCE_INCLUDE_JPEGLIB_CODE
  144567. #if JUCE_MINGW
  144568. typedef unsigned char boolean;
  144569. #endif
  144570. extern "C"
  144571. {
  144572. #define JPEG_INTERNALS
  144573. #undef FAR
  144574. /*** Start of inlined file: jpeglib.h ***/
  144575. #ifndef JPEGLIB_H
  144576. #define JPEGLIB_H
  144577. #ifndef JCONFIG_INCLUDED /* in case jinclude.h already did */
  144578. /*** Start of inlined file: jconfig.h ***/
  144579. // disable all the warnings under MSVC
  144580. #ifdef _MSC_VER
  144581. #pragma warning (disable: 4996 4267 4100 4127 4702 4244)
  144582. #endif
  144583. #ifdef __BORLANDC__
  144584. #pragma warn -8057
  144585. #pragma warn -8019
  144586. #pragma warn -8004
  144587. #pragma warn -8008
  144588. #endif
  144589. #define HAVE_PROTOTYPES
  144590. #define HAVE_UNSIGNED_CHAR
  144591. #define HAVE_UNSIGNED_SHORT
  144592. #undef CHAR_IS_UNSIGNED
  144593. #define HAVE_STDDEF_H
  144594. #define HAVE_STDLIB_H
  144595. #undef NEED_BSD_STRINGS
  144596. #undef NEED_SYS_TYPES_H
  144597. #undef NEED_FAR_POINTERS /* we presume a 32-bit flat memory model */
  144598. #undef NEED_SHORT_EXTERNAL_NAMES
  144599. #undef INCOMPLETE_TYPES_BROKEN
  144600. #ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
  144601. typedef unsigned char boolean;
  144602. #endif
  144603. #define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
  144604. #ifdef JPEG_INTERNALS
  144605. #undef RIGHT_SHIFT_IS_UNSIGNED
  144606. #endif /* JPEG_INTERNALS */
  144607. #ifdef JPEG_CJPEG_DJPEG
  144608. #define BMP_SUPPORTED /* BMP image file format */
  144609. #define GIF_SUPPORTED /* GIF image file format */
  144610. #define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
  144611. #undef RLE_SUPPORTED /* Utah RLE image file format */
  144612. #define TARGA_SUPPORTED /* Targa image file format */
  144613. #define TWO_FILE_COMMANDLINE /* optional */
  144614. #define USE_SETMODE /* Microsoft has setmode() */
  144615. #undef NEED_SIGNAL_CATCHER
  144616. #undef DONT_USE_B_MODE
  144617. #undef PROGRESS_REPORT /* optional */
  144618. #endif /* JPEG_CJPEG_DJPEG */
  144619. /*** End of inlined file: jconfig.h ***/
  144620. /* widely used configuration options */
  144621. #endif
  144622. /*** Start of inlined file: jmorecfg.h ***/
  144623. #define BITS_IN_JSAMPLE 8 /* use 8 or 12 */
  144624. #define MAX_COMPONENTS 10 /* maximum number of image components */
  144625. #if BITS_IN_JSAMPLE == 8
  144626. #ifdef HAVE_UNSIGNED_CHAR
  144627. typedef unsigned char JSAMPLE;
  144628. #define GETJSAMPLE(value) ((int) (value))
  144629. #else /* not HAVE_UNSIGNED_CHAR */
  144630. typedef char JSAMPLE;
  144631. #ifdef CHAR_IS_UNSIGNED
  144632. #define GETJSAMPLE(value) ((int) (value))
  144633. #else
  144634. #define GETJSAMPLE(value) ((int) (value) & 0xFF)
  144635. #endif /* CHAR_IS_UNSIGNED */
  144636. #endif /* HAVE_UNSIGNED_CHAR */
  144637. #define MAXJSAMPLE 255
  144638. #define CENTERJSAMPLE 128
  144639. #endif /* BITS_IN_JSAMPLE == 8 */
  144640. #if BITS_IN_JSAMPLE == 12
  144641. typedef short JSAMPLE;
  144642. #define GETJSAMPLE(value) ((int) (value))
  144643. #define MAXJSAMPLE 4095
  144644. #define CENTERJSAMPLE 2048
  144645. #endif /* BITS_IN_JSAMPLE == 12 */
  144646. typedef short JCOEF;
  144647. #ifdef HAVE_UNSIGNED_CHAR
  144648. typedef unsigned char JOCTET;
  144649. #define GETJOCTET(value) (value)
  144650. #else /* not HAVE_UNSIGNED_CHAR */
  144651. typedef char JOCTET;
  144652. #ifdef CHAR_IS_UNSIGNED
  144653. #define GETJOCTET(value) (value)
  144654. #else
  144655. #define GETJOCTET(value) ((value) & 0xFF)
  144656. #endif /* CHAR_IS_UNSIGNED */
  144657. #endif /* HAVE_UNSIGNED_CHAR */
  144658. #ifdef HAVE_UNSIGNED_CHAR
  144659. typedef unsigned char UINT8;
  144660. #else /* not HAVE_UNSIGNED_CHAR */
  144661. #ifdef CHAR_IS_UNSIGNED
  144662. typedef char UINT8;
  144663. #else /* not CHAR_IS_UNSIGNED */
  144664. typedef short UINT8;
  144665. #endif /* CHAR_IS_UNSIGNED */
  144666. #endif /* HAVE_UNSIGNED_CHAR */
  144667. #ifdef HAVE_UNSIGNED_SHORT
  144668. typedef unsigned short UINT16;
  144669. #else /* not HAVE_UNSIGNED_SHORT */
  144670. typedef unsigned int UINT16;
  144671. #endif /* HAVE_UNSIGNED_SHORT */
  144672. #ifndef XMD_H /* X11/xmd.h correctly defines INT16 */
  144673. typedef short INT16;
  144674. #endif
  144675. #ifndef XMD_H /* X11/xmd.h correctly defines INT32 */
  144676. typedef long INT32;
  144677. #endif
  144678. typedef unsigned int JDIMENSION;
  144679. #define JPEG_MAX_DIMENSION 65500L /* a tad under 64K to prevent overflows */
  144680. #define METHODDEF(type) static type
  144681. #define LOCAL(type) static type
  144682. #define GLOBAL(type) type
  144683. #define EXTERN(type) extern type
  144684. #ifdef HAVE_PROTOTYPES
  144685. #define JMETHOD(type,methodname,arglist) type (*methodname) arglist
  144686. #else
  144687. #define JMETHOD(type,methodname,arglist) type (*methodname) ()
  144688. #endif
  144689. #ifdef NEED_FAR_POINTERS
  144690. #define FAR far
  144691. #else
  144692. #define FAR
  144693. #endif
  144694. #ifndef HAVE_BOOLEAN
  144695. typedef int boolean;
  144696. #endif
  144697. #ifndef FALSE /* in case these macros already exist */
  144698. #define FALSE 0 /* values of boolean */
  144699. #endif
  144700. #ifndef TRUE
  144701. #define TRUE 1
  144702. #endif
  144703. #ifdef JPEG_INTERNALS
  144704. #define JPEG_INTERNAL_OPTIONS
  144705. #endif
  144706. #ifdef JPEG_INTERNAL_OPTIONS
  144707. #define DCT_ISLOW_SUPPORTED /* slow but accurate integer algorithm */
  144708. #define DCT_IFAST_SUPPORTED /* faster, less accurate integer method */
  144709. #define DCT_FLOAT_SUPPORTED /* floating-point: accurate, fast on fast HW */
  144710. #undef C_ARITH_CODING_SUPPORTED /* Arithmetic coding back end? */
  144711. #define C_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
  144712. #define C_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
  144713. #define ENTROPY_OPT_SUPPORTED /* Optimization of entropy coding parms? */
  144714. #define INPUT_SMOOTHING_SUPPORTED /* Input image smoothing option? */
  144715. #undef D_ARITH_CODING_SUPPORTED /* Arithmetic coding back end? */
  144716. #define D_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
  144717. #define D_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
  144718. #define SAVE_MARKERS_SUPPORTED /* jpeg_save_markers() needed? */
  144719. #define BLOCK_SMOOTHING_SUPPORTED /* Block smoothing? (Progressive only) */
  144720. #define IDCT_SCALING_SUPPORTED /* Output rescaling via IDCT? */
  144721. #undef UPSAMPLE_SCALING_SUPPORTED /* Output rescaling at upsample stage? */
  144722. #define UPSAMPLE_MERGING_SUPPORTED /* Fast path for sloppy upsampling? */
  144723. #define QUANT_1PASS_SUPPORTED /* 1-pass color quantization? */
  144724. #define QUANT_2PASS_SUPPORTED /* 2-pass color quantization? */
  144725. #define RGB_RED 0 /* Offset of Red in an RGB scanline element */
  144726. #define RGB_GREEN 1 /* Offset of Green */
  144727. #define RGB_BLUE 2 /* Offset of Blue */
  144728. #define RGB_PIXELSIZE 3 /* JSAMPLEs per RGB scanline element */
  144729. #ifndef INLINE
  144730. #ifdef __GNUC__ /* for instance, GNU C knows about inline */
  144731. #define INLINE __inline__
  144732. #endif
  144733. #ifndef INLINE
  144734. #define INLINE /* default is to define it as empty */
  144735. #endif
  144736. #endif
  144737. #ifndef MULTIPLIER
  144738. #define MULTIPLIER int /* type for fastest integer multiply */
  144739. #endif
  144740. #ifndef FAST_FLOAT
  144741. #ifdef HAVE_PROTOTYPES
  144742. #define FAST_FLOAT float
  144743. #else
  144744. #define FAST_FLOAT double
  144745. #endif
  144746. #endif
  144747. #endif /* JPEG_INTERNAL_OPTIONS */
  144748. /*** End of inlined file: jmorecfg.h ***/
  144749. /* seldom changed options */
  144750. #define JPEG_LIB_VERSION 62 /* Version 6b */
  144751. #define DCTSIZE 8 /* The basic DCT block is 8x8 samples */
  144752. #define DCTSIZE2 64 /* DCTSIZE squared; # of elements in a block */
  144753. #define NUM_QUANT_TBLS 4 /* Quantization tables are numbered 0..3 */
  144754. #define NUM_HUFF_TBLS 4 /* Huffman tables are numbered 0..3 */
  144755. #define NUM_ARITH_TBLS 16 /* Arith-coding tables are numbered 0..15 */
  144756. #define MAX_COMPS_IN_SCAN 4 /* JPEG limit on # of components in one scan */
  144757. #define MAX_SAMP_FACTOR 4 /* JPEG limit on sampling factors */
  144758. #define C_MAX_BLOCKS_IN_MCU 10 /* compressor's limit on blocks per MCU */
  144759. #ifndef D_MAX_BLOCKS_IN_MCU
  144760. #define D_MAX_BLOCKS_IN_MCU 10 /* decompressor's limit on blocks per MCU */
  144761. #endif
  144762. typedef JSAMPLE FAR *JSAMPROW; /* ptr to one image row of pixel samples. */
  144763. typedef JSAMPROW *JSAMPARRAY; /* ptr to some rows (a 2-D sample array) */
  144764. typedef JSAMPARRAY *JSAMPIMAGE; /* a 3-D sample array: top index is color */
  144765. typedef JCOEF JBLOCK[DCTSIZE2]; /* one block of coefficients */
  144766. typedef JBLOCK FAR *JBLOCKROW; /* pointer to one row of coefficient blocks */
  144767. typedef JBLOCKROW *JBLOCKARRAY; /* a 2-D array of coefficient blocks */
  144768. typedef JBLOCKARRAY *JBLOCKIMAGE; /* a 3-D array of coefficient blocks */
  144769. typedef JCOEF FAR *JCOEFPTR; /* useful in a couple of places */
  144770. typedef struct {
  144771. UINT16 quantval[DCTSIZE2]; /* quantization step for each coefficient */
  144772. boolean sent_table; /* TRUE when table has been output */
  144773. } JQUANT_TBL;
  144774. typedef struct {
  144775. UINT8 bits[17]; /* bits[k] = # of symbols with codes of */
  144776. UINT8 huffval[256]; /* The symbols, in order of incr code length */
  144777. boolean sent_table; /* TRUE when table has been output */
  144778. } JHUFF_TBL;
  144779. typedef struct {
  144780. int component_id; /* identifier for this component (0..255) */
  144781. int component_index; /* its index in SOF or cinfo->comp_info[] */
  144782. int h_samp_factor; /* horizontal sampling factor (1..4) */
  144783. int v_samp_factor; /* vertical sampling factor (1..4) */
  144784. int quant_tbl_no; /* quantization table selector (0..3) */
  144785. int dc_tbl_no; /* DC entropy table selector (0..3) */
  144786. int ac_tbl_no; /* AC entropy table selector (0..3) */
  144787. JDIMENSION width_in_blocks;
  144788. JDIMENSION height_in_blocks;
  144789. int DCT_scaled_size;
  144790. JDIMENSION downsampled_width; /* actual width in samples */
  144791. JDIMENSION downsampled_height; /* actual height in samples */
  144792. boolean component_needed; /* do we need the value of this component? */
  144793. int MCU_width; /* number of blocks per MCU, horizontally */
  144794. int MCU_height; /* number of blocks per MCU, vertically */
  144795. int MCU_blocks; /* MCU_width * MCU_height */
  144796. int MCU_sample_width; /* MCU width in samples, MCU_width*DCT_scaled_size */
  144797. int last_col_width; /* # of non-dummy blocks across in last MCU */
  144798. int last_row_height; /* # of non-dummy blocks down in last MCU */
  144799. JQUANT_TBL * quant_table;
  144800. void * dct_table;
  144801. } jpeg_component_info;
  144802. typedef struct {
  144803. int comps_in_scan; /* number of components encoded in this scan */
  144804. int component_index[MAX_COMPS_IN_SCAN]; /* their SOF/comp_info[] indexes */
  144805. int Ss, Se; /* progressive JPEG spectral selection parms */
  144806. int Ah, Al; /* progressive JPEG successive approx. parms */
  144807. } jpeg_scan_info;
  144808. typedef struct jpeg_marker_struct FAR * jpeg_saved_marker_ptr;
  144809. struct jpeg_marker_struct {
  144810. jpeg_saved_marker_ptr next; /* next in list, or NULL */
  144811. UINT8 marker; /* marker code: JPEG_COM, or JPEG_APP0+n */
  144812. unsigned int original_length; /* # bytes of data in the file */
  144813. unsigned int data_length; /* # bytes of data saved at data[] */
  144814. JOCTET FAR * data; /* the data contained in the marker */
  144815. };
  144816. typedef enum {
  144817. JCS_UNKNOWN, /* error/unspecified */
  144818. JCS_GRAYSCALE, /* monochrome */
  144819. JCS_RGB, /* red/green/blue */
  144820. JCS_YCbCr, /* Y/Cb/Cr (also known as YUV) */
  144821. JCS_CMYK, /* C/M/Y/K */
  144822. JCS_YCCK /* Y/Cb/Cr/K */
  144823. } J_COLOR_SPACE;
  144824. typedef enum {
  144825. JDCT_ISLOW, /* slow but accurate integer algorithm */
  144826. JDCT_IFAST, /* faster, less accurate integer method */
  144827. JDCT_FLOAT /* floating-point: accurate, fast on fast HW */
  144828. } J_DCT_METHOD;
  144829. #ifndef JDCT_DEFAULT /* may be overridden in jconfig.h */
  144830. #define JDCT_DEFAULT JDCT_ISLOW
  144831. #endif
  144832. #ifndef JDCT_FASTEST /* may be overridden in jconfig.h */
  144833. #define JDCT_FASTEST JDCT_IFAST
  144834. #endif
  144835. typedef enum {
  144836. JDITHER_NONE, /* no dithering */
  144837. JDITHER_ORDERED, /* simple ordered dither */
  144838. JDITHER_FS /* Floyd-Steinberg error diffusion dither */
  144839. } J_DITHER_MODE;
  144840. #define jpeg_common_fields \
  144841. struct jpeg_error_mgr * err; /* Error handler module */\
  144842. struct jpeg_memory_mgr * mem; /* Memory manager module */\
  144843. struct jpeg_progress_mgr * progress; /* Progress monitor, or NULL if none */\
  144844. void * client_data; /* Available for use by application */\
  144845. boolean is_decompressor; /* So common code can tell which is which */\
  144846. int global_state /* For checking call sequence validity */
  144847. struct jpeg_common_struct {
  144848. jpeg_common_fields; /* Fields common to both master struct types */
  144849. };
  144850. typedef struct jpeg_common_struct * j_common_ptr;
  144851. typedef struct jpeg_compress_struct * j_compress_ptr;
  144852. typedef struct jpeg_decompress_struct * j_decompress_ptr;
  144853. struct jpeg_compress_struct {
  144854. jpeg_common_fields; /* Fields shared with jpeg_decompress_struct */
  144855. struct jpeg_destination_mgr * dest;
  144856. JDIMENSION image_width; /* input image width */
  144857. JDIMENSION image_height; /* input image height */
  144858. int input_components; /* # of color components in input image */
  144859. J_COLOR_SPACE in_color_space; /* colorspace of input image */
  144860. double input_gamma; /* image gamma of input image */
  144861. int data_precision; /* bits of precision in image data */
  144862. int num_components; /* # of color components in JPEG image */
  144863. J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */
  144864. jpeg_component_info * comp_info;
  144865. JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS];
  144866. JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
  144867. JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
  144868. UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
  144869. UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
  144870. UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
  144871. int num_scans; /* # of entries in scan_info array */
  144872. const jpeg_scan_info * scan_info; /* script for multi-scan file, or NULL */
  144873. boolean raw_data_in; /* TRUE=caller supplies downsampled data */
  144874. boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */
  144875. boolean optimize_coding; /* TRUE=optimize entropy encoding parms */
  144876. boolean CCIR601_sampling; /* TRUE=first samples are cosited */
  144877. int smoothing_factor; /* 1..100, or 0 for no input smoothing */
  144878. J_DCT_METHOD dct_method; /* DCT algorithm selector */
  144879. unsigned int restart_interval; /* MCUs per restart, or 0 for no restart */
  144880. int restart_in_rows; /* if > 0, MCU rows per restart interval */
  144881. boolean write_JFIF_header; /* should a JFIF marker be written? */
  144882. UINT8 JFIF_major_version; /* What to write for the JFIF version number */
  144883. UINT8 JFIF_minor_version;
  144884. UINT8 density_unit; /* JFIF code for pixel size units */
  144885. UINT16 X_density; /* Horizontal pixel density */
  144886. UINT16 Y_density; /* Vertical pixel density */
  144887. boolean write_Adobe_marker; /* should an Adobe marker be written? */
  144888. JDIMENSION next_scanline; /* 0 .. image_height-1 */
  144889. boolean progressive_mode; /* TRUE if scan script uses progressive mode */
  144890. int max_h_samp_factor; /* largest h_samp_factor */
  144891. int max_v_samp_factor; /* largest v_samp_factor */
  144892. JDIMENSION total_iMCU_rows; /* # of iMCU rows to be input to coef ctlr */
  144893. int comps_in_scan; /* # of JPEG components in this scan */
  144894. jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN];
  144895. JDIMENSION MCUs_per_row; /* # of MCUs across the image */
  144896. JDIMENSION MCU_rows_in_scan; /* # of MCU rows in the image */
  144897. int blocks_in_MCU; /* # of DCT blocks per MCU */
  144898. int MCU_membership[C_MAX_BLOCKS_IN_MCU];
  144899. int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */
  144900. struct jpeg_comp_master * master;
  144901. struct jpeg_c_main_controller * main;
  144902. struct jpeg_c_prep_controller * prep;
  144903. struct jpeg_c_coef_controller * coef;
  144904. struct jpeg_marker_writer * marker;
  144905. struct jpeg_color_converter * cconvert;
  144906. struct jpeg_downsampler * downsample;
  144907. struct jpeg_forward_dct * fdct;
  144908. struct jpeg_entropy_encoder * entropy;
  144909. jpeg_scan_info * script_space; /* workspace for jpeg_simple_progression */
  144910. int script_space_size;
  144911. };
  144912. struct jpeg_decompress_struct {
  144913. jpeg_common_fields; /* Fields shared with jpeg_compress_struct */
  144914. struct jpeg_source_mgr * src;
  144915. JDIMENSION image_width; /* nominal image width (from SOF marker) */
  144916. JDIMENSION image_height; /* nominal image height */
  144917. int num_components; /* # of color components in JPEG image */
  144918. J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */
  144919. J_COLOR_SPACE out_color_space; /* colorspace for output */
  144920. unsigned int scale_num, scale_denom; /* fraction by which to scale image */
  144921. double output_gamma; /* image gamma wanted in output */
  144922. boolean buffered_image; /* TRUE=multiple output passes */
  144923. boolean raw_data_out; /* TRUE=downsampled data wanted */
  144924. J_DCT_METHOD dct_method; /* IDCT algorithm selector */
  144925. boolean do_fancy_upsampling; /* TRUE=apply fancy upsampling */
  144926. boolean do_block_smoothing; /* TRUE=apply interblock smoothing */
  144927. boolean quantize_colors; /* TRUE=colormapped output wanted */
  144928. J_DITHER_MODE dither_mode; /* type of color dithering to use */
  144929. boolean two_pass_quantize; /* TRUE=use two-pass color quantization */
  144930. int desired_number_of_colors; /* max # colors to use in created colormap */
  144931. boolean enable_1pass_quant; /* enable future use of 1-pass quantizer */
  144932. boolean enable_external_quant;/* enable future use of external colormap */
  144933. boolean enable_2pass_quant; /* enable future use of 2-pass quantizer */
  144934. JDIMENSION output_width; /* scaled image width */
  144935. JDIMENSION output_height; /* scaled image height */
  144936. int out_color_components; /* # of color components in out_color_space */
  144937. int output_components; /* # of color components returned */
  144938. int rec_outbuf_height; /* min recommended height of scanline buffer */
  144939. int actual_number_of_colors; /* number of entries in use */
  144940. JSAMPARRAY colormap; /* The color map as a 2-D pixel array */
  144941. JDIMENSION output_scanline; /* 0 .. output_height-1 */
  144942. int input_scan_number; /* Number of SOS markers seen so far */
  144943. JDIMENSION input_iMCU_row; /* Number of iMCU rows completed */
  144944. int output_scan_number; /* Nominal scan number being displayed */
  144945. JDIMENSION output_iMCU_row; /* Number of iMCU rows read */
  144946. int (*coef_bits)[DCTSIZE2]; /* -1 or current Al value for each coef */
  144947. JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS];
  144948. JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
  144949. JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
  144950. int data_precision; /* bits of precision in image data */
  144951. jpeg_component_info * comp_info;
  144952. boolean progressive_mode; /* TRUE if SOFn specifies progressive mode */
  144953. boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */
  144954. UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
  144955. UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
  144956. UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
  144957. unsigned int restart_interval; /* MCUs per restart interval, or 0 for no restart */
  144958. boolean saw_JFIF_marker; /* TRUE iff a JFIF APP0 marker was found */
  144959. UINT8 JFIF_major_version; /* JFIF version number */
  144960. UINT8 JFIF_minor_version;
  144961. UINT8 density_unit; /* JFIF code for pixel size units */
  144962. UINT16 X_density; /* Horizontal pixel density */
  144963. UINT16 Y_density; /* Vertical pixel density */
  144964. boolean saw_Adobe_marker; /* TRUE iff an Adobe APP14 marker was found */
  144965. UINT8 Adobe_transform; /* Color transform code from Adobe marker */
  144966. boolean CCIR601_sampling; /* TRUE=first samples are cosited */
  144967. jpeg_saved_marker_ptr marker_list; /* Head of list of saved markers */
  144968. int max_h_samp_factor; /* largest h_samp_factor */
  144969. int max_v_samp_factor; /* largest v_samp_factor */
  144970. int min_DCT_scaled_size; /* smallest DCT_scaled_size of any component */
  144971. JDIMENSION total_iMCU_rows; /* # of iMCU rows in image */
  144972. JSAMPLE * sample_range_limit; /* table for fast range-limiting */
  144973. int comps_in_scan; /* # of JPEG components in this scan */
  144974. jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN];
  144975. JDIMENSION MCUs_per_row; /* # of MCUs across the image */
  144976. JDIMENSION MCU_rows_in_scan; /* # of MCU rows in the image */
  144977. int blocks_in_MCU; /* # of DCT blocks per MCU */
  144978. int MCU_membership[D_MAX_BLOCKS_IN_MCU];
  144979. int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */
  144980. int unread_marker;
  144981. struct jpeg_decomp_master * master;
  144982. struct jpeg_d_main_controller * main;
  144983. struct jpeg_d_coef_controller * coef;
  144984. struct jpeg_d_post_controller * post;
  144985. struct jpeg_input_controller * inputctl;
  144986. struct jpeg_marker_reader * marker;
  144987. struct jpeg_entropy_decoder * entropy;
  144988. struct jpeg_inverse_dct * idct;
  144989. struct jpeg_upsampler * upsample;
  144990. struct jpeg_color_deconverter * cconvert;
  144991. struct jpeg_color_quantizer * cquantize;
  144992. };
  144993. struct jpeg_error_mgr {
  144994. JMETHOD(void, error_exit, (j_common_ptr cinfo));
  144995. JMETHOD(void, emit_message, (j_common_ptr cinfo, int msg_level));
  144996. JMETHOD(void, output_message, (j_common_ptr cinfo));
  144997. JMETHOD(void, format_message, (j_common_ptr cinfo, char * buffer));
  144998. #define JMSG_LENGTH_MAX 200 /* recommended size of format_message buffer */
  144999. JMETHOD(void, reset_error_mgr, (j_common_ptr cinfo));
  145000. int msg_code;
  145001. #define JMSG_STR_PARM_MAX 80
  145002. union {
  145003. int i[8];
  145004. char s[JMSG_STR_PARM_MAX];
  145005. } msg_parm;
  145006. int trace_level; /* max msg_level that will be displayed */
  145007. long num_warnings; /* number of corrupt-data warnings */
  145008. const char * const * jpeg_message_table; /* Library errors */
  145009. int last_jpeg_message; /* Table contains strings 0..last_jpeg_message */
  145010. const char * const * addon_message_table; /* Non-library errors */
  145011. int first_addon_message; /* code for first string in addon table */
  145012. int last_addon_message; /* code for last string in addon table */
  145013. };
  145014. struct jpeg_progress_mgr {
  145015. JMETHOD(void, progress_monitor, (j_common_ptr cinfo));
  145016. long pass_counter; /* work units completed in this pass */
  145017. long pass_limit; /* total number of work units in this pass */
  145018. int completed_passes; /* passes completed so far */
  145019. int total_passes; /* total number of passes expected */
  145020. };
  145021. struct jpeg_destination_mgr {
  145022. JOCTET * next_output_byte; /* => next byte to write in buffer */
  145023. size_t free_in_buffer; /* # of byte spaces remaining in buffer */
  145024. JMETHOD(void, init_destination, (j_compress_ptr cinfo));
  145025. JMETHOD(boolean, empty_output_buffer, (j_compress_ptr cinfo));
  145026. JMETHOD(void, term_destination, (j_compress_ptr cinfo));
  145027. };
  145028. struct jpeg_source_mgr {
  145029. const JOCTET * next_input_byte; /* => next byte to read from buffer */
  145030. size_t bytes_in_buffer; /* # of bytes remaining in buffer */
  145031. JMETHOD(void, init_source, (j_decompress_ptr cinfo));
  145032. JMETHOD(boolean, fill_input_buffer, (j_decompress_ptr cinfo));
  145033. JMETHOD(void, skip_input_data, (j_decompress_ptr cinfo, long num_bytes));
  145034. JMETHOD(boolean, resync_to_restart, (j_decompress_ptr cinfo, int desired));
  145035. JMETHOD(void, term_source, (j_decompress_ptr cinfo));
  145036. };
  145037. #define JPOOL_PERMANENT 0 /* lasts until master record is destroyed */
  145038. #define JPOOL_IMAGE 1 /* lasts until done with image/datastream */
  145039. #define JPOOL_NUMPOOLS 2
  145040. typedef struct jvirt_sarray_control * jvirt_sarray_ptr;
  145041. typedef struct jvirt_barray_control * jvirt_barray_ptr;
  145042. struct jpeg_memory_mgr {
  145043. JMETHOD(void *, alloc_small, (j_common_ptr cinfo, int pool_id,
  145044. size_t sizeofobject));
  145045. JMETHOD(void FAR *, alloc_large, (j_common_ptr cinfo, int pool_id,
  145046. size_t sizeofobject));
  145047. JMETHOD(JSAMPARRAY, alloc_sarray, (j_common_ptr cinfo, int pool_id,
  145048. JDIMENSION samplesperrow,
  145049. JDIMENSION numrows));
  145050. JMETHOD(JBLOCKARRAY, alloc_barray, (j_common_ptr cinfo, int pool_id,
  145051. JDIMENSION blocksperrow,
  145052. JDIMENSION numrows));
  145053. JMETHOD(jvirt_sarray_ptr, request_virt_sarray, (j_common_ptr cinfo,
  145054. int pool_id,
  145055. boolean pre_zero,
  145056. JDIMENSION samplesperrow,
  145057. JDIMENSION numrows,
  145058. JDIMENSION maxaccess));
  145059. JMETHOD(jvirt_barray_ptr, request_virt_barray, (j_common_ptr cinfo,
  145060. int pool_id,
  145061. boolean pre_zero,
  145062. JDIMENSION blocksperrow,
  145063. JDIMENSION numrows,
  145064. JDIMENSION maxaccess));
  145065. JMETHOD(void, realize_virt_arrays, (j_common_ptr cinfo));
  145066. JMETHOD(JSAMPARRAY, access_virt_sarray, (j_common_ptr cinfo,
  145067. jvirt_sarray_ptr ptr,
  145068. JDIMENSION start_row,
  145069. JDIMENSION num_rows,
  145070. boolean writable));
  145071. JMETHOD(JBLOCKARRAY, access_virt_barray, (j_common_ptr cinfo,
  145072. jvirt_barray_ptr ptr,
  145073. JDIMENSION start_row,
  145074. JDIMENSION num_rows,
  145075. boolean writable));
  145076. JMETHOD(void, free_pool, (j_common_ptr cinfo, int pool_id));
  145077. JMETHOD(void, self_destruct, (j_common_ptr cinfo));
  145078. long max_memory_to_use;
  145079. long max_alloc_chunk;
  145080. };
  145081. typedef JMETHOD(boolean, jpeg_marker_parser_method, (j_decompress_ptr cinfo));
  145082. #ifdef HAVE_PROTOTYPES
  145083. #define JPP(arglist) arglist
  145084. #else
  145085. #define JPP(arglist) ()
  145086. #endif
  145087. #ifdef NEED_SHORT_EXTERNAL_NAMES
  145088. #define jpeg_std_error jStdError
  145089. #define jpeg_CreateCompress jCreaCompress
  145090. #define jpeg_CreateDecompress jCreaDecompress
  145091. #define jpeg_destroy_compress jDestCompress
  145092. #define jpeg_destroy_decompress jDestDecompress
  145093. #define jpeg_stdio_dest jStdDest
  145094. #define jpeg_stdio_src jStdSrc
  145095. #define jpeg_set_defaults jSetDefaults
  145096. #define jpeg_set_colorspace jSetColorspace
  145097. #define jpeg_default_colorspace jDefColorspace
  145098. #define jpeg_set_quality jSetQuality
  145099. #define jpeg_set_linear_quality jSetLQuality
  145100. #define jpeg_add_quant_table jAddQuantTable
  145101. #define jpeg_quality_scaling jQualityScaling
  145102. #define jpeg_simple_progression jSimProgress
  145103. #define jpeg_suppress_tables jSuppressTables
  145104. #define jpeg_alloc_quant_table jAlcQTable
  145105. #define jpeg_alloc_huff_table jAlcHTable
  145106. #define jpeg_start_compress jStrtCompress
  145107. #define jpeg_write_scanlines jWrtScanlines
  145108. #define jpeg_finish_compress jFinCompress
  145109. #define jpeg_write_raw_data jWrtRawData
  145110. #define jpeg_write_marker jWrtMarker
  145111. #define jpeg_write_m_header jWrtMHeader
  145112. #define jpeg_write_m_byte jWrtMByte
  145113. #define jpeg_write_tables jWrtTables
  145114. #define jpeg_read_header jReadHeader
  145115. #define jpeg_start_decompress jStrtDecompress
  145116. #define jpeg_read_scanlines jReadScanlines
  145117. #define jpeg_finish_decompress jFinDecompress
  145118. #define jpeg_read_raw_data jReadRawData
  145119. #define jpeg_has_multiple_scans jHasMultScn
  145120. #define jpeg_start_output jStrtOutput
  145121. #define jpeg_finish_output jFinOutput
  145122. #define jpeg_input_complete jInComplete
  145123. #define jpeg_new_colormap jNewCMap
  145124. #define jpeg_consume_input jConsumeInput
  145125. #define jpeg_calc_output_dimensions jCalcDimensions
  145126. #define jpeg_save_markers jSaveMarkers
  145127. #define jpeg_set_marker_processor jSetMarker
  145128. #define jpeg_read_coefficients jReadCoefs
  145129. #define jpeg_write_coefficients jWrtCoefs
  145130. #define jpeg_copy_critical_parameters jCopyCrit
  145131. #define jpeg_abort_compress jAbrtCompress
  145132. #define jpeg_abort_decompress jAbrtDecompress
  145133. #define jpeg_abort jAbort
  145134. #define jpeg_destroy jDestroy
  145135. #define jpeg_resync_to_restart jResyncRestart
  145136. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  145137. EXTERN(struct jpeg_error_mgr *) jpeg_std_error
  145138. JPP((struct jpeg_error_mgr * err));
  145139. #define jpeg_create_compress(cinfo) \
  145140. jpeg_CreateCompress((cinfo), JPEG_LIB_VERSION, \
  145141. (size_t) sizeof(struct jpeg_compress_struct))
  145142. #define jpeg_create_decompress(cinfo) \
  145143. jpeg_CreateDecompress((cinfo), JPEG_LIB_VERSION, \
  145144. (size_t) sizeof(struct jpeg_decompress_struct))
  145145. EXTERN(void) jpeg_CreateCompress JPP((j_compress_ptr cinfo,
  145146. int version, size_t structsize));
  145147. EXTERN(void) jpeg_CreateDecompress JPP((j_decompress_ptr cinfo,
  145148. int version, size_t structsize));
  145149. EXTERN(void) jpeg_destroy_compress JPP((j_compress_ptr cinfo));
  145150. EXTERN(void) jpeg_destroy_decompress JPP((j_decompress_ptr cinfo));
  145151. EXTERN(void) jpeg_stdio_dest JPP((j_compress_ptr cinfo, FILE * outfile));
  145152. EXTERN(void) jpeg_stdio_src JPP((j_decompress_ptr cinfo, FILE * infile));
  145153. EXTERN(void) jpeg_set_defaults JPP((j_compress_ptr cinfo));
  145154. EXTERN(void) jpeg_set_colorspace JPP((j_compress_ptr cinfo,
  145155. J_COLOR_SPACE colorspace));
  145156. EXTERN(void) jpeg_default_colorspace JPP((j_compress_ptr cinfo));
  145157. EXTERN(void) jpeg_set_quality JPP((j_compress_ptr cinfo, int quality,
  145158. boolean force_baseline));
  145159. EXTERN(void) jpeg_set_linear_quality JPP((j_compress_ptr cinfo,
  145160. int scale_factor,
  145161. boolean force_baseline));
  145162. EXTERN(void) jpeg_add_quant_table JPP((j_compress_ptr cinfo, int which_tbl,
  145163. const unsigned int *basic_table,
  145164. int scale_factor,
  145165. boolean force_baseline));
  145166. EXTERN(int) jpeg_quality_scaling JPP((int quality));
  145167. EXTERN(void) jpeg_simple_progression JPP((j_compress_ptr cinfo));
  145168. EXTERN(void) jpeg_suppress_tables JPP((j_compress_ptr cinfo,
  145169. boolean suppress));
  145170. EXTERN(JQUANT_TBL *) jpeg_alloc_quant_table JPP((j_common_ptr cinfo));
  145171. EXTERN(JHUFF_TBL *) jpeg_alloc_huff_table JPP((j_common_ptr cinfo));
  145172. EXTERN(void) jpeg_start_compress JPP((j_compress_ptr cinfo,
  145173. boolean write_all_tables));
  145174. EXTERN(JDIMENSION) jpeg_write_scanlines JPP((j_compress_ptr cinfo,
  145175. JSAMPARRAY scanlines,
  145176. JDIMENSION num_lines));
  145177. EXTERN(void) jpeg_finish_compress JPP((j_compress_ptr cinfo));
  145178. EXTERN(JDIMENSION) jpeg_write_raw_data JPP((j_compress_ptr cinfo,
  145179. JSAMPIMAGE data,
  145180. JDIMENSION num_lines));
  145181. EXTERN(void) jpeg_write_marker
  145182. JPP((j_compress_ptr cinfo, int marker,
  145183. const JOCTET * dataptr, unsigned int datalen));
  145184. EXTERN(void) jpeg_write_m_header
  145185. JPP((j_compress_ptr cinfo, int marker, unsigned int datalen));
  145186. EXTERN(void) jpeg_write_m_byte
  145187. JPP((j_compress_ptr cinfo, int val));
  145188. EXTERN(void) jpeg_write_tables JPP((j_compress_ptr cinfo));
  145189. EXTERN(int) jpeg_read_header JPP((j_decompress_ptr cinfo,
  145190. boolean require_image));
  145191. #define JPEG_SUSPENDED 0 /* Suspended due to lack of input data */
  145192. #define JPEG_HEADER_OK 1 /* Found valid image datastream */
  145193. #define JPEG_HEADER_TABLES_ONLY 2 /* Found valid table-specs-only datastream */
  145194. EXTERN(boolean) jpeg_start_decompress JPP((j_decompress_ptr cinfo));
  145195. EXTERN(JDIMENSION) jpeg_read_scanlines JPP((j_decompress_ptr cinfo,
  145196. JSAMPARRAY scanlines,
  145197. JDIMENSION max_lines));
  145198. EXTERN(boolean) jpeg_finish_decompress JPP((j_decompress_ptr cinfo));
  145199. EXTERN(JDIMENSION) jpeg_read_raw_data JPP((j_decompress_ptr cinfo,
  145200. JSAMPIMAGE data,
  145201. JDIMENSION max_lines));
  145202. EXTERN(boolean) jpeg_has_multiple_scans JPP((j_decompress_ptr cinfo));
  145203. EXTERN(boolean) jpeg_start_output JPP((j_decompress_ptr cinfo,
  145204. int scan_number));
  145205. EXTERN(boolean) jpeg_finish_output JPP((j_decompress_ptr cinfo));
  145206. EXTERN(boolean) jpeg_input_complete JPP((j_decompress_ptr cinfo));
  145207. EXTERN(void) jpeg_new_colormap JPP((j_decompress_ptr cinfo));
  145208. EXTERN(int) jpeg_consume_input JPP((j_decompress_ptr cinfo));
  145209. #define JPEG_REACHED_SOS 1 /* Reached start of new scan */
  145210. #define JPEG_REACHED_EOI 2 /* Reached end of image */
  145211. #define JPEG_ROW_COMPLETED 3 /* Completed one iMCU row */
  145212. #define JPEG_SCAN_COMPLETED 4 /* Completed last iMCU row of a scan */
  145213. EXTERN(void) jpeg_calc_output_dimensions JPP((j_decompress_ptr cinfo));
  145214. EXTERN(void) jpeg_save_markers
  145215. JPP((j_decompress_ptr cinfo, int marker_code,
  145216. unsigned int length_limit));
  145217. EXTERN(void) jpeg_set_marker_processor
  145218. JPP((j_decompress_ptr cinfo, int marker_code,
  145219. jpeg_marker_parser_method routine));
  145220. EXTERN(jvirt_barray_ptr *) jpeg_read_coefficients JPP((j_decompress_ptr cinfo));
  145221. EXTERN(void) jpeg_write_coefficients JPP((j_compress_ptr cinfo,
  145222. jvirt_barray_ptr * coef_arrays));
  145223. EXTERN(void) jpeg_copy_critical_parameters JPP((j_decompress_ptr srcinfo,
  145224. j_compress_ptr dstinfo));
  145225. EXTERN(void) jpeg_abort_compress JPP((j_compress_ptr cinfo));
  145226. EXTERN(void) jpeg_abort_decompress JPP((j_decompress_ptr cinfo));
  145227. EXTERN(void) jpeg_abort JPP((j_common_ptr cinfo));
  145228. EXTERN(void) jpeg_destroy JPP((j_common_ptr cinfo));
  145229. EXTERN(boolean) jpeg_resync_to_restart JPP((j_decompress_ptr cinfo,
  145230. int desired));
  145231. #define JPEG_RST0 0xD0 /* RST0 marker code */
  145232. #define JPEG_EOI 0xD9 /* EOI marker code */
  145233. #define JPEG_APP0 0xE0 /* APP0 marker code */
  145234. #define JPEG_COM 0xFE /* COM marker code */
  145235. #ifdef INCOMPLETE_TYPES_BROKEN
  145236. #ifndef JPEG_INTERNALS /* will be defined in jpegint.h */
  145237. struct jvirt_sarray_control { long dummy; };
  145238. struct jvirt_barray_control { long dummy; };
  145239. struct jpeg_comp_master { long dummy; };
  145240. struct jpeg_c_main_controller { long dummy; };
  145241. struct jpeg_c_prep_controller { long dummy; };
  145242. struct jpeg_c_coef_controller { long dummy; };
  145243. struct jpeg_marker_writer { long dummy; };
  145244. struct jpeg_color_converter { long dummy; };
  145245. struct jpeg_downsampler { long dummy; };
  145246. struct jpeg_forward_dct { long dummy; };
  145247. struct jpeg_entropy_encoder { long dummy; };
  145248. struct jpeg_decomp_master { long dummy; };
  145249. struct jpeg_d_main_controller { long dummy; };
  145250. struct jpeg_d_coef_controller { long dummy; };
  145251. struct jpeg_d_post_controller { long dummy; };
  145252. struct jpeg_input_controller { long dummy; };
  145253. struct jpeg_marker_reader { long dummy; };
  145254. struct jpeg_entropy_decoder { long dummy; };
  145255. struct jpeg_inverse_dct { long dummy; };
  145256. struct jpeg_upsampler { long dummy; };
  145257. struct jpeg_color_deconverter { long dummy; };
  145258. struct jpeg_color_quantizer { long dummy; };
  145259. #endif /* JPEG_INTERNALS */
  145260. #endif /* INCOMPLETE_TYPES_BROKEN */
  145261. #ifdef JPEG_INTERNALS
  145262. /*** Start of inlined file: jpegint.h ***/
  145263. typedef enum { /* Operating modes for buffer controllers */
  145264. JBUF_PASS_THRU, /* Plain stripwise operation */
  145265. JBUF_SAVE_SOURCE, /* Run source subobject only, save output */
  145266. JBUF_CRANK_DEST, /* Run dest subobject only, using saved data */
  145267. JBUF_SAVE_AND_PASS /* Run both subobjects, save output */
  145268. } J_BUF_MODE;
  145269. #define CSTATE_START 100 /* after create_compress */
  145270. #define CSTATE_SCANNING 101 /* start_compress done, write_scanlines OK */
  145271. #define CSTATE_RAW_OK 102 /* start_compress done, write_raw_data OK */
  145272. #define CSTATE_WRCOEFS 103 /* jpeg_write_coefficients done */
  145273. #define DSTATE_START 200 /* after create_decompress */
  145274. #define DSTATE_INHEADER 201 /* reading header markers, no SOS yet */
  145275. #define DSTATE_READY 202 /* found SOS, ready for start_decompress */
  145276. #define DSTATE_PRELOAD 203 /* reading multiscan file in start_decompress*/
  145277. #define DSTATE_PRESCAN 204 /* performing dummy pass for 2-pass quant */
  145278. #define DSTATE_SCANNING 205 /* start_decompress done, read_scanlines OK */
  145279. #define DSTATE_RAW_OK 206 /* start_decompress done, read_raw_data OK */
  145280. #define DSTATE_BUFIMAGE 207 /* expecting jpeg_start_output */
  145281. #define DSTATE_BUFPOST 208 /* looking for SOS/EOI in jpeg_finish_output */
  145282. #define DSTATE_RDCOEFS 209 /* reading file in jpeg_read_coefficients */
  145283. #define DSTATE_STOPPING 210 /* looking for EOI in jpeg_finish_decompress */
  145284. struct jpeg_comp_master {
  145285. JMETHOD(void, prepare_for_pass, (j_compress_ptr cinfo));
  145286. JMETHOD(void, pass_startup, (j_compress_ptr cinfo));
  145287. JMETHOD(void, finish_pass, (j_compress_ptr cinfo));
  145288. boolean call_pass_startup; /* True if pass_startup must be called */
  145289. boolean is_last_pass; /* True during last pass */
  145290. };
  145291. struct jpeg_c_main_controller {
  145292. JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  145293. JMETHOD(void, process_data, (j_compress_ptr cinfo,
  145294. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  145295. JDIMENSION in_rows_avail));
  145296. };
  145297. struct jpeg_c_prep_controller {
  145298. JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  145299. JMETHOD(void, pre_process_data, (j_compress_ptr cinfo,
  145300. JSAMPARRAY input_buf,
  145301. JDIMENSION *in_row_ctr,
  145302. JDIMENSION in_rows_avail,
  145303. JSAMPIMAGE output_buf,
  145304. JDIMENSION *out_row_group_ctr,
  145305. JDIMENSION out_row_groups_avail));
  145306. };
  145307. struct jpeg_c_coef_controller {
  145308. JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  145309. JMETHOD(boolean, compress_data, (j_compress_ptr cinfo,
  145310. JSAMPIMAGE input_buf));
  145311. };
  145312. struct jpeg_color_converter {
  145313. JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  145314. JMETHOD(void, color_convert, (j_compress_ptr cinfo,
  145315. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  145316. JDIMENSION output_row, int num_rows));
  145317. };
  145318. struct jpeg_downsampler {
  145319. JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  145320. JMETHOD(void, downsample, (j_compress_ptr cinfo,
  145321. JSAMPIMAGE input_buf, JDIMENSION in_row_index,
  145322. JSAMPIMAGE output_buf,
  145323. JDIMENSION out_row_group_index));
  145324. boolean need_context_rows; /* TRUE if need rows above & below */
  145325. };
  145326. struct jpeg_forward_dct {
  145327. JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  145328. JMETHOD(void, forward_DCT, (j_compress_ptr cinfo,
  145329. jpeg_component_info * compptr,
  145330. JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  145331. JDIMENSION start_row, JDIMENSION start_col,
  145332. JDIMENSION num_blocks));
  145333. };
  145334. struct jpeg_entropy_encoder {
  145335. JMETHOD(void, start_pass, (j_compress_ptr cinfo, boolean gather_statistics));
  145336. JMETHOD(boolean, encode_mcu, (j_compress_ptr cinfo, JBLOCKROW *MCU_data));
  145337. JMETHOD(void, finish_pass, (j_compress_ptr cinfo));
  145338. };
  145339. struct jpeg_marker_writer {
  145340. JMETHOD(void, write_file_header, (j_compress_ptr cinfo));
  145341. JMETHOD(void, write_frame_header, (j_compress_ptr cinfo));
  145342. JMETHOD(void, write_scan_header, (j_compress_ptr cinfo));
  145343. JMETHOD(void, write_file_trailer, (j_compress_ptr cinfo));
  145344. JMETHOD(void, write_tables_only, (j_compress_ptr cinfo));
  145345. JMETHOD(void, write_marker_header, (j_compress_ptr cinfo, int marker,
  145346. unsigned int datalen));
  145347. JMETHOD(void, write_marker_byte, (j_compress_ptr cinfo, int val));
  145348. };
  145349. struct jpeg_decomp_master {
  145350. JMETHOD(void, prepare_for_output_pass, (j_decompress_ptr cinfo));
  145351. JMETHOD(void, finish_output_pass, (j_decompress_ptr cinfo));
  145352. boolean is_dummy_pass; /* True during 1st pass for 2-pass quant */
  145353. };
  145354. struct jpeg_input_controller {
  145355. JMETHOD(int, consume_input, (j_decompress_ptr cinfo));
  145356. JMETHOD(void, reset_input_controller, (j_decompress_ptr cinfo));
  145357. JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo));
  145358. JMETHOD(void, finish_input_pass, (j_decompress_ptr cinfo));
  145359. boolean has_multiple_scans; /* True if file has multiple scans */
  145360. boolean eoi_reached; /* True when EOI has been consumed */
  145361. };
  145362. struct jpeg_d_main_controller {
  145363. JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
  145364. JMETHOD(void, process_data, (j_decompress_ptr cinfo,
  145365. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  145366. JDIMENSION out_rows_avail));
  145367. };
  145368. struct jpeg_d_coef_controller {
  145369. JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo));
  145370. JMETHOD(int, consume_data, (j_decompress_ptr cinfo));
  145371. JMETHOD(void, start_output_pass, (j_decompress_ptr cinfo));
  145372. JMETHOD(int, decompress_data, (j_decompress_ptr cinfo,
  145373. JSAMPIMAGE output_buf));
  145374. jvirt_barray_ptr *coef_arrays;
  145375. };
  145376. struct jpeg_d_post_controller {
  145377. JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
  145378. JMETHOD(void, post_process_data, (j_decompress_ptr cinfo,
  145379. JSAMPIMAGE input_buf,
  145380. JDIMENSION *in_row_group_ctr,
  145381. JDIMENSION in_row_groups_avail,
  145382. JSAMPARRAY output_buf,
  145383. JDIMENSION *out_row_ctr,
  145384. JDIMENSION out_rows_avail));
  145385. };
  145386. struct jpeg_marker_reader {
  145387. JMETHOD(void, reset_marker_reader, (j_decompress_ptr cinfo));
  145388. JMETHOD(int, read_markers, (j_decompress_ptr cinfo));
  145389. jpeg_marker_parser_method read_restart_marker;
  145390. boolean saw_SOI; /* found SOI? */
  145391. boolean saw_SOF; /* found SOF? */
  145392. int next_restart_num; /* next restart number expected (0-7) */
  145393. unsigned int discarded_bytes; /* # of bytes skipped looking for a marker */
  145394. };
  145395. struct jpeg_entropy_decoder {
  145396. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145397. JMETHOD(boolean, decode_mcu, (j_decompress_ptr cinfo,
  145398. JBLOCKROW *MCU_data));
  145399. boolean insufficient_data; /* set TRUE after emitting warning */
  145400. };
  145401. typedef JMETHOD(void, inverse_DCT_method_ptr,
  145402. (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  145403. JCOEFPTR coef_block,
  145404. JSAMPARRAY output_buf, JDIMENSION output_col));
  145405. struct jpeg_inverse_dct {
  145406. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145407. inverse_DCT_method_ptr inverse_DCT[MAX_COMPONENTS];
  145408. };
  145409. struct jpeg_upsampler {
  145410. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145411. JMETHOD(void, upsample, (j_decompress_ptr cinfo,
  145412. JSAMPIMAGE input_buf,
  145413. JDIMENSION *in_row_group_ctr,
  145414. JDIMENSION in_row_groups_avail,
  145415. JSAMPARRAY output_buf,
  145416. JDIMENSION *out_row_ctr,
  145417. JDIMENSION out_rows_avail));
  145418. boolean need_context_rows; /* TRUE if need rows above & below */
  145419. };
  145420. struct jpeg_color_deconverter {
  145421. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145422. JMETHOD(void, color_convert, (j_decompress_ptr cinfo,
  145423. JSAMPIMAGE input_buf, JDIMENSION input_row,
  145424. JSAMPARRAY output_buf, int num_rows));
  145425. };
  145426. struct jpeg_color_quantizer {
  145427. JMETHOD(void, start_pass, (j_decompress_ptr cinfo, boolean is_pre_scan));
  145428. JMETHOD(void, color_quantize, (j_decompress_ptr cinfo,
  145429. JSAMPARRAY input_buf, JSAMPARRAY output_buf,
  145430. int num_rows));
  145431. JMETHOD(void, finish_pass, (j_decompress_ptr cinfo));
  145432. JMETHOD(void, new_color_map, (j_decompress_ptr cinfo));
  145433. };
  145434. #undef MAX
  145435. #define MAX(a,b) ((a) > (b) ? (a) : (b))
  145436. #undef MIN
  145437. #define MIN(a,b) ((a) < (b) ? (a) : (b))
  145438. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  145439. #define SHIFT_TEMPS INT32 shift_temp;
  145440. #define RIGHT_SHIFT(x,shft) \
  145441. ((shift_temp = (x)) < 0 ? \
  145442. (shift_temp >> (shft)) | ((~((INT32) 0)) << (32-(shft))) : \
  145443. (shift_temp >> (shft)))
  145444. #else
  145445. #define SHIFT_TEMPS
  145446. #define RIGHT_SHIFT(x,shft) ((x) >> (shft))
  145447. #endif
  145448. #ifdef NEED_SHORT_EXTERNAL_NAMES
  145449. #define jinit_compress_master jICompress
  145450. #define jinit_c_master_control jICMaster
  145451. #define jinit_c_main_controller jICMainC
  145452. #define jinit_c_prep_controller jICPrepC
  145453. #define jinit_c_coef_controller jICCoefC
  145454. #define jinit_color_converter jICColor
  145455. #define jinit_downsampler jIDownsampler
  145456. #define jinit_forward_dct jIFDCT
  145457. #define jinit_huff_encoder jIHEncoder
  145458. #define jinit_phuff_encoder jIPHEncoder
  145459. #define jinit_marker_writer jIMWriter
  145460. #define jinit_master_decompress jIDMaster
  145461. #define jinit_d_main_controller jIDMainC
  145462. #define jinit_d_coef_controller jIDCoefC
  145463. #define jinit_d_post_controller jIDPostC
  145464. #define jinit_input_controller jIInCtlr
  145465. #define jinit_marker_reader jIMReader
  145466. #define jinit_huff_decoder jIHDecoder
  145467. #define jinit_phuff_decoder jIPHDecoder
  145468. #define jinit_inverse_dct jIIDCT
  145469. #define jinit_upsampler jIUpsampler
  145470. #define jinit_color_deconverter jIDColor
  145471. #define jinit_1pass_quantizer jI1Quant
  145472. #define jinit_2pass_quantizer jI2Quant
  145473. #define jinit_merged_upsampler jIMUpsampler
  145474. #define jinit_memory_mgr jIMemMgr
  145475. #define jdiv_round_up jDivRound
  145476. #define jround_up jRound
  145477. #define jcopy_sample_rows jCopySamples
  145478. #define jcopy_block_row jCopyBlocks
  145479. #define jzero_far jZeroFar
  145480. #define jpeg_zigzag_order jZIGTable
  145481. #define jpeg_natural_order jZAGTable
  145482. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  145483. EXTERN(void) jinit_compress_master JPP((j_compress_ptr cinfo));
  145484. EXTERN(void) jinit_c_master_control JPP((j_compress_ptr cinfo,
  145485. boolean transcode_only));
  145486. EXTERN(void) jinit_c_main_controller JPP((j_compress_ptr cinfo,
  145487. boolean need_full_buffer));
  145488. EXTERN(void) jinit_c_prep_controller JPP((j_compress_ptr cinfo,
  145489. boolean need_full_buffer));
  145490. EXTERN(void) jinit_c_coef_controller JPP((j_compress_ptr cinfo,
  145491. boolean need_full_buffer));
  145492. EXTERN(void) jinit_color_converter JPP((j_compress_ptr cinfo));
  145493. EXTERN(void) jinit_downsampler JPP((j_compress_ptr cinfo));
  145494. EXTERN(void) jinit_forward_dct JPP((j_compress_ptr cinfo));
  145495. EXTERN(void) jinit_huff_encoder JPP((j_compress_ptr cinfo));
  145496. EXTERN(void) jinit_phuff_encoder JPP((j_compress_ptr cinfo));
  145497. EXTERN(void) jinit_marker_writer JPP((j_compress_ptr cinfo));
  145498. EXTERN(void) jinit_master_decompress JPP((j_decompress_ptr cinfo));
  145499. EXTERN(void) jinit_d_main_controller JPP((j_decompress_ptr cinfo,
  145500. boolean need_full_buffer));
  145501. EXTERN(void) jinit_d_coef_controller JPP((j_decompress_ptr cinfo,
  145502. boolean need_full_buffer));
  145503. EXTERN(void) jinit_d_post_controller JPP((j_decompress_ptr cinfo,
  145504. boolean need_full_buffer));
  145505. EXTERN(void) jinit_input_controller JPP((j_decompress_ptr cinfo));
  145506. EXTERN(void) jinit_marker_reader JPP((j_decompress_ptr cinfo));
  145507. EXTERN(void) jinit_huff_decoder JPP((j_decompress_ptr cinfo));
  145508. EXTERN(void) jinit_phuff_decoder JPP((j_decompress_ptr cinfo));
  145509. EXTERN(void) jinit_inverse_dct JPP((j_decompress_ptr cinfo));
  145510. EXTERN(void) jinit_upsampler JPP((j_decompress_ptr cinfo));
  145511. EXTERN(void) jinit_color_deconverter JPP((j_decompress_ptr cinfo));
  145512. EXTERN(void) jinit_1pass_quantizer JPP((j_decompress_ptr cinfo));
  145513. EXTERN(void) jinit_2pass_quantizer JPP((j_decompress_ptr cinfo));
  145514. EXTERN(void) jinit_merged_upsampler JPP((j_decompress_ptr cinfo));
  145515. EXTERN(void) jinit_memory_mgr JPP((j_common_ptr cinfo));
  145516. EXTERN(long) jdiv_round_up JPP((long a, long b));
  145517. EXTERN(long) jround_up JPP((long a, long b));
  145518. EXTERN(void) jcopy_sample_rows JPP((JSAMPARRAY input_array, int source_row,
  145519. JSAMPARRAY output_array, int dest_row,
  145520. int num_rows, JDIMENSION num_cols));
  145521. EXTERN(void) jcopy_block_row JPP((JBLOCKROW input_row, JBLOCKROW output_row,
  145522. JDIMENSION num_blocks));
  145523. EXTERN(void) jzero_far JPP((void FAR * target, size_t bytestozero));
  145524. #if 0 /* This table is not actually needed in v6a */
  145525. extern const int jpeg_zigzag_order[]; /* natural coef order to zigzag order */
  145526. #endif
  145527. extern const int jpeg_natural_order[]; /* zigzag coef order to natural order */
  145528. #ifdef INCOMPLETE_TYPES_BROKEN
  145529. #ifndef AM_MEMORY_MANAGER /* only jmemmgr.c defines these */
  145530. struct jvirt_sarray_control { long dummy; };
  145531. struct jvirt_barray_control { long dummy; };
  145532. #endif
  145533. #endif /* INCOMPLETE_TYPES_BROKEN */
  145534. /*** End of inlined file: jpegint.h ***/
  145535. /* fetch private declarations */
  145536. /*** Start of inlined file: jerror.h ***/
  145537. #ifndef JMESSAGE
  145538. #ifndef JERROR_H
  145539. #define JMAKE_ENUM_LIST
  145540. #else
  145541. #define JMESSAGE(code,string)
  145542. #endif /* JERROR_H */
  145543. #endif /* JMESSAGE */
  145544. #ifdef JMAKE_ENUM_LIST
  145545. typedef enum {
  145546. #define JMESSAGE(code,string) code ,
  145547. #endif /* JMAKE_ENUM_LIST */
  145548. JMESSAGE(JMSG_NOMESSAGE, "Bogus message code %d") /* Must be first entry! */
  145549. JMESSAGE(JERR_ARITH_NOTIMPL,
  145550. "Sorry, there are legal restrictions on arithmetic coding")
  145551. JMESSAGE(JERR_BAD_ALIGN_TYPE, "ALIGN_TYPE is wrong, please fix")
  145552. JMESSAGE(JERR_BAD_ALLOC_CHUNK, "MAX_ALLOC_CHUNK is wrong, please fix")
  145553. JMESSAGE(JERR_BAD_BUFFER_MODE, "Bogus buffer control mode")
  145554. JMESSAGE(JERR_BAD_COMPONENT_ID, "Invalid component ID %d in SOS")
  145555. JMESSAGE(JERR_BAD_DCT_COEF, "DCT coefficient out of range")
  145556. JMESSAGE(JERR_BAD_DCTSIZE, "IDCT output block size %d not supported")
  145557. JMESSAGE(JERR_BAD_HUFF_TABLE, "Bogus Huffman table definition")
  145558. JMESSAGE(JERR_BAD_IN_COLORSPACE, "Bogus input colorspace")
  145559. JMESSAGE(JERR_BAD_J_COLORSPACE, "Bogus JPEG colorspace")
  145560. JMESSAGE(JERR_BAD_LENGTH, "Bogus marker length")
  145561. JMESSAGE(JERR_BAD_LIB_VERSION,
  145562. "Wrong JPEG library version: library is %d, caller expects %d")
  145563. JMESSAGE(JERR_BAD_MCU_SIZE, "Sampling factors too large for interleaved scan")
  145564. JMESSAGE(JERR_BAD_POOL_ID, "Invalid memory pool code %d")
  145565. JMESSAGE(JERR_BAD_PRECISION, "Unsupported JPEG data precision %d")
  145566. JMESSAGE(JERR_BAD_PROGRESSION,
  145567. "Invalid progressive parameters Ss=%d Se=%d Ah=%d Al=%d")
  145568. JMESSAGE(JERR_BAD_PROG_SCRIPT,
  145569. "Invalid progressive parameters at scan script entry %d")
  145570. JMESSAGE(JERR_BAD_SAMPLING, "Bogus sampling factors")
  145571. JMESSAGE(JERR_BAD_SCAN_SCRIPT, "Invalid scan script at entry %d")
  145572. JMESSAGE(JERR_BAD_STATE, "Improper call to JPEG library in state %d")
  145573. JMESSAGE(JERR_BAD_STRUCT_SIZE,
  145574. "JPEG parameter struct mismatch: library thinks size is %u, caller expects %u")
  145575. JMESSAGE(JERR_BAD_VIRTUAL_ACCESS, "Bogus virtual array access")
  145576. JMESSAGE(JERR_BUFFER_SIZE, "Buffer passed to JPEG library is too small")
  145577. JMESSAGE(JERR_CANT_SUSPEND, "Suspension not allowed here")
  145578. JMESSAGE(JERR_CCIR601_NOTIMPL, "CCIR601 sampling not implemented yet")
  145579. JMESSAGE(JERR_COMPONENT_COUNT, "Too many color components: %d, max %d")
  145580. JMESSAGE(JERR_CONVERSION_NOTIMPL, "Unsupported color conversion request")
  145581. JMESSAGE(JERR_DAC_INDEX, "Bogus DAC index %d")
  145582. JMESSAGE(JERR_DAC_VALUE, "Bogus DAC value 0x%x")
  145583. JMESSAGE(JERR_DHT_INDEX, "Bogus DHT index %d")
  145584. JMESSAGE(JERR_DQT_INDEX, "Bogus DQT index %d")
  145585. JMESSAGE(JERR_EMPTY_IMAGE, "Empty JPEG image (DNL not supported)")
  145586. JMESSAGE(JERR_EMS_READ, "Read from EMS failed")
  145587. JMESSAGE(JERR_EMS_WRITE, "Write to EMS failed")
  145588. JMESSAGE(JERR_EOI_EXPECTED, "Didn't expect more than one scan")
  145589. JMESSAGE(JERR_FILE_READ, "Input file read error")
  145590. JMESSAGE(JERR_FILE_WRITE, "Output file write error --- out of disk space?")
  145591. JMESSAGE(JERR_FRACT_SAMPLE_NOTIMPL, "Fractional sampling not implemented yet")
  145592. JMESSAGE(JERR_HUFF_CLEN_OVERFLOW, "Huffman code size table overflow")
  145593. JMESSAGE(JERR_HUFF_MISSING_CODE, "Missing Huffman code table entry")
  145594. JMESSAGE(JERR_IMAGE_TOO_BIG, "Maximum supported image dimension is %u pixels")
  145595. JMESSAGE(JERR_INPUT_EMPTY, "Empty input file")
  145596. JMESSAGE(JERR_INPUT_EOF, "Premature end of input file")
  145597. JMESSAGE(JERR_MISMATCHED_QUANT_TABLE,
  145598. "Cannot transcode due to multiple use of quantization table %d")
  145599. JMESSAGE(JERR_MISSING_DATA, "Scan script does not transmit all data")
  145600. JMESSAGE(JERR_MODE_CHANGE, "Invalid color quantization mode change")
  145601. JMESSAGE(JERR_NOTIMPL, "Not implemented yet")
  145602. JMESSAGE(JERR_NOT_COMPILED, "Requested feature was omitted at compile time")
  145603. JMESSAGE(JERR_NO_BACKING_STORE, "Backing store not supported")
  145604. JMESSAGE(JERR_NO_HUFF_TABLE, "Huffman table 0x%02x was not defined")
  145605. JMESSAGE(JERR_NO_IMAGE, "JPEG datastream contains no image")
  145606. JMESSAGE(JERR_NO_QUANT_TABLE, "Quantization table 0x%02x was not defined")
  145607. JMESSAGE(JERR_NO_SOI, "Not a JPEG file: starts with 0x%02x 0x%02x")
  145608. JMESSAGE(JERR_OUT_OF_MEMORY, "Insufficient memory (case %d)")
  145609. JMESSAGE(JERR_QUANT_COMPONENTS,
  145610. "Cannot quantize more than %d color components")
  145611. JMESSAGE(JERR_QUANT_FEW_COLORS, "Cannot quantize to fewer than %d colors")
  145612. JMESSAGE(JERR_QUANT_MANY_COLORS, "Cannot quantize to more than %d colors")
  145613. JMESSAGE(JERR_SOF_DUPLICATE, "Invalid JPEG file structure: two SOF markers")
  145614. JMESSAGE(JERR_SOF_NO_SOS, "Invalid JPEG file structure: missing SOS marker")
  145615. JMESSAGE(JERR_SOF_UNSUPPORTED, "Unsupported JPEG process: SOF type 0x%02x")
  145616. JMESSAGE(JERR_SOI_DUPLICATE, "Invalid JPEG file structure: two SOI markers")
  145617. JMESSAGE(JERR_SOS_NO_SOF, "Invalid JPEG file structure: SOS before SOF")
  145618. JMESSAGE(JERR_TFILE_CREATE, "Failed to create temporary file %s")
  145619. JMESSAGE(JERR_TFILE_READ, "Read failed on temporary file")
  145620. JMESSAGE(JERR_TFILE_SEEK, "Seek failed on temporary file")
  145621. JMESSAGE(JERR_TFILE_WRITE,
  145622. "Write failed on temporary file --- out of disk space?")
  145623. JMESSAGE(JERR_TOO_LITTLE_DATA, "Application transferred too few scanlines")
  145624. JMESSAGE(JERR_UNKNOWN_MARKER, "Unsupported marker type 0x%02x")
  145625. JMESSAGE(JERR_VIRTUAL_BUG, "Virtual array controller messed up")
  145626. JMESSAGE(JERR_WIDTH_OVERFLOW, "Image too wide for this implementation")
  145627. JMESSAGE(JERR_XMS_READ, "Read from XMS failed")
  145628. JMESSAGE(JERR_XMS_WRITE, "Write to XMS failed")
  145629. JMESSAGE(JMSG_COPYRIGHT, JCOPYRIGHT)
  145630. JMESSAGE(JMSG_VERSION, JVERSION)
  145631. JMESSAGE(JTRC_16BIT_TABLES,
  145632. "Caution: quantization tables are too coarse for baseline JPEG")
  145633. JMESSAGE(JTRC_ADOBE,
  145634. "Adobe APP14 marker: version %d, flags 0x%04x 0x%04x, transform %d")
  145635. JMESSAGE(JTRC_APP0, "Unknown APP0 marker (not JFIF), length %u")
  145636. JMESSAGE(JTRC_APP14, "Unknown APP14 marker (not Adobe), length %u")
  145637. JMESSAGE(JTRC_DAC, "Define Arithmetic Table 0x%02x: 0x%02x")
  145638. JMESSAGE(JTRC_DHT, "Define Huffman Table 0x%02x")
  145639. JMESSAGE(JTRC_DQT, "Define Quantization Table %d precision %d")
  145640. JMESSAGE(JTRC_DRI, "Define Restart Interval %u")
  145641. JMESSAGE(JTRC_EMS_CLOSE, "Freed EMS handle %u")
  145642. JMESSAGE(JTRC_EMS_OPEN, "Obtained EMS handle %u")
  145643. JMESSAGE(JTRC_EOI, "End Of Image")
  145644. JMESSAGE(JTRC_HUFFBITS, " %3d %3d %3d %3d %3d %3d %3d %3d")
  145645. JMESSAGE(JTRC_JFIF, "JFIF APP0 marker: version %d.%02d, density %dx%d %d")
  145646. JMESSAGE(JTRC_JFIF_BADTHUMBNAILSIZE,
  145647. "Warning: thumbnail image size does not match data length %u")
  145648. JMESSAGE(JTRC_JFIF_EXTENSION,
  145649. "JFIF extension marker: type 0x%02x, length %u")
  145650. JMESSAGE(JTRC_JFIF_THUMBNAIL, " with %d x %d thumbnail image")
  145651. JMESSAGE(JTRC_MISC_MARKER, "Miscellaneous marker 0x%02x, length %u")
  145652. JMESSAGE(JTRC_PARMLESS_MARKER, "Unexpected marker 0x%02x")
  145653. JMESSAGE(JTRC_QUANTVALS, " %4u %4u %4u %4u %4u %4u %4u %4u")
  145654. JMESSAGE(JTRC_QUANT_3_NCOLORS, "Quantizing to %d = %d*%d*%d colors")
  145655. JMESSAGE(JTRC_QUANT_NCOLORS, "Quantizing to %d colors")
  145656. JMESSAGE(JTRC_QUANT_SELECTED, "Selected %d colors for quantization")
  145657. JMESSAGE(JTRC_RECOVERY_ACTION, "At marker 0x%02x, recovery action %d")
  145658. JMESSAGE(JTRC_RST, "RST%d")
  145659. JMESSAGE(JTRC_SMOOTH_NOTIMPL,
  145660. "Smoothing not supported with nonstandard sampling ratios")
  145661. JMESSAGE(JTRC_SOF, "Start Of Frame 0x%02x: width=%u, height=%u, components=%d")
  145662. JMESSAGE(JTRC_SOF_COMPONENT, " Component %d: %dhx%dv q=%d")
  145663. JMESSAGE(JTRC_SOI, "Start of Image")
  145664. JMESSAGE(JTRC_SOS, "Start Of Scan: %d components")
  145665. JMESSAGE(JTRC_SOS_COMPONENT, " Component %d: dc=%d ac=%d")
  145666. JMESSAGE(JTRC_SOS_PARAMS, " Ss=%d, Se=%d, Ah=%d, Al=%d")
  145667. JMESSAGE(JTRC_TFILE_CLOSE, "Closed temporary file %s")
  145668. JMESSAGE(JTRC_TFILE_OPEN, "Opened temporary file %s")
  145669. JMESSAGE(JTRC_THUMB_JPEG,
  145670. "JFIF extension marker: JPEG-compressed thumbnail image, length %u")
  145671. JMESSAGE(JTRC_THUMB_PALETTE,
  145672. "JFIF extension marker: palette thumbnail image, length %u")
  145673. JMESSAGE(JTRC_THUMB_RGB,
  145674. "JFIF extension marker: RGB thumbnail image, length %u")
  145675. JMESSAGE(JTRC_UNKNOWN_IDS,
  145676. "Unrecognized component IDs %d %d %d, assuming YCbCr")
  145677. JMESSAGE(JTRC_XMS_CLOSE, "Freed XMS handle %u")
  145678. JMESSAGE(JTRC_XMS_OPEN, "Obtained XMS handle %u")
  145679. JMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d")
  145680. JMESSAGE(JWRN_BOGUS_PROGRESSION,
  145681. "Inconsistent progression sequence for component %d coefficient %d")
  145682. JMESSAGE(JWRN_EXTRANEOUS_DATA,
  145683. "Corrupt JPEG data: %u extraneous bytes before marker 0x%02x")
  145684. JMESSAGE(JWRN_HIT_MARKER, "Corrupt JPEG data: premature end of data segment")
  145685. JMESSAGE(JWRN_HUFF_BAD_CODE, "Corrupt JPEG data: bad Huffman code")
  145686. JMESSAGE(JWRN_JFIF_MAJOR, "Warning: unknown JFIF revision number %d.%02d")
  145687. JMESSAGE(JWRN_JPEG_EOF, "Premature end of JPEG file")
  145688. JMESSAGE(JWRN_MUST_RESYNC,
  145689. "Corrupt JPEG data: found marker 0x%02x instead of RST%d")
  145690. JMESSAGE(JWRN_NOT_SEQUENTIAL, "Invalid SOS parameters for sequential JPEG")
  145691. JMESSAGE(JWRN_TOO_MUCH_DATA, "Application transferred too many scanlines")
  145692. #ifdef JMAKE_ENUM_LIST
  145693. JMSG_LASTMSGCODE
  145694. } J_MESSAGE_CODE;
  145695. #undef JMAKE_ENUM_LIST
  145696. #endif /* JMAKE_ENUM_LIST */
  145697. #undef JMESSAGE
  145698. #ifndef JERROR_H
  145699. #define JERROR_H
  145700. #define ERREXIT(cinfo,code) \
  145701. ((cinfo)->err->msg_code = (code), \
  145702. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145703. #define ERREXIT1(cinfo,code,p1) \
  145704. ((cinfo)->err->msg_code = (code), \
  145705. (cinfo)->err->msg_parm.i[0] = (p1), \
  145706. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145707. #define ERREXIT2(cinfo,code,p1,p2) \
  145708. ((cinfo)->err->msg_code = (code), \
  145709. (cinfo)->err->msg_parm.i[0] = (p1), \
  145710. (cinfo)->err->msg_parm.i[1] = (p2), \
  145711. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145712. #define ERREXIT3(cinfo,code,p1,p2,p3) \
  145713. ((cinfo)->err->msg_code = (code), \
  145714. (cinfo)->err->msg_parm.i[0] = (p1), \
  145715. (cinfo)->err->msg_parm.i[1] = (p2), \
  145716. (cinfo)->err->msg_parm.i[2] = (p3), \
  145717. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145718. #define ERREXIT4(cinfo,code,p1,p2,p3,p4) \
  145719. ((cinfo)->err->msg_code = (code), \
  145720. (cinfo)->err->msg_parm.i[0] = (p1), \
  145721. (cinfo)->err->msg_parm.i[1] = (p2), \
  145722. (cinfo)->err->msg_parm.i[2] = (p3), \
  145723. (cinfo)->err->msg_parm.i[3] = (p4), \
  145724. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145725. #define ERREXITS(cinfo,code,str) \
  145726. ((cinfo)->err->msg_code = (code), \
  145727. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  145728. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145729. #define MAKESTMT(stuff) do { stuff } while (0)
  145730. #define WARNMS(cinfo,code) \
  145731. ((cinfo)->err->msg_code = (code), \
  145732. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  145733. #define WARNMS1(cinfo,code,p1) \
  145734. ((cinfo)->err->msg_code = (code), \
  145735. (cinfo)->err->msg_parm.i[0] = (p1), \
  145736. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  145737. #define WARNMS2(cinfo,code,p1,p2) \
  145738. ((cinfo)->err->msg_code = (code), \
  145739. (cinfo)->err->msg_parm.i[0] = (p1), \
  145740. (cinfo)->err->msg_parm.i[1] = (p2), \
  145741. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  145742. #define TRACEMS(cinfo,lvl,code) \
  145743. ((cinfo)->err->msg_code = (code), \
  145744. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  145745. #define TRACEMS1(cinfo,lvl,code,p1) \
  145746. ((cinfo)->err->msg_code = (code), \
  145747. (cinfo)->err->msg_parm.i[0] = (p1), \
  145748. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  145749. #define TRACEMS2(cinfo,lvl,code,p1,p2) \
  145750. ((cinfo)->err->msg_code = (code), \
  145751. (cinfo)->err->msg_parm.i[0] = (p1), \
  145752. (cinfo)->err->msg_parm.i[1] = (p2), \
  145753. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  145754. #define TRACEMS3(cinfo,lvl,code,p1,p2,p3) \
  145755. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  145756. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); \
  145757. (cinfo)->err->msg_code = (code); \
  145758. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  145759. #define TRACEMS4(cinfo,lvl,code,p1,p2,p3,p4) \
  145760. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  145761. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  145762. (cinfo)->err->msg_code = (code); \
  145763. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  145764. #define TRACEMS5(cinfo,lvl,code,p1,p2,p3,p4,p5) \
  145765. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  145766. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  145767. _mp[4] = (p5); \
  145768. (cinfo)->err->msg_code = (code); \
  145769. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  145770. #define TRACEMS8(cinfo,lvl,code,p1,p2,p3,p4,p5,p6,p7,p8) \
  145771. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  145772. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  145773. _mp[4] = (p5); _mp[5] = (p6); _mp[6] = (p7); _mp[7] = (p8); \
  145774. (cinfo)->err->msg_code = (code); \
  145775. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  145776. #define TRACEMSS(cinfo,lvl,code,str) \
  145777. ((cinfo)->err->msg_code = (code), \
  145778. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  145779. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  145780. #endif /* JERROR_H */
  145781. /*** End of inlined file: jerror.h ***/
  145782. /* fetch error codes too */
  145783. #endif
  145784. #endif /* JPEGLIB_H */
  145785. /*** End of inlined file: jpeglib.h ***/
  145786. /*** Start of inlined file: jcapimin.c ***/
  145787. #define JPEG_INTERNALS
  145788. /*** Start of inlined file: jinclude.h ***/
  145789. #ifndef __jinclude_h__
  145790. #define __jinclude_h__
  145791. /*** Start of inlined file: jconfig.h ***/
  145792. // disable all the warnings under MSVC
  145793. #ifdef _MSC_VER
  145794. #pragma warning (disable: 4996 4267 4100 4127 4702 4244)
  145795. #endif
  145796. #ifdef __BORLANDC__
  145797. #pragma warn -8057
  145798. #pragma warn -8019
  145799. #pragma warn -8004
  145800. #pragma warn -8008
  145801. #endif
  145802. #define HAVE_PROTOTYPES
  145803. #define HAVE_UNSIGNED_CHAR
  145804. #define HAVE_UNSIGNED_SHORT
  145805. #undef CHAR_IS_UNSIGNED
  145806. #define HAVE_STDDEF_H
  145807. #define HAVE_STDLIB_H
  145808. #undef NEED_BSD_STRINGS
  145809. #undef NEED_SYS_TYPES_H
  145810. #undef NEED_FAR_POINTERS /* we presume a 32-bit flat memory model */
  145811. #undef NEED_SHORT_EXTERNAL_NAMES
  145812. #undef INCOMPLETE_TYPES_BROKEN
  145813. #ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
  145814. typedef unsigned char boolean;
  145815. #endif
  145816. #define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
  145817. #ifdef JPEG_INTERNALS
  145818. #undef RIGHT_SHIFT_IS_UNSIGNED
  145819. #endif /* JPEG_INTERNALS */
  145820. #ifdef JPEG_CJPEG_DJPEG
  145821. #define BMP_SUPPORTED /* BMP image file format */
  145822. #define GIF_SUPPORTED /* GIF image file format */
  145823. #define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
  145824. #undef RLE_SUPPORTED /* Utah RLE image file format */
  145825. #define TARGA_SUPPORTED /* Targa image file format */
  145826. #define TWO_FILE_COMMANDLINE /* optional */
  145827. #define USE_SETMODE /* Microsoft has setmode() */
  145828. #undef NEED_SIGNAL_CATCHER
  145829. #undef DONT_USE_B_MODE
  145830. #undef PROGRESS_REPORT /* optional */
  145831. #endif /* JPEG_CJPEG_DJPEG */
  145832. /*** End of inlined file: jconfig.h ***/
  145833. /* auto configuration options */
  145834. #define JCONFIG_INCLUDED /* so that jpeglib.h doesn't do it again */
  145835. #ifdef HAVE_STDDEF_H
  145836. #include <stddef.h>
  145837. #endif
  145838. #ifdef HAVE_STDLIB_H
  145839. #include <stdlib.h>
  145840. #endif
  145841. #ifdef NEED_SYS_TYPES_H
  145842. #include <sys/types.h>
  145843. #endif
  145844. #include <stdio.h>
  145845. #ifdef NEED_BSD_STRINGS
  145846. #include <strings.h>
  145847. #define MEMZERO(target,size) bzero((void *)(target), (size_t)(size))
  145848. #define MEMCOPY(dest,src,size) bcopy((const void *)(src), (void *)(dest), (size_t)(size))
  145849. #else /* not BSD, assume ANSI/SysV string lib */
  145850. #include <string.h>
  145851. #define MEMZERO(target,size) memset((void *)(target), 0, (size_t)(size))
  145852. #define MEMCOPY(dest,src,size) memcpy((void *)(dest), (const void *)(src), (size_t)(size))
  145853. #endif
  145854. #define SIZEOF(object) ((size_t) sizeof(object))
  145855. #define JFREAD(file,buf,sizeofbuf) \
  145856. ((size_t) fread((void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
  145857. #define JFWRITE(file,buf,sizeofbuf) \
  145858. ((size_t) fwrite((const void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
  145859. typedef enum { /* JPEG marker codes */
  145860. M_SOF0 = 0xc0,
  145861. M_SOF1 = 0xc1,
  145862. M_SOF2 = 0xc2,
  145863. M_SOF3 = 0xc3,
  145864. M_SOF5 = 0xc5,
  145865. M_SOF6 = 0xc6,
  145866. M_SOF7 = 0xc7,
  145867. M_JPG = 0xc8,
  145868. M_SOF9 = 0xc9,
  145869. M_SOF10 = 0xca,
  145870. M_SOF11 = 0xcb,
  145871. M_SOF13 = 0xcd,
  145872. M_SOF14 = 0xce,
  145873. M_SOF15 = 0xcf,
  145874. M_DHT = 0xc4,
  145875. M_DAC = 0xcc,
  145876. M_RST0 = 0xd0,
  145877. M_RST1 = 0xd1,
  145878. M_RST2 = 0xd2,
  145879. M_RST3 = 0xd3,
  145880. M_RST4 = 0xd4,
  145881. M_RST5 = 0xd5,
  145882. M_RST6 = 0xd6,
  145883. M_RST7 = 0xd7,
  145884. M_SOI = 0xd8,
  145885. M_EOI = 0xd9,
  145886. M_SOS = 0xda,
  145887. M_DQT = 0xdb,
  145888. M_DNL = 0xdc,
  145889. M_DRI = 0xdd,
  145890. M_DHP = 0xde,
  145891. M_EXP = 0xdf,
  145892. M_APP0 = 0xe0,
  145893. M_APP1 = 0xe1,
  145894. M_APP2 = 0xe2,
  145895. M_APP3 = 0xe3,
  145896. M_APP4 = 0xe4,
  145897. M_APP5 = 0xe5,
  145898. M_APP6 = 0xe6,
  145899. M_APP7 = 0xe7,
  145900. M_APP8 = 0xe8,
  145901. M_APP9 = 0xe9,
  145902. M_APP10 = 0xea,
  145903. M_APP11 = 0xeb,
  145904. M_APP12 = 0xec,
  145905. M_APP13 = 0xed,
  145906. M_APP14 = 0xee,
  145907. M_APP15 = 0xef,
  145908. M_JPG0 = 0xf0,
  145909. M_JPG13 = 0xfd,
  145910. M_COM = 0xfe,
  145911. M_TEM = 0x01,
  145912. M_ERROR = 0x100
  145913. } JPEG_MARKER;
  145914. #ifdef AVOID_TABLES
  145915. #define HUFF_EXTEND(x,s) ((x) < (1<<((s)-1)) ? (x) + (((-1)<<(s)) + 1) : (x))
  145916. #else
  145917. #define HUFF_EXTEND(x,s) ((x) < extend_test[s] ? (x) + extend_offset[s] : (x))
  145918. static const int extend_test[16] = /* entry n is 2**(n-1) */
  145919. { 0, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
  145920. 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000 };
  145921. static const int extend_offset[16] = /* entry n is (-1 << n) + 1 */
  145922. { 0, ((-1)<<1) + 1, ((-1)<<2) + 1, ((-1)<<3) + 1, ((-1)<<4) + 1,
  145923. ((-1)<<5) + 1, ((-1)<<6) + 1, ((-1)<<7) + 1, ((-1)<<8) + 1,
  145924. ((-1)<<9) + 1, ((-1)<<10) + 1, ((-1)<<11) + 1, ((-1)<<12) + 1,
  145925. ((-1)<<13) + 1, ((-1)<<14) + 1, ((-1)<<15) + 1 };
  145926. #endif /* AVOID_TABLES */
  145927. #endif
  145928. /*** End of inlined file: jinclude.h ***/
  145929. GLOBAL(void)
  145930. jpeg_CreateCompress (j_compress_ptr cinfo, int version, size_t structsize)
  145931. {
  145932. int i;
  145933. cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */
  145934. if (version != JPEG_LIB_VERSION)
  145935. ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
  145936. if (structsize != SIZEOF(struct jpeg_compress_struct))
  145937. ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
  145938. (int) SIZEOF(struct jpeg_compress_struct), (int) structsize);
  145939. {
  145940. struct jpeg_error_mgr * err = cinfo->err;
  145941. void * client_data = cinfo->client_data; /* ignore Purify complaint here */
  145942. MEMZERO(cinfo, SIZEOF(struct jpeg_compress_struct));
  145943. cinfo->err = err;
  145944. cinfo->client_data = client_data;
  145945. }
  145946. cinfo->is_decompressor = FALSE;
  145947. jinit_memory_mgr((j_common_ptr) cinfo);
  145948. cinfo->progress = NULL;
  145949. cinfo->dest = NULL;
  145950. cinfo->comp_info = NULL;
  145951. for (i = 0; i < NUM_QUANT_TBLS; i++)
  145952. cinfo->quant_tbl_ptrs[i] = NULL;
  145953. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  145954. cinfo->dc_huff_tbl_ptrs[i] = NULL;
  145955. cinfo->ac_huff_tbl_ptrs[i] = NULL;
  145956. }
  145957. cinfo->script_space = NULL;
  145958. cinfo->input_gamma = 1.0; /* in case application forgets */
  145959. cinfo->global_state = CSTATE_START;
  145960. }
  145961. GLOBAL(void)
  145962. jpeg_destroy_compress (j_compress_ptr cinfo)
  145963. {
  145964. jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
  145965. }
  145966. GLOBAL(void)
  145967. jpeg_abort_compress (j_compress_ptr cinfo)
  145968. {
  145969. jpeg_abort((j_common_ptr) cinfo); /* use common routine */
  145970. }
  145971. GLOBAL(void)
  145972. jpeg_suppress_tables (j_compress_ptr cinfo, boolean suppress)
  145973. {
  145974. int i;
  145975. JQUANT_TBL * qtbl;
  145976. JHUFF_TBL * htbl;
  145977. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  145978. if ((qtbl = cinfo->quant_tbl_ptrs[i]) != NULL)
  145979. qtbl->sent_table = suppress;
  145980. }
  145981. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  145982. if ((htbl = cinfo->dc_huff_tbl_ptrs[i]) != NULL)
  145983. htbl->sent_table = suppress;
  145984. if ((htbl = cinfo->ac_huff_tbl_ptrs[i]) != NULL)
  145985. htbl->sent_table = suppress;
  145986. }
  145987. }
  145988. GLOBAL(void)
  145989. jpeg_finish_compress (j_compress_ptr cinfo)
  145990. {
  145991. JDIMENSION iMCU_row;
  145992. if (cinfo->global_state == CSTATE_SCANNING ||
  145993. cinfo->global_state == CSTATE_RAW_OK) {
  145994. if (cinfo->next_scanline < cinfo->image_height)
  145995. ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
  145996. (*cinfo->master->finish_pass) (cinfo);
  145997. } else if (cinfo->global_state != CSTATE_WRCOEFS)
  145998. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  145999. while (! cinfo->master->is_last_pass) {
  146000. (*cinfo->master->prepare_for_pass) (cinfo);
  146001. for (iMCU_row = 0; iMCU_row < cinfo->total_iMCU_rows; iMCU_row++) {
  146002. if (cinfo->progress != NULL) {
  146003. cinfo->progress->pass_counter = (long) iMCU_row;
  146004. cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows;
  146005. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  146006. }
  146007. if (! (*cinfo->coef->compress_data) (cinfo, (JSAMPIMAGE) NULL))
  146008. ERREXIT(cinfo, JERR_CANT_SUSPEND);
  146009. }
  146010. (*cinfo->master->finish_pass) (cinfo);
  146011. }
  146012. (*cinfo->marker->write_file_trailer) (cinfo);
  146013. (*cinfo->dest->term_destination) (cinfo);
  146014. jpeg_abort((j_common_ptr) cinfo);
  146015. }
  146016. GLOBAL(void)
  146017. jpeg_write_marker (j_compress_ptr cinfo, int marker,
  146018. const JOCTET *dataptr, unsigned int datalen)
  146019. {
  146020. JMETHOD(void, write_marker_byte, (j_compress_ptr info, int val));
  146021. if (cinfo->next_scanline != 0 ||
  146022. (cinfo->global_state != CSTATE_SCANNING &&
  146023. cinfo->global_state != CSTATE_RAW_OK &&
  146024. cinfo->global_state != CSTATE_WRCOEFS))
  146025. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146026. (*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
  146027. write_marker_byte = cinfo->marker->write_marker_byte; /* copy for speed */
  146028. while (datalen--) {
  146029. (*write_marker_byte) (cinfo, *dataptr);
  146030. dataptr++;
  146031. }
  146032. }
  146033. GLOBAL(void)
  146034. jpeg_write_m_header (j_compress_ptr cinfo, int marker, unsigned int datalen)
  146035. {
  146036. if (cinfo->next_scanline != 0 ||
  146037. (cinfo->global_state != CSTATE_SCANNING &&
  146038. cinfo->global_state != CSTATE_RAW_OK &&
  146039. cinfo->global_state != CSTATE_WRCOEFS))
  146040. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146041. (*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
  146042. }
  146043. GLOBAL(void)
  146044. jpeg_write_m_byte (j_compress_ptr cinfo, int val)
  146045. {
  146046. (*cinfo->marker->write_marker_byte) (cinfo, val);
  146047. }
  146048. GLOBAL(void)
  146049. jpeg_write_tables (j_compress_ptr cinfo)
  146050. {
  146051. if (cinfo->global_state != CSTATE_START)
  146052. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146053. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  146054. (*cinfo->dest->init_destination) (cinfo);
  146055. jinit_marker_writer(cinfo);
  146056. (*cinfo->marker->write_tables_only) (cinfo);
  146057. (*cinfo->dest->term_destination) (cinfo);
  146058. }
  146059. /*** End of inlined file: jcapimin.c ***/
  146060. /*** Start of inlined file: jcapistd.c ***/
  146061. #define JPEG_INTERNALS
  146062. GLOBAL(void)
  146063. jpeg_start_compress (j_compress_ptr cinfo, boolean write_all_tables)
  146064. {
  146065. if (cinfo->global_state != CSTATE_START)
  146066. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146067. if (write_all_tables)
  146068. jpeg_suppress_tables(cinfo, FALSE); /* mark all tables to be written */
  146069. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  146070. (*cinfo->dest->init_destination) (cinfo);
  146071. jinit_compress_master(cinfo);
  146072. (*cinfo->master->prepare_for_pass) (cinfo);
  146073. cinfo->next_scanline = 0;
  146074. cinfo->global_state = (cinfo->raw_data_in ? CSTATE_RAW_OK : CSTATE_SCANNING);
  146075. }
  146076. GLOBAL(JDIMENSION)
  146077. jpeg_write_scanlines (j_compress_ptr cinfo, JSAMPARRAY scanlines,
  146078. JDIMENSION num_lines)
  146079. {
  146080. JDIMENSION row_ctr, rows_left;
  146081. if (cinfo->global_state != CSTATE_SCANNING)
  146082. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146083. if (cinfo->next_scanline >= cinfo->image_height)
  146084. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  146085. if (cinfo->progress != NULL) {
  146086. cinfo->progress->pass_counter = (long) cinfo->next_scanline;
  146087. cinfo->progress->pass_limit = (long) cinfo->image_height;
  146088. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  146089. }
  146090. if (cinfo->master->call_pass_startup)
  146091. (*cinfo->master->pass_startup) (cinfo);
  146092. rows_left = cinfo->image_height - cinfo->next_scanline;
  146093. if (num_lines > rows_left)
  146094. num_lines = rows_left;
  146095. row_ctr = 0;
  146096. (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, num_lines);
  146097. cinfo->next_scanline += row_ctr;
  146098. return row_ctr;
  146099. }
  146100. GLOBAL(JDIMENSION)
  146101. jpeg_write_raw_data (j_compress_ptr cinfo, JSAMPIMAGE data,
  146102. JDIMENSION num_lines)
  146103. {
  146104. JDIMENSION lines_per_iMCU_row;
  146105. if (cinfo->global_state != CSTATE_RAW_OK)
  146106. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146107. if (cinfo->next_scanline >= cinfo->image_height) {
  146108. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  146109. return 0;
  146110. }
  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. lines_per_iMCU_row = cinfo->max_v_samp_factor * DCTSIZE;
  146119. if (num_lines < lines_per_iMCU_row)
  146120. ERREXIT(cinfo, JERR_BUFFER_SIZE);
  146121. if (! (*cinfo->coef->compress_data) (cinfo, data)) {
  146122. return 0;
  146123. }
  146124. cinfo->next_scanline += lines_per_iMCU_row;
  146125. return lines_per_iMCU_row;
  146126. }
  146127. /*** End of inlined file: jcapistd.c ***/
  146128. /*** Start of inlined file: jccoefct.c ***/
  146129. #define JPEG_INTERNALS
  146130. #ifdef ENTROPY_OPT_SUPPORTED
  146131. #define FULL_COEF_BUFFER_SUPPORTED
  146132. #else
  146133. #ifdef C_MULTISCAN_FILES_SUPPORTED
  146134. #define FULL_COEF_BUFFER_SUPPORTED
  146135. #endif
  146136. #endif
  146137. typedef struct {
  146138. struct jpeg_c_coef_controller pub; /* public fields */
  146139. JDIMENSION iMCU_row_num; /* iMCU row # within image */
  146140. JDIMENSION mcu_ctr; /* counts MCUs processed in current row */
  146141. int MCU_vert_offset; /* counts MCU rows within iMCU row */
  146142. int MCU_rows_per_iMCU_row; /* number of such rows needed */
  146143. JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU];
  146144. jvirt_barray_ptr whole_image[MAX_COMPONENTS];
  146145. } my_coef_controller;
  146146. typedef my_coef_controller * my_coef_ptr;
  146147. METHODDEF(boolean) compress_data
  146148. JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
  146149. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146150. METHODDEF(boolean) compress_first_pass
  146151. JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
  146152. METHODDEF(boolean) compress_output
  146153. JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
  146154. #endif
  146155. LOCAL(void)
  146156. start_iMCU_row (j_compress_ptr cinfo)
  146157. {
  146158. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146159. if (cinfo->comps_in_scan > 1) {
  146160. coef->MCU_rows_per_iMCU_row = 1;
  146161. } else {
  146162. if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1))
  146163. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
  146164. else
  146165. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  146166. }
  146167. coef->mcu_ctr = 0;
  146168. coef->MCU_vert_offset = 0;
  146169. }
  146170. METHODDEF(void)
  146171. start_pass_coef (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  146172. {
  146173. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146174. coef->iMCU_row_num = 0;
  146175. start_iMCU_row(cinfo);
  146176. switch (pass_mode) {
  146177. case JBUF_PASS_THRU:
  146178. if (coef->whole_image[0] != NULL)
  146179. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146180. coef->pub.compress_data = compress_data;
  146181. break;
  146182. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146183. case JBUF_SAVE_AND_PASS:
  146184. if (coef->whole_image[0] == NULL)
  146185. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146186. coef->pub.compress_data = compress_first_pass;
  146187. break;
  146188. case JBUF_CRANK_DEST:
  146189. if (coef->whole_image[0] == NULL)
  146190. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146191. coef->pub.compress_data = compress_output;
  146192. break;
  146193. #endif
  146194. default:
  146195. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146196. break;
  146197. }
  146198. }
  146199. METHODDEF(boolean)
  146200. compress_data (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  146201. {
  146202. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146203. JDIMENSION MCU_col_num; /* index of current MCU within row */
  146204. JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  146205. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  146206. int blkn, bi, ci, yindex, yoffset, blockcnt;
  146207. JDIMENSION ypos, xpos;
  146208. jpeg_component_info *compptr;
  146209. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  146210. yoffset++) {
  146211. for (MCU_col_num = coef->mcu_ctr; MCU_col_num <= last_MCU_col;
  146212. MCU_col_num++) {
  146213. blkn = 0;
  146214. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  146215. compptr = cinfo->cur_comp_info[ci];
  146216. blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
  146217. : compptr->last_col_width;
  146218. xpos = MCU_col_num * compptr->MCU_sample_width;
  146219. ypos = yoffset * DCTSIZE; /* ypos == (yoffset+yindex) * DCTSIZE */
  146220. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  146221. if (coef->iMCU_row_num < last_iMCU_row ||
  146222. yoffset+yindex < compptr->last_row_height) {
  146223. (*cinfo->fdct->forward_DCT) (cinfo, compptr,
  146224. input_buf[compptr->component_index],
  146225. coef->MCU_buffer[blkn],
  146226. ypos, xpos, (JDIMENSION) blockcnt);
  146227. if (blockcnt < compptr->MCU_width) {
  146228. jzero_far((void FAR *) coef->MCU_buffer[blkn + blockcnt],
  146229. (compptr->MCU_width - blockcnt) * SIZEOF(JBLOCK));
  146230. for (bi = blockcnt; bi < compptr->MCU_width; bi++) {
  146231. coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn+bi-1][0][0];
  146232. }
  146233. }
  146234. } else {
  146235. jzero_far((void FAR *) coef->MCU_buffer[blkn],
  146236. compptr->MCU_width * SIZEOF(JBLOCK));
  146237. for (bi = 0; bi < compptr->MCU_width; bi++) {
  146238. coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn-1][0][0];
  146239. }
  146240. }
  146241. blkn += compptr->MCU_width;
  146242. ypos += DCTSIZE;
  146243. }
  146244. }
  146245. if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
  146246. coef->MCU_vert_offset = yoffset;
  146247. coef->mcu_ctr = MCU_col_num;
  146248. return FALSE;
  146249. }
  146250. }
  146251. coef->mcu_ctr = 0;
  146252. }
  146253. coef->iMCU_row_num++;
  146254. start_iMCU_row(cinfo);
  146255. return TRUE;
  146256. }
  146257. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146258. METHODDEF(boolean)
  146259. compress_first_pass (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  146260. {
  146261. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146262. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  146263. JDIMENSION blocks_across, MCUs_across, MCUindex;
  146264. int bi, ci, h_samp_factor, block_row, block_rows, ndummy;
  146265. JCOEF lastDC;
  146266. jpeg_component_info *compptr;
  146267. JBLOCKARRAY buffer;
  146268. JBLOCKROW thisblockrow, lastblockrow;
  146269. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  146270. ci++, compptr++) {
  146271. buffer = (*cinfo->mem->access_virt_barray)
  146272. ((j_common_ptr) cinfo, coef->whole_image[ci],
  146273. coef->iMCU_row_num * compptr->v_samp_factor,
  146274. (JDIMENSION) compptr->v_samp_factor, TRUE);
  146275. if (coef->iMCU_row_num < last_iMCU_row)
  146276. block_rows = compptr->v_samp_factor;
  146277. else {
  146278. block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  146279. if (block_rows == 0) block_rows = compptr->v_samp_factor;
  146280. }
  146281. blocks_across = compptr->width_in_blocks;
  146282. h_samp_factor = compptr->h_samp_factor;
  146283. ndummy = (int) (blocks_across % h_samp_factor);
  146284. if (ndummy > 0)
  146285. ndummy = h_samp_factor - ndummy;
  146286. for (block_row = 0; block_row < block_rows; block_row++) {
  146287. thisblockrow = buffer[block_row];
  146288. (*cinfo->fdct->forward_DCT) (cinfo, compptr,
  146289. input_buf[ci], thisblockrow,
  146290. (JDIMENSION) (block_row * DCTSIZE),
  146291. (JDIMENSION) 0, blocks_across);
  146292. if (ndummy > 0) {
  146293. thisblockrow += blocks_across; /* => first dummy block */
  146294. jzero_far((void FAR *) thisblockrow, ndummy * SIZEOF(JBLOCK));
  146295. lastDC = thisblockrow[-1][0];
  146296. for (bi = 0; bi < ndummy; bi++) {
  146297. thisblockrow[bi][0] = lastDC;
  146298. }
  146299. }
  146300. }
  146301. if (coef->iMCU_row_num == last_iMCU_row) {
  146302. blocks_across += ndummy; /* include lower right corner */
  146303. MCUs_across = blocks_across / h_samp_factor;
  146304. for (block_row = block_rows; block_row < compptr->v_samp_factor;
  146305. block_row++) {
  146306. thisblockrow = buffer[block_row];
  146307. lastblockrow = buffer[block_row-1];
  146308. jzero_far((void FAR *) thisblockrow,
  146309. (size_t) (blocks_across * SIZEOF(JBLOCK)));
  146310. for (MCUindex = 0; MCUindex < MCUs_across; MCUindex++) {
  146311. lastDC = lastblockrow[h_samp_factor-1][0];
  146312. for (bi = 0; bi < h_samp_factor; bi++) {
  146313. thisblockrow[bi][0] = lastDC;
  146314. }
  146315. thisblockrow += h_samp_factor; /* advance to next MCU in row */
  146316. lastblockrow += h_samp_factor;
  146317. }
  146318. }
  146319. }
  146320. }
  146321. return compress_output(cinfo, input_buf);
  146322. }
  146323. METHODDEF(boolean)
  146324. compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  146325. {
  146326. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146327. JDIMENSION MCU_col_num; /* index of current MCU within row */
  146328. int blkn, ci, xindex, yindex, yoffset;
  146329. JDIMENSION start_col;
  146330. JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  146331. JBLOCKROW buffer_ptr;
  146332. jpeg_component_info *compptr;
  146333. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  146334. compptr = cinfo->cur_comp_info[ci];
  146335. buffer[ci] = (*cinfo->mem->access_virt_barray)
  146336. ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
  146337. coef->iMCU_row_num * compptr->v_samp_factor,
  146338. (JDIMENSION) compptr->v_samp_factor, FALSE);
  146339. }
  146340. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  146341. yoffset++) {
  146342. for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row;
  146343. MCU_col_num++) {
  146344. blkn = 0; /* index of current DCT block within MCU */
  146345. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  146346. compptr = cinfo->cur_comp_info[ci];
  146347. start_col = MCU_col_num * compptr->MCU_width;
  146348. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  146349. buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
  146350. for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
  146351. coef->MCU_buffer[blkn++] = buffer_ptr++;
  146352. }
  146353. }
  146354. }
  146355. if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
  146356. coef->MCU_vert_offset = yoffset;
  146357. coef->mcu_ctr = MCU_col_num;
  146358. return FALSE;
  146359. }
  146360. }
  146361. coef->mcu_ctr = 0;
  146362. }
  146363. coef->iMCU_row_num++;
  146364. start_iMCU_row(cinfo);
  146365. return TRUE;
  146366. }
  146367. #endif /* FULL_COEF_BUFFER_SUPPORTED */
  146368. GLOBAL(void)
  146369. jinit_c_coef_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  146370. {
  146371. my_coef_ptr coef;
  146372. coef = (my_coef_ptr)
  146373. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146374. SIZEOF(my_coef_controller));
  146375. cinfo->coef = (struct jpeg_c_coef_controller *) coef;
  146376. coef->pub.start_pass = start_pass_coef;
  146377. if (need_full_buffer) {
  146378. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146379. int ci;
  146380. jpeg_component_info *compptr;
  146381. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  146382. ci++, compptr++) {
  146383. coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
  146384. ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  146385. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  146386. (long) compptr->h_samp_factor),
  146387. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  146388. (long) compptr->v_samp_factor),
  146389. (JDIMENSION) compptr->v_samp_factor);
  146390. }
  146391. #else
  146392. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146393. #endif
  146394. } else {
  146395. JBLOCKROW buffer;
  146396. int i;
  146397. buffer = (JBLOCKROW)
  146398. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146399. C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  146400. for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) {
  146401. coef->MCU_buffer[i] = buffer + i;
  146402. }
  146403. coef->whole_image[0] = NULL; /* flag for no virtual arrays */
  146404. }
  146405. }
  146406. /*** End of inlined file: jccoefct.c ***/
  146407. /*** Start of inlined file: jccolor.c ***/
  146408. #define JPEG_INTERNALS
  146409. typedef struct {
  146410. struct jpeg_color_converter pub; /* public fields */
  146411. INT32 * rgb_ycc_tab; /* => table for RGB to YCbCr conversion */
  146412. } my_color_converter;
  146413. typedef my_color_converter * my_cconvert_ptr;
  146414. #define SCALEBITS 16 /* speediest right-shift on some machines */
  146415. #define CBCR_OFFSET ((INT32) CENTERJSAMPLE << SCALEBITS)
  146416. #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
  146417. #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
  146418. #define R_Y_OFF 0 /* offset to R => Y section */
  146419. #define G_Y_OFF (1*(MAXJSAMPLE+1)) /* offset to G => Y section */
  146420. #define B_Y_OFF (2*(MAXJSAMPLE+1)) /* etc. */
  146421. #define R_CB_OFF (3*(MAXJSAMPLE+1))
  146422. #define G_CB_OFF (4*(MAXJSAMPLE+1))
  146423. #define B_CB_OFF (5*(MAXJSAMPLE+1))
  146424. #define R_CR_OFF B_CB_OFF /* B=>Cb, R=>Cr are the same */
  146425. #define G_CR_OFF (6*(MAXJSAMPLE+1))
  146426. #define B_CR_OFF (7*(MAXJSAMPLE+1))
  146427. #define TABLE_SIZE (8*(MAXJSAMPLE+1))
  146428. METHODDEF(void)
  146429. rgb_ycc_start (j_compress_ptr cinfo)
  146430. {
  146431. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146432. INT32 * rgb_ycc_tab;
  146433. INT32 i;
  146434. cconvert->rgb_ycc_tab = rgb_ycc_tab = (INT32 *)
  146435. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146436. (TABLE_SIZE * SIZEOF(INT32)));
  146437. for (i = 0; i <= MAXJSAMPLE; i++) {
  146438. rgb_ycc_tab[i+R_Y_OFF] = FIX(0.29900) * i;
  146439. rgb_ycc_tab[i+G_Y_OFF] = FIX(0.58700) * i;
  146440. rgb_ycc_tab[i+B_Y_OFF] = FIX(0.11400) * i + ONE_HALF;
  146441. rgb_ycc_tab[i+R_CB_OFF] = (-FIX(0.16874)) * i;
  146442. rgb_ycc_tab[i+G_CB_OFF] = (-FIX(0.33126)) * i;
  146443. rgb_ycc_tab[i+B_CB_OFF] = FIX(0.50000) * i + CBCR_OFFSET + ONE_HALF-1;
  146444. rgb_ycc_tab[i+G_CR_OFF] = (-FIX(0.41869)) * i;
  146445. rgb_ycc_tab[i+B_CR_OFF] = (-FIX(0.08131)) * i;
  146446. }
  146447. }
  146448. METHODDEF(void)
  146449. rgb_ycc_convert (j_compress_ptr cinfo,
  146450. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146451. JDIMENSION output_row, int num_rows)
  146452. {
  146453. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146454. register int r, g, b;
  146455. register INT32 * ctab = cconvert->rgb_ycc_tab;
  146456. register JSAMPROW inptr;
  146457. register JSAMPROW outptr0, outptr1, outptr2;
  146458. register JDIMENSION col;
  146459. JDIMENSION num_cols = cinfo->image_width;
  146460. while (--num_rows >= 0) {
  146461. inptr = *input_buf++;
  146462. outptr0 = output_buf[0][output_row];
  146463. outptr1 = output_buf[1][output_row];
  146464. outptr2 = output_buf[2][output_row];
  146465. output_row++;
  146466. for (col = 0; col < num_cols; col++) {
  146467. r = GETJSAMPLE(inptr[RGB_RED]);
  146468. g = GETJSAMPLE(inptr[RGB_GREEN]);
  146469. b = GETJSAMPLE(inptr[RGB_BLUE]);
  146470. inptr += RGB_PIXELSIZE;
  146471. outptr0[col] = (JSAMPLE)
  146472. ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  146473. >> SCALEBITS);
  146474. outptr1[col] = (JSAMPLE)
  146475. ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
  146476. >> SCALEBITS);
  146477. outptr2[col] = (JSAMPLE)
  146478. ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
  146479. >> SCALEBITS);
  146480. }
  146481. }
  146482. }
  146483. METHODDEF(void)
  146484. rgb_gray_convert (j_compress_ptr cinfo,
  146485. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146486. JDIMENSION output_row, int num_rows)
  146487. {
  146488. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146489. register int r, g, b;
  146490. register INT32 * ctab = cconvert->rgb_ycc_tab;
  146491. register JSAMPROW inptr;
  146492. register JSAMPROW outptr;
  146493. register JDIMENSION col;
  146494. JDIMENSION num_cols = cinfo->image_width;
  146495. while (--num_rows >= 0) {
  146496. inptr = *input_buf++;
  146497. outptr = output_buf[0][output_row];
  146498. output_row++;
  146499. for (col = 0; col < num_cols; col++) {
  146500. r = GETJSAMPLE(inptr[RGB_RED]);
  146501. g = GETJSAMPLE(inptr[RGB_GREEN]);
  146502. b = GETJSAMPLE(inptr[RGB_BLUE]);
  146503. inptr += RGB_PIXELSIZE;
  146504. outptr[col] = (JSAMPLE)
  146505. ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  146506. >> SCALEBITS);
  146507. }
  146508. }
  146509. }
  146510. METHODDEF(void)
  146511. cmyk_ycck_convert (j_compress_ptr cinfo,
  146512. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146513. JDIMENSION output_row, int num_rows)
  146514. {
  146515. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146516. register int r, g, b;
  146517. register INT32 * ctab = cconvert->rgb_ycc_tab;
  146518. register JSAMPROW inptr;
  146519. register JSAMPROW outptr0, outptr1, outptr2, outptr3;
  146520. register JDIMENSION col;
  146521. JDIMENSION num_cols = cinfo->image_width;
  146522. while (--num_rows >= 0) {
  146523. inptr = *input_buf++;
  146524. outptr0 = output_buf[0][output_row];
  146525. outptr1 = output_buf[1][output_row];
  146526. outptr2 = output_buf[2][output_row];
  146527. outptr3 = output_buf[3][output_row];
  146528. output_row++;
  146529. for (col = 0; col < num_cols; col++) {
  146530. r = MAXJSAMPLE - GETJSAMPLE(inptr[0]);
  146531. g = MAXJSAMPLE - GETJSAMPLE(inptr[1]);
  146532. b = MAXJSAMPLE - GETJSAMPLE(inptr[2]);
  146533. outptr3[col] = inptr[3]; /* don't need GETJSAMPLE here */
  146534. inptr += 4;
  146535. outptr0[col] = (JSAMPLE)
  146536. ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  146537. >> SCALEBITS);
  146538. outptr1[col] = (JSAMPLE)
  146539. ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
  146540. >> SCALEBITS);
  146541. outptr2[col] = (JSAMPLE)
  146542. ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
  146543. >> SCALEBITS);
  146544. }
  146545. }
  146546. }
  146547. METHODDEF(void)
  146548. grayscale_convert (j_compress_ptr cinfo,
  146549. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146550. JDIMENSION output_row, int num_rows)
  146551. {
  146552. register JSAMPROW inptr;
  146553. register JSAMPROW outptr;
  146554. register JDIMENSION col;
  146555. JDIMENSION num_cols = cinfo->image_width;
  146556. int instride = cinfo->input_components;
  146557. while (--num_rows >= 0) {
  146558. inptr = *input_buf++;
  146559. outptr = output_buf[0][output_row];
  146560. output_row++;
  146561. for (col = 0; col < num_cols; col++) {
  146562. outptr[col] = inptr[0]; /* don't need GETJSAMPLE() here */
  146563. inptr += instride;
  146564. }
  146565. }
  146566. }
  146567. METHODDEF(void)
  146568. null_convert (j_compress_ptr cinfo,
  146569. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146570. JDIMENSION output_row, int num_rows)
  146571. {
  146572. register JSAMPROW inptr;
  146573. register JSAMPROW outptr;
  146574. register JDIMENSION col;
  146575. register int ci;
  146576. int nc = cinfo->num_components;
  146577. JDIMENSION num_cols = cinfo->image_width;
  146578. while (--num_rows >= 0) {
  146579. for (ci = 0; ci < nc; ci++) {
  146580. inptr = *input_buf;
  146581. outptr = output_buf[ci][output_row];
  146582. for (col = 0; col < num_cols; col++) {
  146583. outptr[col] = inptr[ci]; /* don't need GETJSAMPLE() here */
  146584. inptr += nc;
  146585. }
  146586. }
  146587. input_buf++;
  146588. output_row++;
  146589. }
  146590. }
  146591. METHODDEF(void)
  146592. null_method (j_compress_ptr cinfo)
  146593. {
  146594. }
  146595. GLOBAL(void)
  146596. jinit_color_converter (j_compress_ptr cinfo)
  146597. {
  146598. my_cconvert_ptr cconvert;
  146599. cconvert = (my_cconvert_ptr)
  146600. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146601. SIZEOF(my_color_converter));
  146602. cinfo->cconvert = (struct jpeg_color_converter *) cconvert;
  146603. cconvert->pub.start_pass = null_method;
  146604. switch (cinfo->in_color_space) {
  146605. case JCS_GRAYSCALE:
  146606. if (cinfo->input_components != 1)
  146607. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146608. break;
  146609. case JCS_RGB:
  146610. #if RGB_PIXELSIZE != 3
  146611. if (cinfo->input_components != RGB_PIXELSIZE)
  146612. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146613. break;
  146614. #endif /* else share code with YCbCr */
  146615. case JCS_YCbCr:
  146616. if (cinfo->input_components != 3)
  146617. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146618. break;
  146619. case JCS_CMYK:
  146620. case JCS_YCCK:
  146621. if (cinfo->input_components != 4)
  146622. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146623. break;
  146624. default: /* JCS_UNKNOWN can be anything */
  146625. if (cinfo->input_components < 1)
  146626. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146627. break;
  146628. }
  146629. switch (cinfo->jpeg_color_space) {
  146630. case JCS_GRAYSCALE:
  146631. if (cinfo->num_components != 1)
  146632. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146633. if (cinfo->in_color_space == JCS_GRAYSCALE)
  146634. cconvert->pub.color_convert = grayscale_convert;
  146635. else if (cinfo->in_color_space == JCS_RGB) {
  146636. cconvert->pub.start_pass = rgb_ycc_start;
  146637. cconvert->pub.color_convert = rgb_gray_convert;
  146638. } else if (cinfo->in_color_space == JCS_YCbCr)
  146639. cconvert->pub.color_convert = grayscale_convert;
  146640. else
  146641. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146642. break;
  146643. case JCS_RGB:
  146644. if (cinfo->num_components != 3)
  146645. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146646. if (cinfo->in_color_space == JCS_RGB && RGB_PIXELSIZE == 3)
  146647. cconvert->pub.color_convert = null_convert;
  146648. else
  146649. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146650. break;
  146651. case JCS_YCbCr:
  146652. if (cinfo->num_components != 3)
  146653. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146654. if (cinfo->in_color_space == JCS_RGB) {
  146655. cconvert->pub.start_pass = rgb_ycc_start;
  146656. cconvert->pub.color_convert = rgb_ycc_convert;
  146657. } else if (cinfo->in_color_space == JCS_YCbCr)
  146658. cconvert->pub.color_convert = null_convert;
  146659. else
  146660. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146661. break;
  146662. case JCS_CMYK:
  146663. if (cinfo->num_components != 4)
  146664. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146665. if (cinfo->in_color_space == JCS_CMYK)
  146666. cconvert->pub.color_convert = null_convert;
  146667. else
  146668. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146669. break;
  146670. case JCS_YCCK:
  146671. if (cinfo->num_components != 4)
  146672. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146673. if (cinfo->in_color_space == JCS_CMYK) {
  146674. cconvert->pub.start_pass = rgb_ycc_start;
  146675. cconvert->pub.color_convert = cmyk_ycck_convert;
  146676. } else if (cinfo->in_color_space == JCS_YCCK)
  146677. cconvert->pub.color_convert = null_convert;
  146678. else
  146679. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146680. break;
  146681. default: /* allow null conversion of JCS_UNKNOWN */
  146682. if (cinfo->jpeg_color_space != cinfo->in_color_space ||
  146683. cinfo->num_components != cinfo->input_components)
  146684. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146685. cconvert->pub.color_convert = null_convert;
  146686. break;
  146687. }
  146688. }
  146689. /*** End of inlined file: jccolor.c ***/
  146690. #undef FIX
  146691. /*** Start of inlined file: jcdctmgr.c ***/
  146692. #define JPEG_INTERNALS
  146693. /*** Start of inlined file: jdct.h ***/
  146694. #ifndef __jdct_h__
  146695. #define __jdct_h__
  146696. #if BITS_IN_JSAMPLE == 8
  146697. typedef int DCTELEM; /* 16 or 32 bits is fine */
  146698. #else
  146699. typedef INT32 DCTELEM; /* must have 32 bits */
  146700. #endif
  146701. typedef JMETHOD(void, forward_DCT_method_ptr, (DCTELEM * data));
  146702. typedef JMETHOD(void, float_DCT_method_ptr, (FAST_FLOAT * data));
  146703. typedef MULTIPLIER ISLOW_MULT_TYPE; /* short or int, whichever is faster */
  146704. #if BITS_IN_JSAMPLE == 8
  146705. typedef MULTIPLIER IFAST_MULT_TYPE; /* 16 bits is OK, use short if faster */
  146706. #define IFAST_SCALE_BITS 2 /* fractional bits in scale factors */
  146707. #else
  146708. typedef INT32 IFAST_MULT_TYPE; /* need 32 bits for scaled quantizers */
  146709. #define IFAST_SCALE_BITS 13 /* fractional bits in scale factors */
  146710. #endif
  146711. typedef FAST_FLOAT FLOAT_MULT_TYPE; /* preferred floating type */
  146712. #define IDCT_range_limit(cinfo) ((cinfo)->sample_range_limit + CENTERJSAMPLE)
  146713. #define RANGE_MASK (MAXJSAMPLE * 4 + 3) /* 2 bits wider than legal samples */
  146714. #ifdef NEED_SHORT_EXTERNAL_NAMES
  146715. #define jpeg_fdct_islow jFDislow
  146716. #define jpeg_fdct_ifast jFDifast
  146717. #define jpeg_fdct_float jFDfloat
  146718. #define jpeg_idct_islow jRDislow
  146719. #define jpeg_idct_ifast jRDifast
  146720. #define jpeg_idct_float jRDfloat
  146721. #define jpeg_idct_4x4 jRD4x4
  146722. #define jpeg_idct_2x2 jRD2x2
  146723. #define jpeg_idct_1x1 jRD1x1
  146724. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  146725. EXTERN(void) jpeg_fdct_islow JPP((DCTELEM * data));
  146726. EXTERN(void) jpeg_fdct_ifast JPP((DCTELEM * data));
  146727. EXTERN(void) jpeg_fdct_float JPP((FAST_FLOAT * data));
  146728. EXTERN(void) jpeg_idct_islow
  146729. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146730. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146731. EXTERN(void) jpeg_idct_ifast
  146732. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146733. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146734. EXTERN(void) jpeg_idct_float
  146735. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146736. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146737. EXTERN(void) jpeg_idct_4x4
  146738. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146739. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146740. EXTERN(void) jpeg_idct_2x2
  146741. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146742. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146743. EXTERN(void) jpeg_idct_1x1
  146744. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146745. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146746. #define ONE ((INT32) 1)
  146747. #define CONST_SCALE (ONE << CONST_BITS)
  146748. #define FIX(x) ((INT32) ((x) * CONST_SCALE + 0.5))
  146749. #define DESCALE(x,n) RIGHT_SHIFT((x) + (ONE << ((n)-1)), n)
  146750. #ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */
  146751. #define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT16) (const)))
  146752. #endif
  146753. #ifdef SHORTxLCONST_32 /* known to work with Microsoft C 6.0 */
  146754. #define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT32) (const)))
  146755. #endif
  146756. #ifndef MULTIPLY16C16 /* default definition */
  146757. #define MULTIPLY16C16(var,const) ((var) * (const))
  146758. #endif
  146759. #ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */
  146760. #define MULTIPLY16V16(var1,var2) (((INT16) (var1)) * ((INT16) (var2)))
  146761. #endif
  146762. #ifndef MULTIPLY16V16 /* default definition */
  146763. #define MULTIPLY16V16(var1,var2) ((var1) * (var2))
  146764. #endif
  146765. #endif
  146766. /*** End of inlined file: jdct.h ***/
  146767. /* Private declarations for DCT subsystem */
  146768. typedef struct {
  146769. struct jpeg_forward_dct pub; /* public fields */
  146770. forward_DCT_method_ptr do_dct;
  146771. DCTELEM * divisors[NUM_QUANT_TBLS];
  146772. #ifdef DCT_FLOAT_SUPPORTED
  146773. float_DCT_method_ptr do_float_dct;
  146774. FAST_FLOAT * float_divisors[NUM_QUANT_TBLS];
  146775. #endif
  146776. } my_fdct_controller;
  146777. typedef my_fdct_controller * my_fdct_ptr;
  146778. METHODDEF(void)
  146779. start_pass_fdctmgr (j_compress_ptr cinfo)
  146780. {
  146781. my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  146782. int ci, qtblno, i;
  146783. jpeg_component_info *compptr;
  146784. JQUANT_TBL * qtbl;
  146785. DCTELEM * dtbl;
  146786. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  146787. ci++, compptr++) {
  146788. qtblno = compptr->quant_tbl_no;
  146789. if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
  146790. cinfo->quant_tbl_ptrs[qtblno] == NULL)
  146791. ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
  146792. qtbl = cinfo->quant_tbl_ptrs[qtblno];
  146793. switch (cinfo->dct_method) {
  146794. #ifdef DCT_ISLOW_SUPPORTED
  146795. case JDCT_ISLOW:
  146796. if (fdct->divisors[qtblno] == NULL) {
  146797. fdct->divisors[qtblno] = (DCTELEM *)
  146798. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146799. DCTSIZE2 * SIZEOF(DCTELEM));
  146800. }
  146801. dtbl = fdct->divisors[qtblno];
  146802. for (i = 0; i < DCTSIZE2; i++) {
  146803. dtbl[i] = ((DCTELEM) qtbl->quantval[i]) << 3;
  146804. }
  146805. break;
  146806. #endif
  146807. #ifdef DCT_IFAST_SUPPORTED
  146808. case JDCT_IFAST:
  146809. {
  146810. #define CONST_BITS 14
  146811. static const INT16 aanscales[DCTSIZE2] = {
  146812. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  146813. 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
  146814. 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
  146815. 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
  146816. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  146817. 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
  146818. 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
  146819. 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
  146820. };
  146821. SHIFT_TEMPS
  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)
  146830. DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
  146831. (INT32) aanscales[i]),
  146832. CONST_BITS-3);
  146833. }
  146834. }
  146835. break;
  146836. #endif
  146837. #ifdef DCT_FLOAT_SUPPORTED
  146838. case JDCT_FLOAT:
  146839. {
  146840. FAST_FLOAT * fdtbl;
  146841. int row, col;
  146842. static const double aanscalefactor[DCTSIZE] = {
  146843. 1.0, 1.387039845, 1.306562965, 1.175875602,
  146844. 1.0, 0.785694958, 0.541196100, 0.275899379
  146845. };
  146846. if (fdct->float_divisors[qtblno] == NULL) {
  146847. fdct->float_divisors[qtblno] = (FAST_FLOAT *)
  146848. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146849. DCTSIZE2 * SIZEOF(FAST_FLOAT));
  146850. }
  146851. fdtbl = fdct->float_divisors[qtblno];
  146852. i = 0;
  146853. for (row = 0; row < DCTSIZE; row++) {
  146854. for (col = 0; col < DCTSIZE; col++) {
  146855. fdtbl[i] = (FAST_FLOAT)
  146856. (1.0 / (((double) qtbl->quantval[i] *
  146857. aanscalefactor[row] * aanscalefactor[col] * 8.0)));
  146858. i++;
  146859. }
  146860. }
  146861. }
  146862. break;
  146863. #endif
  146864. default:
  146865. ERREXIT(cinfo, JERR_NOT_COMPILED);
  146866. break;
  146867. }
  146868. }
  146869. }
  146870. METHODDEF(void)
  146871. forward_DCT (j_compress_ptr cinfo, jpeg_component_info * compptr,
  146872. JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  146873. JDIMENSION start_row, JDIMENSION start_col,
  146874. JDIMENSION num_blocks)
  146875. {
  146876. my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  146877. forward_DCT_method_ptr do_dct = fdct->do_dct;
  146878. DCTELEM * divisors = fdct->divisors[compptr->quant_tbl_no];
  146879. DCTELEM workspace[DCTSIZE2]; /* work area for FDCT subroutine */
  146880. JDIMENSION bi;
  146881. sample_data += start_row; /* fold in the vertical offset once */
  146882. for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
  146883. { register DCTELEM *workspaceptr;
  146884. register JSAMPROW elemptr;
  146885. register int elemr;
  146886. workspaceptr = workspace;
  146887. for (elemr = 0; elemr < DCTSIZE; elemr++) {
  146888. elemptr = sample_data[elemr] + start_col;
  146889. #if DCTSIZE == 8 /* unroll the inner loop */
  146890. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146891. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146892. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146893. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146894. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146895. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146896. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146897. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146898. #else
  146899. { register int elemc;
  146900. for (elemc = DCTSIZE; elemc > 0; elemc--) {
  146901. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146902. }
  146903. }
  146904. #endif
  146905. }
  146906. }
  146907. (*do_dct) (workspace);
  146908. { register DCTELEM temp, qval;
  146909. register int i;
  146910. register JCOEFPTR output_ptr = coef_blocks[bi];
  146911. for (i = 0; i < DCTSIZE2; i++) {
  146912. qval = divisors[i];
  146913. temp = workspace[i];
  146914. #ifdef FAST_DIVIDE
  146915. #define DIVIDE_BY(a,b) a /= b
  146916. #else
  146917. #define DIVIDE_BY(a,b) if (a >= b) a /= b; else a = 0
  146918. #endif
  146919. if (temp < 0) {
  146920. temp = -temp;
  146921. temp += qval>>1; /* for rounding */
  146922. DIVIDE_BY(temp, qval);
  146923. temp = -temp;
  146924. } else {
  146925. temp += qval>>1; /* for rounding */
  146926. DIVIDE_BY(temp, qval);
  146927. }
  146928. output_ptr[i] = (JCOEF) temp;
  146929. }
  146930. }
  146931. }
  146932. }
  146933. #ifdef DCT_FLOAT_SUPPORTED
  146934. METHODDEF(void)
  146935. forward_DCT_float (j_compress_ptr cinfo, jpeg_component_info * compptr,
  146936. JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  146937. JDIMENSION start_row, JDIMENSION start_col,
  146938. JDIMENSION num_blocks)
  146939. {
  146940. my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  146941. float_DCT_method_ptr do_dct = fdct->do_float_dct;
  146942. FAST_FLOAT * divisors = fdct->float_divisors[compptr->quant_tbl_no];
  146943. FAST_FLOAT workspace[DCTSIZE2]; /* work area for FDCT subroutine */
  146944. JDIMENSION bi;
  146945. sample_data += start_row; /* fold in the vertical offset once */
  146946. for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
  146947. { register FAST_FLOAT *workspaceptr;
  146948. register JSAMPROW elemptr;
  146949. register int elemr;
  146950. workspaceptr = workspace;
  146951. for (elemr = 0; elemr < DCTSIZE; elemr++) {
  146952. elemptr = sample_data[elemr] + start_col;
  146953. #if DCTSIZE == 8 /* unroll the inner loop */
  146954. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146955. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146956. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146957. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146958. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146959. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146960. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146961. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146962. #else
  146963. { register int elemc;
  146964. for (elemc = DCTSIZE; elemc > 0; elemc--) {
  146965. *workspaceptr++ = (FAST_FLOAT)
  146966. (GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146967. }
  146968. }
  146969. #endif
  146970. }
  146971. }
  146972. (*do_dct) (workspace);
  146973. { register FAST_FLOAT temp;
  146974. register int i;
  146975. register JCOEFPTR output_ptr = coef_blocks[bi];
  146976. for (i = 0; i < DCTSIZE2; i++) {
  146977. temp = workspace[i] * divisors[i];
  146978. output_ptr[i] = (JCOEF) ((int) (temp + (FAST_FLOAT) 16384.5) - 16384);
  146979. }
  146980. }
  146981. }
  146982. }
  146983. #endif /* DCT_FLOAT_SUPPORTED */
  146984. GLOBAL(void)
  146985. jinit_forward_dct (j_compress_ptr cinfo)
  146986. {
  146987. my_fdct_ptr fdct;
  146988. int i;
  146989. fdct = (my_fdct_ptr)
  146990. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146991. SIZEOF(my_fdct_controller));
  146992. cinfo->fdct = (struct jpeg_forward_dct *) fdct;
  146993. fdct->pub.start_pass = start_pass_fdctmgr;
  146994. switch (cinfo->dct_method) {
  146995. #ifdef DCT_ISLOW_SUPPORTED
  146996. case JDCT_ISLOW:
  146997. fdct->pub.forward_DCT = forward_DCT;
  146998. fdct->do_dct = jpeg_fdct_islow;
  146999. break;
  147000. #endif
  147001. #ifdef DCT_IFAST_SUPPORTED
  147002. case JDCT_IFAST:
  147003. fdct->pub.forward_DCT = forward_DCT;
  147004. fdct->do_dct = jpeg_fdct_ifast;
  147005. break;
  147006. #endif
  147007. #ifdef DCT_FLOAT_SUPPORTED
  147008. case JDCT_FLOAT:
  147009. fdct->pub.forward_DCT = forward_DCT_float;
  147010. fdct->do_float_dct = jpeg_fdct_float;
  147011. break;
  147012. #endif
  147013. default:
  147014. ERREXIT(cinfo, JERR_NOT_COMPILED);
  147015. break;
  147016. }
  147017. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  147018. fdct->divisors[i] = NULL;
  147019. #ifdef DCT_FLOAT_SUPPORTED
  147020. fdct->float_divisors[i] = NULL;
  147021. #endif
  147022. }
  147023. }
  147024. /*** End of inlined file: jcdctmgr.c ***/
  147025. #undef CONST_BITS
  147026. /*** Start of inlined file: jchuff.c ***/
  147027. #define JPEG_INTERNALS
  147028. /*** Start of inlined file: jchuff.h ***/
  147029. #ifndef _jchuff_h_
  147030. #define _jchuff_h_
  147031. #if BITS_IN_JSAMPLE == 8
  147032. #define MAX_COEF_BITS 10
  147033. #else
  147034. #define MAX_COEF_BITS 14
  147035. #endif
  147036. typedef struct {
  147037. unsigned int ehufco[256]; /* code for each symbol */
  147038. char ehufsi[256]; /* length of code for each symbol */
  147039. } c_derived_tbl;
  147040. #ifdef NEED_SHORT_EXTERNAL_NAMES
  147041. #define jpeg_make_c_derived_tbl jMkCDerived
  147042. #define jpeg_gen_optimal_table jGenOptTbl
  147043. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  147044. EXTERN(void) jpeg_make_c_derived_tbl
  147045. JPP((j_compress_ptr cinfo, boolean isDC, int tblno,
  147046. c_derived_tbl ** pdtbl));
  147047. EXTERN(void) jpeg_gen_optimal_table
  147048. JPP((j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[]));
  147049. #endif
  147050. /*** End of inlined file: jchuff.h ***/
  147051. /* Declarations shared with jcphuff.c */
  147052. typedef struct {
  147053. INT32 put_buffer; /* current bit-accumulation buffer */
  147054. int put_bits; /* # of bits now in it */
  147055. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  147056. } savable_state;
  147057. #ifndef NO_STRUCT_ASSIGN
  147058. #define ASSIGN_STATE(dest,src) ((dest) = (src))
  147059. #else
  147060. #if MAX_COMPS_IN_SCAN == 4
  147061. #define ASSIGN_STATE(dest,src) \
  147062. ((dest).put_buffer = (src).put_buffer, \
  147063. (dest).put_bits = (src).put_bits, \
  147064. (dest).last_dc_val[0] = (src).last_dc_val[0], \
  147065. (dest).last_dc_val[1] = (src).last_dc_val[1], \
  147066. (dest).last_dc_val[2] = (src).last_dc_val[2], \
  147067. (dest).last_dc_val[3] = (src).last_dc_val[3])
  147068. #endif
  147069. #endif
  147070. typedef struct {
  147071. struct jpeg_entropy_encoder pub; /* public fields */
  147072. savable_state saved; /* Bit buffer & DC state at start of MCU */
  147073. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  147074. int next_restart_num; /* next restart number to write (0-7) */
  147075. c_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS];
  147076. c_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS];
  147077. #ifdef ENTROPY_OPT_SUPPORTED /* Statistics tables for optimization */
  147078. long * dc_count_ptrs[NUM_HUFF_TBLS];
  147079. long * ac_count_ptrs[NUM_HUFF_TBLS];
  147080. #endif
  147081. } huff_entropy_encoder;
  147082. typedef huff_entropy_encoder * huff_entropy_ptr;
  147083. typedef struct {
  147084. JOCTET * next_output_byte; /* => next byte to write in buffer */
  147085. size_t free_in_buffer; /* # of byte spaces remaining in buffer */
  147086. savable_state cur; /* Current bit buffer & DC state */
  147087. j_compress_ptr cinfo; /* dump_buffer needs access to this */
  147088. } working_state;
  147089. METHODDEF(boolean) encode_mcu_huff JPP((j_compress_ptr cinfo,
  147090. JBLOCKROW *MCU_data));
  147091. METHODDEF(void) finish_pass_huff JPP((j_compress_ptr cinfo));
  147092. #ifdef ENTROPY_OPT_SUPPORTED
  147093. METHODDEF(boolean) encode_mcu_gather JPP((j_compress_ptr cinfo,
  147094. JBLOCKROW *MCU_data));
  147095. METHODDEF(void) finish_pass_gather JPP((j_compress_ptr cinfo));
  147096. #endif
  147097. METHODDEF(void)
  147098. start_pass_huff (j_compress_ptr cinfo, boolean gather_statistics)
  147099. {
  147100. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147101. int ci, dctbl, actbl;
  147102. jpeg_component_info * compptr;
  147103. if (gather_statistics) {
  147104. #ifdef ENTROPY_OPT_SUPPORTED
  147105. entropy->pub.encode_mcu = encode_mcu_gather;
  147106. entropy->pub.finish_pass = finish_pass_gather;
  147107. #else
  147108. ERREXIT(cinfo, JERR_NOT_COMPILED);
  147109. #endif
  147110. } else {
  147111. entropy->pub.encode_mcu = encode_mcu_huff;
  147112. entropy->pub.finish_pass = finish_pass_huff;
  147113. }
  147114. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  147115. compptr = cinfo->cur_comp_info[ci];
  147116. dctbl = compptr->dc_tbl_no;
  147117. actbl = compptr->ac_tbl_no;
  147118. if (gather_statistics) {
  147119. #ifdef ENTROPY_OPT_SUPPORTED
  147120. if (dctbl < 0 || dctbl >= NUM_HUFF_TBLS)
  147121. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, dctbl);
  147122. if (actbl < 0 || actbl >= NUM_HUFF_TBLS)
  147123. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, actbl);
  147124. if (entropy->dc_count_ptrs[dctbl] == NULL)
  147125. entropy->dc_count_ptrs[dctbl] = (long *)
  147126. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147127. 257 * SIZEOF(long));
  147128. MEMZERO(entropy->dc_count_ptrs[dctbl], 257 * SIZEOF(long));
  147129. if (entropy->ac_count_ptrs[actbl] == NULL)
  147130. entropy->ac_count_ptrs[actbl] = (long *)
  147131. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147132. 257 * SIZEOF(long));
  147133. MEMZERO(entropy->ac_count_ptrs[actbl], 257 * SIZEOF(long));
  147134. #endif
  147135. } else {
  147136. jpeg_make_c_derived_tbl(cinfo, TRUE, dctbl,
  147137. & entropy->dc_derived_tbls[dctbl]);
  147138. jpeg_make_c_derived_tbl(cinfo, FALSE, actbl,
  147139. & entropy->ac_derived_tbls[actbl]);
  147140. }
  147141. entropy->saved.last_dc_val[ci] = 0;
  147142. }
  147143. entropy->saved.put_buffer = 0;
  147144. entropy->saved.put_bits = 0;
  147145. entropy->restarts_to_go = cinfo->restart_interval;
  147146. entropy->next_restart_num = 0;
  147147. }
  147148. GLOBAL(void)
  147149. jpeg_make_c_derived_tbl (j_compress_ptr cinfo, boolean isDC, int tblno,
  147150. c_derived_tbl ** pdtbl)
  147151. {
  147152. JHUFF_TBL *htbl;
  147153. c_derived_tbl *dtbl;
  147154. int p, i, l, lastp, si, maxsymbol;
  147155. char huffsize[257];
  147156. unsigned int huffcode[257];
  147157. unsigned int code;
  147158. if (tblno < 0 || tblno >= NUM_HUFF_TBLS)
  147159. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  147160. htbl =
  147161. isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];
  147162. if (htbl == NULL)
  147163. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  147164. if (*pdtbl == NULL)
  147165. *pdtbl = (c_derived_tbl *)
  147166. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147167. SIZEOF(c_derived_tbl));
  147168. dtbl = *pdtbl;
  147169. p = 0;
  147170. for (l = 1; l <= 16; l++) {
  147171. i = (int) htbl->bits[l];
  147172. if (i < 0 || p + i > 256) /* protect against table overrun */
  147173. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  147174. while (i--)
  147175. huffsize[p++] = (char) l;
  147176. }
  147177. huffsize[p] = 0;
  147178. lastp = p;
  147179. code = 0;
  147180. si = huffsize[0];
  147181. p = 0;
  147182. while (huffsize[p]) {
  147183. while (((int) huffsize[p]) == si) {
  147184. huffcode[p++] = code;
  147185. code++;
  147186. }
  147187. if (((INT32) code) >= (((INT32) 1) << si))
  147188. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  147189. code <<= 1;
  147190. si++;
  147191. }
  147192. MEMZERO(dtbl->ehufsi, SIZEOF(dtbl->ehufsi));
  147193. maxsymbol = isDC ? 15 : 255;
  147194. for (p = 0; p < lastp; p++) {
  147195. i = htbl->huffval[p];
  147196. if (i < 0 || i > maxsymbol || dtbl->ehufsi[i])
  147197. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  147198. dtbl->ehufco[i] = huffcode[p];
  147199. dtbl->ehufsi[i] = huffsize[p];
  147200. }
  147201. }
  147202. #define emit_byte(state,val,action) \
  147203. { *(state)->next_output_byte++ = (JOCTET) (val); \
  147204. if (--(state)->free_in_buffer == 0) \
  147205. if (! dump_buffer(state)) \
  147206. { action; } }
  147207. LOCAL(boolean)
  147208. dump_buffer (working_state * state)
  147209. {
  147210. struct jpeg_destination_mgr * dest = state->cinfo->dest;
  147211. if (! (*dest->empty_output_buffer) (state->cinfo))
  147212. return FALSE;
  147213. state->next_output_byte = dest->next_output_byte;
  147214. state->free_in_buffer = dest->free_in_buffer;
  147215. return TRUE;
  147216. }
  147217. INLINE
  147218. LOCAL(boolean)
  147219. emit_bits (working_state * state, unsigned int code, int size)
  147220. {
  147221. register INT32 put_buffer = (INT32) code;
  147222. register int put_bits = state->cur.put_bits;
  147223. if (size == 0)
  147224. ERREXIT(state->cinfo, JERR_HUFF_MISSING_CODE);
  147225. put_buffer &= (((INT32) 1)<<size) - 1; /* mask off any extra bits in code */
  147226. put_bits += size; /* new number of bits in buffer */
  147227. put_buffer <<= 24 - put_bits; /* align incoming bits */
  147228. put_buffer |= state->cur.put_buffer; /* and merge with old buffer contents */
  147229. while (put_bits >= 8) {
  147230. int c = (int) ((put_buffer >> 16) & 0xFF);
  147231. emit_byte(state, c, return FALSE);
  147232. if (c == 0xFF) { /* need to stuff a zero byte? */
  147233. emit_byte(state, 0, return FALSE);
  147234. }
  147235. put_buffer <<= 8;
  147236. put_bits -= 8;
  147237. }
  147238. state->cur.put_buffer = put_buffer; /* update state variables */
  147239. state->cur.put_bits = put_bits;
  147240. return TRUE;
  147241. }
  147242. LOCAL(boolean)
  147243. flush_bits (working_state * state)
  147244. {
  147245. if (! emit_bits(state, 0x7F, 7)) /* fill any partial byte with ones */
  147246. return FALSE;
  147247. state->cur.put_buffer = 0; /* and reset bit-buffer to empty */
  147248. state->cur.put_bits = 0;
  147249. return TRUE;
  147250. }
  147251. LOCAL(boolean)
  147252. encode_one_block (working_state * state, JCOEFPTR block, int last_dc_val,
  147253. c_derived_tbl *dctbl, c_derived_tbl *actbl)
  147254. {
  147255. register int temp, temp2;
  147256. register int nbits;
  147257. register int k, r, i;
  147258. temp = temp2 = block[0] - last_dc_val;
  147259. if (temp < 0) {
  147260. temp = -temp; /* temp is abs value of input */
  147261. temp2--;
  147262. }
  147263. nbits = 0;
  147264. while (temp) {
  147265. nbits++;
  147266. temp >>= 1;
  147267. }
  147268. if (nbits > MAX_COEF_BITS+1)
  147269. ERREXIT(state->cinfo, JERR_BAD_DCT_COEF);
  147270. if (! emit_bits(state, dctbl->ehufco[nbits], dctbl->ehufsi[nbits]))
  147271. return FALSE;
  147272. if (nbits) /* emit_bits rejects calls with size 0 */
  147273. if (! emit_bits(state, (unsigned int) temp2, nbits))
  147274. return FALSE;
  147275. r = 0; /* r = run length of zeros */
  147276. for (k = 1; k < DCTSIZE2; k++) {
  147277. if ((temp = block[jpeg_natural_order[k]]) == 0) {
  147278. r++;
  147279. } else {
  147280. while (r > 15) {
  147281. if (! emit_bits(state, actbl->ehufco[0xF0], actbl->ehufsi[0xF0]))
  147282. return FALSE;
  147283. r -= 16;
  147284. }
  147285. temp2 = temp;
  147286. if (temp < 0) {
  147287. temp = -temp; /* temp is abs value of input */
  147288. temp2--;
  147289. }
  147290. nbits = 1; /* there must be at least one 1 bit */
  147291. while ((temp >>= 1))
  147292. nbits++;
  147293. if (nbits > MAX_COEF_BITS)
  147294. ERREXIT(state->cinfo, JERR_BAD_DCT_COEF);
  147295. i = (r << 4) + nbits;
  147296. if (! emit_bits(state, actbl->ehufco[i], actbl->ehufsi[i]))
  147297. return FALSE;
  147298. if (! emit_bits(state, (unsigned int) temp2, nbits))
  147299. return FALSE;
  147300. r = 0;
  147301. }
  147302. }
  147303. if (r > 0)
  147304. if (! emit_bits(state, actbl->ehufco[0], actbl->ehufsi[0]))
  147305. return FALSE;
  147306. return TRUE;
  147307. }
  147308. LOCAL(boolean)
  147309. emit_restart (working_state * state, int restart_num)
  147310. {
  147311. int ci;
  147312. if (! flush_bits(state))
  147313. return FALSE;
  147314. emit_byte(state, 0xFF, return FALSE);
  147315. emit_byte(state, JPEG_RST0 + restart_num, return FALSE);
  147316. for (ci = 0; ci < state->cinfo->comps_in_scan; ci++)
  147317. state->cur.last_dc_val[ci] = 0;
  147318. return TRUE;
  147319. }
  147320. METHODDEF(boolean)
  147321. encode_mcu_huff (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  147322. {
  147323. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147324. working_state state;
  147325. int blkn, ci;
  147326. jpeg_component_info * compptr;
  147327. state.next_output_byte = cinfo->dest->next_output_byte;
  147328. state.free_in_buffer = cinfo->dest->free_in_buffer;
  147329. ASSIGN_STATE(state.cur, entropy->saved);
  147330. state.cinfo = cinfo;
  147331. if (cinfo->restart_interval) {
  147332. if (entropy->restarts_to_go == 0)
  147333. if (! emit_restart(&state, entropy->next_restart_num))
  147334. return FALSE;
  147335. }
  147336. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  147337. ci = cinfo->MCU_membership[blkn];
  147338. compptr = cinfo->cur_comp_info[ci];
  147339. if (! encode_one_block(&state,
  147340. MCU_data[blkn][0], state.cur.last_dc_val[ci],
  147341. entropy->dc_derived_tbls[compptr->dc_tbl_no],
  147342. entropy->ac_derived_tbls[compptr->ac_tbl_no]))
  147343. return FALSE;
  147344. state.cur.last_dc_val[ci] = MCU_data[blkn][0][0];
  147345. }
  147346. cinfo->dest->next_output_byte = state.next_output_byte;
  147347. cinfo->dest->free_in_buffer = state.free_in_buffer;
  147348. ASSIGN_STATE(entropy->saved, state.cur);
  147349. if (cinfo->restart_interval) {
  147350. if (entropy->restarts_to_go == 0) {
  147351. entropy->restarts_to_go = cinfo->restart_interval;
  147352. entropy->next_restart_num++;
  147353. entropy->next_restart_num &= 7;
  147354. }
  147355. entropy->restarts_to_go--;
  147356. }
  147357. return TRUE;
  147358. }
  147359. METHODDEF(void)
  147360. finish_pass_huff (j_compress_ptr cinfo)
  147361. {
  147362. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147363. working_state state;
  147364. state.next_output_byte = cinfo->dest->next_output_byte;
  147365. state.free_in_buffer = cinfo->dest->free_in_buffer;
  147366. ASSIGN_STATE(state.cur, entropy->saved);
  147367. state.cinfo = cinfo;
  147368. if (! flush_bits(&state))
  147369. ERREXIT(cinfo, JERR_CANT_SUSPEND);
  147370. cinfo->dest->next_output_byte = state.next_output_byte;
  147371. cinfo->dest->free_in_buffer = state.free_in_buffer;
  147372. ASSIGN_STATE(entropy->saved, state.cur);
  147373. }
  147374. #ifdef ENTROPY_OPT_SUPPORTED
  147375. LOCAL(void)
  147376. htest_one_block (j_compress_ptr cinfo, JCOEFPTR block, int last_dc_val,
  147377. long dc_counts[], long ac_counts[])
  147378. {
  147379. register int temp;
  147380. register int nbits;
  147381. register int k, r;
  147382. temp = block[0] - last_dc_val;
  147383. if (temp < 0)
  147384. temp = -temp;
  147385. nbits = 0;
  147386. while (temp) {
  147387. nbits++;
  147388. temp >>= 1;
  147389. }
  147390. if (nbits > MAX_COEF_BITS+1)
  147391. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  147392. dc_counts[nbits]++;
  147393. r = 0; /* r = run length of zeros */
  147394. for (k = 1; k < DCTSIZE2; k++) {
  147395. if ((temp = block[jpeg_natural_order[k]]) == 0) {
  147396. r++;
  147397. } else {
  147398. while (r > 15) {
  147399. ac_counts[0xF0]++;
  147400. r -= 16;
  147401. }
  147402. if (temp < 0)
  147403. temp = -temp;
  147404. nbits = 1; /* there must be at least one 1 bit */
  147405. while ((temp >>= 1))
  147406. nbits++;
  147407. if (nbits > MAX_COEF_BITS)
  147408. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  147409. ac_counts[(r << 4) + nbits]++;
  147410. r = 0;
  147411. }
  147412. }
  147413. if (r > 0)
  147414. ac_counts[0]++;
  147415. }
  147416. METHODDEF(boolean)
  147417. encode_mcu_gather (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  147418. {
  147419. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147420. int blkn, ci;
  147421. jpeg_component_info * compptr;
  147422. if (cinfo->restart_interval) {
  147423. if (entropy->restarts_to_go == 0) {
  147424. for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  147425. entropy->saved.last_dc_val[ci] = 0;
  147426. entropy->restarts_to_go = cinfo->restart_interval;
  147427. }
  147428. entropy->restarts_to_go--;
  147429. }
  147430. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  147431. ci = cinfo->MCU_membership[blkn];
  147432. compptr = cinfo->cur_comp_info[ci];
  147433. htest_one_block(cinfo, MCU_data[blkn][0], entropy->saved.last_dc_val[ci],
  147434. entropy->dc_count_ptrs[compptr->dc_tbl_no],
  147435. entropy->ac_count_ptrs[compptr->ac_tbl_no]);
  147436. entropy->saved.last_dc_val[ci] = MCU_data[blkn][0][0];
  147437. }
  147438. return TRUE;
  147439. }
  147440. GLOBAL(void)
  147441. jpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[])
  147442. {
  147443. #define MAX_CLEN 32 /* assumed maximum initial code length */
  147444. UINT8 bits[MAX_CLEN+1]; /* bits[k] = # of symbols with code length k */
  147445. int codesize[257]; /* codesize[k] = code length of symbol k */
  147446. int others[257]; /* next symbol in current branch of tree */
  147447. int c1, c2;
  147448. int p, i, j;
  147449. long v;
  147450. MEMZERO(bits, SIZEOF(bits));
  147451. MEMZERO(codesize, SIZEOF(codesize));
  147452. for (i = 0; i < 257; i++)
  147453. others[i] = -1; /* init links to empty */
  147454. freq[256] = 1; /* make sure 256 has a nonzero count */
  147455. for (;;) {
  147456. c1 = -1;
  147457. v = 1000000000L;
  147458. for (i = 0; i <= 256; i++) {
  147459. if (freq[i] && freq[i] <= v) {
  147460. v = freq[i];
  147461. c1 = i;
  147462. }
  147463. }
  147464. c2 = -1;
  147465. v = 1000000000L;
  147466. for (i = 0; i <= 256; i++) {
  147467. if (freq[i] && freq[i] <= v && i != c1) {
  147468. v = freq[i];
  147469. c2 = i;
  147470. }
  147471. }
  147472. if (c2 < 0)
  147473. break;
  147474. freq[c1] += freq[c2];
  147475. freq[c2] = 0;
  147476. codesize[c1]++;
  147477. while (others[c1] >= 0) {
  147478. c1 = others[c1];
  147479. codesize[c1]++;
  147480. }
  147481. others[c1] = c2; /* chain c2 onto c1's tree branch */
  147482. codesize[c2]++;
  147483. while (others[c2] >= 0) {
  147484. c2 = others[c2];
  147485. codesize[c2]++;
  147486. }
  147487. }
  147488. for (i = 0; i <= 256; i++) {
  147489. if (codesize[i]) {
  147490. if (codesize[i] > MAX_CLEN)
  147491. ERREXIT(cinfo, JERR_HUFF_CLEN_OVERFLOW);
  147492. bits[codesize[i]]++;
  147493. }
  147494. }
  147495. for (i = MAX_CLEN; i > 16; i--) {
  147496. while (bits[i] > 0) {
  147497. j = i - 2; /* find length of new prefix to be used */
  147498. while (bits[j] == 0)
  147499. j--;
  147500. bits[i] -= 2; /* remove two symbols */
  147501. bits[i-1]++; /* one goes in this length */
  147502. bits[j+1] += 2; /* two new symbols in this length */
  147503. bits[j]--; /* symbol of this length is now a prefix */
  147504. }
  147505. }
  147506. while (bits[i] == 0) /* find largest codelength still in use */
  147507. i--;
  147508. bits[i]--;
  147509. MEMCOPY(htbl->bits, bits, SIZEOF(htbl->bits));
  147510. p = 0;
  147511. for (i = 1; i <= MAX_CLEN; i++) {
  147512. for (j = 0; j <= 255; j++) {
  147513. if (codesize[j] == i) {
  147514. htbl->huffval[p] = (UINT8) j;
  147515. p++;
  147516. }
  147517. }
  147518. }
  147519. htbl->sent_table = FALSE;
  147520. }
  147521. METHODDEF(void)
  147522. finish_pass_gather (j_compress_ptr cinfo)
  147523. {
  147524. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147525. int ci, dctbl, actbl;
  147526. jpeg_component_info * compptr;
  147527. JHUFF_TBL **htblptr;
  147528. boolean did_dc[NUM_HUFF_TBLS];
  147529. boolean did_ac[NUM_HUFF_TBLS];
  147530. MEMZERO(did_dc, SIZEOF(did_dc));
  147531. MEMZERO(did_ac, SIZEOF(did_ac));
  147532. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  147533. compptr = cinfo->cur_comp_info[ci];
  147534. dctbl = compptr->dc_tbl_no;
  147535. actbl = compptr->ac_tbl_no;
  147536. if (! did_dc[dctbl]) {
  147537. htblptr = & cinfo->dc_huff_tbl_ptrs[dctbl];
  147538. if (*htblptr == NULL)
  147539. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  147540. jpeg_gen_optimal_table(cinfo, *htblptr, entropy->dc_count_ptrs[dctbl]);
  147541. did_dc[dctbl] = TRUE;
  147542. }
  147543. if (! did_ac[actbl]) {
  147544. htblptr = & cinfo->ac_huff_tbl_ptrs[actbl];
  147545. if (*htblptr == NULL)
  147546. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  147547. jpeg_gen_optimal_table(cinfo, *htblptr, entropy->ac_count_ptrs[actbl]);
  147548. did_ac[actbl] = TRUE;
  147549. }
  147550. }
  147551. }
  147552. #endif /* ENTROPY_OPT_SUPPORTED */
  147553. GLOBAL(void)
  147554. jinit_huff_encoder (j_compress_ptr cinfo)
  147555. {
  147556. huff_entropy_ptr entropy;
  147557. int i;
  147558. entropy = (huff_entropy_ptr)
  147559. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147560. SIZEOF(huff_entropy_encoder));
  147561. cinfo->entropy = (struct jpeg_entropy_encoder *) entropy;
  147562. entropy->pub.start_pass = start_pass_huff;
  147563. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  147564. entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL;
  147565. #ifdef ENTROPY_OPT_SUPPORTED
  147566. entropy->dc_count_ptrs[i] = entropy->ac_count_ptrs[i] = NULL;
  147567. #endif
  147568. }
  147569. }
  147570. /*** End of inlined file: jchuff.c ***/
  147571. #undef emit_byte
  147572. /*** Start of inlined file: jcinit.c ***/
  147573. #define JPEG_INTERNALS
  147574. GLOBAL(void)
  147575. jinit_compress_master (j_compress_ptr cinfo)
  147576. {
  147577. jinit_c_master_control(cinfo, FALSE /* full compression */);
  147578. if (! cinfo->raw_data_in) {
  147579. jinit_color_converter(cinfo);
  147580. jinit_downsampler(cinfo);
  147581. jinit_c_prep_controller(cinfo, FALSE /* never need full buffer here */);
  147582. }
  147583. jinit_forward_dct(cinfo);
  147584. if (cinfo->arith_code) {
  147585. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  147586. } else {
  147587. if (cinfo->progressive_mode) {
  147588. #ifdef C_PROGRESSIVE_SUPPORTED
  147589. jinit_phuff_encoder(cinfo);
  147590. #else
  147591. ERREXIT(cinfo, JERR_NOT_COMPILED);
  147592. #endif
  147593. } else
  147594. jinit_huff_encoder(cinfo);
  147595. }
  147596. jinit_c_coef_controller(cinfo,
  147597. (boolean) (cinfo->num_scans > 1 || cinfo->optimize_coding));
  147598. jinit_c_main_controller(cinfo, FALSE /* never need full buffer here */);
  147599. jinit_marker_writer(cinfo);
  147600. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  147601. (*cinfo->marker->write_file_header) (cinfo);
  147602. }
  147603. /*** End of inlined file: jcinit.c ***/
  147604. /*** Start of inlined file: jcmainct.c ***/
  147605. #define JPEG_INTERNALS
  147606. #undef FULL_MAIN_BUFFER_SUPPORTED
  147607. typedef struct {
  147608. struct jpeg_c_main_controller pub; /* public fields */
  147609. JDIMENSION cur_iMCU_row; /* number of current iMCU row */
  147610. JDIMENSION rowgroup_ctr; /* counts row groups received in iMCU row */
  147611. boolean suspended; /* remember if we suspended output */
  147612. J_BUF_MODE pass_mode; /* current operating mode */
  147613. JSAMPARRAY buffer[MAX_COMPONENTS];
  147614. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147615. jvirt_sarray_ptr whole_image[MAX_COMPONENTS];
  147616. #endif
  147617. } my_main_controller;
  147618. typedef my_main_controller * my_main_ptr;
  147619. METHODDEF(void) process_data_simple_main
  147620. JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,
  147621. JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));
  147622. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147623. METHODDEF(void) process_data_buffer_main
  147624. JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,
  147625. JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));
  147626. #endif
  147627. METHODDEF(void)
  147628. start_pass_main (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  147629. {
  147630. my_main_ptr main_ = (my_main_ptr) cinfo->main;
  147631. if (cinfo->raw_data_in)
  147632. return;
  147633. main_->cur_iMCU_row = 0; /* initialize counters */
  147634. main_->rowgroup_ctr = 0;
  147635. main_->suspended = FALSE;
  147636. main_->pass_mode = pass_mode; /* save mode for use by process_data */
  147637. switch (pass_mode) {
  147638. case JBUF_PASS_THRU:
  147639. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147640. if (main_->whole_image[0] != NULL)
  147641. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  147642. #endif
  147643. main_->pub.process_data = process_data_simple_main;
  147644. break;
  147645. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147646. case JBUF_SAVE_SOURCE:
  147647. case JBUF_CRANK_DEST:
  147648. case JBUF_SAVE_AND_PASS:
  147649. if (main_->whole_image[0] == NULL)
  147650. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  147651. main_->pub.process_data = process_data_buffer_main;
  147652. break;
  147653. #endif
  147654. default:
  147655. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  147656. break;
  147657. }
  147658. }
  147659. METHODDEF(void)
  147660. process_data_simple_main (j_compress_ptr cinfo,
  147661. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  147662. JDIMENSION in_rows_avail)
  147663. {
  147664. my_main_ptr main_ = (my_main_ptr) cinfo->main;
  147665. while (main_->cur_iMCU_row < cinfo->total_iMCU_rows) {
  147666. if (main_->rowgroup_ctr < DCTSIZE)
  147667. (*cinfo->prep->pre_process_data) (cinfo,
  147668. input_buf, in_row_ctr, in_rows_avail,
  147669. main_->buffer, &main_->rowgroup_ctr,
  147670. (JDIMENSION) DCTSIZE);
  147671. if (main_->rowgroup_ctr != DCTSIZE)
  147672. return;
  147673. if (! (*cinfo->coef->compress_data) (cinfo, main_->buffer)) {
  147674. if (! main_->suspended) {
  147675. (*in_row_ctr)--;
  147676. main_->suspended = TRUE;
  147677. }
  147678. return;
  147679. }
  147680. if (main_->suspended) {
  147681. (*in_row_ctr)++;
  147682. main_->suspended = FALSE;
  147683. }
  147684. main_->rowgroup_ctr = 0;
  147685. main_->cur_iMCU_row++;
  147686. }
  147687. }
  147688. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147689. METHODDEF(void)
  147690. process_data_buffer_main (j_compress_ptr cinfo,
  147691. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  147692. JDIMENSION in_rows_avail)
  147693. {
  147694. my_main_ptr main = (my_main_ptr) cinfo->main;
  147695. int ci;
  147696. jpeg_component_info *compptr;
  147697. boolean writing = (main->pass_mode != JBUF_CRANK_DEST);
  147698. while (main->cur_iMCU_row < cinfo->total_iMCU_rows) {
  147699. if (main->rowgroup_ctr == 0) {
  147700. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147701. ci++, compptr++) {
  147702. main->buffer[ci] = (*cinfo->mem->access_virt_sarray)
  147703. ((j_common_ptr) cinfo, main->whole_image[ci],
  147704. main->cur_iMCU_row * (compptr->v_samp_factor * DCTSIZE),
  147705. (JDIMENSION) (compptr->v_samp_factor * DCTSIZE), writing);
  147706. }
  147707. if (! writing) {
  147708. *in_row_ctr += cinfo->max_v_samp_factor * DCTSIZE;
  147709. main->rowgroup_ctr = DCTSIZE;
  147710. }
  147711. }
  147712. if (writing) {
  147713. (*cinfo->prep->pre_process_data) (cinfo,
  147714. input_buf, in_row_ctr, in_rows_avail,
  147715. main->buffer, &main->rowgroup_ctr,
  147716. (JDIMENSION) DCTSIZE);
  147717. if (main->rowgroup_ctr < DCTSIZE)
  147718. return;
  147719. }
  147720. if (main->pass_mode != JBUF_SAVE_SOURCE) {
  147721. if (! (*cinfo->coef->compress_data) (cinfo, main->buffer)) {
  147722. if (! main->suspended) {
  147723. (*in_row_ctr)--;
  147724. main->suspended = TRUE;
  147725. }
  147726. return;
  147727. }
  147728. if (main->suspended) {
  147729. (*in_row_ctr)++;
  147730. main->suspended = FALSE;
  147731. }
  147732. }
  147733. main->rowgroup_ctr = 0;
  147734. main->cur_iMCU_row++;
  147735. }
  147736. }
  147737. #endif /* FULL_MAIN_BUFFER_SUPPORTED */
  147738. GLOBAL(void)
  147739. jinit_c_main_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  147740. {
  147741. my_main_ptr main_;
  147742. int ci;
  147743. jpeg_component_info *compptr;
  147744. main_ = (my_main_ptr)
  147745. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147746. SIZEOF(my_main_controller));
  147747. cinfo->main = (struct jpeg_c_main_controller *) main_;
  147748. main_->pub.start_pass = start_pass_main;
  147749. if (cinfo->raw_data_in)
  147750. return;
  147751. if (need_full_buffer) {
  147752. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147753. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147754. ci++, compptr++) {
  147755. main->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
  147756. ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  147757. compptr->width_in_blocks * DCTSIZE,
  147758. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  147759. (long) compptr->v_samp_factor) * DCTSIZE,
  147760. (JDIMENSION) (compptr->v_samp_factor * DCTSIZE));
  147761. }
  147762. #else
  147763. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  147764. #endif
  147765. } else {
  147766. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147767. main_->whole_image[0] = NULL; /* flag for no virtual arrays */
  147768. #endif
  147769. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147770. ci++, compptr++) {
  147771. main_->buffer[ci] = (*cinfo->mem->alloc_sarray)
  147772. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147773. compptr->width_in_blocks * DCTSIZE,
  147774. (JDIMENSION) (compptr->v_samp_factor * DCTSIZE));
  147775. }
  147776. }
  147777. }
  147778. /*** End of inlined file: jcmainct.c ***/
  147779. /*** Start of inlined file: jcmarker.c ***/
  147780. #define JPEG_INTERNALS
  147781. typedef struct {
  147782. struct jpeg_marker_writer pub; /* public fields */
  147783. unsigned int last_restart_interval; /* last DRI value emitted; 0 after SOI */
  147784. } my_marker_writer;
  147785. typedef my_marker_writer * my_marker_ptr;
  147786. LOCAL(void)
  147787. emit_byte (j_compress_ptr cinfo, int val)
  147788. {
  147789. struct jpeg_destination_mgr * dest = cinfo->dest;
  147790. *(dest->next_output_byte)++ = (JOCTET) val;
  147791. if (--dest->free_in_buffer == 0) {
  147792. if (! (*dest->empty_output_buffer) (cinfo))
  147793. ERREXIT(cinfo, JERR_CANT_SUSPEND);
  147794. }
  147795. }
  147796. LOCAL(void)
  147797. emit_marker (j_compress_ptr cinfo, JPEG_MARKER mark)
  147798. {
  147799. emit_byte(cinfo, 0xFF);
  147800. emit_byte(cinfo, (int) mark);
  147801. }
  147802. LOCAL(void)
  147803. emit_2bytes (j_compress_ptr cinfo, int value)
  147804. {
  147805. emit_byte(cinfo, (value >> 8) & 0xFF);
  147806. emit_byte(cinfo, value & 0xFF);
  147807. }
  147808. LOCAL(int)
  147809. emit_dqt (j_compress_ptr cinfo, int index)
  147810. {
  147811. JQUANT_TBL * qtbl = cinfo->quant_tbl_ptrs[index];
  147812. int prec;
  147813. int i;
  147814. if (qtbl == NULL)
  147815. ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, index);
  147816. prec = 0;
  147817. for (i = 0; i < DCTSIZE2; i++) {
  147818. if (qtbl->quantval[i] > 255)
  147819. prec = 1;
  147820. }
  147821. if (! qtbl->sent_table) {
  147822. emit_marker(cinfo, M_DQT);
  147823. emit_2bytes(cinfo, prec ? DCTSIZE2*2 + 1 + 2 : DCTSIZE2 + 1 + 2);
  147824. emit_byte(cinfo, index + (prec<<4));
  147825. for (i = 0; i < DCTSIZE2; i++) {
  147826. unsigned int qval = qtbl->quantval[jpeg_natural_order[i]];
  147827. if (prec)
  147828. emit_byte(cinfo, (int) (qval >> 8));
  147829. emit_byte(cinfo, (int) (qval & 0xFF));
  147830. }
  147831. qtbl->sent_table = TRUE;
  147832. }
  147833. return prec;
  147834. }
  147835. LOCAL(void)
  147836. emit_dht (j_compress_ptr cinfo, int index, boolean is_ac)
  147837. {
  147838. JHUFF_TBL * htbl;
  147839. int length, i;
  147840. if (is_ac) {
  147841. htbl = cinfo->ac_huff_tbl_ptrs[index];
  147842. index += 0x10; /* output index has AC bit set */
  147843. } else {
  147844. htbl = cinfo->dc_huff_tbl_ptrs[index];
  147845. }
  147846. if (htbl == NULL)
  147847. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, index);
  147848. if (! htbl->sent_table) {
  147849. emit_marker(cinfo, M_DHT);
  147850. length = 0;
  147851. for (i = 1; i <= 16; i++)
  147852. length += htbl->bits[i];
  147853. emit_2bytes(cinfo, length + 2 + 1 + 16);
  147854. emit_byte(cinfo, index);
  147855. for (i = 1; i <= 16; i++)
  147856. emit_byte(cinfo, htbl->bits[i]);
  147857. for (i = 0; i < length; i++)
  147858. emit_byte(cinfo, htbl->huffval[i]);
  147859. htbl->sent_table = TRUE;
  147860. }
  147861. }
  147862. LOCAL(void)
  147863. emit_dac (j_compress_ptr cinfo)
  147864. {
  147865. #ifdef C_ARITH_CODING_SUPPORTED
  147866. char dc_in_use[NUM_ARITH_TBLS];
  147867. char ac_in_use[NUM_ARITH_TBLS];
  147868. int length, i;
  147869. jpeg_component_info *compptr;
  147870. for (i = 0; i < NUM_ARITH_TBLS; i++)
  147871. dc_in_use[i] = ac_in_use[i] = 0;
  147872. for (i = 0; i < cinfo->comps_in_scan; i++) {
  147873. compptr = cinfo->cur_comp_info[i];
  147874. dc_in_use[compptr->dc_tbl_no] = 1;
  147875. ac_in_use[compptr->ac_tbl_no] = 1;
  147876. }
  147877. length = 0;
  147878. for (i = 0; i < NUM_ARITH_TBLS; i++)
  147879. length += dc_in_use[i] + ac_in_use[i];
  147880. emit_marker(cinfo, M_DAC);
  147881. emit_2bytes(cinfo, length*2 + 2);
  147882. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  147883. if (dc_in_use[i]) {
  147884. emit_byte(cinfo, i);
  147885. emit_byte(cinfo, cinfo->arith_dc_L[i] + (cinfo->arith_dc_U[i]<<4));
  147886. }
  147887. if (ac_in_use[i]) {
  147888. emit_byte(cinfo, i + 0x10);
  147889. emit_byte(cinfo, cinfo->arith_ac_K[i]);
  147890. }
  147891. }
  147892. #endif /* C_ARITH_CODING_SUPPORTED */
  147893. }
  147894. LOCAL(void)
  147895. emit_dri (j_compress_ptr cinfo)
  147896. {
  147897. emit_marker(cinfo, M_DRI);
  147898. emit_2bytes(cinfo, 4); /* fixed length */
  147899. emit_2bytes(cinfo, (int) cinfo->restart_interval);
  147900. }
  147901. LOCAL(void)
  147902. emit_sof (j_compress_ptr cinfo, JPEG_MARKER code)
  147903. {
  147904. int ci;
  147905. jpeg_component_info *compptr;
  147906. emit_marker(cinfo, code);
  147907. emit_2bytes(cinfo, 3 * cinfo->num_components + 2 + 5 + 1); /* length */
  147908. if ((long) cinfo->image_height > 65535L ||
  147909. (long) cinfo->image_width > 65535L)
  147910. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) 65535);
  147911. emit_byte(cinfo, cinfo->data_precision);
  147912. emit_2bytes(cinfo, (int) cinfo->image_height);
  147913. emit_2bytes(cinfo, (int) cinfo->image_width);
  147914. emit_byte(cinfo, cinfo->num_components);
  147915. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147916. ci++, compptr++) {
  147917. emit_byte(cinfo, compptr->component_id);
  147918. emit_byte(cinfo, (compptr->h_samp_factor << 4) + compptr->v_samp_factor);
  147919. emit_byte(cinfo, compptr->quant_tbl_no);
  147920. }
  147921. }
  147922. LOCAL(void)
  147923. emit_sos (j_compress_ptr cinfo)
  147924. {
  147925. int i, td, ta;
  147926. jpeg_component_info *compptr;
  147927. emit_marker(cinfo, M_SOS);
  147928. emit_2bytes(cinfo, 2 * cinfo->comps_in_scan + 2 + 1 + 3); /* length */
  147929. emit_byte(cinfo, cinfo->comps_in_scan);
  147930. for (i = 0; i < cinfo->comps_in_scan; i++) {
  147931. compptr = cinfo->cur_comp_info[i];
  147932. emit_byte(cinfo, compptr->component_id);
  147933. td = compptr->dc_tbl_no;
  147934. ta = compptr->ac_tbl_no;
  147935. if (cinfo->progressive_mode) {
  147936. if (cinfo->Ss == 0) {
  147937. ta = 0; /* DC scan */
  147938. if (cinfo->Ah != 0 && !cinfo->arith_code)
  147939. td = 0; /* no DC table either */
  147940. } else {
  147941. td = 0; /* AC scan */
  147942. }
  147943. }
  147944. emit_byte(cinfo, (td << 4) + ta);
  147945. }
  147946. emit_byte(cinfo, cinfo->Ss);
  147947. emit_byte(cinfo, cinfo->Se);
  147948. emit_byte(cinfo, (cinfo->Ah << 4) + cinfo->Al);
  147949. }
  147950. LOCAL(void)
  147951. emit_jfif_app0 (j_compress_ptr cinfo)
  147952. {
  147953. emit_marker(cinfo, M_APP0);
  147954. emit_2bytes(cinfo, 2 + 4 + 1 + 2 + 1 + 2 + 2 + 1 + 1); /* length */
  147955. emit_byte(cinfo, 0x4A); /* Identifier: ASCII "JFIF" */
  147956. emit_byte(cinfo, 0x46);
  147957. emit_byte(cinfo, 0x49);
  147958. emit_byte(cinfo, 0x46);
  147959. emit_byte(cinfo, 0);
  147960. emit_byte(cinfo, cinfo->JFIF_major_version); /* Version fields */
  147961. emit_byte(cinfo, cinfo->JFIF_minor_version);
  147962. emit_byte(cinfo, cinfo->density_unit); /* Pixel size information */
  147963. emit_2bytes(cinfo, (int) cinfo->X_density);
  147964. emit_2bytes(cinfo, (int) cinfo->Y_density);
  147965. emit_byte(cinfo, 0); /* No thumbnail image */
  147966. emit_byte(cinfo, 0);
  147967. }
  147968. LOCAL(void)
  147969. emit_adobe_app14 (j_compress_ptr cinfo)
  147970. {
  147971. emit_marker(cinfo, M_APP14);
  147972. emit_2bytes(cinfo, 2 + 5 + 2 + 2 + 2 + 1); /* length */
  147973. emit_byte(cinfo, 0x41); /* Identifier: ASCII "Adobe" */
  147974. emit_byte(cinfo, 0x64);
  147975. emit_byte(cinfo, 0x6F);
  147976. emit_byte(cinfo, 0x62);
  147977. emit_byte(cinfo, 0x65);
  147978. emit_2bytes(cinfo, 100); /* Version */
  147979. emit_2bytes(cinfo, 0); /* Flags0 */
  147980. emit_2bytes(cinfo, 0); /* Flags1 */
  147981. switch (cinfo->jpeg_color_space) {
  147982. case JCS_YCbCr:
  147983. emit_byte(cinfo, 1); /* Color transform = 1 */
  147984. break;
  147985. case JCS_YCCK:
  147986. emit_byte(cinfo, 2); /* Color transform = 2 */
  147987. break;
  147988. default:
  147989. emit_byte(cinfo, 0); /* Color transform = 0 */
  147990. break;
  147991. }
  147992. }
  147993. METHODDEF(void)
  147994. write_marker_header (j_compress_ptr cinfo, int marker, unsigned int datalen)
  147995. {
  147996. if (datalen > (unsigned int) 65533) /* safety check */
  147997. ERREXIT(cinfo, JERR_BAD_LENGTH);
  147998. emit_marker(cinfo, (JPEG_MARKER) marker);
  147999. emit_2bytes(cinfo, (int) (datalen + 2)); /* total length */
  148000. }
  148001. METHODDEF(void)
  148002. write_marker_byte (j_compress_ptr cinfo, int val)
  148003. {
  148004. emit_byte(cinfo, val);
  148005. }
  148006. METHODDEF(void)
  148007. write_file_header (j_compress_ptr cinfo)
  148008. {
  148009. my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
  148010. emit_marker(cinfo, M_SOI); /* first the SOI */
  148011. marker->last_restart_interval = 0;
  148012. if (cinfo->write_JFIF_header) /* next an optional JFIF APP0 */
  148013. emit_jfif_app0(cinfo);
  148014. if (cinfo->write_Adobe_marker) /* next an optional Adobe APP14 */
  148015. emit_adobe_app14(cinfo);
  148016. }
  148017. METHODDEF(void)
  148018. write_frame_header (j_compress_ptr cinfo)
  148019. {
  148020. int ci, prec;
  148021. boolean is_baseline;
  148022. jpeg_component_info *compptr;
  148023. prec = 0;
  148024. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148025. ci++, compptr++) {
  148026. prec += emit_dqt(cinfo, compptr->quant_tbl_no);
  148027. }
  148028. if (cinfo->arith_code || cinfo->progressive_mode ||
  148029. cinfo->data_precision != 8) {
  148030. is_baseline = FALSE;
  148031. } else {
  148032. is_baseline = TRUE;
  148033. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148034. ci++, compptr++) {
  148035. if (compptr->dc_tbl_no > 1 || compptr->ac_tbl_no > 1)
  148036. is_baseline = FALSE;
  148037. }
  148038. if (prec && is_baseline) {
  148039. is_baseline = FALSE;
  148040. TRACEMS(cinfo, 0, JTRC_16BIT_TABLES);
  148041. }
  148042. }
  148043. if (cinfo->arith_code) {
  148044. emit_sof(cinfo, M_SOF9); /* SOF code for arithmetic coding */
  148045. } else {
  148046. if (cinfo->progressive_mode)
  148047. emit_sof(cinfo, M_SOF2); /* SOF code for progressive Huffman */
  148048. else if (is_baseline)
  148049. emit_sof(cinfo, M_SOF0); /* SOF code for baseline implementation */
  148050. else
  148051. emit_sof(cinfo, M_SOF1); /* SOF code for non-baseline Huffman file */
  148052. }
  148053. }
  148054. METHODDEF(void)
  148055. write_scan_header (j_compress_ptr cinfo)
  148056. {
  148057. my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
  148058. int i;
  148059. jpeg_component_info *compptr;
  148060. if (cinfo->arith_code) {
  148061. emit_dac(cinfo);
  148062. } else {
  148063. for (i = 0; i < cinfo->comps_in_scan; i++) {
  148064. compptr = cinfo->cur_comp_info[i];
  148065. if (cinfo->progressive_mode) {
  148066. if (cinfo->Ss == 0) {
  148067. if (cinfo->Ah == 0) /* DC needs no table for refinement scan */
  148068. emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
  148069. } else {
  148070. emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
  148071. }
  148072. } else {
  148073. emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
  148074. emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
  148075. }
  148076. }
  148077. }
  148078. if (cinfo->restart_interval != marker->last_restart_interval) {
  148079. emit_dri(cinfo);
  148080. marker->last_restart_interval = cinfo->restart_interval;
  148081. }
  148082. emit_sos(cinfo);
  148083. }
  148084. METHODDEF(void)
  148085. write_file_trailer (j_compress_ptr cinfo)
  148086. {
  148087. emit_marker(cinfo, M_EOI);
  148088. }
  148089. METHODDEF(void)
  148090. write_tables_only (j_compress_ptr cinfo)
  148091. {
  148092. int i;
  148093. emit_marker(cinfo, M_SOI);
  148094. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  148095. if (cinfo->quant_tbl_ptrs[i] != NULL)
  148096. (void) emit_dqt(cinfo, i);
  148097. }
  148098. if (! cinfo->arith_code) {
  148099. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  148100. if (cinfo->dc_huff_tbl_ptrs[i] != NULL)
  148101. emit_dht(cinfo, i, FALSE);
  148102. if (cinfo->ac_huff_tbl_ptrs[i] != NULL)
  148103. emit_dht(cinfo, i, TRUE);
  148104. }
  148105. }
  148106. emit_marker(cinfo, M_EOI);
  148107. }
  148108. GLOBAL(void)
  148109. jinit_marker_writer (j_compress_ptr cinfo)
  148110. {
  148111. my_marker_ptr marker;
  148112. marker = (my_marker_ptr)
  148113. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148114. SIZEOF(my_marker_writer));
  148115. cinfo->marker = (struct jpeg_marker_writer *) marker;
  148116. marker->pub.write_file_header = write_file_header;
  148117. marker->pub.write_frame_header = write_frame_header;
  148118. marker->pub.write_scan_header = write_scan_header;
  148119. marker->pub.write_file_trailer = write_file_trailer;
  148120. marker->pub.write_tables_only = write_tables_only;
  148121. marker->pub.write_marker_header = write_marker_header;
  148122. marker->pub.write_marker_byte = write_marker_byte;
  148123. marker->last_restart_interval = 0;
  148124. }
  148125. /*** End of inlined file: jcmarker.c ***/
  148126. /*** Start of inlined file: jcmaster.c ***/
  148127. #define JPEG_INTERNALS
  148128. typedef enum {
  148129. main_pass, /* input data, also do first output step */
  148130. huff_opt_pass, /* Huffman code optimization pass */
  148131. output_pass /* data output pass */
  148132. } c_pass_type;
  148133. typedef struct {
  148134. struct jpeg_comp_master pub; /* public fields */
  148135. c_pass_type pass_type; /* the type of the current pass */
  148136. int pass_number; /* # of passes completed */
  148137. int total_passes; /* total # of passes needed */
  148138. int scan_number; /* current index in scan_info[] */
  148139. } my_comp_master;
  148140. typedef my_comp_master * my_master_ptr;
  148141. LOCAL(void)
  148142. initial_setup (j_compress_ptr cinfo)
  148143. {
  148144. int ci;
  148145. jpeg_component_info *compptr;
  148146. long samplesperrow;
  148147. JDIMENSION jd_samplesperrow;
  148148. if (cinfo->image_height <= 0 || cinfo->image_width <= 0
  148149. || cinfo->num_components <= 0 || cinfo->input_components <= 0)
  148150. ERREXIT(cinfo, JERR_EMPTY_IMAGE);
  148151. if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION ||
  148152. (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION)
  148153. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
  148154. samplesperrow = (long) cinfo->image_width * (long) cinfo->input_components;
  148155. jd_samplesperrow = (JDIMENSION) samplesperrow;
  148156. if ((long) jd_samplesperrow != samplesperrow)
  148157. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  148158. if (cinfo->data_precision != BITS_IN_JSAMPLE)
  148159. ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
  148160. if (cinfo->num_components > MAX_COMPONENTS)
  148161. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  148162. MAX_COMPONENTS);
  148163. cinfo->max_h_samp_factor = 1;
  148164. cinfo->max_v_samp_factor = 1;
  148165. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148166. ci++, compptr++) {
  148167. if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR ||
  148168. compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
  148169. ERREXIT(cinfo, JERR_BAD_SAMPLING);
  148170. cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
  148171. compptr->h_samp_factor);
  148172. cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
  148173. compptr->v_samp_factor);
  148174. }
  148175. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148176. ci++, compptr++) {
  148177. compptr->component_index = ci;
  148178. compptr->DCT_scaled_size = DCTSIZE;
  148179. compptr->width_in_blocks = (JDIMENSION)
  148180. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  148181. (long) (cinfo->max_h_samp_factor * DCTSIZE));
  148182. compptr->height_in_blocks = (JDIMENSION)
  148183. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  148184. (long) (cinfo->max_v_samp_factor * DCTSIZE));
  148185. compptr->downsampled_width = (JDIMENSION)
  148186. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  148187. (long) cinfo->max_h_samp_factor);
  148188. compptr->downsampled_height = (JDIMENSION)
  148189. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  148190. (long) cinfo->max_v_samp_factor);
  148191. compptr->component_needed = TRUE;
  148192. }
  148193. cinfo->total_iMCU_rows = (JDIMENSION)
  148194. jdiv_round_up((long) cinfo->image_height,
  148195. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  148196. }
  148197. #ifdef C_MULTISCAN_FILES_SUPPORTED
  148198. LOCAL(void)
  148199. validate_script (j_compress_ptr cinfo)
  148200. {
  148201. const jpeg_scan_info * scanptr;
  148202. int scanno, ncomps, ci, coefi, thisi;
  148203. int Ss, Se, Ah, Al;
  148204. boolean component_sent[MAX_COMPONENTS];
  148205. #ifdef C_PROGRESSIVE_SUPPORTED
  148206. int * last_bitpos_ptr;
  148207. int last_bitpos[MAX_COMPONENTS][DCTSIZE2];
  148208. #endif
  148209. if (cinfo->num_scans <= 0)
  148210. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, 0);
  148211. scanptr = cinfo->scan_info;
  148212. if (scanptr->Ss != 0 || scanptr->Se != DCTSIZE2-1) {
  148213. #ifdef C_PROGRESSIVE_SUPPORTED
  148214. cinfo->progressive_mode = TRUE;
  148215. last_bitpos_ptr = & last_bitpos[0][0];
  148216. for (ci = 0; ci < cinfo->num_components; ci++)
  148217. for (coefi = 0; coefi < DCTSIZE2; coefi++)
  148218. *last_bitpos_ptr++ = -1;
  148219. #else
  148220. ERREXIT(cinfo, JERR_NOT_COMPILED);
  148221. #endif
  148222. } else {
  148223. cinfo->progressive_mode = FALSE;
  148224. for (ci = 0; ci < cinfo->num_components; ci++)
  148225. component_sent[ci] = FALSE;
  148226. }
  148227. for (scanno = 1; scanno <= cinfo->num_scans; scanptr++, scanno++) {
  148228. ncomps = scanptr->comps_in_scan;
  148229. if (ncomps <= 0 || ncomps > MAX_COMPS_IN_SCAN)
  148230. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, ncomps, MAX_COMPS_IN_SCAN);
  148231. for (ci = 0; ci < ncomps; ci++) {
  148232. thisi = scanptr->component_index[ci];
  148233. if (thisi < 0 || thisi >= cinfo->num_components)
  148234. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  148235. if (ci > 0 && thisi <= scanptr->component_index[ci-1])
  148236. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  148237. }
  148238. Ss = scanptr->Ss;
  148239. Se = scanptr->Se;
  148240. Ah = scanptr->Ah;
  148241. Al = scanptr->Al;
  148242. if (cinfo->progressive_mode) {
  148243. #ifdef C_PROGRESSIVE_SUPPORTED
  148244. #if BITS_IN_JSAMPLE == 8
  148245. #define MAX_AH_AL 10
  148246. #else
  148247. #define MAX_AH_AL 13
  148248. #endif
  148249. if (Ss < 0 || Ss >= DCTSIZE2 || Se < Ss || Se >= DCTSIZE2 ||
  148250. Ah < 0 || Ah > MAX_AH_AL || Al < 0 || Al > MAX_AH_AL)
  148251. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148252. if (Ss == 0) {
  148253. if (Se != 0) /* DC and AC together not OK */
  148254. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148255. } else {
  148256. if (ncomps != 1) /* AC scans must be for only one component */
  148257. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148258. }
  148259. for (ci = 0; ci < ncomps; ci++) {
  148260. last_bitpos_ptr = & last_bitpos[scanptr->component_index[ci]][0];
  148261. if (Ss != 0 && last_bitpos_ptr[0] < 0) /* AC without prior DC scan */
  148262. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148263. for (coefi = Ss; coefi <= Se; coefi++) {
  148264. if (last_bitpos_ptr[coefi] < 0) {
  148265. if (Ah != 0)
  148266. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148267. } else {
  148268. if (Ah != last_bitpos_ptr[coefi] || Al != Ah-1)
  148269. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148270. }
  148271. last_bitpos_ptr[coefi] = Al;
  148272. }
  148273. }
  148274. #endif
  148275. } else {
  148276. if (Ss != 0 || Se != DCTSIZE2-1 || Ah != 0 || Al != 0)
  148277. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148278. for (ci = 0; ci < ncomps; ci++) {
  148279. thisi = scanptr->component_index[ci];
  148280. if (component_sent[thisi])
  148281. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  148282. component_sent[thisi] = TRUE;
  148283. }
  148284. }
  148285. }
  148286. if (cinfo->progressive_mode) {
  148287. #ifdef C_PROGRESSIVE_SUPPORTED
  148288. for (ci = 0; ci < cinfo->num_components; ci++) {
  148289. if (last_bitpos[ci][0] < 0)
  148290. ERREXIT(cinfo, JERR_MISSING_DATA);
  148291. }
  148292. #endif
  148293. } else {
  148294. for (ci = 0; ci < cinfo->num_components; ci++) {
  148295. if (! component_sent[ci])
  148296. ERREXIT(cinfo, JERR_MISSING_DATA);
  148297. }
  148298. }
  148299. }
  148300. #endif /* C_MULTISCAN_FILES_SUPPORTED */
  148301. LOCAL(void)
  148302. select_scan_parameters (j_compress_ptr cinfo)
  148303. {
  148304. int ci;
  148305. #ifdef C_MULTISCAN_FILES_SUPPORTED
  148306. if (cinfo->scan_info != NULL) {
  148307. my_master_ptr master = (my_master_ptr) cinfo->master;
  148308. const jpeg_scan_info * scanptr = cinfo->scan_info + master->scan_number;
  148309. cinfo->comps_in_scan = scanptr->comps_in_scan;
  148310. for (ci = 0; ci < scanptr->comps_in_scan; ci++) {
  148311. cinfo->cur_comp_info[ci] =
  148312. &cinfo->comp_info[scanptr->component_index[ci]];
  148313. }
  148314. cinfo->Ss = scanptr->Ss;
  148315. cinfo->Se = scanptr->Se;
  148316. cinfo->Ah = scanptr->Ah;
  148317. cinfo->Al = scanptr->Al;
  148318. }
  148319. else
  148320. #endif
  148321. {
  148322. if (cinfo->num_components > MAX_COMPS_IN_SCAN)
  148323. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  148324. MAX_COMPS_IN_SCAN);
  148325. cinfo->comps_in_scan = cinfo->num_components;
  148326. for (ci = 0; ci < cinfo->num_components; ci++) {
  148327. cinfo->cur_comp_info[ci] = &cinfo->comp_info[ci];
  148328. }
  148329. cinfo->Ss = 0;
  148330. cinfo->Se = DCTSIZE2-1;
  148331. cinfo->Ah = 0;
  148332. cinfo->Al = 0;
  148333. }
  148334. }
  148335. LOCAL(void)
  148336. per_scan_setup (j_compress_ptr cinfo)
  148337. {
  148338. int ci, mcublks, tmp;
  148339. jpeg_component_info *compptr;
  148340. if (cinfo->comps_in_scan == 1) {
  148341. compptr = cinfo->cur_comp_info[0];
  148342. cinfo->MCUs_per_row = compptr->width_in_blocks;
  148343. cinfo->MCU_rows_in_scan = compptr->height_in_blocks;
  148344. compptr->MCU_width = 1;
  148345. compptr->MCU_height = 1;
  148346. compptr->MCU_blocks = 1;
  148347. compptr->MCU_sample_width = DCTSIZE;
  148348. compptr->last_col_width = 1;
  148349. tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  148350. if (tmp == 0) tmp = compptr->v_samp_factor;
  148351. compptr->last_row_height = tmp;
  148352. cinfo->blocks_in_MCU = 1;
  148353. cinfo->MCU_membership[0] = 0;
  148354. } else {
  148355. if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
  148356. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
  148357. MAX_COMPS_IN_SCAN);
  148358. cinfo->MCUs_per_row = (JDIMENSION)
  148359. jdiv_round_up((long) cinfo->image_width,
  148360. (long) (cinfo->max_h_samp_factor*DCTSIZE));
  148361. cinfo->MCU_rows_in_scan = (JDIMENSION)
  148362. jdiv_round_up((long) cinfo->image_height,
  148363. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  148364. cinfo->blocks_in_MCU = 0;
  148365. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  148366. compptr = cinfo->cur_comp_info[ci];
  148367. compptr->MCU_width = compptr->h_samp_factor;
  148368. compptr->MCU_height = compptr->v_samp_factor;
  148369. compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
  148370. compptr->MCU_sample_width = compptr->MCU_width * DCTSIZE;
  148371. tmp = (int) (compptr->width_in_blocks % compptr->MCU_width);
  148372. if (tmp == 0) tmp = compptr->MCU_width;
  148373. compptr->last_col_width = tmp;
  148374. tmp = (int) (compptr->height_in_blocks % compptr->MCU_height);
  148375. if (tmp == 0) tmp = compptr->MCU_height;
  148376. compptr->last_row_height = tmp;
  148377. mcublks = compptr->MCU_blocks;
  148378. if (cinfo->blocks_in_MCU + mcublks > C_MAX_BLOCKS_IN_MCU)
  148379. ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
  148380. while (mcublks-- > 0) {
  148381. cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
  148382. }
  148383. }
  148384. }
  148385. if (cinfo->restart_in_rows > 0) {
  148386. long nominal = (long) cinfo->restart_in_rows * (long) cinfo->MCUs_per_row;
  148387. cinfo->restart_interval = (unsigned int) MIN(nominal, 65535L);
  148388. }
  148389. }
  148390. METHODDEF(void)
  148391. prepare_for_pass (j_compress_ptr cinfo)
  148392. {
  148393. my_master_ptr master = (my_master_ptr) cinfo->master;
  148394. switch (master->pass_type) {
  148395. case main_pass:
  148396. select_scan_parameters(cinfo);
  148397. per_scan_setup(cinfo);
  148398. if (! cinfo->raw_data_in) {
  148399. (*cinfo->cconvert->start_pass) (cinfo);
  148400. (*cinfo->downsample->start_pass) (cinfo);
  148401. (*cinfo->prep->start_pass) (cinfo, JBUF_PASS_THRU);
  148402. }
  148403. (*cinfo->fdct->start_pass) (cinfo);
  148404. (*cinfo->entropy->start_pass) (cinfo, cinfo->optimize_coding);
  148405. (*cinfo->coef->start_pass) (cinfo,
  148406. (master->total_passes > 1 ?
  148407. JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
  148408. (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
  148409. if (cinfo->optimize_coding) {
  148410. master->pub.call_pass_startup = FALSE;
  148411. } else {
  148412. master->pub.call_pass_startup = TRUE;
  148413. }
  148414. break;
  148415. #ifdef ENTROPY_OPT_SUPPORTED
  148416. case huff_opt_pass:
  148417. select_scan_parameters(cinfo);
  148418. per_scan_setup(cinfo);
  148419. if (cinfo->Ss != 0 || cinfo->Ah == 0 || cinfo->arith_code) {
  148420. (*cinfo->entropy->start_pass) (cinfo, TRUE);
  148421. (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST);
  148422. master->pub.call_pass_startup = FALSE;
  148423. break;
  148424. }
  148425. master->pass_type = output_pass;
  148426. master->pass_number++;
  148427. #endif
  148428. case output_pass:
  148429. if (! cinfo->optimize_coding) {
  148430. select_scan_parameters(cinfo);
  148431. per_scan_setup(cinfo);
  148432. }
  148433. (*cinfo->entropy->start_pass) (cinfo, FALSE);
  148434. (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST);
  148435. if (master->scan_number == 0)
  148436. (*cinfo->marker->write_frame_header) (cinfo);
  148437. (*cinfo->marker->write_scan_header) (cinfo);
  148438. master->pub.call_pass_startup = FALSE;
  148439. break;
  148440. default:
  148441. ERREXIT(cinfo, JERR_NOT_COMPILED);
  148442. }
  148443. master->pub.is_last_pass = (master->pass_number == master->total_passes-1);
  148444. if (cinfo->progress != NULL) {
  148445. cinfo->progress->completed_passes = master->pass_number;
  148446. cinfo->progress->total_passes = master->total_passes;
  148447. }
  148448. }
  148449. METHODDEF(void)
  148450. pass_startup (j_compress_ptr cinfo)
  148451. {
  148452. cinfo->master->call_pass_startup = FALSE; /* reset flag so call only once */
  148453. (*cinfo->marker->write_frame_header) (cinfo);
  148454. (*cinfo->marker->write_scan_header) (cinfo);
  148455. }
  148456. METHODDEF(void)
  148457. finish_pass_master (j_compress_ptr cinfo)
  148458. {
  148459. my_master_ptr master = (my_master_ptr) cinfo->master;
  148460. (*cinfo->entropy->finish_pass) (cinfo);
  148461. switch (master->pass_type) {
  148462. case main_pass:
  148463. master->pass_type = output_pass;
  148464. if (! cinfo->optimize_coding)
  148465. master->scan_number++;
  148466. break;
  148467. case huff_opt_pass:
  148468. master->pass_type = output_pass;
  148469. break;
  148470. case output_pass:
  148471. if (cinfo->optimize_coding)
  148472. master->pass_type = huff_opt_pass;
  148473. master->scan_number++;
  148474. break;
  148475. }
  148476. master->pass_number++;
  148477. }
  148478. GLOBAL(void)
  148479. jinit_c_master_control (j_compress_ptr cinfo, boolean transcode_only)
  148480. {
  148481. my_master_ptr master;
  148482. master = (my_master_ptr)
  148483. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148484. SIZEOF(my_comp_master));
  148485. cinfo->master = (struct jpeg_comp_master *) master;
  148486. master->pub.prepare_for_pass = prepare_for_pass;
  148487. master->pub.pass_startup = pass_startup;
  148488. master->pub.finish_pass = finish_pass_master;
  148489. master->pub.is_last_pass = FALSE;
  148490. initial_setup(cinfo);
  148491. if (cinfo->scan_info != NULL) {
  148492. #ifdef C_MULTISCAN_FILES_SUPPORTED
  148493. validate_script(cinfo);
  148494. #else
  148495. ERREXIT(cinfo, JERR_NOT_COMPILED);
  148496. #endif
  148497. } else {
  148498. cinfo->progressive_mode = FALSE;
  148499. cinfo->num_scans = 1;
  148500. }
  148501. if (cinfo->progressive_mode) /* TEMPORARY HACK ??? */
  148502. cinfo->optimize_coding = TRUE; /* assume default tables no good for progressive mode */
  148503. if (transcode_only) {
  148504. if (cinfo->optimize_coding)
  148505. master->pass_type = huff_opt_pass;
  148506. else
  148507. master->pass_type = output_pass;
  148508. } else {
  148509. master->pass_type = main_pass;
  148510. }
  148511. master->scan_number = 0;
  148512. master->pass_number = 0;
  148513. if (cinfo->optimize_coding)
  148514. master->total_passes = cinfo->num_scans * 2;
  148515. else
  148516. master->total_passes = cinfo->num_scans;
  148517. }
  148518. /*** End of inlined file: jcmaster.c ***/
  148519. /*** Start of inlined file: jcomapi.c ***/
  148520. #define JPEG_INTERNALS
  148521. GLOBAL(void)
  148522. jpeg_abort (j_common_ptr cinfo)
  148523. {
  148524. int pool;
  148525. if (cinfo->mem == NULL)
  148526. return;
  148527. for (pool = JPOOL_NUMPOOLS-1; pool > JPOOL_PERMANENT; pool--) {
  148528. (*cinfo->mem->free_pool) (cinfo, pool);
  148529. }
  148530. if (cinfo->is_decompressor) {
  148531. cinfo->global_state = DSTATE_START;
  148532. ((j_decompress_ptr) cinfo)->marker_list = NULL;
  148533. } else {
  148534. cinfo->global_state = CSTATE_START;
  148535. }
  148536. }
  148537. GLOBAL(void)
  148538. jpeg_destroy (j_common_ptr cinfo)
  148539. {
  148540. if (cinfo->mem != NULL)
  148541. (*cinfo->mem->self_destruct) (cinfo);
  148542. cinfo->mem = NULL; /* be safe if jpeg_destroy is called twice */
  148543. cinfo->global_state = 0; /* mark it destroyed */
  148544. }
  148545. GLOBAL(JQUANT_TBL *)
  148546. jpeg_alloc_quant_table (j_common_ptr cinfo)
  148547. {
  148548. JQUANT_TBL *tbl;
  148549. tbl = (JQUANT_TBL *)
  148550. (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JQUANT_TBL));
  148551. tbl->sent_table = FALSE; /* make sure this is false in any new table */
  148552. return tbl;
  148553. }
  148554. GLOBAL(JHUFF_TBL *)
  148555. jpeg_alloc_huff_table (j_common_ptr cinfo)
  148556. {
  148557. JHUFF_TBL *tbl;
  148558. tbl = (JHUFF_TBL *)
  148559. (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JHUFF_TBL));
  148560. tbl->sent_table = FALSE; /* make sure this is false in any new table */
  148561. return tbl;
  148562. }
  148563. /*** End of inlined file: jcomapi.c ***/
  148564. /*** Start of inlined file: jcparam.c ***/
  148565. #define JPEG_INTERNALS
  148566. GLOBAL(void)
  148567. jpeg_add_quant_table (j_compress_ptr cinfo, int which_tbl,
  148568. const unsigned int *basic_table,
  148569. int scale_factor, boolean force_baseline)
  148570. {
  148571. JQUANT_TBL ** qtblptr;
  148572. int i;
  148573. long temp;
  148574. if (cinfo->global_state != CSTATE_START)
  148575. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  148576. if (which_tbl < 0 || which_tbl >= NUM_QUANT_TBLS)
  148577. ERREXIT1(cinfo, JERR_DQT_INDEX, which_tbl);
  148578. qtblptr = & cinfo->quant_tbl_ptrs[which_tbl];
  148579. if (*qtblptr == NULL)
  148580. *qtblptr = jpeg_alloc_quant_table((j_common_ptr) cinfo);
  148581. for (i = 0; i < DCTSIZE2; i++) {
  148582. temp = ((long) basic_table[i] * scale_factor + 50L) / 100L;
  148583. if (temp <= 0L) temp = 1L;
  148584. if (temp > 32767L) temp = 32767L; /* max quantizer needed for 12 bits */
  148585. if (force_baseline && temp > 255L)
  148586. temp = 255L; /* limit to baseline range if requested */
  148587. (*qtblptr)->quantval[i] = (UINT16) temp;
  148588. }
  148589. (*qtblptr)->sent_table = FALSE;
  148590. }
  148591. GLOBAL(void)
  148592. jpeg_set_linear_quality (j_compress_ptr cinfo, int scale_factor,
  148593. boolean force_baseline)
  148594. {
  148595. static const unsigned int std_luminance_quant_tbl[DCTSIZE2] = {
  148596. 16, 11, 10, 16, 24, 40, 51, 61,
  148597. 12, 12, 14, 19, 26, 58, 60, 55,
  148598. 14, 13, 16, 24, 40, 57, 69, 56,
  148599. 14, 17, 22, 29, 51, 87, 80, 62,
  148600. 18, 22, 37, 56, 68, 109, 103, 77,
  148601. 24, 35, 55, 64, 81, 104, 113, 92,
  148602. 49, 64, 78, 87, 103, 121, 120, 101,
  148603. 72, 92, 95, 98, 112, 100, 103, 99
  148604. };
  148605. static const unsigned int std_chrominance_quant_tbl[DCTSIZE2] = {
  148606. 17, 18, 24, 47, 99, 99, 99, 99,
  148607. 18, 21, 26, 66, 99, 99, 99, 99,
  148608. 24, 26, 56, 99, 99, 99, 99, 99,
  148609. 47, 66, 99, 99, 99, 99, 99, 99,
  148610. 99, 99, 99, 99, 99, 99, 99, 99,
  148611. 99, 99, 99, 99, 99, 99, 99, 99,
  148612. 99, 99, 99, 99, 99, 99, 99, 99,
  148613. 99, 99, 99, 99, 99, 99, 99, 99
  148614. };
  148615. jpeg_add_quant_table(cinfo, 0, std_luminance_quant_tbl,
  148616. scale_factor, force_baseline);
  148617. jpeg_add_quant_table(cinfo, 1, std_chrominance_quant_tbl,
  148618. scale_factor, force_baseline);
  148619. }
  148620. GLOBAL(int)
  148621. jpeg_quality_scaling (int quality)
  148622. {
  148623. if (quality <= 0) quality = 1;
  148624. if (quality > 100) quality = 100;
  148625. if (quality < 50)
  148626. quality = 5000 / quality;
  148627. else
  148628. quality = 200 - quality*2;
  148629. return quality;
  148630. }
  148631. GLOBAL(void)
  148632. jpeg_set_quality (j_compress_ptr cinfo, int quality, boolean force_baseline)
  148633. {
  148634. quality = jpeg_quality_scaling(quality);
  148635. jpeg_set_linear_quality(cinfo, quality, force_baseline);
  148636. }
  148637. LOCAL(void)
  148638. add_huff_table (j_compress_ptr cinfo,
  148639. JHUFF_TBL **htblptr, const UINT8 *bits, const UINT8 *val)
  148640. {
  148641. int nsymbols, len;
  148642. if (*htblptr == NULL)
  148643. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  148644. MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits));
  148645. nsymbols = 0;
  148646. for (len = 1; len <= 16; len++)
  148647. nsymbols += bits[len];
  148648. if (nsymbols < 1 || nsymbols > 256)
  148649. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  148650. MEMCOPY((*htblptr)->huffval, val, nsymbols * SIZEOF(UINT8));
  148651. (*htblptr)->sent_table = FALSE;
  148652. }
  148653. LOCAL(void)
  148654. std_huff_tables (j_compress_ptr cinfo)
  148655. {
  148656. static const UINT8 bits_dc_luminance[17] =
  148657. { /* 0-base */ 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 };
  148658. static const UINT8 val_dc_luminance[] =
  148659. { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
  148660. static const UINT8 bits_dc_chrominance[17] =
  148661. { /* 0-base */ 0, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 };
  148662. static const UINT8 val_dc_chrominance[] =
  148663. { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
  148664. static const UINT8 bits_ac_luminance[17] =
  148665. { /* 0-base */ 0, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d };
  148666. static const UINT8 val_ac_luminance[] =
  148667. { 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12,
  148668. 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07,
  148669. 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08,
  148670. 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0,
  148671. 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16,
  148672. 0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28,
  148673. 0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
  148674. 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,
  148675. 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,
  148676. 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
  148677. 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79,
  148678. 0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89,
  148679. 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98,
  148680. 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
  148681. 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6,
  148682. 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5,
  148683. 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4,
  148684. 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2,
  148685. 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea,
  148686. 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
  148687. 0xf9, 0xfa };
  148688. static const UINT8 bits_ac_chrominance[17] =
  148689. { /* 0-base */ 0, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77 };
  148690. static const UINT8 val_ac_chrominance[] =
  148691. { 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21,
  148692. 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71,
  148693. 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91,
  148694. 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0,
  148695. 0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34,
  148696. 0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26,
  148697. 0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38,
  148698. 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
  148699. 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
  148700. 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
  148701. 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
  148702. 0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
  148703. 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96,
  148704. 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5,
  148705. 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4,
  148706. 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3,
  148707. 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2,
  148708. 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda,
  148709. 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9,
  148710. 0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
  148711. 0xf9, 0xfa };
  148712. add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[0],
  148713. bits_dc_luminance, val_dc_luminance);
  148714. add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[0],
  148715. bits_ac_luminance, val_ac_luminance);
  148716. add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[1],
  148717. bits_dc_chrominance, val_dc_chrominance);
  148718. add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[1],
  148719. bits_ac_chrominance, val_ac_chrominance);
  148720. }
  148721. GLOBAL(void)
  148722. jpeg_set_defaults (j_compress_ptr cinfo)
  148723. {
  148724. int i;
  148725. if (cinfo->global_state != CSTATE_START)
  148726. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  148727. if (cinfo->comp_info == NULL)
  148728. cinfo->comp_info = (jpeg_component_info *)
  148729. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  148730. MAX_COMPONENTS * SIZEOF(jpeg_component_info));
  148731. cinfo->data_precision = BITS_IN_JSAMPLE;
  148732. jpeg_set_quality(cinfo, 75, TRUE);
  148733. std_huff_tables(cinfo);
  148734. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  148735. cinfo->arith_dc_L[i] = 0;
  148736. cinfo->arith_dc_U[i] = 1;
  148737. cinfo->arith_ac_K[i] = 5;
  148738. }
  148739. cinfo->scan_info = NULL;
  148740. cinfo->num_scans = 0;
  148741. cinfo->raw_data_in = FALSE;
  148742. cinfo->arith_code = FALSE;
  148743. cinfo->optimize_coding = FALSE;
  148744. if (cinfo->data_precision > 8)
  148745. cinfo->optimize_coding = TRUE;
  148746. cinfo->CCIR601_sampling = FALSE;
  148747. cinfo->smoothing_factor = 0;
  148748. cinfo->dct_method = JDCT_DEFAULT;
  148749. cinfo->restart_interval = 0;
  148750. cinfo->restart_in_rows = 0;
  148751. cinfo->JFIF_major_version = 1; /* Default JFIF version = 1.01 */
  148752. cinfo->JFIF_minor_version = 1;
  148753. cinfo->density_unit = 0; /* Pixel size is unknown by default */
  148754. cinfo->X_density = 1; /* Pixel aspect ratio is square by default */
  148755. cinfo->Y_density = 1;
  148756. jpeg_default_colorspace(cinfo);
  148757. }
  148758. GLOBAL(void)
  148759. jpeg_default_colorspace (j_compress_ptr cinfo)
  148760. {
  148761. switch (cinfo->in_color_space) {
  148762. case JCS_GRAYSCALE:
  148763. jpeg_set_colorspace(cinfo, JCS_GRAYSCALE);
  148764. break;
  148765. case JCS_RGB:
  148766. jpeg_set_colorspace(cinfo, JCS_YCbCr);
  148767. break;
  148768. case JCS_YCbCr:
  148769. jpeg_set_colorspace(cinfo, JCS_YCbCr);
  148770. break;
  148771. case JCS_CMYK:
  148772. jpeg_set_colorspace(cinfo, JCS_CMYK); /* By default, no translation */
  148773. break;
  148774. case JCS_YCCK:
  148775. jpeg_set_colorspace(cinfo, JCS_YCCK);
  148776. break;
  148777. case JCS_UNKNOWN:
  148778. jpeg_set_colorspace(cinfo, JCS_UNKNOWN);
  148779. break;
  148780. default:
  148781. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  148782. }
  148783. }
  148784. GLOBAL(void)
  148785. jpeg_set_colorspace (j_compress_ptr cinfo, J_COLOR_SPACE colorspace)
  148786. {
  148787. jpeg_component_info * compptr;
  148788. int ci;
  148789. #define SET_COMP(index,id,hsamp,vsamp,quant,dctbl,actbl) \
  148790. (compptr = &cinfo->comp_info[index], \
  148791. compptr->component_id = (id), \
  148792. compptr->h_samp_factor = (hsamp), \
  148793. compptr->v_samp_factor = (vsamp), \
  148794. compptr->quant_tbl_no = (quant), \
  148795. compptr->dc_tbl_no = (dctbl), \
  148796. compptr->ac_tbl_no = (actbl) )
  148797. if (cinfo->global_state != CSTATE_START)
  148798. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  148799. cinfo->jpeg_color_space = colorspace;
  148800. cinfo->write_JFIF_header = FALSE; /* No marker for non-JFIF colorspaces */
  148801. cinfo->write_Adobe_marker = FALSE; /* write no Adobe marker by default */
  148802. switch (colorspace) {
  148803. case JCS_GRAYSCALE:
  148804. cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
  148805. cinfo->num_components = 1;
  148806. SET_COMP(0, 1, 1,1, 0, 0,0);
  148807. break;
  148808. case JCS_RGB:
  148809. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag RGB */
  148810. cinfo->num_components = 3;
  148811. SET_COMP(0, 0x52 /* 'R' */, 1,1, 0, 0,0);
  148812. SET_COMP(1, 0x47 /* 'G' */, 1,1, 0, 0,0);
  148813. SET_COMP(2, 0x42 /* 'B' */, 1,1, 0, 0,0);
  148814. break;
  148815. case JCS_YCbCr:
  148816. cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
  148817. cinfo->num_components = 3;
  148818. SET_COMP(0, 1, 2,2, 0, 0,0);
  148819. SET_COMP(1, 2, 1,1, 1, 1,1);
  148820. SET_COMP(2, 3, 1,1, 1, 1,1);
  148821. break;
  148822. case JCS_CMYK:
  148823. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag CMYK */
  148824. cinfo->num_components = 4;
  148825. SET_COMP(0, 0x43 /* 'C' */, 1,1, 0, 0,0);
  148826. SET_COMP(1, 0x4D /* 'M' */, 1,1, 0, 0,0);
  148827. SET_COMP(2, 0x59 /* 'Y' */, 1,1, 0, 0,0);
  148828. SET_COMP(3, 0x4B /* 'K' */, 1,1, 0, 0,0);
  148829. break;
  148830. case JCS_YCCK:
  148831. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag YCCK */
  148832. cinfo->num_components = 4;
  148833. SET_COMP(0, 1, 2,2, 0, 0,0);
  148834. SET_COMP(1, 2, 1,1, 1, 1,1);
  148835. SET_COMP(2, 3, 1,1, 1, 1,1);
  148836. SET_COMP(3, 4, 2,2, 0, 0,0);
  148837. break;
  148838. case JCS_UNKNOWN:
  148839. cinfo->num_components = cinfo->input_components;
  148840. if (cinfo->num_components < 1 || cinfo->num_components > MAX_COMPONENTS)
  148841. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  148842. MAX_COMPONENTS);
  148843. for (ci = 0; ci < cinfo->num_components; ci++) {
  148844. SET_COMP(ci, ci, 1,1, 0, 0,0);
  148845. }
  148846. break;
  148847. default:
  148848. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  148849. }
  148850. }
  148851. #ifdef C_PROGRESSIVE_SUPPORTED
  148852. LOCAL(jpeg_scan_info *)
  148853. fill_a_scan (jpeg_scan_info * scanptr, int ci,
  148854. int Ss, int Se, int Ah, int Al)
  148855. {
  148856. scanptr->comps_in_scan = 1;
  148857. scanptr->component_index[0] = ci;
  148858. scanptr->Ss = Ss;
  148859. scanptr->Se = Se;
  148860. scanptr->Ah = Ah;
  148861. scanptr->Al = Al;
  148862. scanptr++;
  148863. return scanptr;
  148864. }
  148865. LOCAL(jpeg_scan_info *)
  148866. fill_scans (jpeg_scan_info * scanptr, int ncomps,
  148867. int Ss, int Se, int Ah, int Al)
  148868. {
  148869. int ci;
  148870. for (ci = 0; ci < ncomps; ci++) {
  148871. scanptr->comps_in_scan = 1;
  148872. scanptr->component_index[0] = ci;
  148873. scanptr->Ss = Ss;
  148874. scanptr->Se = Se;
  148875. scanptr->Ah = Ah;
  148876. scanptr->Al = Al;
  148877. scanptr++;
  148878. }
  148879. return scanptr;
  148880. }
  148881. LOCAL(jpeg_scan_info *)
  148882. fill_dc_scans (jpeg_scan_info * scanptr, int ncomps, int Ah, int Al)
  148883. {
  148884. int ci;
  148885. if (ncomps <= MAX_COMPS_IN_SCAN) {
  148886. scanptr->comps_in_scan = ncomps;
  148887. for (ci = 0; ci < ncomps; ci++)
  148888. scanptr->component_index[ci] = ci;
  148889. scanptr->Ss = scanptr->Se = 0;
  148890. scanptr->Ah = Ah;
  148891. scanptr->Al = Al;
  148892. scanptr++;
  148893. } else {
  148894. scanptr = fill_scans(scanptr, ncomps, 0, 0, Ah, Al);
  148895. }
  148896. return scanptr;
  148897. }
  148898. GLOBAL(void)
  148899. jpeg_simple_progression (j_compress_ptr cinfo)
  148900. {
  148901. int ncomps = cinfo->num_components;
  148902. int nscans;
  148903. jpeg_scan_info * scanptr;
  148904. if (cinfo->global_state != CSTATE_START)
  148905. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  148906. if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
  148907. nscans = 10;
  148908. } else {
  148909. if (ncomps > MAX_COMPS_IN_SCAN)
  148910. nscans = 6 * ncomps; /* 2 DC + 4 AC scans per component */
  148911. else
  148912. nscans = 2 + 4 * ncomps; /* 2 DC scans; 4 AC scans per component */
  148913. }
  148914. if (cinfo->script_space == NULL || cinfo->script_space_size < nscans) {
  148915. cinfo->script_space_size = MAX(nscans, 10);
  148916. cinfo->script_space = (jpeg_scan_info *)
  148917. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  148918. cinfo->script_space_size * SIZEOF(jpeg_scan_info));
  148919. }
  148920. scanptr = cinfo->script_space;
  148921. cinfo->scan_info = scanptr;
  148922. cinfo->num_scans = nscans;
  148923. if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
  148924. scanptr = fill_dc_scans(scanptr, ncomps, 0, 1);
  148925. scanptr = fill_a_scan(scanptr, 0, 1, 5, 0, 2);
  148926. scanptr = fill_a_scan(scanptr, 2, 1, 63, 0, 1);
  148927. scanptr = fill_a_scan(scanptr, 1, 1, 63, 0, 1);
  148928. scanptr = fill_a_scan(scanptr, 0, 6, 63, 0, 2);
  148929. scanptr = fill_a_scan(scanptr, 0, 1, 63, 2, 1);
  148930. scanptr = fill_dc_scans(scanptr, ncomps, 1, 0);
  148931. scanptr = fill_a_scan(scanptr, 2, 1, 63, 1, 0);
  148932. scanptr = fill_a_scan(scanptr, 1, 1, 63, 1, 0);
  148933. scanptr = fill_a_scan(scanptr, 0, 1, 63, 1, 0);
  148934. } else {
  148935. scanptr = fill_dc_scans(scanptr, ncomps, 0, 1);
  148936. scanptr = fill_scans(scanptr, ncomps, 1, 5, 0, 2);
  148937. scanptr = fill_scans(scanptr, ncomps, 6, 63, 0, 2);
  148938. scanptr = fill_scans(scanptr, ncomps, 1, 63, 2, 1);
  148939. scanptr = fill_dc_scans(scanptr, ncomps, 1, 0);
  148940. scanptr = fill_scans(scanptr, ncomps, 1, 63, 1, 0);
  148941. }
  148942. }
  148943. #endif /* C_PROGRESSIVE_SUPPORTED */
  148944. /*** End of inlined file: jcparam.c ***/
  148945. /*** Start of inlined file: jcphuff.c ***/
  148946. #define JPEG_INTERNALS
  148947. #ifdef C_PROGRESSIVE_SUPPORTED
  148948. typedef struct {
  148949. struct jpeg_entropy_encoder pub; /* public fields */
  148950. boolean gather_statistics;
  148951. JOCTET * next_output_byte; /* => next byte to write in buffer */
  148952. size_t free_in_buffer; /* # of byte spaces remaining in buffer */
  148953. INT32 put_buffer; /* current bit-accumulation buffer */
  148954. int put_bits; /* # of bits now in it */
  148955. j_compress_ptr cinfo; /* link to cinfo (needed for dump_buffer) */
  148956. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  148957. int ac_tbl_no; /* the table number of the single component */
  148958. unsigned int EOBRUN; /* run length of EOBs */
  148959. unsigned int BE; /* # of buffered correction bits before MCU */
  148960. char * bit_buffer; /* buffer for correction bits (1 per char) */
  148961. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  148962. int next_restart_num; /* next restart number to write (0-7) */
  148963. c_derived_tbl * derived_tbls[NUM_HUFF_TBLS];
  148964. long * count_ptrs[NUM_HUFF_TBLS];
  148965. } phuff_entropy_encoder;
  148966. typedef phuff_entropy_encoder * phuff_entropy_ptr;
  148967. #define MAX_CORR_BITS 1000 /* Max # of correction bits I can buffer */
  148968. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  148969. #define ISHIFT_TEMPS int ishift_temp;
  148970. #define IRIGHT_SHIFT(x,shft) \
  148971. ((ishift_temp = (x)) < 0 ? \
  148972. (ishift_temp >> (shft)) | ((~0) << (16-(shft))) : \
  148973. (ishift_temp >> (shft)))
  148974. #else
  148975. #define ISHIFT_TEMPS
  148976. #define IRIGHT_SHIFT(x,shft) ((x) >> (shft))
  148977. #endif
  148978. METHODDEF(boolean) encode_mcu_DC_first JPP((j_compress_ptr cinfo,
  148979. JBLOCKROW *MCU_data));
  148980. METHODDEF(boolean) encode_mcu_AC_first JPP((j_compress_ptr cinfo,
  148981. JBLOCKROW *MCU_data));
  148982. METHODDEF(boolean) encode_mcu_DC_refine JPP((j_compress_ptr cinfo,
  148983. JBLOCKROW *MCU_data));
  148984. METHODDEF(boolean) encode_mcu_AC_refine JPP((j_compress_ptr cinfo,
  148985. JBLOCKROW *MCU_data));
  148986. METHODDEF(void) finish_pass_phuff JPP((j_compress_ptr cinfo));
  148987. METHODDEF(void) finish_pass_gather_phuff JPP((j_compress_ptr cinfo));
  148988. METHODDEF(void)
  148989. start_pass_phuff (j_compress_ptr cinfo, boolean gather_statistics)
  148990. {
  148991. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  148992. boolean is_DC_band;
  148993. int ci, tbl;
  148994. jpeg_component_info * compptr;
  148995. entropy->cinfo = cinfo;
  148996. entropy->gather_statistics = gather_statistics;
  148997. is_DC_band = (cinfo->Ss == 0);
  148998. if (cinfo->Ah == 0) {
  148999. if (is_DC_band)
  149000. entropy->pub.encode_mcu = encode_mcu_DC_first;
  149001. else
  149002. entropy->pub.encode_mcu = encode_mcu_AC_first;
  149003. } else {
  149004. if (is_DC_band)
  149005. entropy->pub.encode_mcu = encode_mcu_DC_refine;
  149006. else {
  149007. entropy->pub.encode_mcu = encode_mcu_AC_refine;
  149008. if (entropy->bit_buffer == NULL)
  149009. entropy->bit_buffer = (char *)
  149010. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149011. MAX_CORR_BITS * SIZEOF(char));
  149012. }
  149013. }
  149014. if (gather_statistics)
  149015. entropy->pub.finish_pass = finish_pass_gather_phuff;
  149016. else
  149017. entropy->pub.finish_pass = finish_pass_phuff;
  149018. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  149019. compptr = cinfo->cur_comp_info[ci];
  149020. entropy->last_dc_val[ci] = 0;
  149021. if (is_DC_band) {
  149022. if (cinfo->Ah != 0) /* DC refinement needs no table */
  149023. continue;
  149024. tbl = compptr->dc_tbl_no;
  149025. } else {
  149026. entropy->ac_tbl_no = tbl = compptr->ac_tbl_no;
  149027. }
  149028. if (gather_statistics) {
  149029. if (tbl < 0 || tbl >= NUM_HUFF_TBLS)
  149030. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tbl);
  149031. if (entropy->count_ptrs[tbl] == NULL)
  149032. entropy->count_ptrs[tbl] = (long *)
  149033. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149034. 257 * SIZEOF(long));
  149035. MEMZERO(entropy->count_ptrs[tbl], 257 * SIZEOF(long));
  149036. } else {
  149037. jpeg_make_c_derived_tbl(cinfo, is_DC_band, tbl,
  149038. & entropy->derived_tbls[tbl]);
  149039. }
  149040. }
  149041. entropy->EOBRUN = 0;
  149042. entropy->BE = 0;
  149043. entropy->put_buffer = 0;
  149044. entropy->put_bits = 0;
  149045. entropy->restarts_to_go = cinfo->restart_interval;
  149046. entropy->next_restart_num = 0;
  149047. }
  149048. #define emit_byte(entropy,val) \
  149049. { *(entropy)->next_output_byte++ = (JOCTET) (val); \
  149050. if (--(entropy)->free_in_buffer == 0) \
  149051. dump_buffer_p(entropy); }
  149052. LOCAL(void)
  149053. dump_buffer_p (phuff_entropy_ptr entropy)
  149054. {
  149055. struct jpeg_destination_mgr * dest = entropy->cinfo->dest;
  149056. if (! (*dest->empty_output_buffer) (entropy->cinfo))
  149057. ERREXIT(entropy->cinfo, JERR_CANT_SUSPEND);
  149058. entropy->next_output_byte = dest->next_output_byte;
  149059. entropy->free_in_buffer = dest->free_in_buffer;
  149060. }
  149061. INLINE
  149062. LOCAL(void)
  149063. emit_bits_p (phuff_entropy_ptr entropy, unsigned int code, int size)
  149064. {
  149065. register INT32 put_buffer = (INT32) code;
  149066. register int put_bits = entropy->put_bits;
  149067. if (size == 0)
  149068. ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);
  149069. if (entropy->gather_statistics)
  149070. return; /* do nothing if we're only getting stats */
  149071. put_buffer &= (((INT32) 1)<<size) - 1; /* mask off any extra bits in code */
  149072. put_bits += size; /* new number of bits in buffer */
  149073. put_buffer <<= 24 - put_bits; /* align incoming bits */
  149074. put_buffer |= entropy->put_buffer; /* and merge with old buffer contents */
  149075. while (put_bits >= 8) {
  149076. int c = (int) ((put_buffer >> 16) & 0xFF);
  149077. emit_byte(entropy, c);
  149078. if (c == 0xFF) { /* need to stuff a zero byte? */
  149079. emit_byte(entropy, 0);
  149080. }
  149081. put_buffer <<= 8;
  149082. put_bits -= 8;
  149083. }
  149084. entropy->put_buffer = put_buffer; /* update variables */
  149085. entropy->put_bits = put_bits;
  149086. }
  149087. LOCAL(void)
  149088. flush_bits_p (phuff_entropy_ptr entropy)
  149089. {
  149090. emit_bits_p(entropy, 0x7F, 7); /* fill any partial byte with ones */
  149091. entropy->put_buffer = 0; /* and reset bit-buffer to empty */
  149092. entropy->put_bits = 0;
  149093. }
  149094. INLINE
  149095. LOCAL(void)
  149096. emit_symbol (phuff_entropy_ptr entropy, int tbl_no, int symbol)
  149097. {
  149098. if (entropy->gather_statistics)
  149099. entropy->count_ptrs[tbl_no][symbol]++;
  149100. else {
  149101. c_derived_tbl * tbl = entropy->derived_tbls[tbl_no];
  149102. emit_bits_p(entropy, tbl->ehufco[symbol], tbl->ehufsi[symbol]);
  149103. }
  149104. }
  149105. LOCAL(void)
  149106. emit_buffered_bits (phuff_entropy_ptr entropy, char * bufstart,
  149107. unsigned int nbits)
  149108. {
  149109. if (entropy->gather_statistics)
  149110. return; /* no real work */
  149111. while (nbits > 0) {
  149112. emit_bits_p(entropy, (unsigned int) (*bufstart), 1);
  149113. bufstart++;
  149114. nbits--;
  149115. }
  149116. }
  149117. LOCAL(void)
  149118. emit_eobrun (phuff_entropy_ptr entropy)
  149119. {
  149120. register int temp, nbits;
  149121. if (entropy->EOBRUN > 0) { /* if there is any pending EOBRUN */
  149122. temp = entropy->EOBRUN;
  149123. nbits = 0;
  149124. while ((temp >>= 1))
  149125. nbits++;
  149126. if (nbits > 14)
  149127. ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);
  149128. emit_symbol(entropy, entropy->ac_tbl_no, nbits << 4);
  149129. if (nbits)
  149130. emit_bits_p(entropy, entropy->EOBRUN, nbits);
  149131. entropy->EOBRUN = 0;
  149132. emit_buffered_bits(entropy, entropy->bit_buffer, entropy->BE);
  149133. entropy->BE = 0;
  149134. }
  149135. }
  149136. LOCAL(void)
  149137. emit_restart_p (phuff_entropy_ptr entropy, int restart_num)
  149138. {
  149139. int ci;
  149140. emit_eobrun(entropy);
  149141. if (! entropy->gather_statistics) {
  149142. flush_bits_p(entropy);
  149143. emit_byte(entropy, 0xFF);
  149144. emit_byte(entropy, JPEG_RST0 + restart_num);
  149145. }
  149146. if (entropy->cinfo->Ss == 0) {
  149147. for (ci = 0; ci < entropy->cinfo->comps_in_scan; ci++)
  149148. entropy->last_dc_val[ci] = 0;
  149149. } else {
  149150. entropy->EOBRUN = 0;
  149151. entropy->BE = 0;
  149152. }
  149153. }
  149154. METHODDEF(boolean)
  149155. encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149156. {
  149157. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149158. register int temp, temp2;
  149159. register int nbits;
  149160. int blkn, ci;
  149161. int Al = cinfo->Al;
  149162. JBLOCKROW block;
  149163. jpeg_component_info * compptr;
  149164. ISHIFT_TEMPS
  149165. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149166. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149167. if (cinfo->restart_interval)
  149168. if (entropy->restarts_to_go == 0)
  149169. emit_restart_p(entropy, entropy->next_restart_num);
  149170. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  149171. block = MCU_data[blkn];
  149172. ci = cinfo->MCU_membership[blkn];
  149173. compptr = cinfo->cur_comp_info[ci];
  149174. temp2 = IRIGHT_SHIFT((int) ((*block)[0]), Al);
  149175. temp = temp2 - entropy->last_dc_val[ci];
  149176. entropy->last_dc_val[ci] = temp2;
  149177. temp2 = temp;
  149178. if (temp < 0) {
  149179. temp = -temp; /* temp is abs value of input */
  149180. temp2--;
  149181. }
  149182. nbits = 0;
  149183. while (temp) {
  149184. nbits++;
  149185. temp >>= 1;
  149186. }
  149187. if (nbits > MAX_COEF_BITS+1)
  149188. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  149189. emit_symbol(entropy, compptr->dc_tbl_no, nbits);
  149190. if (nbits) /* emit_bits rejects calls with size 0 */
  149191. emit_bits_p(entropy, (unsigned int) temp2, nbits);
  149192. }
  149193. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149194. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149195. if (cinfo->restart_interval) {
  149196. if (entropy->restarts_to_go == 0) {
  149197. entropy->restarts_to_go = cinfo->restart_interval;
  149198. entropy->next_restart_num++;
  149199. entropy->next_restart_num &= 7;
  149200. }
  149201. entropy->restarts_to_go--;
  149202. }
  149203. return TRUE;
  149204. }
  149205. METHODDEF(boolean)
  149206. encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149207. {
  149208. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149209. register int temp, temp2;
  149210. register int nbits;
  149211. register int r, k;
  149212. int Se = cinfo->Se;
  149213. int Al = cinfo->Al;
  149214. JBLOCKROW block;
  149215. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149216. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149217. if (cinfo->restart_interval)
  149218. if (entropy->restarts_to_go == 0)
  149219. emit_restart_p(entropy, entropy->next_restart_num);
  149220. block = MCU_data[0];
  149221. r = 0; /* r = run length of zeros */
  149222. for (k = cinfo->Ss; k <= Se; k++) {
  149223. if ((temp = (*block)[jpeg_natural_order[k]]) == 0) {
  149224. r++;
  149225. continue;
  149226. }
  149227. if (temp < 0) {
  149228. temp = -temp; /* temp is abs value of input */
  149229. temp >>= Al; /* apply the point transform */
  149230. temp2 = ~temp;
  149231. } else {
  149232. temp >>= Al; /* apply the point transform */
  149233. temp2 = temp;
  149234. }
  149235. if (temp == 0) {
  149236. r++;
  149237. continue;
  149238. }
  149239. if (entropy->EOBRUN > 0)
  149240. emit_eobrun(entropy);
  149241. while (r > 15) {
  149242. emit_symbol(entropy, entropy->ac_tbl_no, 0xF0);
  149243. r -= 16;
  149244. }
  149245. nbits = 1; /* there must be at least one 1 bit */
  149246. while ((temp >>= 1))
  149247. nbits++;
  149248. if (nbits > MAX_COEF_BITS)
  149249. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  149250. emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + nbits);
  149251. emit_bits_p(entropy, (unsigned int) temp2, nbits);
  149252. r = 0; /* reset zero run length */
  149253. }
  149254. if (r > 0) { /* If there are trailing zeroes, */
  149255. entropy->EOBRUN++; /* count an EOB */
  149256. if (entropy->EOBRUN == 0x7FFF)
  149257. emit_eobrun(entropy); /* force it out to avoid overflow */
  149258. }
  149259. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149260. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149261. if (cinfo->restart_interval) {
  149262. if (entropy->restarts_to_go == 0) {
  149263. entropy->restarts_to_go = cinfo->restart_interval;
  149264. entropy->next_restart_num++;
  149265. entropy->next_restart_num &= 7;
  149266. }
  149267. entropy->restarts_to_go--;
  149268. }
  149269. return TRUE;
  149270. }
  149271. METHODDEF(boolean)
  149272. encode_mcu_DC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149273. {
  149274. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149275. register int temp;
  149276. int blkn;
  149277. int Al = cinfo->Al;
  149278. JBLOCKROW block;
  149279. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149280. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149281. if (cinfo->restart_interval)
  149282. if (entropy->restarts_to_go == 0)
  149283. emit_restart_p(entropy, entropy->next_restart_num);
  149284. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  149285. block = MCU_data[blkn];
  149286. temp = (*block)[0];
  149287. emit_bits_p(entropy, (unsigned int) (temp >> Al), 1);
  149288. }
  149289. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149290. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149291. if (cinfo->restart_interval) {
  149292. if (entropy->restarts_to_go == 0) {
  149293. entropy->restarts_to_go = cinfo->restart_interval;
  149294. entropy->next_restart_num++;
  149295. entropy->next_restart_num &= 7;
  149296. }
  149297. entropy->restarts_to_go--;
  149298. }
  149299. return TRUE;
  149300. }
  149301. METHODDEF(boolean)
  149302. encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149303. {
  149304. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149305. register int temp;
  149306. register int r, k;
  149307. int EOB;
  149308. char *BR_buffer;
  149309. unsigned int BR;
  149310. int Se = cinfo->Se;
  149311. int Al = cinfo->Al;
  149312. JBLOCKROW block;
  149313. int absvalues[DCTSIZE2];
  149314. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149315. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149316. if (cinfo->restart_interval)
  149317. if (entropy->restarts_to_go == 0)
  149318. emit_restart_p(entropy, entropy->next_restart_num);
  149319. block = MCU_data[0];
  149320. EOB = 0;
  149321. for (k = cinfo->Ss; k <= Se; k++) {
  149322. temp = (*block)[jpeg_natural_order[k]];
  149323. if (temp < 0)
  149324. temp = -temp; /* temp is abs value of input */
  149325. temp >>= Al; /* apply the point transform */
  149326. absvalues[k] = temp; /* save abs value for main pass */
  149327. if (temp == 1)
  149328. EOB = k; /* EOB = index of last newly-nonzero coef */
  149329. }
  149330. r = 0; /* r = run length of zeros */
  149331. BR = 0; /* BR = count of buffered bits added now */
  149332. BR_buffer = entropy->bit_buffer + entropy->BE; /* Append bits to buffer */
  149333. for (k = cinfo->Ss; k <= Se; k++) {
  149334. if ((temp = absvalues[k]) == 0) {
  149335. r++;
  149336. continue;
  149337. }
  149338. while (r > 15 && k <= EOB) {
  149339. emit_eobrun(entropy);
  149340. emit_symbol(entropy, entropy->ac_tbl_no, 0xF0);
  149341. r -= 16;
  149342. emit_buffered_bits(entropy, BR_buffer, BR);
  149343. BR_buffer = entropy->bit_buffer; /* BE bits are gone now */
  149344. BR = 0;
  149345. }
  149346. if (temp > 1) {
  149347. BR_buffer[BR++] = (char) (temp & 1);
  149348. continue;
  149349. }
  149350. emit_eobrun(entropy);
  149351. emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + 1);
  149352. temp = ((*block)[jpeg_natural_order[k]] < 0) ? 0 : 1;
  149353. emit_bits_p(entropy, (unsigned int) temp, 1);
  149354. emit_buffered_bits(entropy, BR_buffer, BR);
  149355. BR_buffer = entropy->bit_buffer; /* BE bits are gone now */
  149356. BR = 0;
  149357. r = 0; /* reset zero run length */
  149358. }
  149359. if (r > 0 || BR > 0) { /* If there are trailing zeroes, */
  149360. entropy->EOBRUN++; /* count an EOB */
  149361. entropy->BE += BR; /* concat my correction bits to older ones */
  149362. if (entropy->EOBRUN == 0x7FFF || entropy->BE > (MAX_CORR_BITS-DCTSIZE2+1))
  149363. emit_eobrun(entropy);
  149364. }
  149365. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149366. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149367. if (cinfo->restart_interval) {
  149368. if (entropy->restarts_to_go == 0) {
  149369. entropy->restarts_to_go = cinfo->restart_interval;
  149370. entropy->next_restart_num++;
  149371. entropy->next_restart_num &= 7;
  149372. }
  149373. entropy->restarts_to_go--;
  149374. }
  149375. return TRUE;
  149376. }
  149377. METHODDEF(void)
  149378. finish_pass_phuff (j_compress_ptr cinfo)
  149379. {
  149380. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149381. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149382. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149383. emit_eobrun(entropy);
  149384. flush_bits_p(entropy);
  149385. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149386. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149387. }
  149388. METHODDEF(void)
  149389. finish_pass_gather_phuff (j_compress_ptr cinfo)
  149390. {
  149391. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149392. boolean is_DC_band;
  149393. int ci, tbl;
  149394. jpeg_component_info * compptr;
  149395. JHUFF_TBL **htblptr;
  149396. boolean did[NUM_HUFF_TBLS];
  149397. emit_eobrun(entropy);
  149398. is_DC_band = (cinfo->Ss == 0);
  149399. MEMZERO(did, SIZEOF(did));
  149400. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  149401. compptr = cinfo->cur_comp_info[ci];
  149402. if (is_DC_band) {
  149403. if (cinfo->Ah != 0) /* DC refinement needs no table */
  149404. continue;
  149405. tbl = compptr->dc_tbl_no;
  149406. } else {
  149407. tbl = compptr->ac_tbl_no;
  149408. }
  149409. if (! did[tbl]) {
  149410. if (is_DC_band)
  149411. htblptr = & cinfo->dc_huff_tbl_ptrs[tbl];
  149412. else
  149413. htblptr = & cinfo->ac_huff_tbl_ptrs[tbl];
  149414. if (*htblptr == NULL)
  149415. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  149416. jpeg_gen_optimal_table(cinfo, *htblptr, entropy->count_ptrs[tbl]);
  149417. did[tbl] = TRUE;
  149418. }
  149419. }
  149420. }
  149421. GLOBAL(void)
  149422. jinit_phuff_encoder (j_compress_ptr cinfo)
  149423. {
  149424. phuff_entropy_ptr entropy;
  149425. int i;
  149426. entropy = (phuff_entropy_ptr)
  149427. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149428. SIZEOF(phuff_entropy_encoder));
  149429. cinfo->entropy = (struct jpeg_entropy_encoder *) entropy;
  149430. entropy->pub.start_pass = start_pass_phuff;
  149431. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  149432. entropy->derived_tbls[i] = NULL;
  149433. entropy->count_ptrs[i] = NULL;
  149434. }
  149435. entropy->bit_buffer = NULL; /* needed only in AC refinement scan */
  149436. }
  149437. #endif /* C_PROGRESSIVE_SUPPORTED */
  149438. /*** End of inlined file: jcphuff.c ***/
  149439. /*** Start of inlined file: jcprepct.c ***/
  149440. #define JPEG_INTERNALS
  149441. #ifdef INPUT_SMOOTHING_SUPPORTED
  149442. #define CONTEXT_ROWS_SUPPORTED
  149443. #endif
  149444. typedef struct {
  149445. struct jpeg_c_prep_controller pub; /* public fields */
  149446. JSAMPARRAY color_buf[MAX_COMPONENTS];
  149447. JDIMENSION rows_to_go; /* counts rows remaining in source image */
  149448. int next_buf_row; /* index of next row to store in color_buf */
  149449. #ifdef CONTEXT_ROWS_SUPPORTED /* only needed for context case */
  149450. int this_row_group; /* starting row index of group to process */
  149451. int next_buf_stop; /* downsample when we reach this index */
  149452. #endif
  149453. } my_prep_controller;
  149454. typedef my_prep_controller * my_prep_ptr;
  149455. METHODDEF(void)
  149456. start_pass_prep (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  149457. {
  149458. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149459. if (pass_mode != JBUF_PASS_THRU)
  149460. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  149461. prep->rows_to_go = cinfo->image_height;
  149462. prep->next_buf_row = 0;
  149463. #ifdef CONTEXT_ROWS_SUPPORTED
  149464. prep->this_row_group = 0;
  149465. prep->next_buf_stop = 2 * cinfo->max_v_samp_factor;
  149466. #endif
  149467. }
  149468. LOCAL(void)
  149469. expand_bottom_edge (JSAMPARRAY image_data, JDIMENSION num_cols,
  149470. int input_rows, int output_rows)
  149471. {
  149472. register int row;
  149473. for (row = input_rows; row < output_rows; row++) {
  149474. jcopy_sample_rows(image_data, input_rows-1, image_data, row,
  149475. 1, num_cols);
  149476. }
  149477. }
  149478. METHODDEF(void)
  149479. pre_process_data (j_compress_ptr cinfo,
  149480. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  149481. JDIMENSION in_rows_avail,
  149482. JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
  149483. JDIMENSION out_row_groups_avail)
  149484. {
  149485. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149486. int numrows, ci;
  149487. JDIMENSION inrows;
  149488. jpeg_component_info * compptr;
  149489. while (*in_row_ctr < in_rows_avail &&
  149490. *out_row_group_ctr < out_row_groups_avail) {
  149491. inrows = in_rows_avail - *in_row_ctr;
  149492. numrows = cinfo->max_v_samp_factor - prep->next_buf_row;
  149493. numrows = (int) MIN((JDIMENSION) numrows, inrows);
  149494. (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
  149495. prep->color_buf,
  149496. (JDIMENSION) prep->next_buf_row,
  149497. numrows);
  149498. *in_row_ctr += numrows;
  149499. prep->next_buf_row += numrows;
  149500. prep->rows_to_go -= numrows;
  149501. if (prep->rows_to_go == 0 &&
  149502. prep->next_buf_row < cinfo->max_v_samp_factor) {
  149503. for (ci = 0; ci < cinfo->num_components; ci++) {
  149504. expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
  149505. prep->next_buf_row, cinfo->max_v_samp_factor);
  149506. }
  149507. prep->next_buf_row = cinfo->max_v_samp_factor;
  149508. }
  149509. if (prep->next_buf_row == cinfo->max_v_samp_factor) {
  149510. (*cinfo->downsample->downsample) (cinfo,
  149511. prep->color_buf, (JDIMENSION) 0,
  149512. output_buf, *out_row_group_ctr);
  149513. prep->next_buf_row = 0;
  149514. (*out_row_group_ctr)++;
  149515. }
  149516. if (prep->rows_to_go == 0 &&
  149517. *out_row_group_ctr < out_row_groups_avail) {
  149518. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149519. ci++, compptr++) {
  149520. expand_bottom_edge(output_buf[ci],
  149521. compptr->width_in_blocks * DCTSIZE,
  149522. (int) (*out_row_group_ctr * compptr->v_samp_factor),
  149523. (int) (out_row_groups_avail * compptr->v_samp_factor));
  149524. }
  149525. *out_row_group_ctr = out_row_groups_avail;
  149526. break; /* can exit outer loop without test */
  149527. }
  149528. }
  149529. }
  149530. #ifdef CONTEXT_ROWS_SUPPORTED
  149531. METHODDEF(void)
  149532. pre_process_context (j_compress_ptr cinfo,
  149533. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  149534. JDIMENSION in_rows_avail,
  149535. JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
  149536. JDIMENSION out_row_groups_avail)
  149537. {
  149538. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149539. int numrows, ci;
  149540. int buf_height = cinfo->max_v_samp_factor * 3;
  149541. JDIMENSION inrows;
  149542. while (*out_row_group_ctr < out_row_groups_avail) {
  149543. if (*in_row_ctr < in_rows_avail) {
  149544. inrows = in_rows_avail - *in_row_ctr;
  149545. numrows = prep->next_buf_stop - prep->next_buf_row;
  149546. numrows = (int) MIN((JDIMENSION) numrows, inrows);
  149547. (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
  149548. prep->color_buf,
  149549. (JDIMENSION) prep->next_buf_row,
  149550. numrows);
  149551. if (prep->rows_to_go == cinfo->image_height) {
  149552. for (ci = 0; ci < cinfo->num_components; ci++) {
  149553. int row;
  149554. for (row = 1; row <= cinfo->max_v_samp_factor; row++) {
  149555. jcopy_sample_rows(prep->color_buf[ci], 0,
  149556. prep->color_buf[ci], -row,
  149557. 1, cinfo->image_width);
  149558. }
  149559. }
  149560. }
  149561. *in_row_ctr += numrows;
  149562. prep->next_buf_row += numrows;
  149563. prep->rows_to_go -= numrows;
  149564. } else {
  149565. if (prep->rows_to_go != 0)
  149566. break;
  149567. if (prep->next_buf_row < prep->next_buf_stop) {
  149568. for (ci = 0; ci < cinfo->num_components; ci++) {
  149569. expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
  149570. prep->next_buf_row, prep->next_buf_stop);
  149571. }
  149572. prep->next_buf_row = prep->next_buf_stop;
  149573. }
  149574. }
  149575. if (prep->next_buf_row == prep->next_buf_stop) {
  149576. (*cinfo->downsample->downsample) (cinfo,
  149577. prep->color_buf,
  149578. (JDIMENSION) prep->this_row_group,
  149579. output_buf, *out_row_group_ctr);
  149580. (*out_row_group_ctr)++;
  149581. prep->this_row_group += cinfo->max_v_samp_factor;
  149582. if (prep->this_row_group >= buf_height)
  149583. prep->this_row_group = 0;
  149584. if (prep->next_buf_row >= buf_height)
  149585. prep->next_buf_row = 0;
  149586. prep->next_buf_stop = prep->next_buf_row + cinfo->max_v_samp_factor;
  149587. }
  149588. }
  149589. }
  149590. LOCAL(void)
  149591. create_context_buffer (j_compress_ptr cinfo)
  149592. {
  149593. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149594. int rgroup_height = cinfo->max_v_samp_factor;
  149595. int ci, i;
  149596. jpeg_component_info * compptr;
  149597. JSAMPARRAY true_buffer, fake_buffer;
  149598. fake_buffer = (JSAMPARRAY)
  149599. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149600. (cinfo->num_components * 5 * rgroup_height) *
  149601. SIZEOF(JSAMPROW));
  149602. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149603. ci++, compptr++) {
  149604. true_buffer = (*cinfo->mem->alloc_sarray)
  149605. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149606. (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE *
  149607. cinfo->max_h_samp_factor) / compptr->h_samp_factor),
  149608. (JDIMENSION) (3 * rgroup_height));
  149609. MEMCOPY(fake_buffer + rgroup_height, true_buffer,
  149610. 3 * rgroup_height * SIZEOF(JSAMPROW));
  149611. for (i = 0; i < rgroup_height; i++) {
  149612. fake_buffer[i] = true_buffer[2 * rgroup_height + i];
  149613. fake_buffer[4 * rgroup_height + i] = true_buffer[i];
  149614. }
  149615. prep->color_buf[ci] = fake_buffer + rgroup_height;
  149616. fake_buffer += 5 * rgroup_height; /* point to space for next component */
  149617. }
  149618. }
  149619. #endif /* CONTEXT_ROWS_SUPPORTED */
  149620. GLOBAL(void)
  149621. jinit_c_prep_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  149622. {
  149623. my_prep_ptr prep;
  149624. int ci;
  149625. jpeg_component_info * compptr;
  149626. if (need_full_buffer) /* safety check */
  149627. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  149628. prep = (my_prep_ptr)
  149629. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149630. SIZEOF(my_prep_controller));
  149631. cinfo->prep = (struct jpeg_c_prep_controller *) prep;
  149632. prep->pub.start_pass = start_pass_prep;
  149633. if (cinfo->downsample->need_context_rows) {
  149634. #ifdef CONTEXT_ROWS_SUPPORTED
  149635. prep->pub.pre_process_data = pre_process_context;
  149636. create_context_buffer(cinfo);
  149637. #else
  149638. ERREXIT(cinfo, JERR_NOT_COMPILED);
  149639. #endif
  149640. } else {
  149641. prep->pub.pre_process_data = pre_process_data;
  149642. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149643. ci++, compptr++) {
  149644. prep->color_buf[ci] = (*cinfo->mem->alloc_sarray)
  149645. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149646. (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE *
  149647. cinfo->max_h_samp_factor) / compptr->h_samp_factor),
  149648. (JDIMENSION) cinfo->max_v_samp_factor);
  149649. }
  149650. }
  149651. }
  149652. /*** End of inlined file: jcprepct.c ***/
  149653. /*** Start of inlined file: jcsample.c ***/
  149654. #define JPEG_INTERNALS
  149655. typedef JMETHOD(void, downsample1_ptr,
  149656. (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149657. JSAMPARRAY input_data, JSAMPARRAY output_data));
  149658. typedef struct {
  149659. struct jpeg_downsampler pub; /* public fields */
  149660. downsample1_ptr methods[MAX_COMPONENTS];
  149661. } my_downsampler;
  149662. typedef my_downsampler * my_downsample_ptr;
  149663. METHODDEF(void)
  149664. start_pass_downsample (j_compress_ptr cinfo)
  149665. {
  149666. }
  149667. LOCAL(void)
  149668. expand_right_edge (JSAMPARRAY image_data, int num_rows,
  149669. JDIMENSION input_cols, JDIMENSION output_cols)
  149670. {
  149671. register JSAMPROW ptr;
  149672. register JSAMPLE pixval;
  149673. register int count;
  149674. int row;
  149675. int numcols = (int) (output_cols - input_cols);
  149676. if (numcols > 0) {
  149677. for (row = 0; row < num_rows; row++) {
  149678. ptr = image_data[row] + input_cols;
  149679. pixval = ptr[-1]; /* don't need GETJSAMPLE() here */
  149680. for (count = numcols; count > 0; count--)
  149681. *ptr++ = pixval;
  149682. }
  149683. }
  149684. }
  149685. METHODDEF(void)
  149686. sep_downsample (j_compress_ptr cinfo,
  149687. JSAMPIMAGE input_buf, JDIMENSION in_row_index,
  149688. JSAMPIMAGE output_buf, JDIMENSION out_row_group_index)
  149689. {
  149690. my_downsample_ptr downsample = (my_downsample_ptr) cinfo->downsample;
  149691. int ci;
  149692. jpeg_component_info * compptr;
  149693. JSAMPARRAY in_ptr, out_ptr;
  149694. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149695. ci++, compptr++) {
  149696. in_ptr = input_buf[ci] + in_row_index;
  149697. out_ptr = output_buf[ci] + (out_row_group_index * compptr->v_samp_factor);
  149698. (*downsample->methods[ci]) (cinfo, compptr, in_ptr, out_ptr);
  149699. }
  149700. }
  149701. METHODDEF(void)
  149702. int_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149703. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149704. {
  149705. int inrow, outrow, h_expand, v_expand, numpix, numpix2, h, v;
  149706. JDIMENSION outcol, outcol_h; /* outcol_h == outcol*h_expand */
  149707. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  149708. JSAMPROW inptr, outptr;
  149709. INT32 outvalue;
  149710. h_expand = cinfo->max_h_samp_factor / compptr->h_samp_factor;
  149711. v_expand = cinfo->max_v_samp_factor / compptr->v_samp_factor;
  149712. numpix = h_expand * v_expand;
  149713. numpix2 = numpix/2;
  149714. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  149715. cinfo->image_width, output_cols * h_expand);
  149716. inrow = 0;
  149717. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  149718. outptr = output_data[outrow];
  149719. for (outcol = 0, outcol_h = 0; outcol < output_cols;
  149720. outcol++, outcol_h += h_expand) {
  149721. outvalue = 0;
  149722. for (v = 0; v < v_expand; v++) {
  149723. inptr = input_data[inrow+v] + outcol_h;
  149724. for (h = 0; h < h_expand; h++) {
  149725. outvalue += (INT32) GETJSAMPLE(*inptr++);
  149726. }
  149727. }
  149728. *outptr++ = (JSAMPLE) ((outvalue + numpix2) / numpix);
  149729. }
  149730. inrow += v_expand;
  149731. }
  149732. }
  149733. METHODDEF(void)
  149734. fullsize_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149735. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149736. {
  149737. jcopy_sample_rows(input_data, 0, output_data, 0,
  149738. cinfo->max_v_samp_factor, cinfo->image_width);
  149739. expand_right_edge(output_data, cinfo->max_v_samp_factor,
  149740. cinfo->image_width, compptr->width_in_blocks * DCTSIZE);
  149741. }
  149742. METHODDEF(void)
  149743. h2v1_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149744. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149745. {
  149746. int outrow;
  149747. JDIMENSION outcol;
  149748. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  149749. register JSAMPROW inptr, outptr;
  149750. register int bias;
  149751. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  149752. cinfo->image_width, output_cols * 2);
  149753. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  149754. outptr = output_data[outrow];
  149755. inptr = input_data[outrow];
  149756. bias = 0; /* bias = 0,1,0,1,... for successive samples */
  149757. for (outcol = 0; outcol < output_cols; outcol++) {
  149758. *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr) + GETJSAMPLE(inptr[1])
  149759. + bias) >> 1);
  149760. bias ^= 1; /* 0=>1, 1=>0 */
  149761. inptr += 2;
  149762. }
  149763. }
  149764. }
  149765. METHODDEF(void)
  149766. h2v2_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149767. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149768. {
  149769. int inrow, outrow;
  149770. JDIMENSION outcol;
  149771. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  149772. register JSAMPROW inptr0, inptr1, outptr;
  149773. register int bias;
  149774. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  149775. cinfo->image_width, output_cols * 2);
  149776. inrow = 0;
  149777. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  149778. outptr = output_data[outrow];
  149779. inptr0 = input_data[inrow];
  149780. inptr1 = input_data[inrow+1];
  149781. bias = 1; /* bias = 1,2,1,2,... for successive samples */
  149782. for (outcol = 0; outcol < output_cols; outcol++) {
  149783. *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  149784. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1])
  149785. + bias) >> 2);
  149786. bias ^= 3; /* 1=>2, 2=>1 */
  149787. inptr0 += 2; inptr1 += 2;
  149788. }
  149789. inrow += 2;
  149790. }
  149791. }
  149792. #ifdef INPUT_SMOOTHING_SUPPORTED
  149793. METHODDEF(void)
  149794. h2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149795. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149796. {
  149797. int inrow, outrow;
  149798. JDIMENSION colctr;
  149799. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  149800. register JSAMPROW inptr0, inptr1, above_ptr, below_ptr, outptr;
  149801. INT32 membersum, neighsum, memberscale, neighscale;
  149802. expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
  149803. cinfo->image_width, output_cols * 2);
  149804. memberscale = 16384 - cinfo->smoothing_factor * 80; /* scaled (1-5*SF)/4 */
  149805. neighscale = cinfo->smoothing_factor * 16; /* scaled SF/4 */
  149806. inrow = 0;
  149807. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  149808. outptr = output_data[outrow];
  149809. inptr0 = input_data[inrow];
  149810. inptr1 = input_data[inrow+1];
  149811. above_ptr = input_data[inrow-1];
  149812. below_ptr = input_data[inrow+2];
  149813. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  149814. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  149815. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  149816. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  149817. GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[2]) +
  149818. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[2]);
  149819. neighsum += neighsum;
  149820. neighsum += GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[2]) +
  149821. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[2]);
  149822. membersum = membersum * memberscale + neighsum * neighscale;
  149823. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  149824. inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
  149825. for (colctr = output_cols - 2; colctr > 0; colctr--) {
  149826. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  149827. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  149828. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  149829. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  149830. GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[2]) +
  149831. GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[2]);
  149832. neighsum += neighsum;
  149833. neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[2]) +
  149834. GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[2]);
  149835. membersum = membersum * memberscale + neighsum * neighscale;
  149836. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  149837. inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
  149838. }
  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[-1]) + GETJSAMPLE(inptr0[1]) +
  149844. GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[1]);
  149845. neighsum += neighsum;
  149846. neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[1]) +
  149847. GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[1]);
  149848. membersum = membersum * memberscale + neighsum * neighscale;
  149849. *outptr = (JSAMPLE) ((membersum + 32768) >> 16);
  149850. inrow += 2;
  149851. }
  149852. }
  149853. METHODDEF(void)
  149854. fullsize_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
  149855. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149856. {
  149857. int outrow;
  149858. JDIMENSION colctr;
  149859. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  149860. register JSAMPROW inptr, above_ptr, below_ptr, outptr;
  149861. INT32 membersum, neighsum, memberscale, neighscale;
  149862. int colsum, lastcolsum, nextcolsum;
  149863. expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
  149864. cinfo->image_width, output_cols);
  149865. memberscale = 65536L - cinfo->smoothing_factor * 512L; /* scaled 1-8*SF */
  149866. neighscale = cinfo->smoothing_factor * 64; /* scaled SF */
  149867. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  149868. outptr = output_data[outrow];
  149869. inptr = input_data[outrow];
  149870. above_ptr = input_data[outrow-1];
  149871. below_ptr = input_data[outrow+1];
  149872. colsum = GETJSAMPLE(*above_ptr++) + GETJSAMPLE(*below_ptr++) +
  149873. GETJSAMPLE(*inptr);
  149874. membersum = GETJSAMPLE(*inptr++);
  149875. nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
  149876. GETJSAMPLE(*inptr);
  149877. neighsum = colsum + (colsum - membersum) + nextcolsum;
  149878. membersum = membersum * memberscale + neighsum * neighscale;
  149879. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  149880. lastcolsum = colsum; colsum = nextcolsum;
  149881. for (colctr = output_cols - 2; colctr > 0; colctr--) {
  149882. membersum = GETJSAMPLE(*inptr++);
  149883. above_ptr++; below_ptr++;
  149884. nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
  149885. GETJSAMPLE(*inptr);
  149886. neighsum = lastcolsum + (colsum - membersum) + nextcolsum;
  149887. membersum = membersum * memberscale + neighsum * neighscale;
  149888. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  149889. lastcolsum = colsum; colsum = nextcolsum;
  149890. }
  149891. membersum = GETJSAMPLE(*inptr);
  149892. neighsum = lastcolsum + (colsum - membersum) + colsum;
  149893. membersum = membersum * memberscale + neighsum * neighscale;
  149894. *outptr = (JSAMPLE) ((membersum + 32768) >> 16);
  149895. }
  149896. }
  149897. #endif /* INPUT_SMOOTHING_SUPPORTED */
  149898. GLOBAL(void)
  149899. jinit_downsampler (j_compress_ptr cinfo)
  149900. {
  149901. my_downsample_ptr downsample;
  149902. int ci;
  149903. jpeg_component_info * compptr;
  149904. boolean smoothok = TRUE;
  149905. downsample = (my_downsample_ptr)
  149906. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149907. SIZEOF(my_downsampler));
  149908. cinfo->downsample = (struct jpeg_downsampler *) downsample;
  149909. downsample->pub.start_pass = start_pass_downsample;
  149910. downsample->pub.downsample = sep_downsample;
  149911. downsample->pub.need_context_rows = FALSE;
  149912. if (cinfo->CCIR601_sampling)
  149913. ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
  149914. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149915. ci++, compptr++) {
  149916. if (compptr->h_samp_factor == cinfo->max_h_samp_factor &&
  149917. compptr->v_samp_factor == cinfo->max_v_samp_factor) {
  149918. #ifdef INPUT_SMOOTHING_SUPPORTED
  149919. if (cinfo->smoothing_factor) {
  149920. downsample->methods[ci] = fullsize_smooth_downsample;
  149921. downsample->pub.need_context_rows = TRUE;
  149922. } else
  149923. #endif
  149924. downsample->methods[ci] = fullsize_downsample;
  149925. } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
  149926. compptr->v_samp_factor == cinfo->max_v_samp_factor) {
  149927. smoothok = FALSE;
  149928. downsample->methods[ci] = h2v1_downsample;
  149929. } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
  149930. compptr->v_samp_factor * 2 == cinfo->max_v_samp_factor) {
  149931. #ifdef INPUT_SMOOTHING_SUPPORTED
  149932. if (cinfo->smoothing_factor) {
  149933. downsample->methods[ci] = h2v2_smooth_downsample;
  149934. downsample->pub.need_context_rows = TRUE;
  149935. } else
  149936. #endif
  149937. downsample->methods[ci] = h2v2_downsample;
  149938. } else if ((cinfo->max_h_samp_factor % compptr->h_samp_factor) == 0 &&
  149939. (cinfo->max_v_samp_factor % compptr->v_samp_factor) == 0) {
  149940. smoothok = FALSE;
  149941. downsample->methods[ci] = int_downsample;
  149942. } else
  149943. ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
  149944. }
  149945. #ifdef INPUT_SMOOTHING_SUPPORTED
  149946. if (cinfo->smoothing_factor && !smoothok)
  149947. TRACEMS(cinfo, 0, JTRC_SMOOTH_NOTIMPL);
  149948. #endif
  149949. }
  149950. /*** End of inlined file: jcsample.c ***/
  149951. /*** Start of inlined file: jctrans.c ***/
  149952. #define JPEG_INTERNALS
  149953. LOCAL(void) transencode_master_selection
  149954. JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays));
  149955. LOCAL(void) transencode_coef_controller
  149956. JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays));
  149957. GLOBAL(void)
  149958. jpeg_write_coefficients (j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays)
  149959. {
  149960. if (cinfo->global_state != CSTATE_START)
  149961. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  149962. jpeg_suppress_tables(cinfo, FALSE);
  149963. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  149964. (*cinfo->dest->init_destination) (cinfo);
  149965. transencode_master_selection(cinfo, coef_arrays);
  149966. cinfo->next_scanline = 0; /* so jpeg_write_marker works */
  149967. cinfo->global_state = CSTATE_WRCOEFS;
  149968. }
  149969. GLOBAL(void)
  149970. jpeg_copy_critical_parameters (j_decompress_ptr srcinfo,
  149971. j_compress_ptr dstinfo)
  149972. {
  149973. JQUANT_TBL ** qtblptr;
  149974. jpeg_component_info *incomp, *outcomp;
  149975. JQUANT_TBL *c_quant, *slot_quant;
  149976. int tblno, ci, coefi;
  149977. if (dstinfo->global_state != CSTATE_START)
  149978. ERREXIT1(dstinfo, JERR_BAD_STATE, dstinfo->global_state);
  149979. dstinfo->image_width = srcinfo->image_width;
  149980. dstinfo->image_height = srcinfo->image_height;
  149981. dstinfo->input_components = srcinfo->num_components;
  149982. dstinfo->in_color_space = srcinfo->jpeg_color_space;
  149983. jpeg_set_defaults(dstinfo);
  149984. jpeg_set_colorspace(dstinfo, srcinfo->jpeg_color_space);
  149985. dstinfo->data_precision = srcinfo->data_precision;
  149986. dstinfo->CCIR601_sampling = srcinfo->CCIR601_sampling;
  149987. for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) {
  149988. if (srcinfo->quant_tbl_ptrs[tblno] != NULL) {
  149989. qtblptr = & dstinfo->quant_tbl_ptrs[tblno];
  149990. if (*qtblptr == NULL)
  149991. *qtblptr = jpeg_alloc_quant_table((j_common_ptr) dstinfo);
  149992. MEMCOPY((*qtblptr)->quantval,
  149993. srcinfo->quant_tbl_ptrs[tblno]->quantval,
  149994. SIZEOF((*qtblptr)->quantval));
  149995. (*qtblptr)->sent_table = FALSE;
  149996. }
  149997. }
  149998. dstinfo->num_components = srcinfo->num_components;
  149999. if (dstinfo->num_components < 1 || dstinfo->num_components > MAX_COMPONENTS)
  150000. ERREXIT2(dstinfo, JERR_COMPONENT_COUNT, dstinfo->num_components,
  150001. MAX_COMPONENTS);
  150002. for (ci = 0, incomp = srcinfo->comp_info, outcomp = dstinfo->comp_info;
  150003. ci < dstinfo->num_components; ci++, incomp++, outcomp++) {
  150004. outcomp->component_id = incomp->component_id;
  150005. outcomp->h_samp_factor = incomp->h_samp_factor;
  150006. outcomp->v_samp_factor = incomp->v_samp_factor;
  150007. outcomp->quant_tbl_no = incomp->quant_tbl_no;
  150008. tblno = outcomp->quant_tbl_no;
  150009. if (tblno < 0 || tblno >= NUM_QUANT_TBLS ||
  150010. srcinfo->quant_tbl_ptrs[tblno] == NULL)
  150011. ERREXIT1(dstinfo, JERR_NO_QUANT_TABLE, tblno);
  150012. slot_quant = srcinfo->quant_tbl_ptrs[tblno];
  150013. c_quant = incomp->quant_table;
  150014. if (c_quant != NULL) {
  150015. for (coefi = 0; coefi < DCTSIZE2; coefi++) {
  150016. if (c_quant->quantval[coefi] != slot_quant->quantval[coefi])
  150017. ERREXIT1(dstinfo, JERR_MISMATCHED_QUANT_TABLE, tblno);
  150018. }
  150019. }
  150020. }
  150021. if (srcinfo->saw_JFIF_marker) {
  150022. if (srcinfo->JFIF_major_version == 1) {
  150023. dstinfo->JFIF_major_version = srcinfo->JFIF_major_version;
  150024. dstinfo->JFIF_minor_version = srcinfo->JFIF_minor_version;
  150025. }
  150026. dstinfo->density_unit = srcinfo->density_unit;
  150027. dstinfo->X_density = srcinfo->X_density;
  150028. dstinfo->Y_density = srcinfo->Y_density;
  150029. }
  150030. }
  150031. LOCAL(void)
  150032. transencode_master_selection (j_compress_ptr cinfo,
  150033. jvirt_barray_ptr * coef_arrays)
  150034. {
  150035. cinfo->input_components = 1;
  150036. jinit_c_master_control(cinfo, TRUE /* transcode only */);
  150037. if (cinfo->arith_code) {
  150038. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  150039. } else {
  150040. if (cinfo->progressive_mode) {
  150041. #ifdef C_PROGRESSIVE_SUPPORTED
  150042. jinit_phuff_encoder(cinfo);
  150043. #else
  150044. ERREXIT(cinfo, JERR_NOT_COMPILED);
  150045. #endif
  150046. } else
  150047. jinit_huff_encoder(cinfo);
  150048. }
  150049. transencode_coef_controller(cinfo, coef_arrays);
  150050. jinit_marker_writer(cinfo);
  150051. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  150052. (*cinfo->marker->write_file_header) (cinfo);
  150053. }
  150054. typedef struct {
  150055. struct jpeg_c_coef_controller pub; /* public fields */
  150056. JDIMENSION iMCU_row_num; /* iMCU row # within image */
  150057. JDIMENSION mcu_ctr; /* counts MCUs processed in current row */
  150058. int MCU_vert_offset; /* counts MCU rows within iMCU row */
  150059. int MCU_rows_per_iMCU_row; /* number of such rows needed */
  150060. jvirt_barray_ptr * whole_image;
  150061. JBLOCKROW dummy_buffer[C_MAX_BLOCKS_IN_MCU];
  150062. } my_coef_controller2;
  150063. typedef my_coef_controller2 * my_coef_ptr2;
  150064. LOCAL(void)
  150065. start_iMCU_row2 (j_compress_ptr cinfo)
  150066. {
  150067. my_coef_ptr2 coef = (my_coef_ptr2) cinfo->coef;
  150068. if (cinfo->comps_in_scan > 1) {
  150069. coef->MCU_rows_per_iMCU_row = 1;
  150070. } else {
  150071. if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1))
  150072. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
  150073. else
  150074. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  150075. }
  150076. coef->mcu_ctr = 0;
  150077. coef->MCU_vert_offset = 0;
  150078. }
  150079. METHODDEF(void)
  150080. start_pass_coef2 (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  150081. {
  150082. my_coef_ptr2 coef = (my_coef_ptr2) cinfo->coef;
  150083. if (pass_mode != JBUF_CRANK_DEST)
  150084. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  150085. coef->iMCU_row_num = 0;
  150086. start_iMCU_row2(cinfo);
  150087. }
  150088. METHODDEF(boolean)
  150089. compress_output2 (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  150090. {
  150091. my_coef_ptr2 coef = (my_coef_ptr2) cinfo->coef;
  150092. JDIMENSION MCU_col_num; /* index of current MCU within row */
  150093. JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  150094. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  150095. int blkn, ci, xindex, yindex, yoffset, blockcnt;
  150096. JDIMENSION start_col;
  150097. JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  150098. JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU];
  150099. JBLOCKROW buffer_ptr;
  150100. jpeg_component_info *compptr;
  150101. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  150102. compptr = cinfo->cur_comp_info[ci];
  150103. buffer[ci] = (*cinfo->mem->access_virt_barray)
  150104. ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
  150105. coef->iMCU_row_num * compptr->v_samp_factor,
  150106. (JDIMENSION) compptr->v_samp_factor, FALSE);
  150107. }
  150108. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  150109. yoffset++) {
  150110. for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row;
  150111. MCU_col_num++) {
  150112. blkn = 0; /* index of current DCT block within MCU */
  150113. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  150114. compptr = cinfo->cur_comp_info[ci];
  150115. start_col = MCU_col_num * compptr->MCU_width;
  150116. blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
  150117. : compptr->last_col_width;
  150118. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  150119. if (coef->iMCU_row_num < last_iMCU_row ||
  150120. yindex+yoffset < compptr->last_row_height) {
  150121. buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
  150122. for (xindex = 0; xindex < blockcnt; xindex++)
  150123. MCU_buffer[blkn++] = buffer_ptr++;
  150124. } else {
  150125. xindex = 0;
  150126. }
  150127. for (; xindex < compptr->MCU_width; xindex++) {
  150128. MCU_buffer[blkn] = coef->dummy_buffer[blkn];
  150129. MCU_buffer[blkn][0][0] = MCU_buffer[blkn-1][0][0];
  150130. blkn++;
  150131. }
  150132. }
  150133. }
  150134. if (! (*cinfo->entropy->encode_mcu) (cinfo, MCU_buffer)) {
  150135. coef->MCU_vert_offset = yoffset;
  150136. coef->mcu_ctr = MCU_col_num;
  150137. return FALSE;
  150138. }
  150139. }
  150140. coef->mcu_ctr = 0;
  150141. }
  150142. coef->iMCU_row_num++;
  150143. start_iMCU_row2(cinfo);
  150144. return TRUE;
  150145. }
  150146. LOCAL(void)
  150147. transencode_coef_controller (j_compress_ptr cinfo,
  150148. jvirt_barray_ptr * coef_arrays)
  150149. {
  150150. my_coef_ptr2 coef;
  150151. JBLOCKROW buffer;
  150152. int i;
  150153. coef = (my_coef_ptr2)
  150154. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150155. SIZEOF(my_coef_controller2));
  150156. cinfo->coef = (struct jpeg_c_coef_controller *) coef;
  150157. coef->pub.start_pass = start_pass_coef2;
  150158. coef->pub.compress_data = compress_output2;
  150159. coef->whole_image = coef_arrays;
  150160. buffer = (JBLOCKROW)
  150161. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150162. C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  150163. jzero_far((void FAR *) buffer, C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  150164. for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) {
  150165. coef->dummy_buffer[i] = buffer + i;
  150166. }
  150167. }
  150168. /*** End of inlined file: jctrans.c ***/
  150169. /*** Start of inlined file: jdapistd.c ***/
  150170. #define JPEG_INTERNALS
  150171. LOCAL(boolean) output_pass_setup JPP((j_decompress_ptr cinfo));
  150172. GLOBAL(boolean)
  150173. jpeg_start_decompress (j_decompress_ptr cinfo)
  150174. {
  150175. if (cinfo->global_state == DSTATE_READY) {
  150176. jinit_master_decompress(cinfo);
  150177. if (cinfo->buffered_image) {
  150178. cinfo->global_state = DSTATE_BUFIMAGE;
  150179. return TRUE;
  150180. }
  150181. cinfo->global_state = DSTATE_PRELOAD;
  150182. }
  150183. if (cinfo->global_state == DSTATE_PRELOAD) {
  150184. if (cinfo->inputctl->has_multiple_scans) {
  150185. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150186. for (;;) {
  150187. int retcode;
  150188. if (cinfo->progress != NULL)
  150189. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150190. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  150191. if (retcode == JPEG_SUSPENDED)
  150192. return FALSE;
  150193. if (retcode == JPEG_REACHED_EOI)
  150194. break;
  150195. if (cinfo->progress != NULL &&
  150196. (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
  150197. if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
  150198. cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
  150199. }
  150200. }
  150201. }
  150202. #else
  150203. ERREXIT(cinfo, JERR_NOT_COMPILED);
  150204. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  150205. }
  150206. cinfo->output_scan_number = cinfo->input_scan_number;
  150207. } else if (cinfo->global_state != DSTATE_PRESCAN)
  150208. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150209. return output_pass_setup(cinfo);
  150210. }
  150211. LOCAL(boolean)
  150212. output_pass_setup (j_decompress_ptr cinfo)
  150213. {
  150214. if (cinfo->global_state != DSTATE_PRESCAN) {
  150215. (*cinfo->master->prepare_for_output_pass) (cinfo);
  150216. cinfo->output_scanline = 0;
  150217. cinfo->global_state = DSTATE_PRESCAN;
  150218. }
  150219. while (cinfo->master->is_dummy_pass) {
  150220. #ifdef QUANT_2PASS_SUPPORTED
  150221. while (cinfo->output_scanline < cinfo->output_height) {
  150222. JDIMENSION last_scanline;
  150223. if (cinfo->progress != NULL) {
  150224. cinfo->progress->pass_counter = (long) cinfo->output_scanline;
  150225. cinfo->progress->pass_limit = (long) cinfo->output_height;
  150226. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150227. }
  150228. last_scanline = cinfo->output_scanline;
  150229. (*cinfo->main->process_data) (cinfo, (JSAMPARRAY) NULL,
  150230. &cinfo->output_scanline, (JDIMENSION) 0);
  150231. if (cinfo->output_scanline == last_scanline)
  150232. return FALSE; /* No progress made, must suspend */
  150233. }
  150234. (*cinfo->master->finish_output_pass) (cinfo);
  150235. (*cinfo->master->prepare_for_output_pass) (cinfo);
  150236. cinfo->output_scanline = 0;
  150237. #else
  150238. ERREXIT(cinfo, JERR_NOT_COMPILED);
  150239. #endif /* QUANT_2PASS_SUPPORTED */
  150240. }
  150241. cinfo->global_state = cinfo->raw_data_out ? DSTATE_RAW_OK : DSTATE_SCANNING;
  150242. return TRUE;
  150243. }
  150244. GLOBAL(JDIMENSION)
  150245. jpeg_read_scanlines (j_decompress_ptr cinfo, JSAMPARRAY scanlines,
  150246. JDIMENSION max_lines)
  150247. {
  150248. JDIMENSION row_ctr;
  150249. if (cinfo->global_state != DSTATE_SCANNING)
  150250. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150251. if (cinfo->output_scanline >= cinfo->output_height) {
  150252. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  150253. return 0;
  150254. }
  150255. if (cinfo->progress != NULL) {
  150256. cinfo->progress->pass_counter = (long) cinfo->output_scanline;
  150257. cinfo->progress->pass_limit = (long) cinfo->output_height;
  150258. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150259. }
  150260. row_ctr = 0;
  150261. (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, max_lines);
  150262. cinfo->output_scanline += row_ctr;
  150263. return row_ctr;
  150264. }
  150265. GLOBAL(JDIMENSION)
  150266. jpeg_read_raw_data (j_decompress_ptr cinfo, JSAMPIMAGE data,
  150267. JDIMENSION max_lines)
  150268. {
  150269. JDIMENSION lines_per_iMCU_row;
  150270. if (cinfo->global_state != DSTATE_RAW_OK)
  150271. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150272. if (cinfo->output_scanline >= cinfo->output_height) {
  150273. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  150274. return 0;
  150275. }
  150276. if (cinfo->progress != NULL) {
  150277. cinfo->progress->pass_counter = (long) cinfo->output_scanline;
  150278. cinfo->progress->pass_limit = (long) cinfo->output_height;
  150279. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150280. }
  150281. lines_per_iMCU_row = cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size;
  150282. if (max_lines < lines_per_iMCU_row)
  150283. ERREXIT(cinfo, JERR_BUFFER_SIZE);
  150284. if (! (*cinfo->coef->decompress_data) (cinfo, data))
  150285. return 0; /* suspension forced, can do nothing more */
  150286. cinfo->output_scanline += lines_per_iMCU_row;
  150287. return lines_per_iMCU_row;
  150288. }
  150289. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150290. GLOBAL(boolean)
  150291. jpeg_start_output (j_decompress_ptr cinfo, int scan_number)
  150292. {
  150293. if (cinfo->global_state != DSTATE_BUFIMAGE &&
  150294. cinfo->global_state != DSTATE_PRESCAN)
  150295. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150296. if (scan_number <= 0)
  150297. scan_number = 1;
  150298. if (cinfo->inputctl->eoi_reached &&
  150299. scan_number > cinfo->input_scan_number)
  150300. scan_number = cinfo->input_scan_number;
  150301. cinfo->output_scan_number = scan_number;
  150302. return output_pass_setup(cinfo);
  150303. }
  150304. GLOBAL(boolean)
  150305. jpeg_finish_output (j_decompress_ptr cinfo)
  150306. {
  150307. if ((cinfo->global_state == DSTATE_SCANNING ||
  150308. cinfo->global_state == DSTATE_RAW_OK) && cinfo->buffered_image) {
  150309. (*cinfo->master->finish_output_pass) (cinfo);
  150310. cinfo->global_state = DSTATE_BUFPOST;
  150311. } else if (cinfo->global_state != DSTATE_BUFPOST) {
  150312. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150313. }
  150314. while (cinfo->input_scan_number <= cinfo->output_scan_number &&
  150315. ! cinfo->inputctl->eoi_reached) {
  150316. if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
  150317. return FALSE; /* Suspend, come back later */
  150318. }
  150319. cinfo->global_state = DSTATE_BUFIMAGE;
  150320. return TRUE;
  150321. }
  150322. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  150323. /*** End of inlined file: jdapistd.c ***/
  150324. /*** Start of inlined file: jdapimin.c ***/
  150325. #define JPEG_INTERNALS
  150326. GLOBAL(void)
  150327. jpeg_CreateDecompress (j_decompress_ptr cinfo, int version, size_t structsize)
  150328. {
  150329. int i;
  150330. cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */
  150331. if (version != JPEG_LIB_VERSION)
  150332. ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
  150333. if (structsize != SIZEOF(struct jpeg_decompress_struct))
  150334. ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
  150335. (int) SIZEOF(struct jpeg_decompress_struct), (int) structsize);
  150336. {
  150337. struct jpeg_error_mgr * err = cinfo->err;
  150338. void * client_data = cinfo->client_data; /* ignore Purify complaint here */
  150339. MEMZERO(cinfo, SIZEOF(struct jpeg_decompress_struct));
  150340. cinfo->err = err;
  150341. cinfo->client_data = client_data;
  150342. }
  150343. cinfo->is_decompressor = TRUE;
  150344. jinit_memory_mgr((j_common_ptr) cinfo);
  150345. cinfo->progress = NULL;
  150346. cinfo->src = NULL;
  150347. for (i = 0; i < NUM_QUANT_TBLS; i++)
  150348. cinfo->quant_tbl_ptrs[i] = NULL;
  150349. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  150350. cinfo->dc_huff_tbl_ptrs[i] = NULL;
  150351. cinfo->ac_huff_tbl_ptrs[i] = NULL;
  150352. }
  150353. cinfo->marker_list = NULL;
  150354. jinit_marker_reader(cinfo);
  150355. jinit_input_controller(cinfo);
  150356. cinfo->global_state = DSTATE_START;
  150357. }
  150358. GLOBAL(void)
  150359. jpeg_destroy_decompress (j_decompress_ptr cinfo)
  150360. {
  150361. jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
  150362. }
  150363. GLOBAL(void)
  150364. jpeg_abort_decompress (j_decompress_ptr cinfo)
  150365. {
  150366. jpeg_abort((j_common_ptr) cinfo); /* use common routine */
  150367. }
  150368. LOCAL(void)
  150369. default_decompress_parms (j_decompress_ptr cinfo)
  150370. {
  150371. switch (cinfo->num_components) {
  150372. case 1:
  150373. cinfo->jpeg_color_space = JCS_GRAYSCALE;
  150374. cinfo->out_color_space = JCS_GRAYSCALE;
  150375. break;
  150376. case 3:
  150377. if (cinfo->saw_JFIF_marker) {
  150378. cinfo->jpeg_color_space = JCS_YCbCr; /* JFIF implies YCbCr */
  150379. } else if (cinfo->saw_Adobe_marker) {
  150380. switch (cinfo->Adobe_transform) {
  150381. case 0:
  150382. cinfo->jpeg_color_space = JCS_RGB;
  150383. break;
  150384. case 1:
  150385. cinfo->jpeg_color_space = JCS_YCbCr;
  150386. break;
  150387. default:
  150388. WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
  150389. cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
  150390. break;
  150391. }
  150392. } else {
  150393. int cid0 = cinfo->comp_info[0].component_id;
  150394. int cid1 = cinfo->comp_info[1].component_id;
  150395. int cid2 = cinfo->comp_info[2].component_id;
  150396. if (cid0 == 1 && cid1 == 2 && cid2 == 3)
  150397. cinfo->jpeg_color_space = JCS_YCbCr; /* assume JFIF w/out marker */
  150398. else if (cid0 == 82 && cid1 == 71 && cid2 == 66)
  150399. cinfo->jpeg_color_space = JCS_RGB; /* ASCII 'R', 'G', 'B' */
  150400. else {
  150401. TRACEMS3(cinfo, 1, JTRC_UNKNOWN_IDS, cid0, cid1, cid2);
  150402. cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
  150403. }
  150404. }
  150405. cinfo->out_color_space = JCS_RGB;
  150406. break;
  150407. case 4:
  150408. if (cinfo->saw_Adobe_marker) {
  150409. switch (cinfo->Adobe_transform) {
  150410. case 0:
  150411. cinfo->jpeg_color_space = JCS_CMYK;
  150412. break;
  150413. case 2:
  150414. cinfo->jpeg_color_space = JCS_YCCK;
  150415. break;
  150416. default:
  150417. WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
  150418. cinfo->jpeg_color_space = JCS_YCCK; /* assume it's YCCK */
  150419. break;
  150420. }
  150421. } else {
  150422. cinfo->jpeg_color_space = JCS_CMYK;
  150423. }
  150424. cinfo->out_color_space = JCS_CMYK;
  150425. break;
  150426. default:
  150427. cinfo->jpeg_color_space = JCS_UNKNOWN;
  150428. cinfo->out_color_space = JCS_UNKNOWN;
  150429. break;
  150430. }
  150431. cinfo->scale_num = 1; /* 1:1 scaling */
  150432. cinfo->scale_denom = 1;
  150433. cinfo->output_gamma = 1.0;
  150434. cinfo->buffered_image = FALSE;
  150435. cinfo->raw_data_out = FALSE;
  150436. cinfo->dct_method = JDCT_DEFAULT;
  150437. cinfo->do_fancy_upsampling = TRUE;
  150438. cinfo->do_block_smoothing = TRUE;
  150439. cinfo->quantize_colors = FALSE;
  150440. cinfo->dither_mode = JDITHER_FS;
  150441. #ifdef QUANT_2PASS_SUPPORTED
  150442. cinfo->two_pass_quantize = TRUE;
  150443. #else
  150444. cinfo->two_pass_quantize = FALSE;
  150445. #endif
  150446. cinfo->desired_number_of_colors = 256;
  150447. cinfo->colormap = NULL;
  150448. cinfo->enable_1pass_quant = FALSE;
  150449. cinfo->enable_external_quant = FALSE;
  150450. cinfo->enable_2pass_quant = FALSE;
  150451. }
  150452. GLOBAL(int)
  150453. jpeg_read_header (j_decompress_ptr cinfo, boolean require_image)
  150454. {
  150455. int retcode;
  150456. if (cinfo->global_state != DSTATE_START &&
  150457. cinfo->global_state != DSTATE_INHEADER)
  150458. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150459. retcode = jpeg_consume_input(cinfo);
  150460. switch (retcode) {
  150461. case JPEG_REACHED_SOS:
  150462. retcode = JPEG_HEADER_OK;
  150463. break;
  150464. case JPEG_REACHED_EOI:
  150465. if (require_image) /* Complain if application wanted an image */
  150466. ERREXIT(cinfo, JERR_NO_IMAGE);
  150467. jpeg_abort((j_common_ptr) cinfo); /* sets state = DSTATE_START */
  150468. retcode = JPEG_HEADER_TABLES_ONLY;
  150469. break;
  150470. case JPEG_SUSPENDED:
  150471. break;
  150472. }
  150473. return retcode;
  150474. }
  150475. GLOBAL(int)
  150476. jpeg_consume_input (j_decompress_ptr cinfo)
  150477. {
  150478. int retcode = JPEG_SUSPENDED;
  150479. switch (cinfo->global_state) {
  150480. case DSTATE_START:
  150481. (*cinfo->inputctl->reset_input_controller) (cinfo);
  150482. (*cinfo->src->init_source) (cinfo);
  150483. cinfo->global_state = DSTATE_INHEADER;
  150484. case DSTATE_INHEADER:
  150485. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  150486. if (retcode == JPEG_REACHED_SOS) { /* Found SOS, prepare to decompress */
  150487. default_decompress_parms(cinfo);
  150488. cinfo->global_state = DSTATE_READY;
  150489. }
  150490. break;
  150491. case DSTATE_READY:
  150492. retcode = JPEG_REACHED_SOS;
  150493. break;
  150494. case DSTATE_PRELOAD:
  150495. case DSTATE_PRESCAN:
  150496. case DSTATE_SCANNING:
  150497. case DSTATE_RAW_OK:
  150498. case DSTATE_BUFIMAGE:
  150499. case DSTATE_BUFPOST:
  150500. case DSTATE_STOPPING:
  150501. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  150502. break;
  150503. default:
  150504. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150505. }
  150506. return retcode;
  150507. }
  150508. GLOBAL(boolean)
  150509. jpeg_input_complete (j_decompress_ptr cinfo)
  150510. {
  150511. if (cinfo->global_state < DSTATE_START ||
  150512. cinfo->global_state > DSTATE_STOPPING)
  150513. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150514. return cinfo->inputctl->eoi_reached;
  150515. }
  150516. GLOBAL(boolean)
  150517. jpeg_has_multiple_scans (j_decompress_ptr cinfo)
  150518. {
  150519. if (cinfo->global_state < DSTATE_READY ||
  150520. cinfo->global_state > DSTATE_STOPPING)
  150521. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150522. return cinfo->inputctl->has_multiple_scans;
  150523. }
  150524. GLOBAL(boolean)
  150525. jpeg_finish_decompress (j_decompress_ptr cinfo)
  150526. {
  150527. if ((cinfo->global_state == DSTATE_SCANNING ||
  150528. cinfo->global_state == DSTATE_RAW_OK) && ! cinfo->buffered_image) {
  150529. if (cinfo->output_scanline < cinfo->output_height)
  150530. ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
  150531. (*cinfo->master->finish_output_pass) (cinfo);
  150532. cinfo->global_state = DSTATE_STOPPING;
  150533. } else if (cinfo->global_state == DSTATE_BUFIMAGE) {
  150534. cinfo->global_state = DSTATE_STOPPING;
  150535. } else if (cinfo->global_state != DSTATE_STOPPING) {
  150536. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150537. }
  150538. while (! cinfo->inputctl->eoi_reached) {
  150539. if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
  150540. return FALSE; /* Suspend, come back later */
  150541. }
  150542. (*cinfo->src->term_source) (cinfo);
  150543. jpeg_abort((j_common_ptr) cinfo);
  150544. return TRUE;
  150545. }
  150546. /*** End of inlined file: jdapimin.c ***/
  150547. /*** Start of inlined file: jdatasrc.c ***/
  150548. /*** Start of inlined file: jerror.h ***/
  150549. #ifndef JMESSAGE
  150550. #ifndef JERROR_H
  150551. #define JMAKE_ENUM_LIST
  150552. #else
  150553. #define JMESSAGE(code,string)
  150554. #endif /* JERROR_H */
  150555. #endif /* JMESSAGE */
  150556. #ifdef JMAKE_ENUM_LIST
  150557. typedef enum {
  150558. #define JMESSAGE(code,string) code ,
  150559. #endif /* JMAKE_ENUM_LIST */
  150560. JMESSAGE(JMSG_NOMESSAGE, "Bogus message code %d") /* Must be first entry! */
  150561. JMESSAGE(JERR_ARITH_NOTIMPL,
  150562. "Sorry, there are legal restrictions on arithmetic coding")
  150563. JMESSAGE(JERR_BAD_ALIGN_TYPE, "ALIGN_TYPE is wrong, please fix")
  150564. JMESSAGE(JERR_BAD_ALLOC_CHUNK, "MAX_ALLOC_CHUNK is wrong, please fix")
  150565. JMESSAGE(JERR_BAD_BUFFER_MODE, "Bogus buffer control mode")
  150566. JMESSAGE(JERR_BAD_COMPONENT_ID, "Invalid component ID %d in SOS")
  150567. JMESSAGE(JERR_BAD_DCT_COEF, "DCT coefficient out of range")
  150568. JMESSAGE(JERR_BAD_DCTSIZE, "IDCT output block size %d not supported")
  150569. JMESSAGE(JERR_BAD_HUFF_TABLE, "Bogus Huffman table definition")
  150570. JMESSAGE(JERR_BAD_IN_COLORSPACE, "Bogus input colorspace")
  150571. JMESSAGE(JERR_BAD_J_COLORSPACE, "Bogus JPEG colorspace")
  150572. JMESSAGE(JERR_BAD_LENGTH, "Bogus marker length")
  150573. JMESSAGE(JERR_BAD_LIB_VERSION,
  150574. "Wrong JPEG library version: library is %d, caller expects %d")
  150575. JMESSAGE(JERR_BAD_MCU_SIZE, "Sampling factors too large for interleaved scan")
  150576. JMESSAGE(JERR_BAD_POOL_ID, "Invalid memory pool code %d")
  150577. JMESSAGE(JERR_BAD_PRECISION, "Unsupported JPEG data precision %d")
  150578. JMESSAGE(JERR_BAD_PROGRESSION,
  150579. "Invalid progressive parameters Ss=%d Se=%d Ah=%d Al=%d")
  150580. JMESSAGE(JERR_BAD_PROG_SCRIPT,
  150581. "Invalid progressive parameters at scan script entry %d")
  150582. JMESSAGE(JERR_BAD_SAMPLING, "Bogus sampling factors")
  150583. JMESSAGE(JERR_BAD_SCAN_SCRIPT, "Invalid scan script at entry %d")
  150584. JMESSAGE(JERR_BAD_STATE, "Improper call to JPEG library in state %d")
  150585. JMESSAGE(JERR_BAD_STRUCT_SIZE,
  150586. "JPEG parameter struct mismatch: library thinks size is %u, caller expects %u")
  150587. JMESSAGE(JERR_BAD_VIRTUAL_ACCESS, "Bogus virtual array access")
  150588. JMESSAGE(JERR_BUFFER_SIZE, "Buffer passed to JPEG library is too small")
  150589. JMESSAGE(JERR_CANT_SUSPEND, "Suspension not allowed here")
  150590. JMESSAGE(JERR_CCIR601_NOTIMPL, "CCIR601 sampling not implemented yet")
  150591. JMESSAGE(JERR_COMPONENT_COUNT, "Too many color components: %d, max %d")
  150592. JMESSAGE(JERR_CONVERSION_NOTIMPL, "Unsupported color conversion request")
  150593. JMESSAGE(JERR_DAC_INDEX, "Bogus DAC index %d")
  150594. JMESSAGE(JERR_DAC_VALUE, "Bogus DAC value 0x%x")
  150595. JMESSAGE(JERR_DHT_INDEX, "Bogus DHT index %d")
  150596. JMESSAGE(JERR_DQT_INDEX, "Bogus DQT index %d")
  150597. JMESSAGE(JERR_EMPTY_IMAGE, "Empty JPEG image (DNL not supported)")
  150598. JMESSAGE(JERR_EMS_READ, "Read from EMS failed")
  150599. JMESSAGE(JERR_EMS_WRITE, "Write to EMS failed")
  150600. JMESSAGE(JERR_EOI_EXPECTED, "Didn't expect more than one scan")
  150601. JMESSAGE(JERR_FILE_READ, "Input file read error")
  150602. JMESSAGE(JERR_FILE_WRITE, "Output file write error --- out of disk space?")
  150603. JMESSAGE(JERR_FRACT_SAMPLE_NOTIMPL, "Fractional sampling not implemented yet")
  150604. JMESSAGE(JERR_HUFF_CLEN_OVERFLOW, "Huffman code size table overflow")
  150605. JMESSAGE(JERR_HUFF_MISSING_CODE, "Missing Huffman code table entry")
  150606. JMESSAGE(JERR_IMAGE_TOO_BIG, "Maximum supported image dimension is %u pixels")
  150607. JMESSAGE(JERR_INPUT_EMPTY, "Empty input file")
  150608. JMESSAGE(JERR_INPUT_EOF, "Premature end of input file")
  150609. JMESSAGE(JERR_MISMATCHED_QUANT_TABLE,
  150610. "Cannot transcode due to multiple use of quantization table %d")
  150611. JMESSAGE(JERR_MISSING_DATA, "Scan script does not transmit all data")
  150612. JMESSAGE(JERR_MODE_CHANGE, "Invalid color quantization mode change")
  150613. JMESSAGE(JERR_NOTIMPL, "Not implemented yet")
  150614. JMESSAGE(JERR_NOT_COMPILED, "Requested feature was omitted at compile time")
  150615. JMESSAGE(JERR_NO_BACKING_STORE, "Backing store not supported")
  150616. JMESSAGE(JERR_NO_HUFF_TABLE, "Huffman table 0x%02x was not defined")
  150617. JMESSAGE(JERR_NO_IMAGE, "JPEG datastream contains no image")
  150618. JMESSAGE(JERR_NO_QUANT_TABLE, "Quantization table 0x%02x was not defined")
  150619. JMESSAGE(JERR_NO_SOI, "Not a JPEG file: starts with 0x%02x 0x%02x")
  150620. JMESSAGE(JERR_OUT_OF_MEMORY, "Insufficient memory (case %d)")
  150621. JMESSAGE(JERR_QUANT_COMPONENTS,
  150622. "Cannot quantize more than %d color components")
  150623. JMESSAGE(JERR_QUANT_FEW_COLORS, "Cannot quantize to fewer than %d colors")
  150624. JMESSAGE(JERR_QUANT_MANY_COLORS, "Cannot quantize to more than %d colors")
  150625. JMESSAGE(JERR_SOF_DUPLICATE, "Invalid JPEG file structure: two SOF markers")
  150626. JMESSAGE(JERR_SOF_NO_SOS, "Invalid JPEG file structure: missing SOS marker")
  150627. JMESSAGE(JERR_SOF_UNSUPPORTED, "Unsupported JPEG process: SOF type 0x%02x")
  150628. JMESSAGE(JERR_SOI_DUPLICATE, "Invalid JPEG file structure: two SOI markers")
  150629. JMESSAGE(JERR_SOS_NO_SOF, "Invalid JPEG file structure: SOS before SOF")
  150630. JMESSAGE(JERR_TFILE_CREATE, "Failed to create temporary file %s")
  150631. JMESSAGE(JERR_TFILE_READ, "Read failed on temporary file")
  150632. JMESSAGE(JERR_TFILE_SEEK, "Seek failed on temporary file")
  150633. JMESSAGE(JERR_TFILE_WRITE,
  150634. "Write failed on temporary file --- out of disk space?")
  150635. JMESSAGE(JERR_TOO_LITTLE_DATA, "Application transferred too few scanlines")
  150636. JMESSAGE(JERR_UNKNOWN_MARKER, "Unsupported marker type 0x%02x")
  150637. JMESSAGE(JERR_VIRTUAL_BUG, "Virtual array controller messed up")
  150638. JMESSAGE(JERR_WIDTH_OVERFLOW, "Image too wide for this implementation")
  150639. JMESSAGE(JERR_XMS_READ, "Read from XMS failed")
  150640. JMESSAGE(JERR_XMS_WRITE, "Write to XMS failed")
  150641. JMESSAGE(JMSG_COPYRIGHT, JCOPYRIGHT)
  150642. JMESSAGE(JMSG_VERSION, JVERSION)
  150643. JMESSAGE(JTRC_16BIT_TABLES,
  150644. "Caution: quantization tables are too coarse for baseline JPEG")
  150645. JMESSAGE(JTRC_ADOBE,
  150646. "Adobe APP14 marker: version %d, flags 0x%04x 0x%04x, transform %d")
  150647. JMESSAGE(JTRC_APP0, "Unknown APP0 marker (not JFIF), length %u")
  150648. JMESSAGE(JTRC_APP14, "Unknown APP14 marker (not Adobe), length %u")
  150649. JMESSAGE(JTRC_DAC, "Define Arithmetic Table 0x%02x: 0x%02x")
  150650. JMESSAGE(JTRC_DHT, "Define Huffman Table 0x%02x")
  150651. JMESSAGE(JTRC_DQT, "Define Quantization Table %d precision %d")
  150652. JMESSAGE(JTRC_DRI, "Define Restart Interval %u")
  150653. JMESSAGE(JTRC_EMS_CLOSE, "Freed EMS handle %u")
  150654. JMESSAGE(JTRC_EMS_OPEN, "Obtained EMS handle %u")
  150655. JMESSAGE(JTRC_EOI, "End Of Image")
  150656. JMESSAGE(JTRC_HUFFBITS, " %3d %3d %3d %3d %3d %3d %3d %3d")
  150657. JMESSAGE(JTRC_JFIF, "JFIF APP0 marker: version %d.%02d, density %dx%d %d")
  150658. JMESSAGE(JTRC_JFIF_BADTHUMBNAILSIZE,
  150659. "Warning: thumbnail image size does not match data length %u")
  150660. JMESSAGE(JTRC_JFIF_EXTENSION,
  150661. "JFIF extension marker: type 0x%02x, length %u")
  150662. JMESSAGE(JTRC_JFIF_THUMBNAIL, " with %d x %d thumbnail image")
  150663. JMESSAGE(JTRC_MISC_MARKER, "Miscellaneous marker 0x%02x, length %u")
  150664. JMESSAGE(JTRC_PARMLESS_MARKER, "Unexpected marker 0x%02x")
  150665. JMESSAGE(JTRC_QUANTVALS, " %4u %4u %4u %4u %4u %4u %4u %4u")
  150666. JMESSAGE(JTRC_QUANT_3_NCOLORS, "Quantizing to %d = %d*%d*%d colors")
  150667. JMESSAGE(JTRC_QUANT_NCOLORS, "Quantizing to %d colors")
  150668. JMESSAGE(JTRC_QUANT_SELECTED, "Selected %d colors for quantization")
  150669. JMESSAGE(JTRC_RECOVERY_ACTION, "At marker 0x%02x, recovery action %d")
  150670. JMESSAGE(JTRC_RST, "RST%d")
  150671. JMESSAGE(JTRC_SMOOTH_NOTIMPL,
  150672. "Smoothing not supported with nonstandard sampling ratios")
  150673. JMESSAGE(JTRC_SOF, "Start Of Frame 0x%02x: width=%u, height=%u, components=%d")
  150674. JMESSAGE(JTRC_SOF_COMPONENT, " Component %d: %dhx%dv q=%d")
  150675. JMESSAGE(JTRC_SOI, "Start of Image")
  150676. JMESSAGE(JTRC_SOS, "Start Of Scan: %d components")
  150677. JMESSAGE(JTRC_SOS_COMPONENT, " Component %d: dc=%d ac=%d")
  150678. JMESSAGE(JTRC_SOS_PARAMS, " Ss=%d, Se=%d, Ah=%d, Al=%d")
  150679. JMESSAGE(JTRC_TFILE_CLOSE, "Closed temporary file %s")
  150680. JMESSAGE(JTRC_TFILE_OPEN, "Opened temporary file %s")
  150681. JMESSAGE(JTRC_THUMB_JPEG,
  150682. "JFIF extension marker: JPEG-compressed thumbnail image, length %u")
  150683. JMESSAGE(JTRC_THUMB_PALETTE,
  150684. "JFIF extension marker: palette thumbnail image, length %u")
  150685. JMESSAGE(JTRC_THUMB_RGB,
  150686. "JFIF extension marker: RGB thumbnail image, length %u")
  150687. JMESSAGE(JTRC_UNKNOWN_IDS,
  150688. "Unrecognized component IDs %d %d %d, assuming YCbCr")
  150689. JMESSAGE(JTRC_XMS_CLOSE, "Freed XMS handle %u")
  150690. JMESSAGE(JTRC_XMS_OPEN, "Obtained XMS handle %u")
  150691. JMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d")
  150692. JMESSAGE(JWRN_BOGUS_PROGRESSION,
  150693. "Inconsistent progression sequence for component %d coefficient %d")
  150694. JMESSAGE(JWRN_EXTRANEOUS_DATA,
  150695. "Corrupt JPEG data: %u extraneous bytes before marker 0x%02x")
  150696. JMESSAGE(JWRN_HIT_MARKER, "Corrupt JPEG data: premature end of data segment")
  150697. JMESSAGE(JWRN_HUFF_BAD_CODE, "Corrupt JPEG data: bad Huffman code")
  150698. JMESSAGE(JWRN_JFIF_MAJOR, "Warning: unknown JFIF revision number %d.%02d")
  150699. JMESSAGE(JWRN_JPEG_EOF, "Premature end of JPEG file")
  150700. JMESSAGE(JWRN_MUST_RESYNC,
  150701. "Corrupt JPEG data: found marker 0x%02x instead of RST%d")
  150702. JMESSAGE(JWRN_NOT_SEQUENTIAL, "Invalid SOS parameters for sequential JPEG")
  150703. JMESSAGE(JWRN_TOO_MUCH_DATA, "Application transferred too many scanlines")
  150704. #ifdef JMAKE_ENUM_LIST
  150705. JMSG_LASTMSGCODE
  150706. } J_MESSAGE_CODE;
  150707. #undef JMAKE_ENUM_LIST
  150708. #endif /* JMAKE_ENUM_LIST */
  150709. #undef JMESSAGE
  150710. #ifndef JERROR_H
  150711. #define JERROR_H
  150712. #define ERREXIT(cinfo,code) \
  150713. ((cinfo)->err->msg_code = (code), \
  150714. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150715. #define ERREXIT1(cinfo,code,p1) \
  150716. ((cinfo)->err->msg_code = (code), \
  150717. (cinfo)->err->msg_parm.i[0] = (p1), \
  150718. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150719. #define ERREXIT2(cinfo,code,p1,p2) \
  150720. ((cinfo)->err->msg_code = (code), \
  150721. (cinfo)->err->msg_parm.i[0] = (p1), \
  150722. (cinfo)->err->msg_parm.i[1] = (p2), \
  150723. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150724. #define ERREXIT3(cinfo,code,p1,p2,p3) \
  150725. ((cinfo)->err->msg_code = (code), \
  150726. (cinfo)->err->msg_parm.i[0] = (p1), \
  150727. (cinfo)->err->msg_parm.i[1] = (p2), \
  150728. (cinfo)->err->msg_parm.i[2] = (p3), \
  150729. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150730. #define ERREXIT4(cinfo,code,p1,p2,p3,p4) \
  150731. ((cinfo)->err->msg_code = (code), \
  150732. (cinfo)->err->msg_parm.i[0] = (p1), \
  150733. (cinfo)->err->msg_parm.i[1] = (p2), \
  150734. (cinfo)->err->msg_parm.i[2] = (p3), \
  150735. (cinfo)->err->msg_parm.i[3] = (p4), \
  150736. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150737. #define ERREXITS(cinfo,code,str) \
  150738. ((cinfo)->err->msg_code = (code), \
  150739. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  150740. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150741. #define MAKESTMT(stuff) do { stuff } while (0)
  150742. #define WARNMS(cinfo,code) \
  150743. ((cinfo)->err->msg_code = (code), \
  150744. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  150745. #define WARNMS1(cinfo,code,p1) \
  150746. ((cinfo)->err->msg_code = (code), \
  150747. (cinfo)->err->msg_parm.i[0] = (p1), \
  150748. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  150749. #define WARNMS2(cinfo,code,p1,p2) \
  150750. ((cinfo)->err->msg_code = (code), \
  150751. (cinfo)->err->msg_parm.i[0] = (p1), \
  150752. (cinfo)->err->msg_parm.i[1] = (p2), \
  150753. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  150754. #define TRACEMS(cinfo,lvl,code) \
  150755. ((cinfo)->err->msg_code = (code), \
  150756. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  150757. #define TRACEMS1(cinfo,lvl,code,p1) \
  150758. ((cinfo)->err->msg_code = (code), \
  150759. (cinfo)->err->msg_parm.i[0] = (p1), \
  150760. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  150761. #define TRACEMS2(cinfo,lvl,code,p1,p2) \
  150762. ((cinfo)->err->msg_code = (code), \
  150763. (cinfo)->err->msg_parm.i[0] = (p1), \
  150764. (cinfo)->err->msg_parm.i[1] = (p2), \
  150765. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  150766. #define TRACEMS3(cinfo,lvl,code,p1,p2,p3) \
  150767. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  150768. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); \
  150769. (cinfo)->err->msg_code = (code); \
  150770. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  150771. #define TRACEMS4(cinfo,lvl,code,p1,p2,p3,p4) \
  150772. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  150773. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  150774. (cinfo)->err->msg_code = (code); \
  150775. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  150776. #define TRACEMS5(cinfo,lvl,code,p1,p2,p3,p4,p5) \
  150777. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  150778. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  150779. _mp[4] = (p5); \
  150780. (cinfo)->err->msg_code = (code); \
  150781. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  150782. #define TRACEMS8(cinfo,lvl,code,p1,p2,p3,p4,p5,p6,p7,p8) \
  150783. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  150784. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  150785. _mp[4] = (p5); _mp[5] = (p6); _mp[6] = (p7); _mp[7] = (p8); \
  150786. (cinfo)->err->msg_code = (code); \
  150787. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  150788. #define TRACEMSS(cinfo,lvl,code,str) \
  150789. ((cinfo)->err->msg_code = (code), \
  150790. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  150791. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  150792. #endif /* JERROR_H */
  150793. /*** End of inlined file: jerror.h ***/
  150794. typedef struct {
  150795. struct jpeg_source_mgr pub; /* public fields */
  150796. FILE * infile; /* source stream */
  150797. JOCTET * buffer; /* start of buffer */
  150798. boolean start_of_file; /* have we gotten any data yet? */
  150799. } my_source_mgr;
  150800. typedef my_source_mgr * my_src_ptr;
  150801. #define INPUT_BUF_SIZE 4096 /* choose an efficiently fread'able size */
  150802. METHODDEF(void)
  150803. init_source (j_decompress_ptr cinfo)
  150804. {
  150805. my_src_ptr src = (my_src_ptr) cinfo->src;
  150806. src->start_of_file = TRUE;
  150807. }
  150808. METHODDEF(boolean)
  150809. fill_input_buffer (j_decompress_ptr cinfo)
  150810. {
  150811. my_src_ptr src = (my_src_ptr) cinfo->src;
  150812. size_t nbytes;
  150813. nbytes = JFREAD(src->infile, src->buffer, INPUT_BUF_SIZE);
  150814. if (nbytes <= 0) {
  150815. if (src->start_of_file) /* Treat empty input file as fatal error */
  150816. ERREXIT(cinfo, JERR_INPUT_EMPTY);
  150817. WARNMS(cinfo, JWRN_JPEG_EOF);
  150818. src->buffer[0] = (JOCTET) 0xFF;
  150819. src->buffer[1] = (JOCTET) JPEG_EOI;
  150820. nbytes = 2;
  150821. }
  150822. src->pub.next_input_byte = src->buffer;
  150823. src->pub.bytes_in_buffer = nbytes;
  150824. src->start_of_file = FALSE;
  150825. return TRUE;
  150826. }
  150827. METHODDEF(void)
  150828. skip_input_data (j_decompress_ptr cinfo, long num_bytes)
  150829. {
  150830. my_src_ptr src = (my_src_ptr) cinfo->src;
  150831. if (num_bytes > 0) {
  150832. while (num_bytes > (long) src->pub.bytes_in_buffer) {
  150833. num_bytes -= (long) src->pub.bytes_in_buffer;
  150834. (void) fill_input_buffer(cinfo);
  150835. }
  150836. src->pub.next_input_byte += (size_t) num_bytes;
  150837. src->pub.bytes_in_buffer -= (size_t) num_bytes;
  150838. }
  150839. }
  150840. METHODDEF(void)
  150841. term_source (j_decompress_ptr cinfo)
  150842. {
  150843. }
  150844. GLOBAL(void)
  150845. jpeg_stdio_src (j_decompress_ptr cinfo, FILE * infile)
  150846. {
  150847. my_src_ptr src;
  150848. if (cinfo->src == NULL) { /* first time for this JPEG object? */
  150849. cinfo->src = (struct jpeg_source_mgr *)
  150850. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  150851. SIZEOF(my_source_mgr));
  150852. src = (my_src_ptr) cinfo->src;
  150853. src->buffer = (JOCTET *)
  150854. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  150855. INPUT_BUF_SIZE * SIZEOF(JOCTET));
  150856. }
  150857. src = (my_src_ptr) cinfo->src;
  150858. src->pub.init_source = init_source;
  150859. src->pub.fill_input_buffer = fill_input_buffer;
  150860. src->pub.skip_input_data = skip_input_data;
  150861. src->pub.resync_to_restart = jpeg_resync_to_restart; /* use default method */
  150862. src->pub.term_source = term_source;
  150863. src->infile = infile;
  150864. src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */
  150865. src->pub.next_input_byte = NULL; /* until buffer loaded */
  150866. }
  150867. /*** End of inlined file: jdatasrc.c ***/
  150868. /*** Start of inlined file: jdcoefct.c ***/
  150869. #define JPEG_INTERNALS
  150870. #ifndef D_PROGRESSIVE_SUPPORTED
  150871. #undef BLOCK_SMOOTHING_SUPPORTED
  150872. #endif
  150873. typedef struct {
  150874. struct jpeg_d_coef_controller pub; /* public fields */
  150875. JDIMENSION MCU_ctr; /* counts MCUs processed in current row */
  150876. int MCU_vert_offset; /* counts MCU rows within iMCU row */
  150877. int MCU_rows_per_iMCU_row; /* number of such rows needed */
  150878. JBLOCKROW MCU_buffer[D_MAX_BLOCKS_IN_MCU];
  150879. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150880. jvirt_barray_ptr whole_image[MAX_COMPONENTS];
  150881. #endif
  150882. #ifdef BLOCK_SMOOTHING_SUPPORTED
  150883. int * coef_bits_latch;
  150884. #define SAVED_COEFS 6 /* we save coef_bits[0..5] */
  150885. #endif
  150886. } my_coef_controller3;
  150887. typedef my_coef_controller3 * my_coef_ptr3;
  150888. METHODDEF(int) decompress_onepass
  150889. JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
  150890. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150891. METHODDEF(int) decompress_data
  150892. JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
  150893. #endif
  150894. #ifdef BLOCK_SMOOTHING_SUPPORTED
  150895. LOCAL(boolean) smoothing_ok JPP((j_decompress_ptr cinfo));
  150896. METHODDEF(int) decompress_smooth_data
  150897. JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
  150898. #endif
  150899. LOCAL(void)
  150900. start_iMCU_row3 (j_decompress_ptr cinfo)
  150901. {
  150902. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  150903. if (cinfo->comps_in_scan > 1) {
  150904. coef->MCU_rows_per_iMCU_row = 1;
  150905. } else {
  150906. if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
  150907. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
  150908. else
  150909. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  150910. }
  150911. coef->MCU_ctr = 0;
  150912. coef->MCU_vert_offset = 0;
  150913. }
  150914. METHODDEF(void)
  150915. start_input_pass (j_decompress_ptr cinfo)
  150916. {
  150917. cinfo->input_iMCU_row = 0;
  150918. start_iMCU_row3(cinfo);
  150919. }
  150920. METHODDEF(void)
  150921. start_output_pass (j_decompress_ptr cinfo)
  150922. {
  150923. #ifdef BLOCK_SMOOTHING_SUPPORTED
  150924. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  150925. if (coef->pub.coef_arrays != NULL) {
  150926. if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
  150927. coef->pub.decompress_data = decompress_smooth_data;
  150928. else
  150929. coef->pub.decompress_data = decompress_data;
  150930. }
  150931. #endif
  150932. cinfo->output_iMCU_row = 0;
  150933. }
  150934. METHODDEF(int)
  150935. decompress_onepass (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
  150936. {
  150937. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  150938. JDIMENSION MCU_col_num; /* index of current MCU within row */
  150939. JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  150940. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  150941. int blkn, ci, xindex, yindex, yoffset, useful_width;
  150942. JSAMPARRAY output_ptr;
  150943. JDIMENSION start_col, output_col;
  150944. jpeg_component_info *compptr;
  150945. inverse_DCT_method_ptr inverse_DCT;
  150946. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  150947. yoffset++) {
  150948. for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
  150949. MCU_col_num++) {
  150950. jzero_far((void FAR *) coef->MCU_buffer[0],
  150951. (size_t) (cinfo->blocks_in_MCU * SIZEOF(JBLOCK)));
  150952. if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
  150953. coef->MCU_vert_offset = yoffset;
  150954. coef->MCU_ctr = MCU_col_num;
  150955. return JPEG_SUSPENDED;
  150956. }
  150957. blkn = 0; /* index of current DCT block within MCU */
  150958. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  150959. compptr = cinfo->cur_comp_info[ci];
  150960. if (! compptr->component_needed) {
  150961. blkn += compptr->MCU_blocks;
  150962. continue;
  150963. }
  150964. inverse_DCT = cinfo->idct->inverse_DCT[compptr->component_index];
  150965. useful_width = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
  150966. : compptr->last_col_width;
  150967. output_ptr = output_buf[compptr->component_index] +
  150968. yoffset * compptr->DCT_scaled_size;
  150969. start_col = MCU_col_num * compptr->MCU_sample_width;
  150970. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  150971. if (cinfo->input_iMCU_row < last_iMCU_row ||
  150972. yoffset+yindex < compptr->last_row_height) {
  150973. output_col = start_col;
  150974. for (xindex = 0; xindex < useful_width; xindex++) {
  150975. (*inverse_DCT) (cinfo, compptr,
  150976. (JCOEFPTR) coef->MCU_buffer[blkn+xindex],
  150977. output_ptr, output_col);
  150978. output_col += compptr->DCT_scaled_size;
  150979. }
  150980. }
  150981. blkn += compptr->MCU_width;
  150982. output_ptr += compptr->DCT_scaled_size;
  150983. }
  150984. }
  150985. }
  150986. coef->MCU_ctr = 0;
  150987. }
  150988. cinfo->output_iMCU_row++;
  150989. if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
  150990. start_iMCU_row3(cinfo);
  150991. return JPEG_ROW_COMPLETED;
  150992. }
  150993. (*cinfo->inputctl->finish_input_pass) (cinfo);
  150994. return JPEG_SCAN_COMPLETED;
  150995. }
  150996. METHODDEF(int)
  150997. dummy_consume_data (j_decompress_ptr cinfo)
  150998. {
  150999. return JPEG_SUSPENDED; /* Always indicate nothing was done */
  151000. }
  151001. #ifdef D_MULTISCAN_FILES_SUPPORTED
  151002. METHODDEF(int)
  151003. consume_data (j_decompress_ptr cinfo)
  151004. {
  151005. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151006. JDIMENSION MCU_col_num; /* index of current MCU within row */
  151007. int blkn, ci, xindex, yindex, yoffset;
  151008. JDIMENSION start_col;
  151009. JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  151010. JBLOCKROW buffer_ptr;
  151011. jpeg_component_info *compptr;
  151012. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  151013. compptr = cinfo->cur_comp_info[ci];
  151014. buffer[ci] = (*cinfo->mem->access_virt_barray)
  151015. ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
  151016. cinfo->input_iMCU_row * compptr->v_samp_factor,
  151017. (JDIMENSION) compptr->v_samp_factor, TRUE);
  151018. }
  151019. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  151020. yoffset++) {
  151021. for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
  151022. MCU_col_num++) {
  151023. blkn = 0; /* index of current DCT block within MCU */
  151024. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  151025. compptr = cinfo->cur_comp_info[ci];
  151026. start_col = MCU_col_num * compptr->MCU_width;
  151027. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  151028. buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
  151029. for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
  151030. coef->MCU_buffer[blkn++] = buffer_ptr++;
  151031. }
  151032. }
  151033. }
  151034. if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
  151035. coef->MCU_vert_offset = yoffset;
  151036. coef->MCU_ctr = MCU_col_num;
  151037. return JPEG_SUSPENDED;
  151038. }
  151039. }
  151040. coef->MCU_ctr = 0;
  151041. }
  151042. if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
  151043. start_iMCU_row3(cinfo);
  151044. return JPEG_ROW_COMPLETED;
  151045. }
  151046. (*cinfo->inputctl->finish_input_pass) (cinfo);
  151047. return JPEG_SCAN_COMPLETED;
  151048. }
  151049. METHODDEF(int)
  151050. decompress_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
  151051. {
  151052. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151053. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  151054. JDIMENSION block_num;
  151055. int ci, block_row, block_rows;
  151056. JBLOCKARRAY buffer;
  151057. JBLOCKROW buffer_ptr;
  151058. JSAMPARRAY output_ptr;
  151059. JDIMENSION output_col;
  151060. jpeg_component_info *compptr;
  151061. inverse_DCT_method_ptr inverse_DCT;
  151062. while (cinfo->input_scan_number < cinfo->output_scan_number ||
  151063. (cinfo->input_scan_number == cinfo->output_scan_number &&
  151064. cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
  151065. if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED)
  151066. return JPEG_SUSPENDED;
  151067. }
  151068. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151069. ci++, compptr++) {
  151070. if (! compptr->component_needed)
  151071. continue;
  151072. buffer = (*cinfo->mem->access_virt_barray)
  151073. ((j_common_ptr) cinfo, coef->whole_image[ci],
  151074. cinfo->output_iMCU_row * compptr->v_samp_factor,
  151075. (JDIMENSION) compptr->v_samp_factor, FALSE);
  151076. if (cinfo->output_iMCU_row < last_iMCU_row)
  151077. block_rows = compptr->v_samp_factor;
  151078. else {
  151079. block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  151080. if (block_rows == 0) block_rows = compptr->v_samp_factor;
  151081. }
  151082. inverse_DCT = cinfo->idct->inverse_DCT[ci];
  151083. output_ptr = output_buf[ci];
  151084. for (block_row = 0; block_row < block_rows; block_row++) {
  151085. buffer_ptr = buffer[block_row];
  151086. output_col = 0;
  151087. for (block_num = 0; block_num < compptr->width_in_blocks; block_num++) {
  151088. (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) buffer_ptr,
  151089. output_ptr, output_col);
  151090. buffer_ptr++;
  151091. output_col += compptr->DCT_scaled_size;
  151092. }
  151093. output_ptr += compptr->DCT_scaled_size;
  151094. }
  151095. }
  151096. if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
  151097. return JPEG_ROW_COMPLETED;
  151098. return JPEG_SCAN_COMPLETED;
  151099. }
  151100. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  151101. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151102. #define Q01_POS 1
  151103. #define Q10_POS 8
  151104. #define Q20_POS 16
  151105. #define Q11_POS 9
  151106. #define Q02_POS 2
  151107. LOCAL(boolean)
  151108. smoothing_ok (j_decompress_ptr cinfo)
  151109. {
  151110. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151111. boolean smoothing_useful = FALSE;
  151112. int ci, coefi;
  151113. jpeg_component_info *compptr;
  151114. JQUANT_TBL * qtable;
  151115. int * coef_bits;
  151116. int * coef_bits_latch;
  151117. if (! cinfo->progressive_mode || cinfo->coef_bits == NULL)
  151118. return FALSE;
  151119. if (coef->coef_bits_latch == NULL)
  151120. coef->coef_bits_latch = (int *)
  151121. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151122. cinfo->num_components *
  151123. (SAVED_COEFS * SIZEOF(int)));
  151124. coef_bits_latch = coef->coef_bits_latch;
  151125. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151126. ci++, compptr++) {
  151127. if ((qtable = compptr->quant_table) == NULL)
  151128. return FALSE;
  151129. if (qtable->quantval[0] == 0 ||
  151130. qtable->quantval[Q01_POS] == 0 ||
  151131. qtable->quantval[Q10_POS] == 0 ||
  151132. qtable->quantval[Q20_POS] == 0 ||
  151133. qtable->quantval[Q11_POS] == 0 ||
  151134. qtable->quantval[Q02_POS] == 0)
  151135. return FALSE;
  151136. coef_bits = cinfo->coef_bits[ci];
  151137. if (coef_bits[0] < 0)
  151138. return FALSE;
  151139. for (coefi = 1; coefi <= 5; coefi++) {
  151140. coef_bits_latch[coefi] = coef_bits[coefi];
  151141. if (coef_bits[coefi] != 0)
  151142. smoothing_useful = TRUE;
  151143. }
  151144. coef_bits_latch += SAVED_COEFS;
  151145. }
  151146. return smoothing_useful;
  151147. }
  151148. METHODDEF(int)
  151149. decompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
  151150. {
  151151. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151152. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  151153. JDIMENSION block_num, last_block_column;
  151154. int ci, block_row, block_rows, access_rows;
  151155. JBLOCKARRAY buffer;
  151156. JBLOCKROW buffer_ptr, prev_block_row, next_block_row;
  151157. JSAMPARRAY output_ptr;
  151158. JDIMENSION output_col;
  151159. jpeg_component_info *compptr;
  151160. inverse_DCT_method_ptr inverse_DCT;
  151161. boolean first_row, last_row;
  151162. JBLOCK workspace;
  151163. int *coef_bits;
  151164. JQUANT_TBL *quanttbl;
  151165. INT32 Q00,Q01,Q02,Q10,Q11,Q20, num;
  151166. int DC1,DC2,DC3,DC4,DC5,DC6,DC7,DC8,DC9;
  151167. int Al, pred;
  151168. while (cinfo->input_scan_number <= cinfo->output_scan_number &&
  151169. ! cinfo->inputctl->eoi_reached) {
  151170. if (cinfo->input_scan_number == cinfo->output_scan_number) {
  151171. JDIMENSION delta = (cinfo->Ss == 0) ? 1 : 0;
  151172. if (cinfo->input_iMCU_row > cinfo->output_iMCU_row+delta)
  151173. break;
  151174. }
  151175. if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED)
  151176. return JPEG_SUSPENDED;
  151177. }
  151178. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151179. ci++, compptr++) {
  151180. if (! compptr->component_needed)
  151181. continue;
  151182. if (cinfo->output_iMCU_row < last_iMCU_row) {
  151183. block_rows = compptr->v_samp_factor;
  151184. access_rows = block_rows * 2; /* this and next iMCU row */
  151185. last_row = FALSE;
  151186. } else {
  151187. block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  151188. if (block_rows == 0) block_rows = compptr->v_samp_factor;
  151189. access_rows = block_rows; /* this iMCU row only */
  151190. last_row = TRUE;
  151191. }
  151192. if (cinfo->output_iMCU_row > 0) {
  151193. access_rows += compptr->v_samp_factor; /* prior iMCU row too */
  151194. buffer = (*cinfo->mem->access_virt_barray)
  151195. ((j_common_ptr) cinfo, coef->whole_image[ci],
  151196. (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
  151197. (JDIMENSION) access_rows, FALSE);
  151198. buffer += compptr->v_samp_factor; /* point to current iMCU row */
  151199. first_row = FALSE;
  151200. } else {
  151201. buffer = (*cinfo->mem->access_virt_barray)
  151202. ((j_common_ptr) cinfo, coef->whole_image[ci],
  151203. (JDIMENSION) 0, (JDIMENSION) access_rows, FALSE);
  151204. first_row = TRUE;
  151205. }
  151206. coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
  151207. quanttbl = compptr->quant_table;
  151208. Q00 = quanttbl->quantval[0];
  151209. Q01 = quanttbl->quantval[Q01_POS];
  151210. Q10 = quanttbl->quantval[Q10_POS];
  151211. Q20 = quanttbl->quantval[Q20_POS];
  151212. Q11 = quanttbl->quantval[Q11_POS];
  151213. Q02 = quanttbl->quantval[Q02_POS];
  151214. inverse_DCT = cinfo->idct->inverse_DCT[ci];
  151215. output_ptr = output_buf[ci];
  151216. for (block_row = 0; block_row < block_rows; block_row++) {
  151217. buffer_ptr = buffer[block_row];
  151218. if (first_row && block_row == 0)
  151219. prev_block_row = buffer_ptr;
  151220. else
  151221. prev_block_row = buffer[block_row-1];
  151222. if (last_row && block_row == block_rows-1)
  151223. next_block_row = buffer_ptr;
  151224. else
  151225. next_block_row = buffer[block_row+1];
  151226. DC1 = DC2 = DC3 = (int) prev_block_row[0][0];
  151227. DC4 = DC5 = DC6 = (int) buffer_ptr[0][0];
  151228. DC7 = DC8 = DC9 = (int) next_block_row[0][0];
  151229. output_col = 0;
  151230. last_block_column = compptr->width_in_blocks - 1;
  151231. for (block_num = 0; block_num <= last_block_column; block_num++) {
  151232. jcopy_block_row(buffer_ptr, (JBLOCKROW) workspace, (JDIMENSION) 1);
  151233. if (block_num < last_block_column) {
  151234. DC3 = (int) prev_block_row[1][0];
  151235. DC6 = (int) buffer_ptr[1][0];
  151236. DC9 = (int) next_block_row[1][0];
  151237. }
  151238. if ((Al=coef_bits[1]) != 0 && workspace[1] == 0) {
  151239. num = 36 * Q00 * (DC4 - DC6);
  151240. if (num >= 0) {
  151241. pred = (int) (((Q01<<7) + num) / (Q01<<8));
  151242. if (Al > 0 && pred >= (1<<Al))
  151243. pred = (1<<Al)-1;
  151244. } else {
  151245. pred = (int) (((Q01<<7) - num) / (Q01<<8));
  151246. if (Al > 0 && pred >= (1<<Al))
  151247. pred = (1<<Al)-1;
  151248. pred = -pred;
  151249. }
  151250. workspace[1] = (JCOEF) pred;
  151251. }
  151252. if ((Al=coef_bits[2]) != 0 && workspace[8] == 0) {
  151253. num = 36 * Q00 * (DC2 - DC8);
  151254. if (num >= 0) {
  151255. pred = (int) (((Q10<<7) + num) / (Q10<<8));
  151256. if (Al > 0 && pred >= (1<<Al))
  151257. pred = (1<<Al)-1;
  151258. } else {
  151259. pred = (int) (((Q10<<7) - num) / (Q10<<8));
  151260. if (Al > 0 && pred >= (1<<Al))
  151261. pred = (1<<Al)-1;
  151262. pred = -pred;
  151263. }
  151264. workspace[8] = (JCOEF) pred;
  151265. }
  151266. if ((Al=coef_bits[3]) != 0 && workspace[16] == 0) {
  151267. num = 9 * Q00 * (DC2 + DC8 - 2*DC5);
  151268. if (num >= 0) {
  151269. pred = (int) (((Q20<<7) + num) / (Q20<<8));
  151270. if (Al > 0 && pred >= (1<<Al))
  151271. pred = (1<<Al)-1;
  151272. } else {
  151273. pred = (int) (((Q20<<7) - num) / (Q20<<8));
  151274. if (Al > 0 && pred >= (1<<Al))
  151275. pred = (1<<Al)-1;
  151276. pred = -pred;
  151277. }
  151278. workspace[16] = (JCOEF) pred;
  151279. }
  151280. if ((Al=coef_bits[4]) != 0 && workspace[9] == 0) {
  151281. num = 5 * Q00 * (DC1 - DC3 - DC7 + DC9);
  151282. if (num >= 0) {
  151283. pred = (int) (((Q11<<7) + num) / (Q11<<8));
  151284. if (Al > 0 && pred >= (1<<Al))
  151285. pred = (1<<Al)-1;
  151286. } else {
  151287. pred = (int) (((Q11<<7) - num) / (Q11<<8));
  151288. if (Al > 0 && pred >= (1<<Al))
  151289. pred = (1<<Al)-1;
  151290. pred = -pred;
  151291. }
  151292. workspace[9] = (JCOEF) pred;
  151293. }
  151294. if ((Al=coef_bits[5]) != 0 && workspace[2] == 0) {
  151295. num = 9 * Q00 * (DC4 + DC6 - 2*DC5);
  151296. if (num >= 0) {
  151297. pred = (int) (((Q02<<7) + num) / (Q02<<8));
  151298. if (Al > 0 && pred >= (1<<Al))
  151299. pred = (1<<Al)-1;
  151300. } else {
  151301. pred = (int) (((Q02<<7) - num) / (Q02<<8));
  151302. if (Al > 0 && pred >= (1<<Al))
  151303. pred = (1<<Al)-1;
  151304. pred = -pred;
  151305. }
  151306. workspace[2] = (JCOEF) pred;
  151307. }
  151308. (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) workspace,
  151309. output_ptr, output_col);
  151310. DC1 = DC2; DC2 = DC3;
  151311. DC4 = DC5; DC5 = DC6;
  151312. DC7 = DC8; DC8 = DC9;
  151313. buffer_ptr++, prev_block_row++, next_block_row++;
  151314. output_col += compptr->DCT_scaled_size;
  151315. }
  151316. output_ptr += compptr->DCT_scaled_size;
  151317. }
  151318. }
  151319. if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
  151320. return JPEG_ROW_COMPLETED;
  151321. return JPEG_SCAN_COMPLETED;
  151322. }
  151323. #endif /* BLOCK_SMOOTHING_SUPPORTED */
  151324. GLOBAL(void)
  151325. jinit_d_coef_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
  151326. {
  151327. my_coef_ptr3 coef;
  151328. coef = (my_coef_ptr3)
  151329. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151330. SIZEOF(my_coef_controller3));
  151331. cinfo->coef = (struct jpeg_d_coef_controller *) coef;
  151332. coef->pub.start_input_pass = start_input_pass;
  151333. coef->pub.start_output_pass = start_output_pass;
  151334. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151335. coef->coef_bits_latch = NULL;
  151336. #endif
  151337. if (need_full_buffer) {
  151338. #ifdef D_MULTISCAN_FILES_SUPPORTED
  151339. int ci, access_rows;
  151340. jpeg_component_info *compptr;
  151341. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151342. ci++, compptr++) {
  151343. access_rows = compptr->v_samp_factor;
  151344. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151345. if (cinfo->progressive_mode)
  151346. access_rows *= 3;
  151347. #endif
  151348. coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
  151349. ((j_common_ptr) cinfo, JPOOL_IMAGE, TRUE,
  151350. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  151351. (long) compptr->h_samp_factor),
  151352. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  151353. (long) compptr->v_samp_factor),
  151354. (JDIMENSION) access_rows);
  151355. }
  151356. coef->pub.consume_data = consume_data;
  151357. coef->pub.decompress_data = decompress_data;
  151358. coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
  151359. #else
  151360. ERREXIT(cinfo, JERR_NOT_COMPILED);
  151361. #endif
  151362. } else {
  151363. JBLOCKROW buffer;
  151364. int i;
  151365. buffer = (JBLOCKROW)
  151366. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151367. D_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  151368. for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
  151369. coef->MCU_buffer[i] = buffer + i;
  151370. }
  151371. coef->pub.consume_data = dummy_consume_data;
  151372. coef->pub.decompress_data = decompress_onepass;
  151373. coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
  151374. }
  151375. }
  151376. /*** End of inlined file: jdcoefct.c ***/
  151377. #undef FIX
  151378. /*** Start of inlined file: jdcolor.c ***/
  151379. #define JPEG_INTERNALS
  151380. typedef struct {
  151381. struct jpeg_color_deconverter pub; /* public fields */
  151382. int * Cr_r_tab; /* => table for Cr to R conversion */
  151383. int * Cb_b_tab; /* => table for Cb to B conversion */
  151384. INT32 * Cr_g_tab; /* => table for Cr to G conversion */
  151385. INT32 * Cb_g_tab; /* => table for Cb to G conversion */
  151386. } my_color_deconverter2;
  151387. typedef my_color_deconverter2 * my_cconvert_ptr2;
  151388. #define SCALEBITS 16 /* speediest right-shift on some machines */
  151389. #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
  151390. #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
  151391. LOCAL(void)
  151392. build_ycc_rgb_table (j_decompress_ptr cinfo)
  151393. {
  151394. my_cconvert_ptr2 cconvert = (my_cconvert_ptr2) cinfo->cconvert;
  151395. int i;
  151396. INT32 x;
  151397. SHIFT_TEMPS
  151398. cconvert->Cr_r_tab = (int *)
  151399. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151400. (MAXJSAMPLE+1) * SIZEOF(int));
  151401. cconvert->Cb_b_tab = (int *)
  151402. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151403. (MAXJSAMPLE+1) * SIZEOF(int));
  151404. cconvert->Cr_g_tab = (INT32 *)
  151405. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151406. (MAXJSAMPLE+1) * SIZEOF(INT32));
  151407. cconvert->Cb_g_tab = (INT32 *)
  151408. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151409. (MAXJSAMPLE+1) * SIZEOF(INT32));
  151410. for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
  151411. cconvert->Cr_r_tab[i] = (int)
  151412. RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
  151413. cconvert->Cb_b_tab[i] = (int)
  151414. RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
  151415. cconvert->Cr_g_tab[i] = (- FIX(0.71414)) * x;
  151416. cconvert->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF;
  151417. }
  151418. }
  151419. METHODDEF(void)
  151420. ycc_rgb_convert (j_decompress_ptr cinfo,
  151421. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151422. JSAMPARRAY output_buf, int num_rows)
  151423. {
  151424. my_cconvert_ptr2 cconvert = (my_cconvert_ptr2) cinfo->cconvert;
  151425. register int y, cb, cr;
  151426. register JSAMPROW outptr;
  151427. register JSAMPROW inptr0, inptr1, inptr2;
  151428. register JDIMENSION col;
  151429. JDIMENSION num_cols = cinfo->output_width;
  151430. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  151431. register int * Crrtab = cconvert->Cr_r_tab;
  151432. register int * Cbbtab = cconvert->Cb_b_tab;
  151433. register INT32 * Crgtab = cconvert->Cr_g_tab;
  151434. register INT32 * Cbgtab = cconvert->Cb_g_tab;
  151435. SHIFT_TEMPS
  151436. while (--num_rows >= 0) {
  151437. inptr0 = input_buf[0][input_row];
  151438. inptr1 = input_buf[1][input_row];
  151439. inptr2 = input_buf[2][input_row];
  151440. input_row++;
  151441. outptr = *output_buf++;
  151442. for (col = 0; col < num_cols; col++) {
  151443. y = GETJSAMPLE(inptr0[col]);
  151444. cb = GETJSAMPLE(inptr1[col]);
  151445. cr = GETJSAMPLE(inptr2[col]);
  151446. outptr[RGB_RED] = range_limit[y + Crrtab[cr]];
  151447. outptr[RGB_GREEN] = range_limit[y +
  151448. ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
  151449. SCALEBITS))];
  151450. outptr[RGB_BLUE] = range_limit[y + Cbbtab[cb]];
  151451. outptr += RGB_PIXELSIZE;
  151452. }
  151453. }
  151454. }
  151455. METHODDEF(void)
  151456. null_convert2 (j_decompress_ptr cinfo,
  151457. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151458. JSAMPARRAY output_buf, int num_rows)
  151459. {
  151460. register JSAMPROW inptr, outptr;
  151461. register JDIMENSION count;
  151462. register int num_components = cinfo->num_components;
  151463. JDIMENSION num_cols = cinfo->output_width;
  151464. int ci;
  151465. while (--num_rows >= 0) {
  151466. for (ci = 0; ci < num_components; ci++) {
  151467. inptr = input_buf[ci][input_row];
  151468. outptr = output_buf[0] + ci;
  151469. for (count = num_cols; count > 0; count--) {
  151470. *outptr = *inptr++; /* needn't bother with GETJSAMPLE() here */
  151471. outptr += num_components;
  151472. }
  151473. }
  151474. input_row++;
  151475. output_buf++;
  151476. }
  151477. }
  151478. METHODDEF(void)
  151479. grayscale_convert2 (j_decompress_ptr cinfo,
  151480. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151481. JSAMPARRAY output_buf, int num_rows)
  151482. {
  151483. jcopy_sample_rows(input_buf[0], (int) input_row, output_buf, 0,
  151484. num_rows, cinfo->output_width);
  151485. }
  151486. METHODDEF(void)
  151487. gray_rgb_convert (j_decompress_ptr cinfo,
  151488. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151489. JSAMPARRAY output_buf, int num_rows)
  151490. {
  151491. register JSAMPROW inptr, outptr;
  151492. register JDIMENSION col;
  151493. JDIMENSION num_cols = cinfo->output_width;
  151494. while (--num_rows >= 0) {
  151495. inptr = input_buf[0][input_row++];
  151496. outptr = *output_buf++;
  151497. for (col = 0; col < num_cols; col++) {
  151498. outptr[RGB_RED] = outptr[RGB_GREEN] = outptr[RGB_BLUE] = inptr[col];
  151499. outptr += RGB_PIXELSIZE;
  151500. }
  151501. }
  151502. }
  151503. METHODDEF(void)
  151504. ycck_cmyk_convert (j_decompress_ptr cinfo,
  151505. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151506. JSAMPARRAY output_buf, int num_rows)
  151507. {
  151508. my_cconvert_ptr2 cconvert = (my_cconvert_ptr2) cinfo->cconvert;
  151509. register int y, cb, cr;
  151510. register JSAMPROW outptr;
  151511. register JSAMPROW inptr0, inptr1, inptr2, inptr3;
  151512. register JDIMENSION col;
  151513. JDIMENSION num_cols = cinfo->output_width;
  151514. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  151515. register int * Crrtab = cconvert->Cr_r_tab;
  151516. register int * Cbbtab = cconvert->Cb_b_tab;
  151517. register INT32 * Crgtab = cconvert->Cr_g_tab;
  151518. register INT32 * Cbgtab = cconvert->Cb_g_tab;
  151519. SHIFT_TEMPS
  151520. while (--num_rows >= 0) {
  151521. inptr0 = input_buf[0][input_row];
  151522. inptr1 = input_buf[1][input_row];
  151523. inptr2 = input_buf[2][input_row];
  151524. inptr3 = input_buf[3][input_row];
  151525. input_row++;
  151526. outptr = *output_buf++;
  151527. for (col = 0; col < num_cols; col++) {
  151528. y = GETJSAMPLE(inptr0[col]);
  151529. cb = GETJSAMPLE(inptr1[col]);
  151530. cr = GETJSAMPLE(inptr2[col]);
  151531. outptr[0] = range_limit[MAXJSAMPLE - (y + Crrtab[cr])]; /* red */
  151532. outptr[1] = range_limit[MAXJSAMPLE - (y + /* green */
  151533. ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
  151534. SCALEBITS)))];
  151535. outptr[2] = range_limit[MAXJSAMPLE - (y + Cbbtab[cb])]; /* blue */
  151536. outptr[3] = inptr3[col]; /* don't need GETJSAMPLE here */
  151537. outptr += 4;
  151538. }
  151539. }
  151540. }
  151541. METHODDEF(void)
  151542. start_pass_dcolor (j_decompress_ptr cinfo)
  151543. {
  151544. }
  151545. GLOBAL(void)
  151546. jinit_color_deconverter (j_decompress_ptr cinfo)
  151547. {
  151548. my_cconvert_ptr2 cconvert;
  151549. int ci;
  151550. cconvert = (my_cconvert_ptr2)
  151551. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151552. SIZEOF(my_color_deconverter2));
  151553. cinfo->cconvert = (struct jpeg_color_deconverter *) cconvert;
  151554. cconvert->pub.start_pass = start_pass_dcolor;
  151555. switch (cinfo->jpeg_color_space) {
  151556. case JCS_GRAYSCALE:
  151557. if (cinfo->num_components != 1)
  151558. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151559. break;
  151560. case JCS_RGB:
  151561. case JCS_YCbCr:
  151562. if (cinfo->num_components != 3)
  151563. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151564. break;
  151565. case JCS_CMYK:
  151566. case JCS_YCCK:
  151567. if (cinfo->num_components != 4)
  151568. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151569. break;
  151570. default: /* JCS_UNKNOWN can be anything */
  151571. if (cinfo->num_components < 1)
  151572. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151573. break;
  151574. }
  151575. switch (cinfo->out_color_space) {
  151576. case JCS_GRAYSCALE:
  151577. cinfo->out_color_components = 1;
  151578. if (cinfo->jpeg_color_space == JCS_GRAYSCALE ||
  151579. cinfo->jpeg_color_space == JCS_YCbCr) {
  151580. cconvert->pub.color_convert = grayscale_convert2;
  151581. for (ci = 1; ci < cinfo->num_components; ci++)
  151582. cinfo->comp_info[ci].component_needed = FALSE;
  151583. } else
  151584. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151585. break;
  151586. case JCS_RGB:
  151587. cinfo->out_color_components = RGB_PIXELSIZE;
  151588. if (cinfo->jpeg_color_space == JCS_YCbCr) {
  151589. cconvert->pub.color_convert = ycc_rgb_convert;
  151590. build_ycc_rgb_table(cinfo);
  151591. } else if (cinfo->jpeg_color_space == JCS_GRAYSCALE) {
  151592. cconvert->pub.color_convert = gray_rgb_convert;
  151593. } else if (cinfo->jpeg_color_space == JCS_RGB && RGB_PIXELSIZE == 3) {
  151594. cconvert->pub.color_convert = null_convert2;
  151595. } else
  151596. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151597. break;
  151598. case JCS_CMYK:
  151599. cinfo->out_color_components = 4;
  151600. if (cinfo->jpeg_color_space == JCS_YCCK) {
  151601. cconvert->pub.color_convert = ycck_cmyk_convert;
  151602. build_ycc_rgb_table(cinfo);
  151603. } else if (cinfo->jpeg_color_space == JCS_CMYK) {
  151604. cconvert->pub.color_convert = null_convert2;
  151605. } else
  151606. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151607. break;
  151608. default:
  151609. if (cinfo->out_color_space == cinfo->jpeg_color_space) {
  151610. cinfo->out_color_components = cinfo->num_components;
  151611. cconvert->pub.color_convert = null_convert2;
  151612. } else /* unsupported non-null conversion */
  151613. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151614. break;
  151615. }
  151616. if (cinfo->quantize_colors)
  151617. cinfo->output_components = 1; /* single colormapped output component */
  151618. else
  151619. cinfo->output_components = cinfo->out_color_components;
  151620. }
  151621. /*** End of inlined file: jdcolor.c ***/
  151622. #undef FIX
  151623. /*** Start of inlined file: jddctmgr.c ***/
  151624. #define JPEG_INTERNALS
  151625. typedef struct {
  151626. struct jpeg_inverse_dct pub; /* public fields */
  151627. int cur_method[MAX_COMPONENTS];
  151628. } my_idct_controller;
  151629. typedef my_idct_controller * my_idct_ptr;
  151630. typedef union {
  151631. ISLOW_MULT_TYPE islow_array[DCTSIZE2];
  151632. #ifdef DCT_IFAST_SUPPORTED
  151633. IFAST_MULT_TYPE ifast_array[DCTSIZE2];
  151634. #endif
  151635. #ifdef DCT_FLOAT_SUPPORTED
  151636. FLOAT_MULT_TYPE float_array[DCTSIZE2];
  151637. #endif
  151638. } multiplier_table;
  151639. #ifdef DCT_ISLOW_SUPPORTED
  151640. #define PROVIDE_ISLOW_TABLES
  151641. #else
  151642. #ifdef IDCT_SCALING_SUPPORTED
  151643. #define PROVIDE_ISLOW_TABLES
  151644. #endif
  151645. #endif
  151646. METHODDEF(void)
  151647. start_pass (j_decompress_ptr cinfo)
  151648. {
  151649. my_idct_ptr idct = (my_idct_ptr) cinfo->idct;
  151650. int ci, i;
  151651. jpeg_component_info *compptr;
  151652. int method = 0;
  151653. inverse_DCT_method_ptr method_ptr = NULL;
  151654. JQUANT_TBL * qtbl;
  151655. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151656. ci++, compptr++) {
  151657. switch (compptr->DCT_scaled_size) {
  151658. #ifdef IDCT_SCALING_SUPPORTED
  151659. case 1:
  151660. method_ptr = jpeg_idct_1x1;
  151661. method = JDCT_ISLOW; /* jidctred uses islow-style table */
  151662. break;
  151663. case 2:
  151664. method_ptr = jpeg_idct_2x2;
  151665. method = JDCT_ISLOW; /* jidctred uses islow-style table */
  151666. break;
  151667. case 4:
  151668. method_ptr = jpeg_idct_4x4;
  151669. method = JDCT_ISLOW; /* jidctred uses islow-style table */
  151670. break;
  151671. #endif
  151672. case DCTSIZE:
  151673. switch (cinfo->dct_method) {
  151674. #ifdef DCT_ISLOW_SUPPORTED
  151675. case JDCT_ISLOW:
  151676. method_ptr = jpeg_idct_islow;
  151677. method = JDCT_ISLOW;
  151678. break;
  151679. #endif
  151680. #ifdef DCT_IFAST_SUPPORTED
  151681. case JDCT_IFAST:
  151682. method_ptr = jpeg_idct_ifast;
  151683. method = JDCT_IFAST;
  151684. break;
  151685. #endif
  151686. #ifdef DCT_FLOAT_SUPPORTED
  151687. case JDCT_FLOAT:
  151688. method_ptr = jpeg_idct_float;
  151689. method = JDCT_FLOAT;
  151690. break;
  151691. #endif
  151692. default:
  151693. ERREXIT(cinfo, JERR_NOT_COMPILED);
  151694. break;
  151695. }
  151696. break;
  151697. default:
  151698. ERREXIT1(cinfo, JERR_BAD_DCTSIZE, compptr->DCT_scaled_size);
  151699. break;
  151700. }
  151701. idct->pub.inverse_DCT[ci] = method_ptr;
  151702. if (! compptr->component_needed || idct->cur_method[ci] == method)
  151703. continue;
  151704. qtbl = compptr->quant_table;
  151705. if (qtbl == NULL) /* happens if no data yet for component */
  151706. continue;
  151707. idct->cur_method[ci] = method;
  151708. switch (method) {
  151709. #ifdef PROVIDE_ISLOW_TABLES
  151710. case JDCT_ISLOW:
  151711. {
  151712. ISLOW_MULT_TYPE * ismtbl = (ISLOW_MULT_TYPE *) compptr->dct_table;
  151713. for (i = 0; i < DCTSIZE2; i++) {
  151714. ismtbl[i] = (ISLOW_MULT_TYPE) qtbl->quantval[i];
  151715. }
  151716. }
  151717. break;
  151718. #endif
  151719. #ifdef DCT_IFAST_SUPPORTED
  151720. case JDCT_IFAST:
  151721. {
  151722. IFAST_MULT_TYPE * ifmtbl = (IFAST_MULT_TYPE *) compptr->dct_table;
  151723. #define CONST_BITS 14
  151724. static const INT16 aanscales[DCTSIZE2] = {
  151725. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  151726. 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
  151727. 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
  151728. 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
  151729. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  151730. 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
  151731. 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
  151732. 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
  151733. };
  151734. SHIFT_TEMPS
  151735. for (i = 0; i < DCTSIZE2; i++) {
  151736. ifmtbl[i] = (IFAST_MULT_TYPE)
  151737. DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
  151738. (INT32) aanscales[i]),
  151739. CONST_BITS-IFAST_SCALE_BITS);
  151740. }
  151741. }
  151742. break;
  151743. #endif
  151744. #ifdef DCT_FLOAT_SUPPORTED
  151745. case JDCT_FLOAT:
  151746. {
  151747. FLOAT_MULT_TYPE * fmtbl = (FLOAT_MULT_TYPE *) compptr->dct_table;
  151748. int row, col;
  151749. static const double aanscalefactor[DCTSIZE] = {
  151750. 1.0, 1.387039845, 1.306562965, 1.175875602,
  151751. 1.0, 0.785694958, 0.541196100, 0.275899379
  151752. };
  151753. i = 0;
  151754. for (row = 0; row < DCTSIZE; row++) {
  151755. for (col = 0; col < DCTSIZE; col++) {
  151756. fmtbl[i] = (FLOAT_MULT_TYPE)
  151757. ((double) qtbl->quantval[i] *
  151758. aanscalefactor[row] * aanscalefactor[col]);
  151759. i++;
  151760. }
  151761. }
  151762. }
  151763. break;
  151764. #endif
  151765. default:
  151766. ERREXIT(cinfo, JERR_NOT_COMPILED);
  151767. break;
  151768. }
  151769. }
  151770. }
  151771. GLOBAL(void)
  151772. jinit_inverse_dct (j_decompress_ptr cinfo)
  151773. {
  151774. my_idct_ptr idct;
  151775. int ci;
  151776. jpeg_component_info *compptr;
  151777. idct = (my_idct_ptr)
  151778. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151779. SIZEOF(my_idct_controller));
  151780. cinfo->idct = (struct jpeg_inverse_dct *) idct;
  151781. idct->pub.start_pass = start_pass;
  151782. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151783. ci++, compptr++) {
  151784. compptr->dct_table =
  151785. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151786. SIZEOF(multiplier_table));
  151787. MEMZERO(compptr->dct_table, SIZEOF(multiplier_table));
  151788. idct->cur_method[ci] = -1;
  151789. }
  151790. }
  151791. /*** End of inlined file: jddctmgr.c ***/
  151792. #undef CONST_BITS
  151793. #undef ASSIGN_STATE
  151794. /*** Start of inlined file: jdhuff.c ***/
  151795. #define JPEG_INTERNALS
  151796. /*** Start of inlined file: jdhuff.h ***/
  151797. #ifndef __jdhuff_h__
  151798. #define __jdhuff_h__
  151799. #ifdef NEED_SHORT_EXTERNAL_NAMES
  151800. #define jpeg_make_d_derived_tbl jMkDDerived
  151801. #define jpeg_fill_bit_buffer jFilBitBuf
  151802. #define jpeg_huff_decode jHufDecode
  151803. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  151804. #define HUFF_LOOKAHEAD 8 /* # of bits of lookahead */
  151805. typedef struct {
  151806. INT32 maxcode[18]; /* largest code of length k (-1 if none) */
  151807. INT32 valoffset[17]; /* huffval[] offset for codes of length k */
  151808. JHUFF_TBL *pub;
  151809. int look_nbits[1<<HUFF_LOOKAHEAD]; /* # bits, or 0 if too long */
  151810. UINT8 look_sym[1<<HUFF_LOOKAHEAD]; /* symbol, or unused */
  151811. } d_derived_tbl;
  151812. EXTERN(void) jpeg_make_d_derived_tbl
  151813. JPP((j_decompress_ptr cinfo, boolean isDC, int tblno,
  151814. d_derived_tbl ** pdtbl));
  151815. typedef INT32 bit_buf_type; /* type of bit-extraction buffer */
  151816. #define BIT_BUF_SIZE 32 /* size of buffer in bits */
  151817. typedef struct { /* Bitreading state saved across MCUs */
  151818. bit_buf_type get_buffer; /* current bit-extraction buffer */
  151819. int bits_left; /* # of unused bits in it */
  151820. } bitread_perm_state;
  151821. typedef struct { /* Bitreading working state within an MCU */
  151822. const JOCTET * next_input_byte; /* => next byte to read from source */
  151823. size_t bytes_in_buffer; /* # of bytes remaining in source buffer */
  151824. bit_buf_type get_buffer; /* current bit-extraction buffer */
  151825. int bits_left; /* # of unused bits in it */
  151826. j_decompress_ptr cinfo; /* back link to decompress master record */
  151827. } bitread_working_state;
  151828. #define BITREAD_STATE_VARS \
  151829. register bit_buf_type get_buffer; \
  151830. register int bits_left; \
  151831. bitread_working_state br_state
  151832. #define BITREAD_LOAD_STATE(cinfop,permstate) \
  151833. br_state.cinfo = cinfop; \
  151834. br_state.next_input_byte = cinfop->src->next_input_byte; \
  151835. br_state.bytes_in_buffer = cinfop->src->bytes_in_buffer; \
  151836. get_buffer = permstate.get_buffer; \
  151837. bits_left = permstate.bits_left;
  151838. #define BITREAD_SAVE_STATE(cinfop,permstate) \
  151839. cinfop->src->next_input_byte = br_state.next_input_byte; \
  151840. cinfop->src->bytes_in_buffer = br_state.bytes_in_buffer; \
  151841. permstate.get_buffer = get_buffer; \
  151842. permstate.bits_left = bits_left
  151843. #define CHECK_BIT_BUFFER(state,nbits,action) \
  151844. { if (bits_left < (nbits)) { \
  151845. if (! jpeg_fill_bit_buffer(&(state),get_buffer,bits_left,nbits)) \
  151846. { action; } \
  151847. get_buffer = (state).get_buffer; bits_left = (state).bits_left; } }
  151848. #define GET_BITS(nbits) \
  151849. (((int) (get_buffer >> (bits_left -= (nbits)))) & ((1<<(nbits))-1))
  151850. #define PEEK_BITS(nbits) \
  151851. (((int) (get_buffer >> (bits_left - (nbits)))) & ((1<<(nbits))-1))
  151852. #define DROP_BITS(nbits) \
  151853. (bits_left -= (nbits))
  151854. EXTERN(boolean) jpeg_fill_bit_buffer
  151855. JPP((bitread_working_state * state, register bit_buf_type get_buffer,
  151856. register int bits_left, int nbits));
  151857. #define HUFF_DECODE(result,state,htbl,failaction,slowlabel) \
  151858. { register int nb, look; \
  151859. if (bits_left < HUFF_LOOKAHEAD) { \
  151860. if (! jpeg_fill_bit_buffer(&state,get_buffer,bits_left, 0)) {failaction;} \
  151861. get_buffer = state.get_buffer; bits_left = state.bits_left; \
  151862. if (bits_left < HUFF_LOOKAHEAD) { \
  151863. nb = 1; goto slowlabel; \
  151864. } \
  151865. } \
  151866. look = PEEK_BITS(HUFF_LOOKAHEAD); \
  151867. if ((nb = htbl->look_nbits[look]) != 0) { \
  151868. DROP_BITS(nb); \
  151869. result = htbl->look_sym[look]; \
  151870. } else { \
  151871. nb = HUFF_LOOKAHEAD+1; \
  151872. slowlabel: \
  151873. if ((result=jpeg_huff_decode(&state,get_buffer,bits_left,htbl,nb)) < 0) \
  151874. { failaction; } \
  151875. get_buffer = state.get_buffer; bits_left = state.bits_left; \
  151876. } \
  151877. }
  151878. EXTERN(int) jpeg_huff_decode
  151879. JPP((bitread_working_state * state, register bit_buf_type get_buffer,
  151880. register int bits_left, d_derived_tbl * htbl, int min_bits));
  151881. #endif
  151882. /*** End of inlined file: jdhuff.h ***/
  151883. /* Declarations shared with jdphuff.c */
  151884. typedef struct {
  151885. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  151886. } savable_state2;
  151887. #ifndef NO_STRUCT_ASSIGN
  151888. #define ASSIGN_STATE(dest,src) ((dest) = (src))
  151889. #else
  151890. #if MAX_COMPS_IN_SCAN == 4
  151891. #define ASSIGN_STATE(dest,src) \
  151892. ((dest).last_dc_val[0] = (src).last_dc_val[0], \
  151893. (dest).last_dc_val[1] = (src).last_dc_val[1], \
  151894. (dest).last_dc_val[2] = (src).last_dc_val[2], \
  151895. (dest).last_dc_val[3] = (src).last_dc_val[3])
  151896. #endif
  151897. #endif
  151898. typedef struct {
  151899. struct jpeg_entropy_decoder pub; /* public fields */
  151900. bitread_perm_state bitstate; /* Bit buffer at start of MCU */
  151901. savable_state2 saved; /* Other state at start of MCU */
  151902. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  151903. d_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS];
  151904. d_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS];
  151905. d_derived_tbl * dc_cur_tbls[D_MAX_BLOCKS_IN_MCU];
  151906. d_derived_tbl * ac_cur_tbls[D_MAX_BLOCKS_IN_MCU];
  151907. boolean dc_needed[D_MAX_BLOCKS_IN_MCU];
  151908. boolean ac_needed[D_MAX_BLOCKS_IN_MCU];
  151909. } huff_entropy_decoder2;
  151910. typedef huff_entropy_decoder2 * huff_entropy_ptr2;
  151911. METHODDEF(void)
  151912. start_pass_huff_decoder (j_decompress_ptr cinfo)
  151913. {
  151914. huff_entropy_ptr2 entropy = (huff_entropy_ptr2) cinfo->entropy;
  151915. int ci, blkn, dctbl, actbl;
  151916. jpeg_component_info * compptr;
  151917. if (cinfo->Ss != 0 || cinfo->Se != DCTSIZE2-1 ||
  151918. cinfo->Ah != 0 || cinfo->Al != 0)
  151919. WARNMS(cinfo, JWRN_NOT_SEQUENTIAL);
  151920. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  151921. compptr = cinfo->cur_comp_info[ci];
  151922. dctbl = compptr->dc_tbl_no;
  151923. actbl = compptr->ac_tbl_no;
  151924. jpeg_make_d_derived_tbl(cinfo, TRUE, dctbl,
  151925. & entropy->dc_derived_tbls[dctbl]);
  151926. jpeg_make_d_derived_tbl(cinfo, FALSE, actbl,
  151927. & entropy->ac_derived_tbls[actbl]);
  151928. entropy->saved.last_dc_val[ci] = 0;
  151929. }
  151930. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  151931. ci = cinfo->MCU_membership[blkn];
  151932. compptr = cinfo->cur_comp_info[ci];
  151933. entropy->dc_cur_tbls[blkn] = entropy->dc_derived_tbls[compptr->dc_tbl_no];
  151934. entropy->ac_cur_tbls[blkn] = entropy->ac_derived_tbls[compptr->ac_tbl_no];
  151935. if (compptr->component_needed) {
  151936. entropy->dc_needed[blkn] = TRUE;
  151937. entropy->ac_needed[blkn] = (compptr->DCT_scaled_size > 1);
  151938. } else {
  151939. entropy->dc_needed[blkn] = entropy->ac_needed[blkn] = FALSE;
  151940. }
  151941. }
  151942. entropy->bitstate.bits_left = 0;
  151943. entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */
  151944. entropy->pub.insufficient_data = FALSE;
  151945. entropy->restarts_to_go = cinfo->restart_interval;
  151946. }
  151947. GLOBAL(void)
  151948. jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, boolean isDC, int tblno,
  151949. d_derived_tbl ** pdtbl)
  151950. {
  151951. JHUFF_TBL *htbl;
  151952. d_derived_tbl *dtbl;
  151953. int p, i, l, si, numsymbols;
  151954. int lookbits, ctr;
  151955. char huffsize[257];
  151956. unsigned int huffcode[257];
  151957. unsigned int code;
  151958. if (tblno < 0 || tblno >= NUM_HUFF_TBLS)
  151959. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  151960. htbl =
  151961. isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];
  151962. if (htbl == NULL)
  151963. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  151964. if (*pdtbl == NULL)
  151965. *pdtbl = (d_derived_tbl *)
  151966. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151967. SIZEOF(d_derived_tbl));
  151968. dtbl = *pdtbl;
  151969. dtbl->pub = htbl; /* fill in back link */
  151970. p = 0;
  151971. for (l = 1; l <= 16; l++) {
  151972. i = (int) htbl->bits[l];
  151973. if (i < 0 || p + i > 256) /* protect against table overrun */
  151974. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  151975. while (i--)
  151976. huffsize[p++] = (char) l;
  151977. }
  151978. huffsize[p] = 0;
  151979. numsymbols = p;
  151980. code = 0;
  151981. si = huffsize[0];
  151982. p = 0;
  151983. while (huffsize[p]) {
  151984. while (((int) huffsize[p]) == si) {
  151985. huffcode[p++] = code;
  151986. code++;
  151987. }
  151988. if (((INT32) code) >= (((INT32) 1) << si))
  151989. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  151990. code <<= 1;
  151991. si++;
  151992. }
  151993. p = 0;
  151994. for (l = 1; l <= 16; l++) {
  151995. if (htbl->bits[l]) {
  151996. dtbl->valoffset[l] = (INT32) p - (INT32) huffcode[p];
  151997. p += htbl->bits[l];
  151998. dtbl->maxcode[l] = huffcode[p-1]; /* maximum code of length l */
  151999. } else {
  152000. dtbl->maxcode[l] = -1; /* -1 if no codes of this length */
  152001. }
  152002. }
  152003. dtbl->maxcode[17] = 0xFFFFFL; /* ensures jpeg_huff_decode terminates */
  152004. MEMZERO(dtbl->look_nbits, SIZEOF(dtbl->look_nbits));
  152005. p = 0;
  152006. for (l = 1; l <= HUFF_LOOKAHEAD; l++) {
  152007. for (i = 1; i <= (int) htbl->bits[l]; i++, p++) {
  152008. lookbits = huffcode[p] << (HUFF_LOOKAHEAD-l);
  152009. for (ctr = 1 << (HUFF_LOOKAHEAD-l); ctr > 0; ctr--) {
  152010. dtbl->look_nbits[lookbits] = l;
  152011. dtbl->look_sym[lookbits] = htbl->huffval[p];
  152012. lookbits++;
  152013. }
  152014. }
  152015. }
  152016. if (isDC) {
  152017. for (i = 0; i < numsymbols; i++) {
  152018. int sym = htbl->huffval[i];
  152019. if (sym < 0 || sym > 15)
  152020. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  152021. }
  152022. }
  152023. }
  152024. #ifdef SLOW_SHIFT_32
  152025. #define MIN_GET_BITS 15 /* minimum allowable value */
  152026. #else
  152027. #define MIN_GET_BITS (BIT_BUF_SIZE-7)
  152028. #endif
  152029. GLOBAL(boolean)
  152030. jpeg_fill_bit_buffer (bitread_working_state * state,
  152031. register bit_buf_type get_buffer, register int bits_left,
  152032. int nbits)
  152033. {
  152034. register const JOCTET * next_input_byte = state->next_input_byte;
  152035. register size_t bytes_in_buffer = state->bytes_in_buffer;
  152036. j_decompress_ptr cinfo = state->cinfo;
  152037. if (cinfo->unread_marker == 0) { /* cannot advance past a marker */
  152038. while (bits_left < MIN_GET_BITS) {
  152039. register int c;
  152040. if (bytes_in_buffer == 0) {
  152041. if (! (*cinfo->src->fill_input_buffer) (cinfo))
  152042. return FALSE;
  152043. next_input_byte = cinfo->src->next_input_byte;
  152044. bytes_in_buffer = cinfo->src->bytes_in_buffer;
  152045. }
  152046. bytes_in_buffer--;
  152047. c = GETJOCTET(*next_input_byte++);
  152048. if (c == 0xFF) {
  152049. do {
  152050. if (bytes_in_buffer == 0) {
  152051. if (! (*cinfo->src->fill_input_buffer) (cinfo))
  152052. return FALSE;
  152053. next_input_byte = cinfo->src->next_input_byte;
  152054. bytes_in_buffer = cinfo->src->bytes_in_buffer;
  152055. }
  152056. bytes_in_buffer--;
  152057. c = GETJOCTET(*next_input_byte++);
  152058. } while (c == 0xFF);
  152059. if (c == 0) {
  152060. c = 0xFF;
  152061. } else {
  152062. cinfo->unread_marker = c;
  152063. goto no_more_bytes;
  152064. }
  152065. }
  152066. get_buffer = (get_buffer << 8) | c;
  152067. bits_left += 8;
  152068. } /* end while */
  152069. } else {
  152070. no_more_bytes:
  152071. if (nbits > bits_left) {
  152072. if (! cinfo->entropy->insufficient_data) {
  152073. WARNMS(cinfo, JWRN_HIT_MARKER);
  152074. cinfo->entropy->insufficient_data = TRUE;
  152075. }
  152076. get_buffer <<= MIN_GET_BITS - bits_left;
  152077. bits_left = MIN_GET_BITS;
  152078. }
  152079. }
  152080. state->next_input_byte = next_input_byte;
  152081. state->bytes_in_buffer = bytes_in_buffer;
  152082. state->get_buffer = get_buffer;
  152083. state->bits_left = bits_left;
  152084. return TRUE;
  152085. }
  152086. GLOBAL(int)
  152087. jpeg_huff_decode (bitread_working_state * state,
  152088. register bit_buf_type get_buffer, register int bits_left,
  152089. d_derived_tbl * htbl, int min_bits)
  152090. {
  152091. register int l = min_bits;
  152092. register INT32 code;
  152093. CHECK_BIT_BUFFER(*state, l, return -1);
  152094. code = GET_BITS(l);
  152095. while (code > htbl->maxcode[l]) {
  152096. code <<= 1;
  152097. CHECK_BIT_BUFFER(*state, 1, return -1);
  152098. code |= GET_BITS(1);
  152099. l++;
  152100. }
  152101. state->get_buffer = get_buffer;
  152102. state->bits_left = bits_left;
  152103. if (l > 16) {
  152104. WARNMS(state->cinfo, JWRN_HUFF_BAD_CODE);
  152105. return 0; /* fake a zero as the safest result */
  152106. }
  152107. return htbl->pub->huffval[ (int) (code + htbl->valoffset[l]) ];
  152108. }
  152109. LOCAL(boolean)
  152110. process_restart (j_decompress_ptr cinfo)
  152111. {
  152112. huff_entropy_ptr2 entropy = (huff_entropy_ptr2) cinfo->entropy;
  152113. int ci;
  152114. cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8;
  152115. entropy->bitstate.bits_left = 0;
  152116. if (! (*cinfo->marker->read_restart_marker) (cinfo))
  152117. return FALSE;
  152118. for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  152119. entropy->saved.last_dc_val[ci] = 0;
  152120. entropy->restarts_to_go = cinfo->restart_interval;
  152121. if (cinfo->unread_marker == 0)
  152122. entropy->pub.insufficient_data = FALSE;
  152123. return TRUE;
  152124. }
  152125. METHODDEF(boolean)
  152126. decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  152127. {
  152128. huff_entropy_ptr2 entropy = (huff_entropy_ptr2) cinfo->entropy;
  152129. int blkn;
  152130. BITREAD_STATE_VARS;
  152131. savable_state2 state;
  152132. if (cinfo->restart_interval) {
  152133. if (entropy->restarts_to_go == 0)
  152134. if (! process_restart(cinfo))
  152135. return FALSE;
  152136. }
  152137. if (! entropy->pub.insufficient_data) {
  152138. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  152139. ASSIGN_STATE(state, entropy->saved);
  152140. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  152141. JBLOCKROW block = MCU_data[blkn];
  152142. d_derived_tbl * dctbl = entropy->dc_cur_tbls[blkn];
  152143. d_derived_tbl * actbl = entropy->ac_cur_tbls[blkn];
  152144. register int s, k, r;
  152145. HUFF_DECODE(s, br_state, dctbl, return FALSE, label1);
  152146. if (s) {
  152147. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  152148. r = GET_BITS(s);
  152149. s = HUFF_EXTEND(r, s);
  152150. }
  152151. if (entropy->dc_needed[blkn]) {
  152152. int ci = cinfo->MCU_membership[blkn];
  152153. s += state.last_dc_val[ci];
  152154. state.last_dc_val[ci] = s;
  152155. (*block)[0] = (JCOEF) s;
  152156. }
  152157. if (entropy->ac_needed[blkn]) {
  152158. for (k = 1; k < DCTSIZE2; k++) {
  152159. HUFF_DECODE(s, br_state, actbl, return FALSE, label2);
  152160. r = s >> 4;
  152161. s &= 15;
  152162. if (s) {
  152163. k += r;
  152164. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  152165. r = GET_BITS(s);
  152166. s = HUFF_EXTEND(r, s);
  152167. (*block)[jpeg_natural_order[k]] = (JCOEF) s;
  152168. } else {
  152169. if (r != 15)
  152170. break;
  152171. k += 15;
  152172. }
  152173. }
  152174. } else {
  152175. for (k = 1; k < DCTSIZE2; k++) {
  152176. HUFF_DECODE(s, br_state, actbl, return FALSE, label3);
  152177. r = s >> 4;
  152178. s &= 15;
  152179. if (s) {
  152180. k += r;
  152181. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  152182. DROP_BITS(s);
  152183. } else {
  152184. if (r != 15)
  152185. break;
  152186. k += 15;
  152187. }
  152188. }
  152189. }
  152190. }
  152191. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  152192. ASSIGN_STATE(entropy->saved, state);
  152193. }
  152194. entropy->restarts_to_go--;
  152195. return TRUE;
  152196. }
  152197. GLOBAL(void)
  152198. jinit_huff_decoder (j_decompress_ptr cinfo)
  152199. {
  152200. huff_entropy_ptr2 entropy;
  152201. int i;
  152202. entropy = (huff_entropy_ptr2)
  152203. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152204. SIZEOF(huff_entropy_decoder2));
  152205. cinfo->entropy = (struct jpeg_entropy_decoder *) entropy;
  152206. entropy->pub.start_pass = start_pass_huff_decoder;
  152207. entropy->pub.decode_mcu = decode_mcu;
  152208. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  152209. entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL;
  152210. }
  152211. }
  152212. /*** End of inlined file: jdhuff.c ***/
  152213. /*** Start of inlined file: jdinput.c ***/
  152214. #define JPEG_INTERNALS
  152215. typedef struct {
  152216. struct jpeg_input_controller pub; /* public fields */
  152217. boolean inheaders; /* TRUE until first SOS is reached */
  152218. } my_input_controller;
  152219. typedef my_input_controller * my_inputctl_ptr;
  152220. METHODDEF(int) consume_markers JPP((j_decompress_ptr cinfo));
  152221. LOCAL(void)
  152222. initial_setup2 (j_decompress_ptr cinfo)
  152223. {
  152224. int ci;
  152225. jpeg_component_info *compptr;
  152226. if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION ||
  152227. (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION)
  152228. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
  152229. if (cinfo->data_precision != BITS_IN_JSAMPLE)
  152230. ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
  152231. if (cinfo->num_components > MAX_COMPONENTS)
  152232. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  152233. MAX_COMPONENTS);
  152234. cinfo->max_h_samp_factor = 1;
  152235. cinfo->max_v_samp_factor = 1;
  152236. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152237. ci++, compptr++) {
  152238. if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR ||
  152239. compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
  152240. ERREXIT(cinfo, JERR_BAD_SAMPLING);
  152241. cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
  152242. compptr->h_samp_factor);
  152243. cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
  152244. compptr->v_samp_factor);
  152245. }
  152246. cinfo->min_DCT_scaled_size = DCTSIZE;
  152247. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152248. ci++, compptr++) {
  152249. compptr->DCT_scaled_size = DCTSIZE;
  152250. compptr->width_in_blocks = (JDIMENSION)
  152251. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  152252. (long) (cinfo->max_h_samp_factor * DCTSIZE));
  152253. compptr->height_in_blocks = (JDIMENSION)
  152254. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  152255. (long) (cinfo->max_v_samp_factor * DCTSIZE));
  152256. compptr->downsampled_width = (JDIMENSION)
  152257. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  152258. (long) cinfo->max_h_samp_factor);
  152259. compptr->downsampled_height = (JDIMENSION)
  152260. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  152261. (long) cinfo->max_v_samp_factor);
  152262. compptr->component_needed = TRUE;
  152263. compptr->quant_table = NULL;
  152264. }
  152265. cinfo->total_iMCU_rows = (JDIMENSION)
  152266. jdiv_round_up((long) cinfo->image_height,
  152267. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  152268. if (cinfo->comps_in_scan < cinfo->num_components || cinfo->progressive_mode)
  152269. cinfo->inputctl->has_multiple_scans = TRUE;
  152270. else
  152271. cinfo->inputctl->has_multiple_scans = FALSE;
  152272. }
  152273. LOCAL(void)
  152274. per_scan_setup2 (j_decompress_ptr cinfo)
  152275. {
  152276. int ci, mcublks, tmp;
  152277. jpeg_component_info *compptr;
  152278. if (cinfo->comps_in_scan == 1) {
  152279. compptr = cinfo->cur_comp_info[0];
  152280. cinfo->MCUs_per_row = compptr->width_in_blocks;
  152281. cinfo->MCU_rows_in_scan = compptr->height_in_blocks;
  152282. compptr->MCU_width = 1;
  152283. compptr->MCU_height = 1;
  152284. compptr->MCU_blocks = 1;
  152285. compptr->MCU_sample_width = compptr->DCT_scaled_size;
  152286. compptr->last_col_width = 1;
  152287. tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  152288. if (tmp == 0) tmp = compptr->v_samp_factor;
  152289. compptr->last_row_height = tmp;
  152290. cinfo->blocks_in_MCU = 1;
  152291. cinfo->MCU_membership[0] = 0;
  152292. } else {
  152293. if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
  152294. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
  152295. MAX_COMPS_IN_SCAN);
  152296. cinfo->MCUs_per_row = (JDIMENSION)
  152297. jdiv_round_up((long) cinfo->image_width,
  152298. (long) (cinfo->max_h_samp_factor*DCTSIZE));
  152299. cinfo->MCU_rows_in_scan = (JDIMENSION)
  152300. jdiv_round_up((long) cinfo->image_height,
  152301. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  152302. cinfo->blocks_in_MCU = 0;
  152303. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  152304. compptr = cinfo->cur_comp_info[ci];
  152305. compptr->MCU_width = compptr->h_samp_factor;
  152306. compptr->MCU_height = compptr->v_samp_factor;
  152307. compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
  152308. compptr->MCU_sample_width = compptr->MCU_width * compptr->DCT_scaled_size;
  152309. tmp = (int) (compptr->width_in_blocks % compptr->MCU_width);
  152310. if (tmp == 0) tmp = compptr->MCU_width;
  152311. compptr->last_col_width = tmp;
  152312. tmp = (int) (compptr->height_in_blocks % compptr->MCU_height);
  152313. if (tmp == 0) tmp = compptr->MCU_height;
  152314. compptr->last_row_height = tmp;
  152315. mcublks = compptr->MCU_blocks;
  152316. if (cinfo->blocks_in_MCU + mcublks > D_MAX_BLOCKS_IN_MCU)
  152317. ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
  152318. while (mcublks-- > 0) {
  152319. cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
  152320. }
  152321. }
  152322. }
  152323. }
  152324. LOCAL(void)
  152325. latch_quant_tables (j_decompress_ptr cinfo)
  152326. {
  152327. int ci, qtblno;
  152328. jpeg_component_info *compptr;
  152329. JQUANT_TBL * qtbl;
  152330. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  152331. compptr = cinfo->cur_comp_info[ci];
  152332. if (compptr->quant_table != NULL)
  152333. continue;
  152334. qtblno = compptr->quant_tbl_no;
  152335. if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
  152336. cinfo->quant_tbl_ptrs[qtblno] == NULL)
  152337. ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
  152338. qtbl = (JQUANT_TBL *)
  152339. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152340. SIZEOF(JQUANT_TBL));
  152341. MEMCOPY(qtbl, cinfo->quant_tbl_ptrs[qtblno], SIZEOF(JQUANT_TBL));
  152342. compptr->quant_table = qtbl;
  152343. }
  152344. }
  152345. METHODDEF(void)
  152346. start_input_pass2 (j_decompress_ptr cinfo)
  152347. {
  152348. per_scan_setup2(cinfo);
  152349. latch_quant_tables(cinfo);
  152350. (*cinfo->entropy->start_pass) (cinfo);
  152351. (*cinfo->coef->start_input_pass) (cinfo);
  152352. cinfo->inputctl->consume_input = cinfo->coef->consume_data;
  152353. }
  152354. METHODDEF(void)
  152355. finish_input_pass (j_decompress_ptr cinfo)
  152356. {
  152357. cinfo->inputctl->consume_input = consume_markers;
  152358. }
  152359. METHODDEF(int)
  152360. consume_markers (j_decompress_ptr cinfo)
  152361. {
  152362. my_inputctl_ptr inputctl = (my_inputctl_ptr) cinfo->inputctl;
  152363. int val;
  152364. if (inputctl->pub.eoi_reached) /* After hitting EOI, read no further */
  152365. return JPEG_REACHED_EOI;
  152366. val = (*cinfo->marker->read_markers) (cinfo);
  152367. switch (val) {
  152368. case JPEG_REACHED_SOS: /* Found SOS */
  152369. if (inputctl->inheaders) { /* 1st SOS */
  152370. initial_setup2(cinfo);
  152371. inputctl->inheaders = FALSE;
  152372. } else { /* 2nd or later SOS marker */
  152373. if (! inputctl->pub.has_multiple_scans)
  152374. ERREXIT(cinfo, JERR_EOI_EXPECTED); /* Oops, I wasn't expecting this! */
  152375. start_input_pass2(cinfo);
  152376. }
  152377. break;
  152378. case JPEG_REACHED_EOI: /* Found EOI */
  152379. inputctl->pub.eoi_reached = TRUE;
  152380. if (inputctl->inheaders) { /* Tables-only datastream, apparently */
  152381. if (cinfo->marker->saw_SOF)
  152382. ERREXIT(cinfo, JERR_SOF_NO_SOS);
  152383. } else {
  152384. if (cinfo->output_scan_number > cinfo->input_scan_number)
  152385. cinfo->output_scan_number = cinfo->input_scan_number;
  152386. }
  152387. break;
  152388. case JPEG_SUSPENDED:
  152389. break;
  152390. }
  152391. return val;
  152392. }
  152393. METHODDEF(void)
  152394. reset_input_controller (j_decompress_ptr cinfo)
  152395. {
  152396. my_inputctl_ptr inputctl = (my_inputctl_ptr) cinfo->inputctl;
  152397. inputctl->pub.consume_input = consume_markers;
  152398. inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */
  152399. inputctl->pub.eoi_reached = FALSE;
  152400. inputctl->inheaders = TRUE;
  152401. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  152402. (*cinfo->marker->reset_marker_reader) (cinfo);
  152403. cinfo->coef_bits = NULL;
  152404. }
  152405. GLOBAL(void)
  152406. jinit_input_controller (j_decompress_ptr cinfo)
  152407. {
  152408. my_inputctl_ptr inputctl;
  152409. inputctl = (my_inputctl_ptr)
  152410. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  152411. SIZEOF(my_input_controller));
  152412. cinfo->inputctl = (struct jpeg_input_controller *) inputctl;
  152413. inputctl->pub.consume_input = consume_markers;
  152414. inputctl->pub.reset_input_controller = reset_input_controller;
  152415. inputctl->pub.start_input_pass = start_input_pass2;
  152416. inputctl->pub.finish_input_pass = finish_input_pass;
  152417. inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */
  152418. inputctl->pub.eoi_reached = FALSE;
  152419. inputctl->inheaders = TRUE;
  152420. }
  152421. /*** End of inlined file: jdinput.c ***/
  152422. /*** Start of inlined file: jdmainct.c ***/
  152423. #define JPEG_INTERNALS
  152424. typedef struct {
  152425. struct jpeg_d_main_controller pub; /* public fields */
  152426. JSAMPARRAY buffer[MAX_COMPONENTS];
  152427. boolean buffer_full; /* Have we gotten an iMCU row from decoder? */
  152428. JDIMENSION rowgroup_ctr; /* counts row groups output to postprocessor */
  152429. JSAMPIMAGE xbuffer[2]; /* pointers to weird pointer lists */
  152430. int whichptr; /* indicates which pointer set is now in use */
  152431. int context_state; /* process_data state machine status */
  152432. JDIMENSION rowgroups_avail; /* row groups available to postprocessor */
  152433. JDIMENSION iMCU_row_ctr; /* counts iMCU rows to detect image top/bot */
  152434. } my_main_controller4;
  152435. typedef my_main_controller4 * my_main_ptr4;
  152436. #define CTX_PREPARE_FOR_IMCU 0 /* need to prepare for MCU row */
  152437. #define CTX_PROCESS_IMCU 1 /* feeding iMCU to postprocessor */
  152438. #define CTX_POSTPONED_ROW 2 /* feeding postponed row group */
  152439. METHODDEF(void) process_data_simple_main2
  152440. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  152441. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  152442. METHODDEF(void) process_data_context_main
  152443. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  152444. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  152445. #ifdef QUANT_2PASS_SUPPORTED
  152446. METHODDEF(void) process_data_crank_post
  152447. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  152448. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  152449. #endif
  152450. LOCAL(void)
  152451. alloc_funny_pointers (j_decompress_ptr cinfo)
  152452. {
  152453. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152454. int ci, rgroup;
  152455. int M = cinfo->min_DCT_scaled_size;
  152456. jpeg_component_info *compptr;
  152457. JSAMPARRAY xbuf;
  152458. main_->xbuffer[0] = (JSAMPIMAGE)
  152459. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152460. cinfo->num_components * 2 * SIZEOF(JSAMPARRAY));
  152461. main_->xbuffer[1] = main_->xbuffer[0] + cinfo->num_components;
  152462. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152463. ci++, compptr++) {
  152464. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152465. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152466. xbuf = (JSAMPARRAY)
  152467. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152468. 2 * (rgroup * (M + 4)) * SIZEOF(JSAMPROW));
  152469. xbuf += rgroup; /* want one row group at negative offsets */
  152470. main_->xbuffer[0][ci] = xbuf;
  152471. xbuf += rgroup * (M + 4);
  152472. main_->xbuffer[1][ci] = xbuf;
  152473. }
  152474. }
  152475. LOCAL(void)
  152476. make_funny_pointers (j_decompress_ptr cinfo)
  152477. {
  152478. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152479. int ci, i, rgroup;
  152480. int M = cinfo->min_DCT_scaled_size;
  152481. jpeg_component_info *compptr;
  152482. JSAMPARRAY buf, xbuf0, xbuf1;
  152483. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152484. ci++, compptr++) {
  152485. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152486. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152487. xbuf0 = main_->xbuffer[0][ci];
  152488. xbuf1 = main_->xbuffer[1][ci];
  152489. buf = main_->buffer[ci];
  152490. for (i = 0; i < rgroup * (M + 2); i++) {
  152491. xbuf0[i] = xbuf1[i] = buf[i];
  152492. }
  152493. for (i = 0; i < rgroup * 2; i++) {
  152494. xbuf1[rgroup*(M-2) + i] = buf[rgroup*M + i];
  152495. xbuf1[rgroup*M + i] = buf[rgroup*(M-2) + i];
  152496. }
  152497. for (i = 0; i < rgroup; i++) {
  152498. xbuf0[i - rgroup] = xbuf0[0];
  152499. }
  152500. }
  152501. }
  152502. LOCAL(void)
  152503. set_wraparound_pointers (j_decompress_ptr cinfo)
  152504. {
  152505. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152506. int ci, i, rgroup;
  152507. int M = cinfo->min_DCT_scaled_size;
  152508. jpeg_component_info *compptr;
  152509. JSAMPARRAY xbuf0, xbuf1;
  152510. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152511. ci++, compptr++) {
  152512. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152513. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152514. xbuf0 = main_->xbuffer[0][ci];
  152515. xbuf1 = main_->xbuffer[1][ci];
  152516. for (i = 0; i < rgroup; i++) {
  152517. xbuf0[i - rgroup] = xbuf0[rgroup*(M+1) + i];
  152518. xbuf1[i - rgroup] = xbuf1[rgroup*(M+1) + i];
  152519. xbuf0[rgroup*(M+2) + i] = xbuf0[i];
  152520. xbuf1[rgroup*(M+2) + i] = xbuf1[i];
  152521. }
  152522. }
  152523. }
  152524. LOCAL(void)
  152525. set_bottom_pointers (j_decompress_ptr cinfo)
  152526. {
  152527. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152528. int ci, i, rgroup, iMCUheight, rows_left;
  152529. jpeg_component_info *compptr;
  152530. JSAMPARRAY xbuf;
  152531. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152532. ci++, compptr++) {
  152533. iMCUheight = compptr->v_samp_factor * compptr->DCT_scaled_size;
  152534. rgroup = iMCUheight / cinfo->min_DCT_scaled_size;
  152535. rows_left = (int) (compptr->downsampled_height % (JDIMENSION) iMCUheight);
  152536. if (rows_left == 0) rows_left = iMCUheight;
  152537. if (ci == 0) {
  152538. main_->rowgroups_avail = (JDIMENSION) ((rows_left-1) / rgroup + 1);
  152539. }
  152540. xbuf = main_->xbuffer[main_->whichptr][ci];
  152541. for (i = 0; i < rgroup * 2; i++) {
  152542. xbuf[rows_left + i] = xbuf[rows_left-1];
  152543. }
  152544. }
  152545. }
  152546. METHODDEF(void)
  152547. start_pass_main2 (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
  152548. {
  152549. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152550. switch (pass_mode) {
  152551. case JBUF_PASS_THRU:
  152552. if (cinfo->upsample->need_context_rows) {
  152553. main_->pub.process_data = process_data_context_main;
  152554. make_funny_pointers(cinfo); /* Create the xbuffer[] lists */
  152555. main_->whichptr = 0; /* Read first iMCU row into xbuffer[0] */
  152556. main_->context_state = CTX_PREPARE_FOR_IMCU;
  152557. main_->iMCU_row_ctr = 0;
  152558. } else {
  152559. main_->pub.process_data = process_data_simple_main2;
  152560. }
  152561. main_->buffer_full = FALSE; /* Mark buffer empty */
  152562. main_->rowgroup_ctr = 0;
  152563. break;
  152564. #ifdef QUANT_2PASS_SUPPORTED
  152565. case JBUF_CRANK_DEST:
  152566. main_->pub.process_data = process_data_crank_post;
  152567. break;
  152568. #endif
  152569. default:
  152570. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  152571. break;
  152572. }
  152573. }
  152574. METHODDEF(void)
  152575. process_data_simple_main2 (j_decompress_ptr cinfo,
  152576. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  152577. JDIMENSION out_rows_avail)
  152578. {
  152579. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152580. JDIMENSION rowgroups_avail;
  152581. if (! main_->buffer_full) {
  152582. if (! (*cinfo->coef->decompress_data) (cinfo, main_->buffer))
  152583. return; /* suspension forced, can do nothing more */
  152584. main_->buffer_full = TRUE; /* OK, we have an iMCU row to work with */
  152585. }
  152586. rowgroups_avail = (JDIMENSION) cinfo->min_DCT_scaled_size;
  152587. (*cinfo->post->post_process_data) (cinfo, main_->buffer,
  152588. &main_->rowgroup_ctr, rowgroups_avail,
  152589. output_buf, out_row_ctr, out_rows_avail);
  152590. if (main_->rowgroup_ctr >= rowgroups_avail) {
  152591. main_->buffer_full = FALSE;
  152592. main_->rowgroup_ctr = 0;
  152593. }
  152594. }
  152595. METHODDEF(void)
  152596. process_data_context_main (j_decompress_ptr cinfo,
  152597. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  152598. JDIMENSION out_rows_avail)
  152599. {
  152600. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152601. if (! main_->buffer_full) {
  152602. if (! (*cinfo->coef->decompress_data) (cinfo,
  152603. main_->xbuffer[main_->whichptr]))
  152604. return; /* suspension forced, can do nothing more */
  152605. main_->buffer_full = TRUE; /* OK, we have an iMCU row to work with */
  152606. main_->iMCU_row_ctr++; /* count rows received */
  152607. }
  152608. switch (main_->context_state) {
  152609. case CTX_POSTPONED_ROW:
  152610. (*cinfo->post->post_process_data) (cinfo, main_->xbuffer[main_->whichptr],
  152611. &main_->rowgroup_ctr, main_->rowgroups_avail,
  152612. output_buf, out_row_ctr, out_rows_avail);
  152613. if (main_->rowgroup_ctr < main_->rowgroups_avail)
  152614. return; /* Need to suspend */
  152615. main_->context_state = CTX_PREPARE_FOR_IMCU;
  152616. if (*out_row_ctr >= out_rows_avail)
  152617. return; /* Postprocessor exactly filled output buf */
  152618. case CTX_PREPARE_FOR_IMCU:
  152619. main_->rowgroup_ctr = 0;
  152620. main_->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_scaled_size - 1);
  152621. if (main_->iMCU_row_ctr == cinfo->total_iMCU_rows)
  152622. set_bottom_pointers(cinfo);
  152623. main_->context_state = CTX_PROCESS_IMCU;
  152624. case CTX_PROCESS_IMCU:
  152625. (*cinfo->post->post_process_data) (cinfo, main_->xbuffer[main_->whichptr],
  152626. &main_->rowgroup_ctr, main_->rowgroups_avail,
  152627. output_buf, out_row_ctr, out_rows_avail);
  152628. if (main_->rowgroup_ctr < main_->rowgroups_avail)
  152629. return; /* Need to suspend */
  152630. if (main_->iMCU_row_ctr == 1)
  152631. set_wraparound_pointers(cinfo);
  152632. main_->whichptr ^= 1; /* 0=>1 or 1=>0 */
  152633. main_->buffer_full = FALSE;
  152634. main_->rowgroup_ctr = (JDIMENSION) (cinfo->min_DCT_scaled_size + 1);
  152635. main_->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_scaled_size + 2);
  152636. main_->context_state = CTX_POSTPONED_ROW;
  152637. }
  152638. }
  152639. #ifdef QUANT_2PASS_SUPPORTED
  152640. METHODDEF(void)
  152641. process_data_crank_post (j_decompress_ptr cinfo,
  152642. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  152643. JDIMENSION out_rows_avail)
  152644. {
  152645. (*cinfo->post->post_process_data) (cinfo, (JSAMPIMAGE) NULL,
  152646. (JDIMENSION *) NULL, (JDIMENSION) 0,
  152647. output_buf, out_row_ctr, out_rows_avail);
  152648. }
  152649. #endif /* QUANT_2PASS_SUPPORTED */
  152650. GLOBAL(void)
  152651. jinit_d_main_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
  152652. {
  152653. my_main_ptr4 main_;
  152654. int ci, rgroup, ngroups;
  152655. jpeg_component_info *compptr;
  152656. main_ = (my_main_ptr4)
  152657. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152658. SIZEOF(my_main_controller4));
  152659. cinfo->main = (struct jpeg_d_main_controller *) main_;
  152660. main_->pub.start_pass = start_pass_main2;
  152661. if (need_full_buffer) /* shouldn't happen */
  152662. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  152663. if (cinfo->upsample->need_context_rows) {
  152664. if (cinfo->min_DCT_scaled_size < 2) /* unsupported, see comments above */
  152665. ERREXIT(cinfo, JERR_NOTIMPL);
  152666. alloc_funny_pointers(cinfo); /* Alloc space for xbuffer[] lists */
  152667. ngroups = cinfo->min_DCT_scaled_size + 2;
  152668. } else {
  152669. ngroups = cinfo->min_DCT_scaled_size;
  152670. }
  152671. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152672. ci++, compptr++) {
  152673. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152674. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152675. main_->buffer[ci] = (*cinfo->mem->alloc_sarray)
  152676. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152677. compptr->width_in_blocks * compptr->DCT_scaled_size,
  152678. (JDIMENSION) (rgroup * ngroups));
  152679. }
  152680. }
  152681. /*** End of inlined file: jdmainct.c ***/
  152682. /*** Start of inlined file: jdmarker.c ***/
  152683. #define JPEG_INTERNALS
  152684. typedef struct {
  152685. struct jpeg_marker_reader pub; /* public fields */
  152686. jpeg_marker_parser_method process_COM;
  152687. jpeg_marker_parser_method process_APPn[16];
  152688. unsigned int length_limit_COM;
  152689. unsigned int length_limit_APPn[16];
  152690. jpeg_saved_marker_ptr cur_marker; /* NULL if not processing a marker */
  152691. unsigned int bytes_read; /* data bytes read so far in marker */
  152692. } my_marker_reader;
  152693. typedef my_marker_reader * my_marker_ptr2;
  152694. #define INPUT_VARS(cinfo) \
  152695. struct jpeg_source_mgr * datasrc = (cinfo)->src; \
  152696. const JOCTET * next_input_byte = datasrc->next_input_byte; \
  152697. size_t bytes_in_buffer = datasrc->bytes_in_buffer
  152698. #define INPUT_SYNC(cinfo) \
  152699. ( datasrc->next_input_byte = next_input_byte, \
  152700. datasrc->bytes_in_buffer = bytes_in_buffer )
  152701. #define INPUT_RELOAD(cinfo) \
  152702. ( next_input_byte = datasrc->next_input_byte, \
  152703. bytes_in_buffer = datasrc->bytes_in_buffer )
  152704. #define MAKE_BYTE_AVAIL(cinfo,action) \
  152705. if (bytes_in_buffer == 0) { \
  152706. if (! (*datasrc->fill_input_buffer) (cinfo)) \
  152707. { action; } \
  152708. INPUT_RELOAD(cinfo); \
  152709. }
  152710. #define INPUT_BYTE(cinfo,V,action) \
  152711. MAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \
  152712. bytes_in_buffer--; \
  152713. V = GETJOCTET(*next_input_byte++); )
  152714. #define INPUT_2BYTES(cinfo,V,action) \
  152715. MAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \
  152716. bytes_in_buffer--; \
  152717. V = ((unsigned int) GETJOCTET(*next_input_byte++)) << 8; \
  152718. MAKE_BYTE_AVAIL(cinfo,action); \
  152719. bytes_in_buffer--; \
  152720. V += GETJOCTET(*next_input_byte++); )
  152721. LOCAL(boolean)
  152722. get_soi (j_decompress_ptr cinfo)
  152723. {
  152724. int i;
  152725. TRACEMS(cinfo, 1, JTRC_SOI);
  152726. if (cinfo->marker->saw_SOI)
  152727. ERREXIT(cinfo, JERR_SOI_DUPLICATE);
  152728. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  152729. cinfo->arith_dc_L[i] = 0;
  152730. cinfo->arith_dc_U[i] = 1;
  152731. cinfo->arith_ac_K[i] = 5;
  152732. }
  152733. cinfo->restart_interval = 0;
  152734. cinfo->jpeg_color_space = JCS_UNKNOWN;
  152735. cinfo->CCIR601_sampling = FALSE; /* Assume non-CCIR sampling??? */
  152736. cinfo->saw_JFIF_marker = FALSE;
  152737. cinfo->JFIF_major_version = 1; /* set default JFIF APP0 values */
  152738. cinfo->JFIF_minor_version = 1;
  152739. cinfo->density_unit = 0;
  152740. cinfo->X_density = 1;
  152741. cinfo->Y_density = 1;
  152742. cinfo->saw_Adobe_marker = FALSE;
  152743. cinfo->Adobe_transform = 0;
  152744. cinfo->marker->saw_SOI = TRUE;
  152745. return TRUE;
  152746. }
  152747. LOCAL(boolean)
  152748. get_sof (j_decompress_ptr cinfo, boolean is_prog, boolean is_arith)
  152749. {
  152750. INT32 length;
  152751. int c, ci;
  152752. jpeg_component_info * compptr;
  152753. INPUT_VARS(cinfo);
  152754. cinfo->progressive_mode = is_prog;
  152755. cinfo->arith_code = is_arith;
  152756. INPUT_2BYTES(cinfo, length, return FALSE);
  152757. INPUT_BYTE(cinfo, cinfo->data_precision, return FALSE);
  152758. INPUT_2BYTES(cinfo, cinfo->image_height, return FALSE);
  152759. INPUT_2BYTES(cinfo, cinfo->image_width, return FALSE);
  152760. INPUT_BYTE(cinfo, cinfo->num_components, return FALSE);
  152761. length -= 8;
  152762. TRACEMS4(cinfo, 1, JTRC_SOF, cinfo->unread_marker,
  152763. (int) cinfo->image_width, (int) cinfo->image_height,
  152764. cinfo->num_components);
  152765. if (cinfo->marker->saw_SOF)
  152766. ERREXIT(cinfo, JERR_SOF_DUPLICATE);
  152767. if (cinfo->image_height <= 0 || cinfo->image_width <= 0
  152768. || cinfo->num_components <= 0)
  152769. ERREXIT(cinfo, JERR_EMPTY_IMAGE);
  152770. if (length != (cinfo->num_components * 3))
  152771. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152772. if (cinfo->comp_info == NULL) /* do only once, even if suspend */
  152773. cinfo->comp_info = (jpeg_component_info *) (*cinfo->mem->alloc_small)
  152774. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152775. cinfo->num_components * SIZEOF(jpeg_component_info));
  152776. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152777. ci++, compptr++) {
  152778. compptr->component_index = ci;
  152779. INPUT_BYTE(cinfo, compptr->component_id, return FALSE);
  152780. INPUT_BYTE(cinfo, c, return FALSE);
  152781. compptr->h_samp_factor = (c >> 4) & 15;
  152782. compptr->v_samp_factor = (c ) & 15;
  152783. INPUT_BYTE(cinfo, compptr->quant_tbl_no, return FALSE);
  152784. TRACEMS4(cinfo, 1, JTRC_SOF_COMPONENT,
  152785. compptr->component_id, compptr->h_samp_factor,
  152786. compptr->v_samp_factor, compptr->quant_tbl_no);
  152787. }
  152788. cinfo->marker->saw_SOF = TRUE;
  152789. INPUT_SYNC(cinfo);
  152790. return TRUE;
  152791. }
  152792. LOCAL(boolean)
  152793. get_sos (j_decompress_ptr cinfo)
  152794. {
  152795. INT32 length;
  152796. int i, ci, n, c, cc;
  152797. jpeg_component_info * compptr;
  152798. INPUT_VARS(cinfo);
  152799. if (! cinfo->marker->saw_SOF)
  152800. ERREXIT(cinfo, JERR_SOS_NO_SOF);
  152801. INPUT_2BYTES(cinfo, length, return FALSE);
  152802. INPUT_BYTE(cinfo, n, return FALSE); /* Number of components */
  152803. TRACEMS1(cinfo, 1, JTRC_SOS, n);
  152804. if (length != (n * 2 + 6) || n < 1 || n > MAX_COMPS_IN_SCAN)
  152805. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152806. cinfo->comps_in_scan = n;
  152807. for (i = 0; i < n; i++) {
  152808. INPUT_BYTE(cinfo, cc, return FALSE);
  152809. INPUT_BYTE(cinfo, c, return FALSE);
  152810. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152811. ci++, compptr++) {
  152812. if (cc == compptr->component_id)
  152813. goto id_found;
  152814. }
  152815. ERREXIT1(cinfo, JERR_BAD_COMPONENT_ID, cc);
  152816. id_found:
  152817. cinfo->cur_comp_info[i] = compptr;
  152818. compptr->dc_tbl_no = (c >> 4) & 15;
  152819. compptr->ac_tbl_no = (c ) & 15;
  152820. TRACEMS3(cinfo, 1, JTRC_SOS_COMPONENT, cc,
  152821. compptr->dc_tbl_no, compptr->ac_tbl_no);
  152822. }
  152823. INPUT_BYTE(cinfo, c, return FALSE);
  152824. cinfo->Ss = c;
  152825. INPUT_BYTE(cinfo, c, return FALSE);
  152826. cinfo->Se = c;
  152827. INPUT_BYTE(cinfo, c, return FALSE);
  152828. cinfo->Ah = (c >> 4) & 15;
  152829. cinfo->Al = (c ) & 15;
  152830. TRACEMS4(cinfo, 1, JTRC_SOS_PARAMS, cinfo->Ss, cinfo->Se,
  152831. cinfo->Ah, cinfo->Al);
  152832. cinfo->marker->next_restart_num = 0;
  152833. cinfo->input_scan_number++;
  152834. INPUT_SYNC(cinfo);
  152835. return TRUE;
  152836. }
  152837. #ifdef D_ARITH_CODING_SUPPORTED
  152838. LOCAL(boolean)
  152839. get_dac (j_decompress_ptr cinfo)
  152840. {
  152841. INT32 length;
  152842. int index, val;
  152843. INPUT_VARS(cinfo);
  152844. INPUT_2BYTES(cinfo, length, return FALSE);
  152845. length -= 2;
  152846. while (length > 0) {
  152847. INPUT_BYTE(cinfo, index, return FALSE);
  152848. INPUT_BYTE(cinfo, val, return FALSE);
  152849. length -= 2;
  152850. TRACEMS2(cinfo, 1, JTRC_DAC, index, val);
  152851. if (index < 0 || index >= (2*NUM_ARITH_TBLS))
  152852. ERREXIT1(cinfo, JERR_DAC_INDEX, index);
  152853. if (index >= NUM_ARITH_TBLS) { /* define AC table */
  152854. cinfo->arith_ac_K[index-NUM_ARITH_TBLS] = (UINT8) val;
  152855. } else { /* define DC table */
  152856. cinfo->arith_dc_L[index] = (UINT8) (val & 0x0F);
  152857. cinfo->arith_dc_U[index] = (UINT8) (val >> 4);
  152858. if (cinfo->arith_dc_L[index] > cinfo->arith_dc_U[index])
  152859. ERREXIT1(cinfo, JERR_DAC_VALUE, val);
  152860. }
  152861. }
  152862. if (length != 0)
  152863. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152864. INPUT_SYNC(cinfo);
  152865. return TRUE;
  152866. }
  152867. #else /* ! D_ARITH_CODING_SUPPORTED */
  152868. #define get_dac(cinfo) skip_variable(cinfo)
  152869. #endif /* D_ARITH_CODING_SUPPORTED */
  152870. LOCAL(boolean)
  152871. get_dht (j_decompress_ptr cinfo)
  152872. {
  152873. INT32 length;
  152874. UINT8 bits[17];
  152875. UINT8 huffval[256];
  152876. int i, index, count;
  152877. JHUFF_TBL **htblptr;
  152878. INPUT_VARS(cinfo);
  152879. INPUT_2BYTES(cinfo, length, return FALSE);
  152880. length -= 2;
  152881. while (length > 16) {
  152882. INPUT_BYTE(cinfo, index, return FALSE);
  152883. TRACEMS1(cinfo, 1, JTRC_DHT, index);
  152884. bits[0] = 0;
  152885. count = 0;
  152886. for (i = 1; i <= 16; i++) {
  152887. INPUT_BYTE(cinfo, bits[i], return FALSE);
  152888. count += bits[i];
  152889. }
  152890. length -= 1 + 16;
  152891. TRACEMS8(cinfo, 2, JTRC_HUFFBITS,
  152892. bits[1], bits[2], bits[3], bits[4],
  152893. bits[5], bits[6], bits[7], bits[8]);
  152894. TRACEMS8(cinfo, 2, JTRC_HUFFBITS,
  152895. bits[9], bits[10], bits[11], bits[12],
  152896. bits[13], bits[14], bits[15], bits[16]);
  152897. if (count > 256 || ((INT32) count) > length)
  152898. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  152899. for (i = 0; i < count; i++)
  152900. INPUT_BYTE(cinfo, huffval[i], return FALSE);
  152901. length -= count;
  152902. if (index & 0x10) { /* AC table definition */
  152903. index -= 0x10;
  152904. htblptr = &cinfo->ac_huff_tbl_ptrs[index];
  152905. } else { /* DC table definition */
  152906. htblptr = &cinfo->dc_huff_tbl_ptrs[index];
  152907. }
  152908. if (index < 0 || index >= NUM_HUFF_TBLS)
  152909. ERREXIT1(cinfo, JERR_DHT_INDEX, index);
  152910. if (*htblptr == NULL)
  152911. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  152912. MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits));
  152913. MEMCOPY((*htblptr)->huffval, huffval, SIZEOF((*htblptr)->huffval));
  152914. }
  152915. if (length != 0)
  152916. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152917. INPUT_SYNC(cinfo);
  152918. return TRUE;
  152919. }
  152920. LOCAL(boolean)
  152921. get_dqt (j_decompress_ptr cinfo)
  152922. {
  152923. INT32 length;
  152924. int n, i, prec;
  152925. unsigned int tmp;
  152926. JQUANT_TBL *quant_ptr;
  152927. INPUT_VARS(cinfo);
  152928. INPUT_2BYTES(cinfo, length, return FALSE);
  152929. length -= 2;
  152930. while (length > 0) {
  152931. INPUT_BYTE(cinfo, n, return FALSE);
  152932. prec = n >> 4;
  152933. n &= 0x0F;
  152934. TRACEMS2(cinfo, 1, JTRC_DQT, n, prec);
  152935. if (n >= NUM_QUANT_TBLS)
  152936. ERREXIT1(cinfo, JERR_DQT_INDEX, n);
  152937. if (cinfo->quant_tbl_ptrs[n] == NULL)
  152938. cinfo->quant_tbl_ptrs[n] = jpeg_alloc_quant_table((j_common_ptr) cinfo);
  152939. quant_ptr = cinfo->quant_tbl_ptrs[n];
  152940. for (i = 0; i < DCTSIZE2; i++) {
  152941. if (prec)
  152942. INPUT_2BYTES(cinfo, tmp, return FALSE);
  152943. else
  152944. INPUT_BYTE(cinfo, tmp, return FALSE);
  152945. quant_ptr->quantval[jpeg_natural_order[i]] = (UINT16) tmp;
  152946. }
  152947. if (cinfo->err->trace_level >= 2) {
  152948. for (i = 0; i < DCTSIZE2; i += 8) {
  152949. TRACEMS8(cinfo, 2, JTRC_QUANTVALS,
  152950. quant_ptr->quantval[i], quant_ptr->quantval[i+1],
  152951. quant_ptr->quantval[i+2], quant_ptr->quantval[i+3],
  152952. quant_ptr->quantval[i+4], quant_ptr->quantval[i+5],
  152953. quant_ptr->quantval[i+6], quant_ptr->quantval[i+7]);
  152954. }
  152955. }
  152956. length -= DCTSIZE2+1;
  152957. if (prec) length -= DCTSIZE2;
  152958. }
  152959. if (length != 0)
  152960. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152961. INPUT_SYNC(cinfo);
  152962. return TRUE;
  152963. }
  152964. LOCAL(boolean)
  152965. get_dri (j_decompress_ptr cinfo)
  152966. {
  152967. INT32 length;
  152968. unsigned int tmp;
  152969. INPUT_VARS(cinfo);
  152970. INPUT_2BYTES(cinfo, length, return FALSE);
  152971. if (length != 4)
  152972. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152973. INPUT_2BYTES(cinfo, tmp, return FALSE);
  152974. TRACEMS1(cinfo, 1, JTRC_DRI, tmp);
  152975. cinfo->restart_interval = tmp;
  152976. INPUT_SYNC(cinfo);
  152977. return TRUE;
  152978. }
  152979. #define APP0_DATA_LEN 14 /* Length of interesting data in APP0 */
  152980. #define APP14_DATA_LEN 12 /* Length of interesting data in APP14 */
  152981. #define APPN_DATA_LEN 14 /* Must be the largest of the above!! */
  152982. LOCAL(void)
  152983. examine_app0 (j_decompress_ptr cinfo, JOCTET FAR * data,
  152984. unsigned int datalen, INT32 remaining)
  152985. {
  152986. INT32 totallen = (INT32) datalen + remaining;
  152987. if (datalen >= APP0_DATA_LEN &&
  152988. GETJOCTET(data[0]) == 0x4A &&
  152989. GETJOCTET(data[1]) == 0x46 &&
  152990. GETJOCTET(data[2]) == 0x49 &&
  152991. GETJOCTET(data[3]) == 0x46 &&
  152992. GETJOCTET(data[4]) == 0) {
  152993. cinfo->saw_JFIF_marker = TRUE;
  152994. cinfo->JFIF_major_version = GETJOCTET(data[5]);
  152995. cinfo->JFIF_minor_version = GETJOCTET(data[6]);
  152996. cinfo->density_unit = GETJOCTET(data[7]);
  152997. cinfo->X_density = (GETJOCTET(data[8]) << 8) + GETJOCTET(data[9]);
  152998. cinfo->Y_density = (GETJOCTET(data[10]) << 8) + GETJOCTET(data[11]);
  152999. if (cinfo->JFIF_major_version != 1)
  153000. WARNMS2(cinfo, JWRN_JFIF_MAJOR,
  153001. cinfo->JFIF_major_version, cinfo->JFIF_minor_version);
  153002. TRACEMS5(cinfo, 1, JTRC_JFIF,
  153003. cinfo->JFIF_major_version, cinfo->JFIF_minor_version,
  153004. cinfo->X_density, cinfo->Y_density, cinfo->density_unit);
  153005. if (GETJOCTET(data[12]) | GETJOCTET(data[13]))
  153006. TRACEMS2(cinfo, 1, JTRC_JFIF_THUMBNAIL,
  153007. GETJOCTET(data[12]), GETJOCTET(data[13]));
  153008. totallen -= APP0_DATA_LEN;
  153009. if (totallen !=
  153010. ((INT32)GETJOCTET(data[12]) * (INT32)GETJOCTET(data[13]) * (INT32) 3))
  153011. TRACEMS1(cinfo, 1, JTRC_JFIF_BADTHUMBNAILSIZE, (int) totallen);
  153012. } else if (datalen >= 6 &&
  153013. GETJOCTET(data[0]) == 0x4A &&
  153014. GETJOCTET(data[1]) == 0x46 &&
  153015. GETJOCTET(data[2]) == 0x58 &&
  153016. GETJOCTET(data[3]) == 0x58 &&
  153017. GETJOCTET(data[4]) == 0) {
  153018. switch (GETJOCTET(data[5])) {
  153019. case 0x10:
  153020. TRACEMS1(cinfo, 1, JTRC_THUMB_JPEG, (int) totallen);
  153021. break;
  153022. case 0x11:
  153023. TRACEMS1(cinfo, 1, JTRC_THUMB_PALETTE, (int) totallen);
  153024. break;
  153025. case 0x13:
  153026. TRACEMS1(cinfo, 1, JTRC_THUMB_RGB, (int) totallen);
  153027. break;
  153028. default:
  153029. TRACEMS2(cinfo, 1, JTRC_JFIF_EXTENSION,
  153030. GETJOCTET(data[5]), (int) totallen);
  153031. break;
  153032. }
  153033. } else {
  153034. TRACEMS1(cinfo, 1, JTRC_APP0, (int) totallen);
  153035. }
  153036. }
  153037. LOCAL(void)
  153038. examine_app14 (j_decompress_ptr cinfo, JOCTET FAR * data,
  153039. unsigned int datalen, INT32 remaining)
  153040. {
  153041. unsigned int version, flags0, flags1, transform;
  153042. if (datalen >= APP14_DATA_LEN &&
  153043. GETJOCTET(data[0]) == 0x41 &&
  153044. GETJOCTET(data[1]) == 0x64 &&
  153045. GETJOCTET(data[2]) == 0x6F &&
  153046. GETJOCTET(data[3]) == 0x62 &&
  153047. GETJOCTET(data[4]) == 0x65) {
  153048. version = (GETJOCTET(data[5]) << 8) + GETJOCTET(data[6]);
  153049. flags0 = (GETJOCTET(data[7]) << 8) + GETJOCTET(data[8]);
  153050. flags1 = (GETJOCTET(data[9]) << 8) + GETJOCTET(data[10]);
  153051. transform = GETJOCTET(data[11]);
  153052. TRACEMS4(cinfo, 1, JTRC_ADOBE, version, flags0, flags1, transform);
  153053. cinfo->saw_Adobe_marker = TRUE;
  153054. cinfo->Adobe_transform = (UINT8) transform;
  153055. } else {
  153056. TRACEMS1(cinfo, 1, JTRC_APP14, (int) (datalen + remaining));
  153057. }
  153058. }
  153059. METHODDEF(boolean)
  153060. get_interesting_appn (j_decompress_ptr cinfo)
  153061. {
  153062. INT32 length;
  153063. JOCTET b[APPN_DATA_LEN];
  153064. unsigned int i, numtoread;
  153065. INPUT_VARS(cinfo);
  153066. INPUT_2BYTES(cinfo, length, return FALSE);
  153067. length -= 2;
  153068. if (length >= APPN_DATA_LEN)
  153069. numtoread = APPN_DATA_LEN;
  153070. else if (length > 0)
  153071. numtoread = (unsigned int) length;
  153072. else
  153073. numtoread = 0;
  153074. for (i = 0; i < numtoread; i++)
  153075. INPUT_BYTE(cinfo, b[i], return FALSE);
  153076. length -= numtoread;
  153077. switch (cinfo->unread_marker) {
  153078. case M_APP0:
  153079. examine_app0(cinfo, (JOCTET FAR *) b, numtoread, length);
  153080. break;
  153081. case M_APP14:
  153082. examine_app14(cinfo, (JOCTET FAR *) b, numtoread, length);
  153083. break;
  153084. default:
  153085. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo->unread_marker);
  153086. break;
  153087. }
  153088. INPUT_SYNC(cinfo);
  153089. if (length > 0)
  153090. (*cinfo->src->skip_input_data) (cinfo, (long) length);
  153091. return TRUE;
  153092. }
  153093. #ifdef SAVE_MARKERS_SUPPORTED
  153094. METHODDEF(boolean)
  153095. save_marker (j_decompress_ptr cinfo)
  153096. {
  153097. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153098. jpeg_saved_marker_ptr cur_marker = marker->cur_marker;
  153099. unsigned int bytes_read, data_length;
  153100. JOCTET FAR * data;
  153101. INT32 length = 0;
  153102. INPUT_VARS(cinfo);
  153103. if (cur_marker == NULL) {
  153104. INPUT_2BYTES(cinfo, length, return FALSE);
  153105. length -= 2;
  153106. if (length >= 0) { /* watch out for bogus length word */
  153107. unsigned int limit;
  153108. if (cinfo->unread_marker == (int) M_COM)
  153109. limit = marker->length_limit_COM;
  153110. else
  153111. limit = marker->length_limit_APPn[cinfo->unread_marker - (int) M_APP0];
  153112. if ((unsigned int) length < limit)
  153113. limit = (unsigned int) length;
  153114. cur_marker = (jpeg_saved_marker_ptr)
  153115. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153116. SIZEOF(struct jpeg_marker_struct) + limit);
  153117. cur_marker->next = NULL;
  153118. cur_marker->marker = (UINT8) cinfo->unread_marker;
  153119. cur_marker->original_length = (unsigned int) length;
  153120. cur_marker->data_length = limit;
  153121. data = cur_marker->data = (JOCTET FAR *) (cur_marker + 1);
  153122. marker->cur_marker = cur_marker;
  153123. marker->bytes_read = 0;
  153124. bytes_read = 0;
  153125. data_length = limit;
  153126. } else {
  153127. bytes_read = data_length = 0;
  153128. data = NULL;
  153129. }
  153130. } else {
  153131. bytes_read = marker->bytes_read;
  153132. data_length = cur_marker->data_length;
  153133. data = cur_marker->data + bytes_read;
  153134. }
  153135. while (bytes_read < data_length) {
  153136. INPUT_SYNC(cinfo); /* move the restart point to here */
  153137. marker->bytes_read = bytes_read;
  153138. MAKE_BYTE_AVAIL(cinfo, return FALSE);
  153139. while (bytes_read < data_length && bytes_in_buffer > 0) {
  153140. *data++ = *next_input_byte++;
  153141. bytes_in_buffer--;
  153142. bytes_read++;
  153143. }
  153144. }
  153145. if (cur_marker != NULL) { /* will be NULL if bogus length word */
  153146. if (cinfo->marker_list == NULL) {
  153147. cinfo->marker_list = cur_marker;
  153148. } else {
  153149. jpeg_saved_marker_ptr prev = cinfo->marker_list;
  153150. while (prev->next != NULL)
  153151. prev = prev->next;
  153152. prev->next = cur_marker;
  153153. }
  153154. data = cur_marker->data;
  153155. length = cur_marker->original_length - data_length;
  153156. }
  153157. marker->cur_marker = NULL;
  153158. switch (cinfo->unread_marker) {
  153159. case M_APP0:
  153160. examine_app0(cinfo, data, data_length, length);
  153161. break;
  153162. case M_APP14:
  153163. examine_app14(cinfo, data, data_length, length);
  153164. break;
  153165. default:
  153166. TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker,
  153167. (int) (data_length + length));
  153168. break;
  153169. }
  153170. INPUT_SYNC(cinfo); /* do before skip_input_data */
  153171. if (length > 0)
  153172. (*cinfo->src->skip_input_data) (cinfo, (long) length);
  153173. return TRUE;
  153174. }
  153175. #endif /* SAVE_MARKERS_SUPPORTED */
  153176. METHODDEF(boolean)
  153177. skip_variable (j_decompress_ptr cinfo)
  153178. {
  153179. INT32 length;
  153180. INPUT_VARS(cinfo);
  153181. INPUT_2BYTES(cinfo, length, return FALSE);
  153182. length -= 2;
  153183. TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker, (int) length);
  153184. INPUT_SYNC(cinfo); /* do before skip_input_data */
  153185. if (length > 0)
  153186. (*cinfo->src->skip_input_data) (cinfo, (long) length);
  153187. return TRUE;
  153188. }
  153189. LOCAL(boolean)
  153190. next_marker (j_decompress_ptr cinfo)
  153191. {
  153192. int c;
  153193. INPUT_VARS(cinfo);
  153194. for (;;) {
  153195. INPUT_BYTE(cinfo, c, return FALSE);
  153196. while (c != 0xFF) {
  153197. cinfo->marker->discarded_bytes++;
  153198. INPUT_SYNC(cinfo);
  153199. INPUT_BYTE(cinfo, c, return FALSE);
  153200. }
  153201. do {
  153202. INPUT_BYTE(cinfo, c, return FALSE);
  153203. } while (c == 0xFF);
  153204. if (c != 0)
  153205. break; /* found a valid marker, exit loop */
  153206. cinfo->marker->discarded_bytes += 2;
  153207. INPUT_SYNC(cinfo);
  153208. }
  153209. if (cinfo->marker->discarded_bytes != 0) {
  153210. WARNMS2(cinfo, JWRN_EXTRANEOUS_DATA, cinfo->marker->discarded_bytes, c);
  153211. cinfo->marker->discarded_bytes = 0;
  153212. }
  153213. cinfo->unread_marker = c;
  153214. INPUT_SYNC(cinfo);
  153215. return TRUE;
  153216. }
  153217. LOCAL(boolean)
  153218. first_marker (j_decompress_ptr cinfo)
  153219. {
  153220. int c, c2;
  153221. INPUT_VARS(cinfo);
  153222. INPUT_BYTE(cinfo, c, return FALSE);
  153223. INPUT_BYTE(cinfo, c2, return FALSE);
  153224. if (c != 0xFF || c2 != (int) M_SOI)
  153225. ERREXIT2(cinfo, JERR_NO_SOI, c, c2);
  153226. cinfo->unread_marker = c2;
  153227. INPUT_SYNC(cinfo);
  153228. return TRUE;
  153229. }
  153230. METHODDEF(int)
  153231. read_markers (j_decompress_ptr cinfo)
  153232. {
  153233. for (;;) {
  153234. if (cinfo->unread_marker == 0) {
  153235. if (! cinfo->marker->saw_SOI) {
  153236. if (! first_marker(cinfo))
  153237. return JPEG_SUSPENDED;
  153238. } else {
  153239. if (! next_marker(cinfo))
  153240. return JPEG_SUSPENDED;
  153241. }
  153242. }
  153243. switch (cinfo->unread_marker) {
  153244. case M_SOI:
  153245. if (! get_soi(cinfo))
  153246. return JPEG_SUSPENDED;
  153247. break;
  153248. case M_SOF0: /* Baseline */
  153249. case M_SOF1: /* Extended sequential, Huffman */
  153250. if (! get_sof(cinfo, FALSE, FALSE))
  153251. return JPEG_SUSPENDED;
  153252. break;
  153253. case M_SOF2: /* Progressive, Huffman */
  153254. if (! get_sof(cinfo, TRUE, FALSE))
  153255. return JPEG_SUSPENDED;
  153256. break;
  153257. case M_SOF9: /* Extended sequential, arithmetic */
  153258. if (! get_sof(cinfo, FALSE, TRUE))
  153259. return JPEG_SUSPENDED;
  153260. break;
  153261. case M_SOF10: /* Progressive, arithmetic */
  153262. if (! get_sof(cinfo, TRUE, TRUE))
  153263. return JPEG_SUSPENDED;
  153264. break;
  153265. case M_SOF3: /* Lossless, Huffman */
  153266. case M_SOF5: /* Differential sequential, Huffman */
  153267. case M_SOF6: /* Differential progressive, Huffman */
  153268. case M_SOF7: /* Differential lossless, Huffman */
  153269. case M_JPG: /* Reserved for JPEG extensions */
  153270. case M_SOF11: /* Lossless, arithmetic */
  153271. case M_SOF13: /* Differential sequential, arithmetic */
  153272. case M_SOF14: /* Differential progressive, arithmetic */
  153273. case M_SOF15: /* Differential lossless, arithmetic */
  153274. ERREXIT1(cinfo, JERR_SOF_UNSUPPORTED, cinfo->unread_marker);
  153275. break;
  153276. case M_SOS:
  153277. if (! get_sos(cinfo))
  153278. return JPEG_SUSPENDED;
  153279. cinfo->unread_marker = 0; /* processed the marker */
  153280. return JPEG_REACHED_SOS;
  153281. case M_EOI:
  153282. TRACEMS(cinfo, 1, JTRC_EOI);
  153283. cinfo->unread_marker = 0; /* processed the marker */
  153284. return JPEG_REACHED_EOI;
  153285. case M_DAC:
  153286. if (! get_dac(cinfo))
  153287. return JPEG_SUSPENDED;
  153288. break;
  153289. case M_DHT:
  153290. if (! get_dht(cinfo))
  153291. return JPEG_SUSPENDED;
  153292. break;
  153293. case M_DQT:
  153294. if (! get_dqt(cinfo))
  153295. return JPEG_SUSPENDED;
  153296. break;
  153297. case M_DRI:
  153298. if (! get_dri(cinfo))
  153299. return JPEG_SUSPENDED;
  153300. break;
  153301. case M_APP0:
  153302. case M_APP1:
  153303. case M_APP2:
  153304. case M_APP3:
  153305. case M_APP4:
  153306. case M_APP5:
  153307. case M_APP6:
  153308. case M_APP7:
  153309. case M_APP8:
  153310. case M_APP9:
  153311. case M_APP10:
  153312. case M_APP11:
  153313. case M_APP12:
  153314. case M_APP13:
  153315. case M_APP14:
  153316. case M_APP15:
  153317. if (! (*((my_marker_ptr2) cinfo->marker)->process_APPn[
  153318. cinfo->unread_marker - (int) M_APP0]) (cinfo))
  153319. return JPEG_SUSPENDED;
  153320. break;
  153321. case M_COM:
  153322. if (! (*((my_marker_ptr2) cinfo->marker)->process_COM) (cinfo))
  153323. return JPEG_SUSPENDED;
  153324. break;
  153325. case M_RST0: /* these are all parameterless */
  153326. case M_RST1:
  153327. case M_RST2:
  153328. case M_RST3:
  153329. case M_RST4:
  153330. case M_RST5:
  153331. case M_RST6:
  153332. case M_RST7:
  153333. case M_TEM:
  153334. TRACEMS1(cinfo, 1, JTRC_PARMLESS_MARKER, cinfo->unread_marker);
  153335. break;
  153336. case M_DNL: /* Ignore DNL ... perhaps the wrong thing */
  153337. if (! skip_variable(cinfo))
  153338. return JPEG_SUSPENDED;
  153339. break;
  153340. default: /* must be DHP, EXP, JPGn, or RESn */
  153341. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo->unread_marker);
  153342. break;
  153343. }
  153344. cinfo->unread_marker = 0;
  153345. } /* end loop */
  153346. }
  153347. METHODDEF(boolean)
  153348. read_restart_marker (j_decompress_ptr cinfo)
  153349. {
  153350. if (cinfo->unread_marker == 0) {
  153351. if (! next_marker(cinfo))
  153352. return FALSE;
  153353. }
  153354. if (cinfo->unread_marker ==
  153355. ((int) M_RST0 + cinfo->marker->next_restart_num)) {
  153356. TRACEMS1(cinfo, 3, JTRC_RST, cinfo->marker->next_restart_num);
  153357. cinfo->unread_marker = 0;
  153358. } else {
  153359. if (! (*cinfo->src->resync_to_restart) (cinfo,
  153360. cinfo->marker->next_restart_num))
  153361. return FALSE;
  153362. }
  153363. cinfo->marker->next_restart_num = (cinfo->marker->next_restart_num + 1) & 7;
  153364. return TRUE;
  153365. }
  153366. GLOBAL(boolean)
  153367. jpeg_resync_to_restart (j_decompress_ptr cinfo, int desired)
  153368. {
  153369. int marker = cinfo->unread_marker;
  153370. int action = 1;
  153371. WARNMS2(cinfo, JWRN_MUST_RESYNC, marker, desired);
  153372. for (;;) {
  153373. if (marker < (int) M_SOF0)
  153374. action = 2; /* invalid marker */
  153375. else if (marker < (int) M_RST0 || marker > (int) M_RST7)
  153376. action = 3; /* valid non-restart marker */
  153377. else {
  153378. if (marker == ((int) M_RST0 + ((desired+1) & 7)) ||
  153379. marker == ((int) M_RST0 + ((desired+2) & 7)))
  153380. action = 3; /* one of the next two expected restarts */
  153381. else if (marker == ((int) M_RST0 + ((desired-1) & 7)) ||
  153382. marker == ((int) M_RST0 + ((desired-2) & 7)))
  153383. action = 2; /* a prior restart, so advance */
  153384. else
  153385. action = 1; /* desired restart or too far away */
  153386. }
  153387. TRACEMS2(cinfo, 4, JTRC_RECOVERY_ACTION, marker, action);
  153388. switch (action) {
  153389. case 1:
  153390. cinfo->unread_marker = 0;
  153391. return TRUE;
  153392. case 2:
  153393. if (! next_marker(cinfo))
  153394. return FALSE;
  153395. marker = cinfo->unread_marker;
  153396. break;
  153397. case 3:
  153398. return TRUE;
  153399. }
  153400. } /* end loop */
  153401. }
  153402. METHODDEF(void)
  153403. reset_marker_reader (j_decompress_ptr cinfo)
  153404. {
  153405. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153406. cinfo->comp_info = NULL; /* until allocated by get_sof */
  153407. cinfo->input_scan_number = 0; /* no SOS seen yet */
  153408. cinfo->unread_marker = 0; /* no pending marker */
  153409. marker->pub.saw_SOI = FALSE; /* set internal state too */
  153410. marker->pub.saw_SOF = FALSE;
  153411. marker->pub.discarded_bytes = 0;
  153412. marker->cur_marker = NULL;
  153413. }
  153414. GLOBAL(void)
  153415. jinit_marker_reader (j_decompress_ptr cinfo)
  153416. {
  153417. my_marker_ptr2 marker;
  153418. int i;
  153419. marker = (my_marker_ptr2)
  153420. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  153421. SIZEOF(my_marker_reader));
  153422. cinfo->marker = (struct jpeg_marker_reader *) marker;
  153423. marker->pub.reset_marker_reader = reset_marker_reader;
  153424. marker->pub.read_markers = read_markers;
  153425. marker->pub.read_restart_marker = read_restart_marker;
  153426. marker->process_COM = skip_variable;
  153427. marker->length_limit_COM = 0;
  153428. for (i = 0; i < 16; i++) {
  153429. marker->process_APPn[i] = skip_variable;
  153430. marker->length_limit_APPn[i] = 0;
  153431. }
  153432. marker->process_APPn[0] = get_interesting_appn;
  153433. marker->process_APPn[14] = get_interesting_appn;
  153434. reset_marker_reader(cinfo);
  153435. }
  153436. #ifdef SAVE_MARKERS_SUPPORTED
  153437. GLOBAL(void)
  153438. jpeg_save_markers (j_decompress_ptr cinfo, int marker_code,
  153439. unsigned int length_limit)
  153440. {
  153441. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153442. long maxlength;
  153443. jpeg_marker_parser_method processor;
  153444. maxlength = cinfo->mem->max_alloc_chunk - SIZEOF(struct jpeg_marker_struct);
  153445. if (((long) length_limit) > maxlength)
  153446. length_limit = (unsigned int) maxlength;
  153447. if (length_limit) {
  153448. processor = save_marker;
  153449. if (marker_code == (int) M_APP0 && length_limit < APP0_DATA_LEN)
  153450. length_limit = APP0_DATA_LEN;
  153451. else if (marker_code == (int) M_APP14 && length_limit < APP14_DATA_LEN)
  153452. length_limit = APP14_DATA_LEN;
  153453. } else {
  153454. processor = skip_variable;
  153455. if (marker_code == (int) M_APP0 || marker_code == (int) M_APP14)
  153456. processor = get_interesting_appn;
  153457. }
  153458. if (marker_code == (int) M_COM) {
  153459. marker->process_COM = processor;
  153460. marker->length_limit_COM = length_limit;
  153461. } else if (marker_code >= (int) M_APP0 && marker_code <= (int) M_APP15) {
  153462. marker->process_APPn[marker_code - (int) M_APP0] = processor;
  153463. marker->length_limit_APPn[marker_code - (int) M_APP0] = length_limit;
  153464. } else
  153465. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, marker_code);
  153466. }
  153467. #endif /* SAVE_MARKERS_SUPPORTED */
  153468. GLOBAL(void)
  153469. jpeg_set_marker_processor (j_decompress_ptr cinfo, int marker_code,
  153470. jpeg_marker_parser_method routine)
  153471. {
  153472. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153473. if (marker_code == (int) M_COM)
  153474. marker->process_COM = routine;
  153475. else if (marker_code >= (int) M_APP0 && marker_code <= (int) M_APP15)
  153476. marker->process_APPn[marker_code - (int) M_APP0] = routine;
  153477. else
  153478. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, marker_code);
  153479. }
  153480. /*** End of inlined file: jdmarker.c ***/
  153481. /*** Start of inlined file: jdmaster.c ***/
  153482. #define JPEG_INTERNALS
  153483. typedef struct {
  153484. struct jpeg_decomp_master pub; /* public fields */
  153485. int pass_number; /* # of passes completed */
  153486. boolean using_merged_upsample; /* TRUE if using merged upsample/cconvert */
  153487. struct jpeg_color_quantizer * quantizer_1pass;
  153488. struct jpeg_color_quantizer * quantizer_2pass;
  153489. } my_decomp_master;
  153490. typedef my_decomp_master * my_master_ptr6;
  153491. LOCAL(boolean)
  153492. use_merged_upsample (j_decompress_ptr cinfo)
  153493. {
  153494. #ifdef UPSAMPLE_MERGING_SUPPORTED
  153495. if (cinfo->do_fancy_upsampling || cinfo->CCIR601_sampling)
  153496. return FALSE;
  153497. if (cinfo->jpeg_color_space != JCS_YCbCr || cinfo->num_components != 3 ||
  153498. cinfo->out_color_space != JCS_RGB ||
  153499. cinfo->out_color_components != RGB_PIXELSIZE)
  153500. return FALSE;
  153501. if (cinfo->comp_info[0].h_samp_factor != 2 ||
  153502. cinfo->comp_info[1].h_samp_factor != 1 ||
  153503. cinfo->comp_info[2].h_samp_factor != 1 ||
  153504. cinfo->comp_info[0].v_samp_factor > 2 ||
  153505. cinfo->comp_info[1].v_samp_factor != 1 ||
  153506. cinfo->comp_info[2].v_samp_factor != 1)
  153507. return FALSE;
  153508. if (cinfo->comp_info[0].DCT_scaled_size != cinfo->min_DCT_scaled_size ||
  153509. cinfo->comp_info[1].DCT_scaled_size != cinfo->min_DCT_scaled_size ||
  153510. cinfo->comp_info[2].DCT_scaled_size != cinfo->min_DCT_scaled_size)
  153511. return FALSE;
  153512. return TRUE; /* by golly, it'll work... */
  153513. #else
  153514. return FALSE;
  153515. #endif
  153516. }
  153517. GLOBAL(void)
  153518. jpeg_calc_output_dimensions (j_decompress_ptr cinfo)
  153519. {
  153520. #ifdef IDCT_SCALING_SUPPORTED
  153521. int ci;
  153522. jpeg_component_info *compptr;
  153523. #endif
  153524. if (cinfo->global_state != DSTATE_READY)
  153525. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  153526. #ifdef IDCT_SCALING_SUPPORTED
  153527. if (cinfo->scale_num * 8 <= cinfo->scale_denom) {
  153528. cinfo->output_width = (JDIMENSION)
  153529. jdiv_round_up((long) cinfo->image_width, 8L);
  153530. cinfo->output_height = (JDIMENSION)
  153531. jdiv_round_up((long) cinfo->image_height, 8L);
  153532. cinfo->min_DCT_scaled_size = 1;
  153533. } else if (cinfo->scale_num * 4 <= cinfo->scale_denom) {
  153534. cinfo->output_width = (JDIMENSION)
  153535. jdiv_round_up((long) cinfo->image_width, 4L);
  153536. cinfo->output_height = (JDIMENSION)
  153537. jdiv_round_up((long) cinfo->image_height, 4L);
  153538. cinfo->min_DCT_scaled_size = 2;
  153539. } else if (cinfo->scale_num * 2 <= cinfo->scale_denom) {
  153540. cinfo->output_width = (JDIMENSION)
  153541. jdiv_round_up((long) cinfo->image_width, 2L);
  153542. cinfo->output_height = (JDIMENSION)
  153543. jdiv_round_up((long) cinfo->image_height, 2L);
  153544. cinfo->min_DCT_scaled_size = 4;
  153545. } else {
  153546. cinfo->output_width = cinfo->image_width;
  153547. cinfo->output_height = cinfo->image_height;
  153548. cinfo->min_DCT_scaled_size = DCTSIZE;
  153549. }
  153550. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153551. ci++, compptr++) {
  153552. int ssize = cinfo->min_DCT_scaled_size;
  153553. while (ssize < DCTSIZE &&
  153554. (compptr->h_samp_factor * ssize * 2 <=
  153555. cinfo->max_h_samp_factor * cinfo->min_DCT_scaled_size) &&
  153556. (compptr->v_samp_factor * ssize * 2 <=
  153557. cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size)) {
  153558. ssize = ssize * 2;
  153559. }
  153560. compptr->DCT_scaled_size = ssize;
  153561. }
  153562. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153563. ci++, compptr++) {
  153564. compptr->downsampled_width = (JDIMENSION)
  153565. jdiv_round_up((long) cinfo->image_width *
  153566. (long) (compptr->h_samp_factor * compptr->DCT_scaled_size),
  153567. (long) (cinfo->max_h_samp_factor * DCTSIZE));
  153568. compptr->downsampled_height = (JDIMENSION)
  153569. jdiv_round_up((long) cinfo->image_height *
  153570. (long) (compptr->v_samp_factor * compptr->DCT_scaled_size),
  153571. (long) (cinfo->max_v_samp_factor * DCTSIZE));
  153572. }
  153573. #else /* !IDCT_SCALING_SUPPORTED */
  153574. cinfo->output_width = cinfo->image_width;
  153575. cinfo->output_height = cinfo->image_height;
  153576. #endif /* IDCT_SCALING_SUPPORTED */
  153577. switch (cinfo->out_color_space) {
  153578. case JCS_GRAYSCALE:
  153579. cinfo->out_color_components = 1;
  153580. break;
  153581. case JCS_RGB:
  153582. #if RGB_PIXELSIZE != 3
  153583. cinfo->out_color_components = RGB_PIXELSIZE;
  153584. break;
  153585. #endif /* else share code with YCbCr */
  153586. case JCS_YCbCr:
  153587. cinfo->out_color_components = 3;
  153588. break;
  153589. case JCS_CMYK:
  153590. case JCS_YCCK:
  153591. cinfo->out_color_components = 4;
  153592. break;
  153593. default: /* else must be same colorspace as in file */
  153594. cinfo->out_color_components = cinfo->num_components;
  153595. break;
  153596. }
  153597. cinfo->output_components = (cinfo->quantize_colors ? 1 :
  153598. cinfo->out_color_components);
  153599. if (use_merged_upsample(cinfo))
  153600. cinfo->rec_outbuf_height = cinfo->max_v_samp_factor;
  153601. else
  153602. cinfo->rec_outbuf_height = 1;
  153603. }
  153604. LOCAL(void)
  153605. prepare_range_limit_table (j_decompress_ptr cinfo)
  153606. {
  153607. JSAMPLE * table;
  153608. int i;
  153609. table = (JSAMPLE *)
  153610. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153611. (5 * (MAXJSAMPLE+1) + CENTERJSAMPLE) * SIZEOF(JSAMPLE));
  153612. table += (MAXJSAMPLE+1); /* allow negative subscripts of simple table */
  153613. cinfo->sample_range_limit = table;
  153614. MEMZERO(table - (MAXJSAMPLE+1), (MAXJSAMPLE+1) * SIZEOF(JSAMPLE));
  153615. for (i = 0; i <= MAXJSAMPLE; i++)
  153616. table[i] = (JSAMPLE) i;
  153617. table += CENTERJSAMPLE; /* Point to where post-IDCT table starts */
  153618. for (i = CENTERJSAMPLE; i < 2*(MAXJSAMPLE+1); i++)
  153619. table[i] = MAXJSAMPLE;
  153620. MEMZERO(table + (2 * (MAXJSAMPLE+1)),
  153621. (2 * (MAXJSAMPLE+1) - CENTERJSAMPLE) * SIZEOF(JSAMPLE));
  153622. MEMCOPY(table + (4 * (MAXJSAMPLE+1) - CENTERJSAMPLE),
  153623. cinfo->sample_range_limit, CENTERJSAMPLE * SIZEOF(JSAMPLE));
  153624. }
  153625. LOCAL(void)
  153626. master_selection (j_decompress_ptr cinfo)
  153627. {
  153628. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  153629. boolean use_c_buffer;
  153630. long samplesperrow;
  153631. JDIMENSION jd_samplesperrow;
  153632. jpeg_calc_output_dimensions(cinfo);
  153633. prepare_range_limit_table(cinfo);
  153634. samplesperrow = (long) cinfo->output_width * (long) cinfo->out_color_components;
  153635. jd_samplesperrow = (JDIMENSION) samplesperrow;
  153636. if ((long) jd_samplesperrow != samplesperrow)
  153637. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  153638. master->pass_number = 0;
  153639. master->using_merged_upsample = use_merged_upsample(cinfo);
  153640. master->quantizer_1pass = NULL;
  153641. master->quantizer_2pass = NULL;
  153642. if (! cinfo->quantize_colors || ! cinfo->buffered_image) {
  153643. cinfo->enable_1pass_quant = FALSE;
  153644. cinfo->enable_external_quant = FALSE;
  153645. cinfo->enable_2pass_quant = FALSE;
  153646. }
  153647. if (cinfo->quantize_colors) {
  153648. if (cinfo->raw_data_out)
  153649. ERREXIT(cinfo, JERR_NOTIMPL);
  153650. if (cinfo->out_color_components != 3) {
  153651. cinfo->enable_1pass_quant = TRUE;
  153652. cinfo->enable_external_quant = FALSE;
  153653. cinfo->enable_2pass_quant = FALSE;
  153654. cinfo->colormap = NULL;
  153655. } else if (cinfo->colormap != NULL) {
  153656. cinfo->enable_external_quant = TRUE;
  153657. } else if (cinfo->two_pass_quantize) {
  153658. cinfo->enable_2pass_quant = TRUE;
  153659. } else {
  153660. cinfo->enable_1pass_quant = TRUE;
  153661. }
  153662. if (cinfo->enable_1pass_quant) {
  153663. #ifdef QUANT_1PASS_SUPPORTED
  153664. jinit_1pass_quantizer(cinfo);
  153665. master->quantizer_1pass = cinfo->cquantize;
  153666. #else
  153667. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153668. #endif
  153669. }
  153670. if (cinfo->enable_2pass_quant || cinfo->enable_external_quant) {
  153671. #ifdef QUANT_2PASS_SUPPORTED
  153672. jinit_2pass_quantizer(cinfo);
  153673. master->quantizer_2pass = cinfo->cquantize;
  153674. #else
  153675. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153676. #endif
  153677. }
  153678. }
  153679. if (! cinfo->raw_data_out) {
  153680. if (master->using_merged_upsample) {
  153681. #ifdef UPSAMPLE_MERGING_SUPPORTED
  153682. jinit_merged_upsampler(cinfo); /* does color conversion too */
  153683. #else
  153684. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153685. #endif
  153686. } else {
  153687. jinit_color_deconverter(cinfo);
  153688. jinit_upsampler(cinfo);
  153689. }
  153690. jinit_d_post_controller(cinfo, cinfo->enable_2pass_quant);
  153691. }
  153692. jinit_inverse_dct(cinfo);
  153693. if (cinfo->arith_code) {
  153694. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  153695. } else {
  153696. if (cinfo->progressive_mode) {
  153697. #ifdef D_PROGRESSIVE_SUPPORTED
  153698. jinit_phuff_decoder(cinfo);
  153699. #else
  153700. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153701. #endif
  153702. } else
  153703. jinit_huff_decoder(cinfo);
  153704. }
  153705. use_c_buffer = cinfo->inputctl->has_multiple_scans || cinfo->buffered_image;
  153706. jinit_d_coef_controller(cinfo, use_c_buffer);
  153707. if (! cinfo->raw_data_out)
  153708. jinit_d_main_controller(cinfo, FALSE /* never need full buffer here */);
  153709. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  153710. (*cinfo->inputctl->start_input_pass) (cinfo);
  153711. #ifdef D_MULTISCAN_FILES_SUPPORTED
  153712. if (cinfo->progress != NULL && ! cinfo->buffered_image &&
  153713. cinfo->inputctl->has_multiple_scans) {
  153714. int nscans;
  153715. if (cinfo->progressive_mode) {
  153716. nscans = 2 + 3 * cinfo->num_components;
  153717. } else {
  153718. nscans = cinfo->num_components;
  153719. }
  153720. cinfo->progress->pass_counter = 0L;
  153721. cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans;
  153722. cinfo->progress->completed_passes = 0;
  153723. cinfo->progress->total_passes = (cinfo->enable_2pass_quant ? 3 : 2);
  153724. master->pass_number++;
  153725. }
  153726. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  153727. }
  153728. METHODDEF(void)
  153729. prepare_for_output_pass (j_decompress_ptr cinfo)
  153730. {
  153731. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  153732. if (master->pub.is_dummy_pass) {
  153733. #ifdef QUANT_2PASS_SUPPORTED
  153734. master->pub.is_dummy_pass = FALSE;
  153735. (*cinfo->cquantize->start_pass) (cinfo, FALSE);
  153736. (*cinfo->post->start_pass) (cinfo, JBUF_CRANK_DEST);
  153737. (*cinfo->main->start_pass) (cinfo, JBUF_CRANK_DEST);
  153738. #else
  153739. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153740. #endif /* QUANT_2PASS_SUPPORTED */
  153741. } else {
  153742. if (cinfo->quantize_colors && cinfo->colormap == NULL) {
  153743. if (cinfo->two_pass_quantize && cinfo->enable_2pass_quant) {
  153744. cinfo->cquantize = master->quantizer_2pass;
  153745. master->pub.is_dummy_pass = TRUE;
  153746. } else if (cinfo->enable_1pass_quant) {
  153747. cinfo->cquantize = master->quantizer_1pass;
  153748. } else {
  153749. ERREXIT(cinfo, JERR_MODE_CHANGE);
  153750. }
  153751. }
  153752. (*cinfo->idct->start_pass) (cinfo);
  153753. (*cinfo->coef->start_output_pass) (cinfo);
  153754. if (! cinfo->raw_data_out) {
  153755. if (! master->using_merged_upsample)
  153756. (*cinfo->cconvert->start_pass) (cinfo);
  153757. (*cinfo->upsample->start_pass) (cinfo);
  153758. if (cinfo->quantize_colors)
  153759. (*cinfo->cquantize->start_pass) (cinfo, master->pub.is_dummy_pass);
  153760. (*cinfo->post->start_pass) (cinfo,
  153761. (master->pub.is_dummy_pass ? JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
  153762. (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
  153763. }
  153764. }
  153765. if (cinfo->progress != NULL) {
  153766. cinfo->progress->completed_passes = master->pass_number;
  153767. cinfo->progress->total_passes = master->pass_number +
  153768. (master->pub.is_dummy_pass ? 2 : 1);
  153769. if (cinfo->buffered_image && ! cinfo->inputctl->eoi_reached) {
  153770. cinfo->progress->total_passes += (cinfo->enable_2pass_quant ? 2 : 1);
  153771. }
  153772. }
  153773. }
  153774. METHODDEF(void)
  153775. finish_output_pass (j_decompress_ptr cinfo)
  153776. {
  153777. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  153778. if (cinfo->quantize_colors)
  153779. (*cinfo->cquantize->finish_pass) (cinfo);
  153780. master->pass_number++;
  153781. }
  153782. #ifdef D_MULTISCAN_FILES_SUPPORTED
  153783. GLOBAL(void)
  153784. jpeg_new_colormap (j_decompress_ptr cinfo)
  153785. {
  153786. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  153787. if (cinfo->global_state != DSTATE_BUFIMAGE)
  153788. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  153789. if (cinfo->quantize_colors && cinfo->enable_external_quant &&
  153790. cinfo->colormap != NULL) {
  153791. cinfo->cquantize = master->quantizer_2pass;
  153792. (*cinfo->cquantize->new_color_map) (cinfo);
  153793. master->pub.is_dummy_pass = FALSE; /* just in case */
  153794. } else
  153795. ERREXIT(cinfo, JERR_MODE_CHANGE);
  153796. }
  153797. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  153798. GLOBAL(void)
  153799. jinit_master_decompress (j_decompress_ptr cinfo)
  153800. {
  153801. my_master_ptr6 master;
  153802. master = (my_master_ptr6)
  153803. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153804. SIZEOF(my_decomp_master));
  153805. cinfo->master = (struct jpeg_decomp_master *) master;
  153806. master->pub.prepare_for_output_pass = prepare_for_output_pass;
  153807. master->pub.finish_output_pass = finish_output_pass;
  153808. master->pub.is_dummy_pass = FALSE;
  153809. master_selection(cinfo);
  153810. }
  153811. /*** End of inlined file: jdmaster.c ***/
  153812. #undef FIX
  153813. /*** Start of inlined file: jdmerge.c ***/
  153814. #define JPEG_INTERNALS
  153815. #ifdef UPSAMPLE_MERGING_SUPPORTED
  153816. typedef struct {
  153817. struct jpeg_upsampler pub; /* public fields */
  153818. JMETHOD(void, upmethod, (j_decompress_ptr cinfo,
  153819. JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
  153820. JSAMPARRAY output_buf));
  153821. int * Cr_r_tab; /* => table for Cr to R conversion */
  153822. int * Cb_b_tab; /* => table for Cb to B conversion */
  153823. INT32 * Cr_g_tab; /* => table for Cr to G conversion */
  153824. INT32 * Cb_g_tab; /* => table for Cb to G conversion */
  153825. JSAMPROW spare_row;
  153826. boolean spare_full; /* T if spare buffer is occupied */
  153827. JDIMENSION out_row_width; /* samples per output row */
  153828. JDIMENSION rows_to_go; /* counts rows remaining in image */
  153829. } my_upsampler;
  153830. typedef my_upsampler * my_upsample_ptr;
  153831. #define SCALEBITS 16 /* speediest right-shift on some machines */
  153832. #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
  153833. #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
  153834. LOCAL(void)
  153835. build_ycc_rgb_table2 (j_decompress_ptr cinfo)
  153836. {
  153837. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153838. int i;
  153839. INT32 x;
  153840. SHIFT_TEMPS
  153841. upsample->Cr_r_tab = (int *)
  153842. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153843. (MAXJSAMPLE+1) * SIZEOF(int));
  153844. upsample->Cb_b_tab = (int *)
  153845. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153846. (MAXJSAMPLE+1) * SIZEOF(int));
  153847. upsample->Cr_g_tab = (INT32 *)
  153848. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153849. (MAXJSAMPLE+1) * SIZEOF(INT32));
  153850. upsample->Cb_g_tab = (INT32 *)
  153851. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153852. (MAXJSAMPLE+1) * SIZEOF(INT32));
  153853. for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
  153854. upsample->Cr_r_tab[i] = (int)
  153855. RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
  153856. upsample->Cb_b_tab[i] = (int)
  153857. RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
  153858. upsample->Cr_g_tab[i] = (- FIX(0.71414)) * x;
  153859. upsample->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF;
  153860. }
  153861. }
  153862. METHODDEF(void)
  153863. start_pass_merged_upsample (j_decompress_ptr cinfo)
  153864. {
  153865. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153866. upsample->spare_full = FALSE;
  153867. upsample->rows_to_go = cinfo->output_height;
  153868. }
  153869. METHODDEF(void)
  153870. merged_2v_upsample (j_decompress_ptr cinfo,
  153871. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  153872. JDIMENSION in_row_groups_avail,
  153873. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  153874. JDIMENSION out_rows_avail)
  153875. {
  153876. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153877. JSAMPROW work_ptrs[2];
  153878. JDIMENSION num_rows; /* number of rows returned to caller */
  153879. if (upsample->spare_full) {
  153880. jcopy_sample_rows(& upsample->spare_row, 0, output_buf + *out_row_ctr, 0,
  153881. 1, upsample->out_row_width);
  153882. num_rows = 1;
  153883. upsample->spare_full = FALSE;
  153884. } else {
  153885. num_rows = 2;
  153886. if (num_rows > upsample->rows_to_go)
  153887. num_rows = upsample->rows_to_go;
  153888. out_rows_avail -= *out_row_ctr;
  153889. if (num_rows > out_rows_avail)
  153890. num_rows = out_rows_avail;
  153891. work_ptrs[0] = output_buf[*out_row_ctr];
  153892. if (num_rows > 1) {
  153893. work_ptrs[1] = output_buf[*out_row_ctr + 1];
  153894. } else {
  153895. work_ptrs[1] = upsample->spare_row;
  153896. upsample->spare_full = TRUE;
  153897. }
  153898. (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr, work_ptrs);
  153899. }
  153900. *out_row_ctr += num_rows;
  153901. upsample->rows_to_go -= num_rows;
  153902. if (! upsample->spare_full)
  153903. (*in_row_group_ctr)++;
  153904. }
  153905. METHODDEF(void)
  153906. merged_1v_upsample (j_decompress_ptr cinfo,
  153907. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  153908. JDIMENSION in_row_groups_avail,
  153909. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  153910. JDIMENSION out_rows_avail)
  153911. {
  153912. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153913. (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr,
  153914. output_buf + *out_row_ctr);
  153915. (*out_row_ctr)++;
  153916. (*in_row_group_ctr)++;
  153917. }
  153918. METHODDEF(void)
  153919. h2v1_merged_upsample (j_decompress_ptr cinfo,
  153920. JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
  153921. JSAMPARRAY output_buf)
  153922. {
  153923. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153924. register int y, cred, cgreen, cblue;
  153925. int cb, cr;
  153926. register JSAMPROW outptr;
  153927. JSAMPROW inptr0, inptr1, inptr2;
  153928. JDIMENSION col;
  153929. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  153930. int * Crrtab = upsample->Cr_r_tab;
  153931. int * Cbbtab = upsample->Cb_b_tab;
  153932. INT32 * Crgtab = upsample->Cr_g_tab;
  153933. INT32 * Cbgtab = upsample->Cb_g_tab;
  153934. SHIFT_TEMPS
  153935. inptr0 = input_buf[0][in_row_group_ctr];
  153936. inptr1 = input_buf[1][in_row_group_ctr];
  153937. inptr2 = input_buf[2][in_row_group_ctr];
  153938. outptr = output_buf[0];
  153939. for (col = cinfo->output_width >> 1; col > 0; col--) {
  153940. cb = GETJSAMPLE(*inptr1++);
  153941. cr = GETJSAMPLE(*inptr2++);
  153942. cred = Crrtab[cr];
  153943. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  153944. cblue = Cbbtab[cb];
  153945. y = GETJSAMPLE(*inptr0++);
  153946. outptr[RGB_RED] = range_limit[y + cred];
  153947. outptr[RGB_GREEN] = range_limit[y + cgreen];
  153948. outptr[RGB_BLUE] = range_limit[y + cblue];
  153949. outptr += RGB_PIXELSIZE;
  153950. y = GETJSAMPLE(*inptr0++);
  153951. outptr[RGB_RED] = range_limit[y + cred];
  153952. outptr[RGB_GREEN] = range_limit[y + cgreen];
  153953. outptr[RGB_BLUE] = range_limit[y + cblue];
  153954. outptr += RGB_PIXELSIZE;
  153955. }
  153956. if (cinfo->output_width & 1) {
  153957. cb = GETJSAMPLE(*inptr1);
  153958. cr = GETJSAMPLE(*inptr2);
  153959. cred = Crrtab[cr];
  153960. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  153961. cblue = Cbbtab[cb];
  153962. y = GETJSAMPLE(*inptr0);
  153963. outptr[RGB_RED] = range_limit[y + cred];
  153964. outptr[RGB_GREEN] = range_limit[y + cgreen];
  153965. outptr[RGB_BLUE] = range_limit[y + cblue];
  153966. }
  153967. }
  153968. METHODDEF(void)
  153969. h2v2_merged_upsample (j_decompress_ptr cinfo,
  153970. JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
  153971. JSAMPARRAY output_buf)
  153972. {
  153973. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153974. register int y, cred, cgreen, cblue;
  153975. int cb, cr;
  153976. register JSAMPROW outptr0, outptr1;
  153977. JSAMPROW inptr00, inptr01, inptr1, inptr2;
  153978. JDIMENSION col;
  153979. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  153980. int * Crrtab = upsample->Cr_r_tab;
  153981. int * Cbbtab = upsample->Cb_b_tab;
  153982. INT32 * Crgtab = upsample->Cr_g_tab;
  153983. INT32 * Cbgtab = upsample->Cb_g_tab;
  153984. SHIFT_TEMPS
  153985. inptr00 = input_buf[0][in_row_group_ctr*2];
  153986. inptr01 = input_buf[0][in_row_group_ctr*2 + 1];
  153987. inptr1 = input_buf[1][in_row_group_ctr];
  153988. inptr2 = input_buf[2][in_row_group_ctr];
  153989. outptr0 = output_buf[0];
  153990. outptr1 = output_buf[1];
  153991. for (col = cinfo->output_width >> 1; col > 0; col--) {
  153992. cb = GETJSAMPLE(*inptr1++);
  153993. cr = GETJSAMPLE(*inptr2++);
  153994. cred = Crrtab[cr];
  153995. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  153996. cblue = Cbbtab[cb];
  153997. y = GETJSAMPLE(*inptr00++);
  153998. outptr0[RGB_RED] = range_limit[y + cred];
  153999. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  154000. outptr0[RGB_BLUE] = range_limit[y + cblue];
  154001. outptr0 += RGB_PIXELSIZE;
  154002. y = GETJSAMPLE(*inptr00++);
  154003. outptr0[RGB_RED] = range_limit[y + cred];
  154004. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  154005. outptr0[RGB_BLUE] = range_limit[y + cblue];
  154006. outptr0 += RGB_PIXELSIZE;
  154007. y = GETJSAMPLE(*inptr01++);
  154008. outptr1[RGB_RED] = range_limit[y + cred];
  154009. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  154010. outptr1[RGB_BLUE] = range_limit[y + cblue];
  154011. outptr1 += RGB_PIXELSIZE;
  154012. y = GETJSAMPLE(*inptr01++);
  154013. outptr1[RGB_RED] = range_limit[y + cred];
  154014. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  154015. outptr1[RGB_BLUE] = range_limit[y + cblue];
  154016. outptr1 += RGB_PIXELSIZE;
  154017. }
  154018. if (cinfo->output_width & 1) {
  154019. cb = GETJSAMPLE(*inptr1);
  154020. cr = GETJSAMPLE(*inptr2);
  154021. cred = Crrtab[cr];
  154022. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  154023. cblue = Cbbtab[cb];
  154024. y = GETJSAMPLE(*inptr00);
  154025. outptr0[RGB_RED] = range_limit[y + cred];
  154026. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  154027. outptr0[RGB_BLUE] = range_limit[y + cblue];
  154028. y = GETJSAMPLE(*inptr01);
  154029. outptr1[RGB_RED] = range_limit[y + cred];
  154030. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  154031. outptr1[RGB_BLUE] = range_limit[y + cblue];
  154032. }
  154033. }
  154034. GLOBAL(void)
  154035. jinit_merged_upsampler (j_decompress_ptr cinfo)
  154036. {
  154037. my_upsample_ptr upsample;
  154038. upsample = (my_upsample_ptr)
  154039. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154040. SIZEOF(my_upsampler));
  154041. cinfo->upsample = (struct jpeg_upsampler *) upsample;
  154042. upsample->pub.start_pass = start_pass_merged_upsample;
  154043. upsample->pub.need_context_rows = FALSE;
  154044. upsample->out_row_width = cinfo->output_width * cinfo->out_color_components;
  154045. if (cinfo->max_v_samp_factor == 2) {
  154046. upsample->pub.upsample = merged_2v_upsample;
  154047. upsample->upmethod = h2v2_merged_upsample;
  154048. upsample->spare_row = (JSAMPROW)
  154049. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154050. (size_t) (upsample->out_row_width * SIZEOF(JSAMPLE)));
  154051. } else {
  154052. upsample->pub.upsample = merged_1v_upsample;
  154053. upsample->upmethod = h2v1_merged_upsample;
  154054. upsample->spare_row = NULL;
  154055. }
  154056. build_ycc_rgb_table2(cinfo);
  154057. }
  154058. #endif /* UPSAMPLE_MERGING_SUPPORTED */
  154059. /*** End of inlined file: jdmerge.c ***/
  154060. #undef ASSIGN_STATE
  154061. /*** Start of inlined file: jdphuff.c ***/
  154062. #define JPEG_INTERNALS
  154063. #ifdef D_PROGRESSIVE_SUPPORTED
  154064. typedef struct {
  154065. unsigned int EOBRUN; /* remaining EOBs in EOBRUN */
  154066. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  154067. } savable_state3;
  154068. #ifndef NO_STRUCT_ASSIGN
  154069. #define ASSIGN_STATE(dest,src) ((dest) = (src))
  154070. #else
  154071. #if MAX_COMPS_IN_SCAN == 4
  154072. #define ASSIGN_STATE(dest,src) \
  154073. ((dest).EOBRUN = (src).EOBRUN, \
  154074. (dest).last_dc_val[0] = (src).last_dc_val[0], \
  154075. (dest).last_dc_val[1] = (src).last_dc_val[1], \
  154076. (dest).last_dc_val[2] = (src).last_dc_val[2], \
  154077. (dest).last_dc_val[3] = (src).last_dc_val[3])
  154078. #endif
  154079. #endif
  154080. typedef struct {
  154081. struct jpeg_entropy_decoder pub; /* public fields */
  154082. bitread_perm_state bitstate; /* Bit buffer at start of MCU */
  154083. savable_state3 saved; /* Other state at start of MCU */
  154084. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  154085. d_derived_tbl * derived_tbls[NUM_HUFF_TBLS];
  154086. d_derived_tbl * ac_derived_tbl; /* active table during an AC scan */
  154087. } phuff_entropy_decoder;
  154088. typedef phuff_entropy_decoder * phuff_entropy_ptr2;
  154089. METHODDEF(boolean) decode_mcu_DC_first JPP((j_decompress_ptr cinfo,
  154090. JBLOCKROW *MCU_data));
  154091. METHODDEF(boolean) decode_mcu_AC_first JPP((j_decompress_ptr cinfo,
  154092. JBLOCKROW *MCU_data));
  154093. METHODDEF(boolean) decode_mcu_DC_refine JPP((j_decompress_ptr cinfo,
  154094. JBLOCKROW *MCU_data));
  154095. METHODDEF(boolean) decode_mcu_AC_refine JPP((j_decompress_ptr cinfo,
  154096. JBLOCKROW *MCU_data));
  154097. METHODDEF(void)
  154098. start_pass_phuff_decoder (j_decompress_ptr cinfo)
  154099. {
  154100. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154101. boolean is_DC_band, bad;
  154102. int ci, coefi, tbl;
  154103. int *coef_bit_ptr;
  154104. jpeg_component_info * compptr;
  154105. is_DC_band = (cinfo->Ss == 0);
  154106. bad = FALSE;
  154107. if (is_DC_band) {
  154108. if (cinfo->Se != 0)
  154109. bad = TRUE;
  154110. } else {
  154111. if (cinfo->Ss > cinfo->Se || cinfo->Se >= DCTSIZE2)
  154112. bad = TRUE;
  154113. if (cinfo->comps_in_scan != 1)
  154114. bad = TRUE;
  154115. }
  154116. if (cinfo->Ah != 0) {
  154117. if (cinfo->Al != cinfo->Ah-1)
  154118. bad = TRUE;
  154119. }
  154120. if (cinfo->Al > 13) /* need not check for < 0 */
  154121. bad = TRUE;
  154122. if (bad)
  154123. ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
  154124. cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
  154125. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  154126. int cindex = cinfo->cur_comp_info[ci]->component_index;
  154127. coef_bit_ptr = & cinfo->coef_bits[cindex][0];
  154128. if (!is_DC_band && coef_bit_ptr[0] < 0) /* AC without prior DC scan */
  154129. WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, 0);
  154130. for (coefi = cinfo->Ss; coefi <= cinfo->Se; coefi++) {
  154131. int expected = (coef_bit_ptr[coefi] < 0) ? 0 : coef_bit_ptr[coefi];
  154132. if (cinfo->Ah != expected)
  154133. WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, coefi);
  154134. coef_bit_ptr[coefi] = cinfo->Al;
  154135. }
  154136. }
  154137. if (cinfo->Ah == 0) {
  154138. if (is_DC_band)
  154139. entropy->pub.decode_mcu = decode_mcu_DC_first;
  154140. else
  154141. entropy->pub.decode_mcu = decode_mcu_AC_first;
  154142. } else {
  154143. if (is_DC_band)
  154144. entropy->pub.decode_mcu = decode_mcu_DC_refine;
  154145. else
  154146. entropy->pub.decode_mcu = decode_mcu_AC_refine;
  154147. }
  154148. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  154149. compptr = cinfo->cur_comp_info[ci];
  154150. if (is_DC_band) {
  154151. if (cinfo->Ah == 0) { /* DC refinement needs no table */
  154152. tbl = compptr->dc_tbl_no;
  154153. jpeg_make_d_derived_tbl(cinfo, TRUE, tbl,
  154154. & entropy->derived_tbls[tbl]);
  154155. }
  154156. } else {
  154157. tbl = compptr->ac_tbl_no;
  154158. jpeg_make_d_derived_tbl(cinfo, FALSE, tbl,
  154159. & entropy->derived_tbls[tbl]);
  154160. entropy->ac_derived_tbl = entropy->derived_tbls[tbl];
  154161. }
  154162. entropy->saved.last_dc_val[ci] = 0;
  154163. }
  154164. entropy->bitstate.bits_left = 0;
  154165. entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */
  154166. entropy->pub.insufficient_data = FALSE;
  154167. entropy->saved.EOBRUN = 0;
  154168. entropy->restarts_to_go = cinfo->restart_interval;
  154169. }
  154170. LOCAL(boolean)
  154171. process_restartp (j_decompress_ptr cinfo)
  154172. {
  154173. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154174. int ci;
  154175. cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8;
  154176. entropy->bitstate.bits_left = 0;
  154177. if (! (*cinfo->marker->read_restart_marker) (cinfo))
  154178. return FALSE;
  154179. for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  154180. entropy->saved.last_dc_val[ci] = 0;
  154181. entropy->saved.EOBRUN = 0;
  154182. entropy->restarts_to_go = cinfo->restart_interval;
  154183. if (cinfo->unread_marker == 0)
  154184. entropy->pub.insufficient_data = FALSE;
  154185. return TRUE;
  154186. }
  154187. METHODDEF(boolean)
  154188. decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154189. {
  154190. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154191. int Al = cinfo->Al;
  154192. register int s, r;
  154193. int blkn, ci;
  154194. JBLOCKROW block;
  154195. BITREAD_STATE_VARS;
  154196. savable_state3 state;
  154197. d_derived_tbl * tbl;
  154198. jpeg_component_info * compptr;
  154199. if (cinfo->restart_interval) {
  154200. if (entropy->restarts_to_go == 0)
  154201. if (! process_restartp(cinfo))
  154202. return FALSE;
  154203. }
  154204. if (! entropy->pub.insufficient_data) {
  154205. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154206. ASSIGN_STATE(state, entropy->saved);
  154207. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  154208. block = MCU_data[blkn];
  154209. ci = cinfo->MCU_membership[blkn];
  154210. compptr = cinfo->cur_comp_info[ci];
  154211. tbl = entropy->derived_tbls[compptr->dc_tbl_no];
  154212. HUFF_DECODE(s, br_state, tbl, return FALSE, label1);
  154213. if (s) {
  154214. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  154215. r = GET_BITS(s);
  154216. s = HUFF_EXTEND(r, s);
  154217. }
  154218. s += state.last_dc_val[ci];
  154219. state.last_dc_val[ci] = s;
  154220. (*block)[0] = (JCOEF) (s << Al);
  154221. }
  154222. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154223. ASSIGN_STATE(entropy->saved, state);
  154224. }
  154225. entropy->restarts_to_go--;
  154226. return TRUE;
  154227. }
  154228. METHODDEF(boolean)
  154229. decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154230. {
  154231. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154232. int Se = cinfo->Se;
  154233. int Al = cinfo->Al;
  154234. register int s, k, r;
  154235. unsigned int EOBRUN;
  154236. JBLOCKROW block;
  154237. BITREAD_STATE_VARS;
  154238. d_derived_tbl * tbl;
  154239. if (cinfo->restart_interval) {
  154240. if (entropy->restarts_to_go == 0)
  154241. if (! process_restartp(cinfo))
  154242. return FALSE;
  154243. }
  154244. if (! entropy->pub.insufficient_data) {
  154245. EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we need */
  154246. if (EOBRUN > 0) /* if it's a band of zeroes... */
  154247. EOBRUN--; /* ...process it now (we do nothing) */
  154248. else {
  154249. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154250. block = MCU_data[0];
  154251. tbl = entropy->ac_derived_tbl;
  154252. for (k = cinfo->Ss; k <= Se; k++) {
  154253. HUFF_DECODE(s, br_state, tbl, return FALSE, label2);
  154254. r = s >> 4;
  154255. s &= 15;
  154256. if (s) {
  154257. k += r;
  154258. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  154259. r = GET_BITS(s);
  154260. s = HUFF_EXTEND(r, s);
  154261. (*block)[jpeg_natural_order[k]] = (JCOEF) (s << Al);
  154262. } else {
  154263. if (r == 15) { /* ZRL */
  154264. k += 15; /* skip 15 zeroes in band */
  154265. } else { /* EOBr, run length is 2^r + appended bits */
  154266. EOBRUN = 1 << r;
  154267. if (r) { /* EOBr, r > 0 */
  154268. CHECK_BIT_BUFFER(br_state, r, return FALSE);
  154269. r = GET_BITS(r);
  154270. EOBRUN += r;
  154271. }
  154272. EOBRUN--; /* this band is processed at this moment */
  154273. break; /* force end-of-band */
  154274. }
  154275. }
  154276. }
  154277. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154278. }
  154279. entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we need */
  154280. }
  154281. entropy->restarts_to_go--;
  154282. return TRUE;
  154283. }
  154284. METHODDEF(boolean)
  154285. decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154286. {
  154287. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154288. int p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
  154289. int blkn;
  154290. JBLOCKROW block;
  154291. BITREAD_STATE_VARS;
  154292. if (cinfo->restart_interval) {
  154293. if (entropy->restarts_to_go == 0)
  154294. if (! process_restartp(cinfo))
  154295. return FALSE;
  154296. }
  154297. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154298. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  154299. block = MCU_data[blkn];
  154300. CHECK_BIT_BUFFER(br_state, 1, return FALSE);
  154301. if (GET_BITS(1))
  154302. (*block)[0] |= p1;
  154303. }
  154304. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154305. entropy->restarts_to_go--;
  154306. return TRUE;
  154307. }
  154308. METHODDEF(boolean)
  154309. decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154310. {
  154311. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154312. int Se = cinfo->Se;
  154313. int p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
  154314. int m1 = (-1) << cinfo->Al; /* -1 in the bit position being coded */
  154315. register int s, k, r;
  154316. unsigned int EOBRUN;
  154317. JBLOCKROW block;
  154318. JCOEFPTR thiscoef;
  154319. BITREAD_STATE_VARS;
  154320. d_derived_tbl * tbl;
  154321. int num_newnz;
  154322. int newnz_pos[DCTSIZE2];
  154323. if (cinfo->restart_interval) {
  154324. if (entropy->restarts_to_go == 0)
  154325. if (! process_restartp(cinfo))
  154326. return FALSE;
  154327. }
  154328. if (! entropy->pub.insufficient_data) {
  154329. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154330. EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we need */
  154331. block = MCU_data[0];
  154332. tbl = entropy->ac_derived_tbl;
  154333. num_newnz = 0;
  154334. k = cinfo->Ss;
  154335. if (EOBRUN == 0) {
  154336. for (; k <= Se; k++) {
  154337. HUFF_DECODE(s, br_state, tbl, goto undoit, label3);
  154338. r = s >> 4;
  154339. s &= 15;
  154340. if (s) {
  154341. if (s != 1) /* size of new coef should always be 1 */
  154342. WARNMS(cinfo, JWRN_HUFF_BAD_CODE);
  154343. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  154344. if (GET_BITS(1))
  154345. s = p1; /* newly nonzero coef is positive */
  154346. else
  154347. s = m1; /* newly nonzero coef is negative */
  154348. } else {
  154349. if (r != 15) {
  154350. EOBRUN = 1 << r; /* EOBr, run length is 2^r + appended bits */
  154351. if (r) {
  154352. CHECK_BIT_BUFFER(br_state, r, goto undoit);
  154353. r = GET_BITS(r);
  154354. EOBRUN += r;
  154355. }
  154356. break; /* rest of block is handled by EOB logic */
  154357. }
  154358. }
  154359. do {
  154360. thiscoef = *block + jpeg_natural_order[k];
  154361. if (*thiscoef != 0) {
  154362. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  154363. if (GET_BITS(1)) {
  154364. if ((*thiscoef & p1) == 0) { /* do nothing if already set it */
  154365. if (*thiscoef >= 0)
  154366. *thiscoef += p1;
  154367. else
  154368. *thiscoef += m1;
  154369. }
  154370. }
  154371. } else {
  154372. if (--r < 0)
  154373. break; /* reached target zero coefficient */
  154374. }
  154375. k++;
  154376. } while (k <= Se);
  154377. if (s) {
  154378. int pos = jpeg_natural_order[k];
  154379. (*block)[pos] = (JCOEF) s;
  154380. newnz_pos[num_newnz++] = pos;
  154381. }
  154382. }
  154383. }
  154384. if (EOBRUN > 0) {
  154385. for (; k <= Se; k++) {
  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 changed it */
  154391. if (*thiscoef >= 0)
  154392. *thiscoef += p1;
  154393. else
  154394. *thiscoef += m1;
  154395. }
  154396. }
  154397. }
  154398. }
  154399. EOBRUN--;
  154400. }
  154401. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154402. entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we need */
  154403. }
  154404. entropy->restarts_to_go--;
  154405. return TRUE;
  154406. undoit:
  154407. while (num_newnz > 0)
  154408. (*block)[newnz_pos[--num_newnz]] = 0;
  154409. return FALSE;
  154410. }
  154411. GLOBAL(void)
  154412. jinit_phuff_decoder (j_decompress_ptr cinfo)
  154413. {
  154414. phuff_entropy_ptr2 entropy;
  154415. int *coef_bit_ptr;
  154416. int ci, i;
  154417. entropy = (phuff_entropy_ptr2)
  154418. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154419. SIZEOF(phuff_entropy_decoder));
  154420. cinfo->entropy = (struct jpeg_entropy_decoder *) entropy;
  154421. entropy->pub.start_pass = start_pass_phuff_decoder;
  154422. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  154423. entropy->derived_tbls[i] = NULL;
  154424. }
  154425. cinfo->coef_bits = (int (*)[DCTSIZE2])
  154426. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154427. cinfo->num_components*DCTSIZE2*SIZEOF(int));
  154428. coef_bit_ptr = & cinfo->coef_bits[0][0];
  154429. for (ci = 0; ci < cinfo->num_components; ci++)
  154430. for (i = 0; i < DCTSIZE2; i++)
  154431. *coef_bit_ptr++ = -1;
  154432. }
  154433. #endif /* D_PROGRESSIVE_SUPPORTED */
  154434. /*** End of inlined file: jdphuff.c ***/
  154435. /*** Start of inlined file: jdpostct.c ***/
  154436. #define JPEG_INTERNALS
  154437. typedef struct {
  154438. struct jpeg_d_post_controller pub; /* public fields */
  154439. jvirt_sarray_ptr whole_image; /* virtual array, or NULL if one-pass */
  154440. JSAMPARRAY buffer; /* strip buffer, or current strip of virtual */
  154441. JDIMENSION strip_height; /* buffer size in rows */
  154442. JDIMENSION starting_row; /* row # of first row in current strip */
  154443. JDIMENSION next_row; /* index of next row to fill/empty in strip */
  154444. } my_post_controller;
  154445. typedef my_post_controller * my_post_ptr;
  154446. METHODDEF(void) post_process_1pass
  154447. JPP((j_decompress_ptr cinfo,
  154448. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154449. JDIMENSION in_row_groups_avail,
  154450. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154451. JDIMENSION out_rows_avail));
  154452. #ifdef QUANT_2PASS_SUPPORTED
  154453. METHODDEF(void) post_process_prepass
  154454. JPP((j_decompress_ptr cinfo,
  154455. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154456. JDIMENSION in_row_groups_avail,
  154457. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154458. JDIMENSION out_rows_avail));
  154459. METHODDEF(void) post_process_2pass
  154460. JPP((j_decompress_ptr cinfo,
  154461. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154462. JDIMENSION in_row_groups_avail,
  154463. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154464. JDIMENSION out_rows_avail));
  154465. #endif
  154466. METHODDEF(void)
  154467. start_pass_dpost (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
  154468. {
  154469. my_post_ptr post = (my_post_ptr) cinfo->post;
  154470. switch (pass_mode) {
  154471. case JBUF_PASS_THRU:
  154472. if (cinfo->quantize_colors) {
  154473. post->pub.post_process_data = post_process_1pass;
  154474. if (post->buffer == NULL) {
  154475. post->buffer = (*cinfo->mem->access_virt_sarray)
  154476. ((j_common_ptr) cinfo, post->whole_image,
  154477. (JDIMENSION) 0, post->strip_height, TRUE);
  154478. }
  154479. } else {
  154480. post->pub.post_process_data = cinfo->upsample->upsample;
  154481. }
  154482. break;
  154483. #ifdef QUANT_2PASS_SUPPORTED
  154484. case JBUF_SAVE_AND_PASS:
  154485. if (post->whole_image == NULL)
  154486. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154487. post->pub.post_process_data = post_process_prepass;
  154488. break;
  154489. case JBUF_CRANK_DEST:
  154490. if (post->whole_image == NULL)
  154491. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154492. post->pub.post_process_data = post_process_2pass;
  154493. break;
  154494. #endif /* QUANT_2PASS_SUPPORTED */
  154495. default:
  154496. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154497. break;
  154498. }
  154499. post->starting_row = post->next_row = 0;
  154500. }
  154501. METHODDEF(void)
  154502. post_process_1pass (j_decompress_ptr cinfo,
  154503. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154504. JDIMENSION in_row_groups_avail,
  154505. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154506. JDIMENSION out_rows_avail)
  154507. {
  154508. my_post_ptr post = (my_post_ptr) cinfo->post;
  154509. JDIMENSION num_rows, max_rows;
  154510. max_rows = out_rows_avail - *out_row_ctr;
  154511. if (max_rows > post->strip_height)
  154512. max_rows = post->strip_height;
  154513. num_rows = 0;
  154514. (*cinfo->upsample->upsample) (cinfo,
  154515. input_buf, in_row_group_ctr, in_row_groups_avail,
  154516. post->buffer, &num_rows, max_rows);
  154517. (*cinfo->cquantize->color_quantize) (cinfo,
  154518. post->buffer, output_buf + *out_row_ctr, (int) num_rows);
  154519. *out_row_ctr += num_rows;
  154520. }
  154521. #ifdef QUANT_2PASS_SUPPORTED
  154522. METHODDEF(void)
  154523. post_process_prepass (j_decompress_ptr cinfo,
  154524. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154525. JDIMENSION in_row_groups_avail,
  154526. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154527. JDIMENSION out_rows_avail)
  154528. {
  154529. my_post_ptr post = (my_post_ptr) cinfo->post;
  154530. JDIMENSION old_next_row, num_rows;
  154531. if (post->next_row == 0) {
  154532. post->buffer = (*cinfo->mem->access_virt_sarray)
  154533. ((j_common_ptr) cinfo, post->whole_image,
  154534. post->starting_row, post->strip_height, TRUE);
  154535. }
  154536. old_next_row = post->next_row;
  154537. (*cinfo->upsample->upsample) (cinfo,
  154538. input_buf, in_row_group_ctr, in_row_groups_avail,
  154539. post->buffer, &post->next_row, post->strip_height);
  154540. if (post->next_row > old_next_row) {
  154541. num_rows = post->next_row - old_next_row;
  154542. (*cinfo->cquantize->color_quantize) (cinfo, post->buffer + old_next_row,
  154543. (JSAMPARRAY) NULL, (int) num_rows);
  154544. *out_row_ctr += num_rows;
  154545. }
  154546. if (post->next_row >= post->strip_height) {
  154547. post->starting_row += post->strip_height;
  154548. post->next_row = 0;
  154549. }
  154550. }
  154551. METHODDEF(void)
  154552. post_process_2pass (j_decompress_ptr cinfo,
  154553. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154554. JDIMENSION in_row_groups_avail,
  154555. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154556. JDIMENSION out_rows_avail)
  154557. {
  154558. my_post_ptr post = (my_post_ptr) cinfo->post;
  154559. JDIMENSION num_rows, max_rows;
  154560. if (post->next_row == 0) {
  154561. post->buffer = (*cinfo->mem->access_virt_sarray)
  154562. ((j_common_ptr) cinfo, post->whole_image,
  154563. post->starting_row, post->strip_height, FALSE);
  154564. }
  154565. num_rows = post->strip_height - post->next_row; /* available in strip */
  154566. max_rows = out_rows_avail - *out_row_ctr; /* available in output area */
  154567. if (num_rows > max_rows)
  154568. num_rows = max_rows;
  154569. max_rows = cinfo->output_height - post->starting_row;
  154570. if (num_rows > max_rows)
  154571. num_rows = max_rows;
  154572. (*cinfo->cquantize->color_quantize) (cinfo,
  154573. post->buffer + post->next_row, output_buf + *out_row_ctr,
  154574. (int) num_rows);
  154575. *out_row_ctr += num_rows;
  154576. post->next_row += num_rows;
  154577. if (post->next_row >= post->strip_height) {
  154578. post->starting_row += post->strip_height;
  154579. post->next_row = 0;
  154580. }
  154581. }
  154582. #endif /* QUANT_2PASS_SUPPORTED */
  154583. GLOBAL(void)
  154584. jinit_d_post_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
  154585. {
  154586. my_post_ptr post;
  154587. post = (my_post_ptr)
  154588. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154589. SIZEOF(my_post_controller));
  154590. cinfo->post = (struct jpeg_d_post_controller *) post;
  154591. post->pub.start_pass = start_pass_dpost;
  154592. post->whole_image = NULL; /* flag for no virtual arrays */
  154593. post->buffer = NULL; /* flag for no strip buffer */
  154594. if (cinfo->quantize_colors) {
  154595. post->strip_height = (JDIMENSION) cinfo->max_v_samp_factor;
  154596. if (need_full_buffer) {
  154597. #ifdef QUANT_2PASS_SUPPORTED
  154598. post->whole_image = (*cinfo->mem->request_virt_sarray)
  154599. ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  154600. cinfo->output_width * cinfo->out_color_components,
  154601. (JDIMENSION) jround_up((long) cinfo->output_height,
  154602. (long) post->strip_height),
  154603. post->strip_height);
  154604. #else
  154605. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154606. #endif /* QUANT_2PASS_SUPPORTED */
  154607. } else {
  154608. post->buffer = (*cinfo->mem->alloc_sarray)
  154609. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154610. cinfo->output_width * cinfo->out_color_components,
  154611. post->strip_height);
  154612. }
  154613. }
  154614. }
  154615. /*** End of inlined file: jdpostct.c ***/
  154616. #undef FIX
  154617. /*** Start of inlined file: jdsample.c ***/
  154618. #define JPEG_INTERNALS
  154619. typedef JMETHOD(void, upsample1_ptr,
  154620. (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154621. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr));
  154622. typedef struct {
  154623. struct jpeg_upsampler pub; /* public fields */
  154624. JSAMPARRAY color_buf[MAX_COMPONENTS];
  154625. upsample1_ptr methods[MAX_COMPONENTS];
  154626. int next_row_out; /* counts rows emitted from color_buf */
  154627. JDIMENSION rows_to_go; /* counts rows remaining in image */
  154628. int rowgroup_height[MAX_COMPONENTS];
  154629. UINT8 h_expand[MAX_COMPONENTS];
  154630. UINT8 v_expand[MAX_COMPONENTS];
  154631. } my_upsampler2;
  154632. typedef my_upsampler2 * my_upsample_ptr2;
  154633. METHODDEF(void)
  154634. start_pass_upsample (j_decompress_ptr cinfo)
  154635. {
  154636. my_upsample_ptr2 upsample = (my_upsample_ptr2) cinfo->upsample;
  154637. upsample->next_row_out = cinfo->max_v_samp_factor;
  154638. upsample->rows_to_go = cinfo->output_height;
  154639. }
  154640. METHODDEF(void)
  154641. sep_upsample (j_decompress_ptr cinfo,
  154642. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154643. JDIMENSION in_row_groups_avail,
  154644. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154645. JDIMENSION out_rows_avail)
  154646. {
  154647. my_upsample_ptr2 upsample = (my_upsample_ptr2) cinfo->upsample;
  154648. int ci;
  154649. jpeg_component_info * compptr;
  154650. JDIMENSION num_rows;
  154651. if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
  154652. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  154653. ci++, compptr++) {
  154654. (*upsample->methods[ci]) (cinfo, compptr,
  154655. input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
  154656. upsample->color_buf + ci);
  154657. }
  154658. upsample->next_row_out = 0;
  154659. }
  154660. num_rows = (JDIMENSION) (cinfo->max_v_samp_factor - upsample->next_row_out);
  154661. if (num_rows > upsample->rows_to_go)
  154662. num_rows = upsample->rows_to_go;
  154663. out_rows_avail -= *out_row_ctr;
  154664. if (num_rows > out_rows_avail)
  154665. num_rows = out_rows_avail;
  154666. (*cinfo->cconvert->color_convert) (cinfo, upsample->color_buf,
  154667. (JDIMENSION) upsample->next_row_out,
  154668. output_buf + *out_row_ctr,
  154669. (int) num_rows);
  154670. *out_row_ctr += num_rows;
  154671. upsample->rows_to_go -= num_rows;
  154672. upsample->next_row_out += num_rows;
  154673. if (upsample->next_row_out >= cinfo->max_v_samp_factor)
  154674. (*in_row_group_ctr)++;
  154675. }
  154676. METHODDEF(void)
  154677. fullsize_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154678. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154679. {
  154680. *output_data_ptr = input_data;
  154681. }
  154682. METHODDEF(void)
  154683. noop_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154684. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154685. {
  154686. *output_data_ptr = NULL; /* safety check */
  154687. }
  154688. METHODDEF(void)
  154689. int_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154690. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154691. {
  154692. my_upsample_ptr2 upsample = (my_upsample_ptr2) cinfo->upsample;
  154693. JSAMPARRAY output_data = *output_data_ptr;
  154694. register JSAMPROW inptr, outptr;
  154695. register JSAMPLE invalue;
  154696. register int h;
  154697. JSAMPROW outend;
  154698. int h_expand, v_expand;
  154699. int inrow, outrow;
  154700. h_expand = upsample->h_expand[compptr->component_index];
  154701. v_expand = upsample->v_expand[compptr->component_index];
  154702. inrow = outrow = 0;
  154703. while (outrow < cinfo->max_v_samp_factor) {
  154704. inptr = input_data[inrow];
  154705. outptr = output_data[outrow];
  154706. outend = outptr + cinfo->output_width;
  154707. while (outptr < outend) {
  154708. invalue = *inptr++; /* don't need GETJSAMPLE() here */
  154709. for (h = h_expand; h > 0; h--) {
  154710. *outptr++ = invalue;
  154711. }
  154712. }
  154713. if (v_expand > 1) {
  154714. jcopy_sample_rows(output_data, outrow, output_data, outrow+1,
  154715. v_expand-1, cinfo->output_width);
  154716. }
  154717. inrow++;
  154718. outrow += v_expand;
  154719. }
  154720. }
  154721. METHODDEF(void)
  154722. h2v1_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154723. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154724. {
  154725. JSAMPARRAY output_data = *output_data_ptr;
  154726. register JSAMPROW inptr, outptr;
  154727. register JSAMPLE invalue;
  154728. JSAMPROW outend;
  154729. int inrow;
  154730. for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
  154731. inptr = input_data[inrow];
  154732. outptr = output_data[inrow];
  154733. outend = outptr + cinfo->output_width;
  154734. while (outptr < outend) {
  154735. invalue = *inptr++; /* don't need GETJSAMPLE() here */
  154736. *outptr++ = invalue;
  154737. *outptr++ = invalue;
  154738. }
  154739. }
  154740. }
  154741. METHODDEF(void)
  154742. h2v2_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154743. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154744. {
  154745. JSAMPARRAY output_data = *output_data_ptr;
  154746. register JSAMPROW inptr, outptr;
  154747. register JSAMPLE invalue;
  154748. JSAMPROW outend;
  154749. int inrow, outrow;
  154750. inrow = outrow = 0;
  154751. while (outrow < cinfo->max_v_samp_factor) {
  154752. inptr = input_data[inrow];
  154753. outptr = output_data[outrow];
  154754. outend = outptr + cinfo->output_width;
  154755. while (outptr < outend) {
  154756. invalue = *inptr++; /* don't need GETJSAMPLE() here */
  154757. *outptr++ = invalue;
  154758. *outptr++ = invalue;
  154759. }
  154760. jcopy_sample_rows(output_data, outrow, output_data, outrow+1,
  154761. 1, cinfo->output_width);
  154762. inrow++;
  154763. outrow += 2;
  154764. }
  154765. }
  154766. METHODDEF(void)
  154767. h2v1_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154768. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154769. {
  154770. JSAMPARRAY output_data = *output_data_ptr;
  154771. register JSAMPROW inptr, outptr;
  154772. register int invalue;
  154773. register JDIMENSION colctr;
  154774. int inrow;
  154775. for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
  154776. inptr = input_data[inrow];
  154777. outptr = output_data[inrow];
  154778. invalue = GETJSAMPLE(*inptr++);
  154779. *outptr++ = (JSAMPLE) invalue;
  154780. *outptr++ = (JSAMPLE) ((invalue * 3 + GETJSAMPLE(*inptr) + 2) >> 2);
  154781. for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
  154782. invalue = GETJSAMPLE(*inptr++) * 3;
  154783. *outptr++ = (JSAMPLE) ((invalue + GETJSAMPLE(inptr[-2]) + 1) >> 2);
  154784. *outptr++ = (JSAMPLE) ((invalue + GETJSAMPLE(*inptr) + 2) >> 2);
  154785. }
  154786. invalue = GETJSAMPLE(*inptr);
  154787. *outptr++ = (JSAMPLE) ((invalue * 3 + GETJSAMPLE(inptr[-1]) + 1) >> 2);
  154788. *outptr++ = (JSAMPLE) invalue;
  154789. }
  154790. }
  154791. METHODDEF(void)
  154792. h2v2_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154793. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154794. {
  154795. JSAMPARRAY output_data = *output_data_ptr;
  154796. register JSAMPROW inptr0, inptr1, outptr;
  154797. #if BITS_IN_JSAMPLE == 8
  154798. register int thiscolsum, lastcolsum, nextcolsum;
  154799. #else
  154800. register INT32 thiscolsum, lastcolsum, nextcolsum;
  154801. #endif
  154802. register JDIMENSION colctr;
  154803. int inrow, outrow, v;
  154804. inrow = outrow = 0;
  154805. while (outrow < cinfo->max_v_samp_factor) {
  154806. for (v = 0; v < 2; v++) {
  154807. inptr0 = input_data[inrow];
  154808. if (v == 0) /* next nearest is row above */
  154809. inptr1 = input_data[inrow-1];
  154810. else /* next nearest is row below */
  154811. inptr1 = input_data[inrow+1];
  154812. outptr = output_data[outrow++];
  154813. thiscolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
  154814. nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
  154815. *outptr++ = (JSAMPLE) ((thiscolsum * 4 + 8) >> 4);
  154816. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4);
  154817. lastcolsum = thiscolsum; thiscolsum = nextcolsum;
  154818. for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
  154819. nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
  154820. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4);
  154821. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4);
  154822. lastcolsum = thiscolsum; thiscolsum = nextcolsum;
  154823. }
  154824. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4);
  154825. *outptr++ = (JSAMPLE) ((thiscolsum * 4 + 7) >> 4);
  154826. }
  154827. inrow++;
  154828. }
  154829. }
  154830. GLOBAL(void)
  154831. jinit_upsampler (j_decompress_ptr cinfo)
  154832. {
  154833. my_upsample_ptr2 upsample;
  154834. int ci;
  154835. jpeg_component_info * compptr;
  154836. boolean need_buffer, do_fancy;
  154837. int h_in_group, v_in_group, h_out_group, v_out_group;
  154838. upsample = (my_upsample_ptr2)
  154839. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154840. SIZEOF(my_upsampler2));
  154841. cinfo->upsample = (struct jpeg_upsampler *) upsample;
  154842. upsample->pub.start_pass = start_pass_upsample;
  154843. upsample->pub.upsample = sep_upsample;
  154844. upsample->pub.need_context_rows = FALSE; /* until we find out differently */
  154845. if (cinfo->CCIR601_sampling) /* this isn't supported */
  154846. ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
  154847. do_fancy = cinfo->do_fancy_upsampling && cinfo->min_DCT_scaled_size > 1;
  154848. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  154849. ci++, compptr++) {
  154850. h_in_group = (compptr->h_samp_factor * compptr->DCT_scaled_size) /
  154851. cinfo->min_DCT_scaled_size;
  154852. v_in_group = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  154853. cinfo->min_DCT_scaled_size;
  154854. h_out_group = cinfo->max_h_samp_factor;
  154855. v_out_group = cinfo->max_v_samp_factor;
  154856. upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
  154857. need_buffer = TRUE;
  154858. if (! compptr->component_needed) {
  154859. upsample->methods[ci] = noop_upsample;
  154860. need_buffer = FALSE;
  154861. } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
  154862. upsample->methods[ci] = fullsize_upsample;
  154863. need_buffer = FALSE;
  154864. } else if (h_in_group * 2 == h_out_group &&
  154865. v_in_group == v_out_group) {
  154866. if (do_fancy && compptr->downsampled_width > 2)
  154867. upsample->methods[ci] = h2v1_fancy_upsample;
  154868. else
  154869. upsample->methods[ci] = h2v1_upsample;
  154870. } else if (h_in_group * 2 == h_out_group &&
  154871. v_in_group * 2 == v_out_group) {
  154872. if (do_fancy && compptr->downsampled_width > 2) {
  154873. upsample->methods[ci] = h2v2_fancy_upsample;
  154874. upsample->pub.need_context_rows = TRUE;
  154875. } else
  154876. upsample->methods[ci] = h2v2_upsample;
  154877. } else if ((h_out_group % h_in_group) == 0 &&
  154878. (v_out_group % v_in_group) == 0) {
  154879. upsample->methods[ci] = int_upsample;
  154880. upsample->h_expand[ci] = (UINT8) (h_out_group / h_in_group);
  154881. upsample->v_expand[ci] = (UINT8) (v_out_group / v_in_group);
  154882. } else
  154883. ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
  154884. if (need_buffer) {
  154885. upsample->color_buf[ci] = (*cinfo->mem->alloc_sarray)
  154886. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154887. (JDIMENSION) jround_up((long) cinfo->output_width,
  154888. (long) cinfo->max_h_samp_factor),
  154889. (JDIMENSION) cinfo->max_v_samp_factor);
  154890. }
  154891. }
  154892. }
  154893. /*** End of inlined file: jdsample.c ***/
  154894. /*** Start of inlined file: jdtrans.c ***/
  154895. #define JPEG_INTERNALS
  154896. LOCAL(void) transdecode_master_selection JPP((j_decompress_ptr cinfo));
  154897. GLOBAL(jvirt_barray_ptr *)
  154898. jpeg_read_coefficients (j_decompress_ptr cinfo)
  154899. {
  154900. if (cinfo->global_state == DSTATE_READY) {
  154901. transdecode_master_selection(cinfo);
  154902. cinfo->global_state = DSTATE_RDCOEFS;
  154903. }
  154904. if (cinfo->global_state == DSTATE_RDCOEFS) {
  154905. for (;;) {
  154906. int retcode;
  154907. if (cinfo->progress != NULL)
  154908. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  154909. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  154910. if (retcode == JPEG_SUSPENDED)
  154911. return NULL;
  154912. if (retcode == JPEG_REACHED_EOI)
  154913. break;
  154914. if (cinfo->progress != NULL &&
  154915. (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
  154916. if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
  154917. cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
  154918. }
  154919. }
  154920. }
  154921. cinfo->global_state = DSTATE_STOPPING;
  154922. }
  154923. if ((cinfo->global_state == DSTATE_STOPPING ||
  154924. cinfo->global_state == DSTATE_BUFIMAGE) && cinfo->buffered_image) {
  154925. return cinfo->coef->coef_arrays;
  154926. }
  154927. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  154928. return NULL; /* keep compiler happy */
  154929. }
  154930. LOCAL(void)
  154931. transdecode_master_selection (j_decompress_ptr cinfo)
  154932. {
  154933. cinfo->buffered_image = TRUE;
  154934. if (cinfo->arith_code) {
  154935. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  154936. } else {
  154937. if (cinfo->progressive_mode) {
  154938. #ifdef D_PROGRESSIVE_SUPPORTED
  154939. jinit_phuff_decoder(cinfo);
  154940. #else
  154941. ERREXIT(cinfo, JERR_NOT_COMPILED);
  154942. #endif
  154943. } else
  154944. jinit_huff_decoder(cinfo);
  154945. }
  154946. jinit_d_coef_controller(cinfo, TRUE);
  154947. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  154948. (*cinfo->inputctl->start_input_pass) (cinfo);
  154949. if (cinfo->progress != NULL) {
  154950. int nscans;
  154951. if (cinfo->progressive_mode) {
  154952. nscans = 2 + 3 * cinfo->num_components;
  154953. } else if (cinfo->inputctl->has_multiple_scans) {
  154954. nscans = cinfo->num_components;
  154955. } else {
  154956. nscans = 1;
  154957. }
  154958. cinfo->progress->pass_counter = 0L;
  154959. cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans;
  154960. cinfo->progress->completed_passes = 0;
  154961. cinfo->progress->total_passes = 1;
  154962. }
  154963. }
  154964. /*** End of inlined file: jdtrans.c ***/
  154965. /*** Start of inlined file: jfdctflt.c ***/
  154966. #define JPEG_INTERNALS
  154967. #ifdef DCT_FLOAT_SUPPORTED
  154968. #if DCTSIZE != 8
  154969. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  154970. #endif
  154971. GLOBAL(void)
  154972. jpeg_fdct_float (FAST_FLOAT * data)
  154973. {
  154974. FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  154975. FAST_FLOAT tmp10, tmp11, tmp12, tmp13;
  154976. FAST_FLOAT z1, z2, z3, z4, z5, z11, z13;
  154977. FAST_FLOAT *dataptr;
  154978. int ctr;
  154979. dataptr = data;
  154980. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  154981. tmp0 = dataptr[0] + dataptr[7];
  154982. tmp7 = dataptr[0] - dataptr[7];
  154983. tmp1 = dataptr[1] + dataptr[6];
  154984. tmp6 = dataptr[1] - dataptr[6];
  154985. tmp2 = dataptr[2] + dataptr[5];
  154986. tmp5 = dataptr[2] - dataptr[5];
  154987. tmp3 = dataptr[3] + dataptr[4];
  154988. tmp4 = dataptr[3] - dataptr[4];
  154989. tmp10 = tmp0 + tmp3; /* phase 2 */
  154990. tmp13 = tmp0 - tmp3;
  154991. tmp11 = tmp1 + tmp2;
  154992. tmp12 = tmp1 - tmp2;
  154993. dataptr[0] = tmp10 + tmp11; /* phase 3 */
  154994. dataptr[4] = tmp10 - tmp11;
  154995. z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */
  154996. dataptr[2] = tmp13 + z1; /* phase 5 */
  154997. dataptr[6] = tmp13 - z1;
  154998. tmp10 = tmp4 + tmp5; /* phase 2 */
  154999. tmp11 = tmp5 + tmp6;
  155000. tmp12 = tmp6 + tmp7;
  155001. z5 = (tmp10 - tmp12) * ((FAST_FLOAT) 0.382683433); /* c6 */
  155002. z2 = ((FAST_FLOAT) 0.541196100) * tmp10 + z5; /* c2-c6 */
  155003. z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */
  155004. z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */
  155005. z11 = tmp7 + z3; /* phase 5 */
  155006. z13 = tmp7 - z3;
  155007. dataptr[5] = z13 + z2; /* phase 6 */
  155008. dataptr[3] = z13 - z2;
  155009. dataptr[1] = z11 + z4;
  155010. dataptr[7] = z11 - z4;
  155011. dataptr += DCTSIZE; /* advance pointer to next row */
  155012. }
  155013. dataptr = data;
  155014. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155015. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  155016. tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  155017. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  155018. tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  155019. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  155020. tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  155021. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  155022. tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  155023. tmp10 = tmp0 + tmp3; /* phase 2 */
  155024. tmp13 = tmp0 - tmp3;
  155025. tmp11 = tmp1 + tmp2;
  155026. tmp12 = tmp1 - tmp2;
  155027. dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */
  155028. dataptr[DCTSIZE*4] = tmp10 - tmp11;
  155029. z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */
  155030. dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */
  155031. dataptr[DCTSIZE*6] = tmp13 - z1;
  155032. tmp10 = tmp4 + tmp5; /* phase 2 */
  155033. tmp11 = tmp5 + tmp6;
  155034. tmp12 = tmp6 + tmp7;
  155035. z5 = (tmp10 - tmp12) * ((FAST_FLOAT) 0.382683433); /* c6 */
  155036. z2 = ((FAST_FLOAT) 0.541196100) * tmp10 + z5; /* c2-c6 */
  155037. z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */
  155038. z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */
  155039. z11 = tmp7 + z3; /* phase 5 */
  155040. z13 = tmp7 - z3;
  155041. dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */
  155042. dataptr[DCTSIZE*3] = z13 - z2;
  155043. dataptr[DCTSIZE*1] = z11 + z4;
  155044. dataptr[DCTSIZE*7] = z11 - z4;
  155045. dataptr++; /* advance pointer to next column */
  155046. }
  155047. }
  155048. #endif /* DCT_FLOAT_SUPPORTED */
  155049. /*** End of inlined file: jfdctflt.c ***/
  155050. /*** Start of inlined file: jfdctint.c ***/
  155051. #define JPEG_INTERNALS
  155052. #ifdef DCT_ISLOW_SUPPORTED
  155053. #if DCTSIZE != 8
  155054. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155055. #endif
  155056. #if BITS_IN_JSAMPLE == 8
  155057. #define CONST_BITS 13
  155058. #define PASS1_BITS 2
  155059. #else
  155060. #define CONST_BITS 13
  155061. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  155062. #endif
  155063. #if CONST_BITS == 13
  155064. #define FIX_0_298631336 ((INT32) 2446) /* FIX(0.298631336) */
  155065. #define FIX_0_390180644 ((INT32) 3196) /* FIX(0.390180644) */
  155066. #define FIX_0_541196100 ((INT32) 4433) /* FIX(0.541196100) */
  155067. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  155068. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  155069. #define FIX_1_175875602 ((INT32) 9633) /* FIX(1.175875602) */
  155070. #define FIX_1_501321110 ((INT32) 12299) /* FIX(1.501321110) */
  155071. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  155072. #define FIX_1_961570560 ((INT32) 16069) /* FIX(1.961570560) */
  155073. #define FIX_2_053119869 ((INT32) 16819) /* FIX(2.053119869) */
  155074. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  155075. #define FIX_3_072711026 ((INT32) 25172) /* FIX(3.072711026) */
  155076. #else
  155077. #define FIX_0_298631336 FIX(0.298631336)
  155078. #define FIX_0_390180644 FIX(0.390180644)
  155079. #define FIX_0_541196100 FIX(0.541196100)
  155080. #define FIX_0_765366865 FIX(0.765366865)
  155081. #define FIX_0_899976223 FIX(0.899976223)
  155082. #define FIX_1_175875602 FIX(1.175875602)
  155083. #define FIX_1_501321110 FIX(1.501321110)
  155084. #define FIX_1_847759065 FIX(1.847759065)
  155085. #define FIX_1_961570560 FIX(1.961570560)
  155086. #define FIX_2_053119869 FIX(2.053119869)
  155087. #define FIX_2_562915447 FIX(2.562915447)
  155088. #define FIX_3_072711026 FIX(3.072711026)
  155089. #endif
  155090. #if BITS_IN_JSAMPLE == 8
  155091. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  155092. #else
  155093. #define MULTIPLY(var,const) ((var) * (const))
  155094. #endif
  155095. GLOBAL(void)
  155096. jpeg_fdct_islow (DCTELEM * data)
  155097. {
  155098. INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155099. INT32 tmp10, tmp11, tmp12, tmp13;
  155100. INT32 z1, z2, z3, z4, z5;
  155101. DCTELEM *dataptr;
  155102. int ctr;
  155103. SHIFT_TEMPS
  155104. dataptr = data;
  155105. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155106. tmp0 = dataptr[0] + dataptr[7];
  155107. tmp7 = dataptr[0] - dataptr[7];
  155108. tmp1 = dataptr[1] + dataptr[6];
  155109. tmp6 = dataptr[1] - dataptr[6];
  155110. tmp2 = dataptr[2] + dataptr[5];
  155111. tmp5 = dataptr[2] - dataptr[5];
  155112. tmp3 = dataptr[3] + dataptr[4];
  155113. tmp4 = dataptr[3] - dataptr[4];
  155114. tmp10 = tmp0 + tmp3;
  155115. tmp13 = tmp0 - tmp3;
  155116. tmp11 = tmp1 + tmp2;
  155117. tmp12 = tmp1 - tmp2;
  155118. dataptr[0] = (DCTELEM) ((tmp10 + tmp11) << PASS1_BITS);
  155119. dataptr[4] = (DCTELEM) ((tmp10 - tmp11) << PASS1_BITS);
  155120. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
  155121. dataptr[2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
  155122. CONST_BITS-PASS1_BITS);
  155123. dataptr[6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
  155124. CONST_BITS-PASS1_BITS);
  155125. z1 = tmp4 + tmp7;
  155126. z2 = tmp5 + tmp6;
  155127. z3 = tmp4 + tmp6;
  155128. z4 = tmp5 + tmp7;
  155129. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  155130. tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  155131. tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  155132. tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  155133. tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  155134. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  155135. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  155136. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  155137. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  155138. z3 += z5;
  155139. z4 += z5;
  155140. dataptr[7] = (DCTELEM) DESCALE(tmp4 + z1 + z3, CONST_BITS-PASS1_BITS);
  155141. dataptr[5] = (DCTELEM) DESCALE(tmp5 + z2 + z4, CONST_BITS-PASS1_BITS);
  155142. dataptr[3] = (DCTELEM) DESCALE(tmp6 + z2 + z3, CONST_BITS-PASS1_BITS);
  155143. dataptr[1] = (DCTELEM) DESCALE(tmp7 + z1 + z4, CONST_BITS-PASS1_BITS);
  155144. dataptr += DCTSIZE; /* advance pointer to next row */
  155145. }
  155146. dataptr = data;
  155147. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155148. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  155149. tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  155150. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  155151. tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  155152. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  155153. tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  155154. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  155155. tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  155156. tmp10 = tmp0 + tmp3;
  155157. tmp13 = tmp0 - tmp3;
  155158. tmp11 = tmp1 + tmp2;
  155159. tmp12 = tmp1 - tmp2;
  155160. dataptr[DCTSIZE*0] = (DCTELEM) DESCALE(tmp10 + tmp11, PASS1_BITS);
  155161. dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(tmp10 - tmp11, PASS1_BITS);
  155162. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
  155163. dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
  155164. CONST_BITS+PASS1_BITS);
  155165. dataptr[DCTSIZE*6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
  155166. CONST_BITS+PASS1_BITS);
  155167. z1 = tmp4 + tmp7;
  155168. z2 = tmp5 + tmp6;
  155169. z3 = tmp4 + tmp6;
  155170. z4 = tmp5 + tmp7;
  155171. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  155172. tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  155173. tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  155174. tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  155175. tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  155176. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  155177. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  155178. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  155179. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  155180. z3 += z5;
  155181. z4 += z5;
  155182. dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp4 + z1 + z3,
  155183. CONST_BITS+PASS1_BITS);
  155184. dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp5 + z2 + z4,
  155185. CONST_BITS+PASS1_BITS);
  155186. dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp6 + z2 + z3,
  155187. CONST_BITS+PASS1_BITS);
  155188. dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp7 + z1 + z4,
  155189. CONST_BITS+PASS1_BITS);
  155190. dataptr++; /* advance pointer to next column */
  155191. }
  155192. }
  155193. #endif /* DCT_ISLOW_SUPPORTED */
  155194. /*** End of inlined file: jfdctint.c ***/
  155195. #undef CONST_BITS
  155196. #undef MULTIPLY
  155197. #undef FIX_0_541196100
  155198. /*** Start of inlined file: jfdctfst.c ***/
  155199. #define JPEG_INTERNALS
  155200. #ifdef DCT_IFAST_SUPPORTED
  155201. #if DCTSIZE != 8
  155202. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155203. #endif
  155204. #define CONST_BITS 8
  155205. #if CONST_BITS == 8
  155206. #define FIX_0_382683433 ((INT32) 98) /* FIX(0.382683433) */
  155207. #define FIX_0_541196100 ((INT32) 139) /* FIX(0.541196100) */
  155208. #define FIX_0_707106781 ((INT32) 181) /* FIX(0.707106781) */
  155209. #define FIX_1_306562965 ((INT32) 334) /* FIX(1.306562965) */
  155210. #else
  155211. #define FIX_0_382683433 FIX(0.382683433)
  155212. #define FIX_0_541196100 FIX(0.541196100)
  155213. #define FIX_0_707106781 FIX(0.707106781)
  155214. #define FIX_1_306562965 FIX(1.306562965)
  155215. #endif
  155216. #ifndef USE_ACCURATE_ROUNDING
  155217. #undef DESCALE
  155218. #define DESCALE(x,n) RIGHT_SHIFT(x, n)
  155219. #endif
  155220. #define MULTIPLY(var,const) ((DCTELEM) DESCALE((var) * (const), CONST_BITS))
  155221. GLOBAL(void)
  155222. jpeg_fdct_ifast (DCTELEM * data)
  155223. {
  155224. DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155225. DCTELEM tmp10, tmp11, tmp12, tmp13;
  155226. DCTELEM z1, z2, z3, z4, z5, z11, z13;
  155227. DCTELEM *dataptr;
  155228. int ctr;
  155229. SHIFT_TEMPS
  155230. dataptr = data;
  155231. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155232. tmp0 = dataptr[0] + dataptr[7];
  155233. tmp7 = dataptr[0] - dataptr[7];
  155234. tmp1 = dataptr[1] + dataptr[6];
  155235. tmp6 = dataptr[1] - dataptr[6];
  155236. tmp2 = dataptr[2] + dataptr[5];
  155237. tmp5 = dataptr[2] - dataptr[5];
  155238. tmp3 = dataptr[3] + dataptr[4];
  155239. tmp4 = dataptr[3] - dataptr[4];
  155240. tmp10 = tmp0 + tmp3; /* phase 2 */
  155241. tmp13 = tmp0 - tmp3;
  155242. tmp11 = tmp1 + tmp2;
  155243. tmp12 = tmp1 - tmp2;
  155244. dataptr[0] = tmp10 + tmp11; /* phase 3 */
  155245. dataptr[4] = tmp10 - tmp11;
  155246. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */
  155247. dataptr[2] = tmp13 + z1; /* phase 5 */
  155248. dataptr[6] = tmp13 - z1;
  155249. tmp10 = tmp4 + tmp5; /* phase 2 */
  155250. tmp11 = tmp5 + tmp6;
  155251. tmp12 = tmp6 + tmp7;
  155252. z5 = MULTIPLY(tmp10 - tmp12, FIX_0_382683433); /* c6 */
  155253. z2 = MULTIPLY(tmp10, FIX_0_541196100) + z5; /* c2-c6 */
  155254. z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */
  155255. z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */
  155256. z11 = tmp7 + z3; /* phase 5 */
  155257. z13 = tmp7 - z3;
  155258. dataptr[5] = z13 + z2; /* phase 6 */
  155259. dataptr[3] = z13 - z2;
  155260. dataptr[1] = z11 + z4;
  155261. dataptr[7] = z11 - z4;
  155262. dataptr += DCTSIZE; /* advance pointer to next row */
  155263. }
  155264. dataptr = data;
  155265. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155266. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  155267. tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  155268. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  155269. tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  155270. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  155271. tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  155272. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  155273. tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  155274. tmp10 = tmp0 + tmp3; /* phase 2 */
  155275. tmp13 = tmp0 - tmp3;
  155276. tmp11 = tmp1 + tmp2;
  155277. tmp12 = tmp1 - tmp2;
  155278. dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */
  155279. dataptr[DCTSIZE*4] = tmp10 - tmp11;
  155280. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */
  155281. dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */
  155282. dataptr[DCTSIZE*6] = tmp13 - z1;
  155283. tmp10 = tmp4 + tmp5; /* phase 2 */
  155284. tmp11 = tmp5 + tmp6;
  155285. tmp12 = tmp6 + tmp7;
  155286. z5 = MULTIPLY(tmp10 - tmp12, FIX_0_382683433); /* c6 */
  155287. z2 = MULTIPLY(tmp10, FIX_0_541196100) + z5; /* c2-c6 */
  155288. z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */
  155289. z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */
  155290. z11 = tmp7 + z3; /* phase 5 */
  155291. z13 = tmp7 - z3;
  155292. dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */
  155293. dataptr[DCTSIZE*3] = z13 - z2;
  155294. dataptr[DCTSIZE*1] = z11 + z4;
  155295. dataptr[DCTSIZE*7] = z11 - z4;
  155296. dataptr++; /* advance pointer to next column */
  155297. }
  155298. }
  155299. #endif /* DCT_IFAST_SUPPORTED */
  155300. /*** End of inlined file: jfdctfst.c ***/
  155301. #undef FIX_0_541196100
  155302. /*** Start of inlined file: jidctflt.c ***/
  155303. #define JPEG_INTERNALS
  155304. #ifdef DCT_FLOAT_SUPPORTED
  155305. #if DCTSIZE != 8
  155306. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155307. #endif
  155308. #define DEQUANTIZE(coef,quantval) (((FAST_FLOAT) (coef)) * (quantval))
  155309. GLOBAL(void)
  155310. jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155311. JCOEFPTR coef_block,
  155312. JSAMPARRAY output_buf, JDIMENSION output_col)
  155313. {
  155314. FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155315. FAST_FLOAT tmp10, tmp11, tmp12, tmp13;
  155316. FAST_FLOAT z5, z10, z11, z12, z13;
  155317. JCOEFPTR inptr;
  155318. FLOAT_MULT_TYPE * quantptr;
  155319. FAST_FLOAT * wsptr;
  155320. JSAMPROW outptr;
  155321. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155322. int ctr;
  155323. FAST_FLOAT workspace[DCTSIZE2]; /* buffers data between passes */
  155324. SHIFT_TEMPS
  155325. inptr = coef_block;
  155326. quantptr = (FLOAT_MULT_TYPE *) compptr->dct_table;
  155327. wsptr = workspace;
  155328. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  155329. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  155330. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
  155331. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
  155332. inptr[DCTSIZE*7] == 0) {
  155333. FAST_FLOAT dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155334. wsptr[DCTSIZE*0] = dcval;
  155335. wsptr[DCTSIZE*1] = dcval;
  155336. wsptr[DCTSIZE*2] = dcval;
  155337. wsptr[DCTSIZE*3] = dcval;
  155338. wsptr[DCTSIZE*4] = dcval;
  155339. wsptr[DCTSIZE*5] = dcval;
  155340. wsptr[DCTSIZE*6] = dcval;
  155341. wsptr[DCTSIZE*7] = dcval;
  155342. inptr++; /* advance pointers to next column */
  155343. quantptr++;
  155344. wsptr++;
  155345. continue;
  155346. }
  155347. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155348. tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  155349. tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  155350. tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  155351. tmp10 = tmp0 + tmp2; /* phase 3 */
  155352. tmp11 = tmp0 - tmp2;
  155353. tmp13 = tmp1 + tmp3; /* phases 5-3 */
  155354. tmp12 = (tmp1 - tmp3) * ((FAST_FLOAT) 1.414213562) - tmp13; /* 2*c4 */
  155355. tmp0 = tmp10 + tmp13; /* phase 2 */
  155356. tmp3 = tmp10 - tmp13;
  155357. tmp1 = tmp11 + tmp12;
  155358. tmp2 = tmp11 - tmp12;
  155359. tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155360. tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155361. tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155362. tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155363. z13 = tmp6 + tmp5; /* phase 6 */
  155364. z10 = tmp6 - tmp5;
  155365. z11 = tmp4 + tmp7;
  155366. z12 = tmp4 - tmp7;
  155367. tmp7 = z11 + z13; /* phase 5 */
  155368. tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562); /* 2*c4 */
  155369. z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */
  155370. tmp10 = ((FAST_FLOAT) 1.082392200) * z12 - z5; /* 2*(c2-c6) */
  155371. tmp12 = ((FAST_FLOAT) -2.613125930) * z10 + z5; /* -2*(c2+c6) */
  155372. tmp6 = tmp12 - tmp7; /* phase 2 */
  155373. tmp5 = tmp11 - tmp6;
  155374. tmp4 = tmp10 + tmp5;
  155375. wsptr[DCTSIZE*0] = tmp0 + tmp7;
  155376. wsptr[DCTSIZE*7] = tmp0 - tmp7;
  155377. wsptr[DCTSIZE*1] = tmp1 + tmp6;
  155378. wsptr[DCTSIZE*6] = tmp1 - tmp6;
  155379. wsptr[DCTSIZE*2] = tmp2 + tmp5;
  155380. wsptr[DCTSIZE*5] = tmp2 - tmp5;
  155381. wsptr[DCTSIZE*4] = tmp3 + tmp4;
  155382. wsptr[DCTSIZE*3] = tmp3 - tmp4;
  155383. inptr++; /* advance pointers to next column */
  155384. quantptr++;
  155385. wsptr++;
  155386. }
  155387. wsptr = workspace;
  155388. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  155389. outptr = output_buf[ctr] + output_col;
  155390. tmp10 = wsptr[0] + wsptr[4];
  155391. tmp11 = wsptr[0] - wsptr[4];
  155392. tmp13 = wsptr[2] + wsptr[6];
  155393. tmp12 = (wsptr[2] - wsptr[6]) * ((FAST_FLOAT) 1.414213562) - tmp13;
  155394. tmp0 = tmp10 + tmp13;
  155395. tmp3 = tmp10 - tmp13;
  155396. tmp1 = tmp11 + tmp12;
  155397. tmp2 = tmp11 - tmp12;
  155398. z13 = wsptr[5] + wsptr[3];
  155399. z10 = wsptr[5] - wsptr[3];
  155400. z11 = wsptr[1] + wsptr[7];
  155401. z12 = wsptr[1] - wsptr[7];
  155402. tmp7 = z11 + z13;
  155403. tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562);
  155404. z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */
  155405. tmp10 = ((FAST_FLOAT) 1.082392200) * z12 - z5; /* 2*(c2-c6) */
  155406. tmp12 = ((FAST_FLOAT) -2.613125930) * z10 + z5; /* -2*(c2+c6) */
  155407. tmp6 = tmp12 - tmp7;
  155408. tmp5 = tmp11 - tmp6;
  155409. tmp4 = tmp10 + tmp5;
  155410. outptr[0] = range_limit[(int) DESCALE((INT32) (tmp0 + tmp7), 3)
  155411. & RANGE_MASK];
  155412. outptr[7] = range_limit[(int) DESCALE((INT32) (tmp0 - tmp7), 3)
  155413. & RANGE_MASK];
  155414. outptr[1] = range_limit[(int) DESCALE((INT32) (tmp1 + tmp6), 3)
  155415. & RANGE_MASK];
  155416. outptr[6] = range_limit[(int) DESCALE((INT32) (tmp1 - tmp6), 3)
  155417. & RANGE_MASK];
  155418. outptr[2] = range_limit[(int) DESCALE((INT32) (tmp2 + tmp5), 3)
  155419. & RANGE_MASK];
  155420. outptr[5] = range_limit[(int) DESCALE((INT32) (tmp2 - tmp5), 3)
  155421. & RANGE_MASK];
  155422. outptr[4] = range_limit[(int) DESCALE((INT32) (tmp3 + tmp4), 3)
  155423. & RANGE_MASK];
  155424. outptr[3] = range_limit[(int) DESCALE((INT32) (tmp3 - tmp4), 3)
  155425. & RANGE_MASK];
  155426. wsptr += DCTSIZE; /* advance pointer to next row */
  155427. }
  155428. }
  155429. #endif /* DCT_FLOAT_SUPPORTED */
  155430. /*** End of inlined file: jidctflt.c ***/
  155431. #undef CONST_BITS
  155432. #undef FIX_1_847759065
  155433. #undef MULTIPLY
  155434. #undef DEQUANTIZE
  155435. #undef DESCALE
  155436. /*** Start of inlined file: jidctfst.c ***/
  155437. #define JPEG_INTERNALS
  155438. #ifdef DCT_IFAST_SUPPORTED
  155439. #if DCTSIZE != 8
  155440. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155441. #endif
  155442. #if BITS_IN_JSAMPLE == 8
  155443. #define CONST_BITS 8
  155444. #define PASS1_BITS 2
  155445. #else
  155446. #define CONST_BITS 8
  155447. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  155448. #endif
  155449. #if CONST_BITS == 8
  155450. #define FIX_1_082392200 ((INT32) 277) /* FIX(1.082392200) */
  155451. #define FIX_1_414213562 ((INT32) 362) /* FIX(1.414213562) */
  155452. #define FIX_1_847759065 ((INT32) 473) /* FIX(1.847759065) */
  155453. #define FIX_2_613125930 ((INT32) 669) /* FIX(2.613125930) */
  155454. #else
  155455. #define FIX_1_082392200 FIX(1.082392200)
  155456. #define FIX_1_414213562 FIX(1.414213562)
  155457. #define FIX_1_847759065 FIX(1.847759065)
  155458. #define FIX_2_613125930 FIX(2.613125930)
  155459. #endif
  155460. #ifndef USE_ACCURATE_ROUNDING
  155461. #undef DESCALE
  155462. #define DESCALE(x,n) RIGHT_SHIFT(x, n)
  155463. #endif
  155464. #define MULTIPLY(var,const) ((DCTELEM) DESCALE((var) * (const), CONST_BITS))
  155465. #if BITS_IN_JSAMPLE == 8
  155466. #define DEQUANTIZE(coef,quantval) (((IFAST_MULT_TYPE) (coef)) * (quantval))
  155467. #else
  155468. #define DEQUANTIZE(coef,quantval) \
  155469. DESCALE((coef)*(quantval), IFAST_SCALE_BITS-PASS1_BITS)
  155470. #endif
  155471. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  155472. #define ISHIFT_TEMPS DCTELEM ishift_temp;
  155473. #if BITS_IN_JSAMPLE == 8
  155474. #define DCTELEMBITS 16 /* DCTELEM may be 16 or 32 bits */
  155475. #else
  155476. #define DCTELEMBITS 32 /* DCTELEM must be 32 bits */
  155477. #endif
  155478. #define IRIGHT_SHIFT(x,shft) \
  155479. ((ishift_temp = (x)) < 0 ? \
  155480. (ishift_temp >> (shft)) | ((~((DCTELEM) 0)) << (DCTELEMBITS-(shft))) : \
  155481. (ishift_temp >> (shft)))
  155482. #else
  155483. #define ISHIFT_TEMPS
  155484. #define IRIGHT_SHIFT(x,shft) ((x) >> (shft))
  155485. #endif
  155486. #ifdef USE_ACCURATE_ROUNDING
  155487. #define IDESCALE(x,n) ((int) IRIGHT_SHIFT((x) + (1 << ((n)-1)), n))
  155488. #else
  155489. #define IDESCALE(x,n) ((int) IRIGHT_SHIFT(x, n))
  155490. #endif
  155491. GLOBAL(void)
  155492. jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155493. JCOEFPTR coef_block,
  155494. JSAMPARRAY output_buf, JDIMENSION output_col)
  155495. {
  155496. DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155497. DCTELEM tmp10, tmp11, tmp12, tmp13;
  155498. DCTELEM z5, z10, z11, z12, z13;
  155499. JCOEFPTR inptr;
  155500. IFAST_MULT_TYPE * quantptr;
  155501. int * wsptr;
  155502. JSAMPROW outptr;
  155503. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155504. int ctr;
  155505. int workspace[DCTSIZE2]; /* buffers data between passes */
  155506. SHIFT_TEMPS /* for DESCALE */
  155507. ISHIFT_TEMPS /* for IDESCALE */
  155508. inptr = coef_block;
  155509. quantptr = (IFAST_MULT_TYPE *) compptr->dct_table;
  155510. wsptr = workspace;
  155511. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  155512. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  155513. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
  155514. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
  155515. inptr[DCTSIZE*7] == 0) {
  155516. int dcval = (int) DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155517. wsptr[DCTSIZE*0] = dcval;
  155518. wsptr[DCTSIZE*1] = dcval;
  155519. wsptr[DCTSIZE*2] = dcval;
  155520. wsptr[DCTSIZE*3] = dcval;
  155521. wsptr[DCTSIZE*4] = dcval;
  155522. wsptr[DCTSIZE*5] = dcval;
  155523. wsptr[DCTSIZE*6] = dcval;
  155524. wsptr[DCTSIZE*7] = dcval;
  155525. inptr++; /* advance pointers to next column */
  155526. quantptr++;
  155527. wsptr++;
  155528. continue;
  155529. }
  155530. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155531. tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  155532. tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  155533. tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  155534. tmp10 = tmp0 + tmp2; /* phase 3 */
  155535. tmp11 = tmp0 - tmp2;
  155536. tmp13 = tmp1 + tmp3; /* phases 5-3 */
  155537. tmp12 = MULTIPLY(tmp1 - tmp3, FIX_1_414213562) - tmp13; /* 2*c4 */
  155538. tmp0 = tmp10 + tmp13; /* phase 2 */
  155539. tmp3 = tmp10 - tmp13;
  155540. tmp1 = tmp11 + tmp12;
  155541. tmp2 = tmp11 - tmp12;
  155542. tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155543. tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155544. tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155545. tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155546. z13 = tmp6 + tmp5; /* phase 6 */
  155547. z10 = tmp6 - tmp5;
  155548. z11 = tmp4 + tmp7;
  155549. z12 = tmp4 - tmp7;
  155550. tmp7 = z11 + z13; /* phase 5 */
  155551. tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */
  155552. z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */
  155553. tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */
  155554. tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */
  155555. tmp6 = tmp12 - tmp7; /* phase 2 */
  155556. tmp5 = tmp11 - tmp6;
  155557. tmp4 = tmp10 + tmp5;
  155558. wsptr[DCTSIZE*0] = (int) (tmp0 + tmp7);
  155559. wsptr[DCTSIZE*7] = (int) (tmp0 - tmp7);
  155560. wsptr[DCTSIZE*1] = (int) (tmp1 + tmp6);
  155561. wsptr[DCTSIZE*6] = (int) (tmp1 - tmp6);
  155562. wsptr[DCTSIZE*2] = (int) (tmp2 + tmp5);
  155563. wsptr[DCTSIZE*5] = (int) (tmp2 - tmp5);
  155564. wsptr[DCTSIZE*4] = (int) (tmp3 + tmp4);
  155565. wsptr[DCTSIZE*3] = (int) (tmp3 - tmp4);
  155566. inptr++; /* advance pointers to next column */
  155567. quantptr++;
  155568. wsptr++;
  155569. }
  155570. wsptr = workspace;
  155571. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  155572. outptr = output_buf[ctr] + output_col;
  155573. #ifndef NO_ZERO_ROW_TEST
  155574. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 &&
  155575. wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
  155576. JSAMPLE dcval = range_limit[IDESCALE(wsptr[0], PASS1_BITS+3)
  155577. & RANGE_MASK];
  155578. outptr[0] = dcval;
  155579. outptr[1] = dcval;
  155580. outptr[2] = dcval;
  155581. outptr[3] = dcval;
  155582. outptr[4] = dcval;
  155583. outptr[5] = dcval;
  155584. outptr[6] = dcval;
  155585. outptr[7] = dcval;
  155586. wsptr += DCTSIZE; /* advance pointer to next row */
  155587. continue;
  155588. }
  155589. #endif
  155590. tmp10 = ((DCTELEM) wsptr[0] + (DCTELEM) wsptr[4]);
  155591. tmp11 = ((DCTELEM) wsptr[0] - (DCTELEM) wsptr[4]);
  155592. tmp13 = ((DCTELEM) wsptr[2] + (DCTELEM) wsptr[6]);
  155593. tmp12 = MULTIPLY((DCTELEM) wsptr[2] - (DCTELEM) wsptr[6], FIX_1_414213562)
  155594. - tmp13;
  155595. tmp0 = tmp10 + tmp13;
  155596. tmp3 = tmp10 - tmp13;
  155597. tmp1 = tmp11 + tmp12;
  155598. tmp2 = tmp11 - tmp12;
  155599. z13 = (DCTELEM) wsptr[5] + (DCTELEM) wsptr[3];
  155600. z10 = (DCTELEM) wsptr[5] - (DCTELEM) wsptr[3];
  155601. z11 = (DCTELEM) wsptr[1] + (DCTELEM) wsptr[7];
  155602. z12 = (DCTELEM) wsptr[1] - (DCTELEM) wsptr[7];
  155603. tmp7 = z11 + z13; /* phase 5 */
  155604. tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */
  155605. z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */
  155606. tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */
  155607. tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */
  155608. tmp6 = tmp12 - tmp7; /* phase 2 */
  155609. tmp5 = tmp11 - tmp6;
  155610. tmp4 = tmp10 + tmp5;
  155611. outptr[0] = range_limit[IDESCALE(tmp0 + tmp7, PASS1_BITS+3)
  155612. & RANGE_MASK];
  155613. outptr[7] = range_limit[IDESCALE(tmp0 - tmp7, PASS1_BITS+3)
  155614. & RANGE_MASK];
  155615. outptr[1] = range_limit[IDESCALE(tmp1 + tmp6, PASS1_BITS+3)
  155616. & RANGE_MASK];
  155617. outptr[6] = range_limit[IDESCALE(tmp1 - tmp6, PASS1_BITS+3)
  155618. & RANGE_MASK];
  155619. outptr[2] = range_limit[IDESCALE(tmp2 + tmp5, PASS1_BITS+3)
  155620. & RANGE_MASK];
  155621. outptr[5] = range_limit[IDESCALE(tmp2 - tmp5, PASS1_BITS+3)
  155622. & RANGE_MASK];
  155623. outptr[4] = range_limit[IDESCALE(tmp3 + tmp4, PASS1_BITS+3)
  155624. & RANGE_MASK];
  155625. outptr[3] = range_limit[IDESCALE(tmp3 - tmp4, PASS1_BITS+3)
  155626. & RANGE_MASK];
  155627. wsptr += DCTSIZE; /* advance pointer to next row */
  155628. }
  155629. }
  155630. #endif /* DCT_IFAST_SUPPORTED */
  155631. /*** End of inlined file: jidctfst.c ***/
  155632. #undef CONST_BITS
  155633. #undef FIX_1_847759065
  155634. #undef MULTIPLY
  155635. #undef DEQUANTIZE
  155636. /*** Start of inlined file: jidctint.c ***/
  155637. #define JPEG_INTERNALS
  155638. #ifdef DCT_ISLOW_SUPPORTED
  155639. #if DCTSIZE != 8
  155640. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155641. #endif
  155642. #if BITS_IN_JSAMPLE == 8
  155643. #define CONST_BITS 13
  155644. #define PASS1_BITS 2
  155645. #else
  155646. #define CONST_BITS 13
  155647. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  155648. #endif
  155649. #if CONST_BITS == 13
  155650. #define FIX_0_298631336 ((INT32) 2446) /* FIX(0.298631336) */
  155651. #define FIX_0_390180644 ((INT32) 3196) /* FIX(0.390180644) */
  155652. #define FIX_0_541196100 ((INT32) 4433) /* FIX(0.541196100) */
  155653. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  155654. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  155655. #define FIX_1_175875602 ((INT32) 9633) /* FIX(1.175875602) */
  155656. #define FIX_1_501321110 ((INT32) 12299) /* FIX(1.501321110) */
  155657. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  155658. #define FIX_1_961570560 ((INT32) 16069) /* FIX(1.961570560) */
  155659. #define FIX_2_053119869 ((INT32) 16819) /* FIX(2.053119869) */
  155660. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  155661. #define FIX_3_072711026 ((INT32) 25172) /* FIX(3.072711026) */
  155662. #else
  155663. #define FIX_0_298631336 FIX(0.298631336)
  155664. #define FIX_0_390180644 FIX(0.390180644)
  155665. #define FIX_0_541196100 FIX(0.541196100)
  155666. #define FIX_0_765366865 FIX(0.765366865)
  155667. #define FIX_0_899976223 FIX(0.899976223)
  155668. #define FIX_1_175875602 FIX(1.175875602)
  155669. #define FIX_1_501321110 FIX(1.501321110)
  155670. #define FIX_1_847759065 FIX(1.847759065)
  155671. #define FIX_1_961570560 FIX(1.961570560)
  155672. #define FIX_2_053119869 FIX(2.053119869)
  155673. #define FIX_2_562915447 FIX(2.562915447)
  155674. #define FIX_3_072711026 FIX(3.072711026)
  155675. #endif
  155676. #if BITS_IN_JSAMPLE == 8
  155677. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  155678. #else
  155679. #define MULTIPLY(var,const) ((var) * (const))
  155680. #endif
  155681. #define DEQUANTIZE(coef,quantval) (((ISLOW_MULT_TYPE) (coef)) * (quantval))
  155682. GLOBAL(void)
  155683. jpeg_idct_islow (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155684. JCOEFPTR coef_block,
  155685. JSAMPARRAY output_buf, JDIMENSION output_col)
  155686. {
  155687. INT32 tmp0, tmp1, tmp2, tmp3;
  155688. INT32 tmp10, tmp11, tmp12, tmp13;
  155689. INT32 z1, z2, z3, z4, z5;
  155690. JCOEFPTR inptr;
  155691. ISLOW_MULT_TYPE * quantptr;
  155692. int * wsptr;
  155693. JSAMPROW outptr;
  155694. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155695. int ctr;
  155696. int workspace[DCTSIZE2]; /* buffers data between passes */
  155697. SHIFT_TEMPS
  155698. inptr = coef_block;
  155699. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  155700. wsptr = workspace;
  155701. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  155702. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  155703. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
  155704. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
  155705. inptr[DCTSIZE*7] == 0) {
  155706. int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
  155707. wsptr[DCTSIZE*0] = dcval;
  155708. wsptr[DCTSIZE*1] = dcval;
  155709. wsptr[DCTSIZE*2] = dcval;
  155710. wsptr[DCTSIZE*3] = dcval;
  155711. wsptr[DCTSIZE*4] = dcval;
  155712. wsptr[DCTSIZE*5] = dcval;
  155713. wsptr[DCTSIZE*6] = dcval;
  155714. wsptr[DCTSIZE*7] = dcval;
  155715. inptr++; /* advance pointers to next column */
  155716. quantptr++;
  155717. wsptr++;
  155718. continue;
  155719. }
  155720. z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  155721. z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  155722. z1 = MULTIPLY(z2 + z3, FIX_0_541196100);
  155723. tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065);
  155724. tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865);
  155725. z2 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155726. z3 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  155727. tmp0 = (z2 + z3) << CONST_BITS;
  155728. tmp1 = (z2 - z3) << CONST_BITS;
  155729. tmp10 = tmp0 + tmp3;
  155730. tmp13 = tmp0 - tmp3;
  155731. tmp11 = tmp1 + tmp2;
  155732. tmp12 = tmp1 - tmp2;
  155733. tmp0 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155734. tmp1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155735. tmp2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155736. tmp3 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155737. z1 = tmp0 + tmp3;
  155738. z2 = tmp1 + tmp2;
  155739. z3 = tmp0 + tmp2;
  155740. z4 = tmp1 + tmp3;
  155741. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  155742. tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  155743. tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  155744. tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  155745. tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  155746. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  155747. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  155748. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  155749. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  155750. z3 += z5;
  155751. z4 += z5;
  155752. tmp0 += z1 + z3;
  155753. tmp1 += z2 + z4;
  155754. tmp2 += z2 + z3;
  155755. tmp3 += z1 + z4;
  155756. wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp3, CONST_BITS-PASS1_BITS);
  155757. wsptr[DCTSIZE*7] = (int) DESCALE(tmp10 - tmp3, CONST_BITS-PASS1_BITS);
  155758. wsptr[DCTSIZE*1] = (int) DESCALE(tmp11 + tmp2, CONST_BITS-PASS1_BITS);
  155759. wsptr[DCTSIZE*6] = (int) DESCALE(tmp11 - tmp2, CONST_BITS-PASS1_BITS);
  155760. wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 + tmp1, CONST_BITS-PASS1_BITS);
  155761. wsptr[DCTSIZE*5] = (int) DESCALE(tmp12 - tmp1, CONST_BITS-PASS1_BITS);
  155762. wsptr[DCTSIZE*3] = (int) DESCALE(tmp13 + tmp0, CONST_BITS-PASS1_BITS);
  155763. wsptr[DCTSIZE*4] = (int) DESCALE(tmp13 - tmp0, CONST_BITS-PASS1_BITS);
  155764. inptr++; /* advance pointers to next column */
  155765. quantptr++;
  155766. wsptr++;
  155767. }
  155768. wsptr = workspace;
  155769. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  155770. outptr = output_buf[ctr] + output_col;
  155771. #ifndef NO_ZERO_ROW_TEST
  155772. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 &&
  155773. wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
  155774. JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
  155775. & RANGE_MASK];
  155776. outptr[0] = dcval;
  155777. outptr[1] = dcval;
  155778. outptr[2] = dcval;
  155779. outptr[3] = dcval;
  155780. outptr[4] = dcval;
  155781. outptr[5] = dcval;
  155782. outptr[6] = dcval;
  155783. outptr[7] = dcval;
  155784. wsptr += DCTSIZE; /* advance pointer to next row */
  155785. continue;
  155786. }
  155787. #endif
  155788. z2 = (INT32) wsptr[2];
  155789. z3 = (INT32) wsptr[6];
  155790. z1 = MULTIPLY(z2 + z3, FIX_0_541196100);
  155791. tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065);
  155792. tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865);
  155793. tmp0 = ((INT32) wsptr[0] + (INT32) wsptr[4]) << CONST_BITS;
  155794. tmp1 = ((INT32) wsptr[0] - (INT32) wsptr[4]) << CONST_BITS;
  155795. tmp10 = tmp0 + tmp3;
  155796. tmp13 = tmp0 - tmp3;
  155797. tmp11 = tmp1 + tmp2;
  155798. tmp12 = tmp1 - tmp2;
  155799. tmp0 = (INT32) wsptr[7];
  155800. tmp1 = (INT32) wsptr[5];
  155801. tmp2 = (INT32) wsptr[3];
  155802. tmp3 = (INT32) wsptr[1];
  155803. z1 = tmp0 + tmp3;
  155804. z2 = tmp1 + tmp2;
  155805. z3 = tmp0 + tmp2;
  155806. z4 = tmp1 + tmp3;
  155807. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  155808. tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  155809. tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  155810. tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  155811. tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  155812. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  155813. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  155814. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  155815. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  155816. z3 += z5;
  155817. z4 += z5;
  155818. tmp0 += z1 + z3;
  155819. tmp1 += z2 + z4;
  155820. tmp2 += z2 + z3;
  155821. tmp3 += z1 + z4;
  155822. outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp3,
  155823. CONST_BITS+PASS1_BITS+3)
  155824. & RANGE_MASK];
  155825. outptr[7] = range_limit[(int) DESCALE(tmp10 - tmp3,
  155826. CONST_BITS+PASS1_BITS+3)
  155827. & RANGE_MASK];
  155828. outptr[1] = range_limit[(int) DESCALE(tmp11 + tmp2,
  155829. CONST_BITS+PASS1_BITS+3)
  155830. & RANGE_MASK];
  155831. outptr[6] = range_limit[(int) DESCALE(tmp11 - tmp2,
  155832. CONST_BITS+PASS1_BITS+3)
  155833. & RANGE_MASK];
  155834. outptr[2] = range_limit[(int) DESCALE(tmp12 + tmp1,
  155835. CONST_BITS+PASS1_BITS+3)
  155836. & RANGE_MASK];
  155837. outptr[5] = range_limit[(int) DESCALE(tmp12 - tmp1,
  155838. CONST_BITS+PASS1_BITS+3)
  155839. & RANGE_MASK];
  155840. outptr[3] = range_limit[(int) DESCALE(tmp13 + tmp0,
  155841. CONST_BITS+PASS1_BITS+3)
  155842. & RANGE_MASK];
  155843. outptr[4] = range_limit[(int) DESCALE(tmp13 - tmp0,
  155844. CONST_BITS+PASS1_BITS+3)
  155845. & RANGE_MASK];
  155846. wsptr += DCTSIZE; /* advance pointer to next row */
  155847. }
  155848. }
  155849. #endif /* DCT_ISLOW_SUPPORTED */
  155850. /*** End of inlined file: jidctint.c ***/
  155851. /*** Start of inlined file: jidctred.c ***/
  155852. #define JPEG_INTERNALS
  155853. #ifdef IDCT_SCALING_SUPPORTED
  155854. #if DCTSIZE != 8
  155855. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155856. #endif
  155857. #if BITS_IN_JSAMPLE == 8
  155858. #define CONST_BITS 13
  155859. #define PASS1_BITS 2
  155860. #else
  155861. #define CONST_BITS 13
  155862. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  155863. #endif
  155864. #if CONST_BITS == 13
  155865. #define FIX_0_211164243 ((INT32) 1730) /* FIX(0.211164243) */
  155866. #define FIX_0_509795579 ((INT32) 4176) /* FIX(0.509795579) */
  155867. #define FIX_0_601344887 ((INT32) 4926) /* FIX(0.601344887) */
  155868. #define FIX_0_720959822 ((INT32) 5906) /* FIX(0.720959822) */
  155869. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  155870. #define FIX_0_850430095 ((INT32) 6967) /* FIX(0.850430095) */
  155871. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  155872. #define FIX_1_061594337 ((INT32) 8697) /* FIX(1.061594337) */
  155873. #define FIX_1_272758580 ((INT32) 10426) /* FIX(1.272758580) */
  155874. #define FIX_1_451774981 ((INT32) 11893) /* FIX(1.451774981) */
  155875. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  155876. #define FIX_2_172734803 ((INT32) 17799) /* FIX(2.172734803) */
  155877. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  155878. #define FIX_3_624509785 ((INT32) 29692) /* FIX(3.624509785) */
  155879. #else
  155880. #define FIX_0_211164243 FIX(0.211164243)
  155881. #define FIX_0_509795579 FIX(0.509795579)
  155882. #define FIX_0_601344887 FIX(0.601344887)
  155883. #define FIX_0_720959822 FIX(0.720959822)
  155884. #define FIX_0_765366865 FIX(0.765366865)
  155885. #define FIX_0_850430095 FIX(0.850430095)
  155886. #define FIX_0_899976223 FIX(0.899976223)
  155887. #define FIX_1_061594337 FIX(1.061594337)
  155888. #define FIX_1_272758580 FIX(1.272758580)
  155889. #define FIX_1_451774981 FIX(1.451774981)
  155890. #define FIX_1_847759065 FIX(1.847759065)
  155891. #define FIX_2_172734803 FIX(2.172734803)
  155892. #define FIX_2_562915447 FIX(2.562915447)
  155893. #define FIX_3_624509785 FIX(3.624509785)
  155894. #endif
  155895. #if BITS_IN_JSAMPLE == 8
  155896. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  155897. #else
  155898. #define MULTIPLY(var,const) ((var) * (const))
  155899. #endif
  155900. #define DEQUANTIZE(coef,quantval) (((ISLOW_MULT_TYPE) (coef)) * (quantval))
  155901. GLOBAL(void)
  155902. jpeg_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155903. JCOEFPTR coef_block,
  155904. JSAMPARRAY output_buf, JDIMENSION output_col)
  155905. {
  155906. INT32 tmp0, tmp2, tmp10, tmp12;
  155907. INT32 z1, z2, z3, z4;
  155908. JCOEFPTR inptr;
  155909. ISLOW_MULT_TYPE * quantptr;
  155910. int * wsptr;
  155911. JSAMPROW outptr;
  155912. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155913. int ctr;
  155914. int workspace[DCTSIZE*4]; /* buffers data between passes */
  155915. SHIFT_TEMPS
  155916. inptr = coef_block;
  155917. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  155918. wsptr = workspace;
  155919. for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) {
  155920. if (ctr == DCTSIZE-4)
  155921. continue;
  155922. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  155923. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*5] == 0 &&
  155924. inptr[DCTSIZE*6] == 0 && inptr[DCTSIZE*7] == 0) {
  155925. int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
  155926. wsptr[DCTSIZE*0] = dcval;
  155927. wsptr[DCTSIZE*1] = dcval;
  155928. wsptr[DCTSIZE*2] = dcval;
  155929. wsptr[DCTSIZE*3] = dcval;
  155930. continue;
  155931. }
  155932. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155933. tmp0 <<= (CONST_BITS+1);
  155934. z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  155935. z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  155936. tmp2 = MULTIPLY(z2, FIX_1_847759065) + MULTIPLY(z3, - FIX_0_765366865);
  155937. tmp10 = tmp0 + tmp2;
  155938. tmp12 = tmp0 - tmp2;
  155939. z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155940. z2 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155941. z3 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155942. z4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155943. tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */
  155944. + MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */
  155945. + MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */
  155946. + MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */
  155947. tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */
  155948. + MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */
  155949. + MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */
  155950. + MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */
  155951. wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp2, CONST_BITS-PASS1_BITS+1);
  155952. wsptr[DCTSIZE*3] = (int) DESCALE(tmp10 - tmp2, CONST_BITS-PASS1_BITS+1);
  155953. wsptr[DCTSIZE*1] = (int) DESCALE(tmp12 + tmp0, CONST_BITS-PASS1_BITS+1);
  155954. wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 - tmp0, CONST_BITS-PASS1_BITS+1);
  155955. }
  155956. wsptr = workspace;
  155957. for (ctr = 0; ctr < 4; ctr++) {
  155958. outptr = output_buf[ctr] + output_col;
  155959. #ifndef NO_ZERO_ROW_TEST
  155960. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 &&
  155961. wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
  155962. JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
  155963. & RANGE_MASK];
  155964. outptr[0] = dcval;
  155965. outptr[1] = dcval;
  155966. outptr[2] = dcval;
  155967. outptr[3] = dcval;
  155968. wsptr += DCTSIZE; /* advance pointer to next row */
  155969. continue;
  155970. }
  155971. #endif
  155972. tmp0 = ((INT32) wsptr[0]) << (CONST_BITS+1);
  155973. tmp2 = MULTIPLY((INT32) wsptr[2], FIX_1_847759065)
  155974. + MULTIPLY((INT32) wsptr[6], - FIX_0_765366865);
  155975. tmp10 = tmp0 + tmp2;
  155976. tmp12 = tmp0 - tmp2;
  155977. z1 = (INT32) wsptr[7];
  155978. z2 = (INT32) wsptr[5];
  155979. z3 = (INT32) wsptr[3];
  155980. z4 = (INT32) wsptr[1];
  155981. tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */
  155982. + MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */
  155983. + MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */
  155984. + MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */
  155985. tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */
  155986. + MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */
  155987. + MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */
  155988. + MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */
  155989. outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp2,
  155990. CONST_BITS+PASS1_BITS+3+1)
  155991. & RANGE_MASK];
  155992. outptr[3] = range_limit[(int) DESCALE(tmp10 - tmp2,
  155993. CONST_BITS+PASS1_BITS+3+1)
  155994. & RANGE_MASK];
  155995. outptr[1] = range_limit[(int) DESCALE(tmp12 + tmp0,
  155996. CONST_BITS+PASS1_BITS+3+1)
  155997. & RANGE_MASK];
  155998. outptr[2] = range_limit[(int) DESCALE(tmp12 - tmp0,
  155999. CONST_BITS+PASS1_BITS+3+1)
  156000. & RANGE_MASK];
  156001. wsptr += DCTSIZE; /* advance pointer to next row */
  156002. }
  156003. }
  156004. GLOBAL(void)
  156005. jpeg_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  156006. JCOEFPTR coef_block,
  156007. JSAMPARRAY output_buf, JDIMENSION output_col)
  156008. {
  156009. INT32 tmp0, tmp10, z1;
  156010. JCOEFPTR inptr;
  156011. ISLOW_MULT_TYPE * quantptr;
  156012. int * wsptr;
  156013. JSAMPROW outptr;
  156014. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  156015. int ctr;
  156016. int workspace[DCTSIZE*2]; /* buffers data between passes */
  156017. SHIFT_TEMPS
  156018. inptr = coef_block;
  156019. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  156020. wsptr = workspace;
  156021. for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) {
  156022. if (ctr == DCTSIZE-2 || ctr == DCTSIZE-4 || ctr == DCTSIZE-6)
  156023. continue;
  156024. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*3] == 0 &&
  156025. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*7] == 0) {
  156026. int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
  156027. wsptr[DCTSIZE*0] = dcval;
  156028. wsptr[DCTSIZE*1] = dcval;
  156029. continue;
  156030. }
  156031. z1 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  156032. tmp10 = z1 << (CONST_BITS+2);
  156033. z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  156034. tmp0 = MULTIPLY(z1, - FIX_0_720959822); /* sqrt(2) * (c7-c5+c3-c1) */
  156035. z1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  156036. tmp0 += MULTIPLY(z1, FIX_0_850430095); /* sqrt(2) * (-c1+c3+c5+c7) */
  156037. z1 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  156038. tmp0 += MULTIPLY(z1, - FIX_1_272758580); /* sqrt(2) * (-c1+c3-c5-c7) */
  156039. z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  156040. tmp0 += MULTIPLY(z1, FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */
  156041. wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp0, CONST_BITS-PASS1_BITS+2);
  156042. wsptr[DCTSIZE*1] = (int) DESCALE(tmp10 - tmp0, CONST_BITS-PASS1_BITS+2);
  156043. }
  156044. wsptr = workspace;
  156045. for (ctr = 0; ctr < 2; ctr++) {
  156046. outptr = output_buf[ctr] + output_col;
  156047. #ifndef NO_ZERO_ROW_TEST
  156048. if (wsptr[1] == 0 && wsptr[3] == 0 && wsptr[5] == 0 && wsptr[7] == 0) {
  156049. JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
  156050. & RANGE_MASK];
  156051. outptr[0] = dcval;
  156052. outptr[1] = dcval;
  156053. wsptr += DCTSIZE; /* advance pointer to next row */
  156054. continue;
  156055. }
  156056. #endif
  156057. tmp10 = ((INT32) wsptr[0]) << (CONST_BITS+2);
  156058. tmp0 = MULTIPLY((INT32) wsptr[7], - FIX_0_720959822) /* sqrt(2) * (c7-c5+c3-c1) */
  156059. + MULTIPLY((INT32) wsptr[5], FIX_0_850430095) /* sqrt(2) * (-c1+c3+c5+c7) */
  156060. + MULTIPLY((INT32) wsptr[3], - FIX_1_272758580) /* sqrt(2) * (-c1+c3-c5-c7) */
  156061. + MULTIPLY((INT32) wsptr[1], FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */
  156062. outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp0,
  156063. CONST_BITS+PASS1_BITS+3+2)
  156064. & RANGE_MASK];
  156065. outptr[1] = range_limit[(int) DESCALE(tmp10 - tmp0,
  156066. CONST_BITS+PASS1_BITS+3+2)
  156067. & RANGE_MASK];
  156068. wsptr += DCTSIZE; /* advance pointer to next row */
  156069. }
  156070. }
  156071. GLOBAL(void)
  156072. jpeg_idct_1x1 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  156073. JCOEFPTR coef_block,
  156074. JSAMPARRAY output_buf, JDIMENSION output_col)
  156075. {
  156076. int dcval;
  156077. ISLOW_MULT_TYPE * quantptr;
  156078. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  156079. SHIFT_TEMPS
  156080. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  156081. dcval = DEQUANTIZE(coef_block[0], quantptr[0]);
  156082. dcval = (int) DESCALE((INT32) dcval, 3);
  156083. output_buf[0][output_col] = range_limit[dcval & RANGE_MASK];
  156084. }
  156085. #endif /* IDCT_SCALING_SUPPORTED */
  156086. /*** End of inlined file: jidctred.c ***/
  156087. /*** Start of inlined file: jmemmgr.c ***/
  156088. #define JPEG_INTERNALS
  156089. #define AM_MEMORY_MANAGER /* we define jvirt_Xarray_control structs */
  156090. /*** Start of inlined file: jmemsys.h ***/
  156091. #ifndef __jmemsys_h__
  156092. #define __jmemsys_h__
  156093. #ifdef NEED_SHORT_EXTERNAL_NAMES
  156094. #define jpeg_get_small jGetSmall
  156095. #define jpeg_free_small jFreeSmall
  156096. #define jpeg_get_large jGetLarge
  156097. #define jpeg_free_large jFreeLarge
  156098. #define jpeg_mem_available jMemAvail
  156099. #define jpeg_open_backing_store jOpenBackStore
  156100. #define jpeg_mem_init jMemInit
  156101. #define jpeg_mem_term jMemTerm
  156102. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  156103. EXTERN(void *) jpeg_get_small JPP((j_common_ptr cinfo, size_t sizeofobject));
  156104. EXTERN(void) jpeg_free_small JPP((j_common_ptr cinfo, void * object,
  156105. size_t sizeofobject));
  156106. EXTERN(void FAR *) jpeg_get_large JPP((j_common_ptr cinfo,
  156107. size_t sizeofobject));
  156108. EXTERN(void) jpeg_free_large JPP((j_common_ptr cinfo, void FAR * object,
  156109. size_t sizeofobject));
  156110. #ifndef MAX_ALLOC_CHUNK /* may be overridden in jconfig.h */
  156111. #define MAX_ALLOC_CHUNK 1000000000L
  156112. #endif
  156113. EXTERN(long) jpeg_mem_available JPP((j_common_ptr cinfo,
  156114. long min_bytes_needed,
  156115. long max_bytes_needed,
  156116. long already_allocated));
  156117. #define TEMP_NAME_LENGTH 64 /* max length of a temporary file's name */
  156118. #ifdef USE_MSDOS_MEMMGR /* DOS-specific junk */
  156119. typedef unsigned short XMSH; /* type of extended-memory handles */
  156120. typedef unsigned short EMSH; /* type of expanded-memory handles */
  156121. typedef union {
  156122. short file_handle; /* DOS file handle if it's a temp file */
  156123. XMSH xms_handle; /* handle if it's a chunk of XMS */
  156124. EMSH ems_handle; /* handle if it's a chunk of EMS */
  156125. } handle_union;
  156126. #endif /* USE_MSDOS_MEMMGR */
  156127. #ifdef USE_MAC_MEMMGR /* Mac-specific junk */
  156128. #include <Files.h>
  156129. #endif /* USE_MAC_MEMMGR */
  156130. //typedef struct backing_store_struct * backing_store_ptr;
  156131. typedef struct backing_store_struct {
  156132. JMETHOD(void, read_backing_store, (j_common_ptr cinfo,
  156133. struct backing_store_struct *info,
  156134. void FAR * buffer_address,
  156135. long file_offset, long byte_count));
  156136. JMETHOD(void, write_backing_store, (j_common_ptr cinfo,
  156137. struct backing_store_struct *info,
  156138. void FAR * buffer_address,
  156139. long file_offset, long byte_count));
  156140. JMETHOD(void, close_backing_store, (j_common_ptr cinfo,
  156141. struct backing_store_struct *info));
  156142. #ifdef USE_MSDOS_MEMMGR
  156143. handle_union handle; /* reference to backing-store storage object */
  156144. char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */
  156145. #else
  156146. #ifdef USE_MAC_MEMMGR
  156147. short temp_file; /* file reference number to temp file */
  156148. FSSpec tempSpec; /* the FSSpec for the temp file */
  156149. char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */
  156150. #else
  156151. FILE * temp_file; /* stdio reference to temp file */
  156152. char temp_name[TEMP_NAME_LENGTH]; /* name of temp file */
  156153. #endif
  156154. #endif
  156155. } backing_store_info;
  156156. EXTERN(void) jpeg_open_backing_store JPP((j_common_ptr cinfo,
  156157. struct backing_store_struct *info,
  156158. long total_bytes_needed));
  156159. EXTERN(long) jpeg_mem_init JPP((j_common_ptr cinfo));
  156160. EXTERN(void) jpeg_mem_term JPP((j_common_ptr cinfo));
  156161. #endif
  156162. /*** End of inlined file: jmemsys.h ***/
  156163. /* import the system-dependent declarations */
  156164. #ifndef NO_GETENV
  156165. #ifndef HAVE_STDLIB_H /* <stdlib.h> should declare getenv() */
  156166. extern char * getenv JPP((const char * name));
  156167. #endif
  156168. #endif
  156169. #ifndef ALIGN_TYPE /* so can override from jconfig.h */
  156170. #define ALIGN_TYPE double
  156171. #endif
  156172. typedef union small_pool_struct * small_pool_ptr;
  156173. typedef union small_pool_struct {
  156174. struct {
  156175. small_pool_ptr next; /* next in list of pools */
  156176. size_t bytes_used; /* how many bytes already used within pool */
  156177. size_t bytes_left; /* bytes still available in this pool */
  156178. } hdr;
  156179. ALIGN_TYPE dummy; /* included in union to ensure alignment */
  156180. } small_pool_hdr;
  156181. typedef union large_pool_struct FAR * large_pool_ptr;
  156182. typedef union large_pool_struct {
  156183. struct {
  156184. large_pool_ptr next; /* next in list of pools */
  156185. size_t bytes_used; /* how many bytes already used within pool */
  156186. size_t bytes_left; /* bytes still available in this pool */
  156187. } hdr;
  156188. ALIGN_TYPE dummy; /* included in union to ensure alignment */
  156189. } large_pool_hdr;
  156190. typedef struct {
  156191. struct jpeg_memory_mgr pub; /* public fields */
  156192. small_pool_ptr small_list[JPOOL_NUMPOOLS];
  156193. large_pool_ptr large_list[JPOOL_NUMPOOLS];
  156194. jvirt_sarray_ptr virt_sarray_list;
  156195. jvirt_barray_ptr virt_barray_list;
  156196. long total_space_allocated;
  156197. JDIMENSION last_rowsperchunk; /* from most recent alloc_sarray/barray */
  156198. } my_memory_mgr;
  156199. typedef my_memory_mgr * my_mem_ptr;
  156200. struct jvirt_sarray_control {
  156201. JSAMPARRAY mem_buffer; /* => the in-memory buffer */
  156202. JDIMENSION rows_in_array; /* total virtual array height */
  156203. JDIMENSION samplesperrow; /* width of array (and of memory buffer) */
  156204. JDIMENSION maxaccess; /* max rows accessed by access_virt_sarray */
  156205. JDIMENSION rows_in_mem; /* height of memory buffer */
  156206. JDIMENSION rowsperchunk; /* allocation chunk size in mem_buffer */
  156207. JDIMENSION cur_start_row; /* first logical row # in the buffer */
  156208. JDIMENSION first_undef_row; /* row # of first uninitialized row */
  156209. boolean pre_zero; /* pre-zero mode requested? */
  156210. boolean dirty; /* do current buffer contents need written? */
  156211. boolean b_s_open; /* is backing-store data valid? */
  156212. jvirt_sarray_ptr next; /* link to next virtual sarray control block */
  156213. backing_store_info b_s_info; /* System-dependent control info */
  156214. };
  156215. struct jvirt_barray_control {
  156216. JBLOCKARRAY mem_buffer; /* => the in-memory buffer */
  156217. JDIMENSION rows_in_array; /* total virtual array height */
  156218. JDIMENSION blocksperrow; /* width of array (and of memory buffer) */
  156219. JDIMENSION maxaccess; /* max rows accessed by access_virt_barray */
  156220. JDIMENSION rows_in_mem; /* height of memory buffer */
  156221. JDIMENSION rowsperchunk; /* allocation chunk size in mem_buffer */
  156222. JDIMENSION cur_start_row; /* first logical row # in the buffer */
  156223. JDIMENSION first_undef_row; /* row # of first uninitialized row */
  156224. boolean pre_zero; /* pre-zero mode requested? */
  156225. boolean dirty; /* do current buffer contents need written? */
  156226. boolean b_s_open; /* is backing-store data valid? */
  156227. jvirt_barray_ptr next; /* link to next virtual barray control block */
  156228. backing_store_info b_s_info; /* System-dependent control info */
  156229. };
  156230. #ifdef MEM_STATS /* optional extra stuff for statistics */
  156231. LOCAL(void)
  156232. print_mem_stats (j_common_ptr cinfo, int pool_id)
  156233. {
  156234. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156235. small_pool_ptr shdr_ptr;
  156236. large_pool_ptr lhdr_ptr;
  156237. fprintf(stderr, "Freeing pool %d, total space = %ld\n",
  156238. pool_id, mem->total_space_allocated);
  156239. for (lhdr_ptr = mem->large_list[pool_id]; lhdr_ptr != NULL;
  156240. lhdr_ptr = lhdr_ptr->hdr.next) {
  156241. fprintf(stderr, " Large chunk used %ld\n",
  156242. (long) lhdr_ptr->hdr.bytes_used);
  156243. }
  156244. for (shdr_ptr = mem->small_list[pool_id]; shdr_ptr != NULL;
  156245. shdr_ptr = shdr_ptr->hdr.next) {
  156246. fprintf(stderr, " Small chunk used %ld free %ld\n",
  156247. (long) shdr_ptr->hdr.bytes_used,
  156248. (long) shdr_ptr->hdr.bytes_left);
  156249. }
  156250. }
  156251. #endif /* MEM_STATS */
  156252. LOCAL(void)
  156253. out_of_memory (j_common_ptr cinfo, int which)
  156254. {
  156255. #ifdef MEM_STATS
  156256. cinfo->err->trace_level = 2; /* force self_destruct to report stats */
  156257. #endif
  156258. ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, which);
  156259. }
  156260. static const size_t first_pool_slop[JPOOL_NUMPOOLS] =
  156261. {
  156262. 1600, /* first PERMANENT pool */
  156263. 16000 /* first IMAGE pool */
  156264. };
  156265. static const size_t extra_pool_slop[JPOOL_NUMPOOLS] =
  156266. {
  156267. 0, /* additional PERMANENT pools */
  156268. 5000 /* additional IMAGE pools */
  156269. };
  156270. #define MIN_SLOP 50 /* greater than 0 to avoid futile looping */
  156271. METHODDEF(void *)
  156272. alloc_small (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
  156273. {
  156274. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156275. small_pool_ptr hdr_ptr, prev_hdr_ptr;
  156276. char * data_ptr;
  156277. size_t odd_bytes, min_request, slop;
  156278. if (sizeofobject > (size_t) (MAX_ALLOC_CHUNK-SIZEOF(small_pool_hdr)))
  156279. out_of_memory(cinfo, 1); /* request exceeds malloc's ability */
  156280. odd_bytes = sizeofobject % SIZEOF(ALIGN_TYPE);
  156281. if (odd_bytes > 0)
  156282. sizeofobject += SIZEOF(ALIGN_TYPE) - odd_bytes;
  156283. if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
  156284. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156285. prev_hdr_ptr = NULL;
  156286. hdr_ptr = mem->small_list[pool_id];
  156287. while (hdr_ptr != NULL) {
  156288. if (hdr_ptr->hdr.bytes_left >= sizeofobject)
  156289. break; /* found pool with enough space */
  156290. prev_hdr_ptr = hdr_ptr;
  156291. hdr_ptr = hdr_ptr->hdr.next;
  156292. }
  156293. if (hdr_ptr == NULL) {
  156294. min_request = sizeofobject + SIZEOF(small_pool_hdr);
  156295. if (prev_hdr_ptr == NULL) /* first pool in class? */
  156296. slop = first_pool_slop[pool_id];
  156297. else
  156298. slop = extra_pool_slop[pool_id];
  156299. if (slop > (size_t) (MAX_ALLOC_CHUNK-min_request))
  156300. slop = (size_t) (MAX_ALLOC_CHUNK-min_request);
  156301. for (;;) {
  156302. hdr_ptr = (small_pool_ptr) jpeg_get_small(cinfo, min_request + slop);
  156303. if (hdr_ptr != NULL)
  156304. break;
  156305. slop /= 2;
  156306. if (slop < MIN_SLOP) /* give up when it gets real small */
  156307. out_of_memory(cinfo, 2); /* jpeg_get_small failed */
  156308. }
  156309. mem->total_space_allocated += min_request + slop;
  156310. hdr_ptr->hdr.next = NULL;
  156311. hdr_ptr->hdr.bytes_used = 0;
  156312. hdr_ptr->hdr.bytes_left = sizeofobject + slop;
  156313. if (prev_hdr_ptr == NULL) /* first pool in class? */
  156314. mem->small_list[pool_id] = hdr_ptr;
  156315. else
  156316. prev_hdr_ptr->hdr.next = hdr_ptr;
  156317. }
  156318. data_ptr = (char *) (hdr_ptr + 1); /* point to first data byte in pool */
  156319. data_ptr += hdr_ptr->hdr.bytes_used; /* point to place for object */
  156320. hdr_ptr->hdr.bytes_used += sizeofobject;
  156321. hdr_ptr->hdr.bytes_left -= sizeofobject;
  156322. return (void *) data_ptr;
  156323. }
  156324. METHODDEF(void FAR *)
  156325. alloc_large (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
  156326. {
  156327. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156328. large_pool_ptr hdr_ptr;
  156329. size_t odd_bytes;
  156330. if (sizeofobject > (size_t) (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)))
  156331. out_of_memory(cinfo, 3); /* request exceeds malloc's ability */
  156332. odd_bytes = sizeofobject % SIZEOF(ALIGN_TYPE);
  156333. if (odd_bytes > 0)
  156334. sizeofobject += SIZEOF(ALIGN_TYPE) - odd_bytes;
  156335. if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
  156336. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156337. hdr_ptr = (large_pool_ptr) jpeg_get_large(cinfo, sizeofobject +
  156338. SIZEOF(large_pool_hdr));
  156339. if (hdr_ptr == NULL)
  156340. out_of_memory(cinfo, 4); /* jpeg_get_large failed */
  156341. mem->total_space_allocated += sizeofobject + SIZEOF(large_pool_hdr);
  156342. hdr_ptr->hdr.next = mem->large_list[pool_id];
  156343. hdr_ptr->hdr.bytes_used = sizeofobject;
  156344. hdr_ptr->hdr.bytes_left = 0;
  156345. mem->large_list[pool_id] = hdr_ptr;
  156346. return (void FAR *) (hdr_ptr + 1); /* point to first data byte in pool */
  156347. }
  156348. METHODDEF(JSAMPARRAY)
  156349. alloc_sarray (j_common_ptr cinfo, int pool_id,
  156350. JDIMENSION samplesperrow, JDIMENSION numrows)
  156351. {
  156352. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156353. JSAMPARRAY result;
  156354. JSAMPROW workspace;
  156355. JDIMENSION rowsperchunk, currow, i;
  156356. long ltemp;
  156357. ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /
  156358. ((long) samplesperrow * SIZEOF(JSAMPLE));
  156359. if (ltemp <= 0)
  156360. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  156361. if (ltemp < (long) numrows)
  156362. rowsperchunk = (JDIMENSION) ltemp;
  156363. else
  156364. rowsperchunk = numrows;
  156365. mem->last_rowsperchunk = rowsperchunk;
  156366. result = (JSAMPARRAY) alloc_small(cinfo, pool_id,
  156367. (size_t) (numrows * SIZEOF(JSAMPROW)));
  156368. currow = 0;
  156369. while (currow < numrows) {
  156370. rowsperchunk = MIN(rowsperchunk, numrows - currow);
  156371. workspace = (JSAMPROW) alloc_large(cinfo, pool_id,
  156372. (size_t) ((size_t) rowsperchunk * (size_t) samplesperrow
  156373. * SIZEOF(JSAMPLE)));
  156374. for (i = rowsperchunk; i > 0; i--) {
  156375. result[currow++] = workspace;
  156376. workspace += samplesperrow;
  156377. }
  156378. }
  156379. return result;
  156380. }
  156381. METHODDEF(JBLOCKARRAY)
  156382. alloc_barray (j_common_ptr cinfo, int pool_id,
  156383. JDIMENSION blocksperrow, JDIMENSION numrows)
  156384. {
  156385. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156386. JBLOCKARRAY result;
  156387. JBLOCKROW workspace;
  156388. JDIMENSION rowsperchunk, currow, i;
  156389. long ltemp;
  156390. ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /
  156391. ((long) blocksperrow * SIZEOF(JBLOCK));
  156392. if (ltemp <= 0)
  156393. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  156394. if (ltemp < (long) numrows)
  156395. rowsperchunk = (JDIMENSION) ltemp;
  156396. else
  156397. rowsperchunk = numrows;
  156398. mem->last_rowsperchunk = rowsperchunk;
  156399. result = (JBLOCKARRAY) alloc_small(cinfo, pool_id,
  156400. (size_t) (numrows * SIZEOF(JBLOCKROW)));
  156401. currow = 0;
  156402. while (currow < numrows) {
  156403. rowsperchunk = MIN(rowsperchunk, numrows - currow);
  156404. workspace = (JBLOCKROW) alloc_large(cinfo, pool_id,
  156405. (size_t) ((size_t) rowsperchunk * (size_t) blocksperrow
  156406. * SIZEOF(JBLOCK)));
  156407. for (i = rowsperchunk; i > 0; i--) {
  156408. result[currow++] = workspace;
  156409. workspace += blocksperrow;
  156410. }
  156411. }
  156412. return result;
  156413. }
  156414. METHODDEF(jvirt_sarray_ptr)
  156415. request_virt_sarray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
  156416. JDIMENSION samplesperrow, JDIMENSION numrows,
  156417. JDIMENSION maxaccess)
  156418. {
  156419. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156420. jvirt_sarray_ptr result;
  156421. if (pool_id != JPOOL_IMAGE)
  156422. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156423. result = (jvirt_sarray_ptr) alloc_small(cinfo, pool_id,
  156424. SIZEOF(struct jvirt_sarray_control));
  156425. result->mem_buffer = NULL; /* marks array not yet realized */
  156426. result->rows_in_array = numrows;
  156427. result->samplesperrow = samplesperrow;
  156428. result->maxaccess = maxaccess;
  156429. result->pre_zero = pre_zero;
  156430. result->b_s_open = FALSE; /* no associated backing-store object */
  156431. result->next = mem->virt_sarray_list; /* add to list of virtual arrays */
  156432. mem->virt_sarray_list = result;
  156433. return result;
  156434. }
  156435. METHODDEF(jvirt_barray_ptr)
  156436. request_virt_barray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
  156437. JDIMENSION blocksperrow, JDIMENSION numrows,
  156438. JDIMENSION maxaccess)
  156439. {
  156440. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156441. jvirt_barray_ptr result;
  156442. if (pool_id != JPOOL_IMAGE)
  156443. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156444. result = (jvirt_barray_ptr) alloc_small(cinfo, pool_id,
  156445. SIZEOF(struct jvirt_barray_control));
  156446. result->mem_buffer = NULL; /* marks array not yet realized */
  156447. result->rows_in_array = numrows;
  156448. result->blocksperrow = blocksperrow;
  156449. result->maxaccess = maxaccess;
  156450. result->pre_zero = pre_zero;
  156451. result->b_s_open = FALSE; /* no associated backing-store object */
  156452. result->next = mem->virt_barray_list; /* add to list of virtual arrays */
  156453. mem->virt_barray_list = result;
  156454. return result;
  156455. }
  156456. METHODDEF(void)
  156457. realize_virt_arrays (j_common_ptr cinfo)
  156458. {
  156459. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156460. long space_per_minheight, maximum_space, avail_mem;
  156461. long minheights, max_minheights;
  156462. jvirt_sarray_ptr sptr;
  156463. jvirt_barray_ptr bptr;
  156464. space_per_minheight = 0;
  156465. maximum_space = 0;
  156466. for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
  156467. if (sptr->mem_buffer == NULL) { /* if not realized yet */
  156468. space_per_minheight += (long) sptr->maxaccess *
  156469. (long) sptr->samplesperrow * SIZEOF(JSAMPLE);
  156470. maximum_space += (long) sptr->rows_in_array *
  156471. (long) sptr->samplesperrow * SIZEOF(JSAMPLE);
  156472. }
  156473. }
  156474. for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
  156475. if (bptr->mem_buffer == NULL) { /* if not realized yet */
  156476. space_per_minheight += (long) bptr->maxaccess *
  156477. (long) bptr->blocksperrow * SIZEOF(JBLOCK);
  156478. maximum_space += (long) bptr->rows_in_array *
  156479. (long) bptr->blocksperrow * SIZEOF(JBLOCK);
  156480. }
  156481. }
  156482. if (space_per_minheight <= 0)
  156483. return; /* no unrealized arrays, no work */
  156484. avail_mem = jpeg_mem_available(cinfo, space_per_minheight, maximum_space,
  156485. mem->total_space_allocated);
  156486. if (avail_mem >= maximum_space)
  156487. max_minheights = 1000000000L;
  156488. else {
  156489. max_minheights = avail_mem / space_per_minheight;
  156490. if (max_minheights <= 0)
  156491. max_minheights = 1;
  156492. }
  156493. for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
  156494. if (sptr->mem_buffer == NULL) { /* if not realized yet */
  156495. minheights = ((long) sptr->rows_in_array - 1L) / sptr->maxaccess + 1L;
  156496. if (minheights <= max_minheights) {
  156497. sptr->rows_in_mem = sptr->rows_in_array;
  156498. } else {
  156499. sptr->rows_in_mem = (JDIMENSION) (max_minheights * sptr->maxaccess);
  156500. jpeg_open_backing_store(cinfo, & sptr->b_s_info,
  156501. (long) sptr->rows_in_array *
  156502. (long) sptr->samplesperrow *
  156503. (long) SIZEOF(JSAMPLE));
  156504. sptr->b_s_open = TRUE;
  156505. }
  156506. sptr->mem_buffer = alloc_sarray(cinfo, JPOOL_IMAGE,
  156507. sptr->samplesperrow, sptr->rows_in_mem);
  156508. sptr->rowsperchunk = mem->last_rowsperchunk;
  156509. sptr->cur_start_row = 0;
  156510. sptr->first_undef_row = 0;
  156511. sptr->dirty = FALSE;
  156512. }
  156513. }
  156514. for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
  156515. if (bptr->mem_buffer == NULL) { /* if not realized yet */
  156516. minheights = ((long) bptr->rows_in_array - 1L) / bptr->maxaccess + 1L;
  156517. if (minheights <= max_minheights) {
  156518. bptr->rows_in_mem = bptr->rows_in_array;
  156519. } else {
  156520. bptr->rows_in_mem = (JDIMENSION) (max_minheights * bptr->maxaccess);
  156521. jpeg_open_backing_store(cinfo, & bptr->b_s_info,
  156522. (long) bptr->rows_in_array *
  156523. (long) bptr->blocksperrow *
  156524. (long) SIZEOF(JBLOCK));
  156525. bptr->b_s_open = TRUE;
  156526. }
  156527. bptr->mem_buffer = alloc_barray(cinfo, JPOOL_IMAGE,
  156528. bptr->blocksperrow, bptr->rows_in_mem);
  156529. bptr->rowsperchunk = mem->last_rowsperchunk;
  156530. bptr->cur_start_row = 0;
  156531. bptr->first_undef_row = 0;
  156532. bptr->dirty = FALSE;
  156533. }
  156534. }
  156535. }
  156536. LOCAL(void)
  156537. do_sarray_io (j_common_ptr cinfo, jvirt_sarray_ptr ptr, boolean writing)
  156538. {
  156539. long bytesperrow, file_offset, byte_count, rows, thisrow, i;
  156540. bytesperrow = (long) ptr->samplesperrow * SIZEOF(JSAMPLE);
  156541. file_offset = ptr->cur_start_row * bytesperrow;
  156542. for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) {
  156543. rows = MIN((long) ptr->rowsperchunk, (long) ptr->rows_in_mem - i);
  156544. thisrow = (long) ptr->cur_start_row + i;
  156545. rows = MIN(rows, (long) ptr->first_undef_row - thisrow);
  156546. rows = MIN(rows, (long) ptr->rows_in_array - thisrow);
  156547. if (rows <= 0) /* this chunk might be past end of file! */
  156548. break;
  156549. byte_count = rows * bytesperrow;
  156550. if (writing)
  156551. (*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info,
  156552. (void FAR *) ptr->mem_buffer[i],
  156553. file_offset, byte_count);
  156554. else
  156555. (*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info,
  156556. (void FAR *) ptr->mem_buffer[i],
  156557. file_offset, byte_count);
  156558. file_offset += byte_count;
  156559. }
  156560. }
  156561. LOCAL(void)
  156562. do_barray_io (j_common_ptr cinfo, jvirt_barray_ptr ptr, boolean writing)
  156563. {
  156564. long bytesperrow, file_offset, byte_count, rows, thisrow, i;
  156565. bytesperrow = (long) ptr->blocksperrow * SIZEOF(JBLOCK);
  156566. file_offset = ptr->cur_start_row * bytesperrow;
  156567. for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) {
  156568. rows = MIN((long) ptr->rowsperchunk, (long) ptr->rows_in_mem - i);
  156569. thisrow = (long) ptr->cur_start_row + i;
  156570. rows = MIN(rows, (long) ptr->first_undef_row - thisrow);
  156571. rows = MIN(rows, (long) ptr->rows_in_array - thisrow);
  156572. if (rows <= 0) /* this chunk might be past end of file! */
  156573. break;
  156574. byte_count = rows * bytesperrow;
  156575. if (writing)
  156576. (*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info,
  156577. (void FAR *) ptr->mem_buffer[i],
  156578. file_offset, byte_count);
  156579. else
  156580. (*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info,
  156581. (void FAR *) ptr->mem_buffer[i],
  156582. file_offset, byte_count);
  156583. file_offset += byte_count;
  156584. }
  156585. }
  156586. METHODDEF(JSAMPARRAY)
  156587. access_virt_sarray (j_common_ptr cinfo, jvirt_sarray_ptr ptr,
  156588. JDIMENSION start_row, JDIMENSION num_rows,
  156589. boolean writable)
  156590. {
  156591. JDIMENSION end_row = start_row + num_rows;
  156592. JDIMENSION undef_row;
  156593. if (end_row > ptr->rows_in_array || num_rows > ptr->maxaccess ||
  156594. ptr->mem_buffer == NULL)
  156595. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156596. if (start_row < ptr->cur_start_row ||
  156597. end_row > ptr->cur_start_row+ptr->rows_in_mem) {
  156598. if (! ptr->b_s_open)
  156599. ERREXIT(cinfo, JERR_VIRTUAL_BUG);
  156600. if (ptr->dirty) {
  156601. do_sarray_io(cinfo, ptr, TRUE);
  156602. ptr->dirty = FALSE;
  156603. }
  156604. if (start_row > ptr->cur_start_row) {
  156605. ptr->cur_start_row = start_row;
  156606. } else {
  156607. long ltemp;
  156608. ltemp = (long) end_row - (long) ptr->rows_in_mem;
  156609. if (ltemp < 0)
  156610. ltemp = 0; /* don't fall off front end of file */
  156611. ptr->cur_start_row = (JDIMENSION) ltemp;
  156612. }
  156613. do_sarray_io(cinfo, ptr, FALSE);
  156614. }
  156615. if (ptr->first_undef_row < end_row) {
  156616. if (ptr->first_undef_row < start_row) {
  156617. if (writable) /* writer skipped over a section of array */
  156618. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156619. undef_row = start_row; /* but reader is allowed to read ahead */
  156620. } else {
  156621. undef_row = ptr->first_undef_row;
  156622. }
  156623. if (writable)
  156624. ptr->first_undef_row = end_row;
  156625. if (ptr->pre_zero) {
  156626. size_t bytesperrow = (size_t) ptr->samplesperrow * SIZEOF(JSAMPLE);
  156627. undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
  156628. end_row -= ptr->cur_start_row;
  156629. while (undef_row < end_row) {
  156630. jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
  156631. undef_row++;
  156632. }
  156633. } else {
  156634. if (! writable) /* reader looking at undefined data */
  156635. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156636. }
  156637. }
  156638. if (writable)
  156639. ptr->dirty = TRUE;
  156640. return ptr->mem_buffer + (start_row - ptr->cur_start_row);
  156641. }
  156642. METHODDEF(JBLOCKARRAY)
  156643. access_virt_barray (j_common_ptr cinfo, jvirt_barray_ptr ptr,
  156644. JDIMENSION start_row, JDIMENSION num_rows,
  156645. boolean writable)
  156646. {
  156647. JDIMENSION end_row = start_row + num_rows;
  156648. JDIMENSION undef_row;
  156649. if (end_row > ptr->rows_in_array || num_rows > ptr->maxaccess ||
  156650. ptr->mem_buffer == NULL)
  156651. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156652. if (start_row < ptr->cur_start_row ||
  156653. end_row > ptr->cur_start_row+ptr->rows_in_mem) {
  156654. if (! ptr->b_s_open)
  156655. ERREXIT(cinfo, JERR_VIRTUAL_BUG);
  156656. if (ptr->dirty) {
  156657. do_barray_io(cinfo, ptr, TRUE);
  156658. ptr->dirty = FALSE;
  156659. }
  156660. if (start_row > ptr->cur_start_row) {
  156661. ptr->cur_start_row = start_row;
  156662. } else {
  156663. long ltemp;
  156664. ltemp = (long) end_row - (long) ptr->rows_in_mem;
  156665. if (ltemp < 0)
  156666. ltemp = 0; /* don't fall off front end of file */
  156667. ptr->cur_start_row = (JDIMENSION) ltemp;
  156668. }
  156669. do_barray_io(cinfo, ptr, FALSE);
  156670. }
  156671. if (ptr->first_undef_row < end_row) {
  156672. if (ptr->first_undef_row < start_row) {
  156673. if (writable) /* writer skipped over a section of array */
  156674. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156675. undef_row = start_row; /* but reader is allowed to read ahead */
  156676. } else {
  156677. undef_row = ptr->first_undef_row;
  156678. }
  156679. if (writable)
  156680. ptr->first_undef_row = end_row;
  156681. if (ptr->pre_zero) {
  156682. size_t bytesperrow = (size_t) ptr->blocksperrow * SIZEOF(JBLOCK);
  156683. undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
  156684. end_row -= ptr->cur_start_row;
  156685. while (undef_row < end_row) {
  156686. jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
  156687. undef_row++;
  156688. }
  156689. } else {
  156690. if (! writable) /* reader looking at undefined data */
  156691. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156692. }
  156693. }
  156694. if (writable)
  156695. ptr->dirty = TRUE;
  156696. return ptr->mem_buffer + (start_row - ptr->cur_start_row);
  156697. }
  156698. METHODDEF(void)
  156699. free_pool (j_common_ptr cinfo, int pool_id)
  156700. {
  156701. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156702. small_pool_ptr shdr_ptr;
  156703. large_pool_ptr lhdr_ptr;
  156704. size_t space_freed;
  156705. if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
  156706. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156707. #ifdef MEM_STATS
  156708. if (cinfo->err->trace_level > 1)
  156709. print_mem_stats(cinfo, pool_id); /* print pool's memory usage statistics */
  156710. #endif
  156711. if (pool_id == JPOOL_IMAGE) {
  156712. jvirt_sarray_ptr sptr;
  156713. jvirt_barray_ptr bptr;
  156714. for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
  156715. if (sptr->b_s_open) { /* there may be no backing store */
  156716. sptr->b_s_open = FALSE; /* prevent recursive close if error */
  156717. (*sptr->b_s_info.close_backing_store) (cinfo, & sptr->b_s_info);
  156718. }
  156719. }
  156720. mem->virt_sarray_list = NULL;
  156721. for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
  156722. if (bptr->b_s_open) { /* there may be no backing store */
  156723. bptr->b_s_open = FALSE; /* prevent recursive close if error */
  156724. (*bptr->b_s_info.close_backing_store) (cinfo, & bptr->b_s_info);
  156725. }
  156726. }
  156727. mem->virt_barray_list = NULL;
  156728. }
  156729. lhdr_ptr = mem->large_list[pool_id];
  156730. mem->large_list[pool_id] = NULL;
  156731. while (lhdr_ptr != NULL) {
  156732. large_pool_ptr next_lhdr_ptr = lhdr_ptr->hdr.next;
  156733. space_freed = lhdr_ptr->hdr.bytes_used +
  156734. lhdr_ptr->hdr.bytes_left +
  156735. SIZEOF(large_pool_hdr);
  156736. jpeg_free_large(cinfo, (void FAR *) lhdr_ptr, space_freed);
  156737. mem->total_space_allocated -= space_freed;
  156738. lhdr_ptr = next_lhdr_ptr;
  156739. }
  156740. shdr_ptr = mem->small_list[pool_id];
  156741. mem->small_list[pool_id] = NULL;
  156742. while (shdr_ptr != NULL) {
  156743. small_pool_ptr next_shdr_ptr = shdr_ptr->hdr.next;
  156744. space_freed = shdr_ptr->hdr.bytes_used +
  156745. shdr_ptr->hdr.bytes_left +
  156746. SIZEOF(small_pool_hdr);
  156747. jpeg_free_small(cinfo, (void *) shdr_ptr, space_freed);
  156748. mem->total_space_allocated -= space_freed;
  156749. shdr_ptr = next_shdr_ptr;
  156750. }
  156751. }
  156752. METHODDEF(void)
  156753. self_destruct (j_common_ptr cinfo)
  156754. {
  156755. int pool;
  156756. for (pool = JPOOL_NUMPOOLS-1; pool >= JPOOL_PERMANENT; pool--) {
  156757. free_pool(cinfo, pool);
  156758. }
  156759. jpeg_free_small(cinfo, (void *) cinfo->mem, SIZEOF(my_memory_mgr));
  156760. cinfo->mem = NULL; /* ensures I will be called only once */
  156761. jpeg_mem_term(cinfo); /* system-dependent cleanup */
  156762. }
  156763. GLOBAL(void)
  156764. jinit_memory_mgr (j_common_ptr cinfo)
  156765. {
  156766. my_mem_ptr mem;
  156767. long max_to_use;
  156768. int pool;
  156769. size_t test_mac;
  156770. cinfo->mem = NULL; /* for safety if init fails */
  156771. if ((SIZEOF(ALIGN_TYPE) & (SIZEOF(ALIGN_TYPE)-1)) != 0)
  156772. ERREXIT(cinfo, JERR_BAD_ALIGN_TYPE);
  156773. test_mac = (size_t) MAX_ALLOC_CHUNK;
  156774. if ((long) test_mac != MAX_ALLOC_CHUNK ||
  156775. (MAX_ALLOC_CHUNK % SIZEOF(ALIGN_TYPE)) != 0)
  156776. ERREXIT(cinfo, JERR_BAD_ALLOC_CHUNK);
  156777. max_to_use = jpeg_mem_init(cinfo); /* system-dependent initialization */
  156778. mem = (my_mem_ptr) jpeg_get_small(cinfo, SIZEOF(my_memory_mgr));
  156779. if (mem == NULL) {
  156780. jpeg_mem_term(cinfo); /* system-dependent cleanup */
  156781. ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 0);
  156782. }
  156783. mem->pub.alloc_small = alloc_small;
  156784. mem->pub.alloc_large = alloc_large;
  156785. mem->pub.alloc_sarray = alloc_sarray;
  156786. mem->pub.alloc_barray = alloc_barray;
  156787. mem->pub.request_virt_sarray = request_virt_sarray;
  156788. mem->pub.request_virt_barray = request_virt_barray;
  156789. mem->pub.realize_virt_arrays = realize_virt_arrays;
  156790. mem->pub.access_virt_sarray = access_virt_sarray;
  156791. mem->pub.access_virt_barray = access_virt_barray;
  156792. mem->pub.free_pool = free_pool;
  156793. mem->pub.self_destruct = self_destruct;
  156794. mem->pub.max_alloc_chunk = MAX_ALLOC_CHUNK;
  156795. mem->pub.max_memory_to_use = max_to_use;
  156796. for (pool = JPOOL_NUMPOOLS-1; pool >= JPOOL_PERMANENT; pool--) {
  156797. mem->small_list[pool] = NULL;
  156798. mem->large_list[pool] = NULL;
  156799. }
  156800. mem->virt_sarray_list = NULL;
  156801. mem->virt_barray_list = NULL;
  156802. mem->total_space_allocated = SIZEOF(my_memory_mgr);
  156803. cinfo->mem = & mem->pub;
  156804. #ifndef NO_GETENV
  156805. { char * memenv;
  156806. if ((memenv = getenv("JPEGMEM")) != NULL) {
  156807. char ch = 'x';
  156808. if (sscanf(memenv, "%ld%c", &max_to_use, &ch) > 0) {
  156809. if (ch == 'm' || ch == 'M')
  156810. max_to_use *= 1000L;
  156811. mem->pub.max_memory_to_use = max_to_use * 1000L;
  156812. }
  156813. }
  156814. }
  156815. #endif
  156816. }
  156817. /*** End of inlined file: jmemmgr.c ***/
  156818. /*** Start of inlined file: jmemnobs.c ***/
  156819. #define JPEG_INTERNALS
  156820. #ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc(),free() */
  156821. extern void * malloc JPP((size_t size));
  156822. extern void free JPP((void *ptr));
  156823. #endif
  156824. GLOBAL(void *)
  156825. jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject)
  156826. {
  156827. return (void *) malloc(sizeofobject);
  156828. }
  156829. GLOBAL(void)
  156830. jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject)
  156831. {
  156832. free(object);
  156833. }
  156834. GLOBAL(void FAR *)
  156835. jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject)
  156836. {
  156837. return (void FAR *) malloc(sizeofobject);
  156838. }
  156839. GLOBAL(void)
  156840. jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject)
  156841. {
  156842. free(object);
  156843. }
  156844. GLOBAL(long)
  156845. jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed,
  156846. long max_bytes_needed, long already_allocated)
  156847. {
  156848. return max_bytes_needed;
  156849. }
  156850. GLOBAL(void)
  156851. jpeg_open_backing_store (j_common_ptr cinfo, struct backing_store_struct *info,
  156852. long total_bytes_needed)
  156853. {
  156854. ERREXIT(cinfo, JERR_NO_BACKING_STORE);
  156855. }
  156856. GLOBAL(long)
  156857. jpeg_mem_init (j_common_ptr cinfo)
  156858. {
  156859. return 0; /* just set max_memory_to_use to 0 */
  156860. }
  156861. GLOBAL(void)
  156862. jpeg_mem_term (j_common_ptr cinfo)
  156863. {
  156864. }
  156865. /*** End of inlined file: jmemnobs.c ***/
  156866. /*** Start of inlined file: jquant1.c ***/
  156867. #define JPEG_INTERNALS
  156868. #ifdef QUANT_1PASS_SUPPORTED
  156869. #define ODITHER_SIZE 16 /* dimension of dither matrix */
  156870. #define ODITHER_CELLS (ODITHER_SIZE*ODITHER_SIZE) /* # cells in matrix */
  156871. #define ODITHER_MASK (ODITHER_SIZE-1) /* mask for wrapping around counters */
  156872. typedef int ODITHER_MATRIX[ODITHER_SIZE][ODITHER_SIZE];
  156873. typedef int (*ODITHER_MATRIX_PTR)[ODITHER_SIZE];
  156874. static const UINT8 base_dither_matrix[ODITHER_SIZE][ODITHER_SIZE] = {
  156875. { 0,192, 48,240, 12,204, 60,252, 3,195, 51,243, 15,207, 63,255 },
  156876. { 128, 64,176,112,140, 76,188,124,131, 67,179,115,143, 79,191,127 },
  156877. { 32,224, 16,208, 44,236, 28,220, 35,227, 19,211, 47,239, 31,223 },
  156878. { 160, 96,144, 80,172,108,156, 92,163, 99,147, 83,175,111,159, 95 },
  156879. { 8,200, 56,248, 4,196, 52,244, 11,203, 59,251, 7,199, 55,247 },
  156880. { 136, 72,184,120,132, 68,180,116,139, 75,187,123,135, 71,183,119 },
  156881. { 40,232, 24,216, 36,228, 20,212, 43,235, 27,219, 39,231, 23,215 },
  156882. { 168,104,152, 88,164,100,148, 84,171,107,155, 91,167,103,151, 87 },
  156883. { 2,194, 50,242, 14,206, 62,254, 1,193, 49,241, 13,205, 61,253 },
  156884. { 130, 66,178,114,142, 78,190,126,129, 65,177,113,141, 77,189,125 },
  156885. { 34,226, 18,210, 46,238, 30,222, 33,225, 17,209, 45,237, 29,221 },
  156886. { 162, 98,146, 82,174,110,158, 94,161, 97,145, 81,173,109,157, 93 },
  156887. { 10,202, 58,250, 6,198, 54,246, 9,201, 57,249, 5,197, 53,245 },
  156888. { 138, 74,186,122,134, 70,182,118,137, 73,185,121,133, 69,181,117 },
  156889. { 42,234, 26,218, 38,230, 22,214, 41,233, 25,217, 37,229, 21,213 },
  156890. { 170,106,154, 90,166,102,150, 86,169,105,153, 89,165,101,149, 85 }
  156891. };
  156892. #if BITS_IN_JSAMPLE == 8
  156893. typedef INT16 FSERROR; /* 16 bits should be enough */
  156894. typedef int LOCFSERROR; /* use 'int' for calculation temps */
  156895. #else
  156896. typedef INT32 FSERROR; /* may need more than 16 bits */
  156897. typedef INT32 LOCFSERROR; /* be sure calculation temps are big enough */
  156898. #endif
  156899. typedef FSERROR FAR *FSERRPTR; /* pointer to error array (in FAR storage!) */
  156900. #define MAX_Q_COMPS 4 /* max components I can handle */
  156901. typedef struct {
  156902. struct jpeg_color_quantizer pub; /* public fields */
  156903. JSAMPARRAY sv_colormap; /* The color map as a 2-D pixel array */
  156904. int sv_actual; /* number of entries in use */
  156905. JSAMPARRAY colorindex; /* Precomputed mapping for speed */
  156906. boolean is_padded; /* is the colorindex padded for odither? */
  156907. int Ncolors[MAX_Q_COMPS]; /* # of values alloced to each component */
  156908. int row_index; /* cur row's vertical index in dither matrix */
  156909. ODITHER_MATRIX_PTR odither[MAX_Q_COMPS]; /* one dither array per component */
  156910. FSERRPTR fserrors[MAX_Q_COMPS]; /* accumulated errors */
  156911. boolean on_odd_row; /* flag to remember which row we are on */
  156912. } my_cquantizer;
  156913. typedef my_cquantizer * my_cquantize_ptr;
  156914. LOCAL(int)
  156915. select_ncolors (j_decompress_ptr cinfo, int Ncolors[])
  156916. {
  156917. int nc = cinfo->out_color_components; /* number of color components */
  156918. int max_colors = cinfo->desired_number_of_colors;
  156919. int total_colors, iroot, i, j;
  156920. boolean changed;
  156921. long temp;
  156922. static const int RGB_order[3] = { RGB_GREEN, RGB_RED, RGB_BLUE };
  156923. iroot = 1;
  156924. do {
  156925. iroot++;
  156926. temp = iroot; /* set temp = iroot ** nc */
  156927. for (i = 1; i < nc; i++)
  156928. temp *= iroot;
  156929. } while (temp <= (long) max_colors); /* repeat till iroot exceeds root */
  156930. iroot--; /* now iroot = floor(root) */
  156931. if (iroot < 2)
  156932. ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, (int) temp);
  156933. total_colors = 1;
  156934. for (i = 0; i < nc; i++) {
  156935. Ncolors[i] = iroot;
  156936. total_colors *= iroot;
  156937. }
  156938. do {
  156939. changed = FALSE;
  156940. for (i = 0; i < nc; i++) {
  156941. j = (cinfo->out_color_space == JCS_RGB ? RGB_order[i] : i);
  156942. temp = total_colors / Ncolors[j];
  156943. temp *= Ncolors[j]+1; /* done in long arith to avoid oflo */
  156944. if (temp > (long) max_colors)
  156945. break; /* won't fit, done with this pass */
  156946. Ncolors[j]++; /* OK, apply the increment */
  156947. total_colors = (int) temp;
  156948. changed = TRUE;
  156949. }
  156950. } while (changed);
  156951. return total_colors;
  156952. }
  156953. LOCAL(int)
  156954. output_value (j_decompress_ptr cinfo, int ci, int j, int maxj)
  156955. {
  156956. return (int) (((INT32) j * MAXJSAMPLE + maxj/2) / maxj);
  156957. }
  156958. LOCAL(int)
  156959. largest_input_value (j_decompress_ptr cinfo, int ci, int j, int maxj)
  156960. {
  156961. return (int) (((INT32) (2*j + 1) * MAXJSAMPLE + maxj) / (2*maxj));
  156962. }
  156963. LOCAL(void)
  156964. create_colormap (j_decompress_ptr cinfo)
  156965. {
  156966. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  156967. JSAMPARRAY colormap; /* Created colormap */
  156968. int total_colors; /* Number of distinct output colors */
  156969. int i,j,k, nci, blksize, blkdist, ptr, val;
  156970. total_colors = select_ncolors(cinfo, cquantize->Ncolors);
  156971. if (cinfo->out_color_components == 3)
  156972. TRACEMS4(cinfo, 1, JTRC_QUANT_3_NCOLORS,
  156973. total_colors, cquantize->Ncolors[0],
  156974. cquantize->Ncolors[1], cquantize->Ncolors[2]);
  156975. else
  156976. TRACEMS1(cinfo, 1, JTRC_QUANT_NCOLORS, total_colors);
  156977. colormap = (*cinfo->mem->alloc_sarray)
  156978. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  156979. (JDIMENSION) total_colors, (JDIMENSION) cinfo->out_color_components);
  156980. blkdist = total_colors;
  156981. for (i = 0; i < cinfo->out_color_components; i++) {
  156982. nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
  156983. blksize = blkdist / nci;
  156984. for (j = 0; j < nci; j++) {
  156985. val = output_value(cinfo, i, j, nci-1);
  156986. for (ptr = j * blksize; ptr < total_colors; ptr += blkdist) {
  156987. for (k = 0; k < blksize; k++)
  156988. colormap[i][ptr+k] = (JSAMPLE) val;
  156989. }
  156990. }
  156991. blkdist = blksize; /* blksize of this color is blkdist of next */
  156992. }
  156993. cquantize->sv_colormap = colormap;
  156994. cquantize->sv_actual = total_colors;
  156995. }
  156996. LOCAL(void)
  156997. create_colorindex (j_decompress_ptr cinfo)
  156998. {
  156999. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157000. JSAMPROW indexptr;
  157001. int i,j,k, nci, blksize, val, pad;
  157002. if (cinfo->dither_mode == JDITHER_ORDERED) {
  157003. pad = MAXJSAMPLE*2;
  157004. cquantize->is_padded = TRUE;
  157005. } else {
  157006. pad = 0;
  157007. cquantize->is_padded = FALSE;
  157008. }
  157009. cquantize->colorindex = (*cinfo->mem->alloc_sarray)
  157010. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157011. (JDIMENSION) (MAXJSAMPLE+1 + pad),
  157012. (JDIMENSION) cinfo->out_color_components);
  157013. blksize = cquantize->sv_actual;
  157014. for (i = 0; i < cinfo->out_color_components; i++) {
  157015. nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
  157016. blksize = blksize / nci;
  157017. if (pad)
  157018. cquantize->colorindex[i] += MAXJSAMPLE;
  157019. indexptr = cquantize->colorindex[i];
  157020. val = 0;
  157021. k = largest_input_value(cinfo, i, 0, nci-1);
  157022. for (j = 0; j <= MAXJSAMPLE; j++) {
  157023. while (j > k) /* advance val if past boundary */
  157024. k = largest_input_value(cinfo, i, ++val, nci-1);
  157025. indexptr[j] = (JSAMPLE) (val * blksize);
  157026. }
  157027. if (pad)
  157028. for (j = 1; j <= MAXJSAMPLE; j++) {
  157029. indexptr[-j] = indexptr[0];
  157030. indexptr[MAXJSAMPLE+j] = indexptr[MAXJSAMPLE];
  157031. }
  157032. }
  157033. }
  157034. LOCAL(ODITHER_MATRIX_PTR)
  157035. make_odither_array (j_decompress_ptr cinfo, int ncolors)
  157036. {
  157037. ODITHER_MATRIX_PTR odither;
  157038. int j,k;
  157039. INT32 num,den;
  157040. odither = (ODITHER_MATRIX_PTR)
  157041. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157042. SIZEOF(ODITHER_MATRIX));
  157043. den = 2 * ODITHER_CELLS * ((INT32) (ncolors - 1));
  157044. for (j = 0; j < ODITHER_SIZE; j++) {
  157045. for (k = 0; k < ODITHER_SIZE; k++) {
  157046. num = ((INT32) (ODITHER_CELLS-1 - 2*((int)base_dither_matrix[j][k])))
  157047. * MAXJSAMPLE;
  157048. odither[j][k] = (int) (num<0 ? -((-num)/den) : num/den);
  157049. }
  157050. }
  157051. return odither;
  157052. }
  157053. LOCAL(void)
  157054. create_odither_tables (j_decompress_ptr cinfo)
  157055. {
  157056. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157057. ODITHER_MATRIX_PTR odither;
  157058. int i, j, nci;
  157059. for (i = 0; i < cinfo->out_color_components; i++) {
  157060. nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
  157061. odither = NULL; /* search for matching prior component */
  157062. for (j = 0; j < i; j++) {
  157063. if (nci == cquantize->Ncolors[j]) {
  157064. odither = cquantize->odither[j];
  157065. break;
  157066. }
  157067. }
  157068. if (odither == NULL) /* need a new table? */
  157069. odither = make_odither_array(cinfo, nci);
  157070. cquantize->odither[i] = odither;
  157071. }
  157072. }
  157073. METHODDEF(void)
  157074. color_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157075. JSAMPARRAY output_buf, int num_rows)
  157076. {
  157077. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157078. JSAMPARRAY colorindex = cquantize->colorindex;
  157079. register int pixcode, ci;
  157080. register JSAMPROW ptrin, ptrout;
  157081. int row;
  157082. JDIMENSION col;
  157083. JDIMENSION width = cinfo->output_width;
  157084. register int nc = cinfo->out_color_components;
  157085. for (row = 0; row < num_rows; row++) {
  157086. ptrin = input_buf[row];
  157087. ptrout = output_buf[row];
  157088. for (col = width; col > 0; col--) {
  157089. pixcode = 0;
  157090. for (ci = 0; ci < nc; ci++) {
  157091. pixcode += GETJSAMPLE(colorindex[ci][GETJSAMPLE(*ptrin++)]);
  157092. }
  157093. *ptrout++ = (JSAMPLE) pixcode;
  157094. }
  157095. }
  157096. }
  157097. METHODDEF(void)
  157098. color_quantize3 (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157099. JSAMPARRAY output_buf, int num_rows)
  157100. {
  157101. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157102. register int pixcode;
  157103. register JSAMPROW ptrin, ptrout;
  157104. JSAMPROW colorindex0 = cquantize->colorindex[0];
  157105. JSAMPROW colorindex1 = cquantize->colorindex[1];
  157106. JSAMPROW colorindex2 = cquantize->colorindex[2];
  157107. int row;
  157108. JDIMENSION col;
  157109. JDIMENSION width = cinfo->output_width;
  157110. for (row = 0; row < num_rows; row++) {
  157111. ptrin = input_buf[row];
  157112. ptrout = output_buf[row];
  157113. for (col = width; col > 0; col--) {
  157114. pixcode = GETJSAMPLE(colorindex0[GETJSAMPLE(*ptrin++)]);
  157115. pixcode += GETJSAMPLE(colorindex1[GETJSAMPLE(*ptrin++)]);
  157116. pixcode += GETJSAMPLE(colorindex2[GETJSAMPLE(*ptrin++)]);
  157117. *ptrout++ = (JSAMPLE) pixcode;
  157118. }
  157119. }
  157120. }
  157121. METHODDEF(void)
  157122. quantize_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157123. JSAMPARRAY output_buf, int num_rows)
  157124. {
  157125. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157126. register JSAMPROW input_ptr;
  157127. register JSAMPROW output_ptr;
  157128. JSAMPROW colorindex_ci;
  157129. int * dither; /* points to active row of dither matrix */
  157130. int row_index, col_index; /* current indexes into dither matrix */
  157131. int nc = cinfo->out_color_components;
  157132. int ci;
  157133. int row;
  157134. JDIMENSION col;
  157135. JDIMENSION width = cinfo->output_width;
  157136. for (row = 0; row < num_rows; row++) {
  157137. jzero_far((void FAR *) output_buf[row],
  157138. (size_t) (width * SIZEOF(JSAMPLE)));
  157139. row_index = cquantize->row_index;
  157140. for (ci = 0; ci < nc; ci++) {
  157141. input_ptr = input_buf[row] + ci;
  157142. output_ptr = output_buf[row];
  157143. colorindex_ci = cquantize->colorindex[ci];
  157144. dither = cquantize->odither[ci][row_index];
  157145. col_index = 0;
  157146. for (col = width; col > 0; col--) {
  157147. *output_ptr += colorindex_ci[GETJSAMPLE(*input_ptr)+dither[col_index]];
  157148. input_ptr += nc;
  157149. output_ptr++;
  157150. col_index = (col_index + 1) & ODITHER_MASK;
  157151. }
  157152. }
  157153. row_index = (row_index + 1) & ODITHER_MASK;
  157154. cquantize->row_index = row_index;
  157155. }
  157156. }
  157157. METHODDEF(void)
  157158. quantize3_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157159. JSAMPARRAY output_buf, int num_rows)
  157160. {
  157161. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157162. register int pixcode;
  157163. register JSAMPROW input_ptr;
  157164. register JSAMPROW output_ptr;
  157165. JSAMPROW colorindex0 = cquantize->colorindex[0];
  157166. JSAMPROW colorindex1 = cquantize->colorindex[1];
  157167. JSAMPROW colorindex2 = cquantize->colorindex[2];
  157168. int * dither0; /* points to active row of dither matrix */
  157169. int * dither1;
  157170. int * dither2;
  157171. int row_index, col_index; /* current indexes into dither matrix */
  157172. int row;
  157173. JDIMENSION col;
  157174. JDIMENSION width = cinfo->output_width;
  157175. for (row = 0; row < num_rows; row++) {
  157176. row_index = cquantize->row_index;
  157177. input_ptr = input_buf[row];
  157178. output_ptr = output_buf[row];
  157179. dither0 = cquantize->odither[0][row_index];
  157180. dither1 = cquantize->odither[1][row_index];
  157181. dither2 = cquantize->odither[2][row_index];
  157182. col_index = 0;
  157183. for (col = width; col > 0; col--) {
  157184. pixcode = GETJSAMPLE(colorindex0[GETJSAMPLE(*input_ptr++) +
  157185. dither0[col_index]]);
  157186. pixcode += GETJSAMPLE(colorindex1[GETJSAMPLE(*input_ptr++) +
  157187. dither1[col_index]]);
  157188. pixcode += GETJSAMPLE(colorindex2[GETJSAMPLE(*input_ptr++) +
  157189. dither2[col_index]]);
  157190. *output_ptr++ = (JSAMPLE) pixcode;
  157191. col_index = (col_index + 1) & ODITHER_MASK;
  157192. }
  157193. row_index = (row_index + 1) & ODITHER_MASK;
  157194. cquantize->row_index = row_index;
  157195. }
  157196. }
  157197. METHODDEF(void)
  157198. quantize_fs_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157199. JSAMPARRAY output_buf, int num_rows)
  157200. {
  157201. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157202. register LOCFSERROR cur; /* current error or pixel value */
  157203. LOCFSERROR belowerr; /* error for pixel below cur */
  157204. LOCFSERROR bpreverr; /* error for below/prev col */
  157205. LOCFSERROR bnexterr; /* error for below/next col */
  157206. LOCFSERROR delta;
  157207. register FSERRPTR errorptr; /* => fserrors[] at column before current */
  157208. register JSAMPROW input_ptr;
  157209. register JSAMPROW output_ptr;
  157210. JSAMPROW colorindex_ci;
  157211. JSAMPROW colormap_ci;
  157212. int pixcode;
  157213. int nc = cinfo->out_color_components;
  157214. int dir; /* 1 for left-to-right, -1 for right-to-left */
  157215. int dirnc; /* dir * nc */
  157216. int ci;
  157217. int row;
  157218. JDIMENSION col;
  157219. JDIMENSION width = cinfo->output_width;
  157220. JSAMPLE *range_limit = cinfo->sample_range_limit;
  157221. SHIFT_TEMPS
  157222. for (row = 0; row < num_rows; row++) {
  157223. jzero_far((void FAR *) output_buf[row],
  157224. (size_t) (width * SIZEOF(JSAMPLE)));
  157225. for (ci = 0; ci < nc; ci++) {
  157226. input_ptr = input_buf[row] + ci;
  157227. output_ptr = output_buf[row];
  157228. if (cquantize->on_odd_row) {
  157229. input_ptr += (width-1) * nc; /* so point to rightmost pixel */
  157230. output_ptr += width-1;
  157231. dir = -1;
  157232. dirnc = -nc;
  157233. errorptr = cquantize->fserrors[ci] + (width+1); /* => entry after last column */
  157234. } else {
  157235. dir = 1;
  157236. dirnc = nc;
  157237. errorptr = cquantize->fserrors[ci]; /* => entry before first column */
  157238. }
  157239. colorindex_ci = cquantize->colorindex[ci];
  157240. colormap_ci = cquantize->sv_colormap[ci];
  157241. cur = 0;
  157242. belowerr = bpreverr = 0;
  157243. for (col = width; col > 0; col--) {
  157244. cur = RIGHT_SHIFT(cur + errorptr[dir] + 8, 4);
  157245. cur += GETJSAMPLE(*input_ptr);
  157246. cur = GETJSAMPLE(range_limit[cur]);
  157247. pixcode = GETJSAMPLE(colorindex_ci[cur]);
  157248. *output_ptr += (JSAMPLE) pixcode;
  157249. cur -= GETJSAMPLE(colormap_ci[pixcode]);
  157250. bnexterr = cur;
  157251. delta = cur * 2;
  157252. cur += delta; /* form error * 3 */
  157253. errorptr[0] = (FSERROR) (bpreverr + cur);
  157254. cur += delta; /* form error * 5 */
  157255. bpreverr = belowerr + cur;
  157256. belowerr = bnexterr;
  157257. cur += delta; /* form error * 7 */
  157258. input_ptr += dirnc; /* advance input ptr to next column */
  157259. output_ptr += dir; /* advance output ptr to next column */
  157260. errorptr += dir; /* advance errorptr to current column */
  157261. }
  157262. errorptr[0] = (FSERROR) bpreverr; /* unload prev err into array */
  157263. }
  157264. cquantize->on_odd_row = (cquantize->on_odd_row ? FALSE : TRUE);
  157265. }
  157266. }
  157267. LOCAL(void)
  157268. alloc_fs_workspace (j_decompress_ptr cinfo)
  157269. {
  157270. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157271. size_t arraysize;
  157272. int i;
  157273. arraysize = (size_t) ((cinfo->output_width + 2) * SIZEOF(FSERROR));
  157274. for (i = 0; i < cinfo->out_color_components; i++) {
  157275. cquantize->fserrors[i] = (FSERRPTR)
  157276. (*cinfo->mem->alloc_large)((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize);
  157277. }
  157278. }
  157279. METHODDEF(void)
  157280. start_pass_1_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
  157281. {
  157282. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157283. size_t arraysize;
  157284. int i;
  157285. cinfo->colormap = cquantize->sv_colormap;
  157286. cinfo->actual_number_of_colors = cquantize->sv_actual;
  157287. switch (cinfo->dither_mode) {
  157288. case JDITHER_NONE:
  157289. if (cinfo->out_color_components == 3)
  157290. cquantize->pub.color_quantize = color_quantize3;
  157291. else
  157292. cquantize->pub.color_quantize = color_quantize;
  157293. break;
  157294. case JDITHER_ORDERED:
  157295. if (cinfo->out_color_components == 3)
  157296. cquantize->pub.color_quantize = quantize3_ord_dither;
  157297. else
  157298. cquantize->pub.color_quantize = quantize_ord_dither;
  157299. cquantize->row_index = 0; /* initialize state for ordered dither */
  157300. if (! cquantize->is_padded)
  157301. create_colorindex(cinfo);
  157302. if (cquantize->odither[0] == NULL)
  157303. create_odither_tables(cinfo);
  157304. break;
  157305. case JDITHER_FS:
  157306. cquantize->pub.color_quantize = quantize_fs_dither;
  157307. cquantize->on_odd_row = FALSE; /* initialize state for F-S dither */
  157308. if (cquantize->fserrors[0] == NULL)
  157309. alloc_fs_workspace(cinfo);
  157310. arraysize = (size_t) ((cinfo->output_width + 2) * SIZEOF(FSERROR));
  157311. for (i = 0; i < cinfo->out_color_components; i++)
  157312. jzero_far((void FAR *) cquantize->fserrors[i], arraysize);
  157313. break;
  157314. default:
  157315. ERREXIT(cinfo, JERR_NOT_COMPILED);
  157316. break;
  157317. }
  157318. }
  157319. METHODDEF(void)
  157320. finish_pass_1_quant (j_decompress_ptr cinfo)
  157321. {
  157322. }
  157323. METHODDEF(void)
  157324. new_color_map_1_quant (j_decompress_ptr cinfo)
  157325. {
  157326. ERREXIT(cinfo, JERR_MODE_CHANGE);
  157327. }
  157328. GLOBAL(void)
  157329. jinit_1pass_quantizer (j_decompress_ptr cinfo)
  157330. {
  157331. my_cquantize_ptr cquantize;
  157332. cquantize = (my_cquantize_ptr)
  157333. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157334. SIZEOF(my_cquantizer));
  157335. cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize;
  157336. cquantize->pub.start_pass = start_pass_1_quant;
  157337. cquantize->pub.finish_pass = finish_pass_1_quant;
  157338. cquantize->pub.new_color_map = new_color_map_1_quant;
  157339. cquantize->fserrors[0] = NULL; /* Flag FS workspace not allocated */
  157340. cquantize->odither[0] = NULL; /* Also flag odither arrays not allocated */
  157341. if (cinfo->out_color_components > MAX_Q_COMPS)
  157342. ERREXIT1(cinfo, JERR_QUANT_COMPONENTS, MAX_Q_COMPS);
  157343. if (cinfo->desired_number_of_colors > (MAXJSAMPLE+1))
  157344. ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXJSAMPLE+1);
  157345. create_colormap(cinfo);
  157346. create_colorindex(cinfo);
  157347. if (cinfo->dither_mode == JDITHER_FS)
  157348. alloc_fs_workspace(cinfo);
  157349. }
  157350. #endif /* QUANT_1PASS_SUPPORTED */
  157351. /*** End of inlined file: jquant1.c ***/
  157352. /*** Start of inlined file: jquant2.c ***/
  157353. #define JPEG_INTERNALS
  157354. #ifdef QUANT_2PASS_SUPPORTED
  157355. #define R_SCALE 2 /* scale R distances by this much */
  157356. #define G_SCALE 3 /* scale G distances by this much */
  157357. #define B_SCALE 1 /* and B by this much */
  157358. #if RGB_RED == 0
  157359. #define C0_SCALE R_SCALE
  157360. #endif
  157361. #if RGB_BLUE == 0
  157362. #define C0_SCALE B_SCALE
  157363. #endif
  157364. #if RGB_GREEN == 1
  157365. #define C1_SCALE G_SCALE
  157366. #endif
  157367. #if RGB_RED == 2
  157368. #define C2_SCALE R_SCALE
  157369. #endif
  157370. #if RGB_BLUE == 2
  157371. #define C2_SCALE B_SCALE
  157372. #endif
  157373. #define MAXNUMCOLORS (MAXJSAMPLE+1) /* maximum size of colormap */
  157374. #define HIST_C0_BITS 5 /* bits of precision in R/B histogram */
  157375. #define HIST_C1_BITS 6 /* bits of precision in G histogram */
  157376. #define HIST_C2_BITS 5 /* bits of precision in B/R histogram */
  157377. #define HIST_C0_ELEMS (1<<HIST_C0_BITS)
  157378. #define HIST_C1_ELEMS (1<<HIST_C1_BITS)
  157379. #define HIST_C2_ELEMS (1<<HIST_C2_BITS)
  157380. #define C0_SHIFT (BITS_IN_JSAMPLE-HIST_C0_BITS)
  157381. #define C1_SHIFT (BITS_IN_JSAMPLE-HIST_C1_BITS)
  157382. #define C2_SHIFT (BITS_IN_JSAMPLE-HIST_C2_BITS)
  157383. typedef UINT16 histcell; /* histogram cell; prefer an unsigned type */
  157384. typedef histcell FAR * histptr; /* for pointers to histogram cells */
  157385. typedef histcell hist1d[HIST_C2_ELEMS]; /* typedefs for the array */
  157386. typedef hist1d FAR * hist2d; /* type for the 2nd-level pointers */
  157387. typedef hist2d * hist3d; /* type for top-level pointer */
  157388. #if BITS_IN_JSAMPLE == 8
  157389. typedef INT16 FSERROR; /* 16 bits should be enough */
  157390. typedef int LOCFSERROR; /* use 'int' for calculation temps */
  157391. #else
  157392. typedef INT32 FSERROR; /* may need more than 16 bits */
  157393. typedef INT32 LOCFSERROR; /* be sure calculation temps are big enough */
  157394. #endif
  157395. typedef FSERROR FAR *FSERRPTR; /* pointer to error array (in FAR storage!) */
  157396. typedef struct {
  157397. struct jpeg_color_quantizer pub; /* public fields */
  157398. JSAMPARRAY sv_colormap; /* colormap allocated at init time */
  157399. int desired; /* desired # of colors = size of colormap */
  157400. hist3d histogram; /* pointer to the histogram */
  157401. boolean needs_zeroed; /* TRUE if next pass must zero histogram */
  157402. FSERRPTR fserrors; /* accumulated errors */
  157403. boolean on_odd_row; /* flag to remember which row we are on */
  157404. int * error_limiter; /* table for clamping the applied error */
  157405. } my_cquantizer2;
  157406. typedef my_cquantizer2 * my_cquantize_ptr2;
  157407. METHODDEF(void)
  157408. prescan_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157409. JSAMPARRAY output_buf, int num_rows)
  157410. {
  157411. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157412. register JSAMPROW ptr;
  157413. register histptr histp;
  157414. register hist3d histogram = cquantize->histogram;
  157415. int row;
  157416. JDIMENSION col;
  157417. JDIMENSION width = cinfo->output_width;
  157418. for (row = 0; row < num_rows; row++) {
  157419. ptr = input_buf[row];
  157420. for (col = width; col > 0; col--) {
  157421. histp = & histogram[GETJSAMPLE(ptr[0]) >> C0_SHIFT]
  157422. [GETJSAMPLE(ptr[1]) >> C1_SHIFT]
  157423. [GETJSAMPLE(ptr[2]) >> C2_SHIFT];
  157424. if (++(*histp) <= 0)
  157425. (*histp)--;
  157426. ptr += 3;
  157427. }
  157428. }
  157429. }
  157430. typedef struct {
  157431. int c0min, c0max;
  157432. int c1min, c1max;
  157433. int c2min, c2max;
  157434. INT32 volume;
  157435. long colorcount;
  157436. } box;
  157437. typedef box * boxptr;
  157438. LOCAL(boxptr)
  157439. find_biggest_color_pop (boxptr boxlist, int numboxes)
  157440. {
  157441. register boxptr boxp;
  157442. register int i;
  157443. register long maxc = 0;
  157444. boxptr which = NULL;
  157445. for (i = 0, boxp = boxlist; i < numboxes; i++, boxp++) {
  157446. if (boxp->colorcount > maxc && boxp->volume > 0) {
  157447. which = boxp;
  157448. maxc = boxp->colorcount;
  157449. }
  157450. }
  157451. return which;
  157452. }
  157453. LOCAL(boxptr)
  157454. find_biggest_volume (boxptr boxlist, int numboxes)
  157455. {
  157456. register boxptr boxp;
  157457. register int i;
  157458. register INT32 maxv = 0;
  157459. boxptr which = NULL;
  157460. for (i = 0, boxp = boxlist; i < numboxes; i++, boxp++) {
  157461. if (boxp->volume > maxv) {
  157462. which = boxp;
  157463. maxv = boxp->volume;
  157464. }
  157465. }
  157466. return which;
  157467. }
  157468. LOCAL(void)
  157469. update_box (j_decompress_ptr cinfo, boxptr boxp)
  157470. {
  157471. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157472. hist3d histogram = cquantize->histogram;
  157473. histptr histp;
  157474. int c0,c1,c2;
  157475. int c0min,c0max,c1min,c1max,c2min,c2max;
  157476. INT32 dist0,dist1,dist2;
  157477. long ccount;
  157478. c0min = boxp->c0min; c0max = boxp->c0max;
  157479. c1min = boxp->c1min; c1max = boxp->c1max;
  157480. c2min = boxp->c2min; c2max = boxp->c2max;
  157481. if (c0max > c0min)
  157482. for (c0 = c0min; c0 <= c0max; c0++)
  157483. for (c1 = c1min; c1 <= c1max; c1++) {
  157484. histp = & histogram[c0][c1][c2min];
  157485. for (c2 = c2min; c2 <= c2max; c2++)
  157486. if (*histp++ != 0) {
  157487. boxp->c0min = c0min = c0;
  157488. goto have_c0min;
  157489. }
  157490. }
  157491. have_c0min:
  157492. if (c0max > c0min)
  157493. for (c0 = c0max; c0 >= c0min; c0--)
  157494. for (c1 = c1min; c1 <= c1max; c1++) {
  157495. histp = & histogram[c0][c1][c2min];
  157496. for (c2 = c2min; c2 <= c2max; c2++)
  157497. if (*histp++ != 0) {
  157498. boxp->c0max = c0max = c0;
  157499. goto have_c0max;
  157500. }
  157501. }
  157502. have_c0max:
  157503. if (c1max > c1min)
  157504. for (c1 = c1min; c1 <= c1max; c1++)
  157505. for (c0 = c0min; c0 <= c0max; c0++) {
  157506. histp = & histogram[c0][c1][c2min];
  157507. for (c2 = c2min; c2 <= c2max; c2++)
  157508. if (*histp++ != 0) {
  157509. boxp->c1min = c1min = c1;
  157510. goto have_c1min;
  157511. }
  157512. }
  157513. have_c1min:
  157514. if (c1max > c1min)
  157515. for (c1 = c1max; c1 >= c1min; c1--)
  157516. for (c0 = c0min; c0 <= c0max; c0++) {
  157517. histp = & histogram[c0][c1][c2min];
  157518. for (c2 = c2min; c2 <= c2max; c2++)
  157519. if (*histp++ != 0) {
  157520. boxp->c1max = c1max = c1;
  157521. goto have_c1max;
  157522. }
  157523. }
  157524. have_c1max:
  157525. if (c2max > c2min)
  157526. for (c2 = c2min; c2 <= c2max; c2++)
  157527. for (c0 = c0min; c0 <= c0max; c0++) {
  157528. histp = & histogram[c0][c1min][c2];
  157529. for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS)
  157530. if (*histp != 0) {
  157531. boxp->c2min = c2min = c2;
  157532. goto have_c2min;
  157533. }
  157534. }
  157535. have_c2min:
  157536. if (c2max > c2min)
  157537. for (c2 = c2max; c2 >= c2min; c2--)
  157538. for (c0 = c0min; c0 <= c0max; c0++) {
  157539. histp = & histogram[c0][c1min][c2];
  157540. for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS)
  157541. if (*histp != 0) {
  157542. boxp->c2max = c2max = c2;
  157543. goto have_c2max;
  157544. }
  157545. }
  157546. have_c2max:
  157547. dist0 = ((c0max - c0min) << C0_SHIFT) * C0_SCALE;
  157548. dist1 = ((c1max - c1min) << C1_SHIFT) * C1_SCALE;
  157549. dist2 = ((c2max - c2min) << C2_SHIFT) * C2_SCALE;
  157550. boxp->volume = dist0*dist0 + dist1*dist1 + dist2*dist2;
  157551. ccount = 0;
  157552. for (c0 = c0min; c0 <= c0max; c0++)
  157553. for (c1 = c1min; c1 <= c1max; c1++) {
  157554. histp = & histogram[c0][c1][c2min];
  157555. for (c2 = c2min; c2 <= c2max; c2++, histp++)
  157556. if (*histp != 0) {
  157557. ccount++;
  157558. }
  157559. }
  157560. boxp->colorcount = ccount;
  157561. }
  157562. LOCAL(int)
  157563. median_cut (j_decompress_ptr cinfo, boxptr boxlist, int numboxes,
  157564. int desired_colors)
  157565. {
  157566. int n,lb;
  157567. int c0,c1,c2,cmax;
  157568. register boxptr b1,b2;
  157569. while (numboxes < desired_colors) {
  157570. if (numboxes*2 <= desired_colors) {
  157571. b1 = find_biggest_color_pop(boxlist, numboxes);
  157572. } else {
  157573. b1 = find_biggest_volume(boxlist, numboxes);
  157574. }
  157575. if (b1 == NULL) /* no splittable boxes left! */
  157576. break;
  157577. b2 = &boxlist[numboxes]; /* where new box will go */
  157578. b2->c0max = b1->c0max; b2->c1max = b1->c1max; b2->c2max = b1->c2max;
  157579. b2->c0min = b1->c0min; b2->c1min = b1->c1min; b2->c2min = b1->c2min;
  157580. c0 = ((b1->c0max - b1->c0min) << C0_SHIFT) * C0_SCALE;
  157581. c1 = ((b1->c1max - b1->c1min) << C1_SHIFT) * C1_SCALE;
  157582. c2 = ((b1->c2max - b1->c2min) << C2_SHIFT) * C2_SCALE;
  157583. #if RGB_RED == 0
  157584. cmax = c1; n = 1;
  157585. if (c0 > cmax) { cmax = c0; n = 0; }
  157586. if (c2 > cmax) { n = 2; }
  157587. #else
  157588. cmax = c1; n = 1;
  157589. if (c2 > cmax) { cmax = c2; n = 2; }
  157590. if (c0 > cmax) { n = 0; }
  157591. #endif
  157592. switch (n) {
  157593. case 0:
  157594. lb = (b1->c0max + b1->c0min) / 2;
  157595. b1->c0max = lb;
  157596. b2->c0min = lb+1;
  157597. break;
  157598. case 1:
  157599. lb = (b1->c1max + b1->c1min) / 2;
  157600. b1->c1max = lb;
  157601. b2->c1min = lb+1;
  157602. break;
  157603. case 2:
  157604. lb = (b1->c2max + b1->c2min) / 2;
  157605. b1->c2max = lb;
  157606. b2->c2min = lb+1;
  157607. break;
  157608. }
  157609. update_box(cinfo, b1);
  157610. update_box(cinfo, b2);
  157611. numboxes++;
  157612. }
  157613. return numboxes;
  157614. }
  157615. LOCAL(void)
  157616. compute_color (j_decompress_ptr cinfo, boxptr boxp, int icolor)
  157617. {
  157618. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157619. hist3d histogram = cquantize->histogram;
  157620. histptr histp;
  157621. int c0,c1,c2;
  157622. int c0min,c0max,c1min,c1max,c2min,c2max;
  157623. long count;
  157624. long total = 0;
  157625. long c0total = 0;
  157626. long c1total = 0;
  157627. long c2total = 0;
  157628. c0min = boxp->c0min; c0max = boxp->c0max;
  157629. c1min = boxp->c1min; c1max = boxp->c1max;
  157630. c2min = boxp->c2min; c2max = boxp->c2max;
  157631. for (c0 = c0min; c0 <= c0max; c0++)
  157632. for (c1 = c1min; c1 <= c1max; c1++) {
  157633. histp = & histogram[c0][c1][c2min];
  157634. for (c2 = c2min; c2 <= c2max; c2++) {
  157635. if ((count = *histp++) != 0) {
  157636. total += count;
  157637. c0total += ((c0 << C0_SHIFT) + ((1<<C0_SHIFT)>>1)) * count;
  157638. c1total += ((c1 << C1_SHIFT) + ((1<<C1_SHIFT)>>1)) * count;
  157639. c2total += ((c2 << C2_SHIFT) + ((1<<C2_SHIFT)>>1)) * count;
  157640. }
  157641. }
  157642. }
  157643. cinfo->colormap[0][icolor] = (JSAMPLE) ((c0total + (total>>1)) / total);
  157644. cinfo->colormap[1][icolor] = (JSAMPLE) ((c1total + (total>>1)) / total);
  157645. cinfo->colormap[2][icolor] = (JSAMPLE) ((c2total + (total>>1)) / total);
  157646. }
  157647. LOCAL(void)
  157648. select_colors (j_decompress_ptr cinfo, int desired_colors)
  157649. {
  157650. boxptr boxlist;
  157651. int numboxes;
  157652. int i;
  157653. boxlist = (boxptr) (*cinfo->mem->alloc_small)
  157654. ((j_common_ptr) cinfo, JPOOL_IMAGE, desired_colors * SIZEOF(box));
  157655. numboxes = 1;
  157656. boxlist[0].c0min = 0;
  157657. boxlist[0].c0max = MAXJSAMPLE >> C0_SHIFT;
  157658. boxlist[0].c1min = 0;
  157659. boxlist[0].c1max = MAXJSAMPLE >> C1_SHIFT;
  157660. boxlist[0].c2min = 0;
  157661. boxlist[0].c2max = MAXJSAMPLE >> C2_SHIFT;
  157662. update_box(cinfo, & boxlist[0]);
  157663. numboxes = median_cut(cinfo, boxlist, numboxes, desired_colors);
  157664. for (i = 0; i < numboxes; i++)
  157665. compute_color(cinfo, & boxlist[i], i);
  157666. cinfo->actual_number_of_colors = numboxes;
  157667. TRACEMS1(cinfo, 1, JTRC_QUANT_SELECTED, numboxes);
  157668. }
  157669. #define BOX_C0_LOG (HIST_C0_BITS-3)
  157670. #define BOX_C1_LOG (HIST_C1_BITS-3)
  157671. #define BOX_C2_LOG (HIST_C2_BITS-3)
  157672. #define BOX_C0_ELEMS (1<<BOX_C0_LOG) /* # of hist cells in update box */
  157673. #define BOX_C1_ELEMS (1<<BOX_C1_LOG)
  157674. #define BOX_C2_ELEMS (1<<BOX_C2_LOG)
  157675. #define BOX_C0_SHIFT (C0_SHIFT + BOX_C0_LOG)
  157676. #define BOX_C1_SHIFT (C1_SHIFT + BOX_C1_LOG)
  157677. #define BOX_C2_SHIFT (C2_SHIFT + BOX_C2_LOG)
  157678. LOCAL(int)
  157679. find_nearby_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
  157680. JSAMPLE colorlist[])
  157681. {
  157682. int numcolors = cinfo->actual_number_of_colors;
  157683. int maxc0, maxc1, maxc2;
  157684. int centerc0, centerc1, centerc2;
  157685. int i, x, ncolors;
  157686. INT32 minmaxdist, min_dist, max_dist, tdist;
  157687. INT32 mindist[MAXNUMCOLORS]; /* min distance to colormap entry i */
  157688. maxc0 = minc0 + ((1 << BOX_C0_SHIFT) - (1 << C0_SHIFT));
  157689. centerc0 = (minc0 + maxc0) >> 1;
  157690. maxc1 = minc1 + ((1 << BOX_C1_SHIFT) - (1 << C1_SHIFT));
  157691. centerc1 = (minc1 + maxc1) >> 1;
  157692. maxc2 = minc2 + ((1 << BOX_C2_SHIFT) - (1 << C2_SHIFT));
  157693. centerc2 = (minc2 + maxc2) >> 1;
  157694. minmaxdist = 0x7FFFFFFFL;
  157695. for (i = 0; i < numcolors; i++) {
  157696. x = GETJSAMPLE(cinfo->colormap[0][i]);
  157697. if (x < minc0) {
  157698. tdist = (x - minc0) * C0_SCALE;
  157699. min_dist = tdist*tdist;
  157700. tdist = (x - maxc0) * C0_SCALE;
  157701. max_dist = tdist*tdist;
  157702. } else if (x > maxc0) {
  157703. tdist = (x - maxc0) * C0_SCALE;
  157704. min_dist = tdist*tdist;
  157705. tdist = (x - minc0) * C0_SCALE;
  157706. max_dist = tdist*tdist;
  157707. } else {
  157708. min_dist = 0;
  157709. if (x <= centerc0) {
  157710. tdist = (x - maxc0) * C0_SCALE;
  157711. max_dist = tdist*tdist;
  157712. } else {
  157713. tdist = (x - minc0) * C0_SCALE;
  157714. max_dist = tdist*tdist;
  157715. }
  157716. }
  157717. x = GETJSAMPLE(cinfo->colormap[1][i]);
  157718. if (x < minc1) {
  157719. tdist = (x - minc1) * C1_SCALE;
  157720. min_dist += tdist*tdist;
  157721. tdist = (x - maxc1) * C1_SCALE;
  157722. max_dist += tdist*tdist;
  157723. } else if (x > maxc1) {
  157724. tdist = (x - maxc1) * C1_SCALE;
  157725. min_dist += tdist*tdist;
  157726. tdist = (x - minc1) * C1_SCALE;
  157727. max_dist += tdist*tdist;
  157728. } else {
  157729. if (x <= centerc1) {
  157730. tdist = (x - maxc1) * C1_SCALE;
  157731. max_dist += tdist*tdist;
  157732. } else {
  157733. tdist = (x - minc1) * C1_SCALE;
  157734. max_dist += tdist*tdist;
  157735. }
  157736. }
  157737. x = GETJSAMPLE(cinfo->colormap[2][i]);
  157738. if (x < minc2) {
  157739. tdist = (x - minc2) * C2_SCALE;
  157740. min_dist += tdist*tdist;
  157741. tdist = (x - maxc2) * C2_SCALE;
  157742. max_dist += tdist*tdist;
  157743. } else if (x > maxc2) {
  157744. tdist = (x - maxc2) * C2_SCALE;
  157745. min_dist += tdist*tdist;
  157746. tdist = (x - minc2) * C2_SCALE;
  157747. max_dist += tdist*tdist;
  157748. } else {
  157749. if (x <= centerc2) {
  157750. tdist = (x - maxc2) * C2_SCALE;
  157751. max_dist += tdist*tdist;
  157752. } else {
  157753. tdist = (x - minc2) * C2_SCALE;
  157754. max_dist += tdist*tdist;
  157755. }
  157756. }
  157757. mindist[i] = min_dist; /* save away the results */
  157758. if (max_dist < minmaxdist)
  157759. minmaxdist = max_dist;
  157760. }
  157761. ncolors = 0;
  157762. for (i = 0; i < numcolors; i++) {
  157763. if (mindist[i] <= minmaxdist)
  157764. colorlist[ncolors++] = (JSAMPLE) i;
  157765. }
  157766. return ncolors;
  157767. }
  157768. LOCAL(void)
  157769. find_best_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
  157770. int numcolors, JSAMPLE colorlist[], JSAMPLE bestcolor[])
  157771. {
  157772. int ic0, ic1, ic2;
  157773. int i, icolor;
  157774. register INT32 * bptr; /* pointer into bestdist[] array */
  157775. JSAMPLE * cptr; /* pointer into bestcolor[] array */
  157776. INT32 dist0, dist1; /* initial distance values */
  157777. register INT32 dist2; /* current distance in inner loop */
  157778. INT32 xx0, xx1; /* distance increments */
  157779. register INT32 xx2;
  157780. INT32 inc0, inc1, inc2; /* initial values for increments */
  157781. INT32 bestdist[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS];
  157782. bptr = bestdist;
  157783. for (i = BOX_C0_ELEMS*BOX_C1_ELEMS*BOX_C2_ELEMS-1; i >= 0; i--)
  157784. *bptr++ = 0x7FFFFFFFL;
  157785. #define STEP_C0 ((1 << C0_SHIFT) * C0_SCALE)
  157786. #define STEP_C1 ((1 << C1_SHIFT) * C1_SCALE)
  157787. #define STEP_C2 ((1 << C2_SHIFT) * C2_SCALE)
  157788. for (i = 0; i < numcolors; i++) {
  157789. icolor = GETJSAMPLE(colorlist[i]);
  157790. inc0 = (minc0 - GETJSAMPLE(cinfo->colormap[0][icolor])) * C0_SCALE;
  157791. dist0 = inc0*inc0;
  157792. inc1 = (minc1 - GETJSAMPLE(cinfo->colormap[1][icolor])) * C1_SCALE;
  157793. dist0 += inc1*inc1;
  157794. inc2 = (minc2 - GETJSAMPLE(cinfo->colormap[2][icolor])) * C2_SCALE;
  157795. dist0 += inc2*inc2;
  157796. inc0 = inc0 * (2 * STEP_C0) + STEP_C0 * STEP_C0;
  157797. inc1 = inc1 * (2 * STEP_C1) + STEP_C1 * STEP_C1;
  157798. inc2 = inc2 * (2 * STEP_C2) + STEP_C2 * STEP_C2;
  157799. bptr = bestdist;
  157800. cptr = bestcolor;
  157801. xx0 = inc0;
  157802. for (ic0 = BOX_C0_ELEMS-1; ic0 >= 0; ic0--) {
  157803. dist1 = dist0;
  157804. xx1 = inc1;
  157805. for (ic1 = BOX_C1_ELEMS-1; ic1 >= 0; ic1--) {
  157806. dist2 = dist1;
  157807. xx2 = inc2;
  157808. for (ic2 = BOX_C2_ELEMS-1; ic2 >= 0; ic2--) {
  157809. if (dist2 < *bptr) {
  157810. *bptr = dist2;
  157811. *cptr = (JSAMPLE) icolor;
  157812. }
  157813. dist2 += xx2;
  157814. xx2 += 2 * STEP_C2 * STEP_C2;
  157815. bptr++;
  157816. cptr++;
  157817. }
  157818. dist1 += xx1;
  157819. xx1 += 2 * STEP_C1 * STEP_C1;
  157820. }
  157821. dist0 += xx0;
  157822. xx0 += 2 * STEP_C0 * STEP_C0;
  157823. }
  157824. }
  157825. }
  157826. LOCAL(void)
  157827. fill_inverse_cmap (j_decompress_ptr cinfo, int c0, int c1, int c2)
  157828. {
  157829. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157830. hist3d histogram = cquantize->histogram;
  157831. int minc0, minc1, minc2; /* lower left corner of update box */
  157832. int ic0, ic1, ic2;
  157833. register JSAMPLE * cptr; /* pointer into bestcolor[] array */
  157834. register histptr cachep; /* pointer into main cache array */
  157835. JSAMPLE colorlist[MAXNUMCOLORS];
  157836. int numcolors; /* number of candidate colors */
  157837. JSAMPLE bestcolor[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS];
  157838. c0 >>= BOX_C0_LOG;
  157839. c1 >>= BOX_C1_LOG;
  157840. c2 >>= BOX_C2_LOG;
  157841. minc0 = (c0 << BOX_C0_SHIFT) + ((1 << C0_SHIFT) >> 1);
  157842. minc1 = (c1 << BOX_C1_SHIFT) + ((1 << C1_SHIFT) >> 1);
  157843. minc2 = (c2 << BOX_C2_SHIFT) + ((1 << C2_SHIFT) >> 1);
  157844. numcolors = find_nearby_colors(cinfo, minc0, minc1, minc2, colorlist);
  157845. find_best_colors(cinfo, minc0, minc1, minc2, numcolors, colorlist,
  157846. bestcolor);
  157847. c0 <<= BOX_C0_LOG; /* convert ID back to base cell indexes */
  157848. c1 <<= BOX_C1_LOG;
  157849. c2 <<= BOX_C2_LOG;
  157850. cptr = bestcolor;
  157851. for (ic0 = 0; ic0 < BOX_C0_ELEMS; ic0++) {
  157852. for (ic1 = 0; ic1 < BOX_C1_ELEMS; ic1++) {
  157853. cachep = & histogram[c0+ic0][c1+ic1][c2];
  157854. for (ic2 = 0; ic2 < BOX_C2_ELEMS; ic2++) {
  157855. *cachep++ = (histcell) (GETJSAMPLE(*cptr++) + 1);
  157856. }
  157857. }
  157858. }
  157859. }
  157860. METHODDEF(void)
  157861. pass2_no_dither (j_decompress_ptr cinfo,
  157862. JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
  157863. {
  157864. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157865. hist3d histogram = cquantize->histogram;
  157866. register JSAMPROW inptr, outptr;
  157867. register histptr cachep;
  157868. register int c0, c1, c2;
  157869. int row;
  157870. JDIMENSION col;
  157871. JDIMENSION width = cinfo->output_width;
  157872. for (row = 0; row < num_rows; row++) {
  157873. inptr = input_buf[row];
  157874. outptr = output_buf[row];
  157875. for (col = width; col > 0; col--) {
  157876. c0 = GETJSAMPLE(*inptr++) >> C0_SHIFT;
  157877. c1 = GETJSAMPLE(*inptr++) >> C1_SHIFT;
  157878. c2 = GETJSAMPLE(*inptr++) >> C2_SHIFT;
  157879. cachep = & histogram[c0][c1][c2];
  157880. if (*cachep == 0)
  157881. fill_inverse_cmap(cinfo, c0,c1,c2);
  157882. *outptr++ = (JSAMPLE) (*cachep - 1);
  157883. }
  157884. }
  157885. }
  157886. METHODDEF(void)
  157887. pass2_fs_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 LOCFSERROR cur0, cur1, cur2; /* current error or pixel value */
  157893. LOCFSERROR belowerr0, belowerr1, belowerr2; /* error for pixel below cur */
  157894. LOCFSERROR bpreverr0, bpreverr1, bpreverr2; /* error for below/prev col */
  157895. register FSERRPTR errorptr; /* => fserrors[] at column before current */
  157896. JSAMPROW inptr; /* => current input pixel */
  157897. JSAMPROW outptr; /* => current output pixel */
  157898. histptr cachep;
  157899. int dir; /* +1 or -1 depending on direction */
  157900. int dir3; /* 3*dir, for advancing inptr & errorptr */
  157901. int row;
  157902. JDIMENSION col;
  157903. JDIMENSION width = cinfo->output_width;
  157904. JSAMPLE *range_limit = cinfo->sample_range_limit;
  157905. int *error_limit = cquantize->error_limiter;
  157906. JSAMPROW colormap0 = cinfo->colormap[0];
  157907. JSAMPROW colormap1 = cinfo->colormap[1];
  157908. JSAMPROW colormap2 = cinfo->colormap[2];
  157909. SHIFT_TEMPS
  157910. for (row = 0; row < num_rows; row++) {
  157911. inptr = input_buf[row];
  157912. outptr = output_buf[row];
  157913. if (cquantize->on_odd_row) {
  157914. inptr += (width-1) * 3; /* so point to rightmost pixel */
  157915. outptr += width-1;
  157916. dir = -1;
  157917. dir3 = -3;
  157918. errorptr = cquantize->fserrors + (width+1)*3; /* => entry after last column */
  157919. cquantize->on_odd_row = FALSE; /* flip for next time */
  157920. } else {
  157921. dir = 1;
  157922. dir3 = 3;
  157923. errorptr = cquantize->fserrors; /* => entry before first real column */
  157924. cquantize->on_odd_row = TRUE; /* flip for next time */
  157925. }
  157926. cur0 = cur1 = cur2 = 0;
  157927. belowerr0 = belowerr1 = belowerr2 = 0;
  157928. bpreverr0 = bpreverr1 = bpreverr2 = 0;
  157929. for (col = width; col > 0; col--) {
  157930. cur0 = RIGHT_SHIFT(cur0 + errorptr[dir3+0] + 8, 4);
  157931. cur1 = RIGHT_SHIFT(cur1 + errorptr[dir3+1] + 8, 4);
  157932. cur2 = RIGHT_SHIFT(cur2 + errorptr[dir3+2] + 8, 4);
  157933. cur0 = error_limit[cur0];
  157934. cur1 = error_limit[cur1];
  157935. cur2 = error_limit[cur2];
  157936. cur0 += GETJSAMPLE(inptr[0]);
  157937. cur1 += GETJSAMPLE(inptr[1]);
  157938. cur2 += GETJSAMPLE(inptr[2]);
  157939. cur0 = GETJSAMPLE(range_limit[cur0]);
  157940. cur1 = GETJSAMPLE(range_limit[cur1]);
  157941. cur2 = GETJSAMPLE(range_limit[cur2]);
  157942. cachep = & histogram[cur0>>C0_SHIFT][cur1>>C1_SHIFT][cur2>>C2_SHIFT];
  157943. if (*cachep == 0)
  157944. fill_inverse_cmap(cinfo, cur0>>C0_SHIFT,cur1>>C1_SHIFT,cur2>>C2_SHIFT);
  157945. { register int pixcode = *cachep - 1;
  157946. *outptr = (JSAMPLE) pixcode;
  157947. cur0 -= GETJSAMPLE(colormap0[pixcode]);
  157948. cur1 -= GETJSAMPLE(colormap1[pixcode]);
  157949. cur2 -= GETJSAMPLE(colormap2[pixcode]);
  157950. }
  157951. { register LOCFSERROR bnexterr, delta;
  157952. bnexterr = cur0; /* Process component 0 */
  157953. delta = cur0 * 2;
  157954. cur0 += delta; /* form error * 3 */
  157955. errorptr[0] = (FSERROR) (bpreverr0 + cur0);
  157956. cur0 += delta; /* form error * 5 */
  157957. bpreverr0 = belowerr0 + cur0;
  157958. belowerr0 = bnexterr;
  157959. cur0 += delta; /* form error * 7 */
  157960. bnexterr = cur1; /* Process component 1 */
  157961. delta = cur1 * 2;
  157962. cur1 += delta; /* form error * 3 */
  157963. errorptr[1] = (FSERROR) (bpreverr1 + cur1);
  157964. cur1 += delta; /* form error * 5 */
  157965. bpreverr1 = belowerr1 + cur1;
  157966. belowerr1 = bnexterr;
  157967. cur1 += delta; /* form error * 7 */
  157968. bnexterr = cur2; /* Process component 2 */
  157969. delta = cur2 * 2;
  157970. cur2 += delta; /* form error * 3 */
  157971. errorptr[2] = (FSERROR) (bpreverr2 + cur2);
  157972. cur2 += delta; /* form error * 5 */
  157973. bpreverr2 = belowerr2 + cur2;
  157974. belowerr2 = bnexterr;
  157975. cur2 += delta; /* form error * 7 */
  157976. }
  157977. inptr += dir3; /* Advance pixel pointers to next column */
  157978. outptr += dir;
  157979. errorptr += dir3; /* advance errorptr to current column */
  157980. }
  157981. errorptr[0] = (FSERROR) bpreverr0; /* unload prev errs into array */
  157982. errorptr[1] = (FSERROR) bpreverr1;
  157983. errorptr[2] = (FSERROR) bpreverr2;
  157984. }
  157985. }
  157986. LOCAL(void)
  157987. init_error_limit (j_decompress_ptr cinfo)
  157988. {
  157989. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157990. int * table;
  157991. int in, out;
  157992. table = (int *) (*cinfo->mem->alloc_small)
  157993. ((j_common_ptr) cinfo, JPOOL_IMAGE, (MAXJSAMPLE*2+1) * SIZEOF(int));
  157994. table += MAXJSAMPLE; /* so can index -MAXJSAMPLE .. +MAXJSAMPLE */
  157995. cquantize->error_limiter = table;
  157996. #define STEPSIZE ((MAXJSAMPLE+1)/16)
  157997. out = 0;
  157998. for (in = 0; in < STEPSIZE; in++, out++) {
  157999. table[in] = out; table[-in] = -out;
  158000. }
  158001. for (; in < STEPSIZE*3; in++, out += (in&1) ? 0 : 1) {
  158002. table[in] = out; table[-in] = -out;
  158003. }
  158004. for (; in <= MAXJSAMPLE; in++) {
  158005. table[in] = out; table[-in] = -out;
  158006. }
  158007. #undef STEPSIZE
  158008. }
  158009. METHODDEF(void)
  158010. finish_pass1 (j_decompress_ptr cinfo)
  158011. {
  158012. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158013. cinfo->colormap = cquantize->sv_colormap;
  158014. select_colors(cinfo, cquantize->desired);
  158015. cquantize->needs_zeroed = TRUE;
  158016. }
  158017. METHODDEF(void)
  158018. finish_pass2 (j_decompress_ptr cinfo)
  158019. {
  158020. }
  158021. METHODDEF(void)
  158022. start_pass_2_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
  158023. {
  158024. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158025. hist3d histogram = cquantize->histogram;
  158026. int i;
  158027. if (cinfo->dither_mode != JDITHER_NONE)
  158028. cinfo->dither_mode = JDITHER_FS;
  158029. if (is_pre_scan) {
  158030. cquantize->pub.color_quantize = prescan_quantize;
  158031. cquantize->pub.finish_pass = finish_pass1;
  158032. cquantize->needs_zeroed = TRUE; /* Always zero histogram */
  158033. } else {
  158034. if (cinfo->dither_mode == JDITHER_FS)
  158035. cquantize->pub.color_quantize = pass2_fs_dither;
  158036. else
  158037. cquantize->pub.color_quantize = pass2_no_dither;
  158038. cquantize->pub.finish_pass = finish_pass2;
  158039. i = cinfo->actual_number_of_colors;
  158040. if (i < 1)
  158041. ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, 1);
  158042. if (i > MAXNUMCOLORS)
  158043. ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);
  158044. if (cinfo->dither_mode == JDITHER_FS) {
  158045. size_t arraysize = (size_t) ((cinfo->output_width + 2) *
  158046. (3 * SIZEOF(FSERROR)));
  158047. if (cquantize->fserrors == NULL)
  158048. cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large)
  158049. ((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize);
  158050. jzero_far((void FAR *) cquantize->fserrors, arraysize);
  158051. if (cquantize->error_limiter == NULL)
  158052. init_error_limit(cinfo);
  158053. cquantize->on_odd_row = FALSE;
  158054. }
  158055. }
  158056. if (cquantize->needs_zeroed) {
  158057. for (i = 0; i < HIST_C0_ELEMS; i++) {
  158058. jzero_far((void FAR *) histogram[i],
  158059. HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell));
  158060. }
  158061. cquantize->needs_zeroed = FALSE;
  158062. }
  158063. }
  158064. METHODDEF(void)
  158065. new_color_map_2_quant (j_decompress_ptr cinfo)
  158066. {
  158067. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158068. cquantize->needs_zeroed = TRUE;
  158069. }
  158070. GLOBAL(void)
  158071. jinit_2pass_quantizer (j_decompress_ptr cinfo)
  158072. {
  158073. my_cquantize_ptr2 cquantize;
  158074. int i;
  158075. cquantize = (my_cquantize_ptr2)
  158076. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  158077. SIZEOF(my_cquantizer2));
  158078. cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize;
  158079. cquantize->pub.start_pass = start_pass_2_quant;
  158080. cquantize->pub.new_color_map = new_color_map_2_quant;
  158081. cquantize->fserrors = NULL; /* flag optional arrays not allocated */
  158082. cquantize->error_limiter = NULL;
  158083. if (cinfo->out_color_components != 3)
  158084. ERREXIT(cinfo, JERR_NOTIMPL);
  158085. cquantize->histogram = (hist3d) (*cinfo->mem->alloc_small)
  158086. ((j_common_ptr) cinfo, JPOOL_IMAGE, HIST_C0_ELEMS * SIZEOF(hist2d));
  158087. for (i = 0; i < HIST_C0_ELEMS; i++) {
  158088. cquantize->histogram[i] = (hist2d) (*cinfo->mem->alloc_large)
  158089. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  158090. HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell));
  158091. }
  158092. cquantize->needs_zeroed = TRUE; /* histogram is garbage now */
  158093. if (cinfo->enable_2pass_quant) {
  158094. int desired = cinfo->desired_number_of_colors;
  158095. if (desired < 8)
  158096. ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, 8);
  158097. if (desired > MAXNUMCOLORS)
  158098. ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);
  158099. cquantize->sv_colormap = (*cinfo->mem->alloc_sarray)
  158100. ((j_common_ptr) cinfo,JPOOL_IMAGE, (JDIMENSION) desired, (JDIMENSION) 3);
  158101. cquantize->desired = desired;
  158102. } else
  158103. cquantize->sv_colormap = NULL;
  158104. if (cinfo->dither_mode != JDITHER_NONE)
  158105. cinfo->dither_mode = JDITHER_FS;
  158106. if (cinfo->dither_mode == JDITHER_FS) {
  158107. cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large)
  158108. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  158109. (size_t) ((cinfo->output_width + 2) * (3 * SIZEOF(FSERROR))));
  158110. init_error_limit(cinfo);
  158111. }
  158112. }
  158113. #endif /* QUANT_2PASS_SUPPORTED */
  158114. /*** End of inlined file: jquant2.c ***/
  158115. /*** Start of inlined file: jutils.c ***/
  158116. #define JPEG_INTERNALS
  158117. #if 0 /* This table is not actually needed in v6a */
  158118. const int jpeg_zigzag_order[DCTSIZE2] = {
  158119. 0, 1, 5, 6, 14, 15, 27, 28,
  158120. 2, 4, 7, 13, 16, 26, 29, 42,
  158121. 3, 8, 12, 17, 25, 30, 41, 43,
  158122. 9, 11, 18, 24, 31, 40, 44, 53,
  158123. 10, 19, 23, 32, 39, 45, 52, 54,
  158124. 20, 22, 33, 38, 46, 51, 55, 60,
  158125. 21, 34, 37, 47, 50, 56, 59, 61,
  158126. 35, 36, 48, 49, 57, 58, 62, 63
  158127. };
  158128. #endif
  158129. const int jpeg_natural_order[DCTSIZE2+16] = {
  158130. 0, 1, 8, 16, 9, 2, 3, 10,
  158131. 17, 24, 32, 25, 18, 11, 4, 5,
  158132. 12, 19, 26, 33, 40, 48, 41, 34,
  158133. 27, 20, 13, 6, 7, 14, 21, 28,
  158134. 35, 42, 49, 56, 57, 50, 43, 36,
  158135. 29, 22, 15, 23, 30, 37, 44, 51,
  158136. 58, 59, 52, 45, 38, 31, 39, 46,
  158137. 53, 60, 61, 54, 47, 55, 62, 63,
  158138. 63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */
  158139. 63, 63, 63, 63, 63, 63, 63, 63
  158140. };
  158141. GLOBAL(long)
  158142. jdiv_round_up (long a, long b)
  158143. {
  158144. return (a + b - 1L) / b;
  158145. }
  158146. GLOBAL(long)
  158147. jround_up (long a, long b)
  158148. {
  158149. a += b - 1L;
  158150. return a - (a % b);
  158151. }
  158152. #ifndef NEED_FAR_POINTERS /* normal case, same as regular macros */
  158153. #define FMEMCOPY(dest,src,size) MEMCOPY(dest,src,size)
  158154. #define FMEMZERO(target,size) MEMZERO(target,size)
  158155. #else /* 80x86 case, define if we can */
  158156. #ifdef USE_FMEM
  158157. #define FMEMCOPY(dest,src,size) _fmemcpy((void FAR *)(dest), (const void FAR *)(src), (size_t)(size))
  158158. #define FMEMZERO(target,size) _fmemset((void FAR *)(target), 0, (size_t)(size))
  158159. #endif
  158160. #endif
  158161. GLOBAL(void)
  158162. jcopy_sample_rows (JSAMPARRAY input_array, int source_row,
  158163. JSAMPARRAY output_array, int dest_row,
  158164. int num_rows, JDIMENSION num_cols)
  158165. {
  158166. register JSAMPROW inptr, outptr;
  158167. #ifdef FMEMCOPY
  158168. register size_t count = (size_t) (num_cols * SIZEOF(JSAMPLE));
  158169. #else
  158170. register JDIMENSION count;
  158171. #endif
  158172. register int row;
  158173. input_array += source_row;
  158174. output_array += dest_row;
  158175. for (row = num_rows; row > 0; row--) {
  158176. inptr = *input_array++;
  158177. outptr = *output_array++;
  158178. #ifdef FMEMCOPY
  158179. FMEMCOPY(outptr, inptr, count);
  158180. #else
  158181. for (count = num_cols; count > 0; count--)
  158182. *outptr++ = *inptr++; /* needn't bother with GETJSAMPLE() here */
  158183. #endif
  158184. }
  158185. }
  158186. GLOBAL(void)
  158187. jcopy_block_row (JBLOCKROW input_row, JBLOCKROW output_row,
  158188. JDIMENSION num_blocks)
  158189. {
  158190. #ifdef FMEMCOPY
  158191. FMEMCOPY(output_row, input_row, num_blocks * (DCTSIZE2 * SIZEOF(JCOEF)));
  158192. #else
  158193. register JCOEFPTR inptr, outptr;
  158194. register long count;
  158195. inptr = (JCOEFPTR) input_row;
  158196. outptr = (JCOEFPTR) output_row;
  158197. for (count = (long) num_blocks * DCTSIZE2; count > 0; count--) {
  158198. *outptr++ = *inptr++;
  158199. }
  158200. #endif
  158201. }
  158202. GLOBAL(void)
  158203. jzero_far (void FAR * target, size_t bytestozero)
  158204. {
  158205. #ifdef FMEMZERO
  158206. FMEMZERO(target, bytestozero);
  158207. #else
  158208. register char FAR * ptr = (char FAR *) target;
  158209. register size_t count;
  158210. for (count = bytestozero; count > 0; count--) {
  158211. *ptr++ = 0;
  158212. }
  158213. #endif
  158214. }
  158215. /*** End of inlined file: jutils.c ***/
  158216. /*** Start of inlined file: transupp.c ***/
  158217. #define JPEG_INTERNALS
  158218. /*** Start of inlined file: transupp.h ***/
  158219. #ifndef TRANSFORMS_SUPPORTED
  158220. #define TRANSFORMS_SUPPORTED 1 /* 0 disables transform code */
  158221. #endif
  158222. #ifdef NEED_SHORT_EXTERNAL_NAMES
  158223. #define jtransform_request_workspace jTrRequest
  158224. #define jtransform_adjust_parameters jTrAdjust
  158225. #define jtransform_execute_transformation jTrExec
  158226. #define jcopy_markers_setup jCMrkSetup
  158227. #define jcopy_markers_execute jCMrkExec
  158228. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  158229. typedef enum {
  158230. JXFORM_NONE, /* no transformation */
  158231. JXFORM_FLIP_H, /* horizontal flip */
  158232. JXFORM_FLIP_V, /* vertical flip */
  158233. JXFORM_TRANSPOSE, /* transpose across UL-to-LR axis */
  158234. JXFORM_TRANSVERSE, /* transpose across UR-to-LL axis */
  158235. JXFORM_ROT_90, /* 90-degree clockwise rotation */
  158236. JXFORM_ROT_180, /* 180-degree rotation */
  158237. JXFORM_ROT_270 /* 270-degree clockwise (or 90 ccw) */
  158238. } JXFORM_CODE;
  158239. typedef struct {
  158240. JXFORM_CODE transform; /* image transform operator */
  158241. boolean trim; /* if TRUE, trim partial MCUs as needed */
  158242. boolean force_grayscale; /* if TRUE, convert color image to grayscale */
  158243. int num_components; /* # of components in workspace */
  158244. jvirt_barray_ptr * workspace_coef_arrays; /* workspace for transformations */
  158245. } jpeg_transform_info;
  158246. #if TRANSFORMS_SUPPORTED
  158247. EXTERN(void) jtransform_request_workspace
  158248. JPP((j_decompress_ptr srcinfo, jpeg_transform_info *info));
  158249. EXTERN(jvirt_barray_ptr *) jtransform_adjust_parameters
  158250. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158251. jvirt_barray_ptr *src_coef_arrays,
  158252. jpeg_transform_info *info));
  158253. EXTERN(void) jtransform_execute_transformation
  158254. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158255. jvirt_barray_ptr *src_coef_arrays,
  158256. jpeg_transform_info *info));
  158257. #endif /* TRANSFORMS_SUPPORTED */
  158258. typedef enum {
  158259. JCOPYOPT_NONE, /* copy no optional markers */
  158260. JCOPYOPT_COMMENTS, /* copy only comment (COM) markers */
  158261. JCOPYOPT_ALL /* copy all optional markers */
  158262. } JCOPY_OPTION;
  158263. #define JCOPYOPT_DEFAULT JCOPYOPT_COMMENTS /* recommended default */
  158264. EXTERN(void) jcopy_markers_setup
  158265. JPP((j_decompress_ptr srcinfo, JCOPY_OPTION option));
  158266. EXTERN(void) jcopy_markers_execute
  158267. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158268. JCOPY_OPTION option));
  158269. /*** End of inlined file: transupp.h ***/
  158270. /* My own external interface */
  158271. #if TRANSFORMS_SUPPORTED
  158272. LOCAL(void)
  158273. do_flip_h (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158274. jvirt_barray_ptr *src_coef_arrays)
  158275. {
  158276. JDIMENSION MCU_cols, comp_width, blk_x, blk_y;
  158277. int ci, k, offset_y;
  158278. JBLOCKARRAY buffer;
  158279. JCOEFPTR ptr1, ptr2;
  158280. JCOEF temp1, temp2;
  158281. jpeg_component_info *compptr;
  158282. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158283. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158284. compptr = dstinfo->comp_info + ci;
  158285. comp_width = MCU_cols * compptr->h_samp_factor;
  158286. for (blk_y = 0; blk_y < compptr->height_in_blocks;
  158287. blk_y += compptr->v_samp_factor) {
  158288. buffer = (*srcinfo->mem->access_virt_barray)
  158289. ((j_common_ptr) srcinfo, src_coef_arrays[ci], blk_y,
  158290. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158291. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158292. for (blk_x = 0; blk_x * 2 < comp_width; blk_x++) {
  158293. ptr1 = buffer[offset_y][blk_x];
  158294. ptr2 = buffer[offset_y][comp_width - blk_x - 1];
  158295. for (k = 0; k < DCTSIZE2; k += 2) {
  158296. temp1 = *ptr1; /* swap even column */
  158297. temp2 = *ptr2;
  158298. *ptr1++ = temp2;
  158299. *ptr2++ = temp1;
  158300. temp1 = *ptr1; /* swap odd column with sign change */
  158301. temp2 = *ptr2;
  158302. *ptr1++ = -temp2;
  158303. *ptr2++ = -temp1;
  158304. }
  158305. }
  158306. }
  158307. }
  158308. }
  158309. }
  158310. LOCAL(void)
  158311. do_flip_v (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158312. jvirt_barray_ptr *src_coef_arrays,
  158313. jvirt_barray_ptr *dst_coef_arrays)
  158314. {
  158315. JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y;
  158316. int ci, i, j, offset_y;
  158317. JBLOCKARRAY src_buffer, dst_buffer;
  158318. JBLOCKROW src_row_ptr, dst_row_ptr;
  158319. JCOEFPTR src_ptr, dst_ptr;
  158320. jpeg_component_info *compptr;
  158321. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158322. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158323. compptr = dstinfo->comp_info + ci;
  158324. comp_height = MCU_rows * compptr->v_samp_factor;
  158325. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158326. dst_blk_y += compptr->v_samp_factor) {
  158327. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158328. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158329. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158330. if (dst_blk_y < comp_height) {
  158331. src_buffer = (*srcinfo->mem->access_virt_barray)
  158332. ((j_common_ptr) srcinfo, src_coef_arrays[ci],
  158333. comp_height - dst_blk_y - (JDIMENSION) compptr->v_samp_factor,
  158334. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158335. } else {
  158336. src_buffer = (*srcinfo->mem->access_virt_barray)
  158337. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_y,
  158338. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158339. }
  158340. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158341. if (dst_blk_y < comp_height) {
  158342. dst_row_ptr = dst_buffer[offset_y];
  158343. src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1];
  158344. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158345. dst_blk_x++) {
  158346. dst_ptr = dst_row_ptr[dst_blk_x];
  158347. src_ptr = src_row_ptr[dst_blk_x];
  158348. for (i = 0; i < DCTSIZE; i += 2) {
  158349. for (j = 0; j < DCTSIZE; j++)
  158350. *dst_ptr++ = *src_ptr++;
  158351. for (j = 0; j < DCTSIZE; j++)
  158352. *dst_ptr++ = - *src_ptr++;
  158353. }
  158354. }
  158355. } else {
  158356. jcopy_block_row(src_buffer[offset_y], dst_buffer[offset_y],
  158357. compptr->width_in_blocks);
  158358. }
  158359. }
  158360. }
  158361. }
  158362. }
  158363. LOCAL(void)
  158364. do_transpose (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158365. jvirt_barray_ptr *src_coef_arrays,
  158366. jvirt_barray_ptr *dst_coef_arrays)
  158367. {
  158368. JDIMENSION dst_blk_x, dst_blk_y;
  158369. int ci, i, j, offset_x, offset_y;
  158370. JBLOCKARRAY src_buffer, dst_buffer;
  158371. JCOEFPTR src_ptr, dst_ptr;
  158372. jpeg_component_info *compptr;
  158373. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158374. compptr = dstinfo->comp_info + ci;
  158375. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158376. dst_blk_y += compptr->v_samp_factor) {
  158377. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158378. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158379. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158380. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158381. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158382. dst_blk_x += compptr->h_samp_factor) {
  158383. src_buffer = (*srcinfo->mem->access_virt_barray)
  158384. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158385. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158386. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158387. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158388. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158389. for (i = 0; i < DCTSIZE; i++)
  158390. for (j = 0; j < DCTSIZE; j++)
  158391. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158392. }
  158393. }
  158394. }
  158395. }
  158396. }
  158397. }
  158398. LOCAL(void)
  158399. do_rot_90 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158400. jvirt_barray_ptr *src_coef_arrays,
  158401. jvirt_barray_ptr *dst_coef_arrays)
  158402. {
  158403. JDIMENSION MCU_cols, comp_width, dst_blk_x, dst_blk_y;
  158404. int ci, i, j, offset_x, offset_y;
  158405. JBLOCKARRAY src_buffer, dst_buffer;
  158406. JCOEFPTR src_ptr, dst_ptr;
  158407. jpeg_component_info *compptr;
  158408. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158409. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158410. compptr = dstinfo->comp_info + ci;
  158411. comp_width = MCU_cols * compptr->h_samp_factor;
  158412. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158413. dst_blk_y += compptr->v_samp_factor) {
  158414. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158415. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158416. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158417. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158418. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158419. dst_blk_x += compptr->h_samp_factor) {
  158420. src_buffer = (*srcinfo->mem->access_virt_barray)
  158421. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158422. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158423. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158424. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158425. if (dst_blk_x < comp_width) {
  158426. dst_ptr = dst_buffer[offset_y]
  158427. [comp_width - dst_blk_x - offset_x - 1];
  158428. for (i = 0; i < DCTSIZE; i++) {
  158429. for (j = 0; j < DCTSIZE; j++)
  158430. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158431. i++;
  158432. for (j = 0; j < DCTSIZE; j++)
  158433. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158434. }
  158435. } else {
  158436. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158437. for (i = 0; i < DCTSIZE; i++)
  158438. for (j = 0; j < DCTSIZE; j++)
  158439. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158440. }
  158441. }
  158442. }
  158443. }
  158444. }
  158445. }
  158446. }
  158447. LOCAL(void)
  158448. do_rot_270 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158449. jvirt_barray_ptr *src_coef_arrays,
  158450. jvirt_barray_ptr *dst_coef_arrays)
  158451. {
  158452. JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y;
  158453. int ci, i, j, offset_x, offset_y;
  158454. JBLOCKARRAY src_buffer, dst_buffer;
  158455. JCOEFPTR src_ptr, dst_ptr;
  158456. jpeg_component_info *compptr;
  158457. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158458. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158459. compptr = dstinfo->comp_info + ci;
  158460. comp_height = MCU_rows * compptr->v_samp_factor;
  158461. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158462. dst_blk_y += compptr->v_samp_factor) {
  158463. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158464. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158465. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158466. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158467. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158468. dst_blk_x += compptr->h_samp_factor) {
  158469. src_buffer = (*srcinfo->mem->access_virt_barray)
  158470. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158471. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158472. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158473. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158474. if (dst_blk_y < comp_height) {
  158475. src_ptr = src_buffer[offset_x]
  158476. [comp_height - dst_blk_y - offset_y - 1];
  158477. for (i = 0; i < DCTSIZE; i++) {
  158478. for (j = 0; j < DCTSIZE; j++) {
  158479. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158480. j++;
  158481. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158482. }
  158483. }
  158484. } else {
  158485. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158486. for (i = 0; i < DCTSIZE; i++)
  158487. for (j = 0; j < DCTSIZE; j++)
  158488. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158489. }
  158490. }
  158491. }
  158492. }
  158493. }
  158494. }
  158495. }
  158496. LOCAL(void)
  158497. do_rot_180 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158498. jvirt_barray_ptr *src_coef_arrays,
  158499. jvirt_barray_ptr *dst_coef_arrays)
  158500. {
  158501. JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y;
  158502. int ci, i, j, offset_y;
  158503. JBLOCKARRAY src_buffer, dst_buffer;
  158504. JBLOCKROW src_row_ptr, dst_row_ptr;
  158505. JCOEFPTR src_ptr, dst_ptr;
  158506. jpeg_component_info *compptr;
  158507. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158508. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158509. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158510. compptr = dstinfo->comp_info + ci;
  158511. comp_width = MCU_cols * compptr->h_samp_factor;
  158512. comp_height = MCU_rows * compptr->v_samp_factor;
  158513. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158514. dst_blk_y += compptr->v_samp_factor) {
  158515. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158516. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158517. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158518. if (dst_blk_y < comp_height) {
  158519. src_buffer = (*srcinfo->mem->access_virt_barray)
  158520. ((j_common_ptr) srcinfo, src_coef_arrays[ci],
  158521. comp_height - dst_blk_y - (JDIMENSION) compptr->v_samp_factor,
  158522. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158523. } else {
  158524. src_buffer = (*srcinfo->mem->access_virt_barray)
  158525. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_y,
  158526. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158527. }
  158528. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158529. if (dst_blk_y < comp_height) {
  158530. dst_row_ptr = dst_buffer[offset_y];
  158531. src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1];
  158532. for (dst_blk_x = 0; dst_blk_x < comp_width; dst_blk_x++) {
  158533. dst_ptr = dst_row_ptr[dst_blk_x];
  158534. src_ptr = src_row_ptr[comp_width - dst_blk_x - 1];
  158535. for (i = 0; i < DCTSIZE; i += 2) {
  158536. for (j = 0; j < DCTSIZE; j += 2) {
  158537. *dst_ptr++ = *src_ptr++;
  158538. *dst_ptr++ = - *src_ptr++;
  158539. }
  158540. for (j = 0; j < DCTSIZE; j += 2) {
  158541. *dst_ptr++ = - *src_ptr++;
  158542. *dst_ptr++ = *src_ptr++;
  158543. }
  158544. }
  158545. }
  158546. for (; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) {
  158547. dst_ptr = dst_row_ptr[dst_blk_x];
  158548. src_ptr = src_row_ptr[dst_blk_x];
  158549. for (i = 0; i < DCTSIZE; i += 2) {
  158550. for (j = 0; j < DCTSIZE; j++)
  158551. *dst_ptr++ = *src_ptr++;
  158552. for (j = 0; j < DCTSIZE; j++)
  158553. *dst_ptr++ = - *src_ptr++;
  158554. }
  158555. }
  158556. } else {
  158557. dst_row_ptr = dst_buffer[offset_y];
  158558. src_row_ptr = src_buffer[offset_y];
  158559. for (dst_blk_x = 0; dst_blk_x < comp_width; dst_blk_x++) {
  158560. dst_ptr = dst_row_ptr[dst_blk_x];
  158561. src_ptr = src_row_ptr[comp_width - dst_blk_x - 1];
  158562. for (i = 0; i < DCTSIZE2; i += 2) {
  158563. *dst_ptr++ = *src_ptr++;
  158564. *dst_ptr++ = - *src_ptr++;
  158565. }
  158566. }
  158567. for (; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) {
  158568. dst_ptr = dst_row_ptr[dst_blk_x];
  158569. src_ptr = src_row_ptr[dst_blk_x];
  158570. for (i = 0; i < DCTSIZE2; i++)
  158571. *dst_ptr++ = *src_ptr++;
  158572. }
  158573. }
  158574. }
  158575. }
  158576. }
  158577. }
  158578. LOCAL(void)
  158579. do_transverse (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158580. jvirt_barray_ptr *src_coef_arrays,
  158581. jvirt_barray_ptr *dst_coef_arrays)
  158582. {
  158583. JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y;
  158584. int ci, i, j, offset_x, offset_y;
  158585. JBLOCKARRAY src_buffer, dst_buffer;
  158586. JCOEFPTR src_ptr, dst_ptr;
  158587. jpeg_component_info *compptr;
  158588. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158589. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158590. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158591. compptr = dstinfo->comp_info + ci;
  158592. comp_width = MCU_cols * compptr->h_samp_factor;
  158593. comp_height = MCU_rows * compptr->v_samp_factor;
  158594. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158595. dst_blk_y += compptr->v_samp_factor) {
  158596. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158597. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158598. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158599. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158600. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158601. dst_blk_x += compptr->h_samp_factor) {
  158602. src_buffer = (*srcinfo->mem->access_virt_barray)
  158603. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158604. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158605. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158606. if (dst_blk_y < comp_height) {
  158607. src_ptr = src_buffer[offset_x]
  158608. [comp_height - dst_blk_y - offset_y - 1];
  158609. if (dst_blk_x < comp_width) {
  158610. dst_ptr = dst_buffer[offset_y]
  158611. [comp_width - dst_blk_x - offset_x - 1];
  158612. for (i = 0; i < DCTSIZE; i++) {
  158613. for (j = 0; j < DCTSIZE; j++) {
  158614. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158615. j++;
  158616. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158617. }
  158618. i++;
  158619. for (j = 0; j < DCTSIZE; j++) {
  158620. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158621. j++;
  158622. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158623. }
  158624. }
  158625. } else {
  158626. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158627. for (i = 0; i < DCTSIZE; i++) {
  158628. for (j = 0; j < DCTSIZE; j++) {
  158629. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158630. j++;
  158631. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158632. }
  158633. }
  158634. }
  158635. } else {
  158636. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158637. if (dst_blk_x < comp_width) {
  158638. dst_ptr = dst_buffer[offset_y]
  158639. [comp_width - dst_blk_x - offset_x - 1];
  158640. for (i = 0; i < DCTSIZE; i++) {
  158641. for (j = 0; j < DCTSIZE; j++)
  158642. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158643. i++;
  158644. for (j = 0; j < DCTSIZE; j++)
  158645. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158646. }
  158647. } else {
  158648. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158649. for (i = 0; i < DCTSIZE; i++)
  158650. for (j = 0; j < DCTSIZE; j++)
  158651. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158652. }
  158653. }
  158654. }
  158655. }
  158656. }
  158657. }
  158658. }
  158659. }
  158660. GLOBAL(void)
  158661. jtransform_request_workspace (j_decompress_ptr srcinfo,
  158662. jpeg_transform_info *info)
  158663. {
  158664. jvirt_barray_ptr *coef_arrays = NULL;
  158665. jpeg_component_info *compptr;
  158666. int ci;
  158667. if (info->force_grayscale &&
  158668. srcinfo->jpeg_color_space == JCS_YCbCr &&
  158669. srcinfo->num_components == 3) {
  158670. info->num_components = 1;
  158671. } else {
  158672. info->num_components = srcinfo->num_components;
  158673. }
  158674. switch (info->transform) {
  158675. case JXFORM_NONE:
  158676. case JXFORM_FLIP_H:
  158677. break;
  158678. case JXFORM_FLIP_V:
  158679. case JXFORM_ROT_180:
  158680. coef_arrays = (jvirt_barray_ptr *)
  158681. (*srcinfo->mem->alloc_small) ((j_common_ptr) srcinfo, JPOOL_IMAGE,
  158682. SIZEOF(jvirt_barray_ptr) * info->num_components);
  158683. for (ci = 0; ci < info->num_components; ci++) {
  158684. compptr = srcinfo->comp_info + ci;
  158685. coef_arrays[ci] = (*srcinfo->mem->request_virt_barray)
  158686. ((j_common_ptr) srcinfo, JPOOL_IMAGE, FALSE,
  158687. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  158688. (long) compptr->h_samp_factor),
  158689. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  158690. (long) compptr->v_samp_factor),
  158691. (JDIMENSION) compptr->v_samp_factor);
  158692. }
  158693. break;
  158694. case JXFORM_TRANSPOSE:
  158695. case JXFORM_TRANSVERSE:
  158696. case JXFORM_ROT_90:
  158697. case JXFORM_ROT_270:
  158698. coef_arrays = (jvirt_barray_ptr *)
  158699. (*srcinfo->mem->alloc_small) ((j_common_ptr) srcinfo, JPOOL_IMAGE,
  158700. SIZEOF(jvirt_barray_ptr) * info->num_components);
  158701. for (ci = 0; ci < info->num_components; ci++) {
  158702. compptr = srcinfo->comp_info + ci;
  158703. coef_arrays[ci] = (*srcinfo->mem->request_virt_barray)
  158704. ((j_common_ptr) srcinfo, JPOOL_IMAGE, FALSE,
  158705. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  158706. (long) compptr->v_samp_factor),
  158707. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  158708. (long) compptr->h_samp_factor),
  158709. (JDIMENSION) compptr->h_samp_factor);
  158710. }
  158711. break;
  158712. }
  158713. info->workspace_coef_arrays = coef_arrays;
  158714. }
  158715. LOCAL(void)
  158716. transpose_critical_parameters (j_compress_ptr dstinfo)
  158717. {
  158718. int tblno, i, j, ci, itemp;
  158719. jpeg_component_info *compptr;
  158720. JQUANT_TBL *qtblptr;
  158721. JDIMENSION dtemp;
  158722. UINT16 qtemp;
  158723. dtemp = dstinfo->image_width;
  158724. dstinfo->image_width = dstinfo->image_height;
  158725. dstinfo->image_height = dtemp;
  158726. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158727. compptr = dstinfo->comp_info + ci;
  158728. itemp = compptr->h_samp_factor;
  158729. compptr->h_samp_factor = compptr->v_samp_factor;
  158730. compptr->v_samp_factor = itemp;
  158731. }
  158732. for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) {
  158733. qtblptr = dstinfo->quant_tbl_ptrs[tblno];
  158734. if (qtblptr != NULL) {
  158735. for (i = 0; i < DCTSIZE; i++) {
  158736. for (j = 0; j < i; j++) {
  158737. qtemp = qtblptr->quantval[i*DCTSIZE+j];
  158738. qtblptr->quantval[i*DCTSIZE+j] = qtblptr->quantval[j*DCTSIZE+i];
  158739. qtblptr->quantval[j*DCTSIZE+i] = qtemp;
  158740. }
  158741. }
  158742. }
  158743. }
  158744. }
  158745. LOCAL(void)
  158746. trim_right_edge (j_compress_ptr dstinfo)
  158747. {
  158748. int ci, max_h_samp_factor;
  158749. JDIMENSION MCU_cols;
  158750. max_h_samp_factor = 1;
  158751. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158752. int h_samp_factor = dstinfo->comp_info[ci].h_samp_factor;
  158753. max_h_samp_factor = MAX(max_h_samp_factor, h_samp_factor);
  158754. }
  158755. MCU_cols = dstinfo->image_width / (max_h_samp_factor * DCTSIZE);
  158756. if (MCU_cols > 0) /* can't trim to 0 pixels */
  158757. dstinfo->image_width = MCU_cols * (max_h_samp_factor * DCTSIZE);
  158758. }
  158759. LOCAL(void)
  158760. trim_bottom_edge (j_compress_ptr dstinfo)
  158761. {
  158762. int ci, max_v_samp_factor;
  158763. JDIMENSION MCU_rows;
  158764. max_v_samp_factor = 1;
  158765. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158766. int v_samp_factor = dstinfo->comp_info[ci].v_samp_factor;
  158767. max_v_samp_factor = MAX(max_v_samp_factor, v_samp_factor);
  158768. }
  158769. MCU_rows = dstinfo->image_height / (max_v_samp_factor * DCTSIZE);
  158770. if (MCU_rows > 0) /* can't trim to 0 pixels */
  158771. dstinfo->image_height = MCU_rows * (max_v_samp_factor * DCTSIZE);
  158772. }
  158773. GLOBAL(jvirt_barray_ptr *)
  158774. jtransform_adjust_parameters (j_decompress_ptr srcinfo,
  158775. j_compress_ptr dstinfo,
  158776. jvirt_barray_ptr *src_coef_arrays,
  158777. jpeg_transform_info *info)
  158778. {
  158779. if (info->force_grayscale) {
  158780. if ((dstinfo->jpeg_color_space == JCS_YCbCr &&
  158781. dstinfo->num_components == 3) ||
  158782. (dstinfo->jpeg_color_space == JCS_GRAYSCALE &&
  158783. dstinfo->num_components == 1)) {
  158784. int sv_quant_tbl_no = dstinfo->comp_info[0].quant_tbl_no;
  158785. jpeg_set_colorspace(dstinfo, JCS_GRAYSCALE);
  158786. dstinfo->comp_info[0].quant_tbl_no = sv_quant_tbl_no;
  158787. } else {
  158788. ERREXIT(dstinfo, JERR_CONVERSION_NOTIMPL);
  158789. }
  158790. }
  158791. switch (info->transform) {
  158792. case JXFORM_NONE:
  158793. break;
  158794. case JXFORM_FLIP_H:
  158795. if (info->trim)
  158796. trim_right_edge(dstinfo);
  158797. break;
  158798. case JXFORM_FLIP_V:
  158799. if (info->trim)
  158800. trim_bottom_edge(dstinfo);
  158801. break;
  158802. case JXFORM_TRANSPOSE:
  158803. transpose_critical_parameters(dstinfo);
  158804. break;
  158805. case JXFORM_TRANSVERSE:
  158806. transpose_critical_parameters(dstinfo);
  158807. if (info->trim) {
  158808. trim_right_edge(dstinfo);
  158809. trim_bottom_edge(dstinfo);
  158810. }
  158811. break;
  158812. case JXFORM_ROT_90:
  158813. transpose_critical_parameters(dstinfo);
  158814. if (info->trim)
  158815. trim_right_edge(dstinfo);
  158816. break;
  158817. case JXFORM_ROT_180:
  158818. if (info->trim) {
  158819. trim_right_edge(dstinfo);
  158820. trim_bottom_edge(dstinfo);
  158821. }
  158822. break;
  158823. case JXFORM_ROT_270:
  158824. transpose_critical_parameters(dstinfo);
  158825. if (info->trim)
  158826. trim_bottom_edge(dstinfo);
  158827. break;
  158828. }
  158829. if (info->workspace_coef_arrays != NULL)
  158830. return info->workspace_coef_arrays;
  158831. return src_coef_arrays;
  158832. }
  158833. GLOBAL(void)
  158834. jtransform_execute_transformation (j_decompress_ptr srcinfo,
  158835. j_compress_ptr dstinfo,
  158836. jvirt_barray_ptr *src_coef_arrays,
  158837. jpeg_transform_info *info)
  158838. {
  158839. jvirt_barray_ptr *dst_coef_arrays = info->workspace_coef_arrays;
  158840. switch (info->transform) {
  158841. case JXFORM_NONE:
  158842. break;
  158843. case JXFORM_FLIP_H:
  158844. do_flip_h(srcinfo, dstinfo, src_coef_arrays);
  158845. break;
  158846. case JXFORM_FLIP_V:
  158847. do_flip_v(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158848. break;
  158849. case JXFORM_TRANSPOSE:
  158850. do_transpose(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158851. break;
  158852. case JXFORM_TRANSVERSE:
  158853. do_transverse(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158854. break;
  158855. case JXFORM_ROT_90:
  158856. do_rot_90(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158857. break;
  158858. case JXFORM_ROT_180:
  158859. do_rot_180(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158860. break;
  158861. case JXFORM_ROT_270:
  158862. do_rot_270(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158863. break;
  158864. }
  158865. }
  158866. #endif /* TRANSFORMS_SUPPORTED */
  158867. GLOBAL(void)
  158868. jcopy_markers_setup (j_decompress_ptr srcinfo, JCOPY_OPTION option)
  158869. {
  158870. #ifdef SAVE_MARKERS_SUPPORTED
  158871. int m;
  158872. if (option != JCOPYOPT_NONE) {
  158873. jpeg_save_markers(srcinfo, JPEG_COM, 0xFFFF);
  158874. }
  158875. if (option == JCOPYOPT_ALL) {
  158876. for (m = 0; m < 16; m++)
  158877. jpeg_save_markers(srcinfo, JPEG_APP0 + m, 0xFFFF);
  158878. }
  158879. #endif /* SAVE_MARKERS_SUPPORTED */
  158880. }
  158881. GLOBAL(void)
  158882. jcopy_markers_execute (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158883. JCOPY_OPTION option)
  158884. {
  158885. jpeg_saved_marker_ptr marker;
  158886. for (marker = srcinfo->marker_list; marker != NULL; marker = marker->next) {
  158887. if (dstinfo->write_JFIF_header &&
  158888. marker->marker == JPEG_APP0 &&
  158889. marker->data_length >= 5 &&
  158890. GETJOCTET(marker->data[0]) == 0x4A &&
  158891. GETJOCTET(marker->data[1]) == 0x46 &&
  158892. GETJOCTET(marker->data[2]) == 0x49 &&
  158893. GETJOCTET(marker->data[3]) == 0x46 &&
  158894. GETJOCTET(marker->data[4]) == 0)
  158895. continue; /* reject duplicate JFIF */
  158896. if (dstinfo->write_Adobe_marker &&
  158897. marker->marker == JPEG_APP0+14 &&
  158898. marker->data_length >= 5 &&
  158899. GETJOCTET(marker->data[0]) == 0x41 &&
  158900. GETJOCTET(marker->data[1]) == 0x64 &&
  158901. GETJOCTET(marker->data[2]) == 0x6F &&
  158902. GETJOCTET(marker->data[3]) == 0x62 &&
  158903. GETJOCTET(marker->data[4]) == 0x65)
  158904. continue; /* reject duplicate Adobe */
  158905. #ifdef NEED_FAR_POINTERS
  158906. {
  158907. unsigned int i;
  158908. jpeg_write_m_header(dstinfo, marker->marker, marker->data_length);
  158909. for (i = 0; i < marker->data_length; i++)
  158910. jpeg_write_m_byte(dstinfo, marker->data[i]);
  158911. }
  158912. #else
  158913. jpeg_write_marker(dstinfo, marker->marker,
  158914. marker->data, marker->data_length);
  158915. #endif
  158916. }
  158917. }
  158918. /*** End of inlined file: transupp.c ***/
  158919. }
  158920. #else
  158921. #define JPEG_INTERNALS
  158922. #undef FAR
  158923. #include <jpeglib.h>
  158924. #endif
  158925. }
  158926. #if JUCE_MSVC
  158927. #pragma warning (pop)
  158928. #endif
  158929. BEGIN_JUCE_NAMESPACE
  158930. using namespace jpeglibNamespace;
  158931. #if ! JUCE_MSVC
  158932. using jpeglibNamespace::boolean;
  158933. #endif
  158934. struct JPEGDecodingFailure {};
  158935. static void fatalErrorHandler (j_common_ptr)
  158936. {
  158937. throw JPEGDecodingFailure();
  158938. }
  158939. static void silentErrorCallback1 (j_common_ptr) {}
  158940. static void silentErrorCallback2 (j_common_ptr, int) {}
  158941. static void silentErrorCallback3 (j_common_ptr, char*) {}
  158942. static void setupSilentErrorHandler (struct jpeg_error_mgr& err)
  158943. {
  158944. zerostruct (err);
  158945. err.error_exit = fatalErrorHandler;
  158946. err.emit_message = silentErrorCallback2;
  158947. err.output_message = silentErrorCallback1;
  158948. err.format_message = silentErrorCallback3;
  158949. err.reset_error_mgr = silentErrorCallback1;
  158950. }
  158951. static void dummyCallback1 (j_decompress_ptr)
  158952. {
  158953. }
  158954. static void jpegSkip (j_decompress_ptr decompStruct, long num)
  158955. {
  158956. decompStruct->src->next_input_byte += num;
  158957. num = jmin (num, (long) decompStruct->src->bytes_in_buffer);
  158958. decompStruct->src->bytes_in_buffer -= num;
  158959. }
  158960. static boolean jpegFill (j_decompress_ptr)
  158961. {
  158962. return 0;
  158963. }
  158964. Image* juce_loadJPEGImageFromStream (InputStream& in)
  158965. {
  158966. MemoryBlock mb;
  158967. in.readIntoMemoryBlock (mb);
  158968. Image* image = 0;
  158969. if (mb.getSize() > 16)
  158970. {
  158971. struct jpeg_decompress_struct jpegDecompStruct;
  158972. struct jpeg_error_mgr jerr;
  158973. setupSilentErrorHandler (jerr);
  158974. jpegDecompStruct.err = &jerr;
  158975. jpeg_create_decompress (&jpegDecompStruct);
  158976. jpegDecompStruct.src = (jpeg_source_mgr*)(jpegDecompStruct.mem->alloc_small)
  158977. ((j_common_ptr)(&jpegDecompStruct), JPOOL_PERMANENT, sizeof (jpeg_source_mgr));
  158978. jpegDecompStruct.src->init_source = dummyCallback1;
  158979. jpegDecompStruct.src->fill_input_buffer = jpegFill;
  158980. jpegDecompStruct.src->skip_input_data = jpegSkip;
  158981. jpegDecompStruct.src->resync_to_restart = jpeg_resync_to_restart;
  158982. jpegDecompStruct.src->term_source = dummyCallback1;
  158983. jpegDecompStruct.src->next_input_byte = (const unsigned char*) mb.getData();
  158984. jpegDecompStruct.src->bytes_in_buffer = mb.getSize();
  158985. try
  158986. {
  158987. jpeg_read_header (&jpegDecompStruct, TRUE);
  158988. jpeg_calc_output_dimensions (&jpegDecompStruct);
  158989. const int width = jpegDecompStruct.output_width;
  158990. const int height = jpegDecompStruct.output_height;
  158991. jpegDecompStruct.out_color_space = JCS_RGB;
  158992. JSAMPARRAY buffer
  158993. = (*jpegDecompStruct.mem->alloc_sarray) ((j_common_ptr) &jpegDecompStruct,
  158994. JPOOL_IMAGE,
  158995. width * 3, 1);
  158996. if (jpeg_start_decompress (&jpegDecompStruct))
  158997. {
  158998. image = Image::createNativeImage (Image::RGB, width, height, false);
  158999. const bool hasAlphaChan = image->hasAlphaChannel();
  159000. const Image::BitmapData destData (*image, 0, 0, width, height, true);
  159001. for (int y = 0; y < height; ++y)
  159002. {
  159003. jpeg_read_scanlines (&jpegDecompStruct, buffer, 1);
  159004. const uint8* src = *buffer;
  159005. uint8* dest = destData.getLinePointer (y);
  159006. if (hasAlphaChan)
  159007. {
  159008. for (int i = width; --i >= 0;)
  159009. {
  159010. ((PixelARGB*) dest)->setARGB (0xff, src[0], src[1], src[2]);
  159011. ((PixelARGB*) dest)->premultiply();
  159012. dest += destData.pixelStride;
  159013. src += 3;
  159014. }
  159015. }
  159016. else
  159017. {
  159018. for (int i = width; --i >= 0;)
  159019. {
  159020. ((PixelRGB*) dest)->setARGB (0xff, src[0], src[1], src[2]);
  159021. dest += destData.pixelStride;
  159022. src += 3;
  159023. }
  159024. }
  159025. }
  159026. jpeg_finish_decompress (&jpegDecompStruct);
  159027. in.setPosition (((char*) jpegDecompStruct.src->next_input_byte) - (char*) mb.getData());
  159028. }
  159029. jpeg_destroy_decompress (&jpegDecompStruct);
  159030. }
  159031. catch (...)
  159032. {}
  159033. }
  159034. return image;
  159035. }
  159036. static const int jpegBufferSize = 512;
  159037. struct JuceJpegDest : public jpeg_destination_mgr
  159038. {
  159039. OutputStream* output;
  159040. char* buffer;
  159041. };
  159042. static void jpegWriteInit (j_compress_ptr)
  159043. {
  159044. }
  159045. static void jpegWriteTerminate (j_compress_ptr cinfo)
  159046. {
  159047. JuceJpegDest* const dest = (JuceJpegDest*) cinfo->dest;
  159048. const size_t numToWrite = jpegBufferSize - dest->free_in_buffer;
  159049. dest->output->write (dest->buffer, (int) numToWrite);
  159050. }
  159051. static boolean jpegWriteFlush (j_compress_ptr cinfo)
  159052. {
  159053. JuceJpegDest* const dest = (JuceJpegDest*) cinfo->dest;
  159054. const int numToWrite = jpegBufferSize;
  159055. dest->next_output_byte = (JOCTET*) dest->buffer;
  159056. dest->free_in_buffer = jpegBufferSize;
  159057. return dest->output->write (dest->buffer, numToWrite);
  159058. }
  159059. bool juce_writeJPEGImageToStream (const Image& image,
  159060. OutputStream& out,
  159061. float quality)
  159062. {
  159063. if (image.hasAlphaChannel())
  159064. {
  159065. // this method could fill the background in white and still save the image..
  159066. jassertfalse
  159067. return true;
  159068. }
  159069. struct jpeg_compress_struct jpegCompStruct;
  159070. struct jpeg_error_mgr jerr;
  159071. setupSilentErrorHandler (jerr);
  159072. jpegCompStruct.err = &jerr;
  159073. jpeg_create_compress (&jpegCompStruct);
  159074. JuceJpegDest dest;
  159075. jpegCompStruct.dest = &dest;
  159076. dest.output = &out;
  159077. HeapBlock <char> tempBuffer (jpegBufferSize);
  159078. dest.buffer = (char*) tempBuffer;
  159079. dest.next_output_byte = (JOCTET*) dest.buffer;
  159080. dest.free_in_buffer = jpegBufferSize;
  159081. dest.init_destination = jpegWriteInit;
  159082. dest.empty_output_buffer = jpegWriteFlush;
  159083. dest.term_destination = jpegWriteTerminate;
  159084. jpegCompStruct.image_width = image.getWidth();
  159085. jpegCompStruct.image_height = image.getHeight();
  159086. jpegCompStruct.input_components = 3;
  159087. jpegCompStruct.in_color_space = JCS_RGB;
  159088. jpegCompStruct.write_JFIF_header = 1;
  159089. jpegCompStruct.X_density = 72;
  159090. jpegCompStruct.Y_density = 72;
  159091. jpeg_set_defaults (&jpegCompStruct);
  159092. jpegCompStruct.dct_method = JDCT_FLOAT;
  159093. jpegCompStruct.optimize_coding = 1;
  159094. // jpegCompStruct.smoothing_factor = 10;
  159095. if (quality < 0.0f)
  159096. quality = 0.85f;
  159097. jpeg_set_quality (&jpegCompStruct, jlimit (0, 100, roundToInt (quality * 100.0f)), TRUE);
  159098. jpeg_start_compress (&jpegCompStruct, TRUE);
  159099. const int strideBytes = jpegCompStruct.image_width * jpegCompStruct.input_components;
  159100. JSAMPARRAY buffer = (*jpegCompStruct.mem->alloc_sarray) ((j_common_ptr) &jpegCompStruct,
  159101. JPOOL_IMAGE,
  159102. strideBytes, 1);
  159103. const Image::BitmapData srcData (image, 0, 0, jpegCompStruct.image_width, jpegCompStruct.image_height);
  159104. while (jpegCompStruct.next_scanline < jpegCompStruct.image_height)
  159105. {
  159106. const uint8* src = srcData.getLinePointer (jpegCompStruct.next_scanline);
  159107. uint8* dst = *buffer;
  159108. for (int i = jpegCompStruct.image_width; --i >= 0;)
  159109. {
  159110. *dst++ = ((const PixelRGB*) src)->getRed();
  159111. *dst++ = ((const PixelRGB*) src)->getGreen();
  159112. *dst++ = ((const PixelRGB*) src)->getBlue();
  159113. src += srcData.pixelStride;
  159114. }
  159115. jpeg_write_scanlines (&jpegCompStruct, buffer, 1);
  159116. }
  159117. jpeg_finish_compress (&jpegCompStruct);
  159118. jpeg_destroy_compress (&jpegCompStruct);
  159119. out.flush();
  159120. return true;
  159121. }
  159122. END_JUCE_NAMESPACE
  159123. /*** End of inlined file: juce_JPEGLoader.cpp ***/
  159124. /*** Start of inlined file: juce_PNGLoader.cpp ***/
  159125. #ifdef _MSC_VER
  159126. #pragma warning (push)
  159127. #pragma warning (disable: 4390 4611)
  159128. #endif
  159129. namespace zlibNamespace
  159130. {
  159131. #if JUCE_INCLUDE_ZLIB_CODE
  159132. #undef OS_CODE
  159133. #undef fdopen
  159134. #undef OS_CODE
  159135. #else
  159136. #include <zlib.h>
  159137. #endif
  159138. }
  159139. namespace pnglibNamespace
  159140. {
  159141. using namespace zlibNamespace;
  159142. #if JUCE_INCLUDE_PNGLIB_CODE
  159143. #if _MSC_VER != 1310
  159144. using ::calloc; // (causes conflict in VS.NET 2003)
  159145. using ::malloc;
  159146. using ::free;
  159147. #endif
  159148. extern "C"
  159149. {
  159150. using ::abs;
  159151. #define PNG_INTERNAL
  159152. #define NO_DUMMY_DECL
  159153. #define PNG_SETJMP_NOT_SUPPORTED
  159154. /*** Start of inlined file: png.h ***/
  159155. #ifndef PNG_H
  159156. #define PNG_H
  159157. #define PNG_LIBPNG_VER_STRING "1.2.21"
  159158. #define PNG_HEADER_VERSION_STRING \
  159159. " libpng version 1.2.21 - October 4, 2007\n"
  159160. #define PNG_LIBPNG_VER_SONUM 0
  159161. #define PNG_LIBPNG_VER_DLLNUM 13
  159162. #define PNG_LIBPNG_VER_MAJOR 1
  159163. #define PNG_LIBPNG_VER_MINOR 2
  159164. #define PNG_LIBPNG_VER_RELEASE 21
  159165. #define PNG_LIBPNG_VER_BUILD 0
  159166. #define PNG_LIBPNG_BUILD_ALPHA 1
  159167. #define PNG_LIBPNG_BUILD_BETA 2
  159168. #define PNG_LIBPNG_BUILD_RC 3
  159169. #define PNG_LIBPNG_BUILD_STABLE 4
  159170. #define PNG_LIBPNG_BUILD_RELEASE_STATUS_MASK 7
  159171. #define PNG_LIBPNG_BUILD_PATCH 8 /* Can be OR'ed with
  159172. PNG_LIBPNG_BUILD_STABLE only */
  159173. #define PNG_LIBPNG_BUILD_PRIVATE 16 /* Cannot be OR'ed with
  159174. PNG_LIBPNG_BUILD_SPECIAL */
  159175. #define PNG_LIBPNG_BUILD_SPECIAL 32 /* Cannot be OR'ed with
  159176. PNG_LIBPNG_BUILD_PRIVATE */
  159177. #define PNG_LIBPNG_BUILD_BASE_TYPE PNG_LIBPNG_BUILD_STABLE
  159178. #define PNG_LIBPNG_VER 10221 /* 1.2.21 */
  159179. #ifndef PNG_VERSION_INFO_ONLY
  159180. #endif
  159181. /*** Start of inlined file: pngconf.h ***/
  159182. #ifndef PNGCONF_H
  159183. #define PNGCONF_H
  159184. #define PNG_1_2_X
  159185. // These are some Juce config settings that should remove any unnecessary code bloat..
  159186. #define PNG_NO_STDIO 1
  159187. #define PNG_DEBUG 0
  159188. #define PNG_NO_WARNINGS 1
  159189. #define PNG_NO_ERROR_TEXT 1
  159190. #define PNG_NO_ERROR_NUMBERS 1
  159191. #define PNG_NO_USER_MEM 1
  159192. #define PNG_NO_READ_iCCP 1
  159193. #define PNG_NO_READ_UNKNOWN_CHUNKS 1
  159194. #define PNG_NO_READ_USER_CHUNKS 1
  159195. #define PNG_NO_READ_iTXt 1
  159196. #define PNG_NO_READ_sCAL 1
  159197. #define PNG_NO_READ_sPLT 1
  159198. #define png_error(a, b) png_err(a)
  159199. #define png_warning(a, b)
  159200. #define png_chunk_error(a, b) png_err(a)
  159201. #define png_chunk_warning(a, b)
  159202. #ifdef PNG_USER_CONFIG
  159203. # ifndef PNG_USER_PRIVATEBUILD
  159204. # define PNG_USER_PRIVATEBUILD
  159205. # endif
  159206. #include "pngusr.h"
  159207. #endif
  159208. #ifdef PNG_CONFIGURE_LIBPNG
  159209. #ifdef HAVE_CONFIG_H
  159210. #include "config.h"
  159211. #endif
  159212. #endif
  159213. #ifdef __STDC__
  159214. #ifdef SPECIALBUILD
  159215. # pragma message("PNG_LIBPNG_SPECIALBUILD (and deprecated SPECIALBUILD)\
  159216. are now LIBPNG reserved macros. Use PNG_USER_PRIVATEBUILD instead.")
  159217. #endif
  159218. #ifdef PRIVATEBUILD
  159219. # pragma message("PRIVATEBUILD is deprecated.\
  159220. Use PNG_USER_PRIVATEBUILD instead.")
  159221. # define PNG_USER_PRIVATEBUILD PRIVATEBUILD
  159222. #endif
  159223. #endif /* __STDC__ */
  159224. #ifndef PNG_VERSION_INFO_ONLY
  159225. # define PNG_WARN_UNINITIALIZED_ROW 1
  159226. #ifndef PNG_ZBUF_SIZE
  159227. # define PNG_ZBUF_SIZE 8192
  159228. #endif
  159229. #ifndef PNG_NO_READ_SUPPORTED
  159230. # define PNG_READ_SUPPORTED
  159231. #endif
  159232. #ifndef PNG_NO_WRITE_SUPPORTED
  159233. # define PNG_WRITE_SUPPORTED
  159234. #endif
  159235. #if !defined(PNG_1_0_X) && !defined(PNG_NO_MNG_FEATURES)
  159236. # ifndef PNG_MNG_FEATURES_SUPPORTED
  159237. # define PNG_MNG_FEATURES_SUPPORTED
  159238. # endif
  159239. #endif
  159240. #ifndef PNG_NO_FLOATING_POINT_SUPPORTED
  159241. # ifndef PNG_FLOATING_POINT_SUPPORTED
  159242. # define PNG_FLOATING_POINT_SUPPORTED
  159243. # endif
  159244. #endif
  159245. #if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K)
  159246. # define PNG_MAX_MALLOC_64K
  159247. #endif
  159248. #if defined(__CYGWIN__)
  159249. # if defined(ALL_STATIC)
  159250. # if defined(PNG_BUILD_DLL)
  159251. # undef PNG_BUILD_DLL
  159252. # endif
  159253. # if defined(PNG_USE_DLL)
  159254. # undef PNG_USE_DLL
  159255. # endif
  159256. # if defined(PNG_DLL)
  159257. # undef PNG_DLL
  159258. # endif
  159259. # if !defined(PNG_STATIC)
  159260. # define PNG_STATIC
  159261. # endif
  159262. # else
  159263. # if defined (PNG_BUILD_DLL)
  159264. # if defined(PNG_STATIC)
  159265. # undef PNG_STATIC
  159266. # endif
  159267. # if defined(PNG_USE_DLL)
  159268. # undef PNG_USE_DLL
  159269. # endif
  159270. # if !defined(PNG_DLL)
  159271. # define PNG_DLL
  159272. # endif
  159273. # else
  159274. # if defined(PNG_STATIC)
  159275. # if defined(PNG_USE_DLL)
  159276. # undef PNG_USE_DLL
  159277. # endif
  159278. # if defined(PNG_DLL)
  159279. # undef PNG_DLL
  159280. # endif
  159281. # else
  159282. # if !defined(PNG_USE_DLL)
  159283. # define PNG_USE_DLL
  159284. # endif
  159285. # if !defined(PNG_DLL)
  159286. # define PNG_DLL
  159287. # endif
  159288. # endif
  159289. # endif
  159290. # endif
  159291. #endif
  159292. #if defined(_WIN32_WCE)
  159293. # include <windows.h>
  159294. # define PNG_NO_CONSOLE_IO
  159295. # ifdef PNG_DEBUG
  159296. # undef PNG_DEBUG
  159297. # endif
  159298. #endif
  159299. #ifdef PNG_BUILD_DLL
  159300. # ifndef PNG_CONSOLE_IO_SUPPORTED
  159301. # ifndef PNG_NO_CONSOLE_IO
  159302. # define PNG_NO_CONSOLE_IO
  159303. # endif
  159304. # endif
  159305. #endif
  159306. # ifdef PNG_NO_STDIO
  159307. # ifndef PNG_NO_CONSOLE_IO
  159308. # define PNG_NO_CONSOLE_IO
  159309. # endif
  159310. # ifdef PNG_DEBUG
  159311. # if (PNG_DEBUG > 0)
  159312. # include <stdio.h>
  159313. # endif
  159314. # endif
  159315. # else
  159316. # if !defined(_WIN32_WCE)
  159317. # include <stdio.h>
  159318. # endif
  159319. # endif
  159320. #ifndef PNGARG
  159321. #ifdef OF /* zlib prototype munger */
  159322. # define PNGARG(arglist) OF(arglist)
  159323. #else
  159324. #ifdef _NO_PROTO
  159325. # define PNGARG(arglist) ()
  159326. # ifndef PNG_TYPECAST_NULL
  159327. # define PNG_TYPECAST_NULL
  159328. # endif
  159329. #else
  159330. # define PNGARG(arglist) arglist
  159331. #endif /* _NO_PROTO */
  159332. #endif /* OF */
  159333. #endif /* PNGARG */
  159334. #ifndef MACOS
  159335. # if (defined(__MWERKS__) && defined(macintosh)) || defined(applec) || \
  159336. defined(THINK_C) || defined(__SC__) || defined(TARGET_OS_MAC)
  159337. # define MACOS
  159338. # endif
  159339. #endif
  159340. #if !defined(MACOS) && !defined(RISCOS) && !defined(_WIN32_WCE)
  159341. # include <sys/types.h>
  159342. #endif
  159343. #if !defined(PNG_SETJMP_NOT_SUPPORTED) && !defined(PNG_NO_SETJMP_SUPPORTED)
  159344. # define PNG_SETJMP_SUPPORTED
  159345. #endif
  159346. #ifdef PNG_SETJMP_SUPPORTED
  159347. # ifdef __linux__
  159348. # ifdef _BSD_SOURCE
  159349. # define PNG_SAVE_BSD_SOURCE
  159350. # undef _BSD_SOURCE
  159351. # endif
  159352. # ifdef _SETJMP_H
  159353. __png.h__ already includes setjmp.h;
  159354. __dont__ include it again.;
  159355. # endif
  159356. # endif /* __linux__ */
  159357. # include <setjmp.h>
  159358. # ifdef __linux__
  159359. # ifdef PNG_SAVE_BSD_SOURCE
  159360. # define _BSD_SOURCE
  159361. # undef PNG_SAVE_BSD_SOURCE
  159362. # endif
  159363. # endif /* __linux__ */
  159364. #endif /* PNG_SETJMP_SUPPORTED */
  159365. #ifdef BSD
  159366. #if ! JUCE_MAC
  159367. # include <strings.h>
  159368. #endif
  159369. #else
  159370. # include <string.h>
  159371. #endif
  159372. #ifdef PNG_INTERNAL
  159373. #include <stdlib.h>
  159374. #define PNG_EXTERN
  159375. #if defined(PNG_FLOATING_POINT_SUPPORTED)
  159376. # if defined(MACOS)
  159377. # if !defined(__MATH_H__) && !defined(__MATH_H) && !defined(__cmath__)
  159378. # include <fp.h>
  159379. # endif
  159380. # else
  159381. # include <math.h>
  159382. # endif
  159383. # if defined(_AMIGA) && defined(__SASC) && defined(_M68881)
  159384. # include <m68881.h>
  159385. # endif
  159386. #endif
  159387. #if (defined(__MWERKS__) && defined(WIN32)) || defined(__STDC__)
  159388. # define PNG_ALWAYS_EXTERN
  159389. #endif
  159390. #if defined(__TURBOC__) && defined(__MSDOS__)
  159391. # include <mem.h>
  159392. # include <alloc.h>
  159393. #endif
  159394. #if defined(_MSC_VER) && (defined(WIN32) || defined(_Windows) || \
  159395. defined(_WINDOWS) || defined(_WIN32) || defined(__WIN32__))
  159396. # include <malloc.h>
  159397. #endif
  159398. #ifndef PNG_DITHER_RED_BITS
  159399. # define PNG_DITHER_RED_BITS 5
  159400. #endif
  159401. #ifndef PNG_DITHER_GREEN_BITS
  159402. # define PNG_DITHER_GREEN_BITS 5
  159403. #endif
  159404. #ifndef PNG_DITHER_BLUE_BITS
  159405. # define PNG_DITHER_BLUE_BITS 5
  159406. #endif
  159407. #ifndef PNG_MAX_GAMMA_8
  159408. # define PNG_MAX_GAMMA_8 11
  159409. #endif
  159410. #ifndef PNG_GAMMA_THRESHOLD
  159411. # define PNG_GAMMA_THRESHOLD 0.05
  159412. #endif
  159413. #endif /* PNG_INTERNAL */
  159414. #ifndef PNG_NO_CONST
  159415. # define PNG_CONST const
  159416. #else
  159417. # define PNG_CONST
  159418. #endif
  159419. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  159420. # ifndef PNG_NO_iTXt_SUPPORTED
  159421. # define PNG_NO_iTXt_SUPPORTED
  159422. # endif
  159423. # ifndef PNG_NO_READ_iTXt
  159424. # define PNG_NO_READ_iTXt
  159425. # endif
  159426. # ifndef PNG_NO_WRITE_iTXt
  159427. # define PNG_NO_WRITE_iTXt
  159428. # endif
  159429. #endif
  159430. #if !defined(PNG_NO_iTXt_SUPPORTED)
  159431. # if !defined(PNG_READ_iTXt_SUPPORTED) && !defined(PNG_NO_READ_iTXt)
  159432. # define PNG_READ_iTXt
  159433. # endif
  159434. # if !defined(PNG_WRITE_iTXt_SUPPORTED) && !defined(PNG_NO_WRITE_iTXt)
  159435. # define PNG_WRITE_iTXt
  159436. # endif
  159437. #endif
  159438. #ifdef PNG_LEGACY_SUPPORTED
  159439. # define PNG_NO_FREE_ME
  159440. # define PNG_NO_READ_UNKNOWN_CHUNKS
  159441. # define PNG_NO_WRITE_UNKNOWN_CHUNKS
  159442. # define PNG_NO_READ_USER_CHUNKS
  159443. # define PNG_NO_READ_iCCP
  159444. # define PNG_NO_WRITE_iCCP
  159445. # define PNG_NO_READ_iTXt
  159446. # define PNG_NO_WRITE_iTXt
  159447. # define PNG_NO_READ_sCAL
  159448. # define PNG_NO_WRITE_sCAL
  159449. # define PNG_NO_READ_sPLT
  159450. # define PNG_NO_WRITE_sPLT
  159451. # define PNG_NO_INFO_IMAGE
  159452. # define PNG_NO_READ_RGB_TO_GRAY
  159453. # define PNG_NO_READ_USER_TRANSFORM
  159454. # define PNG_NO_WRITE_USER_TRANSFORM
  159455. # define PNG_NO_USER_MEM
  159456. # define PNG_NO_READ_EMPTY_PLTE
  159457. # define PNG_NO_MNG_FEATURES
  159458. # define PNG_NO_FIXED_POINT_SUPPORTED
  159459. #endif
  159460. #if !defined(PNG_FLOATING_POINT_SUPPORTED) || \
  159461. !defined(PNG_NO_FIXED_POINT_SUPPORTED)
  159462. # define PNG_FIXED_POINT_SUPPORTED
  159463. #endif
  159464. #ifndef PNG_NO_FREE_ME
  159465. # define PNG_FREE_ME_SUPPORTED
  159466. #endif
  159467. #if defined(PNG_READ_SUPPORTED)
  159468. #if !defined(PNG_READ_TRANSFORMS_NOT_SUPPORTED) && \
  159469. !defined(PNG_NO_READ_TRANSFORMS)
  159470. # define PNG_READ_TRANSFORMS_SUPPORTED
  159471. #endif
  159472. #ifdef PNG_READ_TRANSFORMS_SUPPORTED
  159473. # ifndef PNG_NO_READ_EXPAND
  159474. # define PNG_READ_EXPAND_SUPPORTED
  159475. # endif
  159476. # ifndef PNG_NO_READ_SHIFT
  159477. # define PNG_READ_SHIFT_SUPPORTED
  159478. # endif
  159479. # ifndef PNG_NO_READ_PACK
  159480. # define PNG_READ_PACK_SUPPORTED
  159481. # endif
  159482. # ifndef PNG_NO_READ_BGR
  159483. # define PNG_READ_BGR_SUPPORTED
  159484. # endif
  159485. # ifndef PNG_NO_READ_SWAP
  159486. # define PNG_READ_SWAP_SUPPORTED
  159487. # endif
  159488. # ifndef PNG_NO_READ_PACKSWAP
  159489. # define PNG_READ_PACKSWAP_SUPPORTED
  159490. # endif
  159491. # ifndef PNG_NO_READ_INVERT
  159492. # define PNG_READ_INVERT_SUPPORTED
  159493. # endif
  159494. # ifndef PNG_NO_READ_DITHER
  159495. # define PNG_READ_DITHER_SUPPORTED
  159496. # endif
  159497. # ifndef PNG_NO_READ_BACKGROUND
  159498. # define PNG_READ_BACKGROUND_SUPPORTED
  159499. # endif
  159500. # ifndef PNG_NO_READ_16_TO_8
  159501. # define PNG_READ_16_TO_8_SUPPORTED
  159502. # endif
  159503. # ifndef PNG_NO_READ_FILLER
  159504. # define PNG_READ_FILLER_SUPPORTED
  159505. # endif
  159506. # ifndef PNG_NO_READ_GAMMA
  159507. # define PNG_READ_GAMMA_SUPPORTED
  159508. # endif
  159509. # ifndef PNG_NO_READ_GRAY_TO_RGB
  159510. # define PNG_READ_GRAY_TO_RGB_SUPPORTED
  159511. # endif
  159512. # ifndef PNG_NO_READ_SWAP_ALPHA
  159513. # define PNG_READ_SWAP_ALPHA_SUPPORTED
  159514. # endif
  159515. # ifndef PNG_NO_READ_INVERT_ALPHA
  159516. # define PNG_READ_INVERT_ALPHA_SUPPORTED
  159517. # endif
  159518. # ifndef PNG_NO_READ_STRIP_ALPHA
  159519. # define PNG_READ_STRIP_ALPHA_SUPPORTED
  159520. # endif
  159521. # ifndef PNG_NO_READ_USER_TRANSFORM
  159522. # define PNG_READ_USER_TRANSFORM_SUPPORTED
  159523. # endif
  159524. # ifndef PNG_NO_READ_RGB_TO_GRAY
  159525. # define PNG_READ_RGB_TO_GRAY_SUPPORTED
  159526. # endif
  159527. #endif /* PNG_READ_TRANSFORMS_SUPPORTED */
  159528. #if !defined(PNG_NO_PROGRESSIVE_READ) && \
  159529. !defined(PNG_PROGRESSIVE_READ_SUPPORTED) /* if you don't do progressive */
  159530. # define PNG_PROGRESSIVE_READ_SUPPORTED /* reading. This is not talking */
  159531. #endif /* about interlacing capability! You'll */
  159532. #define PNG_READ_INTERLACING_SUPPORTED /* required in PNG-compliant decoders */
  159533. #ifndef PNG_NO_READ_COMPOSITE_NODIV
  159534. # ifndef PNG_NO_READ_COMPOSITED_NODIV /* libpng-1.0.x misspelling */
  159535. # define PNG_READ_COMPOSITE_NODIV_SUPPORTED /* well tested on Intel, SGI */
  159536. # endif
  159537. #endif
  159538. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  159539. #ifndef PNG_NO_READ_EMPTY_PLTE
  159540. # define PNG_READ_EMPTY_PLTE_SUPPORTED
  159541. #endif
  159542. #endif
  159543. #endif /* PNG_READ_SUPPORTED */
  159544. #if defined(PNG_WRITE_SUPPORTED)
  159545. # if !defined(PNG_WRITE_TRANSFORMS_NOT_SUPPORTED) && \
  159546. !defined(PNG_NO_WRITE_TRANSFORMS)
  159547. # define PNG_WRITE_TRANSFORMS_SUPPORTED
  159548. #endif
  159549. #ifdef PNG_WRITE_TRANSFORMS_SUPPORTED
  159550. # ifndef PNG_NO_WRITE_SHIFT
  159551. # define PNG_WRITE_SHIFT_SUPPORTED
  159552. # endif
  159553. # ifndef PNG_NO_WRITE_PACK
  159554. # define PNG_WRITE_PACK_SUPPORTED
  159555. # endif
  159556. # ifndef PNG_NO_WRITE_BGR
  159557. # define PNG_WRITE_BGR_SUPPORTED
  159558. # endif
  159559. # ifndef PNG_NO_WRITE_SWAP
  159560. # define PNG_WRITE_SWAP_SUPPORTED
  159561. # endif
  159562. # ifndef PNG_NO_WRITE_PACKSWAP
  159563. # define PNG_WRITE_PACKSWAP_SUPPORTED
  159564. # endif
  159565. # ifndef PNG_NO_WRITE_INVERT
  159566. # define PNG_WRITE_INVERT_SUPPORTED
  159567. # endif
  159568. # ifndef PNG_NO_WRITE_FILLER
  159569. # define PNG_WRITE_FILLER_SUPPORTED /* same as WRITE_STRIP_ALPHA */
  159570. # endif
  159571. # ifndef PNG_NO_WRITE_SWAP_ALPHA
  159572. # define PNG_WRITE_SWAP_ALPHA_SUPPORTED
  159573. # endif
  159574. # ifndef PNG_NO_WRITE_INVERT_ALPHA
  159575. # define PNG_WRITE_INVERT_ALPHA_SUPPORTED
  159576. # endif
  159577. # ifndef PNG_NO_WRITE_USER_TRANSFORM
  159578. # define PNG_WRITE_USER_TRANSFORM_SUPPORTED
  159579. # endif
  159580. #endif /* PNG_WRITE_TRANSFORMS_SUPPORTED */
  159581. #if !defined(PNG_NO_WRITE_INTERLACING_SUPPORTED) && \
  159582. !defined(PNG_WRITE_INTERLACING_SUPPORTED)
  159583. #define PNG_WRITE_INTERLACING_SUPPORTED /* not required for PNG-compliant
  159584. encoders, but can cause trouble
  159585. if left undefined */
  159586. #endif
  159587. #if !defined(PNG_NO_WRITE_WEIGHTED_FILTER) && \
  159588. !defined(PNG_WRITE_WEIGHTED_FILTER) && \
  159589. defined(PNG_FLOATING_POINT_SUPPORTED)
  159590. # define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
  159591. #endif
  159592. #ifndef PNG_NO_WRITE_FLUSH
  159593. # define PNG_WRITE_FLUSH_SUPPORTED
  159594. #endif
  159595. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  159596. #ifndef PNG_NO_WRITE_EMPTY_PLTE
  159597. # define PNG_WRITE_EMPTY_PLTE_SUPPORTED
  159598. #endif
  159599. #endif
  159600. #endif /* PNG_WRITE_SUPPORTED */
  159601. #ifndef PNG_1_0_X
  159602. # ifndef PNG_NO_ERROR_NUMBERS
  159603. # define PNG_ERROR_NUMBERS_SUPPORTED
  159604. # endif
  159605. #endif /* PNG_1_0_X */
  159606. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  159607. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  159608. # ifndef PNG_NO_USER_TRANSFORM_PTR
  159609. # define PNG_USER_TRANSFORM_PTR_SUPPORTED
  159610. # endif
  159611. #endif
  159612. #ifndef PNG_NO_STDIO
  159613. # define PNG_TIME_RFC1123_SUPPORTED
  159614. #endif
  159615. #if !defined(PNG_NO_EASY_ACCESS) && !defined(PNG_EASY_ACCESS_SUPPORTED)
  159616. # define PNG_EASY_ACCESS_SUPPORTED
  159617. #endif
  159618. #if defined(PNG_READ_SUPPORTED) && !defined(PNG_NO_OPTIMIZED_CODE)
  159619. # ifndef PNG_OPTIMIZED_CODE_SUPPORTED
  159620. # define PNG_OPTIMIZED_CODE_SUPPORTED
  159621. # endif
  159622. #endif
  159623. #if defined(PNG_READ_SUPPORTED) && !defined(PNG_NO_ASSEMBLER_CODE)
  159624. # ifndef PNG_ASSEMBLER_CODE_SUPPORTED
  159625. # define PNG_ASSEMBLER_CODE_SUPPORTED
  159626. # endif
  159627. # if defined(__GNUC__) && defined(__x86_64__) && (__GNUC__ < 4)
  159628. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  159629. # define PNG_NO_MMX_CODE
  159630. # endif
  159631. # endif
  159632. # if defined(__APPLE__)
  159633. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  159634. # define PNG_NO_MMX_CODE
  159635. # endif
  159636. # endif
  159637. # if (defined(__MWERKS__) && ((__MWERKS__ < 0x0900) || macintosh))
  159638. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  159639. # define PNG_NO_MMX_CODE
  159640. # endif
  159641. # endif
  159642. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  159643. # define PNG_MMX_CODE_SUPPORTED
  159644. # endif
  159645. #endif
  159646. #if !defined(PNG_1_0_X)
  159647. #if !defined(PNG_NO_USER_MEM) && !defined(PNG_USER_MEM_SUPPORTED)
  159648. # define PNG_USER_MEM_SUPPORTED
  159649. #endif
  159650. #endif /* PNG_1_0_X */
  159651. #if !defined(PNG_1_0_X)
  159652. #ifndef PNG_SET_USER_LIMITS_SUPPORTED
  159653. #if !defined(PNG_NO_SET_USER_LIMITS) && !defined(PNG_SET_USER_LIMITS_SUPPORTED)
  159654. # define PNG_SET_USER_LIMITS_SUPPORTED
  159655. #endif
  159656. #endif
  159657. #endif /* PNG_1_0_X */
  159658. #ifndef PNG_USER_WIDTH_MAX
  159659. # define PNG_USER_WIDTH_MAX 1000000L
  159660. #endif
  159661. #ifndef PNG_USER_HEIGHT_MAX
  159662. # define PNG_USER_HEIGHT_MAX 1000000L
  159663. #endif
  159664. #if defined(PNG_READ_SUPPORTED) && \
  159665. !defined(PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \
  159666. !defined(PNG_NO_READ_ANCILLARY_CHUNKS)
  159667. # define PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
  159668. #endif
  159669. #if defined(PNG_WRITE_SUPPORTED) && \
  159670. !defined(PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \
  159671. !defined(PNG_NO_WRITE_ANCILLARY_CHUNKS)
  159672. # define PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
  159673. #endif
  159674. #ifdef PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
  159675. #ifdef PNG_NO_READ_TEXT
  159676. # define PNG_NO_READ_iTXt
  159677. # define PNG_NO_READ_tEXt
  159678. # define PNG_NO_READ_zTXt
  159679. #endif
  159680. #ifndef PNG_NO_READ_bKGD
  159681. # define PNG_READ_bKGD_SUPPORTED
  159682. # define PNG_bKGD_SUPPORTED
  159683. #endif
  159684. #ifndef PNG_NO_READ_cHRM
  159685. # define PNG_READ_cHRM_SUPPORTED
  159686. # define PNG_cHRM_SUPPORTED
  159687. #endif
  159688. #ifndef PNG_NO_READ_gAMA
  159689. # define PNG_READ_gAMA_SUPPORTED
  159690. # define PNG_gAMA_SUPPORTED
  159691. #endif
  159692. #ifndef PNG_NO_READ_hIST
  159693. # define PNG_READ_hIST_SUPPORTED
  159694. # define PNG_hIST_SUPPORTED
  159695. #endif
  159696. #ifndef PNG_NO_READ_iCCP
  159697. # define PNG_READ_iCCP_SUPPORTED
  159698. # define PNG_iCCP_SUPPORTED
  159699. #endif
  159700. #ifndef PNG_NO_READ_iTXt
  159701. # ifndef PNG_READ_iTXt_SUPPORTED
  159702. # define PNG_READ_iTXt_SUPPORTED
  159703. # endif
  159704. # ifndef PNG_iTXt_SUPPORTED
  159705. # define PNG_iTXt_SUPPORTED
  159706. # endif
  159707. #endif
  159708. #ifndef PNG_NO_READ_oFFs
  159709. # define PNG_READ_oFFs_SUPPORTED
  159710. # define PNG_oFFs_SUPPORTED
  159711. #endif
  159712. #ifndef PNG_NO_READ_pCAL
  159713. # define PNG_READ_pCAL_SUPPORTED
  159714. # define PNG_pCAL_SUPPORTED
  159715. #endif
  159716. #ifndef PNG_NO_READ_sCAL
  159717. # define PNG_READ_sCAL_SUPPORTED
  159718. # define PNG_sCAL_SUPPORTED
  159719. #endif
  159720. #ifndef PNG_NO_READ_pHYs
  159721. # define PNG_READ_pHYs_SUPPORTED
  159722. # define PNG_pHYs_SUPPORTED
  159723. #endif
  159724. #ifndef PNG_NO_READ_sBIT
  159725. # define PNG_READ_sBIT_SUPPORTED
  159726. # define PNG_sBIT_SUPPORTED
  159727. #endif
  159728. #ifndef PNG_NO_READ_sPLT
  159729. # define PNG_READ_sPLT_SUPPORTED
  159730. # define PNG_sPLT_SUPPORTED
  159731. #endif
  159732. #ifndef PNG_NO_READ_sRGB
  159733. # define PNG_READ_sRGB_SUPPORTED
  159734. # define PNG_sRGB_SUPPORTED
  159735. #endif
  159736. #ifndef PNG_NO_READ_tEXt
  159737. # define PNG_READ_tEXt_SUPPORTED
  159738. # define PNG_tEXt_SUPPORTED
  159739. #endif
  159740. #ifndef PNG_NO_READ_tIME
  159741. # define PNG_READ_tIME_SUPPORTED
  159742. # define PNG_tIME_SUPPORTED
  159743. #endif
  159744. #ifndef PNG_NO_READ_tRNS
  159745. # define PNG_READ_tRNS_SUPPORTED
  159746. # define PNG_tRNS_SUPPORTED
  159747. #endif
  159748. #ifndef PNG_NO_READ_zTXt
  159749. # define PNG_READ_zTXt_SUPPORTED
  159750. # define PNG_zTXt_SUPPORTED
  159751. #endif
  159752. #ifndef PNG_NO_READ_UNKNOWN_CHUNKS
  159753. # define PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
  159754. # ifndef PNG_UNKNOWN_CHUNKS_SUPPORTED
  159755. # define PNG_UNKNOWN_CHUNKS_SUPPORTED
  159756. # endif
  159757. # ifndef PNG_NO_HANDLE_AS_UNKNOWN
  159758. # define PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  159759. # endif
  159760. #endif
  159761. #if !defined(PNG_NO_READ_USER_CHUNKS) && \
  159762. defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  159763. # define PNG_READ_USER_CHUNKS_SUPPORTED
  159764. # define PNG_USER_CHUNKS_SUPPORTED
  159765. # ifdef PNG_NO_READ_UNKNOWN_CHUNKS
  159766. # undef PNG_NO_READ_UNKNOWN_CHUNKS
  159767. # endif
  159768. # ifdef PNG_NO_HANDLE_AS_UNKNOWN
  159769. # undef PNG_NO_HANDLE_AS_UNKNOWN
  159770. # endif
  159771. #endif
  159772. #ifndef PNG_NO_READ_OPT_PLTE
  159773. # define PNG_READ_OPT_PLTE_SUPPORTED /* only affects support of the */
  159774. #endif /* optional PLTE chunk in RGB and RGBA images */
  159775. #if defined(PNG_READ_iTXt_SUPPORTED) || defined(PNG_READ_tEXt_SUPPORTED) || \
  159776. defined(PNG_READ_zTXt_SUPPORTED)
  159777. # define PNG_READ_TEXT_SUPPORTED
  159778. # define PNG_TEXT_SUPPORTED
  159779. #endif
  159780. #endif /* PNG_READ_ANCILLARY_CHUNKS_SUPPORTED */
  159781. #ifdef PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
  159782. #ifdef PNG_NO_WRITE_TEXT
  159783. # define PNG_NO_WRITE_iTXt
  159784. # define PNG_NO_WRITE_tEXt
  159785. # define PNG_NO_WRITE_zTXt
  159786. #endif
  159787. #ifndef PNG_NO_WRITE_bKGD
  159788. # define PNG_WRITE_bKGD_SUPPORTED
  159789. # ifndef PNG_bKGD_SUPPORTED
  159790. # define PNG_bKGD_SUPPORTED
  159791. # endif
  159792. #endif
  159793. #ifndef PNG_NO_WRITE_cHRM
  159794. # define PNG_WRITE_cHRM_SUPPORTED
  159795. # ifndef PNG_cHRM_SUPPORTED
  159796. # define PNG_cHRM_SUPPORTED
  159797. # endif
  159798. #endif
  159799. #ifndef PNG_NO_WRITE_gAMA
  159800. # define PNG_WRITE_gAMA_SUPPORTED
  159801. # ifndef PNG_gAMA_SUPPORTED
  159802. # define PNG_gAMA_SUPPORTED
  159803. # endif
  159804. #endif
  159805. #ifndef PNG_NO_WRITE_hIST
  159806. # define PNG_WRITE_hIST_SUPPORTED
  159807. # ifndef PNG_hIST_SUPPORTED
  159808. # define PNG_hIST_SUPPORTED
  159809. # endif
  159810. #endif
  159811. #ifndef PNG_NO_WRITE_iCCP
  159812. # define PNG_WRITE_iCCP_SUPPORTED
  159813. # ifndef PNG_iCCP_SUPPORTED
  159814. # define PNG_iCCP_SUPPORTED
  159815. # endif
  159816. #endif
  159817. #ifndef PNG_NO_WRITE_iTXt
  159818. # ifndef PNG_WRITE_iTXt_SUPPORTED
  159819. # define PNG_WRITE_iTXt_SUPPORTED
  159820. # endif
  159821. # ifndef PNG_iTXt_SUPPORTED
  159822. # define PNG_iTXt_SUPPORTED
  159823. # endif
  159824. #endif
  159825. #ifndef PNG_NO_WRITE_oFFs
  159826. # define PNG_WRITE_oFFs_SUPPORTED
  159827. # ifndef PNG_oFFs_SUPPORTED
  159828. # define PNG_oFFs_SUPPORTED
  159829. # endif
  159830. #endif
  159831. #ifndef PNG_NO_WRITE_pCAL
  159832. # define PNG_WRITE_pCAL_SUPPORTED
  159833. # ifndef PNG_pCAL_SUPPORTED
  159834. # define PNG_pCAL_SUPPORTED
  159835. # endif
  159836. #endif
  159837. #ifndef PNG_NO_WRITE_sCAL
  159838. # define PNG_WRITE_sCAL_SUPPORTED
  159839. # ifndef PNG_sCAL_SUPPORTED
  159840. # define PNG_sCAL_SUPPORTED
  159841. # endif
  159842. #endif
  159843. #ifndef PNG_NO_WRITE_pHYs
  159844. # define PNG_WRITE_pHYs_SUPPORTED
  159845. # ifndef PNG_pHYs_SUPPORTED
  159846. # define PNG_pHYs_SUPPORTED
  159847. # endif
  159848. #endif
  159849. #ifndef PNG_NO_WRITE_sBIT
  159850. # define PNG_WRITE_sBIT_SUPPORTED
  159851. # ifndef PNG_sBIT_SUPPORTED
  159852. # define PNG_sBIT_SUPPORTED
  159853. # endif
  159854. #endif
  159855. #ifndef PNG_NO_WRITE_sPLT
  159856. # define PNG_WRITE_sPLT_SUPPORTED
  159857. # ifndef PNG_sPLT_SUPPORTED
  159858. # define PNG_sPLT_SUPPORTED
  159859. # endif
  159860. #endif
  159861. #ifndef PNG_NO_WRITE_sRGB
  159862. # define PNG_WRITE_sRGB_SUPPORTED
  159863. # ifndef PNG_sRGB_SUPPORTED
  159864. # define PNG_sRGB_SUPPORTED
  159865. # endif
  159866. #endif
  159867. #ifndef PNG_NO_WRITE_tEXt
  159868. # define PNG_WRITE_tEXt_SUPPORTED
  159869. # ifndef PNG_tEXt_SUPPORTED
  159870. # define PNG_tEXt_SUPPORTED
  159871. # endif
  159872. #endif
  159873. #ifndef PNG_NO_WRITE_tIME
  159874. # define PNG_WRITE_tIME_SUPPORTED
  159875. # ifndef PNG_tIME_SUPPORTED
  159876. # define PNG_tIME_SUPPORTED
  159877. # endif
  159878. #endif
  159879. #ifndef PNG_NO_WRITE_tRNS
  159880. # define PNG_WRITE_tRNS_SUPPORTED
  159881. # ifndef PNG_tRNS_SUPPORTED
  159882. # define PNG_tRNS_SUPPORTED
  159883. # endif
  159884. #endif
  159885. #ifndef PNG_NO_WRITE_zTXt
  159886. # define PNG_WRITE_zTXt_SUPPORTED
  159887. # ifndef PNG_zTXt_SUPPORTED
  159888. # define PNG_zTXt_SUPPORTED
  159889. # endif
  159890. #endif
  159891. #ifndef PNG_NO_WRITE_UNKNOWN_CHUNKS
  159892. # define PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
  159893. # ifndef PNG_UNKNOWN_CHUNKS_SUPPORTED
  159894. # define PNG_UNKNOWN_CHUNKS_SUPPORTED
  159895. # endif
  159896. # ifndef PNG_NO_HANDLE_AS_UNKNOWN
  159897. # ifndef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  159898. # define PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  159899. # endif
  159900. # endif
  159901. #endif
  159902. #if defined(PNG_WRITE_iTXt_SUPPORTED) || defined(PNG_WRITE_tEXt_SUPPORTED) || \
  159903. defined(PNG_WRITE_zTXt_SUPPORTED)
  159904. # define PNG_WRITE_TEXT_SUPPORTED
  159905. # ifndef PNG_TEXT_SUPPORTED
  159906. # define PNG_TEXT_SUPPORTED
  159907. # endif
  159908. #endif
  159909. #endif /* PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED */
  159910. #ifndef PNG_NO_INFO_IMAGE
  159911. # define PNG_INFO_IMAGE_SUPPORTED
  159912. #endif
  159913. #if defined(PNG_tIME_SUPPORTED)
  159914. # if !defined(_WIN32_WCE)
  159915. # include <time.h>
  159916. # endif
  159917. #endif
  159918. typedef unsigned long png_uint_32;
  159919. typedef long png_int_32;
  159920. typedef unsigned short png_uint_16;
  159921. typedef short png_int_16;
  159922. typedef unsigned char png_byte;
  159923. #ifdef PNG_SIZE_T
  159924. typedef PNG_SIZE_T png_size_t;
  159925. # define png_sizeof(x) png_convert_size(sizeof (x))
  159926. #else
  159927. typedef size_t png_size_t;
  159928. # define png_sizeof(x) sizeof (x)
  159929. #endif
  159930. #ifdef __BORLANDC__
  159931. # if defined(__LARGE__) || defined(__HUGE__) || defined(__COMPACT__)
  159932. # define LDATA 1
  159933. # else
  159934. # define LDATA 0
  159935. # endif
  159936. # if !defined(__WIN32__) && !defined(__FLAT__) && !defined(__CYGWIN__)
  159937. # define PNG_MAX_MALLOC_64K
  159938. # if (LDATA != 1)
  159939. # ifndef FAR
  159940. # define FAR __far
  159941. # endif
  159942. # define USE_FAR_KEYWORD
  159943. # endif /* LDATA != 1 */
  159944. # endif /* __WIN32__, __FLAT__, __CYGWIN__ */
  159945. #endif /* __BORLANDC__ */
  159946. #if defined(FAR)
  159947. # if defined(M_I86MM)
  159948. # define USE_FAR_KEYWORD
  159949. # define FARDATA FAR
  159950. # include <dos.h>
  159951. # endif
  159952. #endif
  159953. #ifndef FAR
  159954. # define FAR
  159955. #endif
  159956. #ifndef FARDATA
  159957. # define FARDATA
  159958. #endif
  159959. typedef png_int_32 png_fixed_point;
  159960. typedef void FAR * png_voidp;
  159961. typedef png_byte FAR * png_bytep;
  159962. typedef png_uint_32 FAR * png_uint_32p;
  159963. typedef png_int_32 FAR * png_int_32p;
  159964. typedef png_uint_16 FAR * png_uint_16p;
  159965. typedef png_int_16 FAR * png_int_16p;
  159966. typedef PNG_CONST char FAR * png_const_charp;
  159967. typedef char FAR * png_charp;
  159968. typedef png_fixed_point FAR * png_fixed_point_p;
  159969. #ifndef PNG_NO_STDIO
  159970. #if defined(_WIN32_WCE)
  159971. typedef HANDLE png_FILE_p;
  159972. #else
  159973. typedef FILE * png_FILE_p;
  159974. #endif
  159975. #endif
  159976. #ifdef PNG_FLOATING_POINT_SUPPORTED
  159977. typedef double FAR * png_doublep;
  159978. #endif
  159979. typedef png_byte FAR * FAR * png_bytepp;
  159980. typedef png_uint_32 FAR * FAR * png_uint_32pp;
  159981. typedef png_int_32 FAR * FAR * png_int_32pp;
  159982. typedef png_uint_16 FAR * FAR * png_uint_16pp;
  159983. typedef png_int_16 FAR * FAR * png_int_16pp;
  159984. typedef PNG_CONST char FAR * FAR * png_const_charpp;
  159985. typedef char FAR * FAR * png_charpp;
  159986. typedef png_fixed_point FAR * FAR * png_fixed_point_pp;
  159987. #ifdef PNG_FLOATING_POINT_SUPPORTED
  159988. typedef double FAR * FAR * png_doublepp;
  159989. #endif
  159990. typedef char FAR * FAR * FAR * png_charppp;
  159991. #if 0
  159992. typedef charf * png_zcharp;
  159993. typedef charf * FAR * png_zcharpp;
  159994. typedef z_stream FAR * png_zstreamp;
  159995. #endif /* (PNG_1_0_X) || defined(PNG_1_2_X) */
  159996. #if !defined(PNG_DLL) && (defined(PNG_BUILD_DLL) || defined(PNG_USE_DLL))
  159997. # define PNG_DLL
  159998. #endif
  159999. #if defined(__CYGWIN__)
  160000. # if !defined(PNG_STATIC)
  160001. # if defined(PNG_USE_GLOBAL_ARRAYS)
  160002. # undef PNG_USE_GLOBAL_ARRAYS
  160003. # endif
  160004. # if !defined(PNG_USE_LOCAL_ARRAYS)
  160005. # define PNG_USE_LOCAL_ARRAYS
  160006. # endif
  160007. # else
  160008. # if defined(PNG_USE_LOCAL_ARRAYS) || defined(PNG_NO_GLOBAL_ARRAYS)
  160009. # if defined(PNG_USE_GLOBAL_ARRAYS)
  160010. # undef PNG_USE_GLOBAL_ARRAYS
  160011. # endif
  160012. # endif
  160013. # endif
  160014. # if !defined(PNG_USE_LOCAL_ARRAYS) && !defined(PNG_USE_GLOBAL_ARRAYS)
  160015. # define PNG_USE_LOCAL_ARRAYS
  160016. # endif
  160017. #endif
  160018. #if !defined(PNG_USE_LOCAL_ARRAYS) && !defined(PNG_USE_GLOBAL_ARRAYS)
  160019. # if defined(PNG_NO_GLOBAL_ARRAYS) || \
  160020. (defined(__GNUC__) && defined(PNG_DLL)) || defined(_MSC_VER)
  160021. # define PNG_USE_LOCAL_ARRAYS
  160022. # else
  160023. # define PNG_USE_GLOBAL_ARRAYS
  160024. # endif
  160025. #endif
  160026. #if defined(__CYGWIN__)
  160027. # undef PNGAPI
  160028. # define PNGAPI __cdecl
  160029. # undef PNG_IMPEXP
  160030. # define PNG_IMPEXP
  160031. #endif
  160032. #if defined(__MINGW32__) && !defined(PNG_MODULEDEF)
  160033. # ifndef PNG_NO_MODULEDEF
  160034. # define PNG_NO_MODULEDEF
  160035. # endif
  160036. #endif
  160037. #if !defined(PNG_IMPEXP) && defined(PNG_BUILD_DLL) && !defined(PNG_NO_MODULEDEF)
  160038. # define PNG_IMPEXP
  160039. #endif
  160040. #if defined(PNG_DLL) || defined(_DLL) || defined(__DLL__ ) || \
  160041. (( defined(_Windows) || defined(_WINDOWS) || \
  160042. defined(WIN32) || defined(_WIN32) || defined(__WIN32__) ))
  160043. # ifndef PNGAPI
  160044. # if defined(__GNUC__) || (defined (_MSC_VER) && (_MSC_VER >= 800))
  160045. # define PNGAPI __cdecl
  160046. # else
  160047. # define PNGAPI _cdecl
  160048. # endif
  160049. # endif
  160050. # if !defined(PNG_IMPEXP) && (!defined(PNG_DLL) || \
  160051. 0 /* WINCOMPILER_WITH_NO_SUPPORT_FOR_DECLIMPEXP */)
  160052. # define PNG_IMPEXP
  160053. # endif
  160054. # if !defined(PNG_IMPEXP)
  160055. # define PNG_EXPORT_TYPE1(type,symbol) PNG_IMPEXP type PNGAPI symbol
  160056. # define PNG_EXPORT_TYPE2(type,symbol) type PNG_IMPEXP PNGAPI symbol
  160057. # if defined(_MSC_VER) || defined(__BORLANDC__)
  160058. # if (_MSC_VER >= 800) || (__BORLANDC__ >= 0x500)
  160059. # define PNG_EXPORT PNG_EXPORT_TYPE1
  160060. # else
  160061. # define PNG_EXPORT PNG_EXPORT_TYPE2
  160062. # if defined(PNG_BUILD_DLL)
  160063. # define PNG_IMPEXP __export
  160064. # else
  160065. # define PNG_IMPEXP /*__import */ /* doesn't exist AFAIK in
  160066. VC++ */
  160067. # endif /* Exists in Borland C++ for
  160068. C++ classes (== huge) */
  160069. # endif
  160070. # endif
  160071. # if !defined(PNG_IMPEXP)
  160072. # if defined(PNG_BUILD_DLL)
  160073. # define PNG_IMPEXP __declspec(dllexport)
  160074. # else
  160075. # define PNG_IMPEXP __declspec(dllimport)
  160076. # endif
  160077. # endif
  160078. # endif /* PNG_IMPEXP */
  160079. #else /* !(DLL || non-cygwin WINDOWS) */
  160080. # if (defined(__IBMC__) || defined(__IBMCPP__)) && defined(__OS2__)
  160081. # ifndef PNGAPI
  160082. # define PNGAPI _System
  160083. # endif
  160084. # else
  160085. # if 0 /* ... other platforms, with other meanings */
  160086. # endif
  160087. # endif
  160088. #endif
  160089. #ifndef PNGAPI
  160090. # define PNGAPI
  160091. #endif
  160092. #ifndef PNG_IMPEXP
  160093. # define PNG_IMPEXP
  160094. #endif
  160095. #ifdef PNG_BUILDSYMS
  160096. # ifndef PNG_EXPORT
  160097. # define PNG_EXPORT(type,symbol) PNG_FUNCTION_EXPORT symbol END
  160098. # endif
  160099. # ifdef PNG_USE_GLOBAL_ARRAYS
  160100. # ifndef PNG_EXPORT_VAR
  160101. # define PNG_EXPORT_VAR(type) PNG_DATA_EXPORT
  160102. # endif
  160103. # endif
  160104. #endif
  160105. #ifndef PNG_EXPORT
  160106. # define PNG_EXPORT(type,symbol) PNG_IMPEXP type PNGAPI symbol
  160107. #endif
  160108. #ifdef PNG_USE_GLOBAL_ARRAYS
  160109. # ifndef PNG_EXPORT_VAR
  160110. # define PNG_EXPORT_VAR(type) extern PNG_IMPEXP type
  160111. # endif
  160112. #endif
  160113. #ifndef PNG_ABORT
  160114. # define PNG_ABORT() abort()
  160115. #endif
  160116. #ifdef PNG_SETJMP_SUPPORTED
  160117. # define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf)
  160118. #else
  160119. # define png_jmpbuf(png_ptr) \
  160120. (LIBPNG_WAS_COMPILED_WITH__PNG_SETJMP_NOT_SUPPORTED)
  160121. #endif
  160122. #if defined(USE_FAR_KEYWORD) /* memory model independent fns */
  160123. # define CHECK 1
  160124. # define NOCHECK 0
  160125. # define CVT_PTR(ptr) (png_far_to_near(png_ptr,ptr,CHECK))
  160126. # define CVT_PTR_NOCHECK(ptr) (png_far_to_near(png_ptr,ptr,NOCHECK))
  160127. # define png_snprintf _fsnprintf /* Added to v 1.2.19 */
  160128. # define png_strcpy _fstrcpy
  160129. # define png_strncpy _fstrncpy /* Added to v 1.2.6 */
  160130. # define png_strlen _fstrlen
  160131. # define png_memcmp _fmemcmp /* SJT: added */
  160132. # define png_memcpy _fmemcpy
  160133. # define png_memset _fmemset
  160134. #else /* use the usual functions */
  160135. # define CVT_PTR(ptr) (ptr)
  160136. # define CVT_PTR_NOCHECK(ptr) (ptr)
  160137. # ifndef PNG_NO_SNPRINTF
  160138. # ifdef _MSC_VER
  160139. # define png_snprintf _snprintf /* Added to v 1.2.19 */
  160140. # define png_snprintf2 _snprintf
  160141. # define png_snprintf6 _snprintf
  160142. # else
  160143. # define png_snprintf snprintf /* Added to v 1.2.19 */
  160144. # define png_snprintf2 snprintf
  160145. # define png_snprintf6 snprintf
  160146. # endif
  160147. # else
  160148. # define png_snprintf(s1,n,fmt,x1) sprintf(s1,fmt,x1)
  160149. # define png_snprintf2(s1,n,fmt,x1,x2) sprintf(s1,fmt,x1,x2)
  160150. # define png_snprintf6(s1,n,fmt,x1,x2,x3,x4,x5,x6) \
  160151. sprintf(s1,fmt,x1,x2,x3,x4,x5,x6)
  160152. # endif
  160153. # define png_strcpy strcpy
  160154. # define png_strncpy strncpy /* Added to v 1.2.6 */
  160155. # define png_strlen strlen
  160156. # define png_memcmp memcmp /* SJT: added */
  160157. # define png_memcpy memcpy
  160158. # define png_memset memset
  160159. #endif
  160160. #if (PNG_ZBUF_SIZE > 65536L) && defined(PNG_MAX_MALLOC_64K)
  160161. # undef PNG_ZBUF_SIZE
  160162. # define PNG_ZBUF_SIZE 65536L
  160163. #endif
  160164. #endif /* PNG_VERSION_INFO_ONLY */
  160165. #endif /* PNGCONF_H */
  160166. /*** End of inlined file: pngconf.h ***/
  160167. #ifdef _MSC_VER
  160168. #pragma warning (disable: 4996 4100)
  160169. #endif
  160170. #if defined(PNG_USER_PRIVATEBUILD)
  160171. # define PNG_LIBPNG_BUILD_TYPE \
  160172. (PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_PRIVATE)
  160173. #else
  160174. # if defined(PNG_LIBPNG_SPECIALBUILD)
  160175. # define PNG_LIBPNG_BUILD_TYPE \
  160176. (PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_SPECIAL)
  160177. # else
  160178. # define PNG_LIBPNG_BUILD_TYPE (PNG_LIBPNG_BUILD_BASE_TYPE)
  160179. # endif
  160180. #endif
  160181. #ifndef PNG_VERSION_INFO_ONLY
  160182. #ifdef __cplusplus
  160183. extern "C" {
  160184. #endif /* __cplusplus */
  160185. #ifndef PNG_NO_TYPECAST_NULL
  160186. #define int_p_NULL (int *)NULL
  160187. #define png_bytep_NULL (png_bytep)NULL
  160188. #define png_bytepp_NULL (png_bytepp)NULL
  160189. #define png_doublep_NULL (png_doublep)NULL
  160190. #define png_error_ptr_NULL (png_error_ptr)NULL
  160191. #define png_flush_ptr_NULL (png_flush_ptr)NULL
  160192. #define png_free_ptr_NULL (png_free_ptr)NULL
  160193. #define png_infopp_NULL (png_infopp)NULL
  160194. #define png_malloc_ptr_NULL (png_malloc_ptr)NULL
  160195. #define png_read_status_ptr_NULL (png_read_status_ptr)NULL
  160196. #define png_rw_ptr_NULL (png_rw_ptr)NULL
  160197. #define png_structp_NULL (png_structp)NULL
  160198. #define png_uint_16p_NULL (png_uint_16p)NULL
  160199. #define png_voidp_NULL (png_voidp)NULL
  160200. #define png_write_status_ptr_NULL (png_write_status_ptr)NULL
  160201. #else
  160202. #define int_p_NULL NULL
  160203. #define png_bytep_NULL NULL
  160204. #define png_bytepp_NULL NULL
  160205. #define png_doublep_NULL NULL
  160206. #define png_error_ptr_NULL NULL
  160207. #define png_flush_ptr_NULL NULL
  160208. #define png_free_ptr_NULL NULL
  160209. #define png_infopp_NULL NULL
  160210. #define png_malloc_ptr_NULL NULL
  160211. #define png_read_status_ptr_NULL NULL
  160212. #define png_rw_ptr_NULL NULL
  160213. #define png_structp_NULL NULL
  160214. #define png_uint_16p_NULL NULL
  160215. #define png_voidp_NULL NULL
  160216. #define png_write_status_ptr_NULL NULL
  160217. #endif
  160218. #if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN)
  160219. #ifdef PNG_USE_GLOBAL_ARRAYS
  160220. PNG_EXPORT_VAR (PNG_CONST char) png_libpng_ver[18];
  160221. #else
  160222. #define png_libpng_ver png_get_header_ver(NULL)
  160223. #endif
  160224. #ifdef PNG_USE_GLOBAL_ARRAYS
  160225. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_start[7];
  160226. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_inc[7];
  160227. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_ystart[7];
  160228. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_yinc[7];
  160229. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_mask[7];
  160230. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_dsp_mask[7];
  160231. #endif
  160232. #endif /* PNG_NO_EXTERN */
  160233. typedef struct png_color_struct
  160234. {
  160235. png_byte red;
  160236. png_byte green;
  160237. png_byte blue;
  160238. } png_color;
  160239. typedef png_color FAR * png_colorp;
  160240. typedef png_color FAR * FAR * png_colorpp;
  160241. typedef struct png_color_16_struct
  160242. {
  160243. png_byte index; /* used for palette files */
  160244. png_uint_16 red; /* for use in red green blue files */
  160245. png_uint_16 green;
  160246. png_uint_16 blue;
  160247. png_uint_16 gray; /* for use in grayscale files */
  160248. } png_color_16;
  160249. typedef png_color_16 FAR * png_color_16p;
  160250. typedef png_color_16 FAR * FAR * png_color_16pp;
  160251. typedef struct png_color_8_struct
  160252. {
  160253. png_byte red; /* for use in red green blue files */
  160254. png_byte green;
  160255. png_byte blue;
  160256. png_byte gray; /* for use in grayscale files */
  160257. png_byte alpha; /* for alpha channel files */
  160258. } png_color_8;
  160259. typedef png_color_8 FAR * png_color_8p;
  160260. typedef png_color_8 FAR * FAR * png_color_8pp;
  160261. typedef struct png_sPLT_entry_struct
  160262. {
  160263. png_uint_16 red;
  160264. png_uint_16 green;
  160265. png_uint_16 blue;
  160266. png_uint_16 alpha;
  160267. png_uint_16 frequency;
  160268. } png_sPLT_entry;
  160269. typedef png_sPLT_entry FAR * png_sPLT_entryp;
  160270. typedef png_sPLT_entry FAR * FAR * png_sPLT_entrypp;
  160271. typedef struct png_sPLT_struct
  160272. {
  160273. png_charp name; /* palette name */
  160274. png_byte depth; /* depth of palette samples */
  160275. png_sPLT_entryp entries; /* palette entries */
  160276. png_int_32 nentries; /* number of palette entries */
  160277. } png_sPLT_t;
  160278. typedef png_sPLT_t FAR * png_sPLT_tp;
  160279. typedef png_sPLT_t FAR * FAR * png_sPLT_tpp;
  160280. #ifdef PNG_TEXT_SUPPORTED
  160281. typedef struct png_text_struct
  160282. {
  160283. int compression; /* compression value:
  160284. -1: tEXt, none
  160285. 0: zTXt, deflate
  160286. 1: iTXt, none
  160287. 2: iTXt, deflate */
  160288. png_charp key; /* keyword, 1-79 character description of "text" */
  160289. png_charp text; /* comment, may be an empty string (ie "")
  160290. or a NULL pointer */
  160291. png_size_t text_length; /* length of the text string */
  160292. #ifdef PNG_iTXt_SUPPORTED
  160293. png_size_t itxt_length; /* length of the itxt string */
  160294. png_charp lang; /* language code, 0-79 characters
  160295. or a NULL pointer */
  160296. png_charp lang_key; /* keyword translated UTF-8 string, 0 or more
  160297. chars or a NULL pointer */
  160298. #endif
  160299. } png_text;
  160300. typedef png_text FAR * png_textp;
  160301. typedef png_text FAR * FAR * png_textpp;
  160302. #endif
  160303. #define PNG_TEXT_COMPRESSION_NONE_WR -3
  160304. #define PNG_TEXT_COMPRESSION_zTXt_WR -2
  160305. #define PNG_TEXT_COMPRESSION_NONE -1
  160306. #define PNG_TEXT_COMPRESSION_zTXt 0
  160307. #define PNG_ITXT_COMPRESSION_NONE 1
  160308. #define PNG_ITXT_COMPRESSION_zTXt 2
  160309. #define PNG_TEXT_COMPRESSION_LAST 3 /* Not a valid value */
  160310. typedef struct png_time_struct
  160311. {
  160312. png_uint_16 year; /* full year, as in, 1995 */
  160313. png_byte month; /* month of year, 1 - 12 */
  160314. png_byte day; /* day of month, 1 - 31 */
  160315. png_byte hour; /* hour of day, 0 - 23 */
  160316. png_byte minute; /* minute of hour, 0 - 59 */
  160317. png_byte second; /* second of minute, 0 - 60 (for leap seconds) */
  160318. } png_time;
  160319. typedef png_time FAR * png_timep;
  160320. typedef png_time FAR * FAR * png_timepp;
  160321. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160322. typedef struct png_unknown_chunk_t
  160323. {
  160324. png_byte name[5];
  160325. png_byte *data;
  160326. png_size_t size;
  160327. png_byte location; /* mode of operation at read time */
  160328. }
  160329. png_unknown_chunk;
  160330. typedef png_unknown_chunk FAR * png_unknown_chunkp;
  160331. typedef png_unknown_chunk FAR * FAR * png_unknown_chunkpp;
  160332. #endif
  160333. typedef struct png_info_struct
  160334. {
  160335. png_uint_32 width; /* width of image in pixels (from IHDR) */
  160336. png_uint_32 height; /* height of image in pixels (from IHDR) */
  160337. png_uint_32 valid; /* valid chunk data (see PNG_INFO_ below) */
  160338. png_uint_32 rowbytes; /* bytes needed to hold an untransformed row */
  160339. png_colorp palette; /* array of color values (valid & PNG_INFO_PLTE) */
  160340. png_uint_16 num_palette; /* number of color entries in "palette" (PLTE) */
  160341. png_uint_16 num_trans; /* number of transparent palette color (tRNS) */
  160342. png_byte bit_depth; /* 1, 2, 4, 8, or 16 bits/channel (from IHDR) */
  160343. png_byte color_type; /* see PNG_COLOR_TYPE_ below (from IHDR) */
  160344. png_byte compression_type; /* must be PNG_COMPRESSION_TYPE_BASE (IHDR) */
  160345. png_byte filter_type; /* must be PNG_FILTER_TYPE_BASE (from IHDR) */
  160346. png_byte interlace_type; /* One of PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
  160347. png_byte channels; /* number of data channels per pixel (1, 2, 3, 4) */
  160348. png_byte pixel_depth; /* number of bits per pixel */
  160349. png_byte spare_byte; /* to align the data, and for future use */
  160350. png_byte signature[8]; /* magic bytes read by libpng from start of file */
  160351. #if defined(PNG_gAMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  160352. float gamma; /* gamma value of image, if (valid & PNG_INFO_gAMA) */
  160353. #endif
  160354. #if defined(PNG_sRGB_SUPPORTED)
  160355. png_byte srgb_intent; /* sRGB rendering intent [0, 1, 2, or 3] */
  160356. #endif
  160357. #if defined(PNG_TEXT_SUPPORTED)
  160358. int num_text; /* number of comments read/to write */
  160359. int max_text; /* current size of text array */
  160360. png_textp text; /* array of comments read/to write */
  160361. #endif /* PNG_TEXT_SUPPORTED */
  160362. #if defined(PNG_tIME_SUPPORTED)
  160363. png_time mod_time;
  160364. #endif
  160365. #if defined(PNG_sBIT_SUPPORTED)
  160366. png_color_8 sig_bit; /* significant bits in color channels */
  160367. #endif
  160368. #if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_EXPAND_SUPPORTED) || \
  160369. defined(PNG_READ_BACKGROUND_SUPPORTED)
  160370. png_bytep trans; /* transparent values for paletted image */
  160371. png_color_16 trans_values; /* transparent color for non-palette image */
  160372. #endif
  160373. #if defined(PNG_bKGD_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160374. png_color_16 background;
  160375. #endif
  160376. #if defined(PNG_oFFs_SUPPORTED)
  160377. png_int_32 x_offset; /* x offset on page */
  160378. png_int_32 y_offset; /* y offset on page */
  160379. png_byte offset_unit_type; /* offset units type */
  160380. #endif
  160381. #if defined(PNG_pHYs_SUPPORTED)
  160382. png_uint_32 x_pixels_per_unit; /* horizontal pixel density */
  160383. png_uint_32 y_pixels_per_unit; /* vertical pixel density */
  160384. png_byte phys_unit_type; /* resolution type (see PNG_RESOLUTION_ below) */
  160385. #endif
  160386. #if defined(PNG_hIST_SUPPORTED)
  160387. png_uint_16p hist;
  160388. #endif
  160389. #ifdef PNG_cHRM_SUPPORTED
  160390. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160391. float x_white;
  160392. float y_white;
  160393. float x_red;
  160394. float y_red;
  160395. float x_green;
  160396. float y_green;
  160397. float x_blue;
  160398. float y_blue;
  160399. #endif
  160400. #endif
  160401. #if defined(PNG_pCAL_SUPPORTED)
  160402. png_charp pcal_purpose; /* pCAL chunk description string */
  160403. png_int_32 pcal_X0; /* minimum value */
  160404. png_int_32 pcal_X1; /* maximum value */
  160405. png_charp pcal_units; /* Latin-1 string giving physical units */
  160406. png_charpp pcal_params; /* ASCII strings containing parameter values */
  160407. png_byte pcal_type; /* equation type (see PNG_EQUATION_ below) */
  160408. png_byte pcal_nparams; /* number of parameters given in pcal_params */
  160409. #endif
  160410. #ifdef PNG_FREE_ME_SUPPORTED
  160411. png_uint_32 free_me; /* flags items libpng is responsible for freeing */
  160412. #endif
  160413. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160414. png_unknown_chunkp unknown_chunks;
  160415. png_size_t unknown_chunks_num;
  160416. #endif
  160417. #if defined(PNG_iCCP_SUPPORTED)
  160418. png_charp iccp_name; /* profile name */
  160419. png_charp iccp_profile; /* International Color Consortium profile data */
  160420. png_uint_32 iccp_proflen; /* ICC profile data length */
  160421. png_byte iccp_compression; /* Always zero */
  160422. #endif
  160423. #if defined(PNG_sPLT_SUPPORTED)
  160424. png_sPLT_tp splt_palettes;
  160425. png_uint_32 splt_palettes_num;
  160426. #endif
  160427. #if defined(PNG_sCAL_SUPPORTED)
  160428. png_byte scal_unit; /* unit of physical scale */
  160429. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160430. double scal_pixel_width; /* width of one pixel */
  160431. double scal_pixel_height; /* height of one pixel */
  160432. #endif
  160433. #ifdef PNG_FIXED_POINT_SUPPORTED
  160434. png_charp scal_s_width; /* string containing height */
  160435. png_charp scal_s_height; /* string containing width */
  160436. #endif
  160437. #endif
  160438. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  160439. png_bytepp row_pointers; /* the image bits */
  160440. #endif
  160441. #if defined(PNG_FIXED_POINT_SUPPORTED) && defined(PNG_gAMA_SUPPORTED)
  160442. png_fixed_point int_gamma; /* gamma of image, if (valid & PNG_INFO_gAMA) */
  160443. #endif
  160444. #if defined(PNG_cHRM_SUPPORTED) && defined(PNG_FIXED_POINT_SUPPORTED)
  160445. png_fixed_point int_x_white;
  160446. png_fixed_point int_y_white;
  160447. png_fixed_point int_x_red;
  160448. png_fixed_point int_y_red;
  160449. png_fixed_point int_x_green;
  160450. png_fixed_point int_y_green;
  160451. png_fixed_point int_x_blue;
  160452. png_fixed_point int_y_blue;
  160453. #endif
  160454. } png_info;
  160455. typedef png_info FAR * png_infop;
  160456. typedef png_info FAR * FAR * png_infopp;
  160457. #define PNG_UINT_31_MAX ((png_uint_32)0x7fffffffL)
  160458. #define PNG_UINT_32_MAX ((png_uint_32)(-1))
  160459. #define PNG_SIZE_MAX ((png_size_t)(-1))
  160460. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  160461. #define PNG_MAX_UINT PNG_UINT_31_MAX
  160462. #endif
  160463. #define PNG_COLOR_MASK_PALETTE 1
  160464. #define PNG_COLOR_MASK_COLOR 2
  160465. #define PNG_COLOR_MASK_ALPHA 4
  160466. #define PNG_COLOR_TYPE_GRAY 0
  160467. #define PNG_COLOR_TYPE_PALETTE (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_PALETTE)
  160468. #define PNG_COLOR_TYPE_RGB (PNG_COLOR_MASK_COLOR)
  160469. #define PNG_COLOR_TYPE_RGB_ALPHA (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_ALPHA)
  160470. #define PNG_COLOR_TYPE_GRAY_ALPHA (PNG_COLOR_MASK_ALPHA)
  160471. #define PNG_COLOR_TYPE_RGBA PNG_COLOR_TYPE_RGB_ALPHA
  160472. #define PNG_COLOR_TYPE_GA PNG_COLOR_TYPE_GRAY_ALPHA
  160473. #define PNG_COMPRESSION_TYPE_BASE 0 /* Deflate method 8, 32K window */
  160474. #define PNG_COMPRESSION_TYPE_DEFAULT PNG_COMPRESSION_TYPE_BASE
  160475. #define PNG_FILTER_TYPE_BASE 0 /* Single row per-byte filtering */
  160476. #define PNG_INTRAPIXEL_DIFFERENCING 64 /* Used only in MNG datastreams */
  160477. #define PNG_FILTER_TYPE_DEFAULT PNG_FILTER_TYPE_BASE
  160478. #define PNG_INTERLACE_NONE 0 /* Non-interlaced image */
  160479. #define PNG_INTERLACE_ADAM7 1 /* Adam7 interlacing */
  160480. #define PNG_INTERLACE_LAST 2 /* Not a valid value */
  160481. #define PNG_OFFSET_PIXEL 0 /* Offset in pixels */
  160482. #define PNG_OFFSET_MICROMETER 1 /* Offset in micrometers (1/10^6 meter) */
  160483. #define PNG_OFFSET_LAST 2 /* Not a valid value */
  160484. #define PNG_EQUATION_LINEAR 0 /* Linear transformation */
  160485. #define PNG_EQUATION_BASE_E 1 /* Exponential base e transform */
  160486. #define PNG_EQUATION_ARBITRARY 2 /* Arbitrary base exponential transform */
  160487. #define PNG_EQUATION_HYPERBOLIC 3 /* Hyperbolic sine transformation */
  160488. #define PNG_EQUATION_LAST 4 /* Not a valid value */
  160489. #define PNG_SCALE_UNKNOWN 0 /* unknown unit (image scale) */
  160490. #define PNG_SCALE_METER 1 /* meters per pixel */
  160491. #define PNG_SCALE_RADIAN 2 /* radians per pixel */
  160492. #define PNG_SCALE_LAST 3 /* Not a valid value */
  160493. #define PNG_RESOLUTION_UNKNOWN 0 /* pixels/unknown unit (aspect ratio) */
  160494. #define PNG_RESOLUTION_METER 1 /* pixels/meter */
  160495. #define PNG_RESOLUTION_LAST 2 /* Not a valid value */
  160496. #define PNG_sRGB_INTENT_PERCEPTUAL 0
  160497. #define PNG_sRGB_INTENT_RELATIVE 1
  160498. #define PNG_sRGB_INTENT_SATURATION 2
  160499. #define PNG_sRGB_INTENT_ABSOLUTE 3
  160500. #define PNG_sRGB_INTENT_LAST 4 /* Not a valid value */
  160501. #define PNG_KEYWORD_MAX_LENGTH 79
  160502. #define PNG_MAX_PALETTE_LENGTH 256
  160503. #define PNG_INFO_gAMA 0x0001
  160504. #define PNG_INFO_sBIT 0x0002
  160505. #define PNG_INFO_cHRM 0x0004
  160506. #define PNG_INFO_PLTE 0x0008
  160507. #define PNG_INFO_tRNS 0x0010
  160508. #define PNG_INFO_bKGD 0x0020
  160509. #define PNG_INFO_hIST 0x0040
  160510. #define PNG_INFO_pHYs 0x0080
  160511. #define PNG_INFO_oFFs 0x0100
  160512. #define PNG_INFO_tIME 0x0200
  160513. #define PNG_INFO_pCAL 0x0400
  160514. #define PNG_INFO_sRGB 0x0800 /* GR-P, 0.96a */
  160515. #define PNG_INFO_iCCP 0x1000 /* ESR, 1.0.6 */
  160516. #define PNG_INFO_sPLT 0x2000 /* ESR, 1.0.6 */
  160517. #define PNG_INFO_sCAL 0x4000 /* ESR, 1.0.6 */
  160518. #define PNG_INFO_IDAT 0x8000L /* ESR, 1.0.6 */
  160519. typedef struct png_row_info_struct
  160520. {
  160521. png_uint_32 width; /* width of row */
  160522. png_uint_32 rowbytes; /* number of bytes in row */
  160523. png_byte color_type; /* color type of row */
  160524. png_byte bit_depth; /* bit depth of row */
  160525. png_byte channels; /* number of channels (1, 2, 3, or 4) */
  160526. png_byte pixel_depth; /* bits per pixel (depth * channels) */
  160527. } png_row_info;
  160528. typedef png_row_info FAR * png_row_infop;
  160529. typedef png_row_info FAR * FAR * png_row_infopp;
  160530. typedef struct png_struct_def png_struct;
  160531. typedef png_struct FAR * png_structp;
  160532. typedef void (PNGAPI *png_error_ptr) PNGARG((png_structp, png_const_charp));
  160533. typedef void (PNGAPI *png_rw_ptr) PNGARG((png_structp, png_bytep, png_size_t));
  160534. typedef void (PNGAPI *png_flush_ptr) PNGARG((png_structp));
  160535. typedef void (PNGAPI *png_read_status_ptr) PNGARG((png_structp, png_uint_32,
  160536. int));
  160537. typedef void (PNGAPI *png_write_status_ptr) PNGARG((png_structp, png_uint_32,
  160538. int));
  160539. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  160540. typedef void (PNGAPI *png_progressive_info_ptr) PNGARG((png_structp, png_infop));
  160541. typedef void (PNGAPI *png_progressive_end_ptr) PNGARG((png_structp, png_infop));
  160542. typedef void (PNGAPI *png_progressive_row_ptr) PNGARG((png_structp, png_bytep,
  160543. png_uint_32, int));
  160544. #endif
  160545. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  160546. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  160547. defined(PNG_LEGACY_SUPPORTED)
  160548. typedef void (PNGAPI *png_user_transform_ptr) PNGARG((png_structp,
  160549. png_row_infop, png_bytep));
  160550. #endif
  160551. #if defined(PNG_USER_CHUNKS_SUPPORTED)
  160552. typedef int (PNGAPI *png_user_chunk_ptr) PNGARG((png_structp, png_unknown_chunkp));
  160553. #endif
  160554. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160555. typedef void (PNGAPI *png_unknown_chunk_ptr) PNGARG((png_structp));
  160556. #endif
  160557. #define PNG_TRANSFORM_IDENTITY 0x0000 /* read and write */
  160558. #define PNG_TRANSFORM_STRIP_16 0x0001 /* read only */
  160559. #define PNG_TRANSFORM_STRIP_ALPHA 0x0002 /* read only */
  160560. #define PNG_TRANSFORM_PACKING 0x0004 /* read and write */
  160561. #define PNG_TRANSFORM_PACKSWAP 0x0008 /* read and write */
  160562. #define PNG_TRANSFORM_EXPAND 0x0010 /* read only */
  160563. #define PNG_TRANSFORM_INVERT_MONO 0x0020 /* read and write */
  160564. #define PNG_TRANSFORM_SHIFT 0x0040 /* read and write */
  160565. #define PNG_TRANSFORM_BGR 0x0080 /* read and write */
  160566. #define PNG_TRANSFORM_SWAP_ALPHA 0x0100 /* read and write */
  160567. #define PNG_TRANSFORM_SWAP_ENDIAN 0x0200 /* read and write */
  160568. #define PNG_TRANSFORM_INVERT_ALPHA 0x0400 /* read and write */
  160569. #define PNG_TRANSFORM_STRIP_FILLER 0x0800 /* WRITE only */
  160570. #define PNG_FLAG_MNG_EMPTY_PLTE 0x01
  160571. #define PNG_FLAG_MNG_FILTER_64 0x04
  160572. #define PNG_ALL_MNG_FEATURES 0x05
  160573. typedef png_voidp (*png_malloc_ptr) PNGARG((png_structp, png_size_t));
  160574. typedef void (*png_free_ptr) PNGARG((png_structp, png_voidp));
  160575. struct png_struct_def
  160576. {
  160577. #ifdef PNG_SETJMP_SUPPORTED
  160578. jmp_buf jmpbuf; /* used in png_error */
  160579. #endif
  160580. png_error_ptr error_fn; /* function for printing errors and aborting */
  160581. png_error_ptr warning_fn; /* function for printing warnings */
  160582. png_voidp error_ptr; /* user supplied struct for error functions */
  160583. png_rw_ptr write_data_fn; /* function for writing output data */
  160584. png_rw_ptr read_data_fn; /* function for reading input data */
  160585. png_voidp io_ptr; /* ptr to application struct for I/O functions */
  160586. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  160587. png_user_transform_ptr read_user_transform_fn; /* user read transform */
  160588. #endif
  160589. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  160590. png_user_transform_ptr write_user_transform_fn; /* user write transform */
  160591. #endif
  160592. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  160593. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  160594. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  160595. png_voidp user_transform_ptr; /* user supplied struct for user transform */
  160596. png_byte user_transform_depth; /* bit depth of user transformed pixels */
  160597. png_byte user_transform_channels; /* channels in user transformed pixels */
  160598. #endif
  160599. #endif
  160600. png_uint_32 mode; /* tells us where we are in the PNG file */
  160601. png_uint_32 flags; /* flags indicating various things to libpng */
  160602. png_uint_32 transformations; /* which transformations to perform */
  160603. z_stream zstream; /* pointer to decompression structure (below) */
  160604. png_bytep zbuf; /* buffer for zlib */
  160605. png_size_t zbuf_size; /* size of zbuf */
  160606. int zlib_level; /* holds zlib compression level */
  160607. int zlib_method; /* holds zlib compression method */
  160608. int zlib_window_bits; /* holds zlib compression window bits */
  160609. int zlib_mem_level; /* holds zlib compression memory level */
  160610. int zlib_strategy; /* holds zlib compression strategy */
  160611. png_uint_32 width; /* width of image in pixels */
  160612. png_uint_32 height; /* height of image in pixels */
  160613. png_uint_32 num_rows; /* number of rows in current pass */
  160614. png_uint_32 usr_width; /* width of row at start of write */
  160615. png_uint_32 rowbytes; /* size of row in bytes */
  160616. png_uint_32 irowbytes; /* size of current interlaced row in bytes */
  160617. png_uint_32 iwidth; /* width of current interlaced row in pixels */
  160618. png_uint_32 row_number; /* current row in interlace pass */
  160619. png_bytep prev_row; /* buffer to save previous (unfiltered) row */
  160620. png_bytep row_buf; /* buffer to save current (unfiltered) row */
  160621. png_bytep sub_row; /* buffer to save "sub" row when filtering */
  160622. png_bytep up_row; /* buffer to save "up" row when filtering */
  160623. png_bytep avg_row; /* buffer to save "avg" row when filtering */
  160624. png_bytep paeth_row; /* buffer to save "Paeth" row when filtering */
  160625. png_row_info row_info; /* used for transformation routines */
  160626. png_uint_32 idat_size; /* current IDAT size for read */
  160627. png_uint_32 crc; /* current chunk CRC value */
  160628. png_colorp palette; /* palette from the input file */
  160629. png_uint_16 num_palette; /* number of color entries in palette */
  160630. png_uint_16 num_trans; /* number of transparency values */
  160631. png_byte chunk_name[5]; /* null-terminated name of current chunk */
  160632. png_byte compression; /* file compression type (always 0) */
  160633. png_byte filter; /* file filter type (always 0) */
  160634. png_byte interlaced; /* PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
  160635. png_byte pass; /* current interlace pass (0 - 6) */
  160636. png_byte do_filter; /* row filter flags (see PNG_FILTER_ below ) */
  160637. png_byte color_type; /* color type of file */
  160638. png_byte bit_depth; /* bit depth of file */
  160639. png_byte usr_bit_depth; /* bit depth of users row */
  160640. png_byte pixel_depth; /* number of bits per pixel */
  160641. png_byte channels; /* number of channels in file */
  160642. png_byte usr_channels; /* channels at start of write */
  160643. png_byte sig_bytes; /* magic bytes read/written from start of file */
  160644. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  160645. #ifdef PNG_LEGACY_SUPPORTED
  160646. png_byte filler; /* filler byte for pixel expansion */
  160647. #else
  160648. png_uint_16 filler; /* filler bytes for pixel expansion */
  160649. #endif
  160650. #endif
  160651. #if defined(PNG_bKGD_SUPPORTED)
  160652. png_byte background_gamma_type;
  160653. # ifdef PNG_FLOATING_POINT_SUPPORTED
  160654. float background_gamma;
  160655. # endif
  160656. png_color_16 background; /* background color in screen gamma space */
  160657. #if defined(PNG_READ_GAMMA_SUPPORTED)
  160658. png_color_16 background_1; /* background normalized to gamma 1.0 */
  160659. #endif
  160660. #endif /* PNG_bKGD_SUPPORTED */
  160661. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  160662. png_flush_ptr output_flush_fn;/* Function for flushing output */
  160663. png_uint_32 flush_dist; /* how many rows apart to flush, 0 - no flush */
  160664. png_uint_32 flush_rows; /* number of rows written since last flush */
  160665. #endif
  160666. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160667. int gamma_shift; /* number of "insignificant" bits 16-bit gamma */
  160668. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160669. float gamma; /* file gamma value */
  160670. float screen_gamma; /* screen gamma value (display_exponent) */
  160671. #endif
  160672. #endif
  160673. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160674. png_bytep gamma_table; /* gamma table for 8-bit depth files */
  160675. png_bytep gamma_from_1; /* converts from 1.0 to screen */
  160676. png_bytep gamma_to_1; /* converts from file to 1.0 */
  160677. png_uint_16pp gamma_16_table; /* gamma table for 16-bit depth files */
  160678. png_uint_16pp gamma_16_from_1; /* converts from 1.0 to screen */
  160679. png_uint_16pp gamma_16_to_1; /* converts from file to 1.0 */
  160680. #endif
  160681. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_sBIT_SUPPORTED)
  160682. png_color_8 sig_bit; /* significant bits in each available channel */
  160683. #endif
  160684. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  160685. png_color_8 shift; /* shift for significant bit tranformation */
  160686. #endif
  160687. #if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) \
  160688. || defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160689. png_bytep trans; /* transparency values for paletted files */
  160690. png_color_16 trans_values; /* transparency values for non-paletted files */
  160691. #endif
  160692. png_read_status_ptr read_row_fn; /* called after each row is decoded */
  160693. png_write_status_ptr write_row_fn; /* called after each row is encoded */
  160694. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  160695. png_progressive_info_ptr info_fn; /* called after header data fully read */
  160696. png_progressive_row_ptr row_fn; /* called after each prog. row is decoded */
  160697. png_progressive_end_ptr end_fn; /* called after image is complete */
  160698. png_bytep save_buffer_ptr; /* current location in save_buffer */
  160699. png_bytep save_buffer; /* buffer for previously read data */
  160700. png_bytep current_buffer_ptr; /* current location in current_buffer */
  160701. png_bytep current_buffer; /* buffer for recently used data */
  160702. png_uint_32 push_length; /* size of current input chunk */
  160703. png_uint_32 skip_length; /* bytes to skip in input data */
  160704. png_size_t save_buffer_size; /* amount of data now in save_buffer */
  160705. png_size_t save_buffer_max; /* total size of save_buffer */
  160706. png_size_t buffer_size; /* total amount of available input data */
  160707. png_size_t current_buffer_size; /* amount of data now in current_buffer */
  160708. int process_mode; /* what push library is currently doing */
  160709. int cur_palette; /* current push library palette index */
  160710. # if defined(PNG_TEXT_SUPPORTED)
  160711. png_size_t current_text_size; /* current size of text input data */
  160712. png_size_t current_text_left; /* how much text left to read in input */
  160713. png_charp current_text; /* current text chunk buffer */
  160714. png_charp current_text_ptr; /* current location in current_text */
  160715. # endif /* PNG_TEXT_SUPPORTED */
  160716. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  160717. #if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
  160718. png_bytepp offset_table_ptr;
  160719. png_bytep offset_table;
  160720. png_uint_16 offset_table_number;
  160721. png_uint_16 offset_table_count;
  160722. png_uint_16 offset_table_count_free;
  160723. #endif
  160724. #if defined(PNG_READ_DITHER_SUPPORTED)
  160725. png_bytep palette_lookup; /* lookup table for dithering */
  160726. png_bytep dither_index; /* index translation for palette files */
  160727. #endif
  160728. #if defined(PNG_READ_DITHER_SUPPORTED) || defined(PNG_hIST_SUPPORTED)
  160729. png_uint_16p hist; /* histogram */
  160730. #endif
  160731. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  160732. png_byte heuristic_method; /* heuristic for row filter selection */
  160733. png_byte num_prev_filters; /* number of weights for previous rows */
  160734. png_bytep prev_filters; /* filter type(s) of previous row(s) */
  160735. png_uint_16p filter_weights; /* weight(s) for previous line(s) */
  160736. png_uint_16p inv_filter_weights; /* 1/weight(s) for previous line(s) */
  160737. png_uint_16p filter_costs; /* relative filter calculation cost */
  160738. png_uint_16p inv_filter_costs; /* 1/relative filter calculation cost */
  160739. #endif
  160740. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  160741. png_charp time_buffer; /* String to hold RFC 1123 time text */
  160742. #endif
  160743. #ifdef PNG_FREE_ME_SUPPORTED
  160744. png_uint_32 free_me; /* flags items libpng is responsible for freeing */
  160745. #endif
  160746. #if defined(PNG_USER_CHUNKS_SUPPORTED)
  160747. png_voidp user_chunk_ptr;
  160748. png_user_chunk_ptr read_user_chunk_fn; /* user read chunk handler */
  160749. #endif
  160750. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160751. int num_chunk_list;
  160752. png_bytep chunk_list;
  160753. #endif
  160754. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  160755. png_byte rgb_to_gray_status;
  160756. png_uint_16 rgb_to_gray_red_coeff;
  160757. png_uint_16 rgb_to_gray_green_coeff;
  160758. png_uint_16 rgb_to_gray_blue_coeff;
  160759. #endif
  160760. #if defined(PNG_MNG_FEATURES_SUPPORTED) || \
  160761. defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
  160762. defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
  160763. #ifdef PNG_1_0_X
  160764. png_byte mng_features_permitted;
  160765. #else
  160766. png_uint_32 mng_features_permitted;
  160767. #endif /* PNG_1_0_X */
  160768. #endif
  160769. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160770. png_fixed_point int_gamma;
  160771. #endif
  160772. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  160773. png_byte filter_type;
  160774. #endif
  160775. #if defined(PNG_1_0_X)
  160776. png_uint_32 row_buf_size;
  160777. #endif
  160778. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  160779. # if !defined(PNG_1_0_X)
  160780. # if defined(PNG_MMX_CODE_SUPPORTED)
  160781. png_byte mmx_bitdepth_threshold;
  160782. png_uint_32 mmx_rowbytes_threshold;
  160783. # endif
  160784. png_uint_32 asm_flags;
  160785. # endif
  160786. #endif
  160787. #ifdef PNG_USER_MEM_SUPPORTED
  160788. png_voidp mem_ptr; /* user supplied struct for mem functions */
  160789. png_malloc_ptr malloc_fn; /* function for allocating memory */
  160790. png_free_ptr free_fn; /* function for freeing memory */
  160791. #endif
  160792. png_bytep big_row_buf; /* buffer to save current (unfiltered) row */
  160793. #if defined(PNG_READ_DITHER_SUPPORTED)
  160794. png_bytep dither_sort; /* working sort array */
  160795. png_bytep index_to_palette; /* where the original index currently is */
  160796. png_bytep palette_to_index; /* which original index points to this */
  160797. #endif
  160798. png_byte compression_type;
  160799. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  160800. png_uint_32 user_width_max;
  160801. png_uint_32 user_height_max;
  160802. #endif
  160803. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160804. png_unknown_chunk unknown_chunk;
  160805. #endif
  160806. };
  160807. typedef png_structp version_1_2_21;
  160808. typedef png_struct FAR * FAR * png_structpp;
  160809. extern PNG_EXPORT(png_uint_32,png_access_version_number) PNGARG((void));
  160810. extern PNG_EXPORT(void,png_set_sig_bytes) PNGARG((png_structp png_ptr,
  160811. int num_bytes));
  160812. extern PNG_EXPORT(int,png_sig_cmp) PNGARG((png_bytep sig, png_size_t start,
  160813. png_size_t num_to_check));
  160814. extern PNG_EXPORT(int,png_check_sig) PNGARG((png_bytep sig, int num));
  160815. extern PNG_EXPORT(png_structp,png_create_read_struct)
  160816. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  160817. png_error_ptr error_fn, png_error_ptr warn_fn));
  160818. extern PNG_EXPORT(png_structp,png_create_write_struct)
  160819. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  160820. png_error_ptr error_fn, png_error_ptr warn_fn));
  160821. #ifdef PNG_WRITE_SUPPORTED
  160822. extern PNG_EXPORT(png_uint_32,png_get_compression_buffer_size)
  160823. PNGARG((png_structp png_ptr));
  160824. #endif
  160825. #ifdef PNG_WRITE_SUPPORTED
  160826. extern PNG_EXPORT(void,png_set_compression_buffer_size)
  160827. PNGARG((png_structp png_ptr, png_uint_32 size));
  160828. #endif
  160829. extern PNG_EXPORT(int,png_reset_zstream) PNGARG((png_structp png_ptr));
  160830. #ifdef PNG_USER_MEM_SUPPORTED
  160831. extern PNG_EXPORT(png_structp,png_create_read_struct_2)
  160832. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  160833. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  160834. png_malloc_ptr malloc_fn, png_free_ptr free_fn));
  160835. extern PNG_EXPORT(png_structp,png_create_write_struct_2)
  160836. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  160837. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  160838. png_malloc_ptr malloc_fn, png_free_ptr free_fn));
  160839. #endif
  160840. extern PNG_EXPORT(void,png_write_chunk) PNGARG((png_structp png_ptr,
  160841. png_bytep chunk_name, png_bytep data, png_size_t length));
  160842. extern PNG_EXPORT(void,png_write_chunk_start) PNGARG((png_structp png_ptr,
  160843. png_bytep chunk_name, png_uint_32 length));
  160844. extern PNG_EXPORT(void,png_write_chunk_data) PNGARG((png_structp png_ptr,
  160845. png_bytep data, png_size_t length));
  160846. extern PNG_EXPORT(void,png_write_chunk_end) PNGARG((png_structp png_ptr));
  160847. extern PNG_EXPORT(png_infop,png_create_info_struct)
  160848. PNGARG((png_structp png_ptr));
  160849. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  160850. extern PNG_EXPORT(void,png_info_init) PNGARG((png_infop info_ptr));
  160851. #undef png_info_init
  160852. #define png_info_init(info_ptr) png_info_init_3(&info_ptr,\
  160853. png_sizeof(png_info));
  160854. #endif
  160855. extern PNG_EXPORT(void,png_info_init_3) PNGARG((png_infopp info_ptr,
  160856. png_size_t png_info_struct_size));
  160857. extern PNG_EXPORT(void,png_write_info_before_PLTE) PNGARG((png_structp png_ptr,
  160858. png_infop info_ptr));
  160859. extern PNG_EXPORT(void,png_write_info) PNGARG((png_structp png_ptr,
  160860. png_infop info_ptr));
  160861. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  160862. extern PNG_EXPORT(void,png_read_info) PNGARG((png_structp png_ptr,
  160863. png_infop info_ptr));
  160864. #endif
  160865. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  160866. extern PNG_EXPORT(png_charp,png_convert_to_rfc1123)
  160867. PNGARG((png_structp png_ptr, png_timep ptime));
  160868. #endif
  160869. #if !defined(_WIN32_WCE)
  160870. #if defined(PNG_WRITE_tIME_SUPPORTED)
  160871. extern PNG_EXPORT(void,png_convert_from_struct_tm) PNGARG((png_timep ptime,
  160872. struct tm FAR * ttime));
  160873. extern PNG_EXPORT(void,png_convert_from_time_t) PNGARG((png_timep ptime,
  160874. time_t ttime));
  160875. #endif /* PNG_WRITE_tIME_SUPPORTED */
  160876. #endif /* _WIN32_WCE */
  160877. #if defined(PNG_READ_EXPAND_SUPPORTED)
  160878. extern PNG_EXPORT(void,png_set_expand) PNGARG((png_structp png_ptr));
  160879. #if !defined(PNG_1_0_X)
  160880. extern PNG_EXPORT(void,png_set_expand_gray_1_2_4_to_8) PNGARG((png_structp
  160881. png_ptr));
  160882. #endif
  160883. extern PNG_EXPORT(void,png_set_palette_to_rgb) PNGARG((png_structp png_ptr));
  160884. extern PNG_EXPORT(void,png_set_tRNS_to_alpha) PNGARG((png_structp png_ptr));
  160885. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  160886. extern PNG_EXPORT(void,png_set_gray_1_2_4_to_8) PNGARG((png_structp png_ptr));
  160887. #endif
  160888. #endif
  160889. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  160890. extern PNG_EXPORT(void,png_set_bgr) PNGARG((png_structp png_ptr));
  160891. #endif
  160892. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  160893. extern PNG_EXPORT(void,png_set_gray_to_rgb) PNGARG((png_structp png_ptr));
  160894. #endif
  160895. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  160896. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160897. extern PNG_EXPORT(void,png_set_rgb_to_gray) PNGARG((png_structp png_ptr,
  160898. int error_action, double red, double green ));
  160899. #endif
  160900. extern PNG_EXPORT(void,png_set_rgb_to_gray_fixed) PNGARG((png_structp png_ptr,
  160901. int error_action, png_fixed_point red, png_fixed_point green ));
  160902. extern PNG_EXPORT(png_byte,png_get_rgb_to_gray_status) PNGARG((png_structp
  160903. png_ptr));
  160904. #endif
  160905. extern PNG_EXPORT(void,png_build_grayscale_palette) PNGARG((int bit_depth,
  160906. png_colorp palette));
  160907. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  160908. extern PNG_EXPORT(void,png_set_strip_alpha) PNGARG((png_structp png_ptr));
  160909. #endif
  160910. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \
  160911. defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  160912. extern PNG_EXPORT(void,png_set_swap_alpha) PNGARG((png_structp png_ptr));
  160913. #endif
  160914. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \
  160915. defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  160916. extern PNG_EXPORT(void,png_set_invert_alpha) PNGARG((png_structp png_ptr));
  160917. #endif
  160918. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  160919. extern PNG_EXPORT(void,png_set_filler) PNGARG((png_structp png_ptr,
  160920. png_uint_32 filler, int flags));
  160921. #define PNG_FILLER_BEFORE 0
  160922. #define PNG_FILLER_AFTER 1
  160923. #if !defined(PNG_1_0_X)
  160924. extern PNG_EXPORT(void,png_set_add_alpha) PNGARG((png_structp png_ptr,
  160925. png_uint_32 filler, int flags));
  160926. #endif
  160927. #endif /* PNG_READ_FILLER_SUPPORTED || PNG_WRITE_FILLER_SUPPORTED */
  160928. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  160929. extern PNG_EXPORT(void,png_set_swap) PNGARG((png_structp png_ptr));
  160930. #endif
  160931. #if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
  160932. extern PNG_EXPORT(void,png_set_packing) PNGARG((png_structp png_ptr));
  160933. #endif
  160934. #if defined(PNG_READ_PACKSWAP_SUPPORTED) || defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  160935. extern PNG_EXPORT(void,png_set_packswap) PNGARG((png_structp png_ptr));
  160936. #endif
  160937. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  160938. extern PNG_EXPORT(void,png_set_shift) PNGARG((png_structp png_ptr,
  160939. png_color_8p true_bits));
  160940. #endif
  160941. #if defined(PNG_READ_INTERLACING_SUPPORTED) || \
  160942. defined(PNG_WRITE_INTERLACING_SUPPORTED)
  160943. extern PNG_EXPORT(int,png_set_interlace_handling) PNGARG((png_structp png_ptr));
  160944. #endif
  160945. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  160946. extern PNG_EXPORT(void,png_set_invert_mono) PNGARG((png_structp png_ptr));
  160947. #endif
  160948. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  160949. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160950. extern PNG_EXPORT(void,png_set_background) PNGARG((png_structp png_ptr,
  160951. png_color_16p background_color, int background_gamma_code,
  160952. int need_expand, double background_gamma));
  160953. #endif
  160954. #define PNG_BACKGROUND_GAMMA_UNKNOWN 0
  160955. #define PNG_BACKGROUND_GAMMA_SCREEN 1
  160956. #define PNG_BACKGROUND_GAMMA_FILE 2
  160957. #define PNG_BACKGROUND_GAMMA_UNIQUE 3
  160958. #endif
  160959. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  160960. extern PNG_EXPORT(void,png_set_strip_16) PNGARG((png_structp png_ptr));
  160961. #endif
  160962. #if defined(PNG_READ_DITHER_SUPPORTED)
  160963. extern PNG_EXPORT(void,png_set_dither) PNGARG((png_structp png_ptr,
  160964. png_colorp palette, int num_palette, int maximum_colors,
  160965. png_uint_16p histogram, int full_dither));
  160966. #endif
  160967. #if defined(PNG_READ_GAMMA_SUPPORTED)
  160968. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160969. extern PNG_EXPORT(void,png_set_gamma) PNGARG((png_structp png_ptr,
  160970. double screen_gamma, double default_file_gamma));
  160971. #endif
  160972. #endif
  160973. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  160974. #if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
  160975. defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
  160976. extern PNG_EXPORT(void,png_permit_empty_plte) PNGARG((png_structp png_ptr,
  160977. int empty_plte_permitted));
  160978. #endif
  160979. #endif
  160980. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  160981. extern PNG_EXPORT(void,png_set_flush) PNGARG((png_structp png_ptr, int nrows));
  160982. extern PNG_EXPORT(void,png_write_flush) PNGARG((png_structp png_ptr));
  160983. #endif
  160984. extern PNG_EXPORT(void,png_start_read_image) PNGARG((png_structp png_ptr));
  160985. extern PNG_EXPORT(void,png_read_update_info) PNGARG((png_structp png_ptr,
  160986. png_infop info_ptr));
  160987. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  160988. extern PNG_EXPORT(void,png_read_rows) PNGARG((png_structp png_ptr,
  160989. png_bytepp row, png_bytepp display_row, png_uint_32 num_rows));
  160990. #endif
  160991. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  160992. extern PNG_EXPORT(void,png_read_row) PNGARG((png_structp png_ptr,
  160993. png_bytep row,
  160994. png_bytep display_row));
  160995. #endif
  160996. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  160997. extern PNG_EXPORT(void,png_read_image) PNGARG((png_structp png_ptr,
  160998. png_bytepp image));
  160999. #endif
  161000. extern PNG_EXPORT(void,png_write_row) PNGARG((png_structp png_ptr,
  161001. png_bytep row));
  161002. extern PNG_EXPORT(void,png_write_rows) PNGARG((png_structp png_ptr,
  161003. png_bytepp row, png_uint_32 num_rows));
  161004. extern PNG_EXPORT(void,png_write_image) PNGARG((png_structp png_ptr,
  161005. png_bytepp image));
  161006. extern PNG_EXPORT(void,png_write_end) PNGARG((png_structp png_ptr,
  161007. png_infop info_ptr));
  161008. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  161009. extern PNG_EXPORT(void,png_read_end) PNGARG((png_structp png_ptr,
  161010. png_infop info_ptr));
  161011. #endif
  161012. extern PNG_EXPORT(void,png_destroy_info_struct) PNGARG((png_structp png_ptr,
  161013. png_infopp info_ptr_ptr));
  161014. extern PNG_EXPORT(void,png_destroy_read_struct) PNGARG((png_structpp
  161015. png_ptr_ptr, png_infopp info_ptr_ptr, png_infopp end_info_ptr_ptr));
  161016. extern void png_read_destroy PNGARG((png_structp png_ptr, png_infop info_ptr,
  161017. png_infop end_info_ptr));
  161018. extern PNG_EXPORT(void,png_destroy_write_struct)
  161019. PNGARG((png_structpp png_ptr_ptr, png_infopp info_ptr_ptr));
  161020. extern void png_write_destroy PNGARG((png_structp png_ptr));
  161021. extern PNG_EXPORT(void,png_set_crc_action) PNGARG((png_structp png_ptr,
  161022. int crit_action, int ancil_action));
  161023. #define PNG_CRC_DEFAULT 0 /* error/quit warn/discard data */
  161024. #define PNG_CRC_ERROR_QUIT 1 /* error/quit error/quit */
  161025. #define PNG_CRC_WARN_DISCARD 2 /* (INVALID) warn/discard data */
  161026. #define PNG_CRC_WARN_USE 3 /* warn/use data warn/use data */
  161027. #define PNG_CRC_QUIET_USE 4 /* quiet/use data quiet/use data */
  161028. #define PNG_CRC_NO_CHANGE 5 /* use current value use current value */
  161029. extern PNG_EXPORT(void,png_set_filter) PNGARG((png_structp png_ptr, int method,
  161030. int filters));
  161031. #define PNG_NO_FILTERS 0x00
  161032. #define PNG_FILTER_NONE 0x08
  161033. #define PNG_FILTER_SUB 0x10
  161034. #define PNG_FILTER_UP 0x20
  161035. #define PNG_FILTER_AVG 0x40
  161036. #define PNG_FILTER_PAETH 0x80
  161037. #define PNG_ALL_FILTERS (PNG_FILTER_NONE | PNG_FILTER_SUB | PNG_FILTER_UP | \
  161038. PNG_FILTER_AVG | PNG_FILTER_PAETH)
  161039. #define PNG_FILTER_VALUE_NONE 0
  161040. #define PNG_FILTER_VALUE_SUB 1
  161041. #define PNG_FILTER_VALUE_UP 2
  161042. #define PNG_FILTER_VALUE_AVG 3
  161043. #define PNG_FILTER_VALUE_PAETH 4
  161044. #define PNG_FILTER_VALUE_LAST 5
  161045. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) /* EXPERIMENTAL */
  161046. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161047. extern PNG_EXPORT(void,png_set_filter_heuristics) PNGARG((png_structp png_ptr,
  161048. int heuristic_method, int num_weights, png_doublep filter_weights,
  161049. png_doublep filter_costs));
  161050. #endif
  161051. #endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
  161052. #define PNG_FILTER_HEURISTIC_DEFAULT 0 /* Currently "UNWEIGHTED" */
  161053. #define PNG_FILTER_HEURISTIC_UNWEIGHTED 1 /* Used by libpng < 0.95 */
  161054. #define PNG_FILTER_HEURISTIC_WEIGHTED 2 /* Experimental feature */
  161055. #define PNG_FILTER_HEURISTIC_LAST 3 /* Not a valid value */
  161056. extern PNG_EXPORT(void,png_set_compression_level) PNGARG((png_structp png_ptr,
  161057. int level));
  161058. extern PNG_EXPORT(void,png_set_compression_mem_level)
  161059. PNGARG((png_structp png_ptr, int mem_level));
  161060. extern PNG_EXPORT(void,png_set_compression_strategy)
  161061. PNGARG((png_structp png_ptr, int strategy));
  161062. extern PNG_EXPORT(void,png_set_compression_window_bits)
  161063. PNGARG((png_structp png_ptr, int window_bits));
  161064. extern PNG_EXPORT(void,png_set_compression_method) PNGARG((png_structp png_ptr,
  161065. int method));
  161066. #if !defined(PNG_NO_STDIO)
  161067. extern PNG_EXPORT(void,png_init_io) PNGARG((png_structp png_ptr, png_FILE_p fp));
  161068. #endif
  161069. extern PNG_EXPORT(void,png_set_error_fn) PNGARG((png_structp png_ptr,
  161070. png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warning_fn));
  161071. extern PNG_EXPORT(png_voidp,png_get_error_ptr) PNGARG((png_structp png_ptr));
  161072. extern PNG_EXPORT(void,png_set_write_fn) PNGARG((png_structp png_ptr,
  161073. png_voidp io_ptr, png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn));
  161074. extern PNG_EXPORT(void,png_set_read_fn) PNGARG((png_structp png_ptr,
  161075. png_voidp io_ptr, png_rw_ptr read_data_fn));
  161076. extern PNG_EXPORT(png_voidp,png_get_io_ptr) PNGARG((png_structp png_ptr));
  161077. extern PNG_EXPORT(void,png_set_read_status_fn) PNGARG((png_structp png_ptr,
  161078. png_read_status_ptr read_row_fn));
  161079. extern PNG_EXPORT(void,png_set_write_status_fn) PNGARG((png_structp png_ptr,
  161080. png_write_status_ptr write_row_fn));
  161081. #ifdef PNG_USER_MEM_SUPPORTED
  161082. extern PNG_EXPORT(void,png_set_mem_fn) PNGARG((png_structp png_ptr,
  161083. png_voidp mem_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn));
  161084. extern PNG_EXPORT(png_voidp,png_get_mem_ptr) PNGARG((png_structp png_ptr));
  161085. #endif
  161086. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  161087. defined(PNG_LEGACY_SUPPORTED)
  161088. extern PNG_EXPORT(void,png_set_read_user_transform_fn) PNGARG((png_structp
  161089. png_ptr, png_user_transform_ptr read_user_transform_fn));
  161090. #endif
  161091. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  161092. defined(PNG_LEGACY_SUPPORTED)
  161093. extern PNG_EXPORT(void,png_set_write_user_transform_fn) PNGARG((png_structp
  161094. png_ptr, png_user_transform_ptr write_user_transform_fn));
  161095. #endif
  161096. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  161097. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  161098. defined(PNG_LEGACY_SUPPORTED)
  161099. extern PNG_EXPORT(void,png_set_user_transform_info) PNGARG((png_structp
  161100. png_ptr, png_voidp user_transform_ptr, int user_transform_depth,
  161101. int user_transform_channels));
  161102. extern PNG_EXPORT(png_voidp,png_get_user_transform_ptr)
  161103. PNGARG((png_structp png_ptr));
  161104. #endif
  161105. #ifdef PNG_USER_CHUNKS_SUPPORTED
  161106. extern PNG_EXPORT(void,png_set_read_user_chunk_fn) PNGARG((png_structp png_ptr,
  161107. png_voidp user_chunk_ptr, png_user_chunk_ptr read_user_chunk_fn));
  161108. extern PNG_EXPORT(png_voidp,png_get_user_chunk_ptr) PNGARG((png_structp
  161109. png_ptr));
  161110. #endif
  161111. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  161112. extern PNG_EXPORT(void,png_set_progressive_read_fn) PNGARG((png_structp png_ptr,
  161113. png_voidp progressive_ptr,
  161114. png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn,
  161115. png_progressive_end_ptr end_fn));
  161116. extern PNG_EXPORT(png_voidp,png_get_progressive_ptr)
  161117. PNGARG((png_structp png_ptr));
  161118. extern PNG_EXPORT(void,png_process_data) PNGARG((png_structp png_ptr,
  161119. png_infop info_ptr, png_bytep buffer, png_size_t buffer_size));
  161120. extern PNG_EXPORT(void,png_progressive_combine_row) PNGARG((png_structp png_ptr,
  161121. png_bytep old_row, png_bytep new_row));
  161122. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  161123. extern PNG_EXPORT(png_voidp,png_malloc) PNGARG((png_structp png_ptr,
  161124. png_uint_32 size));
  161125. #if defined(PNG_1_0_X)
  161126. # define png_malloc_warn png_malloc
  161127. #else
  161128. extern PNG_EXPORT(png_voidp,png_malloc_warn) PNGARG((png_structp png_ptr,
  161129. png_uint_32 size));
  161130. #endif
  161131. extern PNG_EXPORT(void,png_free) PNGARG((png_structp png_ptr, png_voidp ptr));
  161132. #if defined(PNG_1_0_X)
  161133. extern PNG_EXPORT(voidpf,png_zalloc) PNGARG((voidpf png_ptr, uInt items,
  161134. uInt size));
  161135. extern PNG_EXPORT(void,png_zfree) PNGARG((voidpf png_ptr, voidpf ptr));
  161136. #endif
  161137. extern PNG_EXPORT(void,png_free_data) PNGARG((png_structp png_ptr,
  161138. png_infop info_ptr, png_uint_32 free_me, int num));
  161139. #ifdef PNG_FREE_ME_SUPPORTED
  161140. extern PNG_EXPORT(void,png_data_freer) PNGARG((png_structp png_ptr,
  161141. png_infop info_ptr, int freer, png_uint_32 mask));
  161142. #endif
  161143. #define PNG_DESTROY_WILL_FREE_DATA 1
  161144. #define PNG_SET_WILL_FREE_DATA 1
  161145. #define PNG_USER_WILL_FREE_DATA 2
  161146. #define PNG_FREE_HIST 0x0008
  161147. #define PNG_FREE_ICCP 0x0010
  161148. #define PNG_FREE_SPLT 0x0020
  161149. #define PNG_FREE_ROWS 0x0040
  161150. #define PNG_FREE_PCAL 0x0080
  161151. #define PNG_FREE_SCAL 0x0100
  161152. #define PNG_FREE_UNKN 0x0200
  161153. #define PNG_FREE_LIST 0x0400
  161154. #define PNG_FREE_PLTE 0x1000
  161155. #define PNG_FREE_TRNS 0x2000
  161156. #define PNG_FREE_TEXT 0x4000
  161157. #define PNG_FREE_ALL 0x7fff
  161158. #define PNG_FREE_MUL 0x4220 /* PNG_FREE_SPLT|PNG_FREE_TEXT|PNG_FREE_UNKN */
  161159. #ifdef PNG_USER_MEM_SUPPORTED
  161160. extern PNG_EXPORT(png_voidp,png_malloc_default) PNGARG((png_structp png_ptr,
  161161. png_uint_32 size));
  161162. extern PNG_EXPORT(void,png_free_default) PNGARG((png_structp png_ptr,
  161163. png_voidp ptr));
  161164. #endif
  161165. extern PNG_EXPORT(png_voidp,png_memcpy_check) PNGARG((png_structp png_ptr,
  161166. png_voidp s1, png_voidp s2, png_uint_32 size));
  161167. extern PNG_EXPORT(png_voidp,png_memset_check) PNGARG((png_structp png_ptr,
  161168. png_voidp s1, int value, png_uint_32 size));
  161169. #if defined(USE_FAR_KEYWORD) /* memory model conversion function */
  161170. extern void *png_far_to_near PNGARG((png_structp png_ptr,png_voidp ptr,
  161171. int check));
  161172. #endif /* USE_FAR_KEYWORD */
  161173. #ifndef PNG_NO_ERROR_TEXT
  161174. extern PNG_EXPORT(void,png_error) PNGARG((png_structp png_ptr,
  161175. png_const_charp error_message));
  161176. extern PNG_EXPORT(void,png_chunk_error) PNGARG((png_structp png_ptr,
  161177. png_const_charp error_message));
  161178. #else
  161179. extern PNG_EXPORT(void,png_err) PNGARG((png_structp png_ptr));
  161180. #endif
  161181. #ifndef PNG_NO_WARNINGS
  161182. extern PNG_EXPORT(void,png_warning) PNGARG((png_structp png_ptr,
  161183. png_const_charp warning_message));
  161184. #ifdef PNG_READ_SUPPORTED
  161185. extern PNG_EXPORT(void,png_chunk_warning) PNGARG((png_structp png_ptr,
  161186. png_const_charp warning_message));
  161187. #endif /* PNG_READ_SUPPORTED */
  161188. #endif /* PNG_NO_WARNINGS */
  161189. extern PNG_EXPORT(png_uint_32,png_get_valid) PNGARG((png_structp png_ptr,
  161190. png_infop info_ptr, png_uint_32 flag));
  161191. extern PNG_EXPORT(png_uint_32,png_get_rowbytes) PNGARG((png_structp png_ptr,
  161192. png_infop info_ptr));
  161193. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  161194. extern PNG_EXPORT(png_bytepp,png_get_rows) PNGARG((png_structp png_ptr,
  161195. png_infop info_ptr));
  161196. extern PNG_EXPORT(void,png_set_rows) PNGARG((png_structp png_ptr,
  161197. png_infop info_ptr, png_bytepp row_pointers));
  161198. #endif
  161199. extern PNG_EXPORT(png_byte,png_get_channels) PNGARG((png_structp png_ptr,
  161200. png_infop info_ptr));
  161201. #ifdef PNG_EASY_ACCESS_SUPPORTED
  161202. extern PNG_EXPORT(png_uint_32, png_get_image_width) PNGARG((png_structp
  161203. png_ptr, png_infop info_ptr));
  161204. extern PNG_EXPORT(png_uint_32, png_get_image_height) PNGARG((png_structp
  161205. png_ptr, png_infop info_ptr));
  161206. extern PNG_EXPORT(png_byte, png_get_bit_depth) PNGARG((png_structp
  161207. png_ptr, png_infop info_ptr));
  161208. extern PNG_EXPORT(png_byte, png_get_color_type) PNGARG((png_structp
  161209. png_ptr, png_infop info_ptr));
  161210. extern PNG_EXPORT(png_byte, png_get_filter_type) PNGARG((png_structp
  161211. png_ptr, png_infop info_ptr));
  161212. extern PNG_EXPORT(png_byte, png_get_interlace_type) PNGARG((png_structp
  161213. png_ptr, png_infop info_ptr));
  161214. extern PNG_EXPORT(png_byte, png_get_compression_type) PNGARG((png_structp
  161215. png_ptr, png_infop info_ptr));
  161216. extern PNG_EXPORT(png_uint_32, png_get_pixels_per_meter) PNGARG((png_structp
  161217. png_ptr, png_infop info_ptr));
  161218. extern PNG_EXPORT(png_uint_32, png_get_x_pixels_per_meter) PNGARG((png_structp
  161219. png_ptr, png_infop info_ptr));
  161220. extern PNG_EXPORT(png_uint_32, png_get_y_pixels_per_meter) PNGARG((png_structp
  161221. png_ptr, png_infop info_ptr));
  161222. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161223. extern PNG_EXPORT(float, png_get_pixel_aspect_ratio) PNGARG((png_structp
  161224. png_ptr, png_infop info_ptr));
  161225. #endif
  161226. extern PNG_EXPORT(png_int_32, png_get_x_offset_pixels) PNGARG((png_structp
  161227. png_ptr, png_infop info_ptr));
  161228. extern PNG_EXPORT(png_int_32, png_get_y_offset_pixels) PNGARG((png_structp
  161229. png_ptr, png_infop info_ptr));
  161230. extern PNG_EXPORT(png_int_32, png_get_x_offset_microns) PNGARG((png_structp
  161231. png_ptr, png_infop info_ptr));
  161232. extern PNG_EXPORT(png_int_32, png_get_y_offset_microns) PNGARG((png_structp
  161233. png_ptr, png_infop info_ptr));
  161234. #endif /* PNG_EASY_ACCESS_SUPPORTED */
  161235. extern PNG_EXPORT(png_bytep,png_get_signature) PNGARG((png_structp png_ptr,
  161236. png_infop info_ptr));
  161237. #if defined(PNG_bKGD_SUPPORTED)
  161238. extern PNG_EXPORT(png_uint_32,png_get_bKGD) PNGARG((png_structp png_ptr,
  161239. png_infop info_ptr, png_color_16p *background));
  161240. #endif
  161241. #if defined(PNG_bKGD_SUPPORTED)
  161242. extern PNG_EXPORT(void,png_set_bKGD) PNGARG((png_structp png_ptr,
  161243. png_infop info_ptr, png_color_16p background));
  161244. #endif
  161245. #if defined(PNG_cHRM_SUPPORTED)
  161246. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161247. extern PNG_EXPORT(png_uint_32,png_get_cHRM) PNGARG((png_structp png_ptr,
  161248. png_infop info_ptr, double *white_x, double *white_y, double *red_x,
  161249. double *red_y, double *green_x, double *green_y, double *blue_x,
  161250. double *blue_y));
  161251. #endif
  161252. #ifdef PNG_FIXED_POINT_SUPPORTED
  161253. extern PNG_EXPORT(png_uint_32,png_get_cHRM_fixed) PNGARG((png_structp png_ptr,
  161254. png_infop info_ptr, png_fixed_point *int_white_x, png_fixed_point
  161255. *int_white_y, png_fixed_point *int_red_x, png_fixed_point *int_red_y,
  161256. png_fixed_point *int_green_x, png_fixed_point *int_green_y, png_fixed_point
  161257. *int_blue_x, png_fixed_point *int_blue_y));
  161258. #endif
  161259. #endif
  161260. #if defined(PNG_cHRM_SUPPORTED)
  161261. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161262. extern PNG_EXPORT(void,png_set_cHRM) PNGARG((png_structp png_ptr,
  161263. png_infop info_ptr, double white_x, double white_y, double red_x,
  161264. double red_y, double green_x, double green_y, double blue_x, double blue_y));
  161265. #endif
  161266. #ifdef PNG_FIXED_POINT_SUPPORTED
  161267. extern PNG_EXPORT(void,png_set_cHRM_fixed) PNGARG((png_structp png_ptr,
  161268. png_infop info_ptr, png_fixed_point int_white_x, png_fixed_point int_white_y,
  161269. png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point
  161270. int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x,
  161271. png_fixed_point int_blue_y));
  161272. #endif
  161273. #endif
  161274. #if defined(PNG_gAMA_SUPPORTED)
  161275. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161276. extern PNG_EXPORT(png_uint_32,png_get_gAMA) PNGARG((png_structp png_ptr,
  161277. png_infop info_ptr, double *file_gamma));
  161278. #endif
  161279. extern PNG_EXPORT(png_uint_32,png_get_gAMA_fixed) PNGARG((png_structp png_ptr,
  161280. png_infop info_ptr, png_fixed_point *int_file_gamma));
  161281. #endif
  161282. #if defined(PNG_gAMA_SUPPORTED)
  161283. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161284. extern PNG_EXPORT(void,png_set_gAMA) PNGARG((png_structp png_ptr,
  161285. png_infop info_ptr, double file_gamma));
  161286. #endif
  161287. extern PNG_EXPORT(void,png_set_gAMA_fixed) PNGARG((png_structp png_ptr,
  161288. png_infop info_ptr, png_fixed_point int_file_gamma));
  161289. #endif
  161290. #if defined(PNG_hIST_SUPPORTED)
  161291. extern PNG_EXPORT(png_uint_32,png_get_hIST) PNGARG((png_structp png_ptr,
  161292. png_infop info_ptr, png_uint_16p *hist));
  161293. #endif
  161294. #if defined(PNG_hIST_SUPPORTED)
  161295. extern PNG_EXPORT(void,png_set_hIST) PNGARG((png_structp png_ptr,
  161296. png_infop info_ptr, png_uint_16p hist));
  161297. #endif
  161298. extern PNG_EXPORT(png_uint_32,png_get_IHDR) PNGARG((png_structp png_ptr,
  161299. png_infop info_ptr, png_uint_32 *width, png_uint_32 *height,
  161300. int *bit_depth, int *color_type, int *interlace_method,
  161301. int *compression_method, int *filter_method));
  161302. extern PNG_EXPORT(void,png_set_IHDR) PNGARG((png_structp png_ptr,
  161303. png_infop info_ptr, png_uint_32 width, png_uint_32 height, int bit_depth,
  161304. int color_type, int interlace_method, int compression_method,
  161305. int filter_method));
  161306. #if defined(PNG_oFFs_SUPPORTED)
  161307. extern PNG_EXPORT(png_uint_32,png_get_oFFs) PNGARG((png_structp png_ptr,
  161308. png_infop info_ptr, png_int_32 *offset_x, png_int_32 *offset_y,
  161309. int *unit_type));
  161310. #endif
  161311. #if defined(PNG_oFFs_SUPPORTED)
  161312. extern PNG_EXPORT(void,png_set_oFFs) PNGARG((png_structp png_ptr,
  161313. png_infop info_ptr, png_int_32 offset_x, png_int_32 offset_y,
  161314. int unit_type));
  161315. #endif
  161316. #if defined(PNG_pCAL_SUPPORTED)
  161317. extern PNG_EXPORT(png_uint_32,png_get_pCAL) PNGARG((png_structp png_ptr,
  161318. png_infop info_ptr, png_charp *purpose, png_int_32 *X0, png_int_32 *X1,
  161319. int *type, int *nparams, png_charp *units, png_charpp *params));
  161320. #endif
  161321. #if defined(PNG_pCAL_SUPPORTED)
  161322. extern PNG_EXPORT(void,png_set_pCAL) PNGARG((png_structp png_ptr,
  161323. png_infop info_ptr, png_charp purpose, png_int_32 X0, png_int_32 X1,
  161324. int type, int nparams, png_charp units, png_charpp params));
  161325. #endif
  161326. #if defined(PNG_pHYs_SUPPORTED)
  161327. extern PNG_EXPORT(png_uint_32,png_get_pHYs) PNGARG((png_structp png_ptr,
  161328. png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type));
  161329. #endif
  161330. #if defined(PNG_pHYs_SUPPORTED)
  161331. extern PNG_EXPORT(void,png_set_pHYs) PNGARG((png_structp png_ptr,
  161332. png_infop info_ptr, png_uint_32 res_x, png_uint_32 res_y, int unit_type));
  161333. #endif
  161334. extern PNG_EXPORT(png_uint_32,png_get_PLTE) PNGARG((png_structp png_ptr,
  161335. png_infop info_ptr, png_colorp *palette, int *num_palette));
  161336. extern PNG_EXPORT(void,png_set_PLTE) PNGARG((png_structp png_ptr,
  161337. png_infop info_ptr, png_colorp palette, int num_palette));
  161338. #if defined(PNG_sBIT_SUPPORTED)
  161339. extern PNG_EXPORT(png_uint_32,png_get_sBIT) PNGARG((png_structp png_ptr,
  161340. png_infop info_ptr, png_color_8p *sig_bit));
  161341. #endif
  161342. #if defined(PNG_sBIT_SUPPORTED)
  161343. extern PNG_EXPORT(void,png_set_sBIT) PNGARG((png_structp png_ptr,
  161344. png_infop info_ptr, png_color_8p sig_bit));
  161345. #endif
  161346. #if defined(PNG_sRGB_SUPPORTED)
  161347. extern PNG_EXPORT(png_uint_32,png_get_sRGB) PNGARG((png_structp png_ptr,
  161348. png_infop info_ptr, int *intent));
  161349. #endif
  161350. #if defined(PNG_sRGB_SUPPORTED)
  161351. extern PNG_EXPORT(void,png_set_sRGB) PNGARG((png_structp png_ptr,
  161352. png_infop info_ptr, int intent));
  161353. extern PNG_EXPORT(void,png_set_sRGB_gAMA_and_cHRM) PNGARG((png_structp png_ptr,
  161354. png_infop info_ptr, int intent));
  161355. #endif
  161356. #if defined(PNG_iCCP_SUPPORTED)
  161357. extern PNG_EXPORT(png_uint_32,png_get_iCCP) PNGARG((png_structp png_ptr,
  161358. png_infop info_ptr, png_charpp name, int *compression_type,
  161359. png_charpp profile, png_uint_32 *proflen));
  161360. #endif
  161361. #if defined(PNG_iCCP_SUPPORTED)
  161362. extern PNG_EXPORT(void,png_set_iCCP) PNGARG((png_structp png_ptr,
  161363. png_infop info_ptr, png_charp name, int compression_type,
  161364. png_charp profile, png_uint_32 proflen));
  161365. #endif
  161366. #if defined(PNG_sPLT_SUPPORTED)
  161367. extern PNG_EXPORT(png_uint_32,png_get_sPLT) PNGARG((png_structp png_ptr,
  161368. png_infop info_ptr, png_sPLT_tpp entries));
  161369. #endif
  161370. #if defined(PNG_sPLT_SUPPORTED)
  161371. extern PNG_EXPORT(void,png_set_sPLT) PNGARG((png_structp png_ptr,
  161372. png_infop info_ptr, png_sPLT_tp entries, int nentries));
  161373. #endif
  161374. #if defined(PNG_TEXT_SUPPORTED)
  161375. extern PNG_EXPORT(png_uint_32,png_get_text) PNGARG((png_structp png_ptr,
  161376. png_infop info_ptr, png_textp *text_ptr, int *num_text));
  161377. #endif
  161378. #if defined(PNG_TEXT_SUPPORTED)
  161379. extern PNG_EXPORT(void,png_set_text) PNGARG((png_structp png_ptr,
  161380. png_infop info_ptr, png_textp text_ptr, int num_text));
  161381. #endif
  161382. #if defined(PNG_tIME_SUPPORTED)
  161383. extern PNG_EXPORT(png_uint_32,png_get_tIME) PNGARG((png_structp png_ptr,
  161384. png_infop info_ptr, png_timep *mod_time));
  161385. #endif
  161386. #if defined(PNG_tIME_SUPPORTED)
  161387. extern PNG_EXPORT(void,png_set_tIME) PNGARG((png_structp png_ptr,
  161388. png_infop info_ptr, png_timep mod_time));
  161389. #endif
  161390. #if defined(PNG_tRNS_SUPPORTED)
  161391. extern PNG_EXPORT(png_uint_32,png_get_tRNS) PNGARG((png_structp png_ptr,
  161392. png_infop info_ptr, png_bytep *trans, int *num_trans,
  161393. png_color_16p *trans_values));
  161394. #endif
  161395. #if defined(PNG_tRNS_SUPPORTED)
  161396. extern PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr,
  161397. png_infop info_ptr, png_bytep trans, int num_trans,
  161398. png_color_16p trans_values));
  161399. #endif
  161400. #if defined(PNG_tRNS_SUPPORTED)
  161401. #endif
  161402. #if defined(PNG_sCAL_SUPPORTED)
  161403. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161404. extern PNG_EXPORT(png_uint_32,png_get_sCAL) PNGARG((png_structp png_ptr,
  161405. png_infop info_ptr, int *unit, double *width, double *height));
  161406. #else
  161407. #ifdef PNG_FIXED_POINT_SUPPORTED
  161408. extern PNG_EXPORT(png_uint_32,png_get_sCAL_s) PNGARG((png_structp png_ptr,
  161409. png_infop info_ptr, int *unit, png_charpp swidth, png_charpp sheight));
  161410. #endif
  161411. #endif
  161412. #endif /* PNG_sCAL_SUPPORTED */
  161413. #if defined(PNG_sCAL_SUPPORTED)
  161414. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161415. extern PNG_EXPORT(void,png_set_sCAL) PNGARG((png_structp png_ptr,
  161416. png_infop info_ptr, int unit, double width, double height));
  161417. #else
  161418. #ifdef PNG_FIXED_POINT_SUPPORTED
  161419. extern PNG_EXPORT(void,png_set_sCAL_s) PNGARG((png_structp png_ptr,
  161420. png_infop info_ptr, int unit, png_charp swidth, png_charp sheight));
  161421. #endif
  161422. #endif
  161423. #endif /* PNG_sCAL_SUPPORTED || PNG_WRITE_sCAL_SUPPORTED */
  161424. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  161425. extern PNG_EXPORT(void, png_set_keep_unknown_chunks) PNGARG((png_structp
  161426. png_ptr, int keep, png_bytep chunk_list, int num_chunks));
  161427. extern PNG_EXPORT(void, png_set_unknown_chunks) PNGARG((png_structp png_ptr,
  161428. png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns));
  161429. extern PNG_EXPORT(void, png_set_unknown_chunk_location)
  161430. PNGARG((png_structp png_ptr, png_infop info_ptr, int chunk, int location));
  161431. extern PNG_EXPORT(png_uint_32,png_get_unknown_chunks) PNGARG((png_structp
  161432. png_ptr, png_infop info_ptr, png_unknown_chunkpp entries));
  161433. #endif
  161434. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  161435. PNG_EXPORT(int,png_handle_as_unknown) PNGARG((png_structp png_ptr, png_bytep
  161436. chunk_name));
  161437. #endif
  161438. extern PNG_EXPORT(void, png_set_invalid) PNGARG((png_structp png_ptr,
  161439. png_infop info_ptr, int mask));
  161440. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  161441. extern PNG_EXPORT(void, png_read_png) PNGARG((png_structp png_ptr,
  161442. png_infop info_ptr,
  161443. int transforms,
  161444. png_voidp params));
  161445. extern PNG_EXPORT(void, png_write_png) PNGARG((png_structp png_ptr,
  161446. png_infop info_ptr,
  161447. int transforms,
  161448. png_voidp params));
  161449. #endif
  161450. #ifdef PNG_DEBUG
  161451. #if (PNG_DEBUG > 0)
  161452. #if !defined(PNG_DEBUG_FILE) && defined(_MSC_VER)
  161453. #include <crtdbg.h>
  161454. #if (PNG_DEBUG > 1)
  161455. #define png_debug(l,m) _RPT0(_CRT_WARN,m)
  161456. #define png_debug1(l,m,p1) _RPT1(_CRT_WARN,m,p1)
  161457. #define png_debug2(l,m,p1,p2) _RPT2(_CRT_WARN,m,p1,p2)
  161458. #endif
  161459. #else /* PNG_DEBUG_FILE || !_MSC_VER */
  161460. #ifndef PNG_DEBUG_FILE
  161461. #define PNG_DEBUG_FILE stderr
  161462. #endif /* PNG_DEBUG_FILE */
  161463. #if (PNG_DEBUG > 1)
  161464. #define png_debug(l,m) \
  161465. { \
  161466. int num_tabs=l; \
  161467. fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
  161468. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":"")))); \
  161469. }
  161470. #define png_debug1(l,m,p1) \
  161471. { \
  161472. int num_tabs=l; \
  161473. fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
  161474. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1); \
  161475. }
  161476. #define png_debug2(l,m,p1,p2) \
  161477. { \
  161478. int num_tabs=l; \
  161479. fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
  161480. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1,p2); \
  161481. }
  161482. #endif /* (PNG_DEBUG > 1) */
  161483. #endif /* _MSC_VER */
  161484. #endif /* (PNG_DEBUG > 0) */
  161485. #endif /* PNG_DEBUG */
  161486. #ifndef png_debug
  161487. #define png_debug(l, m)
  161488. #endif
  161489. #ifndef png_debug1
  161490. #define png_debug1(l, m, p1)
  161491. #endif
  161492. #ifndef png_debug2
  161493. #define png_debug2(l, m, p1, p2)
  161494. #endif
  161495. extern PNG_EXPORT(png_charp,png_get_copyright) PNGARG((png_structp png_ptr));
  161496. extern PNG_EXPORT(png_charp,png_get_header_ver) PNGARG((png_structp png_ptr));
  161497. extern PNG_EXPORT(png_charp,png_get_header_version) PNGARG((png_structp png_ptr));
  161498. extern PNG_EXPORT(png_charp,png_get_libpng_ver) PNGARG((png_structp png_ptr));
  161499. #ifdef PNG_MNG_FEATURES_SUPPORTED
  161500. extern PNG_EXPORT(png_uint_32,png_permit_mng_features) PNGARG((png_structp
  161501. png_ptr, png_uint_32 mng_features_permitted));
  161502. #endif
  161503. #define PNG_HANDLE_CHUNK_AS_DEFAULT 0
  161504. #define PNG_HANDLE_CHUNK_NEVER 1
  161505. #define PNG_HANDLE_CHUNK_IF_SAFE 2
  161506. #define PNG_HANDLE_CHUNK_ALWAYS 3
  161507. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  161508. #if defined(PNG_MMX_CODE_SUPPORTED)
  161509. #define PNG_ASM_FLAG_MMX_SUPPORT_COMPILED 0x01 /* not user-settable */
  161510. #define PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU 0x02 /* not user-settable */
  161511. #define PNG_ASM_FLAG_MMX_READ_COMBINE_ROW 0x04
  161512. #define PNG_ASM_FLAG_MMX_READ_INTERLACE 0x08
  161513. #define PNG_ASM_FLAG_MMX_READ_FILTER_SUB 0x10
  161514. #define PNG_ASM_FLAG_MMX_READ_FILTER_UP 0x20
  161515. #define PNG_ASM_FLAG_MMX_READ_FILTER_AVG 0x40
  161516. #define PNG_ASM_FLAG_MMX_READ_FILTER_PAETH 0x80
  161517. #define PNG_ASM_FLAGS_INITIALIZED 0x80000000 /* not user-settable */
  161518. #define PNG_MMX_READ_FLAGS ( PNG_ASM_FLAG_MMX_READ_COMBINE_ROW \
  161519. | PNG_ASM_FLAG_MMX_READ_INTERLACE \
  161520. | PNG_ASM_FLAG_MMX_READ_FILTER_SUB \
  161521. | PNG_ASM_FLAG_MMX_READ_FILTER_UP \
  161522. | PNG_ASM_FLAG_MMX_READ_FILTER_AVG \
  161523. | PNG_ASM_FLAG_MMX_READ_FILTER_PAETH )
  161524. #define PNG_MMX_WRITE_FLAGS ( 0 )
  161525. #define PNG_MMX_FLAGS ( PNG_ASM_FLAG_MMX_SUPPORT_COMPILED \
  161526. | PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU \
  161527. | PNG_MMX_READ_FLAGS \
  161528. | PNG_MMX_WRITE_FLAGS )
  161529. #define PNG_SELECT_READ 1
  161530. #define PNG_SELECT_WRITE 2
  161531. #endif /* PNG_MMX_CODE_SUPPORTED */
  161532. #if !defined(PNG_1_0_X)
  161533. extern PNG_EXPORT(png_uint_32,png_get_mmx_flagmask)
  161534. PNGARG((int flag_select, int *compilerID));
  161535. extern PNG_EXPORT(png_uint_32,png_get_asm_flagmask)
  161536. PNGARG((int flag_select));
  161537. extern PNG_EXPORT(png_uint_32,png_get_asm_flags)
  161538. PNGARG((png_structp png_ptr));
  161539. extern PNG_EXPORT(png_byte,png_get_mmx_bitdepth_threshold)
  161540. PNGARG((png_structp png_ptr));
  161541. extern PNG_EXPORT(png_uint_32,png_get_mmx_rowbytes_threshold)
  161542. PNGARG((png_structp png_ptr));
  161543. extern PNG_EXPORT(void,png_set_asm_flags)
  161544. PNGARG((png_structp png_ptr, png_uint_32 asm_flags));
  161545. extern PNG_EXPORT(void,png_set_mmx_thresholds)
  161546. PNGARG((png_structp png_ptr, png_byte mmx_bitdepth_threshold,
  161547. png_uint_32 mmx_rowbytes_threshold));
  161548. #endif /* PNG_1_0_X */
  161549. #if !defined(PNG_1_0_X)
  161550. extern PNG_EXPORT(int,png_mmx_support) PNGARG((void));
  161551. #endif /* PNG_ASSEMBLER_CODE_SUPPORTED */
  161552. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  161553. extern PNG_EXPORT(void,png_set_strip_error_numbers) PNGARG((png_structp
  161554. png_ptr, png_uint_32 strip_mode));
  161555. #endif
  161556. #endif /* PNG_1_0_X */
  161557. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  161558. extern PNG_EXPORT(void,png_set_user_limits) PNGARG((png_structp
  161559. png_ptr, png_uint_32 user_width_max, png_uint_32 user_height_max));
  161560. extern PNG_EXPORT(png_uint_32,png_get_user_width_max) PNGARG((png_structp
  161561. png_ptr));
  161562. extern PNG_EXPORT(png_uint_32,png_get_user_height_max) PNGARG((png_structp
  161563. png_ptr));
  161564. #endif
  161565. #ifdef PNG_READ_COMPOSITE_NODIV_SUPPORTED
  161566. # define png_composite(composite, fg, alpha, bg) \
  161567. { png_uint_16 temp = (png_uint_16)((png_uint_16)(fg) * (png_uint_16)(alpha) \
  161568. + (png_uint_16)(bg)*(png_uint_16)(255 - \
  161569. (png_uint_16)(alpha)) + (png_uint_16)128); \
  161570. (composite) = (png_byte)((temp + (temp >> 8)) >> 8); }
  161571. # define png_composite_16(composite, fg, alpha, bg) \
  161572. { png_uint_32 temp = (png_uint_32)((png_uint_32)(fg) * (png_uint_32)(alpha) \
  161573. + (png_uint_32)(bg)*(png_uint_32)(65535L - \
  161574. (png_uint_32)(alpha)) + (png_uint_32)32768L); \
  161575. (composite) = (png_uint_16)((temp + (temp >> 16)) >> 16); }
  161576. #else /* standard method using integer division */
  161577. # define png_composite(composite, fg, alpha, bg) \
  161578. (composite) = (png_byte)(((png_uint_16)(fg) * (png_uint_16)(alpha) + \
  161579. (png_uint_16)(bg) * (png_uint_16)(255 - (png_uint_16)(alpha)) + \
  161580. (png_uint_16)127) / 255)
  161581. # define png_composite_16(composite, fg, alpha, bg) \
  161582. (composite) = (png_uint_16)(((png_uint_32)(fg) * (png_uint_32)(alpha) + \
  161583. (png_uint_32)(bg)*(png_uint_32)(65535L - (png_uint_32)(alpha)) + \
  161584. (png_uint_32)32767) / (png_uint_32)65535L)
  161585. #endif /* PNG_READ_COMPOSITE_NODIV_SUPPORTED */
  161586. #if defined(PNG_READ_BIG_ENDIAN_SUPPORTED)
  161587. # define png_get_uint_32(buf) ( *((png_uint_32p) (buf)))
  161588. # define png_get_uint_16(buf) ( *((png_uint_16p) (buf)))
  161589. # define png_get_int_32(buf) ( *((png_int_32p) (buf)))
  161590. #else
  161591. extern PNG_EXPORT(png_uint_32,png_get_uint_32) PNGARG((png_bytep buf));
  161592. extern PNG_EXPORT(png_uint_16,png_get_uint_16) PNGARG((png_bytep buf));
  161593. extern PNG_EXPORT(png_int_32,png_get_int_32) PNGARG((png_bytep buf));
  161594. #endif /* !PNG_READ_BIG_ENDIAN_SUPPORTED */
  161595. extern PNG_EXPORT(png_uint_32,png_get_uint_31)
  161596. PNGARG((png_structp png_ptr, png_bytep buf));
  161597. extern PNG_EXPORT(void,png_save_uint_32)
  161598. PNGARG((png_bytep buf, png_uint_32 i));
  161599. extern PNG_EXPORT(void,png_save_int_32)
  161600. PNGARG((png_bytep buf, png_int_32 i));
  161601. extern PNG_EXPORT(void,png_save_uint_16)
  161602. PNGARG((png_bytep buf, unsigned int i));
  161603. #define PNG_HAVE_IHDR 0x01
  161604. #define PNG_HAVE_PLTE 0x02
  161605. #define PNG_HAVE_IDAT 0x04
  161606. #define PNG_AFTER_IDAT 0x08 /* Have complete zlib datastream */
  161607. #define PNG_HAVE_IEND 0x10
  161608. #if defined(PNG_INTERNAL)
  161609. #define PNG_HAVE_gAMA 0x20
  161610. #define PNG_HAVE_cHRM 0x40
  161611. #define PNG_HAVE_sRGB 0x80
  161612. #define PNG_HAVE_CHUNK_HEADER 0x100
  161613. #define PNG_WROTE_tIME 0x200
  161614. #define PNG_WROTE_INFO_BEFORE_PLTE 0x400
  161615. #define PNG_BACKGROUND_IS_GRAY 0x800
  161616. #define PNG_HAVE_PNG_SIGNATURE 0x1000
  161617. #define PNG_HAVE_CHUNK_AFTER_IDAT 0x2000 /* Have another chunk after IDAT */
  161618. #define PNG_BGR 0x0001
  161619. #define PNG_INTERLACE 0x0002
  161620. #define PNG_PACK 0x0004
  161621. #define PNG_SHIFT 0x0008
  161622. #define PNG_SWAP_BYTES 0x0010
  161623. #define PNG_INVERT_MONO 0x0020
  161624. #define PNG_DITHER 0x0040
  161625. #define PNG_BACKGROUND 0x0080
  161626. #define PNG_BACKGROUND_EXPAND 0x0100
  161627. #define PNG_16_TO_8 0x0400
  161628. #define PNG_RGBA 0x0800
  161629. #define PNG_EXPAND 0x1000
  161630. #define PNG_GAMMA 0x2000
  161631. #define PNG_GRAY_TO_RGB 0x4000
  161632. #define PNG_FILLER 0x8000L
  161633. #define PNG_PACKSWAP 0x10000L
  161634. #define PNG_SWAP_ALPHA 0x20000L
  161635. #define PNG_STRIP_ALPHA 0x40000L
  161636. #define PNG_INVERT_ALPHA 0x80000L
  161637. #define PNG_USER_TRANSFORM 0x100000L
  161638. #define PNG_RGB_TO_GRAY_ERR 0x200000L
  161639. #define PNG_RGB_TO_GRAY_WARN 0x400000L
  161640. #define PNG_RGB_TO_GRAY 0x600000L /* two bits, RGB_TO_GRAY_ERR|WARN */
  161641. #define PNG_ADD_ALPHA 0x1000000L /* Added to libpng-1.2.7 */
  161642. #define PNG_EXPAND_tRNS 0x2000000L /* Added to libpng-1.2.9 */
  161643. #define PNG_STRUCT_PNG 0x0001
  161644. #define PNG_STRUCT_INFO 0x0002
  161645. #define PNG_WEIGHT_SHIFT 8
  161646. #define PNG_WEIGHT_FACTOR (1<<(PNG_WEIGHT_SHIFT))
  161647. #define PNG_COST_SHIFT 3
  161648. #define PNG_COST_FACTOR (1<<(PNG_COST_SHIFT))
  161649. #define PNG_FLAG_ZLIB_CUSTOM_STRATEGY 0x0001
  161650. #define PNG_FLAG_ZLIB_CUSTOM_LEVEL 0x0002
  161651. #define PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL 0x0004
  161652. #define PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS 0x0008
  161653. #define PNG_FLAG_ZLIB_CUSTOM_METHOD 0x0010
  161654. #define PNG_FLAG_ZLIB_FINISHED 0x0020
  161655. #define PNG_FLAG_ROW_INIT 0x0040
  161656. #define PNG_FLAG_FILLER_AFTER 0x0080
  161657. #define PNG_FLAG_CRC_ANCILLARY_USE 0x0100
  161658. #define PNG_FLAG_CRC_ANCILLARY_NOWARN 0x0200
  161659. #define PNG_FLAG_CRC_CRITICAL_USE 0x0400
  161660. #define PNG_FLAG_CRC_CRITICAL_IGNORE 0x0800
  161661. #define PNG_FLAG_FREE_PLTE 0x1000
  161662. #define PNG_FLAG_FREE_TRNS 0x2000
  161663. #define PNG_FLAG_FREE_HIST 0x4000
  161664. #define PNG_FLAG_KEEP_UNKNOWN_CHUNKS 0x8000L
  161665. #define PNG_FLAG_KEEP_UNSAFE_CHUNKS 0x10000L
  161666. #define PNG_FLAG_LIBRARY_MISMATCH 0x20000L
  161667. #define PNG_FLAG_STRIP_ERROR_NUMBERS 0x40000L
  161668. #define PNG_FLAG_STRIP_ERROR_TEXT 0x80000L
  161669. #define PNG_FLAG_MALLOC_NULL_MEM_OK 0x100000L
  161670. #define PNG_FLAG_ADD_ALPHA 0x200000L /* Added to libpng-1.2.8 */
  161671. #define PNG_FLAG_STRIP_ALPHA 0x400000L /* Added to libpng-1.2.8 */
  161672. #define PNG_FLAG_CRC_ANCILLARY_MASK (PNG_FLAG_CRC_ANCILLARY_USE | \
  161673. PNG_FLAG_CRC_ANCILLARY_NOWARN)
  161674. #define PNG_FLAG_CRC_CRITICAL_MASK (PNG_FLAG_CRC_CRITICAL_USE | \
  161675. PNG_FLAG_CRC_CRITICAL_IGNORE)
  161676. #define PNG_FLAG_CRC_MASK (PNG_FLAG_CRC_ANCILLARY_MASK | \
  161677. PNG_FLAG_CRC_CRITICAL_MASK)
  161678. #define PNG_COLOR_DIST(c1, c2) (abs((int)((c1).red) - (int)((c2).red)) + \
  161679. abs((int)((c1).green) - (int)((c2).green)) + \
  161680. abs((int)((c1).blue) - (int)((c2).blue)))
  161681. #define PNG_ROWBYTES(pixel_bits, width) \
  161682. ((pixel_bits) >= 8 ? \
  161683. ((width) * (((png_uint_32)(pixel_bits)) >> 3)) : \
  161684. (( ((width) * ((png_uint_32)(pixel_bits))) + 7) >> 3) )
  161685. #define PNG_OUT_OF_RANGE(value, ideal, delta) \
  161686. ( (value) < (ideal)-(delta) || (value) > (ideal)+(delta) )
  161687. #if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN)
  161688. #ifdef PNG_USE_GLOBAL_ARRAYS
  161689. PNG_EXPORT_VAR (PNG_CONST png_byte FARDATA) png_sig[8];
  161690. #else
  161691. #endif
  161692. #endif /* PNG_NO_EXTERN */
  161693. #define PNG_IHDR png_byte png_IHDR[5] = { 73, 72, 68, 82, '\0'}
  161694. #define PNG_IDAT png_byte png_IDAT[5] = { 73, 68, 65, 84, '\0'}
  161695. #define PNG_IEND png_byte png_IEND[5] = { 73, 69, 78, 68, '\0'}
  161696. #define PNG_PLTE png_byte png_PLTE[5] = { 80, 76, 84, 69, '\0'}
  161697. #define PNG_bKGD png_byte png_bKGD[5] = { 98, 75, 71, 68, '\0'}
  161698. #define PNG_cHRM png_byte png_cHRM[5] = { 99, 72, 82, 77, '\0'}
  161699. #define PNG_gAMA png_byte png_gAMA[5] = {103, 65, 77, 65, '\0'}
  161700. #define PNG_hIST png_byte png_hIST[5] = {104, 73, 83, 84, '\0'}
  161701. #define PNG_iCCP png_byte png_iCCP[5] = {105, 67, 67, 80, '\0'}
  161702. #define PNG_iTXt png_byte png_iTXt[5] = {105, 84, 88, 116, '\0'}
  161703. #define PNG_oFFs png_byte png_oFFs[5] = {111, 70, 70, 115, '\0'}
  161704. #define PNG_pCAL png_byte png_pCAL[5] = {112, 67, 65, 76, '\0'}
  161705. #define PNG_sCAL png_byte png_sCAL[5] = {115, 67, 65, 76, '\0'}
  161706. #define PNG_pHYs png_byte png_pHYs[5] = {112, 72, 89, 115, '\0'}
  161707. #define PNG_sBIT png_byte png_sBIT[5] = {115, 66, 73, 84, '\0'}
  161708. #define PNG_sPLT png_byte png_sPLT[5] = {115, 80, 76, 84, '\0'}
  161709. #define PNG_sRGB png_byte png_sRGB[5] = {115, 82, 71, 66, '\0'}
  161710. #define PNG_tEXt png_byte png_tEXt[5] = {116, 69, 88, 116, '\0'}
  161711. #define PNG_tIME png_byte png_tIME[5] = {116, 73, 77, 69, '\0'}
  161712. #define PNG_tRNS png_byte png_tRNS[5] = {116, 82, 78, 83, '\0'}
  161713. #define PNG_zTXt png_byte png_zTXt[5] = {122, 84, 88, 116, '\0'}
  161714. #ifdef PNG_USE_GLOBAL_ARRAYS
  161715. PNG_EXPORT_VAR (png_byte FARDATA) png_IHDR[5];
  161716. PNG_EXPORT_VAR (png_byte FARDATA) png_IDAT[5];
  161717. PNG_EXPORT_VAR (png_byte FARDATA) png_IEND[5];
  161718. PNG_EXPORT_VAR (png_byte FARDATA) png_PLTE[5];
  161719. PNG_EXPORT_VAR (png_byte FARDATA) png_bKGD[5];
  161720. PNG_EXPORT_VAR (png_byte FARDATA) png_cHRM[5];
  161721. PNG_EXPORT_VAR (png_byte FARDATA) png_gAMA[5];
  161722. PNG_EXPORT_VAR (png_byte FARDATA) png_hIST[5];
  161723. PNG_EXPORT_VAR (png_byte FARDATA) png_iCCP[5];
  161724. PNG_EXPORT_VAR (png_byte FARDATA) png_iTXt[5];
  161725. PNG_EXPORT_VAR (png_byte FARDATA) png_oFFs[5];
  161726. PNG_EXPORT_VAR (png_byte FARDATA) png_pCAL[5];
  161727. PNG_EXPORT_VAR (png_byte FARDATA) png_sCAL[5];
  161728. PNG_EXPORT_VAR (png_byte FARDATA) png_pHYs[5];
  161729. PNG_EXPORT_VAR (png_byte FARDATA) png_sBIT[5];
  161730. PNG_EXPORT_VAR (png_byte FARDATA) png_sPLT[5];
  161731. PNG_EXPORT_VAR (png_byte FARDATA) png_sRGB[5];
  161732. PNG_EXPORT_VAR (png_byte FARDATA) png_tEXt[5];
  161733. PNG_EXPORT_VAR (png_byte FARDATA) png_tIME[5];
  161734. PNG_EXPORT_VAR (png_byte FARDATA) png_tRNS[5];
  161735. PNG_EXPORT_VAR (png_byte FARDATA) png_zTXt[5];
  161736. #endif /* PNG_USE_GLOBAL_ARRAYS */
  161737. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161738. extern PNG_EXPORT(void,png_read_init) PNGARG((png_structp png_ptr));
  161739. #undef png_read_init
  161740. #define png_read_init(png_ptr) png_read_init_3(&png_ptr, \
  161741. PNG_LIBPNG_VER_STRING, png_sizeof(png_struct));
  161742. #endif
  161743. extern PNG_EXPORT(void,png_read_init_3) PNGARG((png_structpp ptr_ptr,
  161744. png_const_charp user_png_ver, png_size_t png_struct_size));
  161745. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161746. extern PNG_EXPORT(void,png_read_init_2) PNGARG((png_structp png_ptr,
  161747. png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t
  161748. png_info_size));
  161749. #endif
  161750. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161751. extern PNG_EXPORT(void,png_write_init) PNGARG((png_structp png_ptr));
  161752. #undef png_write_init
  161753. #define png_write_init(png_ptr) png_write_init_3(&png_ptr, \
  161754. PNG_LIBPNG_VER_STRING, png_sizeof(png_struct));
  161755. #endif
  161756. extern PNG_EXPORT(void,png_write_init_3) PNGARG((png_structpp ptr_ptr,
  161757. png_const_charp user_png_ver, png_size_t png_struct_size));
  161758. extern PNG_EXPORT(void,png_write_init_2) PNGARG((png_structp png_ptr,
  161759. png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t
  161760. png_info_size));
  161761. PNG_EXTERN png_voidp png_create_struct PNGARG((int type));
  161762. PNG_EXTERN void png_destroy_struct PNGARG((png_voidp struct_ptr));
  161763. PNG_EXTERN png_voidp png_create_struct_2 PNGARG((int type, png_malloc_ptr
  161764. malloc_fn, png_voidp mem_ptr));
  161765. PNG_EXTERN void png_destroy_struct_2 PNGARG((png_voidp struct_ptr,
  161766. png_free_ptr free_fn, png_voidp mem_ptr));
  161767. PNG_EXTERN void png_info_destroy PNGARG((png_structp png_ptr,
  161768. png_infop info_ptr));
  161769. #ifndef PNG_1_0_X
  161770. PNG_EXTERN voidpf png_zalloc PNGARG((voidpf png_ptr, uInt items, uInt size));
  161771. PNG_EXTERN void png_zfree PNGARG((voidpf png_ptr, voidpf ptr));
  161772. #ifdef PNG_SIZE_T
  161773. PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size));
  161774. #endif
  161775. PNG_EXTERN void PNGAPI png_default_read_data PNGARG((png_structp png_ptr,
  161776. png_bytep data, png_size_t length));
  161777. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  161778. PNG_EXTERN void PNGAPI png_push_fill_buffer PNGARG((png_structp png_ptr,
  161779. png_bytep buffer, png_size_t length));
  161780. #endif
  161781. PNG_EXTERN void PNGAPI png_default_write_data PNGARG((png_structp png_ptr,
  161782. png_bytep data, png_size_t length));
  161783. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  161784. #if !defined(PNG_NO_STDIO)
  161785. PNG_EXTERN void PNGAPI png_default_flush PNGARG((png_structp png_ptr));
  161786. #endif
  161787. #endif
  161788. #else /* PNG_1_0_X */
  161789. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  161790. PNG_EXTERN void png_push_fill_buffer PNGARG((png_structp png_ptr,
  161791. png_bytep buffer, png_size_t length));
  161792. #endif
  161793. #endif /* PNG_1_0_X */
  161794. PNG_EXTERN void png_reset_crc PNGARG((png_structp png_ptr));
  161795. PNG_EXTERN void png_write_data PNGARG((png_structp png_ptr, png_bytep data,
  161796. png_size_t length));
  161797. PNG_EXTERN void png_read_data PNGARG((png_structp png_ptr, png_bytep data,
  161798. png_size_t length));
  161799. PNG_EXTERN void png_crc_read PNGARG((png_structp png_ptr, png_bytep buf,
  161800. png_size_t length));
  161801. #if defined(PNG_zTXt_SUPPORTED) || defined(PNG_iTXt_SUPPORTED) || \
  161802. defined(PNG_iCCP_SUPPORTED) || defined(PNG_sPLT_SUPPORTED)
  161803. PNG_EXTERN png_charp png_decompress_chunk PNGARG((png_structp png_ptr,
  161804. int comp_type, png_charp chunkdata, png_size_t chunklength,
  161805. png_size_t prefix_length, png_size_t *data_length));
  161806. #endif
  161807. PNG_EXTERN int png_crc_finish PNGARG((png_structp png_ptr, png_uint_32 skip));
  161808. PNG_EXTERN int png_crc_error PNGARG((png_structp png_ptr));
  161809. PNG_EXTERN void png_calculate_crc PNGARG((png_structp png_ptr, png_bytep ptr,
  161810. png_size_t length));
  161811. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  161812. PNG_EXTERN void png_flush PNGARG((png_structp png_ptr));
  161813. #endif
  161814. PNG_EXTERN void png_write_sig PNGARG((png_structp png_ptr));
  161815. PNG_EXTERN void png_write_IHDR PNGARG((png_structp png_ptr, png_uint_32 width,
  161816. png_uint_32 height,
  161817. int bit_depth, int color_type, int compression_method, int filter_method,
  161818. int interlace_method));
  161819. PNG_EXTERN void png_write_PLTE PNGARG((png_structp png_ptr, png_colorp palette,
  161820. png_uint_32 num_pal));
  161821. PNG_EXTERN void png_write_IDAT PNGARG((png_structp png_ptr, png_bytep data,
  161822. png_size_t length));
  161823. PNG_EXTERN void png_write_IEND PNGARG((png_structp png_ptr));
  161824. #if defined(PNG_WRITE_gAMA_SUPPORTED)
  161825. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161826. PNG_EXTERN void png_write_gAMA PNGARG((png_structp png_ptr, double file_gamma));
  161827. #endif
  161828. #ifdef PNG_FIXED_POINT_SUPPORTED
  161829. PNG_EXTERN void png_write_gAMA_fixed PNGARG((png_structp png_ptr, png_fixed_point
  161830. file_gamma));
  161831. #endif
  161832. #endif
  161833. #if defined(PNG_WRITE_sBIT_SUPPORTED)
  161834. PNG_EXTERN void png_write_sBIT PNGARG((png_structp png_ptr, png_color_8p sbit,
  161835. int color_type));
  161836. #endif
  161837. #if defined(PNG_WRITE_cHRM_SUPPORTED)
  161838. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161839. PNG_EXTERN void png_write_cHRM PNGARG((png_structp png_ptr,
  161840. double white_x, double white_y,
  161841. double red_x, double red_y, double green_x, double green_y,
  161842. double blue_x, double blue_y));
  161843. #endif
  161844. #ifdef PNG_FIXED_POINT_SUPPORTED
  161845. PNG_EXTERN void png_write_cHRM_fixed PNGARG((png_structp png_ptr,
  161846. png_fixed_point int_white_x, png_fixed_point int_white_y,
  161847. png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point
  161848. int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x,
  161849. png_fixed_point int_blue_y));
  161850. #endif
  161851. #endif
  161852. #if defined(PNG_WRITE_sRGB_SUPPORTED)
  161853. PNG_EXTERN void png_write_sRGB PNGARG((png_structp png_ptr,
  161854. int intent));
  161855. #endif
  161856. #if defined(PNG_WRITE_iCCP_SUPPORTED)
  161857. PNG_EXTERN void png_write_iCCP PNGARG((png_structp png_ptr,
  161858. png_charp name, int compression_type,
  161859. png_charp profile, int proflen));
  161860. #endif
  161861. #if defined(PNG_WRITE_sPLT_SUPPORTED)
  161862. PNG_EXTERN void png_write_sPLT PNGARG((png_structp png_ptr,
  161863. png_sPLT_tp palette));
  161864. #endif
  161865. #if defined(PNG_WRITE_tRNS_SUPPORTED)
  161866. PNG_EXTERN void png_write_tRNS PNGARG((png_structp png_ptr, png_bytep trans,
  161867. png_color_16p values, int number, int color_type));
  161868. #endif
  161869. #if defined(PNG_WRITE_bKGD_SUPPORTED)
  161870. PNG_EXTERN void png_write_bKGD PNGARG((png_structp png_ptr,
  161871. png_color_16p values, int color_type));
  161872. #endif
  161873. #if defined(PNG_WRITE_hIST_SUPPORTED)
  161874. PNG_EXTERN void png_write_hIST PNGARG((png_structp png_ptr, png_uint_16p hist,
  161875. int num_hist));
  161876. #endif
  161877. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \
  161878. defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
  161879. PNG_EXTERN png_size_t png_check_keyword PNGARG((png_structp png_ptr,
  161880. png_charp key, png_charpp new_key));
  161881. #endif
  161882. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  161883. PNG_EXTERN void png_write_tEXt PNGARG((png_structp png_ptr, png_charp key,
  161884. png_charp text, png_size_t text_len));
  161885. #endif
  161886. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  161887. PNG_EXTERN void png_write_zTXt PNGARG((png_structp png_ptr, png_charp key,
  161888. png_charp text, png_size_t text_len, int compression));
  161889. #endif
  161890. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  161891. PNG_EXTERN void png_write_iTXt PNGARG((png_structp png_ptr,
  161892. int compression, png_charp key, png_charp lang, png_charp lang_key,
  161893. png_charp text));
  161894. #endif
  161895. #if defined(PNG_TEXT_SUPPORTED) /* Added at version 1.0.14 and 1.2.4 */
  161896. PNG_EXTERN int png_set_text_2 PNGARG((png_structp png_ptr,
  161897. png_infop info_ptr, png_textp text_ptr, int num_text));
  161898. #endif
  161899. #if defined(PNG_WRITE_oFFs_SUPPORTED)
  161900. PNG_EXTERN void png_write_oFFs PNGARG((png_structp png_ptr,
  161901. png_int_32 x_offset, png_int_32 y_offset, int unit_type));
  161902. #endif
  161903. #if defined(PNG_WRITE_pCAL_SUPPORTED)
  161904. PNG_EXTERN void png_write_pCAL PNGARG((png_structp png_ptr, png_charp purpose,
  161905. png_int_32 X0, png_int_32 X1, int type, int nparams,
  161906. png_charp units, png_charpp params));
  161907. #endif
  161908. #if defined(PNG_WRITE_pHYs_SUPPORTED)
  161909. PNG_EXTERN void png_write_pHYs PNGARG((png_structp png_ptr,
  161910. png_uint_32 x_pixels_per_unit, png_uint_32 y_pixels_per_unit,
  161911. int unit_type));
  161912. #endif
  161913. #if defined(PNG_WRITE_tIME_SUPPORTED)
  161914. PNG_EXTERN void png_write_tIME PNGARG((png_structp png_ptr,
  161915. png_timep mod_time));
  161916. #endif
  161917. #if defined(PNG_WRITE_sCAL_SUPPORTED)
  161918. #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
  161919. PNG_EXTERN void png_write_sCAL PNGARG((png_structp png_ptr,
  161920. int unit, double width, double height));
  161921. #else
  161922. #ifdef PNG_FIXED_POINT_SUPPORTED
  161923. PNG_EXTERN void png_write_sCAL_s PNGARG((png_structp png_ptr,
  161924. int unit, png_charp width, png_charp height));
  161925. #endif
  161926. #endif
  161927. #endif
  161928. PNG_EXTERN void png_write_finish_row PNGARG((png_structp png_ptr));
  161929. PNG_EXTERN void png_write_start_row PNGARG((png_structp png_ptr));
  161930. #if defined(PNG_READ_GAMMA_SUPPORTED)
  161931. PNG_EXTERN void png_build_gamma_table PNGARG((png_structp png_ptr));
  161932. #endif
  161933. PNG_EXTERN void png_combine_row PNGARG((png_structp png_ptr, png_bytep row,
  161934. int mask));
  161935. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  161936. PNG_EXTERN void png_do_read_interlace PNGARG((png_structp png_ptr));
  161937. #endif
  161938. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  161939. PNG_EXTERN void png_do_write_interlace PNGARG((png_row_infop row_info,
  161940. png_bytep row, int pass));
  161941. #endif
  161942. PNG_EXTERN void png_read_filter_row PNGARG((png_structp png_ptr,
  161943. png_row_infop row_info, png_bytep row, png_bytep prev_row, int filter));
  161944. PNG_EXTERN void png_write_find_filter PNGARG((png_structp png_ptr,
  161945. png_row_infop row_info));
  161946. PNG_EXTERN void png_write_filtered_row PNGARG((png_structp png_ptr,
  161947. png_bytep filtered_row));
  161948. PNG_EXTERN void png_read_finish_row PNGARG((png_structp png_ptr));
  161949. PNG_EXTERN void png_read_start_row PNGARG((png_structp png_ptr));
  161950. PNG_EXTERN void png_read_transform_info PNGARG((png_structp png_ptr,
  161951. png_infop info_ptr));
  161952. #if defined(PNG_READ_FILLER_SUPPORTED)
  161953. PNG_EXTERN void png_do_read_filler PNGARG((png_row_infop row_info,
  161954. png_bytep row, png_uint_32 filler, png_uint_32 flags));
  161955. #endif
  161956. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  161957. PNG_EXTERN void png_do_read_swap_alpha PNGARG((png_row_infop row_info,
  161958. png_bytep row));
  161959. #endif
  161960. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  161961. PNG_EXTERN void png_do_write_swap_alpha PNGARG((png_row_infop row_info,
  161962. png_bytep row));
  161963. #endif
  161964. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  161965. PNG_EXTERN void png_do_read_invert_alpha PNGARG((png_row_infop row_info,
  161966. png_bytep row));
  161967. #endif
  161968. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  161969. PNG_EXTERN void png_do_write_invert_alpha PNGARG((png_row_infop row_info,
  161970. png_bytep row));
  161971. #endif
  161972. #if defined(PNG_WRITE_FILLER_SUPPORTED) || \
  161973. defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  161974. PNG_EXTERN void png_do_strip_filler PNGARG((png_row_infop row_info,
  161975. png_bytep row, png_uint_32 flags));
  161976. #endif
  161977. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  161978. PNG_EXTERN void png_do_swap PNGARG((png_row_infop row_info, png_bytep row));
  161979. #endif
  161980. #if defined(PNG_READ_PACKSWAP_SUPPORTED) || defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  161981. PNG_EXTERN void png_do_packswap PNGARG((png_row_infop row_info, png_bytep row));
  161982. #endif
  161983. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  161984. PNG_EXTERN int png_do_rgb_to_gray PNGARG((png_structp png_ptr, png_row_infop
  161985. row_info, png_bytep row));
  161986. #endif
  161987. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  161988. PNG_EXTERN void png_do_gray_to_rgb PNGARG((png_row_infop row_info,
  161989. png_bytep row));
  161990. #endif
  161991. #if defined(PNG_READ_PACK_SUPPORTED)
  161992. PNG_EXTERN void png_do_unpack PNGARG((png_row_infop row_info, png_bytep row));
  161993. #endif
  161994. #if defined(PNG_READ_SHIFT_SUPPORTED)
  161995. PNG_EXTERN void png_do_unshift PNGARG((png_row_infop row_info, png_bytep row,
  161996. png_color_8p sig_bits));
  161997. #endif
  161998. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  161999. PNG_EXTERN void png_do_invert PNGARG((png_row_infop row_info, png_bytep row));
  162000. #endif
  162001. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  162002. PNG_EXTERN void png_do_chop PNGARG((png_row_infop row_info, png_bytep row));
  162003. #endif
  162004. #if defined(PNG_READ_DITHER_SUPPORTED)
  162005. PNG_EXTERN void png_do_dither PNGARG((png_row_infop row_info,
  162006. png_bytep row, png_bytep palette_lookup, png_bytep dither_lookup));
  162007. # if defined(PNG_CORRECT_PALETTE_SUPPORTED)
  162008. PNG_EXTERN void png_correct_palette PNGARG((png_structp png_ptr,
  162009. png_colorp palette, int num_palette));
  162010. # endif
  162011. #endif
  162012. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  162013. PNG_EXTERN void png_do_bgr PNGARG((png_row_infop row_info, png_bytep row));
  162014. #endif
  162015. #if defined(PNG_WRITE_PACK_SUPPORTED)
  162016. PNG_EXTERN void png_do_pack PNGARG((png_row_infop row_info,
  162017. png_bytep row, png_uint_32 bit_depth));
  162018. #endif
  162019. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  162020. PNG_EXTERN void png_do_shift PNGARG((png_row_infop row_info, png_bytep row,
  162021. png_color_8p bit_depth));
  162022. #endif
  162023. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  162024. #if defined(PNG_READ_GAMMA_SUPPORTED)
  162025. PNG_EXTERN void png_do_background PNGARG((png_row_infop row_info, png_bytep row,
  162026. png_color_16p trans_values, png_color_16p background,
  162027. png_color_16p background_1,
  162028. png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1,
  162029. png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1,
  162030. png_uint_16pp gamma_16_to_1, int gamma_shift));
  162031. #else
  162032. PNG_EXTERN void png_do_background PNGARG((png_row_infop row_info, png_bytep row,
  162033. png_color_16p trans_values, png_color_16p background));
  162034. #endif
  162035. #endif
  162036. #if defined(PNG_READ_GAMMA_SUPPORTED)
  162037. PNG_EXTERN void png_do_gamma PNGARG((png_row_infop row_info, png_bytep row,
  162038. png_bytep gamma_table, png_uint_16pp gamma_16_table,
  162039. int gamma_shift));
  162040. #endif
  162041. #if defined(PNG_READ_EXPAND_SUPPORTED)
  162042. PNG_EXTERN void png_do_expand_palette PNGARG((png_row_infop row_info,
  162043. png_bytep row, png_colorp palette, png_bytep trans, int num_trans));
  162044. PNG_EXTERN void png_do_expand PNGARG((png_row_infop row_info,
  162045. png_bytep row, png_color_16p trans_value));
  162046. #endif
  162047. PNG_EXTERN void png_handle_IHDR PNGARG((png_structp png_ptr, png_infop info_ptr,
  162048. png_uint_32 length));
  162049. PNG_EXTERN void png_handle_PLTE PNGARG((png_structp png_ptr, png_infop info_ptr,
  162050. png_uint_32 length));
  162051. PNG_EXTERN void png_handle_IEND PNGARG((png_structp png_ptr, png_infop info_ptr,
  162052. png_uint_32 length));
  162053. #if defined(PNG_READ_bKGD_SUPPORTED)
  162054. PNG_EXTERN void png_handle_bKGD PNGARG((png_structp png_ptr, png_infop info_ptr,
  162055. png_uint_32 length));
  162056. #endif
  162057. #if defined(PNG_READ_cHRM_SUPPORTED)
  162058. PNG_EXTERN void png_handle_cHRM PNGARG((png_structp png_ptr, png_infop info_ptr,
  162059. png_uint_32 length));
  162060. #endif
  162061. #if defined(PNG_READ_gAMA_SUPPORTED)
  162062. PNG_EXTERN void png_handle_gAMA PNGARG((png_structp png_ptr, png_infop info_ptr,
  162063. png_uint_32 length));
  162064. #endif
  162065. #if defined(PNG_READ_hIST_SUPPORTED)
  162066. PNG_EXTERN void png_handle_hIST PNGARG((png_structp png_ptr, png_infop info_ptr,
  162067. png_uint_32 length));
  162068. #endif
  162069. #if defined(PNG_READ_iCCP_SUPPORTED)
  162070. extern void png_handle_iCCP PNGARG((png_structp png_ptr, png_infop info_ptr,
  162071. png_uint_32 length));
  162072. #endif /* PNG_READ_iCCP_SUPPORTED */
  162073. #if defined(PNG_READ_iTXt_SUPPORTED)
  162074. PNG_EXTERN void png_handle_iTXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  162075. png_uint_32 length));
  162076. #endif
  162077. #if defined(PNG_READ_oFFs_SUPPORTED)
  162078. PNG_EXTERN void png_handle_oFFs PNGARG((png_structp png_ptr, png_infop info_ptr,
  162079. png_uint_32 length));
  162080. #endif
  162081. #if defined(PNG_READ_pCAL_SUPPORTED)
  162082. PNG_EXTERN void png_handle_pCAL PNGARG((png_structp png_ptr, png_infop info_ptr,
  162083. png_uint_32 length));
  162084. #endif
  162085. #if defined(PNG_READ_pHYs_SUPPORTED)
  162086. PNG_EXTERN void png_handle_pHYs PNGARG((png_structp png_ptr, png_infop info_ptr,
  162087. png_uint_32 length));
  162088. #endif
  162089. #if defined(PNG_READ_sBIT_SUPPORTED)
  162090. PNG_EXTERN void png_handle_sBIT PNGARG((png_structp png_ptr, png_infop info_ptr,
  162091. png_uint_32 length));
  162092. #endif
  162093. #if defined(PNG_READ_sCAL_SUPPORTED)
  162094. PNG_EXTERN void png_handle_sCAL PNGARG((png_structp png_ptr, png_infop info_ptr,
  162095. png_uint_32 length));
  162096. #endif
  162097. #if defined(PNG_READ_sPLT_SUPPORTED)
  162098. extern void png_handle_sPLT PNGARG((png_structp png_ptr, png_infop info_ptr,
  162099. png_uint_32 length));
  162100. #endif /* PNG_READ_sPLT_SUPPORTED */
  162101. #if defined(PNG_READ_sRGB_SUPPORTED)
  162102. PNG_EXTERN void png_handle_sRGB PNGARG((png_structp png_ptr, png_infop info_ptr,
  162103. png_uint_32 length));
  162104. #endif
  162105. #if defined(PNG_READ_tEXt_SUPPORTED)
  162106. PNG_EXTERN void png_handle_tEXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  162107. png_uint_32 length));
  162108. #endif
  162109. #if defined(PNG_READ_tIME_SUPPORTED)
  162110. PNG_EXTERN void png_handle_tIME PNGARG((png_structp png_ptr, png_infop info_ptr,
  162111. png_uint_32 length));
  162112. #endif
  162113. #if defined(PNG_READ_tRNS_SUPPORTED)
  162114. PNG_EXTERN void png_handle_tRNS PNGARG((png_structp png_ptr, png_infop info_ptr,
  162115. png_uint_32 length));
  162116. #endif
  162117. #if defined(PNG_READ_zTXt_SUPPORTED)
  162118. PNG_EXTERN void png_handle_zTXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  162119. png_uint_32 length));
  162120. #endif
  162121. PNG_EXTERN void png_handle_unknown PNGARG((png_structp png_ptr,
  162122. png_infop info_ptr, png_uint_32 length));
  162123. PNG_EXTERN void png_check_chunk_name PNGARG((png_structp png_ptr,
  162124. png_bytep chunk_name));
  162125. PNG_EXTERN void png_do_read_transformations PNGARG((png_structp png_ptr));
  162126. PNG_EXTERN void png_do_write_transformations PNGARG((png_structp png_ptr));
  162127. PNG_EXTERN void png_init_read_transformations PNGARG((png_structp png_ptr));
  162128. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  162129. PNG_EXTERN void png_push_read_chunk PNGARG((png_structp png_ptr,
  162130. png_infop info_ptr));
  162131. PNG_EXTERN void png_push_read_sig PNGARG((png_structp png_ptr,
  162132. png_infop info_ptr));
  162133. PNG_EXTERN void png_push_check_crc PNGARG((png_structp png_ptr));
  162134. PNG_EXTERN void png_push_crc_skip PNGARG((png_structp png_ptr,
  162135. png_uint_32 length));
  162136. PNG_EXTERN void png_push_crc_finish PNGARG((png_structp png_ptr));
  162137. PNG_EXTERN void png_push_save_buffer PNGARG((png_structp png_ptr));
  162138. PNG_EXTERN void png_push_restore_buffer PNGARG((png_structp png_ptr,
  162139. png_bytep buffer, png_size_t buffer_length));
  162140. PNG_EXTERN void png_push_read_IDAT PNGARG((png_structp png_ptr));
  162141. PNG_EXTERN void png_process_IDAT_data PNGARG((png_structp png_ptr,
  162142. png_bytep buffer, png_size_t buffer_length));
  162143. PNG_EXTERN void png_push_process_row PNGARG((png_structp png_ptr));
  162144. PNG_EXTERN void png_push_handle_unknown PNGARG((png_structp png_ptr,
  162145. png_infop info_ptr, png_uint_32 length));
  162146. PNG_EXTERN void png_push_have_info PNGARG((png_structp png_ptr,
  162147. png_infop info_ptr));
  162148. PNG_EXTERN void png_push_have_end PNGARG((png_structp png_ptr,
  162149. png_infop info_ptr));
  162150. PNG_EXTERN void png_push_have_row PNGARG((png_structp png_ptr, png_bytep row));
  162151. PNG_EXTERN void png_push_read_end PNGARG((png_structp png_ptr,
  162152. png_infop info_ptr));
  162153. PNG_EXTERN void png_process_some_data PNGARG((png_structp png_ptr,
  162154. png_infop info_ptr));
  162155. PNG_EXTERN void png_read_push_finish_row PNGARG((png_structp png_ptr));
  162156. #if defined(PNG_READ_tEXt_SUPPORTED)
  162157. PNG_EXTERN void png_push_handle_tEXt PNGARG((png_structp png_ptr,
  162158. png_infop info_ptr, png_uint_32 length));
  162159. PNG_EXTERN void png_push_read_tEXt PNGARG((png_structp png_ptr,
  162160. png_infop info_ptr));
  162161. #endif
  162162. #if defined(PNG_READ_zTXt_SUPPORTED)
  162163. PNG_EXTERN void png_push_handle_zTXt PNGARG((png_structp png_ptr,
  162164. png_infop info_ptr, png_uint_32 length));
  162165. PNG_EXTERN void png_push_read_zTXt PNGARG((png_structp png_ptr,
  162166. png_infop info_ptr));
  162167. #endif
  162168. #if defined(PNG_READ_iTXt_SUPPORTED)
  162169. PNG_EXTERN void png_push_handle_iTXt PNGARG((png_structp png_ptr,
  162170. png_infop info_ptr, png_uint_32 length));
  162171. PNG_EXTERN void png_push_read_iTXt PNGARG((png_structp png_ptr,
  162172. png_infop info_ptr));
  162173. #endif
  162174. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  162175. #ifdef PNG_MNG_FEATURES_SUPPORTED
  162176. PNG_EXTERN void png_do_read_intrapixel PNGARG((png_row_infop row_info,
  162177. png_bytep row));
  162178. PNG_EXTERN void png_do_write_intrapixel PNGARG((png_row_infop row_info,
  162179. png_bytep row));
  162180. #endif
  162181. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  162182. #if defined(PNG_MMX_CODE_SUPPORTED)
  162183. /* PRIVATE */
  162184. PNG_EXTERN void png_init_mmx_flags PNGARG((png_structp png_ptr));
  162185. #endif
  162186. #endif
  162187. #if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED)
  162188. PNG_EXTERN png_uint_32 png_get_pixels_per_inch PNGARG((png_structp png_ptr,
  162189. png_infop info_ptr));
  162190. PNG_EXTERN png_uint_32 png_get_x_pixels_per_inch PNGARG((png_structp png_ptr,
  162191. png_infop info_ptr));
  162192. PNG_EXTERN png_uint_32 png_get_y_pixels_per_inch PNGARG((png_structp png_ptr,
  162193. png_infop info_ptr));
  162194. PNG_EXTERN float png_get_x_offset_inches PNGARG((png_structp png_ptr,
  162195. png_infop info_ptr));
  162196. PNG_EXTERN float png_get_y_offset_inches PNGARG((png_structp png_ptr,
  162197. png_infop info_ptr));
  162198. #if defined(PNG_pHYs_SUPPORTED)
  162199. PNG_EXTERN png_uint_32 png_get_pHYs_dpi PNGARG((png_structp png_ptr,
  162200. png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type));
  162201. #endif /* PNG_pHYs_SUPPORTED */
  162202. #endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */
  162203. #endif /* PNG_INTERNAL */
  162204. #ifdef __cplusplus
  162205. }
  162206. #endif
  162207. #endif /* PNG_VERSION_INFO_ONLY */
  162208. #endif /* PNG_H */
  162209. /*** End of inlined file: png.h ***/
  162210. #define PNG_NO_EXTERN
  162211. /*** Start of inlined file: png.c ***/
  162212. #define PNG_INTERNAL
  162213. #define PNG_NO_EXTERN
  162214. typedef version_1_2_21 Your_png_h_is_not_version_1_2_21;
  162215. #ifdef PNG_USE_GLOBAL_ARRAYS
  162216. PNG_CONST char png_libpng_ver[18] = PNG_LIBPNG_VER_STRING;
  162217. #ifdef PNG_READ_SUPPORTED
  162218. PNG_CONST png_byte FARDATA png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  162219. #endif /* PNG_READ_SUPPORTED */
  162220. PNG_IHDR;
  162221. PNG_IDAT;
  162222. PNG_IEND;
  162223. PNG_PLTE;
  162224. PNG_bKGD;
  162225. PNG_cHRM;
  162226. PNG_gAMA;
  162227. PNG_hIST;
  162228. PNG_iCCP;
  162229. PNG_iTXt;
  162230. PNG_oFFs;
  162231. PNG_pCAL;
  162232. PNG_sCAL;
  162233. PNG_pHYs;
  162234. PNG_sBIT;
  162235. PNG_sPLT;
  162236. PNG_sRGB;
  162237. PNG_tEXt;
  162238. PNG_tIME;
  162239. PNG_tRNS;
  162240. PNG_zTXt;
  162241. #ifdef PNG_READ_SUPPORTED
  162242. PNG_CONST int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
  162243. PNG_CONST int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
  162244. PNG_CONST int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
  162245. PNG_CONST int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
  162246. PNG_CONST int FARDATA png_pass_mask[] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
  162247. PNG_CONST int FARDATA png_pass_dsp_mask[]
  162248. = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
  162249. #endif /* PNG_READ_SUPPORTED */
  162250. #endif /* PNG_USE_GLOBAL_ARRAYS */
  162251. #ifdef PNG_READ_SUPPORTED
  162252. void PNGAPI
  162253. png_set_sig_bytes(png_structp png_ptr, int num_bytes)
  162254. {
  162255. if(png_ptr == NULL) return;
  162256. png_debug(1, "in png_set_sig_bytes\n");
  162257. if (num_bytes > 8)
  162258. png_error(png_ptr, "Too many bytes for PNG signature.");
  162259. png_ptr->sig_bytes = (png_byte)(num_bytes < 0 ? 0 : num_bytes);
  162260. }
  162261. int PNGAPI
  162262. png_sig_cmp(png_bytep sig, png_size_t start, png_size_t num_to_check)
  162263. {
  162264. png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  162265. if (num_to_check > 8)
  162266. num_to_check = 8;
  162267. else if (num_to_check < 1)
  162268. return (-1);
  162269. if (start > 7)
  162270. return (-1);
  162271. if (start + num_to_check > 8)
  162272. num_to_check = 8 - start;
  162273. return ((int)(png_memcmp(&sig[start], &png_signature[start], num_to_check)));
  162274. }
  162275. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  162276. int PNGAPI
  162277. png_check_sig(png_bytep sig, int num)
  162278. {
  162279. return ((int)!png_sig_cmp(sig, (png_size_t)0, (png_size_t)num));
  162280. }
  162281. #endif
  162282. #endif /* PNG_READ_SUPPORTED */
  162283. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162284. #ifdef PNG_1_0_X
  162285. voidpf PNGAPI
  162286. #else
  162287. voidpf /* private */
  162288. #endif
  162289. png_zalloc(voidpf png_ptr, uInt items, uInt size)
  162290. {
  162291. png_voidp ptr;
  162292. png_structp p=(png_structp)png_ptr;
  162293. png_uint_32 save_flags=p->flags;
  162294. png_uint_32 num_bytes;
  162295. if(png_ptr == NULL) return (NULL);
  162296. if (items > PNG_UINT_32_MAX/size)
  162297. {
  162298. png_warning (p, "Potential overflow in png_zalloc()");
  162299. return (NULL);
  162300. }
  162301. num_bytes = (png_uint_32)items * size;
  162302. p->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
  162303. ptr = (png_voidp)png_malloc((png_structp)png_ptr, num_bytes);
  162304. p->flags=save_flags;
  162305. #if defined(PNG_1_0_X) && !defined(PNG_NO_ZALLOC_ZERO)
  162306. if (ptr == NULL)
  162307. return ((voidpf)ptr);
  162308. if (num_bytes > (png_uint_32)0x8000L)
  162309. {
  162310. png_memset(ptr, 0, (png_size_t)0x8000L);
  162311. png_memset((png_bytep)ptr + (png_size_t)0x8000L, 0,
  162312. (png_size_t)(num_bytes - (png_uint_32)0x8000L));
  162313. }
  162314. else
  162315. {
  162316. png_memset(ptr, 0, (png_size_t)num_bytes);
  162317. }
  162318. #endif
  162319. return ((voidpf)ptr);
  162320. }
  162321. #ifdef PNG_1_0_X
  162322. void PNGAPI
  162323. #else
  162324. void /* private */
  162325. #endif
  162326. png_zfree(voidpf png_ptr, voidpf ptr)
  162327. {
  162328. png_free((png_structp)png_ptr, (png_voidp)ptr);
  162329. }
  162330. void /* PRIVATE */
  162331. png_reset_crc(png_structp png_ptr)
  162332. {
  162333. png_ptr->crc = crc32(0, Z_NULL, 0);
  162334. }
  162335. void /* PRIVATE */
  162336. png_calculate_crc(png_structp png_ptr, png_bytep ptr, png_size_t length)
  162337. {
  162338. int need_crc = 1;
  162339. if (png_ptr->chunk_name[0] & 0x20) /* ancillary */
  162340. {
  162341. if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
  162342. (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
  162343. need_crc = 0;
  162344. }
  162345. else /* critical */
  162346. {
  162347. if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE)
  162348. need_crc = 0;
  162349. }
  162350. if (need_crc)
  162351. png_ptr->crc = crc32(png_ptr->crc, ptr, (uInt)length);
  162352. }
  162353. png_infop PNGAPI
  162354. png_create_info_struct(png_structp png_ptr)
  162355. {
  162356. png_infop info_ptr;
  162357. png_debug(1, "in png_create_info_struct\n");
  162358. if(png_ptr == NULL) return (NULL);
  162359. #ifdef PNG_USER_MEM_SUPPORTED
  162360. info_ptr = (png_infop)png_create_struct_2(PNG_STRUCT_INFO,
  162361. png_ptr->malloc_fn, png_ptr->mem_ptr);
  162362. #else
  162363. info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
  162364. #endif
  162365. if (info_ptr != NULL)
  162366. png_info_init_3(&info_ptr, png_sizeof(png_info));
  162367. return (info_ptr);
  162368. }
  162369. void PNGAPI
  162370. png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr)
  162371. {
  162372. png_infop info_ptr = NULL;
  162373. if(png_ptr == NULL) return;
  162374. png_debug(1, "in png_destroy_info_struct\n");
  162375. if (info_ptr_ptr != NULL)
  162376. info_ptr = *info_ptr_ptr;
  162377. if (info_ptr != NULL)
  162378. {
  162379. png_info_destroy(png_ptr, info_ptr);
  162380. #ifdef PNG_USER_MEM_SUPPORTED
  162381. png_destroy_struct_2((png_voidp)info_ptr, png_ptr->free_fn,
  162382. png_ptr->mem_ptr);
  162383. #else
  162384. png_destroy_struct((png_voidp)info_ptr);
  162385. #endif
  162386. *info_ptr_ptr = NULL;
  162387. }
  162388. }
  162389. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  162390. #undef png_info_init
  162391. void PNGAPI
  162392. png_info_init(png_infop info_ptr)
  162393. {
  162394. png_info_init_3(&info_ptr, 0);
  162395. }
  162396. #endif
  162397. void PNGAPI
  162398. png_info_init_3(png_infopp ptr_ptr, png_size_t png_info_struct_size)
  162399. {
  162400. png_infop info_ptr = *ptr_ptr;
  162401. if(info_ptr == NULL) return;
  162402. png_debug(1, "in png_info_init_3\n");
  162403. if(png_sizeof(png_info) > png_info_struct_size)
  162404. {
  162405. png_destroy_struct(info_ptr);
  162406. info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
  162407. *ptr_ptr = info_ptr;
  162408. }
  162409. png_memset(info_ptr, 0, png_sizeof (png_info));
  162410. }
  162411. #ifdef PNG_FREE_ME_SUPPORTED
  162412. void PNGAPI
  162413. png_data_freer(png_structp png_ptr, png_infop info_ptr,
  162414. int freer, png_uint_32 mask)
  162415. {
  162416. png_debug(1, "in png_data_freer\n");
  162417. if (png_ptr == NULL || info_ptr == NULL)
  162418. return;
  162419. if(freer == PNG_DESTROY_WILL_FREE_DATA)
  162420. info_ptr->free_me |= mask;
  162421. else if(freer == PNG_USER_WILL_FREE_DATA)
  162422. info_ptr->free_me &= ~mask;
  162423. else
  162424. png_warning(png_ptr,
  162425. "Unknown freer parameter in png_data_freer.");
  162426. }
  162427. #endif
  162428. void PNGAPI
  162429. png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask,
  162430. int num)
  162431. {
  162432. png_debug(1, "in png_free_data\n");
  162433. if (png_ptr == NULL || info_ptr == NULL)
  162434. return;
  162435. #if defined(PNG_TEXT_SUPPORTED)
  162436. #ifdef PNG_FREE_ME_SUPPORTED
  162437. if ((mask & PNG_FREE_TEXT) & info_ptr->free_me)
  162438. #else
  162439. if (mask & PNG_FREE_TEXT)
  162440. #endif
  162441. {
  162442. if (num != -1)
  162443. {
  162444. if (info_ptr->text && info_ptr->text[num].key)
  162445. {
  162446. png_free(png_ptr, info_ptr->text[num].key);
  162447. info_ptr->text[num].key = NULL;
  162448. }
  162449. }
  162450. else
  162451. {
  162452. int i;
  162453. for (i = 0; i < info_ptr->num_text; i++)
  162454. png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, i);
  162455. png_free(png_ptr, info_ptr->text);
  162456. info_ptr->text = NULL;
  162457. info_ptr->num_text=0;
  162458. }
  162459. }
  162460. #endif
  162461. #if defined(PNG_tRNS_SUPPORTED)
  162462. #ifdef PNG_FREE_ME_SUPPORTED
  162463. if ((mask & PNG_FREE_TRNS) & info_ptr->free_me)
  162464. #else
  162465. if ((mask & PNG_FREE_TRNS) && (png_ptr->flags & PNG_FLAG_FREE_TRNS))
  162466. #endif
  162467. {
  162468. png_free(png_ptr, info_ptr->trans);
  162469. info_ptr->valid &= ~PNG_INFO_tRNS;
  162470. #ifndef PNG_FREE_ME_SUPPORTED
  162471. png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
  162472. #endif
  162473. info_ptr->trans = NULL;
  162474. }
  162475. #endif
  162476. #if defined(PNG_sCAL_SUPPORTED)
  162477. #ifdef PNG_FREE_ME_SUPPORTED
  162478. if ((mask & PNG_FREE_SCAL) & info_ptr->free_me)
  162479. #else
  162480. if (mask & PNG_FREE_SCAL)
  162481. #endif
  162482. {
  162483. #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
  162484. png_free(png_ptr, info_ptr->scal_s_width);
  162485. png_free(png_ptr, info_ptr->scal_s_height);
  162486. info_ptr->scal_s_width = NULL;
  162487. info_ptr->scal_s_height = NULL;
  162488. #endif
  162489. info_ptr->valid &= ~PNG_INFO_sCAL;
  162490. }
  162491. #endif
  162492. #if defined(PNG_pCAL_SUPPORTED)
  162493. #ifdef PNG_FREE_ME_SUPPORTED
  162494. if ((mask & PNG_FREE_PCAL) & info_ptr->free_me)
  162495. #else
  162496. if (mask & PNG_FREE_PCAL)
  162497. #endif
  162498. {
  162499. png_free(png_ptr, info_ptr->pcal_purpose);
  162500. png_free(png_ptr, info_ptr->pcal_units);
  162501. info_ptr->pcal_purpose = NULL;
  162502. info_ptr->pcal_units = NULL;
  162503. if (info_ptr->pcal_params != NULL)
  162504. {
  162505. int i;
  162506. for (i = 0; i < (int)info_ptr->pcal_nparams; i++)
  162507. {
  162508. png_free(png_ptr, info_ptr->pcal_params[i]);
  162509. info_ptr->pcal_params[i]=NULL;
  162510. }
  162511. png_free(png_ptr, info_ptr->pcal_params);
  162512. info_ptr->pcal_params = NULL;
  162513. }
  162514. info_ptr->valid &= ~PNG_INFO_pCAL;
  162515. }
  162516. #endif
  162517. #if defined(PNG_iCCP_SUPPORTED)
  162518. #ifdef PNG_FREE_ME_SUPPORTED
  162519. if ((mask & PNG_FREE_ICCP) & info_ptr->free_me)
  162520. #else
  162521. if (mask & PNG_FREE_ICCP)
  162522. #endif
  162523. {
  162524. png_free(png_ptr, info_ptr->iccp_name);
  162525. png_free(png_ptr, info_ptr->iccp_profile);
  162526. info_ptr->iccp_name = NULL;
  162527. info_ptr->iccp_profile = NULL;
  162528. info_ptr->valid &= ~PNG_INFO_iCCP;
  162529. }
  162530. #endif
  162531. #if defined(PNG_sPLT_SUPPORTED)
  162532. #ifdef PNG_FREE_ME_SUPPORTED
  162533. if ((mask & PNG_FREE_SPLT) & info_ptr->free_me)
  162534. #else
  162535. if (mask & PNG_FREE_SPLT)
  162536. #endif
  162537. {
  162538. if (num != -1)
  162539. {
  162540. if(info_ptr->splt_palettes)
  162541. {
  162542. png_free(png_ptr, info_ptr->splt_palettes[num].name);
  162543. png_free(png_ptr, info_ptr->splt_palettes[num].entries);
  162544. info_ptr->splt_palettes[num].name = NULL;
  162545. info_ptr->splt_palettes[num].entries = NULL;
  162546. }
  162547. }
  162548. else
  162549. {
  162550. if(info_ptr->splt_palettes_num)
  162551. {
  162552. int i;
  162553. for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
  162554. png_free_data(png_ptr, info_ptr, PNG_FREE_SPLT, i);
  162555. png_free(png_ptr, info_ptr->splt_palettes);
  162556. info_ptr->splt_palettes = NULL;
  162557. info_ptr->splt_palettes_num = 0;
  162558. }
  162559. info_ptr->valid &= ~PNG_INFO_sPLT;
  162560. }
  162561. }
  162562. #endif
  162563. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  162564. if(png_ptr->unknown_chunk.data)
  162565. {
  162566. png_free(png_ptr, png_ptr->unknown_chunk.data);
  162567. png_ptr->unknown_chunk.data = NULL;
  162568. }
  162569. #ifdef PNG_FREE_ME_SUPPORTED
  162570. if ((mask & PNG_FREE_UNKN) & info_ptr->free_me)
  162571. #else
  162572. if (mask & PNG_FREE_UNKN)
  162573. #endif
  162574. {
  162575. if (num != -1)
  162576. {
  162577. if(info_ptr->unknown_chunks)
  162578. {
  162579. png_free(png_ptr, info_ptr->unknown_chunks[num].data);
  162580. info_ptr->unknown_chunks[num].data = NULL;
  162581. }
  162582. }
  162583. else
  162584. {
  162585. int i;
  162586. if(info_ptr->unknown_chunks_num)
  162587. {
  162588. for (i = 0; i < (int)info_ptr->unknown_chunks_num; i++)
  162589. png_free_data(png_ptr, info_ptr, PNG_FREE_UNKN, i);
  162590. png_free(png_ptr, info_ptr->unknown_chunks);
  162591. info_ptr->unknown_chunks = NULL;
  162592. info_ptr->unknown_chunks_num = 0;
  162593. }
  162594. }
  162595. }
  162596. #endif
  162597. #if defined(PNG_hIST_SUPPORTED)
  162598. #ifdef PNG_FREE_ME_SUPPORTED
  162599. if ((mask & PNG_FREE_HIST) & info_ptr->free_me)
  162600. #else
  162601. if ((mask & PNG_FREE_HIST) && (png_ptr->flags & PNG_FLAG_FREE_HIST))
  162602. #endif
  162603. {
  162604. png_free(png_ptr, info_ptr->hist);
  162605. info_ptr->hist = NULL;
  162606. info_ptr->valid &= ~PNG_INFO_hIST;
  162607. #ifndef PNG_FREE_ME_SUPPORTED
  162608. png_ptr->flags &= ~PNG_FLAG_FREE_HIST;
  162609. #endif
  162610. }
  162611. #endif
  162612. #ifdef PNG_FREE_ME_SUPPORTED
  162613. if ((mask & PNG_FREE_PLTE) & info_ptr->free_me)
  162614. #else
  162615. if ((mask & PNG_FREE_PLTE) && (png_ptr->flags & PNG_FLAG_FREE_PLTE))
  162616. #endif
  162617. {
  162618. png_zfree(png_ptr, info_ptr->palette);
  162619. info_ptr->palette = NULL;
  162620. info_ptr->valid &= ~PNG_INFO_PLTE;
  162621. #ifndef PNG_FREE_ME_SUPPORTED
  162622. png_ptr->flags &= ~PNG_FLAG_FREE_PLTE;
  162623. #endif
  162624. info_ptr->num_palette = 0;
  162625. }
  162626. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  162627. #ifdef PNG_FREE_ME_SUPPORTED
  162628. if ((mask & PNG_FREE_ROWS) & info_ptr->free_me)
  162629. #else
  162630. if (mask & PNG_FREE_ROWS)
  162631. #endif
  162632. {
  162633. if(info_ptr->row_pointers)
  162634. {
  162635. int row;
  162636. for (row = 0; row < (int)info_ptr->height; row++)
  162637. {
  162638. png_free(png_ptr, info_ptr->row_pointers[row]);
  162639. info_ptr->row_pointers[row]=NULL;
  162640. }
  162641. png_free(png_ptr, info_ptr->row_pointers);
  162642. info_ptr->row_pointers=NULL;
  162643. }
  162644. info_ptr->valid &= ~PNG_INFO_IDAT;
  162645. }
  162646. #endif
  162647. #ifdef PNG_FREE_ME_SUPPORTED
  162648. if(num == -1)
  162649. info_ptr->free_me &= ~mask;
  162650. else
  162651. info_ptr->free_me &= ~(mask & ~PNG_FREE_MUL);
  162652. #endif
  162653. }
  162654. void /* PRIVATE */
  162655. png_info_destroy(png_structp png_ptr, png_infop info_ptr)
  162656. {
  162657. png_debug(1, "in png_info_destroy\n");
  162658. png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
  162659. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  162660. if (png_ptr->num_chunk_list)
  162661. {
  162662. png_free(png_ptr, png_ptr->chunk_list);
  162663. png_ptr->chunk_list=NULL;
  162664. png_ptr->num_chunk_list=0;
  162665. }
  162666. #endif
  162667. png_info_init_3(&info_ptr, png_sizeof(png_info));
  162668. }
  162669. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  162670. png_voidp PNGAPI
  162671. png_get_io_ptr(png_structp png_ptr)
  162672. {
  162673. if(png_ptr == NULL) return (NULL);
  162674. return (png_ptr->io_ptr);
  162675. }
  162676. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162677. #if !defined(PNG_NO_STDIO)
  162678. void PNGAPI
  162679. png_init_io(png_structp png_ptr, png_FILE_p fp)
  162680. {
  162681. png_debug(1, "in png_init_io\n");
  162682. if(png_ptr == NULL) return;
  162683. png_ptr->io_ptr = (png_voidp)fp;
  162684. }
  162685. #endif
  162686. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  162687. png_charp PNGAPI
  162688. png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime)
  162689. {
  162690. static PNG_CONST char short_months[12][4] =
  162691. {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
  162692. "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
  162693. if(png_ptr == NULL) return (NULL);
  162694. if (png_ptr->time_buffer == NULL)
  162695. {
  162696. png_ptr->time_buffer = (png_charp)png_malloc(png_ptr, (png_uint_32)(29*
  162697. png_sizeof(char)));
  162698. }
  162699. #if defined(_WIN32_WCE)
  162700. {
  162701. wchar_t time_buf[29];
  162702. wsprintf(time_buf, TEXT("%d %S %d %02d:%02d:%02d +0000"),
  162703. ptime->day % 32, short_months[(ptime->month - 1) % 12],
  162704. ptime->year, ptime->hour % 24, ptime->minute % 60,
  162705. ptime->second % 61);
  162706. WideCharToMultiByte(CP_ACP, 0, time_buf, -1, png_ptr->time_buffer, 29,
  162707. NULL, NULL);
  162708. }
  162709. #else
  162710. #ifdef USE_FAR_KEYWORD
  162711. {
  162712. char near_time_buf[29];
  162713. png_snprintf6(near_time_buf,29,"%d %s %d %02d:%02d:%02d +0000",
  162714. ptime->day % 32, short_months[(ptime->month - 1) % 12],
  162715. ptime->year, ptime->hour % 24, ptime->minute % 60,
  162716. ptime->second % 61);
  162717. png_memcpy(png_ptr->time_buffer, near_time_buf,
  162718. 29*png_sizeof(char));
  162719. }
  162720. #else
  162721. png_snprintf6(png_ptr->time_buffer,29,"%d %s %d %02d:%02d:%02d +0000",
  162722. ptime->day % 32, short_months[(ptime->month - 1) % 12],
  162723. ptime->year, ptime->hour % 24, ptime->minute % 60,
  162724. ptime->second % 61);
  162725. #endif
  162726. #endif /* _WIN32_WCE */
  162727. return ((png_charp)png_ptr->time_buffer);
  162728. }
  162729. #endif /* PNG_TIME_RFC1123_SUPPORTED */
  162730. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  162731. png_charp PNGAPI
  162732. png_get_copyright(png_structp png_ptr)
  162733. {
  162734. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  162735. return ((png_charp) "\n libpng version 1.2.21 - October 4, 2007\n\
  162736. Copyright (c) 1998-2007 Glenn Randers-Pehrson\n\
  162737. Copyright (c) 1996-1997 Andreas Dilger\n\
  162738. Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.\n");
  162739. }
  162740. png_charp PNGAPI
  162741. png_get_libpng_ver(png_structp png_ptr)
  162742. {
  162743. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  162744. return ((png_charp) PNG_LIBPNG_VER_STRING);
  162745. }
  162746. png_charp PNGAPI
  162747. png_get_header_ver(png_structp png_ptr)
  162748. {
  162749. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  162750. return ((png_charp) PNG_LIBPNG_VER_STRING);
  162751. }
  162752. png_charp PNGAPI
  162753. png_get_header_version(png_structp png_ptr)
  162754. {
  162755. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  162756. return ((png_charp) PNG_HEADER_VERSION_STRING
  162757. #ifndef PNG_READ_SUPPORTED
  162758. " (NO READ SUPPORT)"
  162759. #endif
  162760. "\n");
  162761. }
  162762. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162763. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  162764. int PNGAPI
  162765. png_handle_as_unknown(png_structp png_ptr, png_bytep chunk_name)
  162766. {
  162767. int i;
  162768. png_bytep p;
  162769. if(png_ptr == NULL || chunk_name == NULL || png_ptr->num_chunk_list<=0)
  162770. return 0;
  162771. p=png_ptr->chunk_list+png_ptr->num_chunk_list*5-5;
  162772. for (i = png_ptr->num_chunk_list; i; i--, p-=5)
  162773. if (!png_memcmp(chunk_name, p, 4))
  162774. return ((int)*(p+4));
  162775. return 0;
  162776. }
  162777. #endif
  162778. int PNGAPI
  162779. png_reset_zstream(png_structp png_ptr)
  162780. {
  162781. if (png_ptr == NULL) return Z_STREAM_ERROR;
  162782. return (inflateReset(&png_ptr->zstream));
  162783. }
  162784. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  162785. png_uint_32 PNGAPI
  162786. png_access_version_number(void)
  162787. {
  162788. return((png_uint_32) PNG_LIBPNG_VER);
  162789. }
  162790. #if defined(PNG_READ_SUPPORTED) && defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  162791. #if !defined(PNG_1_0_X)
  162792. int PNGAPI
  162793. png_mmx_support(void)
  162794. {
  162795. return -1;
  162796. }
  162797. #endif /* PNG_1_0_X */
  162798. #endif /* PNG_READ_SUPPORTED && PNG_ASSEMBLER_CODE_SUPPORTED */
  162799. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162800. #ifdef PNG_SIZE_T
  162801. PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size));
  162802. png_size_t PNGAPI
  162803. png_convert_size(size_t size)
  162804. {
  162805. if (size > (png_size_t)-1)
  162806. PNG_ABORT(); /* We haven't got access to png_ptr, so no png_error() */
  162807. return ((png_size_t)size);
  162808. }
  162809. #endif /* PNG_SIZE_T */
  162810. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  162811. /*** End of inlined file: png.c ***/
  162812. /*** Start of inlined file: pngerror.c ***/
  162813. #define PNG_INTERNAL
  162814. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162815. static void /* PRIVATE */
  162816. png_default_error PNGARG((png_structp png_ptr,
  162817. png_const_charp error_message));
  162818. #ifndef PNG_NO_WARNINGS
  162819. static void /* PRIVATE */
  162820. png_default_warning PNGARG((png_structp png_ptr,
  162821. png_const_charp warning_message));
  162822. #endif /* PNG_NO_WARNINGS */
  162823. #ifndef PNG_NO_ERROR_TEXT
  162824. void PNGAPI
  162825. png_error(png_structp png_ptr, png_const_charp error_message)
  162826. {
  162827. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  162828. char msg[16];
  162829. if (png_ptr != NULL)
  162830. {
  162831. if (png_ptr->flags&
  162832. (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
  162833. {
  162834. if (*error_message == '#')
  162835. {
  162836. int offset;
  162837. for (offset=1; offset<15; offset++)
  162838. if (*(error_message+offset) == ' ')
  162839. break;
  162840. if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
  162841. {
  162842. int i;
  162843. for (i=0; i<offset-1; i++)
  162844. msg[i]=error_message[i+1];
  162845. msg[i]='\0';
  162846. error_message=msg;
  162847. }
  162848. else
  162849. error_message+=offset;
  162850. }
  162851. else
  162852. {
  162853. if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
  162854. {
  162855. msg[0]='0';
  162856. msg[1]='\0';
  162857. error_message=msg;
  162858. }
  162859. }
  162860. }
  162861. }
  162862. #endif
  162863. if (png_ptr != NULL && png_ptr->error_fn != NULL)
  162864. (*(png_ptr->error_fn))(png_ptr, error_message);
  162865. png_default_error(png_ptr, error_message);
  162866. }
  162867. #else
  162868. void PNGAPI
  162869. png_err(png_structp png_ptr)
  162870. {
  162871. if (png_ptr != NULL && png_ptr->error_fn != NULL)
  162872. (*(png_ptr->error_fn))(png_ptr, '\0');
  162873. png_default_error(png_ptr, '\0');
  162874. }
  162875. #endif /* PNG_NO_ERROR_TEXT */
  162876. #ifndef PNG_NO_WARNINGS
  162877. void PNGAPI
  162878. png_warning(png_structp png_ptr, png_const_charp warning_message)
  162879. {
  162880. int offset = 0;
  162881. if (png_ptr != NULL)
  162882. {
  162883. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  162884. if (png_ptr->flags&
  162885. (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
  162886. #endif
  162887. {
  162888. if (*warning_message == '#')
  162889. {
  162890. for (offset=1; offset<15; offset++)
  162891. if (*(warning_message+offset) == ' ')
  162892. break;
  162893. }
  162894. }
  162895. if (png_ptr != NULL && png_ptr->warning_fn != NULL)
  162896. (*(png_ptr->warning_fn))(png_ptr, warning_message+offset);
  162897. }
  162898. else
  162899. png_default_warning(png_ptr, warning_message+offset);
  162900. }
  162901. #endif /* PNG_NO_WARNINGS */
  162902. #define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
  162903. #if !defined(PNG_NO_WARNINGS) || !defined(PNG_NO_ERROR_TEXT)
  162904. static void /* PRIVATE */
  162905. png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp
  162906. error_message)
  162907. {
  162908. int iout = 0, iin = 0;
  162909. while (iin < 4)
  162910. {
  162911. int c = png_ptr->chunk_name[iin++];
  162912. if (isnonalpha(c))
  162913. {
  162914. buffer[iout++] = '[';
  162915. buffer[iout++] = png_digit[(c & 0xf0) >> 4];
  162916. buffer[iout++] = png_digit[c & 0x0f];
  162917. buffer[iout++] = ']';
  162918. }
  162919. else
  162920. {
  162921. buffer[iout++] = (png_byte)c;
  162922. }
  162923. }
  162924. if (error_message == NULL)
  162925. buffer[iout] = 0;
  162926. else
  162927. {
  162928. buffer[iout++] = ':';
  162929. buffer[iout++] = ' ';
  162930. png_strncpy(buffer+iout, error_message, 63);
  162931. buffer[iout+63] = 0;
  162932. }
  162933. }
  162934. #ifdef PNG_READ_SUPPORTED
  162935. void PNGAPI
  162936. png_chunk_error(png_structp png_ptr, png_const_charp error_message)
  162937. {
  162938. char msg[18+64];
  162939. if (png_ptr == NULL)
  162940. png_error(png_ptr, error_message);
  162941. else
  162942. {
  162943. png_format_buffer(png_ptr, msg, error_message);
  162944. png_error(png_ptr, msg);
  162945. }
  162946. }
  162947. #endif /* PNG_READ_SUPPORTED */
  162948. #endif /* !defined(PNG_NO_WARNINGS) || !defined(PNG_NO_ERROR_TEXT) */
  162949. #ifndef PNG_NO_WARNINGS
  162950. void PNGAPI
  162951. png_chunk_warning(png_structp png_ptr, png_const_charp warning_message)
  162952. {
  162953. char msg[18+64];
  162954. if (png_ptr == NULL)
  162955. png_warning(png_ptr, warning_message);
  162956. else
  162957. {
  162958. png_format_buffer(png_ptr, msg, warning_message);
  162959. png_warning(png_ptr, msg);
  162960. }
  162961. }
  162962. #endif /* PNG_NO_WARNINGS */
  162963. static void /* PRIVATE */
  162964. png_default_error(png_structp png_ptr, png_const_charp error_message)
  162965. {
  162966. #ifndef PNG_NO_CONSOLE_IO
  162967. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  162968. if (*error_message == '#')
  162969. {
  162970. int offset;
  162971. char error_number[16];
  162972. for (offset=0; offset<15; offset++)
  162973. {
  162974. error_number[offset] = *(error_message+offset+1);
  162975. if (*(error_message+offset) == ' ')
  162976. break;
  162977. }
  162978. if((offset > 1) && (offset < 15))
  162979. {
  162980. error_number[offset-1]='\0';
  162981. fprintf(stderr, "libpng error no. %s: %s\n", error_number,
  162982. error_message+offset);
  162983. }
  162984. else
  162985. fprintf(stderr, "libpng error: %s, offset=%d\n", error_message,offset);
  162986. }
  162987. else
  162988. #endif
  162989. fprintf(stderr, "libpng error: %s\n", error_message);
  162990. #endif
  162991. #ifdef PNG_SETJMP_SUPPORTED
  162992. if (png_ptr)
  162993. {
  162994. # ifdef USE_FAR_KEYWORD
  162995. {
  162996. jmp_buf jmpbuf;
  162997. png_memcpy(jmpbuf, png_ptr->jmpbuf, png_sizeof(jmp_buf));
  162998. longjmp(jmpbuf, 1);
  162999. }
  163000. # else
  163001. longjmp(png_ptr->jmpbuf, 1);
  163002. # endif
  163003. }
  163004. #else
  163005. PNG_ABORT();
  163006. #endif
  163007. #ifdef PNG_NO_CONSOLE_IO
  163008. error_message = error_message; /* make compiler happy */
  163009. #endif
  163010. }
  163011. #ifndef PNG_NO_WARNINGS
  163012. static void /* PRIVATE */
  163013. png_default_warning(png_structp png_ptr, png_const_charp warning_message)
  163014. {
  163015. #ifndef PNG_NO_CONSOLE_IO
  163016. # ifdef PNG_ERROR_NUMBERS_SUPPORTED
  163017. if (*warning_message == '#')
  163018. {
  163019. int offset;
  163020. char warning_number[16];
  163021. for (offset=0; offset<15; offset++)
  163022. {
  163023. warning_number[offset]=*(warning_message+offset+1);
  163024. if (*(warning_message+offset) == ' ')
  163025. break;
  163026. }
  163027. if((offset > 1) && (offset < 15))
  163028. {
  163029. warning_number[offset-1]='\0';
  163030. fprintf(stderr, "libpng warning no. %s: %s\n", warning_number,
  163031. warning_message+offset);
  163032. }
  163033. else
  163034. fprintf(stderr, "libpng warning: %s\n", warning_message);
  163035. }
  163036. else
  163037. # endif
  163038. fprintf(stderr, "libpng warning: %s\n", warning_message);
  163039. #else
  163040. warning_message = warning_message; /* make compiler happy */
  163041. #endif
  163042. png_ptr = png_ptr; /* make compiler happy */
  163043. }
  163044. #endif /* PNG_NO_WARNINGS */
  163045. void PNGAPI
  163046. png_set_error_fn(png_structp png_ptr, png_voidp error_ptr,
  163047. png_error_ptr error_fn, png_error_ptr warning_fn)
  163048. {
  163049. if (png_ptr == NULL)
  163050. return;
  163051. png_ptr->error_ptr = error_ptr;
  163052. png_ptr->error_fn = error_fn;
  163053. png_ptr->warning_fn = warning_fn;
  163054. }
  163055. png_voidp PNGAPI
  163056. png_get_error_ptr(png_structp png_ptr)
  163057. {
  163058. if (png_ptr == NULL)
  163059. return NULL;
  163060. return ((png_voidp)png_ptr->error_ptr);
  163061. }
  163062. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  163063. void PNGAPI
  163064. png_set_strip_error_numbers(png_structp png_ptr, png_uint_32 strip_mode)
  163065. {
  163066. if(png_ptr != NULL)
  163067. {
  163068. png_ptr->flags &=
  163069. ((~(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))&strip_mode);
  163070. }
  163071. }
  163072. #endif
  163073. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  163074. /*** End of inlined file: pngerror.c ***/
  163075. /*** Start of inlined file: pngget.c ***/
  163076. #define PNG_INTERNAL
  163077. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  163078. png_uint_32 PNGAPI
  163079. png_get_valid(png_structp png_ptr, png_infop info_ptr, png_uint_32 flag)
  163080. {
  163081. if (png_ptr != NULL && info_ptr != NULL)
  163082. return(info_ptr->valid & flag);
  163083. else
  163084. return(0);
  163085. }
  163086. png_uint_32 PNGAPI
  163087. png_get_rowbytes(png_structp png_ptr, png_infop info_ptr)
  163088. {
  163089. if (png_ptr != NULL && info_ptr != NULL)
  163090. return(info_ptr->rowbytes);
  163091. else
  163092. return(0);
  163093. }
  163094. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  163095. png_bytepp PNGAPI
  163096. png_get_rows(png_structp png_ptr, png_infop info_ptr)
  163097. {
  163098. if (png_ptr != NULL && info_ptr != NULL)
  163099. return(info_ptr->row_pointers);
  163100. else
  163101. return(0);
  163102. }
  163103. #endif
  163104. #ifdef PNG_EASY_ACCESS_SUPPORTED
  163105. png_uint_32 PNGAPI
  163106. png_get_image_width(png_structp png_ptr, png_infop info_ptr)
  163107. {
  163108. if (png_ptr != NULL && info_ptr != NULL)
  163109. {
  163110. return info_ptr->width;
  163111. }
  163112. return (0);
  163113. }
  163114. png_uint_32 PNGAPI
  163115. png_get_image_height(png_structp png_ptr, png_infop info_ptr)
  163116. {
  163117. if (png_ptr != NULL && info_ptr != NULL)
  163118. {
  163119. return info_ptr->height;
  163120. }
  163121. return (0);
  163122. }
  163123. png_byte PNGAPI
  163124. png_get_bit_depth(png_structp png_ptr, png_infop info_ptr)
  163125. {
  163126. if (png_ptr != NULL && info_ptr != NULL)
  163127. {
  163128. return info_ptr->bit_depth;
  163129. }
  163130. return (0);
  163131. }
  163132. png_byte PNGAPI
  163133. png_get_color_type(png_structp png_ptr, png_infop info_ptr)
  163134. {
  163135. if (png_ptr != NULL && info_ptr != NULL)
  163136. {
  163137. return info_ptr->color_type;
  163138. }
  163139. return (0);
  163140. }
  163141. png_byte PNGAPI
  163142. png_get_filter_type(png_structp png_ptr, png_infop info_ptr)
  163143. {
  163144. if (png_ptr != NULL && info_ptr != NULL)
  163145. {
  163146. return info_ptr->filter_type;
  163147. }
  163148. return (0);
  163149. }
  163150. png_byte PNGAPI
  163151. png_get_interlace_type(png_structp png_ptr, png_infop info_ptr)
  163152. {
  163153. if (png_ptr != NULL && info_ptr != NULL)
  163154. {
  163155. return info_ptr->interlace_type;
  163156. }
  163157. return (0);
  163158. }
  163159. png_byte PNGAPI
  163160. png_get_compression_type(png_structp png_ptr, png_infop info_ptr)
  163161. {
  163162. if (png_ptr != NULL && info_ptr != NULL)
  163163. {
  163164. return info_ptr->compression_type;
  163165. }
  163166. return (0);
  163167. }
  163168. png_uint_32 PNGAPI
  163169. png_get_x_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  163170. {
  163171. if (png_ptr != NULL && info_ptr != NULL)
  163172. #if defined(PNG_pHYs_SUPPORTED)
  163173. if (info_ptr->valid & PNG_INFO_pHYs)
  163174. {
  163175. png_debug1(1, "in %s retrieval function\n", "png_get_x_pixels_per_meter");
  163176. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
  163177. return (0);
  163178. else return (info_ptr->x_pixels_per_unit);
  163179. }
  163180. #else
  163181. return (0);
  163182. #endif
  163183. return (0);
  163184. }
  163185. png_uint_32 PNGAPI
  163186. png_get_y_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  163187. {
  163188. if (png_ptr != NULL && info_ptr != NULL)
  163189. #if defined(PNG_pHYs_SUPPORTED)
  163190. if (info_ptr->valid & PNG_INFO_pHYs)
  163191. {
  163192. png_debug1(1, "in %s retrieval function\n", "png_get_y_pixels_per_meter");
  163193. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
  163194. return (0);
  163195. else return (info_ptr->y_pixels_per_unit);
  163196. }
  163197. #else
  163198. return (0);
  163199. #endif
  163200. return (0);
  163201. }
  163202. png_uint_32 PNGAPI
  163203. png_get_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  163204. {
  163205. if (png_ptr != NULL && info_ptr != NULL)
  163206. #if defined(PNG_pHYs_SUPPORTED)
  163207. if (info_ptr->valid & PNG_INFO_pHYs)
  163208. {
  163209. png_debug1(1, "in %s retrieval function\n", "png_get_pixels_per_meter");
  163210. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER ||
  163211. info_ptr->x_pixels_per_unit != info_ptr->y_pixels_per_unit)
  163212. return (0);
  163213. else return (info_ptr->x_pixels_per_unit);
  163214. }
  163215. #else
  163216. return (0);
  163217. #endif
  163218. return (0);
  163219. }
  163220. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163221. float PNGAPI
  163222. png_get_pixel_aspect_ratio(png_structp png_ptr, png_infop info_ptr)
  163223. {
  163224. if (png_ptr != NULL && info_ptr != NULL)
  163225. #if defined(PNG_pHYs_SUPPORTED)
  163226. if (info_ptr->valid & PNG_INFO_pHYs)
  163227. {
  163228. png_debug1(1, "in %s retrieval function\n", "png_get_aspect_ratio");
  163229. if (info_ptr->x_pixels_per_unit == 0)
  163230. return ((float)0.0);
  163231. else
  163232. return ((float)((float)info_ptr->y_pixels_per_unit
  163233. /(float)info_ptr->x_pixels_per_unit));
  163234. }
  163235. #else
  163236. return (0.0);
  163237. #endif
  163238. return ((float)0.0);
  163239. }
  163240. #endif
  163241. png_int_32 PNGAPI
  163242. png_get_x_offset_microns(png_structp png_ptr, png_infop info_ptr)
  163243. {
  163244. if (png_ptr != NULL && info_ptr != NULL)
  163245. #if defined(PNG_oFFs_SUPPORTED)
  163246. if (info_ptr->valid & PNG_INFO_oFFs)
  163247. {
  163248. png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
  163249. if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
  163250. return (0);
  163251. else return (info_ptr->x_offset);
  163252. }
  163253. #else
  163254. return (0);
  163255. #endif
  163256. return (0);
  163257. }
  163258. png_int_32 PNGAPI
  163259. png_get_y_offset_microns(png_structp png_ptr, png_infop info_ptr)
  163260. {
  163261. if (png_ptr != NULL && info_ptr != NULL)
  163262. #if defined(PNG_oFFs_SUPPORTED)
  163263. if (info_ptr->valid & PNG_INFO_oFFs)
  163264. {
  163265. png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
  163266. if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
  163267. return (0);
  163268. else return (info_ptr->y_offset);
  163269. }
  163270. #else
  163271. return (0);
  163272. #endif
  163273. return (0);
  163274. }
  163275. png_int_32 PNGAPI
  163276. png_get_x_offset_pixels(png_structp png_ptr, png_infop info_ptr)
  163277. {
  163278. if (png_ptr != NULL && info_ptr != NULL)
  163279. #if defined(PNG_oFFs_SUPPORTED)
  163280. if (info_ptr->valid & PNG_INFO_oFFs)
  163281. {
  163282. png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
  163283. if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
  163284. return (0);
  163285. else return (info_ptr->x_offset);
  163286. }
  163287. #else
  163288. return (0);
  163289. #endif
  163290. return (0);
  163291. }
  163292. png_int_32 PNGAPI
  163293. png_get_y_offset_pixels(png_structp png_ptr, png_infop info_ptr)
  163294. {
  163295. if (png_ptr != NULL && info_ptr != NULL)
  163296. #if defined(PNG_oFFs_SUPPORTED)
  163297. if (info_ptr->valid & PNG_INFO_oFFs)
  163298. {
  163299. png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
  163300. if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
  163301. return (0);
  163302. else return (info_ptr->y_offset);
  163303. }
  163304. #else
  163305. return (0);
  163306. #endif
  163307. return (0);
  163308. }
  163309. #if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED)
  163310. png_uint_32 PNGAPI
  163311. png_get_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  163312. {
  163313. return ((png_uint_32)((float)png_get_pixels_per_meter(png_ptr, info_ptr)
  163314. *.0254 +.5));
  163315. }
  163316. png_uint_32 PNGAPI
  163317. png_get_x_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  163318. {
  163319. return ((png_uint_32)((float)png_get_x_pixels_per_meter(png_ptr, info_ptr)
  163320. *.0254 +.5));
  163321. }
  163322. png_uint_32 PNGAPI
  163323. png_get_y_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  163324. {
  163325. return ((png_uint_32)((float)png_get_y_pixels_per_meter(png_ptr, info_ptr)
  163326. *.0254 +.5));
  163327. }
  163328. float PNGAPI
  163329. png_get_x_offset_inches(png_structp png_ptr, png_infop info_ptr)
  163330. {
  163331. return ((float)png_get_x_offset_microns(png_ptr, info_ptr)
  163332. *.00003937);
  163333. }
  163334. float PNGAPI
  163335. png_get_y_offset_inches(png_structp png_ptr, png_infop info_ptr)
  163336. {
  163337. return ((float)png_get_y_offset_microns(png_ptr, info_ptr)
  163338. *.00003937);
  163339. }
  163340. #if defined(PNG_pHYs_SUPPORTED)
  163341. png_uint_32 PNGAPI
  163342. png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr,
  163343. png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
  163344. {
  163345. png_uint_32 retval = 0;
  163346. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
  163347. {
  163348. png_debug1(1, "in %s retrieval function\n", "pHYs");
  163349. if (res_x != NULL)
  163350. {
  163351. *res_x = info_ptr->x_pixels_per_unit;
  163352. retval |= PNG_INFO_pHYs;
  163353. }
  163354. if (res_y != NULL)
  163355. {
  163356. *res_y = info_ptr->y_pixels_per_unit;
  163357. retval |= PNG_INFO_pHYs;
  163358. }
  163359. if (unit_type != NULL)
  163360. {
  163361. *unit_type = (int)info_ptr->phys_unit_type;
  163362. retval |= PNG_INFO_pHYs;
  163363. if(*unit_type == 1)
  163364. {
  163365. if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50);
  163366. if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50);
  163367. }
  163368. }
  163369. }
  163370. return (retval);
  163371. }
  163372. #endif /* PNG_pHYs_SUPPORTED */
  163373. #endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */
  163374. #endif /* PNG_EASY_ACCESS_SUPPORTED */
  163375. png_byte PNGAPI
  163376. png_get_channels(png_structp png_ptr, png_infop info_ptr)
  163377. {
  163378. if (png_ptr != NULL && info_ptr != NULL)
  163379. return(info_ptr->channels);
  163380. else
  163381. return (0);
  163382. }
  163383. png_bytep PNGAPI
  163384. png_get_signature(png_structp png_ptr, png_infop info_ptr)
  163385. {
  163386. if (png_ptr != NULL && info_ptr != NULL)
  163387. return(info_ptr->signature);
  163388. else
  163389. return (NULL);
  163390. }
  163391. #if defined(PNG_bKGD_SUPPORTED)
  163392. png_uint_32 PNGAPI
  163393. png_get_bKGD(png_structp png_ptr, png_infop info_ptr,
  163394. png_color_16p *background)
  163395. {
  163396. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD)
  163397. && background != NULL)
  163398. {
  163399. png_debug1(1, "in %s retrieval function\n", "bKGD");
  163400. *background = &(info_ptr->background);
  163401. return (PNG_INFO_bKGD);
  163402. }
  163403. return (0);
  163404. }
  163405. #endif
  163406. #if defined(PNG_cHRM_SUPPORTED)
  163407. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163408. png_uint_32 PNGAPI
  163409. png_get_cHRM(png_structp png_ptr, png_infop info_ptr,
  163410. double *white_x, double *white_y, double *red_x, double *red_y,
  163411. double *green_x, double *green_y, double *blue_x, double *blue_y)
  163412. {
  163413. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  163414. {
  163415. png_debug1(1, "in %s retrieval function\n", "cHRM");
  163416. if (white_x != NULL)
  163417. *white_x = (double)info_ptr->x_white;
  163418. if (white_y != NULL)
  163419. *white_y = (double)info_ptr->y_white;
  163420. if (red_x != NULL)
  163421. *red_x = (double)info_ptr->x_red;
  163422. if (red_y != NULL)
  163423. *red_y = (double)info_ptr->y_red;
  163424. if (green_x != NULL)
  163425. *green_x = (double)info_ptr->x_green;
  163426. if (green_y != NULL)
  163427. *green_y = (double)info_ptr->y_green;
  163428. if (blue_x != NULL)
  163429. *blue_x = (double)info_ptr->x_blue;
  163430. if (blue_y != NULL)
  163431. *blue_y = (double)info_ptr->y_blue;
  163432. return (PNG_INFO_cHRM);
  163433. }
  163434. return (0);
  163435. }
  163436. #endif
  163437. #ifdef PNG_FIXED_POINT_SUPPORTED
  163438. png_uint_32 PNGAPI
  163439. png_get_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
  163440. png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x,
  163441. png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y,
  163442. png_fixed_point *blue_x, png_fixed_point *blue_y)
  163443. {
  163444. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  163445. {
  163446. png_debug1(1, "in %s retrieval function\n", "cHRM");
  163447. if (white_x != NULL)
  163448. *white_x = info_ptr->int_x_white;
  163449. if (white_y != NULL)
  163450. *white_y = info_ptr->int_y_white;
  163451. if (red_x != NULL)
  163452. *red_x = info_ptr->int_x_red;
  163453. if (red_y != NULL)
  163454. *red_y = info_ptr->int_y_red;
  163455. if (green_x != NULL)
  163456. *green_x = info_ptr->int_x_green;
  163457. if (green_y != NULL)
  163458. *green_y = info_ptr->int_y_green;
  163459. if (blue_x != NULL)
  163460. *blue_x = info_ptr->int_x_blue;
  163461. if (blue_y != NULL)
  163462. *blue_y = info_ptr->int_y_blue;
  163463. return (PNG_INFO_cHRM);
  163464. }
  163465. return (0);
  163466. }
  163467. #endif
  163468. #endif
  163469. #if defined(PNG_gAMA_SUPPORTED)
  163470. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163471. png_uint_32 PNGAPI
  163472. png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma)
  163473. {
  163474. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  163475. && file_gamma != NULL)
  163476. {
  163477. png_debug1(1, "in %s retrieval function\n", "gAMA");
  163478. *file_gamma = (double)info_ptr->gamma;
  163479. return (PNG_INFO_gAMA);
  163480. }
  163481. return (0);
  163482. }
  163483. #endif
  163484. #ifdef PNG_FIXED_POINT_SUPPORTED
  163485. png_uint_32 PNGAPI
  163486. png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr,
  163487. png_fixed_point *int_file_gamma)
  163488. {
  163489. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  163490. && int_file_gamma != NULL)
  163491. {
  163492. png_debug1(1, "in %s retrieval function\n", "gAMA");
  163493. *int_file_gamma = info_ptr->int_gamma;
  163494. return (PNG_INFO_gAMA);
  163495. }
  163496. return (0);
  163497. }
  163498. #endif
  163499. #endif
  163500. #if defined(PNG_sRGB_SUPPORTED)
  163501. png_uint_32 PNGAPI
  163502. png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent)
  163503. {
  163504. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)
  163505. && file_srgb_intent != NULL)
  163506. {
  163507. png_debug1(1, "in %s retrieval function\n", "sRGB");
  163508. *file_srgb_intent = (int)info_ptr->srgb_intent;
  163509. return (PNG_INFO_sRGB);
  163510. }
  163511. return (0);
  163512. }
  163513. #endif
  163514. #if defined(PNG_iCCP_SUPPORTED)
  163515. png_uint_32 PNGAPI
  163516. png_get_iCCP(png_structp png_ptr, png_infop info_ptr,
  163517. png_charpp name, int *compression_type,
  163518. png_charpp profile, png_uint_32 *proflen)
  163519. {
  163520. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP)
  163521. && name != NULL && profile != NULL && proflen != NULL)
  163522. {
  163523. png_debug1(1, "in %s retrieval function\n", "iCCP");
  163524. *name = info_ptr->iccp_name;
  163525. *profile = info_ptr->iccp_profile;
  163526. *proflen = (int)info_ptr->iccp_proflen;
  163527. *compression_type = (int)info_ptr->iccp_compression;
  163528. return (PNG_INFO_iCCP);
  163529. }
  163530. return (0);
  163531. }
  163532. #endif
  163533. #if defined(PNG_sPLT_SUPPORTED)
  163534. png_uint_32 PNGAPI
  163535. png_get_sPLT(png_structp png_ptr, png_infop info_ptr,
  163536. png_sPLT_tpp spalettes)
  163537. {
  163538. if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL)
  163539. {
  163540. *spalettes = info_ptr->splt_palettes;
  163541. return ((png_uint_32)info_ptr->splt_palettes_num);
  163542. }
  163543. return (0);
  163544. }
  163545. #endif
  163546. #if defined(PNG_hIST_SUPPORTED)
  163547. png_uint_32 PNGAPI
  163548. png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist)
  163549. {
  163550. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)
  163551. && hist != NULL)
  163552. {
  163553. png_debug1(1, "in %s retrieval function\n", "hIST");
  163554. *hist = info_ptr->hist;
  163555. return (PNG_INFO_hIST);
  163556. }
  163557. return (0);
  163558. }
  163559. #endif
  163560. png_uint_32 PNGAPI
  163561. png_get_IHDR(png_structp png_ptr, png_infop info_ptr,
  163562. png_uint_32 *width, png_uint_32 *height, int *bit_depth,
  163563. int *color_type, int *interlace_type, int *compression_type,
  163564. int *filter_type)
  163565. {
  163566. if (png_ptr != NULL && info_ptr != NULL && width != NULL && height != NULL &&
  163567. bit_depth != NULL && color_type != NULL)
  163568. {
  163569. png_debug1(1, "in %s retrieval function\n", "IHDR");
  163570. *width = info_ptr->width;
  163571. *height = info_ptr->height;
  163572. *bit_depth = info_ptr->bit_depth;
  163573. if (info_ptr->bit_depth < 1 || info_ptr->bit_depth > 16)
  163574. png_error(png_ptr, "Invalid bit depth");
  163575. *color_type = info_ptr->color_type;
  163576. if (info_ptr->color_type > 6)
  163577. png_error(png_ptr, "Invalid color type");
  163578. if (compression_type != NULL)
  163579. *compression_type = info_ptr->compression_type;
  163580. if (filter_type != NULL)
  163581. *filter_type = info_ptr->filter_type;
  163582. if (interlace_type != NULL)
  163583. *interlace_type = info_ptr->interlace_type;
  163584. if (*width == 0 || *width > PNG_UINT_31_MAX)
  163585. png_error(png_ptr, "Invalid image width");
  163586. if (*height == 0 || *height > PNG_UINT_31_MAX)
  163587. png_error(png_ptr, "Invalid image height");
  163588. if (info_ptr->width > (PNG_UINT_32_MAX
  163589. >> 3) /* 8-byte RGBA pixels */
  163590. - 64 /* bigrowbuf hack */
  163591. - 1 /* filter byte */
  163592. - 7*8 /* rounding of width to multiple of 8 pixels */
  163593. - 8) /* extra max_pixel_depth pad */
  163594. {
  163595. png_warning(png_ptr,
  163596. "Width too large for libpng to process image data.");
  163597. }
  163598. return (1);
  163599. }
  163600. return (0);
  163601. }
  163602. #if defined(PNG_oFFs_SUPPORTED)
  163603. png_uint_32 PNGAPI
  163604. png_get_oFFs(png_structp png_ptr, png_infop info_ptr,
  163605. png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)
  163606. {
  163607. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)
  163608. && offset_x != NULL && offset_y != NULL && unit_type != NULL)
  163609. {
  163610. png_debug1(1, "in %s retrieval function\n", "oFFs");
  163611. *offset_x = info_ptr->x_offset;
  163612. *offset_y = info_ptr->y_offset;
  163613. *unit_type = (int)info_ptr->offset_unit_type;
  163614. return (PNG_INFO_oFFs);
  163615. }
  163616. return (0);
  163617. }
  163618. #endif
  163619. #if defined(PNG_pCAL_SUPPORTED)
  163620. png_uint_32 PNGAPI
  163621. png_get_pCAL(png_structp png_ptr, png_infop info_ptr,
  163622. png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
  163623. png_charp *units, png_charpp *params)
  163624. {
  163625. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL)
  163626. && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
  163627. nparams != NULL && units != NULL && params != NULL)
  163628. {
  163629. png_debug1(1, "in %s retrieval function\n", "pCAL");
  163630. *purpose = info_ptr->pcal_purpose;
  163631. *X0 = info_ptr->pcal_X0;
  163632. *X1 = info_ptr->pcal_X1;
  163633. *type = (int)info_ptr->pcal_type;
  163634. *nparams = (int)info_ptr->pcal_nparams;
  163635. *units = info_ptr->pcal_units;
  163636. *params = info_ptr->pcal_params;
  163637. return (PNG_INFO_pCAL);
  163638. }
  163639. return (0);
  163640. }
  163641. #endif
  163642. #if defined(PNG_sCAL_SUPPORTED)
  163643. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163644. png_uint_32 PNGAPI
  163645. png_get_sCAL(png_structp png_ptr, png_infop info_ptr,
  163646. int *unit, double *width, double *height)
  163647. {
  163648. if (png_ptr != NULL && info_ptr != NULL &&
  163649. (info_ptr->valid & PNG_INFO_sCAL))
  163650. {
  163651. *unit = info_ptr->scal_unit;
  163652. *width = info_ptr->scal_pixel_width;
  163653. *height = info_ptr->scal_pixel_height;
  163654. return (PNG_INFO_sCAL);
  163655. }
  163656. return(0);
  163657. }
  163658. #else
  163659. #ifdef PNG_FIXED_POINT_SUPPORTED
  163660. png_uint_32 PNGAPI
  163661. png_get_sCAL_s(png_structp png_ptr, png_infop info_ptr,
  163662. int *unit, png_charpp width, png_charpp height)
  163663. {
  163664. if (png_ptr != NULL && info_ptr != NULL &&
  163665. (info_ptr->valid & PNG_INFO_sCAL))
  163666. {
  163667. *unit = info_ptr->scal_unit;
  163668. *width = info_ptr->scal_s_width;
  163669. *height = info_ptr->scal_s_height;
  163670. return (PNG_INFO_sCAL);
  163671. }
  163672. return(0);
  163673. }
  163674. #endif
  163675. #endif
  163676. #endif
  163677. #if defined(PNG_pHYs_SUPPORTED)
  163678. png_uint_32 PNGAPI
  163679. png_get_pHYs(png_structp png_ptr, png_infop info_ptr,
  163680. png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
  163681. {
  163682. png_uint_32 retval = 0;
  163683. if (png_ptr != NULL && info_ptr != NULL &&
  163684. (info_ptr->valid & PNG_INFO_pHYs))
  163685. {
  163686. png_debug1(1, "in %s retrieval function\n", "pHYs");
  163687. if (res_x != NULL)
  163688. {
  163689. *res_x = info_ptr->x_pixels_per_unit;
  163690. retval |= PNG_INFO_pHYs;
  163691. }
  163692. if (res_y != NULL)
  163693. {
  163694. *res_y = info_ptr->y_pixels_per_unit;
  163695. retval |= PNG_INFO_pHYs;
  163696. }
  163697. if (unit_type != NULL)
  163698. {
  163699. *unit_type = (int)info_ptr->phys_unit_type;
  163700. retval |= PNG_INFO_pHYs;
  163701. }
  163702. }
  163703. return (retval);
  163704. }
  163705. #endif
  163706. png_uint_32 PNGAPI
  163707. png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette,
  163708. int *num_palette)
  163709. {
  163710. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE)
  163711. && palette != NULL)
  163712. {
  163713. png_debug1(1, "in %s retrieval function\n", "PLTE");
  163714. *palette = info_ptr->palette;
  163715. *num_palette = info_ptr->num_palette;
  163716. png_debug1(3, "num_palette = %d\n", *num_palette);
  163717. return (PNG_INFO_PLTE);
  163718. }
  163719. return (0);
  163720. }
  163721. #if defined(PNG_sBIT_SUPPORTED)
  163722. png_uint_32 PNGAPI
  163723. png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit)
  163724. {
  163725. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT)
  163726. && sig_bit != NULL)
  163727. {
  163728. png_debug1(1, "in %s retrieval function\n", "sBIT");
  163729. *sig_bit = &(info_ptr->sig_bit);
  163730. return (PNG_INFO_sBIT);
  163731. }
  163732. return (0);
  163733. }
  163734. #endif
  163735. #if defined(PNG_TEXT_SUPPORTED)
  163736. png_uint_32 PNGAPI
  163737. png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr,
  163738. int *num_text)
  163739. {
  163740. if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0)
  163741. {
  163742. png_debug1(1, "in %s retrieval function\n",
  163743. (png_ptr->chunk_name[0] == '\0' ? "text"
  163744. : (png_const_charp)png_ptr->chunk_name));
  163745. if (text_ptr != NULL)
  163746. *text_ptr = info_ptr->text;
  163747. if (num_text != NULL)
  163748. *num_text = info_ptr->num_text;
  163749. return ((png_uint_32)info_ptr->num_text);
  163750. }
  163751. if (num_text != NULL)
  163752. *num_text = 0;
  163753. return(0);
  163754. }
  163755. #endif
  163756. #if defined(PNG_tIME_SUPPORTED)
  163757. png_uint_32 PNGAPI
  163758. png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time)
  163759. {
  163760. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME)
  163761. && mod_time != NULL)
  163762. {
  163763. png_debug1(1, "in %s retrieval function\n", "tIME");
  163764. *mod_time = &(info_ptr->mod_time);
  163765. return (PNG_INFO_tIME);
  163766. }
  163767. return (0);
  163768. }
  163769. #endif
  163770. #if defined(PNG_tRNS_SUPPORTED)
  163771. png_uint_32 PNGAPI
  163772. png_get_tRNS(png_structp png_ptr, png_infop info_ptr,
  163773. png_bytep *trans, int *num_trans, png_color_16p *trans_values)
  163774. {
  163775. png_uint_32 retval = 0;
  163776. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  163777. {
  163778. png_debug1(1, "in %s retrieval function\n", "tRNS");
  163779. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  163780. {
  163781. if (trans != NULL)
  163782. {
  163783. *trans = info_ptr->trans;
  163784. retval |= PNG_INFO_tRNS;
  163785. }
  163786. if (trans_values != NULL)
  163787. *trans_values = &(info_ptr->trans_values);
  163788. }
  163789. else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */
  163790. {
  163791. if (trans_values != NULL)
  163792. {
  163793. *trans_values = &(info_ptr->trans_values);
  163794. retval |= PNG_INFO_tRNS;
  163795. }
  163796. if(trans != NULL)
  163797. *trans = NULL;
  163798. }
  163799. if(num_trans != NULL)
  163800. {
  163801. *num_trans = info_ptr->num_trans;
  163802. retval |= PNG_INFO_tRNS;
  163803. }
  163804. }
  163805. return (retval);
  163806. }
  163807. #endif
  163808. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  163809. png_uint_32 PNGAPI
  163810. png_get_unknown_chunks(png_structp png_ptr, png_infop info_ptr,
  163811. png_unknown_chunkpp unknowns)
  163812. {
  163813. if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL)
  163814. {
  163815. *unknowns = info_ptr->unknown_chunks;
  163816. return ((png_uint_32)info_ptr->unknown_chunks_num);
  163817. }
  163818. return (0);
  163819. }
  163820. #endif
  163821. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  163822. png_byte PNGAPI
  163823. png_get_rgb_to_gray_status (png_structp png_ptr)
  163824. {
  163825. return (png_byte)(png_ptr? png_ptr->rgb_to_gray_status : 0);
  163826. }
  163827. #endif
  163828. #if defined(PNG_USER_CHUNKS_SUPPORTED)
  163829. png_voidp PNGAPI
  163830. png_get_user_chunk_ptr(png_structp png_ptr)
  163831. {
  163832. return (png_ptr? png_ptr->user_chunk_ptr : NULL);
  163833. }
  163834. #endif
  163835. #ifdef PNG_WRITE_SUPPORTED
  163836. png_uint_32 PNGAPI
  163837. png_get_compression_buffer_size(png_structp png_ptr)
  163838. {
  163839. return (png_uint_32)(png_ptr? png_ptr->zbuf_size : 0L);
  163840. }
  163841. #endif
  163842. #ifdef PNG_ASSEMBLER_CODE_SUPPORTED
  163843. #ifndef PNG_1_0_X
  163844. png_uint_32 PNGAPI
  163845. png_get_asm_flags (png_structp png_ptr)
  163846. {
  163847. return (png_ptr? 0L: 0L);
  163848. }
  163849. png_uint_32 PNGAPI
  163850. png_get_asm_flagmask (int flag_select)
  163851. {
  163852. flag_select=flag_select;
  163853. return 0L;
  163854. }
  163855. png_uint_32 PNGAPI
  163856. png_get_mmx_flagmask (int flag_select, int *compilerID)
  163857. {
  163858. flag_select=flag_select;
  163859. *compilerID = -1; /* unknown (i.e., no asm/MMX code compiled) */
  163860. return 0L;
  163861. }
  163862. png_byte PNGAPI
  163863. png_get_mmx_bitdepth_threshold (png_structp png_ptr)
  163864. {
  163865. return (png_ptr? 0: 0);
  163866. }
  163867. png_uint_32 PNGAPI
  163868. png_get_mmx_rowbytes_threshold (png_structp png_ptr)
  163869. {
  163870. return (png_ptr? 0L: 0L);
  163871. }
  163872. #endif /* ?PNG_1_0_X */
  163873. #endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
  163874. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  163875. png_uint_32 PNGAPI
  163876. png_get_user_width_max (png_structp png_ptr)
  163877. {
  163878. return (png_ptr? png_ptr->user_width_max : 0);
  163879. }
  163880. png_uint_32 PNGAPI
  163881. png_get_user_height_max (png_structp png_ptr)
  163882. {
  163883. return (png_ptr? png_ptr->user_height_max : 0);
  163884. }
  163885. #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
  163886. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  163887. /*** End of inlined file: pngget.c ***/
  163888. /*** Start of inlined file: pngmem.c ***/
  163889. #define PNG_INTERNAL
  163890. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  163891. #if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
  163892. png_voidp /* PRIVATE */
  163893. png_create_struct(int type)
  163894. {
  163895. #ifdef PNG_USER_MEM_SUPPORTED
  163896. return (png_create_struct_2(type, png_malloc_ptr_NULL, png_voidp_NULL));
  163897. }
  163898. png_voidp /* PRIVATE */
  163899. png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
  163900. {
  163901. #endif /* PNG_USER_MEM_SUPPORTED */
  163902. png_size_t size;
  163903. png_voidp struct_ptr;
  163904. if (type == PNG_STRUCT_INFO)
  163905. size = png_sizeof(png_info);
  163906. else if (type == PNG_STRUCT_PNG)
  163907. size = png_sizeof(png_struct);
  163908. else
  163909. return (png_get_copyright(NULL));
  163910. #ifdef PNG_USER_MEM_SUPPORTED
  163911. if(malloc_fn != NULL)
  163912. {
  163913. png_struct dummy_struct;
  163914. png_structp png_ptr = &dummy_struct;
  163915. png_ptr->mem_ptr=mem_ptr;
  163916. struct_ptr = (*(malloc_fn))(png_ptr, (png_uint_32)size);
  163917. }
  163918. else
  163919. #endif /* PNG_USER_MEM_SUPPORTED */
  163920. struct_ptr = (png_voidp)farmalloc(size);
  163921. if (struct_ptr != NULL)
  163922. png_memset(struct_ptr, 0, size);
  163923. return (struct_ptr);
  163924. }
  163925. void /* PRIVATE */
  163926. png_destroy_struct(png_voidp struct_ptr)
  163927. {
  163928. #ifdef PNG_USER_MEM_SUPPORTED
  163929. png_destroy_struct_2(struct_ptr, png_free_ptr_NULL, png_voidp_NULL);
  163930. }
  163931. void /* PRIVATE */
  163932. png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
  163933. png_voidp mem_ptr)
  163934. {
  163935. #endif
  163936. if (struct_ptr != NULL)
  163937. {
  163938. #ifdef PNG_USER_MEM_SUPPORTED
  163939. if(free_fn != NULL)
  163940. {
  163941. png_struct dummy_struct;
  163942. png_structp png_ptr = &dummy_struct;
  163943. png_ptr->mem_ptr=mem_ptr;
  163944. (*(free_fn))(png_ptr, struct_ptr);
  163945. return;
  163946. }
  163947. #endif /* PNG_USER_MEM_SUPPORTED */
  163948. farfree (struct_ptr);
  163949. }
  163950. }
  163951. png_voidp PNGAPI
  163952. png_malloc(png_structp png_ptr, png_uint_32 size)
  163953. {
  163954. png_voidp ret;
  163955. if (png_ptr == NULL || size == 0)
  163956. return (NULL);
  163957. #ifdef PNG_USER_MEM_SUPPORTED
  163958. if(png_ptr->malloc_fn != NULL)
  163959. ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size));
  163960. else
  163961. ret = (png_malloc_default(png_ptr, size));
  163962. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  163963. png_error(png_ptr, "Out of memory!");
  163964. return (ret);
  163965. }
  163966. png_voidp PNGAPI
  163967. png_malloc_default(png_structp png_ptr, png_uint_32 size)
  163968. {
  163969. png_voidp ret;
  163970. #endif /* PNG_USER_MEM_SUPPORTED */
  163971. if (png_ptr == NULL || size == 0)
  163972. return (NULL);
  163973. #ifdef PNG_MAX_MALLOC_64K
  163974. if (size > (png_uint_32)65536L)
  163975. {
  163976. png_warning(png_ptr, "Cannot Allocate > 64K");
  163977. ret = NULL;
  163978. }
  163979. else
  163980. #endif
  163981. if (size != (size_t)size)
  163982. ret = NULL;
  163983. else if (size == (png_uint_32)65536L)
  163984. {
  163985. if (png_ptr->offset_table == NULL)
  163986. {
  163987. ret = farmalloc(size);
  163988. if (ret == NULL || ((png_size_t)ret & 0xffff))
  163989. {
  163990. int num_blocks;
  163991. png_uint_32 total_size;
  163992. png_bytep table;
  163993. int i;
  163994. png_byte huge * hptr;
  163995. if (ret != NULL)
  163996. {
  163997. farfree(ret);
  163998. ret = NULL;
  163999. }
  164000. if(png_ptr->zlib_window_bits > 14)
  164001. num_blocks = (int)(1 << (png_ptr->zlib_window_bits - 14));
  164002. else
  164003. num_blocks = 1;
  164004. if (png_ptr->zlib_mem_level >= 7)
  164005. num_blocks += (int)(1 << (png_ptr->zlib_mem_level - 7));
  164006. else
  164007. num_blocks++;
  164008. total_size = ((png_uint_32)65536L) * (png_uint_32)num_blocks+16;
  164009. table = farmalloc(total_size);
  164010. if (table == NULL)
  164011. {
  164012. #ifndef PNG_USER_MEM_SUPPORTED
  164013. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164014. png_error(png_ptr, "Out Of Memory."); /* Note "O" and "M" */
  164015. else
  164016. png_warning(png_ptr, "Out Of Memory.");
  164017. #endif
  164018. return (NULL);
  164019. }
  164020. if ((png_size_t)table & 0xfff0)
  164021. {
  164022. #ifndef PNG_USER_MEM_SUPPORTED
  164023. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164024. png_error(png_ptr,
  164025. "Farmalloc didn't return normalized pointer");
  164026. else
  164027. png_warning(png_ptr,
  164028. "Farmalloc didn't return normalized pointer");
  164029. #endif
  164030. return (NULL);
  164031. }
  164032. png_ptr->offset_table = table;
  164033. png_ptr->offset_table_ptr = farmalloc(num_blocks *
  164034. png_sizeof (png_bytep));
  164035. if (png_ptr->offset_table_ptr == NULL)
  164036. {
  164037. #ifndef PNG_USER_MEM_SUPPORTED
  164038. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164039. png_error(png_ptr, "Out Of memory."); /* Note "O" and "M" */
  164040. else
  164041. png_warning(png_ptr, "Out Of memory.");
  164042. #endif
  164043. return (NULL);
  164044. }
  164045. hptr = (png_byte huge *)table;
  164046. if ((png_size_t)hptr & 0xf)
  164047. {
  164048. hptr = (png_byte huge *)((long)(hptr) & 0xfffffff0L);
  164049. hptr = hptr + 16L; /* "hptr += 16L" fails on Turbo C++ 3.0 */
  164050. }
  164051. for (i = 0; i < num_blocks; i++)
  164052. {
  164053. png_ptr->offset_table_ptr[i] = (png_bytep)hptr;
  164054. hptr = hptr + (png_uint_32)65536L; /* "+=" fails on TC++3.0 */
  164055. }
  164056. png_ptr->offset_table_number = num_blocks;
  164057. png_ptr->offset_table_count = 0;
  164058. png_ptr->offset_table_count_free = 0;
  164059. }
  164060. }
  164061. if (png_ptr->offset_table_count >= png_ptr->offset_table_number)
  164062. {
  164063. #ifndef PNG_USER_MEM_SUPPORTED
  164064. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164065. png_error(png_ptr, "Out of Memory."); /* Note "o" and "M" */
  164066. else
  164067. png_warning(png_ptr, "Out of Memory.");
  164068. #endif
  164069. return (NULL);
  164070. }
  164071. ret = png_ptr->offset_table_ptr[png_ptr->offset_table_count++];
  164072. }
  164073. else
  164074. ret = farmalloc(size);
  164075. #ifndef PNG_USER_MEM_SUPPORTED
  164076. if (ret == NULL)
  164077. {
  164078. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164079. png_error(png_ptr, "Out of memory."); /* Note "o" and "m" */
  164080. else
  164081. png_warning(png_ptr, "Out of memory."); /* Note "o" and "m" */
  164082. }
  164083. #endif
  164084. return (ret);
  164085. }
  164086. void PNGAPI
  164087. png_free(png_structp png_ptr, png_voidp ptr)
  164088. {
  164089. if (png_ptr == NULL || ptr == NULL)
  164090. return;
  164091. #ifdef PNG_USER_MEM_SUPPORTED
  164092. if (png_ptr->free_fn != NULL)
  164093. {
  164094. (*(png_ptr->free_fn))(png_ptr, ptr);
  164095. return;
  164096. }
  164097. else png_free_default(png_ptr, ptr);
  164098. }
  164099. void PNGAPI
  164100. png_free_default(png_structp png_ptr, png_voidp ptr)
  164101. {
  164102. #endif /* PNG_USER_MEM_SUPPORTED */
  164103. if(png_ptr == NULL) return;
  164104. if (png_ptr->offset_table != NULL)
  164105. {
  164106. int i;
  164107. for (i = 0; i < png_ptr->offset_table_count; i++)
  164108. {
  164109. if (ptr == png_ptr->offset_table_ptr[i])
  164110. {
  164111. ptr = NULL;
  164112. png_ptr->offset_table_count_free++;
  164113. break;
  164114. }
  164115. }
  164116. if (png_ptr->offset_table_count_free == png_ptr->offset_table_count)
  164117. {
  164118. farfree(png_ptr->offset_table);
  164119. farfree(png_ptr->offset_table_ptr);
  164120. png_ptr->offset_table = NULL;
  164121. png_ptr->offset_table_ptr = NULL;
  164122. }
  164123. }
  164124. if (ptr != NULL)
  164125. {
  164126. farfree(ptr);
  164127. }
  164128. }
  164129. #else /* Not the Borland DOS special memory handler */
  164130. png_voidp /* PRIVATE */
  164131. png_create_struct(int type)
  164132. {
  164133. #ifdef PNG_USER_MEM_SUPPORTED
  164134. return (png_create_struct_2(type, png_malloc_ptr_NULL, png_voidp_NULL));
  164135. }
  164136. png_voidp /* PRIVATE */
  164137. png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
  164138. {
  164139. #endif /* PNG_USER_MEM_SUPPORTED */
  164140. png_size_t size;
  164141. png_voidp struct_ptr;
  164142. if (type == PNG_STRUCT_INFO)
  164143. size = png_sizeof(png_info);
  164144. else if (type == PNG_STRUCT_PNG)
  164145. size = png_sizeof(png_struct);
  164146. else
  164147. return (NULL);
  164148. #ifdef PNG_USER_MEM_SUPPORTED
  164149. if(malloc_fn != NULL)
  164150. {
  164151. png_struct dummy_struct;
  164152. png_structp png_ptr = &dummy_struct;
  164153. png_ptr->mem_ptr=mem_ptr;
  164154. struct_ptr = (*(malloc_fn))(png_ptr, size);
  164155. if (struct_ptr != NULL)
  164156. png_memset(struct_ptr, 0, size);
  164157. return (struct_ptr);
  164158. }
  164159. #endif /* PNG_USER_MEM_SUPPORTED */
  164160. #if defined(__TURBOC__) && !defined(__FLAT__)
  164161. struct_ptr = (png_voidp)farmalloc(size);
  164162. #else
  164163. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164164. struct_ptr = (png_voidp)halloc(size,1);
  164165. # else
  164166. struct_ptr = (png_voidp)malloc(size);
  164167. # endif
  164168. #endif
  164169. if (struct_ptr != NULL)
  164170. png_memset(struct_ptr, 0, size);
  164171. return (struct_ptr);
  164172. }
  164173. void /* PRIVATE */
  164174. png_destroy_struct(png_voidp struct_ptr)
  164175. {
  164176. #ifdef PNG_USER_MEM_SUPPORTED
  164177. png_destroy_struct_2(struct_ptr, png_free_ptr_NULL, png_voidp_NULL);
  164178. }
  164179. void /* PRIVATE */
  164180. png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
  164181. png_voidp mem_ptr)
  164182. {
  164183. #endif /* PNG_USER_MEM_SUPPORTED */
  164184. if (struct_ptr != NULL)
  164185. {
  164186. #ifdef PNG_USER_MEM_SUPPORTED
  164187. if(free_fn != NULL)
  164188. {
  164189. png_struct dummy_struct;
  164190. png_structp png_ptr = &dummy_struct;
  164191. png_ptr->mem_ptr=mem_ptr;
  164192. (*(free_fn))(png_ptr, struct_ptr);
  164193. return;
  164194. }
  164195. #endif /* PNG_USER_MEM_SUPPORTED */
  164196. #if defined(__TURBOC__) && !defined(__FLAT__)
  164197. farfree(struct_ptr);
  164198. #else
  164199. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164200. hfree(struct_ptr);
  164201. # else
  164202. free(struct_ptr);
  164203. # endif
  164204. #endif
  164205. }
  164206. }
  164207. png_voidp PNGAPI
  164208. png_malloc(png_structp png_ptr, png_uint_32 size)
  164209. {
  164210. png_voidp ret;
  164211. #ifdef PNG_USER_MEM_SUPPORTED
  164212. if (png_ptr == NULL || size == 0)
  164213. return (NULL);
  164214. if(png_ptr->malloc_fn != NULL)
  164215. ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size));
  164216. else
  164217. ret = (png_malloc_default(png_ptr, size));
  164218. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164219. png_error(png_ptr, "Out of Memory!");
  164220. return (ret);
  164221. }
  164222. png_voidp PNGAPI
  164223. png_malloc_default(png_structp png_ptr, png_uint_32 size)
  164224. {
  164225. png_voidp ret;
  164226. #endif /* PNG_USER_MEM_SUPPORTED */
  164227. if (png_ptr == NULL || size == 0)
  164228. return (NULL);
  164229. #ifdef PNG_MAX_MALLOC_64K
  164230. if (size > (png_uint_32)65536L)
  164231. {
  164232. #ifndef PNG_USER_MEM_SUPPORTED
  164233. if(png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164234. png_error(png_ptr, "Cannot Allocate > 64K");
  164235. else
  164236. #endif
  164237. return NULL;
  164238. }
  164239. #endif
  164240. #if defined(__TURBOC__) && !defined(__FLAT__)
  164241. if (size != (unsigned long)size)
  164242. ret = NULL;
  164243. else
  164244. ret = farmalloc(size);
  164245. #else
  164246. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164247. if (size != (unsigned long)size)
  164248. ret = NULL;
  164249. else
  164250. ret = halloc(size, 1);
  164251. # else
  164252. if (size != (size_t)size)
  164253. ret = NULL;
  164254. else
  164255. ret = malloc((size_t)size);
  164256. # endif
  164257. #endif
  164258. #ifndef PNG_USER_MEM_SUPPORTED
  164259. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164260. png_error(png_ptr, "Out of Memory");
  164261. #endif
  164262. return (ret);
  164263. }
  164264. void PNGAPI
  164265. png_free(png_structp png_ptr, png_voidp ptr)
  164266. {
  164267. if (png_ptr == NULL || ptr == NULL)
  164268. return;
  164269. #ifdef PNG_USER_MEM_SUPPORTED
  164270. if (png_ptr->free_fn != NULL)
  164271. {
  164272. (*(png_ptr->free_fn))(png_ptr, ptr);
  164273. return;
  164274. }
  164275. else png_free_default(png_ptr, ptr);
  164276. }
  164277. void PNGAPI
  164278. png_free_default(png_structp png_ptr, png_voidp ptr)
  164279. {
  164280. if (png_ptr == NULL || ptr == NULL)
  164281. return;
  164282. #endif /* PNG_USER_MEM_SUPPORTED */
  164283. #if defined(__TURBOC__) && !defined(__FLAT__)
  164284. farfree(ptr);
  164285. #else
  164286. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164287. hfree(ptr);
  164288. # else
  164289. free(ptr);
  164290. # endif
  164291. #endif
  164292. }
  164293. #endif /* Not Borland DOS special memory handler */
  164294. #if defined(PNG_1_0_X)
  164295. # define png_malloc_warn png_malloc
  164296. #else
  164297. png_voidp PNGAPI
  164298. png_malloc_warn(png_structp png_ptr, png_uint_32 size)
  164299. {
  164300. png_voidp ptr;
  164301. png_uint_32 save_flags;
  164302. if(png_ptr == NULL) return (NULL);
  164303. save_flags=png_ptr->flags;
  164304. png_ptr->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
  164305. ptr = (png_voidp)png_malloc((png_structp)png_ptr, size);
  164306. png_ptr->flags=save_flags;
  164307. return(ptr);
  164308. }
  164309. #endif
  164310. png_voidp PNGAPI
  164311. png_memcpy_check (png_structp png_ptr, png_voidp s1, png_voidp s2,
  164312. png_uint_32 length)
  164313. {
  164314. png_size_t size;
  164315. size = (png_size_t)length;
  164316. if ((png_uint_32)size != length)
  164317. png_error(png_ptr,"Overflow in png_memcpy_check.");
  164318. return(png_memcpy (s1, s2, size));
  164319. }
  164320. png_voidp PNGAPI
  164321. png_memset_check (png_structp png_ptr, png_voidp s1, int value,
  164322. png_uint_32 length)
  164323. {
  164324. png_size_t size;
  164325. size = (png_size_t)length;
  164326. if ((png_uint_32)size != length)
  164327. png_error(png_ptr,"Overflow in png_memset_check.");
  164328. return (png_memset (s1, value, size));
  164329. }
  164330. #ifdef PNG_USER_MEM_SUPPORTED
  164331. void PNGAPI
  164332. png_set_mem_fn(png_structp png_ptr, png_voidp mem_ptr, png_malloc_ptr
  164333. malloc_fn, png_free_ptr free_fn)
  164334. {
  164335. if(png_ptr != NULL) {
  164336. png_ptr->mem_ptr = mem_ptr;
  164337. png_ptr->malloc_fn = malloc_fn;
  164338. png_ptr->free_fn = free_fn;
  164339. }
  164340. }
  164341. png_voidp PNGAPI
  164342. png_get_mem_ptr(png_structp png_ptr)
  164343. {
  164344. if(png_ptr == NULL) return (NULL);
  164345. return ((png_voidp)png_ptr->mem_ptr);
  164346. }
  164347. #endif /* PNG_USER_MEM_SUPPORTED */
  164348. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  164349. /*** End of inlined file: pngmem.c ***/
  164350. /*** Start of inlined file: pngread.c ***/
  164351. #define PNG_INTERNAL
  164352. #if defined(PNG_READ_SUPPORTED)
  164353. png_structp PNGAPI
  164354. png_create_read_struct(png_const_charp user_png_ver, png_voidp error_ptr,
  164355. png_error_ptr error_fn, png_error_ptr warn_fn)
  164356. {
  164357. #ifdef PNG_USER_MEM_SUPPORTED
  164358. return (png_create_read_struct_2(user_png_ver, error_ptr, error_fn,
  164359. warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL));
  164360. }
  164361. png_structp PNGAPI
  164362. png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
  164363. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  164364. png_malloc_ptr malloc_fn, png_free_ptr free_fn)
  164365. {
  164366. #endif /* PNG_USER_MEM_SUPPORTED */
  164367. png_structp png_ptr;
  164368. #ifdef PNG_SETJMP_SUPPORTED
  164369. #ifdef USE_FAR_KEYWORD
  164370. jmp_buf jmpbuf;
  164371. #endif
  164372. #endif
  164373. int i;
  164374. png_debug(1, "in png_create_read_struct\n");
  164375. #ifdef PNG_USER_MEM_SUPPORTED
  164376. png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
  164377. (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr);
  164378. #else
  164379. png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  164380. #endif
  164381. if (png_ptr == NULL)
  164382. return (NULL);
  164383. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  164384. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  164385. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  164386. #endif
  164387. #ifdef PNG_SETJMP_SUPPORTED
  164388. #ifdef USE_FAR_KEYWORD
  164389. if (setjmp(jmpbuf))
  164390. #else
  164391. if (setjmp(png_ptr->jmpbuf))
  164392. #endif
  164393. {
  164394. png_free(png_ptr, png_ptr->zbuf);
  164395. png_ptr->zbuf=NULL;
  164396. #ifdef PNG_USER_MEM_SUPPORTED
  164397. png_destroy_struct_2((png_voidp)png_ptr,
  164398. (png_free_ptr)free_fn, (png_voidp)mem_ptr);
  164399. #else
  164400. png_destroy_struct((png_voidp)png_ptr);
  164401. #endif
  164402. return (NULL);
  164403. }
  164404. #ifdef USE_FAR_KEYWORD
  164405. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  164406. #endif
  164407. #endif
  164408. #ifdef PNG_USER_MEM_SUPPORTED
  164409. png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
  164410. #endif
  164411. png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
  164412. i=0;
  164413. do
  164414. {
  164415. if(user_png_ver[i] != png_libpng_ver[i])
  164416. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  164417. } while (png_libpng_ver[i++]);
  164418. if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
  164419. {
  164420. if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
  164421. (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
  164422. (user_png_ver[0] == '0' && user_png_ver[2] < '9'))
  164423. {
  164424. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  164425. char msg[80];
  164426. if (user_png_ver)
  164427. {
  164428. png_snprintf(msg, 80,
  164429. "Application was compiled with png.h from libpng-%.20s",
  164430. user_png_ver);
  164431. png_warning(png_ptr, msg);
  164432. }
  164433. png_snprintf(msg, 80,
  164434. "Application is running with png.c from libpng-%.20s",
  164435. png_libpng_ver);
  164436. png_warning(png_ptr, msg);
  164437. #endif
  164438. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  164439. png_ptr->flags=0;
  164440. #endif
  164441. png_error(png_ptr,
  164442. "Incompatible libpng version in application and library");
  164443. }
  164444. }
  164445. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  164446. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  164447. (png_uint_32)png_ptr->zbuf_size);
  164448. png_ptr->zstream.zalloc = png_zalloc;
  164449. png_ptr->zstream.zfree = png_zfree;
  164450. png_ptr->zstream.opaque = (voidpf)png_ptr;
  164451. switch (inflateInit(&png_ptr->zstream))
  164452. {
  164453. case Z_OK: /* Do nothing */ break;
  164454. case Z_MEM_ERROR:
  164455. case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory error"); break;
  164456. case Z_VERSION_ERROR: png_error(png_ptr, "zlib version error"); break;
  164457. default: png_error(png_ptr, "Unknown zlib error");
  164458. }
  164459. png_ptr->zstream.next_out = png_ptr->zbuf;
  164460. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  164461. png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL);
  164462. #ifdef PNG_SETJMP_SUPPORTED
  164463. #ifdef USE_FAR_KEYWORD
  164464. if (setjmp(jmpbuf))
  164465. PNG_ABORT();
  164466. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  164467. #else
  164468. if (setjmp(png_ptr->jmpbuf))
  164469. PNG_ABORT();
  164470. #endif
  164471. #endif
  164472. return (png_ptr);
  164473. }
  164474. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  164475. #undef png_read_init
  164476. void PNGAPI
  164477. png_read_init(png_structp png_ptr)
  164478. {
  164479. png_read_init_2(png_ptr, "1.0.6 or earlier", 0, 0);
  164480. }
  164481. void PNGAPI
  164482. png_read_init_2(png_structp png_ptr, png_const_charp user_png_ver,
  164483. png_size_t png_struct_size, png_size_t png_info_size)
  164484. {
  164485. if(png_ptr == NULL) return;
  164486. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  164487. if(png_sizeof(png_struct) > png_struct_size ||
  164488. png_sizeof(png_info) > png_info_size)
  164489. {
  164490. char msg[80];
  164491. png_ptr->warning_fn=NULL;
  164492. if (user_png_ver)
  164493. {
  164494. png_snprintf(msg, 80,
  164495. "Application was compiled with png.h from libpng-%.20s",
  164496. user_png_ver);
  164497. png_warning(png_ptr, msg);
  164498. }
  164499. png_snprintf(msg, 80,
  164500. "Application is running with png.c from libpng-%.20s",
  164501. png_libpng_ver);
  164502. png_warning(png_ptr, msg);
  164503. }
  164504. #endif
  164505. if(png_sizeof(png_struct) > png_struct_size)
  164506. {
  164507. png_ptr->error_fn=NULL;
  164508. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  164509. png_ptr->flags=0;
  164510. #endif
  164511. png_error(png_ptr,
  164512. "The png struct allocated by the application for reading is too small.");
  164513. }
  164514. if(png_sizeof(png_info) > png_info_size)
  164515. {
  164516. png_ptr->error_fn=NULL;
  164517. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  164518. png_ptr->flags=0;
  164519. #endif
  164520. png_error(png_ptr,
  164521. "The info struct allocated by application for reading is too small.");
  164522. }
  164523. png_read_init_3(&png_ptr, user_png_ver, png_struct_size);
  164524. }
  164525. #endif /* PNG_1_0_X || PNG_1_2_X */
  164526. void PNGAPI
  164527. png_read_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
  164528. png_size_t png_struct_size)
  164529. {
  164530. #ifdef PNG_SETJMP_SUPPORTED
  164531. jmp_buf tmp_jmp; /* to save current jump buffer */
  164532. #endif
  164533. int i=0;
  164534. png_structp png_ptr=*ptr_ptr;
  164535. if(png_ptr == NULL) return;
  164536. do
  164537. {
  164538. if(user_png_ver[i] != png_libpng_ver[i])
  164539. {
  164540. #ifdef PNG_LEGACY_SUPPORTED
  164541. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  164542. #else
  164543. png_ptr->warning_fn=NULL;
  164544. png_warning(png_ptr,
  164545. "Application uses deprecated png_read_init() and should be recompiled.");
  164546. break;
  164547. #endif
  164548. }
  164549. } while (png_libpng_ver[i++]);
  164550. png_debug(1, "in png_read_init_3\n");
  164551. #ifdef PNG_SETJMP_SUPPORTED
  164552. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  164553. #endif
  164554. if(png_sizeof(png_struct) > png_struct_size)
  164555. {
  164556. png_destroy_struct(png_ptr);
  164557. *ptr_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  164558. png_ptr = *ptr_ptr;
  164559. }
  164560. png_memset(png_ptr, 0, png_sizeof (png_struct));
  164561. #ifdef PNG_SETJMP_SUPPORTED
  164562. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  164563. #endif
  164564. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  164565. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  164566. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  164567. #endif
  164568. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  164569. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  164570. (png_uint_32)png_ptr->zbuf_size);
  164571. png_ptr->zstream.zalloc = png_zalloc;
  164572. png_ptr->zstream.zfree = png_zfree;
  164573. png_ptr->zstream.opaque = (voidpf)png_ptr;
  164574. switch (inflateInit(&png_ptr->zstream))
  164575. {
  164576. case Z_OK: /* Do nothing */ break;
  164577. case Z_MEM_ERROR:
  164578. case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory"); break;
  164579. case Z_VERSION_ERROR: png_error(png_ptr, "zlib version"); break;
  164580. default: png_error(png_ptr, "Unknown zlib error");
  164581. }
  164582. png_ptr->zstream.next_out = png_ptr->zbuf;
  164583. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  164584. png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL);
  164585. }
  164586. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  164587. void PNGAPI
  164588. png_read_info(png_structp png_ptr, png_infop info_ptr)
  164589. {
  164590. if(png_ptr == NULL) return;
  164591. png_debug(1, "in png_read_info\n");
  164592. if (png_ptr->sig_bytes < 8)
  164593. {
  164594. png_size_t num_checked = png_ptr->sig_bytes,
  164595. num_to_check = 8 - num_checked;
  164596. png_read_data(png_ptr, &(info_ptr->signature[num_checked]), num_to_check);
  164597. png_ptr->sig_bytes = 8;
  164598. if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
  164599. {
  164600. if (num_checked < 4 &&
  164601. png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))
  164602. png_error(png_ptr, "Not a PNG file");
  164603. else
  164604. png_error(png_ptr, "PNG file corrupted by ASCII conversion");
  164605. }
  164606. if (num_checked < 3)
  164607. png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
  164608. }
  164609. for(;;)
  164610. {
  164611. #ifdef PNG_USE_LOCAL_ARRAYS
  164612. PNG_CONST PNG_IHDR;
  164613. PNG_CONST PNG_IDAT;
  164614. PNG_CONST PNG_IEND;
  164615. PNG_CONST PNG_PLTE;
  164616. #if defined(PNG_READ_bKGD_SUPPORTED)
  164617. PNG_CONST PNG_bKGD;
  164618. #endif
  164619. #if defined(PNG_READ_cHRM_SUPPORTED)
  164620. PNG_CONST PNG_cHRM;
  164621. #endif
  164622. #if defined(PNG_READ_gAMA_SUPPORTED)
  164623. PNG_CONST PNG_gAMA;
  164624. #endif
  164625. #if defined(PNG_READ_hIST_SUPPORTED)
  164626. PNG_CONST PNG_hIST;
  164627. #endif
  164628. #if defined(PNG_READ_iCCP_SUPPORTED)
  164629. PNG_CONST PNG_iCCP;
  164630. #endif
  164631. #if defined(PNG_READ_iTXt_SUPPORTED)
  164632. PNG_CONST PNG_iTXt;
  164633. #endif
  164634. #if defined(PNG_READ_oFFs_SUPPORTED)
  164635. PNG_CONST PNG_oFFs;
  164636. #endif
  164637. #if defined(PNG_READ_pCAL_SUPPORTED)
  164638. PNG_CONST PNG_pCAL;
  164639. #endif
  164640. #if defined(PNG_READ_pHYs_SUPPORTED)
  164641. PNG_CONST PNG_pHYs;
  164642. #endif
  164643. #if defined(PNG_READ_sBIT_SUPPORTED)
  164644. PNG_CONST PNG_sBIT;
  164645. #endif
  164646. #if defined(PNG_READ_sCAL_SUPPORTED)
  164647. PNG_CONST PNG_sCAL;
  164648. #endif
  164649. #if defined(PNG_READ_sPLT_SUPPORTED)
  164650. PNG_CONST PNG_sPLT;
  164651. #endif
  164652. #if defined(PNG_READ_sRGB_SUPPORTED)
  164653. PNG_CONST PNG_sRGB;
  164654. #endif
  164655. #if defined(PNG_READ_tEXt_SUPPORTED)
  164656. PNG_CONST PNG_tEXt;
  164657. #endif
  164658. #if defined(PNG_READ_tIME_SUPPORTED)
  164659. PNG_CONST PNG_tIME;
  164660. #endif
  164661. #if defined(PNG_READ_tRNS_SUPPORTED)
  164662. PNG_CONST PNG_tRNS;
  164663. #endif
  164664. #if defined(PNG_READ_zTXt_SUPPORTED)
  164665. PNG_CONST PNG_zTXt;
  164666. #endif
  164667. #endif /* PNG_USE_LOCAL_ARRAYS */
  164668. png_byte chunk_length[4];
  164669. png_uint_32 length;
  164670. png_read_data(png_ptr, chunk_length, 4);
  164671. length = png_get_uint_31(png_ptr,chunk_length);
  164672. png_reset_crc(png_ptr);
  164673. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  164674. png_debug2(0, "Reading %s chunk, length=%lu.\n", png_ptr->chunk_name,
  164675. length);
  164676. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164677. if(png_ptr->mode & PNG_AFTER_IDAT)
  164678. png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
  164679. if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
  164680. png_handle_IHDR(png_ptr, info_ptr, length);
  164681. else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
  164682. png_handle_IEND(png_ptr, info_ptr, length);
  164683. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  164684. else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
  164685. {
  164686. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164687. png_ptr->mode |= PNG_HAVE_IDAT;
  164688. png_handle_unknown(png_ptr, info_ptr, length);
  164689. if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  164690. png_ptr->mode |= PNG_HAVE_PLTE;
  164691. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164692. {
  164693. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  164694. png_error(png_ptr, "Missing IHDR before IDAT");
  164695. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  164696. !(png_ptr->mode & PNG_HAVE_PLTE))
  164697. png_error(png_ptr, "Missing PLTE before IDAT");
  164698. break;
  164699. }
  164700. }
  164701. #endif
  164702. else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  164703. png_handle_PLTE(png_ptr, info_ptr, length);
  164704. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164705. {
  164706. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  164707. png_error(png_ptr, "Missing IHDR before IDAT");
  164708. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  164709. !(png_ptr->mode & PNG_HAVE_PLTE))
  164710. png_error(png_ptr, "Missing PLTE before IDAT");
  164711. png_ptr->idat_size = length;
  164712. png_ptr->mode |= PNG_HAVE_IDAT;
  164713. break;
  164714. }
  164715. #if defined(PNG_READ_bKGD_SUPPORTED)
  164716. else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
  164717. png_handle_bKGD(png_ptr, info_ptr, length);
  164718. #endif
  164719. #if defined(PNG_READ_cHRM_SUPPORTED)
  164720. else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
  164721. png_handle_cHRM(png_ptr, info_ptr, length);
  164722. #endif
  164723. #if defined(PNG_READ_gAMA_SUPPORTED)
  164724. else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
  164725. png_handle_gAMA(png_ptr, info_ptr, length);
  164726. #endif
  164727. #if defined(PNG_READ_hIST_SUPPORTED)
  164728. else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
  164729. png_handle_hIST(png_ptr, info_ptr, length);
  164730. #endif
  164731. #if defined(PNG_READ_oFFs_SUPPORTED)
  164732. else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
  164733. png_handle_oFFs(png_ptr, info_ptr, length);
  164734. #endif
  164735. #if defined(PNG_READ_pCAL_SUPPORTED)
  164736. else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
  164737. png_handle_pCAL(png_ptr, info_ptr, length);
  164738. #endif
  164739. #if defined(PNG_READ_sCAL_SUPPORTED)
  164740. else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
  164741. png_handle_sCAL(png_ptr, info_ptr, length);
  164742. #endif
  164743. #if defined(PNG_READ_pHYs_SUPPORTED)
  164744. else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
  164745. png_handle_pHYs(png_ptr, info_ptr, length);
  164746. #endif
  164747. #if defined(PNG_READ_sBIT_SUPPORTED)
  164748. else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
  164749. png_handle_sBIT(png_ptr, info_ptr, length);
  164750. #endif
  164751. #if defined(PNG_READ_sRGB_SUPPORTED)
  164752. else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
  164753. png_handle_sRGB(png_ptr, info_ptr, length);
  164754. #endif
  164755. #if defined(PNG_READ_iCCP_SUPPORTED)
  164756. else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
  164757. png_handle_iCCP(png_ptr, info_ptr, length);
  164758. #endif
  164759. #if defined(PNG_READ_sPLT_SUPPORTED)
  164760. else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
  164761. png_handle_sPLT(png_ptr, info_ptr, length);
  164762. #endif
  164763. #if defined(PNG_READ_tEXt_SUPPORTED)
  164764. else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
  164765. png_handle_tEXt(png_ptr, info_ptr, length);
  164766. #endif
  164767. #if defined(PNG_READ_tIME_SUPPORTED)
  164768. else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
  164769. png_handle_tIME(png_ptr, info_ptr, length);
  164770. #endif
  164771. #if defined(PNG_READ_tRNS_SUPPORTED)
  164772. else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
  164773. png_handle_tRNS(png_ptr, info_ptr, length);
  164774. #endif
  164775. #if defined(PNG_READ_zTXt_SUPPORTED)
  164776. else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
  164777. png_handle_zTXt(png_ptr, info_ptr, length);
  164778. #endif
  164779. #if defined(PNG_READ_iTXt_SUPPORTED)
  164780. else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
  164781. png_handle_iTXt(png_ptr, info_ptr, length);
  164782. #endif
  164783. else
  164784. png_handle_unknown(png_ptr, info_ptr, length);
  164785. }
  164786. }
  164787. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  164788. void PNGAPI
  164789. png_read_update_info(png_structp png_ptr, png_infop info_ptr)
  164790. {
  164791. png_debug(1, "in png_read_update_info\n");
  164792. if(png_ptr == NULL) return;
  164793. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  164794. png_read_start_row(png_ptr);
  164795. else
  164796. png_warning(png_ptr,
  164797. "Ignoring extra png_read_update_info() call; row buffer not reallocated");
  164798. png_read_transform_info(png_ptr, info_ptr);
  164799. }
  164800. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  164801. void PNGAPI
  164802. png_start_read_image(png_structp png_ptr)
  164803. {
  164804. png_debug(1, "in png_start_read_image\n");
  164805. if(png_ptr == NULL) return;
  164806. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  164807. png_read_start_row(png_ptr);
  164808. }
  164809. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  164810. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  164811. void PNGAPI
  164812. png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
  164813. {
  164814. #ifdef PNG_USE_LOCAL_ARRAYS
  164815. PNG_CONST PNG_IDAT;
  164816. PNG_CONST int png_pass_dsp_mask[7] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55,
  164817. 0xff};
  164818. PNG_CONST int png_pass_mask[7] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
  164819. #endif
  164820. int ret;
  164821. if(png_ptr == NULL) return;
  164822. png_debug2(1, "in png_read_row (row %lu, pass %d)\n",
  164823. png_ptr->row_number, png_ptr->pass);
  164824. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  164825. png_read_start_row(png_ptr);
  164826. if (png_ptr->row_number == 0 && png_ptr->pass == 0)
  164827. {
  164828. #if defined(PNG_WRITE_INVERT_SUPPORTED) && !defined(PNG_READ_INVERT_SUPPORTED)
  164829. if (png_ptr->transformations & PNG_INVERT_MONO)
  164830. png_warning(png_ptr, "PNG_READ_INVERT_SUPPORTED is not defined.");
  164831. #endif
  164832. #if defined(PNG_WRITE_FILLER_SUPPORTED) && !defined(PNG_READ_FILLER_SUPPORTED)
  164833. if (png_ptr->transformations & PNG_FILLER)
  164834. png_warning(png_ptr, "PNG_READ_FILLER_SUPPORTED is not defined.");
  164835. #endif
  164836. #if defined(PNG_WRITE_PACKSWAP_SUPPORTED) && !defined(PNG_READ_PACKSWAP_SUPPORTED)
  164837. if (png_ptr->transformations & PNG_PACKSWAP)
  164838. png_warning(png_ptr, "PNG_READ_PACKSWAP_SUPPORTED is not defined.");
  164839. #endif
  164840. #if defined(PNG_WRITE_PACK_SUPPORTED) && !defined(PNG_READ_PACK_SUPPORTED)
  164841. if (png_ptr->transformations & PNG_PACK)
  164842. png_warning(png_ptr, "PNG_READ_PACK_SUPPORTED is not defined.");
  164843. #endif
  164844. #if defined(PNG_WRITE_SHIFT_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED)
  164845. if (png_ptr->transformations & PNG_SHIFT)
  164846. png_warning(png_ptr, "PNG_READ_SHIFT_SUPPORTED is not defined.");
  164847. #endif
  164848. #if defined(PNG_WRITE_BGR_SUPPORTED) && !defined(PNG_READ_BGR_SUPPORTED)
  164849. if (png_ptr->transformations & PNG_BGR)
  164850. png_warning(png_ptr, "PNG_READ_BGR_SUPPORTED is not defined.");
  164851. #endif
  164852. #if defined(PNG_WRITE_SWAP_SUPPORTED) && !defined(PNG_READ_SWAP_SUPPORTED)
  164853. if (png_ptr->transformations & PNG_SWAP_BYTES)
  164854. png_warning(png_ptr, "PNG_READ_SWAP_SUPPORTED is not defined.");
  164855. #endif
  164856. }
  164857. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  164858. if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
  164859. {
  164860. switch (png_ptr->pass)
  164861. {
  164862. case 0:
  164863. if (png_ptr->row_number & 0x07)
  164864. {
  164865. if (dsp_row != NULL)
  164866. png_combine_row(png_ptr, dsp_row,
  164867. png_pass_dsp_mask[png_ptr->pass]);
  164868. png_read_finish_row(png_ptr);
  164869. return;
  164870. }
  164871. break;
  164872. case 1:
  164873. if ((png_ptr->row_number & 0x07) || png_ptr->width < 5)
  164874. {
  164875. if (dsp_row != NULL)
  164876. png_combine_row(png_ptr, dsp_row,
  164877. png_pass_dsp_mask[png_ptr->pass]);
  164878. png_read_finish_row(png_ptr);
  164879. return;
  164880. }
  164881. break;
  164882. case 2:
  164883. if ((png_ptr->row_number & 0x07) != 4)
  164884. {
  164885. if (dsp_row != NULL && (png_ptr->row_number & 4))
  164886. png_combine_row(png_ptr, dsp_row,
  164887. png_pass_dsp_mask[png_ptr->pass]);
  164888. png_read_finish_row(png_ptr);
  164889. return;
  164890. }
  164891. break;
  164892. case 3:
  164893. if ((png_ptr->row_number & 3) || png_ptr->width < 3)
  164894. {
  164895. if (dsp_row != NULL)
  164896. png_combine_row(png_ptr, dsp_row,
  164897. png_pass_dsp_mask[png_ptr->pass]);
  164898. png_read_finish_row(png_ptr);
  164899. return;
  164900. }
  164901. break;
  164902. case 4:
  164903. if ((png_ptr->row_number & 3) != 2)
  164904. {
  164905. if (dsp_row != NULL && (png_ptr->row_number & 2))
  164906. png_combine_row(png_ptr, dsp_row,
  164907. png_pass_dsp_mask[png_ptr->pass]);
  164908. png_read_finish_row(png_ptr);
  164909. return;
  164910. }
  164911. break;
  164912. case 5:
  164913. if ((png_ptr->row_number & 1) || png_ptr->width < 2)
  164914. {
  164915. if (dsp_row != NULL)
  164916. png_combine_row(png_ptr, dsp_row,
  164917. png_pass_dsp_mask[png_ptr->pass]);
  164918. png_read_finish_row(png_ptr);
  164919. return;
  164920. }
  164921. break;
  164922. case 6:
  164923. if (!(png_ptr->row_number & 1))
  164924. {
  164925. png_read_finish_row(png_ptr);
  164926. return;
  164927. }
  164928. break;
  164929. }
  164930. }
  164931. #endif
  164932. if (!(png_ptr->mode & PNG_HAVE_IDAT))
  164933. png_error(png_ptr, "Invalid attempt to read row data");
  164934. png_ptr->zstream.next_out = png_ptr->row_buf;
  164935. png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
  164936. do
  164937. {
  164938. if (!(png_ptr->zstream.avail_in))
  164939. {
  164940. while (!png_ptr->idat_size)
  164941. {
  164942. png_byte chunk_length[4];
  164943. png_crc_finish(png_ptr, 0);
  164944. png_read_data(png_ptr, chunk_length, 4);
  164945. png_ptr->idat_size = png_get_uint_31(png_ptr,chunk_length);
  164946. png_reset_crc(png_ptr);
  164947. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  164948. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164949. png_error(png_ptr, "Not enough image data");
  164950. }
  164951. png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size;
  164952. png_ptr->zstream.next_in = png_ptr->zbuf;
  164953. if (png_ptr->zbuf_size > png_ptr->idat_size)
  164954. png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size;
  164955. png_crc_read(png_ptr, png_ptr->zbuf,
  164956. (png_size_t)png_ptr->zstream.avail_in);
  164957. png_ptr->idat_size -= png_ptr->zstream.avail_in;
  164958. }
  164959. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  164960. if (ret == Z_STREAM_END)
  164961. {
  164962. if (png_ptr->zstream.avail_out || png_ptr->zstream.avail_in ||
  164963. png_ptr->idat_size)
  164964. png_error(png_ptr, "Extra compressed data");
  164965. png_ptr->mode |= PNG_AFTER_IDAT;
  164966. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  164967. break;
  164968. }
  164969. if (ret != Z_OK)
  164970. png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg :
  164971. "Decompression error");
  164972. } while (png_ptr->zstream.avail_out);
  164973. png_ptr->row_info.color_type = png_ptr->color_type;
  164974. png_ptr->row_info.width = png_ptr->iwidth;
  164975. png_ptr->row_info.channels = png_ptr->channels;
  164976. png_ptr->row_info.bit_depth = png_ptr->bit_depth;
  164977. png_ptr->row_info.pixel_depth = png_ptr->pixel_depth;
  164978. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  164979. png_ptr->row_info.width);
  164980. if(png_ptr->row_buf[0])
  164981. png_read_filter_row(png_ptr, &(png_ptr->row_info),
  164982. png_ptr->row_buf + 1, png_ptr->prev_row + 1,
  164983. (int)(png_ptr->row_buf[0]));
  164984. png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf,
  164985. png_ptr->rowbytes + 1);
  164986. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  164987. if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  164988. (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
  164989. {
  164990. png_do_read_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1);
  164991. }
  164992. #endif
  164993. if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))
  164994. png_do_read_transformations(png_ptr);
  164995. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  164996. if (png_ptr->interlaced &&
  164997. (png_ptr->transformations & PNG_INTERLACE))
  164998. {
  164999. if (png_ptr->pass < 6)
  165000. png_do_read_interlace(png_ptr);
  165001. if (dsp_row != NULL)
  165002. png_combine_row(png_ptr, dsp_row,
  165003. png_pass_dsp_mask[png_ptr->pass]);
  165004. if (row != NULL)
  165005. png_combine_row(png_ptr, row,
  165006. png_pass_mask[png_ptr->pass]);
  165007. }
  165008. else
  165009. #endif
  165010. {
  165011. if (row != NULL)
  165012. png_combine_row(png_ptr, row, 0xff);
  165013. if (dsp_row != NULL)
  165014. png_combine_row(png_ptr, dsp_row, 0xff);
  165015. }
  165016. png_read_finish_row(png_ptr);
  165017. if (png_ptr->read_row_fn != NULL)
  165018. (*(png_ptr->read_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
  165019. }
  165020. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165021. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165022. void PNGAPI
  165023. png_read_rows(png_structp png_ptr, png_bytepp row,
  165024. png_bytepp display_row, png_uint_32 num_rows)
  165025. {
  165026. png_uint_32 i;
  165027. png_bytepp rp;
  165028. png_bytepp dp;
  165029. png_debug(1, "in png_read_rows\n");
  165030. if(png_ptr == NULL) return;
  165031. rp = row;
  165032. dp = display_row;
  165033. if (rp != NULL && dp != NULL)
  165034. for (i = 0; i < num_rows; i++)
  165035. {
  165036. png_bytep rptr = *rp++;
  165037. png_bytep dptr = *dp++;
  165038. png_read_row(png_ptr, rptr, dptr);
  165039. }
  165040. else if(rp != NULL)
  165041. for (i = 0; i < num_rows; i++)
  165042. {
  165043. png_bytep rptr = *rp;
  165044. png_read_row(png_ptr, rptr, png_bytep_NULL);
  165045. rp++;
  165046. }
  165047. else if(dp != NULL)
  165048. for (i = 0; i < num_rows; i++)
  165049. {
  165050. png_bytep dptr = *dp;
  165051. png_read_row(png_ptr, png_bytep_NULL, dptr);
  165052. dp++;
  165053. }
  165054. }
  165055. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165056. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165057. void PNGAPI
  165058. png_read_image(png_structp png_ptr, png_bytepp image)
  165059. {
  165060. png_uint_32 i,image_height;
  165061. int pass, j;
  165062. png_bytepp rp;
  165063. png_debug(1, "in png_read_image\n");
  165064. if(png_ptr == NULL) return;
  165065. #ifdef PNG_READ_INTERLACING_SUPPORTED
  165066. pass = png_set_interlace_handling(png_ptr);
  165067. #else
  165068. if (png_ptr->interlaced)
  165069. png_error(png_ptr,
  165070. "Cannot read interlaced image -- interlace handler disabled.");
  165071. pass = 1;
  165072. #endif
  165073. image_height=png_ptr->height;
  165074. png_ptr->num_rows = image_height; /* Make sure this is set correctly */
  165075. for (j = 0; j < pass; j++)
  165076. {
  165077. rp = image;
  165078. for (i = 0; i < image_height; i++)
  165079. {
  165080. png_read_row(png_ptr, *rp, png_bytep_NULL);
  165081. rp++;
  165082. }
  165083. }
  165084. }
  165085. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165086. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165087. void PNGAPI
  165088. png_read_end(png_structp png_ptr, png_infop info_ptr)
  165089. {
  165090. png_byte chunk_length[4];
  165091. png_uint_32 length;
  165092. png_debug(1, "in png_read_end\n");
  165093. if(png_ptr == NULL) return;
  165094. png_crc_finish(png_ptr, 0); /* Finish off CRC from last IDAT chunk */
  165095. do
  165096. {
  165097. #ifdef PNG_USE_LOCAL_ARRAYS
  165098. PNG_CONST PNG_IHDR;
  165099. PNG_CONST PNG_IDAT;
  165100. PNG_CONST PNG_IEND;
  165101. PNG_CONST PNG_PLTE;
  165102. #if defined(PNG_READ_bKGD_SUPPORTED)
  165103. PNG_CONST PNG_bKGD;
  165104. #endif
  165105. #if defined(PNG_READ_cHRM_SUPPORTED)
  165106. PNG_CONST PNG_cHRM;
  165107. #endif
  165108. #if defined(PNG_READ_gAMA_SUPPORTED)
  165109. PNG_CONST PNG_gAMA;
  165110. #endif
  165111. #if defined(PNG_READ_hIST_SUPPORTED)
  165112. PNG_CONST PNG_hIST;
  165113. #endif
  165114. #if defined(PNG_READ_iCCP_SUPPORTED)
  165115. PNG_CONST PNG_iCCP;
  165116. #endif
  165117. #if defined(PNG_READ_iTXt_SUPPORTED)
  165118. PNG_CONST PNG_iTXt;
  165119. #endif
  165120. #if defined(PNG_READ_oFFs_SUPPORTED)
  165121. PNG_CONST PNG_oFFs;
  165122. #endif
  165123. #if defined(PNG_READ_pCAL_SUPPORTED)
  165124. PNG_CONST PNG_pCAL;
  165125. #endif
  165126. #if defined(PNG_READ_pHYs_SUPPORTED)
  165127. PNG_CONST PNG_pHYs;
  165128. #endif
  165129. #if defined(PNG_READ_sBIT_SUPPORTED)
  165130. PNG_CONST PNG_sBIT;
  165131. #endif
  165132. #if defined(PNG_READ_sCAL_SUPPORTED)
  165133. PNG_CONST PNG_sCAL;
  165134. #endif
  165135. #if defined(PNG_READ_sPLT_SUPPORTED)
  165136. PNG_CONST PNG_sPLT;
  165137. #endif
  165138. #if defined(PNG_READ_sRGB_SUPPORTED)
  165139. PNG_CONST PNG_sRGB;
  165140. #endif
  165141. #if defined(PNG_READ_tEXt_SUPPORTED)
  165142. PNG_CONST PNG_tEXt;
  165143. #endif
  165144. #if defined(PNG_READ_tIME_SUPPORTED)
  165145. PNG_CONST PNG_tIME;
  165146. #endif
  165147. #if defined(PNG_READ_tRNS_SUPPORTED)
  165148. PNG_CONST PNG_tRNS;
  165149. #endif
  165150. #if defined(PNG_READ_zTXt_SUPPORTED)
  165151. PNG_CONST PNG_zTXt;
  165152. #endif
  165153. #endif /* PNG_USE_LOCAL_ARRAYS */
  165154. png_read_data(png_ptr, chunk_length, 4);
  165155. length = png_get_uint_31(png_ptr,chunk_length);
  165156. png_reset_crc(png_ptr);
  165157. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  165158. png_debug1(0, "Reading %s chunk.\n", png_ptr->chunk_name);
  165159. if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
  165160. png_handle_IHDR(png_ptr, info_ptr, length);
  165161. else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
  165162. png_handle_IEND(png_ptr, info_ptr, length);
  165163. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  165164. else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
  165165. {
  165166. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165167. {
  165168. if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
  165169. png_error(png_ptr, "Too many IDAT's found");
  165170. }
  165171. png_handle_unknown(png_ptr, info_ptr, length);
  165172. if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165173. png_ptr->mode |= PNG_HAVE_PLTE;
  165174. }
  165175. #endif
  165176. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165177. {
  165178. if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
  165179. png_error(png_ptr, "Too many IDAT's found");
  165180. png_crc_finish(png_ptr, length);
  165181. }
  165182. else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165183. png_handle_PLTE(png_ptr, info_ptr, length);
  165184. #if defined(PNG_READ_bKGD_SUPPORTED)
  165185. else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
  165186. png_handle_bKGD(png_ptr, info_ptr, length);
  165187. #endif
  165188. #if defined(PNG_READ_cHRM_SUPPORTED)
  165189. else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
  165190. png_handle_cHRM(png_ptr, info_ptr, length);
  165191. #endif
  165192. #if defined(PNG_READ_gAMA_SUPPORTED)
  165193. else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
  165194. png_handle_gAMA(png_ptr, info_ptr, length);
  165195. #endif
  165196. #if defined(PNG_READ_hIST_SUPPORTED)
  165197. else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
  165198. png_handle_hIST(png_ptr, info_ptr, length);
  165199. #endif
  165200. #if defined(PNG_READ_oFFs_SUPPORTED)
  165201. else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
  165202. png_handle_oFFs(png_ptr, info_ptr, length);
  165203. #endif
  165204. #if defined(PNG_READ_pCAL_SUPPORTED)
  165205. else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
  165206. png_handle_pCAL(png_ptr, info_ptr, length);
  165207. #endif
  165208. #if defined(PNG_READ_sCAL_SUPPORTED)
  165209. else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
  165210. png_handle_sCAL(png_ptr, info_ptr, length);
  165211. #endif
  165212. #if defined(PNG_READ_pHYs_SUPPORTED)
  165213. else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
  165214. png_handle_pHYs(png_ptr, info_ptr, length);
  165215. #endif
  165216. #if defined(PNG_READ_sBIT_SUPPORTED)
  165217. else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
  165218. png_handle_sBIT(png_ptr, info_ptr, length);
  165219. #endif
  165220. #if defined(PNG_READ_sRGB_SUPPORTED)
  165221. else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
  165222. png_handle_sRGB(png_ptr, info_ptr, length);
  165223. #endif
  165224. #if defined(PNG_READ_iCCP_SUPPORTED)
  165225. else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
  165226. png_handle_iCCP(png_ptr, info_ptr, length);
  165227. #endif
  165228. #if defined(PNG_READ_sPLT_SUPPORTED)
  165229. else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
  165230. png_handle_sPLT(png_ptr, info_ptr, length);
  165231. #endif
  165232. #if defined(PNG_READ_tEXt_SUPPORTED)
  165233. else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
  165234. png_handle_tEXt(png_ptr, info_ptr, length);
  165235. #endif
  165236. #if defined(PNG_READ_tIME_SUPPORTED)
  165237. else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
  165238. png_handle_tIME(png_ptr, info_ptr, length);
  165239. #endif
  165240. #if defined(PNG_READ_tRNS_SUPPORTED)
  165241. else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
  165242. png_handle_tRNS(png_ptr, info_ptr, length);
  165243. #endif
  165244. #if defined(PNG_READ_zTXt_SUPPORTED)
  165245. else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
  165246. png_handle_zTXt(png_ptr, info_ptr, length);
  165247. #endif
  165248. #if defined(PNG_READ_iTXt_SUPPORTED)
  165249. else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
  165250. png_handle_iTXt(png_ptr, info_ptr, length);
  165251. #endif
  165252. else
  165253. png_handle_unknown(png_ptr, info_ptr, length);
  165254. } while (!(png_ptr->mode & PNG_HAVE_IEND));
  165255. }
  165256. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165257. void PNGAPI
  165258. png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
  165259. png_infopp end_info_ptr_ptr)
  165260. {
  165261. png_structp png_ptr = NULL;
  165262. png_infop info_ptr = NULL, end_info_ptr = NULL;
  165263. #ifdef PNG_USER_MEM_SUPPORTED
  165264. png_free_ptr free_fn;
  165265. png_voidp mem_ptr;
  165266. #endif
  165267. png_debug(1, "in png_destroy_read_struct\n");
  165268. if (png_ptr_ptr != NULL)
  165269. png_ptr = *png_ptr_ptr;
  165270. if (info_ptr_ptr != NULL)
  165271. info_ptr = *info_ptr_ptr;
  165272. if (end_info_ptr_ptr != NULL)
  165273. end_info_ptr = *end_info_ptr_ptr;
  165274. #ifdef PNG_USER_MEM_SUPPORTED
  165275. free_fn = png_ptr->free_fn;
  165276. mem_ptr = png_ptr->mem_ptr;
  165277. #endif
  165278. png_read_destroy(png_ptr, info_ptr, end_info_ptr);
  165279. if (info_ptr != NULL)
  165280. {
  165281. #if defined(PNG_TEXT_SUPPORTED)
  165282. png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, -1);
  165283. #endif
  165284. #ifdef PNG_USER_MEM_SUPPORTED
  165285. png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn,
  165286. (png_voidp)mem_ptr);
  165287. #else
  165288. png_destroy_struct((png_voidp)info_ptr);
  165289. #endif
  165290. *info_ptr_ptr = NULL;
  165291. }
  165292. if (end_info_ptr != NULL)
  165293. {
  165294. #if defined(PNG_READ_TEXT_SUPPORTED)
  165295. png_free_data(png_ptr, end_info_ptr, PNG_FREE_TEXT, -1);
  165296. #endif
  165297. #ifdef PNG_USER_MEM_SUPPORTED
  165298. png_destroy_struct_2((png_voidp)end_info_ptr, (png_free_ptr)free_fn,
  165299. (png_voidp)mem_ptr);
  165300. #else
  165301. png_destroy_struct((png_voidp)end_info_ptr);
  165302. #endif
  165303. *end_info_ptr_ptr = NULL;
  165304. }
  165305. if (png_ptr != NULL)
  165306. {
  165307. #ifdef PNG_USER_MEM_SUPPORTED
  165308. png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn,
  165309. (png_voidp)mem_ptr);
  165310. #else
  165311. png_destroy_struct((png_voidp)png_ptr);
  165312. #endif
  165313. *png_ptr_ptr = NULL;
  165314. }
  165315. }
  165316. void /* PRIVATE */
  165317. png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr)
  165318. {
  165319. #ifdef PNG_SETJMP_SUPPORTED
  165320. jmp_buf tmp_jmp;
  165321. #endif
  165322. png_error_ptr error_fn;
  165323. png_error_ptr warning_fn;
  165324. png_voidp error_ptr;
  165325. #ifdef PNG_USER_MEM_SUPPORTED
  165326. png_free_ptr free_fn;
  165327. #endif
  165328. png_debug(1, "in png_read_destroy\n");
  165329. if (info_ptr != NULL)
  165330. png_info_destroy(png_ptr, info_ptr);
  165331. if (end_info_ptr != NULL)
  165332. png_info_destroy(png_ptr, end_info_ptr);
  165333. png_free(png_ptr, png_ptr->zbuf);
  165334. png_free(png_ptr, png_ptr->big_row_buf);
  165335. png_free(png_ptr, png_ptr->prev_row);
  165336. #if defined(PNG_READ_DITHER_SUPPORTED)
  165337. png_free(png_ptr, png_ptr->palette_lookup);
  165338. png_free(png_ptr, png_ptr->dither_index);
  165339. #endif
  165340. #if defined(PNG_READ_GAMMA_SUPPORTED)
  165341. png_free(png_ptr, png_ptr->gamma_table);
  165342. #endif
  165343. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  165344. png_free(png_ptr, png_ptr->gamma_from_1);
  165345. png_free(png_ptr, png_ptr->gamma_to_1);
  165346. #endif
  165347. #ifdef PNG_FREE_ME_SUPPORTED
  165348. if (png_ptr->free_me & PNG_FREE_PLTE)
  165349. png_zfree(png_ptr, png_ptr->palette);
  165350. png_ptr->free_me &= ~PNG_FREE_PLTE;
  165351. #else
  165352. if (png_ptr->flags & PNG_FLAG_FREE_PLTE)
  165353. png_zfree(png_ptr, png_ptr->palette);
  165354. png_ptr->flags &= ~PNG_FLAG_FREE_PLTE;
  165355. #endif
  165356. #if defined(PNG_tRNS_SUPPORTED) || \
  165357. defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  165358. #ifdef PNG_FREE_ME_SUPPORTED
  165359. if (png_ptr->free_me & PNG_FREE_TRNS)
  165360. png_free(png_ptr, png_ptr->trans);
  165361. png_ptr->free_me &= ~PNG_FREE_TRNS;
  165362. #else
  165363. if (png_ptr->flags & PNG_FLAG_FREE_TRNS)
  165364. png_free(png_ptr, png_ptr->trans);
  165365. png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
  165366. #endif
  165367. #endif
  165368. #if defined(PNG_READ_hIST_SUPPORTED)
  165369. #ifdef PNG_FREE_ME_SUPPORTED
  165370. if (png_ptr->free_me & PNG_FREE_HIST)
  165371. png_free(png_ptr, png_ptr->hist);
  165372. png_ptr->free_me &= ~PNG_FREE_HIST;
  165373. #else
  165374. if (png_ptr->flags & PNG_FLAG_FREE_HIST)
  165375. png_free(png_ptr, png_ptr->hist);
  165376. png_ptr->flags &= ~PNG_FLAG_FREE_HIST;
  165377. #endif
  165378. #endif
  165379. #if defined(PNG_READ_GAMMA_SUPPORTED)
  165380. if (png_ptr->gamma_16_table != NULL)
  165381. {
  165382. int i;
  165383. int istop = (1 << (8 - png_ptr->gamma_shift));
  165384. for (i = 0; i < istop; i++)
  165385. {
  165386. png_free(png_ptr, png_ptr->gamma_16_table[i]);
  165387. }
  165388. png_free(png_ptr, png_ptr->gamma_16_table);
  165389. }
  165390. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  165391. if (png_ptr->gamma_16_from_1 != NULL)
  165392. {
  165393. int i;
  165394. int istop = (1 << (8 - png_ptr->gamma_shift));
  165395. for (i = 0; i < istop; i++)
  165396. {
  165397. png_free(png_ptr, png_ptr->gamma_16_from_1[i]);
  165398. }
  165399. png_free(png_ptr, png_ptr->gamma_16_from_1);
  165400. }
  165401. if (png_ptr->gamma_16_to_1 != NULL)
  165402. {
  165403. int i;
  165404. int istop = (1 << (8 - png_ptr->gamma_shift));
  165405. for (i = 0; i < istop; i++)
  165406. {
  165407. png_free(png_ptr, png_ptr->gamma_16_to_1[i]);
  165408. }
  165409. png_free(png_ptr, png_ptr->gamma_16_to_1);
  165410. }
  165411. #endif
  165412. #endif
  165413. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  165414. png_free(png_ptr, png_ptr->time_buffer);
  165415. #endif
  165416. inflateEnd(&png_ptr->zstream);
  165417. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  165418. png_free(png_ptr, png_ptr->save_buffer);
  165419. #endif
  165420. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  165421. #ifdef PNG_TEXT_SUPPORTED
  165422. png_free(png_ptr, png_ptr->current_text);
  165423. #endif /* PNG_TEXT_SUPPORTED */
  165424. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  165425. #ifdef PNG_SETJMP_SUPPORTED
  165426. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  165427. #endif
  165428. error_fn = png_ptr->error_fn;
  165429. warning_fn = png_ptr->warning_fn;
  165430. error_ptr = png_ptr->error_ptr;
  165431. #ifdef PNG_USER_MEM_SUPPORTED
  165432. free_fn = png_ptr->free_fn;
  165433. #endif
  165434. png_memset(png_ptr, 0, png_sizeof (png_struct));
  165435. png_ptr->error_fn = error_fn;
  165436. png_ptr->warning_fn = warning_fn;
  165437. png_ptr->error_ptr = error_ptr;
  165438. #ifdef PNG_USER_MEM_SUPPORTED
  165439. png_ptr->free_fn = free_fn;
  165440. #endif
  165441. #ifdef PNG_SETJMP_SUPPORTED
  165442. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  165443. #endif
  165444. }
  165445. void PNGAPI
  165446. png_set_read_status_fn(png_structp png_ptr, png_read_status_ptr read_row_fn)
  165447. {
  165448. if(png_ptr == NULL) return;
  165449. png_ptr->read_row_fn = read_row_fn;
  165450. }
  165451. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165452. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  165453. void PNGAPI
  165454. png_read_png(png_structp png_ptr, png_infop info_ptr,
  165455. int transforms,
  165456. voidp params)
  165457. {
  165458. int row;
  165459. if(png_ptr == NULL) return;
  165460. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  165461. if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
  165462. png_set_invert_alpha(png_ptr);
  165463. #endif
  165464. png_read_info(png_ptr, info_ptr);
  165465. if (info_ptr->height > PNG_UINT_32_MAX/png_sizeof(png_bytep))
  165466. png_error(png_ptr,"Image is too high to process with png_read_png()");
  165467. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  165468. if (transforms & PNG_TRANSFORM_STRIP_16)
  165469. png_set_strip_16(png_ptr);
  165470. #endif
  165471. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  165472. if (transforms & PNG_TRANSFORM_STRIP_ALPHA)
  165473. png_set_strip_alpha(png_ptr);
  165474. #endif
  165475. #if defined(PNG_READ_PACK_SUPPORTED) && !defined(PNG_READ_EXPAND_SUPPORTED)
  165476. if (transforms & PNG_TRANSFORM_PACKING)
  165477. png_set_packing(png_ptr);
  165478. #endif
  165479. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  165480. if (transforms & PNG_TRANSFORM_PACKSWAP)
  165481. png_set_packswap(png_ptr);
  165482. #endif
  165483. #if defined(PNG_READ_EXPAND_SUPPORTED)
  165484. if (transforms & PNG_TRANSFORM_EXPAND)
  165485. if ((png_ptr->bit_depth < 8) ||
  165486. (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ||
  165487. (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)))
  165488. png_set_expand(png_ptr);
  165489. #endif
  165490. #if defined(PNG_READ_INVERT_SUPPORTED)
  165491. if (transforms & PNG_TRANSFORM_INVERT_MONO)
  165492. png_set_invert_mono(png_ptr);
  165493. #endif
  165494. #if defined(PNG_READ_SHIFT_SUPPORTED)
  165495. if ((transforms & PNG_TRANSFORM_SHIFT)
  165496. && png_get_valid(png_ptr, info_ptr, PNG_INFO_sBIT))
  165497. {
  165498. png_color_8p sig_bit;
  165499. png_get_sBIT(png_ptr, info_ptr, &sig_bit);
  165500. png_set_shift(png_ptr, sig_bit);
  165501. }
  165502. #endif
  165503. #if defined(PNG_READ_BGR_SUPPORTED)
  165504. if (transforms & PNG_TRANSFORM_BGR)
  165505. png_set_bgr(png_ptr);
  165506. #endif
  165507. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  165508. if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
  165509. png_set_swap_alpha(png_ptr);
  165510. #endif
  165511. #if defined(PNG_READ_SWAP_SUPPORTED)
  165512. if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
  165513. png_set_swap(png_ptr);
  165514. #endif
  165515. png_read_update_info(png_ptr, info_ptr);
  165516. #ifdef PNG_FREE_ME_SUPPORTED
  165517. png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
  165518. #endif
  165519. if(info_ptr->row_pointers == NULL)
  165520. {
  165521. info_ptr->row_pointers = (png_bytepp)png_malloc(png_ptr,
  165522. info_ptr->height * png_sizeof(png_bytep));
  165523. #ifdef PNG_FREE_ME_SUPPORTED
  165524. info_ptr->free_me |= PNG_FREE_ROWS;
  165525. #endif
  165526. for (row = 0; row < (int)info_ptr->height; row++)
  165527. {
  165528. info_ptr->row_pointers[row] = (png_bytep)png_malloc(png_ptr,
  165529. png_get_rowbytes(png_ptr, info_ptr));
  165530. }
  165531. }
  165532. png_read_image(png_ptr, info_ptr->row_pointers);
  165533. info_ptr->valid |= PNG_INFO_IDAT;
  165534. png_read_end(png_ptr, info_ptr);
  165535. transforms = transforms; /* quiet compiler warnings */
  165536. params = params;
  165537. }
  165538. #endif /* PNG_INFO_IMAGE_SUPPORTED */
  165539. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165540. #endif /* PNG_READ_SUPPORTED */
  165541. /*** End of inlined file: pngread.c ***/
  165542. /*** Start of inlined file: pngpread.c ***/
  165543. #define PNG_INTERNAL
  165544. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  165545. #define PNG_READ_SIG_MODE 0
  165546. #define PNG_READ_CHUNK_MODE 1
  165547. #define PNG_READ_IDAT_MODE 2
  165548. #define PNG_SKIP_MODE 3
  165549. #define PNG_READ_tEXt_MODE 4
  165550. #define PNG_READ_zTXt_MODE 5
  165551. #define PNG_READ_DONE_MODE 6
  165552. #define PNG_READ_iTXt_MODE 7
  165553. #define PNG_ERROR_MODE 8
  165554. void PNGAPI
  165555. png_process_data(png_structp png_ptr, png_infop info_ptr,
  165556. png_bytep buffer, png_size_t buffer_size)
  165557. {
  165558. if(png_ptr == NULL) return;
  165559. png_push_restore_buffer(png_ptr, buffer, buffer_size);
  165560. while (png_ptr->buffer_size)
  165561. {
  165562. png_process_some_data(png_ptr, info_ptr);
  165563. }
  165564. }
  165565. void /* PRIVATE */
  165566. png_process_some_data(png_structp png_ptr, png_infop info_ptr)
  165567. {
  165568. if(png_ptr == NULL) return;
  165569. switch (png_ptr->process_mode)
  165570. {
  165571. case PNG_READ_SIG_MODE:
  165572. {
  165573. png_push_read_sig(png_ptr, info_ptr);
  165574. break;
  165575. }
  165576. case PNG_READ_CHUNK_MODE:
  165577. {
  165578. png_push_read_chunk(png_ptr, info_ptr);
  165579. break;
  165580. }
  165581. case PNG_READ_IDAT_MODE:
  165582. {
  165583. png_push_read_IDAT(png_ptr);
  165584. break;
  165585. }
  165586. #if defined(PNG_READ_tEXt_SUPPORTED)
  165587. case PNG_READ_tEXt_MODE:
  165588. {
  165589. png_push_read_tEXt(png_ptr, info_ptr);
  165590. break;
  165591. }
  165592. #endif
  165593. #if defined(PNG_READ_zTXt_SUPPORTED)
  165594. case PNG_READ_zTXt_MODE:
  165595. {
  165596. png_push_read_zTXt(png_ptr, info_ptr);
  165597. break;
  165598. }
  165599. #endif
  165600. #if defined(PNG_READ_iTXt_SUPPORTED)
  165601. case PNG_READ_iTXt_MODE:
  165602. {
  165603. png_push_read_iTXt(png_ptr, info_ptr);
  165604. break;
  165605. }
  165606. #endif
  165607. case PNG_SKIP_MODE:
  165608. {
  165609. png_push_crc_finish(png_ptr);
  165610. break;
  165611. }
  165612. default:
  165613. {
  165614. png_ptr->buffer_size = 0;
  165615. break;
  165616. }
  165617. }
  165618. }
  165619. void /* PRIVATE */
  165620. png_push_read_sig(png_structp png_ptr, png_infop info_ptr)
  165621. {
  165622. png_size_t num_checked = png_ptr->sig_bytes,
  165623. num_to_check = 8 - num_checked;
  165624. if (png_ptr->buffer_size < num_to_check)
  165625. {
  165626. num_to_check = png_ptr->buffer_size;
  165627. }
  165628. png_push_fill_buffer(png_ptr, &(info_ptr->signature[num_checked]),
  165629. num_to_check);
  165630. png_ptr->sig_bytes = (png_byte)(png_ptr->sig_bytes+num_to_check);
  165631. if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
  165632. {
  165633. if (num_checked < 4 &&
  165634. png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))
  165635. png_error(png_ptr, "Not a PNG file");
  165636. else
  165637. png_error(png_ptr, "PNG file corrupted by ASCII conversion");
  165638. }
  165639. else
  165640. {
  165641. if (png_ptr->sig_bytes >= 8)
  165642. {
  165643. png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  165644. }
  165645. }
  165646. }
  165647. void /* PRIVATE */
  165648. png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
  165649. {
  165650. #ifdef PNG_USE_LOCAL_ARRAYS
  165651. PNG_CONST PNG_IHDR;
  165652. PNG_CONST PNG_IDAT;
  165653. PNG_CONST PNG_IEND;
  165654. PNG_CONST PNG_PLTE;
  165655. #if defined(PNG_READ_bKGD_SUPPORTED)
  165656. PNG_CONST PNG_bKGD;
  165657. #endif
  165658. #if defined(PNG_READ_cHRM_SUPPORTED)
  165659. PNG_CONST PNG_cHRM;
  165660. #endif
  165661. #if defined(PNG_READ_gAMA_SUPPORTED)
  165662. PNG_CONST PNG_gAMA;
  165663. #endif
  165664. #if defined(PNG_READ_hIST_SUPPORTED)
  165665. PNG_CONST PNG_hIST;
  165666. #endif
  165667. #if defined(PNG_READ_iCCP_SUPPORTED)
  165668. PNG_CONST PNG_iCCP;
  165669. #endif
  165670. #if defined(PNG_READ_iTXt_SUPPORTED)
  165671. PNG_CONST PNG_iTXt;
  165672. #endif
  165673. #if defined(PNG_READ_oFFs_SUPPORTED)
  165674. PNG_CONST PNG_oFFs;
  165675. #endif
  165676. #if defined(PNG_READ_pCAL_SUPPORTED)
  165677. PNG_CONST PNG_pCAL;
  165678. #endif
  165679. #if defined(PNG_READ_pHYs_SUPPORTED)
  165680. PNG_CONST PNG_pHYs;
  165681. #endif
  165682. #if defined(PNG_READ_sBIT_SUPPORTED)
  165683. PNG_CONST PNG_sBIT;
  165684. #endif
  165685. #if defined(PNG_READ_sCAL_SUPPORTED)
  165686. PNG_CONST PNG_sCAL;
  165687. #endif
  165688. #if defined(PNG_READ_sRGB_SUPPORTED)
  165689. PNG_CONST PNG_sRGB;
  165690. #endif
  165691. #if defined(PNG_READ_sPLT_SUPPORTED)
  165692. PNG_CONST PNG_sPLT;
  165693. #endif
  165694. #if defined(PNG_READ_tEXt_SUPPORTED)
  165695. PNG_CONST PNG_tEXt;
  165696. #endif
  165697. #if defined(PNG_READ_tIME_SUPPORTED)
  165698. PNG_CONST PNG_tIME;
  165699. #endif
  165700. #if defined(PNG_READ_tRNS_SUPPORTED)
  165701. PNG_CONST PNG_tRNS;
  165702. #endif
  165703. #if defined(PNG_READ_zTXt_SUPPORTED)
  165704. PNG_CONST PNG_zTXt;
  165705. #endif
  165706. #endif /* PNG_USE_LOCAL_ARRAYS */
  165707. if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
  165708. {
  165709. png_byte chunk_length[4];
  165710. if (png_ptr->buffer_size < 8)
  165711. {
  165712. png_push_save_buffer(png_ptr);
  165713. return;
  165714. }
  165715. png_push_fill_buffer(png_ptr, chunk_length, 4);
  165716. png_ptr->push_length = png_get_uint_31(png_ptr,chunk_length);
  165717. png_reset_crc(png_ptr);
  165718. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  165719. png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
  165720. }
  165721. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165722. if(png_ptr->mode & PNG_AFTER_IDAT)
  165723. png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
  165724. if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
  165725. {
  165726. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165727. {
  165728. png_push_save_buffer(png_ptr);
  165729. return;
  165730. }
  165731. png_handle_IHDR(png_ptr, info_ptr, png_ptr->push_length);
  165732. }
  165733. else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
  165734. {
  165735. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165736. {
  165737. png_push_save_buffer(png_ptr);
  165738. return;
  165739. }
  165740. png_handle_IEND(png_ptr, info_ptr, png_ptr->push_length);
  165741. png_ptr->process_mode = PNG_READ_DONE_MODE;
  165742. png_push_have_end(png_ptr, info_ptr);
  165743. }
  165744. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  165745. else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
  165746. {
  165747. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165748. {
  165749. png_push_save_buffer(png_ptr);
  165750. return;
  165751. }
  165752. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165753. png_ptr->mode |= PNG_HAVE_IDAT;
  165754. png_handle_unknown(png_ptr, info_ptr, png_ptr->push_length);
  165755. if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165756. png_ptr->mode |= PNG_HAVE_PLTE;
  165757. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165758. {
  165759. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  165760. png_error(png_ptr, "Missing IHDR before IDAT");
  165761. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  165762. !(png_ptr->mode & PNG_HAVE_PLTE))
  165763. png_error(png_ptr, "Missing PLTE before IDAT");
  165764. }
  165765. }
  165766. #endif
  165767. else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165768. {
  165769. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165770. {
  165771. png_push_save_buffer(png_ptr);
  165772. return;
  165773. }
  165774. png_handle_PLTE(png_ptr, info_ptr, png_ptr->push_length);
  165775. }
  165776. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165777. {
  165778. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  165779. png_error(png_ptr, "Missing IHDR before IDAT");
  165780. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  165781. !(png_ptr->mode & PNG_HAVE_PLTE))
  165782. png_error(png_ptr, "Missing PLTE before IDAT");
  165783. if (png_ptr->mode & PNG_HAVE_IDAT)
  165784. {
  165785. if (!(png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
  165786. if (png_ptr->push_length == 0)
  165787. return;
  165788. if (png_ptr->mode & PNG_AFTER_IDAT)
  165789. png_error(png_ptr, "Too many IDAT's found");
  165790. }
  165791. png_ptr->idat_size = png_ptr->push_length;
  165792. png_ptr->mode |= PNG_HAVE_IDAT;
  165793. png_ptr->process_mode = PNG_READ_IDAT_MODE;
  165794. png_push_have_info(png_ptr, info_ptr);
  165795. png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
  165796. png_ptr->zstream.next_out = png_ptr->row_buf;
  165797. return;
  165798. }
  165799. #if defined(PNG_READ_gAMA_SUPPORTED)
  165800. else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 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_gAMA(png_ptr, info_ptr, png_ptr->push_length);
  165808. }
  165809. #endif
  165810. #if defined(PNG_READ_sBIT_SUPPORTED)
  165811. else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
  165812. {
  165813. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165814. {
  165815. png_push_save_buffer(png_ptr);
  165816. return;
  165817. }
  165818. png_handle_sBIT(png_ptr, info_ptr, png_ptr->push_length);
  165819. }
  165820. #endif
  165821. #if defined(PNG_READ_cHRM_SUPPORTED)
  165822. else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
  165823. {
  165824. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165825. {
  165826. png_push_save_buffer(png_ptr);
  165827. return;
  165828. }
  165829. png_handle_cHRM(png_ptr, info_ptr, png_ptr->push_length);
  165830. }
  165831. #endif
  165832. #if defined(PNG_READ_sRGB_SUPPORTED)
  165833. else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 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_sRGB(png_ptr, info_ptr, png_ptr->push_length);
  165841. }
  165842. #endif
  165843. #if defined(PNG_READ_iCCP_SUPPORTED)
  165844. else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 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_iCCP(png_ptr, info_ptr, png_ptr->push_length);
  165852. }
  165853. #endif
  165854. #if defined(PNG_READ_sPLT_SUPPORTED)
  165855. else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 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_sPLT(png_ptr, info_ptr, png_ptr->push_length);
  165863. }
  165864. #endif
  165865. #if defined(PNG_READ_tRNS_SUPPORTED)
  165866. else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 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_tRNS(png_ptr, info_ptr, png_ptr->push_length);
  165874. }
  165875. #endif
  165876. #if defined(PNG_READ_bKGD_SUPPORTED)
  165877. else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 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_bKGD(png_ptr, info_ptr, png_ptr->push_length);
  165885. }
  165886. #endif
  165887. #if defined(PNG_READ_hIST_SUPPORTED)
  165888. else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 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_hIST(png_ptr, info_ptr, png_ptr->push_length);
  165896. }
  165897. #endif
  165898. #if defined(PNG_READ_pHYs_SUPPORTED)
  165899. else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 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_pHYs(png_ptr, info_ptr, png_ptr->push_length);
  165907. }
  165908. #endif
  165909. #if defined(PNG_READ_oFFs_SUPPORTED)
  165910. else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 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_oFFs(png_ptr, info_ptr, png_ptr->push_length);
  165918. }
  165919. #endif
  165920. #if defined(PNG_READ_pCAL_SUPPORTED)
  165921. else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 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_pCAL(png_ptr, info_ptr, png_ptr->push_length);
  165929. }
  165930. #endif
  165931. #if defined(PNG_READ_sCAL_SUPPORTED)
  165932. else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 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_sCAL(png_ptr, info_ptr, png_ptr->push_length);
  165940. }
  165941. #endif
  165942. #if defined(PNG_READ_tIME_SUPPORTED)
  165943. else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 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_tIME(png_ptr, info_ptr, png_ptr->push_length);
  165951. }
  165952. #endif
  165953. #if defined(PNG_READ_tEXt_SUPPORTED)
  165954. else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 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_push_handle_tEXt(png_ptr, info_ptr, png_ptr->push_length);
  165962. }
  165963. #endif
  165964. #if defined(PNG_READ_zTXt_SUPPORTED)
  165965. else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 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_push_handle_zTXt(png_ptr, info_ptr, png_ptr->push_length);
  165973. }
  165974. #endif
  165975. #if defined(PNG_READ_iTXt_SUPPORTED)
  165976. else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 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_push_handle_iTXt(png_ptr, info_ptr, png_ptr->push_length);
  165984. }
  165985. #endif
  165986. else
  165987. {
  165988. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165989. {
  165990. png_push_save_buffer(png_ptr);
  165991. return;
  165992. }
  165993. png_push_handle_unknown(png_ptr, info_ptr, png_ptr->push_length);
  165994. }
  165995. png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
  165996. }
  165997. void /* PRIVATE */
  165998. png_push_crc_skip(png_structp png_ptr, png_uint_32 skip)
  165999. {
  166000. png_ptr->process_mode = PNG_SKIP_MODE;
  166001. png_ptr->skip_length = skip;
  166002. }
  166003. void /* PRIVATE */
  166004. png_push_crc_finish(png_structp png_ptr)
  166005. {
  166006. if (png_ptr->skip_length && png_ptr->save_buffer_size)
  166007. {
  166008. png_size_t save_size;
  166009. if (png_ptr->skip_length < (png_uint_32)png_ptr->save_buffer_size)
  166010. save_size = (png_size_t)png_ptr->skip_length;
  166011. else
  166012. save_size = png_ptr->save_buffer_size;
  166013. png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size);
  166014. png_ptr->skip_length -= save_size;
  166015. png_ptr->buffer_size -= save_size;
  166016. png_ptr->save_buffer_size -= save_size;
  166017. png_ptr->save_buffer_ptr += save_size;
  166018. }
  166019. if (png_ptr->skip_length && png_ptr->current_buffer_size)
  166020. {
  166021. png_size_t save_size;
  166022. if (png_ptr->skip_length < (png_uint_32)png_ptr->current_buffer_size)
  166023. save_size = (png_size_t)png_ptr->skip_length;
  166024. else
  166025. save_size = png_ptr->current_buffer_size;
  166026. png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size);
  166027. png_ptr->skip_length -= save_size;
  166028. png_ptr->buffer_size -= save_size;
  166029. png_ptr->current_buffer_size -= save_size;
  166030. png_ptr->current_buffer_ptr += save_size;
  166031. }
  166032. if (!png_ptr->skip_length)
  166033. {
  166034. if (png_ptr->buffer_size < 4)
  166035. {
  166036. png_push_save_buffer(png_ptr);
  166037. return;
  166038. }
  166039. png_crc_finish(png_ptr, 0);
  166040. png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  166041. }
  166042. }
  166043. void PNGAPI
  166044. png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length)
  166045. {
  166046. png_bytep ptr;
  166047. if(png_ptr == NULL) return;
  166048. ptr = buffer;
  166049. if (png_ptr->save_buffer_size)
  166050. {
  166051. png_size_t save_size;
  166052. if (length < png_ptr->save_buffer_size)
  166053. save_size = length;
  166054. else
  166055. save_size = png_ptr->save_buffer_size;
  166056. png_memcpy(ptr, png_ptr->save_buffer_ptr, save_size);
  166057. length -= save_size;
  166058. ptr += save_size;
  166059. png_ptr->buffer_size -= save_size;
  166060. png_ptr->save_buffer_size -= save_size;
  166061. png_ptr->save_buffer_ptr += save_size;
  166062. }
  166063. if (length && png_ptr->current_buffer_size)
  166064. {
  166065. png_size_t save_size;
  166066. if (length < png_ptr->current_buffer_size)
  166067. save_size = length;
  166068. else
  166069. save_size = png_ptr->current_buffer_size;
  166070. png_memcpy(ptr, png_ptr->current_buffer_ptr, save_size);
  166071. png_ptr->buffer_size -= save_size;
  166072. png_ptr->current_buffer_size -= save_size;
  166073. png_ptr->current_buffer_ptr += save_size;
  166074. }
  166075. }
  166076. void /* PRIVATE */
  166077. png_push_save_buffer(png_structp png_ptr)
  166078. {
  166079. if (png_ptr->save_buffer_size)
  166080. {
  166081. if (png_ptr->save_buffer_ptr != png_ptr->save_buffer)
  166082. {
  166083. png_size_t i,istop;
  166084. png_bytep sp;
  166085. png_bytep dp;
  166086. istop = png_ptr->save_buffer_size;
  166087. for (i = 0, sp = png_ptr->save_buffer_ptr, dp = png_ptr->save_buffer;
  166088. i < istop; i++, sp++, dp++)
  166089. {
  166090. *dp = *sp;
  166091. }
  166092. }
  166093. }
  166094. if (png_ptr->save_buffer_size + png_ptr->current_buffer_size >
  166095. png_ptr->save_buffer_max)
  166096. {
  166097. png_size_t new_max;
  166098. png_bytep old_buffer;
  166099. if (png_ptr->save_buffer_size > PNG_SIZE_MAX -
  166100. (png_ptr->current_buffer_size + 256))
  166101. {
  166102. png_error(png_ptr, "Potential overflow of save_buffer");
  166103. }
  166104. new_max = png_ptr->save_buffer_size + png_ptr->current_buffer_size + 256;
  166105. old_buffer = png_ptr->save_buffer;
  166106. png_ptr->save_buffer = (png_bytep)png_malloc(png_ptr,
  166107. (png_uint_32)new_max);
  166108. png_memcpy(png_ptr->save_buffer, old_buffer, png_ptr->save_buffer_size);
  166109. png_free(png_ptr, old_buffer);
  166110. png_ptr->save_buffer_max = new_max;
  166111. }
  166112. if (png_ptr->current_buffer_size)
  166113. {
  166114. png_memcpy(png_ptr->save_buffer + png_ptr->save_buffer_size,
  166115. png_ptr->current_buffer_ptr, png_ptr->current_buffer_size);
  166116. png_ptr->save_buffer_size += png_ptr->current_buffer_size;
  166117. png_ptr->current_buffer_size = 0;
  166118. }
  166119. png_ptr->save_buffer_ptr = png_ptr->save_buffer;
  166120. png_ptr->buffer_size = 0;
  166121. }
  166122. void /* PRIVATE */
  166123. png_push_restore_buffer(png_structp png_ptr, png_bytep buffer,
  166124. png_size_t buffer_length)
  166125. {
  166126. png_ptr->current_buffer = buffer;
  166127. png_ptr->current_buffer_size = buffer_length;
  166128. png_ptr->buffer_size = buffer_length + png_ptr->save_buffer_size;
  166129. png_ptr->current_buffer_ptr = png_ptr->current_buffer;
  166130. }
  166131. void /* PRIVATE */
  166132. png_push_read_IDAT(png_structp png_ptr)
  166133. {
  166134. #ifdef PNG_USE_LOCAL_ARRAYS
  166135. PNG_CONST PNG_IDAT;
  166136. #endif
  166137. if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
  166138. {
  166139. png_byte chunk_length[4];
  166140. if (png_ptr->buffer_size < 8)
  166141. {
  166142. png_push_save_buffer(png_ptr);
  166143. return;
  166144. }
  166145. png_push_fill_buffer(png_ptr, chunk_length, 4);
  166146. png_ptr->push_length = png_get_uint_31(png_ptr,chunk_length);
  166147. png_reset_crc(png_ptr);
  166148. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  166149. png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
  166150. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  166151. {
  166152. png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  166153. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  166154. png_error(png_ptr, "Not enough compressed data");
  166155. return;
  166156. }
  166157. png_ptr->idat_size = png_ptr->push_length;
  166158. }
  166159. if (png_ptr->idat_size && png_ptr->save_buffer_size)
  166160. {
  166161. png_size_t save_size;
  166162. if (png_ptr->idat_size < (png_uint_32)png_ptr->save_buffer_size)
  166163. {
  166164. save_size = (png_size_t)png_ptr->idat_size;
  166165. if((png_uint_32)save_size != png_ptr->idat_size)
  166166. png_error(png_ptr, "save_size overflowed in pngpread");
  166167. }
  166168. else
  166169. save_size = png_ptr->save_buffer_size;
  166170. png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size);
  166171. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  166172. png_process_IDAT_data(png_ptr, png_ptr->save_buffer_ptr, save_size);
  166173. png_ptr->idat_size -= save_size;
  166174. png_ptr->buffer_size -= save_size;
  166175. png_ptr->save_buffer_size -= save_size;
  166176. png_ptr->save_buffer_ptr += save_size;
  166177. }
  166178. if (png_ptr->idat_size && png_ptr->current_buffer_size)
  166179. {
  166180. png_size_t save_size;
  166181. if (png_ptr->idat_size < (png_uint_32)png_ptr->current_buffer_size)
  166182. {
  166183. save_size = (png_size_t)png_ptr->idat_size;
  166184. if((png_uint_32)save_size != png_ptr->idat_size)
  166185. png_error(png_ptr, "save_size overflowed in pngpread");
  166186. }
  166187. else
  166188. save_size = png_ptr->current_buffer_size;
  166189. png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size);
  166190. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  166191. png_process_IDAT_data(png_ptr, png_ptr->current_buffer_ptr, save_size);
  166192. png_ptr->idat_size -= save_size;
  166193. png_ptr->buffer_size -= save_size;
  166194. png_ptr->current_buffer_size -= save_size;
  166195. png_ptr->current_buffer_ptr += save_size;
  166196. }
  166197. if (!png_ptr->idat_size)
  166198. {
  166199. if (png_ptr->buffer_size < 4)
  166200. {
  166201. png_push_save_buffer(png_ptr);
  166202. return;
  166203. }
  166204. png_crc_finish(png_ptr, 0);
  166205. png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
  166206. png_ptr->mode |= PNG_AFTER_IDAT;
  166207. }
  166208. }
  166209. void /* PRIVATE */
  166210. png_process_IDAT_data(png_structp png_ptr, png_bytep buffer,
  166211. png_size_t buffer_length)
  166212. {
  166213. int ret;
  166214. if ((png_ptr->flags & PNG_FLAG_ZLIB_FINISHED) && buffer_length)
  166215. png_error(png_ptr, "Extra compression data");
  166216. png_ptr->zstream.next_in = buffer;
  166217. png_ptr->zstream.avail_in = (uInt)buffer_length;
  166218. for(;;)
  166219. {
  166220. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  166221. if (ret != Z_OK)
  166222. {
  166223. if (ret == Z_STREAM_END)
  166224. {
  166225. if (png_ptr->zstream.avail_in)
  166226. png_error(png_ptr, "Extra compressed data");
  166227. if (!(png_ptr->zstream.avail_out))
  166228. {
  166229. png_push_process_row(png_ptr);
  166230. }
  166231. png_ptr->mode |= PNG_AFTER_IDAT;
  166232. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  166233. break;
  166234. }
  166235. else if (ret == Z_BUF_ERROR)
  166236. break;
  166237. else
  166238. png_error(png_ptr, "Decompression Error");
  166239. }
  166240. if (!(png_ptr->zstream.avail_out))
  166241. {
  166242. if ((
  166243. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  166244. png_ptr->interlaced && png_ptr->pass > 6) ||
  166245. (!png_ptr->interlaced &&
  166246. #endif
  166247. png_ptr->row_number == png_ptr->num_rows))
  166248. {
  166249. if (png_ptr->zstream.avail_in)
  166250. {
  166251. png_warning(png_ptr, "Too much data in IDAT chunks");
  166252. }
  166253. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  166254. break;
  166255. }
  166256. png_push_process_row(png_ptr);
  166257. png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
  166258. png_ptr->zstream.next_out = png_ptr->row_buf;
  166259. }
  166260. else
  166261. break;
  166262. }
  166263. }
  166264. void /* PRIVATE */
  166265. png_push_process_row(png_structp png_ptr)
  166266. {
  166267. png_ptr->row_info.color_type = png_ptr->color_type;
  166268. png_ptr->row_info.width = png_ptr->iwidth;
  166269. png_ptr->row_info.channels = png_ptr->channels;
  166270. png_ptr->row_info.bit_depth = png_ptr->bit_depth;
  166271. png_ptr->row_info.pixel_depth = png_ptr->pixel_depth;
  166272. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  166273. png_ptr->row_info.width);
  166274. png_read_filter_row(png_ptr, &(png_ptr->row_info),
  166275. png_ptr->row_buf + 1, png_ptr->prev_row + 1,
  166276. (int)(png_ptr->row_buf[0]));
  166277. png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf,
  166278. png_ptr->rowbytes + 1);
  166279. if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))
  166280. png_do_read_transformations(png_ptr);
  166281. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  166282. if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
  166283. {
  166284. if (png_ptr->pass < 6)
  166285. png_do_read_interlace(png_ptr);
  166286. switch (png_ptr->pass)
  166287. {
  166288. case 0:
  166289. {
  166290. int i;
  166291. for (i = 0; i < 8 && png_ptr->pass == 0; i++)
  166292. {
  166293. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166294. png_read_push_finish_row(png_ptr); /* updates png_ptr->pass */
  166295. }
  166296. if (png_ptr->pass == 2) /* pass 1 might be empty */
  166297. {
  166298. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166299. {
  166300. png_push_have_row(png_ptr, png_bytep_NULL);
  166301. png_read_push_finish_row(png_ptr);
  166302. }
  166303. }
  166304. if (png_ptr->pass == 4 && png_ptr->height <= 4)
  166305. {
  166306. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166307. {
  166308. png_push_have_row(png_ptr, png_bytep_NULL);
  166309. png_read_push_finish_row(png_ptr);
  166310. }
  166311. }
  166312. if (png_ptr->pass == 6 && png_ptr->height <= 4)
  166313. {
  166314. png_push_have_row(png_ptr, png_bytep_NULL);
  166315. png_read_push_finish_row(png_ptr);
  166316. }
  166317. break;
  166318. }
  166319. case 1:
  166320. {
  166321. int i;
  166322. for (i = 0; i < 8 && png_ptr->pass == 1; i++)
  166323. {
  166324. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166325. png_read_push_finish_row(png_ptr);
  166326. }
  166327. if (png_ptr->pass == 2) /* skip top 4 generated rows */
  166328. {
  166329. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166330. {
  166331. png_push_have_row(png_ptr, png_bytep_NULL);
  166332. png_read_push_finish_row(png_ptr);
  166333. }
  166334. }
  166335. break;
  166336. }
  166337. case 2:
  166338. {
  166339. int i;
  166340. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166341. {
  166342. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166343. png_read_push_finish_row(png_ptr);
  166344. }
  166345. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166346. {
  166347. png_push_have_row(png_ptr, png_bytep_NULL);
  166348. png_read_push_finish_row(png_ptr);
  166349. }
  166350. if (png_ptr->pass == 4) /* pass 3 might be empty */
  166351. {
  166352. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166353. {
  166354. png_push_have_row(png_ptr, png_bytep_NULL);
  166355. png_read_push_finish_row(png_ptr);
  166356. }
  166357. }
  166358. break;
  166359. }
  166360. case 3:
  166361. {
  166362. int i;
  166363. for (i = 0; i < 4 && png_ptr->pass == 3; i++)
  166364. {
  166365. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166366. png_read_push_finish_row(png_ptr);
  166367. }
  166368. if (png_ptr->pass == 4) /* skip top two generated rows */
  166369. {
  166370. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166371. {
  166372. png_push_have_row(png_ptr, png_bytep_NULL);
  166373. png_read_push_finish_row(png_ptr);
  166374. }
  166375. }
  166376. break;
  166377. }
  166378. case 4:
  166379. {
  166380. int i;
  166381. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166382. {
  166383. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166384. png_read_push_finish_row(png_ptr);
  166385. }
  166386. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166387. {
  166388. png_push_have_row(png_ptr, png_bytep_NULL);
  166389. png_read_push_finish_row(png_ptr);
  166390. }
  166391. if (png_ptr->pass == 6) /* pass 5 might be empty */
  166392. {
  166393. png_push_have_row(png_ptr, png_bytep_NULL);
  166394. png_read_push_finish_row(png_ptr);
  166395. }
  166396. break;
  166397. }
  166398. case 5:
  166399. {
  166400. int i;
  166401. for (i = 0; i < 2 && png_ptr->pass == 5; i++)
  166402. {
  166403. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166404. png_read_push_finish_row(png_ptr);
  166405. }
  166406. if (png_ptr->pass == 6) /* skip top generated row */
  166407. {
  166408. png_push_have_row(png_ptr, png_bytep_NULL);
  166409. png_read_push_finish_row(png_ptr);
  166410. }
  166411. break;
  166412. }
  166413. case 6:
  166414. {
  166415. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166416. png_read_push_finish_row(png_ptr);
  166417. if (png_ptr->pass != 6)
  166418. break;
  166419. png_push_have_row(png_ptr, png_bytep_NULL);
  166420. png_read_push_finish_row(png_ptr);
  166421. }
  166422. }
  166423. }
  166424. else
  166425. #endif
  166426. {
  166427. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166428. png_read_push_finish_row(png_ptr);
  166429. }
  166430. }
  166431. void /* PRIVATE */
  166432. png_read_push_finish_row(png_structp png_ptr)
  166433. {
  166434. #ifdef PNG_USE_LOCAL_ARRAYS
  166435. PNG_CONST int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
  166436. PNG_CONST int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
  166437. PNG_CONST int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
  166438. PNG_CONST int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
  166439. #endif
  166440. png_ptr->row_number++;
  166441. if (png_ptr->row_number < png_ptr->num_rows)
  166442. return;
  166443. if (png_ptr->interlaced)
  166444. {
  166445. png_ptr->row_number = 0;
  166446. png_memset_check(png_ptr, png_ptr->prev_row, 0,
  166447. png_ptr->rowbytes + 1);
  166448. do
  166449. {
  166450. png_ptr->pass++;
  166451. if ((png_ptr->pass == 1 && png_ptr->width < 5) ||
  166452. (png_ptr->pass == 3 && png_ptr->width < 3) ||
  166453. (png_ptr->pass == 5 && png_ptr->width < 2))
  166454. png_ptr->pass++;
  166455. if (png_ptr->pass > 7)
  166456. png_ptr->pass--;
  166457. if (png_ptr->pass >= 7)
  166458. break;
  166459. png_ptr->iwidth = (png_ptr->width +
  166460. png_pass_inc[png_ptr->pass] - 1 -
  166461. png_pass_start[png_ptr->pass]) /
  166462. png_pass_inc[png_ptr->pass];
  166463. png_ptr->irowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,
  166464. png_ptr->iwidth) + 1;
  166465. if (png_ptr->transformations & PNG_INTERLACE)
  166466. break;
  166467. png_ptr->num_rows = (png_ptr->height +
  166468. png_pass_yinc[png_ptr->pass] - 1 -
  166469. png_pass_ystart[png_ptr->pass]) /
  166470. png_pass_yinc[png_ptr->pass];
  166471. } while (png_ptr->iwidth == 0 || png_ptr->num_rows == 0);
  166472. }
  166473. }
  166474. #if defined(PNG_READ_tEXt_SUPPORTED)
  166475. void /* PRIVATE */
  166476. png_push_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
  166477. length)
  166478. {
  166479. if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
  166480. {
  166481. png_error(png_ptr, "Out of place tEXt");
  166482. info_ptr = info_ptr; /* to quiet some compiler warnings */
  166483. }
  166484. #ifdef PNG_MAX_MALLOC_64K
  166485. png_ptr->skip_length = 0; /* This may not be necessary */
  166486. if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */
  166487. {
  166488. png_warning(png_ptr, "tEXt chunk too large to fit in memory");
  166489. png_ptr->skip_length = length - (png_uint_32)65535L;
  166490. length = (png_uint_32)65535L;
  166491. }
  166492. #endif
  166493. png_ptr->current_text = (png_charp)png_malloc(png_ptr,
  166494. (png_uint_32)(length+1));
  166495. png_ptr->current_text[length] = '\0';
  166496. png_ptr->current_text_ptr = png_ptr->current_text;
  166497. png_ptr->current_text_size = (png_size_t)length;
  166498. png_ptr->current_text_left = (png_size_t)length;
  166499. png_ptr->process_mode = PNG_READ_tEXt_MODE;
  166500. }
  166501. void /* PRIVATE */
  166502. png_push_read_tEXt(png_structp png_ptr, png_infop info_ptr)
  166503. {
  166504. if (png_ptr->buffer_size && png_ptr->current_text_left)
  166505. {
  166506. png_size_t text_size;
  166507. if (png_ptr->buffer_size < png_ptr->current_text_left)
  166508. text_size = png_ptr->buffer_size;
  166509. else
  166510. text_size = png_ptr->current_text_left;
  166511. png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
  166512. png_ptr->current_text_left -= text_size;
  166513. png_ptr->current_text_ptr += text_size;
  166514. }
  166515. if (!(png_ptr->current_text_left))
  166516. {
  166517. png_textp text_ptr;
  166518. png_charp text;
  166519. png_charp key;
  166520. int ret;
  166521. if (png_ptr->buffer_size < 4)
  166522. {
  166523. png_push_save_buffer(png_ptr);
  166524. return;
  166525. }
  166526. png_push_crc_finish(png_ptr);
  166527. #if defined(PNG_MAX_MALLOC_64K)
  166528. if (png_ptr->skip_length)
  166529. return;
  166530. #endif
  166531. key = png_ptr->current_text;
  166532. for (text = key; *text; text++)
  166533. ;
  166534. if (text < key + png_ptr->current_text_size)
  166535. text++;
  166536. text_ptr = (png_textp)png_malloc(png_ptr,
  166537. (png_uint_32)png_sizeof(png_text));
  166538. text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
  166539. text_ptr->key = key;
  166540. #ifdef PNG_iTXt_SUPPORTED
  166541. text_ptr->lang = NULL;
  166542. text_ptr->lang_key = NULL;
  166543. #endif
  166544. text_ptr->text = text;
  166545. ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  166546. png_free(png_ptr, key);
  166547. png_free(png_ptr, text_ptr);
  166548. png_ptr->current_text = NULL;
  166549. if (ret)
  166550. png_warning(png_ptr, "Insufficient memory to store text chunk.");
  166551. }
  166552. }
  166553. #endif
  166554. #if defined(PNG_READ_zTXt_SUPPORTED)
  166555. void /* PRIVATE */
  166556. png_push_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
  166557. length)
  166558. {
  166559. if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
  166560. {
  166561. png_error(png_ptr, "Out of place zTXt");
  166562. info_ptr = info_ptr; /* to quiet some compiler warnings */
  166563. }
  166564. #ifdef PNG_MAX_MALLOC_64K
  166565. if (length > (png_uint_32)65535L)
  166566. {
  166567. png_warning(png_ptr, "zTXt chunk too large to fit in memory");
  166568. png_push_crc_skip(png_ptr, length);
  166569. return;
  166570. }
  166571. #endif
  166572. png_ptr->current_text = (png_charp)png_malloc(png_ptr,
  166573. (png_uint_32)(length+1));
  166574. png_ptr->current_text[length] = '\0';
  166575. png_ptr->current_text_ptr = png_ptr->current_text;
  166576. png_ptr->current_text_size = (png_size_t)length;
  166577. png_ptr->current_text_left = (png_size_t)length;
  166578. png_ptr->process_mode = PNG_READ_zTXt_MODE;
  166579. }
  166580. void /* PRIVATE */
  166581. png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
  166582. {
  166583. if (png_ptr->buffer_size && png_ptr->current_text_left)
  166584. {
  166585. png_size_t text_size;
  166586. if (png_ptr->buffer_size < (png_uint_32)png_ptr->current_text_left)
  166587. text_size = png_ptr->buffer_size;
  166588. else
  166589. text_size = png_ptr->current_text_left;
  166590. png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
  166591. png_ptr->current_text_left -= text_size;
  166592. png_ptr->current_text_ptr += text_size;
  166593. }
  166594. if (!(png_ptr->current_text_left))
  166595. {
  166596. png_textp text_ptr;
  166597. png_charp text;
  166598. png_charp key;
  166599. int ret;
  166600. png_size_t text_size, key_size;
  166601. if (png_ptr->buffer_size < 4)
  166602. {
  166603. png_push_save_buffer(png_ptr);
  166604. return;
  166605. }
  166606. png_push_crc_finish(png_ptr);
  166607. key = png_ptr->current_text;
  166608. for (text = key; *text; text++)
  166609. ;
  166610. if (text >= key + png_ptr->current_text_size)
  166611. {
  166612. png_ptr->current_text = NULL;
  166613. png_free(png_ptr, key);
  166614. return;
  166615. }
  166616. text++;
  166617. if (*text != PNG_TEXT_COMPRESSION_zTXt) /* check compression byte */
  166618. {
  166619. png_ptr->current_text = NULL;
  166620. png_free(png_ptr, key);
  166621. return;
  166622. }
  166623. text++;
  166624. png_ptr->zstream.next_in = (png_bytep )text;
  166625. png_ptr->zstream.avail_in = (uInt)(png_ptr->current_text_size -
  166626. (text - key));
  166627. png_ptr->zstream.next_out = png_ptr->zbuf;
  166628. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  166629. key_size = text - key;
  166630. text_size = 0;
  166631. text = NULL;
  166632. ret = Z_STREAM_END;
  166633. while (png_ptr->zstream.avail_in)
  166634. {
  166635. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  166636. if (ret != Z_OK && ret != Z_STREAM_END)
  166637. {
  166638. inflateReset(&png_ptr->zstream);
  166639. png_ptr->zstream.avail_in = 0;
  166640. png_ptr->current_text = NULL;
  166641. png_free(png_ptr, key);
  166642. png_free(png_ptr, text);
  166643. return;
  166644. }
  166645. if (!(png_ptr->zstream.avail_out) || ret == Z_STREAM_END)
  166646. {
  166647. if (text == NULL)
  166648. {
  166649. text = (png_charp)png_malloc(png_ptr,
  166650. (png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out
  166651. + key_size + 1));
  166652. png_memcpy(text + key_size, png_ptr->zbuf,
  166653. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  166654. png_memcpy(text, key, key_size);
  166655. text_size = key_size + png_ptr->zbuf_size -
  166656. png_ptr->zstream.avail_out;
  166657. *(text + text_size) = '\0';
  166658. }
  166659. else
  166660. {
  166661. png_charp tmp;
  166662. tmp = text;
  166663. text = (png_charp)png_malloc(png_ptr, text_size +
  166664. (png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out
  166665. + 1));
  166666. png_memcpy(text, tmp, text_size);
  166667. png_free(png_ptr, tmp);
  166668. png_memcpy(text + text_size, png_ptr->zbuf,
  166669. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  166670. text_size += png_ptr->zbuf_size - png_ptr->zstream.avail_out;
  166671. *(text + text_size) = '\0';
  166672. }
  166673. if (ret != Z_STREAM_END)
  166674. {
  166675. png_ptr->zstream.next_out = png_ptr->zbuf;
  166676. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  166677. }
  166678. }
  166679. else
  166680. {
  166681. break;
  166682. }
  166683. if (ret == Z_STREAM_END)
  166684. break;
  166685. }
  166686. inflateReset(&png_ptr->zstream);
  166687. png_ptr->zstream.avail_in = 0;
  166688. if (ret != Z_STREAM_END)
  166689. {
  166690. png_ptr->current_text = NULL;
  166691. png_free(png_ptr, key);
  166692. png_free(png_ptr, text);
  166693. return;
  166694. }
  166695. png_ptr->current_text = NULL;
  166696. png_free(png_ptr, key);
  166697. key = text;
  166698. text += key_size;
  166699. text_ptr = (png_textp)png_malloc(png_ptr,
  166700. (png_uint_32)png_sizeof(png_text));
  166701. text_ptr->compression = PNG_TEXT_COMPRESSION_zTXt;
  166702. text_ptr->key = key;
  166703. #ifdef PNG_iTXt_SUPPORTED
  166704. text_ptr->lang = NULL;
  166705. text_ptr->lang_key = NULL;
  166706. #endif
  166707. text_ptr->text = text;
  166708. ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  166709. png_free(png_ptr, key);
  166710. png_free(png_ptr, text_ptr);
  166711. if (ret)
  166712. png_warning(png_ptr, "Insufficient memory to store text chunk.");
  166713. }
  166714. }
  166715. #endif
  166716. #if defined(PNG_READ_iTXt_SUPPORTED)
  166717. void /* PRIVATE */
  166718. png_push_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
  166719. length)
  166720. {
  166721. if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
  166722. {
  166723. png_error(png_ptr, "Out of place iTXt");
  166724. info_ptr = info_ptr; /* to quiet some compiler warnings */
  166725. }
  166726. #ifdef PNG_MAX_MALLOC_64K
  166727. png_ptr->skip_length = 0; /* This may not be necessary */
  166728. if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */
  166729. {
  166730. png_warning(png_ptr, "iTXt chunk too large to fit in memory");
  166731. png_ptr->skip_length = length - (png_uint_32)65535L;
  166732. length = (png_uint_32)65535L;
  166733. }
  166734. #endif
  166735. png_ptr->current_text = (png_charp)png_malloc(png_ptr,
  166736. (png_uint_32)(length+1));
  166737. png_ptr->current_text[length] = '\0';
  166738. png_ptr->current_text_ptr = png_ptr->current_text;
  166739. png_ptr->current_text_size = (png_size_t)length;
  166740. png_ptr->current_text_left = (png_size_t)length;
  166741. png_ptr->process_mode = PNG_READ_iTXt_MODE;
  166742. }
  166743. void /* PRIVATE */
  166744. png_push_read_iTXt(png_structp png_ptr, png_infop info_ptr)
  166745. {
  166746. if (png_ptr->buffer_size && png_ptr->current_text_left)
  166747. {
  166748. png_size_t text_size;
  166749. if (png_ptr->buffer_size < png_ptr->current_text_left)
  166750. text_size = png_ptr->buffer_size;
  166751. else
  166752. text_size = png_ptr->current_text_left;
  166753. png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
  166754. png_ptr->current_text_left -= text_size;
  166755. png_ptr->current_text_ptr += text_size;
  166756. }
  166757. if (!(png_ptr->current_text_left))
  166758. {
  166759. png_textp text_ptr;
  166760. png_charp key;
  166761. int comp_flag;
  166762. png_charp lang;
  166763. png_charp lang_key;
  166764. png_charp text;
  166765. int ret;
  166766. if (png_ptr->buffer_size < 4)
  166767. {
  166768. png_push_save_buffer(png_ptr);
  166769. return;
  166770. }
  166771. png_push_crc_finish(png_ptr);
  166772. #if defined(PNG_MAX_MALLOC_64K)
  166773. if (png_ptr->skip_length)
  166774. return;
  166775. #endif
  166776. key = png_ptr->current_text;
  166777. for (lang = key; *lang; lang++)
  166778. ;
  166779. if (lang < key + png_ptr->current_text_size - 3)
  166780. lang++;
  166781. comp_flag = *lang++;
  166782. lang++; /* skip comp_type, always zero */
  166783. for (lang_key = lang; *lang_key; lang_key++)
  166784. ;
  166785. lang_key++; /* skip NUL separator */
  166786. text=lang_key;
  166787. if (lang_key < key + png_ptr->current_text_size - 1)
  166788. {
  166789. for (; *text; text++)
  166790. ;
  166791. }
  166792. if (text < key + png_ptr->current_text_size)
  166793. text++;
  166794. text_ptr = (png_textp)png_malloc(png_ptr,
  166795. (png_uint_32)png_sizeof(png_text));
  166796. text_ptr->compression = comp_flag + 2;
  166797. text_ptr->key = key;
  166798. text_ptr->lang = lang;
  166799. text_ptr->lang_key = lang_key;
  166800. text_ptr->text = text;
  166801. text_ptr->text_length = 0;
  166802. text_ptr->itxt_length = png_strlen(text);
  166803. ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  166804. png_ptr->current_text = NULL;
  166805. png_free(png_ptr, text_ptr);
  166806. if (ret)
  166807. png_warning(png_ptr, "Insufficient memory to store iTXt chunk.");
  166808. }
  166809. }
  166810. #endif
  166811. void /* PRIVATE */
  166812. png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32
  166813. length)
  166814. {
  166815. png_uint_32 skip=0;
  166816. png_check_chunk_name(png_ptr, png_ptr->chunk_name);
  166817. if (!(png_ptr->chunk_name[0] & 0x20))
  166818. {
  166819. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  166820. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  166821. PNG_HANDLE_CHUNK_ALWAYS
  166822. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  166823. && png_ptr->read_user_chunk_fn == NULL
  166824. #endif
  166825. )
  166826. #endif
  166827. png_chunk_error(png_ptr, "unknown critical chunk");
  166828. info_ptr = info_ptr; /* to quiet some compiler warnings */
  166829. }
  166830. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  166831. if (png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS)
  166832. {
  166833. #ifdef PNG_MAX_MALLOC_64K
  166834. if (length > (png_uint_32)65535L)
  166835. {
  166836. png_warning(png_ptr, "unknown chunk too large to fit in memory");
  166837. skip = length - (png_uint_32)65535L;
  166838. length = (png_uint_32)65535L;
  166839. }
  166840. #endif
  166841. png_strncpy((png_charp)png_ptr->unknown_chunk.name,
  166842. (png_charp)png_ptr->chunk_name, 5);
  166843. png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length);
  166844. png_ptr->unknown_chunk.size = (png_size_t)length;
  166845. png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
  166846. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  166847. if(png_ptr->read_user_chunk_fn != NULL)
  166848. {
  166849. int ret;
  166850. ret = (*(png_ptr->read_user_chunk_fn))
  166851. (png_ptr, &png_ptr->unknown_chunk);
  166852. if (ret < 0)
  166853. png_chunk_error(png_ptr, "error in user chunk");
  166854. if (ret == 0)
  166855. {
  166856. if (!(png_ptr->chunk_name[0] & 0x20))
  166857. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  166858. PNG_HANDLE_CHUNK_ALWAYS)
  166859. png_chunk_error(png_ptr, "unknown critical chunk");
  166860. png_set_unknown_chunks(png_ptr, info_ptr,
  166861. &png_ptr->unknown_chunk, 1);
  166862. }
  166863. }
  166864. #else
  166865. png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1);
  166866. #endif
  166867. png_free(png_ptr, png_ptr->unknown_chunk.data);
  166868. png_ptr->unknown_chunk.data = NULL;
  166869. }
  166870. else
  166871. #endif
  166872. skip=length;
  166873. png_push_crc_skip(png_ptr, skip);
  166874. }
  166875. void /* PRIVATE */
  166876. png_push_have_info(png_structp png_ptr, png_infop info_ptr)
  166877. {
  166878. if (png_ptr->info_fn != NULL)
  166879. (*(png_ptr->info_fn))(png_ptr, info_ptr);
  166880. }
  166881. void /* PRIVATE */
  166882. png_push_have_end(png_structp png_ptr, png_infop info_ptr)
  166883. {
  166884. if (png_ptr->end_fn != NULL)
  166885. (*(png_ptr->end_fn))(png_ptr, info_ptr);
  166886. }
  166887. void /* PRIVATE */
  166888. png_push_have_row(png_structp png_ptr, png_bytep row)
  166889. {
  166890. if (png_ptr->row_fn != NULL)
  166891. (*(png_ptr->row_fn))(png_ptr, row, png_ptr->row_number,
  166892. (int)png_ptr->pass);
  166893. }
  166894. void PNGAPI
  166895. png_progressive_combine_row (png_structp png_ptr,
  166896. png_bytep old_row, png_bytep new_row)
  166897. {
  166898. #ifdef PNG_USE_LOCAL_ARRAYS
  166899. PNG_CONST int FARDATA png_pass_dsp_mask[7] =
  166900. {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
  166901. #endif
  166902. if(png_ptr == NULL) return;
  166903. if (new_row != NULL) /* new_row must == png_ptr->row_buf here. */
  166904. png_combine_row(png_ptr, old_row, png_pass_dsp_mask[png_ptr->pass]);
  166905. }
  166906. void PNGAPI
  166907. png_set_progressive_read_fn(png_structp png_ptr, png_voidp progressive_ptr,
  166908. png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn,
  166909. png_progressive_end_ptr end_fn)
  166910. {
  166911. if(png_ptr == NULL) return;
  166912. png_ptr->info_fn = info_fn;
  166913. png_ptr->row_fn = row_fn;
  166914. png_ptr->end_fn = end_fn;
  166915. png_set_read_fn(png_ptr, progressive_ptr, png_push_fill_buffer);
  166916. }
  166917. png_voidp PNGAPI
  166918. png_get_progressive_ptr(png_structp png_ptr)
  166919. {
  166920. if(png_ptr == NULL) return (NULL);
  166921. return png_ptr->io_ptr;
  166922. }
  166923. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  166924. /*** End of inlined file: pngpread.c ***/
  166925. /*** Start of inlined file: pngrio.c ***/
  166926. #define PNG_INTERNAL
  166927. #if defined(PNG_READ_SUPPORTED)
  166928. void /* PRIVATE */
  166929. png_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  166930. {
  166931. png_debug1(4,"reading %d bytes\n", (int)length);
  166932. if (png_ptr->read_data_fn != NULL)
  166933. (*(png_ptr->read_data_fn))(png_ptr, data, length);
  166934. else
  166935. png_error(png_ptr, "Call to NULL read function");
  166936. }
  166937. #if !defined(PNG_NO_STDIO)
  166938. #ifndef USE_FAR_KEYWORD
  166939. void PNGAPI
  166940. png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  166941. {
  166942. png_size_t check;
  166943. if(png_ptr == NULL) return;
  166944. #if defined(_WIN32_WCE)
  166945. if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  166946. check = 0;
  166947. #else
  166948. check = (png_size_t)fread(data, (png_size_t)1, length,
  166949. (png_FILE_p)png_ptr->io_ptr);
  166950. #endif
  166951. if (check != length)
  166952. png_error(png_ptr, "Read Error");
  166953. }
  166954. #else
  166955. #define NEAR_BUF_SIZE 1024
  166956. #define MIN(a,b) (a <= b ? a : b)
  166957. static void PNGAPI
  166958. png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  166959. {
  166960. int check;
  166961. png_byte *n_data;
  166962. png_FILE_p io_ptr;
  166963. if(png_ptr == NULL) return;
  166964. n_data = (png_byte *)CVT_PTR_NOCHECK(data);
  166965. io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
  166966. if ((png_bytep)n_data == data)
  166967. {
  166968. #if defined(_WIN32_WCE)
  166969. if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  166970. check = 0;
  166971. #else
  166972. check = fread(n_data, 1, length, io_ptr);
  166973. #endif
  166974. }
  166975. else
  166976. {
  166977. png_byte buf[NEAR_BUF_SIZE];
  166978. png_size_t read, remaining, err;
  166979. check = 0;
  166980. remaining = length;
  166981. do
  166982. {
  166983. read = MIN(NEAR_BUF_SIZE, remaining);
  166984. #if defined(_WIN32_WCE)
  166985. if ( !ReadFile((HANDLE)(io_ptr), buf, read, &err, NULL) )
  166986. err = 0;
  166987. #else
  166988. err = fread(buf, (png_size_t)1, read, io_ptr);
  166989. #endif
  166990. png_memcpy(data, buf, read); /* copy far buffer to near buffer */
  166991. if(err != read)
  166992. break;
  166993. else
  166994. check += err;
  166995. data += read;
  166996. remaining -= read;
  166997. }
  166998. while (remaining != 0);
  166999. }
  167000. if ((png_uint_32)check != (png_uint_32)length)
  167001. png_error(png_ptr, "read Error");
  167002. }
  167003. #endif
  167004. #endif
  167005. void PNGAPI
  167006. png_set_read_fn(png_structp png_ptr, png_voidp io_ptr,
  167007. png_rw_ptr read_data_fn)
  167008. {
  167009. if(png_ptr == NULL) return;
  167010. png_ptr->io_ptr = io_ptr;
  167011. #if !defined(PNG_NO_STDIO)
  167012. if (read_data_fn != NULL)
  167013. png_ptr->read_data_fn = read_data_fn;
  167014. else
  167015. png_ptr->read_data_fn = png_default_read_data;
  167016. #else
  167017. png_ptr->read_data_fn = read_data_fn;
  167018. #endif
  167019. if (png_ptr->write_data_fn != NULL)
  167020. {
  167021. png_ptr->write_data_fn = NULL;
  167022. png_warning(png_ptr,
  167023. "It's an error to set both read_data_fn and write_data_fn in the ");
  167024. png_warning(png_ptr,
  167025. "same structure. Resetting write_data_fn to NULL.");
  167026. }
  167027. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  167028. png_ptr->output_flush_fn = NULL;
  167029. #endif
  167030. }
  167031. #endif /* PNG_READ_SUPPORTED */
  167032. /*** End of inlined file: pngrio.c ***/
  167033. /*** Start of inlined file: pngrtran.c ***/
  167034. #define PNG_INTERNAL
  167035. #if defined(PNG_READ_SUPPORTED)
  167036. void PNGAPI
  167037. png_set_crc_action(png_structp png_ptr, int crit_action, int ancil_action)
  167038. {
  167039. png_debug(1, "in png_set_crc_action\n");
  167040. if(png_ptr == NULL) return;
  167041. switch (crit_action)
  167042. {
  167043. case PNG_CRC_NO_CHANGE: /* leave setting as is */
  167044. break;
  167045. case PNG_CRC_WARN_USE: /* warn/use data */
  167046. png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  167047. png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE;
  167048. break;
  167049. case PNG_CRC_QUIET_USE: /* quiet/use data */
  167050. png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  167051. png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE |
  167052. PNG_FLAG_CRC_CRITICAL_IGNORE;
  167053. break;
  167054. case PNG_CRC_WARN_DISCARD: /* not a valid action for critical data */
  167055. png_warning(png_ptr, "Can't discard critical data on CRC error.");
  167056. case PNG_CRC_ERROR_QUIT: /* error/quit */
  167057. case PNG_CRC_DEFAULT:
  167058. default:
  167059. png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  167060. break;
  167061. }
  167062. switch (ancil_action)
  167063. {
  167064. case PNG_CRC_NO_CHANGE: /* leave setting as is */
  167065. break;
  167066. case PNG_CRC_WARN_USE: /* warn/use data */
  167067. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  167068. png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE;
  167069. break;
  167070. case PNG_CRC_QUIET_USE: /* quiet/use data */
  167071. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  167072. png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE |
  167073. PNG_FLAG_CRC_ANCILLARY_NOWARN;
  167074. break;
  167075. case PNG_CRC_ERROR_QUIT: /* error/quit */
  167076. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  167077. png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_NOWARN;
  167078. break;
  167079. case PNG_CRC_WARN_DISCARD: /* warn/discard data */
  167080. case PNG_CRC_DEFAULT:
  167081. default:
  167082. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  167083. break;
  167084. }
  167085. }
  167086. #if defined(PNG_READ_BACKGROUND_SUPPORTED) && \
  167087. defined(PNG_FLOATING_POINT_SUPPORTED)
  167088. void PNGAPI
  167089. png_set_background(png_structp png_ptr,
  167090. png_color_16p background_color, int background_gamma_code,
  167091. int need_expand, double background_gamma)
  167092. {
  167093. png_debug(1, "in png_set_background\n");
  167094. if(png_ptr == NULL) return;
  167095. if (background_gamma_code == PNG_BACKGROUND_GAMMA_UNKNOWN)
  167096. {
  167097. png_warning(png_ptr, "Application must supply a known background gamma");
  167098. return;
  167099. }
  167100. png_ptr->transformations |= PNG_BACKGROUND;
  167101. png_memcpy(&(png_ptr->background), background_color,
  167102. png_sizeof(png_color_16));
  167103. png_ptr->background_gamma = (float)background_gamma;
  167104. png_ptr->background_gamma_type = (png_byte)(background_gamma_code);
  167105. png_ptr->transformations |= (need_expand ? PNG_BACKGROUND_EXPAND : 0);
  167106. }
  167107. #endif
  167108. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  167109. void PNGAPI
  167110. png_set_strip_16(png_structp png_ptr)
  167111. {
  167112. png_debug(1, "in png_set_strip_16\n");
  167113. if(png_ptr == NULL) return;
  167114. png_ptr->transformations |= PNG_16_TO_8;
  167115. }
  167116. #endif
  167117. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  167118. void PNGAPI
  167119. png_set_strip_alpha(png_structp png_ptr)
  167120. {
  167121. png_debug(1, "in png_set_strip_alpha\n");
  167122. if(png_ptr == NULL) return;
  167123. png_ptr->flags |= PNG_FLAG_STRIP_ALPHA;
  167124. }
  167125. #endif
  167126. #if defined(PNG_READ_DITHER_SUPPORTED)
  167127. typedef struct png_dsort_struct
  167128. {
  167129. struct png_dsort_struct FAR * next;
  167130. png_byte left;
  167131. png_byte right;
  167132. } png_dsort;
  167133. typedef png_dsort FAR * png_dsortp;
  167134. typedef png_dsort FAR * FAR * png_dsortpp;
  167135. void PNGAPI
  167136. png_set_dither(png_structp png_ptr, png_colorp palette,
  167137. int num_palette, int maximum_colors, png_uint_16p histogram,
  167138. int full_dither)
  167139. {
  167140. png_debug(1, "in png_set_dither\n");
  167141. if(png_ptr == NULL) return;
  167142. png_ptr->transformations |= PNG_DITHER;
  167143. if (!full_dither)
  167144. {
  167145. int i;
  167146. png_ptr->dither_index = (png_bytep)png_malloc(png_ptr,
  167147. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167148. for (i = 0; i < num_palette; i++)
  167149. png_ptr->dither_index[i] = (png_byte)i;
  167150. }
  167151. if (num_palette > maximum_colors)
  167152. {
  167153. if (histogram != NULL)
  167154. {
  167155. int i;
  167156. png_ptr->dither_sort = (png_bytep)png_malloc(png_ptr,
  167157. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167158. for (i = 0; i < num_palette; i++)
  167159. png_ptr->dither_sort[i] = (png_byte)i;
  167160. for (i = num_palette - 1; i >= maximum_colors; i--)
  167161. {
  167162. int done; /* to stop early if the list is pre-sorted */
  167163. int j;
  167164. done = 1;
  167165. for (j = 0; j < i; j++)
  167166. {
  167167. if (histogram[png_ptr->dither_sort[j]]
  167168. < histogram[png_ptr->dither_sort[j + 1]])
  167169. {
  167170. png_byte t;
  167171. t = png_ptr->dither_sort[j];
  167172. png_ptr->dither_sort[j] = png_ptr->dither_sort[j + 1];
  167173. png_ptr->dither_sort[j + 1] = t;
  167174. done = 0;
  167175. }
  167176. }
  167177. if (done)
  167178. break;
  167179. }
  167180. if (full_dither)
  167181. {
  167182. int j = num_palette;
  167183. for (i = 0; i < maximum_colors; i++)
  167184. {
  167185. if ((int)png_ptr->dither_sort[i] >= maximum_colors)
  167186. {
  167187. do
  167188. j--;
  167189. while ((int)png_ptr->dither_sort[j] >= maximum_colors);
  167190. palette[i] = palette[j];
  167191. }
  167192. }
  167193. }
  167194. else
  167195. {
  167196. int j = num_palette;
  167197. for (i = 0; i < maximum_colors; i++)
  167198. {
  167199. if ((int)png_ptr->dither_sort[i] >= maximum_colors)
  167200. {
  167201. png_color tmp_color;
  167202. do
  167203. j--;
  167204. while ((int)png_ptr->dither_sort[j] >= maximum_colors);
  167205. tmp_color = palette[j];
  167206. palette[j] = palette[i];
  167207. palette[i] = tmp_color;
  167208. png_ptr->dither_index[j] = (png_byte)i;
  167209. png_ptr->dither_index[i] = (png_byte)j;
  167210. }
  167211. }
  167212. for (i = 0; i < num_palette; i++)
  167213. {
  167214. if ((int)png_ptr->dither_index[i] >= maximum_colors)
  167215. {
  167216. int min_d, k, min_k, d_index;
  167217. d_index = png_ptr->dither_index[i];
  167218. min_d = PNG_COLOR_DIST(palette[d_index], palette[0]);
  167219. for (k = 1, min_k = 0; k < maximum_colors; k++)
  167220. {
  167221. int d;
  167222. d = PNG_COLOR_DIST(palette[d_index], palette[k]);
  167223. if (d < min_d)
  167224. {
  167225. min_d = d;
  167226. min_k = k;
  167227. }
  167228. }
  167229. png_ptr->dither_index[i] = (png_byte)min_k;
  167230. }
  167231. }
  167232. }
  167233. png_free(png_ptr, png_ptr->dither_sort);
  167234. png_ptr->dither_sort=NULL;
  167235. }
  167236. else
  167237. {
  167238. int i;
  167239. int max_d;
  167240. int num_new_palette;
  167241. png_dsortp t;
  167242. png_dsortpp hash;
  167243. t=NULL;
  167244. png_ptr->index_to_palette = (png_bytep)png_malloc(png_ptr,
  167245. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167246. png_ptr->palette_to_index = (png_bytep)png_malloc(png_ptr,
  167247. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167248. for (i = 0; i < num_palette; i++)
  167249. {
  167250. png_ptr->index_to_palette[i] = (png_byte)i;
  167251. png_ptr->palette_to_index[i] = (png_byte)i;
  167252. }
  167253. hash = (png_dsortpp)png_malloc(png_ptr, (png_uint_32)(769 *
  167254. png_sizeof (png_dsortp)));
  167255. for (i = 0; i < 769; i++)
  167256. hash[i] = NULL;
  167257. num_new_palette = num_palette;
  167258. max_d = 96;
  167259. while (num_new_palette > maximum_colors)
  167260. {
  167261. for (i = 0; i < num_new_palette - 1; i++)
  167262. {
  167263. int j;
  167264. for (j = i + 1; j < num_new_palette; j++)
  167265. {
  167266. int d;
  167267. d = PNG_COLOR_DIST(palette[i], palette[j]);
  167268. if (d <= max_d)
  167269. {
  167270. t = (png_dsortp)png_malloc_warn(png_ptr,
  167271. (png_uint_32)(png_sizeof(png_dsort)));
  167272. if (t == NULL)
  167273. break;
  167274. t->next = hash[d];
  167275. t->left = (png_byte)i;
  167276. t->right = (png_byte)j;
  167277. hash[d] = t;
  167278. }
  167279. }
  167280. if (t == NULL)
  167281. break;
  167282. }
  167283. if (t != NULL)
  167284. for (i = 0; i <= max_d; i++)
  167285. {
  167286. if (hash[i] != NULL)
  167287. {
  167288. png_dsortp p;
  167289. for (p = hash[i]; p; p = p->next)
  167290. {
  167291. if ((int)png_ptr->index_to_palette[p->left]
  167292. < num_new_palette &&
  167293. (int)png_ptr->index_to_palette[p->right]
  167294. < num_new_palette)
  167295. {
  167296. int j, next_j;
  167297. if (num_new_palette & 0x01)
  167298. {
  167299. j = p->left;
  167300. next_j = p->right;
  167301. }
  167302. else
  167303. {
  167304. j = p->right;
  167305. next_j = p->left;
  167306. }
  167307. num_new_palette--;
  167308. palette[png_ptr->index_to_palette[j]]
  167309. = palette[num_new_palette];
  167310. if (!full_dither)
  167311. {
  167312. int k;
  167313. for (k = 0; k < num_palette; k++)
  167314. {
  167315. if (png_ptr->dither_index[k] ==
  167316. png_ptr->index_to_palette[j])
  167317. png_ptr->dither_index[k] =
  167318. png_ptr->index_to_palette[next_j];
  167319. if ((int)png_ptr->dither_index[k] ==
  167320. num_new_palette)
  167321. png_ptr->dither_index[k] =
  167322. png_ptr->index_to_palette[j];
  167323. }
  167324. }
  167325. png_ptr->index_to_palette[png_ptr->palette_to_index
  167326. [num_new_palette]] = png_ptr->index_to_palette[j];
  167327. png_ptr->palette_to_index[png_ptr->index_to_palette[j]]
  167328. = png_ptr->palette_to_index[num_new_palette];
  167329. png_ptr->index_to_palette[j] = (png_byte)num_new_palette;
  167330. png_ptr->palette_to_index[num_new_palette] = (png_byte)j;
  167331. }
  167332. if (num_new_palette <= maximum_colors)
  167333. break;
  167334. }
  167335. if (num_new_palette <= maximum_colors)
  167336. break;
  167337. }
  167338. }
  167339. for (i = 0; i < 769; i++)
  167340. {
  167341. if (hash[i] != NULL)
  167342. {
  167343. png_dsortp p = hash[i];
  167344. while (p)
  167345. {
  167346. t = p->next;
  167347. png_free(png_ptr, p);
  167348. p = t;
  167349. }
  167350. }
  167351. hash[i] = 0;
  167352. }
  167353. max_d += 96;
  167354. }
  167355. png_free(png_ptr, hash);
  167356. png_free(png_ptr, png_ptr->palette_to_index);
  167357. png_free(png_ptr, png_ptr->index_to_palette);
  167358. png_ptr->palette_to_index=NULL;
  167359. png_ptr->index_to_palette=NULL;
  167360. }
  167361. num_palette = maximum_colors;
  167362. }
  167363. if (png_ptr->palette == NULL)
  167364. {
  167365. png_ptr->palette = palette;
  167366. }
  167367. png_ptr->num_palette = (png_uint_16)num_palette;
  167368. if (full_dither)
  167369. {
  167370. int i;
  167371. png_bytep distance;
  167372. int total_bits = PNG_DITHER_RED_BITS + PNG_DITHER_GREEN_BITS +
  167373. PNG_DITHER_BLUE_BITS;
  167374. int num_red = (1 << PNG_DITHER_RED_BITS);
  167375. int num_green = (1 << PNG_DITHER_GREEN_BITS);
  167376. int num_blue = (1 << PNG_DITHER_BLUE_BITS);
  167377. png_size_t num_entries = ((png_size_t)1 << total_bits);
  167378. png_ptr->palette_lookup = (png_bytep )png_malloc(png_ptr,
  167379. (png_uint_32)(num_entries * png_sizeof (png_byte)));
  167380. png_memset(png_ptr->palette_lookup, 0, num_entries *
  167381. png_sizeof (png_byte));
  167382. distance = (png_bytep)png_malloc(png_ptr, (png_uint_32)(num_entries *
  167383. png_sizeof(png_byte)));
  167384. png_memset(distance, 0xff, num_entries * png_sizeof(png_byte));
  167385. for (i = 0; i < num_palette; i++)
  167386. {
  167387. int ir, ig, ib;
  167388. int r = (palette[i].red >> (8 - PNG_DITHER_RED_BITS));
  167389. int g = (palette[i].green >> (8 - PNG_DITHER_GREEN_BITS));
  167390. int b = (palette[i].blue >> (8 - PNG_DITHER_BLUE_BITS));
  167391. for (ir = 0; ir < num_red; ir++)
  167392. {
  167393. int dr = ((ir > r) ? ir - r : r - ir);
  167394. int index_r = (ir << (PNG_DITHER_BLUE_BITS + PNG_DITHER_GREEN_BITS));
  167395. for (ig = 0; ig < num_green; ig++)
  167396. {
  167397. int dg = ((ig > g) ? ig - g : g - ig);
  167398. int dt = dr + dg;
  167399. int dm = ((dr > dg) ? dr : dg);
  167400. int index_g = index_r | (ig << PNG_DITHER_BLUE_BITS);
  167401. for (ib = 0; ib < num_blue; ib++)
  167402. {
  167403. int d_index = index_g | ib;
  167404. int db = ((ib > b) ? ib - b : b - ib);
  167405. int dmax = ((dm > db) ? dm : db);
  167406. int d = dmax + dt + db;
  167407. if (d < (int)distance[d_index])
  167408. {
  167409. distance[d_index] = (png_byte)d;
  167410. png_ptr->palette_lookup[d_index] = (png_byte)i;
  167411. }
  167412. }
  167413. }
  167414. }
  167415. }
  167416. png_free(png_ptr, distance);
  167417. }
  167418. }
  167419. #endif
  167420. #if defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  167421. void PNGAPI
  167422. png_set_gamma(png_structp png_ptr, double scrn_gamma, double file_gamma)
  167423. {
  167424. png_debug(1, "in png_set_gamma\n");
  167425. if(png_ptr == NULL) return;
  167426. if ((fabs(scrn_gamma * file_gamma - 1.0) > PNG_GAMMA_THRESHOLD) ||
  167427. (png_ptr->color_type & PNG_COLOR_MASK_ALPHA) ||
  167428. (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE))
  167429. png_ptr->transformations |= PNG_GAMMA;
  167430. png_ptr->gamma = (float)file_gamma;
  167431. png_ptr->screen_gamma = (float)scrn_gamma;
  167432. }
  167433. #endif
  167434. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167435. void PNGAPI
  167436. png_set_expand(png_structp png_ptr)
  167437. {
  167438. png_debug(1, "in png_set_expand\n");
  167439. if(png_ptr == NULL) return;
  167440. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167441. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167442. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167443. #endif
  167444. }
  167445. void PNGAPI
  167446. png_set_palette_to_rgb(png_structp png_ptr)
  167447. {
  167448. png_debug(1, "in png_set_palette_to_rgb\n");
  167449. if(png_ptr == NULL) return;
  167450. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167451. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167452. png_ptr->flags &= !(PNG_FLAG_ROW_INIT);
  167453. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167454. #endif
  167455. }
  167456. #if !defined(PNG_1_0_X)
  167457. void PNGAPI
  167458. png_set_expand_gray_1_2_4_to_8(png_structp png_ptr)
  167459. {
  167460. png_debug(1, "in png_set_expand_gray_1_2_4_to_8\n");
  167461. if(png_ptr == NULL) return;
  167462. png_ptr->transformations |= PNG_EXPAND;
  167463. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167464. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167465. #endif
  167466. }
  167467. #endif
  167468. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  167469. void PNGAPI
  167470. png_set_gray_1_2_4_to_8(png_structp png_ptr)
  167471. {
  167472. png_debug(1, "in png_set_gray_1_2_4_to_8\n");
  167473. if(png_ptr == NULL) return;
  167474. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167475. }
  167476. #endif
  167477. void PNGAPI
  167478. png_set_tRNS_to_alpha(png_structp png_ptr)
  167479. {
  167480. png_debug(1, "in png_set_tRNS_to_alpha\n");
  167481. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167482. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167483. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167484. #endif
  167485. }
  167486. #endif /* defined(PNG_READ_EXPAND_SUPPORTED) */
  167487. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  167488. void PNGAPI
  167489. png_set_gray_to_rgb(png_structp png_ptr)
  167490. {
  167491. png_debug(1, "in png_set_gray_to_rgb\n");
  167492. png_ptr->transformations |= PNG_GRAY_TO_RGB;
  167493. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167494. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167495. #endif
  167496. }
  167497. #endif
  167498. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  167499. #if defined(PNG_FLOATING_POINT_SUPPORTED)
  167500. void PNGAPI
  167501. png_set_rgb_to_gray(png_structp png_ptr, int error_action, double red,
  167502. double green)
  167503. {
  167504. int red_fixed = (int)((float)red*100000.0 + 0.5);
  167505. int green_fixed = (int)((float)green*100000.0 + 0.5);
  167506. if(png_ptr == NULL) return;
  167507. png_set_rgb_to_gray_fixed(png_ptr, error_action, red_fixed, green_fixed);
  167508. }
  167509. #endif
  167510. void PNGAPI
  167511. png_set_rgb_to_gray_fixed(png_structp png_ptr, int error_action,
  167512. png_fixed_point red, png_fixed_point green)
  167513. {
  167514. png_debug(1, "in png_set_rgb_to_gray\n");
  167515. if(png_ptr == NULL) return;
  167516. switch(error_action)
  167517. {
  167518. case 1: png_ptr->transformations |= PNG_RGB_TO_GRAY;
  167519. break;
  167520. case 2: png_ptr->transformations |= PNG_RGB_TO_GRAY_WARN;
  167521. break;
  167522. case 3: png_ptr->transformations |= PNG_RGB_TO_GRAY_ERR;
  167523. }
  167524. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  167525. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167526. png_ptr->transformations |= PNG_EXPAND;
  167527. #else
  167528. {
  167529. png_warning(png_ptr, "Cannot do RGB_TO_GRAY without EXPAND_SUPPORTED.");
  167530. png_ptr->transformations &= ~PNG_RGB_TO_GRAY;
  167531. }
  167532. #endif
  167533. {
  167534. png_uint_16 red_int, green_int;
  167535. if(red < 0 || green < 0)
  167536. {
  167537. red_int = 6968; /* .212671 * 32768 + .5 */
  167538. green_int = 23434; /* .715160 * 32768 + .5 */
  167539. }
  167540. else if(red + green < 100000L)
  167541. {
  167542. red_int = (png_uint_16)(((png_uint_32)red*32768L)/100000L);
  167543. green_int = (png_uint_16)(((png_uint_32)green*32768L)/100000L);
  167544. }
  167545. else
  167546. {
  167547. png_warning(png_ptr, "ignoring out of range rgb_to_gray coefficients");
  167548. red_int = 6968;
  167549. green_int = 23434;
  167550. }
  167551. png_ptr->rgb_to_gray_red_coeff = red_int;
  167552. png_ptr->rgb_to_gray_green_coeff = green_int;
  167553. png_ptr->rgb_to_gray_blue_coeff = (png_uint_16)(32768-red_int-green_int);
  167554. }
  167555. }
  167556. #endif
  167557. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  167558. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  167559. defined(PNG_LEGACY_SUPPORTED)
  167560. void PNGAPI
  167561. png_set_read_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
  167562. read_user_transform_fn)
  167563. {
  167564. png_debug(1, "in png_set_read_user_transform_fn\n");
  167565. if(png_ptr == NULL) return;
  167566. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  167567. png_ptr->transformations |= PNG_USER_TRANSFORM;
  167568. png_ptr->read_user_transform_fn = read_user_transform_fn;
  167569. #endif
  167570. #ifdef PNG_LEGACY_SUPPORTED
  167571. if(read_user_transform_fn)
  167572. png_warning(png_ptr,
  167573. "This version of libpng does not support user transforms");
  167574. #endif
  167575. }
  167576. #endif
  167577. void /* PRIVATE */
  167578. png_init_read_transformations(png_structp png_ptr)
  167579. {
  167580. png_debug(1, "in png_init_read_transformations\n");
  167581. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  167582. if(png_ptr != NULL)
  167583. #endif
  167584. {
  167585. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || defined(PNG_READ_SHIFT_SUPPORTED) \
  167586. || defined(PNG_READ_GAMMA_SUPPORTED)
  167587. int color_type = png_ptr->color_type;
  167588. #endif
  167589. #if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED)
  167590. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  167591. if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
  167592. !(color_type & PNG_COLOR_MASK_COLOR))
  167593. {
  167594. png_ptr->mode |= PNG_BACKGROUND_IS_GRAY;
  167595. } else if ((png_ptr->transformations & PNG_BACKGROUND) &&
  167596. !(png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
  167597. (png_ptr->transformations & PNG_GRAY_TO_RGB) &&
  167598. png_ptr->background.red == png_ptr->background.green &&
  167599. png_ptr->background.red == png_ptr->background.blue)
  167600. {
  167601. png_ptr->mode |= PNG_BACKGROUND_IS_GRAY;
  167602. png_ptr->background.gray = png_ptr->background.red;
  167603. }
  167604. #endif
  167605. if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
  167606. (png_ptr->transformations & PNG_EXPAND))
  167607. {
  167608. if (!(color_type & PNG_COLOR_MASK_COLOR)) /* i.e., GRAY or GRAY_ALPHA */
  167609. {
  167610. switch (png_ptr->bit_depth)
  167611. {
  167612. case 1:
  167613. png_ptr->background.gray *= (png_uint_16)0xff;
  167614. png_ptr->background.red = png_ptr->background.green
  167615. = png_ptr->background.blue = png_ptr->background.gray;
  167616. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  167617. {
  167618. png_ptr->trans_values.gray *= (png_uint_16)0xff;
  167619. png_ptr->trans_values.red = png_ptr->trans_values.green
  167620. = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
  167621. }
  167622. break;
  167623. case 2:
  167624. png_ptr->background.gray *= (png_uint_16)0x55;
  167625. png_ptr->background.red = png_ptr->background.green
  167626. = png_ptr->background.blue = png_ptr->background.gray;
  167627. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  167628. {
  167629. png_ptr->trans_values.gray *= (png_uint_16)0x55;
  167630. png_ptr->trans_values.red = png_ptr->trans_values.green
  167631. = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
  167632. }
  167633. break;
  167634. case 4:
  167635. png_ptr->background.gray *= (png_uint_16)0x11;
  167636. png_ptr->background.red = png_ptr->background.green
  167637. = png_ptr->background.blue = png_ptr->background.gray;
  167638. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  167639. {
  167640. png_ptr->trans_values.gray *= (png_uint_16)0x11;
  167641. png_ptr->trans_values.red = png_ptr->trans_values.green
  167642. = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
  167643. }
  167644. break;
  167645. case 8:
  167646. case 16:
  167647. png_ptr->background.red = png_ptr->background.green
  167648. = png_ptr->background.blue = png_ptr->background.gray;
  167649. break;
  167650. }
  167651. }
  167652. else if (color_type == PNG_COLOR_TYPE_PALETTE)
  167653. {
  167654. png_ptr->background.red =
  167655. png_ptr->palette[png_ptr->background.index].red;
  167656. png_ptr->background.green =
  167657. png_ptr->palette[png_ptr->background.index].green;
  167658. png_ptr->background.blue =
  167659. png_ptr->palette[png_ptr->background.index].blue;
  167660. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  167661. if (png_ptr->transformations & PNG_INVERT_ALPHA)
  167662. {
  167663. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167664. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  167665. #endif
  167666. {
  167667. int i,istop;
  167668. istop=(int)png_ptr->num_trans;
  167669. for (i=0; i<istop; i++)
  167670. png_ptr->trans[i] = (png_byte)(255 - png_ptr->trans[i]);
  167671. }
  167672. }
  167673. #endif
  167674. }
  167675. }
  167676. #endif
  167677. #if defined(PNG_READ_BACKGROUND_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED)
  167678. png_ptr->background_1 = png_ptr->background;
  167679. #endif
  167680. #if defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  167681. if ((color_type == PNG_COLOR_TYPE_PALETTE && png_ptr->num_trans != 0)
  167682. && (fabs(png_ptr->screen_gamma * png_ptr->gamma - 1.0)
  167683. < PNG_GAMMA_THRESHOLD))
  167684. {
  167685. int i,k;
  167686. k=0;
  167687. for (i=0; i<png_ptr->num_trans; i++)
  167688. {
  167689. if (png_ptr->trans[i] != 0 && png_ptr->trans[i] != 0xff)
  167690. k=1; /* partial transparency is present */
  167691. }
  167692. if (k == 0)
  167693. png_ptr->transformations &= (~PNG_GAMMA);
  167694. }
  167695. if ((png_ptr->transformations & (PNG_GAMMA | PNG_RGB_TO_GRAY)) &&
  167696. png_ptr->gamma != 0.0)
  167697. {
  167698. png_build_gamma_table(png_ptr);
  167699. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  167700. if (png_ptr->transformations & PNG_BACKGROUND)
  167701. {
  167702. if (color_type == PNG_COLOR_TYPE_PALETTE)
  167703. {
  167704. png_color back, back_1;
  167705. png_colorp palette = png_ptr->palette;
  167706. int num_palette = png_ptr->num_palette;
  167707. int i;
  167708. if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE)
  167709. {
  167710. back.red = png_ptr->gamma_table[png_ptr->background.red];
  167711. back.green = png_ptr->gamma_table[png_ptr->background.green];
  167712. back.blue = png_ptr->gamma_table[png_ptr->background.blue];
  167713. back_1.red = png_ptr->gamma_to_1[png_ptr->background.red];
  167714. back_1.green = png_ptr->gamma_to_1[png_ptr->background.green];
  167715. back_1.blue = png_ptr->gamma_to_1[png_ptr->background.blue];
  167716. }
  167717. else
  167718. {
  167719. double g, gs;
  167720. switch (png_ptr->background_gamma_type)
  167721. {
  167722. case PNG_BACKGROUND_GAMMA_SCREEN:
  167723. g = (png_ptr->screen_gamma);
  167724. gs = 1.0;
  167725. break;
  167726. case PNG_BACKGROUND_GAMMA_FILE:
  167727. g = 1.0 / (png_ptr->gamma);
  167728. gs = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  167729. break;
  167730. case PNG_BACKGROUND_GAMMA_UNIQUE:
  167731. g = 1.0 / (png_ptr->background_gamma);
  167732. gs = 1.0 / (png_ptr->background_gamma *
  167733. png_ptr->screen_gamma);
  167734. break;
  167735. default:
  167736. g = 1.0; /* back_1 */
  167737. gs = 1.0; /* back */
  167738. }
  167739. if ( fabs(gs - 1.0) < PNG_GAMMA_THRESHOLD)
  167740. {
  167741. back.red = (png_byte)png_ptr->background.red;
  167742. back.green = (png_byte)png_ptr->background.green;
  167743. back.blue = (png_byte)png_ptr->background.blue;
  167744. }
  167745. else
  167746. {
  167747. back.red = (png_byte)(pow(
  167748. (double)png_ptr->background.red/255, gs) * 255.0 + .5);
  167749. back.green = (png_byte)(pow(
  167750. (double)png_ptr->background.green/255, gs) * 255.0 + .5);
  167751. back.blue = (png_byte)(pow(
  167752. (double)png_ptr->background.blue/255, gs) * 255.0 + .5);
  167753. }
  167754. back_1.red = (png_byte)(pow(
  167755. (double)png_ptr->background.red/255, g) * 255.0 + .5);
  167756. back_1.green = (png_byte)(pow(
  167757. (double)png_ptr->background.green/255, g) * 255.0 + .5);
  167758. back_1.blue = (png_byte)(pow(
  167759. (double)png_ptr->background.blue/255, g) * 255.0 + .5);
  167760. }
  167761. for (i = 0; i < num_palette; i++)
  167762. {
  167763. if (i < (int)png_ptr->num_trans && png_ptr->trans[i] != 0xff)
  167764. {
  167765. if (png_ptr->trans[i] == 0)
  167766. {
  167767. palette[i] = back;
  167768. }
  167769. else /* if (png_ptr->trans[i] != 0xff) */
  167770. {
  167771. png_byte v, w;
  167772. v = png_ptr->gamma_to_1[palette[i].red];
  167773. png_composite(w, v, png_ptr->trans[i], back_1.red);
  167774. palette[i].red = png_ptr->gamma_from_1[w];
  167775. v = png_ptr->gamma_to_1[palette[i].green];
  167776. png_composite(w, v, png_ptr->trans[i], back_1.green);
  167777. palette[i].green = png_ptr->gamma_from_1[w];
  167778. v = png_ptr->gamma_to_1[palette[i].blue];
  167779. png_composite(w, v, png_ptr->trans[i], back_1.blue);
  167780. palette[i].blue = png_ptr->gamma_from_1[w];
  167781. }
  167782. }
  167783. else
  167784. {
  167785. palette[i].red = png_ptr->gamma_table[palette[i].red];
  167786. palette[i].green = png_ptr->gamma_table[palette[i].green];
  167787. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  167788. }
  167789. }
  167790. }
  167791. else
  167792. {
  167793. double m = (double)(((png_uint_32)1 << png_ptr->bit_depth) - 1);
  167794. double g = 1.0;
  167795. double gs = 1.0;
  167796. switch (png_ptr->background_gamma_type)
  167797. {
  167798. case PNG_BACKGROUND_GAMMA_SCREEN:
  167799. g = (png_ptr->screen_gamma);
  167800. gs = 1.0;
  167801. break;
  167802. case PNG_BACKGROUND_GAMMA_FILE:
  167803. g = 1.0 / (png_ptr->gamma);
  167804. gs = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  167805. break;
  167806. case PNG_BACKGROUND_GAMMA_UNIQUE:
  167807. g = 1.0 / (png_ptr->background_gamma);
  167808. gs = 1.0 / (png_ptr->background_gamma *
  167809. png_ptr->screen_gamma);
  167810. break;
  167811. }
  167812. png_ptr->background_1.gray = (png_uint_16)(pow(
  167813. (double)png_ptr->background.gray / m, g) * m + .5);
  167814. png_ptr->background.gray = (png_uint_16)(pow(
  167815. (double)png_ptr->background.gray / m, gs) * m + .5);
  167816. if ((png_ptr->background.red != png_ptr->background.green) ||
  167817. (png_ptr->background.red != png_ptr->background.blue) ||
  167818. (png_ptr->background.red != png_ptr->background.gray))
  167819. {
  167820. png_ptr->background_1.red = (png_uint_16)(pow(
  167821. (double)png_ptr->background.red / m, g) * m + .5);
  167822. png_ptr->background_1.green = (png_uint_16)(pow(
  167823. (double)png_ptr->background.green / m, g) * m + .5);
  167824. png_ptr->background_1.blue = (png_uint_16)(pow(
  167825. (double)png_ptr->background.blue / m, g) * m + .5);
  167826. png_ptr->background.red = (png_uint_16)(pow(
  167827. (double)png_ptr->background.red / m, gs) * m + .5);
  167828. png_ptr->background.green = (png_uint_16)(pow(
  167829. (double)png_ptr->background.green / m, gs) * m + .5);
  167830. png_ptr->background.blue = (png_uint_16)(pow(
  167831. (double)png_ptr->background.blue / m, gs) * m + .5);
  167832. }
  167833. else
  167834. {
  167835. png_ptr->background_1.red = png_ptr->background_1.green
  167836. = png_ptr->background_1.blue = png_ptr->background_1.gray;
  167837. png_ptr->background.red = png_ptr->background.green
  167838. = png_ptr->background.blue = png_ptr->background.gray;
  167839. }
  167840. }
  167841. }
  167842. else
  167843. #endif /* PNG_READ_BACKGROUND_SUPPORTED */
  167844. if (color_type == PNG_COLOR_TYPE_PALETTE)
  167845. {
  167846. png_colorp palette = png_ptr->palette;
  167847. int num_palette = png_ptr->num_palette;
  167848. int i;
  167849. for (i = 0; i < num_palette; i++)
  167850. {
  167851. palette[i].red = png_ptr->gamma_table[palette[i].red];
  167852. palette[i].green = png_ptr->gamma_table[palette[i].green];
  167853. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  167854. }
  167855. }
  167856. }
  167857. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  167858. else
  167859. #endif
  167860. #endif /* PNG_READ_GAMMA_SUPPORTED && PNG_FLOATING_POINT_SUPPORTED */
  167861. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  167862. if ((png_ptr->transformations & PNG_BACKGROUND) &&
  167863. (color_type == PNG_COLOR_TYPE_PALETTE))
  167864. {
  167865. int i;
  167866. int istop = (int)png_ptr->num_trans;
  167867. png_color back;
  167868. png_colorp palette = png_ptr->palette;
  167869. back.red = (png_byte)png_ptr->background.red;
  167870. back.green = (png_byte)png_ptr->background.green;
  167871. back.blue = (png_byte)png_ptr->background.blue;
  167872. for (i = 0; i < istop; i++)
  167873. {
  167874. if (png_ptr->trans[i] == 0)
  167875. {
  167876. palette[i] = back;
  167877. }
  167878. else if (png_ptr->trans[i] != 0xff)
  167879. {
  167880. png_composite(palette[i].red, palette[i].red,
  167881. png_ptr->trans[i], back.red);
  167882. png_composite(palette[i].green, palette[i].green,
  167883. png_ptr->trans[i], back.green);
  167884. png_composite(palette[i].blue, palette[i].blue,
  167885. png_ptr->trans[i], back.blue);
  167886. }
  167887. }
  167888. }
  167889. #endif /* PNG_READ_BACKGROUND_SUPPORTED */
  167890. #if defined(PNG_READ_SHIFT_SUPPORTED)
  167891. if ((png_ptr->transformations & PNG_SHIFT) &&
  167892. (color_type == PNG_COLOR_TYPE_PALETTE))
  167893. {
  167894. png_uint_16 i;
  167895. png_uint_16 istop = png_ptr->num_palette;
  167896. int sr = 8 - png_ptr->sig_bit.red;
  167897. int sg = 8 - png_ptr->sig_bit.green;
  167898. int sb = 8 - png_ptr->sig_bit.blue;
  167899. if (sr < 0 || sr > 8)
  167900. sr = 0;
  167901. if (sg < 0 || sg > 8)
  167902. sg = 0;
  167903. if (sb < 0 || sb > 8)
  167904. sb = 0;
  167905. for (i = 0; i < istop; i++)
  167906. {
  167907. png_ptr->palette[i].red >>= sr;
  167908. png_ptr->palette[i].green >>= sg;
  167909. png_ptr->palette[i].blue >>= sb;
  167910. }
  167911. }
  167912. #endif /* PNG_READ_SHIFT_SUPPORTED */
  167913. }
  167914. #if !defined(PNG_READ_GAMMA_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED) \
  167915. && !defined(PNG_READ_BACKGROUND_SUPPORTED)
  167916. if(png_ptr)
  167917. return;
  167918. #endif
  167919. }
  167920. void /* PRIVATE */
  167921. png_read_transform_info(png_structp png_ptr, png_infop info_ptr)
  167922. {
  167923. png_debug(1, "in png_read_transform_info\n");
  167924. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167925. if (png_ptr->transformations & PNG_EXPAND)
  167926. {
  167927. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  167928. {
  167929. if (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND_tRNS))
  167930. info_ptr->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
  167931. else
  167932. info_ptr->color_type = PNG_COLOR_TYPE_RGB;
  167933. info_ptr->bit_depth = 8;
  167934. info_ptr->num_trans = 0;
  167935. }
  167936. else
  167937. {
  167938. if (png_ptr->num_trans)
  167939. {
  167940. if (png_ptr->transformations & PNG_EXPAND_tRNS)
  167941. info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
  167942. else
  167943. info_ptr->color_type |= PNG_COLOR_MASK_COLOR;
  167944. }
  167945. if (info_ptr->bit_depth < 8)
  167946. info_ptr->bit_depth = 8;
  167947. info_ptr->num_trans = 0;
  167948. }
  167949. }
  167950. #endif
  167951. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  167952. if (png_ptr->transformations & PNG_BACKGROUND)
  167953. {
  167954. info_ptr->color_type &= ~PNG_COLOR_MASK_ALPHA;
  167955. info_ptr->num_trans = 0;
  167956. info_ptr->background = png_ptr->background;
  167957. }
  167958. #endif
  167959. #if defined(PNG_READ_GAMMA_SUPPORTED)
  167960. if (png_ptr->transformations & PNG_GAMMA)
  167961. {
  167962. #ifdef PNG_FLOATING_POINT_SUPPORTED
  167963. info_ptr->gamma = png_ptr->gamma;
  167964. #endif
  167965. #ifdef PNG_FIXED_POINT_SUPPORTED
  167966. info_ptr->int_gamma = png_ptr->int_gamma;
  167967. #endif
  167968. }
  167969. #endif
  167970. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  167971. if ((png_ptr->transformations & PNG_16_TO_8) && (info_ptr->bit_depth == 16))
  167972. info_ptr->bit_depth = 8;
  167973. #endif
  167974. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  167975. if (png_ptr->transformations & PNG_GRAY_TO_RGB)
  167976. info_ptr->color_type |= PNG_COLOR_MASK_COLOR;
  167977. #endif
  167978. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  167979. if (png_ptr->transformations & PNG_RGB_TO_GRAY)
  167980. info_ptr->color_type &= ~PNG_COLOR_MASK_COLOR;
  167981. #endif
  167982. #if defined(PNG_READ_DITHER_SUPPORTED)
  167983. if (png_ptr->transformations & PNG_DITHER)
  167984. {
  167985. if (((info_ptr->color_type == PNG_COLOR_TYPE_RGB) ||
  167986. (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)) &&
  167987. png_ptr->palette_lookup && info_ptr->bit_depth == 8)
  167988. {
  167989. info_ptr->color_type = PNG_COLOR_TYPE_PALETTE;
  167990. }
  167991. }
  167992. #endif
  167993. #if defined(PNG_READ_PACK_SUPPORTED)
  167994. if ((png_ptr->transformations & PNG_PACK) && (info_ptr->bit_depth < 8))
  167995. info_ptr->bit_depth = 8;
  167996. #endif
  167997. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  167998. info_ptr->channels = 1;
  167999. else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
  168000. info_ptr->channels = 3;
  168001. else
  168002. info_ptr->channels = 1;
  168003. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  168004. if (png_ptr->flags & PNG_FLAG_STRIP_ALPHA)
  168005. info_ptr->color_type &= ~PNG_COLOR_MASK_ALPHA;
  168006. #endif
  168007. if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
  168008. info_ptr->channels++;
  168009. #if defined(PNG_READ_FILLER_SUPPORTED)
  168010. if ((png_ptr->transformations & PNG_FILLER) &&
  168011. ((info_ptr->color_type == PNG_COLOR_TYPE_RGB) ||
  168012. (info_ptr->color_type == PNG_COLOR_TYPE_GRAY)))
  168013. {
  168014. info_ptr->channels++;
  168015. #if !defined(PNG_1_0_X)
  168016. if (png_ptr->transformations & PNG_ADD_ALPHA)
  168017. info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
  168018. #endif
  168019. }
  168020. #endif
  168021. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) && \
  168022. defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  168023. if(png_ptr->transformations & PNG_USER_TRANSFORM)
  168024. {
  168025. if(info_ptr->bit_depth < png_ptr->user_transform_depth)
  168026. info_ptr->bit_depth = png_ptr->user_transform_depth;
  168027. if(info_ptr->channels < png_ptr->user_transform_channels)
  168028. info_ptr->channels = png_ptr->user_transform_channels;
  168029. }
  168030. #endif
  168031. info_ptr->pixel_depth = (png_byte)(info_ptr->channels *
  168032. info_ptr->bit_depth);
  168033. info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth,info_ptr->width);
  168034. #if !defined(PNG_READ_EXPAND_SUPPORTED)
  168035. if(png_ptr)
  168036. return;
  168037. #endif
  168038. }
  168039. void /* PRIVATE */
  168040. png_do_read_transformations(png_structp png_ptr)
  168041. {
  168042. png_debug(1, "in png_do_read_transformations\n");
  168043. if (png_ptr->row_buf == NULL)
  168044. {
  168045. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  168046. char msg[50];
  168047. png_snprintf2(msg, 50,
  168048. "NULL row buffer for row %ld, pass %d", png_ptr->row_number,
  168049. png_ptr->pass);
  168050. png_error(png_ptr, msg);
  168051. #else
  168052. png_error(png_ptr, "NULL row buffer");
  168053. #endif
  168054. }
  168055. #ifdef PNG_WARN_UNINITIALIZED_ROW
  168056. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  168057. #if (PNG_WARN_UNINITIALIZED_ROW==1)
  168058. png_error(png_ptr, "Uninitialized row");
  168059. #else
  168060. png_warning(png_ptr, "Uninitialized row");
  168061. #endif
  168062. #endif
  168063. #if defined(PNG_READ_EXPAND_SUPPORTED)
  168064. if (png_ptr->transformations & PNG_EXPAND)
  168065. {
  168066. if (png_ptr->row_info.color_type == PNG_COLOR_TYPE_PALETTE)
  168067. {
  168068. png_do_expand_palette(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168069. png_ptr->palette, png_ptr->trans, png_ptr->num_trans);
  168070. }
  168071. else
  168072. {
  168073. if (png_ptr->num_trans &&
  168074. (png_ptr->transformations & PNG_EXPAND_tRNS))
  168075. png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168076. &(png_ptr->trans_values));
  168077. else
  168078. png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168079. NULL);
  168080. }
  168081. }
  168082. #endif
  168083. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  168084. if (png_ptr->flags & PNG_FLAG_STRIP_ALPHA)
  168085. png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168086. PNG_FLAG_FILLER_AFTER | (png_ptr->flags & PNG_FLAG_STRIP_ALPHA));
  168087. #endif
  168088. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  168089. if (png_ptr->transformations & PNG_RGB_TO_GRAY)
  168090. {
  168091. int rgb_error =
  168092. png_do_rgb_to_gray(png_ptr, &(png_ptr->row_info), png_ptr->row_buf + 1);
  168093. if(rgb_error)
  168094. {
  168095. png_ptr->rgb_to_gray_status=1;
  168096. if((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
  168097. PNG_RGB_TO_GRAY_WARN)
  168098. png_warning(png_ptr, "png_do_rgb_to_gray found nongray pixel");
  168099. if((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
  168100. PNG_RGB_TO_GRAY_ERR)
  168101. png_error(png_ptr, "png_do_rgb_to_gray found nongray pixel");
  168102. }
  168103. }
  168104. #endif
  168105. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168106. if ((png_ptr->transformations & PNG_GRAY_TO_RGB) &&
  168107. !(png_ptr->mode & PNG_BACKGROUND_IS_GRAY))
  168108. png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168109. #endif
  168110. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168111. if ((png_ptr->transformations & PNG_BACKGROUND) &&
  168112. ((png_ptr->num_trans != 0 ) ||
  168113. (png_ptr->color_type & PNG_COLOR_MASK_ALPHA)))
  168114. png_do_background(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168115. &(png_ptr->trans_values), &(png_ptr->background)
  168116. #if defined(PNG_READ_GAMMA_SUPPORTED)
  168117. , &(png_ptr->background_1),
  168118. png_ptr->gamma_table, png_ptr->gamma_from_1,
  168119. png_ptr->gamma_to_1, png_ptr->gamma_16_table,
  168120. png_ptr->gamma_16_from_1, png_ptr->gamma_16_to_1,
  168121. png_ptr->gamma_shift
  168122. #endif
  168123. );
  168124. #endif
  168125. #if defined(PNG_READ_GAMMA_SUPPORTED)
  168126. if ((png_ptr->transformations & PNG_GAMMA) &&
  168127. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168128. !((png_ptr->transformations & PNG_BACKGROUND) &&
  168129. ((png_ptr->num_trans != 0) ||
  168130. (png_ptr->color_type & PNG_COLOR_MASK_ALPHA))) &&
  168131. #endif
  168132. (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE))
  168133. png_do_gamma(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168134. png_ptr->gamma_table, png_ptr->gamma_16_table,
  168135. png_ptr->gamma_shift);
  168136. #endif
  168137. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  168138. if (png_ptr->transformations & PNG_16_TO_8)
  168139. png_do_chop(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168140. #endif
  168141. #if defined(PNG_READ_DITHER_SUPPORTED)
  168142. if (png_ptr->transformations & PNG_DITHER)
  168143. {
  168144. png_do_dither((png_row_infop)&(png_ptr->row_info), png_ptr->row_buf + 1,
  168145. png_ptr->palette_lookup, png_ptr->dither_index);
  168146. if(png_ptr->row_info.rowbytes == (png_uint_32)0)
  168147. png_error(png_ptr, "png_do_dither returned rowbytes=0");
  168148. }
  168149. #endif
  168150. #if defined(PNG_READ_INVERT_SUPPORTED)
  168151. if (png_ptr->transformations & PNG_INVERT_MONO)
  168152. png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168153. #endif
  168154. #if defined(PNG_READ_SHIFT_SUPPORTED)
  168155. if (png_ptr->transformations & PNG_SHIFT)
  168156. png_do_unshift(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168157. &(png_ptr->shift));
  168158. #endif
  168159. #if defined(PNG_READ_PACK_SUPPORTED)
  168160. if (png_ptr->transformations & PNG_PACK)
  168161. png_do_unpack(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168162. #endif
  168163. #if defined(PNG_READ_BGR_SUPPORTED)
  168164. if (png_ptr->transformations & PNG_BGR)
  168165. png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168166. #endif
  168167. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  168168. if (png_ptr->transformations & PNG_PACKSWAP)
  168169. png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168170. #endif
  168171. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168172. if ((png_ptr->transformations & PNG_GRAY_TO_RGB) &&
  168173. (png_ptr->mode & PNG_BACKGROUND_IS_GRAY))
  168174. png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168175. #endif
  168176. #if defined(PNG_READ_FILLER_SUPPORTED)
  168177. if (png_ptr->transformations & PNG_FILLER)
  168178. png_do_read_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168179. (png_uint_32)png_ptr->filler, png_ptr->flags);
  168180. #endif
  168181. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  168182. if (png_ptr->transformations & PNG_INVERT_ALPHA)
  168183. png_do_read_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168184. #endif
  168185. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  168186. if (png_ptr->transformations & PNG_SWAP_ALPHA)
  168187. png_do_read_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168188. #endif
  168189. #if defined(PNG_READ_SWAP_SUPPORTED)
  168190. if (png_ptr->transformations & PNG_SWAP_BYTES)
  168191. png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168192. #endif
  168193. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  168194. if (png_ptr->transformations & PNG_USER_TRANSFORM)
  168195. {
  168196. if(png_ptr->read_user_transform_fn != NULL)
  168197. (*(png_ptr->read_user_transform_fn)) /* user read transform function */
  168198. (png_ptr, /* png_ptr */
  168199. &(png_ptr->row_info), /* row_info: */
  168200. png_ptr->row_buf + 1); /* start of pixel data for row */
  168201. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  168202. if(png_ptr->user_transform_depth)
  168203. png_ptr->row_info.bit_depth = png_ptr->user_transform_depth;
  168204. if(png_ptr->user_transform_channels)
  168205. png_ptr->row_info.channels = png_ptr->user_transform_channels;
  168206. #endif
  168207. png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth *
  168208. png_ptr->row_info.channels);
  168209. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  168210. png_ptr->row_info.width);
  168211. }
  168212. #endif
  168213. }
  168214. #if defined(PNG_READ_PACK_SUPPORTED)
  168215. void /* PRIVATE */
  168216. png_do_unpack(png_row_infop row_info, png_bytep row)
  168217. {
  168218. png_debug(1, "in png_do_unpack\n");
  168219. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168220. if (row != NULL && row_info != NULL && row_info->bit_depth < 8)
  168221. #else
  168222. if (row_info->bit_depth < 8)
  168223. #endif
  168224. {
  168225. png_uint_32 i;
  168226. png_uint_32 row_width=row_info->width;
  168227. switch (row_info->bit_depth)
  168228. {
  168229. case 1:
  168230. {
  168231. png_bytep sp = row + (png_size_t)((row_width - 1) >> 3);
  168232. png_bytep dp = row + (png_size_t)row_width - 1;
  168233. png_uint_32 shift = 7 - (int)((row_width + 7) & 0x07);
  168234. for (i = 0; i < row_width; i++)
  168235. {
  168236. *dp = (png_byte)((*sp >> shift) & 0x01);
  168237. if (shift == 7)
  168238. {
  168239. shift = 0;
  168240. sp--;
  168241. }
  168242. else
  168243. shift++;
  168244. dp--;
  168245. }
  168246. break;
  168247. }
  168248. case 2:
  168249. {
  168250. png_bytep sp = row + (png_size_t)((row_width - 1) >> 2);
  168251. png_bytep dp = row + (png_size_t)row_width - 1;
  168252. png_uint_32 shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
  168253. for (i = 0; i < row_width; i++)
  168254. {
  168255. *dp = (png_byte)((*sp >> shift) & 0x03);
  168256. if (shift == 6)
  168257. {
  168258. shift = 0;
  168259. sp--;
  168260. }
  168261. else
  168262. shift += 2;
  168263. dp--;
  168264. }
  168265. break;
  168266. }
  168267. case 4:
  168268. {
  168269. png_bytep sp = row + (png_size_t)((row_width - 1) >> 1);
  168270. png_bytep dp = row + (png_size_t)row_width - 1;
  168271. png_uint_32 shift = (int)((1 - ((row_width + 1) & 0x01)) << 2);
  168272. for (i = 0; i < row_width; i++)
  168273. {
  168274. *dp = (png_byte)((*sp >> shift) & 0x0f);
  168275. if (shift == 4)
  168276. {
  168277. shift = 0;
  168278. sp--;
  168279. }
  168280. else
  168281. shift = 4;
  168282. dp--;
  168283. }
  168284. break;
  168285. }
  168286. }
  168287. row_info->bit_depth = 8;
  168288. row_info->pixel_depth = (png_byte)(8 * row_info->channels);
  168289. row_info->rowbytes = row_width * row_info->channels;
  168290. }
  168291. }
  168292. #endif
  168293. #if defined(PNG_READ_SHIFT_SUPPORTED)
  168294. void /* PRIVATE */
  168295. png_do_unshift(png_row_infop row_info, png_bytep row, png_color_8p sig_bits)
  168296. {
  168297. png_debug(1, "in png_do_unshift\n");
  168298. if (
  168299. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168300. row != NULL && row_info != NULL && sig_bits != NULL &&
  168301. #endif
  168302. row_info->color_type != PNG_COLOR_TYPE_PALETTE)
  168303. {
  168304. int shift[4];
  168305. int channels = 0;
  168306. int c;
  168307. png_uint_16 value = 0;
  168308. png_uint_32 row_width = row_info->width;
  168309. if (row_info->color_type & PNG_COLOR_MASK_COLOR)
  168310. {
  168311. shift[channels++] = row_info->bit_depth - sig_bits->red;
  168312. shift[channels++] = row_info->bit_depth - sig_bits->green;
  168313. shift[channels++] = row_info->bit_depth - sig_bits->blue;
  168314. }
  168315. else
  168316. {
  168317. shift[channels++] = row_info->bit_depth - sig_bits->gray;
  168318. }
  168319. if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
  168320. {
  168321. shift[channels++] = row_info->bit_depth - sig_bits->alpha;
  168322. }
  168323. for (c = 0; c < channels; c++)
  168324. {
  168325. if (shift[c] <= 0)
  168326. shift[c] = 0;
  168327. else
  168328. value = 1;
  168329. }
  168330. if (!value)
  168331. return;
  168332. switch (row_info->bit_depth)
  168333. {
  168334. case 2:
  168335. {
  168336. png_bytep bp;
  168337. png_uint_32 i;
  168338. png_uint_32 istop = row_info->rowbytes;
  168339. for (bp = row, i = 0; i < istop; i++)
  168340. {
  168341. *bp >>= 1;
  168342. *bp++ &= 0x55;
  168343. }
  168344. break;
  168345. }
  168346. case 4:
  168347. {
  168348. png_bytep bp = row;
  168349. png_uint_32 i;
  168350. png_uint_32 istop = row_info->rowbytes;
  168351. png_byte mask = (png_byte)((((int)0xf0 >> shift[0]) & (int)0xf0) |
  168352. (png_byte)((int)0xf >> shift[0]));
  168353. for (i = 0; i < istop; i++)
  168354. {
  168355. *bp >>= shift[0];
  168356. *bp++ &= mask;
  168357. }
  168358. break;
  168359. }
  168360. case 8:
  168361. {
  168362. png_bytep bp = row;
  168363. png_uint_32 i;
  168364. png_uint_32 istop = row_width * channels;
  168365. for (i = 0; i < istop; i++)
  168366. {
  168367. *bp++ >>= shift[i%channels];
  168368. }
  168369. break;
  168370. }
  168371. case 16:
  168372. {
  168373. png_bytep bp = row;
  168374. png_uint_32 i;
  168375. png_uint_32 istop = channels * row_width;
  168376. for (i = 0; i < istop; i++)
  168377. {
  168378. value = (png_uint_16)((*bp << 8) + *(bp + 1));
  168379. value >>= shift[i%channels];
  168380. *bp++ = (png_byte)(value >> 8);
  168381. *bp++ = (png_byte)(value & 0xff);
  168382. }
  168383. break;
  168384. }
  168385. }
  168386. }
  168387. }
  168388. #endif
  168389. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  168390. void /* PRIVATE */
  168391. png_do_chop(png_row_infop row_info, png_bytep row)
  168392. {
  168393. png_debug(1, "in png_do_chop\n");
  168394. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168395. if (row != NULL && row_info != NULL && row_info->bit_depth == 16)
  168396. #else
  168397. if (row_info->bit_depth == 16)
  168398. #endif
  168399. {
  168400. png_bytep sp = row;
  168401. png_bytep dp = row;
  168402. png_uint_32 i;
  168403. png_uint_32 istop = row_info->width * row_info->channels;
  168404. for (i = 0; i<istop; i++, sp += 2, dp++)
  168405. {
  168406. #if defined(PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED)
  168407. *dp = *sp + ((((int)(*(sp + 1)) - *sp) > 128) ? 1 : 0);
  168408. #else
  168409. *dp = *sp;
  168410. #endif
  168411. }
  168412. row_info->bit_depth = 8;
  168413. row_info->pixel_depth = (png_byte)(8 * row_info->channels);
  168414. row_info->rowbytes = row_info->width * row_info->channels;
  168415. }
  168416. }
  168417. #endif
  168418. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  168419. void /* PRIVATE */
  168420. png_do_read_swap_alpha(png_row_infop row_info, png_bytep row)
  168421. {
  168422. png_debug(1, "in png_do_read_swap_alpha\n");
  168423. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168424. if (row != NULL && row_info != NULL)
  168425. #endif
  168426. {
  168427. png_uint_32 row_width = row_info->width;
  168428. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  168429. {
  168430. if (row_info->bit_depth == 8)
  168431. {
  168432. png_bytep sp = row + row_info->rowbytes;
  168433. png_bytep dp = sp;
  168434. png_byte save;
  168435. png_uint_32 i;
  168436. for (i = 0; i < row_width; i++)
  168437. {
  168438. save = *(--sp);
  168439. *(--dp) = *(--sp);
  168440. *(--dp) = *(--sp);
  168441. *(--dp) = *(--sp);
  168442. *(--dp) = save;
  168443. }
  168444. }
  168445. else
  168446. {
  168447. png_bytep sp = row + row_info->rowbytes;
  168448. png_bytep dp = sp;
  168449. png_byte save[2];
  168450. png_uint_32 i;
  168451. for (i = 0; i < row_width; i++)
  168452. {
  168453. save[0] = *(--sp);
  168454. save[1] = *(--sp);
  168455. *(--dp) = *(--sp);
  168456. *(--dp) = *(--sp);
  168457. *(--dp) = *(--sp);
  168458. *(--dp) = *(--sp);
  168459. *(--dp) = *(--sp);
  168460. *(--dp) = *(--sp);
  168461. *(--dp) = save[0];
  168462. *(--dp) = save[1];
  168463. }
  168464. }
  168465. }
  168466. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  168467. {
  168468. if (row_info->bit_depth == 8)
  168469. {
  168470. png_bytep sp = row + row_info->rowbytes;
  168471. png_bytep dp = sp;
  168472. png_byte save;
  168473. png_uint_32 i;
  168474. for (i = 0; i < row_width; i++)
  168475. {
  168476. save = *(--sp);
  168477. *(--dp) = *(--sp);
  168478. *(--dp) = save;
  168479. }
  168480. }
  168481. else
  168482. {
  168483. png_bytep sp = row + row_info->rowbytes;
  168484. png_bytep dp = sp;
  168485. png_byte save[2];
  168486. png_uint_32 i;
  168487. for (i = 0; i < row_width; i++)
  168488. {
  168489. save[0] = *(--sp);
  168490. save[1] = *(--sp);
  168491. *(--dp) = *(--sp);
  168492. *(--dp) = *(--sp);
  168493. *(--dp) = save[0];
  168494. *(--dp) = save[1];
  168495. }
  168496. }
  168497. }
  168498. }
  168499. }
  168500. #endif
  168501. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  168502. void /* PRIVATE */
  168503. png_do_read_invert_alpha(png_row_infop row_info, png_bytep row)
  168504. {
  168505. png_debug(1, "in png_do_read_invert_alpha\n");
  168506. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168507. if (row != NULL && row_info != NULL)
  168508. #endif
  168509. {
  168510. png_uint_32 row_width = row_info->width;
  168511. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  168512. {
  168513. if (row_info->bit_depth == 8)
  168514. {
  168515. png_bytep sp = row + row_info->rowbytes;
  168516. png_bytep dp = sp;
  168517. png_uint_32 i;
  168518. for (i = 0; i < row_width; i++)
  168519. {
  168520. *(--dp) = (png_byte)(255 - *(--sp));
  168521. sp-=3;
  168522. dp=sp;
  168523. }
  168524. }
  168525. else
  168526. {
  168527. png_bytep sp = row + row_info->rowbytes;
  168528. png_bytep dp = sp;
  168529. png_uint_32 i;
  168530. for (i = 0; i < row_width; i++)
  168531. {
  168532. *(--dp) = (png_byte)(255 - *(--sp));
  168533. *(--dp) = (png_byte)(255 - *(--sp));
  168534. sp-=6;
  168535. dp=sp;
  168536. }
  168537. }
  168538. }
  168539. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  168540. {
  168541. if (row_info->bit_depth == 8)
  168542. {
  168543. png_bytep sp = row + row_info->rowbytes;
  168544. png_bytep dp = sp;
  168545. png_uint_32 i;
  168546. for (i = 0; i < row_width; i++)
  168547. {
  168548. *(--dp) = (png_byte)(255 - *(--sp));
  168549. *(--dp) = *(--sp);
  168550. }
  168551. }
  168552. else
  168553. {
  168554. png_bytep sp = row + row_info->rowbytes;
  168555. png_bytep dp = sp;
  168556. png_uint_32 i;
  168557. for (i = 0; i < row_width; i++)
  168558. {
  168559. *(--dp) = (png_byte)(255 - *(--sp));
  168560. *(--dp) = (png_byte)(255 - *(--sp));
  168561. sp-=2;
  168562. dp=sp;
  168563. }
  168564. }
  168565. }
  168566. }
  168567. }
  168568. #endif
  168569. #if defined(PNG_READ_FILLER_SUPPORTED)
  168570. void /* PRIVATE */
  168571. png_do_read_filler(png_row_infop row_info, png_bytep row,
  168572. png_uint_32 filler, png_uint_32 flags)
  168573. {
  168574. png_uint_32 i;
  168575. png_uint_32 row_width = row_info->width;
  168576. png_byte hi_filler = (png_byte)((filler>>8) & 0xff);
  168577. png_byte lo_filler = (png_byte)(filler & 0xff);
  168578. png_debug(1, "in png_do_read_filler\n");
  168579. if (
  168580. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168581. row != NULL && row_info != NULL &&
  168582. #endif
  168583. row_info->color_type == PNG_COLOR_TYPE_GRAY)
  168584. {
  168585. if(row_info->bit_depth == 8)
  168586. {
  168587. if (flags & PNG_FLAG_FILLER_AFTER)
  168588. {
  168589. png_bytep sp = row + (png_size_t)row_width;
  168590. png_bytep dp = sp + (png_size_t)row_width;
  168591. for (i = 1; i < row_width; i++)
  168592. {
  168593. *(--dp) = lo_filler;
  168594. *(--dp) = *(--sp);
  168595. }
  168596. *(--dp) = lo_filler;
  168597. row_info->channels = 2;
  168598. row_info->pixel_depth = 16;
  168599. row_info->rowbytes = row_width * 2;
  168600. }
  168601. else
  168602. {
  168603. png_bytep sp = row + (png_size_t)row_width;
  168604. png_bytep dp = sp + (png_size_t)row_width;
  168605. for (i = 0; i < row_width; i++)
  168606. {
  168607. *(--dp) = *(--sp);
  168608. *(--dp) = lo_filler;
  168609. }
  168610. row_info->channels = 2;
  168611. row_info->pixel_depth = 16;
  168612. row_info->rowbytes = row_width * 2;
  168613. }
  168614. }
  168615. else if(row_info->bit_depth == 16)
  168616. {
  168617. if (flags & PNG_FLAG_FILLER_AFTER)
  168618. {
  168619. png_bytep sp = row + (png_size_t)row_width * 2;
  168620. png_bytep dp = sp + (png_size_t)row_width * 2;
  168621. for (i = 1; i < row_width; i++)
  168622. {
  168623. *(--dp) = hi_filler;
  168624. *(--dp) = lo_filler;
  168625. *(--dp) = *(--sp);
  168626. *(--dp) = *(--sp);
  168627. }
  168628. *(--dp) = hi_filler;
  168629. *(--dp) = lo_filler;
  168630. row_info->channels = 2;
  168631. row_info->pixel_depth = 32;
  168632. row_info->rowbytes = row_width * 4;
  168633. }
  168634. else
  168635. {
  168636. png_bytep sp = row + (png_size_t)row_width * 2;
  168637. png_bytep dp = sp + (png_size_t)row_width * 2;
  168638. for (i = 0; i < row_width; i++)
  168639. {
  168640. *(--dp) = *(--sp);
  168641. *(--dp) = *(--sp);
  168642. *(--dp) = hi_filler;
  168643. *(--dp) = lo_filler;
  168644. }
  168645. row_info->channels = 2;
  168646. row_info->pixel_depth = 32;
  168647. row_info->rowbytes = row_width * 4;
  168648. }
  168649. }
  168650. } /* COLOR_TYPE == GRAY */
  168651. else if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  168652. {
  168653. if(row_info->bit_depth == 8)
  168654. {
  168655. if (flags & PNG_FLAG_FILLER_AFTER)
  168656. {
  168657. png_bytep sp = row + (png_size_t)row_width * 3;
  168658. png_bytep dp = sp + (png_size_t)row_width;
  168659. for (i = 1; i < row_width; i++)
  168660. {
  168661. *(--dp) = lo_filler;
  168662. *(--dp) = *(--sp);
  168663. *(--dp) = *(--sp);
  168664. *(--dp) = *(--sp);
  168665. }
  168666. *(--dp) = lo_filler;
  168667. row_info->channels = 4;
  168668. row_info->pixel_depth = 32;
  168669. row_info->rowbytes = row_width * 4;
  168670. }
  168671. else
  168672. {
  168673. png_bytep sp = row + (png_size_t)row_width * 3;
  168674. png_bytep dp = sp + (png_size_t)row_width;
  168675. for (i = 0; i < row_width; i++)
  168676. {
  168677. *(--dp) = *(--sp);
  168678. *(--dp) = *(--sp);
  168679. *(--dp) = *(--sp);
  168680. *(--dp) = lo_filler;
  168681. }
  168682. row_info->channels = 4;
  168683. row_info->pixel_depth = 32;
  168684. row_info->rowbytes = row_width * 4;
  168685. }
  168686. }
  168687. else if(row_info->bit_depth == 16)
  168688. {
  168689. if (flags & PNG_FLAG_FILLER_AFTER)
  168690. {
  168691. png_bytep sp = row + (png_size_t)row_width * 6;
  168692. png_bytep dp = sp + (png_size_t)row_width * 2;
  168693. for (i = 1; i < row_width; i++)
  168694. {
  168695. *(--dp) = hi_filler;
  168696. *(--dp) = lo_filler;
  168697. *(--dp) = *(--sp);
  168698. *(--dp) = *(--sp);
  168699. *(--dp) = *(--sp);
  168700. *(--dp) = *(--sp);
  168701. *(--dp) = *(--sp);
  168702. *(--dp) = *(--sp);
  168703. }
  168704. *(--dp) = hi_filler;
  168705. *(--dp) = lo_filler;
  168706. row_info->channels = 4;
  168707. row_info->pixel_depth = 64;
  168708. row_info->rowbytes = row_width * 8;
  168709. }
  168710. else
  168711. {
  168712. png_bytep sp = row + (png_size_t)row_width * 6;
  168713. png_bytep dp = sp + (png_size_t)row_width * 2;
  168714. for (i = 0; i < row_width; i++)
  168715. {
  168716. *(--dp) = *(--sp);
  168717. *(--dp) = *(--sp);
  168718. *(--dp) = *(--sp);
  168719. *(--dp) = *(--sp);
  168720. *(--dp) = *(--sp);
  168721. *(--dp) = *(--sp);
  168722. *(--dp) = hi_filler;
  168723. *(--dp) = lo_filler;
  168724. }
  168725. row_info->channels = 4;
  168726. row_info->pixel_depth = 64;
  168727. row_info->rowbytes = row_width * 8;
  168728. }
  168729. }
  168730. } /* COLOR_TYPE == RGB */
  168731. }
  168732. #endif
  168733. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168734. void /* PRIVATE */
  168735. png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
  168736. {
  168737. png_uint_32 i;
  168738. png_uint_32 row_width = row_info->width;
  168739. png_debug(1, "in png_do_gray_to_rgb\n");
  168740. if (row_info->bit_depth >= 8 &&
  168741. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168742. row != NULL && row_info != NULL &&
  168743. #endif
  168744. !(row_info->color_type & PNG_COLOR_MASK_COLOR))
  168745. {
  168746. if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
  168747. {
  168748. if (row_info->bit_depth == 8)
  168749. {
  168750. png_bytep sp = row + (png_size_t)row_width - 1;
  168751. png_bytep dp = sp + (png_size_t)row_width * 2;
  168752. for (i = 0; i < row_width; i++)
  168753. {
  168754. *(dp--) = *sp;
  168755. *(dp--) = *sp;
  168756. *(dp--) = *(sp--);
  168757. }
  168758. }
  168759. else
  168760. {
  168761. png_bytep sp = row + (png_size_t)row_width * 2 - 1;
  168762. png_bytep dp = sp + (png_size_t)row_width * 4;
  168763. for (i = 0; i < row_width; i++)
  168764. {
  168765. *(dp--) = *sp;
  168766. *(dp--) = *(sp - 1);
  168767. *(dp--) = *sp;
  168768. *(dp--) = *(sp - 1);
  168769. *(dp--) = *(sp--);
  168770. *(dp--) = *(sp--);
  168771. }
  168772. }
  168773. }
  168774. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  168775. {
  168776. if (row_info->bit_depth == 8)
  168777. {
  168778. png_bytep sp = row + (png_size_t)row_width * 2 - 1;
  168779. png_bytep dp = sp + (png_size_t)row_width * 2;
  168780. for (i = 0; i < row_width; i++)
  168781. {
  168782. *(dp--) = *(sp--);
  168783. *(dp--) = *sp;
  168784. *(dp--) = *sp;
  168785. *(dp--) = *(sp--);
  168786. }
  168787. }
  168788. else
  168789. {
  168790. png_bytep sp = row + (png_size_t)row_width * 4 - 1;
  168791. png_bytep dp = sp + (png_size_t)row_width * 4;
  168792. for (i = 0; i < row_width; i++)
  168793. {
  168794. *(dp--) = *(sp--);
  168795. *(dp--) = *(sp--);
  168796. *(dp--) = *sp;
  168797. *(dp--) = *(sp - 1);
  168798. *(dp--) = *sp;
  168799. *(dp--) = *(sp - 1);
  168800. *(dp--) = *(sp--);
  168801. *(dp--) = *(sp--);
  168802. }
  168803. }
  168804. }
  168805. row_info->channels += (png_byte)2;
  168806. row_info->color_type |= PNG_COLOR_MASK_COLOR;
  168807. row_info->pixel_depth = (png_byte)(row_info->channels *
  168808. row_info->bit_depth);
  168809. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  168810. }
  168811. }
  168812. #endif
  168813. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  168814. int /* PRIVATE */
  168815. png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)
  168816. {
  168817. png_uint_32 i;
  168818. png_uint_32 row_width = row_info->width;
  168819. int rgb_error = 0;
  168820. png_debug(1, "in png_do_rgb_to_gray\n");
  168821. if (
  168822. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168823. row != NULL && row_info != NULL &&
  168824. #endif
  168825. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  168826. {
  168827. png_uint_32 rc = png_ptr->rgb_to_gray_red_coeff;
  168828. png_uint_32 gc = png_ptr->rgb_to_gray_green_coeff;
  168829. png_uint_32 bc = png_ptr->rgb_to_gray_blue_coeff;
  168830. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  168831. {
  168832. if (row_info->bit_depth == 8)
  168833. {
  168834. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  168835. if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL)
  168836. {
  168837. png_bytep sp = row;
  168838. png_bytep dp = row;
  168839. for (i = 0; i < row_width; i++)
  168840. {
  168841. png_byte red = png_ptr->gamma_to_1[*(sp++)];
  168842. png_byte green = png_ptr->gamma_to_1[*(sp++)];
  168843. png_byte blue = png_ptr->gamma_to_1[*(sp++)];
  168844. if(red != green || red != blue)
  168845. {
  168846. rgb_error |= 1;
  168847. *(dp++) = png_ptr->gamma_from_1[
  168848. (rc*red+gc*green+bc*blue)>>15];
  168849. }
  168850. else
  168851. *(dp++) = *(sp-1);
  168852. }
  168853. }
  168854. else
  168855. #endif
  168856. {
  168857. png_bytep sp = row;
  168858. png_bytep dp = row;
  168859. for (i = 0; i < row_width; i++)
  168860. {
  168861. png_byte red = *(sp++);
  168862. png_byte green = *(sp++);
  168863. png_byte blue = *(sp++);
  168864. if(red != green || red != blue)
  168865. {
  168866. rgb_error |= 1;
  168867. *(dp++) = (png_byte)((rc*red+gc*green+bc*blue)>>15);
  168868. }
  168869. else
  168870. *(dp++) = *(sp-1);
  168871. }
  168872. }
  168873. }
  168874. else /* RGB bit_depth == 16 */
  168875. {
  168876. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  168877. if (png_ptr->gamma_16_to_1 != NULL &&
  168878. png_ptr->gamma_16_from_1 != NULL)
  168879. {
  168880. png_bytep sp = row;
  168881. png_bytep dp = row;
  168882. for (i = 0; i < row_width; i++)
  168883. {
  168884. png_uint_16 red, green, blue, w;
  168885. red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168886. green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168887. blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168888. if(red == green && red == blue)
  168889. w = red;
  168890. else
  168891. {
  168892. png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red&0xff) >>
  168893. png_ptr->gamma_shift][red>>8];
  168894. png_uint_16 green_1 = png_ptr->gamma_16_to_1[(green&0xff) >>
  168895. png_ptr->gamma_shift][green>>8];
  168896. png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >>
  168897. png_ptr->gamma_shift][blue>>8];
  168898. png_uint_16 gray16 = (png_uint_16)((rc*red_1 + gc*green_1
  168899. + bc*blue_1)>>15);
  168900. w = png_ptr->gamma_16_from_1[(gray16&0xff) >>
  168901. png_ptr->gamma_shift][gray16 >> 8];
  168902. rgb_error |= 1;
  168903. }
  168904. *(dp++) = (png_byte)((w>>8) & 0xff);
  168905. *(dp++) = (png_byte)(w & 0xff);
  168906. }
  168907. }
  168908. else
  168909. #endif
  168910. {
  168911. png_bytep sp = row;
  168912. png_bytep dp = row;
  168913. for (i = 0; i < row_width; i++)
  168914. {
  168915. png_uint_16 red, green, blue, gray16;
  168916. red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168917. green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168918. blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168919. if(red != green || red != blue)
  168920. rgb_error |= 1;
  168921. gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>15);
  168922. *(dp++) = (png_byte)((gray16>>8) & 0xff);
  168923. *(dp++) = (png_byte)(gray16 & 0xff);
  168924. }
  168925. }
  168926. }
  168927. }
  168928. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  168929. {
  168930. if (row_info->bit_depth == 8)
  168931. {
  168932. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  168933. if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL)
  168934. {
  168935. png_bytep sp = row;
  168936. png_bytep dp = row;
  168937. for (i = 0; i < row_width; i++)
  168938. {
  168939. png_byte red = png_ptr->gamma_to_1[*(sp++)];
  168940. png_byte green = png_ptr->gamma_to_1[*(sp++)];
  168941. png_byte blue = png_ptr->gamma_to_1[*(sp++)];
  168942. if(red != green || red != blue)
  168943. rgb_error |= 1;
  168944. *(dp++) = png_ptr->gamma_from_1
  168945. [(rc*red + gc*green + bc*blue)>>15];
  168946. *(dp++) = *(sp++); /* alpha */
  168947. }
  168948. }
  168949. else
  168950. #endif
  168951. {
  168952. png_bytep sp = row;
  168953. png_bytep dp = row;
  168954. for (i = 0; i < row_width; i++)
  168955. {
  168956. png_byte red = *(sp++);
  168957. png_byte green = *(sp++);
  168958. png_byte blue = *(sp++);
  168959. if(red != green || red != blue)
  168960. rgb_error |= 1;
  168961. *(dp++) = (png_byte)((rc*red + gc*green + bc*blue)>>15);
  168962. *(dp++) = *(sp++); /* alpha */
  168963. }
  168964. }
  168965. }
  168966. else /* RGBA bit_depth == 16 */
  168967. {
  168968. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  168969. if (png_ptr->gamma_16_to_1 != NULL &&
  168970. png_ptr->gamma_16_from_1 != NULL)
  168971. {
  168972. png_bytep sp = row;
  168973. png_bytep dp = row;
  168974. for (i = 0; i < row_width; i++)
  168975. {
  168976. png_uint_16 red, green, blue, w;
  168977. red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168978. green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168979. blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168980. if(red == green && red == blue)
  168981. w = red;
  168982. else
  168983. {
  168984. png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red&0xff) >>
  168985. png_ptr->gamma_shift][red>>8];
  168986. png_uint_16 green_1 = png_ptr->gamma_16_to_1[(green&0xff) >>
  168987. png_ptr->gamma_shift][green>>8];
  168988. png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >>
  168989. png_ptr->gamma_shift][blue>>8];
  168990. png_uint_16 gray16 = (png_uint_16)((rc * red_1
  168991. + gc * green_1 + bc * blue_1)>>15);
  168992. w = png_ptr->gamma_16_from_1[(gray16&0xff) >>
  168993. png_ptr->gamma_shift][gray16 >> 8];
  168994. rgb_error |= 1;
  168995. }
  168996. *(dp++) = (png_byte)((w>>8) & 0xff);
  168997. *(dp++) = (png_byte)(w & 0xff);
  168998. *(dp++) = *(sp++); /* alpha */
  168999. *(dp++) = *(sp++);
  169000. }
  169001. }
  169002. else
  169003. #endif
  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, gray16;
  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. rgb_error |= 1;
  169015. gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>15);
  169016. *(dp++) = (png_byte)((gray16>>8) & 0xff);
  169017. *(dp++) = (png_byte)(gray16 & 0xff);
  169018. *(dp++) = *(sp++); /* alpha */
  169019. *(dp++) = *(sp++);
  169020. }
  169021. }
  169022. }
  169023. }
  169024. row_info->channels -= (png_byte)2;
  169025. row_info->color_type &= ~PNG_COLOR_MASK_COLOR;
  169026. row_info->pixel_depth = (png_byte)(row_info->channels *
  169027. row_info->bit_depth);
  169028. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  169029. }
  169030. return rgb_error;
  169031. }
  169032. #endif
  169033. void PNGAPI
  169034. png_build_grayscale_palette(int bit_depth, png_colorp palette)
  169035. {
  169036. int num_palette;
  169037. int color_inc;
  169038. int i;
  169039. int v;
  169040. png_debug(1, "in png_do_build_grayscale_palette\n");
  169041. if (palette == NULL)
  169042. return;
  169043. switch (bit_depth)
  169044. {
  169045. case 1:
  169046. num_palette = 2;
  169047. color_inc = 0xff;
  169048. break;
  169049. case 2:
  169050. num_palette = 4;
  169051. color_inc = 0x55;
  169052. break;
  169053. case 4:
  169054. num_palette = 16;
  169055. color_inc = 0x11;
  169056. break;
  169057. case 8:
  169058. num_palette = 256;
  169059. color_inc = 1;
  169060. break;
  169061. default:
  169062. num_palette = 0;
  169063. color_inc = 0;
  169064. break;
  169065. }
  169066. for (i = 0, v = 0; i < num_palette; i++, v += color_inc)
  169067. {
  169068. palette[i].red = (png_byte)v;
  169069. palette[i].green = (png_byte)v;
  169070. palette[i].blue = (png_byte)v;
  169071. }
  169072. }
  169073. #if defined(PNG_READ_DITHER_SUPPORTED) && defined(PNG_CORRECT_PALETTE_SUPPORTED)
  169074. void /* PRIVATE */
  169075. png_correct_palette(png_structp png_ptr, png_colorp palette,
  169076. int num_palette)
  169077. {
  169078. png_debug(1, "in png_correct_palette\n");
  169079. #if defined(PNG_READ_BACKGROUND_SUPPORTED) && \
  169080. defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  169081. if (png_ptr->transformations & (PNG_GAMMA | PNG_BACKGROUND))
  169082. {
  169083. png_color back, back_1;
  169084. if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE)
  169085. {
  169086. back.red = png_ptr->gamma_table[png_ptr->background.red];
  169087. back.green = png_ptr->gamma_table[png_ptr->background.green];
  169088. back.blue = png_ptr->gamma_table[png_ptr->background.blue];
  169089. back_1.red = png_ptr->gamma_to_1[png_ptr->background.red];
  169090. back_1.green = png_ptr->gamma_to_1[png_ptr->background.green];
  169091. back_1.blue = png_ptr->gamma_to_1[png_ptr->background.blue];
  169092. }
  169093. else
  169094. {
  169095. double g;
  169096. g = 1.0 / (png_ptr->background_gamma * png_ptr->screen_gamma);
  169097. if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_SCREEN ||
  169098. fabs(g - 1.0) < PNG_GAMMA_THRESHOLD)
  169099. {
  169100. back.red = png_ptr->background.red;
  169101. back.green = png_ptr->background.green;
  169102. back.blue = png_ptr->background.blue;
  169103. }
  169104. else
  169105. {
  169106. back.red =
  169107. (png_byte)(pow((double)png_ptr->background.red/255, g) *
  169108. 255.0 + 0.5);
  169109. back.green =
  169110. (png_byte)(pow((double)png_ptr->background.green/255, g) *
  169111. 255.0 + 0.5);
  169112. back.blue =
  169113. (png_byte)(pow((double)png_ptr->background.blue/255, g) *
  169114. 255.0 + 0.5);
  169115. }
  169116. g = 1.0 / png_ptr->background_gamma;
  169117. back_1.red =
  169118. (png_byte)(pow((double)png_ptr->background.red/255, g) *
  169119. 255.0 + 0.5);
  169120. back_1.green =
  169121. (png_byte)(pow((double)png_ptr->background.green/255, g) *
  169122. 255.0 + 0.5);
  169123. back_1.blue =
  169124. (png_byte)(pow((double)png_ptr->background.blue/255, g) *
  169125. 255.0 + 0.5);
  169126. }
  169127. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  169128. {
  169129. png_uint_32 i;
  169130. for (i = 0; i < (png_uint_32)num_palette; i++)
  169131. {
  169132. if (i < png_ptr->num_trans && png_ptr->trans[i] == 0)
  169133. {
  169134. palette[i] = back;
  169135. }
  169136. else if (i < png_ptr->num_trans && png_ptr->trans[i] != 0xff)
  169137. {
  169138. png_byte v, w;
  169139. v = png_ptr->gamma_to_1[png_ptr->palette[i].red];
  169140. png_composite(w, v, png_ptr->trans[i], back_1.red);
  169141. palette[i].red = png_ptr->gamma_from_1[w];
  169142. v = png_ptr->gamma_to_1[png_ptr->palette[i].green];
  169143. png_composite(w, v, png_ptr->trans[i], back_1.green);
  169144. palette[i].green = png_ptr->gamma_from_1[w];
  169145. v = png_ptr->gamma_to_1[png_ptr->palette[i].blue];
  169146. png_composite(w, v, png_ptr->trans[i], back_1.blue);
  169147. palette[i].blue = png_ptr->gamma_from_1[w];
  169148. }
  169149. else
  169150. {
  169151. palette[i].red = png_ptr->gamma_table[palette[i].red];
  169152. palette[i].green = png_ptr->gamma_table[palette[i].green];
  169153. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  169154. }
  169155. }
  169156. }
  169157. else
  169158. {
  169159. int i;
  169160. for (i = 0; i < num_palette; i++)
  169161. {
  169162. if (palette[i].red == (png_byte)png_ptr->trans_values.gray)
  169163. {
  169164. palette[i] = back;
  169165. }
  169166. else
  169167. {
  169168. palette[i].red = png_ptr->gamma_table[palette[i].red];
  169169. palette[i].green = png_ptr->gamma_table[palette[i].green];
  169170. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  169171. }
  169172. }
  169173. }
  169174. }
  169175. else
  169176. #endif
  169177. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169178. if (png_ptr->transformations & PNG_GAMMA)
  169179. {
  169180. int i;
  169181. for (i = 0; i < num_palette; i++)
  169182. {
  169183. palette[i].red = png_ptr->gamma_table[palette[i].red];
  169184. palette[i].green = png_ptr->gamma_table[palette[i].green];
  169185. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  169186. }
  169187. }
  169188. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  169189. else
  169190. #endif
  169191. #endif
  169192. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  169193. if (png_ptr->transformations & PNG_BACKGROUND)
  169194. {
  169195. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  169196. {
  169197. png_color back;
  169198. back.red = (png_byte)png_ptr->background.red;
  169199. back.green = (png_byte)png_ptr->background.green;
  169200. back.blue = (png_byte)png_ptr->background.blue;
  169201. for (i = 0; i < (int)png_ptr->num_trans; i++)
  169202. {
  169203. if (png_ptr->trans[i] == 0)
  169204. {
  169205. palette[i].red = back.red;
  169206. palette[i].green = back.green;
  169207. palette[i].blue = back.blue;
  169208. }
  169209. else if (png_ptr->trans[i] != 0xff)
  169210. {
  169211. png_composite(palette[i].red, png_ptr->palette[i].red,
  169212. png_ptr->trans[i], back.red);
  169213. png_composite(palette[i].green, png_ptr->palette[i].green,
  169214. png_ptr->trans[i], back.green);
  169215. png_composite(palette[i].blue, png_ptr->palette[i].blue,
  169216. png_ptr->trans[i], back.blue);
  169217. }
  169218. }
  169219. }
  169220. else /* assume grayscale palette (what else could it be?) */
  169221. {
  169222. int i;
  169223. for (i = 0; i < num_palette; i++)
  169224. {
  169225. if (i == (png_byte)png_ptr->trans_values.gray)
  169226. {
  169227. palette[i].red = (png_byte)png_ptr->background.red;
  169228. palette[i].green = (png_byte)png_ptr->background.green;
  169229. palette[i].blue = (png_byte)png_ptr->background.blue;
  169230. }
  169231. }
  169232. }
  169233. }
  169234. #endif
  169235. }
  169236. #endif
  169237. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  169238. void /* PRIVATE */
  169239. png_do_background(png_row_infop row_info, png_bytep row,
  169240. png_color_16p trans_values, png_color_16p background
  169241. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169242. , png_color_16p background_1,
  169243. png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1,
  169244. png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1,
  169245. png_uint_16pp gamma_16_to_1, int gamma_shift
  169246. #endif
  169247. )
  169248. {
  169249. png_bytep sp, dp;
  169250. png_uint_32 i;
  169251. png_uint_32 row_width=row_info->width;
  169252. int shift;
  169253. png_debug(1, "in png_do_background\n");
  169254. if (background != NULL &&
  169255. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169256. row != NULL && row_info != NULL &&
  169257. #endif
  169258. (!(row_info->color_type & PNG_COLOR_MASK_ALPHA) ||
  169259. (row_info->color_type != PNG_COLOR_TYPE_PALETTE && trans_values)))
  169260. {
  169261. switch (row_info->color_type)
  169262. {
  169263. case PNG_COLOR_TYPE_GRAY:
  169264. {
  169265. switch (row_info->bit_depth)
  169266. {
  169267. case 1:
  169268. {
  169269. sp = row;
  169270. shift = 7;
  169271. for (i = 0; i < row_width; i++)
  169272. {
  169273. if ((png_uint_16)((*sp >> shift) & 0x01)
  169274. == trans_values->gray)
  169275. {
  169276. *sp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff);
  169277. *sp |= (png_byte)(background->gray << shift);
  169278. }
  169279. if (!shift)
  169280. {
  169281. shift = 7;
  169282. sp++;
  169283. }
  169284. else
  169285. shift--;
  169286. }
  169287. break;
  169288. }
  169289. case 2:
  169290. {
  169291. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169292. if (gamma_table != NULL)
  169293. {
  169294. sp = row;
  169295. shift = 6;
  169296. for (i = 0; i < row_width; i++)
  169297. {
  169298. if ((png_uint_16)((*sp >> shift) & 0x03)
  169299. == trans_values->gray)
  169300. {
  169301. *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  169302. *sp |= (png_byte)(background->gray << shift);
  169303. }
  169304. else
  169305. {
  169306. png_byte p = (png_byte)((*sp >> shift) & 0x03);
  169307. png_byte g = (png_byte)((gamma_table [p | (p << 2) |
  169308. (p << 4) | (p << 6)] >> 6) & 0x03);
  169309. *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  169310. *sp |= (png_byte)(g << shift);
  169311. }
  169312. if (!shift)
  169313. {
  169314. shift = 6;
  169315. sp++;
  169316. }
  169317. else
  169318. shift -= 2;
  169319. }
  169320. }
  169321. else
  169322. #endif
  169323. {
  169324. sp = row;
  169325. shift = 6;
  169326. for (i = 0; i < row_width; i++)
  169327. {
  169328. if ((png_uint_16)((*sp >> shift) & 0x03)
  169329. == trans_values->gray)
  169330. {
  169331. *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  169332. *sp |= (png_byte)(background->gray << shift);
  169333. }
  169334. if (!shift)
  169335. {
  169336. shift = 6;
  169337. sp++;
  169338. }
  169339. else
  169340. shift -= 2;
  169341. }
  169342. }
  169343. break;
  169344. }
  169345. case 4:
  169346. {
  169347. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169348. if (gamma_table != NULL)
  169349. {
  169350. sp = row;
  169351. shift = 4;
  169352. for (i = 0; i < row_width; i++)
  169353. {
  169354. if ((png_uint_16)((*sp >> shift) & 0x0f)
  169355. == trans_values->gray)
  169356. {
  169357. *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  169358. *sp |= (png_byte)(background->gray << shift);
  169359. }
  169360. else
  169361. {
  169362. png_byte p = (png_byte)((*sp >> shift) & 0x0f);
  169363. png_byte g = (png_byte)((gamma_table[p |
  169364. (p << 4)] >> 4) & 0x0f);
  169365. *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  169366. *sp |= (png_byte)(g << shift);
  169367. }
  169368. if (!shift)
  169369. {
  169370. shift = 4;
  169371. sp++;
  169372. }
  169373. else
  169374. shift -= 4;
  169375. }
  169376. }
  169377. else
  169378. #endif
  169379. {
  169380. sp = row;
  169381. shift = 4;
  169382. for (i = 0; i < row_width; i++)
  169383. {
  169384. if ((png_uint_16)((*sp >> shift) & 0x0f)
  169385. == trans_values->gray)
  169386. {
  169387. *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  169388. *sp |= (png_byte)(background->gray << shift);
  169389. }
  169390. if (!shift)
  169391. {
  169392. shift = 4;
  169393. sp++;
  169394. }
  169395. else
  169396. shift -= 4;
  169397. }
  169398. }
  169399. break;
  169400. }
  169401. case 8:
  169402. {
  169403. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169404. if (gamma_table != NULL)
  169405. {
  169406. sp = row;
  169407. for (i = 0; i < row_width; i++, sp++)
  169408. {
  169409. if (*sp == trans_values->gray)
  169410. {
  169411. *sp = (png_byte)background->gray;
  169412. }
  169413. else
  169414. {
  169415. *sp = gamma_table[*sp];
  169416. }
  169417. }
  169418. }
  169419. else
  169420. #endif
  169421. {
  169422. sp = row;
  169423. for (i = 0; i < row_width; i++, sp++)
  169424. {
  169425. if (*sp == trans_values->gray)
  169426. {
  169427. *sp = (png_byte)background->gray;
  169428. }
  169429. }
  169430. }
  169431. break;
  169432. }
  169433. case 16:
  169434. {
  169435. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169436. if (gamma_16 != NULL)
  169437. {
  169438. sp = row;
  169439. for (i = 0; i < row_width; i++, sp += 2)
  169440. {
  169441. png_uint_16 v;
  169442. v = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169443. if (v == trans_values->gray)
  169444. {
  169445. *sp = (png_byte)((background->gray >> 8) & 0xff);
  169446. *(sp + 1) = (png_byte)(background->gray & 0xff);
  169447. }
  169448. else
  169449. {
  169450. v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169451. *sp = (png_byte)((v >> 8) & 0xff);
  169452. *(sp + 1) = (png_byte)(v & 0xff);
  169453. }
  169454. }
  169455. }
  169456. else
  169457. #endif
  169458. {
  169459. sp = row;
  169460. for (i = 0; i < row_width; i++, sp += 2)
  169461. {
  169462. png_uint_16 v;
  169463. v = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169464. if (v == trans_values->gray)
  169465. {
  169466. *sp = (png_byte)((background->gray >> 8) & 0xff);
  169467. *(sp + 1) = (png_byte)(background->gray & 0xff);
  169468. }
  169469. }
  169470. }
  169471. break;
  169472. }
  169473. }
  169474. break;
  169475. }
  169476. case PNG_COLOR_TYPE_RGB:
  169477. {
  169478. if (row_info->bit_depth == 8)
  169479. {
  169480. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169481. if (gamma_table != NULL)
  169482. {
  169483. sp = row;
  169484. for (i = 0; i < row_width; i++, sp += 3)
  169485. {
  169486. if (*sp == trans_values->red &&
  169487. *(sp + 1) == trans_values->green &&
  169488. *(sp + 2) == trans_values->blue)
  169489. {
  169490. *sp = (png_byte)background->red;
  169491. *(sp + 1) = (png_byte)background->green;
  169492. *(sp + 2) = (png_byte)background->blue;
  169493. }
  169494. else
  169495. {
  169496. *sp = gamma_table[*sp];
  169497. *(sp + 1) = gamma_table[*(sp + 1)];
  169498. *(sp + 2) = gamma_table[*(sp + 2)];
  169499. }
  169500. }
  169501. }
  169502. else
  169503. #endif
  169504. {
  169505. sp = row;
  169506. for (i = 0; i < row_width; i++, sp += 3)
  169507. {
  169508. if (*sp == trans_values->red &&
  169509. *(sp + 1) == trans_values->green &&
  169510. *(sp + 2) == trans_values->blue)
  169511. {
  169512. *sp = (png_byte)background->red;
  169513. *(sp + 1) = (png_byte)background->green;
  169514. *(sp + 2) = (png_byte)background->blue;
  169515. }
  169516. }
  169517. }
  169518. }
  169519. else /* if (row_info->bit_depth == 16) */
  169520. {
  169521. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169522. if (gamma_16 != NULL)
  169523. {
  169524. sp = row;
  169525. for (i = 0; i < row_width; i++, sp += 6)
  169526. {
  169527. png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169528. png_uint_16 g = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169529. png_uint_16 b = (png_uint_16)(((*(sp+4)) << 8) + *(sp+5));
  169530. if (r == trans_values->red && g == trans_values->green &&
  169531. b == trans_values->blue)
  169532. {
  169533. *sp = (png_byte)((background->red >> 8) & 0xff);
  169534. *(sp + 1) = (png_byte)(background->red & 0xff);
  169535. *(sp + 2) = (png_byte)((background->green >> 8) & 0xff);
  169536. *(sp + 3) = (png_byte)(background->green & 0xff);
  169537. *(sp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  169538. *(sp + 5) = (png_byte)(background->blue & 0xff);
  169539. }
  169540. else
  169541. {
  169542. png_uint_16 v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169543. *sp = (png_byte)((v >> 8) & 0xff);
  169544. *(sp + 1) = (png_byte)(v & 0xff);
  169545. v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)];
  169546. *(sp + 2) = (png_byte)((v >> 8) & 0xff);
  169547. *(sp + 3) = (png_byte)(v & 0xff);
  169548. v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)];
  169549. *(sp + 4) = (png_byte)((v >> 8) & 0xff);
  169550. *(sp + 5) = (png_byte)(v & 0xff);
  169551. }
  169552. }
  169553. }
  169554. else
  169555. #endif
  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. }
  169574. }
  169575. }
  169576. break;
  169577. }
  169578. case PNG_COLOR_TYPE_GRAY_ALPHA:
  169579. {
  169580. if (row_info->bit_depth == 8)
  169581. {
  169582. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169583. if (gamma_to_1 != NULL && gamma_from_1 != NULL &&
  169584. gamma_table != NULL)
  169585. {
  169586. sp = row;
  169587. dp = row;
  169588. for (i = 0; i < row_width; i++, sp += 2, dp++)
  169589. {
  169590. png_uint_16 a = *(sp + 1);
  169591. if (a == 0xff)
  169592. {
  169593. *dp = gamma_table[*sp];
  169594. }
  169595. else if (a == 0)
  169596. {
  169597. *dp = (png_byte)background->gray;
  169598. }
  169599. else
  169600. {
  169601. png_byte v, w;
  169602. v = gamma_to_1[*sp];
  169603. png_composite(w, v, a, background_1->gray);
  169604. *dp = gamma_from_1[w];
  169605. }
  169606. }
  169607. }
  169608. else
  169609. #endif
  169610. {
  169611. sp = row;
  169612. dp = row;
  169613. for (i = 0; i < row_width; i++, sp += 2, dp++)
  169614. {
  169615. png_byte a = *(sp + 1);
  169616. if (a == 0xff)
  169617. {
  169618. *dp = *sp;
  169619. }
  169620. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169621. else if (a == 0)
  169622. {
  169623. *dp = (png_byte)background->gray;
  169624. }
  169625. else
  169626. {
  169627. png_composite(*dp, *sp, a, background_1->gray);
  169628. }
  169629. #else
  169630. *dp = (png_byte)background->gray;
  169631. #endif
  169632. }
  169633. }
  169634. }
  169635. else /* if (png_ptr->bit_depth == 16) */
  169636. {
  169637. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169638. if (gamma_16 != NULL && gamma_16_from_1 != NULL &&
  169639. gamma_16_to_1 != NULL)
  169640. {
  169641. sp = row;
  169642. dp = row;
  169643. for (i = 0; i < row_width; i++, sp += 4, dp += 2)
  169644. {
  169645. png_uint_16 a = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169646. if (a == (png_uint_16)0xffff)
  169647. {
  169648. png_uint_16 v;
  169649. v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169650. *dp = (png_byte)((v >> 8) & 0xff);
  169651. *(dp + 1) = (png_byte)(v & 0xff);
  169652. }
  169653. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169654. else if (a == 0)
  169655. #else
  169656. else
  169657. #endif
  169658. {
  169659. *dp = (png_byte)((background->gray >> 8) & 0xff);
  169660. *(dp + 1) = (png_byte)(background->gray & 0xff);
  169661. }
  169662. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169663. else
  169664. {
  169665. png_uint_16 g, v, w;
  169666. g = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp];
  169667. png_composite_16(v, g, a, background_1->gray);
  169668. w = gamma_16_from_1[(v&0xff) >> gamma_shift][v >> 8];
  169669. *dp = (png_byte)((w >> 8) & 0xff);
  169670. *(dp + 1) = (png_byte)(w & 0xff);
  169671. }
  169672. #endif
  169673. }
  169674. }
  169675. else
  169676. #endif
  169677. {
  169678. sp = row;
  169679. dp = row;
  169680. for (i = 0; i < row_width; i++, sp += 4, dp += 2)
  169681. {
  169682. png_uint_16 a = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169683. if (a == (png_uint_16)0xffff)
  169684. {
  169685. png_memcpy(dp, sp, 2);
  169686. }
  169687. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169688. else if (a == 0)
  169689. #else
  169690. else
  169691. #endif
  169692. {
  169693. *dp = (png_byte)((background->gray >> 8) & 0xff);
  169694. *(dp + 1) = (png_byte)(background->gray & 0xff);
  169695. }
  169696. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169697. else
  169698. {
  169699. png_uint_16 g, v;
  169700. g = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169701. png_composite_16(v, g, a, background_1->gray);
  169702. *dp = (png_byte)((v >> 8) & 0xff);
  169703. *(dp + 1) = (png_byte)(v & 0xff);
  169704. }
  169705. #endif
  169706. }
  169707. }
  169708. }
  169709. break;
  169710. }
  169711. case PNG_COLOR_TYPE_RGB_ALPHA:
  169712. {
  169713. if (row_info->bit_depth == 8)
  169714. {
  169715. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169716. if (gamma_to_1 != NULL && gamma_from_1 != NULL &&
  169717. gamma_table != NULL)
  169718. {
  169719. sp = row;
  169720. dp = row;
  169721. for (i = 0; i < row_width; i++, sp += 4, dp += 3)
  169722. {
  169723. png_byte a = *(sp + 3);
  169724. if (a == 0xff)
  169725. {
  169726. *dp = gamma_table[*sp];
  169727. *(dp + 1) = gamma_table[*(sp + 1)];
  169728. *(dp + 2) = gamma_table[*(sp + 2)];
  169729. }
  169730. else if (a == 0)
  169731. {
  169732. *dp = (png_byte)background->red;
  169733. *(dp + 1) = (png_byte)background->green;
  169734. *(dp + 2) = (png_byte)background->blue;
  169735. }
  169736. else
  169737. {
  169738. png_byte v, w;
  169739. v = gamma_to_1[*sp];
  169740. png_composite(w, v, a, background_1->red);
  169741. *dp = gamma_from_1[w];
  169742. v = gamma_to_1[*(sp + 1)];
  169743. png_composite(w, v, a, background_1->green);
  169744. *(dp + 1) = gamma_from_1[w];
  169745. v = gamma_to_1[*(sp + 2)];
  169746. png_composite(w, v, a, background_1->blue);
  169747. *(dp + 2) = gamma_from_1[w];
  169748. }
  169749. }
  169750. }
  169751. else
  169752. #endif
  169753. {
  169754. sp = row;
  169755. dp = row;
  169756. for (i = 0; i < row_width; i++, sp += 4, dp += 3)
  169757. {
  169758. png_byte a = *(sp + 3);
  169759. if (a == 0xff)
  169760. {
  169761. *dp = *sp;
  169762. *(dp + 1) = *(sp + 1);
  169763. *(dp + 2) = *(sp + 2);
  169764. }
  169765. else if (a == 0)
  169766. {
  169767. *dp = (png_byte)background->red;
  169768. *(dp + 1) = (png_byte)background->green;
  169769. *(dp + 2) = (png_byte)background->blue;
  169770. }
  169771. else
  169772. {
  169773. png_composite(*dp, *sp, a, background->red);
  169774. png_composite(*(dp + 1), *(sp + 1), a,
  169775. background->green);
  169776. png_composite(*(dp + 2), *(sp + 2), a,
  169777. background->blue);
  169778. }
  169779. }
  169780. }
  169781. }
  169782. else /* if (row_info->bit_depth == 16) */
  169783. {
  169784. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169785. if (gamma_16 != NULL && gamma_16_from_1 != NULL &&
  169786. gamma_16_to_1 != NULL)
  169787. {
  169788. sp = row;
  169789. dp = row;
  169790. for (i = 0; i < row_width; i++, sp += 8, dp += 6)
  169791. {
  169792. png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
  169793. << 8) + (png_uint_16)(*(sp + 7)));
  169794. if (a == (png_uint_16)0xffff)
  169795. {
  169796. png_uint_16 v;
  169797. v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169798. *dp = (png_byte)((v >> 8) & 0xff);
  169799. *(dp + 1) = (png_byte)(v & 0xff);
  169800. v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)];
  169801. *(dp + 2) = (png_byte)((v >> 8) & 0xff);
  169802. *(dp + 3) = (png_byte)(v & 0xff);
  169803. v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)];
  169804. *(dp + 4) = (png_byte)((v >> 8) & 0xff);
  169805. *(dp + 5) = (png_byte)(v & 0xff);
  169806. }
  169807. else if (a == 0)
  169808. {
  169809. *dp = (png_byte)((background->red >> 8) & 0xff);
  169810. *(dp + 1) = (png_byte)(background->red & 0xff);
  169811. *(dp + 2) = (png_byte)((background->green >> 8) & 0xff);
  169812. *(dp + 3) = (png_byte)(background->green & 0xff);
  169813. *(dp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  169814. *(dp + 5) = (png_byte)(background->blue & 0xff);
  169815. }
  169816. else
  169817. {
  169818. png_uint_16 v, w, x;
  169819. v = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp];
  169820. png_composite_16(w, v, a, background_1->red);
  169821. x = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8];
  169822. *dp = (png_byte)((x >> 8) & 0xff);
  169823. *(dp + 1) = (png_byte)(x & 0xff);
  169824. v = gamma_16_to_1[*(sp + 3) >> gamma_shift][*(sp + 2)];
  169825. png_composite_16(w, v, a, background_1->green);
  169826. x = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8];
  169827. *(dp + 2) = (png_byte)((x >> 8) & 0xff);
  169828. *(dp + 3) = (png_byte)(x & 0xff);
  169829. v = gamma_16_to_1[*(sp + 5) >> gamma_shift][*(sp + 4)];
  169830. png_composite_16(w, v, a, background_1->blue);
  169831. x = gamma_16_from_1[(w & 0xff) >> gamma_shift][w >> 8];
  169832. *(dp + 4) = (png_byte)((x >> 8) & 0xff);
  169833. *(dp + 5) = (png_byte)(x & 0xff);
  169834. }
  169835. }
  169836. }
  169837. else
  169838. #endif
  169839. {
  169840. sp = row;
  169841. dp = row;
  169842. for (i = 0; i < row_width; i++, sp += 8, dp += 6)
  169843. {
  169844. png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
  169845. << 8) + (png_uint_16)(*(sp + 7)));
  169846. if (a == (png_uint_16)0xffff)
  169847. {
  169848. png_memcpy(dp, sp, 6);
  169849. }
  169850. else if (a == 0)
  169851. {
  169852. *dp = (png_byte)((background->red >> 8) & 0xff);
  169853. *(dp + 1) = (png_byte)(background->red & 0xff);
  169854. *(dp + 2) = (png_byte)((background->green >> 8) & 0xff);
  169855. *(dp + 3) = (png_byte)(background->green & 0xff);
  169856. *(dp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  169857. *(dp + 5) = (png_byte)(background->blue & 0xff);
  169858. }
  169859. else
  169860. {
  169861. png_uint_16 v;
  169862. png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169863. png_uint_16 g = (png_uint_16)(((*(sp + 2)) << 8)
  169864. + *(sp + 3));
  169865. png_uint_16 b = (png_uint_16)(((*(sp + 4)) << 8)
  169866. + *(sp + 5));
  169867. png_composite_16(v, r, a, background->red);
  169868. *dp = (png_byte)((v >> 8) & 0xff);
  169869. *(dp + 1) = (png_byte)(v & 0xff);
  169870. png_composite_16(v, g, a, background->green);
  169871. *(dp + 2) = (png_byte)((v >> 8) & 0xff);
  169872. *(dp + 3) = (png_byte)(v & 0xff);
  169873. png_composite_16(v, b, a, background->blue);
  169874. *(dp + 4) = (png_byte)((v >> 8) & 0xff);
  169875. *(dp + 5) = (png_byte)(v & 0xff);
  169876. }
  169877. }
  169878. }
  169879. }
  169880. break;
  169881. }
  169882. }
  169883. if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
  169884. {
  169885. row_info->color_type &= ~PNG_COLOR_MASK_ALPHA;
  169886. row_info->channels--;
  169887. row_info->pixel_depth = (png_byte)(row_info->channels *
  169888. row_info->bit_depth);
  169889. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  169890. }
  169891. }
  169892. }
  169893. #endif
  169894. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169895. void /* PRIVATE */
  169896. png_do_gamma(png_row_infop row_info, png_bytep row,
  169897. png_bytep gamma_table, png_uint_16pp gamma_16_table,
  169898. int gamma_shift)
  169899. {
  169900. png_bytep sp;
  169901. png_uint_32 i;
  169902. png_uint_32 row_width=row_info->width;
  169903. png_debug(1, "in png_do_gamma\n");
  169904. if (
  169905. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169906. row != NULL && row_info != NULL &&
  169907. #endif
  169908. ((row_info->bit_depth <= 8 && gamma_table != NULL) ||
  169909. (row_info->bit_depth == 16 && gamma_16_table != NULL)))
  169910. {
  169911. switch (row_info->color_type)
  169912. {
  169913. case PNG_COLOR_TYPE_RGB:
  169914. {
  169915. if (row_info->bit_depth == 8)
  169916. {
  169917. sp = row;
  169918. for (i = 0; i < row_width; i++)
  169919. {
  169920. *sp = gamma_table[*sp];
  169921. sp++;
  169922. *sp = gamma_table[*sp];
  169923. sp++;
  169924. *sp = gamma_table[*sp];
  169925. sp++;
  169926. }
  169927. }
  169928. else /* if (row_info->bit_depth == 16) */
  169929. {
  169930. sp = row;
  169931. for (i = 0; i < row_width; i++)
  169932. {
  169933. png_uint_16 v;
  169934. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169935. *sp = (png_byte)((v >> 8) & 0xff);
  169936. *(sp + 1) = (png_byte)(v & 0xff);
  169937. sp += 2;
  169938. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169939. *sp = (png_byte)((v >> 8) & 0xff);
  169940. *(sp + 1) = (png_byte)(v & 0xff);
  169941. sp += 2;
  169942. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169943. *sp = (png_byte)((v >> 8) & 0xff);
  169944. *(sp + 1) = (png_byte)(v & 0xff);
  169945. sp += 2;
  169946. }
  169947. }
  169948. break;
  169949. }
  169950. case PNG_COLOR_TYPE_RGB_ALPHA:
  169951. {
  169952. if (row_info->bit_depth == 8)
  169953. {
  169954. sp = row;
  169955. for (i = 0; i < row_width; i++)
  169956. {
  169957. *sp = gamma_table[*sp];
  169958. sp++;
  169959. *sp = gamma_table[*sp];
  169960. sp++;
  169961. *sp = gamma_table[*sp];
  169962. sp++;
  169963. sp++;
  169964. }
  169965. }
  169966. else /* if (row_info->bit_depth == 16) */
  169967. {
  169968. sp = row;
  169969. for (i = 0; i < row_width; i++)
  169970. {
  169971. png_uint_16 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. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169980. *sp = (png_byte)((v >> 8) & 0xff);
  169981. *(sp + 1) = (png_byte)(v & 0xff);
  169982. sp += 4;
  169983. }
  169984. }
  169985. break;
  169986. }
  169987. case PNG_COLOR_TYPE_GRAY_ALPHA:
  169988. {
  169989. if (row_info->bit_depth == 8)
  169990. {
  169991. sp = row;
  169992. for (i = 0; i < row_width; i++)
  169993. {
  169994. *sp = gamma_table[*sp];
  169995. sp += 2;
  169996. }
  169997. }
  169998. else /* if (row_info->bit_depth == 16) */
  169999. {
  170000. sp = row;
  170001. for (i = 0; i < row_width; i++)
  170002. {
  170003. png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170004. *sp = (png_byte)((v >> 8) & 0xff);
  170005. *(sp + 1) = (png_byte)(v & 0xff);
  170006. sp += 4;
  170007. }
  170008. }
  170009. break;
  170010. }
  170011. case PNG_COLOR_TYPE_GRAY:
  170012. {
  170013. if (row_info->bit_depth == 2)
  170014. {
  170015. sp = row;
  170016. for (i = 0; i < row_width; i += 4)
  170017. {
  170018. int a = *sp & 0xc0;
  170019. int b = *sp & 0x30;
  170020. int c = *sp & 0x0c;
  170021. int d = *sp & 0x03;
  170022. *sp = (png_byte)(
  170023. ((((int)gamma_table[a|(a>>2)|(a>>4)|(a>>6)]) ) & 0xc0)|
  170024. ((((int)gamma_table[(b<<2)|b|(b>>2)|(b>>4)])>>2) & 0x30)|
  170025. ((((int)gamma_table[(c<<4)|(c<<2)|c|(c>>2)])>>4) & 0x0c)|
  170026. ((((int)gamma_table[(d<<6)|(d<<4)|(d<<2)|d])>>6) ));
  170027. sp++;
  170028. }
  170029. }
  170030. if (row_info->bit_depth == 4)
  170031. {
  170032. sp = row;
  170033. for (i = 0; i < row_width; i += 2)
  170034. {
  170035. int msb = *sp & 0xf0;
  170036. int lsb = *sp & 0x0f;
  170037. *sp = (png_byte)((((int)gamma_table[msb | (msb >> 4)]) & 0xf0)
  170038. | (((int)gamma_table[(lsb << 4) | lsb]) >> 4));
  170039. sp++;
  170040. }
  170041. }
  170042. else if (row_info->bit_depth == 8)
  170043. {
  170044. sp = row;
  170045. for (i = 0; i < row_width; i++)
  170046. {
  170047. *sp = gamma_table[*sp];
  170048. sp++;
  170049. }
  170050. }
  170051. else if (row_info->bit_depth == 16)
  170052. {
  170053. sp = row;
  170054. for (i = 0; i < row_width; i++)
  170055. {
  170056. png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170057. *sp = (png_byte)((v >> 8) & 0xff);
  170058. *(sp + 1) = (png_byte)(v & 0xff);
  170059. sp += 2;
  170060. }
  170061. }
  170062. break;
  170063. }
  170064. }
  170065. }
  170066. }
  170067. #endif
  170068. #if defined(PNG_READ_EXPAND_SUPPORTED)
  170069. void /* PRIVATE */
  170070. png_do_expand_palette(png_row_infop row_info, png_bytep row,
  170071. png_colorp palette, png_bytep trans, int num_trans)
  170072. {
  170073. int shift, value;
  170074. png_bytep sp, dp;
  170075. png_uint_32 i;
  170076. png_uint_32 row_width=row_info->width;
  170077. png_debug(1, "in png_do_expand_palette\n");
  170078. if (
  170079. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170080. row != NULL && row_info != NULL &&
  170081. #endif
  170082. row_info->color_type == PNG_COLOR_TYPE_PALETTE)
  170083. {
  170084. if (row_info->bit_depth < 8)
  170085. {
  170086. switch (row_info->bit_depth)
  170087. {
  170088. case 1:
  170089. {
  170090. sp = row + (png_size_t)((row_width - 1) >> 3);
  170091. dp = row + (png_size_t)row_width - 1;
  170092. shift = 7 - (int)((row_width + 7) & 0x07);
  170093. for (i = 0; i < row_width; i++)
  170094. {
  170095. if ((*sp >> shift) & 0x01)
  170096. *dp = 1;
  170097. else
  170098. *dp = 0;
  170099. if (shift == 7)
  170100. {
  170101. shift = 0;
  170102. sp--;
  170103. }
  170104. else
  170105. shift++;
  170106. dp--;
  170107. }
  170108. break;
  170109. }
  170110. case 2:
  170111. {
  170112. sp = row + (png_size_t)((row_width - 1) >> 2);
  170113. dp = row + (png_size_t)row_width - 1;
  170114. shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
  170115. for (i = 0; i < row_width; i++)
  170116. {
  170117. value = (*sp >> shift) & 0x03;
  170118. *dp = (png_byte)value;
  170119. if (shift == 6)
  170120. {
  170121. shift = 0;
  170122. sp--;
  170123. }
  170124. else
  170125. shift += 2;
  170126. dp--;
  170127. }
  170128. break;
  170129. }
  170130. case 4:
  170131. {
  170132. sp = row + (png_size_t)((row_width - 1) >> 1);
  170133. dp = row + (png_size_t)row_width - 1;
  170134. shift = (int)((row_width & 0x01) << 2);
  170135. for (i = 0; i < row_width; i++)
  170136. {
  170137. value = (*sp >> shift) & 0x0f;
  170138. *dp = (png_byte)value;
  170139. if (shift == 4)
  170140. {
  170141. shift = 0;
  170142. sp--;
  170143. }
  170144. else
  170145. shift += 4;
  170146. dp--;
  170147. }
  170148. break;
  170149. }
  170150. }
  170151. row_info->bit_depth = 8;
  170152. row_info->pixel_depth = 8;
  170153. row_info->rowbytes = row_width;
  170154. }
  170155. switch (row_info->bit_depth)
  170156. {
  170157. case 8:
  170158. {
  170159. if (trans != NULL)
  170160. {
  170161. sp = row + (png_size_t)row_width - 1;
  170162. dp = row + (png_size_t)(row_width << 2) - 1;
  170163. for (i = 0; i < row_width; i++)
  170164. {
  170165. if ((int)(*sp) >= num_trans)
  170166. *dp-- = 0xff;
  170167. else
  170168. *dp-- = trans[*sp];
  170169. *dp-- = palette[*sp].blue;
  170170. *dp-- = palette[*sp].green;
  170171. *dp-- = palette[*sp].red;
  170172. sp--;
  170173. }
  170174. row_info->bit_depth = 8;
  170175. row_info->pixel_depth = 32;
  170176. row_info->rowbytes = row_width * 4;
  170177. row_info->color_type = 6;
  170178. row_info->channels = 4;
  170179. }
  170180. else
  170181. {
  170182. sp = row + (png_size_t)row_width - 1;
  170183. dp = row + (png_size_t)(row_width * 3) - 1;
  170184. for (i = 0; i < row_width; i++)
  170185. {
  170186. *dp-- = palette[*sp].blue;
  170187. *dp-- = palette[*sp].green;
  170188. *dp-- = palette[*sp].red;
  170189. sp--;
  170190. }
  170191. row_info->bit_depth = 8;
  170192. row_info->pixel_depth = 24;
  170193. row_info->rowbytes = row_width * 3;
  170194. row_info->color_type = 2;
  170195. row_info->channels = 3;
  170196. }
  170197. break;
  170198. }
  170199. }
  170200. }
  170201. }
  170202. void /* PRIVATE */
  170203. png_do_expand(png_row_infop row_info, png_bytep row,
  170204. png_color_16p trans_value)
  170205. {
  170206. int shift, value;
  170207. png_bytep sp, dp;
  170208. png_uint_32 i;
  170209. png_uint_32 row_width=row_info->width;
  170210. png_debug(1, "in png_do_expand\n");
  170211. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170212. if (row != NULL && row_info != NULL)
  170213. #endif
  170214. {
  170215. if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
  170216. {
  170217. png_uint_16 gray = (png_uint_16)(trans_value ? trans_value->gray : 0);
  170218. if (row_info->bit_depth < 8)
  170219. {
  170220. switch (row_info->bit_depth)
  170221. {
  170222. case 1:
  170223. {
  170224. gray = (png_uint_16)((gray&0x01)*0xff);
  170225. sp = row + (png_size_t)((row_width - 1) >> 3);
  170226. dp = row + (png_size_t)row_width - 1;
  170227. shift = 7 - (int)((row_width + 7) & 0x07);
  170228. for (i = 0; i < row_width; i++)
  170229. {
  170230. if ((*sp >> shift) & 0x01)
  170231. *dp = 0xff;
  170232. else
  170233. *dp = 0;
  170234. if (shift == 7)
  170235. {
  170236. shift = 0;
  170237. sp--;
  170238. }
  170239. else
  170240. shift++;
  170241. dp--;
  170242. }
  170243. break;
  170244. }
  170245. case 2:
  170246. {
  170247. gray = (png_uint_16)((gray&0x03)*0x55);
  170248. sp = row + (png_size_t)((row_width - 1) >> 2);
  170249. dp = row + (png_size_t)row_width - 1;
  170250. shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
  170251. for (i = 0; i < row_width; i++)
  170252. {
  170253. value = (*sp >> shift) & 0x03;
  170254. *dp = (png_byte)(value | (value << 2) | (value << 4) |
  170255. (value << 6));
  170256. if (shift == 6)
  170257. {
  170258. shift = 0;
  170259. sp--;
  170260. }
  170261. else
  170262. shift += 2;
  170263. dp--;
  170264. }
  170265. break;
  170266. }
  170267. case 4:
  170268. {
  170269. gray = (png_uint_16)((gray&0x0f)*0x11);
  170270. sp = row + (png_size_t)((row_width - 1) >> 1);
  170271. dp = row + (png_size_t)row_width - 1;
  170272. shift = (int)((1 - ((row_width + 1) & 0x01)) << 2);
  170273. for (i = 0; i < row_width; i++)
  170274. {
  170275. value = (*sp >> shift) & 0x0f;
  170276. *dp = (png_byte)(value | (value << 4));
  170277. if (shift == 4)
  170278. {
  170279. shift = 0;
  170280. sp--;
  170281. }
  170282. else
  170283. shift = 4;
  170284. dp--;
  170285. }
  170286. break;
  170287. }
  170288. }
  170289. row_info->bit_depth = 8;
  170290. row_info->pixel_depth = 8;
  170291. row_info->rowbytes = row_width;
  170292. }
  170293. if (trans_value != NULL)
  170294. {
  170295. if (row_info->bit_depth == 8)
  170296. {
  170297. gray = gray & 0xff;
  170298. sp = row + (png_size_t)row_width - 1;
  170299. dp = row + (png_size_t)(row_width << 1) - 1;
  170300. for (i = 0; i < row_width; i++)
  170301. {
  170302. if (*sp == gray)
  170303. *dp-- = 0;
  170304. else
  170305. *dp-- = 0xff;
  170306. *dp-- = *sp--;
  170307. }
  170308. }
  170309. else if (row_info->bit_depth == 16)
  170310. {
  170311. png_byte gray_high = (gray >> 8) & 0xff;
  170312. png_byte gray_low = gray & 0xff;
  170313. sp = row + row_info->rowbytes - 1;
  170314. dp = row + (row_info->rowbytes << 1) - 1;
  170315. for (i = 0; i < row_width; i++)
  170316. {
  170317. if (*(sp-1) == gray_high && *(sp) == gray_low)
  170318. {
  170319. *dp-- = 0;
  170320. *dp-- = 0;
  170321. }
  170322. else
  170323. {
  170324. *dp-- = 0xff;
  170325. *dp-- = 0xff;
  170326. }
  170327. *dp-- = *sp--;
  170328. *dp-- = *sp--;
  170329. }
  170330. }
  170331. row_info->color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
  170332. row_info->channels = 2;
  170333. row_info->pixel_depth = (png_byte)(row_info->bit_depth << 1);
  170334. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
  170335. row_width);
  170336. }
  170337. }
  170338. else if (row_info->color_type == PNG_COLOR_TYPE_RGB && trans_value)
  170339. {
  170340. if (row_info->bit_depth == 8)
  170341. {
  170342. png_byte red = trans_value->red & 0xff;
  170343. png_byte green = trans_value->green & 0xff;
  170344. png_byte blue = trans_value->blue & 0xff;
  170345. sp = row + (png_size_t)row_info->rowbytes - 1;
  170346. dp = row + (png_size_t)(row_width << 2) - 1;
  170347. for (i = 0; i < row_width; i++)
  170348. {
  170349. if (*(sp - 2) == red && *(sp - 1) == green && *(sp) == blue)
  170350. *dp-- = 0;
  170351. else
  170352. *dp-- = 0xff;
  170353. *dp-- = *sp--;
  170354. *dp-- = *sp--;
  170355. *dp-- = *sp--;
  170356. }
  170357. }
  170358. else if (row_info->bit_depth == 16)
  170359. {
  170360. png_byte red_high = (trans_value->red >> 8) & 0xff;
  170361. png_byte green_high = (trans_value->green >> 8) & 0xff;
  170362. png_byte blue_high = (trans_value->blue >> 8) & 0xff;
  170363. png_byte red_low = trans_value->red & 0xff;
  170364. png_byte green_low = trans_value->green & 0xff;
  170365. png_byte blue_low = trans_value->blue & 0xff;
  170366. sp = row + row_info->rowbytes - 1;
  170367. dp = row + (png_size_t)(row_width << 3) - 1;
  170368. for (i = 0; i < row_width; i++)
  170369. {
  170370. if (*(sp - 5) == red_high &&
  170371. *(sp - 4) == red_low &&
  170372. *(sp - 3) == green_high &&
  170373. *(sp - 2) == green_low &&
  170374. *(sp - 1) == blue_high &&
  170375. *(sp ) == blue_low)
  170376. {
  170377. *dp-- = 0;
  170378. *dp-- = 0;
  170379. }
  170380. else
  170381. {
  170382. *dp-- = 0xff;
  170383. *dp-- = 0xff;
  170384. }
  170385. *dp-- = *sp--;
  170386. *dp-- = *sp--;
  170387. *dp-- = *sp--;
  170388. *dp-- = *sp--;
  170389. *dp-- = *sp--;
  170390. *dp-- = *sp--;
  170391. }
  170392. }
  170393. row_info->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
  170394. row_info->channels = 4;
  170395. row_info->pixel_depth = (png_byte)(row_info->bit_depth << 2);
  170396. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170397. }
  170398. }
  170399. }
  170400. #endif
  170401. #if defined(PNG_READ_DITHER_SUPPORTED)
  170402. void /* PRIVATE */
  170403. png_do_dither(png_row_infop row_info, png_bytep row,
  170404. png_bytep palette_lookup, png_bytep dither_lookup)
  170405. {
  170406. png_bytep sp, dp;
  170407. png_uint_32 i;
  170408. png_uint_32 row_width=row_info->width;
  170409. png_debug(1, "in png_do_dither\n");
  170410. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170411. if (row != NULL && row_info != NULL)
  170412. #endif
  170413. {
  170414. if (row_info->color_type == PNG_COLOR_TYPE_RGB &&
  170415. palette_lookup && row_info->bit_depth == 8)
  170416. {
  170417. int r, g, b, p;
  170418. sp = row;
  170419. dp = row;
  170420. for (i = 0; i < row_width; i++)
  170421. {
  170422. r = *sp++;
  170423. g = *sp++;
  170424. b = *sp++;
  170425. p = (((r >> (8 - PNG_DITHER_RED_BITS)) &
  170426. ((1 << PNG_DITHER_RED_BITS) - 1)) <<
  170427. (PNG_DITHER_GREEN_BITS + PNG_DITHER_BLUE_BITS)) |
  170428. (((g >> (8 - PNG_DITHER_GREEN_BITS)) &
  170429. ((1 << PNG_DITHER_GREEN_BITS) - 1)) <<
  170430. (PNG_DITHER_BLUE_BITS)) |
  170431. ((b >> (8 - PNG_DITHER_BLUE_BITS)) &
  170432. ((1 << PNG_DITHER_BLUE_BITS) - 1));
  170433. *dp++ = palette_lookup[p];
  170434. }
  170435. row_info->color_type = PNG_COLOR_TYPE_PALETTE;
  170436. row_info->channels = 1;
  170437. row_info->pixel_depth = row_info->bit_depth;
  170438. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170439. }
  170440. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA &&
  170441. palette_lookup != NULL && row_info->bit_depth == 8)
  170442. {
  170443. int r, g, b, p;
  170444. sp = row;
  170445. dp = row;
  170446. for (i = 0; i < row_width; i++)
  170447. {
  170448. r = *sp++;
  170449. g = *sp++;
  170450. b = *sp++;
  170451. sp++;
  170452. p = (((r >> (8 - PNG_DITHER_RED_BITS)) &
  170453. ((1 << PNG_DITHER_RED_BITS) - 1)) <<
  170454. (PNG_DITHER_GREEN_BITS + PNG_DITHER_BLUE_BITS)) |
  170455. (((g >> (8 - PNG_DITHER_GREEN_BITS)) &
  170456. ((1 << PNG_DITHER_GREEN_BITS) - 1)) <<
  170457. (PNG_DITHER_BLUE_BITS)) |
  170458. ((b >> (8 - PNG_DITHER_BLUE_BITS)) &
  170459. ((1 << PNG_DITHER_BLUE_BITS) - 1));
  170460. *dp++ = palette_lookup[p];
  170461. }
  170462. row_info->color_type = PNG_COLOR_TYPE_PALETTE;
  170463. row_info->channels = 1;
  170464. row_info->pixel_depth = row_info->bit_depth;
  170465. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170466. }
  170467. else if (row_info->color_type == PNG_COLOR_TYPE_PALETTE &&
  170468. dither_lookup && row_info->bit_depth == 8)
  170469. {
  170470. sp = row;
  170471. for (i = 0; i < row_width; i++, sp++)
  170472. {
  170473. *sp = dither_lookup[*sp];
  170474. }
  170475. }
  170476. }
  170477. }
  170478. #endif
  170479. #ifdef PNG_FLOATING_POINT_SUPPORTED
  170480. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170481. static PNG_CONST int png_gamma_shift[] =
  170482. {0x10, 0x21, 0x42, 0x84, 0x110, 0x248, 0x550, 0xff0, 0x00};
  170483. void /* PRIVATE */
  170484. png_build_gamma_table(png_structp png_ptr)
  170485. {
  170486. png_debug(1, "in png_build_gamma_table\n");
  170487. if (png_ptr->bit_depth <= 8)
  170488. {
  170489. int i;
  170490. double g;
  170491. if (png_ptr->screen_gamma > .000001)
  170492. g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  170493. else
  170494. g = 1.0;
  170495. png_ptr->gamma_table = (png_bytep)png_malloc(png_ptr,
  170496. (png_uint_32)256);
  170497. for (i = 0; i < 256; i++)
  170498. {
  170499. png_ptr->gamma_table[i] = (png_byte)(pow((double)i / 255.0,
  170500. g) * 255.0 + .5);
  170501. }
  170502. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
  170503. defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  170504. if (png_ptr->transformations & ((PNG_BACKGROUND) | PNG_RGB_TO_GRAY))
  170505. {
  170506. g = 1.0 / (png_ptr->gamma);
  170507. png_ptr->gamma_to_1 = (png_bytep)png_malloc(png_ptr,
  170508. (png_uint_32)256);
  170509. for (i = 0; i < 256; i++)
  170510. {
  170511. png_ptr->gamma_to_1[i] = (png_byte)(pow((double)i / 255.0,
  170512. g) * 255.0 + .5);
  170513. }
  170514. png_ptr->gamma_from_1 = (png_bytep)png_malloc(png_ptr,
  170515. (png_uint_32)256);
  170516. if(png_ptr->screen_gamma > 0.000001)
  170517. g = 1.0 / png_ptr->screen_gamma;
  170518. else
  170519. g = png_ptr->gamma; /* probably doing rgb_to_gray */
  170520. for (i = 0; i < 256; i++)
  170521. {
  170522. png_ptr->gamma_from_1[i] = (png_byte)(pow((double)i / 255.0,
  170523. g) * 255.0 + .5);
  170524. }
  170525. }
  170526. #endif /* PNG_READ_BACKGROUND_SUPPORTED || PNG_RGB_TO_GRAY_SUPPORTED */
  170527. }
  170528. else
  170529. {
  170530. double g;
  170531. int i, j, shift, num;
  170532. int sig_bit;
  170533. png_uint_32 ig;
  170534. if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
  170535. {
  170536. sig_bit = (int)png_ptr->sig_bit.red;
  170537. if ((int)png_ptr->sig_bit.green > sig_bit)
  170538. sig_bit = png_ptr->sig_bit.green;
  170539. if ((int)png_ptr->sig_bit.blue > sig_bit)
  170540. sig_bit = png_ptr->sig_bit.blue;
  170541. }
  170542. else
  170543. {
  170544. sig_bit = (int)png_ptr->sig_bit.gray;
  170545. }
  170546. if (sig_bit > 0)
  170547. shift = 16 - sig_bit;
  170548. else
  170549. shift = 0;
  170550. if (png_ptr->transformations & PNG_16_TO_8)
  170551. {
  170552. if (shift < (16 - PNG_MAX_GAMMA_8))
  170553. shift = (16 - PNG_MAX_GAMMA_8);
  170554. }
  170555. if (shift > 8)
  170556. shift = 8;
  170557. if (shift < 0)
  170558. shift = 0;
  170559. png_ptr->gamma_shift = (png_byte)shift;
  170560. num = (1 << (8 - shift));
  170561. if (png_ptr->screen_gamma > .000001)
  170562. g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  170563. else
  170564. g = 1.0;
  170565. png_ptr->gamma_16_table = (png_uint_16pp)png_malloc(png_ptr,
  170566. (png_uint_32)(num * png_sizeof (png_uint_16p)));
  170567. if (png_ptr->transformations & (PNG_16_TO_8 | PNG_BACKGROUND))
  170568. {
  170569. double fin, fout;
  170570. png_uint_32 last, max;
  170571. for (i = 0; i < num; i++)
  170572. {
  170573. png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr,
  170574. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  170575. }
  170576. g = 1.0 / g;
  170577. last = 0;
  170578. for (i = 0; i < 256; i++)
  170579. {
  170580. fout = ((double)i + 0.5) / 256.0;
  170581. fin = pow(fout, g);
  170582. max = (png_uint_32)(fin * (double)((png_uint_32)num << 8));
  170583. while (last <= max)
  170584. {
  170585. png_ptr->gamma_16_table[(int)(last & (0xff >> shift))]
  170586. [(int)(last >> (8 - shift))] = (png_uint_16)(
  170587. (png_uint_16)i | ((png_uint_16)i << 8));
  170588. last++;
  170589. }
  170590. }
  170591. while (last < ((png_uint_32)num << 8))
  170592. {
  170593. png_ptr->gamma_16_table[(int)(last & (0xff >> shift))]
  170594. [(int)(last >> (8 - shift))] = (png_uint_16)65535L;
  170595. last++;
  170596. }
  170597. }
  170598. else
  170599. {
  170600. for (i = 0; i < num; i++)
  170601. {
  170602. png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr,
  170603. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  170604. ig = (((png_uint_32)i * (png_uint_32)png_gamma_shift[shift]) >> 4);
  170605. for (j = 0; j < 256; j++)
  170606. {
  170607. png_ptr->gamma_16_table[i][j] =
  170608. (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
  170609. 65535.0, g) * 65535.0 + .5);
  170610. }
  170611. }
  170612. }
  170613. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
  170614. defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  170615. if (png_ptr->transformations & (PNG_BACKGROUND | PNG_RGB_TO_GRAY))
  170616. {
  170617. g = 1.0 / (png_ptr->gamma);
  170618. png_ptr->gamma_16_to_1 = (png_uint_16pp)png_malloc(png_ptr,
  170619. (png_uint_32)(num * png_sizeof (png_uint_16p )));
  170620. for (i = 0; i < num; i++)
  170621. {
  170622. png_ptr->gamma_16_to_1[i] = (png_uint_16p)png_malloc(png_ptr,
  170623. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  170624. ig = (((png_uint_32)i *
  170625. (png_uint_32)png_gamma_shift[shift]) >> 4);
  170626. for (j = 0; j < 256; j++)
  170627. {
  170628. png_ptr->gamma_16_to_1[i][j] =
  170629. (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
  170630. 65535.0, g) * 65535.0 + .5);
  170631. }
  170632. }
  170633. if(png_ptr->screen_gamma > 0.000001)
  170634. g = 1.0 / png_ptr->screen_gamma;
  170635. else
  170636. g = png_ptr->gamma; /* probably doing rgb_to_gray */
  170637. png_ptr->gamma_16_from_1 = (png_uint_16pp)png_malloc(png_ptr,
  170638. (png_uint_32)(num * png_sizeof (png_uint_16p)));
  170639. for (i = 0; i < num; i++)
  170640. {
  170641. png_ptr->gamma_16_from_1[i] = (png_uint_16p)png_malloc(png_ptr,
  170642. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  170643. ig = (((png_uint_32)i *
  170644. (png_uint_32)png_gamma_shift[shift]) >> 4);
  170645. for (j = 0; j < 256; j++)
  170646. {
  170647. png_ptr->gamma_16_from_1[i][j] =
  170648. (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
  170649. 65535.0, g) * 65535.0 + .5);
  170650. }
  170651. }
  170652. }
  170653. #endif /* PNG_READ_BACKGROUND_SUPPORTED || PNG_RGB_TO_GRAY_SUPPORTED */
  170654. }
  170655. }
  170656. #endif
  170657. #endif
  170658. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  170659. void /* PRIVATE */
  170660. png_do_read_intrapixel(png_row_infop row_info, png_bytep row)
  170661. {
  170662. png_debug(1, "in png_do_read_intrapixel\n");
  170663. if (
  170664. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170665. row != NULL && row_info != NULL &&
  170666. #endif
  170667. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  170668. {
  170669. int bytes_per_pixel;
  170670. png_uint_32 row_width = row_info->width;
  170671. if (row_info->bit_depth == 8)
  170672. {
  170673. png_bytep rp;
  170674. png_uint_32 i;
  170675. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  170676. bytes_per_pixel = 3;
  170677. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  170678. bytes_per_pixel = 4;
  170679. else
  170680. return;
  170681. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  170682. {
  170683. *(rp) = (png_byte)((256 + *rp + *(rp+1))&0xff);
  170684. *(rp+2) = (png_byte)((256 + *(rp+2) + *(rp+1))&0xff);
  170685. }
  170686. }
  170687. else if (row_info->bit_depth == 16)
  170688. {
  170689. png_bytep rp;
  170690. png_uint_32 i;
  170691. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  170692. bytes_per_pixel = 6;
  170693. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  170694. bytes_per_pixel = 8;
  170695. else
  170696. return;
  170697. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  170698. {
  170699. png_uint_32 s0 = (*(rp ) << 8) | *(rp+1);
  170700. png_uint_32 s1 = (*(rp+2) << 8) | *(rp+3);
  170701. png_uint_32 s2 = (*(rp+4) << 8) | *(rp+5);
  170702. png_uint_32 red = (png_uint_32)((s0+s1+65536L) & 0xffffL);
  170703. png_uint_32 blue = (png_uint_32)((s2+s1+65536L) & 0xffffL);
  170704. *(rp ) = (png_byte)((red >> 8) & 0xff);
  170705. *(rp+1) = (png_byte)(red & 0xff);
  170706. *(rp+4) = (png_byte)((blue >> 8) & 0xff);
  170707. *(rp+5) = (png_byte)(blue & 0xff);
  170708. }
  170709. }
  170710. }
  170711. }
  170712. #endif /* PNG_MNG_FEATURES_SUPPORTED */
  170713. #endif /* PNG_READ_SUPPORTED */
  170714. /*** End of inlined file: pngrtran.c ***/
  170715. /*** Start of inlined file: pngrutil.c ***/
  170716. #define PNG_INTERNAL
  170717. #if defined(PNG_READ_SUPPORTED)
  170718. #if defined(_WIN32_WCE) && (_WIN32_WCE<0x500)
  170719. # define WIN32_WCE_OLD
  170720. #endif
  170721. #ifdef PNG_FLOATING_POINT_SUPPORTED
  170722. # if defined(WIN32_WCE_OLD)
  170723. __inline double png_strtod(png_structp png_ptr, PNG_CONST char *nptr, char **endptr)
  170724. {
  170725. double result = 0;
  170726. int len;
  170727. wchar_t *str, *end;
  170728. len = MultiByteToWideChar(CP_ACP, 0, nptr, -1, NULL, 0);
  170729. str = (wchar_t *)png_malloc(png_ptr, len * sizeof(wchar_t));
  170730. if ( NULL != str )
  170731. {
  170732. MultiByteToWideChar(CP_ACP, 0, nptr, -1, str, len);
  170733. result = wcstod(str, &end);
  170734. len = WideCharToMultiByte(CP_ACP, 0, end, -1, NULL, 0, NULL, NULL);
  170735. *endptr = (char *)nptr + (png_strlen(nptr) - len + 1);
  170736. png_free(png_ptr, str);
  170737. }
  170738. return result;
  170739. }
  170740. # else
  170741. # define png_strtod(p,a,b) strtod(a,b)
  170742. # endif
  170743. #endif
  170744. png_uint_32 PNGAPI
  170745. png_get_uint_31(png_structp png_ptr, png_bytep buf)
  170746. {
  170747. png_uint_32 i = png_get_uint_32(buf);
  170748. if (i > PNG_UINT_31_MAX)
  170749. png_error(png_ptr, "PNG unsigned integer out of range.");
  170750. return (i);
  170751. }
  170752. #ifndef PNG_READ_BIG_ENDIAN_SUPPORTED
  170753. png_uint_32 PNGAPI
  170754. png_get_uint_32(png_bytep buf)
  170755. {
  170756. png_uint_32 i = ((png_uint_32)(*buf) << 24) +
  170757. ((png_uint_32)(*(buf + 1)) << 16) +
  170758. ((png_uint_32)(*(buf + 2)) << 8) +
  170759. (png_uint_32)(*(buf + 3));
  170760. return (i);
  170761. }
  170762. png_int_32 PNGAPI
  170763. png_get_int_32(png_bytep buf)
  170764. {
  170765. png_int_32 i = ((png_int_32)(*buf) << 24) +
  170766. ((png_int_32)(*(buf + 1)) << 16) +
  170767. ((png_int_32)(*(buf + 2)) << 8) +
  170768. (png_int_32)(*(buf + 3));
  170769. return (i);
  170770. }
  170771. png_uint_16 PNGAPI
  170772. png_get_uint_16(png_bytep buf)
  170773. {
  170774. png_uint_16 i = (png_uint_16)(((png_uint_16)(*buf) << 8) +
  170775. (png_uint_16)(*(buf + 1)));
  170776. return (i);
  170777. }
  170778. #endif /* PNG_READ_BIG_ENDIAN_SUPPORTED */
  170779. void /* PRIVATE */
  170780. png_crc_read(png_structp png_ptr, png_bytep buf, png_size_t length)
  170781. {
  170782. if(png_ptr == NULL) return;
  170783. png_read_data(png_ptr, buf, length);
  170784. png_calculate_crc(png_ptr, buf, length);
  170785. }
  170786. int /* PRIVATE */
  170787. png_crc_finish(png_structp png_ptr, png_uint_32 skip)
  170788. {
  170789. png_size_t i;
  170790. png_size_t istop = png_ptr->zbuf_size;
  170791. for (i = (png_size_t)skip; i > istop; i -= istop)
  170792. {
  170793. png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
  170794. }
  170795. if (i)
  170796. {
  170797. png_crc_read(png_ptr, png_ptr->zbuf, i);
  170798. }
  170799. if (png_crc_error(png_ptr))
  170800. {
  170801. if (((png_ptr->chunk_name[0] & 0x20) && /* Ancillary */
  170802. !(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)) ||
  170803. (!(png_ptr->chunk_name[0] & 0x20) && /* Critical */
  170804. (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_USE)))
  170805. {
  170806. png_chunk_warning(png_ptr, "CRC error");
  170807. }
  170808. else
  170809. {
  170810. png_chunk_error(png_ptr, "CRC error");
  170811. }
  170812. return (1);
  170813. }
  170814. return (0);
  170815. }
  170816. int /* PRIVATE */
  170817. png_crc_error(png_structp png_ptr)
  170818. {
  170819. png_byte crc_bytes[4];
  170820. png_uint_32 crc;
  170821. int need_crc = 1;
  170822. if (png_ptr->chunk_name[0] & 0x20) /* ancillary */
  170823. {
  170824. if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
  170825. (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
  170826. need_crc = 0;
  170827. }
  170828. else /* critical */
  170829. {
  170830. if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE)
  170831. need_crc = 0;
  170832. }
  170833. png_read_data(png_ptr, crc_bytes, 4);
  170834. if (need_crc)
  170835. {
  170836. crc = png_get_uint_32(crc_bytes);
  170837. return ((int)(crc != png_ptr->crc));
  170838. }
  170839. else
  170840. return (0);
  170841. }
  170842. #if defined(PNG_READ_zTXt_SUPPORTED) || defined(PNG_READ_iTXt_SUPPORTED) || \
  170843. defined(PNG_READ_iCCP_SUPPORTED)
  170844. png_charp /* PRIVATE */
  170845. png_decompress_chunk(png_structp png_ptr, int comp_type,
  170846. png_charp chunkdata, png_size_t chunklength,
  170847. png_size_t prefix_size, png_size_t *newlength)
  170848. {
  170849. static PNG_CONST char msg[] = "Error decoding compressed text";
  170850. png_charp text;
  170851. png_size_t text_size;
  170852. if (comp_type == PNG_COMPRESSION_TYPE_BASE)
  170853. {
  170854. int ret = Z_OK;
  170855. png_ptr->zstream.next_in = (png_bytep)(chunkdata + prefix_size);
  170856. png_ptr->zstream.avail_in = (uInt)(chunklength - prefix_size);
  170857. png_ptr->zstream.next_out = png_ptr->zbuf;
  170858. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  170859. text_size = 0;
  170860. text = NULL;
  170861. while (png_ptr->zstream.avail_in)
  170862. {
  170863. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  170864. if (ret != Z_OK && ret != Z_STREAM_END)
  170865. {
  170866. if (png_ptr->zstream.msg != NULL)
  170867. png_warning(png_ptr, png_ptr->zstream.msg);
  170868. else
  170869. png_warning(png_ptr, msg);
  170870. inflateReset(&png_ptr->zstream);
  170871. png_ptr->zstream.avail_in = 0;
  170872. if (text == NULL)
  170873. {
  170874. text_size = prefix_size + png_sizeof(msg) + 1;
  170875. text = (png_charp)png_malloc_warn(png_ptr, text_size);
  170876. if (text == NULL)
  170877. {
  170878. png_free(png_ptr,chunkdata);
  170879. png_error(png_ptr,"Not enough memory to decompress chunk");
  170880. }
  170881. png_memcpy(text, chunkdata, prefix_size);
  170882. }
  170883. text[text_size - 1] = 0x00;
  170884. text_size = (png_size_t)(chunklength - (text - chunkdata) - 1);
  170885. text_size = png_sizeof(msg) > text_size ? text_size :
  170886. png_sizeof(msg);
  170887. png_memcpy(text + prefix_size, msg, text_size + 1);
  170888. break;
  170889. }
  170890. if (!png_ptr->zstream.avail_out || ret == Z_STREAM_END)
  170891. {
  170892. if (text == NULL)
  170893. {
  170894. text_size = prefix_size +
  170895. png_ptr->zbuf_size - png_ptr->zstream.avail_out;
  170896. text = (png_charp)png_malloc_warn(png_ptr, text_size + 1);
  170897. if (text == NULL)
  170898. {
  170899. png_free(png_ptr,chunkdata);
  170900. png_error(png_ptr,"Not enough memory to decompress chunk.");
  170901. }
  170902. png_memcpy(text + prefix_size, png_ptr->zbuf,
  170903. text_size - prefix_size);
  170904. png_memcpy(text, chunkdata, prefix_size);
  170905. *(text + text_size) = 0x00;
  170906. }
  170907. else
  170908. {
  170909. png_charp tmp;
  170910. tmp = text;
  170911. text = (png_charp)png_malloc_warn(png_ptr,
  170912. (png_uint_32)(text_size +
  170913. png_ptr->zbuf_size - png_ptr->zstream.avail_out + 1));
  170914. if (text == NULL)
  170915. {
  170916. png_free(png_ptr, tmp);
  170917. png_free(png_ptr, chunkdata);
  170918. png_error(png_ptr,"Not enough memory to decompress chunk..");
  170919. }
  170920. png_memcpy(text, tmp, text_size);
  170921. png_free(png_ptr, tmp);
  170922. png_memcpy(text + text_size, png_ptr->zbuf,
  170923. (png_ptr->zbuf_size - png_ptr->zstream.avail_out));
  170924. text_size += png_ptr->zbuf_size - png_ptr->zstream.avail_out;
  170925. *(text + text_size) = 0x00;
  170926. }
  170927. if (ret == Z_STREAM_END)
  170928. break;
  170929. else
  170930. {
  170931. png_ptr->zstream.next_out = png_ptr->zbuf;
  170932. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  170933. }
  170934. }
  170935. }
  170936. if (ret != Z_STREAM_END)
  170937. {
  170938. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  170939. char umsg[52];
  170940. if (ret == Z_BUF_ERROR)
  170941. png_snprintf(umsg, 52,
  170942. "Buffer error in compressed datastream in %s chunk",
  170943. png_ptr->chunk_name);
  170944. else if (ret == Z_DATA_ERROR)
  170945. png_snprintf(umsg, 52,
  170946. "Data error in compressed datastream in %s chunk",
  170947. png_ptr->chunk_name);
  170948. else
  170949. png_snprintf(umsg, 52,
  170950. "Incomplete compressed datastream in %s chunk",
  170951. png_ptr->chunk_name);
  170952. png_warning(png_ptr, umsg);
  170953. #else
  170954. png_warning(png_ptr,
  170955. "Incomplete compressed datastream in chunk other than IDAT");
  170956. #endif
  170957. text_size=prefix_size;
  170958. if (text == NULL)
  170959. {
  170960. text = (png_charp)png_malloc_warn(png_ptr, text_size+1);
  170961. if (text == NULL)
  170962. {
  170963. png_free(png_ptr, chunkdata);
  170964. png_error(png_ptr,"Not enough memory for text.");
  170965. }
  170966. png_memcpy(text, chunkdata, prefix_size);
  170967. }
  170968. *(text + text_size) = 0x00;
  170969. }
  170970. inflateReset(&png_ptr->zstream);
  170971. png_ptr->zstream.avail_in = 0;
  170972. png_free(png_ptr, chunkdata);
  170973. chunkdata = text;
  170974. *newlength=text_size;
  170975. }
  170976. else /* if (comp_type != PNG_COMPRESSION_TYPE_BASE) */
  170977. {
  170978. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  170979. char umsg[50];
  170980. png_snprintf(umsg, 50,
  170981. "Unknown zTXt compression type %d", comp_type);
  170982. png_warning(png_ptr, umsg);
  170983. #else
  170984. png_warning(png_ptr, "Unknown zTXt compression type");
  170985. #endif
  170986. *(chunkdata + prefix_size) = 0x00;
  170987. *newlength=prefix_size;
  170988. }
  170989. return chunkdata;
  170990. }
  170991. #endif
  170992. void /* PRIVATE */
  170993. png_handle_IHDR(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  170994. {
  170995. png_byte buf[13];
  170996. png_uint_32 width, height;
  170997. int bit_depth, color_type, compression_type, filter_type;
  170998. int interlace_type;
  170999. png_debug(1, "in png_handle_IHDR\n");
  171000. if (png_ptr->mode & PNG_HAVE_IHDR)
  171001. png_error(png_ptr, "Out of place IHDR");
  171002. if (length != 13)
  171003. png_error(png_ptr, "Invalid IHDR chunk");
  171004. png_ptr->mode |= PNG_HAVE_IHDR;
  171005. png_crc_read(png_ptr, buf, 13);
  171006. png_crc_finish(png_ptr, 0);
  171007. width = png_get_uint_31(png_ptr, buf);
  171008. height = png_get_uint_31(png_ptr, buf + 4);
  171009. bit_depth = buf[8];
  171010. color_type = buf[9];
  171011. compression_type = buf[10];
  171012. filter_type = buf[11];
  171013. interlace_type = buf[12];
  171014. png_ptr->width = width;
  171015. png_ptr->height = height;
  171016. png_ptr->bit_depth = (png_byte)bit_depth;
  171017. png_ptr->interlaced = (png_byte)interlace_type;
  171018. png_ptr->color_type = (png_byte)color_type;
  171019. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  171020. png_ptr->filter_type = (png_byte)filter_type;
  171021. #endif
  171022. png_ptr->compression_type = (png_byte)compression_type;
  171023. switch (png_ptr->color_type)
  171024. {
  171025. case PNG_COLOR_TYPE_GRAY:
  171026. case PNG_COLOR_TYPE_PALETTE:
  171027. png_ptr->channels = 1;
  171028. break;
  171029. case PNG_COLOR_TYPE_RGB:
  171030. png_ptr->channels = 3;
  171031. break;
  171032. case PNG_COLOR_TYPE_GRAY_ALPHA:
  171033. png_ptr->channels = 2;
  171034. break;
  171035. case PNG_COLOR_TYPE_RGB_ALPHA:
  171036. png_ptr->channels = 4;
  171037. break;
  171038. }
  171039. png_ptr->pixel_depth = (png_byte)(png_ptr->bit_depth *
  171040. png_ptr->channels);
  171041. png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->width);
  171042. png_debug1(3,"bit_depth = %d\n", png_ptr->bit_depth);
  171043. png_debug1(3,"channels = %d\n", png_ptr->channels);
  171044. png_debug1(3,"rowbytes = %lu\n", png_ptr->rowbytes);
  171045. png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth,
  171046. color_type, interlace_type, compression_type, filter_type);
  171047. }
  171048. void /* PRIVATE */
  171049. png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171050. {
  171051. png_color palette[PNG_MAX_PALETTE_LENGTH];
  171052. int num, i;
  171053. #ifndef PNG_NO_POINTER_INDEXING
  171054. png_colorp pal_ptr;
  171055. #endif
  171056. png_debug(1, "in png_handle_PLTE\n");
  171057. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171058. png_error(png_ptr, "Missing IHDR before PLTE");
  171059. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171060. {
  171061. png_warning(png_ptr, "Invalid PLTE after IDAT");
  171062. png_crc_finish(png_ptr, length);
  171063. return;
  171064. }
  171065. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171066. png_error(png_ptr, "Duplicate PLTE chunk");
  171067. png_ptr->mode |= PNG_HAVE_PLTE;
  171068. if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR))
  171069. {
  171070. png_warning(png_ptr,
  171071. "Ignoring PLTE chunk in grayscale PNG");
  171072. png_crc_finish(png_ptr, length);
  171073. return;
  171074. }
  171075. #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
  171076. if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
  171077. {
  171078. png_crc_finish(png_ptr, length);
  171079. return;
  171080. }
  171081. #endif
  171082. if (length > 3*PNG_MAX_PALETTE_LENGTH || length % 3)
  171083. {
  171084. if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
  171085. {
  171086. png_warning(png_ptr, "Invalid palette chunk");
  171087. png_crc_finish(png_ptr, length);
  171088. return;
  171089. }
  171090. else
  171091. {
  171092. png_error(png_ptr, "Invalid palette chunk");
  171093. }
  171094. }
  171095. num = (int)length / 3;
  171096. #ifndef PNG_NO_POINTER_INDEXING
  171097. for (i = 0, pal_ptr = palette; i < num; i++, pal_ptr++)
  171098. {
  171099. png_byte buf[3];
  171100. png_crc_read(png_ptr, buf, 3);
  171101. pal_ptr->red = buf[0];
  171102. pal_ptr->green = buf[1];
  171103. pal_ptr->blue = buf[2];
  171104. }
  171105. #else
  171106. for (i = 0; i < num; i++)
  171107. {
  171108. png_byte buf[3];
  171109. png_crc_read(png_ptr, buf, 3);
  171110. palette[i].red = buf[0];
  171111. palette[i].green = buf[1];
  171112. palette[i].blue = buf[2];
  171113. }
  171114. #endif
  171115. #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
  171116. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171117. #endif
  171118. {
  171119. png_crc_finish(png_ptr, 0);
  171120. }
  171121. #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
  171122. else if (png_crc_error(png_ptr)) /* Only if we have a CRC error */
  171123. {
  171124. if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_USE))
  171125. {
  171126. if (png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)
  171127. {
  171128. png_chunk_error(png_ptr, "CRC error");
  171129. }
  171130. else
  171131. {
  171132. png_chunk_warning(png_ptr, "CRC error");
  171133. return;
  171134. }
  171135. }
  171136. else if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN))
  171137. {
  171138. png_chunk_warning(png_ptr, "CRC error");
  171139. }
  171140. }
  171141. #endif
  171142. png_set_PLTE(png_ptr, info_ptr, palette, num);
  171143. #if defined(PNG_READ_tRNS_SUPPORTED)
  171144. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171145. {
  171146. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  171147. {
  171148. if (png_ptr->num_trans > (png_uint_16)num)
  171149. {
  171150. png_warning(png_ptr, "Truncating incorrect tRNS chunk length");
  171151. png_ptr->num_trans = (png_uint_16)num;
  171152. }
  171153. if (info_ptr->num_trans > (png_uint_16)num)
  171154. {
  171155. png_warning(png_ptr, "Truncating incorrect info tRNS chunk length");
  171156. info_ptr->num_trans = (png_uint_16)num;
  171157. }
  171158. }
  171159. }
  171160. #endif
  171161. }
  171162. void /* PRIVATE */
  171163. png_handle_IEND(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171164. {
  171165. png_debug(1, "in png_handle_IEND\n");
  171166. if (!(png_ptr->mode & PNG_HAVE_IHDR) || !(png_ptr->mode & PNG_HAVE_IDAT))
  171167. {
  171168. png_error(png_ptr, "No image in file");
  171169. }
  171170. png_ptr->mode |= (PNG_AFTER_IDAT | PNG_HAVE_IEND);
  171171. if (length != 0)
  171172. {
  171173. png_warning(png_ptr, "Incorrect IEND chunk length");
  171174. }
  171175. png_crc_finish(png_ptr, length);
  171176. info_ptr =info_ptr; /* quiet compiler warnings about unused info_ptr */
  171177. }
  171178. #if defined(PNG_READ_gAMA_SUPPORTED)
  171179. void /* PRIVATE */
  171180. png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171181. {
  171182. png_fixed_point igamma;
  171183. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171184. float file_gamma;
  171185. #endif
  171186. png_byte buf[4];
  171187. png_debug(1, "in png_handle_gAMA\n");
  171188. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171189. png_error(png_ptr, "Missing IHDR before gAMA");
  171190. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171191. {
  171192. png_warning(png_ptr, "Invalid gAMA after IDAT");
  171193. png_crc_finish(png_ptr, length);
  171194. return;
  171195. }
  171196. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171197. png_warning(png_ptr, "Out of place gAMA chunk");
  171198. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  171199. #if defined(PNG_READ_sRGB_SUPPORTED)
  171200. && !(info_ptr->valid & PNG_INFO_sRGB)
  171201. #endif
  171202. )
  171203. {
  171204. png_warning(png_ptr, "Duplicate gAMA chunk");
  171205. png_crc_finish(png_ptr, length);
  171206. return;
  171207. }
  171208. if (length != 4)
  171209. {
  171210. png_warning(png_ptr, "Incorrect gAMA chunk length");
  171211. png_crc_finish(png_ptr, length);
  171212. return;
  171213. }
  171214. png_crc_read(png_ptr, buf, 4);
  171215. if (png_crc_finish(png_ptr, 0))
  171216. return;
  171217. igamma = (png_fixed_point)png_get_uint_32(buf);
  171218. if (igamma == 0)
  171219. {
  171220. png_warning(png_ptr,
  171221. "Ignoring gAMA chunk with gamma=0");
  171222. return;
  171223. }
  171224. #if defined(PNG_READ_sRGB_SUPPORTED)
  171225. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB))
  171226. if (PNG_OUT_OF_RANGE(igamma, 45500L, 500))
  171227. {
  171228. png_warning(png_ptr,
  171229. "Ignoring incorrect gAMA value when sRGB is also present");
  171230. #ifndef PNG_NO_CONSOLE_IO
  171231. fprintf(stderr, "gamma = (%d/100000)\n", (int)igamma);
  171232. #endif
  171233. return;
  171234. }
  171235. #endif /* PNG_READ_sRGB_SUPPORTED */
  171236. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171237. file_gamma = (float)igamma / (float)100000.0;
  171238. # ifdef PNG_READ_GAMMA_SUPPORTED
  171239. png_ptr->gamma = file_gamma;
  171240. # endif
  171241. png_set_gAMA(png_ptr, info_ptr, file_gamma);
  171242. #endif
  171243. #ifdef PNG_FIXED_POINT_SUPPORTED
  171244. png_set_gAMA_fixed(png_ptr, info_ptr, igamma);
  171245. #endif
  171246. }
  171247. #endif
  171248. #if defined(PNG_READ_sBIT_SUPPORTED)
  171249. void /* PRIVATE */
  171250. png_handle_sBIT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171251. {
  171252. png_size_t truelen;
  171253. png_byte buf[4];
  171254. png_debug(1, "in png_handle_sBIT\n");
  171255. buf[0] = buf[1] = buf[2] = buf[3] = 0;
  171256. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171257. png_error(png_ptr, "Missing IHDR before sBIT");
  171258. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171259. {
  171260. png_warning(png_ptr, "Invalid sBIT after IDAT");
  171261. png_crc_finish(png_ptr, length);
  171262. return;
  171263. }
  171264. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171265. {
  171266. png_warning(png_ptr, "Out of place sBIT chunk");
  171267. }
  171268. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT))
  171269. {
  171270. png_warning(png_ptr, "Duplicate sBIT chunk");
  171271. png_crc_finish(png_ptr, length);
  171272. return;
  171273. }
  171274. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171275. truelen = 3;
  171276. else
  171277. truelen = (png_size_t)png_ptr->channels;
  171278. if (length != truelen || length > 4)
  171279. {
  171280. png_warning(png_ptr, "Incorrect sBIT chunk length");
  171281. png_crc_finish(png_ptr, length);
  171282. return;
  171283. }
  171284. png_crc_read(png_ptr, buf, truelen);
  171285. if (png_crc_finish(png_ptr, 0))
  171286. return;
  171287. if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
  171288. {
  171289. png_ptr->sig_bit.red = buf[0];
  171290. png_ptr->sig_bit.green = buf[1];
  171291. png_ptr->sig_bit.blue = buf[2];
  171292. png_ptr->sig_bit.alpha = buf[3];
  171293. }
  171294. else
  171295. {
  171296. png_ptr->sig_bit.gray = buf[0];
  171297. png_ptr->sig_bit.red = buf[0];
  171298. png_ptr->sig_bit.green = buf[0];
  171299. png_ptr->sig_bit.blue = buf[0];
  171300. png_ptr->sig_bit.alpha = buf[1];
  171301. }
  171302. png_set_sBIT(png_ptr, info_ptr, &(png_ptr->sig_bit));
  171303. }
  171304. #endif
  171305. #if defined(PNG_READ_cHRM_SUPPORTED)
  171306. void /* PRIVATE */
  171307. png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171308. {
  171309. png_byte buf[4];
  171310. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171311. float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
  171312. #endif
  171313. png_fixed_point int_x_white, int_y_white, int_x_red, int_y_red, int_x_green,
  171314. int_y_green, int_x_blue, int_y_blue;
  171315. png_uint_32 uint_x, uint_y;
  171316. png_debug(1, "in png_handle_cHRM\n");
  171317. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171318. png_error(png_ptr, "Missing IHDR before cHRM");
  171319. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171320. {
  171321. png_warning(png_ptr, "Invalid cHRM after IDAT");
  171322. png_crc_finish(png_ptr, length);
  171323. return;
  171324. }
  171325. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171326. png_warning(png_ptr, "Missing PLTE before cHRM");
  171327. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM)
  171328. #if defined(PNG_READ_sRGB_SUPPORTED)
  171329. && !(info_ptr->valid & PNG_INFO_sRGB)
  171330. #endif
  171331. )
  171332. {
  171333. png_warning(png_ptr, "Duplicate cHRM chunk");
  171334. png_crc_finish(png_ptr, length);
  171335. return;
  171336. }
  171337. if (length != 32)
  171338. {
  171339. png_warning(png_ptr, "Incorrect cHRM chunk length");
  171340. png_crc_finish(png_ptr, length);
  171341. return;
  171342. }
  171343. png_crc_read(png_ptr, buf, 4);
  171344. uint_x = png_get_uint_32(buf);
  171345. png_crc_read(png_ptr, buf, 4);
  171346. uint_y = png_get_uint_32(buf);
  171347. if (uint_x > 80000L || uint_y > 80000L ||
  171348. uint_x + uint_y > 100000L)
  171349. {
  171350. png_warning(png_ptr, "Invalid cHRM white point");
  171351. png_crc_finish(png_ptr, 24);
  171352. return;
  171353. }
  171354. int_x_white = (png_fixed_point)uint_x;
  171355. int_y_white = (png_fixed_point)uint_y;
  171356. png_crc_read(png_ptr, buf, 4);
  171357. uint_x = png_get_uint_32(buf);
  171358. png_crc_read(png_ptr, buf, 4);
  171359. uint_y = png_get_uint_32(buf);
  171360. if (uint_x + uint_y > 100000L)
  171361. {
  171362. png_warning(png_ptr, "Invalid cHRM red point");
  171363. png_crc_finish(png_ptr, 16);
  171364. return;
  171365. }
  171366. int_x_red = (png_fixed_point)uint_x;
  171367. int_y_red = (png_fixed_point)uint_y;
  171368. png_crc_read(png_ptr, buf, 4);
  171369. uint_x = png_get_uint_32(buf);
  171370. png_crc_read(png_ptr, buf, 4);
  171371. uint_y = png_get_uint_32(buf);
  171372. if (uint_x + uint_y > 100000L)
  171373. {
  171374. png_warning(png_ptr, "Invalid cHRM green point");
  171375. png_crc_finish(png_ptr, 8);
  171376. return;
  171377. }
  171378. int_x_green = (png_fixed_point)uint_x;
  171379. int_y_green = (png_fixed_point)uint_y;
  171380. png_crc_read(png_ptr, buf, 4);
  171381. uint_x = png_get_uint_32(buf);
  171382. png_crc_read(png_ptr, buf, 4);
  171383. uint_y = png_get_uint_32(buf);
  171384. if (uint_x + uint_y > 100000L)
  171385. {
  171386. png_warning(png_ptr, "Invalid cHRM blue point");
  171387. png_crc_finish(png_ptr, 0);
  171388. return;
  171389. }
  171390. int_x_blue = (png_fixed_point)uint_x;
  171391. int_y_blue = (png_fixed_point)uint_y;
  171392. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171393. white_x = (float)int_x_white / (float)100000.0;
  171394. white_y = (float)int_y_white / (float)100000.0;
  171395. red_x = (float)int_x_red / (float)100000.0;
  171396. red_y = (float)int_y_red / (float)100000.0;
  171397. green_x = (float)int_x_green / (float)100000.0;
  171398. green_y = (float)int_y_green / (float)100000.0;
  171399. blue_x = (float)int_x_blue / (float)100000.0;
  171400. blue_y = (float)int_y_blue / (float)100000.0;
  171401. #endif
  171402. #if defined(PNG_READ_sRGB_SUPPORTED)
  171403. if ((info_ptr != NULL) && (info_ptr->valid & PNG_INFO_sRGB))
  171404. {
  171405. if (PNG_OUT_OF_RANGE(int_x_white, 31270, 1000) ||
  171406. PNG_OUT_OF_RANGE(int_y_white, 32900, 1000) ||
  171407. PNG_OUT_OF_RANGE(int_x_red, 64000L, 1000) ||
  171408. PNG_OUT_OF_RANGE(int_y_red, 33000, 1000) ||
  171409. PNG_OUT_OF_RANGE(int_x_green, 30000, 1000) ||
  171410. PNG_OUT_OF_RANGE(int_y_green, 60000L, 1000) ||
  171411. PNG_OUT_OF_RANGE(int_x_blue, 15000, 1000) ||
  171412. PNG_OUT_OF_RANGE(int_y_blue, 6000, 1000))
  171413. {
  171414. png_warning(png_ptr,
  171415. "Ignoring incorrect cHRM value when sRGB is also present");
  171416. #ifndef PNG_NO_CONSOLE_IO
  171417. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171418. fprintf(stderr,"wx=%f, wy=%f, rx=%f, ry=%f\n",
  171419. white_x, white_y, red_x, red_y);
  171420. fprintf(stderr,"gx=%f, gy=%f, bx=%f, by=%f\n",
  171421. green_x, green_y, blue_x, blue_y);
  171422. #else
  171423. fprintf(stderr,"wx=%ld, wy=%ld, rx=%ld, ry=%ld\n",
  171424. int_x_white, int_y_white, int_x_red, int_y_red);
  171425. fprintf(stderr,"gx=%ld, gy=%ld, bx=%ld, by=%ld\n",
  171426. int_x_green, int_y_green, int_x_blue, int_y_blue);
  171427. #endif
  171428. #endif /* PNG_NO_CONSOLE_IO */
  171429. }
  171430. png_crc_finish(png_ptr, 0);
  171431. return;
  171432. }
  171433. #endif /* PNG_READ_sRGB_SUPPORTED */
  171434. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171435. png_set_cHRM(png_ptr, info_ptr,
  171436. white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
  171437. #endif
  171438. #ifdef PNG_FIXED_POINT_SUPPORTED
  171439. png_set_cHRM_fixed(png_ptr, info_ptr,
  171440. int_x_white, int_y_white, int_x_red, int_y_red, int_x_green,
  171441. int_y_green, int_x_blue, int_y_blue);
  171442. #endif
  171443. if (png_crc_finish(png_ptr, 0))
  171444. return;
  171445. }
  171446. #endif
  171447. #if defined(PNG_READ_sRGB_SUPPORTED)
  171448. void /* PRIVATE */
  171449. png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171450. {
  171451. int intent;
  171452. png_byte buf[1];
  171453. png_debug(1, "in png_handle_sRGB\n");
  171454. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171455. png_error(png_ptr, "Missing IHDR before sRGB");
  171456. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171457. {
  171458. png_warning(png_ptr, "Invalid sRGB after IDAT");
  171459. png_crc_finish(png_ptr, length);
  171460. return;
  171461. }
  171462. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171463. png_warning(png_ptr, "Out of place sRGB chunk");
  171464. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB))
  171465. {
  171466. png_warning(png_ptr, "Duplicate sRGB chunk");
  171467. png_crc_finish(png_ptr, length);
  171468. return;
  171469. }
  171470. if (length != 1)
  171471. {
  171472. png_warning(png_ptr, "Incorrect sRGB chunk length");
  171473. png_crc_finish(png_ptr, length);
  171474. return;
  171475. }
  171476. png_crc_read(png_ptr, buf, 1);
  171477. if (png_crc_finish(png_ptr, 0))
  171478. return;
  171479. intent = buf[0];
  171480. if (intent >= PNG_sRGB_INTENT_LAST)
  171481. {
  171482. png_warning(png_ptr, "Unknown sRGB intent");
  171483. return;
  171484. }
  171485. #if defined(PNG_READ_gAMA_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED)
  171486. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA))
  171487. {
  171488. png_fixed_point igamma;
  171489. #ifdef PNG_FIXED_POINT_SUPPORTED
  171490. igamma=info_ptr->int_gamma;
  171491. #else
  171492. # ifdef PNG_FLOATING_POINT_SUPPORTED
  171493. igamma=(png_fixed_point)(info_ptr->gamma * 100000.);
  171494. # endif
  171495. #endif
  171496. if (PNG_OUT_OF_RANGE(igamma, 45500L, 500))
  171497. {
  171498. png_warning(png_ptr,
  171499. "Ignoring incorrect gAMA value when sRGB is also present");
  171500. #ifndef PNG_NO_CONSOLE_IO
  171501. # ifdef PNG_FIXED_POINT_SUPPORTED
  171502. fprintf(stderr,"incorrect gamma=(%d/100000)\n",(int)png_ptr->int_gamma);
  171503. # else
  171504. # ifdef PNG_FLOATING_POINT_SUPPORTED
  171505. fprintf(stderr,"incorrect gamma=%f\n",png_ptr->gamma);
  171506. # endif
  171507. # endif
  171508. #endif
  171509. }
  171510. }
  171511. #endif /* PNG_READ_gAMA_SUPPORTED */
  171512. #ifdef PNG_READ_cHRM_SUPPORTED
  171513. #ifdef PNG_FIXED_POINT_SUPPORTED
  171514. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  171515. if (PNG_OUT_OF_RANGE(info_ptr->int_x_white, 31270, 1000) ||
  171516. PNG_OUT_OF_RANGE(info_ptr->int_y_white, 32900, 1000) ||
  171517. PNG_OUT_OF_RANGE(info_ptr->int_x_red, 64000L, 1000) ||
  171518. PNG_OUT_OF_RANGE(info_ptr->int_y_red, 33000, 1000) ||
  171519. PNG_OUT_OF_RANGE(info_ptr->int_x_green, 30000, 1000) ||
  171520. PNG_OUT_OF_RANGE(info_ptr->int_y_green, 60000L, 1000) ||
  171521. PNG_OUT_OF_RANGE(info_ptr->int_x_blue, 15000, 1000) ||
  171522. PNG_OUT_OF_RANGE(info_ptr->int_y_blue, 6000, 1000))
  171523. {
  171524. png_warning(png_ptr,
  171525. "Ignoring incorrect cHRM value when sRGB is also present");
  171526. }
  171527. #endif /* PNG_FIXED_POINT_SUPPORTED */
  171528. #endif /* PNG_READ_cHRM_SUPPORTED */
  171529. png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr, intent);
  171530. }
  171531. #endif /* PNG_READ_sRGB_SUPPORTED */
  171532. #if defined(PNG_READ_iCCP_SUPPORTED)
  171533. void /* PRIVATE */
  171534. png_handle_iCCP(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171535. {
  171536. png_charp chunkdata;
  171537. png_byte compression_type;
  171538. png_bytep pC;
  171539. png_charp profile;
  171540. png_uint_32 skip = 0;
  171541. png_uint_32 profile_size, profile_length;
  171542. png_size_t slength, prefix_length, data_length;
  171543. png_debug(1, "in png_handle_iCCP\n");
  171544. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171545. png_error(png_ptr, "Missing IHDR before iCCP");
  171546. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171547. {
  171548. png_warning(png_ptr, "Invalid iCCP after IDAT");
  171549. png_crc_finish(png_ptr, length);
  171550. return;
  171551. }
  171552. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171553. png_warning(png_ptr, "Out of place iCCP chunk");
  171554. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP))
  171555. {
  171556. png_warning(png_ptr, "Duplicate iCCP chunk");
  171557. png_crc_finish(png_ptr, length);
  171558. return;
  171559. }
  171560. #ifdef PNG_MAX_MALLOC_64K
  171561. if (length > (png_uint_32)65535L)
  171562. {
  171563. png_warning(png_ptr, "iCCP chunk too large to fit in memory");
  171564. skip = length - (png_uint_32)65535L;
  171565. length = (png_uint_32)65535L;
  171566. }
  171567. #endif
  171568. chunkdata = (png_charp)png_malloc(png_ptr, length + 1);
  171569. slength = (png_size_t)length;
  171570. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  171571. if (png_crc_finish(png_ptr, skip))
  171572. {
  171573. png_free(png_ptr, chunkdata);
  171574. return;
  171575. }
  171576. chunkdata[slength] = 0x00;
  171577. for (profile = chunkdata; *profile; profile++)
  171578. ;
  171579. ++profile;
  171580. if ( profile >= chunkdata + slength - 1)
  171581. {
  171582. png_free(png_ptr, chunkdata);
  171583. png_warning(png_ptr, "Malformed iCCP chunk");
  171584. return;
  171585. }
  171586. compression_type = *profile++;
  171587. if (compression_type)
  171588. {
  171589. png_warning(png_ptr, "Ignoring nonzero compression type in iCCP chunk");
  171590. compression_type=0x00; /* Reset it to zero (libpng-1.0.6 through 1.0.8
  171591. wrote nonzero) */
  171592. }
  171593. prefix_length = profile - chunkdata;
  171594. chunkdata = png_decompress_chunk(png_ptr, compression_type, chunkdata,
  171595. slength, prefix_length, &data_length);
  171596. profile_length = data_length - prefix_length;
  171597. if ( prefix_length > data_length || profile_length < 4)
  171598. {
  171599. png_free(png_ptr, chunkdata);
  171600. png_warning(png_ptr, "Profile size field missing from iCCP chunk");
  171601. return;
  171602. }
  171603. pC = (png_bytep)(chunkdata+prefix_length);
  171604. profile_size = ((*(pC ))<<24) |
  171605. ((*(pC+1))<<16) |
  171606. ((*(pC+2))<< 8) |
  171607. ((*(pC+3)) );
  171608. if(profile_size < profile_length)
  171609. profile_length = profile_size;
  171610. if(profile_size > profile_length)
  171611. {
  171612. png_free(png_ptr, chunkdata);
  171613. png_warning(png_ptr, "Ignoring truncated iCCP profile.");
  171614. return;
  171615. }
  171616. png_set_iCCP(png_ptr, info_ptr, chunkdata, compression_type,
  171617. chunkdata + prefix_length, profile_length);
  171618. png_free(png_ptr, chunkdata);
  171619. }
  171620. #endif /* PNG_READ_iCCP_SUPPORTED */
  171621. #if defined(PNG_READ_sPLT_SUPPORTED)
  171622. void /* PRIVATE */
  171623. png_handle_sPLT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171624. {
  171625. png_bytep chunkdata;
  171626. png_bytep entry_start;
  171627. png_sPLT_t new_palette;
  171628. #ifdef PNG_NO_POINTER_INDEXING
  171629. png_sPLT_entryp pp;
  171630. #endif
  171631. int data_length, entry_size, i;
  171632. png_uint_32 skip = 0;
  171633. png_size_t slength;
  171634. png_debug(1, "in png_handle_sPLT\n");
  171635. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171636. png_error(png_ptr, "Missing IHDR before sPLT");
  171637. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171638. {
  171639. png_warning(png_ptr, "Invalid sPLT after IDAT");
  171640. png_crc_finish(png_ptr, length);
  171641. return;
  171642. }
  171643. #ifdef PNG_MAX_MALLOC_64K
  171644. if (length > (png_uint_32)65535L)
  171645. {
  171646. png_warning(png_ptr, "sPLT chunk too large to fit in memory");
  171647. skip = length - (png_uint_32)65535L;
  171648. length = (png_uint_32)65535L;
  171649. }
  171650. #endif
  171651. chunkdata = (png_bytep)png_malloc(png_ptr, length + 1);
  171652. slength = (png_size_t)length;
  171653. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  171654. if (png_crc_finish(png_ptr, skip))
  171655. {
  171656. png_free(png_ptr, chunkdata);
  171657. return;
  171658. }
  171659. chunkdata[slength] = 0x00;
  171660. for (entry_start = chunkdata; *entry_start; entry_start++)
  171661. ;
  171662. ++entry_start;
  171663. if (entry_start > chunkdata + slength - 2)
  171664. {
  171665. png_free(png_ptr, chunkdata);
  171666. png_warning(png_ptr, "malformed sPLT chunk");
  171667. return;
  171668. }
  171669. new_palette.depth = *entry_start++;
  171670. entry_size = (new_palette.depth == 8 ? 6 : 10);
  171671. data_length = (slength - (entry_start - chunkdata));
  171672. if (data_length % entry_size)
  171673. {
  171674. png_free(png_ptr, chunkdata);
  171675. png_warning(png_ptr, "sPLT chunk has bad length");
  171676. return;
  171677. }
  171678. new_palette.nentries = (png_int_32) ( data_length / entry_size);
  171679. if ((png_uint_32) new_palette.nentries > (png_uint_32) (PNG_SIZE_MAX /
  171680. png_sizeof(png_sPLT_entry)))
  171681. {
  171682. png_warning(png_ptr, "sPLT chunk too long");
  171683. return;
  171684. }
  171685. new_palette.entries = (png_sPLT_entryp)png_malloc_warn(
  171686. png_ptr, new_palette.nentries * png_sizeof(png_sPLT_entry));
  171687. if (new_palette.entries == NULL)
  171688. {
  171689. png_warning(png_ptr, "sPLT chunk requires too much memory");
  171690. return;
  171691. }
  171692. #ifndef PNG_NO_POINTER_INDEXING
  171693. for (i = 0; i < new_palette.nentries; i++)
  171694. {
  171695. png_sPLT_entryp pp = new_palette.entries + i;
  171696. if (new_palette.depth == 8)
  171697. {
  171698. pp->red = *entry_start++;
  171699. pp->green = *entry_start++;
  171700. pp->blue = *entry_start++;
  171701. pp->alpha = *entry_start++;
  171702. }
  171703. else
  171704. {
  171705. pp->red = png_get_uint_16(entry_start); entry_start += 2;
  171706. pp->green = png_get_uint_16(entry_start); entry_start += 2;
  171707. pp->blue = png_get_uint_16(entry_start); entry_start += 2;
  171708. pp->alpha = png_get_uint_16(entry_start); entry_start += 2;
  171709. }
  171710. pp->frequency = png_get_uint_16(entry_start); entry_start += 2;
  171711. }
  171712. #else
  171713. pp = new_palette.entries;
  171714. for (i = 0; i < new_palette.nentries; i++)
  171715. {
  171716. if (new_palette.depth == 8)
  171717. {
  171718. pp[i].red = *entry_start++;
  171719. pp[i].green = *entry_start++;
  171720. pp[i].blue = *entry_start++;
  171721. pp[i].alpha = *entry_start++;
  171722. }
  171723. else
  171724. {
  171725. pp[i].red = png_get_uint_16(entry_start); entry_start += 2;
  171726. pp[i].green = png_get_uint_16(entry_start); entry_start += 2;
  171727. pp[i].blue = png_get_uint_16(entry_start); entry_start += 2;
  171728. pp[i].alpha = png_get_uint_16(entry_start); entry_start += 2;
  171729. }
  171730. pp->frequency = png_get_uint_16(entry_start); entry_start += 2;
  171731. }
  171732. #endif
  171733. new_palette.name = (png_charp)chunkdata;
  171734. png_set_sPLT(png_ptr, info_ptr, &new_palette, 1);
  171735. png_free(png_ptr, chunkdata);
  171736. png_free(png_ptr, new_palette.entries);
  171737. }
  171738. #endif /* PNG_READ_sPLT_SUPPORTED */
  171739. #if defined(PNG_READ_tRNS_SUPPORTED)
  171740. void /* PRIVATE */
  171741. png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171742. {
  171743. png_byte readbuf[PNG_MAX_PALETTE_LENGTH];
  171744. int bit_mask;
  171745. png_debug(1, "in png_handle_tRNS\n");
  171746. bit_mask = (1 << png_ptr->bit_depth) - 1;
  171747. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171748. png_error(png_ptr, "Missing IHDR before tRNS");
  171749. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171750. {
  171751. png_warning(png_ptr, "Invalid tRNS after IDAT");
  171752. png_crc_finish(png_ptr, length);
  171753. return;
  171754. }
  171755. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  171756. {
  171757. png_warning(png_ptr, "Duplicate tRNS chunk");
  171758. png_crc_finish(png_ptr, length);
  171759. return;
  171760. }
  171761. if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
  171762. {
  171763. png_byte buf[2];
  171764. if (length != 2)
  171765. {
  171766. png_warning(png_ptr, "Incorrect tRNS chunk length");
  171767. png_crc_finish(png_ptr, length);
  171768. return;
  171769. }
  171770. png_crc_read(png_ptr, buf, 2);
  171771. png_ptr->num_trans = 1;
  171772. png_ptr->trans_values.gray = png_get_uint_16(buf) & bit_mask;
  171773. }
  171774. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  171775. {
  171776. png_byte buf[6];
  171777. if (length != 6)
  171778. {
  171779. png_warning(png_ptr, "Incorrect tRNS chunk length");
  171780. png_crc_finish(png_ptr, length);
  171781. return;
  171782. }
  171783. png_crc_read(png_ptr, buf, (png_size_t)length);
  171784. png_ptr->num_trans = 1;
  171785. png_ptr->trans_values.red = png_get_uint_16(buf) & bit_mask;
  171786. png_ptr->trans_values.green = png_get_uint_16(buf + 2) & bit_mask;
  171787. png_ptr->trans_values.blue = png_get_uint_16(buf + 4) & bit_mask;
  171788. }
  171789. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171790. {
  171791. if (!(png_ptr->mode & PNG_HAVE_PLTE))
  171792. {
  171793. png_warning(png_ptr, "Missing PLTE before tRNS");
  171794. }
  171795. if (length > (png_uint_32)png_ptr->num_palette ||
  171796. length > PNG_MAX_PALETTE_LENGTH)
  171797. {
  171798. png_warning(png_ptr, "Incorrect tRNS chunk length");
  171799. png_crc_finish(png_ptr, length);
  171800. return;
  171801. }
  171802. if (length == 0)
  171803. {
  171804. png_warning(png_ptr, "Zero length tRNS chunk");
  171805. png_crc_finish(png_ptr, length);
  171806. return;
  171807. }
  171808. png_crc_read(png_ptr, readbuf, (png_size_t)length);
  171809. png_ptr->num_trans = (png_uint_16)length;
  171810. }
  171811. else
  171812. {
  171813. png_warning(png_ptr, "tRNS chunk not allowed with alpha channel");
  171814. png_crc_finish(png_ptr, length);
  171815. return;
  171816. }
  171817. if (png_crc_finish(png_ptr, 0))
  171818. {
  171819. png_ptr->num_trans = 0;
  171820. return;
  171821. }
  171822. png_set_tRNS(png_ptr, info_ptr, readbuf, png_ptr->num_trans,
  171823. &(png_ptr->trans_values));
  171824. }
  171825. #endif
  171826. #if defined(PNG_READ_bKGD_SUPPORTED)
  171827. void /* PRIVATE */
  171828. png_handle_bKGD(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171829. {
  171830. png_size_t truelen;
  171831. png_byte buf[6];
  171832. png_debug(1, "in png_handle_bKGD\n");
  171833. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171834. png_error(png_ptr, "Missing IHDR before bKGD");
  171835. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171836. {
  171837. png_warning(png_ptr, "Invalid bKGD after IDAT");
  171838. png_crc_finish(png_ptr, length);
  171839. return;
  171840. }
  171841. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  171842. !(png_ptr->mode & PNG_HAVE_PLTE))
  171843. {
  171844. png_warning(png_ptr, "Missing PLTE before bKGD");
  171845. png_crc_finish(png_ptr, length);
  171846. return;
  171847. }
  171848. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD))
  171849. {
  171850. png_warning(png_ptr, "Duplicate bKGD chunk");
  171851. png_crc_finish(png_ptr, length);
  171852. return;
  171853. }
  171854. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171855. truelen = 1;
  171856. else if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
  171857. truelen = 6;
  171858. else
  171859. truelen = 2;
  171860. if (length != truelen)
  171861. {
  171862. png_warning(png_ptr, "Incorrect bKGD chunk length");
  171863. png_crc_finish(png_ptr, length);
  171864. return;
  171865. }
  171866. png_crc_read(png_ptr, buf, truelen);
  171867. if (png_crc_finish(png_ptr, 0))
  171868. return;
  171869. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171870. {
  171871. png_ptr->background.index = buf[0];
  171872. if(info_ptr->num_palette)
  171873. {
  171874. if(buf[0] > info_ptr->num_palette)
  171875. {
  171876. png_warning(png_ptr, "Incorrect bKGD chunk index value");
  171877. return;
  171878. }
  171879. png_ptr->background.red =
  171880. (png_uint_16)png_ptr->palette[buf[0]].red;
  171881. png_ptr->background.green =
  171882. (png_uint_16)png_ptr->palette[buf[0]].green;
  171883. png_ptr->background.blue =
  171884. (png_uint_16)png_ptr->palette[buf[0]].blue;
  171885. }
  171886. }
  171887. else if (!(png_ptr->color_type & PNG_COLOR_MASK_COLOR)) /* GRAY */
  171888. {
  171889. png_ptr->background.red =
  171890. png_ptr->background.green =
  171891. png_ptr->background.blue =
  171892. png_ptr->background.gray = png_get_uint_16(buf);
  171893. }
  171894. else
  171895. {
  171896. png_ptr->background.red = png_get_uint_16(buf);
  171897. png_ptr->background.green = png_get_uint_16(buf + 2);
  171898. png_ptr->background.blue = png_get_uint_16(buf + 4);
  171899. }
  171900. png_set_bKGD(png_ptr, info_ptr, &(png_ptr->background));
  171901. }
  171902. #endif
  171903. #if defined(PNG_READ_hIST_SUPPORTED)
  171904. void /* PRIVATE */
  171905. png_handle_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171906. {
  171907. unsigned int num, i;
  171908. png_uint_16 readbuf[PNG_MAX_PALETTE_LENGTH];
  171909. png_debug(1, "in png_handle_hIST\n");
  171910. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171911. png_error(png_ptr, "Missing IHDR before hIST");
  171912. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171913. {
  171914. png_warning(png_ptr, "Invalid hIST after IDAT");
  171915. png_crc_finish(png_ptr, length);
  171916. return;
  171917. }
  171918. else if (!(png_ptr->mode & PNG_HAVE_PLTE))
  171919. {
  171920. png_warning(png_ptr, "Missing PLTE before hIST");
  171921. png_crc_finish(png_ptr, length);
  171922. return;
  171923. }
  171924. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST))
  171925. {
  171926. png_warning(png_ptr, "Duplicate hIST chunk");
  171927. png_crc_finish(png_ptr, length);
  171928. return;
  171929. }
  171930. num = length / 2 ;
  171931. if (num != (unsigned int) png_ptr->num_palette || num >
  171932. (unsigned int) PNG_MAX_PALETTE_LENGTH)
  171933. {
  171934. png_warning(png_ptr, "Incorrect hIST chunk length");
  171935. png_crc_finish(png_ptr, length);
  171936. return;
  171937. }
  171938. for (i = 0; i < num; i++)
  171939. {
  171940. png_byte buf[2];
  171941. png_crc_read(png_ptr, buf, 2);
  171942. readbuf[i] = png_get_uint_16(buf);
  171943. }
  171944. if (png_crc_finish(png_ptr, 0))
  171945. return;
  171946. png_set_hIST(png_ptr, info_ptr, readbuf);
  171947. }
  171948. #endif
  171949. #if defined(PNG_READ_pHYs_SUPPORTED)
  171950. void /* PRIVATE */
  171951. png_handle_pHYs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171952. {
  171953. png_byte buf[9];
  171954. png_uint_32 res_x, res_y;
  171955. int unit_type;
  171956. png_debug(1, "in png_handle_pHYs\n");
  171957. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171958. png_error(png_ptr, "Missing IHDR before pHYs");
  171959. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171960. {
  171961. png_warning(png_ptr, "Invalid pHYs after IDAT");
  171962. png_crc_finish(png_ptr, length);
  171963. return;
  171964. }
  171965. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
  171966. {
  171967. png_warning(png_ptr, "Duplicate pHYs chunk");
  171968. png_crc_finish(png_ptr, length);
  171969. return;
  171970. }
  171971. if (length != 9)
  171972. {
  171973. png_warning(png_ptr, "Incorrect pHYs chunk length");
  171974. png_crc_finish(png_ptr, length);
  171975. return;
  171976. }
  171977. png_crc_read(png_ptr, buf, 9);
  171978. if (png_crc_finish(png_ptr, 0))
  171979. return;
  171980. res_x = png_get_uint_32(buf);
  171981. res_y = png_get_uint_32(buf + 4);
  171982. unit_type = buf[8];
  171983. png_set_pHYs(png_ptr, info_ptr, res_x, res_y, unit_type);
  171984. }
  171985. #endif
  171986. #if defined(PNG_READ_oFFs_SUPPORTED)
  171987. void /* PRIVATE */
  171988. png_handle_oFFs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171989. {
  171990. png_byte buf[9];
  171991. png_int_32 offset_x, offset_y;
  171992. int unit_type;
  171993. png_debug(1, "in png_handle_oFFs\n");
  171994. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171995. png_error(png_ptr, "Missing IHDR before oFFs");
  171996. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171997. {
  171998. png_warning(png_ptr, "Invalid oFFs after IDAT");
  171999. png_crc_finish(png_ptr, length);
  172000. return;
  172001. }
  172002. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
  172003. {
  172004. png_warning(png_ptr, "Duplicate oFFs chunk");
  172005. png_crc_finish(png_ptr, length);
  172006. return;
  172007. }
  172008. if (length != 9)
  172009. {
  172010. png_warning(png_ptr, "Incorrect oFFs chunk length");
  172011. png_crc_finish(png_ptr, length);
  172012. return;
  172013. }
  172014. png_crc_read(png_ptr, buf, 9);
  172015. if (png_crc_finish(png_ptr, 0))
  172016. return;
  172017. offset_x = png_get_int_32(buf);
  172018. offset_y = png_get_int_32(buf + 4);
  172019. unit_type = buf[8];
  172020. png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y, unit_type);
  172021. }
  172022. #endif
  172023. #if defined(PNG_READ_pCAL_SUPPORTED)
  172024. void /* PRIVATE */
  172025. png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172026. {
  172027. png_charp purpose;
  172028. png_int_32 X0, X1;
  172029. png_byte type, nparams;
  172030. png_charp buf, units, endptr;
  172031. png_charpp params;
  172032. png_size_t slength;
  172033. int i;
  172034. png_debug(1, "in png_handle_pCAL\n");
  172035. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172036. png_error(png_ptr, "Missing IHDR before pCAL");
  172037. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172038. {
  172039. png_warning(png_ptr, "Invalid pCAL after IDAT");
  172040. png_crc_finish(png_ptr, length);
  172041. return;
  172042. }
  172043. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL))
  172044. {
  172045. png_warning(png_ptr, "Duplicate pCAL chunk");
  172046. png_crc_finish(png_ptr, length);
  172047. return;
  172048. }
  172049. png_debug1(2, "Allocating and reading pCAL chunk data (%lu bytes)\n",
  172050. length + 1);
  172051. purpose = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172052. if (purpose == NULL)
  172053. {
  172054. png_warning(png_ptr, "No memory for pCAL purpose.");
  172055. return;
  172056. }
  172057. slength = (png_size_t)length;
  172058. png_crc_read(png_ptr, (png_bytep)purpose, slength);
  172059. if (png_crc_finish(png_ptr, 0))
  172060. {
  172061. png_free(png_ptr, purpose);
  172062. return;
  172063. }
  172064. purpose[slength] = 0x00; /* null terminate the last string */
  172065. png_debug(3, "Finding end of pCAL purpose string\n");
  172066. for (buf = purpose; *buf; buf++)
  172067. ;
  172068. endptr = purpose + slength;
  172069. if (endptr <= buf + 12)
  172070. {
  172071. png_warning(png_ptr, "Invalid pCAL data");
  172072. png_free(png_ptr, purpose);
  172073. return;
  172074. }
  172075. png_debug(3, "Reading pCAL X0, X1, type, nparams, and units\n");
  172076. X0 = png_get_int_32((png_bytep)buf+1);
  172077. X1 = png_get_int_32((png_bytep)buf+5);
  172078. type = buf[9];
  172079. nparams = buf[10];
  172080. units = buf + 11;
  172081. png_debug(3, "Checking pCAL equation type and number of parameters\n");
  172082. if ((type == PNG_EQUATION_LINEAR && nparams != 2) ||
  172083. (type == PNG_EQUATION_BASE_E && nparams != 3) ||
  172084. (type == PNG_EQUATION_ARBITRARY && nparams != 3) ||
  172085. (type == PNG_EQUATION_HYPERBOLIC && nparams != 4))
  172086. {
  172087. png_warning(png_ptr, "Invalid pCAL parameters for equation type");
  172088. png_free(png_ptr, purpose);
  172089. return;
  172090. }
  172091. else if (type >= PNG_EQUATION_LAST)
  172092. {
  172093. png_warning(png_ptr, "Unrecognized equation type for pCAL chunk");
  172094. }
  172095. for (buf = units; *buf; buf++)
  172096. ;
  172097. png_debug(3, "Allocating pCAL parameters array\n");
  172098. params = (png_charpp)png_malloc_warn(png_ptr, (png_uint_32)(nparams
  172099. *png_sizeof(png_charp))) ;
  172100. if (params == NULL)
  172101. {
  172102. png_free(png_ptr, purpose);
  172103. png_warning(png_ptr, "No memory for pCAL params.");
  172104. return;
  172105. }
  172106. for (i = 0; i < (int)nparams; i++)
  172107. {
  172108. buf++; /* Skip the null string terminator from previous parameter. */
  172109. png_debug1(3, "Reading pCAL parameter %d\n", i);
  172110. for (params[i] = buf; buf <= endptr && *buf != 0x00; buf++)
  172111. ;
  172112. if (buf > endptr)
  172113. {
  172114. png_warning(png_ptr, "Invalid pCAL data");
  172115. png_free(png_ptr, purpose);
  172116. png_free(png_ptr, params);
  172117. return;
  172118. }
  172119. }
  172120. png_set_pCAL(png_ptr, info_ptr, purpose, X0, X1, type, nparams,
  172121. units, params);
  172122. png_free(png_ptr, purpose);
  172123. png_free(png_ptr, params);
  172124. }
  172125. #endif
  172126. #if defined(PNG_READ_sCAL_SUPPORTED)
  172127. void /* PRIVATE */
  172128. png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172129. {
  172130. png_charp buffer, ep;
  172131. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172132. double width, height;
  172133. png_charp vp;
  172134. #else
  172135. #ifdef PNG_FIXED_POINT_SUPPORTED
  172136. png_charp swidth, sheight;
  172137. #endif
  172138. #endif
  172139. png_size_t slength;
  172140. png_debug(1, "in png_handle_sCAL\n");
  172141. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172142. png_error(png_ptr, "Missing IHDR before sCAL");
  172143. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172144. {
  172145. png_warning(png_ptr, "Invalid sCAL after IDAT");
  172146. png_crc_finish(png_ptr, length);
  172147. return;
  172148. }
  172149. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sCAL))
  172150. {
  172151. png_warning(png_ptr, "Duplicate sCAL chunk");
  172152. png_crc_finish(png_ptr, length);
  172153. return;
  172154. }
  172155. png_debug1(2, "Allocating and reading sCAL chunk data (%lu bytes)\n",
  172156. length + 1);
  172157. buffer = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172158. if (buffer == NULL)
  172159. {
  172160. png_warning(png_ptr, "Out of memory while processing sCAL chunk");
  172161. return;
  172162. }
  172163. slength = (png_size_t)length;
  172164. png_crc_read(png_ptr, (png_bytep)buffer, slength);
  172165. if (png_crc_finish(png_ptr, 0))
  172166. {
  172167. png_free(png_ptr, buffer);
  172168. return;
  172169. }
  172170. buffer[slength] = 0x00; /* null terminate the last string */
  172171. ep = buffer + 1; /* skip unit byte */
  172172. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172173. width = png_strtod(png_ptr, ep, &vp);
  172174. if (*vp)
  172175. {
  172176. png_warning(png_ptr, "malformed width string in sCAL chunk");
  172177. return;
  172178. }
  172179. #else
  172180. #ifdef PNG_FIXED_POINT_SUPPORTED
  172181. swidth = (png_charp)png_malloc_warn(png_ptr, png_strlen(ep) + 1);
  172182. if (swidth == NULL)
  172183. {
  172184. png_warning(png_ptr, "Out of memory while processing sCAL chunk width");
  172185. return;
  172186. }
  172187. png_memcpy(swidth, ep, (png_size_t)png_strlen(ep));
  172188. #endif
  172189. #endif
  172190. for (ep = buffer; *ep; ep++)
  172191. ;
  172192. ep++;
  172193. if (buffer + slength < ep)
  172194. {
  172195. png_warning(png_ptr, "Truncated sCAL chunk");
  172196. #if defined(PNG_FIXED_POINT_SUPPORTED) && \
  172197. !defined(PNG_FLOATING_POINT_SUPPORTED)
  172198. png_free(png_ptr, swidth);
  172199. #endif
  172200. png_free(png_ptr, buffer);
  172201. return;
  172202. }
  172203. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172204. height = png_strtod(png_ptr, ep, &vp);
  172205. if (*vp)
  172206. {
  172207. png_warning(png_ptr, "malformed height string in sCAL chunk");
  172208. return;
  172209. }
  172210. #else
  172211. #ifdef PNG_FIXED_POINT_SUPPORTED
  172212. sheight = (png_charp)png_malloc_warn(png_ptr, png_strlen(ep) + 1);
  172213. if (swidth == NULL)
  172214. {
  172215. png_warning(png_ptr, "Out of memory while processing sCAL chunk height");
  172216. return;
  172217. }
  172218. png_memcpy(sheight, ep, (png_size_t)png_strlen(ep));
  172219. #endif
  172220. #endif
  172221. if (buffer + slength < ep
  172222. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172223. || width <= 0. || height <= 0.
  172224. #endif
  172225. )
  172226. {
  172227. png_warning(png_ptr, "Invalid sCAL data");
  172228. png_free(png_ptr, buffer);
  172229. #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
  172230. png_free(png_ptr, swidth);
  172231. png_free(png_ptr, sheight);
  172232. #endif
  172233. return;
  172234. }
  172235. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172236. png_set_sCAL(png_ptr, info_ptr, buffer[0], width, height);
  172237. #else
  172238. #ifdef PNG_FIXED_POINT_SUPPORTED
  172239. png_set_sCAL_s(png_ptr, info_ptr, buffer[0], swidth, sheight);
  172240. #endif
  172241. #endif
  172242. png_free(png_ptr, buffer);
  172243. #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
  172244. png_free(png_ptr, swidth);
  172245. png_free(png_ptr, sheight);
  172246. #endif
  172247. }
  172248. #endif
  172249. #if defined(PNG_READ_tIME_SUPPORTED)
  172250. void /* PRIVATE */
  172251. png_handle_tIME(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172252. {
  172253. png_byte buf[7];
  172254. png_time mod_time;
  172255. png_debug(1, "in png_handle_tIME\n");
  172256. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172257. png_error(png_ptr, "Out of place tIME chunk");
  172258. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME))
  172259. {
  172260. png_warning(png_ptr, "Duplicate tIME chunk");
  172261. png_crc_finish(png_ptr, length);
  172262. return;
  172263. }
  172264. if (png_ptr->mode & PNG_HAVE_IDAT)
  172265. png_ptr->mode |= PNG_AFTER_IDAT;
  172266. if (length != 7)
  172267. {
  172268. png_warning(png_ptr, "Incorrect tIME chunk length");
  172269. png_crc_finish(png_ptr, length);
  172270. return;
  172271. }
  172272. png_crc_read(png_ptr, buf, 7);
  172273. if (png_crc_finish(png_ptr, 0))
  172274. return;
  172275. mod_time.second = buf[6];
  172276. mod_time.minute = buf[5];
  172277. mod_time.hour = buf[4];
  172278. mod_time.day = buf[3];
  172279. mod_time.month = buf[2];
  172280. mod_time.year = png_get_uint_16(buf);
  172281. png_set_tIME(png_ptr, info_ptr, &mod_time);
  172282. }
  172283. #endif
  172284. #if defined(PNG_READ_tEXt_SUPPORTED)
  172285. void /* PRIVATE */
  172286. png_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172287. {
  172288. png_textp text_ptr;
  172289. png_charp key;
  172290. png_charp text;
  172291. png_uint_32 skip = 0;
  172292. png_size_t slength;
  172293. int ret;
  172294. png_debug(1, "in png_handle_tEXt\n");
  172295. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172296. png_error(png_ptr, "Missing IHDR before tEXt");
  172297. if (png_ptr->mode & PNG_HAVE_IDAT)
  172298. png_ptr->mode |= PNG_AFTER_IDAT;
  172299. #ifdef PNG_MAX_MALLOC_64K
  172300. if (length > (png_uint_32)65535L)
  172301. {
  172302. png_warning(png_ptr, "tEXt chunk too large to fit in memory");
  172303. skip = length - (png_uint_32)65535L;
  172304. length = (png_uint_32)65535L;
  172305. }
  172306. #endif
  172307. key = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172308. if (key == NULL)
  172309. {
  172310. png_warning(png_ptr, "No memory to process text chunk.");
  172311. return;
  172312. }
  172313. slength = (png_size_t)length;
  172314. png_crc_read(png_ptr, (png_bytep)key, slength);
  172315. if (png_crc_finish(png_ptr, skip))
  172316. {
  172317. png_free(png_ptr, key);
  172318. return;
  172319. }
  172320. key[slength] = 0x00;
  172321. for (text = key; *text; text++)
  172322. ;
  172323. if (text != key + slength)
  172324. text++;
  172325. text_ptr = (png_textp)png_malloc_warn(png_ptr,
  172326. (png_uint_32)png_sizeof(png_text));
  172327. if (text_ptr == NULL)
  172328. {
  172329. png_warning(png_ptr, "Not enough memory to process text chunk.");
  172330. png_free(png_ptr, key);
  172331. return;
  172332. }
  172333. text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
  172334. text_ptr->key = key;
  172335. #ifdef PNG_iTXt_SUPPORTED
  172336. text_ptr->lang = NULL;
  172337. text_ptr->lang_key = NULL;
  172338. text_ptr->itxt_length = 0;
  172339. #endif
  172340. text_ptr->text = text;
  172341. text_ptr->text_length = png_strlen(text);
  172342. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  172343. png_free(png_ptr, key);
  172344. png_free(png_ptr, text_ptr);
  172345. if (ret)
  172346. png_warning(png_ptr, "Insufficient memory to process text chunk.");
  172347. }
  172348. #endif
  172349. #if defined(PNG_READ_zTXt_SUPPORTED)
  172350. void /* PRIVATE */
  172351. png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172352. {
  172353. png_textp text_ptr;
  172354. png_charp chunkdata;
  172355. png_charp text;
  172356. int comp_type;
  172357. int ret;
  172358. png_size_t slength, prefix_len, data_len;
  172359. png_debug(1, "in png_handle_zTXt\n");
  172360. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172361. png_error(png_ptr, "Missing IHDR before zTXt");
  172362. if (png_ptr->mode & PNG_HAVE_IDAT)
  172363. png_ptr->mode |= PNG_AFTER_IDAT;
  172364. #ifdef PNG_MAX_MALLOC_64K
  172365. if (length > (png_uint_32)65535L)
  172366. {
  172367. png_warning(png_ptr,"zTXt chunk too large to fit in memory");
  172368. png_crc_finish(png_ptr, length);
  172369. return;
  172370. }
  172371. #endif
  172372. chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172373. if (chunkdata == NULL)
  172374. {
  172375. png_warning(png_ptr,"Out of memory processing zTXt chunk.");
  172376. return;
  172377. }
  172378. slength = (png_size_t)length;
  172379. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  172380. if (png_crc_finish(png_ptr, 0))
  172381. {
  172382. png_free(png_ptr, chunkdata);
  172383. return;
  172384. }
  172385. chunkdata[slength] = 0x00;
  172386. for (text = chunkdata; *text; text++)
  172387. ;
  172388. if (text >= chunkdata + slength - 2)
  172389. {
  172390. png_warning(png_ptr, "Truncated zTXt chunk");
  172391. png_free(png_ptr, chunkdata);
  172392. return;
  172393. }
  172394. else
  172395. {
  172396. comp_type = *(++text);
  172397. if (comp_type != PNG_TEXT_COMPRESSION_zTXt)
  172398. {
  172399. png_warning(png_ptr, "Unknown compression type in zTXt chunk");
  172400. comp_type = PNG_TEXT_COMPRESSION_zTXt;
  172401. }
  172402. text++; /* skip the compression_method byte */
  172403. }
  172404. prefix_len = text - chunkdata;
  172405. chunkdata = (png_charp)png_decompress_chunk(png_ptr, comp_type, chunkdata,
  172406. (png_size_t)length, prefix_len, &data_len);
  172407. text_ptr = (png_textp)png_malloc_warn(png_ptr,
  172408. (png_uint_32)png_sizeof(png_text));
  172409. if (text_ptr == NULL)
  172410. {
  172411. png_warning(png_ptr,"Not enough memory to process zTXt chunk.");
  172412. png_free(png_ptr, chunkdata);
  172413. return;
  172414. }
  172415. text_ptr->compression = comp_type;
  172416. text_ptr->key = chunkdata;
  172417. #ifdef PNG_iTXt_SUPPORTED
  172418. text_ptr->lang = NULL;
  172419. text_ptr->lang_key = NULL;
  172420. text_ptr->itxt_length = 0;
  172421. #endif
  172422. text_ptr->text = chunkdata + prefix_len;
  172423. text_ptr->text_length = data_len;
  172424. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  172425. png_free(png_ptr, text_ptr);
  172426. png_free(png_ptr, chunkdata);
  172427. if (ret)
  172428. png_error(png_ptr, "Insufficient memory to store zTXt chunk.");
  172429. }
  172430. #endif
  172431. #if defined(PNG_READ_iTXt_SUPPORTED)
  172432. void /* PRIVATE */
  172433. png_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172434. {
  172435. png_textp text_ptr;
  172436. png_charp chunkdata;
  172437. png_charp key, lang, text, lang_key;
  172438. int comp_flag;
  172439. int comp_type = 0;
  172440. int ret;
  172441. png_size_t slength, prefix_len, data_len;
  172442. png_debug(1, "in png_handle_iTXt\n");
  172443. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172444. png_error(png_ptr, "Missing IHDR before iTXt");
  172445. if (png_ptr->mode & PNG_HAVE_IDAT)
  172446. png_ptr->mode |= PNG_AFTER_IDAT;
  172447. #ifdef PNG_MAX_MALLOC_64K
  172448. if (length > (png_uint_32)65535L)
  172449. {
  172450. png_warning(png_ptr,"iTXt chunk too large to fit in memory");
  172451. png_crc_finish(png_ptr, length);
  172452. return;
  172453. }
  172454. #endif
  172455. chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172456. if (chunkdata == NULL)
  172457. {
  172458. png_warning(png_ptr, "No memory to process iTXt chunk.");
  172459. return;
  172460. }
  172461. slength = (png_size_t)length;
  172462. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  172463. if (png_crc_finish(png_ptr, 0))
  172464. {
  172465. png_free(png_ptr, chunkdata);
  172466. return;
  172467. }
  172468. chunkdata[slength] = 0x00;
  172469. for (lang = chunkdata; *lang; lang++)
  172470. ;
  172471. lang++; /* skip NUL separator */
  172472. if (lang >= chunkdata + slength - 3)
  172473. {
  172474. png_warning(png_ptr, "Truncated iTXt chunk");
  172475. png_free(png_ptr, chunkdata);
  172476. return;
  172477. }
  172478. else
  172479. {
  172480. comp_flag = *lang++;
  172481. comp_type = *lang++;
  172482. }
  172483. for (lang_key = lang; *lang_key; lang_key++)
  172484. ;
  172485. lang_key++; /* skip NUL separator */
  172486. if (lang_key >= chunkdata + slength)
  172487. {
  172488. png_warning(png_ptr, "Truncated iTXt chunk");
  172489. png_free(png_ptr, chunkdata);
  172490. return;
  172491. }
  172492. for (text = lang_key; *text; text++)
  172493. ;
  172494. text++; /* skip NUL separator */
  172495. if (text >= chunkdata + slength)
  172496. {
  172497. png_warning(png_ptr, "Malformed iTXt chunk");
  172498. png_free(png_ptr, chunkdata);
  172499. return;
  172500. }
  172501. prefix_len = text - chunkdata;
  172502. key=chunkdata;
  172503. if (comp_flag)
  172504. chunkdata = png_decompress_chunk(png_ptr, comp_type, chunkdata,
  172505. (size_t)length, prefix_len, &data_len);
  172506. else
  172507. data_len=png_strlen(chunkdata + prefix_len);
  172508. text_ptr = (png_textp)png_malloc_warn(png_ptr,
  172509. (png_uint_32)png_sizeof(png_text));
  172510. if (text_ptr == NULL)
  172511. {
  172512. png_warning(png_ptr,"Not enough memory to process iTXt chunk.");
  172513. png_free(png_ptr, chunkdata);
  172514. return;
  172515. }
  172516. text_ptr->compression = (int)comp_flag + 1;
  172517. text_ptr->lang_key = chunkdata+(lang_key-key);
  172518. text_ptr->lang = chunkdata+(lang-key);
  172519. text_ptr->itxt_length = data_len;
  172520. text_ptr->text_length = 0;
  172521. text_ptr->key = chunkdata;
  172522. text_ptr->text = chunkdata + prefix_len;
  172523. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  172524. png_free(png_ptr, text_ptr);
  172525. png_free(png_ptr, chunkdata);
  172526. if (ret)
  172527. png_error(png_ptr, "Insufficient memory to store iTXt chunk.");
  172528. }
  172529. #endif
  172530. void /* PRIVATE */
  172531. png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172532. {
  172533. png_uint_32 skip = 0;
  172534. png_debug(1, "in png_handle_unknown\n");
  172535. if (png_ptr->mode & PNG_HAVE_IDAT)
  172536. {
  172537. #ifdef PNG_USE_LOCAL_ARRAYS
  172538. PNG_CONST PNG_IDAT;
  172539. #endif
  172540. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) /* not an IDAT */
  172541. png_ptr->mode |= PNG_AFTER_IDAT;
  172542. }
  172543. png_check_chunk_name(png_ptr, png_ptr->chunk_name);
  172544. if (!(png_ptr->chunk_name[0] & 0x20))
  172545. {
  172546. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  172547. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  172548. PNG_HANDLE_CHUNK_ALWAYS
  172549. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  172550. && png_ptr->read_user_chunk_fn == NULL
  172551. #endif
  172552. )
  172553. #endif
  172554. png_chunk_error(png_ptr, "unknown critical chunk");
  172555. }
  172556. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  172557. if ((png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS) ||
  172558. (png_ptr->read_user_chunk_fn != NULL))
  172559. {
  172560. #ifdef PNG_MAX_MALLOC_64K
  172561. if (length > (png_uint_32)65535L)
  172562. {
  172563. png_warning(png_ptr, "unknown chunk too large to fit in memory");
  172564. skip = length - (png_uint_32)65535L;
  172565. length = (png_uint_32)65535L;
  172566. }
  172567. #endif
  172568. png_strncpy((png_charp)png_ptr->unknown_chunk.name,
  172569. (png_charp)png_ptr->chunk_name, 5);
  172570. png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length);
  172571. png_ptr->unknown_chunk.size = (png_size_t)length;
  172572. png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
  172573. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  172574. if(png_ptr->read_user_chunk_fn != NULL)
  172575. {
  172576. int ret;
  172577. ret = (*(png_ptr->read_user_chunk_fn))
  172578. (png_ptr, &png_ptr->unknown_chunk);
  172579. if (ret < 0)
  172580. png_chunk_error(png_ptr, "error in user chunk");
  172581. if (ret == 0)
  172582. {
  172583. if (!(png_ptr->chunk_name[0] & 0x20))
  172584. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  172585. PNG_HANDLE_CHUNK_ALWAYS)
  172586. png_chunk_error(png_ptr, "unknown critical chunk");
  172587. png_set_unknown_chunks(png_ptr, info_ptr,
  172588. &png_ptr->unknown_chunk, 1);
  172589. }
  172590. }
  172591. #else
  172592. png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1);
  172593. #endif
  172594. png_free(png_ptr, png_ptr->unknown_chunk.data);
  172595. png_ptr->unknown_chunk.data = NULL;
  172596. }
  172597. else
  172598. #endif
  172599. skip = length;
  172600. png_crc_finish(png_ptr, skip);
  172601. #if !defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  172602. info_ptr = info_ptr; /* quiet compiler warnings about unused info_ptr */
  172603. #endif
  172604. }
  172605. #define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
  172606. void /* PRIVATE */
  172607. png_check_chunk_name(png_structp png_ptr, png_bytep chunk_name)
  172608. {
  172609. png_debug(1, "in png_check_chunk_name\n");
  172610. if (isnonalpha(chunk_name[0]) || isnonalpha(chunk_name[1]) ||
  172611. isnonalpha(chunk_name[2]) || isnonalpha(chunk_name[3]))
  172612. {
  172613. png_chunk_error(png_ptr, "invalid chunk type");
  172614. }
  172615. }
  172616. void /* PRIVATE */
  172617. png_combine_row(png_structp png_ptr, png_bytep row, int mask)
  172618. {
  172619. png_debug(1,"in png_combine_row\n");
  172620. if (mask == 0xff)
  172621. {
  172622. png_memcpy(row, png_ptr->row_buf + 1,
  172623. PNG_ROWBYTES(png_ptr->row_info.pixel_depth, png_ptr->width));
  172624. }
  172625. else
  172626. {
  172627. switch (png_ptr->row_info.pixel_depth)
  172628. {
  172629. case 1:
  172630. {
  172631. png_bytep sp = png_ptr->row_buf + 1;
  172632. png_bytep dp = row;
  172633. int s_inc, s_start, s_end;
  172634. int m = 0x80;
  172635. int shift;
  172636. png_uint_32 i;
  172637. png_uint_32 row_width = png_ptr->width;
  172638. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172639. if (png_ptr->transformations & PNG_PACKSWAP)
  172640. {
  172641. s_start = 0;
  172642. s_end = 7;
  172643. s_inc = 1;
  172644. }
  172645. else
  172646. #endif
  172647. {
  172648. s_start = 7;
  172649. s_end = 0;
  172650. s_inc = -1;
  172651. }
  172652. shift = s_start;
  172653. for (i = 0; i < row_width; i++)
  172654. {
  172655. if (m & mask)
  172656. {
  172657. int value;
  172658. value = (*sp >> shift) & 0x01;
  172659. *dp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff);
  172660. *dp |= (png_byte)(value << shift);
  172661. }
  172662. if (shift == s_end)
  172663. {
  172664. shift = s_start;
  172665. sp++;
  172666. dp++;
  172667. }
  172668. else
  172669. shift += s_inc;
  172670. if (m == 1)
  172671. m = 0x80;
  172672. else
  172673. m >>= 1;
  172674. }
  172675. break;
  172676. }
  172677. case 2:
  172678. {
  172679. png_bytep sp = png_ptr->row_buf + 1;
  172680. png_bytep dp = row;
  172681. int s_start, s_end, s_inc;
  172682. int m = 0x80;
  172683. int shift;
  172684. png_uint_32 i;
  172685. png_uint_32 row_width = png_ptr->width;
  172686. int value;
  172687. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172688. if (png_ptr->transformations & PNG_PACKSWAP)
  172689. {
  172690. s_start = 0;
  172691. s_end = 6;
  172692. s_inc = 2;
  172693. }
  172694. else
  172695. #endif
  172696. {
  172697. s_start = 6;
  172698. s_end = 0;
  172699. s_inc = -2;
  172700. }
  172701. shift = s_start;
  172702. for (i = 0; i < row_width; i++)
  172703. {
  172704. if (m & mask)
  172705. {
  172706. value = (*sp >> shift) & 0x03;
  172707. *dp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  172708. *dp |= (png_byte)(value << shift);
  172709. }
  172710. if (shift == s_end)
  172711. {
  172712. shift = s_start;
  172713. sp++;
  172714. dp++;
  172715. }
  172716. else
  172717. shift += s_inc;
  172718. if (m == 1)
  172719. m = 0x80;
  172720. else
  172721. m >>= 1;
  172722. }
  172723. break;
  172724. }
  172725. case 4:
  172726. {
  172727. png_bytep sp = png_ptr->row_buf + 1;
  172728. png_bytep dp = row;
  172729. int s_start, s_end, s_inc;
  172730. int m = 0x80;
  172731. int shift;
  172732. png_uint_32 i;
  172733. png_uint_32 row_width = png_ptr->width;
  172734. int value;
  172735. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172736. if (png_ptr->transformations & PNG_PACKSWAP)
  172737. {
  172738. s_start = 0;
  172739. s_end = 4;
  172740. s_inc = 4;
  172741. }
  172742. else
  172743. #endif
  172744. {
  172745. s_start = 4;
  172746. s_end = 0;
  172747. s_inc = -4;
  172748. }
  172749. shift = s_start;
  172750. for (i = 0; i < row_width; i++)
  172751. {
  172752. if (m & mask)
  172753. {
  172754. value = (*sp >> shift) & 0xf;
  172755. *dp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  172756. *dp |= (png_byte)(value << shift);
  172757. }
  172758. if (shift == s_end)
  172759. {
  172760. shift = s_start;
  172761. sp++;
  172762. dp++;
  172763. }
  172764. else
  172765. shift += s_inc;
  172766. if (m == 1)
  172767. m = 0x80;
  172768. else
  172769. m >>= 1;
  172770. }
  172771. break;
  172772. }
  172773. default:
  172774. {
  172775. png_bytep sp = png_ptr->row_buf + 1;
  172776. png_bytep dp = row;
  172777. png_size_t pixel_bytes = (png_ptr->row_info.pixel_depth >> 3);
  172778. png_uint_32 i;
  172779. png_uint_32 row_width = png_ptr->width;
  172780. png_byte m = 0x80;
  172781. for (i = 0; i < row_width; i++)
  172782. {
  172783. if (m & mask)
  172784. {
  172785. png_memcpy(dp, sp, pixel_bytes);
  172786. }
  172787. sp += pixel_bytes;
  172788. dp += pixel_bytes;
  172789. if (m == 1)
  172790. m = 0x80;
  172791. else
  172792. m >>= 1;
  172793. }
  172794. break;
  172795. }
  172796. }
  172797. }
  172798. }
  172799. #ifdef PNG_READ_INTERLACING_SUPPORTED
  172800. void /* PRIVATE */
  172801. png_do_read_interlace(png_structp png_ptr)
  172802. {
  172803. png_row_infop row_info = &(png_ptr->row_info);
  172804. png_bytep row = png_ptr->row_buf + 1;
  172805. int pass = png_ptr->pass;
  172806. png_uint_32 transformations = png_ptr->transformations;
  172807. #ifdef PNG_USE_LOCAL_ARRAYS
  172808. PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  172809. #endif
  172810. png_debug(1,"in png_do_read_interlace\n");
  172811. if (row != NULL && row_info != NULL)
  172812. {
  172813. png_uint_32 final_width;
  172814. final_width = row_info->width * png_pass_inc[pass];
  172815. switch (row_info->pixel_depth)
  172816. {
  172817. case 1:
  172818. {
  172819. png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 3);
  172820. png_bytep dp = row + (png_size_t)((final_width - 1) >> 3);
  172821. int sshift, dshift;
  172822. int s_start, s_end, s_inc;
  172823. int jstop = png_pass_inc[pass];
  172824. png_byte v;
  172825. png_uint_32 i;
  172826. int j;
  172827. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172828. if (transformations & PNG_PACKSWAP)
  172829. {
  172830. sshift = (int)((row_info->width + 7) & 0x07);
  172831. dshift = (int)((final_width + 7) & 0x07);
  172832. s_start = 7;
  172833. s_end = 0;
  172834. s_inc = -1;
  172835. }
  172836. else
  172837. #endif
  172838. {
  172839. sshift = 7 - (int)((row_info->width + 7) & 0x07);
  172840. dshift = 7 - (int)((final_width + 7) & 0x07);
  172841. s_start = 0;
  172842. s_end = 7;
  172843. s_inc = 1;
  172844. }
  172845. for (i = 0; i < row_info->width; i++)
  172846. {
  172847. v = (png_byte)((*sp >> sshift) & 0x01);
  172848. for (j = 0; j < jstop; j++)
  172849. {
  172850. *dp &= (png_byte)((0x7f7f >> (7 - dshift)) & 0xff);
  172851. *dp |= (png_byte)(v << dshift);
  172852. if (dshift == s_end)
  172853. {
  172854. dshift = s_start;
  172855. dp--;
  172856. }
  172857. else
  172858. dshift += s_inc;
  172859. }
  172860. if (sshift == s_end)
  172861. {
  172862. sshift = s_start;
  172863. sp--;
  172864. }
  172865. else
  172866. sshift += s_inc;
  172867. }
  172868. break;
  172869. }
  172870. case 2:
  172871. {
  172872. png_bytep sp = row + (png_uint_32)((row_info->width - 1) >> 2);
  172873. png_bytep dp = row + (png_uint_32)((final_width - 1) >> 2);
  172874. int sshift, dshift;
  172875. int s_start, s_end, s_inc;
  172876. int jstop = png_pass_inc[pass];
  172877. png_uint_32 i;
  172878. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172879. if (transformations & PNG_PACKSWAP)
  172880. {
  172881. sshift = (int)(((row_info->width + 3) & 0x03) << 1);
  172882. dshift = (int)(((final_width + 3) & 0x03) << 1);
  172883. s_start = 6;
  172884. s_end = 0;
  172885. s_inc = -2;
  172886. }
  172887. else
  172888. #endif
  172889. {
  172890. sshift = (int)((3 - ((row_info->width + 3) & 0x03)) << 1);
  172891. dshift = (int)((3 - ((final_width + 3) & 0x03)) << 1);
  172892. s_start = 0;
  172893. s_end = 6;
  172894. s_inc = 2;
  172895. }
  172896. for (i = 0; i < row_info->width; i++)
  172897. {
  172898. png_byte v;
  172899. int j;
  172900. v = (png_byte)((*sp >> sshift) & 0x03);
  172901. for (j = 0; j < jstop; j++)
  172902. {
  172903. *dp &= (png_byte)((0x3f3f >> (6 - dshift)) & 0xff);
  172904. *dp |= (png_byte)(v << dshift);
  172905. if (dshift == s_end)
  172906. {
  172907. dshift = s_start;
  172908. dp--;
  172909. }
  172910. else
  172911. dshift += s_inc;
  172912. }
  172913. if (sshift == s_end)
  172914. {
  172915. sshift = s_start;
  172916. sp--;
  172917. }
  172918. else
  172919. sshift += s_inc;
  172920. }
  172921. break;
  172922. }
  172923. case 4:
  172924. {
  172925. png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 1);
  172926. png_bytep dp = row + (png_size_t)((final_width - 1) >> 1);
  172927. int sshift, dshift;
  172928. int s_start, s_end, s_inc;
  172929. png_uint_32 i;
  172930. int jstop = png_pass_inc[pass];
  172931. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172932. if (transformations & PNG_PACKSWAP)
  172933. {
  172934. sshift = (int)(((row_info->width + 1) & 0x01) << 2);
  172935. dshift = (int)(((final_width + 1) & 0x01) << 2);
  172936. s_start = 4;
  172937. s_end = 0;
  172938. s_inc = -4;
  172939. }
  172940. else
  172941. #endif
  172942. {
  172943. sshift = (int)((1 - ((row_info->width + 1) & 0x01)) << 2);
  172944. dshift = (int)((1 - ((final_width + 1) & 0x01)) << 2);
  172945. s_start = 0;
  172946. s_end = 4;
  172947. s_inc = 4;
  172948. }
  172949. for (i = 0; i < row_info->width; i++)
  172950. {
  172951. png_byte v = (png_byte)((*sp >> sshift) & 0xf);
  172952. int j;
  172953. for (j = 0; j < jstop; j++)
  172954. {
  172955. *dp &= (png_byte)((0xf0f >> (4 - dshift)) & 0xff);
  172956. *dp |= (png_byte)(v << dshift);
  172957. if (dshift == s_end)
  172958. {
  172959. dshift = s_start;
  172960. dp--;
  172961. }
  172962. else
  172963. dshift += s_inc;
  172964. }
  172965. if (sshift == s_end)
  172966. {
  172967. sshift = s_start;
  172968. sp--;
  172969. }
  172970. else
  172971. sshift += s_inc;
  172972. }
  172973. break;
  172974. }
  172975. default:
  172976. {
  172977. png_size_t pixel_bytes = (row_info->pixel_depth >> 3);
  172978. png_bytep sp = row + (png_size_t)(row_info->width - 1) * pixel_bytes;
  172979. png_bytep dp = row + (png_size_t)(final_width - 1) * pixel_bytes;
  172980. int jstop = png_pass_inc[pass];
  172981. png_uint_32 i;
  172982. for (i = 0; i < row_info->width; i++)
  172983. {
  172984. png_byte v[8];
  172985. int j;
  172986. png_memcpy(v, sp, pixel_bytes);
  172987. for (j = 0; j < jstop; j++)
  172988. {
  172989. png_memcpy(dp, v, pixel_bytes);
  172990. dp -= pixel_bytes;
  172991. }
  172992. sp -= pixel_bytes;
  172993. }
  172994. break;
  172995. }
  172996. }
  172997. row_info->width = final_width;
  172998. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,final_width);
  172999. }
  173000. #if !defined(PNG_READ_PACKSWAP_SUPPORTED)
  173001. transformations = transformations; /* silence compiler warning */
  173002. #endif
  173003. }
  173004. #endif /* PNG_READ_INTERLACING_SUPPORTED */
  173005. void /* PRIVATE */
  173006. png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep row,
  173007. png_bytep prev_row, int filter)
  173008. {
  173009. png_debug(1, "in png_read_filter_row\n");
  173010. png_debug2(2,"row = %lu, filter = %d\n", png_ptr->row_number, filter);
  173011. switch (filter)
  173012. {
  173013. case PNG_FILTER_VALUE_NONE:
  173014. break;
  173015. case PNG_FILTER_VALUE_SUB:
  173016. {
  173017. png_uint_32 i;
  173018. png_uint_32 istop = row_info->rowbytes;
  173019. png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
  173020. png_bytep rp = row + bpp;
  173021. png_bytep lp = row;
  173022. for (i = bpp; i < istop; i++)
  173023. {
  173024. *rp = (png_byte)(((int)(*rp) + (int)(*lp++)) & 0xff);
  173025. rp++;
  173026. }
  173027. break;
  173028. }
  173029. case PNG_FILTER_VALUE_UP:
  173030. {
  173031. png_uint_32 i;
  173032. png_uint_32 istop = row_info->rowbytes;
  173033. png_bytep rp = row;
  173034. png_bytep pp = prev_row;
  173035. for (i = 0; i < istop; i++)
  173036. {
  173037. *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
  173038. rp++;
  173039. }
  173040. break;
  173041. }
  173042. case PNG_FILTER_VALUE_AVG:
  173043. {
  173044. png_uint_32 i;
  173045. png_bytep rp = row;
  173046. png_bytep pp = prev_row;
  173047. png_bytep lp = row;
  173048. png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
  173049. png_uint_32 istop = row_info->rowbytes - bpp;
  173050. for (i = 0; i < bpp; i++)
  173051. {
  173052. *rp = (png_byte)(((int)(*rp) +
  173053. ((int)(*pp++) / 2 )) & 0xff);
  173054. rp++;
  173055. }
  173056. for (i = 0; i < istop; i++)
  173057. {
  173058. *rp = (png_byte)(((int)(*rp) +
  173059. (int)(*pp++ + *lp++) / 2 ) & 0xff);
  173060. rp++;
  173061. }
  173062. break;
  173063. }
  173064. case PNG_FILTER_VALUE_PAETH:
  173065. {
  173066. png_uint_32 i;
  173067. png_bytep rp = row;
  173068. png_bytep pp = prev_row;
  173069. png_bytep lp = row;
  173070. png_bytep cp = prev_row;
  173071. png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
  173072. png_uint_32 istop=row_info->rowbytes - bpp;
  173073. for (i = 0; i < bpp; i++)
  173074. {
  173075. *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
  173076. rp++;
  173077. }
  173078. for (i = 0; i < istop; i++) /* use leftover rp,pp */
  173079. {
  173080. int a, b, c, pa, pb, pc, p;
  173081. a = *lp++;
  173082. b = *pp++;
  173083. c = *cp++;
  173084. p = b - c;
  173085. pc = a - c;
  173086. #ifdef PNG_USE_ABS
  173087. pa = abs(p);
  173088. pb = abs(pc);
  173089. pc = abs(p + pc);
  173090. #else
  173091. pa = p < 0 ? -p : p;
  173092. pb = pc < 0 ? -pc : pc;
  173093. pc = (p + pc) < 0 ? -(p + pc) : p + pc;
  173094. #endif
  173095. p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
  173096. *rp = (png_byte)(((int)(*rp) + p) & 0xff);
  173097. rp++;
  173098. }
  173099. break;
  173100. }
  173101. default:
  173102. png_warning(png_ptr, "Ignoring bad adaptive filter type");
  173103. *row=0;
  173104. break;
  173105. }
  173106. }
  173107. void /* PRIVATE */
  173108. png_read_finish_row(png_structp png_ptr)
  173109. {
  173110. #ifdef PNG_USE_LOCAL_ARRAYS
  173111. PNG_CONST int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  173112. PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  173113. PNG_CONST int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  173114. PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  173115. #endif
  173116. png_debug(1, "in png_read_finish_row\n");
  173117. png_ptr->row_number++;
  173118. if (png_ptr->row_number < png_ptr->num_rows)
  173119. return;
  173120. if (png_ptr->interlaced)
  173121. {
  173122. png_ptr->row_number = 0;
  173123. png_memset_check(png_ptr, png_ptr->prev_row, 0,
  173124. png_ptr->rowbytes + 1);
  173125. do
  173126. {
  173127. png_ptr->pass++;
  173128. if (png_ptr->pass >= 7)
  173129. break;
  173130. png_ptr->iwidth = (png_ptr->width +
  173131. png_pass_inc[png_ptr->pass] - 1 -
  173132. png_pass_start[png_ptr->pass]) /
  173133. png_pass_inc[png_ptr->pass];
  173134. png_ptr->irowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,
  173135. png_ptr->iwidth) + 1;
  173136. if (!(png_ptr->transformations & PNG_INTERLACE))
  173137. {
  173138. png_ptr->num_rows = (png_ptr->height +
  173139. png_pass_yinc[png_ptr->pass] - 1 -
  173140. png_pass_ystart[png_ptr->pass]) /
  173141. png_pass_yinc[png_ptr->pass];
  173142. if (!(png_ptr->num_rows))
  173143. continue;
  173144. }
  173145. else /* if (png_ptr->transformations & PNG_INTERLACE) */
  173146. break;
  173147. } while (png_ptr->iwidth == 0);
  173148. if (png_ptr->pass < 7)
  173149. return;
  173150. }
  173151. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  173152. {
  173153. #ifdef PNG_USE_LOCAL_ARRAYS
  173154. PNG_CONST PNG_IDAT;
  173155. #endif
  173156. char extra;
  173157. int ret;
  173158. png_ptr->zstream.next_out = (Bytef *)&extra;
  173159. png_ptr->zstream.avail_out = (uInt)1;
  173160. for(;;)
  173161. {
  173162. if (!(png_ptr->zstream.avail_in))
  173163. {
  173164. while (!png_ptr->idat_size)
  173165. {
  173166. png_byte chunk_length[4];
  173167. png_crc_finish(png_ptr, 0);
  173168. png_read_data(png_ptr, chunk_length, 4);
  173169. png_ptr->idat_size = png_get_uint_31(png_ptr, chunk_length);
  173170. png_reset_crc(png_ptr);
  173171. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  173172. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  173173. png_error(png_ptr, "Not enough image data");
  173174. }
  173175. png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size;
  173176. png_ptr->zstream.next_in = png_ptr->zbuf;
  173177. if (png_ptr->zbuf_size > png_ptr->idat_size)
  173178. png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size;
  173179. png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zstream.avail_in);
  173180. png_ptr->idat_size -= png_ptr->zstream.avail_in;
  173181. }
  173182. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  173183. if (ret == Z_STREAM_END)
  173184. {
  173185. if (!(png_ptr->zstream.avail_out) || png_ptr->zstream.avail_in ||
  173186. png_ptr->idat_size)
  173187. png_warning(png_ptr, "Extra compressed data");
  173188. png_ptr->mode |= PNG_AFTER_IDAT;
  173189. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  173190. break;
  173191. }
  173192. if (ret != Z_OK)
  173193. png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg :
  173194. "Decompression Error");
  173195. if (!(png_ptr->zstream.avail_out))
  173196. {
  173197. png_warning(png_ptr, "Extra compressed data.");
  173198. png_ptr->mode |= PNG_AFTER_IDAT;
  173199. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  173200. break;
  173201. }
  173202. }
  173203. png_ptr->zstream.avail_out = 0;
  173204. }
  173205. if (png_ptr->idat_size || png_ptr->zstream.avail_in)
  173206. png_warning(png_ptr, "Extra compression data");
  173207. inflateReset(&png_ptr->zstream);
  173208. png_ptr->mode |= PNG_AFTER_IDAT;
  173209. }
  173210. void /* PRIVATE */
  173211. png_read_start_row(png_structp png_ptr)
  173212. {
  173213. #ifdef PNG_USE_LOCAL_ARRAYS
  173214. PNG_CONST int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  173215. PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  173216. PNG_CONST int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  173217. PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  173218. #endif
  173219. int max_pixel_depth;
  173220. png_uint_32 row_bytes;
  173221. png_debug(1, "in png_read_start_row\n");
  173222. png_ptr->zstream.avail_in = 0;
  173223. png_init_read_transformations(png_ptr);
  173224. if (png_ptr->interlaced)
  173225. {
  173226. if (!(png_ptr->transformations & PNG_INTERLACE))
  173227. png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
  173228. png_pass_ystart[0]) / png_pass_yinc[0];
  173229. else
  173230. png_ptr->num_rows = png_ptr->height;
  173231. png_ptr->iwidth = (png_ptr->width +
  173232. png_pass_inc[png_ptr->pass] - 1 -
  173233. png_pass_start[png_ptr->pass]) /
  173234. png_pass_inc[png_ptr->pass];
  173235. row_bytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->iwidth) + 1;
  173236. png_ptr->irowbytes = (png_size_t)row_bytes;
  173237. if((png_uint_32)png_ptr->irowbytes != row_bytes)
  173238. png_error(png_ptr, "Rowbytes overflow in png_read_start_row");
  173239. }
  173240. else
  173241. {
  173242. png_ptr->num_rows = png_ptr->height;
  173243. png_ptr->iwidth = png_ptr->width;
  173244. png_ptr->irowbytes = png_ptr->rowbytes + 1;
  173245. }
  173246. max_pixel_depth = png_ptr->pixel_depth;
  173247. #if defined(PNG_READ_PACK_SUPPORTED)
  173248. if ((png_ptr->transformations & PNG_PACK) && png_ptr->bit_depth < 8)
  173249. max_pixel_depth = 8;
  173250. #endif
  173251. #if defined(PNG_READ_EXPAND_SUPPORTED)
  173252. if (png_ptr->transformations & PNG_EXPAND)
  173253. {
  173254. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173255. {
  173256. if (png_ptr->num_trans)
  173257. max_pixel_depth = 32;
  173258. else
  173259. max_pixel_depth = 24;
  173260. }
  173261. else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
  173262. {
  173263. if (max_pixel_depth < 8)
  173264. max_pixel_depth = 8;
  173265. if (png_ptr->num_trans)
  173266. max_pixel_depth *= 2;
  173267. }
  173268. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  173269. {
  173270. if (png_ptr->num_trans)
  173271. {
  173272. max_pixel_depth *= 4;
  173273. max_pixel_depth /= 3;
  173274. }
  173275. }
  173276. }
  173277. #endif
  173278. #if defined(PNG_READ_FILLER_SUPPORTED)
  173279. if (png_ptr->transformations & (PNG_FILLER))
  173280. {
  173281. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173282. max_pixel_depth = 32;
  173283. else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
  173284. {
  173285. if (max_pixel_depth <= 8)
  173286. max_pixel_depth = 16;
  173287. else
  173288. max_pixel_depth = 32;
  173289. }
  173290. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  173291. {
  173292. if (max_pixel_depth <= 32)
  173293. max_pixel_depth = 32;
  173294. else
  173295. max_pixel_depth = 64;
  173296. }
  173297. }
  173298. #endif
  173299. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  173300. if (png_ptr->transformations & PNG_GRAY_TO_RGB)
  173301. {
  173302. if (
  173303. #if defined(PNG_READ_EXPAND_SUPPORTED)
  173304. (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND)) ||
  173305. #endif
  173306. #if defined(PNG_READ_FILLER_SUPPORTED)
  173307. (png_ptr->transformations & (PNG_FILLER)) ||
  173308. #endif
  173309. png_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  173310. {
  173311. if (max_pixel_depth <= 16)
  173312. max_pixel_depth = 32;
  173313. else
  173314. max_pixel_depth = 64;
  173315. }
  173316. else
  173317. {
  173318. if (max_pixel_depth <= 8)
  173319. {
  173320. if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  173321. max_pixel_depth = 32;
  173322. else
  173323. max_pixel_depth = 24;
  173324. }
  173325. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  173326. max_pixel_depth = 64;
  173327. else
  173328. max_pixel_depth = 48;
  173329. }
  173330. }
  173331. #endif
  173332. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) && \
  173333. defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  173334. if(png_ptr->transformations & PNG_USER_TRANSFORM)
  173335. {
  173336. int user_pixel_depth=png_ptr->user_transform_depth*
  173337. png_ptr->user_transform_channels;
  173338. if(user_pixel_depth > max_pixel_depth)
  173339. max_pixel_depth=user_pixel_depth;
  173340. }
  173341. #endif
  173342. row_bytes = ((png_ptr->width + 7) & ~((png_uint_32)7));
  173343. row_bytes = PNG_ROWBYTES(max_pixel_depth,row_bytes) +
  173344. 1 + ((max_pixel_depth + 7) >> 3);
  173345. #ifdef PNG_MAX_MALLOC_64K
  173346. if (row_bytes > (png_uint_32)65536L)
  173347. png_error(png_ptr, "This image requires a row greater than 64KB");
  173348. #endif
  173349. png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr, row_bytes+64);
  173350. png_ptr->row_buf = png_ptr->big_row_buf+32;
  173351. #ifdef PNG_MAX_MALLOC_64K
  173352. if ((png_uint_32)png_ptr->rowbytes + 1 > (png_uint_32)65536L)
  173353. png_error(png_ptr, "This image requires a row greater than 64KB");
  173354. #endif
  173355. if ((png_uint_32)png_ptr->rowbytes > (png_uint_32)(PNG_SIZE_MAX - 1))
  173356. png_error(png_ptr, "Row has too many bytes to allocate in memory.");
  173357. png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)(
  173358. png_ptr->rowbytes + 1));
  173359. png_memset_check(png_ptr, png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
  173360. png_debug1(3, "width = %lu,\n", png_ptr->width);
  173361. png_debug1(3, "height = %lu,\n", png_ptr->height);
  173362. png_debug1(3, "iwidth = %lu,\n", png_ptr->iwidth);
  173363. png_debug1(3, "num_rows = %lu\n", png_ptr->num_rows);
  173364. png_debug1(3, "rowbytes = %lu,\n", png_ptr->rowbytes);
  173365. png_debug1(3, "irowbytes = %lu,\n", png_ptr->irowbytes);
  173366. png_ptr->flags |= PNG_FLAG_ROW_INIT;
  173367. }
  173368. #endif /* PNG_READ_SUPPORTED */
  173369. /*** End of inlined file: pngrutil.c ***/
  173370. /*** Start of inlined file: pngset.c ***/
  173371. #define PNG_INTERNAL
  173372. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  173373. #if defined(PNG_bKGD_SUPPORTED)
  173374. void PNGAPI
  173375. png_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p background)
  173376. {
  173377. png_debug1(1, "in %s storage function\n", "bKGD");
  173378. if (png_ptr == NULL || info_ptr == NULL)
  173379. return;
  173380. png_memcpy(&(info_ptr->background), background, png_sizeof(png_color_16));
  173381. info_ptr->valid |= PNG_INFO_bKGD;
  173382. }
  173383. #endif
  173384. #if defined(PNG_cHRM_SUPPORTED)
  173385. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173386. void PNGAPI
  173387. png_set_cHRM(png_structp png_ptr, png_infop info_ptr,
  173388. double white_x, double white_y, double red_x, double red_y,
  173389. double green_x, double green_y, double blue_x, double blue_y)
  173390. {
  173391. png_debug1(1, "in %s storage function\n", "cHRM");
  173392. if (png_ptr == NULL || info_ptr == NULL)
  173393. return;
  173394. if (white_x < 0.0 || white_y < 0.0 ||
  173395. red_x < 0.0 || red_y < 0.0 ||
  173396. green_x < 0.0 || green_y < 0.0 ||
  173397. blue_x < 0.0 || blue_y < 0.0)
  173398. {
  173399. png_warning(png_ptr,
  173400. "Ignoring attempt to set negative chromaticity value");
  173401. return;
  173402. }
  173403. if (white_x > 21474.83 || white_y > 21474.83 ||
  173404. red_x > 21474.83 || red_y > 21474.83 ||
  173405. green_x > 21474.83 || green_y > 21474.83 ||
  173406. blue_x > 21474.83 || blue_y > 21474.83)
  173407. {
  173408. png_warning(png_ptr,
  173409. "Ignoring attempt to set chromaticity value exceeding 21474.83");
  173410. return;
  173411. }
  173412. info_ptr->x_white = (float)white_x;
  173413. info_ptr->y_white = (float)white_y;
  173414. info_ptr->x_red = (float)red_x;
  173415. info_ptr->y_red = (float)red_y;
  173416. info_ptr->x_green = (float)green_x;
  173417. info_ptr->y_green = (float)green_y;
  173418. info_ptr->x_blue = (float)blue_x;
  173419. info_ptr->y_blue = (float)blue_y;
  173420. #ifdef PNG_FIXED_POINT_SUPPORTED
  173421. info_ptr->int_x_white = (png_fixed_point)(white_x*100000.+0.5);
  173422. info_ptr->int_y_white = (png_fixed_point)(white_y*100000.+0.5);
  173423. info_ptr->int_x_red = (png_fixed_point)( red_x*100000.+0.5);
  173424. info_ptr->int_y_red = (png_fixed_point)( red_y*100000.+0.5);
  173425. info_ptr->int_x_green = (png_fixed_point)(green_x*100000.+0.5);
  173426. info_ptr->int_y_green = (png_fixed_point)(green_y*100000.+0.5);
  173427. info_ptr->int_x_blue = (png_fixed_point)( blue_x*100000.+0.5);
  173428. info_ptr->int_y_blue = (png_fixed_point)( blue_y*100000.+0.5);
  173429. #endif
  173430. info_ptr->valid |= PNG_INFO_cHRM;
  173431. }
  173432. #endif
  173433. #ifdef PNG_FIXED_POINT_SUPPORTED
  173434. void PNGAPI
  173435. png_set_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
  173436. png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x,
  173437. png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y,
  173438. png_fixed_point blue_x, png_fixed_point blue_y)
  173439. {
  173440. png_debug1(1, "in %s storage function\n", "cHRM");
  173441. if (png_ptr == NULL || info_ptr == NULL)
  173442. return;
  173443. if (white_x < 0 || white_y < 0 ||
  173444. red_x < 0 || red_y < 0 ||
  173445. green_x < 0 || green_y < 0 ||
  173446. blue_x < 0 || blue_y < 0)
  173447. {
  173448. png_warning(png_ptr,
  173449. "Ignoring attempt to set negative chromaticity value");
  173450. return;
  173451. }
  173452. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173453. if (white_x > (double) PNG_UINT_31_MAX ||
  173454. white_y > (double) PNG_UINT_31_MAX ||
  173455. red_x > (double) PNG_UINT_31_MAX ||
  173456. red_y > (double) PNG_UINT_31_MAX ||
  173457. green_x > (double) PNG_UINT_31_MAX ||
  173458. green_y > (double) PNG_UINT_31_MAX ||
  173459. blue_x > (double) PNG_UINT_31_MAX ||
  173460. blue_y > (double) PNG_UINT_31_MAX)
  173461. #else
  173462. if (white_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173463. white_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173464. red_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173465. red_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173466. green_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173467. green_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173468. blue_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173469. blue_y > (png_fixed_point) PNG_UINT_31_MAX/100000L)
  173470. #endif
  173471. {
  173472. png_warning(png_ptr,
  173473. "Ignoring attempt to set chromaticity value exceeding 21474.83");
  173474. return;
  173475. }
  173476. info_ptr->int_x_white = white_x;
  173477. info_ptr->int_y_white = white_y;
  173478. info_ptr->int_x_red = red_x;
  173479. info_ptr->int_y_red = red_y;
  173480. info_ptr->int_x_green = green_x;
  173481. info_ptr->int_y_green = green_y;
  173482. info_ptr->int_x_blue = blue_x;
  173483. info_ptr->int_y_blue = blue_y;
  173484. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173485. info_ptr->x_white = (float)(white_x/100000.);
  173486. info_ptr->y_white = (float)(white_y/100000.);
  173487. info_ptr->x_red = (float)( red_x/100000.);
  173488. info_ptr->y_red = (float)( red_y/100000.);
  173489. info_ptr->x_green = (float)(green_x/100000.);
  173490. info_ptr->y_green = (float)(green_y/100000.);
  173491. info_ptr->x_blue = (float)( blue_x/100000.);
  173492. info_ptr->y_blue = (float)( blue_y/100000.);
  173493. #endif
  173494. info_ptr->valid |= PNG_INFO_cHRM;
  173495. }
  173496. #endif
  173497. #endif
  173498. #if defined(PNG_gAMA_SUPPORTED)
  173499. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173500. void PNGAPI
  173501. png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma)
  173502. {
  173503. double gamma;
  173504. png_debug1(1, "in %s storage function\n", "gAMA");
  173505. if (png_ptr == NULL || info_ptr == NULL)
  173506. return;
  173507. if (file_gamma > 21474.83)
  173508. {
  173509. png_warning(png_ptr, "Limiting gamma to 21474.83");
  173510. gamma=21474.83;
  173511. }
  173512. else
  173513. gamma=file_gamma;
  173514. info_ptr->gamma = (float)gamma;
  173515. #ifdef PNG_FIXED_POINT_SUPPORTED
  173516. info_ptr->int_gamma = (int)(gamma*100000.+.5);
  173517. #endif
  173518. info_ptr->valid |= PNG_INFO_gAMA;
  173519. if(gamma == 0.0)
  173520. png_warning(png_ptr, "Setting gamma=0");
  173521. }
  173522. #endif
  173523. void PNGAPI
  173524. png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point
  173525. int_gamma)
  173526. {
  173527. png_fixed_point gamma;
  173528. png_debug1(1, "in %s storage function\n", "gAMA");
  173529. if (png_ptr == NULL || info_ptr == NULL)
  173530. return;
  173531. if (int_gamma > (png_fixed_point) PNG_UINT_31_MAX)
  173532. {
  173533. png_warning(png_ptr, "Limiting gamma to 21474.83");
  173534. gamma=PNG_UINT_31_MAX;
  173535. }
  173536. else
  173537. {
  173538. if (int_gamma < 0)
  173539. {
  173540. png_warning(png_ptr, "Setting negative gamma to zero");
  173541. gamma=0;
  173542. }
  173543. else
  173544. gamma=int_gamma;
  173545. }
  173546. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173547. info_ptr->gamma = (float)(gamma/100000.);
  173548. #endif
  173549. #ifdef PNG_FIXED_POINT_SUPPORTED
  173550. info_ptr->int_gamma = gamma;
  173551. #endif
  173552. info_ptr->valid |= PNG_INFO_gAMA;
  173553. if(gamma == 0)
  173554. png_warning(png_ptr, "Setting gamma=0");
  173555. }
  173556. #endif
  173557. #if defined(PNG_hIST_SUPPORTED)
  173558. void PNGAPI
  173559. png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist)
  173560. {
  173561. int i;
  173562. png_debug1(1, "in %s storage function\n", "hIST");
  173563. if (png_ptr == NULL || info_ptr == NULL)
  173564. return;
  173565. if (info_ptr->num_palette == 0 || info_ptr->num_palette
  173566. > PNG_MAX_PALETTE_LENGTH)
  173567. {
  173568. png_warning(png_ptr,
  173569. "Invalid palette size, hIST allocation skipped.");
  173570. return;
  173571. }
  173572. #ifdef PNG_FREE_ME_SUPPORTED
  173573. png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0);
  173574. #endif
  173575. png_ptr->hist = (png_uint_16p)png_malloc_warn(png_ptr,
  173576. (png_uint_32)(PNG_MAX_PALETTE_LENGTH * png_sizeof (png_uint_16)));
  173577. if (png_ptr->hist == NULL)
  173578. {
  173579. png_warning(png_ptr, "Insufficient memory for hIST chunk data.");
  173580. return;
  173581. }
  173582. for (i = 0; i < info_ptr->num_palette; i++)
  173583. png_ptr->hist[i] = hist[i];
  173584. info_ptr->hist = png_ptr->hist;
  173585. info_ptr->valid |= PNG_INFO_hIST;
  173586. #ifdef PNG_FREE_ME_SUPPORTED
  173587. info_ptr->free_me |= PNG_FREE_HIST;
  173588. #else
  173589. png_ptr->flags |= PNG_FLAG_FREE_HIST;
  173590. #endif
  173591. }
  173592. #endif
  173593. void PNGAPI
  173594. png_set_IHDR(png_structp png_ptr, png_infop info_ptr,
  173595. png_uint_32 width, png_uint_32 height, int bit_depth,
  173596. int color_type, int interlace_type, int compression_type,
  173597. int filter_type)
  173598. {
  173599. png_debug1(1, "in %s storage function\n", "IHDR");
  173600. if (png_ptr == NULL || info_ptr == NULL)
  173601. return;
  173602. if (width == 0 || height == 0)
  173603. png_error(png_ptr, "Image width or height is zero in IHDR");
  173604. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  173605. if (width > png_ptr->user_width_max || height > png_ptr->user_height_max)
  173606. png_error(png_ptr, "image size exceeds user limits in IHDR");
  173607. #else
  173608. if (width > PNG_USER_WIDTH_MAX || height > PNG_USER_HEIGHT_MAX)
  173609. png_error(png_ptr, "image size exceeds user limits in IHDR");
  173610. #endif
  173611. if (width > PNG_UINT_31_MAX || height > PNG_UINT_31_MAX)
  173612. png_error(png_ptr, "Invalid image size in IHDR");
  173613. if ( width > (PNG_UINT_32_MAX
  173614. >> 3) /* 8-byte RGBA pixels */
  173615. - 64 /* bigrowbuf hack */
  173616. - 1 /* filter byte */
  173617. - 7*8 /* rounding of width to multiple of 8 pixels */
  173618. - 8) /* extra max_pixel_depth pad */
  173619. png_warning(png_ptr, "Width is too large for libpng to process pixels");
  173620. if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 &&
  173621. bit_depth != 8 && bit_depth != 16)
  173622. png_error(png_ptr, "Invalid bit depth in IHDR");
  173623. if (color_type < 0 || color_type == 1 ||
  173624. color_type == 5 || color_type > 6)
  173625. png_error(png_ptr, "Invalid color type in IHDR");
  173626. if (((color_type == PNG_COLOR_TYPE_PALETTE) && bit_depth > 8) ||
  173627. ((color_type == PNG_COLOR_TYPE_RGB ||
  173628. color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
  173629. color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8))
  173630. png_error(png_ptr, "Invalid color type/bit depth combination in IHDR");
  173631. if (interlace_type >= PNG_INTERLACE_LAST)
  173632. png_error(png_ptr, "Unknown interlace method in IHDR");
  173633. if (compression_type != PNG_COMPRESSION_TYPE_BASE)
  173634. png_error(png_ptr, "Unknown compression method in IHDR");
  173635. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  173636. if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&png_ptr->mng_features_permitted)
  173637. png_warning(png_ptr,"MNG features are not allowed in a PNG datastream");
  173638. if(filter_type != PNG_FILTER_TYPE_BASE)
  173639. {
  173640. if(!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  173641. (filter_type == PNG_INTRAPIXEL_DIFFERENCING) &&
  173642. ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
  173643. (color_type == PNG_COLOR_TYPE_RGB ||
  173644. color_type == PNG_COLOR_TYPE_RGB_ALPHA)))
  173645. png_error(png_ptr, "Unknown filter method in IHDR");
  173646. if(png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)
  173647. png_warning(png_ptr, "Invalid filter method in IHDR");
  173648. }
  173649. #else
  173650. if(filter_type != PNG_FILTER_TYPE_BASE)
  173651. png_error(png_ptr, "Unknown filter method in IHDR");
  173652. #endif
  173653. info_ptr->width = width;
  173654. info_ptr->height = height;
  173655. info_ptr->bit_depth = (png_byte)bit_depth;
  173656. info_ptr->color_type =(png_byte) color_type;
  173657. info_ptr->compression_type = (png_byte)compression_type;
  173658. info_ptr->filter_type = (png_byte)filter_type;
  173659. info_ptr->interlace_type = (png_byte)interlace_type;
  173660. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173661. info_ptr->channels = 1;
  173662. else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
  173663. info_ptr->channels = 3;
  173664. else
  173665. info_ptr->channels = 1;
  173666. if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
  173667. info_ptr->channels++;
  173668. info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth);
  173669. if (width > (PNG_UINT_32_MAX
  173670. >> 3) /* 8-byte RGBA pixels */
  173671. - 64 /* bigrowbuf hack */
  173672. - 1 /* filter byte */
  173673. - 7*8 /* rounding of width to multiple of 8 pixels */
  173674. - 8) /* extra max_pixel_depth pad */
  173675. info_ptr->rowbytes = (png_size_t)0;
  173676. else
  173677. info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth,width);
  173678. }
  173679. #if defined(PNG_oFFs_SUPPORTED)
  173680. void PNGAPI
  173681. png_set_oFFs(png_structp png_ptr, png_infop info_ptr,
  173682. png_int_32 offset_x, png_int_32 offset_y, int unit_type)
  173683. {
  173684. png_debug1(1, "in %s storage function\n", "oFFs");
  173685. if (png_ptr == NULL || info_ptr == NULL)
  173686. return;
  173687. info_ptr->x_offset = offset_x;
  173688. info_ptr->y_offset = offset_y;
  173689. info_ptr->offset_unit_type = (png_byte)unit_type;
  173690. info_ptr->valid |= PNG_INFO_oFFs;
  173691. }
  173692. #endif
  173693. #if defined(PNG_pCAL_SUPPORTED)
  173694. void PNGAPI
  173695. png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
  173696. png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams,
  173697. png_charp units, png_charpp params)
  173698. {
  173699. png_uint_32 length;
  173700. int i;
  173701. png_debug1(1, "in %s storage function\n", "pCAL");
  173702. if (png_ptr == NULL || info_ptr == NULL)
  173703. return;
  173704. length = png_strlen(purpose) + 1;
  173705. png_debug1(3, "allocating purpose for info (%lu bytes)\n", length);
  173706. info_ptr->pcal_purpose = (png_charp)png_malloc_warn(png_ptr, length);
  173707. if (info_ptr->pcal_purpose == NULL)
  173708. {
  173709. png_warning(png_ptr, "Insufficient memory for pCAL purpose.");
  173710. return;
  173711. }
  173712. png_memcpy(info_ptr->pcal_purpose, purpose, (png_size_t)length);
  173713. png_debug(3, "storing X0, X1, type, and nparams in info\n");
  173714. info_ptr->pcal_X0 = X0;
  173715. info_ptr->pcal_X1 = X1;
  173716. info_ptr->pcal_type = (png_byte)type;
  173717. info_ptr->pcal_nparams = (png_byte)nparams;
  173718. length = png_strlen(units) + 1;
  173719. png_debug1(3, "allocating units for info (%lu bytes)\n", length);
  173720. info_ptr->pcal_units = (png_charp)png_malloc_warn(png_ptr, length);
  173721. if (info_ptr->pcal_units == NULL)
  173722. {
  173723. png_warning(png_ptr, "Insufficient memory for pCAL units.");
  173724. return;
  173725. }
  173726. png_memcpy(info_ptr->pcal_units, units, (png_size_t)length);
  173727. info_ptr->pcal_params = (png_charpp)png_malloc_warn(png_ptr,
  173728. (png_uint_32)((nparams + 1) * png_sizeof(png_charp)));
  173729. if (info_ptr->pcal_params == NULL)
  173730. {
  173731. png_warning(png_ptr, "Insufficient memory for pCAL params.");
  173732. return;
  173733. }
  173734. info_ptr->pcal_params[nparams] = NULL;
  173735. for (i = 0; i < nparams; i++)
  173736. {
  173737. length = png_strlen(params[i]) + 1;
  173738. png_debug2(3, "allocating parameter %d for info (%lu bytes)\n", i, length);
  173739. info_ptr->pcal_params[i] = (png_charp)png_malloc_warn(png_ptr, length);
  173740. if (info_ptr->pcal_params[i] == NULL)
  173741. {
  173742. png_warning(png_ptr, "Insufficient memory for pCAL parameter.");
  173743. return;
  173744. }
  173745. png_memcpy(info_ptr->pcal_params[i], params[i], (png_size_t)length);
  173746. }
  173747. info_ptr->valid |= PNG_INFO_pCAL;
  173748. #ifdef PNG_FREE_ME_SUPPORTED
  173749. info_ptr->free_me |= PNG_FREE_PCAL;
  173750. #endif
  173751. }
  173752. #endif
  173753. #if defined(PNG_READ_sCAL_SUPPORTED) || defined(PNG_WRITE_sCAL_SUPPORTED)
  173754. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173755. void PNGAPI
  173756. png_set_sCAL(png_structp png_ptr, png_infop info_ptr,
  173757. int unit, double width, double height)
  173758. {
  173759. png_debug1(1, "in %s storage function\n", "sCAL");
  173760. if (png_ptr == NULL || info_ptr == NULL)
  173761. return;
  173762. info_ptr->scal_unit = (png_byte)unit;
  173763. info_ptr->scal_pixel_width = width;
  173764. info_ptr->scal_pixel_height = height;
  173765. info_ptr->valid |= PNG_INFO_sCAL;
  173766. }
  173767. #else
  173768. #ifdef PNG_FIXED_POINT_SUPPORTED
  173769. void PNGAPI
  173770. png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr,
  173771. int unit, png_charp swidth, png_charp sheight)
  173772. {
  173773. png_uint_32 length;
  173774. png_debug1(1, "in %s storage function\n", "sCAL");
  173775. if (png_ptr == NULL || info_ptr == NULL)
  173776. return;
  173777. info_ptr->scal_unit = (png_byte)unit;
  173778. length = png_strlen(swidth) + 1;
  173779. png_debug1(3, "allocating unit for info (%d bytes)\n", length);
  173780. info_ptr->scal_s_width = (png_charp)png_malloc_warn(png_ptr, length);
  173781. if (info_ptr->scal_s_width == NULL)
  173782. {
  173783. png_warning(png_ptr,
  173784. "Memory allocation failed while processing sCAL.");
  173785. }
  173786. png_memcpy(info_ptr->scal_s_width, swidth, (png_size_t)length);
  173787. length = png_strlen(sheight) + 1;
  173788. png_debug1(3, "allocating unit for info (%d bytes)\n", length);
  173789. info_ptr->scal_s_height = (png_charp)png_malloc_warn(png_ptr, length);
  173790. if (info_ptr->scal_s_height == NULL)
  173791. {
  173792. png_free (png_ptr, info_ptr->scal_s_width);
  173793. png_warning(png_ptr,
  173794. "Memory allocation failed while processing sCAL.");
  173795. }
  173796. png_memcpy(info_ptr->scal_s_height, sheight, (png_size_t)length);
  173797. info_ptr->valid |= PNG_INFO_sCAL;
  173798. #ifdef PNG_FREE_ME_SUPPORTED
  173799. info_ptr->free_me |= PNG_FREE_SCAL;
  173800. #endif
  173801. }
  173802. #endif
  173803. #endif
  173804. #endif
  173805. #if defined(PNG_pHYs_SUPPORTED)
  173806. void PNGAPI
  173807. png_set_pHYs(png_structp png_ptr, png_infop info_ptr,
  173808. png_uint_32 res_x, png_uint_32 res_y, int unit_type)
  173809. {
  173810. png_debug1(1, "in %s storage function\n", "pHYs");
  173811. if (png_ptr == NULL || info_ptr == NULL)
  173812. return;
  173813. info_ptr->x_pixels_per_unit = res_x;
  173814. info_ptr->y_pixels_per_unit = res_y;
  173815. info_ptr->phys_unit_type = (png_byte)unit_type;
  173816. info_ptr->valid |= PNG_INFO_pHYs;
  173817. }
  173818. #endif
  173819. void PNGAPI
  173820. png_set_PLTE(png_structp png_ptr, png_infop info_ptr,
  173821. png_colorp palette, int num_palette)
  173822. {
  173823. png_debug1(1, "in %s storage function\n", "PLTE");
  173824. if (png_ptr == NULL || info_ptr == NULL)
  173825. return;
  173826. if (num_palette < 0 || num_palette > PNG_MAX_PALETTE_LENGTH)
  173827. {
  173828. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173829. png_error(png_ptr, "Invalid palette length");
  173830. else
  173831. {
  173832. png_warning(png_ptr, "Invalid palette length");
  173833. return;
  173834. }
  173835. }
  173836. #ifdef PNG_FREE_ME_SUPPORTED
  173837. png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0);
  173838. #endif
  173839. png_ptr->palette = (png_colorp)png_malloc(png_ptr,
  173840. PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color));
  173841. png_memset(png_ptr->palette, 0, PNG_MAX_PALETTE_LENGTH *
  173842. png_sizeof(png_color));
  173843. png_memcpy(png_ptr->palette, palette, num_palette * png_sizeof (png_color));
  173844. info_ptr->palette = png_ptr->palette;
  173845. info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette;
  173846. #ifdef PNG_FREE_ME_SUPPORTED
  173847. info_ptr->free_me |= PNG_FREE_PLTE;
  173848. #else
  173849. png_ptr->flags |= PNG_FLAG_FREE_PLTE;
  173850. #endif
  173851. info_ptr->valid |= PNG_INFO_PLTE;
  173852. }
  173853. #if defined(PNG_sBIT_SUPPORTED)
  173854. void PNGAPI
  173855. png_set_sBIT(png_structp png_ptr, png_infop info_ptr,
  173856. png_color_8p sig_bit)
  173857. {
  173858. png_debug1(1, "in %s storage function\n", "sBIT");
  173859. if (png_ptr == NULL || info_ptr == NULL)
  173860. return;
  173861. png_memcpy(&(info_ptr->sig_bit), sig_bit, png_sizeof (png_color_8));
  173862. info_ptr->valid |= PNG_INFO_sBIT;
  173863. }
  173864. #endif
  173865. #if defined(PNG_sRGB_SUPPORTED)
  173866. void PNGAPI
  173867. png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int intent)
  173868. {
  173869. png_debug1(1, "in %s storage function\n", "sRGB");
  173870. if (png_ptr == NULL || info_ptr == NULL)
  173871. return;
  173872. info_ptr->srgb_intent = (png_byte)intent;
  173873. info_ptr->valid |= PNG_INFO_sRGB;
  173874. }
  173875. void PNGAPI
  173876. png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr,
  173877. int intent)
  173878. {
  173879. #if defined(PNG_gAMA_SUPPORTED)
  173880. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173881. float file_gamma;
  173882. #endif
  173883. #ifdef PNG_FIXED_POINT_SUPPORTED
  173884. png_fixed_point int_file_gamma;
  173885. #endif
  173886. #endif
  173887. #if defined(PNG_cHRM_SUPPORTED)
  173888. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173889. float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
  173890. #endif
  173891. #ifdef PNG_FIXED_POINT_SUPPORTED
  173892. png_fixed_point int_white_x, int_white_y, int_red_x, int_red_y, int_green_x,
  173893. int_green_y, int_blue_x, int_blue_y;
  173894. #endif
  173895. #endif
  173896. png_debug1(1, "in %s storage function\n", "sRGB_gAMA_and_cHRM");
  173897. if (png_ptr == NULL || info_ptr == NULL)
  173898. return;
  173899. png_set_sRGB(png_ptr, info_ptr, intent);
  173900. #if defined(PNG_gAMA_SUPPORTED)
  173901. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173902. file_gamma = (float).45455;
  173903. png_set_gAMA(png_ptr, info_ptr, file_gamma);
  173904. #endif
  173905. #ifdef PNG_FIXED_POINT_SUPPORTED
  173906. int_file_gamma = 45455L;
  173907. png_set_gAMA_fixed(png_ptr, info_ptr, int_file_gamma);
  173908. #endif
  173909. #endif
  173910. #if defined(PNG_cHRM_SUPPORTED)
  173911. #ifdef PNG_FIXED_POINT_SUPPORTED
  173912. int_white_x = 31270L;
  173913. int_white_y = 32900L;
  173914. int_red_x = 64000L;
  173915. int_red_y = 33000L;
  173916. int_green_x = 30000L;
  173917. int_green_y = 60000L;
  173918. int_blue_x = 15000L;
  173919. int_blue_y = 6000L;
  173920. png_set_cHRM_fixed(png_ptr, info_ptr,
  173921. int_white_x, int_white_y, int_red_x, int_red_y, int_green_x, int_green_y,
  173922. int_blue_x, int_blue_y);
  173923. #endif
  173924. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173925. white_x = (float).3127;
  173926. white_y = (float).3290;
  173927. red_x = (float).64;
  173928. red_y = (float).33;
  173929. green_x = (float).30;
  173930. green_y = (float).60;
  173931. blue_x = (float).15;
  173932. blue_y = (float).06;
  173933. png_set_cHRM(png_ptr, info_ptr,
  173934. white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
  173935. #endif
  173936. #endif
  173937. }
  173938. #endif
  173939. #if defined(PNG_iCCP_SUPPORTED)
  173940. void PNGAPI
  173941. png_set_iCCP(png_structp png_ptr, png_infop info_ptr,
  173942. png_charp name, int compression_type,
  173943. png_charp profile, png_uint_32 proflen)
  173944. {
  173945. png_charp new_iccp_name;
  173946. png_charp new_iccp_profile;
  173947. png_debug1(1, "in %s storage function\n", "iCCP");
  173948. if (png_ptr == NULL || info_ptr == NULL || name == NULL || profile == NULL)
  173949. return;
  173950. new_iccp_name = (png_charp)png_malloc_warn(png_ptr, png_strlen(name)+1);
  173951. if (new_iccp_name == NULL)
  173952. {
  173953. png_warning(png_ptr, "Insufficient memory to process iCCP chunk.");
  173954. return;
  173955. }
  173956. png_strncpy(new_iccp_name, name, png_strlen(name)+1);
  173957. new_iccp_profile = (png_charp)png_malloc_warn(png_ptr, proflen);
  173958. if (new_iccp_profile == NULL)
  173959. {
  173960. png_free (png_ptr, new_iccp_name);
  173961. png_warning(png_ptr, "Insufficient memory to process iCCP profile.");
  173962. return;
  173963. }
  173964. png_memcpy(new_iccp_profile, profile, (png_size_t)proflen);
  173965. png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, 0);
  173966. info_ptr->iccp_proflen = proflen;
  173967. info_ptr->iccp_name = new_iccp_name;
  173968. info_ptr->iccp_profile = new_iccp_profile;
  173969. info_ptr->iccp_compression = (png_byte)compression_type;
  173970. #ifdef PNG_FREE_ME_SUPPORTED
  173971. info_ptr->free_me |= PNG_FREE_ICCP;
  173972. #endif
  173973. info_ptr->valid |= PNG_INFO_iCCP;
  173974. }
  173975. #endif
  173976. #if defined(PNG_TEXT_SUPPORTED)
  173977. void PNGAPI
  173978. png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
  173979. int num_text)
  173980. {
  173981. int ret;
  173982. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, num_text);
  173983. if (ret)
  173984. png_error(png_ptr, "Insufficient memory to store text");
  173985. }
  173986. int /* PRIVATE */
  173987. png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
  173988. int num_text)
  173989. {
  173990. int i;
  173991. png_debug1(1, "in %s storage function\n", (png_ptr->chunk_name[0] == '\0' ?
  173992. "text" : (png_const_charp)png_ptr->chunk_name));
  173993. if (png_ptr == NULL || info_ptr == NULL || num_text == 0)
  173994. return(0);
  173995. if (info_ptr->num_text + num_text > info_ptr->max_text)
  173996. {
  173997. if (info_ptr->text != NULL)
  173998. {
  173999. png_textp old_text;
  174000. int old_max;
  174001. old_max = info_ptr->max_text;
  174002. info_ptr->max_text = info_ptr->num_text + num_text + 8;
  174003. old_text = info_ptr->text;
  174004. info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
  174005. (png_uint_32)(info_ptr->max_text * png_sizeof (png_text)));
  174006. if (info_ptr->text == NULL)
  174007. {
  174008. png_free(png_ptr, old_text);
  174009. return(1);
  174010. }
  174011. png_memcpy(info_ptr->text, old_text, (png_size_t)(old_max *
  174012. png_sizeof(png_text)));
  174013. png_free(png_ptr, old_text);
  174014. }
  174015. else
  174016. {
  174017. info_ptr->max_text = num_text + 8;
  174018. info_ptr->num_text = 0;
  174019. info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
  174020. (png_uint_32)(info_ptr->max_text * png_sizeof (png_text)));
  174021. if (info_ptr->text == NULL)
  174022. return(1);
  174023. #ifdef PNG_FREE_ME_SUPPORTED
  174024. info_ptr->free_me |= PNG_FREE_TEXT;
  174025. #endif
  174026. }
  174027. png_debug1(3, "allocated %d entries for info_ptr->text\n",
  174028. info_ptr->max_text);
  174029. }
  174030. for (i = 0; i < num_text; i++)
  174031. {
  174032. png_size_t text_length,key_len;
  174033. png_size_t lang_len,lang_key_len;
  174034. png_textp textp = &(info_ptr->text[info_ptr->num_text]);
  174035. if (text_ptr[i].key == NULL)
  174036. continue;
  174037. key_len = png_strlen(text_ptr[i].key);
  174038. if(text_ptr[i].compression <= 0)
  174039. {
  174040. lang_len = 0;
  174041. lang_key_len = 0;
  174042. }
  174043. else
  174044. #ifdef PNG_iTXt_SUPPORTED
  174045. {
  174046. if (text_ptr[i].lang != NULL)
  174047. lang_len = png_strlen(text_ptr[i].lang);
  174048. else
  174049. lang_len = 0;
  174050. if (text_ptr[i].lang_key != NULL)
  174051. lang_key_len = png_strlen(text_ptr[i].lang_key);
  174052. else
  174053. lang_key_len = 0;
  174054. }
  174055. #else
  174056. {
  174057. png_warning(png_ptr, "iTXt chunk not supported.");
  174058. continue;
  174059. }
  174060. #endif
  174061. if (text_ptr[i].text == NULL || text_ptr[i].text[0] == '\0')
  174062. {
  174063. text_length = 0;
  174064. #ifdef PNG_iTXt_SUPPORTED
  174065. if(text_ptr[i].compression > 0)
  174066. textp->compression = PNG_ITXT_COMPRESSION_NONE;
  174067. else
  174068. #endif
  174069. textp->compression = PNG_TEXT_COMPRESSION_NONE;
  174070. }
  174071. else
  174072. {
  174073. text_length = png_strlen(text_ptr[i].text);
  174074. textp->compression = text_ptr[i].compression;
  174075. }
  174076. textp->key = (png_charp)png_malloc_warn(png_ptr,
  174077. (png_uint_32)(key_len + text_length + lang_len + lang_key_len + 4));
  174078. if (textp->key == NULL)
  174079. return(1);
  174080. png_debug2(2, "Allocated %lu bytes at %x in png_set_text\n",
  174081. (png_uint_32)(key_len + lang_len + lang_key_len + text_length + 4),
  174082. (int)textp->key);
  174083. png_memcpy(textp->key, text_ptr[i].key,
  174084. (png_size_t)(key_len));
  174085. *(textp->key+key_len) = '\0';
  174086. #ifdef PNG_iTXt_SUPPORTED
  174087. if (text_ptr[i].compression > 0)
  174088. {
  174089. textp->lang=textp->key + key_len + 1;
  174090. png_memcpy(textp->lang, text_ptr[i].lang, lang_len);
  174091. *(textp->lang+lang_len) = '\0';
  174092. textp->lang_key=textp->lang + lang_len + 1;
  174093. png_memcpy(textp->lang_key, text_ptr[i].lang_key, lang_key_len);
  174094. *(textp->lang_key+lang_key_len) = '\0';
  174095. textp->text=textp->lang_key + lang_key_len + 1;
  174096. }
  174097. else
  174098. #endif
  174099. {
  174100. #ifdef PNG_iTXt_SUPPORTED
  174101. textp->lang=NULL;
  174102. textp->lang_key=NULL;
  174103. #endif
  174104. textp->text=textp->key + key_len + 1;
  174105. }
  174106. if(text_length)
  174107. png_memcpy(textp->text, text_ptr[i].text,
  174108. (png_size_t)(text_length));
  174109. *(textp->text+text_length) = '\0';
  174110. #ifdef PNG_iTXt_SUPPORTED
  174111. if(textp->compression > 0)
  174112. {
  174113. textp->text_length = 0;
  174114. textp->itxt_length = text_length;
  174115. }
  174116. else
  174117. #endif
  174118. {
  174119. textp->text_length = text_length;
  174120. #ifdef PNG_iTXt_SUPPORTED
  174121. textp->itxt_length = 0;
  174122. #endif
  174123. }
  174124. info_ptr->num_text++;
  174125. png_debug1(3, "transferred text chunk %d\n", info_ptr->num_text);
  174126. }
  174127. return(0);
  174128. }
  174129. #endif
  174130. #if defined(PNG_tIME_SUPPORTED)
  174131. void PNGAPI
  174132. png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_timep mod_time)
  174133. {
  174134. png_debug1(1, "in %s storage function\n", "tIME");
  174135. if (png_ptr == NULL || info_ptr == NULL ||
  174136. (png_ptr->mode & PNG_WROTE_tIME))
  174137. return;
  174138. png_memcpy(&(info_ptr->mod_time), mod_time, png_sizeof (png_time));
  174139. info_ptr->valid |= PNG_INFO_tIME;
  174140. }
  174141. #endif
  174142. #if defined(PNG_tRNS_SUPPORTED)
  174143. void PNGAPI
  174144. png_set_tRNS(png_structp png_ptr, png_infop info_ptr,
  174145. png_bytep trans, int num_trans, png_color_16p trans_values)
  174146. {
  174147. png_debug1(1, "in %s storage function\n", "tRNS");
  174148. if (png_ptr == NULL || info_ptr == NULL)
  174149. return;
  174150. if (trans != NULL)
  174151. {
  174152. #ifdef PNG_FREE_ME_SUPPORTED
  174153. png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0);
  174154. #endif
  174155. png_ptr->trans = info_ptr->trans = (png_bytep)png_malloc(png_ptr,
  174156. (png_uint_32)PNG_MAX_PALETTE_LENGTH);
  174157. if (num_trans <= PNG_MAX_PALETTE_LENGTH)
  174158. png_memcpy(info_ptr->trans, trans, (png_size_t)num_trans);
  174159. #ifdef PNG_FREE_ME_SUPPORTED
  174160. info_ptr->free_me |= PNG_FREE_TRNS;
  174161. #else
  174162. png_ptr->flags |= PNG_FLAG_FREE_TRNS;
  174163. #endif
  174164. }
  174165. if (trans_values != NULL)
  174166. {
  174167. png_memcpy(&(info_ptr->trans_values), trans_values,
  174168. png_sizeof(png_color_16));
  174169. if (num_trans == 0)
  174170. num_trans = 1;
  174171. }
  174172. info_ptr->num_trans = (png_uint_16)num_trans;
  174173. info_ptr->valid |= PNG_INFO_tRNS;
  174174. }
  174175. #endif
  174176. #if defined(PNG_sPLT_SUPPORTED)
  174177. void PNGAPI
  174178. png_set_sPLT(png_structp png_ptr,
  174179. png_infop info_ptr, png_sPLT_tp entries, int nentries)
  174180. {
  174181. png_sPLT_tp np;
  174182. int i;
  174183. if (png_ptr == NULL || info_ptr == NULL)
  174184. return;
  174185. np = (png_sPLT_tp)png_malloc_warn(png_ptr,
  174186. (info_ptr->splt_palettes_num + nentries) * png_sizeof(png_sPLT_t));
  174187. if (np == NULL)
  174188. {
  174189. png_warning(png_ptr, "No memory for sPLT palettes.");
  174190. return;
  174191. }
  174192. png_memcpy(np, info_ptr->splt_palettes,
  174193. info_ptr->splt_palettes_num * png_sizeof(png_sPLT_t));
  174194. png_free(png_ptr, info_ptr->splt_palettes);
  174195. info_ptr->splt_palettes=NULL;
  174196. for (i = 0; i < nentries; i++)
  174197. {
  174198. png_sPLT_tp to = np + info_ptr->splt_palettes_num + i;
  174199. png_sPLT_tp from = entries + i;
  174200. to->name = (png_charp)png_malloc_warn(png_ptr,
  174201. png_strlen(from->name) + 1);
  174202. if (to->name == NULL)
  174203. {
  174204. png_warning(png_ptr,
  174205. "Out of memory while processing sPLT chunk");
  174206. }
  174207. png_strncpy(to->name, from->name, png_strlen(from->name)+1);
  174208. to->entries = (png_sPLT_entryp)png_malloc_warn(png_ptr,
  174209. from->nentries * png_sizeof(png_sPLT_entry));
  174210. png_memcpy(to->entries, from->entries,
  174211. from->nentries * png_sizeof(png_sPLT_entry));
  174212. if (to->entries == NULL)
  174213. {
  174214. png_warning(png_ptr,
  174215. "Out of memory while processing sPLT chunk");
  174216. png_free(png_ptr,to->name);
  174217. to->name = NULL;
  174218. }
  174219. to->nentries = from->nentries;
  174220. to->depth = from->depth;
  174221. }
  174222. info_ptr->splt_palettes = np;
  174223. info_ptr->splt_palettes_num += nentries;
  174224. info_ptr->valid |= PNG_INFO_sPLT;
  174225. #ifdef PNG_FREE_ME_SUPPORTED
  174226. info_ptr->free_me |= PNG_FREE_SPLT;
  174227. #endif
  174228. }
  174229. #endif /* PNG_sPLT_SUPPORTED */
  174230. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  174231. void PNGAPI
  174232. png_set_unknown_chunks(png_structp png_ptr,
  174233. png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns)
  174234. {
  174235. png_unknown_chunkp np;
  174236. int i;
  174237. if (png_ptr == NULL || info_ptr == NULL || num_unknowns == 0)
  174238. return;
  174239. np = (png_unknown_chunkp)png_malloc_warn(png_ptr,
  174240. (info_ptr->unknown_chunks_num + num_unknowns) *
  174241. png_sizeof(png_unknown_chunk));
  174242. if (np == NULL)
  174243. {
  174244. png_warning(png_ptr,
  174245. "Out of memory while processing unknown chunk.");
  174246. return;
  174247. }
  174248. png_memcpy(np, info_ptr->unknown_chunks,
  174249. info_ptr->unknown_chunks_num * png_sizeof(png_unknown_chunk));
  174250. png_free(png_ptr, info_ptr->unknown_chunks);
  174251. info_ptr->unknown_chunks=NULL;
  174252. for (i = 0; i < num_unknowns; i++)
  174253. {
  174254. png_unknown_chunkp to = np + info_ptr->unknown_chunks_num + i;
  174255. png_unknown_chunkp from = unknowns + i;
  174256. png_strncpy((png_charp)to->name, (png_charp)from->name, 5);
  174257. to->data = (png_bytep)png_malloc_warn(png_ptr, from->size);
  174258. if (to->data == NULL)
  174259. {
  174260. png_warning(png_ptr,
  174261. "Out of memory while processing unknown chunk.");
  174262. }
  174263. else
  174264. {
  174265. png_memcpy(to->data, from->data, from->size);
  174266. to->size = from->size;
  174267. to->location = (png_byte)(png_ptr->mode & 0xff);
  174268. }
  174269. }
  174270. info_ptr->unknown_chunks = np;
  174271. info_ptr->unknown_chunks_num += num_unknowns;
  174272. #ifdef PNG_FREE_ME_SUPPORTED
  174273. info_ptr->free_me |= PNG_FREE_UNKN;
  174274. #endif
  174275. }
  174276. void PNGAPI
  174277. png_set_unknown_chunk_location(png_structp png_ptr, png_infop info_ptr,
  174278. int chunk, int location)
  174279. {
  174280. if(png_ptr != NULL && info_ptr != NULL && chunk >= 0 && chunk <
  174281. (int)info_ptr->unknown_chunks_num)
  174282. info_ptr->unknown_chunks[chunk].location = (png_byte)location;
  174283. }
  174284. #endif
  174285. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  174286. #if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
  174287. defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
  174288. void PNGAPI
  174289. png_permit_empty_plte (png_structp png_ptr, int empty_plte_permitted)
  174290. {
  174291. png_debug(1, "in png_permit_empty_plte, DEPRECATED.\n");
  174292. if (png_ptr == NULL)
  174293. return;
  174294. png_ptr->mng_features_permitted = (png_byte)
  174295. ((png_ptr->mng_features_permitted & (~(PNG_FLAG_MNG_EMPTY_PLTE))) |
  174296. ((empty_plte_permitted & PNG_FLAG_MNG_EMPTY_PLTE)));
  174297. }
  174298. #endif
  174299. #endif
  174300. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  174301. png_uint_32 PNGAPI
  174302. png_permit_mng_features (png_structp png_ptr, png_uint_32 mng_features)
  174303. {
  174304. png_debug(1, "in png_permit_mng_features\n");
  174305. if (png_ptr == NULL)
  174306. return (png_uint_32)0;
  174307. png_ptr->mng_features_permitted =
  174308. (png_byte)(mng_features & PNG_ALL_MNG_FEATURES);
  174309. return (png_uint_32)png_ptr->mng_features_permitted;
  174310. }
  174311. #endif
  174312. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  174313. void PNGAPI
  174314. png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep
  174315. chunk_list, int num_chunks)
  174316. {
  174317. png_bytep new_list, p;
  174318. int i, old_num_chunks;
  174319. if (png_ptr == NULL)
  174320. return;
  174321. if (num_chunks == 0)
  174322. {
  174323. if(keep == PNG_HANDLE_CHUNK_ALWAYS || keep == PNG_HANDLE_CHUNK_IF_SAFE)
  174324. png_ptr->flags |= PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
  174325. else
  174326. png_ptr->flags &= ~PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
  174327. if(keep == PNG_HANDLE_CHUNK_ALWAYS)
  174328. png_ptr->flags |= PNG_FLAG_KEEP_UNSAFE_CHUNKS;
  174329. else
  174330. png_ptr->flags &= ~PNG_FLAG_KEEP_UNSAFE_CHUNKS;
  174331. return;
  174332. }
  174333. if (chunk_list == NULL)
  174334. return;
  174335. old_num_chunks=png_ptr->num_chunk_list;
  174336. new_list=(png_bytep)png_malloc(png_ptr,
  174337. (png_uint_32)(5*(num_chunks+old_num_chunks)));
  174338. if(png_ptr->chunk_list != NULL)
  174339. {
  174340. png_memcpy(new_list, png_ptr->chunk_list,
  174341. (png_size_t)(5*old_num_chunks));
  174342. png_free(png_ptr, png_ptr->chunk_list);
  174343. png_ptr->chunk_list=NULL;
  174344. }
  174345. png_memcpy(new_list+5*old_num_chunks, chunk_list,
  174346. (png_size_t)(5*num_chunks));
  174347. for (p=new_list+5*old_num_chunks+4, i=0; i<num_chunks; i++, p+=5)
  174348. *p=(png_byte)keep;
  174349. png_ptr->num_chunk_list=old_num_chunks+num_chunks;
  174350. png_ptr->chunk_list=new_list;
  174351. #ifdef PNG_FREE_ME_SUPPORTED
  174352. png_ptr->free_me |= PNG_FREE_LIST;
  174353. #endif
  174354. }
  174355. #endif
  174356. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  174357. void PNGAPI
  174358. png_set_read_user_chunk_fn(png_structp png_ptr, png_voidp user_chunk_ptr,
  174359. png_user_chunk_ptr read_user_chunk_fn)
  174360. {
  174361. png_debug(1, "in png_set_read_user_chunk_fn\n");
  174362. if (png_ptr == NULL)
  174363. return;
  174364. png_ptr->read_user_chunk_fn = read_user_chunk_fn;
  174365. png_ptr->user_chunk_ptr = user_chunk_ptr;
  174366. }
  174367. #endif
  174368. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  174369. void PNGAPI
  174370. png_set_rows(png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers)
  174371. {
  174372. png_debug1(1, "in %s storage function\n", "rows");
  174373. if (png_ptr == NULL || info_ptr == NULL)
  174374. return;
  174375. if(info_ptr->row_pointers && (info_ptr->row_pointers != row_pointers))
  174376. png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
  174377. info_ptr->row_pointers = row_pointers;
  174378. if(row_pointers)
  174379. info_ptr->valid |= PNG_INFO_IDAT;
  174380. }
  174381. #endif
  174382. #ifdef PNG_WRITE_SUPPORTED
  174383. void PNGAPI
  174384. png_set_compression_buffer_size(png_structp png_ptr, png_uint_32 size)
  174385. {
  174386. if (png_ptr == NULL)
  174387. return;
  174388. if(png_ptr->zbuf)
  174389. png_free(png_ptr, png_ptr->zbuf);
  174390. png_ptr->zbuf_size = (png_size_t)size;
  174391. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, size);
  174392. png_ptr->zstream.next_out = png_ptr->zbuf;
  174393. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  174394. }
  174395. #endif
  174396. void PNGAPI
  174397. png_set_invalid(png_structp png_ptr, png_infop info_ptr, int mask)
  174398. {
  174399. if (png_ptr && info_ptr)
  174400. info_ptr->valid &= ~(mask);
  174401. }
  174402. #ifndef PNG_1_0_X
  174403. #ifdef PNG_ASSEMBLER_CODE_SUPPORTED
  174404. void PNGAPI
  174405. png_set_asm_flags (png_structp png_ptr, png_uint_32 asm_flags)
  174406. {
  174407. if (png_ptr != NULL)
  174408. png_ptr->asm_flags = 0;
  174409. }
  174410. void PNGAPI
  174411. png_set_mmx_thresholds (png_structp png_ptr,
  174412. png_byte mmx_bitdepth_threshold,
  174413. png_uint_32 mmx_rowbytes_threshold)
  174414. {
  174415. if (png_ptr == NULL)
  174416. return;
  174417. }
  174418. #endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
  174419. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  174420. void PNGAPI
  174421. png_set_user_limits (png_structp png_ptr, png_uint_32 user_width_max,
  174422. png_uint_32 user_height_max)
  174423. {
  174424. if(png_ptr == NULL) return;
  174425. png_ptr->user_width_max = user_width_max;
  174426. png_ptr->user_height_max = user_height_max;
  174427. }
  174428. #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
  174429. #endif /* ?PNG_1_0_X */
  174430. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  174431. /*** End of inlined file: pngset.c ***/
  174432. /*** Start of inlined file: pngtrans.c ***/
  174433. #define PNG_INTERNAL
  174434. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  174435. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  174436. void PNGAPI
  174437. png_set_bgr(png_structp png_ptr)
  174438. {
  174439. png_debug(1, "in png_set_bgr\n");
  174440. if(png_ptr == NULL) return;
  174441. png_ptr->transformations |= PNG_BGR;
  174442. }
  174443. #endif
  174444. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  174445. void PNGAPI
  174446. png_set_swap(png_structp png_ptr)
  174447. {
  174448. png_debug(1, "in png_set_swap\n");
  174449. if(png_ptr == NULL) return;
  174450. if (png_ptr->bit_depth == 16)
  174451. png_ptr->transformations |= PNG_SWAP_BYTES;
  174452. }
  174453. #endif
  174454. #if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
  174455. void PNGAPI
  174456. png_set_packing(png_structp png_ptr)
  174457. {
  174458. png_debug(1, "in png_set_packing\n");
  174459. if(png_ptr == NULL) return;
  174460. if (png_ptr->bit_depth < 8)
  174461. {
  174462. png_ptr->transformations |= PNG_PACK;
  174463. png_ptr->usr_bit_depth = 8;
  174464. }
  174465. }
  174466. #endif
  174467. #if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  174468. void PNGAPI
  174469. png_set_packswap(png_structp png_ptr)
  174470. {
  174471. png_debug(1, "in png_set_packswap\n");
  174472. if(png_ptr == NULL) return;
  174473. if (png_ptr->bit_depth < 8)
  174474. png_ptr->transformations |= PNG_PACKSWAP;
  174475. }
  174476. #endif
  174477. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  174478. void PNGAPI
  174479. png_set_shift(png_structp png_ptr, png_color_8p true_bits)
  174480. {
  174481. png_debug(1, "in png_set_shift\n");
  174482. if(png_ptr == NULL) return;
  174483. png_ptr->transformations |= PNG_SHIFT;
  174484. png_ptr->shift = *true_bits;
  174485. }
  174486. #endif
  174487. #if defined(PNG_READ_INTERLACING_SUPPORTED) || \
  174488. defined(PNG_WRITE_INTERLACING_SUPPORTED)
  174489. int PNGAPI
  174490. png_set_interlace_handling(png_structp png_ptr)
  174491. {
  174492. png_debug(1, "in png_set_interlace handling\n");
  174493. if (png_ptr && png_ptr->interlaced)
  174494. {
  174495. png_ptr->transformations |= PNG_INTERLACE;
  174496. return (7);
  174497. }
  174498. return (1);
  174499. }
  174500. #endif
  174501. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  174502. void PNGAPI
  174503. png_set_filler(png_structp png_ptr, png_uint_32 filler, int filler_loc)
  174504. {
  174505. png_debug(1, "in png_set_filler\n");
  174506. if(png_ptr == NULL) return;
  174507. png_ptr->transformations |= PNG_FILLER;
  174508. png_ptr->filler = (png_byte)filler;
  174509. if (filler_loc == PNG_FILLER_AFTER)
  174510. png_ptr->flags |= PNG_FLAG_FILLER_AFTER;
  174511. else
  174512. png_ptr->flags &= ~PNG_FLAG_FILLER_AFTER;
  174513. if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  174514. {
  174515. png_ptr->usr_channels = 4;
  174516. }
  174517. if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY && png_ptr->bit_depth >= 8)
  174518. {
  174519. png_ptr->usr_channels = 2;
  174520. }
  174521. }
  174522. #if !defined(PNG_1_0_X)
  174523. void PNGAPI
  174524. png_set_add_alpha(png_structp png_ptr, png_uint_32 filler, int filler_loc)
  174525. {
  174526. png_debug(1, "in png_set_add_alpha\n");
  174527. if(png_ptr == NULL) return;
  174528. png_set_filler(png_ptr, filler, filler_loc);
  174529. png_ptr->transformations |= PNG_ADD_ALPHA;
  174530. }
  174531. #endif
  174532. #endif
  174533. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \
  174534. defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  174535. void PNGAPI
  174536. png_set_swap_alpha(png_structp png_ptr)
  174537. {
  174538. png_debug(1, "in png_set_swap_alpha\n");
  174539. if(png_ptr == NULL) return;
  174540. png_ptr->transformations |= PNG_SWAP_ALPHA;
  174541. }
  174542. #endif
  174543. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \
  174544. defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  174545. void PNGAPI
  174546. png_set_invert_alpha(png_structp png_ptr)
  174547. {
  174548. png_debug(1, "in png_set_invert_alpha\n");
  174549. if(png_ptr == NULL) return;
  174550. png_ptr->transformations |= PNG_INVERT_ALPHA;
  174551. }
  174552. #endif
  174553. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  174554. void PNGAPI
  174555. png_set_invert_mono(png_structp png_ptr)
  174556. {
  174557. png_debug(1, "in png_set_invert_mono\n");
  174558. if(png_ptr == NULL) return;
  174559. png_ptr->transformations |= PNG_INVERT_MONO;
  174560. }
  174561. void /* PRIVATE */
  174562. png_do_invert(png_row_infop row_info, png_bytep row)
  174563. {
  174564. png_debug(1, "in png_do_invert\n");
  174565. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174566. if (row == NULL || row_info == NULL)
  174567. return;
  174568. #endif
  174569. if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
  174570. {
  174571. png_bytep rp = row;
  174572. png_uint_32 i;
  174573. png_uint_32 istop = row_info->rowbytes;
  174574. for (i = 0; i < istop; i++)
  174575. {
  174576. *rp = (png_byte)(~(*rp));
  174577. rp++;
  174578. }
  174579. }
  174580. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  174581. row_info->bit_depth == 8)
  174582. {
  174583. png_bytep rp = row;
  174584. png_uint_32 i;
  174585. png_uint_32 istop = row_info->rowbytes;
  174586. for (i = 0; i < istop; i+=2)
  174587. {
  174588. *rp = (png_byte)(~(*rp));
  174589. rp+=2;
  174590. }
  174591. }
  174592. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  174593. row_info->bit_depth == 16)
  174594. {
  174595. png_bytep rp = row;
  174596. png_uint_32 i;
  174597. png_uint_32 istop = row_info->rowbytes;
  174598. for (i = 0; i < istop; i+=4)
  174599. {
  174600. *rp = (png_byte)(~(*rp));
  174601. *(rp+1) = (png_byte)(~(*(rp+1)));
  174602. rp+=4;
  174603. }
  174604. }
  174605. }
  174606. #endif
  174607. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  174608. void /* PRIVATE */
  174609. png_do_swap(png_row_infop row_info, png_bytep row)
  174610. {
  174611. png_debug(1, "in png_do_swap\n");
  174612. if (
  174613. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174614. row != NULL && row_info != NULL &&
  174615. #endif
  174616. row_info->bit_depth == 16)
  174617. {
  174618. png_bytep rp = row;
  174619. png_uint_32 i;
  174620. png_uint_32 istop= row_info->width * row_info->channels;
  174621. for (i = 0; i < istop; i++, rp += 2)
  174622. {
  174623. png_byte t = *rp;
  174624. *rp = *(rp + 1);
  174625. *(rp + 1) = t;
  174626. }
  174627. }
  174628. }
  174629. #endif
  174630. #if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  174631. static PNG_CONST png_byte onebppswaptable[256] = {
  174632. 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0,
  174633. 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
  174634. 0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8,
  174635. 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8,
  174636. 0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4,
  174637. 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4,
  174638. 0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC,
  174639. 0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC,
  174640. 0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2,
  174641. 0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2,
  174642. 0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA,
  174643. 0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA,
  174644. 0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6,
  174645. 0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6,
  174646. 0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE,
  174647. 0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE,
  174648. 0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1,
  174649. 0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1,
  174650. 0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9,
  174651. 0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9,
  174652. 0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5,
  174653. 0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5,
  174654. 0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED,
  174655. 0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD,
  174656. 0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3,
  174657. 0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3,
  174658. 0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB,
  174659. 0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB,
  174660. 0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7,
  174661. 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,
  174662. 0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF,
  174663. 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF
  174664. };
  174665. static PNG_CONST png_byte twobppswaptable[256] = {
  174666. 0x00, 0x40, 0x80, 0xC0, 0x10, 0x50, 0x90, 0xD0,
  174667. 0x20, 0x60, 0xA0, 0xE0, 0x30, 0x70, 0xB0, 0xF0,
  174668. 0x04, 0x44, 0x84, 0xC4, 0x14, 0x54, 0x94, 0xD4,
  174669. 0x24, 0x64, 0xA4, 0xE4, 0x34, 0x74, 0xB4, 0xF4,
  174670. 0x08, 0x48, 0x88, 0xC8, 0x18, 0x58, 0x98, 0xD8,
  174671. 0x28, 0x68, 0xA8, 0xE8, 0x38, 0x78, 0xB8, 0xF8,
  174672. 0x0C, 0x4C, 0x8C, 0xCC, 0x1C, 0x5C, 0x9C, 0xDC,
  174673. 0x2C, 0x6C, 0xAC, 0xEC, 0x3C, 0x7C, 0xBC, 0xFC,
  174674. 0x01, 0x41, 0x81, 0xC1, 0x11, 0x51, 0x91, 0xD1,
  174675. 0x21, 0x61, 0xA1, 0xE1, 0x31, 0x71, 0xB1, 0xF1,
  174676. 0x05, 0x45, 0x85, 0xC5, 0x15, 0x55, 0x95, 0xD5,
  174677. 0x25, 0x65, 0xA5, 0xE5, 0x35, 0x75, 0xB5, 0xF5,
  174678. 0x09, 0x49, 0x89, 0xC9, 0x19, 0x59, 0x99, 0xD9,
  174679. 0x29, 0x69, 0xA9, 0xE9, 0x39, 0x79, 0xB9, 0xF9,
  174680. 0x0D, 0x4D, 0x8D, 0xCD, 0x1D, 0x5D, 0x9D, 0xDD,
  174681. 0x2D, 0x6D, 0xAD, 0xED, 0x3D, 0x7D, 0xBD, 0xFD,
  174682. 0x02, 0x42, 0x82, 0xC2, 0x12, 0x52, 0x92, 0xD2,
  174683. 0x22, 0x62, 0xA2, 0xE2, 0x32, 0x72, 0xB2, 0xF2,
  174684. 0x06, 0x46, 0x86, 0xC6, 0x16, 0x56, 0x96, 0xD6,
  174685. 0x26, 0x66, 0xA6, 0xE6, 0x36, 0x76, 0xB6, 0xF6,
  174686. 0x0A, 0x4A, 0x8A, 0xCA, 0x1A, 0x5A, 0x9A, 0xDA,
  174687. 0x2A, 0x6A, 0xAA, 0xEA, 0x3A, 0x7A, 0xBA, 0xFA,
  174688. 0x0E, 0x4E, 0x8E, 0xCE, 0x1E, 0x5E, 0x9E, 0xDE,
  174689. 0x2E, 0x6E, 0xAE, 0xEE, 0x3E, 0x7E, 0xBE, 0xFE,
  174690. 0x03, 0x43, 0x83, 0xC3, 0x13, 0x53, 0x93, 0xD3,
  174691. 0x23, 0x63, 0xA3, 0xE3, 0x33, 0x73, 0xB3, 0xF3,
  174692. 0x07, 0x47, 0x87, 0xC7, 0x17, 0x57, 0x97, 0xD7,
  174693. 0x27, 0x67, 0xA7, 0xE7, 0x37, 0x77, 0xB7, 0xF7,
  174694. 0x0B, 0x4B, 0x8B, 0xCB, 0x1B, 0x5B, 0x9B, 0xDB,
  174695. 0x2B, 0x6B, 0xAB, 0xEB, 0x3B, 0x7B, 0xBB, 0xFB,
  174696. 0x0F, 0x4F, 0x8F, 0xCF, 0x1F, 0x5F, 0x9F, 0xDF,
  174697. 0x2F, 0x6F, 0xAF, 0xEF, 0x3F, 0x7F, 0xBF, 0xFF
  174698. };
  174699. static PNG_CONST png_byte fourbppswaptable[256] = {
  174700. 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70,
  174701. 0x80, 0x90, 0xA0, 0xB0, 0xC0, 0xD0, 0xE0, 0xF0,
  174702. 0x01, 0x11, 0x21, 0x31, 0x41, 0x51, 0x61, 0x71,
  174703. 0x81, 0x91, 0xA1, 0xB1, 0xC1, 0xD1, 0xE1, 0xF1,
  174704. 0x02, 0x12, 0x22, 0x32, 0x42, 0x52, 0x62, 0x72,
  174705. 0x82, 0x92, 0xA2, 0xB2, 0xC2, 0xD2, 0xE2, 0xF2,
  174706. 0x03, 0x13, 0x23, 0x33, 0x43, 0x53, 0x63, 0x73,
  174707. 0x83, 0x93, 0xA3, 0xB3, 0xC3, 0xD3, 0xE3, 0xF3,
  174708. 0x04, 0x14, 0x24, 0x34, 0x44, 0x54, 0x64, 0x74,
  174709. 0x84, 0x94, 0xA4, 0xB4, 0xC4, 0xD4, 0xE4, 0xF4,
  174710. 0x05, 0x15, 0x25, 0x35, 0x45, 0x55, 0x65, 0x75,
  174711. 0x85, 0x95, 0xA5, 0xB5, 0xC5, 0xD5, 0xE5, 0xF5,
  174712. 0x06, 0x16, 0x26, 0x36, 0x46, 0x56, 0x66, 0x76,
  174713. 0x86, 0x96, 0xA6, 0xB6, 0xC6, 0xD6, 0xE6, 0xF6,
  174714. 0x07, 0x17, 0x27, 0x37, 0x47, 0x57, 0x67, 0x77,
  174715. 0x87, 0x97, 0xA7, 0xB7, 0xC7, 0xD7, 0xE7, 0xF7,
  174716. 0x08, 0x18, 0x28, 0x38, 0x48, 0x58, 0x68, 0x78,
  174717. 0x88, 0x98, 0xA8, 0xB8, 0xC8, 0xD8, 0xE8, 0xF8,
  174718. 0x09, 0x19, 0x29, 0x39, 0x49, 0x59, 0x69, 0x79,
  174719. 0x89, 0x99, 0xA9, 0xB9, 0xC9, 0xD9, 0xE9, 0xF9,
  174720. 0x0A, 0x1A, 0x2A, 0x3A, 0x4A, 0x5A, 0x6A, 0x7A,
  174721. 0x8A, 0x9A, 0xAA, 0xBA, 0xCA, 0xDA, 0xEA, 0xFA,
  174722. 0x0B, 0x1B, 0x2B, 0x3B, 0x4B, 0x5B, 0x6B, 0x7B,
  174723. 0x8B, 0x9B, 0xAB, 0xBB, 0xCB, 0xDB, 0xEB, 0xFB,
  174724. 0x0C, 0x1C, 0x2C, 0x3C, 0x4C, 0x5C, 0x6C, 0x7C,
  174725. 0x8C, 0x9C, 0xAC, 0xBC, 0xCC, 0xDC, 0xEC, 0xFC,
  174726. 0x0D, 0x1D, 0x2D, 0x3D, 0x4D, 0x5D, 0x6D, 0x7D,
  174727. 0x8D, 0x9D, 0xAD, 0xBD, 0xCD, 0xDD, 0xED, 0xFD,
  174728. 0x0E, 0x1E, 0x2E, 0x3E, 0x4E, 0x5E, 0x6E, 0x7E,
  174729. 0x8E, 0x9E, 0xAE, 0xBE, 0xCE, 0xDE, 0xEE, 0xFE,
  174730. 0x0F, 0x1F, 0x2F, 0x3F, 0x4F, 0x5F, 0x6F, 0x7F,
  174731. 0x8F, 0x9F, 0xAF, 0xBF, 0xCF, 0xDF, 0xEF, 0xFF
  174732. };
  174733. void /* PRIVATE */
  174734. png_do_packswap(png_row_infop row_info, png_bytep row)
  174735. {
  174736. png_debug(1, "in png_do_packswap\n");
  174737. if (
  174738. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174739. row != NULL && row_info != NULL &&
  174740. #endif
  174741. row_info->bit_depth < 8)
  174742. {
  174743. png_bytep rp, end, table;
  174744. end = row + row_info->rowbytes;
  174745. if (row_info->bit_depth == 1)
  174746. table = (png_bytep)onebppswaptable;
  174747. else if (row_info->bit_depth == 2)
  174748. table = (png_bytep)twobppswaptable;
  174749. else if (row_info->bit_depth == 4)
  174750. table = (png_bytep)fourbppswaptable;
  174751. else
  174752. return;
  174753. for (rp = row; rp < end; rp++)
  174754. *rp = table[*rp];
  174755. }
  174756. }
  174757. #endif /* PNG_READ_PACKSWAP_SUPPORTED or PNG_WRITE_PACKSWAP_SUPPORTED */
  174758. #if defined(PNG_WRITE_FILLER_SUPPORTED) || \
  174759. defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  174760. void /* PRIVATE */
  174761. png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags)
  174762. {
  174763. png_debug(1, "in png_do_strip_filler\n");
  174764. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174765. if (row != NULL && row_info != NULL)
  174766. #endif
  174767. {
  174768. png_bytep sp=row;
  174769. png_bytep dp=row;
  174770. png_uint_32 row_width=row_info->width;
  174771. png_uint_32 i;
  174772. if ((row_info->color_type == PNG_COLOR_TYPE_RGB ||
  174773. (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA &&
  174774. (flags & PNG_FLAG_STRIP_ALPHA))) &&
  174775. row_info->channels == 4)
  174776. {
  174777. if (row_info->bit_depth == 8)
  174778. {
  174779. if (flags & PNG_FLAG_FILLER_AFTER)
  174780. {
  174781. dp+=3; sp+=4;
  174782. for (i = 1; i < row_width; i++)
  174783. {
  174784. *dp++ = *sp++;
  174785. *dp++ = *sp++;
  174786. *dp++ = *sp++;
  174787. sp++;
  174788. }
  174789. }
  174790. else
  174791. {
  174792. for (i = 0; i < row_width; i++)
  174793. {
  174794. sp++;
  174795. *dp++ = *sp++;
  174796. *dp++ = *sp++;
  174797. *dp++ = *sp++;
  174798. }
  174799. }
  174800. row_info->pixel_depth = 24;
  174801. row_info->rowbytes = row_width * 3;
  174802. }
  174803. else /* if (row_info->bit_depth == 16) */
  174804. {
  174805. if (flags & PNG_FLAG_FILLER_AFTER)
  174806. {
  174807. sp += 8; dp += 6;
  174808. for (i = 1; i < row_width; i++)
  174809. {
  174810. *dp++ = *sp++;
  174811. *dp++ = *sp++;
  174812. *dp++ = *sp++;
  174813. *dp++ = *sp++;
  174814. *dp++ = *sp++;
  174815. *dp++ = *sp++;
  174816. sp += 2;
  174817. }
  174818. }
  174819. else
  174820. {
  174821. for (i = 0; i < row_width; i++)
  174822. {
  174823. sp+=2;
  174824. *dp++ = *sp++;
  174825. *dp++ = *sp++;
  174826. *dp++ = *sp++;
  174827. *dp++ = *sp++;
  174828. *dp++ = *sp++;
  174829. *dp++ = *sp++;
  174830. }
  174831. }
  174832. row_info->pixel_depth = 48;
  174833. row_info->rowbytes = row_width * 6;
  174834. }
  174835. row_info->channels = 3;
  174836. }
  174837. else if ((row_info->color_type == PNG_COLOR_TYPE_GRAY ||
  174838. (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  174839. (flags & PNG_FLAG_STRIP_ALPHA))) &&
  174840. row_info->channels == 2)
  174841. {
  174842. if (row_info->bit_depth == 8)
  174843. {
  174844. if (flags & PNG_FLAG_FILLER_AFTER)
  174845. {
  174846. for (i = 0; i < row_width; i++)
  174847. {
  174848. *dp++ = *sp++;
  174849. sp++;
  174850. }
  174851. }
  174852. else
  174853. {
  174854. for (i = 0; i < row_width; i++)
  174855. {
  174856. sp++;
  174857. *dp++ = *sp++;
  174858. }
  174859. }
  174860. row_info->pixel_depth = 8;
  174861. row_info->rowbytes = row_width;
  174862. }
  174863. else /* if (row_info->bit_depth == 16) */
  174864. {
  174865. if (flags & PNG_FLAG_FILLER_AFTER)
  174866. {
  174867. sp += 4; dp += 2;
  174868. for (i = 1; i < row_width; i++)
  174869. {
  174870. *dp++ = *sp++;
  174871. *dp++ = *sp++;
  174872. sp += 2;
  174873. }
  174874. }
  174875. else
  174876. {
  174877. for (i = 0; i < row_width; i++)
  174878. {
  174879. sp += 2;
  174880. *dp++ = *sp++;
  174881. *dp++ = *sp++;
  174882. }
  174883. }
  174884. row_info->pixel_depth = 16;
  174885. row_info->rowbytes = row_width * 2;
  174886. }
  174887. row_info->channels = 1;
  174888. }
  174889. if (flags & PNG_FLAG_STRIP_ALPHA)
  174890. row_info->color_type &= ~PNG_COLOR_MASK_ALPHA;
  174891. }
  174892. }
  174893. #endif
  174894. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  174895. void /* PRIVATE */
  174896. png_do_bgr(png_row_infop row_info, png_bytep row)
  174897. {
  174898. png_debug(1, "in png_do_bgr\n");
  174899. if (
  174900. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174901. row != NULL && row_info != NULL &&
  174902. #endif
  174903. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  174904. {
  174905. png_uint_32 row_width = row_info->width;
  174906. if (row_info->bit_depth == 8)
  174907. {
  174908. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  174909. {
  174910. png_bytep rp;
  174911. png_uint_32 i;
  174912. for (i = 0, rp = row; i < row_width; i++, rp += 3)
  174913. {
  174914. png_byte save = *rp;
  174915. *rp = *(rp + 2);
  174916. *(rp + 2) = save;
  174917. }
  174918. }
  174919. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  174920. {
  174921. png_bytep rp;
  174922. png_uint_32 i;
  174923. for (i = 0, rp = row; i < row_width; i++, rp += 4)
  174924. {
  174925. png_byte save = *rp;
  174926. *rp = *(rp + 2);
  174927. *(rp + 2) = save;
  174928. }
  174929. }
  174930. }
  174931. else if (row_info->bit_depth == 16)
  174932. {
  174933. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  174934. {
  174935. png_bytep rp;
  174936. png_uint_32 i;
  174937. for (i = 0, rp = row; i < row_width; i++, rp += 6)
  174938. {
  174939. png_byte save = *rp;
  174940. *rp = *(rp + 4);
  174941. *(rp + 4) = save;
  174942. save = *(rp + 1);
  174943. *(rp + 1) = *(rp + 5);
  174944. *(rp + 5) = save;
  174945. }
  174946. }
  174947. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  174948. {
  174949. png_bytep rp;
  174950. png_uint_32 i;
  174951. for (i = 0, rp = row; i < row_width; i++, rp += 8)
  174952. {
  174953. png_byte save = *rp;
  174954. *rp = *(rp + 4);
  174955. *(rp + 4) = save;
  174956. save = *(rp + 1);
  174957. *(rp + 1) = *(rp + 5);
  174958. *(rp + 5) = save;
  174959. }
  174960. }
  174961. }
  174962. }
  174963. }
  174964. #endif /* PNG_READ_BGR_SUPPORTED or PNG_WRITE_BGR_SUPPORTED */
  174965. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  174966. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  174967. defined(PNG_LEGACY_SUPPORTED)
  174968. void PNGAPI
  174969. png_set_user_transform_info(png_structp png_ptr, png_voidp
  174970. user_transform_ptr, int user_transform_depth, int user_transform_channels)
  174971. {
  174972. png_debug(1, "in png_set_user_transform_info\n");
  174973. if(png_ptr == NULL) return;
  174974. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  174975. png_ptr->user_transform_ptr = user_transform_ptr;
  174976. png_ptr->user_transform_depth = (png_byte)user_transform_depth;
  174977. png_ptr->user_transform_channels = (png_byte)user_transform_channels;
  174978. #else
  174979. if(user_transform_ptr || user_transform_depth || user_transform_channels)
  174980. png_warning(png_ptr,
  174981. "This version of libpng does not support user transform info");
  174982. #endif
  174983. }
  174984. #endif
  174985. png_voidp PNGAPI
  174986. png_get_user_transform_ptr(png_structp png_ptr)
  174987. {
  174988. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  174989. if (png_ptr == NULL) return (NULL);
  174990. return ((png_voidp)png_ptr->user_transform_ptr);
  174991. #else
  174992. return (NULL);
  174993. #endif
  174994. }
  174995. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  174996. /*** End of inlined file: pngtrans.c ***/
  174997. /*** Start of inlined file: pngwio.c ***/
  174998. #define PNG_INTERNAL
  174999. #ifdef PNG_WRITE_SUPPORTED
  175000. void /* PRIVATE */
  175001. png_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  175002. {
  175003. if (png_ptr->write_data_fn != NULL )
  175004. (*(png_ptr->write_data_fn))(png_ptr, data, length);
  175005. else
  175006. png_error(png_ptr, "Call to NULL write function");
  175007. }
  175008. #if !defined(PNG_NO_STDIO)
  175009. #ifndef USE_FAR_KEYWORD
  175010. void PNGAPI
  175011. png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  175012. {
  175013. png_uint_32 check;
  175014. if(png_ptr == NULL) return;
  175015. #if defined(_WIN32_WCE)
  175016. if ( !WriteFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  175017. check = 0;
  175018. #else
  175019. check = fwrite(data, 1, length, (png_FILE_p)(png_ptr->io_ptr));
  175020. #endif
  175021. if (check != length)
  175022. png_error(png_ptr, "Write Error");
  175023. }
  175024. #else
  175025. #define NEAR_BUF_SIZE 1024
  175026. #define MIN(a,b) (a <= b ? a : b)
  175027. void PNGAPI
  175028. png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  175029. {
  175030. png_uint_32 check;
  175031. png_byte *near_data; /* Needs to be "png_byte *" instead of "png_bytep" */
  175032. png_FILE_p io_ptr;
  175033. if(png_ptr == NULL) return;
  175034. near_data = (png_byte *)CVT_PTR_NOCHECK(data);
  175035. io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
  175036. if ((png_bytep)near_data == data)
  175037. {
  175038. #if defined(_WIN32_WCE)
  175039. if ( !WriteFile(io_ptr, near_data, length, &check, NULL) )
  175040. check = 0;
  175041. #else
  175042. check = fwrite(near_data, 1, length, io_ptr);
  175043. #endif
  175044. }
  175045. else
  175046. {
  175047. png_byte buf[NEAR_BUF_SIZE];
  175048. png_size_t written, remaining, err;
  175049. check = 0;
  175050. remaining = length;
  175051. do
  175052. {
  175053. written = MIN(NEAR_BUF_SIZE, remaining);
  175054. png_memcpy(buf, data, written); /* copy far buffer to near buffer */
  175055. #if defined(_WIN32_WCE)
  175056. if ( !WriteFile(io_ptr, buf, written, &err, NULL) )
  175057. err = 0;
  175058. #else
  175059. err = fwrite(buf, 1, written, io_ptr);
  175060. #endif
  175061. if (err != written)
  175062. break;
  175063. else
  175064. check += err;
  175065. data += written;
  175066. remaining -= written;
  175067. }
  175068. while (remaining != 0);
  175069. }
  175070. if (check != length)
  175071. png_error(png_ptr, "Write Error");
  175072. }
  175073. #endif
  175074. #endif
  175075. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  175076. void /* PRIVATE */
  175077. png_flush(png_structp png_ptr)
  175078. {
  175079. if (png_ptr->output_flush_fn != NULL)
  175080. (*(png_ptr->output_flush_fn))(png_ptr);
  175081. }
  175082. #if !defined(PNG_NO_STDIO)
  175083. void PNGAPI
  175084. png_default_flush(png_structp png_ptr)
  175085. {
  175086. #if !defined(_WIN32_WCE)
  175087. png_FILE_p io_ptr;
  175088. #endif
  175089. if(png_ptr == NULL) return;
  175090. #if !defined(_WIN32_WCE)
  175091. io_ptr = (png_FILE_p)CVT_PTR((png_ptr->io_ptr));
  175092. if (io_ptr != NULL)
  175093. fflush(io_ptr);
  175094. #endif
  175095. }
  175096. #endif
  175097. #endif
  175098. void PNGAPI
  175099. png_set_write_fn(png_structp png_ptr, png_voidp io_ptr,
  175100. png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn)
  175101. {
  175102. if(png_ptr == NULL) return;
  175103. png_ptr->io_ptr = io_ptr;
  175104. #if !defined(PNG_NO_STDIO)
  175105. if (write_data_fn != NULL)
  175106. png_ptr->write_data_fn = write_data_fn;
  175107. else
  175108. png_ptr->write_data_fn = png_default_write_data;
  175109. #else
  175110. png_ptr->write_data_fn = write_data_fn;
  175111. #endif
  175112. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  175113. #if !defined(PNG_NO_STDIO)
  175114. if (output_flush_fn != NULL)
  175115. png_ptr->output_flush_fn = output_flush_fn;
  175116. else
  175117. png_ptr->output_flush_fn = png_default_flush;
  175118. #else
  175119. png_ptr->output_flush_fn = output_flush_fn;
  175120. #endif
  175121. #endif /* PNG_WRITE_FLUSH_SUPPORTED */
  175122. if (png_ptr->read_data_fn != NULL)
  175123. {
  175124. png_ptr->read_data_fn = NULL;
  175125. png_warning(png_ptr,
  175126. "Attempted to set both read_data_fn and write_data_fn in");
  175127. png_warning(png_ptr,
  175128. "the same structure. Resetting read_data_fn to NULL.");
  175129. }
  175130. }
  175131. #if defined(USE_FAR_KEYWORD)
  175132. #if defined(_MSC_VER)
  175133. void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check)
  175134. {
  175135. void *near_ptr;
  175136. void FAR *far_ptr;
  175137. FP_OFF(near_ptr) = FP_OFF(ptr);
  175138. far_ptr = (void FAR *)near_ptr;
  175139. if(check != 0)
  175140. if(FP_SEG(ptr) != FP_SEG(far_ptr))
  175141. png_error(png_ptr,"segment lost in conversion");
  175142. return(near_ptr);
  175143. }
  175144. # else
  175145. void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check)
  175146. {
  175147. void *near_ptr;
  175148. void FAR *far_ptr;
  175149. near_ptr = (void FAR *)ptr;
  175150. far_ptr = (void FAR *)near_ptr;
  175151. if(check != 0)
  175152. if(far_ptr != ptr)
  175153. png_error(png_ptr,"segment lost in conversion");
  175154. return(near_ptr);
  175155. }
  175156. # endif
  175157. # endif
  175158. #endif /* PNG_WRITE_SUPPORTED */
  175159. /*** End of inlined file: pngwio.c ***/
  175160. /*** Start of inlined file: pngwrite.c ***/
  175161. #define PNG_INTERNAL
  175162. #ifdef PNG_WRITE_SUPPORTED
  175163. void PNGAPI
  175164. png_write_info_before_PLTE(png_structp png_ptr, png_infop info_ptr)
  175165. {
  175166. png_debug(1, "in png_write_info_before_PLTE\n");
  175167. if (png_ptr == NULL || info_ptr == NULL)
  175168. return;
  175169. if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
  175170. {
  175171. png_write_sig(png_ptr); /* write PNG signature */
  175172. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  175173. if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&(png_ptr->mng_features_permitted))
  175174. {
  175175. png_warning(png_ptr,"MNG features are not allowed in a PNG datastream");
  175176. png_ptr->mng_features_permitted=0;
  175177. }
  175178. #endif
  175179. png_write_IHDR(png_ptr, info_ptr->width, info_ptr->height,
  175180. info_ptr->bit_depth, info_ptr->color_type, info_ptr->compression_type,
  175181. info_ptr->filter_type,
  175182. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  175183. info_ptr->interlace_type);
  175184. #else
  175185. 0);
  175186. #endif
  175187. #if defined(PNG_WRITE_gAMA_SUPPORTED)
  175188. if (info_ptr->valid & PNG_INFO_gAMA)
  175189. {
  175190. # ifdef PNG_FLOATING_POINT_SUPPORTED
  175191. png_write_gAMA(png_ptr, info_ptr->gamma);
  175192. #else
  175193. #ifdef PNG_FIXED_POINT_SUPPORTED
  175194. png_write_gAMA_fixed(png_ptr, info_ptr->int_gamma);
  175195. # endif
  175196. #endif
  175197. }
  175198. #endif
  175199. #if defined(PNG_WRITE_sRGB_SUPPORTED)
  175200. if (info_ptr->valid & PNG_INFO_sRGB)
  175201. png_write_sRGB(png_ptr, (int)info_ptr->srgb_intent);
  175202. #endif
  175203. #if defined(PNG_WRITE_iCCP_SUPPORTED)
  175204. if (info_ptr->valid & PNG_INFO_iCCP)
  175205. png_write_iCCP(png_ptr, info_ptr->iccp_name, PNG_COMPRESSION_TYPE_BASE,
  175206. info_ptr->iccp_profile, (int)info_ptr->iccp_proflen);
  175207. #endif
  175208. #if defined(PNG_WRITE_sBIT_SUPPORTED)
  175209. if (info_ptr->valid & PNG_INFO_sBIT)
  175210. png_write_sBIT(png_ptr, &(info_ptr->sig_bit), info_ptr->color_type);
  175211. #endif
  175212. #if defined(PNG_WRITE_cHRM_SUPPORTED)
  175213. if (info_ptr->valid & PNG_INFO_cHRM)
  175214. {
  175215. #ifdef PNG_FLOATING_POINT_SUPPORTED
  175216. png_write_cHRM(png_ptr,
  175217. info_ptr->x_white, info_ptr->y_white,
  175218. info_ptr->x_red, info_ptr->y_red,
  175219. info_ptr->x_green, info_ptr->y_green,
  175220. info_ptr->x_blue, info_ptr->y_blue);
  175221. #else
  175222. # ifdef PNG_FIXED_POINT_SUPPORTED
  175223. png_write_cHRM_fixed(png_ptr,
  175224. info_ptr->int_x_white, info_ptr->int_y_white,
  175225. info_ptr->int_x_red, info_ptr->int_y_red,
  175226. info_ptr->int_x_green, info_ptr->int_y_green,
  175227. info_ptr->int_x_blue, info_ptr->int_y_blue);
  175228. # endif
  175229. #endif
  175230. }
  175231. #endif
  175232. #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
  175233. if (info_ptr->unknown_chunks_num)
  175234. {
  175235. png_unknown_chunk *up;
  175236. png_debug(5, "writing extra chunks\n");
  175237. for (up = info_ptr->unknown_chunks;
  175238. up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
  175239. up++)
  175240. {
  175241. int keep=png_handle_as_unknown(png_ptr, up->name);
  175242. if (keep != PNG_HANDLE_CHUNK_NEVER &&
  175243. up->location && !(up->location & PNG_HAVE_PLTE) &&
  175244. !(up->location & PNG_HAVE_IDAT) &&
  175245. ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
  175246. (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
  175247. {
  175248. png_write_chunk(png_ptr, up->name, up->data, up->size);
  175249. }
  175250. }
  175251. }
  175252. #endif
  175253. png_ptr->mode |= PNG_WROTE_INFO_BEFORE_PLTE;
  175254. }
  175255. }
  175256. void PNGAPI
  175257. png_write_info(png_structp png_ptr, png_infop info_ptr)
  175258. {
  175259. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
  175260. int i;
  175261. #endif
  175262. png_debug(1, "in png_write_info\n");
  175263. if (png_ptr == NULL || info_ptr == NULL)
  175264. return;
  175265. png_write_info_before_PLTE(png_ptr, info_ptr);
  175266. if (info_ptr->valid & PNG_INFO_PLTE)
  175267. png_write_PLTE(png_ptr, info_ptr->palette,
  175268. (png_uint_32)info_ptr->num_palette);
  175269. else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  175270. png_error(png_ptr, "Valid palette required for paletted images");
  175271. #if defined(PNG_WRITE_tRNS_SUPPORTED)
  175272. if (info_ptr->valid & PNG_INFO_tRNS)
  175273. {
  175274. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  175275. if ((png_ptr->transformations & PNG_INVERT_ALPHA) &&
  175276. info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  175277. {
  175278. int j;
  175279. for (j=0; j<(int)info_ptr->num_trans; j++)
  175280. info_ptr->trans[j] = (png_byte)(255 - info_ptr->trans[j]);
  175281. }
  175282. #endif
  175283. png_write_tRNS(png_ptr, info_ptr->trans, &(info_ptr->trans_values),
  175284. info_ptr->num_trans, info_ptr->color_type);
  175285. }
  175286. #endif
  175287. #if defined(PNG_WRITE_bKGD_SUPPORTED)
  175288. if (info_ptr->valid & PNG_INFO_bKGD)
  175289. png_write_bKGD(png_ptr, &(info_ptr->background), info_ptr->color_type);
  175290. #endif
  175291. #if defined(PNG_WRITE_hIST_SUPPORTED)
  175292. if (info_ptr->valid & PNG_INFO_hIST)
  175293. png_write_hIST(png_ptr, info_ptr->hist, info_ptr->num_palette);
  175294. #endif
  175295. #if defined(PNG_WRITE_oFFs_SUPPORTED)
  175296. if (info_ptr->valid & PNG_INFO_oFFs)
  175297. png_write_oFFs(png_ptr, info_ptr->x_offset, info_ptr->y_offset,
  175298. info_ptr->offset_unit_type);
  175299. #endif
  175300. #if defined(PNG_WRITE_pCAL_SUPPORTED)
  175301. if (info_ptr->valid & PNG_INFO_pCAL)
  175302. png_write_pCAL(png_ptr, info_ptr->pcal_purpose, info_ptr->pcal_X0,
  175303. info_ptr->pcal_X1, info_ptr->pcal_type, info_ptr->pcal_nparams,
  175304. info_ptr->pcal_units, info_ptr->pcal_params);
  175305. #endif
  175306. #if defined(PNG_WRITE_sCAL_SUPPORTED)
  175307. if (info_ptr->valid & PNG_INFO_sCAL)
  175308. #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
  175309. png_write_sCAL(png_ptr, (int)info_ptr->scal_unit,
  175310. info_ptr->scal_pixel_width, info_ptr->scal_pixel_height);
  175311. #else
  175312. #ifdef PNG_FIXED_POINT_SUPPORTED
  175313. png_write_sCAL_s(png_ptr, (int)info_ptr->scal_unit,
  175314. info_ptr->scal_s_width, info_ptr->scal_s_height);
  175315. #else
  175316. png_warning(png_ptr,
  175317. "png_write_sCAL not supported; sCAL chunk not written.");
  175318. #endif
  175319. #endif
  175320. #endif
  175321. #if defined(PNG_WRITE_pHYs_SUPPORTED)
  175322. if (info_ptr->valid & PNG_INFO_pHYs)
  175323. png_write_pHYs(png_ptr, info_ptr->x_pixels_per_unit,
  175324. info_ptr->y_pixels_per_unit, info_ptr->phys_unit_type);
  175325. #endif
  175326. #if defined(PNG_WRITE_tIME_SUPPORTED)
  175327. if (info_ptr->valid & PNG_INFO_tIME)
  175328. {
  175329. png_write_tIME(png_ptr, &(info_ptr->mod_time));
  175330. png_ptr->mode |= PNG_WROTE_tIME;
  175331. }
  175332. #endif
  175333. #if defined(PNG_WRITE_sPLT_SUPPORTED)
  175334. if (info_ptr->valid & PNG_INFO_sPLT)
  175335. for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
  175336. png_write_sPLT(png_ptr, info_ptr->splt_palettes + i);
  175337. #endif
  175338. #if defined(PNG_WRITE_TEXT_SUPPORTED)
  175339. for (i = 0; i < info_ptr->num_text; i++)
  175340. {
  175341. png_debug2(2, "Writing header text chunk %d, type %d\n", i,
  175342. info_ptr->text[i].compression);
  175343. if (info_ptr->text[i].compression > 0)
  175344. {
  175345. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  175346. png_write_iTXt(png_ptr,
  175347. info_ptr->text[i].compression,
  175348. info_ptr->text[i].key,
  175349. info_ptr->text[i].lang,
  175350. info_ptr->text[i].lang_key,
  175351. info_ptr->text[i].text);
  175352. #else
  175353. png_warning(png_ptr, "Unable to write international text");
  175354. #endif
  175355. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175356. }
  175357. else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_zTXt)
  175358. {
  175359. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  175360. png_write_zTXt(png_ptr, info_ptr->text[i].key,
  175361. info_ptr->text[i].text, 0,
  175362. info_ptr->text[i].compression);
  175363. #else
  175364. png_warning(png_ptr, "Unable to write compressed text");
  175365. #endif
  175366. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;
  175367. }
  175368. else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
  175369. {
  175370. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  175371. png_write_tEXt(png_ptr, info_ptr->text[i].key,
  175372. info_ptr->text[i].text,
  175373. 0);
  175374. #else
  175375. png_warning(png_ptr, "Unable to write uncompressed text");
  175376. #endif
  175377. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175378. }
  175379. }
  175380. #endif
  175381. #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
  175382. if (info_ptr->unknown_chunks_num)
  175383. {
  175384. png_unknown_chunk *up;
  175385. png_debug(5, "writing extra chunks\n");
  175386. for (up = info_ptr->unknown_chunks;
  175387. up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
  175388. up++)
  175389. {
  175390. int keep=png_handle_as_unknown(png_ptr, up->name);
  175391. if (keep != PNG_HANDLE_CHUNK_NEVER &&
  175392. up->location && (up->location & PNG_HAVE_PLTE) &&
  175393. !(up->location & PNG_HAVE_IDAT) &&
  175394. ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
  175395. (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
  175396. {
  175397. png_write_chunk(png_ptr, up->name, up->data, up->size);
  175398. }
  175399. }
  175400. }
  175401. #endif
  175402. }
  175403. void PNGAPI
  175404. png_write_end(png_structp png_ptr, png_infop info_ptr)
  175405. {
  175406. png_debug(1, "in png_write_end\n");
  175407. if (png_ptr == NULL)
  175408. return;
  175409. if (!(png_ptr->mode & PNG_HAVE_IDAT))
  175410. png_error(png_ptr, "No IDATs written into file");
  175411. if (info_ptr != NULL)
  175412. {
  175413. #if defined(PNG_WRITE_TEXT_SUPPORTED)
  175414. int i; /* local index variable */
  175415. #endif
  175416. #if defined(PNG_WRITE_tIME_SUPPORTED)
  175417. if ((info_ptr->valid & PNG_INFO_tIME) &&
  175418. !(png_ptr->mode & PNG_WROTE_tIME))
  175419. png_write_tIME(png_ptr, &(info_ptr->mod_time));
  175420. #endif
  175421. #if defined(PNG_WRITE_TEXT_SUPPORTED)
  175422. for (i = 0; i < info_ptr->num_text; i++)
  175423. {
  175424. png_debug2(2, "Writing trailer text chunk %d, type %d\n", i,
  175425. info_ptr->text[i].compression);
  175426. if (info_ptr->text[i].compression > 0)
  175427. {
  175428. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  175429. png_write_iTXt(png_ptr,
  175430. info_ptr->text[i].compression,
  175431. info_ptr->text[i].key,
  175432. info_ptr->text[i].lang,
  175433. info_ptr->text[i].lang_key,
  175434. info_ptr->text[i].text);
  175435. #else
  175436. png_warning(png_ptr, "Unable to write international text");
  175437. #endif
  175438. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175439. }
  175440. else if (info_ptr->text[i].compression >= PNG_TEXT_COMPRESSION_zTXt)
  175441. {
  175442. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  175443. png_write_zTXt(png_ptr, info_ptr->text[i].key,
  175444. info_ptr->text[i].text, 0,
  175445. info_ptr->text[i].compression);
  175446. #else
  175447. png_warning(png_ptr, "Unable to write compressed text");
  175448. #endif
  175449. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;
  175450. }
  175451. else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
  175452. {
  175453. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  175454. png_write_tEXt(png_ptr, info_ptr->text[i].key,
  175455. info_ptr->text[i].text, 0);
  175456. #else
  175457. png_warning(png_ptr, "Unable to write uncompressed text");
  175458. #endif
  175459. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175460. }
  175461. }
  175462. #endif
  175463. #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
  175464. if (info_ptr->unknown_chunks_num)
  175465. {
  175466. png_unknown_chunk *up;
  175467. png_debug(5, "writing extra chunks\n");
  175468. for (up = info_ptr->unknown_chunks;
  175469. up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
  175470. up++)
  175471. {
  175472. int keep=png_handle_as_unknown(png_ptr, up->name);
  175473. if (keep != PNG_HANDLE_CHUNK_NEVER &&
  175474. up->location && (up->location & PNG_AFTER_IDAT) &&
  175475. ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
  175476. (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
  175477. {
  175478. png_write_chunk(png_ptr, up->name, up->data, up->size);
  175479. }
  175480. }
  175481. }
  175482. #endif
  175483. }
  175484. png_ptr->mode |= PNG_AFTER_IDAT;
  175485. png_write_IEND(png_ptr);
  175486. }
  175487. #if defined(PNG_WRITE_tIME_SUPPORTED)
  175488. #if !defined(_WIN32_WCE)
  175489. void PNGAPI
  175490. png_convert_from_struct_tm(png_timep ptime, struct tm FAR * ttime)
  175491. {
  175492. png_debug(1, "in png_convert_from_struct_tm\n");
  175493. ptime->year = (png_uint_16)(1900 + ttime->tm_year);
  175494. ptime->month = (png_byte)(ttime->tm_mon + 1);
  175495. ptime->day = (png_byte)ttime->tm_mday;
  175496. ptime->hour = (png_byte)ttime->tm_hour;
  175497. ptime->minute = (png_byte)ttime->tm_min;
  175498. ptime->second = (png_byte)ttime->tm_sec;
  175499. }
  175500. void PNGAPI
  175501. png_convert_from_time_t(png_timep ptime, time_t ttime)
  175502. {
  175503. struct tm *tbuf;
  175504. png_debug(1, "in png_convert_from_time_t\n");
  175505. tbuf = gmtime(&ttime);
  175506. png_convert_from_struct_tm(ptime, tbuf);
  175507. }
  175508. #endif
  175509. #endif
  175510. png_structp PNGAPI
  175511. png_create_write_struct(png_const_charp user_png_ver, png_voidp error_ptr,
  175512. png_error_ptr error_fn, png_error_ptr warn_fn)
  175513. {
  175514. #ifdef PNG_USER_MEM_SUPPORTED
  175515. return (png_create_write_struct_2(user_png_ver, error_ptr, error_fn,
  175516. warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL));
  175517. }
  175518. png_structp PNGAPI
  175519. png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
  175520. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  175521. png_malloc_ptr malloc_fn, png_free_ptr free_fn)
  175522. {
  175523. #endif /* PNG_USER_MEM_SUPPORTED */
  175524. png_structp png_ptr;
  175525. #ifdef PNG_SETJMP_SUPPORTED
  175526. #ifdef USE_FAR_KEYWORD
  175527. jmp_buf jmpbuf;
  175528. #endif
  175529. #endif
  175530. int i;
  175531. png_debug(1, "in png_create_write_struct\n");
  175532. #ifdef PNG_USER_MEM_SUPPORTED
  175533. png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
  175534. (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr);
  175535. #else
  175536. png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  175537. #endif /* PNG_USER_MEM_SUPPORTED */
  175538. if (png_ptr == NULL)
  175539. return (NULL);
  175540. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  175541. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  175542. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  175543. #endif
  175544. #ifdef PNG_SETJMP_SUPPORTED
  175545. #ifdef USE_FAR_KEYWORD
  175546. if (setjmp(jmpbuf))
  175547. #else
  175548. if (setjmp(png_ptr->jmpbuf))
  175549. #endif
  175550. {
  175551. png_free(png_ptr, png_ptr->zbuf);
  175552. png_ptr->zbuf=NULL;
  175553. png_destroy_struct(png_ptr);
  175554. return (NULL);
  175555. }
  175556. #ifdef USE_FAR_KEYWORD
  175557. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  175558. #endif
  175559. #endif
  175560. #ifdef PNG_USER_MEM_SUPPORTED
  175561. png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
  175562. #endif /* PNG_USER_MEM_SUPPORTED */
  175563. png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
  175564. i=0;
  175565. do
  175566. {
  175567. if(user_png_ver[i] != png_libpng_ver[i])
  175568. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  175569. } while (png_libpng_ver[i++]);
  175570. if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
  175571. {
  175572. if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
  175573. (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
  175574. (user_png_ver[0] == '0' && user_png_ver[2] < '9'))
  175575. {
  175576. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  175577. char msg[80];
  175578. if (user_png_ver)
  175579. {
  175580. png_snprintf(msg, 80,
  175581. "Application was compiled with png.h from libpng-%.20s",
  175582. user_png_ver);
  175583. png_warning(png_ptr, msg);
  175584. }
  175585. png_snprintf(msg, 80,
  175586. "Application is running with png.c from libpng-%.20s",
  175587. png_libpng_ver);
  175588. png_warning(png_ptr, msg);
  175589. #endif
  175590. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  175591. png_ptr->flags=0;
  175592. #endif
  175593. png_error(png_ptr,
  175594. "Incompatible libpng version in application and library");
  175595. }
  175596. }
  175597. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  175598. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  175599. (png_uint_32)png_ptr->zbuf_size);
  175600. png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL,
  175601. png_flush_ptr_NULL);
  175602. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  175603. png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
  175604. 1, png_doublep_NULL, png_doublep_NULL);
  175605. #endif
  175606. #ifdef PNG_SETJMP_SUPPORTED
  175607. #ifdef USE_FAR_KEYWORD
  175608. if (setjmp(jmpbuf))
  175609. PNG_ABORT();
  175610. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  175611. #else
  175612. if (setjmp(png_ptr->jmpbuf))
  175613. PNG_ABORT();
  175614. #endif
  175615. #endif
  175616. return (png_ptr);
  175617. }
  175618. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  175619. #undef png_write_init
  175620. void PNGAPI
  175621. png_write_init(png_structp png_ptr)
  175622. {
  175623. png_write_init_2(png_ptr, "1.0.6 or earlier", 0, 0);
  175624. }
  175625. void PNGAPI
  175626. png_write_init_2(png_structp png_ptr, png_const_charp user_png_ver,
  175627. png_size_t png_struct_size, png_size_t png_info_size)
  175628. {
  175629. if(png_ptr == NULL) return;
  175630. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  175631. if(png_sizeof(png_struct) > png_struct_size ||
  175632. png_sizeof(png_info) > png_info_size)
  175633. {
  175634. char msg[80];
  175635. png_ptr->warning_fn=NULL;
  175636. if (user_png_ver)
  175637. {
  175638. png_snprintf(msg, 80,
  175639. "Application was compiled with png.h from libpng-%.20s",
  175640. user_png_ver);
  175641. png_warning(png_ptr, msg);
  175642. }
  175643. png_snprintf(msg, 80,
  175644. "Application is running with png.c from libpng-%.20s",
  175645. png_libpng_ver);
  175646. png_warning(png_ptr, msg);
  175647. }
  175648. #endif
  175649. if(png_sizeof(png_struct) > png_struct_size)
  175650. {
  175651. png_ptr->error_fn=NULL;
  175652. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  175653. png_ptr->flags=0;
  175654. #endif
  175655. png_error(png_ptr,
  175656. "The png struct allocated by the application for writing is too small.");
  175657. }
  175658. if(png_sizeof(png_info) > png_info_size)
  175659. {
  175660. png_ptr->error_fn=NULL;
  175661. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  175662. png_ptr->flags=0;
  175663. #endif
  175664. png_error(png_ptr,
  175665. "The info struct allocated by the application for writing is too small.");
  175666. }
  175667. png_write_init_3(&png_ptr, user_png_ver, png_struct_size);
  175668. }
  175669. #endif /* PNG_1_0_X || PNG_1_2_X */
  175670. void PNGAPI
  175671. png_write_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
  175672. png_size_t png_struct_size)
  175673. {
  175674. png_structp png_ptr=*ptr_ptr;
  175675. #ifdef PNG_SETJMP_SUPPORTED
  175676. jmp_buf tmp_jmp; /* to save current jump buffer */
  175677. #endif
  175678. int i = 0;
  175679. if (png_ptr == NULL)
  175680. return;
  175681. do
  175682. {
  175683. if (user_png_ver[i] != png_libpng_ver[i])
  175684. {
  175685. #ifdef PNG_LEGACY_SUPPORTED
  175686. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  175687. #else
  175688. png_ptr->warning_fn=NULL;
  175689. png_warning(png_ptr,
  175690. "Application uses deprecated png_write_init() and should be recompiled.");
  175691. break;
  175692. #endif
  175693. }
  175694. } while (png_libpng_ver[i++]);
  175695. png_debug(1, "in png_write_init_3\n");
  175696. #ifdef PNG_SETJMP_SUPPORTED
  175697. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  175698. #endif
  175699. if (png_sizeof(png_struct) > png_struct_size)
  175700. {
  175701. png_destroy_struct(png_ptr);
  175702. png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  175703. *ptr_ptr = png_ptr;
  175704. }
  175705. png_memset(png_ptr, 0, png_sizeof (png_struct));
  175706. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  175707. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  175708. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  175709. #endif
  175710. #ifdef PNG_SETJMP_SUPPORTED
  175711. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  175712. #endif
  175713. png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL,
  175714. png_flush_ptr_NULL);
  175715. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  175716. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  175717. (png_uint_32)png_ptr->zbuf_size);
  175718. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  175719. png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
  175720. 1, png_doublep_NULL, png_doublep_NULL);
  175721. #endif
  175722. }
  175723. void PNGAPI
  175724. png_write_rows(png_structp png_ptr, png_bytepp row,
  175725. png_uint_32 num_rows)
  175726. {
  175727. png_uint_32 i; /* row counter */
  175728. png_bytepp rp; /* row pointer */
  175729. png_debug(1, "in png_write_rows\n");
  175730. if (png_ptr == NULL)
  175731. return;
  175732. for (i = 0, rp = row; i < num_rows; i++, rp++)
  175733. {
  175734. png_write_row(png_ptr, *rp);
  175735. }
  175736. }
  175737. void PNGAPI
  175738. png_write_image(png_structp png_ptr, png_bytepp image)
  175739. {
  175740. png_uint_32 i; /* row index */
  175741. int pass, num_pass; /* pass variables */
  175742. png_bytepp rp; /* points to current row */
  175743. if (png_ptr == NULL)
  175744. return;
  175745. png_debug(1, "in png_write_image\n");
  175746. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  175747. num_pass = png_set_interlace_handling(png_ptr);
  175748. #else
  175749. num_pass = 1;
  175750. #endif
  175751. for (pass = 0; pass < num_pass; pass++)
  175752. {
  175753. for (i = 0, rp = image; i < png_ptr->height; i++, rp++)
  175754. {
  175755. png_write_row(png_ptr, *rp);
  175756. }
  175757. }
  175758. }
  175759. void PNGAPI
  175760. png_write_row(png_structp png_ptr, png_bytep row)
  175761. {
  175762. if (png_ptr == NULL)
  175763. return;
  175764. png_debug2(1, "in png_write_row (row %ld, pass %d)\n",
  175765. png_ptr->row_number, png_ptr->pass);
  175766. if (png_ptr->row_number == 0 && png_ptr->pass == 0)
  175767. {
  175768. if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
  175769. png_error(png_ptr,
  175770. "png_write_info was never called before png_write_row.");
  175771. #if !defined(PNG_WRITE_INVERT_SUPPORTED) && defined(PNG_READ_INVERT_SUPPORTED)
  175772. if (png_ptr->transformations & PNG_INVERT_MONO)
  175773. png_warning(png_ptr, "PNG_WRITE_INVERT_SUPPORTED is not defined.");
  175774. #endif
  175775. #if !defined(PNG_WRITE_FILLER_SUPPORTED) && defined(PNG_READ_FILLER_SUPPORTED)
  175776. if (png_ptr->transformations & PNG_FILLER)
  175777. png_warning(png_ptr, "PNG_WRITE_FILLER_SUPPORTED is not defined.");
  175778. #endif
  175779. #if !defined(PNG_WRITE_PACKSWAP_SUPPORTED) && defined(PNG_READ_PACKSWAP_SUPPORTED)
  175780. if (png_ptr->transformations & PNG_PACKSWAP)
  175781. png_warning(png_ptr, "PNG_WRITE_PACKSWAP_SUPPORTED is not defined.");
  175782. #endif
  175783. #if !defined(PNG_WRITE_PACK_SUPPORTED) && defined(PNG_READ_PACK_SUPPORTED)
  175784. if (png_ptr->transformations & PNG_PACK)
  175785. png_warning(png_ptr, "PNG_WRITE_PACK_SUPPORTED is not defined.");
  175786. #endif
  175787. #if !defined(PNG_WRITE_SHIFT_SUPPORTED) && defined(PNG_READ_SHIFT_SUPPORTED)
  175788. if (png_ptr->transformations & PNG_SHIFT)
  175789. png_warning(png_ptr, "PNG_WRITE_SHIFT_SUPPORTED is not defined.");
  175790. #endif
  175791. #if !defined(PNG_WRITE_BGR_SUPPORTED) && defined(PNG_READ_BGR_SUPPORTED)
  175792. if (png_ptr->transformations & PNG_BGR)
  175793. png_warning(png_ptr, "PNG_WRITE_BGR_SUPPORTED is not defined.");
  175794. #endif
  175795. #if !defined(PNG_WRITE_SWAP_SUPPORTED) && defined(PNG_READ_SWAP_SUPPORTED)
  175796. if (png_ptr->transformations & PNG_SWAP_BYTES)
  175797. png_warning(png_ptr, "PNG_WRITE_SWAP_SUPPORTED is not defined.");
  175798. #endif
  175799. png_write_start_row(png_ptr);
  175800. }
  175801. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  175802. if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
  175803. {
  175804. switch (png_ptr->pass)
  175805. {
  175806. case 0:
  175807. if (png_ptr->row_number & 0x07)
  175808. {
  175809. png_write_finish_row(png_ptr);
  175810. return;
  175811. }
  175812. break;
  175813. case 1:
  175814. if ((png_ptr->row_number & 0x07) || png_ptr->width < 5)
  175815. {
  175816. png_write_finish_row(png_ptr);
  175817. return;
  175818. }
  175819. break;
  175820. case 2:
  175821. if ((png_ptr->row_number & 0x07) != 4)
  175822. {
  175823. png_write_finish_row(png_ptr);
  175824. return;
  175825. }
  175826. break;
  175827. case 3:
  175828. if ((png_ptr->row_number & 0x03) || png_ptr->width < 3)
  175829. {
  175830. png_write_finish_row(png_ptr);
  175831. return;
  175832. }
  175833. break;
  175834. case 4:
  175835. if ((png_ptr->row_number & 0x03) != 2)
  175836. {
  175837. png_write_finish_row(png_ptr);
  175838. return;
  175839. }
  175840. break;
  175841. case 5:
  175842. if ((png_ptr->row_number & 0x01) || png_ptr->width < 2)
  175843. {
  175844. png_write_finish_row(png_ptr);
  175845. return;
  175846. }
  175847. break;
  175848. case 6:
  175849. if (!(png_ptr->row_number & 0x01))
  175850. {
  175851. png_write_finish_row(png_ptr);
  175852. return;
  175853. }
  175854. break;
  175855. }
  175856. }
  175857. #endif
  175858. png_ptr->row_info.color_type = png_ptr->color_type;
  175859. png_ptr->row_info.width = png_ptr->usr_width;
  175860. png_ptr->row_info.channels = png_ptr->usr_channels;
  175861. png_ptr->row_info.bit_depth = png_ptr->usr_bit_depth;
  175862. png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth *
  175863. png_ptr->row_info.channels);
  175864. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  175865. png_ptr->row_info.width);
  175866. png_debug1(3, "row_info->color_type = %d\n", png_ptr->row_info.color_type);
  175867. png_debug1(3, "row_info->width = %lu\n", png_ptr->row_info.width);
  175868. png_debug1(3, "row_info->channels = %d\n", png_ptr->row_info.channels);
  175869. png_debug1(3, "row_info->bit_depth = %d\n", png_ptr->row_info.bit_depth);
  175870. png_debug1(3, "row_info->pixel_depth = %d\n", png_ptr->row_info.pixel_depth);
  175871. png_debug1(3, "row_info->rowbytes = %lu\n", png_ptr->row_info.rowbytes);
  175872. png_memcpy_check(png_ptr, png_ptr->row_buf + 1, row,
  175873. png_ptr->row_info.rowbytes);
  175874. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  175875. if (png_ptr->interlaced && png_ptr->pass < 6 &&
  175876. (png_ptr->transformations & PNG_INTERLACE))
  175877. {
  175878. png_do_write_interlace(&(png_ptr->row_info),
  175879. png_ptr->row_buf + 1, png_ptr->pass);
  175880. if (!(png_ptr->row_info.width))
  175881. {
  175882. png_write_finish_row(png_ptr);
  175883. return;
  175884. }
  175885. }
  175886. #endif
  175887. if (png_ptr->transformations)
  175888. png_do_write_transformations(png_ptr);
  175889. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  175890. if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  175891. (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
  175892. {
  175893. png_do_write_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1);
  175894. }
  175895. #endif
  175896. png_write_find_filter(png_ptr, &(png_ptr->row_info));
  175897. if (png_ptr->write_row_fn != NULL)
  175898. (*(png_ptr->write_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
  175899. }
  175900. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  175901. void PNGAPI
  175902. png_set_flush(png_structp png_ptr, int nrows)
  175903. {
  175904. png_debug(1, "in png_set_flush\n");
  175905. if (png_ptr == NULL)
  175906. return;
  175907. png_ptr->flush_dist = (nrows < 0 ? 0 : nrows);
  175908. }
  175909. void PNGAPI
  175910. png_write_flush(png_structp png_ptr)
  175911. {
  175912. int wrote_IDAT;
  175913. png_debug(1, "in png_write_flush\n");
  175914. if (png_ptr == NULL)
  175915. return;
  175916. if (png_ptr->row_number >= png_ptr->num_rows)
  175917. return;
  175918. do
  175919. {
  175920. int ret;
  175921. ret = deflate(&png_ptr->zstream, Z_SYNC_FLUSH);
  175922. wrote_IDAT = 0;
  175923. if (ret != Z_OK)
  175924. {
  175925. if (png_ptr->zstream.msg != NULL)
  175926. png_error(png_ptr, png_ptr->zstream.msg);
  175927. else
  175928. png_error(png_ptr, "zlib error");
  175929. }
  175930. if (!(png_ptr->zstream.avail_out))
  175931. {
  175932. png_write_IDAT(png_ptr, png_ptr->zbuf,
  175933. png_ptr->zbuf_size);
  175934. png_ptr->zstream.next_out = png_ptr->zbuf;
  175935. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  175936. wrote_IDAT = 1;
  175937. }
  175938. } while(wrote_IDAT == 1);
  175939. if (png_ptr->zbuf_size != png_ptr->zstream.avail_out)
  175940. {
  175941. png_write_IDAT(png_ptr, png_ptr->zbuf,
  175942. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  175943. png_ptr->zstream.next_out = png_ptr->zbuf;
  175944. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  175945. }
  175946. png_ptr->flush_rows = 0;
  175947. png_flush(png_ptr);
  175948. }
  175949. #endif /* PNG_WRITE_FLUSH_SUPPORTED */
  175950. void PNGAPI
  175951. png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr)
  175952. {
  175953. png_structp png_ptr = NULL;
  175954. png_infop info_ptr = NULL;
  175955. #ifdef PNG_USER_MEM_SUPPORTED
  175956. png_free_ptr free_fn = NULL;
  175957. png_voidp mem_ptr = NULL;
  175958. #endif
  175959. png_debug(1, "in png_destroy_write_struct\n");
  175960. if (png_ptr_ptr != NULL)
  175961. {
  175962. png_ptr = *png_ptr_ptr;
  175963. #ifdef PNG_USER_MEM_SUPPORTED
  175964. free_fn = png_ptr->free_fn;
  175965. mem_ptr = png_ptr->mem_ptr;
  175966. #endif
  175967. }
  175968. if (info_ptr_ptr != NULL)
  175969. info_ptr = *info_ptr_ptr;
  175970. if (info_ptr != NULL)
  175971. {
  175972. png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
  175973. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  175974. if (png_ptr->num_chunk_list)
  175975. {
  175976. png_free(png_ptr, png_ptr->chunk_list);
  175977. png_ptr->chunk_list=NULL;
  175978. png_ptr->num_chunk_list=0;
  175979. }
  175980. #endif
  175981. #ifdef PNG_USER_MEM_SUPPORTED
  175982. png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn,
  175983. (png_voidp)mem_ptr);
  175984. #else
  175985. png_destroy_struct((png_voidp)info_ptr);
  175986. #endif
  175987. *info_ptr_ptr = NULL;
  175988. }
  175989. if (png_ptr != NULL)
  175990. {
  175991. png_write_destroy(png_ptr);
  175992. #ifdef PNG_USER_MEM_SUPPORTED
  175993. png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn,
  175994. (png_voidp)mem_ptr);
  175995. #else
  175996. png_destroy_struct((png_voidp)png_ptr);
  175997. #endif
  175998. *png_ptr_ptr = NULL;
  175999. }
  176000. }
  176001. void /* PRIVATE */
  176002. png_write_destroy(png_structp png_ptr)
  176003. {
  176004. #ifdef PNG_SETJMP_SUPPORTED
  176005. jmp_buf tmp_jmp; /* save jump buffer */
  176006. #endif
  176007. png_error_ptr error_fn;
  176008. png_error_ptr warning_fn;
  176009. png_voidp error_ptr;
  176010. #ifdef PNG_USER_MEM_SUPPORTED
  176011. png_free_ptr free_fn;
  176012. #endif
  176013. png_debug(1, "in png_write_destroy\n");
  176014. deflateEnd(&png_ptr->zstream);
  176015. png_free(png_ptr, png_ptr->zbuf);
  176016. png_free(png_ptr, png_ptr->row_buf);
  176017. png_free(png_ptr, png_ptr->prev_row);
  176018. png_free(png_ptr, png_ptr->sub_row);
  176019. png_free(png_ptr, png_ptr->up_row);
  176020. png_free(png_ptr, png_ptr->avg_row);
  176021. png_free(png_ptr, png_ptr->paeth_row);
  176022. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  176023. png_free(png_ptr, png_ptr->time_buffer);
  176024. #endif
  176025. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  176026. png_free(png_ptr, png_ptr->prev_filters);
  176027. png_free(png_ptr, png_ptr->filter_weights);
  176028. png_free(png_ptr, png_ptr->inv_filter_weights);
  176029. png_free(png_ptr, png_ptr->filter_costs);
  176030. png_free(png_ptr, png_ptr->inv_filter_costs);
  176031. #endif
  176032. #ifdef PNG_SETJMP_SUPPORTED
  176033. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  176034. #endif
  176035. error_fn = png_ptr->error_fn;
  176036. warning_fn = png_ptr->warning_fn;
  176037. error_ptr = png_ptr->error_ptr;
  176038. #ifdef PNG_USER_MEM_SUPPORTED
  176039. free_fn = png_ptr->free_fn;
  176040. #endif
  176041. png_memset(png_ptr, 0, png_sizeof (png_struct));
  176042. png_ptr->error_fn = error_fn;
  176043. png_ptr->warning_fn = warning_fn;
  176044. png_ptr->error_ptr = error_ptr;
  176045. #ifdef PNG_USER_MEM_SUPPORTED
  176046. png_ptr->free_fn = free_fn;
  176047. #endif
  176048. #ifdef PNG_SETJMP_SUPPORTED
  176049. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  176050. #endif
  176051. }
  176052. void PNGAPI
  176053. png_set_filter(png_structp png_ptr, int method, int filters)
  176054. {
  176055. png_debug(1, "in png_set_filter\n");
  176056. if (png_ptr == NULL)
  176057. return;
  176058. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  176059. if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  176060. (method == PNG_INTRAPIXEL_DIFFERENCING))
  176061. method = PNG_FILTER_TYPE_BASE;
  176062. #endif
  176063. if (method == PNG_FILTER_TYPE_BASE)
  176064. {
  176065. switch (filters & (PNG_ALL_FILTERS | 0x07))
  176066. {
  176067. #ifndef PNG_NO_WRITE_FILTER
  176068. case 5:
  176069. case 6:
  176070. case 7: png_warning(png_ptr, "Unknown row filter for method 0");
  176071. #endif /* PNG_NO_WRITE_FILTER */
  176072. case PNG_FILTER_VALUE_NONE:
  176073. png_ptr->do_filter=PNG_FILTER_NONE; break;
  176074. #ifndef PNG_NO_WRITE_FILTER
  176075. case PNG_FILTER_VALUE_SUB:
  176076. png_ptr->do_filter=PNG_FILTER_SUB; break;
  176077. case PNG_FILTER_VALUE_UP:
  176078. png_ptr->do_filter=PNG_FILTER_UP; break;
  176079. case PNG_FILTER_VALUE_AVG:
  176080. png_ptr->do_filter=PNG_FILTER_AVG; break;
  176081. case PNG_FILTER_VALUE_PAETH:
  176082. png_ptr->do_filter=PNG_FILTER_PAETH; break;
  176083. default: png_ptr->do_filter = (png_byte)filters; break;
  176084. #else
  176085. default: png_warning(png_ptr, "Unknown row filter for method 0");
  176086. #endif /* PNG_NO_WRITE_FILTER */
  176087. }
  176088. if (png_ptr->row_buf != NULL)
  176089. {
  176090. #ifndef PNG_NO_WRITE_FILTER
  176091. if ((png_ptr->do_filter & PNG_FILTER_SUB) && png_ptr->sub_row == NULL)
  176092. {
  176093. png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
  176094. (png_ptr->rowbytes + 1));
  176095. png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
  176096. }
  176097. if ((png_ptr->do_filter & PNG_FILTER_UP) && png_ptr->up_row == NULL)
  176098. {
  176099. if (png_ptr->prev_row == NULL)
  176100. {
  176101. png_warning(png_ptr, "Can't add Up filter after starting");
  176102. png_ptr->do_filter &= ~PNG_FILTER_UP;
  176103. }
  176104. else
  176105. {
  176106. png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
  176107. (png_ptr->rowbytes + 1));
  176108. png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
  176109. }
  176110. }
  176111. if ((png_ptr->do_filter & PNG_FILTER_AVG) && png_ptr->avg_row == NULL)
  176112. {
  176113. if (png_ptr->prev_row == NULL)
  176114. {
  176115. png_warning(png_ptr, "Can't add Average filter after starting");
  176116. png_ptr->do_filter &= ~PNG_FILTER_AVG;
  176117. }
  176118. else
  176119. {
  176120. png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
  176121. (png_ptr->rowbytes + 1));
  176122. png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
  176123. }
  176124. }
  176125. if ((png_ptr->do_filter & PNG_FILTER_PAETH) &&
  176126. png_ptr->paeth_row == NULL)
  176127. {
  176128. if (png_ptr->prev_row == NULL)
  176129. {
  176130. png_warning(png_ptr, "Can't add Paeth filter after starting");
  176131. png_ptr->do_filter &= (png_byte)(~PNG_FILTER_PAETH);
  176132. }
  176133. else
  176134. {
  176135. png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
  176136. (png_ptr->rowbytes + 1));
  176137. png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
  176138. }
  176139. }
  176140. if (png_ptr->do_filter == PNG_NO_FILTERS)
  176141. #endif /* PNG_NO_WRITE_FILTER */
  176142. png_ptr->do_filter = PNG_FILTER_NONE;
  176143. }
  176144. }
  176145. else
  176146. png_error(png_ptr, "Unknown custom filter method");
  176147. }
  176148. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) /* GRR 970116 */
  176149. void PNGAPI
  176150. png_set_filter_heuristics(png_structp png_ptr, int heuristic_method,
  176151. int num_weights, png_doublep filter_weights,
  176152. png_doublep filter_costs)
  176153. {
  176154. int i;
  176155. png_debug(1, "in png_set_filter_heuristics\n");
  176156. if (png_ptr == NULL)
  176157. return;
  176158. if (heuristic_method >= PNG_FILTER_HEURISTIC_LAST)
  176159. {
  176160. png_warning(png_ptr, "Unknown filter heuristic method");
  176161. return;
  176162. }
  176163. if (heuristic_method == PNG_FILTER_HEURISTIC_DEFAULT)
  176164. {
  176165. heuristic_method = PNG_FILTER_HEURISTIC_UNWEIGHTED;
  176166. }
  176167. if (num_weights < 0 || filter_weights == NULL ||
  176168. heuristic_method == PNG_FILTER_HEURISTIC_UNWEIGHTED)
  176169. {
  176170. num_weights = 0;
  176171. }
  176172. png_ptr->num_prev_filters = (png_byte)num_weights;
  176173. png_ptr->heuristic_method = (png_byte)heuristic_method;
  176174. if (num_weights > 0)
  176175. {
  176176. if (png_ptr->prev_filters == NULL)
  176177. {
  176178. png_ptr->prev_filters = (png_bytep)png_malloc(png_ptr,
  176179. (png_uint_32)(png_sizeof(png_byte) * num_weights));
  176180. for (i = 0; i < num_weights; i++)
  176181. {
  176182. png_ptr->prev_filters[i] = 255;
  176183. }
  176184. }
  176185. if (png_ptr->filter_weights == NULL)
  176186. {
  176187. png_ptr->filter_weights = (png_uint_16p)png_malloc(png_ptr,
  176188. (png_uint_32)(png_sizeof(png_uint_16) * num_weights));
  176189. png_ptr->inv_filter_weights = (png_uint_16p)png_malloc(png_ptr,
  176190. (png_uint_32)(png_sizeof(png_uint_16) * num_weights));
  176191. for (i = 0; i < num_weights; i++)
  176192. {
  176193. png_ptr->inv_filter_weights[i] =
  176194. png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR;
  176195. }
  176196. }
  176197. for (i = 0; i < num_weights; i++)
  176198. {
  176199. if (filter_weights[i] < 0.0)
  176200. {
  176201. png_ptr->inv_filter_weights[i] =
  176202. png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR;
  176203. }
  176204. else
  176205. {
  176206. png_ptr->inv_filter_weights[i] =
  176207. (png_uint_16)((double)PNG_WEIGHT_FACTOR*filter_weights[i]+0.5);
  176208. png_ptr->filter_weights[i] =
  176209. (png_uint_16)((double)PNG_WEIGHT_FACTOR/filter_weights[i]+0.5);
  176210. }
  176211. }
  176212. }
  176213. if (png_ptr->filter_costs == NULL)
  176214. {
  176215. png_ptr->filter_costs = (png_uint_16p)png_malloc(png_ptr,
  176216. (png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
  176217. png_ptr->inv_filter_costs = (png_uint_16p)png_malloc(png_ptr,
  176218. (png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
  176219. for (i = 0; i < PNG_FILTER_VALUE_LAST; i++)
  176220. {
  176221. png_ptr->inv_filter_costs[i] =
  176222. png_ptr->filter_costs[i] = PNG_COST_FACTOR;
  176223. }
  176224. }
  176225. for (i = 0; i < PNG_FILTER_VALUE_LAST; i++)
  176226. {
  176227. if (filter_costs == NULL || filter_costs[i] < 0.0)
  176228. {
  176229. png_ptr->inv_filter_costs[i] =
  176230. png_ptr->filter_costs[i] = PNG_COST_FACTOR;
  176231. }
  176232. else if (filter_costs[i] >= 1.0)
  176233. {
  176234. png_ptr->inv_filter_costs[i] =
  176235. (png_uint_16)((double)PNG_COST_FACTOR / filter_costs[i] + 0.5);
  176236. png_ptr->filter_costs[i] =
  176237. (png_uint_16)((double)PNG_COST_FACTOR * filter_costs[i] + 0.5);
  176238. }
  176239. }
  176240. }
  176241. #endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
  176242. void PNGAPI
  176243. png_set_compression_level(png_structp png_ptr, int level)
  176244. {
  176245. png_debug(1, "in png_set_compression_level\n");
  176246. if (png_ptr == NULL)
  176247. return;
  176248. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_LEVEL;
  176249. png_ptr->zlib_level = level;
  176250. }
  176251. void PNGAPI
  176252. png_set_compression_mem_level(png_structp png_ptr, int mem_level)
  176253. {
  176254. png_debug(1, "in png_set_compression_mem_level\n");
  176255. if (png_ptr == NULL)
  176256. return;
  176257. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL;
  176258. png_ptr->zlib_mem_level = mem_level;
  176259. }
  176260. void PNGAPI
  176261. png_set_compression_strategy(png_structp png_ptr, int strategy)
  176262. {
  176263. png_debug(1, "in png_set_compression_strategy\n");
  176264. if (png_ptr == NULL)
  176265. return;
  176266. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_STRATEGY;
  176267. png_ptr->zlib_strategy = strategy;
  176268. }
  176269. void PNGAPI
  176270. png_set_compression_window_bits(png_structp png_ptr, int window_bits)
  176271. {
  176272. if (png_ptr == NULL)
  176273. return;
  176274. if (window_bits > 15)
  176275. png_warning(png_ptr, "Only compression windows <= 32k supported by PNG");
  176276. else if (window_bits < 8)
  176277. png_warning(png_ptr, "Only compression windows >= 256 supported by PNG");
  176278. #ifndef WBITS_8_OK
  176279. if (window_bits == 8)
  176280. {
  176281. png_warning(png_ptr, "Compression window is being reset to 512");
  176282. window_bits=9;
  176283. }
  176284. #endif
  176285. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS;
  176286. png_ptr->zlib_window_bits = window_bits;
  176287. }
  176288. void PNGAPI
  176289. png_set_compression_method(png_structp png_ptr, int method)
  176290. {
  176291. png_debug(1, "in png_set_compression_method\n");
  176292. if (png_ptr == NULL)
  176293. return;
  176294. if (method != 8)
  176295. png_warning(png_ptr, "Only compression method 8 is supported by PNG");
  176296. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_METHOD;
  176297. png_ptr->zlib_method = method;
  176298. }
  176299. void PNGAPI
  176300. png_set_write_status_fn(png_structp png_ptr, png_write_status_ptr write_row_fn)
  176301. {
  176302. if (png_ptr == NULL)
  176303. return;
  176304. png_ptr->write_row_fn = write_row_fn;
  176305. }
  176306. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  176307. void PNGAPI
  176308. png_set_write_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
  176309. write_user_transform_fn)
  176310. {
  176311. png_debug(1, "in png_set_write_user_transform_fn\n");
  176312. if (png_ptr == NULL)
  176313. return;
  176314. png_ptr->transformations |= PNG_USER_TRANSFORM;
  176315. png_ptr->write_user_transform_fn = write_user_transform_fn;
  176316. }
  176317. #endif
  176318. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  176319. void PNGAPI
  176320. png_write_png(png_structp png_ptr, png_infop info_ptr,
  176321. int transforms, voidp params)
  176322. {
  176323. if (png_ptr == NULL || info_ptr == NULL)
  176324. return;
  176325. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  176326. if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
  176327. png_set_invert_alpha(png_ptr);
  176328. #endif
  176329. png_write_info(png_ptr, info_ptr);
  176330. #if defined(PNG_WRITE_INVERT_SUPPORTED)
  176331. if (transforms & PNG_TRANSFORM_INVERT_MONO)
  176332. png_set_invert_mono(png_ptr);
  176333. #endif
  176334. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  176335. if ((transforms & PNG_TRANSFORM_SHIFT)
  176336. && (info_ptr->valid & PNG_INFO_sBIT))
  176337. png_set_shift(png_ptr, &info_ptr->sig_bit);
  176338. #endif
  176339. #if defined(PNG_WRITE_PACK_SUPPORTED)
  176340. if (transforms & PNG_TRANSFORM_PACKING)
  176341. png_set_packing(png_ptr);
  176342. #endif
  176343. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  176344. if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
  176345. png_set_swap_alpha(png_ptr);
  176346. #endif
  176347. #if defined(PNG_WRITE_FILLER_SUPPORTED)
  176348. if (transforms & PNG_TRANSFORM_STRIP_FILLER)
  176349. png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
  176350. #endif
  176351. #if defined(PNG_WRITE_BGR_SUPPORTED)
  176352. if (transforms & PNG_TRANSFORM_BGR)
  176353. png_set_bgr(png_ptr);
  176354. #endif
  176355. #if defined(PNG_WRITE_SWAP_SUPPORTED)
  176356. if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
  176357. png_set_swap(png_ptr);
  176358. #endif
  176359. #if defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  176360. if (transforms & PNG_TRANSFORM_PACKSWAP)
  176361. png_set_packswap(png_ptr);
  176362. #endif
  176363. if (info_ptr->valid & PNG_INFO_IDAT)
  176364. png_write_image(png_ptr, info_ptr->row_pointers);
  176365. png_write_end(png_ptr, info_ptr);
  176366. transforms = transforms; /* quiet compiler warnings */
  176367. params = params;
  176368. }
  176369. #endif
  176370. #endif /* PNG_WRITE_SUPPORTED */
  176371. /*** End of inlined file: pngwrite.c ***/
  176372. /*** Start of inlined file: pngwtran.c ***/
  176373. #define PNG_INTERNAL
  176374. #ifdef PNG_WRITE_SUPPORTED
  176375. void /* PRIVATE */
  176376. png_do_write_transformations(png_structp png_ptr)
  176377. {
  176378. png_debug(1, "in png_do_write_transformations\n");
  176379. if (png_ptr == NULL)
  176380. return;
  176381. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  176382. if (png_ptr->transformations & PNG_USER_TRANSFORM)
  176383. if(png_ptr->write_user_transform_fn != NULL)
  176384. (*(png_ptr->write_user_transform_fn)) /* user write transform function */
  176385. (png_ptr, /* png_ptr */
  176386. &(png_ptr->row_info), /* row_info: */
  176387. png_ptr->row_buf + 1); /* start of pixel data for row */
  176388. #endif
  176389. #if defined(PNG_WRITE_FILLER_SUPPORTED)
  176390. if (png_ptr->transformations & PNG_FILLER)
  176391. png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
  176392. png_ptr->flags);
  176393. #endif
  176394. #if defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  176395. if (png_ptr->transformations & PNG_PACKSWAP)
  176396. png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176397. #endif
  176398. #if defined(PNG_WRITE_PACK_SUPPORTED)
  176399. if (png_ptr->transformations & PNG_PACK)
  176400. png_do_pack(&(png_ptr->row_info), png_ptr->row_buf + 1,
  176401. (png_uint_32)png_ptr->bit_depth);
  176402. #endif
  176403. #if defined(PNG_WRITE_SWAP_SUPPORTED)
  176404. if (png_ptr->transformations & PNG_SWAP_BYTES)
  176405. png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176406. #endif
  176407. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  176408. if (png_ptr->transformations & PNG_SHIFT)
  176409. png_do_shift(&(png_ptr->row_info), png_ptr->row_buf + 1,
  176410. &(png_ptr->shift));
  176411. #endif
  176412. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  176413. if (png_ptr->transformations & PNG_SWAP_ALPHA)
  176414. png_do_write_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176415. #endif
  176416. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  176417. if (png_ptr->transformations & PNG_INVERT_ALPHA)
  176418. png_do_write_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176419. #endif
  176420. #if defined(PNG_WRITE_BGR_SUPPORTED)
  176421. if (png_ptr->transformations & PNG_BGR)
  176422. png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176423. #endif
  176424. #if defined(PNG_WRITE_INVERT_SUPPORTED)
  176425. if (png_ptr->transformations & PNG_INVERT_MONO)
  176426. png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176427. #endif
  176428. }
  176429. #if defined(PNG_WRITE_PACK_SUPPORTED)
  176430. void /* PRIVATE */
  176431. png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth)
  176432. {
  176433. png_debug(1, "in png_do_pack\n");
  176434. if (row_info->bit_depth == 8 &&
  176435. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176436. row != NULL && row_info != NULL &&
  176437. #endif
  176438. row_info->channels == 1)
  176439. {
  176440. switch ((int)bit_depth)
  176441. {
  176442. case 1:
  176443. {
  176444. png_bytep sp, dp;
  176445. int mask, v;
  176446. png_uint_32 i;
  176447. png_uint_32 row_width = row_info->width;
  176448. sp = row;
  176449. dp = row;
  176450. mask = 0x80;
  176451. v = 0;
  176452. for (i = 0; i < row_width; i++)
  176453. {
  176454. if (*sp != 0)
  176455. v |= mask;
  176456. sp++;
  176457. if (mask > 1)
  176458. mask >>= 1;
  176459. else
  176460. {
  176461. mask = 0x80;
  176462. *dp = (png_byte)v;
  176463. dp++;
  176464. v = 0;
  176465. }
  176466. }
  176467. if (mask != 0x80)
  176468. *dp = (png_byte)v;
  176469. break;
  176470. }
  176471. case 2:
  176472. {
  176473. png_bytep sp, dp;
  176474. int shift, v;
  176475. png_uint_32 i;
  176476. png_uint_32 row_width = row_info->width;
  176477. sp = row;
  176478. dp = row;
  176479. shift = 6;
  176480. v = 0;
  176481. for (i = 0; i < row_width; i++)
  176482. {
  176483. png_byte value;
  176484. value = (png_byte)(*sp & 0x03);
  176485. v |= (value << shift);
  176486. if (shift == 0)
  176487. {
  176488. shift = 6;
  176489. *dp = (png_byte)v;
  176490. dp++;
  176491. v = 0;
  176492. }
  176493. else
  176494. shift -= 2;
  176495. sp++;
  176496. }
  176497. if (shift != 6)
  176498. *dp = (png_byte)v;
  176499. break;
  176500. }
  176501. case 4:
  176502. {
  176503. png_bytep sp, dp;
  176504. int shift, v;
  176505. png_uint_32 i;
  176506. png_uint_32 row_width = row_info->width;
  176507. sp = row;
  176508. dp = row;
  176509. shift = 4;
  176510. v = 0;
  176511. for (i = 0; i < row_width; i++)
  176512. {
  176513. png_byte value;
  176514. value = (png_byte)(*sp & 0x0f);
  176515. v |= (value << shift);
  176516. if (shift == 0)
  176517. {
  176518. shift = 4;
  176519. *dp = (png_byte)v;
  176520. dp++;
  176521. v = 0;
  176522. }
  176523. else
  176524. shift -= 4;
  176525. sp++;
  176526. }
  176527. if (shift != 4)
  176528. *dp = (png_byte)v;
  176529. break;
  176530. }
  176531. }
  176532. row_info->bit_depth = (png_byte)bit_depth;
  176533. row_info->pixel_depth = (png_byte)(bit_depth * row_info->channels);
  176534. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
  176535. row_info->width);
  176536. }
  176537. }
  176538. #endif
  176539. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  176540. void /* PRIVATE */
  176541. png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth)
  176542. {
  176543. png_debug(1, "in png_do_shift\n");
  176544. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176545. if (row != NULL && row_info != NULL &&
  176546. #else
  176547. if (
  176548. #endif
  176549. row_info->color_type != PNG_COLOR_TYPE_PALETTE)
  176550. {
  176551. int shift_start[4], shift_dec[4];
  176552. int channels = 0;
  176553. if (row_info->color_type & PNG_COLOR_MASK_COLOR)
  176554. {
  176555. shift_start[channels] = row_info->bit_depth - bit_depth->red;
  176556. shift_dec[channels] = bit_depth->red;
  176557. channels++;
  176558. shift_start[channels] = row_info->bit_depth - bit_depth->green;
  176559. shift_dec[channels] = bit_depth->green;
  176560. channels++;
  176561. shift_start[channels] = row_info->bit_depth - bit_depth->blue;
  176562. shift_dec[channels] = bit_depth->blue;
  176563. channels++;
  176564. }
  176565. else
  176566. {
  176567. shift_start[channels] = row_info->bit_depth - bit_depth->gray;
  176568. shift_dec[channels] = bit_depth->gray;
  176569. channels++;
  176570. }
  176571. if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
  176572. {
  176573. shift_start[channels] = row_info->bit_depth - bit_depth->alpha;
  176574. shift_dec[channels] = bit_depth->alpha;
  176575. channels++;
  176576. }
  176577. if (row_info->bit_depth < 8)
  176578. {
  176579. png_bytep bp = row;
  176580. png_uint_32 i;
  176581. png_byte mask;
  176582. png_uint_32 row_bytes = row_info->rowbytes;
  176583. if (bit_depth->gray == 1 && row_info->bit_depth == 2)
  176584. mask = 0x55;
  176585. else if (row_info->bit_depth == 4 && bit_depth->gray == 3)
  176586. mask = 0x11;
  176587. else
  176588. mask = 0xff;
  176589. for (i = 0; i < row_bytes; i++, bp++)
  176590. {
  176591. png_uint_16 v;
  176592. int j;
  176593. v = *bp;
  176594. *bp = 0;
  176595. for (j = shift_start[0]; j > -shift_dec[0]; j -= shift_dec[0])
  176596. {
  176597. if (j > 0)
  176598. *bp |= (png_byte)((v << j) & 0xff);
  176599. else
  176600. *bp |= (png_byte)((v >> (-j)) & mask);
  176601. }
  176602. }
  176603. }
  176604. else if (row_info->bit_depth == 8)
  176605. {
  176606. png_bytep bp = row;
  176607. png_uint_32 i;
  176608. png_uint_32 istop = channels * row_info->width;
  176609. for (i = 0; i < istop; i++, bp++)
  176610. {
  176611. png_uint_16 v;
  176612. int j;
  176613. int c = (int)(i%channels);
  176614. v = *bp;
  176615. *bp = 0;
  176616. for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
  176617. {
  176618. if (j > 0)
  176619. *bp |= (png_byte)((v << j) & 0xff);
  176620. else
  176621. *bp |= (png_byte)((v >> (-j)) & 0xff);
  176622. }
  176623. }
  176624. }
  176625. else
  176626. {
  176627. png_bytep bp;
  176628. png_uint_32 i;
  176629. png_uint_32 istop = channels * row_info->width;
  176630. for (bp = row, i = 0; i < istop; i++)
  176631. {
  176632. int c = (int)(i%channels);
  176633. png_uint_16 value, v;
  176634. int j;
  176635. v = (png_uint_16)(((png_uint_16)(*bp) << 8) + *(bp + 1));
  176636. value = 0;
  176637. for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
  176638. {
  176639. if (j > 0)
  176640. value |= (png_uint_16)((v << j) & (png_uint_16)0xffff);
  176641. else
  176642. value |= (png_uint_16)((v >> (-j)) & (png_uint_16)0xffff);
  176643. }
  176644. *bp++ = (png_byte)(value >> 8);
  176645. *bp++ = (png_byte)(value & 0xff);
  176646. }
  176647. }
  176648. }
  176649. }
  176650. #endif
  176651. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  176652. void /* PRIVATE */
  176653. png_do_write_swap_alpha(png_row_infop row_info, png_bytep row)
  176654. {
  176655. png_debug(1, "in png_do_write_swap_alpha\n");
  176656. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176657. if (row != NULL && row_info != NULL)
  176658. #endif
  176659. {
  176660. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  176661. {
  176662. if (row_info->bit_depth == 8)
  176663. {
  176664. png_bytep sp, dp;
  176665. png_uint_32 i;
  176666. png_uint_32 row_width = row_info->width;
  176667. for (i = 0, sp = dp = row; i < row_width; i++)
  176668. {
  176669. png_byte save = *(sp++);
  176670. *(dp++) = *(sp++);
  176671. *(dp++) = *(sp++);
  176672. *(dp++) = *(sp++);
  176673. *(dp++) = save;
  176674. }
  176675. }
  176676. else
  176677. {
  176678. png_bytep sp, dp;
  176679. png_uint_32 i;
  176680. png_uint_32 row_width = row_info->width;
  176681. for (i = 0, sp = dp = row; i < row_width; i++)
  176682. {
  176683. png_byte save[2];
  176684. save[0] = *(sp++);
  176685. save[1] = *(sp++);
  176686. *(dp++) = *(sp++);
  176687. *(dp++) = *(sp++);
  176688. *(dp++) = *(sp++);
  176689. *(dp++) = *(sp++);
  176690. *(dp++) = *(sp++);
  176691. *(dp++) = *(sp++);
  176692. *(dp++) = save[0];
  176693. *(dp++) = save[1];
  176694. }
  176695. }
  176696. }
  176697. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  176698. {
  176699. if (row_info->bit_depth == 8)
  176700. {
  176701. png_bytep sp, dp;
  176702. png_uint_32 i;
  176703. png_uint_32 row_width = row_info->width;
  176704. for (i = 0, sp = dp = row; i < row_width; i++)
  176705. {
  176706. png_byte save = *(sp++);
  176707. *(dp++) = *(sp++);
  176708. *(dp++) = save;
  176709. }
  176710. }
  176711. else
  176712. {
  176713. png_bytep sp, dp;
  176714. png_uint_32 i;
  176715. png_uint_32 row_width = row_info->width;
  176716. for (i = 0, sp = dp = row; i < row_width; i++)
  176717. {
  176718. png_byte save[2];
  176719. save[0] = *(sp++);
  176720. save[1] = *(sp++);
  176721. *(dp++) = *(sp++);
  176722. *(dp++) = *(sp++);
  176723. *(dp++) = save[0];
  176724. *(dp++) = save[1];
  176725. }
  176726. }
  176727. }
  176728. }
  176729. }
  176730. #endif
  176731. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  176732. void /* PRIVATE */
  176733. png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
  176734. {
  176735. png_debug(1, "in png_do_write_invert_alpha\n");
  176736. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176737. if (row != NULL && row_info != NULL)
  176738. #endif
  176739. {
  176740. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  176741. {
  176742. if (row_info->bit_depth == 8)
  176743. {
  176744. png_bytep sp, dp;
  176745. png_uint_32 i;
  176746. png_uint_32 row_width = row_info->width;
  176747. for (i = 0, sp = dp = row; i < row_width; i++)
  176748. {
  176749. sp+=3; dp = sp;
  176750. *(dp++) = (png_byte)(255 - *(sp++));
  176751. }
  176752. }
  176753. else
  176754. {
  176755. png_bytep sp, dp;
  176756. png_uint_32 i;
  176757. png_uint_32 row_width = row_info->width;
  176758. for (i = 0, sp = dp = row; i < row_width; i++)
  176759. {
  176760. sp+=6; dp = sp;
  176761. *(dp++) = (png_byte)(255 - *(sp++));
  176762. *(dp++) = (png_byte)(255 - *(sp++));
  176763. }
  176764. }
  176765. }
  176766. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  176767. {
  176768. if (row_info->bit_depth == 8)
  176769. {
  176770. png_bytep sp, dp;
  176771. png_uint_32 i;
  176772. png_uint_32 row_width = row_info->width;
  176773. for (i = 0, sp = dp = row; i < row_width; i++)
  176774. {
  176775. *(dp++) = *(sp++);
  176776. *(dp++) = (png_byte)(255 - *(sp++));
  176777. }
  176778. }
  176779. else
  176780. {
  176781. png_bytep sp, dp;
  176782. png_uint_32 i;
  176783. png_uint_32 row_width = row_info->width;
  176784. for (i = 0, sp = dp = row; i < row_width; i++)
  176785. {
  176786. sp+=2; dp = sp;
  176787. *(dp++) = (png_byte)(255 - *(sp++));
  176788. *(dp++) = (png_byte)(255 - *(sp++));
  176789. }
  176790. }
  176791. }
  176792. }
  176793. }
  176794. #endif
  176795. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  176796. void /* PRIVATE */
  176797. png_do_write_intrapixel(png_row_infop row_info, png_bytep row)
  176798. {
  176799. png_debug(1, "in png_do_write_intrapixel\n");
  176800. if (
  176801. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176802. row != NULL && row_info != NULL &&
  176803. #endif
  176804. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  176805. {
  176806. int bytes_per_pixel;
  176807. png_uint_32 row_width = row_info->width;
  176808. if (row_info->bit_depth == 8)
  176809. {
  176810. png_bytep rp;
  176811. png_uint_32 i;
  176812. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  176813. bytes_per_pixel = 3;
  176814. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  176815. bytes_per_pixel = 4;
  176816. else
  176817. return;
  176818. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  176819. {
  176820. *(rp) = (png_byte)((*rp - *(rp+1))&0xff);
  176821. *(rp+2) = (png_byte)((*(rp+2) - *(rp+1))&0xff);
  176822. }
  176823. }
  176824. else if (row_info->bit_depth == 16)
  176825. {
  176826. png_bytep rp;
  176827. png_uint_32 i;
  176828. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  176829. bytes_per_pixel = 6;
  176830. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  176831. bytes_per_pixel = 8;
  176832. else
  176833. return;
  176834. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  176835. {
  176836. png_uint_32 s0 = (*(rp ) << 8) | *(rp+1);
  176837. png_uint_32 s1 = (*(rp+2) << 8) | *(rp+3);
  176838. png_uint_32 s2 = (*(rp+4) << 8) | *(rp+5);
  176839. png_uint_32 red = (png_uint_32)((s0-s1) & 0xffffL);
  176840. png_uint_32 blue = (png_uint_32)((s2-s1) & 0xffffL);
  176841. *(rp ) = (png_byte)((red >> 8) & 0xff);
  176842. *(rp+1) = (png_byte)(red & 0xff);
  176843. *(rp+4) = (png_byte)((blue >> 8) & 0xff);
  176844. *(rp+5) = (png_byte)(blue & 0xff);
  176845. }
  176846. }
  176847. }
  176848. }
  176849. #endif /* PNG_MNG_FEATURES_SUPPORTED */
  176850. #endif /* PNG_WRITE_SUPPORTED */
  176851. /*** End of inlined file: pngwtran.c ***/
  176852. /*** Start of inlined file: pngwutil.c ***/
  176853. #define PNG_INTERNAL
  176854. #ifdef PNG_WRITE_SUPPORTED
  176855. void PNGAPI
  176856. png_save_uint_32(png_bytep buf, png_uint_32 i)
  176857. {
  176858. buf[0] = (png_byte)((i >> 24) & 0xff);
  176859. buf[1] = (png_byte)((i >> 16) & 0xff);
  176860. buf[2] = (png_byte)((i >> 8) & 0xff);
  176861. buf[3] = (png_byte)(i & 0xff);
  176862. }
  176863. void PNGAPI
  176864. png_save_int_32(png_bytep buf, png_int_32 i)
  176865. {
  176866. buf[0] = (png_byte)((i >> 24) & 0xff);
  176867. buf[1] = (png_byte)((i >> 16) & 0xff);
  176868. buf[2] = (png_byte)((i >> 8) & 0xff);
  176869. buf[3] = (png_byte)(i & 0xff);
  176870. }
  176871. void PNGAPI
  176872. png_save_uint_16(png_bytep buf, unsigned int i)
  176873. {
  176874. buf[0] = (png_byte)((i >> 8) & 0xff);
  176875. buf[1] = (png_byte)(i & 0xff);
  176876. }
  176877. void PNGAPI
  176878. png_write_chunk(png_structp png_ptr, png_bytep chunk_name,
  176879. png_bytep data, png_size_t length)
  176880. {
  176881. if(png_ptr == NULL) return;
  176882. png_write_chunk_start(png_ptr, chunk_name, (png_uint_32)length);
  176883. png_write_chunk_data(png_ptr, data, length);
  176884. png_write_chunk_end(png_ptr);
  176885. }
  176886. void PNGAPI
  176887. png_write_chunk_start(png_structp png_ptr, png_bytep chunk_name,
  176888. png_uint_32 length)
  176889. {
  176890. png_byte buf[4];
  176891. png_debug2(0, "Writing %s chunk (%lu bytes)\n", chunk_name, length);
  176892. if(png_ptr == NULL) return;
  176893. png_save_uint_32(buf, length);
  176894. png_write_data(png_ptr, buf, (png_size_t)4);
  176895. png_write_data(png_ptr, chunk_name, (png_size_t)4);
  176896. png_reset_crc(png_ptr);
  176897. png_calculate_crc(png_ptr, chunk_name, (png_size_t)4);
  176898. }
  176899. void PNGAPI
  176900. png_write_chunk_data(png_structp png_ptr, png_bytep data, png_size_t length)
  176901. {
  176902. if(png_ptr == NULL) return;
  176903. if (data != NULL && length > 0)
  176904. {
  176905. png_calculate_crc(png_ptr, data, length);
  176906. png_write_data(png_ptr, data, length);
  176907. }
  176908. }
  176909. void PNGAPI
  176910. png_write_chunk_end(png_structp png_ptr)
  176911. {
  176912. png_byte buf[4];
  176913. if(png_ptr == NULL) return;
  176914. png_save_uint_32(buf, png_ptr->crc);
  176915. png_write_data(png_ptr, buf, (png_size_t)4);
  176916. }
  176917. void /* PRIVATE */
  176918. png_write_sig(png_structp png_ptr)
  176919. {
  176920. png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  176921. png_write_data(png_ptr, &png_signature[png_ptr->sig_bytes],
  176922. (png_size_t)8 - png_ptr->sig_bytes);
  176923. if(png_ptr->sig_bytes < 3)
  176924. png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
  176925. }
  176926. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_iCCP_SUPPORTED)
  176927. typedef struct
  176928. {
  176929. char *input; /* the uncompressed input data */
  176930. int input_len; /* its length */
  176931. int num_output_ptr; /* number of output pointers used */
  176932. int max_output_ptr; /* size of output_ptr */
  176933. png_charpp output_ptr; /* array of pointers to output */
  176934. } compression_state;
  176935. static int /* PRIVATE */
  176936. png_text_compress(png_structp png_ptr,
  176937. png_charp text, png_size_t text_len, int compression,
  176938. compression_state *comp)
  176939. {
  176940. int ret;
  176941. comp->num_output_ptr = 0;
  176942. comp->max_output_ptr = 0;
  176943. comp->output_ptr = NULL;
  176944. comp->input = NULL;
  176945. comp->input_len = 0;
  176946. if (compression == PNG_TEXT_COMPRESSION_NONE)
  176947. {
  176948. comp->input = text;
  176949. comp->input_len = text_len;
  176950. return((int)text_len);
  176951. }
  176952. if (compression >= PNG_TEXT_COMPRESSION_LAST)
  176953. {
  176954. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  176955. char msg[50];
  176956. png_snprintf(msg, 50, "Unknown compression type %d", compression);
  176957. png_warning(png_ptr, msg);
  176958. #else
  176959. png_warning(png_ptr, "Unknown compression type");
  176960. #endif
  176961. }
  176962. png_ptr->zstream.avail_in = (uInt)text_len;
  176963. png_ptr->zstream.next_in = (Bytef *)text;
  176964. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  176965. png_ptr->zstream.next_out = (Bytef *)png_ptr->zbuf;
  176966. do
  176967. {
  176968. ret = deflate(&png_ptr->zstream, Z_NO_FLUSH);
  176969. if (ret != Z_OK)
  176970. {
  176971. if (png_ptr->zstream.msg != NULL)
  176972. png_error(png_ptr, png_ptr->zstream.msg);
  176973. else
  176974. png_error(png_ptr, "zlib error");
  176975. }
  176976. if (!(png_ptr->zstream.avail_out))
  176977. {
  176978. if (comp->num_output_ptr >= comp->max_output_ptr)
  176979. {
  176980. int old_max;
  176981. old_max = comp->max_output_ptr;
  176982. comp->max_output_ptr = comp->num_output_ptr + 4;
  176983. if (comp->output_ptr != NULL)
  176984. {
  176985. png_charpp old_ptr;
  176986. old_ptr = comp->output_ptr;
  176987. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  176988. (png_uint_32)(comp->max_output_ptr *
  176989. png_sizeof (png_charpp)));
  176990. png_memcpy(comp->output_ptr, old_ptr, old_max
  176991. * png_sizeof (png_charp));
  176992. png_free(png_ptr, old_ptr);
  176993. }
  176994. else
  176995. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  176996. (png_uint_32)(comp->max_output_ptr *
  176997. png_sizeof (png_charp)));
  176998. }
  176999. comp->output_ptr[comp->num_output_ptr] = (png_charp)png_malloc(png_ptr,
  177000. (png_uint_32)png_ptr->zbuf_size);
  177001. png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf,
  177002. png_ptr->zbuf_size);
  177003. comp->num_output_ptr++;
  177004. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  177005. png_ptr->zstream.next_out = png_ptr->zbuf;
  177006. }
  177007. } while (png_ptr->zstream.avail_in);
  177008. do
  177009. {
  177010. ret = deflate(&png_ptr->zstream, Z_FINISH);
  177011. if (ret == Z_OK)
  177012. {
  177013. if (!(png_ptr->zstream.avail_out))
  177014. {
  177015. if (comp->num_output_ptr >= comp->max_output_ptr)
  177016. {
  177017. int old_max;
  177018. old_max = comp->max_output_ptr;
  177019. comp->max_output_ptr = comp->num_output_ptr + 4;
  177020. if (comp->output_ptr != NULL)
  177021. {
  177022. png_charpp old_ptr;
  177023. old_ptr = comp->output_ptr;
  177024. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  177025. (png_uint_32)(comp->max_output_ptr *
  177026. png_sizeof (png_charpp)));
  177027. png_memcpy(comp->output_ptr, old_ptr,
  177028. old_max * png_sizeof (png_charp));
  177029. png_free(png_ptr, old_ptr);
  177030. }
  177031. else
  177032. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  177033. (png_uint_32)(comp->max_output_ptr *
  177034. png_sizeof (png_charp)));
  177035. }
  177036. comp->output_ptr[comp->num_output_ptr] =
  177037. (png_charp)png_malloc(png_ptr, (png_uint_32)png_ptr->zbuf_size);
  177038. png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf,
  177039. png_ptr->zbuf_size);
  177040. comp->num_output_ptr++;
  177041. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  177042. png_ptr->zstream.next_out = png_ptr->zbuf;
  177043. }
  177044. }
  177045. else if (ret != Z_STREAM_END)
  177046. {
  177047. if (png_ptr->zstream.msg != NULL)
  177048. png_error(png_ptr, png_ptr->zstream.msg);
  177049. else
  177050. png_error(png_ptr, "zlib error");
  177051. }
  177052. } while (ret != Z_STREAM_END);
  177053. text_len = png_ptr->zbuf_size * comp->num_output_ptr;
  177054. if (png_ptr->zstream.avail_out < png_ptr->zbuf_size)
  177055. text_len += png_ptr->zbuf_size - (png_size_t)png_ptr->zstream.avail_out;
  177056. return((int)text_len);
  177057. }
  177058. static void /* PRIVATE */
  177059. png_write_compressed_data_out(png_structp png_ptr, compression_state *comp)
  177060. {
  177061. int i;
  177062. if (comp->input)
  177063. {
  177064. png_write_chunk_data(png_ptr, (png_bytep)comp->input,
  177065. (png_size_t)comp->input_len);
  177066. return;
  177067. }
  177068. for (i = 0; i < comp->num_output_ptr; i++)
  177069. {
  177070. png_write_chunk_data(png_ptr,(png_bytep)comp->output_ptr[i],
  177071. png_ptr->zbuf_size);
  177072. png_free(png_ptr, comp->output_ptr[i]);
  177073. comp->output_ptr[i]=NULL;
  177074. }
  177075. if (comp->max_output_ptr != 0)
  177076. png_free(png_ptr, comp->output_ptr);
  177077. comp->output_ptr=NULL;
  177078. if (png_ptr->zstream.avail_out < (png_uint_32)png_ptr->zbuf_size)
  177079. png_write_chunk_data(png_ptr, png_ptr->zbuf,
  177080. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  177081. deflateReset(&png_ptr->zstream);
  177082. png_ptr->zstream.data_type = Z_BINARY;
  177083. }
  177084. #endif
  177085. void /* PRIVATE */
  177086. png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height,
  177087. int bit_depth, int color_type, int compression_type, int filter_type,
  177088. int interlace_type)
  177089. {
  177090. #ifdef PNG_USE_LOCAL_ARRAYS
  177091. PNG_IHDR;
  177092. #endif
  177093. png_byte buf[13]; /* buffer to store the IHDR info */
  177094. png_debug(1, "in png_write_IHDR\n");
  177095. switch (color_type)
  177096. {
  177097. case PNG_COLOR_TYPE_GRAY:
  177098. switch (bit_depth)
  177099. {
  177100. case 1:
  177101. case 2:
  177102. case 4:
  177103. case 8:
  177104. case 16: png_ptr->channels = 1; break;
  177105. default: png_error(png_ptr,"Invalid bit depth for grayscale image");
  177106. }
  177107. break;
  177108. case PNG_COLOR_TYPE_RGB:
  177109. if (bit_depth != 8 && bit_depth != 16)
  177110. png_error(png_ptr, "Invalid bit depth for RGB image");
  177111. png_ptr->channels = 3;
  177112. break;
  177113. case PNG_COLOR_TYPE_PALETTE:
  177114. switch (bit_depth)
  177115. {
  177116. case 1:
  177117. case 2:
  177118. case 4:
  177119. case 8: png_ptr->channels = 1; break;
  177120. default: png_error(png_ptr, "Invalid bit depth for paletted image");
  177121. }
  177122. break;
  177123. case PNG_COLOR_TYPE_GRAY_ALPHA:
  177124. if (bit_depth != 8 && bit_depth != 16)
  177125. png_error(png_ptr, "Invalid bit depth for grayscale+alpha image");
  177126. png_ptr->channels = 2;
  177127. break;
  177128. case PNG_COLOR_TYPE_RGB_ALPHA:
  177129. if (bit_depth != 8 && bit_depth != 16)
  177130. png_error(png_ptr, "Invalid bit depth for RGBA image");
  177131. png_ptr->channels = 4;
  177132. break;
  177133. default:
  177134. png_error(png_ptr, "Invalid image color type specified");
  177135. }
  177136. if (compression_type != PNG_COMPRESSION_TYPE_BASE)
  177137. {
  177138. png_warning(png_ptr, "Invalid compression type specified");
  177139. compression_type = PNG_COMPRESSION_TYPE_BASE;
  177140. }
  177141. if (
  177142. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177143. !((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  177144. ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
  177145. (color_type == PNG_COLOR_TYPE_RGB ||
  177146. color_type == PNG_COLOR_TYPE_RGB_ALPHA) &&
  177147. (filter_type == PNG_INTRAPIXEL_DIFFERENCING)) &&
  177148. #endif
  177149. filter_type != PNG_FILTER_TYPE_BASE)
  177150. {
  177151. png_warning(png_ptr, "Invalid filter type specified");
  177152. filter_type = PNG_FILTER_TYPE_BASE;
  177153. }
  177154. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  177155. if (interlace_type != PNG_INTERLACE_NONE &&
  177156. interlace_type != PNG_INTERLACE_ADAM7)
  177157. {
  177158. png_warning(png_ptr, "Invalid interlace type specified");
  177159. interlace_type = PNG_INTERLACE_ADAM7;
  177160. }
  177161. #else
  177162. interlace_type=PNG_INTERLACE_NONE;
  177163. #endif
  177164. png_ptr->bit_depth = (png_byte)bit_depth;
  177165. png_ptr->color_type = (png_byte)color_type;
  177166. png_ptr->interlaced = (png_byte)interlace_type;
  177167. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177168. png_ptr->filter_type = (png_byte)filter_type;
  177169. #endif
  177170. png_ptr->compression_type = (png_byte)compression_type;
  177171. png_ptr->width = width;
  177172. png_ptr->height = height;
  177173. png_ptr->pixel_depth = (png_byte)(bit_depth * png_ptr->channels);
  177174. png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, width);
  177175. png_ptr->usr_width = png_ptr->width;
  177176. png_ptr->usr_bit_depth = png_ptr->bit_depth;
  177177. png_ptr->usr_channels = png_ptr->channels;
  177178. png_save_uint_32(buf, width);
  177179. png_save_uint_32(buf + 4, height);
  177180. buf[8] = (png_byte)bit_depth;
  177181. buf[9] = (png_byte)color_type;
  177182. buf[10] = (png_byte)compression_type;
  177183. buf[11] = (png_byte)filter_type;
  177184. buf[12] = (png_byte)interlace_type;
  177185. png_write_chunk(png_ptr, png_IHDR, buf, (png_size_t)13);
  177186. png_ptr->zstream.zalloc = png_zalloc;
  177187. png_ptr->zstream.zfree = png_zfree;
  177188. png_ptr->zstream.opaque = (voidpf)png_ptr;
  177189. if (!(png_ptr->do_filter))
  177190. {
  177191. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE ||
  177192. png_ptr->bit_depth < 8)
  177193. png_ptr->do_filter = PNG_FILTER_NONE;
  177194. else
  177195. png_ptr->do_filter = PNG_ALL_FILTERS;
  177196. }
  177197. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_STRATEGY))
  177198. {
  177199. if (png_ptr->do_filter != PNG_FILTER_NONE)
  177200. png_ptr->zlib_strategy = Z_FILTERED;
  177201. else
  177202. png_ptr->zlib_strategy = Z_DEFAULT_STRATEGY;
  177203. }
  177204. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_LEVEL))
  177205. png_ptr->zlib_level = Z_DEFAULT_COMPRESSION;
  177206. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL))
  177207. png_ptr->zlib_mem_level = 8;
  177208. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS))
  177209. png_ptr->zlib_window_bits = 15;
  177210. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_METHOD))
  177211. png_ptr->zlib_method = 8;
  177212. if (deflateInit2(&png_ptr->zstream, png_ptr->zlib_level,
  177213. png_ptr->zlib_method, png_ptr->zlib_window_bits,
  177214. png_ptr->zlib_mem_level, png_ptr->zlib_strategy) != Z_OK)
  177215. png_error(png_ptr, "zlib failed to initialize compressor");
  177216. png_ptr->zstream.next_out = png_ptr->zbuf;
  177217. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  177218. png_ptr->zstream.data_type = Z_BINARY;
  177219. png_ptr->mode = PNG_HAVE_IHDR;
  177220. }
  177221. void /* PRIVATE */
  177222. png_write_PLTE(png_structp png_ptr, png_colorp palette, png_uint_32 num_pal)
  177223. {
  177224. #ifdef PNG_USE_LOCAL_ARRAYS
  177225. PNG_PLTE;
  177226. #endif
  177227. png_uint_32 i;
  177228. png_colorp pal_ptr;
  177229. png_byte buf[3];
  177230. png_debug(1, "in png_write_PLTE\n");
  177231. if ((
  177232. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177233. !(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) &&
  177234. #endif
  177235. num_pal == 0) || num_pal > 256)
  177236. {
  177237. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  177238. {
  177239. png_error(png_ptr, "Invalid number of colors in palette");
  177240. }
  177241. else
  177242. {
  177243. png_warning(png_ptr, "Invalid number of colors in palette");
  177244. return;
  177245. }
  177246. }
  177247. if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR))
  177248. {
  177249. png_warning(png_ptr,
  177250. "Ignoring request to write a PLTE chunk in grayscale PNG");
  177251. return;
  177252. }
  177253. png_ptr->num_palette = (png_uint_16)num_pal;
  177254. png_debug1(3, "num_palette = %d\n", png_ptr->num_palette);
  177255. png_write_chunk_start(png_ptr, png_PLTE, num_pal * 3);
  177256. #ifndef PNG_NO_POINTER_INDEXING
  177257. for (i = 0, pal_ptr = palette; i < num_pal; i++, pal_ptr++)
  177258. {
  177259. buf[0] = pal_ptr->red;
  177260. buf[1] = pal_ptr->green;
  177261. buf[2] = pal_ptr->blue;
  177262. png_write_chunk_data(png_ptr, buf, (png_size_t)3);
  177263. }
  177264. #else
  177265. pal_ptr=palette;
  177266. for (i = 0; i < num_pal; i++)
  177267. {
  177268. buf[0] = pal_ptr[i].red;
  177269. buf[1] = pal_ptr[i].green;
  177270. buf[2] = pal_ptr[i].blue;
  177271. png_write_chunk_data(png_ptr, buf, (png_size_t)3);
  177272. }
  177273. #endif
  177274. png_write_chunk_end(png_ptr);
  177275. png_ptr->mode |= PNG_HAVE_PLTE;
  177276. }
  177277. void /* PRIVATE */
  177278. png_write_IDAT(png_structp png_ptr, png_bytep data, png_size_t length)
  177279. {
  177280. #ifdef PNG_USE_LOCAL_ARRAYS
  177281. PNG_IDAT;
  177282. #endif
  177283. png_debug(1, "in png_write_IDAT\n");
  177284. if (!(png_ptr->mode & PNG_HAVE_IDAT) &&
  177285. png_ptr->compression_type == PNG_COMPRESSION_TYPE_BASE)
  177286. {
  177287. unsigned int z_cmf = data[0]; /* zlib compression method and flags */
  177288. if ((z_cmf & 0x0f) == 8 && (z_cmf & 0xf0) <= 0x70)
  177289. {
  177290. if (length >= 2 &&
  177291. png_ptr->height < 16384 && png_ptr->width < 16384)
  177292. {
  177293. png_uint_32 uncompressed_idat_size = png_ptr->height *
  177294. ((png_ptr->width *
  177295. png_ptr->channels * png_ptr->bit_depth + 15) >> 3);
  177296. unsigned int z_cinfo = z_cmf >> 4;
  177297. unsigned int half_z_window_size = 1 << (z_cinfo + 7);
  177298. while (uncompressed_idat_size <= half_z_window_size &&
  177299. half_z_window_size >= 256)
  177300. {
  177301. z_cinfo--;
  177302. half_z_window_size >>= 1;
  177303. }
  177304. z_cmf = (z_cmf & 0x0f) | (z_cinfo << 4);
  177305. if (data[0] != (png_byte)z_cmf)
  177306. {
  177307. data[0] = (png_byte)z_cmf;
  177308. data[1] &= 0xe0;
  177309. data[1] += (png_byte)(0x1f - ((z_cmf << 8) + data[1]) % 0x1f);
  177310. }
  177311. }
  177312. }
  177313. else
  177314. png_error(png_ptr,
  177315. "Invalid zlib compression method or flags in IDAT");
  177316. }
  177317. png_write_chunk(png_ptr, png_IDAT, data, length);
  177318. png_ptr->mode |= PNG_HAVE_IDAT;
  177319. }
  177320. void /* PRIVATE */
  177321. png_write_IEND(png_structp png_ptr)
  177322. {
  177323. #ifdef PNG_USE_LOCAL_ARRAYS
  177324. PNG_IEND;
  177325. #endif
  177326. png_debug(1, "in png_write_IEND\n");
  177327. png_write_chunk(png_ptr, png_IEND, png_bytep_NULL,
  177328. (png_size_t)0);
  177329. png_ptr->mode |= PNG_HAVE_IEND;
  177330. }
  177331. #if defined(PNG_WRITE_gAMA_SUPPORTED)
  177332. #ifdef PNG_FLOATING_POINT_SUPPORTED
  177333. void /* PRIVATE */
  177334. png_write_gAMA(png_structp png_ptr, double file_gamma)
  177335. {
  177336. #ifdef PNG_USE_LOCAL_ARRAYS
  177337. PNG_gAMA;
  177338. #endif
  177339. png_uint_32 igamma;
  177340. png_byte buf[4];
  177341. png_debug(1, "in png_write_gAMA\n");
  177342. igamma = (png_uint_32)(file_gamma * 100000.0 + 0.5);
  177343. png_save_uint_32(buf, igamma);
  177344. png_write_chunk(png_ptr, png_gAMA, buf, (png_size_t)4);
  177345. }
  177346. #endif
  177347. #ifdef PNG_FIXED_POINT_SUPPORTED
  177348. void /* PRIVATE */
  177349. png_write_gAMA_fixed(png_structp png_ptr, png_fixed_point file_gamma)
  177350. {
  177351. #ifdef PNG_USE_LOCAL_ARRAYS
  177352. PNG_gAMA;
  177353. #endif
  177354. png_byte buf[4];
  177355. png_debug(1, "in png_write_gAMA\n");
  177356. png_save_uint_32(buf, (png_uint_32)file_gamma);
  177357. png_write_chunk(png_ptr, png_gAMA, buf, (png_size_t)4);
  177358. }
  177359. #endif
  177360. #endif
  177361. #if defined(PNG_WRITE_sRGB_SUPPORTED)
  177362. void /* PRIVATE */
  177363. png_write_sRGB(png_structp png_ptr, int srgb_intent)
  177364. {
  177365. #ifdef PNG_USE_LOCAL_ARRAYS
  177366. PNG_sRGB;
  177367. #endif
  177368. png_byte buf[1];
  177369. png_debug(1, "in png_write_sRGB\n");
  177370. if(srgb_intent >= PNG_sRGB_INTENT_LAST)
  177371. png_warning(png_ptr,
  177372. "Invalid sRGB rendering intent specified");
  177373. buf[0]=(png_byte)srgb_intent;
  177374. png_write_chunk(png_ptr, png_sRGB, buf, (png_size_t)1);
  177375. }
  177376. #endif
  177377. #if defined(PNG_WRITE_iCCP_SUPPORTED)
  177378. void /* PRIVATE */
  177379. png_write_iCCP(png_structp png_ptr, png_charp name, int compression_type,
  177380. png_charp profile, int profile_len)
  177381. {
  177382. #ifdef PNG_USE_LOCAL_ARRAYS
  177383. PNG_iCCP;
  177384. #endif
  177385. png_size_t name_len;
  177386. png_charp new_name;
  177387. compression_state comp;
  177388. int embedded_profile_len = 0;
  177389. png_debug(1, "in png_write_iCCP\n");
  177390. comp.num_output_ptr = 0;
  177391. comp.max_output_ptr = 0;
  177392. comp.output_ptr = NULL;
  177393. comp.input = NULL;
  177394. comp.input_len = 0;
  177395. if (name == NULL || (name_len = png_check_keyword(png_ptr, name,
  177396. &new_name)) == 0)
  177397. {
  177398. png_warning(png_ptr, "Empty keyword in iCCP chunk");
  177399. return;
  177400. }
  177401. if (compression_type != PNG_COMPRESSION_TYPE_BASE)
  177402. png_warning(png_ptr, "Unknown compression type in iCCP chunk");
  177403. if (profile == NULL)
  177404. profile_len = 0;
  177405. if (profile_len > 3)
  177406. embedded_profile_len =
  177407. ((*( (png_bytep)profile ))<<24) |
  177408. ((*( (png_bytep)profile+1))<<16) |
  177409. ((*( (png_bytep)profile+2))<< 8) |
  177410. ((*( (png_bytep)profile+3)) );
  177411. if (profile_len < embedded_profile_len)
  177412. {
  177413. png_warning(png_ptr,
  177414. "Embedded profile length too large in iCCP chunk");
  177415. return;
  177416. }
  177417. if (profile_len > embedded_profile_len)
  177418. {
  177419. png_warning(png_ptr,
  177420. "Truncating profile to actual length in iCCP chunk");
  177421. profile_len = embedded_profile_len;
  177422. }
  177423. if (profile_len)
  177424. profile_len = png_text_compress(png_ptr, profile, (png_size_t)profile_len,
  177425. PNG_COMPRESSION_TYPE_BASE, &comp);
  177426. png_write_chunk_start(png_ptr, png_iCCP,
  177427. (png_uint_32)name_len+profile_len+2);
  177428. new_name[name_len+1]=0x00;
  177429. png_write_chunk_data(png_ptr, (png_bytep)new_name, name_len + 2);
  177430. if (profile_len)
  177431. png_write_compressed_data_out(png_ptr, &comp);
  177432. png_write_chunk_end(png_ptr);
  177433. png_free(png_ptr, new_name);
  177434. }
  177435. #endif
  177436. #if defined(PNG_WRITE_sPLT_SUPPORTED)
  177437. void /* PRIVATE */
  177438. png_write_sPLT(png_structp png_ptr, png_sPLT_tp spalette)
  177439. {
  177440. #ifdef PNG_USE_LOCAL_ARRAYS
  177441. PNG_sPLT;
  177442. #endif
  177443. png_size_t name_len;
  177444. png_charp new_name;
  177445. png_byte entrybuf[10];
  177446. int entry_size = (spalette->depth == 8 ? 6 : 10);
  177447. int palette_size = entry_size * spalette->nentries;
  177448. png_sPLT_entryp ep;
  177449. #ifdef PNG_NO_POINTER_INDEXING
  177450. int i;
  177451. #endif
  177452. png_debug(1, "in png_write_sPLT\n");
  177453. if (spalette->name == NULL || (name_len = png_check_keyword(png_ptr,
  177454. spalette->name, &new_name))==0)
  177455. {
  177456. png_warning(png_ptr, "Empty keyword in sPLT chunk");
  177457. return;
  177458. }
  177459. png_write_chunk_start(png_ptr, png_sPLT,
  177460. (png_uint_32)(name_len + 2 + palette_size));
  177461. png_write_chunk_data(png_ptr, (png_bytep)new_name, name_len + 1);
  177462. png_write_chunk_data(png_ptr, (png_bytep)&spalette->depth, 1);
  177463. #ifndef PNG_NO_POINTER_INDEXING
  177464. for (ep = spalette->entries; ep<spalette->entries+spalette->nentries; ep++)
  177465. {
  177466. if (spalette->depth == 8)
  177467. {
  177468. entrybuf[0] = (png_byte)ep->red;
  177469. entrybuf[1] = (png_byte)ep->green;
  177470. entrybuf[2] = (png_byte)ep->blue;
  177471. entrybuf[3] = (png_byte)ep->alpha;
  177472. png_save_uint_16(entrybuf + 4, ep->frequency);
  177473. }
  177474. else
  177475. {
  177476. png_save_uint_16(entrybuf + 0, ep->red);
  177477. png_save_uint_16(entrybuf + 2, ep->green);
  177478. png_save_uint_16(entrybuf + 4, ep->blue);
  177479. png_save_uint_16(entrybuf + 6, ep->alpha);
  177480. png_save_uint_16(entrybuf + 8, ep->frequency);
  177481. }
  177482. png_write_chunk_data(png_ptr, entrybuf, (png_size_t)entry_size);
  177483. }
  177484. #else
  177485. ep=spalette->entries;
  177486. for (i=0; i>spalette->nentries; i++)
  177487. {
  177488. if (spalette->depth == 8)
  177489. {
  177490. entrybuf[0] = (png_byte)ep[i].red;
  177491. entrybuf[1] = (png_byte)ep[i].green;
  177492. entrybuf[2] = (png_byte)ep[i].blue;
  177493. entrybuf[3] = (png_byte)ep[i].alpha;
  177494. png_save_uint_16(entrybuf + 4, ep[i].frequency);
  177495. }
  177496. else
  177497. {
  177498. png_save_uint_16(entrybuf + 0, ep[i].red);
  177499. png_save_uint_16(entrybuf + 2, ep[i].green);
  177500. png_save_uint_16(entrybuf + 4, ep[i].blue);
  177501. png_save_uint_16(entrybuf + 6, ep[i].alpha);
  177502. png_save_uint_16(entrybuf + 8, ep[i].frequency);
  177503. }
  177504. png_write_chunk_data(png_ptr, entrybuf, entry_size);
  177505. }
  177506. #endif
  177507. png_write_chunk_end(png_ptr);
  177508. png_free(png_ptr, new_name);
  177509. }
  177510. #endif
  177511. #if defined(PNG_WRITE_sBIT_SUPPORTED)
  177512. void /* PRIVATE */
  177513. png_write_sBIT(png_structp png_ptr, png_color_8p sbit, int color_type)
  177514. {
  177515. #ifdef PNG_USE_LOCAL_ARRAYS
  177516. PNG_sBIT;
  177517. #endif
  177518. png_byte buf[4];
  177519. png_size_t size;
  177520. png_debug(1, "in png_write_sBIT\n");
  177521. if (color_type & PNG_COLOR_MASK_COLOR)
  177522. {
  177523. png_byte maxbits;
  177524. maxbits = (png_byte)(color_type==PNG_COLOR_TYPE_PALETTE ? 8 :
  177525. png_ptr->usr_bit_depth);
  177526. if (sbit->red == 0 || sbit->red > maxbits ||
  177527. sbit->green == 0 || sbit->green > maxbits ||
  177528. sbit->blue == 0 || sbit->blue > maxbits)
  177529. {
  177530. png_warning(png_ptr, "Invalid sBIT depth specified");
  177531. return;
  177532. }
  177533. buf[0] = sbit->red;
  177534. buf[1] = sbit->green;
  177535. buf[2] = sbit->blue;
  177536. size = 3;
  177537. }
  177538. else
  177539. {
  177540. if (sbit->gray == 0 || sbit->gray > png_ptr->usr_bit_depth)
  177541. {
  177542. png_warning(png_ptr, "Invalid sBIT depth specified");
  177543. return;
  177544. }
  177545. buf[0] = sbit->gray;
  177546. size = 1;
  177547. }
  177548. if (color_type & PNG_COLOR_MASK_ALPHA)
  177549. {
  177550. if (sbit->alpha == 0 || sbit->alpha > png_ptr->usr_bit_depth)
  177551. {
  177552. png_warning(png_ptr, "Invalid sBIT depth specified");
  177553. return;
  177554. }
  177555. buf[size++] = sbit->alpha;
  177556. }
  177557. png_write_chunk(png_ptr, png_sBIT, buf, size);
  177558. }
  177559. #endif
  177560. #if defined(PNG_WRITE_cHRM_SUPPORTED)
  177561. #ifdef PNG_FLOATING_POINT_SUPPORTED
  177562. void /* PRIVATE */
  177563. png_write_cHRM(png_structp png_ptr, double white_x, double white_y,
  177564. double red_x, double red_y, double green_x, double green_y,
  177565. double blue_x, double blue_y)
  177566. {
  177567. #ifdef PNG_USE_LOCAL_ARRAYS
  177568. PNG_cHRM;
  177569. #endif
  177570. png_byte buf[32];
  177571. png_uint_32 itemp;
  177572. png_debug(1, "in png_write_cHRM\n");
  177573. if (white_x < 0 || white_x > 0.8 || white_y < 0 || white_y > 0.8 ||
  177574. white_x + white_y > 1.0)
  177575. {
  177576. png_warning(png_ptr, "Invalid cHRM white point specified");
  177577. #if !defined(PNG_NO_CONSOLE_IO)
  177578. fprintf(stderr,"white_x=%f, white_y=%f\n",white_x, white_y);
  177579. #endif
  177580. return;
  177581. }
  177582. itemp = (png_uint_32)(white_x * 100000.0 + 0.5);
  177583. png_save_uint_32(buf, itemp);
  177584. itemp = (png_uint_32)(white_y * 100000.0 + 0.5);
  177585. png_save_uint_32(buf + 4, itemp);
  177586. if (red_x < 0 || red_y < 0 || red_x + red_y > 1.0)
  177587. {
  177588. png_warning(png_ptr, "Invalid cHRM red point specified");
  177589. return;
  177590. }
  177591. itemp = (png_uint_32)(red_x * 100000.0 + 0.5);
  177592. png_save_uint_32(buf + 8, itemp);
  177593. itemp = (png_uint_32)(red_y * 100000.0 + 0.5);
  177594. png_save_uint_32(buf + 12, itemp);
  177595. if (green_x < 0 || green_y < 0 || green_x + green_y > 1.0)
  177596. {
  177597. png_warning(png_ptr, "Invalid cHRM green point specified");
  177598. return;
  177599. }
  177600. itemp = (png_uint_32)(green_x * 100000.0 + 0.5);
  177601. png_save_uint_32(buf + 16, itemp);
  177602. itemp = (png_uint_32)(green_y * 100000.0 + 0.5);
  177603. png_save_uint_32(buf + 20, itemp);
  177604. if (blue_x < 0 || blue_y < 0 || blue_x + blue_y > 1.0)
  177605. {
  177606. png_warning(png_ptr, "Invalid cHRM blue point specified");
  177607. return;
  177608. }
  177609. itemp = (png_uint_32)(blue_x * 100000.0 + 0.5);
  177610. png_save_uint_32(buf + 24, itemp);
  177611. itemp = (png_uint_32)(blue_y * 100000.0 + 0.5);
  177612. png_save_uint_32(buf + 28, itemp);
  177613. png_write_chunk(png_ptr, png_cHRM, buf, (png_size_t)32);
  177614. }
  177615. #endif
  177616. #ifdef PNG_FIXED_POINT_SUPPORTED
  177617. void /* PRIVATE */
  177618. png_write_cHRM_fixed(png_structp png_ptr, png_fixed_point white_x,
  177619. png_fixed_point white_y, png_fixed_point red_x, png_fixed_point red_y,
  177620. png_fixed_point green_x, png_fixed_point green_y, png_fixed_point blue_x,
  177621. png_fixed_point blue_y)
  177622. {
  177623. #ifdef PNG_USE_LOCAL_ARRAYS
  177624. PNG_cHRM;
  177625. #endif
  177626. png_byte buf[32];
  177627. png_debug(1, "in png_write_cHRM\n");
  177628. if (white_x > 80000L || white_y > 80000L || white_x + white_y > 100000L)
  177629. {
  177630. png_warning(png_ptr, "Invalid fixed cHRM white point specified");
  177631. #if !defined(PNG_NO_CONSOLE_IO)
  177632. fprintf(stderr,"white_x=%ld, white_y=%ld\n",white_x, white_y);
  177633. #endif
  177634. return;
  177635. }
  177636. png_save_uint_32(buf, (png_uint_32)white_x);
  177637. png_save_uint_32(buf + 4, (png_uint_32)white_y);
  177638. if (red_x + red_y > 100000L)
  177639. {
  177640. png_warning(png_ptr, "Invalid cHRM fixed red point specified");
  177641. return;
  177642. }
  177643. png_save_uint_32(buf + 8, (png_uint_32)red_x);
  177644. png_save_uint_32(buf + 12, (png_uint_32)red_y);
  177645. if (green_x + green_y > 100000L)
  177646. {
  177647. png_warning(png_ptr, "Invalid fixed cHRM green point specified");
  177648. return;
  177649. }
  177650. png_save_uint_32(buf + 16, (png_uint_32)green_x);
  177651. png_save_uint_32(buf + 20, (png_uint_32)green_y);
  177652. if (blue_x + blue_y > 100000L)
  177653. {
  177654. png_warning(png_ptr, "Invalid fixed cHRM blue point specified");
  177655. return;
  177656. }
  177657. png_save_uint_32(buf + 24, (png_uint_32)blue_x);
  177658. png_save_uint_32(buf + 28, (png_uint_32)blue_y);
  177659. png_write_chunk(png_ptr, png_cHRM, buf, (png_size_t)32);
  177660. }
  177661. #endif
  177662. #endif
  177663. #if defined(PNG_WRITE_tRNS_SUPPORTED)
  177664. void /* PRIVATE */
  177665. png_write_tRNS(png_structp png_ptr, png_bytep trans, png_color_16p tran,
  177666. int num_trans, int color_type)
  177667. {
  177668. #ifdef PNG_USE_LOCAL_ARRAYS
  177669. PNG_tRNS;
  177670. #endif
  177671. png_byte buf[6];
  177672. png_debug(1, "in png_write_tRNS\n");
  177673. if (color_type == PNG_COLOR_TYPE_PALETTE)
  177674. {
  177675. if (num_trans <= 0 || num_trans > (int)png_ptr->num_palette)
  177676. {
  177677. png_warning(png_ptr,"Invalid number of transparent colors specified");
  177678. return;
  177679. }
  177680. png_write_chunk(png_ptr, png_tRNS, trans, (png_size_t)num_trans);
  177681. }
  177682. else if (color_type == PNG_COLOR_TYPE_GRAY)
  177683. {
  177684. if(tran->gray >= (1 << png_ptr->bit_depth))
  177685. {
  177686. png_warning(png_ptr,
  177687. "Ignoring attempt to write tRNS chunk out-of-range for bit_depth");
  177688. return;
  177689. }
  177690. png_save_uint_16(buf, tran->gray);
  177691. png_write_chunk(png_ptr, png_tRNS, buf, (png_size_t)2);
  177692. }
  177693. else if (color_type == PNG_COLOR_TYPE_RGB)
  177694. {
  177695. png_save_uint_16(buf, tran->red);
  177696. png_save_uint_16(buf + 2, tran->green);
  177697. png_save_uint_16(buf + 4, tran->blue);
  177698. if(png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
  177699. {
  177700. png_warning(png_ptr,
  177701. "Ignoring attempt to write 16-bit tRNS chunk when bit_depth is 8");
  177702. return;
  177703. }
  177704. png_write_chunk(png_ptr, png_tRNS, buf, (png_size_t)6);
  177705. }
  177706. else
  177707. {
  177708. png_warning(png_ptr, "Can't write tRNS with an alpha channel");
  177709. }
  177710. }
  177711. #endif
  177712. #if defined(PNG_WRITE_bKGD_SUPPORTED)
  177713. void /* PRIVATE */
  177714. png_write_bKGD(png_structp png_ptr, png_color_16p back, int color_type)
  177715. {
  177716. #ifdef PNG_USE_LOCAL_ARRAYS
  177717. PNG_bKGD;
  177718. #endif
  177719. png_byte buf[6];
  177720. png_debug(1, "in png_write_bKGD\n");
  177721. if (color_type == PNG_COLOR_TYPE_PALETTE)
  177722. {
  177723. if (
  177724. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177725. (png_ptr->num_palette ||
  177726. (!(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE))) &&
  177727. #endif
  177728. back->index > png_ptr->num_palette)
  177729. {
  177730. png_warning(png_ptr, "Invalid background palette index");
  177731. return;
  177732. }
  177733. buf[0] = back->index;
  177734. png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)1);
  177735. }
  177736. else if (color_type & PNG_COLOR_MASK_COLOR)
  177737. {
  177738. png_save_uint_16(buf, back->red);
  177739. png_save_uint_16(buf + 2, back->green);
  177740. png_save_uint_16(buf + 4, back->blue);
  177741. if(png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
  177742. {
  177743. png_warning(png_ptr,
  177744. "Ignoring attempt to write 16-bit bKGD chunk when bit_depth is 8");
  177745. return;
  177746. }
  177747. png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)6);
  177748. }
  177749. else
  177750. {
  177751. if(back->gray >= (1 << png_ptr->bit_depth))
  177752. {
  177753. png_warning(png_ptr,
  177754. "Ignoring attempt to write bKGD chunk out-of-range for bit_depth");
  177755. return;
  177756. }
  177757. png_save_uint_16(buf, back->gray);
  177758. png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)2);
  177759. }
  177760. }
  177761. #endif
  177762. #if defined(PNG_WRITE_hIST_SUPPORTED)
  177763. void /* PRIVATE */
  177764. png_write_hIST(png_structp png_ptr, png_uint_16p hist, int num_hist)
  177765. {
  177766. #ifdef PNG_USE_LOCAL_ARRAYS
  177767. PNG_hIST;
  177768. #endif
  177769. int i;
  177770. png_byte buf[3];
  177771. png_debug(1, "in png_write_hIST\n");
  177772. if (num_hist > (int)png_ptr->num_palette)
  177773. {
  177774. png_debug2(3, "num_hist = %d, num_palette = %d\n", num_hist,
  177775. png_ptr->num_palette);
  177776. png_warning(png_ptr, "Invalid number of histogram entries specified");
  177777. return;
  177778. }
  177779. png_write_chunk_start(png_ptr, png_hIST, (png_uint_32)(num_hist * 2));
  177780. for (i = 0; i < num_hist; i++)
  177781. {
  177782. png_save_uint_16(buf, hist[i]);
  177783. png_write_chunk_data(png_ptr, buf, (png_size_t)2);
  177784. }
  177785. png_write_chunk_end(png_ptr);
  177786. }
  177787. #endif
  177788. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \
  177789. defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
  177790. png_size_t /* PRIVATE */
  177791. png_check_keyword(png_structp png_ptr, png_charp key, png_charpp new_key)
  177792. {
  177793. png_size_t key_len;
  177794. png_charp kp, dp;
  177795. int kflag;
  177796. int kwarn=0;
  177797. png_debug(1, "in png_check_keyword\n");
  177798. *new_key = NULL;
  177799. if (key == NULL || (key_len = png_strlen(key)) == 0)
  177800. {
  177801. png_warning(png_ptr, "zero length keyword");
  177802. return ((png_size_t)0);
  177803. }
  177804. png_debug1(2, "Keyword to be checked is '%s'\n", key);
  177805. *new_key = (png_charp)png_malloc_warn(png_ptr, (png_uint_32)(key_len + 2));
  177806. if (*new_key == NULL)
  177807. {
  177808. png_warning(png_ptr, "Out of memory while procesing keyword");
  177809. return ((png_size_t)0);
  177810. }
  177811. for (kp = key, dp = *new_key; *kp != '\0'; kp++, dp++)
  177812. {
  177813. if ((png_byte)*kp < 0x20 ||
  177814. ((png_byte)*kp > 0x7E && (png_byte)*kp < 0xA1))
  177815. {
  177816. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  177817. char msg[40];
  177818. png_snprintf(msg, 40,
  177819. "invalid keyword character 0x%02X", (png_byte)*kp);
  177820. png_warning(png_ptr, msg);
  177821. #else
  177822. png_warning(png_ptr, "invalid character in keyword");
  177823. #endif
  177824. *dp = ' ';
  177825. }
  177826. else
  177827. {
  177828. *dp = *kp;
  177829. }
  177830. }
  177831. *dp = '\0';
  177832. kp = *new_key + key_len - 1;
  177833. if (*kp == ' ')
  177834. {
  177835. png_warning(png_ptr, "trailing spaces removed from keyword");
  177836. while (*kp == ' ')
  177837. {
  177838. *(kp--) = '\0';
  177839. key_len--;
  177840. }
  177841. }
  177842. kp = *new_key;
  177843. if (*kp == ' ')
  177844. {
  177845. png_warning(png_ptr, "leading spaces removed from keyword");
  177846. while (*kp == ' ')
  177847. {
  177848. kp++;
  177849. key_len--;
  177850. }
  177851. }
  177852. png_debug1(2, "Checking for multiple internal spaces in '%s'\n", kp);
  177853. for (kflag = 0, dp = *new_key; *kp != '\0'; kp++)
  177854. {
  177855. if (*kp == ' ' && kflag == 0)
  177856. {
  177857. *(dp++) = *kp;
  177858. kflag = 1;
  177859. }
  177860. else if (*kp == ' ')
  177861. {
  177862. key_len--;
  177863. kwarn=1;
  177864. }
  177865. else
  177866. {
  177867. *(dp++) = *kp;
  177868. kflag = 0;
  177869. }
  177870. }
  177871. *dp = '\0';
  177872. if(kwarn)
  177873. png_warning(png_ptr, "extra interior spaces removed from keyword");
  177874. if (key_len == 0)
  177875. {
  177876. png_free(png_ptr, *new_key);
  177877. *new_key=NULL;
  177878. png_warning(png_ptr, "Zero length keyword");
  177879. }
  177880. if (key_len > 79)
  177881. {
  177882. png_warning(png_ptr, "keyword length must be 1 - 79 characters");
  177883. new_key[79] = '\0';
  177884. key_len = 79;
  177885. }
  177886. return (key_len);
  177887. }
  177888. #endif
  177889. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  177890. void /* PRIVATE */
  177891. png_write_tEXt(png_structp png_ptr, png_charp key, png_charp text,
  177892. png_size_t text_len)
  177893. {
  177894. #ifdef PNG_USE_LOCAL_ARRAYS
  177895. PNG_tEXt;
  177896. #endif
  177897. png_size_t key_len;
  177898. png_charp new_key;
  177899. png_debug(1, "in png_write_tEXt\n");
  177900. if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
  177901. {
  177902. png_warning(png_ptr, "Empty keyword in tEXt chunk");
  177903. return;
  177904. }
  177905. if (text == NULL || *text == '\0')
  177906. text_len = 0;
  177907. else
  177908. text_len = png_strlen(text);
  177909. png_write_chunk_start(png_ptr, png_tEXt, (png_uint_32)key_len+text_len+1);
  177910. png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
  177911. if (text_len)
  177912. png_write_chunk_data(png_ptr, (png_bytep)text, text_len);
  177913. png_write_chunk_end(png_ptr);
  177914. png_free(png_ptr, new_key);
  177915. }
  177916. #endif
  177917. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  177918. void /* PRIVATE */
  177919. png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text,
  177920. png_size_t text_len, int compression)
  177921. {
  177922. #ifdef PNG_USE_LOCAL_ARRAYS
  177923. PNG_zTXt;
  177924. #endif
  177925. png_size_t key_len;
  177926. char buf[1];
  177927. png_charp new_key;
  177928. compression_state comp;
  177929. png_debug(1, "in png_write_zTXt\n");
  177930. comp.num_output_ptr = 0;
  177931. comp.max_output_ptr = 0;
  177932. comp.output_ptr = NULL;
  177933. comp.input = NULL;
  177934. comp.input_len = 0;
  177935. if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
  177936. {
  177937. png_warning(png_ptr, "Empty keyword in zTXt chunk");
  177938. return;
  177939. }
  177940. if (text == NULL || *text == '\0' || compression==PNG_TEXT_COMPRESSION_NONE)
  177941. {
  177942. png_write_tEXt(png_ptr, new_key, text, (png_size_t)0);
  177943. png_free(png_ptr, new_key);
  177944. return;
  177945. }
  177946. text_len = png_strlen(text);
  177947. text_len = png_text_compress(png_ptr, text, text_len, compression,
  177948. &comp);
  177949. png_write_chunk_start(png_ptr, png_zTXt, (png_uint_32)
  177950. (key_len+text_len+2));
  177951. png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
  177952. png_free(png_ptr, new_key);
  177953. buf[0] = (png_byte)compression;
  177954. png_write_chunk_data(png_ptr, (png_bytep)buf, (png_size_t)1);
  177955. png_write_compressed_data_out(png_ptr, &comp);
  177956. png_write_chunk_end(png_ptr);
  177957. }
  177958. #endif
  177959. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  177960. void /* PRIVATE */
  177961. png_write_iTXt(png_structp png_ptr, int compression, png_charp key,
  177962. png_charp lang, png_charp lang_key, png_charp text)
  177963. {
  177964. #ifdef PNG_USE_LOCAL_ARRAYS
  177965. PNG_iTXt;
  177966. #endif
  177967. png_size_t lang_len, key_len, lang_key_len, text_len;
  177968. png_charp new_lang, new_key;
  177969. png_byte cbuf[2];
  177970. compression_state comp;
  177971. png_debug(1, "in png_write_iTXt\n");
  177972. comp.num_output_ptr = 0;
  177973. comp.max_output_ptr = 0;
  177974. comp.output_ptr = NULL;
  177975. comp.input = NULL;
  177976. if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
  177977. {
  177978. png_warning(png_ptr, "Empty keyword in iTXt chunk");
  177979. return;
  177980. }
  177981. if (lang == NULL || (lang_len = png_check_keyword(png_ptr, lang, &new_lang))==0)
  177982. {
  177983. png_warning(png_ptr, "Empty language field in iTXt chunk");
  177984. new_lang = NULL;
  177985. lang_len = 0;
  177986. }
  177987. if (lang_key == NULL)
  177988. lang_key_len = 0;
  177989. else
  177990. lang_key_len = png_strlen(lang_key);
  177991. if (text == NULL)
  177992. text_len = 0;
  177993. else
  177994. text_len = png_strlen(text);
  177995. text_len = png_text_compress(png_ptr, text, text_len, compression-2,
  177996. &comp);
  177997. png_write_chunk_start(png_ptr, png_iTXt,
  177998. (png_uint_32)(
  177999. 5 /* comp byte, comp flag, terminators for key, lang and lang_key */
  178000. + key_len
  178001. + lang_len
  178002. + lang_key_len
  178003. + text_len));
  178004. png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
  178005. if (compression == PNG_ITXT_COMPRESSION_NONE || \
  178006. compression == PNG_TEXT_COMPRESSION_NONE)
  178007. cbuf[0] = 0;
  178008. else /* compression == PNG_ITXT_COMPRESSION_zTXt */
  178009. cbuf[0] = 1;
  178010. cbuf[1] = 0;
  178011. png_write_chunk_data(png_ptr, cbuf, 2);
  178012. cbuf[0] = 0;
  178013. png_write_chunk_data(png_ptr, (new_lang ? (png_bytep)new_lang : cbuf), lang_len + 1);
  178014. png_write_chunk_data(png_ptr, (lang_key ? (png_bytep)lang_key : cbuf), lang_key_len + 1);
  178015. png_write_compressed_data_out(png_ptr, &comp);
  178016. png_write_chunk_end(png_ptr);
  178017. png_free(png_ptr, new_key);
  178018. if (new_lang)
  178019. png_free(png_ptr, new_lang);
  178020. }
  178021. #endif
  178022. #if defined(PNG_WRITE_oFFs_SUPPORTED)
  178023. void /* PRIVATE */
  178024. png_write_oFFs(png_structp png_ptr, png_int_32 x_offset, png_int_32 y_offset,
  178025. int unit_type)
  178026. {
  178027. #ifdef PNG_USE_LOCAL_ARRAYS
  178028. PNG_oFFs;
  178029. #endif
  178030. png_byte buf[9];
  178031. png_debug(1, "in png_write_oFFs\n");
  178032. if (unit_type >= PNG_OFFSET_LAST)
  178033. png_warning(png_ptr, "Unrecognized unit type for oFFs chunk");
  178034. png_save_int_32(buf, x_offset);
  178035. png_save_int_32(buf + 4, y_offset);
  178036. buf[8] = (png_byte)unit_type;
  178037. png_write_chunk(png_ptr, png_oFFs, buf, (png_size_t)9);
  178038. }
  178039. #endif
  178040. #if defined(PNG_WRITE_pCAL_SUPPORTED)
  178041. void /* PRIVATE */
  178042. png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0,
  178043. png_int_32 X1, int type, int nparams, png_charp units, png_charpp params)
  178044. {
  178045. #ifdef PNG_USE_LOCAL_ARRAYS
  178046. PNG_pCAL;
  178047. #endif
  178048. png_size_t purpose_len, units_len, total_len;
  178049. png_uint_32p params_len;
  178050. png_byte buf[10];
  178051. png_charp new_purpose;
  178052. int i;
  178053. png_debug1(1, "in png_write_pCAL (%d parameters)\n", nparams);
  178054. if (type >= PNG_EQUATION_LAST)
  178055. png_warning(png_ptr, "Unrecognized equation type for pCAL chunk");
  178056. purpose_len = png_check_keyword(png_ptr, purpose, &new_purpose) + 1;
  178057. png_debug1(3, "pCAL purpose length = %d\n", (int)purpose_len);
  178058. units_len = png_strlen(units) + (nparams == 0 ? 0 : 1);
  178059. png_debug1(3, "pCAL units length = %d\n", (int)units_len);
  178060. total_len = purpose_len + units_len + 10;
  178061. params_len = (png_uint_32p)png_malloc(png_ptr, (png_uint_32)(nparams
  178062. *png_sizeof(png_uint_32)));
  178063. for (i = 0; i < nparams; i++)
  178064. {
  178065. params_len[i] = png_strlen(params[i]) + (i == nparams - 1 ? 0 : 1);
  178066. png_debug2(3, "pCAL parameter %d length = %lu\n", i, params_len[i]);
  178067. total_len += (png_size_t)params_len[i];
  178068. }
  178069. png_debug1(3, "pCAL total length = %d\n", (int)total_len);
  178070. png_write_chunk_start(png_ptr, png_pCAL, (png_uint_32)total_len);
  178071. png_write_chunk_data(png_ptr, (png_bytep)new_purpose, purpose_len);
  178072. png_save_int_32(buf, X0);
  178073. png_save_int_32(buf + 4, X1);
  178074. buf[8] = (png_byte)type;
  178075. buf[9] = (png_byte)nparams;
  178076. png_write_chunk_data(png_ptr, buf, (png_size_t)10);
  178077. png_write_chunk_data(png_ptr, (png_bytep)units, (png_size_t)units_len);
  178078. png_free(png_ptr, new_purpose);
  178079. for (i = 0; i < nparams; i++)
  178080. {
  178081. png_write_chunk_data(png_ptr, (png_bytep)params[i],
  178082. (png_size_t)params_len[i]);
  178083. }
  178084. png_free(png_ptr, params_len);
  178085. png_write_chunk_end(png_ptr);
  178086. }
  178087. #endif
  178088. #if defined(PNG_WRITE_sCAL_SUPPORTED)
  178089. #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
  178090. void /* PRIVATE */
  178091. png_write_sCAL(png_structp png_ptr, int unit, double width, double height)
  178092. {
  178093. #ifdef PNG_USE_LOCAL_ARRAYS
  178094. PNG_sCAL;
  178095. #endif
  178096. char buf[64];
  178097. png_size_t total_len;
  178098. png_debug(1, "in png_write_sCAL\n");
  178099. buf[0] = (char)unit;
  178100. #if defined(_WIN32_WCE)
  178101. {
  178102. wchar_t wc_buf[32];
  178103. size_t wc_len;
  178104. swprintf(wc_buf, TEXT("%12.12e"), width);
  178105. wc_len = wcslen(wc_buf);
  178106. WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, buf + 1, wc_len, NULL, NULL);
  178107. total_len = wc_len + 2;
  178108. swprintf(wc_buf, TEXT("%12.12e"), height);
  178109. wc_len = wcslen(wc_buf);
  178110. WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, buf + total_len, wc_len,
  178111. NULL, NULL);
  178112. total_len += wc_len;
  178113. }
  178114. #else
  178115. png_snprintf(buf + 1, 63, "%12.12e", width);
  178116. total_len = 1 + png_strlen(buf + 1) + 1;
  178117. png_snprintf(buf + total_len, 64-total_len, "%12.12e", height);
  178118. total_len += png_strlen(buf + total_len);
  178119. #endif
  178120. png_debug1(3, "sCAL total length = %u\n", (unsigned int)total_len);
  178121. png_write_chunk(png_ptr, png_sCAL, (png_bytep)buf, total_len);
  178122. }
  178123. #else
  178124. #ifdef PNG_FIXED_POINT_SUPPORTED
  178125. void /* PRIVATE */
  178126. png_write_sCAL_s(png_structp png_ptr, int unit, png_charp width,
  178127. png_charp height)
  178128. {
  178129. #ifdef PNG_USE_LOCAL_ARRAYS
  178130. PNG_sCAL;
  178131. #endif
  178132. png_byte buf[64];
  178133. png_size_t wlen, hlen, total_len;
  178134. png_debug(1, "in png_write_sCAL_s\n");
  178135. wlen = png_strlen(width);
  178136. hlen = png_strlen(height);
  178137. total_len = wlen + hlen + 2;
  178138. if (total_len > 64)
  178139. {
  178140. png_warning(png_ptr, "Can't write sCAL (buffer too small)");
  178141. return;
  178142. }
  178143. buf[0] = (png_byte)unit;
  178144. png_memcpy(buf + 1, width, wlen + 1); /* append the '\0' here */
  178145. png_memcpy(buf + wlen + 2, height, hlen); /* do NOT append the '\0' here */
  178146. png_debug1(3, "sCAL total length = %u\n", (unsigned int)total_len);
  178147. png_write_chunk(png_ptr, png_sCAL, buf, total_len);
  178148. }
  178149. #endif
  178150. #endif
  178151. #endif
  178152. #if defined(PNG_WRITE_pHYs_SUPPORTED)
  178153. void /* PRIVATE */
  178154. png_write_pHYs(png_structp png_ptr, png_uint_32 x_pixels_per_unit,
  178155. png_uint_32 y_pixels_per_unit,
  178156. int unit_type)
  178157. {
  178158. #ifdef PNG_USE_LOCAL_ARRAYS
  178159. PNG_pHYs;
  178160. #endif
  178161. png_byte buf[9];
  178162. png_debug(1, "in png_write_pHYs\n");
  178163. if (unit_type >= PNG_RESOLUTION_LAST)
  178164. png_warning(png_ptr, "Unrecognized unit type for pHYs chunk");
  178165. png_save_uint_32(buf, x_pixels_per_unit);
  178166. png_save_uint_32(buf + 4, y_pixels_per_unit);
  178167. buf[8] = (png_byte)unit_type;
  178168. png_write_chunk(png_ptr, png_pHYs, buf, (png_size_t)9);
  178169. }
  178170. #endif
  178171. #if defined(PNG_WRITE_tIME_SUPPORTED)
  178172. void /* PRIVATE */
  178173. png_write_tIME(png_structp png_ptr, png_timep mod_time)
  178174. {
  178175. #ifdef PNG_USE_LOCAL_ARRAYS
  178176. PNG_tIME;
  178177. #endif
  178178. png_byte buf[7];
  178179. png_debug(1, "in png_write_tIME\n");
  178180. if (mod_time->month > 12 || mod_time->month < 1 ||
  178181. mod_time->day > 31 || mod_time->day < 1 ||
  178182. mod_time->hour > 23 || mod_time->second > 60)
  178183. {
  178184. png_warning(png_ptr, "Invalid time specified for tIME chunk");
  178185. return;
  178186. }
  178187. png_save_uint_16(buf, mod_time->year);
  178188. buf[2] = mod_time->month;
  178189. buf[3] = mod_time->day;
  178190. buf[4] = mod_time->hour;
  178191. buf[5] = mod_time->minute;
  178192. buf[6] = mod_time->second;
  178193. png_write_chunk(png_ptr, png_tIME, buf, (png_size_t)7);
  178194. }
  178195. #endif
  178196. void /* PRIVATE */
  178197. png_write_start_row(png_structp png_ptr)
  178198. {
  178199. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178200. #ifdef PNG_USE_LOCAL_ARRAYS
  178201. int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  178202. int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  178203. int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  178204. int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  178205. #endif
  178206. #endif
  178207. png_size_t buf_size;
  178208. png_debug(1, "in png_write_start_row\n");
  178209. buf_size = (png_size_t)(PNG_ROWBYTES(
  178210. png_ptr->usr_channels*png_ptr->usr_bit_depth,png_ptr->width)+1);
  178211. png_ptr->row_buf = (png_bytep)png_malloc(png_ptr, (png_uint_32)buf_size);
  178212. png_ptr->row_buf[0] = PNG_FILTER_VALUE_NONE;
  178213. #ifndef PNG_NO_WRITE_FILTERING
  178214. if (png_ptr->do_filter & PNG_FILTER_SUB)
  178215. {
  178216. png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
  178217. (png_ptr->rowbytes + 1));
  178218. png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
  178219. }
  178220. if (png_ptr->do_filter & (PNG_FILTER_AVG | PNG_FILTER_UP | PNG_FILTER_PAETH))
  178221. {
  178222. png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)buf_size);
  178223. png_memset(png_ptr->prev_row, 0, buf_size);
  178224. if (png_ptr->do_filter & PNG_FILTER_UP)
  178225. {
  178226. png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
  178227. (png_ptr->rowbytes + 1));
  178228. png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
  178229. }
  178230. if (png_ptr->do_filter & PNG_FILTER_AVG)
  178231. {
  178232. png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
  178233. (png_ptr->rowbytes + 1));
  178234. png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
  178235. }
  178236. if (png_ptr->do_filter & PNG_FILTER_PAETH)
  178237. {
  178238. png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
  178239. (png_ptr->rowbytes + 1));
  178240. png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
  178241. }
  178242. #endif /* PNG_NO_WRITE_FILTERING */
  178243. }
  178244. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178245. if (png_ptr->interlaced)
  178246. {
  178247. if (!(png_ptr->transformations & PNG_INTERLACE))
  178248. {
  178249. png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
  178250. png_pass_ystart[0]) / png_pass_yinc[0];
  178251. png_ptr->usr_width = (png_ptr->width + png_pass_inc[0] - 1 -
  178252. png_pass_start[0]) / png_pass_inc[0];
  178253. }
  178254. else
  178255. {
  178256. png_ptr->num_rows = png_ptr->height;
  178257. png_ptr->usr_width = png_ptr->width;
  178258. }
  178259. }
  178260. else
  178261. #endif
  178262. {
  178263. png_ptr->num_rows = png_ptr->height;
  178264. png_ptr->usr_width = png_ptr->width;
  178265. }
  178266. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  178267. png_ptr->zstream.next_out = png_ptr->zbuf;
  178268. }
  178269. void /* PRIVATE */
  178270. png_write_finish_row(png_structp png_ptr)
  178271. {
  178272. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178273. #ifdef PNG_USE_LOCAL_ARRAYS
  178274. int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  178275. int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  178276. int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  178277. int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  178278. #endif
  178279. #endif
  178280. int ret;
  178281. png_debug(1, "in png_write_finish_row\n");
  178282. png_ptr->row_number++;
  178283. if (png_ptr->row_number < png_ptr->num_rows)
  178284. return;
  178285. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178286. if (png_ptr->interlaced)
  178287. {
  178288. png_ptr->row_number = 0;
  178289. if (png_ptr->transformations & PNG_INTERLACE)
  178290. {
  178291. png_ptr->pass++;
  178292. }
  178293. else
  178294. {
  178295. do
  178296. {
  178297. png_ptr->pass++;
  178298. if (png_ptr->pass >= 7)
  178299. break;
  178300. png_ptr->usr_width = (png_ptr->width +
  178301. png_pass_inc[png_ptr->pass] - 1 -
  178302. png_pass_start[png_ptr->pass]) /
  178303. png_pass_inc[png_ptr->pass];
  178304. png_ptr->num_rows = (png_ptr->height +
  178305. png_pass_yinc[png_ptr->pass] - 1 -
  178306. png_pass_ystart[png_ptr->pass]) /
  178307. png_pass_yinc[png_ptr->pass];
  178308. if (png_ptr->transformations & PNG_INTERLACE)
  178309. break;
  178310. } while (png_ptr->usr_width == 0 || png_ptr->num_rows == 0);
  178311. }
  178312. if (png_ptr->pass < 7)
  178313. {
  178314. if (png_ptr->prev_row != NULL)
  178315. png_memset(png_ptr->prev_row, 0,
  178316. (png_size_t)(PNG_ROWBYTES(png_ptr->usr_channels*
  178317. png_ptr->usr_bit_depth,png_ptr->width))+1);
  178318. return;
  178319. }
  178320. }
  178321. #endif
  178322. do
  178323. {
  178324. ret = deflate(&png_ptr->zstream, Z_FINISH);
  178325. if (ret == Z_OK)
  178326. {
  178327. if (!(png_ptr->zstream.avail_out))
  178328. {
  178329. png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
  178330. png_ptr->zstream.next_out = png_ptr->zbuf;
  178331. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  178332. }
  178333. }
  178334. else if (ret != Z_STREAM_END)
  178335. {
  178336. if (png_ptr->zstream.msg != NULL)
  178337. png_error(png_ptr, png_ptr->zstream.msg);
  178338. else
  178339. png_error(png_ptr, "zlib error");
  178340. }
  178341. } while (ret != Z_STREAM_END);
  178342. if (png_ptr->zstream.avail_out < png_ptr->zbuf_size)
  178343. {
  178344. png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size -
  178345. png_ptr->zstream.avail_out);
  178346. }
  178347. deflateReset(&png_ptr->zstream);
  178348. png_ptr->zstream.data_type = Z_BINARY;
  178349. }
  178350. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  178351. void /* PRIVATE */
  178352. png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
  178353. {
  178354. #ifdef PNG_USE_LOCAL_ARRAYS
  178355. int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  178356. int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  178357. #endif
  178358. png_debug(1, "in png_do_write_interlace\n");
  178359. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  178360. if (row != NULL && row_info != NULL && pass < 6)
  178361. #else
  178362. if (pass < 6)
  178363. #endif
  178364. {
  178365. switch (row_info->pixel_depth)
  178366. {
  178367. case 1:
  178368. {
  178369. png_bytep sp;
  178370. png_bytep dp;
  178371. int shift;
  178372. int d;
  178373. int value;
  178374. png_uint_32 i;
  178375. png_uint_32 row_width = row_info->width;
  178376. dp = row;
  178377. d = 0;
  178378. shift = 7;
  178379. for (i = png_pass_start[pass]; i < row_width;
  178380. i += png_pass_inc[pass])
  178381. {
  178382. sp = row + (png_size_t)(i >> 3);
  178383. value = (int)(*sp >> (7 - (int)(i & 0x07))) & 0x01;
  178384. d |= (value << shift);
  178385. if (shift == 0)
  178386. {
  178387. shift = 7;
  178388. *dp++ = (png_byte)d;
  178389. d = 0;
  178390. }
  178391. else
  178392. shift--;
  178393. }
  178394. if (shift != 7)
  178395. *dp = (png_byte)d;
  178396. break;
  178397. }
  178398. case 2:
  178399. {
  178400. png_bytep sp;
  178401. png_bytep dp;
  178402. int shift;
  178403. int d;
  178404. int value;
  178405. png_uint_32 i;
  178406. png_uint_32 row_width = row_info->width;
  178407. dp = row;
  178408. shift = 6;
  178409. d = 0;
  178410. for (i = png_pass_start[pass]; i < row_width;
  178411. i += png_pass_inc[pass])
  178412. {
  178413. sp = row + (png_size_t)(i >> 2);
  178414. value = (*sp >> ((3 - (int)(i & 0x03)) << 1)) & 0x03;
  178415. d |= (value << shift);
  178416. if (shift == 0)
  178417. {
  178418. shift = 6;
  178419. *dp++ = (png_byte)d;
  178420. d = 0;
  178421. }
  178422. else
  178423. shift -= 2;
  178424. }
  178425. if (shift != 6)
  178426. *dp = (png_byte)d;
  178427. break;
  178428. }
  178429. case 4:
  178430. {
  178431. png_bytep sp;
  178432. png_bytep dp;
  178433. int shift;
  178434. int d;
  178435. int value;
  178436. png_uint_32 i;
  178437. png_uint_32 row_width = row_info->width;
  178438. dp = row;
  178439. shift = 4;
  178440. d = 0;
  178441. for (i = png_pass_start[pass]; i < row_width;
  178442. i += png_pass_inc[pass])
  178443. {
  178444. sp = row + (png_size_t)(i >> 1);
  178445. value = (*sp >> ((1 - (int)(i & 0x01)) << 2)) & 0x0f;
  178446. d |= (value << shift);
  178447. if (shift == 0)
  178448. {
  178449. shift = 4;
  178450. *dp++ = (png_byte)d;
  178451. d = 0;
  178452. }
  178453. else
  178454. shift -= 4;
  178455. }
  178456. if (shift != 4)
  178457. *dp = (png_byte)d;
  178458. break;
  178459. }
  178460. default:
  178461. {
  178462. png_bytep sp;
  178463. png_bytep dp;
  178464. png_uint_32 i;
  178465. png_uint_32 row_width = row_info->width;
  178466. png_size_t pixel_bytes;
  178467. dp = row;
  178468. pixel_bytes = (row_info->pixel_depth >> 3);
  178469. for (i = png_pass_start[pass]; i < row_width;
  178470. i += png_pass_inc[pass])
  178471. {
  178472. sp = row + (png_size_t)i * pixel_bytes;
  178473. if (dp != sp)
  178474. png_memcpy(dp, sp, pixel_bytes);
  178475. dp += pixel_bytes;
  178476. }
  178477. break;
  178478. }
  178479. }
  178480. row_info->width = (row_info->width +
  178481. png_pass_inc[pass] - 1 -
  178482. png_pass_start[pass]) /
  178483. png_pass_inc[pass];
  178484. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
  178485. row_info->width);
  178486. }
  178487. }
  178488. #endif
  178489. #define PNG_MAXSUM (((png_uint_32)(-1)) >> 1)
  178490. #define PNG_HISHIFT 10
  178491. #define PNG_LOMASK ((png_uint_32)0xffffL)
  178492. #define PNG_HIMASK ((png_uint_32)(~PNG_LOMASK >> PNG_HISHIFT))
  178493. void /* PRIVATE */
  178494. png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
  178495. {
  178496. png_bytep best_row;
  178497. #ifndef PNG_NO_WRITE_FILTER
  178498. png_bytep prev_row, row_buf;
  178499. png_uint_32 mins, bpp;
  178500. png_byte filter_to_do = png_ptr->do_filter;
  178501. png_uint_32 row_bytes = row_info->rowbytes;
  178502. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178503. int num_p_filters = (int)png_ptr->num_prev_filters;
  178504. #endif
  178505. png_debug(1, "in png_write_find_filter\n");
  178506. bpp = (row_info->pixel_depth + 7) >> 3;
  178507. prev_row = png_ptr->prev_row;
  178508. #endif
  178509. best_row = png_ptr->row_buf;
  178510. #ifndef PNG_NO_WRITE_FILTER
  178511. row_buf = best_row;
  178512. mins = PNG_MAXSUM;
  178513. if ((filter_to_do & PNG_FILTER_NONE) &&
  178514. filter_to_do != PNG_FILTER_NONE)
  178515. {
  178516. png_bytep rp;
  178517. png_uint_32 sum = 0;
  178518. png_uint_32 i;
  178519. int v;
  178520. for (i = 0, rp = row_buf + 1; i < row_bytes; i++, rp++)
  178521. {
  178522. v = *rp;
  178523. sum += (v < 128) ? v : 256 - v;
  178524. }
  178525. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178526. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178527. {
  178528. png_uint_32 sumhi, sumlo;
  178529. int j;
  178530. sumlo = sum & PNG_LOMASK;
  178531. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK; /* Gives us some footroom */
  178532. for (j = 0; j < num_p_filters; j++)
  178533. {
  178534. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE)
  178535. {
  178536. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  178537. PNG_WEIGHT_SHIFT;
  178538. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  178539. PNG_WEIGHT_SHIFT;
  178540. }
  178541. }
  178542. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >>
  178543. PNG_COST_SHIFT;
  178544. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >>
  178545. PNG_COST_SHIFT;
  178546. if (sumhi > PNG_HIMASK)
  178547. sum = PNG_MAXSUM;
  178548. else
  178549. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178550. }
  178551. #endif
  178552. mins = sum;
  178553. }
  178554. if (filter_to_do == PNG_FILTER_SUB)
  178555. {
  178556. png_bytep rp, lp, dp;
  178557. png_uint_32 i;
  178558. for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp;
  178559. i++, rp++, dp++)
  178560. {
  178561. *dp = *rp;
  178562. }
  178563. for (lp = row_buf + 1; i < row_bytes;
  178564. i++, rp++, lp++, dp++)
  178565. {
  178566. *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff);
  178567. }
  178568. best_row = png_ptr->sub_row;
  178569. }
  178570. else if (filter_to_do & PNG_FILTER_SUB)
  178571. {
  178572. png_bytep rp, dp, lp;
  178573. png_uint_32 sum = 0, lmins = mins;
  178574. png_uint_32 i;
  178575. int v;
  178576. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178577. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178578. {
  178579. int j;
  178580. png_uint_32 lmhi, lmlo;
  178581. lmlo = lmins & PNG_LOMASK;
  178582. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  178583. for (j = 0; j < num_p_filters; j++)
  178584. {
  178585. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB)
  178586. {
  178587. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  178588. PNG_WEIGHT_SHIFT;
  178589. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  178590. PNG_WEIGHT_SHIFT;
  178591. }
  178592. }
  178593. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  178594. PNG_COST_SHIFT;
  178595. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  178596. PNG_COST_SHIFT;
  178597. if (lmhi > PNG_HIMASK)
  178598. lmins = PNG_MAXSUM;
  178599. else
  178600. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  178601. }
  178602. #endif
  178603. for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp;
  178604. i++, rp++, dp++)
  178605. {
  178606. v = *dp = *rp;
  178607. sum += (v < 128) ? v : 256 - v;
  178608. }
  178609. for (lp = row_buf + 1; i < row_bytes;
  178610. i++, rp++, lp++, dp++)
  178611. {
  178612. v = *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff);
  178613. sum += (v < 128) ? v : 256 - v;
  178614. if (sum > lmins) /* We are already worse, don't continue. */
  178615. break;
  178616. }
  178617. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178618. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178619. {
  178620. int j;
  178621. png_uint_32 sumhi, sumlo;
  178622. sumlo = sum & PNG_LOMASK;
  178623. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  178624. for (j = 0; j < num_p_filters; j++)
  178625. {
  178626. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB)
  178627. {
  178628. sumlo = (sumlo * png_ptr->inv_filter_weights[j]) >>
  178629. PNG_WEIGHT_SHIFT;
  178630. sumhi = (sumhi * png_ptr->inv_filter_weights[j]) >>
  178631. PNG_WEIGHT_SHIFT;
  178632. }
  178633. }
  178634. sumlo = (sumlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  178635. PNG_COST_SHIFT;
  178636. sumhi = (sumhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  178637. PNG_COST_SHIFT;
  178638. if (sumhi > PNG_HIMASK)
  178639. sum = PNG_MAXSUM;
  178640. else
  178641. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178642. }
  178643. #endif
  178644. if (sum < mins)
  178645. {
  178646. mins = sum;
  178647. best_row = png_ptr->sub_row;
  178648. }
  178649. }
  178650. if (filter_to_do == PNG_FILTER_UP)
  178651. {
  178652. png_bytep rp, dp, pp;
  178653. png_uint_32 i;
  178654. for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
  178655. pp = prev_row + 1; i < row_bytes;
  178656. i++, rp++, pp++, dp++)
  178657. {
  178658. *dp = (png_byte)(((int)*rp - (int)*pp) & 0xff);
  178659. }
  178660. best_row = png_ptr->up_row;
  178661. }
  178662. else if (filter_to_do & PNG_FILTER_UP)
  178663. {
  178664. png_bytep rp, dp, pp;
  178665. png_uint_32 sum = 0, lmins = mins;
  178666. png_uint_32 i;
  178667. int v;
  178668. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178669. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178670. {
  178671. int j;
  178672. png_uint_32 lmhi, lmlo;
  178673. lmlo = lmins & PNG_LOMASK;
  178674. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  178675. for (j = 0; j < num_p_filters; j++)
  178676. {
  178677. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP)
  178678. {
  178679. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  178680. PNG_WEIGHT_SHIFT;
  178681. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  178682. PNG_WEIGHT_SHIFT;
  178683. }
  178684. }
  178685. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >>
  178686. PNG_COST_SHIFT;
  178687. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >>
  178688. PNG_COST_SHIFT;
  178689. if (lmhi > PNG_HIMASK)
  178690. lmins = PNG_MAXSUM;
  178691. else
  178692. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  178693. }
  178694. #endif
  178695. for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
  178696. pp = prev_row + 1; i < row_bytes; i++)
  178697. {
  178698. v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
  178699. sum += (v < 128) ? v : 256 - v;
  178700. if (sum > lmins) /* We are already worse, don't continue. */
  178701. break;
  178702. }
  178703. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178704. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178705. {
  178706. int j;
  178707. png_uint_32 sumhi, sumlo;
  178708. sumlo = sum & PNG_LOMASK;
  178709. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  178710. for (j = 0; j < num_p_filters; j++)
  178711. {
  178712. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP)
  178713. {
  178714. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  178715. PNG_WEIGHT_SHIFT;
  178716. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  178717. PNG_WEIGHT_SHIFT;
  178718. }
  178719. }
  178720. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >>
  178721. PNG_COST_SHIFT;
  178722. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >>
  178723. PNG_COST_SHIFT;
  178724. if (sumhi > PNG_HIMASK)
  178725. sum = PNG_MAXSUM;
  178726. else
  178727. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178728. }
  178729. #endif
  178730. if (sum < mins)
  178731. {
  178732. mins = sum;
  178733. best_row = png_ptr->up_row;
  178734. }
  178735. }
  178736. if (filter_to_do == PNG_FILTER_AVG)
  178737. {
  178738. png_bytep rp, dp, pp, lp;
  178739. png_uint_32 i;
  178740. for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1,
  178741. pp = prev_row + 1; i < bpp; i++)
  178742. {
  178743. *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff);
  178744. }
  178745. for (lp = row_buf + 1; i < row_bytes; i++)
  178746. {
  178747. *dp++ = (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2))
  178748. & 0xff);
  178749. }
  178750. best_row = png_ptr->avg_row;
  178751. }
  178752. else if (filter_to_do & PNG_FILTER_AVG)
  178753. {
  178754. png_bytep rp, dp, pp, lp;
  178755. png_uint_32 sum = 0, lmins = mins;
  178756. png_uint_32 i;
  178757. int v;
  178758. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178759. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178760. {
  178761. int j;
  178762. png_uint_32 lmhi, lmlo;
  178763. lmlo = lmins & PNG_LOMASK;
  178764. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  178765. for (j = 0; j < num_p_filters; j++)
  178766. {
  178767. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_AVG)
  178768. {
  178769. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  178770. PNG_WEIGHT_SHIFT;
  178771. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  178772. PNG_WEIGHT_SHIFT;
  178773. }
  178774. }
  178775. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >>
  178776. PNG_COST_SHIFT;
  178777. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >>
  178778. PNG_COST_SHIFT;
  178779. if (lmhi > PNG_HIMASK)
  178780. lmins = PNG_MAXSUM;
  178781. else
  178782. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  178783. }
  178784. #endif
  178785. for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1,
  178786. pp = prev_row + 1; i < bpp; i++)
  178787. {
  178788. v = *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff);
  178789. sum += (v < 128) ? v : 256 - v;
  178790. }
  178791. for (lp = row_buf + 1; i < row_bytes; i++)
  178792. {
  178793. v = *dp++ =
  178794. (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2)) & 0xff);
  178795. sum += (v < 128) ? v : 256 - v;
  178796. if (sum > lmins) /* We are already worse, don't continue. */
  178797. break;
  178798. }
  178799. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178800. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178801. {
  178802. int j;
  178803. png_uint_32 sumhi, sumlo;
  178804. sumlo = sum & PNG_LOMASK;
  178805. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  178806. for (j = 0; j < num_p_filters; j++)
  178807. {
  178808. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE)
  178809. {
  178810. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  178811. PNG_WEIGHT_SHIFT;
  178812. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  178813. PNG_WEIGHT_SHIFT;
  178814. }
  178815. }
  178816. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >>
  178817. PNG_COST_SHIFT;
  178818. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >>
  178819. PNG_COST_SHIFT;
  178820. if (sumhi > PNG_HIMASK)
  178821. sum = PNG_MAXSUM;
  178822. else
  178823. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178824. }
  178825. #endif
  178826. if (sum < mins)
  178827. {
  178828. mins = sum;
  178829. best_row = png_ptr->avg_row;
  178830. }
  178831. }
  178832. if (filter_to_do == PNG_FILTER_PAETH)
  178833. {
  178834. png_bytep rp, dp, pp, cp, lp;
  178835. png_uint_32 i;
  178836. for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
  178837. pp = prev_row + 1; i < bpp; i++)
  178838. {
  178839. *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
  178840. }
  178841. for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++)
  178842. {
  178843. int a, b, c, pa, pb, pc, p;
  178844. b = *pp++;
  178845. c = *cp++;
  178846. a = *lp++;
  178847. p = b - c;
  178848. pc = a - c;
  178849. #ifdef PNG_USE_ABS
  178850. pa = abs(p);
  178851. pb = abs(pc);
  178852. pc = abs(p + pc);
  178853. #else
  178854. pa = p < 0 ? -p : p;
  178855. pb = pc < 0 ? -pc : pc;
  178856. pc = (p + pc) < 0 ? -(p + pc) : p + pc;
  178857. #endif
  178858. p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
  178859. *dp++ = (png_byte)(((int)*rp++ - p) & 0xff);
  178860. }
  178861. best_row = png_ptr->paeth_row;
  178862. }
  178863. else if (filter_to_do & PNG_FILTER_PAETH)
  178864. {
  178865. png_bytep rp, dp, pp, cp, lp;
  178866. png_uint_32 sum = 0, lmins = mins;
  178867. png_uint_32 i;
  178868. int v;
  178869. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178870. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178871. {
  178872. int j;
  178873. png_uint_32 lmhi, lmlo;
  178874. lmlo = lmins & PNG_LOMASK;
  178875. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  178876. for (j = 0; j < num_p_filters; j++)
  178877. {
  178878. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH)
  178879. {
  178880. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  178881. PNG_WEIGHT_SHIFT;
  178882. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  178883. PNG_WEIGHT_SHIFT;
  178884. }
  178885. }
  178886. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  178887. PNG_COST_SHIFT;
  178888. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  178889. PNG_COST_SHIFT;
  178890. if (lmhi > PNG_HIMASK)
  178891. lmins = PNG_MAXSUM;
  178892. else
  178893. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  178894. }
  178895. #endif
  178896. for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
  178897. pp = prev_row + 1; i < bpp; i++)
  178898. {
  178899. v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
  178900. sum += (v < 128) ? v : 256 - v;
  178901. }
  178902. for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++)
  178903. {
  178904. int a, b, c, pa, pb, pc, p;
  178905. b = *pp++;
  178906. c = *cp++;
  178907. a = *lp++;
  178908. #ifndef PNG_SLOW_PAETH
  178909. p = b - c;
  178910. pc = a - c;
  178911. #ifdef PNG_USE_ABS
  178912. pa = abs(p);
  178913. pb = abs(pc);
  178914. pc = abs(p + pc);
  178915. #else
  178916. pa = p < 0 ? -p : p;
  178917. pb = pc < 0 ? -pc : pc;
  178918. pc = (p + pc) < 0 ? -(p + pc) : p + pc;
  178919. #endif
  178920. p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
  178921. #else /* PNG_SLOW_PAETH */
  178922. p = a + b - c;
  178923. pa = abs(p - a);
  178924. pb = abs(p - b);
  178925. pc = abs(p - c);
  178926. if (pa <= pb && pa <= pc)
  178927. p = a;
  178928. else if (pb <= pc)
  178929. p = b;
  178930. else
  178931. p = c;
  178932. #endif /* PNG_SLOW_PAETH */
  178933. v = *dp++ = (png_byte)(((int)*rp++ - p) & 0xff);
  178934. sum += (v < 128) ? v : 256 - v;
  178935. if (sum > lmins) /* We are already worse, don't continue. */
  178936. break;
  178937. }
  178938. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178939. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178940. {
  178941. int j;
  178942. png_uint_32 sumhi, sumlo;
  178943. sumlo = sum & PNG_LOMASK;
  178944. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  178945. for (j = 0; j < num_p_filters; j++)
  178946. {
  178947. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH)
  178948. {
  178949. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  178950. PNG_WEIGHT_SHIFT;
  178951. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  178952. PNG_WEIGHT_SHIFT;
  178953. }
  178954. }
  178955. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  178956. PNG_COST_SHIFT;
  178957. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  178958. PNG_COST_SHIFT;
  178959. if (sumhi > PNG_HIMASK)
  178960. sum = PNG_MAXSUM;
  178961. else
  178962. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178963. }
  178964. #endif
  178965. if (sum < mins)
  178966. {
  178967. best_row = png_ptr->paeth_row;
  178968. }
  178969. }
  178970. #endif /* PNG_NO_WRITE_FILTER */
  178971. png_write_filtered_row(png_ptr, best_row);
  178972. #ifndef PNG_NO_WRITE_FILTER
  178973. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178974. if (png_ptr->num_prev_filters > 0)
  178975. {
  178976. int j;
  178977. for (j = 1; j < num_p_filters; j++)
  178978. {
  178979. png_ptr->prev_filters[j] = png_ptr->prev_filters[j - 1];
  178980. }
  178981. png_ptr->prev_filters[j] = best_row[0];
  178982. }
  178983. #endif
  178984. #endif /* PNG_NO_WRITE_FILTER */
  178985. }
  178986. void /* PRIVATE */
  178987. png_write_filtered_row(png_structp png_ptr, png_bytep filtered_row)
  178988. {
  178989. png_debug(1, "in png_write_filtered_row\n");
  178990. png_debug1(2, "filter = %d\n", filtered_row[0]);
  178991. png_ptr->zstream.next_in = filtered_row;
  178992. png_ptr->zstream.avail_in = (uInt)png_ptr->row_info.rowbytes + 1;
  178993. do
  178994. {
  178995. int ret; /* return of zlib */
  178996. ret = deflate(&png_ptr->zstream, Z_NO_FLUSH);
  178997. if (ret != Z_OK)
  178998. {
  178999. if (png_ptr->zstream.msg != NULL)
  179000. png_error(png_ptr, png_ptr->zstream.msg);
  179001. else
  179002. png_error(png_ptr, "zlib error");
  179003. }
  179004. if (!(png_ptr->zstream.avail_out))
  179005. {
  179006. png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
  179007. png_ptr->zstream.next_out = png_ptr->zbuf;
  179008. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  179009. }
  179010. } while (png_ptr->zstream.avail_in);
  179011. if (png_ptr->prev_row != NULL)
  179012. {
  179013. png_bytep tptr;
  179014. tptr = png_ptr->prev_row;
  179015. png_ptr->prev_row = png_ptr->row_buf;
  179016. png_ptr->row_buf = tptr;
  179017. }
  179018. png_write_finish_row(png_ptr);
  179019. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  179020. png_ptr->flush_rows++;
  179021. if (png_ptr->flush_dist > 0 &&
  179022. png_ptr->flush_rows >= png_ptr->flush_dist)
  179023. {
  179024. png_write_flush(png_ptr);
  179025. }
  179026. #endif
  179027. }
  179028. #endif /* PNG_WRITE_SUPPORTED */
  179029. /*** End of inlined file: pngwutil.c ***/
  179030. }
  179031. #else
  179032. #define PNG_INTERNAL
  179033. #define PNG_SETJMP_NOT_SUPPORTED
  179034. #include <png.h>
  179035. #include <pngconf.h>
  179036. #endif
  179037. }
  179038. #ifdef _MSC_VER
  179039. #pragma warning (pop)
  179040. #endif
  179041. BEGIN_JUCE_NAMESPACE
  179042. using namespace pnglibNamespace;
  179043. using ::calloc;
  179044. using ::malloc;
  179045. using ::free;
  179046. static void pngReadCallback (png_structp pngReadStruct, png_bytep data, png_size_t length)
  179047. {
  179048. InputStream* const in = (InputStream*) png_get_io_ptr (pngReadStruct);
  179049. in->read (data, (int) length);
  179050. }
  179051. struct PNGErrorStruct {};
  179052. static void pngErrorCallback (png_structp, png_const_charp)
  179053. {
  179054. throw PNGErrorStruct();
  179055. }
  179056. Image* juce_loadPNGImageFromStream (InputStream& in)
  179057. {
  179058. Image* image = 0;
  179059. png_structp pngReadStruct;
  179060. png_infop pngInfoStruct;
  179061. pngReadStruct = png_create_read_struct (PNG_LIBPNG_VER_STRING, 0, 0, 0);
  179062. if (pngReadStruct != 0)
  179063. {
  179064. pngInfoStruct = png_create_info_struct (pngReadStruct);
  179065. if (pngInfoStruct == 0)
  179066. {
  179067. png_destroy_read_struct (&pngReadStruct, 0, 0);
  179068. return 0;
  179069. }
  179070. png_set_error_fn (pngReadStruct, 0, pngErrorCallback, pngErrorCallback);
  179071. // read the header..
  179072. png_set_read_fn (pngReadStruct, &in, pngReadCallback);
  179073. png_uint_32 width, height;
  179074. int bitDepth, colorType, interlaceType;
  179075. png_read_info (pngReadStruct, pngInfoStruct);
  179076. png_get_IHDR (pngReadStruct, pngInfoStruct,
  179077. &width, &height,
  179078. &bitDepth, &colorType,
  179079. &interlaceType, 0, 0);
  179080. if (bitDepth == 16)
  179081. png_set_strip_16 (pngReadStruct);
  179082. if (colorType == PNG_COLOR_TYPE_PALETTE)
  179083. png_set_expand (pngReadStruct);
  179084. if (bitDepth < 8)
  179085. png_set_expand (pngReadStruct);
  179086. if (png_get_valid (pngReadStruct, pngInfoStruct, PNG_INFO_tRNS))
  179087. png_set_expand (pngReadStruct);
  179088. if (colorType == PNG_COLOR_TYPE_GRAY || colorType == PNG_COLOR_TYPE_GRAY_ALPHA)
  179089. png_set_gray_to_rgb (pngReadStruct);
  179090. png_set_add_alpha (pngReadStruct, 0xff, PNG_FILLER_AFTER);
  179091. bool hasAlphaChan = (colorType & PNG_COLOR_MASK_ALPHA) != 0
  179092. || pngInfoStruct->num_trans > 0;
  179093. // Load the image into a temp buffer in the pnglib format..
  179094. HeapBlock <uint8> tempBuffer (height * (width << 2));
  179095. {
  179096. HeapBlock <png_bytep> rows (height);
  179097. for (int y = (int) height; --y >= 0;)
  179098. rows[y] = (png_bytep) (tempBuffer + (width << 2) * y);
  179099. png_read_image (pngReadStruct, rows);
  179100. png_read_end (pngReadStruct, pngInfoStruct);
  179101. }
  179102. png_destroy_read_struct (&pngReadStruct, &pngInfoStruct, 0);
  179103. // now convert the data to a juce image format..
  179104. image = Image::createNativeImage (hasAlphaChan ? Image::ARGB : Image::RGB,
  179105. (int) width, (int) height, hasAlphaChan);
  179106. hasAlphaChan = image->hasAlphaChannel(); // (the native image creator may not give back what we expect)
  179107. const Image::BitmapData destData (*image, 0, 0, (int) width, (int) height, true);
  179108. uint8* srcRow = tempBuffer;
  179109. uint8* destRow = destData.data;
  179110. for (int y = 0; y < (int) height; ++y)
  179111. {
  179112. const uint8* src = srcRow;
  179113. srcRow += (width << 2);
  179114. uint8* dest = destRow;
  179115. destRow += destData.lineStride;
  179116. if (hasAlphaChan)
  179117. {
  179118. for (int i = (int) width; --i >= 0;)
  179119. {
  179120. ((PixelARGB*) dest)->setARGB (src[3], src[0], src[1], src[2]);
  179121. ((PixelARGB*) dest)->premultiply();
  179122. dest += destData.pixelStride;
  179123. src += 4;
  179124. }
  179125. }
  179126. else
  179127. {
  179128. for (int i = (int) width; --i >= 0;)
  179129. {
  179130. ((PixelRGB*) dest)->setARGB (0, src[0], src[1], src[2]);
  179131. dest += destData.pixelStride;
  179132. src += 4;
  179133. }
  179134. }
  179135. }
  179136. }
  179137. return image;
  179138. }
  179139. static void pngWriteDataCallback (png_structp png_ptr, png_bytep data, png_size_t length)
  179140. {
  179141. OutputStream* const out = (OutputStream*) png_ptr->io_ptr;
  179142. const bool ok = out->write (data, (int) length);
  179143. (void) ok;
  179144. jassert (ok);
  179145. }
  179146. bool juce_writePNGImageToStream (const Image& image, OutputStream& out)
  179147. {
  179148. const int width = image.getWidth();
  179149. const int height = image.getHeight();
  179150. png_structp pngWriteStruct = png_create_write_struct (PNG_LIBPNG_VER_STRING, 0, 0, 0);
  179151. if (pngWriteStruct == 0)
  179152. return false;
  179153. png_infop pngInfoStruct = png_create_info_struct (pngWriteStruct);
  179154. if (pngInfoStruct == 0)
  179155. {
  179156. png_destroy_write_struct (&pngWriteStruct, (png_infopp) 0);
  179157. return false;
  179158. }
  179159. png_set_write_fn (pngWriteStruct, &out, pngWriteDataCallback, 0);
  179160. png_set_IHDR (pngWriteStruct, pngInfoStruct, width, height, 8,
  179161. image.hasAlphaChannel() ? PNG_COLOR_TYPE_RGB_ALPHA
  179162. : PNG_COLOR_TYPE_RGB,
  179163. PNG_INTERLACE_NONE,
  179164. PNG_COMPRESSION_TYPE_BASE,
  179165. PNG_FILTER_TYPE_BASE);
  179166. HeapBlock <png_byte> rowData (width * 4);
  179167. png_color_8 sig_bit;
  179168. sig_bit.red = 8;
  179169. sig_bit.green = 8;
  179170. sig_bit.blue = 8;
  179171. sig_bit.alpha = 8;
  179172. png_set_sBIT (pngWriteStruct, pngInfoStruct, &sig_bit);
  179173. png_write_info (pngWriteStruct, pngInfoStruct);
  179174. png_set_shift (pngWriteStruct, &sig_bit);
  179175. png_set_packing (pngWriteStruct);
  179176. const Image::BitmapData srcData (image, 0, 0, width, height);
  179177. for (int y = 0; y < height; ++y)
  179178. {
  179179. uint8* dst = (uint8*) rowData;
  179180. const uint8* src = srcData.getLinePointer (y);
  179181. if (image.hasAlphaChannel())
  179182. {
  179183. for (int i = width; --i >= 0;)
  179184. {
  179185. PixelARGB p (*(const PixelARGB*) src);
  179186. p.unpremultiply();
  179187. *dst++ = p.getRed();
  179188. *dst++ = p.getGreen();
  179189. *dst++ = p.getBlue();
  179190. *dst++ = p.getAlpha();
  179191. src += srcData.pixelStride;
  179192. }
  179193. }
  179194. else
  179195. {
  179196. for (int i = width; --i >= 0;)
  179197. {
  179198. *dst++ = ((const PixelRGB*) src)->getRed();
  179199. *dst++ = ((const PixelRGB*) src)->getGreen();
  179200. *dst++ = ((const PixelRGB*) src)->getBlue();
  179201. src += srcData.pixelStride;
  179202. }
  179203. }
  179204. png_write_rows (pngWriteStruct, &rowData, 1);
  179205. }
  179206. png_write_end (pngWriteStruct, pngInfoStruct);
  179207. png_destroy_write_struct (&pngWriteStruct, &pngInfoStruct);
  179208. out.flush();
  179209. return true;
  179210. }
  179211. END_JUCE_NAMESPACE
  179212. /*** End of inlined file: juce_PNGLoader.cpp ***/
  179213. #endif
  179214. //==============================================================================
  179215. #if JUCE_BUILD_NATIVE
  179216. #if JUCE_WINDOWS
  179217. /*** Start of inlined file: juce_win32_NativeCode.cpp ***/
  179218. #if JUCE_WINDOWS
  179219. BEGIN_JUCE_NAMESPACE
  179220. #define JUCE_INCLUDED_FILE 1
  179221. // Now include the actual code files..
  179222. /*** Start of inlined file: juce_win32_DynamicLibraryLoader.cpp ***/
  179223. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179224. // compiled on its own).
  179225. #if JUCE_INCLUDED_FILE
  179226. /*** Start of inlined file: juce_win32_DynamicLibraryLoader.h ***/
  179227. #ifndef __JUCE_WIN32_DYNAMICLIBRARYLOADER_JUCEHEADER__
  179228. #define __JUCE_WIN32_DYNAMICLIBRARYLOADER_JUCEHEADER__
  179229. #ifndef DOXYGEN
  179230. // use with DynamicLibraryLoader to simplify importing functions
  179231. //
  179232. // functionName: function to import
  179233. // localFunctionName: name you want to use to actually call it (must be different)
  179234. // returnType: the return type
  179235. // object: the DynamicLibraryLoader to use
  179236. // params: list of params (bracketed)
  179237. //
  179238. #define DynamicLibraryImport(functionName, localFunctionName, returnType, object, params) \
  179239. typedef returnType (WINAPI *type##localFunctionName) params; \
  179240. type##localFunctionName localFunctionName \
  179241. = (type##localFunctionName)object.findProcAddress (#functionName);
  179242. // loads and unloads a DLL automatically
  179243. class JUCE_API DynamicLibraryLoader
  179244. {
  179245. public:
  179246. DynamicLibraryLoader (const String& name);
  179247. ~DynamicLibraryLoader();
  179248. void* findProcAddress (const String& functionName);
  179249. private:
  179250. void* libHandle;
  179251. };
  179252. #endif
  179253. #endif // __JUCE_WIN32_DYNAMICLIBRARYLOADER_JUCEHEADER__
  179254. /*** End of inlined file: juce_win32_DynamicLibraryLoader.h ***/
  179255. DynamicLibraryLoader::DynamicLibraryLoader (const String& name)
  179256. {
  179257. libHandle = LoadLibrary (name);
  179258. }
  179259. DynamicLibraryLoader::~DynamicLibraryLoader()
  179260. {
  179261. FreeLibrary ((HMODULE) libHandle);
  179262. }
  179263. void* DynamicLibraryLoader::findProcAddress (const String& functionName)
  179264. {
  179265. return (void*) GetProcAddress ((HMODULE) libHandle, functionName.toCString());
  179266. }
  179267. #endif
  179268. /*** End of inlined file: juce_win32_DynamicLibraryLoader.cpp ***/
  179269. /*** Start of inlined file: juce_win32_SystemStats.cpp ***/
  179270. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179271. // compiled on its own).
  179272. #if JUCE_INCLUDED_FILE
  179273. extern void juce_initialiseThreadEvents();
  179274. void Logger::outputDebugString (const String& text) throw()
  179275. {
  179276. OutputDebugString (text + T("\n"));
  179277. }
  179278. static int64 hiResTicksPerSecond;
  179279. static double hiResTicksScaleFactor;
  179280. #if JUCE_USE_INTRINSICS
  179281. // CPU info functions using intrinsics...
  179282. #pragma intrinsic (__cpuid)
  179283. #pragma intrinsic (__rdtsc)
  179284. const String SystemStats::getCpuVendor() throw()
  179285. {
  179286. int info [4];
  179287. __cpuid (info, 0);
  179288. char v [12];
  179289. memcpy (v, info + 1, 4);
  179290. memcpy (v + 4, info + 3, 4);
  179291. memcpy (v + 8, info + 2, 4);
  179292. return String (v, 12);
  179293. }
  179294. #else
  179295. // CPU info functions using old fashioned inline asm...
  179296. static void juce_getCpuVendor (char* const v)
  179297. {
  179298. int vendor[4];
  179299. zeromem (vendor, 16);
  179300. #ifdef JUCE_64BIT
  179301. #else
  179302. #ifndef __MINGW32__
  179303. __try
  179304. #endif
  179305. {
  179306. #if JUCE_GCC
  179307. unsigned int dummy = 0;
  179308. __asm__ ("cpuid" : "=a" (dummy), "=b" (vendor[0]), "=c" (vendor[2]),"=d" (vendor[1]) : "a" (0));
  179309. #else
  179310. __asm
  179311. {
  179312. mov eax, 0
  179313. cpuid
  179314. mov [vendor], ebx
  179315. mov [vendor + 4], edx
  179316. mov [vendor + 8], ecx
  179317. }
  179318. #endif
  179319. }
  179320. #ifndef __MINGW32__
  179321. __except (EXCEPTION_EXECUTE_HANDLER)
  179322. {
  179323. *v = 0;
  179324. }
  179325. #endif
  179326. #endif
  179327. memcpy (v, vendor, 16);
  179328. }
  179329. const String SystemStats::getCpuVendor() throw()
  179330. {
  179331. char v [16];
  179332. juce_getCpuVendor (v);
  179333. return String (v, 16);
  179334. }
  179335. #endif
  179336. struct CPUFlags
  179337. {
  179338. bool hasMMX : 1;
  179339. bool hasSSE : 1;
  179340. bool hasSSE2 : 1;
  179341. bool has3DNow : 1;
  179342. };
  179343. static CPUFlags cpuFlags;
  179344. bool SystemStats::hasMMX() throw()
  179345. {
  179346. return cpuFlags.hasMMX;
  179347. }
  179348. bool SystemStats::hasSSE() throw()
  179349. {
  179350. return cpuFlags.hasSSE;
  179351. }
  179352. bool SystemStats::hasSSE2() throw()
  179353. {
  179354. return cpuFlags.hasSSE2;
  179355. }
  179356. bool SystemStats::has3DNow() throw()
  179357. {
  179358. return cpuFlags.has3DNow;
  179359. }
  179360. void SystemStats::initialiseStats() throw()
  179361. {
  179362. juce_initialiseThreadEvents();
  179363. cpuFlags.hasMMX = IsProcessorFeaturePresent (PF_MMX_INSTRUCTIONS_AVAILABLE) != 0;
  179364. cpuFlags.hasSSE = IsProcessorFeaturePresent (PF_XMMI_INSTRUCTIONS_AVAILABLE) != 0;
  179365. cpuFlags.hasSSE2 = IsProcessorFeaturePresent (PF_XMMI64_INSTRUCTIONS_AVAILABLE) != 0;
  179366. #ifdef PF_AMD3D_INSTRUCTIONS_AVAILABLE
  179367. cpuFlags.has3DNow = IsProcessorFeaturePresent (PF_AMD3D_INSTRUCTIONS_AVAILABLE) != 0;
  179368. #else
  179369. cpuFlags.has3DNow = IsProcessorFeaturePresent (PF_3DNOW_INSTRUCTIONS_AVAILABLE) != 0;
  179370. #endif
  179371. LARGE_INTEGER f;
  179372. QueryPerformanceFrequency (&f);
  179373. hiResTicksPerSecond = f.QuadPart;
  179374. hiResTicksScaleFactor = 1000.0 / hiResTicksPerSecond;
  179375. String s (SystemStats::getJUCEVersion());
  179376. #ifdef JUCE_DEBUG
  179377. const MMRESULT res = timeBeginPeriod (1);
  179378. jassert (res == TIMERR_NOERROR);
  179379. #else
  179380. timeBeginPeriod (1);
  179381. #endif
  179382. #if defined (JUCE_DEBUG) && JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS
  179383. _CrtSetDbgFlag (_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
  179384. #endif
  179385. }
  179386. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  179387. {
  179388. OSVERSIONINFO info;
  179389. info.dwOSVersionInfoSize = sizeof (info);
  179390. GetVersionEx (&info);
  179391. if (info.dwPlatformId == VER_PLATFORM_WIN32_NT)
  179392. {
  179393. switch (info.dwMajorVersion)
  179394. {
  179395. case 5: return (info.dwMinorVersion == 0) ? Win2000 : WinXP;
  179396. case 6: return (info.dwMinorVersion == 0) ? WinVista : Windows7;
  179397. default: jassertfalse; break; // !! not a supported OS!
  179398. }
  179399. }
  179400. else if (info.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
  179401. {
  179402. jassert (info.dwMinorVersion != 0); // !! still running on Windows 95??
  179403. return Win98;
  179404. }
  179405. return UnknownOS;
  179406. }
  179407. const String SystemStats::getOperatingSystemName() throw()
  179408. {
  179409. const char* name = "Unknown OS";
  179410. switch (getOperatingSystemType())
  179411. {
  179412. case Windows7: name = "Windows 7"; break;
  179413. case WinVista: name = "Windows Vista"; break;
  179414. case WinXP: name = "Windows XP"; break;
  179415. case Win2000: name = "Windows 2000"; break;
  179416. case Win98: name = "Windows 98"; break;
  179417. default: jassertfalse; break; // !! new type of OS?
  179418. }
  179419. return name;
  179420. }
  179421. bool SystemStats::isOperatingSystem64Bit() throw()
  179422. {
  179423. #ifdef _WIN64
  179424. return true;
  179425. #else
  179426. typedef BOOL (WINAPI* LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
  179427. LPFN_ISWOW64PROCESS fnIsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress (GetModuleHandle (L"kernel32"), "IsWow64Process");
  179428. BOOL isWow64 = FALSE;
  179429. return (fnIsWow64Process != 0)
  179430. && fnIsWow64Process (GetCurrentProcess(), &isWow64)
  179431. && (isWow64 != FALSE);
  179432. #endif
  179433. }
  179434. int SystemStats::getMemorySizeInMegabytes() throw()
  179435. {
  179436. MEMORYSTATUSEX mem;
  179437. mem.dwLength = sizeof (mem);
  179438. GlobalMemoryStatusEx (&mem);
  179439. return (int) (mem.ullTotalPhys / (1024 * 1024)) + 1;
  179440. }
  179441. int SystemStats::getNumCpus() throw()
  179442. {
  179443. SYSTEM_INFO systemInfo;
  179444. GetSystemInfo (&systemInfo);
  179445. return systemInfo.dwNumberOfProcessors;
  179446. }
  179447. uint32 juce_millisecondsSinceStartup() throw()
  179448. {
  179449. return (uint32) GetTickCount();
  179450. }
  179451. int64 Time::getHighResolutionTicks() throw()
  179452. {
  179453. LARGE_INTEGER ticks;
  179454. QueryPerformanceCounter (&ticks);
  179455. const int64 mainCounterAsHiResTicks = (GetTickCount() * hiResTicksPerSecond) / 1000;
  179456. const int64 newOffset = mainCounterAsHiResTicks - ticks.QuadPart;
  179457. // fix for a very obscure PCI hardware bug that can make the counter
  179458. // sometimes jump forwards by a few seconds..
  179459. static int64 hiResTicksOffset = 0;
  179460. const int64 offsetDrift = abs64 (newOffset - hiResTicksOffset);
  179461. if (offsetDrift > (hiResTicksPerSecond >> 1))
  179462. hiResTicksOffset = newOffset;
  179463. return ticks.QuadPart + hiResTicksOffset;
  179464. }
  179465. double Time::getMillisecondCounterHiRes() throw()
  179466. {
  179467. return getHighResolutionTicks() * hiResTicksScaleFactor;
  179468. }
  179469. int64 Time::getHighResolutionTicksPerSecond() throw()
  179470. {
  179471. return hiResTicksPerSecond;
  179472. }
  179473. int64 SystemStats::getClockCycleCounter() throw()
  179474. {
  179475. #if JUCE_USE_INTRINSICS
  179476. // MS intrinsics version...
  179477. return __rdtsc();
  179478. #elif JUCE_GCC
  179479. // GNU inline asm version...
  179480. unsigned int hi = 0, lo = 0;
  179481. __asm__ __volatile__ (
  179482. "xor %%eax, %%eax \n\
  179483. xor %%edx, %%edx \n\
  179484. rdtsc \n\
  179485. movl %%eax, %[lo] \n\
  179486. movl %%edx, %[hi]"
  179487. :
  179488. : [hi] "m" (hi),
  179489. [lo] "m" (lo)
  179490. : "cc", "eax", "ebx", "ecx", "edx", "memory");
  179491. return (int64) ((((uint64) hi) << 32) | lo);
  179492. #else
  179493. // MSVC inline asm version...
  179494. unsigned int hi = 0, lo = 0;
  179495. __asm
  179496. {
  179497. xor eax, eax
  179498. xor edx, edx
  179499. rdtsc
  179500. mov lo, eax
  179501. mov hi, edx
  179502. }
  179503. return (int64) ((((uint64) hi) << 32) | lo);
  179504. #endif
  179505. }
  179506. int SystemStats::getCpuSpeedInMegaherz() throw()
  179507. {
  179508. const int64 cycles = SystemStats::getClockCycleCounter();
  179509. const uint32 millis = Time::getMillisecondCounter();
  179510. int lastResult = 0;
  179511. for (;;)
  179512. {
  179513. int n = 1000000;
  179514. while (--n > 0) {}
  179515. const uint32 millisElapsed = Time::getMillisecondCounter() - millis;
  179516. const int64 cyclesNow = SystemStats::getClockCycleCounter();
  179517. if (millisElapsed > 80)
  179518. {
  179519. const int newResult = (int) (((cyclesNow - cycles) / millisElapsed) / 1000);
  179520. if (millisElapsed > 500 || (lastResult == newResult && newResult > 100))
  179521. return newResult;
  179522. lastResult = newResult;
  179523. }
  179524. }
  179525. }
  179526. bool Time::setSystemTimeToThisTime() const throw()
  179527. {
  179528. SYSTEMTIME st;
  179529. st.wDayOfWeek = 0;
  179530. st.wYear = (WORD) getYear();
  179531. st.wMonth = (WORD) (getMonth() + 1);
  179532. st.wDay = (WORD) getDayOfMonth();
  179533. st.wHour = (WORD) getHours();
  179534. st.wMinute = (WORD) getMinutes();
  179535. st.wSecond = (WORD) getSeconds();
  179536. st.wMilliseconds = (WORD) (millisSinceEpoch % 1000);
  179537. // do this twice because of daylight saving conversion problems - the
  179538. // first one sets it up, the second one kicks it in.
  179539. return SetLocalTime (&st) != 0
  179540. && SetLocalTime (&st) != 0;
  179541. }
  179542. int SystemStats::getPageSize() throw()
  179543. {
  179544. SYSTEM_INFO systemInfo;
  179545. GetSystemInfo (&systemInfo);
  179546. return systemInfo.dwPageSize;
  179547. }
  179548. const String SystemStats::getLogonName()
  179549. {
  179550. TCHAR text [256];
  179551. DWORD len = numElementsInArray (text) - 2;
  179552. zerostruct (text);
  179553. GetUserName (text, &len);
  179554. return String (text, len);
  179555. }
  179556. const String SystemStats::getFullUserName()
  179557. {
  179558. return getLogonName();
  179559. }
  179560. #endif
  179561. /*** End of inlined file: juce_win32_SystemStats.cpp ***/
  179562. /*** Start of inlined file: juce_win32_Threads.cpp ***/
  179563. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179564. // compiled on its own).
  179565. #if JUCE_INCLUDED_FILE
  179566. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  179567. extern HWND juce_messageWindowHandle;
  179568. #endif
  179569. #if ! JUCE_USE_INTRINSICS
  179570. // In newer compilers, the inline versions of these are used (in juce_Atomic.h), but in
  179571. // older ones we have to actually call the ops as win32 functions..
  179572. void Atomic::increment (int32& variable) { InterlockedIncrement (reinterpret_cast <volatile long*> (&variable)); }
  179573. int32 Atomic::incrementAndReturn (int32& variable) { return InterlockedIncrement (reinterpret_cast <volatile long*> (&variable)); }
  179574. void Atomic::decrement (int32& variable) { InterlockedDecrement (reinterpret_cast <volatile long*> (&variable)); }
  179575. int32 Atomic::decrementAndReturn (int32& variable) { return InterlockedDecrement (reinterpret_cast <volatile long*> (&variable)); }
  179576. int32 Atomic::compareAndExchange (int32& destination, int32 newValue, int32 oldValue)
  179577. { return InterlockedCompareExchange (reinterpret_cast <volatile long*> (&destination), newValue, oldValue); }
  179578. #endif
  179579. void* Atomic::swapPointers (void* volatile* value1, void* volatile value2) { return InterlockedExchangePointer (value1, value2); }
  179580. CriticalSection::CriticalSection() throw()
  179581. {
  179582. // (just to check the MS haven't changed this structure and broken things...)
  179583. #if _MSC_VER >= 1400
  179584. static_jassert (sizeof (CRITICAL_SECTION) <= sizeof (internal));
  179585. #else
  179586. static_jassert (sizeof (CRITICAL_SECTION) <= 24);
  179587. #endif
  179588. InitializeCriticalSection ((CRITICAL_SECTION*) internal);
  179589. }
  179590. CriticalSection::~CriticalSection() throw()
  179591. {
  179592. DeleteCriticalSection ((CRITICAL_SECTION*) internal);
  179593. }
  179594. void CriticalSection::enter() const throw()
  179595. {
  179596. EnterCriticalSection ((CRITICAL_SECTION*) internal);
  179597. }
  179598. bool CriticalSection::tryEnter() const throw()
  179599. {
  179600. return TryEnterCriticalSection ((CRITICAL_SECTION*) internal) != FALSE;
  179601. }
  179602. void CriticalSection::exit() const throw()
  179603. {
  179604. LeaveCriticalSection ((CRITICAL_SECTION*) internal);
  179605. }
  179606. WaitableEvent::WaitableEvent() throw()
  179607. : internal (CreateEvent (0, FALSE, FALSE, 0))
  179608. {
  179609. }
  179610. WaitableEvent::~WaitableEvent() throw()
  179611. {
  179612. CloseHandle (internal);
  179613. }
  179614. bool WaitableEvent::wait (const int timeOutMillisecs) const throw()
  179615. {
  179616. return WaitForSingleObject (internal, timeOutMillisecs) == WAIT_OBJECT_0;
  179617. }
  179618. void WaitableEvent::signal() const throw()
  179619. {
  179620. SetEvent (internal);
  179621. }
  179622. void WaitableEvent::reset() const throw()
  179623. {
  179624. ResetEvent (internal);
  179625. }
  179626. void JUCE_API juce_threadEntryPoint (void*);
  179627. static unsigned int __stdcall threadEntryProc (void* userData)
  179628. {
  179629. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  179630. AttachThreadInput (GetWindowThreadProcessId (juce_messageWindowHandle, 0),
  179631. GetCurrentThreadId(), TRUE);
  179632. #endif
  179633. juce_threadEntryPoint (userData);
  179634. _endthreadex (0);
  179635. return 0;
  179636. }
  179637. void juce_CloseThreadHandle (void* handle)
  179638. {
  179639. CloseHandle ((HANDLE) handle);
  179640. }
  179641. void* juce_createThread (void* userData)
  179642. {
  179643. unsigned int threadId;
  179644. return (void*) _beginthreadex (0, 0,
  179645. &threadEntryProc,
  179646. userData,
  179647. 0, &threadId);
  179648. }
  179649. void juce_killThread (void* handle)
  179650. {
  179651. if (handle != 0)
  179652. {
  179653. #ifdef JUCE_DEBUG
  179654. OutputDebugString (_T("** Warning - Forced thread termination **\n"));
  179655. #endif
  179656. TerminateThread (handle, 0);
  179657. }
  179658. }
  179659. void juce_setCurrentThreadName (const String& name)
  179660. {
  179661. #if defined (JUCE_DEBUG) && JUCE_MSVC
  179662. struct
  179663. {
  179664. DWORD dwType;
  179665. LPCSTR szName;
  179666. DWORD dwThreadID;
  179667. DWORD dwFlags;
  179668. } info;
  179669. info.dwType = 0x1000;
  179670. info.szName = name.toCString();
  179671. info.dwThreadID = GetCurrentThreadId();
  179672. info.dwFlags = 0;
  179673. #define MS_VC_EXCEPTION 0x406d1388
  179674. __try
  179675. {
  179676. RaiseException (MS_VC_EXCEPTION, 0, sizeof (info) / sizeof (ULONG_PTR), (ULONG_PTR*) &info);
  179677. }
  179678. __except (EXCEPTION_CONTINUE_EXECUTION)
  179679. {}
  179680. #else
  179681. (void) name;
  179682. #endif
  179683. }
  179684. Thread::ThreadID Thread::getCurrentThreadId()
  179685. {
  179686. return (ThreadID) (pointer_sized_int) GetCurrentThreadId();
  179687. }
  179688. // priority 1 to 10 where 5=normal, 1=low
  179689. bool juce_setThreadPriority (void* threadHandle, int priority)
  179690. {
  179691. int pri = THREAD_PRIORITY_TIME_CRITICAL;
  179692. if (priority < 1)
  179693. pri = THREAD_PRIORITY_IDLE;
  179694. else if (priority < 2)
  179695. pri = THREAD_PRIORITY_LOWEST;
  179696. else if (priority < 5)
  179697. pri = THREAD_PRIORITY_BELOW_NORMAL;
  179698. else if (priority < 7)
  179699. pri = THREAD_PRIORITY_NORMAL;
  179700. else if (priority < 9)
  179701. pri = THREAD_PRIORITY_ABOVE_NORMAL;
  179702. else if (priority < 10)
  179703. pri = THREAD_PRIORITY_HIGHEST;
  179704. if (threadHandle == 0)
  179705. threadHandle = GetCurrentThread();
  179706. return SetThreadPriority (threadHandle, pri) != FALSE;
  179707. }
  179708. void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
  179709. {
  179710. SetThreadAffinityMask (GetCurrentThread(), affinityMask);
  179711. }
  179712. static HANDLE sleepEvent = 0;
  179713. void juce_initialiseThreadEvents()
  179714. {
  179715. if (sleepEvent == 0)
  179716. #ifdef JUCE_DEBUG
  179717. sleepEvent = CreateEvent (0, 0, 0, _T("Juce Sleep Event"));
  179718. #else
  179719. sleepEvent = CreateEvent (0, 0, 0, 0);
  179720. #endif
  179721. }
  179722. void Thread::yield()
  179723. {
  179724. Sleep (0);
  179725. }
  179726. void JUCE_CALLTYPE Thread::sleep (const int millisecs)
  179727. {
  179728. if (millisecs >= 10)
  179729. {
  179730. Sleep (millisecs);
  179731. }
  179732. else
  179733. {
  179734. jassert (sleepEvent != 0);
  179735. // unlike Sleep() this is guaranteed to return to the current thread after
  179736. // the time expires, so we'll use this for short waits, which are more likely
  179737. // to need to be accurate
  179738. WaitForSingleObject (sleepEvent, millisecs);
  179739. }
  179740. }
  179741. static int lastProcessPriority = -1;
  179742. // called by WindowDriver because Windows does wierd things to process priority
  179743. // when you swap apps, and this forces an update when the app is brought to the front.
  179744. void juce_repeatLastProcessPriority()
  179745. {
  179746. if (lastProcessPriority >= 0) // (avoid changing this if it's not been explicitly set by the app..)
  179747. {
  179748. DWORD p;
  179749. switch (lastProcessPriority)
  179750. {
  179751. case Process::LowPriority:
  179752. p = IDLE_PRIORITY_CLASS;
  179753. break;
  179754. case Process::NormalPriority:
  179755. p = NORMAL_PRIORITY_CLASS;
  179756. break;
  179757. case Process::HighPriority:
  179758. p = HIGH_PRIORITY_CLASS;
  179759. break;
  179760. case Process::RealtimePriority:
  179761. p = REALTIME_PRIORITY_CLASS;
  179762. break;
  179763. default:
  179764. jassertfalse // bad priority value
  179765. return;
  179766. }
  179767. SetPriorityClass (GetCurrentProcess(), p);
  179768. }
  179769. }
  179770. void Process::setPriority (ProcessPriority prior)
  179771. {
  179772. if (lastProcessPriority != (int) prior)
  179773. {
  179774. lastProcessPriority = (int) prior;
  179775. juce_repeatLastProcessPriority();
  179776. }
  179777. }
  179778. bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger()
  179779. {
  179780. return IsDebuggerPresent() != FALSE;
  179781. }
  179782. bool JUCE_CALLTYPE Process::isRunningUnderDebugger()
  179783. {
  179784. return juce_isRunningUnderDebugger();
  179785. }
  179786. void Process::raisePrivilege()
  179787. {
  179788. jassertfalse // xxx not implemented
  179789. }
  179790. void Process::lowerPrivilege()
  179791. {
  179792. jassertfalse // xxx not implemented
  179793. }
  179794. void Process::terminate()
  179795. {
  179796. #if defined (JUCE_DEBUG) && JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS
  179797. _CrtDumpMemoryLeaks();
  179798. #endif
  179799. // bullet in the head in case there's a problem shutting down..
  179800. ExitProcess (0);
  179801. }
  179802. void* PlatformUtilities::loadDynamicLibrary (const String& name)
  179803. {
  179804. void* result = 0;
  179805. JUCE_TRY
  179806. {
  179807. result = (void*) LoadLibrary (name);
  179808. }
  179809. JUCE_CATCH_ALL
  179810. return result;
  179811. }
  179812. void PlatformUtilities::freeDynamicLibrary (void* h)
  179813. {
  179814. JUCE_TRY
  179815. {
  179816. if (h != 0)
  179817. FreeLibrary ((HMODULE) h);
  179818. }
  179819. JUCE_CATCH_ALL
  179820. }
  179821. void* PlatformUtilities::getProcedureEntryPoint (void* h, const String& name)
  179822. {
  179823. return (h != 0) ? (void*) GetProcAddress ((HMODULE) h, name.toCString()) : 0;
  179824. }
  179825. InterProcessLock::InterProcessLock (const String& name_)
  179826. : internal (0),
  179827. name (name_),
  179828. reentrancyLevel (0)
  179829. {
  179830. }
  179831. InterProcessLock::~InterProcessLock()
  179832. {
  179833. exit();
  179834. }
  179835. bool InterProcessLock::enter (const int timeOutMillisecs)
  179836. {
  179837. if (reentrancyLevel++ == 0)
  179838. {
  179839. internal = CreateMutex (0, TRUE, "Global\\" + name);
  179840. if (internal != 0 && GetLastError() == ERROR_ALREADY_EXISTS)
  179841. {
  179842. if (timeOutMillisecs == 0
  179843. || WaitForSingleObject (internal, (timeOutMillisecs < 0) ? INFINITE : timeOutMillisecs)
  179844. == WAIT_TIMEOUT)
  179845. {
  179846. ReleaseMutex (internal);
  179847. CloseHandle (internal);
  179848. internal = 0;
  179849. }
  179850. }
  179851. }
  179852. return (internal != 0);
  179853. }
  179854. void InterProcessLock::exit()
  179855. {
  179856. if (--reentrancyLevel == 0 && internal != 0)
  179857. {
  179858. ReleaseMutex (internal);
  179859. CloseHandle (internal);
  179860. internal = 0;
  179861. }
  179862. }
  179863. #endif
  179864. /*** End of inlined file: juce_win32_Threads.cpp ***/
  179865. /*** Start of inlined file: juce_win32_Files.cpp ***/
  179866. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179867. // compiled on its own).
  179868. #if JUCE_INCLUDED_FILE
  179869. #ifndef CSIDL_MYMUSIC
  179870. #define CSIDL_MYMUSIC 0x000d
  179871. #endif
  179872. #ifndef CSIDL_MYVIDEO
  179873. #define CSIDL_MYVIDEO 0x000e
  179874. #endif
  179875. const tchar File::separator = T('\\');
  179876. const tchar* File::separatorString = T("\\");
  179877. bool juce_fileExists (const String& fileName, const bool dontCountDirectories)
  179878. {
  179879. if (fileName.isEmpty())
  179880. return false;
  179881. const DWORD attr = GetFileAttributes (fileName);
  179882. return dontCountDirectories ? ((attr & FILE_ATTRIBUTE_DIRECTORY) == 0)
  179883. : (attr != 0xffffffff);
  179884. }
  179885. bool juce_isDirectory (const String& fileName)
  179886. {
  179887. const DWORD attr = GetFileAttributes (fileName);
  179888. return (attr != 0xffffffff)
  179889. && ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0);
  179890. }
  179891. bool juce_canWriteToFile (const String& fileName)
  179892. {
  179893. const DWORD attr = GetFileAttributes (fileName);
  179894. return ((attr & FILE_ATTRIBUTE_READONLY) == 0);
  179895. }
  179896. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly)
  179897. {
  179898. DWORD attr = GetFileAttributes (fileName);
  179899. if (attr == 0xffffffff)
  179900. return false;
  179901. if (isReadOnly != juce_canWriteToFile (fileName))
  179902. return true;
  179903. if (isReadOnly)
  179904. attr |= FILE_ATTRIBUTE_READONLY;
  179905. else
  179906. attr &= ~FILE_ATTRIBUTE_READONLY;
  179907. return SetFileAttributes (fileName, attr) != FALSE;
  179908. }
  179909. bool File::isHidden() const
  179910. {
  179911. return (GetFileAttributes (getFullPathName()) & FILE_ATTRIBUTE_HIDDEN) != 0;
  179912. }
  179913. bool juce_deleteFile (const String& fileName)
  179914. {
  179915. if (juce_isDirectory (fileName))
  179916. return RemoveDirectory (fileName) != 0;
  179917. return DeleteFile (fileName) != 0;
  179918. }
  179919. bool File::moveToTrash() const
  179920. {
  179921. if (! exists())
  179922. return true;
  179923. SHFILEOPSTRUCT fos;
  179924. zerostruct (fos);
  179925. // The string we pass in must be double null terminated..
  179926. String doubleNullTermPath (getFullPathName() + " ");
  179927. TCHAR* p = (TCHAR*) (const TCHAR*) doubleNullTermPath;
  179928. p [getFullPathName().length()] = 0;
  179929. fos.wFunc = FO_DELETE;
  179930. fos.hwnd = (HWND) 0;
  179931. fos.pFrom = p;
  179932. fos.pTo = NULL;
  179933. fos.fFlags = FOF_ALLOWUNDO | FOF_NOERRORUI | FOF_SILENT | FOF_NOCONFIRMATION
  179934. | FOF_NOCONFIRMMKDIR | FOF_RENAMEONCOLLISION;
  179935. return SHFileOperation (&fos) == 0;
  179936. }
  179937. bool juce_moveFile (const String& source, const String& dest)
  179938. {
  179939. return MoveFile (source, dest) != 0;
  179940. }
  179941. bool juce_copyFile (const String& source, const String& dest)
  179942. {
  179943. return CopyFile (source, dest, false) != 0;
  179944. }
  179945. void juce_createDirectory (const String& fileName)
  179946. {
  179947. if (! juce_fileExists (fileName, true))
  179948. {
  179949. CreateDirectory (fileName, 0);
  179950. }
  179951. }
  179952. // return 0 if not possible
  179953. void* juce_fileOpen (const String& fileName, bool forWriting)
  179954. {
  179955. HANDLE h;
  179956. if (forWriting)
  179957. {
  179958. h = CreateFile (fileName, GENERIC_WRITE, FILE_SHARE_READ, 0,
  179959. OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
  179960. if (h != INVALID_HANDLE_VALUE)
  179961. SetFilePointer (h, 0, 0, FILE_END);
  179962. else
  179963. h = 0;
  179964. }
  179965. else
  179966. {
  179967. h = CreateFile (fileName, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 0,
  179968. OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, 0);
  179969. if (h == INVALID_HANDLE_VALUE)
  179970. h = 0;
  179971. }
  179972. return (void*) h;
  179973. }
  179974. void juce_fileClose (void* handle)
  179975. {
  179976. CloseHandle (handle);
  179977. }
  179978. int juce_fileRead (void* handle, void* buffer, int size)
  179979. {
  179980. DWORD num = 0;
  179981. ReadFile ((HANDLE) handle, buffer, size, &num, 0);
  179982. return num;
  179983. }
  179984. int juce_fileWrite (void* handle, const void* buffer, int size)
  179985. {
  179986. DWORD num;
  179987. WriteFile ((HANDLE) handle,
  179988. buffer, size,
  179989. &num, 0);
  179990. return num;
  179991. }
  179992. int64 juce_fileSetPosition (void* handle, int64 pos)
  179993. {
  179994. LARGE_INTEGER li;
  179995. li.QuadPart = pos;
  179996. li.LowPart = SetFilePointer ((HANDLE) handle,
  179997. li.LowPart,
  179998. &li.HighPart,
  179999. FILE_BEGIN); // (returns -1 if it fails)
  180000. return li.QuadPart;
  180001. }
  180002. int64 juce_fileGetPosition (void* handle)
  180003. {
  180004. LARGE_INTEGER li;
  180005. li.QuadPart = 0;
  180006. li.LowPart = SetFilePointer ((HANDLE) handle,
  180007. 0, &li.HighPart,
  180008. FILE_CURRENT); // (returns -1 if it fails)
  180009. return jmax ((int64) 0, li.QuadPart);
  180010. }
  180011. void juce_fileFlush (void* handle)
  180012. {
  180013. FlushFileBuffers ((HANDLE) handle);
  180014. }
  180015. int64 juce_getFileSize (const String& fileName)
  180016. {
  180017. WIN32_FILE_ATTRIBUTE_DATA attributes;
  180018. if (GetFileAttributesEx (fileName, GetFileExInfoStandard, &attributes))
  180019. {
  180020. return (((int64) attributes.nFileSizeHigh) << 32)
  180021. | attributes.nFileSizeLow;
  180022. }
  180023. return 0;
  180024. }
  180025. static int64 fileTimeToTime (const FILETIME* const ft)
  180026. {
  180027. // tell me if this fails!
  180028. static_jassert (sizeof (ULARGE_INTEGER) == sizeof (FILETIME));
  180029. #if JUCE_GCC
  180030. return (((const ULARGE_INTEGER*) ft)->QuadPart - 116444736000000000LL) / 10000;
  180031. #else
  180032. return (((const ULARGE_INTEGER*) ft)->QuadPart - 116444736000000000) / 10000;
  180033. #endif
  180034. }
  180035. static void timeToFileTime (const int64 time, FILETIME* const ft)
  180036. {
  180037. #if JUCE_GCC
  180038. ((ULARGE_INTEGER*) ft)->QuadPart = time * 10000 + 116444736000000000LL;
  180039. #else
  180040. ((ULARGE_INTEGER*) ft)->QuadPart = time * 10000 + 116444736000000000;
  180041. #endif
  180042. }
  180043. void juce_getFileTimes (const String& fileName,
  180044. int64& modificationTime,
  180045. int64& accessTime,
  180046. int64& creationTime)
  180047. {
  180048. WIN32_FILE_ATTRIBUTE_DATA attributes;
  180049. if (GetFileAttributesEx (fileName, GetFileExInfoStandard, &attributes))
  180050. {
  180051. modificationTime = fileTimeToTime (&attributes.ftLastWriteTime);
  180052. creationTime = fileTimeToTime (&attributes.ftCreationTime);
  180053. accessTime = fileTimeToTime (&attributes.ftLastAccessTime);
  180054. }
  180055. else
  180056. {
  180057. creationTime = accessTime = modificationTime = 0;
  180058. }
  180059. }
  180060. bool juce_setFileTimes (const String& fileName,
  180061. int64 modificationTime,
  180062. int64 accessTime,
  180063. int64 creationTime)
  180064. {
  180065. FILETIME m, a, c;
  180066. if (modificationTime > 0)
  180067. timeToFileTime (modificationTime, &m);
  180068. if (accessTime > 0)
  180069. timeToFileTime (accessTime, &a);
  180070. if (creationTime > 0)
  180071. timeToFileTime (creationTime, &c);
  180072. void* const h = juce_fileOpen (fileName, true);
  180073. bool ok = false;
  180074. if (h != 0)
  180075. {
  180076. ok = SetFileTime ((HANDLE) h,
  180077. (creationTime > 0) ? &c : 0,
  180078. (accessTime > 0) ? &a : 0,
  180079. (modificationTime > 0) ? &m : 0) != 0;
  180080. juce_fileClose (h);
  180081. }
  180082. return ok;
  180083. }
  180084. // return '\0' separated list of strings
  180085. const StringArray juce_getFileSystemRoots()
  180086. {
  180087. TCHAR buffer [2048];
  180088. buffer[0] = 0;
  180089. buffer[1] = 0;
  180090. GetLogicalDriveStrings (2048, buffer);
  180091. TCHAR* n = buffer;
  180092. StringArray roots;
  180093. while (*n != 0)
  180094. {
  180095. roots.add (String (n));
  180096. while (*n++ != 0)
  180097. {
  180098. }
  180099. }
  180100. roots.sort (true);
  180101. return roots;
  180102. }
  180103. const String juce_getVolumeLabel (const String& filenameOnVolume,
  180104. int& volumeSerialNumber)
  180105. {
  180106. TCHAR n [4];
  180107. n[0] = *(const TCHAR*) filenameOnVolume;
  180108. n[1] = L':';
  180109. n[2] = L'\\';
  180110. n[3] = 0;
  180111. TCHAR dest [64];
  180112. DWORD serialNum;
  180113. if (! GetVolumeInformation (n, dest, 64, (DWORD*) &serialNum, 0, 0, 0, 0))
  180114. {
  180115. dest[0] = 0;
  180116. serialNum = 0;
  180117. }
  180118. volumeSerialNumber = serialNum;
  180119. return String (dest);
  180120. }
  180121. static int64 getDiskSpaceInfo (String fn, const bool total)
  180122. {
  180123. if (fn[1] == T(':'))
  180124. fn = fn.substring (0, 2) + T("\\");
  180125. ULARGE_INTEGER spc, tot, totFree;
  180126. if (GetDiskFreeSpaceEx (fn, &spc, &tot, &totFree))
  180127. return (int64) (total ? tot.QuadPart
  180128. : spc.QuadPart);
  180129. return 0;
  180130. }
  180131. int64 File::getBytesFreeOnVolume() const
  180132. {
  180133. return getDiskSpaceInfo (getFullPathName(), false);
  180134. }
  180135. int64 File::getVolumeTotalSize() const
  180136. {
  180137. return getDiskSpaceInfo (getFullPathName(), true);
  180138. }
  180139. static unsigned int getWindowsDriveType (const String& fileName)
  180140. {
  180141. TCHAR n[4];
  180142. n[0] = *(const TCHAR*) fileName;
  180143. n[1] = L':';
  180144. n[2] = L'\\';
  180145. n[3] = 0;
  180146. return GetDriveType (n);
  180147. }
  180148. bool File::isOnCDRomDrive() const
  180149. {
  180150. return getWindowsDriveType (getFullPathName()) == DRIVE_CDROM;
  180151. }
  180152. bool File::isOnHardDisk() const
  180153. {
  180154. if (fullPath.isEmpty())
  180155. return false;
  180156. const unsigned int n = getWindowsDriveType (getFullPathName());
  180157. if (fullPath.toLowerCase()[0] <= 'b'
  180158. && fullPath[1] == T(':'))
  180159. {
  180160. return n != DRIVE_REMOVABLE;
  180161. }
  180162. else
  180163. {
  180164. return n != DRIVE_CDROM && n != DRIVE_REMOTE;
  180165. }
  180166. }
  180167. bool File::isOnRemovableDrive() const
  180168. {
  180169. if (fullPath.isEmpty())
  180170. return false;
  180171. const unsigned int n = getWindowsDriveType (getFullPathName());
  180172. return n == DRIVE_CDROM
  180173. || n == DRIVE_REMOTE
  180174. || n == DRIVE_REMOVABLE
  180175. || n == DRIVE_RAMDISK;
  180176. }
  180177. static const File juce_getSpecialFolderPath (int type)
  180178. {
  180179. WCHAR path [MAX_PATH + 256];
  180180. if (SHGetSpecialFolderPath (0, path, type, 0))
  180181. return File (String (path));
  180182. return File::nonexistent;
  180183. }
  180184. const File JUCE_CALLTYPE File::getSpecialLocation (const SpecialLocationType type)
  180185. {
  180186. int csidlType = 0;
  180187. switch (type)
  180188. {
  180189. case userHomeDirectory:
  180190. csidlType = CSIDL_PROFILE;
  180191. break;
  180192. case userDocumentsDirectory:
  180193. csidlType = CSIDL_PERSONAL;
  180194. break;
  180195. case userDesktopDirectory:
  180196. csidlType = CSIDL_DESKTOP;
  180197. break;
  180198. case userApplicationDataDirectory:
  180199. csidlType = CSIDL_APPDATA;
  180200. break;
  180201. case commonApplicationDataDirectory:
  180202. csidlType = CSIDL_COMMON_APPDATA;
  180203. break;
  180204. case globalApplicationsDirectory:
  180205. csidlType = CSIDL_PROGRAM_FILES;
  180206. break;
  180207. case userMusicDirectory:
  180208. csidlType = CSIDL_MYMUSIC;
  180209. break;
  180210. case userMoviesDirectory:
  180211. csidlType = CSIDL_MYVIDEO;
  180212. break;
  180213. case tempDirectory:
  180214. {
  180215. WCHAR dest [2048];
  180216. dest[0] = 0;
  180217. GetTempPath (2048, dest);
  180218. return File (String (dest));
  180219. }
  180220. case invokedExecutableFile:
  180221. case currentExecutableFile:
  180222. case currentApplicationFile:
  180223. {
  180224. HINSTANCE moduleHandle = (HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle();
  180225. WCHAR dest [MAX_PATH + 256];
  180226. dest[0] = 0;
  180227. GetModuleFileName (moduleHandle, dest, numElementsInArray (dest));
  180228. return File (String (dest));
  180229. }
  180230. break;
  180231. default:
  180232. jassertfalse // unknown type?
  180233. return File::nonexistent;
  180234. }
  180235. return juce_getSpecialFolderPath (csidlType);
  180236. }
  180237. const File File::getCurrentWorkingDirectory()
  180238. {
  180239. WCHAR dest [MAX_PATH + 256];
  180240. dest[0] = 0;
  180241. GetCurrentDirectory (numElementsInArray (dest), dest);
  180242. return File (String (dest));
  180243. }
  180244. bool File::setAsCurrentWorkingDirectory() const
  180245. {
  180246. return SetCurrentDirectory (getFullPathName()) != FALSE;
  180247. }
  180248. const String File::getVersion() const
  180249. {
  180250. String result;
  180251. DWORD handle = 0;
  180252. DWORD bufferSize = GetFileVersionInfoSize (getFullPathName(), &handle);
  180253. HeapBlock <char> buffer;
  180254. buffer.calloc (bufferSize);
  180255. if (GetFileVersionInfo (getFullPathName(), 0, bufferSize, buffer))
  180256. {
  180257. VS_FIXEDFILEINFO* vffi;
  180258. UINT len = 0;
  180259. if (VerQueryValue (buffer, (LPTSTR) _T("\\"), (LPVOID*) &vffi, &len))
  180260. {
  180261. result << (int) HIWORD (vffi->dwFileVersionMS) << "."
  180262. << (int) LOWORD (vffi->dwFileVersionMS) << "."
  180263. << (int) HIWORD (vffi->dwFileVersionLS) << "."
  180264. << (int) LOWORD (vffi->dwFileVersionLS);
  180265. }
  180266. }
  180267. return result;
  180268. }
  180269. const File File::getLinkedTarget() const
  180270. {
  180271. File result (*this);
  180272. String p (getFullPathName());
  180273. if (! exists())
  180274. p += T(".lnk");
  180275. else if (getFileExtension() != T(".lnk"))
  180276. return result;
  180277. ComSmartPtr <IShellLink> shellLink;
  180278. if (SUCCEEDED (shellLink.CoCreateInstance (CLSID_ShellLink, CLSCTX_INPROC_SERVER)))
  180279. {
  180280. ComSmartPtr <IPersistFile> persistFile;
  180281. if (SUCCEEDED (shellLink->QueryInterface (IID_IPersistFile, (LPVOID*) &persistFile)))
  180282. {
  180283. if (SUCCEEDED (persistFile->Load ((const WCHAR*) p, STGM_READ))
  180284. && SUCCEEDED (shellLink->Resolve (0, SLR_ANY_MATCH | SLR_NO_UI)))
  180285. {
  180286. WIN32_FIND_DATA winFindData;
  180287. WCHAR resolvedPath [MAX_PATH];
  180288. if (SUCCEEDED (shellLink->GetPath (resolvedPath, MAX_PATH, &winFindData, SLGP_UNCPRIORITY)))
  180289. result = File (resolvedPath);
  180290. }
  180291. }
  180292. }
  180293. return result;
  180294. }
  180295. template <class FindDataType>
  180296. static void getFindFileInfo (FindDataType& findData,
  180297. String& filename, bool* const isDir, bool* const isHidden,
  180298. int64* const fileSize, Time* const modTime, Time* const creationTime,
  180299. bool* const isReadOnly)
  180300. {
  180301. filename = findData.cFileName;
  180302. if (isDir != 0)
  180303. *isDir = ((findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0);
  180304. if (isHidden != 0)
  180305. *isHidden = ((findData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) != 0);
  180306. if (fileSize != 0)
  180307. *fileSize = findData.nFileSizeLow + (((int64) findData.nFileSizeHigh) << 32);
  180308. if (modTime != 0)
  180309. *modTime = fileTimeToTime (&findData.ftLastWriteTime);
  180310. if (creationTime != 0)
  180311. *creationTime = fileTimeToTime (&findData.ftCreationTime);
  180312. if (isReadOnly != 0)
  180313. *isReadOnly = ((findData.dwFileAttributes & FILE_ATTRIBUTE_READONLY) != 0);
  180314. }
  180315. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResult,
  180316. bool* isDir, bool* isHidden, int64* fileSize,
  180317. Time* modTime, Time* creationTime, bool* isReadOnly)
  180318. {
  180319. String wc (directory);
  180320. if (! wc.endsWithChar (File::separator))
  180321. wc += File::separator;
  180322. wc += wildCard;
  180323. WIN32_FIND_DATA findData;
  180324. HANDLE h = FindFirstFile (wc, &findData);
  180325. if (h != INVALID_HANDLE_VALUE)
  180326. {
  180327. getFindFileInfo (findData, firstResult, isDir, isHidden, fileSize,
  180328. modTime, creationTime, isReadOnly);
  180329. return h;
  180330. }
  180331. firstResult = String::empty;
  180332. return 0;
  180333. }
  180334. bool juce_findFileNext (void* handle, String& resultFile,
  180335. bool* isDir, bool* isHidden, int64* fileSize,
  180336. Time* modTime, Time* creationTime, bool* isReadOnly)
  180337. {
  180338. WIN32_FIND_DATA findData;
  180339. if (handle != 0 && FindNextFile ((HANDLE) handle, &findData) != 0)
  180340. {
  180341. getFindFileInfo (findData, resultFile, isDir, isHidden, fileSize,
  180342. modTime, creationTime, isReadOnly);
  180343. return true;
  180344. }
  180345. resultFile = String::empty;
  180346. return false;
  180347. }
  180348. void juce_findFileClose (void* handle)
  180349. {
  180350. FindClose (handle);
  180351. }
  180352. bool juce_launchFile (const String& fileName,
  180353. const String& parameters)
  180354. {
  180355. HINSTANCE hInstance = 0;
  180356. JUCE_TRY
  180357. {
  180358. hInstance = ShellExecute (0, 0, fileName, parameters, 0, SW_SHOWDEFAULT);
  180359. }
  180360. JUCE_CATCH_ALL
  180361. return hInstance > (HINSTANCE) 32;
  180362. }
  180363. void File::revealToUser() const
  180364. {
  180365. if (isDirectory())
  180366. startAsProcess();
  180367. else if (getParentDirectory().exists())
  180368. getParentDirectory().startAsProcess();
  180369. }
  180370. struct NamedPipeInternal
  180371. {
  180372. HANDLE pipeH;
  180373. HANDLE cancelEvent;
  180374. bool connected, createdPipe;
  180375. NamedPipeInternal()
  180376. : pipeH (0),
  180377. cancelEvent (0),
  180378. connected (false),
  180379. createdPipe (false)
  180380. {
  180381. cancelEvent = CreateEvent (0, FALSE, FALSE, 0);
  180382. }
  180383. ~NamedPipeInternal()
  180384. {
  180385. disconnect();
  180386. if (pipeH != 0)
  180387. CloseHandle (pipeH);
  180388. CloseHandle (cancelEvent);
  180389. }
  180390. bool connect (const int timeOutMs)
  180391. {
  180392. if (! createdPipe)
  180393. return true;
  180394. if (! connected)
  180395. {
  180396. OVERLAPPED over;
  180397. zerostruct (over);
  180398. over.hEvent = CreateEvent (0, TRUE, FALSE, 0);
  180399. if (ConnectNamedPipe (pipeH, &over))
  180400. {
  180401. connected = false; // yes, you read that right. In overlapped mode it should always return 0.
  180402. }
  180403. else
  180404. {
  180405. const int err = GetLastError();
  180406. if (err == ERROR_IO_PENDING || err == ERROR_PIPE_LISTENING)
  180407. {
  180408. HANDLE handles[] = { over.hEvent, cancelEvent };
  180409. if (WaitForMultipleObjects (2, handles, FALSE,
  180410. timeOutMs >= 0 ? timeOutMs : INFINITE) == WAIT_OBJECT_0)
  180411. connected = true;
  180412. }
  180413. else if (err == ERROR_PIPE_CONNECTED)
  180414. {
  180415. connected = true;
  180416. }
  180417. }
  180418. CloseHandle (over.hEvent);
  180419. }
  180420. return connected;
  180421. }
  180422. void disconnect()
  180423. {
  180424. if (connected)
  180425. {
  180426. DisconnectNamedPipe (pipeH);
  180427. connected = false;
  180428. }
  180429. }
  180430. };
  180431. void NamedPipe::close()
  180432. {
  180433. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  180434. delete intern;
  180435. internal = 0;
  180436. }
  180437. bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
  180438. {
  180439. close();
  180440. NamedPipeInternal* const intern = new NamedPipeInternal();
  180441. String file ("\\\\.\\pipe\\");
  180442. file += pipeName;
  180443. intern->createdPipe = createPipe;
  180444. if (createPipe)
  180445. {
  180446. intern->pipeH = CreateNamedPipe (file, PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED, 0,
  180447. PIPE_UNLIMITED_INSTANCES,
  180448. 4096, 4096, 0, NULL);
  180449. }
  180450. else
  180451. {
  180452. intern->pipeH = CreateFile (file, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING,
  180453. FILE_FLAG_OVERLAPPED, 0);
  180454. }
  180455. if (intern->pipeH != INVALID_HANDLE_VALUE)
  180456. {
  180457. internal = intern;
  180458. return true;
  180459. }
  180460. delete intern;
  180461. return false;
  180462. }
  180463. int NamedPipe::read (void* destBuffer, int maxBytesToRead, int timeOutMilliseconds)
  180464. {
  180465. int bytesRead = -1;
  180466. bool waitAgain = true;
  180467. while (waitAgain && internal != 0)
  180468. {
  180469. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  180470. waitAgain = false;
  180471. if (! intern->connect (timeOutMilliseconds))
  180472. break;
  180473. if (maxBytesToRead <= 0)
  180474. return 0;
  180475. OVERLAPPED over;
  180476. zerostruct (over);
  180477. over.hEvent = CreateEvent (0, TRUE, FALSE, 0);
  180478. unsigned long numRead;
  180479. if (ReadFile (intern->pipeH, destBuffer, maxBytesToRead, &numRead, &over))
  180480. {
  180481. bytesRead = (int) numRead;
  180482. }
  180483. else if (GetLastError() == ERROR_IO_PENDING)
  180484. {
  180485. HANDLE handles[] = { over.hEvent, intern->cancelEvent };
  180486. DWORD waitResult = WaitForMultipleObjects (2, handles, FALSE,
  180487. timeOutMilliseconds >= 0 ? timeOutMilliseconds
  180488. : INFINITE);
  180489. if (waitResult != WAIT_OBJECT_0)
  180490. {
  180491. // if the operation timed out, let's cancel it...
  180492. CancelIo (intern->pipeH);
  180493. WaitForSingleObject (over.hEvent, INFINITE); // makes sure cancel is complete
  180494. }
  180495. if (GetOverlappedResult (intern->pipeH, &over, &numRead, FALSE))
  180496. {
  180497. bytesRead = (int) numRead;
  180498. }
  180499. else if (GetLastError() == ERROR_BROKEN_PIPE && intern->createdPipe)
  180500. {
  180501. intern->disconnect();
  180502. waitAgain = true;
  180503. }
  180504. }
  180505. else
  180506. {
  180507. waitAgain = internal != 0;
  180508. Sleep (5);
  180509. }
  180510. CloseHandle (over.hEvent);
  180511. }
  180512. return bytesRead;
  180513. }
  180514. int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
  180515. {
  180516. int bytesWritten = -1;
  180517. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  180518. if (intern != 0 && intern->connect (timeOutMilliseconds))
  180519. {
  180520. if (numBytesToWrite <= 0)
  180521. return 0;
  180522. OVERLAPPED over;
  180523. zerostruct (over);
  180524. over.hEvent = CreateEvent (0, TRUE, FALSE, 0);
  180525. unsigned long numWritten;
  180526. if (WriteFile (intern->pipeH, sourceBuffer, numBytesToWrite, &numWritten, &over))
  180527. {
  180528. bytesWritten = (int) numWritten;
  180529. }
  180530. else if (GetLastError() == ERROR_IO_PENDING)
  180531. {
  180532. HANDLE handles[] = { over.hEvent, intern->cancelEvent };
  180533. DWORD waitResult;
  180534. waitResult = WaitForMultipleObjects (2, handles, FALSE,
  180535. timeOutMilliseconds >= 0 ? timeOutMilliseconds
  180536. : INFINITE);
  180537. if (waitResult != WAIT_OBJECT_0)
  180538. {
  180539. CancelIo (intern->pipeH);
  180540. WaitForSingleObject (over.hEvent, INFINITE);
  180541. }
  180542. if (GetOverlappedResult (intern->pipeH, &over, &numWritten, FALSE))
  180543. {
  180544. bytesWritten = (int) numWritten;
  180545. }
  180546. else if (GetLastError() == ERROR_BROKEN_PIPE && intern->createdPipe)
  180547. {
  180548. intern->disconnect();
  180549. }
  180550. }
  180551. CloseHandle (over.hEvent);
  180552. }
  180553. return bytesWritten;
  180554. }
  180555. void NamedPipe::cancelPendingReads()
  180556. {
  180557. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  180558. if (intern != 0)
  180559. SetEvent (intern->cancelEvent);
  180560. }
  180561. #endif
  180562. /*** End of inlined file: juce_win32_Files.cpp ***/
  180563. /*** Start of inlined file: juce_win32_Network.cpp ***/
  180564. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  180565. // compiled on its own).
  180566. #if JUCE_INCLUDED_FILE
  180567. #ifndef INTERNET_FLAG_NEED_FILE
  180568. #define INTERNET_FLAG_NEED_FILE 0x00000010
  180569. #endif
  180570. #ifndef INTERNET_OPTION_DISABLE_AUTODIAL
  180571. #define INTERNET_OPTION_DISABLE_AUTODIAL 70
  180572. #endif
  180573. bool juce_isOnLine()
  180574. {
  180575. DWORD connectionType;
  180576. return InternetGetConnectedState (&connectionType, 0) != 0
  180577. || (connectionType & (INTERNET_CONNECTION_LAN | INTERNET_CONNECTION_PROXY)) != 0;
  180578. }
  180579. struct ConnectionAndRequestStruct
  180580. {
  180581. HINTERNET connection, request;
  180582. };
  180583. static HINTERNET sessionHandle = 0;
  180584. #ifndef WORKAROUND_TIMEOUT_BUG
  180585. //#define WORKAROUND_TIMEOUT_BUG 1
  180586. #endif
  180587. #if WORKAROUND_TIMEOUT_BUG
  180588. // Required because of a Microsoft bug in setting a timeout
  180589. class InternetConnectThread : public Thread
  180590. {
  180591. public:
  180592. InternetConnectThread (URL_COMPONENTS& uc_, HINTERNET& connection_, const bool isFtp_)
  180593. : Thread ("Internet"), uc (uc_), connection (connection_), isFtp (isFtp_)
  180594. {
  180595. startThread();
  180596. }
  180597. ~InternetConnectThread()
  180598. {
  180599. stopThread (60000);
  180600. }
  180601. void run()
  180602. {
  180603. connection = InternetConnect (sessionHandle, uc.lpszHostName,
  180604. uc.nPort, _T(""), _T(""),
  180605. isFtp ? INTERNET_SERVICE_FTP
  180606. : INTERNET_SERVICE_HTTP,
  180607. 0, 0);
  180608. notify();
  180609. }
  180610. juce_UseDebuggingNewOperator
  180611. private:
  180612. URL_COMPONENTS& uc;
  180613. HINTERNET& connection;
  180614. const bool isFtp;
  180615. InternetConnectThread (const InternetConnectThread&);
  180616. InternetConnectThread& operator= (const InternetConnectThread&);
  180617. };
  180618. #endif
  180619. void* juce_openInternetFile (const String& url,
  180620. const String& headers,
  180621. const MemoryBlock& postData,
  180622. const bool isPost,
  180623. URL::OpenStreamProgressCallback* callback,
  180624. void* callbackContext,
  180625. int timeOutMs)
  180626. {
  180627. if (sessionHandle == 0)
  180628. sessionHandle = InternetOpen (_T("juce"),
  180629. INTERNET_OPEN_TYPE_PRECONFIG,
  180630. 0, 0, 0);
  180631. if (sessionHandle != 0)
  180632. {
  180633. // break up the url..
  180634. TCHAR file[1024], server[1024];
  180635. URL_COMPONENTS uc;
  180636. zerostruct (uc);
  180637. uc.dwStructSize = sizeof (uc);
  180638. uc.dwUrlPathLength = sizeof (file);
  180639. uc.dwHostNameLength = sizeof (server);
  180640. uc.lpszUrlPath = file;
  180641. uc.lpszHostName = server;
  180642. if (InternetCrackUrl (url, 0, 0, &uc))
  180643. {
  180644. int disable = 1;
  180645. InternetSetOption (sessionHandle, INTERNET_OPTION_DISABLE_AUTODIAL, &disable, sizeof (disable));
  180646. if (timeOutMs == 0)
  180647. timeOutMs = 30000;
  180648. else if (timeOutMs < 0)
  180649. timeOutMs = -1;
  180650. InternetSetOption (sessionHandle, INTERNET_OPTION_CONNECT_TIMEOUT, &timeOutMs, sizeof (timeOutMs));
  180651. const bool isFtp = url.startsWithIgnoreCase (T("ftp:"));
  180652. #if WORKAROUND_TIMEOUT_BUG
  180653. HINTERNET connection = 0;
  180654. {
  180655. InternetConnectThread connectThread (uc, connection, isFtp);
  180656. connectThread.wait (timeOutMs);
  180657. if (connection == 0)
  180658. {
  180659. InternetCloseHandle (sessionHandle);
  180660. sessionHandle = 0;
  180661. }
  180662. }
  180663. #else
  180664. HINTERNET connection = InternetConnect (sessionHandle,
  180665. uc.lpszHostName,
  180666. uc.nPort,
  180667. _T(""), _T(""),
  180668. isFtp ? INTERNET_SERVICE_FTP
  180669. : INTERNET_SERVICE_HTTP,
  180670. 0, 0);
  180671. #endif
  180672. if (connection != 0)
  180673. {
  180674. if (isFtp)
  180675. {
  180676. HINTERNET request = FtpOpenFile (connection,
  180677. uc.lpszUrlPath,
  180678. GENERIC_READ,
  180679. FTP_TRANSFER_TYPE_BINARY | INTERNET_FLAG_NEED_FILE,
  180680. 0);
  180681. ConnectionAndRequestStruct* const result = new ConnectionAndRequestStruct();
  180682. result->connection = connection;
  180683. result->request = request;
  180684. return result;
  180685. }
  180686. else
  180687. {
  180688. const TCHAR* mimeTypes[] = { _T("*/*"), 0 };
  180689. DWORD flags = INTERNET_FLAG_RELOAD | INTERNET_FLAG_NO_CACHE_WRITE;
  180690. if (url.startsWithIgnoreCase (T("https:")))
  180691. flags |= INTERNET_FLAG_SECURE; // (this flag only seems necessary if the OS is running IE6 -
  180692. // IE7 seems to automatically work out when it's https)
  180693. HINTERNET request = HttpOpenRequest (connection,
  180694. isPost ? _T("POST")
  180695. : _T("GET"),
  180696. uc.lpszUrlPath,
  180697. 0, 0, mimeTypes, flags, 0);
  180698. if (request != 0)
  180699. {
  180700. INTERNET_BUFFERS buffers;
  180701. zerostruct (buffers);
  180702. buffers.dwStructSize = sizeof (INTERNET_BUFFERS);
  180703. buffers.lpcszHeader = (LPCTSTR) headers;
  180704. buffers.dwHeadersLength = headers.length();
  180705. buffers.dwBufferTotal = (DWORD) postData.getSize();
  180706. ConnectionAndRequestStruct* result = 0;
  180707. if (HttpSendRequestEx (request, &buffers, 0, HSR_INITIATE, 0))
  180708. {
  180709. int bytesSent = 0;
  180710. for (;;)
  180711. {
  180712. const int bytesToDo = jmin (1024, (int) postData.getSize() - bytesSent);
  180713. DWORD bytesDone = 0;
  180714. if (bytesToDo > 0
  180715. && ! InternetWriteFile (request,
  180716. ((const char*) postData.getData()) + bytesSent,
  180717. bytesToDo, &bytesDone))
  180718. {
  180719. break;
  180720. }
  180721. if (bytesToDo == 0 || (int) bytesDone < bytesToDo)
  180722. {
  180723. result = new ConnectionAndRequestStruct();
  180724. result->connection = connection;
  180725. result->request = request;
  180726. HttpEndRequest (request, 0, 0, 0);
  180727. return result;
  180728. }
  180729. bytesSent += bytesDone;
  180730. if (callback != 0 && ! callback (callbackContext, bytesSent, postData.getSize()))
  180731. break;
  180732. }
  180733. }
  180734. InternetCloseHandle (request);
  180735. }
  180736. InternetCloseHandle (connection);
  180737. }
  180738. }
  180739. }
  180740. }
  180741. return 0;
  180742. }
  180743. int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead)
  180744. {
  180745. DWORD bytesRead = 0;
  180746. const ConnectionAndRequestStruct* const crs = (const ConnectionAndRequestStruct*) handle;
  180747. if (crs != 0)
  180748. InternetReadFile (crs->request,
  180749. buffer, bytesToRead,
  180750. &bytesRead);
  180751. return bytesRead;
  180752. }
  180753. int juce_seekInInternetFile (void* handle, int newPosition)
  180754. {
  180755. if (handle != 0)
  180756. {
  180757. const ConnectionAndRequestStruct* const crs = (const ConnectionAndRequestStruct*) handle;
  180758. return InternetSetFilePointer (crs->request,
  180759. newPosition, 0,
  180760. FILE_BEGIN, 0);
  180761. }
  180762. else
  180763. {
  180764. return -1;
  180765. }
  180766. }
  180767. int64 juce_getInternetFileContentLength (void* handle)
  180768. {
  180769. const ConnectionAndRequestStruct* const crs = (const ConnectionAndRequestStruct*) handle;
  180770. if (crs != 0)
  180771. {
  180772. DWORD index = 0;
  180773. DWORD result = 0;
  180774. DWORD size = sizeof (result);
  180775. if (HttpQueryInfo (crs->request,
  180776. HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER,
  180777. &result,
  180778. &size,
  180779. &index))
  180780. {
  180781. return (int64) result;
  180782. }
  180783. }
  180784. return -1;
  180785. }
  180786. void juce_closeInternetFile (void* handle)
  180787. {
  180788. if (handle != 0)
  180789. {
  180790. ConnectionAndRequestStruct* const crs = (ConnectionAndRequestStruct*) handle;
  180791. InternetCloseHandle (crs->request);
  180792. InternetCloseHandle (crs->connection);
  180793. delete crs;
  180794. }
  180795. }
  180796. static int getMACAddressViaGetAdaptersInfo (int64* addresses, int maxNum, const bool littleEndian) throw()
  180797. {
  180798. int numFound = 0;
  180799. DynamicLibraryLoader dll ("iphlpapi.dll");
  180800. DynamicLibraryImport (GetAdaptersInfo, getAdaptersInfo, DWORD, dll, (PIP_ADAPTER_INFO, PULONG))
  180801. if (getAdaptersInfo != 0)
  180802. {
  180803. ULONG len = sizeof (IP_ADAPTER_INFO);
  180804. MemoryBlock mb;
  180805. PIP_ADAPTER_INFO adapterInfo = (PIP_ADAPTER_INFO) mb.getData();
  180806. if (getAdaptersInfo (adapterInfo, &len) == ERROR_BUFFER_OVERFLOW)
  180807. {
  180808. mb.setSize (len);
  180809. adapterInfo = (PIP_ADAPTER_INFO) mb.getData();
  180810. }
  180811. if (getAdaptersInfo (adapterInfo, &len) == NO_ERROR)
  180812. {
  180813. PIP_ADAPTER_INFO adapter = adapterInfo;
  180814. while (adapter != 0)
  180815. {
  180816. int64 mac = 0;
  180817. for (unsigned int i = 0; i < adapter->AddressLength; ++i)
  180818. mac = (mac << 8) | adapter->Address[i];
  180819. if (littleEndian)
  180820. mac = (int64) ByteOrder::swap ((uint64) mac);
  180821. if (numFound < maxNum && mac != 0)
  180822. addresses [numFound++] = mac;
  180823. adapter = adapter->Next;
  180824. }
  180825. }
  180826. }
  180827. return numFound;
  180828. }
  180829. struct ASTAT
  180830. {
  180831. ADAPTER_STATUS adapt;
  180832. NAME_BUFFER NameBuff [30];
  180833. };
  180834. static int getMACAddressesViaNetBios (int64* addresses, int maxNum, const bool littleEndian) throw()
  180835. {
  180836. int numFound = 0;
  180837. DynamicLibraryLoader dll ("netapi32.dll");
  180838. DynamicLibraryImport (Netbios, NetbiosCall, UCHAR, dll, (PNCB))
  180839. if (NetbiosCall != 0)
  180840. {
  180841. NCB ncb;
  180842. zerostruct (ncb);
  180843. ASTAT astat;
  180844. zerostruct (astat);
  180845. LANA_ENUM enums;
  180846. zerostruct (enums);
  180847. ncb.ncb_command = NCBENUM;
  180848. ncb.ncb_buffer = (unsigned char*) &enums;
  180849. ncb.ncb_length = sizeof (LANA_ENUM);
  180850. NetbiosCall (&ncb);
  180851. for (int i = 0; i < enums.length; ++i)
  180852. {
  180853. zerostruct (ncb);
  180854. ncb.ncb_command = NCBRESET;
  180855. ncb.ncb_lana_num = enums.lana[i];
  180856. if (NetbiosCall (&ncb) == 0)
  180857. {
  180858. zerostruct (ncb);
  180859. memcpy (ncb.ncb_callname, "* ", NCBNAMSZ);
  180860. ncb.ncb_command = NCBASTAT;
  180861. ncb.ncb_lana_num = enums.lana[i];
  180862. ncb.ncb_buffer = (unsigned char*) &astat;
  180863. ncb.ncb_length = sizeof (ASTAT);
  180864. if (NetbiosCall (&ncb) == 0)
  180865. {
  180866. if (astat.adapt.adapter_type == 0xfe)
  180867. {
  180868. uint64 mac = 0;
  180869. for (int i = 6; --i >= 0;)
  180870. mac = (mac << 8) | astat.adapt.adapter_address [littleEndian ? i : (5 - i)];
  180871. if (numFound < maxNum && mac != 0)
  180872. addresses [numFound++] = mac;
  180873. }
  180874. }
  180875. }
  180876. }
  180877. }
  180878. return numFound;
  180879. }
  180880. int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian)
  180881. {
  180882. int numFound = getMACAddressViaGetAdaptersInfo (addresses, maxNum, littleEndian);
  180883. if (numFound == 0)
  180884. numFound = getMACAddressesViaNetBios (addresses, maxNum, littleEndian);
  180885. return numFound;
  180886. }
  180887. typedef ULONG (WINAPI *MAPISendMailType) (LHANDLE, ULONG, lpMapiMessage, ::FLAGS, ULONG);
  180888. bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
  180889. const String& emailSubject,
  180890. const String& bodyText,
  180891. const StringArray& filesToAttach)
  180892. {
  180893. HMODULE h = LoadLibraryA ("MAPI32.dll");
  180894. MAPISendMailType mapiSendMail = (MAPISendMailType) GetProcAddress (h, "MAPISendMail");
  180895. bool ok = false;
  180896. if (mapiSendMail != 0)
  180897. {
  180898. MapiMessage message;
  180899. zerostruct (message);
  180900. message.lpszSubject = (LPSTR) emailSubject.toCString();
  180901. message.lpszNoteText = (LPSTR) bodyText.toCString();
  180902. MapiRecipDesc recip;
  180903. zerostruct (recip);
  180904. recip.ulRecipClass = MAPI_TO;
  180905. String targetEmailAddress_ (targetEmailAddress);
  180906. if (targetEmailAddress_.isEmpty())
  180907. targetEmailAddress_ = " "; // (Windows Mail can't deal with a blank address)
  180908. recip.lpszName = (LPSTR) targetEmailAddress_.toCString();
  180909. message.nRecipCount = 1;
  180910. message.lpRecips = &recip;
  180911. MemoryBlock mb (sizeof (MapiFileDesc) * filesToAttach.size());
  180912. mb.fillWith (0);
  180913. MapiFileDesc* files = (MapiFileDesc*) mb.getData();
  180914. message.nFileCount = filesToAttach.size();
  180915. message.lpFiles = files;
  180916. for (int i = 0; i < filesToAttach.size(); ++i)
  180917. {
  180918. files[i].nPosition = (ULONG) -1;
  180919. files[i].lpszPathName = (LPSTR) filesToAttach[i].toCString();
  180920. }
  180921. ok = (mapiSendMail (0, 0, &message, MAPI_DIALOG | MAPI_LOGON_UI, 0) == SUCCESS_SUCCESS);
  180922. }
  180923. FreeLibrary (h);
  180924. return ok;
  180925. }
  180926. #endif
  180927. /*** End of inlined file: juce_win32_Network.cpp ***/
  180928. /*** Start of inlined file: juce_win32_PlatformUtils.cpp ***/
  180929. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  180930. // compiled on its own).
  180931. #if JUCE_INCLUDED_FILE
  180932. static HKEY findKeyForPath (String name,
  180933. const bool createForWriting,
  180934. String& valueName)
  180935. {
  180936. HKEY rootKey = 0;
  180937. if (name.startsWithIgnoreCase (T("HKEY_CURRENT_USER\\")))
  180938. rootKey = HKEY_CURRENT_USER;
  180939. else if (name.startsWithIgnoreCase (T("HKEY_LOCAL_MACHINE\\")))
  180940. rootKey = HKEY_LOCAL_MACHINE;
  180941. else if (name.startsWithIgnoreCase (T("HKEY_CLASSES_ROOT\\")))
  180942. rootKey = HKEY_CLASSES_ROOT;
  180943. if (rootKey != 0)
  180944. {
  180945. name = name.substring (name.indexOfChar (T('\\')) + 1);
  180946. const int lastSlash = name.lastIndexOfChar (T('\\'));
  180947. valueName = name.substring (lastSlash + 1);
  180948. name = name.substring (0, lastSlash);
  180949. HKEY key;
  180950. DWORD result;
  180951. if (createForWriting)
  180952. {
  180953. if (RegCreateKeyEx (rootKey, name, 0, 0, REG_OPTION_NON_VOLATILE,
  180954. (KEY_WRITE | KEY_QUERY_VALUE), 0, &key, &result) == ERROR_SUCCESS)
  180955. return key;
  180956. }
  180957. else
  180958. {
  180959. if (RegOpenKeyEx (rootKey, name, 0, KEY_READ, &key) == ERROR_SUCCESS)
  180960. return key;
  180961. }
  180962. }
  180963. return 0;
  180964. }
  180965. const String PlatformUtilities::getRegistryValue (const String& regValuePath,
  180966. const String& defaultValue)
  180967. {
  180968. String valueName, result (defaultValue);
  180969. HKEY k = findKeyForPath (regValuePath, false, valueName);
  180970. if (k != 0)
  180971. {
  180972. WCHAR buffer [2048];
  180973. unsigned long bufferSize = sizeof (buffer);
  180974. DWORD type = REG_SZ;
  180975. if (RegQueryValueEx (k, valueName, 0, &type, (LPBYTE) buffer, &bufferSize) == ERROR_SUCCESS)
  180976. {
  180977. if (type == REG_SZ)
  180978. result = buffer;
  180979. else if (type == REG_DWORD)
  180980. result = String ((int) *(DWORD*) buffer);
  180981. }
  180982. RegCloseKey (k);
  180983. }
  180984. return result;
  180985. }
  180986. void PlatformUtilities::setRegistryValue (const String& regValuePath,
  180987. const String& value)
  180988. {
  180989. String valueName;
  180990. HKEY k = findKeyForPath (regValuePath, true, valueName);
  180991. if (k != 0)
  180992. {
  180993. RegSetValueEx (k, valueName, 0, REG_SZ,
  180994. (const BYTE*) (const WCHAR*) value,
  180995. sizeof (WCHAR) * (value.length() + 1));
  180996. RegCloseKey (k);
  180997. }
  180998. }
  180999. bool PlatformUtilities::registryValueExists (const String& regValuePath)
  181000. {
  181001. bool exists = false;
  181002. String valueName;
  181003. HKEY k = findKeyForPath (regValuePath, false, valueName);
  181004. if (k != 0)
  181005. {
  181006. unsigned char buffer [2048];
  181007. unsigned long bufferSize = sizeof (buffer);
  181008. DWORD type = 0;
  181009. if (RegQueryValueEx (k, valueName, 0, &type, buffer, &bufferSize) == ERROR_SUCCESS)
  181010. exists = true;
  181011. RegCloseKey (k);
  181012. }
  181013. return exists;
  181014. }
  181015. void PlatformUtilities::deleteRegistryValue (const String& regValuePath)
  181016. {
  181017. String valueName;
  181018. HKEY k = findKeyForPath (regValuePath, true, valueName);
  181019. if (k != 0)
  181020. {
  181021. RegDeleteValue (k, valueName);
  181022. RegCloseKey (k);
  181023. }
  181024. }
  181025. void PlatformUtilities::deleteRegistryKey (const String& regKeyPath)
  181026. {
  181027. String valueName;
  181028. HKEY k = findKeyForPath (regKeyPath, true, valueName);
  181029. if (k != 0)
  181030. {
  181031. RegDeleteKey (k, valueName);
  181032. RegCloseKey (k);
  181033. }
  181034. }
  181035. void PlatformUtilities::registerFileAssociation (const String& fileExtension,
  181036. const String& symbolicDescription,
  181037. const String& fullDescription,
  181038. const File& targetExecutable,
  181039. int iconResourceNumber)
  181040. {
  181041. setRegistryValue ("HKEY_CLASSES_ROOT\\" + fileExtension + "\\", symbolicDescription);
  181042. const String key ("HKEY_CLASSES_ROOT\\" + symbolicDescription);
  181043. if (iconResourceNumber != 0)
  181044. setRegistryValue (key + "\\DefaultIcon\\",
  181045. targetExecutable.getFullPathName() + "," + String (-iconResourceNumber));
  181046. setRegistryValue (key + "\\", fullDescription);
  181047. setRegistryValue (key + "\\shell\\open\\command\\",
  181048. targetExecutable.getFullPathName() + " %1");
  181049. }
  181050. bool juce_IsRunningInWine()
  181051. {
  181052. HKEY key;
  181053. if (RegOpenKeyEx (HKEY_CURRENT_USER, _T("Software\\Wine"), 0, KEY_READ, &key) == ERROR_SUCCESS)
  181054. {
  181055. RegCloseKey (key);
  181056. return true;
  181057. }
  181058. return false;
  181059. }
  181060. const String JUCE_CALLTYPE PlatformUtilities::getCurrentCommandLineParams() throw()
  181061. {
  181062. String s (::GetCommandLineW());
  181063. StringArray tokens;
  181064. tokens.addTokens (s, true); // tokenise so that we can remove the initial filename argument
  181065. return tokens.joinIntoString (T(" "), 1);
  181066. }
  181067. static void* currentModuleHandle = 0;
  181068. void* PlatformUtilities::getCurrentModuleInstanceHandle() throw()
  181069. {
  181070. if (currentModuleHandle == 0)
  181071. currentModuleHandle = GetModuleHandle (0);
  181072. return currentModuleHandle;
  181073. }
  181074. void PlatformUtilities::setCurrentModuleInstanceHandle (void* const newHandle) throw()
  181075. {
  181076. currentModuleHandle = newHandle;
  181077. }
  181078. void PlatformUtilities::fpuReset()
  181079. {
  181080. #if JUCE_MSVC
  181081. _clearfp();
  181082. #endif
  181083. }
  181084. void PlatformUtilities::beep()
  181085. {
  181086. MessageBeep (MB_OK);
  181087. }
  181088. #endif
  181089. /*** End of inlined file: juce_win32_PlatformUtils.cpp ***/
  181090. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  181091. /*** Start of inlined file: juce_win32_Messaging.cpp ***/
  181092. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  181093. // compiled on its own).
  181094. #if JUCE_INCLUDED_FILE
  181095. static const unsigned int specialId = WM_APP + 0x4400;
  181096. static const unsigned int broadcastId = WM_APP + 0x4403;
  181097. static const unsigned int specialCallbackId = WM_APP + 0x4402;
  181098. static const TCHAR* const messageWindowName = _T("JUCEWindow");
  181099. HWND juce_messageWindowHandle = 0;
  181100. extern long improbableWindowNumber; // defined in windowing.cpp
  181101. #ifndef WM_APPCOMMAND
  181102. #define WM_APPCOMMAND 0x0319
  181103. #endif
  181104. static LRESULT CALLBACK juce_MessageWndProc (HWND h,
  181105. const UINT message,
  181106. const WPARAM wParam,
  181107. const LPARAM lParam) throw()
  181108. {
  181109. JUCE_TRY
  181110. {
  181111. if (h == juce_messageWindowHandle)
  181112. {
  181113. if (message == specialCallbackId)
  181114. {
  181115. MessageCallbackFunction* const func = (MessageCallbackFunction*) wParam;
  181116. return (LRESULT) (*func) ((void*) lParam);
  181117. }
  181118. else if (message == specialId)
  181119. {
  181120. // these are trapped early in the dispatch call, but must also be checked
  181121. // here in case there are windows modal dialog boxes doing their own
  181122. // dispatch loop and not calling our version
  181123. MessageManager::getInstance()->deliverMessage ((void*) lParam);
  181124. return 0;
  181125. }
  181126. else if (message == broadcastId)
  181127. {
  181128. const ScopedPointer <String> messageString ((String*) lParam);
  181129. MessageManager::getInstance()->deliverBroadcastMessage (*messageString);
  181130. return 0;
  181131. }
  181132. else if (message == WM_COPYDATA && ((const COPYDATASTRUCT*) lParam)->dwData == broadcastId)
  181133. {
  181134. const String messageString ((const juce_wchar*) ((const COPYDATASTRUCT*) lParam)->lpData,
  181135. ((const COPYDATASTRUCT*) lParam)->cbData / sizeof (juce_wchar));
  181136. PostMessage (juce_messageWindowHandle, broadcastId, 0, (LPARAM) new String (messageString));
  181137. return 0;
  181138. }
  181139. }
  181140. }
  181141. JUCE_CATCH_EXCEPTION
  181142. return DefWindowProc (h, message, wParam, lParam);
  181143. }
  181144. static bool isEventBlockedByModalComps (MSG& m)
  181145. {
  181146. if (Component::getNumCurrentlyModalComponents() == 0
  181147. || GetWindowLong (m.hwnd, GWLP_USERDATA) == improbableWindowNumber)
  181148. return false;
  181149. switch (m.message)
  181150. {
  181151. case WM_MOUSEMOVE:
  181152. case WM_NCMOUSEMOVE:
  181153. case 0x020A: /* WM_MOUSEWHEEL */
  181154. case 0x020E: /* WM_MOUSEHWHEEL */
  181155. case WM_KEYUP:
  181156. case WM_SYSKEYUP:
  181157. case WM_CHAR:
  181158. case WM_APPCOMMAND:
  181159. case WM_LBUTTONUP:
  181160. case WM_MBUTTONUP:
  181161. case WM_RBUTTONUP:
  181162. case WM_MOUSEACTIVATE:
  181163. case WM_NCMOUSEHOVER:
  181164. case WM_MOUSEHOVER:
  181165. return true;
  181166. case WM_NCLBUTTONDOWN:
  181167. case WM_NCLBUTTONDBLCLK:
  181168. case WM_NCRBUTTONDOWN:
  181169. case WM_NCRBUTTONDBLCLK:
  181170. case WM_NCMBUTTONDOWN:
  181171. case WM_NCMBUTTONDBLCLK:
  181172. case WM_LBUTTONDOWN:
  181173. case WM_LBUTTONDBLCLK:
  181174. case WM_MBUTTONDOWN:
  181175. case WM_MBUTTONDBLCLK:
  181176. case WM_RBUTTONDOWN:
  181177. case WM_RBUTTONDBLCLK:
  181178. case WM_KEYDOWN:
  181179. case WM_SYSKEYDOWN:
  181180. {
  181181. Component* const modal = Component::getCurrentlyModalComponent (0);
  181182. if (modal != 0)
  181183. modal->inputAttemptWhenModal();
  181184. return true;
  181185. }
  181186. default:
  181187. break;
  181188. }
  181189. return false;
  181190. }
  181191. bool juce_dispatchNextMessageOnSystemQueue (const bool returnIfNoPendingMessages)
  181192. {
  181193. MSG m;
  181194. if (returnIfNoPendingMessages && ! PeekMessage (&m, (HWND) 0, 0, 0, 0))
  181195. return false;
  181196. if (GetMessage (&m, (HWND) 0, 0, 0) >= 0)
  181197. {
  181198. if (m.message == specialId && m.hwnd == juce_messageWindowHandle)
  181199. {
  181200. MessageManager::getInstance()->deliverMessage ((void*) m.lParam);
  181201. }
  181202. else if (m.message == WM_QUIT)
  181203. {
  181204. if (JUCEApplication::getInstance())
  181205. JUCEApplication::getInstance()->systemRequestedQuit();
  181206. }
  181207. else if (! isEventBlockedByModalComps (m))
  181208. {
  181209. if ((m.message == WM_LBUTTONDOWN || m.message == WM_RBUTTONDOWN)
  181210. && GetWindowLong (m.hwnd, GWLP_USERDATA) != improbableWindowNumber)
  181211. {
  181212. // if it's someone else's window being clicked on, and the focus is
  181213. // currently on a juce window, pass the kb focus over..
  181214. HWND currentFocus = GetFocus();
  181215. if (currentFocus == 0 || GetWindowLong (currentFocus, GWLP_USERDATA) == improbableWindowNumber)
  181216. SetFocus (m.hwnd);
  181217. }
  181218. TranslateMessage (&m);
  181219. DispatchMessage (&m);
  181220. }
  181221. }
  181222. return true;
  181223. }
  181224. bool juce_postMessageToSystemQueue (void* message)
  181225. {
  181226. return PostMessage (juce_messageWindowHandle, specialId, 0, (LPARAM) message) != 0;
  181227. }
  181228. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
  181229. void* userData)
  181230. {
  181231. if (MessageManager::getInstance()->isThisTheMessageThread())
  181232. {
  181233. return (*callback) (userData);
  181234. }
  181235. else
  181236. {
  181237. // If a thread has a MessageManagerLock and then tries to call this method, it'll
  181238. // deadlock because the message manager is blocked from running, and can't
  181239. // call your function..
  181240. jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  181241. return (void*) SendMessage (juce_messageWindowHandle,
  181242. specialCallbackId,
  181243. (WPARAM) callback,
  181244. (LPARAM) userData);
  181245. }
  181246. }
  181247. static BOOL CALLBACK BroadcastEnumWindowProc (HWND hwnd, LPARAM lParam)
  181248. {
  181249. if (hwnd != juce_messageWindowHandle)
  181250. (reinterpret_cast <VoidArray*> (lParam))->add ((void*) hwnd);
  181251. return TRUE;
  181252. }
  181253. void MessageManager::broadcastMessage (const String& value) throw()
  181254. {
  181255. VoidArray windows;
  181256. EnumWindows (&BroadcastEnumWindowProc, (LPARAM) &windows);
  181257. const String localCopy (value);
  181258. COPYDATASTRUCT data;
  181259. data.dwData = broadcastId;
  181260. data.cbData = (localCopy.length() + 1) * sizeof (juce_wchar);
  181261. data.lpData = (void*) (const juce_wchar*) localCopy;
  181262. for (int i = windows.size(); --i >= 0;)
  181263. {
  181264. HWND hwnd = (HWND) windows.getUnchecked(i);
  181265. TCHAR windowName [64]; // no need to read longer strings than this
  181266. GetWindowText (hwnd, windowName, 64);
  181267. windowName [63] = 0;
  181268. if (String (windowName) == String (messageWindowName))
  181269. {
  181270. DWORD_PTR result;
  181271. SendMessageTimeout (hwnd, WM_COPYDATA,
  181272. (WPARAM) juce_messageWindowHandle,
  181273. (LPARAM) &data,
  181274. SMTO_BLOCK | SMTO_ABORTIFHUNG,
  181275. 8000,
  181276. &result);
  181277. }
  181278. }
  181279. }
  181280. static const String getMessageWindowClassName()
  181281. {
  181282. // this name has to be different for each app/dll instance because otherwise
  181283. // poor old Win32 can get a bit confused (even despite it not being a process-global
  181284. // window class).
  181285. static int number = 0;
  181286. if (number == 0)
  181287. number = 0x7fffffff & (int) Time::getHighResolutionTicks();
  181288. return T("JUCEcs_") + String (number);
  181289. }
  181290. void MessageManager::doPlatformSpecificInitialisation()
  181291. {
  181292. OleInitialize (0);
  181293. const String className (getMessageWindowClassName());
  181294. HMODULE hmod = (HMODULE) PlatformUtilities::getCurrentModuleInstanceHandle();
  181295. WNDCLASSEX wc;
  181296. zerostruct (wc);
  181297. wc.cbSize = sizeof (wc);
  181298. wc.lpfnWndProc = (WNDPROC) juce_MessageWndProc;
  181299. wc.cbWndExtra = 4;
  181300. wc.hInstance = hmod;
  181301. wc.lpszClassName = className;
  181302. RegisterClassEx (&wc);
  181303. juce_messageWindowHandle = CreateWindow (wc.lpszClassName,
  181304. messageWindowName,
  181305. 0, 0, 0, 0, 0, 0, 0,
  181306. hmod, 0);
  181307. }
  181308. void MessageManager::doPlatformSpecificShutdown()
  181309. {
  181310. DestroyWindow (juce_messageWindowHandle);
  181311. UnregisterClass (getMessageWindowClassName(), 0);
  181312. OleUninitialize();
  181313. }
  181314. #endif
  181315. /*** End of inlined file: juce_win32_Messaging.cpp ***/
  181316. /*** Start of inlined file: juce_win32_Windowing.cpp ***/
  181317. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  181318. // compiled on its own).
  181319. #if JUCE_INCLUDED_FILE
  181320. #undef GetSystemMetrics // multimon overrides this for some reason and causes a mess..
  181321. // these are in the windows SDK, but need to be repeated here for GCC..
  181322. #ifndef GET_APPCOMMAND_LPARAM
  181323. #define FAPPCOMMAND_MASK 0xF000
  181324. #define GET_APPCOMMAND_LPARAM(lParam) ((short) (HIWORD (lParam) & ~FAPPCOMMAND_MASK))
  181325. #define APPCOMMAND_MEDIA_NEXTTRACK 11
  181326. #define APPCOMMAND_MEDIA_PREVIOUSTRACK 12
  181327. #define APPCOMMAND_MEDIA_STOP 13
  181328. #define APPCOMMAND_MEDIA_PLAY_PAUSE 14
  181329. #define WM_APPCOMMAND 0x0319
  181330. #endif
  181331. extern void juce_repeatLastProcessPriority(); // in juce_win32_Threads.cpp
  181332. extern void juce_CheckCurrentlyFocusedTopLevelWindow(); // in juce_TopLevelWindow.cpp
  181333. extern bool juce_IsRunningInWine();
  181334. #ifndef ULW_ALPHA
  181335. #define ULW_ALPHA 0x00000002
  181336. #endif
  181337. #ifndef AC_SRC_ALPHA
  181338. #define AC_SRC_ALPHA 0x01
  181339. #endif
  181340. static HPALETTE palette = 0;
  181341. static bool createPaletteIfNeeded = true;
  181342. static bool shouldDeactivateTitleBar = true;
  181343. static HICON createHICONFromImage (const Image& image, const BOOL isIcon, int hotspotX, int hotspotY) throw();
  181344. #define WM_TRAYNOTIFY WM_USER + 100
  181345. using ::abs;
  181346. typedef BOOL (WINAPI* UpdateLayeredWinFunc) (HWND, HDC, POINT*, SIZE*, HDC, POINT*, COLORREF, BLENDFUNCTION*, DWORD);
  181347. static UpdateLayeredWinFunc updateLayeredWindow = 0;
  181348. bool Desktop::canUseSemiTransparentWindows() throw()
  181349. {
  181350. if (updateLayeredWindow == 0)
  181351. {
  181352. if (! juce_IsRunningInWine())
  181353. {
  181354. HMODULE user32Mod = GetModuleHandle (_T("user32.dll"));
  181355. updateLayeredWindow = (UpdateLayeredWinFunc) GetProcAddress (user32Mod, "UpdateLayeredWindow");
  181356. }
  181357. }
  181358. return updateLayeredWindow != 0;
  181359. }
  181360. const int extendedKeyModifier = 0x10000;
  181361. const int KeyPress::spaceKey = VK_SPACE;
  181362. const int KeyPress::returnKey = VK_RETURN;
  181363. const int KeyPress::escapeKey = VK_ESCAPE;
  181364. const int KeyPress::backspaceKey = VK_BACK;
  181365. const int KeyPress::deleteKey = VK_DELETE | extendedKeyModifier;
  181366. const int KeyPress::insertKey = VK_INSERT | extendedKeyModifier;
  181367. const int KeyPress::tabKey = VK_TAB;
  181368. const int KeyPress::leftKey = VK_LEFT | extendedKeyModifier;
  181369. const int KeyPress::rightKey = VK_RIGHT | extendedKeyModifier;
  181370. const int KeyPress::upKey = VK_UP | extendedKeyModifier;
  181371. const int KeyPress::downKey = VK_DOWN | extendedKeyModifier;
  181372. const int KeyPress::homeKey = VK_HOME | extendedKeyModifier;
  181373. const int KeyPress::endKey = VK_END | extendedKeyModifier;
  181374. const int KeyPress::pageUpKey = VK_PRIOR | extendedKeyModifier;
  181375. const int KeyPress::pageDownKey = VK_NEXT | extendedKeyModifier;
  181376. const int KeyPress::F1Key = VK_F1 | extendedKeyModifier;
  181377. const int KeyPress::F2Key = VK_F2 | extendedKeyModifier;
  181378. const int KeyPress::F3Key = VK_F3 | extendedKeyModifier;
  181379. const int KeyPress::F4Key = VK_F4 | extendedKeyModifier;
  181380. const int KeyPress::F5Key = VK_F5 | extendedKeyModifier;
  181381. const int KeyPress::F6Key = VK_F6 | extendedKeyModifier;
  181382. const int KeyPress::F7Key = VK_F7 | extendedKeyModifier;
  181383. const int KeyPress::F8Key = VK_F8 | extendedKeyModifier;
  181384. const int KeyPress::F9Key = VK_F9 | extendedKeyModifier;
  181385. const int KeyPress::F10Key = VK_F10 | extendedKeyModifier;
  181386. const int KeyPress::F11Key = VK_F11 | extendedKeyModifier;
  181387. const int KeyPress::F12Key = VK_F12 | extendedKeyModifier;
  181388. const int KeyPress::F13Key = VK_F13 | extendedKeyModifier;
  181389. const int KeyPress::F14Key = VK_F14 | extendedKeyModifier;
  181390. const int KeyPress::F15Key = VK_F15 | extendedKeyModifier;
  181391. const int KeyPress::F16Key = VK_F16 | extendedKeyModifier;
  181392. const int KeyPress::numberPad0 = VK_NUMPAD0 | extendedKeyModifier;
  181393. const int KeyPress::numberPad1 = VK_NUMPAD1 | extendedKeyModifier;
  181394. const int KeyPress::numberPad2 = VK_NUMPAD2 | extendedKeyModifier;
  181395. const int KeyPress::numberPad3 = VK_NUMPAD3 | extendedKeyModifier;
  181396. const int KeyPress::numberPad4 = VK_NUMPAD4 | extendedKeyModifier;
  181397. const int KeyPress::numberPad5 = VK_NUMPAD5 | extendedKeyModifier;
  181398. const int KeyPress::numberPad6 = VK_NUMPAD6 | extendedKeyModifier;
  181399. const int KeyPress::numberPad7 = VK_NUMPAD7 | extendedKeyModifier;
  181400. const int KeyPress::numberPad8 = VK_NUMPAD8 | extendedKeyModifier;
  181401. const int KeyPress::numberPad9 = VK_NUMPAD9 | extendedKeyModifier;
  181402. const int KeyPress::numberPadAdd = VK_ADD | extendedKeyModifier;
  181403. const int KeyPress::numberPadSubtract = VK_SUBTRACT | extendedKeyModifier;
  181404. const int KeyPress::numberPadMultiply = VK_MULTIPLY | extendedKeyModifier;
  181405. const int KeyPress::numberPadDivide = VK_DIVIDE | extendedKeyModifier;
  181406. const int KeyPress::numberPadSeparator = VK_SEPARATOR | extendedKeyModifier;
  181407. const int KeyPress::numberPadDecimalPoint = VK_DECIMAL | extendedKeyModifier;
  181408. const int KeyPress::numberPadEquals = 0x92 /*VK_OEM_NEC_EQUAL*/ | extendedKeyModifier;
  181409. const int KeyPress::numberPadDelete = VK_DELETE | extendedKeyModifier;
  181410. const int KeyPress::playKey = 0x30000;
  181411. const int KeyPress::stopKey = 0x30001;
  181412. const int KeyPress::fastForwardKey = 0x30002;
  181413. const int KeyPress::rewindKey = 0x30003;
  181414. class WindowsBitmapImage : public Image
  181415. {
  181416. public:
  181417. HBITMAP hBitmap;
  181418. BITMAPV4HEADER bitmapInfo;
  181419. HDC hdc;
  181420. unsigned char* bitmapData;
  181421. WindowsBitmapImage (const PixelFormat format_,
  181422. const int w, const int h, const bool clearImage)
  181423. : Image (format_, w, h)
  181424. {
  181425. jassert (format_ == RGB || format_ == ARGB);
  181426. pixelStride = (format_ == RGB) ? 3 : 4;
  181427. zerostruct (bitmapInfo);
  181428. bitmapInfo.bV4Size = sizeof (BITMAPV4HEADER);
  181429. bitmapInfo.bV4Width = w;
  181430. bitmapInfo.bV4Height = h;
  181431. bitmapInfo.bV4Planes = 1;
  181432. bitmapInfo.bV4CSType = 1;
  181433. bitmapInfo.bV4BitCount = (unsigned short) (pixelStride * 8);
  181434. if (format_ == ARGB)
  181435. {
  181436. bitmapInfo.bV4AlphaMask = 0xff000000;
  181437. bitmapInfo.bV4RedMask = 0xff0000;
  181438. bitmapInfo.bV4GreenMask = 0xff00;
  181439. bitmapInfo.bV4BlueMask = 0xff;
  181440. bitmapInfo.bV4V4Compression = BI_BITFIELDS;
  181441. }
  181442. else
  181443. {
  181444. bitmapInfo.bV4V4Compression = BI_RGB;
  181445. }
  181446. lineStride = -((w * pixelStride + 3) & ~3);
  181447. HDC dc = GetDC (0);
  181448. hdc = CreateCompatibleDC (dc);
  181449. ReleaseDC (0, dc);
  181450. SetMapMode (hdc, MM_TEXT);
  181451. hBitmap = CreateDIBSection (hdc,
  181452. (BITMAPINFO*) &(bitmapInfo),
  181453. DIB_RGB_COLORS,
  181454. (void**) &bitmapData,
  181455. 0, 0);
  181456. SelectObject (hdc, hBitmap);
  181457. if (format_ == ARGB && clearImage)
  181458. zeromem (bitmapData, abs (h * lineStride));
  181459. imageData = bitmapData - (lineStride * (h - 1));
  181460. }
  181461. ~WindowsBitmapImage()
  181462. {
  181463. DeleteDC (hdc);
  181464. DeleteObject (hBitmap);
  181465. }
  181466. void blitToWindow (HWND hwnd, HDC dc, const bool transparent,
  181467. const int x, const int y,
  181468. const RectangleList& maskedRegion) throw()
  181469. {
  181470. static HDRAWDIB hdd = 0;
  181471. static bool needToCreateDrawDib = true;
  181472. if (needToCreateDrawDib)
  181473. {
  181474. needToCreateDrawDib = false;
  181475. HDC dc = GetDC (0);
  181476. const int n = GetDeviceCaps (dc, BITSPIXEL);
  181477. ReleaseDC (0, dc);
  181478. // only open if we're not palettised
  181479. if (n > 8)
  181480. hdd = DrawDibOpen();
  181481. }
  181482. if (createPaletteIfNeeded)
  181483. {
  181484. HDC dc = GetDC (0);
  181485. const int n = GetDeviceCaps (dc, BITSPIXEL);
  181486. ReleaseDC (0, dc);
  181487. if (n <= 8)
  181488. palette = CreateHalftonePalette (dc);
  181489. createPaletteIfNeeded = false;
  181490. }
  181491. if (palette != 0)
  181492. {
  181493. SelectPalette (dc, palette, FALSE);
  181494. RealizePalette (dc);
  181495. SetStretchBltMode (dc, HALFTONE);
  181496. }
  181497. SetMapMode (dc, MM_TEXT);
  181498. if (transparent)
  181499. {
  181500. POINT p, pos;
  181501. SIZE size;
  181502. RECT windowBounds;
  181503. GetWindowRect (hwnd, &windowBounds);
  181504. p.x = -x;
  181505. p.y = -y;
  181506. pos.x = windowBounds.left;
  181507. pos.y = windowBounds.top;
  181508. size.cx = windowBounds.right - windowBounds.left;
  181509. size.cy = windowBounds.bottom - windowBounds.top;
  181510. BLENDFUNCTION bf;
  181511. bf.AlphaFormat = AC_SRC_ALPHA;
  181512. bf.BlendFlags = 0;
  181513. bf.BlendOp = AC_SRC_OVER;
  181514. bf.SourceConstantAlpha = 0xff;
  181515. if (! maskedRegion.isEmpty())
  181516. {
  181517. for (RectangleList::Iterator i (maskedRegion); i.next();)
  181518. {
  181519. const Rectangle<int>& r = *i.getRectangle();
  181520. ExcludeClipRect (hdc, r.getX(), r.getY(), r.getRight(), r.getBottom());
  181521. }
  181522. }
  181523. updateLayeredWindow (hwnd, 0, &pos, &size, hdc, &p, 0, &bf, ULW_ALPHA);
  181524. }
  181525. else
  181526. {
  181527. int savedDC = 0;
  181528. if (! maskedRegion.isEmpty())
  181529. {
  181530. savedDC = SaveDC (dc);
  181531. for (RectangleList::Iterator i (maskedRegion); i.next();)
  181532. {
  181533. const Rectangle<int>& r = *i.getRectangle();
  181534. ExcludeClipRect (dc, r.getX(), r.getY(), r.getRight(), r.getBottom());
  181535. }
  181536. }
  181537. const int w = getWidth();
  181538. const int h = getHeight();
  181539. if (hdd == 0)
  181540. {
  181541. StretchDIBits (dc,
  181542. x, y, w, h,
  181543. 0, 0, w, h,
  181544. bitmapData, (const BITMAPINFO*) &bitmapInfo,
  181545. DIB_RGB_COLORS, SRCCOPY);
  181546. }
  181547. else
  181548. {
  181549. DrawDibDraw (hdd, dc, x, y, -1, -1,
  181550. (BITMAPINFOHEADER*) &bitmapInfo, bitmapData,
  181551. 0, 0, w, h, 0);
  181552. }
  181553. if (! maskedRegion.isEmpty())
  181554. RestoreDC (dc, savedDC);
  181555. }
  181556. }
  181557. juce_UseDebuggingNewOperator
  181558. private:
  181559. WindowsBitmapImage (const WindowsBitmapImage&);
  181560. WindowsBitmapImage& operator= (const WindowsBitmapImage&);
  181561. };
  181562. long improbableWindowNumber = 0xf965aa01; // also referenced by messaging.cpp
  181563. bool KeyPress::isKeyCurrentlyDown (const int keyCode) throw()
  181564. {
  181565. SHORT k = (SHORT) keyCode;
  181566. if ((keyCode & extendedKeyModifier) == 0
  181567. && (k >= (SHORT) T('a') && k <= (SHORT) T('z')))
  181568. k += (SHORT) T('A') - (SHORT) T('a');
  181569. const SHORT translatedValues[] = { (SHORT) ',', VK_OEM_COMMA,
  181570. (SHORT) '+', VK_OEM_PLUS,
  181571. (SHORT) '-', VK_OEM_MINUS,
  181572. (SHORT) '.', VK_OEM_PERIOD,
  181573. (SHORT) ';', VK_OEM_1,
  181574. (SHORT) ':', VK_OEM_1,
  181575. (SHORT) '/', VK_OEM_2,
  181576. (SHORT) '?', VK_OEM_2,
  181577. (SHORT) '[', VK_OEM_4,
  181578. (SHORT) ']', VK_OEM_6 };
  181579. for (int i = 0; i < numElementsInArray (translatedValues); i += 2)
  181580. if (k == translatedValues [i])
  181581. k = translatedValues [i + 1];
  181582. return (GetKeyState (k) & 0x8000) != 0;
  181583. }
  181584. static void* callFunctionIfNotLocked (MessageCallbackFunction* callback, void* userData)
  181585. {
  181586. if (MessageManager::getInstance()->currentThreadHasLockedMessageManager())
  181587. return callback (userData);
  181588. else
  181589. return MessageManager::getInstance()->callFunctionOnMessageThread (callback, userData);
  181590. }
  181591. class Win32ComponentPeer : public ComponentPeer
  181592. {
  181593. public:
  181594. Win32ComponentPeer (Component* const component,
  181595. const int windowStyleFlags)
  181596. : ComponentPeer (component, windowStyleFlags),
  181597. dontRepaint (false),
  181598. fullScreen (false),
  181599. isDragging (false),
  181600. isMouseOver (false),
  181601. hasCreatedCaret (false),
  181602. currentWindowIcon (0),
  181603. taskBarIcon (0),
  181604. dropTarget (0)
  181605. {
  181606. callFunctionIfNotLocked (&createWindowCallback, (void*) this);
  181607. setTitle (component->getName());
  181608. if ((windowStyleFlags & windowHasDropShadow) != 0
  181609. && Desktop::canUseSemiTransparentWindows())
  181610. {
  181611. shadower = component->getLookAndFeel().createDropShadowerForComponent (component);
  181612. if (shadower != 0)
  181613. shadower->setOwner (component);
  181614. }
  181615. else
  181616. {
  181617. shadower = 0;
  181618. }
  181619. }
  181620. ~Win32ComponentPeer()
  181621. {
  181622. setTaskBarIcon (0);
  181623. deleteAndZero (shadower);
  181624. // do this before the next bit to avoid messages arriving for this window
  181625. // before it's destroyed
  181626. SetWindowLongPtr (hwnd, GWLP_USERDATA, 0);
  181627. callFunctionIfNotLocked (&destroyWindowCallback, (void*) hwnd);
  181628. if (currentWindowIcon != 0)
  181629. DestroyIcon (currentWindowIcon);
  181630. if (dropTarget != 0)
  181631. {
  181632. dropTarget->Release();
  181633. dropTarget = 0;
  181634. }
  181635. }
  181636. void* getNativeHandle() const
  181637. {
  181638. return (void*) hwnd;
  181639. }
  181640. void setVisible (bool shouldBeVisible)
  181641. {
  181642. ShowWindow (hwnd, shouldBeVisible ? SW_SHOWNA : SW_HIDE);
  181643. if (shouldBeVisible)
  181644. InvalidateRect (hwnd, 0, 0);
  181645. else
  181646. lastPaintTime = 0;
  181647. }
  181648. void setTitle (const String& title)
  181649. {
  181650. SetWindowText (hwnd, title);
  181651. }
  181652. void setPosition (int x, int y)
  181653. {
  181654. offsetWithinParent (x, y);
  181655. SetWindowPos (hwnd, 0,
  181656. x - windowBorder.getLeft(),
  181657. y - windowBorder.getTop(),
  181658. 0, 0,
  181659. SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  181660. }
  181661. void repaintNowIfTransparent()
  181662. {
  181663. if (isTransparent() && lastPaintTime > 0 && Time::getMillisecondCounter() > lastPaintTime + 30)
  181664. handlePaintMessage();
  181665. }
  181666. void updateBorderSize()
  181667. {
  181668. WINDOWINFO info;
  181669. info.cbSize = sizeof (info);
  181670. if (GetWindowInfo (hwnd, &info))
  181671. {
  181672. windowBorder = BorderSize (info.rcClient.top - info.rcWindow.top,
  181673. info.rcClient.left - info.rcWindow.left,
  181674. info.rcWindow.bottom - info.rcClient.bottom,
  181675. info.rcWindow.right - info.rcClient.right);
  181676. }
  181677. }
  181678. void setSize (int w, int h)
  181679. {
  181680. SetWindowPos (hwnd, 0, 0, 0,
  181681. w + windowBorder.getLeftAndRight(),
  181682. h + windowBorder.getTopAndBottom(),
  181683. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  181684. updateBorderSize();
  181685. repaintNowIfTransparent();
  181686. }
  181687. void setBounds (int x, int y, int w, int h, const bool isNowFullScreen)
  181688. {
  181689. fullScreen = isNowFullScreen;
  181690. offsetWithinParent (x, y);
  181691. SetWindowPos (hwnd, 0,
  181692. x - windowBorder.getLeft(),
  181693. y - windowBorder.getTop(),
  181694. w + windowBorder.getLeftAndRight(),
  181695. h + windowBorder.getTopAndBottom(),
  181696. SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  181697. updateBorderSize();
  181698. repaintNowIfTransparent();
  181699. }
  181700. const Rectangle<int> getBounds() const
  181701. {
  181702. RECT r;
  181703. GetWindowRect (hwnd, &r);
  181704. Rectangle<int> bounds (r.left, r.top, r.right - r.left, r.bottom - r.top);
  181705. HWND parentH = GetParent (hwnd);
  181706. if (parentH != 0)
  181707. {
  181708. GetWindowRect (parentH, &r);
  181709. bounds.translate (-r.left, -r.top);
  181710. }
  181711. return windowBorder.subtractedFrom (bounds);
  181712. }
  181713. const Point<int> getScreenPosition() const
  181714. {
  181715. RECT r;
  181716. GetWindowRect (hwnd, &r);
  181717. return Point<int> (r.left + windowBorder.getLeft(),
  181718. r.top + windowBorder.getTop());
  181719. }
  181720. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition)
  181721. {
  181722. return relativePosition + getScreenPosition();
  181723. }
  181724. const Point<int> globalPositionToRelative (const Point<int>& screenPosition)
  181725. {
  181726. return screenPosition - getScreenPosition();
  181727. }
  181728. void setMinimised (bool shouldBeMinimised)
  181729. {
  181730. if (shouldBeMinimised != isMinimised())
  181731. ShowWindow (hwnd, shouldBeMinimised ? SW_MINIMIZE : SW_SHOWNORMAL);
  181732. }
  181733. bool isMinimised() const
  181734. {
  181735. WINDOWPLACEMENT wp;
  181736. wp.length = sizeof (WINDOWPLACEMENT);
  181737. GetWindowPlacement (hwnd, &wp);
  181738. return wp.showCmd == SW_SHOWMINIMIZED;
  181739. }
  181740. void setFullScreen (bool shouldBeFullScreen)
  181741. {
  181742. setMinimised (false);
  181743. if (fullScreen != shouldBeFullScreen)
  181744. {
  181745. fullScreen = shouldBeFullScreen;
  181746. const Component::SafePointer<Component> deletionChecker (component);
  181747. if (! fullScreen)
  181748. {
  181749. const Rectangle<int> boundsCopy (lastNonFullscreenBounds);
  181750. if (hasTitleBar())
  181751. ShowWindow (hwnd, SW_SHOWNORMAL);
  181752. if (! boundsCopy.isEmpty())
  181753. {
  181754. setBounds (boundsCopy.getX(),
  181755. boundsCopy.getY(),
  181756. boundsCopy.getWidth(),
  181757. boundsCopy.getHeight(),
  181758. false);
  181759. }
  181760. }
  181761. else
  181762. {
  181763. if (hasTitleBar())
  181764. ShowWindow (hwnd, SW_SHOWMAXIMIZED);
  181765. else
  181766. SendMessageW (hwnd, WM_SETTINGCHANGE, 0, 0);
  181767. }
  181768. if (deletionChecker != 0)
  181769. handleMovedOrResized();
  181770. }
  181771. }
  181772. bool isFullScreen() const
  181773. {
  181774. if (! hasTitleBar())
  181775. return fullScreen;
  181776. WINDOWPLACEMENT wp;
  181777. wp.length = sizeof (wp);
  181778. GetWindowPlacement (hwnd, &wp);
  181779. return wp.showCmd == SW_SHOWMAXIMIZED;
  181780. }
  181781. bool contains (const Point<int>& position, bool trueIfInAChildWindow) const
  181782. {
  181783. if (((unsigned int) position.getX()) >= (unsigned int) component->getWidth()
  181784. || ((unsigned int) position.getY()) >= (unsigned int) component->getHeight())
  181785. return false;
  181786. RECT r;
  181787. GetWindowRect (hwnd, &r);
  181788. POINT p;
  181789. p.x = position.getX() + r.left + windowBorder.getLeft();
  181790. p.y = position.getY() + r.top + windowBorder.getTop();
  181791. HWND w = WindowFromPoint (p);
  181792. return w == hwnd || (trueIfInAChildWindow && (IsChild (hwnd, w) != 0));
  181793. }
  181794. const BorderSize getFrameSize() const
  181795. {
  181796. return windowBorder;
  181797. }
  181798. bool setAlwaysOnTop (bool alwaysOnTop)
  181799. {
  181800. const bool oldDeactivate = shouldDeactivateTitleBar;
  181801. shouldDeactivateTitleBar = ((styleFlags & windowIsTemporary) == 0);
  181802. SetWindowPos (hwnd, alwaysOnTop ? HWND_TOPMOST : HWND_NOTOPMOST,
  181803. 0, 0, 0, 0,
  181804. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  181805. shouldDeactivateTitleBar = oldDeactivate;
  181806. if (shadower != 0)
  181807. shadower->componentBroughtToFront (*component);
  181808. return true;
  181809. }
  181810. void toFront (bool makeActive)
  181811. {
  181812. setMinimised (false);
  181813. const bool oldDeactivate = shouldDeactivateTitleBar;
  181814. shouldDeactivateTitleBar = ((styleFlags & windowIsTemporary) == 0);
  181815. callFunctionIfNotLocked (makeActive ? &toFrontCallback1
  181816. : &toFrontCallback2,
  181817. (void*) hwnd);
  181818. shouldDeactivateTitleBar = oldDeactivate;
  181819. if (! makeActive)
  181820. {
  181821. // in this case a broughttofront call won't have occured, so do it now..
  181822. handleBroughtToFront();
  181823. }
  181824. }
  181825. void toBehind (ComponentPeer* other)
  181826. {
  181827. Win32ComponentPeer* const otherPeer = dynamic_cast <Win32ComponentPeer*> (other);
  181828. jassert (otherPeer != 0); // wrong type of window?
  181829. if (otherPeer != 0)
  181830. {
  181831. setMinimised (false);
  181832. // must be careful not to try to put a topmost window behind a normal one, or win32
  181833. // promotes the normal one to be topmost!
  181834. if (getComponent()->isAlwaysOnTop() == otherPeer->getComponent()->isAlwaysOnTop())
  181835. SetWindowPos (hwnd, otherPeer->hwnd, 0, 0, 0, 0,
  181836. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  181837. else if (otherPeer->getComponent()->isAlwaysOnTop())
  181838. SetWindowPos (hwnd, HWND_TOP, 0, 0, 0, 0,
  181839. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  181840. }
  181841. }
  181842. bool isFocused() const
  181843. {
  181844. return callFunctionIfNotLocked (&getFocusCallback, 0) == (void*) hwnd;
  181845. }
  181846. void grabFocus()
  181847. {
  181848. const bool oldDeactivate = shouldDeactivateTitleBar;
  181849. shouldDeactivateTitleBar = ((styleFlags & windowIsTemporary) == 0);
  181850. callFunctionIfNotLocked (&setFocusCallback, (void*) hwnd);
  181851. shouldDeactivateTitleBar = oldDeactivate;
  181852. }
  181853. void textInputRequired (const Point<int>&)
  181854. {
  181855. if (! hasCreatedCaret)
  181856. {
  181857. hasCreatedCaret = true;
  181858. CreateCaret (hwnd, (HBITMAP) 1, 0, 0);
  181859. }
  181860. ShowCaret (hwnd);
  181861. SetCaretPos (0, 0);
  181862. }
  181863. void repaint (int x, int y, int w, int h)
  181864. {
  181865. const RECT r = { x, y, x + w, y + h };
  181866. InvalidateRect (hwnd, &r, FALSE);
  181867. }
  181868. void performAnyPendingRepaintsNow()
  181869. {
  181870. MSG m;
  181871. if (component->isVisible() && PeekMessage (&m, hwnd, WM_PAINT, WM_PAINT, PM_REMOVE))
  181872. DispatchMessage (&m);
  181873. }
  181874. static Win32ComponentPeer* getOwnerOfWindow (HWND h) throw()
  181875. {
  181876. if (h != 0 && GetWindowLongPtr (h, GWLP_USERDATA) == improbableWindowNumber)
  181877. return (Win32ComponentPeer*) (pointer_sized_int) GetWindowLongPtr (h, 8);
  181878. return 0;
  181879. }
  181880. void setTaskBarIcon (const Image* const image)
  181881. {
  181882. if (image != 0)
  181883. {
  181884. HICON hicon = createHICONFromImage (*image, TRUE, 0, 0);
  181885. if (taskBarIcon == 0)
  181886. {
  181887. taskBarIcon = new NOTIFYICONDATA();
  181888. taskBarIcon->cbSize = sizeof (NOTIFYICONDATA);
  181889. taskBarIcon->hWnd = (HWND) hwnd;
  181890. taskBarIcon->uID = (int) (pointer_sized_int) hwnd;
  181891. taskBarIcon->uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
  181892. taskBarIcon->uCallbackMessage = WM_TRAYNOTIFY;
  181893. taskBarIcon->hIcon = hicon;
  181894. taskBarIcon->szTip[0] = 0;
  181895. Shell_NotifyIcon (NIM_ADD, taskBarIcon);
  181896. }
  181897. else
  181898. {
  181899. HICON oldIcon = taskBarIcon->hIcon;
  181900. taskBarIcon->hIcon = hicon;
  181901. taskBarIcon->uFlags = NIF_ICON;
  181902. Shell_NotifyIcon (NIM_MODIFY, taskBarIcon);
  181903. DestroyIcon (oldIcon);
  181904. }
  181905. DestroyIcon (hicon);
  181906. }
  181907. else if (taskBarIcon != 0)
  181908. {
  181909. taskBarIcon->uFlags = 0;
  181910. Shell_NotifyIcon (NIM_DELETE, taskBarIcon);
  181911. DestroyIcon (taskBarIcon->hIcon);
  181912. deleteAndZero (taskBarIcon);
  181913. }
  181914. }
  181915. void setTaskBarIconToolTip (const String& toolTip) const
  181916. {
  181917. if (taskBarIcon != 0)
  181918. {
  181919. taskBarIcon->uFlags = NIF_TIP;
  181920. toolTip.copyToUnicode (taskBarIcon->szTip, sizeof (taskBarIcon->szTip) - 1);
  181921. Shell_NotifyIcon (NIM_MODIFY, taskBarIcon);
  181922. }
  181923. }
  181924. bool isInside (HWND h) const
  181925. {
  181926. return GetAncestor (hwnd, GA_ROOT) == h;
  181927. }
  181928. static void updateKeyModifiers() throw()
  181929. {
  181930. int keyMods = 0;
  181931. if (GetKeyState (VK_SHIFT) & 0x8000) keyMods |= ModifierKeys::shiftModifier;
  181932. if (GetKeyState (VK_CONTROL) & 0x8000) keyMods |= ModifierKeys::ctrlModifier;
  181933. if (GetKeyState (VK_MENU) & 0x8000) keyMods |= ModifierKeys::altModifier;
  181934. if (GetKeyState (VK_RMENU) & 0x8000) keyMods &= ~(ModifierKeys::ctrlModifier | ModifierKeys::altModifier);
  181935. currentModifiers = currentModifiers.withOnlyMouseButtons().withFlags (keyMods);
  181936. }
  181937. static void updateModifiersFromWParam (const WPARAM wParam)
  181938. {
  181939. int mouseMods = 0;
  181940. if (wParam & MK_LBUTTON) mouseMods |= ModifierKeys::leftButtonModifier;
  181941. if (wParam & MK_RBUTTON) mouseMods |= ModifierKeys::rightButtonModifier;
  181942. if (wParam & MK_MBUTTON) mouseMods |= ModifierKeys::middleButtonModifier;
  181943. currentModifiers = currentModifiers.withoutMouseButtons().withFlags (mouseMods);
  181944. updateKeyModifiers();
  181945. }
  181946. static int64 getMouseEventTime()
  181947. {
  181948. static int64 eventTimeOffset = 0;
  181949. static DWORD lastMessageTime = 0;
  181950. const DWORD thisMessageTime = GetMessageTime();
  181951. if (thisMessageTime < lastMessageTime || lastMessageTime == 0)
  181952. {
  181953. lastMessageTime = thisMessageTime;
  181954. eventTimeOffset = Time::currentTimeMillis() - thisMessageTime;
  181955. }
  181956. return eventTimeOffset + thisMessageTime;
  181957. }
  181958. juce_UseDebuggingNewOperator
  181959. bool dontRepaint;
  181960. static ModifierKeys currentModifiers;
  181961. static ModifierKeys modifiersAtLastCallback;
  181962. private:
  181963. HWND hwnd;
  181964. DropShadower* shadower;
  181965. bool fullScreen, isDragging, isMouseOver, hasCreatedCaret;
  181966. BorderSize windowBorder;
  181967. HICON currentWindowIcon;
  181968. NOTIFYICONDATA* taskBarIcon;
  181969. IDropTarget* dropTarget;
  181970. class TemporaryImage : public Timer
  181971. {
  181972. public:
  181973. TemporaryImage()
  181974. : image (0)
  181975. {
  181976. }
  181977. ~TemporaryImage()
  181978. {
  181979. delete image;
  181980. }
  181981. WindowsBitmapImage* getImage (const bool transparent, const int w, const int h) throw()
  181982. {
  181983. const Image::PixelFormat format = transparent ? Image::ARGB : Image::RGB;
  181984. if (image == 0 || image->getWidth() < w || image->getHeight() < h || image->getFormat() != format)
  181985. {
  181986. delete image;
  181987. image = new WindowsBitmapImage (format, (w + 31) & ~31, (h + 31) & ~31, false);
  181988. }
  181989. startTimer (3000);
  181990. return image;
  181991. }
  181992. void timerCallback()
  181993. {
  181994. stopTimer();
  181995. deleteAndZero (image);
  181996. }
  181997. private:
  181998. WindowsBitmapImage* image;
  181999. TemporaryImage (const TemporaryImage&);
  182000. TemporaryImage& operator= (const TemporaryImage&);
  182001. };
  182002. TemporaryImage offscreenImageGenerator;
  182003. class WindowClassHolder : public DeletedAtShutdown
  182004. {
  182005. public:
  182006. WindowClassHolder()
  182007. : windowClassName ("JUCE_")
  182008. {
  182009. // this name has to be different for each app/dll instance because otherwise
  182010. // poor old Win32 can get a bit confused (even despite it not being a process-global
  182011. // window class).
  182012. windowClassName << (int) (Time::currentTimeMillis() & 0x7fffffff);
  182013. HINSTANCE moduleHandle = (HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle();
  182014. TCHAR moduleFile [1024];
  182015. moduleFile[0] = 0;
  182016. GetModuleFileName (moduleHandle, moduleFile, 1024);
  182017. WORD iconNum = 0;
  182018. WNDCLASSEX wcex;
  182019. wcex.cbSize = sizeof (wcex);
  182020. wcex.style = CS_OWNDC;
  182021. wcex.lpfnWndProc = (WNDPROC) windowProc;
  182022. wcex.lpszClassName = windowClassName;
  182023. wcex.cbClsExtra = 0;
  182024. wcex.cbWndExtra = 32;
  182025. wcex.hInstance = moduleHandle;
  182026. wcex.hIcon = ExtractAssociatedIcon (moduleHandle, moduleFile, &iconNum);
  182027. iconNum = 1;
  182028. wcex.hIconSm = ExtractAssociatedIcon (moduleHandle, moduleFile, &iconNum);
  182029. wcex.hCursor = 0;
  182030. wcex.hbrBackground = 0;
  182031. wcex.lpszMenuName = 0;
  182032. RegisterClassEx (&wcex);
  182033. }
  182034. ~WindowClassHolder()
  182035. {
  182036. if (ComponentPeer::getNumPeers() == 0)
  182037. UnregisterClass (windowClassName, (HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle());
  182038. clearSingletonInstance();
  182039. }
  182040. String windowClassName;
  182041. juce_DeclareSingleton_SingleThreaded_Minimal (WindowClassHolder);
  182042. };
  182043. static void* createWindowCallback (void* userData)
  182044. {
  182045. ((Win32ComponentPeer*) userData)->createWindow();
  182046. return 0;
  182047. }
  182048. void createWindow()
  182049. {
  182050. DWORD exstyle = WS_EX_ACCEPTFILES;
  182051. DWORD type = WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
  182052. if (hasTitleBar())
  182053. {
  182054. type |= WS_OVERLAPPED;
  182055. exstyle |= WS_EX_APPWINDOW;
  182056. if ((styleFlags & windowHasCloseButton) != 0)
  182057. {
  182058. type |= WS_SYSMENU;
  182059. }
  182060. else
  182061. {
  182062. // annoyingly, windows won't let you have a min/max button without a close button
  182063. jassert ((styleFlags & (windowHasMinimiseButton | windowHasMaximiseButton)) == 0);
  182064. }
  182065. if ((styleFlags & windowIsResizable) != 0)
  182066. type |= WS_THICKFRAME;
  182067. }
  182068. else
  182069. {
  182070. type |= WS_POPUP | WS_SYSMENU;
  182071. if ((styleFlags & windowAppearsOnTaskbar) == 0)
  182072. exstyle |= WS_EX_TOOLWINDOW;
  182073. else
  182074. exstyle |= WS_EX_APPWINDOW;
  182075. }
  182076. if ((styleFlags & windowHasMinimiseButton) != 0)
  182077. type |= WS_MINIMIZEBOX;
  182078. if ((styleFlags & windowHasMaximiseButton) != 0)
  182079. type |= WS_MAXIMIZEBOX;
  182080. if ((styleFlags & windowIgnoresMouseClicks) != 0)
  182081. exstyle |= WS_EX_TRANSPARENT;
  182082. if ((styleFlags & windowIsSemiTransparent) != 0
  182083. && Desktop::canUseSemiTransparentWindows())
  182084. exstyle |= WS_EX_LAYERED;
  182085. hwnd = CreateWindowEx (exstyle, WindowClassHolder::getInstance()->windowClassName, L"", type, 0, 0, 0, 0, 0, 0, 0, 0);
  182086. if (hwnd != 0)
  182087. {
  182088. SetWindowLongPtr (hwnd, 0, 0);
  182089. SetWindowLongPtr (hwnd, 8, (LONG_PTR) this);
  182090. SetWindowLongPtr (hwnd, GWLP_USERDATA, improbableWindowNumber);
  182091. if (dropTarget == 0)
  182092. dropTarget = new JuceDropTarget (this);
  182093. RegisterDragDrop (hwnd, dropTarget);
  182094. updateBorderSize();
  182095. // Calling this function here is (for some reason) necessary to make Windows
  182096. // correctly enable the menu items that we specify in the wm_initmenu message.
  182097. GetSystemMenu (hwnd, false);
  182098. }
  182099. else
  182100. {
  182101. jassertfalse
  182102. }
  182103. }
  182104. static void* destroyWindowCallback (void* handle)
  182105. {
  182106. RevokeDragDrop ((HWND) handle);
  182107. DestroyWindow ((HWND) handle);
  182108. return 0;
  182109. }
  182110. static void* toFrontCallback1 (void* h)
  182111. {
  182112. SetForegroundWindow ((HWND) h);
  182113. return 0;
  182114. }
  182115. static void* toFrontCallback2 (void* h)
  182116. {
  182117. SetWindowPos ((HWND) h, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  182118. return 0;
  182119. }
  182120. static void* setFocusCallback (void* h)
  182121. {
  182122. SetFocus ((HWND) h);
  182123. return 0;
  182124. }
  182125. static void* getFocusCallback (void*)
  182126. {
  182127. return (void*) GetFocus();
  182128. }
  182129. void offsetWithinParent (int& x, int& y) const
  182130. {
  182131. if (isTransparent())
  182132. {
  182133. HWND parentHwnd = GetParent (hwnd);
  182134. if (parentHwnd != 0)
  182135. {
  182136. RECT parentRect;
  182137. GetWindowRect (parentHwnd, &parentRect);
  182138. x += parentRect.left;
  182139. y += parentRect.top;
  182140. }
  182141. }
  182142. }
  182143. bool isTransparent() const
  182144. {
  182145. return (GetWindowLong (hwnd, GWL_EXSTYLE) & WS_EX_LAYERED) != 0;
  182146. }
  182147. inline bool hasTitleBar() const throw() { return (styleFlags & windowHasTitleBar) != 0; }
  182148. void setIcon (const Image& newIcon)
  182149. {
  182150. HICON hicon = createHICONFromImage (newIcon, TRUE, 0, 0);
  182151. if (hicon != 0)
  182152. {
  182153. SendMessage (hwnd, WM_SETICON, ICON_BIG, (LPARAM) hicon);
  182154. SendMessage (hwnd, WM_SETICON, ICON_SMALL, (LPARAM) hicon);
  182155. if (currentWindowIcon != 0)
  182156. DestroyIcon (currentWindowIcon);
  182157. currentWindowIcon = hicon;
  182158. }
  182159. }
  182160. void handlePaintMessage()
  182161. {
  182162. HRGN rgn = CreateRectRgn (0, 0, 0, 0);
  182163. const int regionType = GetUpdateRgn (hwnd, rgn, false);
  182164. PAINTSTRUCT paintStruct;
  182165. HDC dc = BeginPaint (hwnd, &paintStruct); // Note this can immediately generate a WM_NCPAINT
  182166. // message and become re-entrant, but that's OK
  182167. // if something in a paint handler calls, e.g. a message box, this can become reentrant and
  182168. // corrupt the image it's using to paint into, so do a check here.
  182169. static bool reentrant = false;
  182170. if (reentrant)
  182171. {
  182172. DeleteObject (rgn);
  182173. EndPaint (hwnd, &paintStruct);
  182174. return;
  182175. }
  182176. reentrant = true;
  182177. // this is the rectangle to update..
  182178. int x = paintStruct.rcPaint.left;
  182179. int y = paintStruct.rcPaint.top;
  182180. int w = paintStruct.rcPaint.right - x;
  182181. int h = paintStruct.rcPaint.bottom - y;
  182182. const bool transparent = isTransparent();
  182183. if (transparent)
  182184. {
  182185. // it's not possible to have a transparent window with a title bar at the moment!
  182186. jassert (! hasTitleBar());
  182187. RECT r;
  182188. GetWindowRect (hwnd, &r);
  182189. x = y = 0;
  182190. w = r.right - r.left;
  182191. h = r.bottom - r.top;
  182192. }
  182193. if (w > 0 && h > 0)
  182194. {
  182195. clearMaskedRegion();
  182196. WindowsBitmapImage* const offscreenImage = offscreenImageGenerator.getImage (transparent, w, h);
  182197. RectangleList contextClip;
  182198. bool needToPaintAll = true;
  182199. if (regionType == COMPLEXREGION && ! transparent)
  182200. {
  182201. HRGN clipRgn = CreateRectRgnIndirect (&paintStruct.rcPaint);
  182202. CombineRgn (rgn, rgn, clipRgn, RGN_AND);
  182203. DeleteObject (clipRgn);
  182204. char rgnData [8192];
  182205. const DWORD res = GetRegionData (rgn, sizeof (rgnData), (RGNDATA*) rgnData);
  182206. if (res > 0 && res <= sizeof (rgnData))
  182207. {
  182208. const RGNDATAHEADER* const hdr = &(((const RGNDATA*) rgnData)->rdh);
  182209. if (hdr->iType == RDH_RECTANGLES
  182210. && hdr->rcBound.right - hdr->rcBound.left >= w
  182211. && hdr->rcBound.bottom - hdr->rcBound.top >= h)
  182212. {
  182213. needToPaintAll = false;
  182214. const RECT* rects = (const RECT*) (rgnData + sizeof (RGNDATAHEADER));
  182215. int num = ((RGNDATA*) rgnData)->rdh.nCount;
  182216. while (--num >= 0)
  182217. {
  182218. // (need to move this one pixel to the left because of a win32 bug)
  182219. const int cx = jmax (x, (int) rects->left - 1);
  182220. const int cy = rects->top;
  182221. const int cw = rects->right - cx;
  182222. const int ch = rects->bottom - rects->top;
  182223. if (cx + cw - x <= w && cy + ch - y <= h)
  182224. {
  182225. contextClip.addWithoutMerging (Rectangle<int> (cx - x, cy - y, cw, ch));
  182226. }
  182227. else
  182228. {
  182229. needToPaintAll = true;
  182230. break;
  182231. }
  182232. ++rects;
  182233. }
  182234. }
  182235. }
  182236. }
  182237. if (needToPaintAll)
  182238. {
  182239. contextClip.clear();
  182240. contextClip.addWithoutMerging (Rectangle<int> (0, 0, w, h));
  182241. }
  182242. if (transparent)
  182243. {
  182244. RectangleList::Iterator i (contextClip);
  182245. while (i.next())
  182246. {
  182247. const Rectangle<int>& r = *i.getRectangle();
  182248. offscreenImage->clear (r.getX(), r.getY(), r.getWidth(), r.getHeight());
  182249. }
  182250. }
  182251. // if the component's not opaque, this won't draw properly unless the platform can support this
  182252. jassert (Desktop::canUseSemiTransparentWindows() || component->isOpaque());
  182253. updateCurrentModifiers();
  182254. LowLevelGraphicsSoftwareRenderer context (*offscreenImage);
  182255. context.clipToRectangleList (contextClip);
  182256. context.setOrigin (-x, -y);
  182257. handlePaint (context);
  182258. if (! dontRepaint)
  182259. offscreenImage->blitToWindow (hwnd, dc, transparent, x, y, maskedRegion);
  182260. }
  182261. DeleteObject (rgn);
  182262. EndPaint (hwnd, &paintStruct);
  182263. reentrant = false;
  182264. #ifndef JUCE_GCC //xxx should add this fn for gcc..
  182265. _fpreset(); // because some graphics cards can unmask FP exceptions
  182266. #endif
  182267. lastPaintTime = Time::getMillisecondCounter();
  182268. }
  182269. void doMouseEvent (const Point<int>& position)
  182270. {
  182271. handleMouseEvent (0, position, currentModifiers, getMouseEventTime());
  182272. }
  182273. void doMouseMove (const Point<int>& position)
  182274. {
  182275. if (! isMouseOver)
  182276. {
  182277. isMouseOver = true;
  182278. updateKeyModifiers();
  182279. TRACKMOUSEEVENT tme;
  182280. tme.cbSize = sizeof (tme);
  182281. tme.dwFlags = TME_LEAVE;
  182282. tme.hwndTrack = hwnd;
  182283. tme.dwHoverTime = 0;
  182284. if (! TrackMouseEvent (&tme))
  182285. jassertfalse;
  182286. Desktop::getInstance().getMainMouseSource().forceMouseCursorUpdate();
  182287. }
  182288. else if (! isDragging)
  182289. {
  182290. if (! contains (position, false))
  182291. return;
  182292. }
  182293. // (Throttling the incoming queue of mouse-events seems to still be required in XP..)
  182294. static uint32 lastMouseTime = 0;
  182295. const uint32 now = Time::getMillisecondCounter();
  182296. const int maxMouseMovesPerSecond = 60;
  182297. if (now > lastMouseTime + 1000 / maxMouseMovesPerSecond)
  182298. {
  182299. lastMouseTime = now;
  182300. doMouseEvent (position);
  182301. }
  182302. }
  182303. void doMouseDown (const Point<int>& position, const WPARAM wParam)
  182304. {
  182305. if (GetCapture() != hwnd)
  182306. SetCapture (hwnd);
  182307. doMouseMove (position);
  182308. updateModifiersFromWParam (wParam);
  182309. isDragging = true;
  182310. doMouseEvent (position);
  182311. }
  182312. void doMouseUp (const Point<int>& position, const WPARAM wParam)
  182313. {
  182314. updateModifiersFromWParam (wParam);
  182315. isDragging = false;
  182316. // release the mouse capture if the user has released all buttons
  182317. if ((wParam & (MK_LBUTTON | MK_RBUTTON | MK_MBUTTON)) == 0 && hwnd == GetCapture())
  182318. ReleaseCapture();
  182319. doMouseEvent (position);
  182320. }
  182321. void doCaptureChanged()
  182322. {
  182323. if (isDragging)
  182324. doMouseUp (getCurrentMousePos(), (WPARAM) 0);
  182325. }
  182326. void doMouseExit()
  182327. {
  182328. isMouseOver = false;
  182329. doMouseEvent (getCurrentMousePos());
  182330. }
  182331. void doMouseWheel (const Point<int>& position, const WPARAM wParam, const bool isVertical)
  182332. {
  182333. updateKeyModifiers();
  182334. const float amount = jlimit (-1000.0f, 1000.0f, 0.75f * (short) HIWORD (wParam));
  182335. handleMouseWheel (0, position, getMouseEventTime(),
  182336. isVertical ? 0.0f : amount,
  182337. isVertical ? amount : 0.0f);
  182338. }
  182339. void sendModifierKeyChangeIfNeeded()
  182340. {
  182341. if (modifiersAtLastCallback != currentModifiers)
  182342. {
  182343. modifiersAtLastCallback = currentModifiers;
  182344. handleModifierKeysChange();
  182345. }
  182346. }
  182347. bool doKeyUp (const WPARAM key)
  182348. {
  182349. updateKeyModifiers();
  182350. switch (key)
  182351. {
  182352. case VK_SHIFT:
  182353. case VK_CONTROL:
  182354. case VK_MENU:
  182355. case VK_CAPITAL:
  182356. case VK_LWIN:
  182357. case VK_RWIN:
  182358. case VK_APPS:
  182359. case VK_NUMLOCK:
  182360. case VK_SCROLL:
  182361. case VK_LSHIFT:
  182362. case VK_RSHIFT:
  182363. case VK_LCONTROL:
  182364. case VK_LMENU:
  182365. case VK_RCONTROL:
  182366. case VK_RMENU:
  182367. sendModifierKeyChangeIfNeeded();
  182368. }
  182369. return handleKeyUpOrDown (false)
  182370. || Component::getCurrentlyModalComponent() != 0;
  182371. }
  182372. bool doKeyDown (const WPARAM key)
  182373. {
  182374. updateKeyModifiers();
  182375. bool used = false;
  182376. switch (key)
  182377. {
  182378. case VK_SHIFT:
  182379. case VK_LSHIFT:
  182380. case VK_RSHIFT:
  182381. case VK_CONTROL:
  182382. case VK_LCONTROL:
  182383. case VK_RCONTROL:
  182384. case VK_MENU:
  182385. case VK_LMENU:
  182386. case VK_RMENU:
  182387. case VK_LWIN:
  182388. case VK_RWIN:
  182389. case VK_CAPITAL:
  182390. case VK_NUMLOCK:
  182391. case VK_SCROLL:
  182392. case VK_APPS:
  182393. sendModifierKeyChangeIfNeeded();
  182394. break;
  182395. case VK_LEFT:
  182396. case VK_RIGHT:
  182397. case VK_UP:
  182398. case VK_DOWN:
  182399. case VK_PRIOR:
  182400. case VK_NEXT:
  182401. case VK_HOME:
  182402. case VK_END:
  182403. case VK_DELETE:
  182404. case VK_INSERT:
  182405. case VK_F1:
  182406. case VK_F2:
  182407. case VK_F3:
  182408. case VK_F4:
  182409. case VK_F5:
  182410. case VK_F6:
  182411. case VK_F7:
  182412. case VK_F8:
  182413. case VK_F9:
  182414. case VK_F10:
  182415. case VK_F11:
  182416. case VK_F12:
  182417. case VK_F13:
  182418. case VK_F14:
  182419. case VK_F15:
  182420. case VK_F16:
  182421. used = handleKeyUpOrDown (true);
  182422. used = handleKeyPress (extendedKeyModifier | (int) key, 0) || used;
  182423. break;
  182424. case VK_ADD:
  182425. case VK_SUBTRACT:
  182426. case VK_MULTIPLY:
  182427. case VK_DIVIDE:
  182428. case VK_SEPARATOR:
  182429. case VK_DECIMAL:
  182430. used = handleKeyUpOrDown (true);
  182431. break;
  182432. default:
  182433. used = handleKeyUpOrDown (true);
  182434. {
  182435. MSG msg;
  182436. if (! PeekMessage (&msg, hwnd, WM_CHAR, WM_DEADCHAR, PM_NOREMOVE))
  182437. {
  182438. // if there isn't a WM_CHAR or WM_DEADCHAR message pending, we need to
  182439. // manually generate the key-press event that matches this key-down.
  182440. const UINT keyChar = MapVirtualKey (key, 2);
  182441. used = handleKeyPress ((int) LOWORD (keyChar), 0) || used;
  182442. }
  182443. }
  182444. break;
  182445. }
  182446. if (Component::getCurrentlyModalComponent() != 0)
  182447. used = true;
  182448. return used;
  182449. }
  182450. bool doKeyChar (int key, const LPARAM flags)
  182451. {
  182452. updateKeyModifiers();
  182453. juce_wchar textChar = (juce_wchar) key;
  182454. const int virtualScanCode = (flags >> 16) & 0xff;
  182455. if (key >= '0' && key <= '9')
  182456. {
  182457. switch (virtualScanCode) // check for a numeric keypad scan-code
  182458. {
  182459. case 0x52:
  182460. case 0x4f:
  182461. case 0x50:
  182462. case 0x51:
  182463. case 0x4b:
  182464. case 0x4c:
  182465. case 0x4d:
  182466. case 0x47:
  182467. case 0x48:
  182468. case 0x49:
  182469. key = (key - '0') + KeyPress::numberPad0;
  182470. break;
  182471. default:
  182472. break;
  182473. }
  182474. }
  182475. else
  182476. {
  182477. // convert the scan code to an unmodified character code..
  182478. const UINT virtualKey = MapVirtualKey (virtualScanCode, 1);
  182479. UINT keyChar = MapVirtualKey (virtualKey, 2);
  182480. keyChar = LOWORD (keyChar);
  182481. if (keyChar != 0)
  182482. key = (int) keyChar;
  182483. // avoid sending junk text characters for some control-key combinations
  182484. if (textChar < ' ' && currentModifiers.testFlags (ModifierKeys::ctrlModifier | ModifierKeys::altModifier))
  182485. textChar = 0;
  182486. }
  182487. return handleKeyPress (key, textChar);
  182488. }
  182489. bool doAppCommand (const LPARAM lParam)
  182490. {
  182491. int key = 0;
  182492. switch (GET_APPCOMMAND_LPARAM (lParam))
  182493. {
  182494. case APPCOMMAND_MEDIA_PLAY_PAUSE:
  182495. key = KeyPress::playKey;
  182496. break;
  182497. case APPCOMMAND_MEDIA_STOP:
  182498. key = KeyPress::stopKey;
  182499. break;
  182500. case APPCOMMAND_MEDIA_NEXTTRACK:
  182501. key = KeyPress::fastForwardKey;
  182502. break;
  182503. case APPCOMMAND_MEDIA_PREVIOUSTRACK:
  182504. key = KeyPress::rewindKey;
  182505. break;
  182506. }
  182507. if (key != 0)
  182508. {
  182509. updateKeyModifiers();
  182510. if (hwnd == GetActiveWindow())
  182511. {
  182512. handleKeyPress (key, 0);
  182513. return true;
  182514. }
  182515. }
  182516. return false;
  182517. }
  182518. class JuceDropTarget : public IDropTarget
  182519. {
  182520. public:
  182521. JuceDropTarget (Win32ComponentPeer* const owner_)
  182522. : owner (owner_),
  182523. refCount (1)
  182524. {
  182525. }
  182526. virtual ~JuceDropTarget()
  182527. {
  182528. jassert (refCount == 0);
  182529. }
  182530. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  182531. {
  182532. if (id == IID_IUnknown || id == IID_IDropTarget)
  182533. {
  182534. AddRef();
  182535. *result = this;
  182536. return S_OK;
  182537. }
  182538. *result = 0;
  182539. return E_NOINTERFACE;
  182540. }
  182541. ULONG __stdcall AddRef() { return ++refCount; }
  182542. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  182543. HRESULT __stdcall DragEnter (IDataObject* pDataObject, DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect)
  182544. {
  182545. updateFileList (pDataObject);
  182546. owner->handleFileDragMove (files, owner->globalPositionToRelative (Point<int> (mousePos.x, mousePos.y)));
  182547. *pdwEffect = DROPEFFECT_COPY;
  182548. return S_OK;
  182549. }
  182550. HRESULT __stdcall DragLeave()
  182551. {
  182552. owner->handleFileDragExit (files);
  182553. return S_OK;
  182554. }
  182555. HRESULT __stdcall DragOver (DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect)
  182556. {
  182557. owner->handleFileDragMove (files, owner->globalPositionToRelative (Point<int> (mousePos.x, mousePos.y)));
  182558. *pdwEffect = DROPEFFECT_COPY;
  182559. return S_OK;
  182560. }
  182561. HRESULT __stdcall Drop (IDataObject* pDataObject, DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect)
  182562. {
  182563. updateFileList (pDataObject);
  182564. owner->handleFileDragDrop (files, owner->globalPositionToRelative (Point<int> (mousePos.x, mousePos.y)));
  182565. *pdwEffect = DROPEFFECT_COPY;
  182566. return S_OK;
  182567. }
  182568. private:
  182569. Win32ComponentPeer* const owner;
  182570. int refCount;
  182571. StringArray files;
  182572. void updateFileList (IDataObject* const pDataObject)
  182573. {
  182574. files.clear();
  182575. FORMATETC format = { CF_HDROP, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  182576. STGMEDIUM medium = { TYMED_HGLOBAL, { 0 }, 0 };
  182577. if (pDataObject->GetData (&format, &medium) == S_OK)
  182578. {
  182579. const SIZE_T totalLen = GlobalSize (medium.hGlobal);
  182580. const LPDROPFILES pDropFiles = (const LPDROPFILES) GlobalLock (medium.hGlobal);
  182581. unsigned int i = 0;
  182582. if (pDropFiles->fWide)
  182583. {
  182584. const WCHAR* const fname = (WCHAR*) (((const char*) pDropFiles) + sizeof (DROPFILES));
  182585. for (;;)
  182586. {
  182587. unsigned int len = 0;
  182588. while (i + len < totalLen && fname [i + len] != 0)
  182589. ++len;
  182590. if (len == 0)
  182591. break;
  182592. files.add (String (fname + i, len));
  182593. i += len + 1;
  182594. }
  182595. }
  182596. else
  182597. {
  182598. const char* const fname = ((const char*) pDropFiles) + sizeof (DROPFILES);
  182599. for (;;)
  182600. {
  182601. unsigned int len = 0;
  182602. while (i + len < totalLen && fname [i + len] != 0)
  182603. ++len;
  182604. if (len == 0)
  182605. break;
  182606. files.add (String (fname + i, len));
  182607. i += len + 1;
  182608. }
  182609. }
  182610. GlobalUnlock (medium.hGlobal);
  182611. }
  182612. }
  182613. JuceDropTarget (const JuceDropTarget&);
  182614. JuceDropTarget& operator= (const JuceDropTarget&);
  182615. };
  182616. void doSettingChange()
  182617. {
  182618. Desktop::getInstance().refreshMonitorSizes();
  182619. if (fullScreen && ! isMinimised())
  182620. {
  182621. const Rectangle<int> r (component->getParentMonitorArea());
  182622. SetWindowPos (hwnd, 0,
  182623. r.getX(), r.getY(), r.getWidth(), r.getHeight(),
  182624. SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER | SWP_NOSENDCHANGING);
  182625. }
  182626. }
  182627. public:
  182628. static LRESULT CALLBACK windowProc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
  182629. {
  182630. Win32ComponentPeer* const peer = getOwnerOfWindow (h);
  182631. if (peer != 0)
  182632. return peer->peerWindowProc (h, message, wParam, lParam);
  182633. return DefWindowProcW (h, message, wParam, lParam);
  182634. }
  182635. private:
  182636. static const Point<int> getPointFromLParam (LPARAM lParam) throw()
  182637. {
  182638. return Point<int> (GET_X_LPARAM (lParam), GET_Y_LPARAM (lParam));
  182639. }
  182640. const Point<int> getCurrentMousePos() throw()
  182641. {
  182642. RECT wr;
  182643. GetWindowRect (hwnd, &wr);
  182644. const DWORD mp = GetMessagePos();
  182645. return Point<int> (GET_X_LPARAM (mp) - wr.left - windowBorder.getLeft(),
  182646. GET_Y_LPARAM (mp) - wr.top - windowBorder.getTop());
  182647. }
  182648. LRESULT peerWindowProc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
  182649. {
  182650. if (isValidPeer (this))
  182651. {
  182652. switch (message)
  182653. {
  182654. case WM_NCHITTEST:
  182655. if ((styleFlags & windowIgnoresMouseClicks) != 0)
  182656. return HTTRANSPARENT;
  182657. if (hasTitleBar())
  182658. break;
  182659. return HTCLIENT;
  182660. case WM_PAINT:
  182661. handlePaintMessage();
  182662. return 0;
  182663. case WM_NCPAINT:
  182664. if (wParam != 1)
  182665. handlePaintMessage();
  182666. if (hasTitleBar())
  182667. break;
  182668. return 0;
  182669. case WM_ERASEBKGND:
  182670. case WM_NCCALCSIZE:
  182671. if (hasTitleBar())
  182672. break;
  182673. return 1;
  182674. case WM_MOUSEMOVE:
  182675. doMouseMove (getPointFromLParam (lParam));
  182676. return 0;
  182677. case WM_MOUSELEAVE:
  182678. doMouseExit();
  182679. return 0;
  182680. case WM_LBUTTONDOWN:
  182681. case WM_MBUTTONDOWN:
  182682. case WM_RBUTTONDOWN:
  182683. doMouseDown (getPointFromLParam (lParam), wParam);
  182684. return 0;
  182685. case WM_LBUTTONUP:
  182686. case WM_MBUTTONUP:
  182687. case WM_RBUTTONUP:
  182688. doMouseUp (getPointFromLParam (lParam), wParam);
  182689. return 0;
  182690. case WM_CAPTURECHANGED:
  182691. doCaptureChanged();
  182692. return 0;
  182693. case WM_NCMOUSEMOVE:
  182694. if (hasTitleBar())
  182695. break;
  182696. return 0;
  182697. case 0x020A: /* WM_MOUSEWHEEL */
  182698. doMouseWheel (getCurrentMousePos(), wParam, true);
  182699. return 0;
  182700. case 0x020E: /* WM_MOUSEHWHEEL */
  182701. doMouseWheel (getCurrentMousePos(), wParam, false);
  182702. return 0;
  182703. case WM_WINDOWPOSCHANGING:
  182704. if ((styleFlags & (windowHasTitleBar | windowIsResizable)) == (windowHasTitleBar | windowIsResizable))
  182705. {
  182706. WINDOWPOS* const wp = (WINDOWPOS*) lParam;
  182707. if ((wp->flags & (SWP_NOMOVE | SWP_NOSIZE)) != (SWP_NOMOVE | SWP_NOSIZE))
  182708. {
  182709. if (constrainer != 0)
  182710. {
  182711. const Rectangle<int> current (component->getX() - windowBorder.getLeft(),
  182712. component->getY() - windowBorder.getTop(),
  182713. component->getWidth() + windowBorder.getLeftAndRight(),
  182714. component->getHeight() + windowBorder.getTopAndBottom());
  182715. Rectangle<int> pos (wp->x, wp->y, wp->cx, wp->cy);
  182716. constrainer->checkBounds (pos, current,
  182717. Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(),
  182718. pos.getY() != current.getY() && pos.getBottom() == current.getBottom(),
  182719. pos.getX() != current.getX() && pos.getRight() == current.getRight(),
  182720. pos.getY() == current.getY() && pos.getBottom() != current.getBottom(),
  182721. pos.getX() == current.getX() && pos.getRight() != current.getRight());
  182722. wp->x = pos.getX();
  182723. wp->y = pos.getY();
  182724. wp->cx = pos.getWidth();
  182725. wp->cy = pos.getHeight();
  182726. }
  182727. }
  182728. }
  182729. return 0;
  182730. case WM_WINDOWPOSCHANGED:
  182731. handleMovedOrResized();
  182732. if (dontRepaint)
  182733. break; // needed for non-accelerated openGL windows to draw themselves correctly..
  182734. return 0;
  182735. case WM_KEYDOWN:
  182736. case WM_SYSKEYDOWN:
  182737. if (doKeyDown (wParam))
  182738. return 0;
  182739. break;
  182740. case WM_KEYUP:
  182741. case WM_SYSKEYUP:
  182742. if (doKeyUp (wParam))
  182743. return 0;
  182744. break;
  182745. case WM_CHAR:
  182746. if (doKeyChar ((int) wParam, lParam))
  182747. return 0;
  182748. break;
  182749. case WM_APPCOMMAND:
  182750. if (doAppCommand (lParam))
  182751. return TRUE;
  182752. break;
  182753. case WM_SETFOCUS:
  182754. updateKeyModifiers();
  182755. handleFocusGain();
  182756. break;
  182757. case WM_KILLFOCUS:
  182758. if (hasCreatedCaret)
  182759. {
  182760. hasCreatedCaret = false;
  182761. DestroyCaret();
  182762. }
  182763. handleFocusLoss();
  182764. break;
  182765. case WM_ACTIVATEAPP:
  182766. // Windows does weird things to process priority when you swap apps,
  182767. // so this forces an update when the app is brought to the front
  182768. if (wParam != FALSE)
  182769. juce_repeatLastProcessPriority();
  182770. else
  182771. Desktop::getInstance().setKioskModeComponent (0); // turn kiosk mode off if we lose focus
  182772. juce_CheckCurrentlyFocusedTopLevelWindow();
  182773. modifiersAtLastCallback = -1;
  182774. return 0;
  182775. case WM_ACTIVATE:
  182776. if (LOWORD (wParam) == WA_ACTIVE || LOWORD (wParam) == WA_CLICKACTIVE)
  182777. {
  182778. modifiersAtLastCallback = -1;
  182779. updateKeyModifiers();
  182780. if (isMinimised())
  182781. {
  182782. component->repaint();
  182783. handleMovedOrResized();
  182784. if (! ComponentPeer::isValidPeer (this))
  182785. return 0;
  182786. }
  182787. if (LOWORD (wParam) == WA_CLICKACTIVE
  182788. && component->isCurrentlyBlockedByAnotherModalComponent())
  182789. {
  182790. const Point<int> mousePos (component->getMouseXYRelative());
  182791. Component* const underMouse = component->getComponentAt (mousePos.getX(), mousePos.getY());
  182792. if (underMouse != 0 && underMouse->isCurrentlyBlockedByAnotherModalComponent())
  182793. Component::getCurrentlyModalComponent()->inputAttemptWhenModal();
  182794. return 0;
  182795. }
  182796. handleBroughtToFront();
  182797. if (component->isCurrentlyBlockedByAnotherModalComponent())
  182798. Component::getCurrentlyModalComponent()->toFront (true);
  182799. return 0;
  182800. }
  182801. break;
  182802. case WM_NCACTIVATE:
  182803. // while a temporary window is being shown, prevent Windows from deactivating the
  182804. // title bars of our main windows.
  182805. if (wParam == 0 && ! shouldDeactivateTitleBar)
  182806. wParam = TRUE; // change this and let it get passed to the DefWindowProc.
  182807. break;
  182808. case WM_MOUSEACTIVATE:
  182809. if (! component->getMouseClickGrabsKeyboardFocus())
  182810. return MA_NOACTIVATE;
  182811. break;
  182812. case WM_SHOWWINDOW:
  182813. if (wParam != 0)
  182814. handleBroughtToFront();
  182815. break;
  182816. case WM_CLOSE:
  182817. if (! component->isCurrentlyBlockedByAnotherModalComponent())
  182818. handleUserClosingWindow();
  182819. return 0;
  182820. case WM_QUERYENDSESSION:
  182821. if (JUCEApplication::getInstance() != 0)
  182822. {
  182823. JUCEApplication::getInstance()->systemRequestedQuit();
  182824. return MessageManager::getInstance()->hasStopMessageBeenSent();
  182825. }
  182826. return TRUE;
  182827. case WM_TRAYNOTIFY:
  182828. if (component->isCurrentlyBlockedByAnotherModalComponent())
  182829. {
  182830. if (lParam == WM_LBUTTONDOWN || lParam == WM_RBUTTONDOWN
  182831. || lParam == WM_LBUTTONDBLCLK || lParam == WM_LBUTTONDBLCLK)
  182832. {
  182833. Component* const current = Component::getCurrentlyModalComponent();
  182834. if (current != 0)
  182835. current->inputAttemptWhenModal();
  182836. }
  182837. }
  182838. else
  182839. {
  182840. ModifierKeys eventMods (ModifierKeys::getCurrentModifiersRealtime());
  182841. if (lParam == WM_LBUTTONDOWN || lParam == WM_LBUTTONDBLCLK)
  182842. eventMods = eventMods.withFlags (ModifierKeys::leftButtonModifier);
  182843. else if (lParam == WM_RBUTTONDOWN || lParam == WM_RBUTTONDBLCLK)
  182844. eventMods = eventMods.withFlags (ModifierKeys::rightButtonModifier);
  182845. else if (lParam == WM_LBUTTONUP || lParam == WM_RBUTTONUP)
  182846. eventMods = eventMods.withoutMouseButtons();
  182847. const MouseEvent e (Desktop::getInstance().getMainMouseSource(),
  182848. Point<int>(), eventMods, component, getMouseEventTime(),
  182849. Point<int>(), getMouseEventTime(), 1, false);
  182850. if (lParam == WM_LBUTTONDOWN || lParam == WM_RBUTTONDOWN)
  182851. {
  182852. SetFocus (hwnd);
  182853. SetForegroundWindow (hwnd);
  182854. component->mouseDown (e);
  182855. }
  182856. else if (lParam == WM_LBUTTONUP || lParam == WM_RBUTTONUP)
  182857. {
  182858. component->mouseUp (e);
  182859. }
  182860. else if (lParam == WM_LBUTTONDBLCLK || lParam == WM_LBUTTONDBLCLK)
  182861. {
  182862. component->mouseDoubleClick (e);
  182863. }
  182864. else if (lParam == WM_MOUSEMOVE)
  182865. {
  182866. component->mouseMove (e);
  182867. }
  182868. }
  182869. break;
  182870. case WM_SYNCPAINT:
  182871. return 0;
  182872. case WM_PALETTECHANGED:
  182873. InvalidateRect (h, 0, 0);
  182874. break;
  182875. case WM_DISPLAYCHANGE:
  182876. InvalidateRect (h, 0, 0);
  182877. createPaletteIfNeeded = true;
  182878. // intentional fall-through...
  182879. case WM_SETTINGCHANGE: // note the fall-through in the previous case!
  182880. doSettingChange();
  182881. break;
  182882. case WM_INITMENU:
  182883. if (! hasTitleBar())
  182884. {
  182885. if (isFullScreen())
  182886. {
  182887. EnableMenuItem ((HMENU) wParam, SC_RESTORE, MF_BYCOMMAND | MF_ENABLED);
  182888. EnableMenuItem ((HMENU) wParam, SC_MOVE, MF_BYCOMMAND | MF_GRAYED);
  182889. }
  182890. else if (! isMinimised())
  182891. {
  182892. EnableMenuItem ((HMENU) wParam, SC_MAXIMIZE, MF_BYCOMMAND | MF_GRAYED);
  182893. }
  182894. }
  182895. break;
  182896. case WM_SYSCOMMAND:
  182897. switch (wParam & 0xfff0)
  182898. {
  182899. case SC_CLOSE:
  182900. if (sendInputAttemptWhenModalMessage())
  182901. return 0;
  182902. if (hasTitleBar())
  182903. {
  182904. PostMessage (h, WM_CLOSE, 0, 0);
  182905. return 0;
  182906. }
  182907. break;
  182908. case SC_KEYMENU:
  182909. // (NB mustn't call sendInputAttemptWhenModalMessage() here because of very
  182910. // obscure situations that can arise if a modal loop is started from an alt-key
  182911. // keypress).
  182912. if (hasTitleBar() && h == GetCapture())
  182913. ReleaseCapture();
  182914. break;
  182915. case SC_MAXIMIZE:
  182916. if (sendInputAttemptWhenModalMessage())
  182917. return 0;
  182918. setFullScreen (true);
  182919. return 0;
  182920. case SC_MINIMIZE:
  182921. if (sendInputAttemptWhenModalMessage())
  182922. return 0;
  182923. if (! hasTitleBar())
  182924. {
  182925. setMinimised (true);
  182926. return 0;
  182927. }
  182928. break;
  182929. case SC_RESTORE:
  182930. if (sendInputAttemptWhenModalMessage())
  182931. return 0;
  182932. if (hasTitleBar())
  182933. {
  182934. if (isFullScreen())
  182935. {
  182936. setFullScreen (false);
  182937. return 0;
  182938. }
  182939. }
  182940. else
  182941. {
  182942. if (isMinimised())
  182943. setMinimised (false);
  182944. else if (isFullScreen())
  182945. setFullScreen (false);
  182946. return 0;
  182947. }
  182948. break;
  182949. }
  182950. break;
  182951. case WM_NCLBUTTONDOWN:
  182952. case WM_NCRBUTTONDOWN:
  182953. case WM_NCMBUTTONDOWN:
  182954. sendInputAttemptWhenModalMessage();
  182955. break;
  182956. //case WM_IME_STARTCOMPOSITION;
  182957. // return 0;
  182958. case WM_GETDLGCODE:
  182959. return DLGC_WANTALLKEYS;
  182960. default:
  182961. break;
  182962. }
  182963. }
  182964. return DefWindowProcW (h, message, wParam, lParam);
  182965. }
  182966. bool sendInputAttemptWhenModalMessage()
  182967. {
  182968. if (component->isCurrentlyBlockedByAnotherModalComponent())
  182969. {
  182970. Component* const current = Component::getCurrentlyModalComponent();
  182971. if (current != 0)
  182972. current->inputAttemptWhenModal();
  182973. return true;
  182974. }
  182975. return false;
  182976. }
  182977. Win32ComponentPeer (const Win32ComponentPeer&);
  182978. Win32ComponentPeer& operator= (const Win32ComponentPeer&);
  182979. };
  182980. ModifierKeys Win32ComponentPeer::currentModifiers;
  182981. ModifierKeys Win32ComponentPeer::modifiersAtLastCallback;
  182982. ComponentPeer* Component::createNewPeer (int styleFlags, void* /*nativeWindowToAttachTo*/)
  182983. {
  182984. return new Win32ComponentPeer (this, styleFlags);
  182985. }
  182986. juce_ImplementSingleton_SingleThreaded (Win32ComponentPeer::WindowClassHolder);
  182987. void ModifierKeys::updateCurrentModifiers() throw()
  182988. {
  182989. currentModifiers = Win32ComponentPeer::currentModifiers;
  182990. }
  182991. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  182992. {
  182993. Win32ComponentPeer::updateKeyModifiers();
  182994. int keyMods = 0;
  182995. if ((GetKeyState (VK_LBUTTON) & 0x8000) != 0) keyMods |= ModifierKeys::leftButtonModifier;
  182996. if ((GetKeyState (VK_RBUTTON) & 0x8000) != 0) keyMods |= ModifierKeys::rightButtonModifier;
  182997. if ((GetKeyState (VK_MBUTTON) & 0x8000) != 0) keyMods |= ModifierKeys::middleButtonModifier;
  182998. Win32ComponentPeer::currentModifiers
  182999. = Win32ComponentPeer::currentModifiers.withOnlyMouseButtons().withFlags (keyMods);
  183000. return Win32ComponentPeer::currentModifiers;
  183001. }
  183002. void SystemTrayIconComponent::setIconImage (const Image& newImage)
  183003. {
  183004. Win32ComponentPeer* const wp = dynamic_cast <Win32ComponentPeer*> (getPeer());
  183005. if (wp != 0)
  183006. wp->setTaskBarIcon (&newImage);
  183007. }
  183008. void SystemTrayIconComponent::setIconTooltip (const String& tooltip)
  183009. {
  183010. Win32ComponentPeer* const wp = dynamic_cast <Win32ComponentPeer*> (getPeer());
  183011. if (wp != 0)
  183012. wp->setTaskBarIconToolTip (tooltip);
  183013. }
  183014. void juce_setWindowStyleBit (HWND h, const int styleType, const int feature, const bool bitIsSet) throw()
  183015. {
  183016. DWORD val = GetWindowLong (h, styleType);
  183017. if (bitIsSet)
  183018. val |= feature;
  183019. else
  183020. val &= ~feature;
  183021. SetWindowLongPtr (h, styleType, val);
  183022. SetWindowPos (h, 0, 0, 0, 0, 0,
  183023. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER
  183024. | SWP_NOOWNERZORDER | SWP_FRAMECHANGED | SWP_NOSENDCHANGING);
  183025. }
  183026. bool Process::isForegroundProcess()
  183027. {
  183028. HWND fg = GetForegroundWindow();
  183029. if (fg == 0)
  183030. return true;
  183031. // when running as a plugin in IE8, the browser UI runs in a different process to the plugin, so
  183032. // process ID isn't a reliable way to check if the foreground window belongs to us - instead, we
  183033. // have to see if any of our windows are children of the foreground window
  183034. fg = GetAncestor (fg, GA_ROOT);
  183035. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  183036. {
  183037. Win32ComponentPeer* const wp = dynamic_cast <Win32ComponentPeer*> (ComponentPeer::getPeer (i));
  183038. if (wp != 0 && wp->isInside (fg))
  183039. return true;
  183040. }
  183041. return false;
  183042. }
  183043. bool AlertWindow::showNativeDialogBox (const String& title,
  183044. const String& bodyText,
  183045. bool isOkCancel)
  183046. {
  183047. return MessageBox (0, bodyText, title,
  183048. MB_SETFOREGROUND | (isOkCancel ? MB_OKCANCEL
  183049. : MB_OK)) == IDOK;
  183050. }
  183051. void Desktop::createMouseInputSources()
  183052. {
  183053. mouseSources.add (new MouseInputSource (0, true));
  183054. }
  183055. const Point<int> Desktop::getMousePosition()
  183056. {
  183057. POINT mousePos;
  183058. GetCursorPos (&mousePos);
  183059. return Point<int> (mousePos.x, mousePos.y);
  183060. }
  183061. void Desktop::setMousePosition (const Point<int>& newPosition)
  183062. {
  183063. SetCursorPos (newPosition.getX(), newPosition.getY());
  183064. }
  183065. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  183066. {
  183067. return new Image (format, imageWidth, imageHeight, clearImage);
  183068. }
  183069. class ScreenSaverDefeater : public Timer,
  183070. public DeletedAtShutdown
  183071. {
  183072. public:
  183073. ScreenSaverDefeater() throw()
  183074. {
  183075. startTimer (10000);
  183076. timerCallback();
  183077. }
  183078. ~ScreenSaverDefeater() {}
  183079. void timerCallback()
  183080. {
  183081. if (Process::isForegroundProcess())
  183082. {
  183083. // simulate a shift key getting pressed..
  183084. INPUT input[2];
  183085. input[0].type = INPUT_KEYBOARD;
  183086. input[0].ki.wVk = VK_SHIFT;
  183087. input[0].ki.dwFlags = 0;
  183088. input[0].ki.dwExtraInfo = 0;
  183089. input[1].type = INPUT_KEYBOARD;
  183090. input[1].ki.wVk = VK_SHIFT;
  183091. input[1].ki.dwFlags = KEYEVENTF_KEYUP;
  183092. input[1].ki.dwExtraInfo = 0;
  183093. SendInput (2, input, sizeof (INPUT));
  183094. }
  183095. }
  183096. };
  183097. static ScreenSaverDefeater* screenSaverDefeater = 0;
  183098. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  183099. {
  183100. if (isEnabled)
  183101. {
  183102. deleteAndZero (screenSaverDefeater);
  183103. }
  183104. else if (screenSaverDefeater == 0)
  183105. {
  183106. screenSaverDefeater = new ScreenSaverDefeater();
  183107. }
  183108. }
  183109. bool Desktop::isScreenSaverEnabled() throw()
  183110. {
  183111. return screenSaverDefeater == 0;
  183112. }
  183113. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool /*allowMenusAndBars*/)
  183114. {
  183115. if (enableOrDisable)
  183116. kioskModeComponent->setBounds (Desktop::getInstance().getMainMonitorArea (false));
  183117. }
  183118. static BOOL CALLBACK enumMonitorsProc (HMONITOR, HDC, LPRECT r, LPARAM userInfo)
  183119. {
  183120. Array <Rectangle<int> >* const monitorCoords = (Array <Rectangle<int> >*) userInfo;
  183121. monitorCoords->add (Rectangle<int> (r->left, r->top, r->right - r->left, r->bottom - r->top));
  183122. return TRUE;
  183123. }
  183124. void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords, const bool clipToWorkArea)
  183125. {
  183126. EnumDisplayMonitors (0, 0, &enumMonitorsProc, (LPARAM) &monitorCoords);
  183127. // make sure the first in the list is the main monitor
  183128. for (int i = 1; i < monitorCoords.size(); ++i)
  183129. if (monitorCoords[i].getX() == 0 && monitorCoords[i].getY() == 0)
  183130. monitorCoords.swap (i, 0);
  183131. if (monitorCoords.size() == 0)
  183132. {
  183133. RECT r;
  183134. GetWindowRect (GetDesktopWindow(), &r);
  183135. monitorCoords.add (Rectangle<int> (r.left, r.top, r.right - r.left, r.bottom - r.top));
  183136. }
  183137. if (clipToWorkArea)
  183138. {
  183139. // clip the main monitor to the active non-taskbar area
  183140. RECT r;
  183141. SystemParametersInfo (SPI_GETWORKAREA, 0, &r, 0);
  183142. Rectangle<int>& screen = monitorCoords.getReference (0);
  183143. screen.setPosition (jmax (screen.getX(), (int) r.left),
  183144. jmax (screen.getY(), (int) r.top));
  183145. screen.setSize (jmin (screen.getRight(), (int) r.right) - screen.getX(),
  183146. jmin (screen.getBottom(), (int) r.bottom) - screen.getY());
  183147. }
  183148. }
  183149. static Image* createImageFromHBITMAP (HBITMAP bitmap) throw()
  183150. {
  183151. Image* im = 0;
  183152. if (bitmap != 0)
  183153. {
  183154. BITMAP bm;
  183155. if (GetObject (bitmap, sizeof (BITMAP), &bm)
  183156. && bm.bmWidth > 0 && bm.bmHeight > 0)
  183157. {
  183158. HDC tempDC = GetDC (0);
  183159. HDC dc = CreateCompatibleDC (tempDC);
  183160. ReleaseDC (0, tempDC);
  183161. SelectObject (dc, bitmap);
  183162. im = new Image (Image::ARGB, bm.bmWidth, bm.bmHeight, true);
  183163. for (int y = bm.bmHeight; --y >= 0;)
  183164. {
  183165. for (int x = bm.bmWidth; --x >= 0;)
  183166. {
  183167. COLORREF col = GetPixel (dc, x, y);
  183168. im->setPixelAt (x, y, Colour ((uint8) GetRValue (col),
  183169. (uint8) GetGValue (col),
  183170. (uint8) GetBValue (col)));
  183171. }
  183172. }
  183173. DeleteDC (dc);
  183174. }
  183175. }
  183176. return im;
  183177. }
  183178. static Image* createImageFromHICON (HICON icon) throw()
  183179. {
  183180. ICONINFO info;
  183181. if (GetIconInfo (icon, &info))
  183182. {
  183183. Image* const mask = createImageFromHBITMAP (info.hbmMask);
  183184. if (mask == 0)
  183185. return 0;
  183186. Image* const image = createImageFromHBITMAP (info.hbmColor);
  183187. if (image == 0)
  183188. return mask;
  183189. for (int y = image->getHeight(); --y >= 0;)
  183190. {
  183191. for (int x = image->getWidth(); --x >= 0;)
  183192. {
  183193. const float brightness = mask->getPixelAt (x, y).getBrightness();
  183194. if (brightness > 0.0f)
  183195. image->multiplyAlphaAt (x, y, 1.0f - brightness);
  183196. }
  183197. }
  183198. delete mask;
  183199. return image;
  183200. }
  183201. return 0;
  183202. }
  183203. static HICON createHICONFromImage (const Image& image, const BOOL isIcon, int hotspotX, int hotspotY) throw()
  183204. {
  183205. HBITMAP mask = CreateBitmap (image.getWidth(), image.getHeight(), 1, 1, 0);
  183206. ICONINFO info;
  183207. info.fIcon = isIcon;
  183208. info.xHotspot = hotspotX;
  183209. info.yHotspot = hotspotY;
  183210. info.hbmMask = mask;
  183211. HICON hi = 0;
  183212. if (SystemStats::getOperatingSystemType() >= SystemStats::WinXP)
  183213. {
  183214. WindowsBitmapImage bitmap (Image::ARGB, image.getWidth(), image.getHeight(), true);
  183215. Graphics g (bitmap);
  183216. g.drawImageAt (&image, 0, 0);
  183217. info.hbmColor = bitmap.hBitmap;
  183218. hi = CreateIconIndirect (&info);
  183219. }
  183220. else
  183221. {
  183222. HBITMAP colour = CreateCompatibleBitmap (GetDC (0), image.getWidth(), image.getHeight());
  183223. HDC colDC = CreateCompatibleDC (GetDC (0));
  183224. HDC alphaDC = CreateCompatibleDC (GetDC (0));
  183225. SelectObject (colDC, colour);
  183226. SelectObject (alphaDC, mask);
  183227. for (int y = image.getHeight(); --y >= 0;)
  183228. {
  183229. for (int x = image.getWidth(); --x >= 0;)
  183230. {
  183231. const Colour c (image.getPixelAt (x, y));
  183232. SetPixel (colDC, x, y, COLORREF (c.getRed() | (c.getGreen() << 8) | (c.getBlue() << 16)));
  183233. SetPixel (alphaDC, x, y, COLORREF (0xffffff - (c.getAlpha() | (c.getAlpha() << 8) | (c.getAlpha() << 16))));
  183234. }
  183235. }
  183236. DeleteDC (colDC);
  183237. DeleteDC (alphaDC);
  183238. info.hbmColor = colour;
  183239. hi = CreateIconIndirect (&info);
  183240. DeleteObject (colour);
  183241. }
  183242. DeleteObject (mask);
  183243. return hi;
  183244. }
  183245. Image* juce_createIconForFile (const File& file)
  183246. {
  183247. Image* image = 0;
  183248. WCHAR filename [1024];
  183249. file.getFullPathName().copyToUnicode (filename, 1023);
  183250. WORD iconNum = 0;
  183251. HICON icon = ExtractAssociatedIcon ((HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle(),
  183252. filename, &iconNum);
  183253. if (icon != 0)
  183254. {
  183255. image = createImageFromHICON (icon);
  183256. DestroyIcon (icon);
  183257. }
  183258. return image;
  183259. }
  183260. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  183261. {
  183262. const int maxW = GetSystemMetrics (SM_CXCURSOR);
  183263. const int maxH = GetSystemMetrics (SM_CYCURSOR);
  183264. const Image* im = &image;
  183265. Image* newIm = 0;
  183266. if (image.getWidth() > maxW || image.getHeight() > maxH)
  183267. {
  183268. im = newIm = image.createCopy (maxW, maxH);
  183269. hotspotX = (hotspotX * maxW) / image.getWidth();
  183270. hotspotY = (hotspotY * maxH) / image.getHeight();
  183271. }
  183272. void* cursorH = 0;
  183273. const SystemStats::OperatingSystemType os = SystemStats::getOperatingSystemType();
  183274. if (os == SystemStats::WinXP)
  183275. {
  183276. cursorH = (void*) createHICONFromImage (*im, FALSE, hotspotX, hotspotY);
  183277. }
  183278. else
  183279. {
  183280. const int stride = (maxW + 7) >> 3;
  183281. HeapBlock <uint8> andPlane, xorPlane;
  183282. andPlane.calloc (stride * maxH);
  183283. xorPlane.calloc (stride * maxH);
  183284. int index = 0;
  183285. for (int y = 0; y < maxH; ++y)
  183286. {
  183287. for (int x = 0; x < maxW; ++x)
  183288. {
  183289. const unsigned char bit = (unsigned char) (1 << (7 - (x & 7)));
  183290. const Colour pixelColour (im->getPixelAt (x, y));
  183291. if (pixelColour.getAlpha() < 127)
  183292. andPlane [index + (x >> 3)] |= bit;
  183293. else if (pixelColour.getBrightness() >= 0.5f)
  183294. xorPlane [index + (x >> 3)] |= bit;
  183295. }
  183296. index += stride;
  183297. }
  183298. cursorH = CreateCursor (0, hotspotX, hotspotY, maxW, maxH, andPlane, xorPlane);
  183299. }
  183300. delete newIm;
  183301. return cursorH;
  183302. }
  183303. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw()
  183304. {
  183305. if (cursorHandle != 0 && ! isStandard)
  183306. DestroyCursor ((HCURSOR) cursorHandle);
  183307. }
  183308. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  183309. {
  183310. LPCTSTR cursorName = IDC_ARROW;
  183311. switch (type)
  183312. {
  183313. case MouseCursor::NormalCursor:
  183314. cursorName = IDC_ARROW;
  183315. break;
  183316. case MouseCursor::NoCursor:
  183317. return 0;
  183318. case MouseCursor::DraggingHandCursor:
  183319. {
  183320. static void* dragHandCursor = 0;
  183321. if (dragHandCursor == 0)
  183322. {
  183323. static const unsigned char dragHandData[] =
  183324. { 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,
  183325. 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,
  183326. 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 };
  183327. const ScopedPointer <Image> image (ImageFileFormat::loadFrom ((const char*) dragHandData, sizeof (dragHandData)));
  183328. dragHandCursor = juce_createMouseCursorFromImage (*image, 8, 7);
  183329. }
  183330. return dragHandCursor;
  183331. }
  183332. case MouseCursor::WaitCursor:
  183333. cursorName = IDC_WAIT;
  183334. break;
  183335. case MouseCursor::IBeamCursor:
  183336. cursorName = IDC_IBEAM;
  183337. break;
  183338. case MouseCursor::PointingHandCursor:
  183339. cursorName = MAKEINTRESOURCE(32649);
  183340. break;
  183341. case MouseCursor::LeftRightResizeCursor:
  183342. case MouseCursor::LeftEdgeResizeCursor:
  183343. case MouseCursor::RightEdgeResizeCursor:
  183344. cursorName = IDC_SIZEWE;
  183345. break;
  183346. case MouseCursor::UpDownResizeCursor:
  183347. case MouseCursor::TopEdgeResizeCursor:
  183348. case MouseCursor::BottomEdgeResizeCursor:
  183349. cursorName = IDC_SIZENS;
  183350. break;
  183351. case MouseCursor::TopLeftCornerResizeCursor:
  183352. case MouseCursor::BottomRightCornerResizeCursor:
  183353. cursorName = IDC_SIZENWSE;
  183354. break;
  183355. case MouseCursor::TopRightCornerResizeCursor:
  183356. case MouseCursor::BottomLeftCornerResizeCursor:
  183357. cursorName = IDC_SIZENESW;
  183358. break;
  183359. case MouseCursor::UpDownLeftRightResizeCursor:
  183360. cursorName = IDC_SIZEALL;
  183361. break;
  183362. case MouseCursor::CrosshairCursor:
  183363. cursorName = IDC_CROSS;
  183364. break;
  183365. case MouseCursor::CopyingCursor:
  183366. // can't seem to find one of these in the win32 list..
  183367. break;
  183368. }
  183369. HCURSOR cursorH = LoadCursor (0, cursorName);
  183370. if (cursorH == 0)
  183371. cursorH = LoadCursor (0, IDC_ARROW);
  183372. return (void*) cursorH;
  183373. }
  183374. void MouseCursor::showInWindow (ComponentPeer*) const throw()
  183375. {
  183376. SetCursor ((HCURSOR) getHandle());
  183377. }
  183378. void MouseCursor::showInAllWindows() const throw()
  183379. {
  183380. showInWindow (0);
  183381. }
  183382. class JuceDropSource : public IDropSource
  183383. {
  183384. int refCount;
  183385. public:
  183386. JuceDropSource()
  183387. : refCount (1)
  183388. {
  183389. }
  183390. virtual ~JuceDropSource()
  183391. {
  183392. jassert (refCount == 0);
  183393. }
  183394. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  183395. {
  183396. if (id == IID_IUnknown || id == IID_IDropSource)
  183397. {
  183398. AddRef();
  183399. *result = this;
  183400. return S_OK;
  183401. }
  183402. *result = 0;
  183403. return E_NOINTERFACE;
  183404. }
  183405. ULONG __stdcall AddRef() { return ++refCount; }
  183406. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  183407. HRESULT __stdcall QueryContinueDrag (BOOL escapePressed, DWORD keys)
  183408. {
  183409. if (escapePressed)
  183410. return DRAGDROP_S_CANCEL;
  183411. if ((keys & (MK_LBUTTON | MK_RBUTTON)) == 0)
  183412. return DRAGDROP_S_DROP;
  183413. return S_OK;
  183414. }
  183415. HRESULT __stdcall GiveFeedback (DWORD)
  183416. {
  183417. return DRAGDROP_S_USEDEFAULTCURSORS;
  183418. }
  183419. };
  183420. class JuceEnumFormatEtc : public IEnumFORMATETC
  183421. {
  183422. public:
  183423. JuceEnumFormatEtc (const FORMATETC* const format_)
  183424. : refCount (1),
  183425. format (format_),
  183426. index (0)
  183427. {
  183428. }
  183429. virtual ~JuceEnumFormatEtc()
  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_IEnumFORMATETC)
  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 Clone (IEnumFORMATETC** result)
  183447. {
  183448. if (result == 0)
  183449. return E_POINTER;
  183450. JuceEnumFormatEtc* const newOne = new JuceEnumFormatEtc (format);
  183451. newOne->index = index;
  183452. *result = newOne;
  183453. return S_OK;
  183454. }
  183455. HRESULT __stdcall Next (ULONG celt, LPFORMATETC lpFormatEtc, ULONG* pceltFetched)
  183456. {
  183457. if (pceltFetched != 0)
  183458. *pceltFetched = 0;
  183459. else if (celt != 1)
  183460. return S_FALSE;
  183461. if (index == 0 && celt > 0 && lpFormatEtc != 0)
  183462. {
  183463. copyFormatEtc (lpFormatEtc [0], *format);
  183464. ++index;
  183465. if (pceltFetched != 0)
  183466. *pceltFetched = 1;
  183467. return S_OK;
  183468. }
  183469. return S_FALSE;
  183470. }
  183471. HRESULT __stdcall Skip (ULONG celt)
  183472. {
  183473. if (index + (int) celt >= 1)
  183474. return S_FALSE;
  183475. index += celt;
  183476. return S_OK;
  183477. }
  183478. HRESULT __stdcall Reset()
  183479. {
  183480. index = 0;
  183481. return S_OK;
  183482. }
  183483. private:
  183484. int refCount;
  183485. const FORMATETC* const format;
  183486. int index;
  183487. static void copyFormatEtc (FORMATETC& dest, const FORMATETC& source)
  183488. {
  183489. dest = source;
  183490. if (source.ptd != 0)
  183491. {
  183492. dest.ptd = (DVTARGETDEVICE*) CoTaskMemAlloc (sizeof (DVTARGETDEVICE));
  183493. *(dest.ptd) = *(source.ptd);
  183494. }
  183495. }
  183496. JuceEnumFormatEtc (const JuceEnumFormatEtc&);
  183497. JuceEnumFormatEtc& operator= (const JuceEnumFormatEtc&);
  183498. };
  183499. class JuceDataObject : public IDataObject
  183500. {
  183501. JuceDropSource* const dropSource;
  183502. const FORMATETC* const format;
  183503. const STGMEDIUM* const medium;
  183504. int refCount;
  183505. JuceDataObject (const JuceDataObject&);
  183506. JuceDataObject& operator= (const JuceDataObject&);
  183507. public:
  183508. JuceDataObject (JuceDropSource* const dropSource_,
  183509. const FORMATETC* const format_,
  183510. const STGMEDIUM* const medium_)
  183511. : dropSource (dropSource_),
  183512. format (format_),
  183513. medium (medium_),
  183514. refCount (1)
  183515. {
  183516. }
  183517. virtual ~JuceDataObject()
  183518. {
  183519. jassert (refCount == 0);
  183520. }
  183521. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  183522. {
  183523. if (id == IID_IUnknown || id == IID_IDataObject)
  183524. {
  183525. AddRef();
  183526. *result = this;
  183527. return S_OK;
  183528. }
  183529. *result = 0;
  183530. return E_NOINTERFACE;
  183531. }
  183532. ULONG __stdcall AddRef() { return ++refCount; }
  183533. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  183534. HRESULT __stdcall GetData (FORMATETC __RPC_FAR* pFormatEtc, STGMEDIUM __RPC_FAR* pMedium)
  183535. {
  183536. if ((pFormatEtc->tymed & format->tymed) != 0
  183537. && pFormatEtc->cfFormat == format->cfFormat
  183538. && pFormatEtc->dwAspect == format->dwAspect)
  183539. {
  183540. pMedium->tymed = format->tymed;
  183541. pMedium->pUnkForRelease = 0;
  183542. if (format->tymed == TYMED_HGLOBAL)
  183543. {
  183544. const SIZE_T len = GlobalSize (medium->hGlobal);
  183545. void* const src = GlobalLock (medium->hGlobal);
  183546. void* const dst = GlobalAlloc (GMEM_FIXED, len);
  183547. memcpy (dst, src, len);
  183548. GlobalUnlock (medium->hGlobal);
  183549. pMedium->hGlobal = dst;
  183550. return S_OK;
  183551. }
  183552. }
  183553. return DV_E_FORMATETC;
  183554. }
  183555. HRESULT __stdcall QueryGetData (FORMATETC __RPC_FAR* f)
  183556. {
  183557. if (f == 0)
  183558. return E_INVALIDARG;
  183559. if (f->tymed == format->tymed
  183560. && f->cfFormat == format->cfFormat
  183561. && f->dwAspect == format->dwAspect)
  183562. return S_OK;
  183563. return DV_E_FORMATETC;
  183564. }
  183565. HRESULT __stdcall GetCanonicalFormatEtc (FORMATETC __RPC_FAR*, FORMATETC __RPC_FAR* pFormatEtcOut)
  183566. {
  183567. pFormatEtcOut->ptd = 0;
  183568. return E_NOTIMPL;
  183569. }
  183570. HRESULT __stdcall EnumFormatEtc (DWORD direction, IEnumFORMATETC __RPC_FAR *__RPC_FAR *result)
  183571. {
  183572. if (result == 0)
  183573. return E_POINTER;
  183574. if (direction == DATADIR_GET)
  183575. {
  183576. *result = new JuceEnumFormatEtc (format);
  183577. return S_OK;
  183578. }
  183579. *result = 0;
  183580. return E_NOTIMPL;
  183581. }
  183582. HRESULT __stdcall GetDataHere (FORMATETC __RPC_FAR*, STGMEDIUM __RPC_FAR*) { return DATA_E_FORMATETC; }
  183583. HRESULT __stdcall SetData (FORMATETC __RPC_FAR*, STGMEDIUM __RPC_FAR*, BOOL) { return E_NOTIMPL; }
  183584. HRESULT __stdcall DAdvise (FORMATETC __RPC_FAR*, DWORD, IAdviseSink __RPC_FAR*, DWORD __RPC_FAR*) { return OLE_E_ADVISENOTSUPPORTED; }
  183585. HRESULT __stdcall DUnadvise (DWORD) { return E_NOTIMPL; }
  183586. HRESULT __stdcall EnumDAdvise (IEnumSTATDATA __RPC_FAR *__RPC_FAR *) { return OLE_E_ADVISENOTSUPPORTED; }
  183587. };
  183588. static HDROP createHDrop (const StringArray& fileNames) throw()
  183589. {
  183590. int totalChars = 0;
  183591. for (int i = fileNames.size(); --i >= 0;)
  183592. totalChars += fileNames[i].length() + 1;
  183593. HDROP hDrop = (HDROP) GlobalAlloc (GMEM_MOVEABLE | GMEM_ZEROINIT,
  183594. sizeof (DROPFILES)
  183595. + sizeof (WCHAR) * (totalChars + 2));
  183596. if (hDrop != 0)
  183597. {
  183598. LPDROPFILES pDropFiles = (LPDROPFILES) GlobalLock (hDrop);
  183599. pDropFiles->pFiles = sizeof (DROPFILES);
  183600. pDropFiles->fWide = true;
  183601. WCHAR* fname = (WCHAR*) (((char*) pDropFiles) + sizeof (DROPFILES));
  183602. for (int i = 0; i < fileNames.size(); ++i)
  183603. {
  183604. fileNames[i].copyToUnicode (fname, 2048);
  183605. fname += fileNames[i].length() + 1;
  183606. }
  183607. *fname = 0;
  183608. GlobalUnlock (hDrop);
  183609. }
  183610. return hDrop;
  183611. }
  183612. static bool performDragDrop (FORMATETC* const format, STGMEDIUM* const medium, const DWORD whatToDo) throw()
  183613. {
  183614. JuceDropSource* const source = new JuceDropSource();
  183615. JuceDataObject* const data = new JuceDataObject (source, format, medium);
  183616. DWORD effect;
  183617. const HRESULT res = DoDragDrop (data, source, whatToDo, &effect);
  183618. data->Release();
  183619. source->Release();
  183620. return res == DRAGDROP_S_DROP;
  183621. }
  183622. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMove)
  183623. {
  183624. FORMATETC format = { CF_HDROP, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  183625. STGMEDIUM medium = { TYMED_HGLOBAL, { 0 }, 0 };
  183626. medium.hGlobal = createHDrop (files);
  183627. return performDragDrop (&format, &medium, canMove ? (DROPEFFECT_COPY | DROPEFFECT_MOVE)
  183628. : DROPEFFECT_COPY);
  183629. }
  183630. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  183631. {
  183632. FORMATETC format = { CF_TEXT, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  183633. STGMEDIUM medium = { TYMED_HGLOBAL, { 0 }, 0 };
  183634. const int numChars = text.length();
  183635. medium.hGlobal = GlobalAlloc (GMEM_MOVEABLE | GMEM_ZEROINIT, (numChars + 2) * sizeof (WCHAR));
  183636. char* d = (char*) GlobalLock (medium.hGlobal);
  183637. text.copyToUnicode ((WCHAR*) d, numChars + 1);
  183638. format.cfFormat = CF_UNICODETEXT;
  183639. GlobalUnlock (medium.hGlobal);
  183640. return performDragDrop (&format, &medium, DROPEFFECT_COPY | DROPEFFECT_MOVE);
  183641. }
  183642. #endif
  183643. /*** End of inlined file: juce_win32_Windowing.cpp ***/
  183644. /*** Start of inlined file: juce_win32_Fonts.cpp ***/
  183645. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  183646. // compiled on its own).
  183647. #if JUCE_INCLUDED_FILE
  183648. static int CALLBACK wfontEnum2 (ENUMLOGFONTEXW* lpelfe,
  183649. NEWTEXTMETRICEXW*,
  183650. int type,
  183651. LPARAM lParam)
  183652. {
  183653. if (lpelfe != 0 && (type & RASTER_FONTTYPE) == 0)
  183654. {
  183655. const String fontName (lpelfe->elfLogFont.lfFaceName);
  183656. ((StringArray*) lParam)->addIfNotAlreadyThere (fontName.removeCharacters (T("@")));
  183657. }
  183658. return 1;
  183659. }
  183660. static int CALLBACK wfontEnum1 (ENUMLOGFONTEXW* lpelfe,
  183661. NEWTEXTMETRICEXW*,
  183662. int type,
  183663. LPARAM lParam)
  183664. {
  183665. if (lpelfe != 0 && (type & RASTER_FONTTYPE) == 0)
  183666. {
  183667. LOGFONTW lf;
  183668. zerostruct (lf);
  183669. lf.lfWeight = FW_DONTCARE;
  183670. lf.lfOutPrecision = OUT_OUTLINE_PRECIS;
  183671. lf.lfQuality = DEFAULT_QUALITY;
  183672. lf.lfCharSet = DEFAULT_CHARSET;
  183673. lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  183674. lf.lfPitchAndFamily = FF_DONTCARE;
  183675. const String fontName (lpelfe->elfLogFont.lfFaceName);
  183676. fontName.copyToUnicode (lf.lfFaceName, LF_FACESIZE - 1);
  183677. HDC dc = CreateCompatibleDC (0);
  183678. EnumFontFamiliesEx (dc, &lf,
  183679. (FONTENUMPROCW) &wfontEnum2,
  183680. lParam, 0);
  183681. DeleteDC (dc);
  183682. }
  183683. return 1;
  183684. }
  183685. const StringArray Font::findAllTypefaceNames() throw()
  183686. {
  183687. StringArray results;
  183688. HDC dc = CreateCompatibleDC (0);
  183689. {
  183690. LOGFONTW lf;
  183691. zerostruct (lf);
  183692. lf.lfWeight = FW_DONTCARE;
  183693. lf.lfOutPrecision = OUT_OUTLINE_PRECIS;
  183694. lf.lfQuality = DEFAULT_QUALITY;
  183695. lf.lfCharSet = DEFAULT_CHARSET;
  183696. lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  183697. lf.lfPitchAndFamily = FF_DONTCARE;
  183698. lf.lfFaceName[0] = 0;
  183699. EnumFontFamiliesEx (dc, &lf,
  183700. (FONTENUMPROCW) &wfontEnum1,
  183701. (LPARAM) &results, 0);
  183702. }
  183703. DeleteDC (dc);
  183704. results.sort (true);
  183705. return results;
  183706. }
  183707. extern bool juce_IsRunningInWine();
  183708. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw()
  183709. {
  183710. if (juce_IsRunningInWine())
  183711. {
  183712. // If we're running in Wine, then use fonts that might be available on Linux..
  183713. defaultSans = "Bitstream Vera Sans";
  183714. defaultSerif = "Bitstream Vera Serif";
  183715. defaultFixed = "Bitstream Vera Sans Mono";
  183716. }
  183717. else
  183718. {
  183719. defaultSans = "Verdana";
  183720. defaultSerif = "Times";
  183721. defaultFixed = "Lucida Console";
  183722. }
  183723. }
  183724. class FontDCHolder : private DeletedAtShutdown
  183725. {
  183726. public:
  183727. FontDCHolder() throw()
  183728. : dc (0), numKPs (0), size (0),
  183729. bold (false), italic (false)
  183730. {
  183731. }
  183732. ~FontDCHolder() throw()
  183733. {
  183734. if (dc != 0)
  183735. {
  183736. DeleteDC (dc);
  183737. DeleteObject (fontH);
  183738. }
  183739. clearSingletonInstance();
  183740. }
  183741. juce_DeclareSingleton_SingleThreaded_Minimal (FontDCHolder);
  183742. HDC loadFont (const String& fontName_, const bool bold_, const bool italic_, const int size_) throw()
  183743. {
  183744. if (fontName != fontName_ || bold != bold_ || italic != italic_ || size != size_)
  183745. {
  183746. fontName = fontName_;
  183747. bold = bold_;
  183748. italic = italic_;
  183749. size = size_;
  183750. if (dc != 0)
  183751. {
  183752. DeleteDC (dc);
  183753. DeleteObject (fontH);
  183754. kps.free();
  183755. }
  183756. fontH = 0;
  183757. dc = CreateCompatibleDC (0);
  183758. SetMapperFlags (dc, 0);
  183759. SetMapMode (dc, MM_TEXT);
  183760. LOGFONTW lfw;
  183761. zerostruct (lfw);
  183762. lfw.lfCharSet = DEFAULT_CHARSET;
  183763. lfw.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  183764. lfw.lfOutPrecision = OUT_OUTLINE_PRECIS;
  183765. lfw.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
  183766. lfw.lfQuality = PROOF_QUALITY;
  183767. lfw.lfItalic = (BYTE) (italic ? TRUE : FALSE);
  183768. lfw.lfWeight = bold ? FW_BOLD : FW_NORMAL;
  183769. fontName.copyToUnicode (lfw.lfFaceName, LF_FACESIZE - 1);
  183770. lfw.lfHeight = size > 0 ? size : -256;
  183771. HFONT standardSizedFont = CreateFontIndirect (&lfw);
  183772. if (standardSizedFont != 0)
  183773. {
  183774. if (SelectObject (dc, standardSizedFont) != 0)
  183775. {
  183776. fontH = standardSizedFont;
  183777. if (size == 0)
  183778. {
  183779. OUTLINETEXTMETRIC otm;
  183780. if (GetOutlineTextMetrics (dc, sizeof (otm), &otm) != 0)
  183781. {
  183782. lfw.lfHeight = -(int) otm.otmEMSquare;
  183783. fontH = CreateFontIndirect (&lfw);
  183784. SelectObject (dc, fontH);
  183785. DeleteObject (standardSizedFont);
  183786. }
  183787. }
  183788. }
  183789. else
  183790. {
  183791. jassertfalse
  183792. }
  183793. }
  183794. else
  183795. {
  183796. jassertfalse
  183797. }
  183798. }
  183799. return dc;
  183800. }
  183801. KERNINGPAIR* getKerningPairs (int& numKPs_) throw()
  183802. {
  183803. if (kps == 0)
  183804. {
  183805. numKPs = GetKerningPairs (dc, 0, 0);
  183806. kps.calloc (numKPs);
  183807. GetKerningPairs (dc, numKPs, kps);
  183808. }
  183809. numKPs_ = numKPs;
  183810. return kps;
  183811. }
  183812. private:
  183813. HFONT fontH;
  183814. HDC dc;
  183815. String fontName;
  183816. HeapBlock <KERNINGPAIR> kps;
  183817. int numKPs, size;
  183818. bool bold, italic;
  183819. FontDCHolder (const FontDCHolder&);
  183820. FontDCHolder& operator= (const FontDCHolder&);
  183821. };
  183822. juce_ImplementSingleton_SingleThreaded (FontDCHolder);
  183823. class WindowsTypeface : public CustomTypeface
  183824. {
  183825. public:
  183826. WindowsTypeface (const Font& font)
  183827. {
  183828. HDC dc = FontDCHolder::getInstance()->loadFont (font.getTypefaceName(),
  183829. font.isBold(), font.isItalic(), 0);
  183830. TEXTMETRIC tm;
  183831. tm.tmAscent = tm.tmHeight = 1;
  183832. tm.tmDefaultChar = 0;
  183833. GetTextMetrics (dc, &tm);
  183834. setCharacteristics (font.getTypefaceName(),
  183835. tm.tmAscent / (float) tm.tmHeight,
  183836. font.isBold(), font.isItalic(),
  183837. tm.tmDefaultChar);
  183838. }
  183839. bool loadGlyphIfPossible (const juce_wchar character)
  183840. {
  183841. HDC dc = FontDCHolder::getInstance()->loadFont (name, isBold, isItalic, 0);
  183842. GLYPHMETRICS gm;
  183843. {
  183844. const WCHAR charToTest[] = { (WCHAR) character, 0 };
  183845. WORD index = 0;
  183846. if (GetGlyphIndices (dc, charToTest, 1, &index, GGI_MARK_NONEXISTING_GLYPHS) != GDI_ERROR
  183847. && index == 0xffff)
  183848. {
  183849. return false;
  183850. }
  183851. }
  183852. Path glyphPath;
  183853. TEXTMETRIC tm;
  183854. if (! GetTextMetrics (dc, &tm))
  183855. {
  183856. addGlyph (character, glyphPath, 0);
  183857. return true;
  183858. }
  183859. const float height = (float) tm.tmHeight;
  183860. static const MAT2 identityMatrix = { { 0, 1 }, { 0, 0 }, { 0, 0 }, { 0, 1 } };
  183861. const int bufSize = GetGlyphOutline (dc, character, GGO_NATIVE,
  183862. &gm, 0, 0, &identityMatrix);
  183863. if (bufSize > 0)
  183864. {
  183865. HeapBlock<char> data (bufSize);
  183866. GetGlyphOutline (dc, character, GGO_NATIVE, &gm,
  183867. bufSize, data, &identityMatrix);
  183868. const TTPOLYGONHEADER* pheader = reinterpret_cast<TTPOLYGONHEADER*> (data.getData());
  183869. const float scaleX = 1.0f / height;
  183870. const float scaleY = -1.0f / height;
  183871. while ((char*) pheader < data + bufSize)
  183872. {
  183873. float x = scaleX * pheader->pfxStart.x.value;
  183874. float y = scaleY * pheader->pfxStart.y.value;
  183875. glyphPath.startNewSubPath (x, y);
  183876. const TTPOLYCURVE* curve = (const TTPOLYCURVE*) ((const char*) pheader + sizeof (TTPOLYGONHEADER));
  183877. const char* const curveEnd = ((const char*) pheader) + pheader->cb;
  183878. while ((const char*) curve < curveEnd)
  183879. {
  183880. if (curve->wType == TT_PRIM_LINE)
  183881. {
  183882. for (int i = 0; i < curve->cpfx; ++i)
  183883. {
  183884. x = scaleX * curve->apfx[i].x.value;
  183885. y = scaleY * curve->apfx[i].y.value;
  183886. glyphPath.lineTo (x, y);
  183887. }
  183888. }
  183889. else if (curve->wType == TT_PRIM_QSPLINE)
  183890. {
  183891. for (int i = 0; i < curve->cpfx - 1; ++i)
  183892. {
  183893. const float x2 = scaleX * curve->apfx[i].x.value;
  183894. const float y2 = scaleY * curve->apfx[i].y.value;
  183895. float x3, y3;
  183896. if (i < curve->cpfx - 2)
  183897. {
  183898. x3 = 0.5f * (x2 + scaleX * curve->apfx[i + 1].x.value);
  183899. y3 = 0.5f * (y2 + scaleY * curve->apfx[i + 1].y.value);
  183900. }
  183901. else
  183902. {
  183903. x3 = scaleX * curve->apfx[i + 1].x.value;
  183904. y3 = scaleY * curve->apfx[i + 1].y.value;
  183905. }
  183906. glyphPath.quadraticTo (x2, y2, x3, y3);
  183907. x = x3;
  183908. y = y3;
  183909. }
  183910. }
  183911. curve = (const TTPOLYCURVE*) &(curve->apfx [curve->cpfx]);
  183912. }
  183913. pheader = (const TTPOLYGONHEADER*) curve;
  183914. glyphPath.closeSubPath();
  183915. }
  183916. }
  183917. addGlyph (character, glyphPath, gm.gmCellIncX / height);
  183918. int numKPs;
  183919. const KERNINGPAIR* const kps = FontDCHolder::getInstance()->getKerningPairs (numKPs);
  183920. for (int i = 0; i < numKPs; ++i)
  183921. {
  183922. if (kps[i].wFirst == character)
  183923. addKerningPair (kps[i].wFirst, kps[i].wSecond,
  183924. kps[i].iKernAmount / height);
  183925. }
  183926. return true;
  183927. }
  183928. };
  183929. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  183930. {
  183931. return new WindowsTypeface (font);
  183932. }
  183933. #endif
  183934. /*** End of inlined file: juce_win32_Fonts.cpp ***/
  183935. /*** Start of inlined file: juce_win32_FileChooser.cpp ***/
  183936. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  183937. // compiled on its own).
  183938. #if JUCE_INCLUDED_FILE
  183939. static const void* defaultDirPath = 0;
  183940. static String returnedString; // need this to get non-existent pathnames from the directory chooser
  183941. static Component* currentExtraFileWin = 0;
  183942. static bool areThereAnyAlwaysOnTopWindows()
  183943. {
  183944. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  183945. {
  183946. Component* c = Desktop::getInstance().getComponent (i);
  183947. if (c != 0 && c->isAlwaysOnTop() && c->isShowing())
  183948. return true;
  183949. }
  183950. return false;
  183951. }
  183952. static int CALLBACK browseCallbackProc (HWND hWnd, UINT msg, LPARAM lParam, LPARAM /*lpData*/)
  183953. {
  183954. if (msg == BFFM_INITIALIZED)
  183955. {
  183956. SendMessage (hWnd, BFFM_SETSELECTIONW, TRUE, (LPARAM) defaultDirPath);
  183957. }
  183958. else if (msg == BFFM_VALIDATEFAILEDW)
  183959. {
  183960. returnedString = (LPCWSTR) lParam;
  183961. }
  183962. else if (msg == BFFM_VALIDATEFAILEDA)
  183963. {
  183964. returnedString = (const char*) lParam;
  183965. }
  183966. return 0;
  183967. }
  183968. void juce_setWindowStyleBit (HWND h, const int styleType, const int feature, const bool bitIsSet) throw();
  183969. static UINT_PTR CALLBACK openCallback (HWND hdlg, UINT uiMsg, WPARAM /*wParam*/, LPARAM lParam)
  183970. {
  183971. if (currentExtraFileWin != 0)
  183972. {
  183973. if (uiMsg == WM_INITDIALOG)
  183974. {
  183975. HWND dialogH = GetParent (hdlg);
  183976. jassert (dialogH != 0);
  183977. if (dialogH == 0)
  183978. dialogH = hdlg;
  183979. RECT r, cr;
  183980. GetWindowRect (dialogH, &r);
  183981. GetClientRect (dialogH, &cr);
  183982. SetWindowPos (dialogH, 0,
  183983. r.left, r.top,
  183984. currentExtraFileWin->getWidth() + jmax (150, (int) (r.right - r.left)),
  183985. jmax (150, (int) (r.bottom - r.top)),
  183986. SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
  183987. currentExtraFileWin->setBounds (cr.right, cr.top, currentExtraFileWin->getWidth(), cr.bottom - cr.top);
  183988. currentExtraFileWin->getChildComponent(0)->setBounds (0, 0, currentExtraFileWin->getWidth(), currentExtraFileWin->getHeight());
  183989. SetParent ((HWND) currentExtraFileWin->getWindowHandle(), (HWND) dialogH);
  183990. juce_setWindowStyleBit ((HWND)currentExtraFileWin->getWindowHandle(), GWL_STYLE, WS_CHILD, (dialogH != 0));
  183991. juce_setWindowStyleBit ((HWND)currentExtraFileWin->getWindowHandle(), GWL_STYLE, WS_POPUP, (dialogH == 0));
  183992. }
  183993. else if (uiMsg == WM_NOTIFY)
  183994. {
  183995. LPOFNOTIFY ofn = (LPOFNOTIFY) lParam;
  183996. if (ofn->hdr.code == CDN_SELCHANGE)
  183997. {
  183998. FilePreviewComponent* comp = (FilePreviewComponent*) currentExtraFileWin->getChildComponent(0);
  183999. if (comp != 0)
  184000. {
  184001. TCHAR path [MAX_PATH * 2];
  184002. path[0] = 0;
  184003. CommDlg_OpenSave_GetFilePath (GetParent (hdlg), (LPARAM) &path, MAX_PATH);
  184004. const String fn ((const WCHAR*) path);
  184005. comp->selectedFileChanged (File (fn));
  184006. }
  184007. }
  184008. }
  184009. }
  184010. return 0;
  184011. }
  184012. class FPComponentHolder : public Component
  184013. {
  184014. public:
  184015. FPComponentHolder()
  184016. {
  184017. setVisible (true);
  184018. setOpaque (true);
  184019. }
  184020. ~FPComponentHolder()
  184021. {
  184022. }
  184023. void paint (Graphics& g)
  184024. {
  184025. g.fillAll (Colours::lightgrey);
  184026. }
  184027. private:
  184028. FPComponentHolder (const FPComponentHolder&);
  184029. FPComponentHolder& operator= (const FPComponentHolder&);
  184030. };
  184031. void FileChooser::showPlatformDialog (Array<File>& results,
  184032. const String& title,
  184033. const File& currentFileOrDirectory,
  184034. const String& filter,
  184035. bool selectsDirectory,
  184036. bool /*selectsFiles*/,
  184037. bool isSaveDialogue,
  184038. bool warnAboutOverwritingExistingFiles,
  184039. bool selectMultipleFiles,
  184040. FilePreviewComponent* extraInfoComponent)
  184041. {
  184042. const int numCharsAvailable = 32768;
  184043. MemoryBlock filenameSpace ((numCharsAvailable + 1) * sizeof (WCHAR), true);
  184044. WCHAR* const fname = (WCHAR*) filenameSpace.getData();
  184045. int fnameIdx = 0;
  184046. JUCE_TRY
  184047. {
  184048. // use a modal window as the parent for this dialog box
  184049. // to block input from other app windows
  184050. const Rectangle<int> mainMon (Desktop::getInstance().getMainMonitorArea());
  184051. Component w (String::empty);
  184052. w.setBounds (mainMon.getX() + mainMon.getWidth() / 4,
  184053. mainMon.getY() + mainMon.getHeight() / 4,
  184054. 0, 0);
  184055. w.setOpaque (true);
  184056. w.setAlwaysOnTop (areThereAnyAlwaysOnTopWindows());
  184057. w.addToDesktop (0);
  184058. if (extraInfoComponent == 0)
  184059. w.enterModalState();
  184060. String initialDir;
  184061. if (currentFileOrDirectory.isDirectory())
  184062. {
  184063. initialDir = currentFileOrDirectory.getFullPathName();
  184064. }
  184065. else
  184066. {
  184067. currentFileOrDirectory.getFileName().copyToUnicode (fname, numCharsAvailable);
  184068. initialDir = currentFileOrDirectory.getParentDirectory().getFullPathName();
  184069. }
  184070. if (currentExtraFileWin->isValidComponent())
  184071. {
  184072. jassertfalse
  184073. return;
  184074. }
  184075. if (selectsDirectory)
  184076. {
  184077. LPITEMIDLIST list = 0;
  184078. filenameSpace.fillWith (0);
  184079. {
  184080. BROWSEINFO bi;
  184081. zerostruct (bi);
  184082. bi.hwndOwner = (HWND) w.getWindowHandle();
  184083. bi.pszDisplayName = fname;
  184084. bi.lpszTitle = title;
  184085. bi.lpfn = browseCallbackProc;
  184086. #ifdef BIF_USENEWUI
  184087. bi.ulFlags = BIF_USENEWUI | BIF_VALIDATE;
  184088. #else
  184089. bi.ulFlags = 0x50;
  184090. #endif
  184091. defaultDirPath = (const WCHAR*) initialDir;
  184092. list = SHBrowseForFolder (&bi);
  184093. if (! SHGetPathFromIDListW (list, fname))
  184094. {
  184095. fname[0] = 0;
  184096. returnedString = String::empty;
  184097. }
  184098. }
  184099. LPMALLOC al;
  184100. if (list != 0 && SUCCEEDED (SHGetMalloc (&al)))
  184101. al->Free (list);
  184102. defaultDirPath = 0;
  184103. if (returnedString.isNotEmpty())
  184104. {
  184105. const String stringFName (fname);
  184106. results.add (File (stringFName).getSiblingFile (returnedString));
  184107. returnedString = String::empty;
  184108. return;
  184109. }
  184110. }
  184111. else
  184112. {
  184113. DWORD flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
  184114. if (warnAboutOverwritingExistingFiles)
  184115. flags |= OFN_OVERWRITEPROMPT;
  184116. if (selectMultipleFiles)
  184117. flags |= OFN_ALLOWMULTISELECT;
  184118. if (extraInfoComponent != 0)
  184119. {
  184120. flags |= OFN_ENABLEHOOK;
  184121. currentExtraFileWin = new FPComponentHolder();
  184122. currentExtraFileWin->addAndMakeVisible (extraInfoComponent);
  184123. currentExtraFileWin->setSize (jlimit (20, 800, extraInfoComponent->getWidth()),
  184124. extraInfoComponent->getHeight());
  184125. currentExtraFileWin->addToDesktop (0);
  184126. currentExtraFileWin->enterModalState();
  184127. }
  184128. {
  184129. WCHAR filters [1024];
  184130. zeromem (filters, sizeof (filters));
  184131. filter.copyToUnicode (filters, 1024);
  184132. filter.copyToUnicode (filters + filter.length() + 1,
  184133. 1022 - filter.length());
  184134. OPENFILENAMEW of;
  184135. zerostruct (of);
  184136. #ifdef OPENFILENAME_SIZE_VERSION_400W
  184137. of.lStructSize = OPENFILENAME_SIZE_VERSION_400W;
  184138. #else
  184139. of.lStructSize = sizeof (of);
  184140. #endif
  184141. of.hwndOwner = (HWND) w.getWindowHandle();
  184142. of.lpstrFilter = filters;
  184143. of.nFilterIndex = 1;
  184144. of.lpstrFile = fname;
  184145. of.nMaxFile = numCharsAvailable;
  184146. of.lpstrInitialDir = initialDir;
  184147. of.lpstrTitle = title;
  184148. of.Flags = flags;
  184149. if (extraInfoComponent != 0)
  184150. of.lpfnHook = &openCallback;
  184151. if (isSaveDialogue)
  184152. {
  184153. if (! GetSaveFileName (&of))
  184154. fname[0] = 0;
  184155. else
  184156. fnameIdx = of.nFileOffset;
  184157. }
  184158. else
  184159. {
  184160. if (! GetOpenFileName (&of))
  184161. fname[0] = 0;
  184162. else
  184163. fnameIdx = of.nFileOffset;
  184164. }
  184165. }
  184166. }
  184167. }
  184168. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  184169. catch (...)
  184170. {
  184171. fname[0] = 0;
  184172. }
  184173. #endif
  184174. deleteAndZero (currentExtraFileWin);
  184175. const WCHAR* const files = fname;
  184176. if (selectMultipleFiles && fnameIdx > 0 && files [fnameIdx - 1] == 0)
  184177. {
  184178. const WCHAR* filename = files + fnameIdx;
  184179. while (*filename != 0)
  184180. {
  184181. const String filepath (String (files) + T("\\") + String (filename));
  184182. results.add (File (filepath));
  184183. filename += CharacterFunctions::length (filename) + 1;
  184184. }
  184185. }
  184186. else if (files[0] != 0)
  184187. {
  184188. results.add (File (files));
  184189. }
  184190. }
  184191. #endif
  184192. /*** End of inlined file: juce_win32_FileChooser.cpp ***/
  184193. /*** Start of inlined file: juce_win32_Misc.cpp ***/
  184194. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184195. // compiled on its own).
  184196. #if JUCE_INCLUDED_FILE
  184197. void SystemClipboard::copyTextToClipboard (const String& text) throw()
  184198. {
  184199. if (OpenClipboard (0) != 0)
  184200. {
  184201. if (EmptyClipboard() != 0)
  184202. {
  184203. const int len = text.length();
  184204. if (len > 0)
  184205. {
  184206. HGLOBAL bufH = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE,
  184207. (len + 1) * sizeof (wchar_t));
  184208. if (bufH != 0)
  184209. {
  184210. WCHAR* const data = (WCHAR*) GlobalLock (bufH);
  184211. text.copyToUnicode (data, len);
  184212. GlobalUnlock (bufH);
  184213. SetClipboardData (CF_UNICODETEXT, bufH);
  184214. }
  184215. }
  184216. }
  184217. CloseClipboard();
  184218. }
  184219. }
  184220. const String SystemClipboard::getTextFromClipboard() throw()
  184221. {
  184222. String result;
  184223. if (OpenClipboard (0) != 0)
  184224. {
  184225. HANDLE bufH = GetClipboardData (CF_UNICODETEXT);
  184226. if (bufH != 0)
  184227. {
  184228. const wchar_t* const data = (const wchar_t*) GlobalLock (bufH);
  184229. if (data != 0)
  184230. {
  184231. result = String (data, (int) (GlobalSize (bufH) / sizeof (tchar)));
  184232. GlobalUnlock (bufH);
  184233. }
  184234. }
  184235. CloseClipboard();
  184236. }
  184237. return result;
  184238. }
  184239. #endif
  184240. /*** End of inlined file: juce_win32_Misc.cpp ***/
  184241. /*** Start of inlined file: juce_win32_ActiveXComponent.cpp ***/
  184242. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184243. // compiled on its own).
  184244. #if JUCE_INCLUDED_FILE
  184245. namespace ActiveXHelpers
  184246. {
  184247. class JuceIStorage : public IStorage
  184248. {
  184249. int refCount;
  184250. public:
  184251. JuceIStorage() : refCount (1) {}
  184252. virtual ~JuceIStorage()
  184253. {
  184254. jassert (refCount == 0);
  184255. }
  184256. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184257. {
  184258. if (id == IID_IUnknown || id == IID_IStorage)
  184259. {
  184260. AddRef();
  184261. *result = this;
  184262. return S_OK;
  184263. }
  184264. *result = 0;
  184265. return E_NOINTERFACE;
  184266. }
  184267. ULONG __stdcall AddRef() { return ++refCount; }
  184268. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184269. HRESULT __stdcall CreateStream (const WCHAR*, DWORD, DWORD, DWORD, IStream**) { return E_NOTIMPL; }
  184270. HRESULT __stdcall OpenStream (const WCHAR*, void*, DWORD, DWORD, IStream**) { return E_NOTIMPL; }
  184271. HRESULT __stdcall CreateStorage (const WCHAR*, DWORD, DWORD, DWORD, IStorage**) { return E_NOTIMPL; }
  184272. HRESULT __stdcall OpenStorage (const WCHAR*, IStorage*, DWORD, SNB, DWORD, IStorage**) { return E_NOTIMPL; }
  184273. HRESULT __stdcall CopyTo (DWORD, IID const*, SNB, IStorage*) { return E_NOTIMPL; }
  184274. HRESULT __stdcall MoveElementTo (const OLECHAR*,IStorage*, const OLECHAR*, DWORD) { return E_NOTIMPL; }
  184275. HRESULT __stdcall Commit (DWORD) { return E_NOTIMPL; }
  184276. HRESULT __stdcall Revert() { return E_NOTIMPL; }
  184277. HRESULT __stdcall EnumElements (DWORD, void*, DWORD, IEnumSTATSTG**) { return E_NOTIMPL; }
  184278. HRESULT __stdcall DestroyElement (const OLECHAR*) { return E_NOTIMPL; }
  184279. HRESULT __stdcall RenameElement (const WCHAR*, const WCHAR*) { return E_NOTIMPL; }
  184280. HRESULT __stdcall SetElementTimes (const WCHAR*, FILETIME const*, FILETIME const*, FILETIME const*) { return E_NOTIMPL; }
  184281. HRESULT __stdcall SetClass (REFCLSID) { return S_OK; }
  184282. HRESULT __stdcall SetStateBits (DWORD, DWORD) { return E_NOTIMPL; }
  184283. HRESULT __stdcall Stat (STATSTG*, DWORD) { return E_NOTIMPL; }
  184284. juce_UseDebuggingNewOperator
  184285. };
  184286. class JuceOleInPlaceFrame : public IOleInPlaceFrame
  184287. {
  184288. int refCount;
  184289. HWND window;
  184290. public:
  184291. JuceOleInPlaceFrame (HWND window_)
  184292. : refCount (1),
  184293. window (window_)
  184294. {
  184295. }
  184296. virtual ~JuceOleInPlaceFrame()
  184297. {
  184298. jassert (refCount == 0);
  184299. }
  184300. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184301. {
  184302. if (id == IID_IUnknown || id == IID_IOleInPlaceFrame)
  184303. {
  184304. AddRef();
  184305. *result = this;
  184306. return S_OK;
  184307. }
  184308. *result = 0;
  184309. return E_NOINTERFACE;
  184310. }
  184311. ULONG __stdcall AddRef() { return ++refCount; }
  184312. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184313. HRESULT __stdcall GetWindow (HWND* lphwnd) { *lphwnd = window; return S_OK; }
  184314. HRESULT __stdcall ContextSensitiveHelp (BOOL) { return E_NOTIMPL; }
  184315. HRESULT __stdcall GetBorder (LPRECT) { return E_NOTIMPL; }
  184316. HRESULT __stdcall RequestBorderSpace (LPCBORDERWIDTHS) { return E_NOTIMPL; }
  184317. HRESULT __stdcall SetBorderSpace (LPCBORDERWIDTHS) { return E_NOTIMPL; }
  184318. HRESULT __stdcall SetActiveObject (IOleInPlaceActiveObject*, LPCOLESTR) { return S_OK; }
  184319. HRESULT __stdcall InsertMenus (HMENU, LPOLEMENUGROUPWIDTHS) { return E_NOTIMPL; }
  184320. HRESULT __stdcall SetMenu (HMENU, HOLEMENU, HWND) { return S_OK; }
  184321. HRESULT __stdcall RemoveMenus (HMENU) { return E_NOTIMPL; }
  184322. HRESULT __stdcall SetStatusText (LPCOLESTR) { return S_OK; }
  184323. HRESULT __stdcall EnableModeless (BOOL) { return S_OK; }
  184324. HRESULT __stdcall TranslateAccelerator(LPMSG, WORD) { return E_NOTIMPL; }
  184325. juce_UseDebuggingNewOperator
  184326. };
  184327. class JuceIOleInPlaceSite : public IOleInPlaceSite
  184328. {
  184329. int refCount;
  184330. HWND window;
  184331. JuceOleInPlaceFrame* frame;
  184332. public:
  184333. JuceIOleInPlaceSite (HWND window_)
  184334. : refCount (1),
  184335. window (window_)
  184336. {
  184337. frame = new JuceOleInPlaceFrame (window);
  184338. }
  184339. virtual ~JuceIOleInPlaceSite()
  184340. {
  184341. jassert (refCount == 0);
  184342. frame->Release();
  184343. }
  184344. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184345. {
  184346. if (id == IID_IUnknown || id == IID_IOleInPlaceSite)
  184347. {
  184348. AddRef();
  184349. *result = this;
  184350. return S_OK;
  184351. }
  184352. *result = 0;
  184353. return E_NOINTERFACE;
  184354. }
  184355. ULONG __stdcall AddRef() { return ++refCount; }
  184356. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184357. HRESULT __stdcall GetWindow (HWND* lphwnd) { *lphwnd = window; return S_OK; }
  184358. HRESULT __stdcall ContextSensitiveHelp (BOOL) { return E_NOTIMPL; }
  184359. HRESULT __stdcall CanInPlaceActivate() { return S_OK; }
  184360. HRESULT __stdcall OnInPlaceActivate() { return S_OK; }
  184361. HRESULT __stdcall OnUIActivate() { return S_OK; }
  184362. HRESULT __stdcall GetWindowContext (LPOLEINPLACEFRAME* lplpFrame, LPOLEINPLACEUIWINDOW* lplpDoc, LPRECT, LPRECT, LPOLEINPLACEFRAMEINFO lpFrameInfo)
  184363. {
  184364. // frame->AddRef(); // MS docs are unclear about whether this is needed, but it seems to lead to a memory leak..
  184365. *lplpFrame = frame;
  184366. *lplpDoc = 0;
  184367. lpFrameInfo->fMDIApp = FALSE;
  184368. lpFrameInfo->hwndFrame = window;
  184369. lpFrameInfo->haccel = 0;
  184370. lpFrameInfo->cAccelEntries = 0;
  184371. return S_OK;
  184372. }
  184373. HRESULT __stdcall Scroll (SIZE) { return E_NOTIMPL; }
  184374. HRESULT __stdcall OnUIDeactivate (BOOL) { return S_OK; }
  184375. HRESULT __stdcall OnInPlaceDeactivate() { return S_OK; }
  184376. HRESULT __stdcall DiscardUndoState() { return E_NOTIMPL; }
  184377. HRESULT __stdcall DeactivateAndUndo() { return E_NOTIMPL; }
  184378. HRESULT __stdcall OnPosRectChange (LPCRECT) { return S_OK; }
  184379. juce_UseDebuggingNewOperator
  184380. };
  184381. class JuceIOleClientSite : public IOleClientSite
  184382. {
  184383. int refCount;
  184384. JuceIOleInPlaceSite* inplaceSite;
  184385. public:
  184386. JuceIOleClientSite (HWND window)
  184387. : refCount (1)
  184388. {
  184389. inplaceSite = new JuceIOleInPlaceSite (window);
  184390. }
  184391. virtual ~JuceIOleClientSite()
  184392. {
  184393. jassert (refCount == 0);
  184394. inplaceSite->Release();
  184395. }
  184396. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184397. {
  184398. if (id == IID_IUnknown || id == IID_IOleClientSite)
  184399. {
  184400. AddRef();
  184401. *result = this;
  184402. return S_OK;
  184403. }
  184404. else if (id == IID_IOleInPlaceSite)
  184405. {
  184406. inplaceSite->AddRef();
  184407. *result = inplaceSite;
  184408. return S_OK;
  184409. }
  184410. *result = 0;
  184411. return E_NOINTERFACE;
  184412. }
  184413. ULONG __stdcall AddRef() { return ++refCount; }
  184414. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184415. HRESULT __stdcall SaveObject() { return E_NOTIMPL; }
  184416. HRESULT __stdcall GetMoniker (DWORD, DWORD, IMoniker**) { return E_NOTIMPL; }
  184417. HRESULT __stdcall GetContainer (LPOLECONTAINER* ppContainer) { *ppContainer = 0; return E_NOINTERFACE; }
  184418. HRESULT __stdcall ShowObject() { return S_OK; }
  184419. HRESULT __stdcall OnShowWindow (BOOL) { return E_NOTIMPL; }
  184420. HRESULT __stdcall RequestNewObjectLayout() { return E_NOTIMPL; }
  184421. juce_UseDebuggingNewOperator
  184422. };
  184423. static VoidArray activeXComps;
  184424. static HWND getHWND (const ActiveXControlComponent* const component)
  184425. {
  184426. HWND hwnd = 0;
  184427. const IID iid = IID_IOleWindow;
  184428. IOleWindow* const window = (IOleWindow*) component->queryInterface (&iid);
  184429. if (window != 0)
  184430. {
  184431. window->GetWindow (&hwnd);
  184432. window->Release();
  184433. }
  184434. return hwnd;
  184435. }
  184436. static void offerActiveXMouseEventToPeer (ComponentPeer* const peer, HWND hwnd, UINT message, LPARAM lParam)
  184437. {
  184438. RECT activeXRect, peerRect;
  184439. GetWindowRect (hwnd, &activeXRect);
  184440. GetWindowRect ((HWND) peer->getNativeHandle(), &peerRect);
  184441. const Point<int> mousePos (GET_X_LPARAM (lParam) + activeXRect.left - peerRect.left,
  184442. GET_Y_LPARAM (lParam) + activeXRect.top - peerRect.top);
  184443. const int64 mouseEventTime = Win32ComponentPeer::getMouseEventTime();
  184444. ModifierKeys::getCurrentModifiersRealtime(); // to update the mouse button flags
  184445. switch (message)
  184446. {
  184447. case WM_MOUSEMOVE:
  184448. case WM_LBUTTONDOWN:
  184449. case WM_MBUTTONDOWN:
  184450. case WM_RBUTTONDOWN:
  184451. case WM_LBUTTONUP:
  184452. case WM_MBUTTONUP:
  184453. case WM_RBUTTONUP:
  184454. peer->handleMouseEvent (0, mousePos, Win32ComponentPeer::currentModifiers, mouseEventTime);
  184455. break;
  184456. default:
  184457. break;
  184458. }
  184459. }
  184460. }
  184461. class ActiveXControlComponent::ActiveXControlData : public ComponentMovementWatcher
  184462. {
  184463. ActiveXControlComponent* const owner;
  184464. bool wasShowing;
  184465. public:
  184466. HWND controlHWND;
  184467. IStorage* storage;
  184468. IOleClientSite* clientSite;
  184469. IOleObject* control;
  184470. ActiveXControlData (HWND hwnd,
  184471. ActiveXControlComponent* const owner_)
  184472. : ComponentMovementWatcher (owner_),
  184473. owner (owner_),
  184474. wasShowing (owner_ != 0 && owner_->isShowing()),
  184475. controlHWND (0),
  184476. storage (new ActiveXHelpers::JuceIStorage()),
  184477. clientSite (new ActiveXHelpers::JuceIOleClientSite (hwnd)),
  184478. control (0)
  184479. {
  184480. }
  184481. ~ActiveXControlData()
  184482. {
  184483. if (control != 0)
  184484. {
  184485. control->Close (OLECLOSE_NOSAVE);
  184486. control->Release();
  184487. }
  184488. clientSite->Release();
  184489. storage->Release();
  184490. }
  184491. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  184492. {
  184493. Component* const topComp = owner->getTopLevelComponent();
  184494. if (topComp->getPeer() != 0)
  184495. {
  184496. const Point<int> pos (owner->relativePositionToOtherComponent (topComp, Point<int>()));
  184497. owner->setControlBounds (Rectangle<int> (pos.getX(), pos.getY(), owner->getWidth(), owner->getHeight()));
  184498. }
  184499. }
  184500. void componentPeerChanged()
  184501. {
  184502. const bool isShowingNow = owner->isShowing();
  184503. if (wasShowing != isShowingNow)
  184504. {
  184505. wasShowing = isShowingNow;
  184506. owner->setControlVisible (isShowingNow);
  184507. }
  184508. componentMovedOrResized (true, true);
  184509. }
  184510. void componentVisibilityChanged (Component&)
  184511. {
  184512. componentPeerChanged();
  184513. }
  184514. static bool doesWindowMatch (const ActiveXControlComponent* const ax, HWND hwnd)
  184515. {
  184516. return ((ActiveXControlData*) ax->control) != 0
  184517. && ((ActiveXControlData*) ax->control)->controlHWND == hwnd;
  184518. }
  184519. // intercepts events going to an activeX control, so we can sneakily use the mouse events
  184520. static LRESULT CALLBACK activeXHookWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  184521. {
  184522. for (int i = ActiveXHelpers::activeXComps.size(); --i >= 0;)
  184523. {
  184524. const ActiveXControlComponent* const ax = (const ActiveXControlComponent*) ActiveXHelpers::activeXComps.getUnchecked(i);
  184525. if (doesWindowMatch (ax, hwnd))
  184526. {
  184527. switch (message)
  184528. {
  184529. case WM_MOUSEMOVE:
  184530. case WM_LBUTTONDOWN:
  184531. case WM_MBUTTONDOWN:
  184532. case WM_RBUTTONDOWN:
  184533. case WM_LBUTTONUP:
  184534. case WM_MBUTTONUP:
  184535. case WM_RBUTTONUP:
  184536. case WM_LBUTTONDBLCLK:
  184537. case WM_MBUTTONDBLCLK:
  184538. case WM_RBUTTONDBLCLK:
  184539. if (ax->isShowing())
  184540. {
  184541. ComponentPeer* const peer = ax->getPeer();
  184542. if (peer != 0)
  184543. {
  184544. ActiveXHelpers::offerActiveXMouseEventToPeer (peer, hwnd, message, lParam);
  184545. if (! ax->areMouseEventsAllowed())
  184546. return 0;
  184547. }
  184548. }
  184549. break;
  184550. default:
  184551. break;
  184552. }
  184553. return CallWindowProc ((WNDPROC) (ax->originalWndProc), hwnd, message, wParam, lParam);
  184554. }
  184555. }
  184556. return DefWindowProc (hwnd, message, wParam, lParam);
  184557. }
  184558. };
  184559. ActiveXControlComponent::ActiveXControlComponent()
  184560. : originalWndProc (0),
  184561. control (0),
  184562. mouseEventsAllowed (true)
  184563. {
  184564. ActiveXHelpers::activeXComps.add (this);
  184565. }
  184566. ActiveXControlComponent::~ActiveXControlComponent()
  184567. {
  184568. deleteControl();
  184569. ActiveXHelpers::activeXComps.removeValue (this);
  184570. }
  184571. void ActiveXControlComponent::paint (Graphics& g)
  184572. {
  184573. if (control == 0)
  184574. g.fillAll (Colours::lightgrey);
  184575. }
  184576. bool ActiveXControlComponent::createControl (const void* controlIID)
  184577. {
  184578. deleteControl();
  184579. ComponentPeer* const peer = getPeer();
  184580. // the component must have already been added to a real window when you call this!
  184581. jassert (dynamic_cast <Win32ComponentPeer*> (peer) != 0);
  184582. if (dynamic_cast <Win32ComponentPeer*> (peer) != 0)
  184583. {
  184584. const Point<int> pos (relativePositionToOtherComponent (getTopLevelComponent(), Point<int>()));
  184585. HWND hwnd = (HWND) peer->getNativeHandle();
  184586. ScopedPointer <ActiveXControlData> info (new ActiveXControlData (hwnd, this));
  184587. HRESULT hr;
  184588. if ((hr = OleCreate (*(const IID*) controlIID, IID_IOleObject, 1 /*OLERENDER_DRAW*/, 0,
  184589. info->clientSite, info->storage,
  184590. (void**) &(info->control))) == S_OK)
  184591. {
  184592. info->control->SetHostNames (L"Juce", 0);
  184593. if (OleSetContainedObject (info->control, TRUE) == S_OK)
  184594. {
  184595. RECT rect;
  184596. rect.left = pos.getX();
  184597. rect.top = pos.getY();
  184598. rect.right = pos.getX() + getWidth();
  184599. rect.bottom = pos.getY() + getHeight();
  184600. if (info->control->DoVerb (OLEIVERB_SHOW, 0, info->clientSite, 0, hwnd, &rect) == S_OK)
  184601. {
  184602. control = info.release();
  184603. setControlBounds (Rectangle<int> (pos.getX(), pos.getY(), getWidth(), getHeight()));
  184604. ((ActiveXControlData*) control)->controlHWND = ActiveXHelpers::getHWND (this);
  184605. if (((ActiveXControlData*) control)->controlHWND != 0)
  184606. {
  184607. originalWndProc = (void*) (pointer_sized_int) GetWindowLongPtr ((HWND) ((ActiveXControlData*) control)->controlHWND, GWLP_WNDPROC);
  184608. SetWindowLongPtr ((HWND) ((ActiveXControlData*) control)->controlHWND, GWLP_WNDPROC, (LONG_PTR) ActiveXControlData::activeXHookWndProc);
  184609. }
  184610. return true;
  184611. }
  184612. }
  184613. }
  184614. }
  184615. return false;
  184616. }
  184617. void ActiveXControlComponent::deleteControl()
  184618. {
  184619. ActiveXControlData* const info = (ActiveXControlData*) control;
  184620. if (info != 0)
  184621. {
  184622. delete info;
  184623. control = 0;
  184624. originalWndProc = 0;
  184625. }
  184626. }
  184627. void* ActiveXControlComponent::queryInterface (const void* iid) const
  184628. {
  184629. ActiveXControlData* const info = (ActiveXControlData*) control;
  184630. void* result = 0;
  184631. if (info != 0 && info->control != 0
  184632. && info->control->QueryInterface (*(const IID*) iid, &result) == S_OK)
  184633. return result;
  184634. return 0;
  184635. }
  184636. void ActiveXControlComponent::setControlBounds (const Rectangle<int>& newBounds) const
  184637. {
  184638. HWND hwnd = ((ActiveXControlData*) control)->controlHWND;
  184639. if (hwnd != 0)
  184640. MoveWindow (hwnd, newBounds.getX(), newBounds.getY(), newBounds.getWidth(), newBounds.getHeight(), TRUE);
  184641. }
  184642. void ActiveXControlComponent::setControlVisible (const bool shouldBeVisible) const
  184643. {
  184644. HWND hwnd = ((ActiveXControlData*) control)->controlHWND;
  184645. if (hwnd != 0)
  184646. ShowWindow (hwnd, shouldBeVisible ? SW_SHOWNA : SW_HIDE);
  184647. }
  184648. void ActiveXControlComponent::setMouseEventsAllowed (const bool eventsCanReachControl)
  184649. {
  184650. mouseEventsAllowed = eventsCanReachControl;
  184651. }
  184652. #endif
  184653. /*** End of inlined file: juce_win32_ActiveXComponent.cpp ***/
  184654. /*** Start of inlined file: juce_win32_QuickTimeMovieComponent.cpp ***/
  184655. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184656. // compiled on its own).
  184657. #if JUCE_INCLUDED_FILE && JUCE_QUICKTIME
  184658. using namespace QTOLibrary;
  184659. using namespace QTOControlLib;
  184660. bool juce_OpenQuickTimeMovieFromStream (InputStream* input, Movie& movie, Handle& dataHandle);
  184661. static bool isQTAvailable = false;
  184662. class QuickTimeMovieComponent::Pimpl
  184663. {
  184664. public:
  184665. Pimpl() : dataHandle (0)
  184666. {
  184667. }
  184668. ~Pimpl()
  184669. {
  184670. clearHandle();
  184671. }
  184672. void clearHandle()
  184673. {
  184674. if (dataHandle != 0)
  184675. {
  184676. DisposeHandle (dataHandle);
  184677. dataHandle = 0;
  184678. }
  184679. }
  184680. IQTControlPtr qtControl;
  184681. IQTMoviePtr qtMovie;
  184682. Handle dataHandle;
  184683. };
  184684. QuickTimeMovieComponent::QuickTimeMovieComponent()
  184685. : movieLoaded (false),
  184686. controllerVisible (true)
  184687. {
  184688. pimpl = new Pimpl();
  184689. setMouseEventsAllowed (false);
  184690. }
  184691. QuickTimeMovieComponent::~QuickTimeMovieComponent()
  184692. {
  184693. closeMovie();
  184694. pimpl->qtControl = 0;
  184695. deleteControl();
  184696. pimpl = 0;
  184697. }
  184698. bool QuickTimeMovieComponent::isQuickTimeAvailable() throw()
  184699. {
  184700. if (! isQTAvailable)
  184701. isQTAvailable = (InitializeQTML (0) == noErr) && (EnterMovies() == noErr);
  184702. return isQTAvailable;
  184703. }
  184704. void QuickTimeMovieComponent::createControlIfNeeded()
  184705. {
  184706. if (isShowing() && ! isControlCreated())
  184707. {
  184708. const IID qtIID = __uuidof (QTControl);
  184709. if (createControl (&qtIID))
  184710. {
  184711. const IID qtInterfaceIID = __uuidof (IQTControl);
  184712. pimpl->qtControl = (IQTControl*) queryInterface (&qtInterfaceIID);
  184713. if (pimpl->qtControl != 0)
  184714. {
  184715. pimpl->qtControl->Release(); // it has one ref too many at this point
  184716. pimpl->qtControl->QuickTimeInitialize();
  184717. pimpl->qtControl->PutSizing (qtMovieFitsControl);
  184718. if (movieFile != File::nonexistent)
  184719. loadMovie (movieFile, controllerVisible);
  184720. }
  184721. }
  184722. }
  184723. }
  184724. bool QuickTimeMovieComponent::isControlCreated() const
  184725. {
  184726. return isControlOpen();
  184727. }
  184728. bool QuickTimeMovieComponent::loadMovie (InputStream* movieStream,
  184729. const bool isControllerVisible)
  184730. {
  184731. const ScopedPointer<InputStream> movieStreamDeleter (movieStream);
  184732. movieFile = File::nonexistent;
  184733. movieLoaded = false;
  184734. pimpl->qtMovie = 0;
  184735. controllerVisible = isControllerVisible;
  184736. createControlIfNeeded();
  184737. if (isControlCreated())
  184738. {
  184739. if (pimpl->qtControl != 0)
  184740. {
  184741. pimpl->qtControl->Put_MovieHandle (0);
  184742. pimpl->clearHandle();
  184743. Movie movie;
  184744. if (juce_OpenQuickTimeMovieFromStream (movieStream, movie, pimpl->dataHandle))
  184745. {
  184746. pimpl->qtControl->Put_MovieHandle ((long) (pointer_sized_int) movie);
  184747. pimpl->qtMovie = pimpl->qtControl->GetMovie();
  184748. if (pimpl->qtMovie != 0)
  184749. pimpl->qtMovie->PutMovieControllerType (isControllerVisible ? qtMovieControllerTypeStandard
  184750. : qtMovieControllerTypeNone);
  184751. }
  184752. if (movie == 0)
  184753. pimpl->clearHandle();
  184754. }
  184755. movieLoaded = (pimpl->qtMovie != 0);
  184756. }
  184757. else
  184758. {
  184759. // You're trying to open a movie when the control hasn't yet been created, probably because
  184760. // you've not yet added this component to a Window and made the whole component hierarchy visible.
  184761. jassertfalse
  184762. }
  184763. return movieLoaded;
  184764. }
  184765. void QuickTimeMovieComponent::closeMovie()
  184766. {
  184767. stop();
  184768. movieFile = File::nonexistent;
  184769. movieLoaded = false;
  184770. pimpl->qtMovie = 0;
  184771. if (pimpl->qtControl != 0)
  184772. pimpl->qtControl->Put_MovieHandle (0);
  184773. pimpl->clearHandle();
  184774. }
  184775. const File QuickTimeMovieComponent::getCurrentMovieFile() const
  184776. {
  184777. return movieFile;
  184778. }
  184779. bool QuickTimeMovieComponent::isMovieOpen() const
  184780. {
  184781. return movieLoaded;
  184782. }
  184783. double QuickTimeMovieComponent::getMovieDuration() const
  184784. {
  184785. if (pimpl->qtMovie != 0)
  184786. return pimpl->qtMovie->GetDuration() / (double) pimpl->qtMovie->GetTimeScale();
  184787. return 0.0;
  184788. }
  184789. void QuickTimeMovieComponent::getMovieNormalSize (int& width, int& height) const
  184790. {
  184791. if (pimpl->qtMovie != 0)
  184792. {
  184793. struct QTRECT r = pimpl->qtMovie->GetNaturalRect();
  184794. width = r.right - r.left;
  184795. height = r.bottom - r.top;
  184796. }
  184797. else
  184798. {
  184799. width = height = 0;
  184800. }
  184801. }
  184802. void QuickTimeMovieComponent::play()
  184803. {
  184804. if (pimpl->qtMovie != 0)
  184805. pimpl->qtMovie->Play();
  184806. }
  184807. void QuickTimeMovieComponent::stop()
  184808. {
  184809. if (pimpl->qtMovie != 0)
  184810. pimpl->qtMovie->Stop();
  184811. }
  184812. bool QuickTimeMovieComponent::isPlaying() const
  184813. {
  184814. return pimpl->qtMovie != 0 && pimpl->qtMovie->GetRate() != 0.0f;
  184815. }
  184816. void QuickTimeMovieComponent::setPosition (const double seconds)
  184817. {
  184818. if (pimpl->qtMovie != 0)
  184819. pimpl->qtMovie->PutTime ((long) (seconds * pimpl->qtMovie->GetTimeScale()));
  184820. }
  184821. double QuickTimeMovieComponent::getPosition() const
  184822. {
  184823. if (pimpl->qtMovie != 0)
  184824. return pimpl->qtMovie->GetTime() / (double) pimpl->qtMovie->GetTimeScale();
  184825. return 0.0;
  184826. }
  184827. void QuickTimeMovieComponent::setSpeed (const float newSpeed)
  184828. {
  184829. if (pimpl->qtMovie != 0)
  184830. pimpl->qtMovie->PutRate (newSpeed);
  184831. }
  184832. void QuickTimeMovieComponent::setMovieVolume (const float newVolume)
  184833. {
  184834. if (pimpl->qtMovie != 0)
  184835. {
  184836. pimpl->qtMovie->PutAudioVolume (newVolume);
  184837. pimpl->qtMovie->PutAudioMute (newVolume <= 0);
  184838. }
  184839. }
  184840. float QuickTimeMovieComponent::getMovieVolume() const
  184841. {
  184842. if (pimpl->qtMovie != 0)
  184843. return pimpl->qtMovie->GetAudioVolume();
  184844. return 0.0f;
  184845. }
  184846. void QuickTimeMovieComponent::setLooping (const bool shouldLoop)
  184847. {
  184848. if (pimpl->qtMovie != 0)
  184849. pimpl->qtMovie->PutLoop (shouldLoop);
  184850. }
  184851. bool QuickTimeMovieComponent::isLooping() const
  184852. {
  184853. return pimpl->qtMovie != 0 && pimpl->qtMovie->GetLoop();
  184854. }
  184855. bool QuickTimeMovieComponent::isControllerVisible() const
  184856. {
  184857. return controllerVisible;
  184858. }
  184859. void QuickTimeMovieComponent::parentHierarchyChanged()
  184860. {
  184861. createControlIfNeeded();
  184862. QTCompBaseClass::parentHierarchyChanged();
  184863. }
  184864. void QuickTimeMovieComponent::visibilityChanged()
  184865. {
  184866. createControlIfNeeded();
  184867. QTCompBaseClass::visibilityChanged();
  184868. }
  184869. void QuickTimeMovieComponent::paint (Graphics& g)
  184870. {
  184871. if (! isControlCreated())
  184872. g.fillAll (Colours::black);
  184873. }
  184874. static Handle createHandleDataRef (Handle dataHandle, const char* fileName)
  184875. {
  184876. Handle dataRef = 0;
  184877. OSStatus err = PtrToHand (&dataHandle, &dataRef, sizeof (Handle));
  184878. if (err == noErr)
  184879. {
  184880. Str255 suffix;
  184881. CharacterFunctions::copy ((char*) suffix, fileName, 128);
  184882. StringPtr name = suffix;
  184883. err = PtrAndHand (name, dataRef, name[0] + 1);
  184884. if (err == noErr)
  184885. {
  184886. long atoms[3];
  184887. atoms[0] = EndianU32_NtoB (3 * sizeof (long));
  184888. atoms[1] = EndianU32_NtoB (kDataRefExtensionMacOSFileType);
  184889. atoms[2] = EndianU32_NtoB (MovieFileType);
  184890. err = PtrAndHand (atoms, dataRef, 3 * sizeof (long));
  184891. if (err == noErr)
  184892. return dataRef;
  184893. }
  184894. DisposeHandle (dataRef);
  184895. }
  184896. return 0;
  184897. }
  184898. static CFStringRef juceStringToCFString (const String& s)
  184899. {
  184900. const int len = s.length();
  184901. const juce_wchar* const t = (const juce_wchar*) s;
  184902. HeapBlock <UniChar> temp (len + 2);
  184903. for (int i = 0; i <= len; ++i)
  184904. temp[i] = t[i];
  184905. return CFStringCreateWithCharacters (kCFAllocatorDefault, temp, len);
  184906. }
  184907. static bool openMovie (QTNewMoviePropertyElement* props, int prop, Movie& movie)
  184908. {
  184909. Boolean trueBool = true;
  184910. props[prop].propClass = kQTPropertyClass_MovieInstantiation;
  184911. props[prop].propID = kQTMovieInstantiationPropertyID_DontResolveDataRefs;
  184912. props[prop].propValueSize = sizeof (trueBool);
  184913. props[prop].propValueAddress = &trueBool;
  184914. ++prop;
  184915. props[prop].propClass = kQTPropertyClass_MovieInstantiation;
  184916. props[prop].propID = kQTMovieInstantiationPropertyID_AsyncOK;
  184917. props[prop].propValueSize = sizeof (trueBool);
  184918. props[prop].propValueAddress = &trueBool;
  184919. ++prop;
  184920. Boolean isActive = true;
  184921. props[prop].propClass = kQTPropertyClass_NewMovieProperty;
  184922. props[prop].propID = kQTNewMoviePropertyID_Active;
  184923. props[prop].propValueSize = sizeof (isActive);
  184924. props[prop].propValueAddress = &isActive;
  184925. ++prop;
  184926. MacSetPort (0);
  184927. jassert (prop <= 5);
  184928. OSStatus err = NewMovieFromProperties (prop, props, 0, 0, &movie);
  184929. return err == noErr;
  184930. }
  184931. bool juce_OpenQuickTimeMovieFromStream (InputStream* input, Movie& movie, Handle& dataHandle)
  184932. {
  184933. if (input == 0)
  184934. return false;
  184935. dataHandle = 0;
  184936. bool ok = false;
  184937. QTNewMoviePropertyElement props[5];
  184938. zeromem (props, sizeof (props));
  184939. int prop = 0;
  184940. DataReferenceRecord dr;
  184941. props[prop].propClass = kQTPropertyClass_DataLocation;
  184942. props[prop].propID = kQTDataLocationPropertyID_DataReference;
  184943. props[prop].propValueSize = sizeof (dr);
  184944. props[prop].propValueAddress = (void*) &dr;
  184945. ++prop;
  184946. FileInputStream* const fin = dynamic_cast <FileInputStream*> (input);
  184947. if (fin != 0)
  184948. {
  184949. CFStringRef filePath = juceStringToCFString (fin->getFile().getFullPathName());
  184950. QTNewDataReferenceFromFullPathCFString (filePath, (QTPathStyle) kQTNativeDefaultPathStyle, 0,
  184951. &dr.dataRef, &dr.dataRefType);
  184952. ok = openMovie (props, prop, movie);
  184953. DisposeHandle (dr.dataRef);
  184954. CFRelease (filePath);
  184955. }
  184956. else
  184957. {
  184958. // sanity-check because this currently needs to load the whole stream into memory..
  184959. jassert (input->getTotalLength() < 50 * 1024 * 1024);
  184960. dataHandle = NewHandle ((Size) input->getTotalLength());
  184961. HLock (dataHandle);
  184962. // read the entire stream into memory - this is a pain, but can't get it to work
  184963. // properly using a custom callback to supply the data.
  184964. input->read (*dataHandle, (int) input->getTotalLength());
  184965. HUnlock (dataHandle);
  184966. // different types to get QT to try. (We should really be a bit smarter here by
  184967. // working out in advance which one the stream contains, rather than just trying
  184968. // each one)
  184969. const char* const suffixesToTry[] = { "\04.mov", "\04.mp3",
  184970. "\04.avi", "\04.m4a" };
  184971. for (int i = 0; i < numElementsInArray (suffixesToTry) && ! ok; ++i)
  184972. {
  184973. dr.dataRef = createHandleDataRef (dataHandle, suffixesToTry [i]);
  184974. dr.dataRefType = HandleDataHandlerSubType;
  184975. ok = openMovie (props, prop, movie);
  184976. DisposeHandle (dr.dataRef);
  184977. }
  184978. }
  184979. return ok;
  184980. }
  184981. bool QuickTimeMovieComponent::loadMovie (const File& movieFile_,
  184982. const bool isControllerVisible)
  184983. {
  184984. const bool ok = loadMovie (static_cast <InputStream*> (movieFile_.createInputStream()), isControllerVisible);
  184985. movieFile = movieFile_;
  184986. return ok;
  184987. }
  184988. bool QuickTimeMovieComponent::loadMovie (const URL& movieURL,
  184989. const bool isControllerVisible)
  184990. {
  184991. return loadMovie (static_cast <InputStream*> (movieURL.createInputStream (false)), isControllerVisible);
  184992. }
  184993. void QuickTimeMovieComponent::goToStart()
  184994. {
  184995. setPosition (0.0);
  184996. }
  184997. void QuickTimeMovieComponent::setBoundsWithCorrectAspectRatio (const Rectangle<int>& spaceToFitWithin,
  184998. const RectanglePlacement& placement)
  184999. {
  185000. int normalWidth, normalHeight;
  185001. getMovieNormalSize (normalWidth, normalHeight);
  185002. if (normalWidth > 0 && normalHeight > 0 && ! spaceToFitWithin.isEmpty())
  185003. {
  185004. double x = 0.0, y = 0.0, w = normalWidth, h = normalHeight;
  185005. placement.applyTo (x, y, w, h,
  185006. spaceToFitWithin.getX(), spaceToFitWithin.getY(),
  185007. spaceToFitWithin.getWidth(), spaceToFitWithin.getHeight());
  185008. if (w > 0 && h > 0)
  185009. {
  185010. setBounds (roundToInt (x), roundToInt (y),
  185011. roundToInt (w), roundToInt (h));
  185012. }
  185013. }
  185014. else
  185015. {
  185016. setBounds (spaceToFitWithin);
  185017. }
  185018. }
  185019. #endif
  185020. /*** End of inlined file: juce_win32_QuickTimeMovieComponent.cpp ***/
  185021. /*** Start of inlined file: juce_win32_WebBrowserComponent.cpp ***/
  185022. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  185023. // compiled on its own).
  185024. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  185025. class WebBrowserComponentInternal : public ActiveXControlComponent
  185026. {
  185027. public:
  185028. WebBrowserComponentInternal()
  185029. : browser (0),
  185030. connectionPoint (0),
  185031. adviseCookie (0)
  185032. {
  185033. }
  185034. ~WebBrowserComponentInternal()
  185035. {
  185036. if (connectionPoint != 0)
  185037. connectionPoint->Unadvise (adviseCookie);
  185038. if (browser != 0)
  185039. browser->Release();
  185040. }
  185041. void createBrowser()
  185042. {
  185043. createControl (&CLSID_WebBrowser);
  185044. browser = (IWebBrowser2*) queryInterface (&IID_IWebBrowser2);
  185045. IConnectionPointContainer* connectionPointContainer = (IConnectionPointContainer*) queryInterface (&IID_IConnectionPointContainer);
  185046. if (connectionPointContainer != 0)
  185047. {
  185048. connectionPointContainer->FindConnectionPoint (DIID_DWebBrowserEvents2,
  185049. &connectionPoint);
  185050. if (connectionPoint != 0)
  185051. {
  185052. WebBrowserComponent* const owner = dynamic_cast <WebBrowserComponent*> (getParentComponent());
  185053. jassert (owner != 0);
  185054. EventHandler* handler = new EventHandler (owner);
  185055. connectionPoint->Advise (handler, &adviseCookie);
  185056. }
  185057. }
  185058. }
  185059. void goToURL (const String& url,
  185060. const StringArray* headers,
  185061. const MemoryBlock* postData)
  185062. {
  185063. if (browser != 0)
  185064. {
  185065. LPSAFEARRAY sa = 0;
  185066. VARIANT flags, frame, postDataVar, headersVar; // (_variant_t isn't available in all compilers)
  185067. VariantInit (&flags);
  185068. VariantInit (&frame);
  185069. VariantInit (&postDataVar);
  185070. VariantInit (&headersVar);
  185071. if (headers != 0)
  185072. {
  185073. V_VT (&headersVar) = VT_BSTR;
  185074. V_BSTR (&headersVar) = SysAllocString ((const tchar*) headers->joinIntoString ("\r\n"));
  185075. }
  185076. if (postData != 0 && postData->getSize() > 0)
  185077. {
  185078. LPSAFEARRAY sa = SafeArrayCreateVector (VT_UI1, 0, postData->getSize());
  185079. if (sa != 0)
  185080. {
  185081. void* data = 0;
  185082. SafeArrayAccessData (sa, &data);
  185083. jassert (data != 0);
  185084. if (data != 0)
  185085. {
  185086. postData->copyTo (data, 0, postData->getSize());
  185087. SafeArrayUnaccessData (sa);
  185088. VARIANT postDataVar2;
  185089. VariantInit (&postDataVar2);
  185090. V_VT (&postDataVar2) = VT_ARRAY | VT_UI1;
  185091. V_ARRAY (&postDataVar2) = sa;
  185092. postDataVar = postDataVar2;
  185093. }
  185094. }
  185095. }
  185096. browser->Navigate ((BSTR) (const OLECHAR*) url,
  185097. &flags, &frame,
  185098. &postDataVar, &headersVar);
  185099. if (sa != 0)
  185100. SafeArrayDestroy (sa);
  185101. VariantClear (&flags);
  185102. VariantClear (&frame);
  185103. VariantClear (&postDataVar);
  185104. VariantClear (&headersVar);
  185105. }
  185106. }
  185107. IWebBrowser2* browser;
  185108. juce_UseDebuggingNewOperator
  185109. private:
  185110. IConnectionPoint* connectionPoint;
  185111. DWORD adviseCookie;
  185112. class EventHandler : public IDispatch,
  185113. public ComponentMovementWatcher
  185114. {
  185115. public:
  185116. EventHandler (WebBrowserComponent* owner_)
  185117. : ComponentMovementWatcher (owner_),
  185118. owner (owner_),
  185119. refCount (0)
  185120. {
  185121. }
  185122. ~EventHandler()
  185123. {
  185124. }
  185125. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  185126. {
  185127. if (id == IID_IUnknown || id == IID_IDispatch || id == DIID_DWebBrowserEvents2)
  185128. {
  185129. AddRef();
  185130. *result = this;
  185131. return S_OK;
  185132. }
  185133. *result = 0;
  185134. return E_NOINTERFACE;
  185135. }
  185136. ULONG __stdcall AddRef() { return ++refCount; }
  185137. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  185138. HRESULT __stdcall GetTypeInfoCount (UINT __RPC_FAR*) { return E_NOTIMPL; }
  185139. HRESULT __stdcall GetTypeInfo (UINT, LCID, ITypeInfo __RPC_FAR *__RPC_FAR*) { return E_NOTIMPL; }
  185140. HRESULT __stdcall GetIDsOfNames (REFIID, LPOLESTR __RPC_FAR*, UINT, LCID, DISPID __RPC_FAR*) { return E_NOTIMPL; }
  185141. HRESULT __stdcall Invoke (DISPID dispIdMember, REFIID /*riid*/, LCID /*lcid*/,
  185142. WORD /*wFlags*/, DISPPARAMS __RPC_FAR* pDispParams,
  185143. VARIANT __RPC_FAR* /*pVarResult*/, EXCEPINFO __RPC_FAR* /*pExcepInfo*/,
  185144. UINT __RPC_FAR* /*puArgErr*/)
  185145. {
  185146. switch (dispIdMember)
  185147. {
  185148. case DISPID_BEFORENAVIGATE2:
  185149. {
  185150. VARIANT* const vurl = pDispParams->rgvarg[5].pvarVal;
  185151. String url;
  185152. if ((vurl->vt & VT_BYREF) != 0)
  185153. url = *vurl->pbstrVal;
  185154. else
  185155. url = vurl->bstrVal;
  185156. *pDispParams->rgvarg->pboolVal
  185157. = owner->pageAboutToLoad (url) ? VARIANT_FALSE
  185158. : VARIANT_TRUE;
  185159. return S_OK;
  185160. }
  185161. default:
  185162. break;
  185163. }
  185164. return E_NOTIMPL;
  185165. }
  185166. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/) {}
  185167. void componentPeerChanged() {}
  185168. void componentVisibilityChanged (Component&)
  185169. {
  185170. owner->visibilityChanged();
  185171. }
  185172. juce_UseDebuggingNewOperator
  185173. private:
  185174. WebBrowserComponent* const owner;
  185175. int refCount;
  185176. EventHandler (const EventHandler&);
  185177. EventHandler& operator= (const EventHandler&);
  185178. };
  185179. };
  185180. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  185181. : browser (0),
  185182. blankPageShown (false),
  185183. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  185184. {
  185185. setOpaque (true);
  185186. addAndMakeVisible (browser = new WebBrowserComponentInternal());
  185187. }
  185188. WebBrowserComponent::~WebBrowserComponent()
  185189. {
  185190. delete browser;
  185191. }
  185192. void WebBrowserComponent::goToURL (const String& url,
  185193. const StringArray* headers,
  185194. const MemoryBlock* postData)
  185195. {
  185196. lastURL = url;
  185197. lastHeaders.clear();
  185198. if (headers != 0)
  185199. lastHeaders = *headers;
  185200. lastPostData.setSize (0);
  185201. if (postData != 0)
  185202. lastPostData = *postData;
  185203. blankPageShown = false;
  185204. browser->goToURL (url, headers, postData);
  185205. }
  185206. void WebBrowserComponent::stop()
  185207. {
  185208. if (browser->browser != 0)
  185209. browser->browser->Stop();
  185210. }
  185211. void WebBrowserComponent::goBack()
  185212. {
  185213. lastURL = String::empty;
  185214. blankPageShown = false;
  185215. if (browser->browser != 0)
  185216. browser->browser->GoBack();
  185217. }
  185218. void WebBrowserComponent::goForward()
  185219. {
  185220. lastURL = String::empty;
  185221. if (browser->browser != 0)
  185222. browser->browser->GoForward();
  185223. }
  185224. void WebBrowserComponent::refresh()
  185225. {
  185226. if (browser->browser != 0)
  185227. browser->browser->Refresh();
  185228. }
  185229. void WebBrowserComponent::paint (Graphics& g)
  185230. {
  185231. if (browser->browser == 0)
  185232. g.fillAll (Colours::white);
  185233. }
  185234. void WebBrowserComponent::checkWindowAssociation()
  185235. {
  185236. if (isShowing())
  185237. {
  185238. if (browser->browser == 0 && getPeer() != 0)
  185239. {
  185240. browser->createBrowser();
  185241. reloadLastURL();
  185242. }
  185243. else
  185244. {
  185245. if (blankPageShown)
  185246. goBack();
  185247. }
  185248. }
  185249. else
  185250. {
  185251. if (browser != 0 && unloadPageWhenBrowserIsHidden && ! blankPageShown)
  185252. {
  185253. // when the component becomes invisible, some stuff like flash
  185254. // carries on playing audio, so we need to force it onto a blank
  185255. // page to avoid this..
  185256. blankPageShown = true;
  185257. browser->goToURL ("about:blank", 0, 0);
  185258. }
  185259. }
  185260. }
  185261. void WebBrowserComponent::reloadLastURL()
  185262. {
  185263. if (lastURL.isNotEmpty())
  185264. {
  185265. goToURL (lastURL, &lastHeaders, &lastPostData);
  185266. lastURL = String::empty;
  185267. }
  185268. }
  185269. void WebBrowserComponent::parentHierarchyChanged()
  185270. {
  185271. checkWindowAssociation();
  185272. }
  185273. void WebBrowserComponent::resized()
  185274. {
  185275. browser->setSize (getWidth(), getHeight());
  185276. }
  185277. void WebBrowserComponent::visibilityChanged()
  185278. {
  185279. checkWindowAssociation();
  185280. }
  185281. bool WebBrowserComponent::pageAboutToLoad (const String&)
  185282. {
  185283. return true;
  185284. }
  185285. #endif
  185286. /*** End of inlined file: juce_win32_WebBrowserComponent.cpp ***/
  185287. /*** Start of inlined file: juce_win32_OpenGLComponent.cpp ***/
  185288. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  185289. // compiled on its own).
  185290. #if JUCE_INCLUDED_FILE && JUCE_OPENGL
  185291. #define WGL_EXT_FUNCTION_INIT(extType, extFunc) \
  185292. ((extFunc = (extType) wglGetProcAddress (#extFunc)) != 0)
  185293. typedef const char* (WINAPI* PFNWGLGETEXTENSIONSSTRINGARBPROC) (HDC hdc);
  185294. typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBIVARBPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues);
  185295. typedef BOOL (WINAPI * PFNWGLCHOOSEPIXELFORMATARBPROC) (HDC hdc, const int* piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats);
  185296. typedef BOOL (WINAPI * PFNWGLSWAPINTERVALEXTPROC) (int interval);
  185297. typedef int (WINAPI * PFNWGLGETSWAPINTERVALEXTPROC) (void);
  185298. #define WGL_NUMBER_PIXEL_FORMATS_ARB 0x2000
  185299. #define WGL_DRAW_TO_WINDOW_ARB 0x2001
  185300. #define WGL_ACCELERATION_ARB 0x2003
  185301. #define WGL_SWAP_METHOD_ARB 0x2007
  185302. #define WGL_SUPPORT_OPENGL_ARB 0x2010
  185303. #define WGL_PIXEL_TYPE_ARB 0x2013
  185304. #define WGL_DOUBLE_BUFFER_ARB 0x2011
  185305. #define WGL_COLOR_BITS_ARB 0x2014
  185306. #define WGL_RED_BITS_ARB 0x2015
  185307. #define WGL_GREEN_BITS_ARB 0x2017
  185308. #define WGL_BLUE_BITS_ARB 0x2019
  185309. #define WGL_ALPHA_BITS_ARB 0x201B
  185310. #define WGL_DEPTH_BITS_ARB 0x2022
  185311. #define WGL_STENCIL_BITS_ARB 0x2023
  185312. #define WGL_FULL_ACCELERATION_ARB 0x2027
  185313. #define WGL_ACCUM_RED_BITS_ARB 0x201E
  185314. #define WGL_ACCUM_GREEN_BITS_ARB 0x201F
  185315. #define WGL_ACCUM_BLUE_BITS_ARB 0x2020
  185316. #define WGL_ACCUM_ALPHA_BITS_ARB 0x2021
  185317. #define WGL_STEREO_ARB 0x2012
  185318. #define WGL_SAMPLE_BUFFERS_ARB 0x2041
  185319. #define WGL_SAMPLES_ARB 0x2042
  185320. #define WGL_TYPE_RGBA_ARB 0x202B
  185321. static void getWglExtensions (HDC dc, StringArray& result) throw()
  185322. {
  185323. PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB = 0;
  185324. if (WGL_EXT_FUNCTION_INIT (PFNWGLGETEXTENSIONSSTRINGARBPROC, wglGetExtensionsStringARB))
  185325. result.addTokens (String (wglGetExtensionsStringARB (dc)), false);
  185326. else
  185327. jassertfalse // If this fails, it may be because you didn't activate the openGL context
  185328. }
  185329. class WindowedGLContext : public OpenGLContext
  185330. {
  185331. public:
  185332. WindowedGLContext (Component* const component_,
  185333. HGLRC contextToShareWith,
  185334. const OpenGLPixelFormat& pixelFormat)
  185335. : renderContext (0),
  185336. nativeWindow (0),
  185337. dc (0),
  185338. component (component_)
  185339. {
  185340. jassert (component != 0);
  185341. createNativeWindow();
  185342. // Use a default pixel format that should be supported everywhere
  185343. PIXELFORMATDESCRIPTOR pfd;
  185344. zerostruct (pfd);
  185345. pfd.nSize = sizeof (pfd);
  185346. pfd.nVersion = 1;
  185347. pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
  185348. pfd.iPixelType = PFD_TYPE_RGBA;
  185349. pfd.cColorBits = 24;
  185350. pfd.cDepthBits = 16;
  185351. const int format = ChoosePixelFormat (dc, &pfd);
  185352. if (format != 0)
  185353. SetPixelFormat (dc, format, &pfd);
  185354. renderContext = wglCreateContext (dc);
  185355. makeActive();
  185356. setPixelFormat (pixelFormat);
  185357. if (contextToShareWith != 0 && renderContext != 0)
  185358. wglShareLists (contextToShareWith, renderContext);
  185359. }
  185360. ~WindowedGLContext()
  185361. {
  185362. makeInactive();
  185363. wglDeleteContext (renderContext);
  185364. ReleaseDC ((HWND) nativeWindow->getNativeHandle(), dc);
  185365. delete nativeWindow;
  185366. }
  185367. bool makeActive() const throw()
  185368. {
  185369. jassert (renderContext != 0);
  185370. return wglMakeCurrent (dc, renderContext) != 0;
  185371. }
  185372. bool makeInactive() const throw()
  185373. {
  185374. return (! isActive()) || (wglMakeCurrent (0, 0) != 0);
  185375. }
  185376. bool isActive() const throw()
  185377. {
  185378. return wglGetCurrentContext() == renderContext;
  185379. }
  185380. const OpenGLPixelFormat getPixelFormat() const
  185381. {
  185382. OpenGLPixelFormat pf;
  185383. makeActive();
  185384. StringArray availableExtensions;
  185385. getWglExtensions (dc, availableExtensions);
  185386. fillInPixelFormatDetails (GetPixelFormat (dc), pf, availableExtensions);
  185387. return pf;
  185388. }
  185389. void* getRawContext() const throw()
  185390. {
  185391. return renderContext;
  185392. }
  185393. bool setPixelFormat (const OpenGLPixelFormat& pixelFormat)
  185394. {
  185395. makeActive();
  185396. PIXELFORMATDESCRIPTOR pfd;
  185397. zerostruct (pfd);
  185398. pfd.nSize = sizeof (pfd);
  185399. pfd.nVersion = 1;
  185400. pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER;
  185401. pfd.iPixelType = PFD_TYPE_RGBA;
  185402. pfd.iLayerType = PFD_MAIN_PLANE;
  185403. pfd.cColorBits = (BYTE) (pixelFormat.redBits + pixelFormat.greenBits + pixelFormat.blueBits);
  185404. pfd.cRedBits = (BYTE) pixelFormat.redBits;
  185405. pfd.cGreenBits = (BYTE) pixelFormat.greenBits;
  185406. pfd.cBlueBits = (BYTE) pixelFormat.blueBits;
  185407. pfd.cAlphaBits = (BYTE) pixelFormat.alphaBits;
  185408. pfd.cDepthBits = (BYTE) pixelFormat.depthBufferBits;
  185409. pfd.cStencilBits = (BYTE) pixelFormat.stencilBufferBits;
  185410. pfd.cAccumBits = (BYTE) (pixelFormat.accumulationBufferRedBits + pixelFormat.accumulationBufferGreenBits
  185411. + pixelFormat.accumulationBufferBlueBits + pixelFormat.accumulationBufferAlphaBits);
  185412. pfd.cAccumRedBits = (BYTE) pixelFormat.accumulationBufferRedBits;
  185413. pfd.cAccumGreenBits = (BYTE) pixelFormat.accumulationBufferGreenBits;
  185414. pfd.cAccumBlueBits = (BYTE) pixelFormat.accumulationBufferBlueBits;
  185415. pfd.cAccumAlphaBits = (BYTE) pixelFormat.accumulationBufferAlphaBits;
  185416. int format = 0;
  185417. PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB = 0;
  185418. StringArray availableExtensions;
  185419. getWglExtensions (dc, availableExtensions);
  185420. if (availableExtensions.contains ("WGL_ARB_pixel_format")
  185421. && WGL_EXT_FUNCTION_INIT (PFNWGLCHOOSEPIXELFORMATARBPROC, wglChoosePixelFormatARB))
  185422. {
  185423. int attributes[64];
  185424. int n = 0;
  185425. attributes[n++] = WGL_DRAW_TO_WINDOW_ARB;
  185426. attributes[n++] = GL_TRUE;
  185427. attributes[n++] = WGL_SUPPORT_OPENGL_ARB;
  185428. attributes[n++] = GL_TRUE;
  185429. attributes[n++] = WGL_ACCELERATION_ARB;
  185430. attributes[n++] = WGL_FULL_ACCELERATION_ARB;
  185431. attributes[n++] = WGL_DOUBLE_BUFFER_ARB;
  185432. attributes[n++] = GL_TRUE;
  185433. attributes[n++] = WGL_PIXEL_TYPE_ARB;
  185434. attributes[n++] = WGL_TYPE_RGBA_ARB;
  185435. attributes[n++] = WGL_COLOR_BITS_ARB;
  185436. attributes[n++] = pfd.cColorBits;
  185437. attributes[n++] = WGL_RED_BITS_ARB;
  185438. attributes[n++] = pixelFormat.redBits;
  185439. attributes[n++] = WGL_GREEN_BITS_ARB;
  185440. attributes[n++] = pixelFormat.greenBits;
  185441. attributes[n++] = WGL_BLUE_BITS_ARB;
  185442. attributes[n++] = pixelFormat.blueBits;
  185443. attributes[n++] = WGL_ALPHA_BITS_ARB;
  185444. attributes[n++] = pixelFormat.alphaBits;
  185445. attributes[n++] = WGL_DEPTH_BITS_ARB;
  185446. attributes[n++] = pixelFormat.depthBufferBits;
  185447. if (pixelFormat.stencilBufferBits > 0)
  185448. {
  185449. attributes[n++] = WGL_STENCIL_BITS_ARB;
  185450. attributes[n++] = pixelFormat.stencilBufferBits;
  185451. }
  185452. attributes[n++] = WGL_ACCUM_RED_BITS_ARB;
  185453. attributes[n++] = pixelFormat.accumulationBufferRedBits;
  185454. attributes[n++] = WGL_ACCUM_GREEN_BITS_ARB;
  185455. attributes[n++] = pixelFormat.accumulationBufferGreenBits;
  185456. attributes[n++] = WGL_ACCUM_BLUE_BITS_ARB;
  185457. attributes[n++] = pixelFormat.accumulationBufferBlueBits;
  185458. attributes[n++] = WGL_ACCUM_ALPHA_BITS_ARB;
  185459. attributes[n++] = pixelFormat.accumulationBufferAlphaBits;
  185460. if (availableExtensions.contains ("WGL_ARB_multisample")
  185461. && pixelFormat.fullSceneAntiAliasingNumSamples > 0)
  185462. {
  185463. attributes[n++] = WGL_SAMPLE_BUFFERS_ARB;
  185464. attributes[n++] = 1;
  185465. attributes[n++] = WGL_SAMPLES_ARB;
  185466. attributes[n++] = pixelFormat.fullSceneAntiAliasingNumSamples;
  185467. }
  185468. attributes[n++] = 0;
  185469. UINT formatsCount;
  185470. const BOOL ok = wglChoosePixelFormatARB (dc, attributes, 0, 1, &format, &formatsCount);
  185471. (void) ok;
  185472. jassert (ok);
  185473. }
  185474. else
  185475. {
  185476. format = ChoosePixelFormat (dc, &pfd);
  185477. }
  185478. if (format != 0)
  185479. {
  185480. makeInactive();
  185481. // win32 can't change the pixel format of a window, so need to delete the
  185482. // old one and create a new one..
  185483. jassert (nativeWindow != 0);
  185484. ReleaseDC ((HWND) nativeWindow->getNativeHandle(), dc);
  185485. delete nativeWindow;
  185486. createNativeWindow();
  185487. if (SetPixelFormat (dc, format, &pfd))
  185488. {
  185489. wglDeleteContext (renderContext);
  185490. renderContext = wglCreateContext (dc);
  185491. jassert (renderContext != 0);
  185492. return renderContext != 0;
  185493. }
  185494. }
  185495. return false;
  185496. }
  185497. void updateWindowPosition (int x, int y, int w, int h, int)
  185498. {
  185499. SetWindowPos ((HWND) nativeWindow->getNativeHandle(), 0,
  185500. x, y, w, h,
  185501. SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  185502. }
  185503. void repaint()
  185504. {
  185505. const Rectangle<int> bounds (nativeWindow->getBounds());
  185506. nativeWindow->repaint (0, 0, bounds.getWidth(), bounds.getHeight());
  185507. }
  185508. void swapBuffers()
  185509. {
  185510. SwapBuffers (dc);
  185511. }
  185512. bool setSwapInterval (const int numFramesPerSwap)
  185513. {
  185514. makeActive();
  185515. StringArray availableExtensions;
  185516. getWglExtensions (dc, availableExtensions);
  185517. PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = 0;
  185518. return availableExtensions.contains ("WGL_EXT_swap_control")
  185519. && WGL_EXT_FUNCTION_INIT (PFNWGLSWAPINTERVALEXTPROC, wglSwapIntervalEXT)
  185520. && wglSwapIntervalEXT (numFramesPerSwap) != FALSE;
  185521. }
  185522. int getSwapInterval() const
  185523. {
  185524. makeActive();
  185525. StringArray availableExtensions;
  185526. getWglExtensions (dc, availableExtensions);
  185527. PFNWGLGETSWAPINTERVALEXTPROC wglGetSwapIntervalEXT = 0;
  185528. if (availableExtensions.contains ("WGL_EXT_swap_control")
  185529. && WGL_EXT_FUNCTION_INIT (PFNWGLGETSWAPINTERVALEXTPROC, wglGetSwapIntervalEXT))
  185530. return wglGetSwapIntervalEXT();
  185531. return 0;
  185532. }
  185533. void findAlternativeOpenGLPixelFormats (OwnedArray <OpenGLPixelFormat>& results)
  185534. {
  185535. jassert (isActive());
  185536. StringArray availableExtensions;
  185537. getWglExtensions (dc, availableExtensions);
  185538. PFNWGLGETPIXELFORMATATTRIBIVARBPROC wglGetPixelFormatAttribivARB = 0;
  185539. int numTypes = 0;
  185540. if (availableExtensions.contains("WGL_ARB_pixel_format")
  185541. && WGL_EXT_FUNCTION_INIT (PFNWGLGETPIXELFORMATATTRIBIVARBPROC, wglGetPixelFormatAttribivARB))
  185542. {
  185543. int attributes = WGL_NUMBER_PIXEL_FORMATS_ARB;
  185544. if (! wglGetPixelFormatAttribivARB (dc, 1, 0, 1, &attributes, &numTypes))
  185545. jassertfalse
  185546. }
  185547. else
  185548. {
  185549. numTypes = DescribePixelFormat (dc, 0, 0, 0);
  185550. }
  185551. OpenGLPixelFormat pf;
  185552. for (int i = 0; i < numTypes; ++i)
  185553. {
  185554. if (fillInPixelFormatDetails (i + 1, pf, availableExtensions))
  185555. {
  185556. bool alreadyListed = false;
  185557. for (int j = results.size(); --j >= 0;)
  185558. if (pf == *results.getUnchecked(j))
  185559. alreadyListed = true;
  185560. if (! alreadyListed)
  185561. results.add (new OpenGLPixelFormat (pf));
  185562. }
  185563. }
  185564. }
  185565. void* getNativeWindowHandle() const
  185566. {
  185567. return nativeWindow != 0 ? nativeWindow->getNativeHandle() : 0;
  185568. }
  185569. juce_UseDebuggingNewOperator
  185570. HGLRC renderContext;
  185571. private:
  185572. Win32ComponentPeer* nativeWindow;
  185573. Component* const component;
  185574. HDC dc;
  185575. void createNativeWindow()
  185576. {
  185577. nativeWindow = new Win32ComponentPeer (component, 0);
  185578. nativeWindow->dontRepaint = true;
  185579. nativeWindow->setVisible (true);
  185580. HWND hwnd = (HWND) nativeWindow->getNativeHandle();
  185581. Win32ComponentPeer* const peer = dynamic_cast <Win32ComponentPeer*> (component->getTopLevelComponent()->getPeer());
  185582. if (peer != 0)
  185583. {
  185584. SetParent (hwnd, (HWND) peer->getNativeHandle());
  185585. juce_setWindowStyleBit (hwnd, GWL_STYLE, WS_CHILD, true);
  185586. juce_setWindowStyleBit (hwnd, GWL_STYLE, WS_POPUP, false);
  185587. }
  185588. dc = GetDC (hwnd);
  185589. }
  185590. bool fillInPixelFormatDetails (const int pixelFormatIndex,
  185591. OpenGLPixelFormat& result,
  185592. const StringArray& availableExtensions) const throw()
  185593. {
  185594. PFNWGLGETPIXELFORMATATTRIBIVARBPROC wglGetPixelFormatAttribivARB = 0;
  185595. if (availableExtensions.contains ("WGL_ARB_pixel_format")
  185596. && WGL_EXT_FUNCTION_INIT (PFNWGLGETPIXELFORMATATTRIBIVARBPROC, wglGetPixelFormatAttribivARB))
  185597. {
  185598. int attributes[32];
  185599. int numAttributes = 0;
  185600. attributes[numAttributes++] = WGL_DRAW_TO_WINDOW_ARB;
  185601. attributes[numAttributes++] = WGL_SUPPORT_OPENGL_ARB;
  185602. attributes[numAttributes++] = WGL_ACCELERATION_ARB;
  185603. attributes[numAttributes++] = WGL_DOUBLE_BUFFER_ARB;
  185604. attributes[numAttributes++] = WGL_PIXEL_TYPE_ARB;
  185605. attributes[numAttributes++] = WGL_RED_BITS_ARB;
  185606. attributes[numAttributes++] = WGL_GREEN_BITS_ARB;
  185607. attributes[numAttributes++] = WGL_BLUE_BITS_ARB;
  185608. attributes[numAttributes++] = WGL_ALPHA_BITS_ARB;
  185609. attributes[numAttributes++] = WGL_DEPTH_BITS_ARB;
  185610. attributes[numAttributes++] = WGL_STENCIL_BITS_ARB;
  185611. attributes[numAttributes++] = WGL_ACCUM_RED_BITS_ARB;
  185612. attributes[numAttributes++] = WGL_ACCUM_GREEN_BITS_ARB;
  185613. attributes[numAttributes++] = WGL_ACCUM_BLUE_BITS_ARB;
  185614. attributes[numAttributes++] = WGL_ACCUM_ALPHA_BITS_ARB;
  185615. if (availableExtensions.contains ("WGL_ARB_multisample"))
  185616. attributes[numAttributes++] = WGL_SAMPLES_ARB;
  185617. int values[32];
  185618. zeromem (values, sizeof (values));
  185619. if (wglGetPixelFormatAttribivARB (dc, pixelFormatIndex, 0, numAttributes, attributes, values))
  185620. {
  185621. int n = 0;
  185622. bool isValidFormat = (values[n++] == GL_TRUE); // WGL_DRAW_TO_WINDOW_ARB
  185623. isValidFormat = (values[n++] == GL_TRUE) && isValidFormat; // WGL_SUPPORT_OPENGL_ARB
  185624. isValidFormat = (values[n++] == WGL_FULL_ACCELERATION_ARB) && isValidFormat; // WGL_ACCELERATION_ARB
  185625. isValidFormat = (values[n++] == GL_TRUE) && isValidFormat; // WGL_DOUBLE_BUFFER_ARB:
  185626. isValidFormat = (values[n++] == WGL_TYPE_RGBA_ARB) && isValidFormat; // WGL_PIXEL_TYPE_ARB
  185627. result.redBits = values[n++]; // WGL_RED_BITS_ARB
  185628. result.greenBits = values[n++]; // WGL_GREEN_BITS_ARB
  185629. result.blueBits = values[n++]; // WGL_BLUE_BITS_ARB
  185630. result.alphaBits = values[n++]; // WGL_ALPHA_BITS_ARB
  185631. result.depthBufferBits = values[n++]; // WGL_DEPTH_BITS_ARB
  185632. result.stencilBufferBits = values[n++]; // WGL_STENCIL_BITS_ARB
  185633. result.accumulationBufferRedBits = values[n++]; // WGL_ACCUM_RED_BITS_ARB
  185634. result.accumulationBufferGreenBits = values[n++]; // WGL_ACCUM_GREEN_BITS_ARB
  185635. result.accumulationBufferBlueBits = values[n++]; // WGL_ACCUM_BLUE_BITS_ARB
  185636. result.accumulationBufferAlphaBits = values[n++]; // WGL_ACCUM_ALPHA_BITS_ARB
  185637. result.fullSceneAntiAliasingNumSamples = (uint8) values[n++]; // WGL_SAMPLES_ARB
  185638. return isValidFormat;
  185639. }
  185640. else
  185641. {
  185642. jassertfalse
  185643. }
  185644. }
  185645. else
  185646. {
  185647. PIXELFORMATDESCRIPTOR pfd;
  185648. if (DescribePixelFormat (dc, pixelFormatIndex, sizeof (pfd), &pfd))
  185649. {
  185650. result.redBits = pfd.cRedBits;
  185651. result.greenBits = pfd.cGreenBits;
  185652. result.blueBits = pfd.cBlueBits;
  185653. result.alphaBits = pfd.cAlphaBits;
  185654. result.depthBufferBits = pfd.cDepthBits;
  185655. result.stencilBufferBits = pfd.cStencilBits;
  185656. result.accumulationBufferRedBits = pfd.cAccumRedBits;
  185657. result.accumulationBufferGreenBits = pfd.cAccumGreenBits;
  185658. result.accumulationBufferBlueBits = pfd.cAccumBlueBits;
  185659. result.accumulationBufferAlphaBits = pfd.cAccumAlphaBits;
  185660. result.fullSceneAntiAliasingNumSamples = 0;
  185661. return true;
  185662. }
  185663. else
  185664. {
  185665. jassertfalse
  185666. }
  185667. }
  185668. return false;
  185669. }
  185670. WindowedGLContext (const WindowedGLContext&);
  185671. WindowedGLContext& operator= (const WindowedGLContext&);
  185672. };
  185673. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  185674. const OpenGLPixelFormat& pixelFormat,
  185675. const OpenGLContext* const contextToShareWith)
  185676. {
  185677. WindowedGLContext* c = new WindowedGLContext (component,
  185678. contextToShareWith != 0 ? (HGLRC) contextToShareWith->getRawContext() : 0,
  185679. pixelFormat);
  185680. if (c->renderContext == 0)
  185681. deleteAndZero (c);
  185682. return c;
  185683. }
  185684. void* OpenGLComponent::getNativeWindowHandle() const
  185685. {
  185686. return context != 0 ? ((WindowedGLContext*) context)->getNativeWindowHandle() : 0;
  185687. }
  185688. void juce_glViewport (const int w, const int h)
  185689. {
  185690. glViewport (0, 0, w, h);
  185691. }
  185692. void OpenGLPixelFormat::getAvailablePixelFormats (Component* component,
  185693. OwnedArray <OpenGLPixelFormat>& results)
  185694. {
  185695. Component tempComp;
  185696. {
  185697. WindowedGLContext wc (component, 0, OpenGLPixelFormat (8, 8, 16, 0));
  185698. wc.makeActive();
  185699. wc.findAlternativeOpenGLPixelFormats (results);
  185700. }
  185701. }
  185702. #endif
  185703. /*** End of inlined file: juce_win32_OpenGLComponent.cpp ***/
  185704. /*** Start of inlined file: juce_win32_AudioCDReader.cpp ***/
  185705. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  185706. // compiled on its own).
  185707. #if JUCE_INCLUDED_FILE
  185708. #if JUCE_USE_CDREADER
  185709. namespace CDReaderHelpers
  185710. {
  185711. //***************************************************************************
  185712. // %%% TARGET STATUS VALUES %%%
  185713. //***************************************************************************
  185714. #define STATUS_GOOD 0x00 // Status Good
  185715. #define STATUS_CHKCOND 0x02 // Check Condition
  185716. #define STATUS_CONDMET 0x04 // Condition Met
  185717. #define STATUS_BUSY 0x08 // Busy
  185718. #define STATUS_INTERM 0x10 // Intermediate
  185719. #define STATUS_INTCDMET 0x14 // Intermediate-condition met
  185720. #define STATUS_RESCONF 0x18 // Reservation conflict
  185721. #define STATUS_COMTERM 0x22 // Command Terminated
  185722. #define STATUS_QFULL 0x28 // Queue full
  185723. //***************************************************************************
  185724. // %%% SCSI MISCELLANEOUS EQUATES %%%
  185725. //***************************************************************************
  185726. #define MAXLUN 7 // Maximum Logical Unit Id
  185727. #define MAXTARG 7 // Maximum Target Id
  185728. #define MAX_SCSI_LUNS 64 // Maximum Number of SCSI LUNs
  185729. #define MAX_NUM_HA 8 // Maximum Number of SCSI HA's
  185730. //***************************************************************************
  185731. // %%% Commands for all Device Types %%%
  185732. //***************************************************************************
  185733. #define SCSI_CHANGE_DEF 0x40 // Change Definition (Optional)
  185734. #define SCSI_COMPARE 0x39 // Compare (O)
  185735. #define SCSI_COPY 0x18 // Copy (O)
  185736. #define SCSI_COP_VERIFY 0x3A // Copy and Verify (O)
  185737. #define SCSI_INQUIRY 0x12 // Inquiry (MANDATORY)
  185738. #define SCSI_LOG_SELECT 0x4C // Log Select (O)
  185739. #define SCSI_LOG_SENSE 0x4D // Log Sense (O)
  185740. #define SCSI_MODE_SEL6 0x15 // Mode Select 6-byte (Device Specific)
  185741. #define SCSI_MODE_SEL10 0x55 // Mode Select 10-byte (Device Specific)
  185742. #define SCSI_MODE_SEN6 0x1A // Mode Sense 6-byte (Device Specific)
  185743. #define SCSI_MODE_SEN10 0x5A // Mode Sense 10-byte (Device Specific)
  185744. #define SCSI_READ_BUFF 0x3C // Read Buffer (O)
  185745. #define SCSI_REQ_SENSE 0x03 // Request Sense (MANDATORY)
  185746. #define SCSI_SEND_DIAG 0x1D // Send Diagnostic (O)
  185747. #define SCSI_TST_U_RDY 0x00 // Test Unit Ready (MANDATORY)
  185748. #define SCSI_WRITE_BUFF 0x3B // Write Buffer (O)
  185749. //***************************************************************************
  185750. // %%% Commands Unique to Direct Access Devices %%%
  185751. //***************************************************************************
  185752. #define SCSI_COMPARE 0x39 // Compare (O)
  185753. #define SCSI_FORMAT 0x04 // Format Unit (MANDATORY)
  185754. #define SCSI_LCK_UN_CAC 0x36 // Lock Unlock Cache (O)
  185755. #define SCSI_PREFETCH 0x34 // Prefetch (O)
  185756. #define SCSI_MED_REMOVL 0x1E // Prevent/Allow medium Removal (O)
  185757. #define SCSI_READ6 0x08 // Read 6-byte (MANDATORY)
  185758. #define SCSI_READ10 0x28 // Read 10-byte (MANDATORY)
  185759. #define SCSI_RD_CAPAC 0x25 // Read Capacity (MANDATORY)
  185760. #define SCSI_RD_DEFECT 0x37 // Read Defect Data (O)
  185761. #define SCSI_READ_LONG 0x3E // Read Long (O)
  185762. #define SCSI_REASS_BLK 0x07 // Reassign Blocks (O)
  185763. #define SCSI_RCV_DIAG 0x1C // Receive Diagnostic Results (O)
  185764. #define SCSI_RELEASE 0x17 // Release Unit (MANDATORY)
  185765. #define SCSI_REZERO 0x01 // Rezero Unit (O)
  185766. #define SCSI_SRCH_DAT_E 0x31 // Search Data Equal (O)
  185767. #define SCSI_SRCH_DAT_H 0x30 // Search Data High (O)
  185768. #define SCSI_SRCH_DAT_L 0x32 // Search Data Low (O)
  185769. #define SCSI_SEEK6 0x0B // Seek 6-Byte (O)
  185770. #define SCSI_SEEK10 0x2B // Seek 10-Byte (O)
  185771. #define SCSI_SEND_DIAG 0x1D // Send Diagnostics (MANDATORY)
  185772. #define SCSI_SET_LIMIT 0x33 // Set Limits (O)
  185773. #define SCSI_START_STP 0x1B // Start/Stop Unit (O)
  185774. #define SCSI_SYNC_CACHE 0x35 // Synchronize Cache (O)
  185775. #define SCSI_VERIFY 0x2F // Verify (O)
  185776. #define SCSI_WRITE6 0x0A // Write 6-Byte (MANDATORY)
  185777. #define SCSI_WRITE10 0x2A // Write 10-Byte (MANDATORY)
  185778. #define SCSI_WRT_VERIFY 0x2E // Write and Verify (O)
  185779. #define SCSI_WRITE_LONG 0x3F // Write Long (O)
  185780. #define SCSI_WRITE_SAME 0x41 // Write Same (O)
  185781. //***************************************************************************
  185782. // %%% Commands Unique to Sequential Access Devices %%%
  185783. //***************************************************************************
  185784. #define SCSI_ERASE 0x19 // Erase (MANDATORY)
  185785. #define SCSI_LOAD_UN 0x1b // Load/Unload (O)
  185786. #define SCSI_LOCATE 0x2B // Locate (O)
  185787. #define SCSI_RD_BLK_LIM 0x05 // Read Block Limits (MANDATORY)
  185788. #define SCSI_READ_POS 0x34 // Read Position (O)
  185789. #define SCSI_READ_REV 0x0F // Read Reverse (O)
  185790. #define SCSI_REC_BF_DAT 0x14 // Recover Buffer Data (O)
  185791. #define SCSI_RESERVE 0x16 // Reserve Unit (MANDATORY)
  185792. #define SCSI_REWIND 0x01 // Rewind (MANDATORY)
  185793. #define SCSI_SPACE 0x11 // Space (MANDATORY)
  185794. #define SCSI_VERIFY_T 0x13 // Verify (Tape) (O)
  185795. #define SCSI_WRT_FILE 0x10 // Write Filemarks (MANDATORY)
  185796. //***************************************************************************
  185797. // %%% Commands Unique to Printer Devices %%%
  185798. //***************************************************************************
  185799. #define SCSI_PRINT 0x0A // Print (MANDATORY)
  185800. #define SCSI_SLEW_PNT 0x0B // Slew and Print (O)
  185801. #define SCSI_STOP_PNT 0x1B // Stop Print (O)
  185802. #define SCSI_SYNC_BUFF 0x10 // Synchronize Buffer (O)
  185803. //***************************************************************************
  185804. // %%% Commands Unique to Processor Devices %%%
  185805. //***************************************************************************
  185806. #define SCSI_RECEIVE 0x08 // Receive (O)
  185807. #define SCSI_SEND 0x0A // Send (O)
  185808. //***************************************************************************
  185809. // %%% Commands Unique to Write-Once Devices %%%
  185810. //***************************************************************************
  185811. #define SCSI_MEDIUM_SCN 0x38 // Medium Scan (O)
  185812. #define SCSI_SRCHDATE10 0x31 // Search Data Equal 10-Byte (O)
  185813. #define SCSI_SRCHDATE12 0xB1 // Search Data Equal 12-Byte (O)
  185814. #define SCSI_SRCHDATH10 0x30 // Search Data High 10-Byte (O)
  185815. #define SCSI_SRCHDATH12 0xB0 // Search Data High 12-Byte (O)
  185816. #define SCSI_SRCHDATL10 0x32 // Search Data Low 10-Byte (O)
  185817. #define SCSI_SRCHDATL12 0xB2 // Search Data Low 12-Byte (O)
  185818. #define SCSI_SET_LIM_10 0x33 // Set Limits 10-Byte (O)
  185819. #define SCSI_SET_LIM_12 0xB3 // Set Limits 10-Byte (O)
  185820. #define SCSI_VERIFY10 0x2F // Verify 10-Byte (O)
  185821. #define SCSI_VERIFY12 0xAF // Verify 12-Byte (O)
  185822. #define SCSI_WRITE12 0xAA // Write 12-Byte (O)
  185823. #define SCSI_WRT_VER10 0x2E // Write and Verify 10-Byte (O)
  185824. #define SCSI_WRT_VER12 0xAE // Write and Verify 12-Byte (O)
  185825. //***************************************************************************
  185826. // %%% Commands Unique to CD-ROM Devices %%%
  185827. //***************************************************************************
  185828. #define SCSI_PLAYAUD_10 0x45 // Play Audio 10-Byte (O)
  185829. #define SCSI_PLAYAUD_12 0xA5 // Play Audio 12-Byte 12-Byte (O)
  185830. #define SCSI_PLAYAUDMSF 0x47 // Play Audio MSF (O)
  185831. #define SCSI_PLAYA_TKIN 0x48 // Play Audio Track/Index (O)
  185832. #define SCSI_PLYTKREL10 0x49 // Play Track Relative 10-Byte (O)
  185833. #define SCSI_PLYTKREL12 0xA9 // Play Track Relative 12-Byte (O)
  185834. #define SCSI_READCDCAP 0x25 // Read CD-ROM Capacity (MANDATORY)
  185835. #define SCSI_READHEADER 0x44 // Read Header (O)
  185836. #define SCSI_SUBCHANNEL 0x42 // Read Subchannel (O)
  185837. #define SCSI_READ_TOC 0x43 // Read TOC (O)
  185838. //***************************************************************************
  185839. // %%% Commands Unique to Scanner Devices %%%
  185840. //***************************************************************************
  185841. #define SCSI_GETDBSTAT 0x34 // Get Data Buffer Status (O)
  185842. #define SCSI_GETWINDOW 0x25 // Get Window (O)
  185843. #define SCSI_OBJECTPOS 0x31 // Object Postion (O)
  185844. #define SCSI_SCAN 0x1B // Scan (O)
  185845. #define SCSI_SETWINDOW 0x24 // Set Window (MANDATORY)
  185846. //***************************************************************************
  185847. // %%% Commands Unique to Optical Memory Devices %%%
  185848. //***************************************************************************
  185849. #define SCSI_UpdateBlk 0x3D // Update Block (O)
  185850. //***************************************************************************
  185851. // %%% Commands Unique to Medium Changer Devices %%%
  185852. //***************************************************************************
  185853. #define SCSI_EXCHMEDIUM 0xA6 // Exchange Medium (O)
  185854. #define SCSI_INITELSTAT 0x07 // Initialize Element Status (O)
  185855. #define SCSI_POSTOELEM 0x2B // Position to Element (O)
  185856. #define SCSI_REQ_VE_ADD 0xB5 // Request Volume Element Address (O)
  185857. #define SCSI_SENDVOLTAG 0xB6 // Send Volume Tag (O)
  185858. //***************************************************************************
  185859. // %%% Commands Unique to Communication Devices %%%
  185860. //***************************************************************************
  185861. #define SCSI_GET_MSG_6 0x08 // Get Message 6-Byte (MANDATORY)
  185862. #define SCSI_GET_MSG_10 0x28 // Get Message 10-Byte (O)
  185863. #define SCSI_GET_MSG_12 0xA8 // Get Message 12-Byte (O)
  185864. #define SCSI_SND_MSG_6 0x0A // Send Message 6-Byte (MANDATORY)
  185865. #define SCSI_SND_MSG_10 0x2A // Send Message 10-Byte (O)
  185866. #define SCSI_SND_MSG_12 0xAA // Send Message 12-Byte (O)
  185867. //***************************************************************************
  185868. // %%% Request Sense Data Format %%%
  185869. //***************************************************************************
  185870. typedef struct {
  185871. BYTE ErrorCode; // Error Code (70H or 71H)
  185872. BYTE SegmentNum; // Number of current segment descriptor
  185873. BYTE SenseKey; // Sense Key(See bit definitions too)
  185874. BYTE InfoByte0; // Information MSB
  185875. BYTE InfoByte1; // Information MID
  185876. BYTE InfoByte2; // Information MID
  185877. BYTE InfoByte3; // Information LSB
  185878. BYTE AddSenLen; // Additional Sense Length
  185879. BYTE ComSpecInf0; // Command Specific Information MSB
  185880. BYTE ComSpecInf1; // Command Specific Information MID
  185881. BYTE ComSpecInf2; // Command Specific Information MID
  185882. BYTE ComSpecInf3; // Command Specific Information LSB
  185883. BYTE AddSenseCode; // Additional Sense Code
  185884. BYTE AddSenQual; // Additional Sense Code Qualifier
  185885. BYTE FieldRepUCode; // Field Replaceable Unit Code
  185886. BYTE SenKeySpec15; // Sense Key Specific 15th byte
  185887. BYTE SenKeySpec16; // Sense Key Specific 16th byte
  185888. BYTE SenKeySpec17; // Sense Key Specific 17th byte
  185889. BYTE AddSenseBytes; // Additional Sense Bytes
  185890. } SENSE_DATA_FMT;
  185891. //***************************************************************************
  185892. // %%% REQUEST SENSE ERROR CODE %%%
  185893. //***************************************************************************
  185894. #define SERROR_CURRENT 0x70 // Current Errors
  185895. #define SERROR_DEFERED 0x71 // Deferred Errors
  185896. //***************************************************************************
  185897. // %%% REQUEST SENSE BIT DEFINITIONS %%%
  185898. //***************************************************************************
  185899. #define SENSE_VALID 0x80 // Byte 0 Bit 7
  185900. #define SENSE_FILEMRK 0x80 // Byte 2 Bit 7
  185901. #define SENSE_EOM 0x40 // Byte 2 Bit 6
  185902. #define SENSE_ILI 0x20 // Byte 2 Bit 5
  185903. //***************************************************************************
  185904. // %%% REQUEST SENSE SENSE KEY DEFINITIONS %%%
  185905. //***************************************************************************
  185906. #define KEY_NOSENSE 0x00 // No Sense
  185907. #define KEY_RECERROR 0x01 // Recovered Error
  185908. #define KEY_NOTREADY 0x02 // Not Ready
  185909. #define KEY_MEDIUMERR 0x03 // Medium Error
  185910. #define KEY_HARDERROR 0x04 // Hardware Error
  185911. #define KEY_ILLGLREQ 0x05 // Illegal Request
  185912. #define KEY_UNITATT 0x06 // Unit Attention
  185913. #define KEY_DATAPROT 0x07 // Data Protect
  185914. #define KEY_BLANKCHK 0x08 // Blank Check
  185915. #define KEY_VENDSPEC 0x09 // Vendor Specific
  185916. #define KEY_COPYABORT 0x0A // Copy Abort
  185917. #define KEY_EQUAL 0x0C // Equal (Search)
  185918. #define KEY_VOLOVRFLW 0x0D // Volume Overflow
  185919. #define KEY_MISCOMP 0x0E // Miscompare (Search)
  185920. #define KEY_RESERVED 0x0F // Reserved
  185921. //***************************************************************************
  185922. // %%% PERIPHERAL DEVICE TYPE DEFINITIONS %%%
  185923. //***************************************************************************
  185924. #define DTYPE_DASD 0x00 // Disk Device
  185925. #define DTYPE_SEQD 0x01 // Tape Device
  185926. #define DTYPE_PRNT 0x02 // Printer
  185927. #define DTYPE_PROC 0x03 // Processor
  185928. #define DTYPE_WORM 0x04 // Write-once read-multiple
  185929. #define DTYPE_CROM 0x05 // CD-ROM device
  185930. #define DTYPE_SCAN 0x06 // Scanner device
  185931. #define DTYPE_OPTI 0x07 // Optical memory device
  185932. #define DTYPE_JUKE 0x08 // Medium Changer device
  185933. #define DTYPE_COMM 0x09 // Communications device
  185934. #define DTYPE_RESL 0x0A // Reserved (low)
  185935. #define DTYPE_RESH 0x1E // Reserved (high)
  185936. #define DTYPE_UNKNOWN 0x1F // Unknown or no device type
  185937. //***************************************************************************
  185938. // %%% ANSI APPROVED VERSION DEFINITIONS %%%
  185939. //***************************************************************************
  185940. #define ANSI_MAYBE 0x0 // Device may or may not be ANSI approved stand
  185941. #define ANSI_SCSI1 0x1 // Device complies to ANSI X3.131-1986 (SCSI-1)
  185942. #define ANSI_SCSI2 0x2 // Device complies to SCSI-2
  185943. #define ANSI_RESLO 0x3 // Reserved (low)
  185944. #define ANSI_RESHI 0x7 // Reserved (high)
  185945. typedef struct
  185946. {
  185947. USHORT Length;
  185948. UCHAR ScsiStatus;
  185949. UCHAR PathId;
  185950. UCHAR TargetId;
  185951. UCHAR Lun;
  185952. UCHAR CdbLength;
  185953. UCHAR SenseInfoLength;
  185954. UCHAR DataIn;
  185955. ULONG DataTransferLength;
  185956. ULONG TimeOutValue;
  185957. ULONG DataBufferOffset;
  185958. ULONG SenseInfoOffset;
  185959. UCHAR Cdb[16];
  185960. } SCSI_PASS_THROUGH, *PSCSI_PASS_THROUGH;
  185961. typedef struct
  185962. {
  185963. USHORT Length;
  185964. UCHAR ScsiStatus;
  185965. UCHAR PathId;
  185966. UCHAR TargetId;
  185967. UCHAR Lun;
  185968. UCHAR CdbLength;
  185969. UCHAR SenseInfoLength;
  185970. UCHAR DataIn;
  185971. ULONG DataTransferLength;
  185972. ULONG TimeOutValue;
  185973. PVOID DataBuffer;
  185974. ULONG SenseInfoOffset;
  185975. UCHAR Cdb[16];
  185976. } SCSI_PASS_THROUGH_DIRECT, *PSCSI_PASS_THROUGH_DIRECT;
  185977. typedef struct
  185978. {
  185979. SCSI_PASS_THROUGH_DIRECT spt;
  185980. ULONG Filler;
  185981. UCHAR ucSenseBuf[32];
  185982. } SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, *PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER;
  185983. typedef struct
  185984. {
  185985. ULONG Length;
  185986. UCHAR PortNumber;
  185987. UCHAR PathId;
  185988. UCHAR TargetId;
  185989. UCHAR Lun;
  185990. } SCSI_ADDRESS, *PSCSI_ADDRESS;
  185991. #define METHOD_BUFFERED 0
  185992. #define METHOD_IN_DIRECT 1
  185993. #define METHOD_OUT_DIRECT 2
  185994. #define METHOD_NEITHER 3
  185995. #define FILE_ANY_ACCESS 0
  185996. #ifndef FILE_READ_ACCESS
  185997. #define FILE_READ_ACCESS (0x0001)
  185998. #endif
  185999. #ifndef FILE_WRITE_ACCESS
  186000. #define FILE_WRITE_ACCESS (0x0002)
  186001. #endif
  186002. #define IOCTL_SCSI_BASE 0x00000004
  186003. #define SCSI_IOCTL_DATA_OUT 0
  186004. #define SCSI_IOCTL_DATA_IN 1
  186005. #define SCSI_IOCTL_DATA_UNSPECIFIED 2
  186006. #define CTL_CODE2( DevType, Function, Method, Access ) ( \
  186007. ((DevType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) \
  186008. )
  186009. #define IOCTL_SCSI_PASS_THROUGH CTL_CODE2( IOCTL_SCSI_BASE, 0x0401, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS )
  186010. #define IOCTL_SCSI_GET_CAPABILITIES CTL_CODE2( IOCTL_SCSI_BASE, 0x0404, METHOD_BUFFERED, FILE_ANY_ACCESS)
  186011. #define IOCTL_SCSI_PASS_THROUGH_DIRECT CTL_CODE2( IOCTL_SCSI_BASE, 0x0405, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS )
  186012. #define IOCTL_SCSI_GET_ADDRESS CTL_CODE2( IOCTL_SCSI_BASE, 0x0406, METHOD_BUFFERED, FILE_ANY_ACCESS )
  186013. #define SENSE_LEN 14
  186014. #define SRB_DIR_SCSI 0x00
  186015. #define SRB_POSTING 0x01
  186016. #define SRB_ENABLE_RESIDUAL_COUNT 0x04
  186017. #define SRB_DIR_IN 0x08
  186018. #define SRB_DIR_OUT 0x10
  186019. #define SRB_EVENT_NOTIFY 0x40
  186020. #define RESIDUAL_COUNT_SUPPORTED 0x02
  186021. #define MAX_SRB_TIMEOUT 1080001u
  186022. #define DEFAULT_SRB_TIMEOUT 1080001u
  186023. #define SC_HA_INQUIRY 0x00
  186024. #define SC_GET_DEV_TYPE 0x01
  186025. #define SC_EXEC_SCSI_CMD 0x02
  186026. #define SC_ABORT_SRB 0x03
  186027. #define SC_RESET_DEV 0x04
  186028. #define SC_SET_HA_PARMS 0x05
  186029. #define SC_GET_DISK_INFO 0x06
  186030. #define SC_RESCAN_SCSI_BUS 0x07
  186031. #define SC_GETSET_TIMEOUTS 0x08
  186032. #define SS_PENDING 0x00
  186033. #define SS_COMP 0x01
  186034. #define SS_ABORTED 0x02
  186035. #define SS_ABORT_FAIL 0x03
  186036. #define SS_ERR 0x04
  186037. #define SS_INVALID_CMD 0x80
  186038. #define SS_INVALID_HA 0x81
  186039. #define SS_NO_DEVICE 0x82
  186040. #define SS_INVALID_SRB 0xE0
  186041. #define SS_OLD_MANAGER 0xE1
  186042. #define SS_BUFFER_ALIGN 0xE1
  186043. #define SS_ILLEGAL_MODE 0xE2
  186044. #define SS_NO_ASPI 0xE3
  186045. #define SS_FAILED_INIT 0xE4
  186046. #define SS_ASPI_IS_BUSY 0xE5
  186047. #define SS_BUFFER_TO_BIG 0xE6
  186048. #define SS_BUFFER_TOO_BIG 0xE6
  186049. #define SS_MISMATCHED_COMPONENTS 0xE7
  186050. #define SS_NO_ADAPTERS 0xE8
  186051. #define SS_INSUFFICIENT_RESOURCES 0xE9
  186052. #define SS_ASPI_IS_SHUTDOWN 0xEA
  186053. #define SS_BAD_INSTALL 0xEB
  186054. #define HASTAT_OK 0x00
  186055. #define HASTAT_SEL_TO 0x11
  186056. #define HASTAT_DO_DU 0x12
  186057. #define HASTAT_BUS_FREE 0x13
  186058. #define HASTAT_PHASE_ERR 0x14
  186059. #define HASTAT_TIMEOUT 0x09
  186060. #define HASTAT_COMMAND_TIMEOUT 0x0B
  186061. #define HASTAT_MESSAGE_REJECT 0x0D
  186062. #define HASTAT_BUS_RESET 0x0E
  186063. #define HASTAT_PARITY_ERROR 0x0F
  186064. #define HASTAT_REQUEST_SENSE_FAILED 0x10
  186065. #define PACKED
  186066. #pragma pack(1)
  186067. typedef struct
  186068. {
  186069. BYTE SRB_Cmd;
  186070. BYTE SRB_Status;
  186071. BYTE SRB_HaID;
  186072. BYTE SRB_Flags;
  186073. DWORD SRB_Hdr_Rsvd;
  186074. BYTE HA_Count;
  186075. BYTE HA_SCSI_ID;
  186076. BYTE HA_ManagerId[16];
  186077. BYTE HA_Identifier[16];
  186078. BYTE HA_Unique[16];
  186079. WORD HA_Rsvd1;
  186080. BYTE pad[20];
  186081. } PACKED SRB_HAInquiry, *PSRB_HAInquiry, FAR *LPSRB_HAInquiry;
  186082. typedef struct
  186083. {
  186084. BYTE SRB_Cmd;
  186085. BYTE SRB_Status;
  186086. BYTE SRB_HaID;
  186087. BYTE SRB_Flags;
  186088. DWORD SRB_Hdr_Rsvd;
  186089. BYTE SRB_Target;
  186090. BYTE SRB_Lun;
  186091. BYTE SRB_DeviceType;
  186092. BYTE SRB_Rsvd1;
  186093. BYTE pad[68];
  186094. } PACKED SRB_GDEVBlock, *PSRB_GDEVBlock, FAR *LPSRB_GDEVBlock;
  186095. typedef struct
  186096. {
  186097. BYTE SRB_Cmd;
  186098. BYTE SRB_Status;
  186099. BYTE SRB_HaID;
  186100. BYTE SRB_Flags;
  186101. DWORD SRB_Hdr_Rsvd;
  186102. BYTE SRB_Target;
  186103. BYTE SRB_Lun;
  186104. WORD SRB_Rsvd1;
  186105. DWORD SRB_BufLen;
  186106. BYTE FAR *SRB_BufPointer;
  186107. BYTE SRB_SenseLen;
  186108. BYTE SRB_CDBLen;
  186109. BYTE SRB_HaStat;
  186110. BYTE SRB_TargStat;
  186111. VOID FAR *SRB_PostProc;
  186112. BYTE SRB_Rsvd2[20];
  186113. BYTE CDBByte[16];
  186114. BYTE SenseArea[SENSE_LEN+2];
  186115. } PACKED SRB_ExecSCSICmd, *PSRB_ExecSCSICmd, FAR *LPSRB_ExecSCSICmd;
  186116. typedef struct
  186117. {
  186118. BYTE SRB_Cmd;
  186119. BYTE SRB_Status;
  186120. BYTE SRB_HaId;
  186121. BYTE SRB_Flags;
  186122. DWORD SRB_Hdr_Rsvd;
  186123. } PACKED SRB, *PSRB, FAR *LPSRB;
  186124. #pragma pack()
  186125. struct CDDeviceInfo
  186126. {
  186127. char vendor[9];
  186128. char productId[17];
  186129. char rev[5];
  186130. char vendorSpec[21];
  186131. BYTE ha;
  186132. BYTE tgt;
  186133. BYTE lun;
  186134. char scsiDriveLetter; // will be 0 if not using scsi
  186135. };
  186136. class CDReadBuffer
  186137. {
  186138. public:
  186139. int startFrame;
  186140. int numFrames;
  186141. int dataStartOffset;
  186142. int dataLength;
  186143. BYTE* buffer;
  186144. int bufferSize;
  186145. int index;
  186146. bool wantsIndex;
  186147. CDReadBuffer (const int numberOfFrames)
  186148. : startFrame (0),
  186149. numFrames (0),
  186150. dataStartOffset (0),
  186151. dataLength (0),
  186152. index (0),
  186153. wantsIndex (false)
  186154. {
  186155. bufferSize = 2352 * numberOfFrames;
  186156. buffer = (BYTE*) juce_malloc (bufferSize);
  186157. }
  186158. ~CDReadBuffer()
  186159. {
  186160. juce_free (buffer);
  186161. }
  186162. bool isZero() const
  186163. {
  186164. BYTE* p = buffer + dataStartOffset;
  186165. for (int i = dataLength; --i >= 0;)
  186166. if (*p++ != 0)
  186167. return false;
  186168. return true;
  186169. }
  186170. };
  186171. class CDDeviceHandle;
  186172. class CDController
  186173. {
  186174. public:
  186175. CDController();
  186176. virtual ~CDController();
  186177. virtual bool read (CDReadBuffer* t) = 0;
  186178. virtual void shutDown();
  186179. bool readAudio (CDReadBuffer* t, CDReadBuffer* overlapBuffer = 0);
  186180. int getLastIndex();
  186181. public:
  186182. bool initialised;
  186183. CDDeviceHandle* deviceInfo;
  186184. int framesToCheck, framesOverlap;
  186185. void prepare (SRB_ExecSCSICmd& s);
  186186. void perform (SRB_ExecSCSICmd& s);
  186187. void setPaused (bool paused);
  186188. };
  186189. #pragma pack(1)
  186190. struct TOCTRACK
  186191. {
  186192. BYTE rsvd;
  186193. BYTE ADR;
  186194. BYTE trackNumber;
  186195. BYTE rsvd2;
  186196. BYTE addr[4];
  186197. };
  186198. struct TOC
  186199. {
  186200. WORD tocLen;
  186201. BYTE firstTrack;
  186202. BYTE lastTrack;
  186203. TOCTRACK tracks[100];
  186204. };
  186205. #pragma pack()
  186206. enum
  186207. {
  186208. READTYPE_ANY = 0,
  186209. READTYPE_ATAPI1 = 1,
  186210. READTYPE_ATAPI2 = 2,
  186211. READTYPE_READ6 = 3,
  186212. READTYPE_READ10 = 4,
  186213. READTYPE_READ_D8 = 5,
  186214. READTYPE_READ_D4 = 6,
  186215. READTYPE_READ_D4_1 = 7,
  186216. READTYPE_READ10_2 = 8
  186217. };
  186218. class CDDeviceHandle
  186219. {
  186220. public:
  186221. CDDeviceHandle (const CDDeviceInfo* const device)
  186222. : scsiHandle (0),
  186223. readType (READTYPE_ANY),
  186224. controller (0)
  186225. {
  186226. memcpy (&info, device, sizeof (info));
  186227. }
  186228. ~CDDeviceHandle()
  186229. {
  186230. if (controller != 0)
  186231. {
  186232. controller->shutDown();
  186233. controller = 0;
  186234. }
  186235. if (scsiHandle != 0)
  186236. CloseHandle (scsiHandle);
  186237. }
  186238. bool readTOC (TOC* lpToc, bool useMSF);
  186239. bool readAudio (CDReadBuffer* buffer, CDReadBuffer* overlapBuffer = 0);
  186240. void openDrawer (bool shouldBeOpen);
  186241. CDDeviceInfo info;
  186242. HANDLE scsiHandle;
  186243. BYTE readType;
  186244. private:
  186245. ScopedPointer<CDController> controller;
  186246. bool testController (const int readType,
  186247. CDController* const newController,
  186248. CDReadBuffer* const bufferToUse);
  186249. };
  186250. DWORD (*fGetASPI32SupportInfo)(void);
  186251. DWORD (*fSendASPI32Command)(LPSRB);
  186252. static HINSTANCE winAspiLib = 0;
  186253. static bool usingScsi = false;
  186254. static bool initialised = false;
  186255. static bool InitialiseCDRipper()
  186256. {
  186257. if (! initialised)
  186258. {
  186259. initialised = true;
  186260. OSVERSIONINFO info;
  186261. info.dwOSVersionInfoSize = sizeof (info);
  186262. GetVersionEx (&info);
  186263. usingScsi = (info.dwPlatformId == VER_PLATFORM_WIN32_NT) && (info.dwMajorVersion > 4);
  186264. if (! usingScsi)
  186265. {
  186266. fGetASPI32SupportInfo = 0;
  186267. fSendASPI32Command = 0;
  186268. winAspiLib = LoadLibrary (_T("WNASPI32.DLL"));
  186269. if (winAspiLib != 0)
  186270. {
  186271. fGetASPI32SupportInfo = (DWORD(*)(void)) GetProcAddress (winAspiLib, "GetASPI32SupportInfo");
  186272. fSendASPI32Command = (DWORD(*)(LPSRB)) GetProcAddress (winAspiLib, "SendASPI32Command");
  186273. if (fGetASPI32SupportInfo == 0 || fSendASPI32Command == 0)
  186274. return false;
  186275. }
  186276. else
  186277. {
  186278. usingScsi = true;
  186279. }
  186280. }
  186281. }
  186282. return true;
  186283. }
  186284. static void DeinitialiseCDRipper()
  186285. {
  186286. if (winAspiLib != 0)
  186287. {
  186288. fGetASPI32SupportInfo = 0;
  186289. fSendASPI32Command = 0;
  186290. FreeLibrary (winAspiLib);
  186291. winAspiLib = 0;
  186292. }
  186293. initialised = false;
  186294. }
  186295. static HANDLE CreateSCSIDeviceHandle (char driveLetter)
  186296. {
  186297. TCHAR devicePath[] = { '\\', '\\', '.', '\\', driveLetter, ':', 0, 0 };
  186298. OSVERSIONINFO info;
  186299. info.dwOSVersionInfoSize = sizeof (info);
  186300. GetVersionEx (&info);
  186301. DWORD flags = GENERIC_READ;
  186302. if ((info.dwPlatformId == VER_PLATFORM_WIN32_NT) && (info.dwMajorVersion > 4))
  186303. flags = GENERIC_READ | GENERIC_WRITE;
  186304. HANDLE h = CreateFile (devicePath, flags, FILE_SHARE_WRITE | FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  186305. if (h == INVALID_HANDLE_VALUE)
  186306. {
  186307. flags ^= GENERIC_WRITE;
  186308. h = CreateFile (devicePath, flags, FILE_SHARE_WRITE | FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  186309. }
  186310. return h;
  186311. }
  186312. static DWORD performScsiPassThroughCommand (const LPSRB_ExecSCSICmd srb,
  186313. const char driveLetter,
  186314. HANDLE& deviceHandle,
  186315. const bool retryOnFailure = true)
  186316. {
  186317. SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER s;
  186318. zerostruct (s);
  186319. s.spt.Length = sizeof (SCSI_PASS_THROUGH);
  186320. s.spt.CdbLength = srb->SRB_CDBLen;
  186321. s.spt.DataIn = (BYTE) ((srb->SRB_Flags & SRB_DIR_IN)
  186322. ? SCSI_IOCTL_DATA_IN
  186323. : ((srb->SRB_Flags & SRB_DIR_OUT)
  186324. ? SCSI_IOCTL_DATA_OUT
  186325. : SCSI_IOCTL_DATA_UNSPECIFIED));
  186326. s.spt.DataTransferLength = srb->SRB_BufLen;
  186327. s.spt.TimeOutValue = 5;
  186328. s.spt.DataBuffer = srb->SRB_BufPointer;
  186329. s.spt.SenseInfoOffset = offsetof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, ucSenseBuf);
  186330. memcpy (s.spt.Cdb, srb->CDBByte, srb->SRB_CDBLen);
  186331. srb->SRB_Status = SS_ERR;
  186332. srb->SRB_TargStat = 0x0004;
  186333. DWORD bytesReturned = 0;
  186334. if (DeviceIoControl (deviceHandle, IOCTL_SCSI_PASS_THROUGH_DIRECT,
  186335. &s, sizeof (s),
  186336. &s, sizeof (s),
  186337. &bytesReturned, 0) != 0)
  186338. {
  186339. srb->SRB_Status = SS_COMP;
  186340. }
  186341. else if (retryOnFailure)
  186342. {
  186343. const DWORD error = GetLastError();
  186344. if ((error == ERROR_MEDIA_CHANGED) || (error == ERROR_INVALID_HANDLE))
  186345. {
  186346. if (error != ERROR_INVALID_HANDLE)
  186347. CloseHandle (deviceHandle);
  186348. deviceHandle = CreateSCSIDeviceHandle (driveLetter);
  186349. return performScsiPassThroughCommand (srb, driveLetter, deviceHandle, false);
  186350. }
  186351. }
  186352. return srb->SRB_Status;
  186353. }
  186354. // Controller types..
  186355. class ControllerType1 : public CDController
  186356. {
  186357. public:
  186358. ControllerType1() {}
  186359. ~ControllerType1() {}
  186360. bool read (CDReadBuffer* rb)
  186361. {
  186362. if (rb->numFrames * 2352 > rb->bufferSize)
  186363. return false;
  186364. SRB_ExecSCSICmd s;
  186365. prepare (s);
  186366. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186367. s.SRB_BufLen = rb->bufferSize;
  186368. s.SRB_BufPointer = rb->buffer;
  186369. s.SRB_CDBLen = 12;
  186370. s.CDBByte[0] = 0xBE;
  186371. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186372. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186373. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186374. s.CDBByte[8] = (BYTE)(rb->numFrames & 0xFF);
  186375. s.CDBByte[9] = (BYTE)((deviceInfo->readType == READTYPE_ATAPI1) ? 0x10 : 0xF0);
  186376. perform (s);
  186377. if (s.SRB_Status != SS_COMP)
  186378. return false;
  186379. rb->dataLength = rb->numFrames * 2352;
  186380. rb->dataStartOffset = 0;
  186381. return true;
  186382. }
  186383. };
  186384. class ControllerType2 : public CDController
  186385. {
  186386. public:
  186387. ControllerType2() {}
  186388. ~ControllerType2() {}
  186389. void shutDown()
  186390. {
  186391. if (initialised)
  186392. {
  186393. BYTE bufPointer[] = { 0, 0, 0, 8, 83, 0, 0, 0, 0, 0, 8, 0 };
  186394. SRB_ExecSCSICmd s;
  186395. prepare (s);
  186396. s.SRB_Flags = SRB_EVENT_NOTIFY | SRB_ENABLE_RESIDUAL_COUNT;
  186397. s.SRB_BufLen = 0x0C;
  186398. s.SRB_BufPointer = bufPointer;
  186399. s.SRB_CDBLen = 6;
  186400. s.CDBByte[0] = 0x15;
  186401. s.CDBByte[4] = 0x0C;
  186402. perform (s);
  186403. }
  186404. }
  186405. bool init()
  186406. {
  186407. SRB_ExecSCSICmd s;
  186408. s.SRB_Status = SS_ERR;
  186409. if (deviceInfo->readType == READTYPE_READ10_2)
  186410. {
  186411. BYTE bufPointer1[] = { 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9, 48, 35, 6, 0, 0, 0, 0, 0, 128 };
  186412. BYTE bufPointer2[] = { 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9, 48, 1, 6, 32, 7, 0, 0, 0, 0 };
  186413. for (int i = 0; i < 2; ++i)
  186414. {
  186415. prepare (s);
  186416. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186417. s.SRB_BufLen = 0x14;
  186418. s.SRB_BufPointer = (i == 0) ? bufPointer1 : bufPointer2;
  186419. s.SRB_CDBLen = 6;
  186420. s.CDBByte[0] = 0x15;
  186421. s.CDBByte[1] = 0x10;
  186422. s.CDBByte[4] = 0x14;
  186423. perform (s);
  186424. if (s.SRB_Status != SS_COMP)
  186425. return false;
  186426. }
  186427. }
  186428. else
  186429. {
  186430. BYTE bufPointer[] = { 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9, 48 };
  186431. prepare (s);
  186432. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186433. s.SRB_BufLen = 0x0C;
  186434. s.SRB_BufPointer = bufPointer;
  186435. s.SRB_CDBLen = 6;
  186436. s.CDBByte[0] = 0x15;
  186437. s.CDBByte[4] = 0x0C;
  186438. perform (s);
  186439. }
  186440. return s.SRB_Status == SS_COMP;
  186441. }
  186442. bool read (CDReadBuffer* rb)
  186443. {
  186444. if (rb->numFrames * 2352 > rb->bufferSize)
  186445. return false;
  186446. if (!initialised)
  186447. {
  186448. initialised = init();
  186449. if (!initialised)
  186450. return false;
  186451. }
  186452. SRB_ExecSCSICmd s;
  186453. prepare (s);
  186454. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186455. s.SRB_BufLen = rb->bufferSize;
  186456. s.SRB_BufPointer = rb->buffer;
  186457. s.SRB_CDBLen = 10;
  186458. s.CDBByte[0] = 0x28;
  186459. s.CDBByte[1] = (BYTE)(deviceInfo->info.lun << 5);
  186460. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186461. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186462. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186463. s.CDBByte[8] = (BYTE)(rb->numFrames & 0xFF);
  186464. perform (s);
  186465. if (s.SRB_Status != SS_COMP)
  186466. return false;
  186467. rb->dataLength = rb->numFrames * 2352;
  186468. rb->dataStartOffset = 0;
  186469. return true;
  186470. }
  186471. };
  186472. class ControllerType3 : public CDController
  186473. {
  186474. public:
  186475. ControllerType3() {}
  186476. ~ControllerType3() {}
  186477. bool read (CDReadBuffer* rb)
  186478. {
  186479. if (rb->numFrames * 2352 > rb->bufferSize)
  186480. return false;
  186481. if (!initialised)
  186482. {
  186483. setPaused (false);
  186484. initialised = true;
  186485. }
  186486. SRB_ExecSCSICmd s;
  186487. prepare (s);
  186488. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186489. s.SRB_BufLen = rb->numFrames * 2352;
  186490. s.SRB_BufPointer = rb->buffer;
  186491. s.SRB_CDBLen = 12;
  186492. s.CDBByte[0] = 0xD8;
  186493. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186494. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186495. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186496. s.CDBByte[9] = (BYTE)(rb->numFrames & 0xFF);
  186497. perform (s);
  186498. if (s.SRB_Status != SS_COMP)
  186499. return false;
  186500. rb->dataLength = rb->numFrames * 2352;
  186501. rb->dataStartOffset = 0;
  186502. return true;
  186503. }
  186504. };
  186505. class ControllerType4 : public CDController
  186506. {
  186507. public:
  186508. ControllerType4() {}
  186509. ~ControllerType4() {}
  186510. bool selectD4Mode()
  186511. {
  186512. BYTE bufPointer[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 48 };
  186513. SRB_ExecSCSICmd s;
  186514. prepare (s);
  186515. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186516. s.SRB_CDBLen = 6;
  186517. s.SRB_BufLen = 12;
  186518. s.SRB_BufPointer = bufPointer;
  186519. s.CDBByte[0] = 0x15;
  186520. s.CDBByte[1] = 0x10;
  186521. s.CDBByte[4] = 0x08;
  186522. perform (s);
  186523. return s.SRB_Status == SS_COMP;
  186524. }
  186525. bool read (CDReadBuffer* rb)
  186526. {
  186527. if (rb->numFrames * 2352 > rb->bufferSize)
  186528. return false;
  186529. if (!initialised)
  186530. {
  186531. setPaused (true);
  186532. if (deviceInfo->readType == READTYPE_READ_D4_1)
  186533. selectD4Mode();
  186534. initialised = true;
  186535. }
  186536. SRB_ExecSCSICmd s;
  186537. prepare (s);
  186538. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186539. s.SRB_BufLen = rb->bufferSize;
  186540. s.SRB_BufPointer = rb->buffer;
  186541. s.SRB_CDBLen = 10;
  186542. s.CDBByte[0] = 0xD4;
  186543. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186544. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186545. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186546. s.CDBByte[8] = (BYTE)(rb->numFrames & 0xFF);
  186547. perform (s);
  186548. if (s.SRB_Status != SS_COMP)
  186549. return false;
  186550. rb->dataLength = rb->numFrames * 2352;
  186551. rb->dataStartOffset = 0;
  186552. return true;
  186553. }
  186554. };
  186555. CDController::CDController() : initialised (false)
  186556. {
  186557. }
  186558. CDController::~CDController()
  186559. {
  186560. }
  186561. void CDController::prepare (SRB_ExecSCSICmd& s)
  186562. {
  186563. zerostruct (s);
  186564. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  186565. s.SRB_HaID = deviceInfo->info.ha;
  186566. s.SRB_Target = deviceInfo->info.tgt;
  186567. s.SRB_Lun = deviceInfo->info.lun;
  186568. s.SRB_SenseLen = SENSE_LEN;
  186569. }
  186570. void CDController::perform (SRB_ExecSCSICmd& s)
  186571. {
  186572. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  186573. s.SRB_PostProc = (void*)event;
  186574. ResetEvent (event);
  186575. DWORD status = (usingScsi) ? performScsiPassThroughCommand ((LPSRB_ExecSCSICmd)&s,
  186576. deviceInfo->info.scsiDriveLetter,
  186577. deviceInfo->scsiHandle)
  186578. : fSendASPI32Command ((LPSRB)&s);
  186579. if (status == SS_PENDING)
  186580. WaitForSingleObject (event, 4000);
  186581. CloseHandle (event);
  186582. }
  186583. void CDController::setPaused (bool paused)
  186584. {
  186585. SRB_ExecSCSICmd s;
  186586. prepare (s);
  186587. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186588. s.SRB_CDBLen = 10;
  186589. s.CDBByte[0] = 0x4B;
  186590. s.CDBByte[8] = (BYTE) (paused ? 0 : 1);
  186591. perform (s);
  186592. }
  186593. void CDController::shutDown()
  186594. {
  186595. }
  186596. bool CDController::readAudio (CDReadBuffer* rb, CDReadBuffer* overlapBuffer)
  186597. {
  186598. if (overlapBuffer != 0)
  186599. {
  186600. const bool canDoJitter = (overlapBuffer->bufferSize >= 2352 * framesToCheck);
  186601. const bool doJitter = canDoJitter && ! overlapBuffer->isZero();
  186602. if (doJitter
  186603. && overlapBuffer->startFrame > 0
  186604. && overlapBuffer->numFrames > 0
  186605. && overlapBuffer->dataLength > 0)
  186606. {
  186607. const int numFrames = rb->numFrames;
  186608. if (overlapBuffer->startFrame == (rb->startFrame - framesToCheck))
  186609. {
  186610. rb->startFrame -= framesOverlap;
  186611. if (framesToCheck < framesOverlap
  186612. && numFrames + framesOverlap <= rb->bufferSize / 2352)
  186613. rb->numFrames += framesOverlap;
  186614. }
  186615. else
  186616. {
  186617. overlapBuffer->dataLength = 0;
  186618. overlapBuffer->startFrame = 0;
  186619. overlapBuffer->numFrames = 0;
  186620. }
  186621. }
  186622. if (! read (rb))
  186623. return false;
  186624. if (doJitter)
  186625. {
  186626. const int checkLen = framesToCheck * 2352;
  186627. const int maxToCheck = rb->dataLength - checkLen;
  186628. if (overlapBuffer->dataLength == 0 || overlapBuffer->isZero())
  186629. return true;
  186630. BYTE* const p = overlapBuffer->buffer + overlapBuffer->dataStartOffset;
  186631. bool found = false;
  186632. for (int i = 0; i < maxToCheck; ++i)
  186633. {
  186634. if (!memcmp (p, rb->buffer + i, checkLen))
  186635. {
  186636. i += checkLen;
  186637. rb->dataStartOffset = i;
  186638. rb->dataLength -= i;
  186639. rb->startFrame = overlapBuffer->startFrame + framesToCheck;
  186640. found = true;
  186641. break;
  186642. }
  186643. }
  186644. rb->numFrames = rb->dataLength / 2352;
  186645. rb->dataLength = 2352 * rb->numFrames;
  186646. if (!found)
  186647. return false;
  186648. }
  186649. if (canDoJitter)
  186650. {
  186651. memcpy (overlapBuffer->buffer,
  186652. rb->buffer + rb->dataStartOffset + 2352 * (rb->numFrames - framesToCheck),
  186653. 2352 * framesToCheck);
  186654. overlapBuffer->startFrame = rb->startFrame + rb->numFrames - framesToCheck;
  186655. overlapBuffer->numFrames = framesToCheck;
  186656. overlapBuffer->dataLength = 2352 * framesToCheck;
  186657. overlapBuffer->dataStartOffset = 0;
  186658. }
  186659. else
  186660. {
  186661. overlapBuffer->startFrame = 0;
  186662. overlapBuffer->numFrames = 0;
  186663. overlapBuffer->dataLength = 0;
  186664. }
  186665. return true;
  186666. }
  186667. else
  186668. {
  186669. return read (rb);
  186670. }
  186671. }
  186672. int CDController::getLastIndex()
  186673. {
  186674. char qdata[100];
  186675. SRB_ExecSCSICmd s;
  186676. prepare (s);
  186677. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186678. s.SRB_BufLen = sizeof (qdata);
  186679. s.SRB_BufPointer = (BYTE*)qdata;
  186680. s.SRB_CDBLen = 12;
  186681. s.CDBByte[0] = 0x42;
  186682. s.CDBByte[1] = (BYTE)(deviceInfo->info.lun << 5);
  186683. s.CDBByte[2] = 64;
  186684. s.CDBByte[3] = 1; // get current position
  186685. s.CDBByte[7] = 0;
  186686. s.CDBByte[8] = (BYTE)sizeof (qdata);
  186687. perform (s);
  186688. if (s.SRB_Status == SS_COMP)
  186689. return qdata[7];
  186690. return 0;
  186691. }
  186692. bool CDDeviceHandle::readTOC (TOC* lpToc, bool useMSF)
  186693. {
  186694. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  186695. SRB_ExecSCSICmd s;
  186696. zerostruct (s);
  186697. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  186698. s.SRB_HaID = info.ha;
  186699. s.SRB_Target = info.tgt;
  186700. s.SRB_Lun = info.lun;
  186701. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186702. s.SRB_BufLen = 0x324;
  186703. s.SRB_BufPointer = (BYTE*)lpToc;
  186704. s.SRB_SenseLen = 0x0E;
  186705. s.SRB_CDBLen = 0x0A;
  186706. s.SRB_PostProc = (void*)event;
  186707. s.CDBByte[0] = 0x43;
  186708. s.CDBByte[1] = (BYTE)(useMSF ? 0x02 : 0x00);
  186709. s.CDBByte[7] = 0x03;
  186710. s.CDBByte[8] = 0x24;
  186711. ResetEvent (event);
  186712. DWORD status = (usingScsi) ? performScsiPassThroughCommand ((LPSRB_ExecSCSICmd)&s, info.scsiDriveLetter, scsiHandle)
  186713. : fSendASPI32Command ((LPSRB)&s);
  186714. if (status == SS_PENDING)
  186715. WaitForSingleObject (event, 4000);
  186716. CloseHandle (event);
  186717. return (s.SRB_Status == SS_COMP);
  186718. }
  186719. bool CDDeviceHandle::readAudio (CDReadBuffer* const buffer,
  186720. CDReadBuffer* const overlapBuffer)
  186721. {
  186722. if (controller == 0)
  186723. {
  186724. testController (READTYPE_ATAPI2, new ControllerType1(), buffer)
  186725. || testController (READTYPE_ATAPI1, new ControllerType1(), buffer)
  186726. || testController (READTYPE_READ10_2, new ControllerType2(), buffer)
  186727. || testController (READTYPE_READ10, new ControllerType2(), buffer)
  186728. || testController (READTYPE_READ_D8, new ControllerType3(), buffer)
  186729. || testController (READTYPE_READ_D4, new ControllerType4(), buffer)
  186730. || testController (READTYPE_READ_D4_1, new ControllerType4(), buffer);
  186731. }
  186732. buffer->index = 0;
  186733. if ((controller != 0)
  186734. && controller->readAudio (buffer, overlapBuffer))
  186735. {
  186736. if (buffer->wantsIndex)
  186737. buffer->index = controller->getLastIndex();
  186738. return true;
  186739. }
  186740. return false;
  186741. }
  186742. void CDDeviceHandle::openDrawer (bool shouldBeOpen)
  186743. {
  186744. if (shouldBeOpen)
  186745. {
  186746. if (controller != 0)
  186747. {
  186748. controller->shutDown();
  186749. controller = 0;
  186750. }
  186751. if (scsiHandle != 0)
  186752. {
  186753. CloseHandle (scsiHandle);
  186754. scsiHandle = 0;
  186755. }
  186756. }
  186757. SRB_ExecSCSICmd s;
  186758. zerostruct (s);
  186759. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  186760. s.SRB_HaID = info.ha;
  186761. s.SRB_Target = info.tgt;
  186762. s.SRB_Lun = info.lun;
  186763. s.SRB_SenseLen = SENSE_LEN;
  186764. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186765. s.SRB_BufLen = 0;
  186766. s.SRB_BufPointer = 0;
  186767. s.SRB_CDBLen = 12;
  186768. s.CDBByte[0] = 0x1b;
  186769. s.CDBByte[1] = (BYTE)(info.lun << 5);
  186770. s.CDBByte[4] = (BYTE)((shouldBeOpen) ? 2 : 3);
  186771. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  186772. s.SRB_PostProc = (void*)event;
  186773. ResetEvent (event);
  186774. DWORD status = (usingScsi) ? performScsiPassThroughCommand ((LPSRB_ExecSCSICmd)&s, info.scsiDriveLetter, scsiHandle)
  186775. : fSendASPI32Command ((LPSRB)&s);
  186776. if (status == SS_PENDING)
  186777. WaitForSingleObject (event, 4000);
  186778. CloseHandle (event);
  186779. }
  186780. bool CDDeviceHandle::testController (const int type,
  186781. CDController* const newController,
  186782. CDReadBuffer* const rb)
  186783. {
  186784. controller = newController;
  186785. readType = (BYTE)type;
  186786. controller->deviceInfo = this;
  186787. controller->framesToCheck = 1;
  186788. controller->framesOverlap = 3;
  186789. bool passed = false;
  186790. memset (rb->buffer, 0xcd, rb->bufferSize);
  186791. if (controller->read (rb))
  186792. {
  186793. passed = true;
  186794. int* p = (int*) (rb->buffer + rb->dataStartOffset);
  186795. int wrong = 0;
  186796. for (int i = rb->dataLength / 4; --i >= 0;)
  186797. {
  186798. if (*p++ == (int) 0xcdcdcdcd)
  186799. {
  186800. if (++wrong == 4)
  186801. {
  186802. passed = false;
  186803. break;
  186804. }
  186805. }
  186806. else
  186807. {
  186808. wrong = 0;
  186809. }
  186810. }
  186811. }
  186812. if (! passed)
  186813. {
  186814. controller->shutDown();
  186815. controller = 0;
  186816. }
  186817. return passed;
  186818. }
  186819. static void GetAspiDeviceInfo (CDDeviceInfo* dev, BYTE ha, BYTE tgt, BYTE lun)
  186820. {
  186821. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  186822. const int bufSize = 128;
  186823. BYTE buffer[bufSize];
  186824. zeromem (buffer, bufSize);
  186825. SRB_ExecSCSICmd s;
  186826. zerostruct (s);
  186827. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  186828. s.SRB_HaID = ha;
  186829. s.SRB_Target = tgt;
  186830. s.SRB_Lun = lun;
  186831. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186832. s.SRB_BufLen = bufSize;
  186833. s.SRB_BufPointer = buffer;
  186834. s.SRB_SenseLen = SENSE_LEN;
  186835. s.SRB_CDBLen = 6;
  186836. s.SRB_PostProc = (void*)event;
  186837. s.CDBByte[0] = SCSI_INQUIRY;
  186838. s.CDBByte[4] = 100;
  186839. ResetEvent (event);
  186840. if (fSendASPI32Command ((LPSRB)&s) == SS_PENDING)
  186841. WaitForSingleObject (event, 4000);
  186842. CloseHandle (event);
  186843. if (s.SRB_Status == SS_COMP)
  186844. {
  186845. memcpy (dev->vendor, &buffer[8], 8);
  186846. memcpy (dev->productId, &buffer[16], 16);
  186847. memcpy (dev->rev, &buffer[32], 4);
  186848. memcpy (dev->vendorSpec, &buffer[36], 20);
  186849. }
  186850. }
  186851. static int FindCDDevices (CDDeviceInfo* const list,
  186852. int maxItems)
  186853. {
  186854. int count = 0;
  186855. if (usingScsi)
  186856. {
  186857. for (char driveLetter = 'b'; driveLetter <= 'z'; ++driveLetter)
  186858. {
  186859. TCHAR drivePath[8];
  186860. drivePath[0] = driveLetter;
  186861. drivePath[1] = ':';
  186862. drivePath[2] = '\\';
  186863. drivePath[3] = 0;
  186864. if (GetDriveType (drivePath) == DRIVE_CDROM)
  186865. {
  186866. HANDLE h = CreateSCSIDeviceHandle (driveLetter);
  186867. if (h != INVALID_HANDLE_VALUE)
  186868. {
  186869. BYTE buffer[100], passThroughStruct[1024];
  186870. zeromem (buffer, sizeof (buffer));
  186871. zeromem (passThroughStruct, sizeof (passThroughStruct));
  186872. PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER p = (PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER)passThroughStruct;
  186873. p->spt.Length = sizeof (SCSI_PASS_THROUGH);
  186874. p->spt.CdbLength = 6;
  186875. p->spt.SenseInfoLength = 24;
  186876. p->spt.DataIn = SCSI_IOCTL_DATA_IN;
  186877. p->spt.DataTransferLength = 100;
  186878. p->spt.TimeOutValue = 2;
  186879. p->spt.DataBuffer = buffer;
  186880. p->spt.SenseInfoOffset = offsetof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, ucSenseBuf);
  186881. p->spt.Cdb[0] = 0x12;
  186882. p->spt.Cdb[4] = 100;
  186883. DWORD bytesReturned = 0;
  186884. if (DeviceIoControl (h, IOCTL_SCSI_PASS_THROUGH_DIRECT,
  186885. p, sizeof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER),
  186886. p, sizeof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER),
  186887. &bytesReturned, 0) != 0)
  186888. {
  186889. zeromem (&list[count], sizeof (CDDeviceInfo));
  186890. list[count].scsiDriveLetter = driveLetter;
  186891. memcpy (list[count].vendor, &buffer[8], 8);
  186892. memcpy (list[count].productId, &buffer[16], 16);
  186893. memcpy (list[count].rev, &buffer[32], 4);
  186894. memcpy (list[count].vendorSpec, &buffer[36], 20);
  186895. zeromem (passThroughStruct, sizeof (passThroughStruct));
  186896. PSCSI_ADDRESS scsiAddr = (PSCSI_ADDRESS)passThroughStruct;
  186897. scsiAddr->Length = sizeof (SCSI_ADDRESS);
  186898. if (DeviceIoControl (h, IOCTL_SCSI_GET_ADDRESS,
  186899. 0, 0, scsiAddr, sizeof (SCSI_ADDRESS),
  186900. &bytesReturned, 0) != 0)
  186901. {
  186902. list[count].ha = scsiAddr->PortNumber;
  186903. list[count].tgt = scsiAddr->TargetId;
  186904. list[count].lun = scsiAddr->Lun;
  186905. ++count;
  186906. }
  186907. }
  186908. CloseHandle (h);
  186909. }
  186910. }
  186911. }
  186912. }
  186913. else
  186914. {
  186915. const DWORD d = fGetASPI32SupportInfo();
  186916. BYTE status = HIBYTE (LOWORD (d));
  186917. if (status != SS_COMP || status == SS_NO_ADAPTERS)
  186918. return 0;
  186919. const int numAdapters = LOBYTE (LOWORD (d));
  186920. for (BYTE ha = 0; ha < numAdapters; ++ha)
  186921. {
  186922. SRB_HAInquiry s;
  186923. zerostruct (s);
  186924. s.SRB_Cmd = SC_HA_INQUIRY;
  186925. s.SRB_HaID = ha;
  186926. fSendASPI32Command ((LPSRB)&s);
  186927. if (s.SRB_Status == SS_COMP)
  186928. {
  186929. maxItems = (int)s.HA_Unique[3];
  186930. if (maxItems == 0)
  186931. maxItems = 8;
  186932. for (BYTE tgt = 0; tgt < maxItems; ++tgt)
  186933. {
  186934. for (BYTE lun = 0; lun < 8; ++lun)
  186935. {
  186936. SRB_GDEVBlock sb;
  186937. zerostruct (sb);
  186938. sb.SRB_Cmd = SC_GET_DEV_TYPE;
  186939. sb.SRB_HaID = ha;
  186940. sb.SRB_Target = tgt;
  186941. sb.SRB_Lun = lun;
  186942. fSendASPI32Command ((LPSRB) &sb);
  186943. if (sb.SRB_Status == SS_COMP
  186944. && sb.SRB_DeviceType == DTYPE_CROM)
  186945. {
  186946. zeromem (&list[count], sizeof (CDDeviceInfo));
  186947. list[count].ha = ha;
  186948. list[count].tgt = tgt;
  186949. list[count].lun = lun;
  186950. GetAspiDeviceInfo (&(list[count]), ha, tgt, lun);
  186951. ++count;
  186952. }
  186953. }
  186954. }
  186955. }
  186956. }
  186957. }
  186958. return count;
  186959. }
  186960. static int ripperUsers = 0;
  186961. static bool initialisedOk = false;
  186962. class DeinitialiseTimer : private Timer,
  186963. private DeletedAtShutdown
  186964. {
  186965. DeinitialiseTimer (const DeinitialiseTimer&);
  186966. DeinitialiseTimer& operator= (const DeinitialiseTimer&);
  186967. public:
  186968. DeinitialiseTimer()
  186969. {
  186970. startTimer (4000);
  186971. }
  186972. ~DeinitialiseTimer()
  186973. {
  186974. if (--ripperUsers == 0)
  186975. DeinitialiseCDRipper();
  186976. }
  186977. void timerCallback()
  186978. {
  186979. delete this;
  186980. }
  186981. juce_UseDebuggingNewOperator
  186982. };
  186983. static void incUserCount()
  186984. {
  186985. if (ripperUsers++ == 0)
  186986. initialisedOk = InitialiseCDRipper();
  186987. }
  186988. static void decUserCount()
  186989. {
  186990. new DeinitialiseTimer();
  186991. }
  186992. struct CDDeviceWrapper
  186993. {
  186994. ScopedPointer<CDDeviceHandle> cdH;
  186995. ScopedPointer<CDReadBuffer> overlapBuffer;
  186996. bool jitter;
  186997. };
  186998. static int getAddressOf (const TOCTRACK* const t)
  186999. {
  187000. return (((DWORD)t->addr[0]) << 24) + (((DWORD)t->addr[1]) << 16) +
  187001. (((DWORD)t->addr[2]) << 8) + ((DWORD)t->addr[3]);
  187002. }
  187003. static int getMSFAddressOf (const TOCTRACK* const t)
  187004. {
  187005. return 60 * t->addr[1] + t->addr[2];
  187006. }
  187007. static const int samplesPerFrame = 44100 / 75;
  187008. static const int bytesPerFrame = samplesPerFrame * 4;
  187009. static CDDeviceHandle* openHandle (const CDDeviceInfo* const device)
  187010. {
  187011. SRB_GDEVBlock s;
  187012. zerostruct (s);
  187013. s.SRB_Cmd = SC_GET_DEV_TYPE;
  187014. s.SRB_HaID = device->ha;
  187015. s.SRB_Target = device->tgt;
  187016. s.SRB_Lun = device->lun;
  187017. if (usingScsi)
  187018. {
  187019. HANDLE h = CreateSCSIDeviceHandle (device->scsiDriveLetter);
  187020. if (h != INVALID_HANDLE_VALUE)
  187021. {
  187022. CDDeviceHandle* cdh = new CDDeviceHandle (device);
  187023. cdh->scsiHandle = h;
  187024. return cdh;
  187025. }
  187026. }
  187027. else
  187028. {
  187029. if (fSendASPI32Command ((LPSRB)&s) == SS_COMP
  187030. && s.SRB_DeviceType == DTYPE_CROM)
  187031. {
  187032. return new CDDeviceHandle (device);
  187033. }
  187034. }
  187035. return 0;
  187036. }
  187037. }
  187038. const StringArray AudioCDReader::getAvailableCDNames()
  187039. {
  187040. using namespace CDReaderHelpers;
  187041. StringArray results;
  187042. incUserCount();
  187043. if (initialisedOk)
  187044. {
  187045. CDDeviceInfo list[8];
  187046. const int num = FindCDDevices (list, 8);
  187047. decUserCount();
  187048. for (int i = 0; i < num; ++i)
  187049. {
  187050. String s;
  187051. if (list[i].scsiDriveLetter > 0)
  187052. s << String::charToString (list[i].scsiDriveLetter).toUpperCase() << T(": ");
  187053. s << String (list[i].vendor).trim()
  187054. << T(" ") << String (list[i].productId).trim()
  187055. << T(" ") << String (list[i].rev).trim();
  187056. results.add (s);
  187057. }
  187058. }
  187059. return results;
  187060. }
  187061. AudioCDReader* AudioCDReader::createReaderForCD (const int deviceIndex)
  187062. {
  187063. using namespace CDReaderHelpers;
  187064. incUserCount();
  187065. if (initialisedOk)
  187066. {
  187067. CDDeviceInfo list[8];
  187068. const int num = FindCDDevices (list, 8);
  187069. if (((unsigned int) deviceIndex) < (unsigned int) num)
  187070. {
  187071. CDDeviceHandle* const handle = openHandle (&(list[deviceIndex]));
  187072. if (handle != 0)
  187073. {
  187074. CDDeviceWrapper* const d = new CDDeviceWrapper();
  187075. d->cdH = handle;
  187076. d->overlapBuffer = new CDReadBuffer(3);
  187077. return new AudioCDReader (d);
  187078. }
  187079. }
  187080. }
  187081. decUserCount();
  187082. return 0;
  187083. }
  187084. AudioCDReader::AudioCDReader (void* handle_)
  187085. : AudioFormatReader (0, T("CD Audio")),
  187086. handle (handle_),
  187087. indexingEnabled (false),
  187088. lastIndex (0),
  187089. firstFrameInBuffer (0),
  187090. samplesInBuffer (0)
  187091. {
  187092. using namespace CDReaderHelpers;
  187093. jassert (handle_ != 0);
  187094. refreshTrackLengths();
  187095. sampleRate = 44100.0;
  187096. bitsPerSample = 16;
  187097. lengthInSamples = getPositionOfTrackStart (numTracks);
  187098. numChannels = 2;
  187099. usesFloatingPointData = false;
  187100. buffer.setSize (4 * bytesPerFrame, true);
  187101. }
  187102. AudioCDReader::~AudioCDReader()
  187103. {
  187104. using namespace CDReaderHelpers;
  187105. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  187106. delete device;
  187107. decUserCount();
  187108. }
  187109. bool AudioCDReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  187110. int64 startSampleInFile, int numSamples)
  187111. {
  187112. using namespace CDReaderHelpers;
  187113. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  187114. bool ok = true;
  187115. while (numSamples > 0)
  187116. {
  187117. const int bufferStartSample = firstFrameInBuffer * samplesPerFrame;
  187118. const int bufferEndSample = bufferStartSample + samplesInBuffer;
  187119. if (startSampleInFile >= bufferStartSample
  187120. && startSampleInFile < bufferEndSample)
  187121. {
  187122. const int toDo = (int) jmin ((int64) numSamples, bufferEndSample - startSampleInFile);
  187123. int* const l = destSamples[0] + startOffsetInDestBuffer;
  187124. int* const r = numDestChannels > 1 ? (destSamples[1] + startOffsetInDestBuffer) : 0;
  187125. const short* src = (const short*) buffer.getData();
  187126. src += 2 * (startSampleInFile - bufferStartSample);
  187127. for (int i = 0; i < toDo; ++i)
  187128. {
  187129. l[i] = src [i << 1] << 16;
  187130. if (r != 0)
  187131. r[i] = src [(i << 1) + 1] << 16;
  187132. }
  187133. startOffsetInDestBuffer += toDo;
  187134. startSampleInFile += toDo;
  187135. numSamples -= toDo;
  187136. }
  187137. else
  187138. {
  187139. const int framesInBuffer = buffer.getSize() / bytesPerFrame;
  187140. const int frameNeeded = (int) (startSampleInFile / samplesPerFrame);
  187141. if (firstFrameInBuffer + framesInBuffer != frameNeeded)
  187142. {
  187143. device->overlapBuffer->dataLength = 0;
  187144. device->overlapBuffer->startFrame = 0;
  187145. device->overlapBuffer->numFrames = 0;
  187146. device->jitter = false;
  187147. }
  187148. firstFrameInBuffer = frameNeeded;
  187149. lastIndex = 0;
  187150. CDReadBuffer readBuffer (framesInBuffer + 4);
  187151. readBuffer.wantsIndex = indexingEnabled;
  187152. int i;
  187153. for (i = 5; --i >= 0;)
  187154. {
  187155. readBuffer.startFrame = frameNeeded;
  187156. readBuffer.numFrames = framesInBuffer;
  187157. if (device->cdH->readAudio (&readBuffer, (device->jitter) ? device->overlapBuffer : 0))
  187158. break;
  187159. else
  187160. device->overlapBuffer->dataLength = 0;
  187161. }
  187162. if (i >= 0)
  187163. {
  187164. memcpy ((char*) buffer.getData(),
  187165. readBuffer.buffer + readBuffer.dataStartOffset,
  187166. readBuffer.dataLength);
  187167. samplesInBuffer = readBuffer.dataLength >> 2;
  187168. lastIndex = readBuffer.index;
  187169. }
  187170. else
  187171. {
  187172. int* l = destSamples[0] + startOffsetInDestBuffer;
  187173. int* r = numDestChannels > 1 ? (destSamples[1] + startOffsetInDestBuffer) : 0;
  187174. while (--numSamples >= 0)
  187175. {
  187176. *l++ = 0;
  187177. if (r != 0)
  187178. *r++ = 0;
  187179. }
  187180. // sometimes the read fails for just the very last couple of blocks, so
  187181. // we'll ignore and errors in the last half-second of the disk..
  187182. ok = startSampleInFile > (trackStarts [numTracks] - 20000);
  187183. break;
  187184. }
  187185. }
  187186. }
  187187. return ok;
  187188. }
  187189. bool AudioCDReader::isCDStillPresent() const
  187190. {
  187191. using namespace CDReaderHelpers;
  187192. TOC toc;
  187193. zerostruct (toc);
  187194. return ((CDDeviceWrapper*) handle)->cdH->readTOC (&toc, false);
  187195. }
  187196. int AudioCDReader::getNumTracks() const
  187197. {
  187198. return numTracks;
  187199. }
  187200. int AudioCDReader::getPositionOfTrackStart (int trackNum) const
  187201. {
  187202. using namespace CDReaderHelpers;
  187203. return (trackNum >= 0 && trackNum <= numTracks) ? trackStarts [trackNum] * samplesPerFrame
  187204. : 0;
  187205. }
  187206. void AudioCDReader::refreshTrackLengths()
  187207. {
  187208. using namespace CDReaderHelpers;
  187209. zeromem (trackStarts, sizeof (trackStarts));
  187210. zeromem (audioTracks, sizeof (audioTracks));
  187211. TOC toc;
  187212. zerostruct (toc);
  187213. if (((CDDeviceWrapper*)handle)->cdH->readTOC (&toc, false))
  187214. {
  187215. numTracks = 1 + toc.lastTrack - toc.firstTrack;
  187216. for (int i = 0; i <= numTracks; ++i)
  187217. {
  187218. trackStarts[i] = getAddressOf (&toc.tracks[i]);
  187219. audioTracks[i] = ((toc.tracks[i].ADR & 4) == 0);
  187220. }
  187221. }
  187222. else
  187223. {
  187224. numTracks = 0;
  187225. }
  187226. }
  187227. bool AudioCDReader::isTrackAudio (int trackNum) const
  187228. {
  187229. return (trackNum >= 0 && trackNum <= numTracks) ? audioTracks [trackNum]
  187230. : false;
  187231. }
  187232. void AudioCDReader::enableIndexScanning (bool b)
  187233. {
  187234. indexingEnabled = b;
  187235. }
  187236. int AudioCDReader::getLastIndex() const
  187237. {
  187238. return lastIndex;
  187239. }
  187240. const int framesPerIndexRead = 4;
  187241. int AudioCDReader::getIndexAt (int samplePos)
  187242. {
  187243. using namespace CDReaderHelpers;
  187244. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  187245. const int frameNeeded = samplePos / samplesPerFrame;
  187246. device->overlapBuffer->dataLength = 0;
  187247. device->overlapBuffer->startFrame = 0;
  187248. device->overlapBuffer->numFrames = 0;
  187249. device->jitter = false;
  187250. firstFrameInBuffer = 0;
  187251. lastIndex = 0;
  187252. CDReadBuffer readBuffer (4 + framesPerIndexRead);
  187253. readBuffer.wantsIndex = true;
  187254. int i;
  187255. for (i = 5; --i >= 0;)
  187256. {
  187257. readBuffer.startFrame = frameNeeded;
  187258. readBuffer.numFrames = framesPerIndexRead;
  187259. if (device->cdH->readAudio (&readBuffer, (false) ? device->overlapBuffer : 0))
  187260. break;
  187261. }
  187262. if (i >= 0)
  187263. return readBuffer.index;
  187264. return -1;
  187265. }
  187266. const Array <int> AudioCDReader::findIndexesInTrack (const int trackNumber)
  187267. {
  187268. using namespace CDReaderHelpers;
  187269. Array <int> indexes;
  187270. const int trackStart = getPositionOfTrackStart (trackNumber);
  187271. const int trackEnd = getPositionOfTrackStart (trackNumber + 1);
  187272. bool needToScan = true;
  187273. if (trackEnd - trackStart > 20 * 44100)
  187274. {
  187275. // check the end of the track for indexes before scanning the whole thing
  187276. needToScan = false;
  187277. int pos = jmax (trackStart, trackEnd - 44100 * 5);
  187278. bool seenAnIndex = false;
  187279. while (pos <= trackEnd - samplesPerFrame)
  187280. {
  187281. const int index = getIndexAt (pos);
  187282. if (index == 0)
  187283. {
  187284. // lead-out, so skip back a bit if we've not found any indexes yet..
  187285. if (seenAnIndex)
  187286. break;
  187287. pos -= 44100 * 5;
  187288. if (pos < trackStart)
  187289. break;
  187290. }
  187291. else
  187292. {
  187293. if (index > 0)
  187294. seenAnIndex = true;
  187295. if (index > 1)
  187296. {
  187297. needToScan = true;
  187298. break;
  187299. }
  187300. pos += samplesPerFrame * framesPerIndexRead;
  187301. }
  187302. }
  187303. }
  187304. if (needToScan)
  187305. {
  187306. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  187307. int pos = trackStart;
  187308. int last = -1;
  187309. while (pos < trackEnd - samplesPerFrame * 10)
  187310. {
  187311. const int frameNeeded = pos / samplesPerFrame;
  187312. device->overlapBuffer->dataLength = 0;
  187313. device->overlapBuffer->startFrame = 0;
  187314. device->overlapBuffer->numFrames = 0;
  187315. device->jitter = false;
  187316. firstFrameInBuffer = 0;
  187317. CDReadBuffer readBuffer (4);
  187318. readBuffer.wantsIndex = true;
  187319. int i;
  187320. for (i = 5; --i >= 0;)
  187321. {
  187322. readBuffer.startFrame = frameNeeded;
  187323. readBuffer.numFrames = framesPerIndexRead;
  187324. if (device->cdH->readAudio (&readBuffer, (false) ? device->overlapBuffer : 0))
  187325. break;
  187326. }
  187327. if (i < 0)
  187328. break;
  187329. if (readBuffer.index > last && readBuffer.index > 1)
  187330. {
  187331. last = readBuffer.index;
  187332. indexes.add (pos);
  187333. }
  187334. pos += samplesPerFrame * framesPerIndexRead;
  187335. }
  187336. indexes.removeValue (trackStart);
  187337. }
  187338. return indexes;
  187339. }
  187340. int AudioCDReader::getCDDBId()
  187341. {
  187342. using namespace CDReaderHelpers;
  187343. refreshTrackLengths();
  187344. if (numTracks > 0)
  187345. {
  187346. TOC toc;
  187347. zerostruct (toc);
  187348. if (((CDDeviceWrapper*) handle)->cdH->readTOC (&toc, true))
  187349. {
  187350. int n = 0;
  187351. for (int i = numTracks; --i >= 0;)
  187352. {
  187353. int j = getMSFAddressOf (&toc.tracks[i]);
  187354. while (j > 0)
  187355. {
  187356. n += (j % 10);
  187357. j /= 10;
  187358. }
  187359. }
  187360. if (n != 0)
  187361. {
  187362. const int t = getMSFAddressOf (&toc.tracks[numTracks])
  187363. - getMSFAddressOf (&toc.tracks[0]);
  187364. return ((n % 0xff) << 24) | (t << 8) | numTracks;
  187365. }
  187366. }
  187367. }
  187368. return 0;
  187369. }
  187370. void AudioCDReader::ejectDisk()
  187371. {
  187372. using namespace CDReaderHelpers;
  187373. ((CDDeviceWrapper*) handle)->cdH->openDrawer (true);
  187374. }
  187375. #endif
  187376. #if JUCE_USE_CDBURNER
  187377. static IDiscRecorder* enumCDBurners (StringArray* list, int indexToOpen, IDiscMaster** master)
  187378. {
  187379. CoInitialize (0);
  187380. IDiscMaster* dm;
  187381. IDiscRecorder* result = 0;
  187382. if (SUCCEEDED (CoCreateInstance (CLSID_MSDiscMasterObj, 0,
  187383. CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER,
  187384. IID_IDiscMaster,
  187385. (void**) &dm)))
  187386. {
  187387. if (SUCCEEDED (dm->Open()))
  187388. {
  187389. IEnumDiscRecorders* drEnum = 0;
  187390. if (SUCCEEDED (dm->EnumDiscRecorders (&drEnum)))
  187391. {
  187392. IDiscRecorder* dr = 0;
  187393. DWORD dummy;
  187394. int index = 0;
  187395. while (drEnum->Next (1, &dr, &dummy) == S_OK)
  187396. {
  187397. if (indexToOpen == index)
  187398. {
  187399. result = dr;
  187400. break;
  187401. }
  187402. else if (list != 0)
  187403. {
  187404. BSTR path;
  187405. if (SUCCEEDED (dr->GetPath (&path)))
  187406. list->add ((const WCHAR*) path);
  187407. }
  187408. ++index;
  187409. dr->Release();
  187410. }
  187411. drEnum->Release();
  187412. }
  187413. if (master == 0)
  187414. dm->Close();
  187415. }
  187416. if (master != 0)
  187417. *master = dm;
  187418. else
  187419. dm->Release();
  187420. }
  187421. return result;
  187422. }
  187423. class AudioCDBurner::Pimpl : public IDiscMasterProgressEvents,
  187424. public Timer
  187425. {
  187426. public:
  187427. Pimpl (AudioCDBurner& owner_, IDiscMaster* discMaster_, IDiscRecorder* discRecorder_)
  187428. : owner (owner_), discMaster (discMaster_), discRecorder (discRecorder_), redbook (0),
  187429. listener (0), progress (0), shouldCancel (false), refCount (1)
  187430. {
  187431. HRESULT hr = discMaster->SetActiveDiscMasterFormat (IID_IRedbookDiscMaster, (void**) &redbook);
  187432. jassert (SUCCEEDED (hr));
  187433. hr = discMaster->SetActiveDiscRecorder (discRecorder);
  187434. //jassert (SUCCEEDED (hr));
  187435. lastState = getDiskState();
  187436. startTimer (2000);
  187437. }
  187438. ~Pimpl() {}
  187439. void releaseObjects()
  187440. {
  187441. discRecorder->Close();
  187442. if (redbook != 0)
  187443. redbook->Release();
  187444. discRecorder->Release();
  187445. discMaster->Release();
  187446. Release();
  187447. }
  187448. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  187449. {
  187450. if (result == 0)
  187451. return E_POINTER;
  187452. if (id == IID_IUnknown || id == IID_IDiscMasterProgressEvents)
  187453. {
  187454. AddRef();
  187455. *result = this;
  187456. return S_OK;
  187457. }
  187458. *result = 0;
  187459. return E_NOINTERFACE;
  187460. }
  187461. ULONG __stdcall AddRef() { return ++refCount; }
  187462. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  187463. HRESULT __stdcall QueryCancel (boolean* pbCancel)
  187464. {
  187465. if (listener != 0 && ! shouldCancel)
  187466. shouldCancel = listener->audioCDBurnProgress (progress);
  187467. *pbCancel = shouldCancel;
  187468. return S_OK;
  187469. }
  187470. HRESULT __stdcall NotifyBlockProgress (long nCompleted, long nTotal)
  187471. {
  187472. progress = nCompleted / (float) nTotal;
  187473. shouldCancel = listener != 0 && listener->audioCDBurnProgress (progress);
  187474. return E_NOTIMPL;
  187475. }
  187476. HRESULT __stdcall NotifyPnPActivity (void) { return E_NOTIMPL; }
  187477. HRESULT __stdcall NotifyAddProgress (long /*nCompletedSteps*/, long /*nTotalSteps*/) { return E_NOTIMPL; }
  187478. HRESULT __stdcall NotifyTrackProgress (long /*nCurrentTrack*/, long /*nTotalTracks*/) { return E_NOTIMPL; }
  187479. HRESULT __stdcall NotifyPreparingBurn (long /*nEstimatedSeconds*/) { return E_NOTIMPL; }
  187480. HRESULT __stdcall NotifyClosingDisc (long /*nEstimatedSeconds*/) { return E_NOTIMPL; }
  187481. HRESULT __stdcall NotifyBurnComplete (HRESULT /*status*/) { return E_NOTIMPL; }
  187482. HRESULT __stdcall NotifyEraseComplete (HRESULT /*status*/) { return E_NOTIMPL; }
  187483. class ScopedDiscOpener
  187484. {
  187485. public:
  187486. ScopedDiscOpener (Pimpl& p) : pimpl (p) { pimpl.discRecorder->OpenExclusive(); }
  187487. ~ScopedDiscOpener() { pimpl.discRecorder->Close(); }
  187488. private:
  187489. Pimpl& pimpl;
  187490. ScopedDiscOpener (const ScopedDiscOpener&);
  187491. ScopedDiscOpener& operator= (const ScopedDiscOpener&);
  187492. };
  187493. DiskState getDiskState()
  187494. {
  187495. const ScopedDiscOpener opener (*this);
  187496. long type, flags;
  187497. HRESULT hr = discRecorder->QueryMediaType (&type, &flags);
  187498. if (FAILED (hr))
  187499. return unknown;
  187500. if (type != 0 && (flags & MEDIA_WRITABLE) != 0)
  187501. return writableDiskPresent;
  187502. if (type == 0)
  187503. return noDisc;
  187504. else
  187505. return readOnlyDiskPresent;
  187506. }
  187507. int getIntProperty (const LPOLESTR name, const int defaultReturn) const
  187508. {
  187509. ComSmartPtr<IPropertyStorage> prop;
  187510. if (FAILED (discRecorder->GetRecorderProperties (&prop)))
  187511. return defaultReturn;
  187512. PROPSPEC iPropSpec;
  187513. iPropSpec.ulKind = PRSPEC_LPWSTR;
  187514. iPropSpec.lpwstr = name;
  187515. PROPVARIANT iPropVariant;
  187516. return FAILED (prop->ReadMultiple (1, &iPropSpec, &iPropVariant))
  187517. ? defaultReturn : (int) iPropVariant.lVal;
  187518. }
  187519. bool setIntProperty (const LPOLESTR name, const int value) const
  187520. {
  187521. ComSmartPtr<IPropertyStorage> prop;
  187522. if (FAILED (discRecorder->GetRecorderProperties (&prop)))
  187523. return false;
  187524. PROPSPEC iPropSpec;
  187525. iPropSpec.ulKind = PRSPEC_LPWSTR;
  187526. iPropSpec.lpwstr = name;
  187527. PROPVARIANT iPropVariant;
  187528. if (FAILED (prop->ReadMultiple (1, &iPropSpec, &iPropVariant)))
  187529. return false;
  187530. iPropVariant.lVal = (long) value;
  187531. return SUCCEEDED (prop->WriteMultiple (1, &iPropSpec, &iPropVariant, iPropVariant.vt))
  187532. && SUCCEEDED (discRecorder->SetRecorderProperties (prop));
  187533. }
  187534. void timerCallback()
  187535. {
  187536. const DiskState state = getDiskState();
  187537. if (state != lastState)
  187538. {
  187539. lastState = state;
  187540. owner.sendChangeMessage (&owner);
  187541. }
  187542. }
  187543. AudioCDBurner& owner;
  187544. DiskState lastState;
  187545. IDiscMaster* discMaster;
  187546. IDiscRecorder* discRecorder;
  187547. IRedbookDiscMaster* redbook;
  187548. AudioCDBurner::BurnProgressListener* listener;
  187549. float progress;
  187550. bool shouldCancel;
  187551. private:
  187552. int refCount;
  187553. };
  187554. AudioCDBurner::AudioCDBurner (const int deviceIndex)
  187555. {
  187556. IDiscMaster* discMaster = 0;
  187557. IDiscRecorder* discRecorder = enumCDBurners (0, deviceIndex, &discMaster);
  187558. if (discRecorder != 0)
  187559. pimpl = new Pimpl (*this, discMaster, discRecorder);
  187560. }
  187561. AudioCDBurner::~AudioCDBurner()
  187562. {
  187563. if (pimpl != 0)
  187564. pimpl.release()->releaseObjects();
  187565. }
  187566. const StringArray AudioCDBurner::findAvailableDevices()
  187567. {
  187568. StringArray devs;
  187569. enumCDBurners (&devs, -1, 0);
  187570. return devs;
  187571. }
  187572. AudioCDBurner* AudioCDBurner::openDevice (const int deviceIndex)
  187573. {
  187574. ScopedPointer<AudioCDBurner> b (new AudioCDBurner (deviceIndex));
  187575. if (b->pimpl == 0)
  187576. b = 0;
  187577. return b.release();
  187578. }
  187579. AudioCDBurner::DiskState AudioCDBurner::getDiskState() const
  187580. {
  187581. return pimpl->getDiskState();
  187582. }
  187583. bool AudioCDBurner::isDiskPresent() const
  187584. {
  187585. return getDiskState() == writableDiskPresent;
  187586. }
  187587. bool AudioCDBurner::openTray()
  187588. {
  187589. const Pimpl::ScopedDiscOpener opener (*pimpl);
  187590. return SUCCEEDED (pimpl->discRecorder->Eject());
  187591. }
  187592. AudioCDBurner::DiskState AudioCDBurner::waitUntilStateChange (int timeOutMilliseconds)
  187593. {
  187594. const int64 timeout = Time::currentTimeMillis() + timeOutMilliseconds;
  187595. DiskState oldState = getDiskState();
  187596. DiskState newState = oldState;
  187597. while (newState == oldState && Time::currentTimeMillis() < timeout)
  187598. {
  187599. newState = getDiskState();
  187600. Thread::sleep (jmin (250, (int) (timeout - Time::currentTimeMillis())));
  187601. }
  187602. return newState;
  187603. }
  187604. const Array<int> AudioCDBurner::getAvailableWriteSpeeds() const
  187605. {
  187606. Array<int> results;
  187607. const int maxSpeed = pimpl->getIntProperty (L"MaxWriteSpeed", 1);
  187608. const int speeds[] = { 1, 2, 4, 8, 12, 16, 20, 24, 32, 40, 64, 80 };
  187609. for (int i = 0; i < numElementsInArray (speeds); ++i)
  187610. if (speeds[i] <= maxSpeed)
  187611. results.add (speeds[i]);
  187612. results.addIfNotAlreadyThere (maxSpeed);
  187613. return results;
  187614. }
  187615. bool AudioCDBurner::setBufferUnderrunProtection (const bool shouldBeEnabled)
  187616. {
  187617. if (pimpl->getIntProperty (L"BufferUnderrunFreeCapable", 0) == 0)
  187618. return false;
  187619. pimpl->setIntProperty (L"EnableBufferUnderrunFree", shouldBeEnabled ? -1 : 0);
  187620. return pimpl->getIntProperty (L"EnableBufferUnderrunFree", 0) != 0;
  187621. }
  187622. int AudioCDBurner::getNumAvailableAudioBlocks() const
  187623. {
  187624. long blocksFree = 0;
  187625. pimpl->redbook->GetAvailableAudioTrackBlocks (&blocksFree);
  187626. return blocksFree;
  187627. }
  187628. const String AudioCDBurner::burn (AudioCDBurner::BurnProgressListener* listener, bool ejectDiscAfterwards,
  187629. bool performFakeBurnForTesting, int writeSpeed)
  187630. {
  187631. pimpl->setIntProperty (L"WriteSpeed", writeSpeed > 0 ? writeSpeed : -1);
  187632. pimpl->listener = listener;
  187633. pimpl->progress = 0;
  187634. pimpl->shouldCancel = false;
  187635. UINT_PTR cookie;
  187636. HRESULT hr = pimpl->discMaster->ProgressAdvise ((AudioCDBurner::Pimpl*) pimpl, &cookie);
  187637. hr = pimpl->discMaster->RecordDisc (performFakeBurnForTesting,
  187638. ejectDiscAfterwards);
  187639. String error;
  187640. if (hr != S_OK)
  187641. {
  187642. const char* e = "Couldn't open or write to the CD device";
  187643. if (hr == IMAPI_E_USERABORT)
  187644. e = "User cancelled the write operation";
  187645. else if (hr == IMAPI_E_MEDIUM_NOTPRESENT || hr == IMAPI_E_TRACKOPEN)
  187646. e = "No Disk present";
  187647. error = e;
  187648. }
  187649. pimpl->discMaster->ProgressUnadvise (cookie);
  187650. pimpl->listener = 0;
  187651. return error;
  187652. }
  187653. bool AudioCDBurner::addAudioTrack (AudioSource* audioSource, int numSamples)
  187654. {
  187655. if (audioSource == 0)
  187656. return false;
  187657. ScopedPointer<AudioSource> source (audioSource);
  187658. long bytesPerBlock;
  187659. HRESULT hr = pimpl->redbook->GetAudioBlockSize (&bytesPerBlock);
  187660. const int samplesPerBlock = bytesPerBlock / 4;
  187661. bool ok = true;
  187662. hr = pimpl->redbook->CreateAudioTrack ((long) numSamples / (bytesPerBlock * 4));
  187663. HeapBlock <byte> buffer (bytesPerBlock);
  187664. AudioSampleBuffer sourceBuffer (2, samplesPerBlock);
  187665. int samplesDone = 0;
  187666. source->prepareToPlay (samplesPerBlock, 44100.0);
  187667. while (ok)
  187668. {
  187669. {
  187670. AudioSourceChannelInfo info;
  187671. info.buffer = &sourceBuffer;
  187672. info.numSamples = samplesPerBlock;
  187673. info.startSample = 0;
  187674. sourceBuffer.clear();
  187675. source->getNextAudioBlock (info);
  187676. }
  187677. zeromem (buffer, bytesPerBlock);
  187678. AudioDataConverters::convertFloatToInt16LE (sourceBuffer.getSampleData (0, 0),
  187679. buffer, samplesPerBlock, 4);
  187680. AudioDataConverters::convertFloatToInt16LE (sourceBuffer.getSampleData (1, 0),
  187681. buffer + 2, samplesPerBlock, 4);
  187682. hr = pimpl->redbook->AddAudioTrackBlocks (buffer, bytesPerBlock);
  187683. if (FAILED (hr))
  187684. ok = false;
  187685. samplesDone += samplesPerBlock;
  187686. if (samplesDone >= numSamples)
  187687. break;
  187688. }
  187689. hr = pimpl->redbook->CloseAudioTrack();
  187690. return ok && hr == S_OK;
  187691. }
  187692. #endif
  187693. #endif
  187694. /*** End of inlined file: juce_win32_AudioCDReader.cpp ***/
  187695. /*** Start of inlined file: juce_win32_Midi.cpp ***/
  187696. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  187697. // compiled on its own).
  187698. #if JUCE_INCLUDED_FILE
  187699. using ::free;
  187700. namespace MidiConstants
  187701. {
  187702. static const int midiBufferSize = 1024 * 10;
  187703. static const int numInHeaders = 32;
  187704. static const int inBufferSize = 256;
  187705. }
  187706. class MidiInThread : public Thread
  187707. {
  187708. public:
  187709. MidiInThread (MidiInput* const input_,
  187710. MidiInputCallback* const callback_)
  187711. : Thread ("Juce Midi"),
  187712. hIn (0),
  187713. input (input_),
  187714. callback (callback_),
  187715. isStarted (false),
  187716. startTime (0),
  187717. pendingLength(0)
  187718. {
  187719. for (int i = MidiConstants::numInHeaders; --i >= 0;)
  187720. {
  187721. zeromem (&hdr[i], sizeof (MIDIHDR));
  187722. hdr[i].lpData = inData[i];
  187723. hdr[i].dwBufferLength = MidiConstants::inBufferSize;
  187724. }
  187725. };
  187726. ~MidiInThread()
  187727. {
  187728. stop();
  187729. if (hIn != 0)
  187730. {
  187731. int count = 5;
  187732. while (--count >= 0)
  187733. {
  187734. if (midiInClose (hIn) == MMSYSERR_NOERROR)
  187735. break;
  187736. Sleep (20);
  187737. }
  187738. }
  187739. }
  187740. void handle (const uint32 message, const uint32 timeStamp) throw()
  187741. {
  187742. const int byte = message & 0xff;
  187743. if (byte < 0x80)
  187744. return;
  187745. const int numBytes = MidiMessage::getMessageLengthFromFirstByte ((uint8) byte);
  187746. const double time = timeStampToTime (timeStamp);
  187747. {
  187748. const ScopedLock sl (lock);
  187749. if (pendingLength < MidiConstants::midiBufferSize - 12)
  187750. {
  187751. char* const p = pending + pendingLength;
  187752. *(double*) p = time;
  187753. *(uint32*) (p + 8) = numBytes;
  187754. *(uint32*) (p + 12) = message;
  187755. pendingLength += 12 + numBytes;
  187756. }
  187757. else
  187758. {
  187759. jassertfalse // midi buffer overflow! You might need to increase the size..
  187760. }
  187761. }
  187762. notify();
  187763. }
  187764. void handleSysEx (MIDIHDR* const hdr, const uint32 timeStamp) throw()
  187765. {
  187766. const int num = hdr->dwBytesRecorded;
  187767. if (num > 0)
  187768. {
  187769. const double time = timeStampToTime (timeStamp);
  187770. {
  187771. const ScopedLock sl (lock);
  187772. if (pendingLength < MidiConstants::midiBufferSize - (8 + num))
  187773. {
  187774. char* const p = pending + pendingLength;
  187775. *(double*) p = time;
  187776. *(uint32*) (p + 8) = num;
  187777. memcpy (p + 12, hdr->lpData, num);
  187778. pendingLength += 12 + num;
  187779. }
  187780. else
  187781. {
  187782. jassertfalse // midi buffer overflow! You might need to increase the size..
  187783. }
  187784. }
  187785. notify();
  187786. }
  187787. }
  187788. void writeBlock (const int i) throw()
  187789. {
  187790. hdr[i].dwBytesRecorded = 0;
  187791. MMRESULT res = midiInPrepareHeader (hIn, &hdr[i], sizeof (MIDIHDR));
  187792. jassert (res == MMSYSERR_NOERROR);
  187793. res = midiInAddBuffer (hIn, &hdr[i], sizeof (MIDIHDR));
  187794. jassert (res == MMSYSERR_NOERROR);
  187795. }
  187796. void run()
  187797. {
  187798. MemoryBlock pendingCopy (64);
  187799. while (! threadShouldExit())
  187800. {
  187801. for (int i = 0; i < MidiConstants::numInHeaders; ++i)
  187802. {
  187803. if ((hdr[i].dwFlags & WHDR_DONE) != 0)
  187804. {
  187805. MMRESULT res = midiInUnprepareHeader (hIn, &hdr[i], sizeof (MIDIHDR));
  187806. (void) res;
  187807. jassert (res == MMSYSERR_NOERROR);
  187808. writeBlock (i);
  187809. }
  187810. }
  187811. int len;
  187812. {
  187813. const ScopedLock sl (lock);
  187814. len = pendingLength;
  187815. if (len > 0)
  187816. {
  187817. pendingCopy.ensureSize (len);
  187818. pendingCopy.copyFrom (pending, 0, len);
  187819. pendingLength = 0;
  187820. }
  187821. }
  187822. //xxx needs to figure out if blocks are broken up or not
  187823. if (len == 0)
  187824. {
  187825. wait (500);
  187826. }
  187827. else
  187828. {
  187829. const char* p = (const char*) pendingCopy.getData();
  187830. while (len > 0)
  187831. {
  187832. const double time = *(const double*) p;
  187833. const int messageLen = *(const int*) (p + 8);
  187834. const MidiMessage message ((const uint8*) (p + 12), messageLen, time);
  187835. callback->handleIncomingMidiMessage (input, message);
  187836. p += 12 + messageLen;
  187837. len -= 12 + messageLen;
  187838. }
  187839. }
  187840. }
  187841. }
  187842. void start() throw()
  187843. {
  187844. jassert (hIn != 0);
  187845. if (hIn != 0 && ! isStarted)
  187846. {
  187847. stop();
  187848. activeMidiThreads.addIfNotAlreadyThere (this);
  187849. int i;
  187850. for (i = 0; i < MidiConstants::numInHeaders; ++i)
  187851. writeBlock (i);
  187852. startTime = Time::getMillisecondCounter();
  187853. MMRESULT res = midiInStart (hIn);
  187854. jassert (res == MMSYSERR_NOERROR);
  187855. if (res == MMSYSERR_NOERROR)
  187856. {
  187857. isStarted = true;
  187858. pendingLength = 0;
  187859. startThread (6);
  187860. }
  187861. }
  187862. }
  187863. void stop() throw()
  187864. {
  187865. if (isStarted)
  187866. {
  187867. stopThread (5000);
  187868. midiInReset (hIn);
  187869. midiInStop (hIn);
  187870. activeMidiThreads.removeValue (this);
  187871. { const ScopedLock sl (lock); }
  187872. for (int i = MidiConstants::numInHeaders; --i >= 0;)
  187873. {
  187874. if ((hdr[i].dwFlags & WHDR_DONE) != 0)
  187875. {
  187876. int c = 10;
  187877. while (--c >= 0 && midiInUnprepareHeader (hIn, &hdr[i], sizeof (MIDIHDR)) == MIDIERR_STILLPLAYING)
  187878. Sleep (20);
  187879. jassert (c >= 0);
  187880. }
  187881. }
  187882. isStarted = false;
  187883. pendingLength = 0;
  187884. }
  187885. }
  187886. static void CALLBACK midiInCallback (HMIDIIN, UINT uMsg, DWORD_PTR dwInstance, DWORD_PTR midiMessage, DWORD_PTR timeStamp)
  187887. {
  187888. MidiInThread* const thread = reinterpret_cast <MidiInThread*> (dwInstance);
  187889. if (thread != 0 && activeMidiThreads.contains (thread))
  187890. {
  187891. if (uMsg == MIM_DATA)
  187892. thread->handle ((uint32) midiMessage, (uint32) timeStamp);
  187893. else if (uMsg == MIM_LONGDATA)
  187894. thread->handleSysEx ((MIDIHDR*) midiMessage, (uint32) timeStamp);
  187895. }
  187896. }
  187897. juce_UseDebuggingNewOperator
  187898. HMIDIIN hIn;
  187899. private:
  187900. static Array <void*, CriticalSection> activeMidiThreads;
  187901. MidiInput* input;
  187902. MidiInputCallback* callback;
  187903. bool isStarted;
  187904. uint32 startTime;
  187905. CriticalSection lock;
  187906. MIDIHDR hdr [MidiConstants::numInHeaders];
  187907. char inData [MidiConstants::numInHeaders] [MidiConstants::inBufferSize];
  187908. int pendingLength;
  187909. char pending [MidiConstants::midiBufferSize];
  187910. double timeStampToTime (uint32 timeStamp) throw()
  187911. {
  187912. timeStamp += startTime;
  187913. const uint32 now = Time::getMillisecondCounter();
  187914. if (timeStamp > now)
  187915. {
  187916. if (timeStamp > now + 2)
  187917. --startTime;
  187918. timeStamp = now;
  187919. }
  187920. return 0.001 * timeStamp;
  187921. }
  187922. MidiInThread (const MidiInThread&);
  187923. MidiInThread& operator= (const MidiInThread&);
  187924. };
  187925. Array <void*, CriticalSection> MidiInThread::activeMidiThreads;
  187926. const StringArray MidiInput::getDevices()
  187927. {
  187928. StringArray s;
  187929. const int num = midiInGetNumDevs();
  187930. for (int i = 0; i < num; ++i)
  187931. {
  187932. MIDIINCAPS mc;
  187933. zerostruct (mc);
  187934. if (midiInGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  187935. s.add (String (mc.szPname, sizeof (mc.szPname)));
  187936. }
  187937. return s;
  187938. }
  187939. int MidiInput::getDefaultDeviceIndex()
  187940. {
  187941. return 0;
  187942. }
  187943. MidiInput* MidiInput::openDevice (const int index, MidiInputCallback* const callback)
  187944. {
  187945. if (callback == 0)
  187946. return 0;
  187947. UINT deviceId = MIDI_MAPPER;
  187948. int n = 0;
  187949. String name;
  187950. const int num = midiInGetNumDevs();
  187951. for (int i = 0; i < num; ++i)
  187952. {
  187953. MIDIINCAPS mc;
  187954. zerostruct (mc);
  187955. if (midiInGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  187956. {
  187957. if (index == n)
  187958. {
  187959. deviceId = i;
  187960. name = String (mc.szPname, sizeof (mc.szPname));
  187961. break;
  187962. }
  187963. ++n;
  187964. }
  187965. }
  187966. ScopedPointer <MidiInput> in (new MidiInput (name));
  187967. ScopedPointer <MidiInThread> thread (new MidiInThread (in, callback));
  187968. HMIDIIN h;
  187969. HRESULT err = midiInOpen (&h, deviceId,
  187970. (DWORD_PTR) &MidiInThread::midiInCallback,
  187971. (DWORD_PTR) (MidiInThread*) thread,
  187972. CALLBACK_FUNCTION);
  187973. if (err == MMSYSERR_NOERROR)
  187974. {
  187975. thread->hIn = h;
  187976. in->internal = (void*) thread.release();
  187977. return in.release();
  187978. }
  187979. return 0;
  187980. }
  187981. MidiInput::MidiInput (const String& name_)
  187982. : name (name_),
  187983. internal (0)
  187984. {
  187985. }
  187986. MidiInput::~MidiInput()
  187987. {
  187988. delete static_cast <MidiInThread*> (internal);
  187989. }
  187990. void MidiInput::start()
  187991. {
  187992. static_cast <MidiInThread*> (internal)->start();
  187993. }
  187994. void MidiInput::stop()
  187995. {
  187996. static_cast <MidiInThread*> (internal)->stop();
  187997. }
  187998. struct MidiOutHandle
  187999. {
  188000. int refCount;
  188001. UINT deviceId;
  188002. HMIDIOUT handle;
  188003. static Array<MidiOutHandle*> activeHandles;
  188004. juce_UseDebuggingNewOperator
  188005. };
  188006. Array<MidiOutHandle*> MidiOutHandle::activeHandles;
  188007. const StringArray MidiOutput::getDevices()
  188008. {
  188009. StringArray s;
  188010. const int num = midiOutGetNumDevs();
  188011. for (int i = 0; i < num; ++i)
  188012. {
  188013. MIDIOUTCAPS mc;
  188014. zerostruct (mc);
  188015. if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  188016. s.add (String (mc.szPname, sizeof (mc.szPname)));
  188017. }
  188018. return s;
  188019. }
  188020. int MidiOutput::getDefaultDeviceIndex()
  188021. {
  188022. const int num = midiOutGetNumDevs();
  188023. int n = 0;
  188024. for (int i = 0; i < num; ++i)
  188025. {
  188026. MIDIOUTCAPS mc;
  188027. zerostruct (mc);
  188028. if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  188029. {
  188030. if ((mc.wTechnology & MOD_MAPPER) != 0)
  188031. return n;
  188032. ++n;
  188033. }
  188034. }
  188035. return 0;
  188036. }
  188037. MidiOutput* MidiOutput::openDevice (int index)
  188038. {
  188039. UINT deviceId = MIDI_MAPPER;
  188040. const int num = midiOutGetNumDevs();
  188041. int i, n = 0;
  188042. for (i = 0; i < num; ++i)
  188043. {
  188044. MIDIOUTCAPS mc;
  188045. zerostruct (mc);
  188046. if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  188047. {
  188048. // use the microsoft sw synth as a default - best not to allow deviceId
  188049. // to be MIDI_MAPPER, or else device sharing breaks
  188050. if (String (mc.szPname, sizeof (mc.szPname)).containsIgnoreCase (T("microsoft")))
  188051. deviceId = i;
  188052. if (index == n)
  188053. {
  188054. deviceId = i;
  188055. break;
  188056. }
  188057. ++n;
  188058. }
  188059. }
  188060. for (i = MidiOutHandle::activeHandles.size(); --i >= 0;)
  188061. {
  188062. MidiOutHandle* const han = MidiOutHandle::activeHandles.getUnchecked(i);
  188063. if (han != 0 && han->deviceId == deviceId)
  188064. {
  188065. han->refCount++;
  188066. MidiOutput* const out = new MidiOutput();
  188067. out->internal = (void*) han;
  188068. return out;
  188069. }
  188070. }
  188071. for (i = 4; --i >= 0;)
  188072. {
  188073. HMIDIOUT h = 0;
  188074. MMRESULT res = midiOutOpen (&h, deviceId, 0, 0, CALLBACK_NULL);
  188075. if (res == MMSYSERR_NOERROR)
  188076. {
  188077. MidiOutHandle* const han = new MidiOutHandle();
  188078. han->deviceId = deviceId;
  188079. han->refCount = 1;
  188080. han->handle = h;
  188081. MidiOutHandle::activeHandles.add (han);
  188082. MidiOutput* const out = new MidiOutput();
  188083. out->internal = (void*) han;
  188084. return out;
  188085. }
  188086. else if (res == MMSYSERR_ALLOCATED)
  188087. {
  188088. Sleep (100);
  188089. }
  188090. else
  188091. {
  188092. break;
  188093. }
  188094. }
  188095. return 0;
  188096. }
  188097. MidiOutput::~MidiOutput()
  188098. {
  188099. MidiOutHandle* const h = static_cast <MidiOutHandle*> (internal);
  188100. if (MidiOutHandle::activeHandles.contains (h) && --(h->refCount) == 0)
  188101. {
  188102. midiOutClose (h->handle);
  188103. MidiOutHandle::activeHandles.removeValue (h);
  188104. delete h;
  188105. }
  188106. }
  188107. void MidiOutput::reset()
  188108. {
  188109. const MidiOutHandle* const h = static_cast <const MidiOutHandle*> (internal);
  188110. midiOutReset (h->handle);
  188111. }
  188112. bool MidiOutput::getVolume (float& leftVol,
  188113. float& rightVol)
  188114. {
  188115. const MidiOutHandle* const handle = static_cast <const MidiOutHandle*> (internal);
  188116. DWORD n;
  188117. if (midiOutGetVolume (handle->handle, &n) == MMSYSERR_NOERROR)
  188118. {
  188119. const unsigned short* const nn = (const unsigned short*) &n;
  188120. rightVol = nn[0] / (float) 0xffff;
  188121. leftVol = nn[1] / (float) 0xffff;
  188122. return true;
  188123. }
  188124. else
  188125. {
  188126. rightVol = leftVol = 1.0f;
  188127. return false;
  188128. }
  188129. }
  188130. void MidiOutput::setVolume (float leftVol,
  188131. float rightVol)
  188132. {
  188133. const MidiOutHandle* const handle = static_cast <MidiOutHandle*> (internal);
  188134. DWORD n;
  188135. unsigned short* const nn = (unsigned short*) &n;
  188136. nn[0] = (unsigned short) jlimit (0, 0xffff, (int) (rightVol * 0xffff));
  188137. nn[1] = (unsigned short) jlimit (0, 0xffff, (int) (leftVol * 0xffff));
  188138. midiOutSetVolume (handle->handle, n);
  188139. }
  188140. void MidiOutput::sendMessageNow (const MidiMessage& message)
  188141. {
  188142. const MidiOutHandle* const handle = static_cast <const MidiOutHandle*> (internal);
  188143. if (message.getRawDataSize() > 3
  188144. || message.isSysEx())
  188145. {
  188146. MIDIHDR h;
  188147. zerostruct (h);
  188148. h.lpData = (char*) message.getRawData();
  188149. h.dwBufferLength = message.getRawDataSize();
  188150. h.dwBytesRecorded = message.getRawDataSize();
  188151. if (midiOutPrepareHeader (handle->handle, &h, sizeof (MIDIHDR)) == MMSYSERR_NOERROR)
  188152. {
  188153. MMRESULT res = midiOutLongMsg (handle->handle, &h, sizeof (MIDIHDR));
  188154. if (res == MMSYSERR_NOERROR)
  188155. {
  188156. while ((h.dwFlags & MHDR_DONE) == 0)
  188157. Sleep (1);
  188158. int count = 500; // 1 sec timeout
  188159. while (--count >= 0)
  188160. {
  188161. res = midiOutUnprepareHeader (handle->handle, &h, sizeof (MIDIHDR));
  188162. if (res == MIDIERR_STILLPLAYING)
  188163. Sleep (2);
  188164. else
  188165. break;
  188166. }
  188167. }
  188168. }
  188169. }
  188170. else
  188171. {
  188172. midiOutShortMsg (handle->handle,
  188173. *(unsigned int*) message.getRawData());
  188174. }
  188175. }
  188176. #endif
  188177. /*** End of inlined file: juce_win32_Midi.cpp ***/
  188178. /*** Start of inlined file: juce_win32_ASIO.cpp ***/
  188179. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  188180. // compiled on its own).
  188181. #if JUCE_INCLUDED_FILE && JUCE_ASIO
  188182. #undef WINDOWS
  188183. // #define ASIO_DEBUGGING
  188184. #ifdef ASIO_DEBUGGING
  188185. #define log(a) { Logger::writeToLog (a); DBG (a) }
  188186. #else
  188187. #define log(a) {}
  188188. #endif
  188189. #ifdef ASIO_DEBUGGING
  188190. static void logError (const String& context, long error)
  188191. {
  188192. String err ("unknown error");
  188193. if (error == ASE_NotPresent)
  188194. err = "Not Present";
  188195. else if (error == ASE_HWMalfunction)
  188196. err = "Hardware Malfunction";
  188197. else if (error == ASE_InvalidParameter)
  188198. err = "Invalid Parameter";
  188199. else if (error == ASE_InvalidMode)
  188200. err = "Invalid Mode";
  188201. else if (error == ASE_SPNotAdvancing)
  188202. err = "Sample position not advancing";
  188203. else if (error == ASE_NoClock)
  188204. err = "No Clock";
  188205. else if (error == ASE_NoMemory)
  188206. err = "Out of memory";
  188207. log (T("!!error: ") + context + T(" - ") + err);
  188208. }
  188209. #else
  188210. #define logError(a, b) {}
  188211. #endif
  188212. class ASIOAudioIODevice;
  188213. static ASIOAudioIODevice* volatile currentASIODev[3] = { 0, 0, 0 };
  188214. static const int maxASIOChannels = 160;
  188215. class JUCE_API ASIOAudioIODevice : public AudioIODevice,
  188216. private Timer
  188217. {
  188218. public:
  188219. Component ourWindow;
  188220. ASIOAudioIODevice (const String& name_, const CLSID classId_, const int slotNumber,
  188221. const String& optionalDllForDirectLoading_)
  188222. : AudioIODevice (name_, T("ASIO")),
  188223. asioObject (0),
  188224. classId (classId_),
  188225. optionalDllForDirectLoading (optionalDllForDirectLoading_),
  188226. currentBitDepth (16),
  188227. currentSampleRate (0),
  188228. isOpen_ (false),
  188229. isStarted (false),
  188230. postOutput (true),
  188231. insideControlPanelModalLoop (false),
  188232. shouldUsePreferredSize (false)
  188233. {
  188234. name = name_;
  188235. ourWindow.addToDesktop (0);
  188236. windowHandle = ourWindow.getWindowHandle();
  188237. jassert (currentASIODev [slotNumber] == 0);
  188238. currentASIODev [slotNumber] = this;
  188239. openDevice();
  188240. }
  188241. ~ASIOAudioIODevice()
  188242. {
  188243. for (int i = 0; i < numElementsInArray (currentASIODev); ++i)
  188244. if (currentASIODev[i] == this)
  188245. currentASIODev[i] = 0;
  188246. close();
  188247. log ("ASIO - exiting");
  188248. removeCurrentDriver();
  188249. }
  188250. void updateSampleRates()
  188251. {
  188252. // find a list of sample rates..
  188253. const double possibleSampleRates[] = { 44100.0, 48000.0, 88200.0, 96000.0, 176400.0, 192000.0 };
  188254. sampleRates.clear();
  188255. if (asioObject != 0)
  188256. {
  188257. for (int index = 0; index < numElementsInArray (possibleSampleRates); ++index)
  188258. {
  188259. const long err = asioObject->canSampleRate (possibleSampleRates[index]);
  188260. if (err == 0)
  188261. {
  188262. sampleRates.add ((int) possibleSampleRates[index]);
  188263. log (T("rate: ") + String ((int) possibleSampleRates[index]));
  188264. }
  188265. else if (err != ASE_NoClock)
  188266. {
  188267. logError (T("CanSampleRate"), err);
  188268. }
  188269. }
  188270. if (sampleRates.size() == 0)
  188271. {
  188272. double cr = 0;
  188273. const long err = asioObject->getSampleRate (&cr);
  188274. log (T("No sample rates supported - current rate: ") + String ((int) cr));
  188275. if (err == 0)
  188276. sampleRates.add ((int) cr);
  188277. }
  188278. }
  188279. }
  188280. const StringArray getOutputChannelNames()
  188281. {
  188282. return outputChannelNames;
  188283. }
  188284. const StringArray getInputChannelNames()
  188285. {
  188286. return inputChannelNames;
  188287. }
  188288. int getNumSampleRates()
  188289. {
  188290. return sampleRates.size();
  188291. }
  188292. double getSampleRate (int index)
  188293. {
  188294. return sampleRates [index];
  188295. }
  188296. int getNumBufferSizesAvailable()
  188297. {
  188298. return bufferSizes.size();
  188299. }
  188300. int getBufferSizeSamples (int index)
  188301. {
  188302. return bufferSizes [index];
  188303. }
  188304. int getDefaultBufferSize()
  188305. {
  188306. return preferredSize;
  188307. }
  188308. const String open (const BitArray& inputChannels,
  188309. const BitArray& outputChannels,
  188310. double sr,
  188311. int bufferSizeSamples)
  188312. {
  188313. close();
  188314. currentCallback = 0;
  188315. if (bufferSizeSamples <= 0)
  188316. shouldUsePreferredSize = true;
  188317. if (asioObject == 0 || ! isASIOOpen)
  188318. {
  188319. log ("Warning: device not open");
  188320. const String err (openDevice());
  188321. if (asioObject == 0 || ! isASIOOpen)
  188322. return err;
  188323. }
  188324. isStarted = false;
  188325. bufferIndex = -1;
  188326. long err = 0;
  188327. long newPreferredSize = 0;
  188328. // if the preferred size has just changed, assume it's a control panel thing and use it as the new value.
  188329. minSize = 0;
  188330. maxSize = 0;
  188331. newPreferredSize = 0;
  188332. granularity = 0;
  188333. if (asioObject->getBufferSize (&minSize, &maxSize, &newPreferredSize, &granularity) == 0)
  188334. {
  188335. if (preferredSize != 0 && newPreferredSize != 0 && newPreferredSize != preferredSize)
  188336. shouldUsePreferredSize = true;
  188337. preferredSize = newPreferredSize;
  188338. }
  188339. // unfortunate workaround for certain manufacturers whose drivers crash horribly if you make
  188340. // dynamic changes to the buffer size...
  188341. shouldUsePreferredSize = shouldUsePreferredSize
  188342. || getName().containsIgnoreCase (T("Digidesign"));
  188343. if (shouldUsePreferredSize)
  188344. {
  188345. log ("Using preferred size for buffer..");
  188346. if ((err = asioObject->getBufferSize (&minSize, &maxSize, &preferredSize, &granularity)) == 0)
  188347. {
  188348. bufferSizeSamples = preferredSize;
  188349. }
  188350. else
  188351. {
  188352. bufferSizeSamples = 1024;
  188353. logError ("GetBufferSize1", err);
  188354. }
  188355. shouldUsePreferredSize = false;
  188356. }
  188357. int sampleRate = roundDoubleToInt (sr);
  188358. currentSampleRate = sampleRate;
  188359. currentBlockSizeSamples = bufferSizeSamples;
  188360. currentChansOut.clear();
  188361. currentChansIn.clear();
  188362. zeromem (inBuffers, sizeof (inBuffers));
  188363. zeromem (outBuffers, sizeof (outBuffers));
  188364. updateSampleRates();
  188365. if (sampleRate == 0 || (sampleRates.size() > 0 && ! sampleRates.contains (sampleRate)))
  188366. sampleRate = sampleRates[0];
  188367. jassert (sampleRate != 0);
  188368. if (sampleRate == 0)
  188369. sampleRate = 44100;
  188370. long numSources = 32;
  188371. ASIOClockSource clocks[32];
  188372. zeromem (clocks, sizeof (clocks));
  188373. asioObject->getClockSources (clocks, &numSources);
  188374. bool isSourceSet = false;
  188375. // careful not to remove this loop because it does more than just logging!
  188376. int i;
  188377. for (i = 0; i < numSources; ++i)
  188378. {
  188379. String s ("clock: ");
  188380. s += clocks[i].name;
  188381. if (clocks[i].isCurrentSource)
  188382. {
  188383. isSourceSet = true;
  188384. s << " (cur)";
  188385. }
  188386. log (s);
  188387. }
  188388. if (numSources > 1 && ! isSourceSet)
  188389. {
  188390. log ("setting clock source");
  188391. asioObject->setClockSource (clocks[0].index);
  188392. Thread::sleep (20);
  188393. }
  188394. else
  188395. {
  188396. if (numSources == 0)
  188397. {
  188398. log ("ASIO - no clock sources!");
  188399. }
  188400. }
  188401. double cr = 0;
  188402. err = asioObject->getSampleRate (&cr);
  188403. if (err == 0)
  188404. {
  188405. currentSampleRate = cr;
  188406. }
  188407. else
  188408. {
  188409. logError ("GetSampleRate", err);
  188410. currentSampleRate = 0;
  188411. }
  188412. error = String::empty;
  188413. needToReset = false;
  188414. isReSync = false;
  188415. err = 0;
  188416. bool buffersCreated = false;
  188417. if (currentSampleRate != sampleRate)
  188418. {
  188419. log (T("ASIO samplerate: ") + String (currentSampleRate) + T(" to ") + String (sampleRate));
  188420. err = asioObject->setSampleRate (sampleRate);
  188421. if (err == ASE_NoClock && numSources > 0)
  188422. {
  188423. log ("trying to set a clock source..");
  188424. Thread::sleep (10);
  188425. err = asioObject->setClockSource (clocks[0].index);
  188426. if (err != 0)
  188427. {
  188428. logError ("SetClock", err);
  188429. }
  188430. Thread::sleep (10);
  188431. err = asioObject->setSampleRate (sampleRate);
  188432. }
  188433. }
  188434. if (err == 0)
  188435. {
  188436. currentSampleRate = sampleRate;
  188437. if (needToReset)
  188438. {
  188439. if (isReSync)
  188440. {
  188441. log ("Resync request");
  188442. }
  188443. log ("! Resetting ASIO after sample rate change");
  188444. removeCurrentDriver();
  188445. loadDriver();
  188446. const String error (initDriver());
  188447. if (error.isNotEmpty())
  188448. {
  188449. log (T("ASIOInit: ") + error);
  188450. }
  188451. needToReset = false;
  188452. isReSync = false;
  188453. }
  188454. numActiveInputChans = 0;
  188455. numActiveOutputChans = 0;
  188456. ASIOBufferInfo* info = bufferInfos;
  188457. int i;
  188458. for (i = 0; i < totalNumInputChans; ++i)
  188459. {
  188460. if (inputChannels[i])
  188461. {
  188462. currentChansIn.setBit (i);
  188463. info->isInput = 1;
  188464. info->channelNum = i;
  188465. info->buffers[0] = info->buffers[1] = 0;
  188466. ++info;
  188467. ++numActiveInputChans;
  188468. }
  188469. }
  188470. for (i = 0; i < totalNumOutputChans; ++i)
  188471. {
  188472. if (outputChannels[i])
  188473. {
  188474. currentChansOut.setBit (i);
  188475. info->isInput = 0;
  188476. info->channelNum = i;
  188477. info->buffers[0] = info->buffers[1] = 0;
  188478. ++info;
  188479. ++numActiveOutputChans;
  188480. }
  188481. }
  188482. const int totalBuffers = numActiveInputChans + numActiveOutputChans;
  188483. callbacks.sampleRateDidChange = &sampleRateChangedCallback;
  188484. if (currentASIODev[0] == this)
  188485. {
  188486. callbacks.bufferSwitch = &bufferSwitchCallback0;
  188487. callbacks.asioMessage = &asioMessagesCallback0;
  188488. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback0;
  188489. }
  188490. else if (currentASIODev[1] == this)
  188491. {
  188492. callbacks.bufferSwitch = &bufferSwitchCallback1;
  188493. callbacks.asioMessage = &asioMessagesCallback1;
  188494. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback1;
  188495. }
  188496. else if (currentASIODev[2] == this)
  188497. {
  188498. callbacks.bufferSwitch = &bufferSwitchCallback2;
  188499. callbacks.asioMessage = &asioMessagesCallback2;
  188500. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback2;
  188501. }
  188502. else
  188503. {
  188504. jassertfalse
  188505. }
  188506. log ("disposing buffers");
  188507. err = asioObject->disposeBuffers();
  188508. log (T("creating buffers: ") + String (totalBuffers) + T(", ") + String (currentBlockSizeSamples));
  188509. err = asioObject->createBuffers (bufferInfos,
  188510. totalBuffers,
  188511. currentBlockSizeSamples,
  188512. &callbacks);
  188513. if (err != 0)
  188514. {
  188515. currentBlockSizeSamples = preferredSize;
  188516. logError ("create buffers 2", err);
  188517. asioObject->disposeBuffers();
  188518. err = asioObject->createBuffers (bufferInfos,
  188519. totalBuffers,
  188520. currentBlockSizeSamples,
  188521. &callbacks);
  188522. }
  188523. if (err == 0)
  188524. {
  188525. buffersCreated = true;
  188526. tempBuffer.calloc (totalBuffers * currentBlockSizeSamples + 32);
  188527. int n = 0;
  188528. Array <int> types;
  188529. currentBitDepth = 16;
  188530. for (i = 0; i < jmin ((int) totalNumInputChans, maxASIOChannels); ++i)
  188531. {
  188532. if (inputChannels[i])
  188533. {
  188534. inBuffers[n] = tempBuffer + (currentBlockSizeSamples * n);
  188535. ASIOChannelInfo channelInfo;
  188536. zerostruct (channelInfo);
  188537. channelInfo.channel = i;
  188538. channelInfo.isInput = 1;
  188539. asioObject->getChannelInfo (&channelInfo);
  188540. types.addIfNotAlreadyThere (channelInfo.type);
  188541. typeToFormatParameters (channelInfo.type,
  188542. inputChannelBitDepths[n],
  188543. inputChannelBytesPerSample[n],
  188544. inputChannelIsFloat[n],
  188545. inputChannelLittleEndian[n]);
  188546. currentBitDepth = jmax (currentBitDepth, inputChannelBitDepths[n]);
  188547. ++n;
  188548. }
  188549. }
  188550. jassert (numActiveInputChans == n);
  188551. n = 0;
  188552. for (i = 0; i < jmin ((int) totalNumOutputChans, maxASIOChannels); ++i)
  188553. {
  188554. if (outputChannels[i])
  188555. {
  188556. outBuffers[n] = tempBuffer + (currentBlockSizeSamples * (numActiveInputChans + n));
  188557. ASIOChannelInfo channelInfo;
  188558. zerostruct (channelInfo);
  188559. channelInfo.channel = i;
  188560. channelInfo.isInput = 0;
  188561. asioObject->getChannelInfo (&channelInfo);
  188562. types.addIfNotAlreadyThere (channelInfo.type);
  188563. typeToFormatParameters (channelInfo.type,
  188564. outputChannelBitDepths[n],
  188565. outputChannelBytesPerSample[n],
  188566. outputChannelIsFloat[n],
  188567. outputChannelLittleEndian[n]);
  188568. currentBitDepth = jmax (currentBitDepth, outputChannelBitDepths[n]);
  188569. ++n;
  188570. }
  188571. }
  188572. jassert (numActiveOutputChans == n);
  188573. for (i = types.size(); --i >= 0;)
  188574. {
  188575. log (T("channel format: ") + String (types[i]));
  188576. }
  188577. jassert (n <= totalBuffers);
  188578. for (i = 0; i < numActiveOutputChans; ++i)
  188579. {
  188580. const int size = currentBlockSizeSamples * (outputChannelBitDepths[i] >> 3);
  188581. if (bufferInfos [numActiveInputChans + i].buffers[0] == 0
  188582. || bufferInfos [numActiveInputChans + i].buffers[1] == 0)
  188583. {
  188584. log ("!! Null buffers");
  188585. }
  188586. else
  188587. {
  188588. zeromem (bufferInfos[numActiveInputChans + i].buffers[0], size);
  188589. zeromem (bufferInfos[numActiveInputChans + i].buffers[1], size);
  188590. }
  188591. }
  188592. inputLatency = outputLatency = 0;
  188593. if (asioObject->getLatencies (&inputLatency, &outputLatency) != 0)
  188594. {
  188595. log ("ASIO - no latencies");
  188596. }
  188597. else
  188598. {
  188599. log (T("ASIO latencies: ")
  188600. + String ((int) outputLatency)
  188601. + T(", ")
  188602. + String ((int) inputLatency));
  188603. }
  188604. isOpen_ = true;
  188605. log ("starting ASIO");
  188606. calledback = false;
  188607. err = asioObject->start();
  188608. if (err != 0)
  188609. {
  188610. isOpen_ = false;
  188611. log ("ASIO - stop on failure");
  188612. Thread::sleep (10);
  188613. asioObject->stop();
  188614. error = "Can't start device";
  188615. Thread::sleep (10);
  188616. }
  188617. else
  188618. {
  188619. int count = 300;
  188620. while (--count > 0 && ! calledback)
  188621. Thread::sleep (10);
  188622. isStarted = true;
  188623. if (! calledback)
  188624. {
  188625. error = "Device didn't start correctly";
  188626. log ("ASIO didn't callback - stopping..");
  188627. asioObject->stop();
  188628. }
  188629. }
  188630. }
  188631. else
  188632. {
  188633. error = "Can't create i/o buffers";
  188634. }
  188635. }
  188636. else
  188637. {
  188638. error = "Can't set sample rate: ";
  188639. error << sampleRate;
  188640. }
  188641. if (error.isNotEmpty())
  188642. {
  188643. logError (error, err);
  188644. if (asioObject != 0 && buffersCreated)
  188645. asioObject->disposeBuffers();
  188646. Thread::sleep (20);
  188647. isStarted = false;
  188648. isOpen_ = false;
  188649. close();
  188650. }
  188651. needToReset = false;
  188652. isReSync = false;
  188653. return error;
  188654. }
  188655. void close()
  188656. {
  188657. error = String::empty;
  188658. stopTimer();
  188659. stop();
  188660. if (isASIOOpen && isOpen_)
  188661. {
  188662. const ScopedLock sl (callbackLock);
  188663. isOpen_ = false;
  188664. isStarted = false;
  188665. needToReset = false;
  188666. isReSync = false;
  188667. log ("ASIO - stopping");
  188668. if (asioObject != 0)
  188669. {
  188670. Thread::sleep (20);
  188671. asioObject->stop();
  188672. Thread::sleep (10);
  188673. asioObject->disposeBuffers();
  188674. }
  188675. Thread::sleep (10);
  188676. }
  188677. }
  188678. bool isOpen()
  188679. {
  188680. return isOpen_ || insideControlPanelModalLoop;
  188681. }
  188682. int getCurrentBufferSizeSamples()
  188683. {
  188684. return currentBlockSizeSamples;
  188685. }
  188686. double getCurrentSampleRate()
  188687. {
  188688. return currentSampleRate;
  188689. }
  188690. const BitArray getActiveOutputChannels() const
  188691. {
  188692. return currentChansOut;
  188693. }
  188694. const BitArray getActiveInputChannels() const
  188695. {
  188696. return currentChansIn;
  188697. }
  188698. int getCurrentBitDepth()
  188699. {
  188700. return currentBitDepth;
  188701. }
  188702. int getOutputLatencyInSamples()
  188703. {
  188704. return outputLatency + currentBlockSizeSamples / 4;
  188705. }
  188706. int getInputLatencyInSamples()
  188707. {
  188708. return inputLatency + currentBlockSizeSamples / 4;
  188709. }
  188710. void start (AudioIODeviceCallback* callback)
  188711. {
  188712. if (callback != 0)
  188713. {
  188714. callback->audioDeviceAboutToStart (this);
  188715. const ScopedLock sl (callbackLock);
  188716. currentCallback = callback;
  188717. }
  188718. }
  188719. void stop()
  188720. {
  188721. AudioIODeviceCallback* const lastCallback = currentCallback;
  188722. {
  188723. const ScopedLock sl (callbackLock);
  188724. currentCallback = 0;
  188725. }
  188726. if (lastCallback != 0)
  188727. lastCallback->audioDeviceStopped();
  188728. }
  188729. bool isPlaying()
  188730. {
  188731. return isASIOOpen && (currentCallback != 0);
  188732. }
  188733. const String getLastError()
  188734. {
  188735. return error;
  188736. }
  188737. bool hasControlPanel() const
  188738. {
  188739. return true;
  188740. }
  188741. bool showControlPanel()
  188742. {
  188743. log ("ASIO - showing control panel");
  188744. Component modalWindow (String::empty);
  188745. modalWindow.setOpaque (true);
  188746. modalWindow.addToDesktop (0);
  188747. modalWindow.enterModalState();
  188748. bool done = false;
  188749. JUCE_TRY
  188750. {
  188751. // are there are devices that need to be closed before showing their control panel?
  188752. // close();
  188753. insideControlPanelModalLoop = true;
  188754. const uint32 started = Time::getMillisecondCounter();
  188755. if (asioObject != 0)
  188756. {
  188757. asioObject->controlPanel();
  188758. const int spent = (int) Time::getMillisecondCounter() - (int) started;
  188759. log (T("spent: ") + String (spent));
  188760. if (spent > 300)
  188761. {
  188762. shouldUsePreferredSize = true;
  188763. done = true;
  188764. }
  188765. }
  188766. }
  188767. JUCE_CATCH_ALL
  188768. insideControlPanelModalLoop = false;
  188769. return done;
  188770. }
  188771. void resetRequest() throw()
  188772. {
  188773. needToReset = true;
  188774. }
  188775. void resyncRequest() throw()
  188776. {
  188777. needToReset = true;
  188778. isReSync = true;
  188779. }
  188780. void timerCallback()
  188781. {
  188782. if (! insideControlPanelModalLoop)
  188783. {
  188784. stopTimer();
  188785. // used to cause a reset
  188786. log ("! ASIO restart request!");
  188787. if (isOpen_)
  188788. {
  188789. AudioIODeviceCallback* const oldCallback = currentCallback;
  188790. close();
  188791. open (BitArray (currentChansIn), BitArray (currentChansOut),
  188792. currentSampleRate, currentBlockSizeSamples);
  188793. if (oldCallback != 0)
  188794. start (oldCallback);
  188795. }
  188796. }
  188797. else
  188798. {
  188799. startTimer (100);
  188800. }
  188801. }
  188802. juce_UseDebuggingNewOperator
  188803. private:
  188804. IASIO* volatile asioObject;
  188805. ASIOCallbacks callbacks;
  188806. void* windowHandle;
  188807. CLSID classId;
  188808. const String optionalDllForDirectLoading;
  188809. String error;
  188810. long totalNumInputChans, totalNumOutputChans;
  188811. StringArray inputChannelNames, outputChannelNames;
  188812. Array<int> sampleRates, bufferSizes;
  188813. long inputLatency, outputLatency;
  188814. long minSize, maxSize, preferredSize, granularity;
  188815. int volatile currentBlockSizeSamples;
  188816. int volatile currentBitDepth;
  188817. double volatile currentSampleRate;
  188818. BitArray currentChansOut, currentChansIn;
  188819. AudioIODeviceCallback* volatile currentCallback;
  188820. CriticalSection callbackLock;
  188821. ASIOBufferInfo bufferInfos [maxASIOChannels];
  188822. float* inBuffers [maxASIOChannels];
  188823. float* outBuffers [maxASIOChannels];
  188824. int inputChannelBitDepths [maxASIOChannels];
  188825. int outputChannelBitDepths [maxASIOChannels];
  188826. int inputChannelBytesPerSample [maxASIOChannels];
  188827. int outputChannelBytesPerSample [maxASIOChannels];
  188828. bool inputChannelIsFloat [maxASIOChannels];
  188829. bool outputChannelIsFloat [maxASIOChannels];
  188830. bool inputChannelLittleEndian [maxASIOChannels];
  188831. bool outputChannelLittleEndian [maxASIOChannels];
  188832. WaitableEvent event1;
  188833. HeapBlock <float> tempBuffer;
  188834. int volatile bufferIndex, numActiveInputChans, numActiveOutputChans;
  188835. bool isOpen_, isStarted;
  188836. bool volatile isASIOOpen;
  188837. bool volatile calledback;
  188838. bool volatile littleEndian, postOutput, needToReset, isReSync;
  188839. bool volatile insideControlPanelModalLoop;
  188840. bool volatile shouldUsePreferredSize;
  188841. void removeCurrentDriver()
  188842. {
  188843. if (asioObject != 0)
  188844. {
  188845. asioObject->Release();
  188846. asioObject = 0;
  188847. }
  188848. }
  188849. bool loadDriver()
  188850. {
  188851. removeCurrentDriver();
  188852. JUCE_TRY
  188853. {
  188854. if (CoCreateInstance (classId, 0, CLSCTX_INPROC_SERVER,
  188855. classId, (void**) &asioObject) == S_OK)
  188856. {
  188857. return true;
  188858. }
  188859. // If a class isn't registered but we have a path for it, we can fallback to
  188860. // doing a direct load of the COM object (only available via the juce_createASIOAudioIODeviceForGUID function).
  188861. if (optionalDllForDirectLoading.isNotEmpty())
  188862. {
  188863. HMODULE h = LoadLibrary (optionalDllForDirectLoading);
  188864. if (h != 0)
  188865. {
  188866. typedef HRESULT (CALLBACK* DllGetClassObjectFunc) (REFCLSID clsid, REFIID iid, LPVOID* ppv);
  188867. DllGetClassObjectFunc dllGetClassObject = (DllGetClassObjectFunc) GetProcAddress (h, "DllGetClassObject");
  188868. if (dllGetClassObject != 0)
  188869. {
  188870. IClassFactory* classFactory = 0;
  188871. HRESULT hr = dllGetClassObject (classId, IID_IClassFactory, (void**) &classFactory);
  188872. if (classFactory != 0)
  188873. {
  188874. hr = classFactory->CreateInstance (0, classId, (void**) &asioObject);
  188875. classFactory->Release();
  188876. }
  188877. return asioObject != 0;
  188878. }
  188879. }
  188880. }
  188881. }
  188882. JUCE_CATCH_ALL
  188883. asioObject = 0;
  188884. return false;
  188885. }
  188886. const String initDriver()
  188887. {
  188888. if (asioObject != 0)
  188889. {
  188890. char buffer [256];
  188891. zeromem (buffer, sizeof (buffer));
  188892. if (! asioObject->init (windowHandle))
  188893. {
  188894. asioObject->getErrorMessage (buffer);
  188895. return String (buffer, sizeof (buffer) - 1);
  188896. }
  188897. // just in case any daft drivers expect this to be called..
  188898. asioObject->getDriverName (buffer);
  188899. return String::empty;
  188900. }
  188901. return "No Driver";
  188902. }
  188903. const String openDevice()
  188904. {
  188905. // use this in case the driver starts opening dialog boxes..
  188906. Component modalWindow (String::empty);
  188907. modalWindow.setOpaque (true);
  188908. modalWindow.addToDesktop (0);
  188909. modalWindow.enterModalState();
  188910. // open the device and get its info..
  188911. log (T("opening ASIO device: ") + getName());
  188912. needToReset = false;
  188913. isReSync = false;
  188914. outputChannelNames.clear();
  188915. inputChannelNames.clear();
  188916. bufferSizes.clear();
  188917. sampleRates.clear();
  188918. isASIOOpen = false;
  188919. isOpen_ = false;
  188920. totalNumInputChans = 0;
  188921. totalNumOutputChans = 0;
  188922. numActiveInputChans = 0;
  188923. numActiveOutputChans = 0;
  188924. currentCallback = 0;
  188925. error = String::empty;
  188926. if (getName().isEmpty())
  188927. return error;
  188928. long err = 0;
  188929. if (loadDriver())
  188930. {
  188931. if ((error = initDriver()).isEmpty())
  188932. {
  188933. numActiveInputChans = 0;
  188934. numActiveOutputChans = 0;
  188935. totalNumInputChans = 0;
  188936. totalNumOutputChans = 0;
  188937. if (asioObject != 0
  188938. && (err = asioObject->getChannels (&totalNumInputChans, &totalNumOutputChans)) == 0)
  188939. {
  188940. log (String ((int) totalNumInputChans) + T(" in, ") + String ((int) totalNumOutputChans) + T(" out"));
  188941. if ((err = asioObject->getBufferSize (&minSize, &maxSize, &preferredSize, &granularity)) == 0)
  188942. {
  188943. // find a list of buffer sizes..
  188944. log (String ((int) minSize) + T(" ") + String ((int) maxSize) + T(" ") + String ((int)preferredSize) + T(" ") + String ((int)granularity));
  188945. if (granularity >= 0)
  188946. {
  188947. granularity = jmax (1, (int) granularity);
  188948. for (int i = jmax ((int) minSize, (int) granularity); i < jmin (6400, (int) maxSize); i += granularity)
  188949. bufferSizes.addIfNotAlreadyThere (granularity * (i / granularity));
  188950. }
  188951. else if (granularity < 0)
  188952. {
  188953. for (int i = 0; i < 18; ++i)
  188954. {
  188955. const int s = (1 << i);
  188956. if (s >= minSize && s <= maxSize)
  188957. bufferSizes.add (s);
  188958. }
  188959. }
  188960. if (! bufferSizes.contains (preferredSize))
  188961. bufferSizes.insert (0, preferredSize);
  188962. double currentRate = 0;
  188963. asioObject->getSampleRate (&currentRate);
  188964. if (currentRate <= 0.0 || currentRate > 192001.0)
  188965. {
  188966. log ("setting sample rate");
  188967. err = asioObject->setSampleRate (44100.0);
  188968. if (err != 0)
  188969. {
  188970. logError ("setting sample rate", err);
  188971. }
  188972. asioObject->getSampleRate (&currentRate);
  188973. }
  188974. currentSampleRate = currentRate;
  188975. postOutput = (asioObject->outputReady() == 0);
  188976. if (postOutput)
  188977. {
  188978. log ("ASIO outputReady = ok");
  188979. }
  188980. updateSampleRates();
  188981. // ..because cubase does it at this point
  188982. inputLatency = outputLatency = 0;
  188983. if (asioObject->getLatencies (&inputLatency, &outputLatency) != 0)
  188984. {
  188985. log ("ASIO - no latencies");
  188986. }
  188987. log (String ("latencies: ")
  188988. + String ((int) inputLatency)
  188989. + T(", ") + String ((int) outputLatency));
  188990. // create some dummy buffers now.. because cubase does..
  188991. numActiveInputChans = 0;
  188992. numActiveOutputChans = 0;
  188993. ASIOBufferInfo* info = bufferInfos;
  188994. int i, numChans = 0;
  188995. for (i = 0; i < jmin (2, (int) totalNumInputChans); ++i)
  188996. {
  188997. info->isInput = 1;
  188998. info->channelNum = i;
  188999. info->buffers[0] = info->buffers[1] = 0;
  189000. ++info;
  189001. ++numChans;
  189002. }
  189003. const int outputBufferIndex = numChans;
  189004. for (i = 0; i < jmin (2, (int) totalNumOutputChans); ++i)
  189005. {
  189006. info->isInput = 0;
  189007. info->channelNum = i;
  189008. info->buffers[0] = info->buffers[1] = 0;
  189009. ++info;
  189010. ++numChans;
  189011. }
  189012. callbacks.sampleRateDidChange = &sampleRateChangedCallback;
  189013. if (currentASIODev[0] == this)
  189014. {
  189015. callbacks.bufferSwitch = &bufferSwitchCallback0;
  189016. callbacks.asioMessage = &asioMessagesCallback0;
  189017. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback0;
  189018. }
  189019. else if (currentASIODev[1] == this)
  189020. {
  189021. callbacks.bufferSwitch = &bufferSwitchCallback1;
  189022. callbacks.asioMessage = &asioMessagesCallback1;
  189023. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback1;
  189024. }
  189025. else if (currentASIODev[2] == this)
  189026. {
  189027. callbacks.bufferSwitch = &bufferSwitchCallback2;
  189028. callbacks.asioMessage = &asioMessagesCallback2;
  189029. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback2;
  189030. }
  189031. else
  189032. {
  189033. jassertfalse
  189034. }
  189035. log (T("creating buffers (dummy): ") + String (numChans)
  189036. + T(", ") + String ((int) preferredSize));
  189037. if (preferredSize > 0)
  189038. {
  189039. err = asioObject->createBuffers (bufferInfos, numChans, preferredSize, &callbacks);
  189040. if (err != 0)
  189041. {
  189042. logError ("dummy buffers", err);
  189043. }
  189044. }
  189045. long newInps = 0, newOuts = 0;
  189046. asioObject->getChannels (&newInps, &newOuts);
  189047. if (totalNumInputChans != newInps || totalNumOutputChans != newOuts)
  189048. {
  189049. totalNumInputChans = newInps;
  189050. totalNumOutputChans = newOuts;
  189051. log (String ((int) totalNumInputChans) + T(" in; ")
  189052. + String ((int) totalNumOutputChans) + T(" out"));
  189053. }
  189054. updateSampleRates();
  189055. ASIOChannelInfo channelInfo;
  189056. channelInfo.type = 0;
  189057. for (i = 0; i < totalNumInputChans; ++i)
  189058. {
  189059. zerostruct (channelInfo);
  189060. channelInfo.channel = i;
  189061. channelInfo.isInput = 1;
  189062. asioObject->getChannelInfo (&channelInfo);
  189063. inputChannelNames.add (String (channelInfo.name));
  189064. }
  189065. for (i = 0; i < totalNumOutputChans; ++i)
  189066. {
  189067. zerostruct (channelInfo);
  189068. channelInfo.channel = i;
  189069. channelInfo.isInput = 0;
  189070. asioObject->getChannelInfo (&channelInfo);
  189071. outputChannelNames.add (String (channelInfo.name));
  189072. typeToFormatParameters (channelInfo.type,
  189073. outputChannelBitDepths[i],
  189074. outputChannelBytesPerSample[i],
  189075. outputChannelIsFloat[i],
  189076. outputChannelLittleEndian[i]);
  189077. if (i < 2)
  189078. {
  189079. // clear the channels that are used with the dummy stuff
  189080. const int bytesPerBuffer = preferredSize * (outputChannelBitDepths[i] >> 3);
  189081. zeromem (bufferInfos [outputBufferIndex + i].buffers[0], bytesPerBuffer);
  189082. zeromem (bufferInfos [outputBufferIndex + i].buffers[1], bytesPerBuffer);
  189083. }
  189084. }
  189085. outputChannelNames.trim();
  189086. inputChannelNames.trim();
  189087. outputChannelNames.appendNumbersToDuplicates (false, true);
  189088. inputChannelNames.appendNumbersToDuplicates (false, true);
  189089. // start and stop because cubase does it..
  189090. asioObject->getLatencies (&inputLatency, &outputLatency);
  189091. if ((err = asioObject->start()) != 0)
  189092. {
  189093. // ignore an error here, as it might start later after setting other stuff up
  189094. logError ("ASIO start", err);
  189095. }
  189096. Thread::sleep (100);
  189097. asioObject->stop();
  189098. }
  189099. else
  189100. {
  189101. error = "Can't detect buffer sizes";
  189102. }
  189103. }
  189104. else
  189105. {
  189106. error = "Can't detect asio channels";
  189107. }
  189108. }
  189109. }
  189110. else
  189111. {
  189112. error = "No such device";
  189113. }
  189114. if (error.isNotEmpty())
  189115. {
  189116. logError (error, err);
  189117. if (asioObject != 0)
  189118. asioObject->disposeBuffers();
  189119. removeCurrentDriver();
  189120. isASIOOpen = false;
  189121. }
  189122. else
  189123. {
  189124. isASIOOpen = true;
  189125. log ("ASIO device open");
  189126. }
  189127. isOpen_ = false;
  189128. needToReset = false;
  189129. isReSync = false;
  189130. return error;
  189131. }
  189132. void callback (const long index) throw()
  189133. {
  189134. if (isStarted)
  189135. {
  189136. bufferIndex = index;
  189137. processBuffer();
  189138. }
  189139. else
  189140. {
  189141. if (postOutput && (asioObject != 0))
  189142. asioObject->outputReady();
  189143. }
  189144. calledback = true;
  189145. }
  189146. void processBuffer() throw()
  189147. {
  189148. const ASIOBufferInfo* const infos = bufferInfos;
  189149. const int bi = bufferIndex;
  189150. const ScopedLock sl (callbackLock);
  189151. if (needToReset)
  189152. {
  189153. needToReset = false;
  189154. if (isReSync)
  189155. {
  189156. log ("! ASIO resync");
  189157. isReSync = false;
  189158. }
  189159. else
  189160. {
  189161. startTimer (20);
  189162. }
  189163. }
  189164. if (bi >= 0)
  189165. {
  189166. const int samps = currentBlockSizeSamples;
  189167. if (currentCallback != 0)
  189168. {
  189169. int i;
  189170. for (i = 0; i < numActiveInputChans; ++i)
  189171. {
  189172. float* const dst = inBuffers[i];
  189173. jassert (dst != 0);
  189174. const char* const src = (const char*) (infos[i].buffers[bi]);
  189175. if (inputChannelIsFloat[i])
  189176. {
  189177. memcpy (dst, src, samps * sizeof (float));
  189178. }
  189179. else
  189180. {
  189181. jassert (dst == tempBuffer + (samps * i));
  189182. switch (inputChannelBitDepths[i])
  189183. {
  189184. case 16:
  189185. convertInt16ToFloat (src, dst, inputChannelBytesPerSample[i],
  189186. samps, inputChannelLittleEndian[i]);
  189187. break;
  189188. case 24:
  189189. convertInt24ToFloat (src, dst, inputChannelBytesPerSample[i],
  189190. samps, inputChannelLittleEndian[i]);
  189191. break;
  189192. case 32:
  189193. convertInt32ToFloat (src, dst, inputChannelBytesPerSample[i],
  189194. samps, inputChannelLittleEndian[i]);
  189195. break;
  189196. case 64:
  189197. jassertfalse
  189198. break;
  189199. }
  189200. }
  189201. }
  189202. currentCallback->audioDeviceIOCallback ((const float**) inBuffers,
  189203. numActiveInputChans,
  189204. outBuffers,
  189205. numActiveOutputChans,
  189206. samps);
  189207. for (i = 0; i < numActiveOutputChans; ++i)
  189208. {
  189209. float* const src = outBuffers[i];
  189210. jassert (src != 0);
  189211. char* const dst = (char*) (infos [numActiveInputChans + i].buffers[bi]);
  189212. if (outputChannelIsFloat[i])
  189213. {
  189214. memcpy (dst, src, samps * sizeof (float));
  189215. }
  189216. else
  189217. {
  189218. jassert (src == tempBuffer + (samps * (numActiveInputChans + i)));
  189219. switch (outputChannelBitDepths[i])
  189220. {
  189221. case 16:
  189222. convertFloatToInt16 (src, dst, outputChannelBytesPerSample[i],
  189223. samps, outputChannelLittleEndian[i]);
  189224. break;
  189225. case 24:
  189226. convertFloatToInt24 (src, dst, outputChannelBytesPerSample[i],
  189227. samps, outputChannelLittleEndian[i]);
  189228. break;
  189229. case 32:
  189230. convertFloatToInt32 (src, dst, outputChannelBytesPerSample[i],
  189231. samps, outputChannelLittleEndian[i]);
  189232. break;
  189233. case 64:
  189234. jassertfalse
  189235. break;
  189236. }
  189237. }
  189238. }
  189239. }
  189240. else
  189241. {
  189242. for (int i = 0; i < numActiveOutputChans; ++i)
  189243. {
  189244. const int bytesPerBuffer = samps * (outputChannelBitDepths[i] >> 3);
  189245. zeromem (infos[numActiveInputChans + i].buffers[bi], bytesPerBuffer);
  189246. }
  189247. }
  189248. }
  189249. if (postOutput)
  189250. asioObject->outputReady();
  189251. }
  189252. static ASIOTime* bufferSwitchTimeInfoCallback0 (ASIOTime*, long index, long) throw()
  189253. {
  189254. if (currentASIODev[0] != 0)
  189255. currentASIODev[0]->callback (index);
  189256. return 0;
  189257. }
  189258. static ASIOTime* bufferSwitchTimeInfoCallback1 (ASIOTime*, long index, long) throw()
  189259. {
  189260. if (currentASIODev[1] != 0)
  189261. currentASIODev[1]->callback (index);
  189262. return 0;
  189263. }
  189264. static ASIOTime* bufferSwitchTimeInfoCallback2 (ASIOTime*, long index, long) throw()
  189265. {
  189266. if (currentASIODev[2] != 0)
  189267. currentASIODev[2]->callback (index);
  189268. return 0;
  189269. }
  189270. static void bufferSwitchCallback0 (long index, long) throw()
  189271. {
  189272. if (currentASIODev[0] != 0)
  189273. currentASIODev[0]->callback (index);
  189274. }
  189275. static void bufferSwitchCallback1 (long index, long) throw()
  189276. {
  189277. if (currentASIODev[1] != 0)
  189278. currentASIODev[1]->callback (index);
  189279. }
  189280. static void bufferSwitchCallback2 (long index, long) throw()
  189281. {
  189282. if (currentASIODev[2] != 0)
  189283. currentASIODev[2]->callback (index);
  189284. }
  189285. static long asioMessagesCallback0 (long selector, long value, void*, double*) throw()
  189286. {
  189287. return asioMessagesCallback (selector, value, 0);
  189288. }
  189289. static long asioMessagesCallback1 (long selector, long value, void*, double*) throw()
  189290. {
  189291. return asioMessagesCallback (selector, value, 1);
  189292. }
  189293. static long asioMessagesCallback2 (long selector, long value, void*, double*) throw()
  189294. {
  189295. return asioMessagesCallback (selector, value, 2);
  189296. }
  189297. static long asioMessagesCallback (long selector, long value, const int deviceIndex) throw()
  189298. {
  189299. switch (selector)
  189300. {
  189301. case kAsioSelectorSupported:
  189302. if (value == kAsioResetRequest
  189303. || value == kAsioEngineVersion
  189304. || value == kAsioResyncRequest
  189305. || value == kAsioLatenciesChanged
  189306. || value == kAsioSupportsInputMonitor)
  189307. return 1;
  189308. break;
  189309. case kAsioBufferSizeChange:
  189310. break;
  189311. case kAsioResetRequest:
  189312. if (currentASIODev[deviceIndex] != 0)
  189313. currentASIODev[deviceIndex]->resetRequest();
  189314. return 1;
  189315. case kAsioResyncRequest:
  189316. if (currentASIODev[deviceIndex] != 0)
  189317. currentASIODev[deviceIndex]->resyncRequest();
  189318. return 1;
  189319. case kAsioLatenciesChanged:
  189320. return 1;
  189321. case kAsioEngineVersion:
  189322. return 2;
  189323. case kAsioSupportsTimeInfo:
  189324. case kAsioSupportsTimeCode:
  189325. return 0;
  189326. }
  189327. return 0;
  189328. }
  189329. static void sampleRateChangedCallback (ASIOSampleRate) throw()
  189330. {
  189331. }
  189332. static void convertInt16ToFloat (const char* src,
  189333. float* dest,
  189334. const int srcStrideBytes,
  189335. int numSamples,
  189336. const bool littleEndian) throw()
  189337. {
  189338. const double g = 1.0 / 32768.0;
  189339. if (littleEndian)
  189340. {
  189341. while (--numSamples >= 0)
  189342. {
  189343. *dest++ = (float) (g * (short) ByteOrder::littleEndianShort (src));
  189344. src += srcStrideBytes;
  189345. }
  189346. }
  189347. else
  189348. {
  189349. while (--numSamples >= 0)
  189350. {
  189351. *dest++ = (float) (g * (short) ByteOrder::bigEndianShort (src));
  189352. src += srcStrideBytes;
  189353. }
  189354. }
  189355. }
  189356. static void convertFloatToInt16 (const float* src,
  189357. char* dest,
  189358. const int dstStrideBytes,
  189359. int numSamples,
  189360. const bool littleEndian) throw()
  189361. {
  189362. const double maxVal = (double) 0x7fff;
  189363. if (littleEndian)
  189364. {
  189365. while (--numSamples >= 0)
  189366. {
  189367. *(uint16*) dest = ByteOrder::swapIfBigEndian ((uint16) (short) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189368. dest += dstStrideBytes;
  189369. }
  189370. }
  189371. else
  189372. {
  189373. while (--numSamples >= 0)
  189374. {
  189375. *(uint16*) dest = ByteOrder::swapIfLittleEndian ((uint16) (short) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189376. dest += dstStrideBytes;
  189377. }
  189378. }
  189379. }
  189380. static void convertInt24ToFloat (const char* src,
  189381. float* dest,
  189382. const int srcStrideBytes,
  189383. int numSamples,
  189384. const bool littleEndian) throw()
  189385. {
  189386. const double g = 1.0 / 0x7fffff;
  189387. if (littleEndian)
  189388. {
  189389. while (--numSamples >= 0)
  189390. {
  189391. *dest++ = (float) (g * ByteOrder::littleEndian24Bit (src));
  189392. src += srcStrideBytes;
  189393. }
  189394. }
  189395. else
  189396. {
  189397. while (--numSamples >= 0)
  189398. {
  189399. *dest++ = (float) (g * ByteOrder::bigEndian24Bit (src));
  189400. src += srcStrideBytes;
  189401. }
  189402. }
  189403. }
  189404. static void convertFloatToInt24 (const float* src,
  189405. char* dest,
  189406. const int dstStrideBytes,
  189407. int numSamples,
  189408. const bool littleEndian) throw()
  189409. {
  189410. const double maxVal = (double) 0x7fffff;
  189411. if (littleEndian)
  189412. {
  189413. while (--numSamples >= 0)
  189414. {
  189415. ByteOrder::littleEndian24BitToChars ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)), dest);
  189416. dest += dstStrideBytes;
  189417. }
  189418. }
  189419. else
  189420. {
  189421. while (--numSamples >= 0)
  189422. {
  189423. ByteOrder::bigEndian24BitToChars ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)), dest);
  189424. dest += dstStrideBytes;
  189425. }
  189426. }
  189427. }
  189428. static void convertInt32ToFloat (const char* src,
  189429. float* dest,
  189430. const int srcStrideBytes,
  189431. int numSamples,
  189432. const bool littleEndian) throw()
  189433. {
  189434. const double g = 1.0 / 0x7fffffff;
  189435. if (littleEndian)
  189436. {
  189437. while (--numSamples >= 0)
  189438. {
  189439. *dest++ = (float) (g * (int) ByteOrder::littleEndianInt (src));
  189440. src += srcStrideBytes;
  189441. }
  189442. }
  189443. else
  189444. {
  189445. while (--numSamples >= 0)
  189446. {
  189447. *dest++ = (float) (g * (int) ByteOrder::bigEndianInt (src));
  189448. src += srcStrideBytes;
  189449. }
  189450. }
  189451. }
  189452. static void convertFloatToInt32 (const float* src,
  189453. char* dest,
  189454. const int dstStrideBytes,
  189455. int numSamples,
  189456. const bool littleEndian) throw()
  189457. {
  189458. const double maxVal = (double) 0x7fffffff;
  189459. if (littleEndian)
  189460. {
  189461. while (--numSamples >= 0)
  189462. {
  189463. *(uint32*) dest = ByteOrder::swapIfBigEndian ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189464. dest += dstStrideBytes;
  189465. }
  189466. }
  189467. else
  189468. {
  189469. while (--numSamples >= 0)
  189470. {
  189471. *(uint32*) dest = ByteOrder::swapIfLittleEndian ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189472. dest += dstStrideBytes;
  189473. }
  189474. }
  189475. }
  189476. static void typeToFormatParameters (const long type,
  189477. int& bitDepth,
  189478. int& byteStride,
  189479. bool& formatIsFloat,
  189480. bool& littleEndian) throw()
  189481. {
  189482. bitDepth = 0;
  189483. littleEndian = false;
  189484. formatIsFloat = false;
  189485. switch (type)
  189486. {
  189487. case ASIOSTInt16MSB:
  189488. case ASIOSTInt16LSB:
  189489. case ASIOSTInt32MSB16:
  189490. case ASIOSTInt32LSB16:
  189491. bitDepth = 16; break;
  189492. case ASIOSTFloat32MSB:
  189493. case ASIOSTFloat32LSB:
  189494. formatIsFloat = true;
  189495. bitDepth = 32; break;
  189496. case ASIOSTInt32MSB:
  189497. case ASIOSTInt32LSB:
  189498. bitDepth = 32; break;
  189499. case ASIOSTInt24MSB:
  189500. case ASIOSTInt24LSB:
  189501. case ASIOSTInt32MSB24:
  189502. case ASIOSTInt32LSB24:
  189503. case ASIOSTInt32MSB18:
  189504. case ASIOSTInt32MSB20:
  189505. case ASIOSTInt32LSB18:
  189506. case ASIOSTInt32LSB20:
  189507. bitDepth = 24; break;
  189508. case ASIOSTFloat64MSB:
  189509. case ASIOSTFloat64LSB:
  189510. default:
  189511. bitDepth = 64;
  189512. break;
  189513. }
  189514. switch (type)
  189515. {
  189516. case ASIOSTInt16MSB:
  189517. case ASIOSTInt32MSB16:
  189518. case ASIOSTFloat32MSB:
  189519. case ASIOSTFloat64MSB:
  189520. case ASIOSTInt32MSB:
  189521. case ASIOSTInt32MSB18:
  189522. case ASIOSTInt32MSB20:
  189523. case ASIOSTInt32MSB24:
  189524. case ASIOSTInt24MSB:
  189525. littleEndian = false; break;
  189526. case ASIOSTInt16LSB:
  189527. case ASIOSTInt32LSB16:
  189528. case ASIOSTFloat32LSB:
  189529. case ASIOSTFloat64LSB:
  189530. case ASIOSTInt32LSB:
  189531. case ASIOSTInt32LSB18:
  189532. case ASIOSTInt32LSB20:
  189533. case ASIOSTInt32LSB24:
  189534. case ASIOSTInt24LSB:
  189535. littleEndian = true; break;
  189536. default:
  189537. break;
  189538. }
  189539. switch (type)
  189540. {
  189541. case ASIOSTInt16LSB:
  189542. case ASIOSTInt16MSB:
  189543. byteStride = 2; break;
  189544. case ASIOSTInt24LSB:
  189545. case ASIOSTInt24MSB:
  189546. byteStride = 3; break;
  189547. case ASIOSTInt32MSB16:
  189548. case ASIOSTInt32LSB16:
  189549. case ASIOSTInt32MSB:
  189550. case ASIOSTInt32MSB18:
  189551. case ASIOSTInt32MSB20:
  189552. case ASIOSTInt32MSB24:
  189553. case ASIOSTInt32LSB:
  189554. case ASIOSTInt32LSB18:
  189555. case ASIOSTInt32LSB20:
  189556. case ASIOSTInt32LSB24:
  189557. case ASIOSTFloat32LSB:
  189558. case ASIOSTFloat32MSB:
  189559. byteStride = 4; break;
  189560. case ASIOSTFloat64MSB:
  189561. case ASIOSTFloat64LSB:
  189562. byteStride = 8; break;
  189563. default:
  189564. break;
  189565. }
  189566. }
  189567. };
  189568. class ASIOAudioIODeviceType : public AudioIODeviceType
  189569. {
  189570. public:
  189571. ASIOAudioIODeviceType()
  189572. : AudioIODeviceType (T("ASIO")),
  189573. hasScanned (false)
  189574. {
  189575. CoInitialize (0);
  189576. }
  189577. ~ASIOAudioIODeviceType()
  189578. {
  189579. }
  189580. void scanForDevices()
  189581. {
  189582. hasScanned = true;
  189583. deviceNames.clear();
  189584. classIds.clear();
  189585. HKEY hk = 0;
  189586. int index = 0;
  189587. if (RegOpenKeyA (HKEY_LOCAL_MACHINE, "software\\asio", &hk) == ERROR_SUCCESS)
  189588. {
  189589. for (;;)
  189590. {
  189591. char name [256];
  189592. if (RegEnumKeyA (hk, index++, name, 256) == ERROR_SUCCESS)
  189593. {
  189594. addDriverInfo (name, hk);
  189595. }
  189596. else
  189597. {
  189598. break;
  189599. }
  189600. }
  189601. RegCloseKey (hk);
  189602. }
  189603. }
  189604. const StringArray getDeviceNames (const bool /*wantInputNames*/) const
  189605. {
  189606. jassert (hasScanned); // need to call scanForDevices() before doing this
  189607. return deviceNames;
  189608. }
  189609. int getDefaultDeviceIndex (const bool) const
  189610. {
  189611. jassert (hasScanned); // need to call scanForDevices() before doing this
  189612. for (int i = deviceNames.size(); --i >= 0;)
  189613. if (deviceNames[i].containsIgnoreCase (T("asio4all")))
  189614. return i; // asio4all is a safe choice for a default..
  189615. #if JUCE_DEBUG
  189616. if (deviceNames.size() > 1 && deviceNames[0].containsIgnoreCase (T("digidesign")))
  189617. return 1; // (the digi m-box driver crashes the app when you run
  189618. // it in the debugger, which can be a bit annoying)
  189619. #endif
  189620. return 0;
  189621. }
  189622. static int findFreeSlot()
  189623. {
  189624. for (int i = 0; i < numElementsInArray (currentASIODev); ++i)
  189625. if (currentASIODev[i] == 0)
  189626. return i;
  189627. jassertfalse; // unfortunately you can only have a finite number
  189628. // of ASIO devices open at the same time..
  189629. return -1;
  189630. }
  189631. int getIndexOfDevice (AudioIODevice* d, const bool /*asInput*/) const
  189632. {
  189633. jassert (hasScanned); // need to call scanForDevices() before doing this
  189634. return d == 0 ? -1 : deviceNames.indexOf (d->getName());
  189635. }
  189636. bool hasSeparateInputsAndOutputs() const { return false; }
  189637. AudioIODevice* createDevice (const String& outputDeviceName,
  189638. const String& inputDeviceName)
  189639. {
  189640. // ASIO can't open two different devices for input and output - they must be the same one.
  189641. jassert (inputDeviceName == outputDeviceName || outputDeviceName.isEmpty() || inputDeviceName.isEmpty());
  189642. jassert (hasScanned); // need to call scanForDevices() before doing this
  189643. const int index = deviceNames.indexOf (outputDeviceName.isNotEmpty() ? outputDeviceName
  189644. : inputDeviceName);
  189645. if (index >= 0)
  189646. {
  189647. const int freeSlot = findFreeSlot();
  189648. if (freeSlot >= 0)
  189649. return new ASIOAudioIODevice (outputDeviceName, *(classIds [index]), freeSlot, String::empty);
  189650. }
  189651. return 0;
  189652. }
  189653. juce_UseDebuggingNewOperator
  189654. private:
  189655. StringArray deviceNames;
  189656. OwnedArray <CLSID> classIds;
  189657. bool hasScanned;
  189658. static bool checkClassIsOk (const String& classId)
  189659. {
  189660. HKEY hk = 0;
  189661. bool ok = false;
  189662. if (RegOpenKey (HKEY_CLASSES_ROOT, _T("clsid"), &hk) == ERROR_SUCCESS)
  189663. {
  189664. int index = 0;
  189665. for (;;)
  189666. {
  189667. WCHAR buf [512];
  189668. if (RegEnumKey (hk, index++, buf, 512) == ERROR_SUCCESS)
  189669. {
  189670. if (classId.equalsIgnoreCase (buf))
  189671. {
  189672. HKEY subKey, pathKey;
  189673. if (RegOpenKeyEx (hk, buf, 0, KEY_READ, &subKey) == ERROR_SUCCESS)
  189674. {
  189675. if (RegOpenKeyEx (subKey, _T("InprocServer32"), 0, KEY_READ, &pathKey) == ERROR_SUCCESS)
  189676. {
  189677. WCHAR pathName [1024];
  189678. DWORD dtype = REG_SZ;
  189679. DWORD dsize = sizeof (pathName);
  189680. if (RegQueryValueEx (pathKey, 0, 0, &dtype, (LPBYTE) pathName, &dsize) == ERROR_SUCCESS)
  189681. ok = File (pathName).exists();
  189682. RegCloseKey (pathKey);
  189683. }
  189684. RegCloseKey (subKey);
  189685. }
  189686. break;
  189687. }
  189688. }
  189689. else
  189690. {
  189691. break;
  189692. }
  189693. }
  189694. RegCloseKey (hk);
  189695. }
  189696. return ok;
  189697. }
  189698. void addDriverInfo (const String& keyName, HKEY hk)
  189699. {
  189700. HKEY subKey;
  189701. if (RegOpenKeyEx (hk, keyName, 0, KEY_READ, &subKey) == ERROR_SUCCESS)
  189702. {
  189703. WCHAR buf [256];
  189704. zerostruct (buf);
  189705. DWORD dtype = REG_SZ;
  189706. DWORD dsize = sizeof (buf);
  189707. if (RegQueryValueEx (subKey, _T("clsid"), 0, &dtype, (LPBYTE) buf, &dsize) == ERROR_SUCCESS)
  189708. {
  189709. if (dsize > 0 && checkClassIsOk (buf))
  189710. {
  189711. CLSID classId;
  189712. if (CLSIDFromString ((LPOLESTR) buf, &classId) == S_OK)
  189713. {
  189714. dtype = REG_SZ;
  189715. dsize = sizeof (buf);
  189716. String deviceName;
  189717. if (RegQueryValueEx (subKey, _T("description"), 0, &dtype, (LPBYTE) buf, &dsize) == ERROR_SUCCESS)
  189718. deviceName = buf;
  189719. else
  189720. deviceName = keyName;
  189721. log (T("found ") + deviceName);
  189722. deviceNames.add (deviceName);
  189723. classIds.add (new CLSID (classId));
  189724. }
  189725. }
  189726. RegCloseKey (subKey);
  189727. }
  189728. }
  189729. }
  189730. ASIOAudioIODeviceType (const ASIOAudioIODeviceType&);
  189731. ASIOAudioIODeviceType& operator= (const ASIOAudioIODeviceType&);
  189732. };
  189733. AudioIODeviceType* juce_createAudioIODeviceType_ASIO()
  189734. {
  189735. return new ASIOAudioIODeviceType();
  189736. }
  189737. AudioIODevice* juce_createASIOAudioIODeviceForGUID (const String& name,
  189738. void* guid,
  189739. const String& optionalDllForDirectLoading)
  189740. {
  189741. const int freeSlot = ASIOAudioIODeviceType::findFreeSlot();
  189742. if (freeSlot < 0)
  189743. return 0;
  189744. return new ASIOAudioIODevice (name, *(CLSID*) guid, freeSlot, optionalDllForDirectLoading);
  189745. }
  189746. #undef log
  189747. #endif
  189748. /*** End of inlined file: juce_win32_ASIO.cpp ***/
  189749. /*** Start of inlined file: juce_win32_DirectSound.cpp ***/
  189750. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  189751. // compiled on its own).
  189752. #if JUCE_INCLUDED_FILE && JUCE_DIRECTSOUND
  189753. END_JUCE_NAMESPACE
  189754. extern "C"
  189755. {
  189756. // Declare just the minimum number of interfaces for the DSound objects that we need..
  189757. typedef struct typeDSBUFFERDESC
  189758. {
  189759. DWORD dwSize;
  189760. DWORD dwFlags;
  189761. DWORD dwBufferBytes;
  189762. DWORD dwReserved;
  189763. LPWAVEFORMATEX lpwfxFormat;
  189764. GUID guid3DAlgorithm;
  189765. } DSBUFFERDESC;
  189766. struct IDirectSoundBuffer;
  189767. #undef INTERFACE
  189768. #define INTERFACE IDirectSound
  189769. DECLARE_INTERFACE_(IDirectSound, IUnknown)
  189770. {
  189771. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  189772. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  189773. STDMETHOD_(ULONG,Release) (THIS) PURE;
  189774. STDMETHOD(CreateSoundBuffer) (THIS_ DSBUFFERDESC*, IDirectSoundBuffer**, LPUNKNOWN) PURE;
  189775. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  189776. STDMETHOD(DuplicateSoundBuffer) (THIS_ IDirectSoundBuffer*, IDirectSoundBuffer**) PURE;
  189777. STDMETHOD(SetCooperativeLevel) (THIS_ HWND, DWORD) PURE;
  189778. STDMETHOD(Compact) (THIS) PURE;
  189779. STDMETHOD(GetSpeakerConfig) (THIS_ LPDWORD) PURE;
  189780. STDMETHOD(SetSpeakerConfig) (THIS_ DWORD) PURE;
  189781. STDMETHOD(Initialize) (THIS_ const GUID*) PURE;
  189782. };
  189783. #undef INTERFACE
  189784. #define INTERFACE IDirectSoundBuffer
  189785. DECLARE_INTERFACE_(IDirectSoundBuffer, IUnknown)
  189786. {
  189787. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  189788. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  189789. STDMETHOD_(ULONG,Release) (THIS) PURE;
  189790. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  189791. STDMETHOD(GetCurrentPosition) (THIS_ LPDWORD, LPDWORD) PURE;
  189792. STDMETHOD(GetFormat) (THIS_ LPWAVEFORMATEX, DWORD, LPDWORD) PURE;
  189793. STDMETHOD(GetVolume) (THIS_ LPLONG) PURE;
  189794. STDMETHOD(GetPan) (THIS_ LPLONG) PURE;
  189795. STDMETHOD(GetFrequency) (THIS_ LPDWORD) PURE;
  189796. STDMETHOD(GetStatus) (THIS_ LPDWORD) PURE;
  189797. STDMETHOD(Initialize) (THIS_ IDirectSound*, DSBUFFERDESC*) PURE;
  189798. STDMETHOD(Lock) (THIS_ DWORD, DWORD, LPVOID*, LPDWORD, LPVOID*, LPDWORD, DWORD) PURE;
  189799. STDMETHOD(Play) (THIS_ DWORD, DWORD, DWORD) PURE;
  189800. STDMETHOD(SetCurrentPosition) (THIS_ DWORD) PURE;
  189801. STDMETHOD(SetFormat) (THIS_ const WAVEFORMATEX*) PURE;
  189802. STDMETHOD(SetVolume) (THIS_ LONG) PURE;
  189803. STDMETHOD(SetPan) (THIS_ LONG) PURE;
  189804. STDMETHOD(SetFrequency) (THIS_ DWORD) PURE;
  189805. STDMETHOD(Stop) (THIS) PURE;
  189806. STDMETHOD(Unlock) (THIS_ LPVOID, DWORD, LPVOID, DWORD) PURE;
  189807. STDMETHOD(Restore) (THIS) PURE;
  189808. };
  189809. typedef struct typeDSCBUFFERDESC
  189810. {
  189811. DWORD dwSize;
  189812. DWORD dwFlags;
  189813. DWORD dwBufferBytes;
  189814. DWORD dwReserved;
  189815. LPWAVEFORMATEX lpwfxFormat;
  189816. } DSCBUFFERDESC;
  189817. struct IDirectSoundCaptureBuffer;
  189818. #undef INTERFACE
  189819. #define INTERFACE IDirectSoundCapture
  189820. DECLARE_INTERFACE_(IDirectSoundCapture, IUnknown)
  189821. {
  189822. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  189823. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  189824. STDMETHOD_(ULONG,Release) (THIS) PURE;
  189825. STDMETHOD(CreateCaptureBuffer) (THIS_ DSCBUFFERDESC*, IDirectSoundCaptureBuffer**, LPUNKNOWN) PURE;
  189826. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  189827. STDMETHOD(Initialize) (THIS_ const GUID*) PURE;
  189828. };
  189829. #undef INTERFACE
  189830. #define INTERFACE IDirectSoundCaptureBuffer
  189831. DECLARE_INTERFACE_(IDirectSoundCaptureBuffer, IUnknown)
  189832. {
  189833. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  189834. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  189835. STDMETHOD_(ULONG,Release) (THIS) PURE;
  189836. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  189837. STDMETHOD(GetCurrentPosition) (THIS_ LPDWORD, LPDWORD) PURE;
  189838. STDMETHOD(GetFormat) (THIS_ LPWAVEFORMATEX, DWORD, LPDWORD) PURE;
  189839. STDMETHOD(GetStatus) (THIS_ LPDWORD) PURE;
  189840. STDMETHOD(Initialize) (THIS_ IDirectSoundCapture*, DSCBUFFERDESC*) PURE;
  189841. STDMETHOD(Lock) (THIS_ DWORD, DWORD, LPVOID*, LPDWORD, LPVOID*, LPDWORD, DWORD) PURE;
  189842. STDMETHOD(Start) (THIS_ DWORD) PURE;
  189843. STDMETHOD(Stop) (THIS) PURE;
  189844. STDMETHOD(Unlock) (THIS_ LPVOID, DWORD, LPVOID, DWORD) PURE;
  189845. };
  189846. };
  189847. BEGIN_JUCE_NAMESPACE
  189848. static const String getDSErrorMessage (HRESULT hr)
  189849. {
  189850. const char* result = 0;
  189851. switch (hr)
  189852. {
  189853. case MAKE_HRESULT(1, 0x878, 10):
  189854. result = "Device already allocated";
  189855. break;
  189856. case MAKE_HRESULT(1, 0x878, 30):
  189857. result = "Control unavailable";
  189858. break;
  189859. case E_INVALIDARG:
  189860. result = "Invalid parameter";
  189861. break;
  189862. case MAKE_HRESULT(1, 0x878, 50):
  189863. result = "Invalid call";
  189864. break;
  189865. case E_FAIL:
  189866. result = "Generic error";
  189867. break;
  189868. case MAKE_HRESULT(1, 0x878, 70):
  189869. result = "Priority level error";
  189870. break;
  189871. case E_OUTOFMEMORY:
  189872. result = "Out of memory";
  189873. break;
  189874. case MAKE_HRESULT(1, 0x878, 100):
  189875. result = "Bad format";
  189876. break;
  189877. case E_NOTIMPL:
  189878. result = "Unsupported function";
  189879. break;
  189880. case MAKE_HRESULT(1, 0x878, 120):
  189881. result = "No driver";
  189882. break;
  189883. case MAKE_HRESULT(1, 0x878, 130):
  189884. result = "Already initialised";
  189885. break;
  189886. case CLASS_E_NOAGGREGATION:
  189887. result = "No aggregation";
  189888. break;
  189889. case MAKE_HRESULT(1, 0x878, 150):
  189890. result = "Buffer lost";
  189891. break;
  189892. case MAKE_HRESULT(1, 0x878, 160):
  189893. result = "Another app has priority";
  189894. break;
  189895. case MAKE_HRESULT(1, 0x878, 170):
  189896. result = "Uninitialised";
  189897. break;
  189898. case E_NOINTERFACE:
  189899. result = "No interface";
  189900. break;
  189901. case S_OK:
  189902. result = "No error";
  189903. break;
  189904. default:
  189905. return "Unknown error: " + String ((int) hr);
  189906. }
  189907. return result;
  189908. }
  189909. #define DS_DEBUGGING 1
  189910. #ifdef DS_DEBUGGING
  189911. #define CATCH JUCE_CATCH_EXCEPTION
  189912. #undef log
  189913. #define log(a) Logger::writeToLog(a);
  189914. #undef logError
  189915. #define logError(a) logDSError(a, __LINE__);
  189916. static void logDSError (HRESULT hr, int lineNum)
  189917. {
  189918. if (hr != S_OK)
  189919. {
  189920. String error ("DS error at line ");
  189921. error << lineNum << T(" - ") << getDSErrorMessage (hr);
  189922. log (error);
  189923. }
  189924. }
  189925. #else
  189926. #define CATCH JUCE_CATCH_ALL
  189927. #define log(a)
  189928. #define logError(a)
  189929. #endif
  189930. #define DSOUND_FUNCTION(functionName, params) \
  189931. typedef HRESULT (WINAPI *type##functionName) params; \
  189932. static type##functionName ds##functionName = 0;
  189933. #define DSOUND_FUNCTION_LOAD(functionName) \
  189934. ds##functionName = (type##functionName) GetProcAddress (h, #functionName); \
  189935. jassert (ds##functionName != 0);
  189936. typedef BOOL (CALLBACK *LPDSENUMCALLBACKW) (LPGUID, LPCWSTR, LPCWSTR, LPVOID);
  189937. typedef BOOL (CALLBACK *LPDSENUMCALLBACKA) (LPGUID, LPCSTR, LPCSTR, LPVOID);
  189938. DSOUND_FUNCTION (DirectSoundCreate, (const GUID*, IDirectSound**, LPUNKNOWN))
  189939. DSOUND_FUNCTION (DirectSoundCaptureCreate, (const GUID*, IDirectSoundCapture**, LPUNKNOWN))
  189940. DSOUND_FUNCTION (DirectSoundEnumerateW, (LPDSENUMCALLBACKW, LPVOID))
  189941. DSOUND_FUNCTION (DirectSoundCaptureEnumerateW, (LPDSENUMCALLBACKW, LPVOID))
  189942. static void initialiseDSoundFunctions()
  189943. {
  189944. if (dsDirectSoundCreate == 0)
  189945. {
  189946. HMODULE h = LoadLibraryA ("dsound.dll");
  189947. DSOUND_FUNCTION_LOAD (DirectSoundCreate)
  189948. DSOUND_FUNCTION_LOAD (DirectSoundCaptureCreate)
  189949. DSOUND_FUNCTION_LOAD (DirectSoundEnumerateW)
  189950. DSOUND_FUNCTION_LOAD (DirectSoundCaptureEnumerateW)
  189951. }
  189952. }
  189953. class DSoundInternalOutChannel
  189954. {
  189955. String name;
  189956. LPGUID guid;
  189957. int sampleRate, bufferSizeSamples;
  189958. float* leftBuffer;
  189959. float* rightBuffer;
  189960. IDirectSound* pDirectSound;
  189961. IDirectSoundBuffer* pOutputBuffer;
  189962. DWORD writeOffset;
  189963. int totalBytesPerBuffer;
  189964. int bytesPerBuffer;
  189965. unsigned int lastPlayCursor;
  189966. public:
  189967. int bitDepth;
  189968. bool doneFlag;
  189969. DSoundInternalOutChannel (const String& name_,
  189970. LPGUID guid_,
  189971. int rate,
  189972. int bufferSize,
  189973. float* left,
  189974. float* right)
  189975. : name (name_),
  189976. guid (guid_),
  189977. sampleRate (rate),
  189978. bufferSizeSamples (bufferSize),
  189979. leftBuffer (left),
  189980. rightBuffer (right),
  189981. pDirectSound (0),
  189982. pOutputBuffer (0),
  189983. bitDepth (16)
  189984. {
  189985. }
  189986. ~DSoundInternalOutChannel()
  189987. {
  189988. close();
  189989. }
  189990. void close()
  189991. {
  189992. HRESULT hr;
  189993. if (pOutputBuffer != 0)
  189994. {
  189995. JUCE_TRY
  189996. {
  189997. log (T("closing dsound out: ") + name);
  189998. hr = pOutputBuffer->Stop();
  189999. logError (hr);
  190000. }
  190001. CATCH
  190002. JUCE_TRY
  190003. {
  190004. hr = pOutputBuffer->Release();
  190005. logError (hr);
  190006. }
  190007. CATCH
  190008. pOutputBuffer = 0;
  190009. }
  190010. if (pDirectSound != 0)
  190011. {
  190012. JUCE_TRY
  190013. {
  190014. hr = pDirectSound->Release();
  190015. logError (hr);
  190016. }
  190017. CATCH
  190018. pDirectSound = 0;
  190019. }
  190020. }
  190021. const String open()
  190022. {
  190023. log (T("opening dsound out device: ") + name
  190024. + T(" rate=") + String (sampleRate)
  190025. + T(" bits=") + String (bitDepth)
  190026. + T(" buf=") + String (bufferSizeSamples));
  190027. pDirectSound = 0;
  190028. pOutputBuffer = 0;
  190029. writeOffset = 0;
  190030. String error;
  190031. HRESULT hr = E_NOINTERFACE;
  190032. if (dsDirectSoundCreate != 0)
  190033. hr = dsDirectSoundCreate (guid, &pDirectSound, 0);
  190034. if (hr == S_OK)
  190035. {
  190036. bytesPerBuffer = (bufferSizeSamples * (bitDepth >> 2)) & ~15;
  190037. totalBytesPerBuffer = (3 * bytesPerBuffer) & ~15;
  190038. const int numChannels = 2;
  190039. hr = pDirectSound->SetCooperativeLevel (GetDesktopWindow(), 2 /* DSSCL_PRIORITY */);
  190040. logError (hr);
  190041. if (hr == S_OK)
  190042. {
  190043. IDirectSoundBuffer* pPrimaryBuffer;
  190044. DSBUFFERDESC primaryDesc;
  190045. zerostruct (primaryDesc);
  190046. primaryDesc.dwSize = sizeof (DSBUFFERDESC);
  190047. primaryDesc.dwFlags = 1 /* DSBCAPS_PRIMARYBUFFER */;
  190048. primaryDesc.dwBufferBytes = 0;
  190049. primaryDesc.lpwfxFormat = 0;
  190050. log ("opening dsound out step 2");
  190051. hr = pDirectSound->CreateSoundBuffer (&primaryDesc, &pPrimaryBuffer, 0);
  190052. logError (hr);
  190053. if (hr == S_OK)
  190054. {
  190055. WAVEFORMATEX wfFormat;
  190056. wfFormat.wFormatTag = WAVE_FORMAT_PCM;
  190057. wfFormat.nChannels = (unsigned short) numChannels;
  190058. wfFormat.nSamplesPerSec = sampleRate;
  190059. wfFormat.wBitsPerSample = (unsigned short) bitDepth;
  190060. wfFormat.nBlockAlign = (unsigned short) (wfFormat.nChannels * wfFormat.wBitsPerSample / 8);
  190061. wfFormat.nAvgBytesPerSec = wfFormat.nSamplesPerSec * wfFormat.nBlockAlign;
  190062. wfFormat.cbSize = 0;
  190063. hr = pPrimaryBuffer->SetFormat (&wfFormat);
  190064. logError (hr);
  190065. if (hr == S_OK)
  190066. {
  190067. DSBUFFERDESC secondaryDesc;
  190068. zerostruct (secondaryDesc);
  190069. secondaryDesc.dwSize = sizeof (DSBUFFERDESC);
  190070. secondaryDesc.dwFlags = 0x8000 /* DSBCAPS_GLOBALFOCUS */
  190071. | 0x10000 /* DSBCAPS_GETCURRENTPOSITION2 */;
  190072. secondaryDesc.dwBufferBytes = totalBytesPerBuffer;
  190073. secondaryDesc.lpwfxFormat = &wfFormat;
  190074. hr = pDirectSound->CreateSoundBuffer (&secondaryDesc, &pOutputBuffer, 0);
  190075. logError (hr);
  190076. if (hr == S_OK)
  190077. {
  190078. log ("opening dsound out step 3");
  190079. DWORD dwDataLen;
  190080. unsigned char* pDSBuffData;
  190081. hr = pOutputBuffer->Lock (0, totalBytesPerBuffer,
  190082. (LPVOID*) &pDSBuffData, &dwDataLen, 0, 0, 0);
  190083. logError (hr);
  190084. if (hr == S_OK)
  190085. {
  190086. zeromem (pDSBuffData, dwDataLen);
  190087. hr = pOutputBuffer->Unlock (pDSBuffData, dwDataLen, 0, 0);
  190088. if (hr == S_OK)
  190089. {
  190090. hr = pOutputBuffer->SetCurrentPosition (0);
  190091. if (hr == S_OK)
  190092. {
  190093. hr = pOutputBuffer->Play (0, 0, 1 /* DSBPLAY_LOOPING */);
  190094. if (hr == S_OK)
  190095. return String::empty;
  190096. }
  190097. }
  190098. }
  190099. }
  190100. }
  190101. }
  190102. }
  190103. }
  190104. error = getDSErrorMessage (hr);
  190105. close();
  190106. return error;
  190107. }
  190108. void synchronisePosition()
  190109. {
  190110. if (pOutputBuffer != 0)
  190111. {
  190112. DWORD playCursor;
  190113. pOutputBuffer->GetCurrentPosition (&playCursor, &writeOffset);
  190114. }
  190115. }
  190116. bool service()
  190117. {
  190118. if (pOutputBuffer == 0)
  190119. return true;
  190120. DWORD playCursor, writeCursor;
  190121. for (;;)
  190122. {
  190123. HRESULT hr = pOutputBuffer->GetCurrentPosition (&playCursor, &writeCursor);
  190124. if (hr == MAKE_HRESULT (1, 0x878, 150)) // DSERR_BUFFERLOST
  190125. {
  190126. pOutputBuffer->Restore();
  190127. continue;
  190128. }
  190129. if (hr == S_OK)
  190130. break;
  190131. logError (hr);
  190132. jassertfalse
  190133. return true;
  190134. }
  190135. int playWriteGap = writeCursor - playCursor;
  190136. if (playWriteGap < 0)
  190137. playWriteGap += totalBytesPerBuffer;
  190138. int bytesEmpty = playCursor - writeOffset;
  190139. if (bytesEmpty < 0)
  190140. bytesEmpty += totalBytesPerBuffer;
  190141. if (bytesEmpty > (totalBytesPerBuffer - playWriteGap))
  190142. {
  190143. writeOffset = writeCursor;
  190144. bytesEmpty = totalBytesPerBuffer - playWriteGap;
  190145. }
  190146. if (bytesEmpty >= bytesPerBuffer)
  190147. {
  190148. LPBYTE lpbuf1 = 0;
  190149. LPBYTE lpbuf2 = 0;
  190150. DWORD dwSize1 = 0;
  190151. DWORD dwSize2 = 0;
  190152. HRESULT hr = pOutputBuffer->Lock (writeOffset,
  190153. bytesPerBuffer,
  190154. (void**) &lpbuf1, &dwSize1,
  190155. (void**) &lpbuf2, &dwSize2, 0);
  190156. if (hr == MAKE_HRESULT (1, 0x878, 150)) // DSERR_BUFFERLOST
  190157. {
  190158. pOutputBuffer->Restore();
  190159. hr = pOutputBuffer->Lock (writeOffset,
  190160. bytesPerBuffer,
  190161. (void**) &lpbuf1, &dwSize1,
  190162. (void**) &lpbuf2, &dwSize2, 0);
  190163. }
  190164. if (hr == S_OK)
  190165. {
  190166. if (bitDepth == 16)
  190167. {
  190168. const float gainL = 32767.0f;
  190169. const float gainR = 32767.0f;
  190170. int* dest = (int*)lpbuf1;
  190171. const float* left = leftBuffer;
  190172. const float* right = rightBuffer;
  190173. int samples1 = dwSize1 >> 2;
  190174. int samples2 = dwSize2 >> 2;
  190175. if (left == 0)
  190176. {
  190177. while (--samples1 >= 0)
  190178. {
  190179. int r = roundToInt (gainR * *right++);
  190180. if (r < -32768)
  190181. r = -32768;
  190182. else if (r > 32767)
  190183. r = 32767;
  190184. *dest++ = (r << 16);
  190185. }
  190186. dest = (int*)lpbuf2;
  190187. while (--samples2 >= 0)
  190188. {
  190189. int r = roundToInt (gainR * *right++);
  190190. if (r < -32768)
  190191. r = -32768;
  190192. else if (r > 32767)
  190193. r = 32767;
  190194. *dest++ = (r << 16);
  190195. }
  190196. }
  190197. else if (right == 0)
  190198. {
  190199. while (--samples1 >= 0)
  190200. {
  190201. int l = roundToInt (gainL * *left++);
  190202. if (l < -32768)
  190203. l = -32768;
  190204. else if (l > 32767)
  190205. l = 32767;
  190206. l &= 0xffff;
  190207. *dest++ = l;
  190208. }
  190209. dest = (int*)lpbuf2;
  190210. while (--samples2 >= 0)
  190211. {
  190212. int l = roundToInt (gainL * *left++);
  190213. if (l < -32768)
  190214. l = -32768;
  190215. else if (l > 32767)
  190216. l = 32767;
  190217. l &= 0xffff;
  190218. *dest++ = l;
  190219. }
  190220. }
  190221. else
  190222. {
  190223. while (--samples1 >= 0)
  190224. {
  190225. int l = roundToInt (gainL * *left++);
  190226. if (l < -32768)
  190227. l = -32768;
  190228. else if (l > 32767)
  190229. l = 32767;
  190230. l &= 0xffff;
  190231. int r = roundToInt (gainR * *right++);
  190232. if (r < -32768)
  190233. r = -32768;
  190234. else if (r > 32767)
  190235. r = 32767;
  190236. *dest++ = (r << 16) | l;
  190237. }
  190238. dest = (int*)lpbuf2;
  190239. while (--samples2 >= 0)
  190240. {
  190241. int l = roundToInt (gainL * *left++);
  190242. if (l < -32768)
  190243. l = -32768;
  190244. else if (l > 32767)
  190245. l = 32767;
  190246. l &= 0xffff;
  190247. int r = roundToInt (gainR * *right++);
  190248. if (r < -32768)
  190249. r = -32768;
  190250. else if (r > 32767)
  190251. r = 32767;
  190252. *dest++ = (r << 16) | l;
  190253. }
  190254. }
  190255. }
  190256. else
  190257. {
  190258. jassertfalse
  190259. }
  190260. writeOffset = (writeOffset + dwSize1 + dwSize2) % totalBytesPerBuffer;
  190261. pOutputBuffer->Unlock (lpbuf1, dwSize1, lpbuf2, dwSize2);
  190262. }
  190263. else
  190264. {
  190265. jassertfalse
  190266. logError (hr);
  190267. }
  190268. bytesEmpty -= bytesPerBuffer;
  190269. return true;
  190270. }
  190271. else
  190272. {
  190273. return false;
  190274. }
  190275. }
  190276. };
  190277. struct DSoundInternalInChannel
  190278. {
  190279. String name;
  190280. LPGUID guid;
  190281. int sampleRate, bufferSizeSamples;
  190282. float* leftBuffer;
  190283. float* rightBuffer;
  190284. IDirectSound* pDirectSound;
  190285. IDirectSoundCapture* pDirectSoundCapture;
  190286. IDirectSoundCaptureBuffer* pInputBuffer;
  190287. public:
  190288. unsigned int readOffset;
  190289. int bytesPerBuffer, totalBytesPerBuffer;
  190290. int bitDepth;
  190291. bool doneFlag;
  190292. DSoundInternalInChannel (const String& name_,
  190293. LPGUID guid_,
  190294. int rate,
  190295. int bufferSize,
  190296. float* left,
  190297. float* right)
  190298. : name (name_),
  190299. guid (guid_),
  190300. sampleRate (rate),
  190301. bufferSizeSamples (bufferSize),
  190302. leftBuffer (left),
  190303. rightBuffer (right),
  190304. pDirectSound (0),
  190305. pDirectSoundCapture (0),
  190306. pInputBuffer (0),
  190307. bitDepth (16)
  190308. {
  190309. }
  190310. ~DSoundInternalInChannel()
  190311. {
  190312. close();
  190313. }
  190314. void close()
  190315. {
  190316. HRESULT hr;
  190317. if (pInputBuffer != 0)
  190318. {
  190319. JUCE_TRY
  190320. {
  190321. log (T("closing dsound in: ") + name);
  190322. hr = pInputBuffer->Stop();
  190323. logError (hr);
  190324. }
  190325. CATCH
  190326. JUCE_TRY
  190327. {
  190328. hr = pInputBuffer->Release();
  190329. logError (hr);
  190330. }
  190331. CATCH
  190332. pInputBuffer = 0;
  190333. }
  190334. if (pDirectSoundCapture != 0)
  190335. {
  190336. JUCE_TRY
  190337. {
  190338. hr = pDirectSoundCapture->Release();
  190339. logError (hr);
  190340. }
  190341. CATCH
  190342. pDirectSoundCapture = 0;
  190343. }
  190344. if (pDirectSound != 0)
  190345. {
  190346. JUCE_TRY
  190347. {
  190348. hr = pDirectSound->Release();
  190349. logError (hr);
  190350. }
  190351. CATCH
  190352. pDirectSound = 0;
  190353. }
  190354. }
  190355. const String open()
  190356. {
  190357. log (T("opening dsound in device: ") + name
  190358. + T(" rate=") + String (sampleRate) + T(" bits=") + String (bitDepth) + T(" buf=") + String (bufferSizeSamples));
  190359. pDirectSound = 0;
  190360. pDirectSoundCapture = 0;
  190361. pInputBuffer = 0;
  190362. readOffset = 0;
  190363. totalBytesPerBuffer = 0;
  190364. String error;
  190365. HRESULT hr = E_NOINTERFACE;
  190366. if (dsDirectSoundCaptureCreate != 0)
  190367. hr = dsDirectSoundCaptureCreate (guid, &pDirectSoundCapture, 0);
  190368. logError (hr);
  190369. if (hr == S_OK)
  190370. {
  190371. const int numChannels = 2;
  190372. bytesPerBuffer = (bufferSizeSamples * (bitDepth >> 2)) & ~15;
  190373. totalBytesPerBuffer = (3 * bytesPerBuffer) & ~15;
  190374. WAVEFORMATEX wfFormat;
  190375. wfFormat.wFormatTag = WAVE_FORMAT_PCM;
  190376. wfFormat.nChannels = (unsigned short)numChannels;
  190377. wfFormat.nSamplesPerSec = sampleRate;
  190378. wfFormat.wBitsPerSample = (unsigned short)bitDepth;
  190379. wfFormat.nBlockAlign = (unsigned short)(wfFormat.nChannels * (wfFormat.wBitsPerSample / 8));
  190380. wfFormat.nAvgBytesPerSec = wfFormat.nSamplesPerSec * wfFormat.nBlockAlign;
  190381. wfFormat.cbSize = 0;
  190382. DSCBUFFERDESC captureDesc;
  190383. zerostruct (captureDesc);
  190384. captureDesc.dwSize = sizeof (DSCBUFFERDESC);
  190385. captureDesc.dwFlags = 0;
  190386. captureDesc.dwBufferBytes = totalBytesPerBuffer;
  190387. captureDesc.lpwfxFormat = &wfFormat;
  190388. log (T("opening dsound in step 2"));
  190389. hr = pDirectSoundCapture->CreateCaptureBuffer (&captureDesc, &pInputBuffer, 0);
  190390. logError (hr);
  190391. if (hr == S_OK)
  190392. {
  190393. hr = pInputBuffer->Start (1 /* DSCBSTART_LOOPING */);
  190394. logError (hr);
  190395. if (hr == S_OK)
  190396. return String::empty;
  190397. }
  190398. }
  190399. error = getDSErrorMessage (hr);
  190400. close();
  190401. return error;
  190402. }
  190403. void synchronisePosition()
  190404. {
  190405. if (pInputBuffer != 0)
  190406. {
  190407. DWORD capturePos;
  190408. pInputBuffer->GetCurrentPosition (&capturePos, (DWORD*)&readOffset);
  190409. }
  190410. }
  190411. bool service()
  190412. {
  190413. if (pInputBuffer == 0)
  190414. return true;
  190415. DWORD capturePos, readPos;
  190416. HRESULT hr = pInputBuffer->GetCurrentPosition (&capturePos, &readPos);
  190417. logError (hr);
  190418. if (hr != S_OK)
  190419. return true;
  190420. int bytesFilled = readPos - readOffset;
  190421. if (bytesFilled < 0)
  190422. bytesFilled += totalBytesPerBuffer;
  190423. if (bytesFilled >= bytesPerBuffer)
  190424. {
  190425. LPBYTE lpbuf1 = 0;
  190426. LPBYTE lpbuf2 = 0;
  190427. DWORD dwsize1 = 0;
  190428. DWORD dwsize2 = 0;
  190429. HRESULT hr = pInputBuffer->Lock (readOffset,
  190430. bytesPerBuffer,
  190431. (void**) &lpbuf1, &dwsize1,
  190432. (void**) &lpbuf2, &dwsize2, 0);
  190433. if (hr == S_OK)
  190434. {
  190435. if (bitDepth == 16)
  190436. {
  190437. const float g = 1.0f / 32768.0f;
  190438. float* destL = leftBuffer;
  190439. float* destR = rightBuffer;
  190440. int samples1 = dwsize1 >> 2;
  190441. int samples2 = dwsize2 >> 2;
  190442. const short* src = (const short*)lpbuf1;
  190443. if (destL == 0)
  190444. {
  190445. while (--samples1 >= 0)
  190446. {
  190447. ++src;
  190448. *destR++ = *src++ * g;
  190449. }
  190450. src = (const short*)lpbuf2;
  190451. while (--samples2 >= 0)
  190452. {
  190453. ++src;
  190454. *destR++ = *src++ * g;
  190455. }
  190456. }
  190457. else if (destR == 0)
  190458. {
  190459. while (--samples1 >= 0)
  190460. {
  190461. *destL++ = *src++ * g;
  190462. ++src;
  190463. }
  190464. src = (const short*)lpbuf2;
  190465. while (--samples2 >= 0)
  190466. {
  190467. *destL++ = *src++ * g;
  190468. ++src;
  190469. }
  190470. }
  190471. else
  190472. {
  190473. while (--samples1 >= 0)
  190474. {
  190475. *destL++ = *src++ * g;
  190476. *destR++ = *src++ * g;
  190477. }
  190478. src = (const short*)lpbuf2;
  190479. while (--samples2 >= 0)
  190480. {
  190481. *destL++ = *src++ * g;
  190482. *destR++ = *src++ * g;
  190483. }
  190484. }
  190485. }
  190486. else
  190487. {
  190488. jassertfalse
  190489. }
  190490. readOffset = (readOffset + dwsize1 + dwsize2) % totalBytesPerBuffer;
  190491. pInputBuffer->Unlock (lpbuf1, dwsize1, lpbuf2, dwsize2);
  190492. }
  190493. else
  190494. {
  190495. logError (hr);
  190496. jassertfalse
  190497. }
  190498. bytesFilled -= bytesPerBuffer;
  190499. return true;
  190500. }
  190501. else
  190502. {
  190503. return false;
  190504. }
  190505. }
  190506. };
  190507. class DSoundAudioIODevice : public AudioIODevice,
  190508. public Thread
  190509. {
  190510. public:
  190511. DSoundAudioIODevice (const String& deviceName,
  190512. const int outputDeviceIndex_,
  190513. const int inputDeviceIndex_)
  190514. : AudioIODevice (deviceName, "DirectSound"),
  190515. Thread ("Juce DSound"),
  190516. isOpen_ (false),
  190517. isStarted (false),
  190518. outputDeviceIndex (outputDeviceIndex_),
  190519. inputDeviceIndex (inputDeviceIndex_),
  190520. numInputBuffers (0),
  190521. numOutputBuffers (0),
  190522. totalSamplesOut (0),
  190523. sampleRate (0.0),
  190524. inputBuffers (0),
  190525. outputBuffers (0),
  190526. callback (0),
  190527. bufferSizeSamples (0)
  190528. {
  190529. if (outputDeviceIndex_ >= 0)
  190530. {
  190531. outChannels.add (TRANS("Left"));
  190532. outChannels.add (TRANS("Right"));
  190533. }
  190534. if (inputDeviceIndex_ >= 0)
  190535. {
  190536. inChannels.add (TRANS("Left"));
  190537. inChannels.add (TRANS("Right"));
  190538. }
  190539. }
  190540. ~DSoundAudioIODevice()
  190541. {
  190542. close();
  190543. }
  190544. const StringArray getOutputChannelNames()
  190545. {
  190546. return outChannels;
  190547. }
  190548. const StringArray getInputChannelNames()
  190549. {
  190550. return inChannels;
  190551. }
  190552. int getNumSampleRates()
  190553. {
  190554. return 4;
  190555. }
  190556. double getSampleRate (int index)
  190557. {
  190558. const double samps[] = { 44100.0, 48000.0, 88200.0, 96000.0 };
  190559. return samps [jlimit (0, 3, index)];
  190560. }
  190561. int getNumBufferSizesAvailable()
  190562. {
  190563. return 50;
  190564. }
  190565. int getBufferSizeSamples (int index)
  190566. {
  190567. int n = 64;
  190568. for (int i = 0; i < index; ++i)
  190569. n += (n < 512) ? 32
  190570. : ((n < 1024) ? 64
  190571. : ((n < 2048) ? 128 : 256));
  190572. return n;
  190573. }
  190574. int getDefaultBufferSize()
  190575. {
  190576. return 2560;
  190577. }
  190578. const String open (const BitArray& inputChannels,
  190579. const BitArray& outputChannels,
  190580. double sampleRate,
  190581. int bufferSizeSamples)
  190582. {
  190583. lastError = openDevice (inputChannels, outputChannels, sampleRate, bufferSizeSamples);
  190584. isOpen_ = lastError.isEmpty();
  190585. return lastError;
  190586. }
  190587. void close()
  190588. {
  190589. stop();
  190590. if (isOpen_)
  190591. {
  190592. closeDevice();
  190593. isOpen_ = false;
  190594. }
  190595. }
  190596. bool isOpen()
  190597. {
  190598. return isOpen_ && isThreadRunning();
  190599. }
  190600. int getCurrentBufferSizeSamples()
  190601. {
  190602. return bufferSizeSamples;
  190603. }
  190604. double getCurrentSampleRate()
  190605. {
  190606. return sampleRate;
  190607. }
  190608. int getCurrentBitDepth()
  190609. {
  190610. int i, bits = 256;
  190611. for (i = inChans.size(); --i >= 0;)
  190612. bits = jmin (bits, inChans[i]->bitDepth);
  190613. for (i = outChans.size(); --i >= 0;)
  190614. bits = jmin (bits, outChans[i]->bitDepth);
  190615. if (bits > 32)
  190616. bits = 16;
  190617. return bits;
  190618. }
  190619. const BitArray getActiveOutputChannels() const
  190620. {
  190621. return enabledOutputs;
  190622. }
  190623. const BitArray getActiveInputChannels() const
  190624. {
  190625. return enabledInputs;
  190626. }
  190627. int getOutputLatencyInSamples()
  190628. {
  190629. return (int) (getCurrentBufferSizeSamples() * 1.5);
  190630. }
  190631. int getInputLatencyInSamples()
  190632. {
  190633. return getOutputLatencyInSamples();
  190634. }
  190635. void start (AudioIODeviceCallback* call)
  190636. {
  190637. if (isOpen_ && call != 0 && ! isStarted)
  190638. {
  190639. if (! isThreadRunning())
  190640. {
  190641. // something gone wrong and the thread's stopped..
  190642. isOpen_ = false;
  190643. return;
  190644. }
  190645. call->audioDeviceAboutToStart (this);
  190646. const ScopedLock sl (startStopLock);
  190647. callback = call;
  190648. isStarted = true;
  190649. }
  190650. }
  190651. void stop()
  190652. {
  190653. if (isStarted)
  190654. {
  190655. AudioIODeviceCallback* const callbackLocal = callback;
  190656. {
  190657. const ScopedLock sl (startStopLock);
  190658. isStarted = false;
  190659. }
  190660. if (callbackLocal != 0)
  190661. callbackLocal->audioDeviceStopped();
  190662. }
  190663. }
  190664. bool isPlaying()
  190665. {
  190666. return isStarted && isOpen_ && isThreadRunning();
  190667. }
  190668. const String getLastError()
  190669. {
  190670. return lastError;
  190671. }
  190672. juce_UseDebuggingNewOperator
  190673. StringArray inChannels, outChannels;
  190674. int outputDeviceIndex, inputDeviceIndex;
  190675. private:
  190676. bool isOpen_;
  190677. bool isStarted;
  190678. String lastError;
  190679. OwnedArray <DSoundInternalInChannel> inChans;
  190680. OwnedArray <DSoundInternalOutChannel> outChans;
  190681. WaitableEvent startEvent;
  190682. int numInputBuffers, numOutputBuffers, bufferSizeSamples;
  190683. int volatile totalSamplesOut;
  190684. int64 volatile lastBlockTime;
  190685. double sampleRate;
  190686. BitArray enabledInputs, enabledOutputs;
  190687. HeapBlock <float*> inputBuffers, outputBuffers;
  190688. AudioIODeviceCallback* callback;
  190689. CriticalSection startStopLock;
  190690. DSoundAudioIODevice (const DSoundAudioIODevice&);
  190691. DSoundAudioIODevice& operator= (const DSoundAudioIODevice&);
  190692. const String openDevice (const BitArray& inputChannels,
  190693. const BitArray& outputChannels,
  190694. double sampleRate_,
  190695. int bufferSizeSamples_);
  190696. void closeDevice()
  190697. {
  190698. isStarted = false;
  190699. stopThread (5000);
  190700. inChans.clear();
  190701. outChans.clear();
  190702. int i;
  190703. for (i = 0; i < numInputBuffers; ++i)
  190704. juce_free (inputBuffers[i]);
  190705. inputBuffers.free();
  190706. numInputBuffers = 0;
  190707. for (i = 0; i < numOutputBuffers; ++i)
  190708. juce_free (outputBuffers[i]);
  190709. outputBuffers.free();
  190710. numOutputBuffers = 0;
  190711. }
  190712. void resync()
  190713. {
  190714. if (! threadShouldExit())
  190715. {
  190716. sleep (5);
  190717. int i;
  190718. for (i = 0; i < outChans.size(); ++i)
  190719. outChans.getUnchecked(i)->synchronisePosition();
  190720. for (i = 0; i < inChans.size(); ++i)
  190721. inChans.getUnchecked(i)->synchronisePosition();
  190722. }
  190723. }
  190724. public:
  190725. void run()
  190726. {
  190727. while (! threadShouldExit())
  190728. {
  190729. if (wait (100))
  190730. break;
  190731. }
  190732. const int latencyMs = (int) (bufferSizeSamples * 1000.0 / sampleRate);
  190733. const int maxTimeMS = jmax (5, 3 * latencyMs);
  190734. while (! threadShouldExit())
  190735. {
  190736. int numToDo = 0;
  190737. uint32 startTime = Time::getMillisecondCounter();
  190738. int i;
  190739. for (i = inChans.size(); --i >= 0;)
  190740. {
  190741. inChans.getUnchecked(i)->doneFlag = false;
  190742. ++numToDo;
  190743. }
  190744. for (i = outChans.size(); --i >= 0;)
  190745. {
  190746. outChans.getUnchecked(i)->doneFlag = false;
  190747. ++numToDo;
  190748. }
  190749. if (numToDo > 0)
  190750. {
  190751. const int maxCount = 3;
  190752. int count = maxCount;
  190753. for (;;)
  190754. {
  190755. for (i = inChans.size(); --i >= 0;)
  190756. {
  190757. DSoundInternalInChannel* const in = inChans.getUnchecked(i);
  190758. if ((! in->doneFlag) && in->service())
  190759. {
  190760. in->doneFlag = true;
  190761. --numToDo;
  190762. }
  190763. }
  190764. for (i = outChans.size(); --i >= 0;)
  190765. {
  190766. DSoundInternalOutChannel* const out = outChans.getUnchecked(i);
  190767. if ((! out->doneFlag) && out->service())
  190768. {
  190769. out->doneFlag = true;
  190770. --numToDo;
  190771. }
  190772. }
  190773. if (numToDo <= 0)
  190774. break;
  190775. if (Time::getMillisecondCounter() > startTime + maxTimeMS)
  190776. {
  190777. resync();
  190778. break;
  190779. }
  190780. if (--count <= 0)
  190781. {
  190782. Sleep (1);
  190783. count = maxCount;
  190784. }
  190785. if (threadShouldExit())
  190786. return;
  190787. }
  190788. }
  190789. else
  190790. {
  190791. sleep (1);
  190792. }
  190793. const ScopedLock sl (startStopLock);
  190794. if (isStarted)
  190795. {
  190796. JUCE_TRY
  190797. {
  190798. callback->audioDeviceIOCallback (const_cast <const float**> (inputBuffers.getData()),
  190799. numInputBuffers,
  190800. outputBuffers,
  190801. numOutputBuffers,
  190802. bufferSizeSamples);
  190803. }
  190804. JUCE_CATCH_EXCEPTION
  190805. totalSamplesOut += bufferSizeSamples;
  190806. }
  190807. else
  190808. {
  190809. for (i = 0; i < numOutputBuffers; ++i)
  190810. if (outputBuffers[i] != 0)
  190811. zeromem (outputBuffers[i], bufferSizeSamples * sizeof (float));
  190812. totalSamplesOut = 0;
  190813. sleep (1);
  190814. }
  190815. }
  190816. }
  190817. };
  190818. class DSoundAudioIODeviceType : public AudioIODeviceType
  190819. {
  190820. public:
  190821. DSoundAudioIODeviceType()
  190822. : AudioIODeviceType (T("DirectSound")),
  190823. hasScanned (false)
  190824. {
  190825. initialiseDSoundFunctions();
  190826. }
  190827. ~DSoundAudioIODeviceType()
  190828. {
  190829. }
  190830. void scanForDevices()
  190831. {
  190832. hasScanned = true;
  190833. outputDeviceNames.clear();
  190834. outputGuids.clear();
  190835. inputDeviceNames.clear();
  190836. inputGuids.clear();
  190837. if (dsDirectSoundEnumerateW != 0)
  190838. {
  190839. dsDirectSoundEnumerateW (outputEnumProcW, this);
  190840. dsDirectSoundCaptureEnumerateW (inputEnumProcW, this);
  190841. }
  190842. }
  190843. const StringArray getDeviceNames (const bool wantInputNames) const
  190844. {
  190845. jassert (hasScanned); // need to call scanForDevices() before doing this
  190846. return wantInputNames ? inputDeviceNames
  190847. : outputDeviceNames;
  190848. }
  190849. int getDefaultDeviceIndex (const bool /*forInput*/) const
  190850. {
  190851. jassert (hasScanned); // need to call scanForDevices() before doing this
  190852. return 0;
  190853. }
  190854. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  190855. {
  190856. jassert (hasScanned); // need to call scanForDevices() before doing this
  190857. DSoundAudioIODevice* const d = dynamic_cast <DSoundAudioIODevice*> (device);
  190858. if (d == 0)
  190859. return -1;
  190860. return asInput ? d->inputDeviceIndex
  190861. : d->outputDeviceIndex;
  190862. }
  190863. bool hasSeparateInputsAndOutputs() const { return true; }
  190864. AudioIODevice* createDevice (const String& outputDeviceName,
  190865. const String& inputDeviceName)
  190866. {
  190867. jassert (hasScanned); // need to call scanForDevices() before doing this
  190868. const int outputIndex = outputDeviceNames.indexOf (outputDeviceName);
  190869. const int inputIndex = inputDeviceNames.indexOf (inputDeviceName);
  190870. if (outputIndex >= 0 || inputIndex >= 0)
  190871. return new DSoundAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
  190872. : inputDeviceName,
  190873. outputIndex, inputIndex);
  190874. return 0;
  190875. }
  190876. juce_UseDebuggingNewOperator
  190877. StringArray outputDeviceNames;
  190878. OwnedArray <GUID> outputGuids;
  190879. StringArray inputDeviceNames;
  190880. OwnedArray <GUID> inputGuids;
  190881. private:
  190882. bool hasScanned;
  190883. BOOL outputEnumProc (LPGUID lpGUID, String desc)
  190884. {
  190885. desc = desc.trim();
  190886. if (desc.isNotEmpty())
  190887. {
  190888. const String origDesc (desc);
  190889. int n = 2;
  190890. while (outputDeviceNames.contains (desc))
  190891. desc = origDesc + T(" (") + String (n++) + T(")");
  190892. outputDeviceNames.add (desc);
  190893. if (lpGUID != 0)
  190894. outputGuids.add (new GUID (*lpGUID));
  190895. else
  190896. outputGuids.add (0);
  190897. }
  190898. return TRUE;
  190899. }
  190900. static BOOL CALLBACK outputEnumProcW (LPGUID lpGUID, LPCWSTR description, LPCWSTR, LPVOID object)
  190901. {
  190902. return ((DSoundAudioIODeviceType*) object)
  190903. ->outputEnumProc (lpGUID, String (description));
  190904. }
  190905. static BOOL CALLBACK outputEnumProcA (LPGUID lpGUID, LPCTSTR description, LPCTSTR, LPVOID object)
  190906. {
  190907. return ((DSoundAudioIODeviceType*) object)
  190908. ->outputEnumProc (lpGUID, String (description));
  190909. }
  190910. BOOL CALLBACK inputEnumProc (LPGUID lpGUID, String desc)
  190911. {
  190912. desc = desc.trim();
  190913. if (desc.isNotEmpty())
  190914. {
  190915. const String origDesc (desc);
  190916. int n = 2;
  190917. while (inputDeviceNames.contains (desc))
  190918. desc = origDesc + T(" (") + String (n++) + T(")");
  190919. inputDeviceNames.add (desc);
  190920. if (lpGUID != 0)
  190921. inputGuids.add (new GUID (*lpGUID));
  190922. else
  190923. inputGuids.add (0);
  190924. }
  190925. return TRUE;
  190926. }
  190927. static BOOL CALLBACK inputEnumProcW (LPGUID lpGUID, LPCWSTR description, LPCWSTR, LPVOID object)
  190928. {
  190929. return ((DSoundAudioIODeviceType*) object)
  190930. ->inputEnumProc (lpGUID, String (description));
  190931. }
  190932. static BOOL CALLBACK inputEnumProcA (LPGUID lpGUID, LPCTSTR description, LPCTSTR, LPVOID object)
  190933. {
  190934. return ((DSoundAudioIODeviceType*) object)
  190935. ->inputEnumProc (lpGUID, String (description));
  190936. }
  190937. DSoundAudioIODeviceType (const DSoundAudioIODeviceType&);
  190938. DSoundAudioIODeviceType& operator= (const DSoundAudioIODeviceType&);
  190939. };
  190940. const String DSoundAudioIODevice::openDevice (const BitArray& inputChannels,
  190941. const BitArray& outputChannels,
  190942. double sampleRate_,
  190943. int bufferSizeSamples_)
  190944. {
  190945. closeDevice();
  190946. totalSamplesOut = 0;
  190947. sampleRate = sampleRate_;
  190948. if (bufferSizeSamples_ <= 0)
  190949. bufferSizeSamples_ = 960; // use as a default size if none is set.
  190950. bufferSizeSamples = bufferSizeSamples_ & ~7;
  190951. DSoundAudioIODeviceType dlh;
  190952. dlh.scanForDevices();
  190953. enabledInputs = inputChannels;
  190954. enabledInputs.setRange (inChannels.size(),
  190955. enabledInputs.getHighestBit() + 1 - inChannels.size(),
  190956. false);
  190957. numInputBuffers = enabledInputs.countNumberOfSetBits();
  190958. inputBuffers.calloc (numInputBuffers + 2);
  190959. int i, numIns = 0;
  190960. for (i = 0; i <= enabledInputs.getHighestBit(); i += 2)
  190961. {
  190962. float* left = 0;
  190963. float* right = 0;
  190964. if (enabledInputs[i])
  190965. left = inputBuffers[numIns++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  190966. if (enabledInputs[i + 1])
  190967. right = inputBuffers[numIns++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  190968. if (left != 0 || right != 0)
  190969. inChans.add (new DSoundInternalInChannel (dlh.inputDeviceNames [inputDeviceIndex],
  190970. dlh.inputGuids [inputDeviceIndex],
  190971. (int) sampleRate, bufferSizeSamples,
  190972. left, right));
  190973. }
  190974. enabledOutputs = outputChannels;
  190975. enabledOutputs.setRange (outChannels.size(),
  190976. enabledOutputs.getHighestBit() + 1 - outChannels.size(),
  190977. false);
  190978. numOutputBuffers = enabledOutputs.countNumberOfSetBits();
  190979. outputBuffers.calloc (numOutputBuffers + 2);
  190980. int numOuts = 0;
  190981. for (i = 0; i <= enabledOutputs.getHighestBit(); i += 2)
  190982. {
  190983. float* left = 0;
  190984. float* right = 0;
  190985. if (enabledOutputs[i])
  190986. left = outputBuffers[numOuts++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  190987. if (enabledOutputs[i + 1])
  190988. right = outputBuffers[numOuts++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  190989. if (left != 0 || right != 0)
  190990. outChans.add (new DSoundInternalOutChannel (dlh.outputDeviceNames[outputDeviceIndex],
  190991. dlh.outputGuids [outputDeviceIndex],
  190992. (int) sampleRate, bufferSizeSamples,
  190993. left, right));
  190994. }
  190995. String error;
  190996. // boost our priority while opening the devices to try to get better sync between them
  190997. const int oldThreadPri = GetThreadPriority (GetCurrentThread());
  190998. const int oldProcPri = GetPriorityClass (GetCurrentProcess());
  190999. SetThreadPriority (GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
  191000. SetPriorityClass (GetCurrentProcess(), REALTIME_PRIORITY_CLASS);
  191001. for (i = 0; i < outChans.size(); ++i)
  191002. {
  191003. error = outChans[i]->open();
  191004. if (error.isNotEmpty())
  191005. {
  191006. error = T("Error opening ") + dlh.outputDeviceNames[i]
  191007. + T(": \"") + error + T("\"");
  191008. break;
  191009. }
  191010. }
  191011. if (error.isEmpty())
  191012. {
  191013. for (i = 0; i < inChans.size(); ++i)
  191014. {
  191015. error = inChans[i]->open();
  191016. if (error.isNotEmpty())
  191017. {
  191018. error = T("Error opening ") + dlh.inputDeviceNames[i]
  191019. + T(": \"") + error + T("\"");
  191020. break;
  191021. }
  191022. }
  191023. }
  191024. if (error.isEmpty())
  191025. {
  191026. totalSamplesOut = 0;
  191027. for (i = 0; i < outChans.size(); ++i)
  191028. outChans.getUnchecked(i)->synchronisePosition();
  191029. for (i = 0; i < inChans.size(); ++i)
  191030. inChans.getUnchecked(i)->synchronisePosition();
  191031. startThread (9);
  191032. sleep (10);
  191033. notify();
  191034. }
  191035. else
  191036. {
  191037. log (error);
  191038. }
  191039. SetThreadPriority (GetCurrentThread(), oldThreadPri);
  191040. SetPriorityClass (GetCurrentProcess(), oldProcPri);
  191041. return error;
  191042. }
  191043. AudioIODeviceType* juce_createAudioIODeviceType_DirectSound()
  191044. {
  191045. return new DSoundAudioIODeviceType();
  191046. }
  191047. #undef log
  191048. #endif
  191049. /*** End of inlined file: juce_win32_DirectSound.cpp ***/
  191050. /*** Start of inlined file: juce_win32_WASAPI.cpp ***/
  191051. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  191052. // compiled on its own).
  191053. #if JUCE_INCLUDED_FILE && JUCE_WASAPI
  191054. #if 1
  191055. const String getAudioErrorDesc (HRESULT hr)
  191056. {
  191057. const char* e = 0;
  191058. switch (hr)
  191059. {
  191060. case E_POINTER: e = "E_POINTER"; break;
  191061. case E_INVALIDARG: e = "E_INVALIDARG"; break;
  191062. case AUDCLNT_E_NOT_INITIALIZED: e = "AUDCLNT_E_NOT_INITIALIZED"; break;
  191063. case AUDCLNT_E_ALREADY_INITIALIZED: e = "AUDCLNT_E_ALREADY_INITIALIZED"; break;
  191064. case AUDCLNT_E_WRONG_ENDPOINT_TYPE: e = "AUDCLNT_E_WRONG_ENDPOINT_TYPE"; break;
  191065. case AUDCLNT_E_DEVICE_INVALIDATED: e = "AUDCLNT_E_DEVICE_INVALIDATED"; break;
  191066. case AUDCLNT_E_NOT_STOPPED: e = "AUDCLNT_E_NOT_STOPPED"; break;
  191067. case AUDCLNT_E_BUFFER_TOO_LARGE: e = "AUDCLNT_E_BUFFER_TOO_LARGE"; break;
  191068. case AUDCLNT_E_OUT_OF_ORDER: e = "AUDCLNT_E_OUT_OF_ORDER"; break;
  191069. case AUDCLNT_E_UNSUPPORTED_FORMAT: e = "AUDCLNT_E_UNSUPPORTED_FORMAT"; break;
  191070. case AUDCLNT_E_INVALID_SIZE: e = "AUDCLNT_E_INVALID_SIZE"; break;
  191071. case AUDCLNT_E_DEVICE_IN_USE: e = "AUDCLNT_E_DEVICE_IN_USE"; break;
  191072. case AUDCLNT_E_BUFFER_OPERATION_PENDING: e = "AUDCLNT_E_BUFFER_OPERATION_PENDING"; break;
  191073. case AUDCLNT_E_THREAD_NOT_REGISTERED: e = "AUDCLNT_E_THREAD_NOT_REGISTERED"; break;
  191074. case AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED: e = "AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED"; break;
  191075. case AUDCLNT_E_ENDPOINT_CREATE_FAILED: e = "AUDCLNT_E_ENDPOINT_CREATE_FAILED"; break;
  191076. case AUDCLNT_E_SERVICE_NOT_RUNNING: e = "AUDCLNT_E_SERVICE_NOT_RUNNING"; break;
  191077. case AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED: e = "AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED"; break;
  191078. case AUDCLNT_E_EXCLUSIVE_MODE_ONLY: e = "AUDCLNT_E_EXCLUSIVE_MODE_ONLY"; break;
  191079. case AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL: e = "AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL"; break;
  191080. case AUDCLNT_E_EVENTHANDLE_NOT_SET: e = "AUDCLNT_E_EVENTHANDLE_NOT_SET"; break;
  191081. case AUDCLNT_E_INCORRECT_BUFFER_SIZE: e = "AUDCLNT_E_INCORRECT_BUFFER_SIZE"; break;
  191082. case AUDCLNT_E_BUFFER_SIZE_ERROR: e = "AUDCLNT_E_BUFFER_SIZE_ERROR"; break;
  191083. case AUDCLNT_S_BUFFER_EMPTY: e = "AUDCLNT_S_BUFFER_EMPTY"; break;
  191084. case AUDCLNT_S_THREAD_ALREADY_REGISTERED: e = "AUDCLNT_S_THREAD_ALREADY_REGISTERED"; break;
  191085. default: return String::toHexString ((int) hr);
  191086. }
  191087. return e;
  191088. }
  191089. #define logFailure(hr) { if (FAILED (hr)) { DBG ("WASAPI FAIL! " + getAudioErrorDesc (hr)); jassertfalse } }
  191090. #define OK(a) wasapi_checkResult(a)
  191091. static bool wasapi_checkResult (HRESULT hr)
  191092. {
  191093. logFailure (hr);
  191094. return SUCCEEDED (hr);
  191095. }
  191096. #else
  191097. #define logFailure(hr) {}
  191098. #define OK(a) SUCCEEDED(a)
  191099. #endif
  191100. static const String wasapi_getDeviceID (IMMDevice* const device)
  191101. {
  191102. String s;
  191103. WCHAR* deviceId = 0;
  191104. if (OK (device->GetId (&deviceId)))
  191105. {
  191106. s = String (deviceId);
  191107. CoTaskMemFree (deviceId);
  191108. }
  191109. return s;
  191110. }
  191111. static EDataFlow wasapi_getDataFlow (IMMDevice* const device)
  191112. {
  191113. EDataFlow flow = eRender;
  191114. ComSmartPtr <IMMEndpoint> endPoint;
  191115. if (OK (device->QueryInterface (__uuidof (IMMEndpoint), (void**) &endPoint)))
  191116. (void) OK (endPoint->GetDataFlow (&flow));
  191117. return flow;
  191118. }
  191119. static int wasapi_refTimeToSamples (const REFERENCE_TIME& t, const double sampleRate) throw()
  191120. {
  191121. return roundDoubleToInt (sampleRate * ((double) t) * 0.0000001);
  191122. }
  191123. static void wasapi_copyWavFormat (WAVEFORMATEXTENSIBLE& dest, const WAVEFORMATEX* const src) throw()
  191124. {
  191125. memcpy (&dest, src, src->wFormatTag == WAVE_FORMAT_EXTENSIBLE ? sizeof (WAVEFORMATEXTENSIBLE)
  191126. : sizeof (WAVEFORMATEX));
  191127. }
  191128. class WASAPIDeviceBase
  191129. {
  191130. public:
  191131. WASAPIDeviceBase (const ComSmartPtr <IMMDevice>& device_, const bool useExclusiveMode_)
  191132. : device (device_),
  191133. sampleRate (0),
  191134. numChannels (0),
  191135. actualNumChannels (0),
  191136. defaultSampleRate (0),
  191137. minBufferSize (0),
  191138. defaultBufferSize (0),
  191139. latencySamples (0),
  191140. useExclusiveMode (useExclusiveMode_)
  191141. {
  191142. clientEvent = CreateEvent (0, false, false, _T("JuceWASAPI"));
  191143. ComSmartPtr <IAudioClient> tempClient (createClient());
  191144. if (tempClient == 0)
  191145. return;
  191146. REFERENCE_TIME defaultPeriod, minPeriod;
  191147. if (! OK (tempClient->GetDevicePeriod (&defaultPeriod, &minPeriod)))
  191148. return;
  191149. WAVEFORMATEX* mixFormat = 0;
  191150. if (! OK (tempClient->GetMixFormat (&mixFormat)))
  191151. return;
  191152. WAVEFORMATEXTENSIBLE format;
  191153. wasapi_copyWavFormat (format, mixFormat);
  191154. CoTaskMemFree (mixFormat);
  191155. actualNumChannels = numChannels = format.Format.nChannels;
  191156. defaultSampleRate = format.Format.nSamplesPerSec;
  191157. minBufferSize = wasapi_refTimeToSamples (minPeriod, defaultSampleRate);
  191158. defaultBufferSize = wasapi_refTimeToSamples (defaultPeriod, defaultSampleRate);
  191159. FloatElementComparator<double> comparator;
  191160. rates.addSorted (comparator, defaultSampleRate);
  191161. static const double ratesToTest[] = { 44100.0, 48000.0, 88200.0, 96000.0 };
  191162. for (int i = 0; i < numElementsInArray (ratesToTest); ++i)
  191163. {
  191164. if (ratesToTest[i] == defaultSampleRate)
  191165. continue;
  191166. format.Format.nSamplesPerSec = roundDoubleToInt (ratesToTest[i]);
  191167. if (SUCCEEDED (tempClient->IsFormatSupported (useExclusiveMode ? AUDCLNT_SHAREMODE_EXCLUSIVE : AUDCLNT_SHAREMODE_SHARED,
  191168. (WAVEFORMATEX*) &format, 0)))
  191169. if (! rates.contains (ratesToTest[i]))
  191170. rates.addSorted (comparator, ratesToTest[i]);
  191171. }
  191172. }
  191173. ~WASAPIDeviceBase()
  191174. {
  191175. device = 0;
  191176. CloseHandle (clientEvent);
  191177. }
  191178. bool isOk() const throw() { return defaultBufferSize > 0 && defaultSampleRate > 0; }
  191179. bool openClient (const double newSampleRate, const BitArray& newChannels)
  191180. {
  191181. sampleRate = newSampleRate;
  191182. channels = newChannels;
  191183. channels.setRange (actualNumChannels, channels.getHighestBit() + 1 - actualNumChannels, false);
  191184. numChannels = channels.getHighestBit() + 1;
  191185. if (numChannels == 0)
  191186. return true;
  191187. client = createClient();
  191188. if (client != 0
  191189. && (tryInitialisingWithFormat (true, 4) || tryInitialisingWithFormat (false, 4)
  191190. || tryInitialisingWithFormat (false, 3) || tryInitialisingWithFormat (false, 2)))
  191191. {
  191192. channelMaps.clear();
  191193. for (int i = 0; i <= channels.getHighestBit(); ++i)
  191194. if (channels[i])
  191195. channelMaps.add (i);
  191196. REFERENCE_TIME latency;
  191197. if (OK (client->GetStreamLatency (&latency)))
  191198. latencySamples = wasapi_refTimeToSamples (latency, sampleRate);
  191199. (void) OK (client->GetBufferSize (&actualBufferSize));
  191200. return OK (client->SetEventHandle (clientEvent));
  191201. }
  191202. return false;
  191203. }
  191204. void closeClient()
  191205. {
  191206. if (client != 0)
  191207. client->Stop();
  191208. client = 0;
  191209. ResetEvent (clientEvent);
  191210. }
  191211. ComSmartPtr <IMMDevice> device;
  191212. ComSmartPtr <IAudioClient> client;
  191213. double sampleRate, defaultSampleRate;
  191214. int numChannels, actualNumChannels;
  191215. int minBufferSize, defaultBufferSize, latencySamples;
  191216. const bool useExclusiveMode;
  191217. Array <double> rates;
  191218. HANDLE clientEvent;
  191219. BitArray channels;
  191220. AudioDataConverters::DataFormat dataFormat;
  191221. Array <int> channelMaps;
  191222. UINT32 actualBufferSize;
  191223. int bytesPerSample;
  191224. private:
  191225. const ComSmartPtr <IAudioClient> createClient()
  191226. {
  191227. ComSmartPtr <IAudioClient> client;
  191228. if (device != 0)
  191229. {
  191230. HRESULT hr = device->Activate (__uuidof (IAudioClient), CLSCTX_INPROC_SERVER, 0, (void**) &client);
  191231. logFailure (hr);
  191232. }
  191233. return client;
  191234. }
  191235. bool tryInitialisingWithFormat (const bool useFloat, const int bytesPerSampleToTry)
  191236. {
  191237. WAVEFORMATEXTENSIBLE format;
  191238. zerostruct (format);
  191239. if (numChannels <= 2 && bytesPerSampleToTry <= 2)
  191240. {
  191241. format.Format.wFormatTag = WAVE_FORMAT_PCM;
  191242. }
  191243. else
  191244. {
  191245. format.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
  191246. format.Format.cbSize = sizeof (WAVEFORMATEXTENSIBLE) - sizeof (WAVEFORMATEX);
  191247. }
  191248. format.Format.nSamplesPerSec = roundDoubleToInt (sampleRate);
  191249. format.Format.nChannels = (WORD) numChannels;
  191250. format.Format.wBitsPerSample = (WORD) (8 * bytesPerSampleToTry);
  191251. format.Format.nAvgBytesPerSec = (DWORD) (format.Format.nSamplesPerSec * numChannels * bytesPerSampleToTry);
  191252. format.Format.nBlockAlign = (WORD) (numChannels * bytesPerSampleToTry);
  191253. format.SubFormat = useFloat ? KSDATAFORMAT_SUBTYPE_IEEE_FLOAT : KSDATAFORMAT_SUBTYPE_PCM;
  191254. format.Samples.wValidBitsPerSample = format.Format.wBitsPerSample;
  191255. switch (numChannels)
  191256. {
  191257. case 1: format.dwChannelMask = SPEAKER_FRONT_CENTER; break;
  191258. case 2: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT; break;
  191259. case 4: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT; break;
  191260. case 6: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | SPEAKER_LOW_FREQUENCY | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT; break;
  191261. 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;
  191262. default: break;
  191263. }
  191264. WAVEFORMATEXTENSIBLE* nearestFormat = 0;
  191265. HRESULT hr = client->IsFormatSupported (useExclusiveMode ? AUDCLNT_SHAREMODE_EXCLUSIVE : AUDCLNT_SHAREMODE_SHARED,
  191266. (WAVEFORMATEX*) &format, useExclusiveMode ? 0 : (WAVEFORMATEX**) &nearestFormat);
  191267. logFailure (hr);
  191268. if (hr == S_FALSE && format.Format.nSamplesPerSec == nearestFormat->Format.nSamplesPerSec)
  191269. {
  191270. wasapi_copyWavFormat (format, (WAVEFORMATEX*) nearestFormat);
  191271. hr = S_OK;
  191272. }
  191273. CoTaskMemFree (nearestFormat);
  191274. REFERENCE_TIME defaultPeriod = 0, minPeriod = 0;
  191275. if (useExclusiveMode)
  191276. OK (client->GetDevicePeriod (&defaultPeriod, &minPeriod));
  191277. GUID session;
  191278. if (hr == S_OK
  191279. && OK (client->Initialize (useExclusiveMode ? AUDCLNT_SHAREMODE_EXCLUSIVE : AUDCLNT_SHAREMODE_SHARED,
  191280. AUDCLNT_STREAMFLAGS_EVENTCALLBACK,
  191281. defaultPeriod, defaultPeriod, (WAVEFORMATEX*) &format, &session)))
  191282. {
  191283. actualNumChannels = format.Format.nChannels;
  191284. const bool isFloat = format.Format.wFormatTag == WAVE_FORMAT_EXTENSIBLE && format.SubFormat == KSDATAFORMAT_SUBTYPE_IEEE_FLOAT;
  191285. bytesPerSample = format.Format.wBitsPerSample / 8;
  191286. dataFormat = isFloat ? AudioDataConverters::float32LE
  191287. : (bytesPerSample == 4 ? AudioDataConverters::int32LE
  191288. : ((bytesPerSample == 3 ? AudioDataConverters::int24LE
  191289. : AudioDataConverters::int16LE)));
  191290. return true;
  191291. }
  191292. return false;
  191293. }
  191294. };
  191295. class WASAPIInputDevice : public WASAPIDeviceBase
  191296. {
  191297. public:
  191298. WASAPIInputDevice (const ComSmartPtr <IMMDevice>& device_, const bool useExclusiveMode_)
  191299. : WASAPIDeviceBase (device_, useExclusiveMode_),
  191300. reservoir (1, 1)
  191301. {
  191302. }
  191303. ~WASAPIInputDevice()
  191304. {
  191305. close();
  191306. }
  191307. bool open (const double newSampleRate, const BitArray& newChannels)
  191308. {
  191309. reservoirSize = 0;
  191310. reservoirCapacity = 16384;
  191311. reservoir.setSize (actualNumChannels * reservoirCapacity * sizeof (float));
  191312. return openClient (newSampleRate, newChannels)
  191313. && (numChannels == 0 || OK (client->GetService (__uuidof (IAudioCaptureClient), (void**) &captureClient)));
  191314. }
  191315. void close()
  191316. {
  191317. closeClient();
  191318. captureClient = 0;
  191319. reservoir.setSize (0);
  191320. }
  191321. void copyBuffers (float** destBuffers, int numDestBuffers, int bufferSize, Thread& thread)
  191322. {
  191323. if (numChannels <= 0)
  191324. return;
  191325. int offset = 0;
  191326. while (bufferSize > 0)
  191327. {
  191328. if (reservoirSize > 0) // There's stuff in the reservoir, so use that...
  191329. {
  191330. const int samplesToDo = jmin (bufferSize, (int) reservoirSize);
  191331. for (int i = 0; i < numDestBuffers; ++i)
  191332. {
  191333. float* const dest = destBuffers[i] + offset;
  191334. const int srcChan = channelMaps.getUnchecked(i);
  191335. switch (dataFormat)
  191336. {
  191337. case AudioDataConverters::float32LE:
  191338. AudioDataConverters::convertFloat32LEToFloat (((uint8*) reservoir.getData()) + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191339. break;
  191340. case AudioDataConverters::int32LE:
  191341. AudioDataConverters::convertInt32LEToFloat (((uint8*) reservoir.getData()) + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191342. break;
  191343. case AudioDataConverters::int24LE:
  191344. AudioDataConverters::convertInt24LEToFloat (((uint8*) reservoir.getData()) + 3 * srcChan, dest, samplesToDo, 3 * actualNumChannels);
  191345. break;
  191346. case AudioDataConverters::int16LE:
  191347. AudioDataConverters::convertInt16LEToFloat (((uint8*) reservoir.getData()) + 2 * srcChan, dest, samplesToDo, 2 * actualNumChannels);
  191348. break;
  191349. default: jassertfalse; break;
  191350. }
  191351. }
  191352. bufferSize -= samplesToDo;
  191353. offset += samplesToDo;
  191354. reservoirSize -= samplesToDo;
  191355. }
  191356. else
  191357. {
  191358. UINT32 packetLength = 0;
  191359. if (! OK (captureClient->GetNextPacketSize (&packetLength)))
  191360. break;
  191361. if (packetLength == 0)
  191362. {
  191363. if (thread.threadShouldExit())
  191364. break;
  191365. Thread::sleep (1);
  191366. continue;
  191367. }
  191368. uint8* inputData = 0;
  191369. UINT32 numSamplesAvailable;
  191370. DWORD flags;
  191371. if (OK (captureClient->GetBuffer (&inputData, &numSamplesAvailable, &flags, 0, 0)))
  191372. {
  191373. const int samplesToDo = jmin (bufferSize, (int) numSamplesAvailable);
  191374. for (int i = 0; i < numDestBuffers; ++i)
  191375. {
  191376. float* const dest = destBuffers[i] + offset;
  191377. const int srcChan = channelMaps.getUnchecked(i);
  191378. switch (dataFormat)
  191379. {
  191380. case AudioDataConverters::float32LE:
  191381. AudioDataConverters::convertFloat32LEToFloat (inputData + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191382. break;
  191383. case AudioDataConverters::int32LE:
  191384. AudioDataConverters::convertInt32LEToFloat (inputData + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191385. break;
  191386. case AudioDataConverters::int24LE:
  191387. AudioDataConverters::convertInt24LEToFloat (inputData + 3 * srcChan, dest, samplesToDo, 3 * actualNumChannels);
  191388. break;
  191389. case AudioDataConverters::int16LE:
  191390. AudioDataConverters::convertInt16LEToFloat (inputData + 2 * srcChan, dest, samplesToDo, 2 * actualNumChannels);
  191391. break;
  191392. default: jassertfalse; break;
  191393. }
  191394. }
  191395. bufferSize -= samplesToDo;
  191396. offset += samplesToDo;
  191397. if (samplesToDo < (int) numSamplesAvailable)
  191398. {
  191399. reservoirSize = jmin ((int) (numSamplesAvailable - samplesToDo), reservoirCapacity);
  191400. memcpy ((uint8*) reservoir.getData(), inputData + bytesPerSample * actualNumChannels * samplesToDo,
  191401. bytesPerSample * actualNumChannels * reservoirSize);
  191402. }
  191403. captureClient->ReleaseBuffer (numSamplesAvailable);
  191404. }
  191405. }
  191406. }
  191407. }
  191408. ComSmartPtr <IAudioCaptureClient> captureClient;
  191409. MemoryBlock reservoir;
  191410. int reservoirSize, reservoirCapacity;
  191411. };
  191412. class WASAPIOutputDevice : public WASAPIDeviceBase
  191413. {
  191414. public:
  191415. WASAPIOutputDevice (const ComSmartPtr <IMMDevice>& device_, const bool useExclusiveMode_)
  191416. : WASAPIDeviceBase (device_, useExclusiveMode_)
  191417. {
  191418. }
  191419. ~WASAPIOutputDevice()
  191420. {
  191421. close();
  191422. }
  191423. bool open (const double newSampleRate, const BitArray& newChannels)
  191424. {
  191425. return openClient (newSampleRate, newChannels)
  191426. && (numChannels == 0 || OK (client->GetService (__uuidof (IAudioRenderClient), (void**) &renderClient)));
  191427. }
  191428. void close()
  191429. {
  191430. closeClient();
  191431. renderClient = 0;
  191432. }
  191433. void copyBuffers (const float** const srcBuffers, const int numSrcBuffers, int bufferSize, Thread& thread)
  191434. {
  191435. if (numChannels <= 0)
  191436. return;
  191437. int offset = 0;
  191438. while (bufferSize > 0)
  191439. {
  191440. UINT32 padding = 0;
  191441. if (! OK (client->GetCurrentPadding (&padding)))
  191442. return;
  191443. int samplesToDo = useExclusiveMode ? bufferSize
  191444. : jmin ((int) (actualBufferSize - padding), bufferSize);
  191445. if (samplesToDo <= 0)
  191446. {
  191447. if (thread.threadShouldExit())
  191448. break;
  191449. Thread::sleep (0);
  191450. continue;
  191451. }
  191452. uint8* outputData = 0;
  191453. if (OK (renderClient->GetBuffer (samplesToDo, &outputData)))
  191454. {
  191455. for (int i = 0; i < numSrcBuffers; ++i)
  191456. {
  191457. const float* const source = srcBuffers[i] + offset;
  191458. const int destChan = channelMaps.getUnchecked(i);
  191459. switch (dataFormat)
  191460. {
  191461. case AudioDataConverters::float32LE:
  191462. AudioDataConverters::convertFloatToFloat32LE (source, outputData + 4 * destChan, samplesToDo, 4 * actualNumChannels);
  191463. break;
  191464. case AudioDataConverters::int32LE:
  191465. AudioDataConverters::convertFloatToInt32LE (source, outputData + 4 * destChan, samplesToDo, 4 * actualNumChannels);
  191466. break;
  191467. case AudioDataConverters::int24LE:
  191468. AudioDataConverters::convertFloatToInt24LE (source, outputData + 3 * destChan, samplesToDo, 3 * actualNumChannels);
  191469. break;
  191470. case AudioDataConverters::int16LE:
  191471. AudioDataConverters::convertFloatToInt16LE (source, outputData + 2 * destChan, samplesToDo, 2 * actualNumChannels);
  191472. break;
  191473. default: jassertfalse; break;
  191474. }
  191475. }
  191476. renderClient->ReleaseBuffer (samplesToDo, 0);
  191477. offset += samplesToDo;
  191478. bufferSize -= samplesToDo;
  191479. }
  191480. }
  191481. }
  191482. ComSmartPtr <IAudioRenderClient> renderClient;
  191483. };
  191484. class WASAPIAudioIODevice : public AudioIODevice,
  191485. public Thread
  191486. {
  191487. public:
  191488. WASAPIAudioIODevice (const String& deviceName,
  191489. const String& outputDeviceId_,
  191490. const String& inputDeviceId_,
  191491. const bool useExclusiveMode_)
  191492. : AudioIODevice (deviceName, "Windows Audio"),
  191493. Thread ("Juce WASAPI"),
  191494. isOpen_ (false),
  191495. isStarted (false),
  191496. outputDevice (0),
  191497. outputDeviceId (outputDeviceId_),
  191498. inputDevice (0),
  191499. inputDeviceId (inputDeviceId_),
  191500. useExclusiveMode (useExclusiveMode_),
  191501. currentBufferSizeSamples (0),
  191502. currentSampleRate (0),
  191503. callback (0)
  191504. {
  191505. }
  191506. ~WASAPIAudioIODevice()
  191507. {
  191508. close();
  191509. deleteAndZero (inputDevice);
  191510. deleteAndZero (outputDevice);
  191511. }
  191512. bool initialise()
  191513. {
  191514. double defaultSampleRateIn = 0, defaultSampleRateOut = 0;
  191515. int minBufferSizeIn = 0, defaultBufferSizeIn = 0, minBufferSizeOut = 0, defaultBufferSizeOut = 0;
  191516. latencyIn = latencyOut = 0;
  191517. Array <double> ratesIn, ratesOut;
  191518. if (createDevices())
  191519. {
  191520. jassert (inputDevice != 0 || outputDevice != 0);
  191521. if (inputDevice != 0 && outputDevice != 0)
  191522. {
  191523. defaultSampleRate = jmin (inputDevice->defaultSampleRate, outputDevice->defaultSampleRate);
  191524. minBufferSize = jmin (inputDevice->minBufferSize, outputDevice->minBufferSize);
  191525. defaultBufferSize = jmax (inputDevice->defaultBufferSize, outputDevice->defaultBufferSize);
  191526. sampleRates = inputDevice->rates;
  191527. sampleRates.removeValuesNotIn (outputDevice->rates);
  191528. }
  191529. else
  191530. {
  191531. WASAPIDeviceBase* const d = inputDevice != 0 ? (WASAPIDeviceBase*) inputDevice : (WASAPIDeviceBase*) outputDevice;
  191532. defaultSampleRate = d->defaultSampleRate;
  191533. minBufferSize = d->minBufferSize;
  191534. defaultBufferSize = d->defaultBufferSize;
  191535. sampleRates = d->rates;
  191536. }
  191537. IntegerElementComparator<int> comparator;
  191538. bufferSizes.addSorted (comparator, defaultBufferSize);
  191539. if (minBufferSize != defaultBufferSize)
  191540. bufferSizes.addSorted (comparator, minBufferSize);
  191541. int n = 64;
  191542. for (int i = 0; i < 40; ++i)
  191543. {
  191544. if (n >= minBufferSize && n <= 2048 && ! bufferSizes.contains (n))
  191545. bufferSizes.addSorted (comparator, n);
  191546. n += (n < 512) ? 32 : (n < 1024 ? 64 : 128);
  191547. }
  191548. return true;
  191549. }
  191550. return false;
  191551. }
  191552. const StringArray getOutputChannelNames()
  191553. {
  191554. StringArray outChannels;
  191555. if (outputDevice != 0)
  191556. for (int i = 1; i <= outputDevice->actualNumChannels; ++i)
  191557. outChannels.add ("Output channel " + String (i));
  191558. return outChannels;
  191559. }
  191560. const StringArray getInputChannelNames()
  191561. {
  191562. StringArray inChannels;
  191563. if (inputDevice != 0)
  191564. for (int i = 1; i <= inputDevice->actualNumChannels; ++i)
  191565. inChannels.add ("Input channel " + String (i));
  191566. return inChannels;
  191567. }
  191568. int getNumSampleRates() { return sampleRates.size(); }
  191569. double getSampleRate (int index) { return sampleRates [index]; }
  191570. int getNumBufferSizesAvailable() { return bufferSizes.size(); }
  191571. int getBufferSizeSamples (int index) { return bufferSizes [index]; }
  191572. int getDefaultBufferSize() { return defaultBufferSize; }
  191573. int getCurrentBufferSizeSamples() { return currentBufferSizeSamples; }
  191574. double getCurrentSampleRate() { return currentSampleRate; }
  191575. int getCurrentBitDepth() { return 32; }
  191576. int getOutputLatencyInSamples() { return latencyOut; }
  191577. int getInputLatencyInSamples() { return latencyIn; }
  191578. const BitArray getActiveOutputChannels() const { return outputDevice != 0 ? outputDevice->channels : BitArray(); }
  191579. const BitArray getActiveInputChannels() const { return inputDevice != 0 ? inputDevice->channels : BitArray(); }
  191580. const String getLastError() { return lastError; }
  191581. const String open (const BitArray& inputChannels, const BitArray& outputChannels,
  191582. double sampleRate, int bufferSizeSamples)
  191583. {
  191584. close();
  191585. lastError = String::empty;
  191586. if (sampleRates.size() == 0 && inputDevice != 0 && outputDevice != 0)
  191587. {
  191588. lastError = "The input and output devices don't share a common sample rate!";
  191589. return lastError;
  191590. }
  191591. currentBufferSizeSamples = bufferSizeSamples <= 0 ? defaultBufferSize : jmax (bufferSizeSamples, minBufferSize);
  191592. currentSampleRate = sampleRate > 0 ? sampleRate : defaultSampleRate;
  191593. if (inputDevice != 0 && ! inputDevice->open (currentSampleRate, inputChannels))
  191594. {
  191595. lastError = "Couldn't open the input device!";
  191596. return lastError;
  191597. }
  191598. if (outputDevice != 0 && ! outputDevice->open (currentSampleRate, outputChannels))
  191599. {
  191600. close();
  191601. lastError = "Couldn't open the output device!";
  191602. return lastError;
  191603. }
  191604. if (inputDevice != 0)
  191605. ResetEvent (inputDevice->clientEvent);
  191606. if (outputDevice != 0)
  191607. ResetEvent (outputDevice->clientEvent);
  191608. startThread (8);
  191609. Thread::sleep (5);
  191610. if (inputDevice != 0 && inputDevice->client != 0)
  191611. {
  191612. latencyIn = inputDevice->latencySamples + inputDevice->actualBufferSize + inputDevice->minBufferSize;
  191613. HRESULT hr = inputDevice->client->Start();
  191614. logFailure (hr); //xxx handle this
  191615. }
  191616. if (outputDevice != 0 && outputDevice->client != 0)
  191617. {
  191618. latencyOut = outputDevice->latencySamples + outputDevice->actualBufferSize + outputDevice->minBufferSize;
  191619. HRESULT hr = outputDevice->client->Start();
  191620. logFailure (hr); //xxx handle this
  191621. }
  191622. isOpen_ = true;
  191623. return lastError;
  191624. }
  191625. void close()
  191626. {
  191627. stop();
  191628. if (inputDevice != 0)
  191629. SetEvent (inputDevice->clientEvent);
  191630. if (outputDevice != 0)
  191631. SetEvent (outputDevice->clientEvent);
  191632. stopThread (5000);
  191633. if (inputDevice != 0)
  191634. inputDevice->close();
  191635. if (outputDevice != 0)
  191636. outputDevice->close();
  191637. isOpen_ = false;
  191638. }
  191639. bool isOpen() { return isOpen_ && isThreadRunning(); }
  191640. bool isPlaying() { return isStarted && isOpen_ && isThreadRunning(); }
  191641. void start (AudioIODeviceCallback* call)
  191642. {
  191643. if (isOpen_ && call != 0 && ! isStarted)
  191644. {
  191645. if (! isThreadRunning())
  191646. {
  191647. // something's gone wrong and the thread's stopped..
  191648. isOpen_ = false;
  191649. return;
  191650. }
  191651. call->audioDeviceAboutToStart (this);
  191652. const ScopedLock sl (startStopLock);
  191653. callback = call;
  191654. isStarted = true;
  191655. }
  191656. }
  191657. void stop()
  191658. {
  191659. if (isStarted)
  191660. {
  191661. AudioIODeviceCallback* const callbackLocal = callback;
  191662. {
  191663. const ScopedLock sl (startStopLock);
  191664. isStarted = false;
  191665. }
  191666. if (callbackLocal != 0)
  191667. callbackLocal->audioDeviceStopped();
  191668. }
  191669. }
  191670. void setMMThreadPriority()
  191671. {
  191672. DynamicLibraryLoader dll ("avrt.dll");
  191673. DynamicLibraryImport (AvSetMmThreadCharacteristics, avSetMmThreadCharacteristics, HANDLE, dll, (LPCTSTR, LPDWORD))
  191674. DynamicLibraryImport (AvSetMmThreadPriority, avSetMmThreadPriority, HANDLE, dll, (HANDLE, AVRT_PRIORITY))
  191675. if (avSetMmThreadCharacteristics != 0 && avSetMmThreadPriority != 0)
  191676. {
  191677. DWORD dummy = 0;
  191678. HANDLE h = avSetMmThreadCharacteristics (_T("Pro Audio"), &dummy);
  191679. if (h != 0)
  191680. avSetMmThreadPriority (h, AVRT_PRIORITY_NORMAL);
  191681. }
  191682. }
  191683. void run()
  191684. {
  191685. setMMThreadPriority();
  191686. const int bufferSize = currentBufferSizeSamples;
  191687. HANDLE events[2];
  191688. int numEvents = 0;
  191689. if (inputDevice != 0)
  191690. events [numEvents++] = inputDevice->clientEvent;
  191691. if (outputDevice != 0)
  191692. events [numEvents++] = outputDevice->clientEvent;
  191693. const int numInputBuffers = getActiveInputChannels().countNumberOfSetBits();
  191694. const int numOutputBuffers = getActiveOutputChannels().countNumberOfSetBits();
  191695. AudioSampleBuffer ins (jmax (1, numInputBuffers), bufferSize + 32);
  191696. AudioSampleBuffer outs (jmax (1, numOutputBuffers), bufferSize + 32);
  191697. float** const inputBuffers = ins.getArrayOfChannels();
  191698. float** const outputBuffers = outs.getArrayOfChannels();
  191699. ins.clear();
  191700. while (! threadShouldExit())
  191701. {
  191702. const DWORD result = useExclusiveMode ? WaitForSingleObject (inputDevice->clientEvent, 1000)
  191703. : WaitForMultipleObjects (numEvents, events, true, 1000);
  191704. if (result == WAIT_TIMEOUT)
  191705. continue;
  191706. if (threadShouldExit())
  191707. break;
  191708. if (inputDevice != 0)
  191709. inputDevice->copyBuffers (inputBuffers, numInputBuffers, bufferSize, *this);
  191710. // Make the callback..
  191711. {
  191712. const ScopedLock sl (startStopLock);
  191713. if (isStarted)
  191714. {
  191715. JUCE_TRY
  191716. {
  191717. callback->audioDeviceIOCallback ((const float**) inputBuffers,
  191718. numInputBuffers,
  191719. outputBuffers,
  191720. numOutputBuffers,
  191721. bufferSize);
  191722. }
  191723. JUCE_CATCH_EXCEPTION
  191724. }
  191725. else
  191726. {
  191727. outs.clear();
  191728. }
  191729. }
  191730. if (useExclusiveMode && WaitForSingleObject (outputDevice->clientEvent, 1000) == WAIT_TIMEOUT)
  191731. continue;
  191732. if (outputDevice != 0)
  191733. outputDevice->copyBuffers ((const float**) outputBuffers, numOutputBuffers, bufferSize, *this);
  191734. }
  191735. }
  191736. juce_UseDebuggingNewOperator
  191737. String outputDeviceId, inputDeviceId;
  191738. String lastError;
  191739. private:
  191740. // Device stats...
  191741. WASAPIInputDevice* inputDevice;
  191742. WASAPIOutputDevice* outputDevice;
  191743. const bool useExclusiveMode;
  191744. double defaultSampleRate;
  191745. int minBufferSize, defaultBufferSize;
  191746. int latencyIn, latencyOut;
  191747. Array <double> sampleRates;
  191748. Array <int> bufferSizes;
  191749. // Active state...
  191750. bool isOpen_, isStarted;
  191751. int currentBufferSizeSamples;
  191752. double currentSampleRate;
  191753. AudioIODeviceCallback* callback;
  191754. CriticalSection startStopLock;
  191755. bool createDevices()
  191756. {
  191757. ComSmartPtr <IMMDeviceEnumerator> enumerator;
  191758. if (! OK (enumerator.CoCreateInstance (__uuidof (MMDeviceEnumerator), CLSCTX_INPROC_SERVER)))
  191759. return false;
  191760. ComSmartPtr <IMMDeviceCollection> deviceCollection;
  191761. if (! OK (enumerator->EnumAudioEndpoints (eAll, DEVICE_STATE_ACTIVE, &deviceCollection)))
  191762. return false;
  191763. UINT32 numDevices = 0;
  191764. if (! OK (deviceCollection->GetCount (&numDevices)))
  191765. return false;
  191766. for (UINT32 i = 0; i < numDevices; ++i)
  191767. {
  191768. ComSmartPtr <IMMDevice> device;
  191769. if (! OK (deviceCollection->Item (i, &device)))
  191770. continue;
  191771. const String deviceId (wasapi_getDeviceID (device));
  191772. if (deviceId.isEmpty())
  191773. continue;
  191774. const EDataFlow flow = wasapi_getDataFlow (device);
  191775. if (deviceId == inputDeviceId && flow == eCapture)
  191776. inputDevice = new WASAPIInputDevice (device, useExclusiveMode);
  191777. else if (deviceId == outputDeviceId && flow == eRender)
  191778. outputDevice = new WASAPIOutputDevice (device, useExclusiveMode);
  191779. }
  191780. return (outputDeviceId.isEmpty() || (outputDevice != 0 && outputDevice->isOk()))
  191781. && (inputDeviceId.isEmpty() || (inputDevice != 0 && inputDevice->isOk()));
  191782. }
  191783. WASAPIAudioIODevice (const WASAPIAudioIODevice&);
  191784. WASAPIAudioIODevice& operator= (const WASAPIAudioIODevice&);
  191785. };
  191786. class WASAPIAudioIODeviceType : public AudioIODeviceType
  191787. {
  191788. public:
  191789. WASAPIAudioIODeviceType()
  191790. : AudioIODeviceType (T("Windows Audio")),
  191791. hasScanned (false)
  191792. {
  191793. }
  191794. ~WASAPIAudioIODeviceType()
  191795. {
  191796. }
  191797. void scanForDevices()
  191798. {
  191799. hasScanned = true;
  191800. outputDeviceNames.clear();
  191801. inputDeviceNames.clear();
  191802. outputDeviceIds.clear();
  191803. inputDeviceIds.clear();
  191804. ComSmartPtr <IMMDeviceEnumerator> enumerator;
  191805. if (! OK (enumerator.CoCreateInstance (__uuidof (MMDeviceEnumerator), CLSCTX_INPROC_SERVER)))
  191806. return;
  191807. const String defaultRenderer = getDefaultEndpoint (enumerator, false);
  191808. const String defaultCapture = getDefaultEndpoint (enumerator, true);
  191809. ComSmartPtr <IMMDeviceCollection> deviceCollection;
  191810. UINT32 numDevices = 0;
  191811. if (! (OK (enumerator->EnumAudioEndpoints (eAll, DEVICE_STATE_ACTIVE, &deviceCollection))
  191812. && OK (deviceCollection->GetCount (&numDevices))))
  191813. return;
  191814. for (UINT32 i = 0; i < numDevices; ++i)
  191815. {
  191816. ComSmartPtr <IMMDevice> device;
  191817. if (! OK (deviceCollection->Item (i, &device)))
  191818. continue;
  191819. const String deviceId (wasapi_getDeviceID (device));
  191820. DWORD state = 0;
  191821. if (! OK (device->GetState (&state)))
  191822. continue;
  191823. if (state != DEVICE_STATE_ACTIVE)
  191824. continue;
  191825. String name;
  191826. {
  191827. ComSmartPtr <IPropertyStore> properties;
  191828. if (! OK (device->OpenPropertyStore (STGM_READ, &properties)))
  191829. continue;
  191830. PROPVARIANT value;
  191831. PropVariantInit (&value);
  191832. if (OK (properties->GetValue (PKEY_Device_FriendlyName, &value)))
  191833. name = value.pwszVal;
  191834. PropVariantClear (&value);
  191835. }
  191836. const EDataFlow flow = wasapi_getDataFlow (device);
  191837. if (flow == eRender)
  191838. {
  191839. const int index = (deviceId == defaultRenderer) ? 0 : -1;
  191840. outputDeviceIds.insert (index, deviceId);
  191841. outputDeviceNames.insert (index, name);
  191842. }
  191843. else if (flow == eCapture)
  191844. {
  191845. const int index = (deviceId == defaultCapture) ? 0 : -1;
  191846. inputDeviceIds.insert (index, deviceId);
  191847. inputDeviceNames.insert (index, name);
  191848. }
  191849. }
  191850. inputDeviceNames.appendNumbersToDuplicates (false, false);
  191851. outputDeviceNames.appendNumbersToDuplicates (false, false);
  191852. }
  191853. const StringArray getDeviceNames (const bool wantInputNames) const
  191854. {
  191855. jassert (hasScanned); // need to call scanForDevices() before doing this
  191856. return wantInputNames ? inputDeviceNames
  191857. : outputDeviceNames;
  191858. }
  191859. int getDefaultDeviceIndex (const bool /*forInput*/) const
  191860. {
  191861. jassert (hasScanned); // need to call scanForDevices() before doing this
  191862. return 0;
  191863. }
  191864. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  191865. {
  191866. jassert (hasScanned); // need to call scanForDevices() before doing this
  191867. WASAPIAudioIODevice* const d = dynamic_cast <WASAPIAudioIODevice*> (device);
  191868. return d == 0 ? -1 : (asInput ? inputDeviceIds.indexOf (d->inputDeviceId)
  191869. : outputDeviceIds.indexOf (d->outputDeviceId));
  191870. }
  191871. bool hasSeparateInputsAndOutputs() const { return true; }
  191872. AudioIODevice* createDevice (const String& outputDeviceName,
  191873. const String& inputDeviceName)
  191874. {
  191875. jassert (hasScanned); // need to call scanForDevices() before doing this
  191876. const bool useExclusiveMode = false;
  191877. WASAPIAudioIODevice* d = 0;
  191878. const int outputIndex = outputDeviceNames.indexOf (outputDeviceName);
  191879. const int inputIndex = inputDeviceNames.indexOf (inputDeviceName);
  191880. if (outputIndex >= 0 || inputIndex >= 0)
  191881. {
  191882. d = new WASAPIAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
  191883. : inputDeviceName,
  191884. outputDeviceIds [outputIndex],
  191885. inputDeviceIds [inputIndex],
  191886. useExclusiveMode);
  191887. if (! d->initialise())
  191888. deleteAndZero (d);
  191889. }
  191890. return d;
  191891. }
  191892. juce_UseDebuggingNewOperator
  191893. StringArray outputDeviceNames, outputDeviceIds;
  191894. StringArray inputDeviceNames, inputDeviceIds;
  191895. private:
  191896. bool hasScanned;
  191897. static const String getDefaultEndpoint (IMMDeviceEnumerator* const enumerator, const bool forCapture)
  191898. {
  191899. String s;
  191900. IMMDevice* dev = 0;
  191901. if (OK (enumerator->GetDefaultAudioEndpoint (forCapture ? eCapture : eRender,
  191902. eMultimedia, &dev)))
  191903. {
  191904. WCHAR* deviceId = 0;
  191905. if (OK (dev->GetId (&deviceId)))
  191906. {
  191907. s = String (deviceId);
  191908. CoTaskMemFree (deviceId);
  191909. }
  191910. dev->Release();
  191911. }
  191912. return s;
  191913. }
  191914. WASAPIAudioIODeviceType (const WASAPIAudioIODeviceType&);
  191915. WASAPIAudioIODeviceType& operator= (const WASAPIAudioIODeviceType&);
  191916. };
  191917. AudioIODeviceType* juce_createAudioIODeviceType_WASAPI()
  191918. {
  191919. return new WASAPIAudioIODeviceType();
  191920. }
  191921. #undef logFailure
  191922. #undef OK
  191923. #endif
  191924. /*** End of inlined file: juce_win32_WASAPI.cpp ***/
  191925. /*** Start of inlined file: juce_win32_CameraDevice.cpp ***/
  191926. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  191927. // compiled on its own).
  191928. #if JUCE_INCLUDED_FILE && JUCE_USE_CAMERA
  191929. class DShowCameraDeviceInteral : public ChangeBroadcaster
  191930. {
  191931. public:
  191932. DShowCameraDeviceInteral (CameraDevice* const owner_,
  191933. const ComSmartPtr <ICaptureGraphBuilder2>& captureGraphBuilder_,
  191934. const ComSmartPtr <IBaseFilter>& filter_,
  191935. int minWidth, int minHeight,
  191936. int maxWidth, int maxHeight)
  191937. : owner (owner_),
  191938. captureGraphBuilder (captureGraphBuilder_),
  191939. filter (filter_),
  191940. ok (false),
  191941. imageNeedsFlipping (false),
  191942. width (0),
  191943. height (0),
  191944. activeUsers (0),
  191945. recordNextFrameTime (false),
  191946. activeImage (0),
  191947. loadingImage (0)
  191948. {
  191949. HRESULT hr = graphBuilder.CoCreateInstance (CLSID_FilterGraph, CLSCTX_INPROC);
  191950. if (FAILED (hr))
  191951. return;
  191952. hr = captureGraphBuilder->SetFiltergraph (graphBuilder);
  191953. if (FAILED (hr))
  191954. return;
  191955. hr = graphBuilder->QueryInterface (IID_IMediaControl, (void**) &mediaControl);
  191956. if (FAILED (hr))
  191957. return;
  191958. {
  191959. ComSmartPtr <IAMStreamConfig> streamConfig;
  191960. hr = captureGraphBuilder->FindInterface (&PIN_CATEGORY_CAPTURE, 0, filter,
  191961. IID_IAMStreamConfig, (void**) &streamConfig);
  191962. if (streamConfig != 0)
  191963. {
  191964. getVideoSizes (streamConfig);
  191965. if (! selectVideoSize (streamConfig, minWidth, minHeight, maxWidth, maxHeight))
  191966. return;
  191967. }
  191968. }
  191969. hr = graphBuilder->AddFilter (filter, _T("Video Capture"));
  191970. if (FAILED (hr))
  191971. return;
  191972. hr = smartTee.CoCreateInstance (CLSID_SmartTee, CLSCTX_INPROC_SERVER);
  191973. if (FAILED (hr))
  191974. return;
  191975. hr = graphBuilder->AddFilter (smartTee, _T("Smart Tee"));
  191976. if (FAILED (hr))
  191977. return;
  191978. if (! connectFilters (filter, smartTee))
  191979. return;
  191980. ComSmartPtr <IBaseFilter> sampleGrabberBase;
  191981. hr = sampleGrabberBase.CoCreateInstance (CLSID_SampleGrabber, CLSCTX_INPROC_SERVER);
  191982. if (FAILED (hr))
  191983. return;
  191984. hr = sampleGrabberBase->QueryInterface (IID_ISampleGrabber, (void**) &sampleGrabber);
  191985. if (FAILED (hr))
  191986. return;
  191987. AM_MEDIA_TYPE mt;
  191988. zerostruct (mt);
  191989. mt.majortype = MEDIATYPE_Video;
  191990. mt.subtype = MEDIASUBTYPE_RGB24;
  191991. mt.formattype = FORMAT_VideoInfo;
  191992. sampleGrabber->SetMediaType (&mt);
  191993. callback = new GrabberCallback (*this);
  191994. sampleGrabber->SetCallback (callback, 1);
  191995. hr = graphBuilder->AddFilter (sampleGrabberBase, _T("Sample Grabber"));
  191996. if (FAILED (hr))
  191997. return;
  191998. ComSmartPtr <IPin> grabberInputPin;
  191999. if (! (getPin (smartTee, PINDIR_OUTPUT, &smartTeeCaptureOutputPin, "capture")
  192000. && getPin (smartTee, PINDIR_OUTPUT, &smartTeePreviewOutputPin, "preview")
  192001. && getPin (sampleGrabberBase, PINDIR_INPUT, &grabberInputPin)))
  192002. return;
  192003. hr = graphBuilder->Connect (smartTeePreviewOutputPin, grabberInputPin);
  192004. if (FAILED (hr))
  192005. return;
  192006. zerostruct (mt);
  192007. hr = sampleGrabber->GetConnectedMediaType (&mt);
  192008. VIDEOINFOHEADER* pVih = (VIDEOINFOHEADER*) (mt.pbFormat);
  192009. width = pVih->bmiHeader.biWidth;
  192010. height = pVih->bmiHeader.biHeight;
  192011. ComSmartPtr <IBaseFilter> nullFilter;
  192012. hr = nullFilter.CoCreateInstance (CLSID_NullRenderer, CLSCTX_INPROC_SERVER);
  192013. hr = graphBuilder->AddFilter (nullFilter, _T("Null Renderer"));
  192014. if (connectFilters (sampleGrabberBase, nullFilter)
  192015. && addGraphToRot())
  192016. {
  192017. activeImage = new Image (Image::RGB, width, height, true);
  192018. loadingImage = new Image (Image::RGB, width, height, true);
  192019. ok = true;
  192020. }
  192021. }
  192022. ~DShowCameraDeviceInteral()
  192023. {
  192024. if (mediaControl != 0)
  192025. mediaControl->Stop();
  192026. removeGraphFromRot();
  192027. for (int i = viewerComps.size(); --i >= 0;)
  192028. ((DShowCaptureViewerComp*) viewerComps.getUnchecked(i))->ownerDeleted();
  192029. callback = 0;
  192030. graphBuilder = 0;
  192031. sampleGrabber = 0;
  192032. mediaControl = 0;
  192033. filter = 0;
  192034. captureGraphBuilder = 0;
  192035. smartTee = 0;
  192036. smartTeePreviewOutputPin = 0;
  192037. smartTeeCaptureOutputPin = 0;
  192038. asfWriter = 0;
  192039. delete activeImage;
  192040. delete loadingImage;
  192041. }
  192042. void addUser()
  192043. {
  192044. if (ok && activeUsers++ == 0)
  192045. mediaControl->Run();
  192046. }
  192047. void removeUser()
  192048. {
  192049. if (ok && --activeUsers == 0)
  192050. mediaControl->Stop();
  192051. }
  192052. void handleFrame (double /*time*/, BYTE* buffer, long /*bufferSize*/)
  192053. {
  192054. if (recordNextFrameTime)
  192055. {
  192056. const double defaultCameraLatency = 0.1;
  192057. firstRecordedTime = Time::getCurrentTime() - RelativeTime (defaultCameraLatency);
  192058. recordNextFrameTime = false;
  192059. ComSmartPtr <IPin> pin;
  192060. if (getPin (filter, PINDIR_OUTPUT, &pin))
  192061. {
  192062. ComSmartPtr <IAMPushSource> pushSource;
  192063. HRESULT hr = pin->QueryInterface (IID_IAMPushSource, (void**) &pushSource);
  192064. if (pushSource != 0)
  192065. {
  192066. REFERENCE_TIME latency = 0;
  192067. hr = pushSource->GetLatency (&latency);
  192068. firstRecordedTime = firstRecordedTime - RelativeTime ((double) latency);
  192069. }
  192070. }
  192071. }
  192072. {
  192073. const int lineStride = width * 3;
  192074. const ScopedLock sl (imageSwapLock);
  192075. {
  192076. const Image::BitmapData destData (*loadingImage, 0, 0, width, height, true);
  192077. for (int i = 0; i < height; ++i)
  192078. memcpy (destData.getLinePointer ((height - 1) - i),
  192079. buffer + lineStride * i,
  192080. lineStride);
  192081. }
  192082. imageNeedsFlipping = true;
  192083. }
  192084. if (listeners.size() > 0)
  192085. callListeners (*loadingImage);
  192086. sendChangeMessage (this);
  192087. }
  192088. void drawCurrentImage (Graphics& g, int x, int y, int w, int h)
  192089. {
  192090. if (imageNeedsFlipping)
  192091. {
  192092. const ScopedLock sl (imageSwapLock);
  192093. swapVariables (loadingImage, activeImage);
  192094. imageNeedsFlipping = false;
  192095. }
  192096. RectanglePlacement rp (RectanglePlacement::centred);
  192097. double dx = 0, dy = 0, dw = width, dh = height;
  192098. rp.applyTo (dx, dy, dw, dh, x, y, w, h);
  192099. const int rx = roundToInt (dx), ry = roundToInt (dy);
  192100. const int rw = roundToInt (dw), rh = roundToInt (dh);
  192101. g.saveState();
  192102. g.excludeClipRegion (Rectangle<int> (rx, ry, rw, rh));
  192103. g.fillAll (Colours::black);
  192104. g.restoreState();
  192105. g.drawImage (activeImage, rx, ry, rw, rh, 0, 0, width, height);
  192106. }
  192107. bool createFileCaptureFilter (const File& file)
  192108. {
  192109. removeFileCaptureFilter();
  192110. file.deleteFile();
  192111. mediaControl->Stop();
  192112. firstRecordedTime = Time();
  192113. recordNextFrameTime = true;
  192114. HRESULT hr = asfWriter.CoCreateInstance (CLSID_WMAsfWriter, CLSCTX_INPROC_SERVER);
  192115. if (SUCCEEDED (hr))
  192116. {
  192117. ComSmartPtr <IFileSinkFilter> fileSink;
  192118. hr = asfWriter->QueryInterface (IID_IFileSinkFilter, (void**) &fileSink);
  192119. if (SUCCEEDED (hr))
  192120. {
  192121. hr = fileSink->SetFileName (file.getFullPathName(), 0);
  192122. if (SUCCEEDED (hr))
  192123. {
  192124. hr = graphBuilder->AddFilter (asfWriter, _T("AsfWriter"));
  192125. if (SUCCEEDED (hr))
  192126. {
  192127. ComSmartPtr <IConfigAsfWriter> asfConfig;
  192128. hr = asfWriter->QueryInterface (IID_IConfigAsfWriter, (void**) &asfConfig);
  192129. asfConfig->SetIndexMode (true);
  192130. ComSmartPtr <IWMProfileManager> profileManager;
  192131. hr = WMCreateProfileManager (&profileManager);
  192132. // This gibberish is the DirectShow profile for a video-only wmv file.
  192133. String prof ("<profile version=\"589824\" storageformat=\"1\" name=\"Quality\" description=\"Quality type for output.\"><streamconfig "
  192134. "majortype=\"{73646976-0000-0010-8000-00AA00389B71}\" streamnumber=\"1\" streamname=\"Video Stream\" inputname=\"Video409\" bitrate=\"894960\" "
  192135. "bufferwindow=\"0\" reliabletransport=\"1\" decodercomplexity=\"AU\" rfc1766langid=\"en-us\"><videomediaprops maxkeyframespacing=\"50000000\" quality=\"90\"/>"
  192136. "<wmmediatype subtype=\"{33564D57-0000-0010-8000-00AA00389B71}\" bfixedsizesamples=\"0\" btemporalcompression=\"1\" lsamplesize=\"0\"> <videoinfoheader "
  192137. "dwbitrate=\"894960\" dwbiterrorrate=\"0\" avgtimeperframe=\"100000\"><rcsource left=\"0\" top=\"0\" right=\"$WIDTH\" bottom=\"$HEIGHT\"/> <rctarget "
  192138. "left=\"0\" top=\"0\" right=\"$WIDTH\" bottom=\"$HEIGHT\"/> <bitmapinfoheader biwidth=\"$WIDTH\" biheight=\"$HEIGHT\" biplanes=\"1\" bibitcount=\"24\" "
  192139. "bicompression=\"WMV3\" bisizeimage=\"0\" bixpelspermeter=\"0\" biypelspermeter=\"0\" biclrused=\"0\" biclrimportant=\"0\"/> "
  192140. "</videoinfoheader></wmmediatype></streamconfig></profile>");
  192141. prof = prof.replace (T("$WIDTH"), String (width))
  192142. .replace (T("$HEIGHT"), String (height));
  192143. ComSmartPtr <IWMProfile> currentProfile;
  192144. hr = profileManager->LoadProfileByData ((const WCHAR*) prof, &currentProfile);
  192145. hr = asfConfig->ConfigureFilterUsingProfile (currentProfile);
  192146. if (SUCCEEDED (hr))
  192147. {
  192148. ComSmartPtr <IPin> asfWriterInputPin;
  192149. if (getPin (asfWriter, PINDIR_INPUT, &asfWriterInputPin, "Video Input 01"))
  192150. {
  192151. hr = graphBuilder->Connect (smartTeeCaptureOutputPin, asfWriterInputPin);
  192152. if (SUCCEEDED (hr)
  192153. && ok && activeUsers > 0
  192154. && SUCCEEDED (mediaControl->Run()))
  192155. {
  192156. return true;
  192157. }
  192158. }
  192159. }
  192160. }
  192161. }
  192162. }
  192163. }
  192164. removeFileCaptureFilter();
  192165. if (ok && activeUsers > 0)
  192166. mediaControl->Run();
  192167. return false;
  192168. }
  192169. void removeFileCaptureFilter()
  192170. {
  192171. mediaControl->Stop();
  192172. if (asfWriter != 0)
  192173. {
  192174. graphBuilder->RemoveFilter (asfWriter);
  192175. asfWriter = 0;
  192176. }
  192177. if (ok && activeUsers > 0)
  192178. mediaControl->Run();
  192179. }
  192180. void addListener (CameraImageListener* listenerToAdd)
  192181. {
  192182. const ScopedLock sl (listenerLock);
  192183. if (listeners.size() == 0)
  192184. addUser();
  192185. listeners.addIfNotAlreadyThere (listenerToAdd);
  192186. }
  192187. void removeListener (CameraImageListener* listenerToRemove)
  192188. {
  192189. const ScopedLock sl (listenerLock);
  192190. listeners.removeValue (listenerToRemove);
  192191. if (listeners.size() == 0)
  192192. removeUser();
  192193. }
  192194. void callListeners (Image& image)
  192195. {
  192196. const ScopedLock sl (listenerLock);
  192197. for (int i = listeners.size(); --i >= 0;)
  192198. {
  192199. CameraImageListener* l = (CameraImageListener*) listeners[i];
  192200. if (l != 0)
  192201. l->imageReceived (image);
  192202. }
  192203. }
  192204. class DShowCaptureViewerComp : public Component,
  192205. public ChangeListener
  192206. {
  192207. public:
  192208. DShowCaptureViewerComp (DShowCameraDeviceInteral* const owner_)
  192209. : owner (owner_)
  192210. {
  192211. setOpaque (true);
  192212. owner->addChangeListener (this);
  192213. owner->addUser();
  192214. owner->viewerComps.add (this);
  192215. setSize (owner_->width, owner_->height);
  192216. }
  192217. ~DShowCaptureViewerComp()
  192218. {
  192219. if (owner != 0)
  192220. {
  192221. owner->viewerComps.removeValue (this);
  192222. owner->removeUser();
  192223. owner->removeChangeListener (this);
  192224. }
  192225. }
  192226. void ownerDeleted()
  192227. {
  192228. owner = 0;
  192229. }
  192230. void paint (Graphics& g)
  192231. {
  192232. g.setColour (Colours::black);
  192233. g.setImageResamplingQuality (Graphics::lowResamplingQuality);
  192234. if (owner != 0)
  192235. owner->drawCurrentImage (g, 0, 0, getWidth(), getHeight());
  192236. else
  192237. g.fillAll (Colours::black);
  192238. }
  192239. void changeListenerCallback (void*)
  192240. {
  192241. repaint();
  192242. }
  192243. private:
  192244. DShowCameraDeviceInteral* owner;
  192245. };
  192246. bool ok;
  192247. int width, height;
  192248. Time firstRecordedTime;
  192249. VoidArray viewerComps;
  192250. private:
  192251. CameraDevice* const owner;
  192252. ComSmartPtr <ICaptureGraphBuilder2> captureGraphBuilder;
  192253. ComSmartPtr <IBaseFilter> filter;
  192254. ComSmartPtr <IBaseFilter> smartTee;
  192255. ComSmartPtr <IGraphBuilder> graphBuilder;
  192256. ComSmartPtr <ISampleGrabber> sampleGrabber;
  192257. ComSmartPtr <IMediaControl> mediaControl;
  192258. ComSmartPtr <IPin> smartTeePreviewOutputPin;
  192259. ComSmartPtr <IPin> smartTeeCaptureOutputPin;
  192260. ComSmartPtr <IBaseFilter> asfWriter;
  192261. int activeUsers;
  192262. Array <int> widths, heights;
  192263. DWORD graphRegistrationID;
  192264. CriticalSection imageSwapLock;
  192265. bool imageNeedsFlipping;
  192266. Image* loadingImage;
  192267. Image* activeImage;
  192268. bool recordNextFrameTime;
  192269. void getVideoSizes (IAMStreamConfig* const streamConfig)
  192270. {
  192271. widths.clear();
  192272. heights.clear();
  192273. int count = 0, size = 0;
  192274. streamConfig->GetNumberOfCapabilities (&count, &size);
  192275. if (size == sizeof (VIDEO_STREAM_CONFIG_CAPS))
  192276. {
  192277. for (int i = 0; i < count; ++i)
  192278. {
  192279. VIDEO_STREAM_CONFIG_CAPS scc;
  192280. AM_MEDIA_TYPE* config;
  192281. HRESULT hr = streamConfig->GetStreamCaps (i, &config, (BYTE*) &scc);
  192282. if (SUCCEEDED (hr))
  192283. {
  192284. const int w = scc.InputSize.cx;
  192285. const int h = scc.InputSize.cy;
  192286. bool duplicate = false;
  192287. for (int j = widths.size(); --j >= 0;)
  192288. {
  192289. if (w == widths.getUnchecked (j) && h == heights.getUnchecked (j))
  192290. {
  192291. duplicate = true;
  192292. break;
  192293. }
  192294. }
  192295. if (! duplicate)
  192296. {
  192297. DBG ("Camera capture size: " + String (w) + ", " + String (h));
  192298. widths.add (w);
  192299. heights.add (h);
  192300. }
  192301. deleteMediaType (config);
  192302. }
  192303. }
  192304. }
  192305. }
  192306. bool selectVideoSize (IAMStreamConfig* const streamConfig,
  192307. const int minWidth, const int minHeight,
  192308. const int maxWidth, const int maxHeight)
  192309. {
  192310. int count = 0, size = 0, bestArea = 0, bestIndex = -1;
  192311. streamConfig->GetNumberOfCapabilities (&count, &size);
  192312. if (size == sizeof (VIDEO_STREAM_CONFIG_CAPS))
  192313. {
  192314. AM_MEDIA_TYPE* config;
  192315. VIDEO_STREAM_CONFIG_CAPS scc;
  192316. for (int i = 0; i < count; ++i)
  192317. {
  192318. HRESULT hr = streamConfig->GetStreamCaps (i, &config, (BYTE*) &scc);
  192319. if (SUCCEEDED (hr))
  192320. {
  192321. if (scc.InputSize.cx >= minWidth
  192322. && scc.InputSize.cy >= minHeight
  192323. && scc.InputSize.cx <= maxWidth
  192324. && scc.InputSize.cy <= maxHeight)
  192325. {
  192326. int area = scc.InputSize.cx * scc.InputSize.cy;
  192327. if (area > bestArea)
  192328. {
  192329. bestIndex = i;
  192330. bestArea = area;
  192331. }
  192332. }
  192333. deleteMediaType (config);
  192334. }
  192335. }
  192336. if (bestIndex >= 0)
  192337. {
  192338. HRESULT hr = streamConfig->GetStreamCaps (bestIndex, &config, (BYTE*) &scc);
  192339. hr = streamConfig->SetFormat (config);
  192340. deleteMediaType (config);
  192341. return SUCCEEDED (hr);
  192342. }
  192343. }
  192344. return false;
  192345. }
  192346. static bool getPin (IBaseFilter* filter, const PIN_DIRECTION wantedDirection, IPin** result, const char* pinName = 0)
  192347. {
  192348. ComSmartPtr <IEnumPins> enumerator;
  192349. ComSmartPtr <IPin> pin;
  192350. filter->EnumPins (&enumerator);
  192351. while (enumerator->Next (1, &pin, 0) == S_OK)
  192352. {
  192353. PIN_DIRECTION dir;
  192354. pin->QueryDirection (&dir);
  192355. if (wantedDirection == dir)
  192356. {
  192357. PIN_INFO info;
  192358. zerostruct (info);
  192359. pin->QueryPinInfo (&info);
  192360. if (pinName == 0 || String (pinName).equalsIgnoreCase (String (info.achName)))
  192361. {
  192362. pin.p->AddRef();
  192363. *result = pin;
  192364. return true;
  192365. }
  192366. }
  192367. }
  192368. return false;
  192369. }
  192370. bool connectFilters (IBaseFilter* const first, IBaseFilter* const second) const
  192371. {
  192372. ComSmartPtr <IPin> in, out;
  192373. return getPin (first, PINDIR_OUTPUT, &out)
  192374. && getPin (second, PINDIR_INPUT, &in)
  192375. && SUCCEEDED (graphBuilder->Connect (out, in));
  192376. }
  192377. bool addGraphToRot()
  192378. {
  192379. ComSmartPtr <IRunningObjectTable> rot;
  192380. if (FAILED (GetRunningObjectTable (0, &rot)))
  192381. return false;
  192382. ComSmartPtr <IMoniker> moniker;
  192383. WCHAR buffer[128];
  192384. HRESULT hr = CreateItemMoniker (_T("!"), buffer, &moniker);
  192385. if (FAILED (hr))
  192386. return false;
  192387. graphRegistrationID = 0;
  192388. return SUCCEEDED (rot->Register (0, graphBuilder, moniker, &graphRegistrationID));
  192389. }
  192390. void removeGraphFromRot()
  192391. {
  192392. ComSmartPtr <IRunningObjectTable> rot;
  192393. if (SUCCEEDED (GetRunningObjectTable (0, &rot)))
  192394. rot->Revoke (graphRegistrationID);
  192395. }
  192396. static void deleteMediaType (AM_MEDIA_TYPE* const pmt)
  192397. {
  192398. if (pmt->cbFormat != 0)
  192399. CoTaskMemFree ((PVOID) pmt->pbFormat);
  192400. if (pmt->pUnk != 0)
  192401. pmt->pUnk->Release();
  192402. CoTaskMemFree (pmt);
  192403. }
  192404. class GrabberCallback : public ISampleGrabberCB
  192405. {
  192406. public:
  192407. GrabberCallback (DShowCameraDeviceInteral& owner_)
  192408. : owner (owner_)
  192409. {
  192410. }
  192411. HRESULT __stdcall QueryInterface (REFIID id, void** result)
  192412. {
  192413. if (id == IID_IUnknown)
  192414. *result = dynamic_cast <IUnknown*> (this);
  192415. else if (id == IID_ISampleGrabberCB)
  192416. *result = dynamic_cast <ISampleGrabberCB*> (this);
  192417. else
  192418. {
  192419. *result = 0;
  192420. return E_NOINTERFACE;
  192421. }
  192422. AddRef();
  192423. return S_OK;
  192424. }
  192425. ULONG __stdcall AddRef() { return ++refCount; }
  192426. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  192427. STDMETHODIMP SampleCB (double /*SampleTime*/, IMediaSample* /*pSample*/)
  192428. {
  192429. return E_FAIL;
  192430. }
  192431. STDMETHODIMP BufferCB (double time, BYTE* buffer, long bufferSize)
  192432. {
  192433. owner.handleFrame (time, buffer, bufferSize);
  192434. return S_OK;
  192435. }
  192436. private:
  192437. int refCount;
  192438. DShowCameraDeviceInteral& owner;
  192439. GrabberCallback (const GrabberCallback&);
  192440. GrabberCallback& operator= (const GrabberCallback&);
  192441. };
  192442. ComSmartPtr <GrabberCallback> callback;
  192443. VoidArray listeners;
  192444. CriticalSection listenerLock;
  192445. DShowCameraDeviceInteral (const DShowCameraDeviceInteral&);
  192446. DShowCameraDeviceInteral& operator= (const DShowCameraDeviceInteral&);
  192447. };
  192448. CameraDevice::CameraDevice (const String& name_, int /*index*/)
  192449. : name (name_)
  192450. {
  192451. isRecording = false;
  192452. }
  192453. CameraDevice::~CameraDevice()
  192454. {
  192455. stopRecording();
  192456. delete (DShowCameraDeviceInteral*) internal;
  192457. internal = 0;
  192458. }
  192459. Component* CameraDevice::createViewerComponent()
  192460. {
  192461. return new DShowCameraDeviceInteral::DShowCaptureViewerComp ((DShowCameraDeviceInteral*) internal);
  192462. }
  192463. const String CameraDevice::getFileExtension()
  192464. {
  192465. return ".wmv";
  192466. }
  192467. void CameraDevice::startRecordingToFile (const File& file, int quality)
  192468. {
  192469. stopRecording();
  192470. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192471. d->addUser();
  192472. isRecording = d->createFileCaptureFilter (file);
  192473. }
  192474. const Time CameraDevice::getTimeOfFirstRecordedFrame() const
  192475. {
  192476. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192477. return d->firstRecordedTime;
  192478. }
  192479. void CameraDevice::stopRecording()
  192480. {
  192481. if (isRecording)
  192482. {
  192483. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192484. d->removeFileCaptureFilter();
  192485. d->removeUser();
  192486. isRecording = false;
  192487. }
  192488. }
  192489. void CameraDevice::addListener (CameraImageListener* listenerToAdd)
  192490. {
  192491. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192492. if (listenerToAdd != 0)
  192493. d->addListener (listenerToAdd);
  192494. }
  192495. void CameraDevice::removeListener (CameraImageListener* listenerToRemove)
  192496. {
  192497. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192498. if (listenerToRemove != 0)
  192499. d->removeListener (listenerToRemove);
  192500. }
  192501. static ComSmartPtr <IBaseFilter> enumerateCameras (StringArray* const names,
  192502. const int deviceIndexToOpen,
  192503. String& name)
  192504. {
  192505. int index = 0;
  192506. ComSmartPtr <IBaseFilter> result;
  192507. ComSmartPtr <ICreateDevEnum> pDevEnum;
  192508. HRESULT hr = pDevEnum.CoCreateInstance (CLSID_SystemDeviceEnum, CLSCTX_INPROC);
  192509. if (SUCCEEDED (hr))
  192510. {
  192511. ComSmartPtr <IEnumMoniker> enumerator;
  192512. hr = pDevEnum->CreateClassEnumerator (CLSID_VideoInputDeviceCategory, &enumerator, 0);
  192513. if (SUCCEEDED (hr) && enumerator != 0)
  192514. {
  192515. ComSmartPtr <IBaseFilter> captureFilter;
  192516. ComSmartPtr <IMoniker> moniker;
  192517. ULONG fetched;
  192518. while (enumerator->Next (1, &moniker, &fetched) == S_OK)
  192519. {
  192520. hr = moniker->BindToObject (0, 0, IID_IBaseFilter, (void**) &captureFilter);
  192521. if (SUCCEEDED (hr))
  192522. {
  192523. ComSmartPtr <IPropertyBag> propertyBag;
  192524. hr = moniker->BindToStorage (0, 0, IID_IPropertyBag, (void**) &propertyBag);
  192525. if (SUCCEEDED (hr))
  192526. {
  192527. VARIANT var;
  192528. var.vt = VT_BSTR;
  192529. hr = propertyBag->Read (_T("FriendlyName"), &var, 0);
  192530. propertyBag = 0;
  192531. if (SUCCEEDED (hr))
  192532. {
  192533. if (names != 0)
  192534. names->add (var.bstrVal);
  192535. if (index == deviceIndexToOpen)
  192536. {
  192537. name = var.bstrVal;
  192538. result = captureFilter;
  192539. captureFilter = 0;
  192540. break;
  192541. }
  192542. ++index;
  192543. }
  192544. moniker = 0;
  192545. }
  192546. captureFilter = 0;
  192547. }
  192548. }
  192549. }
  192550. }
  192551. return result;
  192552. }
  192553. const StringArray CameraDevice::getAvailableDevices()
  192554. {
  192555. StringArray devs;
  192556. String dummy;
  192557. enumerateCameras (&devs, -1, dummy);
  192558. return devs;
  192559. }
  192560. CameraDevice* CameraDevice::openDevice (int index,
  192561. int minWidth, int minHeight,
  192562. int maxWidth, int maxHeight)
  192563. {
  192564. ComSmartPtr <ICaptureGraphBuilder2> captureGraphBuilder;
  192565. HRESULT hr = captureGraphBuilder.CoCreateInstance (CLSID_CaptureGraphBuilder2, CLSCTX_INPROC);
  192566. if (SUCCEEDED (hr))
  192567. {
  192568. String name;
  192569. const ComSmartPtr <IBaseFilter> filter (enumerateCameras (0, index, name));
  192570. if (filter != 0)
  192571. {
  192572. CameraDevice* const cam = new CameraDevice (name, index);
  192573. DShowCameraDeviceInteral* const intern
  192574. = new DShowCameraDeviceInteral (cam, captureGraphBuilder, filter,
  192575. minWidth, minHeight, maxWidth, maxHeight);
  192576. cam->internal = intern;
  192577. if (intern->ok)
  192578. return cam;
  192579. else
  192580. delete cam;
  192581. }
  192582. }
  192583. return 0;
  192584. }
  192585. #endif
  192586. /*** End of inlined file: juce_win32_CameraDevice.cpp ***/
  192587. #endif
  192588. // Auto-link the other win32 libs that are needed by library calls..
  192589. #if (JUCE_AMALGAMATED_TEMPLATE || defined (JUCE_DLL_BUILD)) && JUCE_MSVC && ! DONT_AUTOLINK_TO_WIN32_LIBRARIES
  192590. /*** Start of inlined file: juce_win32_AutoLinkLibraries.h ***/
  192591. // Auto-links to various win32 libs that are needed by library calls..
  192592. #pragma comment(lib, "kernel32.lib")
  192593. #pragma comment(lib, "user32.lib")
  192594. #pragma comment(lib, "shell32.lib")
  192595. #pragma comment(lib, "gdi32.lib")
  192596. #pragma comment(lib, "vfw32.lib")
  192597. #pragma comment(lib, "comdlg32.lib")
  192598. #pragma comment(lib, "winmm.lib")
  192599. #pragma comment(lib, "wininet.lib")
  192600. #pragma comment(lib, "ole32.lib")
  192601. #pragma comment(lib, "oleaut32.lib")
  192602. #pragma comment(lib, "advapi32.lib")
  192603. #pragma comment(lib, "ws2_32.lib")
  192604. #pragma comment(lib, "comsupp.lib")
  192605. #pragma comment(lib, "version.lib")
  192606. #if JUCE_OPENGL
  192607. #pragma comment(lib, "OpenGL32.Lib")
  192608. #pragma comment(lib, "GlU32.Lib")
  192609. #endif
  192610. #if JUCE_QUICKTIME
  192611. #pragma comment (lib, "QTMLClient.lib")
  192612. #endif
  192613. #if JUCE_USE_CAMERA
  192614. #pragma comment (lib, "Strmiids.lib")
  192615. #pragma comment (lib, "wmvcore.lib")
  192616. #endif
  192617. /*** End of inlined file: juce_win32_AutoLinkLibraries.h ***/
  192618. #endif
  192619. END_JUCE_NAMESPACE
  192620. #endif
  192621. /*** End of inlined file: juce_win32_NativeCode.cpp ***/
  192622. #endif
  192623. #if JUCE_LINUX
  192624. /*** Start of inlined file: juce_linux_NativeCode.cpp ***/
  192625. #if JUCE_LINUX
  192626. BEGIN_JUCE_NAMESPACE
  192627. #if defined (CPU_ISSET) && ! defined (SUPPORT_AFFINITIES)
  192628. #define SUPPORT_AFFINITIES 1
  192629. #endif
  192630. #define JUCE_INCLUDED_FILE 1
  192631. // Now include the actual code files..
  192632. /*** Start of inlined file: juce_posix_SharedCode.h ***/
  192633. CriticalSection::CriticalSection() throw()
  192634. {
  192635. pthread_mutexattr_t atts;
  192636. pthread_mutexattr_init (&atts);
  192637. pthread_mutexattr_settype (&atts, PTHREAD_MUTEX_RECURSIVE);
  192638. pthread_mutex_init (&internal, &atts);
  192639. }
  192640. CriticalSection::~CriticalSection() throw()
  192641. {
  192642. pthread_mutex_destroy (&internal);
  192643. }
  192644. void CriticalSection::enter() const throw()
  192645. {
  192646. pthread_mutex_lock (&internal);
  192647. }
  192648. bool CriticalSection::tryEnter() const throw()
  192649. {
  192650. return pthread_mutex_trylock (&internal) == 0;
  192651. }
  192652. void CriticalSection::exit() const throw()
  192653. {
  192654. pthread_mutex_unlock (&internal);
  192655. }
  192656. struct EventStruct
  192657. {
  192658. pthread_cond_t condition;
  192659. pthread_mutex_t mutex;
  192660. bool triggered;
  192661. };
  192662. WaitableEvent::WaitableEvent() throw()
  192663. {
  192664. EventStruct* const es = new EventStruct();
  192665. es->triggered = false;
  192666. pthread_cond_init (&es->condition, 0);
  192667. pthread_mutex_init (&es->mutex, 0);
  192668. internal = es;
  192669. }
  192670. WaitableEvent::~WaitableEvent() throw()
  192671. {
  192672. EventStruct* const es = (EventStruct*) internal;
  192673. pthread_cond_destroy (&es->condition);
  192674. pthread_mutex_destroy (&es->mutex);
  192675. delete es;
  192676. }
  192677. bool WaitableEvent::wait (const int timeOutMillisecs) const throw()
  192678. {
  192679. EventStruct* const es = (EventStruct*) internal;
  192680. pthread_mutex_lock (&es->mutex);
  192681. if (timeOutMillisecs < 0)
  192682. {
  192683. while (! es->triggered)
  192684. pthread_cond_wait (&es->condition, &es->mutex);
  192685. }
  192686. else
  192687. {
  192688. while (! es->triggered)
  192689. {
  192690. struct timeval t;
  192691. gettimeofday (&t, 0);
  192692. struct timespec time;
  192693. time.tv_sec = t.tv_sec + (timeOutMillisecs / 1000);
  192694. time.tv_nsec = (t.tv_usec + ((timeOutMillisecs % 1000) * 1000)) * 1000;
  192695. if (time.tv_nsec >= 1000000000)
  192696. {
  192697. time.tv_nsec -= 1000000000;
  192698. time.tv_sec++;
  192699. }
  192700. if (pthread_cond_timedwait (&es->condition, &es->mutex, &time) == ETIMEDOUT)
  192701. {
  192702. pthread_mutex_unlock (&es->mutex);
  192703. return false;
  192704. }
  192705. }
  192706. }
  192707. es->triggered = false;
  192708. pthread_mutex_unlock (&es->mutex);
  192709. return true;
  192710. }
  192711. void WaitableEvent::signal() const throw()
  192712. {
  192713. EventStruct* const es = (EventStruct*) internal;
  192714. pthread_mutex_lock (&es->mutex);
  192715. es->triggered = true;
  192716. pthread_cond_broadcast (&es->condition);
  192717. pthread_mutex_unlock (&es->mutex);
  192718. }
  192719. void WaitableEvent::reset() const throw()
  192720. {
  192721. EventStruct* const es = (EventStruct*) internal;
  192722. pthread_mutex_lock (&es->mutex);
  192723. es->triggered = false;
  192724. pthread_mutex_unlock (&es->mutex);
  192725. }
  192726. void JUCE_CALLTYPE Thread::sleep (int millisecs)
  192727. {
  192728. struct timespec time;
  192729. time.tv_sec = millisecs / 1000;
  192730. time.tv_nsec = (millisecs % 1000) * 1000000;
  192731. nanosleep (&time, 0);
  192732. }
  192733. const tchar File::separator = T('/');
  192734. const tchar* File::separatorString = T("/");
  192735. const File File::getCurrentWorkingDirectory()
  192736. {
  192737. HeapBlock<char> heapBuffer;
  192738. char localBuffer [1024];
  192739. char* cwd = getcwd (localBuffer, sizeof (localBuffer) - 1);
  192740. int bufferSize = 4096;
  192741. while (cwd == 0 && errno == ERANGE)
  192742. {
  192743. heapBuffer.malloc (bufferSize);
  192744. cwd = getcwd (heapBuffer, bufferSize - 1);
  192745. bufferSize += 1024;
  192746. }
  192747. return File (String::fromUTF8 (cwd));
  192748. }
  192749. bool File::setAsCurrentWorkingDirectory() const
  192750. {
  192751. return chdir (getFullPathName().toUTF8()) == 0;
  192752. }
  192753. bool juce_copyFile (const String& s, const String& d);
  192754. static bool juce_stat (const String& fileName, struct stat& info)
  192755. {
  192756. return fileName.isNotEmpty()
  192757. && (stat (fileName.toUTF8(), &info) == 0);
  192758. }
  192759. bool juce_isDirectory (const String& fileName)
  192760. {
  192761. struct stat info;
  192762. return fileName.isEmpty()
  192763. || (juce_stat (fileName, info)
  192764. && ((info.st_mode & S_IFDIR) != 0));
  192765. }
  192766. bool juce_fileExists (const String& fileName, const bool dontCountDirectories)
  192767. {
  192768. if (fileName.isEmpty())
  192769. return false;
  192770. const char* const fileNameUTF8 = fileName.toUTF8();
  192771. bool exists = access (fileNameUTF8, F_OK) == 0;
  192772. if (exists && dontCountDirectories)
  192773. {
  192774. struct stat info;
  192775. const int res = stat (fileNameUTF8, &info);
  192776. if (res == 0 && (info.st_mode & S_IFDIR) != 0)
  192777. exists = false;
  192778. }
  192779. return exists;
  192780. }
  192781. int64 juce_getFileSize (const String& fileName)
  192782. {
  192783. struct stat info;
  192784. return juce_stat (fileName, info) ? info.st_size : 0;
  192785. }
  192786. bool juce_canWriteToFile (const String& fileName)
  192787. {
  192788. return access (fileName.toUTF8(), W_OK) == 0;
  192789. }
  192790. bool juce_deleteFile (const String& fileName)
  192791. {
  192792. if (juce_isDirectory (fileName))
  192793. return rmdir ((const char*) fileName.toUTF8()) == 0;
  192794. else
  192795. return remove ((const char*) fileName.toUTF8()) == 0;
  192796. }
  192797. bool juce_moveFile (const String& source, const String& dest)
  192798. {
  192799. if (rename (source.toUTF8(), dest.toUTF8()) == 0)
  192800. return true;
  192801. if (juce_canWriteToFile (source)
  192802. && juce_copyFile (source, dest))
  192803. {
  192804. if (juce_deleteFile (source))
  192805. return true;
  192806. juce_deleteFile (dest);
  192807. }
  192808. return false;
  192809. }
  192810. void juce_createDirectory (const String& fileName)
  192811. {
  192812. mkdir (fileName.toUTF8(), 0777);
  192813. }
  192814. void* juce_fileOpen (const String& fileName, bool forWriting)
  192815. {
  192816. int flags = O_RDONLY;
  192817. if (forWriting)
  192818. {
  192819. if (juce_fileExists (fileName, false))
  192820. {
  192821. const int f = open ((const char*) fileName.toUTF8(), O_RDWR, 00644);
  192822. if (f != -1)
  192823. lseek (f, 0, SEEK_END);
  192824. return (void*) f;
  192825. }
  192826. else
  192827. {
  192828. flags = O_RDWR + O_CREAT;
  192829. }
  192830. }
  192831. return (void*) open ((const char*) fileName.toUTF8(), flags, 00644);
  192832. }
  192833. void juce_fileClose (void* handle)
  192834. {
  192835. if (handle != 0)
  192836. close ((int) (pointer_sized_int) handle);
  192837. }
  192838. int juce_fileRead (void* handle, void* buffer, int size)
  192839. {
  192840. if (handle != 0)
  192841. return (int) read ((int) (pointer_sized_int) handle, buffer, size);
  192842. return 0;
  192843. }
  192844. int juce_fileWrite (void* handle, const void* buffer, int size)
  192845. {
  192846. if (handle != 0)
  192847. return (int) write ((int) (pointer_sized_int) handle, buffer, size);
  192848. return 0;
  192849. }
  192850. int64 juce_fileSetPosition (void* handle, int64 pos)
  192851. {
  192852. if (handle != 0 && lseek ((int) (pointer_sized_int) handle, pos, SEEK_SET) == pos)
  192853. return pos;
  192854. return -1;
  192855. }
  192856. int64 juce_fileGetPosition (void* handle)
  192857. {
  192858. if (handle != 0)
  192859. return lseek ((int) (pointer_sized_int) handle, 0, SEEK_CUR);
  192860. else
  192861. return -1;
  192862. }
  192863. void juce_fileFlush (void* handle)
  192864. {
  192865. if (handle != 0)
  192866. fsync ((int) (pointer_sized_int) handle);
  192867. }
  192868. const File juce_getExecutableFile()
  192869. {
  192870. Dl_info exeInfo;
  192871. dladdr ((const void*) juce_getExecutableFile, &exeInfo);
  192872. return File (String::fromUTF8 (exeInfo.dli_fname));
  192873. }
  192874. // if this file doesn't exist, find a parent of it that does..
  192875. static bool doStatFS (const File* file, struct statfs& result)
  192876. {
  192877. File f (*file);
  192878. for (int i = 5; --i >= 0;)
  192879. {
  192880. if (f.exists())
  192881. break;
  192882. f = f.getParentDirectory();
  192883. }
  192884. return statfs (f.getFullPathName().toUTF8(), &result) == 0;
  192885. }
  192886. int64 File::getBytesFreeOnVolume() const
  192887. {
  192888. struct statfs buf;
  192889. if (doStatFS (this, buf))
  192890. return (int64) buf.f_bsize * (int64) buf.f_bavail; // Note: this returns space available to non-super user
  192891. return 0;
  192892. }
  192893. int64 File::getVolumeTotalSize() const
  192894. {
  192895. struct statfs buf;
  192896. if (doStatFS (this, buf))
  192897. return (int64) buf.f_bsize * (int64) buf.f_blocks;
  192898. return 0;
  192899. }
  192900. const String juce_getVolumeLabel (const String& filenameOnVolume,
  192901. int& volumeSerialNumber)
  192902. {
  192903. volumeSerialNumber = 0;
  192904. #if JUCE_MAC
  192905. struct VolAttrBuf
  192906. {
  192907. u_int32_t length;
  192908. attrreference_t mountPointRef;
  192909. char mountPointSpace [MAXPATHLEN];
  192910. } attrBuf;
  192911. struct attrlist attrList;
  192912. zerostruct (attrList);
  192913. attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
  192914. attrList.volattr = ATTR_VOL_INFO | ATTR_VOL_NAME;
  192915. File f (filenameOnVolume);
  192916. for (;;)
  192917. {
  192918. if (getattrlist ((const char*) f.getFullPathName().toUTF8(),
  192919. &attrList, &attrBuf, sizeof(attrBuf), 0) == 0)
  192920. {
  192921. return String::fromUTF8 (((const char*) &attrBuf.mountPointRef) + attrBuf.mountPointRef.attr_dataoffset,
  192922. (int) attrBuf.mountPointRef.attr_length);
  192923. }
  192924. const File parent (f.getParentDirectory());
  192925. if (f == parent)
  192926. break;
  192927. f = parent;
  192928. }
  192929. #endif
  192930. return String::empty;
  192931. }
  192932. void juce_runSystemCommand (const String& command)
  192933. {
  192934. int result = system ((const char*) command.toUTF8());
  192935. (void) result;
  192936. }
  192937. const String juce_getOutputFromCommand (const String& command)
  192938. {
  192939. // slight bodge here, as we just pipe the output into a temp file and read it...
  192940. const File tempFile (File::getSpecialLocation (File::tempDirectory)
  192941. .getNonexistentChildFile (String::toHexString (Random::getSystemRandom().nextInt()), ".tmp", false));
  192942. juce_runSystemCommand (command + " > " + tempFile.getFullPathName());
  192943. String result (tempFile.loadFileAsString());
  192944. tempFile.deleteFile();
  192945. return result;
  192946. }
  192947. InterProcessLock::InterProcessLock (const String& name_)
  192948. : internal (0),
  192949. name (name_),
  192950. reentrancyLevel (0)
  192951. {
  192952. #if JUCE_MAC
  192953. // (don't use getSpecialLocation() to avoid the temp folder being different for each app)
  192954. const File temp (File (T("~/Library/Caches/Juce")).getChildFile (name));
  192955. #else
  192956. const File temp (File::getSpecialLocation (File::tempDirectory).getChildFile (name));
  192957. #endif
  192958. temp.create();
  192959. internal = open (temp.getFullPathName().toUTF8(), O_RDWR);
  192960. }
  192961. InterProcessLock::~InterProcessLock()
  192962. {
  192963. while (reentrancyLevel > 0)
  192964. this->exit();
  192965. close (internal);
  192966. }
  192967. bool InterProcessLock::enter (const int timeOutMillisecs)
  192968. {
  192969. if (internal == 0)
  192970. return false;
  192971. if (reentrancyLevel != 0)
  192972. return true;
  192973. const int64 endTime = Time::currentTimeMillis() + timeOutMillisecs;
  192974. struct flock fl;
  192975. zerostruct (fl);
  192976. fl.l_whence = SEEK_SET;
  192977. fl.l_type = F_WRLCK;
  192978. for (;;)
  192979. {
  192980. const int result = fcntl (internal, F_SETLK, &fl);
  192981. if (result >= 0)
  192982. {
  192983. ++reentrancyLevel;
  192984. return true;
  192985. }
  192986. if (errno != EINTR)
  192987. {
  192988. if (timeOutMillisecs == 0
  192989. || (timeOutMillisecs > 0 && Time::currentTimeMillis() >= endTime))
  192990. break;
  192991. Thread::sleep (10);
  192992. }
  192993. }
  192994. return false;
  192995. }
  192996. void InterProcessLock::exit()
  192997. {
  192998. if (reentrancyLevel > 0 && internal != 0)
  192999. {
  193000. --reentrancyLevel;
  193001. struct flock fl;
  193002. zerostruct (fl);
  193003. fl.l_whence = SEEK_SET;
  193004. fl.l_type = F_UNLCK;
  193005. for (;;)
  193006. {
  193007. const int result = fcntl (internal, F_SETLKW, &fl);
  193008. if (result >= 0 || errno != EINTR)
  193009. break;
  193010. }
  193011. }
  193012. }
  193013. /*** End of inlined file: juce_posix_SharedCode.h ***/
  193014. /*** Start of inlined file: juce_linux_Files.cpp ***/
  193015. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  193016. // compiled on its own).
  193017. #if JUCE_INCLUDED_FILE
  193018. static const short U_ISOFS_SUPER_MAGIC = 0x9660; // linux/iso_fs.h
  193019. static const short U_MSDOS_SUPER_MAGIC = 0x4d44; // linux/msdos_fs.h
  193020. static const short U_NFS_SUPER_MAGIC = 0x6969; // linux/nfs_fs.h
  193021. static const short U_SMB_SUPER_MAGIC = 0x517B; // linux/smb_fs.h
  193022. void juce_getFileTimes (const String& fileName,
  193023. int64& modificationTime,
  193024. int64& accessTime,
  193025. int64& creationTime)
  193026. {
  193027. modificationTime = 0;
  193028. accessTime = 0;
  193029. creationTime = 0;
  193030. struct stat info;
  193031. const int res = stat (fileName.toUTF8(), &info);
  193032. if (res == 0)
  193033. {
  193034. modificationTime = (int64) info.st_mtime * 1000;
  193035. accessTime = (int64) info.st_atime * 1000;
  193036. creationTime = (int64) info.st_ctime * 1000;
  193037. }
  193038. }
  193039. bool juce_setFileTimes (const String& fileName,
  193040. int64 modificationTime,
  193041. int64 accessTime,
  193042. int64 creationTime)
  193043. {
  193044. struct utimbuf times;
  193045. times.actime = (time_t) (accessTime / 1000);
  193046. times.modtime = (time_t) (modificationTime / 1000);
  193047. return utime (fileName.toUTF8(), &times) == 0;
  193048. }
  193049. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly)
  193050. {
  193051. struct stat info;
  193052. const int res = stat (fileName.toUTF8(), &info);
  193053. if (res != 0)
  193054. return false;
  193055. info.st_mode &= 0777; // Just permissions
  193056. if( isReadOnly )
  193057. info.st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
  193058. else
  193059. // Give everybody write permission?
  193060. info.st_mode |= S_IWUSR | S_IWGRP | S_IWOTH;
  193061. return chmod (fileName.toUTF8(), info.st_mode) == 0;
  193062. }
  193063. bool juce_copyFile (const String& s, const String& d)
  193064. {
  193065. const File source (s), dest (d);
  193066. FileInputStream* in = source.createInputStream();
  193067. bool ok = false;
  193068. if (in != 0)
  193069. {
  193070. if (dest.deleteFile())
  193071. {
  193072. FileOutputStream* const out = dest.createOutputStream();
  193073. if (out != 0)
  193074. {
  193075. const int bytesCopied = out->writeFromInputStream (*in, -1);
  193076. delete out;
  193077. ok = (bytesCopied == source.getSize());
  193078. if (! ok)
  193079. dest.deleteFile();
  193080. }
  193081. }
  193082. delete in;
  193083. }
  193084. return ok;
  193085. }
  193086. const StringArray juce_getFileSystemRoots()
  193087. {
  193088. StringArray s;
  193089. s.add (T("/"));
  193090. return s;
  193091. }
  193092. bool File::isOnCDRomDrive() const
  193093. {
  193094. struct statfs buf;
  193095. if (statfs (getFullPathName().toUTF8(), &buf) == 0)
  193096. return (buf.f_type == U_ISOFS_SUPER_MAGIC);
  193097. // Assume not if this fails for some reason
  193098. return false;
  193099. }
  193100. bool File::isOnHardDisk() const
  193101. {
  193102. struct statfs buf;
  193103. if (statfs (getFullPathName().toUTF8(), &buf) == 0)
  193104. {
  193105. switch (buf.f_type)
  193106. {
  193107. case U_ISOFS_SUPER_MAGIC: // CD-ROM
  193108. case U_MSDOS_SUPER_MAGIC: // Probably floppy (but could be mounted FAT filesystem)
  193109. case U_NFS_SUPER_MAGIC: // Network NFS
  193110. case U_SMB_SUPER_MAGIC: // Network Samba
  193111. return false;
  193112. default:
  193113. // Assume anything else is a hard-disk (but note it could
  193114. // be a RAM disk. There isn't a good way of determining
  193115. // this for sure)
  193116. return true;
  193117. }
  193118. }
  193119. // Assume so if this fails for some reason
  193120. return true;
  193121. }
  193122. bool File::isOnRemovableDrive() const
  193123. {
  193124. jassertfalse // xxx not implemented for linux!
  193125. return false;
  193126. }
  193127. bool File::isHidden() const
  193128. {
  193129. return getFileName().startsWithChar (T('.'));
  193130. }
  193131. const char* juce_Argv0 = 0; // referenced from juce_Application.cpp
  193132. const File File::getSpecialLocation (const SpecialLocationType type)
  193133. {
  193134. switch (type)
  193135. {
  193136. case userHomeDirectory:
  193137. {
  193138. const char* homeDir = getenv ("HOME");
  193139. if (homeDir == 0)
  193140. {
  193141. struct passwd* const pw = getpwuid (getuid());
  193142. if (pw != 0)
  193143. homeDir = pw->pw_dir;
  193144. }
  193145. return File (String::fromUTF8 (homeDir));
  193146. }
  193147. case userDocumentsDirectory:
  193148. case userMusicDirectory:
  193149. case userMoviesDirectory:
  193150. case userApplicationDataDirectory:
  193151. return File ("~");
  193152. case userDesktopDirectory:
  193153. return File ("~/Desktop");
  193154. case commonApplicationDataDirectory:
  193155. return File ("/var");
  193156. case globalApplicationsDirectory:
  193157. return File ("/usr");
  193158. case tempDirectory:
  193159. {
  193160. File tmp ("/var/tmp");
  193161. if (! tmp.isDirectory())
  193162. {
  193163. tmp = T("/tmp");
  193164. if (! tmp.isDirectory())
  193165. tmp = File::getCurrentWorkingDirectory();
  193166. }
  193167. return tmp;
  193168. }
  193169. case invokedExecutableFile:
  193170. if (juce_Argv0 != 0)
  193171. return File (String::fromUTF8 (juce_Argv0));
  193172. // deliberate fall-through...
  193173. case currentExecutableFile:
  193174. case currentApplicationFile:
  193175. return juce_getExecutableFile();
  193176. default:
  193177. jassertfalse // unknown type?
  193178. break;
  193179. }
  193180. return File::nonexistent;
  193181. }
  193182. const String File::getVersion() const
  193183. {
  193184. return String::empty; // xxx not yet implemented
  193185. }
  193186. const File File::getLinkedTarget() const
  193187. {
  193188. char buffer [4096];
  193189. size_t numChars = readlink (getFullPathName().toUTF8(),
  193190. buffer, sizeof (buffer));
  193191. if (numChars > 0 && numChars <= sizeof (buffer))
  193192. return File (String::fromUTF8 (buffer, (int) numChars));
  193193. return *this;
  193194. }
  193195. bool File::moveToTrash() const
  193196. {
  193197. if (! exists())
  193198. return true;
  193199. File trashCan (T("~/.Trash"));
  193200. if (! trashCan.isDirectory())
  193201. trashCan = T("~/.local/share/Trash/files");
  193202. if (! trashCan.isDirectory())
  193203. return false;
  193204. return moveFileTo (trashCan.getNonexistentChildFile (getFileNameWithoutExtension(),
  193205. getFileExtension()));
  193206. }
  193207. struct FindFileStruct
  193208. {
  193209. String parentDir, wildCard;
  193210. DIR* dir;
  193211. bool getNextMatch (String& result, bool* const isDir, bool* const isHidden, int64* const fileSize,
  193212. Time* const modTime, Time* const creationTime, bool* const isReadOnly)
  193213. {
  193214. const char* const wildcardUTF8 = wildCard.toUTF8();
  193215. for (;;)
  193216. {
  193217. struct dirent* const de = readdir (dir);
  193218. if (de == 0)
  193219. break;
  193220. if (fnmatch (wildcardUTF8, de->d_name, FNM_CASEFOLD) == 0)
  193221. {
  193222. result = String::fromUTF8 (de->d_name);
  193223. const String path (parentDir + result);
  193224. if (isDir != 0 || fileSize != 0)
  193225. {
  193226. struct stat info;
  193227. const bool statOk = (stat (path.toUTF8(), &info) == 0);
  193228. if (isDir != 0)
  193229. *isDir = path.isEmpty() || (statOk && ((info.st_mode & S_IFDIR) != 0));
  193230. if (isHidden != 0)
  193231. *isHidden = (de->d_name[0] == '.');
  193232. if (fileSize != 0)
  193233. *fileSize = statOk ? info.st_size : 0;
  193234. }
  193235. if (modTime != 0 || creationTime != 0)
  193236. {
  193237. int64 m, a, c;
  193238. juce_getFileTimes (path, m, a, c);
  193239. if (modTime != 0)
  193240. *modTime = m;
  193241. if (creationTime != 0)
  193242. *creationTime = c;
  193243. }
  193244. if (isReadOnly != 0)
  193245. *isReadOnly = ! juce_canWriteToFile (path);
  193246. return true;
  193247. }
  193248. }
  193249. return false;
  193250. }
  193251. };
  193252. // returns 0 on failure
  193253. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  193254. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime,
  193255. Time* creationTime, bool* isReadOnly)
  193256. {
  193257. DIR* d = opendir (directory.toUTF8());
  193258. if (d != 0)
  193259. {
  193260. FindFileStruct* ff = new FindFileStruct();
  193261. ff->parentDir = directory;
  193262. if (!ff->parentDir.endsWithChar (File::separator))
  193263. ff->parentDir += File::separator;
  193264. ff->wildCard = wildCard;
  193265. if (wildCard == T("*.*"))
  193266. ff->wildCard = T("*");
  193267. ff->dir = d;
  193268. if (ff->getNextMatch (firstResultFile, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly))
  193269. {
  193270. return ff;
  193271. }
  193272. else
  193273. {
  193274. firstResultFile = String::empty;
  193275. isDir = false;
  193276. isHidden = false;
  193277. closedir (d);
  193278. delete ff;
  193279. }
  193280. }
  193281. return 0;
  193282. }
  193283. bool juce_findFileNext (void* handle, String& resultFile,
  193284. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime, Time* creationTime, bool* isReadOnly)
  193285. {
  193286. FindFileStruct* const ff = (FindFileStruct*) handle;
  193287. if (ff != 0)
  193288. return ff->getNextMatch (resultFile, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly);
  193289. return false;
  193290. }
  193291. void juce_findFileClose (void* handle)
  193292. {
  193293. FindFileStruct* const ff = (FindFileStruct*) handle;
  193294. if (ff != 0)
  193295. {
  193296. closedir (ff->dir);
  193297. delete ff;
  193298. }
  193299. }
  193300. bool juce_launchFile (const String& fileName,
  193301. const String& parameters)
  193302. {
  193303. String cmdString (fileName.replace (T(" "), T("\\ "),false));
  193304. cmdString << " " << parameters;
  193305. if (URL::isProbablyAWebsiteURL (fileName)
  193306. || cmdString.startsWithIgnoreCase (T("file:"))
  193307. || URL::isProbablyAnEmailAddress (fileName))
  193308. {
  193309. // create a command that tries to launch a bunch of likely browsers
  193310. const char* const browserNames[] = { "xdg-open", "/etc/alternatives/x-www-browser", "firefox", "mozilla", "konqueror", "opera" };
  193311. StringArray cmdLines;
  193312. for (int i = 0; i < numElementsInArray (browserNames); ++i)
  193313. cmdLines.add (String (browserNames[i]) + T(" ") + cmdString.trim().quoted());
  193314. cmdString = cmdLines.joinIntoString (T(" || "));
  193315. }
  193316. const char* const argv[4] = { "/bin/sh", "-c", (const char*) cmdString.toUTF8(), 0 };
  193317. const int cpid = fork();
  193318. if (cpid == 0)
  193319. {
  193320. setsid();
  193321. // Child process
  193322. execve (argv[0], (char**) argv, environ);
  193323. exit (0);
  193324. }
  193325. return cpid >= 0;
  193326. }
  193327. void File::revealToUser() const
  193328. {
  193329. if (isDirectory())
  193330. startAsProcess();
  193331. else if (getParentDirectory().exists())
  193332. getParentDirectory().startAsProcess();
  193333. }
  193334. #endif
  193335. /*** End of inlined file: juce_linux_Files.cpp ***/
  193336. /*** Start of inlined file: juce_posix_NamedPipe.cpp ***/
  193337. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  193338. // compiled on its own).
  193339. #if JUCE_INCLUDED_FILE
  193340. struct NamedPipeInternal
  193341. {
  193342. String pipeInName, pipeOutName;
  193343. int pipeIn, pipeOut;
  193344. bool volatile createdPipe, blocked, stopReadOperation;
  193345. static void signalHandler (int) {}
  193346. };
  193347. void NamedPipe::cancelPendingReads()
  193348. {
  193349. while (internal != 0 && ((NamedPipeInternal*) internal)->blocked)
  193350. {
  193351. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193352. intern->stopReadOperation = true;
  193353. char buffer [1] = { 0 };
  193354. int bytesWritten = (int) ::write (intern->pipeIn, buffer, 1);
  193355. (void) bytesWritten;
  193356. int timeout = 2000;
  193357. while (intern->blocked && --timeout >= 0)
  193358. Thread::sleep (2);
  193359. intern->stopReadOperation = false;
  193360. }
  193361. }
  193362. void NamedPipe::close()
  193363. {
  193364. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193365. if (intern != 0)
  193366. {
  193367. internal = 0;
  193368. if (intern->pipeIn != -1)
  193369. ::close (intern->pipeIn);
  193370. if (intern->pipeOut != -1)
  193371. ::close (intern->pipeOut);
  193372. if (intern->createdPipe)
  193373. {
  193374. unlink (intern->pipeInName.toUTF8());
  193375. unlink (intern->pipeOutName.toUTF8());
  193376. }
  193377. delete intern;
  193378. }
  193379. }
  193380. bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
  193381. {
  193382. close();
  193383. NamedPipeInternal* const intern = new NamedPipeInternal();
  193384. internal = intern;
  193385. intern->createdPipe = createPipe;
  193386. intern->blocked = false;
  193387. intern->stopReadOperation = false;
  193388. signal (SIGPIPE, NamedPipeInternal::signalHandler);
  193389. siginterrupt (SIGPIPE, 1);
  193390. const String pipePath (T("/tmp/") + File::createLegalFileName (pipeName));
  193391. intern->pipeInName = pipePath + T("_in");
  193392. intern->pipeOutName = pipePath + T("_out");
  193393. intern->pipeIn = -1;
  193394. intern->pipeOut = -1;
  193395. if (createPipe)
  193396. {
  193397. if ((mkfifo (intern->pipeInName.toUTF8(), 0666) && errno != EEXIST)
  193398. || (mkfifo (intern->pipeOutName.toUTF8(), 0666) && errno != EEXIST))
  193399. {
  193400. delete intern;
  193401. internal = 0;
  193402. return false;
  193403. }
  193404. }
  193405. return true;
  193406. }
  193407. int NamedPipe::read (void* destBuffer, int maxBytesToRead, int /*timeOutMilliseconds*/)
  193408. {
  193409. int bytesRead = -1;
  193410. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193411. if (intern != 0)
  193412. {
  193413. intern->blocked = true;
  193414. if (intern->pipeIn == -1)
  193415. {
  193416. if (intern->createdPipe)
  193417. intern->pipeIn = ::open (intern->pipeInName.toUTF8(), O_RDWR);
  193418. else
  193419. intern->pipeIn = ::open (intern->pipeOutName.toUTF8(), O_RDWR);
  193420. if (intern->pipeIn == -1)
  193421. {
  193422. intern->blocked = false;
  193423. return -1;
  193424. }
  193425. }
  193426. bytesRead = 0;
  193427. char* p = (char*) destBuffer;
  193428. while (bytesRead < maxBytesToRead)
  193429. {
  193430. const int bytesThisTime = maxBytesToRead - bytesRead;
  193431. const int numRead = (int) ::read (intern->pipeIn, p, bytesThisTime);
  193432. if (numRead <= 0 || intern->stopReadOperation)
  193433. {
  193434. bytesRead = -1;
  193435. break;
  193436. }
  193437. bytesRead += numRead;
  193438. p += bytesRead;
  193439. }
  193440. intern->blocked = false;
  193441. }
  193442. return bytesRead;
  193443. }
  193444. int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
  193445. {
  193446. int bytesWritten = -1;
  193447. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193448. if (intern != 0)
  193449. {
  193450. if (intern->pipeOut == -1)
  193451. {
  193452. if (intern->createdPipe)
  193453. intern->pipeOut = ::open (intern->pipeOutName.toUTF8(), O_WRONLY);
  193454. else
  193455. intern->pipeOut = ::open (intern->pipeInName.toUTF8(), O_WRONLY);
  193456. if (intern->pipeOut == -1)
  193457. {
  193458. return -1;
  193459. }
  193460. }
  193461. const char* p = (const char*) sourceBuffer;
  193462. bytesWritten = 0;
  193463. const uint32 timeOutTime = Time::getMillisecondCounter() + timeOutMilliseconds;
  193464. while (bytesWritten < numBytesToWrite
  193465. && (timeOutMilliseconds < 0 || Time::getMillisecondCounter() < timeOutTime))
  193466. {
  193467. const int bytesThisTime = numBytesToWrite - bytesWritten;
  193468. const int numWritten = (int) ::write (intern->pipeOut, p, bytesThisTime);
  193469. if (numWritten <= 0)
  193470. {
  193471. bytesWritten = -1;
  193472. break;
  193473. }
  193474. bytesWritten += numWritten;
  193475. p += bytesWritten;
  193476. }
  193477. }
  193478. return bytesWritten;
  193479. }
  193480. #endif
  193481. /*** End of inlined file: juce_posix_NamedPipe.cpp ***/
  193482. /*** Start of inlined file: juce_linux_Network.cpp ***/
  193483. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  193484. // compiled on its own).
  193485. #if JUCE_INCLUDED_FILE
  193486. int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian)
  193487. {
  193488. int numResults = 0;
  193489. const int s = socket (AF_INET, SOCK_DGRAM, 0);
  193490. if (s != -1)
  193491. {
  193492. char buf [1024];
  193493. struct ifconf ifc;
  193494. ifc.ifc_len = sizeof (buf);
  193495. ifc.ifc_buf = buf;
  193496. ioctl (s, SIOCGIFCONF, &ifc);
  193497. for (unsigned int i = 0; i < ifc.ifc_len / sizeof (struct ifreq); ++i)
  193498. {
  193499. struct ifreq ifr;
  193500. strcpy (ifr.ifr_name, ifc.ifc_req[i].ifr_name);
  193501. if (ioctl (s, SIOCGIFFLAGS, &ifr) == 0
  193502. && (ifr.ifr_flags & IFF_LOOPBACK) == 0
  193503. && ioctl (s, SIOCGIFHWADDR, &ifr) == 0
  193504. && numResults < maxNum)
  193505. {
  193506. int64 a = 0;
  193507. for (int j = 6; --j >= 0;)
  193508. a = (a << 8) | (uint8) ifr.ifr_hwaddr.sa_data [littleEndian ? j : (5 - j)];
  193509. *addresses++ = a;
  193510. ++numResults;
  193511. }
  193512. }
  193513. close (s);
  193514. }
  193515. return numResults;
  193516. }
  193517. bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
  193518. const String& emailSubject,
  193519. const String& bodyText,
  193520. const StringArray& filesToAttach)
  193521. {
  193522. jassertfalse // xxx todo
  193523. return false;
  193524. }
  193525. class JUCE_HTTPSocketStream
  193526. {
  193527. public:
  193528. JUCE_HTTPSocketStream()
  193529. : readPosition (0),
  193530. socketHandle (-1),
  193531. levelsOfRedirection (0),
  193532. timeoutSeconds (15)
  193533. {
  193534. }
  193535. ~JUCE_HTTPSocketStream()
  193536. {
  193537. closeSocket();
  193538. }
  193539. bool open (const String& url,
  193540. const String& headers,
  193541. const MemoryBlock& postData,
  193542. const bool isPost,
  193543. URL::OpenStreamProgressCallback* callback,
  193544. void* callbackContext,
  193545. int timeOutMs)
  193546. {
  193547. closeSocket();
  193548. uint32 timeOutTime = Time::getMillisecondCounter();
  193549. if (timeOutMs == 0)
  193550. timeOutTime += 60000;
  193551. else if (timeOutMs < 0)
  193552. timeOutTime = 0xffffffff;
  193553. else
  193554. timeOutTime += timeOutMs;
  193555. String hostName, hostPath;
  193556. int hostPort;
  193557. if (! decomposeURL (url, hostName, hostPath, hostPort))
  193558. return false;
  193559. const struct hostent* host = 0;
  193560. int port = 0;
  193561. String proxyName, proxyPath;
  193562. int proxyPort = 0;
  193563. String proxyURL (getenv ("http_proxy"));
  193564. if (proxyURL.startsWithIgnoreCase (T("http://")))
  193565. {
  193566. if (! decomposeURL (proxyURL, proxyName, proxyPath, proxyPort))
  193567. return false;
  193568. host = gethostbyname ((const char*) proxyName.toUTF8());
  193569. port = proxyPort;
  193570. }
  193571. else
  193572. {
  193573. host = gethostbyname ((const char*) hostName.toUTF8());
  193574. port = hostPort;
  193575. }
  193576. if (host == 0)
  193577. return false;
  193578. struct sockaddr_in address;
  193579. zerostruct (address);
  193580. memcpy ((void*) &address.sin_addr, (const void*) host->h_addr, host->h_length);
  193581. address.sin_family = host->h_addrtype;
  193582. address.sin_port = htons (port);
  193583. socketHandle = socket (host->h_addrtype, SOCK_STREAM, 0);
  193584. if (socketHandle == -1)
  193585. return false;
  193586. int receiveBufferSize = 16384;
  193587. setsockopt (socketHandle, SOL_SOCKET, SO_RCVBUF, (char*) &receiveBufferSize, sizeof (receiveBufferSize));
  193588. setsockopt (socketHandle, SOL_SOCKET, SO_KEEPALIVE, 0, 0);
  193589. #if JUCE_MAC
  193590. setsockopt (socketHandle, SOL_SOCKET, SO_NOSIGPIPE, 0, 0);
  193591. #endif
  193592. if (connect (socketHandle, (struct sockaddr*) &address, sizeof (address)) == -1)
  193593. {
  193594. closeSocket();
  193595. return false;
  193596. }
  193597. const MemoryBlock requestHeader (createRequestHeader (hostName, hostPort,
  193598. proxyName, proxyPort,
  193599. hostPath, url,
  193600. headers, postData,
  193601. isPost));
  193602. size_t totalHeaderSent = 0;
  193603. while (totalHeaderSent < requestHeader.getSize())
  193604. {
  193605. if (Time::getMillisecondCounter() > timeOutTime)
  193606. {
  193607. closeSocket();
  193608. return false;
  193609. }
  193610. const int numToSend = jmin (1024, (int) (requestHeader.getSize() - totalHeaderSent));
  193611. if (send (socketHandle,
  193612. ((const char*) requestHeader.getData()) + totalHeaderSent,
  193613. numToSend, 0)
  193614. != numToSend)
  193615. {
  193616. closeSocket();
  193617. return false;
  193618. }
  193619. totalHeaderSent += numToSend;
  193620. if (callback != 0 && ! callback (callbackContext, totalHeaderSent, requestHeader.getSize()))
  193621. {
  193622. closeSocket();
  193623. return false;
  193624. }
  193625. }
  193626. const String responseHeader (readResponse (timeOutTime));
  193627. if (responseHeader.isNotEmpty())
  193628. {
  193629. //DBG (responseHeader);
  193630. StringArray lines;
  193631. lines.addLines (responseHeader);
  193632. // NB - using charToString() here instead of just T(" "), because that was
  193633. // causing a mysterious gcc internal compiler error...
  193634. const int statusCode = responseHeader.fromFirstOccurrenceOf (String::charToString (T(' ')), false, false)
  193635. .substring (0, 3).getIntValue();
  193636. //int contentLength = findHeaderItem (lines, T("Content-Length:")).getIntValue();
  193637. //bool isChunked = findHeaderItem (lines, T("Transfer-Encoding:")).equalsIgnoreCase ("chunked");
  193638. String location (findHeaderItem (lines, T("Location:")));
  193639. if (statusCode >= 300 && statusCode < 400
  193640. && location.isNotEmpty())
  193641. {
  193642. if (! location.startsWithIgnoreCase (T("http://")))
  193643. location = T("http://") + location;
  193644. if (levelsOfRedirection++ < 3)
  193645. return open (location, headers, postData, isPost, callback, callbackContext, timeOutMs);
  193646. }
  193647. else
  193648. {
  193649. levelsOfRedirection = 0;
  193650. return true;
  193651. }
  193652. }
  193653. closeSocket();
  193654. return false;
  193655. }
  193656. int read (void* buffer, int bytesToRead)
  193657. {
  193658. fd_set readbits;
  193659. FD_ZERO (&readbits);
  193660. FD_SET (socketHandle, &readbits);
  193661. struct timeval tv;
  193662. tv.tv_sec = timeoutSeconds;
  193663. tv.tv_usec = 0;
  193664. if (select (socketHandle + 1, &readbits, 0, 0, &tv) <= 0)
  193665. return 0; // (timeout)
  193666. const int bytesRead = jmax (0, (int) recv (socketHandle, buffer, bytesToRead, MSG_WAITALL));
  193667. readPosition += bytesRead;
  193668. return bytesRead;
  193669. }
  193670. int readPosition;
  193671. juce_UseDebuggingNewOperator
  193672. private:
  193673. int socketHandle, levelsOfRedirection;
  193674. const int timeoutSeconds;
  193675. void closeSocket()
  193676. {
  193677. if (socketHandle >= 0)
  193678. close (socketHandle);
  193679. socketHandle = -1;
  193680. }
  193681. const MemoryBlock createRequestHeader (const String& hostName,
  193682. const int hostPort,
  193683. const String& proxyName,
  193684. const int proxyPort,
  193685. const String& hostPath,
  193686. const String& originalURL,
  193687. const String& headers,
  193688. const MemoryBlock& postData,
  193689. const bool isPost)
  193690. {
  193691. String header (isPost ? "POST " : "GET ");
  193692. if (proxyName.isEmpty())
  193693. {
  193694. header << hostPath << " HTTP/1.0\r\nHost: "
  193695. << hostName << ':' << hostPort;
  193696. }
  193697. else
  193698. {
  193699. header << originalURL << " HTTP/1.0\r\nHost: "
  193700. << proxyName << ':' << proxyPort;
  193701. }
  193702. header << "\r\nUser-Agent: JUCE/"
  193703. << JUCE_MAJOR_VERSION << '.' << JUCE_MINOR_VERSION
  193704. << "\r\nConnection: Close\r\nContent-Length: "
  193705. << postData.getSize() << "\r\n"
  193706. << headers << "\r\n";
  193707. MemoryBlock mb;
  193708. mb.append (header.toUTF8(), (int) strlen (header.toUTF8()));
  193709. mb.append (postData.getData(), postData.getSize());
  193710. return mb;
  193711. }
  193712. const String readResponse (const uint32 timeOutTime)
  193713. {
  193714. int bytesRead = 0, numConsecutiveLFs = 0;
  193715. MemoryBlock buffer (1024, true);
  193716. while (numConsecutiveLFs < 2 && bytesRead < 32768
  193717. && Time::getMillisecondCounter() <= timeOutTime)
  193718. {
  193719. fd_set readbits;
  193720. FD_ZERO (&readbits);
  193721. FD_SET (socketHandle, &readbits);
  193722. struct timeval tv;
  193723. tv.tv_sec = timeoutSeconds;
  193724. tv.tv_usec = 0;
  193725. if (select (socketHandle + 1, &readbits, 0, 0, &tv) <= 0)
  193726. return String::empty; // (timeout)
  193727. buffer.ensureSize (bytesRead + 8, true);
  193728. char* const dest = (char*) buffer.getData() + bytesRead;
  193729. if (recv (socketHandle, dest, 1, 0) == -1)
  193730. return String::empty;
  193731. const char lastByte = *dest;
  193732. ++bytesRead;
  193733. if (lastByte == '\n')
  193734. ++numConsecutiveLFs;
  193735. else if (lastByte != '\r')
  193736. numConsecutiveLFs = 0;
  193737. }
  193738. const String header (String::fromUTF8 ((const char*) buffer.getData()));
  193739. if (header.startsWithIgnoreCase (T("HTTP/")))
  193740. return header.trimEnd();
  193741. return String::empty;
  193742. }
  193743. static bool decomposeURL (const String& url,
  193744. String& host, String& path, int& port)
  193745. {
  193746. if (! url.startsWithIgnoreCase (T("http://")))
  193747. return false;
  193748. const int nextSlash = url.indexOfChar (7, '/');
  193749. int nextColon = url.indexOfChar (7, ':');
  193750. if (nextColon > nextSlash && nextSlash > 0)
  193751. nextColon = -1;
  193752. if (nextColon >= 0)
  193753. {
  193754. host = url.substring (7, nextColon);
  193755. if (nextSlash >= 0)
  193756. port = url.substring (nextColon + 1, nextSlash).getIntValue();
  193757. else
  193758. port = url.substring (nextColon + 1).getIntValue();
  193759. }
  193760. else
  193761. {
  193762. port = 80;
  193763. if (nextSlash >= 0)
  193764. host = url.substring (7, nextSlash);
  193765. else
  193766. host = url.substring (7);
  193767. }
  193768. if (nextSlash >= 0)
  193769. path = url.substring (nextSlash);
  193770. else
  193771. path = T("/");
  193772. return true;
  193773. }
  193774. static const String findHeaderItem (const StringArray& lines, const String& itemName)
  193775. {
  193776. for (int i = 0; i < lines.size(); ++i)
  193777. if (lines[i].startsWithIgnoreCase (itemName))
  193778. return lines[i].substring (itemName.length()).trim();
  193779. return String::empty;
  193780. }
  193781. };
  193782. bool juce_isOnLine()
  193783. {
  193784. return true;
  193785. }
  193786. void* juce_openInternetFile (const String& url,
  193787. const String& headers,
  193788. const MemoryBlock& postData,
  193789. const bool isPost,
  193790. URL::OpenStreamProgressCallback* callback,
  193791. void* callbackContext,
  193792. int timeOutMs)
  193793. {
  193794. JUCE_HTTPSocketStream* const s = new JUCE_HTTPSocketStream();
  193795. if (s->open (url, headers, postData, isPost,
  193796. callback, callbackContext, timeOutMs))
  193797. return s;
  193798. delete s;
  193799. return 0;
  193800. }
  193801. void juce_closeInternetFile (void* handle)
  193802. {
  193803. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  193804. if (s != 0)
  193805. delete s;
  193806. }
  193807. int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead)
  193808. {
  193809. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  193810. if (s != 0)
  193811. return s->read (buffer, bytesToRead);
  193812. return 0;
  193813. }
  193814. int64 juce_getInternetFileContentLength (void* handle)
  193815. {
  193816. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  193817. if (s != 0)
  193818. {
  193819. //xxx todo
  193820. jassertfalse
  193821. }
  193822. return -1;
  193823. }
  193824. int juce_seekInInternetFile (void* handle, int newPosition)
  193825. {
  193826. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  193827. if (s != 0)
  193828. return s->readPosition;
  193829. return 0;
  193830. }
  193831. #endif
  193832. /*** End of inlined file: juce_linux_Network.cpp ***/
  193833. /*** Start of inlined file: juce_linux_SystemStats.cpp ***/
  193834. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  193835. // compiled on its own).
  193836. #if JUCE_INCLUDED_FILE
  193837. void Logger::outputDebugString (const String& text) throw()
  193838. {
  193839. std::cerr << text << std::endl;
  193840. }
  193841. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  193842. {
  193843. return Linux;
  193844. }
  193845. const String SystemStats::getOperatingSystemName() throw()
  193846. {
  193847. return T("Linux");
  193848. }
  193849. bool SystemStats::isOperatingSystem64Bit() throw()
  193850. {
  193851. #if JUCE_64BIT
  193852. return true;
  193853. #else
  193854. //xxx not sure how to find this out?..
  193855. return false;
  193856. #endif
  193857. }
  193858. static const String getCpuInfo (const char* key, bool lastOne = false) throw()
  193859. {
  193860. String info;
  193861. char buf [256];
  193862. FILE* f = fopen ("/proc/cpuinfo", "r");
  193863. while (f != 0 && fgets (buf, sizeof(buf), f))
  193864. {
  193865. if (strncmp (buf, key, strlen (key)) == 0)
  193866. {
  193867. char* p = buf;
  193868. while (*p && *p != '\n')
  193869. ++p;
  193870. if (*p != 0)
  193871. *p = 0;
  193872. p = buf;
  193873. while (*p != 0 && *p != ':')
  193874. ++p;
  193875. if (*p != 0 && *(p + 1) != 0)
  193876. info = p + 2;
  193877. if (! lastOne)
  193878. break;
  193879. }
  193880. }
  193881. fclose (f);
  193882. return info;
  193883. }
  193884. bool SystemStats::hasMMX() throw()
  193885. {
  193886. return getCpuInfo ("flags").contains (T("mmx"));
  193887. }
  193888. bool SystemStats::hasSSE() throw()
  193889. {
  193890. return getCpuInfo ("flags").contains (T("sse"));
  193891. }
  193892. bool SystemStats::hasSSE2() throw()
  193893. {
  193894. return getCpuInfo ("flags").contains (T("sse2"));
  193895. }
  193896. bool SystemStats::has3DNow() throw()
  193897. {
  193898. return getCpuInfo ("flags").contains (T("3dnow"));
  193899. }
  193900. const String SystemStats::getCpuVendor() throw()
  193901. {
  193902. return getCpuInfo ("vendor_id");
  193903. }
  193904. int SystemStats::getCpuSpeedInMegaherz() throw()
  193905. {
  193906. const String speed (getCpuInfo ("cpu MHz"));
  193907. return (int) (speed.getFloatValue() + 0.5f);
  193908. }
  193909. int SystemStats::getMemorySizeInMegabytes() throw()
  193910. {
  193911. struct sysinfo sysi;
  193912. if (sysinfo (&sysi) == 0)
  193913. return (sysi.totalram * sysi.mem_unit / (1024 * 1024));
  193914. return 0;
  193915. }
  193916. uint32 juce_millisecondsSinceStartup() throw()
  193917. {
  193918. static unsigned int calibrate = 0;
  193919. static bool calibrated = false;
  193920. timeval t;
  193921. unsigned int ret = 0;
  193922. if (! gettimeofday (&t, 0))
  193923. {
  193924. if (! calibrated)
  193925. {
  193926. struct sysinfo sysi;
  193927. if (sysinfo (&sysi) == 0)
  193928. // Safe to assume system was not brought up earlier than 1970!
  193929. calibrate = t.tv_sec - sysi.uptime;
  193930. calibrated = true;
  193931. }
  193932. ret = 1000 * (t.tv_sec - calibrate) + (t.tv_usec / 1000);
  193933. }
  193934. return ret;
  193935. }
  193936. double Time::getMillisecondCounterHiRes() throw()
  193937. {
  193938. return getHighResolutionTicks() * 0.001;
  193939. }
  193940. int64 Time::getHighResolutionTicks() throw()
  193941. {
  193942. timeval t;
  193943. if (gettimeofday (&t, 0))
  193944. return 0;
  193945. return ((int64) t.tv_sec * (int64) 1000000) + (int64) t.tv_usec;
  193946. }
  193947. int64 Time::getHighResolutionTicksPerSecond() throw()
  193948. {
  193949. // Microseconds
  193950. return 1000000;
  193951. }
  193952. bool Time::setSystemTimeToThisTime() const throw()
  193953. {
  193954. timeval t;
  193955. t.tv_sec = millisSinceEpoch % 1000000;
  193956. t.tv_usec = millisSinceEpoch - t.tv_sec;
  193957. return settimeofday (&t, NULL) ? false : true;
  193958. }
  193959. int SystemStats::getPageSize() throw()
  193960. {
  193961. static int systemPageSize = 0;
  193962. if (systemPageSize == 0)
  193963. systemPageSize = sysconf (_SC_PAGESIZE);
  193964. return systemPageSize;
  193965. }
  193966. int SystemStats::getNumCpus() throw()
  193967. {
  193968. const int lastCpu = getCpuInfo ("processor", true).getIntValue();
  193969. return lastCpu + 1;
  193970. }
  193971. const String SystemStats::getLogonName()
  193972. {
  193973. const char* user = getenv ("USER");
  193974. if (user == 0)
  193975. {
  193976. struct passwd* const pw = getpwuid (getuid());
  193977. if (pw != 0)
  193978. user = pw->pw_name;
  193979. }
  193980. return String::fromUTF8 (user);
  193981. }
  193982. const String SystemStats::getFullUserName()
  193983. {
  193984. return getLogonName();
  193985. }
  193986. void SystemStats::initialiseStats() throw()
  193987. {
  193988. // Process starts off as root when running suid
  193989. Process::lowerPrivilege();
  193990. String s (SystemStats::getJUCEVersion());
  193991. }
  193992. void PlatformUtilities::fpuReset()
  193993. {
  193994. }
  193995. #endif
  193996. /*** End of inlined file: juce_linux_SystemStats.cpp ***/
  193997. /*** Start of inlined file: juce_linux_Threads.cpp ***/
  193998. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  193999. // compiled on its own).
  194000. #if JUCE_INCLUDED_FILE
  194001. void JUCE_API juce_threadEntryPoint (void*);
  194002. void* threadEntryProc (void* value)
  194003. {
  194004. // New threads start off as root when running suid
  194005. Process::lowerPrivilege();
  194006. juce_threadEntryPoint (value);
  194007. return 0;
  194008. }
  194009. void* juce_createThread (void* userData)
  194010. {
  194011. pthread_t handle = 0;
  194012. if (pthread_create (&handle, 0, threadEntryProc, userData) == 0)
  194013. {
  194014. pthread_detach (handle);
  194015. return (void*)handle;
  194016. }
  194017. return 0;
  194018. }
  194019. void juce_killThread (void* handle)
  194020. {
  194021. if (handle != 0)
  194022. pthread_cancel ((pthread_t)handle);
  194023. }
  194024. void juce_setCurrentThreadName (const String& /*name*/)
  194025. {
  194026. }
  194027. Thread::ThreadID Thread::getCurrentThreadId()
  194028. {
  194029. return (ThreadID) pthread_self();
  194030. }
  194031. // priority 1 to 10 where 5=normal, 1=low. If the handle is 0, sets the
  194032. // priority of the current thread
  194033. bool juce_setThreadPriority (void* handle, int priority)
  194034. {
  194035. struct sched_param param;
  194036. int policy, maxp, minp, pri;
  194037. if (handle == 0)
  194038. handle = (void*) pthread_self();
  194039. if (pthread_getschedparam ((pthread_t) handle, &policy, &param) == 0
  194040. && policy != SCHED_OTHER)
  194041. {
  194042. minp = sched_get_priority_min(policy);
  194043. maxp = sched_get_priority_max(policy);
  194044. pri = ((maxp - minp) / 2) * (priority - 1) / 9;
  194045. if (param.__sched_priority >= (minp + (maxp - minp) / 2))
  194046. // Realtime process priority
  194047. param.__sched_priority = minp + ((maxp - minp) / 2) + pri;
  194048. else
  194049. // High process priority
  194050. param.__sched_priority = minp + pri;
  194051. param.sched_priority = jlimit (1, 127, 1 + (priority * 126) / 11);
  194052. return pthread_setschedparam ((pthread_t) handle, policy, &param) == 0;
  194053. }
  194054. return false;
  194055. }
  194056. void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
  194057. {
  194058. #if SUPPORT_AFFINITIES
  194059. cpu_set_t affinity;
  194060. CPU_ZERO (&affinity);
  194061. for (int i = 0; i < 32; ++i)
  194062. if ((affinityMask & (1 << i)) != 0)
  194063. CPU_SET (i, &affinity);
  194064. sched_setaffinity (getpid(), sizeof (cpu_set_t), &affinity);
  194065. sched_yield();
  194066. #else
  194067. /* affinities aren't supported because either the appropriate header files weren't found,
  194068. or the SUPPORT_AFFINITIES macro was turned off in linuxheaders.h
  194069. */
  194070. jassertfalse
  194071. #endif
  194072. }
  194073. void Thread::yield()
  194074. {
  194075. sched_yield();
  194076. }
  194077. // sets the process to 0=low priority, 1=normal, 2=high, 3=realtime
  194078. void Process::setPriority (ProcessPriority prior)
  194079. {
  194080. struct sched_param param;
  194081. int policy, maxp, minp;
  194082. const int p = (int) prior;
  194083. if (p <= 1)
  194084. policy = SCHED_OTHER;
  194085. else
  194086. policy = SCHED_RR;
  194087. minp = sched_get_priority_min (policy);
  194088. maxp = sched_get_priority_max (policy);
  194089. if (p < 2)
  194090. param.__sched_priority = 0;
  194091. else if (p == 2 )
  194092. // Set to middle of lower realtime priority range
  194093. param.__sched_priority = minp + (maxp - minp) / 4;
  194094. else
  194095. // Set to middle of higher realtime priority range
  194096. param.__sched_priority = minp + (3 * (maxp - minp) / 4);
  194097. pthread_setschedparam (pthread_self(), policy, &param);
  194098. }
  194099. void Process::terminate()
  194100. {
  194101. exit (0);
  194102. }
  194103. bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger()
  194104. {
  194105. static char testResult = 0;
  194106. if (testResult == 0)
  194107. {
  194108. testResult = (char) ptrace (PT_TRACE_ME, 0, 0, 0);
  194109. if (testResult >= 0)
  194110. {
  194111. ptrace (PT_DETACH, 0, (caddr_t) 1, 0);
  194112. testResult = 1;
  194113. }
  194114. }
  194115. return testResult < 0;
  194116. }
  194117. bool JUCE_CALLTYPE Process::isRunningUnderDebugger()
  194118. {
  194119. return juce_isRunningUnderDebugger();
  194120. }
  194121. void Process::raisePrivilege()
  194122. {
  194123. // If running suid root, change effective user
  194124. // to root
  194125. if (geteuid() != 0 && getuid() == 0)
  194126. {
  194127. setreuid (geteuid(), getuid());
  194128. setregid (getegid(), getgid());
  194129. }
  194130. }
  194131. void Process::lowerPrivilege()
  194132. {
  194133. // If runing suid root, change effective user
  194134. // back to real user
  194135. if (geteuid() == 0 && getuid() != 0)
  194136. {
  194137. setreuid (geteuid(), getuid());
  194138. setregid (getegid(), getgid());
  194139. }
  194140. }
  194141. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  194142. void* PlatformUtilities::loadDynamicLibrary (const String& name)
  194143. {
  194144. return dlopen ((const char*) name.toUTF8(), RTLD_LOCAL | RTLD_NOW);
  194145. }
  194146. void PlatformUtilities::freeDynamicLibrary (void* handle)
  194147. {
  194148. dlclose(handle);
  194149. }
  194150. void* PlatformUtilities::getProcedureEntryPoint (void* libraryHandle, const String& procedureName)
  194151. {
  194152. return dlsym (libraryHandle, procedureName.toCString());
  194153. }
  194154. #endif
  194155. #endif
  194156. /*** End of inlined file: juce_linux_Threads.cpp ***/
  194157. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  194158. /*** Start of inlined file: juce_linux_Clipboard.cpp ***/
  194159. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194160. // compiled on its own).
  194161. #if JUCE_INCLUDED_FILE
  194162. #ifdef JUCE_DEBUG
  194163. #define JUCE_DEBUG_XERRORS 1
  194164. #endif
  194165. extern Display* display;
  194166. extern Window juce_messageWindowHandle;
  194167. static String localClipboardContent;
  194168. static Atom atom_UTF8_STRING;
  194169. static Atom atom_CLIPBOARD;
  194170. static Atom atom_TARGETS;
  194171. static void initSelectionAtoms()
  194172. {
  194173. static bool isInitialised = false;
  194174. if (! isInitialised)
  194175. {
  194176. atom_UTF8_STRING = XInternAtom (display, "UTF8_STRING", False);
  194177. atom_CLIPBOARD = XInternAtom (display, "CLIPBOARD", False);
  194178. atom_TARGETS = XInternAtom (display, "TARGETS", False);
  194179. }
  194180. }
  194181. // Read the content of a window property as either a locale-dependent string or an utf8 string
  194182. // works only for strings shorter than 1000000 bytes
  194183. static String juce_readWindowProperty (Window window, Atom prop,
  194184. Atom fmt, // XA_STRING or UTF8_STRING
  194185. bool deleteAfterReading)
  194186. {
  194187. String returnData;
  194188. char* clipData;
  194189. Atom actualType;
  194190. int actualFormat;
  194191. unsigned long numItems, bytesLeft;
  194192. if (XGetWindowProperty (display, window, prop,
  194193. 0L /* offset */, 1000000 /* length (max) */, False,
  194194. AnyPropertyType /* format */,
  194195. &actualType, &actualFormat, &numItems, &bytesLeft,
  194196. (unsigned char**) &clipData) == Success)
  194197. {
  194198. if (actualType == atom_UTF8_STRING && actualFormat == 8)
  194199. {
  194200. returnData = String::fromUTF8 (clipData, numItems);
  194201. }
  194202. else if (actualType == XA_STRING && actualFormat == 8)
  194203. {
  194204. returnData = String (clipData, numItems);
  194205. }
  194206. if (clipData != 0)
  194207. XFree (clipData);
  194208. jassert (bytesLeft == 0 || numItems == 1000000);
  194209. }
  194210. if (deleteAfterReading)
  194211. XDeleteProperty (display, window, prop);
  194212. return returnData;
  194213. }
  194214. // Send a SelectionRequest to the window owning the selection and waits for its answer (with a timeout) */
  194215. static bool juce_requestSelectionContent (String &selection_content, Atom selection, Atom requested_format)
  194216. {
  194217. Atom property_name = XInternAtom (display, "JUCE_SEL", false);
  194218. // The selection owner will be asked to set the JUCE_SEL property on the
  194219. // juce_messageWindowHandle with the selection content
  194220. XConvertSelection (display, selection, requested_format, property_name,
  194221. juce_messageWindowHandle, CurrentTime);
  194222. int timeoutMs = 200; // will wait at most for 200 ms
  194223. do
  194224. {
  194225. XEvent event;
  194226. if (XCheckTypedWindowEvent (display, juce_messageWindowHandle, SelectionNotify, &event))
  194227. {
  194228. if (event.xselection.property == property_name)
  194229. {
  194230. jassert (event.xselection.requestor == juce_messageWindowHandle);
  194231. selection_content = juce_readWindowProperty (event.xselection.requestor,
  194232. event.xselection.property,
  194233. requested_format, true);
  194234. return true;
  194235. }
  194236. else
  194237. {
  194238. return false; // the format we asked for was denied.. (event.xselection.property == None)
  194239. }
  194240. }
  194241. // not very elegant.. we could do a select() or something like that...
  194242. // however clipboard content requesting is inherently slow on x11, it
  194243. // often takes 50ms or more so...
  194244. Thread::sleep (4);
  194245. timeoutMs -= 4;
  194246. }
  194247. while (timeoutMs > 0);
  194248. DBG("timeout for juce_requestSelectionContent");
  194249. return false;
  194250. }
  194251. // Called from the event loop in juce_linux_Messaging in response to SelectionRequest events
  194252. void juce_handleSelectionRequest (XSelectionRequestEvent &evt)
  194253. {
  194254. initSelectionAtoms();
  194255. // the selection content is sent to the target window as a window property
  194256. XSelectionEvent reply;
  194257. reply.type = SelectionNotify;
  194258. reply.display = evt.display;
  194259. reply.requestor = evt.requestor;
  194260. reply.selection = evt.selection;
  194261. reply.target = evt.target;
  194262. reply.property = None; // == "fail"
  194263. reply.time = evt.time;
  194264. HeapBlock <char> data;
  194265. int propertyFormat = 0, numDataItems = 0;
  194266. if (evt.selection == XA_PRIMARY || evt.selection == atom_CLIPBOARD)
  194267. {
  194268. if (evt.target == XA_STRING)
  194269. {
  194270. // format data according to system locale
  194271. numDataItems = localClipboardContent.getNumBytesAsCString() + 1;
  194272. data.calloc (numDataItems + 1);
  194273. localClipboardContent.copyToCString (data, numDataItems);
  194274. propertyFormat = 8; // bits/item
  194275. }
  194276. else if (evt.target == atom_UTF8_STRING)
  194277. {
  194278. // translate to utf8
  194279. numDataItems = localClipboardContent.getNumBytesAsUTF8() + 1;
  194280. data.calloc (numDataItems + 1);
  194281. localClipboardContent.copyToUTF8 (data, numDataItems);
  194282. propertyFormat = 8; // bits/item
  194283. }
  194284. else if (evt.target == atom_TARGETS)
  194285. {
  194286. // another application wants to know what we are able to send
  194287. numDataItems = 2;
  194288. propertyFormat = 32; // atoms are 32-bit
  194289. data.calloc (numDataItems * 4);
  194290. Atom* atoms = reinterpret_cast<Atom*> (data.getData());
  194291. atoms[0] = atom_UTF8_STRING;
  194292. atoms[1] = XA_STRING;
  194293. }
  194294. }
  194295. else
  194296. {
  194297. DBG ("requested unsupported clipboard");
  194298. }
  194299. if (data != 0)
  194300. {
  194301. const int maxReasonableSelectionSize = 1000000;
  194302. // for very big chunks of data, we should use the "INCR" protocol , which is a pain in the *ss
  194303. if (evt.property != None && numDataItems < maxReasonableSelectionSize)
  194304. {
  194305. XChangeProperty (evt.display, evt.requestor,
  194306. evt.property, evt.target,
  194307. propertyFormat /* 8 or 32 */, PropModeReplace,
  194308. reinterpret_cast<const unsigned char*> (data.getData()), numDataItems);
  194309. reply.property = evt.property; // " == success"
  194310. }
  194311. }
  194312. XSendEvent (evt.display, evt.requestor, 0, NoEventMask, (XEvent*) &reply);
  194313. }
  194314. void SystemClipboard::copyTextToClipboard (const String& clipText) throw()
  194315. {
  194316. initSelectionAtoms();
  194317. localClipboardContent = clipText;
  194318. XSetSelectionOwner (display, XA_PRIMARY, juce_messageWindowHandle, CurrentTime);
  194319. XSetSelectionOwner (display, atom_CLIPBOARD, juce_messageWindowHandle, CurrentTime);
  194320. }
  194321. const String SystemClipboard::getTextFromClipboard() throw()
  194322. {
  194323. initSelectionAtoms();
  194324. String content;
  194325. Atom selection = XA_PRIMARY;
  194326. Window selectionOwner = None;
  194327. if ((selectionOwner = XGetSelectionOwner (display, selection)) == None)
  194328. {
  194329. selection = atom_CLIPBOARD;
  194330. selectionOwner = XGetSelectionOwner (display, selection);
  194331. }
  194332. if (selectionOwner != None)
  194333. {
  194334. if (selectionOwner == juce_messageWindowHandle)
  194335. {
  194336. content = localClipboardContent;
  194337. }
  194338. else
  194339. {
  194340. // first try: we want an utf8 string
  194341. bool ok = juce_requestSelectionContent (content, selection, atom_UTF8_STRING);
  194342. if (! ok)
  194343. {
  194344. // second chance, ask for a good old locale-dependent string ..
  194345. ok = juce_requestSelectionContent (content, selection, XA_STRING);
  194346. }
  194347. }
  194348. }
  194349. return content;
  194350. }
  194351. #endif
  194352. /*** End of inlined file: juce_linux_Clipboard.cpp ***/
  194353. /*** Start of inlined file: juce_linux_Messaging.cpp ***/
  194354. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194355. // compiled on its own).
  194356. #if JUCE_INCLUDED_FILE
  194357. #ifdef JUCE_DEBUG
  194358. #define JUCE_DEBUG_XERRORS 1
  194359. #endif
  194360. Display* display = 0; // This is also referenced from WindowDriver.cpp
  194361. Window juce_messageWindowHandle = None;
  194362. XContext improbableNumber; // This is referenced from Windowing.cpp
  194363. extern void juce_windowMessageReceive (XEvent* event); // Defined in Windowing.cpp
  194364. extern void juce_handleSelectionRequest (XSelectionRequestEvent &evt); // Defined in Clipboard.cpp
  194365. ScopedXLock::ScopedXLock() { XLockDisplay (display); }
  194366. ScopedXLock::~ScopedXLock() { XUnlockDisplay (display); }
  194367. class InternalMessageQueue
  194368. {
  194369. public:
  194370. InternalMessageQueue()
  194371. : bytesInSocket (0)
  194372. {
  194373. int ret = ::socketpair (AF_LOCAL, SOCK_STREAM, 0, fd);
  194374. (void) ret; jassert (ret == 0);
  194375. //setNonBlocking (fd[0]);
  194376. //setNonBlocking (fd[1]);
  194377. }
  194378. ~InternalMessageQueue()
  194379. {
  194380. close (fd[0]);
  194381. close (fd[1]);
  194382. }
  194383. void postMessage (Message* msg)
  194384. {
  194385. const int maxBytesInSocketQueue = 128;
  194386. ScopedLock sl (lock);
  194387. queue.add (msg);
  194388. if (bytesInSocket < maxBytesInSocketQueue)
  194389. {
  194390. ++bytesInSocket;
  194391. ScopedUnlock ul (lock);
  194392. const unsigned char x = 0xff;
  194393. size_t bytesWritten = write (fd[0], &x, 1);
  194394. (void) bytesWritten;
  194395. }
  194396. }
  194397. bool isEmpty() const
  194398. {
  194399. ScopedLock sl (lock);
  194400. return queue.size() == 0;
  194401. }
  194402. Message* popNextMessage()
  194403. {
  194404. ScopedLock sl (lock);
  194405. if (bytesInSocket > 0)
  194406. {
  194407. --bytesInSocket;
  194408. ScopedUnlock ul (lock);
  194409. unsigned char x;
  194410. size_t numBytes = read (fd[1], &x, 1);
  194411. (void) numBytes;
  194412. }
  194413. Message* m = queue[0];
  194414. queue.remove (0, false /* deleteObject */);
  194415. return m;
  194416. }
  194417. int getWaitHandle() const { return fd[1]; }
  194418. private:
  194419. CriticalSection lock;
  194420. OwnedArray <Message> queue;
  194421. int fd[2];
  194422. int bytesInSocket;
  194423. static bool setNonBlocking (int handle)
  194424. {
  194425. int socketFlags = fcntl (handle, F_GETFL, 0);
  194426. if (socketFlags == -1)
  194427. return false;
  194428. socketFlags |= O_NONBLOCK;
  194429. return fcntl (handle, F_SETFL, socketFlags) == 0;
  194430. }
  194431. };
  194432. struct MessageThreadFuncCall
  194433. {
  194434. enum { uniqueID = 0x73774623 };
  194435. MessageCallbackFunction* func;
  194436. void* parameter;
  194437. void* result;
  194438. CriticalSection lock;
  194439. WaitableEvent event;
  194440. };
  194441. static InternalMessageQueue* juce_internalMessageQueue = 0;
  194442. // error handling in X11
  194443. static bool errorOccurred = false;
  194444. static bool keyboardBreakOccurred = false;
  194445. static XErrorHandler oldErrorHandler = (XErrorHandler) 0;
  194446. static XIOErrorHandler oldIOErrorHandler = (XIOErrorHandler) 0;
  194447. // Usually happens when client-server connection is broken
  194448. static int ioErrorHandler (Display* display)
  194449. {
  194450. DBG (T("ERROR: connection to X server broken.. terminating."));
  194451. errorOccurred = true;
  194452. if (JUCEApplication::getInstance() != 0)
  194453. Process::terminate();
  194454. return 0;
  194455. }
  194456. // A protocol error has occurred
  194457. static int errorHandler (Display* display, XErrorEvent* event)
  194458. {
  194459. #ifdef JUCE_DEBUG_XERRORS
  194460. char errorStr[64] = { 0 };
  194461. char requestStr[64] = { 0 };
  194462. XGetErrorText (display, event->error_code, errorStr, 64);
  194463. XGetErrorDatabaseText (display, "XRequest", String (event->request_code).toCString(),
  194464. "Unknown", requestStr, 64);
  194465. DBG (T("ERROR: X returned ") + String (errorStr) + T(" for operation ") + String (requestStr));
  194466. #endif
  194467. return 0;
  194468. }
  194469. // Breakin from keyboard
  194470. static void signalHandler (int sig)
  194471. {
  194472. if (sig == SIGINT)
  194473. {
  194474. keyboardBreakOccurred = true;
  194475. return;
  194476. }
  194477. static bool reentrant = false;
  194478. if (! reentrant)
  194479. {
  194480. reentrant = true;
  194481. // Illegal instruction
  194482. fflush (stdout);
  194483. Logger::outputDebugString ("ERROR: Program executed illegal instruction.. terminating");
  194484. errorOccurred = true;
  194485. if (JUCEApplication::getInstance() != 0)
  194486. Process::terminate();
  194487. }
  194488. else
  194489. {
  194490. if (JUCEApplication::getInstance() != 0)
  194491. exit(0);
  194492. }
  194493. }
  194494. void MessageManager::doPlatformSpecificInitialisation()
  194495. {
  194496. // Initialise xlib for multiple thread support
  194497. static bool initThreadCalled = false;
  194498. if (! initThreadCalled)
  194499. {
  194500. if (! XInitThreads())
  194501. {
  194502. // This is fatal! Print error and closedown
  194503. Logger::outputDebugString ("Failed to initialise xlib thread support.");
  194504. if (JUCEApplication::getInstance() != 0)
  194505. Process::terminate();
  194506. return;
  194507. }
  194508. initThreadCalled = true;
  194509. }
  194510. // This is called if the client/server connection is broken
  194511. oldIOErrorHandler = XSetIOErrorHandler (ioErrorHandler);
  194512. // This is called if a protocol error occurs
  194513. oldErrorHandler = XSetErrorHandler (errorHandler);
  194514. // Install signal handler for break-in
  194515. struct sigaction saction;
  194516. sigset_t maskSet;
  194517. sigemptyset (&maskSet);
  194518. saction.sa_handler = signalHandler;
  194519. saction.sa_mask = maskSet;
  194520. saction.sa_flags = 0;
  194521. sigaction (SIGINT, &saction, NULL);
  194522. #ifndef _DEBUG
  194523. // Setup signal handlers for various fatal errors
  194524. sigaction (SIGILL, &saction, NULL);
  194525. sigaction (SIGBUS, &saction, NULL);
  194526. sigaction (SIGFPE, &saction, NULL);
  194527. sigaction (SIGSEGV, &saction, NULL);
  194528. sigaction (SIGSYS, &saction, NULL);
  194529. #endif
  194530. // Create the internal message queue
  194531. juce_internalMessageQueue = new InternalMessageQueue();
  194532. // Try to connect to a display
  194533. String displayName (getenv ("DISPLAY"));
  194534. if (displayName.isEmpty())
  194535. displayName = ":0.0";
  194536. display = XOpenDisplay (displayName.toCString());
  194537. if (display == 0)
  194538. {
  194539. // This is not fatal! we can run headless.
  194540. return;
  194541. }
  194542. // Get defaults for various properties
  194543. int screen = DefaultScreen (display);
  194544. Window root = RootWindow (display, screen);
  194545. Visual* visual = DefaultVisual (display, screen);
  194546. // Create a context to store user data associated with Windows we
  194547. // create in WindowDriver
  194548. improbableNumber = XUniqueContext();
  194549. // We're only interested in client messages for this window
  194550. // which are always sent
  194551. XSetWindowAttributes swa;
  194552. swa.event_mask = NoEventMask;
  194553. // Create our message window (this will never be mapped)
  194554. juce_messageWindowHandle = XCreateWindow (display, root,
  194555. 0, 0, 1, 1, 0, 0, InputOnly,
  194556. visual, CWEventMask, &swa);
  194557. }
  194558. void MessageManager::doPlatformSpecificShutdown()
  194559. {
  194560. deleteAndZero (juce_internalMessageQueue);
  194561. if (display != 0 && ! errorOccurred)
  194562. {
  194563. XDestroyWindow (display, juce_messageWindowHandle);
  194564. XCloseDisplay (display);
  194565. // reset pointers
  194566. juce_messageWindowHandle = 0;
  194567. display = 0;
  194568. // Restore original error handlers
  194569. XSetIOErrorHandler (oldIOErrorHandler);
  194570. oldIOErrorHandler = 0;
  194571. XSetErrorHandler (oldErrorHandler);
  194572. oldErrorHandler = 0;
  194573. }
  194574. }
  194575. bool juce_postMessageToSystemQueue (void* message)
  194576. {
  194577. if (errorOccurred)
  194578. return false;
  194579. juce_internalMessageQueue->postMessage ((Message*) message);
  194580. return true;
  194581. }
  194582. void MessageManager::broadcastMessage (const String& value) throw()
  194583. {
  194584. }
  194585. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* func,
  194586. void* parameter)
  194587. {
  194588. if (errorOccurred)
  194589. return 0;
  194590. if (! isThisTheMessageThread())
  194591. {
  194592. MessageThreadFuncCall messageCallContext;
  194593. messageCallContext.func = func;
  194594. messageCallContext.parameter = parameter;
  194595. juce_internalMessageQueue->postMessage (new Message (MessageThreadFuncCall::uniqueID,
  194596. 0, 0, &messageCallContext));
  194597. // Wait for it to complete before continuing
  194598. messageCallContext.event.wait();
  194599. return messageCallContext.result;
  194600. }
  194601. else
  194602. {
  194603. // Just call the function directly
  194604. return func (parameter);
  194605. }
  194606. }
  194607. // Wait for an event (either XEvent, or an internal Message)
  194608. static bool juce_sleepUntilEvent (const int timeoutMs)
  194609. {
  194610. if (! juce_internalMessageQueue->isEmpty())
  194611. return true;
  194612. if (display != 0)
  194613. {
  194614. ScopedXLock xlock;
  194615. if (XPending (display))
  194616. return true;
  194617. }
  194618. struct timeval tv;
  194619. tv.tv_sec = 0;
  194620. tv.tv_usec = timeoutMs * 1000;
  194621. int fd0 = juce_internalMessageQueue->getWaitHandle();
  194622. int fdmax = fd0;
  194623. fd_set readset;
  194624. FD_ZERO (&readset);
  194625. FD_SET (fd0, &readset);
  194626. if (display != 0)
  194627. {
  194628. ScopedXLock xlock;
  194629. int fd1 = XConnectionNumber (display);
  194630. FD_SET (fd1, &readset);
  194631. fdmax = jmax (fd0, fd1);
  194632. }
  194633. const int ret = select (fdmax + 1, &readset, 0, 0, &tv);
  194634. return (ret > 0); // ret <= 0 if error or timeout
  194635. }
  194636. // Handle next XEvent (if any)
  194637. static bool juce_dispatchNextXEvent()
  194638. {
  194639. if (display == 0)
  194640. return false;
  194641. XEvent evt;
  194642. {
  194643. ScopedXLock xlock;
  194644. if (! XPending (display))
  194645. return false;
  194646. XNextEvent (display, &evt);
  194647. }
  194648. if (evt.type == SelectionRequest && evt.xany.window == juce_messageWindowHandle)
  194649. {
  194650. juce_handleSelectionRequest (evt.xselectionrequest);
  194651. }
  194652. else if (evt.xany.window != juce_messageWindowHandle)
  194653. {
  194654. juce_windowMessageReceive (&evt);
  194655. }
  194656. return true;
  194657. }
  194658. // Handle next internal Message (if any)
  194659. static bool juce_dispatchNextInternalMessage()
  194660. {
  194661. ScopedPointer <Message> msg (juce_internalMessageQueue->popNextMessage());
  194662. if (msg == 0)
  194663. return false;
  194664. if (msg->intParameter1 == MessageThreadFuncCall::uniqueID)
  194665. {
  194666. // Handle callback message
  194667. MessageThreadFuncCall* const call = (MessageThreadFuncCall*) msg->pointerParameter;
  194668. call->result = (*(call->func)) (call->parameter);
  194669. call->event.signal();
  194670. }
  194671. else
  194672. {
  194673. // Handle "normal" messages
  194674. MessageManager::getInstance()->deliverMessage (msg.release());
  194675. }
  194676. return true;
  194677. }
  194678. // this function expects that it will NEVER be called simultaneously for two concurrent threads
  194679. bool juce_dispatchNextMessageOnSystemQueue (bool returnIfNoPendingMessages)
  194680. {
  194681. for (;;)
  194682. {
  194683. if (errorOccurred)
  194684. break;
  194685. if (keyboardBreakOccurred)
  194686. {
  194687. errorOccurred = true;
  194688. if (JUCEApplication::getInstance() != 0)
  194689. Process::terminate();
  194690. break;
  194691. }
  194692. static int totalEventCount = 0;
  194693. ++totalEventCount;
  194694. // The purpose here is to give either priority to XEvents or
  194695. // to internal messages This is necessary to keep a "good"
  194696. // behaviour when the cpu is overloaded
  194697. if (totalEventCount & 1)
  194698. {
  194699. if (juce_dispatchNextXEvent() || juce_dispatchNextInternalMessage())
  194700. return true;
  194701. }
  194702. else
  194703. {
  194704. if (juce_dispatchNextInternalMessage() || juce_dispatchNextXEvent())
  194705. return true;
  194706. }
  194707. if (returnIfNoPendingMessages) // early exit
  194708. break;
  194709. // the timeout is to be on the safe side, but it does not seem to be useful
  194710. juce_sleepUntilEvent (2000);
  194711. }
  194712. return false;
  194713. }
  194714. #endif
  194715. /*** End of inlined file: juce_linux_Messaging.cpp ***/
  194716. /*** Start of inlined file: juce_linux_Fonts.cpp ***/
  194717. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194718. // compiled on its own).
  194719. #if JUCE_INCLUDED_FILE
  194720. class FreeTypeFontFace
  194721. {
  194722. public:
  194723. enum FontStyle
  194724. {
  194725. Plain = 0,
  194726. Bold = 1,
  194727. Italic = 2
  194728. };
  194729. struct FontNameIndex
  194730. {
  194731. String fileName;
  194732. int faceIndex;
  194733. };
  194734. FreeTypeFontFace (const String& familyName) throw()
  194735. : hasSerif (false),
  194736. monospaced (false)
  194737. {
  194738. family = familyName;
  194739. }
  194740. void setFileName (const String& name, const int faceIndex, FontStyle style) throw()
  194741. {
  194742. if (names [(int) style].fileName.isEmpty())
  194743. {
  194744. names [(int) style].fileName = name;
  194745. names [(int) style].faceIndex = faceIndex;
  194746. }
  194747. }
  194748. const String& getFamilyName() const throw() { return family; }
  194749. const String& getFileName (const int style, int& faceIndex) const throw()
  194750. {
  194751. faceIndex = names[style].faceIndex;
  194752. return names[style].fileName;
  194753. }
  194754. void setMonospaced (bool mono) throw() { monospaced = mono; }
  194755. bool getMonospaced() const throw() { return monospaced; }
  194756. void setSerif (const bool serif) throw() { hasSerif = serif; }
  194757. bool getSerif() const throw() { return hasSerif; }
  194758. private:
  194759. String family;
  194760. FontNameIndex names[4];
  194761. bool hasSerif, monospaced;
  194762. };
  194763. class FreeTypeInterface : public DeletedAtShutdown
  194764. {
  194765. public:
  194766. FreeTypeInterface() throw()
  194767. : lastFace (0),
  194768. lastBold (false),
  194769. lastItalic (false)
  194770. {
  194771. if (FT_Init_FreeType (&ftLib) != 0)
  194772. {
  194773. ftLib = 0;
  194774. DBG (T("Failed to initialize FreeType"));
  194775. }
  194776. StringArray fontDirs;
  194777. fontDirs.addTokens (String (getenv ("JUCE_FONT_PATH")), T(";,"), 0);
  194778. fontDirs.removeEmptyStrings (true);
  194779. if (fontDirs.size() == 0)
  194780. {
  194781. XmlDocument fontsConfig (File ("/etc/fonts/fonts.conf"));
  194782. XmlElement* const fontsInfo = fontsConfig.getDocumentElement();
  194783. if (fontsInfo != 0)
  194784. {
  194785. forEachXmlChildElementWithTagName (*fontsInfo, e, T("dir"))
  194786. {
  194787. fontDirs.add (e->getAllSubText().trim());
  194788. }
  194789. delete fontsInfo;
  194790. }
  194791. }
  194792. if (fontDirs.size() == 0)
  194793. fontDirs.add ("/usr/X11R6/lib/X11/fonts");
  194794. for (int i = 0; i < fontDirs.size(); ++i)
  194795. enumerateFaces (fontDirs[i]);
  194796. }
  194797. ~FreeTypeInterface() throw()
  194798. {
  194799. if (lastFace != 0)
  194800. FT_Done_Face (lastFace);
  194801. if (ftLib != 0)
  194802. FT_Done_FreeType (ftLib);
  194803. clearSingletonInstance();
  194804. }
  194805. FreeTypeFontFace* findOrCreate (const String& familyName,
  194806. const bool create = false) throw()
  194807. {
  194808. for (int i = 0; i < faces.size(); i++)
  194809. if (faces[i]->getFamilyName() == familyName)
  194810. return faces[i];
  194811. if (! create)
  194812. return NULL;
  194813. FreeTypeFontFace* newFace = new FreeTypeFontFace (familyName);
  194814. faces.add (newFace);
  194815. return newFace;
  194816. }
  194817. // Enumerate all font faces available in a given directory
  194818. void enumerateFaces (const String& path) throw()
  194819. {
  194820. File dirPath (path);
  194821. if (path.isEmpty() || ! dirPath.isDirectory())
  194822. return;
  194823. DirectoryIterator di (dirPath, true);
  194824. while (di.next())
  194825. {
  194826. File possible (di.getFile());
  194827. if (possible.hasFileExtension (T("ttf"))
  194828. || possible.hasFileExtension (T("pfb"))
  194829. || possible.hasFileExtension (T("pcf")))
  194830. {
  194831. FT_Face face;
  194832. int faceIndex = 0;
  194833. int numFaces = 0;
  194834. do
  194835. {
  194836. if (FT_New_Face (ftLib, possible.getFullPathName().toUTF8(),
  194837. faceIndex, &face) == 0)
  194838. {
  194839. if (faceIndex == 0)
  194840. numFaces = face->num_faces;
  194841. if ((face->face_flags & FT_FACE_FLAG_SCALABLE) != 0)
  194842. {
  194843. FreeTypeFontFace* const newFace = findOrCreate (face->family_name, true);
  194844. int style = (int) FreeTypeFontFace::Plain;
  194845. if ((face->style_flags & FT_STYLE_FLAG_BOLD) != 0)
  194846. style |= (int) FreeTypeFontFace::Bold;
  194847. if ((face->style_flags & FT_STYLE_FLAG_ITALIC) != 0)
  194848. style |= (int) FreeTypeFontFace::Italic;
  194849. newFace->setFileName (possible.getFullPathName(), faceIndex, (FreeTypeFontFace::FontStyle) style);
  194850. newFace->setMonospaced ((face->face_flags & FT_FACE_FLAG_FIXED_WIDTH) != 0);
  194851. // Surely there must be a better way to do this?
  194852. const String name (face->family_name);
  194853. newFace->setSerif (! (name.containsIgnoreCase (T("Sans"))
  194854. || name.containsIgnoreCase (T("Verdana"))
  194855. || name.containsIgnoreCase (T("Arial"))));
  194856. }
  194857. FT_Done_Face (face);
  194858. }
  194859. ++faceIndex;
  194860. }
  194861. while (faceIndex < numFaces);
  194862. }
  194863. }
  194864. }
  194865. // Create a FreeType face object for a given font
  194866. FT_Face createFT_Face (const String& fontName,
  194867. const bool bold,
  194868. const bool italic) throw()
  194869. {
  194870. FT_Face face = 0;
  194871. if (fontName == lastFontName && bold == lastBold && italic == lastItalic)
  194872. {
  194873. face = lastFace;
  194874. }
  194875. else
  194876. {
  194877. if (lastFace != 0)
  194878. {
  194879. FT_Done_Face (lastFace);
  194880. lastFace = 0;
  194881. }
  194882. lastFontName = fontName;
  194883. lastBold = bold;
  194884. lastItalic = italic;
  194885. FreeTypeFontFace* const ftFace = findOrCreate (fontName);
  194886. if (ftFace != 0)
  194887. {
  194888. int style = (int) FreeTypeFontFace::Plain;
  194889. if (bold)
  194890. style |= (int) FreeTypeFontFace::Bold;
  194891. if (italic)
  194892. style |= (int) FreeTypeFontFace::Italic;
  194893. int faceIndex;
  194894. String fileName (ftFace->getFileName (style, faceIndex));
  194895. if (fileName.isEmpty())
  194896. {
  194897. style ^= (int) FreeTypeFontFace::Bold;
  194898. fileName = ftFace->getFileName (style, faceIndex);
  194899. if (fileName.isEmpty())
  194900. {
  194901. style ^= (int) FreeTypeFontFace::Bold;
  194902. style ^= (int) FreeTypeFontFace::Italic;
  194903. fileName = ftFace->getFileName (style, faceIndex);
  194904. if (! fileName.length())
  194905. {
  194906. style ^= (int) FreeTypeFontFace::Bold;
  194907. fileName = ftFace->getFileName (style, faceIndex);
  194908. }
  194909. }
  194910. }
  194911. if (! FT_New_Face (ftLib, fileName.toUTF8(), faceIndex, &lastFace))
  194912. {
  194913. face = lastFace;
  194914. // If there isn't a unicode charmap then select the first one.
  194915. if (FT_Select_Charmap (face, ft_encoding_unicode))
  194916. FT_Set_Charmap (face, face->charmaps[0]);
  194917. }
  194918. }
  194919. }
  194920. return face;
  194921. }
  194922. bool addGlyph (FT_Face face, CustomTypeface& dest, uint32 character) throw()
  194923. {
  194924. const unsigned int glyphIndex = FT_Get_Char_Index (face, character);
  194925. const float height = (float) (face->ascender - face->descender);
  194926. const float scaleX = 1.0f / height;
  194927. const float scaleY = -1.0f / height;
  194928. Path destShape;
  194929. if (FT_Load_Glyph (face, glyphIndex, FT_LOAD_NO_SCALE | FT_LOAD_NO_BITMAP | FT_LOAD_IGNORE_TRANSFORM) != 0
  194930. || face->glyph->format != ft_glyph_format_outline)
  194931. {
  194932. return false;
  194933. }
  194934. const FT_Outline* const outline = &face->glyph->outline;
  194935. const short* const contours = outline->contours;
  194936. const char* const tags = outline->tags;
  194937. FT_Vector* const points = outline->points;
  194938. for (int c = 0; c < outline->n_contours; c++)
  194939. {
  194940. const int startPoint = (c == 0) ? 0 : contours [c - 1] + 1;
  194941. const int endPoint = contours[c];
  194942. for (int p = startPoint; p <= endPoint; p++)
  194943. {
  194944. const float x = scaleX * points[p].x;
  194945. const float y = scaleY * points[p].y;
  194946. if (p == startPoint)
  194947. {
  194948. if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_Conic)
  194949. {
  194950. float x2 = scaleX * points [endPoint].x;
  194951. float y2 = scaleY * points [endPoint].y;
  194952. if (FT_CURVE_TAG (tags[endPoint]) != FT_Curve_Tag_On)
  194953. {
  194954. x2 = (x + x2) * 0.5f;
  194955. y2 = (y + y2) * 0.5f;
  194956. }
  194957. destShape.startNewSubPath (x2, y2);
  194958. }
  194959. else
  194960. {
  194961. destShape.startNewSubPath (x, y);
  194962. }
  194963. }
  194964. if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_On)
  194965. {
  194966. if (p != startPoint)
  194967. destShape.lineTo (x, y);
  194968. }
  194969. else if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_Conic)
  194970. {
  194971. const int nextIndex = (p == endPoint) ? startPoint : p + 1;
  194972. float x2 = scaleX * points [nextIndex].x;
  194973. float y2 = scaleY * points [nextIndex].y;
  194974. if (FT_CURVE_TAG (tags [nextIndex]) == FT_Curve_Tag_Conic)
  194975. {
  194976. x2 = (x + x2) * 0.5f;
  194977. y2 = (y + y2) * 0.5f;
  194978. }
  194979. else
  194980. {
  194981. ++p;
  194982. }
  194983. destShape.quadraticTo (x, y, x2, y2);
  194984. }
  194985. else if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_Cubic)
  194986. {
  194987. if (p >= endPoint)
  194988. return false;
  194989. const int next1 = p + 1;
  194990. const int next2 = (p == (endPoint - 1)) ? startPoint : p + 2;
  194991. const float x2 = scaleX * points [next1].x;
  194992. const float y2 = scaleY * points [next1].y;
  194993. const float x3 = scaleX * points [next2].x;
  194994. const float y3 = scaleY * points [next2].y;
  194995. if (FT_CURVE_TAG (tags[next1]) != FT_Curve_Tag_Cubic
  194996. || FT_CURVE_TAG (tags[next2]) != FT_Curve_Tag_On)
  194997. return false;
  194998. destShape.cubicTo (x, y, x2, y2, x3, y3);
  194999. p += 2;
  195000. }
  195001. }
  195002. destShape.closeSubPath();
  195003. }
  195004. dest.addGlyph (character, destShape, face->glyph->metrics.horiAdvance / height);
  195005. if ((face->face_flags & FT_FACE_FLAG_KERNING) != 0)
  195006. addKerning (face, dest, character, glyphIndex);
  195007. return true;
  195008. }
  195009. void addKerning (FT_Face face, CustomTypeface& dest, const uint32 character, const uint32 glyphIndex) throw()
  195010. {
  195011. const float height = (float) (face->ascender - face->descender);
  195012. uint32 rightGlyphIndex;
  195013. uint32 rightCharCode = FT_Get_First_Char (face, &rightGlyphIndex);
  195014. while (rightGlyphIndex != 0)
  195015. {
  195016. FT_Vector kerning;
  195017. if (FT_Get_Kerning (face, glyphIndex, rightGlyphIndex, ft_kerning_unscaled, &kerning) == 0)
  195018. {
  195019. if (kerning.x != 0)
  195020. dest.addKerningPair (character, rightCharCode, kerning.x / height);
  195021. }
  195022. rightCharCode = FT_Get_Next_Char (face, rightCharCode, &rightGlyphIndex);
  195023. }
  195024. }
  195025. // Add a glyph to a font
  195026. bool addGlyphToFont (const uint32 character,
  195027. const tchar* fontName, bool bold, bool italic,
  195028. CustomTypeface& dest) throw()
  195029. {
  195030. FT_Face face = createFT_Face (fontName, bold, italic);
  195031. if (face != 0)
  195032. return addGlyph (face, dest, character);
  195033. return false;
  195034. }
  195035. void getFamilyNames (StringArray& familyNames) const throw()
  195036. {
  195037. for (int i = 0; i < faces.size(); i++)
  195038. familyNames.add (faces[i]->getFamilyName());
  195039. }
  195040. void getMonospacedNames (StringArray& monoSpaced) const throw()
  195041. {
  195042. for (int i = 0; i < faces.size(); i++)
  195043. if (faces[i]->getMonospaced())
  195044. monoSpaced.add (faces[i]->getFamilyName());
  195045. }
  195046. void getSerifNames (StringArray& serif) const throw()
  195047. {
  195048. for (int i = 0; i < faces.size(); i++)
  195049. if (faces[i]->getSerif())
  195050. serif.add (faces[i]->getFamilyName());
  195051. }
  195052. void getSansSerifNames (StringArray& sansSerif) const throw()
  195053. {
  195054. for (int i = 0; i < faces.size(); i++)
  195055. if (! faces[i]->getSerif())
  195056. sansSerif.add (faces[i]->getFamilyName());
  195057. }
  195058. juce_DeclareSingleton_SingleThreaded_Minimal (FreeTypeInterface)
  195059. private:
  195060. FT_Library ftLib;
  195061. FT_Face lastFace;
  195062. String lastFontName;
  195063. bool lastBold, lastItalic;
  195064. OwnedArray<FreeTypeFontFace> faces;
  195065. };
  195066. juce_ImplementSingleton_SingleThreaded (FreeTypeInterface)
  195067. class FreetypeTypeface : public CustomTypeface
  195068. {
  195069. public:
  195070. FreetypeTypeface (const Font& font)
  195071. {
  195072. FT_Face face = FreeTypeInterface::getInstance()
  195073. ->createFT_Face (font.getTypefaceName(), font.isBold(), font.isItalic());
  195074. if (face == 0)
  195075. {
  195076. #ifdef JUCE_DEBUG
  195077. String msg (T("Failed to create typeface: "));
  195078. msg << font.getTypefaceName() << " " << (font.isBold() ? 'B' : ' ') << (font.isItalic() ? 'I' : ' ');
  195079. DBG (msg);
  195080. #endif
  195081. }
  195082. else
  195083. {
  195084. setCharacteristics (font.getTypefaceName(),
  195085. face->ascender / (float) (face->ascender - face->descender),
  195086. font.isBold(), font.isItalic(),
  195087. L' ');
  195088. }
  195089. }
  195090. bool loadGlyphIfPossible (const juce_wchar character)
  195091. {
  195092. return FreeTypeInterface::getInstance()
  195093. ->addGlyphToFont (character, name, isBold, isItalic, *this);
  195094. }
  195095. };
  195096. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  195097. {
  195098. return new FreetypeTypeface (font);
  195099. }
  195100. const StringArray Font::findAllTypefaceNames() throw()
  195101. {
  195102. StringArray s;
  195103. FreeTypeInterface::getInstance()->getFamilyNames (s);
  195104. s.sort (true);
  195105. return s;
  195106. }
  195107. static const String pickBestFont (const StringArray& names,
  195108. const char* const choicesString)
  195109. {
  195110. StringArray choices;
  195111. choices.addTokens (String (choicesString), T(","), 0);
  195112. choices.trim();
  195113. choices.removeEmptyStrings();
  195114. int i, j;
  195115. for (j = 0; j < choices.size(); ++j)
  195116. if (names.contains (choices[j], true))
  195117. return choices[j];
  195118. for (j = 0; j < choices.size(); ++j)
  195119. for (i = 0; i < names.size(); i++)
  195120. if (names[i].startsWithIgnoreCase (choices[j]))
  195121. return names[i];
  195122. for (j = 0; j < choices.size(); ++j)
  195123. for (i = 0; i < names.size(); i++)
  195124. if (names[i].containsIgnoreCase (choices[j]))
  195125. return names[i];
  195126. return names[0];
  195127. }
  195128. static const String linux_getDefaultSansSerifFontName()
  195129. {
  195130. StringArray allFonts;
  195131. FreeTypeInterface::getInstance()->getSansSerifNames (allFonts);
  195132. return pickBestFont (allFonts, "Verdana, Bitstream Vera Sans, Luxi Sans, Sans");
  195133. }
  195134. static const String linux_getDefaultSerifFontName()
  195135. {
  195136. StringArray allFonts;
  195137. FreeTypeInterface::getInstance()->getSerifNames (allFonts);
  195138. return pickBestFont (allFonts, "Bitstream Vera Serif, Times, Nimbus Roman, Serif");
  195139. }
  195140. static const String linux_getDefaultMonospacedFontName()
  195141. {
  195142. StringArray allFonts;
  195143. FreeTypeInterface::getInstance()->getMonospacedNames (allFonts);
  195144. return pickBestFont (allFonts, "Bitstream Vera Sans Mono, Courier, Sans Mono, Mono");
  195145. }
  195146. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw()
  195147. {
  195148. defaultSans = linux_getDefaultSansSerifFontName();
  195149. defaultSerif = linux_getDefaultSerifFontName();
  195150. defaultFixed = linux_getDefaultMonospacedFontName();
  195151. }
  195152. #endif
  195153. /*** End of inlined file: juce_linux_Fonts.cpp ***/
  195154. /*** Start of inlined file: juce_linux_Windowing.cpp ***/
  195155. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  195156. // compiled on its own).
  195157. #if JUCE_INCLUDED_FILE
  195158. namespace Atoms
  195159. {
  195160. enum ProtocolItems
  195161. {
  195162. TAKE_FOCUS = 0,
  195163. DELETE_WINDOW = 1
  195164. };
  195165. static Atom Protocols, ProtocolList[2], ChangeState, State,
  195166. ActiveWin, Pid, WindowType, WindowState,
  195167. XdndAware, XdndEnter, XdndLeave, XdndPosition, XdndStatus,
  195168. XdndDrop, XdndFinished, XdndSelection, XdndTypeList, XdndActionList,
  195169. XdndActionDescription, XdndActionCopy,
  195170. allowedActions[5],
  195171. allowedMimeTypes[2];
  195172. const unsigned long DndVersion = 3;
  195173. static void initialiseAtoms()
  195174. {
  195175. static bool atomsInitialised = false;
  195176. if (! atomsInitialised)
  195177. {
  195178. atomsInitialised = true;
  195179. Protocols = XInternAtom (display, "WM_PROTOCOLS", True);
  195180. ProtocolList [TAKE_FOCUS] = XInternAtom (display, "WM_TAKE_FOCUS", True);
  195181. ProtocolList [DELETE_WINDOW] = XInternAtom (display, "WM_DELETE_WINDOW", True);
  195182. ChangeState = XInternAtom (display, "WM_CHANGE_STATE", True);
  195183. State = XInternAtom (display, "WM_STATE", True);
  195184. ActiveWin = XInternAtom (display, "_NET_ACTIVE_WINDOW", False);
  195185. Pid = XInternAtom (display, "_NET_WM_PID", False);
  195186. WindowType = XInternAtom (display, "_NET_WM_WINDOW_TYPE", True);
  195187. WindowState = XInternAtom (display, "_NET_WM_WINDOW_STATE", True);
  195188. XdndAware = XInternAtom (display, "XdndAware", False);
  195189. XdndEnter = XInternAtom (display, "XdndEnter", False);
  195190. XdndLeave = XInternAtom (display, "XdndLeave", False);
  195191. XdndPosition = XInternAtom (display, "XdndPosition", False);
  195192. XdndStatus = XInternAtom (display, "XdndStatus", False);
  195193. XdndDrop = XInternAtom (display, "XdndDrop", False);
  195194. XdndFinished = XInternAtom (display, "XdndFinished", False);
  195195. XdndSelection = XInternAtom (display, "XdndSelection", False);
  195196. XdndTypeList = XInternAtom (display, "XdndTypeList", False);
  195197. XdndActionList = XInternAtom (display, "XdndActionList", False);
  195198. XdndActionCopy = XInternAtom (display, "XdndActionCopy", False);
  195199. XdndActionDescription = XInternAtom (display, "XdndActionDescription", False);
  195200. allowedMimeTypes [0] = XInternAtom (display, "text/plain", False);
  195201. allowedMimeTypes [1] = XInternAtom (display, "text/uri-list", False);
  195202. allowedActions [0] = XInternAtom (display, "XdndActionMove", False);
  195203. allowedActions [1] = XdndActionCopy;
  195204. allowedActions [2] = XInternAtom (display, "XdndActionLink", False);
  195205. allowedActions [3] = XInternAtom (display, "XdndActionAsk", False);
  195206. allowedActions [4] = XInternAtom (display, "XdndActionPrivate", False);
  195207. }
  195208. }
  195209. }
  195210. enum SystemTrayValues
  195211. {
  195212. SYSTEM_TRAY_REQUEST_DOCK = 0,
  195213. SYSTEM_TRAY_BEGIN_MESSAGE = 1,
  195214. SYSTEM_TRAY_CANCEL_MESSAGE = 2
  195215. };
  195216. static XErrorHandler oldHandler = 0;
  195217. static int trappedErrorCode = 0;
  195218. extern "C" int errorTrapHandler (Display* dpy, XErrorEvent* err)
  195219. {
  195220. trappedErrorCode = err->error_code;
  195221. return 0;
  195222. }
  195223. static void trapErrors()
  195224. {
  195225. trappedErrorCode = 0;
  195226. oldHandler = XSetErrorHandler (errorTrapHandler);
  195227. }
  195228. static bool untrapErrors()
  195229. {
  195230. XSetErrorHandler (oldHandler);
  195231. return (trappedErrorCode == 0);
  195232. }
  195233. static bool isActiveApplication = false;
  195234. bool Process::isForegroundProcess()
  195235. {
  195236. return isActiveApplication;
  195237. }
  195238. // These are defined in juce_linux_Messaging.cpp
  195239. extern Display* display;
  195240. extern XContext improbableNumber;
  195241. static const int eventMask = NoEventMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask
  195242. | EnterWindowMask | LeaveWindowMask | PointerMotionMask | KeymapStateMask
  195243. | ExposureMask | StructureNotifyMask | FocusChangeMask;
  195244. namespace Keys
  195245. {
  195246. enum MouseButtons
  195247. {
  195248. NoButton = 0,
  195249. LeftButton = 1,
  195250. MiddleButton = 2,
  195251. RightButton = 3,
  195252. WheelUp = 4,
  195253. WheelDown = 5
  195254. };
  195255. static int AltMask = 0;
  195256. static int NumLockMask = 0;
  195257. static bool numLock = false;
  195258. static bool capsLock = false;
  195259. static char keyStates [32];
  195260. static const int extendedKeyModifier = 0x10000000;
  195261. }
  195262. bool KeyPress::isKeyCurrentlyDown (const int keyCode) throw()
  195263. {
  195264. int keysym;
  195265. if (keyCode & Keys::extendedKeyModifier)
  195266. {
  195267. keysym = 0xff00 | (keyCode & 0xff);
  195268. }
  195269. else
  195270. {
  195271. keysym = keyCode;
  195272. if (keysym == (XK_Tab & 0xff)
  195273. || keysym == (XK_Return & 0xff)
  195274. || keysym == (XK_Escape & 0xff)
  195275. || keysym == (XK_BackSpace & 0xff))
  195276. {
  195277. keysym |= 0xff00;
  195278. }
  195279. }
  195280. ScopedXLock xlock;
  195281. const int keycode = XKeysymToKeycode (display, keysym);
  195282. const int keybyte = keycode >> 3;
  195283. const int keybit = (1 << (keycode & 7));
  195284. return (Keys::keyStates [keybyte] & keybit) != 0;
  195285. }
  195286. #if JUCE_USE_XSHM
  195287. static bool isShmAvailable() throw()
  195288. {
  195289. static bool isChecked = false;
  195290. static bool isAvailable = false;
  195291. if (! isChecked)
  195292. {
  195293. isChecked = true;
  195294. int major, minor;
  195295. Bool pixmaps;
  195296. ScopedXLock xlock;
  195297. if (XShmQueryVersion (display, &major, &minor, &pixmaps))
  195298. {
  195299. trapErrors();
  195300. XShmSegmentInfo segmentInfo;
  195301. zerostruct (segmentInfo);
  195302. XImage* xImage = XShmCreateImage (display, DefaultVisual (display, DefaultScreen (display)),
  195303. 24, ZPixmap, 0, &segmentInfo, 50, 50);
  195304. if ((segmentInfo.shmid = shmget (IPC_PRIVATE,
  195305. xImage->bytes_per_line * xImage->height,
  195306. IPC_CREAT | 0777)) >= 0)
  195307. {
  195308. segmentInfo.shmaddr = (char*) shmat (segmentInfo.shmid, 0, 0);
  195309. if (segmentInfo.shmaddr != (void*) -1)
  195310. {
  195311. segmentInfo.readOnly = False;
  195312. xImage->data = segmentInfo.shmaddr;
  195313. XSync (display, False);
  195314. if (XShmAttach (display, &segmentInfo) != 0)
  195315. {
  195316. XSync (display, False);
  195317. XShmDetach (display, &segmentInfo);
  195318. isAvailable = true;
  195319. }
  195320. }
  195321. XFlush (display);
  195322. XDestroyImage (xImage);
  195323. shmdt (segmentInfo.shmaddr);
  195324. }
  195325. shmctl (segmentInfo.shmid, IPC_RMID, 0);
  195326. isAvailable &= untrapErrors();
  195327. }
  195328. }
  195329. return isAvailable;
  195330. }
  195331. #endif
  195332. #if JUCE_USE_XRENDER
  195333. namespace XRender
  195334. {
  195335. typedef Status (*tXRenderQueryVersion) (Display*, int*, int*);
  195336. typedef XRenderPictFormat* (*tXrenderFindStandardFormat) (Display*, int);
  195337. typedef XRenderPictFormat* (*tXRenderFindFormat) (Display*, unsigned long, XRenderPictFormat*, int);
  195338. typedef XRenderPictFormat* (*tXRenderFindVisualFormat) (Display*, Visual*);
  195339. static tXRenderQueryVersion xRenderQueryVersion = 0;
  195340. static tXrenderFindStandardFormat xRenderFindStandardFormat = 0;
  195341. static tXRenderFindFormat xRenderFindFormat = 0;
  195342. static tXRenderFindVisualFormat xRenderFindVisualFormat = 0;
  195343. static bool isAvailable()
  195344. {
  195345. static bool isChecked = false;
  195346. static bool isAvailable = false;
  195347. if (! isChecked)
  195348. {
  195349. ScopedXLock xlock;
  195350. isChecked = true;
  195351. if (xRenderQueryVersion == 0)
  195352. {
  195353. void* h = dlopen ("libXrender.so", RTLD_GLOBAL | RTLD_NOW);
  195354. if (h != 0)
  195355. {
  195356. xRenderQueryVersion = (tXRenderQueryVersion) dlsym (h, "XRenderQueryVersion");
  195357. xRenderFindStandardFormat = (tXrenderFindStandardFormat) dlsym (h, "XrenderFindStandardFormat");
  195358. xRenderFindFormat = (tXRenderFindFormat) dlsym (h, "XRenderFindFormat");
  195359. xRenderFindVisualFormat = (tXRenderFindVisualFormat) dlsym (h, "XRenderFindVisualFormat");
  195360. }
  195361. }
  195362. if (xRenderQueryVersion != 0
  195363. && xRenderFindStandardFormat != 0
  195364. && xRenderFindFormat != 0
  195365. && xRenderFindVisualFormat != 0)
  195366. {
  195367. int major, minor;
  195368. if (xRenderQueryVersion (display, &major, &minor))
  195369. isAvailable = true;
  195370. }
  195371. }
  195372. return isAvailable;
  195373. }
  195374. static XRenderPictFormat* findPictureFormat()
  195375. {
  195376. ScopedXLock xlock;
  195377. XRenderPictFormat* pictFormat = 0;
  195378. if (isAvailable())
  195379. {
  195380. pictFormat = xRenderFindStandardFormat (display, PictStandardARGB32);
  195381. if (pictFormat == 0)
  195382. {
  195383. XRenderPictFormat desiredFormat;
  195384. desiredFormat.type = PictTypeDirect;
  195385. desiredFormat.depth = 32;
  195386. desiredFormat.direct.alphaMask = 0xff;
  195387. desiredFormat.direct.redMask = 0xff;
  195388. desiredFormat.direct.greenMask = 0xff;
  195389. desiredFormat.direct.blueMask = 0xff;
  195390. desiredFormat.direct.alpha = 24;
  195391. desiredFormat.direct.red = 16;
  195392. desiredFormat.direct.green = 8;
  195393. desiredFormat.direct.blue = 0;
  195394. pictFormat = xRenderFindFormat (display,
  195395. PictFormatType | PictFormatDepth
  195396. | PictFormatRedMask | PictFormatRed
  195397. | PictFormatGreenMask | PictFormatGreen
  195398. | PictFormatBlueMask | PictFormatBlue
  195399. | PictFormatAlphaMask | PictFormatAlpha,
  195400. &desiredFormat,
  195401. 0);
  195402. }
  195403. }
  195404. return pictFormat;
  195405. }
  195406. }
  195407. #endif
  195408. namespace Visuals
  195409. {
  195410. static Visual* findVisualWithDepth (const int desiredDepth) throw()
  195411. {
  195412. ScopedXLock xlock;
  195413. Visual* visual = 0;
  195414. int numVisuals = 0;
  195415. long desiredMask = VisualNoMask;
  195416. XVisualInfo desiredVisual;
  195417. desiredVisual.screen = DefaultScreen (display);
  195418. desiredVisual.depth = desiredDepth;
  195419. desiredMask = VisualScreenMask | VisualDepthMask;
  195420. if (desiredDepth == 32)
  195421. {
  195422. desiredVisual.c_class = TrueColor;
  195423. desiredVisual.red_mask = 0x00FF0000;
  195424. desiredVisual.green_mask = 0x0000FF00;
  195425. desiredVisual.blue_mask = 0x000000FF;
  195426. desiredVisual.bits_per_rgb = 8;
  195427. desiredMask |= VisualClassMask;
  195428. desiredMask |= VisualRedMaskMask;
  195429. desiredMask |= VisualGreenMaskMask;
  195430. desiredMask |= VisualBlueMaskMask;
  195431. desiredMask |= VisualBitsPerRGBMask;
  195432. }
  195433. XVisualInfo* xvinfos = XGetVisualInfo (display,
  195434. desiredMask,
  195435. &desiredVisual,
  195436. &numVisuals);
  195437. if (xvinfos != 0)
  195438. {
  195439. for (int i = 0; i < numVisuals; i++)
  195440. {
  195441. if (xvinfos[i].depth == desiredDepth)
  195442. {
  195443. visual = xvinfos[i].visual;
  195444. break;
  195445. }
  195446. }
  195447. XFree (xvinfos);
  195448. }
  195449. return visual;
  195450. }
  195451. static Visual* findVisualFormat (const int desiredDepth, int& matchedDepth) throw()
  195452. {
  195453. Visual* visual = 0;
  195454. if (desiredDepth == 32)
  195455. {
  195456. #if JUCE_USE_XSHM
  195457. if (isShmAvailable())
  195458. {
  195459. #if JUCE_USE_XRENDER
  195460. if (XRender::isAvailable())
  195461. {
  195462. XRenderPictFormat* pictFormat = XRender::findPictureFormat();
  195463. if (pictFormat != 0)
  195464. {
  195465. int numVisuals = 0;
  195466. XVisualInfo desiredVisual;
  195467. desiredVisual.screen = DefaultScreen (display);
  195468. desiredVisual.depth = 32;
  195469. desiredVisual.bits_per_rgb = 8;
  195470. XVisualInfo* xvinfos = XGetVisualInfo (display,
  195471. VisualScreenMask | VisualDepthMask | VisualBitsPerRGBMask,
  195472. &desiredVisual, &numVisuals);
  195473. if (xvinfos != 0)
  195474. {
  195475. for (int i = 0; i < numVisuals; ++i)
  195476. {
  195477. XRenderPictFormat* pictVisualFormat = XRender::xRenderFindVisualFormat (display, xvinfos[i].visual);
  195478. if (pictVisualFormat != 0
  195479. && pictVisualFormat->type == PictTypeDirect
  195480. && pictVisualFormat->direct.alphaMask)
  195481. {
  195482. visual = xvinfos[i].visual;
  195483. matchedDepth = 32;
  195484. break;
  195485. }
  195486. }
  195487. XFree (xvinfos);
  195488. }
  195489. }
  195490. }
  195491. #endif
  195492. if (visual == 0)
  195493. {
  195494. visual = findVisualWithDepth (32);
  195495. if (visual != 0)
  195496. matchedDepth = 32;
  195497. }
  195498. }
  195499. #endif
  195500. }
  195501. if (visual == 0 && desiredDepth >= 24)
  195502. {
  195503. visual = findVisualWithDepth (24);
  195504. if (visual != 0)
  195505. matchedDepth = 24;
  195506. }
  195507. if (visual == 0 && desiredDepth >= 16)
  195508. {
  195509. visual = findVisualWithDepth (16);
  195510. if (visual != 0)
  195511. matchedDepth = 16;
  195512. }
  195513. return visual;
  195514. }
  195515. }
  195516. class XBitmapImage : public Image
  195517. {
  195518. public:
  195519. XBitmapImage (const PixelFormat format_, const int w, const int h,
  195520. const bool clearImage, const int imageDepth_, Visual* visual)
  195521. : Image (format_, w, h),
  195522. imageDepth (imageDepth_),
  195523. gc (None)
  195524. {
  195525. jassert (format_ == RGB || format_ == ARGB);
  195526. pixelStride = (format_ == RGB) ? 3 : 4;
  195527. lineStride = ((w * pixelStride + 3) & ~3);
  195528. ScopedXLock xlock;
  195529. #if JUCE_USE_XSHM
  195530. usingXShm = false;
  195531. if ((imageDepth > 16) && isShmAvailable())
  195532. {
  195533. zerostruct (segmentInfo);
  195534. segmentInfo.shmid = -1;
  195535. segmentInfo.shmaddr = (char *) -1;
  195536. segmentInfo.readOnly = False;
  195537. xImage = XShmCreateImage (display, visual, imageDepth, ZPixmap, 0, &segmentInfo, w, h);
  195538. if (xImage != 0)
  195539. {
  195540. if ((segmentInfo.shmid = shmget (IPC_PRIVATE,
  195541. xImage->bytes_per_line * xImage->height,
  195542. IPC_CREAT | 0777)) >= 0)
  195543. {
  195544. if (segmentInfo.shmid != -1)
  195545. {
  195546. segmentInfo.shmaddr = (char*) shmat (segmentInfo.shmid, 0, 0);
  195547. if (segmentInfo.shmaddr != (void*) -1)
  195548. {
  195549. segmentInfo.readOnly = False;
  195550. xImage->data = segmentInfo.shmaddr;
  195551. imageData = (uint8*) segmentInfo.shmaddr;
  195552. if (XShmAttach (display, &segmentInfo) != 0)
  195553. {
  195554. usingXShm = true;
  195555. }
  195556. else
  195557. {
  195558. jassertfalse
  195559. }
  195560. }
  195561. else
  195562. {
  195563. shmctl (segmentInfo.shmid, IPC_RMID, 0);
  195564. }
  195565. }
  195566. }
  195567. }
  195568. }
  195569. if (! usingXShm)
  195570. #endif
  195571. {
  195572. imageDataAllocated.malloc (lineStride * h);
  195573. imageData = imageDataAllocated;
  195574. if (format_ == ARGB && clearImage)
  195575. zeromem (imageData, h * lineStride);
  195576. xImage = (XImage*) juce_calloc (sizeof (XImage));
  195577. xImage->width = w;
  195578. xImage->height = h;
  195579. xImage->xoffset = 0;
  195580. xImage->format = ZPixmap;
  195581. xImage->data = (char*) imageData;
  195582. xImage->byte_order = ImageByteOrder (display);
  195583. xImage->bitmap_unit = BitmapUnit (display);
  195584. xImage->bitmap_bit_order = BitmapBitOrder (display);
  195585. xImage->bitmap_pad = 32;
  195586. xImage->depth = pixelStride * 8;
  195587. xImage->bytes_per_line = lineStride;
  195588. xImage->bits_per_pixel = pixelStride * 8;
  195589. xImage->red_mask = 0x00FF0000;
  195590. xImage->green_mask = 0x0000FF00;
  195591. xImage->blue_mask = 0x000000FF;
  195592. if (imageDepth == 16)
  195593. {
  195594. const int pixelStride = 2;
  195595. const int lineStride = ((w * pixelStride + 3) & ~3);
  195596. imageData16Bit.malloc (lineStride * h);
  195597. xImage->data = imageData16Bit;
  195598. xImage->bitmap_pad = 16;
  195599. xImage->depth = pixelStride * 8;
  195600. xImage->bytes_per_line = lineStride;
  195601. xImage->bits_per_pixel = pixelStride * 8;
  195602. xImage->red_mask = visual->red_mask;
  195603. xImage->green_mask = visual->green_mask;
  195604. xImage->blue_mask = visual->blue_mask;
  195605. }
  195606. if (! XInitImage (xImage))
  195607. {
  195608. jassertfalse
  195609. }
  195610. }
  195611. }
  195612. ~XBitmapImage()
  195613. {
  195614. ScopedXLock xlock;
  195615. #if JUCE_USE_XSHM
  195616. if (usingXShm)
  195617. {
  195618. XShmDetach (display, &segmentInfo);
  195619. XFlush (display);
  195620. XDestroyImage (xImage);
  195621. shmdt (segmentInfo.shmaddr);
  195622. shmctl (segmentInfo.shmid, IPC_RMID, 0);
  195623. }
  195624. else
  195625. #endif
  195626. {
  195627. xImage->data = 0;
  195628. XDestroyImage (xImage);
  195629. }
  195630. }
  195631. void blitToWindow (Window window, int dx, int dy, int dw, int dh, int sx, int sy)
  195632. {
  195633. ScopedXLock xlock;
  195634. if (gc == 0)
  195635. {
  195636. XGCValues gcvalues;
  195637. gcvalues.foreground = None;
  195638. gcvalues.background = None;
  195639. gcvalues.function = GXcopy;
  195640. gcvalues.plane_mask = AllPlanes;
  195641. gcvalues.clip_mask = None;
  195642. gcvalues.graphics_exposures = False;
  195643. gc = XCreateGC (display, window,
  195644. GCBackground | GCForeground | GCFunction | GCPlaneMask | GCClipMask | GCGraphicsExposures,
  195645. &gcvalues);
  195646. }
  195647. if (imageDepth == 16)
  195648. {
  195649. const uint32 rMask = xImage->red_mask;
  195650. const uint32 rShiftL = jmax (0, getShiftNeeded (rMask));
  195651. const uint32 rShiftR = jmax (0, -getShiftNeeded (rMask));
  195652. const uint32 gMask = xImage->green_mask;
  195653. const uint32 gShiftL = jmax (0, getShiftNeeded (gMask));
  195654. const uint32 gShiftR = jmax (0, -getShiftNeeded (gMask));
  195655. const uint32 bMask = xImage->blue_mask;
  195656. const uint32 bShiftL = jmax (0, getShiftNeeded (bMask));
  195657. const uint32 bShiftR = jmax (0, -getShiftNeeded (bMask));
  195658. const Image::BitmapData srcData (*this, 0, 0, getWidth(), getHeight());
  195659. for (int y = sy; y < sy + dh; ++y)
  195660. {
  195661. const uint8* p = srcData.getPixelPointer (sx, y);
  195662. for (int x = sx; x < sx + dw; ++x)
  195663. {
  195664. const PixelRGB* const pixel = (const PixelRGB*) p;
  195665. p += srcData.pixelStride;
  195666. XPutPixel (xImage, x, y,
  195667. (((((uint32) pixel->getRed()) << rShiftL) >> rShiftR) & rMask)
  195668. | (((((uint32) pixel->getGreen()) << gShiftL) >> gShiftR) & gMask)
  195669. | (((((uint32) pixel->getBlue()) << bShiftL) >> bShiftR) & bMask));
  195670. }
  195671. }
  195672. }
  195673. // blit results to screen.
  195674. #if JUCE_USE_XSHM
  195675. if (usingXShm)
  195676. XShmPutImage (display, (::Drawable) window, gc, xImage, sx, sy, dx, dy, dw, dh, True);
  195677. else
  195678. #endif
  195679. XPutImage (display, (::Drawable) window, gc, xImage, sx, sy, dx, dy, dw, dh);
  195680. }
  195681. juce_UseDebuggingNewOperator
  195682. private:
  195683. XImage* xImage;
  195684. const int imageDepth;
  195685. HeapBlock <char> imageData16Bit;
  195686. GC gc;
  195687. #if JUCE_USE_XSHM
  195688. XShmSegmentInfo segmentInfo;
  195689. bool usingXShm;
  195690. #endif
  195691. static int getShiftNeeded (const uint32 mask) throw()
  195692. {
  195693. for (int i = 32; --i >= 0;)
  195694. if (((mask >> i) & 1) != 0)
  195695. return i - 7;
  195696. jassertfalse
  195697. return 0;
  195698. }
  195699. };
  195700. class LinuxComponentPeer : public ComponentPeer
  195701. {
  195702. public:
  195703. LinuxComponentPeer (Component* const component, const int windowStyleFlags)
  195704. : ComponentPeer (component, windowStyleFlags),
  195705. windowH (0),
  195706. parentWindow (0),
  195707. wx (0),
  195708. wy (0),
  195709. ww (0),
  195710. wh (0),
  195711. taskbarImage (0),
  195712. fullScreen (false),
  195713. mapped (false),
  195714. visual (0),
  195715. depth (0)
  195716. {
  195717. // it's dangerous to create a window on a thread other than the message thread..
  195718. jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  195719. repainter = new LinuxRepaintManager (this);
  195720. createWindow();
  195721. setTitle (component->getName());
  195722. }
  195723. ~LinuxComponentPeer()
  195724. {
  195725. // it's dangerous to delete a window on a thread other than the message thread..
  195726. jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  195727. deleteTaskBarIcon();
  195728. deleteIconPixmaps();
  195729. destroyWindow();
  195730. windowH = 0;
  195731. }
  195732. void* getNativeHandle() const
  195733. {
  195734. return (void*) windowH;
  195735. }
  195736. static LinuxComponentPeer* getPeerFor (Window windowHandle) throw()
  195737. {
  195738. XPointer peer = 0;
  195739. ScopedXLock xlock;
  195740. if (! XFindContext (display, (XID) windowHandle, improbableNumber, &peer))
  195741. {
  195742. if (peer != 0 && ! ComponentPeer::isValidPeer ((LinuxComponentPeer*) peer))
  195743. peer = 0;
  195744. }
  195745. return (LinuxComponentPeer*) peer;
  195746. }
  195747. void setVisible (bool shouldBeVisible)
  195748. {
  195749. ScopedXLock xlock;
  195750. if (shouldBeVisible)
  195751. XMapWindow (display, windowH);
  195752. else
  195753. XUnmapWindow (display, windowH);
  195754. }
  195755. void setTitle (const String& title)
  195756. {
  195757. setWindowTitle (windowH, title);
  195758. }
  195759. void setPosition (int x, int y)
  195760. {
  195761. setBounds (x, y, ww, wh, false);
  195762. }
  195763. void setSize (int w, int h)
  195764. {
  195765. setBounds (wx, wy, w, h, false);
  195766. }
  195767. void setBounds (int x, int y, int w, int h, const bool isNowFullScreen)
  195768. {
  195769. fullScreen = isNowFullScreen;
  195770. if (windowH != 0)
  195771. {
  195772. Component::SafePointer<Component> deletionChecker (component);
  195773. wx = x;
  195774. wy = y;
  195775. ww = jmax (1, w);
  195776. wh = jmax (1, h);
  195777. ScopedXLock xlock;
  195778. // Make sure the Window manager does what we want
  195779. XSizeHints* hints = XAllocSizeHints();
  195780. hints->flags = USSize | USPosition;
  195781. hints->width = ww;
  195782. hints->height = wh;
  195783. hints->x = wx;
  195784. hints->y = wy;
  195785. if ((getStyleFlags() & (windowHasTitleBar | windowIsResizable)) == windowHasTitleBar)
  195786. {
  195787. hints->min_width = hints->max_width = hints->width;
  195788. hints->min_height = hints->max_height = hints->height;
  195789. hints->flags |= PMinSize | PMaxSize;
  195790. }
  195791. XSetWMNormalHints (display, windowH, hints);
  195792. XFree (hints);
  195793. XMoveResizeWindow (display, windowH,
  195794. wx - windowBorder.getLeft(),
  195795. wy - windowBorder.getTop(), ww, wh);
  195796. if (deletionChecker != 0)
  195797. {
  195798. updateBorderSize();
  195799. handleMovedOrResized();
  195800. }
  195801. }
  195802. }
  195803. const Rectangle<int> getBounds() const { return Rectangle<int> (wx, wy, ww, wh); }
  195804. const Point<int> getScreenPosition() const { return Point<int> (wx, wy); }
  195805. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition)
  195806. {
  195807. return relativePosition + getScreenPosition();
  195808. }
  195809. const Point<int> globalPositionToRelative (const Point<int>& screenPosition)
  195810. {
  195811. return screenPosition - getScreenPosition();
  195812. }
  195813. void setMinimised (bool shouldBeMinimised)
  195814. {
  195815. if (shouldBeMinimised)
  195816. {
  195817. Window root = RootWindow (display, DefaultScreen (display));
  195818. XClientMessageEvent clientMsg;
  195819. clientMsg.display = display;
  195820. clientMsg.window = windowH;
  195821. clientMsg.type = ClientMessage;
  195822. clientMsg.format = 32;
  195823. clientMsg.message_type = Atoms::ChangeState;
  195824. clientMsg.data.l[0] = IconicState;
  195825. ScopedXLock xlock;
  195826. XSendEvent (display, root, false,
  195827. SubstructureRedirectMask | SubstructureNotifyMask,
  195828. (XEvent*) &clientMsg);
  195829. }
  195830. else
  195831. {
  195832. setVisible (true);
  195833. }
  195834. }
  195835. bool isMinimised() const
  195836. {
  195837. bool minimised = false;
  195838. unsigned char* stateProp;
  195839. unsigned long nitems, bytesLeft;
  195840. Atom actualType;
  195841. int actualFormat;
  195842. ScopedXLock xlock;
  195843. if (XGetWindowProperty (display, windowH, Atoms::State, 0, 64, False,
  195844. Atoms::State, &actualType, &actualFormat, &nitems, &bytesLeft,
  195845. &stateProp) == Success
  195846. && actualType == Atoms::State
  195847. && actualFormat == 32
  195848. && nitems > 0)
  195849. {
  195850. if (((unsigned long*) stateProp)[0] == IconicState)
  195851. minimised = true;
  195852. XFree (stateProp);
  195853. }
  195854. return minimised;
  195855. }
  195856. void setFullScreen (const bool shouldBeFullScreen)
  195857. {
  195858. Rectangle<int> r (lastNonFullscreenBounds); // (get a copy of this before de-minimising)
  195859. setMinimised (false);
  195860. if (fullScreen != shouldBeFullScreen)
  195861. {
  195862. if (shouldBeFullScreen)
  195863. r = Desktop::getInstance().getMainMonitorArea();
  195864. if (! r.isEmpty())
  195865. setBounds (r.getX(), r.getY(), r.getWidth(), r.getHeight(), shouldBeFullScreen);
  195866. getComponent()->repaint();
  195867. }
  195868. }
  195869. bool isFullScreen() const
  195870. {
  195871. return fullScreen;
  195872. }
  195873. bool isChildWindowOf (Window possibleParent) const
  195874. {
  195875. Window* windowList = 0;
  195876. uint32 windowListSize = 0;
  195877. Window parent, root;
  195878. ScopedXLock xlock;
  195879. if (XQueryTree (display, windowH, &root, &parent, &windowList, &windowListSize) != 0)
  195880. {
  195881. if (windowList != 0)
  195882. XFree (windowList);
  195883. return parent == possibleParent;
  195884. }
  195885. return false;
  195886. }
  195887. bool isFrontWindow() const
  195888. {
  195889. Window* windowList = 0;
  195890. uint32 windowListSize = 0;
  195891. bool result = false;
  195892. ScopedXLock xlock;
  195893. Window parent, root = RootWindow (display, DefaultScreen (display));
  195894. if (XQueryTree (display, root, &root, &parent, &windowList, &windowListSize) != 0)
  195895. {
  195896. for (int i = windowListSize; --i >= 0;)
  195897. {
  195898. LinuxComponentPeer* const peer = LinuxComponentPeer::getPeerFor (windowList[i]);
  195899. if (peer != 0)
  195900. {
  195901. result = (peer == this);
  195902. break;
  195903. }
  195904. }
  195905. }
  195906. if (windowList != 0)
  195907. XFree (windowList);
  195908. return result;
  195909. }
  195910. bool contains (const Point<int>& position, bool trueIfInAChildWindow) const
  195911. {
  195912. int x = position.getX();
  195913. int y = position.getY();
  195914. if (((unsigned int) x) >= (unsigned int) ww
  195915. || ((unsigned int) y) >= (unsigned int) wh)
  195916. return false;
  195917. bool inFront = false;
  195918. for (int i = 0; i < Desktop::getInstance().getNumComponents(); ++i)
  195919. {
  195920. Component* const c = Desktop::getInstance().getComponent (i);
  195921. if (inFront)
  195922. {
  195923. if (c->contains (x + wx - c->getScreenX(),
  195924. y + wy - c->getScreenY()))
  195925. {
  195926. return false;
  195927. }
  195928. }
  195929. else if (c == getComponent())
  195930. {
  195931. inFront = true;
  195932. }
  195933. }
  195934. if (trueIfInAChildWindow)
  195935. return true;
  195936. ::Window root, child;
  195937. unsigned int bw, depth;
  195938. int wx, wy, w, h;
  195939. ScopedXLock xlock;
  195940. if (! XGetGeometry (display, (::Drawable) windowH, &root,
  195941. &wx, &wy, (unsigned int*) &w, (unsigned int*) &h,
  195942. &bw, &depth))
  195943. {
  195944. return false;
  195945. }
  195946. if (! XTranslateCoordinates (display, windowH, windowH, x, y, &wx, &wy, &child))
  195947. return false;
  195948. return child == None;
  195949. }
  195950. const BorderSize getFrameSize() const
  195951. {
  195952. return BorderSize();
  195953. }
  195954. bool setAlwaysOnTop (bool alwaysOnTop)
  195955. {
  195956. if (windowH != 0)
  195957. {
  195958. const bool wasVisible = component->isVisible();
  195959. if (wasVisible)
  195960. setVisible (false); // doesn't always seem to work if the window is visible when this is done..
  195961. {
  195962. ScopedXLock xlock;
  195963. XSetWindowAttributes swa;
  195964. swa.override_redirect = alwaysOnTop ? True : False;
  195965. XChangeWindowAttributes (display, windowH, CWOverrideRedirect, &swa);
  195966. }
  195967. if (wasVisible)
  195968. setVisible (true);
  195969. }
  195970. return true;
  195971. }
  195972. void toFront (bool makeActive)
  195973. {
  195974. if (makeActive)
  195975. {
  195976. setVisible (true);
  195977. grabFocus();
  195978. }
  195979. XEvent ev;
  195980. ev.xclient.type = ClientMessage;
  195981. ev.xclient.serial = 0;
  195982. ev.xclient.send_event = True;
  195983. ev.xclient.message_type = Atoms::ActiveWin;
  195984. ev.xclient.window = windowH;
  195985. ev.xclient.format = 32;
  195986. ev.xclient.data.l[0] = 2;
  195987. ev.xclient.data.l[1] = CurrentTime;
  195988. ev.xclient.data.l[2] = 0;
  195989. ev.xclient.data.l[3] = 0;
  195990. ev.xclient.data.l[4] = 0;
  195991. {
  195992. ScopedXLock xlock;
  195993. XSendEvent (display, RootWindow (display, DefaultScreen (display)),
  195994. False,
  195995. SubstructureRedirectMask | SubstructureNotifyMask,
  195996. &ev);
  195997. XWindowAttributes attr;
  195998. XGetWindowAttributes (display, windowH, &attr);
  195999. if (attr.override_redirect)
  196000. XRaiseWindow (display, windowH);
  196001. XSync (display, False);
  196002. }
  196003. handleBroughtToFront();
  196004. }
  196005. void toBehind (ComponentPeer* other)
  196006. {
  196007. LinuxComponentPeer* const otherPeer = dynamic_cast <LinuxComponentPeer*> (other);
  196008. jassert (otherPeer != 0); // wrong type of window?
  196009. if (otherPeer != 0)
  196010. {
  196011. setMinimised (false);
  196012. Window newStack[] = { otherPeer->windowH, windowH };
  196013. ScopedXLock xlock;
  196014. XRestackWindows (display, newStack, 2);
  196015. }
  196016. }
  196017. bool isFocused() const
  196018. {
  196019. int revert;
  196020. Window focusedWindow = 0;
  196021. ScopedXLock xlock;
  196022. XGetInputFocus (display, &focusedWindow, &revert);
  196023. return focusedWindow == windowH;
  196024. }
  196025. void grabFocus()
  196026. {
  196027. XWindowAttributes atts;
  196028. ScopedXLock xlock;
  196029. if (windowH != 0
  196030. && XGetWindowAttributes (display, windowH, &atts)
  196031. && atts.map_state == IsViewable
  196032. && ! isFocused())
  196033. {
  196034. XSetInputFocus (display, windowH, RevertToParent, CurrentTime);
  196035. isActiveApplication = true;
  196036. }
  196037. }
  196038. void textInputRequired (const Point<int>&)
  196039. {
  196040. }
  196041. void repaint (int x, int y, int w, int h)
  196042. {
  196043. if (Rectangle<int>::intersectRectangles (x, y, w, h,
  196044. 0, 0,
  196045. getComponent()->getWidth(),
  196046. getComponent()->getHeight()))
  196047. {
  196048. repainter->repaint (x, y, w, h);
  196049. }
  196050. }
  196051. void performAnyPendingRepaintsNow()
  196052. {
  196053. repainter->performAnyPendingRepaintsNow();
  196054. }
  196055. static Pixmap juce_createColourPixmapFromImage (Display* display, const Image& image)
  196056. {
  196057. ScopedXLock xlock;
  196058. const int width = image.getWidth();
  196059. const int height = image.getHeight();
  196060. HeapBlock <uint32> colour (width * height);
  196061. int index = 0;
  196062. for (int y = 0; y < height; ++y)
  196063. for (int x = 0; x < width; ++x)
  196064. colour[index++] = image.getPixelAt (x, y).getARGB();
  196065. XImage* ximage = XCreateImage (display, CopyFromParent, 24, ZPixmap,
  196066. 0, reinterpret_cast<char*> (colour.getData()),
  196067. width, height, 32, 0);
  196068. Pixmap pixmap = XCreatePixmap (display, DefaultRootWindow (display),
  196069. width, height, 24);
  196070. GC gc = XCreateGC (display, pixmap, 0, 0);
  196071. XPutImage (display, pixmap, gc, ximage, 0, 0, 0, 0, width, height);
  196072. XFreeGC (display, gc);
  196073. return pixmap;
  196074. }
  196075. static Pixmap juce_createMaskPixmapFromImage (Display* display, const Image& image)
  196076. {
  196077. ScopedXLock xlock;
  196078. const int width = image.getWidth();
  196079. const int height = image.getHeight();
  196080. const int stride = (width + 7) >> 3;
  196081. HeapBlock <uint8> mask;
  196082. mask.calloc (stride * height);
  196083. const bool msbfirst = (BitmapBitOrder (display) == MSBFirst);
  196084. for (int y = 0; y < height; ++y)
  196085. {
  196086. for (int x = 0; x < width; ++x)
  196087. {
  196088. const uint8 bit = (uint8) (1 << (msbfirst ? (7 - (x & 7)) : (x & 7)));
  196089. const int offset = y * stride + (x >> 3);
  196090. if (image.getPixelAt (x, y).getAlpha() >= 128)
  196091. mask[offset] |= bit;
  196092. }
  196093. }
  196094. return XCreatePixmapFromBitmapData (display, DefaultRootWindow (display),
  196095. reinterpret_cast<char*> (mask.getData()), width, height, 1, 0, 1);
  196096. }
  196097. void setIcon (const Image& newIcon)
  196098. {
  196099. const int dataSize = newIcon.getWidth() * newIcon.getHeight() + 2;
  196100. HeapBlock <unsigned long> data (dataSize);
  196101. int index = 0;
  196102. data[index++] = newIcon.getWidth();
  196103. data[index++] = newIcon.getHeight();
  196104. for (int y = 0; y < newIcon.getHeight(); ++y)
  196105. for (int x = 0; x < newIcon.getWidth(); ++x)
  196106. data[index++] = newIcon.getPixelAt (x, y).getARGB();
  196107. ScopedXLock xlock;
  196108. XChangeProperty (display, windowH,
  196109. XInternAtom (display, "_NET_WM_ICON", False),
  196110. XA_CARDINAL, 32, PropModeReplace,
  196111. reinterpret_cast<unsigned char*> (data.getData()), dataSize);
  196112. deleteIconPixmaps();
  196113. XWMHints* wmHints = XGetWMHints (display, windowH);
  196114. if (wmHints == 0)
  196115. wmHints = XAllocWMHints();
  196116. wmHints->flags |= IconPixmapHint | IconMaskHint;
  196117. wmHints->icon_pixmap = juce_createColourPixmapFromImage (display, newIcon);
  196118. wmHints->icon_mask = juce_createMaskPixmapFromImage (display, newIcon);
  196119. XSetWMHints (display, windowH, wmHints);
  196120. XFree (wmHints);
  196121. XSync (display, False);
  196122. }
  196123. void deleteIconPixmaps()
  196124. {
  196125. ScopedXLock xlock;
  196126. XWMHints* wmHints = XGetWMHints (display, windowH);
  196127. if (wmHints != 0)
  196128. {
  196129. if ((wmHints->flags & IconPixmapHint) != 0)
  196130. {
  196131. wmHints->flags &= ~IconPixmapHint;
  196132. XFreePixmap (display, wmHints->icon_pixmap);
  196133. }
  196134. if ((wmHints->flags & IconMaskHint) != 0)
  196135. {
  196136. wmHints->flags &= ~IconMaskHint;
  196137. XFreePixmap (display, wmHints->icon_mask);
  196138. }
  196139. XSetWMHints (display, windowH, wmHints);
  196140. XFree (wmHints);
  196141. }
  196142. }
  196143. void handleWindowMessage (XEvent* event)
  196144. {
  196145. switch (event->xany.type)
  196146. {
  196147. case 2: // 'KeyPress'
  196148. {
  196149. ScopedXLock xlock;
  196150. XKeyEvent* const keyEvent = (XKeyEvent*) &event->xkey;
  196151. updateKeyStates (keyEvent->keycode, true);
  196152. char utf8 [64];
  196153. zeromem (utf8, sizeof (utf8));
  196154. KeySym sym;
  196155. {
  196156. const char* oldLocale = ::setlocale (LC_ALL, 0);
  196157. ::setlocale (LC_ALL, "");
  196158. XLookupString (keyEvent, utf8, sizeof (utf8), &sym, 0);
  196159. ::setlocale (LC_ALL, oldLocale);
  196160. }
  196161. const juce_wchar unicodeChar = *(const juce_wchar*) String::fromUTF8 (utf8, sizeof (utf8) - 1);
  196162. int keyCode = (int) unicodeChar;
  196163. if (keyCode < 0x20)
  196164. keyCode = XKeycodeToKeysym (display, keyEvent->keycode, currentModifiers.isShiftDown() ? 1 : 0);
  196165. const ModifierKeys oldMods (currentModifiers);
  196166. bool keyPressed = false;
  196167. const bool keyDownChange = (sym != NoSymbol) && ! updateKeyModifiersFromSym (sym, true);
  196168. if ((sym & 0xff00) == 0xff00)
  196169. {
  196170. // Translate keypad
  196171. if (sym == XK_KP_Divide)
  196172. keyCode = XK_slash;
  196173. else if (sym == XK_KP_Multiply)
  196174. keyCode = XK_asterisk;
  196175. else if (sym == XK_KP_Subtract)
  196176. keyCode = XK_hyphen;
  196177. else if (sym == XK_KP_Add)
  196178. keyCode = XK_plus;
  196179. else if (sym == XK_KP_Enter)
  196180. keyCode = XK_Return;
  196181. else if (sym == XK_KP_Decimal)
  196182. keyCode = Keys::numLock ? XK_period : XK_Delete;
  196183. else if (sym == XK_KP_0)
  196184. keyCode = Keys::numLock ? XK_0 : XK_Insert;
  196185. else if (sym == XK_KP_1)
  196186. keyCode = Keys::numLock ? XK_1 : XK_End;
  196187. else if (sym == XK_KP_2)
  196188. keyCode = Keys::numLock ? XK_2 : XK_Down;
  196189. else if (sym == XK_KP_3)
  196190. keyCode = Keys::numLock ? XK_3 : XK_Page_Down;
  196191. else if (sym == XK_KP_4)
  196192. keyCode = Keys::numLock ? XK_4 : XK_Left;
  196193. else if (sym == XK_KP_5)
  196194. keyCode = XK_5;
  196195. else if (sym == XK_KP_6)
  196196. keyCode = Keys::numLock ? XK_6 : XK_Right;
  196197. else if (sym == XK_KP_7)
  196198. keyCode = Keys::numLock ? XK_7 : XK_Home;
  196199. else if (sym == XK_KP_8)
  196200. keyCode = Keys::numLock ? XK_8 : XK_Up;
  196201. else if (sym == XK_KP_9)
  196202. keyCode = Keys::numLock ? XK_9 : XK_Page_Up;
  196203. switch (sym)
  196204. {
  196205. case XK_Left:
  196206. case XK_Right:
  196207. case XK_Up:
  196208. case XK_Down:
  196209. case XK_Page_Up:
  196210. case XK_Page_Down:
  196211. case XK_End:
  196212. case XK_Home:
  196213. case XK_Delete:
  196214. case XK_Insert:
  196215. keyPressed = true;
  196216. keyCode = (sym & 0xff) | Keys::extendedKeyModifier;
  196217. break;
  196218. case XK_Tab:
  196219. case XK_Return:
  196220. case XK_Escape:
  196221. case XK_BackSpace:
  196222. keyPressed = true;
  196223. keyCode &= 0xff;
  196224. break;
  196225. default:
  196226. {
  196227. if (sym >= XK_F1 && sym <= XK_F16)
  196228. {
  196229. keyPressed = true;
  196230. keyCode = (sym & 0xff) | Keys::extendedKeyModifier;
  196231. }
  196232. break;
  196233. }
  196234. }
  196235. }
  196236. if (utf8[0] != 0 || ((sym & 0xff00) == 0 && sym >= 8))
  196237. keyPressed = true;
  196238. if (oldMods != currentModifiers)
  196239. handleModifierKeysChange();
  196240. if (keyDownChange)
  196241. handleKeyUpOrDown (true);
  196242. if (keyPressed)
  196243. handleKeyPress (keyCode, unicodeChar);
  196244. break;
  196245. }
  196246. case KeyRelease:
  196247. {
  196248. const XKeyEvent* const keyEvent = (const XKeyEvent*) &event->xkey;
  196249. updateKeyStates (keyEvent->keycode, false);
  196250. ScopedXLock xlock;
  196251. KeySym sym = XKeycodeToKeysym (display, keyEvent->keycode, 0);
  196252. const ModifierKeys oldMods (currentModifiers);
  196253. const bool keyDownChange = (sym != NoSymbol) && ! updateKeyModifiersFromSym (sym, false);
  196254. if (oldMods != currentModifiers)
  196255. handleModifierKeysChange();
  196256. if (keyDownChange)
  196257. handleKeyUpOrDown (false);
  196258. break;
  196259. }
  196260. case ButtonPress:
  196261. {
  196262. const XButtonPressedEvent* const buttonPressEvent = (const XButtonPressedEvent*) &event->xbutton;
  196263. updateKeyModifiers (buttonPressEvent->state);
  196264. bool buttonMsg = false;
  196265. const int map = pointerMap [buttonPressEvent->button - Button1];
  196266. if (map == Keys::WheelUp || map == Keys::WheelDown)
  196267. {
  196268. handleMouseWheel (0, Point<int> (buttonPressEvent->x, buttonPressEvent->y),
  196269. getEventTime (buttonPressEvent->time), 0, map == Keys::WheelDown ? -84.0f : 84.0f);
  196270. }
  196271. if (map == Keys::LeftButton)
  196272. {
  196273. currentModifiers = currentModifiers.withFlags (ModifierKeys::leftButtonModifier);
  196274. buttonMsg = true;
  196275. }
  196276. else if (map == Keys::RightButton)
  196277. {
  196278. currentModifiers = currentModifiers.withFlags (ModifierKeys::rightButtonModifier);
  196279. buttonMsg = true;
  196280. }
  196281. else if (map == Keys::MiddleButton)
  196282. {
  196283. currentModifiers = currentModifiers.withFlags (ModifierKeys::middleButtonModifier);
  196284. buttonMsg = true;
  196285. }
  196286. if (buttonMsg)
  196287. {
  196288. toFront (true);
  196289. handleMouseEvent (0, Point<int> (buttonPressEvent->x, buttonPressEvent->y), currentModifiers,
  196290. getEventTime (buttonPressEvent->time));
  196291. }
  196292. clearLastMousePos();
  196293. break;
  196294. }
  196295. case ButtonRelease:
  196296. {
  196297. const XButtonReleasedEvent* const buttonRelEvent = (const XButtonReleasedEvent*) &event->xbutton;
  196298. updateKeyModifiers (buttonRelEvent->state);
  196299. const int map = pointerMap [buttonRelEvent->button - Button1];
  196300. if (map == Keys::LeftButton)
  196301. currentModifiers = currentModifiers.withoutFlags (ModifierKeys::leftButtonModifier);
  196302. else if (map == Keys::RightButton)
  196303. currentModifiers = currentModifiers.withoutFlags (ModifierKeys::rightButtonModifier);
  196304. else if (map == Keys::MiddleButton)
  196305. currentModifiers = currentModifiers.withoutFlags (ModifierKeys::middleButtonModifier);
  196306. handleMouseEvent (0, Point<int> (buttonRelEvent->x, buttonRelEvent->y), currentModifiers,
  196307. getEventTime (buttonRelEvent->time));
  196308. clearLastMousePos();
  196309. break;
  196310. }
  196311. case MotionNotify:
  196312. {
  196313. const XPointerMovedEvent* const movedEvent = (const XPointerMovedEvent*) &event->xmotion;
  196314. updateKeyModifiers (movedEvent->state);
  196315. const Point<int> mousePos (Desktop::getMousePosition());
  196316. if (lastMousePos != mousePos)
  196317. {
  196318. lastMousePos = mousePos;
  196319. if (parentWindow != 0 && (styleFlags & windowHasTitleBar) == 0)
  196320. {
  196321. Window wRoot = 0, wParent = 0;
  196322. {
  196323. ScopedXLock xlock;
  196324. unsigned int numChildren;
  196325. Window* wChild = 0;
  196326. XQueryTree (display, windowH, &wRoot, &wParent, &wChild, &numChildren);
  196327. }
  196328. if (wParent != 0
  196329. && wParent != windowH
  196330. && wParent != wRoot)
  196331. {
  196332. parentWindow = wParent;
  196333. updateBounds();
  196334. }
  196335. else
  196336. {
  196337. parentWindow = 0;
  196338. }
  196339. }
  196340. handleMouseEvent (0, mousePos - getScreenPosition(), currentModifiers, getEventTime (movedEvent->time));
  196341. }
  196342. break;
  196343. }
  196344. case EnterNotify:
  196345. {
  196346. clearLastMousePos();
  196347. const XEnterWindowEvent* const enterEvent = (const XEnterWindowEvent*) &event->xcrossing;
  196348. if (! currentModifiers.isAnyMouseButtonDown())
  196349. {
  196350. updateKeyModifiers (enterEvent->state);
  196351. handleMouseEvent (0, Point<int> (enterEvent->x, enterEvent->y), currentModifiers, getEventTime (enterEvent->time));
  196352. }
  196353. break;
  196354. }
  196355. case LeaveNotify:
  196356. {
  196357. const XLeaveWindowEvent* const leaveEvent = (const XLeaveWindowEvent*) &event->xcrossing;
  196358. // Suppress the normal leave if we've got a pointer grab, or if
  196359. // it's a bogus one caused by clicking a mouse button when running
  196360. // in a Window manager
  196361. if (((! currentModifiers.isAnyMouseButtonDown()) && leaveEvent->mode == NotifyNormal)
  196362. || leaveEvent->mode == NotifyUngrab)
  196363. {
  196364. updateKeyModifiers (leaveEvent->state);
  196365. handleMouseEvent (0, Point<int> (leaveEvent->x, leaveEvent->y), currentModifiers, getEventTime (leaveEvent->time));
  196366. }
  196367. break;
  196368. }
  196369. case FocusIn:
  196370. {
  196371. isActiveApplication = true;
  196372. if (isFocused())
  196373. handleFocusGain();
  196374. break;
  196375. }
  196376. case FocusOut:
  196377. {
  196378. isActiveApplication = false;
  196379. if (! isFocused())
  196380. handleFocusLoss();
  196381. break;
  196382. }
  196383. case Expose:
  196384. {
  196385. // Batch together all pending expose events
  196386. XExposeEvent* exposeEvent = (XExposeEvent*) &event->xexpose;
  196387. XEvent nextEvent;
  196388. ScopedXLock xlock;
  196389. if (exposeEvent->window != windowH)
  196390. {
  196391. Window child;
  196392. XTranslateCoordinates (display, exposeEvent->window, windowH,
  196393. exposeEvent->x, exposeEvent->y, &exposeEvent->x, &exposeEvent->y,
  196394. &child);
  196395. }
  196396. repaint (exposeEvent->x, exposeEvent->y,
  196397. exposeEvent->width, exposeEvent->height);
  196398. while (XEventsQueued (display, QueuedAfterFlush) > 0)
  196399. {
  196400. XPeekEvent (display, (XEvent*) &nextEvent);
  196401. if (nextEvent.type != Expose || nextEvent.xany.window != event->xany.window)
  196402. break;
  196403. XNextEvent (display, (XEvent*) &nextEvent);
  196404. XExposeEvent* nextExposeEvent = (XExposeEvent*) &nextEvent.xexpose;
  196405. repaint (nextExposeEvent->x, nextExposeEvent->y,
  196406. nextExposeEvent->width, nextExposeEvent->height);
  196407. }
  196408. break;
  196409. }
  196410. case CirculateNotify:
  196411. case CreateNotify:
  196412. case DestroyNotify:
  196413. // Think we can ignore these
  196414. break;
  196415. case ConfigureNotify:
  196416. {
  196417. updateBounds();
  196418. updateBorderSize();
  196419. handleMovedOrResized();
  196420. // if the native title bar is dragged, need to tell any active menus, etc.
  196421. if ((styleFlags & windowHasTitleBar) != 0
  196422. && component->isCurrentlyBlockedByAnotherModalComponent())
  196423. {
  196424. Component* const currentModalComp = Component::getCurrentlyModalComponent();
  196425. if (currentModalComp != 0)
  196426. currentModalComp->inputAttemptWhenModal();
  196427. }
  196428. XConfigureEvent* const confEvent = (XConfigureEvent*) &event->xconfigure;
  196429. if (confEvent->window == windowH
  196430. && confEvent->above != 0
  196431. && isFrontWindow())
  196432. {
  196433. handleBroughtToFront();
  196434. }
  196435. break;
  196436. }
  196437. case ReparentNotify:
  196438. case GravityNotify:
  196439. {
  196440. parentWindow = 0;
  196441. Window wRoot = 0;
  196442. Window* wChild = 0;
  196443. unsigned int numChildren;
  196444. {
  196445. ScopedXLock xlock;
  196446. XQueryTree (display, windowH, &wRoot, &parentWindow, &wChild, &numChildren);
  196447. }
  196448. if (parentWindow == windowH || parentWindow == wRoot)
  196449. parentWindow = 0;
  196450. updateBounds();
  196451. updateBorderSize();
  196452. handleMovedOrResized();
  196453. break;
  196454. }
  196455. case MapNotify:
  196456. mapped = true;
  196457. handleBroughtToFront();
  196458. break;
  196459. case UnmapNotify:
  196460. mapped = false;
  196461. break;
  196462. case MappingNotify:
  196463. {
  196464. XMappingEvent* mappingEvent = (XMappingEvent*) &event->xmapping;
  196465. if (mappingEvent->request != MappingPointer)
  196466. {
  196467. // Deal with modifier/keyboard mapping
  196468. ScopedXLock xlock;
  196469. XRefreshKeyboardMapping (mappingEvent);
  196470. updateModifierMappings();
  196471. }
  196472. break;
  196473. }
  196474. case ClientMessage:
  196475. {
  196476. const XClientMessageEvent* const clientMsg = (const XClientMessageEvent*) &event->xclient;
  196477. if (clientMsg->message_type == Atoms::Protocols && clientMsg->format == 32)
  196478. {
  196479. const Atom atom = (Atom) clientMsg->data.l[0];
  196480. if (atom == Atoms::ProtocolList [Atoms::TAKE_FOCUS])
  196481. {
  196482. XWindowAttributes atts;
  196483. ScopedXLock xlock;
  196484. if (clientMsg->window != 0
  196485. && XGetWindowAttributes (display, clientMsg->window, &atts))
  196486. {
  196487. if (atts.map_state == IsViewable)
  196488. XSetInputFocus (display, clientMsg->window, RevertToParent, clientMsg->data.l[1]);
  196489. }
  196490. }
  196491. else if (atom == Atoms::ProtocolList [Atoms::DELETE_WINDOW])
  196492. {
  196493. handleUserClosingWindow();
  196494. }
  196495. }
  196496. else if (clientMsg->message_type == Atoms::XdndEnter)
  196497. {
  196498. handleDragAndDropEnter (clientMsg);
  196499. }
  196500. else if (clientMsg->message_type == Atoms::XdndLeave)
  196501. {
  196502. resetDragAndDrop();
  196503. }
  196504. else if (clientMsg->message_type == Atoms::XdndPosition)
  196505. {
  196506. handleDragAndDropPosition (clientMsg);
  196507. }
  196508. else if (clientMsg->message_type == Atoms::XdndDrop)
  196509. {
  196510. handleDragAndDropDrop (clientMsg);
  196511. }
  196512. else if (clientMsg->message_type == Atoms::XdndStatus)
  196513. {
  196514. handleDragAndDropStatus (clientMsg);
  196515. }
  196516. else if (clientMsg->message_type == Atoms::XdndFinished)
  196517. {
  196518. resetDragAndDrop();
  196519. }
  196520. break;
  196521. }
  196522. case SelectionNotify:
  196523. handleDragAndDropSelection (event);
  196524. break;
  196525. case SelectionClear:
  196526. case SelectionRequest:
  196527. break;
  196528. default:
  196529. #if JUCE_USE_XSHM
  196530. {
  196531. ScopedXLock xlock;
  196532. if (event->xany.type == XShmGetEventBase (display))
  196533. repainter->notifyPaintCompleted();
  196534. }
  196535. #endif
  196536. break;
  196537. }
  196538. }
  196539. void showMouseCursor (Cursor cursor) throw()
  196540. {
  196541. ScopedXLock xlock;
  196542. XDefineCursor (display, windowH, cursor);
  196543. }
  196544. void setTaskBarIcon (const Image& image)
  196545. {
  196546. ScopedXLock xlock;
  196547. deleteTaskBarIcon();
  196548. taskbarImage = image.createCopy();
  196549. Screen* const screen = XDefaultScreenOfDisplay (display);
  196550. const int screenNumber = XScreenNumberOfScreen (screen);
  196551. String screenAtom ("_NET_SYSTEM_TRAY_S");
  196552. screenAtom << screenNumber;
  196553. Atom selectionAtom = XInternAtom (display, screenAtom.toUTF8(), false);
  196554. XGrabServer (display);
  196555. Window managerWin = XGetSelectionOwner (display, selectionAtom);
  196556. if (managerWin != None)
  196557. XSelectInput (display, managerWin, StructureNotifyMask);
  196558. XUngrabServer (display);
  196559. XFlush (display);
  196560. if (managerWin != None)
  196561. {
  196562. XEvent ev;
  196563. zerostruct (ev);
  196564. ev.xclient.type = ClientMessage;
  196565. ev.xclient.window = managerWin;
  196566. ev.xclient.message_type = XInternAtom (display, "_NET_SYSTEM_TRAY_OPCODE", False);
  196567. ev.xclient.format = 32;
  196568. ev.xclient.data.l[0] = CurrentTime;
  196569. ev.xclient.data.l[1] = SYSTEM_TRAY_REQUEST_DOCK;
  196570. ev.xclient.data.l[2] = windowH;
  196571. ev.xclient.data.l[3] = 0;
  196572. ev.xclient.data.l[4] = 0;
  196573. XSendEvent (display, managerWin, False, NoEventMask, &ev);
  196574. XSync (display, False);
  196575. }
  196576. // For older KDE's ...
  196577. long atomData = 1;
  196578. Atom trayAtom = XInternAtom (display, "KWM_DOCKWINDOW", false);
  196579. XChangeProperty (display, windowH, trayAtom, trayAtom, 32, PropModeReplace, (unsigned char*) &atomData, 1);
  196580. // For more recent KDE's...
  196581. trayAtom = XInternAtom (display, "_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR", false);
  196582. XChangeProperty (display, windowH, trayAtom, XA_WINDOW, 32, PropModeReplace, (unsigned char*) &windowH, 1);
  196583. // a minimum size must be specified for GNOME and Xfce, otherwise the icon is displayed with a width of 1
  196584. XSizeHints* hints = XAllocSizeHints();
  196585. hints->flags = PMinSize;
  196586. hints->min_width = 22;
  196587. hints->min_height = 22;
  196588. XSetWMNormalHints (display, windowH, hints);
  196589. XFree (hints);
  196590. }
  196591. void deleteTaskBarIcon()
  196592. {
  196593. deleteAndZero (taskbarImage);
  196594. }
  196595. const Image* getTaskbarIcon() const throw() { return taskbarImage; }
  196596. juce_UseDebuggingNewOperator
  196597. bool dontRepaint;
  196598. static ModifierKeys currentModifiers;
  196599. private:
  196600. class LinuxRepaintManager : public Timer
  196601. {
  196602. public:
  196603. LinuxRepaintManager (LinuxComponentPeer* const peer_)
  196604. : peer (peer_),
  196605. lastTimeImageUsed (0)
  196606. {
  196607. #if JUCE_USE_XSHM
  196608. shmCompletedDrawing = true;
  196609. useARGBImagesForRendering = isShmAvailable();
  196610. if (useARGBImagesForRendering)
  196611. {
  196612. ScopedXLock xlock;
  196613. XShmSegmentInfo segmentinfo;
  196614. XImage* const testImage
  196615. = XShmCreateImage (display, DefaultVisual (display, DefaultScreen (display)),
  196616. 24, ZPixmap, 0, &segmentinfo, 64, 64);
  196617. useARGBImagesForRendering = (testImage->bits_per_pixel == 32);
  196618. XDestroyImage (testImage);
  196619. }
  196620. #endif
  196621. }
  196622. ~LinuxRepaintManager()
  196623. {
  196624. }
  196625. void timerCallback()
  196626. {
  196627. #if JUCE_USE_XSHM
  196628. if (! shmCompletedDrawing)
  196629. return;
  196630. #endif
  196631. if (! regionsNeedingRepaint.isEmpty())
  196632. {
  196633. stopTimer();
  196634. performAnyPendingRepaintsNow();
  196635. }
  196636. else if (Time::getApproximateMillisecondCounter() > lastTimeImageUsed + 3000)
  196637. {
  196638. stopTimer();
  196639. image = 0;
  196640. }
  196641. }
  196642. void repaint (int x, int y, int w, int h)
  196643. {
  196644. if (! isTimerRunning())
  196645. startTimer (repaintTimerPeriod);
  196646. regionsNeedingRepaint.add (x, y, w, h);
  196647. }
  196648. void performAnyPendingRepaintsNow()
  196649. {
  196650. #if JUCE_USE_XSHM
  196651. if (! shmCompletedDrawing)
  196652. {
  196653. startTimer (repaintTimerPeriod);
  196654. return;
  196655. }
  196656. #endif
  196657. peer->clearMaskedRegion();
  196658. RectangleList originalRepaintRegion (regionsNeedingRepaint);
  196659. regionsNeedingRepaint.clear();
  196660. const Rectangle<int> totalArea (originalRepaintRegion.getBounds());
  196661. if (! totalArea.isEmpty())
  196662. {
  196663. if (image == 0 || image->getWidth() < totalArea.getWidth()
  196664. || image->getHeight() < totalArea.getHeight())
  196665. {
  196666. #if JUCE_USE_XSHM
  196667. image = new XBitmapImage (useARGBImagesForRendering ? Image::ARGB
  196668. : Image::RGB,
  196669. #else
  196670. image = new XBitmapImage (Image::RGB,
  196671. #endif
  196672. (totalArea.getWidth() + 31) & ~31,
  196673. (totalArea.getHeight() + 31) & ~31,
  196674. false,
  196675. peer->depth,
  196676. peer->visual);
  196677. }
  196678. startTimer (repaintTimerPeriod);
  196679. LowLevelGraphicsSoftwareRenderer context (*image);
  196680. context.setOrigin (-totalArea.getX(), -totalArea.getY());
  196681. if (context.clipToRectangleList (originalRepaintRegion))
  196682. {
  196683. if (peer->depth == 32)
  196684. {
  196685. RectangleList::Iterator i (originalRepaintRegion);
  196686. while (i.next())
  196687. {
  196688. const Rectangle<int>& r = *i.getRectangle();
  196689. image->clear (r.getX() - totalArea.getX(), r.getY() - totalArea.getY(), r.getWidth(), r.getHeight());
  196690. }
  196691. }
  196692. peer->handlePaint (context);
  196693. }
  196694. if (! peer->maskedRegion.isEmpty())
  196695. originalRepaintRegion.subtract (peer->maskedRegion);
  196696. for (RectangleList::Iterator i (originalRepaintRegion); i.next();)
  196697. {
  196698. #if JUCE_USE_XSHM
  196699. shmCompletedDrawing = false;
  196700. #endif
  196701. const Rectangle<int>& r = *i.getRectangle();
  196702. image->blitToWindow (peer->windowH,
  196703. r.getX(), r.getY(), r.getWidth(), r.getHeight(),
  196704. r.getX() - totalArea.getX(), r.getY() - totalArea.getY());
  196705. }
  196706. }
  196707. lastTimeImageUsed = Time::getApproximateMillisecondCounter();
  196708. startTimer (repaintTimerPeriod);
  196709. }
  196710. #if JUCE_USE_XSHM
  196711. void notifyPaintCompleted() { shmCompletedDrawing = true; }
  196712. #endif
  196713. private:
  196714. enum { repaintTimerPeriod = 1000 / 100 };
  196715. LinuxComponentPeer* const peer;
  196716. ScopedPointer <XBitmapImage> image;
  196717. uint32 lastTimeImageUsed;
  196718. RectangleList regionsNeedingRepaint;
  196719. #if JUCE_USE_XSHM
  196720. bool useARGBImagesForRendering, shmCompletedDrawing;
  196721. #endif
  196722. LinuxRepaintManager (const LinuxRepaintManager&);
  196723. LinuxRepaintManager& operator= (const LinuxRepaintManager&);
  196724. };
  196725. ScopedPointer <LinuxRepaintManager> repainter;
  196726. friend class LinuxRepaintManager;
  196727. Window windowH, parentWindow;
  196728. int wx, wy, ww, wh;
  196729. Image* taskbarImage;
  196730. bool fullScreen, mapped;
  196731. Visual* visual;
  196732. int depth;
  196733. BorderSize windowBorder;
  196734. struct MotifWmHints
  196735. {
  196736. unsigned long flags;
  196737. unsigned long functions;
  196738. unsigned long decorations;
  196739. long input_mode;
  196740. unsigned long status;
  196741. };
  196742. static void updateKeyStates (const int keycode, const bool press) throw()
  196743. {
  196744. const int keybyte = keycode >> 3;
  196745. const int keybit = (1 << (keycode & 7));
  196746. if (press)
  196747. Keys::keyStates [keybyte] |= keybit;
  196748. else
  196749. Keys::keyStates [keybyte] &= ~keybit;
  196750. }
  196751. static void updateKeyModifiers (const int status) throw()
  196752. {
  196753. int keyMods = 0;
  196754. if (status & ShiftMask) keyMods |= ModifierKeys::shiftModifier;
  196755. if (status & ControlMask) keyMods |= ModifierKeys::ctrlModifier;
  196756. if (status & Keys::AltMask) keyMods |= ModifierKeys::altModifier;
  196757. currentModifiers = currentModifiers.withOnlyMouseButtons().withFlags (keyMods);
  196758. Keys::numLock = ((status & Keys::NumLockMask) != 0);
  196759. Keys::capsLock = ((status & LockMask) != 0);
  196760. }
  196761. static bool updateKeyModifiersFromSym (KeySym sym, const bool press) throw()
  196762. {
  196763. int modifier = 0;
  196764. bool isModifier = true;
  196765. switch (sym)
  196766. {
  196767. case XK_Shift_L:
  196768. case XK_Shift_R:
  196769. modifier = ModifierKeys::shiftModifier;
  196770. break;
  196771. case XK_Control_L:
  196772. case XK_Control_R:
  196773. modifier = ModifierKeys::ctrlModifier;
  196774. break;
  196775. case XK_Alt_L:
  196776. case XK_Alt_R:
  196777. modifier = ModifierKeys::altModifier;
  196778. break;
  196779. case XK_Num_Lock:
  196780. if (press)
  196781. Keys::numLock = ! Keys::numLock;
  196782. break;
  196783. case XK_Caps_Lock:
  196784. if (press)
  196785. Keys::capsLock = ! Keys::capsLock;
  196786. break;
  196787. case XK_Scroll_Lock:
  196788. break;
  196789. default:
  196790. isModifier = false;
  196791. break;
  196792. }
  196793. if (modifier != 0)
  196794. {
  196795. if (press)
  196796. currentModifiers = currentModifiers.withFlags (modifier);
  196797. else
  196798. currentModifiers = currentModifiers.withoutFlags (modifier);
  196799. }
  196800. return isModifier;
  196801. }
  196802. // Alt and Num lock are not defined by standard X
  196803. // modifier constants: check what they're mapped to
  196804. static void updateModifierMappings() throw()
  196805. {
  196806. ScopedXLock xlock;
  196807. const int altLeftCode = XKeysymToKeycode (display, XK_Alt_L);
  196808. const int numLockCode = XKeysymToKeycode (display, XK_Num_Lock);
  196809. Keys::AltMask = 0;
  196810. Keys::NumLockMask = 0;
  196811. XModifierKeymap* mapping = XGetModifierMapping (display);
  196812. if (mapping)
  196813. {
  196814. for (int i = 0; i < 8; i++)
  196815. {
  196816. if (mapping->modifiermap [i << 1] == altLeftCode)
  196817. Keys::AltMask = 1 << i;
  196818. else if (mapping->modifiermap [i << 1] == numLockCode)
  196819. Keys::NumLockMask = 1 << i;
  196820. }
  196821. XFreeModifiermap (mapping);
  196822. }
  196823. }
  196824. void removeWindowDecorations (Window wndH)
  196825. {
  196826. Atom hints = XInternAtom (display, "_MOTIF_WM_HINTS", True);
  196827. if (hints != None)
  196828. {
  196829. MotifWmHints motifHints;
  196830. zerostruct (motifHints);
  196831. motifHints.flags = 2; /* MWM_HINTS_DECORATIONS */
  196832. motifHints.decorations = 0;
  196833. ScopedXLock xlock;
  196834. XChangeProperty (display, wndH, hints, hints, 32, PropModeReplace,
  196835. (unsigned char*) &motifHints, 4);
  196836. }
  196837. hints = XInternAtom (display, "_WIN_HINTS", True);
  196838. if (hints != None)
  196839. {
  196840. long gnomeHints = 0;
  196841. ScopedXLock xlock;
  196842. XChangeProperty (display, wndH, hints, hints, 32, PropModeReplace,
  196843. (unsigned char*) &gnomeHints, 1);
  196844. }
  196845. hints = XInternAtom (display, "KWM_WIN_DECORATION", True);
  196846. if (hints != None)
  196847. {
  196848. long kwmHints = 2; /*KDE_tinyDecoration*/
  196849. ScopedXLock xlock;
  196850. XChangeProperty (display, wndH, hints, hints, 32, PropModeReplace,
  196851. (unsigned char*) &kwmHints, 1);
  196852. }
  196853. }
  196854. void addWindowButtons (Window wndH)
  196855. {
  196856. ScopedXLock xlock;
  196857. Atom hints = XInternAtom (display, "_MOTIF_WM_HINTS", True);
  196858. if (hints != None)
  196859. {
  196860. MotifWmHints motifHints;
  196861. zerostruct (motifHints);
  196862. motifHints.flags = 1 | 2; /* MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS */
  196863. motifHints.decorations = 2 /* MWM_DECOR_BORDER */ | 8 /* MWM_DECOR_TITLE */ | 16; /* MWM_DECOR_MENU */
  196864. motifHints.functions = 4 /* MWM_FUNC_MOVE */;
  196865. if ((styleFlags & windowHasCloseButton) != 0)
  196866. motifHints.functions |= 32; /* MWM_FUNC_CLOSE */
  196867. if ((styleFlags & windowHasMinimiseButton) != 0)
  196868. {
  196869. motifHints.functions |= 8; /* MWM_FUNC_MINIMIZE */
  196870. motifHints.decorations |= 0x20; /* MWM_DECOR_MINIMIZE */
  196871. }
  196872. if ((styleFlags & windowHasMaximiseButton) != 0)
  196873. {
  196874. motifHints.functions |= 0x10; /* MWM_FUNC_MAXIMIZE */
  196875. motifHints.decorations |= 0x40; /* MWM_DECOR_MAXIMIZE */
  196876. }
  196877. if ((styleFlags & windowIsResizable) != 0)
  196878. {
  196879. motifHints.functions |= 2; /* MWM_FUNC_RESIZE */
  196880. motifHints.decorations |= 0x4; /* MWM_DECOR_RESIZEH */
  196881. }
  196882. XChangeProperty (display, wndH, hints, hints, 32, 0, (unsigned char*) &motifHints, 5);
  196883. }
  196884. hints = XInternAtom (display, "_NET_WM_ALLOWED_ACTIONS", True);
  196885. if (hints != None)
  196886. {
  196887. int netHints [6];
  196888. int num = 0;
  196889. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_RESIZE", (styleFlags & windowIsResizable) ? True : False);
  196890. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_FULLSCREEN", (styleFlags & windowHasMaximiseButton) ? True : False);
  196891. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_MINIMIZE", (styleFlags & windowHasMinimiseButton) ? True : False);
  196892. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_CLOSE", (styleFlags & windowHasCloseButton) ? True : False);
  196893. XChangeProperty (display, wndH, hints, XA_ATOM, 32, PropModeReplace,
  196894. (unsigned char*) &netHints, num);
  196895. }
  196896. }
  196897. void setWindowType (Window wndH)
  196898. {
  196899. int netHints [2];
  196900. int numHints = 0;
  196901. if ((styleFlags & windowIsTemporary) != 0
  196902. || ((styleFlags & windowHasDropShadow) == 0 && Desktop::canUseSemiTransparentWindows()))
  196903. {
  196904. netHints [numHints] = XInternAtom (display, "_NET_WM_WINDOW_TYPE_COMBO", True);
  196905. }
  196906. else
  196907. {
  196908. netHints [numHints] = XInternAtom (display, "_NET_WM_WINDOW_TYPE_NORMAL", True);
  196909. }
  196910. if (netHints [numHints] != 0)
  196911. ++numHints;
  196912. netHints[numHints] = XInternAtom (display, "_KDE_NET_WM_WINDOW_TYPE_OVERRIDE", True);
  196913. if (netHints [numHints] != 0)
  196914. ++numHints;
  196915. XChangeProperty (display, wndH, Atoms::WindowType, XA_ATOM, 32, PropModeReplace,
  196916. (unsigned char*) &netHints, numHints);
  196917. if ((styleFlags & windowAppearsOnTaskbar) == 0)
  196918. {
  196919. }
  196920. }
  196921. void createWindow()
  196922. {
  196923. ScopedXLock xlock;
  196924. Atoms::initialiseAtoms();
  196925. resetDragAndDrop();
  196926. // Get defaults for various properties
  196927. const int screen = DefaultScreen (display);
  196928. Window root = RootWindow (display, screen);
  196929. // Try to obtain a 32-bit visual or fallback to 24 or 16
  196930. visual = Visuals::findVisualFormat ((styleFlags & windowIsSemiTransparent) ? 32 : 24, depth);
  196931. if (visual == 0)
  196932. {
  196933. Logger::outputDebugString ("ERROR: System doesn't support 32, 24 or 16 bit RGB display.\n");
  196934. Process::terminate();
  196935. }
  196936. // Create and install a colormap suitable fr our visual
  196937. Colormap colormap = XCreateColormap (display, root, visual, AllocNone);
  196938. XInstallColormap (display, colormap);
  196939. // Set up the window attributes
  196940. XSetWindowAttributes swa;
  196941. swa.border_pixel = 0;
  196942. swa.background_pixmap = None;
  196943. swa.colormap = colormap;
  196944. swa.override_redirect = getComponent()->isAlwaysOnTop() ? True : False;
  196945. swa.event_mask = eventMask;
  196946. Window wndH = XCreateWindow (display, root,
  196947. 0, 0, 1, 1,
  196948. 0, depth, InputOutput, visual,
  196949. CWBorderPixel | CWColormap | CWBackPixmap | CWEventMask | CWOverrideRedirect,
  196950. &swa);
  196951. XGrabButton (display, AnyButton, AnyModifier, wndH, False,
  196952. ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
  196953. GrabModeAsync, GrabModeAsync, None, None);
  196954. // Set the window context to identify the window handle object
  196955. if (XSaveContext (display, (XID) wndH, improbableNumber, (XPointer) this))
  196956. {
  196957. // Failed
  196958. jassertfalse
  196959. Logger::outputDebugString ("Failed to create context information for window.\n");
  196960. XDestroyWindow (display, wndH);
  196961. wndH = 0;
  196962. }
  196963. // Set window manager hints
  196964. XWMHints* wmHints = XAllocWMHints();
  196965. wmHints->flags = InputHint | StateHint;
  196966. wmHints->input = True; // Locally active input model
  196967. wmHints->initial_state = NormalState;
  196968. XSetWMHints (display, wndH, wmHints);
  196969. XFree (wmHints);
  196970. // Set the window type
  196971. setWindowType (wndH);
  196972. // Define decoration
  196973. if ((styleFlags & windowHasTitleBar) == 0)
  196974. removeWindowDecorations (wndH);
  196975. else
  196976. addWindowButtons (wndH);
  196977. // Set window name
  196978. setWindowTitle (wndH, getComponent()->getName());
  196979. // Associate the PID, allowing to be shut down when something goes wrong
  196980. unsigned long pid = getpid();
  196981. XChangeProperty (display, wndH, Atoms::Pid, XA_CARDINAL, 32, PropModeReplace,
  196982. (unsigned char*) &pid, 1);
  196983. // Set window manager protocols
  196984. XChangeProperty (display, wndH, Atoms::Protocols, XA_ATOM, 32, PropModeReplace,
  196985. (unsigned char*) Atoms::ProtocolList, 2);
  196986. // Set drag and drop flags
  196987. XChangeProperty (display, wndH, Atoms::XdndTypeList, XA_ATOM, 32, PropModeReplace,
  196988. (const unsigned char*) Atoms::allowedMimeTypes, numElementsInArray (Atoms::allowedMimeTypes));
  196989. XChangeProperty (display, wndH, Atoms::XdndActionList, XA_ATOM, 32, PropModeReplace,
  196990. (const unsigned char*) Atoms::allowedActions, numElementsInArray (Atoms::allowedActions));
  196991. XChangeProperty (display, wndH, Atoms::XdndActionDescription, XA_STRING, 8, PropModeReplace,
  196992. (const unsigned char*) "", 0);
  196993. unsigned long dndVersion = Atoms::DndVersion;
  196994. XChangeProperty (display, wndH, Atoms::XdndAware, XA_ATOM, 32, PropModeReplace,
  196995. (const unsigned char*) &dndVersion, 1);
  196996. // Initialise the pointer and keyboard mapping
  196997. // This is not the same as the logical pointer mapping the X server uses:
  196998. // we don't mess with this.
  196999. static bool mappingInitialised = false;
  197000. if (! mappingInitialised)
  197001. {
  197002. mappingInitialised = true;
  197003. const int numButtons = XGetPointerMapping (display, 0, 0);
  197004. if (numButtons == 2)
  197005. {
  197006. pointerMap[0] = Keys::LeftButton;
  197007. pointerMap[1] = Keys::RightButton;
  197008. pointerMap[2] = pointerMap[3] = pointerMap[4] = Keys::NoButton;
  197009. }
  197010. else if (numButtons >= 3)
  197011. {
  197012. pointerMap[0] = Keys::LeftButton;
  197013. pointerMap[1] = Keys::MiddleButton;
  197014. pointerMap[2] = Keys::RightButton;
  197015. if (numButtons >= 5)
  197016. {
  197017. pointerMap[3] = Keys::WheelUp;
  197018. pointerMap[4] = Keys::WheelDown;
  197019. }
  197020. }
  197021. updateModifierMappings();
  197022. }
  197023. windowH = wndH;
  197024. }
  197025. void destroyWindow()
  197026. {
  197027. ScopedXLock xlock;
  197028. XPointer handlePointer;
  197029. if (! XFindContext (display, (XID) windowH, improbableNumber, &handlePointer))
  197030. XDeleteContext (display, (XID) windowH, improbableNumber);
  197031. XDestroyWindow (display, windowH);
  197032. // Wait for it to complete and then remove any events for this
  197033. // window from the event queue.
  197034. XSync (display, false);
  197035. XEvent event;
  197036. while (XCheckWindowEvent (display, windowH, eventMask, &event) == True)
  197037. {}
  197038. }
  197039. static int64 getEventTime (::Time t)
  197040. {
  197041. static int64 eventTimeOffset = 0x12345678;
  197042. const int64 thisMessageTime = t;
  197043. if (eventTimeOffset == 0x12345678)
  197044. eventTimeOffset = Time::currentTimeMillis() - thisMessageTime;
  197045. return eventTimeOffset + thisMessageTime;
  197046. }
  197047. static void setWindowTitle (Window xwin, const String& title)
  197048. {
  197049. XTextProperty nameProperty;
  197050. char* strings[] = { const_cast <char*> (title.toUTF8()) };
  197051. ScopedXLock xlock;
  197052. if (XStringListToTextProperty (strings, 1, &nameProperty))
  197053. {
  197054. XSetWMName (display, xwin, &nameProperty);
  197055. XSetWMIconName (display, xwin, &nameProperty);
  197056. XFree (nameProperty.value);
  197057. }
  197058. }
  197059. void updateBorderSize()
  197060. {
  197061. if ((styleFlags & windowHasTitleBar) == 0)
  197062. {
  197063. windowBorder = BorderSize (0);
  197064. }
  197065. else if (windowBorder.getTopAndBottom() == 0 && windowBorder.getLeftAndRight() == 0)
  197066. {
  197067. ScopedXLock xlock;
  197068. Atom hints = XInternAtom (display, "_NET_FRAME_EXTENTS", True);
  197069. if (hints != None)
  197070. {
  197071. unsigned char* data = 0;
  197072. unsigned long nitems, bytesLeft;
  197073. Atom actualType;
  197074. int actualFormat;
  197075. if (XGetWindowProperty (display, windowH, hints, 0, 4, False,
  197076. XA_CARDINAL, &actualType, &actualFormat, &nitems, &bytesLeft,
  197077. &data) == Success)
  197078. {
  197079. const unsigned long* const sizes = (const unsigned long*) data;
  197080. if (actualFormat == 32)
  197081. windowBorder = BorderSize ((int) sizes[2], (int) sizes[0],
  197082. (int) sizes[3], (int) sizes[1]);
  197083. XFree (data);
  197084. }
  197085. }
  197086. }
  197087. }
  197088. void updateBounds()
  197089. {
  197090. jassert (windowH != 0);
  197091. if (windowH != 0)
  197092. {
  197093. Window root, child;
  197094. unsigned int bw, depth;
  197095. ScopedXLock xlock;
  197096. if (! XGetGeometry (display, (::Drawable) windowH, &root,
  197097. &wx, &wy, (unsigned int*) &ww, (unsigned int*) &wh,
  197098. &bw, &depth))
  197099. {
  197100. wx = wy = ww = wh = 0;
  197101. }
  197102. else if (! XTranslateCoordinates (display, windowH, root, 0, 0, &wx, &wy, &child))
  197103. {
  197104. wx = wy = 0;
  197105. }
  197106. }
  197107. }
  197108. void resetDragAndDrop()
  197109. {
  197110. dragAndDropFiles.clear();
  197111. lastDropPos = Point<int> (-1, -1);
  197112. dragAndDropCurrentMimeType = 0;
  197113. dragAndDropSourceWindow = 0;
  197114. srcMimeTypeAtomList.clear();
  197115. }
  197116. void sendDragAndDropMessage (XClientMessageEvent& msg)
  197117. {
  197118. msg.type = ClientMessage;
  197119. msg.display = display;
  197120. msg.window = dragAndDropSourceWindow;
  197121. msg.format = 32;
  197122. msg.data.l[0] = windowH;
  197123. ScopedXLock xlock;
  197124. XSendEvent (display, dragAndDropSourceWindow, False, 0, (XEvent*) &msg);
  197125. }
  197126. void sendDragAndDropStatus (const bool acceptDrop, Atom dropAction)
  197127. {
  197128. XClientMessageEvent msg;
  197129. zerostruct (msg);
  197130. msg.message_type = Atoms::XdndStatus;
  197131. msg.data.l[1] = (acceptDrop ? 1 : 0) | 2; // 2 indicates that we want to receive position messages
  197132. msg.data.l[4] = dropAction;
  197133. sendDragAndDropMessage (msg);
  197134. }
  197135. void sendDragAndDropLeave()
  197136. {
  197137. XClientMessageEvent msg;
  197138. zerostruct (msg);
  197139. msg.message_type = Atoms::XdndLeave;
  197140. sendDragAndDropMessage (msg);
  197141. }
  197142. void sendDragAndDropFinish()
  197143. {
  197144. XClientMessageEvent msg;
  197145. zerostruct (msg);
  197146. msg.message_type = Atoms::XdndFinished;
  197147. sendDragAndDropMessage (msg);
  197148. }
  197149. void handleDragAndDropStatus (const XClientMessageEvent* const clientMsg)
  197150. {
  197151. if ((clientMsg->data.l[1] & 1) == 0)
  197152. {
  197153. sendDragAndDropLeave();
  197154. if (dragAndDropFiles.size() > 0)
  197155. handleFileDragExit (dragAndDropFiles);
  197156. dragAndDropFiles.clear();
  197157. }
  197158. }
  197159. void handleDragAndDropPosition (const XClientMessageEvent* const clientMsg)
  197160. {
  197161. if (dragAndDropSourceWindow == 0)
  197162. return;
  197163. dragAndDropSourceWindow = clientMsg->data.l[0];
  197164. Point<int> dropPos ((int) clientMsg->data.l[2] >> 16,
  197165. (int) clientMsg->data.l[2] & 0xffff);
  197166. dropPos -= getScreenPosition();
  197167. if (lastDropPos != dropPos)
  197168. {
  197169. lastDropPos = dropPos;
  197170. dragAndDropTimestamp = clientMsg->data.l[3];
  197171. Atom targetAction = Atoms::XdndActionCopy;
  197172. for (int i = numElementsInArray (Atoms::allowedActions); --i >= 0;)
  197173. {
  197174. if ((Atom) clientMsg->data.l[4] == Atoms::allowedActions[i])
  197175. {
  197176. targetAction = Atoms::allowedActions[i];
  197177. break;
  197178. }
  197179. }
  197180. sendDragAndDropStatus (true, targetAction);
  197181. if (dragAndDropFiles.size() == 0)
  197182. updateDraggedFileList (clientMsg);
  197183. if (dragAndDropFiles.size() > 0)
  197184. handleFileDragMove (dragAndDropFiles, dropPos);
  197185. }
  197186. }
  197187. void handleDragAndDropDrop (const XClientMessageEvent* const clientMsg)
  197188. {
  197189. if (dragAndDropFiles.size() == 0)
  197190. updateDraggedFileList (clientMsg);
  197191. const StringArray files (dragAndDropFiles);
  197192. const Point<int> lastPos (lastDropPos);
  197193. sendDragAndDropFinish();
  197194. resetDragAndDrop();
  197195. if (files.size() > 0)
  197196. handleFileDragDrop (files, lastPos);
  197197. }
  197198. void handleDragAndDropEnter (const XClientMessageEvent* const clientMsg)
  197199. {
  197200. dragAndDropFiles.clear();
  197201. srcMimeTypeAtomList.clear();
  197202. dragAndDropCurrentMimeType = 0;
  197203. const unsigned long dndCurrentVersion = static_cast <unsigned long> (clientMsg->data.l[1] & 0xff000000) >> 24;
  197204. if (dndCurrentVersion < 3 || dndCurrentVersion > Atoms::DndVersion)
  197205. {
  197206. dragAndDropSourceWindow = 0;
  197207. return;
  197208. }
  197209. dragAndDropSourceWindow = clientMsg->data.l[0];
  197210. if ((clientMsg->data.l[1] & 1) != 0)
  197211. {
  197212. Atom actual;
  197213. int format;
  197214. unsigned long count = 0, remaining = 0;
  197215. unsigned char* data = 0;
  197216. ScopedXLock xlock;
  197217. XGetWindowProperty (display, dragAndDropSourceWindow, Atoms::XdndTypeList,
  197218. 0, 0x8000000L, False, XA_ATOM, &actual, &format,
  197219. &count, &remaining, &data);
  197220. if (data != 0)
  197221. {
  197222. if (actual == XA_ATOM && format == 32 && count != 0)
  197223. {
  197224. const unsigned long* const types = (const unsigned long*) data;
  197225. for (unsigned int i = 0; i < count; ++i)
  197226. if (types[i] != None)
  197227. srcMimeTypeAtomList.add (types[i]);
  197228. }
  197229. XFree (data);
  197230. }
  197231. }
  197232. if (srcMimeTypeAtomList.size() == 0)
  197233. {
  197234. for (int i = 2; i < 5; ++i)
  197235. if (clientMsg->data.l[i] != None)
  197236. srcMimeTypeAtomList.add (clientMsg->data.l[i]);
  197237. if (srcMimeTypeAtomList.size() == 0)
  197238. {
  197239. dragAndDropSourceWindow = 0;
  197240. return;
  197241. }
  197242. }
  197243. for (int i = 0; i < srcMimeTypeAtomList.size() && dragAndDropCurrentMimeType == 0; ++i)
  197244. for (int j = 0; j < numElementsInArray (Atoms::allowedMimeTypes); ++j)
  197245. if (srcMimeTypeAtomList[i] == Atoms::allowedMimeTypes[j])
  197246. dragAndDropCurrentMimeType = Atoms::allowedMimeTypes[j];
  197247. handleDragAndDropPosition (clientMsg);
  197248. }
  197249. void handleDragAndDropSelection (const XEvent* const evt)
  197250. {
  197251. dragAndDropFiles.clear();
  197252. if (evt->xselection.property != 0)
  197253. {
  197254. StringArray lines;
  197255. {
  197256. MemoryBlock dropData;
  197257. for (;;)
  197258. {
  197259. Atom actual;
  197260. uint8* data = 0;
  197261. unsigned long count = 0, remaining = 0;
  197262. int format = 0;
  197263. ScopedXLock xlock;
  197264. if (XGetWindowProperty (display, evt->xany.window, evt->xselection.property,
  197265. dropData.getSize() / 4, 65536, 1, AnyPropertyType, &actual,
  197266. &format, &count, &remaining, &data) == Success)
  197267. {
  197268. dropData.append (data, count * format / 8);
  197269. XFree (data);
  197270. if (remaining == 0)
  197271. break;
  197272. }
  197273. else
  197274. {
  197275. XFree (data);
  197276. break;
  197277. }
  197278. }
  197279. lines.addLines (dropData.toString());
  197280. }
  197281. for (int i = 0; i < lines.size(); ++i)
  197282. dragAndDropFiles.add (URL::removeEscapeChars (lines[i].fromFirstOccurrenceOf (T("file://"), false, true)));
  197283. dragAndDropFiles.trim();
  197284. dragAndDropFiles.removeEmptyStrings();
  197285. }
  197286. }
  197287. void updateDraggedFileList (const XClientMessageEvent* const clientMsg)
  197288. {
  197289. dragAndDropFiles.clear();
  197290. if (dragAndDropSourceWindow != None
  197291. && dragAndDropCurrentMimeType != 0)
  197292. {
  197293. dragAndDropTimestamp = clientMsg->data.l[2];
  197294. ScopedXLock xlock;
  197295. XConvertSelection (display,
  197296. Atoms::XdndSelection,
  197297. dragAndDropCurrentMimeType,
  197298. XInternAtom (display, "JXSelectionWindowProperty", 0),
  197299. windowH,
  197300. dragAndDropTimestamp);
  197301. }
  197302. }
  197303. StringArray dragAndDropFiles;
  197304. int dragAndDropTimestamp;
  197305. Point<int> lastDropPos;
  197306. Atom dragAndDropCurrentMimeType;
  197307. Window dragAndDropSourceWindow;
  197308. Array <Atom> srcMimeTypeAtomList;
  197309. static int pointerMap[5];
  197310. static Point<int> lastMousePos;
  197311. static void clearLastMousePos() throw()
  197312. {
  197313. lastMousePos = Point<int> (0x100000, 0x100000);
  197314. }
  197315. };
  197316. ModifierKeys LinuxComponentPeer::currentModifiers;
  197317. int LinuxComponentPeer::pointerMap[5];
  197318. Point<int> LinuxComponentPeer::lastMousePos;
  197319. void ModifierKeys::updateCurrentModifiers() throw()
  197320. {
  197321. currentModifiers = LinuxComponentPeer::currentModifiers;
  197322. }
  197323. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  197324. {
  197325. Window root, child;
  197326. int x, y, winx, winy;
  197327. unsigned int mask;
  197328. int mouseMods = 0;
  197329. ScopedXLock xlock;
  197330. if (XQueryPointer (display, RootWindow (display, DefaultScreen (display)),
  197331. &root, &child, &x, &y, &winx, &winy, &mask) != False)
  197332. {
  197333. if ((mask & Button1Mask) != 0) mouseMods |= ModifierKeys::leftButtonModifier;
  197334. if ((mask & Button2Mask) != 0) mouseMods |= ModifierKeys::middleButtonModifier;
  197335. if ((mask & Button3Mask) != 0) mouseMods |= ModifierKeys::rightButtonModifier;
  197336. }
  197337. LinuxComponentPeer::currentModifiers = LinuxComponentPeer::currentModifiers.withoutMouseButtons().withFlags (mouseMods);
  197338. return LinuxComponentPeer::currentModifiers;
  197339. }
  197340. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  197341. {
  197342. if (enableOrDisable)
  197343. kioskModeComponent->setBounds (Desktop::getInstance().getMainMonitorArea (false));
  197344. }
  197345. ComponentPeer* Component::createNewPeer (int styleFlags, void* /*nativeWindowToAttachTo*/)
  197346. {
  197347. return new LinuxComponentPeer (this, styleFlags);
  197348. }
  197349. // (this callback is hooked up in the messaging code)
  197350. void juce_windowMessageReceive (XEvent* event)
  197351. {
  197352. if (event->xany.window != None)
  197353. {
  197354. LinuxComponentPeer* const peer = LinuxComponentPeer::getPeerFor (event->xany.window);
  197355. if (ComponentPeer::isValidPeer (peer))
  197356. peer->handleWindowMessage (event);
  197357. }
  197358. else
  197359. {
  197360. switch (event->xany.type)
  197361. {
  197362. case KeymapNotify:
  197363. {
  197364. const XKeymapEvent* const keymapEvent = (const XKeymapEvent*) &event->xkeymap;
  197365. memcpy (Keys::keyStates, keymapEvent->key_vector, 32);
  197366. break;
  197367. }
  197368. default:
  197369. break;
  197370. }
  197371. }
  197372. }
  197373. void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords, const bool /*clipToWorkArea*/)
  197374. {
  197375. if (display == 0)
  197376. return;
  197377. #if JUCE_USE_XINERAMA
  197378. int major_opcode, first_event, first_error;
  197379. ScopedXLock xlock;
  197380. if (XQueryExtension (display, "XINERAMA", &major_opcode, &first_event, &first_error))
  197381. {
  197382. typedef Bool (*tXineramaIsActive) (Display*);
  197383. typedef XineramaScreenInfo* (*tXineramaQueryScreens) (Display*, int*);
  197384. static tXineramaIsActive xXineramaIsActive = 0;
  197385. static tXineramaQueryScreens xXineramaQueryScreens = 0;
  197386. if (xXineramaIsActive == 0 || xXineramaQueryScreens == 0)
  197387. {
  197388. void* h = dlopen ("libXinerama.so", RTLD_GLOBAL | RTLD_NOW);
  197389. if (h != 0)
  197390. {
  197391. xXineramaIsActive = (tXineramaIsActive) dlsym (h, "XineramaIsActive");
  197392. xXineramaQueryScreens = (tXineramaQueryScreens) dlsym (h, "XineramaQueryScreens");
  197393. }
  197394. }
  197395. if (xXineramaIsActive != 0
  197396. && xXineramaQueryScreens != 0
  197397. && xXineramaIsActive (display))
  197398. {
  197399. int numMonitors = 0;
  197400. XineramaScreenInfo* const screens = xXineramaQueryScreens (display, &numMonitors);
  197401. if (screens != 0)
  197402. {
  197403. for (int i = numMonitors; --i >= 0;)
  197404. {
  197405. int index = screens[i].screen_number;
  197406. if (index >= 0)
  197407. {
  197408. while (monitorCoords.size() < index)
  197409. monitorCoords.add (Rectangle<int>());
  197410. monitorCoords.set (index, Rectangle<int> (screens[i].x_org,
  197411. screens[i].y_org,
  197412. screens[i].width,
  197413. screens[i].height));
  197414. }
  197415. }
  197416. XFree (screens);
  197417. }
  197418. }
  197419. }
  197420. if (monitorCoords.size() == 0)
  197421. #endif
  197422. {
  197423. Atom hints = XInternAtom (display, "_NET_WORKAREA", True);
  197424. if (hints != None)
  197425. {
  197426. const int numMonitors = ScreenCount (display);
  197427. for (int i = 0; i < numMonitors; ++i)
  197428. {
  197429. Window root = RootWindow (display, i);
  197430. unsigned long nitems, bytesLeft;
  197431. Atom actualType;
  197432. int actualFormat;
  197433. unsigned char* data = 0;
  197434. if (XGetWindowProperty (display, root, hints, 0, 4, False,
  197435. XA_CARDINAL, &actualType, &actualFormat, &nitems, &bytesLeft,
  197436. &data) == Success)
  197437. {
  197438. const long* const position = (const long*) data;
  197439. if (actualType == XA_CARDINAL && actualFormat == 32 && nitems == 4)
  197440. monitorCoords.add (Rectangle<int> (position[0], position[1],
  197441. position[2], position[3]));
  197442. XFree (data);
  197443. }
  197444. }
  197445. }
  197446. if (monitorCoords.size() == 0)
  197447. {
  197448. monitorCoords.add (Rectangle<int> (0, 0,
  197449. DisplayWidth (display, DefaultScreen (display)),
  197450. DisplayHeight (display, DefaultScreen (display))));
  197451. }
  197452. }
  197453. }
  197454. void Desktop::createMouseInputSources()
  197455. {
  197456. mouseSources.add (new MouseInputSource (0, true));
  197457. }
  197458. bool Desktop::canUseSemiTransparentWindows() throw()
  197459. {
  197460. int matchedDepth = 0;
  197461. const int desiredDepth = 32;
  197462. return Visuals::findVisualFormat (desiredDepth, matchedDepth) != 0
  197463. && (matchedDepth == desiredDepth);
  197464. }
  197465. const Point<int> Desktop::getMousePosition()
  197466. {
  197467. Window root, child;
  197468. int x, y, winx, winy;
  197469. unsigned int mask;
  197470. ScopedXLock xlock;
  197471. if (XQueryPointer (display,
  197472. RootWindow (display, DefaultScreen (display)),
  197473. &root, &child,
  197474. &x, &y, &winx, &winy, &mask) == False)
  197475. {
  197476. // Pointer not on the default screen
  197477. x = y = -1;
  197478. }
  197479. return Point<int> (x, y);
  197480. }
  197481. void Desktop::setMousePosition (const Point<int>& newPosition)
  197482. {
  197483. ScopedXLock xlock;
  197484. Window root = RootWindow (display, DefaultScreen (display));
  197485. XWarpPointer (display, None, root, 0, 0, 0, 0, newPosition.getX(), newPosition.getY());
  197486. }
  197487. static bool screenSaverAllowed = true;
  197488. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  197489. {
  197490. if (screenSaverAllowed != isEnabled)
  197491. {
  197492. screenSaverAllowed = isEnabled;
  197493. typedef void (*tXScreenSaverSuspend) (Display*, Bool);
  197494. static tXScreenSaverSuspend xScreenSaverSuspend = 0;
  197495. if (xScreenSaverSuspend == 0)
  197496. {
  197497. void* h = dlopen ("libXss.so", RTLD_GLOBAL | RTLD_NOW);
  197498. if (h != 0)
  197499. xScreenSaverSuspend = (tXScreenSaverSuspend) dlsym (h, "XScreenSaverSuspend");
  197500. }
  197501. ScopedXLock xlock;
  197502. if (xScreenSaverSuspend != 0)
  197503. xScreenSaverSuspend (display, ! isEnabled);
  197504. }
  197505. }
  197506. bool Desktop::isScreenSaverEnabled() throw()
  197507. {
  197508. return screenSaverAllowed;
  197509. }
  197510. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  197511. {
  197512. ScopedXLock xlock;
  197513. Window root = RootWindow (display, DefaultScreen (display));
  197514. const unsigned int imageW = image.getWidth();
  197515. const unsigned int imageH = image.getHeight();
  197516. unsigned int cursorW, cursorH;
  197517. if (! XQueryBestCursor (display, root, imageW, imageH, &cursorW, &cursorH))
  197518. return 0;
  197519. Image im (Image::ARGB, cursorW, cursorH, true);
  197520. Graphics g (im);
  197521. if (imageW > cursorW || imageH > cursorH)
  197522. {
  197523. hotspotX = (hotspotX * cursorW) / imageW;
  197524. hotspotY = (hotspotY * cursorH) / imageH;
  197525. g.drawImageWithin (&image, 0, 0, imageW, imageH,
  197526. RectanglePlacement::xLeft | RectanglePlacement::yTop | RectanglePlacement::onlyReduceInSize,
  197527. false);
  197528. }
  197529. else
  197530. {
  197531. g.drawImageAt (&image, 0, 0);
  197532. }
  197533. const int stride = (cursorW + 7) >> 3;
  197534. HeapBlock <uint8> maskPlane, sourcePlane;
  197535. maskPlane.calloc (stride * cursorH);
  197536. sourcePlane.calloc (stride * cursorH);
  197537. const bool msbfirst = (BitmapBitOrder (display) == MSBFirst);
  197538. for (int y = cursorH; --y >= 0;)
  197539. {
  197540. for (int x = cursorW; --x >= 0;)
  197541. {
  197542. const uint8 mask = (uint8) (1 << (msbfirst ? (7 - (x & 7)) : (x & 7)));
  197543. const int offset = y * stride + (x >> 3);
  197544. const Colour c (im.getPixelAt (x, y));
  197545. if (c.getAlpha() >= 128)
  197546. maskPlane[offset] |= mask;
  197547. if (c.getBrightness() >= 0.5f)
  197548. sourcePlane[offset] |= mask;
  197549. }
  197550. }
  197551. Pixmap sourcePixmap = XCreatePixmapFromBitmapData (display, root, reinterpret_cast <char*> (sourcePlane.getData()), cursorW, cursorH, 0xffff, 0, 1);
  197552. Pixmap maskPixmap = XCreatePixmapFromBitmapData (display, root, reinterpret_cast <char*> (maskPlane.getData()), cursorW, cursorH, 0xffff, 0, 1);
  197553. XColor white, black;
  197554. black.red = black.green = black.blue = 0;
  197555. white.red = white.green = white.blue = 0xffff;
  197556. void* result = (void*) XCreatePixmapCursor (display, sourcePixmap, maskPixmap, &white, &black, hotspotX, hotspotY);
  197557. XFreePixmap (display, sourcePixmap);
  197558. XFreePixmap (display, maskPixmap);
  197559. return result;
  197560. }
  197561. void juce_deleteMouseCursor (void* const cursorHandle, const bool) throw()
  197562. {
  197563. ScopedXLock xlock;
  197564. if (cursorHandle != None)
  197565. XFreeCursor (display, (Cursor) cursorHandle);
  197566. }
  197567. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  197568. {
  197569. unsigned int shape;
  197570. switch (type)
  197571. {
  197572. case MouseCursor::NoCursor:
  197573. {
  197574. const Image im (Image::ARGB, 16, 16, true);
  197575. return juce_createMouseCursorFromImage (im, 0, 0);
  197576. }
  197577. case MouseCursor::NormalCursor:
  197578. return (void*) None; // Use parent cursor
  197579. case MouseCursor::DraggingHandCursor:
  197580. {
  197581. static unsigned char dragHandData[] = {71,73,70,56,57,97,16,0,16,0,145,2,0,0,0,0,255,255,255,0,
  197582. 0,0,0,0,0,33,249,4,1,0,0,2,0,44,0,0,0,0,16,0,
  197583. 16,0,0,2,52,148,47,0,200,185,16,130,90,12,74,139,107,84,123,39,
  197584. 132,117,151,116,132,146,248,60,209,138,98,22,203,114,34,236,37,52,77,217,
  197585. 247,154,191,119,110,240,193,128,193,95,163,56,60,234,98,135,2,0,59 };
  197586. const int dragHandDataSize = 99;
  197587. const ScopedPointer <Image> im (ImageFileFormat::loadFrom ((const char*) dragHandData, dragHandDataSize));
  197588. return juce_createMouseCursorFromImage (*im, 8, 7);
  197589. }
  197590. case MouseCursor::CopyingCursor:
  197591. {
  197592. static unsigned char copyCursorData[] = {71,73,70,56,57,97,21,0,21,0,145,0,0,0,0,0,255,255,255,0,
  197593. 128,128,255,255,255,33,249,4,1,0,0,3,0,44,0,0,0,0,21,0,
  197594. 21,0,0,2,72,4,134,169,171,16,199,98,11,79,90,71,161,93,56,111,
  197595. 78,133,218,215,137,31,82,154,100,200,86,91,202,142,12,108,212,87,235,174,
  197596. 15,54,214,126,237,226,37,96,59,141,16,37,18,201,142,157,230,204,51,112,
  197597. 252,114,147,74,83,5,50,68,147,208,217,16,71,149,252,124,5,0,59,0,0 };
  197598. const int copyCursorSize = 119;
  197599. const ScopedPointer <Image> im (ImageFileFormat::loadFrom ((const char*) copyCursorData, copyCursorSize));
  197600. return juce_createMouseCursorFromImage (*im, 1, 3);
  197601. }
  197602. case MouseCursor::WaitCursor:
  197603. shape = XC_watch;
  197604. break;
  197605. case MouseCursor::IBeamCursor:
  197606. shape = XC_xterm;
  197607. break;
  197608. case MouseCursor::PointingHandCursor:
  197609. shape = XC_hand2;
  197610. break;
  197611. case MouseCursor::LeftRightResizeCursor:
  197612. shape = XC_sb_h_double_arrow;
  197613. break;
  197614. case MouseCursor::UpDownResizeCursor:
  197615. shape = XC_sb_v_double_arrow;
  197616. break;
  197617. case MouseCursor::UpDownLeftRightResizeCursor:
  197618. shape = XC_fleur;
  197619. break;
  197620. case MouseCursor::TopEdgeResizeCursor:
  197621. shape = XC_top_side;
  197622. break;
  197623. case MouseCursor::BottomEdgeResizeCursor:
  197624. shape = XC_bottom_side;
  197625. break;
  197626. case MouseCursor::LeftEdgeResizeCursor:
  197627. shape = XC_left_side;
  197628. break;
  197629. case MouseCursor::RightEdgeResizeCursor:
  197630. shape = XC_right_side;
  197631. break;
  197632. case MouseCursor::TopLeftCornerResizeCursor:
  197633. shape = XC_top_left_corner;
  197634. break;
  197635. case MouseCursor::TopRightCornerResizeCursor:
  197636. shape = XC_top_right_corner;
  197637. break;
  197638. case MouseCursor::BottomLeftCornerResizeCursor:
  197639. shape = XC_bottom_left_corner;
  197640. break;
  197641. case MouseCursor::BottomRightCornerResizeCursor:
  197642. shape = XC_bottom_right_corner;
  197643. break;
  197644. case MouseCursor::CrosshairCursor:
  197645. shape = XC_crosshair;
  197646. break;
  197647. default:
  197648. return (void*) None; // Use parent cursor
  197649. }
  197650. ScopedXLock xlock;
  197651. return (void*) XCreateFontCursor (display, shape);
  197652. }
  197653. void MouseCursor::showInWindow (ComponentPeer* peer) const throw()
  197654. {
  197655. LinuxComponentPeer* const lp = dynamic_cast <LinuxComponentPeer*> (peer);
  197656. if (lp != 0)
  197657. lp->showMouseCursor ((Cursor) getHandle());
  197658. }
  197659. void MouseCursor::showInAllWindows() const throw()
  197660. {
  197661. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  197662. showInWindow (ComponentPeer::getPeer (i));
  197663. }
  197664. Image* juce_createIconForFile (const File& file)
  197665. {
  197666. return 0;
  197667. }
  197668. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  197669. {
  197670. return new Image (format, imageWidth, imageHeight, clearImage);
  197671. }
  197672. #if JUCE_OPENGL
  197673. class WindowedGLContext : public OpenGLContext
  197674. {
  197675. public:
  197676. WindowedGLContext (Component* const component,
  197677. const OpenGLPixelFormat& pixelFormat_,
  197678. GLXContext sharedContext)
  197679. : renderContext (0),
  197680. embeddedWindow (0),
  197681. pixelFormat (pixelFormat_)
  197682. {
  197683. jassert (component != 0);
  197684. LinuxComponentPeer* const peer = dynamic_cast <LinuxComponentPeer*> (component->getTopLevelComponent()->getPeer());
  197685. if (peer == 0)
  197686. return;
  197687. ScopedXLock xlock;
  197688. XSync (display, False);
  197689. GLint attribs [64];
  197690. int n = 0;
  197691. attribs[n++] = GLX_RGBA;
  197692. attribs[n++] = GLX_DOUBLEBUFFER;
  197693. attribs[n++] = GLX_RED_SIZE;
  197694. attribs[n++] = pixelFormat.redBits;
  197695. attribs[n++] = GLX_GREEN_SIZE;
  197696. attribs[n++] = pixelFormat.greenBits;
  197697. attribs[n++] = GLX_BLUE_SIZE;
  197698. attribs[n++] = pixelFormat.blueBits;
  197699. attribs[n++] = GLX_ALPHA_SIZE;
  197700. attribs[n++] = pixelFormat.alphaBits;
  197701. attribs[n++] = GLX_DEPTH_SIZE;
  197702. attribs[n++] = pixelFormat.depthBufferBits;
  197703. attribs[n++] = GLX_STENCIL_SIZE;
  197704. attribs[n++] = pixelFormat.stencilBufferBits;
  197705. attribs[n++] = GLX_ACCUM_RED_SIZE;
  197706. attribs[n++] = pixelFormat.accumulationBufferRedBits;
  197707. attribs[n++] = GLX_ACCUM_GREEN_SIZE;
  197708. attribs[n++] = pixelFormat.accumulationBufferGreenBits;
  197709. attribs[n++] = GLX_ACCUM_BLUE_SIZE;
  197710. attribs[n++] = pixelFormat.accumulationBufferBlueBits;
  197711. attribs[n++] = GLX_ACCUM_ALPHA_SIZE;
  197712. attribs[n++] = pixelFormat.accumulationBufferAlphaBits;
  197713. // xxx not sure how to do fullSceneAntiAliasingNumSamples on linux..
  197714. attribs[n++] = None;
  197715. XVisualInfo* const bestVisual = glXChooseVisual (display, DefaultScreen (display), attribs);
  197716. if (bestVisual == 0)
  197717. return;
  197718. renderContext = glXCreateContext (display, bestVisual, sharedContext, GL_TRUE);
  197719. Window windowH = (Window) peer->getNativeHandle();
  197720. Colormap colourMap = XCreateColormap (display, windowH, bestVisual->visual, AllocNone);
  197721. XSetWindowAttributes swa;
  197722. swa.colormap = colourMap;
  197723. swa.border_pixel = 0;
  197724. swa.event_mask = ExposureMask | StructureNotifyMask;
  197725. embeddedWindow = XCreateWindow (display, windowH,
  197726. 0, 0, 1, 1, 0,
  197727. bestVisual->depth,
  197728. InputOutput,
  197729. bestVisual->visual,
  197730. CWBorderPixel | CWColormap | CWEventMask,
  197731. &swa);
  197732. XSaveContext (display, (XID) embeddedWindow, improbableNumber, (XPointer) peer);
  197733. XMapWindow (display, embeddedWindow);
  197734. XFreeColormap (display, colourMap);
  197735. XFree (bestVisual);
  197736. XSync (display, False);
  197737. }
  197738. ~WindowedGLContext()
  197739. {
  197740. makeInactive();
  197741. ScopedXLock xlock;
  197742. glXDestroyContext (display, renderContext);
  197743. XUnmapWindow (display, embeddedWindow);
  197744. XDestroyWindow (display, embeddedWindow);
  197745. }
  197746. bool makeActive() const throw()
  197747. {
  197748. jassert (renderContext != 0);
  197749. ScopedXLock xlock;
  197750. return glXMakeCurrent (display, embeddedWindow, renderContext)
  197751. && XSync (display, False);
  197752. }
  197753. bool makeInactive() const throw()
  197754. {
  197755. ScopedXLock xlock;
  197756. return (! isActive()) || glXMakeCurrent (display, None, 0);
  197757. }
  197758. bool isActive() const throw()
  197759. {
  197760. ScopedXLock xlock;
  197761. return glXGetCurrentContext() == renderContext;
  197762. }
  197763. const OpenGLPixelFormat getPixelFormat() const
  197764. {
  197765. return pixelFormat;
  197766. }
  197767. void* getRawContext() const throw()
  197768. {
  197769. return renderContext;
  197770. }
  197771. void updateWindowPosition (int x, int y, int w, int h, int)
  197772. {
  197773. ScopedXLock xlock;
  197774. XMoveResizeWindow (display, embeddedWindow,
  197775. x, y, jmax (1, w), jmax (1, h));
  197776. }
  197777. void swapBuffers()
  197778. {
  197779. ScopedXLock xlock;
  197780. glXSwapBuffers (display, embeddedWindow);
  197781. }
  197782. bool setSwapInterval (const int numFramesPerSwap)
  197783. {
  197784. // xxx needs doing..
  197785. return false;
  197786. }
  197787. int getSwapInterval() const
  197788. {
  197789. // xxx needs doing..
  197790. return 0;
  197791. }
  197792. void repaint()
  197793. {
  197794. }
  197795. juce_UseDebuggingNewOperator
  197796. GLXContext renderContext;
  197797. private:
  197798. Window embeddedWindow;
  197799. OpenGLPixelFormat pixelFormat;
  197800. WindowedGLContext (const WindowedGLContext&);
  197801. WindowedGLContext& operator= (const WindowedGLContext&);
  197802. };
  197803. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  197804. const OpenGLPixelFormat& pixelFormat,
  197805. const OpenGLContext* const contextToShareWith)
  197806. {
  197807. WindowedGLContext* c = new WindowedGLContext (component, pixelFormat,
  197808. contextToShareWith != 0 ? (GLXContext) contextToShareWith->getRawContext() : 0);
  197809. if (c->renderContext == 0)
  197810. deleteAndZero (c);
  197811. return c;
  197812. }
  197813. void juce_glViewport (const int w, const int h)
  197814. {
  197815. glViewport (0, 0, w, h);
  197816. }
  197817. void OpenGLPixelFormat::getAvailablePixelFormats (Component* component,
  197818. OwnedArray <OpenGLPixelFormat>& results)
  197819. {
  197820. results.add (new OpenGLPixelFormat()); // xxx
  197821. }
  197822. #endif
  197823. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  197824. {
  197825. jassertfalse // not implemented!
  197826. return false;
  197827. }
  197828. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  197829. {
  197830. jassertfalse // not implemented!
  197831. return false;
  197832. }
  197833. void SystemTrayIconComponent::setIconImage (const Image& newImage)
  197834. {
  197835. if (! isOnDesktop ())
  197836. addToDesktop (0);
  197837. LinuxComponentPeer* const wp = dynamic_cast <LinuxComponentPeer*> (getPeer());
  197838. if (wp != 0)
  197839. {
  197840. wp->setTaskBarIcon (newImage);
  197841. setVisible (true);
  197842. toFront (false);
  197843. repaint();
  197844. }
  197845. }
  197846. void SystemTrayIconComponent::paint (Graphics& g)
  197847. {
  197848. LinuxComponentPeer* const wp = dynamic_cast <LinuxComponentPeer*> (getPeer());
  197849. if (wp != 0)
  197850. {
  197851. const Image* const image = wp->getTaskbarIcon();
  197852. if (image != 0)
  197853. {
  197854. g.drawImageWithin (image, 0, 0, getWidth(), getHeight(),
  197855. RectanglePlacement::xLeft | RectanglePlacement::yTop | RectanglePlacement::onlyReduceInSize,
  197856. false);
  197857. }
  197858. }
  197859. }
  197860. void SystemTrayIconComponent::setIconTooltip (const String& tooltip)
  197861. {
  197862. // xxx not yet implemented!
  197863. }
  197864. void PlatformUtilities::beep()
  197865. {
  197866. std::cout << "\a" << std::flush;
  197867. }
  197868. bool AlertWindow::showNativeDialogBox (const String& title,
  197869. const String& bodyText,
  197870. bool isOkCancel)
  197871. {
  197872. // use a non-native one for the time being..
  197873. if (isOkCancel)
  197874. return AlertWindow::showOkCancelBox (AlertWindow::NoIcon, title, bodyText);
  197875. else
  197876. AlertWindow::showMessageBox (AlertWindow::NoIcon, title, bodyText);
  197877. return true;
  197878. }
  197879. const int KeyPress::spaceKey = XK_space & 0xff;
  197880. const int KeyPress::returnKey = XK_Return & 0xff;
  197881. const int KeyPress::escapeKey = XK_Escape & 0xff;
  197882. const int KeyPress::backspaceKey = XK_BackSpace & 0xff;
  197883. const int KeyPress::leftKey = (XK_Left & 0xff) | Keys::extendedKeyModifier;
  197884. const int KeyPress::rightKey = (XK_Right & 0xff) | Keys::extendedKeyModifier;
  197885. const int KeyPress::upKey = (XK_Up & 0xff) | Keys::extendedKeyModifier;
  197886. const int KeyPress::downKey = (XK_Down & 0xff) | Keys::extendedKeyModifier;
  197887. const int KeyPress::pageUpKey = (XK_Page_Up & 0xff) | Keys::extendedKeyModifier;
  197888. const int KeyPress::pageDownKey = (XK_Page_Down & 0xff) | Keys::extendedKeyModifier;
  197889. const int KeyPress::endKey = (XK_End & 0xff) | Keys::extendedKeyModifier;
  197890. const int KeyPress::homeKey = (XK_Home & 0xff) | Keys::extendedKeyModifier;
  197891. const int KeyPress::insertKey = (XK_Insert & 0xff) | Keys::extendedKeyModifier;
  197892. const int KeyPress::deleteKey = (XK_Delete & 0xff) | Keys::extendedKeyModifier;
  197893. const int KeyPress::tabKey = XK_Tab & 0xff;
  197894. const int KeyPress::F1Key = (XK_F1 & 0xff) | Keys::extendedKeyModifier;
  197895. const int KeyPress::F2Key = (XK_F2 & 0xff) | Keys::extendedKeyModifier;
  197896. const int KeyPress::F3Key = (XK_F3 & 0xff) | Keys::extendedKeyModifier;
  197897. const int KeyPress::F4Key = (XK_F4 & 0xff) | Keys::extendedKeyModifier;
  197898. const int KeyPress::F5Key = (XK_F5 & 0xff) | Keys::extendedKeyModifier;
  197899. const int KeyPress::F6Key = (XK_F6 & 0xff) | Keys::extendedKeyModifier;
  197900. const int KeyPress::F7Key = (XK_F7 & 0xff) | Keys::extendedKeyModifier;
  197901. const int KeyPress::F8Key = (XK_F8 & 0xff) | Keys::extendedKeyModifier;
  197902. const int KeyPress::F9Key = (XK_F9 & 0xff) | Keys::extendedKeyModifier;
  197903. const int KeyPress::F10Key = (XK_F10 & 0xff) | Keys::extendedKeyModifier;
  197904. const int KeyPress::F11Key = (XK_F11 & 0xff) | Keys::extendedKeyModifier;
  197905. const int KeyPress::F12Key = (XK_F12 & 0xff) | Keys::extendedKeyModifier;
  197906. const int KeyPress::F13Key = (XK_F13 & 0xff) | Keys::extendedKeyModifier;
  197907. const int KeyPress::F14Key = (XK_F14 & 0xff) | Keys::extendedKeyModifier;
  197908. const int KeyPress::F15Key = (XK_F15 & 0xff) | Keys::extendedKeyModifier;
  197909. const int KeyPress::F16Key = (XK_F16 & 0xff) | Keys::extendedKeyModifier;
  197910. const int KeyPress::numberPad0 = (XK_KP_0 & 0xff) | Keys::extendedKeyModifier;
  197911. const int KeyPress::numberPad1 = (XK_KP_1 & 0xff) | Keys::extendedKeyModifier;
  197912. const int KeyPress::numberPad2 = (XK_KP_2 & 0xff) | Keys::extendedKeyModifier;
  197913. const int KeyPress::numberPad3 = (XK_KP_3 & 0xff) | Keys::extendedKeyModifier;
  197914. const int KeyPress::numberPad4 = (XK_KP_4 & 0xff) | Keys::extendedKeyModifier;
  197915. const int KeyPress::numberPad5 = (XK_KP_5 & 0xff) | Keys::extendedKeyModifier;
  197916. const int KeyPress::numberPad6 = (XK_KP_6 & 0xff) | Keys::extendedKeyModifier;
  197917. const int KeyPress::numberPad7 = (XK_KP_7 & 0xff)| Keys::extendedKeyModifier;
  197918. const int KeyPress::numberPad8 = (XK_KP_8 & 0xff)| Keys::extendedKeyModifier;
  197919. const int KeyPress::numberPad9 = (XK_KP_9 & 0xff)| Keys::extendedKeyModifier;
  197920. const int KeyPress::numberPadAdd = (XK_KP_Add & 0xff)| Keys::extendedKeyModifier;
  197921. const int KeyPress::numberPadSubtract = (XK_KP_Subtract & 0xff)| Keys::extendedKeyModifier;
  197922. const int KeyPress::numberPadMultiply = (XK_KP_Multiply & 0xff)| Keys::extendedKeyModifier;
  197923. const int KeyPress::numberPadDivide = (XK_KP_Divide & 0xff)| Keys::extendedKeyModifier;
  197924. const int KeyPress::numberPadSeparator = (XK_KP_Separator & 0xff)| Keys::extendedKeyModifier;
  197925. const int KeyPress::numberPadDecimalPoint = (XK_KP_Decimal & 0xff)| Keys::extendedKeyModifier;
  197926. const int KeyPress::numberPadEquals = (XK_KP_Equal & 0xff)| Keys::extendedKeyModifier;
  197927. const int KeyPress::numberPadDelete = (XK_KP_Delete & 0xff)| Keys::extendedKeyModifier;
  197928. const int KeyPress::playKey = (0xffeeff00) | Keys::extendedKeyModifier;
  197929. const int KeyPress::stopKey = (0xffeeff01) | Keys::extendedKeyModifier;
  197930. const int KeyPress::fastForwardKey = (0xffeeff02) | Keys::extendedKeyModifier;
  197931. const int KeyPress::rewindKey = (0xffeeff03) | Keys::extendedKeyModifier;
  197932. #endif
  197933. /*** End of inlined file: juce_linux_Windowing.cpp ***/
  197934. /*** Start of inlined file: juce_linux_Audio.cpp ***/
  197935. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  197936. // compiled on its own).
  197937. #if JUCE_INCLUDED_FILE && JUCE_ALSA
  197938. static const int maxNumChans = 64;
  197939. static void getDeviceSampleRates (snd_pcm_t* handle, Array <int>& rates)
  197940. {
  197941. const int ratesToTry[] = { 22050, 32000, 44100, 48000, 88200, 96000, 176400, 192000, 0 };
  197942. snd_pcm_hw_params_t* hwParams;
  197943. snd_pcm_hw_params_alloca (&hwParams);
  197944. for (int i = 0; ratesToTry[i] != 0; ++i)
  197945. {
  197946. if (snd_pcm_hw_params_any (handle, hwParams) >= 0
  197947. && snd_pcm_hw_params_test_rate (handle, hwParams, ratesToTry[i], 0) == 0)
  197948. {
  197949. rates.addIfNotAlreadyThere (ratesToTry[i]);
  197950. }
  197951. }
  197952. }
  197953. static void getDeviceNumChannels (snd_pcm_t* handle, unsigned int* minChans, unsigned int* maxChans)
  197954. {
  197955. snd_pcm_hw_params_t *params;
  197956. snd_pcm_hw_params_alloca (&params);
  197957. if (snd_pcm_hw_params_any (handle, params) >= 0)
  197958. {
  197959. snd_pcm_hw_params_get_channels_min (params, minChans);
  197960. snd_pcm_hw_params_get_channels_max (params, maxChans);
  197961. }
  197962. }
  197963. static void getDeviceProperties (const String& deviceID,
  197964. unsigned int& minChansOut,
  197965. unsigned int& maxChansOut,
  197966. unsigned int& minChansIn,
  197967. unsigned int& maxChansIn,
  197968. Array <int>& rates)
  197969. {
  197970. if (deviceID.isEmpty())
  197971. return;
  197972. snd_ctl_t* handle;
  197973. if (snd_ctl_open (&handle, deviceID.upToLastOccurrenceOf (T(","), false, false).toUTF8(), SND_CTL_NONBLOCK) >= 0)
  197974. {
  197975. snd_pcm_info_t* info;
  197976. snd_pcm_info_alloca (&info);
  197977. snd_pcm_info_set_stream (info, SND_PCM_STREAM_PLAYBACK);
  197978. snd_pcm_info_set_device (info, deviceID.fromLastOccurrenceOf (T(","), false, false).getIntValue());
  197979. snd_pcm_info_set_subdevice (info, 0);
  197980. if (snd_ctl_pcm_info (handle, info) >= 0)
  197981. {
  197982. snd_pcm_t* pcmHandle;
  197983. if (snd_pcm_open (&pcmHandle, deviceID.toUTF8(), SND_PCM_STREAM_PLAYBACK, SND_PCM_ASYNC | SND_PCM_NONBLOCK ) >= 0)
  197984. {
  197985. getDeviceNumChannels (pcmHandle, &minChansOut, &maxChansOut);
  197986. getDeviceSampleRates (pcmHandle, rates);
  197987. snd_pcm_close (pcmHandle);
  197988. }
  197989. }
  197990. snd_pcm_info_set_stream (info, SND_PCM_STREAM_CAPTURE);
  197991. if (snd_ctl_pcm_info (handle, info) >= 0)
  197992. {
  197993. snd_pcm_t* pcmHandle;
  197994. if (snd_pcm_open (&pcmHandle, deviceID.toUTF8(), SND_PCM_STREAM_CAPTURE, SND_PCM_ASYNC | SND_PCM_NONBLOCK ) >= 0)
  197995. {
  197996. getDeviceNumChannels (pcmHandle, &minChansIn, &maxChansIn);
  197997. if (rates.size() == 0)
  197998. getDeviceSampleRates (pcmHandle, rates);
  197999. snd_pcm_close (pcmHandle);
  198000. }
  198001. }
  198002. snd_ctl_close (handle);
  198003. }
  198004. }
  198005. class ALSADevice
  198006. {
  198007. public:
  198008. ALSADevice (const String& deviceID,
  198009. const bool forInput)
  198010. : handle (0),
  198011. bitDepth (16),
  198012. numChannelsRunning (0),
  198013. isInput (forInput),
  198014. sampleFormat (AudioDataConverters::int16LE)
  198015. {
  198016. failed (snd_pcm_open (&handle, deviceID.toUTF8(),
  198017. forInput ? SND_PCM_STREAM_CAPTURE : SND_PCM_STREAM_PLAYBACK,
  198018. SND_PCM_ASYNC));
  198019. }
  198020. ~ALSADevice()
  198021. {
  198022. if (handle != 0)
  198023. snd_pcm_close (handle);
  198024. }
  198025. bool setParameters (unsigned int sampleRate, int numChannels, int bufferSize)
  198026. {
  198027. if (handle == 0)
  198028. return false;
  198029. snd_pcm_hw_params_t* hwParams;
  198030. snd_pcm_hw_params_alloca (&hwParams);
  198031. if (failed (snd_pcm_hw_params_any (handle, hwParams)))
  198032. return false;
  198033. if (snd_pcm_hw_params_set_access (handle, hwParams, SND_PCM_ACCESS_RW_NONINTERLEAVED) >= 0)
  198034. isInterleaved = false;
  198035. else if (snd_pcm_hw_params_set_access (handle, hwParams, SND_PCM_ACCESS_RW_INTERLEAVED) >= 0)
  198036. isInterleaved = true;
  198037. else
  198038. {
  198039. jassertfalse
  198040. return false;
  198041. }
  198042. const int formatsToTry[] = { SND_PCM_FORMAT_FLOAT_LE, 32, AudioDataConverters::float32LE,
  198043. SND_PCM_FORMAT_FLOAT_BE, 32, AudioDataConverters::float32BE,
  198044. SND_PCM_FORMAT_S32_LE, 32, AudioDataConverters::int32LE,
  198045. SND_PCM_FORMAT_S32_BE, 32, AudioDataConverters::int32BE,
  198046. SND_PCM_FORMAT_S24_3LE, 24, AudioDataConverters::int24LE,
  198047. SND_PCM_FORMAT_S24_3BE, 24, AudioDataConverters::int24BE,
  198048. SND_PCM_FORMAT_S16_LE, 16, AudioDataConverters::int16LE,
  198049. SND_PCM_FORMAT_S16_BE, 16, AudioDataConverters::int16BE };
  198050. bitDepth = 0;
  198051. for (int i = 0; i < numElementsInArray (formatsToTry); i += 3)
  198052. {
  198053. if (snd_pcm_hw_params_set_format (handle, hwParams, (_snd_pcm_format) formatsToTry [i]) >= 0)
  198054. {
  198055. bitDepth = formatsToTry [i + 1];
  198056. sampleFormat = (AudioDataConverters::DataFormat) formatsToTry [i + 2];
  198057. break;
  198058. }
  198059. }
  198060. if (bitDepth == 0)
  198061. {
  198062. error = "device doesn't support a compatible PCM format";
  198063. DBG (T("ALSA error: ") + error + T("\n"));
  198064. return false;
  198065. }
  198066. int dir = 0;
  198067. unsigned int periods = 4;
  198068. snd_pcm_uframes_t samplesPerPeriod = bufferSize;
  198069. if (failed (snd_pcm_hw_params_set_rate_near (handle, hwParams, &sampleRate, 0))
  198070. || failed (snd_pcm_hw_params_set_channels (handle, hwParams, numChannels))
  198071. || failed (snd_pcm_hw_params_set_periods_near (handle, hwParams, &periods, &dir))
  198072. || failed (snd_pcm_hw_params_set_period_size_near (handle, hwParams, &samplesPerPeriod, &dir))
  198073. || failed (snd_pcm_hw_params (handle, hwParams)))
  198074. {
  198075. return false;
  198076. }
  198077. snd_pcm_sw_params_t* swParams;
  198078. snd_pcm_sw_params_alloca (&swParams);
  198079. snd_pcm_uframes_t boundary;
  198080. if (failed (snd_pcm_sw_params_current (handle, swParams))
  198081. || failed (snd_pcm_sw_params_get_boundary (swParams, &boundary))
  198082. || failed (snd_pcm_sw_params_set_silence_threshold (handle, swParams, 0))
  198083. || failed (snd_pcm_sw_params_set_silence_size (handle, swParams, boundary))
  198084. || failed (snd_pcm_sw_params_set_start_threshold (handle, swParams, samplesPerPeriod))
  198085. || failed (snd_pcm_sw_params_set_stop_threshold (handle, swParams, boundary))
  198086. || failed (snd_pcm_sw_params (handle, swParams)))
  198087. {
  198088. return false;
  198089. }
  198090. numChannelsRunning = numChannels;
  198091. return true;
  198092. }
  198093. bool write (float** const data, const int numSamples)
  198094. {
  198095. if (isInterleaved)
  198096. {
  198097. scratch.ensureSize (sizeof (float) * numSamples * numChannelsRunning, false);
  198098. float* interleaved = reinterpret_cast <float*> (scratch.getData());
  198099. AudioDataConverters::interleaveSamples ((const float**) data, interleaved, numSamples, numChannelsRunning);
  198100. AudioDataConverters::convertFloatToFormat (sampleFormat, interleaved, interleaved, numSamples * numChannelsRunning);
  198101. snd_pcm_sframes_t num = snd_pcm_writei (handle, (void*) interleaved, numSamples);
  198102. if (failed (num) && num != -EPIPE && num != -ESTRPIPE)
  198103. return false;
  198104. }
  198105. else
  198106. {
  198107. for (int i = 0; i < numChannelsRunning; ++i)
  198108. if (data[i] != 0)
  198109. AudioDataConverters::convertFloatToFormat (sampleFormat, data[i], data[i], numSamples);
  198110. snd_pcm_sframes_t num = snd_pcm_writen (handle, (void**) data, numSamples);
  198111. if (failed (num))
  198112. {
  198113. if (num == -EPIPE)
  198114. {
  198115. if (failed (snd_pcm_prepare (handle)))
  198116. return false;
  198117. }
  198118. else if (num != -ESTRPIPE)
  198119. return false;
  198120. }
  198121. }
  198122. return true;
  198123. }
  198124. bool read (float** const data, const int numSamples)
  198125. {
  198126. if (isInterleaved)
  198127. {
  198128. scratch.ensureSize (sizeof (float) * numSamples * numChannelsRunning, false);
  198129. float* interleaved = reinterpret_cast <float*> (scratch.getData());
  198130. snd_pcm_sframes_t num = snd_pcm_readi (handle, (void*) interleaved, numSamples);
  198131. if (failed (num))
  198132. {
  198133. if (num == -EPIPE)
  198134. {
  198135. if (failed (snd_pcm_prepare (handle)))
  198136. return false;
  198137. }
  198138. else if (num != -ESTRPIPE)
  198139. return false;
  198140. }
  198141. AudioDataConverters::convertFormatToFloat (sampleFormat, interleaved, interleaved, numSamples * numChannelsRunning);
  198142. AudioDataConverters::deinterleaveSamples (interleaved, data, numSamples, numChannelsRunning);
  198143. }
  198144. else
  198145. {
  198146. snd_pcm_sframes_t num = snd_pcm_readn (handle, (void**) data, numSamples);
  198147. if (failed (num) && num != -EPIPE && num != -ESTRPIPE)
  198148. return false;
  198149. for (int i = 0; i < numChannelsRunning; ++i)
  198150. if (data[i] != 0)
  198151. AudioDataConverters::convertFormatToFloat (sampleFormat, data[i], data[i], numSamples);
  198152. }
  198153. return true;
  198154. }
  198155. juce_UseDebuggingNewOperator
  198156. snd_pcm_t* handle;
  198157. String error;
  198158. int bitDepth, numChannelsRunning;
  198159. private:
  198160. const bool isInput;
  198161. bool isInterleaved;
  198162. MemoryBlock scratch;
  198163. AudioDataConverters::DataFormat sampleFormat;
  198164. bool failed (const int errorNum)
  198165. {
  198166. if (errorNum >= 0)
  198167. return false;
  198168. error = snd_strerror (errorNum);
  198169. DBG (T("ALSA error: ") + error + T("\n"));
  198170. return true;
  198171. }
  198172. };
  198173. class ALSAThread : public Thread
  198174. {
  198175. public:
  198176. ALSAThread (const String& inputId_,
  198177. const String& outputId_)
  198178. : Thread ("Juce ALSA"),
  198179. sampleRate (0),
  198180. bufferSize (0),
  198181. callback (0),
  198182. inputId (inputId_),
  198183. outputId (outputId_),
  198184. outputDevice (0),
  198185. inputDevice (0),
  198186. numCallbacks (0),
  198187. totalNumInputChannels (0),
  198188. totalNumOutputChannels (0)
  198189. {
  198190. zeromem (outputChannelData, sizeof (outputChannelData));
  198191. zeromem (outputChannelDataForCallback, sizeof (outputChannelDataForCallback));
  198192. zeromem (inputChannelData, sizeof (inputChannelData));
  198193. zeromem (inputChannelDataForCallback, sizeof (inputChannelDataForCallback));
  198194. initialiseRatesAndChannels();
  198195. }
  198196. ~ALSAThread()
  198197. {
  198198. close();
  198199. }
  198200. void open (BitArray inputChannels,
  198201. BitArray outputChannels,
  198202. const double sampleRate_,
  198203. const int bufferSize_)
  198204. {
  198205. close();
  198206. error = String::empty;
  198207. sampleRate = sampleRate_;
  198208. bufferSize = bufferSize_;
  198209. currentInputChans.clear();
  198210. currentOutputChans.clear();
  198211. if (inputChannels.getHighestBit() >= 0)
  198212. {
  198213. for (int i = 0; i <= jmax (inputChannels.getHighestBit(), (int) minChansIn); ++i)
  198214. {
  198215. inputChannelData [i] = (float*) juce_calloc (sizeof (float) * bufferSize);
  198216. if (inputChannels[i])
  198217. {
  198218. inputChannelDataForCallback [totalNumInputChannels++] = inputChannelData [i];
  198219. currentInputChans.setBit (i);
  198220. }
  198221. }
  198222. }
  198223. if (outputChannels.getHighestBit() >= 0)
  198224. {
  198225. for (int i = 0; i <= jmax (outputChannels.getHighestBit(), (int) minChansOut); ++i)
  198226. {
  198227. outputChannelData [i] = (float*) juce_calloc (sizeof (float) * bufferSize);
  198228. if (outputChannels[i])
  198229. {
  198230. outputChannelDataForCallback [totalNumOutputChannels++] = outputChannelData [i];
  198231. currentOutputChans.setBit (i);
  198232. }
  198233. }
  198234. }
  198235. if (totalNumOutputChannels > 0 && outputId.isNotEmpty())
  198236. {
  198237. outputDevice = new ALSADevice (outputId, false);
  198238. if (outputDevice->error.isNotEmpty())
  198239. {
  198240. error = outputDevice->error;
  198241. deleteAndZero (outputDevice);
  198242. return;
  198243. }
  198244. currentOutputChans.setRange (0, minChansOut, true);
  198245. if (! outputDevice->setParameters ((unsigned int) sampleRate,
  198246. jlimit ((int) minChansOut, (int) maxChansOut, currentOutputChans.getHighestBit() + 1),
  198247. bufferSize))
  198248. {
  198249. error = outputDevice->error;
  198250. deleteAndZero (outputDevice);
  198251. return;
  198252. }
  198253. }
  198254. if (totalNumInputChannels > 0 && inputId.isNotEmpty())
  198255. {
  198256. inputDevice = new ALSADevice (inputId, true);
  198257. if (inputDevice->error.isNotEmpty())
  198258. {
  198259. error = inputDevice->error;
  198260. deleteAndZero (inputDevice);
  198261. return;
  198262. }
  198263. currentInputChans.setRange (0, minChansIn, true);
  198264. if (! inputDevice->setParameters ((unsigned int) sampleRate,
  198265. jlimit ((int) minChansIn, (int) maxChansIn, currentInputChans.getHighestBit() + 1),
  198266. bufferSize))
  198267. {
  198268. error = inputDevice->error;
  198269. deleteAndZero (inputDevice);
  198270. return;
  198271. }
  198272. }
  198273. if (outputDevice == 0 && inputDevice == 0)
  198274. {
  198275. error = "no channels";
  198276. return;
  198277. }
  198278. if (outputDevice != 0 && inputDevice != 0)
  198279. {
  198280. snd_pcm_link (outputDevice->handle, inputDevice->handle);
  198281. }
  198282. if (inputDevice != 0 && failed (snd_pcm_prepare (inputDevice->handle)))
  198283. return;
  198284. if (outputDevice != 0 && failed (snd_pcm_prepare (outputDevice->handle)))
  198285. return;
  198286. startThread (9);
  198287. int count = 1000;
  198288. while (numCallbacks == 0)
  198289. {
  198290. sleep (5);
  198291. if (--count < 0 || ! isThreadRunning())
  198292. {
  198293. error = "device didn't start";
  198294. break;
  198295. }
  198296. }
  198297. }
  198298. void close()
  198299. {
  198300. stopThread (6000);
  198301. deleteAndZero (inputDevice);
  198302. deleteAndZero (outputDevice);
  198303. for (int i = 0; i < maxNumChans; ++i)
  198304. {
  198305. juce_free (inputChannelData [i]);
  198306. juce_free (outputChannelData [i]);
  198307. }
  198308. zeromem (outputChannelData, sizeof (outputChannelData));
  198309. zeromem (outputChannelDataForCallback, sizeof (outputChannelDataForCallback));
  198310. zeromem (inputChannelData, sizeof (inputChannelData));
  198311. zeromem (inputChannelDataForCallback, sizeof (inputChannelDataForCallback));
  198312. totalNumOutputChannels = 0;
  198313. totalNumInputChannels = 0;
  198314. numCallbacks = 0;
  198315. }
  198316. void setCallback (AudioIODeviceCallback* const newCallback) throw()
  198317. {
  198318. const ScopedLock sl (callbackLock);
  198319. callback = newCallback;
  198320. }
  198321. void run()
  198322. {
  198323. while (! threadShouldExit())
  198324. {
  198325. if (inputDevice != 0)
  198326. {
  198327. if (! inputDevice->read (inputChannelData, bufferSize))
  198328. {
  198329. DBG ("ALSA: read failure");
  198330. break;
  198331. }
  198332. }
  198333. if (threadShouldExit())
  198334. break;
  198335. {
  198336. const ScopedLock sl (callbackLock);
  198337. ++numCallbacks;
  198338. if (callback != 0)
  198339. {
  198340. callback->audioDeviceIOCallback ((const float**) inputChannelDataForCallback,
  198341. totalNumInputChannels,
  198342. outputChannelDataForCallback,
  198343. totalNumOutputChannels,
  198344. bufferSize);
  198345. }
  198346. else
  198347. {
  198348. for (int i = 0; i < totalNumOutputChannels; ++i)
  198349. zeromem (outputChannelDataForCallback[i], sizeof (float) * bufferSize);
  198350. }
  198351. }
  198352. if (outputDevice != 0)
  198353. {
  198354. failed (snd_pcm_wait (outputDevice->handle, 2000));
  198355. if (threadShouldExit())
  198356. break;
  198357. failed (snd_pcm_avail_update (outputDevice->handle));
  198358. if (! outputDevice->write (outputChannelData, bufferSize))
  198359. {
  198360. DBG ("ALSA: write failure");
  198361. break;
  198362. }
  198363. }
  198364. }
  198365. }
  198366. int getBitDepth() const throw()
  198367. {
  198368. if (outputDevice != 0)
  198369. return outputDevice->bitDepth;
  198370. if (inputDevice != 0)
  198371. return inputDevice->bitDepth;
  198372. return 16;
  198373. }
  198374. juce_UseDebuggingNewOperator
  198375. String error;
  198376. double sampleRate;
  198377. int bufferSize;
  198378. BitArray currentInputChans, currentOutputChans;
  198379. Array <int> sampleRates;
  198380. StringArray channelNamesOut, channelNamesIn;
  198381. AudioIODeviceCallback* callback;
  198382. private:
  198383. const String inputId, outputId;
  198384. ALSADevice* outputDevice;
  198385. ALSADevice* inputDevice;
  198386. int numCallbacks;
  198387. CriticalSection callbackLock;
  198388. float* outputChannelData [maxNumChans];
  198389. float* outputChannelDataForCallback [maxNumChans];
  198390. int totalNumInputChannels;
  198391. float* inputChannelData [maxNumChans];
  198392. float* inputChannelDataForCallback [maxNumChans];
  198393. int totalNumOutputChannels;
  198394. unsigned int minChansOut, maxChansOut;
  198395. unsigned int minChansIn, maxChansIn;
  198396. bool failed (const int errorNum) throw()
  198397. {
  198398. if (errorNum >= 0)
  198399. return false;
  198400. error = snd_strerror (errorNum);
  198401. DBG (T("ALSA error: ") + error + T("\n"));
  198402. return true;
  198403. }
  198404. void initialiseRatesAndChannels() throw()
  198405. {
  198406. sampleRates.clear();
  198407. channelNamesOut.clear();
  198408. channelNamesIn.clear();
  198409. minChansOut = 0;
  198410. maxChansOut = 0;
  198411. minChansIn = 0;
  198412. maxChansIn = 0;
  198413. unsigned int dummy = 0;
  198414. getDeviceProperties (inputId, dummy, dummy, minChansIn, maxChansIn, sampleRates);
  198415. getDeviceProperties (outputId, minChansOut, maxChansOut, dummy, dummy, sampleRates);
  198416. unsigned int i;
  198417. for (i = 0; i < maxChansOut; ++i)
  198418. channelNamesOut.add (T("channel ") + String ((int) i + 1));
  198419. for (i = 0; i < maxChansIn; ++i)
  198420. channelNamesIn.add (T("channel ") + String ((int) i + 1));
  198421. }
  198422. };
  198423. class ALSAAudioIODevice : public AudioIODevice
  198424. {
  198425. public:
  198426. ALSAAudioIODevice (const String& deviceName,
  198427. const String& inputId_,
  198428. const String& outputId_)
  198429. : AudioIODevice (deviceName, T("ALSA")),
  198430. inputId (inputId_),
  198431. outputId (outputId_),
  198432. isOpen_ (false),
  198433. isStarted (false),
  198434. internal (0)
  198435. {
  198436. internal = new ALSAThread (inputId, outputId);
  198437. }
  198438. ~ALSAAudioIODevice()
  198439. {
  198440. delete internal;
  198441. }
  198442. const StringArray getOutputChannelNames()
  198443. {
  198444. return internal->channelNamesOut;
  198445. }
  198446. const StringArray getInputChannelNames()
  198447. {
  198448. return internal->channelNamesIn;
  198449. }
  198450. int getNumSampleRates()
  198451. {
  198452. return internal->sampleRates.size();
  198453. }
  198454. double getSampleRate (int index)
  198455. {
  198456. return internal->sampleRates [index];
  198457. }
  198458. int getNumBufferSizesAvailable()
  198459. {
  198460. return 50;
  198461. }
  198462. int getBufferSizeSamples (int index)
  198463. {
  198464. int n = 16;
  198465. for (int i = 0; i < index; ++i)
  198466. n += n < 64 ? 16
  198467. : (n < 512 ? 32
  198468. : (n < 1024 ? 64
  198469. : (n < 2048 ? 128 : 256)));
  198470. return n;
  198471. }
  198472. int getDefaultBufferSize()
  198473. {
  198474. return 512;
  198475. }
  198476. const String open (const BitArray& inputChannels,
  198477. const BitArray& outputChannels,
  198478. double sampleRate,
  198479. int bufferSizeSamples)
  198480. {
  198481. close();
  198482. if (bufferSizeSamples <= 0)
  198483. bufferSizeSamples = getDefaultBufferSize();
  198484. if (sampleRate <= 0)
  198485. {
  198486. for (int i = 0; i < getNumSampleRates(); ++i)
  198487. {
  198488. if (getSampleRate (i) >= 44100)
  198489. {
  198490. sampleRate = getSampleRate (i);
  198491. break;
  198492. }
  198493. }
  198494. }
  198495. internal->open (inputChannels, outputChannels,
  198496. sampleRate, bufferSizeSamples);
  198497. isOpen_ = internal->error.isEmpty();
  198498. return internal->error;
  198499. }
  198500. void close()
  198501. {
  198502. stop();
  198503. internal->close();
  198504. isOpen_ = false;
  198505. }
  198506. bool isOpen()
  198507. {
  198508. return isOpen_;
  198509. }
  198510. int getCurrentBufferSizeSamples()
  198511. {
  198512. return internal->bufferSize;
  198513. }
  198514. double getCurrentSampleRate()
  198515. {
  198516. return internal->sampleRate;
  198517. }
  198518. int getCurrentBitDepth()
  198519. {
  198520. return internal->getBitDepth();
  198521. }
  198522. const BitArray getActiveOutputChannels() const
  198523. {
  198524. return internal->currentOutputChans;
  198525. }
  198526. const BitArray getActiveInputChannels() const
  198527. {
  198528. return internal->currentInputChans;
  198529. }
  198530. int getOutputLatencyInSamples()
  198531. {
  198532. return 0;
  198533. }
  198534. int getInputLatencyInSamples()
  198535. {
  198536. return 0;
  198537. }
  198538. void start (AudioIODeviceCallback* callback)
  198539. {
  198540. if (! isOpen_)
  198541. callback = 0;
  198542. internal->setCallback (callback);
  198543. if (callback != 0)
  198544. callback->audioDeviceAboutToStart (this);
  198545. isStarted = (callback != 0);
  198546. }
  198547. void stop()
  198548. {
  198549. AudioIODeviceCallback* const oldCallback = internal->callback;
  198550. start (0);
  198551. if (oldCallback != 0)
  198552. oldCallback->audioDeviceStopped();
  198553. }
  198554. bool isPlaying()
  198555. {
  198556. return isStarted && internal->error.isEmpty();
  198557. }
  198558. const String getLastError()
  198559. {
  198560. return internal->error;
  198561. }
  198562. String inputId, outputId;
  198563. private:
  198564. bool isOpen_, isStarted;
  198565. ALSAThread* internal;
  198566. };
  198567. class ALSAAudioIODeviceType : public AudioIODeviceType
  198568. {
  198569. public:
  198570. ALSAAudioIODeviceType()
  198571. : AudioIODeviceType (T("ALSA")),
  198572. hasScanned (false)
  198573. {
  198574. }
  198575. ~ALSAAudioIODeviceType()
  198576. {
  198577. }
  198578. void scanForDevices()
  198579. {
  198580. if (hasScanned)
  198581. return;
  198582. hasScanned = true;
  198583. inputNames.clear();
  198584. inputIds.clear();
  198585. outputNames.clear();
  198586. outputIds.clear();
  198587. snd_ctl_t* handle;
  198588. snd_ctl_card_info_t* info;
  198589. snd_ctl_card_info_alloca (&info);
  198590. int cardNum = -1;
  198591. while (outputIds.size() + inputIds.size() <= 32)
  198592. {
  198593. snd_card_next (&cardNum);
  198594. if (cardNum < 0)
  198595. break;
  198596. if (snd_ctl_open (&handle, ("hw:" + String (cardNum)).toUTF8(), SND_CTL_NONBLOCK) >= 0)
  198597. {
  198598. if (snd_ctl_card_info (handle, info) >= 0)
  198599. {
  198600. String cardId (snd_ctl_card_info_get_id (info));
  198601. if (cardId.removeCharacters (T("0123456789")).isEmpty())
  198602. cardId = String (cardNum);
  198603. int device = -1;
  198604. for (;;)
  198605. {
  198606. if (snd_ctl_pcm_next_device (handle, &device) < 0 || device < 0)
  198607. break;
  198608. String id, name;
  198609. id << "hw:" << cardId << ',' << device;
  198610. bool isInput, isOutput;
  198611. if (testDevice (id, isInput, isOutput))
  198612. {
  198613. name << snd_ctl_card_info_get_name (info);
  198614. if (name.isEmpty())
  198615. name = id;
  198616. if (isInput)
  198617. {
  198618. inputNames.add (name);
  198619. inputIds.add (id);
  198620. }
  198621. if (isOutput)
  198622. {
  198623. outputNames.add (name);
  198624. outputIds.add (id);
  198625. }
  198626. }
  198627. }
  198628. }
  198629. snd_ctl_close (handle);
  198630. }
  198631. }
  198632. inputNames.appendNumbersToDuplicates (false, true);
  198633. outputNames.appendNumbersToDuplicates (false, true);
  198634. }
  198635. const StringArray getDeviceNames (const bool wantInputNames) const
  198636. {
  198637. jassert (hasScanned); // need to call scanForDevices() before doing this
  198638. return wantInputNames ? inputNames : outputNames;
  198639. }
  198640. int getDefaultDeviceIndex (const bool forInput) const
  198641. {
  198642. jassert (hasScanned); // need to call scanForDevices() before doing this
  198643. return 0;
  198644. }
  198645. bool hasSeparateInputsAndOutputs() const { return true; }
  198646. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  198647. {
  198648. jassert (hasScanned); // need to call scanForDevices() before doing this
  198649. ALSAAudioIODevice* const d = dynamic_cast <ALSAAudioIODevice*> (device);
  198650. if (d == 0)
  198651. return -1;
  198652. return asInput ? inputIds.indexOf (d->inputId)
  198653. : outputIds.indexOf (d->outputId);
  198654. }
  198655. AudioIODevice* createDevice (const String& outputDeviceName,
  198656. const String& inputDeviceName)
  198657. {
  198658. jassert (hasScanned); // need to call scanForDevices() before doing this
  198659. const int inputIndex = inputNames.indexOf (inputDeviceName);
  198660. const int outputIndex = outputNames.indexOf (outputDeviceName);
  198661. String deviceName (outputIndex >= 0 ? outputDeviceName
  198662. : inputDeviceName);
  198663. if (inputIndex >= 0 || outputIndex >= 0)
  198664. return new ALSAAudioIODevice (deviceName,
  198665. inputIds [inputIndex],
  198666. outputIds [outputIndex]);
  198667. return 0;
  198668. }
  198669. juce_UseDebuggingNewOperator
  198670. private:
  198671. StringArray inputNames, outputNames, inputIds, outputIds;
  198672. bool hasScanned;
  198673. static bool testDevice (const String& id, bool& isInput, bool& isOutput)
  198674. {
  198675. unsigned int minChansOut = 0, maxChansOut = 0;
  198676. unsigned int minChansIn = 0, maxChansIn = 0;
  198677. Array <int> rates;
  198678. getDeviceProperties (id, minChansOut, maxChansOut, minChansIn, maxChansIn, rates);
  198679. DBG (T("ALSA device: ") + id
  198680. + T(" outs=") + String ((int) minChansOut) + T("-") + String ((int) maxChansOut)
  198681. + T(" ins=") + String ((int) minChansIn) + T("-") + String ((int) maxChansIn)
  198682. + T(" rates=") + String (rates.size()));
  198683. isInput = maxChansIn > 0;
  198684. isOutput = maxChansOut > 0;
  198685. return (isInput || isOutput) && rates.size() > 0;
  198686. }
  198687. ALSAAudioIODeviceType (const ALSAAudioIODeviceType&);
  198688. ALSAAudioIODeviceType& operator= (const ALSAAudioIODeviceType&);
  198689. };
  198690. AudioIODeviceType* juce_createAudioIODeviceType_ALSA()
  198691. {
  198692. return new ALSAAudioIODeviceType();
  198693. }
  198694. #endif
  198695. /*** End of inlined file: juce_linux_Audio.cpp ***/
  198696. /*** Start of inlined file: juce_linux_JackAudio.cpp ***/
  198697. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  198698. // compiled on its own).
  198699. #ifdef JUCE_INCLUDED_FILE
  198700. #if JUCE_JACK
  198701. static void* juce_libjack_handle = 0;
  198702. void* juce_load_jack_function (const char* const name)
  198703. {
  198704. if (juce_libjack_handle == 0)
  198705. return 0;
  198706. return dlsym (juce_libjack_handle, name);
  198707. }
  198708. #define JUCE_DECL_JACK_FUNCTION(return_type, fn_name, argument_types, arguments) \
  198709. typedef return_type (*fn_name##_ptr_t)argument_types; \
  198710. return_type fn_name argument_types { \
  198711. static fn_name##_ptr_t fn = 0; \
  198712. if (fn == 0) { fn = (fn_name##_ptr_t)juce_load_jack_function(#fn_name); } \
  198713. if (fn) return (*fn)arguments; \
  198714. else return 0; \
  198715. }
  198716. #define JUCE_DECL_VOID_JACK_FUNCTION(fn_name, argument_types, arguments) \
  198717. typedef void (*fn_name##_ptr_t)argument_types; \
  198718. void fn_name argument_types { \
  198719. static fn_name##_ptr_t fn = 0; \
  198720. if (fn == 0) { fn = (fn_name##_ptr_t)juce_load_jack_function(#fn_name); } \
  198721. if (fn) (*fn)arguments; \
  198722. }
  198723. 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));
  198724. JUCE_DECL_JACK_FUNCTION (int, jack_client_close, (jack_client_t *client), (client));
  198725. JUCE_DECL_JACK_FUNCTION (int, jack_activate, (jack_client_t* client), (client));
  198726. JUCE_DECL_JACK_FUNCTION (int, jack_deactivate, (jack_client_t* client), (client));
  198727. JUCE_DECL_JACK_FUNCTION (jack_nframes_t, jack_get_buffer_size, (jack_client_t* client), (client));
  198728. JUCE_DECL_JACK_FUNCTION (jack_nframes_t, jack_get_sample_rate, (jack_client_t* client), (client));
  198729. JUCE_DECL_VOID_JACK_FUNCTION (jack_on_shutdown, (jack_client_t* client, void (*function)(void* arg), void* arg), (client, function, arg));
  198730. JUCE_DECL_JACK_FUNCTION (void* , jack_port_get_buffer, (jack_port_t* port, jack_nframes_t nframes), (port, nframes));
  198731. JUCE_DECL_JACK_FUNCTION (jack_nframes_t, jack_port_get_total_latency, (jack_client_t* client, jack_port_t* port), (client, port));
  198732. 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));
  198733. JUCE_DECL_VOID_JACK_FUNCTION (jack_set_error_function, (void (*func)(const char*)), (func));
  198734. JUCE_DECL_JACK_FUNCTION (int, jack_set_process_callback, (jack_client_t* client, JackProcessCallback process_callback, void* arg), (client, process_callback, arg));
  198735. 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));
  198736. JUCE_DECL_JACK_FUNCTION (int, jack_connect, (jack_client_t* client, const char* source_port, const char* destination_port), (client, source_port, destination_port));
  198737. JUCE_DECL_JACK_FUNCTION (const char*, jack_port_name, (const jack_port_t* port), (port));
  198738. JUCE_DECL_JACK_FUNCTION (int, jack_set_port_connect_callback, (jack_client_t* client, JackPortConnectCallback connect_callback, void* arg), (client, connect_callback, arg));
  198739. JUCE_DECL_JACK_FUNCTION (jack_port_t* , jack_port_by_id, (jack_client_t* client, jack_port_id_t port_id), (client, port_id));
  198740. JUCE_DECL_JACK_FUNCTION (int, jack_port_connected, (const jack_port_t* port), (port));
  198741. JUCE_DECL_JACK_FUNCTION (int, jack_port_connected_to, (const jack_port_t* port, const char* port_name), (port, port_name));
  198742. #if JUCE_DEBUG
  198743. #define JACK_LOGGING_ENABLED 1
  198744. #endif
  198745. #if JACK_LOGGING_ENABLED
  198746. static void jack_Log (const String& s)
  198747. {
  198748. std::cerr << s << std::endl;
  198749. }
  198750. static void dumpJackErrorMessage (const jack_status_t status) throw()
  198751. {
  198752. if (status & JackServerFailed || status & JackServerError)
  198753. jack_Log ("Unable to connect to JACK server");
  198754. if (status & JackVersionError)
  198755. jack_Log ("Client's protocol version does not match");
  198756. if (status & JackInvalidOption)
  198757. jack_Log ("The operation contained an invalid or unsupported option");
  198758. if (status & JackNameNotUnique)
  198759. jack_Log ("The desired client name was not unique");
  198760. if (status & JackNoSuchClient)
  198761. jack_Log ("Requested client does not exist");
  198762. if (status & JackInitFailure)
  198763. jack_Log ("Unable to initialize client");
  198764. }
  198765. #else
  198766. #define dumpJackErrorMessage(a) {}
  198767. #define jack_Log(...) {}
  198768. #endif
  198769. #ifndef JUCE_JACK_CLIENT_NAME
  198770. #define JUCE_JACK_CLIENT_NAME "JuceJack"
  198771. #endif
  198772. class JackAudioIODevice : public AudioIODevice
  198773. {
  198774. public:
  198775. JackAudioIODevice (const String& deviceName,
  198776. const String& inputId_,
  198777. const String& outputId_)
  198778. : AudioIODevice (deviceName, T("JACK")),
  198779. inputId (inputId_),
  198780. outputId (outputId_),
  198781. isOpen_ (false),
  198782. callback (0),
  198783. totalNumberOfInputChannels (0),
  198784. totalNumberOfOutputChannels (0)
  198785. {
  198786. jassert (deviceName.isNotEmpty());
  198787. jack_status_t status;
  198788. client = JUCE_NAMESPACE::jack_client_open (JUCE_JACK_CLIENT_NAME, JackNoStartServer, &status);
  198789. if (client == 0)
  198790. {
  198791. dumpJackErrorMessage (status);
  198792. }
  198793. else
  198794. {
  198795. JUCE_NAMESPACE::jack_set_error_function (errorCallback);
  198796. // open input ports
  198797. const StringArray inputChannels (getInputChannelNames());
  198798. for (int i = 0; i < inputChannels.size(); i++)
  198799. {
  198800. String inputName;
  198801. inputName << "in_" << ++totalNumberOfInputChannels;
  198802. inputPorts.add (JUCE_NAMESPACE::jack_port_register (client, inputName.toUTF8(),
  198803. JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0));
  198804. }
  198805. // open output ports
  198806. const StringArray outputChannels (getOutputChannelNames());
  198807. for (int i = 0; i < outputChannels.size (); i++)
  198808. {
  198809. String outputName;
  198810. outputName << "out_" << ++totalNumberOfOutputChannels;
  198811. outputPorts.add (JUCE_NAMESPACE::jack_port_register (client, outputName.toUTF8(),
  198812. JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0));
  198813. }
  198814. inChans.calloc (totalNumberOfInputChannels + 2);
  198815. outChans.calloc (totalNumberOfOutputChannels + 2);
  198816. }
  198817. }
  198818. ~JackAudioIODevice()
  198819. {
  198820. close();
  198821. if (client != 0)
  198822. {
  198823. JUCE_NAMESPACE::jack_client_close (client);
  198824. client = 0;
  198825. }
  198826. }
  198827. const StringArray getChannelNames (bool forInput) const
  198828. {
  198829. StringArray names;
  198830. const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */
  198831. forInput ? JackPortIsInput : JackPortIsOutput);
  198832. if (ports != 0)
  198833. {
  198834. int j = 0;
  198835. while (ports[j] != 0)
  198836. {
  198837. const String portName (ports [j++]);
  198838. if (portName.upToFirstOccurrenceOf (T(":"), false, false) == getName())
  198839. names.add (portName.fromFirstOccurrenceOf (T(":"), false, false));
  198840. }
  198841. free (ports);
  198842. }
  198843. return names;
  198844. }
  198845. const StringArray getOutputChannelNames() { return getChannelNames (false); }
  198846. const StringArray getInputChannelNames() { return getChannelNames (true); }
  198847. int getNumSampleRates() { return client != 0 ? 1 : 0; }
  198848. double getSampleRate (int index) { return client != 0 ? JUCE_NAMESPACE::jack_get_sample_rate (client) : 0; }
  198849. int getNumBufferSizesAvailable() { return client != 0 ? 1 : 0; }
  198850. int getBufferSizeSamples (int index) { return getDefaultBufferSize(); }
  198851. int getDefaultBufferSize() { return client != 0 ? JUCE_NAMESPACE::jack_get_buffer_size (client) : 0; }
  198852. const String open (const BitArray& inputChannels, const BitArray& outputChannels,
  198853. double sampleRate, int bufferSizeSamples)
  198854. {
  198855. if (client == 0)
  198856. {
  198857. lastError = T("No JACK client running");
  198858. return lastError;
  198859. }
  198860. lastError = String::empty;
  198861. close();
  198862. JUCE_NAMESPACE::jack_set_process_callback (client, processCallback, this);
  198863. JUCE_NAMESPACE::jack_on_shutdown (client, shutdownCallback, this);
  198864. JUCE_NAMESPACE::jack_activate (client);
  198865. isOpen_ = true;
  198866. if (! inputChannels.isEmpty())
  198867. {
  198868. const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsOutput);
  198869. if (ports != 0)
  198870. {
  198871. const int numInputChannels = inputChannels.getHighestBit () + 1;
  198872. for (int i = 0; i < numInputChannels; ++i)
  198873. {
  198874. const String portName (ports[i]);
  198875. if (inputChannels[i] && portName.upToFirstOccurrenceOf (T(":"), false, false) == getName())
  198876. {
  198877. int error = JUCE_NAMESPACE::jack_connect (client, ports[i], JUCE_NAMESPACE::jack_port_name ((jack_port_t*) inputPorts[i]));
  198878. if (error != 0)
  198879. jack_Log ("Cannot connect input port " + String (i) + " (" + String (ports[i]) + "), error " + String (error));
  198880. }
  198881. }
  198882. free (ports);
  198883. }
  198884. }
  198885. if (! outputChannels.isEmpty())
  198886. {
  198887. const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsInput);
  198888. if (ports != 0)
  198889. {
  198890. const int numOutputChannels = outputChannels.getHighestBit () + 1;
  198891. for (int i = 0; i < numOutputChannels; ++i)
  198892. {
  198893. const String portName (ports[i]);
  198894. if (outputChannels[i] && portName.upToFirstOccurrenceOf (T(":"), false, false) == getName())
  198895. {
  198896. int error = JUCE_NAMESPACE::jack_connect (client, JUCE_NAMESPACE::jack_port_name ((jack_port_t*) outputPorts[i]), ports[i]);
  198897. if (error != 0)
  198898. jack_Log ("Cannot connect output port " + String (i) + " (" + String (ports[i]) + "), error " + String (error));
  198899. }
  198900. }
  198901. free (ports);
  198902. }
  198903. }
  198904. return lastError;
  198905. }
  198906. void close()
  198907. {
  198908. stop();
  198909. if (client != 0)
  198910. {
  198911. JUCE_NAMESPACE::jack_deactivate (client);
  198912. JUCE_NAMESPACE::jack_set_process_callback (client, processCallback, 0);
  198913. JUCE_NAMESPACE::jack_on_shutdown (client, shutdownCallback, 0);
  198914. }
  198915. isOpen_ = false;
  198916. }
  198917. void start (AudioIODeviceCallback* newCallback)
  198918. {
  198919. if (isOpen_ && newCallback != callback)
  198920. {
  198921. if (newCallback != 0)
  198922. newCallback->audioDeviceAboutToStart (this);
  198923. AudioIODeviceCallback* const oldCallback = callback;
  198924. {
  198925. const ScopedLock sl (callbackLock);
  198926. callback = newCallback;
  198927. }
  198928. if (oldCallback != 0)
  198929. oldCallback->audioDeviceStopped();
  198930. }
  198931. }
  198932. void stop()
  198933. {
  198934. start (0);
  198935. }
  198936. bool isOpen() { return isOpen_; }
  198937. bool isPlaying() { return callback != 0; }
  198938. int getCurrentBufferSizeSamples() { return getBufferSizeSamples (0); }
  198939. double getCurrentSampleRate() { return getSampleRate (0); }
  198940. int getCurrentBitDepth() { return 32; }
  198941. const String getLastError() { return lastError; }
  198942. const BitArray getActiveOutputChannels() const
  198943. {
  198944. BitArray outputBits;
  198945. for (int i = 0; i < outputPorts.size(); i++)
  198946. if (JUCE_NAMESPACE::jack_port_connected ((jack_port_t*) outputPorts [i]))
  198947. outputBits.setBit (i);
  198948. return outputBits;
  198949. }
  198950. const BitArray getActiveInputChannels() const
  198951. {
  198952. BitArray inputBits;
  198953. for (int i = 0; i < inputPorts.size(); i++)
  198954. if (JUCE_NAMESPACE::jack_port_connected ((jack_port_t*) inputPorts [i]))
  198955. inputBits.setBit (i);
  198956. return inputBits;
  198957. }
  198958. int getOutputLatencyInSamples()
  198959. {
  198960. int latency = 0;
  198961. for (int i = 0; i < outputPorts.size(); i++)
  198962. latency = jmax (latency, (int) JUCE_NAMESPACE::jack_port_get_total_latency (client, (jack_port_t*) outputPorts [i]));
  198963. return latency;
  198964. }
  198965. int getInputLatencyInSamples()
  198966. {
  198967. int latency = 0;
  198968. for (int i = 0; i < inputPorts.size(); i++)
  198969. latency = jmax (latency, (int) JUCE_NAMESPACE::jack_port_get_total_latency (client, (jack_port_t*) inputPorts [i]));
  198970. return latency;
  198971. }
  198972. String inputId, outputId;
  198973. private:
  198974. void process (const int numSamples)
  198975. {
  198976. int i, numActiveInChans = 0, numActiveOutChans = 0;
  198977. for (i = 0; i < totalNumberOfInputChannels; ++i)
  198978. {
  198979. jack_default_audio_sample_t* in
  198980. = (jack_default_audio_sample_t*) JUCE_NAMESPACE::jack_port_get_buffer ((jack_port_t*) inputPorts.getUnchecked(i), numSamples);
  198981. if (in != 0)
  198982. inChans [numActiveInChans++] = (float*) in;
  198983. }
  198984. for (i = 0; i < totalNumberOfOutputChannels; ++i)
  198985. {
  198986. jack_default_audio_sample_t* out
  198987. = (jack_default_audio_sample_t*) JUCE_NAMESPACE::jack_port_get_buffer ((jack_port_t*) outputPorts.getUnchecked(i), numSamples);
  198988. if (out != 0)
  198989. outChans [numActiveOutChans++] = (float*) out;
  198990. }
  198991. const ScopedLock sl (callbackLock);
  198992. if (callback != 0)
  198993. {
  198994. callback->audioDeviceIOCallback (const_cast<const float**> (inChans.getData()), numActiveInChans,
  198995. outChans, numActiveOutChans, numSamples);
  198996. }
  198997. else
  198998. {
  198999. for (i = 0; i < numActiveOutChans; ++i)
  199000. zeromem (outChans[i], sizeof (float) * numSamples);
  199001. }
  199002. }
  199003. static int processCallback (jack_nframes_t nframes, void* callbackArgument)
  199004. {
  199005. if (callbackArgument != 0)
  199006. ((JackAudioIODevice*) callbackArgument)->process (nframes);
  199007. return 0;
  199008. }
  199009. static void threadInitCallback (void* callbackArgument)
  199010. {
  199011. jack_Log ("JackAudioIODevice::initialise");
  199012. }
  199013. static void shutdownCallback (void* callbackArgument)
  199014. {
  199015. jack_Log ("JackAudioIODevice::shutdown");
  199016. JackAudioIODevice* device = (JackAudioIODevice*) callbackArgument;
  199017. if (device != 0)
  199018. {
  199019. device->client = 0;
  199020. device->close();
  199021. }
  199022. }
  199023. static void errorCallback (const char* msg)
  199024. {
  199025. jack_Log ("JackAudioIODevice::errorCallback " + String (msg));
  199026. }
  199027. bool isOpen_;
  199028. jack_client_t* client;
  199029. String lastError;
  199030. AudioIODeviceCallback* callback;
  199031. CriticalSection callbackLock;
  199032. HeapBlock <float*> inChans, outChans;
  199033. int totalNumberOfInputChannels;
  199034. int totalNumberOfOutputChannels;
  199035. VoidArray inputPorts, outputPorts;
  199036. };
  199037. class JackAudioIODeviceType : public AudioIODeviceType
  199038. {
  199039. public:
  199040. JackAudioIODeviceType()
  199041. : AudioIODeviceType (T("JACK")),
  199042. hasScanned (false)
  199043. {
  199044. }
  199045. ~JackAudioIODeviceType()
  199046. {
  199047. }
  199048. void scanForDevices()
  199049. {
  199050. hasScanned = true;
  199051. inputNames.clear();
  199052. inputIds.clear();
  199053. outputNames.clear();
  199054. outputIds.clear();
  199055. if (juce_libjack_handle == 0)
  199056. {
  199057. juce_libjack_handle = dlopen ("libjack.so", RTLD_LAZY);
  199058. if (juce_libjack_handle == 0)
  199059. return;
  199060. }
  199061. // open a dummy client
  199062. jack_status_t status;
  199063. jack_client_t* client = JUCE_NAMESPACE::jack_client_open ("JuceJackDummy", JackNoStartServer, &status);
  199064. if (client == 0)
  199065. {
  199066. dumpJackErrorMessage (status);
  199067. }
  199068. else
  199069. {
  199070. // scan for output devices
  199071. const char** ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsOutput);
  199072. if (ports != 0)
  199073. {
  199074. int j = 0;
  199075. while (ports[j] != 0)
  199076. {
  199077. String clientName (ports[j]);
  199078. clientName = clientName.upToFirstOccurrenceOf (T(":"), false, false);
  199079. if (clientName != String (JUCE_JACK_CLIENT_NAME)
  199080. && ! inputNames.contains (clientName))
  199081. {
  199082. inputNames.add (clientName);
  199083. inputIds.add (ports [j]);
  199084. }
  199085. ++j;
  199086. }
  199087. free (ports);
  199088. }
  199089. // scan for input devices
  199090. ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsInput);
  199091. if (ports != 0)
  199092. {
  199093. int j = 0;
  199094. while (ports[j] != 0)
  199095. {
  199096. String clientName (ports[j]);
  199097. clientName = clientName.upToFirstOccurrenceOf (T(":"), false, false);
  199098. if (clientName != String (JUCE_JACK_CLIENT_NAME)
  199099. && ! outputNames.contains (clientName))
  199100. {
  199101. outputNames.add (clientName);
  199102. outputIds.add (ports [j]);
  199103. }
  199104. ++j;
  199105. }
  199106. free (ports);
  199107. }
  199108. JUCE_NAMESPACE::jack_client_close (client);
  199109. }
  199110. }
  199111. const StringArray getDeviceNames (const bool wantInputNames) const
  199112. {
  199113. jassert (hasScanned); // need to call scanForDevices() before doing this
  199114. return wantInputNames ? inputNames : outputNames;
  199115. }
  199116. int getDefaultDeviceIndex (const bool forInput) const
  199117. {
  199118. jassert (hasScanned); // need to call scanForDevices() before doing this
  199119. return 0;
  199120. }
  199121. bool hasSeparateInputsAndOutputs() const { return true; }
  199122. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  199123. {
  199124. jassert (hasScanned); // need to call scanForDevices() before doing this
  199125. JackAudioIODevice* const d = dynamic_cast <JackAudioIODevice*> (device);
  199126. if (d == 0)
  199127. return -1;
  199128. return asInput ? inputIds.indexOf (d->inputId)
  199129. : outputIds.indexOf (d->outputId);
  199130. }
  199131. AudioIODevice* createDevice (const String& outputDeviceName,
  199132. const String& inputDeviceName)
  199133. {
  199134. jassert (hasScanned); // need to call scanForDevices() before doing this
  199135. const int inputIndex = inputNames.indexOf (inputDeviceName);
  199136. const int outputIndex = outputNames.indexOf (outputDeviceName);
  199137. if (inputIndex >= 0 || outputIndex >= 0)
  199138. return new JackAudioIODevice (outputIndex >= 0 ? outputDeviceName
  199139. : inputDeviceName,
  199140. inputIds [inputIndex],
  199141. outputIds [outputIndex]);
  199142. return 0;
  199143. }
  199144. juce_UseDebuggingNewOperator
  199145. private:
  199146. StringArray inputNames, outputNames, inputIds, outputIds;
  199147. bool hasScanned;
  199148. JackAudioIODeviceType (const JackAudioIODeviceType&);
  199149. JackAudioIODeviceType& operator= (const JackAudioIODeviceType&);
  199150. };
  199151. AudioIODeviceType* juce_createAudioIODeviceType_JACK()
  199152. {
  199153. return new JackAudioIODeviceType();
  199154. }
  199155. #else // if JACK is turned off..
  199156. AudioIODeviceType* juce_createAudioIODeviceType_JACK() { return 0; }
  199157. #endif
  199158. #endif
  199159. /*** End of inlined file: juce_linux_JackAudio.cpp ***/
  199160. /*** Start of inlined file: juce_linux_Midi.cpp ***/
  199161. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199162. // compiled on its own).
  199163. #if JUCE_INCLUDED_FILE
  199164. #if JUCE_ALSA
  199165. static snd_seq_t* iterateDevices (const bool forInput,
  199166. StringArray& deviceNamesFound,
  199167. const int deviceIndexToOpen)
  199168. {
  199169. snd_seq_t* returnedHandle = 0;
  199170. snd_seq_t* seqHandle;
  199171. if (snd_seq_open (&seqHandle, "default", forInput ? SND_SEQ_OPEN_INPUT
  199172. : SND_SEQ_OPEN_OUTPUT, 0) == 0)
  199173. {
  199174. snd_seq_system_info_t* systemInfo;
  199175. snd_seq_client_info_t* clientInfo;
  199176. if (snd_seq_system_info_malloc (&systemInfo) == 0)
  199177. {
  199178. if (snd_seq_system_info (seqHandle, systemInfo) == 0
  199179. && snd_seq_client_info_malloc (&clientInfo) == 0)
  199180. {
  199181. int numClients = snd_seq_system_info_get_cur_clients (systemInfo);
  199182. while (--numClients >= 0 && returnedHandle == 0)
  199183. {
  199184. if (snd_seq_query_next_client (seqHandle, clientInfo) == 0)
  199185. {
  199186. snd_seq_port_info_t* portInfo;
  199187. if (snd_seq_port_info_malloc (&portInfo) == 0)
  199188. {
  199189. int numPorts = snd_seq_client_info_get_num_ports (clientInfo);
  199190. const int client = snd_seq_client_info_get_client (clientInfo);
  199191. snd_seq_port_info_set_client (portInfo, client);
  199192. snd_seq_port_info_set_port (portInfo, -1);
  199193. while (--numPorts >= 0)
  199194. {
  199195. if (snd_seq_query_next_port (seqHandle, portInfo) == 0
  199196. && (snd_seq_port_info_get_capability (portInfo)
  199197. & (forInput ? SND_SEQ_PORT_CAP_READ
  199198. : SND_SEQ_PORT_CAP_WRITE)) != 0)
  199199. {
  199200. deviceNamesFound.add (snd_seq_client_info_get_name (clientInfo));
  199201. if (deviceNamesFound.size() == deviceIndexToOpen + 1)
  199202. {
  199203. const int sourcePort = snd_seq_port_info_get_port (portInfo);
  199204. const int sourceClient = snd_seq_client_info_get_client (clientInfo);
  199205. if (sourcePort != -1)
  199206. {
  199207. snd_seq_set_client_name (seqHandle,
  199208. forInput ? "Juce Midi Input"
  199209. : "Juce Midi Output");
  199210. const int portId
  199211. = snd_seq_create_simple_port (seqHandle,
  199212. forInput ? "Juce Midi In Port"
  199213. : "Juce Midi Out Port",
  199214. forInput ? (SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_WRITE)
  199215. : (SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_READ),
  199216. SND_SEQ_PORT_TYPE_MIDI_GENERIC);
  199217. snd_seq_connect_from (seqHandle, portId, sourceClient, sourcePort);
  199218. returnedHandle = seqHandle;
  199219. }
  199220. }
  199221. }
  199222. }
  199223. snd_seq_port_info_free (portInfo);
  199224. }
  199225. }
  199226. }
  199227. snd_seq_client_info_free (clientInfo);
  199228. }
  199229. snd_seq_system_info_free (systemInfo);
  199230. }
  199231. if (returnedHandle == 0)
  199232. snd_seq_close (seqHandle);
  199233. }
  199234. deviceNamesFound.appendNumbersToDuplicates (true, true);
  199235. return returnedHandle;
  199236. }
  199237. static snd_seq_t* createDevice (const bool forInput,
  199238. const String& deviceNameToOpen)
  199239. {
  199240. snd_seq_t* seqHandle = 0;
  199241. if (snd_seq_open (&seqHandle, "default", forInput ? SND_SEQ_OPEN_INPUT
  199242. : SND_SEQ_OPEN_OUTPUT, 0) == 0)
  199243. {
  199244. snd_seq_set_client_name (seqHandle,
  199245. (deviceNameToOpen + (forInput ? " Input" : " Output")).toCString());
  199246. const int portId
  199247. = snd_seq_create_simple_port (seqHandle,
  199248. forInput ? "in"
  199249. : "out",
  199250. forInput ? (SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_WRITE)
  199251. : (SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_READ),
  199252. forInput ? SND_SEQ_PORT_TYPE_APPLICATION
  199253. : SND_SEQ_PORT_TYPE_MIDI_GENERIC);
  199254. if (portId < 0)
  199255. {
  199256. snd_seq_close (seqHandle);
  199257. seqHandle = 0;
  199258. }
  199259. }
  199260. return seqHandle;
  199261. }
  199262. class MidiOutputDevice
  199263. {
  199264. public:
  199265. MidiOutputDevice (MidiOutput* const midiOutput_,
  199266. snd_seq_t* const seqHandle_)
  199267. :
  199268. midiOutput (midiOutput_),
  199269. seqHandle (seqHandle_),
  199270. maxEventSize (16 * 1024)
  199271. {
  199272. jassert (seqHandle != 0 && midiOutput != 0);
  199273. snd_midi_event_new (maxEventSize, &midiParser);
  199274. }
  199275. ~MidiOutputDevice()
  199276. {
  199277. snd_midi_event_free (midiParser);
  199278. snd_seq_close (seqHandle);
  199279. }
  199280. void sendMessageNow (const MidiMessage& message)
  199281. {
  199282. if (message.getRawDataSize() > maxEventSize)
  199283. {
  199284. maxEventSize = message.getRawDataSize();
  199285. snd_midi_event_free (midiParser);
  199286. snd_midi_event_new (maxEventSize, &midiParser);
  199287. }
  199288. snd_seq_event_t event;
  199289. snd_seq_ev_clear (&event);
  199290. snd_midi_event_encode (midiParser,
  199291. message.getRawData(),
  199292. message.getRawDataSize(),
  199293. &event);
  199294. snd_midi_event_reset_encode (midiParser);
  199295. snd_seq_ev_set_source (&event, 0);
  199296. snd_seq_ev_set_subs (&event);
  199297. snd_seq_ev_set_direct (&event);
  199298. snd_seq_event_output (seqHandle, &event);
  199299. snd_seq_drain_output (seqHandle);
  199300. }
  199301. juce_UseDebuggingNewOperator
  199302. private:
  199303. MidiOutput* const midiOutput;
  199304. snd_seq_t* const seqHandle;
  199305. snd_midi_event_t* midiParser;
  199306. int maxEventSize;
  199307. };
  199308. const StringArray MidiOutput::getDevices()
  199309. {
  199310. StringArray devices;
  199311. iterateDevices (false, devices, -1);
  199312. return devices;
  199313. }
  199314. int MidiOutput::getDefaultDeviceIndex()
  199315. {
  199316. return 0;
  199317. }
  199318. MidiOutput* MidiOutput::openDevice (int deviceIndex)
  199319. {
  199320. MidiOutput* newDevice = 0;
  199321. StringArray devices;
  199322. snd_seq_t* const handle = iterateDevices (false, devices, deviceIndex);
  199323. if (handle != 0)
  199324. {
  199325. newDevice = new MidiOutput();
  199326. newDevice->internal = new MidiOutputDevice (newDevice, handle);
  199327. }
  199328. return newDevice;
  199329. }
  199330. MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
  199331. {
  199332. MidiOutput* newDevice = 0;
  199333. snd_seq_t* const handle = createDevice (false, deviceName);
  199334. if (handle != 0)
  199335. {
  199336. newDevice = new MidiOutput();
  199337. newDevice->internal = new MidiOutputDevice (newDevice, handle);
  199338. }
  199339. return newDevice;
  199340. }
  199341. MidiOutput::~MidiOutput()
  199342. {
  199343. MidiOutputDevice* const device = (MidiOutputDevice*) internal;
  199344. delete device;
  199345. }
  199346. void MidiOutput::reset()
  199347. {
  199348. }
  199349. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  199350. {
  199351. return false;
  199352. }
  199353. void MidiOutput::setVolume (float leftVol, float rightVol)
  199354. {
  199355. }
  199356. void MidiOutput::sendMessageNow (const MidiMessage& message)
  199357. {
  199358. ((MidiOutputDevice*) internal)->sendMessageNow (message);
  199359. }
  199360. class MidiInputThread : public Thread
  199361. {
  199362. public:
  199363. MidiInputThread (MidiInput* const midiInput_,
  199364. snd_seq_t* const seqHandle_,
  199365. MidiInputCallback* const callback_)
  199366. : Thread (T("Juce MIDI Input")),
  199367. midiInput (midiInput_),
  199368. seqHandle (seqHandle_),
  199369. callback (callback_)
  199370. {
  199371. jassert (seqHandle != 0 && callback != 0 && midiInput != 0);
  199372. }
  199373. ~MidiInputThread()
  199374. {
  199375. snd_seq_close (seqHandle);
  199376. }
  199377. void run()
  199378. {
  199379. const int maxEventSize = 16 * 1024;
  199380. snd_midi_event_t* midiParser;
  199381. if (snd_midi_event_new (maxEventSize, &midiParser) >= 0)
  199382. {
  199383. HeapBlock <uint8> buffer (maxEventSize);
  199384. const int numPfds = snd_seq_poll_descriptors_count (seqHandle, POLLIN);
  199385. struct pollfd* const pfd = (struct pollfd*) alloca (numPfds * sizeof (struct pollfd));
  199386. snd_seq_poll_descriptors (seqHandle, pfd, numPfds, POLLIN);
  199387. while (! threadShouldExit())
  199388. {
  199389. if (poll (pfd, numPfds, 500) > 0)
  199390. {
  199391. snd_seq_event_t* inputEvent = 0;
  199392. snd_seq_nonblock (seqHandle, 1);
  199393. do
  199394. {
  199395. if (snd_seq_event_input (seqHandle, &inputEvent) >= 0)
  199396. {
  199397. // xxx what about SYSEXes that are too big for the buffer?
  199398. const int numBytes = snd_midi_event_decode (midiParser, buffer, maxEventSize, inputEvent);
  199399. snd_midi_event_reset_decode (midiParser);
  199400. if (numBytes > 0)
  199401. {
  199402. const MidiMessage message ((const uint8*) buffer,
  199403. numBytes,
  199404. Time::getMillisecondCounter() * 0.001);
  199405. callback->handleIncomingMidiMessage (midiInput, message);
  199406. }
  199407. snd_seq_free_event (inputEvent);
  199408. }
  199409. }
  199410. while (snd_seq_event_input_pending (seqHandle, 0) > 0);
  199411. snd_seq_free_event (inputEvent);
  199412. }
  199413. }
  199414. snd_midi_event_free (midiParser);
  199415. }
  199416. };
  199417. juce_UseDebuggingNewOperator
  199418. private:
  199419. MidiInput* const midiInput;
  199420. snd_seq_t* const seqHandle;
  199421. MidiInputCallback* const callback;
  199422. };
  199423. MidiInput::MidiInput (const String& name_)
  199424. : name (name_),
  199425. internal (0)
  199426. {
  199427. }
  199428. MidiInput::~MidiInput()
  199429. {
  199430. stop();
  199431. MidiInputThread* const thread = (MidiInputThread*) internal;
  199432. delete thread;
  199433. }
  199434. void MidiInput::start()
  199435. {
  199436. ((MidiInputThread*) internal)->startThread();
  199437. }
  199438. void MidiInput::stop()
  199439. {
  199440. ((MidiInputThread*) internal)->stopThread (3000);
  199441. }
  199442. int MidiInput::getDefaultDeviceIndex()
  199443. {
  199444. return 0;
  199445. }
  199446. const StringArray MidiInput::getDevices()
  199447. {
  199448. StringArray devices;
  199449. iterateDevices (true, devices, -1);
  199450. return devices;
  199451. }
  199452. MidiInput* MidiInput::openDevice (int deviceIndex, MidiInputCallback* callback)
  199453. {
  199454. MidiInput* newDevice = 0;
  199455. StringArray devices;
  199456. snd_seq_t* const handle = iterateDevices (true, devices, deviceIndex);
  199457. if (handle != 0)
  199458. {
  199459. newDevice = new MidiInput (devices [deviceIndex]);
  199460. newDevice->internal = new MidiInputThread (newDevice, handle, callback);
  199461. }
  199462. return newDevice;
  199463. }
  199464. MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback)
  199465. {
  199466. MidiInput* newDevice = 0;
  199467. snd_seq_t* const handle = createDevice (true, deviceName);
  199468. if (handle != 0)
  199469. {
  199470. newDevice = new MidiInput (deviceName);
  199471. newDevice->internal = new MidiInputThread (newDevice, handle, callback);
  199472. }
  199473. return newDevice;
  199474. }
  199475. #else
  199476. // (These are just stub functions if ALSA is unavailable...)
  199477. const StringArray MidiOutput::getDevices() { return StringArray(); }
  199478. int MidiOutput::getDefaultDeviceIndex() { return 0; }
  199479. MidiOutput* MidiOutput::openDevice (int) { return 0; }
  199480. MidiOutput* MidiOutput::createNewDevice (const String&) { return 0; }
  199481. MidiOutput::~MidiOutput() {}
  199482. void MidiOutput::reset() {}
  199483. bool MidiOutput::getVolume (float&, float&) { return false; }
  199484. void MidiOutput::setVolume (float, float) {}
  199485. void MidiOutput::sendMessageNow (const MidiMessage&) {}
  199486. MidiInput::MidiInput (const String& name_) : name (name_), internal (0) {}
  199487. MidiInput::~MidiInput() {}
  199488. void MidiInput::start() {}
  199489. void MidiInput::stop() {}
  199490. int MidiInput::getDefaultDeviceIndex() { return 0; }
  199491. const StringArray MidiInput::getDevices() { return StringArray(); }
  199492. MidiInput* MidiInput::openDevice (int, MidiInputCallback*) { return 0; }
  199493. MidiInput* MidiInput::createNewDevice (const String&, MidiInputCallback*) { return 0; }
  199494. #endif
  199495. #endif
  199496. /*** End of inlined file: juce_linux_Midi.cpp ***/
  199497. /*** Start of inlined file: juce_linux_AudioCDReader.cpp ***/
  199498. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199499. // compiled on its own).
  199500. #if JUCE_INCLUDED_FILE && JUCE_USE_CDREADER
  199501. AudioCDReader::AudioCDReader()
  199502. : AudioFormatReader (0, T("CD Audio"))
  199503. {
  199504. }
  199505. const StringArray AudioCDReader::getAvailableCDNames()
  199506. {
  199507. StringArray names;
  199508. return names;
  199509. }
  199510. AudioCDReader* AudioCDReader::createReaderForCD (const int index)
  199511. {
  199512. return 0;
  199513. }
  199514. AudioCDReader::~AudioCDReader()
  199515. {
  199516. }
  199517. void AudioCDReader::refreshTrackLengths()
  199518. {
  199519. }
  199520. bool AudioCDReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  199521. int64 startSampleInFile, int numSamples)
  199522. {
  199523. return false;
  199524. }
  199525. bool AudioCDReader::isCDStillPresent() const
  199526. {
  199527. return false;
  199528. }
  199529. int AudioCDReader::getNumTracks() const
  199530. {
  199531. return 0;
  199532. }
  199533. int AudioCDReader::getPositionOfTrackStart (int trackNum) const
  199534. {
  199535. return 0;
  199536. }
  199537. bool AudioCDReader::isTrackAudio (int trackNum) const
  199538. {
  199539. return false;
  199540. }
  199541. void AudioCDReader::enableIndexScanning (bool b)
  199542. {
  199543. }
  199544. int AudioCDReader::getLastIndex() const
  199545. {
  199546. return 0;
  199547. }
  199548. const Array<int> AudioCDReader::findIndexesInTrack (const int trackNumber)
  199549. {
  199550. return Array<int>();
  199551. }
  199552. int AudioCDReader::getCDDBId()
  199553. {
  199554. return 0;
  199555. }
  199556. #endif
  199557. /*** End of inlined file: juce_linux_AudioCDReader.cpp ***/
  199558. /*** Start of inlined file: juce_linux_FileChooser.cpp ***/
  199559. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199560. // compiled on its own).
  199561. #if JUCE_INCLUDED_FILE
  199562. void FileChooser::showPlatformDialog (Array<File>& results,
  199563. const String& title,
  199564. const File& file,
  199565. const String& filters,
  199566. bool isDirectory,
  199567. bool selectsFiles,
  199568. bool isSave,
  199569. bool warnAboutOverwritingExistingFiles,
  199570. bool selectMultipleFiles,
  199571. FilePreviewComponent* previewComponent)
  199572. {
  199573. const tchar* const separator = T(":");
  199574. String command ("zenity --file-selection");
  199575. if (title.isNotEmpty())
  199576. command << " --title=\"" << title << "\"";
  199577. if (file != File::nonexistent)
  199578. command << " --filename=\"" << file.getFullPathName () << "\"";
  199579. if (isDirectory)
  199580. command << " --directory";
  199581. if (isSave)
  199582. command << " --save";
  199583. if (selectMultipleFiles)
  199584. command << " --multiple --separator=\"" << separator << "\"";
  199585. command << " 2>&1";
  199586. MemoryOutputStream result;
  199587. int status = -1;
  199588. FILE* stream = popen ((const char*) command.toUTF8(), "r");
  199589. if (stream != 0)
  199590. {
  199591. for (;;)
  199592. {
  199593. char buffer [1024];
  199594. const int bytesRead = fread (buffer, 1, sizeof (buffer), stream);
  199595. if (bytesRead <= 0)
  199596. break;
  199597. result.write (buffer, bytesRead);
  199598. }
  199599. status = pclose (stream);
  199600. }
  199601. if (status == 0)
  199602. {
  199603. String resultString (String::fromUTF8 ((const char*) result.getData(), result.getDataSize()));
  199604. StringArray tokens;
  199605. if (selectMultipleFiles)
  199606. tokens.addTokens (resultString, separator, 0);
  199607. else
  199608. tokens.add (resultString);
  199609. for (int i = 0; i < tokens.size(); i++)
  199610. results.add (File (tokens[i]));
  199611. return;
  199612. }
  199613. //xxx ain't got one!
  199614. jassertfalse
  199615. }
  199616. #endif
  199617. /*** End of inlined file: juce_linux_FileChooser.cpp ***/
  199618. /*** Start of inlined file: juce_linux_WebBrowserComponent.cpp ***/
  199619. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199620. // compiled on its own).
  199621. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  199622. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  199623. : browser (0),
  199624. blankPageShown (false),
  199625. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  199626. {
  199627. setOpaque (true);
  199628. }
  199629. WebBrowserComponent::~WebBrowserComponent()
  199630. {
  199631. }
  199632. void WebBrowserComponent::goToURL (const String& url,
  199633. const StringArray* headers,
  199634. const MemoryBlock* postData)
  199635. {
  199636. lastURL = url;
  199637. lastHeaders.clear();
  199638. if (headers != 0)
  199639. lastHeaders = *headers;
  199640. lastPostData.setSize (0);
  199641. if (postData != 0)
  199642. lastPostData = *postData;
  199643. blankPageShown = false;
  199644. }
  199645. void WebBrowserComponent::stop()
  199646. {
  199647. }
  199648. void WebBrowserComponent::goBack()
  199649. {
  199650. lastURL = String::empty;
  199651. blankPageShown = false;
  199652. }
  199653. void WebBrowserComponent::goForward()
  199654. {
  199655. lastURL = String::empty;
  199656. }
  199657. void WebBrowserComponent::refresh()
  199658. {
  199659. }
  199660. void WebBrowserComponent::paint (Graphics& g)
  199661. {
  199662. g.fillAll (Colours::white);
  199663. }
  199664. void WebBrowserComponent::checkWindowAssociation()
  199665. {
  199666. }
  199667. void WebBrowserComponent::reloadLastURL()
  199668. {
  199669. if (lastURL.isNotEmpty())
  199670. {
  199671. goToURL (lastURL, &lastHeaders, &lastPostData);
  199672. lastURL = String::empty;
  199673. }
  199674. }
  199675. void WebBrowserComponent::parentHierarchyChanged()
  199676. {
  199677. checkWindowAssociation();
  199678. }
  199679. void WebBrowserComponent::resized()
  199680. {
  199681. }
  199682. void WebBrowserComponent::visibilityChanged()
  199683. {
  199684. checkWindowAssociation();
  199685. }
  199686. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  199687. {
  199688. return true;
  199689. }
  199690. #endif
  199691. /*** End of inlined file: juce_linux_WebBrowserComponent.cpp ***/
  199692. #endif
  199693. END_JUCE_NAMESPACE
  199694. #endif
  199695. /*** End of inlined file: juce_linux_NativeCode.cpp ***/
  199696. #endif
  199697. #if JUCE_MAC || JUCE_IPHONE
  199698. /*** Start of inlined file: juce_mac_NativeCode.mm ***/
  199699. #if JUCE_MAC || JUCE_IPHONE
  199700. BEGIN_JUCE_NAMESPACE
  199701. #undef Point
  199702. #define JUCE_INCLUDED_FILE 1
  199703. // Now include the actual code files..
  199704. /*** Start of inlined file: juce_mac_ObjCSuffix.h ***/
  199705. #ifndef JUCE_ObjCExtraSuffix
  199706. #define JUCE_ObjCExtraSuffix 3
  199707. #endif
  199708. #define appendMacro1(a, b, c, d, e) a ## _ ## b ## _ ## c ## _ ## d ## _ ## e
  199709. #define appendMacro2(a, b, c, d, e) appendMacro1(a, b, c, d, e)
  199710. #define MakeObjCClassName(rootName) appendMacro2 (rootName, JUCE_MAJOR_VERSION, JUCE_MINOR_VERSION, JUCE_BUILDNUMBER, JUCE_ObjCExtraSuffix)
  199711. /*** End of inlined file: juce_mac_ObjCSuffix.h ***/
  199712. /*** Start of inlined file: juce_mac_Strings.mm ***/
  199713. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  199714. // compiled on its own).
  199715. #if JUCE_INCLUDED_FILE
  199716. static const String nsStringToJuce (NSString* s)
  199717. {
  199718. return String::fromUTF8 ([s UTF8String]);
  199719. }
  199720. static NSString* juceStringToNS (const String& s)
  199721. {
  199722. return [NSString stringWithUTF8String: s.toUTF8()];
  199723. }
  199724. static const String convertUTF16ToString (const UniChar* utf16)
  199725. {
  199726. String s;
  199727. while (*utf16 != 0)
  199728. s += (juce_wchar) *utf16++;
  199729. return s;
  199730. }
  199731. const String PlatformUtilities::cfStringToJuceString (CFStringRef cfString)
  199732. {
  199733. String result;
  199734. if (cfString != 0)
  199735. {
  199736. CFRange range = { 0, CFStringGetLength (cfString) };
  199737. HeapBlock <UniChar> u (range.length + 1);
  199738. CFStringGetCharacters (cfString, range, u);
  199739. u[range.length] = 0;
  199740. result = convertUTF16ToString (u);
  199741. }
  199742. return result;
  199743. }
  199744. CFStringRef PlatformUtilities::juceStringToCFString (const String& s)
  199745. {
  199746. const int len = s.length();
  199747. const juce_wchar* t = (const juce_wchar*) s;
  199748. HeapBlock <UniChar> temp (len + 2);
  199749. for (int i = 0; i <= len; ++i)
  199750. temp[i] = t[i];
  199751. return CFStringCreateWithCharacters (kCFAllocatorDefault, temp, len);
  199752. }
  199753. const String PlatformUtilities::convertToPrecomposedUnicode (const String& s)
  199754. {
  199755. #if JUCE_IPHONE
  199756. const ScopedAutoReleasePool pool;
  199757. return nsStringToJuce ([juceStringToNS (s) precomposedStringWithCanonicalMapping]);
  199758. #else
  199759. UnicodeMapping map;
  199760. map.unicodeEncoding = CreateTextEncoding (kTextEncodingUnicodeDefault,
  199761. kUnicodeNoSubset,
  199762. kTextEncodingDefaultFormat);
  199763. map.otherEncoding = CreateTextEncoding (kTextEncodingUnicodeDefault,
  199764. kUnicodeCanonicalCompVariant,
  199765. kTextEncodingDefaultFormat);
  199766. map.mappingVersion = kUnicodeUseLatestMapping;
  199767. UnicodeToTextInfo conversionInfo = 0;
  199768. String result;
  199769. if (CreateUnicodeToTextInfo (&map, &conversionInfo) == noErr)
  199770. {
  199771. const int len = s.length();
  199772. HeapBlock <UniChar> tempIn, tempOut;
  199773. tempIn.calloc (len + 2);
  199774. tempOut.calloc (len + 2);
  199775. for (int i = 0; i <= len; ++i)
  199776. tempIn[i] = s[i];
  199777. ByteCount bytesRead = 0;
  199778. ByteCount outputBufferSize = 0;
  199779. if (ConvertFromUnicodeToText (conversionInfo,
  199780. len * sizeof (UniChar), tempIn,
  199781. kUnicodeDefaultDirectionMask,
  199782. 0, 0, 0, 0,
  199783. len * sizeof (UniChar), &bytesRead,
  199784. &outputBufferSize, tempOut) == noErr)
  199785. {
  199786. result.preallocateStorage (bytesRead / sizeof (UniChar) + 2);
  199787. tchar* t = const_cast <tchar*> ((const tchar*) result);
  199788. unsigned int i;
  199789. for (i = 0; i < bytesRead / sizeof (UniChar); ++i)
  199790. t[i] = (tchar) tempOut[i];
  199791. t[i] = 0;
  199792. }
  199793. DisposeUnicodeToTextInfo (&conversionInfo);
  199794. }
  199795. return result;
  199796. #endif
  199797. }
  199798. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  199799. void SystemClipboard::copyTextToClipboard (const String& text) throw()
  199800. {
  199801. #if JUCE_IPHONE
  199802. [[UIPasteboard generalPasteboard] setValue: juceStringToNS (text)
  199803. forPasteboardType: @"public.text"];
  199804. #else
  199805. [[NSPasteboard generalPasteboard] declareTypes: [NSArray arrayWithObject: NSStringPboardType]
  199806. owner: nil];
  199807. [[NSPasteboard generalPasteboard] setString: juceStringToNS (text)
  199808. forType: NSStringPboardType];
  199809. #endif
  199810. }
  199811. const String SystemClipboard::getTextFromClipboard() throw()
  199812. {
  199813. #if JUCE_IPHONE
  199814. NSString* text = [[UIPasteboard generalPasteboard] valueForPasteboardType: @"public.text"];
  199815. #else
  199816. NSString* text = [[NSPasteboard generalPasteboard] stringForType: NSStringPboardType];
  199817. #endif
  199818. return text == 0 ? String::empty
  199819. : nsStringToJuce (text);
  199820. }
  199821. #endif
  199822. #endif
  199823. /*** End of inlined file: juce_mac_Strings.mm ***/
  199824. /*** Start of inlined file: juce_mac_SystemStats.mm ***/
  199825. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  199826. // compiled on its own).
  199827. #if JUCE_INCLUDED_FILE
  199828. static int64 highResTimerFrequency = 0;
  199829. static double highResTimerToMillisecRatio = 0;
  199830. #if JUCE_INTEL
  199831. static void juce_getCpuVendor (char* const v) throw()
  199832. {
  199833. int vendor[4];
  199834. zerostruct (vendor);
  199835. int dummy = 0;
  199836. asm ("mov %%ebx, %%esi \n\t"
  199837. "cpuid \n\t"
  199838. "xchg %%esi, %%ebx"
  199839. : "=a" (dummy), "=S" (vendor[0]), "=c" (vendor[2]), "=d" (vendor[1]) : "a" (0));
  199840. memcpy (v, vendor, 16);
  199841. }
  199842. static unsigned int getCPUIDWord (unsigned int& familyModel, unsigned int& extFeatures)
  199843. {
  199844. unsigned int cpu = 0;
  199845. unsigned int ext = 0;
  199846. unsigned int family = 0;
  199847. unsigned int dummy = 0;
  199848. asm ("mov %%ebx, %%esi \n\t"
  199849. "cpuid \n\t"
  199850. "xchg %%esi, %%ebx"
  199851. : "=a" (family), "=S" (ext), "=c" (dummy), "=d" (cpu) : "a" (1));
  199852. familyModel = family;
  199853. extFeatures = ext;
  199854. return cpu;
  199855. }
  199856. struct CPUFlags
  199857. {
  199858. bool hasMMX : 1;
  199859. bool hasSSE : 1;
  199860. bool hasSSE2 : 1;
  199861. bool has3DNow : 1;
  199862. };
  199863. static CPUFlags cpuFlags;
  199864. #endif
  199865. void SystemStats::initialiseStats() throw()
  199866. {
  199867. static bool initialised = false;
  199868. if (! initialised)
  199869. {
  199870. initialised = true;
  199871. #if JUCE_MAC
  199872. // extremely annoying: adding this line stops the apple menu items from working. Of
  199873. // course, not adding it means that carbon windows (e.g. in plugins) won't get
  199874. // any events.
  199875. //NSApplicationLoad();
  199876. [NSApplication sharedApplication];
  199877. #endif
  199878. #if JUCE_INTEL
  199879. {
  199880. unsigned int familyModel, extFeatures;
  199881. const unsigned int features = getCPUIDWord (familyModel, extFeatures);
  199882. cpuFlags.hasMMX = ((features & (1 << 23)) != 0);
  199883. cpuFlags.hasSSE = ((features & (1 << 25)) != 0);
  199884. cpuFlags.hasSSE2 = ((features & (1 << 26)) != 0);
  199885. cpuFlags.has3DNow = ((extFeatures & (1 << 31)) != 0);
  199886. }
  199887. #endif
  199888. mach_timebase_info_data_t timebase;
  199889. (void) mach_timebase_info (&timebase);
  199890. highResTimerFrequency = (int64) (1.0e9 * timebase.denom / timebase.numer);
  199891. highResTimerToMillisecRatio = timebase.numer / (1.0e6 * timebase.denom);
  199892. String s (SystemStats::getJUCEVersion());
  199893. rlimit lim;
  199894. getrlimit (RLIMIT_NOFILE, &lim);
  199895. lim.rlim_cur = lim.rlim_max = RLIM_INFINITY;
  199896. setrlimit (RLIMIT_NOFILE, &lim);
  199897. }
  199898. }
  199899. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  199900. {
  199901. return MacOSX;
  199902. }
  199903. const String SystemStats::getOperatingSystemName() throw()
  199904. {
  199905. return T("Mac OS X");
  199906. }
  199907. bool SystemStats::isOperatingSystem64Bit() throw()
  199908. {
  199909. #if JUCE_64BIT
  199910. return true;
  199911. #else
  199912. //xxx not sure how to find this out?..
  199913. return false;
  199914. #endif
  199915. }
  199916. int SystemStats::getMemorySizeInMegabytes() throw()
  199917. {
  199918. uint64 mem = 0;
  199919. size_t memSize = sizeof (mem);
  199920. int mib[] = { CTL_HW, HW_MEMSIZE };
  199921. sysctl (mib, 2, &mem, &memSize, 0, 0);
  199922. return (int) (mem / (1024 * 1024));
  199923. }
  199924. bool SystemStats::hasMMX() throw()
  199925. {
  199926. #if JUCE_INTEL
  199927. return cpuFlags.hasMMX;
  199928. #else
  199929. return false;
  199930. #endif
  199931. }
  199932. bool SystemStats::hasSSE() throw()
  199933. {
  199934. #if JUCE_INTEL
  199935. return cpuFlags.hasSSE;
  199936. #else
  199937. return false;
  199938. #endif
  199939. }
  199940. bool SystemStats::hasSSE2() throw()
  199941. {
  199942. #if JUCE_INTEL
  199943. return cpuFlags.hasSSE2;
  199944. #else
  199945. return false;
  199946. #endif
  199947. }
  199948. bool SystemStats::has3DNow() throw()
  199949. {
  199950. #if JUCE_INTEL
  199951. return cpuFlags.has3DNow;
  199952. #else
  199953. return false;
  199954. #endif
  199955. }
  199956. const String SystemStats::getCpuVendor() throw()
  199957. {
  199958. #if JUCE_INTEL
  199959. char v [16];
  199960. juce_getCpuVendor (v);
  199961. return String (v, 16);
  199962. #else
  199963. return String::empty;
  199964. #endif
  199965. }
  199966. int SystemStats::getCpuSpeedInMegaherz() throw()
  199967. {
  199968. uint64 speedHz = 0;
  199969. size_t speedSize = sizeof (speedHz);
  199970. int mib[] = { CTL_HW, HW_CPU_FREQ };
  199971. sysctl (mib, 2, &speedHz, &speedSize, 0, 0);
  199972. #if JUCE_BIG_ENDIAN
  199973. if (speedSize == 4)
  199974. speedHz >>= 32;
  199975. #endif
  199976. return (int) (speedHz / 1000000);
  199977. }
  199978. int SystemStats::getNumCpus() throw()
  199979. {
  199980. #if JUCE_IPHONE || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5)
  199981. return (int) [[NSProcessInfo processInfo] activeProcessorCount];
  199982. #else
  199983. return MPProcessors();
  199984. #endif
  199985. }
  199986. const String SystemStats::getLogonName()
  199987. {
  199988. return nsStringToJuce (NSUserName());
  199989. }
  199990. const String SystemStats::getFullUserName()
  199991. {
  199992. return nsStringToJuce (NSFullUserName());
  199993. }
  199994. uint32 juce_millisecondsSinceStartup() throw()
  199995. {
  199996. return (uint32) (mach_absolute_time() * highResTimerToMillisecRatio);
  199997. }
  199998. double Time::getMillisecondCounterHiRes() throw()
  199999. {
  200000. return mach_absolute_time() * highResTimerToMillisecRatio;
  200001. }
  200002. int64 Time::getHighResolutionTicks() throw()
  200003. {
  200004. return (int64) mach_absolute_time();
  200005. }
  200006. int64 Time::getHighResolutionTicksPerSecond() throw()
  200007. {
  200008. return highResTimerFrequency;
  200009. }
  200010. int64 SystemStats::getClockCycleCounter() throw()
  200011. {
  200012. return (int64) mach_absolute_time();
  200013. }
  200014. bool Time::setSystemTimeToThisTime() const throw()
  200015. {
  200016. jassertfalse
  200017. return false;
  200018. }
  200019. int SystemStats::getPageSize() throw()
  200020. {
  200021. return (int) NSPageSize();
  200022. }
  200023. void PlatformUtilities::fpuReset()
  200024. {
  200025. }
  200026. #endif
  200027. /*** End of inlined file: juce_mac_SystemStats.mm ***/
  200028. /*** Start of inlined file: juce_mac_Network.mm ***/
  200029. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200030. // compiled on its own).
  200031. #if JUCE_INCLUDED_FILE
  200032. int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian)
  200033. {
  200034. #ifndef IFT_ETHER
  200035. #define IFT_ETHER 6
  200036. #endif
  200037. ifaddrs* addrs = 0;
  200038. int numResults = 0;
  200039. if (getifaddrs (&addrs) == 0)
  200040. {
  200041. const ifaddrs* cursor = addrs;
  200042. while (cursor != 0 && numResults < maxNum)
  200043. {
  200044. sockaddr_storage* sto = (sockaddr_storage*) cursor->ifa_addr;
  200045. if (sto->ss_family == AF_LINK)
  200046. {
  200047. const sockaddr_dl* const sadd = (const sockaddr_dl*) cursor->ifa_addr;
  200048. if (sadd->sdl_type == IFT_ETHER)
  200049. {
  200050. const uint8* const addr = ((const uint8*) sadd->sdl_data) + sadd->sdl_nlen;
  200051. uint64 a = 0;
  200052. for (int i = 6; --i >= 0;)
  200053. a = (a << 8) | addr [littleEndian ? i : (5 - i)];
  200054. *addresses++ = (int64) a;
  200055. ++numResults;
  200056. }
  200057. }
  200058. cursor = cursor->ifa_next;
  200059. }
  200060. freeifaddrs (addrs);
  200061. }
  200062. return numResults;
  200063. }
  200064. bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
  200065. const String& emailSubject,
  200066. const String& bodyText,
  200067. const StringArray& filesToAttach)
  200068. {
  200069. #if JUCE_IPHONE
  200070. //xxx probably need to use MFMailComposeViewController
  200071. jassertfalse
  200072. return false;
  200073. #else
  200074. const ScopedAutoReleasePool pool;
  200075. String script;
  200076. script << "tell application \"Mail\"\r\n"
  200077. "set newMessage to make new outgoing message with properties {subject:\""
  200078. << emailSubject.replace (T("\""), T("\\\""))
  200079. << "\", content:\""
  200080. << bodyText.replace (T("\""), T("\\\""))
  200081. << "\" & return & return}\r\n"
  200082. "tell newMessage\r\n"
  200083. "set visible to true\r\n"
  200084. "set sender to \"sdfsdfsdfewf\"\r\n"
  200085. "make new to recipient at end of to recipients with properties {address:\""
  200086. << targetEmailAddress
  200087. << "\"}\r\n";
  200088. for (int i = 0; i < filesToAttach.size(); ++i)
  200089. {
  200090. script << "tell content\r\n"
  200091. "make new attachment with properties {file name:\""
  200092. << filesToAttach[i].replace (T("\""), T("\\\""))
  200093. << "\"} at after the last paragraph\r\n"
  200094. "end tell\r\n";
  200095. }
  200096. script << "end tell\r\n"
  200097. "end tell\r\n";
  200098. NSAppleScript* s = [[NSAppleScript alloc]
  200099. initWithSource: juceStringToNS (script)];
  200100. NSDictionary* error = 0;
  200101. const bool ok = [s executeAndReturnError: &error] != nil;
  200102. [s release];
  200103. return ok;
  200104. #endif
  200105. }
  200106. END_JUCE_NAMESPACE
  200107. using namespace JUCE_NAMESPACE;
  200108. #define JuceURLConnection MakeObjCClassName(JuceURLConnection)
  200109. @interface JuceURLConnection : NSObject
  200110. {
  200111. @public
  200112. NSURLRequest* request;
  200113. NSURLConnection* connection;
  200114. NSMutableData* data;
  200115. Thread* runLoopThread;
  200116. bool initialised, hasFailed, hasFinished;
  200117. int position;
  200118. int64 contentLength;
  200119. NSLock* dataLock;
  200120. }
  200121. - (JuceURLConnection*) initWithRequest: (NSURLRequest*) req withCallback: (URL::OpenStreamProgressCallback*) callback withContext: (void*) context;
  200122. - (void) dealloc;
  200123. - (void) connection: (NSURLConnection*) connection didReceiveResponse: (NSURLResponse*) response;
  200124. - (void) connection: (NSURLConnection*) connection didFailWithError: (NSError*) error;
  200125. - (void) connection: (NSURLConnection*) connection didReceiveData: (NSData*) data;
  200126. - (void) connectionDidFinishLoading: (NSURLConnection*) connection;
  200127. - (BOOL) isOpen;
  200128. - (int) read: (char*) dest numBytes: (int) num;
  200129. - (int) readPosition;
  200130. - (void) stop;
  200131. - (void) createConnection;
  200132. @end
  200133. class JuceURLConnectionMessageThread : public Thread
  200134. {
  200135. JuceURLConnection* owner;
  200136. public:
  200137. JuceURLConnectionMessageThread (JuceURLConnection* owner_)
  200138. : Thread (T("http connection")),
  200139. owner (owner_)
  200140. {
  200141. }
  200142. ~JuceURLConnectionMessageThread()
  200143. {
  200144. stopThread (10000);
  200145. }
  200146. void run()
  200147. {
  200148. [owner createConnection];
  200149. while (! threadShouldExit())
  200150. {
  200151. const ScopedAutoReleasePool pool;
  200152. [[NSRunLoop currentRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.01]];
  200153. }
  200154. }
  200155. };
  200156. @implementation JuceURLConnection
  200157. - (JuceURLConnection*) initWithRequest: (NSURLRequest*) req
  200158. withCallback: (URL::OpenStreamProgressCallback*) callback
  200159. withContext: (void*) context;
  200160. {
  200161. [super init];
  200162. request = req;
  200163. [request retain];
  200164. data = [[NSMutableData data] retain];
  200165. dataLock = [[NSLock alloc] init];
  200166. connection = 0;
  200167. initialised = false;
  200168. hasFailed = false;
  200169. hasFinished = false;
  200170. contentLength = -1;
  200171. runLoopThread = new JuceURLConnectionMessageThread (self);
  200172. runLoopThread->startThread();
  200173. while (runLoopThread->isThreadRunning() && ! initialised)
  200174. {
  200175. if (callback != 0)
  200176. callback (context, -1, (int) [[request HTTPBody] length]);
  200177. Thread::sleep (1);
  200178. }
  200179. return self;
  200180. }
  200181. - (void) dealloc
  200182. {
  200183. [self stop];
  200184. delete runLoopThread;
  200185. [connection release];
  200186. [data release];
  200187. [dataLock release];
  200188. [request release];
  200189. [super dealloc];
  200190. }
  200191. - (void) createConnection
  200192. {
  200193. connection = [[NSURLConnection alloc] initWithRequest: request
  200194. delegate: [self retain]];
  200195. if (connection == nil)
  200196. runLoopThread->signalThreadShouldExit();
  200197. }
  200198. - (void) connection: (NSURLConnection*) connection didReceiveResponse: (NSURLResponse*) response
  200199. {
  200200. [dataLock lock];
  200201. [data setLength: 0];
  200202. [dataLock unlock];
  200203. initialised = true;
  200204. contentLength = [response expectedContentLength];
  200205. }
  200206. - (void) connection: (NSURLConnection*) connection didFailWithError: (NSError*) error
  200207. {
  200208. DBG (nsStringToJuce ([error description]));
  200209. hasFailed = true;
  200210. initialised = true;
  200211. runLoopThread->signalThreadShouldExit();
  200212. }
  200213. - (void) connection: (NSURLConnection*) connection didReceiveData: (NSData*) newData
  200214. {
  200215. [dataLock lock];
  200216. [data appendData: newData];
  200217. [dataLock unlock];
  200218. initialised = true;
  200219. }
  200220. - (void) connectionDidFinishLoading: (NSURLConnection*) connection
  200221. {
  200222. hasFinished = true;
  200223. initialised = true;
  200224. runLoopThread->signalThreadShouldExit();
  200225. }
  200226. - (BOOL) isOpen
  200227. {
  200228. return connection != 0 && ! hasFailed;
  200229. }
  200230. - (int) readPosition
  200231. {
  200232. return position;
  200233. }
  200234. - (int) read: (char*) dest numBytes: (int) numNeeded
  200235. {
  200236. int numDone = 0;
  200237. while (numNeeded > 0)
  200238. {
  200239. int available = jmin (numNeeded, (int) [data length]);
  200240. if (available > 0)
  200241. {
  200242. [dataLock lock];
  200243. [data getBytes: dest length: available];
  200244. [data replaceBytesInRange: NSMakeRange (0, available) withBytes: nil length: 0];
  200245. [dataLock unlock];
  200246. numDone += available;
  200247. numNeeded -= available;
  200248. dest += available;
  200249. }
  200250. else
  200251. {
  200252. if (hasFailed || hasFinished)
  200253. break;
  200254. Thread::sleep (1);
  200255. }
  200256. }
  200257. position += numDone;
  200258. return numDone;
  200259. }
  200260. - (void) stop
  200261. {
  200262. [connection cancel];
  200263. runLoopThread->stopThread (10000);
  200264. }
  200265. @end
  200266. BEGIN_JUCE_NAMESPACE
  200267. bool juce_isOnLine()
  200268. {
  200269. return true;
  200270. }
  200271. void* juce_openInternetFile (const String& url,
  200272. const String& headers,
  200273. const MemoryBlock& postData,
  200274. const bool isPost,
  200275. URL::OpenStreamProgressCallback* callback,
  200276. void* callbackContext,
  200277. int timeOutMs)
  200278. {
  200279. const ScopedAutoReleasePool pool;
  200280. NSMutableURLRequest* req = [NSMutableURLRequest
  200281. requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
  200282. cachePolicy: NSURLRequestUseProtocolCachePolicy
  200283. timeoutInterval: timeOutMs <= 0 ? 60.0 : (timeOutMs / 1000.0)];
  200284. if (req == nil)
  200285. return 0;
  200286. [req setHTTPMethod: isPost ? @"POST" : @"GET"];
  200287. //[req setCachePolicy: NSURLRequestReloadIgnoringLocalAndRemoteCacheData];
  200288. StringArray headerLines;
  200289. headerLines.addLines (headers);
  200290. headerLines.removeEmptyStrings (true);
  200291. for (int i = 0; i < headerLines.size(); ++i)
  200292. {
  200293. const String key (headerLines[i].upToFirstOccurrenceOf (T(":"), false, false).trim());
  200294. const String value (headerLines[i].fromFirstOccurrenceOf (T(":"), false, false).trim());
  200295. if (key.isNotEmpty() && value.isNotEmpty())
  200296. [req addValue: juceStringToNS (value) forHTTPHeaderField: juceStringToNS (key)];
  200297. }
  200298. if (isPost && postData.getSize() > 0)
  200299. {
  200300. [req setHTTPBody: [NSData dataWithBytes: postData.getData()
  200301. length: postData.getSize()]];
  200302. }
  200303. JuceURLConnection* const s = [[JuceURLConnection alloc] initWithRequest: req
  200304. withCallback: callback
  200305. withContext: callbackContext];
  200306. if ([s isOpen])
  200307. return s;
  200308. [s release];
  200309. return 0;
  200310. }
  200311. void juce_closeInternetFile (void* handle)
  200312. {
  200313. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200314. if (s != 0)
  200315. {
  200316. const ScopedAutoReleasePool pool;
  200317. [s stop];
  200318. [s release];
  200319. }
  200320. }
  200321. int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead)
  200322. {
  200323. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200324. if (s != 0)
  200325. {
  200326. const ScopedAutoReleasePool pool;
  200327. return [s read: (char*) buffer numBytes: bytesToRead];
  200328. }
  200329. return 0;
  200330. }
  200331. int64 juce_getInternetFileContentLength (void* handle)
  200332. {
  200333. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200334. if (s != 0)
  200335. return s->contentLength;
  200336. return -1;
  200337. }
  200338. int juce_seekInInternetFile (void* handle, int newPosition)
  200339. {
  200340. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200341. if (s != 0)
  200342. return [s readPosition];
  200343. return 0;
  200344. }
  200345. #endif
  200346. /*** End of inlined file: juce_mac_Network.mm ***/
  200347. /*** Start of inlined file: juce_posix_NamedPipe.cpp ***/
  200348. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200349. // compiled on its own).
  200350. #if JUCE_INCLUDED_FILE
  200351. struct NamedPipeInternal
  200352. {
  200353. String pipeInName, pipeOutName;
  200354. int pipeIn, pipeOut;
  200355. bool volatile createdPipe, blocked, stopReadOperation;
  200356. static void signalHandler (int) {}
  200357. };
  200358. void NamedPipe::cancelPendingReads()
  200359. {
  200360. while (internal != 0 && ((NamedPipeInternal*) internal)->blocked)
  200361. {
  200362. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200363. intern->stopReadOperation = true;
  200364. char buffer [1] = { 0 };
  200365. int bytesWritten = (int) ::write (intern->pipeIn, buffer, 1);
  200366. (void) bytesWritten;
  200367. int timeout = 2000;
  200368. while (intern->blocked && --timeout >= 0)
  200369. Thread::sleep (2);
  200370. intern->stopReadOperation = false;
  200371. }
  200372. }
  200373. void NamedPipe::close()
  200374. {
  200375. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200376. if (intern != 0)
  200377. {
  200378. internal = 0;
  200379. if (intern->pipeIn != -1)
  200380. ::close (intern->pipeIn);
  200381. if (intern->pipeOut != -1)
  200382. ::close (intern->pipeOut);
  200383. if (intern->createdPipe)
  200384. {
  200385. unlink (intern->pipeInName.toUTF8());
  200386. unlink (intern->pipeOutName.toUTF8());
  200387. }
  200388. delete intern;
  200389. }
  200390. }
  200391. bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
  200392. {
  200393. close();
  200394. NamedPipeInternal* const intern = new NamedPipeInternal();
  200395. internal = intern;
  200396. intern->createdPipe = createPipe;
  200397. intern->blocked = false;
  200398. intern->stopReadOperation = false;
  200399. signal (SIGPIPE, NamedPipeInternal::signalHandler);
  200400. siginterrupt (SIGPIPE, 1);
  200401. const String pipePath (T("/tmp/") + File::createLegalFileName (pipeName));
  200402. intern->pipeInName = pipePath + T("_in");
  200403. intern->pipeOutName = pipePath + T("_out");
  200404. intern->pipeIn = -1;
  200405. intern->pipeOut = -1;
  200406. if (createPipe)
  200407. {
  200408. if ((mkfifo (intern->pipeInName.toUTF8(), 0666) && errno != EEXIST)
  200409. || (mkfifo (intern->pipeOutName.toUTF8(), 0666) && errno != EEXIST))
  200410. {
  200411. delete intern;
  200412. internal = 0;
  200413. return false;
  200414. }
  200415. }
  200416. return true;
  200417. }
  200418. int NamedPipe::read (void* destBuffer, int maxBytesToRead, int /*timeOutMilliseconds*/)
  200419. {
  200420. int bytesRead = -1;
  200421. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200422. if (intern != 0)
  200423. {
  200424. intern->blocked = true;
  200425. if (intern->pipeIn == -1)
  200426. {
  200427. if (intern->createdPipe)
  200428. intern->pipeIn = ::open (intern->pipeInName.toUTF8(), O_RDWR);
  200429. else
  200430. intern->pipeIn = ::open (intern->pipeOutName.toUTF8(), O_RDWR);
  200431. if (intern->pipeIn == -1)
  200432. {
  200433. intern->blocked = false;
  200434. return -1;
  200435. }
  200436. }
  200437. bytesRead = 0;
  200438. char* p = (char*) destBuffer;
  200439. while (bytesRead < maxBytesToRead)
  200440. {
  200441. const int bytesThisTime = maxBytesToRead - bytesRead;
  200442. const int numRead = (int) ::read (intern->pipeIn, p, bytesThisTime);
  200443. if (numRead <= 0 || intern->stopReadOperation)
  200444. {
  200445. bytesRead = -1;
  200446. break;
  200447. }
  200448. bytesRead += numRead;
  200449. p += bytesRead;
  200450. }
  200451. intern->blocked = false;
  200452. }
  200453. return bytesRead;
  200454. }
  200455. int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
  200456. {
  200457. int bytesWritten = -1;
  200458. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200459. if (intern != 0)
  200460. {
  200461. if (intern->pipeOut == -1)
  200462. {
  200463. if (intern->createdPipe)
  200464. intern->pipeOut = ::open (intern->pipeOutName.toUTF8(), O_WRONLY);
  200465. else
  200466. intern->pipeOut = ::open (intern->pipeInName.toUTF8(), O_WRONLY);
  200467. if (intern->pipeOut == -1)
  200468. {
  200469. return -1;
  200470. }
  200471. }
  200472. const char* p = (const char*) sourceBuffer;
  200473. bytesWritten = 0;
  200474. const uint32 timeOutTime = Time::getMillisecondCounter() + timeOutMilliseconds;
  200475. while (bytesWritten < numBytesToWrite
  200476. && (timeOutMilliseconds < 0 || Time::getMillisecondCounter() < timeOutTime))
  200477. {
  200478. const int bytesThisTime = numBytesToWrite - bytesWritten;
  200479. const int numWritten = (int) ::write (intern->pipeOut, p, bytesThisTime);
  200480. if (numWritten <= 0)
  200481. {
  200482. bytesWritten = -1;
  200483. break;
  200484. }
  200485. bytesWritten += numWritten;
  200486. p += bytesWritten;
  200487. }
  200488. }
  200489. return bytesWritten;
  200490. }
  200491. #endif
  200492. /*** End of inlined file: juce_posix_NamedPipe.cpp ***/
  200493. /*** Start of inlined file: juce_mac_Threads.mm ***/
  200494. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200495. // compiled on its own).
  200496. #if JUCE_INCLUDED_FILE
  200497. void JUCE_API juce_threadEntryPoint (void*);
  200498. void* threadEntryProc (void* userData)
  200499. {
  200500. const ScopedAutoReleasePool pool;
  200501. juce_threadEntryPoint (userData);
  200502. return 0;
  200503. }
  200504. void* juce_createThread (void* userData)
  200505. {
  200506. pthread_t handle = 0;
  200507. if (pthread_create (&handle, 0, threadEntryProc, userData) == 0)
  200508. {
  200509. pthread_detach (handle);
  200510. return (void*) handle;
  200511. }
  200512. return 0;
  200513. }
  200514. void juce_killThread (void* handle)
  200515. {
  200516. if (handle != 0)
  200517. pthread_cancel ((pthread_t) handle);
  200518. }
  200519. void juce_setCurrentThreadName (const String& /*name*/)
  200520. {
  200521. }
  200522. Thread::ThreadID Thread::getCurrentThreadId()
  200523. {
  200524. return (ThreadID) pthread_self();
  200525. }
  200526. bool juce_setThreadPriority (void* handle, int priority)
  200527. {
  200528. if (handle == 0)
  200529. handle = (void*) pthread_self();
  200530. struct sched_param param;
  200531. int policy;
  200532. pthread_getschedparam ((pthread_t) handle, &policy, &param);
  200533. param.sched_priority = jlimit (1, 127, 1 + (priority * 126) / 11);
  200534. return pthread_setschedparam ((pthread_t) handle, policy, &param) == 0;
  200535. }
  200536. void Thread::yield()
  200537. {
  200538. sched_yield();
  200539. }
  200540. void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
  200541. {
  200542. // xxx
  200543. jassertfalse
  200544. }
  200545. bool Process::isForegroundProcess()
  200546. {
  200547. #if JUCE_MAC
  200548. return [NSApp isActive];
  200549. #else
  200550. return true; // xxx change this if more than one app is ever possible on the iPhone!
  200551. #endif
  200552. }
  200553. void Process::raisePrivilege()
  200554. {
  200555. jassertfalse
  200556. }
  200557. void Process::lowerPrivilege()
  200558. {
  200559. jassertfalse
  200560. }
  200561. void Process::terminate()
  200562. {
  200563. exit (0);
  200564. }
  200565. void Process::setPriority (ProcessPriority p)
  200566. {
  200567. // xxx
  200568. }
  200569. #endif
  200570. /*** End of inlined file: juce_mac_Threads.mm ***/
  200571. /*** Start of inlined file: juce_posix_SharedCode.h ***/
  200572. CriticalSection::CriticalSection() throw()
  200573. {
  200574. pthread_mutexattr_t atts;
  200575. pthread_mutexattr_init (&atts);
  200576. pthread_mutexattr_settype (&atts, PTHREAD_MUTEX_RECURSIVE);
  200577. pthread_mutex_init (&internal, &atts);
  200578. }
  200579. CriticalSection::~CriticalSection() throw()
  200580. {
  200581. pthread_mutex_destroy (&internal);
  200582. }
  200583. void CriticalSection::enter() const throw()
  200584. {
  200585. pthread_mutex_lock (&internal);
  200586. }
  200587. bool CriticalSection::tryEnter() const throw()
  200588. {
  200589. return pthread_mutex_trylock (&internal) == 0;
  200590. }
  200591. void CriticalSection::exit() const throw()
  200592. {
  200593. pthread_mutex_unlock (&internal);
  200594. }
  200595. struct EventStruct
  200596. {
  200597. pthread_cond_t condition;
  200598. pthread_mutex_t mutex;
  200599. bool triggered;
  200600. };
  200601. WaitableEvent::WaitableEvent() throw()
  200602. {
  200603. EventStruct* const es = new EventStruct();
  200604. es->triggered = false;
  200605. pthread_cond_init (&es->condition, 0);
  200606. pthread_mutex_init (&es->mutex, 0);
  200607. internal = es;
  200608. }
  200609. WaitableEvent::~WaitableEvent() throw()
  200610. {
  200611. EventStruct* const es = (EventStruct*) internal;
  200612. pthread_cond_destroy (&es->condition);
  200613. pthread_mutex_destroy (&es->mutex);
  200614. delete es;
  200615. }
  200616. bool WaitableEvent::wait (const int timeOutMillisecs) const throw()
  200617. {
  200618. EventStruct* const es = (EventStruct*) internal;
  200619. pthread_mutex_lock (&es->mutex);
  200620. if (timeOutMillisecs < 0)
  200621. {
  200622. while (! es->triggered)
  200623. pthread_cond_wait (&es->condition, &es->mutex);
  200624. }
  200625. else
  200626. {
  200627. while (! es->triggered)
  200628. {
  200629. struct timeval t;
  200630. gettimeofday (&t, 0);
  200631. struct timespec time;
  200632. time.tv_sec = t.tv_sec + (timeOutMillisecs / 1000);
  200633. time.tv_nsec = (t.tv_usec + ((timeOutMillisecs % 1000) * 1000)) * 1000;
  200634. if (time.tv_nsec >= 1000000000)
  200635. {
  200636. time.tv_nsec -= 1000000000;
  200637. time.tv_sec++;
  200638. }
  200639. if (pthread_cond_timedwait (&es->condition, &es->mutex, &time) == ETIMEDOUT)
  200640. {
  200641. pthread_mutex_unlock (&es->mutex);
  200642. return false;
  200643. }
  200644. }
  200645. }
  200646. es->triggered = false;
  200647. pthread_mutex_unlock (&es->mutex);
  200648. return true;
  200649. }
  200650. void WaitableEvent::signal() const throw()
  200651. {
  200652. EventStruct* const es = (EventStruct*) internal;
  200653. pthread_mutex_lock (&es->mutex);
  200654. es->triggered = true;
  200655. pthread_cond_broadcast (&es->condition);
  200656. pthread_mutex_unlock (&es->mutex);
  200657. }
  200658. void WaitableEvent::reset() const throw()
  200659. {
  200660. EventStruct* const es = (EventStruct*) internal;
  200661. pthread_mutex_lock (&es->mutex);
  200662. es->triggered = false;
  200663. pthread_mutex_unlock (&es->mutex);
  200664. }
  200665. void JUCE_CALLTYPE Thread::sleep (int millisecs)
  200666. {
  200667. struct timespec time;
  200668. time.tv_sec = millisecs / 1000;
  200669. time.tv_nsec = (millisecs % 1000) * 1000000;
  200670. nanosleep (&time, 0);
  200671. }
  200672. const tchar File::separator = T('/');
  200673. const tchar* File::separatorString = T("/");
  200674. const File File::getCurrentWorkingDirectory()
  200675. {
  200676. HeapBlock<char> heapBuffer;
  200677. char localBuffer [1024];
  200678. char* cwd = getcwd (localBuffer, sizeof (localBuffer) - 1);
  200679. int bufferSize = 4096;
  200680. while (cwd == 0 && errno == ERANGE)
  200681. {
  200682. heapBuffer.malloc (bufferSize);
  200683. cwd = getcwd (heapBuffer, bufferSize - 1);
  200684. bufferSize += 1024;
  200685. }
  200686. return File (String::fromUTF8 (cwd));
  200687. }
  200688. bool File::setAsCurrentWorkingDirectory() const
  200689. {
  200690. return chdir (getFullPathName().toUTF8()) == 0;
  200691. }
  200692. bool juce_copyFile (const String& s, const String& d);
  200693. static bool juce_stat (const String& fileName, struct stat& info)
  200694. {
  200695. return fileName.isNotEmpty()
  200696. && (stat (fileName.toUTF8(), &info) == 0);
  200697. }
  200698. bool juce_isDirectory (const String& fileName)
  200699. {
  200700. struct stat info;
  200701. return fileName.isEmpty()
  200702. || (juce_stat (fileName, info)
  200703. && ((info.st_mode & S_IFDIR) != 0));
  200704. }
  200705. bool juce_fileExists (const String& fileName, const bool dontCountDirectories)
  200706. {
  200707. if (fileName.isEmpty())
  200708. return false;
  200709. const char* const fileNameUTF8 = fileName.toUTF8();
  200710. bool exists = access (fileNameUTF8, F_OK) == 0;
  200711. if (exists && dontCountDirectories)
  200712. {
  200713. struct stat info;
  200714. const int res = stat (fileNameUTF8, &info);
  200715. if (res == 0 && (info.st_mode & S_IFDIR) != 0)
  200716. exists = false;
  200717. }
  200718. return exists;
  200719. }
  200720. int64 juce_getFileSize (const String& fileName)
  200721. {
  200722. struct stat info;
  200723. return juce_stat (fileName, info) ? info.st_size : 0;
  200724. }
  200725. bool juce_canWriteToFile (const String& fileName)
  200726. {
  200727. return access (fileName.toUTF8(), W_OK) == 0;
  200728. }
  200729. bool juce_deleteFile (const String& fileName)
  200730. {
  200731. if (juce_isDirectory (fileName))
  200732. return rmdir ((const char*) fileName.toUTF8()) == 0;
  200733. else
  200734. return remove ((const char*) fileName.toUTF8()) == 0;
  200735. }
  200736. bool juce_moveFile (const String& source, const String& dest)
  200737. {
  200738. if (rename (source.toUTF8(), dest.toUTF8()) == 0)
  200739. return true;
  200740. if (juce_canWriteToFile (source)
  200741. && juce_copyFile (source, dest))
  200742. {
  200743. if (juce_deleteFile (source))
  200744. return true;
  200745. juce_deleteFile (dest);
  200746. }
  200747. return false;
  200748. }
  200749. void juce_createDirectory (const String& fileName)
  200750. {
  200751. mkdir (fileName.toUTF8(), 0777);
  200752. }
  200753. void* juce_fileOpen (const String& fileName, bool forWriting)
  200754. {
  200755. int flags = O_RDONLY;
  200756. if (forWriting)
  200757. {
  200758. if (juce_fileExists (fileName, false))
  200759. {
  200760. const int f = open ((const char*) fileName.toUTF8(), O_RDWR, 00644);
  200761. if (f != -1)
  200762. lseek (f, 0, SEEK_END);
  200763. return (void*) f;
  200764. }
  200765. else
  200766. {
  200767. flags = O_RDWR + O_CREAT;
  200768. }
  200769. }
  200770. return (void*) open ((const char*) fileName.toUTF8(), flags, 00644);
  200771. }
  200772. void juce_fileClose (void* handle)
  200773. {
  200774. if (handle != 0)
  200775. close ((int) (pointer_sized_int) handle);
  200776. }
  200777. int juce_fileRead (void* handle, void* buffer, int size)
  200778. {
  200779. if (handle != 0)
  200780. return (int) read ((int) (pointer_sized_int) handle, buffer, size);
  200781. return 0;
  200782. }
  200783. int juce_fileWrite (void* handle, const void* buffer, int size)
  200784. {
  200785. if (handle != 0)
  200786. return (int) write ((int) (pointer_sized_int) handle, buffer, size);
  200787. return 0;
  200788. }
  200789. int64 juce_fileSetPosition (void* handle, int64 pos)
  200790. {
  200791. if (handle != 0 && lseek ((int) (pointer_sized_int) handle, pos, SEEK_SET) == pos)
  200792. return pos;
  200793. return -1;
  200794. }
  200795. int64 juce_fileGetPosition (void* handle)
  200796. {
  200797. if (handle != 0)
  200798. return lseek ((int) (pointer_sized_int) handle, 0, SEEK_CUR);
  200799. else
  200800. return -1;
  200801. }
  200802. void juce_fileFlush (void* handle)
  200803. {
  200804. if (handle != 0)
  200805. fsync ((int) (pointer_sized_int) handle);
  200806. }
  200807. const File juce_getExecutableFile()
  200808. {
  200809. Dl_info exeInfo;
  200810. dladdr ((const void*) juce_getExecutableFile, &exeInfo);
  200811. return File (String::fromUTF8 (exeInfo.dli_fname));
  200812. }
  200813. // if this file doesn't exist, find a parent of it that does..
  200814. static bool doStatFS (const File* file, struct statfs& result)
  200815. {
  200816. File f (*file);
  200817. for (int i = 5; --i >= 0;)
  200818. {
  200819. if (f.exists())
  200820. break;
  200821. f = f.getParentDirectory();
  200822. }
  200823. return statfs (f.getFullPathName().toUTF8(), &result) == 0;
  200824. }
  200825. int64 File::getBytesFreeOnVolume() const
  200826. {
  200827. struct statfs buf;
  200828. if (doStatFS (this, buf))
  200829. return (int64) buf.f_bsize * (int64) buf.f_bavail; // Note: this returns space available to non-super user
  200830. return 0;
  200831. }
  200832. int64 File::getVolumeTotalSize() const
  200833. {
  200834. struct statfs buf;
  200835. if (doStatFS (this, buf))
  200836. return (int64) buf.f_bsize * (int64) buf.f_blocks;
  200837. return 0;
  200838. }
  200839. const String juce_getVolumeLabel (const String& filenameOnVolume,
  200840. int& volumeSerialNumber)
  200841. {
  200842. volumeSerialNumber = 0;
  200843. #if JUCE_MAC
  200844. struct VolAttrBuf
  200845. {
  200846. u_int32_t length;
  200847. attrreference_t mountPointRef;
  200848. char mountPointSpace [MAXPATHLEN];
  200849. } attrBuf;
  200850. struct attrlist attrList;
  200851. zerostruct (attrList);
  200852. attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
  200853. attrList.volattr = ATTR_VOL_INFO | ATTR_VOL_NAME;
  200854. File f (filenameOnVolume);
  200855. for (;;)
  200856. {
  200857. if (getattrlist ((const char*) f.getFullPathName().toUTF8(),
  200858. &attrList, &attrBuf, sizeof(attrBuf), 0) == 0)
  200859. {
  200860. return String::fromUTF8 (((const char*) &attrBuf.mountPointRef) + attrBuf.mountPointRef.attr_dataoffset,
  200861. (int) attrBuf.mountPointRef.attr_length);
  200862. }
  200863. const File parent (f.getParentDirectory());
  200864. if (f == parent)
  200865. break;
  200866. f = parent;
  200867. }
  200868. #endif
  200869. return String::empty;
  200870. }
  200871. void juce_runSystemCommand (const String& command)
  200872. {
  200873. int result = system ((const char*) command.toUTF8());
  200874. (void) result;
  200875. }
  200876. const String juce_getOutputFromCommand (const String& command)
  200877. {
  200878. // slight bodge here, as we just pipe the output into a temp file and read it...
  200879. const File tempFile (File::getSpecialLocation (File::tempDirectory)
  200880. .getNonexistentChildFile (String::toHexString (Random::getSystemRandom().nextInt()), ".tmp", false));
  200881. juce_runSystemCommand (command + " > " + tempFile.getFullPathName());
  200882. String result (tempFile.loadFileAsString());
  200883. tempFile.deleteFile();
  200884. return result;
  200885. }
  200886. InterProcessLock::InterProcessLock (const String& name_)
  200887. : internal (0),
  200888. name (name_),
  200889. reentrancyLevel (0)
  200890. {
  200891. #if JUCE_MAC
  200892. // (don't use getSpecialLocation() to avoid the temp folder being different for each app)
  200893. const File temp (File (T("~/Library/Caches/Juce")).getChildFile (name));
  200894. #else
  200895. const File temp (File::getSpecialLocation (File::tempDirectory).getChildFile (name));
  200896. #endif
  200897. temp.create();
  200898. internal = open (temp.getFullPathName().toUTF8(), O_RDWR);
  200899. }
  200900. InterProcessLock::~InterProcessLock()
  200901. {
  200902. while (reentrancyLevel > 0)
  200903. this->exit();
  200904. close (internal);
  200905. }
  200906. bool InterProcessLock::enter (const int timeOutMillisecs)
  200907. {
  200908. if (internal == 0)
  200909. return false;
  200910. if (reentrancyLevel != 0)
  200911. return true;
  200912. const int64 endTime = Time::currentTimeMillis() + timeOutMillisecs;
  200913. struct flock fl;
  200914. zerostruct (fl);
  200915. fl.l_whence = SEEK_SET;
  200916. fl.l_type = F_WRLCK;
  200917. for (;;)
  200918. {
  200919. const int result = fcntl (internal, F_SETLK, &fl);
  200920. if (result >= 0)
  200921. {
  200922. ++reentrancyLevel;
  200923. return true;
  200924. }
  200925. if (errno != EINTR)
  200926. {
  200927. if (timeOutMillisecs == 0
  200928. || (timeOutMillisecs > 0 && Time::currentTimeMillis() >= endTime))
  200929. break;
  200930. Thread::sleep (10);
  200931. }
  200932. }
  200933. return false;
  200934. }
  200935. void InterProcessLock::exit()
  200936. {
  200937. if (reentrancyLevel > 0 && internal != 0)
  200938. {
  200939. --reentrancyLevel;
  200940. struct flock fl;
  200941. zerostruct (fl);
  200942. fl.l_whence = SEEK_SET;
  200943. fl.l_type = F_UNLCK;
  200944. for (;;)
  200945. {
  200946. const int result = fcntl (internal, F_SETLKW, &fl);
  200947. if (result >= 0 || errno != EINTR)
  200948. break;
  200949. }
  200950. }
  200951. }
  200952. /*** End of inlined file: juce_posix_SharedCode.h ***/
  200953. /*** Start of inlined file: juce_mac_Files.mm ***/
  200954. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200955. // compiled on its own).
  200956. #if JUCE_INCLUDED_FILE
  200957. void juce_getFileTimes (const String& fileName,
  200958. int64& modificationTime,
  200959. int64& accessTime,
  200960. int64& creationTime)
  200961. {
  200962. modificationTime = 0;
  200963. accessTime = 0;
  200964. creationTime = 0;
  200965. struct stat info;
  200966. const int res = stat (fileName.toUTF8(), &info);
  200967. if (res == 0)
  200968. {
  200969. modificationTime = (int64) info.st_mtime * 1000;
  200970. accessTime = (int64) info.st_atime * 1000;
  200971. creationTime = (int64) info.st_ctime * 1000;
  200972. }
  200973. }
  200974. bool juce_setFileTimes (const String& fileName,
  200975. int64 modificationTime,
  200976. int64 accessTime,
  200977. int64 creationTime)
  200978. {
  200979. struct utimbuf times;
  200980. times.actime = (time_t) (accessTime / 1000);
  200981. times.modtime = (time_t) (modificationTime / 1000);
  200982. return utime (fileName.toUTF8(), &times) == 0;
  200983. }
  200984. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly)
  200985. {
  200986. struct stat info;
  200987. const int res = stat (fileName.toUTF8(), &info);
  200988. if (res != 0)
  200989. return false;
  200990. info.st_mode &= 0777; // Just permissions
  200991. if (isReadOnly)
  200992. info.st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
  200993. else
  200994. // Give everybody write permission?
  200995. info.st_mode |= S_IWUSR | S_IWGRP | S_IWOTH;
  200996. return chmod (fileName.toUTF8(), info.st_mode) == 0;
  200997. }
  200998. bool juce_copyFile (const String& src, const String& dst)
  200999. {
  201000. const ScopedAutoReleasePool pool;
  201001. NSFileManager* fm = [NSFileManager defaultManager];
  201002. return [fm fileExistsAtPath: juceStringToNS (src)]
  201003. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  201004. && [fm copyItemAtPath: juceStringToNS (src)
  201005. toPath: juceStringToNS (dst)
  201006. error: nil];
  201007. #else
  201008. && [fm copyPath: juceStringToNS (src)
  201009. toPath: juceStringToNS (dst)
  201010. handler: nil];
  201011. #endif
  201012. }
  201013. const StringArray juce_getFileSystemRoots()
  201014. {
  201015. StringArray s;
  201016. s.add (T("/"));
  201017. return s;
  201018. }
  201019. static bool isFileOnDriveType (const File* const f, const char** types)
  201020. {
  201021. struct statfs buf;
  201022. if (doStatFS (f, buf))
  201023. {
  201024. const String type (buf.f_fstypename);
  201025. while (*types != 0)
  201026. if (type.equalsIgnoreCase (*types++))
  201027. return true;
  201028. }
  201029. return false;
  201030. }
  201031. bool File::isOnCDRomDrive() const
  201032. {
  201033. static const char* const cdTypes[] = { "cd9660", "cdfs", "cddafs", "udf", 0 };
  201034. return isFileOnDriveType (this, (const char**) cdTypes);
  201035. }
  201036. bool File::isOnHardDisk() const
  201037. {
  201038. static const char* const nonHDTypes[] = { "nfs", "smbfs", "ramfs", 0 };
  201039. return ! (isOnCDRomDrive() || isFileOnDriveType (this, (const char**) nonHDTypes));
  201040. }
  201041. bool File::isOnRemovableDrive() const
  201042. {
  201043. #if JUCE_IPHONE
  201044. return false; // xxx is this possible?
  201045. #else
  201046. const ScopedAutoReleasePool pool;
  201047. BOOL removable = false;
  201048. [[NSWorkspace sharedWorkspace]
  201049. getFileSystemInfoForPath: juceStringToNS (getFullPathName())
  201050. isRemovable: &removable
  201051. isWritable: nil
  201052. isUnmountable: nil
  201053. description: nil
  201054. type: nil];
  201055. return removable;
  201056. #endif
  201057. }
  201058. static bool juce_isHiddenFile (const String& path)
  201059. {
  201060. #if JUCE_IPHONE
  201061. return File (path).getFileName().startsWithChar (T('.'));
  201062. #else
  201063. FSRef ref;
  201064. if (! PlatformUtilities::makeFSRefFromPath (&ref, path))
  201065. return false;
  201066. FSCatalogInfo info;
  201067. FSGetCatalogInfo (&ref, kFSCatInfoNodeFlags | kFSCatInfoFinderInfo, &info, 0, 0, 0);
  201068. if ((info.nodeFlags & kFSNodeIsDirectoryBit) != 0)
  201069. return (((FolderInfo*) &info.finderInfo)->finderFlags & kIsInvisible) != 0;
  201070. return (((FileInfo*) &info.finderInfo)->finderFlags & kIsInvisible) != 0;
  201071. #endif
  201072. }
  201073. bool File::isHidden() const
  201074. {
  201075. return juce_isHiddenFile (getFullPathName());
  201076. }
  201077. const char* juce_Argv0 = 0; // referenced from juce_Application.cpp
  201078. const File File::getSpecialLocation (const SpecialLocationType type)
  201079. {
  201080. const ScopedAutoReleasePool pool;
  201081. String resultPath;
  201082. switch (type)
  201083. {
  201084. case userHomeDirectory:
  201085. resultPath = nsStringToJuce (NSHomeDirectory());
  201086. break;
  201087. case userDocumentsDirectory:
  201088. resultPath = "~/Documents";
  201089. break;
  201090. case userDesktopDirectory:
  201091. resultPath = "~/Desktop";
  201092. break;
  201093. case userApplicationDataDirectory:
  201094. resultPath = "~/Library";
  201095. break;
  201096. case commonApplicationDataDirectory:
  201097. resultPath = "/Library";
  201098. break;
  201099. case globalApplicationsDirectory:
  201100. resultPath = "/Applications";
  201101. break;
  201102. case userMusicDirectory:
  201103. resultPath = "~/Music";
  201104. break;
  201105. case userMoviesDirectory:
  201106. resultPath = "~/Movies";
  201107. break;
  201108. case tempDirectory:
  201109. {
  201110. File tmp (T("~/Library/Caches/") + juce_getExecutableFile().getFileNameWithoutExtension());
  201111. tmp.createDirectory();
  201112. return tmp.getFullPathName();
  201113. }
  201114. case invokedExecutableFile:
  201115. if (juce_Argv0 != 0)
  201116. return File (String::fromUTF8 (juce_Argv0));
  201117. // deliberate fall-through...
  201118. case currentExecutableFile:
  201119. return juce_getExecutableFile();
  201120. case currentApplicationFile:
  201121. {
  201122. const File exe (juce_getExecutableFile());
  201123. const File parent (exe.getParentDirectory());
  201124. return parent.getFullPathName().endsWithIgnoreCase (T("Contents/MacOS"))
  201125. ? parent.getParentDirectory().getParentDirectory()
  201126. : exe;
  201127. }
  201128. default:
  201129. jassertfalse // unknown type?
  201130. break;
  201131. }
  201132. if (resultPath.isNotEmpty())
  201133. return File (PlatformUtilities::convertToPrecomposedUnicode (resultPath));
  201134. return File::nonexistent;
  201135. }
  201136. const String File::getVersion() const
  201137. {
  201138. const ScopedAutoReleasePool pool;
  201139. String result;
  201140. NSBundle* bundle = [NSBundle bundleWithPath: juceStringToNS (getFullPathName())];
  201141. if (bundle != 0)
  201142. {
  201143. NSDictionary* info = [bundle infoDictionary];
  201144. if (info != 0)
  201145. {
  201146. NSString* name = [info valueForKey: @"CFBundleShortVersionString"];
  201147. if (name != nil)
  201148. result = nsStringToJuce (name);
  201149. }
  201150. }
  201151. return result;
  201152. }
  201153. const File File::getLinkedTarget() const
  201154. {
  201155. #if JUCE_IPHONE || (defined (MAC_OS_X_VERSION_10_5) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
  201156. NSString* dest = [[NSFileManager defaultManager] destinationOfSymbolicLinkAtPath: juceStringToNS (getFullPathName()) error: nil];
  201157. #else
  201158. NSString* dest = [[NSFileManager defaultManager] pathContentOfSymbolicLinkAtPath: juceStringToNS (getFullPathName())];
  201159. #endif
  201160. if (dest != nil)
  201161. return File (nsStringToJuce (dest));
  201162. return *this;
  201163. }
  201164. bool File::moveToTrash() const
  201165. {
  201166. if (! exists())
  201167. return true;
  201168. #if JUCE_IPHONE
  201169. return deleteFile(); //xxx is there a trashcan on the iPhone?
  201170. #else
  201171. const ScopedAutoReleasePool pool;
  201172. NSString* p = juceStringToNS (getFullPathName());
  201173. return [[NSWorkspace sharedWorkspace]
  201174. performFileOperation: NSWorkspaceRecycleOperation
  201175. source: [p stringByDeletingLastPathComponent]
  201176. destination: @""
  201177. files: [NSArray arrayWithObject: [p lastPathComponent]]
  201178. tag: nil ];
  201179. #endif
  201180. }
  201181. struct FindFileStruct
  201182. {
  201183. NSDirectoryEnumerator* enumerator;
  201184. String parentDir, wildCard;
  201185. };
  201186. bool juce_findFileNext (void* handle, String& resultFile,
  201187. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime, Time* creationTime, bool* isReadOnly)
  201188. {
  201189. ScopedAutoReleasePool pool;
  201190. FindFileStruct* ff = (FindFileStruct*) handle;
  201191. NSString* file;
  201192. const char* const wildcardUTF8 = ff->wildCard.toUTF8();
  201193. for (;;)
  201194. {
  201195. if (ff == 0 || (file = [ff->enumerator nextObject]) == 0)
  201196. return false;
  201197. [ff->enumerator skipDescendents];
  201198. resultFile = nsStringToJuce (file);
  201199. if (fnmatch (wildcardUTF8, resultFile.toUTF8(), FNM_CASEFOLD) != 0)
  201200. continue;
  201201. const String path (ff->parentDir + resultFile);
  201202. if (isDir != 0 || fileSize != 0)
  201203. {
  201204. struct stat info;
  201205. const bool statOk = juce_stat (path, info);
  201206. if (isDir != 0)
  201207. *isDir = statOk && ((info.st_mode & S_IFDIR) != 0);
  201208. if (isHidden != 0)
  201209. *isHidden = juce_isHiddenFile (path);
  201210. if (fileSize != 0)
  201211. *fileSize = statOk ? info.st_size : 0;
  201212. }
  201213. if (modTime != 0 || creationTime != 0)
  201214. {
  201215. int64 m, a, c;
  201216. juce_getFileTimes (path, m, a, c);
  201217. if (modTime != 0)
  201218. *modTime = m;
  201219. if (creationTime != 0)
  201220. *creationTime = c;
  201221. }
  201222. if (isReadOnly != 0)
  201223. *isReadOnly = ! juce_canWriteToFile (path);
  201224. return true;
  201225. }
  201226. }
  201227. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  201228. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime,
  201229. Time* creationTime, bool* isReadOnly)
  201230. {
  201231. ScopedAutoReleasePool pool;
  201232. NSDirectoryEnumerator* e = [[NSFileManager defaultManager] enumeratorAtPath: juceStringToNS (directory)];
  201233. if (e != 0)
  201234. {
  201235. ScopedPointer <FindFileStruct> ff (new FindFileStruct());
  201236. ff->enumerator = [e retain];
  201237. ff->parentDir = directory;
  201238. ff->wildCard = wildCard;
  201239. if (! ff->parentDir.endsWithChar (File::separator))
  201240. ff->parentDir += File::separator;
  201241. if (juce_findFileNext (ff, firstResultFile, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly))
  201242. return ff.release();
  201243. [e release];
  201244. }
  201245. return 0;
  201246. }
  201247. void juce_findFileClose (void* handle)
  201248. {
  201249. ScopedAutoReleasePool pool;
  201250. ScopedPointer <FindFileStruct> ff ((FindFileStruct*) handle);
  201251. [ff->enumerator release];
  201252. }
  201253. bool juce_launchExecutable (const String& pathAndArguments)
  201254. {
  201255. const char* const argv[4] = { "/bin/sh", "-c", pathAndArguments.toUTF8(), 0 };
  201256. const int cpid = fork();
  201257. if (cpid == 0)
  201258. {
  201259. // Child process
  201260. if (execve (argv[0], (char**) argv, 0) < 0)
  201261. exit (0);
  201262. }
  201263. else
  201264. {
  201265. if (cpid < 0)
  201266. return false;
  201267. }
  201268. return true;
  201269. }
  201270. bool juce_launchFile (const String& fileName, const String& parameters)
  201271. {
  201272. #if JUCE_IPHONE
  201273. return [[UIApplication sharedApplication] openURL: [NSURL fileURLWithPath: juceStringToNS (fileName)]];
  201274. #else
  201275. const ScopedAutoReleasePool pool;
  201276. if (parameters.isEmpty())
  201277. {
  201278. return [[NSWorkspace sharedWorkspace] openFile: juceStringToNS (fileName)]
  201279. || [[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: juceStringToNS (fileName)]];
  201280. }
  201281. bool ok = false;
  201282. FSRef ref;
  201283. if (PlatformUtilities::makeFSRefFromPath (&ref, fileName))
  201284. {
  201285. if (PlatformUtilities::isBundle (fileName))
  201286. {
  201287. NSMutableArray* urls = [NSMutableArray array];
  201288. StringArray docs;
  201289. docs.addTokens (parameters, true);
  201290. for (int i = 0; i < docs.size(); ++i)
  201291. [urls addObject: juceStringToNS (docs[i])];
  201292. ok = [[NSWorkspace sharedWorkspace] openURLs: urls
  201293. withAppBundleIdentifier: [[NSBundle bundleWithPath: juceStringToNS (fileName)] bundleIdentifier]
  201294. options: 0
  201295. additionalEventParamDescriptor: nil
  201296. launchIdentifiers: nil];
  201297. }
  201298. else
  201299. {
  201300. ok = juce_launchExecutable (T("\"") + fileName + T("\" ") + parameters);
  201301. }
  201302. }
  201303. return ok;
  201304. #endif
  201305. }
  201306. void File::revealToUser() const
  201307. {
  201308. #if ! JUCE_IPHONE
  201309. if (exists())
  201310. [[NSWorkspace sharedWorkspace] selectFile: juceStringToNS (getFullPathName()) inFileViewerRootedAtPath: @""];
  201311. else if (getParentDirectory().exists())
  201312. getParentDirectory().revealToUser();
  201313. #endif
  201314. }
  201315. #if ! JUCE_IPHONE
  201316. bool PlatformUtilities::makeFSRefFromPath (FSRef* destFSRef, const String& path)
  201317. {
  201318. return FSPathMakeRef ((const UInt8*) path.toUTF8(), destFSRef, 0) == noErr;
  201319. }
  201320. const String PlatformUtilities::makePathFromFSRef (FSRef* file)
  201321. {
  201322. char path [2048];
  201323. zerostruct (path);
  201324. if (FSRefMakePath (file, (UInt8*) path, sizeof (path) - 1) == noErr)
  201325. return PlatformUtilities::convertToPrecomposedUnicode (String::fromUTF8 (path));
  201326. return String::empty;
  201327. }
  201328. #endif
  201329. OSType PlatformUtilities::getTypeOfFile (const String& filename)
  201330. {
  201331. const ScopedAutoReleasePool pool;
  201332. #if JUCE_IPHONE || (defined (MAC_OS_X_VERSION_10_5) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
  201333. NSDictionary* fileDict = [[NSFileManager defaultManager] attributesOfItemAtPath: juceStringToNS (filename) error: nil];
  201334. #else
  201335. NSDictionary* fileDict = [[NSFileManager defaultManager] fileAttributesAtPath: juceStringToNS (filename) traverseLink: NO];
  201336. #endif
  201337. //return (OSType) [fileDict objectForKey: NSFileHFSTypeCode];
  201338. return [fileDict fileHFSTypeCode];
  201339. }
  201340. bool PlatformUtilities::isBundle (const String& filename)
  201341. {
  201342. #if JUCE_IPHONE
  201343. return false; // xxx can't find a sensible way to do this without trying to open the bundle..
  201344. #else
  201345. const ScopedAutoReleasePool pool;
  201346. return [[NSWorkspace sharedWorkspace] isFilePackageAtPath: juceStringToNS (filename)];
  201347. #endif
  201348. }
  201349. #endif
  201350. /*** End of inlined file: juce_mac_Files.mm ***/
  201351. #if JUCE_IPHONE
  201352. /*** Start of inlined file: juce_iphone_MiscUtilities.mm ***/
  201353. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201354. // compiled on its own).
  201355. #if JUCE_INCLUDED_FILE
  201356. static JUCEApplication* juce_intialisingApp;
  201357. END_JUCE_NAMESPACE
  201358. @interface JuceAppStartupDelegate : NSObject <UIApplicationDelegate>
  201359. {
  201360. }
  201361. - (void) applicationDidFinishLaunching: (UIApplication*) application;
  201362. - (void) applicationWillResignActive: (UIApplication*) application;
  201363. @end
  201364. @implementation JuceAppStartupDelegate
  201365. - (void) applicationDidFinishLaunching: (UIApplication*) application
  201366. {
  201367. String dummy;
  201368. if (! juce_intialisingApp->initialiseApp (dummy))
  201369. exit (0);
  201370. }
  201371. - (void) applicationWillResignActive: (UIApplication*) application
  201372. {
  201373. JUCEApplication::shutdownAppAndClearUp();
  201374. }
  201375. @end
  201376. BEGIN_JUCE_NAMESPACE
  201377. int juce_IPhoneMain (int argc, const char* argv[], JUCEApplication* app)
  201378. {
  201379. juce_intialisingApp = app;
  201380. return UIApplicationMain (argc, const_cast<char**> (argv), nil, @"JuceAppStartupDelegate");
  201381. }
  201382. ScopedAutoReleasePool::ScopedAutoReleasePool()
  201383. {
  201384. pool = [[NSAutoreleasePool alloc] init];
  201385. }
  201386. ScopedAutoReleasePool::~ScopedAutoReleasePool()
  201387. {
  201388. [((NSAutoreleasePool*) pool) release];
  201389. }
  201390. void PlatformUtilities::beep()
  201391. {
  201392. //xxx
  201393. //AudioServicesPlaySystemSound ();
  201394. }
  201395. void PlatformUtilities::addItemToDock (const File& file)
  201396. {
  201397. }
  201398. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  201399. END_JUCE_NAMESPACE
  201400. @interface JuceAlertBoxDelegate : NSObject
  201401. {
  201402. @public
  201403. bool clickedOk;
  201404. }
  201405. - (void) alertView: (UIAlertView*) alertView clickedButtonAtIndex: (NSInteger) buttonIndex;
  201406. @end
  201407. @implementation JuceAlertBoxDelegate
  201408. - (void) alertView: (UIAlertView*) alertView clickedButtonAtIndex: (NSInteger) buttonIndex
  201409. {
  201410. clickedOk = (buttonIndex == 0);
  201411. alertView.hidden = true;
  201412. }
  201413. @end
  201414. BEGIN_JUCE_NAMESPACE
  201415. // (This function is used directly by other bits of code)
  201416. bool juce_iPhoneShowModalAlert (const String& title,
  201417. const String& bodyText,
  201418. NSString* okButtonText,
  201419. NSString* cancelButtonText)
  201420. {
  201421. const ScopedAutoReleasePool pool;
  201422. JuceAlertBoxDelegate* callback = [[JuceAlertBoxDelegate alloc] init];
  201423. UIAlertView* alert = [[UIAlertView alloc] initWithTitle: juceStringToNS (title)
  201424. message: juceStringToNS (bodyText)
  201425. delegate: callback
  201426. cancelButtonTitle: okButtonText
  201427. otherButtonTitles: cancelButtonText, nil];
  201428. [alert retain];
  201429. [alert show];
  201430. while (! alert.hidden && alert.superview != nil)
  201431. [[NSRunLoop mainRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.01]];
  201432. const bool result = callback->clickedOk;
  201433. [alert release];
  201434. [callback release];
  201435. return result;
  201436. }
  201437. bool AlertWindow::showNativeDialogBox (const String& title,
  201438. const String& bodyText,
  201439. bool isOkCancel)
  201440. {
  201441. return juce_iPhoneShowModalAlert (title, bodyText,
  201442. @"OK",
  201443. isOkCancel ? @"Cancel" : nil);
  201444. }
  201445. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  201446. {
  201447. jassertfalse // no such thing on the iphone!
  201448. return false;
  201449. }
  201450. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  201451. {
  201452. jassertfalse // no such thing on the iphone!
  201453. return false;
  201454. }
  201455. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  201456. {
  201457. [[UIApplication sharedApplication] setIdleTimerDisabled: ! isEnabled];
  201458. }
  201459. bool Desktop::isScreenSaverEnabled() throw()
  201460. {
  201461. return ! [[UIApplication sharedApplication] isIdleTimerDisabled];
  201462. }
  201463. void juce_updateMultiMonitorInfo (Array <Rectangle <int> >& monitorCoords, const bool clipToWorkArea)
  201464. {
  201465. const ScopedAutoReleasePool pool;
  201466. monitorCoords.clear();
  201467. CGRect r = clipToWorkArea ? [[UIScreen mainScreen] applicationFrame]
  201468. : [[UIScreen mainScreen] bounds];
  201469. monitorCoords.add (Rectangle<int> ((int) r.origin.x,
  201470. (int) r.origin.y,
  201471. (int) r.size.width,
  201472. (int) r.size.height));
  201473. }
  201474. #endif
  201475. #endif
  201476. /*** End of inlined file: juce_iphone_MiscUtilities.mm ***/
  201477. #else
  201478. /*** Start of inlined file: juce_mac_MiscUtilities.mm ***/
  201479. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201480. // compiled on its own).
  201481. #if JUCE_INCLUDED_FILE
  201482. ScopedAutoReleasePool::ScopedAutoReleasePool()
  201483. {
  201484. pool = [[NSAutoreleasePool alloc] init];
  201485. }
  201486. ScopedAutoReleasePool::~ScopedAutoReleasePool()
  201487. {
  201488. [((NSAutoreleasePool*) pool) release];
  201489. }
  201490. void PlatformUtilities::beep()
  201491. {
  201492. NSBeep();
  201493. }
  201494. void PlatformUtilities::addItemToDock (const File& file)
  201495. {
  201496. // check that it's not already there...
  201497. if (! juce_getOutputFromCommand ("defaults read com.apple.dock persistent-apps")
  201498. .containsIgnoreCase (file.getFullPathName()))
  201499. {
  201500. 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>"
  201501. + file.getFullPathName() + "</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>\"");
  201502. juce_runSystemCommand ("osascript -e \"tell application \\\"Dock\\\" to quit\"");
  201503. }
  201504. }
  201505. int PlatformUtilities::getOSXMinorVersionNumber()
  201506. {
  201507. SInt32 versionMinor = 0;
  201508. OSErr err = Gestalt (gestaltSystemVersionMinor, &versionMinor);
  201509. (void) err;
  201510. jassert (err == noErr);
  201511. return (int) versionMinor;
  201512. }
  201513. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  201514. bool AlertWindow::showNativeDialogBox (const String& title,
  201515. const String& bodyText,
  201516. bool isOkCancel)
  201517. {
  201518. const ScopedAutoReleasePool pool;
  201519. return NSRunAlertPanel (juceStringToNS (title),
  201520. juceStringToNS (bodyText),
  201521. @"Ok",
  201522. isOkCancel ? @"Cancel" : nil,
  201523. nil) == NSAlertDefaultReturn;
  201524. }
  201525. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  201526. {
  201527. if (files.size() == 0)
  201528. return false;
  201529. MouseInputSource* draggingSource = Desktop::getInstance().getDraggingMouseSource(0);
  201530. if (draggingSource == 0)
  201531. {
  201532. jassertfalse // This method must be called in response to a component's mouseDown or mouseDrag event!
  201533. return false;
  201534. }
  201535. Component* sourceComp = draggingSource->getComponentUnderMouse();
  201536. if (sourceComp == 0)
  201537. {
  201538. jassertfalse // This method must be called in response to a component's mouseDown or mouseDrag event!
  201539. return false;
  201540. }
  201541. const ScopedAutoReleasePool pool;
  201542. NSView* view = (NSView*) sourceComp->getWindowHandle();
  201543. if (view == 0)
  201544. return false;
  201545. NSPasteboard* pboard = [NSPasteboard pasteboardWithName: NSDragPboard];
  201546. [pboard declareTypes: [NSArray arrayWithObject: NSFilenamesPboardType]
  201547. owner: nil];
  201548. NSMutableArray* filesArray = [NSMutableArray arrayWithCapacity: 4];
  201549. for (int i = 0; i < files.size(); ++i)
  201550. [filesArray addObject: juceStringToNS (files[i])];
  201551. [pboard setPropertyList: filesArray
  201552. forType: NSFilenamesPboardType];
  201553. NSPoint dragPosition = [view convertPoint: [[[view window] currentEvent] locationInWindow]
  201554. fromView: nil];
  201555. dragPosition.x -= 16;
  201556. dragPosition.y -= 16;
  201557. [view dragImage: [[NSWorkspace sharedWorkspace] iconForFile: juceStringToNS (files[0])]
  201558. at: dragPosition
  201559. offset: NSMakeSize (0, 0)
  201560. event: [[view window] currentEvent]
  201561. pasteboard: pboard
  201562. source: view
  201563. slideBack: YES];
  201564. return true;
  201565. }
  201566. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  201567. {
  201568. jassertfalse // not implemented!
  201569. return false;
  201570. }
  201571. bool Desktop::canUseSemiTransparentWindows() throw()
  201572. {
  201573. return true;
  201574. }
  201575. const Point<int> Desktop::getMousePosition()
  201576. {
  201577. const ScopedAutoReleasePool pool;
  201578. const NSPoint p ([NSEvent mouseLocation]);
  201579. return Point<int> (roundToInt (p.x), roundToInt ([[[NSScreen screens] objectAtIndex: 0] frame].size.height - p.y));
  201580. }
  201581. void Desktop::setMousePosition (const Point<int>& newPosition)
  201582. {
  201583. // this rubbish needs to be done around the warp call, to avoid causing a
  201584. // bizarre glitch..
  201585. CGAssociateMouseAndMouseCursorPosition (false);
  201586. CGWarpMouseCursorPosition (CGPointMake (newPosition.getX(), newPosition.getY()));
  201587. CGAssociateMouseAndMouseCursorPosition (true);
  201588. }
  201589. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  201590. class ScreenSaverDefeater : public Timer,
  201591. public DeletedAtShutdown
  201592. {
  201593. public:
  201594. ScreenSaverDefeater() throw()
  201595. {
  201596. startTimer (10000);
  201597. timerCallback();
  201598. }
  201599. ~ScreenSaverDefeater() {}
  201600. void timerCallback()
  201601. {
  201602. if (Process::isForegroundProcess())
  201603. UpdateSystemActivity (UsrActivity);
  201604. }
  201605. };
  201606. static ScreenSaverDefeater* screenSaverDefeater = 0;
  201607. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  201608. {
  201609. if (isEnabled)
  201610. {
  201611. deleteAndZero (screenSaverDefeater);
  201612. }
  201613. else if (screenSaverDefeater == 0)
  201614. {
  201615. screenSaverDefeater = new ScreenSaverDefeater();
  201616. }
  201617. }
  201618. bool Desktop::isScreenSaverEnabled() throw()
  201619. {
  201620. return screenSaverDefeater == 0;
  201621. }
  201622. #else
  201623. static IOPMAssertionID screenSaverDisablerID = 0;
  201624. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  201625. {
  201626. if (isEnabled)
  201627. {
  201628. if (screenSaverDisablerID != 0)
  201629. {
  201630. IOPMAssertionRelease (screenSaverDisablerID);
  201631. screenSaverDisablerID = 0;
  201632. }
  201633. }
  201634. else
  201635. {
  201636. if (screenSaverDisablerID == 0)
  201637. {
  201638. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  201639. IOPMAssertionCreateWithName (kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn,
  201640. CFSTR ("Juce"), &screenSaverDisablerID);
  201641. #else
  201642. IOPMAssertionCreate (kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn,
  201643. &screenSaverDisablerID);
  201644. #endif
  201645. }
  201646. }
  201647. }
  201648. bool Desktop::isScreenSaverEnabled() throw()
  201649. {
  201650. return screenSaverDisablerID == 0;
  201651. }
  201652. #endif
  201653. void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords, const bool clipToWorkArea)
  201654. {
  201655. const ScopedAutoReleasePool pool;
  201656. monitorCoords.clear();
  201657. NSArray* screens = [NSScreen screens];
  201658. const CGFloat mainScreenBottom = [[[NSScreen screens] objectAtIndex: 0] frame].size.height;
  201659. for (unsigned int i = 0; i < [screens count]; ++i)
  201660. {
  201661. NSScreen* s = (NSScreen*) [screens objectAtIndex: i];
  201662. NSRect r = clipToWorkArea ? [s visibleFrame]
  201663. : [s frame];
  201664. monitorCoords.add (Rectangle<int> ((int) r.origin.x,
  201665. (int) (mainScreenBottom - (r.origin.y + r.size.height)),
  201666. (int) r.size.width,
  201667. (int) r.size.height));
  201668. }
  201669. jassert (monitorCoords.size() > 0);
  201670. }
  201671. #endif
  201672. #endif
  201673. /*** End of inlined file: juce_mac_MiscUtilities.mm ***/
  201674. #endif
  201675. /*** Start of inlined file: juce_mac_Debugging.mm ***/
  201676. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201677. // compiled on its own).
  201678. #if JUCE_INCLUDED_FILE
  201679. void Logger::outputDebugString (const String& text) throw()
  201680. {
  201681. std::cerr << text << std::endl;
  201682. }
  201683. bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger()
  201684. {
  201685. static char testResult = 0;
  201686. if (testResult == 0)
  201687. {
  201688. struct kinfo_proc info;
  201689. int m[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid() };
  201690. size_t sz = sizeof (info);
  201691. sysctl (m, 4, &info, &sz, 0, 0);
  201692. testResult = ((info.kp_proc.p_flag & P_TRACED) != 0) ? 1 : -1;
  201693. }
  201694. return testResult > 0;
  201695. }
  201696. bool JUCE_CALLTYPE Process::isRunningUnderDebugger()
  201697. {
  201698. return juce_isRunningUnderDebugger();
  201699. }
  201700. #endif
  201701. /*** End of inlined file: juce_mac_Debugging.mm ***/
  201702. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  201703. #if JUCE_IPHONE
  201704. /*** Start of inlined file: juce_mac_Fonts.mm ***/
  201705. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201706. // compiled on its own).
  201707. #if JUCE_INCLUDED_FILE
  201708. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  201709. #define SUPPORT_10_4_FONTS 1
  201710. #define NEW_CGFONT_FUNCTIONS_UNAVAILABLE (CGFontCreateWithFontName == 0)
  201711. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  201712. #define SUPPORT_ONLY_10_4_FONTS 1
  201713. #endif
  201714. END_JUCE_NAMESPACE
  201715. @interface NSFont (PrivateHack)
  201716. - (NSGlyph) _defaultGlyphForChar: (unichar) theChar;
  201717. @end
  201718. BEGIN_JUCE_NAMESPACE
  201719. #endif
  201720. class MacTypeface : public Typeface
  201721. {
  201722. public:
  201723. MacTypeface (const Font& font)
  201724. : Typeface (font.getTypefaceName())
  201725. {
  201726. const ScopedAutoReleasePool pool;
  201727. renderingTransform = CGAffineTransformIdentity;
  201728. bool needsItalicTransform = false;
  201729. #if JUCE_IPHONE
  201730. NSString* fontName = juceStringToNS (font.getTypefaceName());
  201731. if (font.isItalic() || font.isBold())
  201732. {
  201733. NSArray* familyFonts = [UIFont fontNamesForFamilyName: juceStringToNS (font.getTypefaceName())];
  201734. for (NSString* i in familyFonts)
  201735. {
  201736. const String fn (nsStringToJuce (i));
  201737. const String afterDash (fn.fromFirstOccurrenceOf (T("-"), false, false));
  201738. const bool probablyBold = afterDash.containsIgnoreCase (T("bold")) || fn.endsWithIgnoreCase (T("bold"));
  201739. const bool probablyItalic = afterDash.containsIgnoreCase (T("oblique"))
  201740. || afterDash.containsIgnoreCase (T("italic"))
  201741. || fn.endsWithIgnoreCase (T("oblique"))
  201742. || fn.endsWithIgnoreCase (T("italic"));
  201743. if (probablyBold == font.isBold()
  201744. && probablyItalic == font.isItalic())
  201745. {
  201746. fontName = i;
  201747. needsItalicTransform = false;
  201748. break;
  201749. }
  201750. else if (probablyBold && (! probablyItalic) && probablyBold == font.isBold())
  201751. {
  201752. fontName = i;
  201753. needsItalicTransform = true; // not ideal, so carry on in case we find a better one
  201754. }
  201755. }
  201756. if (needsItalicTransform)
  201757. renderingTransform.c = 0.15f;
  201758. }
  201759. fontRef = CGFontCreateWithFontName ((CFStringRef) fontName);
  201760. const int ascender = abs (CGFontGetAscent (fontRef));
  201761. const float totalHeight = ascender + abs (CGFontGetDescent (fontRef));
  201762. ascent = ascender / totalHeight;
  201763. unitsToHeightScaleFactor = 1.0f / totalHeight;
  201764. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / totalHeight;
  201765. #else
  201766. nsFont = [NSFont fontWithName: juceStringToNS (font.getTypefaceName()) size: 1024];
  201767. if (font.isItalic())
  201768. {
  201769. NSFont* newFont = [[NSFontManager sharedFontManager] convertFont: nsFont
  201770. toHaveTrait: NSItalicFontMask];
  201771. if (newFont == nsFont)
  201772. needsItalicTransform = true; // couldn't find a proper italic version, so fake it with a transform..
  201773. nsFont = newFont;
  201774. }
  201775. if (font.isBold())
  201776. nsFont = [[NSFontManager sharedFontManager] convertFont: nsFont toHaveTrait: NSBoldFontMask];
  201777. [nsFont retain];
  201778. ascent = fabsf ((float) [nsFont ascender]);
  201779. float totalSize = ascent + fabsf ((float) [nsFont descender]);
  201780. ascent /= totalSize;
  201781. pathTransform = AffineTransform::identity.scale (1.0f / totalSize, 1.0f / totalSize);
  201782. if (needsItalicTransform)
  201783. {
  201784. pathTransform = pathTransform.sheared (-0.15f, 0.0f);
  201785. renderingTransform.c = 0.15f;
  201786. }
  201787. #if SUPPORT_ONLY_10_4_FONTS
  201788. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  201789. if (atsFont == 0)
  201790. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  201791. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  201792. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  201793. unitsToHeightScaleFactor = 1.0f / totalHeight;
  201794. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  201795. #else
  201796. #if SUPPORT_10_4_FONTS
  201797. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  201798. {
  201799. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  201800. if (atsFont == 0)
  201801. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  201802. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  201803. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  201804. unitsToHeightScaleFactor = 1.0f / totalHeight;
  201805. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  201806. }
  201807. else
  201808. #endif
  201809. {
  201810. fontRef = CGFontCreateWithFontName ((CFStringRef) [nsFont fontName]);
  201811. const int totalHeight = abs (CGFontGetAscent (fontRef)) + abs (CGFontGetDescent (fontRef));
  201812. unitsToHeightScaleFactor = 1.0f / totalHeight;
  201813. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / (float) totalHeight;
  201814. }
  201815. #endif
  201816. #endif
  201817. }
  201818. ~MacTypeface()
  201819. {
  201820. #if ! JUCE_IPHONE
  201821. [nsFont release];
  201822. #endif
  201823. if (fontRef != 0)
  201824. CGFontRelease (fontRef);
  201825. }
  201826. float getAscent() const
  201827. {
  201828. return ascent;
  201829. }
  201830. float getDescent() const
  201831. {
  201832. return 1.0f - ascent;
  201833. }
  201834. float getStringWidth (const String& text)
  201835. {
  201836. if (fontRef == 0 || text.isEmpty())
  201837. return 0;
  201838. const int length = text.length();
  201839. HeapBlock <CGGlyph> glyphs;
  201840. createGlyphsForString (text, length, glyphs);
  201841. float x = 0;
  201842. #if SUPPORT_ONLY_10_4_FONTS
  201843. HeapBlock <NSSize> advances (length);
  201844. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast <NSGlyph*> (glyphs.getData()) count: length];
  201845. for (int i = 0; i < length; ++i)
  201846. x += advances[i].width;
  201847. #else
  201848. #if SUPPORT_10_4_FONTS
  201849. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  201850. {
  201851. HeapBlock <NSSize> advances (length);
  201852. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast<NSGlyph*> (glyphs.getData()) count: length];
  201853. for (int i = 0; i < length; ++i)
  201854. x += advances[i].width;
  201855. }
  201856. else
  201857. #endif
  201858. {
  201859. HeapBlock <int> advances (length);
  201860. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  201861. for (int i = 0; i < length; ++i)
  201862. x += advances[i];
  201863. }
  201864. #endif
  201865. return x * unitsToHeightScaleFactor;
  201866. }
  201867. void getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array <float>& xOffsets)
  201868. {
  201869. xOffsets.add (0);
  201870. if (fontRef == 0 || text.isEmpty())
  201871. return;
  201872. const int length = text.length();
  201873. HeapBlock <CGGlyph> glyphs;
  201874. createGlyphsForString (text, length, glyphs);
  201875. #if SUPPORT_ONLY_10_4_FONTS
  201876. HeapBlock <NSSize> advances (length);
  201877. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast <NSGlyph*> (glyphs.getData()) count: length];
  201878. int x = 0;
  201879. for (int i = 0; i < length; ++i)
  201880. {
  201881. x += advances[i].width;
  201882. xOffsets.add (x * unitsToHeightScaleFactor);
  201883. resultGlyphs.add (reinterpret_cast <NSGlyph*> (glyphs.getData())[i]);
  201884. }
  201885. #else
  201886. #if SUPPORT_10_4_FONTS
  201887. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  201888. {
  201889. HeapBlock <NSSize> advances (length);
  201890. NSGlyph* const nsGlyphs = reinterpret_cast<NSGlyph*> (glyphs.getData());
  201891. [nsFont getAdvancements: advances forGlyphs: nsGlyphs count: length];
  201892. float x = 0;
  201893. for (int i = 0; i < length; ++i)
  201894. {
  201895. x += advances[i].width;
  201896. xOffsets.add (x * unitsToHeightScaleFactor);
  201897. resultGlyphs.add (nsGlyphs[i]);
  201898. }
  201899. }
  201900. else
  201901. #endif
  201902. {
  201903. HeapBlock <int> advances (length);
  201904. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  201905. {
  201906. int x = 0;
  201907. for (int i = 0; i < length; ++i)
  201908. {
  201909. x += advances [i];
  201910. xOffsets.add (x * unitsToHeightScaleFactor);
  201911. resultGlyphs.add (glyphs[i]);
  201912. }
  201913. }
  201914. }
  201915. #endif
  201916. }
  201917. bool getOutlineForGlyph (int glyphNumber, Path& path)
  201918. {
  201919. #if JUCE_IPHONE
  201920. return false;
  201921. #else
  201922. if (nsFont == 0)
  201923. return false;
  201924. // we might need to apply a transform to the path, so it mustn't have anything else in it
  201925. jassert (path.isEmpty());
  201926. const ScopedAutoReleasePool pool;
  201927. NSBezierPath* bez = [NSBezierPath bezierPath];
  201928. [bez moveToPoint: NSMakePoint (0, 0)];
  201929. [bez appendBezierPathWithGlyph: (NSGlyph) glyphNumber
  201930. inFont: nsFont];
  201931. for (int i = 0; i < [bez elementCount]; ++i)
  201932. {
  201933. NSPoint p[3];
  201934. switch ([bez elementAtIndex: i associatedPoints: p])
  201935. {
  201936. case NSMoveToBezierPathElement:
  201937. path.startNewSubPath ((float) p[0].x, (float) -p[0].y);
  201938. break;
  201939. case NSLineToBezierPathElement:
  201940. path.lineTo ((float) p[0].x, (float) -p[0].y);
  201941. break;
  201942. case NSCurveToBezierPathElement:
  201943. 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);
  201944. break;
  201945. case NSClosePathBezierPathElement:
  201946. path.closeSubPath();
  201947. break;
  201948. default:
  201949. jassertfalse
  201950. break;
  201951. }
  201952. }
  201953. path.applyTransform (pathTransform);
  201954. return true;
  201955. #endif
  201956. }
  201957. juce_UseDebuggingNewOperator
  201958. CGFontRef fontRef;
  201959. float fontHeightToCGSizeFactor;
  201960. CGAffineTransform renderingTransform;
  201961. private:
  201962. float ascent, unitsToHeightScaleFactor;
  201963. #if JUCE_IPHONE
  201964. #else
  201965. NSFont* nsFont;
  201966. AffineTransform pathTransform;
  201967. #endif
  201968. void createGlyphsForString (const juce_wchar* const text, const int length, HeapBlock <CGGlyph>& glyphs)
  201969. {
  201970. #if SUPPORT_10_4_FONTS
  201971. #if ! SUPPORT_ONLY_10_4_FONTS
  201972. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  201973. #endif
  201974. {
  201975. glyphs.malloc (sizeof (NSGlyph) * length, 1);
  201976. NSGlyph* const nsGlyphs = reinterpret_cast<NSGlyph*> (glyphs.getData());
  201977. for (int i = 0; i < length; ++i)
  201978. nsGlyphs[i] = (NSGlyph) [nsFont _defaultGlyphForChar: text[i]];
  201979. return;
  201980. }
  201981. #endif
  201982. #if ! SUPPORT_ONLY_10_4_FONTS
  201983. if (charToGlyphMapper == 0)
  201984. charToGlyphMapper = new CharToGlyphMapper (fontRef);
  201985. glyphs.malloc (length);
  201986. for (int i = 0; i < length; ++i)
  201987. glyphs[i] = (CGGlyph) charToGlyphMapper->getGlyphForCharacter (text[i]);
  201988. #endif
  201989. }
  201990. #if ! SUPPORT_ONLY_10_4_FONTS
  201991. // Reads a CGFontRef's character map table to convert unicode into glyph numbers
  201992. class CharToGlyphMapper
  201993. {
  201994. public:
  201995. CharToGlyphMapper (CGFontRef fontRef)
  201996. : segCount (0), endCode (0), startCode (0), idDelta (0),
  201997. idRangeOffset (0), glyphIndexes (0)
  201998. {
  201999. CFDataRef cmapTable = CGFontCopyTableForTag (fontRef, 'cmap');
  202000. if (cmapTable != 0)
  202001. {
  202002. const int numSubtables = getValue16 (cmapTable, 2);
  202003. for (int i = 0; i < numSubtables; ++i)
  202004. {
  202005. if (getValue16 (cmapTable, i * 8 + 4) == 0) // check for platform ID of 0
  202006. {
  202007. const int offset = getValue32 (cmapTable, i * 8 + 8);
  202008. if (getValue16 (cmapTable, offset) == 4) // check that it's format 4..
  202009. {
  202010. const int length = getValue16 (cmapTable, offset + 2);
  202011. const int segCountX2 = getValue16 (cmapTable, offset + 6);
  202012. segCount = segCountX2 / 2;
  202013. const int endCodeOffset = offset + 14;
  202014. const int startCodeOffset = endCodeOffset + 2 + segCountX2;
  202015. const int idDeltaOffset = startCodeOffset + segCountX2;
  202016. const int idRangeOffsetOffset = idDeltaOffset + segCountX2;
  202017. const int glyphIndexesOffset = idRangeOffsetOffset + segCountX2;
  202018. endCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + endCodeOffset, segCountX2);
  202019. startCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + startCodeOffset, segCountX2);
  202020. idDelta = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idDeltaOffset, segCountX2);
  202021. idRangeOffset = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idRangeOffsetOffset, segCountX2);
  202022. glyphIndexes = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + glyphIndexesOffset, offset + length - glyphIndexesOffset);
  202023. }
  202024. break;
  202025. }
  202026. }
  202027. CFRelease (cmapTable);
  202028. }
  202029. }
  202030. ~CharToGlyphMapper()
  202031. {
  202032. if (endCode != 0)
  202033. {
  202034. CFRelease (endCode);
  202035. CFRelease (startCode);
  202036. CFRelease (idDelta);
  202037. CFRelease (idRangeOffset);
  202038. CFRelease (glyphIndexes);
  202039. }
  202040. }
  202041. int getGlyphForCharacter (const juce_wchar c) const
  202042. {
  202043. for (int i = 0; i < segCount; ++i)
  202044. {
  202045. if (getValue16 (endCode, i * 2) >= c)
  202046. {
  202047. const int start = getValue16 (startCode, i * 2);
  202048. if (start > c)
  202049. break;
  202050. const int delta = getValue16 (idDelta, i * 2);
  202051. const int rangeOffset = getValue16 (idRangeOffset, i * 2);
  202052. if (rangeOffset == 0)
  202053. return delta + c;
  202054. else
  202055. return getValue16 (glyphIndexes, 2 * ((rangeOffset / 2) + (c - start) - (segCount - i)));
  202056. }
  202057. }
  202058. // If we failed to find it "properly", this dodgy fall-back seems to do the trick for most fonts!
  202059. return jmax (-1, c - 29);
  202060. }
  202061. private:
  202062. int segCount;
  202063. CFDataRef endCode, startCode, idDelta, idRangeOffset, glyphIndexes;
  202064. static uint16 getValue16 (CFDataRef data, const int index)
  202065. {
  202066. return CFSwapInt16BigToHost (*(UInt16*) (CFDataGetBytePtr (data) + index));
  202067. }
  202068. static uint32 getValue32 (CFDataRef data, const int index)
  202069. {
  202070. return CFSwapInt32BigToHost (*(UInt32*) (CFDataGetBytePtr (data) + index));
  202071. }
  202072. };
  202073. ScopedPointer <CharToGlyphMapper> charToGlyphMapper;
  202074. #endif
  202075. };
  202076. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  202077. {
  202078. return new MacTypeface (font);
  202079. }
  202080. const StringArray Font::findAllTypefaceNames() throw()
  202081. {
  202082. StringArray names;
  202083. const ScopedAutoReleasePool pool;
  202084. #if JUCE_IPHONE
  202085. NSArray* fonts = [UIFont familyNames];
  202086. #else
  202087. NSArray* fonts = [[NSFontManager sharedFontManager] availableFontFamilies];
  202088. #endif
  202089. for (unsigned int i = 0; i < [fonts count]; ++i)
  202090. names.add (nsStringToJuce ((NSString*) [fonts objectAtIndex: i]));
  202091. names.sort (true);
  202092. return names;
  202093. }
  202094. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw()
  202095. {
  202096. #if JUCE_IPHONE
  202097. defaultSans = "Helvetica";
  202098. defaultSerif = "Times New Roman";
  202099. defaultFixed = "Courier New";
  202100. #else
  202101. defaultSans = "Lucida Grande";
  202102. defaultSerif = "Times New Roman";
  202103. defaultFixed = "Monaco";
  202104. #endif
  202105. }
  202106. #endif
  202107. /*** End of inlined file: juce_mac_Fonts.mm ***/
  202108. /*** Start of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  202109. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  202110. // compiled on its own).
  202111. #if JUCE_INCLUDED_FILE
  202112. class CoreGraphicsImage : public Image
  202113. {
  202114. public:
  202115. CoreGraphicsImage (const PixelFormat format_,
  202116. const int imageWidth_,
  202117. const int imageHeight_,
  202118. const bool clearImage)
  202119. : Image (format_, imageWidth_, imageHeight_, clearImage)
  202120. {
  202121. CGColorSpaceRef colourSpace = format == Image::SingleChannel ? CGColorSpaceCreateDeviceGray()
  202122. : CGColorSpaceCreateDeviceRGB();
  202123. context = CGBitmapContextCreate (imageData, imageWidth, imageHeight, 8, lineStride,
  202124. colourSpace, getCGImageFlags (*this));
  202125. CGColorSpaceRelease (colourSpace);
  202126. }
  202127. ~CoreGraphicsImage()
  202128. {
  202129. CGContextRelease (context);
  202130. }
  202131. LowLevelGraphicsContext* createLowLevelContext();
  202132. static CGImageRef createImage (const Image& juceImage, const bool forAlpha, CGColorSpaceRef colourSpace)
  202133. {
  202134. const CoreGraphicsImage* nativeImage = dynamic_cast <const CoreGraphicsImage*> (&juceImage);
  202135. if (nativeImage != 0 && (juceImage.getFormat() == Image::SingleChannel || ! forAlpha))
  202136. {
  202137. return CGBitmapContextCreateImage (nativeImage->context);
  202138. }
  202139. else
  202140. {
  202141. const Image::BitmapData srcData (juceImage, 0, 0, juceImage.getWidth(), juceImage.getHeight());
  202142. CGDataProviderRef provider = CGDataProviderCreateWithData (0, srcData.data, srcData.lineStride * srcData.height, 0);
  202143. CGImageRef imageRef = CGImageCreate (srcData.width, srcData.height,
  202144. 8, srcData.pixelStride * 8, srcData.lineStride,
  202145. colourSpace, getCGImageFlags (juceImage), provider,
  202146. 0, true, kCGRenderingIntentDefault);
  202147. CGDataProviderRelease (provider);
  202148. return imageRef;
  202149. }
  202150. }
  202151. #if JUCE_MAC
  202152. static NSImage* createNSImage (const Image& image)
  202153. {
  202154. const ScopedAutoReleasePool pool;
  202155. NSImage* im = [[NSImage alloc] init];
  202156. [im setSize: NSMakeSize (image.getWidth(), image.getHeight())];
  202157. [im lockFocus];
  202158. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  202159. CGImageRef imageRef = createImage (image, false, colourSpace);
  202160. CGColorSpaceRelease (colourSpace);
  202161. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  202162. CGContextDrawImage (cg, CGRectMake (0, 0, image.getWidth(), image.getHeight()), imageRef);
  202163. CGImageRelease (imageRef);
  202164. [im unlockFocus];
  202165. return im;
  202166. }
  202167. #endif
  202168. CGContextRef context;
  202169. private:
  202170. static CGBitmapInfo getCGImageFlags (const Image& image)
  202171. {
  202172. #if JUCE_BIG_ENDIAN
  202173. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Big) : kCGBitmapByteOrderDefault;
  202174. #else
  202175. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little) : kCGBitmapByteOrderDefault;
  202176. #endif
  202177. }
  202178. };
  202179. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  202180. {
  202181. #if USE_COREGRAPHICS_RENDERING
  202182. return new CoreGraphicsImage (format == RGB ? ARGB : format, imageWidth, imageHeight, clearImage);
  202183. #else
  202184. return new Image (format, imageWidth, imageHeight, clearImage);
  202185. #endif
  202186. }
  202187. class CoreGraphicsContext : public LowLevelGraphicsContext
  202188. {
  202189. public:
  202190. CoreGraphicsContext (CGContextRef context_, const float flipHeight_)
  202191. : context (context_),
  202192. flipHeight (flipHeight_),
  202193. state (new SavedState()),
  202194. numGradientLookupEntries (0)
  202195. {
  202196. CGContextRetain (context);
  202197. CGContextSaveGState(context);
  202198. CGContextSetShouldSmoothFonts (context, true);
  202199. CGContextSetShouldAntialias (context, true);
  202200. CGContextSetBlendMode (context, kCGBlendModeNormal);
  202201. rgbColourSpace = CGColorSpaceCreateDeviceRGB();
  202202. greyColourSpace = CGColorSpaceCreateDeviceGray();
  202203. gradientCallbacks.version = 0;
  202204. gradientCallbacks.evaluate = gradientCallback;
  202205. gradientCallbacks.releaseInfo = 0;
  202206. setFont (Font());
  202207. }
  202208. ~CoreGraphicsContext()
  202209. {
  202210. CGContextRestoreGState (context);
  202211. CGContextRelease (context);
  202212. CGColorSpaceRelease (rgbColourSpace);
  202213. CGColorSpaceRelease (greyColourSpace);
  202214. }
  202215. bool isVectorDevice() const { return false; }
  202216. void setOrigin (int x, int y)
  202217. {
  202218. CGContextTranslateCTM (context, x, -y);
  202219. }
  202220. bool clipToRectangle (const Rectangle<int>& r)
  202221. {
  202222. CGContextClipToRect (context, CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight()));
  202223. return ! isClipEmpty();
  202224. }
  202225. bool clipToRectangleList (const RectangleList& clipRegion)
  202226. {
  202227. if (clipRegion.isEmpty())
  202228. {
  202229. CGContextClipToRect (context, CGRectMake (0, 0, 0, 0));
  202230. return false;
  202231. }
  202232. else
  202233. {
  202234. const int numRects = clipRegion.getNumRectangles();
  202235. HeapBlock <CGRect> rects (numRects);
  202236. for (int i = 0; i < numRects; ++i)
  202237. {
  202238. const Rectangle<int>& r = clipRegion.getRectangle(i);
  202239. rects[i] = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  202240. }
  202241. CGContextClipToRects (context, rects, numRects);
  202242. return ! isClipEmpty();
  202243. }
  202244. }
  202245. void excludeClipRectangle (const Rectangle<int>& r)
  202246. {
  202247. RectangleList remaining (getClipBounds());
  202248. remaining.subtract (r);
  202249. clipToRectangleList (remaining);
  202250. }
  202251. void clipToPath (const Path& path, const AffineTransform& transform)
  202252. {
  202253. createPath (path, transform);
  202254. CGContextClip (context);
  202255. }
  202256. void clipToImageAlpha (const Image& sourceImage, const Rectangle<int>& srcClip, const AffineTransform& transform)
  202257. {
  202258. if (! transform.isSingularity())
  202259. {
  202260. Image* singleChannelImage = createAlphaChannelImage (sourceImage);
  202261. CGImageRef image = CoreGraphicsImage::createImage (*singleChannelImage, true, greyColourSpace);
  202262. flip();
  202263. AffineTransform t (AffineTransform::scale (1.0f, -1.0f).translated (0, sourceImage.getHeight()).followedBy (transform));
  202264. applyTransform (t);
  202265. CGRect r = CGRectMake (0, 0, sourceImage.getWidth(), sourceImage.getHeight());
  202266. CGContextClipToMask (context, r, image);
  202267. applyTransform (t.inverted());
  202268. flip();
  202269. CGImageRelease (image);
  202270. deleteAlphaChannelImage (sourceImage, singleChannelImage);
  202271. }
  202272. }
  202273. bool clipRegionIntersects (const Rectangle<int>& r)
  202274. {
  202275. return getClipBounds().intersects (r);
  202276. }
  202277. const Rectangle<int> getClipBounds() const
  202278. {
  202279. CGRect bounds = CGRectIntegral (CGContextGetClipBoundingBox (context));
  202280. return Rectangle<int> (roundToInt (bounds.origin.x),
  202281. roundToInt (flipHeight - (bounds.origin.y + bounds.size.height)),
  202282. roundToInt (bounds.size.width),
  202283. roundToInt (bounds.size.height));
  202284. }
  202285. bool isClipEmpty() const
  202286. {
  202287. return CGRectIsEmpty (CGContextGetClipBoundingBox (context));
  202288. }
  202289. void saveState()
  202290. {
  202291. CGContextSaveGState (context);
  202292. stateStack.add (new SavedState (*state));
  202293. }
  202294. void restoreState()
  202295. {
  202296. CGContextRestoreGState (context);
  202297. SavedState* const top = stateStack.getLast();
  202298. if (top != 0)
  202299. {
  202300. state = top;
  202301. stateStack.removeLast (1, false);
  202302. }
  202303. else
  202304. {
  202305. jassertfalse // trying to pop with an empty stack!
  202306. }
  202307. }
  202308. void setFill (const FillType& fillType)
  202309. {
  202310. state->fillType = fillType;
  202311. if (fillType.isColour())
  202312. {
  202313. CGContextSetRGBFillColor (context, fillType.colour.getFloatRed(), fillType.colour.getFloatGreen(),
  202314. fillType.colour.getFloatBlue(), fillType.colour.getFloatAlpha());
  202315. CGContextSetAlpha (context, 1.0f);
  202316. }
  202317. }
  202318. void setOpacity (float newOpacity)
  202319. {
  202320. state->fillType.setOpacity (newOpacity);
  202321. setFill (state->fillType);
  202322. }
  202323. void setInterpolationQuality (Graphics::ResamplingQuality quality)
  202324. {
  202325. CGContextSetInterpolationQuality (context, quality == Graphics::lowResamplingQuality
  202326. ? kCGInterpolationLow
  202327. : kCGInterpolationHigh);
  202328. }
  202329. void fillRect (const Rectangle<int>& r, const bool replaceExistingContents)
  202330. {
  202331. CGRect cgRect = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  202332. if (replaceExistingContents)
  202333. {
  202334. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  202335. CGContextClearRect (context, cgRect);
  202336. #else
  202337. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  202338. if (CGContextDrawLinearGradient == 0) // (just a way of checking whether we're running in 10.5 or later)
  202339. CGContextClearRect (context, cgRect);
  202340. else
  202341. #endif
  202342. CGContextSetBlendMode (context, kCGBlendModeCopy);
  202343. #endif
  202344. fillRect (r, false);
  202345. CGContextSetBlendMode (context, kCGBlendModeNormal);
  202346. }
  202347. else
  202348. {
  202349. if (state->fillType.isColour())
  202350. {
  202351. CGContextFillRect (context, cgRect);
  202352. }
  202353. else if (state->fillType.isGradient())
  202354. {
  202355. CGContextSaveGState (context);
  202356. CGContextClipToRect (context, cgRect);
  202357. drawGradient();
  202358. CGContextRestoreGState (context);
  202359. }
  202360. else
  202361. {
  202362. CGContextSaveGState (context);
  202363. CGContextClipToRect (context, cgRect);
  202364. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  202365. CGContextRestoreGState (context);
  202366. }
  202367. }
  202368. }
  202369. void fillPath (const Path& path, const AffineTransform& transform)
  202370. {
  202371. CGContextSaveGState (context);
  202372. if (state->fillType.isColour())
  202373. {
  202374. flip();
  202375. applyTransform (transform);
  202376. createPath (path);
  202377. if (path.isUsingNonZeroWinding())
  202378. CGContextFillPath (context);
  202379. else
  202380. CGContextEOFillPath (context);
  202381. }
  202382. else
  202383. {
  202384. createPath (path, transform);
  202385. if (path.isUsingNonZeroWinding())
  202386. CGContextClip (context);
  202387. else
  202388. CGContextEOClip (context);
  202389. if (state->fillType.isGradient())
  202390. drawGradient();
  202391. else
  202392. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  202393. }
  202394. CGContextRestoreGState (context);
  202395. }
  202396. void drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  202397. const AffineTransform& transform, const bool fillEntireClipAsTiles)
  202398. {
  202399. jassert (sourceImage.getBounds().contains (srcClip));
  202400. CGImageRef fullImage = CoreGraphicsImage::createImage (sourceImage, false, rgbColourSpace);
  202401. CGImageRef image = fullImage;
  202402. if (srcClip != sourceImage.getBounds())
  202403. {
  202404. image = CGImageCreateWithImageInRect (fullImage, CGRectMake (srcClip.getX(), srcClip.getY(),
  202405. srcClip.getWidth(), srcClip.getHeight()));
  202406. CGImageRelease (fullImage);
  202407. }
  202408. CGContextSaveGState (context);
  202409. CGContextSetAlpha (context, state->fillType.getOpacity());
  202410. flip();
  202411. applyTransform (AffineTransform::scale (1.0f, -1.0f).translated (0, srcClip.getHeight()).followedBy (transform));
  202412. CGRect imageRect = CGRectMake (0, 0, srcClip.getWidth(), srcClip.getHeight());
  202413. if (fillEntireClipAsTiles)
  202414. {
  202415. #if JUCE_IPHONE || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5)
  202416. CGContextDrawTiledImage (context, imageRect, image);
  202417. #else
  202418. #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
  202419. // There's a bug in CGContextDrawTiledImage that makes it incredibly slow
  202420. // if it's doing a transformation - it's quicker to just draw lots of images manually
  202421. if (CGContextDrawTiledImage != 0 && transform.isOnlyTranslation())
  202422. CGContextDrawTiledImage (context, imageRect, image);
  202423. else
  202424. #endif
  202425. {
  202426. // Fallback to manually doing a tiled fill on 10.4
  202427. CGRect clip = CGRectIntegral (CGContextGetClipBoundingBox (context));
  202428. const int iw = srcClip.getWidth();
  202429. const int ih = srcClip.getHeight();
  202430. int x = 0, y = 0;
  202431. while (x > clip.origin.x) x -= iw;
  202432. while (y > clip.origin.y) y -= ih;
  202433. const int right = (int) (clip.origin.x + clip.size.width);
  202434. const int bottom = (int) (clip.origin.y + clip.size.height);
  202435. while (y < bottom)
  202436. {
  202437. for (int x2 = x; x2 < right; x2 += iw)
  202438. CGContextDrawImage (context, CGRectMake (x2, y, iw, ih), image);
  202439. y += ih;
  202440. }
  202441. }
  202442. #endif
  202443. }
  202444. else
  202445. {
  202446. CGContextDrawImage (context, imageRect, image);
  202447. }
  202448. CGImageRelease (image); // (This causes a memory bug in iPhone sim 3.0 - try upgrading to a later version if you hit this)
  202449. CGContextRestoreGState (context);
  202450. }
  202451. void drawLine (double x1, double y1, double x2, double y2)
  202452. {
  202453. CGContextSetLineCap (context, kCGLineCapSquare);
  202454. CGContextSetLineWidth (context, 1.0f);
  202455. CGContextSetRGBStrokeColor (context,
  202456. state->fillType.colour.getFloatRed(), state->fillType.colour.getFloatGreen(),
  202457. state->fillType.colour.getFloatBlue(), state->fillType.colour.getFloatAlpha());
  202458. CGPoint line[] = { { (float) x1 + 0.5f, flipHeight - ((float) y1 + 0.5f) },
  202459. { (float) x2 + 0.5f, flipHeight - ((float) y2 + 0.5f) } };
  202460. CGContextStrokeLineSegments (context, line, 1);
  202461. }
  202462. void drawVerticalLine (const int x, double top, double bottom)
  202463. {
  202464. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  202465. CGContextFillRect (context, CGRectMake (x, flipHeight - (float) bottom, 1.0f, (float) (bottom - top)));
  202466. #else
  202467. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  202468. // the x co-ord slightly to trick it..
  202469. CGContextFillRect (context, CGRectMake (x + 1.0f / 256.0f, flipHeight - (float) bottom, 1.0f + 1.0f / 256.0f, (float) (bottom - top)));
  202470. #endif
  202471. }
  202472. void drawHorizontalLine (const int y, double left, double right)
  202473. {
  202474. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  202475. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + 1.0f), (float) (right - left), 1.0f));
  202476. #else
  202477. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  202478. // the x co-ord slightly to trick it..
  202479. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + (1.0f + 1.0f / 256.0f)), (float) (right - left), 1.0f + 1.0f / 256.0f));
  202480. #endif
  202481. }
  202482. void setFont (const Font& newFont)
  202483. {
  202484. if (state->font != newFont)
  202485. {
  202486. state->fontRef = 0;
  202487. state->font = newFont;
  202488. MacTypeface* mf = dynamic_cast <MacTypeface*> ((Typeface*) state->font.getTypeface());
  202489. if (mf != 0)
  202490. {
  202491. state->fontRef = mf->fontRef;
  202492. CGContextSetFont (context, state->fontRef);
  202493. CGContextSetFontSize (context, state->font.getHeight() * mf->fontHeightToCGSizeFactor);
  202494. state->fontTransform = mf->renderingTransform;
  202495. state->fontTransform.a *= state->font.getHorizontalScale();
  202496. CGContextSetTextMatrix (context, state->fontTransform);
  202497. }
  202498. }
  202499. }
  202500. const Font getFont()
  202501. {
  202502. return state->font;
  202503. }
  202504. void drawGlyph (int glyphNumber, const AffineTransform& transform)
  202505. {
  202506. if (state->fontRef != 0 && state->fillType.isColour())
  202507. {
  202508. if (transform.isOnlyTranslation())
  202509. {
  202510. CGGlyph g = glyphNumber;
  202511. CGContextShowGlyphsAtPoint (context, transform.getTranslationX(),
  202512. flipHeight - roundToInt (transform.getTranslationY()), &g, 1);
  202513. }
  202514. else
  202515. {
  202516. CGContextSaveGState (context);
  202517. flip();
  202518. applyTransform (transform);
  202519. CGAffineTransform t = state->fontTransform;
  202520. t.d = -t.d;
  202521. CGContextSetTextMatrix (context, t);
  202522. CGGlyph g = glyphNumber;
  202523. CGContextShowGlyphsAtPoint (context, 0, 0, &g, 1);
  202524. CGContextSetTextMatrix (context, state->fontTransform);
  202525. CGContextRestoreGState (context);
  202526. }
  202527. }
  202528. else
  202529. {
  202530. Path p;
  202531. Font& f = state->font;
  202532. f.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  202533. fillPath (p, AffineTransform::scale (f.getHeight() * f.getHorizontalScale(), f.getHeight())
  202534. .followedBy (transform));
  202535. }
  202536. }
  202537. private:
  202538. CGContextRef context;
  202539. const float flipHeight;
  202540. CGColorSpaceRef rgbColourSpace, greyColourSpace;
  202541. CGFunctionCallbacks gradientCallbacks;
  202542. struct SavedState
  202543. {
  202544. SavedState()
  202545. : font (1.0f), fontRef (0), fontTransform (CGAffineTransformIdentity)
  202546. {
  202547. }
  202548. SavedState (const SavedState& other)
  202549. : fillType (other.fillType), font (other.font), fontRef (other.fontRef),
  202550. fontTransform (other.fontTransform)
  202551. {
  202552. }
  202553. ~SavedState()
  202554. {
  202555. }
  202556. FillType fillType;
  202557. Font font;
  202558. CGFontRef fontRef;
  202559. CGAffineTransform fontTransform;
  202560. };
  202561. ScopedPointer <SavedState> state;
  202562. OwnedArray <SavedState> stateStack;
  202563. HeapBlock <PixelARGB> gradientLookupTable;
  202564. int numGradientLookupEntries;
  202565. static void gradientCallback (void* info, const CGFloat* inData, CGFloat* outData)
  202566. {
  202567. const CoreGraphicsContext* const g = (const CoreGraphicsContext*) info;
  202568. const int index = roundToInt (g->numGradientLookupEntries * inData[0]);
  202569. PixelARGB colour (g->gradientLookupTable [jlimit (0, g->numGradientLookupEntries, index)]);
  202570. colour.unpremultiply();
  202571. outData[0] = colour.getRed() / 255.0f;
  202572. outData[1] = colour.getGreen() / 255.0f;
  202573. outData[2] = colour.getBlue() / 255.0f;
  202574. outData[3] = colour.getAlpha() / 255.0f;
  202575. }
  202576. CGShadingRef createGradient (const AffineTransform& transform, ColourGradient gradient)
  202577. {
  202578. numGradientLookupEntries = gradient.createLookupTable (transform, gradientLookupTable);
  202579. --numGradientLookupEntries;
  202580. CGShadingRef result = 0;
  202581. CGFunctionRef function = CGFunctionCreate ((void*) this, 1, 0, 4, 0, &gradientCallbacks);
  202582. CGPoint p1 (CGPointMake (gradient.x1, gradient.y1));
  202583. if (gradient.isRadial)
  202584. {
  202585. result = CGShadingCreateRadial (rgbColourSpace, p1, 0,
  202586. p1, hypotf (gradient.x1 - gradient.x2, gradient.y1 - gradient.y2),
  202587. function, true, true);
  202588. }
  202589. else
  202590. {
  202591. result = CGShadingCreateAxial (rgbColourSpace, p1,
  202592. CGPointMake (gradient.x2, gradient.y2),
  202593. function, true, true);
  202594. }
  202595. CGFunctionRelease (function);
  202596. return result;
  202597. }
  202598. void drawGradient()
  202599. {
  202600. flip();
  202601. applyTransform (state->fillType.transform);
  202602. CGContextSetInterpolationQuality (context, kCGInterpolationDefault); // (This is required for 10.4, where there's a crash if
  202603. // you draw a gradient with high quality interp enabled).
  202604. CGShadingRef shading = createGradient (state->fillType.transform, *(state->fillType.gradient));
  202605. CGContextSetAlpha (context, state->fillType.getOpacity());
  202606. CGContextDrawShading (context, shading);
  202607. CGShadingRelease (shading);
  202608. }
  202609. void createPath (const Path& path) const
  202610. {
  202611. CGContextBeginPath (context);
  202612. Path::Iterator i (path);
  202613. while (i.next())
  202614. {
  202615. switch (i.elementType)
  202616. {
  202617. case Path::Iterator::startNewSubPath:
  202618. CGContextMoveToPoint (context, i.x1, i.y1);
  202619. break;
  202620. case Path::Iterator::lineTo:
  202621. CGContextAddLineToPoint (context, i.x1, i.y1);
  202622. break;
  202623. case Path::Iterator::quadraticTo:
  202624. CGContextAddQuadCurveToPoint (context, i.x1, i.y1, i.x2, i.y2);
  202625. break;
  202626. case Path::Iterator::cubicTo:
  202627. CGContextAddCurveToPoint (context, i.x1, i.y1, i.x2, i.y2, i.x3, i.y3);
  202628. break;
  202629. case Path::Iterator::closePath:
  202630. CGContextClosePath (context); break;
  202631. default:
  202632. jassertfalse
  202633. break;
  202634. }
  202635. }
  202636. }
  202637. void createPath (const Path& path, const AffineTransform& transform) const
  202638. {
  202639. CGContextBeginPath (context);
  202640. Path::Iterator i (path);
  202641. while (i.next())
  202642. {
  202643. switch (i.elementType)
  202644. {
  202645. case Path::Iterator::startNewSubPath:
  202646. transform.transformPoint (i.x1, i.y1);
  202647. CGContextMoveToPoint (context, i.x1, flipHeight - i.y1);
  202648. break;
  202649. case Path::Iterator::lineTo:
  202650. transform.transformPoint (i.x1, i.y1);
  202651. CGContextAddLineToPoint (context, i.x1, flipHeight - i.y1);
  202652. break;
  202653. case Path::Iterator::quadraticTo:
  202654. transform.transformPoint (i.x1, i.y1);
  202655. transform.transformPoint (i.x2, i.y2);
  202656. CGContextAddQuadCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2);
  202657. break;
  202658. case Path::Iterator::cubicTo:
  202659. transform.transformPoint (i.x1, i.y1);
  202660. transform.transformPoint (i.x2, i.y2);
  202661. transform.transformPoint (i.x3, i.y3);
  202662. CGContextAddCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2, i.x3, flipHeight - i.y3);
  202663. break;
  202664. case Path::Iterator::closePath:
  202665. CGContextClosePath (context); break;
  202666. default:
  202667. jassertfalse
  202668. break;
  202669. }
  202670. }
  202671. }
  202672. static Image* createAlphaChannelImage (const Image& im)
  202673. {
  202674. if (im.getFormat() == Image::SingleChannel)
  202675. return const_cast <Image*> (&im);
  202676. return im.createCopyOfAlphaChannel();
  202677. }
  202678. static void deleteAlphaChannelImage (const Image& im, Image* const alphaIm)
  202679. {
  202680. if (im.getFormat() != Image::SingleChannel)
  202681. delete alphaIm;
  202682. }
  202683. void flip() const
  202684. {
  202685. CGContextConcatCTM (context, CGAffineTransformMake (1, 0, 0, -1, 0, flipHeight));
  202686. }
  202687. void applyTransform (const AffineTransform& transform) const
  202688. {
  202689. CGAffineTransform t;
  202690. t.a = transform.mat00;
  202691. t.b = transform.mat10;
  202692. t.c = transform.mat01;
  202693. t.d = transform.mat11;
  202694. t.tx = transform.mat02;
  202695. t.ty = transform.mat12;
  202696. CGContextConcatCTM (context, t);
  202697. }
  202698. float flipY (float y) const
  202699. {
  202700. return flipHeight - y;
  202701. }
  202702. };
  202703. LowLevelGraphicsContext* CoreGraphicsImage::createLowLevelContext()
  202704. {
  202705. return new CoreGraphicsContext (context, imageHeight);
  202706. }
  202707. #endif
  202708. /*** End of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  202709. /*** Start of inlined file: juce_iphone_UIViewComponentPeer.mm ***/
  202710. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  202711. // compiled on its own).
  202712. #if JUCE_INCLUDED_FILE
  202713. class UIViewComponentPeer;
  202714. END_JUCE_NAMESPACE
  202715. #define JuceUIView MakeObjCClassName(JuceUIView)
  202716. @interface JuceUIView : UIView
  202717. {
  202718. @public
  202719. UIViewComponentPeer* owner;
  202720. }
  202721. - (JuceUIView*) initWithOwner: (UIViewComponentPeer*) owner withFrame: (CGRect) frame;
  202722. - (void) dealloc;
  202723. - (void) drawRect: (CGRect) r;
  202724. - (void) touchesBegan: (NSSet*) touches withEvent: (UIEvent*) event;
  202725. - (void) touchesMoved: (NSSet*) touches withEvent: (UIEvent*) event;
  202726. - (void) touchesEnded: (NSSet*) touches withEvent: (UIEvent*) event;
  202727. - (void) touchesCancelled: (NSSet*) touches withEvent: (UIEvent*) event;
  202728. - (BOOL) becomeFirstResponder;
  202729. - (BOOL) resignFirstResponder;
  202730. - (BOOL) canBecomeFirstResponder;
  202731. - (void) asyncRepaint: (id) rect;
  202732. @end
  202733. #define JuceUIWindow MakeObjCClassName(JuceUIWindow)
  202734. @interface JuceUIWindow : UIWindow
  202735. {
  202736. @private
  202737. UIViewComponentPeer* owner;
  202738. bool isZooming;
  202739. }
  202740. - (void) setOwner: (UIViewComponentPeer*) owner;
  202741. - (void) becomeKeyWindow;
  202742. @end
  202743. BEGIN_JUCE_NAMESPACE
  202744. class UIViewComponentPeer : public ComponentPeer
  202745. {
  202746. public:
  202747. UIViewComponentPeer (Component* const component,
  202748. const int windowStyleFlags,
  202749. UIView* viewToAttachTo);
  202750. ~UIViewComponentPeer();
  202751. void* getNativeHandle() const;
  202752. void setVisible (bool shouldBeVisible);
  202753. void setTitle (const String& title);
  202754. void setPosition (int x, int y);
  202755. void setSize (int w, int h);
  202756. void setBounds (int x, int y, int w, int h, const bool isNowFullScreen);
  202757. const Rectangle<int> getBounds() const;
  202758. const Rectangle<int> getBounds (const bool global) const;
  202759. const Point<int> getScreenPosition() const;
  202760. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition);
  202761. const Point<int> globalPositionToRelative (const Point<int>& screenPosition);
  202762. void setMinimised (bool shouldBeMinimised);
  202763. bool isMinimised() const;
  202764. void setFullScreen (bool shouldBeFullScreen);
  202765. bool isFullScreen() const;
  202766. bool contains (const Point<int>& position, bool trueIfInAChildWindow) const;
  202767. const BorderSize getFrameSize() const;
  202768. bool setAlwaysOnTop (bool alwaysOnTop);
  202769. void toFront (bool makeActiveWindow);
  202770. void toBehind (ComponentPeer* other);
  202771. void setIcon (const Image& newIcon);
  202772. virtual void drawRect (CGRect r);
  202773. virtual bool canBecomeKeyWindow();
  202774. virtual bool windowShouldClose();
  202775. virtual void redirectMovedOrResized();
  202776. virtual CGRect constrainRect (CGRect r);
  202777. virtual void viewFocusGain();
  202778. virtual void viewFocusLoss();
  202779. bool isFocused() const;
  202780. void grabFocus();
  202781. void textInputRequired (const Point<int>& position);
  202782. void handleTouches (UIEvent* e, bool isDown, bool isUp, bool isCancel);
  202783. void repaint (int x, int y, int w, int h);
  202784. void performAnyPendingRepaintsNow();
  202785. juce_UseDebuggingNewOperator
  202786. UIWindow* window;
  202787. JuceUIView* view;
  202788. bool isSharedWindow, fullScreen, insideDrawRect;
  202789. static ModifierKeys currentModifiers;
  202790. static int64 getMouseTime (UIEvent* e)
  202791. {
  202792. return (Time::currentTimeMillis() - Time::getMillisecondCounter())
  202793. + (int64) ([e timestamp] * 1000.0);
  202794. }
  202795. Array <UITouch*> currentTouches;
  202796. };
  202797. END_JUCE_NAMESPACE
  202798. @implementation JuceUIView
  202799. - (JuceUIView*) initWithOwner: (UIViewComponentPeer*) owner_
  202800. withFrame: (CGRect) frame
  202801. {
  202802. [super initWithFrame: frame];
  202803. owner = owner_;
  202804. return self;
  202805. }
  202806. - (void) dealloc
  202807. {
  202808. [super dealloc];
  202809. }
  202810. - (void) drawRect: (CGRect) r
  202811. {
  202812. if (owner != 0)
  202813. owner->drawRect (r);
  202814. }
  202815. bool KeyPress::isKeyCurrentlyDown (const int keyCode) throw()
  202816. {
  202817. return false;
  202818. }
  202819. ModifierKeys UIViewComponentPeer::currentModifiers;
  202820. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  202821. {
  202822. return UIViewComponentPeer::currentModifiers;
  202823. }
  202824. void ModifierKeys::updateCurrentModifiers() throw()
  202825. {
  202826. currentModifiers = UIViewComponentPeer::currentModifiers;
  202827. }
  202828. JUCE_NAMESPACE::Point<int> juce_lastMousePos;
  202829. - (void) touchesBegan: (NSSet*) touches withEvent: (UIEvent*) event
  202830. {
  202831. if (owner != 0)
  202832. owner->handleTouches (event, true, false, false);
  202833. }
  202834. - (void) touchesMoved: (NSSet*) touches withEvent: (UIEvent*) event
  202835. {
  202836. if (owner != 0)
  202837. owner->handleTouches (event, false, false, false);
  202838. }
  202839. - (void) touchesEnded: (NSSet*) touches withEvent: (UIEvent*) event
  202840. {
  202841. if (owner != 0)
  202842. owner->handleTouches (event, false, true, false);
  202843. }
  202844. - (void) touchesCancelled: (NSSet*) touches withEvent: (UIEvent*) event
  202845. {
  202846. if (owner != 0)
  202847. owner->handleTouches (event, false, true, true);
  202848. [self touchesEnded: touches withEvent: event];
  202849. }
  202850. - (BOOL) becomeFirstResponder
  202851. {
  202852. if (owner != 0)
  202853. owner->viewFocusGain();
  202854. return true;
  202855. }
  202856. - (BOOL) resignFirstResponder
  202857. {
  202858. if (owner != 0)
  202859. owner->viewFocusLoss();
  202860. return true;
  202861. }
  202862. - (BOOL) canBecomeFirstResponder
  202863. {
  202864. return owner != 0 && owner->canBecomeKeyWindow();
  202865. }
  202866. - (void) asyncRepaint: (id) rect
  202867. {
  202868. CGRect* r = (CGRect*) [((NSData*) rect) bytes];
  202869. [self setNeedsDisplayInRect: *r];
  202870. }
  202871. @end
  202872. @implementation JuceUIWindow
  202873. - (void) setOwner: (UIViewComponentPeer*) owner_
  202874. {
  202875. owner = owner_;
  202876. isZooming = false;
  202877. }
  202878. - (void) becomeKeyWindow
  202879. {
  202880. [super becomeKeyWindow];
  202881. if (owner != 0)
  202882. owner->grabFocus();
  202883. }
  202884. @end
  202885. BEGIN_JUCE_NAMESPACE
  202886. UIViewComponentPeer::UIViewComponentPeer (Component* const component,
  202887. const int windowStyleFlags,
  202888. UIView* viewToAttachTo)
  202889. : ComponentPeer (component, windowStyleFlags),
  202890. window (0),
  202891. view (0),
  202892. isSharedWindow (viewToAttachTo != 0),
  202893. fullScreen (false),
  202894. insideDrawRect (false)
  202895. {
  202896. CGRect r;
  202897. r.origin.x = 0;
  202898. r.origin.y = 0;
  202899. r.size.width = (float) component->getWidth();
  202900. r.size.height = (float) component->getHeight();
  202901. view = [[JuceUIView alloc] initWithOwner: this withFrame: r];
  202902. if (isSharedWindow)
  202903. {
  202904. window = [viewToAttachTo window];
  202905. [viewToAttachTo addSubview: view];
  202906. setVisible (component->isVisible());
  202907. }
  202908. else
  202909. {
  202910. r.origin.x = (float) component->getX();
  202911. r.origin.y = (float) component->getY();
  202912. r.origin.y = [[UIScreen mainScreen] bounds].size.height - (r.origin.y + r.size.height);
  202913. window = [[JuceUIWindow alloc] init];
  202914. window.frame = r;
  202915. window.opaque = component->isOpaque();
  202916. view.opaque = component->isOpaque();
  202917. window.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent: 0];
  202918. view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent: 0];
  202919. [((JuceUIWindow*) window) setOwner: this];
  202920. if (component->isAlwaysOnTop())
  202921. window.windowLevel = UIWindowLevelAlert;
  202922. [window addSubview: view];
  202923. view.frame = CGRectMake (0, 0, r.size.width, r.size.height);
  202924. view.hidden = ! component->isVisible();
  202925. window.hidden = ! component->isVisible();
  202926. view.multipleTouchEnabled = YES;
  202927. }
  202928. setTitle (component->getName());
  202929. }
  202930. UIViewComponentPeer::~UIViewComponentPeer()
  202931. {
  202932. view->owner = 0;
  202933. [view removeFromSuperview];
  202934. [view release];
  202935. if (! isSharedWindow)
  202936. {
  202937. [((JuceUIWindow*) window) setOwner: 0];
  202938. [window release];
  202939. }
  202940. }
  202941. void* UIViewComponentPeer::getNativeHandle() const
  202942. {
  202943. return view;
  202944. }
  202945. void UIViewComponentPeer::setVisible (bool shouldBeVisible)
  202946. {
  202947. view.hidden = ! shouldBeVisible;
  202948. if (! isSharedWindow)
  202949. window.hidden = ! shouldBeVisible;
  202950. }
  202951. void UIViewComponentPeer::setTitle (const String& title)
  202952. {
  202953. // xxx is this possible?
  202954. }
  202955. void UIViewComponentPeer::setPosition (int x, int y)
  202956. {
  202957. setBounds (x, y, component->getWidth(), component->getHeight(), false);
  202958. }
  202959. void UIViewComponentPeer::setSize (int w, int h)
  202960. {
  202961. setBounds (component->getX(), component->getY(), w, h, false);
  202962. }
  202963. void UIViewComponentPeer::setBounds (int x, int y, int w, int h, const bool isNowFullScreen)
  202964. {
  202965. fullScreen = isNowFullScreen;
  202966. w = jmax (0, w);
  202967. h = jmax (0, h);
  202968. CGRect r;
  202969. r.origin.x = (float) x;
  202970. r.origin.y = (float) y;
  202971. r.size.width = (float) w;
  202972. r.size.height = (float) h;
  202973. if (isSharedWindow)
  202974. {
  202975. //r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  202976. if ([view frame].size.width != r.size.width
  202977. || [view frame].size.height != r.size.height)
  202978. [view setNeedsDisplay];
  202979. view.frame = r;
  202980. }
  202981. else
  202982. {
  202983. window.frame = r;
  202984. view.frame = CGRectMake (0, 0, r.size.width, r.size.height);
  202985. }
  202986. }
  202987. const Rectangle<int> UIViewComponentPeer::getBounds (const bool global) const
  202988. {
  202989. CGRect r = [view frame];
  202990. if (global && [view window] != 0)
  202991. {
  202992. r = [view convertRect: r toView: nil];
  202993. CGRect wr = [[view window] frame];
  202994. r.origin.x += wr.origin.x;
  202995. r.origin.y += wr.origin.y;
  202996. }
  202997. return Rectangle<int> ((int) r.origin.x, (int) r.origin.y,
  202998. (int) r.size.width, (int) r.size.height);
  202999. }
  203000. const Rectangle<int> UIViewComponentPeer::getBounds() const
  203001. {
  203002. return getBounds (! isSharedWindow);
  203003. }
  203004. const Point<int> UIViewComponentPeer::getScreenPosition() const
  203005. {
  203006. return getBounds (true).getPosition();
  203007. }
  203008. const Point<int> UIViewComponentPeer::relativePositionToGlobal (const Point<int>& relativePosition)
  203009. {
  203010. return relativePosition + getScreenPosition();
  203011. }
  203012. const Point<int> UIViewComponentPeer::globalPositionToRelative (const Point<int>& screenPosition)
  203013. {
  203014. return screenPosition - getScreenPosition();
  203015. }
  203016. CGRect UIViewComponentPeer::constrainRect (CGRect r)
  203017. {
  203018. if (constrainer != 0)
  203019. {
  203020. CGRect current = [window frame];
  203021. current.origin.y = [[UIScreen mainScreen] bounds].size.height - current.origin.y - current.size.height;
  203022. r.origin.y = [[UIScreen mainScreen] bounds].size.height - r.origin.y - r.size.height;
  203023. Rectangle<int> pos ((int) r.origin.x, (int) r.origin.y,
  203024. (int) r.size.width, (int) r.size.height);
  203025. Rectangle<int> original ((int) current.origin.x, (int) current.origin.y,
  203026. (int) current.size.width, (int) current.size.height);
  203027. constrainer->checkBounds (pos, original,
  203028. Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(),
  203029. pos.getY() != original.getY() && pos.getBottom() == original.getBottom(),
  203030. pos.getX() != original.getX() && pos.getRight() == original.getRight(),
  203031. pos.getY() == original.getY() && pos.getBottom() != original.getBottom(),
  203032. pos.getX() == original.getX() && pos.getRight() != original.getRight());
  203033. r.origin.x = pos.getX();
  203034. r.origin.y = [[UIScreen mainScreen] bounds].size.height - r.size.height - pos.getY();
  203035. r.size.width = pos.getWidth();
  203036. r.size.height = pos.getHeight();
  203037. }
  203038. return r;
  203039. }
  203040. void UIViewComponentPeer::setMinimised (bool shouldBeMinimised)
  203041. {
  203042. // xxx
  203043. }
  203044. bool UIViewComponentPeer::isMinimised() const
  203045. {
  203046. return false;
  203047. }
  203048. void UIViewComponentPeer::setFullScreen (bool shouldBeFullScreen)
  203049. {
  203050. if (! isSharedWindow)
  203051. {
  203052. Rectangle<int> r (lastNonFullscreenBounds);
  203053. setMinimised (false);
  203054. if (fullScreen != shouldBeFullScreen)
  203055. {
  203056. if (shouldBeFullScreen)
  203057. r = Desktop::getInstance().getMainMonitorArea();
  203058. // (can't call the component's setBounds method because that'll reset our fullscreen flag)
  203059. if (r != getComponent()->getBounds() && ! r.isEmpty())
  203060. setBounds (r.getX(), r.getY(), r.getWidth(), r.getHeight(), shouldBeFullScreen);
  203061. }
  203062. }
  203063. }
  203064. bool UIViewComponentPeer::isFullScreen() const
  203065. {
  203066. return fullScreen;
  203067. }
  203068. bool UIViewComponentPeer::contains (const Point<int>& position, bool trueIfInAChildWindow) const
  203069. {
  203070. if (((unsigned int) position.getX()) >= (unsigned int) component->getWidth()
  203071. || ((unsigned int) position.getY()) >= (unsigned int) component->getHeight())
  203072. return false;
  203073. CGPoint p;
  203074. p.x = (float) position.getX();
  203075. p.y = (float) position.getY();
  203076. UIView* v = [view hitTest: p withEvent: nil];
  203077. if (trueIfInAChildWindow)
  203078. return v != nil;
  203079. return v == view;
  203080. }
  203081. const BorderSize UIViewComponentPeer::getFrameSize() const
  203082. {
  203083. BorderSize b;
  203084. if (! isSharedWindow)
  203085. {
  203086. CGRect v = [view convertRect: [view frame] toView: nil];
  203087. CGRect w = [window frame];
  203088. b.setTop ((int) (w.size.height - (v.origin.y + v.size.height)));
  203089. b.setBottom ((int) v.origin.y);
  203090. b.setLeft ((int) v.origin.x);
  203091. b.setRight ((int) (w.size.width - (v.origin.x + v.size.width)));
  203092. }
  203093. return b;
  203094. }
  203095. bool UIViewComponentPeer::setAlwaysOnTop (bool alwaysOnTop)
  203096. {
  203097. if (! isSharedWindow)
  203098. window.windowLevel = alwaysOnTop ? UIWindowLevelAlert : UIWindowLevelNormal;
  203099. return true;
  203100. }
  203101. void UIViewComponentPeer::toFront (bool makeActiveWindow)
  203102. {
  203103. if (isSharedWindow)
  203104. [[view superview] bringSubviewToFront: view];
  203105. if (window != 0 && component->isVisible())
  203106. [window makeKeyAndVisible];
  203107. }
  203108. void UIViewComponentPeer::toBehind (ComponentPeer* other)
  203109. {
  203110. UIViewComponentPeer* o = (UIViewComponentPeer*) other;
  203111. if (isSharedWindow)
  203112. {
  203113. [[view superview] insertSubview: view belowSubview: o->view];
  203114. }
  203115. else
  203116. {
  203117. jassertfalse // don't know how to do this
  203118. }
  203119. }
  203120. void UIViewComponentPeer::setIcon (const Image& /*newIcon*/)
  203121. {
  203122. // to do..
  203123. }
  203124. void UIViewComponentPeer::handleTouches (UIEvent* event, const bool isDown, const bool isUp, bool isCancel)
  203125. {
  203126. NSArray* touches = [[event touchesForView: view] allObjects];
  203127. for (unsigned int i = 0; i < [touches count]; ++i)
  203128. {
  203129. UITouch* touch = [touches objectAtIndex: i];
  203130. CGPoint p = [touch locationInView: view];
  203131. const Point<int> pos ((int) p.x, (int) p.y);
  203132. juce_lastMousePos = pos + getScreenPosition();
  203133. const int64 time = getMouseTime (event);
  203134. int touchIndex = currentTouches.indexOf (touch);
  203135. if (touchIndex < 0)
  203136. {
  203137. touchIndex = currentTouches.size();
  203138. currentTouches.add (touch);
  203139. }
  203140. if (isDown)
  203141. {
  203142. currentModifiers = currentModifiers.withoutMouseButtons();
  203143. handleMouseEvent (touchIndex, pos, currentModifiers, time);
  203144. currentModifiers = currentModifiers.withoutMouseButtons().withFlags (ModifierKeys::leftButtonModifier);
  203145. }
  203146. else if (isUp)
  203147. {
  203148. currentModifiers = currentModifiers.withoutMouseButtons();
  203149. currentTouches.remove (touchIndex);
  203150. }
  203151. if (isCancel)
  203152. currentTouches.clear();
  203153. handleMouseEvent (touchIndex, pos, currentModifiers, time);
  203154. }
  203155. }
  203156. static UIViewComponentPeer* currentlyFocusedPeer = 0;
  203157. void UIViewComponentPeer::viewFocusGain()
  203158. {
  203159. if (currentlyFocusedPeer != this)
  203160. {
  203161. if (ComponentPeer::isValidPeer (currentlyFocusedPeer))
  203162. currentlyFocusedPeer->handleFocusLoss();
  203163. currentlyFocusedPeer = this;
  203164. handleFocusGain();
  203165. }
  203166. }
  203167. void UIViewComponentPeer::viewFocusLoss()
  203168. {
  203169. if (currentlyFocusedPeer == this)
  203170. {
  203171. currentlyFocusedPeer = 0;
  203172. handleFocusLoss();
  203173. }
  203174. }
  203175. void juce_HandleProcessFocusChange()
  203176. {
  203177. if (UIViewComponentPeer::isValidPeer (currentlyFocusedPeer))
  203178. {
  203179. if (Process::isForegroundProcess())
  203180. {
  203181. currentlyFocusedPeer->handleFocusGain();
  203182. ComponentPeer::bringModalComponentToFront();
  203183. }
  203184. else
  203185. {
  203186. currentlyFocusedPeer->handleFocusLoss();
  203187. // turn kiosk mode off if we lose focus..
  203188. Desktop::getInstance().setKioskModeComponent (0);
  203189. }
  203190. }
  203191. }
  203192. bool UIViewComponentPeer::isFocused() const
  203193. {
  203194. return isSharedWindow ? this == currentlyFocusedPeer
  203195. : (window != 0 && [window isKeyWindow]);
  203196. }
  203197. void UIViewComponentPeer::grabFocus()
  203198. {
  203199. if (window != 0)
  203200. {
  203201. [window makeKeyWindow];
  203202. viewFocusGain();
  203203. }
  203204. }
  203205. void UIViewComponentPeer::textInputRequired (const Point<int>&)
  203206. {
  203207. }
  203208. void UIViewComponentPeer::drawRect (CGRect r)
  203209. {
  203210. if (r.size.width < 1.0f || r.size.height < 1.0f)
  203211. return;
  203212. CGContextRef cg = UIGraphicsGetCurrentContext();
  203213. if (! component->isOpaque())
  203214. CGContextClearRect (cg, CGContextGetClipBoundingBox (cg));
  203215. CGContextConcatCTM (cg, CGAffineTransformMake (1, 0, 0, -1, 0, view.bounds.size.height));
  203216. CoreGraphicsContext g (cg, view.bounds.size.height);
  203217. insideDrawRect = true;
  203218. handlePaint (g);
  203219. insideDrawRect = false;
  203220. }
  203221. bool UIViewComponentPeer::canBecomeKeyWindow()
  203222. {
  203223. return (getStyleFlags() & JUCE_NAMESPACE::ComponentPeer::windowIgnoresKeyPresses) == 0;
  203224. }
  203225. bool UIViewComponentPeer::windowShouldClose()
  203226. {
  203227. if (! isValidPeer (this))
  203228. return YES;
  203229. handleUserClosingWindow();
  203230. return NO;
  203231. }
  203232. void UIViewComponentPeer::redirectMovedOrResized()
  203233. {
  203234. handleMovedOrResized();
  203235. }
  203236. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  203237. {
  203238. }
  203239. class AsyncRepaintMessage : public CallbackMessage
  203240. {
  203241. public:
  203242. UIViewComponentPeer* const peer;
  203243. const Rectangle<int> rect;
  203244. AsyncRepaintMessage (UIViewComponentPeer* const peer_, const Rectangle<int>& rect_)
  203245. : peer (peer_), rect (rect_)
  203246. {
  203247. }
  203248. void messageCallback()
  203249. {
  203250. if (ComponentPeer::isValidPeer (peer))
  203251. peer->repaint (rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
  203252. }
  203253. };
  203254. void UIViewComponentPeer::repaint (int x, int y, int w, int h)
  203255. {
  203256. if (insideDrawRect || ! MessageManager::getInstance()->isThisTheMessageThread())
  203257. {
  203258. (new AsyncRepaintMessage (this, Rectangle<int> (x, y, w, h)))->post();
  203259. }
  203260. else
  203261. {
  203262. [view setNeedsDisplayInRect: CGRectMake ((float) x, (float) y, (float) w, (float) h)];
  203263. }
  203264. }
  203265. void UIViewComponentPeer::performAnyPendingRepaintsNow()
  203266. {
  203267. }
  203268. ComponentPeer* Component::createNewPeer (int styleFlags, void* windowToAttachTo)
  203269. {
  203270. return new UIViewComponentPeer (this, styleFlags, (UIView*) windowToAttachTo);
  203271. }
  203272. Image* juce_createIconForFile (const File& file)
  203273. {
  203274. return 0;
  203275. }
  203276. void Desktop::createMouseInputSources()
  203277. {
  203278. for (int i = 0; i < 10; ++i)
  203279. mouseSources.add (new MouseInputSource (i, false));
  203280. }
  203281. bool Desktop::canUseSemiTransparentWindows() throw()
  203282. {
  203283. return true;
  203284. }
  203285. const Point<int> Desktop::getMousePosition()
  203286. {
  203287. return juce_lastMousePos;
  203288. }
  203289. void Desktop::setMousePosition (const Point<int>&)
  203290. {
  203291. }
  203292. const int KeyPress::spaceKey = ' ';
  203293. const int KeyPress::returnKey = 0x0d;
  203294. const int KeyPress::escapeKey = 0x1b;
  203295. const int KeyPress::backspaceKey = 0x7f;
  203296. const int KeyPress::leftKey = 0x1000;
  203297. const int KeyPress::rightKey = 0x1001;
  203298. const int KeyPress::upKey = 0x1002;
  203299. const int KeyPress::downKey = 0x1003;
  203300. const int KeyPress::pageUpKey = 0x1004;
  203301. const int KeyPress::pageDownKey = 0x1005;
  203302. const int KeyPress::endKey = 0x1006;
  203303. const int KeyPress::homeKey = 0x1007;
  203304. const int KeyPress::deleteKey = 0x1008;
  203305. const int KeyPress::insertKey = -1;
  203306. const int KeyPress::tabKey = 9;
  203307. const int KeyPress::F1Key = 0x2001;
  203308. const int KeyPress::F2Key = 0x2002;
  203309. const int KeyPress::F3Key = 0x2003;
  203310. const int KeyPress::F4Key = 0x2004;
  203311. const int KeyPress::F5Key = 0x2005;
  203312. const int KeyPress::F6Key = 0x2006;
  203313. const int KeyPress::F7Key = 0x2007;
  203314. const int KeyPress::F8Key = 0x2008;
  203315. const int KeyPress::F9Key = 0x2009;
  203316. const int KeyPress::F10Key = 0x200a;
  203317. const int KeyPress::F11Key = 0x200b;
  203318. const int KeyPress::F12Key = 0x200c;
  203319. const int KeyPress::F13Key = 0x200d;
  203320. const int KeyPress::F14Key = 0x200e;
  203321. const int KeyPress::F15Key = 0x200f;
  203322. const int KeyPress::F16Key = 0x2010;
  203323. const int KeyPress::numberPad0 = 0x30020;
  203324. const int KeyPress::numberPad1 = 0x30021;
  203325. const int KeyPress::numberPad2 = 0x30022;
  203326. const int KeyPress::numberPad3 = 0x30023;
  203327. const int KeyPress::numberPad4 = 0x30024;
  203328. const int KeyPress::numberPad5 = 0x30025;
  203329. const int KeyPress::numberPad6 = 0x30026;
  203330. const int KeyPress::numberPad7 = 0x30027;
  203331. const int KeyPress::numberPad8 = 0x30028;
  203332. const int KeyPress::numberPad9 = 0x30029;
  203333. const int KeyPress::numberPadAdd = 0x3002a;
  203334. const int KeyPress::numberPadSubtract = 0x3002b;
  203335. const int KeyPress::numberPadMultiply = 0x3002c;
  203336. const int KeyPress::numberPadDivide = 0x3002d;
  203337. const int KeyPress::numberPadSeparator = 0x3002e;
  203338. const int KeyPress::numberPadDecimalPoint = 0x3002f;
  203339. const int KeyPress::numberPadEquals = 0x30030;
  203340. const int KeyPress::numberPadDelete = 0x30031;
  203341. const int KeyPress::playKey = 0x30000;
  203342. const int KeyPress::stopKey = 0x30001;
  203343. const int KeyPress::fastForwardKey = 0x30002;
  203344. const int KeyPress::rewindKey = 0x30003;
  203345. #endif
  203346. /*** End of inlined file: juce_iphone_UIViewComponentPeer.mm ***/
  203347. /*** Start of inlined file: juce_iphone_MessageManager.mm ***/
  203348. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203349. // compiled on its own).
  203350. #if JUCE_INCLUDED_FILE
  203351. struct CallbackMessagePayload
  203352. {
  203353. MessageCallbackFunction* function;
  203354. void* parameter;
  203355. void* volatile result;
  203356. bool volatile hasBeenExecuted;
  203357. };
  203358. END_JUCE_NAMESPACE
  203359. using namespace JUCE_NAMESPACE;
  203360. @interface JuceAppDelegate : NSObject <UIApplicationDelegate>
  203361. {
  203362. }
  203363. - (JuceAppDelegate*) init;
  203364. - (void) dealloc;
  203365. - (BOOL) application: (UIApplication*) application handleOpenURL: (NSURL*) url;
  203366. - (void) applicationDidBecomeActive: (NSNotification*) aNotification;
  203367. - (void) applicationDidResignActive: (NSNotification*) aNotification;
  203368. - (void) applicationWillUnhide: (NSNotification*) aNotification;
  203369. - (void) customEvent: (id) data;
  203370. - (void) performCallback: (id) info;
  203371. @end
  203372. @implementation JuceAppDelegate
  203373. - (JuceAppDelegate*) init
  203374. {
  203375. [super init];
  203376. [[UIApplication sharedApplication] setDelegate: self];
  203377. return self;
  203378. }
  203379. - (void) dealloc
  203380. {
  203381. [[UIApplication sharedApplication] setDelegate: nil];
  203382. [super dealloc];
  203383. }
  203384. - (BOOL) application: (UIApplication*) application handleOpenURL: (NSURL*) url
  203385. {
  203386. if (JUCEApplication::getInstance() != 0)
  203387. {
  203388. JUCEApplication::getInstance()->anotherInstanceStarted (nsStringToJuce ([url absoluteString]));
  203389. return YES;
  203390. }
  203391. return NO;
  203392. }
  203393. - (void) applicationDidBecomeActive: (NSNotification*) aNotification
  203394. {
  203395. juce_HandleProcessFocusChange();
  203396. }
  203397. - (void) applicationDidResignActive: (NSNotification*) aNotification
  203398. {
  203399. juce_HandleProcessFocusChange();
  203400. }
  203401. - (void) applicationWillUnhide: (NSNotification*) aNotification
  203402. {
  203403. juce_HandleProcessFocusChange();
  203404. }
  203405. - (void) customEvent: (id) n
  203406. {
  203407. NSData* data = (NSData*) n;
  203408. void* message = 0;
  203409. [data getBytes: &message length: sizeof (message)];
  203410. [data release];
  203411. if (message != 0)
  203412. MessageManager::getInstance()->deliverMessage (message);
  203413. }
  203414. - (void) performCallback: (id) info
  203415. {
  203416. if ([info isKindOfClass: [NSData class]])
  203417. {
  203418. CallbackMessagePayload* pl = (CallbackMessagePayload*) [((NSData*) info) bytes];
  203419. if (pl != 0)
  203420. {
  203421. pl->result = (*pl->function) (pl->parameter);
  203422. pl->hasBeenExecuted = true;
  203423. }
  203424. }
  203425. else
  203426. {
  203427. jassertfalse // should never get here!
  203428. }
  203429. }
  203430. @end
  203431. BEGIN_JUCE_NAMESPACE
  203432. static JuceAppDelegate* juceAppDelegate = 0;
  203433. void MessageManager::runDispatchLoop()
  203434. {
  203435. jassert (isThisTheMessageThread()); // must only be called by the message thread
  203436. runDispatchLoopUntil (-1);
  203437. }
  203438. void MessageManager::stopDispatchLoop()
  203439. {
  203440. exit (0); // iPhone apps get no mercy..
  203441. }
  203442. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  203443. {
  203444. const ScopedAutoReleasePool pool;
  203445. jassert (isThisTheMessageThread()); // must only be called by the message thread
  203446. uint32 endTime = Time::getMillisecondCounter() + millisecondsToRunFor;
  203447. NSDate* endDate = [NSDate dateWithTimeIntervalSinceNow: millisecondsToRunFor * 0.001];
  203448. while (! quitMessagePosted)
  203449. {
  203450. const ScopedAutoReleasePool pool;
  203451. [[NSRunLoop currentRunLoop] runMode: NSDefaultRunLoopMode
  203452. beforeDate: endDate];
  203453. if (millisecondsToRunFor >= 0 && Time::getMillisecondCounter() >= endTime)
  203454. break;
  203455. }
  203456. return ! quitMessagePosted;
  203457. }
  203458. static CFRunLoopRef runLoop = 0;
  203459. static CFRunLoopSourceRef runLoopSource = 0;
  203460. static Array <void*, CriticalSection>* pendingMessages = 0;
  203461. static void runLoopSourceCallback (void*)
  203462. {
  203463. if (pendingMessages != 0)
  203464. {
  203465. int numDispatched = 0;
  203466. do
  203467. {
  203468. void* const nextMessage = pendingMessages->remove (0);
  203469. if (nextMessage == 0)
  203470. return;
  203471. const ScopedAutoReleasePool pool;
  203472. MessageManager::getInstance()->deliverMessage (nextMessage);
  203473. } while (++numDispatched <= 4);
  203474. CFRunLoopSourceSignal (runLoopSource);
  203475. CFRunLoopWakeUp (runLoop);
  203476. }
  203477. }
  203478. void MessageManager::doPlatformSpecificInitialisation()
  203479. {
  203480. pendingMessages = new Array <void*, CriticalSection>();
  203481. runLoop = CFRunLoopGetCurrent();
  203482. CFRunLoopSourceContext sourceContext;
  203483. zerostruct (sourceContext);
  203484. sourceContext.perform = runLoopSourceCallback;
  203485. runLoopSource = CFRunLoopSourceCreate (kCFAllocatorDefault, 1, &sourceContext);
  203486. CFRunLoopAddSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
  203487. if (juceAppDelegate == 0)
  203488. juceAppDelegate = [[JuceAppDelegate alloc] init];
  203489. }
  203490. void MessageManager::doPlatformSpecificShutdown()
  203491. {
  203492. CFRunLoopSourceInvalidate (runLoopSource);
  203493. CFRelease (runLoopSource);
  203494. runLoopSource = 0;
  203495. if (pendingMessages != 0)
  203496. {
  203497. while (pendingMessages->size() > 0)
  203498. delete ((Message*) pendingMessages->remove(0));
  203499. deleteAndZero (pendingMessages);
  203500. }
  203501. if (juceAppDelegate != 0)
  203502. {
  203503. [[NSRunLoop currentRunLoop] cancelPerformSelectorsWithTarget: juceAppDelegate];
  203504. [juceAppDelegate release];
  203505. juceAppDelegate = 0;
  203506. }
  203507. }
  203508. bool juce_postMessageToSystemQueue (void* message)
  203509. {
  203510. if (pendingMessages != 0)
  203511. {
  203512. pendingMessages->add (message);
  203513. CFRunLoopSourceSignal (runLoopSource);
  203514. CFRunLoopWakeUp (runLoop);
  203515. }
  203516. return true;
  203517. }
  203518. void MessageManager::broadcastMessage (const String& value) throw()
  203519. {
  203520. }
  203521. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
  203522. void* data)
  203523. {
  203524. if (isThisTheMessageThread())
  203525. {
  203526. return (*callback) (data);
  203527. }
  203528. else
  203529. {
  203530. // If a thread has a MessageManagerLock and then tries to call this method, it'll
  203531. // deadlock because the message manager is blocked from running, so can never
  203532. // call your function..
  203533. jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  203534. const ScopedAutoReleasePool pool;
  203535. CallbackMessagePayload cmp;
  203536. cmp.function = callback;
  203537. cmp.parameter = data;
  203538. cmp.result = 0;
  203539. cmp.hasBeenExecuted = false;
  203540. [juceAppDelegate performSelectorOnMainThread: @selector (performCallback:)
  203541. withObject: [NSData dataWithBytesNoCopy: &cmp
  203542. length: sizeof (cmp)
  203543. freeWhenDone: NO]
  203544. waitUntilDone: YES];
  203545. return cmp.result;
  203546. }
  203547. }
  203548. #endif
  203549. /*** End of inlined file: juce_iphone_MessageManager.mm ***/
  203550. /*** Start of inlined file: juce_mac_FileChooser.mm ***/
  203551. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203552. // compiled on its own).
  203553. #if JUCE_INCLUDED_FILE
  203554. #if JUCE_MAC
  203555. END_JUCE_NAMESPACE
  203556. using namespace JUCE_NAMESPACE;
  203557. #define JuceFileChooserDelegate MakeObjCClassName(JuceFileChooserDelegate)
  203558. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  203559. @interface JuceFileChooserDelegate : NSObject <NSOpenSavePanelDelegate>
  203560. #else
  203561. @interface JuceFileChooserDelegate : NSObject
  203562. #endif
  203563. {
  203564. StringArray* filters;
  203565. }
  203566. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_;
  203567. - (void) dealloc;
  203568. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename;
  203569. @end
  203570. @implementation JuceFileChooserDelegate
  203571. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_
  203572. {
  203573. [super init];
  203574. filters = filters_;
  203575. return self;
  203576. }
  203577. - (void) dealloc
  203578. {
  203579. delete filters;
  203580. [super dealloc];
  203581. }
  203582. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename
  203583. {
  203584. const File f (nsStringToJuce (filename));
  203585. for (int i = filters->size(); --i >= 0;)
  203586. if (f.getFileName().matchesWildcard ((*filters)[i], true))
  203587. return true;
  203588. return f.isDirectory();
  203589. }
  203590. @end
  203591. BEGIN_JUCE_NAMESPACE
  203592. void FileChooser::showPlatformDialog (Array<File>& results,
  203593. const String& title,
  203594. const File& currentFileOrDirectory,
  203595. const String& filter,
  203596. bool selectsDirectory,
  203597. bool selectsFiles,
  203598. bool isSaveDialogue,
  203599. bool warnAboutOverwritingExistingFiles,
  203600. bool selectMultipleFiles,
  203601. FilePreviewComponent* extraInfoComponent)
  203602. {
  203603. const ScopedAutoReleasePool pool;
  203604. StringArray* filters = new StringArray();
  203605. filters->addTokens (filter.replaceCharacters (T(",:"), T(";;")), T(";"), String::empty);
  203606. filters->trim();
  203607. filters->removeEmptyStrings();
  203608. JuceFileChooserDelegate* delegate = [[JuceFileChooserDelegate alloc] initWithFilters: filters];
  203609. [delegate autorelease];
  203610. NSSavePanel* panel = isSaveDialogue ? [NSSavePanel savePanel]
  203611. : [NSOpenPanel openPanel];
  203612. [panel setTitle: juceStringToNS (title)];
  203613. if (! isSaveDialogue)
  203614. {
  203615. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  203616. [openPanel setCanChooseDirectories: selectsDirectory];
  203617. [openPanel setCanChooseFiles: selectsFiles];
  203618. [openPanel setAllowsMultipleSelection: selectMultipleFiles];
  203619. }
  203620. [panel setDelegate: delegate];
  203621. if (isSaveDialogue || selectsDirectory)
  203622. [panel setCanCreateDirectories: YES];
  203623. String directory, filename;
  203624. if (currentFileOrDirectory.isDirectory())
  203625. {
  203626. directory = currentFileOrDirectory.getFullPathName();
  203627. }
  203628. else
  203629. {
  203630. directory = currentFileOrDirectory.getParentDirectory().getFullPathName();
  203631. filename = currentFileOrDirectory.getFileName();
  203632. }
  203633. if ([panel runModalForDirectory: juceStringToNS (directory)
  203634. file: juceStringToNS (filename)]
  203635. == NSOKButton)
  203636. {
  203637. if (isSaveDialogue)
  203638. {
  203639. results.add (File (nsStringToJuce ([panel filename])));
  203640. }
  203641. else
  203642. {
  203643. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  203644. NSArray* urls = [openPanel filenames];
  203645. for (unsigned int i = 0; i < [urls count]; ++i)
  203646. {
  203647. NSString* f = [urls objectAtIndex: i];
  203648. results.add (File (nsStringToJuce (f)));
  203649. }
  203650. }
  203651. }
  203652. [panel setDelegate: nil];
  203653. }
  203654. #else
  203655. void FileChooser::showPlatformDialog (Array<File>& results,
  203656. const String& title,
  203657. const File& currentFileOrDirectory,
  203658. const String& filter,
  203659. bool selectsDirectory,
  203660. bool selectsFiles,
  203661. bool isSaveDialogue,
  203662. bool warnAboutOverwritingExistingFiles,
  203663. bool selectMultipleFiles,
  203664. FilePreviewComponent* extraInfoComponent)
  203665. {
  203666. const ScopedAutoReleasePool pool;
  203667. jassertfalse //xxx to do
  203668. }
  203669. #endif
  203670. #endif
  203671. /*** End of inlined file: juce_mac_FileChooser.mm ***/
  203672. /*** Start of inlined file: juce_mac_OpenGLComponent.mm ***/
  203673. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203674. // compiled on its own).
  203675. #if JUCE_INCLUDED_FILE && JUCE_OPENGL
  203676. #if JUCE_MAC
  203677. END_JUCE_NAMESPACE
  203678. #define ThreadSafeNSOpenGLView MakeObjCClassName(ThreadSafeNSOpenGLView)
  203679. @interface ThreadSafeNSOpenGLView : NSOpenGLView
  203680. {
  203681. CriticalSection* contextLock;
  203682. bool needsUpdate;
  203683. }
  203684. - (id) initWithFrame: (NSRect) frameRect pixelFormat: (NSOpenGLPixelFormat*) format;
  203685. - (bool) makeActive;
  203686. - (void) makeInactive;
  203687. - (void) reshape;
  203688. @end
  203689. @implementation ThreadSafeNSOpenGLView
  203690. - (id) initWithFrame: (NSRect) frameRect
  203691. pixelFormat: (NSOpenGLPixelFormat*) format
  203692. {
  203693. contextLock = new CriticalSection();
  203694. self = [super initWithFrame: frameRect pixelFormat: format];
  203695. if (self != nil)
  203696. [[NSNotificationCenter defaultCenter] addObserver: self
  203697. selector: @selector (_surfaceNeedsUpdate:)
  203698. name: NSViewGlobalFrameDidChangeNotification
  203699. object: self];
  203700. return self;
  203701. }
  203702. - (void) dealloc
  203703. {
  203704. [[NSNotificationCenter defaultCenter] removeObserver: self];
  203705. delete contextLock;
  203706. [super dealloc];
  203707. }
  203708. - (bool) makeActive
  203709. {
  203710. const ScopedLock sl (*contextLock);
  203711. if ([self openGLContext] == 0)
  203712. return false;
  203713. [[self openGLContext] makeCurrentContext];
  203714. if (needsUpdate)
  203715. {
  203716. [super update];
  203717. needsUpdate = false;
  203718. }
  203719. return true;
  203720. }
  203721. - (void) makeInactive
  203722. {
  203723. const ScopedLock sl (*contextLock);
  203724. [NSOpenGLContext clearCurrentContext];
  203725. }
  203726. - (void) _surfaceNeedsUpdate: (NSNotification*) notification
  203727. {
  203728. const ScopedLock sl (*contextLock);
  203729. needsUpdate = true;
  203730. }
  203731. - (void) update
  203732. {
  203733. const ScopedLock sl (*contextLock);
  203734. needsUpdate = true;
  203735. }
  203736. - (void) reshape
  203737. {
  203738. const ScopedLock sl (*contextLock);
  203739. needsUpdate = true;
  203740. }
  203741. @end
  203742. BEGIN_JUCE_NAMESPACE
  203743. class WindowedGLContext : public OpenGLContext
  203744. {
  203745. public:
  203746. WindowedGLContext (Component* const component,
  203747. const OpenGLPixelFormat& pixelFormat_,
  203748. NSOpenGLContext* sharedContext)
  203749. : renderContext (0),
  203750. pixelFormat (pixelFormat_)
  203751. {
  203752. jassert (component != 0);
  203753. NSOpenGLPixelFormatAttribute attribs [64];
  203754. int n = 0;
  203755. attribs[n++] = NSOpenGLPFADoubleBuffer;
  203756. attribs[n++] = NSOpenGLPFAAccelerated;
  203757. attribs[n++] = NSOpenGLPFAMPSafe; // NSOpenGLPFAAccelerated, NSOpenGLPFAMultiScreen, NSOpenGLPFASingleRenderer
  203758. attribs[n++] = NSOpenGLPFAColorSize;
  203759. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.redBits,
  203760. pixelFormat.greenBits,
  203761. pixelFormat.blueBits);
  203762. attribs[n++] = NSOpenGLPFAAlphaSize;
  203763. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.alphaBits;
  203764. attribs[n++] = NSOpenGLPFADepthSize;
  203765. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.depthBufferBits;
  203766. attribs[n++] = NSOpenGLPFAStencilSize;
  203767. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.stencilBufferBits;
  203768. attribs[n++] = NSOpenGLPFAAccumSize;
  203769. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.accumulationBufferRedBits,
  203770. pixelFormat.accumulationBufferGreenBits,
  203771. pixelFormat.accumulationBufferBlueBits,
  203772. pixelFormat.accumulationBufferAlphaBits);
  203773. // xxx not sure how to do fullSceneAntiAliasingNumSamples..
  203774. attribs[n++] = NSOpenGLPFASampleBuffers;
  203775. attribs[n++] = (NSOpenGLPixelFormatAttribute) 1;
  203776. attribs[n++] = NSOpenGLPFAClosestPolicy;
  203777. attribs[n++] = NSOpenGLPFANoRecovery;
  203778. attribs[n++] = (NSOpenGLPixelFormatAttribute) 0;
  203779. NSOpenGLPixelFormat* format
  203780. = [[NSOpenGLPixelFormat alloc] initWithAttributes: attribs];
  203781. view = [[ThreadSafeNSOpenGLView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  203782. pixelFormat: format];
  203783. renderContext = [[[NSOpenGLContext alloc] initWithFormat: format
  203784. shareContext: sharedContext] autorelease];
  203785. const GLint swapInterval = 1;
  203786. [renderContext setValues: &swapInterval forParameter: NSOpenGLCPSwapInterval];
  203787. [view setOpenGLContext: renderContext];
  203788. [renderContext setView: view];
  203789. [format release];
  203790. viewHolder = new NSViewComponentInternal (view, component);
  203791. }
  203792. ~WindowedGLContext()
  203793. {
  203794. makeInactive();
  203795. [renderContext clearDrawable];
  203796. viewHolder = 0;
  203797. }
  203798. bool makeActive() const throw()
  203799. {
  203800. jassert (renderContext != 0);
  203801. [view makeActive];
  203802. return isActive();
  203803. }
  203804. bool makeInactive() const throw()
  203805. {
  203806. [view makeInactive];
  203807. return true;
  203808. }
  203809. bool isActive() const throw()
  203810. {
  203811. return [NSOpenGLContext currentContext] == renderContext;
  203812. }
  203813. const OpenGLPixelFormat getPixelFormat() const { return pixelFormat; }
  203814. void* getRawContext() const throw() { return renderContext; }
  203815. void updateWindowPosition (int x, int y, int w, int h, int outerWindowHeight)
  203816. {
  203817. }
  203818. void swapBuffers()
  203819. {
  203820. [renderContext flushBuffer];
  203821. }
  203822. bool setSwapInterval (const int numFramesPerSwap)
  203823. {
  203824. [renderContext setValues: (const GLint*) &numFramesPerSwap
  203825. forParameter: NSOpenGLCPSwapInterval];
  203826. return true;
  203827. }
  203828. int getSwapInterval() const
  203829. {
  203830. GLint numFrames = 0;
  203831. [renderContext getValues: &numFrames
  203832. forParameter: NSOpenGLCPSwapInterval];
  203833. return numFrames;
  203834. }
  203835. void repaint()
  203836. {
  203837. // we need to invalidate the juce view that holds this gl view, to make it
  203838. // cause a repaint callback
  203839. NSView* v = (NSView*) viewHolder->view;
  203840. NSRect r = [v frame];
  203841. // bit of a bodge here.. if we only invalidate the area of the gl component,
  203842. // it's completely covered by the NSOpenGLView, so the OS throws away the
  203843. // repaint message, thus never causing our paint() callback, and never repainting
  203844. // the comp. So invalidating just a little bit around the edge helps..
  203845. [[v superview] setNeedsDisplayInRect: NSInsetRect (r, -2.0f, -2.0f)];
  203846. }
  203847. void* getNativeWindowHandle() const { return viewHolder->view; }
  203848. juce_UseDebuggingNewOperator
  203849. NSOpenGLContext* renderContext;
  203850. ThreadSafeNSOpenGLView* view;
  203851. private:
  203852. OpenGLPixelFormat pixelFormat;
  203853. ScopedPointer <NSViewComponentInternal> viewHolder;
  203854. WindowedGLContext (const WindowedGLContext&);
  203855. WindowedGLContext& operator= (const WindowedGLContext&);
  203856. };
  203857. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  203858. const OpenGLPixelFormat& pixelFormat,
  203859. const OpenGLContext* const contextToShareWith)
  203860. {
  203861. ScopedPointer <WindowedGLContext> c (new WindowedGLContext (component, pixelFormat,
  203862. contextToShareWith != 0 ? (NSOpenGLContext*) contextToShareWith->getRawContext() : 0));
  203863. return (c->renderContext != 0) ? c.release() : 0;
  203864. }
  203865. void* OpenGLComponent::getNativeWindowHandle() const
  203866. {
  203867. return context != 0 ? ((WindowedGLContext*) context)->getNativeWindowHandle()
  203868. : 0;
  203869. }
  203870. void juce_glViewport (const int w, const int h)
  203871. {
  203872. glViewport (0, 0, w, h);
  203873. }
  203874. void OpenGLPixelFormat::getAvailablePixelFormats (Component* /*component*/,
  203875. OwnedArray <OpenGLPixelFormat>& results)
  203876. {
  203877. /* GLint attribs [64];
  203878. int n = 0;
  203879. attribs[n++] = AGL_RGBA;
  203880. attribs[n++] = AGL_DOUBLEBUFFER;
  203881. attribs[n++] = AGL_ACCELERATED;
  203882. attribs[n++] = AGL_NO_RECOVERY;
  203883. attribs[n++] = AGL_NONE;
  203884. AGLPixelFormat p = aglChoosePixelFormat (0, 0, attribs);
  203885. while (p != 0)
  203886. {
  203887. OpenGLPixelFormat* const pf = new OpenGLPixelFormat();
  203888. pf->redBits = getAGLAttribute (p, AGL_RED_SIZE);
  203889. pf->greenBits = getAGLAttribute (p, AGL_GREEN_SIZE);
  203890. pf->blueBits = getAGLAttribute (p, AGL_BLUE_SIZE);
  203891. pf->alphaBits = getAGLAttribute (p, AGL_ALPHA_SIZE);
  203892. pf->depthBufferBits = getAGLAttribute (p, AGL_DEPTH_SIZE);
  203893. pf->stencilBufferBits = getAGLAttribute (p, AGL_STENCIL_SIZE);
  203894. pf->accumulationBufferRedBits = getAGLAttribute (p, AGL_ACCUM_RED_SIZE);
  203895. pf->accumulationBufferGreenBits = getAGLAttribute (p, AGL_ACCUM_GREEN_SIZE);
  203896. pf->accumulationBufferBlueBits = getAGLAttribute (p, AGL_ACCUM_BLUE_SIZE);
  203897. pf->accumulationBufferAlphaBits = getAGLAttribute (p, AGL_ACCUM_ALPHA_SIZE);
  203898. results.add (pf);
  203899. p = aglNextPixelFormat (p);
  203900. }*/
  203901. //jassertfalse //xxx can't see how you do this in cocoa!
  203902. }
  203903. #else
  203904. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  203905. const OpenGLPixelFormat& pixelFormat,
  203906. const OpenGLContext* const contextToShareWith)
  203907. {
  203908. return 0;
  203909. }
  203910. void juce_glViewport (const int w, const int h)
  203911. {
  203912. //glViewport (0, 0, w, h);
  203913. }
  203914. #endif
  203915. #endif
  203916. /*** End of inlined file: juce_mac_OpenGLComponent.mm ***/
  203917. /*** Start of inlined file: juce_mac_MouseCursor.mm ***/
  203918. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203919. // compiled on its own).
  203920. #if JUCE_INCLUDED_FILE
  203921. #if JUCE_MAC
  203922. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  203923. {
  203924. NSImage* im = CoreGraphicsImage::createNSImage (image);
  203925. NSCursor* c = [[NSCursor alloc] initWithImage: im
  203926. hotSpot: NSMakePoint (hotspotX, hotspotY)];
  203927. [im release];
  203928. return (void*) c;
  203929. }
  203930. static void* juce_cursorFromData (const unsigned char* data, const size_t size, float hx, float hy) throw()
  203931. {
  203932. ScopedPointer <Image> im (ImageFileFormat::loadFrom ((const char*) data, (int) size));
  203933. jassert (im != 0);
  203934. if (im == 0)
  203935. return 0;
  203936. return juce_createMouseCursorFromImage (*im,
  203937. (int) (hx * im->getWidth()),
  203938. (int) (hy * im->getHeight()));
  203939. }
  203940. static void* juce_cursorFromWebKitFile (const char* filename, float hx, float hy)
  203941. {
  203942. File f ("/System/Library/Frameworks/WebKit.framework/Frameworks/WebCore.framework/Resources");
  203943. MemoryBlock mb;
  203944. if (f.getChildFile (filename).loadFileAsData (mb))
  203945. return juce_cursorFromData ((const unsigned char*) mb.getData(), mb.getSize(), hx, hy);
  203946. return 0;
  203947. }
  203948. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  203949. {
  203950. const ScopedAutoReleasePool pool;
  203951. NSCursor* c = 0;
  203952. switch (type)
  203953. {
  203954. case MouseCursor::NormalCursor:
  203955. c = [NSCursor arrowCursor];
  203956. break;
  203957. case MouseCursor::NoCursor:
  203958. {
  203959. Image blank (Image::ARGB, 8, 8, true);
  203960. return juce_createMouseCursorFromImage (blank, 0, 0);
  203961. }
  203962. case MouseCursor::DraggingHandCursor:
  203963. c = [NSCursor openHandCursor];
  203964. break;
  203965. case MouseCursor::CopyingCursor:
  203966. return juce_cursorFromWebKitFile ("copyCursor.png", 0, 0);
  203967. case MouseCursor::WaitCursor:
  203968. c = [NSCursor arrowCursor]; // avoid this on the mac, let the OS provide the beachball
  203969. break;
  203970. //return juce_cursorFromWebKitFile ("waitCursor.png", 0.5f, 0.5f);
  203971. case MouseCursor::IBeamCursor:
  203972. c = [NSCursor IBeamCursor];
  203973. break;
  203974. case MouseCursor::PointingHandCursor:
  203975. c = [NSCursor pointingHandCursor];
  203976. break;
  203977. case MouseCursor::LeftRightResizeCursor:
  203978. c = [NSCursor resizeLeftRightCursor];
  203979. break;
  203980. case MouseCursor::LeftEdgeResizeCursor:
  203981. c = [NSCursor resizeLeftCursor];
  203982. break;
  203983. case MouseCursor::RightEdgeResizeCursor:
  203984. c = [NSCursor resizeRightCursor];
  203985. break;
  203986. case MouseCursor::UpDownResizeCursor:
  203987. case MouseCursor::TopEdgeResizeCursor:
  203988. case MouseCursor::BottomEdgeResizeCursor:
  203989. return juce_cursorFromWebKitFile ("northSouthResizeCursor.png", 0.5f, 0.5f);
  203990. case MouseCursor::TopLeftCornerResizeCursor:
  203991. case MouseCursor::BottomRightCornerResizeCursor:
  203992. return juce_cursorFromWebKitFile ("northWestSouthEastResizeCursor.png", 0.5f, 0.5f);
  203993. case MouseCursor::TopRightCornerResizeCursor:
  203994. case MouseCursor::BottomLeftCornerResizeCursor:
  203995. return juce_cursorFromWebKitFile ("northEastSouthWestResizeCursor.png", 0.5f, 0.5f);
  203996. case MouseCursor::UpDownLeftRightResizeCursor:
  203997. return juce_cursorFromWebKitFile ("moveCursor.png", 0.5f, 0.5f);
  203998. case MouseCursor::CrosshairCursor:
  203999. c = [NSCursor crosshairCursor];
  204000. break;
  204001. }
  204002. [c retain];
  204003. return (void*) c;
  204004. }
  204005. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw()
  204006. {
  204007. NSCursor* c = (NSCursor*) cursorHandle;
  204008. [c release];
  204009. }
  204010. void MouseCursor::showInAllWindows() const throw()
  204011. {
  204012. showInWindow (0);
  204013. }
  204014. void MouseCursor::showInWindow (ComponentPeer*) const throw()
  204015. {
  204016. NSCursor* const c = (NSCursor*) getHandle();
  204017. [c set];
  204018. }
  204019. #else
  204020. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw() { return 0; }
  204021. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw() { return 0; }
  204022. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw() {}
  204023. void MouseCursor::showInAllWindows() const throw() {}
  204024. void MouseCursor::showInWindow (ComponentPeer*) const throw() {}
  204025. #endif
  204026. #endif
  204027. /*** End of inlined file: juce_mac_MouseCursor.mm ***/
  204028. /*** Start of inlined file: juce_mac_WebBrowserComponent.mm ***/
  204029. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204030. // compiled on its own).
  204031. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  204032. #if JUCE_MAC
  204033. END_JUCE_NAMESPACE
  204034. #define DownloadClickDetector MakeObjCClassName(DownloadClickDetector)
  204035. @interface DownloadClickDetector : NSObject
  204036. {
  204037. JUCE_NAMESPACE::WebBrowserComponent* ownerComponent;
  204038. }
  204039. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent;
  204040. - (void) webView: (WebView*) webView decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  204041. request: (NSURLRequest*) request
  204042. frame: (WebFrame*) frame
  204043. decisionListener: (id<WebPolicyDecisionListener>) listener;
  204044. @end
  204045. @implementation DownloadClickDetector
  204046. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent_
  204047. {
  204048. [super init];
  204049. ownerComponent = ownerComponent_;
  204050. return self;
  204051. }
  204052. - (void) webView: (WebView*) sender decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  204053. request: (NSURLRequest*) request
  204054. frame: (WebFrame*) frame
  204055. decisionListener: (id <WebPolicyDecisionListener>) listener
  204056. {
  204057. NSURL* url = [actionInformation valueForKey: @"WebActionOriginalURLKey"];
  204058. if (ownerComponent->pageAboutToLoad (nsStringToJuce ([url absoluteString])))
  204059. [listener use];
  204060. else
  204061. [listener ignore];
  204062. }
  204063. @end
  204064. BEGIN_JUCE_NAMESPACE
  204065. class WebBrowserComponentInternal : public NSViewComponent
  204066. {
  204067. public:
  204068. WebBrowserComponentInternal (WebBrowserComponent* owner)
  204069. {
  204070. webView = [[WebView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  204071. frameName: @""
  204072. groupName: @""];
  204073. setView (webView);
  204074. clickListener = [[DownloadClickDetector alloc] initWithWebBrowserOwner: owner];
  204075. [webView setPolicyDelegate: clickListener];
  204076. }
  204077. ~WebBrowserComponentInternal()
  204078. {
  204079. [webView setPolicyDelegate: nil];
  204080. [clickListener release];
  204081. setView (0);
  204082. }
  204083. void goToURL (const String& url,
  204084. const StringArray* headers,
  204085. const MemoryBlock* postData)
  204086. {
  204087. NSMutableURLRequest* r
  204088. = [NSMutableURLRequest requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
  204089. cachePolicy: NSURLRequestUseProtocolCachePolicy
  204090. timeoutInterval: 30.0];
  204091. if (postData != 0 && postData->getSize() > 0)
  204092. {
  204093. [r setHTTPMethod: @"POST"];
  204094. [r setHTTPBody: [NSData dataWithBytes: postData->getData()
  204095. length: postData->getSize()]];
  204096. }
  204097. if (headers != 0)
  204098. {
  204099. for (int i = 0; i < headers->size(); ++i)
  204100. {
  204101. const String headerName ((*headers)[i].upToFirstOccurrenceOf (T(":"), false, false).trim());
  204102. const String headerValue ((*headers)[i].fromFirstOccurrenceOf (T(":"), false, false).trim());
  204103. [r setValue: juceStringToNS (headerValue)
  204104. forHTTPHeaderField: juceStringToNS (headerName)];
  204105. }
  204106. }
  204107. stop();
  204108. [[webView mainFrame] loadRequest: r];
  204109. }
  204110. void goBack()
  204111. {
  204112. [webView goBack];
  204113. }
  204114. void goForward()
  204115. {
  204116. [webView goForward];
  204117. }
  204118. void stop()
  204119. {
  204120. [webView stopLoading: nil];
  204121. }
  204122. void refresh()
  204123. {
  204124. [webView reload: nil];
  204125. }
  204126. private:
  204127. WebView* webView;
  204128. DownloadClickDetector* clickListener;
  204129. };
  204130. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  204131. : browser (0),
  204132. blankPageShown (false),
  204133. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  204134. {
  204135. setOpaque (true);
  204136. addAndMakeVisible (browser = new WebBrowserComponentInternal (this));
  204137. }
  204138. WebBrowserComponent::~WebBrowserComponent()
  204139. {
  204140. deleteAndZero (browser);
  204141. }
  204142. void WebBrowserComponent::goToURL (const String& url,
  204143. const StringArray* headers,
  204144. const MemoryBlock* postData)
  204145. {
  204146. lastURL = url;
  204147. lastHeaders.clear();
  204148. if (headers != 0)
  204149. lastHeaders = *headers;
  204150. lastPostData.setSize (0);
  204151. if (postData != 0)
  204152. lastPostData = *postData;
  204153. blankPageShown = false;
  204154. browser->goToURL (url, headers, postData);
  204155. }
  204156. void WebBrowserComponent::stop()
  204157. {
  204158. browser->stop();
  204159. }
  204160. void WebBrowserComponent::goBack()
  204161. {
  204162. lastURL = String::empty;
  204163. blankPageShown = false;
  204164. browser->goBack();
  204165. }
  204166. void WebBrowserComponent::goForward()
  204167. {
  204168. lastURL = String::empty;
  204169. browser->goForward();
  204170. }
  204171. void WebBrowserComponent::refresh()
  204172. {
  204173. browser->refresh();
  204174. }
  204175. void WebBrowserComponent::paint (Graphics& g)
  204176. {
  204177. }
  204178. void WebBrowserComponent::checkWindowAssociation()
  204179. {
  204180. if (isShowing())
  204181. {
  204182. if (blankPageShown)
  204183. goBack();
  204184. }
  204185. else
  204186. {
  204187. if (unloadPageWhenBrowserIsHidden && ! blankPageShown)
  204188. {
  204189. // when the component becomes invisible, some stuff like flash
  204190. // carries on playing audio, so we need to force it onto a blank
  204191. // page to avoid this, (and send it back when it's made visible again).
  204192. blankPageShown = true;
  204193. browser->goToURL ("about:blank", 0, 0);
  204194. }
  204195. }
  204196. }
  204197. void WebBrowserComponent::reloadLastURL()
  204198. {
  204199. if (lastURL.isNotEmpty())
  204200. {
  204201. goToURL (lastURL, &lastHeaders, &lastPostData);
  204202. lastURL = String::empty;
  204203. }
  204204. }
  204205. void WebBrowserComponent::parentHierarchyChanged()
  204206. {
  204207. checkWindowAssociation();
  204208. }
  204209. void WebBrowserComponent::resized()
  204210. {
  204211. browser->setSize (getWidth(), getHeight());
  204212. }
  204213. void WebBrowserComponent::visibilityChanged()
  204214. {
  204215. checkWindowAssociation();
  204216. }
  204217. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  204218. {
  204219. return true;
  204220. }
  204221. #else
  204222. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  204223. {
  204224. }
  204225. WebBrowserComponent::~WebBrowserComponent()
  204226. {
  204227. }
  204228. void WebBrowserComponent::goToURL (const String& url,
  204229. const StringArray* headers,
  204230. const MemoryBlock* postData)
  204231. {
  204232. }
  204233. void WebBrowserComponent::stop()
  204234. {
  204235. }
  204236. void WebBrowserComponent::goBack()
  204237. {
  204238. }
  204239. void WebBrowserComponent::goForward()
  204240. {
  204241. }
  204242. void WebBrowserComponent::refresh()
  204243. {
  204244. }
  204245. void WebBrowserComponent::paint (Graphics& g)
  204246. {
  204247. }
  204248. void WebBrowserComponent::checkWindowAssociation()
  204249. {
  204250. }
  204251. void WebBrowserComponent::reloadLastURL()
  204252. {
  204253. }
  204254. void WebBrowserComponent::parentHierarchyChanged()
  204255. {
  204256. }
  204257. void WebBrowserComponent::resized()
  204258. {
  204259. }
  204260. void WebBrowserComponent::visibilityChanged()
  204261. {
  204262. }
  204263. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  204264. {
  204265. return true;
  204266. }
  204267. #endif
  204268. #endif
  204269. /*** End of inlined file: juce_mac_WebBrowserComponent.mm ***/
  204270. /*** Start of inlined file: juce_iphone_Audio.cpp ***/
  204271. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204272. // compiled on its own).
  204273. #if JUCE_INCLUDED_FILE
  204274. class IPhoneAudioIODevice : public AudioIODevice
  204275. {
  204276. public:
  204277. IPhoneAudioIODevice (const String& deviceName)
  204278. : AudioIODevice (deviceName, T("Audio")),
  204279. audioUnit (0),
  204280. isRunning (false),
  204281. callback (0),
  204282. actualBufferSize (0),
  204283. floatData (1, 2)
  204284. {
  204285. numInputChannels = 2;
  204286. numOutputChannels = 2;
  204287. preferredBufferSize = 0;
  204288. AudioSessionInitialize (0, 0, interruptionListenerStatic, this);
  204289. updateDeviceInfo();
  204290. }
  204291. ~IPhoneAudioIODevice()
  204292. {
  204293. close();
  204294. }
  204295. const StringArray getOutputChannelNames()
  204296. {
  204297. StringArray s;
  204298. s.add ("Left");
  204299. s.add ("Right");
  204300. return s;
  204301. }
  204302. const StringArray getInputChannelNames()
  204303. {
  204304. StringArray s;
  204305. if (audioInputIsAvailable)
  204306. {
  204307. s.add ("Left");
  204308. s.add ("Right");
  204309. }
  204310. return s;
  204311. }
  204312. int getNumSampleRates()
  204313. {
  204314. return 1;
  204315. }
  204316. double getSampleRate (int index)
  204317. {
  204318. return sampleRate;
  204319. }
  204320. int getNumBufferSizesAvailable()
  204321. {
  204322. return 1;
  204323. }
  204324. int getBufferSizeSamples (int index)
  204325. {
  204326. return getDefaultBufferSize();
  204327. }
  204328. int getDefaultBufferSize()
  204329. {
  204330. return 1024;
  204331. }
  204332. const String open (const BitArray& inputChannels,
  204333. const BitArray& outputChannels,
  204334. double sampleRate,
  204335. int bufferSize)
  204336. {
  204337. close();
  204338. lastError = String::empty;
  204339. preferredBufferSize = (bufferSize <= 0) ? getDefaultBufferSize() : bufferSize;
  204340. // xxx set up channel mapping
  204341. activeOutputChans = outputChannels;
  204342. activeOutputChans.setRange (2, activeOutputChans.getHighestBit(), false);
  204343. numOutputChannels = activeOutputChans.countNumberOfSetBits();
  204344. monoOutputChannelNumber = activeOutputChans.findNextSetBit (0);
  204345. activeInputChans = inputChannels;
  204346. activeInputChans.setRange (2, activeInputChans.getHighestBit(), false);
  204347. numInputChannels = activeInputChans.countNumberOfSetBits();
  204348. monoInputChannelNumber = activeInputChans.findNextSetBit (0);
  204349. AudioSessionSetActive (true);
  204350. UInt32 audioCategory = kAudioSessionCategory_PlayAndRecord;
  204351. AudioSessionSetProperty (kAudioSessionProperty_AudioCategory, sizeof (audioCategory), &audioCategory);
  204352. AudioSessionAddPropertyListener (kAudioSessionProperty_AudioRouteChange, propertyChangedStatic, this);
  204353. fixAudioRouteIfSetToReceiver();
  204354. updateDeviceInfo();
  204355. Float32 bufferDuration = preferredBufferSize / sampleRate;
  204356. AudioSessionSetProperty (kAudioSessionProperty_PreferredHardwareIOBufferDuration, sizeof (bufferDuration), &bufferDuration);
  204357. actualBufferSize = preferredBufferSize;
  204358. prepareFloatBuffers();
  204359. isRunning = true;
  204360. propertyChanged (0, 0, 0); // creates and starts the AU
  204361. lastError = audioUnit != 0 ? String::empty
  204362. : T("Couldn't open the device");
  204363. return lastError;
  204364. }
  204365. void close()
  204366. {
  204367. if (isRunning)
  204368. {
  204369. isRunning = false;
  204370. AudioSessionSetActive (false);
  204371. if (audioUnit != 0)
  204372. {
  204373. AudioComponentInstanceDispose (audioUnit);
  204374. audioUnit = 0;
  204375. }
  204376. }
  204377. }
  204378. bool isOpen()
  204379. {
  204380. return isRunning;
  204381. }
  204382. int getCurrentBufferSizeSamples()
  204383. {
  204384. return actualBufferSize;
  204385. }
  204386. double getCurrentSampleRate()
  204387. {
  204388. return sampleRate;
  204389. }
  204390. int getCurrentBitDepth()
  204391. {
  204392. return 16;
  204393. }
  204394. const BitArray getActiveOutputChannels() const
  204395. {
  204396. return activeOutputChans;
  204397. }
  204398. const BitArray getActiveInputChannels() const
  204399. {
  204400. return activeInputChans;
  204401. }
  204402. int getOutputLatencyInSamples()
  204403. {
  204404. return 0; //xxx
  204405. }
  204406. int getInputLatencyInSamples()
  204407. {
  204408. return 0; //xxx
  204409. }
  204410. void start (AudioIODeviceCallback* callback_)
  204411. {
  204412. if (isRunning && callback != callback_)
  204413. {
  204414. if (callback_ != 0)
  204415. callback_->audioDeviceAboutToStart (this);
  204416. const ScopedLock sl (callbackLock);
  204417. callback = callback_;
  204418. }
  204419. }
  204420. void stop()
  204421. {
  204422. if (isRunning)
  204423. {
  204424. AudioIODeviceCallback* lastCallback;
  204425. {
  204426. const ScopedLock sl (callbackLock);
  204427. lastCallback = callback;
  204428. callback = 0;
  204429. }
  204430. if (lastCallback != 0)
  204431. lastCallback->audioDeviceStopped();
  204432. }
  204433. }
  204434. bool isPlaying()
  204435. {
  204436. return isRunning && callback != 0;
  204437. }
  204438. const String getLastError()
  204439. {
  204440. return lastError;
  204441. }
  204442. private:
  204443. CriticalSection callbackLock;
  204444. Float64 sampleRate;
  204445. int numInputChannels, numOutputChannels;
  204446. int preferredBufferSize;
  204447. int actualBufferSize;
  204448. bool isRunning;
  204449. String lastError;
  204450. AudioStreamBasicDescription format;
  204451. AudioUnit audioUnit;
  204452. UInt32 audioInputIsAvailable;
  204453. AudioIODeviceCallback* callback;
  204454. BitArray activeOutputChans, activeInputChans;
  204455. AudioSampleBuffer floatData;
  204456. float* inputChannels[3];
  204457. float* outputChannels[3];
  204458. bool monoInputChannelNumber, monoOutputChannelNumber;
  204459. void prepareFloatBuffers()
  204460. {
  204461. floatData.setSize (numInputChannels + numOutputChannels, actualBufferSize);
  204462. zerostruct (inputChannels);
  204463. zerostruct (outputChannels);
  204464. for (int i = 0; i < numInputChannels; ++i)
  204465. inputChannels[i] = floatData.getSampleData (i);
  204466. for (int i = 0; i < numOutputChannels; ++i)
  204467. outputChannels[i] = floatData.getSampleData (i + numInputChannels);
  204468. }
  204469. OSStatus process (AudioUnitRenderActionFlags* ioActionFlags, const AudioTimeStamp* inTimeStamp,
  204470. UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList* ioData)
  204471. {
  204472. OSStatus err = noErr;
  204473. if (audioInputIsAvailable)
  204474. err = AudioUnitRender (audioUnit, ioActionFlags, inTimeStamp, 1, inNumberFrames, ioData);
  204475. const ScopedLock sl (callbackLock);
  204476. if (callback != 0)
  204477. {
  204478. if (audioInputIsAvailable && numInputChannels > 0)
  204479. {
  204480. short* shortData = (short*) ioData->mBuffers[0].mData;
  204481. if (numInputChannels >= 2)
  204482. {
  204483. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204484. {
  204485. inputChannels[0][i] = *shortData++ * (1.0f / 32768.0f);
  204486. inputChannels[1][i] = *shortData++ * (1.0f / 32768.0f);
  204487. }
  204488. }
  204489. else
  204490. {
  204491. if (monoInputChannelNumber > 0)
  204492. ++shortData;
  204493. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204494. {
  204495. inputChannels[0][i] = *shortData++ * (1.0f / 32768.0f);
  204496. ++shortData;
  204497. }
  204498. }
  204499. }
  204500. else
  204501. {
  204502. for (int i = numInputChannels; --i >= 0;)
  204503. zeromem (inputChannels[i], sizeof (float) * inNumberFrames);
  204504. }
  204505. callback->audioDeviceIOCallback ((const float**) inputChannels, numInputChannels,
  204506. outputChannels, numOutputChannels,
  204507. (int) inNumberFrames);
  204508. short* shortData = (short*) ioData->mBuffers[0].mData;
  204509. int n = 0;
  204510. if (numOutputChannels >= 2)
  204511. {
  204512. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204513. {
  204514. shortData [n++] = (short) (outputChannels[0][i] * 32767.0f);
  204515. shortData [n++] = (short) (outputChannels[1][i] * 32767.0f);
  204516. }
  204517. }
  204518. else if (numOutputChannels == 1)
  204519. {
  204520. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204521. {
  204522. const short s = (short) (outputChannels[monoOutputChannelNumber][i] * 32767.0f);
  204523. shortData [n++] = s;
  204524. shortData [n++] = s;
  204525. }
  204526. }
  204527. else
  204528. {
  204529. zeromem (ioData->mBuffers[0].mData, 2 * sizeof (short) * inNumberFrames);
  204530. }
  204531. }
  204532. else
  204533. {
  204534. zeromem (ioData->mBuffers[0].mData, 2 * sizeof (short) * inNumberFrames);
  204535. }
  204536. return err;
  204537. }
  204538. void updateDeviceInfo()
  204539. {
  204540. UInt32 size = sizeof (sampleRate);
  204541. AudioSessionGetProperty (kAudioSessionProperty_CurrentHardwareSampleRate, &size, &sampleRate);
  204542. size = sizeof (audioInputIsAvailable);
  204543. AudioSessionGetProperty (kAudioSessionProperty_AudioInputAvailable, &size, &audioInputIsAvailable);
  204544. }
  204545. void propertyChanged (AudioSessionPropertyID inID, UInt32 inDataSize, const void* inPropertyValue)
  204546. {
  204547. if (! isRunning)
  204548. return;
  204549. if (inPropertyValue != 0)
  204550. {
  204551. CFDictionaryRef routeChangeDictionary = (CFDictionaryRef) inPropertyValue;
  204552. CFNumberRef routeChangeReasonRef = (CFNumberRef) CFDictionaryGetValue (routeChangeDictionary,
  204553. CFSTR (kAudioSession_AudioRouteChangeKey_Reason));
  204554. SInt32 routeChangeReason;
  204555. CFNumberGetValue (routeChangeReasonRef, kCFNumberSInt32Type, &routeChangeReason);
  204556. if (routeChangeReason == kAudioSessionRouteChangeReason_OldDeviceUnavailable)
  204557. fixAudioRouteIfSetToReceiver();
  204558. }
  204559. updateDeviceInfo();
  204560. createAudioUnit();
  204561. AudioSessionSetActive (true);
  204562. if (audioUnit != 0)
  204563. {
  204564. UInt32 formatSize = sizeof (format);
  204565. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &format, &formatSize);
  204566. Float32 bufferDuration = preferredBufferSize / sampleRate;
  204567. UInt32 bufferDurationSize = sizeof (bufferDuration);
  204568. AudioSessionGetProperty (kAudioSessionProperty_CurrentHardwareIOBufferDuration, &bufferDurationSize, &bufferDurationSize);
  204569. actualBufferSize = (int) (sampleRate * bufferDuration + 0.5);
  204570. AudioOutputUnitStart (audioUnit);
  204571. }
  204572. }
  204573. void interruptionListener (UInt32 inInterruption)
  204574. {
  204575. if (inInterruption == kAudioSessionEndInterruption)
  204576. {
  204577. isRunning = true;
  204578. AudioSessionSetActive (true);
  204579. AudioOutputUnitStart (audioUnit);
  204580. }
  204581. }
  204582. static OSStatus processStatic (void* inRefCon, AudioUnitRenderActionFlags* ioActionFlags, const AudioTimeStamp* inTimeStamp,
  204583. UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList* ioData)
  204584. {
  204585. return ((IPhoneAudioIODevice*) inRefCon)->process (ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, ioData);
  204586. }
  204587. static void propertyChangedStatic (void* inClientData, AudioSessionPropertyID inID, UInt32 inDataSize, const void* inPropertyValue)
  204588. {
  204589. ((IPhoneAudioIODevice*) inClientData)->propertyChanged (inID, inDataSize, inPropertyValue);
  204590. }
  204591. static void interruptionListenerStatic (void* inClientData, UInt32 inInterruption)
  204592. {
  204593. ((IPhoneAudioIODevice*) inClientData)->interruptionListener (inInterruption);
  204594. }
  204595. void resetFormat (const int numChannels)
  204596. {
  204597. memset (&format, 0, sizeof (format));
  204598. format.mFormatID = kAudioFormatLinearPCM;
  204599. format.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked;
  204600. format.mBitsPerChannel = 8 * sizeof (short);
  204601. format.mChannelsPerFrame = 2;
  204602. format.mFramesPerPacket = 1;
  204603. format.mBytesPerFrame = format.mBytesPerPacket = 2 * sizeof (short);
  204604. }
  204605. bool createAudioUnit()
  204606. {
  204607. if (audioUnit != 0)
  204608. {
  204609. AudioComponentInstanceDispose (audioUnit);
  204610. audioUnit = 0;
  204611. }
  204612. resetFormat (2);
  204613. AudioComponentDescription desc;
  204614. desc.componentType = kAudioUnitType_Output;
  204615. desc.componentSubType = kAudioUnitSubType_RemoteIO;
  204616. desc.componentManufacturer = kAudioUnitManufacturer_Apple;
  204617. desc.componentFlags = 0;
  204618. desc.componentFlagsMask = 0;
  204619. AudioComponent comp = AudioComponentFindNext (0, &desc);
  204620. AudioComponentInstanceNew (comp, &audioUnit);
  204621. if (audioUnit == 0)
  204622. return false;
  204623. const UInt32 one = 1;
  204624. AudioUnitSetProperty (audioUnit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input, 1, &one, sizeof (one));
  204625. AudioChannelLayout layout;
  204626. layout.mChannelBitmap = 0;
  204627. layout.mNumberChannelDescriptions = 0;
  204628. layout.mChannelLayoutTag = kAudioChannelLayoutTag_Stereo;
  204629. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_AudioChannelLayout, kAudioUnitScope_Input, 0, &layout, sizeof (layout));
  204630. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_AudioChannelLayout, kAudioUnitScope_Output, 0, &layout, sizeof (layout));
  204631. AURenderCallbackStruct inputProc;
  204632. inputProc.inputProc = processStatic;
  204633. inputProc.inputProcRefCon = this;
  204634. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, 0, &inputProc, sizeof (inputProc));
  204635. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &format, sizeof (format));
  204636. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &format, sizeof (format));
  204637. AudioUnitInitialize (audioUnit);
  204638. return true;
  204639. }
  204640. // If the routing is set to go through the receiver (i.e. the speaker, but quiet), this re-routes it
  204641. // to make it loud. Needed because by default when using an input + output, the output is kept quiet.
  204642. static void fixAudioRouteIfSetToReceiver()
  204643. {
  204644. CFStringRef audioRoute = 0;
  204645. UInt32 propertySize = sizeof (audioRoute);
  204646. if (AudioSessionGetProperty (kAudioSessionProperty_AudioRoute, &propertySize, &audioRoute) == noErr)
  204647. {
  204648. NSString* route = (NSString*) audioRoute;
  204649. //DBG ("audio route: " + nsStringToJuce (route));
  204650. if ([route hasPrefix: @"Receiver"])
  204651. {
  204652. UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
  204653. AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute, sizeof (audioRouteOverride), &audioRouteOverride);
  204654. }
  204655. CFRelease (audioRoute);
  204656. }
  204657. }
  204658. IPhoneAudioIODevice (const IPhoneAudioIODevice&);
  204659. IPhoneAudioIODevice& operator= (const IPhoneAudioIODevice&);
  204660. };
  204661. class IPhoneAudioIODeviceType : public AudioIODeviceType
  204662. {
  204663. public:
  204664. IPhoneAudioIODeviceType()
  204665. : AudioIODeviceType (T("iPhone Audio"))
  204666. {
  204667. }
  204668. ~IPhoneAudioIODeviceType()
  204669. {
  204670. }
  204671. void scanForDevices()
  204672. {
  204673. }
  204674. const StringArray getDeviceNames (const bool wantInputNames) const
  204675. {
  204676. StringArray s;
  204677. s.add ("iPhone Audio");
  204678. return s;
  204679. }
  204680. int getDefaultDeviceIndex (const bool forInput) const
  204681. {
  204682. return 0;
  204683. }
  204684. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  204685. {
  204686. return device != 0 ? 0 : -1;
  204687. }
  204688. bool hasSeparateInputsAndOutputs() const { return false; }
  204689. AudioIODevice* createDevice (const String& outputDeviceName,
  204690. const String& inputDeviceName)
  204691. {
  204692. if (outputDeviceName.isNotEmpty() || inputDeviceName.isNotEmpty())
  204693. {
  204694. return new IPhoneAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
  204695. : inputDeviceName);
  204696. }
  204697. return 0;
  204698. }
  204699. juce_UseDebuggingNewOperator
  204700. private:
  204701. IPhoneAudioIODeviceType (const IPhoneAudioIODeviceType&);
  204702. IPhoneAudioIODeviceType& operator= (const IPhoneAudioIODeviceType&);
  204703. };
  204704. AudioIODeviceType* juce_createAudioIODeviceType_iPhoneAudio()
  204705. {
  204706. return new IPhoneAudioIODeviceType();
  204707. }
  204708. #endif
  204709. /*** End of inlined file: juce_iphone_Audio.cpp ***/
  204710. /*** Start of inlined file: juce_mac_CoreMidi.cpp ***/
  204711. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204712. // compiled on its own).
  204713. #if JUCE_INCLUDED_FILE
  204714. #if JUCE_MAC
  204715. #undef log
  204716. #define log(a) Logger::writeToLog(a)
  204717. static bool logAnyErrorsMidi (const OSStatus err, const int lineNum)
  204718. {
  204719. if (err == noErr)
  204720. return true;
  204721. log (T("CoreMidi error: ") + String (lineNum) + T(" - ") + String::toHexString ((int)err));
  204722. jassertfalse
  204723. return false;
  204724. }
  204725. #undef OK
  204726. #define OK(a) logAnyErrorsMidi(a, __LINE__)
  204727. static const String getEndpointName (MIDIEndpointRef endpoint, bool isExternal)
  204728. {
  204729. String result;
  204730. CFStringRef str = 0;
  204731. MIDIObjectGetStringProperty (endpoint, kMIDIPropertyName, &str);
  204732. if (str != 0)
  204733. {
  204734. result = PlatformUtilities::cfStringToJuceString (str);
  204735. CFRelease (str);
  204736. str = 0;
  204737. }
  204738. MIDIEntityRef entity = 0;
  204739. MIDIEndpointGetEntity (endpoint, &entity);
  204740. if (entity == 0)
  204741. return result; // probably virtual
  204742. if (result.isEmpty())
  204743. {
  204744. // endpoint name has zero length - try the entity
  204745. MIDIObjectGetStringProperty (entity, kMIDIPropertyName, &str);
  204746. if (str != 0)
  204747. {
  204748. result += PlatformUtilities::cfStringToJuceString (str);
  204749. CFRelease (str);
  204750. str = 0;
  204751. }
  204752. }
  204753. // now consider the device's name
  204754. MIDIDeviceRef device = 0;
  204755. MIDIEntityGetDevice (entity, &device);
  204756. if (device == 0)
  204757. return result;
  204758. MIDIObjectGetStringProperty (device, kMIDIPropertyName, &str);
  204759. if (str != 0)
  204760. {
  204761. const String s (PlatformUtilities::cfStringToJuceString (str));
  204762. CFRelease (str);
  204763. // if an external device has only one entity, throw away
  204764. // the endpoint name and just use the device name
  204765. if (isExternal && MIDIDeviceGetNumberOfEntities (device) < 2)
  204766. {
  204767. result = s;
  204768. }
  204769. else if (! result.startsWithIgnoreCase (s))
  204770. {
  204771. // prepend the device name to the entity name
  204772. result = (s + T(" ") + result).trimEnd();
  204773. }
  204774. }
  204775. return result;
  204776. }
  204777. static const String getConnectedEndpointName (MIDIEndpointRef endpoint)
  204778. {
  204779. String result;
  204780. // Does the endpoint have connections?
  204781. CFDataRef connections = 0;
  204782. int numConnections = 0;
  204783. MIDIObjectGetDataProperty (endpoint, kMIDIPropertyConnectionUniqueID, &connections);
  204784. if (connections != 0)
  204785. {
  204786. numConnections = (int) (CFDataGetLength (connections) / sizeof (MIDIUniqueID));
  204787. if (numConnections > 0)
  204788. {
  204789. const SInt32* pid = reinterpret_cast <const SInt32*> (CFDataGetBytePtr (connections));
  204790. for (int i = 0; i < numConnections; ++i, ++pid)
  204791. {
  204792. MIDIUniqueID uid = EndianS32_BtoN (*pid);
  204793. MIDIObjectRef connObject;
  204794. MIDIObjectType connObjectType;
  204795. OSStatus err = MIDIObjectFindByUniqueID (uid, &connObject, &connObjectType);
  204796. if (err == noErr)
  204797. {
  204798. String s;
  204799. if (connObjectType == kMIDIObjectType_ExternalSource
  204800. || connObjectType == kMIDIObjectType_ExternalDestination)
  204801. {
  204802. // Connected to an external device's endpoint (10.3 and later).
  204803. s = getEndpointName (static_cast <MIDIEndpointRef> (connObject), true);
  204804. }
  204805. else
  204806. {
  204807. // Connected to an external device (10.2) (or something else, catch-all)
  204808. CFStringRef str = 0;
  204809. MIDIObjectGetStringProperty (connObject, kMIDIPropertyName, &str);
  204810. if (str != 0)
  204811. {
  204812. s = PlatformUtilities::cfStringToJuceString (str);
  204813. CFRelease (str);
  204814. }
  204815. }
  204816. if (s.isNotEmpty())
  204817. {
  204818. if (result.isNotEmpty())
  204819. result += (", ");
  204820. result += s;
  204821. }
  204822. }
  204823. }
  204824. }
  204825. CFRelease (connections);
  204826. }
  204827. if (result.isNotEmpty())
  204828. return result;
  204829. // Here, either the endpoint had no connections, or we failed to obtain names for any of them.
  204830. return getEndpointName (endpoint, false);
  204831. }
  204832. const StringArray MidiOutput::getDevices()
  204833. {
  204834. StringArray s;
  204835. const ItemCount num = MIDIGetNumberOfDestinations();
  204836. for (ItemCount i = 0; i < num; ++i)
  204837. {
  204838. MIDIEndpointRef dest = MIDIGetDestination (i);
  204839. if (dest != 0)
  204840. {
  204841. String name (getConnectedEndpointName (dest));
  204842. if (name.isEmpty())
  204843. name = "<error>";
  204844. s.add (name);
  204845. }
  204846. else
  204847. {
  204848. s.add ("<error>");
  204849. }
  204850. }
  204851. return s;
  204852. }
  204853. int MidiOutput::getDefaultDeviceIndex()
  204854. {
  204855. return 0;
  204856. }
  204857. static MIDIClientRef globalMidiClient;
  204858. static bool hasGlobalClientBeenCreated = false;
  204859. static bool makeSureClientExists()
  204860. {
  204861. if (! hasGlobalClientBeenCreated)
  204862. {
  204863. String name (T("JUCE"));
  204864. if (JUCEApplication::getInstance() != 0)
  204865. name = JUCEApplication::getInstance()->getApplicationName();
  204866. CFStringRef appName = PlatformUtilities::juceStringToCFString (name);
  204867. hasGlobalClientBeenCreated = OK (MIDIClientCreate (appName, 0, 0, &globalMidiClient));
  204868. CFRelease (appName);
  204869. }
  204870. return hasGlobalClientBeenCreated;
  204871. }
  204872. class MidiPortAndEndpoint
  204873. {
  204874. public:
  204875. MidiPortAndEndpoint (MIDIPortRef port_, MIDIEndpointRef endPoint_)
  204876. : port (port_), endPoint (endPoint_)
  204877. {
  204878. }
  204879. ~MidiPortAndEndpoint()
  204880. {
  204881. if (port != 0)
  204882. MIDIPortDispose (port);
  204883. if (port == 0 && endPoint != 0) // if port == 0, it means we created the endpoint, so it's safe to delete it
  204884. MIDIEndpointDispose (endPoint);
  204885. }
  204886. MIDIPortRef port;
  204887. MIDIEndpointRef endPoint;
  204888. };
  204889. MidiOutput* MidiOutput::openDevice (int index)
  204890. {
  204891. MidiOutput* mo = 0;
  204892. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfDestinations())
  204893. {
  204894. MIDIEndpointRef endPoint = MIDIGetDestination (index);
  204895. CFStringRef pname;
  204896. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  204897. {
  204898. log (T("CoreMidi - opening out: ") + PlatformUtilities::cfStringToJuceString (pname));
  204899. if (makeSureClientExists())
  204900. {
  204901. MIDIPortRef port;
  204902. if (OK (MIDIOutputPortCreate (globalMidiClient, pname, &port)))
  204903. {
  204904. mo = new MidiOutput();
  204905. mo->internal = (void*) new MidiPortAndEndpoint (port, endPoint);
  204906. }
  204907. }
  204908. CFRelease (pname);
  204909. }
  204910. }
  204911. return mo;
  204912. }
  204913. MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
  204914. {
  204915. MidiOutput* mo = 0;
  204916. if (makeSureClientExists())
  204917. {
  204918. MIDIEndpointRef endPoint;
  204919. CFStringRef name = PlatformUtilities::juceStringToCFString (deviceName);
  204920. if (OK (MIDISourceCreate (globalMidiClient, name, &endPoint)))
  204921. {
  204922. mo = new MidiOutput();
  204923. mo->internal = (void*) new MidiPortAndEndpoint (0, endPoint);
  204924. }
  204925. CFRelease (name);
  204926. }
  204927. return mo;
  204928. }
  204929. MidiOutput::~MidiOutput()
  204930. {
  204931. delete (MidiPortAndEndpoint*) internal;
  204932. }
  204933. void MidiOutput::reset()
  204934. {
  204935. }
  204936. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  204937. {
  204938. return false;
  204939. }
  204940. void MidiOutput::setVolume (float leftVol, float rightVol)
  204941. {
  204942. }
  204943. void MidiOutput::sendMessageNow (const MidiMessage& message)
  204944. {
  204945. MidiPortAndEndpoint* const mpe = (MidiPortAndEndpoint*) internal;
  204946. if (message.isSysEx())
  204947. {
  204948. const int maxPacketSize = 256;
  204949. int pos = 0, bytesLeft = message.getRawDataSize();
  204950. const int numPackets = (bytesLeft + maxPacketSize - 1) / maxPacketSize;
  204951. HeapBlock <MIDIPacketList> packets;
  204952. packets.malloc (32 * numPackets + message.getRawDataSize(), 1);
  204953. packets->numPackets = numPackets;
  204954. MIDIPacket* p = packets->packet;
  204955. for (int i = 0; i < numPackets; ++i)
  204956. {
  204957. p->timeStamp = 0;
  204958. p->length = jmin (maxPacketSize, bytesLeft);
  204959. memcpy (p->data, message.getRawData() + pos, p->length);
  204960. pos += p->length;
  204961. bytesLeft -= p->length;
  204962. p = MIDIPacketNext (p);
  204963. }
  204964. if (mpe->port != 0)
  204965. MIDISend (mpe->port, mpe->endPoint, packets);
  204966. else
  204967. MIDIReceived (mpe->endPoint, packets);
  204968. }
  204969. else
  204970. {
  204971. MIDIPacketList packets;
  204972. packets.numPackets = 1;
  204973. packets.packet[0].timeStamp = 0;
  204974. packets.packet[0].length = message.getRawDataSize();
  204975. *(int*) (packets.packet[0].data) = *(const int*) message.getRawData();
  204976. if (mpe->port != 0)
  204977. MIDISend (mpe->port, mpe->endPoint, &packets);
  204978. else
  204979. MIDIReceived (mpe->endPoint, &packets);
  204980. }
  204981. }
  204982. const StringArray MidiInput::getDevices()
  204983. {
  204984. StringArray s;
  204985. const ItemCount num = MIDIGetNumberOfSources();
  204986. for (ItemCount i = 0; i < num; ++i)
  204987. {
  204988. MIDIEndpointRef source = MIDIGetSource (i);
  204989. if (source != 0)
  204990. {
  204991. String name (getConnectedEndpointName (source));
  204992. if (name.isEmpty())
  204993. name = "<error>";
  204994. s.add (name);
  204995. }
  204996. else
  204997. {
  204998. s.add ("<error>");
  204999. }
  205000. }
  205001. return s;
  205002. }
  205003. int MidiInput::getDefaultDeviceIndex()
  205004. {
  205005. return 0;
  205006. }
  205007. struct MidiPortAndCallback
  205008. {
  205009. MidiInput* input;
  205010. MidiPortAndEndpoint* portAndEndpoint;
  205011. MidiInputCallback* callback;
  205012. MemoryBlock pendingData;
  205013. int pendingBytes;
  205014. double pendingDataTime;
  205015. bool active;
  205016. void processSysex (const uint8*& d, int& size, const double time)
  205017. {
  205018. if (*d == 0xf0)
  205019. {
  205020. pendingBytes = 0;
  205021. pendingDataTime = time;
  205022. }
  205023. pendingData.ensureSize (pendingBytes + size, false);
  205024. uint8* totalMessage = (uint8*) pendingData.getData();
  205025. uint8* dest = totalMessage + pendingBytes;
  205026. while (size > 0)
  205027. {
  205028. if (pendingBytes > 0 && *d >= 0x80)
  205029. {
  205030. if (*d >= 0xfa || *d == 0xf8)
  205031. {
  205032. callback->handleIncomingMidiMessage (input, MidiMessage (*d, time));
  205033. ++d;
  205034. --size;
  205035. }
  205036. else
  205037. {
  205038. if (*d == 0xf7)
  205039. {
  205040. *dest++ = *d++;
  205041. pendingBytes++;
  205042. --size;
  205043. }
  205044. break;
  205045. }
  205046. }
  205047. else
  205048. {
  205049. *dest++ = *d++;
  205050. pendingBytes++;
  205051. --size;
  205052. }
  205053. }
  205054. if (totalMessage [pendingBytes - 1] == 0xf7)
  205055. {
  205056. callback->handleIncomingMidiMessage (input, MidiMessage (totalMessage, pendingBytes, pendingDataTime));
  205057. pendingBytes = 0;
  205058. }
  205059. else
  205060. {
  205061. callback->handlePartialSysexMessage (input, totalMessage, pendingBytes, pendingDataTime);
  205062. }
  205063. }
  205064. };
  205065. namespace CoreMidiCallbacks
  205066. {
  205067. static CriticalSection callbackLock;
  205068. static VoidArray activeCallbacks;
  205069. }
  205070. static void midiInputProc (const MIDIPacketList* pktlist,
  205071. void* readProcRefCon,
  205072. void* srcConnRefCon)
  205073. {
  205074. double time = Time::getMillisecondCounterHiRes() * 0.001;
  205075. const double originalTime = time;
  205076. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) readProcRefCon;
  205077. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205078. if (CoreMidiCallbacks::activeCallbacks.contains (mpc) && mpc->active)
  205079. {
  205080. const MIDIPacket* packet = &pktlist->packet[0];
  205081. for (unsigned int i = 0; i < pktlist->numPackets; ++i)
  205082. {
  205083. const uint8* d = (const uint8*) (packet->data);
  205084. int size = packet->length;
  205085. while (size > 0)
  205086. {
  205087. time = originalTime;
  205088. if (mpc->pendingBytes > 0 || d[0] == 0xf0)
  205089. {
  205090. mpc->processSysex (d, size, time);
  205091. }
  205092. else
  205093. {
  205094. int used = 0;
  205095. const MidiMessage m (d, size, used, 0, time);
  205096. if (used <= 0)
  205097. {
  205098. jassertfalse // malformed midi message
  205099. break;
  205100. }
  205101. else
  205102. {
  205103. mpc->callback->handleIncomingMidiMessage (mpc->input, m);
  205104. }
  205105. size -= used;
  205106. d += used;
  205107. }
  205108. }
  205109. packet = MIDIPacketNext (packet);
  205110. }
  205111. }
  205112. }
  205113. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  205114. {
  205115. MidiInput* mi = 0;
  205116. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfSources())
  205117. {
  205118. MIDIEndpointRef endPoint = MIDIGetSource (index);
  205119. if (endPoint != 0)
  205120. {
  205121. CFStringRef pname;
  205122. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  205123. {
  205124. log (T("CoreMidi - opening inp: ") + PlatformUtilities::cfStringToJuceString (pname));
  205125. if (makeSureClientExists())
  205126. {
  205127. MIDIPortRef port;
  205128. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  205129. mpc->active = false;
  205130. if (OK (MIDIInputPortCreate (globalMidiClient, pname, midiInputProc, mpc, &port)))
  205131. {
  205132. if (OK (MIDIPortConnectSource (port, endPoint, 0)))
  205133. {
  205134. mpc->portAndEndpoint = new MidiPortAndEndpoint (port, endPoint);
  205135. mpc->callback = callback;
  205136. mpc->pendingBytes = 0;
  205137. mpc->pendingData.ensureSize (128);
  205138. mi = new MidiInput (getDevices() [index]);
  205139. mpc->input = mi;
  205140. mi->internal = (void*) mpc;
  205141. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205142. CoreMidiCallbacks::activeCallbacks.add (mpc.release());
  205143. }
  205144. else
  205145. {
  205146. OK (MIDIPortDispose (port));
  205147. }
  205148. }
  205149. }
  205150. }
  205151. CFRelease (pname);
  205152. }
  205153. }
  205154. return mi;
  205155. }
  205156. MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback)
  205157. {
  205158. MidiInput* mi = 0;
  205159. if (makeSureClientExists())
  205160. {
  205161. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  205162. mpc->active = false;
  205163. MIDIEndpointRef endPoint;
  205164. CFStringRef name = PlatformUtilities::juceStringToCFString(deviceName);
  205165. if (OK (MIDIDestinationCreate (globalMidiClient, name, midiInputProc, mpc, &endPoint)))
  205166. {
  205167. mpc->portAndEndpoint = new MidiPortAndEndpoint (0, endPoint);
  205168. mpc->callback = callback;
  205169. mpc->pendingBytes = 0;
  205170. mpc->pendingData.ensureSize (128);
  205171. mi = new MidiInput (deviceName);
  205172. mpc->input = mi;
  205173. mi->internal = (void*) mpc;
  205174. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205175. CoreMidiCallbacks::activeCallbacks.add (mpc.release());
  205176. }
  205177. CFRelease (name);
  205178. }
  205179. return mi;
  205180. }
  205181. MidiInput::MidiInput (const String& name_)
  205182. : name (name_)
  205183. {
  205184. }
  205185. MidiInput::~MidiInput()
  205186. {
  205187. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  205188. mpc->active = false;
  205189. {
  205190. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205191. CoreMidiCallbacks::activeCallbacks.removeValue (mpc);
  205192. }
  205193. if (mpc->portAndEndpoint->port != 0)
  205194. OK (MIDIPortDisconnectSource (mpc->portAndEndpoint->port, mpc->portAndEndpoint->endPoint));
  205195. delete mpc->portAndEndpoint;
  205196. delete mpc;
  205197. }
  205198. void MidiInput::start()
  205199. {
  205200. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205201. ((MidiPortAndCallback*) internal)->active = true;
  205202. }
  205203. void MidiInput::stop()
  205204. {
  205205. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205206. ((MidiPortAndCallback*) internal)->active = false;
  205207. }
  205208. #undef log
  205209. #else
  205210. MidiOutput::~MidiOutput()
  205211. {
  205212. }
  205213. void MidiOutput::reset()
  205214. {
  205215. }
  205216. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  205217. {
  205218. return false;
  205219. }
  205220. void MidiOutput::setVolume (float leftVol, float rightVol)
  205221. {
  205222. }
  205223. void MidiOutput::sendMessageNow (const MidiMessage& message)
  205224. {
  205225. }
  205226. const StringArray MidiOutput::getDevices()
  205227. {
  205228. return StringArray();
  205229. }
  205230. MidiOutput* MidiOutput::openDevice (int index)
  205231. {
  205232. return 0;
  205233. }
  205234. const StringArray MidiInput::getDevices()
  205235. {
  205236. return StringArray();
  205237. }
  205238. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  205239. {
  205240. return 0;
  205241. }
  205242. #endif
  205243. #endif
  205244. /*** End of inlined file: juce_mac_CoreMidi.cpp ***/
  205245. #else
  205246. /*** Start of inlined file: juce_mac_Fonts.mm ***/
  205247. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  205248. // compiled on its own).
  205249. #if JUCE_INCLUDED_FILE
  205250. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  205251. #define SUPPORT_10_4_FONTS 1
  205252. #define NEW_CGFONT_FUNCTIONS_UNAVAILABLE (CGFontCreateWithFontName == 0)
  205253. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  205254. #define SUPPORT_ONLY_10_4_FONTS 1
  205255. #endif
  205256. END_JUCE_NAMESPACE
  205257. @interface NSFont (PrivateHack)
  205258. - (NSGlyph) _defaultGlyphForChar: (unichar) theChar;
  205259. @end
  205260. BEGIN_JUCE_NAMESPACE
  205261. #endif
  205262. class MacTypeface : public Typeface
  205263. {
  205264. public:
  205265. MacTypeface (const Font& font)
  205266. : Typeface (font.getTypefaceName())
  205267. {
  205268. const ScopedAutoReleasePool pool;
  205269. renderingTransform = CGAffineTransformIdentity;
  205270. bool needsItalicTransform = false;
  205271. #if JUCE_IPHONE
  205272. NSString* fontName = juceStringToNS (font.getTypefaceName());
  205273. if (font.isItalic() || font.isBold())
  205274. {
  205275. NSArray* familyFonts = [UIFont fontNamesForFamilyName: juceStringToNS (font.getTypefaceName())];
  205276. for (NSString* i in familyFonts)
  205277. {
  205278. const String fn (nsStringToJuce (i));
  205279. const String afterDash (fn.fromFirstOccurrenceOf (T("-"), false, false));
  205280. const bool probablyBold = afterDash.containsIgnoreCase (T("bold")) || fn.endsWithIgnoreCase (T("bold"));
  205281. const bool probablyItalic = afterDash.containsIgnoreCase (T("oblique"))
  205282. || afterDash.containsIgnoreCase (T("italic"))
  205283. || fn.endsWithIgnoreCase (T("oblique"))
  205284. || fn.endsWithIgnoreCase (T("italic"));
  205285. if (probablyBold == font.isBold()
  205286. && probablyItalic == font.isItalic())
  205287. {
  205288. fontName = i;
  205289. needsItalicTransform = false;
  205290. break;
  205291. }
  205292. else if (probablyBold && (! probablyItalic) && probablyBold == font.isBold())
  205293. {
  205294. fontName = i;
  205295. needsItalicTransform = true; // not ideal, so carry on in case we find a better one
  205296. }
  205297. }
  205298. if (needsItalicTransform)
  205299. renderingTransform.c = 0.15f;
  205300. }
  205301. fontRef = CGFontCreateWithFontName ((CFStringRef) fontName);
  205302. const int ascender = abs (CGFontGetAscent (fontRef));
  205303. const float totalHeight = ascender + abs (CGFontGetDescent (fontRef));
  205304. ascent = ascender / totalHeight;
  205305. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205306. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / totalHeight;
  205307. #else
  205308. nsFont = [NSFont fontWithName: juceStringToNS (font.getTypefaceName()) size: 1024];
  205309. if (font.isItalic())
  205310. {
  205311. NSFont* newFont = [[NSFontManager sharedFontManager] convertFont: nsFont
  205312. toHaveTrait: NSItalicFontMask];
  205313. if (newFont == nsFont)
  205314. needsItalicTransform = true; // couldn't find a proper italic version, so fake it with a transform..
  205315. nsFont = newFont;
  205316. }
  205317. if (font.isBold())
  205318. nsFont = [[NSFontManager sharedFontManager] convertFont: nsFont toHaveTrait: NSBoldFontMask];
  205319. [nsFont retain];
  205320. ascent = fabsf ((float) [nsFont ascender]);
  205321. float totalSize = ascent + fabsf ((float) [nsFont descender]);
  205322. ascent /= totalSize;
  205323. pathTransform = AffineTransform::identity.scale (1.0f / totalSize, 1.0f / totalSize);
  205324. if (needsItalicTransform)
  205325. {
  205326. pathTransform = pathTransform.sheared (-0.15f, 0.0f);
  205327. renderingTransform.c = 0.15f;
  205328. }
  205329. #if SUPPORT_ONLY_10_4_FONTS
  205330. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205331. if (atsFont == 0)
  205332. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205333. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  205334. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  205335. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205336. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  205337. #else
  205338. #if SUPPORT_10_4_FONTS
  205339. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205340. {
  205341. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205342. if (atsFont == 0)
  205343. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205344. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  205345. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  205346. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205347. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  205348. }
  205349. else
  205350. #endif
  205351. {
  205352. fontRef = CGFontCreateWithFontName ((CFStringRef) [nsFont fontName]);
  205353. const int totalHeight = abs (CGFontGetAscent (fontRef)) + abs (CGFontGetDescent (fontRef));
  205354. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205355. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / (float) totalHeight;
  205356. }
  205357. #endif
  205358. #endif
  205359. }
  205360. ~MacTypeface()
  205361. {
  205362. #if ! JUCE_IPHONE
  205363. [nsFont release];
  205364. #endif
  205365. if (fontRef != 0)
  205366. CGFontRelease (fontRef);
  205367. }
  205368. float getAscent() const
  205369. {
  205370. return ascent;
  205371. }
  205372. float getDescent() const
  205373. {
  205374. return 1.0f - ascent;
  205375. }
  205376. float getStringWidth (const String& text)
  205377. {
  205378. if (fontRef == 0 || text.isEmpty())
  205379. return 0;
  205380. const int length = text.length();
  205381. HeapBlock <CGGlyph> glyphs;
  205382. createGlyphsForString (text, length, glyphs);
  205383. float x = 0;
  205384. #if SUPPORT_ONLY_10_4_FONTS
  205385. HeapBlock <NSSize> advances (length);
  205386. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast <NSGlyph*> (glyphs.getData()) count: length];
  205387. for (int i = 0; i < length; ++i)
  205388. x += advances[i].width;
  205389. #else
  205390. #if SUPPORT_10_4_FONTS
  205391. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205392. {
  205393. HeapBlock <NSSize> advances (length);
  205394. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast<NSGlyph*> (glyphs.getData()) count: length];
  205395. for (int i = 0; i < length; ++i)
  205396. x += advances[i].width;
  205397. }
  205398. else
  205399. #endif
  205400. {
  205401. HeapBlock <int> advances (length);
  205402. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  205403. for (int i = 0; i < length; ++i)
  205404. x += advances[i];
  205405. }
  205406. #endif
  205407. return x * unitsToHeightScaleFactor;
  205408. }
  205409. void getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array <float>& xOffsets)
  205410. {
  205411. xOffsets.add (0);
  205412. if (fontRef == 0 || text.isEmpty())
  205413. return;
  205414. const int length = text.length();
  205415. HeapBlock <CGGlyph> glyphs;
  205416. createGlyphsForString (text, length, glyphs);
  205417. #if SUPPORT_ONLY_10_4_FONTS
  205418. HeapBlock <NSSize> advances (length);
  205419. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast <NSGlyph*> (glyphs.getData()) count: length];
  205420. int x = 0;
  205421. for (int i = 0; i < length; ++i)
  205422. {
  205423. x += advances[i].width;
  205424. xOffsets.add (x * unitsToHeightScaleFactor);
  205425. resultGlyphs.add (reinterpret_cast <NSGlyph*> (glyphs.getData())[i]);
  205426. }
  205427. #else
  205428. #if SUPPORT_10_4_FONTS
  205429. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205430. {
  205431. HeapBlock <NSSize> advances (length);
  205432. NSGlyph* const nsGlyphs = reinterpret_cast<NSGlyph*> (glyphs.getData());
  205433. [nsFont getAdvancements: advances forGlyphs: nsGlyphs count: length];
  205434. float x = 0;
  205435. for (int i = 0; i < length; ++i)
  205436. {
  205437. x += advances[i].width;
  205438. xOffsets.add (x * unitsToHeightScaleFactor);
  205439. resultGlyphs.add (nsGlyphs[i]);
  205440. }
  205441. }
  205442. else
  205443. #endif
  205444. {
  205445. HeapBlock <int> advances (length);
  205446. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  205447. {
  205448. int x = 0;
  205449. for (int i = 0; i < length; ++i)
  205450. {
  205451. x += advances [i];
  205452. xOffsets.add (x * unitsToHeightScaleFactor);
  205453. resultGlyphs.add (glyphs[i]);
  205454. }
  205455. }
  205456. }
  205457. #endif
  205458. }
  205459. bool getOutlineForGlyph (int glyphNumber, Path& path)
  205460. {
  205461. #if JUCE_IPHONE
  205462. return false;
  205463. #else
  205464. if (nsFont == 0)
  205465. return false;
  205466. // we might need to apply a transform to the path, so it mustn't have anything else in it
  205467. jassert (path.isEmpty());
  205468. const ScopedAutoReleasePool pool;
  205469. NSBezierPath* bez = [NSBezierPath bezierPath];
  205470. [bez moveToPoint: NSMakePoint (0, 0)];
  205471. [bez appendBezierPathWithGlyph: (NSGlyph) glyphNumber
  205472. inFont: nsFont];
  205473. for (int i = 0; i < [bez elementCount]; ++i)
  205474. {
  205475. NSPoint p[3];
  205476. switch ([bez elementAtIndex: i associatedPoints: p])
  205477. {
  205478. case NSMoveToBezierPathElement:
  205479. path.startNewSubPath ((float) p[0].x, (float) -p[0].y);
  205480. break;
  205481. case NSLineToBezierPathElement:
  205482. path.lineTo ((float) p[0].x, (float) -p[0].y);
  205483. break;
  205484. case NSCurveToBezierPathElement:
  205485. 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);
  205486. break;
  205487. case NSClosePathBezierPathElement:
  205488. path.closeSubPath();
  205489. break;
  205490. default:
  205491. jassertfalse
  205492. break;
  205493. }
  205494. }
  205495. path.applyTransform (pathTransform);
  205496. return true;
  205497. #endif
  205498. }
  205499. juce_UseDebuggingNewOperator
  205500. CGFontRef fontRef;
  205501. float fontHeightToCGSizeFactor;
  205502. CGAffineTransform renderingTransform;
  205503. private:
  205504. float ascent, unitsToHeightScaleFactor;
  205505. #if JUCE_IPHONE
  205506. #else
  205507. NSFont* nsFont;
  205508. AffineTransform pathTransform;
  205509. #endif
  205510. void createGlyphsForString (const juce_wchar* const text, const int length, HeapBlock <CGGlyph>& glyphs)
  205511. {
  205512. #if SUPPORT_10_4_FONTS
  205513. #if ! SUPPORT_ONLY_10_4_FONTS
  205514. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205515. #endif
  205516. {
  205517. glyphs.malloc (sizeof (NSGlyph) * length, 1);
  205518. NSGlyph* const nsGlyphs = reinterpret_cast<NSGlyph*> (glyphs.getData());
  205519. for (int i = 0; i < length; ++i)
  205520. nsGlyphs[i] = (NSGlyph) [nsFont _defaultGlyphForChar: text[i]];
  205521. return;
  205522. }
  205523. #endif
  205524. #if ! SUPPORT_ONLY_10_4_FONTS
  205525. if (charToGlyphMapper == 0)
  205526. charToGlyphMapper = new CharToGlyphMapper (fontRef);
  205527. glyphs.malloc (length);
  205528. for (int i = 0; i < length; ++i)
  205529. glyphs[i] = (CGGlyph) charToGlyphMapper->getGlyphForCharacter (text[i]);
  205530. #endif
  205531. }
  205532. #if ! SUPPORT_ONLY_10_4_FONTS
  205533. // Reads a CGFontRef's character map table to convert unicode into glyph numbers
  205534. class CharToGlyphMapper
  205535. {
  205536. public:
  205537. CharToGlyphMapper (CGFontRef fontRef)
  205538. : segCount (0), endCode (0), startCode (0), idDelta (0),
  205539. idRangeOffset (0), glyphIndexes (0)
  205540. {
  205541. CFDataRef cmapTable = CGFontCopyTableForTag (fontRef, 'cmap');
  205542. if (cmapTable != 0)
  205543. {
  205544. const int numSubtables = getValue16 (cmapTable, 2);
  205545. for (int i = 0; i < numSubtables; ++i)
  205546. {
  205547. if (getValue16 (cmapTable, i * 8 + 4) == 0) // check for platform ID of 0
  205548. {
  205549. const int offset = getValue32 (cmapTable, i * 8 + 8);
  205550. if (getValue16 (cmapTable, offset) == 4) // check that it's format 4..
  205551. {
  205552. const int length = getValue16 (cmapTable, offset + 2);
  205553. const int segCountX2 = getValue16 (cmapTable, offset + 6);
  205554. segCount = segCountX2 / 2;
  205555. const int endCodeOffset = offset + 14;
  205556. const int startCodeOffset = endCodeOffset + 2 + segCountX2;
  205557. const int idDeltaOffset = startCodeOffset + segCountX2;
  205558. const int idRangeOffsetOffset = idDeltaOffset + segCountX2;
  205559. const int glyphIndexesOffset = idRangeOffsetOffset + segCountX2;
  205560. endCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + endCodeOffset, segCountX2);
  205561. startCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + startCodeOffset, segCountX2);
  205562. idDelta = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idDeltaOffset, segCountX2);
  205563. idRangeOffset = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idRangeOffsetOffset, segCountX2);
  205564. glyphIndexes = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + glyphIndexesOffset, offset + length - glyphIndexesOffset);
  205565. }
  205566. break;
  205567. }
  205568. }
  205569. CFRelease (cmapTable);
  205570. }
  205571. }
  205572. ~CharToGlyphMapper()
  205573. {
  205574. if (endCode != 0)
  205575. {
  205576. CFRelease (endCode);
  205577. CFRelease (startCode);
  205578. CFRelease (idDelta);
  205579. CFRelease (idRangeOffset);
  205580. CFRelease (glyphIndexes);
  205581. }
  205582. }
  205583. int getGlyphForCharacter (const juce_wchar c) const
  205584. {
  205585. for (int i = 0; i < segCount; ++i)
  205586. {
  205587. if (getValue16 (endCode, i * 2) >= c)
  205588. {
  205589. const int start = getValue16 (startCode, i * 2);
  205590. if (start > c)
  205591. break;
  205592. const int delta = getValue16 (idDelta, i * 2);
  205593. const int rangeOffset = getValue16 (idRangeOffset, i * 2);
  205594. if (rangeOffset == 0)
  205595. return delta + c;
  205596. else
  205597. return getValue16 (glyphIndexes, 2 * ((rangeOffset / 2) + (c - start) - (segCount - i)));
  205598. }
  205599. }
  205600. // If we failed to find it "properly", this dodgy fall-back seems to do the trick for most fonts!
  205601. return jmax (-1, c - 29);
  205602. }
  205603. private:
  205604. int segCount;
  205605. CFDataRef endCode, startCode, idDelta, idRangeOffset, glyphIndexes;
  205606. static uint16 getValue16 (CFDataRef data, const int index)
  205607. {
  205608. return CFSwapInt16BigToHost (*(UInt16*) (CFDataGetBytePtr (data) + index));
  205609. }
  205610. static uint32 getValue32 (CFDataRef data, const int index)
  205611. {
  205612. return CFSwapInt32BigToHost (*(UInt32*) (CFDataGetBytePtr (data) + index));
  205613. }
  205614. };
  205615. ScopedPointer <CharToGlyphMapper> charToGlyphMapper;
  205616. #endif
  205617. };
  205618. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  205619. {
  205620. return new MacTypeface (font);
  205621. }
  205622. const StringArray Font::findAllTypefaceNames() throw()
  205623. {
  205624. StringArray names;
  205625. const ScopedAutoReleasePool pool;
  205626. #if JUCE_IPHONE
  205627. NSArray* fonts = [UIFont familyNames];
  205628. #else
  205629. NSArray* fonts = [[NSFontManager sharedFontManager] availableFontFamilies];
  205630. #endif
  205631. for (unsigned int i = 0; i < [fonts count]; ++i)
  205632. names.add (nsStringToJuce ((NSString*) [fonts objectAtIndex: i]));
  205633. names.sort (true);
  205634. return names;
  205635. }
  205636. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw()
  205637. {
  205638. #if JUCE_IPHONE
  205639. defaultSans = "Helvetica";
  205640. defaultSerif = "Times New Roman";
  205641. defaultFixed = "Courier New";
  205642. #else
  205643. defaultSans = "Lucida Grande";
  205644. defaultSerif = "Times New Roman";
  205645. defaultFixed = "Monaco";
  205646. #endif
  205647. }
  205648. #endif
  205649. /*** End of inlined file: juce_mac_Fonts.mm ***/
  205650. // (must go before juce_mac_CoreGraphicsContext.mm)
  205651. /*** Start of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  205652. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  205653. // compiled on its own).
  205654. #if JUCE_INCLUDED_FILE
  205655. class CoreGraphicsImage : public Image
  205656. {
  205657. public:
  205658. CoreGraphicsImage (const PixelFormat format_,
  205659. const int imageWidth_,
  205660. const int imageHeight_,
  205661. const bool clearImage)
  205662. : Image (format_, imageWidth_, imageHeight_, clearImage)
  205663. {
  205664. CGColorSpaceRef colourSpace = format == Image::SingleChannel ? CGColorSpaceCreateDeviceGray()
  205665. : CGColorSpaceCreateDeviceRGB();
  205666. context = CGBitmapContextCreate (imageData, imageWidth, imageHeight, 8, lineStride,
  205667. colourSpace, getCGImageFlags (*this));
  205668. CGColorSpaceRelease (colourSpace);
  205669. }
  205670. ~CoreGraphicsImage()
  205671. {
  205672. CGContextRelease (context);
  205673. }
  205674. LowLevelGraphicsContext* createLowLevelContext();
  205675. static CGImageRef createImage (const Image& juceImage, const bool forAlpha, CGColorSpaceRef colourSpace)
  205676. {
  205677. const CoreGraphicsImage* nativeImage = dynamic_cast <const CoreGraphicsImage*> (&juceImage);
  205678. if (nativeImage != 0 && (juceImage.getFormat() == Image::SingleChannel || ! forAlpha))
  205679. {
  205680. return CGBitmapContextCreateImage (nativeImage->context);
  205681. }
  205682. else
  205683. {
  205684. const Image::BitmapData srcData (juceImage, 0, 0, juceImage.getWidth(), juceImage.getHeight());
  205685. CGDataProviderRef provider = CGDataProviderCreateWithData (0, srcData.data, srcData.lineStride * srcData.height, 0);
  205686. CGImageRef imageRef = CGImageCreate (srcData.width, srcData.height,
  205687. 8, srcData.pixelStride * 8, srcData.lineStride,
  205688. colourSpace, getCGImageFlags (juceImage), provider,
  205689. 0, true, kCGRenderingIntentDefault);
  205690. CGDataProviderRelease (provider);
  205691. return imageRef;
  205692. }
  205693. }
  205694. #if JUCE_MAC
  205695. static NSImage* createNSImage (const Image& image)
  205696. {
  205697. const ScopedAutoReleasePool pool;
  205698. NSImage* im = [[NSImage alloc] init];
  205699. [im setSize: NSMakeSize (image.getWidth(), image.getHeight())];
  205700. [im lockFocus];
  205701. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  205702. CGImageRef imageRef = createImage (image, false, colourSpace);
  205703. CGColorSpaceRelease (colourSpace);
  205704. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  205705. CGContextDrawImage (cg, CGRectMake (0, 0, image.getWidth(), image.getHeight()), imageRef);
  205706. CGImageRelease (imageRef);
  205707. [im unlockFocus];
  205708. return im;
  205709. }
  205710. #endif
  205711. CGContextRef context;
  205712. private:
  205713. static CGBitmapInfo getCGImageFlags (const Image& image)
  205714. {
  205715. #if JUCE_BIG_ENDIAN
  205716. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Big) : kCGBitmapByteOrderDefault;
  205717. #else
  205718. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little) : kCGBitmapByteOrderDefault;
  205719. #endif
  205720. }
  205721. };
  205722. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  205723. {
  205724. #if USE_COREGRAPHICS_RENDERING
  205725. return new CoreGraphicsImage (format == RGB ? ARGB : format, imageWidth, imageHeight, clearImage);
  205726. #else
  205727. return new Image (format, imageWidth, imageHeight, clearImage);
  205728. #endif
  205729. }
  205730. class CoreGraphicsContext : public LowLevelGraphicsContext
  205731. {
  205732. public:
  205733. CoreGraphicsContext (CGContextRef context_, const float flipHeight_)
  205734. : context (context_),
  205735. flipHeight (flipHeight_),
  205736. state (new SavedState()),
  205737. numGradientLookupEntries (0)
  205738. {
  205739. CGContextRetain (context);
  205740. CGContextSaveGState(context);
  205741. CGContextSetShouldSmoothFonts (context, true);
  205742. CGContextSetShouldAntialias (context, true);
  205743. CGContextSetBlendMode (context, kCGBlendModeNormal);
  205744. rgbColourSpace = CGColorSpaceCreateDeviceRGB();
  205745. greyColourSpace = CGColorSpaceCreateDeviceGray();
  205746. gradientCallbacks.version = 0;
  205747. gradientCallbacks.evaluate = gradientCallback;
  205748. gradientCallbacks.releaseInfo = 0;
  205749. setFont (Font());
  205750. }
  205751. ~CoreGraphicsContext()
  205752. {
  205753. CGContextRestoreGState (context);
  205754. CGContextRelease (context);
  205755. CGColorSpaceRelease (rgbColourSpace);
  205756. CGColorSpaceRelease (greyColourSpace);
  205757. }
  205758. bool isVectorDevice() const { return false; }
  205759. void setOrigin (int x, int y)
  205760. {
  205761. CGContextTranslateCTM (context, x, -y);
  205762. }
  205763. bool clipToRectangle (const Rectangle<int>& r)
  205764. {
  205765. CGContextClipToRect (context, CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight()));
  205766. return ! isClipEmpty();
  205767. }
  205768. bool clipToRectangleList (const RectangleList& clipRegion)
  205769. {
  205770. if (clipRegion.isEmpty())
  205771. {
  205772. CGContextClipToRect (context, CGRectMake (0, 0, 0, 0));
  205773. return false;
  205774. }
  205775. else
  205776. {
  205777. const int numRects = clipRegion.getNumRectangles();
  205778. HeapBlock <CGRect> rects (numRects);
  205779. for (int i = 0; i < numRects; ++i)
  205780. {
  205781. const Rectangle<int>& r = clipRegion.getRectangle(i);
  205782. rects[i] = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  205783. }
  205784. CGContextClipToRects (context, rects, numRects);
  205785. return ! isClipEmpty();
  205786. }
  205787. }
  205788. void excludeClipRectangle (const Rectangle<int>& r)
  205789. {
  205790. RectangleList remaining (getClipBounds());
  205791. remaining.subtract (r);
  205792. clipToRectangleList (remaining);
  205793. }
  205794. void clipToPath (const Path& path, const AffineTransform& transform)
  205795. {
  205796. createPath (path, transform);
  205797. CGContextClip (context);
  205798. }
  205799. void clipToImageAlpha (const Image& sourceImage, const Rectangle<int>& srcClip, const AffineTransform& transform)
  205800. {
  205801. if (! transform.isSingularity())
  205802. {
  205803. Image* singleChannelImage = createAlphaChannelImage (sourceImage);
  205804. CGImageRef image = CoreGraphicsImage::createImage (*singleChannelImage, true, greyColourSpace);
  205805. flip();
  205806. AffineTransform t (AffineTransform::scale (1.0f, -1.0f).translated (0, sourceImage.getHeight()).followedBy (transform));
  205807. applyTransform (t);
  205808. CGRect r = CGRectMake (0, 0, sourceImage.getWidth(), sourceImage.getHeight());
  205809. CGContextClipToMask (context, r, image);
  205810. applyTransform (t.inverted());
  205811. flip();
  205812. CGImageRelease (image);
  205813. deleteAlphaChannelImage (sourceImage, singleChannelImage);
  205814. }
  205815. }
  205816. bool clipRegionIntersects (const Rectangle<int>& r)
  205817. {
  205818. return getClipBounds().intersects (r);
  205819. }
  205820. const Rectangle<int> getClipBounds() const
  205821. {
  205822. CGRect bounds = CGRectIntegral (CGContextGetClipBoundingBox (context));
  205823. return Rectangle<int> (roundToInt (bounds.origin.x),
  205824. roundToInt (flipHeight - (bounds.origin.y + bounds.size.height)),
  205825. roundToInt (bounds.size.width),
  205826. roundToInt (bounds.size.height));
  205827. }
  205828. bool isClipEmpty() const
  205829. {
  205830. return CGRectIsEmpty (CGContextGetClipBoundingBox (context));
  205831. }
  205832. void saveState()
  205833. {
  205834. CGContextSaveGState (context);
  205835. stateStack.add (new SavedState (*state));
  205836. }
  205837. void restoreState()
  205838. {
  205839. CGContextRestoreGState (context);
  205840. SavedState* const top = stateStack.getLast();
  205841. if (top != 0)
  205842. {
  205843. state = top;
  205844. stateStack.removeLast (1, false);
  205845. }
  205846. else
  205847. {
  205848. jassertfalse // trying to pop with an empty stack!
  205849. }
  205850. }
  205851. void setFill (const FillType& fillType)
  205852. {
  205853. state->fillType = fillType;
  205854. if (fillType.isColour())
  205855. {
  205856. CGContextSetRGBFillColor (context, fillType.colour.getFloatRed(), fillType.colour.getFloatGreen(),
  205857. fillType.colour.getFloatBlue(), fillType.colour.getFloatAlpha());
  205858. CGContextSetAlpha (context, 1.0f);
  205859. }
  205860. }
  205861. void setOpacity (float newOpacity)
  205862. {
  205863. state->fillType.setOpacity (newOpacity);
  205864. setFill (state->fillType);
  205865. }
  205866. void setInterpolationQuality (Graphics::ResamplingQuality quality)
  205867. {
  205868. CGContextSetInterpolationQuality (context, quality == Graphics::lowResamplingQuality
  205869. ? kCGInterpolationLow
  205870. : kCGInterpolationHigh);
  205871. }
  205872. void fillRect (const Rectangle<int>& r, const bool replaceExistingContents)
  205873. {
  205874. CGRect cgRect = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  205875. if (replaceExistingContents)
  205876. {
  205877. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  205878. CGContextClearRect (context, cgRect);
  205879. #else
  205880. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  205881. if (CGContextDrawLinearGradient == 0) // (just a way of checking whether we're running in 10.5 or later)
  205882. CGContextClearRect (context, cgRect);
  205883. else
  205884. #endif
  205885. CGContextSetBlendMode (context, kCGBlendModeCopy);
  205886. #endif
  205887. fillRect (r, false);
  205888. CGContextSetBlendMode (context, kCGBlendModeNormal);
  205889. }
  205890. else
  205891. {
  205892. if (state->fillType.isColour())
  205893. {
  205894. CGContextFillRect (context, cgRect);
  205895. }
  205896. else if (state->fillType.isGradient())
  205897. {
  205898. CGContextSaveGState (context);
  205899. CGContextClipToRect (context, cgRect);
  205900. drawGradient();
  205901. CGContextRestoreGState (context);
  205902. }
  205903. else
  205904. {
  205905. CGContextSaveGState (context);
  205906. CGContextClipToRect (context, cgRect);
  205907. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  205908. CGContextRestoreGState (context);
  205909. }
  205910. }
  205911. }
  205912. void fillPath (const Path& path, const AffineTransform& transform)
  205913. {
  205914. CGContextSaveGState (context);
  205915. if (state->fillType.isColour())
  205916. {
  205917. flip();
  205918. applyTransform (transform);
  205919. createPath (path);
  205920. if (path.isUsingNonZeroWinding())
  205921. CGContextFillPath (context);
  205922. else
  205923. CGContextEOFillPath (context);
  205924. }
  205925. else
  205926. {
  205927. createPath (path, transform);
  205928. if (path.isUsingNonZeroWinding())
  205929. CGContextClip (context);
  205930. else
  205931. CGContextEOClip (context);
  205932. if (state->fillType.isGradient())
  205933. drawGradient();
  205934. else
  205935. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  205936. }
  205937. CGContextRestoreGState (context);
  205938. }
  205939. void drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  205940. const AffineTransform& transform, const bool fillEntireClipAsTiles)
  205941. {
  205942. jassert (sourceImage.getBounds().contains (srcClip));
  205943. CGImageRef fullImage = CoreGraphicsImage::createImage (sourceImage, false, rgbColourSpace);
  205944. CGImageRef image = fullImage;
  205945. if (srcClip != sourceImage.getBounds())
  205946. {
  205947. image = CGImageCreateWithImageInRect (fullImage, CGRectMake (srcClip.getX(), srcClip.getY(),
  205948. srcClip.getWidth(), srcClip.getHeight()));
  205949. CGImageRelease (fullImage);
  205950. }
  205951. CGContextSaveGState (context);
  205952. CGContextSetAlpha (context, state->fillType.getOpacity());
  205953. flip();
  205954. applyTransform (AffineTransform::scale (1.0f, -1.0f).translated (0, srcClip.getHeight()).followedBy (transform));
  205955. CGRect imageRect = CGRectMake (0, 0, srcClip.getWidth(), srcClip.getHeight());
  205956. if (fillEntireClipAsTiles)
  205957. {
  205958. #if JUCE_IPHONE || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5)
  205959. CGContextDrawTiledImage (context, imageRect, image);
  205960. #else
  205961. #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
  205962. // There's a bug in CGContextDrawTiledImage that makes it incredibly slow
  205963. // if it's doing a transformation - it's quicker to just draw lots of images manually
  205964. if (CGContextDrawTiledImage != 0 && transform.isOnlyTranslation())
  205965. CGContextDrawTiledImage (context, imageRect, image);
  205966. else
  205967. #endif
  205968. {
  205969. // Fallback to manually doing a tiled fill on 10.4
  205970. CGRect clip = CGRectIntegral (CGContextGetClipBoundingBox (context));
  205971. const int iw = srcClip.getWidth();
  205972. const int ih = srcClip.getHeight();
  205973. int x = 0, y = 0;
  205974. while (x > clip.origin.x) x -= iw;
  205975. while (y > clip.origin.y) y -= ih;
  205976. const int right = (int) (clip.origin.x + clip.size.width);
  205977. const int bottom = (int) (clip.origin.y + clip.size.height);
  205978. while (y < bottom)
  205979. {
  205980. for (int x2 = x; x2 < right; x2 += iw)
  205981. CGContextDrawImage (context, CGRectMake (x2, y, iw, ih), image);
  205982. y += ih;
  205983. }
  205984. }
  205985. #endif
  205986. }
  205987. else
  205988. {
  205989. CGContextDrawImage (context, imageRect, image);
  205990. }
  205991. CGImageRelease (image); // (This causes a memory bug in iPhone sim 3.0 - try upgrading to a later version if you hit this)
  205992. CGContextRestoreGState (context);
  205993. }
  205994. void drawLine (double x1, double y1, double x2, double y2)
  205995. {
  205996. CGContextSetLineCap (context, kCGLineCapSquare);
  205997. CGContextSetLineWidth (context, 1.0f);
  205998. CGContextSetRGBStrokeColor (context,
  205999. state->fillType.colour.getFloatRed(), state->fillType.colour.getFloatGreen(),
  206000. state->fillType.colour.getFloatBlue(), state->fillType.colour.getFloatAlpha());
  206001. CGPoint line[] = { { (float) x1 + 0.5f, flipHeight - ((float) y1 + 0.5f) },
  206002. { (float) x2 + 0.5f, flipHeight - ((float) y2 + 0.5f) } };
  206003. CGContextStrokeLineSegments (context, line, 1);
  206004. }
  206005. void drawVerticalLine (const int x, double top, double bottom)
  206006. {
  206007. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  206008. CGContextFillRect (context, CGRectMake (x, flipHeight - (float) bottom, 1.0f, (float) (bottom - top)));
  206009. #else
  206010. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  206011. // the x co-ord slightly to trick it..
  206012. CGContextFillRect (context, CGRectMake (x + 1.0f / 256.0f, flipHeight - (float) bottom, 1.0f + 1.0f / 256.0f, (float) (bottom - top)));
  206013. #endif
  206014. }
  206015. void drawHorizontalLine (const int y, double left, double right)
  206016. {
  206017. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  206018. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + 1.0f), (float) (right - left), 1.0f));
  206019. #else
  206020. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  206021. // the x co-ord slightly to trick it..
  206022. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + (1.0f + 1.0f / 256.0f)), (float) (right - left), 1.0f + 1.0f / 256.0f));
  206023. #endif
  206024. }
  206025. void setFont (const Font& newFont)
  206026. {
  206027. if (state->font != newFont)
  206028. {
  206029. state->fontRef = 0;
  206030. state->font = newFont;
  206031. MacTypeface* mf = dynamic_cast <MacTypeface*> ((Typeface*) state->font.getTypeface());
  206032. if (mf != 0)
  206033. {
  206034. state->fontRef = mf->fontRef;
  206035. CGContextSetFont (context, state->fontRef);
  206036. CGContextSetFontSize (context, state->font.getHeight() * mf->fontHeightToCGSizeFactor);
  206037. state->fontTransform = mf->renderingTransform;
  206038. state->fontTransform.a *= state->font.getHorizontalScale();
  206039. CGContextSetTextMatrix (context, state->fontTransform);
  206040. }
  206041. }
  206042. }
  206043. const Font getFont()
  206044. {
  206045. return state->font;
  206046. }
  206047. void drawGlyph (int glyphNumber, const AffineTransform& transform)
  206048. {
  206049. if (state->fontRef != 0 && state->fillType.isColour())
  206050. {
  206051. if (transform.isOnlyTranslation())
  206052. {
  206053. CGGlyph g = glyphNumber;
  206054. CGContextShowGlyphsAtPoint (context, transform.getTranslationX(),
  206055. flipHeight - roundToInt (transform.getTranslationY()), &g, 1);
  206056. }
  206057. else
  206058. {
  206059. CGContextSaveGState (context);
  206060. flip();
  206061. applyTransform (transform);
  206062. CGAffineTransform t = state->fontTransform;
  206063. t.d = -t.d;
  206064. CGContextSetTextMatrix (context, t);
  206065. CGGlyph g = glyphNumber;
  206066. CGContextShowGlyphsAtPoint (context, 0, 0, &g, 1);
  206067. CGContextSetTextMatrix (context, state->fontTransform);
  206068. CGContextRestoreGState (context);
  206069. }
  206070. }
  206071. else
  206072. {
  206073. Path p;
  206074. Font& f = state->font;
  206075. f.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  206076. fillPath (p, AffineTransform::scale (f.getHeight() * f.getHorizontalScale(), f.getHeight())
  206077. .followedBy (transform));
  206078. }
  206079. }
  206080. private:
  206081. CGContextRef context;
  206082. const float flipHeight;
  206083. CGColorSpaceRef rgbColourSpace, greyColourSpace;
  206084. CGFunctionCallbacks gradientCallbacks;
  206085. struct SavedState
  206086. {
  206087. SavedState()
  206088. : font (1.0f), fontRef (0), fontTransform (CGAffineTransformIdentity)
  206089. {
  206090. }
  206091. SavedState (const SavedState& other)
  206092. : fillType (other.fillType), font (other.font), fontRef (other.fontRef),
  206093. fontTransform (other.fontTransform)
  206094. {
  206095. }
  206096. ~SavedState()
  206097. {
  206098. }
  206099. FillType fillType;
  206100. Font font;
  206101. CGFontRef fontRef;
  206102. CGAffineTransform fontTransform;
  206103. };
  206104. ScopedPointer <SavedState> state;
  206105. OwnedArray <SavedState> stateStack;
  206106. HeapBlock <PixelARGB> gradientLookupTable;
  206107. int numGradientLookupEntries;
  206108. static void gradientCallback (void* info, const CGFloat* inData, CGFloat* outData)
  206109. {
  206110. const CoreGraphicsContext* const g = (const CoreGraphicsContext*) info;
  206111. const int index = roundToInt (g->numGradientLookupEntries * inData[0]);
  206112. PixelARGB colour (g->gradientLookupTable [jlimit (0, g->numGradientLookupEntries, index)]);
  206113. colour.unpremultiply();
  206114. outData[0] = colour.getRed() / 255.0f;
  206115. outData[1] = colour.getGreen() / 255.0f;
  206116. outData[2] = colour.getBlue() / 255.0f;
  206117. outData[3] = colour.getAlpha() / 255.0f;
  206118. }
  206119. CGShadingRef createGradient (const AffineTransform& transform, ColourGradient gradient)
  206120. {
  206121. numGradientLookupEntries = gradient.createLookupTable (transform, gradientLookupTable);
  206122. --numGradientLookupEntries;
  206123. CGShadingRef result = 0;
  206124. CGFunctionRef function = CGFunctionCreate ((void*) this, 1, 0, 4, 0, &gradientCallbacks);
  206125. CGPoint p1 (CGPointMake (gradient.x1, gradient.y1));
  206126. if (gradient.isRadial)
  206127. {
  206128. result = CGShadingCreateRadial (rgbColourSpace, p1, 0,
  206129. p1, hypotf (gradient.x1 - gradient.x2, gradient.y1 - gradient.y2),
  206130. function, true, true);
  206131. }
  206132. else
  206133. {
  206134. result = CGShadingCreateAxial (rgbColourSpace, p1,
  206135. CGPointMake (gradient.x2, gradient.y2),
  206136. function, true, true);
  206137. }
  206138. CGFunctionRelease (function);
  206139. return result;
  206140. }
  206141. void drawGradient()
  206142. {
  206143. flip();
  206144. applyTransform (state->fillType.transform);
  206145. CGContextSetInterpolationQuality (context, kCGInterpolationDefault); // (This is required for 10.4, where there's a crash if
  206146. // you draw a gradient with high quality interp enabled).
  206147. CGShadingRef shading = createGradient (state->fillType.transform, *(state->fillType.gradient));
  206148. CGContextSetAlpha (context, state->fillType.getOpacity());
  206149. CGContextDrawShading (context, shading);
  206150. CGShadingRelease (shading);
  206151. }
  206152. void createPath (const Path& path) const
  206153. {
  206154. CGContextBeginPath (context);
  206155. Path::Iterator i (path);
  206156. while (i.next())
  206157. {
  206158. switch (i.elementType)
  206159. {
  206160. case Path::Iterator::startNewSubPath:
  206161. CGContextMoveToPoint (context, i.x1, i.y1);
  206162. break;
  206163. case Path::Iterator::lineTo:
  206164. CGContextAddLineToPoint (context, i.x1, i.y1);
  206165. break;
  206166. case Path::Iterator::quadraticTo:
  206167. CGContextAddQuadCurveToPoint (context, i.x1, i.y1, i.x2, i.y2);
  206168. break;
  206169. case Path::Iterator::cubicTo:
  206170. CGContextAddCurveToPoint (context, i.x1, i.y1, i.x2, i.y2, i.x3, i.y3);
  206171. break;
  206172. case Path::Iterator::closePath:
  206173. CGContextClosePath (context); break;
  206174. default:
  206175. jassertfalse
  206176. break;
  206177. }
  206178. }
  206179. }
  206180. void createPath (const Path& path, const AffineTransform& transform) const
  206181. {
  206182. CGContextBeginPath (context);
  206183. Path::Iterator i (path);
  206184. while (i.next())
  206185. {
  206186. switch (i.elementType)
  206187. {
  206188. case Path::Iterator::startNewSubPath:
  206189. transform.transformPoint (i.x1, i.y1);
  206190. CGContextMoveToPoint (context, i.x1, flipHeight - i.y1);
  206191. break;
  206192. case Path::Iterator::lineTo:
  206193. transform.transformPoint (i.x1, i.y1);
  206194. CGContextAddLineToPoint (context, i.x1, flipHeight - i.y1);
  206195. break;
  206196. case Path::Iterator::quadraticTo:
  206197. transform.transformPoint (i.x1, i.y1);
  206198. transform.transformPoint (i.x2, i.y2);
  206199. CGContextAddQuadCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2);
  206200. break;
  206201. case Path::Iterator::cubicTo:
  206202. transform.transformPoint (i.x1, i.y1);
  206203. transform.transformPoint (i.x2, i.y2);
  206204. transform.transformPoint (i.x3, i.y3);
  206205. CGContextAddCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2, i.x3, flipHeight - i.y3);
  206206. break;
  206207. case Path::Iterator::closePath:
  206208. CGContextClosePath (context); break;
  206209. default:
  206210. jassertfalse
  206211. break;
  206212. }
  206213. }
  206214. }
  206215. static Image* createAlphaChannelImage (const Image& im)
  206216. {
  206217. if (im.getFormat() == Image::SingleChannel)
  206218. return const_cast <Image*> (&im);
  206219. return im.createCopyOfAlphaChannel();
  206220. }
  206221. static void deleteAlphaChannelImage (const Image& im, Image* const alphaIm)
  206222. {
  206223. if (im.getFormat() != Image::SingleChannel)
  206224. delete alphaIm;
  206225. }
  206226. void flip() const
  206227. {
  206228. CGContextConcatCTM (context, CGAffineTransformMake (1, 0, 0, -1, 0, flipHeight));
  206229. }
  206230. void applyTransform (const AffineTransform& transform) const
  206231. {
  206232. CGAffineTransform t;
  206233. t.a = transform.mat00;
  206234. t.b = transform.mat10;
  206235. t.c = transform.mat01;
  206236. t.d = transform.mat11;
  206237. t.tx = transform.mat02;
  206238. t.ty = transform.mat12;
  206239. CGContextConcatCTM (context, t);
  206240. }
  206241. float flipY (float y) const
  206242. {
  206243. return flipHeight - y;
  206244. }
  206245. };
  206246. LowLevelGraphicsContext* CoreGraphicsImage::createLowLevelContext()
  206247. {
  206248. return new CoreGraphicsContext (context, imageHeight);
  206249. }
  206250. #endif
  206251. /*** End of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  206252. /*** Start of inlined file: juce_mac_NSViewComponentPeer.mm ***/
  206253. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  206254. // compiled on its own).
  206255. #if JUCE_INCLUDED_FILE
  206256. class NSViewComponentPeer;
  206257. END_JUCE_NAMESPACE
  206258. #define JuceNSView MakeObjCClassName(JuceNSView)
  206259. @interface JuceNSView : NSView<NSTextInput>
  206260. {
  206261. @public
  206262. NSViewComponentPeer* owner;
  206263. NSNotificationCenter* notificationCenter;
  206264. String* stringBeingComposed;
  206265. bool textWasInserted;
  206266. }
  206267. - (JuceNSView*) initWithOwner: (NSViewComponentPeer*) owner withFrame: (NSRect) frame;
  206268. - (void) dealloc;
  206269. - (BOOL) isOpaque;
  206270. - (void) drawRect: (NSRect) r;
  206271. - (void) mouseDown: (NSEvent*) ev;
  206272. - (void) asyncMouseDown: (NSEvent*) ev;
  206273. - (void) mouseUp: (NSEvent*) ev;
  206274. - (void) asyncMouseUp: (NSEvent*) ev;
  206275. - (void) mouseDragged: (NSEvent*) ev;
  206276. - (void) mouseMoved: (NSEvent*) ev;
  206277. - (void) mouseEntered: (NSEvent*) ev;
  206278. - (void) mouseExited: (NSEvent*) ev;
  206279. - (void) rightMouseDown: (NSEvent*) ev;
  206280. - (void) rightMouseDragged: (NSEvent*) ev;
  206281. - (void) rightMouseUp: (NSEvent*) ev;
  206282. - (void) otherMouseDown: (NSEvent*) ev;
  206283. - (void) otherMouseDragged: (NSEvent*) ev;
  206284. - (void) otherMouseUp: (NSEvent*) ev;
  206285. - (void) scrollWheel: (NSEvent*) ev;
  206286. - (BOOL) acceptsFirstMouse: (NSEvent*) ev;
  206287. - (void) frameChanged: (NSNotification*) n;
  206288. - (void) viewDidMoveToWindow;
  206289. - (void) keyDown: (NSEvent*) ev;
  206290. - (void) keyUp: (NSEvent*) ev;
  206291. // NSTextInput Methods
  206292. - (void) insertText: (id) aString;
  206293. - (void) doCommandBySelector: (SEL) aSelector;
  206294. - (void) setMarkedText: (id) aString selectedRange: (NSRange) selRange;
  206295. - (void) unmarkText;
  206296. - (BOOL) hasMarkedText;
  206297. - (long) conversationIdentifier;
  206298. - (NSAttributedString*) attributedSubstringFromRange: (NSRange) theRange;
  206299. - (NSRange) markedRange;
  206300. - (NSRange) selectedRange;
  206301. - (NSRect) firstRectForCharacterRange: (NSRange) theRange;
  206302. - (unsigned int) characterIndexForPoint: (NSPoint) thePoint;
  206303. - (NSArray*) validAttributesForMarkedText;
  206304. - (void) flagsChanged: (NSEvent*) ev;
  206305. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206306. - (BOOL) performKeyEquivalent: (NSEvent*) ev;
  206307. #endif
  206308. - (BOOL) becomeFirstResponder;
  206309. - (BOOL) resignFirstResponder;
  206310. - (BOOL) acceptsFirstResponder;
  206311. - (void) asyncRepaint: (id) rect;
  206312. - (NSArray*) getSupportedDragTypes;
  206313. - (BOOL) sendDragCallback: (int) type sender: (id <NSDraggingInfo>) sender;
  206314. - (NSDragOperation) draggingEntered: (id <NSDraggingInfo>) sender;
  206315. - (NSDragOperation) draggingUpdated: (id <NSDraggingInfo>) sender;
  206316. - (void) draggingEnded: (id <NSDraggingInfo>) sender;
  206317. - (void) draggingExited: (id <NSDraggingInfo>) sender;
  206318. - (BOOL) prepareForDragOperation: (id <NSDraggingInfo>) sender;
  206319. - (BOOL) performDragOperation: (id <NSDraggingInfo>) sender;
  206320. - (void) concludeDragOperation: (id <NSDraggingInfo>) sender;
  206321. @end
  206322. #define JuceNSWindow MakeObjCClassName(JuceNSWindow)
  206323. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  206324. @interface JuceNSWindow : NSWindow <NSWindowDelegate>
  206325. #else
  206326. @interface JuceNSWindow : NSWindow
  206327. #endif
  206328. {
  206329. @private
  206330. NSViewComponentPeer* owner;
  206331. bool isZooming;
  206332. }
  206333. - (void) setOwner: (NSViewComponentPeer*) owner;
  206334. - (BOOL) canBecomeKeyWindow;
  206335. - (void) becomeKeyWindow;
  206336. - (BOOL) windowShouldClose: (id) window;
  206337. - (NSRect) constrainFrameRect: (NSRect) frameRect toScreen: (NSScreen*) screen;
  206338. - (NSSize) windowWillResize: (NSWindow*) window toSize: (NSSize) proposedFrameSize;
  206339. - (void) zoom: (id) sender;
  206340. @end
  206341. BEGIN_JUCE_NAMESPACE
  206342. class NSViewComponentPeer : public ComponentPeer
  206343. {
  206344. public:
  206345. NSViewComponentPeer (Component* const component,
  206346. const int windowStyleFlags,
  206347. NSView* viewToAttachTo);
  206348. ~NSViewComponentPeer();
  206349. void* getNativeHandle() const;
  206350. void setVisible (bool shouldBeVisible);
  206351. void setTitle (const String& title);
  206352. void setPosition (int x, int y);
  206353. void setSize (int w, int h);
  206354. void setBounds (int x, int y, int w, int h, const bool isNowFullScreen);
  206355. const Rectangle<int> getBounds (const bool global) const;
  206356. const Rectangle<int> getBounds() const;
  206357. const Point<int> getScreenPosition() const;
  206358. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition);
  206359. const Point<int> globalPositionToRelative (const Point<int>& screenPosition);
  206360. void setMinimised (bool shouldBeMinimised);
  206361. bool isMinimised() const;
  206362. void setFullScreen (bool shouldBeFullScreen);
  206363. bool isFullScreen() const;
  206364. bool contains (const Point<int>& position, bool trueIfInAChildWindow) const;
  206365. const BorderSize getFrameSize() const;
  206366. bool setAlwaysOnTop (bool alwaysOnTop);
  206367. void toFront (bool makeActiveWindow);
  206368. void toBehind (ComponentPeer* other);
  206369. void setIcon (const Image& newIcon);
  206370. const StringArray getAvailableRenderingEngines() throw();
  206371. int getCurrentRenderingEngine() throw();
  206372. void setCurrentRenderingEngine (int index) throw();
  206373. virtual void redirectMouseDown (NSEvent* ev);
  206374. virtual void redirectMouseUp (NSEvent* ev);
  206375. virtual void redirectMouseDrag (NSEvent* ev);
  206376. virtual void redirectMouseMove (NSEvent* ev);
  206377. virtual void redirectMouseEnter (NSEvent* ev);
  206378. virtual void redirectMouseExit (NSEvent* ev);
  206379. virtual void redirectMouseWheel (NSEvent* ev);
  206380. void sendMouseEvent (NSEvent* ev);
  206381. bool handleKeyEvent (NSEvent* ev, bool isKeyDown);
  206382. virtual bool redirectKeyDown (NSEvent* ev);
  206383. virtual bool redirectKeyUp (NSEvent* ev);
  206384. virtual void redirectModKeyChange (NSEvent* ev);
  206385. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206386. virtual bool redirectPerformKeyEquivalent (NSEvent* ev);
  206387. #endif
  206388. virtual BOOL sendDragCallback (int type, id <NSDraggingInfo> sender);
  206389. virtual bool isOpaque();
  206390. virtual void drawRect (NSRect r);
  206391. virtual bool canBecomeKeyWindow();
  206392. virtual bool windowShouldClose();
  206393. virtual void redirectMovedOrResized();
  206394. virtual void viewMovedToWindow();
  206395. virtual NSRect constrainRect (NSRect r);
  206396. static void showArrowCursorIfNeeded();
  206397. static void updateModifiers (NSEvent* e);
  206398. static void updateKeysDown (NSEvent* ev, bool isKeyDown);
  206399. static int getKeyCodeFromEvent (NSEvent* ev)
  206400. {
  206401. const String unmodified (nsStringToJuce ([ev charactersIgnoringModifiers]));
  206402. int keyCode = unmodified[0];
  206403. if (keyCode == 0x19) // (backwards-tab)
  206404. keyCode = '\t';
  206405. else if (keyCode == 0x03) // (enter)
  206406. keyCode = '\r';
  206407. return keyCode;
  206408. }
  206409. static int64 getMouseTime (NSEvent* e)
  206410. {
  206411. return (Time::currentTimeMillis() - Time::getMillisecondCounter())
  206412. + (int64) ([e timestamp] * 1000.0);
  206413. }
  206414. static const Point<int> getMousePos (NSEvent* e, NSView* view)
  206415. {
  206416. NSPoint p = [view convertPoint: [e locationInWindow] fromView: nil];
  206417. return Point<int> (roundToInt (p.x), roundToInt ([view frame].size.height - p.y));
  206418. }
  206419. static int getModifierForButtonNumber (const NSInteger num)
  206420. {
  206421. return num == 0 ? ModifierKeys::leftButtonModifier
  206422. : (num == 1 ? ModifierKeys::rightButtonModifier
  206423. : (num == 2 ? ModifierKeys::middleButtonModifier : 0));
  206424. }
  206425. virtual void viewFocusGain();
  206426. virtual void viewFocusLoss();
  206427. bool isFocused() const;
  206428. void grabFocus();
  206429. void textInputRequired (const Point<int>& position);
  206430. void repaint (int x, int y, int w, int h);
  206431. void performAnyPendingRepaintsNow();
  206432. juce_UseDebuggingNewOperator
  206433. NSWindow* window;
  206434. JuceNSView* view;
  206435. bool isSharedWindow, fullScreen, insideDrawRect, usingCoreGraphics, recursiveToFrontCall;
  206436. static ModifierKeys currentModifiers;
  206437. static ComponentPeer* currentlyFocusedPeer;
  206438. static VoidArray keysCurrentlyDown;
  206439. };
  206440. END_JUCE_NAMESPACE
  206441. @implementation JuceNSView
  206442. - (JuceNSView*) initWithOwner: (NSViewComponentPeer*) owner_
  206443. withFrame: (NSRect) frame
  206444. {
  206445. [super initWithFrame: frame];
  206446. owner = owner_;
  206447. stringBeingComposed = 0;
  206448. textWasInserted = false;
  206449. notificationCenter = [NSNotificationCenter defaultCenter];
  206450. [notificationCenter addObserver: self
  206451. selector: @selector (frameChanged:)
  206452. name: NSViewFrameDidChangeNotification
  206453. object: self];
  206454. if (! owner_->isSharedWindow)
  206455. {
  206456. [notificationCenter addObserver: self
  206457. selector: @selector (frameChanged:)
  206458. name: NSWindowDidMoveNotification
  206459. object: owner_->window];
  206460. }
  206461. [self registerForDraggedTypes: [self getSupportedDragTypes]];
  206462. return self;
  206463. }
  206464. - (void) dealloc
  206465. {
  206466. [notificationCenter removeObserver: self];
  206467. delete stringBeingComposed;
  206468. [super dealloc];
  206469. }
  206470. - (void) drawRect: (NSRect) r
  206471. {
  206472. if (owner != 0)
  206473. owner->drawRect (r);
  206474. }
  206475. - (BOOL) isOpaque
  206476. {
  206477. return owner == 0 || owner->isOpaque();
  206478. }
  206479. - (void) mouseDown: (NSEvent*) ev
  206480. {
  206481. // In some host situations, the host will stop modal loops from working
  206482. // correctly if they're called from a mouse event, so we'll trigger
  206483. // the event asynchronously..
  206484. if (JUCEApplication::getInstance() == 0)
  206485. [self performSelectorOnMainThread: @selector (asyncMouseDown:)
  206486. withObject: ev
  206487. waitUntilDone: NO];
  206488. else
  206489. [self asyncMouseDown: ev];
  206490. }
  206491. - (void) asyncMouseDown: (NSEvent*) ev
  206492. {
  206493. if (owner != 0)
  206494. owner->redirectMouseDown (ev);
  206495. }
  206496. - (void) mouseUp: (NSEvent*) ev
  206497. {
  206498. // In some host situations, the host will stop modal loops from working
  206499. // correctly if they're called from a mouse event, so we'll trigger
  206500. // the event asynchronously..
  206501. if (JUCEApplication::getInstance() == 0)
  206502. [self performSelectorOnMainThread: @selector (asyncMouseUp:)
  206503. withObject: ev
  206504. waitUntilDone: NO];
  206505. else
  206506. [self asyncMouseUp: ev];
  206507. }
  206508. - (void) asyncMouseUp: (NSEvent*) ev
  206509. {
  206510. if (owner != 0)
  206511. owner->redirectMouseUp (ev);
  206512. }
  206513. - (void) mouseDragged: (NSEvent*) ev
  206514. {
  206515. if (owner != 0)
  206516. owner->redirectMouseDrag (ev);
  206517. }
  206518. - (void) mouseMoved: (NSEvent*) ev
  206519. {
  206520. if (owner != 0)
  206521. owner->redirectMouseMove (ev);
  206522. }
  206523. - (void) mouseEntered: (NSEvent*) ev
  206524. {
  206525. if (owner != 0)
  206526. owner->redirectMouseEnter (ev);
  206527. }
  206528. - (void) mouseExited: (NSEvent*) ev
  206529. {
  206530. if (owner != 0)
  206531. owner->redirectMouseExit (ev);
  206532. }
  206533. - (void) rightMouseDown: (NSEvent*) ev
  206534. {
  206535. [self mouseDown: ev];
  206536. }
  206537. - (void) rightMouseDragged: (NSEvent*) ev
  206538. {
  206539. [self mouseDragged: ev];
  206540. }
  206541. - (void) rightMouseUp: (NSEvent*) ev
  206542. {
  206543. [self mouseUp: ev];
  206544. }
  206545. - (void) otherMouseDown: (NSEvent*) ev
  206546. {
  206547. [self mouseDown: ev];
  206548. }
  206549. - (void) otherMouseDragged: (NSEvent*) ev
  206550. {
  206551. [self mouseDragged: ev];
  206552. }
  206553. - (void) otherMouseUp: (NSEvent*) ev
  206554. {
  206555. [self mouseUp: ev];
  206556. }
  206557. - (void) scrollWheel: (NSEvent*) ev
  206558. {
  206559. if (owner != 0)
  206560. owner->redirectMouseWheel (ev);
  206561. }
  206562. - (BOOL) acceptsFirstMouse: (NSEvent*) ev
  206563. {
  206564. return YES;
  206565. }
  206566. - (void) frameChanged: (NSNotification*) n
  206567. {
  206568. if (owner != 0)
  206569. owner->redirectMovedOrResized();
  206570. }
  206571. - (void) viewDidMoveToWindow
  206572. {
  206573. if (owner != 0)
  206574. owner->viewMovedToWindow();
  206575. }
  206576. - (void) asyncRepaint: (id) rect
  206577. {
  206578. NSRect* r = (NSRect*) [((NSData*) rect) bytes];
  206579. [self setNeedsDisplayInRect: *r];
  206580. }
  206581. - (void) keyDown: (NSEvent*) ev
  206582. {
  206583. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206584. textWasInserted = false;
  206585. if (target != 0)
  206586. [self interpretKeyEvents: [NSArray arrayWithObject: ev]];
  206587. else
  206588. deleteAndZero (stringBeingComposed);
  206589. if ((! textWasInserted) && (owner == 0 || ! owner->redirectKeyDown (ev)))
  206590. [super keyDown: ev];
  206591. }
  206592. - (void) keyUp: (NSEvent*) ev
  206593. {
  206594. if (owner == 0 || ! owner->redirectKeyUp (ev))
  206595. [super keyUp: ev];
  206596. }
  206597. - (void) insertText: (id) aString
  206598. {
  206599. // This commits multi-byte text when return is pressed, or after every keypress for western keyboards
  206600. if ([aString length] > 0)
  206601. {
  206602. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206603. if (target != 0)
  206604. {
  206605. target->insertTextAtCaret (nsStringToJuce ([aString isKindOfClass: [NSAttributedString class]] ? [aString string] : aString));
  206606. textWasInserted = true;
  206607. }
  206608. }
  206609. deleteAndZero (stringBeingComposed);
  206610. }
  206611. - (void) doCommandBySelector: (SEL) aSelector
  206612. {
  206613. }
  206614. - (void) setMarkedText: (id) aString selectedRange: (NSRange) selectionRange
  206615. {
  206616. if (stringBeingComposed == 0)
  206617. stringBeingComposed = new String();
  206618. *stringBeingComposed = nsStringToJuce ([aString isKindOfClass:[NSAttributedString class]] ? [aString string] : aString);
  206619. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206620. if (target != 0)
  206621. {
  206622. const Range<int> currentHighlight (target->getHighlightedRegion());
  206623. target->insertTextAtCaret (*stringBeingComposed);
  206624. target->setHighlightedRegion (currentHighlight.withLength (stringBeingComposed->length()));
  206625. textWasInserted = true;
  206626. }
  206627. }
  206628. - (void) unmarkText
  206629. {
  206630. if (stringBeingComposed != 0)
  206631. {
  206632. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206633. if (target != 0)
  206634. {
  206635. target->insertTextAtCaret (*stringBeingComposed);
  206636. textWasInserted = true;
  206637. }
  206638. }
  206639. deleteAndZero (stringBeingComposed);
  206640. }
  206641. - (BOOL) hasMarkedText
  206642. {
  206643. return stringBeingComposed != 0;
  206644. }
  206645. - (long) conversationIdentifier
  206646. {
  206647. return (long) (pointer_sized_int) self;
  206648. }
  206649. - (NSAttributedString*) attributedSubstringFromRange: (NSRange) theRange
  206650. {
  206651. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206652. if (target != 0)
  206653. {
  206654. const Range<int> r ((int) theRange.location,
  206655. (int) (theRange.location + theRange.length));
  206656. return [[[NSAttributedString alloc] initWithString: juceStringToNS (target->getTextInRange (r))] autorelease];
  206657. }
  206658. return nil;
  206659. }
  206660. - (NSRange) markedRange
  206661. {
  206662. return stringBeingComposed != 0 ? NSMakeRange (0, stringBeingComposed->length())
  206663. : NSMakeRange (NSNotFound, 0);
  206664. }
  206665. - (NSRange) selectedRange
  206666. {
  206667. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206668. if (target != 0)
  206669. {
  206670. const Range<int> highlight (target->getHighlightedRegion());
  206671. if (! highlight.isEmpty())
  206672. return NSMakeRange (highlight.getStart(), highlight.getLength());
  206673. }
  206674. return NSMakeRange (NSNotFound, 0);
  206675. }
  206676. - (NSRect) firstRectForCharacterRange: (NSRange) theRange
  206677. {
  206678. JUCE_NAMESPACE::Component* const comp = dynamic_cast <JUCE_NAMESPACE::Component*> (owner->findCurrentTextInputTarget());
  206679. if (comp == 0)
  206680. return NSMakeRect (0, 0, 0, 0);
  206681. const Rectangle<int> bounds (comp->getScreenBounds());
  206682. return NSMakeRect (bounds.getX(),
  206683. [[[NSScreen screens] objectAtIndex: 0] frame].size.height - bounds.getY(),
  206684. bounds.getWidth(),
  206685. bounds.getHeight());
  206686. }
  206687. - (unsigned int) characterIndexForPoint: (NSPoint) thePoint
  206688. {
  206689. return NSNotFound;
  206690. }
  206691. - (NSArray*) validAttributesForMarkedText
  206692. {
  206693. return [NSArray array];
  206694. }
  206695. - (void) flagsChanged: (NSEvent*) ev
  206696. {
  206697. if (owner != 0)
  206698. owner->redirectModKeyChange (ev);
  206699. }
  206700. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206701. - (BOOL) performKeyEquivalent: (NSEvent*) ev
  206702. {
  206703. if (owner != 0 && owner->redirectPerformKeyEquivalent (ev))
  206704. return true;
  206705. return [super performKeyEquivalent: ev];
  206706. }
  206707. #endif
  206708. - (BOOL) becomeFirstResponder
  206709. {
  206710. if (owner != 0)
  206711. owner->viewFocusGain();
  206712. return true;
  206713. }
  206714. - (BOOL) resignFirstResponder
  206715. {
  206716. if (owner != 0)
  206717. owner->viewFocusLoss();
  206718. return true;
  206719. }
  206720. - (BOOL) acceptsFirstResponder
  206721. {
  206722. return owner != 0 && owner->canBecomeKeyWindow();
  206723. }
  206724. - (NSArray*) getSupportedDragTypes
  206725. {
  206726. return [NSArray arrayWithObjects: NSFilenamesPboardType, /*NSFilesPromisePboardType, NSStringPboardType,*/ nil];
  206727. }
  206728. - (BOOL) sendDragCallback: (int) type sender: (id <NSDraggingInfo>) sender
  206729. {
  206730. return owner != 0 && owner->sendDragCallback (type, sender);
  206731. }
  206732. - (NSDragOperation) draggingEntered: (id <NSDraggingInfo>) sender
  206733. {
  206734. if ([self sendDragCallback: 0 sender: sender])
  206735. return NSDragOperationCopy | NSDragOperationMove | NSDragOperationGeneric;
  206736. else
  206737. return NSDragOperationNone;
  206738. }
  206739. - (NSDragOperation) draggingUpdated: (id <NSDraggingInfo>) sender
  206740. {
  206741. if ([self sendDragCallback: 0 sender: sender])
  206742. return NSDragOperationCopy | NSDragOperationMove | NSDragOperationGeneric;
  206743. else
  206744. return NSDragOperationNone;
  206745. }
  206746. - (void) draggingEnded: (id <NSDraggingInfo>) sender
  206747. {
  206748. [self sendDragCallback: 1 sender: sender];
  206749. }
  206750. - (void) draggingExited: (id <NSDraggingInfo>) sender
  206751. {
  206752. [self sendDragCallback: 1 sender: sender];
  206753. }
  206754. - (BOOL) prepareForDragOperation: (id <NSDraggingInfo>) sender
  206755. {
  206756. return YES;
  206757. }
  206758. - (BOOL) performDragOperation: (id <NSDraggingInfo>) sender
  206759. {
  206760. return [self sendDragCallback: 2 sender: sender];
  206761. }
  206762. - (void) concludeDragOperation: (id <NSDraggingInfo>) sender
  206763. {
  206764. }
  206765. @end
  206766. @implementation JuceNSWindow
  206767. - (void) setOwner: (NSViewComponentPeer*) owner_
  206768. {
  206769. owner = owner_;
  206770. isZooming = false;
  206771. }
  206772. - (BOOL) canBecomeKeyWindow
  206773. {
  206774. return owner != 0 && owner->canBecomeKeyWindow();
  206775. }
  206776. - (void) becomeKeyWindow
  206777. {
  206778. [super becomeKeyWindow];
  206779. if (owner != 0)
  206780. owner->grabFocus();
  206781. }
  206782. - (BOOL) windowShouldClose: (id) window
  206783. {
  206784. return owner == 0 || owner->windowShouldClose();
  206785. }
  206786. - (NSRect) constrainFrameRect: (NSRect) frameRect toScreen: (NSScreen*) screen
  206787. {
  206788. if (owner != 0)
  206789. frameRect = owner->constrainRect (frameRect);
  206790. return frameRect;
  206791. }
  206792. - (NSSize) windowWillResize: (NSWindow*) window toSize: (NSSize) proposedFrameSize
  206793. {
  206794. if (isZooming)
  206795. return proposedFrameSize;
  206796. NSRect frameRect = [self frame];
  206797. frameRect.origin.y -= proposedFrameSize.height - frameRect.size.height;
  206798. frameRect.size = proposedFrameSize;
  206799. if (owner != 0)
  206800. frameRect = owner->constrainRect (frameRect);
  206801. return frameRect.size;
  206802. }
  206803. - (void) zoom: (id) sender
  206804. {
  206805. isZooming = true;
  206806. [super zoom: sender];
  206807. isZooming = false;
  206808. }
  206809. - (void) windowWillMove: (NSNotification*) notification
  206810. {
  206811. if (JUCE_NAMESPACE::Component::getCurrentlyModalComponent() != 0
  206812. && owner->getComponent()->isCurrentlyBlockedByAnotherModalComponent()
  206813. && (owner->getStyleFlags() & JUCE_NAMESPACE::ComponentPeer::windowHasTitleBar) != 0)
  206814. JUCE_NAMESPACE::Component::getCurrentlyModalComponent()->inputAttemptWhenModal();
  206815. }
  206816. @end
  206817. BEGIN_JUCE_NAMESPACE
  206818. ModifierKeys NSViewComponentPeer::currentModifiers;
  206819. ComponentPeer* NSViewComponentPeer::currentlyFocusedPeer = 0;
  206820. VoidArray NSViewComponentPeer::keysCurrentlyDown;
  206821. bool KeyPress::isKeyCurrentlyDown (const int keyCode) throw()
  206822. {
  206823. if (NSViewComponentPeer::keysCurrentlyDown.contains ((void*) keyCode))
  206824. return true;
  206825. if (keyCode >= 'A' && keyCode <= 'Z'
  206826. && NSViewComponentPeer::keysCurrentlyDown.contains ((void*) (int) CharacterFunctions::toLowerCase ((tchar) keyCode)))
  206827. return true;
  206828. if (keyCode >= 'a' && keyCode <= 'z'
  206829. && NSViewComponentPeer::keysCurrentlyDown.contains ((void*) (int) CharacterFunctions::toUpperCase ((tchar) keyCode)))
  206830. return true;
  206831. return false;
  206832. }
  206833. void NSViewComponentPeer::updateModifiers (NSEvent* e)
  206834. {
  206835. int m = 0;
  206836. if (([e modifierFlags] & NSShiftKeyMask) != 0) m |= ModifierKeys::shiftModifier;
  206837. if (([e modifierFlags] & NSControlKeyMask) != 0) m |= ModifierKeys::ctrlModifier;
  206838. if (([e modifierFlags] & NSAlternateKeyMask) != 0) m |= ModifierKeys::altModifier;
  206839. if (([e modifierFlags] & NSCommandKeyMask) != 0) m |= ModifierKeys::commandModifier;
  206840. currentModifiers = currentModifiers.withOnlyMouseButtons().withFlags (m);
  206841. }
  206842. void NSViewComponentPeer::updateKeysDown (NSEvent* ev, bool isKeyDown)
  206843. {
  206844. updateModifiers (ev);
  206845. int keyCode = getKeyCodeFromEvent (ev);
  206846. if (keyCode != 0)
  206847. {
  206848. if (isKeyDown)
  206849. keysCurrentlyDown.addIfNotAlreadyThere ((void*) keyCode);
  206850. else
  206851. keysCurrentlyDown.removeValue ((void*) keyCode);
  206852. }
  206853. }
  206854. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  206855. {
  206856. return NSViewComponentPeer::currentModifiers;
  206857. }
  206858. void ModifierKeys::updateCurrentModifiers() throw()
  206859. {
  206860. currentModifiers = NSViewComponentPeer::currentModifiers;
  206861. }
  206862. NSViewComponentPeer::NSViewComponentPeer (Component* const component_,
  206863. const int windowStyleFlags,
  206864. NSView* viewToAttachTo)
  206865. : ComponentPeer (component_, windowStyleFlags),
  206866. window (0),
  206867. view (0),
  206868. isSharedWindow (viewToAttachTo != 0),
  206869. fullScreen (false),
  206870. insideDrawRect (false),
  206871. #if USE_COREGRAPHICS_RENDERING
  206872. usingCoreGraphics (true),
  206873. #else
  206874. usingCoreGraphics (false),
  206875. #endif
  206876. recursiveToFrontCall (false)
  206877. {
  206878. NSRect r;
  206879. r.origin.x = 0;
  206880. r.origin.y = 0;
  206881. r.size.width = (float) component->getWidth();
  206882. r.size.height = (float) component->getHeight();
  206883. view = [[JuceNSView alloc] initWithOwner: this withFrame: r];
  206884. [view setPostsFrameChangedNotifications: YES];
  206885. if (isSharedWindow)
  206886. {
  206887. window = [viewToAttachTo window];
  206888. [viewToAttachTo addSubview: view];
  206889. setVisible (component->isVisible());
  206890. }
  206891. else
  206892. {
  206893. r.origin.x = (float) component->getX();
  206894. r.origin.y = (float) component->getY();
  206895. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - (r.origin.y + r.size.height);
  206896. unsigned int style = 0;
  206897. if ((windowStyleFlags & windowHasTitleBar) == 0)
  206898. style = NSBorderlessWindowMask;
  206899. else
  206900. style = NSTitledWindowMask;
  206901. if ((windowStyleFlags & windowHasMinimiseButton) != 0)
  206902. style |= NSMiniaturizableWindowMask;
  206903. if ((windowStyleFlags & windowHasCloseButton) != 0)
  206904. style |= NSClosableWindowMask;
  206905. if ((windowStyleFlags & windowIsResizable) != 0)
  206906. style |= NSResizableWindowMask;
  206907. window = [[JuceNSWindow alloc] initWithContentRect: r
  206908. styleMask: style
  206909. backing: NSBackingStoreBuffered
  206910. defer: YES];
  206911. [((JuceNSWindow*) window) setOwner: this];
  206912. [window orderOut: nil];
  206913. [window setDelegate: (JuceNSWindow*) window];
  206914. [window setOpaque: component->isOpaque()];
  206915. [window setHasShadow: ((windowStyleFlags & windowHasDropShadow) != 0)];
  206916. if (component->isAlwaysOnTop())
  206917. [window setLevel: NSFloatingWindowLevel];
  206918. [window setContentView: view];
  206919. [window setAutodisplay: YES];
  206920. [window setAcceptsMouseMovedEvents: YES];
  206921. // We'll both retain and also release this on closing because plugin hosts can unexpectedly
  206922. // close the window for us, and also tend to get cause trouble if setReleasedWhenClosed is NO.
  206923. [window setReleasedWhenClosed: YES];
  206924. [window retain];
  206925. [window setExcludedFromWindowsMenu: (windowStyleFlags & windowIsTemporary) != 0];
  206926. [window setIgnoresMouseEvents: (windowStyleFlags & windowIgnoresMouseClicks) != 0];
  206927. }
  206928. setTitle (component->getName());
  206929. }
  206930. NSViewComponentPeer::~NSViewComponentPeer()
  206931. {
  206932. view->owner = 0;
  206933. [view removeFromSuperview];
  206934. [view release];
  206935. if (! isSharedWindow)
  206936. {
  206937. [((JuceNSWindow*) window) setOwner: 0];
  206938. [window close];
  206939. [window release];
  206940. }
  206941. }
  206942. void* NSViewComponentPeer::getNativeHandle() const
  206943. {
  206944. return view;
  206945. }
  206946. void NSViewComponentPeer::setVisible (bool shouldBeVisible)
  206947. {
  206948. if (isSharedWindow)
  206949. {
  206950. [view setHidden: ! shouldBeVisible];
  206951. }
  206952. else
  206953. {
  206954. if (shouldBeVisible)
  206955. {
  206956. [window orderFront: nil];
  206957. handleBroughtToFront();
  206958. }
  206959. else
  206960. {
  206961. [window orderOut: nil];
  206962. }
  206963. }
  206964. }
  206965. void NSViewComponentPeer::setTitle (const String& title)
  206966. {
  206967. const ScopedAutoReleasePool pool;
  206968. if (! isSharedWindow)
  206969. [window setTitle: juceStringToNS (title)];
  206970. }
  206971. void NSViewComponentPeer::setPosition (int x, int y)
  206972. {
  206973. setBounds (x, y, component->getWidth(), component->getHeight(), false);
  206974. }
  206975. void NSViewComponentPeer::setSize (int w, int h)
  206976. {
  206977. setBounds (component->getX(), component->getY(), w, h, false);
  206978. }
  206979. void NSViewComponentPeer::setBounds (int x, int y, int w, int h, const bool isNowFullScreen)
  206980. {
  206981. fullScreen = isNowFullScreen;
  206982. w = jmax (0, w);
  206983. h = jmax (0, h);
  206984. NSRect r;
  206985. r.origin.x = (float) x;
  206986. r.origin.y = (float) y;
  206987. r.size.width = (float) w;
  206988. r.size.height = (float) h;
  206989. if (isSharedWindow)
  206990. {
  206991. r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  206992. if ([view frame].size.width != r.size.width
  206993. || [view frame].size.height != r.size.height)
  206994. [view setNeedsDisplay: true];
  206995. [view setFrame: r];
  206996. }
  206997. else
  206998. {
  206999. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - (r.origin.y + r.size.height);
  207000. [window setFrame: [window frameRectForContentRect: r]
  207001. display: true];
  207002. }
  207003. }
  207004. const Rectangle<int> NSViewComponentPeer::getBounds (const bool global) const
  207005. {
  207006. NSRect r = [view frame];
  207007. if (global && [view window] != 0)
  207008. {
  207009. r = [view convertRect: r toView: nil];
  207010. NSRect wr = [[view window] frame];
  207011. r.origin.x += wr.origin.x;
  207012. r.origin.y += wr.origin.y;
  207013. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.origin.y - r.size.height;
  207014. }
  207015. else
  207016. {
  207017. r.origin.y = [[view superview] frame].size.height - r.origin.y - r.size.height;
  207018. }
  207019. return Rectangle<int> ((int) r.origin.x, (int) r.origin.y, (int) r.size.width, (int) r.size.height);
  207020. }
  207021. const Rectangle<int> NSViewComponentPeer::getBounds() const
  207022. {
  207023. return getBounds (! isSharedWindow);
  207024. }
  207025. const Point<int> NSViewComponentPeer::getScreenPosition() const
  207026. {
  207027. return getBounds (true).getPosition();
  207028. }
  207029. const Point<int> NSViewComponentPeer::relativePositionToGlobal (const Point<int>& relativePosition)
  207030. {
  207031. return relativePosition + getScreenPosition();
  207032. }
  207033. const Point<int> NSViewComponentPeer::globalPositionToRelative (const Point<int>& screenPosition)
  207034. {
  207035. return screenPosition - getScreenPosition();
  207036. }
  207037. NSRect NSViewComponentPeer::constrainRect (NSRect r)
  207038. {
  207039. if (constrainer != 0)
  207040. {
  207041. NSRect current = [window frame];
  207042. current.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - current.origin.y - current.size.height;
  207043. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.origin.y - r.size.height;
  207044. Rectangle<int> pos ((int) r.origin.x, (int) r.origin.y,
  207045. (int) r.size.width, (int) r.size.height);
  207046. Rectangle<int> original ((int) current.origin.x, (int) current.origin.y,
  207047. (int) current.size.width, (int) current.size.height);
  207048. constrainer->checkBounds (pos, original,
  207049. Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(),
  207050. pos.getY() != original.getY() && pos.getBottom() == original.getBottom(),
  207051. pos.getX() != original.getX() && pos.getRight() == original.getRight(),
  207052. pos.getY() == original.getY() && pos.getBottom() != original.getBottom(),
  207053. pos.getX() == original.getX() && pos.getRight() != original.getRight());
  207054. r.origin.x = pos.getX();
  207055. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.size.height - pos.getY();
  207056. r.size.width = pos.getWidth();
  207057. r.size.height = pos.getHeight();
  207058. }
  207059. return r;
  207060. }
  207061. void NSViewComponentPeer::setMinimised (bool shouldBeMinimised)
  207062. {
  207063. if (! isSharedWindow)
  207064. {
  207065. if (shouldBeMinimised)
  207066. [window miniaturize: nil];
  207067. else
  207068. [window deminiaturize: nil];
  207069. }
  207070. }
  207071. bool NSViewComponentPeer::isMinimised() const
  207072. {
  207073. return window != 0 && [window isMiniaturized];
  207074. }
  207075. void NSViewComponentPeer::setFullScreen (bool shouldBeFullScreen)
  207076. {
  207077. if (! isSharedWindow)
  207078. {
  207079. Rectangle<int> r (lastNonFullscreenBounds);
  207080. setMinimised (false);
  207081. if (fullScreen != shouldBeFullScreen)
  207082. {
  207083. if (shouldBeFullScreen && (getStyleFlags() & windowHasTitleBar) != 0)
  207084. {
  207085. fullScreen = true;
  207086. [window performZoom: nil];
  207087. }
  207088. else
  207089. {
  207090. if (shouldBeFullScreen)
  207091. r = Desktop::getInstance().getMainMonitorArea();
  207092. // (can't call the component's setBounds method because that'll reset our fullscreen flag)
  207093. if (r != getComponent()->getBounds() && ! r.isEmpty())
  207094. setBounds (r.getX(), r.getY(), r.getWidth(), r.getHeight(), shouldBeFullScreen);
  207095. }
  207096. }
  207097. }
  207098. }
  207099. bool NSViewComponentPeer::isFullScreen() const
  207100. {
  207101. return fullScreen;
  207102. }
  207103. bool NSViewComponentPeer::contains (const Point<int>& position, bool trueIfInAChildWindow) const
  207104. {
  207105. if (((unsigned int) position.getX()) >= (unsigned int) component->getWidth()
  207106. || ((unsigned int) position.getY()) >= (unsigned int) component->getHeight())
  207107. return false;
  207108. NSPoint p;
  207109. p.x = (float) position.getX();
  207110. p.y = (float) position.getY();
  207111. NSView* v = [view hitTest: p];
  207112. if (trueIfInAChildWindow)
  207113. return v != nil;
  207114. return v == view;
  207115. }
  207116. const BorderSize NSViewComponentPeer::getFrameSize() const
  207117. {
  207118. BorderSize b;
  207119. if (! isSharedWindow)
  207120. {
  207121. NSRect v = [view convertRect: [view frame] toView: nil];
  207122. NSRect w = [window frame];
  207123. b.setTop ((int) (w.size.height - (v.origin.y + v.size.height)));
  207124. b.setBottom ((int) v.origin.y);
  207125. b.setLeft ((int) v.origin.x);
  207126. b.setRight ((int) (w.size.width - (v.origin.x + v.size.width)));
  207127. }
  207128. return b;
  207129. }
  207130. bool NSViewComponentPeer::setAlwaysOnTop (bool alwaysOnTop)
  207131. {
  207132. if (! isSharedWindow)
  207133. {
  207134. [window setLevel: alwaysOnTop ? NSFloatingWindowLevel
  207135. : NSNormalWindowLevel];
  207136. }
  207137. return true;
  207138. }
  207139. void NSViewComponentPeer::toFront (bool makeActiveWindow)
  207140. {
  207141. if (isSharedWindow)
  207142. {
  207143. [[view superview] addSubview: view
  207144. positioned: NSWindowAbove
  207145. relativeTo: nil];
  207146. }
  207147. if (window != 0 && component->isVisible())
  207148. {
  207149. if (makeActiveWindow)
  207150. [window makeKeyAndOrderFront: nil];
  207151. else
  207152. [window orderFront: nil];
  207153. if (! recursiveToFrontCall)
  207154. {
  207155. recursiveToFrontCall = true;
  207156. handleBroughtToFront();
  207157. recursiveToFrontCall = false;
  207158. }
  207159. }
  207160. }
  207161. void NSViewComponentPeer::toBehind (ComponentPeer* other)
  207162. {
  207163. NSViewComponentPeer* o = (NSViewComponentPeer*) other;
  207164. if (isSharedWindow)
  207165. {
  207166. [[view superview] addSubview: view
  207167. positioned: NSWindowBelow
  207168. relativeTo: o->view];
  207169. }
  207170. else
  207171. {
  207172. [window orderWindow: NSWindowBelow
  207173. relativeTo: o->window != 0 ? [o->window windowNumber]
  207174. : nil ];
  207175. }
  207176. }
  207177. void NSViewComponentPeer::setIcon (const Image& /*newIcon*/)
  207178. {
  207179. // to do..
  207180. }
  207181. void NSViewComponentPeer::viewFocusGain()
  207182. {
  207183. if (currentlyFocusedPeer != this)
  207184. {
  207185. if (ComponentPeer::isValidPeer (currentlyFocusedPeer))
  207186. currentlyFocusedPeer->handleFocusLoss();
  207187. currentlyFocusedPeer = this;
  207188. handleFocusGain();
  207189. }
  207190. }
  207191. void NSViewComponentPeer::viewFocusLoss()
  207192. {
  207193. if (currentlyFocusedPeer == this)
  207194. {
  207195. currentlyFocusedPeer = 0;
  207196. handleFocusLoss();
  207197. }
  207198. }
  207199. void juce_HandleProcessFocusChange()
  207200. {
  207201. NSViewComponentPeer::keysCurrentlyDown.clear();
  207202. if (NSViewComponentPeer::isValidPeer (NSViewComponentPeer::currentlyFocusedPeer))
  207203. {
  207204. if (Process::isForegroundProcess())
  207205. {
  207206. NSViewComponentPeer::currentlyFocusedPeer->handleFocusGain();
  207207. ComponentPeer::bringModalComponentToFront();
  207208. }
  207209. else
  207210. {
  207211. NSViewComponentPeer::currentlyFocusedPeer->handleFocusLoss();
  207212. // turn kiosk mode off if we lose focus..
  207213. Desktop::getInstance().setKioskModeComponent (0);
  207214. }
  207215. }
  207216. }
  207217. bool NSViewComponentPeer::isFocused() const
  207218. {
  207219. return isSharedWindow ? this == currentlyFocusedPeer
  207220. : (window != 0 && [window isKeyWindow]);
  207221. }
  207222. void NSViewComponentPeer::grabFocus()
  207223. {
  207224. if (window != 0)
  207225. {
  207226. [window makeKeyWindow];
  207227. [window makeFirstResponder: view];
  207228. viewFocusGain();
  207229. }
  207230. }
  207231. void NSViewComponentPeer::textInputRequired (const Point<int>&)
  207232. {
  207233. }
  207234. bool NSViewComponentPeer::handleKeyEvent (NSEvent* ev, bool isKeyDown)
  207235. {
  207236. String unicode (nsStringToJuce ([ev characters]));
  207237. String unmodified (nsStringToJuce ([ev charactersIgnoringModifiers]));
  207238. int keyCode = getKeyCodeFromEvent (ev);
  207239. //DBG ("unicode: " + unicode + " " + String::toHexString ((int) unicode[0]));
  207240. //DBG ("unmodified: " + unmodified + " " + String::toHexString ((int) unmodified[0]));
  207241. if (unicode.isNotEmpty() || keyCode != 0)
  207242. {
  207243. if (isKeyDown)
  207244. {
  207245. bool used = false;
  207246. while (unicode.length() > 0)
  207247. {
  207248. juce_wchar textCharacter = unicode[0];
  207249. unicode = unicode.substring (1);
  207250. if (([ev modifierFlags] & NSCommandKeyMask) != 0)
  207251. textCharacter = 0;
  207252. used = handleKeyUpOrDown (true) || used;
  207253. used = handleKeyPress (keyCode, textCharacter) || used;
  207254. }
  207255. return used;
  207256. }
  207257. else
  207258. {
  207259. if (handleKeyUpOrDown (false))
  207260. return true;
  207261. }
  207262. }
  207263. return false;
  207264. }
  207265. bool NSViewComponentPeer::redirectKeyDown (NSEvent* ev)
  207266. {
  207267. updateKeysDown (ev, true);
  207268. bool used = handleKeyEvent (ev, true);
  207269. if (([ev modifierFlags] & NSCommandKeyMask) != 0)
  207270. {
  207271. // for command keys, the key-up event is thrown away, so simulate one..
  207272. updateKeysDown (ev, false);
  207273. used = (isValidPeer (this) && handleKeyEvent (ev, false)) || used;
  207274. }
  207275. // (If we're running modally, don't allow unused keystrokes to be passed
  207276. // along to other blocked views..)
  207277. if (Component::getCurrentlyModalComponent() != 0)
  207278. used = true;
  207279. return used;
  207280. }
  207281. bool NSViewComponentPeer::redirectKeyUp (NSEvent* ev)
  207282. {
  207283. updateKeysDown (ev, false);
  207284. return handleKeyEvent (ev, false)
  207285. || Component::getCurrentlyModalComponent() != 0;
  207286. }
  207287. void NSViewComponentPeer::redirectModKeyChange (NSEvent* ev)
  207288. {
  207289. keysCurrentlyDown.clear();
  207290. handleKeyUpOrDown (true);
  207291. updateModifiers (ev);
  207292. handleModifierKeysChange();
  207293. }
  207294. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  207295. bool NSViewComponentPeer::redirectPerformKeyEquivalent (NSEvent* ev)
  207296. {
  207297. if ([ev type] == NSKeyDown)
  207298. return redirectKeyDown (ev);
  207299. else if ([ev type] == NSKeyUp)
  207300. return redirectKeyUp (ev);
  207301. return false;
  207302. }
  207303. #endif
  207304. void NSViewComponentPeer::sendMouseEvent (NSEvent* ev)
  207305. {
  207306. updateModifiers (ev);
  207307. handleMouseEvent (0, getMousePos (ev, view), currentModifiers, getMouseTime (ev));
  207308. }
  207309. void NSViewComponentPeer::redirectMouseDown (NSEvent* ev)
  207310. {
  207311. currentModifiers = currentModifiers.withFlags (getModifierForButtonNumber ([ev buttonNumber]));
  207312. sendMouseEvent (ev);
  207313. }
  207314. void NSViewComponentPeer::redirectMouseUp (NSEvent* ev)
  207315. {
  207316. currentModifiers = currentModifiers.withoutFlags (getModifierForButtonNumber ([ev buttonNumber]));
  207317. sendMouseEvent (ev);
  207318. showArrowCursorIfNeeded();
  207319. }
  207320. void NSViewComponentPeer::redirectMouseDrag (NSEvent* ev)
  207321. {
  207322. currentModifiers = currentModifiers.withFlags (getModifierForButtonNumber ([ev buttonNumber]));
  207323. sendMouseEvent (ev);
  207324. }
  207325. void NSViewComponentPeer::redirectMouseMove (NSEvent* ev)
  207326. {
  207327. currentModifiers = currentModifiers.withoutMouseButtons();
  207328. sendMouseEvent (ev);
  207329. showArrowCursorIfNeeded();
  207330. }
  207331. void NSViewComponentPeer::redirectMouseEnter (NSEvent* ev)
  207332. {
  207333. currentModifiers = currentModifiers.withoutMouseButtons();
  207334. sendMouseEvent (ev);
  207335. }
  207336. void NSViewComponentPeer::redirectMouseExit (NSEvent* ev)
  207337. {
  207338. currentModifiers = currentModifiers.withoutMouseButtons();
  207339. sendMouseEvent (ev);
  207340. }
  207341. void NSViewComponentPeer::redirectMouseWheel (NSEvent* ev)
  207342. {
  207343. updateModifiers (ev);
  207344. handleMouseWheel (0, getMousePos (ev, view), getMouseTime (ev),
  207345. [ev deltaX] * 10.0f, [ev deltaY] * 10.0f);
  207346. }
  207347. void NSViewComponentPeer::showArrowCursorIfNeeded()
  207348. {
  207349. MouseInputSource& mouse = Desktop::getInstance().getMainMouseSource();
  207350. if (mouse.getComponentUnderMouse() == 0
  207351. && Desktop::getInstance().findComponentAt (mouse.getScreenPosition()) == 0)
  207352. {
  207353. [[NSCursor arrowCursor] set];
  207354. }
  207355. }
  207356. BOOL NSViewComponentPeer::sendDragCallback (int type, id <NSDraggingInfo> sender)
  207357. {
  207358. NSString* bestType
  207359. = [[sender draggingPasteboard] availableTypeFromArray: [view getSupportedDragTypes]];
  207360. if (bestType == nil)
  207361. return false;
  207362. NSPoint p = [view convertPoint: [sender draggingLocation] fromView: nil];
  207363. const Point<int> pos ((int) p.x, (int) ([view frame].size.height - p.y));
  207364. StringArray files;
  207365. id list = [[sender draggingPasteboard] propertyListForType: bestType];
  207366. if (list == nil)
  207367. return false;
  207368. if ([list isKindOfClass: [NSArray class]])
  207369. {
  207370. NSArray* items = (NSArray*) list;
  207371. for (unsigned int i = 0; i < [items count]; ++i)
  207372. files.add (nsStringToJuce ((NSString*) [items objectAtIndex: i]));
  207373. }
  207374. if (files.size() == 0)
  207375. return false;
  207376. if (type == 0)
  207377. handleFileDragMove (files, pos);
  207378. else if (type == 1)
  207379. handleFileDragExit (files);
  207380. else if (type == 2)
  207381. handleFileDragDrop (files, pos);
  207382. return true;
  207383. }
  207384. bool NSViewComponentPeer::isOpaque()
  207385. {
  207386. return component == 0 || component->isOpaque();
  207387. }
  207388. void NSViewComponentPeer::drawRect (NSRect r)
  207389. {
  207390. if (r.size.width < 1.0f || r.size.height < 1.0f)
  207391. return;
  207392. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  207393. if (! component->isOpaque())
  207394. CGContextClearRect (cg, CGContextGetClipBoundingBox (cg));
  207395. #if USE_COREGRAPHICS_RENDERING
  207396. if (usingCoreGraphics)
  207397. {
  207398. CoreGraphicsContext context (cg, (float) [view frame].size.height);
  207399. insideDrawRect = true;
  207400. handlePaint (context);
  207401. insideDrawRect = false;
  207402. }
  207403. else
  207404. #endif
  207405. {
  207406. Image temp (getComponent()->isOpaque() ? Image::RGB : Image::ARGB,
  207407. (int) (r.size.width + 0.5f),
  207408. (int) (r.size.height + 0.5f),
  207409. ! getComponent()->isOpaque());
  207410. LowLevelGraphicsSoftwareRenderer context (temp);
  207411. context.setOrigin (-roundToInt (r.origin.x),
  207412. -roundToInt ([view frame].size.height - (r.origin.y + r.size.height)));
  207413. const NSRect* rects = 0;
  207414. NSInteger numRects = 0;
  207415. [view getRectsBeingDrawn: &rects count: &numRects];
  207416. RectangleList clip;
  207417. for (int i = 0; i < numRects; ++i)
  207418. {
  207419. clip.addWithoutMerging (Rectangle<int> (roundToInt (rects[i].origin.x),
  207420. roundToInt ([view frame].size.height - (rects[i].origin.y + rects[i].size.height)),
  207421. roundToInt (rects[i].size.width),
  207422. roundToInt (rects[i].size.height)));
  207423. }
  207424. if (context.clipToRectangleList (clip))
  207425. {
  207426. insideDrawRect = true;
  207427. handlePaint (context);
  207428. insideDrawRect = false;
  207429. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  207430. CGImageRef image = CoreGraphicsImage::createImage (temp, false, colourSpace);
  207431. CGColorSpaceRelease (colourSpace);
  207432. CGContextDrawImage (cg, CGRectMake (r.origin.x, r.origin.y, temp.getWidth(), temp.getHeight()), image);
  207433. CGImageRelease (image);
  207434. }
  207435. }
  207436. }
  207437. const StringArray NSViewComponentPeer::getAvailableRenderingEngines() throw()
  207438. {
  207439. StringArray s;
  207440. s.add ("Software Renderer");
  207441. #if USE_COREGRAPHICS_RENDERING
  207442. s.add ("CoreGraphics Renderer");
  207443. #endif
  207444. return s;
  207445. }
  207446. int NSViewComponentPeer::getCurrentRenderingEngine() throw()
  207447. {
  207448. return usingCoreGraphics ? 1 : 0;
  207449. }
  207450. void NSViewComponentPeer::setCurrentRenderingEngine (int index) throw()
  207451. {
  207452. #if USE_COREGRAPHICS_RENDERING
  207453. if (usingCoreGraphics != (index > 0))
  207454. {
  207455. usingCoreGraphics = index > 0;
  207456. [view setNeedsDisplay: true];
  207457. }
  207458. #endif
  207459. }
  207460. bool NSViewComponentPeer::canBecomeKeyWindow()
  207461. {
  207462. return (getStyleFlags() & JUCE_NAMESPACE::ComponentPeer::windowIgnoresKeyPresses) == 0;
  207463. }
  207464. bool NSViewComponentPeer::windowShouldClose()
  207465. {
  207466. if (! isValidPeer (this))
  207467. return YES;
  207468. handleUserClosingWindow();
  207469. return NO;
  207470. }
  207471. void NSViewComponentPeer::redirectMovedOrResized()
  207472. {
  207473. handleMovedOrResized();
  207474. }
  207475. void NSViewComponentPeer::viewMovedToWindow()
  207476. {
  207477. if (isSharedWindow)
  207478. window = [view window];
  207479. }
  207480. void Desktop::createMouseInputSources()
  207481. {
  207482. mouseSources.add (new MouseInputSource (0, true));
  207483. }
  207484. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  207485. {
  207486. // Very annoyingly, this function has to use the old SetSystemUIMode function,
  207487. // which is in Carbon.framework. But, because there's no Cocoa equivalent, it
  207488. // is apparently still available in 64-bit apps..
  207489. if (enableOrDisable)
  207490. {
  207491. SetSystemUIMode (kUIModeAllSuppressed, allowMenusAndBars ? kUIOptionAutoShowMenuBar : 0);
  207492. kioskModeComponent->setBounds (Desktop::getInstance().getMainMonitorArea (false));
  207493. }
  207494. else
  207495. {
  207496. SetSystemUIMode (kUIModeNormal, 0);
  207497. }
  207498. }
  207499. class AsyncRepaintMessage : public CallbackMessage
  207500. {
  207501. public:
  207502. NSViewComponentPeer* const peer;
  207503. const Rectangle<int> rect;
  207504. AsyncRepaintMessage (NSViewComponentPeer* const peer_, const Rectangle<int>& rect_)
  207505. : peer (peer_), rect (rect_)
  207506. {
  207507. }
  207508. void messageCallback()
  207509. {
  207510. if (ComponentPeer::isValidPeer (peer))
  207511. peer->repaint (rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
  207512. }
  207513. };
  207514. void NSViewComponentPeer::repaint (int x, int y, int w, int h)
  207515. {
  207516. if (insideDrawRect)
  207517. {
  207518. (new AsyncRepaintMessage (this, Rectangle<int> (x, y, w, h)))->post();
  207519. }
  207520. else
  207521. {
  207522. [view setNeedsDisplayInRect: NSMakeRect ((float) x, (float) ([view frame].size.height - (y + h)),
  207523. (float) w, (float) h)];
  207524. }
  207525. }
  207526. void NSViewComponentPeer::performAnyPendingRepaintsNow()
  207527. {
  207528. [view displayIfNeeded];
  207529. }
  207530. ComponentPeer* Component::createNewPeer (int styleFlags, void* windowToAttachTo)
  207531. {
  207532. return new NSViewComponentPeer (this, styleFlags, (NSView*) windowToAttachTo);
  207533. }
  207534. Image* juce_createIconForFile (const File& file)
  207535. {
  207536. const ScopedAutoReleasePool pool;
  207537. NSImage* image = [[NSWorkspace sharedWorkspace] iconForFile: juceStringToNS (file.getFullPathName())];
  207538. CoreGraphicsImage* result = new CoreGraphicsImage (Image::ARGB, (int) [image size].width, (int) [image size].height, true);
  207539. [NSGraphicsContext saveGraphicsState];
  207540. [NSGraphicsContext setCurrentContext: [NSGraphicsContext graphicsContextWithGraphicsPort: result->context flipped: false]];
  207541. [image drawAtPoint: NSMakePoint (0, 0)
  207542. fromRect: NSMakeRect (0, 0, [image size].width, [image size].height)
  207543. operation: NSCompositeSourceOver fraction: 1.0f];
  207544. [[NSGraphicsContext currentContext] flushGraphics];
  207545. [NSGraphicsContext restoreGraphicsState];
  207546. return result;
  207547. }
  207548. const int KeyPress::spaceKey = ' ';
  207549. const int KeyPress::returnKey = 0x0d;
  207550. const int KeyPress::escapeKey = 0x1b;
  207551. const int KeyPress::backspaceKey = 0x7f;
  207552. const int KeyPress::leftKey = NSLeftArrowFunctionKey;
  207553. const int KeyPress::rightKey = NSRightArrowFunctionKey;
  207554. const int KeyPress::upKey = NSUpArrowFunctionKey;
  207555. const int KeyPress::downKey = NSDownArrowFunctionKey;
  207556. const int KeyPress::pageUpKey = NSPageUpFunctionKey;
  207557. const int KeyPress::pageDownKey = NSPageDownFunctionKey;
  207558. const int KeyPress::endKey = NSEndFunctionKey;
  207559. const int KeyPress::homeKey = NSHomeFunctionKey;
  207560. const int KeyPress::deleteKey = NSDeleteFunctionKey;
  207561. const int KeyPress::insertKey = -1;
  207562. const int KeyPress::tabKey = 9;
  207563. const int KeyPress::F1Key = NSF1FunctionKey;
  207564. const int KeyPress::F2Key = NSF2FunctionKey;
  207565. const int KeyPress::F3Key = NSF3FunctionKey;
  207566. const int KeyPress::F4Key = NSF4FunctionKey;
  207567. const int KeyPress::F5Key = NSF5FunctionKey;
  207568. const int KeyPress::F6Key = NSF6FunctionKey;
  207569. const int KeyPress::F7Key = NSF7FunctionKey;
  207570. const int KeyPress::F8Key = NSF8FunctionKey;
  207571. const int KeyPress::F9Key = NSF9FunctionKey;
  207572. const int KeyPress::F10Key = NSF10FunctionKey;
  207573. const int KeyPress::F11Key = NSF1FunctionKey;
  207574. const int KeyPress::F12Key = NSF12FunctionKey;
  207575. const int KeyPress::F13Key = NSF13FunctionKey;
  207576. const int KeyPress::F14Key = NSF14FunctionKey;
  207577. const int KeyPress::F15Key = NSF15FunctionKey;
  207578. const int KeyPress::F16Key = NSF16FunctionKey;
  207579. const int KeyPress::numberPad0 = 0x30020;
  207580. const int KeyPress::numberPad1 = 0x30021;
  207581. const int KeyPress::numberPad2 = 0x30022;
  207582. const int KeyPress::numberPad3 = 0x30023;
  207583. const int KeyPress::numberPad4 = 0x30024;
  207584. const int KeyPress::numberPad5 = 0x30025;
  207585. const int KeyPress::numberPad6 = 0x30026;
  207586. const int KeyPress::numberPad7 = 0x30027;
  207587. const int KeyPress::numberPad8 = 0x30028;
  207588. const int KeyPress::numberPad9 = 0x30029;
  207589. const int KeyPress::numberPadAdd = 0x3002a;
  207590. const int KeyPress::numberPadSubtract = 0x3002b;
  207591. const int KeyPress::numberPadMultiply = 0x3002c;
  207592. const int KeyPress::numberPadDivide = 0x3002d;
  207593. const int KeyPress::numberPadSeparator = 0x3002e;
  207594. const int KeyPress::numberPadDecimalPoint = 0x3002f;
  207595. const int KeyPress::numberPadEquals = 0x30030;
  207596. const int KeyPress::numberPadDelete = 0x30031;
  207597. const int KeyPress::playKey = 0x30000;
  207598. const int KeyPress::stopKey = 0x30001;
  207599. const int KeyPress::fastForwardKey = 0x30002;
  207600. const int KeyPress::rewindKey = 0x30003;
  207601. #endif
  207602. /*** End of inlined file: juce_mac_NSViewComponentPeer.mm ***/
  207603. /*** Start of inlined file: juce_mac_MouseCursor.mm ***/
  207604. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  207605. // compiled on its own).
  207606. #if JUCE_INCLUDED_FILE
  207607. #if JUCE_MAC
  207608. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  207609. {
  207610. NSImage* im = CoreGraphicsImage::createNSImage (image);
  207611. NSCursor* c = [[NSCursor alloc] initWithImage: im
  207612. hotSpot: NSMakePoint (hotspotX, hotspotY)];
  207613. [im release];
  207614. return (void*) c;
  207615. }
  207616. static void* juce_cursorFromData (const unsigned char* data, const size_t size, float hx, float hy) throw()
  207617. {
  207618. ScopedPointer <Image> im (ImageFileFormat::loadFrom ((const char*) data, (int) size));
  207619. jassert (im != 0);
  207620. if (im == 0)
  207621. return 0;
  207622. return juce_createMouseCursorFromImage (*im,
  207623. (int) (hx * im->getWidth()),
  207624. (int) (hy * im->getHeight()));
  207625. }
  207626. static void* juce_cursorFromWebKitFile (const char* filename, float hx, float hy)
  207627. {
  207628. File f ("/System/Library/Frameworks/WebKit.framework/Frameworks/WebCore.framework/Resources");
  207629. MemoryBlock mb;
  207630. if (f.getChildFile (filename).loadFileAsData (mb))
  207631. return juce_cursorFromData ((const unsigned char*) mb.getData(), mb.getSize(), hx, hy);
  207632. return 0;
  207633. }
  207634. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  207635. {
  207636. const ScopedAutoReleasePool pool;
  207637. NSCursor* c = 0;
  207638. switch (type)
  207639. {
  207640. case MouseCursor::NormalCursor:
  207641. c = [NSCursor arrowCursor];
  207642. break;
  207643. case MouseCursor::NoCursor:
  207644. {
  207645. Image blank (Image::ARGB, 8, 8, true);
  207646. return juce_createMouseCursorFromImage (blank, 0, 0);
  207647. }
  207648. case MouseCursor::DraggingHandCursor:
  207649. c = [NSCursor openHandCursor];
  207650. break;
  207651. case MouseCursor::CopyingCursor:
  207652. return juce_cursorFromWebKitFile ("copyCursor.png", 0, 0);
  207653. case MouseCursor::WaitCursor:
  207654. c = [NSCursor arrowCursor]; // avoid this on the mac, let the OS provide the beachball
  207655. break;
  207656. //return juce_cursorFromWebKitFile ("waitCursor.png", 0.5f, 0.5f);
  207657. case MouseCursor::IBeamCursor:
  207658. c = [NSCursor IBeamCursor];
  207659. break;
  207660. case MouseCursor::PointingHandCursor:
  207661. c = [NSCursor pointingHandCursor];
  207662. break;
  207663. case MouseCursor::LeftRightResizeCursor:
  207664. c = [NSCursor resizeLeftRightCursor];
  207665. break;
  207666. case MouseCursor::LeftEdgeResizeCursor:
  207667. c = [NSCursor resizeLeftCursor];
  207668. break;
  207669. case MouseCursor::RightEdgeResizeCursor:
  207670. c = [NSCursor resizeRightCursor];
  207671. break;
  207672. case MouseCursor::UpDownResizeCursor:
  207673. case MouseCursor::TopEdgeResizeCursor:
  207674. case MouseCursor::BottomEdgeResizeCursor:
  207675. return juce_cursorFromWebKitFile ("northSouthResizeCursor.png", 0.5f, 0.5f);
  207676. case MouseCursor::TopLeftCornerResizeCursor:
  207677. case MouseCursor::BottomRightCornerResizeCursor:
  207678. return juce_cursorFromWebKitFile ("northWestSouthEastResizeCursor.png", 0.5f, 0.5f);
  207679. case MouseCursor::TopRightCornerResizeCursor:
  207680. case MouseCursor::BottomLeftCornerResizeCursor:
  207681. return juce_cursorFromWebKitFile ("northEastSouthWestResizeCursor.png", 0.5f, 0.5f);
  207682. case MouseCursor::UpDownLeftRightResizeCursor:
  207683. return juce_cursorFromWebKitFile ("moveCursor.png", 0.5f, 0.5f);
  207684. case MouseCursor::CrosshairCursor:
  207685. c = [NSCursor crosshairCursor];
  207686. break;
  207687. }
  207688. [c retain];
  207689. return (void*) c;
  207690. }
  207691. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw()
  207692. {
  207693. NSCursor* c = (NSCursor*) cursorHandle;
  207694. [c release];
  207695. }
  207696. void MouseCursor::showInAllWindows() const throw()
  207697. {
  207698. showInWindow (0);
  207699. }
  207700. void MouseCursor::showInWindow (ComponentPeer*) const throw()
  207701. {
  207702. NSCursor* const c = (NSCursor*) getHandle();
  207703. [c set];
  207704. }
  207705. #else
  207706. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw() { return 0; }
  207707. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw() { return 0; }
  207708. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw() {}
  207709. void MouseCursor::showInAllWindows() const throw() {}
  207710. void MouseCursor::showInWindow (ComponentPeer*) const throw() {}
  207711. #endif
  207712. #endif
  207713. /*** End of inlined file: juce_mac_MouseCursor.mm ***/
  207714. /*** Start of inlined file: juce_mac_NSViewComponent.mm ***/
  207715. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  207716. // compiled on its own).
  207717. #if JUCE_INCLUDED_FILE
  207718. class NSViewComponentInternal : public ComponentMovementWatcher
  207719. {
  207720. Component* const owner;
  207721. NSViewComponentPeer* currentPeer;
  207722. bool wasShowing;
  207723. public:
  207724. NSView* const view;
  207725. NSViewComponentInternal (NSView* const view_, Component* const owner_)
  207726. : ComponentMovementWatcher (owner_),
  207727. owner (owner_),
  207728. currentPeer (0),
  207729. wasShowing (false),
  207730. view (view_)
  207731. {
  207732. [view_ retain];
  207733. if (owner_->isShowing())
  207734. componentPeerChanged();
  207735. }
  207736. ~NSViewComponentInternal()
  207737. {
  207738. [view removeFromSuperview];
  207739. [view release];
  207740. }
  207741. void componentMovedOrResized (Component& comp, bool wasMoved, bool wasResized)
  207742. {
  207743. ComponentMovementWatcher::componentMovedOrResized (comp, wasMoved, wasResized);
  207744. // The ComponentMovementWatcher version of this method avoids calling
  207745. // us when the top-level comp is resized, but for an NSView we need to know this
  207746. // because with inverted co-ords, we need to update the position even if the
  207747. // top-left pos hasn't changed
  207748. if (comp.isOnDesktop() && wasResized)
  207749. componentMovedOrResized (wasMoved, wasResized);
  207750. }
  207751. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  207752. {
  207753. Component* const topComp = owner->getTopLevelComponent();
  207754. if (topComp->getPeer() != 0)
  207755. {
  207756. const Point<int> pos (owner->relativePositionToOtherComponent (topComp, Point<int>()));
  207757. NSRect r;
  207758. r.origin.x = (float) pos.getX();
  207759. r.origin.y = (float) pos.getY();
  207760. r.size.width = (float) owner->getWidth();
  207761. r.size.height = (float) owner->getHeight();
  207762. r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  207763. [view setFrame: r];
  207764. }
  207765. }
  207766. void componentPeerChanged()
  207767. {
  207768. NSViewComponentPeer* const peer = dynamic_cast <NSViewComponentPeer*> (owner->getPeer());
  207769. if (currentPeer != peer)
  207770. {
  207771. [view removeFromSuperview];
  207772. currentPeer = peer;
  207773. if (peer != 0)
  207774. {
  207775. [peer->view addSubview: view];
  207776. componentMovedOrResized (false, false);
  207777. }
  207778. }
  207779. [view setHidden: ! owner->isShowing()];
  207780. }
  207781. void componentVisibilityChanged (Component&)
  207782. {
  207783. componentPeerChanged();
  207784. }
  207785. juce_UseDebuggingNewOperator
  207786. private:
  207787. NSViewComponentInternal (const NSViewComponentInternal&);
  207788. NSViewComponentInternal& operator= (const NSViewComponentInternal&);
  207789. };
  207790. NSViewComponent::NSViewComponent()
  207791. {
  207792. }
  207793. NSViewComponent::~NSViewComponent()
  207794. {
  207795. }
  207796. void NSViewComponent::setView (void* view)
  207797. {
  207798. if (view != getView())
  207799. {
  207800. if (view != 0)
  207801. info = new NSViewComponentInternal ((NSView*) view, this);
  207802. else
  207803. info = 0;
  207804. }
  207805. }
  207806. void* NSViewComponent::getView() const
  207807. {
  207808. return info == 0 ? 0 : info->view;
  207809. }
  207810. void NSViewComponent::paint (Graphics& g)
  207811. {
  207812. }
  207813. #endif
  207814. /*** End of inlined file: juce_mac_NSViewComponent.mm ***/
  207815. /*** Start of inlined file: juce_mac_AppleRemote.mm ***/
  207816. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  207817. // compiled on its own).
  207818. #if JUCE_INCLUDED_FILE
  207819. AppleRemoteDevice::AppleRemoteDevice()
  207820. : device (0),
  207821. queue (0),
  207822. remoteId (0)
  207823. {
  207824. }
  207825. AppleRemoteDevice::~AppleRemoteDevice()
  207826. {
  207827. stop();
  207828. }
  207829. static io_object_t getAppleRemoteDevice()
  207830. {
  207831. CFMutableDictionaryRef dict = IOServiceMatching ("AppleIRController");
  207832. io_iterator_t iter = 0;
  207833. io_object_t iod = 0;
  207834. if (IOServiceGetMatchingServices (kIOMasterPortDefault, dict, &iter) == kIOReturnSuccess
  207835. && iter != 0)
  207836. {
  207837. iod = IOIteratorNext (iter);
  207838. }
  207839. IOObjectRelease (iter);
  207840. return iod;
  207841. }
  207842. static bool createAppleRemoteInterface (io_object_t iod, void** device)
  207843. {
  207844. jassert (*device == 0);
  207845. io_name_t classname;
  207846. if (IOObjectGetClass (iod, classname) == kIOReturnSuccess)
  207847. {
  207848. IOCFPlugInInterface** cfPlugInInterface = 0;
  207849. SInt32 score = 0;
  207850. if (IOCreatePlugInInterfaceForService (iod,
  207851. kIOHIDDeviceUserClientTypeID,
  207852. kIOCFPlugInInterfaceID,
  207853. &cfPlugInInterface,
  207854. &score) == kIOReturnSuccess)
  207855. {
  207856. HRESULT hr = (*cfPlugInInterface)->QueryInterface (cfPlugInInterface,
  207857. CFUUIDGetUUIDBytes (kIOHIDDeviceInterfaceID),
  207858. device);
  207859. (void) hr;
  207860. (*cfPlugInInterface)->Release (cfPlugInInterface);
  207861. }
  207862. }
  207863. return *device != 0;
  207864. }
  207865. bool AppleRemoteDevice::start (const bool inExclusiveMode)
  207866. {
  207867. if (queue != 0)
  207868. return true;
  207869. stop();
  207870. bool result = false;
  207871. io_object_t iod = getAppleRemoteDevice();
  207872. if (iod != 0)
  207873. {
  207874. if (createAppleRemoteInterface (iod, &device) && open (inExclusiveMode))
  207875. result = true;
  207876. else
  207877. stop();
  207878. IOObjectRelease (iod);
  207879. }
  207880. return result;
  207881. }
  207882. void AppleRemoteDevice::stop()
  207883. {
  207884. if (queue != 0)
  207885. {
  207886. (*(IOHIDQueueInterface**) queue)->stop ((IOHIDQueueInterface**) queue);
  207887. (*(IOHIDQueueInterface**) queue)->dispose ((IOHIDQueueInterface**) queue);
  207888. (*(IOHIDQueueInterface**) queue)->Release ((IOHIDQueueInterface**) queue);
  207889. queue = 0;
  207890. }
  207891. if (device != 0)
  207892. {
  207893. (*(IOHIDDeviceInterface**) device)->close ((IOHIDDeviceInterface**) device);
  207894. (*(IOHIDDeviceInterface**) device)->Release ((IOHIDDeviceInterface**) device);
  207895. device = 0;
  207896. }
  207897. }
  207898. bool AppleRemoteDevice::isActive() const
  207899. {
  207900. return queue != 0;
  207901. }
  207902. static void appleRemoteQueueCallback (void* const target, const IOReturn result, void*, void*)
  207903. {
  207904. if (result == kIOReturnSuccess)
  207905. ((AppleRemoteDevice*) target)->handleCallbackInternal();
  207906. }
  207907. bool AppleRemoteDevice::open (const bool openInExclusiveMode)
  207908. {
  207909. Array <int> cookies;
  207910. CFArrayRef elements;
  207911. IOHIDDeviceInterface122** const device122 = (IOHIDDeviceInterface122**) device;
  207912. if ((*device122)->copyMatchingElements (device122, 0, &elements) != kIOReturnSuccess)
  207913. return false;
  207914. for (int i = 0; i < CFArrayGetCount (elements); ++i)
  207915. {
  207916. CFDictionaryRef element = (CFDictionaryRef) CFArrayGetValueAtIndex (elements, i);
  207917. // get the cookie
  207918. CFTypeRef object = CFDictionaryGetValue (element, CFSTR (kIOHIDElementCookieKey));
  207919. if (object == 0 || CFGetTypeID (object) != CFNumberGetTypeID())
  207920. continue;
  207921. long number;
  207922. if (! CFNumberGetValue ((CFNumberRef) object, kCFNumberLongType, &number))
  207923. continue;
  207924. cookies.add ((int) number);
  207925. }
  207926. CFRelease (elements);
  207927. if ((*(IOHIDDeviceInterface**) device)
  207928. ->open ((IOHIDDeviceInterface**) device,
  207929. openInExclusiveMode ? kIOHIDOptionsTypeSeizeDevice
  207930. : kIOHIDOptionsTypeNone) == KERN_SUCCESS)
  207931. {
  207932. queue = (*(IOHIDDeviceInterface**) device)->allocQueue ((IOHIDDeviceInterface**) device);
  207933. if (queue != 0)
  207934. {
  207935. (*(IOHIDQueueInterface**) queue)->create ((IOHIDQueueInterface**) queue, 0, 12);
  207936. for (int i = 0; i < cookies.size(); ++i)
  207937. {
  207938. IOHIDElementCookie cookie = (IOHIDElementCookie) cookies.getUnchecked(i);
  207939. (*(IOHIDQueueInterface**) queue)->addElement ((IOHIDQueueInterface**) queue, cookie, 0);
  207940. }
  207941. CFRunLoopSourceRef eventSource;
  207942. if ((*(IOHIDQueueInterface**) queue)
  207943. ->createAsyncEventSource ((IOHIDQueueInterface**) queue, &eventSource) == KERN_SUCCESS)
  207944. {
  207945. if ((*(IOHIDQueueInterface**) queue)->setEventCallout ((IOHIDQueueInterface**) queue,
  207946. appleRemoteQueueCallback, this, 0) == KERN_SUCCESS)
  207947. {
  207948. CFRunLoopAddSource (CFRunLoopGetCurrent(), eventSource, kCFRunLoopDefaultMode);
  207949. (*(IOHIDQueueInterface**) queue)->start ((IOHIDQueueInterface**) queue);
  207950. return true;
  207951. }
  207952. }
  207953. }
  207954. }
  207955. return false;
  207956. }
  207957. void AppleRemoteDevice::handleCallbackInternal()
  207958. {
  207959. int totalValues = 0;
  207960. AbsoluteTime nullTime = { 0, 0 };
  207961. char cookies [12];
  207962. int numCookies = 0;
  207963. while (numCookies < numElementsInArray (cookies))
  207964. {
  207965. IOHIDEventStruct e;
  207966. if ((*(IOHIDQueueInterface**) queue)->getNextEvent ((IOHIDQueueInterface**) queue, &e, nullTime, 0) != kIOReturnSuccess)
  207967. break;
  207968. if ((int) e.elementCookie == 19)
  207969. {
  207970. remoteId = e.value;
  207971. buttonPressed (switched, false);
  207972. }
  207973. else
  207974. {
  207975. totalValues += e.value;
  207976. cookies [numCookies++] = (char) (pointer_sized_int) e.elementCookie;
  207977. }
  207978. }
  207979. cookies [numCookies++] = 0;
  207980. //DBG (String::toHexString ((uint8*) cookies, numCookies, 1) + " " + String (totalValues));
  207981. static const char buttonPatterns[] =
  207982. {
  207983. 0x1f, 0x14, 0x12, 0x1f, 0x14, 0x12, 0,
  207984. 0x1f, 0x15, 0x12, 0x1f, 0x15, 0x12, 0,
  207985. 0x1f, 0x1d, 0x1c, 0x12, 0,
  207986. 0x1f, 0x1e, 0x1c, 0x12, 0,
  207987. 0x1f, 0x16, 0x12, 0x1f, 0x16, 0x12, 0,
  207988. 0x1f, 0x17, 0x12, 0x1f, 0x17, 0x12, 0,
  207989. 0x1f, 0x12, 0x04, 0x02, 0,
  207990. 0x1f, 0x12, 0x03, 0x02, 0,
  207991. 0x1f, 0x12, 0x1f, 0x12, 0,
  207992. 0x23, 0x1f, 0x12, 0x23, 0x1f, 0x12, 0,
  207993. 19, 0
  207994. };
  207995. int buttonNum = (int) menuButton;
  207996. int i = 0;
  207997. while (i < numElementsInArray (buttonPatterns))
  207998. {
  207999. if (strcmp (cookies, buttonPatterns + i) == 0)
  208000. {
  208001. buttonPressed ((ButtonType) buttonNum, totalValues > 0);
  208002. break;
  208003. }
  208004. i += (int) strlen (buttonPatterns + i) + 1;
  208005. ++buttonNum;
  208006. }
  208007. }
  208008. #endif
  208009. /*** End of inlined file: juce_mac_AppleRemote.mm ***/
  208010. /*** Start of inlined file: juce_mac_OpenGLComponent.mm ***/
  208011. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208012. // compiled on its own).
  208013. #if JUCE_INCLUDED_FILE && JUCE_OPENGL
  208014. #if JUCE_MAC
  208015. END_JUCE_NAMESPACE
  208016. #define ThreadSafeNSOpenGLView MakeObjCClassName(ThreadSafeNSOpenGLView)
  208017. @interface ThreadSafeNSOpenGLView : NSOpenGLView
  208018. {
  208019. CriticalSection* contextLock;
  208020. bool needsUpdate;
  208021. }
  208022. - (id) initWithFrame: (NSRect) frameRect pixelFormat: (NSOpenGLPixelFormat*) format;
  208023. - (bool) makeActive;
  208024. - (void) makeInactive;
  208025. - (void) reshape;
  208026. @end
  208027. @implementation ThreadSafeNSOpenGLView
  208028. - (id) initWithFrame: (NSRect) frameRect
  208029. pixelFormat: (NSOpenGLPixelFormat*) format
  208030. {
  208031. contextLock = new CriticalSection();
  208032. self = [super initWithFrame: frameRect pixelFormat: format];
  208033. if (self != nil)
  208034. [[NSNotificationCenter defaultCenter] addObserver: self
  208035. selector: @selector (_surfaceNeedsUpdate:)
  208036. name: NSViewGlobalFrameDidChangeNotification
  208037. object: self];
  208038. return self;
  208039. }
  208040. - (void) dealloc
  208041. {
  208042. [[NSNotificationCenter defaultCenter] removeObserver: self];
  208043. delete contextLock;
  208044. [super dealloc];
  208045. }
  208046. - (bool) makeActive
  208047. {
  208048. const ScopedLock sl (*contextLock);
  208049. if ([self openGLContext] == 0)
  208050. return false;
  208051. [[self openGLContext] makeCurrentContext];
  208052. if (needsUpdate)
  208053. {
  208054. [super update];
  208055. needsUpdate = false;
  208056. }
  208057. return true;
  208058. }
  208059. - (void) makeInactive
  208060. {
  208061. const ScopedLock sl (*contextLock);
  208062. [NSOpenGLContext clearCurrentContext];
  208063. }
  208064. - (void) _surfaceNeedsUpdate: (NSNotification*) notification
  208065. {
  208066. const ScopedLock sl (*contextLock);
  208067. needsUpdate = true;
  208068. }
  208069. - (void) update
  208070. {
  208071. const ScopedLock sl (*contextLock);
  208072. needsUpdate = true;
  208073. }
  208074. - (void) reshape
  208075. {
  208076. const ScopedLock sl (*contextLock);
  208077. needsUpdate = true;
  208078. }
  208079. @end
  208080. BEGIN_JUCE_NAMESPACE
  208081. class WindowedGLContext : public OpenGLContext
  208082. {
  208083. public:
  208084. WindowedGLContext (Component* const component,
  208085. const OpenGLPixelFormat& pixelFormat_,
  208086. NSOpenGLContext* sharedContext)
  208087. : renderContext (0),
  208088. pixelFormat (pixelFormat_)
  208089. {
  208090. jassert (component != 0);
  208091. NSOpenGLPixelFormatAttribute attribs [64];
  208092. int n = 0;
  208093. attribs[n++] = NSOpenGLPFADoubleBuffer;
  208094. attribs[n++] = NSOpenGLPFAAccelerated;
  208095. attribs[n++] = NSOpenGLPFAMPSafe; // NSOpenGLPFAAccelerated, NSOpenGLPFAMultiScreen, NSOpenGLPFASingleRenderer
  208096. attribs[n++] = NSOpenGLPFAColorSize;
  208097. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.redBits,
  208098. pixelFormat.greenBits,
  208099. pixelFormat.blueBits);
  208100. attribs[n++] = NSOpenGLPFAAlphaSize;
  208101. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.alphaBits;
  208102. attribs[n++] = NSOpenGLPFADepthSize;
  208103. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.depthBufferBits;
  208104. attribs[n++] = NSOpenGLPFAStencilSize;
  208105. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.stencilBufferBits;
  208106. attribs[n++] = NSOpenGLPFAAccumSize;
  208107. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.accumulationBufferRedBits,
  208108. pixelFormat.accumulationBufferGreenBits,
  208109. pixelFormat.accumulationBufferBlueBits,
  208110. pixelFormat.accumulationBufferAlphaBits);
  208111. // xxx not sure how to do fullSceneAntiAliasingNumSamples..
  208112. attribs[n++] = NSOpenGLPFASampleBuffers;
  208113. attribs[n++] = (NSOpenGLPixelFormatAttribute) 1;
  208114. attribs[n++] = NSOpenGLPFAClosestPolicy;
  208115. attribs[n++] = NSOpenGLPFANoRecovery;
  208116. attribs[n++] = (NSOpenGLPixelFormatAttribute) 0;
  208117. NSOpenGLPixelFormat* format
  208118. = [[NSOpenGLPixelFormat alloc] initWithAttributes: attribs];
  208119. view = [[ThreadSafeNSOpenGLView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  208120. pixelFormat: format];
  208121. renderContext = [[[NSOpenGLContext alloc] initWithFormat: format
  208122. shareContext: sharedContext] autorelease];
  208123. const GLint swapInterval = 1;
  208124. [renderContext setValues: &swapInterval forParameter: NSOpenGLCPSwapInterval];
  208125. [view setOpenGLContext: renderContext];
  208126. [renderContext setView: view];
  208127. [format release];
  208128. viewHolder = new NSViewComponentInternal (view, component);
  208129. }
  208130. ~WindowedGLContext()
  208131. {
  208132. makeInactive();
  208133. [renderContext clearDrawable];
  208134. viewHolder = 0;
  208135. }
  208136. bool makeActive() const throw()
  208137. {
  208138. jassert (renderContext != 0);
  208139. [view makeActive];
  208140. return isActive();
  208141. }
  208142. bool makeInactive() const throw()
  208143. {
  208144. [view makeInactive];
  208145. return true;
  208146. }
  208147. bool isActive() const throw()
  208148. {
  208149. return [NSOpenGLContext currentContext] == renderContext;
  208150. }
  208151. const OpenGLPixelFormat getPixelFormat() const { return pixelFormat; }
  208152. void* getRawContext() const throw() { return renderContext; }
  208153. void updateWindowPosition (int x, int y, int w, int h, int outerWindowHeight)
  208154. {
  208155. }
  208156. void swapBuffers()
  208157. {
  208158. [renderContext flushBuffer];
  208159. }
  208160. bool setSwapInterval (const int numFramesPerSwap)
  208161. {
  208162. [renderContext setValues: (const GLint*) &numFramesPerSwap
  208163. forParameter: NSOpenGLCPSwapInterval];
  208164. return true;
  208165. }
  208166. int getSwapInterval() const
  208167. {
  208168. GLint numFrames = 0;
  208169. [renderContext getValues: &numFrames
  208170. forParameter: NSOpenGLCPSwapInterval];
  208171. return numFrames;
  208172. }
  208173. void repaint()
  208174. {
  208175. // we need to invalidate the juce view that holds this gl view, to make it
  208176. // cause a repaint callback
  208177. NSView* v = (NSView*) viewHolder->view;
  208178. NSRect r = [v frame];
  208179. // bit of a bodge here.. if we only invalidate the area of the gl component,
  208180. // it's completely covered by the NSOpenGLView, so the OS throws away the
  208181. // repaint message, thus never causing our paint() callback, and never repainting
  208182. // the comp. So invalidating just a little bit around the edge helps..
  208183. [[v superview] setNeedsDisplayInRect: NSInsetRect (r, -2.0f, -2.0f)];
  208184. }
  208185. void* getNativeWindowHandle() const { return viewHolder->view; }
  208186. juce_UseDebuggingNewOperator
  208187. NSOpenGLContext* renderContext;
  208188. ThreadSafeNSOpenGLView* view;
  208189. private:
  208190. OpenGLPixelFormat pixelFormat;
  208191. ScopedPointer <NSViewComponentInternal> viewHolder;
  208192. WindowedGLContext (const WindowedGLContext&);
  208193. WindowedGLContext& operator= (const WindowedGLContext&);
  208194. };
  208195. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  208196. const OpenGLPixelFormat& pixelFormat,
  208197. const OpenGLContext* const contextToShareWith)
  208198. {
  208199. ScopedPointer <WindowedGLContext> c (new WindowedGLContext (component, pixelFormat,
  208200. contextToShareWith != 0 ? (NSOpenGLContext*) contextToShareWith->getRawContext() : 0));
  208201. return (c->renderContext != 0) ? c.release() : 0;
  208202. }
  208203. void* OpenGLComponent::getNativeWindowHandle() const
  208204. {
  208205. return context != 0 ? ((WindowedGLContext*) context)->getNativeWindowHandle()
  208206. : 0;
  208207. }
  208208. void juce_glViewport (const int w, const int h)
  208209. {
  208210. glViewport (0, 0, w, h);
  208211. }
  208212. void OpenGLPixelFormat::getAvailablePixelFormats (Component* /*component*/,
  208213. OwnedArray <OpenGLPixelFormat>& results)
  208214. {
  208215. /* GLint attribs [64];
  208216. int n = 0;
  208217. attribs[n++] = AGL_RGBA;
  208218. attribs[n++] = AGL_DOUBLEBUFFER;
  208219. attribs[n++] = AGL_ACCELERATED;
  208220. attribs[n++] = AGL_NO_RECOVERY;
  208221. attribs[n++] = AGL_NONE;
  208222. AGLPixelFormat p = aglChoosePixelFormat (0, 0, attribs);
  208223. while (p != 0)
  208224. {
  208225. OpenGLPixelFormat* const pf = new OpenGLPixelFormat();
  208226. pf->redBits = getAGLAttribute (p, AGL_RED_SIZE);
  208227. pf->greenBits = getAGLAttribute (p, AGL_GREEN_SIZE);
  208228. pf->blueBits = getAGLAttribute (p, AGL_BLUE_SIZE);
  208229. pf->alphaBits = getAGLAttribute (p, AGL_ALPHA_SIZE);
  208230. pf->depthBufferBits = getAGLAttribute (p, AGL_DEPTH_SIZE);
  208231. pf->stencilBufferBits = getAGLAttribute (p, AGL_STENCIL_SIZE);
  208232. pf->accumulationBufferRedBits = getAGLAttribute (p, AGL_ACCUM_RED_SIZE);
  208233. pf->accumulationBufferGreenBits = getAGLAttribute (p, AGL_ACCUM_GREEN_SIZE);
  208234. pf->accumulationBufferBlueBits = getAGLAttribute (p, AGL_ACCUM_BLUE_SIZE);
  208235. pf->accumulationBufferAlphaBits = getAGLAttribute (p, AGL_ACCUM_ALPHA_SIZE);
  208236. results.add (pf);
  208237. p = aglNextPixelFormat (p);
  208238. }*/
  208239. //jassertfalse //xxx can't see how you do this in cocoa!
  208240. }
  208241. #else
  208242. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  208243. const OpenGLPixelFormat& pixelFormat,
  208244. const OpenGLContext* const contextToShareWith)
  208245. {
  208246. return 0;
  208247. }
  208248. void juce_glViewport (const int w, const int h)
  208249. {
  208250. //glViewport (0, 0, w, h);
  208251. }
  208252. #endif
  208253. #endif
  208254. /*** End of inlined file: juce_mac_OpenGLComponent.mm ***/
  208255. /*** Start of inlined file: juce_mac_MainMenu.mm ***/
  208256. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208257. // compiled on its own).
  208258. #if JUCE_INCLUDED_FILE
  208259. class JuceMainMenuHandler;
  208260. END_JUCE_NAMESPACE
  208261. using namespace JUCE_NAMESPACE;
  208262. #define JuceMenuCallback MakeObjCClassName(JuceMenuCallback)
  208263. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  208264. @interface JuceMenuCallback : NSObject <NSMenuDelegate>
  208265. #else
  208266. @interface JuceMenuCallback : NSObject
  208267. #endif
  208268. {
  208269. JuceMainMenuHandler* owner;
  208270. }
  208271. - (JuceMenuCallback*) initWithOwner: (JuceMainMenuHandler*) owner_;
  208272. - (void) dealloc;
  208273. - (void) menuItemInvoked: (id) menu;
  208274. - (void) menuNeedsUpdate: (NSMenu*) menu;
  208275. @end
  208276. BEGIN_JUCE_NAMESPACE
  208277. class JuceMainMenuHandler : private MenuBarModelListener,
  208278. private DeletedAtShutdown
  208279. {
  208280. public:
  208281. static JuceMainMenuHandler* instance;
  208282. JuceMainMenuHandler()
  208283. : currentModel (0),
  208284. lastUpdateTime (0)
  208285. {
  208286. callback = [[JuceMenuCallback alloc] initWithOwner: this];
  208287. }
  208288. ~JuceMainMenuHandler()
  208289. {
  208290. setMenu (0);
  208291. jassert (instance == this);
  208292. instance = 0;
  208293. [callback release];
  208294. }
  208295. void setMenu (MenuBarModel* const newMenuBarModel)
  208296. {
  208297. if (currentModel != newMenuBarModel)
  208298. {
  208299. if (currentModel != 0)
  208300. currentModel->removeListener (this);
  208301. currentModel = newMenuBarModel;
  208302. if (currentModel != 0)
  208303. currentModel->addListener (this);
  208304. menuBarItemsChanged (0);
  208305. }
  208306. }
  208307. void addSubMenu (NSMenu* parent, const PopupMenu& child,
  208308. const String& name, const int menuId, const int tag)
  208309. {
  208310. NSMenuItem* item = [parent addItemWithTitle: juceStringToNS (name)
  208311. action: nil
  208312. keyEquivalent: @""];
  208313. [item setTag: tag];
  208314. NSMenu* sub = createMenu (child, name, menuId, tag);
  208315. [parent setSubmenu: sub forItem: item];
  208316. [sub setAutoenablesItems: false];
  208317. [sub release];
  208318. }
  208319. void updateSubMenu (NSMenuItem* parentItem, const PopupMenu& menuToCopy,
  208320. const String& name, const int menuId, const int tag)
  208321. {
  208322. [parentItem setTag: tag];
  208323. NSMenu* menu = [parentItem submenu];
  208324. [menu setTitle: juceStringToNS (name)];
  208325. while ([menu numberOfItems] > 0)
  208326. [menu removeItemAtIndex: 0];
  208327. PopupMenu::MenuItemIterator iter (menuToCopy);
  208328. while (iter.next())
  208329. addMenuItem (iter, menu, menuId, tag);
  208330. [menu setAutoenablesItems: false];
  208331. [menu update];
  208332. }
  208333. void menuBarItemsChanged (MenuBarModel*)
  208334. {
  208335. lastUpdateTime = Time::getMillisecondCounter();
  208336. StringArray menuNames;
  208337. if (currentModel != 0)
  208338. menuNames = currentModel->getMenuBarNames();
  208339. NSMenu* menuBar = [NSApp mainMenu];
  208340. while ([menuBar numberOfItems] > 1 + menuNames.size())
  208341. [menuBar removeItemAtIndex: [menuBar numberOfItems] - 1];
  208342. int menuId = 1;
  208343. for (int i = 0; i < menuNames.size(); ++i)
  208344. {
  208345. const PopupMenu menu (currentModel->getMenuForIndex (i, menuNames [i]));
  208346. if (i >= [menuBar numberOfItems] - 1)
  208347. addSubMenu (menuBar, menu, menuNames[i], menuId, i);
  208348. else
  208349. updateSubMenu ([menuBar itemAtIndex: 1 + i], menu, menuNames[i], menuId, i);
  208350. }
  208351. }
  208352. static void flashMenuBar (NSMenu* menu)
  208353. {
  208354. if ([[menu title] isEqualToString: @"Apple"])
  208355. return;
  208356. [menu retain];
  208357. const unichar f35Key = NSF35FunctionKey;
  208358. NSString* f35String = [NSString stringWithCharacters: &f35Key length: 1];
  208359. NSMenuItem* item = [[NSMenuItem alloc] initWithTitle: @"x"
  208360. action: nil
  208361. keyEquivalent: f35String];
  208362. [item setTarget: nil];
  208363. [menu insertItem: item atIndex: [menu numberOfItems]];
  208364. [item release];
  208365. if ([menu indexOfItem: item] >= 0)
  208366. {
  208367. NSEvent* f35Event = [NSEvent keyEventWithType: NSKeyDown
  208368. location: NSZeroPoint
  208369. modifierFlags: NSCommandKeyMask
  208370. timestamp: 0
  208371. windowNumber: 0
  208372. context: [NSGraphicsContext currentContext]
  208373. characters: f35String
  208374. charactersIgnoringModifiers: f35String
  208375. isARepeat: NO
  208376. keyCode: 0];
  208377. [menu performKeyEquivalent: f35Event];
  208378. [menu removeItem: item]; // (this throws if the item isn't actually in the menu)
  208379. }
  208380. [menu release];
  208381. }
  208382. static NSMenuItem* findMenuItem (NSMenu* const menu, const ApplicationCommandTarget::InvocationInfo& info)
  208383. {
  208384. for (NSInteger i = [menu numberOfItems]; --i >= 0;)
  208385. {
  208386. NSMenuItem* m = [menu itemAtIndex: i];
  208387. if ([m tag] == info.commandID)
  208388. return m;
  208389. if ([m submenu] != 0)
  208390. {
  208391. NSMenuItem* found = findMenuItem ([m submenu], info);
  208392. if (found != 0)
  208393. return found;
  208394. }
  208395. }
  208396. return 0;
  208397. }
  208398. void menuCommandInvoked (MenuBarModel*, const ApplicationCommandTarget::InvocationInfo& info)
  208399. {
  208400. NSMenuItem* item = findMenuItem ([NSApp mainMenu], info);
  208401. if (item != 0)
  208402. flashMenuBar ([item menu]);
  208403. }
  208404. void updateMenus()
  208405. {
  208406. if (Time::getMillisecondCounter() > lastUpdateTime + 500)
  208407. menuBarItemsChanged (0);
  208408. }
  208409. void invoke (const int commandId, ApplicationCommandManager* const commandManager, const int topLevelIndex) const
  208410. {
  208411. if (currentModel != 0)
  208412. {
  208413. if (commandManager != 0)
  208414. {
  208415. ApplicationCommandTarget::InvocationInfo info (commandId);
  208416. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromMenu;
  208417. commandManager->invoke (info, true);
  208418. }
  208419. currentModel->menuItemSelected (commandId, topLevelIndex);
  208420. }
  208421. }
  208422. MenuBarModel* currentModel;
  208423. uint32 lastUpdateTime;
  208424. void addMenuItem (PopupMenu::MenuItemIterator& iter, NSMenu* menuToAddTo,
  208425. const int topLevelMenuId, const int topLevelIndex)
  208426. {
  208427. NSString* text = juceStringToNS (iter.itemName.upToFirstOccurrenceOf (T("<end>"), false, true));
  208428. if (text == 0)
  208429. text = @"";
  208430. if (iter.isSeparator)
  208431. {
  208432. [menuToAddTo addItem: [NSMenuItem separatorItem]];
  208433. }
  208434. else if (iter.isSectionHeader)
  208435. {
  208436. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  208437. action: nil
  208438. keyEquivalent: @""];
  208439. [item setEnabled: false];
  208440. }
  208441. else if (iter.subMenu != 0)
  208442. {
  208443. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  208444. action: nil
  208445. keyEquivalent: @""];
  208446. [item setTag: iter.itemId];
  208447. [item setEnabled: iter.isEnabled];
  208448. NSMenu* sub = createMenu (*iter.subMenu, iter.itemName, topLevelMenuId, topLevelIndex);
  208449. [sub setDelegate: nil];
  208450. [menuToAddTo setSubmenu: sub forItem: item];
  208451. [sub release];
  208452. }
  208453. else
  208454. {
  208455. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  208456. action: @selector (menuItemInvoked:)
  208457. keyEquivalent: @""];
  208458. [item setTag: iter.itemId];
  208459. [item setEnabled: iter.isEnabled];
  208460. [item setState: iter.isTicked ? NSOnState : NSOffState];
  208461. [item setTarget: (id) callback];
  208462. NSMutableArray* info = [NSMutableArray arrayWithObject: [NSNumber numberWithUnsignedLongLong: (pointer_sized_int) (void*) iter.commandManager]];
  208463. [info addObject: [NSNumber numberWithInt: topLevelIndex]];
  208464. [item setRepresentedObject: info];
  208465. if (iter.commandManager != 0)
  208466. {
  208467. const Array <KeyPress> keyPresses (iter.commandManager->getKeyMappings()
  208468. ->getKeyPressesAssignedToCommand (iter.itemId));
  208469. if (keyPresses.size() > 0)
  208470. {
  208471. const KeyPress& kp = keyPresses.getReference(0);
  208472. juce_wchar key = kp.getTextCharacter();
  208473. if (kp.getKeyCode() == KeyPress::backspaceKey)
  208474. key = NSBackspaceCharacter;
  208475. else if (kp.getKeyCode() == KeyPress::deleteKey)
  208476. key = NSDeleteCharacter;
  208477. else if (key == 0)
  208478. key = (juce_wchar) kp.getKeyCode();
  208479. unsigned int mods = 0;
  208480. if (kp.getModifiers().isShiftDown())
  208481. mods |= NSShiftKeyMask;
  208482. if (kp.getModifiers().isCtrlDown())
  208483. mods |= NSControlKeyMask;
  208484. if (kp.getModifiers().isAltDown())
  208485. mods |= NSAlternateKeyMask;
  208486. if (kp.getModifiers().isCommandDown())
  208487. mods |= NSCommandKeyMask;
  208488. [item setKeyEquivalent: juceStringToNS (String::charToString (key))];
  208489. [item setKeyEquivalentModifierMask: mods];
  208490. }
  208491. }
  208492. }
  208493. }
  208494. JuceMenuCallback* callback;
  208495. private:
  208496. NSMenu* createMenu (const PopupMenu menu,
  208497. const String& menuName,
  208498. const int topLevelMenuId,
  208499. const int topLevelIndex)
  208500. {
  208501. NSMenu* m = [[NSMenu alloc] initWithTitle: juceStringToNS (menuName)];
  208502. [m setAutoenablesItems: false];
  208503. [m setDelegate: callback];
  208504. PopupMenu::MenuItemIterator iter (menu);
  208505. while (iter.next())
  208506. addMenuItem (iter, m, topLevelMenuId, topLevelIndex);
  208507. [m update];
  208508. return m;
  208509. }
  208510. };
  208511. JuceMainMenuHandler* JuceMainMenuHandler::instance = 0;
  208512. END_JUCE_NAMESPACE
  208513. @implementation JuceMenuCallback
  208514. - (JuceMenuCallback*) initWithOwner: (JuceMainMenuHandler*) owner_
  208515. {
  208516. [super init];
  208517. owner = owner_;
  208518. return self;
  208519. }
  208520. - (void) dealloc
  208521. {
  208522. [super dealloc];
  208523. }
  208524. - (void) menuItemInvoked: (id) menu
  208525. {
  208526. NSMenuItem* item = (NSMenuItem*) menu;
  208527. if ([[item representedObject] isKindOfClass: [NSArray class]])
  208528. {
  208529. // 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
  208530. // our own components, which may have wanted to intercept it. So, rather than dispatching directly, we'll feed it back
  208531. // into the focused component and let it trigger the menu item indirectly.
  208532. NSEvent* e = [NSApp currentEvent];
  208533. if ([e type] == NSKeyDown || [e type] == NSKeyUp)
  208534. {
  208535. if (JUCE_NAMESPACE::Component::getCurrentlyFocusedComponent() != 0)
  208536. {
  208537. JUCE_NAMESPACE::NSViewComponentPeer* peer = dynamic_cast <JUCE_NAMESPACE::NSViewComponentPeer*> (JUCE_NAMESPACE::Component::getCurrentlyFocusedComponent()->getPeer());
  208538. if (peer != 0)
  208539. {
  208540. if ([e type] == NSKeyDown)
  208541. peer->redirectKeyDown (e);
  208542. else
  208543. peer->redirectKeyUp (e);
  208544. return;
  208545. }
  208546. }
  208547. }
  208548. NSArray* info = (NSArray*) [item representedObject];
  208549. owner->invoke ((int) [item tag],
  208550. (ApplicationCommandManager*) (pointer_sized_int)
  208551. [((NSNumber*) [info objectAtIndex: 0]) unsignedLongLongValue],
  208552. (int) [((NSNumber*) [info objectAtIndex: 1]) intValue]);
  208553. }
  208554. }
  208555. - (void) menuNeedsUpdate: (NSMenu*) menu;
  208556. {
  208557. if (JuceMainMenuHandler::instance != 0)
  208558. JuceMainMenuHandler::instance->updateMenus();
  208559. }
  208560. @end
  208561. BEGIN_JUCE_NAMESPACE
  208562. static NSMenu* createStandardAppMenu (NSMenu* menu, const String& appName,
  208563. const PopupMenu* extraItems)
  208564. {
  208565. if (extraItems != 0 && JuceMainMenuHandler::instance != 0 && extraItems->getNumItems() > 0)
  208566. {
  208567. PopupMenu::MenuItemIterator iter (*extraItems);
  208568. while (iter.next())
  208569. JuceMainMenuHandler::instance->addMenuItem (iter, menu, 0, -1);
  208570. [menu addItem: [NSMenuItem separatorItem]];
  208571. }
  208572. NSMenuItem* item;
  208573. // Services...
  208574. item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString (@"Services", nil)
  208575. action: nil keyEquivalent: @""];
  208576. [menu addItem: item];
  208577. [item release];
  208578. NSMenu* servicesMenu = [[NSMenu alloc] initWithTitle: @"Services"];
  208579. [menu setSubmenu: servicesMenu forItem: item];
  208580. [NSApp setServicesMenu: servicesMenu];
  208581. [servicesMenu release];
  208582. [menu addItem: [NSMenuItem separatorItem]];
  208583. // Hide + Show stuff...
  208584. item = [[NSMenuItem alloc] initWithTitle: juceStringToNS ("Hide " + appName)
  208585. action: @selector (hide:) keyEquivalent: @"h"];
  208586. [item setTarget: NSApp];
  208587. [menu addItem: item];
  208588. [item release];
  208589. item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString (@"Hide Others", nil)
  208590. action: @selector (hideOtherApplications:) keyEquivalent: @"h"];
  208591. [item setKeyEquivalentModifierMask: NSCommandKeyMask | NSAlternateKeyMask];
  208592. [item setTarget: NSApp];
  208593. [menu addItem: item];
  208594. [item release];
  208595. item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString (@"Show All", nil)
  208596. action: @selector (unhideAllApplications:) keyEquivalent: @""];
  208597. [item setTarget: NSApp];
  208598. [menu addItem: item];
  208599. [item release];
  208600. [menu addItem: [NSMenuItem separatorItem]];
  208601. // Quit item....
  208602. item = [[NSMenuItem alloc] initWithTitle: juceStringToNS ("Quit " + appName)
  208603. action: @selector (terminate:) keyEquivalent: @"q"];
  208604. [item setTarget: NSApp];
  208605. [menu addItem: item];
  208606. [item release];
  208607. return menu;
  208608. }
  208609. // Since our app has no NIB, this initialises a standard app menu...
  208610. static void rebuildMainMenu (const PopupMenu* extraItems)
  208611. {
  208612. // this can't be used in a plugin!
  208613. jassert (JUCEApplication::getInstance() != 0);
  208614. if (JUCEApplication::getInstance() != 0)
  208615. {
  208616. const ScopedAutoReleasePool pool;
  208617. NSMenu* mainMenu = [[NSMenu alloc] initWithTitle: @"MainMenu"];
  208618. NSMenuItem* item = [mainMenu addItemWithTitle: @"Apple" action: nil keyEquivalent: @""];
  208619. NSMenu* appMenu = [[NSMenu alloc] initWithTitle: @"Apple"];
  208620. [NSApp performSelector: @selector (setAppleMenu:) withObject: appMenu];
  208621. [mainMenu setSubmenu: appMenu forItem: item];
  208622. [NSApp setMainMenu: mainMenu];
  208623. createStandardAppMenu (appMenu, JUCEApplication::getInstance()->getApplicationName(), extraItems);
  208624. [appMenu release];
  208625. [mainMenu release];
  208626. }
  208627. }
  208628. void MenuBarModel::setMacMainMenu (MenuBarModel* newMenuBarModel,
  208629. const PopupMenu* extraAppleMenuItems)
  208630. {
  208631. if (getMacMainMenu() != newMenuBarModel)
  208632. {
  208633. const ScopedAutoReleasePool pool;
  208634. if (newMenuBarModel == 0)
  208635. {
  208636. delete JuceMainMenuHandler::instance;
  208637. jassert (JuceMainMenuHandler::instance == 0); // should be zeroed in the destructor
  208638. jassert (extraAppleMenuItems == 0); // you can't specify some extra items without also supplying a model
  208639. extraAppleMenuItems = 0;
  208640. }
  208641. else
  208642. {
  208643. if (JuceMainMenuHandler::instance == 0)
  208644. JuceMainMenuHandler::instance = new JuceMainMenuHandler();
  208645. JuceMainMenuHandler::instance->setMenu (newMenuBarModel);
  208646. }
  208647. }
  208648. rebuildMainMenu (extraAppleMenuItems);
  208649. if (newMenuBarModel != 0)
  208650. newMenuBarModel->menuItemsChanged();
  208651. }
  208652. MenuBarModel* MenuBarModel::getMacMainMenu()
  208653. {
  208654. return JuceMainMenuHandler::instance != 0
  208655. ? JuceMainMenuHandler::instance->currentModel : 0;
  208656. }
  208657. void initialiseMainMenu()
  208658. {
  208659. if (JUCEApplication::getInstance() != 0) // only needed in an app
  208660. rebuildMainMenu (0);
  208661. }
  208662. #endif
  208663. /*** End of inlined file: juce_mac_MainMenu.mm ***/
  208664. /*** Start of inlined file: juce_mac_FileChooser.mm ***/
  208665. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208666. // compiled on its own).
  208667. #if JUCE_INCLUDED_FILE
  208668. #if JUCE_MAC
  208669. END_JUCE_NAMESPACE
  208670. using namespace JUCE_NAMESPACE;
  208671. #define JuceFileChooserDelegate MakeObjCClassName(JuceFileChooserDelegate)
  208672. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  208673. @interface JuceFileChooserDelegate : NSObject <NSOpenSavePanelDelegate>
  208674. #else
  208675. @interface JuceFileChooserDelegate : NSObject
  208676. #endif
  208677. {
  208678. StringArray* filters;
  208679. }
  208680. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_;
  208681. - (void) dealloc;
  208682. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename;
  208683. @end
  208684. @implementation JuceFileChooserDelegate
  208685. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_
  208686. {
  208687. [super init];
  208688. filters = filters_;
  208689. return self;
  208690. }
  208691. - (void) dealloc
  208692. {
  208693. delete filters;
  208694. [super dealloc];
  208695. }
  208696. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename
  208697. {
  208698. const File f (nsStringToJuce (filename));
  208699. for (int i = filters->size(); --i >= 0;)
  208700. if (f.getFileName().matchesWildcard ((*filters)[i], true))
  208701. return true;
  208702. return f.isDirectory();
  208703. }
  208704. @end
  208705. BEGIN_JUCE_NAMESPACE
  208706. void FileChooser::showPlatformDialog (Array<File>& results,
  208707. const String& title,
  208708. const File& currentFileOrDirectory,
  208709. const String& filter,
  208710. bool selectsDirectory,
  208711. bool selectsFiles,
  208712. bool isSaveDialogue,
  208713. bool warnAboutOverwritingExistingFiles,
  208714. bool selectMultipleFiles,
  208715. FilePreviewComponent* extraInfoComponent)
  208716. {
  208717. const ScopedAutoReleasePool pool;
  208718. StringArray* filters = new StringArray();
  208719. filters->addTokens (filter.replaceCharacters (T(",:"), T(";;")), T(";"), String::empty);
  208720. filters->trim();
  208721. filters->removeEmptyStrings();
  208722. JuceFileChooserDelegate* delegate = [[JuceFileChooserDelegate alloc] initWithFilters: filters];
  208723. [delegate autorelease];
  208724. NSSavePanel* panel = isSaveDialogue ? [NSSavePanel savePanel]
  208725. : [NSOpenPanel openPanel];
  208726. [panel setTitle: juceStringToNS (title)];
  208727. if (! isSaveDialogue)
  208728. {
  208729. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  208730. [openPanel setCanChooseDirectories: selectsDirectory];
  208731. [openPanel setCanChooseFiles: selectsFiles];
  208732. [openPanel setAllowsMultipleSelection: selectMultipleFiles];
  208733. }
  208734. [panel setDelegate: delegate];
  208735. if (isSaveDialogue || selectsDirectory)
  208736. [panel setCanCreateDirectories: YES];
  208737. String directory, filename;
  208738. if (currentFileOrDirectory.isDirectory())
  208739. {
  208740. directory = currentFileOrDirectory.getFullPathName();
  208741. }
  208742. else
  208743. {
  208744. directory = currentFileOrDirectory.getParentDirectory().getFullPathName();
  208745. filename = currentFileOrDirectory.getFileName();
  208746. }
  208747. if ([panel runModalForDirectory: juceStringToNS (directory)
  208748. file: juceStringToNS (filename)]
  208749. == NSOKButton)
  208750. {
  208751. if (isSaveDialogue)
  208752. {
  208753. results.add (File (nsStringToJuce ([panel filename])));
  208754. }
  208755. else
  208756. {
  208757. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  208758. NSArray* urls = [openPanel filenames];
  208759. for (unsigned int i = 0; i < [urls count]; ++i)
  208760. {
  208761. NSString* f = [urls objectAtIndex: i];
  208762. results.add (File (nsStringToJuce (f)));
  208763. }
  208764. }
  208765. }
  208766. [panel setDelegate: nil];
  208767. }
  208768. #else
  208769. void FileChooser::showPlatformDialog (Array<File>& results,
  208770. const String& title,
  208771. const File& currentFileOrDirectory,
  208772. const String& filter,
  208773. bool selectsDirectory,
  208774. bool selectsFiles,
  208775. bool isSaveDialogue,
  208776. bool warnAboutOverwritingExistingFiles,
  208777. bool selectMultipleFiles,
  208778. FilePreviewComponent* extraInfoComponent)
  208779. {
  208780. const ScopedAutoReleasePool pool;
  208781. jassertfalse //xxx to do
  208782. }
  208783. #endif
  208784. #endif
  208785. /*** End of inlined file: juce_mac_FileChooser.mm ***/
  208786. /*** Start of inlined file: juce_mac_QuickTimeMovieComponent.mm ***/
  208787. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208788. // compiled on its own).
  208789. #if JUCE_INCLUDED_FILE && JUCE_QUICKTIME
  208790. END_JUCE_NAMESPACE
  208791. #define NonInterceptingQTMovieView MakeObjCClassName(NonInterceptingQTMovieView)
  208792. @interface NonInterceptingQTMovieView : QTMovieView
  208793. {
  208794. }
  208795. - (id) initWithFrame: (NSRect) frame;
  208796. - (BOOL) acceptsFirstMouse: (NSEvent*) theEvent;
  208797. - (NSView*) hitTest: (NSPoint) p;
  208798. @end
  208799. @implementation NonInterceptingQTMovieView
  208800. - (id) initWithFrame: (NSRect) frame
  208801. {
  208802. self = [super initWithFrame: frame];
  208803. [self setNextResponder: [self superview]];
  208804. return self;
  208805. }
  208806. - (void) dealloc
  208807. {
  208808. [super dealloc];
  208809. }
  208810. - (NSView*) hitTest: (NSPoint) point
  208811. {
  208812. return [self isControllerVisible] ? [super hitTest: point] : nil;
  208813. }
  208814. - (BOOL) acceptsFirstMouse: (NSEvent*) theEvent
  208815. {
  208816. return YES;
  208817. }
  208818. @end
  208819. BEGIN_JUCE_NAMESPACE
  208820. #define theMovie (static_cast <QTMovie*> (movie))
  208821. QuickTimeMovieComponent::QuickTimeMovieComponent()
  208822. : movie (0)
  208823. {
  208824. setOpaque (true);
  208825. setVisible (true);
  208826. QTMovieView* view = [[NonInterceptingQTMovieView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)];
  208827. setView (view);
  208828. [view release];
  208829. }
  208830. QuickTimeMovieComponent::~QuickTimeMovieComponent()
  208831. {
  208832. closeMovie();
  208833. setView (0);
  208834. }
  208835. bool QuickTimeMovieComponent::isQuickTimeAvailable() throw()
  208836. {
  208837. return true;
  208838. }
  208839. static QTMovie* openMovieFromStream (InputStream* movieStream, File& movieFile)
  208840. {
  208841. // unfortunately, QTMovie objects can only be created on the main thread..
  208842. jassert (MessageManager::getInstance()->isThisTheMessageThread());
  208843. QTMovie* movie = 0;
  208844. FileInputStream* const fin = dynamic_cast <FileInputStream*> (movieStream);
  208845. if (fin != 0)
  208846. {
  208847. movieFile = fin->getFile();
  208848. movie = [QTMovie movieWithFile: juceStringToNS (movieFile.getFullPathName())
  208849. error: nil];
  208850. }
  208851. else
  208852. {
  208853. MemoryBlock temp;
  208854. movieStream->readIntoMemoryBlock (temp);
  208855. const char* const suffixesToTry[] = { ".mov", ".mp3", ".avi", ".m4a" };
  208856. for (int i = 0; i < numElementsInArray (suffixesToTry); ++i)
  208857. {
  208858. movie = [QTMovie movieWithDataReference: [QTDataReference dataReferenceWithReferenceToData: [NSData dataWithBytes: temp.getData()
  208859. length: temp.getSize()]
  208860. name: [NSString stringWithUTF8String: suffixesToTry[i]]
  208861. MIMEType: @""]
  208862. error: nil];
  208863. if (movie != 0)
  208864. break;
  208865. }
  208866. }
  208867. return movie;
  208868. }
  208869. bool QuickTimeMovieComponent::loadMovie (const File& movieFile_,
  208870. const bool isControllerVisible_)
  208871. {
  208872. return loadMovie ((InputStream*) movieFile_.createInputStream(), isControllerVisible_);
  208873. }
  208874. bool QuickTimeMovieComponent::loadMovie (InputStream* movieStream,
  208875. const bool controllerVisible_)
  208876. {
  208877. closeMovie();
  208878. if (getPeer() == 0)
  208879. {
  208880. // To open a movie, this component must be visible inside a functioning window, so that
  208881. // the QT control can be assigned to the window.
  208882. jassertfalse
  208883. return false;
  208884. }
  208885. movie = openMovieFromStream (movieStream, movieFile);
  208886. [theMovie retain];
  208887. QTMovieView* view = (QTMovieView*) getView();
  208888. [view setMovie: theMovie];
  208889. [view setControllerVisible: controllerVisible_];
  208890. setLooping (looping);
  208891. return movie != nil;
  208892. }
  208893. bool QuickTimeMovieComponent::loadMovie (const URL& movieURL,
  208894. const bool isControllerVisible_)
  208895. {
  208896. // unfortunately, QTMovie objects can only be created on the main thread..
  208897. jassert (MessageManager::getInstance()->isThisTheMessageThread());
  208898. closeMovie();
  208899. if (getPeer() == 0)
  208900. {
  208901. // To open a movie, this component must be visible inside a functioning window, so that
  208902. // the QT control can be assigned to the window.
  208903. jassertfalse
  208904. return false;
  208905. }
  208906. NSURL* url = [NSURL URLWithString: juceStringToNS (movieURL.toString (true))];
  208907. NSError* err;
  208908. if ([QTMovie canInitWithURL: url])
  208909. movie = [QTMovie movieWithURL: url error: &err];
  208910. [theMovie retain];
  208911. QTMovieView* view = (QTMovieView*) getView();
  208912. [view setMovie: theMovie];
  208913. [view setControllerVisible: controllerVisible];
  208914. setLooping (looping);
  208915. return movie != nil;
  208916. }
  208917. void QuickTimeMovieComponent::closeMovie()
  208918. {
  208919. stop();
  208920. QTMovieView* view = (QTMovieView*) getView();
  208921. [view setMovie: nil];
  208922. [theMovie release];
  208923. movie = 0;
  208924. movieFile = File::nonexistent;
  208925. }
  208926. bool QuickTimeMovieComponent::isMovieOpen() const
  208927. {
  208928. return movie != nil;
  208929. }
  208930. const File QuickTimeMovieComponent::getCurrentMovieFile() const
  208931. {
  208932. return movieFile;
  208933. }
  208934. void QuickTimeMovieComponent::play()
  208935. {
  208936. [theMovie play];
  208937. }
  208938. void QuickTimeMovieComponent::stop()
  208939. {
  208940. [theMovie stop];
  208941. }
  208942. bool QuickTimeMovieComponent::isPlaying() const
  208943. {
  208944. return movie != 0 && [theMovie rate] != 0;
  208945. }
  208946. void QuickTimeMovieComponent::setPosition (const double seconds)
  208947. {
  208948. if (movie != 0)
  208949. {
  208950. QTTime t;
  208951. t.timeValue = (uint64) (100000.0 * seconds);
  208952. t.timeScale = 100000;
  208953. t.flags = 0;
  208954. [theMovie setCurrentTime: t];
  208955. }
  208956. }
  208957. double QuickTimeMovieComponent::getPosition() const
  208958. {
  208959. if (movie == 0)
  208960. return 0.0;
  208961. QTTime t = [theMovie currentTime];
  208962. return t.timeValue / (double) t.timeScale;
  208963. }
  208964. void QuickTimeMovieComponent::setSpeed (const float newSpeed)
  208965. {
  208966. [theMovie setRate: newSpeed];
  208967. }
  208968. double QuickTimeMovieComponent::getMovieDuration() const
  208969. {
  208970. if (movie == 0)
  208971. return 0.0;
  208972. QTTime t = [theMovie duration];
  208973. return t.timeValue / (double) t.timeScale;
  208974. }
  208975. void QuickTimeMovieComponent::setLooping (const bool shouldLoop)
  208976. {
  208977. looping = shouldLoop;
  208978. [theMovie setAttribute: [NSNumber numberWithBool: shouldLoop]
  208979. forKey: QTMovieLoopsAttribute];
  208980. }
  208981. bool QuickTimeMovieComponent::isLooping() const
  208982. {
  208983. return looping;
  208984. }
  208985. void QuickTimeMovieComponent::setMovieVolume (const float newVolume)
  208986. {
  208987. [theMovie setVolume: newVolume];
  208988. }
  208989. float QuickTimeMovieComponent::getMovieVolume() const
  208990. {
  208991. return movie != 0 ? [theMovie volume] : 0.0f;
  208992. }
  208993. void QuickTimeMovieComponent::getMovieNormalSize (int& width, int& height) const
  208994. {
  208995. width = 0;
  208996. height = 0;
  208997. if (movie != 0)
  208998. {
  208999. NSSize s = [[theMovie attributeForKey: QTMovieNaturalSizeAttribute] sizeValue];
  209000. width = (int) s.width;
  209001. height = (int) s.height;
  209002. }
  209003. }
  209004. void QuickTimeMovieComponent::paint (Graphics& g)
  209005. {
  209006. if (movie == 0)
  209007. g.fillAll (Colours::black);
  209008. }
  209009. bool QuickTimeMovieComponent::isControllerVisible() const
  209010. {
  209011. return controllerVisible;
  209012. }
  209013. void QuickTimeMovieComponent::goToStart()
  209014. {
  209015. setPosition (0.0);
  209016. }
  209017. void QuickTimeMovieComponent::setBoundsWithCorrectAspectRatio (const Rectangle<int>& spaceToFitWithin,
  209018. const RectanglePlacement& placement)
  209019. {
  209020. int normalWidth, normalHeight;
  209021. getMovieNormalSize (normalWidth, normalHeight);
  209022. if (normalWidth > 0 && normalHeight > 0 && ! spaceToFitWithin.isEmpty())
  209023. {
  209024. double x = 0.0, y = 0.0, w = normalWidth, h = normalHeight;
  209025. placement.applyTo (x, y, w, h,
  209026. spaceToFitWithin.getX(), spaceToFitWithin.getY(),
  209027. spaceToFitWithin.getWidth(), spaceToFitWithin.getHeight());
  209028. if (w > 0 && h > 0)
  209029. {
  209030. setBounds (roundToInt (x), roundToInt (y),
  209031. roundToInt (w), roundToInt (h));
  209032. }
  209033. }
  209034. else
  209035. {
  209036. setBounds (spaceToFitWithin);
  209037. }
  209038. }
  209039. #if ! (JUCE_MAC && JUCE_64BIT)
  209040. bool juce_OpenQuickTimeMovieFromStream (InputStream* movieStream, Movie& result, Handle& dataHandle)
  209041. {
  209042. if (movieStream == 0)
  209043. return false;
  209044. File file;
  209045. QTMovie* movie = openMovieFromStream (movieStream, file);
  209046. if (movie != nil)
  209047. result = [movie quickTimeMovie];
  209048. return movie != nil;
  209049. }
  209050. #endif
  209051. #endif
  209052. /*** End of inlined file: juce_mac_QuickTimeMovieComponent.mm ***/
  209053. /*** Start of inlined file: juce_mac_AudioCDBurner.mm ***/
  209054. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209055. // compiled on its own).
  209056. #if JUCE_INCLUDED_FILE && JUCE_USE_CDBURNER
  209057. const int kilobytesPerSecond1x = 176;
  209058. END_JUCE_NAMESPACE
  209059. #define OpenDiskDevice MakeObjCClassName(OpenDiskDevice)
  209060. @interface OpenDiskDevice : NSObject
  209061. {
  209062. @public
  209063. DRDevice* device;
  209064. NSMutableArray* tracks;
  209065. bool underrunProtection;
  209066. }
  209067. - (OpenDiskDevice*) initWithDRDevice: (DRDevice*) device;
  209068. - (void) dealloc;
  209069. - (void) addSourceTrack: (JUCE_NAMESPACE::AudioSource*) source numSamples: (int) numSamples_;
  209070. - (void) burn: (JUCE_NAMESPACE::AudioCDBurner::BurnProgressListener*) listener errorString: (JUCE_NAMESPACE::String*) error
  209071. ejectAfterwards: (bool) shouldEject isFake: (bool) peformFakeBurnForTesting speed: (int) burnSpeed;
  209072. @end
  209073. #define AudioTrackProducer MakeObjCClassName(AudioTrackProducer)
  209074. @interface AudioTrackProducer : NSObject
  209075. {
  209076. JUCE_NAMESPACE::AudioSource* source;
  209077. int readPosition, lengthInFrames;
  209078. }
  209079. - (AudioTrackProducer*) init: (int) lengthInFrames;
  209080. - (AudioTrackProducer*) initWithAudioSource: (JUCE_NAMESPACE::AudioSource*) source numSamples: (int) lengthInSamples;
  209081. - (void) dealloc;
  209082. - (void) setupTrackProperties: (DRTrack*) track;
  209083. - (void) cleanupTrackAfterBurn: (DRTrack*) track;
  209084. - (BOOL) cleanupTrackAfterVerification:(DRTrack*)track;
  209085. - (uint64_t) estimateLengthOfTrack:(DRTrack*)track;
  209086. - (BOOL) prepareTrack:(DRTrack*)track forBurn:(DRBurn*)burn
  209087. toMedia:(NSDictionary*)mediaInfo;
  209088. - (BOOL) prepareTrackForVerification:(DRTrack*)track;
  209089. - (uint32_t) produceDataForTrack:(DRTrack*)track intoBuffer:(char*)buffer
  209090. length:(uint32_t)bufferLength atAddress:(uint64_t)address
  209091. blockSize:(uint32_t)blockSize ioFlags:(uint32_t*)flags;
  209092. - (uint32_t) producePreGapForTrack:(DRTrack*)track
  209093. intoBuffer:(char*)buffer length:(uint32_t)bufferLength
  209094. atAddress:(uint64_t)address blockSize:(uint32_t)blockSize
  209095. ioFlags:(uint32_t*)flags;
  209096. - (BOOL) verifyDataForTrack:(DRTrack*)track inBuffer:(const char*)buffer
  209097. length:(uint32_t)bufferLength atAddress:(uint64_t)address
  209098. blockSize:(uint32_t)blockSize ioFlags:(uint32_t*)flags;
  209099. - (uint32_t) producePreGapForTrack:(DRTrack*)track
  209100. intoBuffer:(char*)buffer length:(uint32_t)bufferLength
  209101. atAddress:(uint64_t)address blockSize:(uint32_t)blockSize
  209102. ioFlags:(uint32_t*)flags;
  209103. @end
  209104. @implementation OpenDiskDevice
  209105. - (OpenDiskDevice*) initWithDRDevice: (DRDevice*) device_
  209106. {
  209107. [super init];
  209108. device = device_;
  209109. tracks = [[NSMutableArray alloc] init];
  209110. underrunProtection = true;
  209111. return self;
  209112. }
  209113. - (void) dealloc
  209114. {
  209115. [tracks release];
  209116. [super dealloc];
  209117. }
  209118. - (void) addSourceTrack: (JUCE_NAMESPACE::AudioSource*) source_ numSamples: (int) numSamples_
  209119. {
  209120. AudioTrackProducer* p = [[AudioTrackProducer alloc] initWithAudioSource: source_ numSamples: numSamples_];
  209121. DRTrack* t = [[DRTrack alloc] initWithProducer: p];
  209122. [p setupTrackProperties: t];
  209123. [tracks addObject: t];
  209124. [t release];
  209125. [p release];
  209126. }
  209127. - (void) burn: (JUCE_NAMESPACE::AudioCDBurner::BurnProgressListener*) listener errorString: (JUCE_NAMESPACE::String*) error
  209128. ejectAfterwards: (bool) shouldEject isFake: (bool) peformFakeBurnForTesting speed: (int) burnSpeed
  209129. {
  209130. DRBurn* burn = [DRBurn burnForDevice: device];
  209131. if (! [device acquireExclusiveAccess])
  209132. {
  209133. *error = "Couldn't open or write to the CD device";
  209134. return;
  209135. }
  209136. [device acquireMediaReservation];
  209137. NSMutableDictionary* d = [[burn properties] mutableCopy];
  209138. [d autorelease];
  209139. [d setObject: [NSNumber numberWithBool: peformFakeBurnForTesting] forKey: DRBurnTestingKey];
  209140. [d setObject: [NSNumber numberWithBool: false] forKey: DRBurnVerifyDiscKey];
  209141. [d setObject: (shouldEject ? DRBurnCompletionActionEject : DRBurnCompletionActionMount) forKey: DRBurnCompletionActionKey];
  209142. if (burnSpeed > 0)
  209143. [d setObject: [NSNumber numberWithFloat: burnSpeed * JUCE_NAMESPACE::kilobytesPerSecond1x] forKey: DRBurnRequestedSpeedKey];
  209144. if (! underrunProtection)
  209145. [d setObject: [NSNumber numberWithBool: false] forKey: DRBurnUnderrunProtectionKey];
  209146. [burn setProperties: d];
  209147. [burn writeLayout: tracks];
  209148. for (;;)
  209149. {
  209150. JUCE_NAMESPACE::Thread::sleep (300);
  209151. float progress = [[[burn status] objectForKey: DRStatusPercentCompleteKey] floatValue];
  209152. if (listener != 0 && listener->audioCDBurnProgress (progress))
  209153. {
  209154. [burn abort];
  209155. *error = "User cancelled the write operation";
  209156. break;
  209157. }
  209158. if ([[[burn status] objectForKey: DRStatusStateKey] isEqualTo: DRStatusStateFailed])
  209159. {
  209160. *error = "Write operation failed";
  209161. break;
  209162. }
  209163. else if ([[[burn status] objectForKey: DRStatusStateKey] isEqualTo: DRStatusStateDone])
  209164. {
  209165. break;
  209166. }
  209167. NSString* err = (NSString*) [[[burn status] objectForKey: DRErrorStatusKey]
  209168. objectForKey: DRErrorStatusErrorStringKey];
  209169. if ([err length] > 0)
  209170. {
  209171. *error = JUCE_NAMESPACE::String::fromUTF8 ([err UTF8String]);
  209172. break;
  209173. }
  209174. }
  209175. [device releaseMediaReservation];
  209176. [device releaseExclusiveAccess];
  209177. }
  209178. @end
  209179. @implementation AudioTrackProducer
  209180. - (AudioTrackProducer*) init: (int) lengthInFrames_
  209181. {
  209182. lengthInFrames = lengthInFrames_;
  209183. readPosition = 0;
  209184. return self;
  209185. }
  209186. - (void) setupTrackProperties: (DRTrack*) track
  209187. {
  209188. NSMutableDictionary* p = [[track properties] mutableCopy];
  209189. [p setObject:[DRMSF msfWithFrames: lengthInFrames] forKey: DRTrackLengthKey];
  209190. [p setObject:[NSNumber numberWithUnsignedShort:2352] forKey: DRBlockSizeKey];
  209191. [p setObject:[NSNumber numberWithInt:0] forKey: DRDataFormKey];
  209192. [p setObject:[NSNumber numberWithInt:0] forKey: DRBlockTypeKey];
  209193. [p setObject:[NSNumber numberWithInt:0] forKey: DRTrackModeKey];
  209194. [p setObject:[NSNumber numberWithInt:0] forKey: DRSessionFormatKey];
  209195. [track setProperties: p];
  209196. [p release];
  209197. }
  209198. - (AudioTrackProducer*) initWithAudioSource: (JUCE_NAMESPACE::AudioSource*) source_ numSamples: (int) lengthInSamples
  209199. {
  209200. AudioTrackProducer* s = [self init: (lengthInSamples + 587) / 588];
  209201. if (s != nil)
  209202. s->source = source_;
  209203. return s;
  209204. }
  209205. - (void) dealloc
  209206. {
  209207. if (source != 0)
  209208. {
  209209. source->releaseResources();
  209210. delete source;
  209211. }
  209212. [super dealloc];
  209213. }
  209214. - (void) cleanupTrackAfterBurn: (DRTrack*) track
  209215. {
  209216. }
  209217. - (BOOL) cleanupTrackAfterVerification: (DRTrack*) track
  209218. {
  209219. return true;
  209220. }
  209221. - (uint64_t) estimateLengthOfTrack: (DRTrack*) track
  209222. {
  209223. return lengthInFrames;
  209224. }
  209225. - (BOOL) prepareTrack: (DRTrack*) track forBurn: (DRBurn*) burn
  209226. toMedia: (NSDictionary*) mediaInfo
  209227. {
  209228. if (source != 0)
  209229. source->prepareToPlay (44100 / 75, 44100);
  209230. readPosition = 0;
  209231. return true;
  209232. }
  209233. - (BOOL) prepareTrackForVerification: (DRTrack*) track
  209234. {
  209235. if (source != 0)
  209236. source->prepareToPlay (44100 / 75, 44100);
  209237. return true;
  209238. }
  209239. - (uint32_t) produceDataForTrack: (DRTrack*) track intoBuffer: (char*) buffer
  209240. length: (uint32_t) bufferLength atAddress: (uint64_t) address
  209241. blockSize: (uint32_t) blockSize ioFlags: (uint32_t*) flags
  209242. {
  209243. if (source != 0)
  209244. {
  209245. const int numSamples = JUCE_NAMESPACE::jmin ((int) bufferLength / 4, (lengthInFrames * (44100 / 75)) - readPosition);
  209246. if (numSamples > 0)
  209247. {
  209248. JUCE_NAMESPACE::AudioSampleBuffer tempBuffer (2, numSamples);
  209249. JUCE_NAMESPACE::AudioSourceChannelInfo info;
  209250. info.buffer = &tempBuffer;
  209251. info.startSample = 0;
  209252. info.numSamples = numSamples;
  209253. source->getNextAudioBlock (info);
  209254. JUCE_NAMESPACE::AudioDataConverters::convertFloatToInt16LE (tempBuffer.getSampleData (0),
  209255. buffer, numSamples, 4);
  209256. JUCE_NAMESPACE::AudioDataConverters::convertFloatToInt16LE (tempBuffer.getSampleData (1),
  209257. buffer + 2, numSamples, 4);
  209258. readPosition += numSamples;
  209259. }
  209260. return numSamples * 4;
  209261. }
  209262. return 0;
  209263. }
  209264. - (uint32_t) producePreGapForTrack: (DRTrack*) track
  209265. intoBuffer: (char*) buffer length: (uint32_t) bufferLength
  209266. atAddress: (uint64_t) address blockSize: (uint32_t) blockSize
  209267. ioFlags: (uint32_t*) flags
  209268. {
  209269. zeromem (buffer, bufferLength);
  209270. return bufferLength;
  209271. }
  209272. - (BOOL) verifyDataForTrack: (DRTrack*) track inBuffer: (const char*) buffer
  209273. length: (uint32_t) bufferLength atAddress: (uint64_t) address
  209274. blockSize: (uint32_t) blockSize ioFlags: (uint32_t*) flags
  209275. {
  209276. return true;
  209277. }
  209278. @end
  209279. BEGIN_JUCE_NAMESPACE
  209280. class AudioCDBurner::Pimpl : public Timer
  209281. {
  209282. public:
  209283. Pimpl (AudioCDBurner& owner_, const int deviceIndex)
  209284. : device (0), owner (owner_)
  209285. {
  209286. DRDevice* dev = [[DRDevice devices] objectAtIndex: deviceIndex];
  209287. if (dev != 0)
  209288. {
  209289. device = [[OpenDiskDevice alloc] initWithDRDevice: dev];
  209290. lastState = getDiskState();
  209291. startTimer (1000);
  209292. }
  209293. }
  209294. ~Pimpl()
  209295. {
  209296. stopTimer();
  209297. [device release];
  209298. }
  209299. void timerCallback()
  209300. {
  209301. const DiskState state = getDiskState();
  209302. if (state != lastState)
  209303. {
  209304. lastState = state;
  209305. owner.sendChangeMessage (&owner);
  209306. }
  209307. }
  209308. DiskState getDiskState() const
  209309. {
  209310. if ([device->device isValid])
  209311. {
  209312. NSDictionary* status = [device->device status];
  209313. NSString* state = [status objectForKey: DRDeviceMediaStateKey];
  209314. if ([state isEqualTo: DRDeviceMediaStateNone])
  209315. {
  209316. if ([[status objectForKey: DRDeviceIsTrayOpenKey] boolValue])
  209317. return trayOpen;
  209318. return noDisc;
  209319. }
  209320. if ([state isEqualTo: DRDeviceMediaStateMediaPresent])
  209321. {
  209322. if ([[[status objectForKey: DRDeviceMediaInfoKey] objectForKey: DRDeviceMediaBlocksFreeKey] intValue] > 0)
  209323. return writableDiskPresent;
  209324. else
  209325. return readOnlyDiskPresent;
  209326. }
  209327. }
  209328. return unknown;
  209329. }
  209330. bool openTray() { return [device->device isValid] && [device->device ejectMedia]; }
  209331. const Array<int> getAvailableWriteSpeeds() const
  209332. {
  209333. Array<int> results;
  209334. if ([device->device isValid])
  209335. {
  209336. NSArray* speeds = [[[device->device status] objectForKey: DRDeviceMediaInfoKey] objectForKey: DRDeviceBurnSpeedsKey];
  209337. for (unsigned int i = 0; i < [speeds count]; ++i)
  209338. {
  209339. const int kbPerSec = [[speeds objectAtIndex: i] intValue];
  209340. results.add (kbPerSec / kilobytesPerSecond1x);
  209341. }
  209342. }
  209343. return results;
  209344. }
  209345. bool setBufferUnderrunProtection (const bool shouldBeEnabled)
  209346. {
  209347. if ([device->device isValid])
  209348. {
  209349. device->underrunProtection = shouldBeEnabled;
  209350. return shouldBeEnabled && [[[device->device status] objectForKey: DRDeviceCanUnderrunProtectCDKey] boolValue];
  209351. }
  209352. return false;
  209353. }
  209354. int getNumAvailableAudioBlocks() const
  209355. {
  209356. return [[[[device->device status] objectForKey: DRDeviceMediaInfoKey]
  209357. objectForKey: DRDeviceMediaBlocksFreeKey] intValue];
  209358. }
  209359. OpenDiskDevice* device;
  209360. private:
  209361. DiskState lastState;
  209362. AudioCDBurner& owner;
  209363. };
  209364. AudioCDBurner::AudioCDBurner (const int deviceIndex)
  209365. {
  209366. pimpl = new Pimpl (*this, deviceIndex);
  209367. }
  209368. AudioCDBurner::~AudioCDBurner()
  209369. {
  209370. }
  209371. AudioCDBurner* AudioCDBurner::openDevice (const int deviceIndex)
  209372. {
  209373. ScopedPointer <AudioCDBurner> b (new AudioCDBurner (deviceIndex));
  209374. if (b->pimpl->device == 0)
  209375. b = 0;
  209376. return b.release();
  209377. }
  209378. static NSArray* findDiskBurnerDevices()
  209379. {
  209380. NSMutableArray* results = [NSMutableArray array];
  209381. NSArray* devs = [DRDevice devices];
  209382. if (devs != 0)
  209383. {
  209384. int num = [devs count];
  209385. int i;
  209386. for (i = 0; i < num; ++i)
  209387. {
  209388. NSDictionary* dic = [[devs objectAtIndex: i] info];
  209389. NSString* name = [dic valueForKey: DRDeviceProductNameKey];
  209390. if (name != nil)
  209391. [results addObject: name];
  209392. }
  209393. }
  209394. return results;
  209395. }
  209396. const StringArray AudioCDBurner::findAvailableDevices()
  209397. {
  209398. NSArray* names = findDiskBurnerDevices();
  209399. StringArray s;
  209400. for (unsigned int i = 0; i < [names count]; ++i)
  209401. s.add (String::fromUTF8 ([[names objectAtIndex: i] UTF8String]));
  209402. return s;
  209403. }
  209404. AudioCDBurner::DiskState AudioCDBurner::getDiskState() const
  209405. {
  209406. return pimpl->getDiskState();
  209407. }
  209408. bool AudioCDBurner::isDiskPresent() const
  209409. {
  209410. return getDiskState() == writableDiskPresent;
  209411. }
  209412. bool AudioCDBurner::openTray()
  209413. {
  209414. return pimpl->openTray();
  209415. }
  209416. AudioCDBurner::DiskState AudioCDBurner::waitUntilStateChange (int timeOutMilliseconds)
  209417. {
  209418. const int64 timeout = Time::currentTimeMillis() + timeOutMilliseconds;
  209419. DiskState oldState = getDiskState();
  209420. DiskState newState = oldState;
  209421. while (newState == oldState && Time::currentTimeMillis() < timeout)
  209422. {
  209423. newState = getDiskState();
  209424. Thread::sleep (100);
  209425. }
  209426. return newState;
  209427. }
  209428. const Array<int> AudioCDBurner::getAvailableWriteSpeeds() const
  209429. {
  209430. return pimpl->getAvailableWriteSpeeds();
  209431. }
  209432. bool AudioCDBurner::setBufferUnderrunProtection (const bool shouldBeEnabled)
  209433. {
  209434. return pimpl->setBufferUnderrunProtection (shouldBeEnabled);
  209435. }
  209436. int AudioCDBurner::getNumAvailableAudioBlocks() const
  209437. {
  209438. return pimpl->getNumAvailableAudioBlocks();
  209439. }
  209440. bool AudioCDBurner::addAudioTrack (AudioSource* source, int numSamps)
  209441. {
  209442. if ([pimpl->device->device isValid])
  209443. {
  209444. [pimpl->device addSourceTrack: source numSamples: numSamps];
  209445. return true;
  209446. }
  209447. return false;
  209448. }
  209449. const String AudioCDBurner::burn (JUCE_NAMESPACE::AudioCDBurner::BurnProgressListener* listener,
  209450. bool ejectDiscAfterwards,
  209451. bool performFakeBurnForTesting,
  209452. int writeSpeed)
  209453. {
  209454. String error ("Couldn't open or write to the CD device");
  209455. if ([pimpl->device->device isValid])
  209456. {
  209457. error = String::empty;
  209458. [pimpl->device burn: listener
  209459. errorString: &error
  209460. ejectAfterwards: ejectDiscAfterwards
  209461. isFake: performFakeBurnForTesting
  209462. speed: writeSpeed];
  209463. }
  209464. return error;
  209465. }
  209466. #endif
  209467. #if JUCE_INCLUDED_FILE && JUCE_USE_CDREADER
  209468. void AudioCDReader::ejectDisk()
  209469. {
  209470. const ScopedAutoReleasePool p;
  209471. [[NSWorkspace sharedWorkspace] unmountAndEjectDeviceAtPath: juceStringToNS (volumeDir.getFullPathName())];
  209472. }
  209473. #endif
  209474. /*** End of inlined file: juce_mac_AudioCDBurner.mm ***/
  209475. /*** Start of inlined file: juce_mac_MessageManager.mm ***/
  209476. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209477. // compiled on its own).
  209478. #if JUCE_INCLUDED_FILE
  209479. struct CallbackMessagePayload
  209480. {
  209481. MessageCallbackFunction* function;
  209482. void* parameter;
  209483. void* volatile result;
  209484. bool volatile hasBeenExecuted;
  209485. };
  209486. class AppDelegateRedirector
  209487. {
  209488. public:
  209489. AppDelegateRedirector()
  209490. {
  209491. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_4
  209492. runLoop = CFRunLoopGetMain();
  209493. #else
  209494. runLoop = CFRunLoopGetCurrent();
  209495. #endif
  209496. CFRunLoopSourceContext sourceContext;
  209497. zerostruct (sourceContext);
  209498. sourceContext.info = this;
  209499. sourceContext.perform = runLoopSourceCallback;
  209500. runLoopSource = CFRunLoopSourceCreate (kCFAllocatorDefault, 1, &sourceContext);
  209501. CFRunLoopAddSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
  209502. }
  209503. virtual ~AppDelegateRedirector()
  209504. {
  209505. CFRunLoopRemoveSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
  209506. CFRunLoopSourceInvalidate (runLoopSource);
  209507. CFRelease (runLoopSource);
  209508. while (messages.size() > 0)
  209509. delete ((Message*) messages.remove(0));
  209510. }
  209511. virtual NSApplicationTerminateReply shouldTerminate()
  209512. {
  209513. if (JUCEApplication::getInstance() != 0)
  209514. {
  209515. JUCEApplication::getInstance()->systemRequestedQuit();
  209516. return NSTerminateCancel;
  209517. }
  209518. return NSTerminateNow;
  209519. }
  209520. virtual BOOL openFile (const NSString* filename)
  209521. {
  209522. if (JUCEApplication::getInstance() != 0)
  209523. {
  209524. JUCEApplication::getInstance()->anotherInstanceStarted (nsStringToJuce (filename));
  209525. return YES;
  209526. }
  209527. return NO;
  209528. }
  209529. virtual void openFiles (NSArray* filenames)
  209530. {
  209531. StringArray files;
  209532. for (unsigned int i = 0; i < [filenames count]; ++i)
  209533. {
  209534. String filename (nsStringToJuce ((NSString*) [filenames objectAtIndex: i]));
  209535. if (filename.containsChar (T(' ')))
  209536. filename = filename.quoted('"');
  209537. files.add (filename);
  209538. }
  209539. if (files.size() > 0 && JUCEApplication::getInstance() != 0)
  209540. {
  209541. JUCEApplication::getInstance()->anotherInstanceStarted (files.joinIntoString (T(" ")));
  209542. }
  209543. }
  209544. virtual void focusChanged()
  209545. {
  209546. juce_HandleProcessFocusChange();
  209547. }
  209548. virtual void performCallback (CallbackMessagePayload* pl)
  209549. {
  209550. pl->result = (*pl->function) (pl->parameter);
  209551. pl->hasBeenExecuted = true;
  209552. }
  209553. virtual void deleteSelf()
  209554. {
  209555. delete this;
  209556. }
  209557. void postMessage (void* m)
  209558. {
  209559. messages.add (m);
  209560. CFRunLoopSourceSignal (runLoopSource);
  209561. CFRunLoopWakeUp (runLoop);
  209562. }
  209563. private:
  209564. CFRunLoopRef runLoop;
  209565. CFRunLoopSourceRef runLoopSource;
  209566. Array <void*, CriticalSection> messages;
  209567. void runLoopCallback()
  209568. {
  209569. int numDispatched = 0;
  209570. do
  209571. {
  209572. void* const nextMessage = messages.remove (0);
  209573. if (nextMessage == 0)
  209574. return;
  209575. const ScopedAutoReleasePool pool;
  209576. MessageManager::getInstance()->deliverMessage (nextMessage);
  209577. } while (++numDispatched <= 4);
  209578. CFRunLoopSourceSignal (runLoopSource);
  209579. CFRunLoopWakeUp (runLoop);
  209580. }
  209581. static void runLoopSourceCallback (void* info)
  209582. {
  209583. ((AppDelegateRedirector*) info)->runLoopCallback();
  209584. }
  209585. };
  209586. END_JUCE_NAMESPACE
  209587. using namespace JUCE_NAMESPACE;
  209588. #define JuceAppDelegate MakeObjCClassName(JuceAppDelegate)
  209589. @interface JuceAppDelegate : NSObject
  209590. {
  209591. @private
  209592. id oldDelegate;
  209593. @public
  209594. AppDelegateRedirector* redirector;
  209595. }
  209596. - (JuceAppDelegate*) init;
  209597. - (void) dealloc;
  209598. - (BOOL) application: (NSApplication*) theApplication openFile: (NSString*) filename;
  209599. - (void) application: (NSApplication*) sender openFiles: (NSArray*) filenames;
  209600. - (NSApplicationTerminateReply) applicationShouldTerminate: (NSApplication*) app;
  209601. - (void) applicationDidBecomeActive: (NSNotification*) aNotification;
  209602. - (void) applicationDidResignActive: (NSNotification*) aNotification;
  209603. - (void) applicationWillUnhide: (NSNotification*) aNotification;
  209604. - (void) performCallback: (id) info;
  209605. - (void) dummyMethod;
  209606. @end
  209607. @implementation JuceAppDelegate
  209608. - (JuceAppDelegate*) init
  209609. {
  209610. [super init];
  209611. redirector = new AppDelegateRedirector();
  209612. NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
  209613. if (JUCEApplication::getInstance() != 0)
  209614. {
  209615. oldDelegate = [NSApp delegate];
  209616. [NSApp setDelegate: self];
  209617. }
  209618. else
  209619. {
  209620. oldDelegate = 0;
  209621. [center addObserver: self selector: @selector (applicationDidResignActive:)
  209622. name: NSApplicationDidResignActiveNotification object: NSApp];
  209623. [center addObserver: self selector: @selector (applicationDidBecomeActive:)
  209624. name: NSApplicationDidBecomeActiveNotification object: NSApp];
  209625. [center addObserver: self selector: @selector (applicationWillUnhide:)
  209626. name: NSApplicationWillUnhideNotification object: NSApp];
  209627. }
  209628. return self;
  209629. }
  209630. - (void) dealloc
  209631. {
  209632. if (oldDelegate != 0)
  209633. [NSApp setDelegate: oldDelegate];
  209634. redirector->deleteSelf();
  209635. [super dealloc];
  209636. }
  209637. - (NSApplicationTerminateReply) applicationShouldTerminate: (NSApplication*) app
  209638. {
  209639. return redirector->shouldTerminate();
  209640. }
  209641. - (BOOL) application: (NSApplication*) app openFile: (NSString*) filename
  209642. {
  209643. return redirector->openFile (filename);
  209644. }
  209645. - (void) application: (NSApplication*) sender openFiles: (NSArray*) filenames
  209646. {
  209647. return redirector->openFiles (filenames);
  209648. }
  209649. - (void) applicationDidBecomeActive: (NSNotification*) aNotification
  209650. {
  209651. redirector->focusChanged();
  209652. }
  209653. - (void) applicationDidResignActive: (NSNotification*) aNotification
  209654. {
  209655. redirector->focusChanged();
  209656. }
  209657. - (void) applicationWillUnhide: (NSNotification*) aNotification
  209658. {
  209659. redirector->focusChanged();
  209660. }
  209661. - (void) performCallback: (id) info
  209662. {
  209663. if ([info isKindOfClass: [NSData class]])
  209664. {
  209665. CallbackMessagePayload* pl = (CallbackMessagePayload*) [((NSData*) info) bytes];
  209666. if (pl != 0)
  209667. redirector->performCallback (pl);
  209668. }
  209669. else
  209670. {
  209671. jassertfalse // should never get here!
  209672. }
  209673. }
  209674. - (void) dummyMethod {} // (used as a way of running a dummy thread)
  209675. @end
  209676. BEGIN_JUCE_NAMESPACE
  209677. static JuceAppDelegate* juceAppDelegate = 0;
  209678. void MessageManager::runDispatchLoop()
  209679. {
  209680. if (! quitMessagePosted) // check that the quit message wasn't already posted..
  209681. {
  209682. const ScopedAutoReleasePool pool;
  209683. // must only be called by the message thread!
  209684. jassert (isThisTheMessageThread());
  209685. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  209686. @try
  209687. {
  209688. [NSApp run];
  209689. }
  209690. @catch (NSException* e)
  209691. {
  209692. // An AppKit exception will kill the app, but at least this provides a chance to log it.,
  209693. std::runtime_error ex (std::string ("NSException: ") + [[e name] UTF8String] + ", Reason:" + [[e reason] UTF8String]);
  209694. JUCEApplication::sendUnhandledException (&ex, __FILE__, __LINE__);
  209695. }
  209696. @finally
  209697. {
  209698. }
  209699. #else
  209700. [NSApp run];
  209701. #endif
  209702. }
  209703. }
  209704. void MessageManager::stopDispatchLoop()
  209705. {
  209706. quitMessagePosted = true;
  209707. [NSApp stop: nil];
  209708. [NSApp activateIgnoringOtherApps: YES]; // (if the app is inactive, it sits there and ignores the quit request until the next time it gets activated)
  209709. [NSEvent startPeriodicEventsAfterDelay: 0 withPeriod: 0.1];
  209710. }
  209711. static bool isEventBlockedByModalComps (NSEvent* e)
  209712. {
  209713. if (Component::getNumCurrentlyModalComponents() == 0)
  209714. return false;
  209715. NSWindow* const w = [e window];
  209716. if (w == 0 || [w worksWhenModal])
  209717. return false;
  209718. bool isKey = false, isInputAttempt = false;
  209719. switch ([e type])
  209720. {
  209721. case NSKeyDown:
  209722. case NSKeyUp:
  209723. isKey = isInputAttempt = true;
  209724. break;
  209725. case NSLeftMouseDown:
  209726. case NSRightMouseDown:
  209727. case NSOtherMouseDown:
  209728. isInputAttempt = true;
  209729. break;
  209730. case NSLeftMouseDragged:
  209731. case NSRightMouseDragged:
  209732. case NSLeftMouseUp:
  209733. case NSRightMouseUp:
  209734. case NSOtherMouseUp:
  209735. case NSOtherMouseDragged:
  209736. if (Desktop::getInstance().getDraggingMouseSource(0) != 0)
  209737. return false;
  209738. break;
  209739. case NSMouseMoved:
  209740. case NSMouseEntered:
  209741. case NSMouseExited:
  209742. case NSCursorUpdate:
  209743. case NSScrollWheel:
  209744. case NSTabletPoint:
  209745. case NSTabletProximity:
  209746. break;
  209747. default:
  209748. return false;
  209749. }
  209750. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  209751. {
  209752. ComponentPeer* const peer = ComponentPeer::getPeer (i);
  209753. NSView* const compView = (NSView*) peer->getNativeHandle();
  209754. if ([compView window] == w)
  209755. {
  209756. if (isKey)
  209757. {
  209758. if (compView == [w firstResponder])
  209759. return false;
  209760. }
  209761. else
  209762. {
  209763. if (NSPointInRect ([compView convertPoint: [e locationInWindow] fromView: nil],
  209764. [compView bounds]))
  209765. return false;
  209766. }
  209767. }
  209768. }
  209769. if (isInputAttempt)
  209770. {
  209771. if (! [NSApp isActive])
  209772. [NSApp activateIgnoringOtherApps: YES];
  209773. Component* const modal = Component::getCurrentlyModalComponent (0);
  209774. if (modal != 0)
  209775. modal->inputAttemptWhenModal();
  209776. }
  209777. return true;
  209778. }
  209779. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  209780. {
  209781. const ScopedAutoReleasePool pool;
  209782. jassert (isThisTheMessageThread()); // must only be called by the message thread
  209783. uint32 endTime = Time::getMillisecondCounter() + millisecondsToRunFor;
  209784. while (! quitMessagePosted)
  209785. {
  209786. const ScopedAutoReleasePool pool2;
  209787. CFRunLoopRunInMode (kCFRunLoopDefaultMode, 0.001, true);
  209788. NSEvent* e = [NSApp nextEventMatchingMask: NSAnyEventMask
  209789. untilDate: [NSDate dateWithTimeIntervalSinceNow: 0.001]
  209790. inMode: NSDefaultRunLoopMode
  209791. dequeue: YES];
  209792. if (e != 0 && ! isEventBlockedByModalComps (e))
  209793. [NSApp sendEvent: e];
  209794. if (Time::getMillisecondCounter() >= endTime)
  209795. break;
  209796. }
  209797. return ! quitMessagePosted;
  209798. }
  209799. void MessageManager::doPlatformSpecificInitialisation()
  209800. {
  209801. if (juceAppDelegate == 0)
  209802. juceAppDelegate = [[JuceAppDelegate alloc] init];
  209803. // This launches a dummy thread, which forces Cocoa to initialise NSThreads
  209804. // correctly (needed prior to 10.5)
  209805. if (! [NSThread isMultiThreaded])
  209806. [NSThread detachNewThreadSelector: @selector (dummyMethod)
  209807. toTarget: juceAppDelegate
  209808. withObject: nil];
  209809. initialiseMainMenu();
  209810. }
  209811. void MessageManager::doPlatformSpecificShutdown()
  209812. {
  209813. if (juceAppDelegate != 0)
  209814. {
  209815. [[NSRunLoop currentRunLoop] cancelPerformSelectorsWithTarget: juceAppDelegate];
  209816. [[NSNotificationCenter defaultCenter] removeObserver: juceAppDelegate];
  209817. [juceAppDelegate release];
  209818. juceAppDelegate = 0;
  209819. }
  209820. }
  209821. bool juce_postMessageToSystemQueue (void* message)
  209822. {
  209823. juceAppDelegate->redirector->postMessage (message);
  209824. return true;
  209825. }
  209826. void MessageManager::broadcastMessage (const String& value) throw()
  209827. {
  209828. }
  209829. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
  209830. void* data)
  209831. {
  209832. if (isThisTheMessageThread())
  209833. {
  209834. return (*callback) (data);
  209835. }
  209836. else
  209837. {
  209838. // If a thread has a MessageManagerLock and then tries to call this method, it'll
  209839. // deadlock because the message manager is blocked from running, so can never
  209840. // call your function..
  209841. jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  209842. const ScopedAutoReleasePool pool;
  209843. CallbackMessagePayload cmp;
  209844. cmp.function = callback;
  209845. cmp.parameter = data;
  209846. cmp.result = 0;
  209847. cmp.hasBeenExecuted = false;
  209848. [juceAppDelegate performSelectorOnMainThread: @selector (performCallback:)
  209849. withObject: [NSData dataWithBytesNoCopy: &cmp
  209850. length: sizeof (cmp)
  209851. freeWhenDone: NO]
  209852. waitUntilDone: YES];
  209853. return cmp.result;
  209854. }
  209855. }
  209856. #endif
  209857. /*** End of inlined file: juce_mac_MessageManager.mm ***/
  209858. /*** Start of inlined file: juce_mac_WebBrowserComponent.mm ***/
  209859. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209860. // compiled on its own).
  209861. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  209862. #if JUCE_MAC
  209863. END_JUCE_NAMESPACE
  209864. #define DownloadClickDetector MakeObjCClassName(DownloadClickDetector)
  209865. @interface DownloadClickDetector : NSObject
  209866. {
  209867. JUCE_NAMESPACE::WebBrowserComponent* ownerComponent;
  209868. }
  209869. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent;
  209870. - (void) webView: (WebView*) webView decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  209871. request: (NSURLRequest*) request
  209872. frame: (WebFrame*) frame
  209873. decisionListener: (id<WebPolicyDecisionListener>) listener;
  209874. @end
  209875. @implementation DownloadClickDetector
  209876. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent_
  209877. {
  209878. [super init];
  209879. ownerComponent = ownerComponent_;
  209880. return self;
  209881. }
  209882. - (void) webView: (WebView*) sender decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  209883. request: (NSURLRequest*) request
  209884. frame: (WebFrame*) frame
  209885. decisionListener: (id <WebPolicyDecisionListener>) listener
  209886. {
  209887. NSURL* url = [actionInformation valueForKey: @"WebActionOriginalURLKey"];
  209888. if (ownerComponent->pageAboutToLoad (nsStringToJuce ([url absoluteString])))
  209889. [listener use];
  209890. else
  209891. [listener ignore];
  209892. }
  209893. @end
  209894. BEGIN_JUCE_NAMESPACE
  209895. class WebBrowserComponentInternal : public NSViewComponent
  209896. {
  209897. public:
  209898. WebBrowserComponentInternal (WebBrowserComponent* owner)
  209899. {
  209900. webView = [[WebView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  209901. frameName: @""
  209902. groupName: @""];
  209903. setView (webView);
  209904. clickListener = [[DownloadClickDetector alloc] initWithWebBrowserOwner: owner];
  209905. [webView setPolicyDelegate: clickListener];
  209906. }
  209907. ~WebBrowserComponentInternal()
  209908. {
  209909. [webView setPolicyDelegate: nil];
  209910. [clickListener release];
  209911. setView (0);
  209912. }
  209913. void goToURL (const String& url,
  209914. const StringArray* headers,
  209915. const MemoryBlock* postData)
  209916. {
  209917. NSMutableURLRequest* r
  209918. = [NSMutableURLRequest requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
  209919. cachePolicy: NSURLRequestUseProtocolCachePolicy
  209920. timeoutInterval: 30.0];
  209921. if (postData != 0 && postData->getSize() > 0)
  209922. {
  209923. [r setHTTPMethod: @"POST"];
  209924. [r setHTTPBody: [NSData dataWithBytes: postData->getData()
  209925. length: postData->getSize()]];
  209926. }
  209927. if (headers != 0)
  209928. {
  209929. for (int i = 0; i < headers->size(); ++i)
  209930. {
  209931. const String headerName ((*headers)[i].upToFirstOccurrenceOf (T(":"), false, false).trim());
  209932. const String headerValue ((*headers)[i].fromFirstOccurrenceOf (T(":"), false, false).trim());
  209933. [r setValue: juceStringToNS (headerValue)
  209934. forHTTPHeaderField: juceStringToNS (headerName)];
  209935. }
  209936. }
  209937. stop();
  209938. [[webView mainFrame] loadRequest: r];
  209939. }
  209940. void goBack()
  209941. {
  209942. [webView goBack];
  209943. }
  209944. void goForward()
  209945. {
  209946. [webView goForward];
  209947. }
  209948. void stop()
  209949. {
  209950. [webView stopLoading: nil];
  209951. }
  209952. void refresh()
  209953. {
  209954. [webView reload: nil];
  209955. }
  209956. private:
  209957. WebView* webView;
  209958. DownloadClickDetector* clickListener;
  209959. };
  209960. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  209961. : browser (0),
  209962. blankPageShown (false),
  209963. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  209964. {
  209965. setOpaque (true);
  209966. addAndMakeVisible (browser = new WebBrowserComponentInternal (this));
  209967. }
  209968. WebBrowserComponent::~WebBrowserComponent()
  209969. {
  209970. deleteAndZero (browser);
  209971. }
  209972. void WebBrowserComponent::goToURL (const String& url,
  209973. const StringArray* headers,
  209974. const MemoryBlock* postData)
  209975. {
  209976. lastURL = url;
  209977. lastHeaders.clear();
  209978. if (headers != 0)
  209979. lastHeaders = *headers;
  209980. lastPostData.setSize (0);
  209981. if (postData != 0)
  209982. lastPostData = *postData;
  209983. blankPageShown = false;
  209984. browser->goToURL (url, headers, postData);
  209985. }
  209986. void WebBrowserComponent::stop()
  209987. {
  209988. browser->stop();
  209989. }
  209990. void WebBrowserComponent::goBack()
  209991. {
  209992. lastURL = String::empty;
  209993. blankPageShown = false;
  209994. browser->goBack();
  209995. }
  209996. void WebBrowserComponent::goForward()
  209997. {
  209998. lastURL = String::empty;
  209999. browser->goForward();
  210000. }
  210001. void WebBrowserComponent::refresh()
  210002. {
  210003. browser->refresh();
  210004. }
  210005. void WebBrowserComponent::paint (Graphics& g)
  210006. {
  210007. }
  210008. void WebBrowserComponent::checkWindowAssociation()
  210009. {
  210010. if (isShowing())
  210011. {
  210012. if (blankPageShown)
  210013. goBack();
  210014. }
  210015. else
  210016. {
  210017. if (unloadPageWhenBrowserIsHidden && ! blankPageShown)
  210018. {
  210019. // when the component becomes invisible, some stuff like flash
  210020. // carries on playing audio, so we need to force it onto a blank
  210021. // page to avoid this, (and send it back when it's made visible again).
  210022. blankPageShown = true;
  210023. browser->goToURL ("about:blank", 0, 0);
  210024. }
  210025. }
  210026. }
  210027. void WebBrowserComponent::reloadLastURL()
  210028. {
  210029. if (lastURL.isNotEmpty())
  210030. {
  210031. goToURL (lastURL, &lastHeaders, &lastPostData);
  210032. lastURL = String::empty;
  210033. }
  210034. }
  210035. void WebBrowserComponent::parentHierarchyChanged()
  210036. {
  210037. checkWindowAssociation();
  210038. }
  210039. void WebBrowserComponent::resized()
  210040. {
  210041. browser->setSize (getWidth(), getHeight());
  210042. }
  210043. void WebBrowserComponent::visibilityChanged()
  210044. {
  210045. checkWindowAssociation();
  210046. }
  210047. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  210048. {
  210049. return true;
  210050. }
  210051. #else
  210052. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  210053. {
  210054. }
  210055. WebBrowserComponent::~WebBrowserComponent()
  210056. {
  210057. }
  210058. void WebBrowserComponent::goToURL (const String& url,
  210059. const StringArray* headers,
  210060. const MemoryBlock* postData)
  210061. {
  210062. }
  210063. void WebBrowserComponent::stop()
  210064. {
  210065. }
  210066. void WebBrowserComponent::goBack()
  210067. {
  210068. }
  210069. void WebBrowserComponent::goForward()
  210070. {
  210071. }
  210072. void WebBrowserComponent::refresh()
  210073. {
  210074. }
  210075. void WebBrowserComponent::paint (Graphics& g)
  210076. {
  210077. }
  210078. void WebBrowserComponent::checkWindowAssociation()
  210079. {
  210080. }
  210081. void WebBrowserComponent::reloadLastURL()
  210082. {
  210083. }
  210084. void WebBrowserComponent::parentHierarchyChanged()
  210085. {
  210086. }
  210087. void WebBrowserComponent::resized()
  210088. {
  210089. }
  210090. void WebBrowserComponent::visibilityChanged()
  210091. {
  210092. }
  210093. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  210094. {
  210095. return true;
  210096. }
  210097. #endif
  210098. #endif
  210099. /*** End of inlined file: juce_mac_WebBrowserComponent.mm ***/
  210100. /*** Start of inlined file: juce_mac_CoreAudio.cpp ***/
  210101. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  210102. // compiled on its own).
  210103. #if JUCE_INCLUDED_FILE
  210104. #ifndef JUCE_COREAUDIO_ERROR_LOGGING_ENABLED
  210105. #define JUCE_COREAUDIO_ERROR_LOGGING_ENABLED 1
  210106. #endif
  210107. #undef log
  210108. #if JUCE_COREAUDIO_LOGGING_ENABLED
  210109. #define log(a) Logger::writeToLog (a)
  210110. #else
  210111. #define log(a)
  210112. #endif
  210113. #undef OK
  210114. #if JUCE_COREAUDIO_ERROR_LOGGING_ENABLED
  210115. static bool logAnyErrors_CoreAudio (const OSStatus err, const int lineNum)
  210116. {
  210117. if (err == noErr)
  210118. return true;
  210119. Logger::writeToLog (T("CoreAudio error: ") + String (lineNum) + T(" - ") + String::toHexString ((int)err));
  210120. jassertfalse
  210121. return false;
  210122. }
  210123. #define OK(a) logAnyErrors_CoreAudio (a, __LINE__)
  210124. #else
  210125. #define OK(a) (a == noErr)
  210126. #endif
  210127. class CoreAudioInternal : public Timer
  210128. {
  210129. public:
  210130. CoreAudioInternal (AudioDeviceID id)
  210131. : inputLatency (0),
  210132. outputLatency (0),
  210133. callback (0),
  210134. #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
  210135. audioProcID (0),
  210136. #endif
  210137. inputDevice (0),
  210138. isSlaveDevice (false),
  210139. deviceID (id),
  210140. started (false),
  210141. sampleRate (0),
  210142. bufferSize (512),
  210143. numInputChans (0),
  210144. numOutputChans (0),
  210145. callbacksAllowed (true),
  210146. numInputChannelInfos (0),
  210147. numOutputChannelInfos (0)
  210148. {
  210149. jassert (deviceID != 0);
  210150. updateDetailsFromDevice();
  210151. AudioObjectPropertyAddress pa;
  210152. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  210153. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210154. pa.mElement = kAudioObjectPropertyElementWildcard;
  210155. AudioObjectAddPropertyListener (deviceID, &pa, deviceListenerProc, this);
  210156. }
  210157. ~CoreAudioInternal()
  210158. {
  210159. AudioObjectPropertyAddress pa;
  210160. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  210161. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210162. pa.mElement = kAudioObjectPropertyElementWildcard;
  210163. AudioObjectRemovePropertyListener (deviceID, &pa, deviceListenerProc, this);
  210164. stop (false);
  210165. delete inputDevice;
  210166. }
  210167. void allocateTempBuffers()
  210168. {
  210169. const int tempBufSize = bufferSize + 4;
  210170. audioBuffer.calloc ((numInputChans + numOutputChans) * tempBufSize);
  210171. tempInputBuffers.calloc (numInputChans + 2);
  210172. tempOutputBuffers.calloc (numOutputChans + 2);
  210173. int i, count = 0;
  210174. for (i = 0; i < numInputChans; ++i)
  210175. tempInputBuffers[i] = audioBuffer + count++ * tempBufSize;
  210176. for (i = 0; i < numOutputChans; ++i)
  210177. tempOutputBuffers[i] = audioBuffer + count++ * tempBufSize;
  210178. }
  210179. // returns the number of actual available channels
  210180. void fillInChannelInfo (const bool input)
  210181. {
  210182. int chanNum = 0;
  210183. UInt32 size;
  210184. AudioObjectPropertyAddress pa;
  210185. pa.mSelector = kAudioDevicePropertyStreamConfiguration;
  210186. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210187. pa.mElement = kAudioObjectPropertyElementMaster;
  210188. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210189. {
  210190. HeapBlock <AudioBufferList> bufList;
  210191. bufList.calloc (size, 1);
  210192. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, bufList)))
  210193. {
  210194. const int numStreams = bufList->mNumberBuffers;
  210195. for (int i = 0; i < numStreams; ++i)
  210196. {
  210197. const AudioBuffer& b = bufList->mBuffers[i];
  210198. for (unsigned int j = 0; j < b.mNumberChannels; ++j)
  210199. {
  210200. String name;
  210201. {
  210202. char channelName [256];
  210203. zerostruct (channelName);
  210204. UInt32 nameSize = sizeof (channelName);
  210205. UInt32 channelNum = chanNum + 1;
  210206. pa.mSelector = kAudioDevicePropertyChannelName;
  210207. if (AudioObjectGetPropertyData (deviceID, &pa, sizeof (channelNum), &channelNum, &nameSize, channelName) == noErr)
  210208. name = String::fromUTF8 (channelName, nameSize);
  210209. }
  210210. if (input)
  210211. {
  210212. if (activeInputChans[chanNum])
  210213. {
  210214. inputChannelInfo [numInputChannelInfos].streamNum = i;
  210215. inputChannelInfo [numInputChannelInfos].dataOffsetSamples = j;
  210216. inputChannelInfo [numInputChannelInfos].dataStrideSamples = b.mNumberChannels;
  210217. ++numInputChannelInfos;
  210218. }
  210219. if (name.isEmpty())
  210220. name << "Input " << (chanNum + 1);
  210221. inChanNames.add (name);
  210222. }
  210223. else
  210224. {
  210225. if (activeOutputChans[chanNum])
  210226. {
  210227. outputChannelInfo [numOutputChannelInfos].streamNum = i;
  210228. outputChannelInfo [numOutputChannelInfos].dataOffsetSamples = j;
  210229. outputChannelInfo [numOutputChannelInfos].dataStrideSamples = b.mNumberChannels;
  210230. ++numOutputChannelInfos;
  210231. }
  210232. if (name.isEmpty())
  210233. name << "Output " << (chanNum + 1);
  210234. outChanNames.add (name);
  210235. }
  210236. ++chanNum;
  210237. }
  210238. }
  210239. }
  210240. }
  210241. }
  210242. void updateDetailsFromDevice()
  210243. {
  210244. stopTimer();
  210245. if (deviceID == 0)
  210246. return;
  210247. const ScopedLock sl (callbackLock);
  210248. Float64 sr;
  210249. UInt32 size = sizeof (Float64);
  210250. AudioObjectPropertyAddress pa;
  210251. pa.mSelector = kAudioDevicePropertyNominalSampleRate;
  210252. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210253. pa.mElement = kAudioObjectPropertyElementMaster;
  210254. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &sr)))
  210255. sampleRate = sr;
  210256. UInt32 framesPerBuf;
  210257. size = sizeof (framesPerBuf);
  210258. pa.mSelector = kAudioDevicePropertyBufferFrameSize;
  210259. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &framesPerBuf)))
  210260. {
  210261. bufferSize = framesPerBuf;
  210262. allocateTempBuffers();
  210263. }
  210264. bufferSizes.clear();
  210265. pa.mSelector = kAudioDevicePropertyBufferFrameSizeRange;
  210266. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210267. {
  210268. HeapBlock <AudioValueRange> ranges;
  210269. ranges.calloc (size, 1);
  210270. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, ranges)))
  210271. {
  210272. bufferSizes.add ((int) ranges[0].mMinimum);
  210273. for (int i = 32; i < 2048; i += 32)
  210274. {
  210275. for (int j = size / (int) sizeof (AudioValueRange); --j >= 0;)
  210276. {
  210277. if (i >= ranges[j].mMinimum && i <= ranges[j].mMaximum)
  210278. {
  210279. bufferSizes.addIfNotAlreadyThere (i);
  210280. break;
  210281. }
  210282. }
  210283. }
  210284. if (bufferSize > 0)
  210285. bufferSizes.addIfNotAlreadyThere (bufferSize);
  210286. }
  210287. }
  210288. if (bufferSizes.size() == 0 && bufferSize > 0)
  210289. bufferSizes.add (bufferSize);
  210290. sampleRates.clear();
  210291. const double possibleRates[] = { 44100.0, 48000.0, 88200.0, 96000.0, 176400.0, 192000.0 };
  210292. String rates;
  210293. pa.mSelector = kAudioDevicePropertyAvailableNominalSampleRates;
  210294. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210295. {
  210296. HeapBlock <AudioValueRange> ranges;
  210297. ranges.calloc (size, 1);
  210298. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, ranges)))
  210299. {
  210300. for (int i = 0; i < numElementsInArray (possibleRates); ++i)
  210301. {
  210302. bool ok = false;
  210303. for (int j = size / (int) sizeof (AudioValueRange); --j >= 0;)
  210304. if (possibleRates[i] >= ranges[j].mMinimum - 2 && possibleRates[i] <= ranges[j].mMaximum + 2)
  210305. ok = true;
  210306. if (ok)
  210307. {
  210308. sampleRates.add (possibleRates[i]);
  210309. rates << possibleRates[i] << T(" ");
  210310. }
  210311. }
  210312. }
  210313. }
  210314. if (sampleRates.size() == 0 && sampleRate > 0)
  210315. {
  210316. sampleRates.add (sampleRate);
  210317. rates << sampleRate;
  210318. }
  210319. log (T("sr: ") + rates);
  210320. inputLatency = 0;
  210321. outputLatency = 0;
  210322. UInt32 lat;
  210323. size = sizeof (lat);
  210324. pa.mSelector = kAudioDevicePropertyLatency;
  210325. pa.mScope = kAudioDevicePropertyScopeInput;
  210326. //if (AudioDeviceGetProperty (deviceID, 0, true, kAudioDevicePropertyLatency, &size, &lat) == noErr)
  210327. if (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &lat) == noErr)
  210328. inputLatency = (int) lat;
  210329. pa.mScope = kAudioDevicePropertyScopeOutput;
  210330. size = sizeof (lat);
  210331. if (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &lat) == noErr)
  210332. outputLatency = (int) lat;
  210333. log (T("lat: ") + String (inputLatency) + T(" ") + String (outputLatency));
  210334. inChanNames.clear();
  210335. outChanNames.clear();
  210336. inputChannelInfo.calloc (numInputChans + 2);
  210337. numInputChannelInfos = 0;
  210338. outputChannelInfo.calloc (numOutputChans + 2);
  210339. numOutputChannelInfos = 0;
  210340. fillInChannelInfo (true);
  210341. fillInChannelInfo (false);
  210342. }
  210343. const StringArray getSources (bool input)
  210344. {
  210345. StringArray s;
  210346. HeapBlock <OSType> types;
  210347. const int num = getAllDataSourcesForDevice (deviceID, input, types);
  210348. for (int i = 0; i < num; ++i)
  210349. {
  210350. AudioValueTranslation avt;
  210351. char buffer[256];
  210352. avt.mInputData = (void*) &(types[i]);
  210353. avt.mInputDataSize = sizeof (UInt32);
  210354. avt.mOutputData = buffer;
  210355. avt.mOutputDataSize = 256;
  210356. UInt32 transSize = sizeof (avt);
  210357. AudioObjectPropertyAddress pa;
  210358. pa.mSelector = kAudioDevicePropertyDataSourceNameForID;
  210359. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210360. pa.mElement = kAudioObjectPropertyElementMaster;
  210361. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &transSize, &avt)))
  210362. {
  210363. DBG (buffer);
  210364. s.add (buffer);
  210365. }
  210366. }
  210367. return s;
  210368. }
  210369. int getCurrentSourceIndex (bool input) const
  210370. {
  210371. OSType currentSourceID = 0;
  210372. UInt32 size = sizeof (currentSourceID);
  210373. int result = -1;
  210374. AudioObjectPropertyAddress pa;
  210375. pa.mSelector = kAudioDevicePropertyDataSource;
  210376. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210377. pa.mElement = kAudioObjectPropertyElementMaster;
  210378. if (deviceID != 0)
  210379. {
  210380. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &currentSourceID)))
  210381. {
  210382. HeapBlock <OSType> types;
  210383. const int num = getAllDataSourcesForDevice (deviceID, input, types);
  210384. for (int i = 0; i < num; ++i)
  210385. {
  210386. if (types[num] == currentSourceID)
  210387. {
  210388. result = i;
  210389. break;
  210390. }
  210391. }
  210392. }
  210393. }
  210394. return result;
  210395. }
  210396. void setCurrentSourceIndex (int index, bool input)
  210397. {
  210398. if (deviceID != 0)
  210399. {
  210400. HeapBlock <OSType> types;
  210401. const int num = getAllDataSourcesForDevice (deviceID, input, types);
  210402. if (((unsigned int) index) < (unsigned int) num)
  210403. {
  210404. AudioObjectPropertyAddress pa;
  210405. pa.mSelector = kAudioDevicePropertyDataSource;
  210406. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210407. pa.mElement = kAudioObjectPropertyElementMaster;
  210408. OSType typeId = types[index];
  210409. OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (typeId), &typeId));
  210410. }
  210411. }
  210412. }
  210413. const String reopen (const BitArray& inputChannels,
  210414. const BitArray& outputChannels,
  210415. double newSampleRate,
  210416. int bufferSizeSamples)
  210417. {
  210418. String error;
  210419. log ("CoreAudio reopen");
  210420. callbacksAllowed = false;
  210421. stopTimer();
  210422. stop (false);
  210423. activeInputChans = inputChannels;
  210424. activeInputChans.setRange (inChanNames.size(),
  210425. activeInputChans.getHighestBit() + 1 - inChanNames.size(),
  210426. false);
  210427. activeOutputChans = outputChannels;
  210428. activeOutputChans.setRange (outChanNames.size(),
  210429. activeOutputChans.getHighestBit() + 1 - outChanNames.size(),
  210430. false);
  210431. numInputChans = activeInputChans.countNumberOfSetBits();
  210432. numOutputChans = activeOutputChans.countNumberOfSetBits();
  210433. // set sample rate
  210434. AudioObjectPropertyAddress pa;
  210435. pa.mSelector = kAudioDevicePropertyNominalSampleRate;
  210436. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210437. pa.mElement = kAudioObjectPropertyElementMaster;
  210438. Float64 sr = newSampleRate;
  210439. if (! OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (sr), &sr)))
  210440. {
  210441. error = "Couldn't change sample rate";
  210442. }
  210443. else
  210444. {
  210445. // change buffer size
  210446. UInt32 framesPerBuf = bufferSizeSamples;
  210447. pa.mSelector = kAudioDevicePropertyBufferFrameSize;
  210448. if (! OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (framesPerBuf), &framesPerBuf)))
  210449. {
  210450. error = "Couldn't change buffer size";
  210451. }
  210452. else
  210453. {
  210454. // Annoyingly, after changing the rate and buffer size, some devices fail to
  210455. // correctly report their new settings until some random time in the future, so
  210456. // after calling updateDetailsFromDevice, we need to manually bodge these values
  210457. // to make sure we're using the correct numbers..
  210458. updateDetailsFromDevice();
  210459. sampleRate = newSampleRate;
  210460. bufferSize = bufferSizeSamples;
  210461. if (sampleRates.size() == 0)
  210462. error = "Device has no available sample-rates";
  210463. else if (bufferSizes.size() == 0)
  210464. error = "Device has no available buffer-sizes";
  210465. else if (inputDevice != 0)
  210466. error = inputDevice->reopen (inputChannels,
  210467. outputChannels,
  210468. newSampleRate,
  210469. bufferSizeSamples);
  210470. }
  210471. }
  210472. callbacksAllowed = true;
  210473. return error;
  210474. }
  210475. bool start (AudioIODeviceCallback* cb)
  210476. {
  210477. if (! started)
  210478. {
  210479. callback = 0;
  210480. if (deviceID != 0)
  210481. {
  210482. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  210483. if (OK (AudioDeviceAddIOProc (deviceID, audioIOProc, (void*) this)))
  210484. #else
  210485. if (OK (AudioDeviceCreateIOProcID (deviceID, audioIOProc, (void*) this, &audioProcID)))
  210486. #endif
  210487. {
  210488. if (OK (AudioDeviceStart (deviceID, audioIOProc)))
  210489. {
  210490. started = true;
  210491. }
  210492. else
  210493. {
  210494. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  210495. OK (AudioDeviceRemoveIOProc (deviceID, audioIOProc));
  210496. #else
  210497. OK (AudioDeviceDestroyIOProcID (deviceID, audioProcID));
  210498. audioProcID = 0;
  210499. #endif
  210500. }
  210501. }
  210502. }
  210503. }
  210504. if (started)
  210505. {
  210506. const ScopedLock sl (callbackLock);
  210507. callback = cb;
  210508. }
  210509. if (inputDevice != 0)
  210510. return started && inputDevice->start (cb);
  210511. else
  210512. return started;
  210513. }
  210514. void stop (bool leaveInterruptRunning)
  210515. {
  210516. {
  210517. const ScopedLock sl (callbackLock);
  210518. callback = 0;
  210519. }
  210520. if (started
  210521. && (deviceID != 0)
  210522. && ! leaveInterruptRunning)
  210523. {
  210524. OK (AudioDeviceStop (deviceID, audioIOProc));
  210525. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  210526. OK (AudioDeviceRemoveIOProc (deviceID, audioIOProc));
  210527. #else
  210528. OK (AudioDeviceDestroyIOProcID (deviceID, audioProcID));
  210529. audioProcID = 0;
  210530. #endif
  210531. started = false;
  210532. { const ScopedLock sl (callbackLock); }
  210533. // wait until it's definately stopped calling back..
  210534. for (int i = 40; --i >= 0;)
  210535. {
  210536. Thread::sleep (50);
  210537. UInt32 running = 0;
  210538. UInt32 size = sizeof (running);
  210539. AudioObjectPropertyAddress pa;
  210540. pa.mSelector = kAudioDevicePropertyDeviceIsRunning;
  210541. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210542. pa.mElement = kAudioObjectPropertyElementMaster;
  210543. OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &running));
  210544. if (running == 0)
  210545. break;
  210546. }
  210547. const ScopedLock sl (callbackLock);
  210548. }
  210549. if (inputDevice != 0)
  210550. inputDevice->stop (leaveInterruptRunning);
  210551. }
  210552. double getSampleRate() const
  210553. {
  210554. return sampleRate;
  210555. }
  210556. int getBufferSize() const
  210557. {
  210558. return bufferSize;
  210559. }
  210560. void audioCallback (const AudioBufferList* inInputData,
  210561. AudioBufferList* outOutputData)
  210562. {
  210563. int i;
  210564. const ScopedLock sl (callbackLock);
  210565. if (callback != 0)
  210566. {
  210567. if (inputDevice == 0)
  210568. {
  210569. for (i = numInputChans; --i >= 0;)
  210570. {
  210571. const CallbackDetailsForChannel& info = inputChannelInfo[i];
  210572. float* dest = tempInputBuffers [i];
  210573. const float* src = ((const float*) inInputData->mBuffers[info.streamNum].mData)
  210574. + info.dataOffsetSamples;
  210575. const int stride = info.dataStrideSamples;
  210576. if (stride != 0) // if this is zero, info is invalid
  210577. {
  210578. for (int j = bufferSize; --j >= 0;)
  210579. {
  210580. *dest++ = *src;
  210581. src += stride;
  210582. }
  210583. }
  210584. }
  210585. }
  210586. if (! isSlaveDevice)
  210587. {
  210588. if (inputDevice == 0)
  210589. {
  210590. callback->audioDeviceIOCallback (const_cast<const float**> (tempInputBuffers.getData()),
  210591. numInputChans,
  210592. tempOutputBuffers,
  210593. numOutputChans,
  210594. bufferSize);
  210595. }
  210596. else
  210597. {
  210598. jassert (inputDevice->bufferSize == bufferSize);
  210599. // Sometimes the two linked devices seem to get their callbacks in
  210600. // parallel, so we need to lock both devices to stop the input data being
  210601. // changed while inside our callback..
  210602. const ScopedLock sl2 (inputDevice->callbackLock);
  210603. callback->audioDeviceIOCallback (const_cast<const float**> (inputDevice->tempInputBuffers.getData()),
  210604. inputDevice->numInputChans,
  210605. tempOutputBuffers,
  210606. numOutputChans,
  210607. bufferSize);
  210608. }
  210609. for (i = numOutputChans; --i >= 0;)
  210610. {
  210611. const CallbackDetailsForChannel& info = outputChannelInfo[i];
  210612. const float* src = tempOutputBuffers [i];
  210613. float* dest = ((float*) outOutputData->mBuffers[info.streamNum].mData)
  210614. + info.dataOffsetSamples;
  210615. const int stride = info.dataStrideSamples;
  210616. if (stride != 0) // if this is zero, info is invalid
  210617. {
  210618. for (int j = bufferSize; --j >= 0;)
  210619. {
  210620. *dest = *src++;
  210621. dest += stride;
  210622. }
  210623. }
  210624. }
  210625. }
  210626. }
  210627. else
  210628. {
  210629. for (i = jmin (numOutputChans, numOutputChannelInfos); --i >= 0;)
  210630. {
  210631. const CallbackDetailsForChannel& info = outputChannelInfo[i];
  210632. float* dest = ((float*) outOutputData->mBuffers[info.streamNum].mData)
  210633. + info.dataOffsetSamples;
  210634. const int stride = info.dataStrideSamples;
  210635. if (stride != 0) // if this is zero, info is invalid
  210636. {
  210637. for (int j = bufferSize; --j >= 0;)
  210638. {
  210639. *dest = 0.0f;
  210640. dest += stride;
  210641. }
  210642. }
  210643. }
  210644. }
  210645. }
  210646. // called by callbacks
  210647. void deviceDetailsChanged()
  210648. {
  210649. if (callbacksAllowed)
  210650. startTimer (100);
  210651. }
  210652. void timerCallback()
  210653. {
  210654. stopTimer();
  210655. log ("CoreAudio device changed callback");
  210656. const double oldSampleRate = sampleRate;
  210657. const int oldBufferSize = bufferSize;
  210658. updateDetailsFromDevice();
  210659. if (oldBufferSize != bufferSize || oldSampleRate != sampleRate)
  210660. {
  210661. callbacksAllowed = false;
  210662. stop (false);
  210663. updateDetailsFromDevice();
  210664. callbacksAllowed = true;
  210665. }
  210666. }
  210667. CoreAudioInternal* getRelatedDevice() const
  210668. {
  210669. UInt32 size = 0;
  210670. ScopedPointer <CoreAudioInternal> result;
  210671. AudioObjectPropertyAddress pa;
  210672. pa.mSelector = kAudioDevicePropertyRelatedDevices;
  210673. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210674. pa.mElement = kAudioObjectPropertyElementMaster;
  210675. if (deviceID != 0
  210676. && AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size) == noErr
  210677. && size > 0)
  210678. {
  210679. HeapBlock <AudioDeviceID> devs;
  210680. devs.calloc (size, 1);
  210681. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, devs)))
  210682. {
  210683. for (unsigned int i = 0; i < size / sizeof (AudioDeviceID); ++i)
  210684. {
  210685. if (devs[i] != deviceID && devs[i] != 0)
  210686. {
  210687. result = new CoreAudioInternal (devs[i]);
  210688. const bool thisIsInput = inChanNames.size() > 0 && outChanNames.size() == 0;
  210689. const bool otherIsInput = result->inChanNames.size() > 0 && result->outChanNames.size() == 0;
  210690. if (thisIsInput != otherIsInput
  210691. || (inChanNames.size() + outChanNames.size() == 0)
  210692. || (result->inChanNames.size() + result->outChanNames.size()) == 0)
  210693. break;
  210694. result = 0;
  210695. }
  210696. }
  210697. }
  210698. }
  210699. return result.release();
  210700. }
  210701. juce_UseDebuggingNewOperator
  210702. int inputLatency, outputLatency;
  210703. BitArray activeInputChans, activeOutputChans;
  210704. StringArray inChanNames, outChanNames;
  210705. Array <double> sampleRates;
  210706. Array <int> bufferSizes;
  210707. AudioIODeviceCallback* callback;
  210708. #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
  210709. AudioDeviceIOProcID audioProcID;
  210710. #endif
  210711. CoreAudioInternal* inputDevice;
  210712. bool isSlaveDevice;
  210713. private:
  210714. CriticalSection callbackLock;
  210715. AudioDeviceID deviceID;
  210716. bool started;
  210717. double sampleRate;
  210718. int bufferSize;
  210719. HeapBlock <float> audioBuffer;
  210720. int numInputChans, numOutputChans;
  210721. bool callbacksAllowed;
  210722. struct CallbackDetailsForChannel
  210723. {
  210724. int streamNum;
  210725. int dataOffsetSamples;
  210726. int dataStrideSamples;
  210727. };
  210728. int numInputChannelInfos, numOutputChannelInfos;
  210729. HeapBlock <CallbackDetailsForChannel> inputChannelInfo, outputChannelInfo;
  210730. HeapBlock <float*> tempInputBuffers, tempOutputBuffers;
  210731. CoreAudioInternal (const CoreAudioInternal&);
  210732. CoreAudioInternal& operator= (const CoreAudioInternal&);
  210733. static OSStatus audioIOProc (AudioDeviceID inDevice,
  210734. const AudioTimeStamp* inNow,
  210735. const AudioBufferList* inInputData,
  210736. const AudioTimeStamp* inInputTime,
  210737. AudioBufferList* outOutputData,
  210738. const AudioTimeStamp* inOutputTime,
  210739. void* device)
  210740. {
  210741. ((CoreAudioInternal*) device)->audioCallback (inInputData, outOutputData);
  210742. return noErr;
  210743. }
  210744. static OSStatus deviceListenerProc (AudioDeviceID /*inDevice*/, UInt32 /*inLine*/, const AudioObjectPropertyAddress* pa, void* inClientData)
  210745. {
  210746. CoreAudioInternal* const intern = (CoreAudioInternal*) inClientData;
  210747. switch (pa->mSelector)
  210748. {
  210749. case kAudioDevicePropertyBufferSize:
  210750. case kAudioDevicePropertyBufferFrameSize:
  210751. case kAudioDevicePropertyNominalSampleRate:
  210752. case kAudioDevicePropertyStreamFormat:
  210753. case kAudioDevicePropertyDeviceIsAlive:
  210754. intern->deviceDetailsChanged();
  210755. break;
  210756. case kAudioDevicePropertyBufferSizeRange:
  210757. case kAudioDevicePropertyVolumeScalar:
  210758. case kAudioDevicePropertyMute:
  210759. case kAudioDevicePropertyPlayThru:
  210760. case kAudioDevicePropertyDataSource:
  210761. case kAudioDevicePropertyDeviceIsRunning:
  210762. break;
  210763. }
  210764. return noErr;
  210765. }
  210766. static int getAllDataSourcesForDevice (AudioDeviceID deviceID, const bool input, HeapBlock <OSType>& types)
  210767. {
  210768. AudioObjectPropertyAddress pa;
  210769. pa.mSelector = kAudioDevicePropertyDataSources;
  210770. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210771. pa.mElement = kAudioObjectPropertyElementMaster;
  210772. UInt32 size = 0;
  210773. if (deviceID != 0
  210774. && OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210775. {
  210776. types.calloc (size, 1);
  210777. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, types)))
  210778. return size / (int) sizeof (OSType);
  210779. }
  210780. return 0;
  210781. }
  210782. };
  210783. class CoreAudioIODevice : public AudioIODevice
  210784. {
  210785. public:
  210786. CoreAudioIODevice (const String& deviceName,
  210787. AudioDeviceID inputDeviceId,
  210788. const int inputIndex_,
  210789. AudioDeviceID outputDeviceId,
  210790. const int outputIndex_)
  210791. : AudioIODevice (deviceName, "CoreAudio"),
  210792. inputIndex (inputIndex_),
  210793. outputIndex (outputIndex_),
  210794. isOpen_ (false),
  210795. isStarted (false)
  210796. {
  210797. internal = 0;
  210798. CoreAudioInternal* device = 0;
  210799. if (outputDeviceId == 0 || outputDeviceId == inputDeviceId)
  210800. {
  210801. jassert (inputDeviceId != 0);
  210802. device = new CoreAudioInternal (inputDeviceId);
  210803. }
  210804. else
  210805. {
  210806. device = new CoreAudioInternal (outputDeviceId);
  210807. if (inputDeviceId != 0)
  210808. {
  210809. CoreAudioInternal* secondDevice = new CoreAudioInternal (inputDeviceId);
  210810. device->inputDevice = secondDevice;
  210811. secondDevice->isSlaveDevice = true;
  210812. }
  210813. }
  210814. internal = device;
  210815. AudioObjectPropertyAddress pa;
  210816. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  210817. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210818. pa.mElement = kAudioObjectPropertyElementWildcard;
  210819. AudioObjectAddPropertyListener (kAudioObjectSystemObject, &pa, hardwareListenerProc, internal);
  210820. }
  210821. ~CoreAudioIODevice()
  210822. {
  210823. AudioObjectPropertyAddress pa;
  210824. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  210825. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210826. pa.mElement = kAudioObjectPropertyElementWildcard;
  210827. AudioObjectRemovePropertyListener (kAudioObjectSystemObject, &pa, hardwareListenerProc, internal);
  210828. delete internal;
  210829. }
  210830. const StringArray getOutputChannelNames()
  210831. {
  210832. return internal->outChanNames;
  210833. }
  210834. const StringArray getInputChannelNames()
  210835. {
  210836. if (internal->inputDevice != 0)
  210837. return internal->inputDevice->inChanNames;
  210838. else
  210839. return internal->inChanNames;
  210840. }
  210841. int getNumSampleRates()
  210842. {
  210843. return internal->sampleRates.size();
  210844. }
  210845. double getSampleRate (int index)
  210846. {
  210847. return internal->sampleRates [index];
  210848. }
  210849. int getNumBufferSizesAvailable()
  210850. {
  210851. return internal->bufferSizes.size();
  210852. }
  210853. int getBufferSizeSamples (int index)
  210854. {
  210855. return internal->bufferSizes [index];
  210856. }
  210857. int getDefaultBufferSize()
  210858. {
  210859. for (int i = 0; i < getNumBufferSizesAvailable(); ++i)
  210860. if (getBufferSizeSamples(i) >= 512)
  210861. return getBufferSizeSamples(i);
  210862. return 512;
  210863. }
  210864. const String open (const BitArray& inputChannels,
  210865. const BitArray& outputChannels,
  210866. double sampleRate,
  210867. int bufferSizeSamples)
  210868. {
  210869. isOpen_ = true;
  210870. if (bufferSizeSamples <= 0)
  210871. bufferSizeSamples = getDefaultBufferSize();
  210872. lastError = internal->reopen (inputChannels, outputChannels, sampleRate, bufferSizeSamples);
  210873. isOpen_ = lastError.isEmpty();
  210874. return lastError;
  210875. }
  210876. void close()
  210877. {
  210878. isOpen_ = false;
  210879. internal->stop (false);
  210880. }
  210881. bool isOpen()
  210882. {
  210883. return isOpen_;
  210884. }
  210885. int getCurrentBufferSizeSamples()
  210886. {
  210887. return internal != 0 ? internal->getBufferSize() : 512;
  210888. }
  210889. double getCurrentSampleRate()
  210890. {
  210891. return internal != 0 ? internal->getSampleRate() : 0;
  210892. }
  210893. int getCurrentBitDepth()
  210894. {
  210895. return 32; // no way to find out, so just assume it's high..
  210896. }
  210897. const BitArray getActiveOutputChannels() const
  210898. {
  210899. return internal != 0 ? internal->activeOutputChans : BitArray();
  210900. }
  210901. const BitArray getActiveInputChannels() const
  210902. {
  210903. BitArray chans;
  210904. if (internal != 0)
  210905. {
  210906. chans = internal->activeInputChans;
  210907. if (internal->inputDevice != 0)
  210908. chans.orWith (internal->inputDevice->activeInputChans);
  210909. }
  210910. return chans;
  210911. }
  210912. int getOutputLatencyInSamples()
  210913. {
  210914. if (internal == 0)
  210915. return 0;
  210916. // this seems like a good guess at getting the latency right - comparing
  210917. // this with a round-trip measurement, it gets it to within a few millisecs
  210918. // for the built-in mac soundcard
  210919. return internal->outputLatency + internal->getBufferSize() * 2;
  210920. }
  210921. int getInputLatencyInSamples()
  210922. {
  210923. if (internal == 0)
  210924. return 0;
  210925. return internal->inputLatency + internal->getBufferSize() * 2;
  210926. }
  210927. void start (AudioIODeviceCallback* callback)
  210928. {
  210929. if (internal != 0 && ! isStarted)
  210930. {
  210931. if (callback != 0)
  210932. callback->audioDeviceAboutToStart (this);
  210933. isStarted = true;
  210934. internal->start (callback);
  210935. }
  210936. }
  210937. void stop()
  210938. {
  210939. if (isStarted && internal != 0)
  210940. {
  210941. AudioIODeviceCallback* const lastCallback = internal->callback;
  210942. isStarted = false;
  210943. internal->stop (true);
  210944. if (lastCallback != 0)
  210945. lastCallback->audioDeviceStopped();
  210946. }
  210947. }
  210948. bool isPlaying()
  210949. {
  210950. if (internal->callback == 0)
  210951. isStarted = false;
  210952. return isStarted;
  210953. }
  210954. const String getLastError()
  210955. {
  210956. return lastError;
  210957. }
  210958. int inputIndex, outputIndex;
  210959. juce_UseDebuggingNewOperator
  210960. private:
  210961. CoreAudioInternal* internal;
  210962. bool isOpen_, isStarted;
  210963. String lastError;
  210964. static OSStatus hardwareListenerProc (AudioDeviceID /*inDevice*/, UInt32 /*inLine*/, const AudioObjectPropertyAddress* pa, void* inClientData)
  210965. {
  210966. CoreAudioInternal* const intern = (CoreAudioInternal*) inClientData;
  210967. switch (pa->mSelector)
  210968. {
  210969. case kAudioHardwarePropertyDevices:
  210970. intern->deviceDetailsChanged();
  210971. break;
  210972. case kAudioHardwarePropertyDefaultOutputDevice:
  210973. case kAudioHardwarePropertyDefaultInputDevice:
  210974. case kAudioHardwarePropertyDefaultSystemOutputDevice:
  210975. break;
  210976. }
  210977. return noErr;
  210978. }
  210979. CoreAudioIODevice (const CoreAudioIODevice&);
  210980. CoreAudioIODevice& operator= (const CoreAudioIODevice&);
  210981. };
  210982. class CoreAudioIODeviceType : public AudioIODeviceType
  210983. {
  210984. public:
  210985. CoreAudioIODeviceType()
  210986. : AudioIODeviceType (T("CoreAudio")),
  210987. hasScanned (false)
  210988. {
  210989. }
  210990. ~CoreAudioIODeviceType()
  210991. {
  210992. }
  210993. void scanForDevices()
  210994. {
  210995. hasScanned = true;
  210996. inputDeviceNames.clear();
  210997. outputDeviceNames.clear();
  210998. inputIds.clear();
  210999. outputIds.clear();
  211000. UInt32 size;
  211001. AudioObjectPropertyAddress pa;
  211002. pa.mSelector = kAudioHardwarePropertyDevices;
  211003. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211004. pa.mElement = kAudioObjectPropertyElementMaster;
  211005. if (OK (AudioObjectGetPropertyDataSize (kAudioObjectSystemObject, &pa, 0, 0, &size)))
  211006. {
  211007. HeapBlock <AudioDeviceID> devs;
  211008. devs.calloc (size, 1);
  211009. if (OK (AudioObjectGetPropertyData (kAudioObjectSystemObject, &pa, 0, 0, &size, devs)))
  211010. {
  211011. static bool alreadyLogged = false;
  211012. const int num = size / (int) sizeof (AudioDeviceID);
  211013. for (int i = 0; i < num; ++i)
  211014. {
  211015. char name [1024];
  211016. size = sizeof (name);
  211017. pa.mSelector = kAudioDevicePropertyDeviceName;
  211018. if (OK (AudioObjectGetPropertyData (devs[i], &pa, 0, 0, &size, name)))
  211019. {
  211020. const String nameString (String::fromUTF8 (name, (int) strlen (name)));
  211021. if (! alreadyLogged)
  211022. log (T("CoreAudio device: ") + nameString);
  211023. const int numIns = getNumChannels (devs[i], true);
  211024. const int numOuts = getNumChannels (devs[i], false);
  211025. if (numIns > 0)
  211026. {
  211027. inputDeviceNames.add (nameString);
  211028. inputIds.add (devs[i]);
  211029. }
  211030. if (numOuts > 0)
  211031. {
  211032. outputDeviceNames.add (nameString);
  211033. outputIds.add (devs[i]);
  211034. }
  211035. }
  211036. }
  211037. alreadyLogged = true;
  211038. }
  211039. }
  211040. inputDeviceNames.appendNumbersToDuplicates (false, true);
  211041. outputDeviceNames.appendNumbersToDuplicates (false, true);
  211042. }
  211043. const StringArray getDeviceNames (const bool wantInputNames) const
  211044. {
  211045. jassert (hasScanned); // need to call scanForDevices() before doing this
  211046. if (wantInputNames)
  211047. return inputDeviceNames;
  211048. else
  211049. return outputDeviceNames;
  211050. }
  211051. int getDefaultDeviceIndex (const bool forInput) const
  211052. {
  211053. jassert (hasScanned); // need to call scanForDevices() before doing this
  211054. AudioDeviceID deviceID;
  211055. UInt32 size = sizeof (deviceID);
  211056. // if they're asking for any input channels at all, use the default input, so we
  211057. // get the built-in mic rather than the built-in output with no inputs..
  211058. AudioObjectPropertyAddress pa;
  211059. pa.mSelector = forInput ? kAudioHardwarePropertyDefaultInputDevice : kAudioHardwarePropertyDefaultOutputDevice;
  211060. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211061. pa.mElement = kAudioObjectPropertyElementMaster;
  211062. if (AudioObjectGetPropertyData (kAudioObjectSystemObject, &pa, 0, 0, &size, &deviceID) == noErr)
  211063. {
  211064. if (forInput)
  211065. {
  211066. for (int i = inputIds.size(); --i >= 0;)
  211067. if (inputIds[i] == deviceID)
  211068. return i;
  211069. }
  211070. else
  211071. {
  211072. for (int i = outputIds.size(); --i >= 0;)
  211073. if (outputIds[i] == deviceID)
  211074. return i;
  211075. }
  211076. }
  211077. return 0;
  211078. }
  211079. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  211080. {
  211081. jassert (hasScanned); // need to call scanForDevices() before doing this
  211082. CoreAudioIODevice* const d = dynamic_cast <CoreAudioIODevice*> (device);
  211083. if (d == 0)
  211084. return -1;
  211085. return asInput ? d->inputIndex
  211086. : d->outputIndex;
  211087. }
  211088. bool hasSeparateInputsAndOutputs() const { return true; }
  211089. AudioIODevice* createDevice (const String& outputDeviceName,
  211090. const String& inputDeviceName)
  211091. {
  211092. jassert (hasScanned); // need to call scanForDevices() before doing this
  211093. const int inputIndex = inputDeviceNames.indexOf (inputDeviceName);
  211094. const int outputIndex = outputDeviceNames.indexOf (outputDeviceName);
  211095. String deviceName (outputDeviceName);
  211096. if (deviceName.isEmpty())
  211097. deviceName = inputDeviceName;
  211098. if (index >= 0)
  211099. return new CoreAudioIODevice (deviceName,
  211100. inputIds [inputIndex],
  211101. inputIndex,
  211102. outputIds [outputIndex],
  211103. outputIndex);
  211104. return 0;
  211105. }
  211106. juce_UseDebuggingNewOperator
  211107. private:
  211108. StringArray inputDeviceNames, outputDeviceNames;
  211109. Array <AudioDeviceID> inputIds, outputIds;
  211110. bool hasScanned;
  211111. static int getNumChannels (AudioDeviceID deviceID, bool input)
  211112. {
  211113. int total = 0;
  211114. UInt32 size;
  211115. AudioObjectPropertyAddress pa;
  211116. pa.mSelector = kAudioDevicePropertyStreamConfiguration;
  211117. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  211118. pa.mElement = kAudioObjectPropertyElementMaster;
  211119. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  211120. {
  211121. HeapBlock <AudioBufferList> bufList;
  211122. bufList.calloc (size, 1);
  211123. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, bufList)))
  211124. {
  211125. const int numStreams = bufList->mNumberBuffers;
  211126. for (int i = 0; i < numStreams; ++i)
  211127. {
  211128. const AudioBuffer& b = bufList->mBuffers[i];
  211129. total += b.mNumberChannels;
  211130. }
  211131. }
  211132. }
  211133. return total;
  211134. }
  211135. CoreAudioIODeviceType (const CoreAudioIODeviceType&);
  211136. CoreAudioIODeviceType& operator= (const CoreAudioIODeviceType&);
  211137. };
  211138. AudioIODeviceType* juce_createAudioIODeviceType_CoreAudio()
  211139. {
  211140. return new CoreAudioIODeviceType();
  211141. }
  211142. #undef log
  211143. #endif
  211144. /*** End of inlined file: juce_mac_CoreAudio.cpp ***/
  211145. /*** Start of inlined file: juce_mac_CoreMidi.cpp ***/
  211146. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  211147. // compiled on its own).
  211148. #if JUCE_INCLUDED_FILE
  211149. #if JUCE_MAC
  211150. #undef log
  211151. #define log(a) Logger::writeToLog(a)
  211152. static bool logAnyErrorsMidi (const OSStatus err, const int lineNum)
  211153. {
  211154. if (err == noErr)
  211155. return true;
  211156. log (T("CoreMidi error: ") + String (lineNum) + T(" - ") + String::toHexString ((int)err));
  211157. jassertfalse
  211158. return false;
  211159. }
  211160. #undef OK
  211161. #define OK(a) logAnyErrorsMidi(a, __LINE__)
  211162. static const String getEndpointName (MIDIEndpointRef endpoint, bool isExternal)
  211163. {
  211164. String result;
  211165. CFStringRef str = 0;
  211166. MIDIObjectGetStringProperty (endpoint, kMIDIPropertyName, &str);
  211167. if (str != 0)
  211168. {
  211169. result = PlatformUtilities::cfStringToJuceString (str);
  211170. CFRelease (str);
  211171. str = 0;
  211172. }
  211173. MIDIEntityRef entity = 0;
  211174. MIDIEndpointGetEntity (endpoint, &entity);
  211175. if (entity == 0)
  211176. return result; // probably virtual
  211177. if (result.isEmpty())
  211178. {
  211179. // endpoint name has zero length - try the entity
  211180. MIDIObjectGetStringProperty (entity, kMIDIPropertyName, &str);
  211181. if (str != 0)
  211182. {
  211183. result += PlatformUtilities::cfStringToJuceString (str);
  211184. CFRelease (str);
  211185. str = 0;
  211186. }
  211187. }
  211188. // now consider the device's name
  211189. MIDIDeviceRef device = 0;
  211190. MIDIEntityGetDevice (entity, &device);
  211191. if (device == 0)
  211192. return result;
  211193. MIDIObjectGetStringProperty (device, kMIDIPropertyName, &str);
  211194. if (str != 0)
  211195. {
  211196. const String s (PlatformUtilities::cfStringToJuceString (str));
  211197. CFRelease (str);
  211198. // if an external device has only one entity, throw away
  211199. // the endpoint name and just use the device name
  211200. if (isExternal && MIDIDeviceGetNumberOfEntities (device) < 2)
  211201. {
  211202. result = s;
  211203. }
  211204. else if (! result.startsWithIgnoreCase (s))
  211205. {
  211206. // prepend the device name to the entity name
  211207. result = (s + T(" ") + result).trimEnd();
  211208. }
  211209. }
  211210. return result;
  211211. }
  211212. static const String getConnectedEndpointName (MIDIEndpointRef endpoint)
  211213. {
  211214. String result;
  211215. // Does the endpoint have connections?
  211216. CFDataRef connections = 0;
  211217. int numConnections = 0;
  211218. MIDIObjectGetDataProperty (endpoint, kMIDIPropertyConnectionUniqueID, &connections);
  211219. if (connections != 0)
  211220. {
  211221. numConnections = (int) (CFDataGetLength (connections) / sizeof (MIDIUniqueID));
  211222. if (numConnections > 0)
  211223. {
  211224. const SInt32* pid = reinterpret_cast <const SInt32*> (CFDataGetBytePtr (connections));
  211225. for (int i = 0; i < numConnections; ++i, ++pid)
  211226. {
  211227. MIDIUniqueID uid = EndianS32_BtoN (*pid);
  211228. MIDIObjectRef connObject;
  211229. MIDIObjectType connObjectType;
  211230. OSStatus err = MIDIObjectFindByUniqueID (uid, &connObject, &connObjectType);
  211231. if (err == noErr)
  211232. {
  211233. String s;
  211234. if (connObjectType == kMIDIObjectType_ExternalSource
  211235. || connObjectType == kMIDIObjectType_ExternalDestination)
  211236. {
  211237. // Connected to an external device's endpoint (10.3 and later).
  211238. s = getEndpointName (static_cast <MIDIEndpointRef> (connObject), true);
  211239. }
  211240. else
  211241. {
  211242. // Connected to an external device (10.2) (or something else, catch-all)
  211243. CFStringRef str = 0;
  211244. MIDIObjectGetStringProperty (connObject, kMIDIPropertyName, &str);
  211245. if (str != 0)
  211246. {
  211247. s = PlatformUtilities::cfStringToJuceString (str);
  211248. CFRelease (str);
  211249. }
  211250. }
  211251. if (s.isNotEmpty())
  211252. {
  211253. if (result.isNotEmpty())
  211254. result += (", ");
  211255. result += s;
  211256. }
  211257. }
  211258. }
  211259. }
  211260. CFRelease (connections);
  211261. }
  211262. if (result.isNotEmpty())
  211263. return result;
  211264. // Here, either the endpoint had no connections, or we failed to obtain names for any of them.
  211265. return getEndpointName (endpoint, false);
  211266. }
  211267. const StringArray MidiOutput::getDevices()
  211268. {
  211269. StringArray s;
  211270. const ItemCount num = MIDIGetNumberOfDestinations();
  211271. for (ItemCount i = 0; i < num; ++i)
  211272. {
  211273. MIDIEndpointRef dest = MIDIGetDestination (i);
  211274. if (dest != 0)
  211275. {
  211276. String name (getConnectedEndpointName (dest));
  211277. if (name.isEmpty())
  211278. name = "<error>";
  211279. s.add (name);
  211280. }
  211281. else
  211282. {
  211283. s.add ("<error>");
  211284. }
  211285. }
  211286. return s;
  211287. }
  211288. int MidiOutput::getDefaultDeviceIndex()
  211289. {
  211290. return 0;
  211291. }
  211292. static MIDIClientRef globalMidiClient;
  211293. static bool hasGlobalClientBeenCreated = false;
  211294. static bool makeSureClientExists()
  211295. {
  211296. if (! hasGlobalClientBeenCreated)
  211297. {
  211298. String name (T("JUCE"));
  211299. if (JUCEApplication::getInstance() != 0)
  211300. name = JUCEApplication::getInstance()->getApplicationName();
  211301. CFStringRef appName = PlatformUtilities::juceStringToCFString (name);
  211302. hasGlobalClientBeenCreated = OK (MIDIClientCreate (appName, 0, 0, &globalMidiClient));
  211303. CFRelease (appName);
  211304. }
  211305. return hasGlobalClientBeenCreated;
  211306. }
  211307. class MidiPortAndEndpoint
  211308. {
  211309. public:
  211310. MidiPortAndEndpoint (MIDIPortRef port_, MIDIEndpointRef endPoint_)
  211311. : port (port_), endPoint (endPoint_)
  211312. {
  211313. }
  211314. ~MidiPortAndEndpoint()
  211315. {
  211316. if (port != 0)
  211317. MIDIPortDispose (port);
  211318. if (port == 0 && endPoint != 0) // if port == 0, it means we created the endpoint, so it's safe to delete it
  211319. MIDIEndpointDispose (endPoint);
  211320. }
  211321. MIDIPortRef port;
  211322. MIDIEndpointRef endPoint;
  211323. };
  211324. MidiOutput* MidiOutput::openDevice (int index)
  211325. {
  211326. MidiOutput* mo = 0;
  211327. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfDestinations())
  211328. {
  211329. MIDIEndpointRef endPoint = MIDIGetDestination (index);
  211330. CFStringRef pname;
  211331. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  211332. {
  211333. log (T("CoreMidi - opening out: ") + PlatformUtilities::cfStringToJuceString (pname));
  211334. if (makeSureClientExists())
  211335. {
  211336. MIDIPortRef port;
  211337. if (OK (MIDIOutputPortCreate (globalMidiClient, pname, &port)))
  211338. {
  211339. mo = new MidiOutput();
  211340. mo->internal = (void*) new MidiPortAndEndpoint (port, endPoint);
  211341. }
  211342. }
  211343. CFRelease (pname);
  211344. }
  211345. }
  211346. return mo;
  211347. }
  211348. MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
  211349. {
  211350. MidiOutput* mo = 0;
  211351. if (makeSureClientExists())
  211352. {
  211353. MIDIEndpointRef endPoint;
  211354. CFStringRef name = PlatformUtilities::juceStringToCFString (deviceName);
  211355. if (OK (MIDISourceCreate (globalMidiClient, name, &endPoint)))
  211356. {
  211357. mo = new MidiOutput();
  211358. mo->internal = (void*) new MidiPortAndEndpoint (0, endPoint);
  211359. }
  211360. CFRelease (name);
  211361. }
  211362. return mo;
  211363. }
  211364. MidiOutput::~MidiOutput()
  211365. {
  211366. delete (MidiPortAndEndpoint*) internal;
  211367. }
  211368. void MidiOutput::reset()
  211369. {
  211370. }
  211371. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  211372. {
  211373. return false;
  211374. }
  211375. void MidiOutput::setVolume (float leftVol, float rightVol)
  211376. {
  211377. }
  211378. void MidiOutput::sendMessageNow (const MidiMessage& message)
  211379. {
  211380. MidiPortAndEndpoint* const mpe = (MidiPortAndEndpoint*) internal;
  211381. if (message.isSysEx())
  211382. {
  211383. const int maxPacketSize = 256;
  211384. int pos = 0, bytesLeft = message.getRawDataSize();
  211385. const int numPackets = (bytesLeft + maxPacketSize - 1) / maxPacketSize;
  211386. HeapBlock <MIDIPacketList> packets;
  211387. packets.malloc (32 * numPackets + message.getRawDataSize(), 1);
  211388. packets->numPackets = numPackets;
  211389. MIDIPacket* p = packets->packet;
  211390. for (int i = 0; i < numPackets; ++i)
  211391. {
  211392. p->timeStamp = 0;
  211393. p->length = jmin (maxPacketSize, bytesLeft);
  211394. memcpy (p->data, message.getRawData() + pos, p->length);
  211395. pos += p->length;
  211396. bytesLeft -= p->length;
  211397. p = MIDIPacketNext (p);
  211398. }
  211399. if (mpe->port != 0)
  211400. MIDISend (mpe->port, mpe->endPoint, packets);
  211401. else
  211402. MIDIReceived (mpe->endPoint, packets);
  211403. }
  211404. else
  211405. {
  211406. MIDIPacketList packets;
  211407. packets.numPackets = 1;
  211408. packets.packet[0].timeStamp = 0;
  211409. packets.packet[0].length = message.getRawDataSize();
  211410. *(int*) (packets.packet[0].data) = *(const int*) message.getRawData();
  211411. if (mpe->port != 0)
  211412. MIDISend (mpe->port, mpe->endPoint, &packets);
  211413. else
  211414. MIDIReceived (mpe->endPoint, &packets);
  211415. }
  211416. }
  211417. const StringArray MidiInput::getDevices()
  211418. {
  211419. StringArray s;
  211420. const ItemCount num = MIDIGetNumberOfSources();
  211421. for (ItemCount i = 0; i < num; ++i)
  211422. {
  211423. MIDIEndpointRef source = MIDIGetSource (i);
  211424. if (source != 0)
  211425. {
  211426. String name (getConnectedEndpointName (source));
  211427. if (name.isEmpty())
  211428. name = "<error>";
  211429. s.add (name);
  211430. }
  211431. else
  211432. {
  211433. s.add ("<error>");
  211434. }
  211435. }
  211436. return s;
  211437. }
  211438. int MidiInput::getDefaultDeviceIndex()
  211439. {
  211440. return 0;
  211441. }
  211442. struct MidiPortAndCallback
  211443. {
  211444. MidiInput* input;
  211445. MidiPortAndEndpoint* portAndEndpoint;
  211446. MidiInputCallback* callback;
  211447. MemoryBlock pendingData;
  211448. int pendingBytes;
  211449. double pendingDataTime;
  211450. bool active;
  211451. void processSysex (const uint8*& d, int& size, const double time)
  211452. {
  211453. if (*d == 0xf0)
  211454. {
  211455. pendingBytes = 0;
  211456. pendingDataTime = time;
  211457. }
  211458. pendingData.ensureSize (pendingBytes + size, false);
  211459. uint8* totalMessage = (uint8*) pendingData.getData();
  211460. uint8* dest = totalMessage + pendingBytes;
  211461. while (size > 0)
  211462. {
  211463. if (pendingBytes > 0 && *d >= 0x80)
  211464. {
  211465. if (*d >= 0xfa || *d == 0xf8)
  211466. {
  211467. callback->handleIncomingMidiMessage (input, MidiMessage (*d, time));
  211468. ++d;
  211469. --size;
  211470. }
  211471. else
  211472. {
  211473. if (*d == 0xf7)
  211474. {
  211475. *dest++ = *d++;
  211476. pendingBytes++;
  211477. --size;
  211478. }
  211479. break;
  211480. }
  211481. }
  211482. else
  211483. {
  211484. *dest++ = *d++;
  211485. pendingBytes++;
  211486. --size;
  211487. }
  211488. }
  211489. if (totalMessage [pendingBytes - 1] == 0xf7)
  211490. {
  211491. callback->handleIncomingMidiMessage (input, MidiMessage (totalMessage, pendingBytes, pendingDataTime));
  211492. pendingBytes = 0;
  211493. }
  211494. else
  211495. {
  211496. callback->handlePartialSysexMessage (input, totalMessage, pendingBytes, pendingDataTime);
  211497. }
  211498. }
  211499. };
  211500. namespace CoreMidiCallbacks
  211501. {
  211502. static CriticalSection callbackLock;
  211503. static VoidArray activeCallbacks;
  211504. }
  211505. static void midiInputProc (const MIDIPacketList* pktlist,
  211506. void* readProcRefCon,
  211507. void* srcConnRefCon)
  211508. {
  211509. double time = Time::getMillisecondCounterHiRes() * 0.001;
  211510. const double originalTime = time;
  211511. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) readProcRefCon;
  211512. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211513. if (CoreMidiCallbacks::activeCallbacks.contains (mpc) && mpc->active)
  211514. {
  211515. const MIDIPacket* packet = &pktlist->packet[0];
  211516. for (unsigned int i = 0; i < pktlist->numPackets; ++i)
  211517. {
  211518. const uint8* d = (const uint8*) (packet->data);
  211519. int size = packet->length;
  211520. while (size > 0)
  211521. {
  211522. time = originalTime;
  211523. if (mpc->pendingBytes > 0 || d[0] == 0xf0)
  211524. {
  211525. mpc->processSysex (d, size, time);
  211526. }
  211527. else
  211528. {
  211529. int used = 0;
  211530. const MidiMessage m (d, size, used, 0, time);
  211531. if (used <= 0)
  211532. {
  211533. jassertfalse // malformed midi message
  211534. break;
  211535. }
  211536. else
  211537. {
  211538. mpc->callback->handleIncomingMidiMessage (mpc->input, m);
  211539. }
  211540. size -= used;
  211541. d += used;
  211542. }
  211543. }
  211544. packet = MIDIPacketNext (packet);
  211545. }
  211546. }
  211547. }
  211548. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  211549. {
  211550. MidiInput* mi = 0;
  211551. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfSources())
  211552. {
  211553. MIDIEndpointRef endPoint = MIDIGetSource (index);
  211554. if (endPoint != 0)
  211555. {
  211556. CFStringRef pname;
  211557. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  211558. {
  211559. log (T("CoreMidi - opening inp: ") + PlatformUtilities::cfStringToJuceString (pname));
  211560. if (makeSureClientExists())
  211561. {
  211562. MIDIPortRef port;
  211563. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  211564. mpc->active = false;
  211565. if (OK (MIDIInputPortCreate (globalMidiClient, pname, midiInputProc, mpc, &port)))
  211566. {
  211567. if (OK (MIDIPortConnectSource (port, endPoint, 0)))
  211568. {
  211569. mpc->portAndEndpoint = new MidiPortAndEndpoint (port, endPoint);
  211570. mpc->callback = callback;
  211571. mpc->pendingBytes = 0;
  211572. mpc->pendingData.ensureSize (128);
  211573. mi = new MidiInput (getDevices() [index]);
  211574. mpc->input = mi;
  211575. mi->internal = (void*) mpc;
  211576. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211577. CoreMidiCallbacks::activeCallbacks.add (mpc.release());
  211578. }
  211579. else
  211580. {
  211581. OK (MIDIPortDispose (port));
  211582. }
  211583. }
  211584. }
  211585. }
  211586. CFRelease (pname);
  211587. }
  211588. }
  211589. return mi;
  211590. }
  211591. MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback)
  211592. {
  211593. MidiInput* mi = 0;
  211594. if (makeSureClientExists())
  211595. {
  211596. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  211597. mpc->active = false;
  211598. MIDIEndpointRef endPoint;
  211599. CFStringRef name = PlatformUtilities::juceStringToCFString(deviceName);
  211600. if (OK (MIDIDestinationCreate (globalMidiClient, name, midiInputProc, mpc, &endPoint)))
  211601. {
  211602. mpc->portAndEndpoint = new MidiPortAndEndpoint (0, endPoint);
  211603. mpc->callback = callback;
  211604. mpc->pendingBytes = 0;
  211605. mpc->pendingData.ensureSize (128);
  211606. mi = new MidiInput (deviceName);
  211607. mpc->input = mi;
  211608. mi->internal = (void*) mpc;
  211609. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211610. CoreMidiCallbacks::activeCallbacks.add (mpc.release());
  211611. }
  211612. CFRelease (name);
  211613. }
  211614. return mi;
  211615. }
  211616. MidiInput::MidiInput (const String& name_)
  211617. : name (name_)
  211618. {
  211619. }
  211620. MidiInput::~MidiInput()
  211621. {
  211622. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  211623. mpc->active = false;
  211624. {
  211625. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211626. CoreMidiCallbacks::activeCallbacks.removeValue (mpc);
  211627. }
  211628. if (mpc->portAndEndpoint->port != 0)
  211629. OK (MIDIPortDisconnectSource (mpc->portAndEndpoint->port, mpc->portAndEndpoint->endPoint));
  211630. delete mpc->portAndEndpoint;
  211631. delete mpc;
  211632. }
  211633. void MidiInput::start()
  211634. {
  211635. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211636. ((MidiPortAndCallback*) internal)->active = true;
  211637. }
  211638. void MidiInput::stop()
  211639. {
  211640. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211641. ((MidiPortAndCallback*) internal)->active = false;
  211642. }
  211643. #undef log
  211644. #else
  211645. MidiOutput::~MidiOutput()
  211646. {
  211647. }
  211648. void MidiOutput::reset()
  211649. {
  211650. }
  211651. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  211652. {
  211653. return false;
  211654. }
  211655. void MidiOutput::setVolume (float leftVol, float rightVol)
  211656. {
  211657. }
  211658. void MidiOutput::sendMessageNow (const MidiMessage& message)
  211659. {
  211660. }
  211661. const StringArray MidiOutput::getDevices()
  211662. {
  211663. return StringArray();
  211664. }
  211665. MidiOutput* MidiOutput::openDevice (int index)
  211666. {
  211667. return 0;
  211668. }
  211669. const StringArray MidiInput::getDevices()
  211670. {
  211671. return StringArray();
  211672. }
  211673. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  211674. {
  211675. return 0;
  211676. }
  211677. #endif
  211678. #endif
  211679. /*** End of inlined file: juce_mac_CoreMidi.cpp ***/
  211680. /*** Start of inlined file: juce_mac_CameraDevice.mm ***/
  211681. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  211682. // compiled on its own).
  211683. #if JUCE_INCLUDED_FILE && JUCE_QUICKTIME && JUCE_USE_CAMERA
  211684. #define QTCaptureCallbackDelegate MakeObjCClassName(QTCaptureCallbackDelegate)
  211685. class QTCameraDeviceInteral;
  211686. END_JUCE_NAMESPACE
  211687. @interface QTCaptureCallbackDelegate : NSObject
  211688. {
  211689. @public
  211690. CameraDevice* owner;
  211691. QTCameraDeviceInteral* internal;
  211692. int64 firstPresentationTime;
  211693. int64 averageTimeOffset;
  211694. }
  211695. - (QTCaptureCallbackDelegate*) initWithOwner: (CameraDevice*) owner internalDev: (QTCameraDeviceInteral*) d;
  211696. - (void) dealloc;
  211697. - (void) captureOutput: (QTCaptureOutput*) captureOutput
  211698. didOutputVideoFrame: (CVImageBufferRef) videoFrame
  211699. withSampleBuffer: (QTSampleBuffer*) sampleBuffer
  211700. fromConnection: (QTCaptureConnection*) connection;
  211701. - (void) captureOutput: (QTCaptureFileOutput*) captureOutput
  211702. didOutputSampleBuffer: (QTSampleBuffer*) sampleBuffer
  211703. fromConnection: (QTCaptureConnection*) connection;
  211704. @end
  211705. BEGIN_JUCE_NAMESPACE
  211706. class QTCameraDeviceInteral
  211707. {
  211708. public:
  211709. QTCameraDeviceInteral (CameraDevice* owner, int index)
  211710. {
  211711. const ScopedAutoReleasePool pool;
  211712. session = [[QTCaptureSession alloc] init];
  211713. NSArray* devs = [QTCaptureDevice inputDevicesWithMediaType: QTMediaTypeVideo];
  211714. device = (QTCaptureDevice*) [devs objectAtIndex: index];
  211715. input = 0;
  211716. audioInput = 0;
  211717. audioDevice = 0;
  211718. fileOutput = 0;
  211719. imageOutput = 0;
  211720. callbackDelegate = [[QTCaptureCallbackDelegate alloc] initWithOwner: owner
  211721. internalDev: this];
  211722. NSError* err = 0;
  211723. [device retain];
  211724. [device open: &err];
  211725. if (err == 0)
  211726. {
  211727. input = [[QTCaptureDeviceInput alloc] initWithDevice: device];
  211728. audioInput = [[QTCaptureDeviceInput alloc] initWithDevice: device];
  211729. [session addInput: input error: &err];
  211730. if (err == 0)
  211731. {
  211732. resetFile();
  211733. imageOutput = [[QTCaptureDecompressedVideoOutput alloc] init];
  211734. [imageOutput setDelegate: callbackDelegate];
  211735. if (err == 0)
  211736. {
  211737. [session startRunning];
  211738. return;
  211739. }
  211740. }
  211741. }
  211742. openingError = nsStringToJuce ([err description]);
  211743. DBG (openingError);
  211744. }
  211745. ~QTCameraDeviceInteral()
  211746. {
  211747. [session stopRunning];
  211748. [session removeOutput: imageOutput];
  211749. [session release];
  211750. [input release];
  211751. [device release];
  211752. [audioDevice release];
  211753. [audioInput release];
  211754. [fileOutput release];
  211755. [imageOutput release];
  211756. [callbackDelegate release];
  211757. }
  211758. void resetFile()
  211759. {
  211760. [fileOutput recordToOutputFileURL: nil];
  211761. [session removeOutput: fileOutput];
  211762. [fileOutput release];
  211763. fileOutput = [[QTCaptureMovieFileOutput alloc] init];
  211764. [session removeInput: audioInput];
  211765. [audioInput release];
  211766. audioInput = 0;
  211767. [audioDevice release];
  211768. audioDevice = 0;
  211769. [fileOutput setDelegate: callbackDelegate];
  211770. }
  211771. void addDefaultAudioInput()
  211772. {
  211773. NSError* err = nil;
  211774. audioDevice = [QTCaptureDevice defaultInputDeviceWithMediaType: QTMediaTypeSound];
  211775. if ([audioDevice open: &err])
  211776. [audioDevice retain];
  211777. else
  211778. audioDevice = nil;
  211779. if (audioDevice != 0)
  211780. {
  211781. audioInput = [[QTCaptureDeviceInput alloc] initWithDevice: audioDevice];
  211782. [session addInput: audioInput error: &err];
  211783. }
  211784. }
  211785. void addListener (CameraImageListener* listenerToAdd)
  211786. {
  211787. const ScopedLock sl (listenerLock);
  211788. if (listeners.size() == 0)
  211789. [session addOutput: imageOutput error: nil];
  211790. listeners.addIfNotAlreadyThere (listenerToAdd);
  211791. }
  211792. void removeListener (CameraImageListener* listenerToRemove)
  211793. {
  211794. const ScopedLock sl (listenerLock);
  211795. listeners.removeValue (listenerToRemove);
  211796. if (listeners.size() == 0)
  211797. [session removeOutput: imageOutput];
  211798. }
  211799. void callListeners (CIImage* frame, int w, int h)
  211800. {
  211801. CoreGraphicsImage image (Image::ARGB, w, h, false);
  211802. CIContext* cic = [CIContext contextWithCGContext: image.context options: nil];
  211803. [cic drawImage: frame inRect: CGRectMake (0, 0, w, h) fromRect: CGRectMake (0, 0, w, h)];
  211804. CGContextFlush (image.context);
  211805. const ScopedLock sl (listenerLock);
  211806. for (int i = listeners.size(); --i >= 0;)
  211807. {
  211808. CameraImageListener* l = (CameraImageListener*) listeners[i];
  211809. if (l != 0)
  211810. l->imageReceived (image);
  211811. }
  211812. }
  211813. QTCaptureDevice* device;
  211814. QTCaptureDeviceInput* input;
  211815. QTCaptureDevice* audioDevice;
  211816. QTCaptureDeviceInput* audioInput;
  211817. QTCaptureSession* session;
  211818. QTCaptureMovieFileOutput* fileOutput;
  211819. QTCaptureDecompressedVideoOutput* imageOutput;
  211820. QTCaptureCallbackDelegate* callbackDelegate;
  211821. String openingError;
  211822. VoidArray listeners;
  211823. CriticalSection listenerLock;
  211824. };
  211825. END_JUCE_NAMESPACE
  211826. @implementation QTCaptureCallbackDelegate
  211827. - (QTCaptureCallbackDelegate*) initWithOwner: (CameraDevice*) owner_
  211828. internalDev: (QTCameraDeviceInteral*) d
  211829. {
  211830. [super init];
  211831. owner = owner_;
  211832. internal = d;
  211833. firstPresentationTime = 0;
  211834. averageTimeOffset = 0;
  211835. return self;
  211836. }
  211837. - (void) dealloc
  211838. {
  211839. [super dealloc];
  211840. }
  211841. - (void) captureOutput: (QTCaptureOutput*) captureOutput
  211842. didOutputVideoFrame: (CVImageBufferRef) videoFrame
  211843. withSampleBuffer: (QTSampleBuffer*) sampleBuffer
  211844. fromConnection: (QTCaptureConnection*) connection
  211845. {
  211846. if (internal->listeners.size() > 0)
  211847. {
  211848. const ScopedAutoReleasePool pool;
  211849. internal->callListeners ([CIImage imageWithCVImageBuffer: videoFrame],
  211850. CVPixelBufferGetWidth (videoFrame),
  211851. CVPixelBufferGetHeight (videoFrame));
  211852. }
  211853. }
  211854. - (void) captureOutput: (QTCaptureFileOutput*) captureOutput
  211855. didOutputSampleBuffer: (QTSampleBuffer*) sampleBuffer
  211856. fromConnection: (QTCaptureConnection*) connection
  211857. {
  211858. const Time now (Time::getCurrentTime());
  211859. int64 presentationTime = ([sampleBuffer presentationTime].timeValue * 1000) / [sampleBuffer presentationTime].timeScale;
  211860. #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
  211861. NSNumber* hosttime = (NSNumber*) [sampleBuffer attributeForKey: QTSampleBufferHostTimeAttribute];
  211862. #else
  211863. NSNumber* hosttime = (NSNumber*) [sampleBuffer attributeForKey: @"hostTime"];
  211864. #endif
  211865. if (hosttime != nil)
  211866. presentationTime = (int64) AudioConvertHostTimeToNanos ([hosttime unsignedLongLongValue]) / 1000000;
  211867. const int64 timeDiff = now.toMilliseconds() - presentationTime - 50;
  211868. if (firstPresentationTime == 0)
  211869. {
  211870. firstPresentationTime = presentationTime;
  211871. averageTimeOffset = timeDiff;
  211872. }
  211873. else
  211874. {
  211875. averageTimeOffset = (averageTimeOffset * 120 + timeDiff * 8) / 128;
  211876. }
  211877. }
  211878. @end
  211879. BEGIN_JUCE_NAMESPACE
  211880. class QTCaptureViewerComp : public NSViewComponent
  211881. {
  211882. public:
  211883. QTCaptureViewerComp (CameraDevice* const cameraDevice, QTCameraDeviceInteral* const internal)
  211884. {
  211885. const ScopedAutoReleasePool pool;
  211886. captureView = [[QTCaptureView alloc] init];
  211887. [captureView setCaptureSession: internal->session];
  211888. setSize (640, 480); // xxx need to somehow get the movie size - how?
  211889. setView (captureView);
  211890. }
  211891. ~QTCaptureViewerComp()
  211892. {
  211893. setView (0);
  211894. [captureView setCaptureSession: nil];
  211895. [captureView release];
  211896. }
  211897. QTCaptureView* captureView;
  211898. };
  211899. CameraDevice::CameraDevice (const String& name_, int index)
  211900. : name (name_)
  211901. {
  211902. isRecording = false;
  211903. QTCameraDeviceInteral* d = new QTCameraDeviceInteral (this, index);
  211904. internal = d;
  211905. }
  211906. CameraDevice::~CameraDevice()
  211907. {
  211908. stopRecording();
  211909. delete (QTCameraDeviceInteral*) internal;
  211910. internal = 0;
  211911. }
  211912. Component* CameraDevice::createViewerComponent()
  211913. {
  211914. return new QTCaptureViewerComp (this, (QTCameraDeviceInteral*) internal);
  211915. }
  211916. const String CameraDevice::getFileExtension()
  211917. {
  211918. return ".mov";
  211919. }
  211920. void CameraDevice::startRecordingToFile (const File& file, int quality)
  211921. {
  211922. stopRecording();
  211923. QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal;
  211924. d->callbackDelegate->firstPresentationTime = 0;
  211925. file.deleteFile();
  211926. // In some versions of QT (e.g. on 10.5), if you record video without audio, the speed comes
  211927. // out wrong, so we'll put some audio in there too..,
  211928. d->addDefaultAudioInput();
  211929. [d->session addOutput: d->fileOutput error: nil];
  211930. NSEnumerator* connectionEnumerator = [[d->fileOutput connections] objectEnumerator];
  211931. for (;;)
  211932. {
  211933. QTCaptureConnection* connection = [connectionEnumerator nextObject];
  211934. if (connection == 0)
  211935. break;
  211936. QTCompressionOptions* options = 0;
  211937. NSString* mediaType = [connection mediaType];
  211938. if ([mediaType isEqualToString: QTMediaTypeVideo])
  211939. options = [QTCompressionOptions compressionOptionsWithIdentifier:
  211940. quality >= 1 ? @"QTCompressionOptionsSD480SizeH264Video"
  211941. : @"QTCompressionOptions240SizeH264Video"];
  211942. else if ([mediaType isEqualToString: QTMediaTypeSound])
  211943. options = [QTCompressionOptions compressionOptionsWithIdentifier: @"QTCompressionOptionsHighQualityAACAudio"];
  211944. [d->fileOutput setCompressionOptions: options forConnection: connection];
  211945. }
  211946. [d->fileOutput recordToOutputFileURL: [NSURL fileURLWithPath: juceStringToNS (file.getFullPathName())]];
  211947. isRecording = true;
  211948. }
  211949. const Time CameraDevice::getTimeOfFirstRecordedFrame() const
  211950. {
  211951. QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal;
  211952. if (d->callbackDelegate->firstPresentationTime != 0)
  211953. return Time (d->callbackDelegate->firstPresentationTime + d->callbackDelegate->averageTimeOffset);
  211954. return Time();
  211955. }
  211956. void CameraDevice::stopRecording()
  211957. {
  211958. if (isRecording)
  211959. {
  211960. QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal;
  211961. d->resetFile();
  211962. isRecording = false;
  211963. }
  211964. }
  211965. void CameraDevice::addListener (CameraImageListener* listenerToAdd)
  211966. {
  211967. QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal;
  211968. if (listenerToAdd != 0)
  211969. d->addListener (listenerToAdd);
  211970. }
  211971. void CameraDevice::removeListener (CameraImageListener* listenerToRemove)
  211972. {
  211973. QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal;
  211974. if (listenerToRemove != 0)
  211975. d->removeListener (listenerToRemove);
  211976. }
  211977. const StringArray CameraDevice::getAvailableDevices()
  211978. {
  211979. const ScopedAutoReleasePool pool;
  211980. StringArray results;
  211981. NSArray* devs = [QTCaptureDevice inputDevicesWithMediaType: QTMediaTypeVideo];
  211982. for (int i = 0; i < (int) [devs count]; ++i)
  211983. {
  211984. QTCaptureDevice* dev = (QTCaptureDevice*) [devs objectAtIndex: i];
  211985. results.add (nsStringToJuce ([dev localizedDisplayName]));
  211986. }
  211987. return results;
  211988. }
  211989. CameraDevice* CameraDevice::openDevice (int index,
  211990. int minWidth, int minHeight,
  211991. int maxWidth, int maxHeight)
  211992. {
  211993. ScopedPointer <CameraDevice> d (new CameraDevice (getAvailableDevices() [index], index));
  211994. if (((QTCameraDeviceInteral*) (d->internal))->openingError.isEmpty())
  211995. return d.release();
  211996. return 0;
  211997. }
  211998. #endif
  211999. /*** End of inlined file: juce_mac_CameraDevice.mm ***/
  212000. #endif
  212001. #endif
  212002. END_JUCE_NAMESPACE
  212003. #endif
  212004. /*** End of inlined file: juce_mac_NativeCode.mm ***/
  212005. #endif
  212006. #endif